@naturalcycles/js-lib 15.52.0 → 15.53.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/dist/http/fetcher.d.ts
CHANGED
package/dist/http/fetcher.js
CHANGED
|
@@ -591,7 +591,7 @@ export class Fetcher {
|
|
|
591
591
|
}
|
|
592
592
|
const norm = _merge({
|
|
593
593
|
baseUrl: '',
|
|
594
|
-
name:
|
|
594
|
+
name: this.getFetcherName(cfg),
|
|
595
595
|
inputUrl: '',
|
|
596
596
|
responseType: 'json',
|
|
597
597
|
searchParams: {},
|
|
@@ -622,10 +622,21 @@ export class Fetcher {
|
|
|
622
622
|
hooks: {},
|
|
623
623
|
throwHttpErrors: true,
|
|
624
624
|
errorData: {},
|
|
625
|
-
}, _omit(cfg, ['method', 'credentials', 'headers', 'redirect', 'logger']));
|
|
625
|
+
}, _omit(cfg, ['method', 'credentials', 'headers', 'redirect', 'logger', 'name']));
|
|
626
626
|
norm.init.headers = _mapKeys(norm.init.headers, k => k.toLowerCase());
|
|
627
627
|
return norm;
|
|
628
628
|
}
|
|
629
|
+
getFetcherName(cfg) {
|
|
630
|
+
let { name } = cfg;
|
|
631
|
+
if (!name && cfg.baseUrl) {
|
|
632
|
+
// derive FetcherName from baseUrl
|
|
633
|
+
const url = URL.parse(cfg.baseUrl);
|
|
634
|
+
if (url) {
|
|
635
|
+
name = url.hostname;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return name;
|
|
639
|
+
}
|
|
629
640
|
normalizeOptions(opt) {
|
|
630
641
|
const req = {
|
|
631
642
|
..._pick(this.cfg, [
|
|
@@ -5,9 +5,10 @@ import type { ErrorData } from '../error/error.model.js';
|
|
|
5
5
|
import type { CommonLogger } from '../log/commonLogger.js';
|
|
6
6
|
import type { AnyObject, NumberOfMilliseconds, Promisable, Reviver, UnixTimestampMillis } from '../types.js';
|
|
7
7
|
import type { HttpMethod, HttpStatusFamily } from './http.model.js';
|
|
8
|
-
export interface FetcherNormalizedCfg extends Required<Omit<FetcherCfg, 'dispatcher'>>, Omit<FetcherRequest, 'started' | 'fullUrl' | 'logRequest' | 'logRequestBody' | 'logResponse' | 'logResponseBody' | 'debug' | 'redirect' | 'credentials' | 'throwHttpErrors' | 'errorData'> {
|
|
8
|
+
export interface FetcherNormalizedCfg extends Required<Omit<FetcherCfg, 'dispatcher' | 'name'>>, Omit<FetcherRequest, 'started' | 'fullUrl' | 'logRequest' | 'logRequestBody' | 'logResponse' | 'logResponseBody' | 'debug' | 'redirect' | 'credentials' | 'throwHttpErrors' | 'errorData'> {
|
|
9
9
|
logger: CommonLogger;
|
|
10
10
|
searchParams: Record<string, any>;
|
|
11
|
+
name?: string;
|
|
11
12
|
}
|
|
12
13
|
export type FetcherBeforeRequestHook = (req: FetcherRequest) => Promisable<void>;
|
|
13
14
|
export type FetcherAfterResponseHook = <BODY = unknown>(res: FetcherResponse<BODY>) => Promisable<void>;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@ import type { HttpMethod, HttpStatusFamily } from './http.model.js'
|
|
|
15
15
|
|
|
16
16
|
export interface FetcherNormalizedCfg
|
|
17
17
|
extends
|
|
18
|
-
Required<Omit<FetcherCfg, 'dispatcher'>>,
|
|
18
|
+
Required<Omit<FetcherCfg, 'dispatcher' | 'name'>>,
|
|
19
19
|
Omit<
|
|
20
20
|
FetcherRequest,
|
|
21
21
|
| 'started'
|
|
@@ -32,6 +32,7 @@ export interface FetcherNormalizedCfg
|
|
|
32
32
|
> {
|
|
33
33
|
logger: CommonLogger
|
|
34
34
|
searchParams: Record<string, any>
|
|
35
|
+
name?: string
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export type FetcherBeforeRequestHook = (req: FetcherRequest) => Promisable<void>
|
package/src/http/fetcher.ts
CHANGED
|
@@ -726,7 +726,7 @@ export class Fetcher {
|
|
|
726
726
|
const norm: FetcherNormalizedCfg = _merge(
|
|
727
727
|
{
|
|
728
728
|
baseUrl: '',
|
|
729
|
-
name:
|
|
729
|
+
name: this.getFetcherName(cfg),
|
|
730
730
|
inputUrl: '',
|
|
731
731
|
responseType: 'json',
|
|
732
732
|
searchParams: {},
|
|
@@ -758,7 +758,7 @@ export class Fetcher {
|
|
|
758
758
|
throwHttpErrors: true,
|
|
759
759
|
errorData: {},
|
|
760
760
|
},
|
|
761
|
-
_omit(cfg, ['method', 'credentials', 'headers', 'redirect', 'logger']),
|
|
761
|
+
_omit(cfg, ['method', 'credentials', 'headers', 'redirect', 'logger', 'name']),
|
|
762
762
|
)
|
|
763
763
|
|
|
764
764
|
norm.init.headers = _mapKeys(norm.init.headers, k => k.toLowerCase())
|
|
@@ -766,6 +766,18 @@ export class Fetcher {
|
|
|
766
766
|
return norm
|
|
767
767
|
}
|
|
768
768
|
|
|
769
|
+
private getFetcherName(cfg: FetcherCfg): string | undefined {
|
|
770
|
+
let { name } = cfg
|
|
771
|
+
if (!name && cfg.baseUrl) {
|
|
772
|
+
// derive FetcherName from baseUrl
|
|
773
|
+
const url = URL.parse(cfg.baseUrl)
|
|
774
|
+
if (url) {
|
|
775
|
+
name = url.hostname
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
return name
|
|
779
|
+
}
|
|
780
|
+
|
|
769
781
|
private normalizeOptions(opt: FetcherOptions): FetcherRequest {
|
|
770
782
|
const req: FetcherRequest = {
|
|
771
783
|
..._pick(this.cfg, [
|