@go-avro/avro-js 0.0.42 → 0.0.44

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 (83) hide show
  1. package/dist/auth/AuthManager.d.ts +3 -3
  2. package/dist/auth/AuthManager.js +24 -24
  3. package/dist/auth/storage.d.ts +1 -1
  4. package/dist/auth/storage.js +3 -3
  5. package/dist/client/AvroQueryClientProvider.d.ts +4 -4
  6. package/dist/client/AvroQueryClientProvider.js +3 -3
  7. package/dist/client/QueryClient.d.ts +15 -15
  8. package/dist/client/QueryClient.js +239 -259
  9. package/dist/client/core/fetch.js +9 -9
  10. package/dist/client/core/utils.js +4 -4
  11. package/dist/client/core/xhr.js +21 -21
  12. package/dist/client/hooks/analytics.js +12 -12
  13. package/dist/client/hooks/avro.js +4 -4
  14. package/dist/client/hooks/bills.js +36 -39
  15. package/dist/client/hooks/catalog_items.js +25 -31
  16. package/dist/client/hooks/chats.js +6 -6
  17. package/dist/client/hooks/companies.js +45 -57
  18. package/dist/client/hooks/email.d.ts +3 -3
  19. package/dist/client/hooks/email.js +5 -5
  20. package/dist/client/hooks/events.js +71 -81
  21. package/dist/client/hooks/groups.js +25 -31
  22. package/dist/client/hooks/jobs.js +29 -34
  23. package/dist/client/hooks/labels.js +25 -31
  24. package/dist/client/hooks/messages.js +7 -7
  25. package/dist/client/hooks/months.js +21 -21
  26. package/dist/client/hooks/plans.js +4 -4
  27. package/dist/client/hooks/prepayments.js +21 -21
  28. package/dist/client/hooks/proposal.js +11 -11
  29. package/dist/client/hooks/root.js +4 -4
  30. package/dist/client/hooks/routes.js +42 -53
  31. package/dist/client/hooks/sessions.js +33 -45
  32. package/dist/client/hooks/skills.js +22 -28
  33. package/dist/client/hooks/teams.js +26 -32
  34. package/dist/client/hooks/timecards.js +13 -13
  35. package/dist/client/hooks/users.js +39 -42
  36. package/dist/client/hooks/waivers.js +23 -23
  37. package/dist/index.d.ts +38 -38
  38. package/dist/index.js +37 -37
  39. package/dist/types/api/AdditionalCharge.d.ts +2 -2
  40. package/dist/types/api/Avro.d.ts +1 -1
  41. package/dist/types/api/Bill.d.ts +4 -4
  42. package/dist/types/api/Bill.js +4 -4
  43. package/dist/types/api/BillPayment.d.ts +2 -2
  44. package/dist/types/api/BillUser.d.ts +1 -1
  45. package/dist/types/api/CatalogItem.d.ts +1 -1
  46. package/dist/types/api/Chat.d.ts +2 -2
  47. package/dist/types/api/Company.d.ts +12 -12
  48. package/dist/types/api/CustomLineItem.d.ts +2 -2
  49. package/dist/types/api/Email.d.ts +2 -2
  50. package/dist/types/api/EmailNotification.d.ts +2 -2
  51. package/dist/types/api/Group.d.ts +1 -1
  52. package/dist/types/api/Job.d.ts +6 -6
  53. package/dist/types/api/Job.js +12 -12
  54. package/dist/types/api/LineItem.d.ts +1 -1
  55. package/dist/types/api/LineItem.js +12 -12
  56. package/dist/types/api/MemberState.d.ts +1 -1
  57. package/dist/types/api/Message.d.ts +1 -1
  58. package/dist/types/api/PaymentMethod.d.ts +1 -1
  59. package/dist/types/api/PaymentOption.d.ts +1 -1
  60. package/dist/types/api/PaymentType.js +2 -2
  61. package/dist/types/api/PlanPayment.d.ts +1 -1
  62. package/dist/types/api/Prepayment.d.ts +4 -4
  63. package/dist/types/api/Prepayment.js +1 -1
  64. package/dist/types/api/Route.d.ts +2 -2
  65. package/dist/types/api/Route.js +7 -7
  66. package/dist/types/api/RouteJob.d.ts +1 -1
  67. package/dist/types/api/ServiceMonth.d.ts +2 -2
  68. package/dist/types/api/Session.d.ts +2 -2
  69. package/dist/types/api/Task.d.ts +7 -7
  70. package/dist/types/api/Task.js +20 -22
  71. package/dist/types/api/Timecard.d.ts +1 -1
  72. package/dist/types/api/Timecard.js +4 -4
  73. package/dist/types/api/TimecardAction.js +6 -6
  74. package/dist/types/api/User.d.ts +4 -4
  75. package/dist/types/api/UserCompanyAssociation.d.ts +2 -2
  76. package/dist/types/api/UserCompanyAssociation.js +45 -45
  77. package/dist/types/api/_Event.d.ts +5 -5
  78. package/dist/types/api/_Event.js +1 -1
  79. package/dist/types/api.d.ts +44 -44
  80. package/dist/types/api.js +42 -42
  81. package/dist/types/cache.d.ts +1 -1
  82. package/dist/types/client.d.ts +1 -1
  83. package/package.json +2 -1
@@ -1,11 +1,11 @@
1
- import { AuthState, Tokens } from "../types/auth";
2
- import { Cache, CacheData } from "../types/cache";
1
+ import { AuthState, Tokens } from '../types/auth';
2
+ import { Cache, CacheData } from '../types/cache';
3
3
  export declare class AuthManager {
4
4
  private storages;
5
5
  private baseUrl;
6
6
  private tokenRefreshedCallbacks;
7
7
  private tokenRefreshFailedCallbacks;
8
- constructor({ baseUrl, storage, }: {
8
+ constructor({ baseUrl, storage }: {
9
9
  baseUrl: string;
10
10
  storage: Cache | Cache[];
11
11
  });
@@ -1,35 +1,35 @@
1
- import { AuthState } from "../types/auth";
2
- import { StandardError } from "../types/error";
1
+ import { AuthState } from '../types/auth';
2
+ import { StandardError } from '../types/error';
3
3
  export class AuthManager {
4
- constructor({ baseUrl, storage, }) {
4
+ constructor({ baseUrl, storage }) {
5
5
  this.tokenRefreshedCallbacks = [];
6
6
  this.tokenRefreshFailedCallbacks = [];
7
7
  this.storages = Array.isArray(storage) ? storage : [storage];
8
8
  if (this.storages.length === 0) {
9
- throw new Error("At least one token storage must be provided");
9
+ throw new Error('At least one token storage must be provided');
10
10
  }
11
11
  this.storages.forEach((storage) => {
12
12
  if (!storage ||
13
- typeof storage.get !== "function" ||
14
- typeof storage.set !== "function" ||
15
- typeof storage.clear !== "function") {
16
- throw new Error("Invalid token storage provided");
13
+ typeof storage.get !== 'function' ||
14
+ typeof storage.set !== 'function' ||
15
+ typeof storage.clear !== 'function') {
16
+ throw new Error('Invalid token storage provided');
17
17
  }
18
18
  });
19
19
  this.baseUrl = baseUrl;
20
20
  }
21
21
  async isAuthenticated() {
22
22
  if (!this.storages.length) {
23
- throw new Error("No token storages initialized");
23
+ throw new Error('No token storages initialized');
24
24
  }
25
25
  for (const storage of this.storages) {
26
26
  const cache = await storage.get();
27
- if (cache && typeof cache !== "string" && cache.access_token) {
27
+ if (cache && typeof cache !== 'string' && cache.access_token) {
28
28
  try {
29
29
  const response = await fetch(`${this.baseUrl}/validate`, {
30
- method: "POST",
30
+ method: 'POST',
31
31
  headers: {
32
- "Content-Type": "application/json",
32
+ 'Content-Type': 'application/json',
33
33
  Authorization: `Bearer ${cache.access_token}`,
34
34
  },
35
35
  });
@@ -41,9 +41,9 @@ export class AuthManager {
41
41
  const newTokens = await this.refreshTokens();
42
42
  if (newTokens && newTokens.access_token) {
43
43
  const retryResponse = await fetch(`${this.baseUrl}/validate`, {
44
- method: "POST",
44
+ method: 'POST',
45
45
  headers: {
46
- "Content-Type": "application/json",
46
+ 'Content-Type': 'application/json',
47
47
  Authorization: `Bearer ${newTokens.access_token}`,
48
48
  },
49
49
  });
@@ -54,7 +54,7 @@ export class AuthManager {
54
54
  }
55
55
  }
56
56
  catch (error) {
57
- console.error("Error validating access token:", error);
57
+ console.error('Error validating access token:', error);
58
58
  }
59
59
  }
60
60
  }
@@ -63,14 +63,14 @@ export class AuthManager {
63
63
  async fetchNewTokens() {
64
64
  for (const storage of this.storages) {
65
65
  const cache = await storage.get();
66
- if (!cache || typeof cache === "string" || !cache.refresh_token)
66
+ if (!cache || typeof cache === 'string' || !cache.refresh_token)
67
67
  continue;
68
68
  try {
69
69
  const response = await fetch(`${this.baseUrl}/refresh`, {
70
- method: "POST",
70
+ method: 'POST',
71
71
  headers: {
72
- "Content-Type": "application/json",
73
- Accept: "application/json",
72
+ 'Content-Type': 'application/json',
73
+ Accept: 'application/json',
74
74
  Authorization: `Bearer ${cache.refresh_token}`,
75
75
  },
76
76
  });
@@ -83,15 +83,15 @@ export class AuthManager {
83
83
  storage.clear();
84
84
  }
85
85
  }
86
- throw new StandardError(410, "Failed to refresh tokens from all storages");
86
+ throw new StandardError(410, 'Failed to refresh tokens from all storages');
87
87
  }
88
88
  async accessToken() {
89
89
  if (!this.storages.length) {
90
- throw new Error("No token storages initialized");
90
+ throw new Error('No token storages initialized');
91
91
  }
92
92
  for (const storage of this.storages) {
93
93
  const cache = await storage.get();
94
- if (cache && typeof cache !== "string" && cache.access_token)
94
+ if (cache && typeof cache !== 'string' && cache.access_token)
95
95
  return cache.access_token;
96
96
  }
97
97
  const newToken = await this.refreshTokens();
@@ -137,8 +137,8 @@ export class AuthManager {
137
137
  return undefined;
138
138
  }
139
139
  for (const storage of this.storages) {
140
- const companyId = await storage.get("companyId");
141
- if (companyId && typeof companyId === "string")
140
+ const companyId = await storage.get('companyId');
141
+ if (companyId && typeof companyId === 'string')
142
142
  return companyId;
143
143
  }
144
144
  return undefined;
@@ -1,4 +1,4 @@
1
- import { Cache, CacheData } from "../types/cache";
1
+ import { Cache, CacheData } from '../types/cache';
2
2
  export declare class MemoryStorage implements Cache {
3
3
  private data;
4
4
  get(key?: keyof CacheData): Promise<CacheData | string | null>;
@@ -14,11 +14,11 @@ export class MemoryStorage {
14
14
  }
15
15
  export class LocalStorage {
16
16
  constructor() {
17
- this.key = "cache_data";
17
+ this.key = 'cache_data';
18
18
  }
19
19
  async get(key) {
20
- const item = JSON.parse(localStorage.getItem(this.key) ?? "null");
21
- if (typeof item !== "object" || item === null) {
20
+ const item = JSON.parse(localStorage.getItem(this.key) ?? 'null');
21
+ if (typeof item !== 'object' || item === null) {
22
22
  return null;
23
23
  }
24
24
  return item ? (key ? (item[key] ?? null) : item) : null;
@@ -1,7 +1,7 @@
1
- import React, { ReactNode } from "react";
2
- import { QueryClient } from "@tanstack/react-query";
3
- import { AvroQueryClient, AvroQueryClientConfig } from "./QueryClient";
4
- import { AuthManager } from "../auth/AuthManager";
1
+ import React, { ReactNode } from 'react';
2
+ import { QueryClient } from '@tanstack/react-query';
3
+ import { AvroQueryClient, AvroQueryClientConfig } from './QueryClient';
4
+ import { AuthManager } from '../auth/AuthManager';
5
5
  export interface AvroQueryClientProviderProps {
6
6
  baseUrl: string;
7
7
  authManager: AuthManager;
@@ -1,5 +1,5 @@
1
- import React, { createContext, useContext, useMemo, useEffect, useRef, useCallback, } from "react";
2
- import { AvroQueryClient } from "./QueryClient";
1
+ import React, { createContext, useContext, useMemo, useEffect, useRef, useCallback, } from 'react';
2
+ import { AvroQueryClient } from './QueryClient';
3
3
  const AvroQueryClientContext = createContext(null);
4
4
  export const AvroQueryClientProvider = ({ baseUrl, authManager, queryClient, configOverrides, children, }) => {
5
5
  const client = useMemo(() => {
@@ -32,7 +32,7 @@ export const AvroQueryClientProvider = ({ baseUrl, authManager, queryClient, con
32
32
  export const useAvroQueryClient = () => {
33
33
  const ctx = useContext(AvroQueryClientContext);
34
34
  if (!ctx) {
35
- throw new Error("useAvroQueryClient must be used within <AvroQueryClientProvider>");
35
+ throw new Error('useAvroQueryClient must be used within <AvroQueryClientProvider>');
36
36
  }
37
37
  return ctx;
38
38
  };
@@ -1,13 +1,13 @@
1
- import { Socket } from "socket.io-client";
2
- import { InfiniteData, QueryClient, UseInfiniteQueryResult, useMutation, UseQueryResult } from "@tanstack/react-query";
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, Prepayment, Timecard, TimecardActionType, TimecardStatus } from "../types/api";
5
- import { AuthState, Tokens } from "../types/auth";
6
- import { CancelToken, RetryStrategy } from "../types/client";
7
- import { StandardError } from "../types/error";
8
- import { CacheData } from "../types/cache";
9
- import { Waiver } from "../types/api/Waiver";
10
- import type { EmailSucceededPayload, EmailFailedPayload, EmailType } from "../types/api/EmailNotification";
1
+ import { Socket } from 'socket.io-client';
2
+ import { InfiniteData, QueryClient, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
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, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api';
5
+ import { AuthState, Tokens } from '../types/auth';
6
+ import { CancelToken, RetryStrategy } from '../types/client';
7
+ import { StandardError } from '../types/error';
8
+ import { CacheData } from '../types/cache';
9
+ import { Waiver } from '../types/api/Waiver';
10
+ import type { EmailSucceededPayload, EmailFailedPayload, EmailType } from '../types/api/EmailNotification';
11
11
  /** Callbacks for a tracked email request. */
12
12
  export interface TrackEmailOptions {
13
13
  emailType?: EmailType;
@@ -24,7 +24,7 @@ export interface AvroQueryClientConfig {
24
24
  retryStrategy?: RetryStrategy;
25
25
  timeout?: number;
26
26
  }
27
- declare module "../client/QueryClient" {
27
+ declare module '../client/QueryClient' {
28
28
  interface AvroQueryClient {
29
29
  _xhr<T>(method: string, path: string, body: any, cancelToken?: CancelToken, headers?: Record<string, string>, isIdempotent?: boolean, retryCount?: number, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
30
30
  _fetch<T>(method: string, path: string, body: any, cancelToken?: CancelToken, headers?: Record<string, string>, isIdempotent?: boolean, retryCount?: number): Promise<T>;
@@ -398,7 +398,7 @@ declare module "../client/QueryClient" {
398
398
  events: (_Event & {
399
399
  page?: number;
400
400
  })[];
401
- action: "billed" | "paid";
401
+ action: 'billed' | 'paid';
402
402
  }>>;
403
403
  useUpdateTeam(): ReturnType<typeof useMutation<{
404
404
  msg: string;
@@ -410,13 +410,13 @@ declare module "../client/QueryClient" {
410
410
  months: (ServiceMonth & {
411
411
  page?: number;
412
412
  })[];
413
- action: "billed" | "paid";
413
+ action: 'billed' | 'paid';
414
414
  }>>;
415
415
  useUpdatePrepayments(): ReturnType<typeof useMutation<void, StandardError, {
416
416
  prepayments: (Prepayment & {
417
417
  page?: number;
418
418
  })[];
419
- action: "billed" | "paid";
419
+ action: 'billed' | 'paid';
420
420
  }>>;
421
421
  useUpdateUserCompany(): ReturnType<typeof useMutation<{
422
422
  msg: string;
@@ -630,7 +630,7 @@ export declare class AvroQueryClient {
630
630
  * for deletes / entities without a fetchPath.
631
631
  */
632
632
  _syncEntity(queryClient: QueryClient, params: {
633
- action: "create" | "update" | "delete";
633
+ action: 'create' | 'update' | 'delete';
634
634
  entityKey: string;
635
635
  id: string;
636
636
  fetchPath?: string;