@widergy/polling-handling 2.0.0 → 2.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # [2.1.0](https://github.com/widergy/polling-handling/compare/v2.0.1...v2.1.0) (2024-04-19)
2
+
3
+
4
+ ### Features
5
+
6
+ * remove interval from poll and moved it into handle ([73af151](https://github.com/widergy/polling-handling/commit/73af15157cda016f19792066927401ac72fd066c))
7
+ * take url from response ([58ac12d](https://github.com/widergy/polling-handling/commit/58ac12d41d047b6c1c4495cebe04ceb234b197e6))
8
+
9
+ ## [2.0.1](https://github.com/widergy/polling-handling/compare/v2.0.0...v2.0.1) (2023-11-11)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * update commitlint.config.js ([36aa5ff](https://github.com/widergy/polling-handling/commit/36aa5ff789db6548cbd46eede3ef5a030168342f))
15
+
1
16
  # [2.0.0](https://github.com/widergy/polling-handling/compare/v1.7.0...v2.0.0) (2023-11-10)
2
17
 
3
18
 
package/lib/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ApisauceInstance } from 'apisauce';
2
2
  interface Options {
3
3
  retries: number;
4
+ interval: number;
4
5
  }
5
6
  declare class Polling {
6
7
  baseUrl: string;
@@ -8,7 +9,7 @@ declare class Polling {
8
9
  apiInstance: ApisauceInstance;
9
10
  constructor(baseUrl?: string, failureCallback?: (response: any, data: any) => void);
10
11
  init(baseUrl: string, monitors: any, failureCallback: (response: any, data: any) => void): void;
11
- handle(originalRequest: any, timeout: number, options: Options): Promise<any>;
12
+ handle(originalRequest: any, timeout: number | undefined, options: Options): Promise<any>;
12
13
  }
13
14
  declare const _default: Polling;
14
15
  export default _default;
package/lib/index.js CHANGED
@@ -55,9 +55,9 @@ const pollResource = (url, interval, timeout, headers, failureCallback, original
55
55
  };
56
56
  return new Promise(pollingRequest);
57
57
  };
58
- const poll = async (baseUrl, request, failureCallback, originalUrl, timeout = DEFAULT_TIMEOUT, interval = DEFAULT_INTERVAL) => {
58
+ const poll = async (baseUrl, request, failureCallback, originalUrl, timeout, interval) => {
59
59
  const response = await request;
60
- const url = `${baseUrl}${response.data.job_id ? response.data.job_id : response.data.response}`;
60
+ const url = response.data.url || `${baseUrl}${response.data.job_id ? response.data.job_id : response.data.response}`;
61
61
  if (response.data.token) {
62
62
  response.config.headers.Authorization = response.data.token;
63
63
  }
@@ -85,17 +85,17 @@ class Polling {
85
85
  api.addMonitor(monitor);
86
86
  });
87
87
  }
88
- async handle(originalRequest, timeout, options) {
88
+ async handle(originalRequest, timeout = DEFAULT_TIMEOUT, options) {
89
89
  const request = await originalRequest;
90
90
  const originalUrl = request.config.url;
91
- const { retries = 0 } = options || {};
91
+ const { retries = 0, interval = DEFAULT_INTERVAL } = options || {};
92
92
  const response = {};
93
93
  if (!request.ok) {
94
94
  response.error = (0, errorHandling_1.getResponseError)(request);
95
95
  response.status = request.status;
96
96
  return response;
97
97
  }
98
- return poll(this.baseUrl, request, this.failureCallback, originalUrl, timeout)
98
+ return poll(this.baseUrl, request, this.failureCallback, originalUrl, timeout, interval)
99
99
  .then((result) => {
100
100
  response.data = result.data;
101
101
  return response;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widergy/polling-handling",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Utility GO! Polling Handling",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",