@gcmdev/faxios 0.1.0 → 0.2.1

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 (210) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +40 -1774
  3. package/dist/index.d.ts +9 -6
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/adapters/fetch-helpers.d.ts +1 -0
  7. package/dist/lib/adapters/fetch-helpers.d.ts.map +1 -0
  8. package/dist/lib/adapters/fetch.d.ts +1 -0
  9. package/dist/lib/adapters/fetch.d.ts.map +1 -0
  10. package/dist/lib/adapters/fetch.js +23 -3
  11. package/dist/lib/adapters/fetch.js.map +1 -1
  12. package/dist/lib/cancel/CanceledError.d.ts +1 -0
  13. package/dist/lib/cancel/CanceledError.d.ts.map +1 -0
  14. package/dist/lib/cancel/isCancel.d.ts +3 -1
  15. package/dist/lib/cancel/isCancel.d.ts.map +1 -0
  16. package/dist/lib/cancel/isCancel.js +3 -0
  17. package/dist/lib/cancel/isCancel.js.map +1 -1
  18. package/dist/lib/core/Faxios.d.ts +6 -17
  19. package/dist/lib/core/Faxios.d.ts.map +1 -0
  20. package/dist/lib/core/Faxios.js +144 -76
  21. package/dist/lib/core/Faxios.js.map +1 -1
  22. package/dist/lib/core/FaxiosError.d.ts +19 -6
  23. package/dist/lib/core/FaxiosError.d.ts.map +1 -0
  24. package/dist/lib/core/FaxiosError.js +16 -1
  25. package/dist/lib/core/FaxiosError.js.map +1 -1
  26. package/dist/lib/core/FaxiosHeaders.d.ts +12 -8
  27. package/dist/lib/core/FaxiosHeaders.d.ts.map +1 -0
  28. package/dist/lib/core/FaxiosHeaders.js +1 -0
  29. package/dist/lib/core/FaxiosHeaders.js.map +1 -1
  30. package/dist/lib/core/buildFullPath.d.ts +1 -0
  31. package/dist/lib/core/buildFullPath.d.ts.map +1 -0
  32. package/dist/lib/core/define.d.ts +19 -2
  33. package/dist/lib/core/define.d.ts.map +1 -0
  34. package/dist/lib/core/define.js.map +1 -1
  35. package/dist/lib/core/dispatchRequest.d.ts +1 -0
  36. package/dist/lib/core/dispatchRequest.d.ts.map +1 -0
  37. package/dist/lib/core/dispatchRequest.js +4 -0
  38. package/dist/lib/core/dispatchRequest.js.map +1 -1
  39. package/dist/lib/core/mergeConfig.d.ts +1 -0
  40. package/dist/lib/core/mergeConfig.d.ts.map +1 -0
  41. package/dist/lib/core/prepareRequest.d.ts +1 -0
  42. package/dist/lib/core/prepareRequest.d.ts.map +1 -0
  43. package/dist/lib/core/prepareRequest.js +1 -20
  44. package/dist/lib/core/prepareRequest.js.map +1 -1
  45. package/dist/lib/core/route.d.ts +11 -2
  46. package/dist/lib/core/route.d.ts.map +1 -0
  47. package/dist/lib/core/route.js.map +1 -1
  48. package/dist/lib/core/settle.d.ts +1 -0
  49. package/dist/lib/core/settle.d.ts.map +1 -0
  50. package/dist/lib/core/transformData.d.ts +1 -0
  51. package/dist/lib/core/transformData.d.ts.map +1 -0
  52. package/dist/lib/core/validateSchema.d.ts +1 -0
  53. package/dist/lib/core/validateSchema.d.ts.map +1 -0
  54. package/dist/lib/defaults/index.d.ts +1 -0
  55. package/dist/lib/defaults/index.d.ts.map +1 -0
  56. package/dist/lib/defaults/index.js +3 -3
  57. package/dist/lib/defaults/index.js.map +1 -1
  58. package/dist/lib/defaults/transitional.d.ts +1 -1
  59. package/dist/lib/defaults/transitional.d.ts.map +1 -0
  60. package/dist/lib/defaults/transitional.js +0 -1
  61. package/dist/lib/defaults/transitional.js.map +1 -1
  62. package/dist/lib/env/data.d.ts +2 -1
  63. package/dist/lib/env/data.d.ts.map +1 -0
  64. package/dist/lib/env/data.js +1 -1
  65. package/dist/lib/env/data.js.map +1 -1
  66. package/dist/lib/faxios.d.ts +115 -48
  67. package/dist/lib/faxios.d.ts.map +1 -0
  68. package/dist/lib/faxios.js +14 -2
  69. package/dist/lib/faxios.js.map +1 -1
  70. package/dist/lib/helpers/FaxiosURLSearchParams.d.ts +3 -1
  71. package/dist/lib/helpers/FaxiosURLSearchParams.d.ts.map +1 -0
  72. package/dist/lib/helpers/FaxiosURLSearchParams.js.map +1 -1
  73. package/dist/lib/helpers/HttpStatusCode.d.ts +1 -0
  74. package/dist/lib/helpers/HttpStatusCode.d.ts.map +1 -0
  75. package/dist/lib/helpers/buildURL.d.ts +1 -0
  76. package/dist/lib/helpers/buildURL.d.ts.map +1 -0
  77. package/dist/lib/helpers/buildURL.js +7 -1
  78. package/dist/lib/helpers/buildURL.js.map +1 -1
  79. package/dist/lib/helpers/cloneConfig.d.ts +4 -0
  80. package/dist/lib/helpers/cloneConfig.d.ts.map +1 -0
  81. package/dist/lib/helpers/cloneConfig.js +21 -0
  82. package/dist/lib/helpers/cloneConfig.js.map +1 -0
  83. package/dist/lib/helpers/combineURLs.d.ts +1 -0
  84. package/dist/lib/helpers/combineURLs.d.ts.map +1 -0
  85. package/dist/lib/helpers/composeSignals.d.ts +1 -0
  86. package/dist/lib/helpers/composeSignals.d.ts.map +1 -0
  87. package/dist/lib/helpers/composeSignals.js +8 -1
  88. package/dist/lib/helpers/composeSignals.js.map +1 -1
  89. package/dist/lib/helpers/cookies.d.ts +1 -0
  90. package/dist/lib/helpers/cookies.d.ts.map +1 -0
  91. package/dist/lib/helpers/estimateDataURLDecodedBytes.d.ts +1 -0
  92. package/dist/lib/helpers/estimateDataURLDecodedBytes.d.ts.map +1 -0
  93. package/dist/lib/helpers/formDataToJSON.d.ts +1 -0
  94. package/dist/lib/helpers/formDataToJSON.d.ts.map +1 -0
  95. package/dist/lib/helpers/isAbsoluteURL.d.ts +1 -0
  96. package/dist/lib/helpers/isAbsoluteURL.d.ts.map +1 -0
  97. package/dist/lib/helpers/isFaxiosError.d.ts +8 -2
  98. package/dist/lib/helpers/isFaxiosError.d.ts.map +1 -0
  99. package/dist/lib/helpers/isFaxiosError.js +5 -1
  100. package/dist/lib/helpers/isFaxiosError.js.map +1 -1
  101. package/dist/lib/helpers/isURLSameOrigin.d.ts +1 -0
  102. package/dist/lib/helpers/isURLSameOrigin.d.ts.map +1 -0
  103. package/dist/lib/helpers/parseHeaders.d.ts +1 -0
  104. package/dist/lib/helpers/parseHeaders.d.ts.map +1 -0
  105. package/dist/lib/helpers/progressEventReducer.d.ts +1 -0
  106. package/dist/lib/helpers/progressEventReducer.d.ts.map +1 -0
  107. package/dist/lib/helpers/sanitizeHeaderValue.d.ts +1 -0
  108. package/dist/lib/helpers/sanitizeHeaderValue.d.ts.map +1 -0
  109. package/dist/lib/helpers/speedometer.d.ts +1 -0
  110. package/dist/lib/helpers/speedometer.d.ts.map +1 -0
  111. package/dist/lib/helpers/substitutePathParams.d.ts +1 -0
  112. package/dist/lib/helpers/substitutePathParams.d.ts.map +1 -0
  113. package/dist/lib/helpers/throttle.d.ts +1 -0
  114. package/dist/lib/helpers/throttle.d.ts.map +1 -0
  115. package/dist/lib/helpers/toFormData.d.ts +1 -0
  116. package/dist/lib/helpers/toFormData.d.ts.map +1 -0
  117. package/dist/lib/helpers/toURLEncodedForm.d.ts +1 -0
  118. package/dist/lib/helpers/toURLEncodedForm.d.ts.map +1 -0
  119. package/dist/lib/helpers/trackStream.d.ts +1 -0
  120. package/dist/lib/helpers/trackStream.d.ts.map +1 -0
  121. package/dist/lib/helpers/validator.d.ts +1 -0
  122. package/dist/lib/helpers/validator.d.ts.map +1 -0
  123. package/dist/lib/platform.d.ts +2 -1
  124. package/dist/lib/platform.d.ts.map +1 -0
  125. package/dist/lib/plugins/attempt.d.ts +2 -0
  126. package/dist/lib/plugins/attempt.d.ts.map +1 -0
  127. package/dist/lib/plugins/attempt.js +4 -0
  128. package/dist/lib/plugins/attempt.js.map +1 -0
  129. package/dist/lib/plugins/authBearer.d.ts +31 -0
  130. package/dist/lib/plugins/authBearer.d.ts.map +1 -0
  131. package/dist/lib/plugins/authBearer.js +99 -0
  132. package/dist/lib/plugins/authBearer.js.map +1 -0
  133. package/dist/lib/plugins/definePlugin.d.ts +22 -0
  134. package/dist/lib/plugins/definePlugin.d.ts.map +1 -0
  135. package/dist/lib/plugins/definePlugin.js +14 -0
  136. package/dist/lib/plugins/definePlugin.js.map +1 -0
  137. package/dist/lib/plugins/retry.d.ts +66 -0
  138. package/dist/lib/plugins/retry.d.ts.map +1 -0
  139. package/dist/lib/plugins/retry.js +168 -0
  140. package/dist/lib/plugins/retry.js.map +1 -0
  141. package/dist/lib/plugins/timing.d.ts +32 -0
  142. package/dist/lib/plugins/timing.d.ts.map +1 -0
  143. package/dist/lib/plugins/timing.js +53 -0
  144. package/dist/lib/plugins/timing.js.map +1 -0
  145. package/dist/lib/types/standard-schema.d.ts +1 -0
  146. package/dist/lib/types/standard-schema.d.ts.map +1 -0
  147. package/dist/lib/types.d.ts +125 -34
  148. package/dist/lib/types.d.ts.map +1 -0
  149. package/dist/lib/utils.d.ts +1 -0
  150. package/dist/lib/utils.d.ts.map +1 -0
  151. package/package.json +42 -19
  152. package/skills/configure-requests/SKILL.md +380 -0
  153. package/skills/configure-requests/references/axios-differences.md +67 -0
  154. package/skills/configure-requests/references/plugins.md +127 -0
  155. package/src/index.ts +57 -0
  156. package/src/lib/adapters/fetch-helpers.ts +167 -0
  157. package/src/lib/adapters/fetch.ts +810 -0
  158. package/src/lib/cancel/CanceledError.ts +23 -0
  159. package/src/lib/cancel/isCancel.ts +10 -0
  160. package/src/lib/core/Faxios.ts +513 -0
  161. package/src/lib/core/FaxiosError.ts +283 -0
  162. package/src/lib/core/FaxiosHeaders.ts +529 -0
  163. package/src/lib/core/buildFullPath.ts +51 -0
  164. package/src/lib/core/define.ts +127 -0
  165. package/src/lib/core/dispatchRequest.ts +171 -0
  166. package/src/lib/core/mergeConfig.ts +175 -0
  167. package/src/lib/core/prepareRequest.ts +155 -0
  168. package/src/lib/core/route.ts +68 -0
  169. package/src/lib/core/settle.ts +20 -0
  170. package/src/lib/core/transformData.ts +23 -0
  171. package/src/lib/core/validateSchema.ts +53 -0
  172. package/src/lib/defaults/index.ts +221 -0
  173. package/src/lib/defaults/transitional.ts +9 -0
  174. package/src/lib/env/data.ts +1 -0
  175. package/src/lib/faxios.ts +306 -0
  176. package/src/lib/helpers/FaxiosURLSearchParams.ts +52 -0
  177. package/src/lib/helpers/HttpStatusCode.ts +77 -0
  178. package/src/lib/helpers/buildURL.ts +77 -0
  179. package/src/lib/helpers/cloneConfig.ts +23 -0
  180. package/src/lib/helpers/combineURLs.ts +11 -0
  181. package/src/lib/helpers/composeSignals.ts +74 -0
  182. package/src/lib/helpers/cookies.ts +68 -0
  183. package/src/lib/helpers/deprecatedMethod.ts +32 -0
  184. package/src/lib/helpers/estimateDataURLDecodedBytes.ts +95 -0
  185. package/src/lib/helpers/formDataToJSON.ts +122 -0
  186. package/src/lib/helpers/isAbsoluteURL.ts +13 -0
  187. package/src/lib/helpers/isFaxiosError.ts +19 -0
  188. package/src/lib/helpers/isURLSameOrigin.ts +16 -0
  189. package/src/lib/helpers/parseHeaders.ts +76 -0
  190. package/src/lib/helpers/progressEventReducer.ts +57 -0
  191. package/src/lib/helpers/sanitizeHeaderValue.ts +61 -0
  192. package/src/lib/helpers/speedometer.ts +55 -0
  193. package/src/lib/helpers/substitutePathParams.ts +13 -0
  194. package/src/lib/helpers/throttle.ts +45 -0
  195. package/src/lib/helpers/toFormData.ts +296 -0
  196. package/src/lib/helpers/toURLEncodedForm.ts +14 -0
  197. package/src/lib/helpers/trackStream.ts +123 -0
  198. package/src/lib/helpers/validator.ts +114 -0
  199. package/src/lib/platform.ts +44 -0
  200. package/src/lib/plugins/attempt.ts +3 -0
  201. package/src/lib/plugins/authBearer.ts +124 -0
  202. package/src/lib/plugins/definePlugin.ts +34 -0
  203. package/src/lib/plugins/retry.ts +245 -0
  204. package/src/lib/plugins/timing.ts +76 -0
  205. package/src/lib/types/standard-schema.ts +58 -0
  206. package/src/lib/types.ts +496 -0
  207. package/src/lib/utils.ts +932 -0
  208. package/dist/lib/core/InterceptorManager.d.ts +0 -9
  209. package/dist/lib/core/InterceptorManager.js +0 -28
  210. package/dist/lib/core/InterceptorManager.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitizeHeaderValue.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/sanitizeHeaderValue.ts"],"names":[],"mappings":"AA8CA,eAAO,MAAM,mBAAmB,GAAI,OAAO,OAAO,sBACQ,CAAC;AAK3D,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAAE,2BAQ3F"}
@@ -6,3 +6,4 @@
6
6
  */
7
7
  declare function speedometer(samplesCount?: number, min?: number): (chunkLength: number) => number | undefined;
8
8
  export default speedometer;
9
+ //# sourceMappingURL=speedometer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speedometer.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/speedometer.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,iBAAS,WAAW,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CA4CrG;AAED,eAAe,WAAW,CAAC"}
@@ -1,2 +1,3 @@
1
1
  /** Expects raw (unencoded) param values — applies encodeURIComponent here. */
2
2
  export declare function substitutePathParams(url: string, params: Record<string, unknown>): string;
3
+ //# sourceMappingURL=substitutePathParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"substitutePathParams.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/substitutePathParams.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAWzF"}
@@ -6,3 +6,4 @@
6
6
  */
7
7
  declare function throttle(fn: (...args: Array<unknown>) => void, freq: number): [(...args: Array<unknown>) => void, () => void];
8
8
  export default throttle;
9
+ //# sourceMappingURL=throttle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/throttle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,iBAAS,QAAQ,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,MAAM,IAAI,CAAC,CAoCtH;AAED,eAAe,QAAQ,CAAC"}
@@ -24,3 +24,4 @@ export declare const DEFAULT_FORM_DATA_MAX_DEPTH = 100;
24
24
  */
25
25
  declare function toFormData(obj: unknown, formData?: GenericFormData | null, options?: Record<string, unknown>): GenericFormData;
26
26
  export default toFormData;
27
+ //# sourceMappingURL=toFormData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toFormData.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/toFormData.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAA6C,oBAAoB;AAK9F,eAAO,MAAM,2BAA2B,MAAM,CAAC;AA2D/C;;;;;;;;;;;;IAYI;AAEJ;;;;;;;;GAQG;AACH,iBAAS,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,eAAe,CA0MvH;AAED,eAAe,UAAU,CAAC"}
@@ -1,2 +1,3 @@
1
1
  import type { GenericFormData } from "../types.js";
2
2
  export default function toURLEncodedForm(data: unknown, options?: Record<string, unknown>): GenericFormData;
3
+ //# sourceMappingURL=toURLEncodedForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toURLEncodedForm.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/toURLEncodedForm.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB;AAGnD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,mBAOxF"}
@@ -1 +1,2 @@
1
1
  export declare const trackStream: (stream: unknown, chunkSize: number | undefined, onProgress?: ((bytes: number) => void) | null, onFinish?: ((err?: unknown) => void) | null) => unknown;
2
+ //# sourceMappingURL=trackStream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trackStream.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/trackStream.ts"],"names":[],"mappings":"AA6EA,eAAO,MAAM,WAAW,GAAI,QAAQ,OAAO,EAAE,WAAW,MAAM,GAAG,SAAS,EAAE,aAAa,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,KAAG,OA6CxK,CAAC"}
@@ -14,3 +14,4 @@ declare const _default: {
14
14
  validators: Record<string, ValidatorFn | undefined>;
15
15
  };
16
16
  export default _default;
17
+ //# sourceMappingURL=validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/validator.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,OAAO,GAAG,MAAM,CAAC;AAmE7F;;;;;;;;GAQG;AAEH,iBAAS,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC,EAAE,YAAY,EAAE,OAAO,GAAG,IAAI,CA0BrH;;;;;AAED,wBAGE"}
@@ -6,7 +6,7 @@ declare const _default: {
6
6
  new (init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
7
7
  prototype: URLSearchParams;
8
8
  } | typeof FaxiosURLSearchParams;
9
- FormData: (new (...args: Array<unknown>) => object) | null;
9
+ FormData: (new () => object) | null;
10
10
  Blob: (new (...args: Array<unknown>) => object) | null;
11
11
  };
12
12
  protocols: string[];
@@ -20,3 +20,4 @@ declare const _default: {
20
20
  origin: string;
21
21
  };
22
22
  export default _default;
23
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/lib/platform.ts"],"names":[],"mappings":"AAEA,OAAO,qBAAqB,2CAA2C;;;;;;;;6BAQhD,MAAM;6BACN,KAAK,CAAC,OAAO,CAAC,KAAK,MAAM;;;;;;;kBAJtB,MAAM;oBAAc,MAAM;;;;AAuBpD,wBAaE"}
@@ -0,0 +1,2 @@
1
+ export declare const RETRY_ATTEMPT: unique symbol;
2
+ //# sourceMappingURL=attempt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempt.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/attempt.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,EAAE,OAAO,MAAuC,CAAC"}
@@ -0,0 +1,4 @@
1
+ // Shared only by the built-in plugins; not exported from any entry point. retry writes the number
2
+ // of the try it is about to make under this key of ctx.state, and timing reads it.
3
+ export const RETRY_ATTEMPT = Symbol("faxios.retry.attempt");
4
+ //# sourceMappingURL=attempt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempt.js","sourceRoot":"","sources":["../../../src/lib/plugins/attempt.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,mFAAmF;AACnF,MAAM,CAAC,MAAM,aAAa,GAAkB,MAAM,CAAC,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { FaxiosPlugin } from "../types.js";
2
+ /** What `authBearer` provides to plugins installed after it. */
3
+ export type AuthBearerCapability = {
4
+ auth: {
5
+ getToken: () => Promise<string>;
6
+ };
7
+ };
8
+ export type AuthBearerOptions = {
9
+ /** Replace a header the request already has. Default `false`: an explicit header is kept. */
10
+ overwrite?: boolean;
11
+ /** Put before the token, separated by a space. Default `"Bearer"`; `""` sends the bare token. */
12
+ scheme?: string;
13
+ /** The header to set. Default `"Authorization"`. */
14
+ header?: string;
15
+ /**
16
+ * The origins (`"https://api.example.com"`) that get the token, replacing the default rule:
17
+ * with an absolute `baseURL`, only its origin; otherwise only relative request URLs.
18
+ */
19
+ origins?: Array<string>;
20
+ };
21
+ /**
22
+ * Sets `Authorization: Bearer <token>` on requests to the API it guards, asking `getToken` each
23
+ * time, and provides the `auth` capability so later plugins (for example a token-refresh plugin)
24
+ * can ask for a token too. A header the request already has is kept unless `overwrite` is set.
25
+ * The token goes only to the `baseURL` origin when `baseURL` is absolute, otherwise only to
26
+ * relative request URLs; `origins` replaces that rule.
27
+ */
28
+ export declare function authBearer(getToken: () => string | Promise<string>, options?: AuthBearerOptions): FaxiosPlugin<{
29
+ provides: AuthBearerCapability;
30
+ }>;
31
+ //# sourceMappingURL=authBearer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authBearer.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/authBearer.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAA+B,oBAAoB;AAI7E,gEAAgE;AAChE,MAAM,MAAM,oBAAoB,GAAG;IAAE,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;KAAE,CAAC;CAAE,CAAC;AAEnF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,6FAA6F;IAC7F,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iGAAiG;IACjG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACzB,CAAC;AA6DF;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,GAAE,iBAAsB,GAAG,YAAY,CAAC;IAAE,QAAQ,EAAE,oBAAoB,CAAC;CAAE,CAAC,CA6BvJ"}
@@ -0,0 +1,99 @@
1
+ // @ts-self-types="./authBearer.d.ts" — required for Deno: maps built .js to adjacent .d.ts in dist/
2
+ import buildFullPath from "../core/buildFullPath.js";
3
+ import FaxiosError from "../core/FaxiosError.js";
4
+ import FaxiosHeaders from "../core/FaxiosHeaders.js";
5
+ import isAbsoluteURL from "../helpers/isAbsoluteURL.js";
6
+ import validator from "../helpers/validator.js";
7
+ import utils from "../utils.js";
8
+ import { definePlugin } from "./definePlugin.js";
9
+ // A header name is a token (RFC 9110 §5.6.2).
10
+ const TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
11
+ // A bare origin, optionally with a trailing slash. A path would look like a narrower limit than
12
+ // the origin the token is really sent to.
13
+ function originOf(value) {
14
+ if (typeof value !== "string")
15
+ return null;
16
+ try {
17
+ const { origin } = new URL(value);
18
+ return origin !== "null" && (value === origin || value === `${origin}/`) ? origin : null;
19
+ }
20
+ catch {
21
+ return null;
22
+ }
23
+ }
24
+ const optionsSchema = {
25
+ overwrite: validator.validators["boolean"],
26
+ scheme: (value) => (typeof value === "string" && !/[\r\n]/.test(value)) || "a string without line breaks",
27
+ header: (value) => (typeof value === "string" && TOKEN.test(value)) || "a header name",
28
+ origins: (value) => (Array.isArray(value) && value.every(o => originOf(o) !== null)) || "an array of origins such as \"https://api.example.com\"",
29
+ };
30
+ const own = (source, key) => (utils.hasOwnProp(source, key) ? source[key] : undefined);
31
+ // Resolves a relative URL the way a page would, without ever matching a real origin, so a URL
32
+ // that leaves the page (`//host`, `/\host`) is told apart from one that stays on it.
33
+ const SAME_ORIGIN = "https://same-origin.invalid";
34
+ function resolvedOrigin(url, base) {
35
+ try {
36
+ return new URL(url, base).origin;
37
+ }
38
+ catch {
39
+ return null;
40
+ }
41
+ }
42
+ // A relative URL goes to the page's origin, which only a browser has.
43
+ function pageHref() {
44
+ const location = "location" in globalThis ? globalThis.location : undefined;
45
+ if (location && typeof location === "object" && "href" in location && typeof location.href === "string")
46
+ return location.href;
47
+ return undefined;
48
+ }
49
+ function sendsTokenTo(config, origins) {
50
+ const baseURL = own(config, "baseURL");
51
+ const url = buildFullPath(baseURL, own(config, "url"), own(config, "allowAbsoluteUrls"), config);
52
+ if (origins) {
53
+ const origin = resolvedOrigin(url, isAbsoluteURL(url) ? undefined : pageHref());
54
+ return origin !== null && origins.includes(origin);
55
+ }
56
+ if (typeof baseURL === "string" && isAbsoluteURL(baseURL)) {
57
+ return resolvedOrigin(url, baseURL) === resolvedOrigin(baseURL, undefined);
58
+ }
59
+ return !isAbsoluteURL(url) && resolvedOrigin(url, SAME_ORIGIN) === SAME_ORIGIN;
60
+ }
61
+ /**
62
+ * Sets `Authorization: Bearer <token>` on requests to the API it guards, asking `getToken` each
63
+ * time, and provides the `auth` capability so later plugins (for example a token-refresh plugin)
64
+ * can ask for a token too. A header the request already has is kept unless `overwrite` is set.
65
+ * The token goes only to the `baseURL` origin when `baseURL` is absolute, otherwise only to
66
+ * relative request URLs; `origins` replaces that rule.
67
+ */
68
+ export function authBearer(getToken, options = {}) {
69
+ if (typeof getToken !== "function") {
70
+ throw new FaxiosError("authBearer: getToken must be a function", FaxiosError.ERR_BAD_OPTION_VALUE);
71
+ }
72
+ // Callers without TypeScript can pass anything.
73
+ const given = options;
74
+ if (given === null || typeof given !== "object") {
75
+ throw new FaxiosError("authBearer options must be an object", FaxiosError.ERR_BAD_OPTION_VALUE);
76
+ }
77
+ validator.assertOptions(options, optionsSchema, false);
78
+ const overwrite = own(options, "overwrite") ?? false;
79
+ const scheme = own(options, "scheme") ?? "Bearer";
80
+ const header = own(options, "header") ?? "Authorization";
81
+ const origins = own(options, "origins")?.map(o => originOf(o)) ?? null;
82
+ const auth = { getToken: async () => getToken() };
83
+ return definePlugin({
84
+ name: "authBearer",
85
+ provides: { auth },
86
+ middleware: async (ctx, next) => {
87
+ if ((!overwrite && ctx.config.headers.has(header)) || !sendsTokenTo(ctx.config, origins))
88
+ return next(ctx);
89
+ const token = await auth.getToken();
90
+ // On a copy: middleware that calls next() again (retry installed before this plugin) comes
91
+ // back through here without the header, so every try asks for a fresh token.
92
+ const headers = new FaxiosHeaders(ctx.config.headers).set(header, scheme ? `${scheme} ${token}` : token, true);
93
+ const config = { ...ctx.config };
94
+ config.headers = headers;
95
+ return next({ ...ctx, config });
96
+ },
97
+ });
98
+ }
99
+ //# sourceMappingURL=authBearer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authBearer.js","sourceRoot":"","sources":["../../../src/lib/plugins/authBearer.ts"],"names":[],"mappings":"AAAA,oGAAoG;AAEpG,OAAO,aAAa,iCAAiC;AACrD,OAAO,WAAW,+BAA+B;AACjD,OAAO,aAAa,iCAAiC;AACrD,OAAO,aAAa,oCAAoC;AACxD,OAAO,SAAS,gCAAgC;AAEhD,OAAO,KAAK,oBAAoB;AAChC,OAAO,EAAE,YAAY,EAAE,0BAA0B;AAmBjD,8CAA8C;AAC9C,MAAM,KAAK,GAAG,gCAAgC,CAAC;AAE/C,gGAAgG;AAChG,0CAA0C;AAC1C,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3C,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAClC,OAAO,MAAM,KAAK,MAAM,IAAI,CAAC,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,CAA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AK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpC,2FAA2F;YAC3F,6EAA6E;YAC7E,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC/G,MAAM,MAAM,GAAG,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;YACjC,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;YACzB,OAAO,IAAI,CAAC,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;QAClC,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { FaxiosMiddleware, FaxiosPlugin } from "../types.js";
2
+ type Slot<T> = [keyof T] extends [never] ? unknown : T;
3
+ type RequiredCapabilities<TCapabilities, TProvides> = [keyof TProvides] extends [never] ? Slot<TCapabilities> : Slot<{
4
+ [K in keyof TCapabilities as K extends keyof TProvides ? never : K]: TCapabilities[K];
5
+ }>;
6
+ /**
7
+ * Builds a plugin for `use()` and infers its `FaxiosPlugin` slots from the object: `provides` from
8
+ * the `provides` value, `options` and `requires` from the context type the middleware annotates
9
+ * (`ctx: FaxiosContext<Options, Capabilities>`). Capabilities the plugin provides itself don't
10
+ * count as required. Returns the same object.
11
+ */
12
+ export declare function definePlugin<TProvides = {}, TOptions = {}, TCapabilities = TProvides>(plugin: {
13
+ name: string;
14
+ provides?: TProvides & NoInfer<Pick<TCapabilities, keyof TProvides & keyof TCapabilities>>;
15
+ middleware: FaxiosMiddleware<TOptions, TCapabilities>;
16
+ }): FaxiosPlugin<{
17
+ requires: RequiredCapabilities<TCapabilities, TProvides>;
18
+ provides: Slot<TProvides>;
19
+ options: Slot<TOptions>;
20
+ }>;
21
+ export {};
22
+ //# sourceMappingURL=definePlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definePlugin.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/definePlugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,oBAAoB;AAGlE,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC;AAGvD,KAAK,oBAAoB,CAAC,aAAa,EAAE,SAAS,IAAI,CAAC,MAAM,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,GACnF,IAAI,CAAC,aAAa,CAAC,GACnB,IAAI,CAAC;KAAG,CAAC,IAAI,MAAM,aAAa,IAAI,CAAC,SAAS,MAAM,SAAS,GAAG,KAAK,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;CAAG,CAAC,CAAC;AAErG;;;;;GAKG;AAEH,wBAAgB,YAAY,CAAC,SAAS,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAE,aAAa,GAAG,SAAS,EAAE,MAAM,EAAE;IAC7F,IAAI,EAAE,MAAM,CAAC;IAGb,QAAQ,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,CAAC,CAAC;IAC3F,UAAU,EAAE,gBAAgB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;CACvD,GAAG,YAAY,CAAC;IACf,QAAQ,EAAE,oBAAoB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IACzD,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC1B,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;CACzB,CAAC,CAGD"}
@@ -0,0 +1,14 @@
1
+ // @ts-self-types="./definePlugin.d.ts" — required for Deno: maps built .js to adjacent .d.ts in dist/
2
+ // The `@gcmdev/faxios/plugins` entry point. The built-in plugins have their own subpaths.
3
+ /**
4
+ * Builds a plugin for `use()` and infers its `FaxiosPlugin` slots from the object: `provides` from
5
+ * the `provides` value, `options` and `requires` from the context type the middleware annotates
6
+ * (`ctx: FaxiosContext<Options, Capabilities>`). Capabilities the plugin provides itself don't
7
+ * count as required. Returns the same object.
8
+ */
9
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- `{}`: no capabilities or options, as in FaxiosContext
10
+ export function definePlugin(plugin) {
11
+ // Only the types change: use() reads the fields at install time, as it does for any plugin.
12
+ return plugin;
13
+ }
14
+ //# sourceMappingURL=definePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definePlugin.js","sourceRoot":"","sources":["../../../src/lib/plugins/definePlugin.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,0FAA0F;AAY1F;;;;;GAKG;AACH,4HAA4H;AAC5H,MAAM,UAAU,YAAY,CAA2D,MAMtF;IAKC,4FAA4F;IAC5F,OAAO,MAAe,CAAC;AACzB,CAAC"}
@@ -0,0 +1,66 @@
1
+ import type { FaxiosPlugin, Method } from "../types.js";
2
+ export type RetryOptions = {
3
+ /** Total tries, counting the first request. Default 3. */
4
+ attempts?: number;
5
+ /**
6
+ * Whether the try that just failed should be retried. `attempt` counts from 1.
7
+ * Default: network errors, timeouts and the `statuses`; never a cancellation. A custom `retryOn`
8
+ * replaces that whole predicate, so `statuses` is ignored when both are set. retryOn decides
9
+ * only within `methods`; to retry POST, list it in `methods`.
10
+ */
11
+ retryOn?: (error: unknown, attempt: number) => boolean;
12
+ /**
13
+ * Response statuses the default predicate retries. Default 408, 429, 500, 502, 503 and 504.
14
+ * Ignored when `retryOn` is set.
15
+ */
16
+ statuses?: ReadonlyArray<number>;
17
+ /**
18
+ * Milliseconds to wait before the next try, or a function of the try that failed. Default 100ms,
19
+ * doubling. Capped at `maxDelay`, then jittered. A 429 or 503 with a `Retry-After` header waits
20
+ * that long instead, unless `respectRetryAfter` is `false`.
21
+ */
22
+ delay?: number | ((attempt: number, error: unknown) => number);
23
+ /** The most the computed backoff waits, in milliseconds. Default 30 000. Doesn't apply to `Retry-After`. */
24
+ maxDelay?: number;
25
+ /**
26
+ * `"full"` (default) waits a random time between 0 and the capped backoff, so clients that failed
27
+ * together don't retry together; `"none"` waits the capped backoff. Doesn't apply to `Retry-After`.
28
+ */
29
+ jitter?: "full" | "none";
30
+ /**
31
+ * The longest `Retry-After` (seconds or an HTTP date, on a 429 or 503) to wait, in milliseconds.
32
+ * Default 300 000 (5 minutes). A longer one rejects with the response's error instead of retrying.
33
+ * Ignored when `respectRetryAfter` is `false`.
34
+ */
35
+ maxRetryAfter?: number;
36
+ /**
37
+ * Whether a 429 or 503's `Retry-After` header sets the wait. Default `true`. With `false`, every
38
+ * retry waits the computed backoff and `maxRetryAfter` doesn't apply; which requests retry doesn't
39
+ * change. Turn it off when another plugin, such as a queue throttle, honours `Retry-After` itself.
40
+ */
41
+ respectRetryAfter?: boolean;
42
+ /**
43
+ * Called before each wait with the error, the try that failed and the wait in milliseconds. If it
44
+ * throws, the request rejects with that error and stops retrying.
45
+ */
46
+ onRetry?: (error: unknown, attempt: number, delayMs: number) => void;
47
+ /**
48
+ * HTTP methods that may be retried, in any case. Default: GET, HEAD, OPTIONS, PUT, DELETE and
49
+ * QUERY. POST and PATCH aren't idempotent, so add them only if your API dedupes repeats. A request
50
+ * whose method isn't listed is never retried, whatever `retryOn` or `statuses` say.
51
+ */
52
+ methods?: ReadonlyArray<Method>;
53
+ };
54
+ /** Per-request override: `false` turns retries off, an object overrides the plugin's options. */
55
+ export type RetryRequestOptions = {
56
+ retry?: RetryOptions | false;
57
+ };
58
+ /**
59
+ * Retries failed requests by calling `next` again. Each `next` dispatches its own copy of the
60
+ * config, so every try starts from the same input. Install it inside middleware that should run
61
+ * once per request (for example `timing` installed first measures all tries together).
62
+ */
63
+ export declare function retry(options?: RetryOptions): FaxiosPlugin<{
64
+ options: RetryRequestOptions;
65
+ }>;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C,CAiCjG"}
@@ -0,0 +1,168 @@
1
+ // @ts-self-types="./retry.d.ts" — required for Deno: maps built .js to adjacent .d.ts in dist/
2
+ import CanceledError from "../cancel/CanceledError.js";
3
+ import isCancel from "../cancel/isCancel.js";
4
+ import FaxiosError from "../core/FaxiosError.js";
5
+ import validator from "../helpers/validator.js";
6
+ import utils from "../utils.js";
7
+ import { RETRY_ATTEMPT } from "./attempt.js";
8
+ import { definePlugin } from "./definePlugin.js";
9
+ // Config values are read as own properties only (repo rule for possibly untrusted input).
10
+ const ownValue = (source, key) => (utils.hasOwnProp(source, key) ? source[key] : undefined);
11
+ const isWait = (ms) => typeof ms === "number" && Number.isFinite(ms) && ms >= 0;
12
+ // An HTTP method is a token (RFC 9110 §9.1, §5.6.2); anything else can never match a request.
13
+ const TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
14
+ const isStatus = (value) => Number.isInteger(value) && value >= 100 && value <= 599;
15
+ // Bounded on purpose: NaN or Infinity would make a failing request loop forever.
16
+ const optionsSchema = {
17
+ attempts: (value) => (Number.isInteger(value) && value >= 1) || "an integer of at least 1",
18
+ retryOn: validator.validators["function"],
19
+ delay: (value) => isWait(value) || typeof value === "function" || "a finite number of at least 0 or a function",
20
+ methods: (value) => (Array.isArray(value) && value.every(m => typeof m === "string" && TOKEN.test(m))) || "an array of HTTP method names",
21
+ statuses: (value) => (Array.isArray(value) && value.every(isStatus)) || "an array of HTTP status codes (100-599)",
22
+ maxRetryAfter: (value) => isWait(value) || "a finite number of milliseconds of at least 0",
23
+ maxDelay: (value) => isWait(value) || "a finite number of milliseconds of at least 0",
24
+ jitter: (value) => value === "full" || value === "none" || "\"full\" or \"none\"",
25
+ respectRetryAfter: validator.validators["boolean"],
26
+ onRetry: validator.validators["function"],
27
+ };
28
+ // Transient failures: timeout, rate limit, and server errors that may clear on their own. 501 and
29
+ // 505 mean the server will never handle the request, so they aren't here.
30
+ const DEFAULT_STATUSES = [408, 429, 500, 502, 503, 504];
31
+ // Statuses whose Retry-After says when to try again (RFC 9110 §10.2.3).
32
+ const RETRY_AFTER_STATUSES = [429, 503];
33
+ // Methods whose repeat has the same effect as one request (RFC 9110 §9.2.2, plus QUERY).
34
+ const IDEMPOTENT_METHODS = ["get", "head", "options", "put", "delete", "query"];
35
+ // One check for both the factory argument and a per-request override.
36
+ function assertRetryOptions(value, config) {
37
+ if (value === null || typeof value !== "object") {
38
+ throw new FaxiosError("retry options must be an object", FaxiosError.ERR_BAD_OPTION_VALUE, config);
39
+ }
40
+ validator.assertOptions(value, optionsSchema, false);
41
+ }
42
+ function retryByDefault(error, statuses) {
43
+ if (isCancel(error) || !(error instanceof FaxiosError))
44
+ return false;
45
+ if (error.code === FaxiosError.ERR_NETWORK || error.code === FaxiosError.ETIMEDOUT)
46
+ return true;
47
+ const status = error.response?.status;
48
+ return status !== undefined && statuses.includes(status);
49
+ }
50
+ // The wait a 429 or 503 asks for, in milliseconds: delay-seconds or an HTTP date (a past date
51
+ // means now). undefined when there's no usable header, so the computed backoff applies.
52
+ function retryAfterMs(error) {
53
+ if (!(error instanceof FaxiosError) || !error.response || !RETRY_AFTER_STATUSES.includes(error.response.status))
54
+ return undefined;
55
+ const value = error.response.headers.get("retry-after");
56
+ if (typeof value !== "string")
57
+ return undefined;
58
+ const trimmed = value.trim();
59
+ if (/^\d+$/.test(trimmed))
60
+ return Number(trimmed) * 1000;
61
+ const date = Date.parse(trimmed);
62
+ return Number.isNaN(date) ? undefined : Math.max(0, date - Date.now());
63
+ }
64
+ const doublingDelay = (attempt) => 100 * 2 ** (attempt - 1);
65
+ // A stream is consumed by the first try, so sending it again would send nothing.
66
+ // The same stream checks the fetch adapter uses: web ReadableStreams and Node-style pipe streams.
67
+ function canReplay(data) {
68
+ return !utils.isReadableStream?.(data) && !utils.isStream(data);
69
+ }
70
+ function wait(ms, signal, config) {
71
+ return new Promise((resolve, reject) => {
72
+ if (signal?.aborted) {
73
+ reject(new CanceledError(null, config));
74
+ return;
75
+ }
76
+ const onAbort = () => {
77
+ clearTimeout(timer);
78
+ signal?.removeEventListener?.("abort", onAbort);
79
+ reject(new CanceledError(null, config));
80
+ };
81
+ const timer = setTimeout(() => {
82
+ signal?.removeEventListener?.("abort", onAbort);
83
+ resolve();
84
+ }, ms);
85
+ signal?.addEventListener?.("abort", onAbort);
86
+ });
87
+ }
88
+ // Each list is lower-cased right after it is validated: the plugin's once, a per-request override's
89
+ // on the request that carries it.
90
+ function retriesMethod(config, perRequest, pluginMethods) {
91
+ const requestMethods = perRequest ? ownValue(perRequest, "methods")?.map(m => m.toLowerCase()) : undefined;
92
+ const methods = requestMethods ?? pluginMethods ?? IDEMPOTENT_METHODS;
93
+ return methods.includes(String(ownValue(config, "method") ?? "get").toLowerCase());
94
+ }
95
+ // Per field, request first: no merged object, and only own properties count.
96
+ function resolvePolicy(options, perRequest) {
97
+ const setting = (key) => (perRequest ? ownValue(perRequest, key) : undefined) ?? ownValue(options, key);
98
+ const statuses = setting("statuses") ?? DEFAULT_STATUSES;
99
+ return {
100
+ attempts: setting("attempts") ?? 3,
101
+ retryOn: setting("retryOn") ?? ((error) => retryByDefault(error, statuses)),
102
+ delay: setting("delay") ?? doublingDelay,
103
+ maxDelay: setting("maxDelay") ?? 30_000,
104
+ jitter: setting("jitter") ?? "full",
105
+ maxRetryAfter: setting("maxRetryAfter") ?? 300_000,
106
+ respectRetryAfter: setting("respectRetryAfter") ?? true,
107
+ onRetry: setting("onRetry"),
108
+ };
109
+ }
110
+ // How long to wait before the next try, or undefined when the server's Retry-After is longer
111
+ // than the caller is willing to wait, so the error is rethrown.
112
+ function waitBeforeRetry(error, attempt, policy, config) {
113
+ const retryAfter = policy.respectRetryAfter ? retryAfterMs(error) : undefined;
114
+ if (retryAfter !== undefined)
115
+ return retryAfter > policy.maxRetryAfter ? undefined : retryAfter;
116
+ const computed = typeof policy.delay === "function" ? policy.delay(attempt, error) : policy.delay;
117
+ if (!isWait(computed)) {
118
+ throw new FaxiosError(`retry: delay must give a finite number of at least 0, got ${String(computed)}`, FaxiosError.ERR_BAD_OPTION_VALUE, config);
119
+ }
120
+ const capped = Math.min(computed, policy.maxDelay);
121
+ // Jitter only spreads out clients that failed together; it needs no unpredictability.
122
+ // eslint-disable-next-line sonarjs/pseudo-random -- see above
123
+ return policy.jitter === "full" ? Math.floor(Math.random() * capped) : capped;
124
+ }
125
+ /**
126
+ * Retries failed requests by calling `next` again. Each `next` dispatches its own copy of the
127
+ * config, so every try starts from the same input. Install it inside middleware that should run
128
+ * once per request (for example `timing` installed first measures all tries together).
129
+ */
130
+ export function retry(options = {}) {
131
+ assertRetryOptions(options);
132
+ // Lower-cased once here, so requests compare names without re-casing the list.
133
+ const pluginMethods = ownValue(options, "methods")?.map(m => m.toLowerCase());
134
+ return definePlugin({
135
+ name: "retry",
136
+ middleware: async (ctx, next) => {
137
+ const perRequest = ownValue(ctx.config, "retry");
138
+ if (perRequest === false)
139
+ return next(ctx);
140
+ if (perRequest !== undefined)
141
+ assertRetryOptions(perRequest, ctx.config);
142
+ const policy = resolvePolicy(options, perRequest);
143
+ if (!retriesMethod(ctx.config, perRequest, pluginMethods))
144
+ return next(ctx);
145
+ // Tries run one after another on purpose: each must finish before deciding on the next.
146
+ for (let attempt = 1;; attempt++) {
147
+ // For timing: the try number, read after next() settles.
148
+ ctx.state[RETRY_ATTEMPT] = attempt;
149
+ try {
150
+ // eslint-disable-next-line no-await-in-loop -- see above
151
+ return await next(ctx);
152
+ }
153
+ catch (error) {
154
+ if (attempt >= policy.attempts || !canReplay(ownValue(ctx.config, "data")) || !policy.retryOn(error, attempt))
155
+ throw error;
156
+ const ms = waitBeforeRetry(error, attempt, policy, ctx.config);
157
+ if (ms === undefined)
158
+ throw error;
159
+ // A throwing hook rejects the request with its own error, before any wait.
160
+ policy.onRetry?.(error, attempt, ms);
161
+ // eslint-disable-next-line no-await-in-loop -- see above
162
+ await wait(ms, ownValue(ctx.config, "signal"), ctx.config);
163
+ }
164
+ }
165
+ },
166
+ });
167
+ }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M,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC;wBAAE,MAAM,KAAK,CAAC;oBAC3H,MAAM,EAAE,GAAG,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;oBAC/D,IAAI,EAAE,KAAK,SAAS;wBAAE,MAAM,KAAK,CAAC;oBAClC,2EAA2E;oBAC3E,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;oBACrC,yDAAyD;oBACzD,MAAM,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;gBAC7D,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { FaxiosPlugin } from "../types.js";
2
+ /**
3
+ * What `timing` reports once per request: `status` on success, `error` on failure. No config,
4
+ * headers or body, so an event is safe to log.
5
+ */
6
+ export type TimingEvent = {
7
+ /** The request method, upper-cased (`"GET"`). */
8
+ method: string;
9
+ /** The full request URL without its query string and fragment. */
10
+ url: string;
11
+ /**
12
+ * The try number from `retry`: each try's when installed after it, the final try's when
13
+ * installed before it. Absent without `retry`.
14
+ */
15
+ attempt?: number;
16
+ durationMs: number;
17
+ } & ({
18
+ status: number;
19
+ error?: undefined;
20
+ } | {
21
+ status?: undefined;
22
+ error: unknown;
23
+ });
24
+ /**
25
+ * Measures the time around `next` and calls `onTiming` once per request with the method, URL,
26
+ * duration and status or error. Installed before `retry`, the duration covers every try;
27
+ * installed after it, each try is reported. The response is returned unchanged. If `onTiming`
28
+ * throws while reporting a failure, the request still rejects with its own error; while
29
+ * reporting a success, its error rejects the request.
30
+ */
31
+ export declare function timing(onTiming: (event: TimingEvent) => void): FaxiosPlugin;
32
+ //# sourceMappingURL=timing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timing.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/timing.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAiB,YAAY,EAAE,oBAAoB;AAK/D;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAC;CAAE,GAAG;IAAE,MAAM,CAAC,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;CAAE,CAAC,CAAC;AAsBvF;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,YAAY,CAuB3E"}