@go-avro/avro-js 0.0.2-beta.63 → 0.0.2-beta.65
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, Company, Job, LineItem, LoginResponse, Route, ServiceMonth, Session, User, UserCompanyAssociation } from '../types/api';
|
|
4
|
+
import { _Event, ApiInfo, Bill, Break, Chat, Company, Job, LineItem, LoginResponse, 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';
|
|
@@ -36,6 +36,12 @@ declare module '../client/QueryClient' {
|
|
|
36
36
|
paid?: boolean;
|
|
37
37
|
jobId?: string;
|
|
38
38
|
}): UseInfiniteQueryResult<InfiniteData<_Event[], unknown>, StandardError>;
|
|
39
|
+
useGetChats(companyGuid: string, body: {
|
|
40
|
+
amt?: number;
|
|
41
|
+
known_ids?: string[];
|
|
42
|
+
unknown_ids?: string[];
|
|
43
|
+
query?: string;
|
|
44
|
+
}): UseInfiniteQueryResult<InfiniteData<Chat[], unknown>, StandardError>;
|
|
39
45
|
useGetMonths(companyGuid: string, body: {
|
|
40
46
|
amt?: number;
|
|
41
47
|
known_ids?: string[];
|
|
@@ -64,6 +70,7 @@ declare module '../client/QueryClient' {
|
|
|
64
70
|
useGetSelf(): UseQueryResult<User, StandardError>;
|
|
65
71
|
useGetBill(billId: string): UseQueryResult<Bill, StandardError>;
|
|
66
72
|
useGetRoute(routeId: string): UseQueryResult<Route, StandardError>;
|
|
73
|
+
useGetChat(chatId: string): UseQueryResult<Chat, StandardError>;
|
|
67
74
|
useGetUserSessions(): UseQueryResult<Session[], StandardError>;
|
|
68
75
|
useCreateEvent(): ReturnType<typeof useMutation<{
|
|
69
76
|
id: string;
|
|
@@ -226,6 +233,13 @@ export declare class AvroQueryClient {
|
|
|
226
233
|
query?: string;
|
|
227
234
|
offset?: number;
|
|
228
235
|
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
236
|
+
fetchChats(companyGuid: string, body?: {
|
|
237
|
+
amt?: number;
|
|
238
|
+
known_ids?: string[];
|
|
239
|
+
unknown_ids?: string[];
|
|
240
|
+
query?: string;
|
|
241
|
+
offset?: number;
|
|
242
|
+
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
229
243
|
fetchEvents(companyGuid: string, body?: {
|
|
230
244
|
amt?: number;
|
|
231
245
|
known_ids?: string[];
|
|
@@ -125,6 +125,22 @@ export class AvroQueryClient {
|
|
|
125
125
|
throw new StandardError(500, 'Failed to fetch jobs');
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
|
+
fetchChats(companyGuid, body = {}, cancelToken, headers = {}) {
|
|
129
|
+
if (!companyGuid || companyGuid.trim() === '') {
|
|
130
|
+
return Promise.reject(new StandardError(400, 'Company GUID is required'));
|
|
131
|
+
}
|
|
132
|
+
return this._fetch('POST', `/company/${companyGuid}/chats`, body, cancelToken, headers)
|
|
133
|
+
.then(response => {
|
|
134
|
+
if (!response || !Array.isArray(response)) {
|
|
135
|
+
throw new StandardError(400, 'Invalid chats response');
|
|
136
|
+
}
|
|
137
|
+
return response;
|
|
138
|
+
})
|
|
139
|
+
.catch(err => {
|
|
140
|
+
console.error('Failed to fetch chats:', err);
|
|
141
|
+
throw new StandardError(500, 'Failed to fetch chats');
|
|
142
|
+
});
|
|
143
|
+
}
|
|
128
144
|
fetchEvents(companyGuid, body = {}, cancelToken, headers = {}) {
|
|
129
145
|
if (!companyGuid || companyGuid.trim() === '') {
|
|
130
146
|
return Promise.reject(new StandardError(400, 'Company GUID is required'));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AvroQueryClient } from "../../client/QueryClient";
|
|
2
|
+
import { useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
AvroQueryClient.prototype.useGetChats = function (companyGuid, body) {
|
|
4
|
+
const queryClient = useQueryClient();
|
|
5
|
+
const result = useInfiniteQuery({
|
|
6
|
+
queryKey: [
|
|
7
|
+
'chats',
|
|
8
|
+
companyGuid,
|
|
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.fetchChats(companyGuid, { ...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
|
+
};
|
|
31
|
+
AvroQueryClient.prototype.useGetChat = function (chatId) {
|
|
32
|
+
return useQuery({
|
|
33
|
+
queryKey: ['chat', chatId],
|
|
34
|
+
queryFn: () => this.get(`/chat/${chatId}`),
|
|
35
|
+
enabled: Boolean(chatId),
|
|
36
|
+
});
|
|
37
|
+
};
|
package/dist/types/api.d.ts
CHANGED
|
@@ -277,7 +277,7 @@ export interface UserCompanyAssociation {
|
|
|
277
277
|
effective_permissions: string[];
|
|
278
278
|
time_created: number | null;
|
|
279
279
|
time_updated: number | null;
|
|
280
|
-
notification_setting:
|
|
280
|
+
notification_setting: NotificationLevel[];
|
|
281
281
|
share_email_company_wide: boolean;
|
|
282
282
|
notifications: Notification[];
|
|
283
283
|
groups: string[];
|