@go-avro/avro-js 0.0.2-beta.140 → 0.0.2-beta.141

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, 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 } 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 } 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';
@@ -86,6 +86,13 @@ declare module '../client/QueryClient' {
86
86
  query?: string;
87
87
  paid?: boolean;
88
88
  }): UseInfiniteQueryResult<InfiniteData<Bill[], unknown>, StandardError>;
89
+ useGetLabels(body: {
90
+ amt?: number;
91
+ known_ids?: string[];
92
+ unknown_ids?: string[];
93
+ query?: string;
94
+ offset?: number;
95
+ }, total: number, onProgress?: (fraction: number) => void): UseQueryResult<Label[], StandardError>;
89
96
  useGetGroups(body: {
90
97
  amt?: number;
91
98
  known_ids?: string[];
@@ -120,6 +127,11 @@ declare module '../client/QueryClient' {
120
127
  }, StandardError, {
121
128
  groupData: Partial<Group>;
122
129
  }>>;
130
+ useCreateLabel(): ReturnType<typeof useMutation<{
131
+ id: string;
132
+ }, StandardError, {
133
+ labelData: Partial<Label>;
134
+ }>>;
123
135
  useCreateSkill(): ReturnType<typeof useMutation<{
124
136
  id: string;
125
137
  }, StandardError, {
@@ -204,6 +216,12 @@ declare module '../client/QueryClient' {
204
216
  groupId: string;
205
217
  groupData: Partial<Group>;
206
218
  }>>;
219
+ useUpdateLabel(): ReturnType<typeof useMutation<{
220
+ msg: string;
221
+ }, StandardError, {
222
+ labelId: string;
223
+ labelData: Partial<Label>;
224
+ }>>;
207
225
  useUpdateJob(): ReturnType<typeof useMutation<{
208
226
  msg: string;
209
227
  }, StandardError, {
@@ -281,6 +299,11 @@ declare module '../client/QueryClient' {
281
299
  }, StandardError, {
282
300
  groupId: string;
283
301
  }>>;
302
+ useDeleteLabel(): ReturnType<typeof useMutation<{
303
+ msg: string;
304
+ }, StandardError, {
305
+ labelId: string;
306
+ }>>;
284
307
  useDeleteEvent(): ReturnType<typeof useMutation<{
285
308
  msg: string;
286
309
  }, StandardError, {
@@ -437,6 +460,13 @@ export declare class AvroQueryClient {
437
460
  query?: string;
438
461
  offset?: number;
439
462
  }, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
463
+ fetchLabels(body?: {
464
+ amt?: number;
465
+ known_ids?: string[];
466
+ unknown_ids?: string[];
467
+ query?: string;
468
+ offset?: number;
469
+ }, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
440
470
  fetchGroups(body?: {
441
471
  amt?: number;
442
472
  known_ids?: string[];
@@ -408,6 +408,25 @@ export class AvroQueryClient {
408
408
  throw new StandardError(500, 'Failed to fetch teams');
409
409
  });
410
410
  }
411
+ fetchLabels(body = {}, cancelToken, headers = {}) {
412
+ if (!this.companyId || this.companyId.trim() === '') {
413
+ throw new StandardError(400, 'Company ID is required');
414
+ }
415
+ return this._fetch('POST', `/company/${this.companyId}/labels`, JSON.stringify(body), cancelToken, {
416
+ ...headers,
417
+ 'Content-Type': 'application/json',
418
+ })
419
+ .then(response => {
420
+ if (!response || !Array.isArray(response)) {
421
+ throw new StandardError(400, 'Invalid labels response');
422
+ }
423
+ return response;
424
+ })
425
+ .catch(err => {
426
+ console.error('Failed to fetch labels:', err);
427
+ throw new StandardError(500, 'Failed to fetch labels');
428
+ });
429
+ }
411
430
  fetchGroups(body = {}, cancelToken, headers = {}) {
412
431
  if (!this.companyId || this.companyId.trim() === '') {
413
432
  throw new StandardError(400, 'Company ID is required');
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,130 @@
1
+ import { useMutation, useQuery } from "@tanstack/react-query";
2
+ import { AvroQueryClient } from "../../client/QueryClient";
3
+ AvroQueryClient.prototype.useGetLabels = function (body, total, onProgress) {
4
+ return useQuery({
5
+ queryKey: ['labels', this.companyId, body.amt ?? 50, body.query ?? "", total ?? "all"],
6
+ queryFn: async () => {
7
+ if (typeof total !== "number") {
8
+ return this.fetchLabels({ ...body, offset: 0 });
9
+ }
10
+ onProgress?.(0);
11
+ const pageCount = body.amt ? Math.ceil(total / body.amt) + 1 : 1;
12
+ let completed = 0;
13
+ const promises = Array.from({ length: pageCount }, (_, i) => this.fetchLabels({
14
+ ...body,
15
+ offset: i * (body.amt ?? 1),
16
+ }));
17
+ const trackedPromises = promises.map((promise) => promise.then((result) => {
18
+ completed++;
19
+ const fraction = completed / pageCount;
20
+ onProgress?.(fraction);
21
+ return result;
22
+ }));
23
+ const pages = await Promise.all(trackedPromises);
24
+ const labels = pages.flat();
25
+ return labels;
26
+ },
27
+ });
28
+ };
29
+ AvroQueryClient.prototype.useCreateLabel = function () {
30
+ const queryClient = this.getQueryClient();
31
+ return useMutation({
32
+ mutationFn: async ({ labelData }) => {
33
+ return this.post(`/company/${this.companyId}/label`, JSON.stringify(labelData), undefined, { "Content-Type": "application/json" });
34
+ },
35
+ onSettled: () => {
36
+ queryClient.invalidateQueries({ queryKey: ['company'] });
37
+ queryClient.invalidateQueries({ queryKey: ['labels'] });
38
+ },
39
+ });
40
+ };
41
+ AvroQueryClient.prototype.useUpdateLabel = function () {
42
+ const queryClient = this.getQueryClient();
43
+ return useMutation({
44
+ mutationFn: async ({ labelId, labelData }) => {
45
+ return this.put(`/label/${labelId}`, JSON.stringify(labelData), undefined, { "Content-Type": "application/json" });
46
+ },
47
+ onMutate: async ({ labelId, labelData }) => {
48
+ await queryClient.cancelQueries({ queryKey: ['labels'] });
49
+ await queryClient.cancelQueries({ queryKey: ['label', labelId] });
50
+ const previousLabels = queryClient.getQueryData(['labels']);
51
+ const previousLabel = queryClient.getQueryData(['label', labelId]);
52
+ queryClient.setQueryData(['label', labelId], (oldData) => {
53
+ if (!oldData)
54
+ return oldData;
55
+ return { ...oldData, ...labelData };
56
+ });
57
+ queryClient.setQueriesData({ queryKey: ['labels'] }, (oldData) => {
58
+ if (!oldData)
59
+ return oldData;
60
+ if (oldData.pages) {
61
+ const updatedPages = oldData.pages.map((page) => page.map((label) => label.id === labelId ? { ...label, ...labelData } : label));
62
+ return { ...oldData, pages: updatedPages };
63
+ }
64
+ if (Array.isArray(oldData)) {
65
+ return oldData.map((label) => label.id === labelId ? { ...label, ...labelData } : label);
66
+ }
67
+ return oldData;
68
+ });
69
+ return { previousLabels, previousLabel };
70
+ },
71
+ onError: (_err, variables, context) => {
72
+ const { labelId } = variables;
73
+ if (context?.previousLabels) {
74
+ queryClient.setQueryData(['labels'], context.previousLabels);
75
+ }
76
+ if (context?.previousLabel) {
77
+ queryClient.setQueryData(['label', labelId], context.previousLabel);
78
+ }
79
+ },
80
+ onSettled: (_data, _error, variables) => {
81
+ const { labelId } = variables;
82
+ queryClient.invalidateQueries({ queryKey: ['labels'] });
83
+ queryClient.invalidateQueries({ queryKey: ['label', labelId] });
84
+ queryClient.invalidateQueries({ queryKey: ['company'] });
85
+ },
86
+ });
87
+ };
88
+ AvroQueryClient.prototype.useDeleteLabel = function () {
89
+ const queryClient = this.getQueryClient();
90
+ return useMutation({
91
+ mutationFn: async ({ labelId, }) => {
92
+ return this.delete(`/label/${labelId}`);
93
+ },
94
+ onMutate: async ({ labelId }) => {
95
+ await queryClient.cancelQueries({ queryKey: ['labels'] });
96
+ await queryClient.cancelQueries({ queryKey: ['label', labelId] });
97
+ const previousLabels = queryClient.getQueryData(['labels']);
98
+ const previousLabel = queryClient.getQueryData(['label', labelId]);
99
+ queryClient.setQueryData(['label', labelId], undefined);
100
+ queryClient.setQueriesData({ queryKey: ['labels'] }, (oldData) => {
101
+ if (!oldData)
102
+ return oldData;
103
+ if (oldData.pages) {
104
+ const updatedPages = oldData.pages.map((page) => page.filter((label) => label.id !== labelId));
105
+ return { ...oldData, pages: updatedPages };
106
+ }
107
+ if (Array.isArray(oldData)) {
108
+ return oldData.filter((label) => label.id !== labelId);
109
+ }
110
+ return oldData;
111
+ });
112
+ return { previousLabels, previousLabel };
113
+ },
114
+ onError: (_err, variables, context) => {
115
+ const { labelId } = variables;
116
+ if (context?.previousLabels) {
117
+ queryClient.setQueryData(['labels'], context.previousLabels);
118
+ }
119
+ if (context?.previousLabel) {
120
+ queryClient.setQueryData(['label', labelId], context.previousLabel);
121
+ }
122
+ },
123
+ onSettled: (_data, _error, variables) => {
124
+ const { labelId } = variables;
125
+ queryClient.invalidateQueries({ queryKey: ['labels'] });
126
+ queryClient.invalidateQueries({ queryKey: ['label', labelId] });
127
+ queryClient.invalidateQueries({ queryKey: ['company'] });
128
+ },
129
+ });
130
+ };
package/dist/index.d.ts CHANGED
@@ -20,6 +20,7 @@ import './client/hooks/plans';
20
20
  import './client/hooks/analytics';
21
21
  import './client/hooks/avro';
22
22
  import './client/hooks/teams';
23
+ import './client/hooks/labels';
23
24
  import './client/hooks/groups';
24
25
  import './client/hooks/skills';
25
26
  export * from './types/api';
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ import './client/hooks/plans';
20
20
  import './client/hooks/analytics';
21
21
  import './client/hooks/avro';
22
22
  import './client/hooks/teams';
23
+ import './client/hooks/labels';
23
24
  import './client/hooks/groups';
24
25
  import './client/hooks/skills';
25
26
  export * from './types/api';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.140",
3
+ "version": "0.0.2-beta.141",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",