opengate-js 16.1.2 → 16.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/README.md +84 -8
- package/dist/{opengate-api-bower-16.1.2.js → opengate-api-bower-16.3.0.js} +1493 -1153
- package/dist/opengate-api-bower-16.3.0.js.map +6 -0
- package/dist/opengate-api-bower-16.3.0.min.js +117 -0
- package/dist/opengate-api-bower-16.3.0.min.js.map +6 -0
- package/dist/opengate-api-npm.js +4 -0
- package/dist/opengate-api-npm.js.map +1 -1
- package/dist/opengate-api-npm.mjs +167 -56
- package/dist/opengate-api-npm.mjs.map +2 -2
- package/dist/src/InternalOpenGateAPI.js +38 -2
- package/dist/src/InternalOpenGateAPI.js.map +1 -1
- package/dist/src/notebookScheduler/NotebookScheduler.js +13 -0
- package/dist/src/notebookScheduler/NotebookScheduler.js.map +1 -1
- package/dist/src/searching/AssetSearch.js +1 -1
- package/dist/src/searching/AssetSearch.js.map +1 -1
- package/dist/src/searching/BaseSearch.js +3 -3
- package/dist/src/searching/DeviceSearch.js +1 -1
- package/dist/src/searching/DeviceSearch.js.map +1 -1
- package/dist/src/searching/EntitySearch.js +1 -1
- package/dist/src/searching/EntitySearch.js.map +1 -1
- package/dist/src/searching/WPSearch.js +1 -1
- package/dist/src/searching/WPSearch.js.map +1 -1
- package/dist/src/security/Certificates.js +0 -14
- package/dist/src/security/Certificates.js.map +1 -1
- package/dist/src/util/NorthAmpliaREST.js +77 -2
- package/dist/src/util/NorthAmpliaREST.js.map +1 -1
- package/dist/src/util/http/RequestSpec.js +21 -10
- package/dist/src/util/http/RequestSpec.js.map +1 -1
- package/opengate-api-npm.js +6 -0
- package/package.json +2 -2
- package/src/InternalOpenGateAPI.js +46 -2
- package/src/notebookScheduler/NotebookScheduler.js +14 -0
- package/src/searching/AssetSearch.js +1 -1
- package/src/searching/BaseSearch.js +3 -3
- package/src/searching/DeviceSearch.js +1 -1
- package/src/searching/EntitySearch.js +1 -1
- package/src/searching/WPSearch.js +1 -1
- package/src/security/Certificates.js +0 -32
- package/src/util/NorthAmpliaREST.js +87 -2
- package/src/util/http/RequestSpec.js +29 -10
- package/types/opengate-api-npm.d.ts +7 -1
- package/types/src/InternalOpenGateAPI.d.ts +103 -8
- package/types/src/notebookScheduler/NotebookScheduler.d.ts +7 -0
- package/types/src/security/Certificates.d.ts +0 -1
- package/types/src/util/NorthAmpliaREST.d.ts +25 -0
- package/dist/opengate-api-bower-16.1.2.js.map +0 -6
- package/dist/opengate-api-bower-16.1.2.min.js +0 -116
- package/dist/opengate-api-bower-16.1.2.min.js.map +0 -6
package/dist/opengate-api-npm.js
CHANGED
|
@@ -35,6 +35,10 @@ var import_InternalOpenGateAPI = __toESM(require("./src/InternalOpenGateAPI"));
|
|
|
35
35
|
var import_NorthAmpliaREST = __toESM(require("./src/util/NorthAmpliaREST"));
|
|
36
36
|
var import_SouthAmpliaREST = __toESM(require("./src/util/SouthAmpliaREST"));
|
|
37
37
|
class OpenGateAPI extends import_InternalOpenGateAPI.default {
|
|
38
|
+
/**
|
|
39
|
+
* @param {import('./src/InternalOpenGateAPI').OpenGateOptions & Record<string, unknown>} _options - the client's
|
|
40
|
+
* configuration; see the README's Configuration section.
|
|
41
|
+
*/
|
|
38
42
|
constructor(_options) {
|
|
39
43
|
super(
|
|
40
44
|
new import_NorthAmpliaREST.default(_options, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../opengate-api-npm.js"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iCAAgC;AAChC,6BAA4B;AAC5B,6BAA4B;
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iCAAgC;AAChC,6BAA4B;AAC5B,6BAA4B;AAI5B,MAAO,oBAAkC,2BAAAA,QAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKzD,YAAY,UAAU;AAClB;AAAA,MACI,IAAI,uBAAAC,QAAgB,UAAU;AAAA,QAC1B,gBAAgB;AAAA,MACpB,CAAC;AAAA,MACD,IAAI,uBAAAC,QAAgB,UAAU;AAAA,QAC1B,gBAAgB;AAAA,MACpB,CAAC;AAAA,MACD;AAAA,IACJ;AAAA,EACJ;AACJ;",
|
|
5
5
|
"names": ["InternalOpenGateAPI", "NorthAmpliaREST", "SouthAmpliaREST"]
|
|
6
6
|
}
|
|
@@ -123,11 +123,11 @@ var require_check_types = __commonJS({
|
|
|
123
123
|
]);
|
|
124
124
|
}
|
|
125
125
|
},
|
|
126
|
-
_checkStringAndLength: function(parameter,
|
|
127
|
-
if (typeof parameter !== "string" || parameter.length >
|
|
126
|
+
_checkStringAndLength: function(parameter, length, name) {
|
|
127
|
+
if (typeof parameter !== "string" || parameter.length > length) {
|
|
128
128
|
throw checkError([
|
|
129
129
|
{ message: "OGAPI_STRING_PARAMETER", parameter: name },
|
|
130
|
-
{ message: "OGAPI_MAX_LENGTH", parameter:
|
|
130
|
+
{ message: "OGAPI_MAX_LENGTH", parameter: length }
|
|
131
131
|
]);
|
|
132
132
|
}
|
|
133
133
|
},
|
|
@@ -1367,8 +1367,8 @@ var BaseOperationBuilder = class {
|
|
|
1367
1367
|
_checkMandatoryParameters() {
|
|
1368
1368
|
if (this._config.parameters && this._config.parameters.schema) {
|
|
1369
1369
|
const validate = this._ajv.compile(this._config.parameters.schema);
|
|
1370
|
-
const
|
|
1371
|
-
if (!
|
|
1370
|
+
const valid = validate(this._build.parameters);
|
|
1371
|
+
if (!valid) {
|
|
1372
1372
|
throw new Error(validate.errors);
|
|
1373
1373
|
}
|
|
1374
1374
|
}
|
|
@@ -2412,19 +2412,6 @@ var Certificates = class extends Security {
|
|
|
2412
2412
|
this._usages = usages;
|
|
2413
2413
|
return this;
|
|
2414
2414
|
}
|
|
2415
|
-
_checkHardware(hardware) {
|
|
2416
|
-
if (typeof hardware === "string") {
|
|
2417
|
-
hardware = eval("(" + hardware + ")");
|
|
2418
|
-
}
|
|
2419
|
-
let length = Object.keys(hardware).length;
|
|
2420
|
-
let valid = false;
|
|
2421
|
-
if (length === 1 && hardware.hardwareId && typeof hardware.hardwareId === "string" && hardware.hardwareId.length > 0) {
|
|
2422
|
-
valid = true;
|
|
2423
|
-
} else if (length === 3 && hardware.manufacturer && hardware.model && hardware.modelVersion && typeof hardware.manufacturer === "string" && typeof hardware.model === "string" && typeof hardware.modelVersion === "string" && hardware.manufacturer.length > 0 && hardware.model.length > 0 && hardware.modelVersion.length > 0) {
|
|
2424
|
-
valid = true;
|
|
2425
|
-
}
|
|
2426
|
-
return valid;
|
|
2427
|
-
}
|
|
2428
2415
|
/**
|
|
2429
2416
|
* Set the tags attribute
|
|
2430
2417
|
* @param {Array} tags
|
|
@@ -2493,7 +2480,6 @@ var Certificates = class extends Security {
|
|
|
2493
2480
|
description: this._description || void 0,
|
|
2494
2481
|
administrativeState: this._administrativeState || void 0,
|
|
2495
2482
|
usages: this._usages || void 0,
|
|
2496
|
-
hardware: this._hardware || void 0,
|
|
2497
2483
|
tags: this._tags || void 0,
|
|
2498
2484
|
parameters: this._parameters || void 0,
|
|
2499
2485
|
domains: this._domains || void 0
|
|
@@ -3312,7 +3298,7 @@ var BaseSearch = class _BaseSearch {
|
|
|
3312
3298
|
execute() {
|
|
3313
3299
|
var defered = q9.defer();
|
|
3314
3300
|
var promise = defered.promise;
|
|
3315
|
-
this._ogapi.Napi.
|
|
3301
|
+
this._ogapi.Napi._searchPost(
|
|
3316
3302
|
this._resource,
|
|
3317
3303
|
this._filter(),
|
|
3318
3304
|
this._timeout,
|
|
@@ -3375,7 +3361,7 @@ var BaseSearch = class _BaseSearch {
|
|
|
3375
3361
|
this._setExtraHeaders({
|
|
3376
3362
|
Accept: "text/plain"
|
|
3377
3363
|
});
|
|
3378
|
-
this._ogapi.Napi.
|
|
3364
|
+
this._ogapi.Napi._searchPost(
|
|
3379
3365
|
this._resource,
|
|
3380
3366
|
filter,
|
|
3381
3367
|
this._timeout,
|
|
@@ -3427,7 +3413,7 @@ var BaseSearch = class _BaseSearch {
|
|
|
3427
3413
|
statusCode: 403
|
|
3428
3414
|
});
|
|
3429
3415
|
} else {
|
|
3430
|
-
_this._ogapi.Napi.
|
|
3416
|
+
_this._ogapi.Napi._searchPost(
|
|
3431
3417
|
_this._resource,
|
|
3432
3418
|
filter,
|
|
3433
3419
|
_this._timeout,
|
|
@@ -4953,7 +4939,7 @@ var WPSearch = class extends BaseSearch {
|
|
|
4953
4939
|
statusCode: 403
|
|
4954
4940
|
});
|
|
4955
4941
|
} else {
|
|
4956
|
-
_this._ogapi.Napi.
|
|
4942
|
+
_this._ogapi.Napi._searchPost(_this._resource, filter, _this._timeout, _this._getExtraHeaders(), _this._getUrlParameters()).then((response) => {
|
|
4957
4943
|
let statusCode = response.statusCode;
|
|
4958
4944
|
let body = response.body;
|
|
4959
4945
|
if (!body && response.text) {
|
|
@@ -8256,7 +8242,7 @@ var DeviceSearch = class extends Search {
|
|
|
8256
8242
|
var defered = q25.defer();
|
|
8257
8243
|
var promise = defered.promise;
|
|
8258
8244
|
var parameters = this._getUrlParameters();
|
|
8259
|
-
this._ogapi.Napi.
|
|
8245
|
+
this._ogapi.Napi._searchPost(this._resource, this._filter(), this._timeout, this._getExtraHeaders(), parameters).then((response) => {
|
|
8260
8246
|
let resultQuery = response.body;
|
|
8261
8247
|
let statusCode = response.statusCode;
|
|
8262
8248
|
if (statusCode === 200 && resultQuery.entities) {
|
|
@@ -8596,7 +8582,7 @@ var AssetSearch = class extends Search {
|
|
|
8596
8582
|
var defered = q26.defer();
|
|
8597
8583
|
var promise = defered.promise;
|
|
8598
8584
|
var parameters = this._getUrlParameters();
|
|
8599
|
-
this._ogapi.Napi.
|
|
8585
|
+
this._ogapi.Napi._searchPost(this._resource, this._filter(), this._timeout, this._getExtraHeaders(), parameters).then((response) => {
|
|
8600
8586
|
let resultQuery = response.body;
|
|
8601
8587
|
let statusCode = response.statusCode;
|
|
8602
8588
|
if (statusCode === 200) {
|
|
@@ -13186,9 +13172,9 @@ var Bundles = class extends BaseProvision {
|
|
|
13186
13172
|
* @param {string} hardware
|
|
13187
13173
|
* @return {Bundles}
|
|
13188
13174
|
*/
|
|
13189
|
-
withHardware(
|
|
13190
|
-
if (typeof
|
|
13191
|
-
this._hardware =
|
|
13175
|
+
withHardware(hardware) {
|
|
13176
|
+
if (typeof hardware !== "string") throw new Error("Parameter hardware must be a string");
|
|
13177
|
+
this._hardware = hardware;
|
|
13192
13178
|
return this;
|
|
13193
13179
|
}
|
|
13194
13180
|
/**
|
|
@@ -14002,7 +13988,7 @@ var Hardware = class {
|
|
|
14002
13988
|
return ret;
|
|
14003
13989
|
}
|
|
14004
13990
|
composeElement() {
|
|
14005
|
-
var
|
|
13991
|
+
var hardware = {
|
|
14006
13992
|
serialnumber: this._serialnumber,
|
|
14007
13993
|
manufacturer: {
|
|
14008
13994
|
name: this._manufacturerName,
|
|
@@ -14014,7 +14000,7 @@ var Hardware = class {
|
|
|
14014
14000
|
},
|
|
14015
14001
|
clockDate: this._clockDate
|
|
14016
14002
|
};
|
|
14017
|
-
return
|
|
14003
|
+
return hardware;
|
|
14018
14004
|
}
|
|
14019
14005
|
};
|
|
14020
14006
|
|
|
@@ -14601,11 +14587,11 @@ var Subscriber = class {
|
|
|
14601
14587
|
* @param {Hardware} hardware - optionals field
|
|
14602
14588
|
* @return {Subscriber}
|
|
14603
14589
|
*/
|
|
14604
|
-
withHardware(
|
|
14605
|
-
if (!(
|
|
14590
|
+
withHardware(hardware) {
|
|
14591
|
+
if (!(hardware instanceof Hardware)) {
|
|
14606
14592
|
throw new Error("Parameter hardware must be hardware type");
|
|
14607
14593
|
}
|
|
14608
|
-
this._hardware =
|
|
14594
|
+
this._hardware = hardware;
|
|
14609
14595
|
return this;
|
|
14610
14596
|
}
|
|
14611
14597
|
composeElement() {
|
|
@@ -14825,11 +14811,11 @@ var CommsModuleMessage = class {
|
|
|
14825
14811
|
* @param {Hardware} hardware - optionals field
|
|
14826
14812
|
* @return {CommsModule}
|
|
14827
14813
|
*/
|
|
14828
|
-
withHardware(
|
|
14829
|
-
if (!(
|
|
14814
|
+
withHardware(hardware) {
|
|
14815
|
+
if (!(hardware instanceof Hardware)) {
|
|
14830
14816
|
throw new Error("Parameter hardware must be hardware type");
|
|
14831
14817
|
}
|
|
14832
|
-
this._hardware =
|
|
14818
|
+
this._hardware = hardware;
|
|
14833
14819
|
return this;
|
|
14834
14820
|
}
|
|
14835
14821
|
/**
|
|
@@ -15020,11 +15006,11 @@ var Event = class {
|
|
|
15020
15006
|
* @param {Hardware} hardware - optionals field
|
|
15021
15007
|
* @return {Event}
|
|
15022
15008
|
*/
|
|
15023
|
-
withHardware(
|
|
15024
|
-
if (!(
|
|
15009
|
+
withHardware(hardware) {
|
|
15010
|
+
if (!(hardware instanceof Hardware)) {
|
|
15025
15011
|
throw new Error("Parameter hardware must be Hardware type");
|
|
15026
15012
|
}
|
|
15027
|
-
this._hardware =
|
|
15013
|
+
this._hardware = hardware;
|
|
15028
15014
|
return this;
|
|
15029
15015
|
}
|
|
15030
15016
|
/**
|
|
@@ -18417,7 +18403,7 @@ var EntitySearch = class extends Search {
|
|
|
18417
18403
|
var defered = q40.defer();
|
|
18418
18404
|
var promise = defered.promise;
|
|
18419
18405
|
var parameters = this._getUrlParameters();
|
|
18420
|
-
this._ogapi.Napi.
|
|
18406
|
+
this._ogapi.Napi._searchPost(this._resource, this._filter(), this._timeout, this._getExtraHeaders(), parameters).then((response) => {
|
|
18421
18407
|
let resultQuery = response.body;
|
|
18422
18408
|
let statusCode = response.statusCode;
|
|
18423
18409
|
if (statusCode === 200 && resultQuery.entities && resultQuery.entities.length > 0) {
|
|
@@ -19714,6 +19700,15 @@ function respond(route, request) {
|
|
|
19714
19700
|
}
|
|
19715
19701
|
|
|
19716
19702
|
// src/util/http/RequestSpec.js
|
|
19703
|
+
function transportError(message, reason) {
|
|
19704
|
+
const error = new Error(message);
|
|
19705
|
+
error.reason = reason;
|
|
19706
|
+
if (reason === "timeout") {
|
|
19707
|
+
error.timeout = true;
|
|
19708
|
+
error.code = "ECONNABORTED";
|
|
19709
|
+
}
|
|
19710
|
+
return error;
|
|
19711
|
+
}
|
|
19717
19712
|
var beforeStart;
|
|
19718
19713
|
function setBeforeStart(callback) {
|
|
19719
19714
|
beforeStart = callback;
|
|
@@ -19999,7 +19994,7 @@ var RequestSpec = class {
|
|
|
19999
19994
|
this.aborted = true;
|
|
20000
19995
|
this.clearTimeout();
|
|
20001
19996
|
if (this._xhr) this._xhr.abort();
|
|
20002
|
-
else if (this._controller) this._controller.abort(
|
|
19997
|
+
else if (this._controller) this._controller.abort(transportError("Request aborted", "aborted"));
|
|
20003
19998
|
this.emit("abort");
|
|
20004
19999
|
return this;
|
|
20005
20000
|
}
|
|
@@ -20293,7 +20288,7 @@ var RequestSpec = class {
|
|
|
20293
20288
|
}
|
|
20294
20289
|
_execute() {
|
|
20295
20290
|
return __async(this, null, function* () {
|
|
20296
|
-
if (this.aborted) throw
|
|
20291
|
+
if (this.aborted) throw transportError("Request aborted", "aborted");
|
|
20297
20292
|
const mocked = match(this.method, this.url);
|
|
20298
20293
|
if (mocked) {
|
|
20299
20294
|
const lowerCased = {};
|
|
@@ -20387,9 +20382,7 @@ var RequestSpec = class {
|
|
|
20387
20382
|
let expire;
|
|
20388
20383
|
const promise = new Promise((resolve, reject) => {
|
|
20389
20384
|
expire = (message) => {
|
|
20390
|
-
const error =
|
|
20391
|
-
error.timeout = true;
|
|
20392
|
-
error.code = "ECONNABORTED";
|
|
20385
|
+
const error = transportError(message, "timeout");
|
|
20393
20386
|
this.timedout = true;
|
|
20394
20387
|
if (this._xhr) this._xhr.abort();
|
|
20395
20388
|
else if (this._controller) this._controller.abort(error);
|
|
@@ -20411,7 +20404,11 @@ var RequestSpec = class {
|
|
|
20411
20404
|
if (duplex) init.duplex = duplex;
|
|
20412
20405
|
if (controller) init.signal = controller.signal;
|
|
20413
20406
|
if (this._withCredentials) init.credentials = "include";
|
|
20414
|
-
const
|
|
20407
|
+
const sent = fetch(this.url, init).catch((error) => {
|
|
20408
|
+
if (error && typeof error === "object" && !error.reason) error.reason = "network";
|
|
20409
|
+
throw error;
|
|
20410
|
+
});
|
|
20411
|
+
const raw = yield Promise.race([sent, expiry.promise]);
|
|
20415
20412
|
if (this._responseTimer) {
|
|
20416
20413
|
clearTimeout(this._responseTimer);
|
|
20417
20414
|
this._responseTimer = null;
|
|
@@ -20453,7 +20450,7 @@ var RequestSpec = class {
|
|
|
20453
20450
|
const xhr = new XMLHttpRequest();
|
|
20454
20451
|
this._xhr = xhr;
|
|
20455
20452
|
if (this.aborted) {
|
|
20456
|
-
reject(
|
|
20453
|
+
reject(transportError("Request aborted", "aborted"));
|
|
20457
20454
|
return;
|
|
20458
20455
|
}
|
|
20459
20456
|
const expiry = this._expiry();
|
|
@@ -20497,9 +20494,9 @@ var RequestSpec = class {
|
|
|
20497
20494
|
if (!this._isResponseOK(response)) reject(toError(response));
|
|
20498
20495
|
else resolve(response);
|
|
20499
20496
|
};
|
|
20500
|
-
xhr.onerror = () => reject(
|
|
20501
|
-
xhr.ontimeout = () => reject(
|
|
20502
|
-
xhr.onabort = () => reject(
|
|
20497
|
+
xhr.onerror = () => reject(transportError("Network error", "network"));
|
|
20498
|
+
xhr.ontimeout = () => reject(transportError("Timeout of " + this._timeout + "ms exceeded", "timeout"));
|
|
20499
|
+
xhr.onabort = () => reject(transportError("Request aborted", "aborted"));
|
|
20503
20500
|
xhr.send(body === void 0 ? null : body);
|
|
20504
20501
|
});
|
|
20505
20502
|
}
|
|
@@ -22669,6 +22666,16 @@ var NotebookScheduler = class extends BaseProvision {
|
|
|
22669
22666
|
this._reportRetentionDays = reportRetentionDays;
|
|
22670
22667
|
return this;
|
|
22671
22668
|
}
|
|
22669
|
+
/**
|
|
22670
|
+
* Sets the timezone attribute
|
|
22671
|
+
* @param {string} timezone
|
|
22672
|
+
* @return {NotebookScheduler}
|
|
22673
|
+
*/
|
|
22674
|
+
withTimezone(timezone) {
|
|
22675
|
+
import_check_types11.default._checkString(timezone, "timezone");
|
|
22676
|
+
this._timezone = timezone;
|
|
22677
|
+
return this;
|
|
22678
|
+
}
|
|
22672
22679
|
withParams(params) {
|
|
22673
22680
|
import_check_types11.default._checkArray(params, "params");
|
|
22674
22681
|
this._params = params;
|
|
@@ -22683,6 +22690,9 @@ var NotebookScheduler = class extends BaseProvision {
|
|
|
22683
22690
|
generateReport: this._generateReport || false,
|
|
22684
22691
|
params: this._params || []
|
|
22685
22692
|
};
|
|
22693
|
+
if (this._timezone) {
|
|
22694
|
+
notebookData.timeZone = this._timezone;
|
|
22695
|
+
}
|
|
22686
22696
|
return notebookData;
|
|
22687
22697
|
}
|
|
22688
22698
|
create() {
|
|
@@ -23885,8 +23895,9 @@ var registerBeforeStartHook = setBeforeStart;
|
|
|
23885
23895
|
var InternalOpenGateAPI = class _InternalOpenGateAPI {
|
|
23886
23896
|
/**
|
|
23887
23897
|
* Constructor
|
|
23888
|
-
* @param {
|
|
23889
|
-
* @param {
|
|
23898
|
+
* @param {object} northAmpliaREST - the client that sends requests to the North API.
|
|
23899
|
+
* @param {object} southAmpliaREST - the client that sends requests to the South API.
|
|
23900
|
+
* @param {OpenGateOptions & Record<string, unknown>} _options - the client's configuration.
|
|
23890
23901
|
*/
|
|
23891
23902
|
constructor(northAmpliaREST, southAmpliaREST, _options) {
|
|
23892
23903
|
if (this.constructor === _InternalOpenGateAPI) {
|
|
@@ -23904,6 +23915,7 @@ var InternalOpenGateAPI = class _InternalOpenGateAPI {
|
|
|
23904
23915
|
if (_options.hooks && _options.hooks.beforeStart && typeof _options.hooks.beforeStart === "function") {
|
|
23905
23916
|
registerBeforeStartHook(_options.hooks.beforeStart);
|
|
23906
23917
|
}
|
|
23918
|
+
Object.defineProperty(this, "_options", { value: Object.freeze(__spreadValues({}, _options)) });
|
|
23907
23919
|
this.Napi = northAmpliaREST;
|
|
23908
23920
|
this.Sapi = southAmpliaREST;
|
|
23909
23921
|
this.EX = Expression;
|
|
@@ -23912,6 +23924,26 @@ var InternalOpenGateAPI = class _InternalOpenGateAPI {
|
|
|
23912
23924
|
this.alarms = new AlarmActions(this);
|
|
23913
23925
|
this.entityBuilder = new EntityBuilder(this);
|
|
23914
23926
|
}
|
|
23927
|
+
/**
|
|
23928
|
+
* A new client with this one's options, and the given ones on top. The merge is shallow: an
|
|
23929
|
+
* override of `south` replaces the whole object.
|
|
23930
|
+
*
|
|
23931
|
+
* A clone of a read-only client is read-only too, and asking for `readOnly: false` throws: code
|
|
23932
|
+
* handed a read-only client cannot widen it this way. `logger` and `hooks` are process-wide, so
|
|
23933
|
+
* overriding them in a clone changes them for every client.
|
|
23934
|
+
* @example
|
|
23935
|
+
* const widgetApi = ogapi.clone({ readOnly: true });
|
|
23936
|
+
* @param {Partial<OpenGateOptions> & Record<string, unknown>} [overrides] - the options to change.
|
|
23937
|
+
* @return {this}
|
|
23938
|
+
*/
|
|
23939
|
+
clone(overrides = {}) {
|
|
23940
|
+
if (this._options.readOnly && "readOnly" in overrides && !overrides.readOnly) {
|
|
23941
|
+
throw new Error("OGAPI: a clone of a read-only client is read-only too");
|
|
23942
|
+
}
|
|
23943
|
+
const options = __spreadValues(__spreadValues({}, this._options), overrides);
|
|
23944
|
+
if (this._options.readOnly) options.readOnly = true;
|
|
23945
|
+
return new this.constructor(options);
|
|
23946
|
+
}
|
|
23915
23947
|
/**
|
|
23916
23948
|
* This returns a util to find a user
|
|
23917
23949
|
* @return {UserFinder}
|
|
@@ -25031,6 +25063,8 @@ var NorthAmpliaREST = class {
|
|
|
25031
25063
|
* @return {Promise}
|
|
25032
25064
|
*/
|
|
25033
25065
|
get(url, timeout, headers, parameters, asBlob, serviceBaseURL) {
|
|
25066
|
+
const rejected = this._guard("GET", url, serviceBaseURL);
|
|
25067
|
+
if (rejected) return rejected;
|
|
25034
25068
|
const _url = this._createUrl(url, parameters, serviceBaseURL);
|
|
25035
25069
|
logger_default.info("GET", _url);
|
|
25036
25070
|
var req = new RequestSpec("GET", _url);
|
|
@@ -25047,6 +25081,8 @@ var NorthAmpliaREST = class {
|
|
|
25047
25081
|
* @return {Promise}
|
|
25048
25082
|
*/
|
|
25049
25083
|
patch(url, data, timeout, headers, parameters, serviceBaseURL) {
|
|
25084
|
+
const rejected = this._guard("PATCH", url, serviceBaseURL);
|
|
25085
|
+
if (rejected) return rejected;
|
|
25050
25086
|
const _url = this._createUrl(url, parameters, serviceBaseURL);
|
|
25051
25087
|
logger_default.info("PATCH", _url);
|
|
25052
25088
|
var req = new RequestSpec("PATCH", _url).send(data);
|
|
@@ -25063,6 +25099,8 @@ var NorthAmpliaREST = class {
|
|
|
25063
25099
|
* @return {Promise}
|
|
25064
25100
|
*/
|
|
25065
25101
|
post(url, data, timeout, headers, parameters, serviceBaseURL) {
|
|
25102
|
+
const rejected = this._guard("POST", url, serviceBaseURL);
|
|
25103
|
+
if (rejected) return rejected;
|
|
25066
25104
|
const _url = this._createUrl(url, parameters, serviceBaseURL);
|
|
25067
25105
|
logger_default.info("POST", _url);
|
|
25068
25106
|
var req = new RequestSpec("POST", _url).send(data);
|
|
@@ -25080,6 +25118,8 @@ var NorthAmpliaREST = class {
|
|
|
25080
25118
|
* @return {Promise}
|
|
25081
25119
|
*/
|
|
25082
25120
|
post_multipart(url, formData, events, timeout, headers, parameters, serviceBaseURL) {
|
|
25121
|
+
const rejected = this._guard("POST", url, serviceBaseURL);
|
|
25122
|
+
if (rejected) return rejected;
|
|
25083
25123
|
const _url = this._createUrl(url, parameters, serviceBaseURL);
|
|
25084
25124
|
logger_default.info("POST_MULTIPART", _url);
|
|
25085
25125
|
let req = new RequestSpec("POST", _url);
|
|
@@ -25097,6 +25137,8 @@ var NorthAmpliaREST = class {
|
|
|
25097
25137
|
* @return {Promise}
|
|
25098
25138
|
*/
|
|
25099
25139
|
put(url, data, timeout, headers, parameters, serviceBaseURL) {
|
|
25140
|
+
const rejected = this._guard("PUT", url, serviceBaseURL);
|
|
25141
|
+
if (rejected) return rejected;
|
|
25100
25142
|
const _url = this._createUrl(url, parameters, serviceBaseURL);
|
|
25101
25143
|
logger_default.info("PUT", _url);
|
|
25102
25144
|
var req = new RequestSpec("PUT", _url).send(data);
|
|
@@ -25121,6 +25163,8 @@ var NorthAmpliaREST = class {
|
|
|
25121
25163
|
* @return {Promise}
|
|
25122
25164
|
*/
|
|
25123
25165
|
put_multipart(url, formData, events, timeout, headers, parameters, serviceBaseURL) {
|
|
25166
|
+
const rejected = this._guard("PUT", url, serviceBaseURL);
|
|
25167
|
+
if (rejected) return rejected;
|
|
25124
25168
|
const _url = this._createUrl(url, parameters, serviceBaseURL);
|
|
25125
25169
|
logger_default.info("PUT_MULTIPART", _url);
|
|
25126
25170
|
let req = new RequestSpec("PUT", _url);
|
|
@@ -25194,6 +25238,8 @@ var NorthAmpliaREST = class {
|
|
|
25194
25238
|
* @return {Promise}
|
|
25195
25239
|
*/
|
|
25196
25240
|
delete(url, timeout, headers, parameters, body, serviceBaseURL) {
|
|
25241
|
+
const rejected = this._guard("DELETE", url, serviceBaseURL);
|
|
25242
|
+
if (rejected) return rejected;
|
|
25197
25243
|
const _url = this._createUrl(url, parameters, serviceBaseURL);
|
|
25198
25244
|
logger_default.info("DELETE", _url);
|
|
25199
25245
|
var req;
|
|
@@ -25219,9 +25265,9 @@ var NorthAmpliaREST = class {
|
|
|
25219
25265
|
}
|
|
25220
25266
|
}
|
|
25221
25267
|
var relativeUrlSplit = relativeUrl.split("/");
|
|
25222
|
-
var
|
|
25268
|
+
var length = relativeUrlSplit.length;
|
|
25223
25269
|
relativeUrlSplit.forEach(function(item, index) {
|
|
25224
|
-
if (index ===
|
|
25270
|
+
if (index === length - 1 && item.indexOf("?") > 0) {
|
|
25225
25271
|
var parameters2 = item.substring(item.indexOf("?"), item.length);
|
|
25226
25272
|
var _item = item.substring(0, item.indexOf("?"));
|
|
25227
25273
|
encode.push(urlencode(_item) + parameters2);
|
|
@@ -25231,6 +25277,62 @@ var NorthAmpliaREST = class {
|
|
|
25231
25277
|
});
|
|
25232
25278
|
return this._url(this._options) + "/" + this._getDefaultBaseURL(serviceBaseURL) + "/" + encode.join("/");
|
|
25233
25279
|
}
|
|
25280
|
+
/**
|
|
25281
|
+
* POST for a search, which reads. The search layer calls this instead of `post` so that a
|
|
25282
|
+
* read-only client lets it through; the mark lasts only for the synchronous guard inside `post`.
|
|
25283
|
+
* @return {Promise}
|
|
25284
|
+
*/
|
|
25285
|
+
_searchPost(url, data, timeout, headers, parameters, serviceBaseURL) {
|
|
25286
|
+
this._searchIntent = true;
|
|
25287
|
+
try {
|
|
25288
|
+
return this.post(url, data, timeout, headers, parameters, serviceBaseURL);
|
|
25289
|
+
} finally {
|
|
25290
|
+
this._searchIntent = false;
|
|
25291
|
+
}
|
|
25292
|
+
}
|
|
25293
|
+
/** @return {Promise|null} a rejection to return before sending, or null to go ahead. */
|
|
25294
|
+
_guard(method, url, serviceBaseURL) {
|
|
25295
|
+
return this._rejectDuplicatedBase(url, serviceBaseURL) || this._rejectWrite(method, url);
|
|
25296
|
+
}
|
|
25297
|
+
/**
|
|
25298
|
+
* With `readOnly`, everything but GET and search POSTs is refused before it leaves: the search
|
|
25299
|
+
* builders, and a free `post` to a `search/...` path. It guards against mistakes, not against
|
|
25300
|
+
* code that holds the client and means harm -- `_searchPost` and `fetch` are one call away. The
|
|
25301
|
+
* server, or a proxy in front of it, remains the boundary.
|
|
25302
|
+
* @return {Promise|null}
|
|
25303
|
+
*/
|
|
25304
|
+
_rejectWrite(method, url) {
|
|
25305
|
+
if (!this._options.readOnly || method === "GET") return null;
|
|
25306
|
+
const isSearch = this._searchIntent || typeof url === "string" && /^\/*search\//.test(url);
|
|
25307
|
+
if (method === "POST" && isSearch) return null;
|
|
25308
|
+
const message = "OGAPI: read-only client refused " + method + " " + url;
|
|
25309
|
+
return q50.reject({
|
|
25310
|
+
statusCode: 403,
|
|
25311
|
+
data: { errors: [{ code: 403, message }] },
|
|
25312
|
+
reason: "read-only",
|
|
25313
|
+
cause: new Error(message)
|
|
25314
|
+
});
|
|
25315
|
+
}
|
|
25316
|
+
/**
|
|
25317
|
+
* The default base (`north/v80`, or `v80` on South) is prepended to every path, so a path that
|
|
25318
|
+
* repeats it, such as `/north/v80/provision/...`, used to reach `north/v80//north/v80/...` and
|
|
25319
|
+
* fail with a misleading error. Such a call never worked, so refusing it breaks nothing. A
|
|
25320
|
+
* caller-given `serviceBaseURL` is left alone: its paths are its own business.
|
|
25321
|
+
* @return {Promise|null} a rejection to return, or null when the path is fine.
|
|
25322
|
+
*/
|
|
25323
|
+
_rejectDuplicatedBase(url, serviceBaseURL) {
|
|
25324
|
+
if (serviceBaseURL || typeof url !== "string") return null;
|
|
25325
|
+
const base = this._getDefaultBaseURL();
|
|
25326
|
+
const firstSegment = base.split("/")[0];
|
|
25327
|
+
if (url.replace(/^\/+/, "").split("/")[0] !== firstSegment) return null;
|
|
25328
|
+
const message = 'OGAPI: the path "' + url + '" already starts with "' + firstSegment + '/", but "' + base + '/" is prepended to every path. Pass the path relative to it, or give a serviceBaseURL.';
|
|
25329
|
+
return q50.reject({
|
|
25330
|
+
statusCode: 400,
|
|
25331
|
+
data: { errors: [{ code: 400, message }] },
|
|
25332
|
+
reason: "invalid-path",
|
|
25333
|
+
cause: new Error(message)
|
|
25334
|
+
});
|
|
25335
|
+
}
|
|
25234
25336
|
_getDefaultBaseURL(serviceBaseURL) {
|
|
25235
25337
|
if (!serviceBaseURL) {
|
|
25236
25338
|
if (this._isSouth) {
|
|
@@ -25298,11 +25400,16 @@ var NorthAmpliaREST = class {
|
|
|
25298
25400
|
status = 408;
|
|
25299
25401
|
}
|
|
25300
25402
|
}
|
|
25301
|
-
|
|
25403
|
+
const rejection = {
|
|
25302
25404
|
statusCode: status,
|
|
25303
25405
|
data,
|
|
25304
25406
|
headers: headers2
|
|
25305
|
-
}
|
|
25407
|
+
};
|
|
25408
|
+
if (typeof err.response === "undefined") {
|
|
25409
|
+
rejection.reason = err.reason || "unknown";
|
|
25410
|
+
rejection.cause = err;
|
|
25411
|
+
}
|
|
25412
|
+
defered.reject(rejection);
|
|
25306
25413
|
} else {
|
|
25307
25414
|
defered.resolve(res);
|
|
25308
25415
|
}
|
|
@@ -25327,6 +25434,10 @@ var SouthAmpliaREST = class extends NorthAmpliaREST {
|
|
|
25327
25434
|
|
|
25328
25435
|
// opengate-api-npm.js
|
|
25329
25436
|
var OpenGateAPI = class extends InternalOpenGateAPI {
|
|
25437
|
+
/**
|
|
25438
|
+
* @param {import('./src/InternalOpenGateAPI').OpenGateOptions & Record<string, unknown>} _options - the client's
|
|
25439
|
+
* configuration; see the README's Configuration section.
|
|
25440
|
+
*/
|
|
25330
25441
|
constructor(_options) {
|
|
25331
25442
|
super(
|
|
25332
25443
|
new NorthAmpliaREST(_options, {
|