@cloudflare/deploy-helpers 0.29.0 → 0.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -154,8 +154,15 @@ declare function getWorkersDevSubdomain(complianceConfig: ComplianceConfig, acco
154
154
  * optional and the Worker-scoped API can validate the requested operation.
155
155
  */
156
156
  declare function getWorkersDevSubdomainIfAccessible(complianceConfig: ComplianceConfig, accountId: string, options?: GetWorkersDevSubdomainOptions): Promise<string | undefined>;
157
- /** Gets the Worker-scoped subdomain configuration and routable URLs. */
158
- declare function getWorkerSubdomain(complianceConfig: ComplianceConfig, accountId: string, workerName: string): Promise<WorkerSubdomain>;
157
+ /**
158
+ * Gets the Worker-scoped subdomain configuration and routable URLs.
159
+ *
160
+ * @param options - Allow the script subdomain fallback after a successful first upload,
161
+ * when the Worker resource may not yet be readable.
162
+ */
163
+ declare function getWorkerSubdomain(complianceConfig: ComplianceConfig, accountId: string, workerName: string, options?: {
164
+ fallbackToScriptOnNotFound?: boolean;
165
+ }): Promise<WorkerSubdomain>;
159
166
  //#endregion
160
167
  //#region src/triggers/zones.d.ts
161
168
  interface Zone {
@@ -794,10 +801,10 @@ declare function fetchWorkerConfig(complianceConfig: ComplianceConfig, accountId
794
801
  environment: string;
795
802
  created_on: string;
796
803
  modified_on: string;
797
- script: {
804
+ script?: {
798
805
  id: string;
799
806
  tag: string;
800
- tags: string[];
807
+ tags: string[] | null;
801
808
  etag: string;
802
809
  handlers: string[];
803
810
  modified_on: string;
@@ -814,7 +821,7 @@ declare function fetchWorkerConfig(complianceConfig: ComplianceConfig, accountId
814
821
  placement_mode?: "smart";
815
822
  tail_consumers?: import("@cloudflare/workers-utils/config").TailConsumer[];
816
823
  observability?: import("@cloudflare/workers-utils/config").Observability;
817
- };
824
+ } | null;
818
825
  };
819
826
  cronTriggers: CronTriggersRes;
820
827
  }>;
package/dist/index.mjs CHANGED
@@ -2647,11 +2647,14 @@ const RESET_CATCH_ALL_BODY = {
2647
2647
  /** Resolve the deployed Worker's stable public tag (used as owner_worker_tag). */
2648
2648
  async function resolveOwnerWorkerTag(config, accountId, scriptName) {
2649
2649
  const deadline = Date.now() + PLAN_RETRY_TIMEOUT_MS;
2650
- for (;;) try {
2651
- const { default_environment } = await fetchResult(config, `/accounts/${accountId}/workers/services/${scriptName}`);
2652
- return default_environment.script.tag;
2653
- } catch (error) {
2654
- if (!isWorkerNotFoundError(error)) throw error;
2650
+ for (;;) {
2651
+ try {
2652
+ const { default_environment } = await fetchResult(config, `/accounts/${accountId}/workers/services/${scriptName}`);
2653
+ const tag = default_environment.script?.tag;
2654
+ if (tag) return tag;
2655
+ } catch (error) {
2656
+ if (!isWorkerNotFoundError(error)) throw error;
2657
+ }
2655
2658
  if (Date.now() + PLAN_RETRY_DELAY_MS >= deadline) throw new UserError("Email Routing could not find the deployed Worker yet. Re-run the deployment.", { telemetryMessage: "email routing worker metadata not found" });
2656
2659
  await new Promise((resolve) => setTimeout(resolve, PLAN_RETRY_DELAY_MS));
2657
2660
  }
@@ -3154,13 +3157,24 @@ async function getWorkersDevSubdomainIfAccessible(complianceConfig, accountId, o
3154
3157
  const result = await getWorkersDevSubdomainInternal(complianceConfig, accountId, options);
3155
3158
  return "unauthorizedError" in result ? void 0 : result.subdomain;
3156
3159
  }
3157
- /** Gets the Worker-scoped subdomain configuration and routable URLs. */
3158
- async function getWorkerSubdomain(complianceConfig, accountId, workerName) {
3159
- const worker = await retryOnAPIFailure(() => fetchResult(complianceConfig, `/accounts/${accountId}/workers/workers/${workerName}`), logger);
3160
+ /**
3161
+ * Gets the Worker-scoped subdomain configuration and routable URLs.
3162
+ *
3163
+ * @param options - Allow the script subdomain fallback after a successful first upload,
3164
+ * when the Worker resource may not yet be readable.
3165
+ */
3166
+ async function getWorkerSubdomain(complianceConfig, accountId, workerName, options = {}) {
3167
+ let subdomain;
3168
+ try {
3169
+ subdomain = (await retryOnAPIFailure(() => fetchResult(complianceConfig, `/accounts/${accountId}/workers/workers/${workerName}`), logger)).subdomain;
3170
+ } catch (error) {
3171
+ if (!options.fallbackToScriptOnNotFound || !(error instanceof APIError) || error.status !== 404 || error.code !== 10007) throw error;
3172
+ subdomain = await retryOnAPIFailure(() => fetchResult(complianceConfig, `/accounts/${accountId}/workers/scripts/${workerName}/subdomain`), logger);
3173
+ }
3160
3174
  return {
3161
- ...worker.subdomain,
3162
- enabled: worker.subdomain.enabled ?? false,
3163
- previews_enabled: worker.subdomain.previews_enabled ?? false
3175
+ ...subdomain,
3176
+ enabled: subdomain.enabled ?? false,
3177
+ previews_enabled: subdomain.previews_enabled ?? false
3164
3178
  };
3165
3179
  }
3166
3180
  function getRegistrationWarning(registrationContext) {
@@ -3666,7 +3680,7 @@ async function subdomainDeploy(props, accountId, scriptName, workerUrl, routes,
3666
3680
  const { config } = props;
3667
3681
  const displayConfigFileName = configFileName(config.configPath, config.userConfigPath);
3668
3682
  const { workers_dev: wantWorkersDev, preview_urls: wantPreviews } = getSubdomainValues(config.workers_dev, config.preview_urls, routes);
3669
- const before = await getWorkerSubdomain(config, accountId, scriptName);
3683
+ const before = await getWorkerSubdomain(config, accountId, scriptName, { fallbackToScriptOnNotFound: firstDeploy });
3670
3684
  if (wantWorkersDev) {
3671
3685
  const workersDevHostname = before.url ? new URL(before.url).hostname : `${scriptName}.${await getWorkersDevSubdomain(config, accountId, { configPath: config.configPath })}`;
3672
3686
  deployments.push(Promise.resolve({ targets: [workersDevHostname] }));
@@ -6255,7 +6269,7 @@ async function getMigrationsToUpload(scriptName, props) {
6255
6269
  suppressNotFoundError(err);
6256
6270
  }
6257
6271
  else try {
6258
- script = (await fetchResult(config, `/accounts/${accountId}/workers/services/${scriptName}`)).default_environment.script;
6272
+ script = (await fetchResult(config, `/accounts/${accountId}/workers/services/${scriptName}`)).default_environment.script ?? void 0;
6259
6273
  } catch (err) {
6260
6274
  suppressNotFoundError(err);
6261
6275
  }
@@ -13956,22 +13970,24 @@ async function fetchWorkerConfig(complianceConfig, accountId, workerName, enviro
13956
13970
  */
13957
13971
  async function downloadWorkerConfig(complianceConfig, workerName, environment, entrypoint, accountId, fetchRoutes, fetchCustomDomains) {
13958
13972
  const { bindings, routes, customDomains, subdomainStatus, serviceEnvMetadata, cronTriggers } = await fetchWorkerConfig(complianceConfig, accountId, workerName, environment, fetchRoutes, fetchCustomDomains);
13973
+ const { script } = serviceEnvMetadata;
13974
+ if (!script) throw new UserError(`Cannot download configuration for Worker "${workerName}" because it has no uploaded script. Deploy the Worker first.`, { telemetryMessage: "worker config download script missing" });
13959
13975
  return constructWranglerConfig({
13960
13976
  name: workerName,
13961
13977
  entrypoint,
13962
- compatibility_date: serviceEnvMetadata.script.compatibility_date,
13963
- compatibility_flags: serviceEnvMetadata.script.compatibility_flags,
13964
- tags: serviceEnvMetadata.script.tags,
13965
- migration_tag: serviceEnvMetadata.script.migration_tag,
13966
- tail_consumers: serviceEnvMetadata.script.tail_consumers,
13967
- observability: serviceEnvMetadata.script.observability,
13968
- limits: serviceEnvMetadata.script.limits,
13978
+ compatibility_date: script.compatibility_date,
13979
+ compatibility_flags: script.compatibility_flags,
13980
+ tags: script.tags,
13981
+ migration_tag: script.migration_tag,
13982
+ tail_consumers: script.tail_consumers,
13983
+ observability: script.observability,
13984
+ limits: script.limits,
13969
13985
  bindings,
13970
13986
  routes,
13971
13987
  domains: customDomains,
13972
13988
  subdomain: subdomainStatus,
13973
13989
  schedules: cronTriggers.schedules.map((s) => ({ cron: s.cron })),
13974
- placement: serviceEnvMetadata.script.placement_mode ? { mode: serviceEnvMetadata.script.placement_mode } : void 0,
13990
+ placement: script.placement_mode ? { mode: script.placement_mode } : void 0,
13975
13991
  logpush: void 0
13976
13992
  });
13977
13993
  }
@@ -13990,16 +14006,14 @@ async function verifyWorkerMatchesCITag(complianceConfig, accountId, workerName,
13990
14006
  }
13991
14007
  const envAccountID = getCloudflareAccountIdFromEnv();
13992
14008
  if (accountId !== envAccountID) throw new FatalError(`The \`account_id\` in your ${configFileName(configPath)} file must match the \`account_id\` for this account. Please update your ${configFileName(configPath)} file with \`${formatConfigSnippet({ account_id: envAccountID }, configPath, false)}\``, { telemetryMessage: "ci match tag account mismatch" });
13993
- let tag;
13994
- try {
13995
- tag = (await fetchResult(complianceConfig, `/accounts/${accountId}/workers/services/${workerName}`)).default_environment.script.tag;
13996
- logger.debug(`API returned with tag: ${tag} for worker: ${workerName}`);
13997
- } catch (e) {
14009
+ const tag = (await fetchResult(complianceConfig, `/accounts/${accountId}/workers/services/${workerName}`).catch((e) => {
13998
14010
  logger.debug(e);
13999
- if (isWorkerNotFoundError(e)) throw new FatalError(`The Worker "${workerName}" was not found in your account. Check that the name in your ${configFileName(configPath)} file is correct and that the Worker exists in this account.`, { telemetryMessage: "ci match tag worker not found" });
14000
- else if (e instanceof APIError) throw new FatalError("An error occurred while trying to validate that the Worker name matches what is expected by the build system.\n" + e.message + "\n" + e.notes.map((note) => note.text).join("\n"), { telemetryMessage: "ci match tag validation api error" });
14001
- else throw new FatalError("The Worker name could not be validated against what is expected by the build system. Please retry the build. If the problem persists, please contact support.", { telemetryMessage: "ci match tag validation failed" });
14002
- }
14011
+ if (isWorkerNotFoundError(e)) return;
14012
+ if (e instanceof APIError) throw new FatalError("An error occurred while trying to validate that the Worker name matches what is expected by the build system.\n" + e.message + "\n" + e.notes.map((note) => note.text).join("\n"), { telemetryMessage: "ci match tag validation api error" });
14013
+ throw new FatalError("The Worker name could not be validated against what is expected by the build system. Please retry the build. If the problem persists, please contact support.", { telemetryMessage: "ci match tag validation failed" });
14014
+ }))?.default_environment.script?.tag;
14015
+ if (!tag) throw new FatalError(`The Worker "${workerName}" was not found in your account. Check that the name in your ${configFileName(configPath)} file is correct and that the Worker exists in this account.`, { telemetryMessage: "ci match tag worker not found" });
14016
+ logger.debug(`API returned with tag: ${tag} for worker: ${workerName}`);
14003
14017
  if (tag !== matchTag) {
14004
14018
  logger.debug(`Failed to match Worker tag. The API returned "${tag}", but the CI system expected "${matchTag}"`);
14005
14019
  throw new FatalError(`The name in your ${configFileName(configPath)} file (${workerName}) must match the name of your Worker. Please update the name field in your ${configFileName(configPath)} file.`, { telemetryMessage: "ci match tag tag mismatch" });
@@ -14160,50 +14174,54 @@ async function preUploadApiChecks(props, config, queueCreateCommand) {
14160
14174
  if (typeof e === "object" && e !== null && "code" in e && e.code === 10092) workerExists = false;
14161
14175
  else throw e;
14162
14176
  }
14163
- else try {
14164
- const serviceMetaData = await fetchResult(config, `/accounts/${accountId}/workers/services/${name}`);
14165
- const { default_environment: { script } } = serviceMetaData;
14166
- workerTag = script.tag;
14167
- tags = script.tags ?? tags;
14168
- if (props.command === "deploy" && props.failIfWorkerNameTaken) throw new UserError(`A Worker named "${name}" already exists in your account. This deploy could not confirm that it should update that Worker, so it stopped instead of overwriting it. To update the existing Worker, add a ${configFileName(config.configPath, config.userConfigPath)} that names "${name}"; to deploy separately, use a different name.`, { telemetryMessage: "deploy unverified worker name already exists" });
14169
- if (script.last_deployed_from === "dash") {
14170
- const { routesOnly, customDomainsOnly } = partitionRoutes(props.command === "deploy" ? props.routes : []);
14171
- const configDiff = getRemoteConfigDiff(await downloadWorkerConfig(config, name, serviceMetaData.default_environment.environment, props.entry.file, accountId, routesOnly.length > 0, customDomainsOnly.length > 0), props.command === "deploy" ? {
14172
- ...config,
14173
- routes: props.routes
14174
- } : config);
14175
- if (!configDiff.nonDestructive) {
14176
- logger.warn(`The local configuration being used (generated from your local configuration file) differs from the remote configuration of your Worker set via the Cloudflare Dashboard:\n${configDiff.diff}\n\nUploading the Worker will override the remote configuration with your local one.`);
14177
- if (!await deployConfirm("Would you like to continue?")) {
14178
- if (config.userConfigPath && /\.jsonc?$/.test(config.userConfigPath) && !(props.strict && isNonInteractiveOrCI()) && await confirm("Would you like to update the local config file with the remote values?", {
14179
- defaultValue: true,
14180
- fallbackValue: true
14181
- })) {
14182
- const patchObj = getConfigPatch(configDiff.diff, props.env);
14183
- experimental_patchConfig(config.userConfigPath, patchObj, false);
14177
+ else {
14178
+ try {
14179
+ const serviceMetaData = await fetchResult(config, `/accounts/${accountId}/workers/services/${name}`);
14180
+ const { default_environment: { script } } = serviceMetaData;
14181
+ workerExists = Boolean(script);
14182
+ if (script) {
14183
+ workerTag = script.tag;
14184
+ tags = script.tags ?? tags;
14185
+ }
14186
+ if (props.command === "deploy" && props.failIfWorkerNameTaken) throw new UserError(`A Worker named "${name}" already exists in your account. This deploy could not confirm that it should update that Worker, so it stopped instead of overwriting it. To update the existing Worker, add a ${configFileName(config.configPath, config.userConfigPath)} that names "${name}"; to deploy separately, use a different name.`, { telemetryMessage: "deploy unverified worker name already exists" });
14187
+ if (script?.last_deployed_from === "dash") {
14188
+ const { routesOnly, customDomainsOnly } = partitionRoutes(props.command === "deploy" ? props.routes : []);
14189
+ const configDiff = getRemoteConfigDiff(await downloadWorkerConfig(config, name, serviceMetaData.default_environment.environment, props.entry.file, accountId, routesOnly.length > 0, customDomainsOnly.length > 0), props.command === "deploy" ? {
14190
+ ...config,
14191
+ routes: props.routes
14192
+ } : config);
14193
+ if (!configDiff.nonDestructive) {
14194
+ logger.warn(`The local configuration being used (generated from your local configuration file) differs from the remote configuration of your Worker set via the Cloudflare Dashboard:\n${configDiff.diff}\n\nUploading the Worker will override the remote configuration with your local one.`);
14195
+ if (!await deployConfirm("Would you like to continue?")) {
14196
+ if (config.userConfigPath && /\.jsonc?$/.test(config.userConfigPath) && !(props.strict && isNonInteractiveOrCI()) && await confirm("Would you like to update the local config file with the remote values?", {
14197
+ defaultValue: true,
14198
+ fallbackValue: true
14199
+ })) {
14200
+ const patchObj = getConfigPatch(configDiff.diff, props.env);
14201
+ experimental_patchConfig(config.userConfigPath, patchObj, false);
14202
+ }
14203
+ return {
14204
+ workerTag,
14205
+ tags,
14206
+ workerExists,
14207
+ aborted: true
14208
+ };
14184
14209
  }
14185
- return {
14186
- workerTag,
14187
- tags,
14188
- workerExists,
14189
- aborted: true
14190
- };
14191
14210
  }
14211
+ } else if (script?.last_deployed_from === "api") {
14212
+ logger.warn(`You are about to upload a Worker that was last updated via the script API.\nEdits that have been made via the script API will be overridden by your local code and config.`);
14213
+ if (!await deployConfirm("Would you like to continue?")) return {
14214
+ workerTag,
14215
+ tags,
14216
+ workerExists,
14217
+ aborted: true
14218
+ };
14192
14219
  }
14193
- } else if (script.last_deployed_from === "api") {
14194
- logger.warn(`You are about to upload a Worker that was last updated via the script API.\nEdits that have been made via the script API will be overridden by your local code and config.`);
14195
- if (!await deployConfirm("Would you like to continue?")) return {
14196
- workerTag,
14197
- tags,
14198
- workerExists,
14199
- aborted: true
14200
- };
14201
- }
14202
- } catch (e) {
14203
- if (isWorkerNotFoundError(e)) {
14204
- if (props.command === "versions upload") throw new UserError("You cannot upload a new version of a Worker that does not yet exist. Please run the `deploy` command first.", { telemetryMessage: "versions upload worker not found" });
14220
+ } catch (e) {
14221
+ if (!isWorkerNotFoundError(e)) throw e;
14205
14222
  workerExists = false;
14206
- } else throw e;
14223
+ }
14224
+ if (!workerExists && props.command === "versions upload") throw new UserError("You cannot upload a new version of a Worker that does not yet exist. Please run the `deploy` command first.", { telemetryMessage: "versions upload worker not found" });
14207
14225
  }
14208
14226
  const remoteSecretsCheck = await checkRemoteSecretsOverride(config, name, accountId);
14209
14227
  if (remoteSecretsCheck?.override) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/deploy-helpers",
3
- "version": "0.29.0",
3
+ "version": "0.29.1",
4
4
  "description": "Internal deploy helpers for workers-sdk. Not intended for external use — APIs may change without notice.",
5
5
  "homepage": "https://github.com/cloudflare/workers-sdk/tree/main/packages/deploy-helpers#readme",
6
6
  "bugs": {
@@ -44,14 +44,14 @@
44
44
  "pretty-bytes": "6.1.1",
45
45
  "undici": "7.30.2",
46
46
  "ws": "8.21.0",
47
- "@cloudflare/cli-shared-helpers": "0.3.12",
48
- "@cloudflare/config": "1.0.0-rc.3",
49
- "@cloudflare/containers-shared": "0.27.1",
50
- "@cloudflare/workers-utils": "0.56.0",
51
- "miniflare": "5.20261119.0-beta"
47
+ "@cloudflare/cli-shared-helpers": "0.3.13",
48
+ "@cloudflare/config": "1.0.0-rc.4",
49
+ "@cloudflare/containers-shared": "0.27.2",
50
+ "@cloudflare/workers-utils": "0.57.0",
51
+ "miniflare": "5.20261123.0-beta"
52
52
  },
53
53
  "devDependencies": {
54
- "@cloudflare/workers-types": "^5.20261119.1",
54
+ "@cloudflare/workers-types": "^5.20261123.1",
55
55
  "@cspotcode/source-map-support": "0.8.1",
56
56
  "@types/command-exists": "^1.2.0",
57
57
  "@types/json-diff": "^1.0.3",