@go-avro/avro-js 0.0.2-beta.165 → 0.0.2-beta.167
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/auth/AuthManager.d.ts +1 -1
- package/dist/auth/AuthManager.js +2 -2
- package/dist/client/QueryClient.d.ts +27 -6
- package/dist/client/QueryClient.js +6 -5
- package/dist/client/hooks/catalog_items.d.ts +1 -0
- package/dist/client/hooks/catalog_items.js +90 -0
- package/dist/client/hooks/jobs.js +8 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/api.d.ts +19 -0
- package/package.json +1 -1
|
@@ -19,6 +19,6 @@ export declare class AuthManager {
|
|
|
19
19
|
setCache(data: Partial<CacheData>): Promise<void>;
|
|
20
20
|
getCache(key?: keyof CacheData): Promise<CacheData | string | null>;
|
|
21
21
|
clearCache(): Promise<void>;
|
|
22
|
-
getCompanyId(): Promise<string |
|
|
22
|
+
getCompanyId(): Promise<string | undefined>;
|
|
23
23
|
setCompanyId(companyId: string): Promise<void[]>;
|
|
24
24
|
}
|
package/dist/auth/AuthManager.js
CHANGED
|
@@ -129,14 +129,14 @@ export class AuthManager {
|
|
|
129
129
|
}
|
|
130
130
|
async getCompanyId() {
|
|
131
131
|
if (!this.storages.length) {
|
|
132
|
-
return
|
|
132
|
+
return undefined;
|
|
133
133
|
}
|
|
134
134
|
for (const storage of this.storages) {
|
|
135
135
|
const companyId = await storage.get('companyId');
|
|
136
136
|
if (companyId && typeof companyId === 'string')
|
|
137
137
|
return companyId;
|
|
138
138
|
}
|
|
139
|
-
return
|
|
139
|
+
return undefined;
|
|
140
140
|
}
|
|
141
141
|
async setCompanyId(companyId) {
|
|
142
142
|
return Promise.all(this.storages.map(s => s.set({ companyId })));
|
|
@@ -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 } 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 } 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';
|
|
@@ -20,7 +20,11 @@ declare module '../client/QueryClient' {
|
|
|
20
20
|
getDelay(strategy: RetryStrategy, attempt: number): number;
|
|
21
21
|
sleep(ms: number): Promise<void>;
|
|
22
22
|
useGetRoot(): UseQueryResult<ApiInfo, StandardError>;
|
|
23
|
-
useGetJobs(
|
|
23
|
+
useGetJobs(params?: {
|
|
24
|
+
companyId?: string;
|
|
25
|
+
numJobs?: number;
|
|
26
|
+
onProgress?: (fraction: number) => void;
|
|
27
|
+
}): UseQueryResult<Job[], StandardError>;
|
|
24
28
|
getJobsFromCache(queryClient?: QueryClient): Job[];
|
|
25
29
|
useGetInfiniteJobs(body: {
|
|
26
30
|
amt?: number;
|
|
@@ -120,6 +124,7 @@ declare module '../client/QueryClient' {
|
|
|
120
124
|
useGetBill(billId: string): UseQueryResult<Bill, StandardError>;
|
|
121
125
|
useGetRoute(routeId: string): UseQueryResult<Route, StandardError>;
|
|
122
126
|
useGetChat(chatId: string): UseQueryResult<Chat, StandardError>;
|
|
127
|
+
useGetCatalogItem(catalogItemId: string): UseQueryResult<CatalogItem, StandardError>;
|
|
123
128
|
useGetUserSessions(): UseQueryResult<Session[], StandardError>;
|
|
124
129
|
useGetAvro(): UseQueryResult<Avro, StandardError>;
|
|
125
130
|
useSearchUsers(searchUsername: string): UseQueryResult<User[], StandardError>;
|
|
@@ -176,6 +181,11 @@ declare module '../client/QueryClient' {
|
|
|
176
181
|
logo: File | null;
|
|
177
182
|
}>;
|
|
178
183
|
}>>;
|
|
184
|
+
useCreateCatalogItem(): ReturnType<typeof useMutation<{
|
|
185
|
+
id: string;
|
|
186
|
+
}, StandardError, {
|
|
187
|
+
data: Partial<CatalogItem>;
|
|
188
|
+
}>>;
|
|
179
189
|
useCreateJob(): ReturnType<typeof useMutation<{
|
|
180
190
|
id: string;
|
|
181
191
|
}, StandardError, {
|
|
@@ -242,6 +252,12 @@ declare module '../client/QueryClient' {
|
|
|
242
252
|
labelId: string;
|
|
243
253
|
labelData: Partial<Label>;
|
|
244
254
|
}>>;
|
|
255
|
+
useUpdateCatalogItem(): ReturnType<typeof useMutation<{
|
|
256
|
+
msg: string;
|
|
257
|
+
}, StandardError, {
|
|
258
|
+
catalogItemId: string;
|
|
259
|
+
data: Partial<CatalogItem>;
|
|
260
|
+
}>>;
|
|
245
261
|
useUpdateJob(): ReturnType<typeof useMutation<{
|
|
246
262
|
msg: string;
|
|
247
263
|
}, StandardError, {
|
|
@@ -290,6 +306,11 @@ declare module '../client/QueryClient' {
|
|
|
290
306
|
user_id: string;
|
|
291
307
|
data: Partial<UserCompanyAssociation>;
|
|
292
308
|
}>>;
|
|
309
|
+
useDeleteCatalogItem(): ReturnType<typeof useMutation<{
|
|
310
|
+
msg: string;
|
|
311
|
+
}, StandardError, {
|
|
312
|
+
catalogItemId: string;
|
|
313
|
+
}>>;
|
|
293
314
|
useUpdateSessionBreak(): ReturnType<typeof useMutation<{
|
|
294
315
|
msg: string;
|
|
295
316
|
}, StandardError, {
|
|
@@ -377,8 +398,8 @@ export declare class AvroQueryClient {
|
|
|
377
398
|
protected config: Required<AvroQueryClientConfig>;
|
|
378
399
|
readonly socket: Socket;
|
|
379
400
|
_authState: AuthState;
|
|
380
|
-
companyId: string |
|
|
381
|
-
company: Company |
|
|
401
|
+
companyId: string | undefined;
|
|
402
|
+
company: Company | undefined;
|
|
382
403
|
private authStateListeners;
|
|
383
404
|
constructor(config: AvroQueryClientConfig);
|
|
384
405
|
emit(eventName: string, data: unknown): void;
|
|
@@ -416,7 +437,7 @@ export declare class AvroQueryClient {
|
|
|
416
437
|
setCache(data: Partial<CacheData>): Promise<void>;
|
|
417
438
|
getCache(key?: keyof CacheData | undefined): Promise<CacheData | string | null>;
|
|
418
439
|
setCompanyId(companyId: string): Promise<void[]>;
|
|
419
|
-
getCompanyId(): Promise<string |
|
|
440
|
+
getCompanyId(): Promise<string | undefined>;
|
|
420
441
|
clearCache(): Promise<void>;
|
|
421
442
|
onAuthStateChange(cb: (v: AuthState) => void): () => void;
|
|
422
443
|
offAuthStateChange(cb: (v: AuthState) => void): void;
|
|
@@ -432,7 +453,7 @@ export declare class AvroQueryClient {
|
|
|
432
453
|
query?: string;
|
|
433
454
|
offset?: number;
|
|
434
455
|
route_id?: string;
|
|
435
|
-
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
456
|
+
}, companyId?: string, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
436
457
|
fetchChats(body?: {
|
|
437
458
|
amt?: number;
|
|
438
459
|
known_ids?: string[];
|
|
@@ -6,8 +6,8 @@ import { StandardError } from '../types/error';
|
|
|
6
6
|
export class AvroQueryClient {
|
|
7
7
|
constructor(config) {
|
|
8
8
|
this._authState = AuthState.UNKNOWN;
|
|
9
|
-
this.companyId =
|
|
10
|
-
this.company =
|
|
9
|
+
this.companyId = undefined;
|
|
10
|
+
this.company = undefined;
|
|
11
11
|
this.authStateListeners = [];
|
|
12
12
|
this.config = {
|
|
13
13
|
baseUrl: config.baseUrl,
|
|
@@ -238,11 +238,12 @@ export class AvroQueryClient {
|
|
|
238
238
|
}
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
|
-
fetchJobs(body = {}, cancelToken, headers = {}) {
|
|
242
|
-
|
|
241
|
+
fetchJobs(body = {}, companyId, cancelToken, headers = {}) {
|
|
242
|
+
const companyIdToUse = companyId ?? this.companyId;
|
|
243
|
+
if (!companyIdToUse || companyIdToUse.trim() === '') {
|
|
243
244
|
throw new StandardError(400, 'Company ID is required');
|
|
244
245
|
}
|
|
245
|
-
return this._fetch('POST', `/company/${
|
|
246
|
+
return this._fetch('POST', `/company/${companyIdToUse}/jobs`, JSON.stringify(body), cancelToken, {
|
|
246
247
|
...headers,
|
|
247
248
|
'Content-Type': 'application/json',
|
|
248
249
|
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
AvroQueryClient.prototype.useCreateCatalogItem = function () {
|
|
4
|
+
const queryClient = this.getQueryClient();
|
|
5
|
+
return useMutation({
|
|
6
|
+
mutationFn: async ({ data }) => {
|
|
7
|
+
return this.post(`/company/${this.companyId}/catalog`, JSON.stringify(data), undefined, { 'Content-Type': 'application/json' });
|
|
8
|
+
},
|
|
9
|
+
onMutate: async () => {
|
|
10
|
+
await queryClient.cancelQueries({ queryKey: ['catalog_items', this.companyId] });
|
|
11
|
+
const previousItems = queryClient.getQueryData(['catalog_items', this.companyId]);
|
|
12
|
+
return { previousItems };
|
|
13
|
+
},
|
|
14
|
+
onError: (_err, _variables, context) => {
|
|
15
|
+
if (context?.previousItems) {
|
|
16
|
+
queryClient.setQueryData(['catalog_items', this.companyId], context.previousItems);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
onSettled: () => {
|
|
20
|
+
queryClient.invalidateQueries({ queryKey: ['catalog_items', this.companyId] });
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
AvroQueryClient.prototype.useUpdateCatalogItem = function () {
|
|
25
|
+
const queryClient = this.getQueryClient();
|
|
26
|
+
return useMutation({
|
|
27
|
+
mutationFn: ({ catalogItemId, data }) => {
|
|
28
|
+
return this.put(`/catalog_item/${catalogItemId}`, JSON.stringify(data), undefined, {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
onMutate: async ({ catalogItemId, data }) => {
|
|
33
|
+
await queryClient.cancelQueries({ queryKey: ['catalog_items'] });
|
|
34
|
+
await queryClient.cancelQueries({ queryKey: ['catalog_item', catalogItemId] });
|
|
35
|
+
const previousItems = queryClient.getQueryData(['catalog_items']);
|
|
36
|
+
const previousItem = queryClient.getQueryData(['catalog_item', catalogItemId]);
|
|
37
|
+
queryClient.setQueryData(['catalog_item', catalogItemId], (oldData) => oldData ? { ...oldData, ...data } : undefined);
|
|
38
|
+
queryClient.setQueriesData({ queryKey: ['catalog_items'] }, (oldData) => {
|
|
39
|
+
if (!oldData)
|
|
40
|
+
return oldData;
|
|
41
|
+
if (oldData.pages) {
|
|
42
|
+
return {
|
|
43
|
+
...oldData,
|
|
44
|
+
pages: oldData.pages.map((page) => page.map((item) => item.id === catalogItemId ? { ...item, ...data } : item)),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(oldData)) {
|
|
48
|
+
return oldData.map((item) => item.id === catalogItemId ? { ...item, ...data } : item);
|
|
49
|
+
}
|
|
50
|
+
return oldData;
|
|
51
|
+
});
|
|
52
|
+
return { previousItems, previousItem };
|
|
53
|
+
},
|
|
54
|
+
onError: (err, variables, context) => {
|
|
55
|
+
const { catalogItemId } = variables;
|
|
56
|
+
if (context?.previousItems) {
|
|
57
|
+
queryClient.setQueryData(['catalog_items'], context.previousItems);
|
|
58
|
+
}
|
|
59
|
+
if (context?.previousItem) {
|
|
60
|
+
queryClient.setQueryData(['catalog_item', catalogItemId], context.previousItem);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
onSettled: (_data, _error, variables) => {
|
|
64
|
+
const { catalogItemId } = variables;
|
|
65
|
+
queryClient.invalidateQueries({ queryKey: ['catalog_items'] });
|
|
66
|
+
queryClient.invalidateQueries({ queryKey: ['catalog_item', catalogItemId] });
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
AvroQueryClient.prototype.useDeleteCatalogItem = function () {
|
|
71
|
+
const queryClient = this.getQueryClient();
|
|
72
|
+
return useMutation({
|
|
73
|
+
mutationFn: async ({ catalogItemId }) => {
|
|
74
|
+
return this.delete(`/catalog_item/${catalogItemId}`);
|
|
75
|
+
},
|
|
76
|
+
onMutate: async ({ catalogItemId }) => {
|
|
77
|
+
await queryClient.cancelQueries({ queryKey: ['catalog_items'] });
|
|
78
|
+
const previousItems = queryClient.getQueryData(['catalog_items']);
|
|
79
|
+
return { previousItems };
|
|
80
|
+
},
|
|
81
|
+
onError: (_err, _variables, context) => {
|
|
82
|
+
if (context?.previousItems) {
|
|
83
|
+
queryClient.setQueryData(['catalog_items'], context.previousItems);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
onSettled: (_data, _error) => {
|
|
87
|
+
queryClient.invalidateQueries({ queryKey: ['catalog_items'] });
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
};
|
|
@@ -6,20 +6,22 @@ AvroQueryClient.prototype.getJobsFromCache = function (queryClient) {
|
|
|
6
6
|
}
|
|
7
7
|
return (queryClient.getQueryData(['jobs', this.companyId, this.company?.num_jobs]) ?? []);
|
|
8
8
|
};
|
|
9
|
-
AvroQueryClient.prototype.useGetJobs = function (
|
|
9
|
+
AvroQueryClient.prototype.useGetJobs = function (params) {
|
|
10
10
|
const queryClient = this.getQueryClient();
|
|
11
11
|
const amt = 50;
|
|
12
|
+
const company_id = params?.companyId ?? this.companyId;
|
|
13
|
+
const num_jobs = params?.numJobs ?? this.company?.num_jobs ?? 0;
|
|
12
14
|
return useQuery({
|
|
13
|
-
queryKey: ['jobs',
|
|
15
|
+
queryKey: ['jobs', company_id, num_jobs],
|
|
14
16
|
queryFn: async () => {
|
|
15
|
-
onProgress?.(0);
|
|
16
|
-
const pageCount = amt ? Math.ceil((
|
|
17
|
+
params?.onProgress?.(0);
|
|
18
|
+
const pageCount = amt ? Math.ceil((num_jobs ?? 0) / amt) + 1 : 1;
|
|
17
19
|
let completed = 0;
|
|
18
|
-
const promises = Array.from({ length: pageCount }, (_, i) => this.fetchJobs({ offset: i * (amt ?? 1), amt }));
|
|
20
|
+
const promises = Array.from({ length: pageCount }, (_, i) => this.fetchJobs({ offset: i * (amt ?? 1), amt }, company_id));
|
|
19
21
|
const trackedPromises = promises.map((promise) => promise.then((result) => {
|
|
20
22
|
completed++;
|
|
21
23
|
const fraction = completed / pageCount;
|
|
22
|
-
onProgress?.(fraction);
|
|
24
|
+
params?.onProgress?.(fraction);
|
|
23
25
|
return result;
|
|
24
26
|
}));
|
|
25
27
|
const pages = await Promise.all(trackedPromises);
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ import './client/hooks/companies';
|
|
|
15
15
|
import './client/hooks/users';
|
|
16
16
|
import './client/hooks/sessions';
|
|
17
17
|
import './client/hooks/chats';
|
|
18
|
+
import './client/hooks/catalog_items';
|
|
18
19
|
import './client/hooks/messages';
|
|
19
20
|
import './client/hooks/plans';
|
|
20
21
|
import './client/hooks/analytics';
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import './client/hooks/companies';
|
|
|
15
15
|
import './client/hooks/users';
|
|
16
16
|
import './client/hooks/sessions';
|
|
17
17
|
import './client/hooks/chats';
|
|
18
|
+
import './client/hooks/catalog_items';
|
|
18
19
|
import './client/hooks/messages';
|
|
19
20
|
import './client/hooks/plans';
|
|
20
21
|
import './client/hooks/analytics';
|
package/dist/types/api.d.ts
CHANGED
|
@@ -7,6 +7,24 @@ export interface ApiInfo {
|
|
|
7
7
|
version: string;
|
|
8
8
|
vroom_healthy: boolean;
|
|
9
9
|
}
|
|
10
|
+
export interface CatalogItem {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
company_id: string;
|
|
14
|
+
description: string;
|
|
15
|
+
industry: string;
|
|
16
|
+
price_format: string;
|
|
17
|
+
payment_options: PaymentOption[];
|
|
18
|
+
}
|
|
19
|
+
export interface PaymentOption {
|
|
20
|
+
name: string;
|
|
21
|
+
id: string;
|
|
22
|
+
is_prepay: boolean;
|
|
23
|
+
price_under_prepay?: number;
|
|
24
|
+
price: number;
|
|
25
|
+
recommended_prepay_count?: number;
|
|
26
|
+
mode: "MONTH" | "SERVICE";
|
|
27
|
+
}
|
|
10
28
|
export interface PaymentMethod {
|
|
11
29
|
allow_redisplay: string;
|
|
12
30
|
autopay: boolean;
|
|
@@ -438,6 +456,7 @@ export interface Company {
|
|
|
438
456
|
email: string;
|
|
439
457
|
emails: Email[];
|
|
440
458
|
skills: Skill[];
|
|
459
|
+
catalog_items: CatalogItem[];
|
|
441
460
|
time_created: number;
|
|
442
461
|
time_updated: number | null;
|
|
443
462
|
users: UserCompanyAssociation[];
|