@molecule/app-http-axios 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -14
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-
|
|
6
|
+
Generated: 2026-11-08T06:05:40.595Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-http-axios
|
|
@@ -128,54 +128,65 @@ interface HttpClient {
|
|
|
128
128
|
* Base URL for all requests.
|
|
129
129
|
*/
|
|
130
130
|
baseURL: string
|
|
131
|
+
|
|
131
132
|
/**
|
|
132
133
|
* Default headers for all requests.
|
|
133
134
|
*/
|
|
134
135
|
defaultHeaders: Record<string, string>
|
|
136
|
+
|
|
135
137
|
/**
|
|
136
138
|
* Makes a generic HTTP request. `data` is a field of THIS config object — the same body
|
|
137
139
|
* `post(url, data, config)` takes as its second argument.
|
|
138
140
|
*/
|
|
139
141
|
request<T = unknown>(config: FullRequestConfig): Promise<HttpResponse<T>>
|
|
142
|
+
|
|
140
143
|
/**
|
|
141
144
|
* Makes a GET request.
|
|
142
145
|
*/
|
|
143
146
|
get<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>
|
|
147
|
+
|
|
144
148
|
/**
|
|
145
149
|
* Makes a POST request. `data` is the request BODY, not a config object: the wire body is
|
|
146
150
|
* `data` itself, so `post(url, { data: body })` sends `{"data":body}` — pass `body` directly.
|
|
147
151
|
* A config (headers, params) is the THIRD argument.
|
|
148
152
|
*/
|
|
149
153
|
post<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
|
|
154
|
+
|
|
150
155
|
/**
|
|
151
156
|
* Makes a PUT request. `data` is the request BODY (second argument) — never `{ data: body }`,
|
|
152
157
|
* which sends `{"data":body}`; a config is the THIRD argument.
|
|
153
158
|
*/
|
|
154
159
|
put<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
|
|
160
|
+
|
|
155
161
|
/**
|
|
156
162
|
* Makes a PATCH request. `data` is the request BODY (second argument) — never `{ data: body }`,
|
|
157
163
|
* which sends `{"data":body}`; a config is the THIRD argument.
|
|
158
164
|
*/
|
|
159
165
|
patch<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
|
|
166
|
+
|
|
160
167
|
/**
|
|
161
168
|
* Makes a DELETE request.
|
|
162
169
|
*/
|
|
163
170
|
delete<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>
|
|
171
|
+
|
|
164
172
|
/**
|
|
165
173
|
* Adds a request interceptor.
|
|
166
174
|
* Returns a function to remove the interceptor.
|
|
167
175
|
*/
|
|
168
176
|
addRequestInterceptor(interceptor: RequestInterceptor): () => void
|
|
177
|
+
|
|
169
178
|
/**
|
|
170
179
|
* Adds a response interceptor.
|
|
171
180
|
* Returns a function to remove the interceptor.
|
|
172
181
|
*/
|
|
173
182
|
addResponseInterceptor(interceptor: ResponseInterceptor): () => void
|
|
183
|
+
|
|
174
184
|
/**
|
|
175
185
|
* Adds an error interceptor.
|
|
176
186
|
* Returns a function to remove the interceptor.
|
|
177
187
|
*/
|
|
178
188
|
addErrorInterceptor(interceptor: ErrorInterceptor): () => void
|
|
189
|
+
|
|
179
190
|
/**
|
|
180
191
|
* Sets the authorization token.
|
|
181
192
|
*
|
|
@@ -187,11 +198,13 @@ interface HttpClient {
|
|
|
187
198
|
* the resolver is removed, the static token is sent again.
|
|
188
199
|
*/
|
|
189
200
|
setAuthToken(token: string | null): void
|
|
201
|
+
|
|
190
202
|
/**
|
|
191
203
|
* Returns the token the client applies to its next request: the resolver's answer when one
|
|
192
204
|
* is registered, else the static token from `setAuthToken`.
|
|
193
205
|
*/
|
|
194
206
|
getAuthToken(): string | null
|
|
207
|
+
|
|
195
208
|
/**
|
|
196
209
|
* Registers the LIVE token resolver every request of this client reads, or clears it with
|
|
197
210
|
* `null`.
|
|
@@ -222,6 +235,7 @@ interface HttpClient {
|
|
|
222
235
|
* @param resolver - Returns the current access token (or null/undefined), or `null` to clear.
|
|
223
236
|
*/
|
|
224
237
|
setAuthTokenResolver?(resolver: AuthTokenResolver | null): void
|
|
238
|
+
|
|
225
239
|
/**
|
|
226
240
|
* Registers a handler for authentication errors (401).
|
|
227
241
|
*
|
|
@@ -244,18 +258,22 @@ interface HttpClientConfig {
|
|
|
244
258
|
* `//cdn…`) is requested as written.
|
|
245
259
|
*/
|
|
246
260
|
baseURL?: string
|
|
261
|
+
|
|
247
262
|
/**
|
|
248
263
|
* Default headers for all requests.
|
|
249
264
|
*/
|
|
250
265
|
defaultHeaders?: Record<string, string>
|
|
266
|
+
|
|
251
267
|
/**
|
|
252
268
|
* Default timeout in milliseconds.
|
|
253
269
|
*/
|
|
254
270
|
timeout?: number
|
|
271
|
+
|
|
255
272
|
/**
|
|
256
273
|
* Whether to include credentials by default.
|
|
257
274
|
*/
|
|
258
275
|
withCredentials?: boolean
|
|
276
|
+
|
|
259
277
|
/**
|
|
260
278
|
* The scheme of the `Authorization` header the auth token is sent with:
|
|
261
279
|
* `Bearer` (default), or what your API expects, e.g. `Token` for an API that
|
|
@@ -265,6 +283,7 @@ interface HttpClientConfig {
|
|
|
265
283
|
* it returns.
|
|
266
284
|
*/
|
|
267
285
|
authScheme?: string
|
|
286
|
+
|
|
268
287
|
/**
|
|
269
288
|
* Default retry policy for every request this client makes, or `false` to
|
|
270
289
|
* disable retries. A request's own `retry` overrides it.
|
|
@@ -283,18 +302,22 @@ interface RequestConfig {
|
|
|
283
302
|
* Request headers.
|
|
284
303
|
*/
|
|
285
304
|
headers?: Record<string, string>
|
|
305
|
+
|
|
286
306
|
/**
|
|
287
307
|
* Query parameters.
|
|
288
308
|
*/
|
|
289
309
|
params?: Record<string, string | number | boolean | undefined>
|
|
310
|
+
|
|
290
311
|
/**
|
|
291
312
|
* Request timeout in milliseconds.
|
|
292
313
|
*/
|
|
293
314
|
timeout?: number
|
|
315
|
+
|
|
294
316
|
/**
|
|
295
317
|
* Whether to include credentials (cookies).
|
|
296
318
|
*/
|
|
297
319
|
withCredentials?: boolean
|
|
320
|
+
|
|
298
321
|
/**
|
|
299
322
|
* Send this request WITHOUT waiting for the session restore (the auth gate).
|
|
300
323
|
*
|
|
@@ -319,14 +342,17 @@ interface RequestConfig {
|
|
|
319
342
|
* directly.
|
|
320
343
|
*/
|
|
321
344
|
skipAuthGate?: boolean
|
|
345
|
+
|
|
322
346
|
/**
|
|
323
347
|
* Response type.
|
|
324
348
|
*/
|
|
325
349
|
responseType?: 'json' | 'text' | 'blob' | 'arraybuffer'
|
|
350
|
+
|
|
326
351
|
/**
|
|
327
352
|
* Abort signal for cancellation.
|
|
328
353
|
*/
|
|
329
354
|
signal?: AbortSignal
|
|
355
|
+
|
|
330
356
|
/**
|
|
331
357
|
* Request body data, as a field of THIS config object — the `request({ method, url, data })`
|
|
332
358
|
* form. The verb methods take the body as their SECOND argument: `post(url, data, config)`,
|
|
@@ -335,10 +361,12 @@ interface RequestConfig {
|
|
|
335
361
|
* sees none of the fields at its top level.
|
|
336
362
|
*/
|
|
337
363
|
data?: unknown
|
|
364
|
+
|
|
338
365
|
/**
|
|
339
366
|
* Custom request options (implementation-specific).
|
|
340
367
|
*/
|
|
341
368
|
options?: Record<string, unknown>
|
|
369
|
+
|
|
342
370
|
/**
|
|
343
371
|
* Retry policy for this request, or `false` to disable retries.
|
|
344
372
|
*
|
|
@@ -362,10 +390,12 @@ interface FullRequestConfig extends RequestConfig {
|
|
|
362
390
|
* HTTP method.
|
|
363
391
|
*/
|
|
364
392
|
method: HttpMethod
|
|
393
|
+
|
|
365
394
|
/**
|
|
366
395
|
* Request URL (can be relative or absolute).
|
|
367
396
|
*/
|
|
368
397
|
url: string
|
|
398
|
+
|
|
369
399
|
/**
|
|
370
400
|
* Request body data — a field of this config object, never a second argument here.
|
|
371
401
|
*/
|
|
@@ -383,18 +413,22 @@ interface HttpResponse<T = unknown> {
|
|
|
383
413
|
* Response data.
|
|
384
414
|
*/
|
|
385
415
|
data: T
|
|
416
|
+
|
|
386
417
|
/**
|
|
387
418
|
* HTTP status code.
|
|
388
419
|
*/
|
|
389
420
|
status: number
|
|
421
|
+
|
|
390
422
|
/**
|
|
391
423
|
* HTTP status text.
|
|
392
424
|
*/
|
|
393
425
|
statusText: string
|
|
426
|
+
|
|
394
427
|
/**
|
|
395
428
|
* Response headers.
|
|
396
429
|
*/
|
|
397
430
|
headers: Record<string, string>
|
|
431
|
+
|
|
398
432
|
/**
|
|
399
433
|
* Original request config.
|
|
400
434
|
*/
|
|
@@ -464,6 +498,11 @@ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTION
|
|
|
464
498
|
|
|
465
499
|
HTTP error with response details.
|
|
466
500
|
|
|
501
|
+
`instanceof HttpError` also recognizes compatible failures carrying the shared
|
|
502
|
+
`Symbol.for('@molecule/app-http/HttpError')` brand, including non-ok auth responses
|
|
503
|
+
and errors from duplicated package copies. Branded producers must provide this
|
|
504
|
+
class's instance fields. Subclasses retain ordinary prototype-based checks.
|
|
505
|
+
|
|
467
506
|
Request metadata on `config` and `response.config` is limited to method, a
|
|
468
507
|
credential-redacted URL, and the two boolean notification-suppression controls
|
|
469
508
|
(`molSilentErrorNotification` and `molSilentRateLimitNotification`). Request bodies,
|
|
@@ -480,17 +519,29 @@ session. The correct check is {@link isAuthFailure} (`status === 401 || status =
|
|
|
480
519
|
`isNoResponse` (`status === 0`) identifies this case.
|
|
481
520
|
|
|
482
521
|
```typescript
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
522
|
+
class HttpError extends Error {
|
|
523
|
+
/**
|
|
524
|
+
* Recognizes the shared failed-request contract without widening subclass checks.
|
|
525
|
+
*
|
|
526
|
+
* @param value - Any value to test.
|
|
527
|
+
* @returns True for a prototype instance, or a compatible branded value checked against the base class.
|
|
528
|
+
*/
|
|
529
|
+
static [Symbol.hasInstance](value: unknown): boolean {
|
|
530
|
+
return (
|
|
531
|
+
Function.prototype[Symbol.hasInstance].call(this, value) ||
|
|
532
|
+
(this === HttpError &&
|
|
533
|
+
typeof value === 'object' &&
|
|
534
|
+
value !== null &&
|
|
535
|
+
(value as Record<symbol, unknown>)[HTTP_ERROR_BRAND] === true)
|
|
536
|
+
)
|
|
537
|
+
}
|
|
538
|
+
|
|
489
539
|
/**
|
|
490
540
|
* Redacts URL userinfo and credential query/fragment values while preserving the path and
|
|
491
541
|
* non-secret parameters. Shared by compatible HTTP and auth error/log views.
|
|
492
542
|
*/
|
|
493
|
-
static readonly redactUrlCredentials
|
|
543
|
+
static readonly redactUrlCredentials = redactUrlCredentials
|
|
544
|
+
|
|
494
545
|
/**
|
|
495
546
|
* Builds a failed-request error.
|
|
496
547
|
*
|
|
@@ -510,12 +561,18 @@ declare class HttpError extends Error {
|
|
|
510
561
|
*/
|
|
511
562
|
constructor(
|
|
512
563
|
message: string,
|
|
513
|
-
status: number,
|
|
514
|
-
response?: HttpResponse
|
|
515
|
-
config?: FullRequestConfig
|
|
516
|
-
errorKey?: string
|
|
517
|
-
aborted
|
|
518
|
-
)
|
|
564
|
+
public status: number,
|
|
565
|
+
public response?: HttpResponse,
|
|
566
|
+
public config?: FullRequestConfig,
|
|
567
|
+
public errorKey?: string,
|
|
568
|
+
public aborted = false,
|
|
569
|
+
) {
|
|
570
|
+
super(snapshotCredentials(message))
|
|
571
|
+
this.name = 'HttpError'
|
|
572
|
+
this.response = response ? errorResponse(response) : undefined
|
|
573
|
+
this.config = config ? errorRequestConfig(config) : undefined
|
|
574
|
+
Object.defineProperty(this, HTTP_ERROR_BRAND, { value: true })
|
|
575
|
+
}
|
|
519
576
|
}
|
|
520
577
|
```
|
|
521
578
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-http-axios",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "Axios HTTP client provider for @molecule/app-http",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"axios": "^1.6.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@molecule/app-logger": "1.0.
|
|
28
|
+
"@molecule/app-logger": "1.0.6",
|
|
29
29
|
"@types/node": "26.6.5",
|
|
30
30
|
"axios": "1.20.0",
|
|
31
31
|
"typescript": "6.0.3",
|