@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.
- package/.babelrc +12 -0
- package/.eslintrc.json +21 -0
- package/.github/workflows/build-publish.yml +46 -0
- package/.prettierrc +0 -0
- package/README.md +92 -0
- package/dist/browser.js +6925 -0
- package/examples/UsingBearerTokenFNAsync/bearerTokenExample.js +22 -0
- package/examples/UsingBearerTokenFNAsync/config.js +88 -0
- package/examples/UsingBearerTokenFNAsync/index.html +205 -0
- package/examples/UsingBearerTokenFNAsync/modelCInput.json +15 -0
- package/examples/UsingBearerTokenFNAsync/models/Model_C.zip +0 -0
- package/examples/UsingBearerTokenString/bearerTokenExample.js +22 -0
- package/examples/UsingBearerTokenString/config.js +182 -0
- package/examples/UsingBearerTokenString/index.html +191 -0
- package/examples/UsingBearerTokenString/modelCInput.json +15 -0
- package/examples/UsingBearerTokenString/models/Model_C.zip +0 -0
- package/examples/UsingSyntheticKeyFNAsync/bearerTokenExample.js +22 -0
- package/examples/UsingSyntheticKeyFNAsync/config.js +195 -0
- package/examples/UsingSyntheticKeyFNAsync/index.html +205 -0
- package/examples/UsingSyntheticKeyFNAsync/modelCInput.json +15 -0
- package/examples/UsingSyntheticKeyFNAsync/models/Model_C.zip +0 -0
- package/examples/UsingSyntheticKeyString/bearerTokenExample.js +22 -0
- package/examples/UsingSyntheticKeyString/config.js +181 -0
- package/examples/UsingSyntheticKeyString/index.html +192 -0
- package/examples/UsingSyntheticKeyString/modelCInput.json +15 -0
- package/examples/UsingSyntheticKeyString/models/Model_C.zip +0 -0
- package/examples/asyncFunctionModel/config.js +96 -0
- package/examples/asyncFunctionModel/modelCInput.json +15 -0
- package/examples/asyncFunctionModel/models/Model_C.zip +0 -0
- package/examples/asyncFunctionModel/node.js +125 -0
- package/examples/asyncFunctionModel/tool.js +17 -0
- package/examples/base64Model/config.js +96 -0
- package/examples/base64Model/modelCInput.json +15 -0
- package/examples/base64Model/models/Model_C.zip +0 -0
- package/examples/base64Model/node.js +125 -0
- package/examples/base64Model/tool.js +17 -0
- package/examples/base64modelBrowser/config.js +96 -0
- package/examples/base64modelBrowser/index.html +194 -0
- package/examples/base64modelBrowser/modelCInput.json +15 -0
- package/examples/base64modelBrowser/models/Model_C.zip +0 -0
- package/examples/base64modelBrowser/models/base64model.txt +1 -0
- package/examples/base64modelBrowser/node.js +126 -0
- package/examples/base64modelBrowser/tool.js +17 -0
- package/examples/binary/config.js +96 -0
- package/examples/binary/modelCInput.json +15 -0
- package/examples/binary/models/Model_C.zip +0 -0
- package/examples/binary/models/binary.txt +1 -0
- package/examples/binary/node.js +131 -0
- package/examples/binary/tool.js +18 -0
- package/examples/functionModel/config.js +96 -0
- package/examples/functionModel/modelCInput.json +15 -0
- package/examples/functionModel/models/Model_C.zip +0 -0
- package/examples/functionModel/node.js +138 -0
- package/examples/functionModel/tool.js +17 -0
- package/examples/nodejs/node.js +250 -0
- package/examples/nodejs/test_models/Archive.zip +0 -0
- package/examples/nodejs/test_models/BlackScholes.zip +0 -0
- package/examples/nodejs/test_models/Model_A.zip +0 -0
- package/examples/nodejs/test_models/Par7.zip +0 -0
- package/package.json +79 -0
- package/src/browser.js +198 -0
- package/src/error.js +87 -0
- package/src/helpers/utils.js +79 -0
- package/src/logger.js +3 -0
- package/src/models.js +26 -0
- package/src/node.js +254 -0
- package/src/resolver/externalResolver.js +118 -0
- package/src/services/entityStore.js +260 -0
- package/src/services/resolver.js +134 -0
- package/src/services/spark.js +80 -0
- package/src/tenant_resolver/externalResolver_coherent.js +118 -0
- package/src/tenant_resolver/externalResolver_test.js +118 -0
- package/src/validate.js +38 -0
- package/test/config.test.js +124 -0
- package/test/mock-data/dummy-config.json +102 -0
- package/test/mock-data/valid.json +21 -0
- package/test/spark-sdk.test.js +28 -0
- package/tsconfig.json +105 -0
- package/types/browser.d.ts +72 -0
- package/types/browser.d.ts.map +1 -0
- package/types/error.d.ts +42 -0
- package/types/error.d.ts.map +1 -0
- package/types/helpers/utils.d.ts +11 -0
- package/types/helpers/utils.d.ts.map +1 -0
- package/types/logger.d.ts +3 -0
- package/types/logger.d.ts.map +1 -0
- package/types/models.d.ts +8 -0
- package/types/models.d.ts.map +1 -0
- package/types/node.d.ts +78 -0
- package/types/node.d.ts.map +1 -0
- package/types/resolver/externalResolver.d.ts +2 -0
- package/types/resolver/externalResolver.d.ts.map +1 -0
- package/types/services/entityStore.d.ts +51 -0
- package/types/services/entityStore.d.ts.map +1 -0
- package/types/services/resolver.d.ts +20 -0
- package/types/services/resolver.d.ts.map +1 -0
- package/types/services/spark.d.ts +6 -0
- package/types/services/spark.d.ts.map +1 -0
- package/types/tenant_resolver/externalResolver_coherent.d.ts +2 -0
- package/types/tenant_resolver/externalResolver_coherent.d.ts.map +1 -0
- package/types/tenant_resolver/externalResolver_test.d.ts +2 -0
- package/types/tenant_resolver/externalResolver_test.d.ts.map +1 -0
- package/types/validate.d.ts +4 -0
- package/types/validate.d.ts.map +1 -0
package/.babelrc
ADDED
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
|
+
```
|