@go-avro/avro-js 0.0.2-beta.65 → 0.0.2-beta.67

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, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
3
3
  import { AuthManager } from '../auth/AuthManager';
4
- import { _Event, ApiInfo, Bill, Break, Chat, Company, Job, LineItem, LoginResponse, Route, ServiceMonth, Session, User, UserCompanyAssociation } from '../types/api';
4
+ import { _Event, ApiInfo, Bill, Break, Chat, Company, Job, LineItem, LoginResponse, Message, Route, ServiceMonth, Session, User, UserCompanyAssociation } from '../types/api';
5
5
  import { Tokens } from '../types/auth';
6
6
  import { CancelToken, RetryStrategy } from '../types/client';
7
7
  import { StandardError } from '../types/error';
@@ -42,6 +42,16 @@ declare module '../client/QueryClient' {
42
42
  unknown_ids?: string[];
43
43
  query?: string;
44
44
  }): UseInfiniteQueryResult<InfiniteData<Chat[], unknown>, StandardError>;
45
+ useGetMessages(chatGuid: string, body: {
46
+ amt?: number;
47
+ known_ids?: string[];
48
+ unknown_ids?: string[];
49
+ query?: string;
50
+ unbilled?: boolean;
51
+ billed?: boolean;
52
+ paid?: boolean;
53
+ jobId?: string;
54
+ }): UseInfiniteQueryResult<InfiniteData<Message[], unknown>, StandardError>;
45
55
  useGetMonths(companyGuid: string, body: {
46
56
  amt?: number;
47
57
  known_ids?: string[];
@@ -240,6 +250,13 @@ export declare class AvroQueryClient {
240
250
  query?: string;
241
251
  offset?: number;
242
252
  }, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
253
+ fetchMessages(chatGuid: string, body?: {
254
+ amt?: number;
255
+ known_ids?: string[];
256
+ unknown_ids?: string[];
257
+ query?: string;
258
+ offset?: number;
259
+ }, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
243
260
  fetchEvents(companyGuid: string, body?: {
244
261
  amt?: number;
245
262
  known_ids?: string[];
@@ -141,6 +141,22 @@ export class AvroQueryClient {
141
141
  throw new StandardError(500, 'Failed to fetch chats');
142
142
  });
143
143
  }
144
+ fetchMessages(chatGuid, body = {}, cancelToken, headers = {}) {
145
+ if (!chatGuid || chatGuid.trim() === '') {
146
+ return Promise.reject(new StandardError(400, 'Chat GUID is required'));
147
+ }
148
+ return this._fetch('POST', `/chat/${chatGuid}/messages`, body, cancelToken, headers)
149
+ .then(response => {
150
+ if (!response || !Array.isArray(response)) {
151
+ throw new StandardError(400, 'Invalid messages response');
152
+ }
153
+ return response;
154
+ })
155
+ .catch(err => {
156
+ console.error('Failed to fetch messages:', err);
157
+ throw new StandardError(500, 'Failed to fetch messages');
158
+ });
159
+ }
144
160
  fetchEvents(companyGuid, body = {}, cancelToken, headers = {}) {
145
161
  if (!companyGuid || companyGuid.trim() === '') {
146
162
  return Promise.reject(new StandardError(400, 'Company GUID is required'));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ import { AvroQueryClient } from "../../client/QueryClient";
2
+ import { useInfiniteQuery, useQueryClient } from "@tanstack/react-query";
3
+ AvroQueryClient.prototype.useGetMessages = function (chatGuid, body) {
4
+ const queryClient = useQueryClient();
5
+ const result = useInfiniteQuery({
6
+ queryKey: [
7
+ 'messages',
8
+ chatGuid,
9
+ body.amt ?? 50,
10
+ body.known_ids ?? [],
11
+ body.unknown_ids ?? [],
12
+ body.query ?? '',
13
+ ],
14
+ initialPageParam: 0,
15
+ getNextPageParam: (lastPage, allPages) => {
16
+ if (lastPage.length < (body.amt ?? 50))
17
+ return undefined;
18
+ return allPages.flat().length; // next offset
19
+ },
20
+ queryFn: ({ pageParam = 0 }) => this.fetchMessages(chatGuid, { ...body, offset: pageParam }),
21
+ });
22
+ if (result.data) {
23
+ result.data.pages.forEach((data_page) => {
24
+ data_page.forEach((chat) => {
25
+ queryClient.setQueryData(['chat', chat.id], chat);
26
+ });
27
+ });
28
+ }
29
+ return result;
30
+ };
package/dist/index.d.ts CHANGED
@@ -13,6 +13,8 @@ import './client/hooks/bills';
13
13
  import './client/hooks/companies';
14
14
  import './client/hooks/users';
15
15
  import './client/hooks/sessions';
16
+ import './client/hooks/chats';
17
+ import './client/hooks/messages';
16
18
  export * from './types/api';
17
19
  export * from './types/auth';
18
20
  export * from './types/error';
package/dist/index.js CHANGED
@@ -13,6 +13,8 @@ import './client/hooks/bills';
13
13
  import './client/hooks/companies';
14
14
  import './client/hooks/users';
15
15
  import './client/hooks/sessions';
16
+ import './client/hooks/chats';
17
+ import './client/hooks/messages';
16
18
  export * from './types/api';
17
19
  export * from './types/auth';
18
20
  export * from './types/error';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.65",
3
+ "version": "0.0.2-beta.67",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",