@go-avro/avro-js 0.1.9 → 0.1.11

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,7 @@ 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';
10
11
  import { ProposalTerms } from '../types/api/ProposalTerms.js';
11
12
  import type { EmailSucceededPayload, EmailFailedPayload, EmailType } from '../types/api/EmailNotification.js';
12
13
  import type { BulkDeleteBillsResponse, BulkEmailBillsResponse } from './hooks/bills.js';
@@ -189,7 +190,7 @@ declare module './QueryClient.js' {
189
190
  }): Promise<{
190
191
  msg: string;
191
192
  }>;
192
- useGetProposal(proposal_id: string): UseQueryResult<any, StandardError>;
193
+ useGetProposal(proposal_id: string): UseQueryResult<Proposal, StandardError>;
193
194
  useGetProposalTerms(): UseQueryResult<ProposalTerms[], StandardError>;
194
195
  useCreateProposalTerms(): ReturnType<typeof useMutation<{
195
196
  id: string;
@@ -286,6 +287,7 @@ declare module './QueryClient.js' {
286
287
  payment_option_id: string;
287
288
  }[];
288
289
  terms_version_id?: string;
290
+ pay_in_cash?: boolean;
289
291
  }>>;
290
292
  useCreateMessage(chatId: string): ReturnType<typeof useMutation<{
291
293
  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
  };
@@ -9,6 +9,8 @@ AvroQueryClient.prototype.useGetProposalTerms = function () {
9
9
  });
10
10
  };
11
11
  AvroQueryClient.prototype.useCreateProposalTerms = function () {
12
+ const queryClient = this.getQueryClient();
13
+ const listKey = keys.list('proposal_terms', this.companyId);
12
14
  return useMutation({
13
15
  mutationFn: async (data) => {
14
16
  return this.post({
@@ -17,12 +19,43 @@ AvroQueryClient.prototype.useCreateProposalTerms = function () {
17
19
  headers: { 'Content-Type': 'application/json' },
18
20
  });
19
21
  },
20
- onSuccess: () => {
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)));
21
50
  this.syncAfterMutation('proposal_terms');
22
51
  },
52
+ onError: (_err, _variables, context) => {
53
+ queryClient.setQueryData(listKey, context?.previous);
54
+ },
23
55
  });
24
56
  };
25
57
  AvroQueryClient.prototype.useUpdateProposalTerms = function () {
58
+ const queryClient = this.getQueryClient();
26
59
  return useMutation({
27
60
  mutationFn: async ({ termsId, updates, }) => {
28
61
  return this.put({
@@ -31,8 +64,30 @@ AvroQueryClient.prototype.useUpdateProposalTerms = function () {
31
64
  headers: { 'Content-Type': 'application/json' },
32
65
  });
33
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
+ },
34
86
  onSuccess: () => {
35
87
  this.syncAfterMutation('proposal_terms');
36
88
  },
89
+ onError: (_err, _variables, context) => {
90
+ context?.previous.forEach(([key, data]) => queryClient.setQueryData(key, data));
91
+ },
37
92
  });
38
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,6 +195,7 @@ 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
  },
@@ -60,4 +60,5 @@ export interface Company {
60
60
  timecard_length: number;
61
61
  default_pass_on_fees: boolean;
62
62
  require_team_for_clock_in: boolean;
63
+ accepts_cash_payments: boolean;
63
64
  }
@@ -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 {};
@@ -9,7 +9,7 @@ export interface ProposalTermsVersion {
9
9
  export interface ProposalTerms {
10
10
  id: string;
11
11
  company_id: string;
12
- name: string;
12
+ name: string | null;
13
13
  archived: boolean;
14
14
  current_version: ProposalTermsVersion | null;
15
15
  time_created: number | null;
@@ -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,7 @@ 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';
38
39
  export * from './api/ProposalTerms.js';
39
40
  export * from './api/Reaction.js';
40
41
  export * from './api/Route.js';
package/dist/types/api.js CHANGED
@@ -32,6 +32,7 @@ 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';
35
36
  export * from './api/ProposalTerms.js';
36
37
  export * from './api/Reaction.js';
37
38
  export * from './api/Route.js';
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.1.9";
1
+ export declare const AVRO_JS_VERSION = "0.1.11";
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.9';
3
+ export const AVRO_JS_VERSION = '0.1.11';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",