@awsless/awsless 0.0.12 → 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 +200 -157
- package/dist/bin.js +200 -157
- package/dist/index.d.ts +179 -0
- package/package.json +1 -1
package/dist/bin.cjs
CHANGED
|
@@ -83,15 +83,15 @@ var flushDebug = () => {
|
|
|
83
83
|
|
|
84
84
|
// src/util/param.ts
|
|
85
85
|
var import_client_ssm = require("@aws-sdk/client-ssm");
|
|
86
|
-
var configParameterPrefix = (
|
|
87
|
-
return `/${
|
|
86
|
+
var configParameterPrefix = (config) => {
|
|
87
|
+
return `/${config.stage}/awsless/${config.name}`;
|
|
88
88
|
};
|
|
89
89
|
var Params = class {
|
|
90
|
-
constructor(
|
|
91
|
-
this.config =
|
|
90
|
+
constructor(config) {
|
|
91
|
+
this.config = config;
|
|
92
92
|
this.client = new import_client_ssm.SSMClient({
|
|
93
|
-
credentials:
|
|
94
|
-
region:
|
|
93
|
+
credentials: config.credentials,
|
|
94
|
+
region: config.region
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
client;
|
|
@@ -166,13 +166,13 @@ var Params = class {
|
|
|
166
166
|
};
|
|
167
167
|
|
|
168
168
|
// src/stack.ts
|
|
169
|
-
var toStack = ({ config
|
|
170
|
-
const stackName = `${
|
|
169
|
+
var toStack = ({ config, assets, app, stackConfig, plugins }) => {
|
|
170
|
+
const stackName = `${config.name}-${stackConfig.name}`;
|
|
171
171
|
const stack = new import_aws_cdk_lib.Stack(app, stackConfig.name, {
|
|
172
172
|
stackName,
|
|
173
173
|
tags: {
|
|
174
|
-
APP:
|
|
175
|
-
STAGE:
|
|
174
|
+
APP: config.name,
|
|
175
|
+
STAGE: config.stage,
|
|
176
176
|
STACK: stackConfig.name
|
|
177
177
|
}
|
|
178
178
|
});
|
|
@@ -183,7 +183,7 @@ var toStack = ({ config: config2, assets, app, stackConfig, plugins }) => {
|
|
|
183
183
|
};
|
|
184
184
|
debug("Run plugin onStack listeners");
|
|
185
185
|
const functions = plugins.map((plugin) => plugin.onStack?.({
|
|
186
|
-
config
|
|
186
|
+
config,
|
|
187
187
|
assets,
|
|
188
188
|
app,
|
|
189
189
|
stack,
|
|
@@ -202,12 +202,12 @@ var toStack = ({ config: config2, assets, app, stackConfig, plugins }) => {
|
|
|
202
202
|
],
|
|
203
203
|
resources: [
|
|
204
204
|
import_aws_cdk_lib.Arn.format({
|
|
205
|
-
region:
|
|
206
|
-
account:
|
|
205
|
+
region: config.region,
|
|
206
|
+
account: config.account,
|
|
207
207
|
partition: "aws",
|
|
208
208
|
service: "ssm",
|
|
209
209
|
resource: "parameter",
|
|
210
|
-
resourceName: configParameterPrefix(
|
|
210
|
+
resourceName: configParameterPrefix(config)
|
|
211
211
|
})
|
|
212
212
|
// Fn.sub('arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter' + configParameterPrefix(config)),
|
|
213
213
|
]
|
|
@@ -400,17 +400,17 @@ var zipFiles = (files) => {
|
|
|
400
400
|
}
|
|
401
401
|
});
|
|
402
402
|
};
|
|
403
|
-
var writeBuildHash = async (
|
|
404
|
-
const funcPath = (0, import_path3.join)(assetDir, "function",
|
|
403
|
+
var writeBuildHash = async (config, stack, id, hash) => {
|
|
404
|
+
const funcPath = (0, import_path3.join)(assetDir, "function", config.name, stack.artifactId, id);
|
|
405
405
|
const versionFile = (0, import_path3.join)(funcPath, "HASH");
|
|
406
406
|
await (0, import_promises2.writeFile)(versionFile, hash);
|
|
407
407
|
};
|
|
408
|
-
var writeBuildFiles = async (
|
|
408
|
+
var writeBuildFiles = async (config, stack, id, files) => {
|
|
409
409
|
const bundle = await zipFiles(files);
|
|
410
|
-
const funcPath = (0, import_path3.join)(assetDir, "function",
|
|
410
|
+
const funcPath = (0, import_path3.join)(assetDir, "function", config.name, stack.artifactId, id);
|
|
411
411
|
const filesPath = (0, import_path3.join)(funcPath, "files");
|
|
412
412
|
const bundleFile = (0, import_path3.join)(funcPath, "bundle.zip");
|
|
413
|
-
debug("Bundle size of", style.info((0, import_path3.join)(
|
|
413
|
+
debug("Bundle size of", style.info((0, import_path3.join)(config.name, stack.artifactId, id)), "is", style.attr((0, import_filesize.filesize)(bundle.byteLength)));
|
|
414
414
|
await (0, import_promises2.mkdir)(filesPath, { recursive: true });
|
|
415
415
|
await (0, import_promises2.writeFile)(bundleFile, bundle);
|
|
416
416
|
await Promise.all(files.map(async (file) => {
|
|
@@ -436,20 +436,20 @@ var import_client_s3 = require("@aws-sdk/client-s3");
|
|
|
436
436
|
// src/stack/bootstrap.ts
|
|
437
437
|
var import_aws_cdk_lib2 = require("aws-cdk-lib");
|
|
438
438
|
var import_aws_s3 = require("aws-cdk-lib/aws-s3");
|
|
439
|
-
var assetBucketName = (
|
|
440
|
-
return `awsless-bootstrap-${
|
|
439
|
+
var assetBucketName = (config) => {
|
|
440
|
+
return `awsless-bootstrap-${config.account}-${config.region}`;
|
|
441
441
|
};
|
|
442
|
-
var assetBucketUrl = (
|
|
443
|
-
const bucket = assetBucketName(
|
|
444
|
-
return `https://s3-${
|
|
442
|
+
var assetBucketUrl = (config, stackName) => {
|
|
443
|
+
const bucket = assetBucketName(config);
|
|
444
|
+
return `https://s3-${config.region}.amazonaws.com/${bucket}/${stackName}/cloudformation.json`;
|
|
445
445
|
};
|
|
446
446
|
var version = "2";
|
|
447
|
-
var bootstrapStack = (
|
|
447
|
+
var bootstrapStack = (config, app) => {
|
|
448
448
|
const stack = new import_aws_cdk_lib2.Stack(app, "bootstrap", {
|
|
449
449
|
stackName: `awsless-bootstrap`
|
|
450
450
|
});
|
|
451
451
|
new import_aws_s3.Bucket(stack, "assets", {
|
|
452
|
-
bucketName: assetBucketName(
|
|
452
|
+
bucketName: assetBucketName(config),
|
|
453
453
|
versioned: true,
|
|
454
454
|
accessControl: import_aws_s3.BucketAccessControl.PRIVATE,
|
|
455
455
|
removalPolicy: import_aws_cdk_lib2.RemovalPolicy.DESTROY
|
|
@@ -467,17 +467,17 @@ var shouldDeployBootstrap = async (client, name) => {
|
|
|
467
467
|
};
|
|
468
468
|
|
|
469
469
|
// src/plugins/function/util/publish.ts
|
|
470
|
-
var publishFunctionAsset = async (
|
|
471
|
-
const bucket = assetBucketName(
|
|
472
|
-
const key = `${
|
|
473
|
-
const funcPath = (0, import_path5.join)(assetDir, "function",
|
|
470
|
+
var publishFunctionAsset = async (config, stack, id) => {
|
|
471
|
+
const bucket = assetBucketName(config);
|
|
472
|
+
const key = `${config.name}/${stack.artifactId}/function/${id}.zip`;
|
|
473
|
+
const funcPath = (0, import_path5.join)(assetDir, "function", config.name, stack.artifactId, id);
|
|
474
474
|
const bundleFile = (0, import_path5.join)(funcPath, "bundle.zip");
|
|
475
475
|
const hashFile = (0, import_path5.join)(funcPath, "HASH");
|
|
476
476
|
const hash = await (0, import_promises3.readFile)(hashFile, "utf8");
|
|
477
477
|
const file = await (0, import_promises3.readFile)(bundleFile);
|
|
478
478
|
const client = new import_client_s3.S3Client({
|
|
479
|
-
credentials:
|
|
480
|
-
region:
|
|
479
|
+
credentials: config.credentials,
|
|
480
|
+
region: config.region
|
|
481
481
|
});
|
|
482
482
|
let getResult;
|
|
483
483
|
try {
|
|
@@ -612,8 +612,8 @@ var functionPlugin = definePlugin({
|
|
|
612
612
|
});
|
|
613
613
|
}
|
|
614
614
|
});
|
|
615
|
-
var toFunction = ({ config
|
|
616
|
-
const props = typeof fileOrProps === "string" ? { ...
|
|
615
|
+
var toFunction = ({ config, stack, assets }, id, fileOrProps) => {
|
|
616
|
+
const props = typeof fileOrProps === "string" ? { ...config.defaults?.function, file: fileOrProps } : { ...config.defaults?.function, ...fileOrProps };
|
|
617
617
|
const lambda = new import_aws_lambda3.Function(stack, toId("function", id), {
|
|
618
618
|
functionName: toName(stack, id),
|
|
619
619
|
handler: "index.default",
|
|
@@ -621,8 +621,8 @@ var toFunction = ({ config: config2, stack, assets }, id, fileOrProps) => {
|
|
|
621
621
|
...props,
|
|
622
622
|
memorySize: props.memorySize.toMebibytes()
|
|
623
623
|
});
|
|
624
|
-
lambda.addEnvironment("APP",
|
|
625
|
-
lambda.addEnvironment("STAGE",
|
|
624
|
+
lambda.addEnvironment("APP", config.name, { removeInEdge: true });
|
|
625
|
+
lambda.addEnvironment("STAGE", config.stage, { removeInEdge: true });
|
|
626
626
|
lambda.addEnvironment("STACK", stack.artifactId, { removeInEdge: true });
|
|
627
627
|
if (lambda.runtime.toString().startsWith("nodejs")) {
|
|
628
628
|
lambda.addEnvironment("AWS_NODEJS_CONNECTION_REUSE_ENABLED", "1", {
|
|
@@ -635,8 +635,8 @@ var toFunction = ({ config: config2, stack, assets }, id, fileOrProps) => {
|
|
|
635
635
|
resourceName: id,
|
|
636
636
|
async build() {
|
|
637
637
|
const result = await rollupBuild(props.file);
|
|
638
|
-
const bundle = await writeBuildFiles(
|
|
639
|
-
await writeBuildHash(
|
|
638
|
+
const bundle = await writeBuildFiles(config, stack, id, result.files);
|
|
639
|
+
await writeBuildHash(config, stack, id, result.hash);
|
|
640
640
|
const func = lambda.node.defaultChild;
|
|
641
641
|
func.handler = result.handler;
|
|
642
642
|
return {
|
|
@@ -644,11 +644,11 @@ var toFunction = ({ config: config2, stack, assets }, id, fileOrProps) => {
|
|
|
644
644
|
};
|
|
645
645
|
},
|
|
646
646
|
async publish() {
|
|
647
|
-
const version2 = await publishFunctionAsset(
|
|
647
|
+
const version2 = await publishFunctionAsset(config, stack, id);
|
|
648
648
|
const func = lambda.node.defaultChild;
|
|
649
649
|
func.code = {
|
|
650
|
-
s3Bucket: assetBucketName(
|
|
651
|
-
s3Key: `${
|
|
650
|
+
s3Bucket: assetBucketName(config),
|
|
651
|
+
s3Key: `${config.name}/${stack.artifactId}/function/${id}.zip`,
|
|
652
652
|
s3ObjectVersion: version2
|
|
653
653
|
};
|
|
654
654
|
}
|
|
@@ -717,9 +717,9 @@ var queuePlugin = definePlugin({
|
|
|
717
717
|
}).array()
|
|
718
718
|
}),
|
|
719
719
|
onStack(ctx) {
|
|
720
|
-
const { stack, config
|
|
720
|
+
const { stack, config, stackConfig, bind } = ctx;
|
|
721
721
|
return Object.entries(stackConfig.queues || {}).map(([id, functionOrProps]) => {
|
|
722
|
-
const props = typeof functionOrProps === "string" ? { ...
|
|
722
|
+
const props = typeof functionOrProps === "string" ? { ...config.defaults.queue, consumer: functionOrProps } : { ...config.defaults.queue, ...functionOrProps };
|
|
723
723
|
const queue2 = new import_aws_sqs.Queue(stack, toId("queue", id), {
|
|
724
724
|
queueName: toName(stack, id),
|
|
725
725
|
...props,
|
|
@@ -883,20 +883,20 @@ var topicPlugin = definePlugin({
|
|
|
883
883
|
topics: import_zod18.z.record(ResourceIdSchema, FunctionSchema).optional()
|
|
884
884
|
}).array()
|
|
885
885
|
}),
|
|
886
|
-
onBootstrap({ config
|
|
887
|
-
const allTopicNames =
|
|
886
|
+
onBootstrap({ config, stack }) {
|
|
887
|
+
const allTopicNames = config.stacks.map((stack2) => {
|
|
888
888
|
return Object.keys(stack2.topics || {});
|
|
889
889
|
}).flat();
|
|
890
890
|
const uniqueTopicNames = [...new Set(allTopicNames)];
|
|
891
891
|
uniqueTopicNames.forEach((id) => {
|
|
892
892
|
new import_aws_sns.Topic(stack, toId("topic", id), {
|
|
893
|
-
topicName: `${
|
|
893
|
+
topicName: `${config.name}-${id}`,
|
|
894
894
|
displayName: id
|
|
895
895
|
});
|
|
896
896
|
});
|
|
897
897
|
},
|
|
898
898
|
onStack(ctx) {
|
|
899
|
-
const { config
|
|
899
|
+
const { config, stack, stackConfig, bind } = ctx;
|
|
900
900
|
return Object.entries(stackConfig.topics || {}).map(([id, props]) => {
|
|
901
901
|
const lambda = toFunction(ctx, id, props);
|
|
902
902
|
const topic = import_aws_sns.Topic.fromTopicArn(
|
|
@@ -905,7 +905,7 @@ var topicPlugin = definePlugin({
|
|
|
905
905
|
import_aws_cdk_lib4.Arn.format({
|
|
906
906
|
arnFormat: import_aws_cdk_lib4.ArnFormat.NO_RESOURCE_NAME,
|
|
907
907
|
service: "sns",
|
|
908
|
-
resource: `${
|
|
908
|
+
resource: `${config.name}-${id}`
|
|
909
909
|
}, stack)
|
|
910
910
|
);
|
|
911
911
|
lambda.addEventSource(new import_aws_lambda_event_sources2.SnsEventSource(topic));
|
|
@@ -997,19 +997,19 @@ var graphqlPlugin = definePlugin({
|
|
|
997
997
|
})).optional()
|
|
998
998
|
}).array()
|
|
999
999
|
}),
|
|
1000
|
-
onBootstrap({ config
|
|
1000
|
+
onBootstrap({ config, stack, assets }) {
|
|
1001
1001
|
const list3 = /* @__PURE__ */ new Set();
|
|
1002
|
-
Object.values(
|
|
1002
|
+
Object.values(config.stacks).forEach((stackConfig) => {
|
|
1003
1003
|
Object.keys(stackConfig.graphql || {}).forEach((id) => {
|
|
1004
1004
|
list3.add(id);
|
|
1005
1005
|
});
|
|
1006
1006
|
});
|
|
1007
1007
|
list3.forEach((id) => {
|
|
1008
|
-
const file = (0, import_path6.join)(assetDir, "graphql",
|
|
1009
|
-
const authorization =
|
|
1008
|
+
const file = (0, import_path6.join)(assetDir, "graphql", config.name, id, "schema.graphql");
|
|
1009
|
+
const authorization = config.defaults.graphql?.[id]?.authorization;
|
|
1010
1010
|
const authProps = {};
|
|
1011
1011
|
if (authorization) {
|
|
1012
|
-
const authorizer = toFunction({ config
|
|
1012
|
+
const authorizer = toFunction({ config, assets, stack }, `${id}-authorizer`, authorization.authorizer);
|
|
1013
1013
|
authProps.additionalAuthenticationProviders = [{
|
|
1014
1014
|
authenticationType: import_aws_appsync.AuthorizationType.LAMBDA,
|
|
1015
1015
|
lambdaAuthorizerConfig: {
|
|
@@ -1033,7 +1033,7 @@ var graphqlPlugin = definePlugin({
|
|
|
1033
1033
|
resourceName: id,
|
|
1034
1034
|
async build() {
|
|
1035
1035
|
const schemas = [];
|
|
1036
|
-
await Promise.all(Object.values(
|
|
1036
|
+
await Promise.all(Object.values(config.stacks).map(async (stackConfig) => {
|
|
1037
1037
|
const schemaFiles = toArray(stackConfig.graphql?.[id].schema || []);
|
|
1038
1038
|
await Promise.all(schemaFiles.map(async (schemaFile) => {
|
|
1039
1039
|
const schema3 = await (0, import_promises4.readFile)(schemaFile, "utf8");
|
|
@@ -1052,9 +1052,9 @@ var graphqlPlugin = definePlugin({
|
|
|
1052
1052
|
});
|
|
1053
1053
|
},
|
|
1054
1054
|
onStack(ctx) {
|
|
1055
|
-
const { config
|
|
1055
|
+
const { config, stack, stackConfig } = ctx;
|
|
1056
1056
|
return Object.entries(stackConfig.graphql || {}).map(([id, props]) => {
|
|
1057
|
-
const defaults =
|
|
1057
|
+
const defaults = config.defaults.graphql?.[id] || {};
|
|
1058
1058
|
return Object.entries(props.resolvers || {}).map(([typeAndField, functionProps]) => {
|
|
1059
1059
|
const api = import_aws_appsync.GraphqlApi.fromGraphqlApiAttributes(stack, toId("graphql", id), {
|
|
1060
1060
|
graphqlApiId: import_aws_cdk_lib5.Fn.importValue(toId("graphql", id))
|
|
@@ -1077,6 +1077,48 @@ var graphqlPlugin = definePlugin({
|
|
|
1077
1077
|
}
|
|
1078
1078
|
});
|
|
1079
1079
|
|
|
1080
|
+
// src/plugins/pubsub.ts
|
|
1081
|
+
var import_zod22 = require("zod");
|
|
1082
|
+
var import_aws_iot = require("aws-cdk-lib/aws-iot");
|
|
1083
|
+
var import_aws_iam3 = require("aws-cdk-lib/aws-iam");
|
|
1084
|
+
var pubsubPlugin = definePlugin({
|
|
1085
|
+
name: "pubsub",
|
|
1086
|
+
schema: import_zod22.z.object({
|
|
1087
|
+
stacks: import_zod22.z.object({
|
|
1088
|
+
pubsub: import_zod22.z.record(ResourceIdSchema, import_zod22.z.object({
|
|
1089
|
+
sql: import_zod22.z.string(),
|
|
1090
|
+
sqlVersion: import_zod22.z.enum(["2015-10-08", "2016-03-23", "beta"]).default("2016-03-23"),
|
|
1091
|
+
consumer: FunctionSchema
|
|
1092
|
+
})).optional()
|
|
1093
|
+
}).array()
|
|
1094
|
+
}),
|
|
1095
|
+
onStack(ctx) {
|
|
1096
|
+
const { stack, stackConfig, bind } = ctx;
|
|
1097
|
+
bind((lambda) => {
|
|
1098
|
+
lambda.addToRolePolicy(new import_aws_iam3.PolicyStatement({
|
|
1099
|
+
actions: ["iot:publish"],
|
|
1100
|
+
resources: ["*"]
|
|
1101
|
+
}));
|
|
1102
|
+
});
|
|
1103
|
+
return Object.entries(stackConfig.pubsub || {}).map(([id, props]) => {
|
|
1104
|
+
const lambda = toFunction(ctx, id, props.consumer);
|
|
1105
|
+
new import_aws_iot.CfnTopicRule(stack, toId("pubsub", id), {
|
|
1106
|
+
ruleName: toName(stack, id),
|
|
1107
|
+
topicRulePayload: {
|
|
1108
|
+
sql: props.sql,
|
|
1109
|
+
awsIotSqlVersion: props.sqlVersion,
|
|
1110
|
+
actions: [{
|
|
1111
|
+
lambda: {
|
|
1112
|
+
functionArn: lambda.functionArn
|
|
1113
|
+
}
|
|
1114
|
+
}]
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
return lambda;
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
});
|
|
1121
|
+
|
|
1080
1122
|
// src/plugins/index.ts
|
|
1081
1123
|
var defaultPlugins = [
|
|
1082
1124
|
functionPlugin,
|
|
@@ -1086,21 +1128,22 @@ var defaultPlugins = [
|
|
|
1086
1128
|
storePlugin,
|
|
1087
1129
|
topicPlugin,
|
|
1088
1130
|
searchPlugin,
|
|
1089
|
-
graphqlPlugin
|
|
1131
|
+
graphqlPlugin,
|
|
1132
|
+
pubsubPlugin
|
|
1090
1133
|
];
|
|
1091
1134
|
|
|
1092
1135
|
// src/stack/app-bootstrap.ts
|
|
1093
|
-
var appBootstrapStack = ({ config
|
|
1136
|
+
var appBootstrapStack = ({ config, app, assets }) => {
|
|
1094
1137
|
const stack = new import_aws_cdk_lib6.Stack(app, "bootstrap", {
|
|
1095
|
-
stackName: `${
|
|
1138
|
+
stackName: `${config.name}-bootstrap`
|
|
1096
1139
|
});
|
|
1097
1140
|
const plugins = [
|
|
1098
1141
|
...defaultPlugins,
|
|
1099
|
-
...
|
|
1142
|
+
...config.plugins || []
|
|
1100
1143
|
];
|
|
1101
1144
|
debug("Run plugin onBootstrap listeners");
|
|
1102
1145
|
const functions = plugins.map((plugin) => plugin.onBootstrap?.({
|
|
1103
|
-
config
|
|
1146
|
+
config,
|
|
1104
1147
|
app,
|
|
1105
1148
|
stack,
|
|
1106
1149
|
assets
|
|
@@ -1124,9 +1167,9 @@ var flattenDependencyTree = (stacks) => {
|
|
|
1124
1167
|
return list3;
|
|
1125
1168
|
};
|
|
1126
1169
|
var createDependencyTree = (stacks, startingLevel) => {
|
|
1127
|
-
const list3 = stacks.map(({ stack, config
|
|
1170
|
+
const list3 = stacks.map(({ stack, config }) => ({
|
|
1128
1171
|
stack,
|
|
1129
|
-
depends:
|
|
1172
|
+
depends: config?.depends?.map((dep) => dep.name) || []
|
|
1130
1173
|
}));
|
|
1131
1174
|
const findChildren = (list4, parents, level) => {
|
|
1132
1175
|
const children = [];
|
|
@@ -1198,11 +1241,11 @@ var Assets = class {
|
|
|
1198
1241
|
};
|
|
1199
1242
|
|
|
1200
1243
|
// src/app.ts
|
|
1201
|
-
var makeApp = (
|
|
1244
|
+
var makeApp = (config) => {
|
|
1202
1245
|
return new import_aws_cdk_lib7.App({
|
|
1203
1246
|
outdir: assemblyDir,
|
|
1204
1247
|
defaultStackSynthesizer: new import_aws_cdk_lib7.DefaultStackSynthesizer({
|
|
1205
|
-
fileAssetsBucketName: assetBucketName(
|
|
1248
|
+
fileAssetsBucketName: assetBucketName(config),
|
|
1206
1249
|
fileAssetPublishingRoleArn: "",
|
|
1207
1250
|
generateBootstrapVersionRule: false
|
|
1208
1251
|
})
|
|
@@ -1219,26 +1262,26 @@ var getAllDepends = (filters) => {
|
|
|
1219
1262
|
walk(filters);
|
|
1220
1263
|
return list3;
|
|
1221
1264
|
};
|
|
1222
|
-
var toApp = async (
|
|
1265
|
+
var toApp = async (config, filters) => {
|
|
1223
1266
|
const assets = new Assets();
|
|
1224
|
-
const app = makeApp(
|
|
1267
|
+
const app = makeApp(config);
|
|
1225
1268
|
const stacks = [];
|
|
1226
1269
|
const plugins = [
|
|
1227
1270
|
...defaultPlugins,
|
|
1228
|
-
...
|
|
1271
|
+
...config.plugins || []
|
|
1229
1272
|
];
|
|
1230
1273
|
debug("Plugins detected:", plugins.map((plugin) => style.info(plugin.name)).join(", "));
|
|
1231
1274
|
debug("Run plugin onApp listeners");
|
|
1232
|
-
plugins.forEach((plugin) => plugin.onApp?.({ config
|
|
1233
|
-
const bootstrap2 = appBootstrapStack({ config
|
|
1275
|
+
plugins.forEach((plugin) => plugin.onApp?.({ config, app, assets }));
|
|
1276
|
+
const bootstrap2 = appBootstrapStack({ config, app, assets });
|
|
1234
1277
|
debug("Stack filters:", filters.map((filter) => style.info(filter)).join(", "));
|
|
1235
|
-
const filterdStacks = filters.length === 0 ?
|
|
1278
|
+
const filterdStacks = filters.length === 0 ? config.stacks : getAllDepends(
|
|
1236
1279
|
// config.stacks,
|
|
1237
|
-
|
|
1280
|
+
config.stacks.filter((stack) => filters.includes(stack.name))
|
|
1238
1281
|
);
|
|
1239
1282
|
for (const stackConfig of filterdStacks) {
|
|
1240
1283
|
const { stack, bindings } = toStack({
|
|
1241
|
-
config
|
|
1284
|
+
config,
|
|
1242
1285
|
stackConfig,
|
|
1243
1286
|
assets,
|
|
1244
1287
|
plugins,
|
|
@@ -1343,17 +1386,17 @@ var getCredentials = (profile) => {
|
|
|
1343
1386
|
};
|
|
1344
1387
|
|
|
1345
1388
|
// src/schema/app.ts
|
|
1346
|
-
var
|
|
1389
|
+
var import_zod26 = require("zod");
|
|
1347
1390
|
|
|
1348
1391
|
// src/schema/stack.ts
|
|
1349
|
-
var
|
|
1350
|
-
var StackSchema =
|
|
1392
|
+
var import_zod23 = require("zod");
|
|
1393
|
+
var StackSchema = import_zod23.z.object({
|
|
1351
1394
|
name: ResourceIdSchema,
|
|
1352
|
-
depends:
|
|
1395
|
+
depends: import_zod23.z.array(import_zod23.z.lazy(() => StackSchema)).optional()
|
|
1353
1396
|
});
|
|
1354
1397
|
|
|
1355
1398
|
// src/schema/region.ts
|
|
1356
|
-
var
|
|
1399
|
+
var import_zod24 = require("zod");
|
|
1357
1400
|
var US = ["us-east-2", "us-east-1", "us-west-1", "us-west-2"];
|
|
1358
1401
|
var AF = ["af-south-1"];
|
|
1359
1402
|
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"];
|
|
@@ -1370,29 +1413,29 @@ var regions = [
|
|
|
1370
1413
|
...ME,
|
|
1371
1414
|
...SA
|
|
1372
1415
|
];
|
|
1373
|
-
var RegionSchema =
|
|
1416
|
+
var RegionSchema = import_zod24.z.enum(regions);
|
|
1374
1417
|
|
|
1375
1418
|
// src/schema/plugin.ts
|
|
1376
|
-
var
|
|
1377
|
-
var PluginSchema =
|
|
1378
|
-
name:
|
|
1379
|
-
schema:
|
|
1419
|
+
var import_zod25 = require("zod");
|
|
1420
|
+
var PluginSchema = import_zod25.z.object({
|
|
1421
|
+
name: import_zod25.z.string(),
|
|
1422
|
+
schema: import_zod25.z.custom().optional(),
|
|
1380
1423
|
// depends: z.array(z.lazy(() => PluginSchema)).optional(),
|
|
1381
|
-
onBootstrap:
|
|
1382
|
-
onStack:
|
|
1383
|
-
onApp:
|
|
1424
|
+
onBootstrap: import_zod25.z.function().returns(import_zod25.z.any()).optional(),
|
|
1425
|
+
onStack: import_zod25.z.function().returns(import_zod25.z.any()).optional(),
|
|
1426
|
+
onApp: import_zod25.z.function().returns(import_zod25.z.void()).optional()
|
|
1384
1427
|
// bind: z.function().optional(),
|
|
1385
1428
|
});
|
|
1386
1429
|
|
|
1387
1430
|
// src/schema/app.ts
|
|
1388
|
-
var AppSchema =
|
|
1431
|
+
var AppSchema = import_zod26.z.object({
|
|
1389
1432
|
name: ResourceIdSchema,
|
|
1390
1433
|
region: RegionSchema,
|
|
1391
|
-
profile:
|
|
1392
|
-
stage:
|
|
1393
|
-
defaults:
|
|
1394
|
-
stacks:
|
|
1395
|
-
plugins:
|
|
1434
|
+
profile: import_zod26.z.string(),
|
|
1435
|
+
stage: import_zod26.z.string().regex(/[a-z]+/).default("prod"),
|
|
1436
|
+
defaults: import_zod26.z.object({}).default({}),
|
|
1437
|
+
stacks: import_zod26.z.array(StackSchema).min(1),
|
|
1438
|
+
plugins: import_zod26.z.array(PluginSchema).optional()
|
|
1396
1439
|
});
|
|
1397
1440
|
|
|
1398
1441
|
// src/util/import.ts
|
|
@@ -1472,14 +1515,14 @@ var importConfig = async (options) => {
|
|
|
1472
1515
|
schema2 = schema2.and(plugin.schema);
|
|
1473
1516
|
}
|
|
1474
1517
|
}
|
|
1475
|
-
const
|
|
1476
|
-
debug("Load credentials", style.info(
|
|
1477
|
-
const credentials = getCredentials(
|
|
1518
|
+
const config = await schema2.parseAsync(appConfig);
|
|
1519
|
+
debug("Load credentials", style.info(config.profile));
|
|
1520
|
+
const credentials = getCredentials(config.profile);
|
|
1478
1521
|
debug("Load AWS account ID");
|
|
1479
|
-
const account = await getAccountId(credentials,
|
|
1522
|
+
const account = await getAccountId(credentials, config.region);
|
|
1480
1523
|
debug("Account ID:", style.info(account));
|
|
1481
1524
|
return {
|
|
1482
|
-
...
|
|
1525
|
+
...config,
|
|
1483
1526
|
account,
|
|
1484
1527
|
credentials
|
|
1485
1528
|
};
|
|
@@ -1501,14 +1544,14 @@ var list = (data) => {
|
|
|
1501
1544
|
};
|
|
1502
1545
|
|
|
1503
1546
|
// src/cli/ui/layout/header.ts
|
|
1504
|
-
var header = (
|
|
1547
|
+
var header = (config) => {
|
|
1505
1548
|
return [
|
|
1506
1549
|
br(),
|
|
1507
1550
|
list({
|
|
1508
|
-
App:
|
|
1509
|
-
Stage:
|
|
1510
|
-
Region:
|
|
1511
|
-
Profile:
|
|
1551
|
+
App: config.name,
|
|
1552
|
+
Stage: config.stage,
|
|
1553
|
+
Region: config.region,
|
|
1554
|
+
Profile: config.profile
|
|
1512
1555
|
}),
|
|
1513
1556
|
br()
|
|
1514
1557
|
];
|
|
@@ -1826,9 +1869,9 @@ var layout = async (cb) => {
|
|
|
1826
1869
|
term.out.write(logo());
|
|
1827
1870
|
try {
|
|
1828
1871
|
const options = program.optsWithGlobals();
|
|
1829
|
-
const
|
|
1830
|
-
term.out.write(header(
|
|
1831
|
-
await cb(
|
|
1872
|
+
const config = await importConfig(options);
|
|
1873
|
+
term.out.write(header(config));
|
|
1874
|
+
await cb(config, term.out.write.bind(term.out), term);
|
|
1832
1875
|
} catch (error) {
|
|
1833
1876
|
if (error instanceof Error) {
|
|
1834
1877
|
term.out.write(dialog("error", [error.message]));
|
|
@@ -1943,8 +1986,8 @@ var cleanUp = async () => {
|
|
|
1943
1986
|
// src/cli/command/build.ts
|
|
1944
1987
|
var build = (program2) => {
|
|
1945
1988
|
program2.command("build").argument("[stack...]", "Optionally filter stacks to build").description("Build your app").action(async (filters) => {
|
|
1946
|
-
await layout(async (
|
|
1947
|
-
const { app, assets } = await toApp(
|
|
1989
|
+
await layout(async (config, write) => {
|
|
1990
|
+
const { app, assets } = await toApp(config, filters);
|
|
1948
1991
|
await cleanUp();
|
|
1949
1992
|
await write(assetBuilder(assets));
|
|
1950
1993
|
app.synth();
|
|
@@ -1957,11 +2000,11 @@ var import_client_cloudformation = require("@aws-sdk/client-cloudformation");
|
|
|
1957
2000
|
var import_client_s32 = require("@aws-sdk/client-s3");
|
|
1958
2001
|
var StackClient = class {
|
|
1959
2002
|
// 30 seconds
|
|
1960
|
-
constructor(
|
|
1961
|
-
this.config =
|
|
2003
|
+
constructor(config) {
|
|
2004
|
+
this.config = config;
|
|
1962
2005
|
this.client = new import_client_cloudformation.CloudFormationClient({
|
|
1963
|
-
credentials:
|
|
1964
|
-
region:
|
|
2006
|
+
credentials: config.credentials,
|
|
2007
|
+
region: config.region
|
|
1965
2008
|
});
|
|
1966
2009
|
}
|
|
1967
2010
|
client;
|
|
@@ -2190,12 +2233,12 @@ var confirmPrompt = (label, options = {}) => {
|
|
|
2190
2233
|
};
|
|
2191
2234
|
|
|
2192
2235
|
// src/cli/ui/complex/bootstrap.ts
|
|
2193
|
-
var bootstrapDeployer = (
|
|
2236
|
+
var bootstrapDeployer = (config) => {
|
|
2194
2237
|
return async (term) => {
|
|
2195
2238
|
debug("Initializing bootstrap");
|
|
2196
|
-
const app = makeApp(
|
|
2197
|
-
const client = new StackClient(
|
|
2198
|
-
const bootstrap2 = bootstrapStack(
|
|
2239
|
+
const app = makeApp(config);
|
|
2240
|
+
const client = new StackClient(config);
|
|
2241
|
+
const bootstrap2 = bootstrapStack(config, app);
|
|
2199
2242
|
const shouldDeploy = await shouldDeployBootstrap(client, bootstrap2.stackName);
|
|
2200
2243
|
if (shouldDeploy) {
|
|
2201
2244
|
term.out.write(dialog("warning", [`Your app hasn't been bootstrapped yet`]));
|
|
@@ -2219,8 +2262,8 @@ var bootstrapDeployer = (config2) => {
|
|
|
2219
2262
|
// src/cli/command/bootstrap.ts
|
|
2220
2263
|
var bootstrap = (program2) => {
|
|
2221
2264
|
program2.command("bootstrap").description("Create the awsless bootstrap stack").action(async () => {
|
|
2222
|
-
await layout(async (
|
|
2223
|
-
await write(bootstrapDeployer(
|
|
2265
|
+
await layout(async (config, write) => {
|
|
2266
|
+
await write(bootstrapDeployer(config));
|
|
2224
2267
|
});
|
|
2225
2268
|
});
|
|
2226
2269
|
};
|
|
@@ -2264,14 +2307,14 @@ var stackTree = (nodes, statuses) => {
|
|
|
2264
2307
|
// src/cli/command/status.ts
|
|
2265
2308
|
var status = (program2) => {
|
|
2266
2309
|
program2.command("status").argument("[stacks...]", "Optionally filter stacks to lookup status").description("View the application status").action(async (filters) => {
|
|
2267
|
-
await layout(async (
|
|
2268
|
-
const { app, assets, dependencyTree } = await toApp(
|
|
2310
|
+
await layout(async (config, write) => {
|
|
2311
|
+
const { app, assets, dependencyTree } = await toApp(config, filters);
|
|
2269
2312
|
await cleanUp();
|
|
2270
2313
|
await write(assetBuilder(assets));
|
|
2271
2314
|
write(br());
|
|
2272
2315
|
const assembly = app.synth();
|
|
2273
2316
|
const doneLoading = write(loadingDialog("Loading stack information..."));
|
|
2274
|
-
const client = new StackClient(
|
|
2317
|
+
const client = new StackClient(config);
|
|
2275
2318
|
const statuses = [];
|
|
2276
2319
|
const stackStatuses = {};
|
|
2277
2320
|
assembly.stacks.forEach((stack) => {
|
|
@@ -2311,9 +2354,9 @@ var status = (program2) => {
|
|
|
2311
2354
|
// src/cli/command/deploy.ts
|
|
2312
2355
|
var deploy = (program2) => {
|
|
2313
2356
|
program2.command("deploy").argument("[stacks...]", "Optionally filter stacks to deploy").description("Deploy your app to AWS").action(async (filters) => {
|
|
2314
|
-
await layout(async (
|
|
2315
|
-
await write(bootstrapDeployer(
|
|
2316
|
-
const { app, stackNames, assets, dependencyTree } = await toApp(
|
|
2357
|
+
await layout(async (config, write) => {
|
|
2358
|
+
await write(bootstrapDeployer(config));
|
|
2359
|
+
const { app, stackNames, assets, dependencyTree } = await toApp(config, filters);
|
|
2317
2360
|
const formattedFilter = stackNames.map((i) => style.info(i)).join(style.placeholder(", "));
|
|
2318
2361
|
debug("Stacks to deploy", formattedFilter);
|
|
2319
2362
|
const deployAll = filters.length === 0;
|
|
@@ -2342,7 +2385,7 @@ var deploy = (program2) => {
|
|
|
2342
2385
|
write(br());
|
|
2343
2386
|
write(stackTree(dependencyTree, statuses));
|
|
2344
2387
|
write(br());
|
|
2345
|
-
const client = new StackClient(
|
|
2388
|
+
const client = new StackClient(config);
|
|
2346
2389
|
const deploymentLine = createDeploymentLine(dependencyTree);
|
|
2347
2390
|
for (const stacks of deploymentLine) {
|
|
2348
2391
|
const results = await Promise.allSettled(stacks.map(async (stack) => {
|
|
@@ -2431,35 +2474,35 @@ var textPrompt = (label, options = {}) => {
|
|
|
2431
2474
|
};
|
|
2432
2475
|
};
|
|
2433
2476
|
|
|
2434
|
-
// src/cli/command/
|
|
2477
|
+
// src/cli/command/secrets/set.ts
|
|
2435
2478
|
var set = (program2) => {
|
|
2436
|
-
program2.command("set <name>").description("Set a
|
|
2437
|
-
await layout(async (
|
|
2438
|
-
const params = new Params(
|
|
2479
|
+
program2.command("set <name>").description("Set a secret value").action(async (name) => {
|
|
2480
|
+
await layout(async (config, write) => {
|
|
2481
|
+
const params = new Params(config);
|
|
2439
2482
|
write(list({
|
|
2440
|
-
"Set
|
|
2483
|
+
"Set secret parameter": style.info(name)
|
|
2441
2484
|
}));
|
|
2442
2485
|
write(br());
|
|
2443
|
-
const value = await write(textPrompt("Enter
|
|
2486
|
+
const value = await write(textPrompt("Enter secret value"));
|
|
2444
2487
|
if (value === "") {
|
|
2445
|
-
write(dialog("error", [`Provided
|
|
2488
|
+
write(dialog("error", [`Provided secret value can't be empty`]));
|
|
2446
2489
|
} else {
|
|
2447
|
-
const done = write(loadingDialog(`Saving remote
|
|
2490
|
+
const done = write(loadingDialog(`Saving remote secret parameter`));
|
|
2448
2491
|
await params.set(name, value);
|
|
2449
|
-
done(`Done saving remote
|
|
2492
|
+
done(`Done saving remote secret parameter`);
|
|
2450
2493
|
}
|
|
2451
2494
|
});
|
|
2452
2495
|
});
|
|
2453
2496
|
};
|
|
2454
2497
|
|
|
2455
|
-
// src/cli/command/
|
|
2498
|
+
// src/cli/command/secrets/get.ts
|
|
2456
2499
|
var get = (program2) => {
|
|
2457
|
-
program2.command("get <name>").description("Get a
|
|
2458
|
-
await layout(async (
|
|
2459
|
-
const params = new Params(
|
|
2460
|
-
const done = write(loadingDialog(`Getting remote
|
|
2500
|
+
program2.command("get <name>").description("Get a secret value").action(async (name) => {
|
|
2501
|
+
await layout(async (config, write) => {
|
|
2502
|
+
const params = new Params(config);
|
|
2503
|
+
const done = write(loadingDialog(`Getting remote secret parameter`));
|
|
2461
2504
|
const value = await params.get(name);
|
|
2462
|
-
done(`Done getting remote
|
|
2505
|
+
done(`Done getting remote secret parameter`);
|
|
2463
2506
|
write(br());
|
|
2464
2507
|
write(list({
|
|
2465
2508
|
Name: name,
|
|
@@ -2469,20 +2512,20 @@ var get = (program2) => {
|
|
|
2469
2512
|
});
|
|
2470
2513
|
};
|
|
2471
2514
|
|
|
2472
|
-
// src/cli/command/
|
|
2515
|
+
// src/cli/command/secrets/delete.ts
|
|
2473
2516
|
var del = (program2) => {
|
|
2474
|
-
program2.command("delete <name>").description("Delete a
|
|
2475
|
-
await layout(async (
|
|
2476
|
-
const params = new Params(
|
|
2477
|
-
write(dialog("warning", [`Your deleting the ${style.info(name)}
|
|
2517
|
+
program2.command("delete <name>").description("Delete a secret value").action(async (name) => {
|
|
2518
|
+
await layout(async (config, write) => {
|
|
2519
|
+
const params = new Params(config);
|
|
2520
|
+
write(dialog("warning", [`Your deleting the ${style.info(name)} secret parameter`]));
|
|
2478
2521
|
const confirm = await write(confirmPrompt("Are you sure?"));
|
|
2479
2522
|
if (!confirm) {
|
|
2480
2523
|
throw new Cancelled();
|
|
2481
2524
|
}
|
|
2482
|
-
const done = write(loadingDialog(`Deleting remote
|
|
2525
|
+
const done = write(loadingDialog(`Deleting remote secret parameter`));
|
|
2483
2526
|
const value = await params.get(name);
|
|
2484
2527
|
await params.delete(name);
|
|
2485
|
-
done(`Done deleting remote
|
|
2528
|
+
done(`Done deleting remote secret parameter`);
|
|
2486
2529
|
write(br());
|
|
2487
2530
|
write(list({
|
|
2488
2531
|
Name: name,
|
|
@@ -2492,33 +2535,33 @@ var del = (program2) => {
|
|
|
2492
2535
|
});
|
|
2493
2536
|
};
|
|
2494
2537
|
|
|
2495
|
-
// src/cli/command/
|
|
2538
|
+
// src/cli/command/secrets/list.ts
|
|
2496
2539
|
var list2 = (program2) => {
|
|
2497
|
-
program2.command("list").description(`List all
|
|
2498
|
-
await layout(async (
|
|
2499
|
-
const params = new Params(
|
|
2500
|
-
const done = write(loadingDialog("Loading
|
|
2540
|
+
program2.command("list").description(`List all secret value's`).action(async () => {
|
|
2541
|
+
await layout(async (config, write) => {
|
|
2542
|
+
const params = new Params(config);
|
|
2543
|
+
const done = write(loadingDialog("Loading secret parameters..."));
|
|
2501
2544
|
const values = await params.list();
|
|
2502
|
-
done("Done loading
|
|
2545
|
+
done("Done loading secret values");
|
|
2503
2546
|
if (Object.keys(values).length > 0) {
|
|
2504
2547
|
write(br());
|
|
2505
2548
|
write(list(values));
|
|
2506
2549
|
} else {
|
|
2507
|
-
write(dialog("warning", ["No
|
|
2550
|
+
write(dialog("warning", ["No secret parameters found"]));
|
|
2508
2551
|
}
|
|
2509
2552
|
});
|
|
2510
2553
|
});
|
|
2511
2554
|
};
|
|
2512
2555
|
|
|
2513
|
-
// src/cli/command/
|
|
2556
|
+
// src/cli/command/secrets/index.ts
|
|
2514
2557
|
var commands = [
|
|
2515
2558
|
set,
|
|
2516
2559
|
get,
|
|
2517
2560
|
del,
|
|
2518
2561
|
list2
|
|
2519
2562
|
];
|
|
2520
|
-
var
|
|
2521
|
-
const command = program2.command("
|
|
2563
|
+
var secrets = (program2) => {
|
|
2564
|
+
const command = program2.command("secrets").description(`Manage app secrets`);
|
|
2522
2565
|
commands.forEach((cb) => cb(command));
|
|
2523
2566
|
};
|
|
2524
2567
|
|
|
@@ -2539,7 +2582,7 @@ var commands2 = [
|
|
|
2539
2582
|
status,
|
|
2540
2583
|
build,
|
|
2541
2584
|
deploy,
|
|
2542
|
-
|
|
2585
|
+
secrets
|
|
2543
2586
|
// diff,
|
|
2544
2587
|
// remove,
|
|
2545
2588
|
// test,
|