@go-avro/avro-js 1.6.6-rc6 → 1.6.6-rc8

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.js';
4
- import { _Event, ActiveSessionSummary, AddressFeatureCollection, ApiInfo, Avro, StorageAnalytics, ClientErrorReport, ErrorLogEntry, PerformanceMetrics, AuditLogEntry, AuditQueryParams, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Chat, CheckIn, Company, CompanySummary, DelayEventCreatePayload, EventUpdatePayload, LineItemType, FinancialInsightData, RevenueInsightData, Job, JobUpdate, EventInsightData, AppleLinkProof, AppleLoginResult, MicrosoftLoginResult, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, UserMergeSummary, Skill, Group, Label, RouteScheduleConfig, RouteWritePayload, CatalogItem, Device, DeviceInfo, LocationServicesStatus, Payout, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api.js';
4
+ import { _Event, ActiveSessionSummary, AddressFeatureCollection, ApiInfo, Avro, StorageAnalytics, ClientErrorReport, ErrorLogEntry, PerformanceMetrics, AuditLogEntry, AuditQueryParams, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Chat, CheckIn, Company, CompanySummary, DelayEventCreatePayload, EventUpdatePayload, LineItemType, FinancialInsightData, RevenueInsightData, Job, JobUpdate, EventInsightData, AppleLinkProof, AppleLoginResult, MicrosoftLoginResult, LoginResponse, Message, Permission, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, UserMergeSummary, Skill, Group, Label, RouteScheduleConfig, RouteWritePayload, CatalogItem, Device, DeviceInfo, LocationServicesStatus, Payout, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api.js';
5
5
  import { AuthState, Tokens } from '../types/auth.js';
6
6
  import { CancelToken, ClientId, RetryStrategy } from '../types/client.js';
7
7
  import { StandardError } from '../types/error.js';
@@ -11,7 +11,7 @@ import { Proposal } from '../types/api/Proposal.js';
11
11
  import { ProposalTerms } from '../types/api/ProposalTerms.js';
12
12
  import type { EmailSucceededPayload, EmailFailedPayload, EmailType } from '../types/api/EmailNotification.js';
13
13
  import type { BulkDeleteBillsResponse, BulkEmailBillsResponse } from './hooks/bills.js';
14
- import type { BillWritePayload, BreakWritePayload, CatalogItemCreatePayload, CatalogItemUpdatePayload, CompanyCreatePayload, CompanyUpdatePayload, EventCreatePayload, IntuitImportResult, MemberAddPayload, MemberUpdatePayload, PayoutStatusFilter, ProposalReviewPayload, ProposalWritePayload, SessionCreatePayload, SessionUpdatePayload, SkillCreatePayload, SkillUpdatePayload, TeamWritePayload, UserCreatePayload, UserUpdatePayload } from './requests.js';
14
+ import type { BillWritePayload, BreakWritePayload, CatalogItemCreatePayload, CatalogItemUpdatePayload, CompanyCreatePayload, CompanyUpdatePayload, EventCreatePayload, IntuitSyncStatus, MemberAddPayload, MemberUpdatePayload, PayoutStatusFilter, ProposalReviewPayload, ProposalWritePayload, SessionCreatePayload, SessionUpdatePayload, SkillCreatePayload, SkillUpdatePayload, TeamWritePayload, UserCreatePayload, UserUpdatePayload } from './requests.js';
15
15
  import { type QueryPersistOptions } from './persist.js';
16
16
  export interface TrackEmailOptions {
17
17
  emailType?: EmailType;
@@ -486,7 +486,11 @@ declare module './QueryClient.js' {
486
486
  id: string | null;
487
487
  job_id: string | null;
488
488
  }>;
489
- useImportBillsFromIntuit(): ReturnType<typeof useMutation<IntuitImportResult, StandardError, void>>;
489
+ useImportBillsFromIntuit(): ReturnType<typeof useMutation<{
490
+ msg: string;
491
+ }, StandardError, void>>;
492
+ /** The company's QuickBooks sync as its socket events report it. */
493
+ useIntuitSyncStatus(): IntuitSyncStatus;
490
494
  useSyncBillToIntuit(): ReturnType<typeof useMutation<{
491
495
  msg: string;
492
496
  }, StandardError, {
@@ -614,6 +618,8 @@ declare module './QueryClient.js' {
614
618
  user_ids?: string[];
615
619
  enabled?: boolean;
616
620
  }): UseQueryResult<UserCompanyAssociation[], StandardError>;
621
+ /** Whether the viewer's membership grants `permission`; undefined until known. */
622
+ useHasPermission(permission: Permission): boolean | undefined;
617
623
  useReportDevice(): ReturnType<typeof useMutation<Device, StandardError, DeviceInfo & {
618
624
  location_status?: LocationServicesStatus;
619
625
  }>>;
@@ -1,4 +1,5 @@
1
1
  import { useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
2
+ import { useEffect, useState } from 'react';
2
3
  import { AvroQueryClient } from '../QueryClient.js';
3
4
  import { seedDetails } from '../cache.js';
4
5
  import { restoreNs, snapshotNs } from '../cache.js';
@@ -221,16 +222,40 @@ AvroQueryClient.prototype.useSyncBillToIntuit = function () {
221
222
  AvroQueryClient.prototype.useImportBillsFromIntuit = function () {
222
223
  const queryClient = this.getQueryClient();
223
224
  return useMutation({
225
+ // Starts the sync (202); follow it with useIntuitSyncStatus.
224
226
  mutationFn: async () => {
225
227
  return this.post({
226
228
  path: `/company/${this.companyId}/intuit/import`,
227
229
  });
228
230
  },
229
- onSuccess: () => {
230
- this.syncAfterMutation('bill');
231
- },
232
231
  });
233
232
  };
233
+ /**
234
+ * The company's QuickBooks sync, followed over the socket: `running` (with the
235
+ * latest progress) from `intuit_sync_started` on, then `complete` with the
236
+ * counts or `error`. Every staff member sees a run, whoever started it; the
237
+ * bills it changes arrive through the changes stream.
238
+ */
239
+ AvroQueryClient.prototype.useIntuitSyncStatus = function () {
240
+ const [status, setStatus] = useState({ state: 'idle' });
241
+ useEffect(() => {
242
+ const started = () => setStatus({ state: 'running' });
243
+ const progress = (data) => setStatus({ state: 'running', progress: data });
244
+ const complete = (data) => setStatus({ state: 'complete', result: data });
245
+ const failed = (data) => setStatus({ state: 'error', message: data?.msg ?? 'QuickBooks sync failed' });
246
+ this.on('intuit_sync_started', started);
247
+ this.on('intuit_sync_progress', progress);
248
+ this.on('intuit_sync_complete', complete);
249
+ this.on('intuit_sync_error', failed);
250
+ return () => {
251
+ this.off('intuit_sync_started', started);
252
+ this.off('intuit_sync_progress', progress);
253
+ this.off('intuit_sync_complete', complete);
254
+ this.off('intuit_sync_error', failed);
255
+ };
256
+ }, [this]);
257
+ return status;
258
+ };
234
259
  AvroQueryClient.prototype.generatePDFFromBackend = function ({ billId }) {
235
260
  return this.get({
236
261
  path: `/company/${this.companyId}/bill/${billId}/pdf`,
@@ -2,7 +2,10 @@ import { useMutation, useQuery } from '@tanstack/react-query';
2
2
  import { AvroQueryClient } from '../QueryClient.js';
3
3
  import { restoreNs, snapshotNs } from '../cache.js';
4
4
  import { keys } from '../realtime.js';
5
+ import { Permission } from '../../types/api.js';
5
6
  AvroQueryClient.prototype.useGetTeams = function (body, total, onProgress) {
7
+ // Customers and roles without team read get a 403; don't ask.
8
+ const canReadTeams = this.useHasPermission(Permission.CAN_READ_TEAMS);
6
9
  return useQuery({
7
10
  queryKey: keys.list('teams', this.companyId, {
8
11
  amt: body.amt ?? 50,
@@ -30,7 +33,7 @@ AvroQueryClient.prototype.useGetTeams = function (body, total, onProgress) {
30
33
  const teams = pages.flat();
31
34
  return teams;
32
35
  },
33
- enabled: Boolean(this.companyId),
36
+ enabled: Boolean(this.companyId) && canReadTeams !== false,
34
37
  });
35
38
  };
36
39
  AvroQueryClient.prototype.useCreateTeam = function () {
@@ -228,3 +228,16 @@ AvroQueryClient.prototype.useGetCompanyUsers = function (body = {}) {
228
228
  staleTime: 30000,
229
229
  });
230
230
  };
231
+ /**
232
+ * Whether the signed-in user's membership in the current company grants
233
+ * `permission`, directly or through a group: the check the backend makes
234
+ * before answering. `undefined` until the membership has loaded, so callers
235
+ * choose how to treat "not known yet"; gate a query with `!== false` to only
236
+ * skip it once the permission is known to be missing.
237
+ */
238
+ AvroQueryClient.prototype.useHasPermission = function (permission) {
239
+ const { data: self } = this.useGetSelf();
240
+ const { data: members } = this.useGetCompanyUsers();
241
+ const me = members?.find((member) => member.user?.id === self?.id);
242
+ return me ? (me.effective_permissions ?? []).includes(permission) : undefined;
243
+ };
@@ -229,17 +229,41 @@ export interface BillWritePayload {
229
229
  enabled_payment_methods?: PaymentType[];
230
230
  pass_on_fees?: boolean;
231
231
  }
232
- /** Response of `POST /company/<id>/intuit/import` (backend `IntuitImportResult`). */
232
+ /** Counts a finished QuickBooks sync reports (the `intuit_sync_complete` payload). */
233
233
  export interface IntuitImportResult {
234
234
  msg: string;
235
235
  imported: number;
236
236
  skipped: number;
237
237
  payments_imported: number;
238
238
  payments_skipped: number;
239
+ /** Avro bills sent to QuickBooks as new invoices. */
239
240
  pushed: number;
241
+ /** Avro payments sent to QuickBooks. */
240
242
  payments_pushed: number;
243
+ /** Bills QuickBooks refused; they retry on the next sync. */
241
244
  push_failed: number;
242
245
  }
246
+ /** A sync's phases, in order: send to QuickBooks, import invoices, import payments. */
247
+ export type IntuitSyncPhase = 'push' | 'import' | 'payments';
248
+ /** An `intuit_sync_progress` payload: `done` of `total` items in `phase`. */
249
+ export interface IntuitSyncProgress {
250
+ phase: IntuitSyncPhase;
251
+ done: number;
252
+ total: number;
253
+ }
254
+ /** The company's QuickBooks sync as its socket events report it. */
255
+ export type IntuitSyncStatus = {
256
+ state: 'idle';
257
+ } | {
258
+ state: 'running';
259
+ progress?: IntuitSyncProgress;
260
+ } | {
261
+ state: 'complete';
262
+ result: IntuitImportResult;
263
+ } | {
264
+ state: 'error';
265
+ message: string;
266
+ };
243
267
  /**
244
268
  * A payment option on a catalog item write (backend `CreatePaymentOption`).
245
269
  * Prices are integer cents.
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "1.6.6-rc6";
1
+ export declare const AVRO_JS_VERSION = "1.6.6-rc8";
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 = '1.6.6-rc6';
3
+ export const AVRO_JS_VERSION = '1.6.6-rc8';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "1.6.6-rc6",
3
+ "version": "1.6.6-rc8",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",