@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
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # kumologica-sdk
2
+
3
+ Kumologica SDK consist of 4 products:
4
+ - Kumologica designer
5
+ - Kumologica runtime
6
+ - Kumologica CLI
7
+ - Kumologica nodes development kit
8
+
9
+ ## Installation
10
+
11
+ To install kumologica sdk, run the following command:
12
+
13
+ ```bash
14
+ npm install -g @kumologica/sdk
15
+ ```
16
+ Note that node.js is required to run installation and kumologica sdk. To install node.js go to [nodejs.org](https://nodejs.org)
17
+ ### Upgrade
18
+ Use the same command to upgrade kumologica sdk to the latest version.
19
+
20
+ To upgrade kumologica sdk to the specific version or tag, use:
21
+
22
+ ```bash
23
+ npm install -g @kumologica/sdk@{version number}
24
+ ```
25
+
26
+ ## Getting started
27
+
28
+ Kumologica sdk contains CLI that provides various commands.
29
+ ### Create sample project
30
+
31
+ To create project with sample code and then open project in kumologica designer run following commands:
32
+ ```bash
33
+ # create project with name firstproject
34
+ kl create -p firstproject
35
+
36
+ # open firstproject in kumologica designer
37
+
38
+ kl open firstproject
39
+ ```
40
+ ### Opening kumologica designer
41
+ To open kumologica designer run command:
42
+
43
+ ```bash
44
+ kl open
45
+ ```
46
+ You can always create new project withing kumologica designer or choose existing project to open.
47
+
48
+ ## Next Steps
49
+
50
+ - [Build your first api flow](https://docs.kumologica.com/docs/guide/GettingStarted.html#build-your-first-api-flow)
51
+ - [Build your second api flow](https://docs.kumologica.com/docs/guide/GettingStarted.html#build-your-second-api-flow)
52
+ - [Kumologica documentation](https://docs.kumologica.com/docs/guide/Intro.html)
package/bin/kl.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('../cli/cli.js');
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ class KumologicaError extends Error {
4
+ constructor(message, code, options = {}) {
5
+ super(message);
6
+ this.code = code;
7
+ this.decoratedMessage = options.decoratedMessage;
8
+ }
9
+ }
10
+
11
+ Object.defineProperty(KumologicaError.prototype, 'name', {
12
+ value: KumologicaError.name,
13
+ configurable: true,
14
+ writable: true,
15
+ });
16
+
17
+ module.exports = KumologicaError;
package/cli/cli.js ADDED
@@ -0,0 +1,7 @@
1
+ require('yargs/yargs')(process.argv.slice(2))
2
+ .commandDir('commands')
3
+ .demandCommand()
4
+ .help('help', 'Show usage information & exit')
5
+ .alias('help', 'h')
6
+ // .epilog("copyright 2021")
7
+ .argv
@@ -0,0 +1,49 @@
1
+ exports.command = 'aws';
2
+ exports.desc = `Builds aws lambda binaries:
3
+ * generates aws lambda artefacts
4
+ * runs npm install
5
+ * creates zip file
6
+
7
+ Documentation:
8
+ https://docs.kumologica.com/docs/references/cli/BuildAws.html`;
9
+
10
+ exports.builder = {
11
+ "flow-file-name": {
12
+ describe: "The name of kumologica flow file.\n Auto search if not provided.\n ",
13
+ type: 'string',
14
+ alias: 'f',
15
+ nargs: 1
16
+ },
17
+ "project-directory": {
18
+ describe: "The root directory of project.\n Current working directory if not provided.\n",
19
+ type: 'string',
20
+ alias: 'd',
21
+ nargs: 1
22
+ },
23
+ "zip-file-name": {
24
+ describe: "The name of zip file to be created",
25
+ type: 'string',
26
+ default: 'lambda.zip',
27
+ alias: 'z',
28
+ nargs: 1
29
+ }
30
+ }
31
+
32
+ function display(argv) {
33
+ console.log(`\nBuilding aws lambda artefacts with following parameters: \n`);
34
+ console.log('project-directory: %s', argv["project-directory"]||'');
35
+ console.log('flow-file-name: %s', argv["flow-file-name"]||'');
36
+ console.log('zip-file-name: %s', argv["zip-file-name"]||'');
37
+ }
38
+
39
+ exports.handler = function (argv) {
40
+ display(argv);
41
+
42
+ try {
43
+ const { build } = require('@kumologica/builder');
44
+ build('aws', argv);
45
+ } catch (e) {
46
+ console.log(`${e.message}`);
47
+ process.exit(1);
48
+ }
49
+ }
@@ -0,0 +1,43 @@
1
+ exports.command = 'azure';
2
+ exports.desc = `Generate azure function artefacts and build zip file`;
3
+
4
+ exports.builder = {
5
+ "flow-file-name": {
6
+ describe: "The name of kumologica flow file.\n Auto search if not provided.",
7
+ type: 'string',
8
+ alias: 'f',
9
+ nargs: 1
10
+ },
11
+ "project-directory": {
12
+ describe: "The root directory of project.\n Process directory if not provided.",
13
+ type: 'string',
14
+ alias: 'd',
15
+ nargs: 1
16
+ },
17
+ "zip-file-name": {
18
+ describe: "The name of zip file name",
19
+ type: 'string',
20
+ default: 'azure.zip',
21
+ alias: 'z',
22
+ nargs: 1
23
+ }
24
+ }
25
+
26
+ function display(argv) {
27
+ console.log(`\nBuilding azure function artefacts with following parameters: \n`);
28
+ console.log('project-directory: %s', argv["project-directory"] || '');
29
+ console.log('flow-file-name: %s', argv["flow-file-name"] || '');
30
+ console.log('zip-file-name: %s', argv["zip-file-name"] || '');
31
+ }
32
+
33
+ exports.handler = function (argv) {
34
+ display(argv);
35
+
36
+ try {
37
+ const { build } = require('@kumologica/builder');
38
+ build('azure', argv);
39
+ } catch (e) {
40
+ console.log(`${e.message}`);
41
+ process.exit(1);
42
+ }
43
+ }
@@ -0,0 +1,49 @@
1
+ exports.command = 'kumohub';
2
+ exports.desc = `Builds kumohub binaries:
3
+ * generates kumohub artefacts
4
+ * runs npm install
5
+ * creates zip file
6
+
7
+ Documentation:
8
+ https://docs.kumologica.com/docs/references/cli/BuildKumohub.html`;
9
+
10
+ exports.builder = {
11
+ "flow-file-name": {
12
+ describe: "The name of kumologica flow file.\n Auto search if not provided.\n ",
13
+ type: 'string',
14
+ alias: 'f',
15
+ nargs: 1
16
+ },
17
+ "project-directory": {
18
+ describe: "The root directory of project.\n Current working directory if not provided.\n",
19
+ type: 'string',
20
+ alias: 'd',
21
+ nargs: 1
22
+ },
23
+ "zip-file-name": {
24
+ describe: "The name of zip file to be created",
25
+ type: 'string',
26
+ default: 'lambda.zip',
27
+ alias: 'z',
28
+ nargs: 1
29
+ }
30
+ }
31
+
32
+ function display(argv) {
33
+ console.log(`\nBuilding kumohub artefacts with following parameters: \n`);
34
+ console.log('project-directory: %s', argv["project-directory"]||'');
35
+ console.log('flow-file-name: %s', argv["flow-file-name"]||'');
36
+ console.log('zip-file-name: %s', argv["zip-file-name"]||'');
37
+ }
38
+
39
+ exports.handler = function (argv) {
40
+ display(argv);
41
+
42
+ try {
43
+ const { build } = require('@kumologica/builder');
44
+ build('kumohub', argv);
45
+ } catch (e) {
46
+ console.log(`${e.message}`);
47
+ process.exit(1);
48
+ }
49
+ }
@@ -0,0 +1,6 @@
1
+ exports.command = 'build <provider>'
2
+ exports.desc = 'Build kumologica flow binaries'
3
+ exports.builder = function (yargs) {
4
+ return yargs.commandDir('build-commands')
5
+ }
6
+ exports.handler = function (argv) {}
@@ -0,0 +1,49 @@
1
+ const pathlib = require('path');
2
+ const { prompt, Select } = require('enquirer');
3
+ const { logNotice, logError } = require('../../utils/logger');
4
+ const { downloadTemplateFromRepo, listAvailableTemplates } = require('../../utils/download-template-from-repo');
5
+
6
+ async function createProjectIteratively() {
7
+ let availableTemplates;
8
+ try {
9
+ availableTemplates = await listAvailableTemplates();
10
+ } catch (err) {
11
+ logError('Error found while retrieving the list of available templates. Please ensure that your internet connection is active and try again');
12
+ process.exit(1);
13
+ }
14
+ // Project name
15
+ const projectNameResponse = await prompt({
16
+ type: 'input',
17
+ name: 'projectName',
18
+ message: 'Enter the name for the project'
19
+ });
20
+ let aProjectName = projectNameResponse.projectName;
21
+
22
+ // Target Path
23
+ const directoryResponse = await prompt({
24
+ type: 'input',
25
+ name: 'directory',
26
+ message: 'Enter the path where the project will be created '
27
+ });
28
+ let aProjectPath = directoryResponse.directory;
29
+
30
+ // Template name
31
+ const promptTemplate = new Select({
32
+ name: 'template',
33
+ message: 'Pick one of the available templates',
34
+ choices: availableTemplates
35
+ });
36
+
37
+ let aTemplateName = await promptTemplate.run();
38
+
39
+ try {
40
+ await downloadTemplateFromRepo(undefined, aTemplateName, aProjectPath, aProjectName);
41
+ logNotice(`Successfully created project: ${pathlib.join(aProjectPath, aProjectName)}`)
42
+ } catch (err) {
43
+ logError(`Error found while creating project due to: ${err.message}`);
44
+ process.exit(1);
45
+ }
46
+ }
47
+
48
+
49
+ module.exports = createProjectIteratively;
@@ -0,0 +1,5 @@
1
+ const createProjectIteratively = require('./create-project-iteratively');
2
+
3
+ module.exports = {
4
+ createProjectIteratively
5
+ }
@@ -0,0 +1,66 @@
1
+ const pathlib = require('path');
2
+ const { codegen } = require('@kumologica/builder');
3
+
4
+ const { logNotice, logError } = require('../utils/logger');
5
+ const { downloadTemplateFromRepo, isPlainGitURL } = require('../utils/download-template-from-repo');
6
+ const { createProjectIteratively } = require('./create-commands');
7
+
8
+ exports.command = 'create [options]'
9
+ exports.builder = (yargs) => {
10
+ yargs.option(`path`, {
11
+ describe: "The project path where the project will be created",
12
+ // demandOption: "The path is required.",
13
+ type: 'string',
14
+ alias: 'p',
15
+ nargs: 1
16
+ })
17
+ yargs.option(`template`, {
18
+ describe: `Template for the project`,
19
+ type: 'string',
20
+ alias: 't',
21
+ nargs: 1
22
+ })
23
+ }
24
+
25
+
26
+ exports.desc = 'Create a kumologica project. Do not pass any options to create iteratively.'
27
+ exports.handler = async ({ path, template }) => {
28
+ const { version } = require('../../../sdk/package.json');
29
+
30
+ if (!path && !template) {
31
+ await createProjectIteratively();
32
+ } else if (!path && template) {
33
+ try {
34
+ await downloadTemplateFromRepo(undefined, template, process.cwd(), template);
35
+ logNotice(`Successfully created project: ${pathlib.join(process.cwd(), template)}`);
36
+ } catch (e) {
37
+ logError(e.message);
38
+ }
39
+ } else if (path && !template) {
40
+ try {
41
+ codegen.generateBoilerplateProject({
42
+ basePath: process.cwd(),
43
+ projectName: path,
44
+ runtimeVersion: version
45
+ });
46
+ logNotice(`Successfully created project: ${pathlib.join(process.cwd(), path)}`);
47
+ } catch (e) {
48
+ logError(e.message);
49
+ }
50
+ } else if (path && template) {
51
+ path = pathlib.resolve(path);
52
+ let projectPath = pathlib.dirname(path);
53
+ let projectName = pathlib.basename(path);
54
+ try {
55
+ if (isPlainGitURL(template)) {
56
+ await downloadTemplateFromRepo(template, undefined, projectPath, projectName);
57
+ } else {
58
+ await downloadTemplateFromRepo(undefined, template, projectPath, projectName);
59
+ }
60
+ logNotice(`Successfully created project: ${path}`);
61
+ } catch (e) {
62
+ logError(e.message);
63
+ }
64
+ }
65
+
66
+ }
@@ -0,0 +1,114 @@
1
+ exports.command = 'kumohub';
2
+ exports.desc = `Deploy kumologica flow to kumohub.io account`;
3
+
4
+ exports.builder = {
5
+ "flow-file-name": {
6
+ describe: "The name of kumologica flow file.\n Auto search if not provided.\n",
7
+ type: 'string',
8
+ alias: 'f',
9
+ nargs: 1
10
+ },
11
+ "service-name": {
12
+ describe: "The name of service.\n flow file name without extension if not provided.\n Service name will be sanitized to be compatible with aws lambda name restrictions.\n",
13
+ type: 'string',
14
+ nargs: 1
15
+ },
16
+ "project-directory": {
17
+ describe: "The root directory of project.\n Process working directory if not provided.\n",
18
+ type: 'string',
19
+ alias: 'd',
20
+ nargs: 1
21
+ },
22
+ "environment": {
23
+ describe: `Environment variables, JSON Syntax: '{"Variables": {"key": "value", ...}}'\n`,
24
+ type: 'string',
25
+ nargs: 1
26
+ },
27
+ "account": {
28
+ describe: "The name of kumohub.io account\n",
29
+ type: 'string',
30
+ required: true,
31
+ alias: 'a',
32
+ nargs: 1
33
+ },
34
+ "username": {
35
+ describe: "The username to login to kumohub.io account\n",
36
+ type: 'string',
37
+ required: true,
38
+ alias: 'u',
39
+ nargs: 1
40
+ },
41
+ "password": {
42
+ describe: "The username password to login to kumohub.io account\n",
43
+ type: 'string',
44
+ required: true,
45
+ alias: 'p',
46
+ nargs: 1
47
+ },
48
+ "workspace": {
49
+ describe: "The name of the workspace where flow to be deployed.\n",
50
+ type: 'string',
51
+ required: true,
52
+ alias: 'w',
53
+ nargs: 1
54
+ },
55
+ "stage": {
56
+ describe: "The name of the stage where flow to be deployed\n",
57
+ type: 'string',
58
+ required: true,
59
+ alias: 's',
60
+ nargs: 1
61
+ },
62
+ "policy": {
63
+ describe: "The name of security policy to assign to the flow.\n",
64
+ type: 'string',
65
+ required: true,
66
+ default: "Public",
67
+ nargs: 1
68
+ },
69
+ "memory": {
70
+ describe: "The amount of memory (MB) to be allocated to the flow. 128 MB to 10240 MB\n",
71
+ type: 'string',
72
+ nargs: 1,
73
+ default: "512"
74
+ },
75
+ "timeout": {
76
+ describe: "The amount of seconds flow should be run before timing out. Up to 900 seconds\n",
77
+ type: 'string',
78
+ nargs: 1,
79
+ default: "30"
80
+ },
81
+ "description": {
82
+ describe: "The description of function.\n",
83
+ type: 'string',
84
+ nargs: 1
85
+ }
86
+ }
87
+
88
+ function display(argv) {
89
+ console.log(`\nDeploying flow to kumohub.io with following parameters: \n`);
90
+ console.log('project-directory: %s', argv["project-directory"] || '');
91
+ console.log('flow-file-name: %s', argv["flow-file-name"] || '');
92
+ console.log('service-name: %s', argv["service-name"] || '');
93
+ console.log('environment vars: %s', argv["environment"] || '');
94
+ console.log('username: %s', argv["username"] || '');
95
+ console.log('password: %s', argv["password"]? "provided": "missing");
96
+ console.log('workspace: %s', argv["workspace"] || '');
97
+ console.log('stage: %s', argv["stage"] || '');
98
+ console.log('policy: %s', argv["policy"] || '');
99
+ console.log('memory: %s', argv["memory"] || '');
100
+ console.log('timeout: %s', argv["timeout"] || '');
101
+ console.log('description: %s', argv["description"] || '');
102
+ }
103
+
104
+ exports.handler = function (argv) {
105
+ display(argv);
106
+
107
+ try {
108
+ const { deploy } = require('@kumologica/builder');
109
+ deploy('kumohub', argv);
110
+ } catch (e) {
111
+ console.log(`${e.message}`);
112
+ process.exit(1);
113
+ }
114
+ }
@@ -0,0 +1,6 @@
1
+ exports.command = 'deploy <provider>'
2
+ exports.desc = 'Deploy kumologica flow binaries'
3
+ exports.builder = function (yargs) {
4
+ return yargs.commandDir('deploy-commands')
5
+ }
6
+ exports.handler = function (argv) {}
@@ -0,0 +1,60 @@
1
+ exports.command = 'html';
2
+ exports.desc = `Generates html documentation of kumologica flow.`;
3
+
4
+ exports.builder = {
5
+ "project-directory": {
6
+ describe: "\nThe root directory of kumologica project. Current working directory used if not provided.",
7
+ type: 'string',
8
+ alias: 'd',
9
+ nargs: 1
10
+ },
11
+ "flow-file-name": {
12
+ describe: "\nThe name of kumologica flow file to be created, must end with .json extension. Auto search if not provided.",
13
+ type: 'string',
14
+ alias: 'f',
15
+ nargs: 1
16
+ },
17
+ "documentation-directory": {
18
+ describe: "\nThe directory where documentation will be created.",
19
+ type: 'string',
20
+ alias: 'c',
21
+ default: 'docs',
22
+ nargs: 1
23
+ }
24
+ }
25
+
26
+ function validate(argv) {
27
+ const chalk = require('chalk');
28
+
29
+ if (argv["flow-file-name"] && !argv["flow-file-name"].endsWith('.json')) {
30
+ console.log(`${chalk.redBright("Validation Error: flow-file-name must end with .json extension.")}`);
31
+ process.exit(1);
32
+ }
33
+ }
34
+ function display(argv) {
35
+ console.log('Parameters:');
36
+ console.log(' documentation-directory: %s', argv["documentation-directory"]||'');
37
+ console.log(' project-directory: %s', argv["project-directory"]||'');
38
+ console.log(' flow-file-name: %s', argv["flow-file-name"]||'');
39
+ }
40
+
41
+ exports.handler = async function (argv) {
42
+ console.log('\nGenerating html documentation\n');
43
+ display(argv);
44
+ validate(argv);
45
+
46
+ const chalk = require('chalk');
47
+
48
+ try {
49
+ const { doc } = require('@kumologica/builder');
50
+ const docsDirectory = doc("html", argv);
51
+ console.log(chalk.greenBright('Documentation generated successfully:'));
52
+ console.log(chalk.greenBright(docsDirectory));
53
+
54
+ process.exit(0);
55
+ } catch (e) {
56
+
57
+ console.log(`${chalk.redBright(e.message)}`);
58
+ process.exit(1);
59
+ }
60
+ }
@@ -0,0 +1,6 @@
1
+ exports.command = 'doc <format>'
2
+ exports.desc = 'Generate documentation for kumologica flow'
3
+ exports.builder = function (yargs) {
4
+ return yargs.commandDir('doc-commands')
5
+ }
6
+ exports.handler = function (argv) {}