@xapp/stentor-service 1.44.9 → 1.44.11

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.
@@ -1,5 +1,5 @@
1
1
  import { LocationGeocode } from "stentor-models";
2
- import { FetchService } from "./FetchService";
2
+ import { FetchService } from "stentor-service-fetch";
3
3
  export interface LocationServiceOptions {
4
4
  apikey: string;
5
5
  urlbase?: string;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /*! Copyright (c) 2019, XAPPmedia */
4
- const now = require("performance-now");
5
4
  const stentor_constants_1 = require("stentor-constants");
6
- const FetchService_1 = require("./FetchService");
5
+ const stentor_service_fetch_1 = require("stentor-service-fetch");
7
6
  /**
8
7
  * Service to transform a location into lat/long coordinates via Google Maps' API
9
8
  *
@@ -11,14 +10,14 @@ const FetchService_1 = require("./FetchService");
11
10
  * @export
12
11
  * @class LocationService
13
12
  */
14
- class LocationService extends FetchService_1.FetchService {
13
+ class LocationService extends stentor_service_fetch_1.FetchService {
15
14
  constructor(options) {
16
15
  super();
17
16
  this.apikey = options.apikey;
18
17
  this.urlbase = options.urlbase || "https://maps.googleapis.com/maps/api/geocode/json";
19
18
  }
20
19
  getGeocode(address) {
21
- const start = now();
20
+ const start = performance.now();
22
21
  const apiKey = this.apikey;
23
22
  const apiURL = `${this.urlbase}?address=${address}&key=${apiKey}`;
24
23
  let status;
@@ -33,7 +32,7 @@ class LocationService extends FetchService_1.FetchService {
33
32
  return response.json();
34
33
  })
35
34
  .then(response => {
36
- const end = now();
35
+ const end = performance.now();
37
36
  const geocode = {
38
37
  latitude: undefined,
39
38
  longitude: undefined
@@ -1 +1 @@
1
- {"version":3,"file":"LocationService.js","sourceRoot":"","sources":["../src/LocationService.ts"],"names":[],"mappings":";;AAAA,oCAAoC;AACpC,MAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACvC,yDAAyD;AAGzD,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,QAAQ,CAAC,EAAE;YAC9B,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;YAE9B,MAAM,OAAO,GAAoB;gBAC7B,QAAQ,EAAE,SAAS;gBACnB,SAAS,EAAE,SAAS;aACvB,CAAC;YAEF,OAAO,CAAC,IAAI,CAAC,mCAAmC,GAAG,GAAG,KAAK,gBAAgB,CAAC,CAAC;YAE7E,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE;gBACzB,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAC7D,OAAO,CAAC,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAE9D,OAAO,OAAO,CAAC;aAClB;iBAAM;gBACH,MAAM,IAAI,KAAK,CACX,gCAAgC,OAAO,0DAA0D,CACpG,CAAC;aACL;QACL,CAAC,CAAC,CAAC;IACX,CAAC;CACJ;AApDD,kCAoDC"}
@@ -1,6 +1,6 @@
1
1
  /*! Copyright (c) 2019, XAPPmedia */
2
2
  import "isomorphic-fetch";
3
- import { FetchService } from "../FetchService";
3
+ import { FetchService } from "stentor-service-fetch";
4
4
  import { Resource, ResourceService } from "./ResourceService";
5
5
  export declare const DEFAULT_PROTOCOL = "https:";
6
6
  /**
@@ -5,7 +5,7 @@ exports.AbstractResourceService = exports.DEFAULT_PROTOCOL = void 0;
5
5
  require("isomorphic-fetch");
6
6
  const queryString = require("query-string");
7
7
  const URL = require("url");
8
- const FetchService_1 = require("../FetchService");
8
+ const stentor_service_fetch_1 = require("stentor-service-fetch");
9
9
  const ResourceService_1 = require("./ResourceService");
10
10
  const find = require("lodash.find");
11
11
  const template = require("lodash.template");
@@ -21,7 +21,7 @@ exports.DEFAULT_PROTOCOL = "https:";
21
21
  * @class AbstractResourceService
22
22
  * @extends {AbstractService}
23
23
  */
24
- class AbstractResourceService extends FetchService_1.FetchService {
24
+ class AbstractResourceService extends stentor_service_fetch_1.FetchService {
25
25
  constructor(props) {
26
26
  super(props);
27
27
  this.protocol = exports.DEFAULT_PROTOCOL;
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractResourceService.js","sourceRoot":"","sources":["../../src/ResourceService/AbstractResourceService.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,4BAA0B;AAC1B,4CAA4C;AAC5C,2BAA2B;AAC3B,kDAA+C;AAC/C,uDAAqF;AAErF,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACpC,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE/B,QAAA,gBAAgB,GAAG,QAAQ,CAAC;AAEzC;;;;;;;;;;GAUG;AACH,MAAsB,uBAAwB,SAAQ,2BAAY;IAW9D,YAAY,KAAuB;QAC/B,KAAK,CAAC,KAAK,CAAC,CAAC;QAXR,aAAQ,GAAW,wBAAgB,CAAC;QAazC,IAAI,KAAK,EAAE;YACP,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;YAC/B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,wBAAgB,CAAC;YACnD,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;YACvB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;YAC7B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;SACpC;IACL,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CAAI,iBAAuC;QAC1C,IAAI,QAAqB,CAAC;QAC1B,IAAI,kBAA0B,CAAC;QAE/B,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE;YACvC,kBAAkB,GAAG,iBAAiB,CAAC;YACvC,4BAA4B;YAC5B,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,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,EAAE;YACX,MAAM,IAAI,KAAK,CAAC,2BAA2B,kBAAkB,EAAE,CAAC,CAAC;SACpE;QAED,MAAM,GAAG,GAAkB;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;SAC1B,CAAC;QAEF,4CAA4C;QAC5C,MAAM,YAAY,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC7C,GAAG,CAAC,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QACjD,GAAG,CAAC,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEnD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAE7B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;aACzD,IAAI,CAAC,QAAQ,CAAC,EAAE;YACb,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC3B,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,EAAE;YACT,cAAc;YACd,OAAO,IAAA,uCAAqB,EAAI,IAAI,EAAE,QAAQ,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACX,CAAC;CACJ;AAxED,0DAwEC"}
@@ -1,4 +1,4 @@
1
- import { Service } from "../Service";
1
+ import { BaseService } from "stentor-models";
2
2
  /**
3
3
  * A simple map of keys and values that are used
4
4
  * to replace a templated request.
@@ -47,7 +47,7 @@ export interface Resource<T = any> {
47
47
  * @interface ResourceService
48
48
  * @extends {Service}
49
49
  */
50
- export interface ResourceService extends Service {
50
+ export interface ResourceService extends BaseService {
51
51
  protocol?: string;
52
52
  hostname: string;
53
53
  port?: number;
package/lib/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /*! Copyright (c) 2019, XAPPmedia */
2
2
  export * from "./APIService";
3
- export * from "./FetchService";
4
3
  export * from "./LocationService";
5
4
  export * from "./MetricsService";
6
5
  export * from "./ResourceService";
7
- export * from "./Service";
6
+ export { FetchService, TimeoutError } from "stentor-service-fetch";
package/lib/index.js CHANGED
@@ -14,11 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.TimeoutError = exports.FetchService = void 0;
17
18
  /*! Copyright (c) 2019, XAPPmedia */
18
19
  __exportStar(require("./APIService"), exports);
19
- __exportStar(require("./FetchService"), exports);
20
20
  __exportStar(require("./LocationService"), exports);
21
21
  __exportStar(require("./MetricsService"), exports);
22
22
  __exportStar(require("./ResourceService"), exports);
23
- __exportStar(require("./Service"), exports);
23
+ var stentor_service_fetch_1 = require("stentor-service-fetch");
24
+ Object.defineProperty(exports, "FetchService", { enumerable: true, get: function () { return stentor_service_fetch_1.FetchService; } });
25
+ Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return stentor_service_fetch_1.TimeoutError; } });
24
26
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,+CAA6B;AAC7B,iDAA+B;AAC/B,oDAAkC;AAClC,mDAAiC;AACjC,oDAAkC;AAClC,4CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,+CAA6B;AAC7B,oDAAkC;AAClC,mDAAiC;AACjC,oDAAkC;AAElC,+DAAmE;AAA1D,qHAAA,YAAY,OAAA;AAAE,qHAAA,YAAY,OAAA"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "1.44.9",
7
+ "version": "1.44.11",
8
8
  "description": "Base service to be extended for making API calls",
9
9
  "types": "lib/index",
10
10
  "main": "lib/index",
@@ -34,10 +34,10 @@
34
34
  "stentor-request": "1.57.60",
35
35
  "stentor-utils": "1.57.60",
36
36
  "ts-node": "10.9.1",
37
- "typescript": "4.9.4"
37
+ "typescript": "4.9.5"
38
38
  },
39
39
  "dependencies": {
40
- "@xapp/stentor-app": "1.44.9",
40
+ "@xapp/stentor-app": "1.44.10",
41
41
  "abort-controller": "3.0.0",
42
42
  "isomorphic-fetch": "3.0.0",
43
43
  "jsonpath": "1.1.1",
@@ -46,6 +46,7 @@
46
46
  "moment": "2.29.4",
47
47
  "performance-node": "0.2.0",
48
48
  "query-string": "7.1.3",
49
+ "stentor-service-fetch": "1.57.60",
49
50
  "traverse": "0.6.7",
50
51
  "uuid4": "2.0.3"
51
52
  },
@@ -61,5 +62,5 @@
61
62
  "clean": "rm -rf ./lib/*",
62
63
  "ftest": "mocha --recursive -r ts-node/register \"./src/**/*.ftest.ts\""
63
64
  },
64
- "gitHead": "74802b4221276312486f7ca5cd550db9888a2528"
65
+ "gitHead": "2e96680910fba65b067bd5d8961f735393698e32"
65
66
  }
@@ -1,31 +0,0 @@
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
- }
@@ -1,67 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"FetchService.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B,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;AA5CD,oCA4CC"}
@@ -1,16 +0,0 @@
1
- /*! Copyright (c) 2019, XAPPmedia */
2
- import { Service } from "./Service";
3
- /**
4
- * Abstract service
5
- *
6
- * @export
7
- * @abstract
8
- * @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
- }
@@ -1,25 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,17 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=Service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service/Service.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- /*! Copyright (c) 2019, XAPPmedia */
2
- export * from "./AbstractService";
3
- export * from "./Service";
@@ -1,20 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Service/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,oDAAkC;AAClC,4CAA0B"}