@awsless/awsless 0.0.11 → 0.0.13
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/bin.cjs +207 -161
- package/dist/bin.js +207 -161
- package/dist/index.cjs +22 -20
- package/dist/index.d.ts +185 -6
- package/dist/index.js +18 -16
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -63,15 +63,15 @@ var flushDebug = () => {
|
|
|
63
63
|
|
|
64
64
|
// src/util/param.ts
|
|
65
65
|
import { DeleteParameterCommand, GetParameterCommand, GetParametersByPathCommand, ParameterType, PutParameterCommand, SSMClient } from "@aws-sdk/client-ssm";
|
|
66
|
-
var configParameterPrefix = (
|
|
67
|
-
return `/${
|
|
66
|
+
var configParameterPrefix = (config) => {
|
|
67
|
+
return `/${config.stage}/awsless/${config.name}`;
|
|
68
68
|
};
|
|
69
69
|
var Params = class {
|
|
70
|
-
constructor(
|
|
71
|
-
this.config =
|
|
70
|
+
constructor(config) {
|
|
71
|
+
this.config = config;
|
|
72
72
|
this.client = new SSMClient({
|
|
73
|
-
credentials:
|
|
74
|
-
region:
|
|
73
|
+
credentials: config.credentials,
|
|
74
|
+
region: config.region
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
client;
|
|
@@ -146,13 +146,13 @@ var Params = class {
|
|
|
146
146
|
};
|
|
147
147
|
|
|
148
148
|
// src/stack.ts
|
|
149
|
-
var toStack = ({ config
|
|
150
|
-
const stackName = `${
|
|
149
|
+
var toStack = ({ config, assets, app, stackConfig, plugins }) => {
|
|
150
|
+
const stackName = `${config.name}-${stackConfig.name}`;
|
|
151
151
|
const stack = new Stack(app, stackConfig.name, {
|
|
152
152
|
stackName,
|
|
153
153
|
tags: {
|
|
154
|
-
APP:
|
|
155
|
-
STAGE:
|
|
154
|
+
APP: config.name,
|
|
155
|
+
STAGE: config.stage,
|
|
156
156
|
STACK: stackConfig.name
|
|
157
157
|
}
|
|
158
158
|
});
|
|
@@ -163,7 +163,7 @@ var toStack = ({ config: config2, assets, app, stackConfig, plugins }) => {
|
|
|
163
163
|
};
|
|
164
164
|
debug("Run plugin onStack listeners");
|
|
165
165
|
const functions = plugins.map((plugin) => plugin.onStack?.({
|
|
166
|
-
config
|
|
166
|
+
config,
|
|
167
167
|
assets,
|
|
168
168
|
app,
|
|
169
169
|
stack,
|
|
@@ -182,12 +182,12 @@ var toStack = ({ config: config2, assets, app, stackConfig, plugins }) => {
|
|
|
182
182
|
],
|
|
183
183
|
resources: [
|
|
184
184
|
Arn.format({
|
|
185
|
-
region:
|
|
186
|
-
account:
|
|
185
|
+
region: config.region,
|
|
186
|
+
account: config.account,
|
|
187
187
|
partition: "aws",
|
|
188
188
|
service: "ssm",
|
|
189
189
|
resource: "parameter",
|
|
190
|
-
resourceName: configParameterPrefix(
|
|
190
|
+
resourceName: configParameterPrefix(config)
|
|
191
191
|
})
|
|
192
192
|
// Fn.sub('arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter' + configParameterPrefix(config)),
|
|
193
193
|
]
|
|
@@ -377,17 +377,17 @@ var zipFiles = (files) => {
|
|
|
377
377
|
}
|
|
378
378
|
});
|
|
379
379
|
};
|
|
380
|
-
var writeBuildHash = async (
|
|
381
|
-
const funcPath = join2(assetDir, "function",
|
|
380
|
+
var writeBuildHash = async (config, stack, id, hash) => {
|
|
381
|
+
const funcPath = join2(assetDir, "function", config.name, stack.artifactId, id);
|
|
382
382
|
const versionFile = join2(funcPath, "HASH");
|
|
383
383
|
await writeFile(versionFile, hash);
|
|
384
384
|
};
|
|
385
|
-
var writeBuildFiles = async (
|
|
385
|
+
var writeBuildFiles = async (config, stack, id, files) => {
|
|
386
386
|
const bundle = await zipFiles(files);
|
|
387
|
-
const funcPath = join2(assetDir, "function",
|
|
387
|
+
const funcPath = join2(assetDir, "function", config.name, stack.artifactId, id);
|
|
388
388
|
const filesPath = join2(funcPath, "files");
|
|
389
389
|
const bundleFile = join2(funcPath, "bundle.zip");
|
|
390
|
-
debug("Bundle size of", style.info(join2(
|
|
390
|
+
debug("Bundle size of", style.info(join2(config.name, stack.artifactId, id)), "is", style.attr(filesize(bundle.byteLength)));
|
|
391
391
|
await mkdir(filesPath, { recursive: true });
|
|
392
392
|
await writeFile(bundleFile, bundle);
|
|
393
393
|
await Promise.all(files.map(async (file) => {
|
|
@@ -413,20 +413,20 @@ import { GetObjectCommand, ObjectCannedACL, PutObjectCommand, S3Client, StorageC
|
|
|
413
413
|
// src/stack/bootstrap.ts
|
|
414
414
|
import { CfnOutput, RemovalPolicy, Stack as Stack2 } from "aws-cdk-lib";
|
|
415
415
|
import { Bucket, BucketAccessControl } from "aws-cdk-lib/aws-s3";
|
|
416
|
-
var assetBucketName = (
|
|
417
|
-
return `awsless-bootstrap-${
|
|
416
|
+
var assetBucketName = (config) => {
|
|
417
|
+
return `awsless-bootstrap-${config.account}-${config.region}`;
|
|
418
418
|
};
|
|
419
|
-
var assetBucketUrl = (
|
|
420
|
-
const bucket = assetBucketName(
|
|
421
|
-
return `https://s3-${
|
|
419
|
+
var assetBucketUrl = (config, stackName) => {
|
|
420
|
+
const bucket = assetBucketName(config);
|
|
421
|
+
return `https://s3-${config.region}.amazonaws.com/${bucket}/${stackName}/cloudformation.json`;
|
|
422
422
|
};
|
|
423
423
|
var version = "2";
|
|
424
|
-
var bootstrapStack = (
|
|
424
|
+
var bootstrapStack = (config, app) => {
|
|
425
425
|
const stack = new Stack2(app, "bootstrap", {
|
|
426
426
|
stackName: `awsless-bootstrap`
|
|
427
427
|
});
|
|
428
428
|
new Bucket(stack, "assets", {
|
|
429
|
-
bucketName: assetBucketName(
|
|
429
|
+
bucketName: assetBucketName(config),
|
|
430
430
|
versioned: true,
|
|
431
431
|
accessControl: BucketAccessControl.PRIVATE,
|
|
432
432
|
removalPolicy: RemovalPolicy.DESTROY
|
|
@@ -444,17 +444,17 @@ var shouldDeployBootstrap = async (client, name) => {
|
|
|
444
444
|
};
|
|
445
445
|
|
|
446
446
|
// src/plugins/function/util/publish.ts
|
|
447
|
-
var publishFunctionAsset = async (
|
|
448
|
-
const bucket = assetBucketName(
|
|
449
|
-
const key = `${
|
|
450
|
-
const funcPath = join3(assetDir, "function",
|
|
447
|
+
var publishFunctionAsset = async (config, stack, id) => {
|
|
448
|
+
const bucket = assetBucketName(config);
|
|
449
|
+
const key = `${config.name}/${stack.artifactId}/function/${id}.zip`;
|
|
450
|
+
const funcPath = join3(assetDir, "function", config.name, stack.artifactId, id);
|
|
451
451
|
const bundleFile = join3(funcPath, "bundle.zip");
|
|
452
452
|
const hashFile = join3(funcPath, "HASH");
|
|
453
453
|
const hash = await readFile(hashFile, "utf8");
|
|
454
454
|
const file = await readFile(bundleFile);
|
|
455
455
|
const client = new S3Client({
|
|
456
|
-
credentials:
|
|
457
|
-
region:
|
|
456
|
+
credentials: config.credentials,
|
|
457
|
+
region: config.region
|
|
458
458
|
});
|
|
459
459
|
let getResult;
|
|
460
460
|
try {
|
|
@@ -527,19 +527,22 @@ var rollupBuild = async (input) => {
|
|
|
527
527
|
json()
|
|
528
528
|
]
|
|
529
529
|
});
|
|
530
|
-
const
|
|
530
|
+
const result = await bundle.generate({
|
|
531
531
|
format: "esm",
|
|
532
532
|
sourcemap: "hidden",
|
|
533
533
|
exports: "default"
|
|
534
534
|
});
|
|
535
|
-
const
|
|
535
|
+
const output = result.output[0];
|
|
536
|
+
const code = output.code;
|
|
537
|
+
const map = output.map?.toString();
|
|
538
|
+
const hash = createHash("sha1").update(code).digest("hex");
|
|
536
539
|
return {
|
|
537
540
|
handler: "index.default",
|
|
538
541
|
hash,
|
|
539
542
|
files: [{
|
|
540
543
|
name: "index.mjs",
|
|
541
|
-
code
|
|
542
|
-
map
|
|
544
|
+
code,
|
|
545
|
+
map
|
|
543
546
|
}]
|
|
544
547
|
};
|
|
545
548
|
};
|
|
@@ -586,8 +589,8 @@ var functionPlugin = definePlugin({
|
|
|
586
589
|
});
|
|
587
590
|
}
|
|
588
591
|
});
|
|
589
|
-
var toFunction = ({ config
|
|
590
|
-
const props = typeof fileOrProps === "string" ? { ...
|
|
592
|
+
var toFunction = ({ config, stack, assets }, id, fileOrProps) => {
|
|
593
|
+
const props = typeof fileOrProps === "string" ? { ...config.defaults?.function, file: fileOrProps } : { ...config.defaults?.function, ...fileOrProps };
|
|
591
594
|
const lambda = new Function(stack, toId("function", id), {
|
|
592
595
|
functionName: toName(stack, id),
|
|
593
596
|
handler: "index.default",
|
|
@@ -595,8 +598,8 @@ var toFunction = ({ config: config2, stack, assets }, id, fileOrProps) => {
|
|
|
595
598
|
...props,
|
|
596
599
|
memorySize: props.memorySize.toMebibytes()
|
|
597
600
|
});
|
|
598
|
-
lambda.addEnvironment("APP",
|
|
599
|
-
lambda.addEnvironment("STAGE",
|
|
601
|
+
lambda.addEnvironment("APP", config.name, { removeInEdge: true });
|
|
602
|
+
lambda.addEnvironment("STAGE", config.stage, { removeInEdge: true });
|
|
600
603
|
lambda.addEnvironment("STACK", stack.artifactId, { removeInEdge: true });
|
|
601
604
|
if (lambda.runtime.toString().startsWith("nodejs")) {
|
|
602
605
|
lambda.addEnvironment("AWS_NODEJS_CONNECTION_REUSE_ENABLED", "1", {
|
|
@@ -609,8 +612,8 @@ var toFunction = ({ config: config2, stack, assets }, id, fileOrProps) => {
|
|
|
609
612
|
resourceName: id,
|
|
610
613
|
async build() {
|
|
611
614
|
const result = await rollupBuild(props.file);
|
|
612
|
-
const bundle = await writeBuildFiles(
|
|
613
|
-
await writeBuildHash(
|
|
615
|
+
const bundle = await writeBuildFiles(config, stack, id, result.files);
|
|
616
|
+
await writeBuildHash(config, stack, id, result.hash);
|
|
614
617
|
const func = lambda.node.defaultChild;
|
|
615
618
|
func.handler = result.handler;
|
|
616
619
|
return {
|
|
@@ -618,11 +621,11 @@ var toFunction = ({ config: config2, stack, assets }, id, fileOrProps) => {
|
|
|
618
621
|
};
|
|
619
622
|
},
|
|
620
623
|
async publish() {
|
|
621
|
-
const version2 = await publishFunctionAsset(
|
|
624
|
+
const version2 = await publishFunctionAsset(config, stack, id);
|
|
622
625
|
const func = lambda.node.defaultChild;
|
|
623
626
|
func.code = {
|
|
624
|
-
s3Bucket: assetBucketName(
|
|
625
|
-
s3Key: `${
|
|
627
|
+
s3Bucket: assetBucketName(config),
|
|
628
|
+
s3Key: `${config.name}/${stack.artifactId}/function/${id}.zip`,
|
|
626
629
|
s3ObjectVersion: version2
|
|
627
630
|
};
|
|
628
631
|
}
|
|
@@ -691,9 +694,9 @@ var queuePlugin = definePlugin({
|
|
|
691
694
|
}).array()
|
|
692
695
|
}),
|
|
693
696
|
onStack(ctx) {
|
|
694
|
-
const { stack, config
|
|
697
|
+
const { stack, config, stackConfig, bind } = ctx;
|
|
695
698
|
return Object.entries(stackConfig.queues || {}).map(([id, functionOrProps]) => {
|
|
696
|
-
const props = typeof functionOrProps === "string" ? { ...
|
|
699
|
+
const props = typeof functionOrProps === "string" ? { ...config.defaults.queue, consumer: functionOrProps } : { ...config.defaults.queue, ...functionOrProps };
|
|
697
700
|
const queue2 = new Queue(stack, toId("queue", id), {
|
|
698
701
|
queueName: toName(stack, id),
|
|
699
702
|
...props,
|
|
@@ -857,20 +860,20 @@ var topicPlugin = definePlugin({
|
|
|
857
860
|
topics: z18.record(ResourceIdSchema, FunctionSchema).optional()
|
|
858
861
|
}).array()
|
|
859
862
|
}),
|
|
860
|
-
onBootstrap({ config
|
|
861
|
-
const allTopicNames =
|
|
863
|
+
onBootstrap({ config, stack }) {
|
|
864
|
+
const allTopicNames = config.stacks.map((stack2) => {
|
|
862
865
|
return Object.keys(stack2.topics || {});
|
|
863
866
|
}).flat();
|
|
864
867
|
const uniqueTopicNames = [...new Set(allTopicNames)];
|
|
865
868
|
uniqueTopicNames.forEach((id) => {
|
|
866
869
|
new Topic(stack, toId("topic", id), {
|
|
867
|
-
topicName: `${
|
|
870
|
+
topicName: `${config.name}-${id}`,
|
|
868
871
|
displayName: id
|
|
869
872
|
});
|
|
870
873
|
});
|
|
871
874
|
},
|
|
872
875
|
onStack(ctx) {
|
|
873
|
-
const { config
|
|
876
|
+
const { config, stack, stackConfig, bind } = ctx;
|
|
874
877
|
return Object.entries(stackConfig.topics || {}).map(([id, props]) => {
|
|
875
878
|
const lambda = toFunction(ctx, id, props);
|
|
876
879
|
const topic = Topic.fromTopicArn(
|
|
@@ -879,7 +882,7 @@ var topicPlugin = definePlugin({
|
|
|
879
882
|
Arn2.format({
|
|
880
883
|
arnFormat: ArnFormat.NO_RESOURCE_NAME,
|
|
881
884
|
service: "sns",
|
|
882
|
-
resource: `${
|
|
885
|
+
resource: `${config.name}-${id}`
|
|
883
886
|
}, stack)
|
|
884
887
|
);
|
|
885
888
|
lambda.addEventSource(new SnsEventSource(topic));
|
|
@@ -971,19 +974,19 @@ var graphqlPlugin = definePlugin({
|
|
|
971
974
|
})).optional()
|
|
972
975
|
}).array()
|
|
973
976
|
}),
|
|
974
|
-
onBootstrap({ config
|
|
977
|
+
onBootstrap({ config, stack, assets }) {
|
|
975
978
|
const list3 = /* @__PURE__ */ new Set();
|
|
976
|
-
Object.values(
|
|
979
|
+
Object.values(config.stacks).forEach((stackConfig) => {
|
|
977
980
|
Object.keys(stackConfig.graphql || {}).forEach((id) => {
|
|
978
981
|
list3.add(id);
|
|
979
982
|
});
|
|
980
983
|
});
|
|
981
984
|
list3.forEach((id) => {
|
|
982
|
-
const file = join4(assetDir, "graphql",
|
|
983
|
-
const authorization =
|
|
985
|
+
const file = join4(assetDir, "graphql", config.name, id, "schema.graphql");
|
|
986
|
+
const authorization = config.defaults.graphql?.[id]?.authorization;
|
|
984
987
|
const authProps = {};
|
|
985
988
|
if (authorization) {
|
|
986
|
-
const authorizer = toFunction({ config
|
|
989
|
+
const authorizer = toFunction({ config, assets, stack }, `${id}-authorizer`, authorization.authorizer);
|
|
987
990
|
authProps.additionalAuthenticationProviders = [{
|
|
988
991
|
authenticationType: AuthorizationType.LAMBDA,
|
|
989
992
|
lambdaAuthorizerConfig: {
|
|
@@ -1007,7 +1010,7 @@ var graphqlPlugin = definePlugin({
|
|
|
1007
1010
|
resourceName: id,
|
|
1008
1011
|
async build() {
|
|
1009
1012
|
const schemas = [];
|
|
1010
|
-
await Promise.all(Object.values(
|
|
1013
|
+
await Promise.all(Object.values(config.stacks).map(async (stackConfig) => {
|
|
1011
1014
|
const schemaFiles = toArray(stackConfig.graphql?.[id].schema || []);
|
|
1012
1015
|
await Promise.all(schemaFiles.map(async (schemaFile) => {
|
|
1013
1016
|
const schema3 = await readFile2(schemaFile, "utf8");
|
|
@@ -1026,9 +1029,9 @@ var graphqlPlugin = definePlugin({
|
|
|
1026
1029
|
});
|
|
1027
1030
|
},
|
|
1028
1031
|
onStack(ctx) {
|
|
1029
|
-
const { config
|
|
1032
|
+
const { config, stack, stackConfig } = ctx;
|
|
1030
1033
|
return Object.entries(stackConfig.graphql || {}).map(([id, props]) => {
|
|
1031
|
-
const defaults =
|
|
1034
|
+
const defaults = config.defaults.graphql?.[id] || {};
|
|
1032
1035
|
return Object.entries(props.resolvers || {}).map(([typeAndField, functionProps]) => {
|
|
1033
1036
|
const api = GraphqlApi.fromGraphqlApiAttributes(stack, toId("graphql", id), {
|
|
1034
1037
|
graphqlApiId: Fn.importValue(toId("graphql", id))
|
|
@@ -1051,6 +1054,48 @@ var graphqlPlugin = definePlugin({
|
|
|
1051
1054
|
}
|
|
1052
1055
|
});
|
|
1053
1056
|
|
|
1057
|
+
// src/plugins/pubsub.ts
|
|
1058
|
+
import { z as z22 } from "zod";
|
|
1059
|
+
import { CfnTopicRule } from "aws-cdk-lib/aws-iot";
|
|
1060
|
+
import { PolicyStatement as PolicyStatement3 } from "aws-cdk-lib/aws-iam";
|
|
1061
|
+
var pubsubPlugin = definePlugin({
|
|
1062
|
+
name: "pubsub",
|
|
1063
|
+
schema: z22.object({
|
|
1064
|
+
stacks: z22.object({
|
|
1065
|
+
pubsub: z22.record(ResourceIdSchema, z22.object({
|
|
1066
|
+
sql: z22.string(),
|
|
1067
|
+
sqlVersion: z22.enum(["2015-10-08", "2016-03-23", "beta"]).default("2016-03-23"),
|
|
1068
|
+
consumer: FunctionSchema
|
|
1069
|
+
})).optional()
|
|
1070
|
+
}).array()
|
|
1071
|
+
}),
|
|
1072
|
+
onStack(ctx) {
|
|
1073
|
+
const { stack, stackConfig, bind } = ctx;
|
|
1074
|
+
bind((lambda) => {
|
|
1075
|
+
lambda.addToRolePolicy(new PolicyStatement3({
|
|
1076
|
+
actions: ["iot:publish"],
|
|
1077
|
+
resources: ["*"]
|
|
1078
|
+
}));
|
|
1079
|
+
});
|
|
1080
|
+
return Object.entries(stackConfig.pubsub || {}).map(([id, props]) => {
|
|
1081
|
+
const lambda = toFunction(ctx, id, props.consumer);
|
|
1082
|
+
new CfnTopicRule(stack, toId("pubsub", id), {
|
|
1083
|
+
ruleName: toName(stack, id),
|
|
1084
|
+
topicRulePayload: {
|
|
1085
|
+
sql: props.sql,
|
|
1086
|
+
awsIotSqlVersion: props.sqlVersion,
|
|
1087
|
+
actions: [{
|
|
1088
|
+
lambda: {
|
|
1089
|
+
functionArn: lambda.functionArn
|
|
1090
|
+
}
|
|
1091
|
+
}]
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1094
|
+
return lambda;
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
|
|
1054
1099
|
// src/plugins/index.ts
|
|
1055
1100
|
var defaultPlugins = [
|
|
1056
1101
|
functionPlugin,
|
|
@@ -1060,21 +1105,22 @@ var defaultPlugins = [
|
|
|
1060
1105
|
storePlugin,
|
|
1061
1106
|
topicPlugin,
|
|
1062
1107
|
searchPlugin,
|
|
1063
|
-
graphqlPlugin
|
|
1108
|
+
graphqlPlugin,
|
|
1109
|
+
pubsubPlugin
|
|
1064
1110
|
];
|
|
1065
1111
|
|
|
1066
1112
|
// src/stack/app-bootstrap.ts
|
|
1067
|
-
var appBootstrapStack = ({ config
|
|
1113
|
+
var appBootstrapStack = ({ config, app, assets }) => {
|
|
1068
1114
|
const stack = new Stack3(app, "bootstrap", {
|
|
1069
|
-
stackName: `${
|
|
1115
|
+
stackName: `${config.name}-bootstrap`
|
|
1070
1116
|
});
|
|
1071
1117
|
const plugins = [
|
|
1072
1118
|
...defaultPlugins,
|
|
1073
|
-
...
|
|
1119
|
+
...config.plugins || []
|
|
1074
1120
|
];
|
|
1075
1121
|
debug("Run plugin onBootstrap listeners");
|
|
1076
1122
|
const functions = plugins.map((plugin) => plugin.onBootstrap?.({
|
|
1077
|
-
config
|
|
1123
|
+
config,
|
|
1078
1124
|
app,
|
|
1079
1125
|
stack,
|
|
1080
1126
|
assets
|
|
@@ -1098,9 +1144,9 @@ var flattenDependencyTree = (stacks) => {
|
|
|
1098
1144
|
return list3;
|
|
1099
1145
|
};
|
|
1100
1146
|
var createDependencyTree = (stacks, startingLevel) => {
|
|
1101
|
-
const list3 = stacks.map(({ stack, config
|
|
1147
|
+
const list3 = stacks.map(({ stack, config }) => ({
|
|
1102
1148
|
stack,
|
|
1103
|
-
depends:
|
|
1149
|
+
depends: config?.depends?.map((dep) => dep.name) || []
|
|
1104
1150
|
}));
|
|
1105
1151
|
const findChildren = (list4, parents, level) => {
|
|
1106
1152
|
const children = [];
|
|
@@ -1172,11 +1218,11 @@ var Assets = class {
|
|
|
1172
1218
|
};
|
|
1173
1219
|
|
|
1174
1220
|
// src/app.ts
|
|
1175
|
-
var makeApp = (
|
|
1221
|
+
var makeApp = (config) => {
|
|
1176
1222
|
return new App4({
|
|
1177
1223
|
outdir: assemblyDir,
|
|
1178
1224
|
defaultStackSynthesizer: new DefaultStackSynthesizer({
|
|
1179
|
-
fileAssetsBucketName: assetBucketName(
|
|
1225
|
+
fileAssetsBucketName: assetBucketName(config),
|
|
1180
1226
|
fileAssetPublishingRoleArn: "",
|
|
1181
1227
|
generateBootstrapVersionRule: false
|
|
1182
1228
|
})
|
|
@@ -1193,26 +1239,26 @@ var getAllDepends = (filters) => {
|
|
|
1193
1239
|
walk(filters);
|
|
1194
1240
|
return list3;
|
|
1195
1241
|
};
|
|
1196
|
-
var toApp = async (
|
|
1242
|
+
var toApp = async (config, filters) => {
|
|
1197
1243
|
const assets = new Assets();
|
|
1198
|
-
const app = makeApp(
|
|
1244
|
+
const app = makeApp(config);
|
|
1199
1245
|
const stacks = [];
|
|
1200
1246
|
const plugins = [
|
|
1201
1247
|
...defaultPlugins,
|
|
1202
|
-
...
|
|
1248
|
+
...config.plugins || []
|
|
1203
1249
|
];
|
|
1204
1250
|
debug("Plugins detected:", plugins.map((plugin) => style.info(plugin.name)).join(", "));
|
|
1205
1251
|
debug("Run plugin onApp listeners");
|
|
1206
|
-
plugins.forEach((plugin) => plugin.onApp?.({ config
|
|
1207
|
-
const bootstrap2 = appBootstrapStack({ config
|
|
1252
|
+
plugins.forEach((plugin) => plugin.onApp?.({ config, app, assets }));
|
|
1253
|
+
const bootstrap2 = appBootstrapStack({ config, app, assets });
|
|
1208
1254
|
debug("Stack filters:", filters.map((filter) => style.info(filter)).join(", "));
|
|
1209
|
-
const filterdStacks = filters.length === 0 ?
|
|
1255
|
+
const filterdStacks = filters.length === 0 ? config.stacks : getAllDepends(
|
|
1210
1256
|
// config.stacks,
|
|
1211
|
-
|
|
1257
|
+
config.stacks.filter((stack) => filters.includes(stack.name))
|
|
1212
1258
|
);
|
|
1213
1259
|
for (const stackConfig of filterdStacks) {
|
|
1214
1260
|
const { stack, bindings } = toStack({
|
|
1215
|
-
config
|
|
1261
|
+
config,
|
|
1216
1262
|
stackConfig,
|
|
1217
1263
|
assets,
|
|
1218
1264
|
plugins,
|
|
@@ -1317,17 +1363,17 @@ var getCredentials = (profile) => {
|
|
|
1317
1363
|
};
|
|
1318
1364
|
|
|
1319
1365
|
// src/schema/app.ts
|
|
1320
|
-
import { z as
|
|
1366
|
+
import { z as z26 } from "zod";
|
|
1321
1367
|
|
|
1322
1368
|
// src/schema/stack.ts
|
|
1323
|
-
import { z as
|
|
1324
|
-
var StackSchema =
|
|
1369
|
+
import { z as z23 } from "zod";
|
|
1370
|
+
var StackSchema = z23.object({
|
|
1325
1371
|
name: ResourceIdSchema,
|
|
1326
|
-
depends:
|
|
1372
|
+
depends: z23.array(z23.lazy(() => StackSchema)).optional()
|
|
1327
1373
|
});
|
|
1328
1374
|
|
|
1329
1375
|
// src/schema/region.ts
|
|
1330
|
-
import { z as
|
|
1376
|
+
import { z as z24 } from "zod";
|
|
1331
1377
|
var US = ["us-east-2", "us-east-1", "us-west-1", "us-west-2"];
|
|
1332
1378
|
var AF = ["af-south-1"];
|
|
1333
1379
|
var AP = ["ap-east-1", "ap-south-2", "ap-southeast-3", "ap-southeast-4", "ap-south-1", "ap-northeast-3", "ap-northeast-2", "ap-southeast-1", "ap-southeast-2", "ap-northeast-1"];
|
|
@@ -1344,29 +1390,29 @@ var regions = [
|
|
|
1344
1390
|
...ME,
|
|
1345
1391
|
...SA
|
|
1346
1392
|
];
|
|
1347
|
-
var RegionSchema =
|
|
1393
|
+
var RegionSchema = z24.enum(regions);
|
|
1348
1394
|
|
|
1349
1395
|
// src/schema/plugin.ts
|
|
1350
|
-
import { z as
|
|
1351
|
-
var PluginSchema =
|
|
1352
|
-
name:
|
|
1353
|
-
schema:
|
|
1396
|
+
import { z as z25 } from "zod";
|
|
1397
|
+
var PluginSchema = z25.object({
|
|
1398
|
+
name: z25.string(),
|
|
1399
|
+
schema: z25.custom().optional(),
|
|
1354
1400
|
// depends: z.array(z.lazy(() => PluginSchema)).optional(),
|
|
1355
|
-
onBootstrap:
|
|
1356
|
-
onStack:
|
|
1357
|
-
onApp:
|
|
1401
|
+
onBootstrap: z25.function().returns(z25.any()).optional(),
|
|
1402
|
+
onStack: z25.function().returns(z25.any()).optional(),
|
|
1403
|
+
onApp: z25.function().returns(z25.void()).optional()
|
|
1358
1404
|
// bind: z.function().optional(),
|
|
1359
1405
|
});
|
|
1360
1406
|
|
|
1361
1407
|
// src/schema/app.ts
|
|
1362
|
-
var AppSchema =
|
|
1408
|
+
var AppSchema = z26.object({
|
|
1363
1409
|
name: ResourceIdSchema,
|
|
1364
1410
|
region: RegionSchema,
|
|
1365
|
-
profile:
|
|
1366
|
-
stage:
|
|
1367
|
-
defaults:
|
|
1368
|
-
stacks:
|
|
1369
|
-
plugins:
|
|
1411
|
+
profile: z26.string(),
|
|
1412
|
+
stage: z26.string().regex(/[a-z]+/).default("prod"),
|
|
1413
|
+
defaults: z26.object({}).default({}),
|
|
1414
|
+
stacks: z26.array(StackSchema).min(1),
|
|
1415
|
+
plugins: z26.array(PluginSchema).optional()
|
|
1370
1416
|
});
|
|
1371
1417
|
|
|
1372
1418
|
// src/util/import.ts
|
|
@@ -1446,14 +1492,14 @@ var importConfig = async (options) => {
|
|
|
1446
1492
|
schema2 = schema2.and(plugin.schema);
|
|
1447
1493
|
}
|
|
1448
1494
|
}
|
|
1449
|
-
const
|
|
1450
|
-
debug("Load credentials", style.info(
|
|
1451
|
-
const credentials = getCredentials(
|
|
1495
|
+
const config = await schema2.parseAsync(appConfig);
|
|
1496
|
+
debug("Load credentials", style.info(config.profile));
|
|
1497
|
+
const credentials = getCredentials(config.profile);
|
|
1452
1498
|
debug("Load AWS account ID");
|
|
1453
|
-
const account = await getAccountId(credentials,
|
|
1499
|
+
const account = await getAccountId(credentials, config.region);
|
|
1454
1500
|
debug("Account ID:", style.info(account));
|
|
1455
1501
|
return {
|
|
1456
|
-
...
|
|
1502
|
+
...config,
|
|
1457
1503
|
account,
|
|
1458
1504
|
credentials
|
|
1459
1505
|
};
|
|
@@ -1475,14 +1521,14 @@ var list = (data) => {
|
|
|
1475
1521
|
};
|
|
1476
1522
|
|
|
1477
1523
|
// src/cli/ui/layout/header.ts
|
|
1478
|
-
var header = (
|
|
1524
|
+
var header = (config) => {
|
|
1479
1525
|
return [
|
|
1480
1526
|
br(),
|
|
1481
1527
|
list({
|
|
1482
|
-
App:
|
|
1483
|
-
Stage:
|
|
1484
|
-
Region:
|
|
1485
|
-
Profile:
|
|
1528
|
+
App: config.name,
|
|
1529
|
+
Stage: config.stage,
|
|
1530
|
+
Region: config.region,
|
|
1531
|
+
Profile: config.profile
|
|
1486
1532
|
}),
|
|
1487
1533
|
br()
|
|
1488
1534
|
];
|
|
@@ -1800,9 +1846,9 @@ var layout = async (cb) => {
|
|
|
1800
1846
|
term.out.write(logo());
|
|
1801
1847
|
try {
|
|
1802
1848
|
const options = program.optsWithGlobals();
|
|
1803
|
-
const
|
|
1804
|
-
term.out.write(header(
|
|
1805
|
-
await cb(
|
|
1849
|
+
const config = await importConfig(options);
|
|
1850
|
+
term.out.write(header(config));
|
|
1851
|
+
await cb(config, term.out.write.bind(term.out), term);
|
|
1806
1852
|
} catch (error) {
|
|
1807
1853
|
if (error instanceof Error) {
|
|
1808
1854
|
term.out.write(dialog("error", [error.message]));
|
|
@@ -1917,8 +1963,8 @@ var cleanUp = async () => {
|
|
|
1917
1963
|
// src/cli/command/build.ts
|
|
1918
1964
|
var build = (program2) => {
|
|
1919
1965
|
program2.command("build").argument("[stack...]", "Optionally filter stacks to build").description("Build your app").action(async (filters) => {
|
|
1920
|
-
await layout(async (
|
|
1921
|
-
const { app, assets } = await toApp(
|
|
1966
|
+
await layout(async (config, write) => {
|
|
1967
|
+
const { app, assets } = await toApp(config, filters);
|
|
1922
1968
|
await cleanUp();
|
|
1923
1969
|
await write(assetBuilder(assets));
|
|
1924
1970
|
app.synth();
|
|
@@ -1931,11 +1977,11 @@ import { CloudFormationClient, CreateStackCommand, DeleteStackCommand, DescribeS
|
|
|
1931
1977
|
import { S3Client as S3Client2, PutObjectCommand as PutObjectCommand2, ObjectCannedACL as ObjectCannedACL2, StorageClass as StorageClass2 } from "@aws-sdk/client-s3";
|
|
1932
1978
|
var StackClient = class {
|
|
1933
1979
|
// 30 seconds
|
|
1934
|
-
constructor(
|
|
1935
|
-
this.config =
|
|
1980
|
+
constructor(config) {
|
|
1981
|
+
this.config = config;
|
|
1936
1982
|
this.client = new CloudFormationClient({
|
|
1937
|
-
credentials:
|
|
1938
|
-
region:
|
|
1983
|
+
credentials: config.credentials,
|
|
1984
|
+
region: config.region
|
|
1939
1985
|
});
|
|
1940
1986
|
}
|
|
1941
1987
|
client;
|
|
@@ -2164,12 +2210,12 @@ var confirmPrompt = (label, options = {}) => {
|
|
|
2164
2210
|
};
|
|
2165
2211
|
|
|
2166
2212
|
// src/cli/ui/complex/bootstrap.ts
|
|
2167
|
-
var bootstrapDeployer = (
|
|
2213
|
+
var bootstrapDeployer = (config) => {
|
|
2168
2214
|
return async (term) => {
|
|
2169
2215
|
debug("Initializing bootstrap");
|
|
2170
|
-
const app = makeApp(
|
|
2171
|
-
const client = new StackClient(
|
|
2172
|
-
const bootstrap2 = bootstrapStack(
|
|
2216
|
+
const app = makeApp(config);
|
|
2217
|
+
const client = new StackClient(config);
|
|
2218
|
+
const bootstrap2 = bootstrapStack(config, app);
|
|
2173
2219
|
const shouldDeploy = await shouldDeployBootstrap(client, bootstrap2.stackName);
|
|
2174
2220
|
if (shouldDeploy) {
|
|
2175
2221
|
term.out.write(dialog("warning", [`Your app hasn't been bootstrapped yet`]));
|
|
@@ -2193,8 +2239,8 @@ var bootstrapDeployer = (config2) => {
|
|
|
2193
2239
|
// src/cli/command/bootstrap.ts
|
|
2194
2240
|
var bootstrap = (program2) => {
|
|
2195
2241
|
program2.command("bootstrap").description("Create the awsless bootstrap stack").action(async () => {
|
|
2196
|
-
await layout(async (
|
|
2197
|
-
await write(bootstrapDeployer(
|
|
2242
|
+
await layout(async (config, write) => {
|
|
2243
|
+
await write(bootstrapDeployer(config));
|
|
2198
2244
|
});
|
|
2199
2245
|
});
|
|
2200
2246
|
};
|
|
@@ -2238,14 +2284,14 @@ var stackTree = (nodes, statuses) => {
|
|
|
2238
2284
|
// src/cli/command/status.ts
|
|
2239
2285
|
var status = (program2) => {
|
|
2240
2286
|
program2.command("status").argument("[stacks...]", "Optionally filter stacks to lookup status").description("View the application status").action(async (filters) => {
|
|
2241
|
-
await layout(async (
|
|
2242
|
-
const { app, assets, dependencyTree } = await toApp(
|
|
2287
|
+
await layout(async (config, write) => {
|
|
2288
|
+
const { app, assets, dependencyTree } = await toApp(config, filters);
|
|
2243
2289
|
await cleanUp();
|
|
2244
2290
|
await write(assetBuilder(assets));
|
|
2245
2291
|
write(br());
|
|
2246
2292
|
const assembly = app.synth();
|
|
2247
2293
|
const doneLoading = write(loadingDialog("Loading stack information..."));
|
|
2248
|
-
const client = new StackClient(
|
|
2294
|
+
const client = new StackClient(config);
|
|
2249
2295
|
const statuses = [];
|
|
2250
2296
|
const stackStatuses = {};
|
|
2251
2297
|
assembly.stacks.forEach((stack) => {
|
|
@@ -2285,9 +2331,9 @@ var status = (program2) => {
|
|
|
2285
2331
|
// src/cli/command/deploy.ts
|
|
2286
2332
|
var deploy = (program2) => {
|
|
2287
2333
|
program2.command("deploy").argument("[stacks...]", "Optionally filter stacks to deploy").description("Deploy your app to AWS").action(async (filters) => {
|
|
2288
|
-
await layout(async (
|
|
2289
|
-
await write(bootstrapDeployer(
|
|
2290
|
-
const { app, stackNames, assets, dependencyTree } = await toApp(
|
|
2334
|
+
await layout(async (config, write) => {
|
|
2335
|
+
await write(bootstrapDeployer(config));
|
|
2336
|
+
const { app, stackNames, assets, dependencyTree } = await toApp(config, filters);
|
|
2291
2337
|
const formattedFilter = stackNames.map((i) => style.info(i)).join(style.placeholder(", "));
|
|
2292
2338
|
debug("Stacks to deploy", formattedFilter);
|
|
2293
2339
|
const deployAll = filters.length === 0;
|
|
@@ -2316,7 +2362,7 @@ var deploy = (program2) => {
|
|
|
2316
2362
|
write(br());
|
|
2317
2363
|
write(stackTree(dependencyTree, statuses));
|
|
2318
2364
|
write(br());
|
|
2319
|
-
const client = new StackClient(
|
|
2365
|
+
const client = new StackClient(config);
|
|
2320
2366
|
const deploymentLine = createDeploymentLine(dependencyTree);
|
|
2321
2367
|
for (const stacks of deploymentLine) {
|
|
2322
2368
|
const results = await Promise.allSettled(stacks.map(async (stack) => {
|
|
@@ -2405,35 +2451,35 @@ var textPrompt = (label, options = {}) => {
|
|
|
2405
2451
|
};
|
|
2406
2452
|
};
|
|
2407
2453
|
|
|
2408
|
-
// src/cli/command/
|
|
2454
|
+
// src/cli/command/secrets/set.ts
|
|
2409
2455
|
var set = (program2) => {
|
|
2410
|
-
program2.command("set <name>").description("Set a
|
|
2411
|
-
await layout(async (
|
|
2412
|
-
const params = new Params(
|
|
2456
|
+
program2.command("set <name>").description("Set a secret value").action(async (name) => {
|
|
2457
|
+
await layout(async (config, write) => {
|
|
2458
|
+
const params = new Params(config);
|
|
2413
2459
|
write(list({
|
|
2414
|
-
"Set
|
|
2460
|
+
"Set secret parameter": style.info(name)
|
|
2415
2461
|
}));
|
|
2416
2462
|
write(br());
|
|
2417
|
-
const value = await write(textPrompt("Enter
|
|
2463
|
+
const value = await write(textPrompt("Enter secret value"));
|
|
2418
2464
|
if (value === "") {
|
|
2419
|
-
write(dialog("error", [`Provided
|
|
2465
|
+
write(dialog("error", [`Provided secret value can't be empty`]));
|
|
2420
2466
|
} else {
|
|
2421
|
-
const done = write(loadingDialog(`Saving remote
|
|
2467
|
+
const done = write(loadingDialog(`Saving remote secret parameter`));
|
|
2422
2468
|
await params.set(name, value);
|
|
2423
|
-
done(`Done saving remote
|
|
2469
|
+
done(`Done saving remote secret parameter`);
|
|
2424
2470
|
}
|
|
2425
2471
|
});
|
|
2426
2472
|
});
|
|
2427
2473
|
};
|
|
2428
2474
|
|
|
2429
|
-
// src/cli/command/
|
|
2475
|
+
// src/cli/command/secrets/get.ts
|
|
2430
2476
|
var get = (program2) => {
|
|
2431
|
-
program2.command("get <name>").description("Get a
|
|
2432
|
-
await layout(async (
|
|
2433
|
-
const params = new Params(
|
|
2434
|
-
const done = write(loadingDialog(`Getting remote
|
|
2477
|
+
program2.command("get <name>").description("Get a secret value").action(async (name) => {
|
|
2478
|
+
await layout(async (config, write) => {
|
|
2479
|
+
const params = new Params(config);
|
|
2480
|
+
const done = write(loadingDialog(`Getting remote secret parameter`));
|
|
2435
2481
|
const value = await params.get(name);
|
|
2436
|
-
done(`Done getting remote
|
|
2482
|
+
done(`Done getting remote secret parameter`);
|
|
2437
2483
|
write(br());
|
|
2438
2484
|
write(list({
|
|
2439
2485
|
Name: name,
|
|
@@ -2443,20 +2489,20 @@ var get = (program2) => {
|
|
|
2443
2489
|
});
|
|
2444
2490
|
};
|
|
2445
2491
|
|
|
2446
|
-
// src/cli/command/
|
|
2492
|
+
// src/cli/command/secrets/delete.ts
|
|
2447
2493
|
var del = (program2) => {
|
|
2448
|
-
program2.command("delete <name>").description("Delete a
|
|
2449
|
-
await layout(async (
|
|
2450
|
-
const params = new Params(
|
|
2451
|
-
write(dialog("warning", [`Your deleting the ${style.info(name)}
|
|
2494
|
+
program2.command("delete <name>").description("Delete a secret value").action(async (name) => {
|
|
2495
|
+
await layout(async (config, write) => {
|
|
2496
|
+
const params = new Params(config);
|
|
2497
|
+
write(dialog("warning", [`Your deleting the ${style.info(name)} secret parameter`]));
|
|
2452
2498
|
const confirm = await write(confirmPrompt("Are you sure?"));
|
|
2453
2499
|
if (!confirm) {
|
|
2454
2500
|
throw new Cancelled();
|
|
2455
2501
|
}
|
|
2456
|
-
const done = write(loadingDialog(`Deleting remote
|
|
2502
|
+
const done = write(loadingDialog(`Deleting remote secret parameter`));
|
|
2457
2503
|
const value = await params.get(name);
|
|
2458
2504
|
await params.delete(name);
|
|
2459
|
-
done(`Done deleting remote
|
|
2505
|
+
done(`Done deleting remote secret parameter`);
|
|
2460
2506
|
write(br());
|
|
2461
2507
|
write(list({
|
|
2462
2508
|
Name: name,
|
|
@@ -2466,33 +2512,33 @@ var del = (program2) => {
|
|
|
2466
2512
|
});
|
|
2467
2513
|
};
|
|
2468
2514
|
|
|
2469
|
-
// src/cli/command/
|
|
2515
|
+
// src/cli/command/secrets/list.ts
|
|
2470
2516
|
var list2 = (program2) => {
|
|
2471
|
-
program2.command("list").description(`List all
|
|
2472
|
-
await layout(async (
|
|
2473
|
-
const params = new Params(
|
|
2474
|
-
const done = write(loadingDialog("Loading
|
|
2517
|
+
program2.command("list").description(`List all secret value's`).action(async () => {
|
|
2518
|
+
await layout(async (config, write) => {
|
|
2519
|
+
const params = new Params(config);
|
|
2520
|
+
const done = write(loadingDialog("Loading secret parameters..."));
|
|
2475
2521
|
const values = await params.list();
|
|
2476
|
-
done("Done loading
|
|
2522
|
+
done("Done loading secret values");
|
|
2477
2523
|
if (Object.keys(values).length > 0) {
|
|
2478
2524
|
write(br());
|
|
2479
2525
|
write(list(values));
|
|
2480
2526
|
} else {
|
|
2481
|
-
write(dialog("warning", ["No
|
|
2527
|
+
write(dialog("warning", ["No secret parameters found"]));
|
|
2482
2528
|
}
|
|
2483
2529
|
});
|
|
2484
2530
|
});
|
|
2485
2531
|
};
|
|
2486
2532
|
|
|
2487
|
-
// src/cli/command/
|
|
2533
|
+
// src/cli/command/secrets/index.ts
|
|
2488
2534
|
var commands = [
|
|
2489
2535
|
set,
|
|
2490
2536
|
get,
|
|
2491
2537
|
del,
|
|
2492
2538
|
list2
|
|
2493
2539
|
];
|
|
2494
|
-
var
|
|
2495
|
-
const command = program2.command("
|
|
2540
|
+
var secrets = (program2) => {
|
|
2541
|
+
const command = program2.command("secrets").description(`Manage app secrets`);
|
|
2496
2542
|
commands.forEach((cb) => cb(command));
|
|
2497
2543
|
};
|
|
2498
2544
|
|
|
@@ -2513,7 +2559,7 @@ var commands2 = [
|
|
|
2513
2559
|
status,
|
|
2514
2560
|
build,
|
|
2515
2561
|
deploy,
|
|
2516
|
-
|
|
2562
|
+
secrets
|
|
2517
2563
|
// diff,
|
|
2518
2564
|
// remove,
|
|
2519
2565
|
// test,
|