@go-avro/avro-js 0.0.95 → 0.0.97

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, ActiveSessionSummary, AddressFeatureCollection, ApiInfo, Avro, StorageAnalytics, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Break, Chat, CheckIn, Company, DelayEventCreatePayload, EventUpdatePayload, LineItemType, FinancialInsightData, RevenueInsightData, Job, JobUpdate, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill, Group, Label, RouteScheduleConfig, RouteWritePayload, CatalogItem, Payout, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api';
4
+ import { _Event, ActiveSessionSummary, AddressFeatureCollection, ApiInfo, Avro, StorageAnalytics, ClientErrorReport, ErrorLogEntry, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Break, Chat, CheckIn, Company, DelayEventCreatePayload, EventUpdatePayload, LineItemType, FinancialInsightData, RevenueInsightData, Job, JobUpdate, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill, Group, Label, RouteScheduleConfig, RouteWritePayload, 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';
@@ -236,6 +236,11 @@ declare module '../client/QueryClient' {
236
236
  useGetTimecard(timecardId?: string, enabled?: boolean): UseQueryResult<Timecard, StandardError>;
237
237
  useGetAvro(): UseQueryResult<Avro, StandardError>;
238
238
  useGetStorageAnalytics(): UseQueryResult<StorageAnalytics, StandardError>;
239
+ useGetErrorLog(limit?: number): UseQueryResult<ErrorLogEntry[], StandardError>;
240
+ useClearErrorLog(): ReturnType<typeof useMutation<{
241
+ msg: string;
242
+ cleared: number;
243
+ }, StandardError, void>>;
239
244
  useSearchUsers(searchUsername: string): UseQueryResult<User[], StandardError>;
240
245
  useReviewProposal(proposal_id: string): ReturnType<typeof useMutation<{
241
246
  msg: string;
@@ -683,6 +688,11 @@ export declare class AvroQueryClient {
683
688
  headers?: Record<string, string>;
684
689
  progressUpdateCallback?: (loaded: number, total: number) => void;
685
690
  }): Promise<T>;
691
+ /**
692
+ * Report a client-side crash or error to the admin error log.
693
+ * Fire-and-forget: never throws, so it is safe inside error handlers.
694
+ */
695
+ reportClientError(report: ClientErrorReport): Promise<void>;
686
696
  post<T>({ path, data, cancelToken, headers, progressUpdateCallback, maxRetries, }: {
687
697
  path: string;
688
698
  data?: any;
@@ -571,6 +571,23 @@ export class AvroQueryClient {
571
571
  get({ path, cancelToken, headers, progressUpdateCallback, }) {
572
572
  return this._xhr('GET', path, null, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
573
573
  }
574
+ /**
575
+ * Report a client-side crash or error to the admin error log.
576
+ * Fire-and-forget: never throws, so it is safe inside error handlers.
577
+ */
578
+ async reportClientError(report) {
579
+ try {
580
+ await this.post({
581
+ path: '/client/error',
582
+ data: JSON.stringify(report),
583
+ headers: { 'Content-Type': 'application/json' },
584
+ maxRetries: 0,
585
+ });
586
+ }
587
+ catch {
588
+ // Reporting must never become a second failure.
589
+ }
590
+ }
574
591
  post({ path, data, cancelToken, headers, progressUpdateCallback, maxRetries, }) {
575
592
  return this._xhr('POST', path, data, cancelToken, headers, false, maxRetries ?? this.config.maxRetries, progressUpdateCallback);
576
593
  }
@@ -1,4 +1,4 @@
1
- import { useQuery } from '@tanstack/react-query';
1
+ import { useMutation, useQuery } from '@tanstack/react-query';
2
2
  import { AvroQueryClient } from '../../client/QueryClient';
3
3
  AvroQueryClient.prototype.useGetAvro = function () {
4
4
  return useQuery({
@@ -13,3 +13,23 @@ AvroQueryClient.prototype.useGetStorageAnalytics = function () {
13
13
  queryFn: () => this.get({ path: '/avro/storage' }),
14
14
  });
15
15
  };
16
+ AvroQueryClient.prototype.useGetErrorLog = function (limit = 200) {
17
+ return useQuery({
18
+ queryKey: ['avro', 'errors', limit],
19
+ queryFn: async () => {
20
+ const res = await this.get({
21
+ path: `/avro/errors?limit=${limit}`,
22
+ });
23
+ return res.errors;
24
+ },
25
+ });
26
+ };
27
+ AvroQueryClient.prototype.useClearErrorLog = function () {
28
+ const queryClient = this.getQueryClient();
29
+ return useMutation({
30
+ mutationFn: () => this.delete({ path: '/avro/errors' }),
31
+ onSuccess: () => {
32
+ queryClient.invalidateQueries({ queryKey: ['avro', 'errors'] });
33
+ },
34
+ });
35
+ };
@@ -26,3 +26,42 @@ export interface StorageAnalytics {
26
26
  /** Ordered by bytes, largest first. */
27
27
  by_company: StorageByCompany[];
28
28
  }
29
+ /** A crash or error reported by a client (app or web). */
30
+ export interface ClientErrorReport {
31
+ message: string;
32
+ stack?: string;
33
+ fatal?: boolean;
34
+ platform?: string;
35
+ app_version?: string;
36
+ update_id?: string;
37
+ route?: string;
38
+ extra?: Record<string, unknown>;
39
+ }
40
+ /** One entry in the admin error log (backend errors and client crashes). */
41
+ export interface ErrorLogEntry {
42
+ id: string;
43
+ time: number;
44
+ source: 'backend' | 'app' | 'web' | string;
45
+ status?: number;
46
+ message?: string | null;
47
+ traceback?: string;
48
+ stack?: string;
49
+ fatal?: boolean;
50
+ platform?: string;
51
+ app_version?: string;
52
+ update_id?: string;
53
+ route?: string;
54
+ method?: string;
55
+ path?: string;
56
+ endpoint?: string | null;
57
+ client_id?: string | null;
58
+ client_version?: string | null;
59
+ js_version?: string | null;
60
+ user_agent?: string | null;
61
+ remote_addr?: string | null;
62
+ user?: {
63
+ id: string;
64
+ username: string;
65
+ } | null;
66
+ extra?: Record<string, unknown>;
67
+ }
@@ -174,6 +174,8 @@ export interface BillInsightData {
174
174
  end: number;
175
175
  overdue_count: number;
176
176
  not_overdue_count: number;
177
+ overdue_amount: number;
178
+ not_overdue_amount: number;
177
179
  }
178
180
  export interface ActiveSessionSummary {
179
181
  id: string;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.0.95";
1
+ export declare const AVRO_JS_VERSION = "0.0.97";
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.95';
3
+ export const AVRO_JS_VERSION = '0.0.97';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.95",
3
+ "version": "0.0.97",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",