@coherentglobal/spark-execute-sdk 0.4.5 → 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 +152 -141
- package/package.json +9 -3
- package/src/browser.js +42 -154
- 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) {
|
|
@@ -6423,8 +6334,17 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6423
6334
|
return lookup[this.priority[0]](input, versionID, this);
|
|
6424
6335
|
case 4:
|
|
6425
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:
|
|
6426
6346
|
return _context.abrupt("return", response);
|
|
6427
|
-
case
|
|
6347
|
+
case 10:
|
|
6428
6348
|
case "end":
|
|
6429
6349
|
return _context.stop();
|
|
6430
6350
|
}
|
|
@@ -6445,8 +6365,8 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6445
6365
|
while (1) {
|
|
6446
6366
|
switch (_context3.prev = _context3.next) {
|
|
6447
6367
|
case 0:
|
|
6448
|
-
model =
|
|
6449
|
-
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);
|
|
6450
6370
|
if (!(input !== null && input !== void 0 && input.request_meta)) {
|
|
6451
6371
|
input.request_meta = {};
|
|
6452
6372
|
}
|
|
@@ -6462,7 +6382,7 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6462
6382
|
* @returns
|
|
6463
6383
|
*/
|
|
6464
6384
|
callback = /*#__PURE__*/function () {
|
|
6465
|
-
var
|
|
6385
|
+
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(options) {
|
|
6466
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;
|
|
6467
6387
|
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
6468
6388
|
while (1) {
|
|
@@ -6509,7 +6429,7 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6509
6429
|
}, _callee2);
|
|
6510
6430
|
}));
|
|
6511
6431
|
return function callback(_x6) {
|
|
6512
|
-
return
|
|
6432
|
+
return _ref2.apply(this, arguments);
|
|
6513
6433
|
};
|
|
6514
6434
|
}();
|
|
6515
6435
|
registry = new WasmRunner("", callback);
|
|
@@ -6518,7 +6438,7 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6518
6438
|
_context3.next = 10;
|
|
6519
6439
|
break;
|
|
6520
6440
|
}
|
|
6521
|
-
_model2 =
|
|
6441
|
+
_model2 = findModel(input.request_meta, ds.model);
|
|
6522
6442
|
_context3.next = 10;
|
|
6523
6443
|
return registry.append({
|
|
6524
6444
|
id: modelVersionId,
|
|
@@ -6554,33 +6474,42 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6554
6474
|
key: "onlineModelEndpoint",
|
|
6555
6475
|
value: function () {
|
|
6556
6476
|
var _onlineModelEndpoint = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(input, versionID, ds) {
|
|
6557
|
-
var token, header, options, modelUrl, response, result;
|
|
6477
|
+
var isPublic, token, header, options, modelUrl, response, result;
|
|
6558
6478
|
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
6559
6479
|
while (1) {
|
|
6560
6480
|
switch (_context4.prev = _context4.next) {
|
|
6561
6481
|
case 0:
|
|
6482
|
+
isPublic = ds.authType === "public";
|
|
6562
6483
|
token = "";
|
|
6484
|
+
if (isPublic) {
|
|
6485
|
+
_context4.next = 12;
|
|
6486
|
+
break;
|
|
6487
|
+
}
|
|
6563
6488
|
if (!(ds.token.constructor.name === "AsyncFunction")) {
|
|
6564
|
-
_context4.next =
|
|
6489
|
+
_context4.next = 9;
|
|
6565
6490
|
break;
|
|
6566
6491
|
}
|
|
6567
|
-
_context4.next =
|
|
6492
|
+
_context4.next = 6;
|
|
6568
6493
|
return ds.token();
|
|
6569
|
-
case
|
|
6494
|
+
case 6:
|
|
6570
6495
|
token = _context4.sent;
|
|
6571
|
-
_context4.next =
|
|
6496
|
+
_context4.next = 10;
|
|
6572
6497
|
break;
|
|
6573
|
-
case
|
|
6574
|
-
|
|
6575
|
-
|
|
6498
|
+
case 9:
|
|
6499
|
+
if (typeof ds.token === "function") {
|
|
6500
|
+
token = ds.token();
|
|
6501
|
+
} else {
|
|
6502
|
+
token = ds.token;
|
|
6503
|
+
}
|
|
6504
|
+
case 10:
|
|
6576
6505
|
if (!utils.isEmpty(ds.token)) {
|
|
6577
|
-
_context4.next =
|
|
6506
|
+
_context4.next = 12;
|
|
6578
6507
|
break;
|
|
6579
6508
|
}
|
|
6580
6509
|
throw new WasmRunnerErrors.UnauthorizedError();
|
|
6581
|
-
case
|
|
6582
|
-
_context4.prev =
|
|
6583
|
-
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) : {};
|
|
6584
6513
|
options = {
|
|
6585
6514
|
method: "POST",
|
|
6586
6515
|
body: JSON.stringify({
|
|
@@ -6591,26 +6520,26 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6591
6520
|
"content-type": "application/json"
|
|
6592
6521
|
}), header)
|
|
6593
6522
|
};
|
|
6594
|
-
modelUrl = new URL("/".concat(ds.tenant, "/api/v3/execute"), ds.url);
|
|
6595
|
-
_context4.next =
|
|
6523
|
+
modelUrl = new URL("/".concat(ds.tenant, "/api/v3/").concat(!isPublic ? "execute" : "public"), ds.url);
|
|
6524
|
+
_context4.next = 18;
|
|
6596
6525
|
return fetch(modelUrl, options);
|
|
6597
|
-
case
|
|
6526
|
+
case 18:
|
|
6598
6527
|
response = _context4.sent;
|
|
6599
|
-
_context4.next =
|
|
6528
|
+
_context4.next = 21;
|
|
6600
6529
|
return response.json();
|
|
6601
|
-
case
|
|
6530
|
+
case 21:
|
|
6602
6531
|
result = _context4.sent;
|
|
6603
6532
|
return _context4.abrupt("return", result);
|
|
6604
|
-
case
|
|
6605
|
-
_context4.prev =
|
|
6606
|
-
_context4.t0 = _context4["catch"](
|
|
6533
|
+
case 25:
|
|
6534
|
+
_context4.prev = 25;
|
|
6535
|
+
_context4.t0 = _context4["catch"](12);
|
|
6607
6536
|
return _context4.abrupt("return", _context4.t0);
|
|
6608
|
-
case
|
|
6537
|
+
case 28:
|
|
6609
6538
|
case "end":
|
|
6610
6539
|
return _context4.stop();
|
|
6611
6540
|
}
|
|
6612
6541
|
}
|
|
6613
|
-
}, _callee4, null, [[
|
|
6542
|
+
}, _callee4, null, [[12, 25]]);
|
|
6614
6543
|
}));
|
|
6615
6544
|
function onlineModelEndpoint(_x7, _x8, _x9) {
|
|
6616
6545
|
return _onlineModelEndpoint.apply(this, arguments);
|
|
@@ -6622,7 +6551,7 @@ var Spark = /*#__PURE__*/function () {
|
|
|
6622
6551
|
}();
|
|
6623
6552
|
module.exports = Spark;
|
|
6624
6553
|
|
|
6625
|
-
},{"./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){
|
|
6626
6555
|
"use strict";
|
|
6627
6556
|
|
|
6628
6557
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
@@ -6765,6 +6694,98 @@ module.exports = {
|
|
|
6765
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){
|
|
6766
6695
|
"use strict";
|
|
6767
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
|
+
|
|
6768
6789
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6769
6790
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
6770
6791
|
var WasmRunnerErrors = require("../error.js");
|
|
@@ -6830,7 +6851,7 @@ module.exports = {
|
|
|
6830
6851
|
getAuthHeaders: getAuthHeaders
|
|
6831
6852
|
};
|
|
6832
6853
|
|
|
6833
|
-
},{"../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){
|
|
6834
6855
|
(function (Buffer){(function (){
|
|
6835
6856
|
"use strict";
|
|
6836
6857
|
|
|
@@ -6848,7 +6869,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
6848
6869
|
*/
|
|
6849
6870
|
var processModels = function processModels(nodegen) {
|
|
6850
6871
|
var processedModels = _objectSpread({}, nodegen);
|
|
6851
|
-
// console.log('MODELS TO PROCESS: ', processedModels)
|
|
6852
6872
|
switch (nodegen.type) {
|
|
6853
6873
|
case "binary":
|
|
6854
6874
|
case "uint8array":
|
|
@@ -6861,13 +6881,10 @@ var processModels = function processModels(nodegen) {
|
|
|
6861
6881
|
data: Buffer.from(nodegen.binary.data, "base64")
|
|
6862
6882
|
};
|
|
6863
6883
|
processedModels.binary = model;
|
|
6864
|
-
// nodegen.binary = model;
|
|
6865
6884
|
} else {
|
|
6866
6885
|
var _model = Buffer.from(nodegen.binary, "base64");
|
|
6867
6886
|
processedModels.binary = _model;
|
|
6868
|
-
// nodegen.binary = model;
|
|
6869
6887
|
}
|
|
6870
|
-
|
|
6871
6888
|
break;
|
|
6872
6889
|
case "function":
|
|
6873
6890
|
var func = nodegen.binary;
|
|
@@ -6882,10 +6899,8 @@ var processModels = function processModels(nodegen) {
|
|
|
6882
6899
|
return func();
|
|
6883
6900
|
case 2:
|
|
6884
6901
|
processedModels.binary = _context.sent;
|
|
6885
|
-
// nodegen.binary = await func();
|
|
6886
6902
|
model = Buffer.from(nodegen.binary, "base64");
|
|
6887
6903
|
processedModels.binary = model;
|
|
6888
|
-
// nodegen.binary = model;
|
|
6889
6904
|
case 5:
|
|
6890
6905
|
case "end":
|
|
6891
6906
|
return _context.stop();
|
|
@@ -6894,12 +6909,8 @@ var processModels = function processModels(nodegen) {
|
|
|
6894
6909
|
}, _callee);
|
|
6895
6910
|
}))();
|
|
6896
6911
|
} else {
|
|
6897
|
-
|
|
6898
|
-
var _model2 = Buffer.from(nodegen.binary, "base64");
|
|
6899
|
-
processedModels.binary = _model2;
|
|
6900
|
-
// nodegen.binary = model;
|
|
6912
|
+
processedModels.binary = func();
|
|
6901
6913
|
}
|
|
6902
|
-
|
|
6903
6914
|
default:
|
|
6904
6915
|
break;
|
|
6905
6916
|
}
|
|
@@ -6908,7 +6919,7 @@ var processModels = function processModels(nodegen) {
|
|
|
6908
6919
|
module.exports = processModels;
|
|
6909
6920
|
|
|
6910
6921
|
}).call(this)}).call(this,require("buffer").Buffer)
|
|
6911
|
-
},{"@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){
|
|
6912
6923
|
"use strict";
|
|
6913
6924
|
|
|
6914
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"
|