@go-avro/avro-js 1.6.2 → 1.6.3
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 +37 -2
- package/dist/client/QueryClient.js +107 -6
- package/dist/types/api/User.d.ts +4 -0
- package/dist/types/api.d.ts +12 -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, AppleLoginResult, 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';
|
|
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';
|
|
@@ -850,10 +850,45 @@ export declare class AvroQueryClient {
|
|
|
850
850
|
token: string;
|
|
851
851
|
cancelToken?: CancelToken;
|
|
852
852
|
}>>;
|
|
853
|
-
|
|
853
|
+
/**
|
|
854
|
+
* Sign in with an Apple identity token. `nonce` is the raw value whose
|
|
855
|
+
* SHA-256 was passed to Apple; the server checks and spends it. With no
|
|
856
|
+
* account for the Apple ID yet this resolves `NEEDS_ACCOUNT` (rather
|
|
857
|
+
* than failing) carrying the handle for `useAppleRegister`.
|
|
858
|
+
*/
|
|
859
|
+
useAppleLogin(): ReturnType<typeof useMutation<AppleLoginResult, StandardError, {
|
|
854
860
|
token: string;
|
|
861
|
+
nonce: string;
|
|
862
|
+
authorizationCode?: string | null;
|
|
863
|
+
cancelToken?: CancelToken;
|
|
864
|
+
}>>;
|
|
865
|
+
/**
|
|
866
|
+
* Create an account for an Apple ID that `useAppleLogin` found no
|
|
867
|
+
* account for, then sign in. Apple only shares the name on the first
|
|
868
|
+
* authorization, so the caller supplies it (prompting when missing).
|
|
869
|
+
*/
|
|
870
|
+
useAppleRegister(): ReturnType<typeof useMutation<LoginResponse, StandardError, {
|
|
871
|
+
appleToken: string;
|
|
872
|
+
firstName: string;
|
|
873
|
+
lastName?: string;
|
|
874
|
+
username?: string;
|
|
875
|
+
inviteToken?: string;
|
|
876
|
+
authorizationCode?: string | null;
|
|
855
877
|
cancelToken?: CancelToken;
|
|
856
878
|
}>>;
|
|
879
|
+
/** Link an Apple ID to the signed-in account (fresh token + raw nonce). */
|
|
880
|
+
useAppleLink(): ReturnType<typeof useMutation<{
|
|
881
|
+
msg: string;
|
|
882
|
+
}, StandardError, {
|
|
883
|
+
token: string;
|
|
884
|
+
nonce: string;
|
|
885
|
+
authorizationCode?: string | null;
|
|
886
|
+
cancelToken?: CancelToken;
|
|
887
|
+
}>>;
|
|
888
|
+
/** Unlink the account's Apple ID; the server revokes Apple's grant. */
|
|
889
|
+
useAppleUnlink(): ReturnType<typeof useMutation<{
|
|
890
|
+
msg: string;
|
|
891
|
+
}, StandardError, void>>;
|
|
857
892
|
setTokens(tokens: Tokens): Promise<void>;
|
|
858
893
|
setCache(data: Partial<CacheData> | Object): Promise<void>;
|
|
859
894
|
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,76 @@ 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 ({ token, nonce, authorizationCode, cancelToken, }) => {
|
|
706
|
+
return this.post({
|
|
707
|
+
path: '/apple/link',
|
|
708
|
+
data: JSON.stringify({
|
|
709
|
+
token,
|
|
710
|
+
nonce,
|
|
711
|
+
authorization_code: authorizationCode ?? undefined,
|
|
712
|
+
}),
|
|
713
|
+
cancelToken,
|
|
714
|
+
headers: { 'Content-Type': 'application/json' },
|
|
715
|
+
});
|
|
716
|
+
},
|
|
717
|
+
onSettled: () => {
|
|
718
|
+
this.syncAfterMutation('user');
|
|
719
|
+
},
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
/** Unlink the account's Apple ID; the server revokes Apple's grant. */
|
|
723
|
+
useAppleUnlink() {
|
|
724
|
+
return useMutation({
|
|
725
|
+
mutationFn: async () => {
|
|
726
|
+
return this.delete({ path: '/apple/link' });
|
|
727
|
+
},
|
|
728
|
+
onSettled: () => {
|
|
729
|
+
this.syncAfterMutation('user');
|
|
730
|
+
},
|
|
731
|
+
});
|
|
732
|
+
}
|
|
632
733
|
setTokens(tokens) {
|
|
633
734
|
return this.config.authManager.setTokens(tokens);
|
|
634
735
|
}
|
package/dist/types/api/User.d.ts
CHANGED
package/dist/types/api.d.ts
CHANGED
|
@@ -56,6 +56,18 @@ export declare const LoginResponse: {
|
|
|
56
56
|
readonly NEEDS_TOTP: "NEEDS_TOTP";
|
|
57
57
|
};
|
|
58
58
|
export type LoginResponse = (typeof LoginResponse)[keyof typeof LoginResponse];
|
|
59
|
+
/**
|
|
60
|
+
* Outcome of `useAppleLogin`. With no account for the Apple ID yet,
|
|
61
|
+
* `apple_token` is a one-time handle (10 min) for `useAppleRegister`.
|
|
62
|
+
*/
|
|
63
|
+
export type AppleLoginResult = {
|
|
64
|
+
status: typeof LoginResponse.SUCCESS;
|
|
65
|
+
} | {
|
|
66
|
+
status: 'NEEDS_ACCOUNT';
|
|
67
|
+
apple_token: string;
|
|
68
|
+
email: string | null;
|
|
69
|
+
is_private_email: boolean;
|
|
70
|
+
};
|
|
59
71
|
export interface ApiInfo {
|
|
60
72
|
app_semver: string;
|
|
61
73
|
build_time: string;
|
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.3";
|
package/dist/version.js
CHANGED