@go-avro/avro-js 0.0.85 → 0.0.87

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';
4
- import { _Event, ActiveSessionSummary, AddressFeatureCollection, ApiInfo, Avro, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Break, Chat, CheckIn, Company, EventUpdatePayload, FinancialInsightData, RevenueInsightData, Job, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill, Group, Label, RouteScheduleConfig, RouteWritePayload, CatalogItem, Payout, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api';
4
+ import { _Event, ActiveSessionSummary, AddressFeatureCollection, ApiInfo, Avro, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Break, Chat, CheckIn, Company, EventUpdatePayload, FinancialInsightData, RevenueInsightData, Job, JobUpdate, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill, Group, Label, RouteScheduleConfig, RouteWritePayload, CatalogItem, Payout, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api';
5
5
  import { AuthState, Tokens } from '../types/auth';
6
6
  import { CancelToken, ClientId, RetryStrategy } from '../types/client';
7
7
  import { StandardError } from '../types/error';
@@ -65,6 +65,8 @@ declare module '../client/QueryClient' {
65
65
  billed?: boolean;
66
66
  paid?: boolean;
67
67
  jobId?: string;
68
+ sort_by?: 'date' | 'amount' | 'name';
69
+ direction?: 'asc' | 'desc';
68
70
  enabled?: boolean;
69
71
  }): UseInfiniteQueryResult<InfiniteData<_Event[], unknown>, StandardError>;
70
72
  useGetSessions(body: {
@@ -86,6 +88,8 @@ declare module '../client/QueryClient' {
86
88
  billed?: boolean;
87
89
  paid?: boolean;
88
90
  taskId?: string;
91
+ sort_by?: 'date' | 'amount' | 'name';
92
+ direction?: 'asc' | 'desc';
89
93
  enabled?: boolean;
90
94
  }): UseInfiniteQueryResult<InfiniteData<Prepayment[], unknown>, StandardError>;
91
95
  useGetMessages(chatId: string, body: {
@@ -103,6 +107,8 @@ declare module '../client/QueryClient' {
103
107
  billed?: boolean;
104
108
  paid?: boolean;
105
109
  jobId?: string;
110
+ sort_by?: 'date' | 'amount' | 'name';
111
+ direction?: 'asc' | 'desc';
106
112
  enabled?: boolean;
107
113
  }): UseInfiniteQueryResult<InfiniteData<ServiceMonth[], unknown>, StandardError>;
108
114
  useGetBills(body: {
@@ -117,6 +123,10 @@ declare module '../client/QueryClient' {
117
123
  paid_to?: number;
118
124
  amount_min?: number;
119
125
  amount_max?: number;
126
+ /** Label guids; bills match via their events'/months' jobs. */
127
+ labels?: string[];
128
+ sort_by?: 'date' | 'amount' | 'number';
129
+ direction?: 'asc' | 'desc';
120
130
  }): UseInfiniteQueryResult<InfiniteData<Bill[], unknown>, StandardError>;
121
131
  useGetPayouts(body: {
122
132
  amt?: number;
@@ -352,7 +362,7 @@ declare module '../client/QueryClient' {
352
362
  breakData: Partial<Break>;
353
363
  }>>;
354
364
  useManageJobs(): ReturnType<typeof useMutation<void, StandardError, {
355
- jobs: Partial<Job>[];
365
+ jobs: JobUpdate[];
356
366
  }>>;
357
367
  useScheduleRoutes(): ReturnType<typeof useMutation<{
358
368
  msg: string;
@@ -457,7 +467,7 @@ declare module '../client/QueryClient' {
457
467
  msg: string;
458
468
  }, StandardError, {
459
469
  jobId: string;
460
- updates: Partial<Job>;
470
+ updates: JobUpdate;
461
471
  }>>;
462
472
  useUpdateSkill(): ReturnType<typeof useMutation<{
463
473
  msg: string;
@@ -496,6 +506,12 @@ declare module '../client/QueryClient' {
496
506
  teamId: string;
497
507
  teamData: Partial<Team>;
498
508
  }>>;
509
+ useUpdateMonth(): ReturnType<typeof useMutation<{
510
+ msg: string;
511
+ }, StandardError, {
512
+ monthId: string;
513
+ updates: Partial<ServiceMonth>;
514
+ }>>;
499
515
  useUpdateMonths(): ReturnType<typeof useMutation<void, StandardError, {
500
516
  months: (ServiceMonth & {
501
517
  page?: number;
@@ -2,7 +2,7 @@ import io from 'socket.io-client';
2
2
  import { useMutation, useQueryClient, } from '@tanstack/react-query';
3
3
  import { v4 as uuidv4 } from 'uuid';
4
4
  import { fetchCensusFeatures } from '../census';
5
- import { _Event, Job, LoginResponse, Route, } from '../types/api';
5
+ import { _Event, Bill, Job, LoginResponse, Route, } from '../types/api';
6
6
  import { AuthState } from '../types/auth';
7
7
  import { StandardError } from '../types/error';
8
8
  function isBulkEvent(c) {
@@ -217,6 +217,7 @@ const SOCKET_EVENT_CONFIG = {
217
217
  entityKey: 'bills',
218
218
  action: 'create',
219
219
  fetchPath: (id) => `/bill/${id}`,
220
+ construct: (d) => new Bill(d),
220
221
  matchesQuery: matchesBillsListQuery,
221
222
  },
222
223
  delete_bill: { entityKey: 'bills', action: 'delete', fetchPath: null },
@@ -312,6 +313,7 @@ const SOCKET_EVENT_CONFIG = {
312
313
  },
313
314
  // ── Service Months ──
314
315
  create_month: { entityKey: 'months', action: 'create', fetchPath: null },
316
+ update_month: { invalidateKeys: [['months']] },
315
317
  update_months: { invalidateKeys: [['months']] },
316
318
  delete_months: { invalidateKeys: [['months']] },
317
319
  // ── Tasks (nested under jobs — target the parent job) ──
@@ -1,5 +1,6 @@
1
1
  import { useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
2
2
  import { AvroQueryClient } from '../../client/QueryClient';
3
+ import { Bill } from '../../types/api';
3
4
  AvroQueryClient.prototype.useGetBills = function (body) {
4
5
  const queryClient = this.getQueryClient();
5
6
  const result = useInfiniteQuery({
@@ -26,7 +27,7 @@ AvroQueryClient.prototype.useGetBills = function (body) {
26
27
  return undefined;
27
28
  return allPages.flat().length; // next offset
28
29
  },
29
- queryFn: ({ pageParam = 0 }) => this.fetchBills({ ...body, offset: pageParam }),
30
+ queryFn: ({ pageParam = 0 }) => this.fetchBills({ ...body, offset: pageParam }).then((bills) => bills.map((bill) => new Bill(bill))),
30
31
  });
31
32
  if (result.data) {
32
33
  result.data.pages.forEach((data_page) => {
@@ -40,7 +41,7 @@ AvroQueryClient.prototype.useGetBills = function (body) {
40
41
  AvroQueryClient.prototype.useGetBill = function (billId) {
41
42
  return useQuery({
42
43
  queryKey: ['bills', billId],
43
- queryFn: () => this.get({ path: `/bill/${billId}` }),
44
+ queryFn: () => this.get({ path: `/bill/${billId}` }).then((bill) => new Bill(bill)),
44
45
  enabled: Boolean(billId),
45
46
  });
46
47
  };
@@ -37,6 +37,21 @@ AvroQueryClient.prototype.useGetMonths = function (body) {
37
37
  }
38
38
  return result;
39
39
  };
40
+ AvroQueryClient.prototype.useUpdateMonth = function () {
41
+ const queryClient = this.getQueryClient();
42
+ return useMutation({
43
+ mutationFn: async ({ monthId, updates, }) => {
44
+ return this.put({
45
+ path: `/month/${monthId}`,
46
+ data: JSON.stringify(updates),
47
+ headers: { 'Content-Type': 'application/json' },
48
+ });
49
+ },
50
+ onSuccess: () => {
51
+ queryClient.invalidateQueries({ queryKey: ['months'] });
52
+ },
53
+ });
54
+ };
40
55
  AvroQueryClient.prototype.useUpdateMonths = function () {
41
56
  const queryClient = this.getQueryClient();
42
57
  return useMutation({
@@ -1,6 +1,7 @@
1
1
  import { BillPayment } from '../../types/api/BillPayment';
2
2
  import { BillUser } from '../../types/api/BillUser';
3
3
  import { CustomLineItem } from '../../types/api/CustomLineItem';
4
+ import { LineItem } from '../../types/api/LineItem';
4
5
  import { PaymentType } from '../../types/api/PaymentType';
5
6
  import { ProcessingFeeLineItem } from '../../types/api/ProcessingFeeLineItem';
6
7
  export type BillLineItem = CustomLineItem | ProcessingFeeLineItem;
@@ -11,33 +12,40 @@ export declare const BillStatus: {
11
12
  readonly MANUALLY_PAID: "MANUALLY_PAID";
12
13
  };
13
14
  export type BillStatus = (typeof BillStatus)[keyof typeof BillStatus];
14
- export interface Bill {
15
- id: string;
16
- invoice_id: number;
17
- intuit_id: string | null;
18
- name: string;
19
- amount: number;
20
- billed_by: string;
21
- customer_email: string | null;
22
- manual_emails: string[][];
23
- users: BillUser[];
24
- status: BillStatus;
25
- enabled_payment_methods: PaymentType[];
26
- time_created: number;
27
- time_updated: number;
28
- events: string[];
29
- intent_created_at: number;
30
- intent_last_created_at: number;
31
- payments: BillPayment[];
32
- line_items: BillLineItem[];
33
- prepayments: string[];
34
- months: string[];
35
- due_date: number;
36
- pass_on_fees: boolean;
15
+ declare module '../../types/api/Bill' {
16
+ interface Bill {
17
+ id: string;
18
+ invoice_id: number;
19
+ intuit_id: string | null;
20
+ name: string;
21
+ billed_by: string;
22
+ customer_email: string | null;
23
+ manual_emails: string[][];
24
+ users: BillUser[];
25
+ status: BillStatus;
26
+ enabled_payment_methods: PaymentType[];
27
+ time_created: number;
28
+ time_updated: number;
29
+ events: string[];
30
+ intent_created_at: number;
31
+ intent_last_created_at: number;
32
+ payments: BillPayment[];
33
+ line_items: LineItem[];
34
+ prepayments: string[];
35
+ months: string[];
36
+ due_date: number;
37
+ pass_on_fees: boolean;
38
+ }
39
+ }
40
+ export declare class Bill {
41
+ constructor(init?: Partial<Bill>);
42
+ total: () => number;
43
+ labels: () => string[];
44
+ customItems: () => BillLineItem[];
45
+ topLevelItems: () => LineItem[];
46
+ childItems: (parentId: string) => LineItem[];
37
47
  }
38
- /** Line-item kinds addressable by PUT /bill/<id>/line-items/status. */
39
48
  export type BillLineItemStatusKind = 'event' | 'service_month' | 'prepayment' | 'line_item';
40
- /** One per-line-item paid/unpaid marking on a bill. */
41
49
  export interface BillLineItemStatusUpdate {
42
50
  type: BillLineItemStatusKind;
43
51
  id: string;
@@ -1,6 +1,25 @@
1
+ import { LineItem } from '../../types/api/LineItem';
1
2
  export const BillStatus = {
2
3
  SENT: 'SENT',
3
4
  PAID: 'PAID',
4
5
  PARTIALLY_PAID: 'PARTIALLY_PAID',
5
6
  MANUALLY_PAID: 'MANUALLY_PAID',
6
7
  };
8
+ export class Bill {
9
+ constructor(init) {
10
+ this.total = () => (this.line_items ?? []).reduce((sum, item) => {
11
+ const cost = item.line_item_type === 'EVENT' ? Math.max(item.cost, 0) : item.cost;
12
+ return sum + cost * (item.amount ?? 1);
13
+ }, 0);
14
+ this.labels = () => [
15
+ ...new Set((this.line_items ?? []).flatMap((item) => item.job_labels ?? [])),
16
+ ];
17
+ this.customItems = () => (this.line_items ?? []).filter((item) => item.line_item_type === 'CUSTOM' || item.line_item_type === 'PROCESSING_FEE');
18
+ this.topLevelItems = () => (this.line_items ?? []).filter((item) => !item.parent_id);
19
+ this.childItems = (parentId) => (this.line_items ?? []).filter((item) => item.parent_id === parentId);
20
+ Object.assign(this, init);
21
+ if (init?.line_items) {
22
+ this.line_items = init.line_items.map((item) => new LineItem(item));
23
+ }
24
+ }
25
+ }
@@ -31,6 +31,9 @@ declare module '../../types/api/Job' {
31
31
  owner: string | null;
32
32
  }
33
33
  }
34
+ export type JobUpdate = Partial<Omit<Job, 'subscribers'>> & {
35
+ subscribers?: string[];
36
+ };
34
37
  export declare class Job {
35
38
  constructor(init?: Partial<Job>);
36
39
  isOverdue: () => boolean;
@@ -30,6 +30,8 @@ declare module '../../types/api/LineItem' {
30
30
  job_name: string;
31
31
  job_address: string;
32
32
  job_labels: string[];
33
+ bill_pub_id: number | null;
34
+ parent_id: string | null;
33
35
  company_id: string;
34
36
  time_created: number;
35
37
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.0.85";
1
+ export declare const AVRO_JS_VERSION = "0.0.87";
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.0.85';
3
+ export const AVRO_JS_VERSION = '0.0.87';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.85",
3
+ "version": "0.0.87",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",