@cloudflare/deploy-helpers 0.14.0 → 0.14.2

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.
@@ -2,6 +2,7 @@ import { __name } from './chunk-Q72B4Q5Z.mjs';
2
2
 
3
3
  // src/shared/context.ts
4
4
  var logger;
5
+ var createCloudflareClient;
5
6
  var fetchResult;
6
7
  var fetchListResult;
7
8
  var fetchPagedListResult;
@@ -11,6 +12,7 @@ var prompt;
11
12
  var select;
12
13
  function initDeployHelpersContext(ctx) {
13
14
  logger = ctx.logger;
15
+ createCloudflareClient = ctx.createCloudflareClient;
14
16
  fetchResult = ctx.fetchResult;
15
17
  fetchListResult = ctx.fetchListResult;
16
18
  fetchPagedListResult = ctx.fetchPagedListResult;
@@ -21,4 +23,4 @@ function initDeployHelpersContext(ctx) {
21
23
  }
22
24
  __name(initDeployHelpersContext, "initDeployHelpersContext");
23
25
 
24
- export { confirm, fetchKVGetValue, fetchListResult, fetchPagedListResult, fetchResult, initDeployHelpersContext, logger, prompt, select };
26
+ export { confirm, createCloudflareClient, fetchKVGetValue, fetchListResult, fetchPagedListResult, fetchResult, initDeployHelpersContext, logger, prompt, select };
@@ -1,11 +1,13 @@
1
1
  import { BuiltImage, ContainerNormalizedConfig, BuiltContainerImage } from '@cloudflare/containers-shared';
2
- import { ContainerApp, Config, FetchResultFetcher, FetchListResultFetcher, FetchPagedListResultFetcher, FetchKVGetValueFetcher, Logger, Entry, ValidatedAssetsOptions, LegacyAssetPaths, Route, CfModule, CfWorkerSourceMap, CfModuleType } from '@cloudflare/workers-utils';
2
+ import { ContainerApp, Config, ComplianceConfig, FetchResultFetcher, FetchListResultFetcher, FetchPagedListResultFetcher, FetchKVGetValueFetcher, Logger, Entry, ValidatedAssetsOptions, LegacyAssetPaths, Route, CfModule, CfWorkerSourceMap, CfModuleType } from '@cloudflare/workers-utils';
3
+ import Cloudflare from 'cloudflare';
3
4
 
4
5
  /**
5
6
  * client needs to handle logger and fetch/auth implementation
6
7
  * these are passed into this package to handle any API requests/logs
7
8
  */
8
9
  type DeployHelpersContext = {
10
+ createCloudflareClient: (complianceConfig: ComplianceConfig) => Cloudflare;
9
11
  fetchResult: FetchResultFetcher;
10
12
  fetchListResult: FetchListResultFetcher;
11
13
  fetchPagedListResult: FetchPagedListResultFetcher;
@@ -189,6 +191,7 @@ type TriggerProps = {
189
191
  * const { logger } = await import("./context"); // WRONG: captures undefined
190
192
  */
191
193
  declare let logger: Logger;
194
+ declare let createCloudflareClient: DeployHelpersContext["createCloudflareClient"];
192
195
  declare let fetchResult: FetchResultFetcher;
193
196
  declare let fetchListResult: FetchListResultFetcher;
194
197
  declare let fetchPagedListResult: FetchPagedListResultFetcher;
@@ -202,4 +205,4 @@ declare let select: DeployHelpersContext["select"];
202
205
  */
203
206
  declare function initDeployHelpersContext(ctx: DeployHelpersContext): void;
204
207
 
205
- export { type BuiltDurableObjectContainerImage as B, type ContainerlessConfig as C, type DeployProps as D, type SharedDeployVersionsProps as S, type TriggerProps as T, type VersionsUploadProps as V, type WorkerBuildResult as W, type TriggerDeployment as a, type ContainerDeployConfig as b, type DeployHelpersContext as c, confirm as d, fetchListResult as e, fetchKVGetValue as f, fetchPagedListResult as g, fetchResult as h, initDeployHelpersContext as i, logger as l, prompt as p, select as s };
208
+ export { type BuiltDurableObjectContainerImage as B, type ContainerlessConfig as C, type DeployProps as D, type SharedDeployVersionsProps as S, type TriggerProps as T, type VersionsUploadProps as V, type WorkerBuildResult as W, type TriggerDeployment as a, type ContainerDeployConfig as b, type DeployHelpersContext as c, confirm as d, createCloudflareClient as e, fetchKVGetValue as f, fetchListResult as g, fetchPagedListResult as h, initDeployHelpersContext as i, fetchResult as j, logger as l, prompt as p, select as s };
@@ -1,3 +1,4 @@
1
- export { d as confirm, f as fetchKVGetValue, e as fetchListResult, g as fetchPagedListResult, h as fetchResult, i as initDeployHelpersContext, l as logger, p as prompt, s as select } from './context-CruwKULH.mjs';
1
+ export { d as confirm, e as createCloudflareClient, f as fetchKVGetValue, g as fetchListResult, h as fetchPagedListResult, j as fetchResult, i as initDeployHelpersContext, l as logger, p as prompt, s as select } from './context-B7aozQRl.mjs';
2
2
  import '@cloudflare/workers-utils';
3
3
  import '@cloudflare/containers-shared';
4
+ import 'cloudflare';
package/dist/context.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export { confirm, fetchKVGetValue, fetchListResult, fetchPagedListResult, fetchResult, initDeployHelpersContext, logger, prompt, select } from './chunk-Z4LB73IF.mjs';
1
+ export { confirm, createCloudflareClient, fetchKVGetValue, fetchListResult, fetchPagedListResult, fetchResult, initDeployHelpersContext, logger, prompt, select } from './chunk-BH7NP23L.mjs';
2
2
  import './chunk-Q72B4Q5Z.mjs';
package/dist/index.d.mts CHANGED
@@ -1,14 +1,16 @@
1
- import { S as SharedDeployVersionsProps, D as DeployProps, C as ContainerlessConfig, W as WorkerBuildResult, V as VersionsUploadProps, T as TriggerProps, a as TriggerDeployment, B as BuiltDurableObjectContainerImage } from './context-CruwKULH.mjs';
2
- export { b as ContainerDeployConfig, c as DeployHelpersContext, i as initDeployHelpersContext } from './context-CruwKULH.mjs';
1
+ import { S as SharedDeployVersionsProps, D as DeployProps, C as ContainerlessConfig, W as WorkerBuildResult, V as VersionsUploadProps, T as TriggerProps, a as TriggerDeployment, B as BuiltDurableObjectContainerImage } from './context-B7aozQRl.mjs';
2
+ export { b as ContainerDeployConfig, c as DeployHelpersContext, i as initDeployHelpersContext } from './context-B7aozQRl.mjs';
3
3
  import * as _cloudflare_workers_utils from '@cloudflare/workers-utils';
4
4
  import { CfModule, Config, AssetsOptions, ComplianceConfig, LegacyAssetPaths, Route, ZoneIdRoute, ZoneNameRoute, CustomDomainRoute, CfPlacement, Binding as Binding$1, RawConfig, CfCapnp, CfScriptFormat, ParseError, WorkerMetadataBinding, CfUserLimits, CfWorkerInit, TailConsumer, StreamingTailConsumer, Observability, ResolvedDurableObjectContainerApp, DurableObjectContainerApp, ExportsReconciliationErrorDetail, ExportsReconciliationResult, StartDevWorkerInput, Json, CacheOptions, PreviewsConfig } from '@cloudflare/workers-utils';
5
5
  import { FormData } from 'undici';
6
+ import { Worker } from 'cloudflare/resources/workers/beta/workers/workers';
6
7
  export { createWorkerUploadForm, fromMimeType, moduleTypeMimeType } from './create-worker-upload-form.mjs';
7
8
  import { Options } from '@cspotcode/source-map-support';
8
9
  import Protocol from 'devtools-protocol';
9
10
  import { NodeJSCompatMode } from 'miniflare';
10
11
  import { ParsedOutputWorkerConfig, ParsedOutputRootConfig } from '@cloudflare/config';
11
12
  import { ContainerNormalizedConfig } from '@cloudflare/containers-shared';
13
+ import 'cloudflare';
12
14
 
13
15
  interface BundleSize {
14
16
  size: number;
@@ -96,10 +98,27 @@ type GetWorkersDevSubdomainOptions = {
96
98
  configPath?: string | undefined;
97
99
  registrationContext?: WorkersDevSubdomainRegistrationContext | undefined;
98
100
  };
101
+ type WorkerSubdomain = Worker.Subdomain & {
102
+ enabled: boolean;
103
+ previews_enabled: boolean;
104
+ url?: string;
105
+ /** Includes the leading "-" separator. */
106
+ preview_url_suffix?: string;
107
+ };
99
108
  /**
100
109
  * Gets the <user-subdomain>.(fed.)workers.dev URL for the given account.
101
110
  */
102
111
  declare function getWorkersDevSubdomain(complianceConfig: ComplianceConfig, accountId: string, options?: GetWorkersDevSubdomainOptions): Promise<string>;
112
+ /**
113
+ * Gets the account's workers.dev hostname when the token can read it.
114
+ *
115
+ * Granular Worker tokens may manage a Worker without access to account-level
116
+ * subdomain metadata. Callers should use this helper only when the hostname is
117
+ * optional and the Worker-scoped API can validate the requested operation.
118
+ */
119
+ declare function getWorkersDevSubdomainIfAccessible(complianceConfig: ComplianceConfig, accountId: string, options?: GetWorkersDevSubdomainOptions): Promise<string | undefined>;
120
+ /** Gets the Worker-scoped subdomain configuration and routable URLs. */
121
+ declare function getWorkerSubdomain(complianceConfig: ComplianceConfig, accountId: string, workerName: string): Promise<WorkerSubdomain>;
103
122
 
104
123
  interface Zone {
105
124
  id: string;
@@ -941,7 +960,6 @@ interface PreviewResource {
941
960
  name: string;
942
961
  slug: string;
943
962
  urls?: string[];
944
- worker_name: string;
945
963
  tags?: string[];
946
964
  observability?: Observability;
947
965
  logpush?: boolean;
@@ -1274,4 +1292,4 @@ type DrawConnectedChildBoxOptions = {
1274
1292
  */
1275
1293
  declare function drawConnectedChildBox(contentLines: string[], options?: DrawConnectedChildBoxOptions): string;
1276
1294
 
1277
- export { ACTOR_BINDING_DEPENDS_ON_EXPORT_CODE, type ApiDeployment, type ApiVersion, type AssetManifest, type AssetUploadStats, type AssetsUploadResult, type Binding, BuiltDurableObjectContainerImage, type BulkInputNullableResult, type BulkInputResult, type BundleSize, type Consumer, type ConsumerSettings, ContainerlessConfig, type CreatePreviewDeploymentRequestParams, type CreatePreviewRequestParams, type CustomDomain, type CustomDomainChangeset, type DeployCallbacks, DeployProps, type DeploymentResource, type DurableObjectContainerApplication, EXPORTS_RECONCILIATION_ERROR_CODE, type EnvBindings, INCONSISTENT_EXPORTS_ACROSS_VERSIONS_CODE, INVALID_INHERIT_BINDING_CODE, type JsonLike, NO_ACTIVE_PREVIEW_URLS_MESSAGE, NoInputError, type NonVersionedScriptSettings, PREVIEW_DOMAIN_PROVISIONING_NOTE, type PackageDependency, type Percentage, type PostQueueBody, type PostQueueResponse, type PostTypedConsumerBody, type PreparedContainerImages, type PreviewArgs, type PreviewAssetsOptions, type PreviewBaseConfig, type PreviewBaseConfigPatch, type PreviewBuildOutput, type PreviewBuildOutputRootConfig, type PreviewCallbacks, type PreviewDeleteArgs, type PreviewDeploymentModule, type PreviewRequestOptions, type PreviewResource, type PreviewResult, type Producer, type ProvisionBindingsResult, type PullRequestMetadata, type PurgeQueueBody, type PurgeQueueResponse, type QueueJurisdiction, type QueueResponse, type QueueSettings, type RetrieveSourceMapFunction, type RouteObject, type ScriptReference, type Settings, SharedDeployVersionsProps, TriggerDeployment, TriggerProps, type TypedConsumerResponse, type UpdatePreviewRequestParams, type VersionCache, type VersionId, type VersionedDurableObjectContainerApplication, type VersionsUploadCallbacks, VersionsUploadProps, WORKER_LEGACY_ENVIRONMENT_NOT_FOUND_ERR_CODE, WORKER_NOT_FOUND_ERR_CODE, WORKFLOW_CRON_REQUIRES_PAID_PLAN_CODE, WORKFLOW_NOT_FOUND_CODE, WorkerBuildResult, type Workflow, type WorkflowConflict, type Zone, type ZoneIdCache, addRequiredSecretsInheritBindings, addWorkersSitesBindings, applyServiceAndEnvironmentTags, assemblePreviewScriptSettings, assertPreviewBuildOutputRootConfig, buildAssetManifest, checkRemoteSecretsOverride, checkWorkflowConflicts, collectPackageDependencies, confirmLatestDeploymentOverwrite, createDeployment, createDurableObjectContainerApplication, createPreview, createPreviewDeployment, createPreviewDeploymentForm, createPreviewParentWorker, createTruncatedAlias, decodeJwtPayload, deletePreview, deletePullConsumer, deleteWorkerConsumer, deploy, deployDurableObjectContainerApplications, deployVersionedDurableObjectContainerApplications, deployWfpUserWorker, diagnoseScriptSizeError, diagnoseStartupError, diffJsonObjects, downloadWorkerConfig, drawBox, drawConnectedChildBox, editPreview, ensureQueuesExistByConfig, extractBuildOutputBindings, extractConfigBindings, fetchDeployableVersions, fetchDeploymentVersions, fetchLatestDeployment, fetchLatestDeployments, fetchSecrets, fetchVersion, fetchVersions, fetchWorkerConfig, formatAlignedRows, formatBindings, formatNoActivePreviewUrlsMessage, generatePreviewAlias, getBindingValue, getBranchName, getCommitSha, getConfigPatch, getDeployConfirmFunction, getEdgeKvUploadConcurrency, getHeadCommitMessage, getHeadCommitRef, getMigrationsToUpload, getPreview, getPreviewBaseConfig, getPreviewDeployment, getPreviewOwnedContainerClassNames, getPullRequestMetadata, getQueue, getRemoteConfigDiff, getRepositoryUrl, getSettings, getSize, getSourceMappedStack, getSourceMappedString, getSubdomainValues, getSubdomainValuesAPIMock, getVersionedDurableObjectContainerApplications, getWorkersDevSubdomain, getZoneForRoute, getZoneIdFromHost, handleMissingSecretsError, handleUnsafeCapnp, hasDefinedEnvironments, hashFile, helpIfErrorIsSizeOrScriptStartup, isExportsReconciliationErrorDetails, isJwtExpired, isModifiedDiffValue, isNonDestructive, isWorkerNotFoundError, listConsumers, listQueues, maybeRetrieveFileSourceMap, padToVisibleWidth, parseBulkInputToObject, parseConfigPlacement, patchNonVersionedScriptSettings, patchPreviewBaseConfig, patchPreviewDeployment, postConsumer, prepareDurableObjectContainerApplications, preview, previewBuildOutput, previewContainerAppName, previewDelete, printBundleSize, printVersions, provisionBindings, publishCustomDomains, publishRoutes, putConsumer, putConsumerById, renderBindingDependsOnExportError, renderExportsReconciliationError, renderExportsReconciliationSuccess, renderInconsistentExportsAcrossVersionsError, renderRoute, resolveAssetOptions, resolveDoLifecyclePayload, resolveExportsUploadPayload, resolveVersionedDurableObjectContainerApplications, resolveWorkerName, sanitizeBranchName, shouldUseCIMetadataFallback, stripAnsi, syncAssets, tagsAreEqual, triggersDeploy, updateQueueConsumers, validateEventTriggerTargets, validateFileSecrets, validateImageLessContainerApplicationsForUpload, validateNodeCompatMode, validateRoutes, verifyWorkerMatchesCITag, versionsUpload, visibleLength, warnOnErrorUpdatingServiceAndEnvironmentTags, workerNotFoundErrorMessage };
1295
+ export { ACTOR_BINDING_DEPENDS_ON_EXPORT_CODE, type ApiDeployment, type ApiVersion, type AssetManifest, type AssetUploadStats, type AssetsUploadResult, type Binding, BuiltDurableObjectContainerImage, type BulkInputNullableResult, type BulkInputResult, type BundleSize, type Consumer, type ConsumerSettings, ContainerlessConfig, type CreatePreviewDeploymentRequestParams, type CreatePreviewRequestParams, type CustomDomain, type CustomDomainChangeset, type DeployCallbacks, DeployProps, type DeploymentResource, type DurableObjectContainerApplication, EXPORTS_RECONCILIATION_ERROR_CODE, type EnvBindings, INCONSISTENT_EXPORTS_ACROSS_VERSIONS_CODE, INVALID_INHERIT_BINDING_CODE, type JsonLike, NO_ACTIVE_PREVIEW_URLS_MESSAGE, NoInputError, type NonVersionedScriptSettings, PREVIEW_DOMAIN_PROVISIONING_NOTE, type PackageDependency, type Percentage, type PostQueueBody, type PostQueueResponse, type PostTypedConsumerBody, type PreparedContainerImages, type PreviewArgs, type PreviewAssetsOptions, type PreviewBaseConfig, type PreviewBaseConfigPatch, type PreviewBuildOutput, type PreviewBuildOutputRootConfig, type PreviewCallbacks, type PreviewDeleteArgs, type PreviewDeploymentModule, type PreviewRequestOptions, type PreviewResource, type PreviewResult, type Producer, type ProvisionBindingsResult, type PullRequestMetadata, type PurgeQueueBody, type PurgeQueueResponse, type QueueJurisdiction, type QueueResponse, type QueueSettings, type RetrieveSourceMapFunction, type RouteObject, type ScriptReference, type Settings, SharedDeployVersionsProps, TriggerDeployment, TriggerProps, type TypedConsumerResponse, type UpdatePreviewRequestParams, type VersionCache, type VersionId, type VersionedDurableObjectContainerApplication, type VersionsUploadCallbacks, VersionsUploadProps, WORKER_LEGACY_ENVIRONMENT_NOT_FOUND_ERR_CODE, WORKER_NOT_FOUND_ERR_CODE, WORKFLOW_CRON_REQUIRES_PAID_PLAN_CODE, WORKFLOW_NOT_FOUND_CODE, WorkerBuildResult, type WorkerSubdomain, type Workflow, type WorkflowConflict, type Zone, type ZoneIdCache, addRequiredSecretsInheritBindings, addWorkersSitesBindings, applyServiceAndEnvironmentTags, assemblePreviewScriptSettings, assertPreviewBuildOutputRootConfig, buildAssetManifest, checkRemoteSecretsOverride, checkWorkflowConflicts, collectPackageDependencies, confirmLatestDeploymentOverwrite, createDeployment, createDurableObjectContainerApplication, createPreview, createPreviewDeployment, createPreviewDeploymentForm, createPreviewParentWorker, createTruncatedAlias, decodeJwtPayload, deletePreview, deletePullConsumer, deleteWorkerConsumer, deploy, deployDurableObjectContainerApplications, deployVersionedDurableObjectContainerApplications, deployWfpUserWorker, diagnoseScriptSizeError, diagnoseStartupError, diffJsonObjects, downloadWorkerConfig, drawBox, drawConnectedChildBox, editPreview, ensureQueuesExistByConfig, extractBuildOutputBindings, extractConfigBindings, fetchDeployableVersions, fetchDeploymentVersions, fetchLatestDeployment, fetchLatestDeployments, fetchSecrets, fetchVersion, fetchVersions, fetchWorkerConfig, formatAlignedRows, formatBindings, formatNoActivePreviewUrlsMessage, generatePreviewAlias, getBindingValue, getBranchName, getCommitSha, getConfigPatch, getDeployConfirmFunction, getEdgeKvUploadConcurrency, getHeadCommitMessage, getHeadCommitRef, getMigrationsToUpload, getPreview, getPreviewBaseConfig, getPreviewDeployment, getPreviewOwnedContainerClassNames, getPullRequestMetadata, getQueue, getRemoteConfigDiff, getRepositoryUrl, getSettings, getSize, getSourceMappedStack, getSourceMappedString, getSubdomainValues, getSubdomainValuesAPIMock, getVersionedDurableObjectContainerApplications, getWorkerSubdomain, getWorkersDevSubdomain, getWorkersDevSubdomainIfAccessible, getZoneForRoute, getZoneIdFromHost, handleMissingSecretsError, handleUnsafeCapnp, hasDefinedEnvironments, hashFile, helpIfErrorIsSizeOrScriptStartup, isExportsReconciliationErrorDetails, isJwtExpired, isModifiedDiffValue, isNonDestructive, isWorkerNotFoundError, listConsumers, listQueues, maybeRetrieveFileSourceMap, padToVisibleWidth, parseBulkInputToObject, parseConfigPlacement, patchNonVersionedScriptSettings, patchPreviewBaseConfig, patchPreviewDeployment, postConsumer, prepareDurableObjectContainerApplications, preview, previewBuildOutput, previewContainerAppName, previewDelete, printBundleSize, printVersions, provisionBindings, publishCustomDomains, publishRoutes, putConsumer, putConsumerById, renderBindingDependsOnExportError, renderExportsReconciliationError, renderExportsReconciliationSuccess, renderInconsistentExportsAcrossVersionsError, renderRoute, resolveAssetOptions, resolveDoLifecyclePayload, resolveExportsUploadPayload, resolveVersionedDurableObjectContainerApplications, resolveWorkerName, sanitizeBranchName, shouldUseCIMetadataFallback, stripAnsi, syncAssets, tagsAreEqual, triggersDeploy, updateQueueConsumers, validateEventTriggerTargets, validateFileSecrets, validateImageLessContainerApplicationsForUpload, validateNodeCompatMode, validateRoutes, verifyWorkerMatchesCITag, versionsUpload, visibleLength, warnOnErrorUpdatingServiceAndEnvironmentTags, workerNotFoundErrorMessage };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { fetchResult, fetchPagedListResult, logger, confirm, fetchListResult, prompt, select } from './chunk-Z4LB73IF.mjs';
2
- export { initDeployHelpersContext } from './chunk-Z4LB73IF.mjs';
1
+ import { fetchResult, fetchPagedListResult, logger, confirm, fetchListResult, createCloudflareClient, prompt, select } from './chunk-BH7NP23L.mjs';
2
+ export { initDeployHelpersContext } from './chunk-BH7NP23L.mjs';
3
3
  import { createWorkerUploadForm, moduleTypeMimeType } from './chunk-QBZBEHZB.mjs';
4
4
  export { createWorkerUploadForm, fromMimeType, handleUnsafeCapnp, moduleTypeMimeType } from './chunk-QBZBEHZB.mjs';
5
5
  import { __commonJS, __name, __require, __toESM, __export } from './chunk-Q72B4Q5Z.mjs';
@@ -3759,6 +3759,18 @@ function toValidSubdomain(input) {
3759
3759
  }
3760
3760
  __name(toValidSubdomain, "toValidSubdomain");
3761
3761
  async function getWorkersDevSubdomain(complianceConfig, accountId, options = {}) {
3762
+ const result = await getWorkersDevSubdomainInternal(
3763
+ complianceConfig,
3764
+ accountId,
3765
+ options
3766
+ );
3767
+ if ("unauthorizedError" in result) {
3768
+ throw result.unauthorizedError;
3769
+ }
3770
+ return result.subdomain;
3771
+ }
3772
+ __name(getWorkersDevSubdomain, "getWorkersDevSubdomain");
3773
+ async function getWorkersDevSubdomainInternal(complianceConfig, accountId, options) {
3762
3774
  const {
3763
3775
  abortSignal,
3764
3776
  autoRegisterSubdomain,
@@ -3773,42 +3785,71 @@ async function getWorkersDevSubdomain(complianceConfig, accountId, options = {})
3773
3785
  void 0,
3774
3786
  abortSignal
3775
3787
  );
3776
- return `${subdomain}${getComplianceRegionSubdomain(complianceConfig)}.workers.dev`;
3788
+ return {
3789
+ subdomain: `${subdomain}${getComplianceRegionSubdomain(complianceConfig)}.workers.dev`
3790
+ };
3777
3791
  } catch (e) {
3792
+ if (e instanceof APIError && e.code === 1e4) {
3793
+ return { unauthorizedError: e };
3794
+ }
3778
3795
  const error51 = e;
3779
3796
  if (typeof error51 !== "object" || !error51 || error51.code !== 10007) {
3780
3797
  throw e;
3781
3798
  }
3782
- logger.warn(getRegistrationWarning(registrationContext));
3783
- if (autoRegisterSubdomain) {
3784
- return await registerSubdomain(
3799
+ }
3800
+ logger.warn(getRegistrationWarning(registrationContext));
3801
+ if (autoRegisterSubdomain) {
3802
+ return {
3803
+ subdomain: await registerSubdomain(
3785
3804
  complianceConfig,
3786
3805
  accountId,
3787
3806
  configPath,
3788
3807
  registrationContext,
3789
3808
  autoRegisterSubdomain
3790
- );
3791
- }
3792
- const wantsToRegister = await confirm(
3793
- "Would you like to register a workers.dev subdomain now?",
3794
- { fallbackValue: false }
3809
+ )
3810
+ };
3811
+ }
3812
+ const wantsToRegister = await confirm(
3813
+ "Would you like to register a workers.dev subdomain now?",
3814
+ { fallbackValue: false }
3815
+ );
3816
+ if (!wantsToRegister) {
3817
+ throw getRegistrationDeclinedError(
3818
+ registrationContext,
3819
+ accountId,
3820
+ configPath
3795
3821
  );
3796
- if (!wantsToRegister) {
3797
- throw getRegistrationDeclinedError(
3798
- registrationContext,
3799
- accountId,
3800
- configPath
3801
- );
3802
- }
3803
- return await registerSubdomain(
3822
+ }
3823
+ return {
3824
+ subdomain: await registerSubdomain(
3804
3825
  complianceConfig,
3805
3826
  accountId,
3806
3827
  configPath,
3807
3828
  registrationContext
3808
- );
3809
- }
3829
+ )
3830
+ };
3810
3831
  }
3811
- __name(getWorkersDevSubdomain, "getWorkersDevSubdomain");
3832
+ __name(getWorkersDevSubdomainInternal, "getWorkersDevSubdomainInternal");
3833
+ async function getWorkersDevSubdomainIfAccessible(complianceConfig, accountId, options = {}) {
3834
+ const result = await getWorkersDevSubdomainInternal(
3835
+ complianceConfig,
3836
+ accountId,
3837
+ options
3838
+ );
3839
+ return "unauthorizedError" in result ? void 0 : result.subdomain;
3840
+ }
3841
+ __name(getWorkersDevSubdomainIfAccessible, "getWorkersDevSubdomainIfAccessible");
3842
+ async function getWorkerSubdomain(complianceConfig, accountId, workerName) {
3843
+ const worker = await createCloudflareClient(
3844
+ complianceConfig
3845
+ ).workers.beta.workers.get(workerName, { account_id: accountId });
3846
+ return {
3847
+ ...worker.subdomain,
3848
+ enabled: worker.subdomain.enabled ?? false,
3849
+ previews_enabled: worker.subdomain.previews_enabled ?? false
3850
+ };
3851
+ }
3852
+ __name(getWorkerSubdomain, "getWorkerSubdomain");
3812
3853
  function getRegistrationWarning(registrationContext) {
3813
3854
  switch (registrationContext) {
3814
3855
  case "workflows":
@@ -4408,8 +4449,7 @@ function getSubdomainValuesAPIMock(config_workers_dev, config_preview_urls, rout
4408
4449
  };
4409
4450
  }
4410
4451
  __name(getSubdomainValuesAPIMock, "getSubdomainValuesAPIMock");
4411
- async function validateSubdomainMixedState(props, accountId, scriptName, before, after, firstDeploy) {
4412
- const { config: config2 } = props;
4452
+ async function validateSubdomainMixedState(scriptName, before, after, previewURLSuffix, firstDeploy) {
4413
4453
  const changed = after.workers_dev !== before.workers_dev || after.preview_urls !== before.preview_urls;
4414
4454
  if (!changed) {
4415
4455
  return after;
@@ -4426,10 +4466,7 @@ async function validateSubdomainMixedState(props, accountId, scriptName, before,
4426
4466
  if (after.workers_dev === after.preview_urls) {
4427
4467
  return after;
4428
4468
  }
4429
- const userSubdomain = await getWorkersDevSubdomain(config2, accountId, {
4430
- configPath: config2.configPath
4431
- });
4432
- const previewUrl = `https://<VERSION_PREFIX>-${scriptName}.${userSubdomain}`;
4469
+ const previewUrl = previewURLSuffix ? `https://<VERSION_PREFIX>${previewURLSuffix}` : `https://<VERSION_PREFIX>-${scriptName}.<YOUR_SUBDOMAIN>.workers.dev`;
4433
4470
  if (!after.workers_dev && after.preview_urls) {
4434
4471
  logger.warn(
4435
4472
  [
@@ -4458,14 +4495,17 @@ __name(validateSubdomainMixedState, "validateSubdomainMixedState");
4458
4495
  async function subdomainDeploy(props, accountId, scriptName, workerUrl, routes, deployments, firstDeploy) {
4459
4496
  const { config: config2 } = props;
4460
4497
  const { workers_dev: wantWorkersDev, preview_urls: wantPreviews } = getSubdomainValues(config2.workers_dev, config2.preview_urls, routes);
4498
+ const before = await getWorkerSubdomain(config2, accountId, scriptName);
4461
4499
  if (wantWorkersDev) {
4462
- const userSubdomain = await getWorkersDevSubdomain(config2, accountId, {
4500
+ const workersDevHostname = before.url ? new URL(before.url).hostname : `${scriptName}.${await getWorkersDevSubdomain(config2, accountId, {
4463
4501
  configPath: config2.configPath
4464
- });
4465
- const workersDevURL = `${scriptName}.${userSubdomain}`;
4466
- deployments.push(Promise.resolve({ targets: [workersDevURL] }));
4502
+ })}`;
4503
+ deployments.push(
4504
+ Promise.resolve({
4505
+ targets: [workersDevHostname]
4506
+ })
4507
+ );
4467
4508
  }
4468
- const before = await fetchResult(config2, `${workerUrl}/subdomain`);
4469
4509
  const after = await retryOnAPIFailure(
4470
4510
  async () => fetchResult(config2, `${workerUrl}/subdomain`, {
4471
4511
  method: "POST",
@@ -4511,11 +4551,10 @@ async function subdomainDeploy(props, accountId, scriptName, workerUrl, routes,
4511
4551
  );
4512
4552
  }
4513
4553
  await validateSubdomainMixedState(
4514
- props,
4515
- accountId,
4516
4554
  scriptName,
4517
4555
  { workers_dev: before.enabled, preview_urls: before.previews_enabled },
4518
4556
  { workers_dev: after.enabled, preview_urls: after.previews_enabled },
4557
+ before.preview_url_suffix,
4519
4558
  firstDeploy
4520
4559
  );
4521
4560
  return {
@@ -25285,7 +25324,7 @@ Edits that have been made via the script API will be overridden by your local co
25285
25324
  );
25286
25325
  const wantsWorkersDev = props.command === "deploy" && props.dispatchNamespace === void 0 && getSubdomainValues(config2.workers_dev, config2.preview_urls, props.routes).workers_dev;
25287
25326
  if (!workerExists && wantsWorkersDev) {
25288
- await getWorkersDevSubdomain(config2, accountId, {
25327
+ await getWorkersDevSubdomainIfAccessible(config2, accountId, {
25289
25328
  autoRegisterSubdomain: props.autoRegisterWorkersDevSubdomain,
25290
25329
  configPath: config2.configPath
25291
25330
  });
@@ -26169,16 +26208,17 @@ async function uploadWorkerVersion(props, config2, buildResult, callbacks) {
26169
26208
  let versionPreviewUrl = void 0;
26170
26209
  let versionPreviewAliasUrl = void 0;
26171
26210
  if (versionId && hasPreview) {
26172
- const { previews_enabled: previews_available_on_subdomain } = await fetchResult(config2, `${workerUrl}/subdomain`);
26173
- if (previews_available_on_subdomain) {
26174
- const userSubdomain = await getWorkersDevSubdomain(config2, accountId, {
26175
- configPath: config2.configPath
26176
- });
26211
+ const workerSubdomain = await getWorkerSubdomain(
26212
+ config2,
26213
+ accountId,
26214
+ workerName
26215
+ );
26216
+ if (workerSubdomain.previews_enabled && workerSubdomain.preview_url_suffix) {
26177
26217
  const shortVersion = versionId.slice(0, 8);
26178
- versionPreviewUrl = `https://${shortVersion}-${workerName}.${userSubdomain}`;
26218
+ versionPreviewUrl = `https://${shortVersion}${workerSubdomain.preview_url_suffix}`;
26179
26219
  logger.log(`Version Preview URL: ${versionPreviewUrl}`);
26180
26220
  if (props.previewAlias) {
26181
- versionPreviewAliasUrl = `https://${props.previewAlias}-${workerName}.${userSubdomain}`;
26221
+ versionPreviewAliasUrl = `https://${props.previewAlias}${workerSubdomain.preview_url_suffix}`;
26182
26222
  logger.log(`Version Preview Alias URL: ${versionPreviewAliasUrl}`);
26183
26223
  }
26184
26224
  }
@@ -27420,6 +27460,49 @@ function formatPreviewDeploymentSummary(config2, previewResource, deployment, is
27420
27460
  ].join("\n");
27421
27461
  }
27422
27462
  __name(formatPreviewDeploymentSummary, "formatPreviewDeploymentSummary");
27463
+ function getPreviewCustomDomainHostnames(config2) {
27464
+ const routes = config2.routes ?? (config2.route ? [config2.route] : []);
27465
+ return routes.filter(
27466
+ (route) => isCustomDomainRoute(route) && route.previews_enabled === true
27467
+ ).map((route) => normalizeHostname(route.pattern));
27468
+ }
27469
+ __name(getPreviewCustomDomainHostnames, "getPreviewCustomDomainHostnames");
27470
+ function normalizeHostname(hostname3) {
27471
+ try {
27472
+ return new URL(`https://${hostname3}`).hostname.replace(/\.$/, "");
27473
+ } catch {
27474
+ return hostname3.toLowerCase().replace(/\.$/, "");
27475
+ }
27476
+ }
27477
+ __name(normalizeHostname, "normalizeHostname");
27478
+ function hostnameMatchesCustomDomain(hostname3, customDomain) {
27479
+ const normalizedHostname = normalizeHostname(hostname3);
27480
+ return normalizedHostname === customDomain || normalizedHostname.endsWith(`.${customDomain}`);
27481
+ }
27482
+ __name(hostnameMatchesCustomDomain, "hostnameMatchesCustomDomain");
27483
+ function previewUrlMatchesCustomDomain(url3, customDomains) {
27484
+ try {
27485
+ const { hostname: hostname3 } = new URL(url3);
27486
+ return customDomains.some(
27487
+ (domain2) => hostnameMatchesCustomDomain(hostname3, domain2)
27488
+ );
27489
+ } catch {
27490
+ return false;
27491
+ }
27492
+ }
27493
+ __name(previewUrlMatchesCustomDomain, "previewUrlMatchesCustomDomain");
27494
+ function logMissingCustomDomainPreviewUrlsWarning(config2, previewResource, deployment) {
27495
+ const customDomains = getPreviewCustomDomainHostnames(config2);
27496
+ const urls = [...previewResource.urls ?? [], ...deployment.urls ?? []];
27497
+ if (customDomains.length === 0 || urls.length === 0 || urls.some((url3) => previewUrlMatchesCustomDomain(url3, customDomains))) {
27498
+ return;
27499
+ }
27500
+ logger.log("");
27501
+ logger.warn(
27502
+ "Custom domain Preview URLs are configured, but none are active for this Preview. If you added `previews_enabled = true` after your last deployment, run `wrangler deploy` once to publish the custom domain Preview route, then run `wrangler preview` again. If you already deployed with that setting, the custom domain may still be provisioning."
27503
+ );
27504
+ }
27505
+ __name(logMissingCustomDomainPreviewUrlsWarning, "logMissingCustomDomainPreviewUrlsWarning");
27423
27506
  function logMissingPreviewsBindingsWarning(productionBindingsExpectedInPreview, remotePreviewDefaultBindings, localPreviewBindings) {
27424
27507
  const availableBindingNames = /* @__PURE__ */ new Set([
27425
27508
  ...Object.keys(remotePreviewDefaultBindings ?? {}),
@@ -27628,6 +27711,11 @@ async function runPreview(accountId, args, config2, buildResult, assetsOptions,
27628
27711
  pullRequest
27629
27712
  )
27630
27713
  );
27714
+ logMissingCustomDomainPreviewUrlsWarning(
27715
+ config2,
27716
+ previewResource,
27717
+ deployment
27718
+ );
27631
27719
  }
27632
27720
  return { preview: previewResource, deployment, isNewPreview };
27633
27721
  }
@@ -27931,4 +28019,4 @@ __name(formatBindings, "formatBindings");
27931
28019
  * THE SOFTWARE.
27932
28020
  */
27933
28021
 
27934
- export { ACTOR_BINDING_DEPENDS_ON_EXPORT_CODE, EXPORTS_RECONCILIATION_ERROR_CODE, INCONSISTENT_EXPORTS_ACROSS_VERSIONS_CODE, INVALID_INHERIT_BINDING_CODE, NO_ACTIVE_PREVIEW_URLS_MESSAGE, NoInputError, PREVIEW_DOMAIN_PROVISIONING_NOTE, WORKER_LEGACY_ENVIRONMENT_NOT_FOUND_ERR_CODE, WORKER_NOT_FOUND_ERR_CODE, WORKFLOW_CRON_REQUIRES_PAID_PLAN_CODE, WORKFLOW_NOT_FOUND_CODE, addRequiredSecretsInheritBindings, addWorkersSitesBindings, applyServiceAndEnvironmentTags, assemblePreviewScriptSettings, assertPreviewBuildOutputRootConfig, buildAssetManifest, checkRemoteSecretsOverride, checkWorkflowConflicts, collectPackageDependencies, confirmLatestDeploymentOverwrite, createDeployment, createDurableObjectContainerApplication, createPreview, createPreviewDeployment, createPreviewDeploymentForm, createPreviewParentWorker, createTruncatedAlias, decodeJwtPayload, deletePreview, deletePullConsumer, deleteWorkerConsumer, deploy, deployDurableObjectContainerApplications, deployVersionedDurableObjectContainerApplications, deployWfpUserWorker, diagnoseScriptSizeError, diagnoseStartupError, diffJsonObjects, downloadWorkerConfig, drawBox, drawConnectedChildBox, editPreview, ensureQueuesExistByConfig, extractBuildOutputBindings, extractConfigBindings, fetchDeployableVersions, fetchDeploymentVersions, fetchLatestDeployment, fetchLatestDeployments, fetchSecrets, fetchVersion, fetchVersions, fetchWorkerConfig, formatAlignedRows, formatBindings, formatNoActivePreviewUrlsMessage, generatePreviewAlias, getBindingValue, getBranchName2 as getBranchName, getCommitSha, getConfigPatch, getDeployConfirmFunction, getEdgeKvUploadConcurrency, getHeadCommitMessage, getHeadCommitRef, getMigrationsToUpload, getPreview, getPreviewBaseConfig, getPreviewDeployment, getPreviewOwnedContainerClassNames, getPullRequestMetadata, getQueue, getRemoteConfigDiff, getRepositoryUrl, getSettings, getSize, getSourceMappedStack, getSourceMappedString, getSubdomainValues, getSubdomainValuesAPIMock, getVersionedDurableObjectContainerApplications, getWorkersDevSubdomain, getZoneForRoute, getZoneIdFromHost, handleMissingSecretsError, hasDefinedEnvironments, hashFile, helpIfErrorIsSizeOrScriptStartup, isExportsReconciliationErrorDetails, isJwtExpired, isModifiedDiffValue, isNonDestructive, isWorkerNotFoundError, listConsumers, listQueues, maybeRetrieveFileSourceMap, padToVisibleWidth, parseBulkInputToObject, parseConfigPlacement, patchNonVersionedScriptSettings, patchPreviewBaseConfig, patchPreviewDeployment, postConsumer, prepareDurableObjectContainerApplications, preview, previewBuildOutput, previewContainerAppName, previewDelete, printBundleSize, printVersions, provisionBindings, publishCustomDomains, publishRoutes, putConsumer, putConsumerById, renderBindingDependsOnExportError, renderExportsReconciliationError, renderExportsReconciliationSuccess, renderInconsistentExportsAcrossVersionsError, renderRoute, resolveAssetOptions, resolveDoLifecyclePayload, resolveExportsUploadPayload, resolveVersionedDurableObjectContainerApplications, resolveWorkerName, sanitizeBranchName, shouldUseCIMetadataFallback, stripAnsi, syncAssets, tagsAreEqual, triggersDeploy, updateQueueConsumers, validateEventTriggerTargets, validateFileSecrets, validateImageLessContainerApplicationsForUpload, validateNodeCompatMode, validateRoutes, verifyWorkerMatchesCITag, versionsUpload, visibleLength, warnOnErrorUpdatingServiceAndEnvironmentTags, workerNotFoundErrorMessage };
28022
+ export { ACTOR_BINDING_DEPENDS_ON_EXPORT_CODE, EXPORTS_RECONCILIATION_ERROR_CODE, INCONSISTENT_EXPORTS_ACROSS_VERSIONS_CODE, INVALID_INHERIT_BINDING_CODE, NO_ACTIVE_PREVIEW_URLS_MESSAGE, NoInputError, PREVIEW_DOMAIN_PROVISIONING_NOTE, WORKER_LEGACY_ENVIRONMENT_NOT_FOUND_ERR_CODE, WORKER_NOT_FOUND_ERR_CODE, WORKFLOW_CRON_REQUIRES_PAID_PLAN_CODE, WORKFLOW_NOT_FOUND_CODE, addRequiredSecretsInheritBindings, addWorkersSitesBindings, applyServiceAndEnvironmentTags, assemblePreviewScriptSettings, assertPreviewBuildOutputRootConfig, buildAssetManifest, checkRemoteSecretsOverride, checkWorkflowConflicts, collectPackageDependencies, confirmLatestDeploymentOverwrite, createDeployment, createDurableObjectContainerApplication, createPreview, createPreviewDeployment, createPreviewDeploymentForm, createPreviewParentWorker, createTruncatedAlias, decodeJwtPayload, deletePreview, deletePullConsumer, deleteWorkerConsumer, deploy, deployDurableObjectContainerApplications, deployVersionedDurableObjectContainerApplications, deployWfpUserWorker, diagnoseScriptSizeError, diagnoseStartupError, diffJsonObjects, downloadWorkerConfig, drawBox, drawConnectedChildBox, editPreview, ensureQueuesExistByConfig, extractBuildOutputBindings, extractConfigBindings, fetchDeployableVersions, fetchDeploymentVersions, fetchLatestDeployment, fetchLatestDeployments, fetchSecrets, fetchVersion, fetchVersions, fetchWorkerConfig, formatAlignedRows, formatBindings, formatNoActivePreviewUrlsMessage, generatePreviewAlias, getBindingValue, getBranchName2 as getBranchName, getCommitSha, getConfigPatch, getDeployConfirmFunction, getEdgeKvUploadConcurrency, getHeadCommitMessage, getHeadCommitRef, getMigrationsToUpload, getPreview, getPreviewBaseConfig, getPreviewDeployment, getPreviewOwnedContainerClassNames, getPullRequestMetadata, getQueue, getRemoteConfigDiff, getRepositoryUrl, getSettings, getSize, getSourceMappedStack, getSourceMappedString, getSubdomainValues, getSubdomainValuesAPIMock, getVersionedDurableObjectContainerApplications, getWorkerSubdomain, getWorkersDevSubdomain, getWorkersDevSubdomainIfAccessible, getZoneForRoute, getZoneIdFromHost, handleMissingSecretsError, hasDefinedEnvironments, hashFile, helpIfErrorIsSizeOrScriptStartup, isExportsReconciliationErrorDetails, isJwtExpired, isModifiedDiffValue, isNonDestructive, isWorkerNotFoundError, listConsumers, listQueues, maybeRetrieveFileSourceMap, padToVisibleWidth, parseBulkInputToObject, parseConfigPlacement, patchNonVersionedScriptSettings, patchPreviewBaseConfig, patchPreviewDeployment, postConsumer, prepareDurableObjectContainerApplications, preview, previewBuildOutput, previewContainerAppName, previewDelete, printBundleSize, printVersions, provisionBindings, publishCustomDomains, publishRoutes, putConsumer, putConsumerById, renderBindingDependsOnExportError, renderExportsReconciliationError, renderExportsReconciliationSuccess, renderInconsistentExportsAcrossVersionsError, renderRoute, resolveAssetOptions, resolveDoLifecyclePayload, resolveExportsUploadPayload, resolveVersionedDurableObjectContainerApplications, resolveWorkerName, sanitizeBranchName, shouldUseCIMetadataFallback, stripAnsi, syncAssets, tagsAreEqual, triggersDeploy, updateQueueConsumers, validateEventTriggerTargets, validateFileSecrets, validateImageLessContainerApplicationsForUpload, validateNodeCompatMode, validateRoutes, verifyWorkerMatchesCITag, versionsUpload, visibleLength, warnOnErrorUpdatingServiceAndEnvironmentTags, workerNotFoundErrorMessage };