@go-avro/avro-js 1.6.3 → 1.6.4-rc3

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.
Files changed (69) hide show
  1. package/dist/client/QueryClient.d.ts +71 -56
  2. package/dist/client/QueryClient.js +50 -26
  3. package/dist/client/hooks/audit.js +4 -2
  4. package/dist/client/hooks/avro.js +6 -2
  5. package/dist/client/hooks/bills.d.ts +1 -1
  6. package/dist/client/hooks/bills.js +23 -3
  7. package/dist/client/hooks/catalog_items.js +4 -1
  8. package/dist/client/hooks/companies.js +22 -2
  9. package/dist/client/hooks/events.js +7 -5
  10. package/dist/client/hooks/jobs.js +26 -3
  11. package/dist/client/hooks/messages.js +6 -2
  12. package/dist/client/hooks/plans.js +1 -1
  13. package/dist/client/hooks/routes.js +31 -1
  14. package/dist/client/hooks/sessions.js +10 -3
  15. package/dist/client/hooks/skills.js +1 -1
  16. package/dist/client/hooks/timecards.js +2 -1
  17. package/dist/client/hooks/users.js +34 -2
  18. package/dist/client/realtime.js +8 -3
  19. package/dist/client/requests.d.ts +221 -0
  20. package/dist/client/requests.js +5 -0
  21. package/dist/client/wire.d.ts +7 -0
  22. package/dist/client/wire.js +14 -0
  23. package/dist/index.d.ts +1 -0
  24. package/dist/types/api/AdditionalCharge.d.ts +2 -1
  25. package/dist/types/api/Avro.d.ts +33 -28
  26. package/dist/types/api/Bill.d.ts +7 -5
  27. package/dist/types/api/BillPayment.d.ts +8 -4
  28. package/dist/types/api/BillUser.d.ts +3 -2
  29. package/dist/types/api/CatalogItem.d.ts +9 -6
  30. package/dist/types/api/Chat.d.ts +3 -5
  31. package/dist/types/api/Company.d.ts +39 -13
  32. package/dist/types/api/DelayEvent.d.ts +5 -2
  33. package/dist/types/api/Email.d.ts +14 -3
  34. package/dist/types/api/Friendship.d.ts +8 -0
  35. package/dist/types/api/Group.d.ts +3 -2
  36. package/dist/types/api/Job.d.ts +24 -3
  37. package/dist/types/api/LineItem.d.ts +3 -2
  38. package/dist/types/api/MemberState.d.ts +2 -1
  39. package/dist/types/api/Message.d.ts +4 -3
  40. package/dist/types/api/Notification.d.ts +26 -0
  41. package/dist/types/api/PaymentMethod.d.ts +7 -2
  42. package/dist/types/api/PaymentOption.d.ts +6 -4
  43. package/dist/types/api/Payout.d.ts +1 -1
  44. package/dist/types/api/Plan.d.ts +5 -4
  45. package/dist/types/api/PlanPayment.d.ts +5 -3
  46. package/dist/types/api/Prepayment.d.ts +2 -1
  47. package/dist/types/api/Reaction.d.ts +3 -3
  48. package/dist/types/api/Refund.d.ts +1 -1
  49. package/dist/types/api/Route.d.ts +11 -10
  50. package/dist/types/api/Route.js +5 -0
  51. package/dist/types/api/RouteJob.d.ts +1 -1
  52. package/dist/types/api/ServiceMonth.d.ts +2 -2
  53. package/dist/types/api/Session.d.ts +5 -2
  54. package/dist/types/api/Skill.d.ts +2 -2
  55. package/dist/types/api/Subscription.d.ts +5 -3
  56. package/dist/types/api/Task.d.ts +10 -9
  57. package/dist/types/api/Task.js +3 -1
  58. package/dist/types/api/TimecardAction.d.ts +2 -2
  59. package/dist/types/api/User.d.ts +11 -9
  60. package/dist/types/api/UserCompanyAssociation.d.ts +7 -1
  61. package/dist/types/api/UserMerge.d.ts +18 -0
  62. package/dist/types/api/UserMerge.js +1 -0
  63. package/dist/types/api/_Event.d.ts +20 -4
  64. package/dist/types/api/_Event.js +1 -0
  65. package/dist/types/api.d.ts +60 -29
  66. package/dist/types/api.js +1 -0
  67. package/dist/version.d.ts +1 -1
  68. package/dist/version.js +1 -1
  69. 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, 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, CompanySummary, 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';
@@ -11,6 +11,7 @@ import { Proposal } from '../types/api/Proposal.js';
11
11
  import { ProposalTerms } from '../types/api/ProposalTerms.js';
12
12
  import type { EmailSucceededPayload, EmailFailedPayload, EmailType } from '../types/api/EmailNotification.js';
13
13
  import type { BulkDeleteBillsResponse, BulkEmailBillsResponse } from './hooks/bills.js';
14
+ import type { BillWritePayload, CatalogItemCreatePayload, CatalogItemUpdatePayload, CompanyCreatePayload, EventCreatePayload, IntuitImportResult, PayoutStatusFilter, ProposalReviewPayload, ProposalWritePayload, SkillCreatePayload, SkillUpdatePayload, UserCreatePayload, UserUpdatePayload } from './requests.js';
14
15
  import { type QueryPersistOptions } from './persist.js';
15
16
  export interface TrackEmailOptions {
16
17
  emailType?: EmailType;
@@ -146,7 +147,7 @@ declare module './QueryClient.js' {
146
147
  useGetPayouts(body: {
147
148
  amt?: number;
148
149
  query?: string;
149
- status?: string;
150
+ status?: PayoutStatusFilter | '';
150
151
  known_ids?: string[];
151
152
  unknown_ids?: string[];
152
153
  created_from?: number;
@@ -178,14 +179,15 @@ declare module './QueryClient.js' {
178
179
  offset?: number;
179
180
  }, total: number, onProgress?: (fraction: number) => void): UseQueryResult<Group[], StandardError>;
180
181
  useGetPlans(code: string): UseQueryResult<Plan[], StandardError>;
181
- useGetCompanies(options?: {}): UseQueryResult<Company[], StandardError>;
182
+ useGetCompanies(options?: {}): UseQueryResult<CompanySummary[], StandardError>;
182
183
  generatePDFFromBackend({ billId }: {
183
184
  billId: string;
184
185
  }): Promise<Blob>;
185
186
  sendBillingEmail(options: {
186
187
  billId: string;
187
188
  subject?: string;
188
- recipients?: string[][];
189
+ /** `[name, email]` pairs; omitted: the bill's own recipients. */
190
+ recipients?: [string, string][];
189
191
  request_id?: string;
190
192
  }): Promise<{
191
193
  msg: string;
@@ -193,10 +195,12 @@ declare module './QueryClient.js' {
193
195
  useGetProposal(proposal_id: string): UseQueryResult<Proposal, StandardError>;
194
196
  useGetProposalTerms(): UseQueryResult<ProposalTerms[], StandardError>;
195
197
  useCreateProposalTerms(): ReturnType<typeof useMutation<{
198
+ msg: string;
196
199
  id: string;
197
200
  }, StandardError, {
198
201
  name: string;
199
202
  body: string;
203
+ archived?: boolean;
200
204
  }>>;
201
205
  useUpdateProposalTerms(): ReturnType<typeof useMutation<{
202
206
  msg: string;
@@ -277,18 +281,15 @@ declare module './QueryClient.js' {
277
281
  cleared: number;
278
282
  }, StandardError, void>>;
279
283
  useSearchUsers(searchUsername: string): UseQueryResult<User[], StandardError>;
284
+ useMergeUsersPreview(keepId: string, duplicateId: string): UseQueryResult<UserMergeSummary, StandardError>;
285
+ useMergeUsers(): ReturnType<typeof useMutation<UserMergeSummary, StandardError, {
286
+ keepId: string;
287
+ duplicateId: string;
288
+ }>>;
280
289
  useReviewProposal(proposal_id: string): ReturnType<typeof useMutation<{
281
290
  msg: string;
282
291
  bill_id?: string;
283
- }, StandardError, {
284
- tasks: {
285
- id: string;
286
- status: string;
287
- payment_option_id: string;
288
- }[];
289
- terms_version_id?: string;
290
- pay_in_cash?: boolean;
291
- }>>;
292
+ }, StandardError, ProposalReviewPayload>>;
292
293
  useCreateMessage(chatId: string): ReturnType<typeof useMutation<{
293
294
  msg?: string;
294
295
  id: string;
@@ -298,36 +299,47 @@ declare module './QueryClient.js' {
298
299
  id?: string;
299
300
  }>>;
300
301
  useCreateProposal(): ReturnType<typeof useMutation<{
302
+ msg: string;
301
303
  id: string;
302
304
  }, StandardError, {
303
305
  job_id: string;
304
- data: Record<string, any>;
306
+ data: ProposalWritePayload;
305
307
  }>>;
306
308
  useCreateGroup(): ReturnType<typeof useMutation<{
309
+ msg: string;
307
310
  id: string;
308
311
  }, StandardError, {
309
- groupData: Partial<Group>;
312
+ groupData: Partial<Group> & {
313
+ name: string;
314
+ };
310
315
  }>>;
311
316
  useCreateWaiver(): ReturnType<typeof useMutation<{
317
+ msg: string;
312
318
  id: string;
313
319
  }, StandardError, {
314
- waiverData: Partial<Waiver>;
320
+ waiverData: Partial<Waiver> & {
321
+ name: string;
322
+ };
315
323
  }>>;
316
324
  useCreateLabel(): ReturnType<typeof useMutation<{
325
+ msg: string;
317
326
  id: string;
318
327
  }, StandardError, {
319
- labelData: Partial<Label>;
328
+ labelData: Partial<Label> & {
329
+ name: string;
330
+ };
320
331
  }>>;
321
332
  useCreateSkill(): ReturnType<typeof useMutation<{
333
+ msg: string;
322
334
  id: string;
323
335
  }, StandardError, {
324
- skillData: Partial<Skill>;
336
+ skillData: SkillCreatePayload;
325
337
  }>>;
326
338
  useCreateEvent(): ReturnType<typeof useMutation<{
327
339
  id: string;
328
340
  msg: string;
329
341
  }, StandardError, {
330
- eventData: Partial<_Event>;
342
+ eventData: EventCreatePayload;
331
343
  }>>;
332
344
  useCreateDelayEvent(): ReturnType<typeof useMutation<{
333
345
  id: string;
@@ -336,7 +348,8 @@ declare module './QueryClient.js' {
336
348
  delayData: DelayEventCreatePayload;
337
349
  }>>;
338
350
  useCreateUserSession(): ReturnType<typeof useMutation<{
339
- id: string;
351
+ msg: string;
352
+ id: string | null;
340
353
  }, StandardError, {
341
354
  sessionData: Partial<Session>;
342
355
  }>>;
@@ -353,61 +366,58 @@ declare module './QueryClient.js' {
353
366
  };
354
367
  }>>;
355
368
  useCreateBill(): ReturnType<typeof useMutation<{
369
+ msg: string;
356
370
  id: string;
357
371
  invoice_id: number;
358
372
  }, StandardError, {
359
- data: Partial<Bill>;
373
+ data: BillWritePayload;
360
374
  }>>;
361
375
  useCreateCompany(): ReturnType<typeof useMutation<{
376
+ msg: string;
362
377
  id: string;
363
378
  }, StandardError, {
364
- companyData: Partial<Company | {
365
- logo: File | null;
366
- }>;
379
+ companyData: CompanyCreatePayload;
367
380
  }>>;
368
381
  useCreateCatalogItem(): ReturnType<typeof useMutation<{
382
+ msg: string;
369
383
  id: string;
370
384
  }, StandardError, {
371
- data: Partial<CatalogItem>;
385
+ data: CatalogItemCreatePayload;
372
386
  }>>;
373
387
  useCreateJob(): ReturnType<typeof useMutation<{
388
+ msg: string;
374
389
  id: string;
375
390
  }, StandardError, {
376
- jobData: Partial<Job>;
391
+ jobData: JobUpdate;
377
392
  }>>;
378
393
  useCreateRoute(): ReturnType<typeof useMutation<{
394
+ msg: string;
379
395
  id: string;
380
396
  }, StandardError, {
381
397
  routeData: RouteWritePayload;
382
398
  }>>;
383
399
  useCreateTeam(): ReturnType<typeof useMutation<{
400
+ msg: string;
384
401
  id: string;
385
402
  }, StandardError, {
386
- teamData: Partial<Team>;
403
+ teamData: Partial<Team> & {
404
+ name: string;
405
+ };
387
406
  }>>;
388
407
  useCreateSelf(): ReturnType<typeof useMutation<{
389
408
  msg: string;
390
409
  id?: string;
391
410
  access_token?: string;
392
411
  refresh_token?: string;
393
- }, StandardError, Partial<User> & {
394
- code?: string;
395
- invite_token?: string;
396
- password?: string;
397
- company_id?: string;
398
- }>>;
412
+ }, StandardError, UserCreatePayload>>;
399
413
  useCreateUser(): ReturnType<typeof useMutation<{
400
414
  msg: string;
401
415
  id?: string;
402
416
  access_token?: string;
403
417
  refresh_token?: string;
404
- }, StandardError, Partial<User> & {
405
- code?: string;
406
- invite_token?: string;
407
- password?: string;
408
- company_id?: string;
409
- }>>;
418
+ }, StandardError, UserCreatePayload>>;
410
419
  useCreateSessionBreak(): ReturnType<typeof useMutation<{
420
+ msg: string;
411
421
  id: string;
412
422
  }, StandardError, {
413
423
  sessionId: string;
@@ -441,7 +451,7 @@ declare module './QueryClient.js' {
441
451
  }>>;
442
452
  useCheckOut(): ReturnType<typeof useMutation<{
443
453
  msg: string;
444
- id: string;
454
+ id: string | null;
445
455
  job_id: string | null;
446
456
  }, StandardError, {
447
457
  checkinId: string;
@@ -453,14 +463,10 @@ declare module './QueryClient.js' {
453
463
  }>;
454
464
  checkOut(checkinId: string): Promise<{
455
465
  msg: string;
456
- id: string;
466
+ id: string | null;
457
467
  job_id: string | null;
458
468
  }>;
459
- useImportBillsFromIntuit(): ReturnType<typeof useMutation<{
460
- msg: string;
461
- imported: number;
462
- skipped: number;
463
- }, StandardError, void>>;
469
+ useImportBillsFromIntuit(): ReturnType<typeof useMutation<IntuitImportResult, StandardError, void>>;
464
470
  useSyncBillToIntuit(): ReturnType<typeof useMutation<{
465
471
  msg: string;
466
472
  }, StandardError, {
@@ -513,7 +519,7 @@ declare module './QueryClient.js' {
513
519
  msg: string;
514
520
  }, StandardError, {
515
521
  catalogItemId: string;
516
- data: Partial<CatalogItem>;
522
+ data: CatalogItemUpdatePayload;
517
523
  }>>;
518
524
  useUpdateJob(): ReturnType<typeof useMutation<{
519
525
  msg: string;
@@ -525,13 +531,13 @@ declare module './QueryClient.js' {
525
531
  msg: string;
526
532
  }, StandardError, {
527
533
  skillId: string;
528
- updates: Partial<Skill>;
534
+ updates: SkillUpdatePayload;
529
535
  }>>;
530
536
  useUpdateBill(): ReturnType<typeof useMutation<{
531
537
  msg: string;
532
538
  }, StandardError, {
533
539
  billId: string;
534
- updates: Partial<Bill>;
540
+ updates: BillWritePayload;
535
541
  }>>;
536
542
  useUpdateBillLineItemStatus(): ReturnType<typeof useMutation<{
537
543
  msg: string;
@@ -622,7 +628,7 @@ declare module './QueryClient.js' {
622
628
  }>>;
623
629
  useUpdateUser(userId: string): ReturnType<typeof useMutation<{
624
630
  msg: string;
625
- }, StandardError, Partial<User>>>;
631
+ }, StandardError, UserUpdatePayload>>;
626
632
  useDeleteJobs(): ReturnType<typeof useMutation<{
627
633
  msg: string;
628
634
  }, StandardError, {
@@ -647,6 +653,14 @@ declare module './QueryClient.js' {
647
653
  user_id: string;
648
654
  data: Partial<UserCompanyAssociation>;
649
655
  }>>;
656
+ useAddUserCompany(): ReturnType<typeof useMutation<{
657
+ msg: string;
658
+ id: string;
659
+ }, StandardError, {
660
+ userId: string;
661
+ groupId?: string;
662
+ companyId?: string;
663
+ }>>;
650
664
  useRemoveUserCompany(): ReturnType<typeof useMutation<{
651
665
  msg: string;
652
666
  }, StandardError, {
@@ -879,10 +893,7 @@ export declare class AvroQueryClient {
879
893
  /** Link an Apple ID to the signed-in account (fresh token + raw nonce). */
880
894
  useAppleLink(): ReturnType<typeof useMutation<{
881
895
  msg: string;
882
- }, StandardError, {
883
- token: string;
884
- nonce: string;
885
- authorizationCode?: string | null;
896
+ }, StandardError, AppleLinkProof & {
886
897
  cancelToken?: CancelToken;
887
898
  }>>;
888
899
  /** Unlink the account's Apple ID; the server revokes Apple's grant. */
@@ -993,9 +1004,12 @@ export declare class AvroQueryClient {
993
1004
  billed?: boolean;
994
1005
  paid?: boolean;
995
1006
  job_id?: string | null;
1007
+ task_id?: string | null;
996
1008
  sort_by?: 'date' | 'amount' | 'name';
997
1009
  direction?: 'asc' | 'desc';
998
1010
  line_item_types?: LineItemType[];
1011
+ created_from?: number;
1012
+ created_to?: number;
999
1013
  }, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
1000
1014
  fetchMonths(body?: {
1001
1015
  amt?: number;
@@ -1032,7 +1046,7 @@ export declare class AvroQueryClient {
1032
1046
  fetchPayouts(body?: {
1033
1047
  amt?: number;
1034
1048
  query?: string;
1035
- status?: string;
1049
+ status?: PayoutStatusFilter | '';
1036
1050
  known_ids?: string[];
1037
1051
  unknown_ids?: string[];
1038
1052
  offset?: number;
@@ -1102,7 +1116,8 @@ export declare class AvroQueryClient {
1102
1116
  sendEmail(emailId: string, formData: FormData, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<void>;
1103
1117
  sendBillEmail(billId: string, body?: {
1104
1118
  subject?: string;
1105
- recipients?: string[][];
1119
+ /** `[name, email]` pairs; omitted: the bill's own recipients. */
1120
+ recipients?: [string, string][];
1106
1121
  base_url?: string;
1107
1122
  request_id?: string;
1108
1123
  }): Promise<void>;
@@ -6,6 +6,7 @@ import { fetchCensusFeatures } from '../census.js';
6
6
  import { LoginResponse, } from '../types/api.js';
7
7
  import { AuthState } from '../types/auth.js';
8
8
  import { StandardError } from '../types/error.js';
9
+ import { withoutEmpty } from './wire.js';
9
10
  import { ChangeApplier, fallbackInvalidate, patchMember, patchMemberLocation, patchTeamLocation, } from './realtime.js';
10
11
  import { QueryPersister } from './persist.js';
11
12
  /** Keep the original status (401/403/404/0…) when surfacing a list-fetch failure. */
@@ -40,8 +41,12 @@ function filterLocally(items, body, fields) {
40
41
  /** Translate a legacy camelCase parent filter to the snake_case the backend reads. */
41
42
  function withWireParent(body, legacy, wire) {
42
43
  const { [legacy]: legacyValue, ...rest } = body;
43
- return { ...rest, [wire]: rest[wire] ?? legacyValue ?? undefined };
44
+ // The backend's id filters are UUIDs: '' or null means "no filter",
45
+ // so omit the key rather than send a value it rejects.
46
+ return { ...rest, [wire]: rest[wire] || legacyValue || undefined };
44
47
  }
48
+ /** `ListMessages.amt` upper bound. */
49
+ const MAX_MESSAGES_PER_PAGE = 100;
45
50
  const AUTH_RECHECK_MIN_MS = 2000;
46
51
  const AUTH_RECHECK_MAX_MS = 60000;
47
52
  const SOCKET_AUTH_RETRY_MS = 10000;
@@ -353,21 +358,24 @@ export class AvroQueryClient {
353
358
  this._presencePending.clear();
354
359
  if (!this.companyId || userIds.length === 0)
355
360
  return;
356
- this.post({
357
- path: `/company/${this.companyId}/users`,
358
- data: JSON.stringify({ user_ids: userIds }),
359
- headers: { 'Content-Type': 'application/json' },
360
- idempotent: true,
361
- })
362
- .then((members) => {
363
- if (!Array.isArray(members)) {
364
- markMembersStale();
365
- return;
366
- }
367
- for (const member of members)
368
- patchMember(queryClient, member);
369
- })
370
- .catch(markMembersStale);
361
+ // `ListCompanyUsers.user_ids` holds at most 1000 ids.
362
+ for (let i = 0; i < userIds.length; i += 1000) {
363
+ this.post({
364
+ path: `/company/${this.companyId}/users`,
365
+ data: JSON.stringify({ user_ids: userIds.slice(i, i + 1000) }),
366
+ headers: { 'Content-Type': 'application/json' },
367
+ idempotent: true,
368
+ })
369
+ .then((members) => {
370
+ if (!Array.isArray(members)) {
371
+ markMembersStale();
372
+ return;
373
+ }
374
+ for (const member of members)
375
+ patchMember(queryClient, member);
376
+ })
377
+ .catch(markMembersStale);
378
+ }
371
379
  }, PRESENCE_COALESCE_MS);
372
380
  });
373
381
  on('location_update', (data) => {
@@ -581,7 +589,7 @@ export class AvroQueryClient {
581
589
  const queryClient = this.getQueryClient();
582
590
  return useMutation({
583
591
  mutationFn: async ({ token, cancelToken, }) => {
584
- const resp = await this._xhr('POST', `/google/authorize?token=${token}`, {}, cancelToken, { 'Content-Type': 'application/json' });
592
+ const resp = await this._xhr('POST', `/google/authorize?token=${encodeURIComponent(token)}`, {}, cancelToken, { 'Content-Type': 'application/json' });
585
593
  if (!resp || !('access_token' in resp)) {
586
594
  if (resp.msg === 'TOTP required') {
587
595
  return LoginResponse.NEEDS_TOTP;
@@ -702,13 +710,14 @@ export class AvroQueryClient {
702
710
  /** Link an Apple ID to the signed-in account (fresh token + raw nonce). */
703
711
  useAppleLink() {
704
712
  return useMutation({
705
- mutationFn: async ({ token, nonce, authorizationCode, cancelToken, }) => {
713
+ mutationFn: async ({ cancelToken, ...proof }) => {
706
714
  return this.post({
707
715
  path: '/apple/link',
708
716
  data: JSON.stringify({
709
- token,
710
- nonce,
711
- authorization_code: authorizationCode ?? undefined,
717
+ ...('appleToken' in proof
718
+ ? { apple_token: proof.appleToken }
719
+ : { token: proof.token, nonce: proof.nonce }),
720
+ authorization_code: proof.authorizationCode ?? undefined,
712
721
  }),
713
722
  cancelToken,
714
723
  headers: { 'Content-Type': 'application/json' },
@@ -897,7 +906,7 @@ export class AvroQueryClient {
897
906
  if (!companyIdToUse || companyIdToUse.trim() === '') {
898
907
  throw new StandardError(400, 'Company ID is required');
899
908
  }
900
- return this._fetch('POST', `/company/${companyIdToUse}/jobs`, JSON.stringify(body), cancelToken, {
909
+ return this._fetch('POST', `/company/${companyIdToUse}/jobs`, JSON.stringify(withoutEmpty(body, 'route_id')), cancelToken, {
901
910
  ...headers,
902
911
  'Content-Type': 'application/json',
903
912
  }, true)
@@ -992,7 +1001,16 @@ export class AvroQueryClient {
992
1001
  if (!chatId || chatId.trim() === '') {
993
1002
  throw new StandardError(400, 'Chat ID is required');
994
1003
  }
995
- return this._fetch('POST', `/chat/${chatId}/messages`, JSON.stringify(body), cancelToken, {
1004
+ // `ListMessages`: the keyword field is `keyword`, and `amt` must be 1..100.
1005
+ const { query, amt, ...rest } = body;
1006
+ if (amt !== undefined && amt < 1)
1007
+ return Promise.resolve([]);
1008
+ const wire = {
1009
+ ...rest,
1010
+ ...(amt !== undefined && { amt: Math.min(Math.floor(amt), MAX_MESSAGES_PER_PAGE) }),
1011
+ ...(query && { keyword: query }),
1012
+ };
1013
+ return this._fetch('POST', `/chat/${chatId}/messages`, JSON.stringify(wire), cancelToken, {
996
1014
  ...headers,
997
1015
  'Content-Type': 'application/json',
998
1016
  }, true)
@@ -1049,7 +1067,7 @@ export class AvroQueryClient {
1049
1067
  if (!this.companyId || this.companyId.trim() === '') {
1050
1068
  throw new StandardError(400, 'Company ID is required');
1051
1069
  }
1052
- return this._fetch('POST', `/company/${this.companyId}/events`, JSON.stringify(body), cancelToken, {
1070
+ return this._fetch('POST', `/company/${this.companyId}/events`, JSON.stringify(withoutEmpty(body, 'job_id', 'task_id')), cancelToken, {
1053
1071
  ...headers,
1054
1072
  'Content-Type': 'application/json',
1055
1073
  }, true)
@@ -1068,6 +1086,9 @@ export class AvroQueryClient {
1068
1086
  if (!this.companyId || this.companyId.trim() === '') {
1069
1087
  throw new StandardError(400, 'Company ID is required');
1070
1088
  }
1089
+ // `amt` must be >= 1 here (omit it for every row).
1090
+ if (body.amt !== undefined && body.amt < 1)
1091
+ return Promise.resolve([]);
1071
1092
  return this._fetch('POST', `/company/${this.companyId}/months`, JSON.stringify(withWireParent(body, 'jobId', 'job_id')), cancelToken, {
1072
1093
  ...headers,
1073
1094
  'Content-Type': 'application/json',
@@ -1106,7 +1127,10 @@ export class AvroQueryClient {
1106
1127
  if (!this.companyId || this.companyId.trim() === '') {
1107
1128
  throw new StandardError(400, 'Company ID is required');
1108
1129
  }
1109
- return this._fetch('POST', `/company/${this.companyId}/payouts`, JSON.stringify(body), cancelToken, {
1130
+ // `amt` must be >= 1 here (omit it for every row).
1131
+ if (body.amt !== undefined && body.amt < 1)
1132
+ return Promise.resolve([]);
1133
+ return this._fetch('POST', `/company/${this.companyId}/payouts`, JSON.stringify(withoutEmpty(body, 'status')), cancelToken, {
1110
1134
  ...headers,
1111
1135
  'Content-Type': 'application/json',
1112
1136
  }, true)
@@ -1227,7 +1251,7 @@ export class AvroQueryClient {
1227
1251
  throw new StandardError(400, 'Company ID is required');
1228
1252
  }
1229
1253
  const amount = body.amt ?? Math.max(body.unknown_ids?.length ?? 0, 50);
1230
- return this._fetch('POST', `/company/${companyId}/sessions?amount=${amount}`, JSON.stringify({ ...body, amt: amount }), cancelToken, {
1254
+ return this._fetch('POST', `/company/${companyId}/sessions?amount=${amount}`, JSON.stringify(withoutEmpty({ ...body, amt: amount }, 'user_id')), cancelToken, {
1231
1255
  ...headers,
1232
1256
  'Content-Type': 'application/json',
1233
1257
  }, true)
@@ -8,8 +8,10 @@ const buildQuery = (params) => {
8
8
  search.set('entity_type', params.entityType);
9
9
  if (params?.action)
10
10
  search.set('action', params.action);
11
- if (params?.limit !== undefined)
12
- search.set('limit', String(params.limit));
11
+ // The audit endpoints take an integer `limit` of 1..500.
12
+ if (params?.limit !== undefined) {
13
+ search.set('limit', String(Math.min(Math.max(Math.floor(params.limit), 1), 500)));
14
+ }
13
15
  const encoded = search.toString();
14
16
  return encoded ? `?${encoded}` : '';
15
17
  };
@@ -18,7 +18,8 @@ AvroQueryClient.prototype.useGetErrorLog = function (limit = 200) {
18
18
  queryKey: ['avro', 'errors', limit],
19
19
  queryFn: async () => {
20
20
  const res = await this.get({
21
- path: `/avro/errors?limit=${limit}`,
21
+ // `limit` is an integer of 1..1000.
22
+ path: `/avro/errors?limit=${Math.min(Math.max(Math.floor(limit), 1), 1000)}`,
22
23
  });
23
24
  return res.errors;
24
25
  },
@@ -27,7 +28,10 @@ AvroQueryClient.prototype.useGetErrorLog = function (limit = 200) {
27
28
  AvroQueryClient.prototype.useGetPerformanceMetrics = function ({ limit = 360, refetchInterval, } = {}) {
28
29
  return useQuery({
29
30
  queryKey: ['avro', 'performance', limit],
30
- queryFn: () => this.get({ path: `/avro/performance?limit=${limit}` }),
31
+ // `limit` is an integer of 1..2880.
32
+ queryFn: () => this.get({
33
+ path: `/avro/performance?limit=${Math.min(Math.max(Math.floor(limit), 1), 2880)}`,
34
+ }),
31
35
  staleTime: 0,
32
36
  refetchInterval,
33
37
  });
@@ -10,7 +10,7 @@
10
10
  */
11
11
  export interface BulkBillError {
12
12
  bill_id: string;
13
- invoice_id: number | null;
13
+ invoice_id: number;
14
14
  reason: string;
15
15
  }
16
16
  export interface BulkDeleteBillsResponse {
@@ -4,6 +4,18 @@ import { seedDetails } from '../cache.js';
4
4
  import { restoreNs, snapshotNs } from '../cache.js';
5
5
  import { keys } from '../realtime.js';
6
6
  import { Bill } from '../../types/api.js';
7
+ /**
8
+ * Keep only the `BillLineItemIn` fields, so cached LineItem rows (with
9
+ * `id`, `status`, …) can be passed back as custom items.
10
+ */
11
+ function toBillLineItemInput(item) {
12
+ return {
13
+ name: item.name,
14
+ description: item.description,
15
+ amount: item.amount,
16
+ cost: item.cost,
17
+ };
18
+ }
7
19
  AvroQueryClient.prototype.useGetBills = function (body) {
8
20
  const queryClient = this.getQueryClient();
9
21
  const result = useInfiniteQuery({
@@ -47,13 +59,14 @@ AvroQueryClient.prototype.useCreateBill = function () {
47
59
  const body = {
48
60
  events: data.events ?? [],
49
61
  months: data.months ?? [],
50
- line_items: data.line_items ?? [],
62
+ line_items: (data.line_items ?? []).map(toBillLineItemInput),
51
63
  manual_emails: data.manual_emails ?? [],
52
64
  prepayments: data.prepayments ?? [],
53
65
  enabled_payment_methods: data.enabled_payment_methods ?? [],
54
66
  pass_on_fees: data.pass_on_fees,
55
67
  users: data.users,
56
68
  due_date: data.due_date,
69
+ name: data.name,
57
70
  };
58
71
  return this.post({
59
72
  path: `/company/${this.companyId}/bill`,
@@ -85,15 +98,22 @@ AvroQueryClient.prototype.useUpdateBill = function () {
85
98
  const queryClient = this.getQueryClient();
86
99
  return useMutation({
87
100
  mutationFn: ({ billId, updates }) => {
101
+ const body = updates.line_items
102
+ ? { ...updates, line_items: updates.line_items.map(toBillLineItemInput) }
103
+ : updates;
88
104
  return this.put({
89
105
  path: `/bill/${billId}`,
90
- data: JSON.stringify(updates),
106
+ data: JSON.stringify(body),
91
107
  headers: {
92
108
  'Content-Type': 'application/json',
93
109
  },
94
110
  });
95
111
  },
96
- onMutate: async ({ billId, updates }) => {
112
+ onMutate: async ({ billId, updates: wireUpdates }) => {
113
+ // `users`/`line_items` are request-shaped (user ids + amounts,
114
+ // bare custom items), not the cached BillUser/LineItem rows; the
115
+ // echoed change brings the real ones.
116
+ const { users: _users, line_items: _lineItems, ...updates } = wireUpdates;
97
117
  await queryClient.cancelQueries({ queryKey: ['bills'] });
98
118
  await queryClient.cancelQueries({ queryKey: ['bills', billId] });
99
119
  const previousBills = snapshotNs(queryClient, 'bills');
@@ -43,7 +43,10 @@ AvroQueryClient.prototype.useUpdateCatalogItem = function () {
43
43
  },
44
44
  });
45
45
  },
46
- onMutate: async ({ catalogItemId, data }) => {
46
+ onMutate: async ({ catalogItemId, data: wireData }) => {
47
+ // Enum names and payment options are request-shaped (any case,
48
+ // no ids); only merge the fields stored as sent.
49
+ const { industry: _industry, price_format: _priceFormat, payment_options: _paymentOptions, ...data } = wireData;
47
50
  await queryClient.cancelQueries({ queryKey: ['catalog_items'] });
48
51
  await queryClient.cancelQueries({
49
52
  queryKey: ['catalog_items', catalogItemId],
@@ -68,7 +68,7 @@ AvroQueryClient.prototype.useGetCurrentCompany = function () {
68
68
  AvroQueryClient.prototype.useCreateCompany = function () {
69
69
  const queryClient = this.getQueryClient();
70
70
  return useMutation({
71
- mutationFn: async ({ companyData, }) => {
71
+ mutationFn: async ({ companyData }) => {
72
72
  return this.post({
73
73
  path: `/company`,
74
74
  data: JSON.stringify(companyData),
@@ -101,7 +101,9 @@ AvroQueryClient.prototype.useUpdateCompany = function () {
101
101
  queryClient.setQueryData(['/company/list'], (oldList) => {
102
102
  if (!oldList)
103
103
  return oldList;
104
- return oldList.map((company) => company?.id === companyId ? { ...company, ...companyData } : company);
104
+ // The list only carries {id, name, plan_id, balance}.
105
+ const { name } = companyData;
106
+ return oldList.map((company) => company?.id === companyId && name ? { ...company, name } : company);
105
107
  });
106
108
  return { previousCompany, previousCompanyList };
107
109
  },
@@ -151,6 +153,24 @@ AvroQueryClient.prototype.useCreateUserCompany = function () {
151
153
  },
152
154
  });
153
155
  };
156
+ /**
157
+ * Add an existing user to a company (the current one by default), optionally
158
+ * straight into a group such as a user type, in a single request.
159
+ */
160
+ AvroQueryClient.prototype.useAddUserCompany = function () {
161
+ return useMutation({
162
+ mutationFn: async ({ userId, groupId, companyId, }) => {
163
+ return this.post({
164
+ path: `/company/${companyId ?? this.companyId}/user/${userId}`,
165
+ data: JSON.stringify({ user_id: userId, ...(groupId ? { group: groupId } : {}) }),
166
+ headers: { 'Content-Type': 'application/json' },
167
+ });
168
+ },
169
+ onSuccess: () => {
170
+ this.syncAfterMutation('member', 'company', 'group');
171
+ },
172
+ });
173
+ };
154
174
  AvroQueryClient.prototype.useRemoveUserCompany = function () {
155
175
  const queryClient = this.getQueryClient();
156
176
  return useMutation({