@go-avro/avro-js 0.0.70 → 0.0.72
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/auth/AuthManager.js +5 -2
- package/dist/client/QueryClient.d.ts +10 -1
- package/dist/client/QueryClient.js +7 -2
- package/dist/client/hooks/bills.js +27 -0
- package/dist/client/hooks/checkins.js +3 -1
- package/dist/types/api/Bill.d.ts +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/auth/AuthManager.js
CHANGED
|
@@ -78,9 +78,12 @@ export class AuthManager {
|
|
|
78
78
|
const newTokens = await response.json();
|
|
79
79
|
return newTokens;
|
|
80
80
|
}
|
|
81
|
+
if (response.status === 401 || response.status === 422) {
|
|
82
|
+
storage.clear();
|
|
83
|
+
}
|
|
81
84
|
}
|
|
82
|
-
catch
|
|
83
|
-
|
|
85
|
+
catch {
|
|
86
|
+
console.error('Error refreshing tokens from storage:', storage);
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
throw new StandardError(410, 'Failed to refresh tokens from all storages');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Socket } from 'socket.io-client';
|
|
2
2
|
import { InfiniteData, QueryClient, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import { AuthManager } from '../auth/AuthManager';
|
|
4
|
-
import { _Event, ActiveSessionSummary, ApiInfo, Avro, Bill, BillInsightData, Break, Chat, CheckIn, Company, EventUpdatePayload, FinancialInsightData, RevenueInsightData, Job, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill, Group, Label, RouteScheduleConfig, RouteWritePayload, CatalogItem, Payout, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api';
|
|
4
|
+
import { _Event, ActiveSessionSummary, ApiInfo, Avro, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Break, Chat, CheckIn, Company, EventUpdatePayload, FinancialInsightData, RevenueInsightData, Job, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill, Group, Label, RouteScheduleConfig, RouteWritePayload, CatalogItem, Payout, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api';
|
|
5
5
|
import { AuthState, Tokens } from '../types/auth';
|
|
6
6
|
import { CancelToken, ClientId, RetryStrategy } from '../types/client';
|
|
7
7
|
import { StandardError } from '../types/error';
|
|
@@ -453,6 +453,13 @@ declare module '../client/QueryClient' {
|
|
|
453
453
|
billId: string;
|
|
454
454
|
updates: Partial<Bill>;
|
|
455
455
|
}>>;
|
|
456
|
+
useUpdateBillLineItemStatus(): ReturnType<typeof useMutation<{
|
|
457
|
+
msg: string;
|
|
458
|
+
status: BillStatus;
|
|
459
|
+
}, StandardError, {
|
|
460
|
+
billId: string;
|
|
461
|
+
items: BillLineItemStatusUpdate[];
|
|
462
|
+
}>>;
|
|
456
463
|
useUpdateRoute(): ReturnType<typeof useMutation<{
|
|
457
464
|
msg: string;
|
|
458
465
|
}, StandardError, {
|
|
@@ -695,6 +702,8 @@ export declare class AvroQueryClient {
|
|
|
695
702
|
getAuthState(): AuthState;
|
|
696
703
|
getAuthStateAsync(): Promise<AuthState>;
|
|
697
704
|
getQueryClient(): QueryClient;
|
|
705
|
+
attachQueryClient(queryClient: QueryClient): void;
|
|
706
|
+
peekQueryClient(): QueryClient | null;
|
|
698
707
|
_syncEntity(queryClient: QueryClient, params: {
|
|
699
708
|
action: 'create' | 'update' | 'delete';
|
|
700
709
|
entityKey: string;
|
|
@@ -464,8 +464,7 @@ export class AvroQueryClient {
|
|
|
464
464
|
* (old backend), we fall back to full invalidation.
|
|
465
465
|
*/
|
|
466
466
|
setupSocketInvalidation(queryClient) {
|
|
467
|
-
|
|
468
|
-
if (this._queryClient)
|
|
467
|
+
if (this._socketInvalidationCleanup)
|
|
469
468
|
return;
|
|
470
469
|
this._queryClient = queryClient;
|
|
471
470
|
const handlers = [];
|
|
@@ -773,6 +772,12 @@ export class AvroQueryClient {
|
|
|
773
772
|
getQueryClient() {
|
|
774
773
|
return useQueryClient();
|
|
775
774
|
}
|
|
775
|
+
attachQueryClient(queryClient) {
|
|
776
|
+
this._queryClient ?? (this._queryClient = queryClient);
|
|
777
|
+
}
|
|
778
|
+
peekQueryClient() {
|
|
779
|
+
return this._queryClient;
|
|
780
|
+
}
|
|
776
781
|
async _syncEntity(queryClient, params) {
|
|
777
782
|
const { action, entityKey, id, fetchPath, construct, matchesQuery } = params;
|
|
778
783
|
const predicate = (q) => matchesEntityKey(q, entityKey);
|
|
@@ -142,6 +142,33 @@ AvroQueryClient.prototype.useUpdateBill = function () {
|
|
|
142
142
|
},
|
|
143
143
|
});
|
|
144
144
|
};
|
|
145
|
+
AvroQueryClient.prototype.useUpdateBillLineItemStatus = function () {
|
|
146
|
+
const queryClient = this.getQueryClient();
|
|
147
|
+
return useMutation({
|
|
148
|
+
mutationFn: async ({ billId, items, }) => {
|
|
149
|
+
return this.put({
|
|
150
|
+
path: `/bill/${billId}/line-items/status`,
|
|
151
|
+
data: JSON.stringify({ items }),
|
|
152
|
+
headers: {
|
|
153
|
+
'Content-Type': 'application/json',
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
onSuccess: async (_result, { billId }) => {
|
|
158
|
+
await this._syncEntity(queryClient, {
|
|
159
|
+
action: 'update',
|
|
160
|
+
entityKey: 'bills',
|
|
161
|
+
id: billId,
|
|
162
|
+
fetchPath: `/bill/${billId}`,
|
|
163
|
+
});
|
|
164
|
+
// Item paid state also lives on the underlying events,
|
|
165
|
+
// service months and prepayments
|
|
166
|
+
await queryClient.invalidateQueries({ queryKey: ['events'] });
|
|
167
|
+
await queryClient.invalidateQueries({ queryKey: ['months'] });
|
|
168
|
+
await queryClient.invalidateQueries({ queryKey: ['prepayments'] });
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
};
|
|
145
172
|
AvroQueryClient.prototype.useDeleteBill = function () {
|
|
146
173
|
const queryClient = this.getQueryClient();
|
|
147
174
|
return useMutation({
|
|
@@ -7,7 +7,9 @@ import { Job } from '../../types/api/Job';
|
|
|
7
7
|
* location task) where the socket is usually down — sync directly.
|
|
8
8
|
*/
|
|
9
9
|
const syncCheckinCaches = async (client, jobId) => {
|
|
10
|
-
const queryClient = client.
|
|
10
|
+
const queryClient = client.peekQueryClient();
|
|
11
|
+
if (!queryClient)
|
|
12
|
+
return;
|
|
11
13
|
queryClient.invalidateQueries({ queryKey: ['checkins'] });
|
|
12
14
|
if (!jobId)
|
|
13
15
|
return;
|
package/dist/types/api/Bill.d.ts
CHANGED
|
@@ -35,3 +35,11 @@ export interface Bill {
|
|
|
35
35
|
due_date: number;
|
|
36
36
|
pass_on_fees: boolean;
|
|
37
37
|
}
|
|
38
|
+
/** Line-item kinds addressable by PUT /bill/<id>/line-items/status. */
|
|
39
|
+
export type BillLineItemStatusKind = 'event' | 'service_month' | 'prepayment' | 'line_item';
|
|
40
|
+
/** One per-line-item paid/unpaid marking on a bill. */
|
|
41
|
+
export interface BillLineItemStatusUpdate {
|
|
42
|
+
type: BillLineItemStatusKind;
|
|
43
|
+
id: string;
|
|
44
|
+
paid: boolean;
|
|
45
|
+
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AVRO_JS_VERSION = "0.0.
|
|
1
|
+
export declare const AVRO_JS_VERSION = "0.0.72";
|
package/dist/version.js
CHANGED