@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
@@ -2,6 +2,7 @@ import { useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
2
2
  import { AvroQueryClient } from '../QueryClient.js';
3
3
  import { restoreNs, snapshotNs, seedDetails, removeOptimisticRow } from '../cache.js';
4
4
  import { keys, matchesList } from '../realtime.js';
5
+ import { withoutEmpty } from '../wire.js';
5
6
  import { constructEvent, DelayEvent, Job, LineItemStatus, Task, getTaskOverdueTime, } from '../../types/api.js';
6
7
  const isJobsQuery = (q) => q.queryKey[0] === 'jobs';
7
8
  const isEventsQuery = (q) => q.queryKey[0] === 'events';
@@ -64,11 +65,14 @@ AvroQueryClient.prototype.useCreateEvent = function () {
64
65
  mutationFn: ({ eventData }) => {
65
66
  return this.post({
66
67
  path: `/company/${this.companyId}/event`,
67
- data: JSON.stringify(eventData),
68
+ // `team_id` is a UUID: '' (no team picked) is omitted.
69
+ data: JSON.stringify(withoutEmpty(eventData, 'team_id')),
68
70
  headers: { 'Content-Type': 'application/json' },
69
71
  });
70
72
  },
71
- onMutate: async ({ eventData }) => {
73
+ onMutate: async ({ eventData: wireEventData }) => {
74
+ // Wire-shaped participants must not land in cached _Event.users.
75
+ const { users: _wireUsers, ...eventData } = wireEventData;
72
76
  await queryClient.cancelQueries({ queryKey: ['events'] });
73
77
  const previousJob = queryClient.getQueryData([
74
78
  'jobs',
@@ -77,7 +81,6 @@ AvroQueryClient.prototype.useCreateEvent = function () {
77
81
  const optimisticEvent = constructEvent({
78
82
  ...eventData,
79
83
  id: Math.random().toString(36).substring(2, 11),
80
- company_id: this.companyId,
81
84
  });
82
85
  if (previousJob) {
83
86
  const updatedJob = new Job({
@@ -159,7 +162,6 @@ AvroQueryClient.prototype.useCreateDelayEvent = function () {
159
162
  const optimisticEvent = new DelayEvent({
160
163
  ...delayData,
161
164
  id: Math.random().toString(36).substring(2, 11),
162
- company_id: this.companyId,
163
165
  time_started: now,
164
166
  time_ended: now,
165
167
  cost: 0,
@@ -244,7 +246,7 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
244
246
  mutationFn: ({ eventId, updates }) => {
245
247
  return this.put({
246
248
  path: `/event/${eventId}`,
247
- data: JSON.stringify(updates),
249
+ data: JSON.stringify(withoutEmpty(updates, 'team_id')),
248
250
  headers: { 'Content-Type': 'application/json' },
249
251
  });
250
252
  },
@@ -3,6 +3,7 @@ import { AvroQueryClient } from '../QueryClient.js';
3
3
  import { seedDetails } from '../cache.js';
4
4
  import { keys, constructJob } from '../realtime.js';
5
5
  import { Job } from '../../types/api.js';
6
+ import { withoutEmpty } from '../wire.js';
6
7
  AvroQueryClient.prototype.getJobsFromCache = function (queryClient) {
7
8
  const client = queryClient ?? this.peekQueryClient();
8
9
  if (!client) {
@@ -10,6 +11,28 @@ AvroQueryClient.prototype.getJobsFromCache = function (queryClient) {
10
11
  }
11
12
  return client.getQueryData(keys.list('jobs', this.companyId)) ?? [];
12
13
  };
14
+ /**
15
+ * Omit blank ids from a job write. `UpdateJob`/`ManagedJob` type the job,
16
+ * task, prepayment, owner and catalog item ids as UUIDs; a blank id means
17
+ * "new row" / "none", which is what omitting it says.
18
+ */
19
+ function toJobWire(job) {
20
+ const wire = withoutEmpty(job, 'id', 'owner_id');
21
+ if (!wire.tasks)
22
+ return wire;
23
+ return {
24
+ ...wire,
25
+ tasks: wire.tasks.map((task) => {
26
+ const wireTask = withoutEmpty(task, 'id', 'catalog_item_id');
27
+ return wireTask.prepayments
28
+ ? {
29
+ ...wireTask,
30
+ prepayments: wireTask.prepayments.map((p) => withoutEmpty(p, 'id')),
31
+ }
32
+ : wireTask;
33
+ }),
34
+ };
35
+ }
13
36
  const JOBS_SYNC_CHUNK = 50;
14
37
  const JOBS_SYNC_CONCURRENCY = 3;
15
38
  async function runLimited(items, limit, worker) {
@@ -108,7 +131,7 @@ AvroQueryClient.prototype.useCreateJob = function () {
108
131
  mutationFn: ({ jobData }) => {
109
132
  return this.post({
110
133
  path: `/company/${this.companyId}/job`,
111
- data: JSON.stringify(jobData),
134
+ data: JSON.stringify(toJobWire(jobData)),
112
135
  headers: { 'Content-Type': 'application/json' },
113
136
  });
114
137
  },
@@ -123,7 +146,7 @@ AvroQueryClient.prototype.useManageJobs = function () {
123
146
  mutationFn: ({ jobs }) => {
124
147
  return this.post({
125
148
  path: `/company/${this.companyId}/jobs/manage`,
126
- data: JSON.stringify({ jobs }),
149
+ data: JSON.stringify({ jobs: jobs.map(toJobWire) }),
127
150
  headers: { 'Content-Type': 'application/json' },
128
151
  });
129
152
  },
@@ -138,7 +161,7 @@ AvroQueryClient.prototype.useUpdateJob = function () {
138
161
  mutationFn: ({ jobId, updates }) => {
139
162
  return this.put({
140
163
  path: `/job/${jobId}`,
141
- data: JSON.stringify(updates),
164
+ data: JSON.stringify(toJobWire(updates)),
142
165
  headers: { 'Content-Type': 'application/json' },
143
166
  });
144
167
  },
@@ -4,21 +4,25 @@ import { seedDetails } from '../cache.js';
4
4
  import { keys } from '../realtime.js';
5
5
  AvroQueryClient.prototype.useGetMessages = function (chatId, body) {
6
6
  const queryClient = this.getQueryClient();
7
+ // The backend pages messages 1..100 at a time (default 10); send the
8
+ // page size explicitly so `getNextPageParam` compares against it.
9
+ const amt = Math.min(Math.max(body.amt ?? 50, 1), 100);
7
10
  const result = useInfiniteQuery({
8
11
  queryKey: keys.infinite('messages', chatId, {
9
- amt: body.amt ?? 50,
12
+ amt,
10
13
  known_ids: body.known_ids ?? [],
11
14
  unknown_ids: body.unknown_ids ?? [],
12
15
  query: body.query ?? '',
13
16
  }),
14
17
  initialPageParam: 0,
15
18
  getNextPageParam: (lastPage, allPages) => {
16
- if (lastPage.length < (body.amt ?? 50))
19
+ if (lastPage.length < amt)
17
20
  return undefined;
18
21
  return allPages.flat().length; // next offset
19
22
  },
20
23
  queryFn: ({ pageParam = 0 }) => this.fetchMessages(chatId, {
21
24
  ...body,
25
+ amt,
22
26
  offset: pageParam,
23
27
  }).then((messages) => seedDetails(queryClient, 'message', messages)),
24
28
  enabled: Boolean(chatId),
@@ -3,6 +3,6 @@ import { AvroQueryClient } from '../QueryClient.js';
3
3
  AvroQueryClient.prototype.useGetPlans = function (code) {
4
4
  return useQuery({
5
5
  queryKey: ['plans', code],
6
- queryFn: async () => this.get({ path: `/plans${code ? `?code=${code}` : ''}` }),
6
+ queryFn: async () => this.get({ path: `/plans${code ? `?code=${encodeURIComponent(code)}` : ''}` }),
7
7
  });
8
8
  };
@@ -14,6 +14,36 @@ const dedupeJobTasks = (payload) => payload.jobs
14
14
  : job),
15
15
  }
16
16
  : payload;
17
+ /**
18
+ * Drop `''` task ids from a schedule request: `ScheduleRoutes` types every
19
+ * task id as a UUID, so one blank id (e.g. an unsaved task) would 400 the
20
+ * whole request instead of being skipped.
21
+ */
22
+ const withoutBlankTaskIds = (schedule) => {
23
+ const ids = (list) => list?.filter((id) => id !== '');
24
+ return {
25
+ ...schedule,
26
+ ...(schedule.whitelist && { whitelist: ids(schedule.whitelist) }),
27
+ ...(schedule.blacklist && { blacklist: ids(schedule.blacklist) }),
28
+ ...(schedule.tasks && {
29
+ tasks: schedule.tasks
30
+ .filter((entry) => (typeof entry === 'string' ? entry : entry.task) !== '')
31
+ .map((entry) => typeof entry === 'string'
32
+ ? entry
33
+ : { ...entry, depends_on: ids(entry.depends_on) }),
34
+ }),
35
+ ...(schedule.schedules && {
36
+ schedules: schedule.schedules.map((team) => team.schedule
37
+ ? {
38
+ ...team,
39
+ schedule: team.schedule.map((stop) => stop.type === 'job'
40
+ ? { ...stop, task_ids: ids(stop.task_ids) ?? [] }
41
+ : stop),
42
+ }
43
+ : team),
44
+ }),
45
+ };
46
+ };
17
47
  AvroQueryClient.prototype.useGetRoutes = function (body, total, onProgress) {
18
48
  return useQuery({
19
49
  queryKey: keys.list('routes', this.companyId, {
@@ -128,7 +158,7 @@ AvroQueryClient.prototype.useScheduleRoutes = function () {
128
158
  mutationFn: async ({ schedule }) => {
129
159
  return this.post({
130
160
  path: `/company/${this.companyId}/schedule`,
131
- data: JSON.stringify(schedule),
161
+ data: JSON.stringify(withoutBlankTaskIds(schedule)),
132
162
  headers: { 'Content-Type': 'application/json' },
133
163
  });
134
164
  },
@@ -3,6 +3,7 @@ import { AvroQueryClient } from '../QueryClient.js';
3
3
  import { keys, isListKey } from '../realtime.js';
4
4
  import { removeOptimisticRow, seedDetails } from '../cache.js';
5
5
  import { Session } from '../../types/api.js';
6
+ import { withoutEmpty } from '../wire.js';
6
7
  const NS = 'sessions';
7
8
  function listFilters(body) {
8
9
  return {
@@ -89,13 +90,19 @@ AvroQueryClient.prototype.useGetActiveCompanySessions = function (params = {}) {
89
90
  // Optimistic patch on every cached sessions list; the echoed `changes`
90
91
  // batch settles the cache when the socket is up, else syncAfterMutation
91
92
  // falls back to a refetch.
93
+ /**
94
+ * Session id fields the backend types as UUIDs (`StartSession` /
95
+ * `UpdateSession`); `''` is omitted rather than sent.
96
+ */
97
+ const SESSION_ID_FIELDS = ['team_id', 'route_id', 'current_route_id', 'user_id'];
92
98
  AvroQueryClient.prototype.useCreateUserSession = function () {
93
99
  const queryClient = this.getQueryClient();
94
100
  return useMutation({
95
101
  mutationFn: ({ sessionData }) => {
102
+ // `id` is null only when an already-open session closed mid-request.
96
103
  return this.post({
97
104
  path: `/company/${this.companyId}/session`,
98
- data: JSON.stringify(sessionData),
105
+ data: JSON.stringify(withoutEmpty(sessionData, ...SESSION_ID_FIELDS)),
99
106
  headers: { 'Content-Type': 'application/json' },
100
107
  });
101
108
  },
@@ -167,7 +174,7 @@ AvroQueryClient.prototype.useUpdateUserSession = function () {
167
174
  mutationFn: ({ sessionId, updates }) => {
168
175
  return this.put({
169
176
  path: `/session/${sessionId}`,
170
- data: JSON.stringify(updates),
177
+ data: JSON.stringify(withoutEmpty(updates, ...SESSION_ID_FIELDS)),
171
178
  headers: { 'Content-Type': 'application/json' },
172
179
  });
173
180
  },
@@ -225,7 +232,7 @@ AvroQueryClient.prototype.useUpdateCompanySession = function () {
225
232
  mutationFn: ({ sessionId, updates, companyId, }) => {
226
233
  return this.put({
227
234
  path: `/company/${companyId ?? this.companyId}/session/${sessionId}`,
228
- data: JSON.stringify(updates),
235
+ data: JSON.stringify(withoutEmpty(updates, ...SESSION_ID_FIELDS)),
229
236
  headers: { 'Content-Type': 'application/json' },
230
237
  });
231
238
  },
@@ -51,7 +51,7 @@ AvroQueryClient.prototype.useGetSkills = function (body, total, onProgress) {
51
51
  AvroQueryClient.prototype.useUpdateSkill = function () {
52
52
  const queryClient = this.getQueryClient();
53
53
  return useMutation({
54
- mutationFn: async ({ skillId, updates }) => {
54
+ mutationFn: async ({ skillId, updates, }) => {
55
55
  return this.put({
56
56
  path: `/skill/${skillId}`,
57
57
  data: JSON.stringify(updates),
@@ -1,6 +1,7 @@
1
1
  import { useMutation, useQuery } from '@tanstack/react-query';
2
2
  import { AvroQueryClient } from '../QueryClient.js';
3
3
  import { keys } from '../realtime.js';
4
+ import { withoutEmpty } from '../wire.js';
4
5
  AvroQueryClient.prototype.useGetCompanyTimecards = function (params = {}) {
5
6
  const companyId = params.companyId ?? this.companyId;
6
7
  return useQuery({
@@ -48,7 +49,7 @@ AvroQueryClient.prototype.useCreateTimecard = function () {
48
49
  const targetCompanyId = companyId ?? this.companyId;
49
50
  return this.post({
50
51
  path: `/company/${targetCompanyId}/timecard`,
51
- data: JSON.stringify(data),
52
+ data: JSON.stringify(withoutEmpty(data, 'user_company_id')),
52
53
  headers: { 'Content-Type': 'application/json' },
53
54
  });
54
55
  },
@@ -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'],
@@ -79,7 +108,9 @@ AvroQueryClient.prototype.useUpdateUser = function (userId) {
79
108
  headers: { 'Content-Type': 'application/json' },
80
109
  });
81
110
  },
82
- onMutate: async (data) => {
111
+ onMutate: async (wireData) => {
112
+ // Credentials are request-only; keep them out of the cache.
113
+ const { password: _password, current_password: _currentPassword, apple_token: _appleToken, apple_nonce: _appleNonce, ...data } = wireData;
83
114
  await queryClient.cancelQueries({ queryKey: ['user'] });
84
115
  await queryClient.cancelQueries({ queryKey: ['users', userId] });
85
116
  const previousSelf = queryClient.getQueryData(['user']);
@@ -184,7 +215,8 @@ AvroQueryClient.prototype.useGetCompanyUsers = function (body = {}) {
184
215
  queryKey: ['users', 'company', this.companyId, body.query ?? '', body.user_ids ?? null],
185
216
  queryFn: () => this.post({
186
217
  path: `/company/${this.companyId}/users`,
187
- data: JSON.stringify(body),
218
+ // `enabled` is a hook option, not a `ListCompanyUsers` field.
219
+ data: JSON.stringify({ query: body.query, user_ids: body.user_ids }),
188
220
  headers: { 'Content-Type': 'application/json' },
189
221
  }),
190
222
  enabled: Boolean(this.companyId) && (body.enabled ?? true),
@@ -45,13 +45,13 @@ export function constructJob(raw) {
45
45
  const job = new Job(raw);
46
46
  job.current_event = job.tasks.reduce((latest, task) => {
47
47
  return task.current_event &&
48
- (!latest || task.current_event.time_started > latest.time_started)
48
+ (!latest || (task.current_event.time_started ?? 0) > (latest.time_started ?? 0))
49
49
  ? task.current_event
50
50
  : latest;
51
51
  }, job.current_event);
52
52
  job.last_completed_event = job.tasks.reduce((latest, task) => {
53
53
  return task.last_completed_event &&
54
- (!latest || task.last_completed_event.time_started > latest.time_started)
54
+ (!latest || (task.last_completed_event.time_started ?? 0) > (latest.time_started ?? 0))
55
55
  ? task.last_completed_event
56
56
  : latest;
57
57
  }, job.last_completed_event);
@@ -176,7 +176,12 @@ function matchPayouts(filters, item) {
176
176
  return 'unknown';
177
177
  return searchAware(filters);
178
178
  }
179
- const bulk = (method, extra = {}) => (client, ids) => client[method]({ ...extra, unknown_ids: ids, amt: ids.length });
179
+ const bulk = (method, extra = {}) => (client, ids) =>
180
+ // List endpoints reject `amt: 0` (payouts/months require amt >= 1),
181
+ // and an empty `unknown_ids` would mean "no id filter" anyway.
182
+ ids.length === 0
183
+ ? Promise.resolve([])
184
+ : client[method]({ ...extra, unknown_ids: ids, amt: ids.length });
180
185
  /** Line-item list endpoints default to unbilled-only: ask for every bucket. */
181
186
  const ALL_LINE_ITEM_STATUSES = { unbilled: true, billed: true, paid: true };
182
187
  /** Single-entity GET (404/403 is treated as gone by the applier). */
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Request bodies and endpoint-specific responses of the REST API, matching
3
+ * the backend's pydantic schemas (`avro/views/<domain>/schemas.py`).
4
+ */
5
+ import type { CatalogIndustry, CatalogPriceFormat, EventUpdatePayload, PaymentType, TaskStatus, User } from '../types/api.js';
6
+ /** Body of `POST /company/<id>/skill` (backend `CreateSkill`). */
7
+ export interface SkillCreatePayload {
8
+ /** 1–255 characters. */
9
+ name: string;
10
+ /** At most 1023 characters. */
11
+ description?: string | null;
12
+ }
13
+ /** Body of `PUT /skill/<id>` (backend `UpdateSkill`); omitted fields are unchanged. */
14
+ export type SkillUpdatePayload = Partial<SkillCreatePayload>;
15
+ /** `status` filter of `POST /company/<id>/payouts` (backend `PayoutsListBody`). */
16
+ export type PayoutStatusFilter = 'paid' | 'pending' | 'in_transit' | 'canceled' | 'failed';
17
+ /**
18
+ * Body of `POST /company/<id>/event` (backend `CreateCompanyEvent`): the
19
+ * `UpdateEvent` fields plus the job. `team_id: ''` is omitted by the SDK.
20
+ */
21
+ export type EventCreatePayload = EventUpdatePayload & {
22
+ job_id: string;
23
+ };
24
+ /**
25
+ * Body of `POST /company` (backend `CreateCompany`). `logo` is not read by
26
+ * this endpoint (upload it with `POST /company/<id>/logo`); it is accepted
27
+ * here only so existing callers type-check.
28
+ */
29
+ export interface CompanyCreatePayload {
30
+ /** 1–256 characters. */
31
+ name: string;
32
+ /** Referral code; unknown codes are ignored. */
33
+ code?: string | null;
34
+ /** IANA zone name. */
35
+ timezone?: string | null;
36
+ overdue_threshold?: number | null;
37
+ delay_scalar?: number | null;
38
+ /** Plan GUID to subscribe to. */
39
+ plan?: string | null;
40
+ logo?: File | null;
41
+ }
42
+ /**
43
+ * Body of `POST /user` (backend `CreateUser`). `password` and `last_name`
44
+ * may be empty; `email` must look like an address; `phone_number` must be a
45
+ * real number with country code (e.g. `+1 616-555-0100`).
46
+ */
47
+ export interface UserCreatePayload {
48
+ /** 1–150 characters. */
49
+ username: string;
50
+ /** At most 100 characters. */
51
+ first_name: string;
52
+ /** At most 100 characters. */
53
+ last_name: string;
54
+ password: string;
55
+ email: string;
56
+ phone_number?: string | null;
57
+ /** Referral code. */
58
+ code?: string | null;
59
+ /** Company GUID to join as a customer. */
60
+ company_id?: string | null;
61
+ invite_token?: string | null;
62
+ share_location?: boolean | null;
63
+ share_email?: boolean | null;
64
+ share_phone?: boolean | null;
65
+ share_with_public?: boolean | null;
66
+ }
67
+ /**
68
+ * Body of `PUT /user/<id>` (backend `UpdateUser`): profile fields plus the
69
+ * credentials a password/email change needs. `phone_number: ''` leaves the
70
+ * number unchanged; a new `password` must be non-empty.
71
+ */
72
+ export type UserUpdatePayload = Partial<User> & {
73
+ password?: string;
74
+ current_password?: string;
75
+ /** A fresh Apple identity token, instead of `current_password`. */
76
+ apple_token?: string;
77
+ apple_nonce?: string;
78
+ };
79
+ /** A custom line item on a bill write (backend `BillLineItemIn`). */
80
+ export interface BillLineItemInput {
81
+ name?: string;
82
+ description?: string;
83
+ /** Quantity; may be fractional (e.g. hours). */
84
+ amount?: number;
85
+ /** Unit price in integer cents. */
86
+ cost?: number;
87
+ }
88
+ /** A member recipient on a bill write (backend `BillUserIn`). */
89
+ export interface BillUserInput {
90
+ /** The member's user GUID. */
91
+ id: string;
92
+ /**
93
+ * Create only: charge up to this many integer cents (>= 0) to the
94
+ * user's autopay method. Fractional values are rejected.
95
+ */
96
+ amt?: number | null;
97
+ }
98
+ /**
99
+ * Body of `POST /company/<id>/bill` and `PUT /bill/<id>` (backend
100
+ * `CreateBill` / `UpdateBill`); omitted or null fields are unchanged.
101
+ */
102
+ export interface BillWritePayload {
103
+ /** Event GUIDs; replaces the bill's events. */
104
+ events?: string[] | null;
105
+ /** Service month GUIDs. */
106
+ months?: string[] | null;
107
+ /** Prepayment GUIDs. */
108
+ prepayments?: string[] | null;
109
+ /** Replaces the bill's custom line items. */
110
+ line_items?: BillLineItemInput[] | null;
111
+ /** Extra recipients as `[name, email]` pairs. */
112
+ manual_emails?: [string, string][] | null;
113
+ users?: BillUserInput[] | null;
114
+ /** At most 256 characters. */
115
+ name?: string | null;
116
+ /** Marks every item paid outside Avro. */
117
+ status?: 'MANUALLY_PAID' | null;
118
+ /** Unix seconds. */
119
+ due_date?: number | null;
120
+ /** Empty means the company's defaults. */
121
+ enabled_payment_methods?: PaymentType[] | null;
122
+ pass_on_fees?: boolean | null;
123
+ }
124
+ /** Response of `POST /company/<id>/intuit/import` (backend `IntuitImportResult`). */
125
+ export interface IntuitImportResult {
126
+ msg: string;
127
+ imported: number;
128
+ skipped: number;
129
+ payments_imported: number;
130
+ payments_skipped: number;
131
+ }
132
+ /**
133
+ * A payment option on a catalog item write (backend `CreatePaymentOption`).
134
+ * Prices are integer cents.
135
+ */
136
+ export interface PaymentOptionInput {
137
+ /** 1–64 characters. */
138
+ name: string;
139
+ is_prepay?: boolean;
140
+ price_under_prepay?: number | null;
141
+ price?: number;
142
+ recommended_prepay_count?: number | null;
143
+ /** Case-insensitive; defaults to `NONE`. */
144
+ mode?: 'NONE' | 'MONTH' | 'SERVICE' | Lowercase<'NONE' | 'MONTH' | 'SERVICE'>;
145
+ }
146
+ /**
147
+ * Body of `PUT /catalog_item/<id>` (backend `UpdateCatalogItem`); omitted
148
+ * fields are unchanged and `null` clears the `recommended_*` fields.
149
+ */
150
+ export interface CatalogItemUpdatePayload {
151
+ /** 1–256 characters. */
152
+ name?: string | null;
153
+ description?: string | null;
154
+ /**
155
+ * A `CatalogIndustry` name, matched case-insensitively with spaces for
156
+ * underscores (`'Snow Removal'`).
157
+ */
158
+ industry?: CatalogIndustry | (string & {}) | null;
159
+ /** A `CatalogPriceFormat` name, matched like `industry`. */
160
+ price_format?: CatalogPriceFormat | (string & {}) | null;
161
+ /** Integer seconds between services. */
162
+ recommended_frequency?: number | null;
163
+ /** Unix seconds (>= 0). */
164
+ recommended_activate_on?: number | null;
165
+ /** Unix seconds (>= 0). */
166
+ recommended_expire_on?: number | null;
167
+ /** Skill GUIDs; replaces the item's skills. */
168
+ skills?: string[] | null;
169
+ /** Replaces the item's payment options. */
170
+ payment_options?: PaymentOptionInput[] | null;
171
+ }
172
+ /** Body of `POST /company/<id>/catalog_item` (backend `CreateCatalogItem`). */
173
+ export type CatalogItemCreatePayload = CatalogItemUpdatePayload & {
174
+ name: string;
175
+ };
176
+ /**
177
+ * Body of `POST /job/<id>/proposal` and `PUT /proposal/<id>` (backend
178
+ * `CreateProposal` / `UpdateProposal`); omitted fields are unchanged, and
179
+ * null clears `terms_version_id` / `prepay_due_date`.
180
+ */
181
+ export interface ProposalWritePayload {
182
+ /** Unix seconds (>= 0) after which the customer can no longer review. */
183
+ expire_on?: number | null;
184
+ /** Terms version GUID; null detaches. */
185
+ terms_version_id?: string | null;
186
+ /** Unix seconds (>= 0); null clears. */
187
+ prepay_due_date?: number | null;
188
+ /** Replaces the proposal's tasks (only `id` is read). */
189
+ tasks?: {
190
+ id: string;
191
+ }[] | null;
192
+ }
193
+ /** A prepayment a customer commits to when accepting a task (backend `AcceptPrepayment`). */
194
+ export interface ProposalReviewPrepayment {
195
+ /** Unit price in integer cents (>= 0). */
196
+ cost?: number;
197
+ /** Integer count (>= 1). */
198
+ amount?: number;
199
+ type?: 'SERVICE' | 'MONTH';
200
+ description?: string;
201
+ name?: string;
202
+ }
203
+ /** The customer's decision on one proposal task (backend `ReviewTask`). */
204
+ export interface ProposalReviewTask {
205
+ id: string;
206
+ /** `ARCHIVED` rejects the task; anything else accepts it. */
207
+ status?: TaskStatus | null;
208
+ prepayments?: ProposalReviewPrepayment[] | null;
209
+ bill_mode?: 'NONE' | 'MONTH' | 'SERVICE' | null;
210
+ /** Chosen price in integer cents. */
211
+ price?: number | null;
212
+ /** @deprecated Not read by the backend. */
213
+ payment_option_id?: string;
214
+ }
215
+ /** Body of `POST /proposal/<id>/review` (backend `ReviewProposal`). */
216
+ export interface ProposalReviewPayload {
217
+ tasks?: ProposalReviewTask[];
218
+ /** Required when the proposal has terms and any task is accepted. */
219
+ terms_version_id?: string | null;
220
+ pay_in_cash?: boolean;
221
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Request bodies and endpoint-specific responses of the REST API, matching
3
+ * the backend's pydantic schemas (`avro/views/<domain>/schemas.py`).
4
+ */
5
+ export {};
@@ -0,0 +1,7 @@
1
+ /** Helpers that shape request bodies to what the backend schemas accept. */
2
+ /**
3
+ * Drop optional keys holding `''`. The backend schemas type these as UUIDs
4
+ * or enums, so an empty string is a 400, while an omitted key means "no
5
+ * filter" (lists) or "unchanged" (updates).
6
+ */
7
+ export declare function withoutEmpty<T extends object>(body: T, ...keys: string[]): T;
@@ -0,0 +1,14 @@
1
+ /** Helpers that shape request bodies to what the backend schemas accept. */
2
+ /**
3
+ * Drop optional keys holding `''`. The backend schemas type these as UUIDs
4
+ * or enums, so an empty string is a 400, while an omitted key means "no
5
+ * filter" (lists) or "unchanged" (updates).
6
+ */
7
+ export function withoutEmpty(body, ...keys) {
8
+ const out = { ...body };
9
+ for (const key of keys) {
10
+ if (out[key] === '')
11
+ delete out[key];
12
+ }
13
+ return out;
14
+ }
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { AvroQueryClientProvider, useAvroQueryClient, useSocketEvent, } from './
3
3
  export { useEmailStatus } from './client/hooks/email.js';
4
4
  export type { EmailResult, EmailResultStatus, UseEmailStatusOptions } from './client/hooks/email.js';
5
5
  export type { BulkBillError, BulkDeleteBillsResponse, BulkEmailBillsResponse, } from './client/hooks/bills.js';
6
+ export type * from './client/requests.js';
6
7
  export { AuthManager } from './auth/AuthManager.js';
7
8
  export { MemoryStorage, LocalStorage } from './auth/storage.js';
8
9
  export { QueryPersister, IndexedDBStore, MemoryKeyValueStore, defaultKeyValueStore, PERSISTED_NAMESPACES, } from './client/persist.js';
@@ -1,6 +1,7 @@
1
1
  import { LineItem } from './LineItem.js';
2
2
  export interface AdditionalCharge extends LineItem {
3
3
  line_item_type: 'ADDITIONAL_CHARGE';
4
- time_updated: number | null;
4
+ /** GUID of the event the charge belongs to. */
5
+ parent_id: string;
5
6
  earned_revenue: number;
6
7
  }