@kumologica/sdk 3.2.0-beta8 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- exports.command = 'kumohub';
1
+ /*exports.command = 'kumohub';
2
2
  exports.desc = `Deploy kumologica flow to kumohub.io account`;
3
3
 
4
4
  exports.builder = {
@@ -111,4 +111,6 @@ exports.handler = function (argv) {
111
111
  console.log(`${e.message}`);
112
112
  process.exit(1);
113
113
  }
114
- }
114
+ }
115
+
116
+ */
@@ -1,6 +1,7 @@
1
- exports.command = 'deploy <provider>'
1
+ /*exports.command = 'deploy <provider>'
2
2
  exports.desc = 'Deploy kumologica flow binaries'
3
3
  exports.builder = function (yargs) {
4
4
  return yargs.commandDir('deploy-commands')
5
5
  }
6
- exports.handler = function (argv) {}
6
+ exports.handler = function (argv) {}
7
+ */
@@ -158,14 +158,15 @@ Examples:
158
158
  Cloudwatch Event:\n-----------------
159
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
160
  * name - the name of event, optional, default value: Event+timestamp if not provided
161
+ * state - state of event rule: ENABLED or DISABLED, default ENABLED
161
162
  * reference - the reference property set for event listener node that should handle event. Optional
162
163
 
163
164
  Examples:
164
165
  1. Creates event trigger using cron expression that runs at 10am UTC every day:\n
165
166
  {"event": {"expression": "cron(0 10 * * ? *)"}}
166
167
 
167
- 2. Creates event trigger using rate expression that runs every minute:\n
168
- {"event": {"expression": "rate(1 minute)"}}\n
168
+ 2. Creates event trigger using rate expression that runs every minute and is initially disabled:\n
169
+ {"event": {"expression": "rate(1 minute), "state": "DISABLED"}}\n
169
170
 
170
171
  3. Creates event trigger using rate expression that runs every minute for event listener with reference "cleanup":\n
171
172
  {"event": {"expression": "rate(1 minute)", "reference": "cleanup"}}\n
@@ -0,0 +1,374 @@
1
+ const { exp } = require('@kumologica/builder');
2
+
3
+ exports.command = 'aws';
4
+ exports.desc = `Export github workflow file to automate deployment of kumologica flow into AWS using github action workflow.`;
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
+ alias: 't',
50
+ nargs: 1
51
+ },
52
+ "memory-size": {
53
+ describe: "\nThe amount of memory allocated to function, default 128 (MB), must be multiple of 64 (MB), max 4096 (MB)",
54
+ type: 'number',
55
+ default: 128,
56
+ alias: 'm',
57
+ nargs: 1
58
+ },
59
+ description: {
60
+ describe: "\nThe description of a function",
61
+ type: 'string',
62
+ nargs: 1
63
+ },
64
+ environment: {
65
+ describe: `\nEnvironment variables, JSON Syntax: '{"Variables": {"string": "string" ...}'}`,
66
+ type: 'string',
67
+ alias: 'e',
68
+ nargs: 1
69
+ },
70
+ tags: {
71
+ describe: `\nTags, JSON Syntax: '{"name": "value" ...}'`,
72
+ type: 'string',
73
+ alias: 'g',
74
+ nargs: 1
75
+ },
76
+ "tracing-config": {
77
+ describe: `\nX-Ray config, JSON Syntax: '{"Mode": "Active"|"PassThrough"}' `,
78
+ type: 'string',
79
+ alias: 'x',
80
+ nargs: 1
81
+ },
82
+ "kms-key-arn": {
83
+ describe: "\nThe ARN of KMS key to encrypt env variables",
84
+ type: 'string',
85
+ alias: 'k',
86
+ nargs: 1
87
+ },
88
+ "vpc-config": {
89
+ describe: `\nThe list of security groups and subnets of VPC, JSON syntax: '{ "SubnetIds": ["string", ...],"SecurityGroupIds": ["string", ...]}'`,
90
+ type: 'string',
91
+ alias: 'v',
92
+ nargs: 1
93
+ },
94
+ architectures: {
95
+ describe: "\nThe instruction set architecture that the function supports, a string array with one of x86_64, arm64. Default value: [x86_64].",
96
+ type: 'string',
97
+ nargs: 1
98
+ },
99
+ runtime: {
100
+ describe: "\nThe runtime, only nodejs runtimes allowed: nodejs12.x | nodejs14.x | nodejs16.x | ...",
101
+ type: 'string',
102
+ default: 'nodejs14.x',
103
+ alias: 'r',
104
+ nargs: 1
105
+ },
106
+ "dead-letter-config": {
107
+ describe: `\nThe arn of the dead letter queue or topic JSON Syntax: '{"TargetArn": "string"}'`,
108
+ type: 'string',
109
+ alias: 'q',
110
+ nargs: 1
111
+ },
112
+ "file-system-configs": {
113
+ describe: `\nAWS EFS config details, JSON Syntax: '[{"Arn": "string","LocalMountPath": "string"} ...]'`,
114
+ type: 'string',
115
+ nargs: 1
116
+ },
117
+ "log-retention-days": {
118
+ describe: '\nNumber of days logs to be retained',
119
+ type: 'number',
120
+ nargs: 1
121
+ },
122
+ "role-arn": {
123
+ 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.`,
124
+ type: 'string',
125
+ nargs: 1
126
+ },
127
+ "layers": {
128
+ describe: `\nList of arn of lambda layers to be added.`,
129
+ type: 'string',
130
+ nargs: 1
131
+ },
132
+ "policy": {
133
+ 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.`,
134
+ type: 'string',
135
+ nargs: 1
136
+ },
137
+ "strict-mode": {
138
+ 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.',
139
+ type: 'boolean',
140
+ nargs: 1,
141
+ default: true
142
+ },
143
+ triggers: {
144
+ describe: `\nArray of lambda triggers, JSON Syntax: '[{"api": {"apiId": "..",..}]'}
145
+
146
+ Supported triggers:
147
+
148
+ Partner Event:\n-----------------
149
+ * partnerEventBusName - The name of partner event bus name
150
+ * name - the name of event, optional, default value: Event+timestamp if not provided
151
+ * detailType - the detail-type content of the event. Optional
152
+
153
+ Examples:
154
+ 1. Creates partner event trigger for salesforce AccountChangeEvent event:\n
155
+ {"partnerEvent": {"detail-type": "AccountChangeEvent", "partnerEventBusName": "aws.partner/salesforce.com/444444444/555555"}}
156
+
157
+ Cloudwatch Event:\n-----------------
158
+ * 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
159
+ * name - the name of event, optional, default value: Event+timestamp if not provided
160
+ * reference - the reference property set for event listener node that should handle event. Optional
161
+
162
+ Examples:
163
+ 1. Creates event trigger using cron expression that runs at 10am UTC every day:\n
164
+ {"event": {"expression": "cron(0 10 * * ? *)"}}
165
+
166
+ 2. Creates event trigger using rate expression that runs every minute:\n
167
+ {"event": {"expression": "rate(1 minute)"}}\n
168
+
169
+ 3. Creates event trigger using rate expression that runs every minute for event listener with reference "cleanup":\n
170
+ {"event": {"expression": "rate(1 minute)", "reference": "cleanup"}}\n
171
+
172
+ SNS:\n----
173
+ * topicArn - the ARN of sns topic, required
174
+
175
+ Example:
176
+ {"sns": {"topicArn": "arn:aws:sns: ..."}}
177
+
178
+ SQS:\n----
179
+ * queueArn - the ARN of sqs queue, required
180
+ * batchSize - the size of batch, optional
181
+
182
+ Example:
183
+ {"sqs": {"queueArn": "arn:aws:sqs: ..."}}
184
+
185
+ DynamoDB Stream:\n----
186
+ * streamArn - the ARN of dynamodb stream, required
187
+ * batchSize - the size of batch, optional
188
+ * batchWindow - maximum batching window in seconds, optional
189
+ * startingPosition - either LATEST or TRIM_HORIZON, optional
190
+ Example:
191
+ {"dynamodb": {"streamArn": "arn:aws: ...", "startingPosition": "LATEST"}}
192
+
193
+ Kinesis Stream:\n---------------
194
+ * streamArn - the ARN of kinesis stream, required
195
+ * batchSize - the size of batch, optional
196
+ * batchWindow - maximum batching window in seconds, optional
197
+ * startingPosition - either LATEST or TRIM_HORIZON, optional
198
+ Example:
199
+ {"kinesis": {"streamArn": "arn:aws: ...", "startingPosition": "LATEST"}}
200
+
201
+ S3:\n---
202
+ * bucket - the name of the bucket, required
203
+ * sourceAccount - the account id
204
+ * eventType - the size of batch, optional
205
+ * prefix - maximum batching window in seconds, optional
206
+ * suffix - either LATEST or TRIM_HORIZON, optional
207
+ Example:
208
+ {"s3": {"bucket": "testBucket", "eventType": "ObjectCreated.*"}}
209
+
210
+ Rest api gateway:\n-----------------
211
+ * apiId: the id of rest api, required
212
+ * stage: the stage name of api gateway, required
213
+ * parentId: the id of parent resource where lambda {proxy+} should be added, required
214
+ * resource: the name of resource linked to lambda, required if parentId is not root or lambda linked to non root in api gw
215
+ * authorizerType: the type of authorizer: TOKEN, COGNITO_USER_POOLS, REQUEST
216
+ * authorizerId: the if of authorizer, optional
217
+ * apiKeyRequired: true if api key is required. default false
218
+ * scopes: array of scopes, optional
219
+
220
+ Examples:
221
+
222
+ 1. Creates new api gateway, default: 'test' stage and root proxy resource:
223
+
224
+ {"api": {
225
+ "apiId": "create new",
226
+ "apiName": "booking api"\n}
227
+
228
+ 2. Creates new api gateway, default: 'test' stage and proxy resource under /users resource:
229
+
230
+ {"api": {
231
+ "apiId": "create new",
232
+ "apiName": "users api",
233
+ "resource": "users"\n}\n}
234
+
235
+ 3. Uses existing api gateway, 'test' stage, creates proxy resource under /users resource, attaches request authorizer to proxy and required OAuth scopes:
236
+ {"api": {
237
+ "apiId": "fg4wsf",
238
+ "stage": "test",
239
+ "parentId": "vfgd24d",
240
+ "resource": "users",
241
+ "authorizerId": "3dgfd42",
242
+ "authorizerType": "REQUEST",
243
+ "scopes": ["users", "admins"]\n}
244
+
245
+ 4. Uses existing api gateway, 'test' stage, creates proxy resource under specified parent id:
246
+ {"api": {
247
+ \t"apiId": "fg4wsf",
248
+ \t"stage": "test",
249
+ \t"parentId": "vfgd24d"\n}
250
+
251
+ 5. Creates new api gateway, default: 'test' stage, proxy resource under /users resource with required api key:
252
+
253
+ {"api": {
254
+ "apiId": "create new",
255
+ "apiName": "users api",
256
+ "resource": "users",
257
+ "apiKeyRequired: true\n}\n}
258
+ `,
259
+ type: 'string',
260
+ nargs: 1
261
+ },
262
+
263
+ }
264
+
265
+ function display(argv) {
266
+ console.log('Parameters:');
267
+ console.log(' flow-file-name: %s', argv["flow-file-name"]||'');
268
+ console.log(' zip-file-name: %s', argv["zip-file-name"]||'');
269
+ console.log(' lambda-name: %s', argv["lambda-name"]||'');
270
+ console.log(' role-name: %s', argv["role-name"]||'');
271
+ console.log(' bucket-name: %s', argv["bucket-name"]);
272
+ console.log(' timeout: %s', argv["timeout"]);
273
+ console.log(' memory-size: %s', argv["memory-size"]||'');
274
+ console.log(' description: %s', argv.description||'');
275
+ console.log(' environment: %s', argv.environment||'');
276
+ console.log(' tags: %s', argv["tags"]||'');
277
+ console.log(' tracing-config: %s', argv["tracing-config"]||'');
278
+ console.log(' kms-key-arn: %s', argv["kms-key-arn"]||'');
279
+ console.log(' vpc-config: %s', argv["vpc-config"]||'');
280
+ console.log(' architectures: %s', argv.architectures || '');
281
+ console.log(' runtime: %s', argv.runtime||'');
282
+ console.log(' dead-letter-config: %s', argv["dead-letter-config"]||'');
283
+ console.log(' file-system-configs: %s', argv["file-system-configs"]||'');
284
+ console.log(' log-retention-days: %s', argv["log-retention-days"]||'');
285
+ console.log(' role-arn: %s', argv["role-arn"]||'');
286
+ console.log(' policy: %s', argv["policy"] || '');
287
+ console.log(' layers: %s', argv["layers"] || '');
288
+ console.log(` strict-mode: ${argv["strict-mode"]}`);
289
+ console.log(' triggers: %s', argv.triggers||'');
290
+ }
291
+
292
+ function validateJson(name, s) {
293
+ if (typeof s !== 'string') {
294
+ throw new Error (`Validation error: parameter '${name}' value is not string: '${s}'`);
295
+ }
296
+
297
+ let type;
298
+ try {
299
+ const result = JSON.parse(s);
300
+ type = Object.prototype.toString.call(result);
301
+ } catch (e) {
302
+ throw new Error (`Validation error: parameter '${name}': ${e.message}`);
303
+ }
304
+
305
+ if (!(type === '[object Object]' || type === '[object Array]')) {
306
+ throw new Error (`Validation error: parameter '${name}' value is not in JSON format: '${s}'`);
307
+ }
308
+ }
309
+
310
+ function validate(argv) {
311
+
312
+ const validator = require('../utils/validator');
313
+
314
+ if (argv.environment) {
315
+ validateJson("environment", argv.environment);
316
+ }
317
+ if (argv.tags) {
318
+ validateJson("tags", argv.tags);
319
+ }
320
+ if (argv["tracing-config"]) {
321
+ validateJson("tracing-config", argv["tracing-config"]);
322
+ }
323
+ if (argv["vpc-config"]) {
324
+ validateJson("vpc-config", argv["vpc-config"]);
325
+ }
326
+ if (argv["dead-letter-config"]) {
327
+ validateJson("dead-letter-config", argv["dead-letter-config"]);
328
+ }
329
+ if (argv["file-system-configs"]) {
330
+ validateJson("file-system-configs", argv["file-system-configs"]);
331
+ }
332
+ if (argv["policy"]) {
333
+ validateJson("policy", argv["policy"]);
334
+ }
335
+ if (argv["layers"]) {
336
+ validateJson("layers", argv["layers"]);
337
+ }
338
+ if (argv.triggers) {
339
+ validateJson("triggers", argv.triggers);
340
+ validator.validate("triggers", JSON.parse(argv.triggers));
341
+ }
342
+ if (argv.runtime) {
343
+ if (!argv.runtime.startsWith("nodejs")) {
344
+ 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|...`);
345
+ }
346
+ }
347
+ if (argv.architectures ) {
348
+ argv.architectures = JSON.parse(argv.architectures);
349
+ if (!argv.architectures.length || argv.architectures.length != 1 || !["x86_64","arm64"].includes(argv.architectures[0])) {
350
+ throw new Error (`Validation error: parameter 'architectures' must be an array with one element, either x86_64 or arm64`);
351
+ }
352
+ }
353
+ }
354
+
355
+ exports.handler = function (argv) {
356
+ console.log('\nGenerating Github action workflow\n');
357
+ display(argv);
358
+ const chalk = require('chalk');
359
+
360
+ try {
361
+ validate(argv);
362
+
363
+ const { exp } = require('@kumologica/builder');
364
+
365
+ exp('github', 'aws', argv);
366
+ console.log(chalk.greenBright('Github action workflow created successfully.'));
367
+
368
+ process.exit(0);
369
+ } catch (e) {
370
+
371
+ console.log(`${chalk.redBright(e.message)}`);
372
+ process.exit(1);
373
+ }
374
+ }
@@ -0,0 +1,6 @@
1
+ exports.command = 'github <platform>'
2
+ exports.desc = 'Export github workflow for kumologica flow'
3
+ exports.builder = function (yargs) {
4
+ return yargs.commandDir('github-commands')
5
+ }
6
+ exports.handler = function (argv) {}
@@ -29,6 +29,12 @@ const triggersSchema = {
29
29
  "title": "Event name",
30
30
  "type": "string"
31
31
  },
32
+ "state": {
33
+ "$id": "#root/items/event/state",
34
+ "title": "State",
35
+ "type": "string",
36
+ "enum": ["DISABLED", "ENABLED"]
37
+ },
32
38
  "reference": {
33
39
  "$id": "#root/items/event/reference",
34
40
  "title": "Event Listener reference",
@@ -168,8 +174,52 @@ const triggersSchema = {
168
174
  }
169
175
  }
170
176
  }
177
+ },
178
+ "websocket": {
179
+ "$id": "#root/items/websocket",
180
+ "title": "Api",
181
+ "type": "object",
182
+ required: [],
183
+ additionalProperties: false,
184
+ required: ["apiId"],
185
+ "properties": {
186
+ "apiId": {
187
+ "$id": "#root/items/websocket/apiId",
188
+ "title": "ApiId",
189
+ "type": "string",
190
+ "pattern": "^.*$"
191
+ },
192
+ "apiName": {
193
+ "$id": "#root/items/websocket/apiName",
194
+ "title": "ApiName",
195
+ "type": "string",
196
+ "pattern": "^.*$"
197
+ },
198
+ "stage": {
199
+ "$id": "#root/items/websocket/stage",
200
+ "title": "Stage",
201
+ "type": "string",
202
+ "pattern": "^.*$"
203
+ },
204
+ "authorizerId": {
205
+ "$id": "#root/items/websocket/authorizerId",
206
+ "title": "Authorizerid",
207
+ "type": "string",
208
+ "pattern": "^.*$"
209
+ },
210
+ "authorizerType": {
211
+ "$id": "#root/items/websocket/authorizerType",
212
+ "title": "AuthorizerType",
213
+ "type": "string",
214
+ "pattern": "^.*$"
215
+ },
216
+ "apiKeyRequired": {
217
+ "$id": "#root/items/websocket/apiKeyRequired",
218
+ "title": "ApiKeyRequired",
219
+ "type": "boolean"
220
+ }
221
+ }
171
222
  }
172
-
173
223
  }
174
224
  }
175
225
  };
Binary file
@@ -0,0 +1,23 @@
1
+ {
2
+ "test": {
3
+ "testcase": "e8fb91dc.46c24",
4
+ "environment": "debug",
5
+ "environments": [
6
+ "; ===========================================================",
7
+ "; Environment variables must be defined under one section",
8
+ "; You can define as many sections as you need.",
9
+ "; (Remove the semicolons to uncomment the lines)",
10
+ "; ===========================================================",
11
+ "",
12
+ "; Example:",
13
+ "",
14
+ "[debug]",
15
+ "KUMOLOGICA_LOGLEVEL=DEBUG",
16
+ "",
17
+ "[trace]",
18
+ "KUMOLOGICA_LOGLEVEL=TRACE",
19
+ "; VAR_1=VALUE_1",
20
+ ""
21
+ ]
22
+ }
23
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": "0.0.1",
3
+ "runtime": {
4
+ "loglevel": "info",
5
+ "middlewares": [],
6
+ "plugins": []
7
+ }
8
+ }
9
+