@xapp/stentor-service 1.77.2 → 1.78.2

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.
@@ -0,0 +1,31 @@
1
+ /*! Copyright (c) 2019, XAPPmedia */
2
+ import "isomorphic-fetch";
3
+ import "abort-controller/polyfill";
4
+ import { AbstractService } from "./Service";
5
+ export interface WithTimeout {
6
+ /**
7
+ * Timeout in milliseconds
8
+ */
9
+ timeout?: number;
10
+ }
11
+ export declare class TimeoutError extends Error {
12
+ constructor(message: string);
13
+ }
14
+ /**
15
+ * Abstract service for services that primarily rely on the fetch API.
16
+ *
17
+ * It includes built-in timeout feature to better keep track of external APIs.
18
+ *
19
+ * @export
20
+ * @abstract
21
+ * @class FetchService
22
+ * @extends {AbstractService}
23
+ */
24
+ export declare abstract class FetchService extends AbstractService {
25
+ /**
26
+ * Wrapper around fetch to add some basic diagnostics
27
+ *
28
+ * Will throw a TimeoutError if the timeout is reached.
29
+ */
30
+ protected fetch(url: string, options?: RequestInit & WithTimeout): Promise<Response>;
31
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FetchService = exports.TimeoutError = void 0;
4
+ /*! Copyright (c) 2019, XAPPmedia */
5
+ require("isomorphic-fetch");
6
+ require("abort-controller/polyfill");
7
+ const Service_1 = require("./Service");
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;
17
+ /**
18
+ * Abstract service for services that primarily rely on the fetch API.
19
+ *
20
+ * It includes built-in timeout feature to better keep track of external APIs.
21
+ *
22
+ * @export
23
+ * @abstract
24
+ * @class FetchService
25
+ * @extends {AbstractService}
26
+ */
27
+ class FetchService extends Service_1.AbstractService {
28
+ /**
29
+ * Wrapper around fetch to add some basic diagnostics
30
+ *
31
+ * Will throw a TimeoutError if the timeout is reached.
32
+ */
33
+ fetch(url, options) {
34
+ const start = now();
35
+ const controller = new AbortController();
36
+ if (options) {
37
+ if (!options.signal) {
38
+ options.signal = controller.signal;
39
+ }
40
+ }
41
+ else {
42
+ options = {
43
+ signal: controller.signal
44
+ };
45
+ }
46
+ const timeoutInMS = (options === null || options === void 0 ? void 0 : options.timeout) || this.timeout;
47
+ const timeout = setTimeout(() => {
48
+ controller.abort();
49
+ }, timeoutInMS);
50
+ return fetch(url, options).then(response => {
51
+ const end = now();
52
+ if (this.logs) {
53
+ console.info(`Resource took ${url} ${end - start} ms to receive`);
54
+ }
55
+ return response;
56
+ }).catch((error) => {
57
+ if (error.name === "AbortError") {
58
+ throw new TimeoutError(`Timeout of ${this.timeout} ms reached.`);
59
+ }
60
+ throw error;
61
+ }).finally(() => {
62
+ clearTimeout(timeout);
63
+ });
64
+ }
65
+ }
66
+ exports.FetchService = FetchService;
67
+ //# sourceMappingURL=FetchService.js.map
@@ -0,0 +1 @@
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;AASvC,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;AAED;;;;;;;;;GASG;AACH,MAAsB,YAAa,SAAQ,yBAAe;IACtD;;;;OAIG;IACO,KAAK,CAAC,GAAW,EAAE,OAAmC;QAC5D,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC;QAEpB,MAAM,UAAU,GA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class AbstractService
9
+ * @implements {Service}
10
+ */
11
+ export declare abstract class AbstractService implements Service {
12
+ readonly timeout: number;
13
+ readonly retryAttempts: number;
14
+ readonly logs: boolean;
15
+ constructor(props?: Service);
16
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractService = void 0;
4
+ /**
5
+ * Abstract service
6
+ *
7
+ * @export
8
+ * @abstract
9
+ * @class AbstractService
10
+ * @implements {Service}
11
+ */
12
+ class AbstractService {
13
+ constructor(props) {
14
+ this.timeout = 1000;
15
+ this.retryAttempts = 0;
16
+ this.logs = false;
17
+ if (props) {
18
+ this.timeout = props.timeout !== undefined ? props.timeout : this.timeout;
19
+ this.retryAttempts = props.retryAttempts !== undefined ? props.retryAttempts : this.retryAttempts;
20
+ this.logs = typeof props.logs === "boolean" ? props.logs : this.logs;
21
+ }
22
+ }
23
+ }
24
+ exports.AbstractService = AbstractService;
25
+ //# sourceMappingURL=AbstractService.js.map
@@ -0,0 +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,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"}
@@ -0,0 +1,17 @@
1
+ /*! Copyright (c) 2019, XAPPmedia */
2
+ export interface Service {
3
+ name?: string;
4
+ /**
5
+ * Timeout
6
+ */
7
+ timeout?: number;
8
+ /**
9
+ * How many attempts to make on the API
10
+ */
11
+ retryAttempts?: number;
12
+ type?: string;
13
+ /**
14
+ * Log information from the service
15
+ */
16
+ logs?: boolean;
17
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service/Service.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ /*! Copyright (c) 2019, XAPPmedia */
2
+ export * from "./AbstractService";
3
+ export * from "./Service";
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /*! Copyright (c) 2019, XAPPmedia */
18
+ __exportStar(require("./AbstractService"), exports);
19
+ __exportStar(require("./Service"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Service/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,oDAAkC;AAClC,4CAA0B"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "1.77.2",
7
+ "version": "1.78.2",
8
8
  "description": "Base service to be extended for making API calls",
9
9
  "types": "lib/index",
10
10
  "main": "lib/index",
@@ -27,12 +27,12 @@
27
27
  "mocha": "11.7.5",
28
28
  "sinon": "21.0.0",
29
29
  "sinon-chai": "3.7.0",
30
- "stentor-constants": "1.71.0",
31
- "stentor-context": "1.71.0",
32
- "stentor-models": "1.71.0",
33
- "stentor-request": "1.71.0",
34
- "stentor-service-fetch": "1.71.0",
35
- "stentor-utils": "1.71.0",
30
+ "stentor-constants": "1.72.0",
31
+ "stentor-context": "1.72.0",
32
+ "stentor-models": "1.72.0",
33
+ "stentor-request": "1.72.0",
34
+ "stentor-service-fetch": "1.72.0",
35
+ "stentor-utils": "1.72.0",
36
36
  "ts-node": "10.9.2",
37
37
  "typescript": "5.9.3"
38
38
  },
@@ -55,5 +55,5 @@
55
55
  "clean": "rm -rf ./lib/*",
56
56
  "ftest": "mocha --recursive -r ts-node/register \"./src/**/*.ftest.ts\""
57
57
  },
58
- "gitHead": "2ad66e5027dcf0a1aae780792cd30c7a5f284c76"
58
+ "gitHead": "aa12717f4c89adc8be07967d8aabe33671d787b1"
59
59
  }