@go-to-k/cdkd 0.263.2 → 0.264.0

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/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { $ as rewriteTemplateAssetReferences, $t as StackHasActiveImportsError, A as disableInstanceApiTermination, At as uploadCfnTemplate, B as DiffCalculator, Bt as CdkdError, C as yellow, Ct as resolveStateBucketWithDefaultAndSource, D as findActionableSilentDrops, Dt as CFN_TEMPLATE_URL_LIMIT, E as ProviderRegistry, Et as CFN_TEMPLATE_BODY_LIMIT, F as WAFv2WebACLProvider, Ft as AwsClients, G as rebuildClientForBucketRegion, Gt as LocalStartServiceError, H as TemplateParser, I as normalizeAwsTagsToCfn, It as getAwsClients, J as stringifyValue, Jt as NestedStackChildDirectDestroyError, K as shouldRetainResource, L as resolveExplicitPhysicalId, Lt as resetAwsClients, M as IntrinsicFunctionResolver, Mt as AssemblyReader, N as cfnRefValueFromPhysicalId, O as CloudControlProvider, Ot as MIGRATE_TMP_PREFIX, P as refStateLookupFromResource, Pt as resolveBucketRegion, Q as loadPublishableAssetManifest, Qt as ResourceUpdateNotSupportedError, R as assertRegionMatch, Rt as setAwsClients, S as red, St as resolveStateBucketWithDefault, T as collectInlinePolicyNamesManagedBySiblings, Tt as warnDeprecatedNoPrefixCliFlag, U as LockManager, Ut as LocalInvokeBuildError$1, V as DagBuilder, W as S3StateBackend, Wt as LocalMigrateError, X as buildAssetRedirectMap, Xt as ProvisioningError, Y as WorkGraph, Yt as PartialFailureError, Z as createAssetRedirectResolver, Zt as ResourceTimeoutError, _ as formatResourceLine, _t as getLegacyStateBucketName, a as DeploymentEventsStore, an as normalizeAwsError, at as validateAssetBucketName, b as gray, bt as resolveCaptureObservedState, c as withResourceDeadline, ct as formatDockerLoginError, d as IMPLICIT_DELETE_DEPENDENCIES, dt as runDockerStreaming, en as StackTerminationProtectionError, et as AssetModeResolver, f as computeImplicitDeleteEdges, ft as AssetManifestLoader, g as renderStatefulReason, gt as getDefaultStateBucketName, h as isStatefulRecreateTargetSync, ht as synthesisStatusMessage, i as DeploymentEventsReader, it as parseBootstrapMarker, j as isTerminationProtectionPropagationError, jt as expectedOwnerParam, k as slowCcOperationTimeoutMs, kt as findLargeInlineResources, l as withRetry, lt as getDockerCmd, m as MULTI_REGION_RECREATE_BLOCKED_TYPES, mt as Synthesizer, n as DEFAULT_RESOURCE_WARN_AFTER_MS, nt as ensureAssetStorage, o as planRollback, on as withErrorHandling, ot as validateContainerRepoName, p as extractDeploymentEventError, pt as getDockerImageBySourceHash, q as AssetPublisher, qt as MissingCdkCliError, r as DeployEngine, rt as getBootstrapMarkerKey, s as replayRollback, st as buildDockerImage, t as DEFAULT_RESOURCE_TIMEOUT_MS, tt as BOOTSTRAP_MARKER_PREFIX, u as isRetryableTransientError, ut as runDockerForeground, v as bold, vt as resolveApp, w as IAMRoleProvider, wt as resolveUseCdkBootstrapAssets, x as green, xt as resolveSkipPrefix, y as cyan, yt as resolveAutoAssetStorage, z as applyRoleArnIfSet } from "./deploy-engine-j-e2Q0XH.js";
2
+ import { $ as createAssetRedirectResolver, $t as ResourceTimeoutError, A as CloudControlProvider, At as MIGRATE_TMP_PREFIX, B as assertRegionMatch, Bt as setAwsClients, C as green, Ct as resolveSkipPrefix, D as collectInlinePolicyNamesManagedBySiblings, Dt as warnDeprecatedNoPrefixCliFlag, E as IAMRoleProvider, Et as resolveUseCdkBootstrapAssets, F as cfnRefValueFromPhysicalId, G as LockManager, Gt as LocalInvokeBuildError$1, H as DiffCalculator, Ht as CdkdError, I as refStateLookupFromResource, It as resolveBucketRegion, J as shouldRetainResource, K as S3StateBackend, Kt as LocalMigrateError, L as WAFv2WebACLProvider, Lt as AwsClients, M as disableInstanceApiTermination, Mt as uploadCfnTemplate, N as isTerminationProtectionPropagationError, Nt as expectedOwnerParam, O as ProviderRegistry, Ot as CFN_TEMPLATE_BODY_LIMIT, P as IntrinsicFunctionResolver, Pt as AssemblyReader, Q as buildAssetRedirectMap, Qt as ProvisioningError, R as normalizeAwsTagsToCfn, Rt as getAwsClients, S as gray, St as resolveCaptureObservedState, T as yellow, Tt as resolveStateBucketWithDefaultAndSource, U as DagBuilder, V as applyRoleArnIfSet, W as TemplateParser, X as stringifyValue, Xt as NestedStackChildDirectDestroyError, Y as AssetPublisher, Yt as MissingCdkCliError, Z as WorkGraph, Zt as PartialFailureError, _ as isStatefulRecreateTargetSync, _t as synthesisStatusMessage, a as DeploymentEventsStore, at as getBootstrapMarkerKey, b as bold, bt as resolveApp, c as replayFailedOperations, cn as withErrorHandling, ct as validateContainerRepoName, d as withRetry, dt as getDockerCmd, en as ResourceUpdateNotSupportedError, et as loadPublishableAssetManifest, f as isRetryableTransientError, ft as runDockerForeground, g as MULTI_REGION_RECREATE_BLOCKED_TYPES, gt as Synthesizer, h as extractDeploymentEventError, ht as getDockerImageBySourceHash, i as DeploymentEventsReader, it as ensureAssetStorage, j as slowCcOperationTimeoutMs, jt as findLargeInlineResources, k as findActionableSilentDrops, kt as CFN_TEMPLATE_URL_LIMIT, l as replayRollback, lt as buildDockerImage, m as computeImplicitDeleteEdges, mt as AssetManifestLoader, n as DEFAULT_RESOURCE_WARN_AFTER_MS, nn as StackTerminationProtectionError, nt as AssetModeResolver, o as planFailedOps, ot as parseBootstrapMarker, p as IMPLICIT_DELETE_DEPENDENCIES, pt as runDockerStreaming, q as rebuildClientForBucketRegion, qt as LocalStartServiceError, r as DeployEngine, rt as BOOTSTRAP_MARKER_PREFIX, s as planRollback, sn as normalizeAwsError, st as validateAssetBucketName, t as DEFAULT_RESOURCE_TIMEOUT_MS, tn as StackHasActiveImportsError, tt as rewriteTemplateAssetReferences, u as withResourceDeadline, ut as formatDockerLoginError, v as renderStatefulReason, vt as getDefaultStateBucketName, w as red, wt as resolveStateBucketWithDefault, x as cyan, xt as resolveAutoAssetStorage, y as formatResourceLine, yt as getLegacyStateBucketName, z as resolveExplicitPhysicalId, zt as resetAwsClients } from "./deploy-engine-hlS6y_-0.js";
3
3
  import { a as getLiveRenderer, c as PATTERN_B_RESOURCE_TYPES, d as generateResourceNameWithFallback, f as withSkipPrefix, i as runStackBuffered, n as getLogger, o as PATTERN_B_NAME_OPTIONS, p as withStackName, s as PATTERN_B_NAME_PROPERTIES, u as generateResourceName } from "./logger-BYMEE-BS.js";
4
- import { t as ASGProvider } from "./asg-provider-CkNAViXd.js";
4
+ import { t as ASGProvider } from "./asg-provider-B5N9p1vq.js";
5
5
  import { AsyncLocalStorage } from "node:async_hooks";
6
6
  import { createHash, randomBytes, randomUUID } from "node:crypto";
7
7
  import { CopyObjectCommand, CreateBucketCommand, DeleteBucketAnalyticsConfigurationCommand, DeleteBucketCommand, DeleteBucketCorsCommand, DeleteBucketIntelligentTieringConfigurationCommand, DeleteBucketInventoryConfigurationCommand, DeleteBucketLifecycleCommand, DeleteBucketMetricsConfigurationCommand, DeleteBucketPolicyCommand, DeleteBucketReplicationCommand, DeleteBucketTaggingCommand, DeleteBucketWebsiteCommand, DeleteObjectsCommand, GetBucketAccelerateConfigurationCommand, GetBucketCorsCommand, GetBucketEncryptionCommand, GetBucketLifecycleConfigurationCommand, GetBucketLocationCommand, GetBucketLoggingCommand, GetBucketNotificationConfigurationCommand, GetBucketPolicyCommand, GetBucketReplicationCommand, GetBucketTaggingCommand, GetBucketVersioningCommand, GetBucketWebsiteCommand, GetObjectCommand, GetObjectLockConfigurationCommand, GetPublicAccessBlockCommand, HeadBucketCommand, ListBucketAnalyticsConfigurationsCommand, ListBucketIntelligentTieringConfigurationsCommand, ListBucketInventoryConfigurationsCommand, ListBucketMetricsConfigurationsCommand, ListObjectVersionsCommand, ListObjectsV2Command, NoSuchBucket, PutBucketAccelerateConfigurationCommand, PutBucketAnalyticsConfigurationCommand, PutBucketCorsCommand, PutBucketEncryptionCommand, PutBucketIntelligentTieringConfigurationCommand, PutBucketInventoryConfigurationCommand, PutBucketLifecycleConfigurationCommand, PutBucketLoggingCommand, PutBucketMetricsConfigurationCommand, PutBucketNotificationConfigurationCommand, PutBucketOwnershipControlsCommand, PutBucketPolicyCommand, PutBucketReplicationCommand, PutBucketTaggingCommand, PutBucketVersioningCommand, PutBucketWebsiteCommand, PutObjectCommand, PutObjectLockConfigurationCommand, PutPublicAccessBlockCommand, S3Client, S3ServiceException } from "@aws-sdk/client-s3";
@@ -49508,12 +49508,25 @@ function actionLabel(item) {
49508
49508
  case "orphan-retain": return ` - orphan ${op.logicalId} (${op.resourceType}) [DeletionPolicy Retain/Snapshot — left in AWS]`;
49509
49509
  case "orphan-flag": return ` - orphan ${op.logicalId} (${op.resourceType}) [--orphan]`;
49510
49510
  case "revert": return ` - revert ${op.logicalId} (${op.resourceType})${rep}`;
49511
+ case "reverse-replacement": return ` - reverse-replace ${op.logicalId} (${op.resourceType}) [re-create old resource, delete new]`;
49512
+ case "reverse-replacement-readopt": return ` - reverse-replace ${op.logicalId} (${op.resourceType}) [delete new, re-adopt retained old resource]`;
49511
49513
  case "unrecoverable-delete": return ` - (cannot restore) ${op.logicalId} (${op.resourceType}) — was DELETED, unrecoverable`;
49512
49514
  case "skip-mismatch": return ` - skip ${op.logicalId} (${op.resourceType}) — physical id changed, needs manual attention`;
49513
49515
  case "skip-absent": return ` - skip ${op.logicalId} (${op.resourceType}) — no longer in state`;
49514
49516
  case "skip-already-done": return ` - skip ${op.logicalId} (${op.resourceType}) — already reverted`;
49515
49517
  }
49516
49518
  }
49519
+ /** Human label for a planned FAILED-op revert (issue #1198, --revert-failed). */
49520
+ function failedActionLabel(item) {
49521
+ const { op, action } = item;
49522
+ switch (action) {
49523
+ case "revert-failed-update": return ` - revert ${op.logicalId} (${op.resourceType}) [FAILED update — remote state unknown, force-applying previous properties]`;
49524
+ case "delete-failed-create": return ` - delete ${op.logicalId} (${op.resourceType}) [FAILED create]`;
49525
+ case "skip-failed-unknown": return ` - skip ${op.logicalId} (${op.resourceType}) — failed CREATE recorded no physical id`;
49526
+ case "skip-failed-noop": return ` - skip ${op.logicalId} (${op.resourceType}) — failed ${op.changeType} left nothing to revert`;
49527
+ case "skip-failed-absent": return ` - skip ${op.logicalId} (${op.resourceType}) — no previous state available`;
49528
+ }
49529
+ }
49517
49530
  async function confirm(question) {
49518
49531
  const rl = readline$1.createInterface({
49519
49532
  input: process.stdin,
@@ -49578,6 +49591,11 @@ async function rollbackCommand(stackArg, options) {
49578
49591
  for (let s = journal.segments.length - 1; s >= 0; s--) {
49579
49592
  const segment = journal.segments[s];
49580
49593
  logger.info(`\n Segment ${s + 1}/${journal.segments.length} (${segment.reason}${segment.runId ? `, run ${segment.runId}` : ""}):`);
49594
+ if (segment.failedOperations && segment.failedOperations.length > 0) if (options.revertFailed) {
49595
+ const failedPlan = planFailedOps(segment.failedOperations, planStateView);
49596
+ for (const item of failedPlan) logger.info(failedActionLabel(item));
49597
+ applyFailedPlanToPreview(failedPlan, planStateView);
49598
+ } else for (const fop of segment.failedOperations) logger.info(` - (left as-is) ${fop.logicalId} (${fop.resourceType}) — its ${fop.changeType} FAILED mid-deploy; pass --revert-failed to attempt reverting it`);
49581
49599
  const plan = planRollback(segment.operations, planStateView, orphanLogicalIds);
49582
49600
  for (const item of plan) logger.info(actionLabel(item));
49583
49601
  applyPlanToPreview(plan, planStateView);
@@ -49639,11 +49657,42 @@ async function rollbackCommand(stackArg, options) {
49639
49657
  stateBucket: setup.bucket,
49640
49658
  exportIndexStore: setup.exportIndexStore,
49641
49659
  destroyOptions: { ...options.profile && { profile: options.profile } }
49642
- }, () => withStackName(stackName, () => replayRollback(segment.operations, stateResources, stackName, ctx, {
49643
- orphanLogicalIds,
49644
- afterOp: saveState,
49645
- isInterrupted: () => interrupted
49646
- })));
49660
+ }, () => withStackName(stackName, async () => {
49661
+ let failedOpFailures = 0;
49662
+ let failedOpWarnings = 0;
49663
+ if (options.revertFailed && segment.failedOperations && segment.failedOperations.length > 0) {
49664
+ const failedResult = await replayFailedOperations(segment.failedOperations, stateResources, stackName, ctx, {
49665
+ afterOp: saveState,
49666
+ isInterrupted: () => interrupted,
49667
+ emitEnvelope: segment.operations.length === 0
49668
+ });
49669
+ failedOpFailures = failedResult.failures;
49670
+ failedOpWarnings = failedResult.warnings;
49671
+ const remaining = failedResult.remainingFailedOps;
49672
+ if (remaining.length !== segment.failedOperations.length) try {
49673
+ await setup.stateBackend.setRollbackJournalFailedOperations(stackName, region, remaining);
49674
+ if (remaining.length === 0) delete segment.failedOperations;
49675
+ else segment.failedOperations = remaining;
49676
+ } catch (stripError) {
49677
+ logger.warn(`Failed to strip replayed failed-ops from the journal: ${stripError instanceof Error ? stripError.message : String(stripError)}`);
49678
+ }
49679
+ if (failedResult.interrupted) return {
49680
+ failures: failedOpFailures,
49681
+ warnings: failedOpWarnings,
49682
+ interrupted: true
49683
+ };
49684
+ }
49685
+ const replayResult = await replayRollback(segment.operations, stateResources, stackName, ctx, {
49686
+ orphanLogicalIds,
49687
+ afterOp: saveState,
49688
+ isInterrupted: () => interrupted
49689
+ });
49690
+ return {
49691
+ failures: replayResult.failures + failedOpFailures,
49692
+ warnings: replayResult.warnings + failedOpWarnings,
49693
+ interrupted: replayResult.interrupted
49694
+ };
49695
+ }));
49647
49696
  totalFailures += result.failures;
49648
49697
  totalWarnings += result.warnings;
49649
49698
  if (result.interrupted) {
@@ -49690,6 +49739,26 @@ function applyPlanToPreview(plan, previewState) {
49690
49739
  if (op.changeType === "CREATE") delete previewState[op.logicalId];
49691
49740
  break;
49692
49741
  case "revert":
49742
+ case "reverse-replacement":
49743
+ case "reverse-replacement-readopt":
49744
+ if (op.previousState) previewState[op.logicalId] = op.previousState;
49745
+ break;
49746
+ default: break;
49747
+ }
49748
+ }
49749
+ }
49750
+ /**
49751
+ * Apply a planned FAILED-op revert's effect to the plan-preview state
49752
+ * (issue #1198). Mirrors `replayFailedOperations` without touching AWS.
49753
+ */
49754
+ function applyFailedPlanToPreview(plan, previewState) {
49755
+ for (const item of plan) {
49756
+ const { op, action } = item;
49757
+ switch (action) {
49758
+ case "delete-failed-create":
49759
+ delete previewState[op.logicalId];
49760
+ break;
49761
+ case "revert-failed-update":
49693
49762
  if (op.previousState) previewState[op.logicalId] = op.previousState;
49694
49763
  break;
49695
49764
  default: break;
@@ -49697,13 +49766,14 @@ function applyPlanToPreview(plan, previewState) {
49697
49766
  }
49698
49767
  }
49699
49768
  function createRollbackCommand() {
49700
- const cmd = new Command("rollback").description("Revert a stack to its pre-deploy state after a failed --no-rollback / interrupted deploy or a partially-failed automatic rollback (state-driven, no synth needed).").argument("[stack]", "Stack name to roll back (defaults to the single journaled stack)").addOption(new Option("--force", "Skip the confirmation prompt").default(false)).addOption(new Option("--orphan <logicalId>", "Skip the given resource during replay (repeatable). Mirrors cdk rollback --orphan.").argParser((value, previous) => [...previous ?? [], value])).addOption(stackRegionOption()).addHelpText("after", [
49769
+ const cmd = new Command("rollback").description("Revert a stack to its pre-deploy state after a failed --no-rollback / interrupted deploy or a partially-failed automatic rollback (state-driven, no synth needed).").argument("[stack]", "Stack name to roll back (defaults to the single journaled stack)").addOption(new Option("--force", "Skip the confirmation prompt").default(false)).addOption(new Option("--orphan <logicalId>", "Skip the given resource during replay (repeatable). Mirrors cdk rollback --orphan.").argParser((value, previous) => [...previous ?? [], value])).addOption(new Option("--revert-failed", "Also attempt to revert the resource whose operation FAILED mid-deploy. Off by default: the remote state of the failed resource is unknown, so force-applying its previous state is opt-in.").default(false)).addOption(stackRegionOption()).addHelpText("after", [
49701
49770
  "",
49702
49771
  "Examples:",
49703
49772
  " cdkd rollback MyStack",
49704
49773
  " cdkd rollback # single journaled stack",
49705
49774
  " cdkd rollback MyStack --force",
49706
49775
  " cdkd rollback MyStack --orphan MyBucket --orphan MyTable",
49776
+ " cdkd rollback MyStack --revert-failed # also revert the failed in-flight resource",
49707
49777
  " cdkd rollback MyStack --stack-region us-west-2",
49708
49778
  "",
49709
49779
  "Exit codes: 0 = clean, 2 = partial (journal kept for re-run), 1 = hard error."
@@ -61883,7 +61953,7 @@ function createMigrateCommand() {
61883
61953
  */
61884
61954
  function buildProgram() {
61885
61955
  const program = new Command();
61886
- program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.263.2");
61956
+ program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.264.0");
61887
61957
  program.hook("preAction", (_thisCommand, actionCommand) => {
61888
61958
  const { profile } = actionCommand.optsWithGlobals();
61889
61959
  if (profile !== void 0) process.env["AWS_PROFILE"] = profile;