@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,286 @@
1
+
2
+
3
+ /**
4
+ * @mixin @kumologica-core/runtime_flows
5
+ */
6
+
7
+ /**
8
+ * @typedef Flows
9
+ * @type {object}
10
+ * @property {string} rev - the flow revision identifier
11
+ * @property {Array} flows - the flow configuration, an array of node configuration objects
12
+ */
13
+
14
+ /**
15
+ * @typedef Flow
16
+ * @type {object}
17
+ * @property {string} id - the flow identifier
18
+ * @property {string} label - a label for the flow
19
+ * @property {Array} nodes - an array of node configuration objects
20
+ */
21
+
22
+ var runtime;
23
+
24
+ var api = (module.exports = {
25
+ init: function(_runtime) {
26
+ runtime = _runtime;
27
+ },
28
+ /**
29
+ * Gets the current flow configuration
30
+ * @param {Object} opts
31
+ * @param {User} opts.user - the user calling the api
32
+ * @return {Promise<Flows>} - the active flow configuration
33
+ * @memberof @kumologica-core/runtime_flows
34
+ */
35
+ getFlows: function(opts) {
36
+ return new Promise(function(resolve, reject) {
37
+ runtime.log.audit({ event: 'flows.get' } /*,req*/);
38
+ return resolve(runtime.nodes.getFlows());
39
+ });
40
+ },
41
+ /**
42
+ * Sets the current flow configuration
43
+ * @param {Object} opts
44
+ * @param {User} opts.user - the user calling the api
45
+ * @return {Promise<Flows>} - the active flow configuration
46
+ * @memberof @kumologica-core/runtime_flows
47
+ */
48
+ setFlows: function(opts) {
49
+ return new Promise(function(resolve, reject) {
50
+ var flows = opts.flows;
51
+
52
+ var deploymentType = opts.deploymentType || 'full';
53
+ runtime.log.audit({ event: 'flows.set', type: deploymentType } /*,req*/);
54
+
55
+ var apiPromise;
56
+ if (deploymentType === 'reload') {
57
+ apiPromise = runtime.nodes.loadFlows(true);
58
+ } else {
59
+ if (flows.hasOwnProperty('rev')) {
60
+ var currentVersion = runtime.nodes.getFlows().rev;
61
+ if (currentVersion !== flows.rev) {
62
+ var err;
63
+ err = new Error();
64
+ err.code = 'version_mismatch';
65
+ err.status = 409;
66
+ //TODO: log warning
67
+ return reject(err);
68
+ }
69
+ }
70
+ apiPromise = runtime.nodes.setFlows(flows.flows, deploymentType);
71
+ }
72
+ apiPromise
73
+ .then(function(flowId) {
74
+ return resolve({ rev: flowId });
75
+ })
76
+ .catch(function(err) {
77
+ if (deploymentType === 'save'){
78
+ runtime.log.warn(`Error saving flows: ${err.message}`);
79
+ } else{
80
+ runtime.log.warn(`Error reloading flows: ${err.message}`);
81
+ }
82
+ runtime.log.warn(err.stack);
83
+ return reject(err);
84
+ });
85
+ });
86
+ },
87
+
88
+ /**
89
+ * Adds a flow configuration
90
+ * @param {Object} opts
91
+ * @param {User} opts.user - the user calling the api
92
+ * @param {Object} opts.flow - the flow to add
93
+ * @return {Promise<String>} - the id of the added flow
94
+ * @memberof @kumologica-core/runtime_flows
95
+ */
96
+ addFlow: function(opts) {
97
+ return new Promise(function(resolve, reject) {
98
+ var flow = opts.flow;
99
+ runtime.nodes
100
+ .addFlow(flow)
101
+ .then(function(id) {
102
+ runtime.log.audit({ event: 'flow.add', id: id });
103
+ return resolve(id);
104
+ })
105
+ .catch(function(err) {
106
+ runtime.log.audit({
107
+ event: 'flow.add',
108
+ error: err.code || 'unexpected_error',
109
+ message: err.toString()
110
+ });
111
+ err.status = 400;
112
+ return reject(err);
113
+ });
114
+ });
115
+ },
116
+
117
+ /**
118
+ * Gets an individual flow configuration
119
+ * @param {Object} opts
120
+ * @param {User} opts.user - the user calling the api
121
+ * @param {Object} opts.id - the id of the flow to retrieve
122
+ * @return {Promise<Flow>} - the active flow configuration
123
+ * @memberof @kumologica-core/runtime_flows
124
+ */
125
+ getFlow: function(opts) {
126
+ return new Promise(function(resolve, reject) {
127
+ var flow = runtime.nodes.getFlow(opts.id);
128
+ if (flow) {
129
+ runtime.log.audit({ event: 'flow.get', id: opts.id });
130
+ return resolve(flow);
131
+ } else {
132
+ runtime.log.audit({
133
+ event: 'flow.get',
134
+ id: opts.id,
135
+ error: 'not_found'
136
+ });
137
+ var err = new Error();
138
+ err.code = 'not_found';
139
+ err.status = 404;
140
+ return reject(err);
141
+ }
142
+ });
143
+ },
144
+ /**
145
+ * Updates an existing flow configuration
146
+ * @param {Object} opts
147
+ * @param {User} opts.user - the user calling the api
148
+ * @param {Object} opts.id - the id of the flow to update
149
+ * @param {Object} opts.flow - the flow configuration
150
+ * @return {Promise<String>} - the id of the updated flow
151
+ * @memberof @kumologica-core/runtime_flows
152
+ */
153
+ updateFlow: function(opts) {
154
+ return new Promise(function(resolve, reject) {
155
+ var flow = opts.flow;
156
+ var id = opts.id;
157
+ try {
158
+ runtime.nodes
159
+ .updateFlow(id, flow)
160
+ .then(function() {
161
+ runtime.log.audit({ event: 'flow.update', id: id });
162
+ return resolve(id);
163
+ })
164
+ .catch(function(err) {
165
+ runtime.log.audit({
166
+ event: 'flow.update',
167
+ error: err.code || 'unexpected_error',
168
+ message: err.toString()
169
+ });
170
+ err.status = 400;
171
+ return reject(err);
172
+ });
173
+ } catch (err) {
174
+ if (err.code === 404) {
175
+ runtime.log.audit({
176
+ event: 'flow.update',
177
+ id: id,
178
+ error: 'not_found'
179
+ });
180
+ // TODO: this swap around of .code and .status isn't ideal
181
+ err.status = 404;
182
+ err.code = 'not_found';
183
+ return reject(err);
184
+ } else {
185
+ runtime.log.audit({
186
+ event: 'flow.update',
187
+ error: err.code || 'unexpected_error',
188
+ message: err.toString()
189
+ });
190
+ err.status = 400;
191
+ return reject(err);
192
+ }
193
+ }
194
+ });
195
+ },
196
+ /**
197
+ * Deletes a flow
198
+ * @param {Object} opts
199
+ * @param {User} opts.user - the user calling the api
200
+ * @param {Object} opts.id - the id of the flow to delete
201
+ * @return {Promise} - resolves if successful
202
+ * @memberof @kumologica-core/runtime_flows
203
+ */
204
+ deleteFlow: function(opts) {
205
+ return new Promise(function(resolve, reject) {
206
+ var id = opts.id;
207
+ try {
208
+ runtime.nodes
209
+ .removeFlow(id)
210
+ .then(function() {
211
+ runtime.log.audit({ event: 'flow.remove', id: id });
212
+ return resolve();
213
+ })
214
+ .catch(function(err) {
215
+ runtime.log.audit({
216
+ event: 'flow.remove',
217
+ id: id,
218
+ error: err.code || 'unexpected_error',
219
+ message: err.toString()
220
+ });
221
+ err.status = 400;
222
+ return reject(err);
223
+ });
224
+ } catch (err) {
225
+ if (err.code === 404) {
226
+ runtime.log.audit({
227
+ event: 'flow.remove',
228
+ id: id,
229
+ error: 'not_found'
230
+ });
231
+ // TODO: this swap around of .code and .status isn't ideal
232
+ err.status = 404;
233
+ err.code = 'not_found';
234
+ return reject(err);
235
+ } else {
236
+ runtime.log.audit({
237
+ event: 'flow.remove',
238
+ id: id,
239
+ error: err.code || 'unexpected_error',
240
+ message: err.toString()
241
+ });
242
+ err.status = 400;
243
+ return reject(err);
244
+ }
245
+ }
246
+ });
247
+ },
248
+
249
+ /**
250
+ * Gets the safe credentials for a node
251
+ * @param {Object} opts
252
+ * @param {User} opts.user - the user calling the api
253
+ * @param {String} opts.type - the node type to return the credential information for
254
+ * @param {String} opts.id - the node id
255
+ * @return {Promise<Object>} - the safe credentials
256
+ * @memberof @kumologica-core/runtime_flows
257
+ */
258
+ getNodeCredentials: function(opts) {
259
+ return new Promise(function(resolve, reject) {
260
+ runtime.log.audit({
261
+ event: 'credentials.get',
262
+ type: opts.type,
263
+ id: opts.id
264
+ });
265
+ var credentials = runtime.nodes.getCredentials(opts.id);
266
+ if (!credentials) {
267
+ return resolve({});
268
+ }
269
+ var definition = runtime.nodes.getCredentialDefinition(opts.type) || {};
270
+
271
+ var sendCredentials = {};
272
+ for (var cred in definition) {
273
+ if (definition.hasOwnProperty(cred)) {
274
+ if (definition[cred].type == 'password') {
275
+ var key = 'has_' + cred;
276
+ sendCredentials[key] =
277
+ credentials[cred] != null && credentials[cred] !== '';
278
+ continue;
279
+ }
280
+ sendCredentials[cred] = credentials[cred] || '';
281
+ }
282
+ }
283
+ resolve(sendCredentials);
284
+ });
285
+ }
286
+ });
@@ -0,0 +1,29 @@
1
+ var runtime;
2
+
3
+ var api = module.exports = {
4
+ init: function(_runtime) {
5
+ runtime = _runtime;
6
+ api.comms.init(runtime);
7
+ api.flows.init(runtime);
8
+ api.nodes.init(runtime);
9
+ api.settings.init(runtime);
10
+ api.library.init(runtime);
11
+ api.projects.init(runtime);
12
+ api.context.init(runtime);
13
+ },
14
+
15
+ comms: require("./comms"),
16
+ flows: require("./flows"),
17
+ library: require("./library"),
18
+ nodes: require("./nodes"),
19
+ settings: require("./settings"),
20
+ projects: require("./projects"),
21
+ context: require("./context"),
22
+
23
+ isStarted: function(opts) {
24
+ return Promise.resolve(runtime.isStarted());
25
+ },
26
+ version: function(opts) {
27
+ return Promise.resolve(runtime.version());
28
+ }
29
+ }
@@ -0,0 +1,106 @@
1
+
2
+
3
+ /**
4
+ * @mixin @kumologica-core/runtime_library
5
+ */
6
+
7
+ var runtime;
8
+
9
+ var api = module.exports = {
10
+ init: function(_runtime) {
11
+ runtime = _runtime;
12
+ },
13
+
14
+ /**
15
+ * Gets an entry from the library.
16
+ * @param {Object} opts
17
+ * @param {User} opts.user - the user calling the api
18
+ * @param {String} opts.type - the type of entry
19
+ * @param {String} opts.path - the path of the entry
20
+ * @return {Promise<String|Object>} - resolves when complete
21
+ * @memberof @kumologica-core/runtime_library
22
+ */
23
+ getEntry: function(opts) {
24
+ return new Promise(function(resolve,reject) {
25
+ runtime.library.getEntry(opts.type,opts.path).then(function(result) {
26
+ runtime.log.audit({event: "library.get",type:opts.type,path:opts.path});
27
+ return resolve(result);
28
+ }).catch(function(err) {
29
+ if (err) {
30
+ runtime.log.warn(`Error loading library entry '${opts.path}': ${err.toString()}`);
31
+ if (err.code === 'forbidden') {
32
+ err.status = 403;
33
+ return reject(err);
34
+ } else if (err.code === "not_found") {
35
+ err.status = 404;
36
+ } else {
37
+ err.status = 400;
38
+ }
39
+ runtime.log.audit({event: "library.get",type:opts.type,path:opts.path,error:err.code});
40
+ return reject(err);
41
+ }
42
+ runtime.log.audit({event: "library.get",type:opts.type,error:"not_found"});
43
+ var error = new Error();
44
+ error.code = "not_found";
45
+ error.status = 404;
46
+ return reject(error);
47
+ });
48
+ })
49
+ },
50
+
51
+ /**
52
+ * Saves an entry to the library
53
+ * @param {Object} opts
54
+ * @param {User} opts.user - the user calling the api
55
+ * @param {String} opts.type - the type of entry
56
+ * @param {String} opts.path - the path of the entry
57
+ * @param {Object} opts.meta - any meta data associated with the entry
58
+ * @param {String} opts.body - the body of the entry
59
+ * @return {Promise} - resolves when complete
60
+ * @memberof @kumologica-core/runtime_library
61
+ */
62
+ saveEntry: function(opts) {
63
+ return new Promise(function(resolve,reject) {
64
+ runtime.library.saveEntry(opts.type,opts.path,opts.meta,opts.body).then(function() {
65
+ runtime.log.audit({event: "library.set",type:opts.type,path:opts.path});
66
+ return resolve();
67
+ }).catch(function(err) {
68
+ runtime.log.warn(`Error saving library entry '${opts.path}': ${err.toString()}`);
69
+ if (err.code === 'forbidden') {
70
+ runtime.log.audit({event: "library.set",type:opts.type,path:opts.path,error:"forbidden"});
71
+ err.status = 403;
72
+ return reject(err);
73
+ }
74
+ runtime.log.audit({event: "library.set",type:opts.type,path:opts.path,error:"unexpected_error",message:err.toString()});
75
+ var error = new Error();
76
+ error.status = 400;
77
+ return reject(error);
78
+ });
79
+ })
80
+ },
81
+ /**
82
+ * Returns a complete listing of all entries of a given type in the library.
83
+ * @param {Object} opts
84
+ * @param {User} opts.user - the user calling the api
85
+ * @param {String} opts.type - the type of entry
86
+ * @return {Promise<Object>} - the entry listing
87
+ * @memberof @kumologica-core/runtime_library
88
+ */
89
+ getEntries: function(opts) {
90
+ return new Promise(function(resolve,reject) {
91
+ if (opts.type !== 'flows') {
92
+ return reject(new Error("API only supports flows"));
93
+
94
+ }
95
+ runtime.storage.getAllFlows().then(function(flows) {
96
+ runtime.log.audit({event: "library.get.all",type:"flow"});
97
+ var examples = runtime.nodes.getNodeExampleFlows();
98
+ if (examples) {
99
+ flows.d = flows.d||{};
100
+ flows.d._examples_ = examples;
101
+ }
102
+ return resolve(flows);
103
+ });
104
+ })
105
+ }
106
+ }