@naturalcycles/js-lib 14.132.0 → 14.133.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.
@@ -345,7 +345,7 @@ class Fetcher {
345
345
  return norm;
346
346
  }
347
347
  normalizeOptions(url, opt) {
348
- const { baseUrl, timeoutSeconds, throwHttpErrors, retryPost, retry4xx, retry5xx, retry, mode, jsonReviver, } = this.cfg;
348
+ const { timeoutSeconds, throwHttpErrors, retryPost, retry4xx, retry5xx, retry, mode, jsonReviver, } = this.cfg;
349
349
  const req = {
350
350
  mode,
351
351
  url,
@@ -370,6 +370,7 @@ class Fetcher {
370
370
  }),
371
371
  };
372
372
  // setup url
373
+ const baseUrl = opt.baseUrl || this.cfg.baseUrl;
373
374
  if (baseUrl) {
374
375
  if (url.startsWith('/')) {
375
376
  console.warn(`Fetcher: url should not start with / when baseUrl is specified`);
@@ -68,7 +68,7 @@ export interface FetcherRetryOptions {
68
68
  timeoutMax: number;
69
69
  timeoutMultiplier: number;
70
70
  }
71
- export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers'> {
71
+ export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers' | 'baseUrl'> {
72
72
  url: string;
73
73
  init: RequestInitNormalized;
74
74
  mode: FetcherMode;
@@ -81,6 +81,7 @@ export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers
81
81
  }
82
82
  export interface FetcherOptions {
83
83
  method?: HttpMethod;
84
+ baseUrl?: string;
84
85
  throwHttpErrors?: boolean;
85
86
  /**
86
87
  * Default: 30.
@@ -387,7 +387,7 @@ export class Fetcher {
387
387
  }
388
388
  normalizeOptions(url, opt) {
389
389
  var _a, _b;
390
- const { baseUrl, timeoutSeconds, throwHttpErrors, retryPost, retry4xx, retry5xx, retry, mode, jsonReviver, } = this.cfg;
390
+ const { timeoutSeconds, throwHttpErrors, retryPost, retry4xx, retry5xx, retry, mode, jsonReviver, } = this.cfg;
391
391
  const req = Object.assign(Object.assign({ mode,
392
392
  url,
393
393
  timeoutSeconds,
@@ -399,6 +399,7 @@ export class Fetcher {
399
399
  headers: _mapKeys(opt.headers || {}, k => k.toLowerCase()),
400
400
  }) });
401
401
  // setup url
402
+ const baseUrl = opt.baseUrl || this.cfg.baseUrl;
402
403
  if (baseUrl) {
403
404
  if (url.startsWith('/')) {
404
405
  console.warn(`Fetcher: url should not start with / when baseUrl is specified`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.132.0",
3
+ "version": "14.133.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -79,7 +79,7 @@ export interface FetcherRetryOptions {
79
79
  timeoutMultiplier: number
80
80
  }
81
81
 
82
- export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers'> {
82
+ export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers' | 'baseUrl'> {
83
83
  url: string
84
84
  init: RequestInitNormalized
85
85
  mode: FetcherMode
@@ -93,6 +93,9 @@ export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers
93
93
 
94
94
  export interface FetcherOptions {
95
95
  method?: HttpMethod
96
+
97
+ baseUrl?: string
98
+
96
99
  throwHttpErrors?: boolean
97
100
  /**
98
101
  * Default: 30.
@@ -436,7 +436,6 @@ export class Fetcher {
436
436
 
437
437
  private normalizeOptions(url: string, opt: FetcherOptions): FetcherRequest {
438
438
  const {
439
- baseUrl,
440
439
  timeoutSeconds,
441
440
  throwHttpErrors,
442
441
  retryPost,
@@ -475,6 +474,7 @@ export class Fetcher {
475
474
  }
476
475
 
477
476
  // setup url
477
+ const baseUrl = opt.baseUrl || this.cfg.baseUrl
478
478
  if (baseUrl) {
479
479
  if (url.startsWith('/')) {
480
480
  console.warn(`Fetcher: url should not start with / when baseUrl is specified`)
@@ -1,3 +1,4 @@
1
+ // Should be uppercase, because e.g this browser issue: https://github.com/axios/axios/issues/26
1
2
  export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD'
2
3
 
3
4
  export type HttpStatusFamily = 5 | 4 | 3 | 2 | 1