@go-avro/avro-js 0.0.4-beta.2 → 0.0.4-beta.20

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.
Files changed (91) hide show
  1. package/dist/auth/AuthManager.d.ts +2 -2
  2. package/dist/client/QueryClient.d.ts +54 -2
  3. package/dist/client/QueryClient.js +29 -7
  4. package/dist/client/hooks/bills.js +1 -0
  5. package/dist/client/hooks/catalog_items.js +8 -1
  6. package/dist/client/hooks/jobs.js +8 -1
  7. package/dist/client/hooks/prepayments.js +60 -1
  8. package/dist/client/hooks/proposal.js +8 -1
  9. package/dist/client/hooks/users.js +15 -1
  10. package/dist/client/hooks/waivers.d.ts +1 -0
  11. package/dist/client/hooks/waivers.js +123 -0
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.js +1 -0
  14. package/dist/types/api/AdditionalCharge.d.ts +5 -0
  15. package/dist/types/api/AdditionalCharge.js +1 -0
  16. package/dist/types/api/Avro.d.ts +11 -0
  17. package/dist/types/api/Avro.js +1 -0
  18. package/dist/types/api/Bill.d.ts +27 -0
  19. package/dist/types/api/Bill.js +1 -0
  20. package/dist/types/api/BillPayment.d.ts +13 -0
  21. package/dist/types/api/BillPayment.js +1 -0
  22. package/dist/types/api/BillUser.d.ts +11 -0
  23. package/dist/types/api/BillUser.js +1 -0
  24. package/dist/types/api/Break.d.ts +7 -0
  25. package/dist/types/api/Break.js +1 -0
  26. package/dist/types/api/CatalogItem.d.ts +16 -0
  27. package/dist/types/api/CatalogItem.js +1 -0
  28. package/dist/types/api/Chat.d.ts +12 -0
  29. package/dist/types/api/Chat.js +1 -0
  30. package/dist/types/api/Company.d.ts +58 -0
  31. package/dist/types/api/Company.js +1 -0
  32. package/dist/types/api/CustomLineItem.d.ts +4 -0
  33. package/dist/types/api/CustomLineItem.js +1 -0
  34. package/dist/types/api/Email.d.ts +21 -0
  35. package/dist/types/api/Email.js +1 -0
  36. package/dist/types/api/Friendship.d.ts +2 -0
  37. package/dist/types/api/Friendship.js +1 -0
  38. package/dist/types/api/Group.d.ts +12 -0
  39. package/dist/types/api/Group.js +1 -0
  40. package/dist/types/api/Job.d.ts +29 -0
  41. package/dist/types/api/Job.js +1 -0
  42. package/dist/types/api/Label.d.ts +7 -0
  43. package/dist/types/api/Label.js +1 -0
  44. package/dist/types/api/LineItem.d.ts +41 -0
  45. package/dist/types/api/LineItem.js +30 -0
  46. package/dist/types/api/MemberState.d.ts +7 -0
  47. package/dist/types/api/MemberState.js +1 -0
  48. package/dist/types/api/Message.d.ts +13 -0
  49. package/dist/types/api/Message.js +1 -0
  50. package/dist/types/api/PaymentMethod.d.ts +51 -0
  51. package/dist/types/api/PaymentMethod.js +1 -0
  52. package/dist/types/api/PaymentOption.d.ts +9 -0
  53. package/dist/types/api/PaymentOption.js +1 -0
  54. package/dist/types/api/PaymentType.d.ts +5 -0
  55. package/dist/types/api/PaymentType.js +5 -0
  56. package/dist/types/api/Plan.d.ts +13 -0
  57. package/dist/types/api/Plan.js +1 -0
  58. package/dist/types/api/PlanPayment.d.ts +10 -0
  59. package/dist/types/api/PlanPayment.js +1 -0
  60. package/dist/types/api/Prepayment.d.ts +15 -0
  61. package/dist/types/api/Prepayment.js +7 -0
  62. package/dist/types/api/Reaction.d.ts +8 -0
  63. package/dist/types/api/Reaction.js +1 -0
  64. package/dist/types/api/Route.d.ts +34 -0
  65. package/dist/types/api/Route.js +49 -0
  66. package/dist/types/api/RouteJob.d.ts +15 -0
  67. package/dist/types/api/RouteJob.js +5 -0
  68. package/dist/types/api/ServiceMonth.d.ts +7 -0
  69. package/dist/types/api/ServiceMonth.js +1 -0
  70. package/dist/types/api/Session.d.ts +13 -0
  71. package/dist/types/api/Session.js +1 -0
  72. package/dist/types/api/Skill.d.ts +7 -0
  73. package/dist/types/api/Skill.js +1 -0
  74. package/dist/types/api/Subscription.d.ts +8 -0
  75. package/dist/types/api/Subscription.js +1 -0
  76. package/dist/types/api/Task.d.ts +56 -0
  77. package/dist/types/api/Task.js +59 -0
  78. package/dist/types/api/User.d.ts +23 -0
  79. package/dist/types/api/User.js +1 -0
  80. package/dist/types/api/UserCompanyAssociation.d.ts +71 -0
  81. package/dist/types/api/UserCompanyAssociation.js +53 -0
  82. package/dist/types/api/UserEvent.d.ts +13 -0
  83. package/dist/types/api/UserEvent.js +1 -0
  84. package/dist/types/api/Waiver.d.ts +9 -0
  85. package/dist/types/api/Waiver.js +1 -0
  86. package/dist/types/api/_Event.d.ts +19 -0
  87. package/dist/types/api/_Event.js +1 -0
  88. package/dist/types/api.d.ts +41 -587
  89. package/dist/types/api.js +37 -74
  90. package/dist/types/cache.d.ts +2 -2
  91. package/package.json +1 -1
@@ -16,8 +16,8 @@ export declare class AuthManager {
16
16
  onTokenRefreshFailed(callback: () => void): void;
17
17
  refreshTokens(): Promise<Tokens>;
18
18
  setTokens(tokens: Tokens): Promise<void>;
19
- setCache(data: Partial<CacheData>): Promise<void>;
20
- getCache(key?: keyof CacheData): Promise<CacheData | string | null>;
19
+ setCache(data: Partial<CacheData> | Object): Promise<void>;
20
+ getCache(key?: keyof CacheData | string): Promise<CacheData[keyof CacheData] | Object | string | null>;
21
21
  clearCache(): Promise<void>;
22
22
  getCompanyId(): Promise<string | undefined>;
23
23
  setCompanyId(companyId: string): Promise<void[]>;
@@ -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, {
@@ -213,10 +226,24 @@ declare module '../client/QueryClient' {
213
226
  useCreateSelf(): ReturnType<typeof useMutation<{
214
227
  msg: string;
215
228
  id?: string;
229
+ access_token?: string;
230
+ refresh_token?: string;
216
231
  }, StandardError, Partial<User> & {
217
232
  code?: string;
218
233
  invite_token?: string;
219
234
  password?: string;
235
+ company_id?: string;
236
+ }>>;
237
+ useCreateUser(): ReturnType<typeof useMutation<{
238
+ msg: string;
239
+ id?: string;
240
+ access_token?: string;
241
+ refresh_token?: string;
242
+ }, StandardError, Partial<User> & {
243
+ code?: string;
244
+ invite_token?: string;
245
+ password?: string;
246
+ company_id?: string;
220
247
  }>>;
221
248
  useCreateSessionBreak(): ReturnType<typeof useMutation<{
222
249
  id: string;
@@ -261,6 +288,12 @@ declare module '../client/QueryClient' {
261
288
  labelId: string;
262
289
  labelData: Partial<Label>;
263
290
  }>>;
291
+ useUpdateWaiver(): ReturnType<typeof useMutation<{
292
+ msg: string;
293
+ }, StandardError, {
294
+ waiverId: string;
295
+ updates: Partial<Waiver>;
296
+ }>>;
264
297
  useUpdateCatalogItem(): ReturnType<typeof useMutation<{
265
298
  msg: string;
266
299
  }, StandardError, {
@@ -309,6 +342,12 @@ declare module '../client/QueryClient' {
309
342
  })[];
310
343
  action: "billed" | "paid";
311
344
  }>>;
345
+ useUpdatePrepayments(): ReturnType<typeof useMutation<void, StandardError, {
346
+ prepayments: (Prepayment & {
347
+ page?: number;
348
+ })[];
349
+ action: "billed" | "paid";
350
+ }>>;
312
351
  useUpdateUserCompany(): ReturnType<typeof useMutation<{
313
352
  msg: string;
314
353
  }, StandardError, {
@@ -363,6 +402,11 @@ declare module '../client/QueryClient' {
363
402
  }, StandardError, {
364
403
  groupId: string;
365
404
  }>>;
405
+ useDeleteWaiver(): ReturnType<typeof useMutation<{
406
+ msg: string;
407
+ }, StandardError, {
408
+ waiverId: string;
409
+ }>>;
366
410
  useDeleteLabel(): ReturnType<typeof useMutation<{
367
411
  msg: string;
368
412
  }, StandardError, {
@@ -418,6 +462,7 @@ export declare class AvroQueryClient {
418
462
  post<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
419
463
  put<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
420
464
  delete<T>(path: string, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
465
+ loginSuccess(tokens: Tokens): Promise<void>;
421
466
  useLogin(): ReturnType<typeof useMutation<LoginResponse, StandardError, {
422
467
  username: string;
423
468
  password?: string;
@@ -443,8 +488,8 @@ export declare class AvroQueryClient {
443
488
  cancelToken?: CancelToken;
444
489
  }>>;
445
490
  setTokens(tokens: Tokens): Promise<void>;
446
- setCache(data: Partial<CacheData>): Promise<void>;
447
- getCache(key?: keyof CacheData | undefined): Promise<CacheData | string | null>;
491
+ setCache(data: Partial<CacheData> | Object): Promise<void>;
492
+ getCache(key?: keyof CacheData | string): Promise<CacheData[keyof CacheData] | Object | string | null>;
448
493
  setCompanyId(companyId: string): Promise<void[]>;
449
494
  getCompanyId(): Promise<string | undefined>;
450
495
  clearCache(): Promise<void>;
@@ -488,6 +533,13 @@ export declare class AvroQueryClient {
488
533
  paid?: boolean;
489
534
  taskId?: string | null;
490
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>;
491
543
  fetchEvents(body?: {
492
544
  amt?: number;
493
545
  known_ids?: string[];
@@ -82,6 +82,14 @@ export class AvroQueryClient {
82
82
  delete(path, cancelToken, headers = {}, progressUpdateCallback) {
83
83
  return this._xhr('DELETE', path, null, cancelToken, headers, false, this.config.maxRetries, progressUpdateCallback);
84
84
  }
85
+ loginSuccess(tokens) {
86
+ this.setAuthState(AuthState.AUTHENTICATED);
87
+ this.socket.auth = { token: tokens.access_token };
88
+ if (!this.socket.connected) {
89
+ this.socket.connect();
90
+ }
91
+ return this.config.authManager.setTokens(tokens);
92
+ }
85
93
  useLogin() {
86
94
  const queryClient = this.getQueryClient();
87
95
  return useMutation({
@@ -93,12 +101,7 @@ export class AvroQueryClient {
93
101
  }
94
102
  throw new StandardError(401, 'Invalid login response');
95
103
  }
96
- this.setAuthState(AuthState.AUTHENTICATED);
97
- this.socket.auth = { token: resp.access_token };
98
- if (!this.socket.connected) {
99
- this.socket.connect();
100
- }
101
- await this.config.authManager.setTokens({ access_token: resp.access_token, refresh_token: resp.refresh_token });
104
+ await this.loginSuccess({ access_token: resp.access_token, refresh_token: resp.refresh_token });
102
105
  return LoginResponse.SUCCESS;
103
106
  },
104
107
  onSettled: () => {
@@ -173,7 +176,7 @@ export class AvroQueryClient {
173
176
  setCache(data) {
174
177
  return this.config.authManager.setCache(data);
175
178
  }
176
- getCache(key) {
179
+ async getCache(key) {
177
180
  return this.config.authManager.getCache(key);
178
181
  }
179
182
  setCompanyId(companyId) {
@@ -315,6 +318,25 @@ export class AvroQueryClient {
315
318
  throw new StandardError(500, 'Failed to fetch prepayments');
316
319
  });
317
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
+ }
318
340
  async fetchEvents(body = {}, cancelToken, headers = {}) {
319
341
  if (!this.companyId || this.companyId.trim() === '') {
320
342
  throw new StandardError(400, 'Company ID is required');
@@ -45,6 +45,7 @@ AvroQueryClient.prototype.useCreateBill = function () {
45
45
  line_items: data.line_items ?? [],
46
46
  manual_emails: data.manual_emails ?? [],
47
47
  prepayments: data.prepayments ?? [],
48
+ enabled_payment_methods: data.enabled_payment_methods ?? [],
48
49
  users: data.users,
49
50
  due_date: data.due_date,
50
51
  };
@@ -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({
@@ -1,5 +1,6 @@
1
1
  import { useMutation, useQuery, useInfiniteQuery } from '@tanstack/react-query';
2
2
  import { AvroQueryClient } from '../../client/QueryClient';
3
+ import { Task } from '../../types/api';
3
4
  AvroQueryClient.prototype.getJobsFromCache = function (queryClient) {
4
5
  if (!queryClient) {
5
6
  queryClient = this.getQueryClient();
@@ -27,6 +28,7 @@ AvroQueryClient.prototype.useGetJobs = function (params) {
27
28
  const pages = await Promise.all(trackedPromises);
28
29
  const jobs = pages.flat();
29
30
  jobs.forEach((job) => {
31
+ job.tasks = job.tasks.map((task) => new Task(task));
30
32
  job.current_event = job.tasks.reduce((latest, task) => {
31
33
  return task.current_event && (!latest || task.current_event.time_started > latest.time_started) ? task.current_event : latest;
32
34
  }, job.current_event);
@@ -64,6 +66,7 @@ AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
64
66
  if (result.data) {
65
67
  result.data.pages.forEach((data_page) => {
66
68
  data_page.forEach((job) => {
69
+ job.tasks = job.tasks.map((task) => new Task(task));
67
70
  job.overdue_time = (job.tasks || []).reduce((maxOverdue, task) => {
68
71
  return (task.overdue_time && task.overdue_time > maxOverdue) ? task.overdue_time : maxOverdue;
69
72
  }, 0);
@@ -76,7 +79,11 @@ AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
76
79
  AvroQueryClient.prototype.useGetJob = function (jobId) {
77
80
  return useQuery({
78
81
  queryKey: ['job', jobId],
79
- queryFn: () => this.get(`/job/${jobId}`),
82
+ queryFn: async () => {
83
+ const job = await this.get(`/job/${jobId}`);
84
+ job.tasks = job.tasks.map((task) => new Task(task));
85
+ return job;
86
+ },
80
87
  enabled: Boolean(jobId),
81
88
  });
82
89
  };
@@ -1,5 +1,6 @@
1
- import { useInfiniteQuery } from '@tanstack/react-query';
1
+ import { useInfiniteQuery, useMutation } from '@tanstack/react-query';
2
2
  import { AvroQueryClient } from '../../client/QueryClient';
3
+ import { LineItemStatus } from '../../types/api';
3
4
  AvroQueryClient.prototype.useGetPrepayments = function (body) {
4
5
  const queryClient = this.getQueryClient();
5
6
  const result = useInfiniteQuery({
@@ -34,3 +35,61 @@ AvroQueryClient.prototype.useGetPrepayments = function (body) {
34
35
  }
35
36
  return result;
36
37
  };
38
+ AvroQueryClient.prototype.useUpdatePrepayments = function () {
39
+ const queryClient = this.getQueryClient();
40
+ return useMutation({
41
+ mutationFn: async ({ prepayments, action, }) => {
42
+ const prepaymentIds = prepayments.map(prepayment => prepayment.id);
43
+ return this.put(`/company/${this.companyId}/prepayments`, JSON.stringify({
44
+ prepayments: prepaymentIds,
45
+ status: action === "billed" ? LineItemStatus.EXTERNALLY_BILLED : LineItemStatus.EXTERNALLY_PAID,
46
+ }), undefined, {
47
+ "Content-Type": "application/json",
48
+ });
49
+ },
50
+ onMutate: async ({ prepayments, action }) => {
51
+ await queryClient.cancelQueries({ queryKey: ['prepayments'] });
52
+ await queryClient.cancelQueries({ queryKey: ['prepayment'] });
53
+ const previousPrepayments = queryClient.getQueryData(['prepayments']);
54
+ const previousPrepaymentObjs = prepayments.map(prepayment => queryClient.getQueryData(['prepayment', prepayment.id]));
55
+ const prepaymentIds = prepayments.map(prepayment => prepayment.id);
56
+ prepaymentIds.forEach((prepaymentId, idx) => {
57
+ queryClient.setQueryData(['prepayment', prepaymentId], (oldData) => {
58
+ return oldData
59
+ ? { ...oldData, status: action === "billed" ? LineItemStatus.EXTERNALLY_BILLED : LineItemStatus.EXTERNALLY_PAID }
60
+ : oldData;
61
+ });
62
+ });
63
+ queryClient.setQueriesData({ queryKey: ['prepayments'] }, (oldData) => {
64
+ if (!oldData)
65
+ return oldData;
66
+ if (oldData.pages) {
67
+ const updatedPages = oldData.pages.map((page) => page.map((prepayment) => prepaymentIds.includes(prepayment.id)
68
+ ? { ...prepayment, status: action === "billed" ? LineItemStatus.EXTERNALLY_BILLED : LineItemStatus.EXTERNALLY_PAID }
69
+ : prepayment));
70
+ return { ...oldData, pages: updatedPages };
71
+ }
72
+ if (Array.isArray(oldData)) {
73
+ return oldData.map((prepayment) => prepaymentIds.includes(prepayment.id)
74
+ ? { ...prepayment, status: action === "billed" ? LineItemStatus.EXTERNALLY_BILLED : LineItemStatus.EXTERNALLY_PAID }
75
+ : prepayment);
76
+ }
77
+ return oldData;
78
+ });
79
+ return { previousPrepayments, previousPrepaymentObjs };
80
+ },
81
+ onError: (err, variables, context) => {
82
+ if (context) {
83
+ queryClient.setQueryData(['prepayments'], context.previousPrepayments);
84
+ context.previousPrepaymentObjs.forEach((prepaymentObj) => {
85
+ queryClient.setQueryData(['prepayment', prepaymentObj.id], prepaymentObj);
86
+ });
87
+ }
88
+ },
89
+ onSettled: () => {
90
+ queryClient.invalidateQueries({ queryKey: ['prepayments'] });
91
+ queryClient.invalidateQueries({ queryKey: ['prepayment'] });
92
+ queryClient.invalidateQueries({ queryKey: ['company'] });
93
+ },
94
+ });
95
+ };
@@ -1,5 +1,6 @@
1
1
  import { useMutation, useQuery } from "@tanstack/react-query";
2
2
  import { AvroQueryClient } from "../../client/QueryClient";
3
+ import { Task } from "../../types/api/Task";
3
4
  AvroQueryClient.prototype.useCreateProposal = function () {
4
5
  return useMutation({
5
6
  mutationFn: async ({ job_id, data }) => {
@@ -17,6 +18,12 @@ AvroQueryClient.prototype.useAcceptProposal = function (proposal_id) {
17
18
  AvroQueryClient.prototype.useGetProposal = function (proposal_id) {
18
19
  return useQuery({
19
20
  queryKey: ['proposal', proposal_id],
20
- queryFn: async () => this.get(`/proposal/${proposal_id}`),
21
+ queryFn: async () => {
22
+ const proposal = await this.get(`/proposal/${proposal_id}`);
23
+ if (proposal && Array.isArray(proposal.tasks)) {
24
+ proposal.tasks = proposal.tasks.map((task) => new Task(task));
25
+ }
26
+ return proposal;
27
+ },
21
28
  });
22
29
  };
@@ -32,7 +32,21 @@ AvroQueryClient.prototype.useCreateSelf = function () {
32
32
  mutationFn: async (data) => {
33
33
  return this.post('/user', JSON.stringify(data), undefined, { "Content-Type": "application/json" });
34
34
  },
35
- onSettled: () => {
35
+ onSettled: (data) => {
36
+ queryClient.invalidateQueries({ queryKey: ['user'] });
37
+ if (data?.access_token && data?.refresh_token) {
38
+ return this.loginSuccess({ access_token: data.access_token, refresh_token: data.refresh_token });
39
+ }
40
+ },
41
+ });
42
+ };
43
+ AvroQueryClient.prototype.useCreateUser = function () {
44
+ const queryClient = this.getQueryClient();
45
+ return useMutation({
46
+ mutationFn: async (data) => {
47
+ return this.post('/user', JSON.stringify(data), undefined, { "Content-Type": "application/json" });
48
+ },
49
+ onSettled: (data) => {
36
50
  queryClient.invalidateQueries({ queryKey: ['user'] });
37
51
  },
38
52
  });
@@ -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,5 @@
1
+ import { LineItem } from "../../types/api/LineItem";
2
+ export interface AdditionalCharge extends LineItem {
3
+ line_item_type: "ADDITIONAL_CHARGE";
4
+ time_updated: number | null;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { Email } from "../../types/api/Email";
2
+ export interface Avro {
3
+ id: string;
4
+ name: string;
5
+ time_created: number;
6
+ time_updated: number;
7
+ emails: Email[];
8
+ totp_email_id: string;
9
+ billing_email_id: string;
10
+ join_email_id: string;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import { BillPayment } from "../../types/api/BillPayment";
2
+ import { BillUser } from "../../types/api/BillUser";
3
+ import { CustomLineItem } from "../../types/api/CustomLineItem";
4
+ import { PaymentType } from "../../types/api/PaymentType";
5
+ export interface Bill {
6
+ id: string;
7
+ invoice_id: number;
8
+ intuit_id: string | null;
9
+ name: string;
10
+ amount: number;
11
+ billed_by: string;
12
+ customer_email: string | null;
13
+ manual_emails: string[][];
14
+ users: BillUser[];
15
+ status: "SENT" | "PAID" | "PARTIALLY_PAID" | "MANUALLY_PAID";
16
+ enabled_payment_methods: PaymentType[];
17
+ time_created: number;
18
+ time_updated: number;
19
+ events: string[];
20
+ intent_created_at: number;
21
+ intent_last_created_at: number;
22
+ payments: BillPayment[];
23
+ line_items: CustomLineItem[];
24
+ prepayments: string[];
25
+ months: string[];
26
+ due_date: number;
27
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ export interface BillPayment {
2
+ id: string;
3
+ amount: number;
4
+ avro_fees: number;
5
+ stripe_fees: number;
6
+ stripe_pi_id: string;
7
+ bill_user_id: string;
8
+ status: "created" | "processing" | "succeeded" | "failed" | "canceled" | "requires_action";
9
+ type: "us_bank_account" | "card";
10
+ action_required_at: number;
11
+ time_created: number;
12
+ time_updated: number | null;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { BillPayment } from "../../types/api/BillPayment";
2
+ export interface BillUser {
3
+ id: string;
4
+ user_id: string;
5
+ bill_id: string;
6
+ invoice_id: string;
7
+ payment_attempts: BillPayment[];
8
+ time_created: number;
9
+ time_updated: number | null;
10
+ amount: number;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export interface Break {
2
+ id: string;
3
+ time_started: number;
4
+ time_ended: number;
5
+ company_billable: boolean;
6
+ client_billable: boolean;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { PaymentOption } from "../../types/api/PaymentOption";
2
+ export interface CatalogItem {
3
+ id: string;
4
+ name: string;
5
+ company_id: string;
6
+ description: string;
7
+ industry: string;
8
+ price_format: string;
9
+ payment_options: PaymentOption[];
10
+ recommended_frequency?: number | null;
11
+ recommended_activate_on?: number | null;
12
+ recommended_expire_on?: number | null;
13
+ time_created: number;
14
+ time_updated: number | null;
15
+ skills: string[];
16
+ }
@@ -0,0 +1 @@
1
+ export {};