@alanszp/axios-node 5.0.0 → 6.0.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/axios.d.ts +2 -7
- package/dist/axios.js +2 -5
- package/dist/axios.js.map +1 -1
- package/package.json +4 -3
- package/src/axios.ts +4 -14
package/dist/axios.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
-
export interface SharedContext {
|
|
4
|
-
lifecycleId: string;
|
|
5
|
-
lifecycleChain: string;
|
|
6
|
-
}
|
|
1
|
+
import { SharedContext } from "@alanszp/shared-context";
|
|
7
2
|
export declare const isAxiosError: any;
|
|
8
3
|
export declare function createAxios(): import("axios").AxiosInstance;
|
|
9
|
-
export declare function createAxiosWithTrace(
|
|
4
|
+
export declare function createAxiosWithTrace(sharedContext: SharedContext): import("axios").AxiosInstance;
|
package/dist/axios.js
CHANGED
|
@@ -28,15 +28,12 @@ function createAxios() {
|
|
|
28
28
|
return axios;
|
|
29
29
|
}
|
|
30
30
|
exports.createAxios = createAxios;
|
|
31
|
-
function createAxiosWithTrace(
|
|
31
|
+
function createAxiosWithTrace(sharedContext) {
|
|
32
32
|
const axios = axios_1.default.create();
|
|
33
33
|
axios.interceptors.request.use((config) => {
|
|
34
|
-
const context = requestSharedContext.getStore();
|
|
35
|
-
if (!context)
|
|
36
|
-
return config;
|
|
37
34
|
return Object.assign(Object.assign({}, config), {
|
|
38
35
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
39
|
-
headers: Object.assign({ "x-lifecycle-id":
|
|
36
|
+
headers: Object.assign({ "x-lifecycle-id": sharedContext.getLifecycleId(), "x-lifecycle-chain": sharedContext.getLifecycleChain() }, config.headers) });
|
|
40
37
|
}, mapAxiosErrorToRequestError);
|
|
41
38
|
axios.interceptors.response.use(id, mapAxiosErrorToRequestError);
|
|
42
39
|
return axios;
|
package/dist/axios.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios.js","sourceRoot":"","sources":["../src/axios.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAgD;
|
|
1
|
+
{"version":3,"file":"axios.js","sourceRoot":"","sources":["../src/axios.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAgD;AAChD,sEAAmE;AACnE,sEAAmE;AACnE,wDAAqD;AAGxC,QAAA,YAAY,GAAG,eAAW,CAAC,YAAY,CAAC,IAAI,CAAC,eAAW,CAAC,CAAC;AAEvE,SAAS,2BAA2B,CAAI,KAAU;IAChD,IAAI,KAAK,CAAC,QAAQ,EAAE;QAClB,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,yCAAmB,CAAI,KAAsB,CAAC,CAAC,CAAC;KAC3E;IAED,IAAI,KAAK,CAAC,OAAO,EAAE;QACjB,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,yCAAmB,CAAC,KAAsB,CAAC,CAAC,CAAC;KACxE;IAED,OAAO,CAAC,MAAM,CAAC,IAAI,2BAAY,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,EAAE,CAAI,CAAI;IACjB,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAgB,WAAW;IACzB,MAAM,KAAK,GAAG,eAAW,CAAC,MAAM,EAAE,CAAC;IACnC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,2BAA2B,CAAC,CAAC;IAChE,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,2BAA2B,CAAC,CAAC;IACjE,OAAO,KAAK,CAAC;AACf,CAAC;AALD,kCAKC;AAED,SAAgB,oBAAoB,CAAC,aAA4B;IAC/D,MAAM,KAAK,GAAG,eAAW,CAAC,MAAM,EAAE,CAAC;IAEnC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QACxC,uCACK,MAAM;YACT,mEAAmE;YACnE,OAAO,kBACL,gBAAgB,EAAE,aAAa,CAAC,cAAc,EAAE,EAChD,mBAAmB,EAAE,aAAa,CAAC,iBAAiB,EAAE,IACnD,MAAM,CAAC,OAAO,KAEnB;IACJ,CAAC,EAAE,2BAA2B,CAAC,CAAC;IAEhC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,2BAA2B,CAAC,CAAC;IAEjE,OAAO,KAAK,CAAC;AACf,CAAC;AAlBD,oDAkBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alanszp/axios-node",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Alan's axios wrapper with base interceptor.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
"yalc-publish": "yarn run yalc publish"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@alanszp/errors": "^
|
|
22
|
+
"@alanszp/errors": "^6.0.0",
|
|
23
|
+
"@alanszp/shared-context": "^6.0.0",
|
|
23
24
|
"axios": "^0.24.0"
|
|
24
25
|
},
|
|
25
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "75b34d763277366fdf93146cd1d20084ff469273"
|
|
26
27
|
}
|
package/src/axios.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import AxiosGlobal, { AxiosError } from "axios";
|
|
2
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
3
2
|
import { NetworkRequestError } from "./errors/NetworkRequestError";
|
|
4
3
|
import { Non200ResponseError } from "./errors/Non200ResponseError";
|
|
5
4
|
import { GenericError } from "./errors/GenericError";
|
|
6
|
-
|
|
7
|
-
export interface SharedContext {
|
|
8
|
-
lifecycleId: string;
|
|
9
|
-
lifecycleChain: string;
|
|
10
|
-
}
|
|
5
|
+
import { SharedContext } from "@alanszp/shared-context";
|
|
11
6
|
|
|
12
7
|
export const isAxiosError = AxiosGlobal.isAxiosError.bind(AxiosGlobal);
|
|
13
8
|
|
|
@@ -34,21 +29,16 @@ export function createAxios() {
|
|
|
34
29
|
return axios;
|
|
35
30
|
}
|
|
36
31
|
|
|
37
|
-
export function createAxiosWithTrace(
|
|
38
|
-
requestSharedContext: AsyncLocalStorage<SharedContext>
|
|
39
|
-
) {
|
|
32
|
+
export function createAxiosWithTrace(sharedContext: SharedContext) {
|
|
40
33
|
const axios = AxiosGlobal.create();
|
|
41
34
|
|
|
42
35
|
axios.interceptors.request.use((config) => {
|
|
43
|
-
const context = requestSharedContext.getStore();
|
|
44
|
-
if (!context) return config;
|
|
45
|
-
|
|
46
36
|
return {
|
|
47
37
|
...config,
|
|
48
38
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
49
39
|
headers: {
|
|
50
|
-
"x-lifecycle-id":
|
|
51
|
-
"x-lifecycle-chain":
|
|
40
|
+
"x-lifecycle-id": sharedContext.getLifecycleId(),
|
|
41
|
+
"x-lifecycle-chain": sharedContext.getLifecycleChain(),
|
|
52
42
|
...config.headers,
|
|
53
43
|
},
|
|
54
44
|
};
|