@cloudflare/deploy-helpers 0.13.0 → 0.14.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.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';
@@ -10,8 +10,8 @@ import path__default, { resolve, isAbsolute, sep, extname } from 'node:path';
10
10
  import url2, { URLSearchParams as URLSearchParams$1 } from 'node:url';
11
11
  import * as cli from '@cloudflare/cli-shared-helpers';
12
12
  import { updateStatus, cancel } from '@cloudflare/cli-shared-helpers';
13
- import { SchedulingPolicy, ApplicationsService, ApiError, listDurableObjects, resolveImageName, pushImageIfChanged, ContainerImagePreparationsService, ContainerImagePreparationStatus, createDurableObjectNamespaceResolver, initContainersSharedContext, pushBuiltContainerImage, deployContainers, verifyDockerInstalled } from '@cloudflare/containers-shared';
14
- import { INHERIT_SYMBOL, APIError, UserError, getEnvironmentVariableFactory, isNonInteractiveOrCI, getHostFromRoute, retryOnAPIFailure, ParseError, getComplianceRegionSubdomain, configFileName, formatTime, getSubdomainMixedStateCheckDisabled, LOGGER_LEVELS, CONTAINER_IMAGES_BINDING, getResolvedDurableObjectContainerApps, isDurableObjectContainerApp, getDockerPath, validateDurableObjectContainerApplications, getDurableObjectClassNameToUseSQLiteMap, SERVICE_TAG_PREFIX, ENVIRONMENT_TAG_PREFIX, getDurableObjectExports, partitionExports, getWranglerTmpDir, parsePackageJSON, getInstalledPackageVersion, FatalError, readFileSync as readFileSync$1, parseJSON, printBindings, experimental_readRawConfig, experimental_patchConfig, PatchConfigError, COMPLIANCE_REGION_CONFIG_UNKNOWN, constructWranglerConfig, getCIMatchTag, formatConfigSnippet, DEFAULT_COMPAT_DATE, writeOutput, getDurableObjectContainerApps, getBindings, hasDurableObjectExports, parseNonHyphenedUuid, getWorkersCIBranchName, getCIOverrideName, getBindingTypeFriendlyName, defaultWranglerConfig } from '@cloudflare/workers-utils';
13
+ import { SchedulingPolicy, ApplicationsService, listDurableObjects, ApiError, resolveImageName, pushImageIfChanged, ContainerImagePreparationsService, ContainerImagePreparationStatus, createDurableObjectNamespaceResolver, initContainersSharedContext, pushBuiltContainerImage, deployContainers, verifyDockerInstalled } from '@cloudflare/containers-shared';
14
+ import { INHERIT_SYMBOL, APIError, UserError, getEnvironmentVariableFactory, isNonInteractiveOrCI, getHostFromRoute, retryOnAPIFailure, ParseError, getComplianceRegionSubdomain, configFileName, formatTime, getSubdomainMixedStateCheckDisabled, LOGGER_LEVELS, getResolvedDurableObjectContainerApps, isDurableObjectContainerApp, getDockerPath, validateDurableObjectContainerApplications, getDurableObjectClassNameToUseSQLiteMap, SERVICE_TAG_PREFIX, ENVIRONMENT_TAG_PREFIX, getDurableObjectExports, partitionExports, getWranglerTmpDir, parsePackageJSON, getInstalledPackageVersion, FatalError, readFileSync as readFileSync$1, parseJSON, printBindings, experimental_readRawConfig, experimental_patchConfig, PatchConfigError, COMPLIANCE_REGION_CONFIG_UNKNOWN, constructWranglerConfig, getCIMatchTag, formatConfigSnippet, DEFAULT_COMPAT_DATE, writeOutput, getDurableObjectContainerApps, getBindings, hasDurableObjectExports, parseNonHyphenedUuid, getWorkersCIBranchName, getCIOverrideName, getBindingTypeFriendlyName, defaultWranglerConfig } from '@cloudflare/workers-utils';
15
15
  import { Response, FormData } from 'undici';
16
16
  import chalk6 from 'chalk';
17
17
  import PQueue from 'p-queue';
@@ -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 {
@@ -6523,59 +6562,6 @@ function formatVersions(versions, traffic) {
6523
6562
  }).join("\n\n");
6524
6563
  }
6525
6564
  __name(formatVersions, "formatVersions");
6526
- async function clearRemovedContainerImagesBindings(config2, durableObjectContainerConfig, bindings, workerUrl) {
6527
- if (durableObjectContainerConfig.length > 0) {
6528
- return;
6529
- }
6530
- const settings = await fetchResult(
6531
- config2,
6532
- `${workerUrl}/settings`
6533
- );
6534
- if (settings.bindings.some(({ name }) => name === CONTAINER_IMAGES_BINDING)) {
6535
- bindings[CONTAINER_IMAGES_BINDING] ??= { type: "json", value: {} };
6536
- }
6537
- }
6538
- __name(clearRemovedContainerImagesBindings, "clearRemovedContainerImagesBindings");
6539
- function addContainerImagesBinding(durableObjectContainerConfig, bindings, preparedContainerImages, options = {}) {
6540
- const shouldInheritExisting = options.preserveExisting && options.workerExists && options.hasExistingBinding;
6541
- if (options.preserveExisting && !shouldInheritExisting) {
6542
- return;
6543
- }
6544
- if (durableObjectContainerConfig.length === 0 && !shouldInheritExisting) {
6545
- return;
6546
- }
6547
- if (bindings[CONTAINER_IMAGES_BINDING] !== void 0) {
6548
- throw new UserError(
6549
- `The binding name "${CONTAINER_IMAGES_BINDING}" is reserved for Durable Object-managed Container images.`,
6550
- {
6551
- telemetryMessage: "durable object container images binding name conflict"
6552
- }
6553
- );
6554
- }
6555
- if (options.preserveExisting) {
6556
- bindings[CONTAINER_IMAGES_BINDING] = { type: "inherit" };
6557
- return;
6558
- }
6559
- bindings[CONTAINER_IMAGES_BINDING] = {
6560
- type: "json",
6561
- value: Object.fromEntries(
6562
- getResolvedDurableObjectContainerApps(
6563
- durableObjectContainerConfig,
6564
- options.exports
6565
- ).map((container) => {
6566
- const configuredImages = Object.keys(container.images ?? {});
6567
- const preparedImages = preparedContainerImages[container.class_name];
6568
- if (configuredImages.length > 0 && preparedImages === void 0) {
6569
- throw new Error(
6570
- `Container images for Durable Object class "${container.class_name}" were not prepared before upload.`
6571
- );
6572
- }
6573
- return [container.class_name, preparedImages ?? {}];
6574
- })
6575
- )
6576
- };
6577
- }
6578
- __name(addContainerImagesBinding, "addContainerImagesBinding");
6579
6565
  function getContainerMetadata(containers, preparedContainerImages = {}, options = {}) {
6580
6566
  const managedClasses = new Map(
6581
6567
  getResolvedDurableObjectContainerApps(containers, options.exports).map(
@@ -6625,8 +6611,7 @@ async function getContainerMetadataForRolloutSkip(config2, containers, {
6625
6611
  allowUnprepared: true,
6626
6612
  exports: config2.exports
6627
6613
  }
6628
- ),
6629
- hasExistingContainerImagesBinding: false
6614
+ )
6630
6615
  };
6631
6616
  }
6632
6617
  if (dispatchNamespace !== void 0) {
@@ -6652,22 +6637,6 @@ async function getContainerMetadataForRolloutSkip(config2, containers, {
6652
6637
  void 0,
6653
6638
  latestDeployment.versions.map(({ version_id }) => version_id)
6654
6639
  );
6655
- const containerImagesBindingByVersion = versions.map(
6656
- (version2) => version2.resources.bindings.some(
6657
- (binding) => binding.name === CONTAINER_IMAGES_BINDING
6658
- )
6659
- );
6660
- const hasExistingContainerImagesBinding = containerImagesBindingByVersion[0] ?? false;
6661
- if (containerImagesBindingByVersion.some(
6662
- (hasBinding) => hasBinding !== hasExistingContainerImagesBinding
6663
- )) {
6664
- throw new UserError(
6665
- `All currently deployed Worker Versions must have identical ${CONTAINER_IMAGES_BINDING} binding presence when using --containers-rollout=none.`,
6666
- {
6667
- telemetryMessage: "rollout none inconsistent durable object container image binding"
6668
- }
6669
- );
6670
- }
6671
6640
  const containerMetadataByVersion = versions.map(
6672
6641
  (version2) => version2.resources?.script_runtime?.containers
6673
6642
  );
@@ -6676,8 +6645,7 @@ async function getContainerMetadataForRolloutSkip(config2, containers, {
6676
6645
  );
6677
6646
  if (existingMetadata.length === 0) {
6678
6647
  return {
6679
- containers: void 0,
6680
- hasExistingContainerImagesBinding
6648
+ containers: void 0
6681
6649
  };
6682
6650
  }
6683
6651
  const expectedMetadata = existingMetadata[0];
@@ -6692,8 +6660,7 @@ async function getContainerMetadataForRolloutSkip(config2, containers, {
6692
6660
  );
6693
6661
  }
6694
6662
  return {
6695
- containers: existingMetadata[0],
6696
- hasExistingContainerImagesBinding
6663
+ containers: existingMetadata[0]
6697
6664
  };
6698
6665
  }
6699
6666
  __name(getContainerMetadataForRolloutSkip, "getContainerMetadataForRolloutSkip");
@@ -6745,24 +6712,6 @@ async function createDurableObjectContainerApplication(application, namespaceId)
6745
6712
  );
6746
6713
  }
6747
6714
  __name(createDurableObjectContainerApplication, "createDurableObjectContainerApplication");
6748
- function getContainerImageClasses(version2) {
6749
- const binding = version2.resources.bindings.find(
6750
- (candidate) => candidate.name === CONTAINER_IMAGES_BINDING
6751
- );
6752
- if (binding === void 0) {
6753
- return void 0;
6754
- }
6755
- if (binding.type !== "json" || typeof binding.json !== "object" || binding.json === null || Array.isArray(binding.json)) {
6756
- throw new UserError(
6757
- `Worker Version ${version2.id} has invalid ${CONTAINER_IMAGES_BINDING} metadata.`,
6758
- {
6759
- telemetryMessage: "versions deploy invalid durable object container image binding"
6760
- }
6761
- );
6762
- }
6763
- return new Set(Object.keys(binding.json));
6764
- }
6765
- __name(getContainerImageClasses, "getContainerImageClasses");
6766
6715
  function getNamespaceId(version2, scriptName, className) {
6767
6716
  const binding = version2.resources.bindings.find(
6768
6717
  (candidate) => candidate.type === "durable_object_namespace" && candidate.class_name === className && (candidate.script_name === void 0 || candidate.script_name === scriptName)
@@ -6770,18 +6719,17 @@ function getNamespaceId(version2, scriptName, className) {
6770
6719
  return binding?.type === "durable_object_namespace" ? binding.namespace_id : void 0;
6771
6720
  }
6772
6721
  __name(getNamespaceId, "getNamespaceId");
6773
- function getDurableObjectContainerApplicationsFromVersion(version2, scriptName) {
6774
- const containerClasses = getContainerImageClasses(version2);
6775
- if (containerClasses === void 0) {
6776
- return [];
6777
- }
6722
+ function getDurableObjectContainerApplicationsFromVersion(version2, scriptName, containerClasses) {
6778
6723
  const containers = version2.resources.script_runtime.containers ?? [];
6779
- return [...containerClasses].sort().map((className) => {
6724
+ return [...containerClasses].sort().flatMap((className) => {
6780
6725
  const matchingContainers = containers.filter(
6781
6726
  (container2) => container2.class_name === className
6782
6727
  );
6728
+ if (matchingContainers.length === 0) {
6729
+ return [];
6730
+ }
6783
6731
  const [container] = matchingContainers;
6784
- if (matchingContainers.length !== 1 || container?.name === void 0) {
6732
+ if (typeof className !== "string" || className.length === 0 || matchingContainers.length !== 1 || !container?.name) {
6785
6733
  throw new UserError(
6786
6734
  `Worker Version ${version2.id} has invalid Durable Object-managed Container metadata for class "${className}".`,
6787
6735
  {
@@ -6798,8 +6746,17 @@ function getDurableObjectContainerApplicationsFromVersion(version2, scriptName)
6798
6746
  }
6799
6747
  __name(getDurableObjectContainerApplicationsFromVersion, "getDurableObjectContainerApplicationsFromVersion");
6800
6748
  function getVersionedDurableObjectContainerApplications(versions, scriptName) {
6749
+ const containerClasses = new Set(
6750
+ versions.flatMap(
6751
+ (version2) => (version2.resources.script_runtime.containers ?? []).filter((container) => Object.keys(container.images ?? {}).length > 0).map((container) => container.class_name)
6752
+ )
6753
+ );
6801
6754
  const applicationsByVersion = versions.map(
6802
- (version2) => getDurableObjectContainerApplicationsFromVersion(version2, scriptName)
6755
+ (version2) => getDurableObjectContainerApplicationsFromVersion(
6756
+ version2,
6757
+ scriptName,
6758
+ containerClasses
6759
+ )
6803
6760
  );
6804
6761
  const [firstApplications = []] = applicationsByVersion;
6805
6762
  const expectedDefinition = JSON.stringify(
@@ -6838,6 +6795,52 @@ function getVersionedDurableObjectContainerApplications(versions, scriptName) {
6838
6795
  });
6839
6796
  }
6840
6797
  __name(getVersionedDurableObjectContainerApplications, "getVersionedDurableObjectContainerApplications");
6798
+ function validateApplicationIdentity(application, namespaceId, existing) {
6799
+ if (existing.id !== namespaceId || existing.durable_objects?.namespace_id !== namespaceId || existing.scheduling_policy !== SchedulingPolicy.DURABLE_OBJECT || existing.name !== application.name) {
6800
+ throw new UserError(
6801
+ `The application for Durable Object namespace "${namespaceId}" does not match Container "${application.name}". The existing name, namespace, and scheduling policy must match before its settings can be applied.`,
6802
+ {
6803
+ telemetryMessage: "durable object container application identity mismatch"
6804
+ }
6805
+ );
6806
+ }
6807
+ }
6808
+ __name(validateApplicationIdentity, "validateApplicationIdentity");
6809
+ async function validateImageLessContainerApplicationsForUpload(config2, containers, { accountId, scriptName }) {
6810
+ const imageLessContainers = getResolvedDurableObjectContainerApps(
6811
+ containers,
6812
+ config2.exports
6813
+ ).filter((container) => Object.keys(container.images ?? {}).length === 0);
6814
+ if (imageLessContainers.length === 0) {
6815
+ return;
6816
+ }
6817
+ const namespaces = await listDurableObjects(config2, accountId);
6818
+ for (const container of imageLessContainers) {
6819
+ const namespace = namespaces.find(
6820
+ (candidate) => candidate.class === container.class_name && candidate.script === scriptName && candidate.preview === void 0 && candidate.dispatch_namespace === void 0
6821
+ );
6822
+ let existing;
6823
+ if (namespace !== void 0) {
6824
+ try {
6825
+ existing = await ApplicationsService.getApplication(namespace.id);
6826
+ } catch (error51) {
6827
+ if (!(error51 instanceof ApiError) || error51.status !== 404) {
6828
+ throw error51;
6829
+ }
6830
+ }
6831
+ }
6832
+ if (namespace === void 0 || existing === void 0) {
6833
+ throw new UserError(
6834
+ `Container "${container.name}" has no named images and has not been provisioned. Run \`wrangler deploy\` to create its Durable Object-managed application before using \`wrangler versions upload\`, or configure at least one named image.`,
6835
+ {
6836
+ telemetryMessage: "versions upload image less container application missing"
6837
+ }
6838
+ );
6839
+ }
6840
+ validateApplicationIdentity(container, namespace.id, existing);
6841
+ }
6842
+ }
6843
+ __name(validateImageLessContainerApplicationsForUpload, "validateImageLessContainerApplicationsForUpload");
6841
6844
  async function applyApplication(application, namespaceId, settings = {}, updateExisting = false) {
6842
6845
  let existing;
6843
6846
  try {
@@ -6851,14 +6854,7 @@ async function applyApplication(application, namespaceId, settings = {}, updateE
6851
6854
  );
6852
6855
  return;
6853
6856
  }
6854
- if (existing.id !== namespaceId || existing.durable_objects?.namespace_id !== namespaceId || existing.scheduling_policy !== SchedulingPolicy.DURABLE_OBJECT || existing.name !== application.name) {
6855
- throw new UserError(
6856
- `The application for Durable Object namespace "${namespaceId}" does not match Container "${application.name}". The existing name, namespace, and scheduling policy must match before its settings can be applied.`,
6857
- {
6858
- telemetryMessage: "durable object container application identity mismatch"
6859
- }
6860
- );
6861
- }
6857
+ validateApplicationIdentity(application, namespaceId, existing);
6862
6858
  if (!updateExisting) {
6863
6859
  return;
6864
6860
  }
@@ -7013,7 +7009,8 @@ async function prepareDurableObjectContainerApplications(config2, durableObjectC
7013
7009
  accountId,
7014
7010
  dryRun,
7015
7011
  scriptName,
7016
- dispatchNamespace
7012
+ dispatchNamespace,
7013
+ requireExistingImageLessApplications = false
7017
7014
  }) {
7018
7015
  validateDurableObjectContainerApplications(
7019
7016
  config2,
@@ -7048,6 +7045,14 @@ async function prepareDurableObjectContainerApplications(config2, durableObjectC
7048
7045
  }
7049
7046
  }
7050
7047
  }
7048
+ if (!dryRun && requireExistingImageLessApplications) {
7049
+ assert6(accountId);
7050
+ await validateImageLessContainerApplicationsForUpload(
7051
+ config2,
7052
+ durableObjectContainerConfig,
7053
+ { accountId, scriptName }
7054
+ );
7055
+ }
7051
7056
  const containers = managedContainers.filter(
7052
7057
  (container) => Object.keys(container.images ?? {}).length > 0
7053
7058
  );
@@ -25319,7 +25324,7 @@ Edits that have been made via the script API will be overridden by your local co
25319
25324
  );
25320
25325
  const wantsWorkersDev = props.command === "deploy" && props.dispatchNamespace === void 0 && getSubdomainValues(config2.workers_dev, config2.preview_urls, props.routes).workers_dev;
25321
25326
  if (!workerExists && wantsWorkersDev) {
25322
- await getWorkersDevSubdomain(config2, accountId, {
25327
+ await getWorkersDevSubdomainIfAccessible(config2, accountId, {
25323
25328
  autoRegisterSubdomain: props.autoRegisterWorkersDevSubdomain,
25324
25329
  configPath: config2.configPath
25325
25330
  });
@@ -25493,25 +25498,6 @@ async function deployWorker(props, config2, buildResult, callbacks) {
25493
25498
  type: "deploy",
25494
25499
  workerExists
25495
25500
  });
25496
- if (!skipContainerChanges && keepVars && !isDryRun && workerExists) {
25497
- await clearRemovedContainerImagesBindings(
25498
- config2,
25499
- durableObjectContainerConfig,
25500
- bindings,
25501
- workerUrl
25502
- );
25503
- }
25504
- addContainerImagesBinding(
25505
- durableObjectContainerConfig,
25506
- bindings,
25507
- preparedContainerImages ?? {},
25508
- {
25509
- preserveExisting: skipContainerChanges,
25510
- exports: config2.exports,
25511
- workerExists,
25512
- hasExistingBinding: rolloutSkipContainerState?.hasExistingContainerImagesBinding
25513
- }
25514
- );
25515
25501
  if (workersSitesAssets.manifest) {
25516
25502
  modules.push({
25517
25503
  name: "__STATIC_CONTENT_MANIFEST",
@@ -25948,10 +25934,7 @@ async function uploadWorkerVersion(props, config2, buildResult, callbacks) {
25948
25934
  const { entry, compatibilityDate, compatibilityFlags, keepVars, accountId } = props;
25949
25935
  const assetsOptions = resolveAssetOptions(props, config2);
25950
25936
  const { name } = validateWorkerProps(props, config2);
25951
- const { workerTag, tags, workerExists, aborted: aborted2 } = await preUploadApiChecks(
25952
- props,
25953
- config2
25954
- );
25937
+ const { workerTag, tags, aborted: aborted2 } = await preUploadApiChecks(props, config2);
25955
25938
  if (aborted2) {
25956
25939
  return { versionId: null, workerTag };
25957
25940
  }
@@ -26001,7 +25984,8 @@ async function uploadWorkerVersion(props, config2, buildResult, callbacks) {
26001
25984
  {
26002
25985
  accountId,
26003
25986
  dryRun: Boolean(props.dryRun),
26004
- scriptName
25987
+ scriptName,
25988
+ requireExistingImageLessApplications: true
26005
25989
  }
26006
25990
  );
26007
25991
  const assetsUploadResult = assetsOptions && !props.dryRun ? await syncAssets(config2, accountId, assetsOptions.directory, scriptName) : void 0;
@@ -26020,20 +26004,6 @@ async function uploadWorkerVersion(props, config2, buildResult, callbacks) {
26020
26004
  }
26021
26005
  }
26022
26006
  addRequiredSecretsInheritBindings(config2, bindings, { type: "upload" });
26023
- if (keepVars && !props.dryRun && workerExists) {
26024
- await clearRemovedContainerImagesBindings(
26025
- config2,
26026
- durableObjectContainerConfig,
26027
- bindings,
26028
- workerUrl
26029
- );
26030
- }
26031
- addContainerImagesBinding(
26032
- durableObjectContainerConfig,
26033
- bindings,
26034
- preparedContainerImages ?? {},
26035
- { exports: config2.exports }
26036
- );
26037
26007
  const placement = parseConfigPlacement(config2.placement);
26038
26008
  const entryPointName = path__default.basename(resolvedEntryPointPath);
26039
26009
  const main = {
@@ -26221,7 +26191,9 @@ async function uploadWorkerVersion(props, config2, buildResult, callbacks) {
26221
26191
  assert6(versionId);
26222
26192
  await deployDurableObjectContainerApplications(
26223
26193
  config2,
26224
- durableObjectContainerConfig,
26194
+ durableObjectContainerConfig.filter(
26195
+ (container) => Object.keys(container.images ?? {}).length > 0
26196
+ ),
26225
26197
  {
26226
26198
  versionId,
26227
26199
  accountId,
@@ -26236,16 +26208,17 @@ async function uploadWorkerVersion(props, config2, buildResult, callbacks) {
26236
26208
  let versionPreviewUrl = void 0;
26237
26209
  let versionPreviewAliasUrl = void 0;
26238
26210
  if (versionId && hasPreview) {
26239
- const { previews_enabled: previews_available_on_subdomain } = await fetchResult(config2, `${workerUrl}/subdomain`);
26240
- if (previews_available_on_subdomain) {
26241
- const userSubdomain = await getWorkersDevSubdomain(config2, accountId, {
26242
- configPath: config2.configPath
26243
- });
26211
+ const workerSubdomain = await getWorkerSubdomain(
26212
+ config2,
26213
+ accountId,
26214
+ workerName
26215
+ );
26216
+ if (workerSubdomain.previews_enabled && workerSubdomain.preview_url_suffix) {
26244
26217
  const shortVersion = versionId.slice(0, 8);
26245
- versionPreviewUrl = `https://${shortVersion}-${workerName}.${userSubdomain}`;
26218
+ versionPreviewUrl = `https://${shortVersion}${workerSubdomain.preview_url_suffix}`;
26246
26219
  logger.log(`Version Preview URL: ${versionPreviewUrl}`);
26247
26220
  if (props.previewAlias) {
26248
- versionPreviewAliasUrl = `https://${props.previewAlias}-${workerName}.${userSubdomain}`;
26221
+ versionPreviewAliasUrl = `https://${props.previewAlias}${workerSubdomain.preview_url_suffix}`;
26249
26222
  logger.log(`Version Preview Alias URL: ${versionPreviewAliasUrl}`);
26250
26223
  }
26251
26224
  }
@@ -27056,14 +27029,14 @@ function assemblePreviewScriptSettings(config2) {
27056
27029
  return result;
27057
27030
  }
27058
27031
  __name(assemblePreviewScriptSettings, "assemblePreviewScriptSettings");
27059
- function assertPreviewBuildOutputSettings(settings) {
27060
- if (settings?.isPreview !== true) {
27032
+ function assertPreviewBuildOutputRootConfig(rootConfig) {
27033
+ if (rootConfig?.buildContext.isPreview !== true) {
27061
27034
  throw new UserError("Build Output was not created by a Preview build.", {
27062
27035
  telemetryMessage: "preview build output missing preview intent"
27063
27036
  });
27064
27037
  }
27065
27038
  }
27066
- __name(assertPreviewBuildOutputSettings, "assertPreviewBuildOutputSettings");
27039
+ __name(assertPreviewBuildOutputRootConfig, "assertPreviewBuildOutputRootConfig");
27067
27040
  function buildPreviewContainerConfig(config2, parentWorkerName, previewSlug, previewContainers) {
27068
27041
  const previews = config2.previews;
27069
27042
  const previewDOBindings = previews?.durable_objects?.bindings ?? [];
@@ -27712,8 +27685,8 @@ async function preview(accountId, args, config2, buildResult, assetsOptions, cal
27712
27685
  }
27713
27686
  __name(preview, "preview");
27714
27687
  async function previewBuildOutput(accountId, args, buildOutput) {
27715
- const { workerConfig, projectSettings, buildResult, assets } = buildOutput;
27716
- assertPreviewBuildOutputSettings(projectSettings);
27688
+ const { workerConfig, rootConfig, buildResult, assets } = buildOutput;
27689
+ assertPreviewBuildOutputRootConfig(rootConfig);
27717
27690
  if (workerConfig.domains?.length) {
27718
27691
  throw new UserError(
27719
27692
  "Preview uploads from Build Output don't support the `domains` field.",
@@ -27756,10 +27729,14 @@ async function previewBuildOutput(accountId, args, buildOutput) {
27756
27729
  }
27757
27730
  );
27758
27731
  }
27759
- const convertedConfig = convertToWranglerConfig(
27760
- workerConfig,
27761
- projectSettings
27762
- );
27732
+ const { buildContext: _buildContext, ...settings } = rootConfig;
27733
+ const { manifest: _manifest, ...worker } = workerConfig;
27734
+ const convertedConfig = convertToWranglerConfig({
27735
+ ...settings,
27736
+ worker,
27737
+ // TODO: Add support for Containers in Preview uploads from Build Output.
27738
+ containers: []
27739
+ });
27763
27740
  const previewBuildResult = buildResult && {
27764
27741
  ...buildResult,
27765
27742
  mainModuleName: workerConfig.manifest?.mainModule
@@ -27994,4 +27971,4 @@ __name(formatBindings, "formatBindings");
27994
27971
  * THE SOFTWARE.
27995
27972
  */
27996
27973
 
27997
- 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, assertPreviewBuildOutputSettings, 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, validateNodeCompatMode, validateRoutes, verifyWorkerMatchesCITag, versionsUpload, visibleLength, warnOnErrorUpdatingServiceAndEnvironmentTags, workerNotFoundErrorMessage };
27974
+ 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 };