@go-avro/avro-js 0.0.2-beta.66 → 0.0.2-beta.68
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.
- package/dist/client/QueryClient.d.ts +25 -1
- package/dist/client/QueryClient.js +16 -0
- package/dist/client/hooks/companies.js +28 -0
- package/dist/client/hooks/messages.d.ts +1 -0
- package/dist/client/hooks/messages.js +30 -0
- package/dist/client/hooks/plans.d.ts +1 -0
- package/dist/client/hooks/plans.js +9 -0
- package/dist/client/hooks/users.js +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/types/api.d.ts +2 -0
- package/package.json +1 -1
|
@@ -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, Plan, 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[];
|
|
@@ -59,6 +69,7 @@ declare module '../client/QueryClient' {
|
|
|
59
69
|
query?: string;
|
|
60
70
|
paid?: boolean;
|
|
61
71
|
}): UseInfiniteQueryResult<InfiniteData<Bill[], unknown>, StandardError>;
|
|
72
|
+
useGetPlans(code: string): UseQueryResult<Plan[], StandardError>;
|
|
62
73
|
useGetCompanies(options?: {}): UseQueryResult<{
|
|
63
74
|
name: string;
|
|
64
75
|
id: string;
|
|
@@ -72,6 +83,7 @@ declare module '../client/QueryClient' {
|
|
|
72
83
|
useGetRoute(routeId: string): UseQueryResult<Route, StandardError>;
|
|
73
84
|
useGetChat(chatId: string): UseQueryResult<Chat, StandardError>;
|
|
74
85
|
useGetUserSessions(): UseQueryResult<Session[], StandardError>;
|
|
86
|
+
useSearchUsers(searchUsername: string): UseQueryResult<User[], StandardError>;
|
|
75
87
|
useCreateEvent(): ReturnType<typeof useMutation<{
|
|
76
88
|
id: string;
|
|
77
89
|
}, StandardError, {
|
|
@@ -205,6 +217,11 @@ declare module '../client/QueryClient' {
|
|
|
205
217
|
useDeleteSelf(): ReturnType<typeof useMutation<{
|
|
206
218
|
msg: string;
|
|
207
219
|
}, StandardError, void>>;
|
|
220
|
+
useDeleteCompany(): ReturnType<typeof useMutation<{
|
|
221
|
+
msg: string;
|
|
222
|
+
}, StandardError, {
|
|
223
|
+
companyId: string;
|
|
224
|
+
}>>;
|
|
208
225
|
}
|
|
209
226
|
}
|
|
210
227
|
export declare class AvroQueryClient {
|
|
@@ -240,6 +257,13 @@ export declare class AvroQueryClient {
|
|
|
240
257
|
query?: string;
|
|
241
258
|
offset?: number;
|
|
242
259
|
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
260
|
+
fetchMessages(chatGuid: string, body?: {
|
|
261
|
+
amt?: number;
|
|
262
|
+
known_ids?: string[];
|
|
263
|
+
unknown_ids?: string[];
|
|
264
|
+
query?: string;
|
|
265
|
+
offset?: number;
|
|
266
|
+
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
243
267
|
fetchEvents(companyGuid: string, body?: {
|
|
244
268
|
amt?: number;
|
|
245
269
|
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'));
|
|
@@ -49,3 +49,31 @@ AvroQueryClient.prototype.useUpdateCompany = function () {
|
|
|
49
49
|
},
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
|
+
AvroQueryClient.prototype.useDeleteCompany = function () {
|
|
53
|
+
const queryClient = useQueryClient();
|
|
54
|
+
return useMutation({
|
|
55
|
+
mutationFn: async ({ companyId }) => {
|
|
56
|
+
return this.delete(`/company/${companyId}`);
|
|
57
|
+
},
|
|
58
|
+
onMutate: async ({ companyId }) => {
|
|
59
|
+
await queryClient.cancelQueries({ queryKey: ['/company/list'] });
|
|
60
|
+
await queryClient.cancelQueries({ queryKey: ['company', companyId] });
|
|
61
|
+
const previousCompanyList = queryClient.getQueryData(['/company/list']);
|
|
62
|
+
queryClient.setQueryData(['/company/list'], (oldList) => {
|
|
63
|
+
if (!oldList)
|
|
64
|
+
return oldList;
|
|
65
|
+
return oldList.filter((company) => company.id !== companyId);
|
|
66
|
+
});
|
|
67
|
+
return { previousCompanyList };
|
|
68
|
+
},
|
|
69
|
+
onError: (err, companyId, context) => {
|
|
70
|
+
if (context?.previousCompanyList) {
|
|
71
|
+
queryClient.setQueryData(['/company/list'], context.previousCompanyList);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
onSettled: (_data, _error, companyId) => {
|
|
75
|
+
queryClient.invalidateQueries({ queryKey: ['/company/list'] });
|
|
76
|
+
queryClient.invalidateQueries({ queryKey: ['company', companyId] });
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AvroQueryClient } from "../../client/QueryClient";
|
|
2
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
AvroQueryClient.prototype.useGetPlans = function (code) {
|
|
4
|
+
const queryClient = useQueryClient();
|
|
5
|
+
return useQuery({
|
|
6
|
+
queryKey: ['plans', code],
|
|
7
|
+
queryFn: async () => this.get(`/plans${code ? `?code=${code}` : ''}`),
|
|
8
|
+
});
|
|
9
|
+
};
|
|
@@ -7,6 +7,17 @@ AvroQueryClient.prototype.useGetUser = function (userId) {
|
|
|
7
7
|
enabled: Boolean(userId),
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
AvroQueryClient.prototype.useSearchUsers = function (searchUsername) {
|
|
11
|
+
return useQuery({
|
|
12
|
+
queryKey: ['user', 'search', searchUsername],
|
|
13
|
+
queryFn: () => {
|
|
14
|
+
if (!searchUsername)
|
|
15
|
+
return Promise.resolve([]);
|
|
16
|
+
return this.get(`/user/search/${searchUsername}`);
|
|
17
|
+
},
|
|
18
|
+
enabled: Boolean(searchUsername),
|
|
19
|
+
});
|
|
20
|
+
};
|
|
10
21
|
AvroQueryClient.prototype.useGetSelf = function () {
|
|
11
22
|
return useQuery({
|
|
12
23
|
queryKey: ['user'],
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ import './client/hooks/companies';
|
|
|
14
14
|
import './client/hooks/users';
|
|
15
15
|
import './client/hooks/sessions';
|
|
16
16
|
import './client/hooks/chats';
|
|
17
|
+
import './client/hooks/messages';
|
|
18
|
+
import './client/hooks/plans';
|
|
17
19
|
export * from './types/api';
|
|
18
20
|
export * from './types/auth';
|
|
19
21
|
export * from './types/error';
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,8 @@ import './client/hooks/companies';
|
|
|
14
14
|
import './client/hooks/users';
|
|
15
15
|
import './client/hooks/sessions';
|
|
16
16
|
import './client/hooks/chats';
|
|
17
|
+
import './client/hooks/messages';
|
|
18
|
+
import './client/hooks/plans';
|
|
17
19
|
export * from './types/api';
|
|
18
20
|
export * from './types/auth';
|
|
19
21
|
export * from './types/error';
|
package/dist/types/api.d.ts
CHANGED