@go-avro/avro-js 0.0.42 → 0.0.44

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 (83) hide show
  1. package/dist/auth/AuthManager.d.ts +3 -3
  2. package/dist/auth/AuthManager.js +24 -24
  3. package/dist/auth/storage.d.ts +1 -1
  4. package/dist/auth/storage.js +3 -3
  5. package/dist/client/AvroQueryClientProvider.d.ts +4 -4
  6. package/dist/client/AvroQueryClientProvider.js +3 -3
  7. package/dist/client/QueryClient.d.ts +15 -15
  8. package/dist/client/QueryClient.js +239 -259
  9. package/dist/client/core/fetch.js +9 -9
  10. package/dist/client/core/utils.js +4 -4
  11. package/dist/client/core/xhr.js +21 -21
  12. package/dist/client/hooks/analytics.js +12 -12
  13. package/dist/client/hooks/avro.js +4 -4
  14. package/dist/client/hooks/bills.js +36 -39
  15. package/dist/client/hooks/catalog_items.js +25 -31
  16. package/dist/client/hooks/chats.js +6 -6
  17. package/dist/client/hooks/companies.js +45 -57
  18. package/dist/client/hooks/email.d.ts +3 -3
  19. package/dist/client/hooks/email.js +5 -5
  20. package/dist/client/hooks/events.js +71 -81
  21. package/dist/client/hooks/groups.js +25 -31
  22. package/dist/client/hooks/jobs.js +29 -34
  23. package/dist/client/hooks/labels.js +25 -31
  24. package/dist/client/hooks/messages.js +7 -7
  25. package/dist/client/hooks/months.js +21 -21
  26. package/dist/client/hooks/plans.js +4 -4
  27. package/dist/client/hooks/prepayments.js +21 -21
  28. package/dist/client/hooks/proposal.js +11 -11
  29. package/dist/client/hooks/root.js +4 -4
  30. package/dist/client/hooks/routes.js +42 -53
  31. package/dist/client/hooks/sessions.js +33 -45
  32. package/dist/client/hooks/skills.js +22 -28
  33. package/dist/client/hooks/teams.js +26 -32
  34. package/dist/client/hooks/timecards.js +13 -13
  35. package/dist/client/hooks/users.js +39 -42
  36. package/dist/client/hooks/waivers.js +23 -23
  37. package/dist/index.d.ts +38 -38
  38. package/dist/index.js +37 -37
  39. package/dist/types/api/AdditionalCharge.d.ts +2 -2
  40. package/dist/types/api/Avro.d.ts +1 -1
  41. package/dist/types/api/Bill.d.ts +4 -4
  42. package/dist/types/api/Bill.js +4 -4
  43. package/dist/types/api/BillPayment.d.ts +2 -2
  44. package/dist/types/api/BillUser.d.ts +1 -1
  45. package/dist/types/api/CatalogItem.d.ts +1 -1
  46. package/dist/types/api/Chat.d.ts +2 -2
  47. package/dist/types/api/Company.d.ts +12 -12
  48. package/dist/types/api/CustomLineItem.d.ts +2 -2
  49. package/dist/types/api/Email.d.ts +2 -2
  50. package/dist/types/api/EmailNotification.d.ts +2 -2
  51. package/dist/types/api/Group.d.ts +1 -1
  52. package/dist/types/api/Job.d.ts +6 -6
  53. package/dist/types/api/Job.js +12 -12
  54. package/dist/types/api/LineItem.d.ts +1 -1
  55. package/dist/types/api/LineItem.js +12 -12
  56. package/dist/types/api/MemberState.d.ts +1 -1
  57. package/dist/types/api/Message.d.ts +1 -1
  58. package/dist/types/api/PaymentMethod.d.ts +1 -1
  59. package/dist/types/api/PaymentOption.d.ts +1 -1
  60. package/dist/types/api/PaymentType.js +2 -2
  61. package/dist/types/api/PlanPayment.d.ts +1 -1
  62. package/dist/types/api/Prepayment.d.ts +4 -4
  63. package/dist/types/api/Prepayment.js +1 -1
  64. package/dist/types/api/Route.d.ts +2 -2
  65. package/dist/types/api/Route.js +7 -7
  66. package/dist/types/api/RouteJob.d.ts +1 -1
  67. package/dist/types/api/ServiceMonth.d.ts +2 -2
  68. package/dist/types/api/Session.d.ts +2 -2
  69. package/dist/types/api/Task.d.ts +7 -7
  70. package/dist/types/api/Task.js +20 -22
  71. package/dist/types/api/Timecard.d.ts +1 -1
  72. package/dist/types/api/Timecard.js +4 -4
  73. package/dist/types/api/TimecardAction.js +6 -6
  74. package/dist/types/api/User.d.ts +4 -4
  75. package/dist/types/api/UserCompanyAssociation.d.ts +2 -2
  76. package/dist/types/api/UserCompanyAssociation.js +45 -45
  77. package/dist/types/api/_Event.d.ts +5 -5
  78. package/dist/types/api/_Event.js +1 -1
  79. package/dist/types/api.d.ts +44 -44
  80. package/dist/types/api.js +42 -42
  81. package/dist/types/cache.d.ts +1 -1
  82. package/dist/types/client.d.ts +1 -1
  83. package/package.json +2 -1
@@ -1,11 +1,11 @@
1
- import { AvroQueryClient } from "../../client/QueryClient";
2
- import { StandardError } from "../../types/error";
3
- import { AuthState } from "../../types/auth";
1
+ import { AvroQueryClient } from '../../client/QueryClient';
2
+ import { StandardError } from '../../types/error';
3
+ import { AuthState } from '../../types/auth';
4
4
  AvroQueryClient.prototype._fetch = async function (method, path, body, cancelToken, headers = {}, isIdempotent = false, retryCount = 0) {
5
5
  const checkCancelled = () => {
6
6
  try {
7
7
  if (cancelToken?.isCancelled()) {
8
- throw new StandardError(0, "Request cancelled");
8
+ throw new StandardError(0, 'Request cancelled');
9
9
  }
10
10
  }
11
11
  catch (error) {
@@ -30,9 +30,9 @@ AvroQueryClient.prototype._fetch = async function (method, path, body, cancelTok
30
30
  };
31
31
  const response = await fetch(url, options);
32
32
  if (response.ok) {
33
- const contentType = response.headers.get("content-type") ?? "";
34
- if (contentType.includes("application/pdf") ||
35
- contentType.includes("application/octet-stream")) {
33
+ const contentType = response.headers.get('content-type') ?? '';
34
+ if (contentType.includes('application/pdf') ||
35
+ contentType.includes('application/octet-stream')) {
36
36
  return response.blob();
37
37
  }
38
38
  const text = await response.text();
@@ -59,7 +59,7 @@ AvroQueryClient.prototype._fetch = async function (method, path, body, cancelTok
59
59
  errorMessage = parsedError.message ?? parsedError.msg ?? errorMessage;
60
60
  }
61
61
  catch (e) {
62
- console.error("Ignoring:", e);
62
+ console.error('Ignoring:', e);
63
63
  }
64
64
  throw new StandardError(response.status, errorMessage);
65
65
  }
@@ -68,7 +68,7 @@ AvroQueryClient.prototype._fetch = async function (method, path, body, cancelTok
68
68
  throw error;
69
69
  }
70
70
  const message = error instanceof Error ? error.message : String(error);
71
- console.error("Fetch error:", message);
71
+ console.error('Fetch error:', message);
72
72
  throw new StandardError(0, `Request failed: ${message}`);
73
73
  }
74
74
  };
@@ -1,12 +1,12 @@
1
- import { AvroQueryClient } from "../../client/QueryClient";
1
+ import { AvroQueryClient } from '../../client/QueryClient';
2
2
  AvroQueryClient.prototype.getDelay = function (strategy, attempt) {
3
- if (typeof strategy === "function") {
3
+ if (typeof strategy === 'function') {
4
4
  return strategy(attempt);
5
5
  }
6
- else if (strategy === "fixed") {
6
+ else if (strategy === 'fixed') {
7
7
  return 1000;
8
8
  }
9
- else if (strategy === "exponential") {
9
+ else if (strategy === 'exponential') {
10
10
  return Math.pow(2, attempt) * 100;
11
11
  }
12
12
  throw new Error(`Invalid retry strategy: ${strategy}`);
@@ -1,10 +1,10 @@
1
- import { AvroQueryClient } from "../../client/QueryClient";
2
- import { StandardError } from "../../types/error";
3
- import { AuthState } from "../../types/auth";
1
+ import { AvroQueryClient } from '../../client/QueryClient';
2
+ import { StandardError } from '../../types/error';
3
+ import { AuthState } from '../../types/auth';
4
4
  AvroQueryClient.prototype._xhr = async function (method, path, body, cancelToken, headers = {}, isIdempotent = false, retryCount = 0, progressUpdateCallback) {
5
5
  const checkCancelled = () => {
6
6
  if (cancelToken?.isCancelled()) {
7
- throw new StandardError(0, "Request cancelled");
7
+ throw new StandardError(0, 'Request cancelled');
8
8
  }
9
9
  };
10
10
  for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
@@ -19,14 +19,14 @@ AvroQueryClient.prototype._xhr = async function (method, path, body, cancelToken
19
19
  const url = this.config.baseUrl + path;
20
20
  xhr.open(method, url, true);
21
21
  if (token)
22
- xhr.setRequestHeader("Authorization", `Bearer ${token}`);
22
+ xhr.setRequestHeader('Authorization', `Bearer ${token}`);
23
23
  Object.entries(headers).forEach(([key, value]) => xhr.setRequestHeader(key, value));
24
24
  xhr.onload = () => {
25
25
  if (xhr.status >= 200 && xhr.status < 300) {
26
26
  try {
27
- const contentType = xhr.getResponseHeader("content-type") || "";
28
- if (contentType.includes("application/pdf") ||
29
- contentType.includes("application/octet-stream")) {
27
+ const contentType = xhr.getResponseHeader('content-type') || '';
28
+ if (contentType.includes('application/pdf') ||
29
+ contentType.includes('application/octet-stream')) {
30
30
  resolve(new Blob([xhr.response], { type: contentType }));
31
31
  return;
32
32
  }
@@ -47,15 +47,15 @@ AvroQueryClient.prototype._xhr = async function (method, path, body, cancelToken
47
47
  msg = parsed.message ?? parsed.msg ?? msg;
48
48
  }
49
49
  catch (e) {
50
- console.error("Ignoring:", e);
50
+ console.error('Ignoring:', e);
51
51
  }
52
52
  reject(new StandardError(xhr.status, msg));
53
53
  }
54
54
  };
55
- xhr.onerror = () => reject(new StandardError(0, "Network Error"));
55
+ xhr.onerror = () => reject(new StandardError(0, 'Network Error'));
56
56
  if (this.config.timeout) {
57
57
  xhr.timeout = this.config.timeout;
58
- xhr.ontimeout = () => reject(new StandardError(0, "Request timed out"));
58
+ xhr.ontimeout = () => reject(new StandardError(0, 'Request timed out'));
59
59
  }
60
60
  if (progressUpdateCallback && xhr.upload) {
61
61
  xhr.upload.onprogress = (event) => {
@@ -65,37 +65,37 @@ AvroQueryClient.prototype._xhr = async function (method, path, body, cancelToken
65
65
  };
66
66
  }
67
67
  // Set responseType to 'blob' if expecting binary
68
- const contentType = headers["Content-Type"] || "";
69
- if (contentType.includes("application/pdf") ||
70
- contentType.includes("application/octet-stream")) {
71
- xhr.responseType = "blob";
68
+ const contentType = headers['Content-Type'] || '';
69
+ if (contentType.includes('application/pdf') ||
70
+ contentType.includes('application/octet-stream')) {
71
+ xhr.responseType = 'blob';
72
72
  }
73
73
  xhr.send(body);
74
74
  });
75
75
  return result;
76
76
  }
77
77
  catch (error) {
78
- console.error("xhr error:", error);
78
+ console.error('xhr error:', error);
79
79
  if (!(error instanceof StandardError)) {
80
80
  const message = error instanceof Error ? error.message : String(error);
81
- console.error("Non-StandardError caught:", message);
81
+ console.error('Non-StandardError caught:', message);
82
82
  throw new StandardError(0, `An unexpected error occurred: ${message}`);
83
83
  }
84
84
  if (error.status === 401 &&
85
85
  this.config.authManager.refreshTokens &&
86
86
  attempt === 0 &&
87
87
  this.getAuthState() === AuthState.AUTHENTICATED) {
88
- console.log("Attempting to refresh tokens due to 401 response");
88
+ console.log('Attempting to refresh tokens due to 401 response');
89
89
  try {
90
90
  await this.config.authManager.refreshTokens();
91
91
  continue;
92
92
  }
93
93
  catch (refreshError) {
94
- throw new StandardError(401, "Unauthorized (refresh failed)");
94
+ throw new StandardError(401, 'Unauthorized (refresh failed)');
95
95
  }
96
96
  }
97
97
  if (error.status === 401 || attempt >= this.config.maxRetries) {
98
- console.error("Not retrying request, throwing error.");
98
+ console.error('Not retrying request, throwing error.');
99
99
  throw error;
100
100
  }
101
101
  const delay = this.getDelay(this.config.retryStrategy, attempt);
@@ -103,5 +103,5 @@ AvroQueryClient.prototype._xhr = async function (method, path, body, cancelToken
103
103
  await this.sleep(delay);
104
104
  }
105
105
  }
106
- throw new StandardError(0, "Request failed after maximum retries.");
106
+ throw new StandardError(0, 'Request failed after maximum retries.');
107
107
  };
@@ -1,47 +1,47 @@
1
- import { useQuery } from "@tanstack/react-query";
2
- import { AvroQueryClient } from "../../client/QueryClient";
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import { AvroQueryClient } from '../../client/QueryClient';
3
3
  AvroQueryClient.prototype.useGetAnalytics = function () {
4
4
  return useQuery({
5
- queryKey: ["analytics"],
5
+ queryKey: ['analytics'],
6
6
  queryFn: () => this.post({
7
- path: "/avro/analytics",
7
+ path: '/avro/analytics',
8
8
  }),
9
9
  enabled: true,
10
10
  });
11
11
  };
12
12
  AvroQueryClient.prototype.useFinanceAnalytics = function ({ periods, cumulative, }) {
13
13
  return useQuery({
14
- queryKey: ["analytics", "finance", this.companyId, periods, cumulative],
14
+ queryKey: ['analytics', 'finance', this.companyId, periods, cumulative],
15
15
  queryFn: () => this.post({
16
16
  path: `/company/${this.companyId}/analytics/finance`,
17
17
  data: JSON.stringify({ periods, cumulative }),
18
18
  headers: {
19
- "Content-Type": "application/json",
19
+ 'Content-Type': 'application/json',
20
20
  },
21
21
  }),
22
22
  });
23
23
  };
24
- AvroQueryClient.prototype.useEventAnalytics = function ({ periods, }) {
24
+ AvroQueryClient.prototype.useEventAnalytics = function ({ periods }) {
25
25
  return useQuery({
26
- queryKey: ["analytics", "events", this.companyId, periods],
26
+ queryKey: ['analytics', 'events', this.companyId, periods],
27
27
  queryFn: () => this.post({
28
28
  path: `/company/${this.companyId}/analytics/events`,
29
29
  data: JSON.stringify({ periods }),
30
30
  headers: {
31
- "Content-Type": "application/json",
31
+ 'Content-Type': 'application/json',
32
32
  },
33
33
  }),
34
34
  enabled: Boolean(this.companyId),
35
35
  });
36
36
  };
37
- AvroQueryClient.prototype.useRevenueAnalytics = function ({ periods, }) {
37
+ AvroQueryClient.prototype.useRevenueAnalytics = function ({ periods }) {
38
38
  return useQuery({
39
- queryKey: ["analytics", "revenue", this.companyId, periods],
39
+ queryKey: ['analytics', 'revenue', this.companyId, periods],
40
40
  queryFn: () => this.post({
41
41
  path: `/company/${this.companyId}/analytics/revenue`,
42
42
  data: JSON.stringify({ periods }),
43
43
  headers: {
44
- "Content-Type": "application/json",
44
+ 'Content-Type': 'application/json',
45
45
  },
46
46
  }),
47
47
  enabled: Boolean(this.companyId),
@@ -1,9 +1,9 @@
1
- import { useQuery } from "@tanstack/react-query";
2
- import { AvroQueryClient } from "../../client/QueryClient";
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import { AvroQueryClient } from '../../client/QueryClient';
3
3
  AvroQueryClient.prototype.useGetAvro = function () {
4
4
  return useQuery({
5
- queryKey: ["avro"],
6
- queryFn: () => this.get({ path: "/avro" }),
5
+ queryKey: ['avro'],
6
+ queryFn: () => this.get({ path: '/avro' }),
7
7
  enabled: true,
8
8
  });
9
9
  };
@@ -1,12 +1,12 @@
1
- import { useInfiniteQuery, useQuery, useMutation } from "@tanstack/react-query";
2
- import { AvroQueryClient } from "../../client/QueryClient";
1
+ import { useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
2
+ import { AvroQueryClient } from '../../client/QueryClient';
3
3
  AvroQueryClient.prototype.useGetBills = function (body) {
4
4
  const queryClient = this.getQueryClient();
5
5
  const result = useInfiniteQuery({
6
6
  queryKey: [
7
- "bills",
7
+ 'bills',
8
8
  this.companyId,
9
- body.query ?? "",
9
+ body.query ?? '',
10
10
  body.known_ids ?? [],
11
11
  body.unknown_ids ?? [],
12
12
  body.paid ?? false,
@@ -22,7 +22,7 @@ AvroQueryClient.prototype.useGetBills = function (body) {
22
22
  if (result.data) {
23
23
  result.data.pages.forEach((data_page) => {
24
24
  data_page.forEach((bill) => {
25
- queryClient.setQueryData(["bills", bill.id], bill);
25
+ queryClient.setQueryData(['bills', bill.id], bill);
26
26
  });
27
27
  });
28
28
  }
@@ -30,7 +30,7 @@ AvroQueryClient.prototype.useGetBills = function (body) {
30
30
  };
31
31
  AvroQueryClient.prototype.useGetBill = function (billId) {
32
32
  return useQuery({
33
- queryKey: ["bills", billId],
33
+ queryKey: ['bills', billId],
34
34
  queryFn: () => this.get({ path: `/bill/${billId}` }),
35
35
  enabled: Boolean(billId),
36
36
  });
@@ -53,29 +53,29 @@ AvroQueryClient.prototype.useCreateBill = function () {
53
53
  path: `/company/${this.companyId}/bill`,
54
54
  data: JSON.stringify(body),
55
55
  headers: {
56
- "Content-Type": "application/json",
56
+ 'Content-Type': 'application/json',
57
57
  },
58
58
  });
59
59
  },
60
60
  onMutate: async () => {
61
61
  await queryClient.cancelQueries({
62
- queryKey: ["bills", this.companyId],
62
+ queryKey: ['bills', this.companyId],
63
63
  });
64
- const previousBills = queryClient.getQueryData(["bills", this.companyId]);
64
+ const previousBills = queryClient.getQueryData(['bills', this.companyId]);
65
65
  // TODO: Create a fake bill object for optimistic update and update events and months accordingly
66
66
  return { previousBills };
67
67
  },
68
68
  onSuccess: async (result) => {
69
69
  await this._syncEntity(queryClient, {
70
- action: "create",
71
- entityKey: "bills",
70
+ action: 'create',
71
+ entityKey: 'bills',
72
72
  id: result.id,
73
73
  fetchPath: `/bill/${result.id}`,
74
74
  });
75
75
  },
76
76
  onError: (_err, _variables, context) => {
77
77
  if (context?.previousBills) {
78
- queryClient.setQueryData(["bills"], context.previousBills);
78
+ queryClient.setQueryData(['bills'], context.previousBills);
79
79
  }
80
80
  },
81
81
  });
@@ -83,22 +83,22 @@ AvroQueryClient.prototype.useCreateBill = function () {
83
83
  AvroQueryClient.prototype.useUpdateBill = function () {
84
84
  const queryClient = this.getQueryClient();
85
85
  return useMutation({
86
- mutationFn: ({ billId, updates, }) => {
86
+ mutationFn: ({ billId, updates }) => {
87
87
  return this.put({
88
88
  path: `/bill/${billId}`,
89
89
  data: JSON.stringify(updates),
90
90
  headers: {
91
- "Content-Type": "application/json",
91
+ 'Content-Type': 'application/json',
92
92
  },
93
93
  });
94
94
  },
95
95
  onMutate: async ({ billId, updates }) => {
96
- await queryClient.cancelQueries({ queryKey: ["bills"] });
97
- await queryClient.cancelQueries({ queryKey: ["bills", billId] });
98
- const previousBills = queryClient.getQueryData(["bills"]);
99
- const previousBill = queryClient.getQueryData(["bills", billId]);
100
- queryClient.setQueryData(["bills", billId], (oldData) => oldData ? { ...oldData, ...updates } : undefined);
101
- queryClient.setQueriesData({ queryKey: ["bills"] }, (oldData) => {
96
+ await queryClient.cancelQueries({ queryKey: ['bills'] });
97
+ await queryClient.cancelQueries({ queryKey: ['bills', billId] });
98
+ const previousBills = queryClient.getQueryData(['bills']);
99
+ const previousBill = queryClient.getQueryData(['bills', billId]);
100
+ queryClient.setQueryData(['bills', billId], (oldData) => oldData ? { ...oldData, ...updates } : undefined);
101
+ queryClient.setQueriesData({ queryKey: ['bills'] }, (oldData) => {
102
102
  if (!oldData)
103
103
  return oldData;
104
104
  if (oldData.pages) {
@@ -116,8 +116,8 @@ AvroQueryClient.prototype.useUpdateBill = function () {
116
116
  },
117
117
  onSuccess: async (_result, { billId }) => {
118
118
  await this._syncEntity(queryClient, {
119
- action: "update",
120
- entityKey: "bills",
119
+ action: 'update',
120
+ entityKey: 'bills',
121
121
  id: billId,
122
122
  fetchPath: `/bill/${billId}`,
123
123
  });
@@ -125,10 +125,10 @@ AvroQueryClient.prototype.useUpdateBill = function () {
125
125
  onError: (err, variables, context) => {
126
126
  const { billId } = variables;
127
127
  if (context?.previousBills) {
128
- queryClient.setQueryData(["bills"], context.previousBills);
128
+ queryClient.setQueryData(['bills'], context.previousBills);
129
129
  }
130
130
  if (context?.previousBill) {
131
- queryClient.setQueryData(["bills", billId], context.previousBill);
131
+ queryClient.setQueryData(['bills', billId], context.previousBill);
132
132
  }
133
133
  },
134
134
  });
@@ -140,21 +140,21 @@ AvroQueryClient.prototype.useDeleteBill = function () {
140
140
  return this.delete({ path: `/bill/${billId}` });
141
141
  },
142
142
  onMutate: async ({ billId }) => {
143
- await queryClient.cancelQueries({ queryKey: ["bills"] });
144
- const previousBills = queryClient.getQueryData(["bills"]);
143
+ await queryClient.cancelQueries({ queryKey: ['bills'] });
144
+ const previousBills = queryClient.getQueryData(['bills']);
145
145
  // TODO: Create a fake bill object for optimistic update and update events and months accordingly
146
146
  return { previousBills };
147
147
  },
148
148
  onSuccess: async (_result, { billId }) => {
149
149
  await this._syncEntity(queryClient, {
150
- action: "delete",
151
- entityKey: "bills",
150
+ action: 'delete',
151
+ entityKey: 'bills',
152
152
  id: billId,
153
153
  });
154
154
  },
155
155
  onError: (_err, _variables, context) => {
156
156
  if (context?.previousBills) {
157
- queryClient.setQueryData(["bills"], context.previousBills);
157
+ queryClient.setQueryData(['bills'], context.previousBills);
158
158
  }
159
159
  },
160
160
  });
@@ -168,20 +168,17 @@ AvroQueryClient.prototype.useSyncBillToIntuit = function () {
168
168
  });
169
169
  },
170
170
  onMutate: async ({ billId }) => {
171
- await queryClient.cancelQueries({ queryKey: ["bills", billId] });
172
- const previousBill = queryClient.getQueryData([
173
- "bills",
174
- billId,
175
- ]);
171
+ await queryClient.cancelQueries({ queryKey: ['bills', billId] });
172
+ const previousBill = queryClient.getQueryData(['bills', billId]);
176
173
  return { previousBill };
177
174
  },
178
175
  onSuccess: () => {
179
- queryClient.invalidateQueries({ queryKey: ["bills"] });
176
+ queryClient.invalidateQueries({ queryKey: ['bills'] });
180
177
  },
181
178
  onError: (_err, variables, context) => {
182
179
  const { billId } = variables;
183
180
  if (context?.previousBill) {
184
- queryClient.setQueryData(["bills", billId], context.previousBill);
181
+ queryClient.setQueryData(['bills', billId], context.previousBill);
185
182
  }
186
183
  },
187
184
  });
@@ -195,11 +192,11 @@ AvroQueryClient.prototype.useImportBillsFromIntuit = function () {
195
192
  });
196
193
  },
197
194
  onSuccess: () => {
198
- queryClient.invalidateQueries({ queryKey: ["bills"] });
195
+ queryClient.invalidateQueries({ queryKey: ['bills'] });
199
196
  },
200
197
  });
201
198
  };
202
- AvroQueryClient.prototype.generatePDFFromBackend = function ({ billId, }) {
199
+ AvroQueryClient.prototype.generatePDFFromBackend = function ({ billId }) {
203
200
  return this.get({
204
201
  path: `/company/${this.companyId}/bill/${billId}/pdf`,
205
202
  }).then((response) => {
@@ -211,7 +208,7 @@ AvroQueryClient.prototype.sendBillingEmail = async function ({ subject, billId,
211
208
  path: `/bill/${billId}/email`,
212
209
  data: JSON.stringify({ recipients, subject, request_id }),
213
210
  headers: {
214
- "Content-Type": "application/json",
211
+ 'Content-Type': 'application/json',
215
212
  },
216
213
  });
217
214
  };
@@ -1,5 +1,5 @@
1
- import { useQuery, useMutation } from "@tanstack/react-query";
2
- import { AvroQueryClient } from "../../client/QueryClient";
1
+ import { useQuery, useMutation } from '@tanstack/react-query';
2
+ import { AvroQueryClient } from '../../client/QueryClient';
3
3
  AvroQueryClient.prototype.useCreateCatalogItem = function () {
4
4
  const queryClient = this.getQueryClient();
5
5
  return useMutation({
@@ -8,31 +8,28 @@ AvroQueryClient.prototype.useCreateCatalogItem = function () {
8
8
  path: `/company/${this.companyId}/catalog_item`,
9
9
  data: JSON.stringify(data),
10
10
  headers: {
11
- "Content-Type": "application/json",
11
+ 'Content-Type': 'application/json',
12
12
  },
13
13
  });
14
14
  },
15
15
  onMutate: async () => {
16
16
  await queryClient.cancelQueries({
17
- queryKey: ["catalog_items", this.companyId],
17
+ queryKey: ['catalog_items', this.companyId],
18
18
  });
19
- const previousItems = queryClient.getQueryData([
20
- "catalog_items",
21
- this.companyId,
22
- ]);
19
+ const previousItems = queryClient.getQueryData(['catalog_items', this.companyId]);
23
20
  return { previousItems };
24
21
  },
25
22
  onSuccess: async (result) => {
26
23
  await this._syncEntity(queryClient, {
27
- action: "create",
28
- entityKey: "catalog_items",
24
+ action: 'create',
25
+ entityKey: 'catalog_items',
29
26
  id: result.id,
30
27
  fetchPath: `/catalog_item/${result.id}`,
31
28
  });
32
29
  },
33
30
  onError: (_err, _variables, context) => {
34
31
  if (context?.previousItems) {
35
- queryClient.setQueryData(["catalog_items", this.companyId], context.previousItems);
32
+ queryClient.setQueryData(['catalog_items', this.companyId], context.previousItems);
36
33
  }
37
34
  },
38
35
  });
@@ -45,22 +42,19 @@ AvroQueryClient.prototype.useUpdateCatalogItem = function () {
45
42
  path: `/catalog_item/${catalogItemId}`,
46
43
  data: JSON.stringify(data),
47
44
  headers: {
48
- "Content-Type": "application/json",
45
+ 'Content-Type': 'application/json',
49
46
  },
50
47
  });
51
48
  },
52
49
  onMutate: async ({ catalogItemId, data }) => {
53
- await queryClient.cancelQueries({ queryKey: ["catalog_items"] });
50
+ await queryClient.cancelQueries({ queryKey: ['catalog_items'] });
54
51
  await queryClient.cancelQueries({
55
- queryKey: ["catalog_items", catalogItemId],
52
+ queryKey: ['catalog_items', catalogItemId],
56
53
  });
57
- const previousItems = queryClient.getQueryData(["catalog_items"]);
58
- const previousItem = queryClient.getQueryData([
59
- "catalog_items",
60
- catalogItemId,
61
- ]);
62
- queryClient.setQueryData(["catalog_items", catalogItemId], (oldData) => oldData ? { ...oldData, ...data } : undefined);
63
- queryClient.setQueriesData({ queryKey: ["catalog_items"] }, (oldData) => {
54
+ const previousItems = queryClient.getQueryData(['catalog_items']);
55
+ const previousItem = queryClient.getQueryData(['catalog_items', catalogItemId]);
56
+ queryClient.setQueryData(['catalog_items', catalogItemId], (oldData) => oldData ? { ...oldData, ...data } : undefined);
57
+ queryClient.setQueriesData({ queryKey: ['catalog_items'] }, (oldData) => {
64
58
  if (!oldData)
65
59
  return oldData;
66
60
  if (oldData.pages) {
@@ -78,8 +72,8 @@ AvroQueryClient.prototype.useUpdateCatalogItem = function () {
78
72
  },
79
73
  onSuccess: async (_result, { catalogItemId }) => {
80
74
  await this._syncEntity(queryClient, {
81
- action: "update",
82
- entityKey: "catalog_items",
75
+ action: 'update',
76
+ entityKey: 'catalog_items',
83
77
  id: catalogItemId,
84
78
  fetchPath: `/catalog_item/${catalogItemId}`,
85
79
  });
@@ -87,17 +81,17 @@ AvroQueryClient.prototype.useUpdateCatalogItem = function () {
87
81
  onError: (err, variables, context) => {
88
82
  const { catalogItemId } = variables;
89
83
  if (context?.previousItems) {
90
- queryClient.setQueryData(["catalog_items"], context.previousItems);
84
+ queryClient.setQueryData(['catalog_items'], context.previousItems);
91
85
  }
92
86
  if (context?.previousItem) {
93
- queryClient.setQueryData(["catalog_items", catalogItemId], context.previousItem);
87
+ queryClient.setQueryData(['catalog_items', catalogItemId], context.previousItem);
94
88
  }
95
89
  },
96
90
  });
97
91
  };
98
92
  AvroQueryClient.prototype.useGetCatalogItem = function (catalogItemId) {
99
93
  return useQuery({
100
- queryKey: ["catalog_items", catalogItemId],
94
+ queryKey: ['catalog_items', catalogItemId],
101
95
  queryFn: () => this.get({ path: `/catalog_item/${catalogItemId}` }),
102
96
  enabled: Boolean(catalogItemId),
103
97
  });
@@ -111,20 +105,20 @@ AvroQueryClient.prototype.useDeleteCatalogItem = function () {
111
105
  });
112
106
  },
113
107
  onMutate: async ({ catalogItemId }) => {
114
- await queryClient.cancelQueries({ queryKey: ["catalog_items"] });
115
- const previousItems = queryClient.getQueryData(["catalog_items"]);
108
+ await queryClient.cancelQueries({ queryKey: ['catalog_items'] });
109
+ const previousItems = queryClient.getQueryData(['catalog_items']);
116
110
  return { previousItems };
117
111
  },
118
112
  onSuccess: async (_result, { catalogItemId }) => {
119
113
  await this._syncEntity(queryClient, {
120
- action: "delete",
121
- entityKey: "catalog_items",
114
+ action: 'delete',
115
+ entityKey: 'catalog_items',
122
116
  id: catalogItemId,
123
117
  });
124
118
  },
125
119
  onError: (_err, _variables, context) => {
126
120
  if (context?.previousItems) {
127
- queryClient.setQueryData(["catalog_items"], context.previousItems);
121
+ queryClient.setQueryData(['catalog_items'], context.previousItems);
128
122
  }
129
123
  },
130
124
  });
@@ -1,15 +1,15 @@
1
- import { useInfiniteQuery, useQuery } from "@tanstack/react-query";
2
- import { AvroQueryClient } from "../../client/QueryClient";
1
+ import { useInfiniteQuery, useQuery } from '@tanstack/react-query';
2
+ import { AvroQueryClient } from '../../client/QueryClient';
3
3
  AvroQueryClient.prototype.useGetChats = function (body) {
4
4
  const queryClient = this.getQueryClient();
5
5
  const result = useInfiniteQuery({
6
6
  queryKey: [
7
- "chats",
7
+ 'chats',
8
8
  this.companyId,
9
9
  body.amt ?? 50,
10
10
  body.known_ids ?? [],
11
11
  body.unknown_ids ?? [],
12
- body.query ?? "",
12
+ body.query ?? '',
13
13
  ],
14
14
  initialPageParam: 0,
15
15
  getNextPageParam: (lastPage, allPages) => {
@@ -22,7 +22,7 @@ AvroQueryClient.prototype.useGetChats = function (body) {
22
22
  if (result.data) {
23
23
  result.data.pages.forEach((data_page) => {
24
24
  data_page.forEach((chat) => {
25
- queryClient.setQueryData(["chats", chat.id], chat);
25
+ queryClient.setQueryData(['chats', chat.id], chat);
26
26
  });
27
27
  });
28
28
  }
@@ -30,7 +30,7 @@ AvroQueryClient.prototype.useGetChats = function (body) {
30
30
  };
31
31
  AvroQueryClient.prototype.useGetChat = function (chatId) {
32
32
  return useQuery({
33
- queryKey: ["chats", chatId],
33
+ queryKey: ['chats', chatId],
34
34
  queryFn: () => this.get({ path: `/chat/${chatId}` }),
35
35
  enabled: Boolean(chatId),
36
36
  });