@coherentglobal/spark-execute-sdk 0.3.0

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 (104) hide show
  1. package/.babelrc +12 -0
  2. package/.eslintrc.json +21 -0
  3. package/.github/workflows/build-publish.yml +46 -0
  4. package/.prettierrc +0 -0
  5. package/README.md +92 -0
  6. package/dist/browser.js +6925 -0
  7. package/examples/UsingBearerTokenFNAsync/bearerTokenExample.js +22 -0
  8. package/examples/UsingBearerTokenFNAsync/config.js +88 -0
  9. package/examples/UsingBearerTokenFNAsync/index.html +205 -0
  10. package/examples/UsingBearerTokenFNAsync/modelCInput.json +15 -0
  11. package/examples/UsingBearerTokenFNAsync/models/Model_C.zip +0 -0
  12. package/examples/UsingBearerTokenString/bearerTokenExample.js +22 -0
  13. package/examples/UsingBearerTokenString/config.js +182 -0
  14. package/examples/UsingBearerTokenString/index.html +191 -0
  15. package/examples/UsingBearerTokenString/modelCInput.json +15 -0
  16. package/examples/UsingBearerTokenString/models/Model_C.zip +0 -0
  17. package/examples/UsingSyntheticKeyFNAsync/bearerTokenExample.js +22 -0
  18. package/examples/UsingSyntheticKeyFNAsync/config.js +195 -0
  19. package/examples/UsingSyntheticKeyFNAsync/index.html +205 -0
  20. package/examples/UsingSyntheticKeyFNAsync/modelCInput.json +15 -0
  21. package/examples/UsingSyntheticKeyFNAsync/models/Model_C.zip +0 -0
  22. package/examples/UsingSyntheticKeyString/bearerTokenExample.js +22 -0
  23. package/examples/UsingSyntheticKeyString/config.js +181 -0
  24. package/examples/UsingSyntheticKeyString/index.html +192 -0
  25. package/examples/UsingSyntheticKeyString/modelCInput.json +15 -0
  26. package/examples/UsingSyntheticKeyString/models/Model_C.zip +0 -0
  27. package/examples/asyncFunctionModel/config.js +96 -0
  28. package/examples/asyncFunctionModel/modelCInput.json +15 -0
  29. package/examples/asyncFunctionModel/models/Model_C.zip +0 -0
  30. package/examples/asyncFunctionModel/node.js +125 -0
  31. package/examples/asyncFunctionModel/tool.js +17 -0
  32. package/examples/base64Model/config.js +96 -0
  33. package/examples/base64Model/modelCInput.json +15 -0
  34. package/examples/base64Model/models/Model_C.zip +0 -0
  35. package/examples/base64Model/node.js +125 -0
  36. package/examples/base64Model/tool.js +17 -0
  37. package/examples/base64modelBrowser/config.js +96 -0
  38. package/examples/base64modelBrowser/index.html +194 -0
  39. package/examples/base64modelBrowser/modelCInput.json +15 -0
  40. package/examples/base64modelBrowser/models/Model_C.zip +0 -0
  41. package/examples/base64modelBrowser/models/base64model.txt +1 -0
  42. package/examples/base64modelBrowser/node.js +126 -0
  43. package/examples/base64modelBrowser/tool.js +17 -0
  44. package/examples/binary/config.js +96 -0
  45. package/examples/binary/modelCInput.json +15 -0
  46. package/examples/binary/models/Model_C.zip +0 -0
  47. package/examples/binary/models/binary.txt +1 -0
  48. package/examples/binary/node.js +131 -0
  49. package/examples/binary/tool.js +18 -0
  50. package/examples/functionModel/config.js +96 -0
  51. package/examples/functionModel/modelCInput.json +15 -0
  52. package/examples/functionModel/models/Model_C.zip +0 -0
  53. package/examples/functionModel/node.js +138 -0
  54. package/examples/functionModel/tool.js +17 -0
  55. package/examples/nodejs/node.js +250 -0
  56. package/examples/nodejs/test_models/Archive.zip +0 -0
  57. package/examples/nodejs/test_models/BlackScholes.zip +0 -0
  58. package/examples/nodejs/test_models/Model_A.zip +0 -0
  59. package/examples/nodejs/test_models/Par7.zip +0 -0
  60. package/package.json +79 -0
  61. package/src/browser.js +198 -0
  62. package/src/error.js +87 -0
  63. package/src/helpers/utils.js +79 -0
  64. package/src/logger.js +3 -0
  65. package/src/models.js +26 -0
  66. package/src/node.js +254 -0
  67. package/src/resolver/externalResolver.js +118 -0
  68. package/src/services/entityStore.js +260 -0
  69. package/src/services/resolver.js +134 -0
  70. package/src/services/spark.js +80 -0
  71. package/src/tenant_resolver/externalResolver_coherent.js +118 -0
  72. package/src/tenant_resolver/externalResolver_test.js +118 -0
  73. package/src/validate.js +38 -0
  74. package/test/config.test.js +124 -0
  75. package/test/mock-data/dummy-config.json +102 -0
  76. package/test/mock-data/valid.json +21 -0
  77. package/test/spark-sdk.test.js +28 -0
  78. package/tsconfig.json +105 -0
  79. package/types/browser.d.ts +72 -0
  80. package/types/browser.d.ts.map +1 -0
  81. package/types/error.d.ts +42 -0
  82. package/types/error.d.ts.map +1 -0
  83. package/types/helpers/utils.d.ts +11 -0
  84. package/types/helpers/utils.d.ts.map +1 -0
  85. package/types/logger.d.ts +3 -0
  86. package/types/logger.d.ts.map +1 -0
  87. package/types/models.d.ts +8 -0
  88. package/types/models.d.ts.map +1 -0
  89. package/types/node.d.ts +78 -0
  90. package/types/node.d.ts.map +1 -0
  91. package/types/resolver/externalResolver.d.ts +2 -0
  92. package/types/resolver/externalResolver.d.ts.map +1 -0
  93. package/types/services/entityStore.d.ts +51 -0
  94. package/types/services/entityStore.d.ts.map +1 -0
  95. package/types/services/resolver.d.ts +20 -0
  96. package/types/services/resolver.d.ts.map +1 -0
  97. package/types/services/spark.d.ts +6 -0
  98. package/types/services/spark.d.ts.map +1 -0
  99. package/types/tenant_resolver/externalResolver_coherent.d.ts +2 -0
  100. package/types/tenant_resolver/externalResolver_coherent.d.ts.map +1 -0
  101. package/types/tenant_resolver/externalResolver_test.d.ts +2 -0
  102. package/types/tenant_resolver/externalResolver_test.d.ts.map +1 -0
  103. package/types/validate.d.ts +4 -0
  104. package/types/validate.d.ts.map +1 -0
package/.babelrc ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "@babel/preset-env",
5
+ {
6
+ "targets": {
7
+ "esmodules": true
8
+ }
9
+ }
10
+ ]
11
+ ]
12
+ }
package/.eslintrc.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "extends": [
3
+ "airbnb/base",
4
+ "prettier",
5
+ "plugin:node/recommended",
6
+ "plugin:mocha/recommended"
7
+ ],
8
+ "parserOptions": {
9
+ "ecmaVersion": 2020
10
+ },
11
+ "plugins": ["prettier", "mocha"],
12
+ "rules": {
13
+ "prettier/prettier": "error",
14
+ "no-unused-vars": "warn",
15
+ "no-console": "off",
16
+ "func-names": "off",
17
+ "no-process-exit": "off",
18
+ "object-shorthand": "off",
19
+ "class-methods-use-this": "off"
20
+ }
21
+ }
@@ -0,0 +1,46 @@
1
+ name: Build and Publish Action
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - dev
7
+
8
+ jobs:
9
+ build:
10
+ name: Build & Publish
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v3
15
+
16
+ - name: Cache node modules
17
+ id: cache-npm
18
+ uses: actions/cache@v3
19
+ env:
20
+ cache-name: cache-node-modules
21
+ with:
22
+ # npm cache files are stored in `~/.npm` on Linux/macOS
23
+ path: ~/.npm
24
+ key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
25
+ restore-keys: |
26
+ ${{ runner.os }}-build-${{ env.cache-name }}-
27
+ ${{ runner.os }}-build-
28
+ ${{ runner.os }}-
29
+
30
+ - if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
31
+ name: List the state of node modules
32
+ continue-on-error: true
33
+ run: npm list
34
+
35
+ - name: Setup Node
36
+ uses: actions/setup-node@v3
37
+ with:
38
+ node-version: 16
39
+ registry-url: 'https://registry.npmjs.org'
40
+ always-auth: true
41
+ - name: Install dependencies and build 🔧
42
+ run: npm install && npm run bundle:full
43
+ - name: Publish package on NPM 📦
44
+ run: npm publish --access public
45
+ env:
46
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/.prettierrc ADDED
File without changes
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ <div align="center">
2
+ <br>
3
+ <h1> Spark Execute SDK </h1>
4
+ </div>
5
+
6
+ # About the Project
7
+
8
+ A Software Development Kit (SDK) that can run either WASM or Fallback Endpoint to call Spark Api model calculation.
9
+
10
+ # How to's
11
+
12
+ ## Installation
13
+
14
+ ```
15
+ npm install @coherentglobal/spark-execute-sdk
16
+ ```
17
+
18
+ or
19
+
20
+ ```
21
+ yarn add @coherentglobal/spark-execute-sdk
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Configuration
27
+
28
+ ```js
29
+ const config = {
30
+ sparkEndpoint: {
31
+ url: "https://excel.dev.coherent.global", // Spark Endpoint to be used on Fallback
32
+ tenant: "tenant", // Spark tenant name
33
+ authType: public | syntheticKey | bearerToken
34
+ // If syntheticKey
35
+ syntheticKey: "apiKey" or generateSyntheticKey(), // value or a func - func call every time making API call, user will do cache
36
+ // If bearerToken
37
+ bearerToken: generateToken(), //a func - func call every time making API call, user will do cache
38
+ },
39
+ nodegenModels: [
40
+ {
41
+ versionId: "uuid",
42
+ type: "base64",
43
+ binary: Blob | Base64 | BinaryUnit | Func(versionId), // a binary zipped file or a function the will get the zipped file
44
+ metadata: {
45
+ // Spark Model Metadata
46
+ }
47
+ }
48
+ ]
49
+ }
50
+ ```
51
+
52
+ ## Methods
53
+
54
+ ### Initialize Spark Execute SDK
55
+
56
+ Instantiate the Model Class.
57
+
58
+ ```js
59
+ const Spark = new Spark(config);
60
+ ```
61
+
62
+ ### Execute
63
+
64
+ ### (async) execute(input)
65
+
66
+ Perform the calculation. The sdk will use the request_meta.version_uuid of input argument to locate the model
67
+
68
+ ```js
69
+ const response = await Spark.execute(input).catch((err) => {
70
+ // Do something here
71
+ });
72
+ ```
73
+
74
+ ### Sample Input
75
+
76
+ ```json
77
+ {
78
+ "request_data": {
79
+ "inputs": {
80
+ "Input": 1
81
+ }
82
+ },
83
+ "request_meta": {
84
+ "version_id": "<model id>",
85
+ "transaction_date": "2022-09-19T04:17:17.142Z",
86
+ "call_purpose": "Spark - API Tester",
87
+ "source_system": "",
88
+ "correlation_id": "",
89
+ "requested_output": ""
90
+ }
91
+ }
92
+ ```