@go-avro/avro-js 1.6.3 → 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.
@@ -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, 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';
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, {
@@ -879,10 +892,7 @@ export declare class AvroQueryClient {
879
892
  /** Link an Apple ID to the signed-in account (fresh token + raw nonce). */
880
893
  useAppleLink(): ReturnType<typeof useMutation<{
881
894
  msg: string;
882
- }, StandardError, {
883
- token: string;
884
- nonce: string;
885
- authorizationCode?: string | null;
895
+ }, StandardError, AppleLinkProof & {
886
896
  cancelToken?: CancelToken;
887
897
  }>>;
888
898
  /** Unlink the account's Apple ID; the server revokes Apple's grant. */
@@ -702,13 +702,14 @@ export class AvroQueryClient {
702
702
  /** Link an Apple ID to the signed-in account (fresh token + raw nonce). */
703
703
  useAppleLink() {
704
704
  return useMutation({
705
- mutationFn: async ({ token, nonce, authorizationCode, cancelToken, }) => {
705
+ mutationFn: async ({ cancelToken, ...proof }) => {
706
706
  return this.post({
707
707
  path: '/apple/link',
708
708
  data: JSON.stringify({
709
- token,
710
- nonce,
711
- authorization_code: authorizationCode ?? undefined,
709
+ ...('appleToken' in proof
710
+ ? { apple_token: proof.appleToken }
711
+ : { token: proof.token, nonce: proof.nonce }),
712
+ authorization_code: proof.authorizationCode ?? undefined,
712
713
  }),
713
714
  cancelToken,
714
715
  headers: { 'Content-Type': 'application/json' },
@@ -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'],
@@ -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 {};
@@ -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';
@@ -58,7 +59,8 @@ export declare const LoginResponse: {
58
59
  export type LoginResponse = (typeof LoginResponse)[keyof typeof LoginResponse];
59
60
  /**
60
61
  * Outcome of `useAppleLogin`. With no account for the Apple ID yet,
61
- * `apple_token` is a one-time handle (10 min) for `useAppleRegister`.
62
+ * `apple_token` is a one-time handle (10 min) for `useAppleRegister`, or for
63
+ * `useAppleLink` after signing in another way.
62
64
  */
63
65
  export type AppleLoginResult = {
64
66
  status: typeof LoginResponse.SUCCESS;
@@ -68,6 +70,18 @@ export type AppleLoginResult = {
68
70
  email: string | null;
69
71
  is_private_email: boolean;
70
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
+ };
71
85
  export interface ApiInfo {
72
86
  app_semver: string;
73
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.3";
1
+ export declare const AVRO_JS_VERSION = "1.6.4-rc2";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // AUTO-GENERATED by scripts/gen-version.js — do not edit by hand.
2
2
  // Regenerated from package.json by the `prebuild` npm hook.
3
- export const AVRO_JS_VERSION = '1.6.3';
3
+ export const AVRO_JS_VERSION = '1.6.4-rc2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "1.6.3",
3
+ "version": "1.6.4-rc2",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",