Skip to content

fix: derive Amplitude server URL from host#173

Merged
angeloashmore merged 1 commit intomainfrom
aa/fix-amplitude-server-url
May 5, 2026
Merged

fix: derive Amplitude server URL from host#173
angeloashmore merged 1 commit intomainfrom
aa/fix-amplitude-server-url

Conversation

@angeloashmore
Copy link
Copy Markdown
Member

@angeloashmore angeloashmore commented May 4, 2026

Resolves: https://prismic-team.slack.com/archives/C02L3FN3AJK/p1777913609468359?thread_ts=1777913489.898219&cid=C02L3FN3AJK

Description

The Amplitude server and API key were picked from the build-time env.PROD flag, so users on hosts other than the one matching the build hit the wrong Amplitude environment (or one they can't reach at all). Pick them from the user's configured host instead.

Also handle unexpected network failures from the request helper so a flag lookup can't crash the CLI.

Checklist

  • A comprehensive Linear ticket, providing sufficient context and details to facilitate the review of the PR, is linked to the PR.
  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

Preview

How to QA 1


View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

Note

Medium Risk
Moderate risk because it changes how feature-flag/variant data is fetched (new host-based routing and API keys) and adds new handling for unexpected request failures, which can affect CLI behavior in network-error scenarios.

Overview
Fixes Amplitude flag fetching to be host-aware. Replaces the build-time env.PROD selection with a new getVariantData() client that derives the Amplitude base URL (https://amplitude.${host}/) and API key from the user’s configured host (supports prismic.io and wroom.io).

Hardens CLI error handling. The Type Builder enablement check now reads the dev-tools-types-builder-cloud value from returned variant data, and the CLI catches UnknownRequestError to print a sanitized “network request failed unexpectedly” message (removing query params) instead of crashing.

Reviewed by Cursor Bugbot for commit 0f52048. Bugbot is set up for automated code reviews on this repo. Configure here.

Footnotes

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment.

Pick the Amplitude server and API key based on the user's configured
host instead of the build-time env.PROD flag, and gracefully handle
unexpected network failures so a flag lookup can't crash the CLI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0f52048. Configure here.

Comment thread src/clients/amplitude.ts
throw new Error(
`The Amplitude service is only supported in: ${DEFAULT_PRISMIC_HOST}, ${WROOM_PRISMIC_HOST}`,
);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unsupported host throws unhandled error, crashing the CLI

Medium Severity

getAmplitudeApiKey throws a plain Error for any host other than prismic.io or wroom.io. This error is not caught in checkIsTypeBuilderEnabled, and no handler in the index.ts error chain matches a generic Error, so it falls through to the catch-all that re-throws — crashing the CLI. The PR description states that "a flag lookup can't crash the CLI," but this introduces a new crash path for users on custom hosts (set via PRISMIC_HOST env or stored credentials). The old code always selected one of two API keys based on env.PROD and never threw.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0f52048. Configure here.

Copy link
Copy Markdown
Contributor

@jomifepe jomifepe left a comment

Choose a reason for hiding this comment

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

LGTM 💯

@angeloashmore angeloashmore merged commit cc6f2d7 into main May 5, 2026
13 checks passed
@angeloashmore angeloashmore deleted the aa/fix-amplitude-server-url branch May 5, 2026 18:08
@github-actions github-actions Bot mentioned this pull request May 5, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants