fix: derive Amplitude server URL from host#173
Conversation
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>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
| throw new Error( | ||
| `The Amplitude service is only supported in: ${DEFAULT_PRISMIC_HOST}, ${WROOM_PRISMIC_HOST}`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit 0f52048. Configure here.


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.PRODflag, 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
Preview
How to QA 1
Need help on this PR? Tag
@codesmithwith what you need.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.PRODselection with a newgetVariantData()client that derives the Amplitude base URL (https://amplitude.${host}/) and API key from the user’s configuredhost(supportsprismic.ioandwroom.io).Hardens CLI error handling. The Type Builder enablement check now reads the
dev-tools-types-builder-cloudvalue from returned variant data, and the CLI catchesUnknownRequestErrorto 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
Please use these labels when submitting a review:
⚠️ #issue: Strongly suggest a change.
❓ #ask: Ask a question.
💡 #idea: Suggest an idea.
🎉 #nice: Share a compliment. ↩