@go-avro/avro-js 0.0.2-beta.173 → 0.0.2-beta.175

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, ApiInfo, Avro, Bill, Break, Chat, Company, FinancialInsightData, Job, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill, Group, Label, RouteScheduleConfig, CatalogItem } from '../types/api';
4
+ import { _Event, ApiInfo, Avro, Bill, Break, Chat, Company, FinancialInsightData, Job, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill, Group, Label, RouteScheduleConfig, CatalogItem, Prepayment } from '../types/api';
5
5
  import { AuthState, Tokens } from '../types/auth';
6
6
  import { CancelToken, RetryStrategy } from '../types/client';
7
7
  import { StandardError } from '../types/error';
@@ -63,7 +63,7 @@ declare module '../client/QueryClient' {
63
63
  unknown_ids?: string[];
64
64
  query?: string;
65
65
  }): UseInfiniteQueryResult<InfiniteData<Chat[], unknown>, StandardError>;
66
- useGetMessages(chatId: string, body: {
66
+ useGetPrepayments(body: {
67
67
  amt?: number;
68
68
  known_ids?: string[];
69
69
  unknown_ids?: string[];
@@ -71,7 +71,13 @@ declare module '../client/QueryClient' {
71
71
  unbilled?: boolean;
72
72
  billed?: boolean;
73
73
  paid?: boolean;
74
- jobId?: string;
74
+ taskId?: string;
75
+ }): UseInfiniteQueryResult<InfiniteData<Prepayment[], unknown>, StandardError>;
76
+ useGetMessages(chatId: string, body: {
77
+ amt?: number;
78
+ known_ids?: string[];
79
+ unknown_ids?: string[];
80
+ query?: string;
75
81
  }): UseInfiniteQueryResult<InfiniteData<Message[], unknown>, StandardError>;
76
82
  useGetMonths(body: {
77
83
  amt?: number;
@@ -468,6 +474,17 @@ export declare class AvroQueryClient {
468
474
  query?: string;
469
475
  offset?: number;
470
476
  }, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
477
+ fetchPrepayments(body?: {
478
+ amt?: number;
479
+ known_ids?: string[];
480
+ unknown_ids?: string[];
481
+ query?: string;
482
+ offset?: number;
483
+ unbilled?: boolean;
484
+ billed?: boolean;
485
+ paid?: boolean;
486
+ taskId?: string | null;
487
+ }, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
471
488
  fetchEvents(body?: {
472
489
  amt?: number;
473
490
  known_ids?: string[];
@@ -296,6 +296,25 @@ export class AvroQueryClient {
296
296
  throw new StandardError(500, 'Failed to fetch messages');
297
297
  });
298
298
  }
299
+ async fetchPrepayments(body = {}, cancelToken, headers = {}) {
300
+ if (!this.companyId || this.companyId.trim() === '') {
301
+ throw new StandardError(400, 'Company ID is required');
302
+ }
303
+ return this._fetch('POST', `/company/${this.companyId}/prepayments`, JSON.stringify(body), cancelToken, {
304
+ ...headers,
305
+ 'Content-Type': 'application/json',
306
+ })
307
+ .then(response => {
308
+ if (!response || !Array.isArray(response)) {
309
+ throw new StandardError(400, 'Invalid prepayments response');
310
+ }
311
+ return response;
312
+ })
313
+ .catch(err => {
314
+ console.error('Failed to fetch prepayments:', err);
315
+ throw new StandardError(500, 'Failed to fetch prepayments');
316
+ });
317
+ }
299
318
  async fetchEvents(body = {}, cancelToken, headers = {}) {
300
319
  if (!this.companyId || this.companyId.trim() === '') {
301
320
  throw new StandardError(400, 'Company ID is required');
@@ -21,8 +21,8 @@ AvroQueryClient.prototype.useGetMessages = function (chatId, body) {
21
21
  });
22
22
  if (result.data) {
23
23
  result.data.pages.forEach((data_page) => {
24
- data_page.forEach((chat) => {
25
- queryClient.setQueryData(['chat', chat.id], chat);
24
+ data_page.forEach((message) => {
25
+ queryClient.setQueryData(['message', message.id], message);
26
26
  });
27
27
  });
28
28
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import { useInfiniteQuery } from '@tanstack/react-query';
2
+ import { AvroQueryClient } from '../../client/QueryClient';
3
+ AvroQueryClient.prototype.useGetPrepayments = function (body) {
4
+ const queryClient = this.getQueryClient();
5
+ const result = useInfiniteQuery({
6
+ queryKey: [
7
+ 'prepayments',
8
+ this.companyId,
9
+ body.amt ?? 50,
10
+ body.known_ids ?? [],
11
+ body.unknown_ids ?? [],
12
+ body.query ?? '',
13
+ body.unbilled ?? true,
14
+ body.billed ?? true,
15
+ body.paid ?? true,
16
+ body.taskId ?? '',
17
+ ],
18
+ initialPageParam: 0,
19
+ getNextPageParam: (lastPage, allPages) => {
20
+ if (lastPage.length < (body.amt ?? 50))
21
+ return undefined;
22
+ return allPages.flat().length; // next offset
23
+ },
24
+ queryFn: ({ pageParam = 0 }) => this.fetchPrepayments({ ...body, offset: pageParam }),
25
+ });
26
+ if (result.data) {
27
+ result.data.pages.forEach((data_page) => {
28
+ data_page.forEach((prepayment) => {
29
+ queryClient.setQueryData(['prepayment', prepayment.id], prepayment);
30
+ });
31
+ });
32
+ }
33
+ return result;
34
+ };
@@ -563,6 +563,15 @@ export interface Job {
563
563
  labels: string[];
564
564
  owner: string;
565
565
  }
566
+ export interface Prepayment extends LineItem {
567
+ id: string;
568
+ task_id: string | null;
569
+ type: "SERVICE" | "MONTH";
570
+ time_created: number;
571
+ time_updated: number | null;
572
+ num_events: number;
573
+ num_service_months: number;
574
+ }
566
575
  export interface Task {
567
576
  enforce_proof_amount: boolean;
568
577
  events: _Event[];
@@ -592,8 +601,7 @@ export interface Task {
592
601
  expire_on: number | null;
593
602
  catalog_item_id: string | null;
594
603
  bill_day: number | null;
595
- services_prepaid: number;
596
- months_prepaid: number;
604
+ prepayments: Prepayment[];
597
605
  priority: boolean;
598
606
  route_ids: string[];
599
607
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.173",
3
+ "version": "0.0.2-beta.175",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",