@intelligems/sst 2.47.3 → 2.49.3

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/util/process.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ /// <reference types="node" resolution-mode="require"/>
1
2
  import { exec } from "child_process";
2
3
  export declare const execAsync: typeof exec.__promisify__;
@@ -0,0 +1,89 @@
1
+ export declare const PROJECT_CONFIG = "cdk.json";
2
+ export declare const USER_DEFAULTS = "~/.cdk.json";
3
+ export declare enum Command {
4
+ LS = "ls",
5
+ LIST = "list",
6
+ DIFF = "diff",
7
+ BOOTSTRAP = "bootstrap",
8
+ DEPLOY = "deploy",
9
+ DESTROY = "destroy",
10
+ SYNTHESIZE = "synthesize",
11
+ SYNTH = "synth",
12
+ METADATA = "metadata",
13
+ INIT = "init",
14
+ VERSION = "version",
15
+ WATCH = "watch",
16
+ GC = "gc",
17
+ ROLLBACK = "rollback",
18
+ IMPORT = "import",
19
+ ACKNOWLEDGE = "acknowledge",
20
+ ACK = "ack",
21
+ NOTICES = "notices",
22
+ MIGRATE = "migrate",
23
+ CONTEXT = "context",
24
+ DOCS = "docs",
25
+ DOC = "doc",
26
+ DOCTOR = "doctor",
27
+ REFACTOR = "refactor",
28
+ DRIFT = "drift"
29
+ }
30
+ export type Arguments = {
31
+ readonly _: [Command, ...string[]];
32
+ readonly exclusively?: boolean;
33
+ readonly STACKS?: string[];
34
+ readonly lookups?: boolean;
35
+ readonly [name: string]: unknown;
36
+ };
37
+ export interface ConfigurationProps {
38
+ /**
39
+ * Configuration passed via command line arguments
40
+ *
41
+ * @default - Nothing passed
42
+ */
43
+ readonly commandLineArguments?: Arguments;
44
+ /**
45
+ * Whether or not to use context from `.cdk.json` in user home directory
46
+ *
47
+ * @default true
48
+ */
49
+ readonly readUserContext?: boolean;
50
+ }
51
+ /**
52
+ * All sources of settings combined
53
+ */
54
+ export declare class Configuration {
55
+ private readonly props;
56
+ settings: any;
57
+ context: any;
58
+ readonly defaultConfig: any;
59
+ private readonly commandLineArguments;
60
+ private readonly commandLineContext;
61
+ private _projectConfig?;
62
+ private _projectContext?;
63
+ private loaded;
64
+ constructor(props?: ConfigurationProps);
65
+ private get projectConfig();
66
+ get projectContext(): any;
67
+ /**
68
+ * Load all config
69
+ */
70
+ load(): Promise<this>;
71
+ /**
72
+ * Save the project context
73
+ */
74
+ saveContext(): Promise<this>;
75
+ }
76
+ /**
77
+ * Parse CLI arguments into Settings
78
+ *
79
+ * CLI arguments in must be accessed in the CLI code via
80
+ * `configuration.settings.get(['argName'])` instead of via `args.argName`.
81
+ *
82
+ * The advantage is that they can be configured via `cdk.json` and
83
+ * `$HOME/.cdk.json`. Arguments not listed below and accessed via this object
84
+ * can only be specified on the command line.
85
+ *
86
+ * @param argv - the received CLI arguments.
87
+ * @returns a new Settings object.
88
+ */
89
+ export declare function commandLineArgumentsToSettings(argv: Arguments): any;
@@ -0,0 +1,311 @@
1
+ // @ts-nocheck
2
+ import * as os from "os";
3
+ import * as fs_path from "path";
4
+ import * as fs from "fs";
5
+ export const PROJECT_CONFIG = "cdk.json";
6
+ export const USER_DEFAULTS = "~/.cdk.json";
7
+ const CONTEXT_KEY = "context";
8
+ const cdkToolkitUrl = await import.meta.resolve("@aws-cdk/toolkit-lib");
9
+ const cdkToolkitPath = new URL(cdkToolkitUrl).pathname;
10
+ const { ToolkitError } = await import(cdkToolkitPath);
11
+ const { Context, PROJECT_CONTEXT } = await import(fs_path.resolve(cdkToolkitPath, "..", "api", "context.js"));
12
+ const { Settings } = await import(fs_path.resolve(cdkToolkitPath, "..", "api", "settings.js"));
13
+ const { Tags } = await import(fs_path.resolve(cdkToolkitPath, "..", "api", "tags", "index.js"));
14
+ export var Command;
15
+ (function (Command) {
16
+ Command["LS"] = "ls";
17
+ Command["LIST"] = "list";
18
+ Command["DIFF"] = "diff";
19
+ Command["BOOTSTRAP"] = "bootstrap";
20
+ Command["DEPLOY"] = "deploy";
21
+ Command["DESTROY"] = "destroy";
22
+ Command["SYNTHESIZE"] = "synthesize";
23
+ Command["SYNTH"] = "synth";
24
+ Command["METADATA"] = "metadata";
25
+ Command["INIT"] = "init";
26
+ Command["VERSION"] = "version";
27
+ Command["WATCH"] = "watch";
28
+ Command["GC"] = "gc";
29
+ Command["ROLLBACK"] = "rollback";
30
+ Command["IMPORT"] = "import";
31
+ Command["ACKNOWLEDGE"] = "acknowledge";
32
+ Command["ACK"] = "ack";
33
+ Command["NOTICES"] = "notices";
34
+ Command["MIGRATE"] = "migrate";
35
+ Command["CONTEXT"] = "context";
36
+ Command["DOCS"] = "docs";
37
+ Command["DOC"] = "doc";
38
+ Command["DOCTOR"] = "doctor";
39
+ Command["REFACTOR"] = "refactor";
40
+ Command["DRIFT"] = "drift";
41
+ })(Command || (Command = {}));
42
+ const BUNDLING_COMMANDS = [
43
+ Command.DEPLOY,
44
+ Command.DIFF,
45
+ Command.SYNTH,
46
+ Command.SYNTHESIZE,
47
+ Command.WATCH,
48
+ Command.IMPORT,
49
+ ];
50
+ /**
51
+ * All sources of settings combined
52
+ */
53
+ export class Configuration {
54
+ props;
55
+ settings = new Settings();
56
+ context = new Context();
57
+ defaultConfig = new Settings({
58
+ versionReporting: true,
59
+ assetMetadata: true,
60
+ pathMetadata: true,
61
+ output: "cdk.out",
62
+ });
63
+ commandLineArguments;
64
+ commandLineContext;
65
+ _projectConfig;
66
+ _projectContext;
67
+ loaded = false;
68
+ constructor(props = {}) {
69
+ this.props = props;
70
+ this.commandLineArguments = props.commandLineArguments
71
+ ? commandLineArgumentsToSettings(props.commandLineArguments)
72
+ : new Settings();
73
+ this.commandLineContext = this.commandLineArguments
74
+ .subSettings([CONTEXT_KEY])
75
+ .makeReadOnly();
76
+ }
77
+ get projectConfig() {
78
+ if (!this._projectConfig) {
79
+ throw new ToolkitError("#load has not been called yet!");
80
+ }
81
+ return this._projectConfig;
82
+ }
83
+ get projectContext() {
84
+ if (!this._projectContext) {
85
+ throw new ToolkitError("#load has not been called yet!");
86
+ }
87
+ return this._projectContext;
88
+ }
89
+ /**
90
+ * Load all config
91
+ */
92
+ async load() {
93
+ const userConfig = await loadAndLog(USER_DEFAULTS);
94
+ this._projectConfig = await loadAndLog(PROJECT_CONFIG);
95
+ this._projectContext = await loadAndLog(PROJECT_CONTEXT);
96
+ // @todo cannot currently be disabled by cli users
97
+ const readUserContext = this.props.readUserContext ?? true;
98
+ if (userConfig.get(["build"])) {
99
+ throw new ToolkitError("The `build` key cannot be specified in the user config (~/.cdk.json), specify it in the project config (cdk.json) instead");
100
+ }
101
+ const contextSources = [
102
+ { bag: this.commandLineContext },
103
+ {
104
+ fileName: PROJECT_CONFIG,
105
+ bag: this.projectConfig.subSettings([CONTEXT_KEY]).makeReadOnly(),
106
+ },
107
+ { fileName: PROJECT_CONTEXT, bag: this.projectContext },
108
+ ];
109
+ if (readUserContext) {
110
+ contextSources.push({
111
+ fileName: USER_DEFAULTS,
112
+ bag: userConfig.subSettings([CONTEXT_KEY]).makeReadOnly(),
113
+ });
114
+ }
115
+ this.context = new Context(...contextSources);
116
+ // Build settings from what's left
117
+ this.settings = this.defaultConfig
118
+ .merge(userConfig)
119
+ .merge(this.projectConfig)
120
+ .merge(this.commandLineArguments)
121
+ .makeReadOnly();
122
+ this.loaded = true;
123
+ return this;
124
+ }
125
+ /**
126
+ * Save the project context
127
+ */
128
+ async saveContext() {
129
+ if (!this.loaded) {
130
+ return this;
131
+ } // Avoid overwriting files with nothing
132
+ await this.projectContext.save(PROJECT_CONTEXT);
133
+ return this;
134
+ }
135
+ }
136
+ async function loadAndLog(fileName) {
137
+ return await settingsFromFile(fileName);
138
+ }
139
+ async function settingsFromFile(fileName) {
140
+ let settings;
141
+ const expanded = expandHomeDir(fileName);
142
+ if (fs.existsSync(expanded)) {
143
+ const data = JSON.parse(fs.readFileSync(expanded, "utf-8"));
144
+ settings = new Settings(data);
145
+ }
146
+ else {
147
+ settings = new Settings();
148
+ }
149
+ // See https://github.com/aws/aws-cdk/issues/59
150
+ prohibitContextKeys(settings, ["default-account", "default-region"], fileName);
151
+ warnAboutContextKey(settings, "aws:", fileName);
152
+ return settings;
153
+ }
154
+ function prohibitContextKeys(settings, keys, fileName) {
155
+ const context = settings.get(["context"]);
156
+ if (!context || typeof context !== "object") {
157
+ return;
158
+ }
159
+ for (const key of keys) {
160
+ if (key in context) {
161
+ throw new ToolkitError(`The 'context.${key}' key was found in ${fs_path.resolve(fileName)}, but it is no longer supported. Please remove it.`);
162
+ }
163
+ }
164
+ }
165
+ function warnAboutContextKey(settings, prefix, fileName) {
166
+ const context = settings.get(["context"]);
167
+ if (!context || typeof context !== "object") {
168
+ return;
169
+ }
170
+ for (const contextKey of Object.keys(context)) {
171
+ if (contextKey.startsWith(prefix)) {
172
+ console.warn(`A reserved context key ('context.${prefix}') key was found in ${fs_path.resolve(fileName)}, it might cause surprising behavior and should be removed.`);
173
+ }
174
+ }
175
+ }
176
+ function expandHomeDir(x) {
177
+ if (x.startsWith("~")) {
178
+ return fs_path.join(os.homedir(), x.slice(1));
179
+ }
180
+ return x;
181
+ }
182
+ /**
183
+ * Parse CLI arguments into Settings
184
+ *
185
+ * CLI arguments in must be accessed in the CLI code via
186
+ * `configuration.settings.get(['argName'])` instead of via `args.argName`.
187
+ *
188
+ * The advantage is that they can be configured via `cdk.json` and
189
+ * `$HOME/.cdk.json`. Arguments not listed below and accessed via this object
190
+ * can only be specified on the command line.
191
+ *
192
+ * @param argv - the received CLI arguments.
193
+ * @returns a new Settings object.
194
+ */
195
+ export function commandLineArgumentsToSettings(argv) {
196
+ const context = parseStringContextListToObject(argv);
197
+ const tags = parseStringTagsListToObject(expectStringList(argv.tags));
198
+ // Determine bundling stacks
199
+ let bundlingStacks;
200
+ if (BUNDLING_COMMANDS.includes(argv._[0])) {
201
+ // If we deploy, diff, synth or watch a list of stacks exclusively we skip
202
+ // bundling for all other stacks.
203
+ bundlingStacks = argv.exclusively ? argv.STACKS ?? ["**"] : ["**"];
204
+ }
205
+ else {
206
+ // Skip bundling for all stacks
207
+ bundlingStacks = [];
208
+ }
209
+ return new Settings({
210
+ app: argv.app,
211
+ browser: argv.browser,
212
+ build: argv.build,
213
+ caBundlePath: argv.caBundlePath,
214
+ context,
215
+ debug: argv.debug,
216
+ tags,
217
+ language: argv.language,
218
+ pathMetadata: argv.pathMetadata,
219
+ assetMetadata: argv.assetMetadata,
220
+ profile: argv.profile,
221
+ plugin: argv.plugin,
222
+ requireApproval: argv.requireApproval,
223
+ toolkitStackName: argv.toolkitStackName,
224
+ toolkitBucket: {
225
+ bucketName: argv.bootstrapBucketName,
226
+ kmsKeyId: argv.bootstrapKmsKeyId,
227
+ },
228
+ versionReporting: argv.versionReporting,
229
+ staging: argv.staging,
230
+ output: argv.output,
231
+ outputsFile: argv.outputsFile,
232
+ progress: argv.progress,
233
+ proxy: argv.proxy,
234
+ bundlingStacks,
235
+ lookups: argv.lookups,
236
+ rollback: argv.rollback,
237
+ notices: argv.notices,
238
+ assetParallelism: argv["asset-parallelism"],
239
+ assetPrebuild: argv["asset-prebuild"],
240
+ ignoreNoStacks: argv["ignore-no-stacks"],
241
+ hotswap: {
242
+ ecs: {
243
+ minimumHealthyPercent: argv.hotswapEcsMinimumHealthyPercent,
244
+ maximumHealthyPercent: argv.hotswapEcsMaximumHealthyPercent,
245
+ stabilizationTimeoutSeconds: argv.hotswapEcsStabilizationTimeoutSeconds,
246
+ },
247
+ },
248
+ unstable: argv.unstable,
249
+ });
250
+ }
251
+ function expectStringList(x) {
252
+ if (x === undefined) {
253
+ return undefined;
254
+ }
255
+ if (!Array.isArray(x)) {
256
+ throw new ToolkitError(`Expected array, got '${x}'`);
257
+ }
258
+ const nonStrings = x.filter((e) => typeof e !== "string");
259
+ if (nonStrings.length > 0) {
260
+ throw new ToolkitError(`Expected list of strings, found ${nonStrings}`);
261
+ }
262
+ return x;
263
+ }
264
+ function parseStringContextListToObject(argv) {
265
+ const context = {};
266
+ for (const assignment of argv.context || []) {
267
+ const parts = assignment.split(/=(.*)/, 2);
268
+ if (parts.length === 2) {
269
+ if (parts[0].match(/^aws:.+/)) {
270
+ throw new ToolkitError(`User-provided context cannot use keys prefixed with 'aws:', but ${parts[0]} was provided.`);
271
+ }
272
+ context[parts[0]] = parts[1];
273
+ }
274
+ else {
275
+ console.warn("Context argument is not an assignment (key=value): %s", assignment);
276
+ }
277
+ }
278
+ return context;
279
+ }
280
+ /**
281
+ * Parse tags out of arguments
282
+ *
283
+ * Return undefined if no tags were provided, return an empty array if only empty
284
+ * strings were provided
285
+ */
286
+ function parseStringTagsListToObject(argTags) {
287
+ if (argTags === undefined) {
288
+ return undefined;
289
+ }
290
+ if (argTags.length === 0) {
291
+ return undefined;
292
+ }
293
+ const nonEmptyTags = argTags.filter((t) => t !== "");
294
+ if (nonEmptyTags.length === 0) {
295
+ return [];
296
+ }
297
+ const tags = [];
298
+ for (const assignment of nonEmptyTags) {
299
+ const parts = assignment.split(/=(.*)/, 2);
300
+ if (parts.length === 2) {
301
+ tags.push({
302
+ Key: parts[0],
303
+ Value: parts[1],
304
+ });
305
+ }
306
+ else {
307
+ console.warn("Tags argument is not an assignment (key=value): %s", assignment);
308
+ }
309
+ }
310
+ return tags.length > 0 ? tags : undefined;
311
+ }
@@ -1,216 +0,0 @@
1
- import * as cxapi from "@aws-cdk/cx-api";
2
- import type { Tag } from "@aws-sdk/client-cloudformation";
3
- import type { SDK, SdkProvider } from "sst-aws-cdk/lib/api/aws-auth/index.js";
4
- import type { EnvironmentResources } from "sst-aws-cdk/lib/api/environment-resources.js";
5
- import { HotswapMode, HotswapPropertyOverrides } from "sst-aws-cdk/lib/api/hotswap/common.js";
6
- import { ResourcesToImport } from "sst-aws-cdk/lib/api/util/cloudformation.js";
7
- import { type StackActivityProgress } from "sst-aws-cdk/lib/api/util/cloudformation/stack-activity-monitor.js";
8
- import { StringWithoutPlaceholders } from "sst-aws-cdk/lib/api/util/placeholders.js";
9
- export type DeployStackResult = SuccessfulDeployStackResult | NeedRollbackFirstDeployStackResult | ReplacementRequiresNoRollbackStackResult;
10
- /** Successfully deployed a stack */
11
- export interface SuccessfulDeployStackResult {
12
- readonly type: "did-deploy-stack";
13
- readonly noOp: boolean;
14
- readonly outputs: {
15
- [name: string]: string;
16
- };
17
- readonly stackArn: string;
18
- }
19
- /** The stack is currently in a failpaused state, and needs to be rolled back before the deployment */
20
- export interface NeedRollbackFirstDeployStackResult {
21
- readonly type: "failpaused-need-rollback-first";
22
- readonly reason: "not-norollback" | "replacement";
23
- }
24
- /** The upcoming change has a replacement, which requires deploying without --no-rollback */
25
- export interface ReplacementRequiresNoRollbackStackResult {
26
- readonly type: "replacement-requires-norollback";
27
- }
28
- export declare function assertIsSuccessfulDeployStackResult(x: DeployStackResult): asserts x is SuccessfulDeployStackResult;
29
- export interface DeployStackOptions {
30
- /**
31
- * The stack to be deployed
32
- */
33
- readonly stack: cxapi.CloudFormationStackArtifact;
34
- /**
35
- * Skip monitoring
36
- */
37
- readonly noMonitor?: boolean;
38
- /**
39
- * The environment to deploy this stack in
40
- *
41
- * The environment on the stack artifact may be unresolved, this one
42
- * must be resolved.
43
- */
44
- readonly resolvedEnvironment: cxapi.Environment;
45
- /**
46
- * The SDK to use for deploying the stack
47
- *
48
- * Should have been initialized with the correct role with which
49
- * stack operations should be performed.
50
- */
51
- readonly sdk: SDK;
52
- /**
53
- * SDK provider (seeded with default credentials)
54
- *
55
- * Will be used to:
56
- * - Publish assets, either legacy assets or large CFN templates
57
- * that aren't themselves assets from a manifest. (Needs an SDK
58
- * Provider because the file publishing role is declared as part
59
- * of the asset).
60
- * - Hotswap
61
- */
62
- readonly sdkProvider: SdkProvider;
63
- /**
64
- * Information about the bootstrap stack found in the target environment
65
- */
66
- readonly envResources: EnvironmentResources;
67
- /**
68
- * Role to pass to CloudFormation to execute the change set
69
- *
70
- * To obtain a `StringWithoutPlaceholders`, run a regular
71
- * string though `TargetEnvironment.replacePlaceholders`.
72
- *
73
- * @default - No execution role; CloudFormation either uses the role currently associated with
74
- * the stack, or otherwise uses current AWS credentials.
75
- */
76
- readonly roleArn?: StringWithoutPlaceholders;
77
- /**
78
- * Notification ARNs to pass to CloudFormation to notify when the change set has completed
79
- *
80
- * @default - No notifications
81
- */
82
- readonly notificationArns?: string[];
83
- /**
84
- * Name to deploy the stack under
85
- *
86
- * @default - Name from assembly
87
- */
88
- readonly deployName?: string;
89
- /**
90
- * Quiet or verbose deployment
91
- *
92
- * @default false
93
- */
94
- readonly quiet?: boolean;
95
- /**
96
- * List of asset IDs which shouldn't be built
97
- *
98
- * @default - Build all assets
99
- */
100
- readonly reuseAssets?: string[];
101
- /**
102
- * Tags to pass to CloudFormation to add to stack
103
- *
104
- * @default - No tags
105
- */
106
- readonly tags?: Tag[];
107
- /**
108
- * What deployment method to use
109
- *
110
- * @default - Change set with defaults
111
- */
112
- readonly deploymentMethod?: DeploymentMethod;
113
- /**
114
- * The collection of extra parameters
115
- * (in addition to those used for assets)
116
- * to pass to the deployed template.
117
- * Note that parameters with `undefined` or empty values will be ignored,
118
- * and not passed to the template.
119
- *
120
- * @default - no additional parameters will be passed to the template
121
- */
122
- readonly parameters?: {
123
- [name: string]: string | undefined;
124
- };
125
- /**
126
- * Use previous values for unspecified parameters
127
- *
128
- * If not set, all parameters must be specified for every deployment.
129
- *
130
- * @default false
131
- */
132
- readonly usePreviousParameters?: boolean;
133
- /**
134
- * Display mode for stack deployment progress.
135
- *
136
- * @default StackActivityProgress.Bar stack events will be displayed for
137
- * the resource currently being deployed.
138
- */
139
- readonly progress?: StackActivityProgress;
140
- /**
141
- * Deploy even if the deployed template is identical to the one we are about to deploy.
142
- * @default false
143
- */
144
- readonly force?: boolean;
145
- /**
146
- * Whether we are on a CI system
147
- *
148
- * @default false
149
- */
150
- readonly ci?: boolean;
151
- /**
152
- * Rollback failed deployments
153
- *
154
- * @default true
155
- */
156
- readonly rollback?: boolean;
157
- readonly hotswap?: HotswapMode;
158
- /**
159
- * Extra properties that configure hotswap behavior
160
- */
161
- readonly hotswapPropertyOverrides?: HotswapPropertyOverrides;
162
- /**
163
- * The extra string to append to the User-Agent header when performing AWS SDK calls.
164
- *
165
- * @default - nothing extra is appended to the User-Agent header
166
- */
167
- readonly extraUserAgent?: string;
168
- /**
169
- * If set, change set of type IMPORT will be created, and resourcesToImport
170
- * passed to it.
171
- */
172
- readonly resourcesToImport?: ResourcesToImport;
173
- /**
174
- * If present, use this given template instead of the stored one
175
- *
176
- * @default - Use the stored template
177
- */
178
- readonly overrideTemplate?: any;
179
- /**
180
- * Whether to build/publish assets in parallel
181
- *
182
- * @default true To remain backward compatible.
183
- */
184
- readonly assetParallelism?: boolean;
185
- }
186
- export type DeploymentMethod = DirectDeploymentMethod | ChangeSetDeploymentMethod;
187
- export interface DirectDeploymentMethod {
188
- readonly method: "direct";
189
- }
190
- export interface ChangeSetDeploymentMethod {
191
- readonly method: "change-set";
192
- /**
193
- * Whether to execute the changeset or leave it in review.
194
- *
195
- * @default true
196
- */
197
- readonly execute?: boolean;
198
- /**
199
- * Optional name to use for the CloudFormation change set.
200
- * If not provided, a name will be generated automatically.
201
- */
202
- readonly changeSetName?: string;
203
- }
204
- export declare function deployStack(options: DeployStackOptions): Promise<DeployStackResult | undefined>;
205
- export interface DestroyStackOptions {
206
- /**
207
- * The stack to be destroyed
208
- */
209
- stack: cxapi.CloudFormationStackArtifact;
210
- sdk: SDK;
211
- roleArn?: string;
212
- deployName?: string;
213
- quiet?: boolean;
214
- ci?: boolean;
215
- }
216
- export declare function destroyStack(options: DestroyStackOptions): Promise<void>;