@go-avro/avro-js 0.0.61 → 0.0.63

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, RevenueInsightData, Job, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill, Group, Label, RouteScheduleConfig, CatalogItem, Payout, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api';
4
+ import { _Event, ActiveSessionSummary, ApiInfo, Avro, Bill, BillInsightData, Break, Chat, Company, FinancialInsightData, RevenueInsightData, Job, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill, Group, Label, RouteScheduleConfig, CatalogItem, Payout, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api';
5
5
  import { AuthState, Tokens } from '../types/auth';
6
6
  import { CancelToken, ClientId, RetryStrategy } from '../types/client';
7
7
  import { StandardError } from '../types/error';
@@ -171,6 +171,13 @@ declare module '../client/QueryClient' {
171
171
  periods: number[][];
172
172
  cumulative: boolean;
173
173
  }): UseQueryResult<FinancialInsightData[], StandardError>;
174
+ useBillAnalytics({ periods, cumulative, }: {
175
+ periods: number[][];
176
+ cumulative: boolean;
177
+ }): UseQueryResult<BillInsightData[], StandardError>;
178
+ useActiveSessions(options?: {
179
+ refetchInterval?: number;
180
+ }): UseQueryResult<ActiveSessionSummary[], StandardError>;
174
181
  useEventAnalytics({ periods, }: {
175
182
  periods: number[][];
176
183
  }): UseQueryResult<EventInsightData[], StandardError>;
@@ -188,6 +195,14 @@ declare module '../client/QueryClient' {
188
195
  useGetChat(chatId: string): UseQueryResult<Chat, StandardError>;
189
196
  useGetCatalogItem(catalogItemId: string): UseQueryResult<CatalogItem, StandardError>;
190
197
  useGetUserSessions(): UseQueryResult<Session[], StandardError>;
198
+ useGetCompanySessionsByIds(sessionIds: string[], params?: {
199
+ companyId?: string;
200
+ enabled?: boolean;
201
+ }): UseQueryResult<Session[], StandardError>;
202
+ useGetActiveCompanySessions(params?: {
203
+ companyId?: string;
204
+ enabled?: boolean;
205
+ }): UseQueryResult<Session[], StandardError>;
191
206
  useGetCompanyTimecards(params?: {
192
207
  companyId?: string;
193
208
  periodStart?: number;
@@ -214,8 +214,18 @@ const SOCKET_EVENT_CONFIG = {
214
214
  delete_bill: { entityKey: 'bills', action: 'delete', fetchPath: null },
215
215
  update_bills: { invalidateKeys: [['bills']] },
216
216
  // ── Sessions ──
217
- create_session: { entityKey: 'sessions', action: 'create', fetchPath: null },
218
- update_session: { entityKey: 'sessions', action: 'update', fetchPath: null },
217
+ create_session: {
218
+ entityKey: 'sessions',
219
+ action: 'create',
220
+ fetchPath: null,
221
+ alsoInvalidate: [['analytics', 'sessions']],
222
+ },
223
+ update_session: {
224
+ entityKey: 'sessions',
225
+ action: 'update',
226
+ fetchPath: null,
227
+ alsoInvalidate: [['analytics', 'sessions']],
228
+ },
219
229
  // ── Catalog Items ──
220
230
  create_catalog_item: {
221
231
  entityKey: 'catalog_items',
@@ -21,6 +21,33 @@ AvroQueryClient.prototype.useFinanceAnalytics = function ({ periods, cumulative,
21
21
  }),
22
22
  });
23
23
  };
24
+ AvroQueryClient.prototype.useBillAnalytics = function ({ periods, cumulative, }) {
25
+ return useQuery({
26
+ queryKey: ['analytics', 'bills', this.companyId, periods, cumulative],
27
+ queryFn: () => this.post({
28
+ path: `/company/${this.companyId}/analytics/bills`,
29
+ data: JSON.stringify({ periods, cumulative }),
30
+ headers: {
31
+ 'Content-Type': 'application/json',
32
+ },
33
+ }),
34
+ enabled: Boolean(this.companyId),
35
+ });
36
+ };
37
+ AvroQueryClient.prototype.useActiveSessions = function ({ refetchInterval, } = {}) {
38
+ return useQuery({
39
+ queryKey: ['analytics', 'sessions', this.companyId],
40
+ queryFn: () => this.post({
41
+ path: `/company/${this.companyId}/analytics/sessions`,
42
+ data: JSON.stringify({}),
43
+ headers: {
44
+ 'Content-Type': 'application/json',
45
+ },
46
+ }),
47
+ enabled: Boolean(this.companyId),
48
+ refetchInterval,
49
+ });
50
+ };
24
51
  AvroQueryClient.prototype.useEventAnalytics = function ({ periods }) {
25
52
  return useQuery({
26
53
  queryKey: ['analytics', 'events', this.companyId, periods],
@@ -7,6 +7,56 @@ AvroQueryClient.prototype.useGetUserSessions = function () {
7
7
  enabled: Boolean(this.companyId),
8
8
  });
9
9
  };
10
+ AvroQueryClient.prototype.useGetCompanySessionsByIds = function (sessionIds, params = {}) {
11
+ const companyId = params.companyId ?? this.companyId;
12
+ const sortedIds = [...sessionIds].sort();
13
+ return useQuery({
14
+ queryKey: ['sessions', companyId, 'by-ids', sortedIds],
15
+ queryFn: async () => {
16
+ const amount = Math.max(sortedIds.length, 50);
17
+ const sessions = await this.post({
18
+ path: `/company/${companyId}/sessions?amount=${amount}`,
19
+ data: JSON.stringify({ unknown_ids: sortedIds }),
20
+ headers: { 'Content-Type': 'application/json' },
21
+ });
22
+ return Array.isArray(sessions) ? sessions : [];
23
+ },
24
+ enabled: Boolean(companyId) && sortedIds.length > 0 && (params.enabled ?? true),
25
+ });
26
+ };
27
+ AvroQueryClient.prototype.useGetActiveCompanySessions = function (params = {}) {
28
+ const companyId = params.companyId ?? this.companyId;
29
+ return useQuery({
30
+ queryKey: ['sessions', companyId, 'active'],
31
+ queryFn: async () => {
32
+ const pageSize = 100;
33
+ const maxPages = 10;
34
+ const knownIds = [];
35
+ const openSessions = [];
36
+ for (let page = 0; page < maxPages; page += 1) {
37
+ const pageSessions = await this.post({
38
+ path: `/company/${companyId}/sessions?amount=${pageSize}`,
39
+ data: JSON.stringify({ known_ids: knownIds }),
40
+ headers: { 'Content-Type': 'application/json' },
41
+ });
42
+ if (!Array.isArray(pageSessions) || pageSessions.length === 0)
43
+ break;
44
+ for (const session of pageSessions) {
45
+ const isOpen = session.time_ended == null ||
46
+ session.time_ended <= 0 ||
47
+ session.time_ended <= session.time_started;
48
+ if (isOpen)
49
+ openSessions.push(session);
50
+ }
51
+ knownIds.push(...pageSessions.map((s) => s.id).filter(Boolean));
52
+ if (pageSessions.length < pageSize)
53
+ break;
54
+ }
55
+ return openSessions;
56
+ },
57
+ enabled: Boolean(companyId) && (params.enabled ?? true),
58
+ });
59
+ };
10
60
  AvroQueryClient.prototype.useCreateUserSession = function () {
11
61
  const queryClient = this.getQueryClient();
12
62
  return useMutation({
@@ -208,6 +208,18 @@ export interface FinancialInsightData {
208
208
  total: number;
209
209
  };
210
210
  }
211
+ export interface BillInsightData {
212
+ start: number;
213
+ end: number;
214
+ overdue_count: number;
215
+ not_overdue_count: number;
216
+ }
217
+ export interface ActiveSessionSummary {
218
+ id: string;
219
+ user_id: string;
220
+ team_id: string | null;
221
+ time_started: number;
222
+ }
211
223
  export interface EventInsightData {
212
224
  start: number;
213
225
  end: number;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.0.61";
1
+ export declare const AVRO_JS_VERSION = "0.0.63";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // AUTO-GENERATED by scripts/gen-version.js — do not edit by hand.
2
2
  // Regenerated from package.json by the `prebuild` npm hook.
3
- export const AVRO_JS_VERSION = '0.0.61';
3
+ export const AVRO_JS_VERSION = '0.0.63';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.61",
3
+ "version": "0.0.63",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",