@go-avro/avro-js 0.0.4-beta.13 → 0.0.4-beta.15
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/client/QueryClient.d.ts +31 -0
- package/dist/client/QueryClient.js +19 -0
- package/dist/client/hooks/catalog_items.js +8 -1
- package/dist/client/hooks/waivers.d.ts +1 -0
- package/dist/client/hooks/waivers.js +123 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/api/Waiver.d.ts +9 -0
- package/dist/types/api/Waiver.js +1 -0
- package/dist/types/api.d.ts +1 -0
- package/dist/types/api.js +1 -0
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ import { AuthState, Tokens } from '../types/auth';
|
|
|
6
6
|
import { CancelToken, RetryStrategy } from '../types/client';
|
|
7
7
|
import { StandardError } from '../types/error';
|
|
8
8
|
import { CacheData } from '../types/cache';
|
|
9
|
+
import { Waiver } from '../types/api/Waiver';
|
|
9
10
|
export interface AvroQueryClientConfig {
|
|
10
11
|
baseUrl: string;
|
|
11
12
|
authManager: AuthManager;
|
|
@@ -106,6 +107,13 @@ declare module '../client/QueryClient' {
|
|
|
106
107
|
query?: string;
|
|
107
108
|
offset?: number;
|
|
108
109
|
}, total: number, onProgress?: (fraction: number) => void): UseQueryResult<Label[], StandardError>;
|
|
110
|
+
useGetWaivers(body: {
|
|
111
|
+
amt?: number;
|
|
112
|
+
known_ids?: string[];
|
|
113
|
+
unknown_ids?: string[];
|
|
114
|
+
query?: string;
|
|
115
|
+
offset?: number;
|
|
116
|
+
}, total: number, onProgress?: (fraction: number) => void): UseQueryResult<Waiver[], StandardError>;
|
|
109
117
|
useGetGroups(body: {
|
|
110
118
|
amt?: number;
|
|
111
119
|
known_ids?: string[];
|
|
@@ -156,6 +164,11 @@ declare module '../client/QueryClient' {
|
|
|
156
164
|
}, StandardError, {
|
|
157
165
|
groupData: Partial<Group>;
|
|
158
166
|
}>>;
|
|
167
|
+
useCreateWaiver(): ReturnType<typeof useMutation<{
|
|
168
|
+
id: string;
|
|
169
|
+
}, StandardError, {
|
|
170
|
+
waiverData: Partial<Waiver>;
|
|
171
|
+
}>>;
|
|
159
172
|
useCreateLabel(): ReturnType<typeof useMutation<{
|
|
160
173
|
id: string;
|
|
161
174
|
}, StandardError, {
|
|
@@ -275,6 +288,12 @@ declare module '../client/QueryClient' {
|
|
|
275
288
|
labelId: string;
|
|
276
289
|
labelData: Partial<Label>;
|
|
277
290
|
}>>;
|
|
291
|
+
useUpdateWaiver(): ReturnType<typeof useMutation<{
|
|
292
|
+
msg: string;
|
|
293
|
+
}, StandardError, {
|
|
294
|
+
waiverId: string;
|
|
295
|
+
updates: Partial<Waiver>;
|
|
296
|
+
}>>;
|
|
278
297
|
useUpdateCatalogItem(): ReturnType<typeof useMutation<{
|
|
279
298
|
msg: string;
|
|
280
299
|
}, StandardError, {
|
|
@@ -383,6 +402,11 @@ declare module '../client/QueryClient' {
|
|
|
383
402
|
}, StandardError, {
|
|
384
403
|
groupId: string;
|
|
385
404
|
}>>;
|
|
405
|
+
useDeleteWaiver(): ReturnType<typeof useMutation<{
|
|
406
|
+
msg: string;
|
|
407
|
+
}, StandardError, {
|
|
408
|
+
waiverId: string;
|
|
409
|
+
}>>;
|
|
386
410
|
useDeleteLabel(): ReturnType<typeof useMutation<{
|
|
387
411
|
msg: string;
|
|
388
412
|
}, StandardError, {
|
|
@@ -509,6 +533,13 @@ export declare class AvroQueryClient {
|
|
|
509
533
|
paid?: boolean;
|
|
510
534
|
taskId?: string | null;
|
|
511
535
|
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
536
|
+
fetchWaivers(body?: {
|
|
537
|
+
amt?: number;
|
|
538
|
+
query?: string;
|
|
539
|
+
offset?: number;
|
|
540
|
+
known_ids?: string[];
|
|
541
|
+
unknown_ids?: string[];
|
|
542
|
+
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
512
543
|
fetchEvents(body?: {
|
|
513
544
|
amt?: number;
|
|
514
545
|
known_ids?: string[];
|
|
@@ -318,6 +318,25 @@ export class AvroQueryClient {
|
|
|
318
318
|
throw new StandardError(500, 'Failed to fetch prepayments');
|
|
319
319
|
});
|
|
320
320
|
}
|
|
321
|
+
async fetchWaivers(body = {}, cancelToken, headers = {}) {
|
|
322
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
323
|
+
throw new StandardError(400, 'Company ID is required');
|
|
324
|
+
}
|
|
325
|
+
return this._fetch('POST', `/company/${this.companyId}/waivers`, JSON.stringify(body), cancelToken, {
|
|
326
|
+
...headers,
|
|
327
|
+
'Content-Type': 'application/json',
|
|
328
|
+
})
|
|
329
|
+
.then(response => {
|
|
330
|
+
if (!response || !Array.isArray(response)) {
|
|
331
|
+
throw new StandardError(400, 'Invalid waivers response');
|
|
332
|
+
}
|
|
333
|
+
return response;
|
|
334
|
+
})
|
|
335
|
+
.catch(err => {
|
|
336
|
+
console.error('Failed to fetch waivers:', err);
|
|
337
|
+
throw new StandardError(500, 'Failed to fetch waivers');
|
|
338
|
+
});
|
|
339
|
+
}
|
|
321
340
|
async fetchEvents(body = {}, cancelToken, headers = {}) {
|
|
322
341
|
if (!this.companyId || this.companyId.trim() === '') {
|
|
323
342
|
throw new StandardError(400, 'Company ID is required');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMutation } from '@tanstack/react-query';
|
|
1
|
+
import { useQuery, useMutation } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useCreateCatalogItem = function () {
|
|
4
4
|
const queryClient = this.getQueryClient();
|
|
@@ -67,6 +67,13 @@ AvroQueryClient.prototype.useUpdateCatalogItem = function () {
|
|
|
67
67
|
},
|
|
68
68
|
});
|
|
69
69
|
};
|
|
70
|
+
AvroQueryClient.prototype.useGetCatalogItem = function (catalogItemId) {
|
|
71
|
+
return useQuery({
|
|
72
|
+
queryKey: ['catalog_item', catalogItemId],
|
|
73
|
+
queryFn: () => this.get(`/catalog_item/${catalogItemId}`),
|
|
74
|
+
enabled: Boolean(catalogItemId),
|
|
75
|
+
});
|
|
76
|
+
};
|
|
70
77
|
AvroQueryClient.prototype.useDeleteCatalogItem = function () {
|
|
71
78
|
const queryClient = this.getQueryClient();
|
|
72
79
|
return useMutation({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
AvroQueryClient.prototype.useCreateWaiver = function () {
|
|
4
|
+
const queryClient = this.getQueryClient();
|
|
5
|
+
return useMutation({
|
|
6
|
+
mutationFn: async ({ waiverData }) => {
|
|
7
|
+
return this.post(`/company/${this.companyId}/waiver`, JSON.stringify(waiverData), undefined, {
|
|
8
|
+
"Content-Type": "application/json",
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
onSettled: () => {
|
|
12
|
+
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
13
|
+
queryClient.invalidateQueries({ queryKey: ['waivers'] });
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
AvroQueryClient.prototype.useGetWaivers = function (body, total, onProgress) {
|
|
18
|
+
return useQuery({
|
|
19
|
+
queryKey: ['waivers', this.companyId, body.amt ?? 50, body.known_ids ?? [], body.unknown_ids ?? [], body.offset ?? 0, body.query ?? "", total ?? "all"],
|
|
20
|
+
queryFn: async () => {
|
|
21
|
+
if (typeof total !== "number") {
|
|
22
|
+
return this.fetchWaivers({ ...body, offset: 0 });
|
|
23
|
+
}
|
|
24
|
+
onProgress?.(0);
|
|
25
|
+
const pageCount = body.amt ? Math.ceil(total / body.amt) + 1 : 1;
|
|
26
|
+
let completed = 0;
|
|
27
|
+
const promises = Array.from({ length: pageCount }, (_, i) => this.fetchWaivers({
|
|
28
|
+
...body,
|
|
29
|
+
offset: i * (body.amt ?? 1),
|
|
30
|
+
}));
|
|
31
|
+
const trackedPromises = promises.map((promise) => promise.then((result) => {
|
|
32
|
+
completed++;
|
|
33
|
+
const fraction = completed / pageCount;
|
|
34
|
+
onProgress?.(fraction);
|
|
35
|
+
return result;
|
|
36
|
+
}));
|
|
37
|
+
const pages = await Promise.all(trackedPromises);
|
|
38
|
+
const waivers = pages.flat();
|
|
39
|
+
return waivers;
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
AvroQueryClient.prototype.useUpdateWaiver = function () {
|
|
44
|
+
const queryClient = this.getQueryClient();
|
|
45
|
+
return useMutation({
|
|
46
|
+
mutationFn: async ({ waiverId, updates }) => {
|
|
47
|
+
return this.put(`/waiver/${waiverId}`, JSON.stringify(updates), undefined, {
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
onMutate: async ({ waiverId, updates }) => {
|
|
52
|
+
await queryClient.cancelQueries({ queryKey: ['waivers'] });
|
|
53
|
+
await queryClient.cancelQueries({ queryKey: ['waiver', waiverId] });
|
|
54
|
+
const previousWaivers = queryClient.getQueryData(['waivers']);
|
|
55
|
+
const previousWaiver = queryClient.getQueryData(['waiver', waiverId]);
|
|
56
|
+
queryClient.setQueryData(['waiver', waiverId], (oldData) => {
|
|
57
|
+
if (!oldData)
|
|
58
|
+
return oldData;
|
|
59
|
+
return { ...oldData, ...updates };
|
|
60
|
+
});
|
|
61
|
+
queryClient.setQueriesData({ queryKey: ['waivers'] }, (oldData) => {
|
|
62
|
+
if (!oldData)
|
|
63
|
+
return oldData;
|
|
64
|
+
if (oldData.pages) {
|
|
65
|
+
const updatedPages = oldData.pages.map((page) => page.map((waiver) => waiver.id === waiverId ? { ...waiver, ...updates } : waiver));
|
|
66
|
+
return { ...oldData, pages: updatedPages };
|
|
67
|
+
}
|
|
68
|
+
if (Array.isArray(oldData)) {
|
|
69
|
+
return oldData.map((waiver) => waiver.id === waiverId ? { ...waiver, ...updates } : waiver);
|
|
70
|
+
}
|
|
71
|
+
return oldData;
|
|
72
|
+
});
|
|
73
|
+
return { previousWaivers, previousWaiver };
|
|
74
|
+
},
|
|
75
|
+
onError: (_err, variables, context) => {
|
|
76
|
+
const { waiverId } = variables;
|
|
77
|
+
if (context?.previousWaivers) {
|
|
78
|
+
queryClient.setQueryData(['waivers'], context.previousWaivers);
|
|
79
|
+
}
|
|
80
|
+
if (context?.previousWaiver) {
|
|
81
|
+
queryClient.setQueryData(['waiver', waiverId], context.previousWaiver);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
onSettled: (_data, _error, variables) => {
|
|
85
|
+
const { waiverId } = variables;
|
|
86
|
+
queryClient.invalidateQueries({ queryKey: ['waivers'] });
|
|
87
|
+
queryClient.invalidateQueries({ queryKey: ['waiver', waiverId] });
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
AvroQueryClient.prototype.useDeleteWaiver = function () {
|
|
92
|
+
const queryClient = this.getQueryClient();
|
|
93
|
+
return useMutation({
|
|
94
|
+
mutationFn: async ({ waiverId }) => {
|
|
95
|
+
return this.delete(`/waiver/${waiverId}`);
|
|
96
|
+
},
|
|
97
|
+
onMutate: async ({ waiverId }) => {
|
|
98
|
+
await queryClient.cancelQueries({ queryKey: ['waivers'] });
|
|
99
|
+
const previousWaivers = queryClient.getQueryData(['waivers']);
|
|
100
|
+
queryClient.setQueriesData({ queryKey: ['waivers'] }, (oldData) => {
|
|
101
|
+
if (!oldData)
|
|
102
|
+
return oldData;
|
|
103
|
+
if (oldData.pages) {
|
|
104
|
+
const updatedPages = oldData.pages.map((page) => page.filter((waiver) => waiver.id !== waiverId));
|
|
105
|
+
return { ...oldData, pages: updatedPages };
|
|
106
|
+
}
|
|
107
|
+
if (Array.isArray(oldData)) {
|
|
108
|
+
return oldData.filter((waiver) => waiver.id !== waiverId);
|
|
109
|
+
}
|
|
110
|
+
return oldData;
|
|
111
|
+
});
|
|
112
|
+
return { previousWaivers };
|
|
113
|
+
},
|
|
114
|
+
onError: (_err, variables, context) => {
|
|
115
|
+
if (context?.previousWaivers) {
|
|
116
|
+
queryClient.setQueryData(['waivers'], context.previousWaivers);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
onSettled: () => {
|
|
120
|
+
queryClient.invalidateQueries({ queryKey: ['waivers'] });
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ import './client/hooks/labels';
|
|
|
26
26
|
import './client/hooks/groups';
|
|
27
27
|
import './client/hooks/skills';
|
|
28
28
|
import './client/hooks/proposal';
|
|
29
|
+
import './client/hooks/waivers';
|
|
29
30
|
export * from './types/api';
|
|
30
31
|
export * from './types/auth';
|
|
31
32
|
export * from './types/cache';
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import './client/hooks/labels';
|
|
|
26
26
|
import './client/hooks/groups';
|
|
27
27
|
import './client/hooks/skills';
|
|
28
28
|
import './client/hooks/proposal';
|
|
29
|
+
import './client/hooks/waivers';
|
|
29
30
|
export * from './types/api';
|
|
30
31
|
export * from './types/auth';
|
|
31
32
|
export * from './types/cache';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/api.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export * from "../types/api/Task";
|
|
|
34
34
|
export * from "../types/api/User";
|
|
35
35
|
export * from "../types/api/UserCompanyAssociation";
|
|
36
36
|
export * from "../types/api/UserEvent";
|
|
37
|
+
export * from "../types/api/Waiver";
|
|
37
38
|
export declare const LoginResponse: {
|
|
38
39
|
readonly SUCCESS: "SUCCESS";
|
|
39
40
|
readonly NEEDS_TOTP: "NEEDS_TOTP";
|
package/dist/types/api.js
CHANGED
|
@@ -34,6 +34,7 @@ export * from "../types/api/Task";
|
|
|
34
34
|
export * from "../types/api/User";
|
|
35
35
|
export * from "../types/api/UserCompanyAssociation";
|
|
36
36
|
export * from "../types/api/UserEvent";
|
|
37
|
+
export * from "../types/api/Waiver";
|
|
37
38
|
export const LoginResponse = {
|
|
38
39
|
SUCCESS: "SUCCESS",
|
|
39
40
|
NEEDS_TOTP: "NEEDS_TOTP",
|