@sme.up/kokos-sdk-node 0.0.1

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 (81) hide show
  1. package/README.md +12 -0
  2. package/bin/kokos.js +26 -0
  3. package/docker/restapi/Dockerfile +14 -0
  4. package/docs/.nojekyll +1 -0
  5. package/docs/assets/highlight.css +78 -0
  6. package/docs/assets/main.js +58 -0
  7. package/docs/assets/search.js +1 -0
  8. package/docs/assets/style.css +1338 -0
  9. package/docs/classes/ExecuteFunPayload.html +108 -0
  10. package/docs/classes/ExecutionContext.html +101 -0
  11. package/docs/classes/Fun.html +171 -0
  12. package/docs/classes/FunObject.html +115 -0
  13. package/docs/classes/User.html +122 -0
  14. package/docs/enums/SmeupDataStructureType.html +95 -0
  15. package/docs/index.html +100 -0
  16. package/docs/interfaces/KokosService.html +88 -0
  17. package/docs/interfaces/KokosServiceMethods.html +83 -0
  18. package/docs/interfaces/KokosServiceModule.html +88 -0
  19. package/docs/interfaces/SmeupCell.html +106 -0
  20. package/docs/interfaces/SmeupColumn.html +210 -0
  21. package/docs/interfaces/SmeupDataStructure.html +91 -0
  22. package/docs/interfaces/SmeupMessage.html +102 -0
  23. package/docs/interfaces/SmeupObject.html +153 -0
  24. package/docs/interfaces/SmeupRow.html +93 -0
  25. package/docs/interfaces/SmeupTable.html +105 -0
  26. package/docs/interfaces/SmeupTree.html +112 -0
  27. package/docs/interfaces/SmeupTreeNode.html +109 -0
  28. package/docs/modules.html +93 -0
  29. package/docs/types/SmeupMessageGravity.html +61 -0
  30. package/docs/variables/SMEUP_MESSAGE_GRAVITY.html +72 -0
  31. package/init/JS_00_01.txt +64 -0
  32. package/lib/caller/serviceCaller.d.ts +32 -0
  33. package/lib/caller/serviceCaller.js +66 -0
  34. package/lib/entrypoint/restapi/index.d.ts +1 -0
  35. package/lib/entrypoint/restapi/index.js +110 -0
  36. package/lib/index.d.ts +9 -0
  37. package/lib/index.js +9 -0
  38. package/lib/services/JS_00_01.d.ts +3 -0
  39. package/lib/services/JS_00_01.js +67 -0
  40. package/lib/types/data-structures/smeupDataStructure.d.ts +32 -0
  41. package/lib/types/data-structures/smeupDataStructure.js +19 -0
  42. package/lib/types/data-structures/smeupObject.d.ts +21 -0
  43. package/lib/types/data-structures/smeupObject.js +1 -0
  44. package/lib/types/data-structures/smeupTable.d.ts +66 -0
  45. package/lib/types/data-structures/smeupTable.js +1 -0
  46. package/lib/types/data-structures/smeupTree.d.ts +21 -0
  47. package/lib/types/data-structures/smeupTree.js +1 -0
  48. package/lib/types/exceptions/application.d.ts +8 -0
  49. package/lib/types/exceptions/application.js +12 -0
  50. package/lib/types/exceptions/execution.d.ts +7 -0
  51. package/lib/types/exceptions/execution.js +10 -0
  52. package/lib/types/exceptions/validation.d.ts +7 -0
  53. package/lib/types/exceptions/validation.js +9 -0
  54. package/lib/types/general.d.ts +65 -0
  55. package/lib/types/general.js +158 -0
  56. package/lib/utils/path.d.ts +5 -0
  57. package/lib/utils/path.js +28 -0
  58. package/package.json +63 -0
  59. package/scripts/build.js +26 -0
  60. package/scripts/init.js +95 -0
  61. package/scripts/restapi/build-image-restapi.js +60 -0
  62. package/scripts/restapi/dev.js +30 -0
  63. package/scripts/restapi/start.js +14 -0
  64. package/swagger/favicon-16x16.png +0 -0
  65. package/swagger/favicon-32x32.png +0 -0
  66. package/swagger/index.html +61 -0
  67. package/swagger/oauth2-redirect.html +72 -0
  68. package/swagger/openapi.yaml +130 -0
  69. package/swagger/swagger-ui-bundle.js +92 -0
  70. package/swagger/swagger-ui-bundle.js.map +1 -0
  71. package/swagger/swagger-ui-es-bundle-core.js +9 -0
  72. package/swagger/swagger-ui-es-bundle-core.js.map +1 -0
  73. package/swagger/swagger-ui-es-bundle.js +92 -0
  74. package/swagger/swagger-ui-es-bundle.js.map +1 -0
  75. package/swagger/swagger-ui-standalone-preset.js +22 -0
  76. package/swagger/swagger-ui-standalone-preset.js.map +1 -0
  77. package/swagger/swagger-ui.css +4 -0
  78. package/swagger/swagger-ui.css.map +1 -0
  79. package/swagger/swagger-ui.js +9 -0
  80. package/swagger/swagger-ui.js.map +1 -0
  81. package/tsconfig.json +24 -0
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env node
2
+
3
+ import path from "path";
4
+ import fs from "fs";
5
+ import url from "url";
6
+
7
+ /**
8
+ * INITIALIZER SCRIPT
9
+ *
10
+ * syntax: npx @sme.up/kokos-template-node init [PROJECT_NAME]
11
+ *
12
+ * - create package.json
13
+ * - create tsconfig.json
14
+ * - create src/service/JS_00_01 example service
15
+ */
16
+
17
+ // constant
18
+ const __filename = url.fileURLToPath(import.meta.url);
19
+ const __dirname = path.dirname(__filename);
20
+
21
+ try {
22
+ // root path
23
+ const rootPath = process.cwd();
24
+
25
+ const projectName = process.argv[3];
26
+ if (!projectName) {
27
+ console.error(
28
+ "Error: project name not defined \nSyntax: npx @sme.up/kokos-template-node init [PROJECT_NAME]"
29
+ );
30
+ process.exit();
31
+ }
32
+
33
+ const projectPath = path.resolve(rootPath, projectName);
34
+
35
+ // create folder named as projecName
36
+ fs.mkdirSync(projectPath);
37
+
38
+ // read package.json, tsconfig.json, README.md
39
+ const packageJson = JSON.parse(
40
+ fs.readFileSync(path.resolve(__dirname, "../package.json"))
41
+ );
42
+ const tsconfigJson = JSON.parse(fs.readFileSync(
43
+ path.resolve(__dirname, "../tsconfig.json")
44
+ ));
45
+ const readme = fs.readFileSync(path.resolve(__dirname, "../README.md"));
46
+
47
+ // create package json
48
+ const projectPackageJson = {
49
+ name: projectName,
50
+ version: "0.0.1",
51
+ description: "Kokos Micro Executor Node.js",
52
+ type: "module",
53
+ scripts: {
54
+ build: "kokos build",
55
+ "build-image:restapi": "kokos build-image:restapi",
56
+ "dev:restapi": "kokos dev:restapi",
57
+ "start:restapi": "kokos start:restapi",
58
+ },
59
+ dependencies: {
60
+ "@sme.up/kokos-template-node": packageJson.version,
61
+ },
62
+ };
63
+ // create package.json
64
+ const packageJsonStream = fs.createWriteStream(
65
+ path.resolve(projectPath, "package.json")
66
+ );
67
+ packageJsonStream.write(JSON.stringify(projectPackageJson, null, "\t"));
68
+ packageJsonStream.end();
69
+ // create tsconfig.json
70
+ const tsconfigStream = fs.createWriteStream(
71
+ path.resolve(projectPath, "tsconfig.json")
72
+ );
73
+ tsconfigStream.write(JSON.stringify(tsconfigJson, null, "\t"));
74
+ tsconfigStream.end();
75
+ // create README.md file
76
+ const readmeStream = fs.createWriteStream(
77
+ path.resolve(projectPath, "README.md")
78
+ );
79
+ readmeStream.write(readme);
80
+ readmeStream.end();
81
+
82
+ // create src folder
83
+ const srcFolder = path.resolve(projectPath, "src");
84
+ fs.mkdirSync(srcFolder);
85
+ // create services folder
86
+ const serviceFolder = path.resolve(srcFolder, "services");
87
+ fs.mkdirSync(serviceFolder);
88
+ // load content from JS_00_01.txt
89
+ // Copy /init/JS_00_01.txt file to [ROOT]/src/services/JS_00_01.ts
90
+ const txtFile = path.resolve(__dirname, "../init/JS_00_01.txt");
91
+ const tsFile = path.resolve(serviceFolder, "JS_00_01.ts");
92
+ fs.copyFileSync(txtFile, tsFile);
93
+ } catch (err) {
94
+ console.error(err);
95
+ }
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { exec } from "child_process";
4
+ import { getProjectRoot } from "../../lib/utils/path.js";
5
+ import { readFile } from "fs/promises";
6
+ import path from "path";
7
+ import fs from "fs";
8
+
9
+ /**
10
+ * BUILD IMAGE FOR REST API
11
+ */
12
+
13
+ try {
14
+ // dockerfile path
15
+ const dockerfilePath = path.resolve(
16
+ `${getProjectRoot()}/node_modules/@sme.up/kokos-template-node/docker/restapi/Dockerfile`
17
+ );
18
+ const destinationDockerfilePath = `${getProjectRoot()}/Dockerfile`;
19
+
20
+ // copy dockerfile to project root
21
+ fs.copyFileSync(dockerfilePath, destinationDockerfilePath);
22
+
23
+ // load package json
24
+ const packageJson = JSON.parse(
25
+ await readFile(new URL(getProjectRoot() + "/package.json", import.meta.url))
26
+ );
27
+
28
+ // get image name based on project name
29
+ let imageName;
30
+ if (packageJson.name.includes("@")) {
31
+ imageName = packageJson.name.substring(packageJson.name.indexOf("/") + 1);
32
+ } else {
33
+ imageName = packageJson.name;
34
+ }
35
+
36
+ // start production mode
37
+ console.log(`Start build image for REST API: ${imageName}`);
38
+
39
+ // build project with typescript compiler
40
+ const dockerBuild = exec(`docker build -t ${imageName} .`);
41
+
42
+ // redirect docker build stdout to standard output
43
+ dockerBuild.stdout.pipe(process.stdout);
44
+ // redirect docker build stderr to standard output
45
+ dockerBuild.stderr.pipe(process.stderr);
46
+
47
+ if (dockerBuild.pid) {
48
+ console.log(
49
+ `Building image...\nPress CTRL+C to exit\nPID: ${dockerBuild.pid}`
50
+ );
51
+ }
52
+
53
+ dockerBuild.on("exit", function () {
54
+ // delete dockerfile from project root
55
+ fs.unlinkSync(destinationDockerfilePath);
56
+ console.log("Image build successfull");
57
+ });
58
+ } catch (err) {
59
+ console.error(err);
60
+ }
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { exec } from "child_process";
4
+
5
+ /**
6
+ * DEVELOPMENT MODE
7
+ */
8
+
9
+ // set environment variables
10
+ process.env.NODE_ENV = "development";
11
+
12
+ // start nodemon
13
+ const devServer = exec(
14
+ "NODE_ENV=development nodemon --watch src/**/* -e ts,js --exec node --experimental-specifier-resolution=node --loader ts-node/esm node_modules/@sme.up/kokos-template-node/lib/entrypoint/restapi/index.js"
15
+ );
16
+
17
+ // redirect docker build stdout to standard output
18
+ devServer.stdout.pipe(process.stdout);
19
+ // redirect docker build stderr to standard output
20
+ devServer.stderr.pipe(process.stderr);
21
+
22
+ if (!devServer.pid) {
23
+ console.log(
24
+ `Development mode active \nPress CTRL+C to exit\nPID: ${devServer.pid}`
25
+ );
26
+ }
27
+
28
+ devServer.on("exit", function () {
29
+ console.log("Development server terminated");
30
+ });
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * PRODUCTION MODE
5
+ */
6
+
7
+ // start production mode
8
+ console.log("Start production mode");
9
+
10
+ // set environment variables
11
+ process.env.NODE_ENV = "production";
12
+
13
+ // start rest api entrypoint
14
+ import("../../lib/entrypoint/restapi/index.js");
Binary file
Binary file
@@ -0,0 +1,61 @@
1
+ <!-- HTML for static distribution bundle build -->
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <title>Swagger UI</title>
7
+ <link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
8
+ <link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
9
+ <link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
10
+ <style>
11
+ html
12
+ {
13
+ box-sizing: border-box;
14
+ overflow: -moz-scrollbars-vertical;
15
+ overflow-y: scroll;
16
+ }
17
+
18
+ *,
19
+ *:before,
20
+ *:after
21
+ {
22
+ box-sizing: inherit;
23
+ }
24
+
25
+ body
26
+ {
27
+ margin:0;
28
+ background: #fafafa;
29
+ }
30
+ </style>
31
+ </head>
32
+
33
+ <body>
34
+ <div id="swagger-ui"></div>
35
+
36
+ <script src="./swagger-ui-bundle.js"> </script>
37
+ <script src="./swagger-ui-standalone-preset.js"> </script>
38
+ <script>
39
+ window.onload = function() {
40
+ var pathArray = window.location.pathname.split('/');
41
+
42
+ // Build a system
43
+ const ui = SwaggerUIBundle({
44
+ url: window.location.origin + "/" + pathArray[1] + "/openapi.yaml" ,
45
+ dom_id: '#swagger-ui',
46
+ deepLinking: true,
47
+ presets: [
48
+ SwaggerUIBundle.presets.apis,
49
+ SwaggerUIStandalonePreset
50
+ ],
51
+ plugins: [
52
+ SwaggerUIBundle.plugins.DownloadUrl
53
+ ],
54
+ layout: "StandaloneLayout"
55
+ })
56
+
57
+ window.ui = ui
58
+ }
59
+ </script>
60
+ </body>
61
+ </html>
@@ -0,0 +1,72 @@
1
+ <!doctype html>
2
+ <html lang="en-US">
3
+ <title>Swagger UI: OAuth2 Redirect</title>
4
+ <body>
5
+ </body>
6
+ </html>
7
+ <script>
8
+ 'use strict';
9
+ function run () {
10
+ var oauth2 = window.opener.swaggerUIRedirectOauth2;
11
+ var sentState = oauth2.state;
12
+ var redirectUrl = oauth2.redirectUrl;
13
+ var isValid, qp, arr;
14
+
15
+ if (/code|token|error/.test(window.location.hash)) {
16
+ qp = window.location.hash.substring(1);
17
+ } else {
18
+ qp = location.search.substring(1);
19
+ }
20
+
21
+ arr = qp.split("&")
22
+ arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';})
23
+ qp = qp ? JSON.parse('{' + arr.join() + '}',
24
+ function (key, value) {
25
+ return key === "" ? value : decodeURIComponent(value)
26
+ }
27
+ ) : {}
28
+
29
+ isValid = qp.state === sentState
30
+
31
+ if ((
32
+ oauth2.auth.schema.get("flow") === "accessCode"||
33
+ oauth2.auth.schema.get("flow") === "authorizationCode"
34
+ ) && !oauth2.auth.code) {
35
+ if (!isValid) {
36
+ oauth2.errCb({
37
+ authId: oauth2.auth.name,
38
+ source: "auth",
39
+ level: "warning",
40
+ message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
41
+ });
42
+ }
43
+
44
+ if (qp.code) {
45
+ delete oauth2.state;
46
+ oauth2.auth.code = qp.code;
47
+ oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
48
+ } else {
49
+ let oauthErrorMsg
50
+ if (qp.error) {
51
+ oauthErrorMsg = "["+qp.error+"]: " +
52
+ (qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
53
+ (qp.error_uri ? "More info: "+qp.error_uri : "");
54
+ }
55
+
56
+ oauth2.errCb({
57
+ authId: oauth2.auth.name,
58
+ source: "auth",
59
+ level: "error",
60
+ message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
61
+ });
62
+ }
63
+ } else {
64
+ oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
65
+ }
66
+ window.close();
67
+ }
68
+
69
+ window.addEventListener('DOMContentLoaded', function () {
70
+ run();
71
+ });
72
+ </script>
@@ -0,0 +1,130 @@
1
+ ---
2
+ openapi: "3.0.0"
3
+ info:
4
+ title: Kokos Micro Executor (Node) API
5
+ description: Api Docs
6
+ version: 2.0.0
7
+ servers:
8
+ - url: /
9
+ paths:
10
+ /api/v1/livez:
11
+ get:
12
+ tags:
13
+ - health
14
+ operationId: Livez
15
+ responses:
16
+ default:
17
+ description: no description
18
+ "200":
19
+ description: OK
20
+ /api/v1/readyz:
21
+ get:
22
+ tags:
23
+ - health
24
+ operationId: Readyz
25
+ responses:
26
+ default:
27
+ description: no description
28
+ "200":
29
+ description: OK
30
+ /api/v1/executeFun:
31
+ post:
32
+ tags:
33
+ - execution
34
+ operationId: ExecuteFun
35
+ requestBody:
36
+ content:
37
+ application/json:
38
+ schema:
39
+ $ref: "#/components/schemas/executeFunPayload"
40
+ responses:
41
+ default:
42
+ description: SmeupDataStructure
43
+ "200":
44
+ description: OK
45
+ components:
46
+ schemas:
47
+ executeFunPayload:
48
+ type: object
49
+ properties:
50
+ fun:
51
+ type: object
52
+ properties:
53
+ component:
54
+ type: string
55
+ service:
56
+ type: string
57
+ function:
58
+ type: string
59
+ obj1:
60
+ type: object
61
+ properties:
62
+ t:
63
+ type: string
64
+ p:
65
+ type: string
66
+ k:
67
+ type: string
68
+ obj2:
69
+ type: object
70
+ properties:
71
+ t:
72
+ type: string
73
+ p:
74
+ type: string
75
+ k:
76
+ type: string
77
+ obj3:
78
+ type: object
79
+ properties:
80
+ t:
81
+ type: string
82
+ p:
83
+ type: string
84
+ k:
85
+ type: string
86
+ obj4:
87
+ type: object
88
+ properties:
89
+ t:
90
+ type: string
91
+ p:
92
+ type: string
93
+ k:
94
+ type: string
95
+ obj5:
96
+ type: object
97
+ properties:
98
+ t:
99
+ type: string
100
+ p:
101
+ type: string
102
+ k:
103
+ type: string
104
+ obj6:
105
+ type: object
106
+ properties:
107
+ t:
108
+ type: string
109
+ p:
110
+ type: string
111
+ k:
112
+ type: string
113
+ P:
114
+ type: string
115
+ INPUT:
116
+ type: string
117
+ context:
118
+ type: object
119
+ properties:
120
+ user:
121
+ type: object
122
+ properties:
123
+ sessionId:
124
+ type: string
125
+ username:
126
+ type: string
127
+ environment:
128
+ type: string
129
+ device:
130
+ type: string