@ama-sdk/client-fetch 11.3.0-prerelease.33

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.
Files changed (157) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +33 -0
  3. package/cjs/api-fetch-client.js +581 -0
  4. package/cjs/fetch-plugin.js +4 -0
  5. package/cjs/plugins/abort/abort.fetch.js +84 -0
  6. package/cjs/plugins/abort/abort.spec.js +204 -0
  7. package/cjs/plugins/abort/index.js +18 -0
  8. package/cjs/plugins/concurrent/concurrent.fetch.js +263 -0
  9. package/cjs/plugins/concurrent/concurrent.spec.js +239 -0
  10. package/cjs/plugins/concurrent/index.js +18 -0
  11. package/cjs/plugins/index.js +25 -0
  12. package/cjs/plugins/keepalive/index.js +18 -0
  13. package/cjs/plugins/keepalive/keepalive.request.js +289 -0
  14. package/cjs/plugins/keepalive/keepalive.spec.js +162 -0
  15. package/cjs/plugins/mock-intercept/index.js +19 -0
  16. package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +288 -0
  17. package/cjs/plugins/mock-intercept/mock-intercept.interface.js +4 -0
  18. package/cjs/plugins/mock-intercept/mock-intercept.spec.js +445 -0
  19. package/cjs/plugins/perf-metric/index.js +18 -0
  20. package/cjs/plugins/perf-metric/perf-metric.fetch.js +371 -0
  21. package/cjs/plugins/perf-metric/perf-metric.probe.spec.js +60 -0
  22. package/cjs/plugins/retry/index.js +18 -0
  23. package/cjs/plugins/retry/retry.fetch.js +371 -0
  24. package/cjs/plugins/retry/retry.spec.js +348 -0
  25. package/cjs/plugins/timeout/index.js +18 -0
  26. package/cjs/plugins/timeout/timeout.fetch.js +320 -0
  27. package/cjs/plugins/timeout/timeout.spec.js +443 -0
  28. package/cjs/plugins/wait-for/index.js +18 -0
  29. package/cjs/plugins/wait-for/wait-for.fetch.js +350 -0
  30. package/cjs/plugins/wait-for/wait-for.spec.js +383 -0
  31. package/cjs/public_api.js +20 -0
  32. package/collection.json +11 -0
  33. package/esm2015/api-fetch-client.js +571 -0
  34. package/esm2015/fetch-plugin.js +4 -0
  35. package/esm2015/plugins/abort/abort.fetch.js +74 -0
  36. package/esm2015/plugins/abort/abort.spec.js +200 -0
  37. package/esm2015/plugins/abort/index.js +1 -0
  38. package/esm2015/plugins/concurrent/concurrent.fetch.js +255 -0
  39. package/esm2015/plugins/concurrent/concurrent.spec.js +235 -0
  40. package/esm2015/plugins/concurrent/index.js +1 -0
  41. package/esm2015/plugins/index.js +8 -0
  42. package/esm2015/plugins/keepalive/index.js +1 -0
  43. package/esm2015/plugins/keepalive/keepalive.request.js +281 -0
  44. package/esm2015/plugins/keepalive/keepalive.spec.js +158 -0
  45. package/esm2015/plugins/mock-intercept/index.js +2 -0
  46. package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +283 -0
  47. package/esm2015/plugins/mock-intercept/mock-intercept.interface.js +1 -0
  48. package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +441 -0
  49. package/esm2015/plugins/perf-metric/index.js +1 -0
  50. package/esm2015/plugins/perf-metric/perf-metric.fetch.js +363 -0
  51. package/esm2015/plugins/perf-metric/perf-metric.probe.spec.js +56 -0
  52. package/esm2015/plugins/retry/index.js +1 -0
  53. package/esm2015/plugins/retry/retry.fetch.js +363 -0
  54. package/esm2015/plugins/retry/retry.spec.js +344 -0
  55. package/esm2015/plugins/timeout/index.js +1 -0
  56. package/esm2015/plugins/timeout/timeout.fetch.js +310 -0
  57. package/esm2015/plugins/timeout/timeout.spec.js +439 -0
  58. package/esm2015/plugins/wait-for/index.js +1 -0
  59. package/esm2015/plugins/wait-for/wait-for.fetch.js +379 -0
  60. package/esm2015/plugins/wait-for/wait-for.spec.js +379 -0
  61. package/esm2015/public_api.js +3 -0
  62. package/package.json +196 -0
  63. package/schematics/ng-add/index.d.ts +8 -0
  64. package/schematics/ng-add/index.d.ts.map +1 -0
  65. package/schematics/ng-add/index.js +67 -0
  66. package/schematics/ng-add/migration/import-map.d.ts +6 -0
  67. package/schematics/ng-add/migration/import-map.d.ts.map +1 -0
  68. package/schematics/ng-add/migration/import-map.js +39 -0
  69. package/schematics/ng-add/schema.d.ts +6 -0
  70. package/schematics/ng-add/schema.d.ts.map +1 -0
  71. package/schematics/ng-add/schema.js +3 -0
  72. package/schematics/ng-add/schema.json +18 -0
  73. package/schematics/package.json +3 -0
  74. package/src/api-fetch-client.d.ts +46 -0
  75. package/src/api-fetch-client.d.ts.map +1 -0
  76. package/src/api-fetch-client.js +126 -0
  77. package/src/api-fetch-client.js.map +1 -0
  78. package/src/fetch-plugin.d.ts +38 -0
  79. package/src/fetch-plugin.d.ts.map +1 -0
  80. package/src/fetch-plugin.js +2 -0
  81. package/src/fetch-plugin.js.map +1 -0
  82. package/src/plugins/abort/abort.fetch.d.ts +66 -0
  83. package/src/plugins/abort/abort.fetch.d.ts.map +1 -0
  84. package/src/plugins/abort/abort.fetch.js +32 -0
  85. package/src/plugins/abort/abort.fetch.js.map +1 -0
  86. package/src/plugins/abort/index.d.ts +2 -0
  87. package/src/plugins/abort/index.d.ts.map +1 -0
  88. package/src/plugins/abort/index.js +2 -0
  89. package/src/plugins/abort/index.js.map +1 -0
  90. package/src/plugins/concurrent/concurrent.fetch.d.ts +33 -0
  91. package/src/plugins/concurrent/concurrent.fetch.d.ts.map +1 -0
  92. package/src/plugins/concurrent/concurrent.fetch.js +57 -0
  93. package/src/plugins/concurrent/concurrent.fetch.js.map +1 -0
  94. package/src/plugins/concurrent/index.d.ts +2 -0
  95. package/src/plugins/concurrent/index.d.ts.map +1 -0
  96. package/src/plugins/concurrent/index.js +2 -0
  97. package/src/plugins/concurrent/index.js.map +1 -0
  98. package/src/plugins/index.d.ts +9 -0
  99. package/src/plugins/index.d.ts.map +1 -0
  100. package/src/plugins/index.js +9 -0
  101. package/src/plugins/index.js.map +1 -0
  102. package/src/plugins/keepalive/index.d.ts +2 -0
  103. package/src/plugins/keepalive/index.d.ts.map +1 -0
  104. package/src/plugins/keepalive/index.js +2 -0
  105. package/src/plugins/keepalive/index.js.map +1 -0
  106. package/src/plugins/keepalive/keepalive.request.d.ts +18 -0
  107. package/src/plugins/keepalive/keepalive.request.d.ts.map +1 -0
  108. package/src/plugins/keepalive/keepalive.request.js +39 -0
  109. package/src/plugins/keepalive/keepalive.request.js.map +1 -0
  110. package/src/plugins/mock-intercept/index.d.ts +3 -0
  111. package/src/plugins/mock-intercept/index.d.ts.map +1 -0
  112. package/src/plugins/mock-intercept/index.js +3 -0
  113. package/src/plugins/mock-intercept/index.js.map +1 -0
  114. package/src/plugins/mock-intercept/mock-intercept.fetch.d.ts +15 -0
  115. package/src/plugins/mock-intercept/mock-intercept.fetch.d.ts.map +1 -0
  116. package/src/plugins/mock-intercept/mock-intercept.fetch.js +47 -0
  117. package/src/plugins/mock-intercept/mock-intercept.fetch.js.map +1 -0
  118. package/src/plugins/mock-intercept/mock-intercept.interface.d.ts +10 -0
  119. package/src/plugins/mock-intercept/mock-intercept.interface.d.ts.map +1 -0
  120. package/src/plugins/mock-intercept/mock-intercept.interface.js +2 -0
  121. package/src/plugins/mock-intercept/mock-intercept.interface.js.map +1 -0
  122. package/src/plugins/perf-metric/index.d.ts +2 -0
  123. package/src/plugins/perf-metric/index.d.ts.map +1 -0
  124. package/src/plugins/perf-metric/index.js +2 -0
  125. package/src/plugins/perf-metric/index.js.map +1 -0
  126. package/src/plugins/perf-metric/perf-metric.fetch.d.ts +133 -0
  127. package/src/plugins/perf-metric/perf-metric.fetch.d.ts.map +1 -0
  128. package/src/plugins/perf-metric/perf-metric.fetch.js +111 -0
  129. package/src/plugins/perf-metric/perf-metric.fetch.js.map +1 -0
  130. package/src/plugins/retry/index.d.ts +2 -0
  131. package/src/plugins/retry/index.d.ts.map +1 -0
  132. package/src/plugins/retry/index.js +2 -0
  133. package/src/plugins/retry/index.js.map +1 -0
  134. package/src/plugins/retry/retry.fetch.d.ts +53 -0
  135. package/src/plugins/retry/retry.fetch.d.ts.map +1 -0
  136. package/src/plugins/retry/retry.fetch.js +66 -0
  137. package/src/plugins/retry/retry.fetch.js.map +1 -0
  138. package/src/plugins/timeout/index.d.ts +2 -0
  139. package/src/plugins/timeout/index.d.ts.map +1 -0
  140. package/src/plugins/timeout/index.js +2 -0
  141. package/src/plugins/timeout/index.js.map +1 -0
  142. package/src/plugins/timeout/timeout.fetch.d.ts +47 -0
  143. package/src/plugins/timeout/timeout.fetch.d.ts.map +1 -0
  144. package/src/plugins/timeout/timeout.fetch.js +105 -0
  145. package/src/plugins/timeout/timeout.fetch.js.map +1 -0
  146. package/src/plugins/wait-for/index.d.ts +2 -0
  147. package/src/plugins/wait-for/index.d.ts.map +1 -0
  148. package/src/plugins/wait-for/index.js +2 -0
  149. package/src/plugins/wait-for/index.js.map +1 -0
  150. package/src/plugins/wait-for/wait-for.fetch.d.ts +78 -0
  151. package/src/plugins/wait-for/wait-for.fetch.d.ts.map +1 -0
  152. package/src/plugins/wait-for/wait-for.fetch.js +104 -0
  153. package/src/plugins/wait-for/wait-for.fetch.js.map +1 -0
  154. package/src/public_api.d.ts +4 -0
  155. package/src/public_api.d.ts.map +1 -0
  156. package/src/public_api.js +4 -0
  157. package/src/public_api.js.map +1 -0
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Plugin to add the keepalive flag to the request
3
+ */
4
+ export class KeepaliveRequest {
5
+ constructor(force = false) {
6
+ if (force) {
7
+ this.active = true;
8
+ }
9
+ else {
10
+ void this.testKeepAlive();
11
+ }
12
+ }
13
+ /**
14
+ * Keepalive flag has a partial support on some browsers, especially due to custom Headers.
15
+ * For instance, using the flag with custom headers causes the browser to trigger an error:
16
+ * 'Preflight request for request with keepalive specified is currently not supported'
17
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=835821
18
+ * To avoid this issue we do a fake fetch call to check whether we can activate it or not in the browser.
19
+ */
20
+ async testKeepAlive() {
21
+ const customHeaders = new Headers();
22
+ customHeaders.set('Content-Type', 'application/json');
23
+ try {
24
+ await fetch('', { headers: customHeaders, keepalive: true });
25
+ this.active = true;
26
+ }
27
+ catch (e) {
28
+ this.active = false;
29
+ }
30
+ }
31
+ load() {
32
+ return {
33
+ transform: (data) => {
34
+ return { ...data, keepalive: this.active };
35
+ }
36
+ };
37
+ }
38
+ }
39
+ //# sourceMappingURL=keepalive.request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keepalive.request.js","sourceRoot":"","sources":["../../../../src/plugins/keepalive/keepalive.request.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAI3B,YAAY,KAAK,GAAG,KAAK;QACvB,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,KAAK,IAAI,CAAC,aAAa,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACK,KAAK,CAAC,aAAa;QACzB,MAAM,aAAa,GAAG,IAAI,OAAO,EAAE,CAAC;QACpC,aAAa,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QACtD,IAAI,CAAC;YACH,MAAM,KAAK,CAAC,EAAE,EAAE,EAAC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;YAC3D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACtB,CAAC;IACH,CAAC;IAEM,IAAI;QACT,OAAO;YACL,SAAS,EAAE,CAAC,IAAoB,EAAE,EAAE;gBAClC,OAAO,EAAC,GAAG,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,EAAC,CAAC;YAC3C,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export * from './mock-intercept.fetch';
2
+ export * from './mock-intercept.interface';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/mock-intercept/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './mock-intercept.fetch';
2
+ export * from './mock-intercept.interface';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/mock-intercept/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { PluginAsyncRunner } from '@ama-sdk/core';
2
+ import { MockInterceptFetchParameters } from './mock-intercept.interface';
3
+ import type { FetchPlugin, FetchPluginContext, PluginAsyncStarter } from '../../fetch-plugin';
4
+ /**
5
+ * Plugin to mock and intercept the fetch of SDK
6
+ *
7
+ * This plugin should be used only with the MockInterceptRequest Plugin.
8
+ * It will allow the user to delay the response or to handle the getResponse function provided with the mock (if present).
9
+ */
10
+ export declare class MockInterceptFetch implements FetchPlugin {
11
+ protected options: MockInterceptFetchParameters;
12
+ constructor(options: MockInterceptFetchParameters);
13
+ load(context: FetchPluginContext): PluginAsyncRunner<Response, Promise<Response>> & PluginAsyncStarter;
14
+ }
15
+ //# sourceMappingURL=mock-intercept.fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-intercept.fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/mock-intercept/mock-intercept.fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAE1E,OAAO,KAAK,EAAa,WAAW,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAEzG;;;;;GAKG;AACH,qBAAa,kBAAmB,YAAW,WAAW;IAExC,SAAS,CAAC,OAAO,EAAE,4BAA4B;gBAArC,OAAO,EAAE,4BAA4B;IAEpD,IAAI,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,kBAAkB;CA0C9G"}
@@ -0,0 +1,47 @@
1
+ import { CUSTOM_MOCK_OPERATION_ID_HEADER, MockInterceptRequest } from '@ama-sdk/core';
2
+ /**
3
+ * Plugin to mock and intercept the fetch of SDK
4
+ *
5
+ * This plugin should be used only with the MockInterceptRequest Plugin.
6
+ * It will allow the user to delay the response or to handle the getResponse function provided with the mock (if present).
7
+ */
8
+ export class MockInterceptFetch {
9
+ constructor(options) {
10
+ this.options = options;
11
+ }
12
+ load(context) {
13
+ if (!context.apiClient.options.requestPlugins.some((plugin) => plugin instanceof MockInterceptRequest)) {
14
+ throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
15
+ }
16
+ return {
17
+ transform: async (fetchCall) => {
18
+ await this.options.adapter.initialize();
19
+ let responsePromise = fetchCall;
20
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
21
+ if (!context.options.headers || !(context.options.headers instanceof Headers) || !context.options.headers.has(CUSTOM_MOCK_OPERATION_ID_HEADER)) {
22
+ return responsePromise;
23
+ }
24
+ if (typeof this.options.delayTiming !== 'undefined') {
25
+ const delay = typeof this.options.delayTiming === 'number' ? this.options.delayTiming : await this.options.delayTiming(context);
26
+ const resp = await responsePromise;
27
+ responsePromise = new Promise((resolve) => setTimeout(resolve, delay)).then(() => resp);
28
+ }
29
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
30
+ const operationId = context.options.headers.get(CUSTOM_MOCK_OPERATION_ID_HEADER);
31
+ try {
32
+ const mock = this.options.adapter.getLatestMock(operationId);
33
+ if (!mock.getResponse) {
34
+ return responsePromise;
35
+ }
36
+ const response = mock.getResponse();
37
+ return responsePromise.then(() => response);
38
+ }
39
+ catch {
40
+ (context.logger || console).error(`Failed to retrieve the latest mock for Operation ID ${operationId}, fallback to default mock`);
41
+ return responsePromise;
42
+ }
43
+ }
44
+ };
45
+ }
46
+ }
47
+ //# sourceMappingURL=mock-intercept.fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-intercept.fetch.js","sourceRoot":"","sources":["../../../../src/plugins/mock-intercept/mock-intercept.fetch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,+BAA+B,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAGtF;;;;;GAKG;AACH,MAAM,OAAO,kBAAkB;IAE7B,YAAsB,OAAqC;QAArC,YAAO,GAAP,OAAO,CAA8B;IAAG,CAAC;IAExD,IAAI,CAAC,OAA2B;QAErC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,YAAY,oBAAoB,CAAC,EAAE,CAAC;YACvG,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC;QACxG,CAAC;QAED,OAAO;YACL,SAAS,EAAE,KAAK,EAAE,SAAoB,EAAE,EAAE;gBACxC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;gBAExC,IAAI,eAAe,GAAG,SAAS,CAAC;gBAChC,4EAA4E;gBAC5E,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,YAAY,OAAO,CAAC,IAAI,CAAE,OAAO,CAAC,OAAO,CAAC,OAAmB,CAAC,GAAG,CAAC,+BAA+B,CAAC,EAAE,CAAC;oBAC5J,OAAO,eAAe,CAAC;gBACzB,CAAC;gBAED,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,WAAW,EAAE,CAAC;oBACpD,MAAM,KAAK,GAAG,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;oBAChI,MAAM,IAAI,GAAG,MAAM,eAAe,CAAC;oBACnC,eAAe,GAAG,IAAI,OAAO,CAAW,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;gBACpG,CAAC;gBAED,4EAA4E;gBAC5E,MAAM,WAAW,GAAI,OAAO,CAAC,OAAO,CAAC,OAAmB,CAAC,GAAG,CAAC,+BAA+B,CAAE,CAAC;gBAC/F,IAAI,CAAC;oBACH,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;oBAE7D,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;wBACtB,OAAO,eAAe,CAAC;oBACzB,CAAC;oBAED,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;oBACpC,OAAO,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC;gBAE9C,CAAC;gBAAC,MAAM,CAAC;oBACP,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC,KAAK,CAAC,uDAAuD,WAAW,4BAA4B,CAAC,CAAC;oBAClI,OAAO,eAAe,CAAC;gBACzB,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CAEF"}
@@ -0,0 +1,10 @@
1
+ import type { MockAdapter } from '@ama-sdk/core';
2
+ import type { FetchPluginContext } from '../../fetch-plugin';
3
+ /** Mock Fetch Plugin options */
4
+ export interface MockInterceptFetchParameters {
5
+ /** List of mocks to be used */
6
+ adapter: MockAdapter;
7
+ /** Delays the mock response, in milliseconds */
8
+ delayTiming?: number | ((context: FetchPluginContext) => number | Promise<number>);
9
+ }
10
+ //# sourceMappingURL=mock-intercept.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-intercept.interface.d.ts","sourceRoot":"","sources":["../../../../src/plugins/mock-intercept/mock-intercept.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,gCAAgC;AAChC,MAAM,WAAW,4BAA4B;IAC3C,+BAA+B;IAC/B,OAAO,EAAE,WAAW,CAAC;IACrB,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,kBAAkB,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;CACpF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mock-intercept.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-intercept.interface.js","sourceRoot":"","sources":["../../../../src/plugins/mock-intercept/mock-intercept.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export * from './perf-metric.fetch';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/perf-metric/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './perf-metric.fetch';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/perf-metric/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,133 @@
1
+ import type { FetchCall, FetchPlugin, FetchPluginContext } from '../../fetch-plugin';
2
+ /**
3
+ * Performance metric mark associated to a call.
4
+ */
5
+ export interface Mark {
6
+ /**
7
+ * Id of the mark.
8
+ */
9
+ markId: string;
10
+ /**
11
+ * URL of the call.
12
+ */
13
+ url: string;
14
+ /**
15
+ * Options of the call.
16
+ */
17
+ requestOptions: RequestInit;
18
+ /**
19
+ * Start time of the call.
20
+ */
21
+ startTime: number;
22
+ /**
23
+ * Response of the call.
24
+ */
25
+ response?: Response;
26
+ /**
27
+ * Error of the call.
28
+ */
29
+ error?: Error;
30
+ /**
31
+ * End time of the call.
32
+ */
33
+ endTime?: number;
34
+ }
35
+ /** Performance object supporting NodeJs Performance and Web Performance reporting */
36
+ type CrossPlatformPerformance = {
37
+ /** @see Performance.mark */
38
+ mark: (...x: Parameters<Performance['mark']>) => ReturnType<Performance['mark']> | void;
39
+ /** @see Performance.measure */
40
+ measure: (measureName: string, startOrMeasureOptions?: string, endMark?: string) => ReturnType<Performance['measure']> | void;
41
+ };
42
+ /**
43
+ * Options for this plugin.
44
+ */
45
+ export interface PerformanceMetricOptions {
46
+ /**
47
+ * Callback function to be called when a mark is closed.
48
+ */
49
+ onMarkComplete: (mark: Mark) => void | Promise<void>;
50
+ /**
51
+ * Callback function to be called when a mark is closed with an error.
52
+ */
53
+ onMarkError: (mark: Mark) => void | Promise<void>;
54
+ /**
55
+ * Callback function called when a mark is opened.
56
+ */
57
+ onMarkOpen: (mark: Mark) => void | Promise<void>;
58
+ /**
59
+ * Instance of the performance reporter to use for performance measurements.
60
+ * @default window.performance on browser only, undefined on node
61
+ */
62
+ performance: CrossPlatformPerformance;
63
+ /**
64
+ * Retrieve the performance tag name
65
+ * @param status status of the call
66
+ * @param markId Mark ID
67
+ */
68
+ getPerformanceTag: (status: string, markId: string) => string;
69
+ }
70
+ /**
71
+ * Performance metric plugin.
72
+ */
73
+ export declare class PerformanceMetricPlugin implements FetchPlugin {
74
+ /**
75
+ * Callback function called when a mark is closed.
76
+ */
77
+ onMarkComplete?: (mark: Mark) => void | Promise<void>;
78
+ /**
79
+ * Callback function called when a mark is closed with an error.
80
+ */
81
+ onMarkError?: (mark: Mark) => void | Promise<void>;
82
+ /**
83
+ * Callback function called when a mark is opened.
84
+ */
85
+ onMarkOpen?: (mark: Mark) => void | Promise<void>;
86
+ /**
87
+ * Opened marks.
88
+ */
89
+ protected readonly openMarks: {
90
+ [markId: string]: Mark;
91
+ };
92
+ /**
93
+ * Performance reporter to use for performance measurements.
94
+ * @default window.performance on browser only, undefined on node
95
+ */
96
+ protected readonly performance: CrossPlatformPerformance | undefined;
97
+ /**
98
+ * Method used to get the current time as default implementation if no Performance API available.
99
+ * Date.now() is used by default.
100
+ */
101
+ protected getTime: () => number;
102
+ constructor(options?: Partial<PerformanceMetricOptions>);
103
+ /**
104
+ * Retrieve the performance tag name
105
+ * @param status status of the call
106
+ * @param markId Mark ID
107
+ */
108
+ protected getPerformanceTag: (status: string, markId: string) => string;
109
+ /**
110
+ * Opens a mark associated to a call.
111
+ * @param url URL of the call associated to the mark to open
112
+ * @param requestOptions Options of the call associated to the mark to open
113
+ */
114
+ openMark(url: string, requestOptions: RequestInit): string;
115
+ /**
116
+ * Closes the mark matching the given mark id.
117
+ * @param markId Id of the mark to close
118
+ * @param response Response of the call associated to the mark to close
119
+ */
120
+ closeMark(markId: string, response: Response): void;
121
+ /**
122
+ * Closes the mark matching the given mark id with an error.
123
+ * @param markId Id of the mark to close
124
+ * @param error Optional error of the call associated to the mark to close
125
+ */
126
+ closeMarkWithError(markId: string, error: Error | undefined): void;
127
+ /** @inheritDoc */
128
+ load(context: FetchPluginContext): {
129
+ transform: (fetchCall: FetchCall) => Promise<Response>;
130
+ };
131
+ }
132
+ export {};
133
+ //# sourceMappingURL=perf-metric.fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perf-metric.fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/perf-metric/perf-metric.fetch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAErF;;GAEG;AACH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.openMarks = {};
11
+ /**
12
+ * Method used to get the current time as default implementation if no Performance API available.
13
+ * Date.now() is used by default.
14
+ */
15
+ this.getTime = Date.now;
16
+ /**
17
+ * Retrieve the performance tag name
18
+ * @param status status of the call
19
+ * @param markId Mark ID
20
+ */
21
+ this.getPerformanceTag = (status, markId) => `sdk:${status}:${markId}`;
22
+ this.getPerformanceTag = options?.getPerformanceTag || this.getPerformanceTag;
23
+ this.performance = options?.performance || (typeof window !== 'undefined' ? window.performance : undefined);
24
+ this.onMarkComplete = options ? options.onMarkComplete : this.onMarkComplete;
25
+ this.onMarkError = options ? options.onMarkError : this.onMarkError;
26
+ this.onMarkOpen = options ? options.onMarkOpen : this.onMarkOpen;
27
+ }
28
+ /**
29
+ * Opens a mark associated to a call.
30
+ * @param url URL of the call associated to the mark to open
31
+ * @param requestOptions Options of the call associated to the mark to open
32
+ */
33
+ openMark(url, requestOptions) {
34
+ const markId = v4();
35
+ const perfMark = this.performance?.mark(this.getPerformanceTag('start', markId)) || undefined;
36
+ const startTime = perfMark?.startTime ?? this.getTime();
37
+ const mark = {
38
+ markId,
39
+ url,
40
+ requestOptions,
41
+ startTime
42
+ };
43
+ this.openMarks[markId] = mark;
44
+ if (this.onMarkOpen) {
45
+ void this.onMarkOpen(mark);
46
+ }
47
+ return markId;
48
+ }
49
+ /**
50
+ * Closes the mark matching the given mark id.
51
+ * @param markId Id of the mark to close
52
+ * @param response Response of the call associated to the mark to close
53
+ */
54
+ closeMark(markId, response) {
55
+ const perfMark = this.performance?.mark(this.getPerformanceTag('end', markId)) || undefined;
56
+ const endTime = perfMark?.startTime ?? this.getTime();
57
+ this.performance?.measure(this.getPerformanceTag('measure', markId), this.getPerformanceTag('start', markId), this.getPerformanceTag('end', markId));
58
+ const mark = this.openMarks[markId];
59
+ if (!mark) {
60
+ return;
61
+ }
62
+ if (this.onMarkComplete) {
63
+ void this.onMarkComplete({
64
+ ...mark,
65
+ response,
66
+ endTime
67
+ });
68
+ }
69
+ delete this.openMarks[markId];
70
+ }
71
+ /**
72
+ * Closes the mark matching the given mark id with an error.
73
+ * @param markId Id of the mark to close
74
+ * @param error Optional error of the call associated to the mark to close
75
+ */
76
+ closeMarkWithError(markId, error) {
77
+ const perfMark = this.performance?.mark(this.getPerformanceTag('error', markId)) || undefined;
78
+ const endTime = perfMark?.startTime ?? this.getTime();
79
+ this.performance?.measure(this.getPerformanceTag('measure', markId), this.getPerformanceTag('start', markId), this.getPerformanceTag('error', markId));
80
+ const mark = this.openMarks[markId];
81
+ if (!mark) {
82
+ return;
83
+ }
84
+ if (this.onMarkError) {
85
+ void this.onMarkError({
86
+ ...mark,
87
+ error,
88
+ endTime
89
+ });
90
+ }
91
+ delete this.openMarks[markId];
92
+ }
93
+ /** @inheritDoc */
94
+ load(context) {
95
+ return {
96
+ transform: async (fetchCall) => {
97
+ const markId = this.openMark(context.url, context.options);
98
+ try {
99
+ const response = await fetchCall;
100
+ this.closeMark(markId, response);
101
+ return response;
102
+ }
103
+ catch (exception) {
104
+ this.closeMarkWithError(markId, exception);
105
+ throw exception;
106
+ }
107
+ }
108
+ };
109
+ }
110
+ }
111
+ //# sourceMappingURL=perf-metric.fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perf-metric.fetch.js","sourceRoot":"","sources":["../../../../src/plugins/perf-metric/perf-metric.fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAoF1B;;GAEG;AACH,MAAM,OAAO,uBAAuB;IAiClC,YAAY,OAA2C;QAjBvD;;WAEG;QACgB,cAAS,GAA6B,EAAE,CAAC;QAQ5D;;;WAGG;QACO,YAAO,GAAiB,IAAI,CAAC,GAAG,CAAC;QAU3C;;;;WAIG;QACO,sBAAiB,GAAG,CAAC,MAAc,EAAE,MAAc,EAAE,EAAE,CAAC,OAAO,MAAM,IAAI,MAAM,EAAE,CAAC;QAZ1F,IAAI,CAAC,iBAAiB,GAAG,OAAO,EAAE,iBAAiB,IAAI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AAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,KAAK,IAAI,CAAC,WAAW,CAAC;gBACpB,GAAG,IAAI;gBACP,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED,kBAAkB;IACX,IAAI,CAAC,OAA2B;QACrC,OAAO;YACL,SAAS,EAAE,KAAK,EAAE,SAAoB,EAAE,EAAE;gBACxC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;gBAE3D,IAAI,CAAC;oBACH,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC;oBACjC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;oBACjC,OAAO,QAAQ,CAAC;gBAClB,CAAC;gBAAC,OAAO,SAAc,EAAE,CAAC;oBACxB,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;oBAC3C,MAAM,SAAS,CAAC;gBAClB,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export * from './retry.fetch';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/retry/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './retry.fetch';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/retry/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,53 @@
1
+ import type { FetchCall, FetchPlugin, FetchPluginContext } from '../../fetch-plugin';
2
+ /**
3
+ * Function to run to determine if we need to retry the call
4
+ * @param numberOfRetry
5
+ * @param condition
6
+ * @example
7
+ * ```typescript
8
+ * const condition = async (context: FetchPluginContext, data?: Response, error?: Error) => {
9
+ * const status = data.status;
10
+ * return status !== 200;
11
+ * }
12
+ * const plugin = new RetryConditionType(5, condition);
13
+ * ```
14
+ * @example
15
+ * ```typescript
16
+ * const condition = async (context: FetchPluginContext, data?: Response, error?: Error) => {
17
+ * const receivedData = data && await data.text();
18
+ * return !!data && /^error$/.test(data);
19
+ * }
20
+ * const plugin = new RetryConditionType(5, condition);
21
+ * ```
22
+ */
23
+ export type RetryConditionType = (context: FetchPluginContext, data?: Response, error?: Error) => boolean | Promise<boolean>;
24
+ /**
25
+ * Plugin to Retry a fetch call
26
+ */
27
+ export declare class RetryFetch implements FetchPlugin {
28
+ /** Number of retry */
29
+ numberOfRetry: number;
30
+ /** Condition of retrying */
31
+ condition: RetryConditionType;
32
+ /** If we wait between the next retry. It will be random value between minSleep and maxSleep ms */
33
+ sleepBetweenRetry: (numberOfRetry?: number) => number | Promise<number>;
34
+ /**
35
+ * Retry Fetch plugin
36
+ * @param numberOfRetry Number of retry
37
+ * @param condition Condition of retrying, return true to launch the retry process
38
+ * @param sleepBetweenRetry
39
+ */
40
+ constructor(numberOfRetry?: number, condition?: RetryConditionType, sleepBetweenRetry?: (numberOfRetry?: number) => number | Promise<number>);
41
+ /**
42
+ * Launch a retry
43
+ * @param context
44
+ */
45
+ private retry;
46
+ private delay;
47
+ private waitAndRetry;
48
+ /** @inheritDoc */
49
+ load(context: FetchPluginContext): {
50
+ transform: (fetchCall: FetchCall) => Promise<Response>;
51
+ };
52
+ }
53
+ //# sourceMappingURL=retry.fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/retry/retry.fetch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAErF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE,kBAAkB,EAAE,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAE7H;;GAEG;AACH,qBAAa,UAAW,YAAW,WAAW;IAC5C,sBAAsB;IACf,aAAa,EAAE,MAAM,CAAC;IAE7B,4BAA4B;IACrB,SAAS,EAAE,kBAAkB,CAAC;IAErC,kGAAkG;IAC3F,iBAAiB,EAAE,CAAC,aAAa,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE/E;;;;;OAKG;gBAED,aAAa,SAAI,EACjB,SAAS,GAAE,kBAA6H,EACxI,iBAAiB,GAAE,CAAC,aAAa,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAW;IAMnF;;;OAGG;IACH,OAAO,CAAC,KAAK;YAQC,KAAK;YAML,YAAY;IAK1B,kBAAkB;IACX,IAAI,CAAC,OAAO,EAAE,kBAAkB;+BAIN,SAAS;;CAwB3C"}
@@ -0,0 +1,66 @@
1
+ import { CanceledCallError } from '@ama-sdk/core';
2
+ /**
3
+ * Plugin to Retry a fetch call
4
+ */
5
+ export class RetryFetch {
6
+ /**
7
+ * Retry Fetch plugin
8
+ * @param numberOfRetry Number of retry
9
+ * @param condition Condition of retrying, return true to launch the retry process
10
+ * @param sleepBetweenRetry
11
+ */
12
+ constructor(numberOfRetry = 3, condition = (_context, _data, error) => !(error instanceof CanceledCallError), sleepBetweenRetry = () => 0) {
13
+ this.numberOfRetry = numberOfRetry;
14
+ this.condition = condition;
15
+ this.sleepBetweenRetry = sleepBetweenRetry;
16
+ }
17
+ /**
18
+ * Launch a retry
19
+ * @param context
20
+ */
21
+ retry(context) {
22
+ let asyncResponse = fetch(context.url, context.options);
23
+ for (const plugin of context.fetchPlugins) {
24
+ asyncResponse = plugin.transform(asyncResponse);
25
+ }
26
+ return asyncResponse;
27
+ }
28
+ async delay(countDown) {
29
+ // eslint-disable-next-line no-async-promise-executor
30
+ return new Promise(async (resolve) => setTimeout(resolve, await this.sleepBetweenRetry(countDown)));
31
+ }
32
+ async waitAndRetry(context, countDown) {
33
+ await this.delay(countDown);
34
+ return this.retry(context);
35
+ }
36
+ /** @inheritDoc */
37
+ load(context) {
38
+ let countDown = this.numberOfRetry;
39
+ return {
40
+ transform: async (fetchCall) => {
41
+ try {
42
+ const result = await fetchCall;
43
+ if (!result.ok && countDown > 0) {
44
+ const conditionResult = await this.condition(context, result.clone());
45
+ if (conditionResult) {
46
+ countDown--;
47
+ return this.waitAndRetry(context, countDown);
48
+ }
49
+ }
50
+ return result;
51
+ }
52
+ catch (e) {
53
+ if (countDown) {
54
+ const conditionResult = await this.condition(context, undefined, e);
55
+ if (conditionResult) {
56
+ countDown--;
57
+ return this.waitAndRetry(context, countDown);
58
+ }
59
+ }
60
+ throw e;
61
+ }
62
+ }
63
+ };
64
+ }
65
+ }
66
+ //# sourceMappingURL=retry.fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.fetch.js","sourceRoot":"","sources":["../../../../src/plugins/retry/retry.fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA0BlD;;GAEG;AACH,MAAM,OAAO,UAAU;IAUrB;;;;;OAKG;IACH,YACE,aAAa,GAAG,CAAC,EACjB,YAAgC,CAAC,QAA4B,EAAE,KAAgB,EAAE,KAAa,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,YAAY,iBAAiB,CAAC,EACxI,oBAA0E,GAAG,EAAE,CAAC,CAAC;QACjF,IAAI,CAAC,aAAa,GAAG,aAAa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,CAAC;4BACZ,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;wBAC/C,CAAC;oBACH,CAAC;oBACD,OAAO,MAAM,CAAC;gBAChB,CAAC;gBAAC,OAAO,CAAM,EAAE,CAAC;oBAChB,IAAI,SAAS,EAAE,CAAC;wBACd,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;wBACpE,IAAI,eAAe,EAAE,CAAC;4BACpB,SAAS,EAAE,CAAC;4BACZ,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;wBAC/C,CAAC;oBACH,CAAC;oBACD,MAAM,CAAC,CAAC;gBACV,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export * from './timeout.fetch';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/timeout/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './timeout.fetch';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/timeout/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { FetchCall, FetchPlugin, FetchPluginContext } from '../../fetch-plugin';
2
+ /**
3
+ * Type to describe the timer status of the {@see TimeoutFetch} plugin.
4
+ * Today, only the stop and restart of the timer is supported which match the following events:
5
+ * - stop: stop the timeout timer
6
+ * - start: reset the timer and restart it
7
+ */
8
+ export type TimeoutStatus = 'timeoutStopped' | 'timeoutStarted';
9
+ /**
10
+ * Event handler that will emit event to pause the timeout
11
+ * Today the timeout only
12
+ */
13
+ export type TimeoutPauseEventHandler = ((timeoutPauseCallback: (timeoutStatus: TimeoutStatus) => void, context: any) => () => void);
14
+ /**
15
+ * Factory to generate a {@see TimeoutPauseEventHandler} depending on various configurations
16
+ */
17
+ export type TimeoutPauseEventHandlerFactory<T> = (config?: Partial<T>) => TimeoutPauseEventHandler;
18
+ /**
19
+ * Captures Imperva captcha events and calls the event callback
20
+ * It can only be used for browser's integrating imperva captcha
21
+ * @param config: list of host names that can trigger a captcha event
22
+ * @param config
23
+ * @returns removeEventListener
24
+ */
25
+ export declare const impervaCaptchaEventHandlerFactory: TimeoutPauseEventHandlerFactory<{
26
+ whiteListedHostNames: string[];
27
+ }>;
28
+ /**
29
+ * Plugin to fire an exception on timeout
30
+ */
31
+ export declare class TimeoutFetch implements FetchPlugin {
32
+ private readonly timeoutPauseEvent?;
33
+ /** Fetch timeout (in millisecond) */
34
+ timeout: number;
35
+ private timerSubscription;
36
+ private timerPauseState;
37
+ /**
38
+ * Timeout Fetch plugin.
39
+ * @param timeout Timeout in millisecond
40
+ * @param timeoutPauseEvent Event that will trigger the pause and reset of the timeout
41
+ */
42
+ constructor(timeout?: number, timeoutPauseEvent?: TimeoutPauseEventHandler | undefined);
43
+ load(context: FetchPluginContext): {
44
+ transform: (fetchCall: FetchCall) => Promise<Response>;
45
+ };
46
+ }
47
+ //# sourceMappingURL=timeout.fetch.d.ts.map