@venizia/ignis-helpers 0.4.8 → 0.5.0-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.
Files changed (87) hide show
  1. package/dist/esm/common/constants/http.d.ts +3 -0
  2. package/dist/esm/common/constants/http.js +3 -0
  3. package/dist/esm/common/constants/http.js.map +1 -1
  4. package/dist/esm/common/redact.js +2 -0
  5. package/dist/esm/common/redact.js.map +1 -1
  6. package/dist/esm/core.d.ts +5 -2
  7. package/dist/esm/core.js +5 -2
  8. package/dist/esm/core.js.map +1 -1
  9. package/dist/esm/modules/network/http-request/base-network-request.helper.d.ts +5 -0
  10. package/dist/esm/modules/network/http-request/base-network-request.helper.js +14 -17
  11. package/dist/esm/modules/network/http-request/base-network-request.helper.js.map +1 -1
  12. package/dist/esm/modules/network/http-request/common/constants.d.ts +2 -1
  13. package/dist/esm/modules/network/http-request/common/constants.js +2 -1
  14. package/dist/esm/modules/network/http-request/common/constants.js.map +1 -1
  15. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts +37 -11
  16. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +181 -38
  17. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
  18. package/dist/esm/modules/network/http-request/fetcher/base-fetcher.d.ts +204 -18
  19. package/dist/esm/modules/network/http-request/fetcher/base-fetcher.js +433 -13
  20. package/dist/esm/modules/network/http-request/fetcher/base-fetcher.js.map +1 -1
  21. package/dist/esm/modules/network/http-request/fetcher/common/body-limit.d.ts +36 -0
  22. package/dist/esm/modules/network/http-request/fetcher/common/body-limit.js +119 -0
  23. package/dist/esm/modules/network/http-request/fetcher/common/body-limit.js.map +1 -0
  24. package/dist/esm/modules/network/http-request/fetcher/common/errors.d.ts +40 -0
  25. package/dist/esm/modules/network/http-request/fetcher/common/errors.js +37 -0
  26. package/dist/esm/modules/network/http-request/fetcher/common/errors.js.map +1 -0
  27. package/dist/esm/modules/network/http-request/fetcher/common/guard.d.ts +27 -0
  28. package/dist/esm/modules/network/http-request/fetcher/common/guard.js +2 -0
  29. package/dist/esm/modules/network/http-request/fetcher/common/guard.js.map +1 -0
  30. package/dist/esm/modules/network/http-request/fetcher/common/index.d.ts +6 -0
  31. package/dist/esm/modules/network/http-request/fetcher/common/index.js +6 -0
  32. package/dist/esm/modules/network/http-request/fetcher/common/index.js.map +1 -1
  33. package/dist/esm/modules/network/http-request/fetcher/common/request-context.d.ts +15 -0
  34. package/dist/esm/modules/network/http-request/fetcher/common/request-context.js +11 -0
  35. package/dist/esm/modules/network/http-request/fetcher/common/request-context.js.map +1 -0
  36. package/dist/esm/modules/network/http-request/fetcher/common/response-reader.d.ts +9 -0
  37. package/dist/esm/modules/network/http-request/fetcher/common/response-reader.js +14 -0
  38. package/dist/esm/modules/network/http-request/fetcher/common/response-reader.js.map +1 -0
  39. package/dist/esm/modules/network/http-request/fetcher/common/types.d.ts +65 -1
  40. package/dist/esm/modules/network/http-request/fetcher/common/types.js.map +1 -1
  41. package/dist/esm/modules/network/http-request/fetcher/common/utilities.d.ts +68 -0
  42. package/dist/esm/modules/network/http-request/fetcher/common/utilities.js +143 -0
  43. package/dist/esm/modules/network/http-request/fetcher/common/utilities.js.map +1 -0
  44. package/dist/esm/modules/network/http-request/fetcher/index.d.ts +2 -1
  45. package/dist/esm/modules/network/http-request/fetcher/index.js +2 -1
  46. package/dist/esm/modules/network/http-request/fetcher/index.js.map +1 -1
  47. package/dist/esm/modules/network/http-request/fetcher/native-fetcher.d.ts +83 -0
  48. package/dist/esm/modules/network/http-request/fetcher/native-fetcher.js +221 -0
  49. package/dist/esm/modules/network/http-request/fetcher/native-fetcher.js.map +1 -0
  50. package/dist/esm/modules/network/utilities/index.d.ts +1 -0
  51. package/dist/esm/modules/network/utilities/index.js +1 -0
  52. package/dist/esm/modules/network/utilities/index.js.map +1 -1
  53. package/dist/esm/modules/network/utilities/query-string.d.ts +6 -23
  54. package/dist/esm/modules/network/utilities/query-string.js +3 -17
  55. package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
  56. package/dist/esm/modules/network/utilities/url-builder.d.ts +39 -0
  57. package/dist/esm/modules/network/utilities/url-builder.js +102 -0
  58. package/dist/esm/modules/network/utilities/url-builder.js.map +1 -0
  59. package/dist/esm/modules/network/utilities/url-safety/common/constants.d.ts +0 -3
  60. package/dist/esm/modules/network/utilities/url-safety/common/constants.js.map +1 -1
  61. package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts +38 -0
  62. package/dist/esm/modules/network/utilities/url-safety/common/errors.js +33 -1
  63. package/dist/esm/modules/network/utilities/url-safety/common/errors.js.map +1 -1
  64. package/dist/esm/modules/network/utilities/url-safety/common/types.d.ts +26 -3
  65. package/dist/esm/modules/network/utilities/url-safety/common/types.js.map +1 -1
  66. package/dist/esm/modules/network/utilities/url-safety/guard.d.ts +46 -0
  67. package/dist/esm/modules/network/utilities/url-safety/guard.js +145 -0
  68. package/dist/esm/modules/network/utilities/url-safety/guard.js.map +1 -0
  69. package/dist/esm/modules/network/utilities/url-safety/index.d.ts +1 -1
  70. package/dist/esm/modules/network/utilities/url-safety/index.js +1 -1
  71. package/dist/esm/modules/network/utilities/url-safety/index.js.map +1 -1
  72. package/dist/esm/modules/network/utilities/url-safety/policy.d.ts +52 -2
  73. package/dist/esm/modules/network/utilities/url-safety/policy.js +161 -14
  74. package/dist/esm/modules/network/utilities/url-safety/policy.js.map +1 -1
  75. package/dist/esm/modules/queue/bullmq/helper.d.ts +43 -7
  76. package/dist/esm/modules/queue/bullmq/helper.js +70 -2
  77. package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
  78. package/dist/esm/modules/retry/helper.d.ts +3 -1
  79. package/dist/esm/modules/retry/helper.js +8 -4
  80. package/dist/esm/modules/retry/helper.js.map +1 -1
  81. package/package.json +3 -3
  82. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts +0 -41
  83. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +0 -111
  84. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js.map +0 -1
  85. package/dist/esm/modules/network/utilities/url-safety/ingest.d.ts +0 -95
  86. package/dist/esm/modules/network/utilities/url-safety/ingest.js +0 -328
  87. package/dist/esm/modules/network/utilities/url-safety/ingest.js.map +0 -1
@@ -1,71 +1,214 @@
1
1
  import { HTTP } from '../../../../common/index.js';
2
- import { RedactUtility } from '../../../../common/redact.js';
3
2
  import axios from 'axios';
3
+ import http from 'node:http';
4
4
  import https from 'node:https';
5
- import { stringify } from 'node:querystring';
5
+ import { isIP } from 'node:net';
6
+ import { QueryStringUtility } from '../../utilities/query-string.js';
7
+ import { getError } from '../../../error/index.js';
6
8
  import { BaseNetworkRequest } from '../base-network-request.helper.js';
7
- import { AbstractNetworkFetchableHelper } from './base-fetcher.js';
8
- /** Fetcher over an axios instance (`getWorker()`). HTTPS calls share one keep-alive agent that verifies certificates unless `rejectUnauthorized` is `false`; an `httpsAgent` passed in the request wins. */
9
+ import { AbstractNetworkFetchableHelper, } from './base-fetcher.js';
10
+ import { BodyLimit } from './common/body-limit.js';
11
+ import { FetchHeaders } from './common/utilities.js';
12
+ /**
13
+ * The request options a guarded call accepts, besides the ones the pipeline owns. An allowlist, not a denylist: axios keeps
14
+ * adding transport knobs (`httpVersion`, `http2Options`, ...) that connect on their own and ignore the pinned agent, so
15
+ * anything not listed here is refused, per call and in `defaultConfigs`. Plain data only: a function runs with the axios
16
+ * config as `this` (`transformRequest` can rewrite `url` or `socketPath`), `auth` is re-applied after the cross-origin
17
+ * header strip, and `baseURL` makes axios combine urls, so none of them is listed. A caller sets `Authorization` through
18
+ * `headers`, transforms the body before the call and the answer after it.
19
+ */
20
+ const GUARDED_OPTIONS = new Set([
21
+ 'withCredentials',
22
+ 'responseType',
23
+ 'responseEncoding',
24
+ 'xsrfCookieName',
25
+ 'xsrfHeaderName',
26
+ 'withXSRFToken',
27
+ 'maxContentLength',
28
+ 'maxBodyLength',
29
+ 'maxRate',
30
+ 'decompress',
31
+ 'transitional',
32
+ 'rejectUnauthorized',
33
+ ]);
34
+ /** A `lookup` for `net`/`tls` that answers the vetted addresses and nothing else: the client never resolves the name. */
35
+ const pinnedLookup = (addresses) => {
36
+ const answers = addresses.map((address) => ({ address, family: isIP(address) === 6 ? 6 : 4 }));
37
+ return (_hostname, options, callback) => {
38
+ const wantsAll = typeof options === 'object' && options !== null && Reflect.get(options, 'all') === true;
39
+ if (wantsAll) {
40
+ callback(null, answers);
41
+ return;
42
+ }
43
+ const [first] = answers;
44
+ callback(null, first.address, first.family);
45
+ };
46
+ };
47
+ /** Fetcher over an axios instance (`getWorker()`): the pipeline of `AbstractNetworkFetchableHelper` with axios as the client. HTTPS calls share one keep-alive agent that verifies certificates unless `rejectUnauthorized` is `false`; an `httpsAgent` passed in the request wins - and is refused together with a `guard`, because an agent of the caller's could connect elsewhere than the vetted address. */
9
48
  export class AxiosFetcher extends AbstractNetworkFetchableHelper {
10
49
  constructor(opts) {
11
- super({ name: opts.name, variant: 'axios' });
12
- const { defaultConfigs } = opts;
50
+ super({
51
+ name: opts.name,
52
+ variant: 'axios',
53
+ defaults: opts.defaults,
54
+ hooks: opts.hooks,
55
+ guardEngine: opts.guardEngine,
56
+ });
13
57
  opts?.logger?.info('Creating new network request worker instance! Name: %s', this.name);
58
+ this.isRejectingUnauthorized = opts.rejectUnauthorized ?? true;
14
59
  this.httpsAgent = new https.Agent({
15
60
  keepAlive: true,
16
- rejectUnauthorized: opts.rejectUnauthorized ?? true,
61
+ rejectUnauthorized: this.isRejectingUnauthorized,
17
62
  });
18
- this.worker = axios.create({ ...defaultConfigs });
63
+ this.configured = { ...opts.defaultConfigs };
64
+ this.worker = axios.create({ ...opts.defaultConfigs });
65
+ }
66
+ assertCallSupported(opts) {
67
+ const { guard, extra } = opts;
68
+ if (guard === undefined) {
69
+ return;
70
+ }
71
+ if (guard.proxy !== undefined) {
72
+ throw getError({
73
+ message: `[${this.name}] A guarded call cannot use guard.proxy with axios | the request would go direct and unpinned; use a NativeFetcher for a proxied call`,
74
+ });
75
+ }
76
+ const source = { ...this.configured, ...extra };
77
+ const found = Object.keys(source).filter((name) => source[name] !== undefined &&
78
+ (!GUARDED_OPTIONS.has(name) || typeof source[name] === 'function'));
79
+ if (found.includes('baseURL') || found.includes('allowAbsoluteUrls')) {
80
+ throw getError({
81
+ message: `[${this.name}] A guarded call needs one absolute url | use an AxiosFetcher without baseUrl, or a NativeFetcher (found: ${found.join(', ')})`,
82
+ });
83
+ }
84
+ if (found.length > 0) {
85
+ throw getError({
86
+ message: `[${this.name}] A guarded call cannot set ${found.join(', ')} | only ${[...GUARDED_OPTIONS].join(', ')} are accepted with a guard: any other option could connect to an address the guard did not vet`,
87
+ });
88
+ }
89
+ if (source.rejectUnauthorized === false || !this.isRejectingUnauthorized) {
90
+ throw getError({
91
+ message: `[${this.name}] A guarded call cannot turn TLS verification off | rejectUnauthorized: false has no use on an untrusted url`,
92
+ });
93
+ }
94
+ if (source.responseType === 'stream') {
95
+ throw getError({
96
+ message: `[${this.name}] A guarded call cannot ask for a stream with axios | the pinned agent is gone when the call returns and a stream is not capped; use a NativeFetcher to stream`,
97
+ });
98
+ }
19
99
  }
20
- send(opts, logger) {
21
- const { url, method = HTTP.Methods.GET, params = {}, body: data, headers, ...rest } = opts;
100
+ buildUrl(opts) {
101
+ const { url, params } = opts;
102
+ const query = params ? QueryStringUtility.toQueryString({ params }) : '';
103
+ return query ? `${url}${url.includes('?') ? '&' : '?'}${query}` : url;
104
+ }
105
+ /** An axios body-size overflow is the cap's refusal (permanent), not a transport error the retry would repeat. */
106
+ refineError(opts) {
107
+ const { error, url } = opts;
108
+ if (axios.isAxiosError(error) && /maxContentLength/.test(error.message)) {
109
+ return BodyLimit.refuse({ detail: `${error.message} | url: ${url}` });
110
+ }
111
+ return error;
112
+ }
113
+ async exchange(opts) {
114
+ const { method, url, headers, body, signal, addresses, proxy, isManualRedirect, maxBytes, extra, } = opts;
115
+ const { rejectUnauthorized, httpAgent, httpsAgent, ...axiosExtra } = extra;
22
116
  const props = {
23
- url,
24
- method: method.toUpperCase(),
25
- params,
26
- data,
27
- headers,
28
- paramsSerializer: { serialize: (p) => stringify(p) },
29
- ...rest,
117
+ ...axiosExtra,
118
+ url: url.toString(),
119
+ method,
120
+ data: body,
121
+ headers: Object.fromEntries(headers),
122
+ signal,
123
+ // The pipeline owns the status check, the redirects and the deadline; axios only carries the bytes.
124
+ validateStatus: () => true,
125
+ ...(isManualRedirect ? { maxRedirects: 0 } : {}),
126
+ ...(maxBytes === undefined ? {} : { maxContentLength: maxBytes }),
30
127
  };
31
- const protocol = this.getProtocol(url);
32
- if (protocol === HTTP.Protocols.HTTPS) {
33
- // A caller's own agent WINS. The previous code assigned after the `...rest` spread, so a
34
- // hardened agent - custom CA, pinning, mTLS - was overwritten and the secure path was
35
- // unreachable through the public seam.
128
+ const isPinned = addresses.length > 0 && !proxy;
129
+ const protocol = this.getProtocol(url.toString());
130
+ const isUnauthorizedAllowed = rejectUnauthorized === false;
131
+ if (isPinned) {
132
+ // The agent of THIS exchange: it answers the vetted addresses, keeps nothing alive, and is destroyed with the answer.
133
+ const lookup = pinnedLookup(addresses);
134
+ props.proxy = false;
135
+ props.httpAgent = new http.Agent({ keepAlive: false, lookup });
136
+ props.httpsAgent = new https.Agent({
137
+ keepAlive: false,
138
+ lookup,
139
+ rejectUnauthorized: !isUnauthorizedAllowed && this.isRejectingUnauthorized,
140
+ });
141
+ }
142
+ else if (protocol === HTTP.Protocols.HTTPS) {
143
+ // A caller's own agent WINS. The previous code assigned after the `...rest` spread, so a hardened agent - custom CA, pinning, mTLS - was overwritten and the secure path was unreachable through the public seam.
36
144
  props.httpsAgent =
37
- rest.httpsAgent ??
38
- (opts.rejectUnauthorized === undefined
145
+ httpsAgent instanceof https.Agent
146
+ ? httpsAgent
147
+ : rejectUnauthorized === undefined
39
148
  ? this.httpsAgent
40
- : new https.Agent({ keepAlive: true, rejectUnauthorized: opts.rejectUnauthorized }));
149
+ : new https.Agent({
150
+ keepAlive: true,
151
+ rejectUnauthorized: rejectUnauthorized !== false,
152
+ });
153
+ }
154
+ else if (httpAgent instanceof http.Agent) {
155
+ props.httpAgent = httpAgent;
156
+ }
157
+ try {
158
+ let response;
159
+ try {
160
+ const result = await this.worker.request(props);
161
+ response = result;
162
+ }
163
+ catch (error) {
164
+ throw this.refineError({ error, url: url.toString() });
165
+ }
166
+ return {
167
+ response,
168
+ status: response.status,
169
+ statusText: response.statusText,
170
+ headers: new Headers(Object.entries(response.headers).map(([name, value]) => [name, String(value)])),
171
+ // axios has read the body already: nothing is left to free.
172
+ discard: async () => undefined,
173
+ // axios has read the body already: the answer is as it came.
174
+ keepBody: async () => response,
175
+ readJson: async () => response.data,
176
+ // `maxContentLength` stopped an oversized body while it was read; the answer is as it came.
177
+ capped: () => response,
178
+ };
179
+ }
180
+ finally {
181
+ if (isPinned) {
182
+ props.httpAgent?.destroy();
183
+ props.httpsAgent?.destroy();
184
+ }
41
185
  }
42
- logger
43
- ?.for(this.send.name)
44
- .info('URL: %s | Props: %s', url, RedactUtility.redactSecrets({ value: props }));
45
- return this.worker.request(props);
46
186
  }
47
187
  }
48
- /** `BaseNetworkRequest` over an `AxiosFetcher`. Defaults: JSON content type, 60000 ms `timeout`, and no rejection for status below 500 (`validateStatus`). */
188
+ /** `BaseNetworkRequest` over an `AxiosFetcher`. Defaults: JSON content type and a 60000 ms `timeout`; a status outside 2xx throws a `UrlFetchError`. */
49
189
  export class AxiosNetworkRequest extends BaseNetworkRequest {
50
190
  constructor(opts) {
51
191
  const { name, networkOptions } = opts;
52
192
  const { headers, baseUrl, timeout, ...rest } = networkOptions;
53
- const mergedHeaders = {
54
- ['content-type']: 'application/json; charset=utf-8',
55
- ...headers,
56
- };
57
193
  const defaultConfigs = {
58
194
  withCredentials: true,
59
- validateStatus: (status) => status < 500,
60
- timeout: timeout ?? 60 * 1000,
61
195
  ...rest,
62
196
  baseURL: baseUrl,
63
- headers: mergedHeaders,
64
197
  };
65
198
  super({
66
199
  name,
67
200
  baseUrl,
68
- fetcher: new AxiosFetcher({ name, defaultConfigs }),
201
+ fetcher: new AxiosFetcher({
202
+ name,
203
+ defaultConfigs,
204
+ defaults: {
205
+ timeout: timeout ?? 60 * 1000,
206
+ ...opts.defaults,
207
+ headers: FetchHeaders.withJsonDefault({ layers: [headers, opts.defaults?.headers] }),
208
+ },
209
+ hooks: opts.hooks,
210
+ guardEngine: opts.guardEngine,
211
+ }),
69
212
  });
70
213
  }
71
214
  }
@@ -1 +1 @@
1
- {"version":3,"file":"axios-fetcher.js","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/fetcher/axios-fetcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAoB,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAA0E,MAAM,OAAO,CAAC;AAC/F,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAAE,8BAA8B,EAAwB,MAAM,gBAAgB,CAAC;AAatF,4MAA4M;AAC5M,MAAM,OAAO,YAAa,SAAQ,8BAOjC;IASC,YAAY,IAUX;QACC,KAAK,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC7C,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;QAChC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,wDAAwD,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAExF,IAAI,CAAC,UAAU,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC;YAChC,SAAS,EAAE,IAAI;YACf,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,IAAI,IAAI;SACpD,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM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,KAAK,CAAC,CAAC;IACvC,CAAC;CACF;AAUD,8JAA8J;AAC9J,MAAM,OAAO,mBAAoB,SAAQ,kBAA2B;IAClE,YAAY,IAAiC;QAC3C,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;QACtC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,cAAc,CAAC;QAE9D,MAAM,aAAa,GAA+C;YAChE,CAAC,cAAc,CAAC,EAAE,iCAAiC;YACnD,GAAG,OAAO;SACX,CAAC;QAEF,MAAM,cAAc,GAAuB;YACzC,eAAe,EAAE,IAAI;YACrB,cAAc,EAAE,CAAC,MAAc,EAAE,EAAE,CAAC,MAAM,GAAG,GAAG;YAChD,OAAO,EAAE,OAAO,IAAI,EAAE,GAAG,IAAI;YAC7B,GAAG,IAAI;YACP,OAAO,EAAE,OAAO;YAChB,OAAO,EAAE,aAAa;SACvB,CAAC;QAEF,KAAK,CAAC;YACJ,IAAI;YACJ,OAAO;YACP,OAAO,EAAE,IAAI,YAAY,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;SACpD,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { HTTP, type THttpMethod } from '@/common';\nimport { RedactUtility } from '@/common/redact';\nimport axios, { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from 'axios';\nimport https from 'node:https';\nimport { stringify } from 'node:querystring';\nimport { BaseNetworkRequest } from '../base-network-request.helper';\nimport type { ILogger } from '@/modules/logger/common/types';\nimport { AbstractNetworkFetchableHelper, type IRequestOptions } from './base-fetcher';\n\n/** Request accepted by `AxiosFetcher`: an axios config where `body` is sent as the axios `data`. `rejectUnauthorized` set here overrides the instance setting for this call. */\nexport interface IAxiosRequestOptions extends AxiosRequestConfig, IRequestOptions {\n url: string;\n method?: THttpMethod;\n params?: Record<string, unknown>;\n body?: Record<string, unknown>;\n headers?: Record<string, string>;\n /** Whether this call rejects an HTTPS server whose certificate fails verification; `false` turns verification off for this call. */\n rejectUnauthorized?: boolean;\n}\n\n/** Fetcher over an axios instance (`getWorker()`). HTTPS calls share one keep-alive agent that verifies certificates unless `rejectUnauthorized` is `false`; an `httpsAgent` passed in the request wins. */\nexport class AxiosFetcher extends AbstractNetworkFetchableHelper<\n 'axios',\n IAxiosRequestOptions,\n // The named type, not the `axios.` NAMESPACE: the namespace form resolves only under node16\n // module resolution, and this package also emits an ESM build under `bundler` resolution.\n AxiosResponse<unknown>,\n AxiosInstance\n> {\n /**\n * One agent for the instance, not one per request. Built here so TLS verification is decided\n * ONCE, at construction, rather than per call - and so connections are actually reused: a fresh\n * agent per request forces a new TCP and TLS handshake every time (measured: 10 handshakes for 10\n * requests, versus 1).\n */\n private readonly httpsAgent: https.Agent;\n\n constructor(opts: {\n name: string;\n defaultConfigs: AxiosRequestConfig;\n logger?: ILogger;\n /**\n * Whether this instance rejects an HTTPS server whose certificate fails verification.\n * `false` turns verification off.\n * @default true\n */\n rejectUnauthorized?: boolean;\n }) {\n super({ name: opts.name, variant: 'axios' });\n const { defaultConfigs } = opts;\n opts?.logger?.info('Creating new network request worker instance! Name: %s', this.name);\n\n this.httpsAgent = new https.Agent({\n keepAlive: true,\n rejectUnauthorized: opts.rejectUnauthorized ?? true,\n });\n\n this.worker = axios.create({ ...defaultConfigs });\n }\n\n override send<T = unknown>(opts: IAxiosRequestOptions, logger?: ILogger) {\n const { url, method = HTTP.Methods.GET, params = {}, body: data, headers, ...rest } = opts;\n const props: AxiosRequestConfig = {\n url,\n method: method.toUpperCase(),\n params,\n data,\n headers,\n paramsSerializer: { serialize: (p) => stringify(p) },\n ...rest,\n };\n\n const protocol = this.getProtocol(url);\n\n if (protocol === HTTP.Protocols.HTTPS) {\n // A caller's own agent WINS. The previous code assigned after the `...rest` spread, so a\n // hardened agent - custom CA, pinning, mTLS - was overwritten and the secure path was\n // unreachable through the public seam.\n props.httpsAgent =\n rest.httpsAgent ??\n (opts.rejectUnauthorized === undefined\n ? this.httpsAgent\n : new https.Agent({ keepAlive: true, rejectUnauthorized: opts.rejectUnauthorized }));\n }\n\n logger\n ?.for(this.send.name)\n .info('URL: %s | Props: %s', url, RedactUtility.redactSecrets({ value: props }));\n\n return this.worker.request<T>(props);\n }\n}\n\n/** Options of `AxiosNetworkRequest`: an axios config with `baseUrl` in place of `baseURL`. */\nexport interface IAxiosNetworkRequestOptions {\n name: string;\n networkOptions: Omit<AxiosRequestConfig, 'baseURL'> & {\n baseUrl?: string;\n };\n}\n\n/** `BaseNetworkRequest` over an `AxiosFetcher`. Defaults: JSON content type, 60000 ms `timeout`, and no rejection for status below 500 (`validateStatus`). */\nexport class AxiosNetworkRequest extends BaseNetworkRequest<'axios'> {\n constructor(opts: IAxiosNetworkRequestOptions) {\n const { name, networkOptions } = opts;\n const { headers, baseUrl, timeout, ...rest } = networkOptions;\n\n const mergedHeaders: NonNullable<AxiosRequestConfig['headers']> = {\n ['content-type']: 'application/json; charset=utf-8',\n ...headers,\n };\n\n const defaultConfigs: AxiosRequestConfig = {\n withCredentials: true,\n validateStatus: (status: number) => status < 500,\n timeout: timeout ?? 60 * 1000,\n ...rest,\n baseURL: baseUrl,\n headers: mergedHeaders,\n };\n\n super({\n name,\n baseUrl,\n fetcher: new AxiosFetcher({ name, defaultConfigs }),\n });\n }\n}\n"]}
1
+ {"version":3,"file":"axios-fetcher.js","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/fetcher/axios-fetcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,KAA0E,MAAM,OAAO,CAAC;AAC/F,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,C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AwJ;AACxJ,MAAM,OAAO,mBAAoB,SAAQ,kBAA2B;IAClE,YAAY,IAAiC;QAC3C,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;QACtC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,cAAc,CAAC;QAE9D,MAAM,cAAc,GAAuB;YACzC,eAAe,EAAE,IAAI;YACrB,GAAG,IAAI;YACP,OAAO,EAAE,OAAO;SACjB,CAAC;QAEF,KAAK,CAAC;YACJ,IAAI;YACJ,OAAO;YACP,OAAO,EAAE,IAAI,YAAY,CAAC;gBACxB,IAAI;gBACJ,cAAc;gBACd,QAAQ,EAAE;oBACR,OAAO,EAAE,OAAO,IAAI,EAAE,GAAG,IAAI;oBAC7B,GAAG,IAAI,CAAC,QAAQ;oBAChB,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC;iBACrF;gBACD,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,WAAW,EAAE,IAAI,CAAC,WAAW;aAC9B,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { HTTP } from '@/common';\nimport axios, { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from 'axios';\nimport http from 'node:http';\nimport https from 'node:https';\nimport { isIP } from 'node:net';\nimport { QueryStringUtility } from '../../utilities/query-string';\nimport { getError } from '@/modules/error';\nimport type { IUrlSafetyPolicy } from '@/modules/network/utilities/url-safety/common/types';\nimport { BaseNetworkRequest } from '../base-network-request.helper';\nimport type { ILogger } from '@/modules/logger/common/types';\nimport {\n AbstractNetworkFetchableHelper,\n type IFetchExchange,\n type IFetchExchangeRequest,\n type IRequestOptions,\n} from './base-fetcher';\nimport type { IFetchGuard } from './common/guard';\nimport type { IFetcherDefaults, IFetcherHooks } from './common/types';\nimport { BodyLimit } from './common/body-limit';\nimport { FetchHeaders } from './common/utilities';\n\n/**\n * The request options a guarded call accepts, besides the ones the pipeline owns. An allowlist, not a denylist: axios keeps\n * adding transport knobs (`httpVersion`, `http2Options`, ...) that connect on their own and ignore the pinned agent, so\n * anything not listed here is refused, per call and in `defaultConfigs`. Plain data only: a function runs with the axios\n * config as `this` (`transformRequest` can rewrite `url` or `socketPath`), `auth` is re-applied after the cross-origin\n * header strip, and `baseURL` makes axios combine urls, so none of them is listed. A caller sets `Authorization` through\n * `headers`, transforms the body before the call and the answer after it.\n */\nconst GUARDED_OPTIONS = new Set([\n 'withCredentials',\n 'responseType',\n 'responseEncoding',\n 'xsrfCookieName',\n 'xsrfHeaderName',\n 'withXSRFToken',\n 'maxContentLength',\n 'maxBodyLength',\n 'maxRate',\n 'decompress',\n 'transitional',\n 'rejectUnauthorized',\n]);\n\n/** The fields of an axios config the pipeline owns. */\ntype TOwnedAxiosFields =\n | 'url'\n | 'method'\n | 'params'\n | 'data'\n | 'headers'\n | 'signal'\n | 'timeout'\n | 'maxRedirects'\n | 'validateStatus';\n\n/** Request accepted by `AxiosFetcher`: an axios config where `body` is sent as the axios `data`. `rejectUnauthorized` set here overrides the instance setting for this call. */\nexport interface IAxiosRequestOptions\n extends Omit<AxiosRequestConfig, TOwnedAxiosFields>, IRequestOptions {\n url: string;\n params?: Record<string, unknown>;\n body?: Record<string, unknown>;\n /** Whether this call rejects an HTTPS server whose certificate fails verification; `false` turns verification off for this call. */\n rejectUnauthorized?: boolean;\n}\n\n/** A `lookup` for `net`/`tls` that answers the vetted addresses and nothing else: the client never resolves the name. */\nconst pinnedLookup = (addresses: string[]) => {\n const answers = addresses.map((address) => ({ address, family: isIP(address) === 6 ? 6 : 4 }));\n\n return (\n _hostname: string,\n options: unknown,\n callback: (\n error: Error | null,\n address: string | Array<{ address: string; family: number }>,\n family?: number,\n ) => void,\n ) => {\n const wantsAll =\n typeof options === 'object' && options !== null && Reflect.get(options, 'all') === true;\n\n if (wantsAll) {\n callback(null, answers);\n\n return;\n }\n\n const [first] = answers;\n callback(null, first.address, first.family);\n };\n};\n\n/** Fetcher over an axios instance (`getWorker()`): the pipeline of `AbstractNetworkFetchableHelper` with axios as the client. HTTPS calls share one keep-alive agent that verifies certificates unless `rejectUnauthorized` is `false`; an `httpsAgent` passed in the request wins - and is refused together with a `guard`, because an agent of the caller's could connect elsewhere than the vetted address. */\nexport class AxiosFetcher extends AbstractNetworkFetchableHelper<\n 'axios',\n IAxiosRequestOptions,\n // The named type, not the `axios.` NAMESPACE: the namespace form resolves only under node16\n // module resolution, and this package also emits an ESM build under `bundler` resolution.\n AxiosResponse<unknown>,\n AxiosInstance\n> {\n /**\n * One agent for the instance, not one per request. Built here so TLS verification is decided\n * ONCE, at construction, rather than per call - and so connections are actually reused: a fresh\n * agent per request forces a new TCP and TLS handshake every time (measured: 10 handshakes for 10\n * requests, versus 1). A guarded call never uses it: it gets an agent of its own that answers one vetted address and is dropped with the call, so no pin outlives it.\n */\n private readonly httpsAgent: https.Agent;\n private readonly isRejectingUnauthorized: boolean;\n /** What the caller put in `defaultConfigs`: a guarded call checks it like its own options. */\n private readonly configured: Record<string, unknown>;\n\n constructor(opts: {\n name: string;\n defaultConfigs?: AxiosRequestConfig;\n defaults?: IFetcherDefaults;\n hooks?: IFetcherHooks;\n /** The server half of the url guard (`UrlGuard`); a call that passes `guard` needs it. */\n guardEngine?: IFetchGuard;\n logger?: ILogger;\n /**\n * Whether this instance rejects an HTTPS server whose certificate fails verification.\n * `false` turns verification off.\n * @default true\n */\n rejectUnauthorized?: boolean;\n }) {\n super({\n name: opts.name,\n variant: 'axios',\n defaults: opts.defaults,\n hooks: opts.hooks,\n guardEngine: opts.guardEngine,\n });\n opts?.logger?.info('Creating new network request worker instance! Name: %s', this.name);\n\n this.isRejectingUnauthorized = opts.rejectUnauthorized ?? true;\n this.httpsAgent = new https.Agent({\n keepAlive: true,\n rejectUnauthorized: this.isRejectingUnauthorized,\n });\n\n this.configured = { ...opts.defaultConfigs };\n this.worker = axios.create({ ...opts.defaultConfigs });\n }\n\n protected override assertCallSupported(opts: {\n guard?: IUrlSafetyPolicy;\n extra: Record<string | symbol, unknown>;\n }): void {\n const { guard, extra } = opts;\n\n if (guard === undefined) {\n return;\n }\n\n if (guard.proxy !== undefined) {\n throw getError({\n message: `[${this.name}] A guarded call cannot use guard.proxy with axios | the request would go direct and unpinned; use a NativeFetcher for a proxied call`,\n });\n }\n\n const source: Record<string, unknown> = { ...this.configured, ...extra };\n const found = Object.keys(source).filter(\n (name) =>\n source[name] !== undefined &&\n (!GUARDED_OPTIONS.has(name) || typeof source[name] === 'function'),\n );\n\n if (found.includes('baseURL') || found.includes('allowAbsoluteUrls')) {\n throw getError({\n message: `[${this.name}] A guarded call needs one absolute url | use an AxiosFetcher without baseUrl, or a NativeFetcher (found: ${found.join(', ')})`,\n });\n }\n\n if (found.length > 0) {\n throw getError({\n message: `[${this.name}] A guarded call cannot set ${found.join(', ')} | only ${[...GUARDED_OPTIONS].join(', ')} are accepted with a guard: any other option could connect to an address the guard did not vet`,\n });\n }\n\n if (source.rejectUnauthorized === false || !this.isRejectingUnauthorized) {\n throw getError({\n message: `[${this.name}] A guarded call cannot turn TLS verification off | rejectUnauthorized: false has no use on an untrusted url`,\n });\n }\n\n if (source.responseType === 'stream') {\n throw getError({\n message: `[${this.name}] A guarded call cannot ask for a stream with axios | the pinned agent is gone when the call returns and a stream is not capped; use a NativeFetcher to stream`,\n });\n }\n }\n\n protected override buildUrl(opts: { url: string; params?: Record<string, unknown> }): string {\n const { url, params } = opts;\n const query = params ? QueryStringUtility.toQueryString({ params }) : '';\n\n return query ? `${url}${url.includes('?') ? '&' : '?'}${query}` : url;\n }\n\n /** An axios body-size overflow is the cap's refusal (permanent), not a transport error the retry would repeat. */\n private refineError(opts: { error: unknown; url: string }): unknown {\n const { error, url } = opts;\n\n if (axios.isAxiosError(error) && /maxContentLength/.test(error.message)) {\n return BodyLimit.refuse({ detail: `${error.message} | url: ${url}` });\n }\n\n return error;\n }\n\n protected override async exchange(\n opts: IFetchExchangeRequest,\n ): Promise<IFetchExchange<AxiosResponse<unknown>>> {\n const {\n method,\n url,\n headers,\n body,\n signal,\n addresses,\n proxy,\n isManualRedirect,\n maxBytes,\n extra,\n } = opts;\n const { rejectUnauthorized, httpAgent, httpsAgent, ...axiosExtra } = extra;\n const props: AxiosRequestConfig = {\n ...axiosExtra,\n url: url.toString(),\n method,\n data: body,\n headers: Object.fromEntries(headers),\n signal,\n // The pipeline owns the status check, the redirects and the deadline; axios only carries the bytes.\n validateStatus: () => true,\n ...(isManualRedirect ? { maxRedirects: 0 } : {}),\n ...(maxBytes === undefined ? {} : { maxContentLength: maxBytes }),\n };\n const isPinned = addresses.length > 0 && !proxy;\n const protocol = this.getProtocol(url.toString());\n const isUnauthorizedAllowed = rejectUnauthorized === false;\n\n if (isPinned) {\n // The agent of THIS exchange: it answers the vetted addresses, keeps nothing alive, and is destroyed with the answer.\n const lookup = pinnedLookup(addresses);\n\n props.proxy = false;\n props.httpAgent = new http.Agent({ keepAlive: false, lookup });\n props.httpsAgent = new https.Agent({\n keepAlive: false,\n lookup,\n rejectUnauthorized: !isUnauthorizedAllowed && this.isRejectingUnauthorized,\n });\n } else if (protocol === HTTP.Protocols.HTTPS) {\n // A caller's own agent WINS. The previous code assigned after the `...rest` spread, so a hardened agent - custom CA, pinning, mTLS - was overwritten and the secure path was unreachable through the public seam.\n props.httpsAgent =\n httpsAgent instanceof https.Agent\n ? httpsAgent\n : rejectUnauthorized === undefined\n ? this.httpsAgent\n : new https.Agent({\n keepAlive: true,\n rejectUnauthorized: rejectUnauthorized !== false,\n });\n } else if (httpAgent instanceof http.Agent) {\n props.httpAgent = httpAgent;\n }\n\n try {\n let response: AxiosResponse<unknown>;\n\n try {\n const result = await this.worker.request(props);\n response = result;\n } catch (error) {\n throw this.refineError({ error, url: url.toString() });\n }\n\n return {\n response,\n status: response.status,\n statusText: response.statusText,\n headers: new Headers(\n Object.entries(response.headers).map(([name, value]) => [name, String(value)]),\n ),\n // axios has read the body already: nothing is left to free.\n discard: async () => undefined,\n // axios has read the body already: the answer is as it came.\n keepBody: async () => response,\n readJson: async () => response.data,\n // `maxContentLength` stopped an oversized body while it was read; the answer is as it came.\n capped: () => response,\n };\n } finally {\n if (isPinned) {\n props.httpAgent?.destroy();\n props.httpsAgent?.destroy();\n }\n }\n }\n}\n\n/** Options of `AxiosNetworkRequest`: an axios config with `baseUrl` in place of `baseURL`. */\nexport interface IAxiosNetworkRequestOptions {\n name: string;\n networkOptions: Omit<AxiosRequestConfig, 'baseURL' | 'headers' | 'timeout'> & {\n baseUrl?: string;\n headers?: Record<string, string>;\n /** Per attempt, in milliseconds. @default 60000 */\n timeout?: number;\n };\n defaults?: IFetcherDefaults;\n hooks?: IFetcherHooks;\n guardEngine?: IFetchGuard;\n}\n\n/** `BaseNetworkRequest` over an `AxiosFetcher`. Defaults: JSON content type and a 60000 ms `timeout`; a status outside 2xx throws a `UrlFetchError`. */\nexport class AxiosNetworkRequest extends BaseNetworkRequest<'axios'> {\n constructor(opts: IAxiosNetworkRequestOptions) {\n const { name, networkOptions } = opts;\n const { headers, baseUrl, timeout, ...rest } = networkOptions;\n\n const defaultConfigs: AxiosRequestConfig = {\n withCredentials: true,\n ...rest,\n baseURL: baseUrl,\n };\n\n super({\n name,\n baseUrl,\n fetcher: new AxiosFetcher({\n name,\n defaultConfigs,\n defaults: {\n timeout: timeout ?? 60 * 1000,\n ...opts.defaults,\n headers: FetchHeaders.withJsonDefault({ layers: [headers, opts.defaults?.headers] }),\n },\n hooks: opts.hooks,\n guardEngine: opts.guardEngine,\n }),\n });\n }\n}\n"]}
@@ -1,47 +1,233 @@
1
1
  import { type THttpMethod } from '../../../../common/constants/http.js';
2
2
  import type { ILogger } from '../../../logger/common/types.js';
3
+ import type { IUrlSafetyPolicy } from '../../utilities/url-safety/common/types.js';
4
+ import type { z } from 'zod';
3
5
  import { type TFetcherVariant } from '../common/index.js';
6
+ import type { IFetchGuard } from './common/guard.js';
7
+ import type { IFetchParsed, IFetchRetryOptions, IFetcherDefaults, IFetcherHooks, TFetchHeaders } from './common/types.js';
4
8
  /** What a fetcher calls on the logger it is handed, so a host logger with only these two (a browser app's) is accepted as is. */
5
9
  export type TFetcherLogger = Pick<ILogger, 'debug' | 'info'>;
6
- /** Options every fetcher accepts. `timeout` is in milliseconds; other keys pass through to the underlying client. */
10
+ /** Options every fetcher accepts. `timeout` is in milliseconds and counts per attempt; other keys pass through to the underlying client. */
7
11
  export interface IRequestOptions {
8
12
  url: string;
9
- method?: THttpMethod;
13
+ method?: THttpMethod | (string & Record<never, never>);
10
14
  params?: Record<string, unknown>;
15
+ /** Merged over the fetcher's default headers, header by header; a `null` or `undefined` value removes a default. */
16
+ headers?: TFetchHeaders;
17
+ body?: unknown;
18
+ signal?: AbortSignal;
11
19
  timeout?: number;
20
+ /** Presence turns retrying on; replaces the fetcher's default retry whole. `{ maxAttempts: 1 }` stops it. */
21
+ retry?: IFetchRetryOptions;
22
+ /** Presence turns the url guard on (`{}` is the default policy). A fetcher default guard can be replaced here, never removed. */
23
+ guard?: IUrlSafetyPolicy;
24
+ /** The body is cut off, and the call fails, once it crosses this many bytes. */
25
+ maxBytes?: number;
26
+ /** Redirects followed by hand; `0` hands back the 3xx as a `UrlFetchError`. Unset: the client follows (a guard follows 3). */
27
+ maxRedirects?: number;
28
+ /**
29
+ * Which statuses are an answer; any other throws a `UrlFetchError`. A list ADDS to 2xx (`[HTTP.ResultCodes.RS_4.NotFound]`
30
+ * is 2xx or 404); a function decides alone. Unset, only 2xx.
31
+ */
32
+ acceptStatus?: ReadonlyArray<number> | ((status: number) => boolean);
33
+ /** The body is parsed with it, and the call answers `{ data, status, headers, response }`. */
34
+ schema?: z.ZodType;
12
35
  [extra: symbol | string]: unknown;
13
36
  }
14
- /** Contract of an HTTP fetcher: `send` takes the method from the options, the verb methods fix it, and `getWorker` returns the underlying client (`W`). */
37
+ /** The answer one exchange with the server gave, in the terms the pipeline needs, whichever client made it. */
38
+ export interface IFetchExchange<RS> {
39
+ response: RS;
40
+ status: number;
41
+ statusText: string;
42
+ headers: Headers;
43
+ /** Frees the socket of a body nobody will read (a redirect). */
44
+ discard(): Promise<void>;
45
+ /** The same answer with at most `maxBytes` of its body kept readable, the rest released: what a refused status hands back. */
46
+ keepBody(opts: {
47
+ maxBytes: number;
48
+ }): Promise<RS>;
49
+ /** The body as JSON; throws a `SyntaxError` when it is not. */
50
+ readJson(opts: {
51
+ maxBytes?: number;
52
+ }): Promise<unknown>;
53
+ /** The same answer with its body cut off at `maxBytes`. */
54
+ capped(opts: {
55
+ maxBytes: number;
56
+ }): RS;
57
+ }
58
+ /** One request to the network, after the hooks and the guard have had their say. */
59
+ export interface IFetchExchangeRequest {
60
+ method: string;
61
+ url: URL;
62
+ headers: Headers;
63
+ body: unknown;
64
+ signal?: AbortSignal;
65
+ /** The addresses the guard vetted: connect to these and no other. Empty: connect as the client would. */
66
+ addresses: string[];
67
+ /** The host name the certificate is verified for when the connection goes to an address; unset for a literal address or a plain http url. */
68
+ tlsServerName?: string;
69
+ /** A proxy the guard policy chose. */
70
+ proxy?: string;
71
+ /** Do not follow a redirect: the pipeline reads the 3xx and walks it. */
72
+ isManualRedirect: boolean;
73
+ maxBytes?: number;
74
+ /** What the call carried that is the client's own (`credentials`, `httpsAgent`, ...). */
75
+ extra: Record<string | symbol, unknown>;
76
+ }
77
+ /** Contract of an HTTP fetcher: `send` takes the method from the options, the verb methods fix it, and `getWorker` returns the underlying client (`W`). Without a `schema` a call answers the raw response `RS`; with one, `IFetchParsed`. */
15
78
  export interface IFetchable<V extends TFetcherVariant, RQ extends IRequestOptions, RS, W = unknown> {
16
- send(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
17
- get(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
18
- post(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
19
- put(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
20
- patch(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
21
- delete(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
22
- query(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
79
+ send(opts: RQ & {
80
+ schema?: undefined;
81
+ }, logger?: TFetcherLogger): Promise<RS>;
82
+ send<S extends z.ZodType>(opts: RQ & {
83
+ schema: S;
84
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
85
+ get(opts: RQ & {
86
+ schema?: undefined;
87
+ }, logger?: TFetcherLogger): Promise<RS>;
88
+ get<S extends z.ZodType>(opts: RQ & {
89
+ schema: S;
90
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
91
+ post(opts: RQ & {
92
+ schema?: undefined;
93
+ }, logger?: TFetcherLogger): Promise<RS>;
94
+ post<S extends z.ZodType>(opts: RQ & {
95
+ schema: S;
96
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
97
+ put(opts: RQ & {
98
+ schema?: undefined;
99
+ }, logger?: TFetcherLogger): Promise<RS>;
100
+ put<S extends z.ZodType>(opts: RQ & {
101
+ schema: S;
102
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
103
+ patch(opts: RQ & {
104
+ schema?: undefined;
105
+ }, logger?: TFetcherLogger): Promise<RS>;
106
+ patch<S extends z.ZodType>(opts: RQ & {
107
+ schema: S;
108
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
109
+ delete(opts: RQ & {
110
+ schema?: undefined;
111
+ }, logger?: TFetcherLogger): Promise<RS>;
112
+ delete<S extends z.ZodType>(opts: RQ & {
113
+ schema: S;
114
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
115
+ query(opts: RQ & {
116
+ schema?: undefined;
117
+ }, logger?: TFetcherLogger): Promise<RS>;
118
+ query<S extends z.ZodType>(opts: RQ & {
119
+ schema: S;
120
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
23
121
  getVariant(): V;
24
122
  getWorker(): W;
25
123
  }
26
- /** `W` defaults to `unknown` so this stays free of `axios` - a concrete fetcher binds it to its real worker type (`AxiosInstance`, `typeof fetch`), which is then inherited on `this.worker` with no override needed. */
124
+ /** What one call settled to, before the verb overloads give it their types. */
125
+ type TFetchSettled<RS> = RS | IFetchParsed<unknown, RS>;
126
+ /**
127
+ * The pipeline every fetcher shares: defaults, hooks, the url guard, redirects, the status check, the body cap, the
128
+ * schema, retries. A concrete fetcher supplies the exchange with one client (`exchange`) and the shape of its urls and
129
+ * bodies; `W` defaults to `unknown` so this stays free of `axios`.
130
+ */
27
131
  export declare abstract class AbstractNetworkFetchableHelper<V extends TFetcherVariant, RQ extends IRequestOptions, RS, W = unknown> implements IFetchable<V, RQ, RS, W> {
28
132
  protected name: string;
29
133
  protected variant: V;
30
134
  protected worker: W;
135
+ protected defaults: IFetcherDefaults;
136
+ protected hooks: IFetcherHooks;
137
+ protected guardEngine?: IFetchGuard;
31
138
  constructor(opts: {
32
139
  name: string;
33
140
  variant: V;
34
141
  worker?: W;
142
+ defaults?: IFetcherDefaults;
143
+ hooks?: IFetcherHooks;
144
+ /** The server half of the url guard (`UrlGuard`); a call that passes `guard` needs it. */
145
+ guardEngine?: IFetchGuard;
35
146
  });
36
- abstract send(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
147
+ /** One exchange with the server: the request as the pipeline decided it, the answer in the pipeline's terms. */
148
+ protected abstract exchange(opts: IFetchExchangeRequest, logger?: TFetcherLogger): Promise<IFetchExchange<RS>>;
149
+ /** The url of a call with its `params` written into the query string. */
150
+ protected abstract buildUrl(opts: {
151
+ url: string;
152
+ params?: Record<string, unknown>;
153
+ }): string;
154
+ /** Whether `body` can be sent again to a redirect target. */
155
+ protected isReplayable(opts: {
156
+ body: unknown;
157
+ }): boolean;
158
+ /** What the request log says about a body: its size or its presence, never its content. */
159
+ protected describeBody(opts: {
160
+ body: unknown;
161
+ }): string | undefined;
162
+ /** Refuses a call the client cannot honour; `AxiosFetcher` refuses a guard it cannot pin. */
163
+ protected assertCallSupported(_opts: {
164
+ guard?: IUrlSafetyPolicy;
165
+ extra: Record<string | symbol, unknown>;
166
+ }): void;
167
+ /** What each attempt needs to know of the call. */
168
+ private resolveCall;
169
+ /** `AbortSignal` of one attempt: the caller's own, and the attempt's deadline. */
170
+ private attemptSignal;
171
+ /** The body of a refused status or a mismatch is gone; the typed error carries what is left of the answer. */
172
+ private refuseStatus;
173
+ /** The guard's verdict on one hop: the url to send and the addresses to pin; with no guard, the target as it is. */
174
+ private vetTarget;
175
+ /** One attempt: hook, guard, exchange (redirects walked by hand when asked), status, cap, schema. */
176
+ private runAttempt;
177
+ /** The cap and the schema, once the status is accepted. */
178
+ private finish;
179
+ private parseUrl;
180
+ /** The absolute target of a redirect; a `Location` that is not a url is a typed error, never a bare `TypeError`. */
181
+ private resolveLocation;
182
+ /** The whole call: retries around the attempts, and the one `onError` for the failure that ends it. */
183
+ protected perform(opts: RQ & {
184
+ schema?: z.ZodType;
185
+ }, logger?: TFetcherLogger): Promise<TFetchSettled<RS>>;
37
186
  getProtocol(url: string): "http" | "https";
38
187
  getVariant(): V;
39
188
  getWorker(): W;
40
- get(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
41
- post(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
42
- put(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
43
- patch(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
44
- delete(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
45
- query(opts: RQ, logger?: TFetcherLogger): Promise<RS>;
189
+ send(opts: RQ & {
190
+ schema?: undefined;
191
+ }, logger?: TFetcherLogger): Promise<RS>;
192
+ send<S extends z.ZodType>(opts: RQ & {
193
+ schema: S;
194
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
195
+ get(opts: RQ & {
196
+ schema?: undefined;
197
+ }, logger?: TFetcherLogger): Promise<RS>;
198
+ get<S extends z.ZodType>(opts: RQ & {
199
+ schema: S;
200
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
201
+ post(opts: RQ & {
202
+ schema?: undefined;
203
+ }, logger?: TFetcherLogger): Promise<RS>;
204
+ post<S extends z.ZodType>(opts: RQ & {
205
+ schema: S;
206
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
207
+ put(opts: RQ & {
208
+ schema?: undefined;
209
+ }, logger?: TFetcherLogger): Promise<RS>;
210
+ put<S extends z.ZodType>(opts: RQ & {
211
+ schema: S;
212
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
213
+ patch(opts: RQ & {
214
+ schema?: undefined;
215
+ }, logger?: TFetcherLogger): Promise<RS>;
216
+ patch<S extends z.ZodType>(opts: RQ & {
217
+ schema: S;
218
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
219
+ delete(opts: RQ & {
220
+ schema?: undefined;
221
+ }, logger?: TFetcherLogger): Promise<RS>;
222
+ delete<S extends z.ZodType>(opts: RQ & {
223
+ schema: S;
224
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
225
+ query(opts: RQ & {
226
+ schema?: undefined;
227
+ }, logger?: TFetcherLogger): Promise<RS>;
228
+ query<S extends z.ZodType>(opts: RQ & {
229
+ schema: S;
230
+ }, logger?: TFetcherLogger): Promise<IFetchParsed<z.infer<S>, RS>>;
46
231
  }
232
+ export {};
47
233
  //# sourceMappingURL=base-fetcher.d.ts.map