Skip to content

Constrain auth.site to the documented Datadog sites#372

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 5 commits into
masterfrom
oliver/oliverli/typed-auth-sites
May 16, 2026
Merged

Constrain auth.site to the documented Datadog sites#372
gh-worker-dd-mergequeue-cf854d[bot] merged 5 commits into
masterfrom
oliver/oliverli/typed-auth-sites

Conversation

@oliverli
Copy link
Copy Markdown
Collaborator

@oliverli oliverli commented May 15, 2026

What and why?

Previously AuthOptions.site was string, which let typos flow silently into Datadog intake URLs.

It was also a major source of bugs as sometimes Datadog API endpoints would inadvertently be specified as e.g. https://${auth.site}/api/etc/etc without the api subdomain, causing 403s when the APIs are run.

How?

  • Introduces a SITES runtime tuple in packages/core/src/constants.ts as the
    single source of truth (matches the existing ALL_ENVS / SUPPORTED_BUNDLERS
    pattern).
  • Derives the Sites type from SITES so type and runtime stay in lockstep.
  • Validates auth.site and DATADOG_SITE / DD_SITE in validateOptions and
    throws a clear error pointing at
    https://docs.datadoghq.com/getting_started/site/ when an unsupported value
    is provided.
  • Renames the test helper FAKE_SITE -> DEFAULT_SITE (now a real Sites value)
    and types defaultAuth as AuthOptionsWithDefaults so test fixtures match
    the tightened contract.

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

Previously AuthOptions.site was string, which let typos flow silently into
Datadog intake URLs. This change:

- Introduces a SITES runtime tuple in packages/core/src/constants.ts as the
  single source of truth (matches the existing ALL_ENVS / SUPPORTED_BUNDLERS
  pattern).
- Derives the Sites type from SITES so type and runtime stay in lockstep.
- Validates auth.site and DATADOG_SITE / DD_SITE in validateOptions and
  throws a clear error pointing at
  https://docs.datadoghq.com/getting_started/site/ when an unsupported value
  is provided.
- Renames the test helper FAKE_SITE -> DEFAULT_SITE (now a real Sites value)
  and types defaultAuth as AuthOptionsWithDefaults so test fixtures match
  the tightened contract.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@oliverli oliverli requested review from a team and yoannmoinet as code owners May 15, 2026 20:20
Copy link
Copy Markdown
Collaborator Author

oliverli commented May 15, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7971543423

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/constants.ts
@datadog-official
Copy link
Copy Markdown

datadog-official Bot commented May 15, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 604b9e4 | Docs | Datadog PR Page | Give us feedback!

oliverli and others added 2 commits May 15, 2026 16:27
Two assertions in packages/plugins/apps/src/index.test.ts hardcoded the
prior FAKE_SITE value ('example.com'): the uploader.uploadArchive
expectation and the nock intake host. Both now reference DEFAULT_SITE
(imported from the test mocks helper) so the test tracks the helper
rather than the literal value.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Update both the generated full-configuration block (via the readme
integrity template) and the auth.site prose section:

- The type signature now shows site?: Sites instead of site?: string.
- The prose lists all 8 documented Datadog sites explicitly (dropping
  the trailing "etc.") and calls out that invalid values now throw at
  plugin initialization.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread packages/core/src/types.ts Outdated
Comment thread packages/factory/src/validate.ts Outdated
Comment thread packages/tests/src/_jest/helpers/mocks.ts Outdated
- Rename the Sites type to Site (singular) everywhere it's used —
  auth.site, isSite typeguard, factory validation. The README's
  generated config block now shows site?: Site.
- Move DEFAULT_SITE from packages/tests/_jest/helpers/mocks.ts to
  packages/core/src/constants.ts (derived from SITES[0]) so the
  factory's fallback and the test fixture share one source of truth.
  Tests that referenced DEFAULT_SITE now import from @dd/core/constants.
- Collapse validateAuth + the post-validation re-narrow into a single
  resolveSite helper that both validates and narrows
  string | undefined -> Site | undefined. Drop the
  (SITES as readonly string[]) cast in isSite in favor of .some().
- Skip auth.site validation entirely when DATADOG_SITE / DD_SITE is set,
  via short-circuit in the envSite ?? resolveSite(...) chain, so a
  stale auth.site can't block a build that has opted into an env
  override.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@oliverli oliverli requested a review from yoannmoinet May 15, 2026 21:00
Comment thread README.md Outdated
Co-authored-by: Yoann Moinet <597828+yoannmoinet@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants