@coherentglobal/spark-execute-sdk 0.4.4 → 0.4.7
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 +38 -9
- package/dist/browser.js +154 -144
- package/package.json +9 -3
- package/src/browser.js +42 -155
- package/src/findModels.js +132 -0
- package/src/models.js +6 -12
- package/src/node.js +80 -182
- package/src/services/resolver.js +5 -6
- package/src/validate.js +2 -3
- package/types/browser.d.ts +6 -0
- package/types/browser.d.ts.map +1 -1
- package/types/models.d.ts +1 -1
- package/types/models.d.ts.map +1 -1
- package/types/node.d.ts +19 -5
- package/types/node.d.ts.map +1 -1
- package/types/resolver/externalResolver.d.ts.map +1 -1
- package/types/validate.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -7,13 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
A Software Development Kit (SDK) that can run either [Spark](https://coherent.global/spark/) model web-assembly or Calling an HTTPS endpoint.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
# Roadmap
|
|
12
|
-
|
|
13
|
-
- Calling an HTTPS endpoint on Spark SaaS.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
10
|
# How to's
|
|
18
11
|
|
|
19
12
|
## Installation
|
|
@@ -32,12 +25,14 @@ yarn add @coherentglobal/spark-execute-sdk
|
|
|
32
25
|
|
|
33
26
|
### Configuration
|
|
34
27
|
|
|
28
|
+
#### Both Online and Offline Config is enabled
|
|
29
|
+
|
|
35
30
|
```js
|
|
36
31
|
const config = {
|
|
37
32
|
sparkEndpoint: {
|
|
38
|
-
url: "https://excel.dev.coherent.global", // Spark Endpoint to be used
|
|
33
|
+
url: "https://excel.dev.coherent.global", // Spark Endpoint to be used to run model using Spark SaaS
|
|
39
34
|
tenant: "tenant", // Spark tenant name
|
|
40
|
-
authType: public | syntheticKey | bearerToken,
|
|
35
|
+
authType: public | syntheticKey | bearerToken, // public endpoint don't require token / synthetic key
|
|
41
36
|
// If syntheticKey
|
|
42
37
|
syntheticKey: "apiKey" or generateSyntheticKey(), // value or a func - func call every time making API call, user will do cache
|
|
43
38
|
// If bearerToken
|
|
@@ -56,6 +51,40 @@ const config = {
|
|
|
56
51
|
}
|
|
57
52
|
```
|
|
58
53
|
|
|
54
|
+
#### Online Only Configuration
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
const config = {
|
|
58
|
+
sparkEndpoint: {
|
|
59
|
+
url: "https://excel.dev.coherent.global", // Spark Endpoint to be used to run model using Spark SaaS
|
|
60
|
+
tenant: "tenant", // Spark tenant name
|
|
61
|
+
authType: public | syntheticKey | bearerToken, // public endpoint don't require token / synthetic key
|
|
62
|
+
// If syntheticKey
|
|
63
|
+
syntheticKey: "apiKey" || generateSyntheticKey(), // value or a func - func call every time making API call, user will do cache
|
|
64
|
+
// If bearerToken
|
|
65
|
+
bearerToken: "token" || generateToken(), //a func - func call every time making API call, user will do cache
|
|
66
|
+
},
|
|
67
|
+
nodegenModels: [],
|
|
68
|
+
};
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### Offline Only Configuration
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
const config = {
|
|
75
|
+
nodegenModels: [
|
|
76
|
+
{
|
|
77
|
+
versionId: "uuid",
|
|
78
|
+
type: "base64",
|
|
79
|
+
binary: Blob | Base64 | BinaryUnit | Func(versionId), // a binary zipped file or a function the will get the zipped file
|
|
80
|
+
metadata: {
|
|
81
|
+
// Spark Model Metadata
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
|
|
59
88
|
## Methods
|
|
60
89
|
|
|
61
90
|
### Initialize Spark Execute SDK
|
package/dist/browser.js
CHANGED
|
@@ -6210,41 +6210,36 @@ var _require = require("@coherentglobal/wasm-runner"),
|
|
|
6210
6210
|
WasmRunner = _require.WasmRunner;
|
|
6211
6211
|
var validate = require("./validate.js");
|
|
6212
6212
|
var processModels = require("./models.js");
|
|
6213
|
+
var findModel = require("./findModels.js");
|
|
6213
6214
|
var registry = {};
|
|
6214
6215
|
var Spark = /*#__PURE__*/function () {
|
|
6215
6216
|
/**
|
|
6216
6217
|
* @param {object} config
|
|
6217
6218
|
*/
|
|
6218
6219
|
function Spark(config) {
|
|
6220
|
+
var _this$config$sparkEnd, _this$config, _this$config$sparkEnd2, _this$config$sparkEnd3, _this$config2, _this$config2$sparkEn, _ref, _this$config$sparkEnd4, _this$config3, _this$config3$sparkEn, _this$config4, _this$config4$sparkEn, _this$config$sparkEnd5, _this$config5, _this$config5$sparkEn, _this$config6;
|
|
6219
6221
|
(0, _classCallCheck2["default"])(this, Spark);
|
|
6220
6222
|
/**
|
|
6221
6223
|
* @private
|
|
6222
6224
|
*/
|
|
6223
6225
|
this.config = this.validateConfig(config);
|
|
6224
|
-
|
|
6225
|
-
_this$config$sparkEnd = _this$config.sparkEndpoint,
|
|
6226
|
-
syntheticKey = _this$config$sparkEnd.syntheticKey,
|
|
6227
|
-
bearerToken = _this$config$sparkEnd.bearerToken,
|
|
6228
|
-
authType = _this$config$sparkEnd.authType,
|
|
6229
|
-
tenant = _this$config$sparkEnd.tenant,
|
|
6230
|
-
url = _this$config$sparkEnd.url,
|
|
6231
|
-
nodeGenModels = _this$config.nodeGenModels;
|
|
6226
|
+
|
|
6232
6227
|
/**
|
|
6233
6228
|
* @private
|
|
6234
6229
|
*/
|
|
6235
|
-
this.tenant = tenant;
|
|
6230
|
+
this.tenant = (_this$config$sparkEnd = (_this$config = this.config) === null || _this$config === void 0 ? void 0 : (_this$config$sparkEnd2 = _this$config.sparkEndpoint) === null || _this$config$sparkEnd2 === void 0 ? void 0 : _this$config$sparkEnd2.tenant) !== null && _this$config$sparkEnd !== void 0 ? _this$config$sparkEnd : "";
|
|
6236
6231
|
/**
|
|
6237
6232
|
* @private
|
|
6238
6233
|
*/
|
|
6239
|
-
this.authType = authType;
|
|
6234
|
+
this.authType = (_this$config$sparkEnd3 = (_this$config2 = this.config) === null || _this$config2 === void 0 ? void 0 : (_this$config2$sparkEn = _this$config2.sparkEndpoint) === null || _this$config2$sparkEn === void 0 ? void 0 : _this$config2$sparkEn.authType) !== null && _this$config$sparkEnd3 !== void 0 ? _this$config$sparkEnd3 : "";
|
|
6240
6235
|
/**
|
|
6241
6236
|
* @private
|
|
6242
6237
|
*/
|
|
6243
|
-
this.token = syntheticKey || bearerToken;
|
|
6238
|
+
this.token = (_ref = (_this$config$sparkEnd4 = (_this$config3 = this.config) === null || _this$config3 === void 0 ? void 0 : (_this$config3$sparkEn = _this$config3.sparkEndpoint) === null || _this$config3$sparkEn === void 0 ? void 0 : _this$config3$sparkEn.syntheticKey) !== null && _this$config$sparkEnd4 !== void 0 ? _this$config$sparkEnd4 : (_this$config4 = this.config) === null || _this$config4 === void 0 ? void 0 : (_this$config4$sparkEn = _this$config4.sparkEndpoint) === null || _this$config4$sparkEn === void 0 ? void 0 : _this$config4$sparkEn.bearerToken) !== null && _ref !== void 0 ? _ref : "";
|
|
6244
6239
|
/**
|
|
6245
6240
|
* @private
|
|
6246
6241
|
*/
|
|
6247
|
-
this.url = url;
|
|
6242
|
+
this.url = (_this$config$sparkEnd5 = (_this$config5 = this.config) === null || _this$config5 === void 0 ? void 0 : (_this$config5$sparkEn = _this$config5.sparkEndpoint) === null || _this$config5$sparkEn === void 0 ? void 0 : _this$config5$sparkEn.url) !== null && _this$config$sparkEnd5 !== void 0 ? _this$config$sparkEnd5 : "";
|
|
6248
6243
|
/**
|
|
6249
6244
|
* @private
|
|
6250
6245
|
*/
|
|
@@ -6252,12 +6247,13 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6252
6247
|
/**
|
|
6253
6248
|
* @private
|
|
6254
6249
|
*/
|
|
6255
|
-
this.model = this._models(nodeGenModels);
|
|
6250
|
+
this.model = this._models((_this$config6 = this.config) === null || _this$config6 === void 0 ? void 0 : _this$config6.nodeGenModels);
|
|
6256
6251
|
/**
|
|
6257
6252
|
* @private
|
|
6258
6253
|
*/
|
|
6259
|
-
this.priority = ["model"];
|
|
6254
|
+
this.priority = ["model", "onlineEndpoint"];
|
|
6260
6255
|
}
|
|
6256
|
+
|
|
6261
6257
|
/**
|
|
6262
6258
|
*
|
|
6263
6259
|
* @param {object} nodegen
|
|
@@ -6301,91 +6297,6 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6301
6297
|
if (!model) throw new WasmRunnerErrors.MissingModelError(id);
|
|
6302
6298
|
return model;
|
|
6303
6299
|
}
|
|
6304
|
-
}, {
|
|
6305
|
-
key: "_findModel",
|
|
6306
|
-
value: function _findModel(requestMeta) {
|
|
6307
|
-
var model = {};
|
|
6308
|
-
if (requestMeta.version_id) {
|
|
6309
|
-
model = this.model.filter(function (_ref) {
|
|
6310
|
-
var versionId = _ref.versionId;
|
|
6311
|
-
return versionId === requestMeta.version_id;
|
|
6312
|
-
});
|
|
6313
|
-
} else if (requestMeta.servicename && requestMeta.version) {
|
|
6314
|
-
model = this.model.filter(function (_ref2) {
|
|
6315
|
-
var metaData = _ref2.metaData;
|
|
6316
|
-
return metaData.EngineInformation.ServiceName === requestMeta.servicename && metaData.EngineInformation.Revision === requestMeta.version;
|
|
6317
|
-
});
|
|
6318
|
-
} else if (requestMeta.servicename && requestMeta.transaction_date) {
|
|
6319
|
-
model = this.model.filter(function (_ref3) {
|
|
6320
|
-
var metaData = _ref3.metaData;
|
|
6321
|
-
return metaData.EngineInformation.ServiceName === requestMeta.servicename && new Date(requestMeta.transaction_date) >= new Date(metaData.EffectiveStartDate) && new Date(requestMeta.transaction_date) <= new Date(metaData.EffectiveEndDate);
|
|
6322
|
-
});
|
|
6323
|
-
if (model.length > 1) {
|
|
6324
|
-
return model.sort(function (versionA, versionB) {
|
|
6325
|
-
return versionA.metaData.EngineInformation.Revision.replace(/\d+/g, function (n) {
|
|
6326
|
-
return +n + 100000;
|
|
6327
|
-
}).localCompare(versionB.metaData.EngineInformation.Revision.replace(/\d+/g, function (n) {
|
|
6328
|
-
return +n + 100000;
|
|
6329
|
-
}));
|
|
6330
|
-
}).reverse();
|
|
6331
|
-
}
|
|
6332
|
-
} else if (requestMeta.service_id && requestMeta.version) {
|
|
6333
|
-
model = this.model.filter(function (_ref4) {
|
|
6334
|
-
var metaData = _ref4.metaData;
|
|
6335
|
-
return metaData.EngineInformation.ServiceGuid === requestMeta.service_id && metaData.EngineInformation.Revision === requestMeta.version;
|
|
6336
|
-
});
|
|
6337
|
-
} else if (requestMeta.service_id && requestMeta.transaction_date) {
|
|
6338
|
-
model = this.model.filter(function (_ref5) {
|
|
6339
|
-
var metaData = _ref5.metaData;
|
|
6340
|
-
return metaData.EngineInformation.ServiceGuid === requestMeta.service_id && new Date(requestMeta.transaction_date) >= new Date(metaData.EffectiveStartDate) && new Date(requestMeta.transaction_date) <= new Date(metaData.EffectiveEndDate);
|
|
6341
|
-
});
|
|
6342
|
-
if (model.length > 1) {
|
|
6343
|
-
return model.sort(function (versionA, versionB) {
|
|
6344
|
-
return versionA.metaData.EngineInformation.Revision.replace(/\d+/g, function (n) {
|
|
6345
|
-
return +n + 100000;
|
|
6346
|
-
}).localCompare(versionB.metaData.EngineInformation.Revision.replace(/\d+/g, function (n) {
|
|
6347
|
-
return +n + 100000;
|
|
6348
|
-
}));
|
|
6349
|
-
}).reverse();
|
|
6350
|
-
}
|
|
6351
|
-
} else if (requestMeta.service_uri && requestMeta.transaction_date) {
|
|
6352
|
-
var regex = /folders\/(.+)\/services\/(.+)/gi;
|
|
6353
|
-
var parts = regex.exec(requestMeta.service_uri);
|
|
6354
|
-
var folder, service;
|
|
6355
|
-
if (parts) {
|
|
6356
|
-
folder = decodeURI(parts[1]);
|
|
6357
|
-
service = decodeURI(parts[2]);
|
|
6358
|
-
}
|
|
6359
|
-
model = this.model.filter(function (_ref6) {
|
|
6360
|
-
var metaData = _ref6.metaData;
|
|
6361
|
-
return metaData.EngineInformation.ProductName === folder && metaData.EngineInformation.ServiceName === service && new Date(requestMeta.transaction_date) >= new Date(metaData.EffectiveStartDate) && new Date(requestMeta.transaction_date) <= new Date(metaData.EffectiveEndDate);
|
|
6362
|
-
});
|
|
6363
|
-
if (model.length > 1) {
|
|
6364
|
-
return model.sort(function (versionA, versionB) {
|
|
6365
|
-
return versionA.metaData.EngineInformation.Revision.replace(/\d+/g, function (n) {
|
|
6366
|
-
return +n + 100000;
|
|
6367
|
-
}).localCompare(versionB.metaData.EngineInformation.Revision.replace(/\d+/g, function (n) {
|
|
6368
|
-
return +n + 100000;
|
|
6369
|
-
}));
|
|
6370
|
-
}).reverse();
|
|
6371
|
-
}
|
|
6372
|
-
} else if (requestMeta.service_uri && requestMeta.version) {
|
|
6373
|
-
var _regex = /folders\/(.+)\/services\/(.+)/gi;
|
|
6374
|
-
var _parts = _regex.exec(requestMeta.service_uri);
|
|
6375
|
-
var _folder, _service;
|
|
6376
|
-
if (_parts) {
|
|
6377
|
-
_folder = decodeURI(_parts[1]);
|
|
6378
|
-
_service = decodeURI(_parts[2]);
|
|
6379
|
-
}
|
|
6380
|
-
model = this.model.filter(function (_ref7) {
|
|
6381
|
-
var metaData = _ref7.metaData;
|
|
6382
|
-
return metaData.EngineInformation.ProductName === _folder && metaData.EngineInformation.ServiceName === _service && metaData.EngineInformation.Revision === requestMeta.version;
|
|
6383
|
-
});
|
|
6384
|
-
} else {
|
|
6385
|
-
throw new Error("Model not found. requestMeta: " + JSON.stringify(requestMeta) + " tenant: " + this.tenant);
|
|
6386
|
-
}
|
|
6387
|
-
return model[0];
|
|
6388
|
-
}
|
|
6389
6300
|
}, {
|
|
6390
6301
|
key: "_getModelByMeta",
|
|
6391
6302
|
value: function _getModelByMeta(folderName, serviceName) {
|
|
@@ -6414,18 +6325,26 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6414
6325
|
while (1) {
|
|
6415
6326
|
switch (_context.prev = _context.next) {
|
|
6416
6327
|
case 0:
|
|
6417
|
-
console.log("-------UOPD---");
|
|
6418
6328
|
versionID = version_id || (input === null || input === void 0 ? void 0 : (_input$request_meta = input.request_meta) === null || _input$request_meta === void 0 ? void 0 : _input$request_meta.version_id) || (input === null || input === void 0 ? void 0 : (_input$request_meta2 = input.request_meta) === null || _input$request_meta2 === void 0 ? void 0 : _input$request_meta2.version_uuid);
|
|
6419
6329
|
lookup = {
|
|
6420
6330
|
model: this.offlineModel,
|
|
6421
6331
|
onlineEndpoint: this.onlineModelEndpoint
|
|
6422
6332
|
};
|
|
6423
|
-
_context.next =
|
|
6333
|
+
_context.next = 4;
|
|
6424
6334
|
return lookup[this.priority[0]](input, versionID, this);
|
|
6425
|
-
case
|
|
6335
|
+
case 4:
|
|
6426
6336
|
response = _context.sent;
|
|
6337
|
+
if (!(response instanceof Error && this.config.sparkEndpoint !== undefined)) {
|
|
6338
|
+
_context.next = 9;
|
|
6339
|
+
break;
|
|
6340
|
+
}
|
|
6341
|
+
_context.next = 8;
|
|
6342
|
+
return lookup[this.priority[1]](input, versionID, this);
|
|
6343
|
+
case 8:
|
|
6344
|
+
response = _context.sent;
|
|
6345
|
+
case 9:
|
|
6427
6346
|
return _context.abrupt("return", response);
|
|
6428
|
-
case
|
|
6347
|
+
case 10:
|
|
6429
6348
|
case "end":
|
|
6430
6349
|
return _context.stop();
|
|
6431
6350
|
}
|
|
@@ -6446,8 +6365,8 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6446
6365
|
while (1) {
|
|
6447
6366
|
switch (_context3.prev = _context3.next) {
|
|
6448
6367
|
case 0:
|
|
6449
|
-
model =
|
|
6450
|
-
modelVersionId = versionID || model && (model === null || model === void 0 ? void 0 : model.versionId);
|
|
6368
|
+
model = findModel(input.request_meta, ds.model);
|
|
6369
|
+
modelVersionId = versionID || model && (model === null || model === void 0 ? void 0 : model.versionId);
|
|
6451
6370
|
if (!(input !== null && input !== void 0 && input.request_meta)) {
|
|
6452
6371
|
input.request_meta = {};
|
|
6453
6372
|
}
|
|
@@ -6463,7 +6382,7 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6463
6382
|
* @returns
|
|
6464
6383
|
*/
|
|
6465
6384
|
callback = /*#__PURE__*/function () {
|
|
6466
|
-
var
|
|
6385
|
+
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(options) {
|
|
6467
6386
|
var hasFolderName, hasServiceName, hasVersionId, _model$metaData$Engin, _model$metaData, _model$metaData$Engin2, _model$metaData$Engin3, _model$metaData2, _model$metaData2$Engi, _model$metaData$Engin4, _model$metaData3, _model$metaData3$Engi, _model$metaData$Engin5, _model$metaData4, _model$metaData4$Engi, _model;
|
|
6468
6387
|
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
6469
6388
|
while (1) {
|
|
@@ -6510,7 +6429,7 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6510
6429
|
}, _callee2);
|
|
6511
6430
|
}));
|
|
6512
6431
|
return function callback(_x6) {
|
|
6513
|
-
return
|
|
6432
|
+
return _ref2.apply(this, arguments);
|
|
6514
6433
|
};
|
|
6515
6434
|
}();
|
|
6516
6435
|
registry = new WasmRunner("", callback);
|
|
@@ -6519,7 +6438,7 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6519
6438
|
_context3.next = 10;
|
|
6520
6439
|
break;
|
|
6521
6440
|
}
|
|
6522
|
-
_model2 =
|
|
6441
|
+
_model2 = findModel(input.request_meta, ds.model);
|
|
6523
6442
|
_context3.next = 10;
|
|
6524
6443
|
return registry.append({
|
|
6525
6444
|
id: modelVersionId,
|
|
@@ -6555,33 +6474,42 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6555
6474
|
key: "onlineModelEndpoint",
|
|
6556
6475
|
value: function () {
|
|
6557
6476
|
var _onlineModelEndpoint = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(input, versionID, ds) {
|
|
6558
|
-
var token, header, options, modelUrl, response, result;
|
|
6477
|
+
var isPublic, token, header, options, modelUrl, response, result;
|
|
6559
6478
|
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
6560
6479
|
while (1) {
|
|
6561
6480
|
switch (_context4.prev = _context4.next) {
|
|
6562
6481
|
case 0:
|
|
6482
|
+
isPublic = ds.authType === "public";
|
|
6563
6483
|
token = "";
|
|
6484
|
+
if (isPublic) {
|
|
6485
|
+
_context4.next = 12;
|
|
6486
|
+
break;
|
|
6487
|
+
}
|
|
6564
6488
|
if (!(ds.token.constructor.name === "AsyncFunction")) {
|
|
6565
|
-
_context4.next =
|
|
6489
|
+
_context4.next = 9;
|
|
6566
6490
|
break;
|
|
6567
6491
|
}
|
|
6568
|
-
_context4.next =
|
|
6492
|
+
_context4.next = 6;
|
|
6569
6493
|
return ds.token();
|
|
6570
|
-
case
|
|
6494
|
+
case 6:
|
|
6571
6495
|
token = _context4.sent;
|
|
6572
|
-
_context4.next =
|
|
6496
|
+
_context4.next = 10;
|
|
6573
6497
|
break;
|
|
6574
|
-
case
|
|
6575
|
-
|
|
6576
|
-
|
|
6498
|
+
case 9:
|
|
6499
|
+
if (typeof ds.token === "function") {
|
|
6500
|
+
token = ds.token();
|
|
6501
|
+
} else {
|
|
6502
|
+
token = ds.token;
|
|
6503
|
+
}
|
|
6504
|
+
case 10:
|
|
6577
6505
|
if (!utils.isEmpty(ds.token)) {
|
|
6578
|
-
_context4.next =
|
|
6506
|
+
_context4.next = 12;
|
|
6579
6507
|
break;
|
|
6580
6508
|
}
|
|
6581
6509
|
throw new WasmRunnerErrors.UnauthorizedError();
|
|
6582
|
-
case
|
|
6583
|
-
_context4.prev =
|
|
6584
|
-
header = utils.getAuthHeaders(token, ds.authType, ds.tenant);
|
|
6510
|
+
case 12:
|
|
6511
|
+
_context4.prev = 12;
|
|
6512
|
+
header = !isPublic ? utils.getAuthHeaders(token, ds.authType, ds.tenant) : {};
|
|
6585
6513
|
options = {
|
|
6586
6514
|
method: "POST",
|
|
6587
6515
|
body: JSON.stringify({
|
|
@@ -6592,26 +6520,26 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6592
6520
|
"content-type": "application/json"
|
|
6593
6521
|
}), header)
|
|
6594
6522
|
};
|
|
6595
|
-
modelUrl = new URL("/".concat(ds.tenant, "/api/v3/execute"), ds.url);
|
|
6596
|
-
_context4.next =
|
|
6523
|
+
modelUrl = new URL("/".concat(ds.tenant, "/api/v3/").concat(!isPublic ? "execute" : "public"), ds.url);
|
|
6524
|
+
_context4.next = 18;
|
|
6597
6525
|
return fetch(modelUrl, options);
|
|
6598
|
-
case
|
|
6526
|
+
case 18:
|
|
6599
6527
|
response = _context4.sent;
|
|
6600
|
-
_context4.next =
|
|
6528
|
+
_context4.next = 21;
|
|
6601
6529
|
return response.json();
|
|
6602
|
-
case
|
|
6530
|
+
case 21:
|
|
6603
6531
|
result = _context4.sent;
|
|
6604
6532
|
return _context4.abrupt("return", result);
|
|
6605
|
-
case
|
|
6606
|
-
_context4.prev =
|
|
6607
|
-
_context4.t0 = _context4["catch"](
|
|
6533
|
+
case 25:
|
|
6534
|
+
_context4.prev = 25;
|
|
6535
|
+
_context4.t0 = _context4["catch"](12);
|
|
6608
6536
|
return _context4.abrupt("return", _context4.t0);
|
|
6609
|
-
case
|
|
6537
|
+
case 28:
|
|
6610
6538
|
case "end":
|
|
6611
6539
|
return _context4.stop();
|
|
6612
6540
|
}
|
|
6613
6541
|
}
|
|
6614
|
-
}, _callee4, null, [[
|
|
6542
|
+
}, _callee4, null, [[12, 25]]);
|
|
6615
6543
|
}));
|
|
6616
6544
|
function onlineModelEndpoint(_x7, _x8, _x9) {
|
|
6617
6545
|
return _onlineModelEndpoint.apply(this, arguments);
|
|
@@ -6623,7 +6551,7 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6623
6551
|
}();
|
|
6624
6552
|
module.exports = Spark;
|
|
6625
6553
|
|
|
6626
|
-
},{"./error.js":43,"./helpers/utils.js":
|
|
6554
|
+
},{"./error.js":43,"./findModels.js":44,"./helpers/utils.js":45,"./models.js":46,"./validate.js":47,"@babel/runtime/helpers/asyncToGenerator":2,"@babel/runtime/helpers/classCallCheck":3,"@babel/runtime/helpers/createClass":5,"@babel/runtime/helpers/defineProperty":6,"@babel/runtime/helpers/interopRequireDefault":9,"@babel/runtime/regenerator":17,"@coherentglobal/wasm-runner":18}],43:[function(require,module,exports){
|
|
6627
6555
|
"use strict";
|
|
6628
6556
|
|
|
6629
6557
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
@@ -6766,6 +6694,98 @@ module.exports = {
|
|
|
6766
6694
|
},{"@babel/runtime/helpers/classCallCheck":3,"@babel/runtime/helpers/createClass":5,"@babel/runtime/helpers/getPrototypeOf":7,"@babel/runtime/helpers/inherits":8,"@babel/runtime/helpers/interopRequireDefault":9,"@babel/runtime/helpers/possibleConstructorReturn":12,"@babel/runtime/helpers/wrapNativeSuper":16}],44:[function(require,module,exports){
|
|
6767
6695
|
"use strict";
|
|
6768
6696
|
|
|
6697
|
+
var WasmRunnerErrors = require("./error");
|
|
6698
|
+
var findModel = function findModel(requestMeta, nodegenModels) {
|
|
6699
|
+
var model = {};
|
|
6700
|
+
if (requestMeta.version_id) {
|
|
6701
|
+
model = nodegenModels.filter(function (_ref) {
|
|
6702
|
+
var versionId = _ref.versionId;
|
|
6703
|
+
return versionId === requestMeta.version_id;
|
|
6704
|
+
});
|
|
6705
|
+
} else if (requestMeta.servicename && requestMeta.version) {
|
|
6706
|
+
model = nodegenModels.filter(function (_ref2) {
|
|
6707
|
+
var metaData = _ref2.metaData;
|
|
6708
|
+
return metaData.EngineInformation.ServiceName === requestMeta.servicename && metaData.EngineInformation.Revision === requestMeta.version;
|
|
6709
|
+
});
|
|
6710
|
+
} else if (requestMeta.servicename && requestMeta.transaction_date) {
|
|
6711
|
+
model = nodegenModels.filter(function (_ref3) {
|
|
6712
|
+
var metaData = _ref3.metaData;
|
|
6713
|
+
return metaData.EngineInformation.ServiceName === requestMeta.servicename && new Date(requestMeta.transaction_date) >= new Date(metaData.EffectiveStartDate) && new Date(requestMeta.transaction_date) <= new Date(metaData.EffectiveEndDate);
|
|
6714
|
+
});
|
|
6715
|
+
if (model.length > 1) {
|
|
6716
|
+
return model.sort(function (versionA, versionB) {
|
|
6717
|
+
return versionA.metaData.EngineInformation.Revision.replace(/\d+/g, function (n) {
|
|
6718
|
+
return +n + 100000;
|
|
6719
|
+
}).localCompare(versionB.metaData.EngineInformation.Revision.replace(/\d+/g, function (n) {
|
|
6720
|
+
return +n + 100000;
|
|
6721
|
+
}));
|
|
6722
|
+
}).reverse();
|
|
6723
|
+
}
|
|
6724
|
+
} else if (requestMeta.service_id && requestMeta.version) {
|
|
6725
|
+
model = nodegenModels.filter(function (_ref4) {
|
|
6726
|
+
var metaData = _ref4.metaData;
|
|
6727
|
+
return metaData.EngineInformation.ServiceGuid === requestMeta.service_id && metaData.EngineInformation.Revision === requestMeta.version;
|
|
6728
|
+
});
|
|
6729
|
+
} else if (requestMeta.service_id && requestMeta.transaction_date) {
|
|
6730
|
+
model = nodegenModels.filter(function (_ref5) {
|
|
6731
|
+
var metaData = _ref5.metaData;
|
|
6732
|
+
return metaData.EngineInformation.ServiceGuid === requestMeta.service_id && new Date(requestMeta.transaction_date) >= new Date(metaData.EffectiveStartDate) && new Date(requestMeta.transaction_date) <= new Date(metaData.EffectiveEndDate);
|
|
6733
|
+
});
|
|
6734
|
+
if (model.length > 1) {
|
|
6735
|
+
return model.sort(function (versionA, versionB) {
|
|
6736
|
+
return versionA.metaData.EngineInformation.Revision.replace(/\d+/g, function (n) {
|
|
6737
|
+
return +n + 100000;
|
|
6738
|
+
}).localCompare(versionB.metaData.EngineInformation.Revision.replace(/\d+/g, function (n) {
|
|
6739
|
+
return +n + 100000;
|
|
6740
|
+
}));
|
|
6741
|
+
}).reverse();
|
|
6742
|
+
}
|
|
6743
|
+
} else if (requestMeta.service_uri && requestMeta.transaction_date) {
|
|
6744
|
+
var regex = /folders\/(.+)\/services\/(.+)/gi;
|
|
6745
|
+
var parts = regex.exec(requestMeta.service_uri);
|
|
6746
|
+
var folder, service;
|
|
6747
|
+
if (parts) {
|
|
6748
|
+
folder = decodeURI(parts[1]);
|
|
6749
|
+
service = decodeURI(parts[2]);
|
|
6750
|
+
}
|
|
6751
|
+
model = nodegenModels.filter(function (_ref6) {
|
|
6752
|
+
var metaData = _ref6.metaData;
|
|
6753
|
+
return metaData.EngineInformation.ProductName === folder && metaData.EngineInformation.ServiceName === service && new Date(requestMeta.transaction_date) >= new Date(metaData.EffectiveStartDate) && new Date(requestMeta.transaction_date) <= new Date(metaData.EffectiveEndDate);
|
|
6754
|
+
});
|
|
6755
|
+
if (model.length > 1) {
|
|
6756
|
+
return model.sort(function (versionA, versionB) {
|
|
6757
|
+
return versionA.metaData.EngineInformation.Revision.replace(/\d+/g, function (n) {
|
|
6758
|
+
return +n + 100000;
|
|
6759
|
+
}).localCompare(versionB.metaData.EngineInformation.Revision.replace(/\d+/g, function (n) {
|
|
6760
|
+
return +n + 100000;
|
|
6761
|
+
}));
|
|
6762
|
+
}).reverse();
|
|
6763
|
+
}
|
|
6764
|
+
} else if (requestMeta.service_uri && requestMeta.version) {
|
|
6765
|
+
var _regex = /folders\/(.+)\/services\/(.+)/gi;
|
|
6766
|
+
var _parts = _regex.exec(requestMeta.service_uri);
|
|
6767
|
+
var _folder, _service;
|
|
6768
|
+
if (_parts) {
|
|
6769
|
+
_folder = decodeURI(_parts[1]);
|
|
6770
|
+
_service = decodeURI(_parts[2]);
|
|
6771
|
+
}
|
|
6772
|
+
model = nodegenModels.filter(function (_ref7) {
|
|
6773
|
+
var metaData = _ref7.metaData;
|
|
6774
|
+
return metaData.EngineInformation.ProductName === _folder && metaData.EngineInformation.ServiceName === _service && metaData.EngineInformation.Revision === requestMeta.version;
|
|
6775
|
+
});
|
|
6776
|
+
} else {
|
|
6777
|
+
throw new Error("Model not found. requestMeta: " + JSON.stringify(requestMeta));
|
|
6778
|
+
}
|
|
6779
|
+
if (model.length === 0) {
|
|
6780
|
+
throw new WasmRunnerErrors.MissingModelError(requestMeta === null || requestMeta === void 0 ? void 0 : requestMeta.version_id);
|
|
6781
|
+
}
|
|
6782
|
+
return model[0];
|
|
6783
|
+
};
|
|
6784
|
+
module.exports = findModel;
|
|
6785
|
+
|
|
6786
|
+
},{"./error":43}],45:[function(require,module,exports){
|
|
6787
|
+
"use strict";
|
|
6788
|
+
|
|
6769
6789
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6770
6790
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
6771
6791
|
var WasmRunnerErrors = require("../error.js");
|
|
@@ -6831,7 +6851,7 @@ module.exports = {
|
|
|
6831
6851
|
getAuthHeaders: getAuthHeaders
|
|
6832
6852
|
};
|
|
6833
6853
|
|
|
6834
|
-
},{"../error.js":43,"@babel/runtime/helpers/interopRequireDefault":9,"@babel/runtime/helpers/typeof":15}],
|
|
6854
|
+
},{"../error.js":43,"@babel/runtime/helpers/interopRequireDefault":9,"@babel/runtime/helpers/typeof":15}],46:[function(require,module,exports){
|
|
6835
6855
|
(function (Buffer){(function (){
|
|
6836
6856
|
"use strict";
|
|
6837
6857
|
|
|
@@ -6849,7 +6869,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
6849
6869
|
*/
|
|
6850
6870
|
var processModels = function processModels(nodegen) {
|
|
6851
6871
|
var processedModels = _objectSpread({}, nodegen);
|
|
6852
|
-
// console.log('MODELS TO PROCESS: ', processedModels)
|
|
6853
6872
|
switch (nodegen.type) {
|
|
6854
6873
|
case "binary":
|
|
6855
6874
|
case "uint8array":
|
|
@@ -6862,13 +6881,10 @@ var processModels = function processModels(nodegen) {
|
|
|
6862
6881
|
data: Buffer.from(nodegen.binary.data, "base64")
|
|
6863
6882
|
};
|
|
6864
6883
|
processedModels.binary = model;
|
|
6865
|
-
// nodegen.binary = model;
|
|
6866
6884
|
} else {
|
|
6867
6885
|
var _model = Buffer.from(nodegen.binary, "base64");
|
|
6868
6886
|
processedModels.binary = _model;
|
|
6869
|
-
// nodegen.binary = model;
|
|
6870
6887
|
}
|
|
6871
|
-
|
|
6872
6888
|
break;
|
|
6873
6889
|
case "function":
|
|
6874
6890
|
var func = nodegen.binary;
|
|
@@ -6883,10 +6899,8 @@ var processModels = function processModels(nodegen) {
|
|
|
6883
6899
|
return func();
|
|
6884
6900
|
case 2:
|
|
6885
6901
|
processedModels.binary = _context.sent;
|
|
6886
|
-
// nodegen.binary = await func();
|
|
6887
6902
|
model = Buffer.from(nodegen.binary, "base64");
|
|
6888
6903
|
processedModels.binary = model;
|
|
6889
|
-
// nodegen.binary = model;
|
|
6890
6904
|
case 5:
|
|
6891
6905
|
case "end":
|
|
6892
6906
|
return _context.stop();
|
|
@@ -6895,12 +6909,8 @@ var processModels = function processModels(nodegen) {
|
|
|
6895
6909
|
}, _callee);
|
|
6896
6910
|
}))();
|
|
6897
6911
|
} else {
|
|
6898
|
-
|
|
6899
|
-
var _model2 = Buffer.from(nodegen.binary, "base64");
|
|
6900
|
-
processedModels.binary = _model2;
|
|
6901
|
-
// nodegen.binary = model;
|
|
6912
|
+
processedModels.binary = func();
|
|
6902
6913
|
}
|
|
6903
|
-
|
|
6904
6914
|
default:
|
|
6905
6915
|
break;
|
|
6906
6916
|
}
|
|
@@ -6909,7 +6919,7 @@ var processModels = function processModels(nodegen) {
|
|
|
6909
6919
|
module.exports = processModels;
|
|
6910
6920
|
|
|
6911
6921
|
}).call(this)}).call(this,require("buffer").Buffer)
|
|
6912
|
-
},{"@babel/runtime/helpers/asyncToGenerator":2,"@babel/runtime/helpers/defineProperty":6,"@babel/runtime/helpers/interopRequireDefault":9,"@babel/runtime/helpers/typeof":15,"@babel/runtime/regenerator":17,"buffer":24}],
|
|
6922
|
+
},{"@babel/runtime/helpers/asyncToGenerator":2,"@babel/runtime/helpers/defineProperty":6,"@babel/runtime/helpers/interopRequireDefault":9,"@babel/runtime/helpers/typeof":15,"@babel/runtime/regenerator":17,"buffer":24}],47:[function(require,module,exports){
|
|
6913
6923
|
"use strict";
|
|
6914
6924
|
|
|
6915
6925
|
var Joi = require("joi");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coherentglobal/spark-execute-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/node.js",
|
|
6
6
|
"browser": "dist/browser.js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"build:types": "tsc --declaration",
|
|
10
10
|
"bundle:full": "browserify src/browser.js --standalone Spark > dist/browser.js",
|
|
11
11
|
"bundle:min": "browserify src/browser.js --standalone Spark | uglifyjs --compress --mangle --comments false > lib/sparkexecute.min.js",
|
|
12
|
-
"test": "npx mocha --bail --exit --recursive --timeout 100000 --reporter nyan"
|
|
12
|
+
"test": "npx mocha --bail --exit --recursive --timeout 100000 --reporter nyan",
|
|
13
|
+
"cover": "nyc --check-coverage --reporter=lcov --lines 60 mocha --bail --exit --recursive --timeout 100000"
|
|
13
14
|
},
|
|
14
15
|
"engines": {
|
|
15
16
|
"node": ">=14.0.0"
|
|
@@ -25,6 +26,7 @@
|
|
|
25
26
|
"@types/node": "^18.7.18",
|
|
26
27
|
"axios": "^0.27.2",
|
|
27
28
|
"chai": "^4.3.6",
|
|
29
|
+
"fs": "^0.0.1-security",
|
|
28
30
|
"got": "^11.8.3",
|
|
29
31
|
"http-status-codes": "^2.2.0",
|
|
30
32
|
"joi": "^17.6.0",
|
|
@@ -35,7 +37,6 @@
|
|
|
35
37
|
"uuid": "^9.0.0"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
38
|
-
"prettier": "^2.7.1",
|
|
39
40
|
"@babel/cli": "^7.18.10",
|
|
40
41
|
"@babel/core": "^7.19.0",
|
|
41
42
|
"@babel/plugin-transform-runtime": "^7.18.10",
|
|
@@ -49,10 +50,15 @@
|
|
|
49
50
|
"eslint-config-prettier": "^8.5.0",
|
|
50
51
|
"eslint-plugin-node": "^11.1.0",
|
|
51
52
|
"eslint-plugin-prettier": "^4.0.0",
|
|
53
|
+
"express": "^4.18.2",
|
|
52
54
|
"jest": "^29.0.2",
|
|
53
55
|
"jsdoc": "^3.6.11",
|
|
54
56
|
"mocha": "^10.0.0",
|
|
57
|
+
"nock": "^13.2.9",
|
|
58
|
+
"nyc": "^15.1.0",
|
|
59
|
+
"prettier": "^2.7.1",
|
|
55
60
|
"should": "^13.2.3",
|
|
61
|
+
"supertest": "^6.3.1",
|
|
56
62
|
"ts-node": "^10.9.1",
|
|
57
63
|
"typescript": "^4.8.3",
|
|
58
64
|
"uglify-js": "^3.17.0"
|