@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.
- package/README.md +52 -0
- package/bin/kl.js +2 -0
- package/cli/KumologicaError.js +17 -0
- package/cli/cli.js +7 -0
- package/cli/commands/build-commands/aws.js +49 -0
- package/cli/commands/build-commands/azure.js +43 -0
- package/cli/commands/build-commands/kumohub.js +49 -0
- package/cli/commands/build.js +6 -0
- package/cli/commands/create-commands/create-project-iteratively.js +49 -0
- package/cli/commands/create-commands/index.js +5 -0
- package/cli/commands/create.js +66 -0
- package/cli/commands/deploy-commands/kumohub.js +114 -0
- package/cli/commands/deploy.js +6 -0
- package/cli/commands/doc-commands/html.js +60 -0
- package/cli/commands/doc.js +6 -0
- package/cli/commands/export-commands/cloudformation.js +371 -0
- package/cli/commands/export-commands/serverless.js +164 -0
- package/cli/commands/export-commands/terraform-commands/aws.js +193 -0
- package/cli/commands/export-commands/terraform-commands/azure.js +148 -0
- package/cli/commands/export-commands/terraform.js +6 -0
- package/cli/commands/export-commands/utils/validator.js +195 -0
- package/cli/commands/export.js +6 -0
- package/cli/commands/list-templates.js +24 -0
- package/cli/commands/open.js +53 -0
- package/cli/commands/start.js +165 -0
- package/cli/commands/test/TestSuiteRunner.js +76 -0
- package/cli/commands/test.js +123 -0
- package/cli/utils/download-template-from-repo.js +346 -0
- package/cli/utils/download-test.js +12 -0
- package/cli/utils/download.js +119 -0
- package/cli/utils/fs/copy-dir-contents-sync.js +15 -0
- package/cli/utils/fs/create-zip-file.js +39 -0
- package/cli/utils/fs/dir-exists-sync.js +14 -0
- package/cli/utils/fs/dir-exists.js +17 -0
- package/cli/utils/fs/file-exists-sync.js +14 -0
- package/cli/utils/fs/file-exists.js +12 -0
- package/cli/utils/fs/get-tmp-dir-path.js +22 -0
- package/cli/utils/fs/parse.js +40 -0
- package/cli/utils/fs/read-file-sync.js +11 -0
- package/cli/utils/fs/read-file.js +10 -0
- package/cli/utils/fs/safe-move-file.js +58 -0
- package/cli/utils/fs/walk-dir-sync.js +34 -0
- package/cli/utils/fs/write-file-sync.js +31 -0
- package/cli/utils/fs/write-file.js +32 -0
- package/cli/utils/logger.js +26 -0
- package/cli/utils/rename-service.js +49 -0
- package/package.json +72 -0
- package/src/api/core/comms.js +141 -0
- package/src/api/core/context.js +296 -0
- package/src/api/core/flows.js +286 -0
- package/src/api/core/index.js +29 -0
- package/src/api/core/library.js +106 -0
- package/src/api/core/nodes.js +476 -0
- package/src/api/core/projects.js +426 -0
- package/src/api/core/rest/context.js +42 -0
- package/src/api/core/rest/flow.js +53 -0
- package/src/api/core/rest/flows.js +53 -0
- package/src/api/core/rest/index.js +171 -0
- package/src/api/core/rest/nodes.js +164 -0
- package/src/api/core/rest/util.js +53 -0
- package/src/api/core/settings.js +287 -0
- package/src/api/tools/base/DesignerTool.js +108 -0
- package/src/api/tools/core/flow.js +58 -0
- package/src/api/tools/core/index.js +18 -0
- package/src/api/tools/core/node.js +77 -0
- package/src/api/tools/debugger/index.js +193 -0
- package/src/api/tools/filemanager/index.js +127 -0
- package/src/api/tools/git/index.js +103 -0
- package/src/api/tools/index.js +13 -0
- package/src/api/tools/test/index.js +56 -0
- package/src/api/tools/test/lib/TestCaseRunner.js +105 -0
- package/src/api/tools/test/lib/fixtures/example3-flow.json +148 -0
- package/src/api/tools/test/lib/fixtures/package.json +6 -0
- package/src/api/tools/test/lib/fixtures/s3-event.js +43 -0
- package/src/api/tools/test/lib/reporters/index.js +120 -0
- package/src/server/DesignerServer.js +141 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mixin @kumologica-core/runtime_nodes
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
|
|
7
|
+
var runtime;
|
|
8
|
+
|
|
9
|
+
function putNode(node, enabled) {
|
|
10
|
+
var info;
|
|
11
|
+
var promise;
|
|
12
|
+
if (!node.err && node.enabled === enabled) {
|
|
13
|
+
promise = Promise.resolve(node);
|
|
14
|
+
} else {
|
|
15
|
+
if (enabled) {
|
|
16
|
+
promise = runtime.nodes.enableNode(node.id);
|
|
17
|
+
} else {
|
|
18
|
+
promise = runtime.nodes.disableNode(node.id);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return promise;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var api = (module.exports = {
|
|
25
|
+
init: function(_runtime) {
|
|
26
|
+
runtime = _runtime;
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Gets the info of an individual node set
|
|
31
|
+
* @param {Object} opts
|
|
32
|
+
* @param {User} opts.user - the user calling the api
|
|
33
|
+
* @param {String} opts.id - the id of the node set to return
|
|
34
|
+
* @return {Promise<NodeInfo>} - the node information
|
|
35
|
+
* @memberof @kumologica-core/runtime_nodes
|
|
36
|
+
*/
|
|
37
|
+
getNodeInfo: function(opts) {
|
|
38
|
+
return new Promise(function(resolve, reject) {
|
|
39
|
+
var id = opts.id;
|
|
40
|
+
var result = runtime.nodes.getNodeInfo(id);
|
|
41
|
+
if (result) {
|
|
42
|
+
runtime.log.audit({ event: 'nodes.info.get', id: id });
|
|
43
|
+
delete result.loaded;
|
|
44
|
+
return resolve(result);
|
|
45
|
+
} else {
|
|
46
|
+
runtime.log.audit({
|
|
47
|
+
event: 'nodes.info.get',
|
|
48
|
+
id: id,
|
|
49
|
+
error: 'not_found'
|
|
50
|
+
});
|
|
51
|
+
var err = new Error();
|
|
52
|
+
err.code = 'not_found';
|
|
53
|
+
err.status = 404;
|
|
54
|
+
return reject(err);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Gets the list of node modules installed in the runtime
|
|
61
|
+
* @param {Object} opts
|
|
62
|
+
* @param {User} opts.user - the user calling the api
|
|
63
|
+
* @return {Promise<NodeList>} - the list of node modules
|
|
64
|
+
* @memberof @kumologica-core/runtime_nodes
|
|
65
|
+
*/
|
|
66
|
+
getNodeList: function(opts) {
|
|
67
|
+
return new Promise(function(resolve, reject) {
|
|
68
|
+
runtime.log.audit({ event: 'nodes.list.get' });
|
|
69
|
+
return resolve(runtime.nodes.getNodeList());
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets an individual node's html content
|
|
75
|
+
* @param {Object} opts
|
|
76
|
+
* @param {User} opts.user - the user calling the api
|
|
77
|
+
* @param {String} opts.id - the id of the node set to return
|
|
78
|
+
* @param {String} opts.lang - the locale language to return
|
|
79
|
+
* @return {Promise<String>} - the node html content
|
|
80
|
+
* @memberof @kumologica-core/runtime_nodes
|
|
81
|
+
*/
|
|
82
|
+
getNodeConfig: function(opts) {
|
|
83
|
+
return new Promise(function(resolve, reject) {
|
|
84
|
+
var id = opts.id;
|
|
85
|
+
var lang = opts.lang;
|
|
86
|
+
var result = runtime.nodes.getNodeConfig(id, lang);
|
|
87
|
+
if (result) {
|
|
88
|
+
runtime.log.audit({ event: 'nodes.config.get', id: id });
|
|
89
|
+
return resolve(result);
|
|
90
|
+
} else {
|
|
91
|
+
runtime.log.audit({
|
|
92
|
+
event: 'nodes.config.get',
|
|
93
|
+
id: id,
|
|
94
|
+
error: 'not_found'
|
|
95
|
+
});
|
|
96
|
+
var err = new Error();
|
|
97
|
+
err.code = 'not_found';
|
|
98
|
+
err.status = 404;
|
|
99
|
+
return reject(err);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* Gets all node html content
|
|
105
|
+
* @param {Object} opts
|
|
106
|
+
* @param {User} opts.user - the user calling the api
|
|
107
|
+
* @param {String} opts.lang - the locale language to return
|
|
108
|
+
* @return {Promise<String>} - the node html content
|
|
109
|
+
* @memberof @kumologica-core/runtime_nodes
|
|
110
|
+
*/
|
|
111
|
+
getNodeConfigs: function(opts) {
|
|
112
|
+
return new Promise(function(resolve, reject) {
|
|
113
|
+
runtime.log.audit({ event: 'nodes.configs.get' });
|
|
114
|
+
return resolve(runtime.nodes.getNodeConfigs(opts.lang));
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Gets the info of a node module
|
|
120
|
+
* @param {Object} opts
|
|
121
|
+
* @param {User} opts.user - the user calling the api
|
|
122
|
+
* @param {String} opts.module - the id of the module to return
|
|
123
|
+
* @return {Promise<ModuleInfo>} - the node module info
|
|
124
|
+
* @memberof @kumologica-core/runtime_nodes
|
|
125
|
+
*/
|
|
126
|
+
getModuleInfo: function(opts) {
|
|
127
|
+
return new Promise(function(resolve, reject) {
|
|
128
|
+
var result = runtime.nodes.getModuleInfo(opts.module);
|
|
129
|
+
if (result) {
|
|
130
|
+
runtime.log.audit({ event: 'nodes.module.get', id: opts.module });
|
|
131
|
+
return resolve(result);
|
|
132
|
+
} else {
|
|
133
|
+
runtime.log.audit({
|
|
134
|
+
event: 'nodes.module.get',
|
|
135
|
+
id: opts.module,
|
|
136
|
+
error: 'not_found'
|
|
137
|
+
});
|
|
138
|
+
var err = new Error();
|
|
139
|
+
err.code = 'not_found';
|
|
140
|
+
err.status = 404;
|
|
141
|
+
return reject(err);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
reloadModules: async function(opts) {
|
|
147
|
+
let result = await runtime.nodes.reload();
|
|
148
|
+
return result;
|
|
149
|
+
},
|
|
150
|
+
/**
|
|
151
|
+
* Install a new module into the runtime
|
|
152
|
+
* @param {Object} opts
|
|
153
|
+
* @param {User} opts.user - the user calling the api
|
|
154
|
+
* @param {String} opts.module - the id of the module to install
|
|
155
|
+
* @param {String} opts.version - (optional) the version of the module to install
|
|
156
|
+
* @return {Promise<ModuleInfo>} - the node module info
|
|
157
|
+
* @memberof @kumologica-core/runtime_nodes
|
|
158
|
+
*/
|
|
159
|
+
addModule: function(opts) {
|
|
160
|
+
return new Promise(function(resolve, reject) {
|
|
161
|
+
if (!runtime.settings.available()) {
|
|
162
|
+
runtime.log.audit({
|
|
163
|
+
event: 'nodes.install',
|
|
164
|
+
error: 'settings_unavailable'
|
|
165
|
+
});
|
|
166
|
+
var err = new Error('Settings unavailable');
|
|
167
|
+
err.code = 'settings_unavailable';
|
|
168
|
+
err.status = 400;
|
|
169
|
+
return reject(err);
|
|
170
|
+
}
|
|
171
|
+
if (opts.module) {
|
|
172
|
+
var existingModule = runtime.nodes.getModuleInfo(opts.module);
|
|
173
|
+
if (existingModule) {
|
|
174
|
+
if (!opts.version || existingModule.version === opts.version) {
|
|
175
|
+
runtime.log.audit({
|
|
176
|
+
event: 'nodes.install',
|
|
177
|
+
module: opts.module,
|
|
178
|
+
version: opts.version,
|
|
179
|
+
error: 'module_already_loaded'
|
|
180
|
+
});
|
|
181
|
+
var err = new Error('Module already loaded');
|
|
182
|
+
err.code = 'module_already_loaded';
|
|
183
|
+
err.status = 400;
|
|
184
|
+
return reject(err);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
runtime.nodes
|
|
188
|
+
.installModule(opts.module, opts.version)
|
|
189
|
+
.then(function(info) {
|
|
190
|
+
runtime.log.audit({
|
|
191
|
+
event: 'nodes.install',
|
|
192
|
+
module: opts.module,
|
|
193
|
+
version: opts.version
|
|
194
|
+
});
|
|
195
|
+
return resolve(info);
|
|
196
|
+
})
|
|
197
|
+
.catch(function(err) {
|
|
198
|
+
if (err.code === 404) {
|
|
199
|
+
runtime.log.audit({
|
|
200
|
+
event: 'nodes.install',
|
|
201
|
+
module: opts.module,
|
|
202
|
+
version: opts.version,
|
|
203
|
+
error: 'not_found'
|
|
204
|
+
});
|
|
205
|
+
// TODO: code/status
|
|
206
|
+
err.status = 404;
|
|
207
|
+
} else if (err.code) {
|
|
208
|
+
err.status = 400;
|
|
209
|
+
runtime.log.audit({
|
|
210
|
+
event: 'nodes.install',
|
|
211
|
+
module: opts.module,
|
|
212
|
+
version: opts.version,
|
|
213
|
+
error: err.code
|
|
214
|
+
});
|
|
215
|
+
} else {
|
|
216
|
+
err.status = 400;
|
|
217
|
+
runtime.log.audit({
|
|
218
|
+
event: 'nodes.install',
|
|
219
|
+
module: opts.module,
|
|
220
|
+
version: opts.version,
|
|
221
|
+
error: err.code || 'unexpected_error',
|
|
222
|
+
message: err.toString()
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return reject(err);
|
|
226
|
+
});
|
|
227
|
+
} else {
|
|
228
|
+
runtime.log.audit({
|
|
229
|
+
event: 'nodes.install',
|
|
230
|
+
module: opts.module,
|
|
231
|
+
error: 'invalid_request'
|
|
232
|
+
});
|
|
233
|
+
var err = new Error('Invalid request');
|
|
234
|
+
err.code = 'invalid_request';
|
|
235
|
+
err.status = 400;
|
|
236
|
+
return reject(err);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
},
|
|
240
|
+
/**
|
|
241
|
+
* Removes a module from the runtime
|
|
242
|
+
* @param {Object} opts
|
|
243
|
+
* @param {User} opts.user - the user calling the api
|
|
244
|
+
* @param {String} opts.module - the id of the module to remove
|
|
245
|
+
* @return {Promise} - resolves when complete
|
|
246
|
+
* @memberof @kumologica-core/runtime_nodes
|
|
247
|
+
*/
|
|
248
|
+
removeModule: function(opts) {
|
|
249
|
+
return new Promise(function(resolve, reject) {
|
|
250
|
+
if (!runtime.settings.available()) {
|
|
251
|
+
runtime.log.audit({
|
|
252
|
+
event: 'nodes.install',
|
|
253
|
+
error: 'settings_unavailable'
|
|
254
|
+
});
|
|
255
|
+
var err = new Error('Settings unavailable');
|
|
256
|
+
err.code = 'settings_unavailable';
|
|
257
|
+
err.status = 400;
|
|
258
|
+
return reject(err);
|
|
259
|
+
}
|
|
260
|
+
var module = runtime.nodes.getModuleInfo(opts.module);
|
|
261
|
+
if (!module) {
|
|
262
|
+
runtime.log.audit({
|
|
263
|
+
event: 'nodes.remove',
|
|
264
|
+
module: opts.module,
|
|
265
|
+
error: 'not_found'
|
|
266
|
+
});
|
|
267
|
+
var err = new Error();
|
|
268
|
+
err.code = 'not_found';
|
|
269
|
+
err.status = 404;
|
|
270
|
+
return reject(err);
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
runtime.nodes
|
|
274
|
+
.uninstallModule(opts.module)
|
|
275
|
+
.then(function() {
|
|
276
|
+
runtime.log.audit({ event: 'nodes.remove', module: opts.module });
|
|
277
|
+
resolve();
|
|
278
|
+
})
|
|
279
|
+
.catch(function(err) {
|
|
280
|
+
err.status = 400;
|
|
281
|
+
runtime.log.audit({
|
|
282
|
+
event: 'nodes.remove',
|
|
283
|
+
module: opts.module,
|
|
284
|
+
error: err.code || 'unexpected_error',
|
|
285
|
+
message: err.toString()
|
|
286
|
+
});
|
|
287
|
+
return reject(err);
|
|
288
|
+
});
|
|
289
|
+
} catch (error) {
|
|
290
|
+
runtime.log.audit({
|
|
291
|
+
event: 'nodes.remove',
|
|
292
|
+
module: opts.module,
|
|
293
|
+
error: error.code || 'unexpected_error',
|
|
294
|
+
message: error.toString()
|
|
295
|
+
});
|
|
296
|
+
error.status = 400;
|
|
297
|
+
return reject(error);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
},
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Enables or disables a module in the runtime
|
|
304
|
+
* @param {Object} opts
|
|
305
|
+
* @param {User} opts.user - the user calling the api
|
|
306
|
+
* @param {String} opts.module - the id of the module to enable or disable
|
|
307
|
+
* @param {String} opts.enabled - whether the module should be enabled or disabled
|
|
308
|
+
* @return {Promise<ModuleInfo>} - the module info object
|
|
309
|
+
* @memberof @kumologica-core/runtime_nodes
|
|
310
|
+
*/
|
|
311
|
+
setModuleState: function(opts) {
|
|
312
|
+
var mod = opts.module;
|
|
313
|
+
return new Promise(function(resolve, reject) {
|
|
314
|
+
if (!runtime.settings.available()) {
|
|
315
|
+
runtime.log.audit({
|
|
316
|
+
event: 'nodes.module.set',
|
|
317
|
+
error: 'settings_unavailable'
|
|
318
|
+
});
|
|
319
|
+
var err = new Error('Settings unavailable');
|
|
320
|
+
err.code = 'settings_unavailable';
|
|
321
|
+
err.status = 400;
|
|
322
|
+
return reject(err);
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
var module = runtime.nodes.getModuleInfo(mod);
|
|
326
|
+
if (!module) {
|
|
327
|
+
runtime.log.audit({
|
|
328
|
+
event: 'nodes.module.set',
|
|
329
|
+
module: mod,
|
|
330
|
+
error: 'not_found'
|
|
331
|
+
});
|
|
332
|
+
var err = new Error();
|
|
333
|
+
err.code = 'not_found';
|
|
334
|
+
err.status = 404;
|
|
335
|
+
return reject(err);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
var nodes = module.nodes;
|
|
339
|
+
var promises = [];
|
|
340
|
+
for (var i = 0; i < nodes.length; ++i) {
|
|
341
|
+
promises.push(putNode(nodes[i], opts.enabled));
|
|
342
|
+
}
|
|
343
|
+
Promise.all(promises)
|
|
344
|
+
.then(function() {
|
|
345
|
+
return resolve(runtime.nodes.getModuleInfo(mod));
|
|
346
|
+
})
|
|
347
|
+
.catch(function(err) {
|
|
348
|
+
err.status = 400;
|
|
349
|
+
return reject(err);
|
|
350
|
+
});
|
|
351
|
+
} catch (error) {
|
|
352
|
+
runtime.log.audit({
|
|
353
|
+
event: 'nodes.module.set',
|
|
354
|
+
module: mod,
|
|
355
|
+
enabled: opts.enabled,
|
|
356
|
+
error: error.code || 'unexpected_error',
|
|
357
|
+
message: error.toString()
|
|
358
|
+
});
|
|
359
|
+
error.status = 400;
|
|
360
|
+
return reject(error);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
},
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Enables or disables a n individual node-set in the runtime
|
|
367
|
+
* @param {Object} opts
|
|
368
|
+
* @param {User} opts.user - the user calling the api
|
|
369
|
+
* @param {String} opts.id - the id of the node-set to enable or disable
|
|
370
|
+
* @param {String} opts.enabled - whether the module should be enabled or disabled
|
|
371
|
+
* @return {Promise<ModuleInfo>} - the module info object
|
|
372
|
+
* @memberof @kumologica-core/runtime_nodes
|
|
373
|
+
*/
|
|
374
|
+
setNodeSetState: function(opts) {
|
|
375
|
+
return new Promise(function(resolve, reject) {
|
|
376
|
+
if (!runtime.settings.available()) {
|
|
377
|
+
runtime.log.audit({
|
|
378
|
+
event: 'nodes.info.set',
|
|
379
|
+
error: 'settings_unavailable'
|
|
380
|
+
});
|
|
381
|
+
var err = new Error('Settings unavailable');
|
|
382
|
+
err.code = 'settings_unavailable';
|
|
383
|
+
err.status = 400;
|
|
384
|
+
return reject(err);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
var id = opts.id;
|
|
388
|
+
var enabled = opts.enabled;
|
|
389
|
+
try {
|
|
390
|
+
var node = runtime.nodes.getNodeInfo(id);
|
|
391
|
+
if (!node) {
|
|
392
|
+
runtime.log.audit({
|
|
393
|
+
event: 'nodes.info.set',
|
|
394
|
+
id: id,
|
|
395
|
+
error: 'not_found'
|
|
396
|
+
});
|
|
397
|
+
var err = new Error();
|
|
398
|
+
err.code = 'not_found';
|
|
399
|
+
err.status = 404;
|
|
400
|
+
return reject(err);
|
|
401
|
+
} else {
|
|
402
|
+
delete node.loaded;
|
|
403
|
+
putNode(node, enabled)
|
|
404
|
+
.then(function(result) {
|
|
405
|
+
runtime.log.audit({
|
|
406
|
+
event: 'nodes.info.set',
|
|
407
|
+
id: id,
|
|
408
|
+
enabled: enabled
|
|
409
|
+
});
|
|
410
|
+
return resolve(result);
|
|
411
|
+
})
|
|
412
|
+
.catch(function(err) {
|
|
413
|
+
runtime.log.audit({
|
|
414
|
+
event: 'nodes.info.set',
|
|
415
|
+
id: id,
|
|
416
|
+
enabled: enabled,
|
|
417
|
+
error: err.code || 'unexpected_error',
|
|
418
|
+
message: err.toString()
|
|
419
|
+
});
|
|
420
|
+
err.status = 400;
|
|
421
|
+
return reject(err);
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
} catch (error) {
|
|
425
|
+
runtime.log.audit({
|
|
426
|
+
event: 'nodes.info.set',
|
|
427
|
+
id: id,
|
|
428
|
+
enabled: enabled,
|
|
429
|
+
error: error.code || 'unexpected_error',
|
|
430
|
+
message: error.toString()
|
|
431
|
+
});
|
|
432
|
+
error.status = 400;
|
|
433
|
+
return reject(error);
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
},
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Gets the list of all icons available in the modules installed within the runtime
|
|
440
|
+
* @param {Object} opts
|
|
441
|
+
* @param {User} opts.user - the user calling the api
|
|
442
|
+
* @return {Promise<IconList>} - the list of all icons
|
|
443
|
+
* @memberof @kumologica-core/runtime_nodes
|
|
444
|
+
*/
|
|
445
|
+
getIconList: function(opts) {
|
|
446
|
+
return new Promise(function(resolve, reject) {
|
|
447
|
+
runtime.log.audit({ event: 'nodes.icons.get' });
|
|
448
|
+
return resolve(runtime.nodes.getNodeIcons());
|
|
449
|
+
});
|
|
450
|
+
},
|
|
451
|
+
/**
|
|
452
|
+
* Gets a node icon
|
|
453
|
+
* @param {Object} opts
|
|
454
|
+
* @param {User} opts.user - the user calling the api
|
|
455
|
+
* @param {String} opts.module - the id of the module requesting the icon
|
|
456
|
+
* @param {String} opts.icon - the name of the icon
|
|
457
|
+
* @return {Promise<Buffer>} - the icon file as a Buffer or null if no icon available
|
|
458
|
+
* @memberof @kumologica-core/runtime_nodes
|
|
459
|
+
*/
|
|
460
|
+
getIcon: function(opts) {
|
|
461
|
+
return new Promise(function(resolve, reject) {
|
|
462
|
+
var iconPath = runtime.nodes.getNodeIconPath(opts.module, opts.icon);
|
|
463
|
+
if (iconPath) {
|
|
464
|
+
fs.readFile(iconPath, function(err, data) {
|
|
465
|
+
if (err) {
|
|
466
|
+
err.status = 400;
|
|
467
|
+
return reject(err);
|
|
468
|
+
}
|
|
469
|
+
return resolve(data);
|
|
470
|
+
});
|
|
471
|
+
} else {
|
|
472
|
+
resolve(null);
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
});
|