@xapp/stentor-service 1.40.228 → 1.40.231
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/lib/FetchService.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/*! Copyright (c) 2019, XAPPmedia */
|
|
2
2
|
import "isomorphic-fetch";
|
|
3
|
+
import "abort-controller/polyfill";
|
|
3
4
|
import { AbstractService } from "./Service";
|
|
5
|
+
export declare class TimeoutError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
4
8
|
/**
|
|
5
9
|
* Abstract service for services that primarily rely on the fetch API.
|
|
6
10
|
*
|
|
11
|
+
* It includes built-in timeout feature to better keep track of external APIs.
|
|
12
|
+
*
|
|
7
13
|
* @export
|
|
8
14
|
* @abstract
|
|
9
15
|
* @class FetchService
|
|
@@ -13,11 +19,13 @@ export declare abstract class FetchService extends AbstractService {
|
|
|
13
19
|
/**
|
|
14
20
|
* Wrapper around fetch to add some basic diagnostics
|
|
15
21
|
*
|
|
22
|
+
* Will throw a TimeoutError if the timeout is reached.
|
|
23
|
+
*
|
|
16
24
|
* @protected
|
|
17
25
|
* @param {string} url
|
|
18
26
|
* @param {RequestInit} options
|
|
19
27
|
* @returns {Promise<Response>}
|
|
20
28
|
* @memberof AbstractResourceService
|
|
21
29
|
*/
|
|
22
|
-
protected fetch(url: string, options
|
|
30
|
+
protected fetch(url: string, options?: RequestInit): Promise<Response>;
|
|
23
31
|
}
|
package/lib/FetchService.js
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FetchService = void 0;
|
|
3
|
+
exports.FetchService = exports.TimeoutError = void 0;
|
|
4
4
|
/*! Copyright (c) 2019, XAPPmedia */
|
|
5
5
|
require("isomorphic-fetch");
|
|
6
|
+
require("abort-controller/polyfill");
|
|
6
7
|
const Service_1 = require("./Service");
|
|
7
8
|
const now = require("performance-now");
|
|
9
|
+
class TimeoutError extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "TimeoutError";
|
|
13
|
+
Error.captureStackTrace(this, this.constructor);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.TimeoutError = TimeoutError;
|
|
8
17
|
/**
|
|
9
18
|
* Abstract service for services that primarily rely on the fetch API.
|
|
10
19
|
*
|
|
20
|
+
* It includes built-in timeout feature to better keep track of external APIs.
|
|
21
|
+
*
|
|
11
22
|
* @export
|
|
12
23
|
* @abstract
|
|
13
24
|
* @class FetchService
|
|
@@ -17,6 +28,8 @@ class FetchService extends Service_1.AbstractService {
|
|
|
17
28
|
/**
|
|
18
29
|
* Wrapper around fetch to add some basic diagnostics
|
|
19
30
|
*
|
|
31
|
+
* Will throw a TimeoutError if the timeout is reached.
|
|
32
|
+
*
|
|
20
33
|
* @protected
|
|
21
34
|
* @param {string} url
|
|
22
35
|
* @param {RequestInit} options
|
|
@@ -25,12 +38,33 @@ class FetchService extends Service_1.AbstractService {
|
|
|
25
38
|
*/
|
|
26
39
|
fetch(url, options) {
|
|
27
40
|
const start = now();
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
if (options) {
|
|
43
|
+
if (!options.signal) {
|
|
44
|
+
options.signal = controller.signal;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
options = {
|
|
49
|
+
signal: controller.signal
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const timeout = setTimeout(() => {
|
|
53
|
+
controller.abort();
|
|
54
|
+
}, this.timeout);
|
|
28
55
|
return fetch(url, options).then(response => {
|
|
29
56
|
const end = now();
|
|
30
57
|
if (this.logs) {
|
|
31
|
-
console.info(`Resource took ${url} ${end - start}ms to receive`);
|
|
58
|
+
console.info(`Resource took ${url} ${end - start} ms to receive`);
|
|
32
59
|
}
|
|
33
60
|
return response;
|
|
61
|
+
}).catch((error) => {
|
|
62
|
+
if (error.name === "AbortError") {
|
|
63
|
+
throw new TimeoutError(`Timeout of ${this.timeout} ms reached.`);
|
|
64
|
+
}
|
|
65
|
+
throw error;
|
|
66
|
+
}).finally(() => {
|
|
67
|
+
clearTimeout(timeout);
|
|
34
68
|
});
|
|
35
69
|
}
|
|
36
70
|
}
|
package/lib/FetchService.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchService.js","sourceRoot":"","sources":["../src/FetchService.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,4BAA0B;AAC1B,uCAA4C;AAE5C,MAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAEvC
|
|
1
|
+
{"version":3,"file":"FetchService.js","sourceRoot":"","sources":["../src/FetchService.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,4BAA0B;AAC1B,qCAAkC;AAElC,uCAA4C;AAE5C,MAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAEvC,MAAa,YAAa,SAAQ,KAAK;IAEnC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACpD,CAAC;CACJ;AAPD,oCAOC;AAGD;;;;;;;;;GASG;AACH,MAAsB,YAAa,SAAQ,yBAAe;IACtD;;;;;;;;;;OAUG;IACO,KAAK,CAAC,GAAW,EAAE,OAAqB;QAC9C,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC;QAEpB,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAA;QAExC,IAAI,OAAO,EAAE;YACT,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;gBACjB,OAAO,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;aACtC;SACJ;aAAM;YACH,OAAO,GAAG;gBACN,MAAM,EAAE,UAAU,CAAC,MAAM;aAC5B,CAAA;SACJ;QAED,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,UAAU,CAAC,KAAK,EAAE,CAAA;QACtB,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAEjB,OAAO,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YACvC,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC;YAClB,IAAI,IAAI,CAAC,IAAI,EAAE;gBACX,OAAO,CAAC,IAAI,CAAC,iBAAiB,GAAG,IAAI,GAAG,GAAG,KAAK,gBAAgB,CAAC,CAAC;aACrE;YACD,OAAO,QAAQ,CAAC;QACpB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;YAEtB,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;gBAC7B,MAAM,IAAI,YAAY,CAAC,cAAc,IAAI,CAAC,OAAO,cAAc,CAAC,CAAC;aACpE;YAED,MAAM,KAAK,CAAC;QAChB,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;YACZ,YAAY,CAAC,OAAO,CAAC,CAAA;QACzB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAhDD,oCAgDC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractService.js","sourceRoot":"","sources":["../../src/Service/AbstractService.ts"],"names":[],"mappings":";;;AAGA;;;;;;;GAOG;AACH,MAAsB,eAAe;IAKjC,YAAY,KAAe;QAJlB,YAAO,GAAW,
|
|
1
|
+
{"version":3,"file":"AbstractService.js","sourceRoot":"","sources":["../../src/Service/AbstractService.ts"],"names":[],"mappings":";;;AAGA;;;;;;;GAOG;AACH,MAAsB,eAAe;IAKjC,YAAY,KAAe;QAJlB,YAAO,GAAW,IAAI,CAAC;QACvB,kBAAa,GAAW,CAAC,CAAC;QAC1B,SAAI,GAAY,KAAK,CAAC;QAG3B,IAAI,KAAK,EAAE;YACP,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;YAC1E,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC;YAClG,IAAI,CAAC,IAAI,GAAG,OAAO,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;SACxE;IACL,CAAC;CACJ;AAZD,0CAYC"}
|
package/lib/Service/Service.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/*! Copyright (c) 2019, XAPPmedia */
|
|
2
2
|
export interface Service {
|
|
3
3
|
name?: string;
|
|
4
|
+
/**
|
|
5
|
+
* Timeout
|
|
6
|
+
*/
|
|
4
7
|
timeout?: number;
|
|
8
|
+
/**
|
|
9
|
+
* How many attempts to make on the API
|
|
10
|
+
*/
|
|
5
11
|
retryAttempts?: number;
|
|
6
12
|
type?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Log information from the service
|
|
15
|
+
*/
|
|
7
16
|
logs?: boolean;
|
|
8
17
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.40.
|
|
7
|
+
"version": "1.40.231",
|
|
8
8
|
"description": "Base service to be extended for making API calls",
|
|
9
9
|
"types": "lib/index",
|
|
10
10
|
"main": "lib/index",
|
|
@@ -16,24 +16,29 @@
|
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/chai": "4.3.1",
|
|
19
|
+
"@types/chai-as-promised": "7.1.5",
|
|
19
20
|
"@types/jsonpath": "0.2.0",
|
|
20
21
|
"@types/lodash": "4.14.182",
|
|
21
22
|
"@types/sinon": "4.3.3",
|
|
22
23
|
"@types/sinon-chai": "3.2.8",
|
|
23
24
|
"@xapp/config": "0.2.3",
|
|
24
25
|
"chai": "4.3.6",
|
|
26
|
+
"chai-as-promised": "7.1.1",
|
|
25
27
|
"fetch-mock": "9.11.0",
|
|
28
|
+
"mocha": "10.0.0",
|
|
26
29
|
"sinon": "14.0.0",
|
|
27
30
|
"sinon-chai": "3.7.0",
|
|
28
|
-
"stentor-constants": "1.56.
|
|
29
|
-
"stentor-context": "1.56.
|
|
30
|
-
"stentor-models": "1.56.
|
|
31
|
-
"stentor-request": "1.56.
|
|
32
|
-
"stentor-utils": "1.56.
|
|
31
|
+
"stentor-constants": "1.56.43",
|
|
32
|
+
"stentor-context": "1.56.43",
|
|
33
|
+
"stentor-models": "1.56.43",
|
|
34
|
+
"stentor-request": "1.56.43",
|
|
35
|
+
"stentor-utils": "1.56.43",
|
|
36
|
+
"ts-node": "10.6.0",
|
|
33
37
|
"typescript": "4.7.4"
|
|
34
38
|
},
|
|
35
39
|
"dependencies": {
|
|
36
|
-
"@xapp/stentor-app": "1.40.
|
|
40
|
+
"@xapp/stentor-app": "1.40.231",
|
|
41
|
+
"abort-controller": "3.0.0",
|
|
37
42
|
"isomorphic-fetch": "3.0.0",
|
|
38
43
|
"jsonpath": "1.1.1",
|
|
39
44
|
"lodash.find": "4.6.0",
|
|
@@ -53,7 +58,8 @@
|
|
|
53
58
|
},
|
|
54
59
|
"scripts": {
|
|
55
60
|
"build": "tsc -d true -p .",
|
|
56
|
-
"clean": "rm -rf ./lib/*"
|
|
61
|
+
"clean": "rm -rf ./lib/*",
|
|
62
|
+
"ftest": "mocha --recursive -r ts-node/register \"./src/**/*.ftest.ts\""
|
|
57
63
|
},
|
|
58
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "3a2133f5b86c4b26bcc962f2b4fc8151bfa67d97"
|
|
59
65
|
}
|