@go-avro/avro-js 0.0.2-beta.7 → 0.0.2-beta.70

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.
Files changed (46) hide show
  1. package/README.md +1 -0
  2. package/dist/auth/AuthManager.d.ts +2 -0
  3. package/dist/auth/AuthManager.js +8 -0
  4. package/dist/client/QueryClient.d.ts +314 -12
  5. package/dist/client/QueryClient.js +211 -186
  6. package/dist/client/core/fetch.d.ts +1 -0
  7. package/dist/client/core/fetch.js +67 -0
  8. package/dist/client/core/utils.d.ts +1 -0
  9. package/dist/client/core/utils.js +13 -0
  10. package/dist/client/core/xhr.d.ts +1 -0
  11. package/dist/client/core/xhr.js +87 -0
  12. package/dist/client/hooks/analytics.d.ts +1 -0
  13. package/dist/client/hooks/analytics.js +10 -0
  14. package/dist/client/hooks/avro.d.ts +1 -0
  15. package/dist/client/hooks/avro.js +9 -0
  16. package/dist/client/hooks/bills.d.ts +1 -0
  17. package/dist/client/hooks/bills.js +141 -0
  18. package/dist/client/hooks/chats.d.ts +1 -0
  19. package/dist/client/hooks/chats.js +37 -0
  20. package/dist/client/hooks/companies.d.ts +1 -0
  21. package/dist/client/hooks/companies.js +79 -0
  22. package/dist/client/hooks/events.d.ts +1 -0
  23. package/dist/client/hooks/events.js +307 -0
  24. package/dist/client/hooks/jobs.d.ts +1 -0
  25. package/dist/client/hooks/jobs.js +184 -0
  26. package/dist/client/hooks/messages.d.ts +1 -0
  27. package/dist/client/hooks/messages.js +30 -0
  28. package/dist/client/hooks/months.d.ts +1 -0
  29. package/dist/client/hooks/months.js +92 -0
  30. package/dist/client/hooks/plans.d.ts +1 -0
  31. package/dist/client/hooks/plans.js +9 -0
  32. package/dist/client/hooks/root.d.ts +1 -0
  33. package/dist/client/hooks/root.js +8 -0
  34. package/dist/client/hooks/routes.d.ts +1 -0
  35. package/dist/client/hooks/routes.js +125 -0
  36. package/dist/client/hooks/sessions.d.ts +1 -0
  37. package/dist/client/hooks/sessions.js +154 -0
  38. package/dist/client/hooks/teams.d.ts +1 -0
  39. package/dist/client/hooks/teams.js +73 -0
  40. package/dist/client/hooks/users.d.ts +1 -0
  41. package/dist/client/hooks/users.js +104 -0
  42. package/dist/index.d.ts +19 -0
  43. package/dist/index.js +19 -0
  44. package/dist/types/api.d.ts +115 -24
  45. package/dist/types/api.js +10 -1
  46. package/package.json +6 -1
@@ -0,0 +1,73 @@
1
+ import { AvroQueryClient } from "../../client/QueryClient";
2
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3
+ AvroQueryClient.prototype.useGetTeams = function (companyGuid, body, total = 0, onProgress) {
4
+ const queryClient = useQueryClient();
5
+ return useQuery({
6
+ queryKey: ['teams', companyGuid, body.amt ?? 50, body.query ?? ""],
7
+ queryFn: async () => {
8
+ if (total === 0) {
9
+ onProgress?.(1);
10
+ return [];
11
+ }
12
+ onProgress?.(0);
13
+ const pageCount = body.amt ? Math.ceil(total / body.amt) : 0;
14
+ let completed = 0;
15
+ const promises = Array.from({ length: pageCount }, (_, i) => this.fetchTeams(companyGuid, {
16
+ ...body,
17
+ offset: i * (body.amt ?? 0),
18
+ }));
19
+ const trackedPromises = promises.map((promise) => promise.then((result) => {
20
+ completed++;
21
+ const fraction = completed / pageCount;
22
+ onProgress?.(fraction);
23
+ return result;
24
+ }));
25
+ const pages = await Promise.all(trackedPromises);
26
+ const routes = pages.flat();
27
+ return routes;
28
+ },
29
+ enabled: Boolean(companyGuid) && companyGuid.length > 0 && Boolean(total) && total >= 0,
30
+ });
31
+ };
32
+ AvroQueryClient.prototype.useDeleteTeam = function () {
33
+ const queryClient = useQueryClient();
34
+ return useMutation({
35
+ mutationFn: async ({ teamId, }) => {
36
+ return this.delete(`/team/${teamId}`);
37
+ },
38
+ onMutate: async ({ teamId }) => {
39
+ await queryClient.cancelQueries({ queryKey: ['teams'] });
40
+ await queryClient.cancelQueries({ queryKey: ['team', teamId] });
41
+ const previousRoutes = queryClient.getQueryData(['teams']);
42
+ const previousRoute = queryClient.getQueryData(['team', teamId]);
43
+ queryClient.setQueryData(['team', teamId], undefined);
44
+ queryClient.setQueriesData({ queryKey: ['teams'] }, (oldData) => {
45
+ if (!oldData)
46
+ return oldData;
47
+ if (oldData.pages) {
48
+ const updatedPages = oldData.pages.map((page) => page.filter((team) => team.id !== teamId));
49
+ return { ...oldData, pages: updatedPages };
50
+ }
51
+ if (Array.isArray(oldData)) {
52
+ return oldData.filter((team) => team.id !== teamId);
53
+ }
54
+ return oldData;
55
+ });
56
+ return { previousRoutes, previousRoute };
57
+ },
58
+ onError: (_err, variables, context) => {
59
+ const { teamId } = variables;
60
+ if (context?.previousRoutes) {
61
+ queryClient.setQueryData(['teams'], context.previousRoutes);
62
+ }
63
+ if (context?.previousRoute) {
64
+ queryClient.setQueryData(['team', teamId], context.previousRoute);
65
+ }
66
+ },
67
+ onSettled: (_data, _error, variables) => {
68
+ const { teamId } = variables;
69
+ queryClient.invalidateQueries({ queryKey: ['teams'] });
70
+ queryClient.invalidateQueries({ queryKey: ['team', teamId] });
71
+ },
72
+ });
73
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,104 @@
1
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2
+ import { AvroQueryClient } from "../../client/QueryClient";
3
+ AvroQueryClient.prototype.useGetUser = function (userId) {
4
+ return useQuery({
5
+ queryKey: ['user', userId],
6
+ queryFn: () => this.get(`/user/${userId}`),
7
+ enabled: Boolean(userId),
8
+ });
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
+ };
21
+ AvroQueryClient.prototype.useGetSelf = function () {
22
+ return useQuery({
23
+ queryKey: ['user'],
24
+ queryFn: () => this.get(`/user`),
25
+ enabled: Boolean(this),
26
+ });
27
+ };
28
+ AvroQueryClient.prototype.useCreateSelf = function () {
29
+ const queryClient = useQueryClient();
30
+ return useMutation({
31
+ mutationFn: async (data) => {
32
+ return this.post('/user', JSON.stringify(data), undefined, { "Content-Type": "application/json" });
33
+ },
34
+ onSettled: () => {
35
+ queryClient.invalidateQueries({ queryKey: ['user'] });
36
+ },
37
+ });
38
+ };
39
+ AvroQueryClient.prototype.useUpdateUserCompany = function () {
40
+ const queryClient = useQueryClient();
41
+ return useMutation({
42
+ mutationFn: async ({ company_id, user_id, data }) => {
43
+ return this.put(`/company/${company_id}/user/${user_id}`, JSON.stringify(data), undefined, { "Content-Type": "application/json" });
44
+ },
45
+ // Optimistically update the user data and company data in the cache
46
+ onMutate: async (data) => {
47
+ await queryClient.cancelQueries({ queryKey: ['user'] });
48
+ await queryClient.cancelQueries({ queryKey: ['company', data.company_id] });
49
+ const previousUser = queryClient.getQueryData(['user']);
50
+ const previousCompany = queryClient.getQueryData(['company', data.company_id]);
51
+ if (previousUser) {
52
+ let oldUserCompany = previousUser.companies?.find(c => c.company === data.company_id);
53
+ if (oldUserCompany) {
54
+ oldUserCompany = { ...oldUserCompany, ...data.data };
55
+ const newCompanies = previousUser.companies?.map(c => c.company === data.company_id ? oldUserCompany : c) ?? [];
56
+ queryClient.setQueryData(['user'], { ...previousUser, companies: newCompanies });
57
+ }
58
+ }
59
+ if (previousCompany) {
60
+ let oldCompanyUser = previousCompany.users?.find((u) => u.user.id === data.user_id);
61
+ if (oldCompanyUser) {
62
+ oldCompanyUser = { ...oldCompanyUser, ...data.data };
63
+ const newUsers = previousCompany.users?.map((u) => u.user.id === data.user_id ? oldCompanyUser : u) ?? [];
64
+ queryClient.setQueryData(['company', data.company_id], { ...previousCompany, users: newUsers });
65
+ }
66
+ }
67
+ return { previousUser, previousCompany };
68
+ },
69
+ onError: (err, _, context) => {
70
+ if (context?.previousUser) {
71
+ queryClient.setQueryData(['user'], context.previousUser);
72
+ }
73
+ if (context?.previousCompany) {
74
+ queryClient.setQueryData(['company'], context.previousCompany);
75
+ }
76
+ },
77
+ onSettled: (data, error, variables) => {
78
+ queryClient.invalidateQueries({ queryKey: ['user'] });
79
+ queryClient.invalidateQueries({ queryKey: ['company', variables.company_id] });
80
+ },
81
+ });
82
+ };
83
+ AvroQueryClient.prototype.useDeleteSelf = function () {
84
+ const queryClient = useQueryClient();
85
+ return useMutation({
86
+ mutationFn: async () => {
87
+ return this.delete(`/user`);
88
+ },
89
+ onMutate: async () => {
90
+ await queryClient.cancelQueries({ queryKey: ['user'] });
91
+ const previousUser = queryClient.getQueryData(['user']);
92
+ queryClient.removeQueries({ queryKey: ['user'] });
93
+ return { previousUser };
94
+ },
95
+ onError: (err, _, context) => {
96
+ if (context?.previousUser) {
97
+ queryClient.setQueryData(['user'], context.previousUser);
98
+ }
99
+ },
100
+ onSettled: () => {
101
+ queryClient.invalidateQueries({ queryKey: ['user'] });
102
+ },
103
+ });
104
+ };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,25 @@
1
1
  export { AvroQueryClientConfig, AvroQueryClient } from './client/QueryClient';
2
2
  export { AuthManager } from './auth/AuthManager';
3
3
  export { MemoryStorage, LocalStorage } from './auth/storage';
4
+ import './client/core/xhr';
5
+ import './client/core/fetch';
6
+ import './client/core/utils';
7
+ import './client/hooks/root';
8
+ import './client/hooks/jobs';
9
+ import './client/hooks/routes';
10
+ import './client/hooks/events';
11
+ import './client/hooks/months';
12
+ import './client/hooks/bills';
13
+ import './client/hooks/companies';
14
+ import './client/hooks/users';
15
+ import './client/hooks/sessions';
16
+ import './client/hooks/chats';
17
+ import './client/hooks/messages';
18
+ import './client/hooks/plans';
19
+ import './client/hooks/analytics';
20
+ import './client/hooks/avro';
21
+ import './client/hooks/teams';
4
22
  export * from './types/api';
23
+ export * from './types/auth';
5
24
  export * from './types/error';
6
25
  export * from './types/client';
package/dist/index.js CHANGED
@@ -1,6 +1,25 @@
1
1
  export { AvroQueryClient } from './client/QueryClient';
2
2
  export { AuthManager } from './auth/AuthManager';
3
3
  export { MemoryStorage, LocalStorage } from './auth/storage';
4
+ import './client/core/xhr';
5
+ import './client/core/fetch';
6
+ import './client/core/utils';
7
+ import './client/hooks/root';
8
+ import './client/hooks/jobs';
9
+ import './client/hooks/routes';
10
+ import './client/hooks/events';
11
+ import './client/hooks/months';
12
+ import './client/hooks/bills';
13
+ import './client/hooks/companies';
14
+ import './client/hooks/users';
15
+ import './client/hooks/sessions';
16
+ import './client/hooks/chats';
17
+ import './client/hooks/messages';
18
+ import './client/hooks/plans';
19
+ import './client/hooks/analytics';
20
+ import './client/hooks/avro';
21
+ import './client/hooks/teams';
4
22
  export * from './types/api';
23
+ export * from './types/auth';
5
24
  export * from './types/error';
6
25
  export * from './types/client';
@@ -1,3 +1,12 @@
1
+ export interface ApiInfo {
2
+ app_semver: string;
3
+ db_healthy: boolean;
4
+ logged_in_as: string;
5
+ ors_healthy: string;
6
+ pelias_healthy: boolean;
7
+ version: string;
8
+ vroom_healthy: boolean;
9
+ }
1
10
  export interface PaymentMethod {
2
11
  allow_redisplay: string;
3
12
  autopay: boolean;
@@ -68,12 +77,16 @@ export interface MemberState {
68
77
  }
69
78
  export interface LineItem {
70
79
  id: string;
80
+ line_item_type: "CUSTOM" | "ADDITIONAL_CHARGE" | "EVENT" | "SERVICE_MONTH";
71
81
  name: string;
72
82
  description: string;
73
83
  cost: number | null;
74
84
  amount: number | null;
75
85
  time_created: number;
76
86
  }
87
+ export interface CustomLineItem extends LineItem {
88
+ line_item_type: "CUSTOM";
89
+ }
77
90
  export interface Reaction {
78
91
  id: string;
79
92
  message_id: string;
@@ -163,6 +176,8 @@ export interface Plan {
163
176
  trial_period_days: number;
164
177
  time_created: number;
165
178
  time_updated: number;
179
+ available_to_new_companies?: boolean;
180
+ available_to?: string[];
166
181
  }
167
182
  export interface BillPayment {
168
183
  id: string;
@@ -193,8 +208,8 @@ export interface User {
193
208
  companies: UserCompanyAssociation[] | null;
194
209
  email: string | null;
195
210
  phone_number: string | null;
196
- time_created: string | null;
197
- time_updated: string | null;
211
+ time_created: number;
212
+ time_updated: number | null;
198
213
  can_send_emails: boolean | null;
199
214
  payment_methods: PaymentMethod[];
200
215
  autopay_payment_types: string[];
@@ -209,20 +224,20 @@ export interface Break {
209
224
  company_billable: boolean;
210
225
  client_billable: boolean;
211
226
  }
212
- export interface ServiceMonth {
213
- id: string;
227
+ export interface ServiceMonth extends LineItem {
228
+ line_item_type: "SERVICE_MONTH";
214
229
  job_name: string;
215
230
  job_id: string | null;
231
+ job_address: string;
232
+ job_labels: string[];
216
233
  bill_id: string | null;
217
- cost: number;
218
234
  billed: boolean;
219
235
  paid: boolean;
220
- amount: number;
221
- time_created: number;
236
+ tasks: string[];
222
237
  time_updated: number | null;
223
238
  }
224
239
  export interface Session {
225
- session_id: string;
240
+ id: string;
226
241
  user_id: string;
227
242
  company_id: string;
228
243
  time_started: number;
@@ -230,7 +245,7 @@ export interface Session {
230
245
  break_id: string;
231
246
  is_paused: boolean;
232
247
  team_id: string;
233
- current_route_id: string;
248
+ route_id: string;
234
249
  breaks: Break[];
235
250
  }
236
251
  export interface Group {
@@ -244,6 +259,18 @@ export interface Group {
244
259
  time_created: number;
245
260
  time_updated: number;
246
261
  }
262
+ export declare const NotificationLevel: {
263
+ readonly IN_APP: 0;
264
+ readonly EMAIL: 1;
265
+ readonly SMS: 2;
266
+ readonly PUSH: 3;
267
+ };
268
+ export type NotificationLevel = typeof NotificationLevel[keyof typeof NotificationLevel];
269
+ export declare const LoginResponse: {
270
+ readonly SUCCESS: "SUCCESS";
271
+ readonly NEEDS_TOTP: "NEEDS_TOTP";
272
+ };
273
+ export type LoginResponse = typeof LoginResponse[keyof typeof LoginResponse];
247
274
  export interface UserCompanyAssociation {
248
275
  id: string;
249
276
  user: User;
@@ -252,9 +279,9 @@ export interface UserCompanyAssociation {
252
279
  effective_permissions: string[];
253
280
  time_created: number | null;
254
281
  time_updated: number | null;
255
- notification_setting: number[];
282
+ notification_setting: NotificationLevel[];
256
283
  share_email_company_wide: boolean;
257
- notifications: number[];
284
+ notifications: Notification[];
258
285
  groups: string[];
259
286
  }
260
287
  export interface Email {
@@ -294,6 +321,7 @@ export interface Bill {
294
321
  customer_email: string | null;
295
322
  manual_emails: string[][];
296
323
  users: BillUser[];
324
+ paid: boolean;
297
325
  paid_at: number;
298
326
  time_created: number;
299
327
  time_updated: number;
@@ -301,7 +329,7 @@ export interface Bill {
301
329
  intent_created_at: number;
302
330
  intent_last_created_at: number;
303
331
  payment: BillPayment | null;
304
- line_items: LineItem[];
332
+ line_items: CustomLineItem[];
305
333
  months: string[];
306
334
  due_date: number;
307
335
  }
@@ -333,8 +361,8 @@ export interface Company {
333
361
  teams: Team[];
334
362
  emails: Email[];
335
363
  skills: Skill[];
336
- time_created: string;
337
- time_updated: string | null;
364
+ time_created: number;
365
+ time_updated: number | null;
338
366
  users: UserCompanyAssociation[];
339
367
  use_client_side_customer_start_billing: boolean;
340
368
  use_client_side_customer_stop_billing: boolean;
@@ -416,6 +444,7 @@ export interface Job {
416
444
  routes: RouteJob[];
417
445
  subscribers: Subscription[];
418
446
  manual_emails: string[][];
447
+ overdue_time: number;
419
448
  last_completed_event: _Event | null;
420
449
  last_event: _Event | null;
421
450
  labels: string[];
@@ -438,6 +467,7 @@ export interface Task {
438
467
  created_by: UserCompanyAssociation | null;
439
468
  overdueness: number | null;
440
469
  overdue_time: number;
470
+ last_completed_event: _Event | null;
441
471
  last_event: _Event | null;
442
472
  delay: number;
443
473
  skills: string[];
@@ -471,22 +501,17 @@ export interface taskEndInfo {
471
501
  internal_notes: string;
472
502
  external_notes: string;
473
503
  }
474
- export interface AdditionalCharge {
475
- id: string;
476
- time_created: number;
504
+ export interface AdditionalCharge extends LineItem {
505
+ line_item_type: "ADDITIONAL_CHARGE";
477
506
  time_updated: number | null;
478
- name: string;
479
- amount: number;
480
507
  }
481
- export interface _Event {
508
+ export interface _Event extends LineItem {
482
509
  breaks: string[];
483
- id: string;
484
- name: string;
510
+ line_item_type: "EVENT";
485
511
  internal_notes: string;
486
512
  external_notes: string;
487
513
  proofs: string[];
488
514
  tasks: string[];
489
- time_created: number;
490
515
  time_ended: number;
491
516
  time_started: number;
492
517
  time_updated: number | null;
@@ -498,9 +523,75 @@ export interface _Event {
498
523
  additional_charges: AdditionalCharge[];
499
524
  user_id: string;
500
525
  team_id: string;
501
- cost: number;
502
526
  billed: boolean;
503
527
  paid: boolean;
504
528
  autostart: boolean;
505
529
  job_labels: string[];
506
530
  }
531
+ export interface FinancialInsightData {
532
+ start: number;
533
+ end: number;
534
+ unbilled: {
535
+ events: {
536
+ count: number;
537
+ amount: number;
538
+ };
539
+ service_months: {
540
+ count: number;
541
+ amount: number;
542
+ };
543
+ total: number;
544
+ };
545
+ billed_unbilled: {
546
+ events: {
547
+ count: number;
548
+ amount: number;
549
+ };
550
+ service_months: {
551
+ count: number;
552
+ amount: number;
553
+ };
554
+ total: number;
555
+ };
556
+ paid_unbilled: {
557
+ events: {
558
+ count: number;
559
+ amount: number;
560
+ };
561
+ service_months: {
562
+ count: number;
563
+ amount: number;
564
+ };
565
+ total: number;
566
+ };
567
+ prepaid: {
568
+ events: {
569
+ count: number;
570
+ amount: number;
571
+ };
572
+ service_months: {
573
+ count: number;
574
+ amount: number;
575
+ };
576
+ total: number;
577
+ };
578
+ accounts_receivable: {
579
+ overdue: number;
580
+ not_overdue: number;
581
+ };
582
+ cash: number;
583
+ }
584
+ export interface EventInsightData {
585
+ start: number;
586
+ end: number;
587
+ events_per_job: {
588
+ id: string;
589
+ name: string;
590
+ event_count: number;
591
+ }[];
592
+ events_per_team: {
593
+ team_id: string;
594
+ event_count: number;
595
+ }[];
596
+ total_events: number;
597
+ }
package/dist/types/api.js CHANGED
@@ -1 +1,10 @@
1
- export {};
1
+ export const NotificationLevel = {
2
+ IN_APP: 0,
3
+ EMAIL: 1,
4
+ SMS: 2,
5
+ PUSH: 3
6
+ };
7
+ export const LoginResponse = {
8
+ SUCCESS: "SUCCESS",
9
+ NEEDS_TOTP: "NEEDS_TOTP",
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.7",
3
+ "version": "0.0.2-beta.70",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -33,6 +33,7 @@
33
33
  "license": "CC-BY-SA-4.0",
34
34
  "devDependencies": {
35
35
  "@types/jest": "^29.0.0",
36
+ "@types/react": "^19.2.2",
36
37
  "@typescript-eslint/eslint-plugin": "^8.38.0",
37
38
  "@typescript-eslint/parser": "^8.38.0",
38
39
  "eslint": "^8.57.1",
@@ -50,5 +51,9 @@
50
51
  ],
51
52
  "publishConfig": {
52
53
  "access": "public"
54
+ },
55
+ "dependencies": {
56
+ "@tanstack/react-query": "^5.90.2",
57
+ "socket.io-client": "^4.8.1"
53
58
  }
54
59
  }