@npora/request 1.11.1 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -182,6 +182,10 @@ The body options `body`, `json`, `form`, and `formData` are mutually exclusive.
182
182
  `GET` and `HEAD` requests cannot contain a body. Invalid configuration throws a
183
183
  `RequestError` before the adapter sends a request.
184
184
 
185
+ See the complete [configuration reference](https://github.com/npora/request/blob/main/docs/configuration.md)
186
+ for every option, default, merge rule, plugin extension, environment limit,
187
+ and transfer-progress behavior.
188
+
185
189
  Create isolated clients with inherited defaults:
186
190
 
187
191
  ```ts
@@ -420,6 +424,7 @@ allowlist, and size budgets.
420
424
 
421
425
  ## Documentation
422
426
 
427
+ - [Configuration reference](https://github.com/npora/request/blob/main/docs/configuration.md)
423
428
  - [API reference](https://github.com/npora/request/blob/main/docs/api.md)
424
429
  - [Architecture](https://github.com/npora/request/blob/main/docs/architecture.md)
425
430
  - [Migration from 0.x](https://github.com/npora/request/blob/main/docs/migration.md)
package/dist/index.cjs CHANGED
@@ -1230,7 +1230,8 @@ var Pipeline = class {
1230
1230
  while (true) try {
1231
1231
  const headers = validatedHeaders;
1232
1232
  validatedHeaders = void 0;
1233
- context.response = headers && this.adapter.requestValidated ? await this.adapter.requestValidated(context.config, headers, preserveRaw || this.hooks.hasResponseHooks || this.interceptors.response.active) : await this.adapter.request(context.config);
1233
+ if (this.hooks.hasTransportHooks) await this.hooks.runTransport(context);
1234
+ if (!context.response) context.response = headers && this.adapter.requestValidated ? await this.adapter.requestValidated(context.config, headers, preserveRaw || this.hooks.hasResponseHooks || this.interceptors.response.active) : await this.adapter.request(context.config);
1234
1235
  return await this.processResponse(context);
1235
1236
  } catch (error) {
1236
1237
  if (!await this.notifyError(context, error)) return this.fail(context, context.error, false);
@@ -1390,6 +1391,7 @@ function normalizePriority$1(priority) {
1390
1391
  var PluginHooks = class {
1391
1392
  constructor() {
1392
1393
  this.requestHooks = new HookRegistry();
1394
+ this.transportHooks = new HookRegistry();
1393
1395
  this.responseHooks = new HookRegistry();
1394
1396
  this.errorHooks = new HookRegistry();
1395
1397
  this.settledHooks = new HookRegistry();
@@ -1401,6 +1403,9 @@ var PluginHooks = class {
1401
1403
  get hasResponseHooks() {
1402
1404
  return this.responseHooks.active;
1403
1405
  }
1406
+ get hasTransportHooks() {
1407
+ return this.transportHooks.active;
1408
+ }
1404
1409
  get hasErrorHooks() {
1405
1410
  return this.errorHooks.active;
1406
1411
  }
@@ -1416,6 +1421,9 @@ var PluginHooks = class {
1416
1421
  onResponse(hook, options = {}) {
1417
1422
  return this.responseHooks.register(hook, options);
1418
1423
  }
1424
+ onTransport(hook, options = {}) {
1425
+ return this.transportHooks.register(hook, options);
1426
+ }
1419
1427
  onError(hook, options = {}) {
1420
1428
  return this.errorHooks.register(hook, options);
1421
1429
  }
@@ -1431,6 +1439,12 @@ var PluginHooks = class {
1431
1439
  async runResponse(context) {
1432
1440
  for (const hook of this.responseHooks.values()) await hook(context);
1433
1441
  }
1442
+ async runTransport(context) {
1443
+ for (const hook of this.transportHooks.values()) {
1444
+ await hook(context);
1445
+ if (context.response) return;
1446
+ }
1447
+ }
1434
1448
  async runError(context) {
1435
1449
  for (const hook of this.errorHooks.values()) await hook(context);
1436
1450
  }
@@ -1546,6 +1560,9 @@ function createScopedHooks(hooks, pluginPriority, cleanups) {
1546
1560
  onRequest(hook, options) {
1547
1561
  return trackHook(hooks.onRequest(hook, withPriority(options, pluginPriority)), cleanups);
1548
1562
  },
1563
+ onTransport(hook, options) {
1564
+ return trackHook(hooks.onTransport(hook, withPriority(options, pluginPriority)), cleanups);
1565
+ },
1549
1566
  onResponse(hook, options) {
1550
1567
  return trackHook(hooks.onResponse(hook, withPriority(options, pluginPriority)), cleanups);
1551
1568
  },
@@ -2801,7 +2818,7 @@ function downloadPlugin(options = {}) {
2801
2818
  responseType
2802
2819
  };
2803
2820
  });
2804
- context.hooks.onRequest(async (requestContext) => {
2821
+ context.hooks.onTransport(async (requestContext) => {
2805
2822
  if (requestContext.response) return;
2806
2823
  const onProgress = resolveExtensionConfig(requestContext.config, "download")?.onProgress;
2807
2824
  if (!onProgress || !shouldUseXHR(options.transport)) return;
@@ -3201,7 +3218,7 @@ function uploadPlugin() {
3201
3218
  formData: upload.data
3202
3219
  };
3203
3220
  });
3204
- context.hooks.onRequest(async (requestContext) => {
3221
+ context.hooks.onTransport(async (requestContext) => {
3205
3222
  if (requestContext.response) return;
3206
3223
  const upload = resolveExtensionConfig(requestContext.config, "upload");
3207
3224
  if (!upload?.onProgress) return;
package/dist/index.d.cts CHANGED
@@ -264,6 +264,11 @@ interface DownloadProgress {
264
264
  progress?: number;
265
265
  }
266
266
  interface DownloadOptions {
267
+ /**
268
+ * Reserved legacy field. It does not save or rename the returned Blob.
269
+ *
270
+ * @deprecated This field currently has no effect.
271
+ */
267
272
  filename?: string;
268
273
  /**
269
274
  * Called while the response stream is being consumed.
@@ -550,6 +555,14 @@ interface PluginInterceptorManager<T> {
550
555
  }
551
556
  interface PluginHookManager {
552
557
  onRequest(hook: RequestHook, options?: HookOptions): HookDisposer;
558
+ /**
559
+ * Provide an alternative transport for the current attempt.
560
+ *
561
+ * Transport hooks run inside the retry loop. A hook that handles the
562
+ * request assigns `context.response`; later transport hooks and the client
563
+ * adapter are then skipped for that attempt.
564
+ */
565
+ onTransport(hook: RequestHook, options?: HookOptions): HookDisposer;
553
566
  onResponse(hook: RequestHook, options?: HookOptions): HookDisposer;
554
567
  onError(hook: RequestHook, options?: HookOptions): HookDisposer;
555
568
  /**
package/dist/index.d.ts CHANGED
@@ -264,6 +264,11 @@ interface DownloadProgress {
264
264
  progress?: number;
265
265
  }
266
266
  interface DownloadOptions {
267
+ /**
268
+ * Reserved legacy field. It does not save or rename the returned Blob.
269
+ *
270
+ * @deprecated This field currently has no effect.
271
+ */
267
272
  filename?: string;
268
273
  /**
269
274
  * Called while the response stream is being consumed.
@@ -550,6 +555,14 @@ interface PluginInterceptorManager<T> {
550
555
  }
551
556
  interface PluginHookManager {
552
557
  onRequest(hook: RequestHook, options?: HookOptions): HookDisposer;
558
+ /**
559
+ * Provide an alternative transport for the current attempt.
560
+ *
561
+ * Transport hooks run inside the retry loop. A hook that handles the
562
+ * request assigns `context.response`; later transport hooks and the client
563
+ * adapter are then skipped for that attempt.
564
+ */
565
+ onTransport(hook: RequestHook, options?: HookOptions): HookDisposer;
553
566
  onResponse(hook: RequestHook, options?: HookOptions): HookDisposer;
554
567
  onError(hook: RequestHook, options?: HookOptions): HookDisposer;
555
568
  /**
package/dist/index.js CHANGED
@@ -1229,7 +1229,8 @@ var Pipeline = class {
1229
1229
  while (true) try {
1230
1230
  const headers = validatedHeaders;
1231
1231
  validatedHeaders = void 0;
1232
- context.response = headers && this.adapter.requestValidated ? await this.adapter.requestValidated(context.config, headers, preserveRaw || this.hooks.hasResponseHooks || this.interceptors.response.active) : await this.adapter.request(context.config);
1232
+ if (this.hooks.hasTransportHooks) await this.hooks.runTransport(context);
1233
+ if (!context.response) context.response = headers && this.adapter.requestValidated ? await this.adapter.requestValidated(context.config, headers, preserveRaw || this.hooks.hasResponseHooks || this.interceptors.response.active) : await this.adapter.request(context.config);
1233
1234
  return await this.processResponse(context);
1234
1235
  } catch (error) {
1235
1236
  if (!await this.notifyError(context, error)) return this.fail(context, context.error, false);
@@ -1389,6 +1390,7 @@ function normalizePriority$1(priority) {
1389
1390
  var PluginHooks = class {
1390
1391
  constructor() {
1391
1392
  this.requestHooks = new HookRegistry();
1393
+ this.transportHooks = new HookRegistry();
1392
1394
  this.responseHooks = new HookRegistry();
1393
1395
  this.errorHooks = new HookRegistry();
1394
1396
  this.settledHooks = new HookRegistry();
@@ -1400,6 +1402,9 @@ var PluginHooks = class {
1400
1402
  get hasResponseHooks() {
1401
1403
  return this.responseHooks.active;
1402
1404
  }
1405
+ get hasTransportHooks() {
1406
+ return this.transportHooks.active;
1407
+ }
1403
1408
  get hasErrorHooks() {
1404
1409
  return this.errorHooks.active;
1405
1410
  }
@@ -1415,6 +1420,9 @@ var PluginHooks = class {
1415
1420
  onResponse(hook, options = {}) {
1416
1421
  return this.responseHooks.register(hook, options);
1417
1422
  }
1423
+ onTransport(hook, options = {}) {
1424
+ return this.transportHooks.register(hook, options);
1425
+ }
1418
1426
  onError(hook, options = {}) {
1419
1427
  return this.errorHooks.register(hook, options);
1420
1428
  }
@@ -1430,6 +1438,12 @@ var PluginHooks = class {
1430
1438
  async runResponse(context) {
1431
1439
  for (const hook of this.responseHooks.values()) await hook(context);
1432
1440
  }
1441
+ async runTransport(context) {
1442
+ for (const hook of this.transportHooks.values()) {
1443
+ await hook(context);
1444
+ if (context.response) return;
1445
+ }
1446
+ }
1433
1447
  async runError(context) {
1434
1448
  for (const hook of this.errorHooks.values()) await hook(context);
1435
1449
  }
@@ -1545,6 +1559,9 @@ function createScopedHooks(hooks, pluginPriority, cleanups) {
1545
1559
  onRequest(hook, options) {
1546
1560
  return trackHook(hooks.onRequest(hook, withPriority(options, pluginPriority)), cleanups);
1547
1561
  },
1562
+ onTransport(hook, options) {
1563
+ return trackHook(hooks.onTransport(hook, withPriority(options, pluginPriority)), cleanups);
1564
+ },
1548
1565
  onResponse(hook, options) {
1549
1566
  return trackHook(hooks.onResponse(hook, withPriority(options, pluginPriority)), cleanups);
1550
1567
  },
@@ -2800,7 +2817,7 @@ function downloadPlugin(options = {}) {
2800
2817
  responseType
2801
2818
  };
2802
2819
  });
2803
- context.hooks.onRequest(async (requestContext) => {
2820
+ context.hooks.onTransport(async (requestContext) => {
2804
2821
  if (requestContext.response) return;
2805
2822
  const onProgress = resolveExtensionConfig(requestContext.config, "download")?.onProgress;
2806
2823
  if (!onProgress || !shouldUseXHR(options.transport)) return;
@@ -3200,7 +3217,7 @@ function uploadPlugin() {
3200
3217
  formData: upload.data
3201
3218
  };
3202
3219
  });
3203
- context.hooks.onRequest(async (requestContext) => {
3220
+ context.hooks.onTransport(async (requestContext) => {
3204
3221
  if (requestContext.response) return;
3205
3222
  const upload = resolveExtensionConfig(requestContext.config, "upload");
3206
3223
  if (!upload?.onProgress) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npora/request",
3
- "version": "1.11.1",
3
+ "version": "1.12.0",
4
4
  "description": "A modern, TypeScript-first HTTP client powered by the Fetch API.",
5
5
  "keywords": [
6
6
  "npora",