@leancodepl/axios-cqrs-client 8.3.2 → 8.3.4

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/index.cjs.js CHANGED
@@ -27,7 +27,7 @@ function createError(error) {
27
27
  error
28
28
  };
29
29
  }
30
- function mkCqrsClient({ cqrsEndpoint, tokenProvider, axiosOptions }) {
30
+ function mkCqrsClient({ cqrsEndpoint, tokenProvider, axiosOptions, tokenHeader = "Authorization" }) {
31
31
  const apiAxios = axios.create(_extends({
32
32
  baseURL: cqrsEndpoint
33
33
  }, axiosOptions));
@@ -35,7 +35,7 @@ function mkCqrsClient({ cqrsEndpoint, tokenProvider, axiosOptions }) {
35
35
  const token = await (tokenProvider == null ? void 0 : tokenProvider.getToken());
36
36
  if (token) {
37
37
  var _config_headers;
38
- (_config_headers = config.headers) == null ? void 0 : _config_headers.set("Authorization", `Bearer ${token}`);
38
+ (_config_headers = config.headers) == null ? void 0 : _config_headers.set(tokenHeader, `Bearer ${token}`);
39
39
  }
40
40
  return config;
41
41
  });
@@ -85,7 +85,14 @@ function mkCqrsClient({ cqrsEndpoint, tokenProvider, axiosOptions }) {
85
85
  });
86
86
  return {
87
87
  createQuery (type) {
88
- return (dto)=>apiAxios.post("query/" + type, dto).then((r)=>r.data);
88
+ return (dto)=>{
89
+ const abortController = new AbortController();
90
+ const promise = apiAxios.post("query/" + type, dto, {
91
+ signal: abortController.signal
92
+ }).then((r)=>r.data);
93
+ promise.abort = abortController.abort.bind(abortController);
94
+ return promise;
95
+ };
89
96
  },
90
97
  createOperation (type) {
91
98
  return (dto)=>apiAxios.post("operation/" + type, dto).then((r)=>r.data);
package/index.esm.js CHANGED
@@ -25,7 +25,7 @@ function createError(error) {
25
25
  error
26
26
  };
27
27
  }
28
- function mkCqrsClient({ cqrsEndpoint, tokenProvider, axiosOptions }) {
28
+ function mkCqrsClient({ cqrsEndpoint, tokenProvider, axiosOptions, tokenHeader = "Authorization" }) {
29
29
  const apiAxios = axios.create(_extends({
30
30
  baseURL: cqrsEndpoint
31
31
  }, axiosOptions));
@@ -33,7 +33,7 @@ function mkCqrsClient({ cqrsEndpoint, tokenProvider, axiosOptions }) {
33
33
  const token = await (tokenProvider == null ? void 0 : tokenProvider.getToken());
34
34
  if (token) {
35
35
  var _config_headers;
36
- (_config_headers = config.headers) == null ? void 0 : _config_headers.set("Authorization", `Bearer ${token}`);
36
+ (_config_headers = config.headers) == null ? void 0 : _config_headers.set(tokenHeader, `Bearer ${token}`);
37
37
  }
38
38
  return config;
39
39
  });
@@ -83,7 +83,14 @@ function mkCqrsClient({ cqrsEndpoint, tokenProvider, axiosOptions }) {
83
83
  });
84
84
  return {
85
85
  createQuery (type) {
86
- return (dto)=>apiAxios.post("query/" + type, dto).then((r)=>r.data);
86
+ return (dto)=>{
87
+ const abortController = new AbortController();
88
+ const promise = apiAxios.post("query/" + type, dto, {
89
+ signal: abortController.signal
90
+ }).then((r)=>r.data);
91
+ promise.abort = abortController.abort.bind(abortController);
92
+ return promise;
93
+ };
87
94
  },
88
95
  createOperation (type) {
89
96
  return (dto)=>apiAxios.post("operation/" + type, dto).then((r)=>r.data);
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@leancodepl/axios-cqrs-client",
3
- "version": "8.3.2",
3
+ "version": "8.3.4",
4
4
  "license": "Apache-2.0",
5
5
  "dependencies": {
6
- "@leancodepl/cqrs-client-base": "8.3.2",
7
- "@leancodepl/validation": "8.3.2",
6
+ "@leancodepl/cqrs-client-base": "8.3.4",
7
+ "@leancodepl/validation": "8.3.4",
8
8
  "axios": ">=1.6.0"
9
9
  },
10
10
  "exports": {
@@ -4,9 +4,10 @@ export type MkCqrsClientParameters = {
4
4
  cqrsEndpoint: string;
5
5
  tokenProvider?: TokenProvider;
6
6
  axiosOptions?: CreateAxiosDefaults;
7
+ tokenHeader?: string;
7
8
  };
8
- export declare function mkCqrsClient({ cqrsEndpoint, tokenProvider, axiosOptions }: MkCqrsClientParameters): {
9
- createQuery<TQuery, TResult>(type: string): (dto: TQuery) => Promise<ApiError | ApiSuccess<TResult>>;
9
+ export declare function mkCqrsClient({ cqrsEndpoint, tokenProvider, axiosOptions, tokenHeader, }: MkCqrsClientParameters): {
10
+ createQuery<TQuery, TResult>(type: string): (dto: TQuery) => QueryPromise<TResult>;
10
11
  createOperation<TOperation, TResult>(type: string): (dto: TOperation) => Promise<ApiError | ApiSuccess<TResult>>;
11
12
  createCommand<TCommand, TErrorCodes extends {
12
13
  [name: string]: number;
@@ -18,3 +19,7 @@ export declare function mkCqrsClient({ cqrsEndpoint, tokenProvider, axiosOptions
18
19
  }, never>>;
19
20
  };
20
21
  };
22
+ export type QueryAbort = {
23
+ abort: AbortController["abort"];
24
+ };
25
+ export type QueryPromise<TResult> = Promise<ApiResponse<TResult>> & QueryAbort;