@aws-blocks/core 0.2.0 → 0.3.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.
Files changed (123) hide show
  1. package/dist/cdk/blocks-backend.d.ts +35 -9
  2. package/dist/cdk/blocks-backend.d.ts.map +1 -1
  3. package/dist/cdk/blocks-backend.js +52 -69
  4. package/dist/cdk/blocks-backend.test.js +61 -69
  5. package/dist/cdk/blocks-defaults.d.ts +27 -1
  6. package/dist/cdk/blocks-defaults.d.ts.map +1 -1
  7. package/dist/cdk/blocks-defaults.js +5 -1
  8. package/dist/cdk/blocks-defaults.test.js +4 -2
  9. package/dist/cdk/blocks-stack.test.js +73 -37
  10. package/dist/cdk/compute/default-compute-factory.d.ts +33 -0
  11. package/dist/cdk/compute/default-compute-factory.d.ts.map +1 -0
  12. package/dist/cdk/compute/default-compute-factory.js +3 -0
  13. package/dist/cdk/index.d.ts +46 -5
  14. package/dist/cdk/index.d.ts.map +1 -1
  15. package/dist/cdk/index.js +57 -7
  16. package/dist/cdk/internal.d.ts +1 -0
  17. package/dist/cdk/internal.d.ts.map +1 -1
  18. package/dist/hosting-secrets.d.ts +48 -0
  19. package/dist/hosting-secrets.d.ts.map +1 -0
  20. package/dist/hosting-secrets.js +57 -0
  21. package/dist/hosting-secrets.test.d.ts +2 -0
  22. package/dist/hosting-secrets.test.d.ts.map +1 -0
  23. package/dist/hosting-secrets.test.js +81 -0
  24. package/dist/hosting.d.ts +88 -6
  25. package/dist/hosting.d.ts.map +1 -1
  26. package/dist/hosting.js +83 -24
  27. package/dist/hosting.test.js +158 -10
  28. package/dist/index.cdk.d.ts +13 -12
  29. package/dist/index.cdk.d.ts.map +1 -1
  30. package/dist/index.cdk.js +13 -9
  31. package/dist/index.d.ts +8 -7
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +9 -5
  34. package/dist/lambda-handler.test.js +66 -0
  35. package/dist/pipeline/index.d.ts +24 -2
  36. package/dist/pipeline/index.d.ts.map +1 -1
  37. package/dist/pipeline/index.js +41 -1
  38. package/dist/pipeline.test.d.ts +2 -0
  39. package/dist/pipeline.test.d.ts.map +1 -0
  40. package/dist/pipeline.test.js +47 -0
  41. package/dist/rpc.d.ts +21 -0
  42. package/dist/rpc.d.ts.map +1 -1
  43. package/dist/rpc.js +34 -0
  44. package/dist/rpc.test.js +38 -1
  45. package/dist/scripts/config.d.ts +15 -0
  46. package/dist/scripts/config.d.ts.map +1 -0
  47. package/dist/scripts/config.js +29 -0
  48. package/dist/scripts/deploy.d.ts.map +1 -1
  49. package/dist/scripts/deploy.js +4 -0
  50. package/dist/scripts/dev-server.d.ts +8 -0
  51. package/dist/scripts/dev-server.d.ts.map +1 -1
  52. package/dist/scripts/dev-server.js +31 -0
  53. package/dist/scripts/generate-client.d.ts.map +1 -1
  54. package/dist/scripts/generate-client.js +9 -4
  55. package/dist/scripts/generate-client.test.js +19 -4
  56. package/dist/scripts/index.d.ts +13 -10
  57. package/dist/scripts/index.d.ts.map +1 -1
  58. package/dist/scripts/index.js +11 -8
  59. package/dist/scripts/preflight-credentials.d.ts +30 -0
  60. package/dist/scripts/preflight-credentials.d.ts.map +1 -0
  61. package/dist/scripts/preflight-credentials.js +108 -0
  62. package/dist/scripts/preflight-credentials.test.d.ts +2 -0
  63. package/dist/scripts/preflight-credentials.test.d.ts.map +1 -0
  64. package/dist/scripts/preflight-credentials.test.js +77 -0
  65. package/dist/scripts/sandbox-args.test.d.ts +2 -0
  66. package/dist/scripts/sandbox-args.test.d.ts.map +1 -0
  67. package/dist/scripts/sandbox-args.test.js +77 -0
  68. package/dist/scripts/sandbox.d.ts +52 -0
  69. package/dist/scripts/sandbox.d.ts.map +1 -1
  70. package/dist/scripts/sandbox.js +92 -15
  71. package/dist/scripts/secret.d.ts +15 -0
  72. package/dist/scripts/secret.d.ts.map +1 -0
  73. package/dist/scripts/secret.js +29 -0
  74. package/dist/scripts/secret.test.d.ts +2 -0
  75. package/dist/scripts/secret.test.d.ts.map +1 -0
  76. package/dist/scripts/secret.test.js +28 -0
  77. package/dist/scripts/typegen.d.ts +15 -0
  78. package/dist/scripts/typegen.d.ts.map +1 -0
  79. package/dist/scripts/typegen.js +16 -0
  80. package/dist/secret-naming.d.ts +58 -0
  81. package/dist/secret-naming.d.ts.map +1 -0
  82. package/dist/secret-naming.js +67 -0
  83. package/dist/secret-naming.test.d.ts +2 -0
  84. package/dist/secret-naming.test.d.ts.map +1 -0
  85. package/dist/secret-naming.test.js +40 -0
  86. package/dist/version.d.ts +1 -1
  87. package/dist/version.js +1 -1
  88. package/package.json +2 -1
  89. package/src/cdk/blocks-backend.test.ts +267 -272
  90. package/src/cdk/blocks-backend.ts +71 -79
  91. package/src/cdk/blocks-defaults.test.ts +4 -2
  92. package/src/cdk/blocks-defaults.ts +27 -1
  93. package/src/cdk/blocks-stack.test.ts +161 -118
  94. package/src/cdk/compute/default-compute-factory.ts +37 -0
  95. package/src/cdk/index.ts +84 -8
  96. package/src/cdk/internal.ts +1 -0
  97. package/src/hosting-secrets.test.ts +106 -0
  98. package/src/hosting-secrets.ts +106 -0
  99. package/src/hosting.test.ts +244 -63
  100. package/src/hosting.ts +180 -68
  101. package/src/index.cdk.ts +77 -38
  102. package/src/index.ts +35 -16
  103. package/src/lambda-handler.test.ts +74 -0
  104. package/src/pipeline/index.ts +64 -11
  105. package/src/pipeline.test.ts +55 -0
  106. package/src/rpc.test.ts +44 -1
  107. package/src/rpc.ts +41 -0
  108. package/src/scripts/config.ts +35 -0
  109. package/src/scripts/deploy.ts +5 -0
  110. package/src/scripts/dev-server.ts +40 -0
  111. package/src/scripts/generate-client.test.ts +43 -8
  112. package/src/scripts/generate-client.ts +70 -65
  113. package/src/scripts/index.ts +20 -17
  114. package/src/scripts/preflight-credentials.test.ts +110 -0
  115. package/src/scripts/preflight-credentials.ts +131 -0
  116. package/src/scripts/sandbox-args.test.ts +92 -0
  117. package/src/scripts/sandbox.ts +102 -15
  118. package/src/scripts/secret.test.ts +35 -0
  119. package/src/scripts/secret.ts +35 -0
  120. package/src/scripts/typegen.ts +18 -0
  121. package/src/secret-naming.test.ts +59 -0
  122. package/src/secret-naming.ts +99 -0
  123. package/src/version.ts +1 -1
@@ -1,13 +1,16 @@
1
- export { startDevServer, type DevServerOptions } from './dev-server.js';
2
- export { startSandbox, destroySandbox, type SandboxOptions } from './sandbox.js';
1
+ export { type BuildAndSendEventOptions, buildAndSendEvent, type CommandName, type CommandState, classifyError, trackCommand, } from '../telemetry/index.js';
2
+ export { listConfig, removeConfig, runConfigCli, setConfig } from './config.js';
3
+ export { type ConsoleOptions, openConsole } from './console.js';
4
+ export { type DeployOptions, deploy } from './deploy.js';
5
+ export { type DestroyOptions, destroy } from './destroy.js';
6
+ export { type DevServerOptions, startDevServer } from './dev-server.js';
7
+ export { ensureSecrets, loadEnvFile, loadProductionEnv } from './ensure-secrets.js';
3
8
  export { generateClientCode, writeClientCode } from './generate-client.js';
4
9
  export { generateSpec, writeSpec } from './generate-spec.js';
5
- export { validateSpec, type SpecValidationError } from './validate-spec.js';
6
- export { deploy, type DeployOptions } from './deploy.js';
7
- export { destroy, type DestroyOptions } from './destroy.js';
8
- export { openConsole, type ConsoleOptions } from './console.js';
9
- export { ensureSecrets, loadProductionEnv, loadEnvFile } from './ensure-secrets.js';
10
- export { trackCommand, buildAndSendEvent, classifyError, type CommandName, type CommandState, type BuildAndSendEventOptions, } from '../telemetry/index.js';
11
- export { telemetry, type TelemetryOptions } from './telemetry.js';
12
- export { getStackId, getSandboxId, getStackName } from './stack-id.js';
10
+ export { destroySandbox, type SandboxOptions, startSandbox } from './sandbox.js';
11
+ export { listSecrets, removeSecret, runSecretCli, setSecret } from './secret.js';
12
+ export { getSandboxId, getStackId, getStackName } from './stack-id.js';
13
+ export { type TelemetryOptions, telemetry } from './telemetry.js';
14
+ export { runTypegenCli } from './typegen.js';
15
+ export { type SpecValidationError, validateSpec } from './validate-spec.js';
13
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACpF,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,wBAAwB,GAC9B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,aAAa,EACb,YAAY,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,KAAK,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,KAAK,cAAc,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,KAAK,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,KAAK,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
@@ -1,14 +1,17 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+ export { buildAndSendEvent, classifyError, trackCommand, } from '../telemetry/index.js';
4
+ export { listConfig, removeConfig, runConfigCli, setConfig } from './config.js';
5
+ export { openConsole } from './console.js';
6
+ export { deploy } from './deploy.js';
7
+ export { destroy } from './destroy.js';
3
8
  export { startDevServer } from './dev-server.js';
4
- export { startSandbox, destroySandbox } from './sandbox.js';
9
+ export { ensureSecrets, loadEnvFile, loadProductionEnv } from './ensure-secrets.js';
5
10
  export { generateClientCode, writeClientCode } from './generate-client.js';
6
11
  export { generateSpec, writeSpec } from './generate-spec.js';
7
- export { validateSpec } from './validate-spec.js';
8
- export { deploy } from './deploy.js';
9
- export { destroy } from './destroy.js';
10
- export { openConsole } from './console.js';
11
- export { ensureSecrets, loadProductionEnv, loadEnvFile } from './ensure-secrets.js';
12
- export { trackCommand, buildAndSendEvent, classifyError, } from '../telemetry/index.js';
12
+ export { destroySandbox, startSandbox } from './sandbox.js';
13
+ export { listSecrets, removeSecret, runSecretCli, setSecret } from './secret.js';
14
+ export { getSandboxId, getStackId, getStackName } from './stack-id.js';
13
15
  export { telemetry } from './telemetry.js';
14
- export { getStackId, getSandboxId, getStackName } from './stack-id.js';
16
+ export { runTypegenCli } from './typegen.js';
17
+ export { validateSpec } from './validate-spec.js';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Resolve the region for the STS probe from the environment. Returns `null`
3
+ * when neither `AWS_REGION` nor `AWS_DEFAULT_REGION` is set — the caller then
4
+ * skips the probe rather than guessing a region, because a hardcoded guess
5
+ * (e.g. `us-east-1`) belongs to a different **partition** than GovCloud
6
+ * (`us-gov-*`) or China (`cn-*`) and would fail against a partition the user
7
+ * isn't even deploying to.
8
+ */
9
+ export declare function resolveProbeRegion(env?: NodeJS.ProcessEnv): string | null;
10
+ /**
11
+ * Probe that resolves when valid AWS credentials are available for `region` and
12
+ * rejects otherwise. Injectable so the guard can be unit-tested without network
13
+ * or real credentials; production callers use the default {@link stsProbe}.
14
+ */
15
+ export type CredentialProbe = (region: string) => Promise<void>;
16
+ /**
17
+ * Verify AWS credentials before a deploy command spends time synthesizing, and
18
+ * fail fast with actionable guidance when they're missing, expired, or invalid.
19
+ *
20
+ * Skips silently (with a warning) when no region can be resolved from the
21
+ * environment, and treats network/service errors as non-fatal — see the module
22
+ * doc for the rationale.
23
+ *
24
+ * @param command - The npm script name, used in the messages (e.g. `sandbox`, `deploy`).
25
+ * @param probe - Credential probe; defaults to STS GetCallerIdentity. Override in tests.
26
+ * @param env - Environment to resolve the region from. Defaults to `process.env`.
27
+ * @throws {Error} With actionable guidance when the probe reports a credential error.
28
+ */
29
+ export declare function assertAwsCredentials(command: string, probe?: CredentialProbe, env?: NodeJS.ProcessEnv): Promise<void>;
30
+ //# sourceMappingURL=preflight-credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preflight-credentials.d.ts","sourceRoot":"","sources":["../../src/scripts/preflight-credentials.ts"],"names":[],"mappings":"AAmCA;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,GAAG,IAAI,CAEtF;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAyBhE;;;;;;;;;;;;GAYG;AACH,wBAAsB,oBAAoB,CACzC,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,eAA0B,EACjC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAClC,OAAO,CAAC,IAAI,CAAC,CAoCf"}
@@ -0,0 +1,108 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * Pre-deploy AWS credential check.
5
+ *
6
+ * `cdk deploy` spends ~10 seconds synthesizing the app before it makes its
7
+ * first AWS call, so a missing or expired credential surfaces only *after* that
8
+ * wasted synth — as an opaque CDK/CloudFormation error that doesn't name the
9
+ * real cause. Calling STS GetCallerIdentity up front turns that into an
10
+ * immediate, actionable message the moment a deploy command starts.
11
+ *
12
+ * The check is intentionally conservative: it fails fast **only** on a real
13
+ * credential problem (missing/expired/invalid). A network or service error
14
+ * (STS unreachable, throttled, disabled in a region) is not treated as a
15
+ * credential failure — it warns and lets the deploy proceed, since blocking on
16
+ * an unverifiable probe would reject a deploy that might have worked.
17
+ */
18
+ /**
19
+ * Error `name`s that mean the credentials themselves are missing, expired, or
20
+ * invalid — the cases where the "configure your credentials" remediation is
21
+ * correct. Anything else (network, throttling, an explicit `AccessDenied` — which
22
+ * actually proves the identity resolved) is surfaced as itself instead.
23
+ */
24
+ const CREDENTIAL_ERROR_NAMES = new Set([
25
+ 'CredentialsProviderError',
26
+ 'ExpiredToken',
27
+ 'ExpiredTokenException',
28
+ 'InvalidClientTokenId',
29
+ 'UnrecognizedClientException',
30
+ 'SignatureDoesNotMatch',
31
+ 'TokenRefreshRequired',
32
+ ]);
33
+ /**
34
+ * Resolve the region for the STS probe from the environment. Returns `null`
35
+ * when neither `AWS_REGION` nor `AWS_DEFAULT_REGION` is set — the caller then
36
+ * skips the probe rather than guessing a region, because a hardcoded guess
37
+ * (e.g. `us-east-1`) belongs to a different **partition** than GovCloud
38
+ * (`us-gov-*`) or China (`cn-*`) and would fail against a partition the user
39
+ * isn't even deploying to.
40
+ */
41
+ export function resolveProbeRegion(env = process.env) {
42
+ return env.AWS_REGION || env.AWS_DEFAULT_REGION || null;
43
+ }
44
+ /**
45
+ * Default probe: STS GetCallerIdentity via the SDK's standard credential chain
46
+ * (env vars, shared config/credentials, SSO, container/instance roles).
47
+ *
48
+ * Dynamically imported so the STS client is only loaded when a deploy actually
49
+ * runs — never during dev-server startup or a mock unit test. Bounded with a
50
+ * short request timeout and a single attempt (matching `common/config.ts`) so a
51
+ * bad network can't make this hang *longer* than the synth it's replacing.
52
+ */
53
+ const stsProbe = async (region) => {
54
+ const { STSClient, GetCallerIdentityCommand } = await import('@aws-sdk/client-sts');
55
+ const client = new STSClient({
56
+ region,
57
+ maxAttempts: 1,
58
+ requestHandler: { connectionTimeout: 2000, requestTimeout: 3000 },
59
+ });
60
+ try {
61
+ await client.send(new GetCallerIdentityCommand({}));
62
+ }
63
+ finally {
64
+ client.destroy();
65
+ }
66
+ };
67
+ /**
68
+ * Verify AWS credentials before a deploy command spends time synthesizing, and
69
+ * fail fast with actionable guidance when they're missing, expired, or invalid.
70
+ *
71
+ * Skips silently (with a warning) when no region can be resolved from the
72
+ * environment, and treats network/service errors as non-fatal — see the module
73
+ * doc for the rationale.
74
+ *
75
+ * @param command - The npm script name, used in the messages (e.g. `sandbox`, `deploy`).
76
+ * @param probe - Credential probe; defaults to STS GetCallerIdentity. Override in tests.
77
+ * @param env - Environment to resolve the region from. Defaults to `process.env`.
78
+ * @throws {Error} With actionable guidance when the probe reports a credential error.
79
+ */
80
+ export async function assertAwsCredentials(command, probe = stsProbe, env = process.env) {
81
+ const region = resolveProbeRegion(env);
82
+ if (!region) {
83
+ console.warn(`⚠️ Skipping the AWS credential pre-check for \`npm run ${command}\`: ` +
84
+ 'no region set in AWS_REGION / AWS_DEFAULT_REGION. The deploy will surface any credential error itself.');
85
+ return;
86
+ }
87
+ try {
88
+ await probe(region);
89
+ }
90
+ catch (error) {
91
+ // Use the error *name* only — never the raw message, which for an STS
92
+ // authorization failure embeds the caller ARN and account id (and this
93
+ // Error propagates through telemetry).
94
+ const name = error instanceof Error && error.name ? error.name : 'UnknownError';
95
+ if (CREDENTIAL_ERROR_NAMES.has(name)) {
96
+ throw new Error(`AWS credentials could not be verified for \`npm run ${command}\` (${name}).\n` +
97
+ 'Configure AWS credentials — for example:\n' +
98
+ ' • run `aws configure` (or `aws sso login`), or\n' +
99
+ ' • set AWS_PROFILE to a configured profile, or\n' +
100
+ ' • export AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY (and AWS_SESSION_TOKEN for temporary credentials).\n' +
101
+ `Then re-run \`npm run ${command}\`.`);
102
+ }
103
+ // Not a credential problem (network, throttling, STS disabled in-region, …).
104
+ // Don't block a deploy that might still work — warn and continue.
105
+ console.warn(`⚠️ Could not verify AWS credentials for \`npm run ${command}\` (${name}); ` +
106
+ 'continuing — the deploy will report any real error.');
107
+ }
108
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=preflight-credentials.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preflight-credentials.test.d.ts","sourceRoot":"","sources":["../../src/scripts/preflight-credentials.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,77 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import assert from 'node:assert';
4
+ import { describe, it, mock } from 'node:test';
5
+ import { assertAwsCredentials, resolveProbeRegion } from './preflight-credentials.js';
6
+ const REGION_ENV = { AWS_REGION: 'us-east-1' };
7
+ /** Build an Error with a specific `name`, as the AWS SDK throws. */
8
+ function namedError(name, message = 'raw sdk detail') {
9
+ const err = new Error(message);
10
+ err.name = name;
11
+ return err;
12
+ }
13
+ describe('resolveProbeRegion', () => {
14
+ it('prefers AWS_REGION', () => {
15
+ assert.strictEqual(resolveProbeRegion({ AWS_REGION: 'eu-west-1', AWS_DEFAULT_REGION: 'us-east-2' }), 'eu-west-1');
16
+ });
17
+ it('falls back to AWS_DEFAULT_REGION', () => {
18
+ assert.strictEqual(resolveProbeRegion({ AWS_DEFAULT_REGION: 'ap-south-1' }), 'ap-south-1');
19
+ });
20
+ it('returns null when neither is set (caller then skips the probe)', () => {
21
+ assert.strictEqual(resolveProbeRegion({}), null);
22
+ });
23
+ });
24
+ describe('assertAwsCredentials', () => {
25
+ it('resolves silently when the credential probe succeeds', async () => {
26
+ let calledRegion;
27
+ await assert.doesNotReject(() => assertAwsCredentials('sandbox', async (region) => {
28
+ calledRegion = region;
29
+ }, REGION_ENV));
30
+ assert.strictEqual(calledRegion, 'us-east-1');
31
+ });
32
+ it('throws actionable guidance on a real credential error, naming the command', async () => {
33
+ await assert.rejects(() => assertAwsCredentials('sandbox', async () => { throw namedError('CredentialsProviderError'); }, REGION_ENV), (err) => {
34
+ assert.match(err.message, /npm run sandbox/);
35
+ assert.match(err.message, /aws configure|AWS_PROFILE|AWS_ACCESS_KEY_ID/);
36
+ assert.match(err.message, /CredentialsProviderError/); // the name, for debugging
37
+ return true;
38
+ });
39
+ });
40
+ it('treats an expired token as a credential error', async () => {
41
+ await assert.rejects(() => assertAwsCredentials('deploy', async () => { throw namedError('ExpiredToken'); }, REGION_ENV), (err) => {
42
+ assert.match(err.message, /npm run deploy/);
43
+ assert.match(err.message, /aws sso login|AWS_PROFILE/);
44
+ return true;
45
+ });
46
+ });
47
+ it('does NOT leak the raw error message (ARN / account id)', async () => {
48
+ const arnMessage = 'User: arn:aws:iam::123456789012:user/alice is not authorized to perform sts:GetCallerIdentity';
49
+ await assert.rejects(() => assertAwsCredentials('deploy', async () => { throw namedError('InvalidClientTokenId', arnMessage); }, REGION_ENV), (err) => {
50
+ assert.doesNotMatch(err.message, /arn:aws:iam/);
51
+ assert.doesNotMatch(err.message, /123456789012/);
52
+ return true;
53
+ });
54
+ });
55
+ it('does not throw on a network/service error — warns and continues', async () => {
56
+ const warn = mock.method(console, 'warn', () => { });
57
+ try {
58
+ await assert.doesNotReject(() => assertAwsCredentials('sandbox', async () => { throw namedError('TimeoutError'); }, REGION_ENV));
59
+ assert.ok(warn.mock.calls.some((c) => String(c.arguments[0]).includes('Could not verify')), 'should warn that credentials could not be verified');
60
+ }
61
+ finally {
62
+ warn.mock.restore();
63
+ }
64
+ });
65
+ it('skips the probe (with a warning) when no region is resolvable', async () => {
66
+ const warn = mock.method(console, 'warn', () => { });
67
+ let probed = false;
68
+ try {
69
+ await assertAwsCredentials('sandbox', async () => { probed = true; }, {});
70
+ assert.strictEqual(probed, false, 'probe must not run without a region');
71
+ assert.ok(warn.mock.calls.some((c) => String(c.arguments[0]).includes('Skipping the AWS credential pre-check')), 'should warn that the pre-check was skipped');
72
+ }
73
+ finally {
74
+ warn.mock.restore();
75
+ }
76
+ });
77
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sandbox-args.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-args.test.d.ts","sourceRoot":"","sources":["../../src/scripts/sandbox-args.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,77 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { describe, it } from 'node:test';
4
+ import assert from 'node:assert';
5
+ import { buildSandboxDeployArgs, sandboxFailureRecoveryHint } from './sandbox.js';
6
+ import { buildCdkDeployArgs } from './deploy-stream.js';
7
+ /**
8
+ * Return the value that follows `flag` in `args`, failing with a clear message
9
+ * if the flag is absent. Reading `args[indexOf(flag) + 1]` directly silently
10
+ * reads `args[0]` when the flag is missing (indexOf returns -1), which turns a
11
+ * dropped flag into a confusing value mismatch instead of a "flag missing".
12
+ *
13
+ * NOTE: resolves only the FIRST occurrence of `flag`. `--context` legitimately
14
+ * appears twice in this argv (projectRoot, then sandboxMode=true), so do not
15
+ * use `valueAfter(args, '--context')` expecting the second value — it silently
16
+ * returns the first. Assert repeated flags with `args.includes(...)` instead.
17
+ */
18
+ function valueAfter(args, flag) {
19
+ const i = args.indexOf(flag);
20
+ assert.ok(i !== -1, `expected ${flag} in: ${args.join(' ')}`);
21
+ return args[i + 1];
22
+ }
23
+ describe('buildSandboxDeployArgs — express mode (sandbox only)', () => {
24
+ const args = buildSandboxDeployArgs({
25
+ outDir: '.blocks-sandbox',
26
+ projectRoot: '/app',
27
+ backendPath: 'aws-blocks/index.ts',
28
+ });
29
+ it('enables CloudFormation Express Mode via --express', () => {
30
+ assert.ok(args.includes('--express'), `expected --express in: ${args.join(' ')}`);
31
+ });
32
+ it('pairs express mode with the direct deployment method', () => {
33
+ assert.strictEqual(valueAfter(args, '--method'), 'direct');
34
+ });
35
+ it('leaves express-mode rollback at its default (off) — no --rollback', () => {
36
+ // Express Mode disables automatic rollback by default; we keep that default
37
+ // for the throwaway sandbox loop. Passing --rollback here would silently
38
+ // give up the speedup.
39
+ assert.ok(!args.includes('--rollback'), `sandbox must not force --rollback: ${args.join(' ')}`);
40
+ });
41
+ it('deploys every stack so Lambda@Edge apps synth cleanly', () => {
42
+ assert.ok(args.includes('--all'), `expected --all in: ${args.join(' ')}`);
43
+ });
44
+ it('keeps the non-interactive deploy contract and sandbox context', () => {
45
+ assert.deepStrictEqual(args.slice(0, 4), ['exec', 'cdk', '--', 'deploy']);
46
+ assert.strictEqual(valueAfter(args, '--require-approval'), 'never');
47
+ assert.strictEqual(valueAfter(args, '--outputs-file'), '.blocks-sandbox/outputs.json');
48
+ assert.ok(args.includes('sandboxMode=true'), `expected sandboxMode=true in: ${args.join(' ')}`);
49
+ assert.strictEqual(valueAfter(args, '--app'), 'npm exec tsx -- -C cdk aws-blocks/index.ts');
50
+ });
51
+ it('interpolates the provided outDir and projectRoot', () => {
52
+ const custom = buildSandboxDeployArgs({ outDir: 'out', projectRoot: '/other', backendPath: 'b.ts' });
53
+ assert.strictEqual(valueAfter(custom, '--outputs-file'), 'out/outputs.json');
54
+ assert.strictEqual(valueAfter(custom, '--context'), 'projectRoot=/other');
55
+ });
56
+ it('does NOT leak express mode into the production deploy path', () => {
57
+ // A production deploy must keep a reviewable change set and full
58
+ // stabilization with rollback: neither `--express` nor `--method direct`
59
+ // (both sandbox-only speedups) may appear in buildCdkDeployArgs.
60
+ const prod = buildCdkDeployArgs({ projectRoot: '/app', outputsFile: '.blocks-sandbox/outputs.json' });
61
+ assert.ok(!prod.includes('--express'), `production deploy must not use --express: ${prod.join(' ')}`);
62
+ assert.ok(!prod.includes('--method'), `production deploy must not use --method: ${prod.join(' ')}`);
63
+ });
64
+ });
65
+ describe('sandboxFailureRecoveryHint — no silent dead-end after a failed express deploy', () => {
66
+ const hint = sandboxFailureRecoveryHint();
67
+ it('points to the repo-native destroy + redeploy recovery', () => {
68
+ assert.match(hint, /npm run sandbox:destroy/);
69
+ assert.match(hint, /npm run sandbox\b/);
70
+ });
71
+ it('covers the manual UPDATE_ROLLBACK_FAILED escape hatch', () => {
72
+ assert.match(hint, /continue-update-rollback/);
73
+ });
74
+ it('explains why (rollback is off under express mode)', () => {
75
+ assert.match(hint, /rollback is off|automatic rollback/i);
76
+ });
77
+ });
@@ -6,6 +6,58 @@ export interface SandboxOptions {
6
6
  /** Custom dev server command. Defaults to 'npx vite'. For Next.js use 'npx next dev'. */
7
7
  devCommand?: string;
8
8
  }
9
+ export interface SandboxDeployArgsOptions {
10
+ /** Directory CDK writes stack outputs to (relative to the project root). */
11
+ outDir: string;
12
+ /** Project root passed to synth as `--context projectRoot=…` (usually `process.cwd()`). */
13
+ projectRoot: string;
14
+ /** Backend entry passed to `--app` so CDK synthesizes from the app definition. */
15
+ backendPath: string;
16
+ }
17
+ /**
18
+ * Build the `npm exec cdk -- deploy …` argv used by the sandbox deploy.
19
+ *
20
+ * Kept pure (no I/O) so the argv contract — in particular the flags below — can
21
+ * be asserted directly, the same way {@link buildCdkDeployArgs} is for the
22
+ * production path.
23
+ *
24
+ * - `--all`: an app that uses Lambda@Edge (e.g. a Next.js route with
25
+ * `export const runtime = 'edge'`) synthesizes a SECOND stack
26
+ * (`edge-lambda-stack-*`, region us-east-1) in addition to the main hosting
27
+ * stack. Without `--all`, CDK refuses with "specify which stacks to use".
28
+ * Deploying every stack in a sandbox app is the intended behavior.
29
+ * - `--method direct`: skip CloudFormation change-set creation and call
30
+ * UpdateStack directly. This is the baseline sandbox deployment method that
31
+ * `--express` builds on.
32
+ * - `--express` (**CloudFormation Express Mode — sandbox only**): the real
33
+ * speedup. CloudFormation reports each stack operation complete as soon as
34
+ * the resource's configuration is applied, WITHOUT waiting for full
35
+ * stabilization. Because it skips stabilization it also disables automatic
36
+ * rollback by default, so a failed deploy can leave the stack in a failed
37
+ * state — acceptable for the throwaway sandbox iteration loop, never for
38
+ * production. We leave rollback at Express Mode's default (off) and do NOT
39
+ * pass `--rollback`. The production deploy path (`deploy.ts`) deliberately
40
+ * uses neither `--express` nor `--method direct`: it keeps a reviewable
41
+ * change set and full stabilization with rollback, which are exactly the
42
+ * safety signals a production deploy should keep. Requires an aws-cdk CLI
43
+ * new enough to expose `--express`; our pinned `^2.1138.0` has it.
44
+ */
45
+ export declare function buildSandboxDeployArgs({ outDir, projectRoot, backendPath }: SandboxDeployArgsOptions): string[];
46
+ /**
47
+ * Operator-facing recovery guidance printed when a sandbox deploy fails.
48
+ *
49
+ * Express Mode (see {@link buildSandboxDeployArgs}) disables CloudFormation's
50
+ * automatic rollback, so a failed deploy does NOT clean up after itself: a
51
+ * failed *first* deploy leaves the stack in `CREATE_FAILED`/`ROLLBACK_COMPLETE`
52
+ * and a failed update can land in `UPDATE_ROLLBACK_FAILED`. In those states
53
+ * CloudFormation refuses the next `UpdateStack`, so a plain re-run of
54
+ * `npm run sandbox` would hit the same wall — a silent dead-end for the fast
55
+ * loop. This spells out the exact way out instead of leaving the operator to
56
+ * discover it via a cryptic CloudFormation error.
57
+ *
58
+ * Kept pure so it can be asserted in a unit test.
59
+ */
60
+ export declare function sandboxFailureRecoveryHint(): string;
9
61
  export declare function startSandbox(options: SandboxOptions): Promise<string | undefined>;
10
62
  export declare function destroySandbox(backendPath: string): Promise<void>;
11
63
  //# sourceMappingURL=sandbox.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../src/scripts/sandbox.ts"],"names":[],"mappings":"AA+BA,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,yFAAyF;IACzF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,cAAc,+BAkMzD;AAED,wBAAsB,cAAc,CAAC,WAAW,EAAE,MAAM,iBAwCvD"}
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../src/scripts/sandbox.ts"],"names":[],"mappings":"AAiCA,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,yFAAyF;IACzF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,wBAAwB;IACvC,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,2FAA2F;IAC3F,WAAW,EAAE,MAAM,CAAC;IACpB,kFAAkF;IAClF,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,wBAAwB,GAAG,MAAM,EAAE,CAY/G;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CAYnD;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,cAAc,+BAwMzD;AAED,wBAAsB,cAAc,CAAC,WAAW,EAAE,MAAM,iBAwCvD"}
@@ -5,9 +5,11 @@ import { writeFileSync, mkdirSync, readFileSync } from "node:fs";
5
5
  import { join, resolve, dirname } from "node:path";
6
6
  import { fileURLToPath, pathToFileURL } from "node:url";
7
7
  import { ensureSecrets, loadEnvFile } from './ensure-secrets.js';
8
+ import { assertAwsCredentials } from './preflight-credentials.js';
8
9
  import { applyExternalMigrations } from './external-migrations-step.js';
9
10
  import { trackCommand } from '../telemetry/trackCommand.js';
10
11
  import { buildAndSendEvent } from '../telemetry/client.js';
12
+ import { classifyError } from '../telemetry/trackCommand.js';
11
13
  import { getCdkTelemetryEnv } from './cdk-telemetry-env.js';
12
14
  import { runSync, spawnCommand } from './run-command.js';
13
15
  import { terminateProcessTree } from './process-tree.js';
@@ -27,6 +29,74 @@ async function importBackendForRegistry(backendPath) {
27
29
  // best-effort — telemetry never affects the command
28
30
  }
29
31
  }
32
+ /**
33
+ * Build the `npm exec cdk -- deploy …` argv used by the sandbox deploy.
34
+ *
35
+ * Kept pure (no I/O) so the argv contract — in particular the flags below — can
36
+ * be asserted directly, the same way {@link buildCdkDeployArgs} is for the
37
+ * production path.
38
+ *
39
+ * - `--all`: an app that uses Lambda@Edge (e.g. a Next.js route with
40
+ * `export const runtime = 'edge'`) synthesizes a SECOND stack
41
+ * (`edge-lambda-stack-*`, region us-east-1) in addition to the main hosting
42
+ * stack. Without `--all`, CDK refuses with "specify which stacks to use".
43
+ * Deploying every stack in a sandbox app is the intended behavior.
44
+ * - `--method direct`: skip CloudFormation change-set creation and call
45
+ * UpdateStack directly. This is the baseline sandbox deployment method that
46
+ * `--express` builds on.
47
+ * - `--express` (**CloudFormation Express Mode — sandbox only**): the real
48
+ * speedup. CloudFormation reports each stack operation complete as soon as
49
+ * the resource's configuration is applied, WITHOUT waiting for full
50
+ * stabilization. Because it skips stabilization it also disables automatic
51
+ * rollback by default, so a failed deploy can leave the stack in a failed
52
+ * state — acceptable for the throwaway sandbox iteration loop, never for
53
+ * production. We leave rollback at Express Mode's default (off) and do NOT
54
+ * pass `--rollback`. The production deploy path (`deploy.ts`) deliberately
55
+ * uses neither `--express` nor `--method direct`: it keeps a reviewable
56
+ * change set and full stabilization with rollback, which are exactly the
57
+ * safety signals a production deploy should keep. Requires an aws-cdk CLI
58
+ * new enough to expose `--express`; our pinned `^2.1138.0` has it.
59
+ */
60
+ export function buildSandboxDeployArgs({ outDir, projectRoot, backendPath }) {
61
+ return [
62
+ "exec", "cdk", "--", "deploy",
63
+ "--all",
64
+ "--method", "direct",
65
+ "--express",
66
+ "--require-approval", "never",
67
+ "--outputs-file", `${outDir}/outputs.json`,
68
+ "--context", `projectRoot=${projectRoot}`,
69
+ "--context", "sandboxMode=true",
70
+ "--app", `npm exec tsx -- -C cdk ${backendPath}`,
71
+ ];
72
+ }
73
+ /**
74
+ * Operator-facing recovery guidance printed when a sandbox deploy fails.
75
+ *
76
+ * Express Mode (see {@link buildSandboxDeployArgs}) disables CloudFormation's
77
+ * automatic rollback, so a failed deploy does NOT clean up after itself: a
78
+ * failed *first* deploy leaves the stack in `CREATE_FAILED`/`ROLLBACK_COMPLETE`
79
+ * and a failed update can land in `UPDATE_ROLLBACK_FAILED`. In those states
80
+ * CloudFormation refuses the next `UpdateStack`, so a plain re-run of
81
+ * `npm run sandbox` would hit the same wall — a silent dead-end for the fast
82
+ * loop. This spells out the exact way out instead of leaving the operator to
83
+ * discover it via a cryptic CloudFormation error.
84
+ *
85
+ * Kept pure so it can be asserted in a unit test.
86
+ */
87
+ export function sandboxFailureRecoveryHint() {
88
+ return [
89
+ "",
90
+ "ℹ️ Express Mode leaves failed sandbox stacks in place (automatic rollback is off).",
91
+ " If the next `npm run sandbox` reports the stack cannot be updated, recover with:",
92
+ "",
93
+ " npm run sandbox:destroy # tears the failed stack down (handles ROLLBACK_COMPLETE)",
94
+ " npm run sandbox # redeploy from a clean slate",
95
+ "",
96
+ " If destroy reports UPDATE_ROLLBACK_FAILED, first run:",
97
+ " aws cloudformation continue-update-rollback --stack-name <your-sandbox-stack>",
98
+ ].join("\n");
99
+ }
30
100
  export async function startSandbox(options) {
31
101
  const { backendPath, outDir = ".blocks-sandbox", clientPort = 3000, deployOnly = false, devCommand } = options;
32
102
  const sandboxStartTime = Date.now();
@@ -39,6 +109,23 @@ export async function startSandbox(options) {
39
109
  throw e;
40
110
  }
41
111
  process.env.BLOCKS_STAGE = 'sandbox';
112
+ // Fail fast if AWS credentials are missing/expired, before spending ~10s in
113
+ // synth only to hit an opaque CDK credential error. Unlike deploy(), startSandbox
114
+ // isn't wrapped in trackCommand, so emit the FAIL event manually (mirroring the
115
+ // CDK-deploy failure path below) before rethrowing — otherwise a no-creds abort
116
+ // sends no telemetry.
117
+ try {
118
+ await assertAwsCredentials('sandbox');
119
+ }
120
+ catch (error) {
121
+ buildAndSendEvent({
122
+ command: 'sandbox',
123
+ state: 'FAIL',
124
+ duration: Date.now() - sandboxStartTime,
125
+ error: classifyError(error),
126
+ });
127
+ throw error;
128
+ }
42
129
  // Provision connection string to SSM SecureString.
43
130
  // On first deploy, creates the parameter. On subsequent deploys, updates if changed.
44
131
  // projectRoot is process.cwd() — the same value passed to cdk as --context
@@ -59,21 +146,10 @@ export async function startSandbox(options) {
59
146
  console.log("🚀 Deploying to AWS...");
60
147
  console.log(" (This may take a few minutes on first deploy)");
61
148
  try {
62
- runSync("npm", [
63
- "exec", "cdk", "--", "deploy",
64
- // `--all`: an app that uses Lambda@Edge (e.g. a Next.js route with
65
- // `export const runtime = 'edge'`) synthesizes a SECOND stack
66
- // (`edge-lambda-stack-*`, region us-east-1) in addition to the main
67
- // hosting stack. Without `--all`, CDK refuses with "specify which
68
- // stacks to use". Deploying every stack in a sandbox app is the
69
- // intended behavior, so select them all.
70
- "--all",
71
- "--require-approval", "never",
72
- "--outputs-file", `${outDir}/outputs.json`,
73
- "--context", `projectRoot=${process.cwd()}`,
74
- "--context", "sandboxMode=true",
75
- "--app", `npm exec tsx -- -C cdk ${backendPath}`,
76
- ], {
149
+ runSync("npm",
150
+ // Argv (including sandbox-only CloudFormation Express Mode, `--express`)
151
+ // is built by buildSandboxDeployArgs see its doc for why each flag exists.
152
+ buildSandboxDeployArgs({ outDir, projectRoot: process.cwd(), backendPath }), {
77
153
  stdio: "inherit",
78
154
  env: { ...process.env, NODE_OPTIONS: "--conditions=cdk", ...getCdkTelemetryEnv('sandbox') },
79
155
  });
@@ -86,6 +162,7 @@ export async function startSandbox(options) {
86
162
  error: { code: 'CDK_DEPLOY_FAILED', phase: 'deploy' },
87
163
  });
88
164
  console.error("\n❌ Deployment failed.");
165
+ console.error(sandboxFailureRecoveryHint());
89
166
  throw error;
90
167
  }
91
168
  const outputs = JSON.parse(readFileSync(`${outDir}/outputs.json`, "utf-8"));
@@ -0,0 +1,15 @@
1
+ /** Set (create or overwrite) a Blocks secret. */
2
+ export declare function setSecret(key: string, value: string, opts?: {
3
+ stage?: string;
4
+ }): Promise<void>;
5
+ /** List Blocks secret keys (names only). */
6
+ export declare function listSecrets(opts?: {
7
+ stage?: string;
8
+ }): Promise<string[]>;
9
+ /** Remove a Blocks secret. */
10
+ export declare function removeSecret(key: string, opts?: {
11
+ stage?: string;
12
+ }): Promise<boolean>;
13
+ /** CLI dispatcher for `blocks secret <set|list|remove> …`. */
14
+ export declare function runSecretCli(argv: string[]): Promise<void>;
15
+ //# sourceMappingURL=secret.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secret.d.ts","sourceRoot":"","sources":["../../src/scripts/secret.ts"],"names":[],"mappings":"AAgBA,iDAAiD;AACjD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAElG;AAED,4CAA4C;AAC5C,wBAAgB,WAAW,CAAC,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAE5E;AAED,8BAA8B;AAC9B,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAEzF;AAED,8DAA8D;AAC9D,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1D"}
@@ -0,0 +1,29 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * `blocks secret` — manage a Blocks app's **secrets** (AWS Secrets Manager),
5
+ * pinned to the Blocks `/blocks/<stackId>/secrets` namespace (scoped to the app's
6
+ * stable `stackId` from `.blocks/config.json`, so two apps in one account never
7
+ * collide). Thin wrapper over the shared `@aws-blocks/hosting` CLI with the kind
8
+ * fixed to `secret`. The `config` counterpart is `./config.ts`.
9
+ *
10
+ * @module
11
+ */
12
+ import { listValues, removeValue, runValueCli, setValue } from '@aws-blocks/hosting/scripts';
13
+ import { blocksSecretPrefix } from '../secret-naming.js';
14
+ /** Set (create or overwrite) a Blocks secret. */
15
+ export function setSecret(key, value, opts = {}) {
16
+ return setValue('secret', key, value, { prefix: blocksSecretPrefix(), ...opts });
17
+ }
18
+ /** List Blocks secret keys (names only). */
19
+ export function listSecrets(opts = {}) {
20
+ return listValues('secret', { prefix: blocksSecretPrefix(), ...opts });
21
+ }
22
+ /** Remove a Blocks secret. */
23
+ export function removeSecret(key, opts = {}) {
24
+ return removeValue('secret', key, { prefix: blocksSecretPrefix(), ...opts });
25
+ }
26
+ /** CLI dispatcher for `blocks secret <set|list|remove> …`. */
27
+ export function runSecretCli(argv) {
28
+ return runValueCli(argv, { kind: 'secret', prefix: blocksSecretPrefix(), label: 'blocks secret' });
29
+ }