@go-avro/avro-js 0.0.106 → 0.0.107
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.
- package/dist/client/QueryClient.d.ts +17 -2
- package/dist/client/QueryClient.js +21 -2
- package/dist/client/hooks/devices.d.ts +1 -0
- package/dist/client/hooks/devices.js +33 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/presence.d.ts +23 -0
- package/dist/presence.js +33 -0
- package/dist/types/api/Device.d.ts +37 -0
- package/dist/types/api/Device.js +5 -0
- package/dist/types/api/User.d.ts +2 -0
- package/dist/types/api/UserCompanyAssociation.d.ts +0 -1
- package/dist/types/api.d.ts +3 -0
- package/dist/types/api.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -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, ClientErrorReport, ErrorLogEntry, AuditLogEntry, AuditQueryParams, 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, AuditLogEntry, AuditQueryParams, 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, Device, DeviceInfo, LocationServicesStatus, 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';
|
|
@@ -25,6 +25,7 @@ export interface AvroQueryClientConfig {
|
|
|
25
25
|
timeout?: number;
|
|
26
26
|
clientId?: ClientId;
|
|
27
27
|
clientVersion?: string;
|
|
28
|
+
device?: DeviceInfo;
|
|
28
29
|
}
|
|
29
30
|
declare module '../client/QueryClient' {
|
|
30
31
|
interface AvroQueryClient {
|
|
@@ -546,6 +547,15 @@ declare module '../client/QueryClient' {
|
|
|
546
547
|
user_id: string;
|
|
547
548
|
data: Partial<UserCompanyAssociation>;
|
|
548
549
|
}>>;
|
|
550
|
+
useDevices(): UseQueryResult<Device[], StandardError>;
|
|
551
|
+
useReportDevice(): ReturnType<typeof useMutation<Device, StandardError, DeviceInfo & {
|
|
552
|
+
location_status?: LocationServicesStatus;
|
|
553
|
+
}>>;
|
|
554
|
+
useDeleteDevice(): ReturnType<typeof useMutation<{
|
|
555
|
+
msg: string;
|
|
556
|
+
}, StandardError, {
|
|
557
|
+
device_id: string;
|
|
558
|
+
}>>;
|
|
549
559
|
useDeleteCatalogItem(): ReturnType<typeof useMutation<{
|
|
550
560
|
msg: string;
|
|
551
561
|
}, StandardError, {
|
|
@@ -652,7 +662,7 @@ export declare function matchesBillsListQuery(queryKey: readonly unknown[], item
|
|
|
652
662
|
export declare function matchesJobsListQuery(queryKey: readonly unknown[], item: any): ListQueryMatch;
|
|
653
663
|
export declare function matchesRoutesListQuery(queryKey: readonly unknown[], _item: any): ListQueryMatch;
|
|
654
664
|
export declare class AvroQueryClient {
|
|
655
|
-
protected config: Required<Omit<AvroQueryClientConfig, 'clientId' | 'clientVersion'>> & Pick<AvroQueryClientConfig, 'clientId' | 'clientVersion'>;
|
|
665
|
+
protected config: Required<Omit<AvroQueryClientConfig, 'clientId' | 'clientVersion' | 'device'>> & Pick<AvroQueryClientConfig, 'clientId' | 'clientVersion' | 'device'>;
|
|
656
666
|
readonly socket: Socket;
|
|
657
667
|
_authState: AuthState;
|
|
658
668
|
companyId: string | undefined;
|
|
@@ -663,6 +673,11 @@ export declare class AvroQueryClient {
|
|
|
663
673
|
private _emailTracking;
|
|
664
674
|
private _emailListenersInit;
|
|
665
675
|
constructor(config: AvroQueryClientConfig);
|
|
676
|
+
/** Handshake payload: the token plus, when known, this install's identity. */
|
|
677
|
+
private socketAuth;
|
|
678
|
+
/** The install identity sent with sockets and location pings, if any. */
|
|
679
|
+
get device(): DeviceInfo | undefined;
|
|
680
|
+
setDevice(device: DeviceInfo | undefined): void;
|
|
666
681
|
emit(eventName: string, data: unknown): void;
|
|
667
682
|
on<T>(eventName: string, callback: (data: T) => void): void;
|
|
668
683
|
off(eventName: string, callback?: Function): void;
|
|
@@ -394,6 +394,7 @@ export class AvroQueryClient {
|
|
|
394
394
|
timeout: config.timeout ?? 0,
|
|
395
395
|
clientId: config.clientId,
|
|
396
396
|
clientVersion: config.clientVersion,
|
|
397
|
+
device: config.device,
|
|
397
398
|
};
|
|
398
399
|
this.socket = io(config.baseUrl, {
|
|
399
400
|
autoConnect: false,
|
|
@@ -408,7 +409,7 @@ export class AvroQueryClient {
|
|
|
408
409
|
Promise.all([this.getCompanyId(), this.config.authManager.accessToken()])
|
|
409
410
|
.then(([id, token]) => {
|
|
410
411
|
this.companyId = id;
|
|
411
|
-
this.socket.auth =
|
|
412
|
+
this.socket.auth = this.socketAuth(token);
|
|
412
413
|
this.socket.connect();
|
|
413
414
|
})
|
|
414
415
|
.catch((err) => {
|
|
@@ -435,7 +436,7 @@ export class AvroQueryClient {
|
|
|
435
436
|
this.config.authManager.onTokenRefreshed((newAccessToken) => {
|
|
436
437
|
if (this.socket && newAccessToken) {
|
|
437
438
|
this.setAuthState(AuthState.AUTHENTICATED);
|
|
438
|
-
this.socket.auth =
|
|
439
|
+
this.socket.auth = this.socketAuth(newAccessToken);
|
|
439
440
|
this.socket.disconnect().connect();
|
|
440
441
|
}
|
|
441
442
|
});
|
|
@@ -443,6 +444,24 @@ export class AvroQueryClient {
|
|
|
443
444
|
void this.forceLogout();
|
|
444
445
|
});
|
|
445
446
|
}
|
|
447
|
+
/** Handshake payload: the token plus, when known, this install's identity. */
|
|
448
|
+
socketAuth(token) {
|
|
449
|
+
return this.config.device ? { token, device: this.config.device } : { token };
|
|
450
|
+
}
|
|
451
|
+
/** The install identity sent with sockets and location pings, if any. */
|
|
452
|
+
get device() {
|
|
453
|
+
return this.config.device;
|
|
454
|
+
}
|
|
455
|
+
setDevice(device) {
|
|
456
|
+
this.config.device = device;
|
|
457
|
+
if (this.socket.connected) {
|
|
458
|
+
const auth = this.socket.auth;
|
|
459
|
+
if (auth?.token) {
|
|
460
|
+
this.socket.auth = this.socketAuth(auth.token);
|
|
461
|
+
this.socket.disconnect().connect();
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
446
465
|
emit(eventName, data) {
|
|
447
466
|
if (!this.socket?.connected) {
|
|
448
467
|
console.error('Socket is not connected. Cannot emit event.');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
AvroQueryClient.prototype.useDevices = function () {
|
|
4
|
+
return useQuery({
|
|
5
|
+
queryKey: ['devices'],
|
|
6
|
+
queryFn: () => this.get({ path: '/devices' }),
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
AvroQueryClient.prototype.useReportDevice = function () {
|
|
10
|
+
const queryClient = this.getQueryClient();
|
|
11
|
+
return useMutation({
|
|
12
|
+
mutationFn: (data) => this.put({
|
|
13
|
+
path: '/device',
|
|
14
|
+
data: JSON.stringify({ ...this.device, ...data }),
|
|
15
|
+
headers: { 'Content-Type': 'application/json' },
|
|
16
|
+
}),
|
|
17
|
+
onSuccess: () => {
|
|
18
|
+
queryClient.invalidateQueries({ queryKey: ['devices'] });
|
|
19
|
+
queryClient.invalidateQueries({ queryKey: ['user'] });
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
AvroQueryClient.prototype.useDeleteDevice = function () {
|
|
24
|
+
const queryClient = this.getQueryClient();
|
|
25
|
+
return useMutation({
|
|
26
|
+
mutationFn: ({ device_id }) => this.delete({ path: `/device/${device_id}` }),
|
|
27
|
+
onSuccess: () => {
|
|
28
|
+
queryClient.invalidateQueries({ queryKey: ['devices'] });
|
|
29
|
+
queryClient.invalidateQueries({ queryKey: ['user'] });
|
|
30
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ import './client/hooks/months';
|
|
|
18
18
|
import './client/hooks/bills';
|
|
19
19
|
import './client/hooks/payouts';
|
|
20
20
|
import './client/hooks/companies';
|
|
21
|
+
import './client/hooks/devices';
|
|
21
22
|
import './client/hooks/users';
|
|
22
23
|
import './client/hooks/sessions';
|
|
23
24
|
import './client/hooks/checkins';
|
|
@@ -39,6 +40,7 @@ import './client/hooks/email';
|
|
|
39
40
|
export { defaultPassOnFeeMethod } from './billing/fees';
|
|
40
41
|
export { reverseGeocode } from './geocode';
|
|
41
42
|
export { fetchCensusFeatures } from './census';
|
|
43
|
+
export { LOCATION_STALE_MINUTES, REPORTING_STATUSES, locationAgeMinutes, isLocationStale, isReportingStatus, isMobileDevice, mobileDevices, } from './presence';
|
|
42
44
|
export type { ReverseGeocodeResult } from './geocode';
|
|
43
45
|
export * from './types/api';
|
|
44
46
|
export * from './types/auth';
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import './client/hooks/months';
|
|
|
16
16
|
import './client/hooks/bills';
|
|
17
17
|
import './client/hooks/payouts';
|
|
18
18
|
import './client/hooks/companies';
|
|
19
|
+
import './client/hooks/devices';
|
|
19
20
|
import './client/hooks/users';
|
|
20
21
|
import './client/hooks/sessions';
|
|
21
22
|
import './client/hooks/checkins';
|
|
@@ -37,6 +38,7 @@ import './client/hooks/email';
|
|
|
37
38
|
export { defaultPassOnFeeMethod } from './billing/fees';
|
|
38
39
|
export { reverseGeocode } from './geocode';
|
|
39
40
|
export { fetchCensusFeatures } from './census';
|
|
41
|
+
export { LOCATION_STALE_MINUTES, REPORTING_STATUSES, locationAgeMinutes, isLocationStale, isReportingStatus, isMobileDevice, mobileDevices, } from './presence';
|
|
40
42
|
export * from './types/api';
|
|
41
43
|
export * from './types/auth';
|
|
42
44
|
export * from './types/cache';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Device, Location, LocationServicesStatus } from './types/api';
|
|
2
|
+
/**
|
|
3
|
+
* Statuses under which a device promises to keep pinging. Mirrors the
|
|
4
|
+
* backend's REPORTING_STATUSES: only these flip to APP_DEAD when the
|
|
5
|
+
* device's last socket drops.
|
|
6
|
+
*/
|
|
7
|
+
export declare const REPORTING_STATUSES: readonly LocationServicesStatus[];
|
|
8
|
+
export declare const isReportingStatus: (status: LocationServicesStatus | null | undefined) => boolean;
|
|
9
|
+
/** Only phones/tablets report location; web devices are presence-only. */
|
|
10
|
+
export declare const isMobileDevice: (device: Pick<Device, "platform">) => boolean;
|
|
11
|
+
/** The user's mobile devices, most recently seen first. */
|
|
12
|
+
export declare const mobileDevices: (devices: Device[] | null | undefined) => Device[];
|
|
13
|
+
/**
|
|
14
|
+
* A member whose last fix is older than this is "stale": the app is
|
|
15
|
+
* connected but the OS has stopped delivering positions (typical for a
|
|
16
|
+
* stationary phone in the background on iOS). Distinct from
|
|
17
|
+
* `location_status`, which reports permissions / app liveness.
|
|
18
|
+
*/
|
|
19
|
+
export declare const LOCATION_STALE_MINUTES = 15;
|
|
20
|
+
/** Age of a location fix in whole minutes, or null when there is none. */
|
|
21
|
+
export declare const locationAgeMinutes: (location: Pick<Location, "time_collected"> | null | undefined, nowMs?: number) => number | null;
|
|
22
|
+
/** True when the fix is missing or older than `staleMinutes`. */
|
|
23
|
+
export declare const isLocationStale: (location: Pick<Location, "time_collected"> | null | undefined, staleMinutes?: number, nowMs?: number) => boolean;
|
package/dist/presence.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Statuses under which a device promises to keep pinging. Mirrors the
|
|
3
|
+
* backend's REPORTING_STATUSES: only these flip to APP_DEAD when the
|
|
4
|
+
* device's last socket drops.
|
|
5
|
+
*/
|
|
6
|
+
export const REPORTING_STATUSES = [
|
|
7
|
+
'OKAY',
|
|
8
|
+
'BACKGROUND_ONLY',
|
|
9
|
+
'REDUCED_ACCURACY',
|
|
10
|
+
];
|
|
11
|
+
export const isReportingStatus = (status) => status != null && REPORTING_STATUSES.includes(status);
|
|
12
|
+
/** Only phones/tablets report location; web devices are presence-only. */
|
|
13
|
+
export const isMobileDevice = (device) => device.platform === 'ios' || device.platform === 'android';
|
|
14
|
+
/** The user's mobile devices, most recently seen first. */
|
|
15
|
+
export const mobileDevices = (devices) => (devices ?? []).filter(isMobileDevice).sort((a, b) => (b.last_seen ?? 0) - (a.last_seen ?? 0));
|
|
16
|
+
/**
|
|
17
|
+
* A member whose last fix is older than this is "stale": the app is
|
|
18
|
+
* connected but the OS has stopped delivering positions (typical for a
|
|
19
|
+
* stationary phone in the background on iOS). Distinct from
|
|
20
|
+
* `location_status`, which reports permissions / app liveness.
|
|
21
|
+
*/
|
|
22
|
+
export const LOCATION_STALE_MINUTES = 15;
|
|
23
|
+
/** Age of a location fix in whole minutes, or null when there is none. */
|
|
24
|
+
export const locationAgeMinutes = (location, nowMs = Date.now()) => {
|
|
25
|
+
if (!location?.time_collected)
|
|
26
|
+
return null;
|
|
27
|
+
return Math.max(0, Math.floor((nowMs / 1000 - location.time_collected) / 60));
|
|
28
|
+
};
|
|
29
|
+
/** True when the fix is missing or older than `staleMinutes`. */
|
|
30
|
+
export const isLocationStale = (location, staleMinutes = LOCATION_STALE_MINUTES, nowMs = Date.now()) => {
|
|
31
|
+
const age = locationAgeMinutes(location, nowMs);
|
|
32
|
+
return age === null || age >= staleMinutes;
|
|
33
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Location } from '../../types/api';
|
|
2
|
+
import { LocationServicesStatus } from '../../types/api/UserCompanyAssociation';
|
|
3
|
+
export declare const DevicePlatform: {
|
|
4
|
+
readonly IOS: "ios";
|
|
5
|
+
readonly ANDROID: "android";
|
|
6
|
+
readonly WEB: "web";
|
|
7
|
+
};
|
|
8
|
+
export type DevicePlatform = (typeof DevicePlatform)[keyof typeof DevicePlatform];
|
|
9
|
+
/** What a client tells the server about the install it is running on. */
|
|
10
|
+
export interface DeviceInfo {
|
|
11
|
+
/** Stable per-install id (identifierForVendor, androidId, stored UUID). */
|
|
12
|
+
device_key: string;
|
|
13
|
+
platform: DevicePlatform;
|
|
14
|
+
/** User-facing label, e.g. "Chris's iPhone". */
|
|
15
|
+
name?: string;
|
|
16
|
+
/** Hardware, e.g. "iPhone 17" or "ASUS Zenbook". */
|
|
17
|
+
model?: string;
|
|
18
|
+
/** OS and version, e.g. "iOS 26.1" or "macOS 15". */
|
|
19
|
+
os?: string;
|
|
20
|
+
app_version?: string;
|
|
21
|
+
}
|
|
22
|
+
/** A device the user has connected from, as tracked by the server. */
|
|
23
|
+
export interface Device {
|
|
24
|
+
id: string;
|
|
25
|
+
user_id: string;
|
|
26
|
+
platform: DevicePlatform;
|
|
27
|
+
name: string | null;
|
|
28
|
+
model: string | null;
|
|
29
|
+
os: string | null;
|
|
30
|
+
app_version: string | null;
|
|
31
|
+
location_status: LocationServicesStatus;
|
|
32
|
+
/** Whether the device currently holds a socket. */
|
|
33
|
+
online: boolean;
|
|
34
|
+
last_location: Location | null;
|
|
35
|
+
last_seen: number | null;
|
|
36
|
+
time_created: number | null;
|
|
37
|
+
}
|
package/dist/types/api/User.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BillUser } from '../../types/api/BillUser';
|
|
2
|
+
import { Device } from '../../types/api/Device';
|
|
2
3
|
import { Chat } from '../../types/api/Chat';
|
|
3
4
|
import { PaymentMethod } from '../../types/api/PaymentMethod';
|
|
4
5
|
import { PaymentType } from '../../types/api/PaymentType';
|
|
@@ -15,6 +16,7 @@ export interface User {
|
|
|
15
16
|
time_created: number;
|
|
16
17
|
time_updated: number | null;
|
|
17
18
|
share_location: boolean;
|
|
19
|
+
devices: Device[] | null;
|
|
18
20
|
notification_setting: NotificationLevel[] | null;
|
|
19
21
|
can_send_emails: boolean | null;
|
|
20
22
|
payment_methods: PaymentMethod[];
|
package/dist/types/api.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Route } from '../types/api/Route';
|
|
|
4
4
|
export * from '../types/api/_Event';
|
|
5
5
|
export * from '../types/api/AdditionalCharge';
|
|
6
6
|
export * from '../types/api/DelayEvent';
|
|
7
|
+
export * from '../types/api/Device';
|
|
7
8
|
export * from '../types/api/Address';
|
|
8
9
|
export * from '../types/api/Avro';
|
|
9
10
|
export * from '../types/api/AuditLog';
|
|
@@ -102,6 +103,8 @@ export interface Location {
|
|
|
102
103
|
team_id: string | null;
|
|
103
104
|
user_company_id: string;
|
|
104
105
|
user_id: string;
|
|
106
|
+
device_id: string | null;
|
|
107
|
+
version: string | null;
|
|
105
108
|
latitude: number;
|
|
106
109
|
longitude: number;
|
|
107
110
|
time_collected: number;
|
package/dist/types/api.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from '../types/api/_Event';
|
|
2
2
|
export * from '../types/api/AdditionalCharge';
|
|
3
3
|
export * from '../types/api/DelayEvent';
|
|
4
|
+
export * from '../types/api/Device';
|
|
4
5
|
export * from '../types/api/Address';
|
|
5
6
|
export * from '../types/api/Avro';
|
|
6
7
|
export * from '../types/api/AuditLog';
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AVRO_JS_VERSION = "0.0.
|
|
1
|
+
export declare const AVRO_JS_VERSION = "0.0.107";
|
package/dist/version.js
CHANGED