@kumologica/sdk 3.0.0-alpha4

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 (76) hide show
  1. package/README.md +52 -0
  2. package/bin/kl.js +2 -0
  3. package/cli/KumologicaError.js +17 -0
  4. package/cli/cli.js +7 -0
  5. package/cli/commands/build-commands/aws.js +49 -0
  6. package/cli/commands/build-commands/azure.js +43 -0
  7. package/cli/commands/build-commands/kumohub.js +49 -0
  8. package/cli/commands/build.js +6 -0
  9. package/cli/commands/create-commands/create-project-iteratively.js +49 -0
  10. package/cli/commands/create-commands/index.js +5 -0
  11. package/cli/commands/create.js +66 -0
  12. package/cli/commands/deploy-commands/kumohub.js +114 -0
  13. package/cli/commands/deploy.js +6 -0
  14. package/cli/commands/doc-commands/html.js +60 -0
  15. package/cli/commands/doc.js +6 -0
  16. package/cli/commands/export-commands/cloudformation.js +371 -0
  17. package/cli/commands/export-commands/serverless.js +164 -0
  18. package/cli/commands/export-commands/terraform-commands/aws.js +193 -0
  19. package/cli/commands/export-commands/terraform-commands/azure.js +148 -0
  20. package/cli/commands/export-commands/terraform.js +6 -0
  21. package/cli/commands/export-commands/utils/validator.js +195 -0
  22. package/cli/commands/export.js +6 -0
  23. package/cli/commands/list-templates.js +24 -0
  24. package/cli/commands/open.js +53 -0
  25. package/cli/commands/start.js +165 -0
  26. package/cli/commands/test/TestSuiteRunner.js +76 -0
  27. package/cli/commands/test.js +123 -0
  28. package/cli/utils/download-template-from-repo.js +346 -0
  29. package/cli/utils/download-test.js +12 -0
  30. package/cli/utils/download.js +119 -0
  31. package/cli/utils/fs/copy-dir-contents-sync.js +15 -0
  32. package/cli/utils/fs/create-zip-file.js +39 -0
  33. package/cli/utils/fs/dir-exists-sync.js +14 -0
  34. package/cli/utils/fs/dir-exists.js +17 -0
  35. package/cli/utils/fs/file-exists-sync.js +14 -0
  36. package/cli/utils/fs/file-exists.js +12 -0
  37. package/cli/utils/fs/get-tmp-dir-path.js +22 -0
  38. package/cli/utils/fs/parse.js +40 -0
  39. package/cli/utils/fs/read-file-sync.js +11 -0
  40. package/cli/utils/fs/read-file.js +10 -0
  41. package/cli/utils/fs/safe-move-file.js +58 -0
  42. package/cli/utils/fs/walk-dir-sync.js +34 -0
  43. package/cli/utils/fs/write-file-sync.js +31 -0
  44. package/cli/utils/fs/write-file.js +32 -0
  45. package/cli/utils/logger.js +26 -0
  46. package/cli/utils/rename-service.js +49 -0
  47. package/package.json +72 -0
  48. package/src/api/core/comms.js +141 -0
  49. package/src/api/core/context.js +296 -0
  50. package/src/api/core/flows.js +286 -0
  51. package/src/api/core/index.js +29 -0
  52. package/src/api/core/library.js +106 -0
  53. package/src/api/core/nodes.js +476 -0
  54. package/src/api/core/projects.js +426 -0
  55. package/src/api/core/rest/context.js +42 -0
  56. package/src/api/core/rest/flow.js +53 -0
  57. package/src/api/core/rest/flows.js +53 -0
  58. package/src/api/core/rest/index.js +171 -0
  59. package/src/api/core/rest/nodes.js +164 -0
  60. package/src/api/core/rest/util.js +53 -0
  61. package/src/api/core/settings.js +287 -0
  62. package/src/api/tools/base/DesignerTool.js +108 -0
  63. package/src/api/tools/core/flow.js +58 -0
  64. package/src/api/tools/core/index.js +18 -0
  65. package/src/api/tools/core/node.js +77 -0
  66. package/src/api/tools/debugger/index.js +193 -0
  67. package/src/api/tools/filemanager/index.js +127 -0
  68. package/src/api/tools/git/index.js +103 -0
  69. package/src/api/tools/index.js +13 -0
  70. package/src/api/tools/test/index.js +56 -0
  71. package/src/api/tools/test/lib/TestCaseRunner.js +105 -0
  72. package/src/api/tools/test/lib/fixtures/example3-flow.json +148 -0
  73. package/src/api/tools/test/lib/fixtures/package.json +6 -0
  74. package/src/api/tools/test/lib/fixtures/s3-event.js +43 -0
  75. package/src/api/tools/test/lib/reporters/index.js +120 -0
  76. package/src/server/DesignerServer.js +141 -0
@@ -0,0 +1,371 @@
1
+ const { boolean } = require('yargs');
2
+
3
+ exports.command = 'cloudformation';
4
+ exports.desc = `Build aws cloud formation script. \n Parameters are equivalent of command: "aws lambda create-function"`;
5
+
6
+ exports.builder = {
7
+
8
+ "project-directory": {
9
+ describe: "\nThe location of kumologica project.\n Current working directory if not provided.",
10
+ type: 'string',
11
+ alias: 'd',
12
+ nargs: 1
13
+ },
14
+ "flow-file-name": {
15
+ describe: "\nThe name of kumologica flow file.\n Auto search if not provided.",
16
+ type: 'string',
17
+ alias: 'f',
18
+ nargs: 1
19
+ },
20
+ "lambda-name": {
21
+ describe: "\nThe name of lambda function,\n default to flow name",
22
+ type: 'string',
23
+ alias: 'l',
24
+ nargs: 1
25
+ },
26
+ "zip-file-name": {
27
+ describe: "\nThe name of zip file of built lambda. The zip file may not exists until 'aws cloudformation package' command is called." ,
28
+ demandOption: "The name of zip file is required.",
29
+ type: 'string',
30
+ alias: 'z',
31
+ nargs: 1
32
+ },
33
+ "role-name": {
34
+ describe: "\nThe name of lambda role, default to {lambda-name}-role",
35
+ type: 'string',
36
+ alias: 'o',
37
+ nargs: 1
38
+ },
39
+ "bucket-name": {
40
+ describe: "\nThe name of bucket where zipped lambda is loaded from",
41
+ demandOption: "The name of s3 bucket is required.",
42
+ type: 'string',
43
+ alias: 'b',
44
+ nargs: 1
45
+ },
46
+ timeout: {
47
+ describe: "\nThe time in seconds lambda is allowed to run, max: 900",
48
+ type: 'number',
49
+ default: 10,
50
+ alias: 't',
51
+ nargs: 1
52
+ },
53
+ "memory-size": {
54
+ describe: "\nThe amount of memory allocated to function, default 128 (MB), must be multiple of 64 (MB), max 4096 (MB)",
55
+ type: 'number',
56
+ default: 128,
57
+ alias: 'm',
58
+ nargs: 1
59
+ },
60
+ description: {
61
+ describe: "\nThe description of a function",
62
+ type: 'string',
63
+ nargs: 1
64
+ },
65
+ environment: {
66
+ describe: `\nEnvironment variables, JSON Syntax: '{"Variables": {"string": "string" ...}'}`,
67
+ type: 'string',
68
+ alias: 'e',
69
+ nargs: 1
70
+ },
71
+ tags: {
72
+ describe: `\nTags, JSON Syntax: '{"name": "value" ...}'`,
73
+ type: 'string',
74
+ alias: 'g',
75
+ nargs: 1
76
+ },
77
+ "tracing-config": {
78
+ describe: `\nX-Ray config, JSON Syntax: '{"Mode": "Active"|"PassThrough"}' `,
79
+ type: 'string',
80
+ alias: 'x',
81
+ nargs: 1
82
+ },
83
+ "kms-key-arn": {
84
+ describe: "\nThe ARN of KMS key to encrypt env variables",
85
+ type: 'string',
86
+ alias: 'k',
87
+ nargs: 1
88
+ },
89
+ "vpc-config": {
90
+ describe: `\nThe list of security groups and subnets of VPC, JSON syntax: '{ "SubnetIds": ["string", ...],"SecurityGroupIds": ["string", ...]}'`,
91
+ type: 'string',
92
+ alias: 'v',
93
+ nargs: 1
94
+ },
95
+ architectures: {
96
+ describe: "\nThe instruction set architecture that the function supports, a string array with one of x86_64, arm64. Default value: [x86_64].",
97
+ type: 'string',
98
+ nargs: 1
99
+ },
100
+ runtime: {
101
+ describe: "\nThe runtime, only nodejs runtimes allowed: nodejs12.x | nodejs14.x | nodejs16.x | ...",
102
+ type: 'string',
103
+ default: 'nodejs14.x',
104
+ alias: 'r',
105
+ nargs: 1
106
+ },
107
+ "dead-letter-config": {
108
+ describe: `\nThe arn of the dead letter queue or topic JSON Syntax: '{"TargetArn": "string"}'`,
109
+ type: 'string',
110
+ alias: 'q',
111
+ nargs: 1
112
+ },
113
+ "file-system-configs": {
114
+ describe: `\nAWS EFS config details, JSON Syntax: '[{"Arn": "string","LocalMountPath": "string"} ...]'`,
115
+ type: 'string',
116
+ nargs: 1
117
+ },
118
+ "log-retention-days": {
119
+ describe: '\nNumber of days logs to be retained',
120
+ type: 'number',
121
+ nargs: 1
122
+ },
123
+ "role-arn": {
124
+ describe: `\nThe arn of IAM role to assign to lambda, otherwise this command will generate role. \n Important!\n This parameter should only be used if this command is not able to generate sufficient role based on flow details.`,
125
+ type: 'string',
126
+ nargs: 1
127
+ },
128
+ "layers": {
129
+ describe: `\nList of arn of lambda layers to be added.`,
130
+ type: 'string',
131
+ nargs: 1
132
+ },
133
+ "policy": {
134
+ describe: `\nAdditional iam policy to add to the role. It must be in valid aws policy format, for example: '{"Effect": "Allow", "Resource": ["*"],"Action": ["sns:Publish"]}'. if policy is invalid, cloudformation stack will fail. The value can be single policy statement or array of statements if required. This parameter is ignored if role-arn is provided.`,
135
+ type: 'string',
136
+ nargs: 1
137
+ },
138
+ "strict-mode": {
139
+ describe: '\nFails script creation if insufficient resource definition is provided (string values or environment reference). If false, then resource will be substituted with "*" if missing.',
140
+ type: 'boolean',
141
+ nargs: 1,
142
+ default: true
143
+ },
144
+ triggers: {
145
+ describe: `\nArray of lambda triggers, JSON Syntax: '[{"api": {"apiId": "..",..}]'}
146
+
147
+ Supported triggers:
148
+
149
+ Partner Event:\n-----------------
150
+ * partnerEventBusName - The name of partner event bus name
151
+ * name - the name of event, optional, default value: Event+timestamp if not provided
152
+ * detailType - the detail-type content of the event. Optional
153
+
154
+ Examples:
155
+ 1. Creates partner event trigger for salesforce AccountChangeEvent event:\n
156
+ {"partnerEvent": {"detail-type": "AccountChangeEvent", "partnerEventBusName": "aws.partner/salesforce.com/444444444/555555"}}
157
+
158
+ Cloudwatch Event:\n-----------------
159
+ * schedule - cron expression (minutes hours days-of-month month days-of-week year) or fixed rate expression, required.\n See more: https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html
160
+ * name - the name of event, optional, default value: Event+timestamp if not provided
161
+ * reference - the reference property set for event listener node that should handle event. Optional
162
+
163
+ Examples:
164
+ 1. Creates event trigger using cron expression that runs at 10am UTC every day:\n
165
+ {"event": {"expression": "cron(0 10 * * ? *)"}}
166
+
167
+ 2. Creates event trigger using rate expression that runs every minute:\n
168
+ {"event": {"expression": "rate(1 minute)"}}\n
169
+
170
+ 3. Creates event trigger using rate expression that runs every minute for event listener with reference "cleanup":\n
171
+ {"event": {"expression": "rate(1 minute)", "reference": "cleanup"}}\n
172
+
173
+ SNS:\n----
174
+ * topicArn - the ARN of sns topic, required
175
+
176
+ Example:
177
+ {"sns": {"topicArn": "arn:aws:sns: ..."}}
178
+
179
+ SQS:\n----
180
+ * queueArn - the ARN of sqs queue, required
181
+ * batchSize - the size of batch, optional
182
+
183
+ Example:
184
+ {"sqs": {"queueArn": "arn:aws:sqs: ..."}}
185
+
186
+ DynamoDB Stream:\n----
187
+ * streamArn - the ARN of dynamodb stream, required
188
+ * batchSize - the size of batch, optional
189
+ * batchWindow - maximum batching window in seconds, optional
190
+ * startingPosition - either LATEST or TRIM_HORIZON, optional
191
+ Example:
192
+ {"dynamodb": {"streamArn": "arn:aws: ...", "startingPosition": "LATEST"}}
193
+
194
+ Kinesis Stream:\n---------------
195
+ * streamArn - the ARN of kinesis stream, required
196
+ * batchSize - the size of batch, optional
197
+ * batchWindow - maximum batching window in seconds, optional
198
+ * startingPosition - either LATEST or TRIM_HORIZON, optional
199
+ Example:
200
+ {"kinesis": {"streamArn": "arn:aws: ...", "startingPosition": "LATEST"}}
201
+
202
+ S3:\n---
203
+ * bucket - the name of the bucket, required
204
+ * sourceAccount - the account id
205
+ * eventType - the size of batch, optional
206
+ * prefix - maximum batching window in seconds, optional
207
+ * suffix - either LATEST or TRIM_HORIZON, optional
208
+ Example:
209
+ {"s3": {"bucket": "testBucket", "eventType": "ObjectCreated.*"}}
210
+
211
+ Rest api gateway:\n-----------------
212
+ * apiId: the id of rest api, required
213
+ * stage: the stage name of api gateway, required
214
+ * parentId: the id of parent resource where lambda {proxy+} should be added, required
215
+ * resource: the name of resource linked to lambda, required if parentId is not root or lambda linked to non root in api gw
216
+ * authorizerType: the type of authorizer: TOKEN, COGNITO_USER_POOLS, REQUEST
217
+ * authorizerId: the if of authorizer, optional
218
+ * apiKeyRequired: true if api key is required. default false
219
+ * scopes: array of scopes, optional
220
+
221
+ Examples:
222
+
223
+ 1. Creates new api gateway, default: 'test' stage and root proxy resource:
224
+
225
+ {"api": {
226
+ "apiId": "create new",
227
+ "apiName": "booking api"\n}
228
+
229
+ 2. Creates new api gateway, default: 'test' stage and proxy resource under /users resource:
230
+
231
+ {"api": {
232
+ "apiId": "create new",
233
+ "apiName": "users api",
234
+ "resource": "users"\n}\n}
235
+
236
+ 3. Uses existing api gateway, 'test' stage, creates proxy resource under /users resource, attaches request authorizer to proxy and required OAuth scopes:
237
+ {"api": {
238
+ "apiId": "fg4wsf",
239
+ "stage": "test",
240
+ "parentId": "vfgd24d",
241
+ "resource": "users",
242
+ "authorizerId": "3dgfd42",
243
+ "authorizerType": "REQUEST",
244
+ "scopes": ["users", "admins"]\n}
245
+
246
+ 4. Uses existing api gateway, 'test' stage, creates proxy resource under specified parent id:
247
+ {"api": {
248
+ \t"apiId": "fg4wsf",
249
+ \t"stage": "test",
250
+ \t"parentId": "vfgd24d"\n}
251
+
252
+ 5. Creates new api gateway, default: 'test' stage, proxy resource under /users resource with required api key:
253
+
254
+ {"api": {
255
+ "apiId": "create new",
256
+ "apiName": "users api",
257
+ "resource": "users",
258
+ "apiKeyRequired: true\n}\n}
259
+ `,
260
+ type: 'string',
261
+ nargs: 1
262
+ },
263
+
264
+ }
265
+
266
+ function display(argv) {
267
+ console.log('Parameters:');
268
+ console.log(' flow-file-name: %s', argv["flow-file-name"]||'');
269
+ console.log(' zip-file-name: %s', argv["zip-file-name"]||'');
270
+ console.log(' lambda-name: %s', argv["lambda-name"]||'');
271
+ console.log(' role-name: %s', argv["role-name"]||'');
272
+ console.log(' bucket-name: %s', argv["bucket-name"]);
273
+ console.log(' timeout: %s', argv.timeout||'');
274
+ console.log(' memory-size: %s', argv["memory-size"]||'');
275
+ console.log(' description: %s', argv.description||'');
276
+ console.log(' environment: %s', argv.environment||'');
277
+ console.log(' tags: %s', argv["tags"]||'');
278
+ console.log(' tracing-config: %s', argv["tracing-config"]||'');
279
+ console.log(' kms-key-arn: %s', argv["kms-key-arn"]||'');
280
+ console.log(' vpc-config: %s', argv["vpc-config"]||'');
281
+ console.log(' architectures: %s', argv.architectures || '');
282
+ console.log(' runtime: %s', argv.runtime||'');
283
+ console.log(' dead-letter-config: %s', argv["dead-letter-config"]||'');
284
+ console.log(' file-system-configs: %s', argv["file-system-configs"]||'');
285
+ console.log(' log-retention-days: %s', argv["log-retention-days"]||'');
286
+ console.log(' role-arn: %s', argv["role-arn"]||'');
287
+ console.log(' policy: %s', argv["policy"] || '');
288
+ console.log(' layers: %s', argv["layers"] || '');
289
+ console.log(` strict-mode: ${argv["strict-mode"]}`);
290
+ console.log(' triggers: %s', argv.triggers||'');
291
+ }
292
+
293
+ function validateJson(name, s) {
294
+ if (typeof s !== 'string') {
295
+ throw new Error (`Validation error: parameter '${name}' value is not string: '${s}'`);
296
+ }
297
+
298
+ let type;
299
+ try {
300
+ const result = JSON.parse(s);
301
+ type = Object.prototype.toString.call(result);
302
+ } catch (e) {
303
+ throw new Error (`Validation error: parameter '${name}': ${e.message}`);
304
+ }
305
+
306
+ if (!(type === '[object Object]' || type === '[object Array]')) {
307
+ throw new Error (`Validation error: parameter '${name}' value is not in JSON format: '${s}'`);
308
+ }
309
+ }
310
+
311
+ function validate(argv) {
312
+
313
+ const validator = require('./utils/validator');
314
+
315
+ if (argv.environment) {
316
+ validateJson("environment", argv.environment);
317
+ }
318
+ if (argv.tags) {
319
+ validateJson("tags", argv.tags);
320
+ }
321
+ if (argv["tracing-config"]) {
322
+ validateJson("tracing-config", argv["tracing-config"]);
323
+ }
324
+ if (argv["vpc-config"]) {
325
+ validateJson("vpc-config", argv["vpc-config"]);
326
+ }
327
+ if (argv["dead-letter-config"]) {
328
+ validateJson("dead-letter-config", argv["dead-letter-config"]);
329
+ }
330
+ if (argv["file-system-configs"]) {
331
+ validateJson("file-system-configs", argv["file-system-configs"]);
332
+ }
333
+ if (argv["layers"]) {
334
+ validateJson("layers", argv["layers"]);
335
+ }
336
+ if (argv.triggers) {
337
+ validateJson("triggers", argv.triggers);
338
+ validator.validate("triggers", JSON.parse(argv.triggers));
339
+ }
340
+ if (argv.runtime) {
341
+ if (!argv.runtime.startsWith("nodejs")) {
342
+ throw new Error (`Validation error: parameter 'runtime' must be one of supported nodejs values: nodejs|nodejs4.3|nodejs6.10|nodejs8.10|nodejs10.x|nodejs12.x|...`);
343
+ }
344
+ }
345
+ if (argv.architectures ) {
346
+ if (!argv.architectures.length || argv.architectures.length != 1 || !["x86_64","arm64"].includes(argv.architectures[0])) {
347
+ throw new Error (`Validation error: parameter 'architectures' must be an array with one element, either x86_64 or arm64`);
348
+ }
349
+ }
350
+ }
351
+
352
+ exports.handler = function (argv) {
353
+ console.log('\nGenerating AWS Cloud Formation script\n');
354
+ display(argv);
355
+ const chalk = require('chalk');
356
+
357
+ try {
358
+ validate(argv);
359
+
360
+ const { exp } = require('@kumologica/builder');
361
+
362
+ exp('cloudformation', 'aws', argv);
363
+ console.log(chalk.greenBright('AWS Cloud Formation script created successfully.'));
364
+
365
+ process.exit(0);
366
+ } catch (e) {
367
+
368
+ console.log(`${chalk.redBright(e.message)}`);
369
+ process.exit(1);
370
+ }
371
+ }
@@ -0,0 +1,164 @@
1
+ const { build } = require('@kumologica/builder');
2
+
3
+ exports.command = 'serverless';
4
+ exports.desc = `Export serverless.yml file to deploy kumologica flow using serverless framework"`;
5
+
6
+ exports.builder = {
7
+ "bucket-name": {
8
+ describe: "The name of bucket where zipped lambda is loaded from",
9
+ type: 'string',
10
+ alias: 'b',
11
+ nargs: 1
12
+ },
13
+ timeout: {
14
+ describe: "The time in seconds flow lambda is allowed to run, default: 3, max: 900",
15
+ type: 'number',
16
+ alias: 't',
17
+ nargs: 1
18
+ },
19
+ "memory-size": {
20
+ describe: "The amount of memory allocated to function, default 128 (MB), value must be multiple of 64 (MB)",
21
+ type: 'number',
22
+ alias: 'm',
23
+ nargs: 1
24
+ },
25
+ description: {
26
+ describe: "The description of a function",
27
+ type: 'string',
28
+ alias: 'd',
29
+ nargs: 1
30
+ },
31
+ environment: {
32
+ describe: `Environment variables, JSON Syntax: '{"Variables": {"string": "string" ...}'}`,
33
+ type: 'string',
34
+ alias: 'e',
35
+ nargs: 1
36
+ },
37
+ tags: {
38
+ describe: 'Tags, JSON Syntax:{"string": "string" ...}',
39
+ type: 'string',
40
+ alias: 'g',
41
+ nargs: 1
42
+ },
43
+ "tracing-config": {
44
+ describe: 'X-Ray config, JSON Syntax: {"Mode": "Active"|"PassThrough"} ',
45
+ type: 'string',
46
+ alias: 'x',
47
+ nargs: 1
48
+ },
49
+ "kms-key-arn": {
50
+ describe: "The ARN of KMS key to encrypt env variables",
51
+ type: 'string',
52
+ alias: 'k',
53
+ nargs: 1
54
+ },
55
+ "vpc-config": {
56
+ describe: 'The list of security groups and subnets of VPC, JSON syntax: { "SubnetIds": ["string", ...],"SecurityGroupIds": ["string", ...]}',
57
+ type: 'string',
58
+ alias: 'v',
59
+ nargs: 1
60
+ },
61
+ runtime: {
62
+ describe: "The runtime, only nodejs runtimes allowed: nodejs|nodejs4.3|nodejs6.10|nodejs8.10|nodejs10.x|nodejs12.x|...",
63
+ type: 'string',
64
+ alias: 'r',
65
+ nargs: 1
66
+ },
67
+ "dead-letter-config": {
68
+ describe: 'The arn of the dead letter queue or topic JSON Syntax: {"TargetArn": "string"}',
69
+ type: 'string',
70
+ alias: 'q',
71
+ nargs: 1
72
+ },
73
+ "file-system-configs": {
74
+ describe: 'AWS EFS config details, JSON Syntax: [{"Arn": "string","LocalMountPath": "string"} ...]',
75
+ type: 'string',
76
+ alias: 'f',
77
+ nargs: 1
78
+ }
79
+ }
80
+
81
+ function display(argv) {
82
+ console.log(`\nBuilding aws lambda artefacts with following parameters: \n`);
83
+ console.log('bucket-name: %s', argv["bucket-name"]);
84
+ console.log('timeout: %s', argv.timeout||'');
85
+ console.log('memory-size: %s', argv["memory-size"]||'');
86
+ console.log('description: %s', argv.description||'');
87
+ console.log('environment: %s', argv.environment||'');
88
+ console.log('tags: %s', argv["tags"]||'');
89
+ console.log('tracing-config: %s', argv["tracing-config"]||'');
90
+ console.log('kms-key-arn: %s', argv["kms-key-arn"]||'');
91
+ console.log('vpc-config: %s', argv["vpc-config"]||'');
92
+ console.log('runtime: %s', argv.runtime||'');
93
+ console.log('dead-letter-config: %s', argv["dead-letter-config"]||'');
94
+ console.log('file-system-configs: %s', argv["file-system-configs"]||'');
95
+ }
96
+
97
+ function validateNotEmpty(name, v) {
98
+ if (!v) {
99
+ throw new Error (`Validation error: parameter '${name}' can not be empty`);
100
+ }
101
+ }
102
+
103
+ function validateJson(name, s) {
104
+ console.log(`tof: ${typeof s } val: ${s}`);
105
+ if (typeof s !== 'string') {
106
+ throw new Error (`Validation error: parameter '${name}' value is not string: '${s}'`);
107
+ }
108
+
109
+ let type;
110
+ try {
111
+ const result = JSON.parse(s);
112
+ type = Object.prototype.toString.call(result);
113
+ } catch (e) {
114
+ throw new Error (`Validation error: parameter '${name}': ${e.message}`);
115
+ }
116
+
117
+ if (!(type === '[object Object]' || type === '[object Array]')) {
118
+ throw new Error (`Validation error: parameter '${name}' value is not in JSON format: '${s}'`);
119
+ }
120
+
121
+ console.log(`Parameter ${name} is valid`);
122
+ }
123
+
124
+ function validate(argv) {
125
+
126
+ validateNotEmpty('bucket-name', argv["bucket-name"]);
127
+
128
+ if (argv.environment) {
129
+ validateJson("environment", argv.environment);
130
+ }
131
+ if (argv.tags) {
132
+ validateJson("tags", argv.tags);
133
+ }
134
+ if (argv["tracing-config"]) {
135
+ validateJson("tracing-config", argv["tracing-config"]);
136
+ }
137
+ if (argv["vpc-config"]) {
138
+ validateJson("vpc-config", argv["vpc-config"]);
139
+ }
140
+ if (argv["dead-letter-config"]) {
141
+ validateJson("dead-letter-config", argv["dead-letter-config"]);
142
+ }
143
+ if (argv["file-system-configs"]) {
144
+ validateJson("file-system-configs", argv["file-system-configs"]);
145
+ }
146
+ if (argv.runtime) {
147
+ if (!argv.runtime.startsWith("nodejs")) {
148
+ throw new Error (`Validation error: parameter 'runtime' must be one of supported nodejs values: nodejs|nodejs4.3|nodejs6.10|nodejs8.10|nodejs10.x|nodejs12.x|...`);
149
+ }
150
+ }
151
+ }
152
+
153
+ exports.handler = function (argv) {
154
+ display(argv);
155
+
156
+ try {
157
+ validate(argv);
158
+ build('aws', argv);
159
+
160
+ } catch (e) {
161
+ console.log(`${e.message}`);
162
+ process.exit(1);
163
+ }
164
+ }