@go-avro/avro-js 0.0.93 → 0.0.95
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 +9 -1
- package/dist/client/QueryClient.js +23 -19
- package/dist/client/hooks/avro.js +6 -0
- package/dist/client/hooks/companies.js +12 -3
- package/dist/client/hooks/users.js +12 -1
- package/dist/types/api/Avro.d.ts +17 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -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, AddressFeatureCollection, ApiInfo, Avro, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Break, Chat, CheckIn, Company, DelayEventCreatePayload, EventUpdatePayload, LineItemType, FinancialInsightData, RevenueInsightData, Job, JobUpdate, 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, AddressFeatureCollection, ApiInfo, Avro, StorageAnalytics, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Break, Chat, CheckIn, Company, DelayEventCreatePayload, EventUpdatePayload, LineItemType, FinancialInsightData, RevenueInsightData, Job, JobUpdate, 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';
|
|
@@ -235,6 +235,7 @@ declare module '../client/QueryClient' {
|
|
|
235
235
|
}): UseQueryResult<Timecard[], StandardError>;
|
|
236
236
|
useGetTimecard(timecardId?: string, enabled?: boolean): UseQueryResult<Timecard, StandardError>;
|
|
237
237
|
useGetAvro(): UseQueryResult<Avro, StandardError>;
|
|
238
|
+
useGetStorageAnalytics(): UseQueryResult<StorageAnalytics, StandardError>;
|
|
238
239
|
useSearchUsers(searchUsername: string): UseQueryResult<User[], StandardError>;
|
|
239
240
|
useReviewProposal(proposal_id: string): ReturnType<typeof useMutation<{
|
|
240
241
|
msg: string;
|
|
@@ -754,6 +755,13 @@ export declare class AvroQueryClient {
|
|
|
754
755
|
construct?: (raw: any) => any;
|
|
755
756
|
matchesQuery?: (queryKey: readonly unknown[], item: any) => ListQueryMatch;
|
|
756
757
|
}): Promise<any>;
|
|
758
|
+
/**
|
|
759
|
+
* Drop all local auth state without a server round-trip: stored
|
|
760
|
+
* tokens, cached company, query cache, socket, and auth state.
|
|
761
|
+
* The single teardown path for logout, refresh failure, and a
|
|
762
|
+
* server that no longer recognizes our identity.
|
|
763
|
+
*/
|
|
764
|
+
forceLogout(): Promise<void>;
|
|
757
765
|
useLogout(): ReturnType<typeof useMutation<void, StandardError, CancelToken | undefined>>;
|
|
758
766
|
fetchJobs(body?: {
|
|
759
767
|
amt?: number;
|
|
@@ -440,11 +440,7 @@ export class AvroQueryClient {
|
|
|
440
440
|
}
|
|
441
441
|
});
|
|
442
442
|
config.authManager.onTokenRefreshFailed(() => {
|
|
443
|
-
this.
|
|
444
|
-
this.setAuthState(AuthState.UNAUTHENTICATED);
|
|
445
|
-
if (this.socket && this.socket.connected) {
|
|
446
|
-
this.socket.disconnect();
|
|
447
|
-
}
|
|
443
|
+
void this.forceLogout();
|
|
448
444
|
});
|
|
449
445
|
}
|
|
450
446
|
emit(eventName, data) {
|
|
@@ -886,26 +882,34 @@ export class AvroQueryClient {
|
|
|
886
882
|
return undefined;
|
|
887
883
|
}
|
|
888
884
|
}
|
|
885
|
+
/**
|
|
886
|
+
* Drop all local auth state without a server round-trip: stored
|
|
887
|
+
* tokens, cached company, query cache, socket, and auth state.
|
|
888
|
+
* The single teardown path for logout, refresh failure, and a
|
|
889
|
+
* server that no longer recognizes our identity.
|
|
890
|
+
*/
|
|
891
|
+
async forceLogout() {
|
|
892
|
+
await this.clearCache();
|
|
893
|
+
this.setAuthState(AuthState.UNAUTHENTICATED);
|
|
894
|
+
if (this.socket && this.socket.connected) {
|
|
895
|
+
this.socket.disconnect();
|
|
896
|
+
}
|
|
897
|
+
this.getQueryClient().removeQueries();
|
|
898
|
+
}
|
|
889
899
|
useLogout() {
|
|
890
|
-
const queryClient = this.getQueryClient();
|
|
891
900
|
return useMutation({
|
|
892
901
|
mutationFn: async (cancelToken) => {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
902
|
+
try {
|
|
903
|
+
await this.post({
|
|
904
|
+
path: '/logout',
|
|
905
|
+
cancelToken,
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
finally {
|
|
909
|
+
await this.forceLogout();
|
|
900
910
|
}
|
|
901
|
-
},
|
|
902
|
-
onSettled: () => {
|
|
903
|
-
this.clearCache();
|
|
904
|
-
this.setAuthState(AuthState.UNAUTHENTICATED);
|
|
905
|
-
queryClient.removeQueries();
|
|
906
911
|
},
|
|
907
912
|
onError: (err) => {
|
|
908
|
-
this.clearCache();
|
|
909
913
|
console.error('Logout failed:', err);
|
|
910
914
|
throw new StandardError(500, 'Logout failed');
|
|
911
915
|
},
|
|
@@ -7,3 +7,9 @@ AvroQueryClient.prototype.useGetAvro = function () {
|
|
|
7
7
|
enabled: true,
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
AvroQueryClient.prototype.useGetStorageAnalytics = function () {
|
|
11
|
+
return useQuery({
|
|
12
|
+
queryKey: ['avro', 'storage'],
|
|
13
|
+
queryFn: () => this.get({ path: '/avro/storage' }),
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { StandardError } from '../../types/error';
|
|
3
4
|
import { AuthState } from '../../types/auth';
|
|
4
5
|
AvroQueryClient.prototype.useGetCompanies = function (options = {}) {
|
|
5
6
|
return useQuery({
|
|
@@ -47,9 +48,17 @@ AvroQueryClient.prototype.useGetCurrentCompany = function () {
|
|
|
47
48
|
throw new Error('No company ID set and no companies available');
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
try {
|
|
52
|
+
this.company = await this.get({
|
|
53
|
+
path: `/company/${this.companyId}`,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
if (err instanceof StandardError && err.status === 404) {
|
|
58
|
+
await this.setCompanyId('');
|
|
59
|
+
}
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
53
62
|
return this.company;
|
|
54
63
|
},
|
|
55
64
|
enabled: this.getAuthState() === AuthState.AUTHENTICATED,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { StandardError } from '../../types/error';
|
|
3
4
|
import { AuthState } from '../../types/auth';
|
|
4
5
|
AvroQueryClient.prototype.useGetUser = function (userId) {
|
|
5
6
|
return useQuery({
|
|
@@ -22,7 +23,17 @@ AvroQueryClient.prototype.useSearchUsers = function (searchUsername) {
|
|
|
22
23
|
AvroQueryClient.prototype.useGetSelf = function () {
|
|
23
24
|
return useQuery({
|
|
24
25
|
queryKey: ['user'],
|
|
25
|
-
queryFn: () =>
|
|
26
|
+
queryFn: async () => {
|
|
27
|
+
try {
|
|
28
|
+
return await this.get({ path: `/user` });
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
if (err instanceof StandardError && err.status === 404) {
|
|
32
|
+
await this.forceLogout();
|
|
33
|
+
}
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
26
37
|
enabled: this.getAuthState() === AuthState.AUTHENTICATED,
|
|
27
38
|
});
|
|
28
39
|
};
|
package/dist/types/api/Avro.d.ts
CHANGED
|
@@ -9,3 +9,20 @@ export interface Avro {
|
|
|
9
9
|
billing_email_id: string;
|
|
10
10
|
join_email_id: string;
|
|
11
11
|
}
|
|
12
|
+
export interface StorageByType {
|
|
13
|
+
type: string;
|
|
14
|
+
count: number;
|
|
15
|
+
bytes: number;
|
|
16
|
+
}
|
|
17
|
+
export interface StorageByCompany {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
count: number;
|
|
21
|
+
bytes: number;
|
|
22
|
+
}
|
|
23
|
+
export interface StorageAnalytics {
|
|
24
|
+
total_bytes: number;
|
|
25
|
+
by_type: StorageByType[];
|
|
26
|
+
/** Ordered by bytes, largest first. */
|
|
27
|
+
by_company: StorageByCompany[];
|
|
28
|
+
}
|
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.95";
|
package/dist/version.js
CHANGED