@naturalcycles/js-lib 14.124.1 → 14.125.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.
@@ -89,6 +89,10 @@ export interface FetcherOptions {
89
89
  */
90
90
  body?: Blob | BufferSource | FormData | URLSearchParams | string;
91
91
  credentials?: RequestCredentials;
92
+ /**
93
+ * Default to true.
94
+ */
95
+ followRedirects?: boolean;
92
96
  headers?: Record<string, any>;
93
97
  mode?: FetcherMode;
94
98
  searchParams?: Record<string, any>;
@@ -166,6 +170,10 @@ export declare class Fetcher {
166
170
  deleteVoid: (url: string, opt?: FetcherOptions) => Promise<void>;
167
171
  headVoid: (url: string, opt?: FetcherOptions) => Promise<void>;
168
172
  fetch<T = unknown>(url: string, opt?: FetcherOptions): Promise<T>;
173
+ /**
174
+ * Returns FetcherResponse.
175
+ * Never throws, returns `err` property in the response instead.
176
+ */
169
177
  rawFetch<T = unknown>(url: string, rawOpt?: FetcherOptions): Promise<FetcherResponse<T>>;
170
178
  private processRetry;
171
179
  /**
@@ -88,6 +88,10 @@ class Fetcher {
88
88
  }
89
89
  return res.body;
90
90
  }
91
+ /**
92
+ * Returns FetcherResponse.
93
+ * Never throws, returns `err` property in the response instead.
94
+ */
91
95
  async rawFetch(url, rawOpt = {}) {
92
96
  const { logger } = this.cfg;
93
97
  const req = this.normalizeOptions(url, rawOpt);
@@ -332,6 +336,7 @@ class Fetcher {
332
336
  ...this.cfg.init,
333
337
  method: opt.method || this.cfg.init.method,
334
338
  credentials: opt.credentials || this.cfg.init.credentials,
339
+ redirect: opt.followRedirects ?? this.cfg.followRedirects ?? true ? 'follow' : 'error',
335
340
  }, {
336
341
  headers: (0, object_util_1._mapKeys)(opt.headers || {}, k => k.toLowerCase()),
337
342
  }),
@@ -77,6 +77,10 @@ export class Fetcher {
77
77
  }
78
78
  return res.body;
79
79
  }
80
+ /**
81
+ * Returns FetcherResponse.
82
+ * Never throws, returns `err` property in the response instead.
83
+ */
80
84
  async rawFetch(url, rawOpt = {}) {
81
85
  var _a, e_1, _b, _c, _d, e_2, _e, _f;
82
86
  var _g, _h, _j;
@@ -355,6 +359,7 @@ export class Fetcher {
355
359
  return norm;
356
360
  }
357
361
  normalizeOptions(url, opt) {
362
+ var _a, _b;
358
363
  const { baseUrl, timeoutSeconds, throwHttpErrors, retryPost, retry4xx, retry5xx, retry, mode } = this.cfg;
359
364
  const req = Object.assign(Object.assign({ mode,
360
365
  url,
@@ -362,7 +367,7 @@ export class Fetcher {
362
367
  throwHttpErrors,
363
368
  retryPost,
364
369
  retry4xx,
365
- retry5xx }, _omit(opt, ['method', 'headers', 'credentials'])), { retry: Object.assign(Object.assign({}, retry), _filterUndefinedValues(opt.retry || {})), init: _merge(Object.assign(Object.assign({}, this.cfg.init), { method: opt.method || this.cfg.init.method, credentials: opt.credentials || this.cfg.init.credentials }), {
370
+ retry5xx }, _omit(opt, ['method', 'headers', 'credentials'])), { retry: Object.assign(Object.assign({}, retry), _filterUndefinedValues(opt.retry || {})), init: _merge(Object.assign(Object.assign({}, this.cfg.init), { method: opt.method || this.cfg.init.method, credentials: opt.credentials || this.cfg.init.credentials, redirect: ((_b = (_a = opt.followRedirects) !== null && _a !== void 0 ? _a : this.cfg.followRedirects) !== null && _b !== void 0 ? _b : true) ? 'follow' : 'error' }), {
366
371
  headers: _mapKeys(opt.headers || {}, k => k.toLowerCase()),
367
372
  }) });
368
373
  // setup url
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.124.1",
3
+ "version": "14.125.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -117,6 +117,10 @@ export interface FetcherOptions {
117
117
  body?: Blob | BufferSource | FormData | URLSearchParams | string
118
118
 
119
119
  credentials?: RequestCredentials
120
+ /**
121
+ * Default to true.
122
+ */
123
+ followRedirects?: boolean
120
124
 
121
125
  // Removing RequestInit from options to simplify FetcherOptions interface.
122
126
  // Will instead only add hand-picked useful options, such as `credentials`.
@@ -287,6 +291,10 @@ export class Fetcher {
287
291
  return res.body!
288
292
  }
289
293
 
294
+ /**
295
+ * Returns FetcherResponse.
296
+ * Never throws, returns `err` property in the response instead.
297
+ */
290
298
  async rawFetch<T = unknown>(
291
299
  url: string,
292
300
  rawOpt: FetcherOptions = {},
@@ -575,6 +583,7 @@ export class Fetcher {
575
583
  ...this.cfg.init,
576
584
  method: opt.method || this.cfg.init.method,
577
585
  credentials: opt.credentials || this.cfg.init.credentials,
586
+ redirect: opt.followRedirects ?? this.cfg.followRedirects ?? true ? 'follow' : 'error',
578
587
  },
579
588
  {
580
589
  headers: _mapKeys(opt.headers || {}, k => k.toLowerCase()),