@go-avro/avro-js 0.1.8 → 0.1.10

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.
@@ -7,6 +7,8 @@ import { CancelToken, ClientId, RetryStrategy } from '../types/client.js';
7
7
  import { StandardError } from '../types/error.js';
8
8
  import { CacheData } from '../types/cache.js';
9
9
  import { Waiver } from '../types/api/Waiver.js';
10
+ import { Proposal } from '../types/api/Proposal.js';
11
+ import { ProposalTerms } from '../types/api/ProposalTerms.js';
10
12
  import type { EmailSucceededPayload, EmailFailedPayload, EmailType } from '../types/api/EmailNotification.js';
11
13
  import type { BulkDeleteBillsResponse, BulkEmailBillsResponse } from './hooks/bills.js';
12
14
  import { type QueryPersistOptions } from './persist.js';
@@ -188,7 +190,24 @@ declare module './QueryClient.js' {
188
190
  }): Promise<{
189
191
  msg: string;
190
192
  }>;
191
- useGetProposal(proposal_id: string): UseQueryResult<any, StandardError>;
193
+ useGetProposal(proposal_id: string): UseQueryResult<Proposal, StandardError>;
194
+ useGetProposalTerms(): UseQueryResult<ProposalTerms[], StandardError>;
195
+ useCreateProposalTerms(): ReturnType<typeof useMutation<{
196
+ id: string;
197
+ }, StandardError, {
198
+ name: string;
199
+ body: string;
200
+ }>>;
201
+ useUpdateProposalTerms(): ReturnType<typeof useMutation<{
202
+ msg: string;
203
+ }, StandardError, {
204
+ termsId: string;
205
+ updates: {
206
+ name?: string;
207
+ body?: string;
208
+ archived?: boolean;
209
+ };
210
+ }>>;
192
211
  useAutocompleteAddress(address: string, options?: {
193
212
  size?: number;
194
213
  minLength?: number;
@@ -267,6 +286,7 @@ declare module './QueryClient.js' {
267
286
  status: string;
268
287
  payment_option_id: string;
269
288
  }[];
289
+ terms_version_id?: string;
270
290
  }>>;
271
291
  useCreateMessage(chatId: string): ReturnType<typeof useMutation<{
272
292
  id: string;
@@ -1,6 +1,6 @@
1
1
  import { useMutation, useQuery } from '@tanstack/react-query';
2
2
  import { AvroQueryClient } from '../QueryClient.js';
3
- import { Task } from '../../types/api/Task.js';
3
+ import { Task } from '../../types/api.js';
4
4
  AvroQueryClient.prototype.useCreateProposal = function () {
5
5
  const queryClient = this.getQueryClient();
6
6
  return useMutation({
@@ -38,10 +38,7 @@ AvroQueryClient.prototype.useGetProposal = function (proposal_id) {
38
38
  const proposal = await this.get({
39
39
  path: `/proposal/${proposal_id}`,
40
40
  });
41
- if (proposal && Array.isArray(proposal.tasks)) {
42
- proposal.tasks = proposal.tasks.map((task) => new Task(task));
43
- }
44
- return proposal;
41
+ return { ...proposal, tasks: proposal.tasks.map((task) => new Task(task)) };
45
42
  },
46
43
  });
47
44
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,93 @@
1
+ import { useMutation, useQuery } from '@tanstack/react-query';
2
+ import { AvroQueryClient } from '../QueryClient.js';
3
+ import { keys } from '../realtime.js';
4
+ AvroQueryClient.prototype.useGetProposalTerms = function () {
5
+ return useQuery({
6
+ queryKey: keys.list('proposal_terms', this.companyId),
7
+ queryFn: () => this.get({ path: `/company/${this.companyId}/proposal_terms` }),
8
+ enabled: Boolean(this.companyId),
9
+ });
10
+ };
11
+ AvroQueryClient.prototype.useCreateProposalTerms = function () {
12
+ const queryClient = this.getQueryClient();
13
+ const listKey = keys.list('proposal_terms', this.companyId);
14
+ return useMutation({
15
+ mutationFn: async (data) => {
16
+ return this.post({
17
+ path: `/company/${this.companyId}/proposal_terms`,
18
+ data: JSON.stringify(data),
19
+ headers: { 'Content-Type': 'application/json' },
20
+ });
21
+ },
22
+ onMutate: async ({ name, body }) => {
23
+ await queryClient.cancelQueries({ queryKey: listKey });
24
+ const previous = queryClient.getQueryData(listKey);
25
+ const tempId = `temp-${Date.now()}`;
26
+ const now = Math.floor(Date.now() / 1000);
27
+ const optimistic = {
28
+ id: tempId,
29
+ company_id: this.companyId ?? '',
30
+ name,
31
+ archived: false,
32
+ current_version: {
33
+ id: `${tempId}-v1`,
34
+ terms_id: tempId,
35
+ name,
36
+ version: 1,
37
+ body,
38
+ time_created: now,
39
+ },
40
+ time_created: now,
41
+ time_updated: now,
42
+ };
43
+ queryClient.setQueryData(listKey, (old) => old ? [...old, optimistic] : old);
44
+ return { previous, tempId };
45
+ },
46
+ onSuccess: ({ id }, _variables, context) => {
47
+ queryClient.setQueryData(listKey, (old) => old?.some((t) => t.id === id)
48
+ ? old.filter((t) => t.id !== context?.tempId)
49
+ : old?.map((t) => (t.id === context?.tempId ? { ...t, id } : t)));
50
+ this.syncAfterMutation('proposal_terms');
51
+ },
52
+ onError: (_err, _variables, context) => {
53
+ queryClient.setQueryData(listKey, context?.previous);
54
+ },
55
+ });
56
+ };
57
+ AvroQueryClient.prototype.useUpdateProposalTerms = function () {
58
+ const queryClient = this.getQueryClient();
59
+ return useMutation({
60
+ mutationFn: async ({ termsId, updates, }) => {
61
+ return this.put({
62
+ path: `/proposal_terms/${termsId}`,
63
+ data: JSON.stringify(updates),
64
+ headers: { 'Content-Type': 'application/json' },
65
+ });
66
+ },
67
+ onMutate: async ({ termsId, updates }) => {
68
+ const { name, body, archived } = updates;
69
+ const patch = (t) => t.id !== termsId
70
+ ? t
71
+ : {
72
+ ...t,
73
+ name: name ?? t.name,
74
+ archived: archived ?? t.archived,
75
+ current_version: t.current_version && {
76
+ ...t.current_version,
77
+ name: name ?? t.current_version.name,
78
+ body: body ?? t.current_version.body,
79
+ },
80
+ };
81
+ await queryClient.cancelQueries({ queryKey: ['proposal_terms'] });
82
+ const previous = queryClient.getQueriesData({ queryKey: ['proposal_terms'] });
83
+ queryClient.setQueriesData({ queryKey: ['proposal_terms'] }, (old) => (Array.isArray(old) ? old.map(patch) : old && patch(old)));
84
+ return { previous };
85
+ },
86
+ onSuccess: () => {
87
+ this.syncAfterMutation('proposal_terms');
88
+ },
89
+ onError: (_err, _variables, context) => {
90
+ context?.previous.forEach(([key, data]) => queryClient.setQueryData(key, data));
91
+ },
92
+ });
93
+ };
@@ -4,7 +4,7 @@
4
4
  * `delete` removes, `invalidate` refetches. Query keys: `[ns, id]`
5
5
  * detail, `keys.list/keys.infinite(ns, scope, filters)` for lists.
6
6
  */
7
- import { Bill, constructEvent, Job, Route, Session } from '../types/api.js';
7
+ import { Bill, constructEvent, Job, Route, Session, Task } from '../types/api.js';
8
8
  export const keys = {
9
9
  detail: (ns, id) => [ns, id],
10
10
  list: (ns, scope, filters = {}) => [ns, 'list', scope ?? '', filters],
@@ -195,9 +195,14 @@ export const REGISTRY = {
195
195
  },
196
196
  proposal: {
197
197
  ns: 'proposals',
198
+ construct: (d) => ({ ...d, tasks: d.tasks.map((t) => new Task(t)) }),
198
199
  fetchOne: (client, id) => client.get({ path: `/proposal/${id}` }),
199
200
  alsoInvalidate: [['tasks']],
200
201
  },
202
+ proposal_terms: {
203
+ ns: 'proposal_terms',
204
+ fetchOne: (client, id) => client.get({ path: `/proposal_terms/${id}` }),
205
+ },
201
206
  month: { ns: 'months', fetchMany: bulk('fetchMonths'), listMatch: matchLineItems },
202
207
  prepayment: {
203
208
  ns: 'prepayments',
package/dist/index.d.ts CHANGED
@@ -36,6 +36,7 @@ import './client/hooks/labels.js';
36
36
  import './client/hooks/groups.js';
37
37
  import './client/hooks/skills.js';
38
38
  import './client/hooks/proposal.js';
39
+ import './client/hooks/proposal_terms.js';
39
40
  import './client/hooks/timecards.js';
40
41
  import './client/hooks/waivers.js';
41
42
  import './client/hooks/email.js';
package/dist/index.js CHANGED
@@ -33,6 +33,7 @@ import './client/hooks/labels.js';
33
33
  import './client/hooks/groups.js';
34
34
  import './client/hooks/skills.js';
35
35
  import './client/hooks/proposal.js';
36
+ import './client/hooks/proposal_terms.js';
36
37
  import './client/hooks/timecards.js';
37
38
  import './client/hooks/waivers.js';
38
39
  import './client/hooks/email.js';
@@ -40,7 +40,7 @@ export declare class Job {
40
40
  isOverdue: () => boolean;
41
41
  getOverdueLabel: () => string;
42
42
  getStatus(): "PENDING_CUSTOMER" | "PENDING_COMPANY" | "ACTIVE" | "ARCHIVED" | "DRAFT" | "PENDING_PAYMENT" | "PENDING_ACTIVATION";
43
- getStatusLabel(): "Active" | "Draft" | "Archived" | "Pending Activation" | "Customer Approval" | "Company Approval" | "Awaiting Payment";
43
+ getStatusLabel(): "Active" | "Archived" | "Customer Approval" | "Company Approval" | "Awaiting Payment" | "Pending Activation" | "Draft";
44
44
  /**
45
45
  * Returns the sum of `service` (in seconds) for the tasks attached to a
46
46
  * given routeJob. Use this to compute predicted completion time:
@@ -0,0 +1,12 @@
1
+ import { ProposalTermsVersion } from './ProposalTerms.js';
2
+ import { Task } from './Task.js';
3
+ export interface Proposal {
4
+ id: string;
5
+ company_id: string;
6
+ job_id: string;
7
+ expire_on: number | null;
8
+ expired: boolean;
9
+ terms: ProposalTermsVersion | null;
10
+ accepted_at: number | null;
11
+ tasks: Task[];
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ export interface ProposalTermsVersion {
2
+ id: string;
3
+ terms_id: string;
4
+ name: string;
5
+ version: number;
6
+ body: string;
7
+ time_created: number | null;
8
+ }
9
+ export interface ProposalTerms {
10
+ id: string;
11
+ company_id: string;
12
+ name: string | null;
13
+ archived: boolean;
14
+ current_version: ProposalTermsVersion | null;
15
+ time_created: number | null;
16
+ time_updated: number | null;
17
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -68,7 +68,7 @@ declare module './Task.js' {
68
68
  }
69
69
  export declare class Task {
70
70
  constructor(init?: Partial<Task>);
71
- getStatusLabel: () => "Active" | "Draft" | "Archived" | "Pending Customer Approval" | "Pending Company Approval" | "Pending Payment" | "Pending Activation";
71
+ getStatusLabel: () => "Active" | "Archived" | "Pending Activation" | "Draft" | "Pending Customer Approval" | "Pending Company Approval" | "Pending Payment";
72
72
  getUnroutedReasonLabel: () => string | null;
73
73
  isOverdue: () => boolean;
74
74
  getOverdueLabel: () => string;
@@ -35,6 +35,8 @@ export * from './api/Plan.js';
35
35
  export * from './api/PlanPayment.js';
36
36
  export * from './api/Prepayment.js';
37
37
  export * from './api/ProcessingFeeLineItem.js';
38
+ export * from './api/Proposal.js';
39
+ export * from './api/ProposalTerms.js';
38
40
  export * from './api/Reaction.js';
39
41
  export * from './api/Route.js';
40
42
  export * from './api/RouteJob.js';
package/dist/types/api.js CHANGED
@@ -32,6 +32,8 @@ export * from './api/Plan.js';
32
32
  export * from './api/PlanPayment.js';
33
33
  export * from './api/Prepayment.js';
34
34
  export * from './api/ProcessingFeeLineItem.js';
35
+ export * from './api/Proposal.js';
36
+ export * from './api/ProposalTerms.js';
35
37
  export * from './api/Reaction.js';
36
38
  export * from './api/Route.js';
37
39
  export * from './api/RouteJob.js';
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.1.8";
1
+ export declare const AVRO_JS_VERSION = "0.1.10";
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 = '0.1.8';
3
+ export const AVRO_JS_VERSION = '0.1.10';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",