@go-avro/avro-js 1.6.2 → 1.6.4-rc2
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 +47 -2
- package/dist/client/QueryClient.js +108 -6
- package/dist/client/hooks/companies.js +18 -0
- package/dist/client/hooks/users.js +29 -0
- package/dist/types/api/User.d.ts +4 -0
- package/dist/types/api/UserMerge.d.ts +18 -0
- package/dist/types/api/UserMerge.js +1 -0
- package/dist/types/api.d.ts +26 -0
- package/dist/types/api.js +1 -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.js';
|
|
4
|
-
import { _Event, ActiveSessionSummary, AddressFeatureCollection, ApiInfo, Avro, StorageAnalytics, ClientErrorReport, ErrorLogEntry, PerformanceMetrics, AuditLogEntry, AuditQueryParams, 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, Device, DeviceInfo, LocationServicesStatus, Payout, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api.js';
|
|
4
|
+
import { _Event, ActiveSessionSummary, AddressFeatureCollection, ApiInfo, Avro, StorageAnalytics, ClientErrorReport, ErrorLogEntry, PerformanceMetrics, AuditLogEntry, AuditQueryParams, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Break, Chat, CheckIn, Company, DelayEventCreatePayload, EventUpdatePayload, LineItemType, FinancialInsightData, RevenueInsightData, Job, JobUpdate, EventInsightData, AppleLinkProof, AppleLoginResult, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, UserMergeSummary, Skill, Group, Label, RouteScheduleConfig, RouteWritePayload, CatalogItem, Device, DeviceInfo, LocationServicesStatus, Payout, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api.js';
|
|
5
5
|
import { AuthState, Tokens } from '../types/auth.js';
|
|
6
6
|
import { CancelToken, ClientId, RetryStrategy } from '../types/client.js';
|
|
7
7
|
import { StandardError } from '../types/error.js';
|
|
@@ -277,6 +277,11 @@ declare module './QueryClient.js' {
|
|
|
277
277
|
cleared: number;
|
|
278
278
|
}, StandardError, void>>;
|
|
279
279
|
useSearchUsers(searchUsername: string): UseQueryResult<User[], StandardError>;
|
|
280
|
+
useMergeUsersPreview(keepId: string, duplicateId: string): UseQueryResult<UserMergeSummary, StandardError>;
|
|
281
|
+
useMergeUsers(): ReturnType<typeof useMutation<UserMergeSummary, StandardError, {
|
|
282
|
+
keepId: string;
|
|
283
|
+
duplicateId: string;
|
|
284
|
+
}>>;
|
|
280
285
|
useReviewProposal(proposal_id: string): ReturnType<typeof useMutation<{
|
|
281
286
|
msg: string;
|
|
282
287
|
bill_id?: string;
|
|
@@ -647,6 +652,14 @@ declare module './QueryClient.js' {
|
|
|
647
652
|
user_id: string;
|
|
648
653
|
data: Partial<UserCompanyAssociation>;
|
|
649
654
|
}>>;
|
|
655
|
+
useAddUserCompany(): ReturnType<typeof useMutation<{
|
|
656
|
+
msg: string;
|
|
657
|
+
id: string;
|
|
658
|
+
}, StandardError, {
|
|
659
|
+
userId: string;
|
|
660
|
+
groupId?: string;
|
|
661
|
+
companyId?: string;
|
|
662
|
+
}>>;
|
|
650
663
|
useRemoveUserCompany(): ReturnType<typeof useMutation<{
|
|
651
664
|
msg: string;
|
|
652
665
|
}, StandardError, {
|
|
@@ -850,10 +863,42 @@ export declare class AvroQueryClient {
|
|
|
850
863
|
token: string;
|
|
851
864
|
cancelToken?: CancelToken;
|
|
852
865
|
}>>;
|
|
853
|
-
|
|
866
|
+
/**
|
|
867
|
+
* Sign in with an Apple identity token. `nonce` is the raw value whose
|
|
868
|
+
* SHA-256 was passed to Apple; the server checks and spends it. With no
|
|
869
|
+
* account for the Apple ID yet this resolves `NEEDS_ACCOUNT` (rather
|
|
870
|
+
* than failing) carrying the handle for `useAppleRegister`.
|
|
871
|
+
*/
|
|
872
|
+
useAppleLogin(): ReturnType<typeof useMutation<AppleLoginResult, StandardError, {
|
|
854
873
|
token: string;
|
|
874
|
+
nonce: string;
|
|
875
|
+
authorizationCode?: string | null;
|
|
855
876
|
cancelToken?: CancelToken;
|
|
856
877
|
}>>;
|
|
878
|
+
/**
|
|
879
|
+
* Create an account for an Apple ID that `useAppleLogin` found no
|
|
880
|
+
* account for, then sign in. Apple only shares the name on the first
|
|
881
|
+
* authorization, so the caller supplies it (prompting when missing).
|
|
882
|
+
*/
|
|
883
|
+
useAppleRegister(): ReturnType<typeof useMutation<LoginResponse, StandardError, {
|
|
884
|
+
appleToken: string;
|
|
885
|
+
firstName: string;
|
|
886
|
+
lastName?: string;
|
|
887
|
+
username?: string;
|
|
888
|
+
inviteToken?: string;
|
|
889
|
+
authorizationCode?: string | null;
|
|
890
|
+
cancelToken?: CancelToken;
|
|
891
|
+
}>>;
|
|
892
|
+
/** Link an Apple ID to the signed-in account (fresh token + raw nonce). */
|
|
893
|
+
useAppleLink(): ReturnType<typeof useMutation<{
|
|
894
|
+
msg: string;
|
|
895
|
+
}, StandardError, AppleLinkProof & {
|
|
896
|
+
cancelToken?: CancelToken;
|
|
897
|
+
}>>;
|
|
898
|
+
/** Unlink the account's Apple ID; the server revokes Apple's grant. */
|
|
899
|
+
useAppleUnlink(): ReturnType<typeof useMutation<{
|
|
900
|
+
msg: string;
|
|
901
|
+
}, StandardError, void>>;
|
|
857
902
|
setTokens(tokens: Tokens): Promise<void>;
|
|
858
903
|
setCache(data: Partial<CacheData> | Object): Promise<void>;
|
|
859
904
|
getCache(key?: keyof CacheData | string): Promise<CacheData[keyof CacheData] | Object | string | null>;
|
|
@@ -603,22 +603,53 @@ export class AvroQueryClient {
|
|
|
603
603
|
},
|
|
604
604
|
});
|
|
605
605
|
}
|
|
606
|
+
/**
|
|
607
|
+
* Sign in with an Apple identity token. `nonce` is the raw value whose
|
|
608
|
+
* SHA-256 was passed to Apple; the server checks and spends it. With no
|
|
609
|
+
* account for the Apple ID yet this resolves `NEEDS_ACCOUNT` (rather
|
|
610
|
+
* than failing) carrying the handle for `useAppleRegister`.
|
|
611
|
+
*/
|
|
606
612
|
useAppleLogin() {
|
|
607
613
|
const queryClient = this.getQueryClient();
|
|
608
614
|
return useMutation({
|
|
609
|
-
mutationFn: async ({ token, cancelToken, }) => {
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
615
|
+
mutationFn: async ({ token, nonce, authorizationCode, cancelToken, }) => {
|
|
616
|
+
let resp;
|
|
617
|
+
try {
|
|
618
|
+
resp = await this.post({
|
|
619
|
+
path: '/apple/login',
|
|
620
|
+
data: JSON.stringify({
|
|
621
|
+
token,
|
|
622
|
+
nonce,
|
|
623
|
+
authorization_code: authorizationCode ?? undefined,
|
|
624
|
+
}),
|
|
625
|
+
cancelToken,
|
|
626
|
+
headers: { 'Content-Type': 'application/json' },
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
catch (err) {
|
|
630
|
+
const body = err instanceof StandardError ? err.body : undefined;
|
|
631
|
+
if (err instanceof StandardError &&
|
|
632
|
+
err.status === 404 &&
|
|
633
|
+
body &&
|
|
634
|
+
typeof body.apple_token === 'string') {
|
|
635
|
+
const notFound = body;
|
|
636
|
+
return {
|
|
637
|
+
status: 'NEEDS_ACCOUNT',
|
|
638
|
+
apple_token: notFound.apple_token,
|
|
639
|
+
email: notFound.email ?? null,
|
|
640
|
+
is_private_email: Boolean(notFound.is_private_email),
|
|
641
|
+
};
|
|
614
642
|
}
|
|
643
|
+
throw err;
|
|
644
|
+
}
|
|
645
|
+
if (!resp || !('access_token' in resp)) {
|
|
615
646
|
throw new StandardError(401, 'Invalid Apple login response');
|
|
616
647
|
}
|
|
617
648
|
await this.loginSuccess({
|
|
618
649
|
access_token: resp.access_token,
|
|
619
650
|
refresh_token: resp.refresh_token,
|
|
620
651
|
});
|
|
621
|
-
return LoginResponse.SUCCESS;
|
|
652
|
+
return { status: LoginResponse.SUCCESS };
|
|
622
653
|
},
|
|
623
654
|
onSettled: () => {
|
|
624
655
|
queryClient.invalidateQueries();
|
|
@@ -629,6 +660,77 @@ export class AvroQueryClient {
|
|
|
629
660
|
},
|
|
630
661
|
});
|
|
631
662
|
}
|
|
663
|
+
/**
|
|
664
|
+
* Create an account for an Apple ID that `useAppleLogin` found no
|
|
665
|
+
* account for, then sign in. Apple only shares the name on the first
|
|
666
|
+
* authorization, so the caller supplies it (prompting when missing).
|
|
667
|
+
*/
|
|
668
|
+
useAppleRegister() {
|
|
669
|
+
const queryClient = this.getQueryClient();
|
|
670
|
+
return useMutation({
|
|
671
|
+
mutationFn: async ({ appleToken, firstName, lastName, username, inviteToken, authorizationCode, cancelToken, }) => {
|
|
672
|
+
const resp = await this.post({
|
|
673
|
+
path: '/apple/register',
|
|
674
|
+
data: JSON.stringify({
|
|
675
|
+
apple_token: appleToken,
|
|
676
|
+
first_name: firstName,
|
|
677
|
+
last_name: lastName,
|
|
678
|
+
username,
|
|
679
|
+
invite_token: inviteToken,
|
|
680
|
+
authorization_code: authorizationCode ?? undefined,
|
|
681
|
+
}),
|
|
682
|
+
cancelToken,
|
|
683
|
+
headers: { 'Content-Type': 'application/json' },
|
|
684
|
+
});
|
|
685
|
+
if (!resp || !('access_token' in resp)) {
|
|
686
|
+
throw new StandardError(401, 'Invalid Apple sign-up response');
|
|
687
|
+
}
|
|
688
|
+
await this.loginSuccess({
|
|
689
|
+
access_token: resp.access_token,
|
|
690
|
+
refresh_token: resp.refresh_token,
|
|
691
|
+
});
|
|
692
|
+
return LoginResponse.SUCCESS;
|
|
693
|
+
},
|
|
694
|
+
onSettled: () => {
|
|
695
|
+
queryClient.invalidateQueries();
|
|
696
|
+
},
|
|
697
|
+
onError: (err) => {
|
|
698
|
+
console.error('Apple sign-up failed:', err);
|
|
699
|
+
},
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
/** Link an Apple ID to the signed-in account (fresh token + raw nonce). */
|
|
703
|
+
useAppleLink() {
|
|
704
|
+
return useMutation({
|
|
705
|
+
mutationFn: async ({ cancelToken, ...proof }) => {
|
|
706
|
+
return this.post({
|
|
707
|
+
path: '/apple/link',
|
|
708
|
+
data: JSON.stringify({
|
|
709
|
+
...('appleToken' in proof
|
|
710
|
+
? { apple_token: proof.appleToken }
|
|
711
|
+
: { token: proof.token, nonce: proof.nonce }),
|
|
712
|
+
authorization_code: proof.authorizationCode ?? undefined,
|
|
713
|
+
}),
|
|
714
|
+
cancelToken,
|
|
715
|
+
headers: { 'Content-Type': 'application/json' },
|
|
716
|
+
});
|
|
717
|
+
},
|
|
718
|
+
onSettled: () => {
|
|
719
|
+
this.syncAfterMutation('user');
|
|
720
|
+
},
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
/** Unlink the account's Apple ID; the server revokes Apple's grant. */
|
|
724
|
+
useAppleUnlink() {
|
|
725
|
+
return useMutation({
|
|
726
|
+
mutationFn: async () => {
|
|
727
|
+
return this.delete({ path: '/apple/link' });
|
|
728
|
+
},
|
|
729
|
+
onSettled: () => {
|
|
730
|
+
this.syncAfterMutation('user');
|
|
731
|
+
},
|
|
732
|
+
});
|
|
733
|
+
}
|
|
632
734
|
setTokens(tokens) {
|
|
633
735
|
return this.config.authManager.setTokens(tokens);
|
|
634
736
|
}
|
|
@@ -151,6 +151,24 @@ AvroQueryClient.prototype.useCreateUserCompany = function () {
|
|
|
151
151
|
},
|
|
152
152
|
});
|
|
153
153
|
};
|
|
154
|
+
/**
|
|
155
|
+
* Add an existing user to a company (the current one by default), optionally
|
|
156
|
+
* straight into a group such as a user type, in a single request.
|
|
157
|
+
*/
|
|
158
|
+
AvroQueryClient.prototype.useAddUserCompany = function () {
|
|
159
|
+
return useMutation({
|
|
160
|
+
mutationFn: async ({ userId, groupId, companyId, }) => {
|
|
161
|
+
return this.post({
|
|
162
|
+
path: `/company/${companyId ?? this.companyId}/user/${userId}`,
|
|
163
|
+
data: JSON.stringify({ user_id: userId, ...(groupId ? { group: groupId } : {}) }),
|
|
164
|
+
headers: { 'Content-Type': 'application/json' },
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
onSuccess: () => {
|
|
168
|
+
this.syncAfterMutation('member', 'company', 'group');
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
};
|
|
154
172
|
AvroQueryClient.prototype.useRemoveUserCompany = function () {
|
|
155
173
|
const queryClient = this.getQueryClient();
|
|
156
174
|
return useMutation({
|
|
@@ -20,6 +20,35 @@ AvroQueryClient.prototype.useSearchUsers = function (searchUsername) {
|
|
|
20
20
|
enabled: Boolean(searchUsername),
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
+
/** Root only: what merging `duplicateId` into `keepId` would move. Changes nothing. */
|
|
24
|
+
AvroQueryClient.prototype.useMergeUsersPreview = function (keepId, duplicateId) {
|
|
25
|
+
return useQuery({
|
|
26
|
+
queryKey: ['users', 'merge', keepId, duplicateId],
|
|
27
|
+
queryFn: () => this.post({
|
|
28
|
+
path: `/user/${keepId}/merge`,
|
|
29
|
+
data: JSON.stringify({ duplicate: duplicateId, dry_run: true }),
|
|
30
|
+
headers: { 'Content-Type': 'application/json' },
|
|
31
|
+
idempotent: true,
|
|
32
|
+
}),
|
|
33
|
+
enabled: Boolean(keepId && duplicateId),
|
|
34
|
+
// A refusal (same account, root user) won't change on retry.
|
|
35
|
+
retry: false,
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
/** Root only: merge `duplicateId` into `keepId`, then delete the duplicate. */
|
|
39
|
+
AvroQueryClient.prototype.useMergeUsers = function () {
|
|
40
|
+
const queryClient = this.getQueryClient();
|
|
41
|
+
return useMutation({
|
|
42
|
+
mutationFn: ({ keepId, duplicateId }) => this.post({
|
|
43
|
+
path: `/user/${keepId}/merge`,
|
|
44
|
+
data: JSON.stringify({ duplicate: duplicateId, dry_run: false }),
|
|
45
|
+
headers: { 'Content-Type': 'application/json' },
|
|
46
|
+
}),
|
|
47
|
+
onSuccess: () => {
|
|
48
|
+
queryClient.invalidateQueries({ queryKey: ['users'] });
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
};
|
|
23
52
|
AvroQueryClient.prototype.useGetSelf = function () {
|
|
24
53
|
return useQuery({
|
|
25
54
|
queryKey: ['user'],
|
package/dist/types/api/User.d.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What merging a duplicate account into another moves (`POST
|
|
3
|
+
* /user/{keepId}/merge`). The same shape answers the dry-run preview.
|
|
4
|
+
*/
|
|
5
|
+
export interface UserMergeSummary {
|
|
6
|
+
msg: string;
|
|
7
|
+
/** Rows moved per table, keyed by table name; tables with none are left out. */
|
|
8
|
+
rows: Record<string, number>;
|
|
9
|
+
/** Companies only the duplicate belonged to; the kept account joins them. */
|
|
10
|
+
companies_moved: string[];
|
|
11
|
+
/** Companies both belonged to; the duplicate's membership is folded in. */
|
|
12
|
+
companies_folded: string[];
|
|
13
|
+
/** Saved payment methods removed with the duplicate's Stripe customer. */
|
|
14
|
+
payment_methods_dropped: number;
|
|
15
|
+
/** `moved` to the kept account, or `revoked` because it already has one. */
|
|
16
|
+
apple_identity: 'moved' | 'revoked' | null;
|
|
17
|
+
microsoft_identity_moved: boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/api.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './api/_Event.js';
|
|
|
5
5
|
export * from './api/AdditionalCharge.js';
|
|
6
6
|
export * from './api/DelayEvent.js';
|
|
7
7
|
export * from './api/Device.js';
|
|
8
|
+
export * from './api/UserMerge.js';
|
|
8
9
|
export * from './api/Address.js';
|
|
9
10
|
export * from './api/Avro.js';
|
|
10
11
|
export * from './api/AuditLog.js';
|
|
@@ -56,6 +57,31 @@ export declare const LoginResponse: {
|
|
|
56
57
|
readonly NEEDS_TOTP: "NEEDS_TOTP";
|
|
57
58
|
};
|
|
58
59
|
export type LoginResponse = (typeof LoginResponse)[keyof typeof LoginResponse];
|
|
60
|
+
/**
|
|
61
|
+
* Outcome of `useAppleLogin`. With no account for the Apple ID yet,
|
|
62
|
+
* `apple_token` is a one-time handle (10 min) for `useAppleRegister`, or for
|
|
63
|
+
* `useAppleLink` after signing in another way.
|
|
64
|
+
*/
|
|
65
|
+
export type AppleLoginResult = {
|
|
66
|
+
status: typeof LoginResponse.SUCCESS;
|
|
67
|
+
} | {
|
|
68
|
+
status: 'NEEDS_ACCOUNT';
|
|
69
|
+
apple_token: string;
|
|
70
|
+
email: string | null;
|
|
71
|
+
is_private_email: boolean;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Proof of the Apple ID `useAppleLink` attaches: a fresh identity token and
|
|
75
|
+
* its raw nonce, or the `apple_token` handle from a `NEEDS_ACCOUNT` sign-in.
|
|
76
|
+
*/
|
|
77
|
+
export type AppleLinkProof = {
|
|
78
|
+
token: string;
|
|
79
|
+
nonce: string;
|
|
80
|
+
authorizationCode?: string | null;
|
|
81
|
+
} | {
|
|
82
|
+
appleToken: string;
|
|
83
|
+
authorizationCode?: string | null;
|
|
84
|
+
};
|
|
59
85
|
export interface ApiInfo {
|
|
60
86
|
app_semver: string;
|
|
61
87
|
build_time: string;
|
package/dist/types/api.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from './api/_Event.js';
|
|
|
2
2
|
export * from './api/AdditionalCharge.js';
|
|
3
3
|
export * from './api/DelayEvent.js';
|
|
4
4
|
export * from './api/Device.js';
|
|
5
|
+
export * from './api/UserMerge.js';
|
|
5
6
|
export * from './api/Address.js';
|
|
6
7
|
export * from './api/Avro.js';
|
|
7
8
|
export * from './api/AuditLog.js';
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AVRO_JS_VERSION = "1.6.
|
|
1
|
+
export declare const AVRO_JS_VERSION = "1.6.4-rc2";
|
package/dist/version.js
CHANGED