@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,426 @@
1
+
2
+
3
+ /**
4
+ * @mixin @kumologica-core/runtime_projects
5
+ */
6
+
7
+ var runtime;
8
+
9
+ var api = module.exports = {
10
+ init: function(_runtime) {
11
+ runtime = _runtime;
12
+ },
13
+ available: function(opts) {
14
+ return Promise.resolve(!!runtime.storage.projects);
15
+ },
16
+
17
+ /**
18
+ * List projects known to the runtime
19
+ * @param {Object} opts
20
+ * @param {User} opts.user - the user calling the api
21
+ * @return {Promise<Object>} - resolves when complete
22
+ * @memberof @kumologica-core/runtime_projects
23
+ */
24
+ listProjects: function(opts) {
25
+ return runtime.storage.projects.listProjects(opts.user).then(function(list) {
26
+ var active = runtime.storage.projects.getActiveProject(opts.user);
27
+ var response = {
28
+ projects: list
29
+ };
30
+ if (active) {
31
+ response.active = active.name;
32
+ }
33
+ return response;
34
+ }).catch(function(err) {
35
+ err.status = 400;
36
+ throw err;
37
+ })
38
+ },
39
+
40
+ /**
41
+ * Create a new project
42
+ * @param {Object} opts
43
+ * @param {User} opts.user - the user calling the api
44
+ * @param {Object} opts.project - the project information
45
+ * @return {Promise<Object>} - resolves when complete
46
+ * @memberof @kumologica-core/runtime_projects
47
+ */
48
+ createProject: function(opts) {
49
+ return runtime.storage.projects.createProject(opts.user, opts.project)
50
+ },
51
+
52
+ /**
53
+ * Initialises an empty project
54
+ * @param {Object} opts
55
+ * @param {User} opts.user - the user calling the api
56
+ * @param {String} opts.id - the id of the project to initialise
57
+ * @param {Object} opts.project - the project information
58
+ * @return {Promise<Object>} - resolves when complete
59
+ * @memberof @kumologica-core/runtime_projects
60
+ */
61
+ initialiseProject: function(opts) {
62
+ // Initialised set when creating default files for an empty repo
63
+ return runtime.storage.projects.initialiseProject(opts.user, opts.id, opts.project)
64
+ },
65
+
66
+ /**
67
+ * Gets the active project
68
+ * @param {Object} opts
69
+ * @param {User} opts.user - the user calling the api
70
+ * @return {Promise<Object>} - the active project
71
+ * @memberof @kumologica-core/runtime_projects
72
+ */
73
+ getActiveProject: function(opts) {
74
+ return Promise.resolve(runtime.storage.projects.getActiveProject(opts.user));
75
+ },
76
+
77
+ /**
78
+ *
79
+ * @param {Object} opts
80
+ * @param {User} opts.user - the user calling the api
81
+ * @param {String} opts.id - the id of the project to activate
82
+ * @return {Promise<Object>} - resolves when complete
83
+ * @memberof @kumologica-core/runtime_projects
84
+ */
85
+ setActiveProject: function(opts) {
86
+ var currentProject = runtime.storage.projects.getActiveProject(opts.user);
87
+ if (!currentProject || opts.id !== currentProject.name) {
88
+ return runtime.storage.projects.setActiveProject(opts.user, opts.id);
89
+ } else {
90
+ return Promise.resolve();
91
+ }
92
+ },
93
+
94
+ /**
95
+ * Gets a projects metadata
96
+ * @param {Object} opts
97
+ * @param {User} opts.user - the user calling the api
98
+ * @param {String} opts.id - the id of the project to get
99
+ * @return {Promise<Object>} - the project metadata
100
+ * @memberof @kumologica-core/runtime_projects
101
+ */
102
+ getProject: function(opts) {
103
+ return runtime.storage.projects.getProject(opts.user, opts.id)
104
+ },
105
+
106
+ /**
107
+ * Updates the metadata of an existing project
108
+ * @param {Object} opts
109
+ * @param {User} opts.user - the user calling the api
110
+ * @param {String} opts.id - the id of the project to update
111
+ * @param {Object} opts.project - the project information
112
+ * @return {Promise<Object>} - resolves when complete
113
+ * @memberof @kumologica-core/runtime_projects
114
+ */
115
+ updateProject: function(opts) {
116
+ return runtime.storage.projects.updateProject(opts.user, opts.id, opts.project);
117
+ },
118
+
119
+ /**
120
+ * Deletes a project
121
+ * @param {Object} opts
122
+ * @param {User} opts.user - the user calling the api
123
+ * @param {String} opts.id - the id of the project to update
124
+ * @return {Promise<Object>} - resolves when complete
125
+ * @memberof @kumologica-core/runtime_projects
126
+ */
127
+ deleteProject: function(opts) {
128
+ return runtime.storage.projects.deleteProject(opts.user, opts.id);
129
+ },
130
+
131
+ /**
132
+ * Gets current git status of a project
133
+ * @param {Object} opts
134
+ * @param {User} opts.user - the user calling the api
135
+ * @param {String} opts.id - the id of the project
136
+ * @param {Boolean} opts.remote - whether to include status of remote repos
137
+ * @return {Promise<Object>} - the project status
138
+ * @memberof @kumologica-core/runtime_projects
139
+ */
140
+ getStatus: function(opts) {
141
+ return runtime.storage.projects.getStatus(opts.user, opts.id, opts.remote)
142
+ },
143
+
144
+ /**
145
+ * Get a list of local branches
146
+ * @param {Object} opts
147
+ * @param {User} opts.user - the user calling the api
148
+ * @param {String} opts.id - the id of the project
149
+ * @param {Boolean} opts.remote - whether to return remote branches (true) or local (false)
150
+ * @return {Promise<Object>} - a list of the local branches
151
+ * @memberof @kumologica-core/runtime_projects
152
+ */
153
+ getBranches: function(opts) {
154
+ return runtime.storage.projects.getBranches(opts.user, opts.id, opts.remote);
155
+ },
156
+
157
+ /**
158
+ * Gets the status of a branch
159
+ * @param {Object} opts
160
+ * @param {User} opts.user - the user calling the api
161
+ * @param {String} opts.id - the id of the project
162
+ * @param {String} opts.branch - the name of the branch
163
+ * @return {Promise<Object>} - the status of the branch
164
+ * @memberof @kumologica-core/runtime_projects
165
+ */
166
+ getBranchStatus: function(opts) {
167
+ return runtime.storage.projects.getBranchStatus(opts.user, opts.id, opts.branch);
168
+ },
169
+
170
+ /**
171
+ * Sets the current local branch
172
+ * @param {Object} opts
173
+ * @param {User} opts.user - the user calling the api
174
+ * @param {String} opts.id - the id of the project
175
+ * @param {String} opts.branch - the name of the branch
176
+ * @param {Boolean} opts.create - whether to create the branch if it doesn't exist
177
+ * @return {Promise<Object>} - resolves when complete
178
+ * @memberof @kumologica-core/runtime_projects
179
+ */
180
+ setBranch: function(opts) {
181
+ return runtime.storage.projects.setBranch(opts.user, opts.id, opts.branch, opts.create)
182
+ },
183
+
184
+ /**
185
+ * Deletes a branch
186
+ * @param {Object} opts
187
+ * @param {User} opts.user - the user calling the api
188
+ * @param {String} opts.id - the id of the project
189
+ * @param {String} opts.branch - the name of the branch
190
+ * @param {Boolean} opts.force - whether to force delete
191
+ * @return {Promise<Object>} - resolves when complete
192
+ * @memberof @kumologica-core/runtime_projects
193
+ */
194
+ deleteBranch: function(opts) {
195
+ return runtime.storage.projects.deleteBranch(opts.user, opts.id, opts.branch, false, opts.force);
196
+ },
197
+
198
+ /**
199
+ * Commits the current staged files
200
+ * @param {Object} opts
201
+ * @param {User} opts.user - the user calling the api
202
+ * @param {String} opts.id - the id of the project
203
+ * @param {String} opts.message - the message to associate with the commit
204
+ * @return {Promise<Object>} - resolves when complete
205
+ * @memberof @kumologica-core/runtime_projects
206
+ */
207
+ commit: function(opts) {
208
+ return runtime.storage.projects.commit(opts.user, opts.id,{message: opts.message});
209
+ },
210
+
211
+ /**
212
+ * Gets the details of a single commit
213
+ * @param {Object} opts
214
+ * @param {User} opts.user - the user calling the api
215
+ * @param {String} opts.id - the id of the project
216
+ * @param {String} opts.sha - the sha of the commit to return
217
+ * @return {Promise<Object>} - the commit details
218
+ * @memberof @kumologica-core/runtime_projects
219
+ */
220
+ getCommit: function(opts) {
221
+ return runtime.storage.projects.getCommit(opts.user, opts.id, opts.sha);
222
+ },
223
+
224
+ /**
225
+ * Gets the commit history of the project
226
+ * @param {Object} opts
227
+ * @param {User} opts.user - the user calling the api
228
+ * @param {String} opts.id - the id of the project
229
+ * @param {String} opts.limit - limit how many to return
230
+ * @param {String} opts.before - id of the commit to work back from
231
+ * @return {Promise<Array>} - an array of commits
232
+ * @memberof @kumologica-core/runtime_projects
233
+ */
234
+ getCommits: function(opts) {
235
+ return runtime.storage.projects.getCommits(opts.user, opts.id, {
236
+ limit: opts.limit || 20,
237
+ before: opts.before
238
+ });
239
+ },
240
+
241
+ /**
242
+ * Abort an in-progress merge
243
+ * @param {Object} opts
244
+ * @param {User} opts.user - the user calling the api
245
+ * @param {String} opts.id - the id of the project
246
+ * @return {Promise<Object>} - resolves when complete
247
+ * @memberof @kumologica-core/runtime_projects
248
+ */
249
+ abortMerge: function(opts) {
250
+ return runtime.storage.projects.abortMerge(opts.user, opts.id);
251
+ },
252
+
253
+ /**
254
+ * Resolves a merge conflict
255
+ * @param {Object} opts
256
+ * @param {User} opts.user - the user calling the api
257
+ * @param {String} opts.id - the id of the project
258
+ * @param {String} opts.path - the path of the file being merged
259
+ * @param {String} opts.resolutions - how to resolve the merge conflict
260
+ * @return {Promise<Object>} - resolves when complete
261
+ * @memberof @kumologica-core/runtime_projects
262
+ */
263
+ resolveMerge: function(opts) {
264
+ return runtime.storage.projects.resolveMerge(opts.user, opts.id, opts.path, opts.resolution);
265
+ },
266
+
267
+ /**
268
+ * Gets a listing of the files in the project
269
+ * @param {Object} opts
270
+ * @param {User} opts.user - the user calling the api
271
+ * @param {String} opts.id - the id of the project
272
+ * @return {Promise<Object>} - the file listing
273
+ * @memberof @kumologica-core/runtime_projects
274
+ */
275
+ getFiles: function(opts) {
276
+ return runtime.storage.projects.getFiles(opts.user, opts.id);
277
+ },
278
+
279
+ /**
280
+ * Gets the contents of a file
281
+ * @param {Object} opts
282
+ * @param {User} opts.user - the user calling the api
283
+ * @param {String} opts.id - the id of the project
284
+ * @param {String} opts.path - the path of the file
285
+ * @param {String} opts.tree - the version control tree to use
286
+ * @return {Promise<String>} - the content of the file
287
+ * @memberof @kumologica-core/runtime_projects
288
+ */
289
+ getFile: function(opts) {
290
+ return runtime.storage.projects.getFile(opts.user, opts.id,opts.path,opts.tree);
291
+ },
292
+
293
+ /**
294
+ *
295
+ * @param {Object} opts
296
+ * @param {User} opts.user - the user calling the api
297
+ * @param {String} opts.id - the id of the project
298
+ * @param {String|Array} opts.path - the path of the file, or an array of paths
299
+ * @return {Promise<Object>} - resolves when complete
300
+ * @memberof @kumologica-core/runtime_projects
301
+ */
302
+ stageFile: function(opts) {
303
+ return runtime.storage.projects.stageFile(opts.user, opts.id, opts.path);
304
+ },
305
+
306
+ /**
307
+ *
308
+ * @param {Object} opts
309
+ * @param {User} opts.user - the user calling the api
310
+ * @param {String} opts.id - the id of the project
311
+ * @param {String} opts.path - the path of the file. If not set, all staged files are unstaged
312
+ * @return {Promise<Object>} - resolves when complete
313
+ * @memberof @kumologica-core/runtime_projects
314
+ */
315
+ unstageFile: function(opts) {
316
+ return runtime.storage.projects.unstageFile(opts.user, opts.id, opts.path);
317
+ },
318
+
319
+ /**
320
+ * Reverts changes to a file back to its commited version
321
+ * @param {Object} opts
322
+ * @param {User} opts.user - the user calling the api
323
+ * @param {String} opts.id - the id of the project
324
+ * @param {String} opts.path - the path of the file
325
+ * @return {Promise<Object>} - resolves when complete
326
+ * @memberof @kumologica-core/runtime_projects
327
+ */
328
+ revertFile: function(opts) {
329
+ return runtime.storage.projects.revertFile(opts.user, opts.id,opts.path)
330
+ },
331
+
332
+ /**
333
+ * Get the diff of a file
334
+ * @param {Object} opts
335
+ * @param {User} opts.user - the user calling the api
336
+ * @param {String} opts.id - the id of the project
337
+ * @param {String} opts.path - the path of the file
338
+ * @param {String} opts.type - the type of diff
339
+ * @return {Promise<Object>} - the requested diff
340
+ * @memberof @kumologica-core/runtime_projects
341
+ */
342
+ getFileDiff: function(opts) {
343
+ return runtime.storage.projects.getFileDiff(opts.user, opts.id, opts.path, opts.type);
344
+ },
345
+
346
+ /**
347
+ * Gets a list of the project remotes
348
+ * @param {Object} opts
349
+ * @param {User} opts.user - the user calling the api
350
+ * @param {String} opts.id - the id of the project
351
+ * @return {Promise<Object>} - a list of project remotes
352
+ * @memberof @kumologica-core/runtime_projects
353
+ */
354
+ getRemotes: function(opts) {
355
+ return runtime.storage.projects.getRemotes(opts.user, opts.id);
356
+
357
+ },
358
+
359
+ /**
360
+ *
361
+ * @param {Object} opts
362
+ * @param {User} opts.user - the user calling the api
363
+ * @param {String} opts.id - the id of the project
364
+ * @param {Object} opts.remote - the remote metadata
365
+ * @param {String} opts.remote.name - the name of the remote
366
+ * @param {String} opts.remote.url - the url of the remote
367
+ * @return {Promise<Object>} - resolves when complete
368
+ * @memberof @kumologica-core/runtime_projects
369
+ */
370
+ addRemote: function(opts) {
371
+ return runtime.storage.projects.addRemote(opts.user, opts.id, opts.remote)
372
+ },
373
+
374
+ /**
375
+ * Remove a project remote
376
+ * @param {Object} opts
377
+ * @param {User} opts.user - the user calling the api
378
+ * @param {String} opts.id - the id of the project
379
+ * @param {String} opts.remote - the name of the remote
380
+ * @return {Promise<Object>} - resolves when complete
381
+ * @memberof @kumologica-core/runtime_projects
382
+ */
383
+ removeRemote: function(opts) {
384
+ return runtime.storage.projects.removeRemote(opts.user, opts.id, opts.remote);
385
+ },
386
+
387
+ /**
388
+ *
389
+ * @param {Object} opts
390
+ * @param {User} opts.user - the user calling the api
391
+ * @param {String} opts.id - the id of the project
392
+ * @param {Object} opts.remote - the remote metadata
393
+ * @param {String} opts.remote.name - the name of the remote
394
+ * @return {Promise<Object>} - resolves when complete
395
+ * @memberof @kumologica-core/runtime_projects
396
+ */
397
+ updateRemote: function(opts) {
398
+ return runtime.storage.projects.updateRemote(opts.user, opts.id, opts.remote.name, opts.remote)
399
+ },
400
+
401
+ /**
402
+ * Pull changes from the remote
403
+ * @param {Object} opts
404
+ * @param {User} opts.user - the user calling the api
405
+ * @return {Promise<Object>} - resolves when complete
406
+ * @memberof @kumologica-core/runtime_projects
407
+ */
408
+ pull: function(opts) {
409
+ return runtime.storage.projects.pull(opts.user, opts.id, opts.remote, opts.track, opts.allowUnrelatedHistories);
410
+ },
411
+
412
+ /**
413
+ * Push changes to a remote
414
+ * @param {Object} opts
415
+ * @param {User} opts.user - the user calling the api
416
+ * @param {String} opts.id - the id of the project
417
+ * @param {String} opts.remote - the name of the remote
418
+ * @param {String} opts.track - whether to set the remote as the upstream
419
+ * @return {Promise<Object>} - resolves when complete
420
+ * @memberof @kumologica-core/runtime_projects
421
+ */
422
+ push: function(opts) {
423
+ return runtime.storage.projects.push(opts.user, opts.id, opts.remote, opts.track);
424
+ }
425
+
426
+ }
@@ -0,0 +1,42 @@
1
+
2
+
3
+ var apiUtils = require("./util");
4
+
5
+ var runtimeAPI;
6
+
7
+
8
+ module.exports = {
9
+ init: function(_runtimeAPI) {
10
+ runtimeAPI = _runtimeAPI;
11
+ },
12
+
13
+ get: function(req,res) {
14
+ var opts = {
15
+ user: req.user,
16
+ scope: req.params.scope,
17
+ id: req.params.id,
18
+ key: req.params[0],
19
+ store: req.query['store']
20
+ }
21
+ runtimeAPI.context.getValue(opts).then(function(result) {
22
+ res.json(result);
23
+ }).catch(function(err) {
24
+ apiUtils.rejectHandler(req,res,err);
25
+ })
26
+ },
27
+
28
+ delete: function(req,res) {
29
+ var opts = {
30
+ user: req.user,
31
+ scope: req.params.scope,
32
+ id: req.params.id,
33
+ key: req.params[0],
34
+ store: req.query['store']
35
+ }
36
+ runtimeAPI.context.delete(opts).then(function(result) {
37
+ res.status(204).end();
38
+ }).catch(function(err) {
39
+ apiUtils.rejectHandler(req,res,err);
40
+ })
41
+ }
42
+ }
@@ -0,0 +1,53 @@
1
+ let runtimeAPI;
2
+ const apiUtils = require("./util");
3
+
4
+ module.exports = {
5
+ init: function(_runtimeAPI) {
6
+ runtimeAPI = _runtimeAPI;
7
+ },
8
+ get: function(req,res) {
9
+ var opts = {
10
+ user: req.user,
11
+ id: req.params.id
12
+ }
13
+ runtimeAPI.flows.getFlow(opts).then(function(result) {
14
+ return res.json(result);
15
+ }).catch(function(err) {
16
+ apiUtils.rejectHandler(req,res,err);
17
+ })
18
+ },
19
+ post: function(req,res) {
20
+ var opts = {
21
+ user: req.user,
22
+ flow: req.body
23
+ }
24
+ runtimeAPI.flows.addFlow(opts).then(function(id) {
25
+ return res.json({id:id});
26
+ }).catch(function(err) {
27
+ apiUtils.rejectHandler(req,res,err);
28
+ })
29
+ },
30
+ put: function(req,res) {
31
+ var opts = {
32
+ user: req.user,
33
+ id: req.params.id,
34
+ flow: req.body
35
+ }
36
+ runtimeAPI.flows.updateFlow(opts).then(function(id) {
37
+ return res.json({id:id});
38
+ }).catch(function(err) {
39
+ apiUtils.rejectHandler(req,res,err);
40
+ })
41
+ },
42
+ delete: function(req,res) {
43
+ var opts = {
44
+ user: req.user,
45
+ id: req.params.id
46
+ }
47
+ runtimeAPI.flows.deleteFlow(opts).then(function() {
48
+ res.status(204).end();
49
+ }).catch(function(err) {
50
+ apiUtils.rejectHandler(req,res,err);
51
+ })
52
+ }
53
+ }
@@ -0,0 +1,53 @@
1
+
2
+
3
+ var runtimeAPI;
4
+ const apiUtils = require('./util');
5
+
6
+ module.exports = {
7
+ init: function(_runtimeAPI) {
8
+ runtimeAPI = _runtimeAPI;
9
+ },
10
+ get: function(req, res) {
11
+ var version = req.get('kumologica-core-API-Version') || 'v1';
12
+ if (!/^v[12]$/.test(version)) {
13
+ return res.status(400).json({
14
+ code: 'invalid_api_version',
15
+ message: 'Invalid API Version requested'
16
+ });
17
+ }
18
+ var opts = {
19
+ user: req.user
20
+ };
21
+ runtimeAPI.flows
22
+ .getFlows(opts)
23
+ .then(function(result) {
24
+ if (version === 'v1') {
25
+ res.json(result.flows);
26
+ } else if (version === 'v2') {
27
+ res.json(result);
28
+ }
29
+ })
30
+ .catch(function(err) {
31
+ apiUtils.rejectHandler(req, res, err);
32
+ });
33
+ },
34
+ post: async (req, res) => {
35
+ var opts = {
36
+ user: req.user,
37
+ deploymentType: req.get('kumologica-core-Deployment-Type') || 'full'
38
+ };
39
+
40
+ if (opts.deploymentType !== 'reload') {
41
+ opts.flows = req.body;
42
+ }
43
+
44
+ try {
45
+ let result = await runtimeAPI.flows.setFlows(opts);
46
+ // Disable below line until we decide if IDE is responsible to bind triggers to lambda
47
+ // RED.events.emit('editor:post-deployment');
48
+ res.json(result);
49
+ } catch (err) {
50
+ apiUtils.rejectHandler(req, res, err);
51
+ }
52
+ }
53
+ };