@leancodepl/react-query-cqrs-client 8.3.1 → 8.3.3

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
@@ -57,13 +57,13 @@ function uncapitalizedJSONParse(json) {
57
57
  function uncapitalizedParse() {
58
58
  return ($source)=>$source.pipe(operators.map(uncapitalizedJSONParse));
59
59
  }
60
- function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions }) {
60
+ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions, tokenHeader = "Authorization" }) {
61
61
  function mkFetcher(endpoint, config = {}) {
62
62
  const apiCall = (data, token)=>{
63
63
  var _ajaxOptions_withCredentials;
64
64
  return ajax.ajax(_extends({}, ajaxOptions, config, {
65
65
  headers: {
66
- Authorization: token,
66
+ [tokenHeader]: token,
67
67
  "Content-Type": "application/json"
68
68
  },
69
69
  url: `${cqrsEndpoint}/${endpoint}`,
@@ -163,9 +163,7 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
163
163
  "invalidateQueries"
164
164
  ]);
165
165
  return reactQuery.useMutation(_extends({
166
- mutationKey: [
167
- type
168
- ],
166
+ mutationKey: useApiOperation.key,
169
167
  mutationFn: (variables)=>rxjs.firstValueFrom(useApiOperation.fetcher(variables))
170
168
  }, options, {
171
169
  async onSuccess (data, variables, context) {
@@ -180,6 +178,9 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
180
178
  }), queryClient);
181
179
  }
182
180
  useApiOperation.type = type;
181
+ useApiOperation.key = [
182
+ useApiOperation.type
183
+ ];
183
184
  useApiOperation.fetcher = (variables)=>fetcher(variables).pipe(uncapitalizedParse());
184
185
  return useApiOperation;
185
186
  },
@@ -195,9 +196,7 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
195
196
  "onSettled"
196
197
  ]);
197
198
  return reactQuery.useMutation(_extends({}, options, {
198
- mutationKey: [
199
- type
200
- ],
199
+ mutationKey: useApiCommand.key,
201
200
  mutationFn: (variables)=>{
202
201
  if (!handler) {
203
202
  return rxjs.firstValueFrom(useApiCommand.fetcher(variables));
@@ -228,6 +227,9 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
228
227
  }), queryClient);
229
228
  }
230
229
  useApiCommand.type = type;
230
+ useApiCommand.key = [
231
+ useApiCommand.type
232
+ ];
231
233
  useApiCommand.fetcher = (variables)=>fetcher(variables);
232
234
  useApiCommand.call = (variables, handler)=>{
233
235
  const $response = useApiCommand.fetcher(variables);
package/index.esm.js CHANGED
@@ -55,13 +55,13 @@ function uncapitalizedJSONParse(json) {
55
55
  function uncapitalizedParse() {
56
56
  return ($source)=>$source.pipe(map(uncapitalizedJSONParse));
57
57
  }
58
- function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions }) {
58
+ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions, tokenHeader = "Authorization" }) {
59
59
  function mkFetcher(endpoint, config = {}) {
60
60
  const apiCall = (data, token)=>{
61
61
  var _ajaxOptions_withCredentials;
62
62
  return ajax(_extends({}, ajaxOptions, config, {
63
63
  headers: {
64
- Authorization: token,
64
+ [tokenHeader]: token,
65
65
  "Content-Type": "application/json"
66
66
  },
67
67
  url: `${cqrsEndpoint}/${endpoint}`,
@@ -161,9 +161,7 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
161
161
  "invalidateQueries"
162
162
  ]);
163
163
  return useMutation(_extends({
164
- mutationKey: [
165
- type
166
- ],
164
+ mutationKey: useApiOperation.key,
167
165
  mutationFn: (variables)=>firstValueFrom(useApiOperation.fetcher(variables))
168
166
  }, options, {
169
167
  async onSuccess (data, variables, context) {
@@ -178,6 +176,9 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
178
176
  }), queryClient);
179
177
  }
180
178
  useApiOperation.type = type;
179
+ useApiOperation.key = [
180
+ useApiOperation.type
181
+ ];
181
182
  useApiOperation.fetcher = (variables)=>fetcher(variables).pipe(uncapitalizedParse());
182
183
  return useApiOperation;
183
184
  },
@@ -193,9 +194,7 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
193
194
  "onSettled"
194
195
  ]);
195
196
  return useMutation(_extends({}, options, {
196
- mutationKey: [
197
- type
198
- ],
197
+ mutationKey: useApiCommand.key,
199
198
  mutationFn: (variables)=>{
200
199
  if (!handler) {
201
200
  return firstValueFrom(useApiCommand.fetcher(variables));
@@ -226,6 +225,9 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
226
225
  }), queryClient);
227
226
  }
228
227
  useApiCommand.type = type;
228
+ useApiCommand.key = [
229
+ useApiCommand.type
230
+ ];
229
231
  useApiCommand.fetcher = (variables)=>fetcher(variables);
230
232
  useApiCommand.call = (variables, handler)=>{
231
233
  const $response = useApiCommand.fetcher(variables);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@leancodepl/react-query-cqrs-client",
3
- "version": "8.3.1",
3
+ "version": "8.3.3",
4
4
  "license": "Apache-2.0",
5
5
  "dependencies": {
6
- "@leancodepl/cqrs-client-base": "8.3.1",
7
- "@leancodepl/utils": "8.3.1",
8
- "@leancodepl/validation": "8.3.1",
6
+ "@leancodepl/cqrs-client-base": "8.3.3",
7
+ "@leancodepl/utils": "8.3.3",
8
+ "@leancodepl/validation": "8.3.3",
9
9
  "@tanstack/react-query": ">=5.0.0",
10
10
  "rxjs": ">=7.0.0"
11
11
  },
@@ -5,11 +5,12 @@ import { ApiResponse, CommandResult, TokenProvider } from "@leancodepl/cqrs-clie
5
5
  import { ValidationErrorsHandler } from "@leancodepl/validation";
6
6
  import { NullableUncapitalizeDeep } from "./types";
7
7
  export declare function uncapitalizedParse<TResult>(): OperatorFunction<string, NullableUncapitalizeDeep<TResult>>;
8
- export declare function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions, }: {
8
+ export declare function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions, tokenHeader, }: {
9
9
  cqrsEndpoint: string;
10
10
  queryClient: QueryClient;
11
11
  tokenProvider?: Partial<TokenProvider>;
12
12
  ajaxOptions?: Omit<AjaxConfig, "body" | "headers" | "method" | "responseType" | "url">;
13
+ tokenHeader?: string;
13
14
  }): {
14
15
  createQuery<TQuery, TResult>(type: string): {
15
16
  (data: TQuery, options?: Omit<UndefinedInitialDataOptions<NullableUncapitalizeDeep<TResult>, unknown>, "queryFn" | "queryKey">): import("@tanstack/react-query").UseQueryResult<NullableUncapitalizeDeep<TResult>, unknown>;
@@ -38,6 +39,7 @@ export declare function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider,
38
39
  invalidateQueries?: QueryKey[];
39
40
  } & Omit<UseMutationOptions<NullableUncapitalizeDeep<TResult>, unknown, TOperation, TContext>, "mutationFn" | "mutationKey">): UseMutationResult<NullableUncapitalizeDeep<TResult>, unknown, TOperation, TContext>;
40
41
  type: string;
42
+ key: string[];
41
43
  fetcher(variables: TOperation): Observable<NullableUncapitalizeDeep<TResult>>;
42
44
  };
43
45
  createCommand<TCommand, TErrorCodes extends {
@@ -57,6 +59,7 @@ export declare function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider,
57
59
  optimisticUpdate?: (variables: TCommand) => Promise<() => void>[];
58
60
  } & Omit<UseMutationOptions<TResult, TResult, TCommand, TContext>, "mutationFn" | "mutationKey">): UseMutationResult<TResult, TResult, TCommand, TContext>;
59
61
  type: string;
62
+ key: string[];
60
63
  fetcher(variables: TCommand): Observable<CommandResult<TErrorCodes>>;
61
64
  call<TResult>(variables: TCommand, handler: (handler: ValidationErrorsHandler<{
62
65
  success: -1;