@go-avro/avro-js 0.0.77 → 0.0.79
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/census.d.ts +8 -0
- package/dist/census.js +76 -0
- package/dist/client/QueryClient.d.ts +25 -2
- package/dist/client/QueryClient.js +55 -2
- package/dist/client/core/xhr.js +4 -3
- package/dist/client/hooks/address.d.ts +1 -0
- package/dist/client/hooks/address.js +45 -0
- package/dist/client/hooks/routes.js +6 -1
- package/dist/geocode.d.ts +9 -0
- package/dist/geocode.js +25 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/types/api/Address.d.ts +22 -0
- package/dist/types/api/Address.js +1 -0
- package/dist/types/api/Job.js +2 -2
- package/dist/types/api/RouteJob.d.ts +5 -7
- package/dist/types/api/RouteJob.js +3 -6
- package/dist/types/api.d.ts +5 -1
- 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
package/dist/census.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AddressFeature } from './types/api';
|
|
2
|
+
/**
|
|
3
|
+
* Geocode an address with the US Census geocoder, directly from the
|
|
4
|
+
* client so requests come from each user's own IP rather than funneling
|
|
5
|
+
* through the backend. Returns [] on any failure — census results only
|
|
6
|
+
* ever supplement Pelias results.
|
|
7
|
+
*/
|
|
8
|
+
export declare const fetchCensusFeatures: (address: string) => Promise<AddressFeature[]>;
|
package/dist/census.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const CENSUS_GEOCODER_URL = 'https://geocoding.geo.census.gov/geocoder/locations/onelineaddress';
|
|
2
|
+
const CENSUS_BENCHMARK = 'Public_AR_Census2020';
|
|
3
|
+
const CENSUS_TIMEOUT_MS = 3000;
|
|
4
|
+
// The census geocoder sends no CORS headers, so browsers can only reach
|
|
5
|
+
// it via JSONP (script-tag injection).
|
|
6
|
+
const jsonpRequest = (url, timeoutMs) => new Promise((resolve, reject) => {
|
|
7
|
+
const host = window;
|
|
8
|
+
const callbackName = `__avro_census_cb_${Math.random().toString(36).slice(2)}`;
|
|
9
|
+
const script = document.createElement('script');
|
|
10
|
+
const cleanup = () => {
|
|
11
|
+
delete host[callbackName];
|
|
12
|
+
script.remove();
|
|
13
|
+
clearTimeout(timer);
|
|
14
|
+
};
|
|
15
|
+
const timer = setTimeout(() => {
|
|
16
|
+
cleanup();
|
|
17
|
+
reject(new Error('Census request timed out'));
|
|
18
|
+
}, timeoutMs);
|
|
19
|
+
host[callbackName] = (data) => {
|
|
20
|
+
cleanup();
|
|
21
|
+
resolve(data);
|
|
22
|
+
};
|
|
23
|
+
script.onerror = () => {
|
|
24
|
+
cleanup();
|
|
25
|
+
reject(new Error('Census request failed'));
|
|
26
|
+
};
|
|
27
|
+
script.src = `${url}&callback=${callbackName}`;
|
|
28
|
+
document.head.appendChild(script);
|
|
29
|
+
});
|
|
30
|
+
// React Native has no DOM for JSONP, but also enforces no CORS, so a
|
|
31
|
+
// plain fetch works there.
|
|
32
|
+
const fetchRequest = async (url, timeoutMs) => {
|
|
33
|
+
const controller = new AbortController();
|
|
34
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
35
|
+
try {
|
|
36
|
+
const res = await fetch(url, { signal: controller.signal });
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
throw new Error(`Census request failed: ${res.status}`);
|
|
39
|
+
}
|
|
40
|
+
return await res.json();
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
clearTimeout(timer);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Geocode an address with the US Census geocoder, directly from the
|
|
48
|
+
* client so requests come from each user's own IP rather than funneling
|
|
49
|
+
* through the backend. Returns [] on any failure — census results only
|
|
50
|
+
* ever supplement Pelias results.
|
|
51
|
+
*/
|
|
52
|
+
export const fetchCensusFeatures = async (address) => {
|
|
53
|
+
const useJsonp = typeof document !== 'undefined';
|
|
54
|
+
const params = new URLSearchParams({
|
|
55
|
+
address: address.trim(),
|
|
56
|
+
benchmark: CENSUS_BENCHMARK,
|
|
57
|
+
format: useJsonp ? 'jsonp' : 'json',
|
|
58
|
+
});
|
|
59
|
+
const url = `${CENSUS_GEOCODER_URL}?${params.toString()}`;
|
|
60
|
+
try {
|
|
61
|
+
const data = (useJsonp
|
|
62
|
+
? await jsonpRequest(url, CENSUS_TIMEOUT_MS)
|
|
63
|
+
: await fetchRequest(url, CENSUS_TIMEOUT_MS));
|
|
64
|
+
return (data.result?.addressMatches ?? []).map((match) => ({
|
|
65
|
+
type: 'Feature',
|
|
66
|
+
geometry: {
|
|
67
|
+
type: 'Point',
|
|
68
|
+
coordinates: [match.coordinates.x, match.coordinates.y],
|
|
69
|
+
},
|
|
70
|
+
properties: { label: match.matchedAddress },
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
};
|
|
@@ -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, ApiInfo, Avro, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Break, Chat, CheckIn, Company, EventUpdatePayload, FinancialInsightData, RevenueInsightData, Job, 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, Bill, BillInsightData, BillLineItemStatusUpdate, BillStatus, Break, Chat, CheckIn, Company, EventUpdatePayload, FinancialInsightData, RevenueInsightData, Job, 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';
|
|
@@ -166,6 +166,18 @@ declare module '../client/QueryClient' {
|
|
|
166
166
|
msg: string;
|
|
167
167
|
}>;
|
|
168
168
|
useGetProposal(proposal_id: string): UseQueryResult<any, StandardError>;
|
|
169
|
+
useAutocompleteAddress(address: string, options?: {
|
|
170
|
+
size?: number;
|
|
171
|
+
minLength?: number;
|
|
172
|
+
debounceMs?: number;
|
|
173
|
+
includeCensus?: boolean;
|
|
174
|
+
}): UseQueryResult<AddressFeatureCollection, StandardError>;
|
|
175
|
+
useSearchAddress(address: string, options?: {
|
|
176
|
+
focusPointLatitude?: number;
|
|
177
|
+
focusPointLongitude?: number;
|
|
178
|
+
minLength?: number;
|
|
179
|
+
debounceMs?: number;
|
|
180
|
+
}): UseQueryResult<AddressFeatureCollection, StandardError>;
|
|
169
181
|
useGetAnalytics(): UseQueryResult<any, StandardError>;
|
|
170
182
|
useFinanceAnalytics({ periods, cumulative, }: {
|
|
171
183
|
periods: number[][];
|
|
@@ -647,12 +659,13 @@ export declare class AvroQueryClient {
|
|
|
647
659
|
headers?: Record<string, string>;
|
|
648
660
|
progressUpdateCallback?: (loaded: number, total: number) => void;
|
|
649
661
|
}): Promise<T>;
|
|
650
|
-
post<T>({ path, data, cancelToken, headers, progressUpdateCallback, }: {
|
|
662
|
+
post<T>({ path, data, cancelToken, headers, progressUpdateCallback, maxRetries, }: {
|
|
651
663
|
path: string;
|
|
652
664
|
data?: any;
|
|
653
665
|
cancelToken?: CancelToken;
|
|
654
666
|
headers?: Record<string, string>;
|
|
655
667
|
progressUpdateCallback?: (loaded: number, total: number) => void;
|
|
668
|
+
maxRetries?: number;
|
|
656
669
|
}): Promise<T>;
|
|
657
670
|
put<T>({ path, data, cancelToken, headers, progressUpdateCallback, }: {
|
|
658
671
|
path: string;
|
|
@@ -727,6 +740,16 @@ export declare class AvroQueryClient {
|
|
|
727
740
|
offset?: number;
|
|
728
741
|
route_id?: string;
|
|
729
742
|
}, companyId?: string, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
743
|
+
autocompleteAddress({ address, size, include_census, }: {
|
|
744
|
+
address: string;
|
|
745
|
+
size?: number;
|
|
746
|
+
include_census?: boolean;
|
|
747
|
+
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<AddressFeatureCollection>;
|
|
748
|
+
searchAddress({ address, focus_point_latitude, focus_point_longitude, }: {
|
|
749
|
+
address: string;
|
|
750
|
+
focus_point_latitude?: number;
|
|
751
|
+
focus_point_longitude?: number;
|
|
752
|
+
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<AddressFeatureCollection>;
|
|
730
753
|
fetchChats(body?: {
|
|
731
754
|
amt?: number;
|
|
732
755
|
known_ids?: string[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import io from 'socket.io-client';
|
|
2
2
|
import { useMutation, useQueryClient, } from '@tanstack/react-query';
|
|
3
3
|
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
import { fetchCensusFeatures } from '../census';
|
|
4
5
|
import { _Event, Job, LoginResponse, Route, } from '../types/api';
|
|
5
6
|
import { AuthState } from '../types/auth';
|
|
6
7
|
import { StandardError } from '../types/error';
|
|
@@ -564,8 +565,8 @@ export class AvroQueryClient {
|
|
|
564
565
|
get({ path, cancelToken, headers, progressUpdateCallback, }) {
|
|
565
566
|
return this._xhr('GET', path, null, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
|
|
566
567
|
}
|
|
567
|
-
post({ path, data, cancelToken, headers, progressUpdateCallback, }) {
|
|
568
|
-
return this._xhr('POST', path, data, cancelToken, headers, false, this.config.maxRetries, progressUpdateCallback);
|
|
568
|
+
post({ path, data, cancelToken, headers, progressUpdateCallback, maxRetries, }) {
|
|
569
|
+
return this._xhr('POST', path, data, cancelToken, headers, false, maxRetries ?? this.config.maxRetries, progressUpdateCallback);
|
|
569
570
|
}
|
|
570
571
|
put({ path, data, cancelToken, headers, progressUpdateCallback, }) {
|
|
571
572
|
return this._xhr('PUT', path, data, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
|
|
@@ -920,6 +921,58 @@ export class AvroQueryClient {
|
|
|
920
921
|
throw new StandardError(500, `Failed to fetch jobs: ${err.message ?? err}`);
|
|
921
922
|
});
|
|
922
923
|
}
|
|
924
|
+
async autocompleteAddress({ address, size = 10, include_census = true, }, cancelToken, headers = {}) {
|
|
925
|
+
const peliasPromise = this.post({
|
|
926
|
+
path: '/address/autocomplete',
|
|
927
|
+
data: JSON.stringify({ address, size }),
|
|
928
|
+
cancelToken,
|
|
929
|
+
headers: {
|
|
930
|
+
...headers,
|
|
931
|
+
'Content-Type': 'application/json',
|
|
932
|
+
},
|
|
933
|
+
// Autocomplete is per-keystroke; retrying a down backend just
|
|
934
|
+
// multiplies the load. The next keystroke is the retry.
|
|
935
|
+
maxRetries: 0,
|
|
936
|
+
});
|
|
937
|
+
if (!include_census) {
|
|
938
|
+
return peliasPromise;
|
|
939
|
+
}
|
|
940
|
+
// The census lookup runs client-side (each user's own IP) and in
|
|
941
|
+
// parallel with the backend call; fetchCensusFeatures never rejects.
|
|
942
|
+
const [pelias, census] = await Promise.all([
|
|
943
|
+
peliasPromise.then((value) => ({ value, error: null }), (error) => ({ value: null, error })),
|
|
944
|
+
fetchCensusFeatures(address),
|
|
945
|
+
]);
|
|
946
|
+
if (!pelias.value && census.length === 0) {
|
|
947
|
+
throw pelias.error;
|
|
948
|
+
}
|
|
949
|
+
const features = pelias.value?.features ?? [];
|
|
950
|
+
const knownLabels = new Set(features.map((feature) => feature.properties.label.toLowerCase()));
|
|
951
|
+
return {
|
|
952
|
+
...pelias.value,
|
|
953
|
+
type: 'FeatureCollection',
|
|
954
|
+
features: [
|
|
955
|
+
...features,
|
|
956
|
+
...census.filter((feature) => !knownLabels.has(feature.properties.label.toLowerCase())),
|
|
957
|
+
],
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
searchAddress({ address, focus_point_latitude, focus_point_longitude, }, cancelToken, headers = {}) {
|
|
961
|
+
return this.post({
|
|
962
|
+
path: '/address/search',
|
|
963
|
+
data: JSON.stringify({
|
|
964
|
+
address,
|
|
965
|
+
...(focus_point_latitude !== undefined && { focus_point_latitude }),
|
|
966
|
+
...(focus_point_longitude !== undefined && { focus_point_longitude }),
|
|
967
|
+
}),
|
|
968
|
+
cancelToken,
|
|
969
|
+
headers: {
|
|
970
|
+
...headers,
|
|
971
|
+
'Content-Type': 'application/json',
|
|
972
|
+
},
|
|
973
|
+
maxRetries: 0,
|
|
974
|
+
});
|
|
975
|
+
}
|
|
923
976
|
fetchChats(body = {}, cancelToken, headers = {}) {
|
|
924
977
|
if (!this.companyId || this.companyId.trim() === '') {
|
|
925
978
|
throw new StandardError(400, 'Company ID is required');
|
package/dist/client/core/xhr.js
CHANGED
|
@@ -2,13 +2,14 @@ import { AvroQueryClient } from '../../client/QueryClient';
|
|
|
2
2
|
import { StandardError } from '../../types/error';
|
|
3
3
|
import { AuthState } from '../../types/auth';
|
|
4
4
|
import { AVRO_JS_VERSION } from '../../version';
|
|
5
|
-
AvroQueryClient.prototype._xhr = async function (method, path, body, cancelToken, headers = {}, isIdempotent = false, retryCount
|
|
5
|
+
AvroQueryClient.prototype._xhr = async function (method, path, body, cancelToken, headers = {}, isIdempotent = false, retryCount, progressUpdateCallback) {
|
|
6
|
+
const maxRetries = retryCount ?? this.config.maxRetries;
|
|
6
7
|
const checkCancelled = () => {
|
|
7
8
|
if (cancelToken?.isCancelled()) {
|
|
8
9
|
throw new StandardError(0, 'Request cancelled');
|
|
9
10
|
}
|
|
10
11
|
};
|
|
11
|
-
for (let attempt = 0; attempt <=
|
|
12
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
12
13
|
try {
|
|
13
14
|
checkCancelled();
|
|
14
15
|
const token = this.getAuthState() === AuthState.AUTHENTICATED
|
|
@@ -102,7 +103,7 @@ AvroQueryClient.prototype._xhr = async function (method, path, body, cancelToken
|
|
|
102
103
|
throw new StandardError(401, 'Unauthorized (refresh failed)');
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
|
-
if (error.status === 401 || attempt >=
|
|
106
|
+
if (error.status === 401 || attempt >= maxRetries) {
|
|
106
107
|
console.error('Not retrying request, throwing error.');
|
|
107
108
|
throw error;
|
|
108
109
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { keepPreviousData, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
4
|
+
const useDebouncedValue = (value, delayMs) => {
|
|
5
|
+
const [debounced, setDebounced] = useState(value);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const handle = setTimeout(() => setDebounced(value), delayMs);
|
|
8
|
+
return () => clearTimeout(handle);
|
|
9
|
+
}, [value, delayMs]);
|
|
10
|
+
return debounced;
|
|
11
|
+
};
|
|
12
|
+
AvroQueryClient.prototype.useAutocompleteAddress = function (address, { size = 10, minLength = 3, debounceMs = 500, includeCensus = true, } = {}) {
|
|
13
|
+
const trimmed = address.trim();
|
|
14
|
+
const debouncedAddress = useDebouncedValue(trimmed, debounceMs);
|
|
15
|
+
return useQuery({
|
|
16
|
+
queryKey: ['address', 'autocomplete', debouncedAddress, size, includeCensus],
|
|
17
|
+
queryFn: () => this.autocompleteAddress({
|
|
18
|
+
address: debouncedAddress,
|
|
19
|
+
size,
|
|
20
|
+
include_census: includeCensus,
|
|
21
|
+
}),
|
|
22
|
+
// Gate on the live value too so clearing the input stops the
|
|
23
|
+
// debounced fetch from firing.
|
|
24
|
+
enabled: trimmed.length >= minLength && debouncedAddress.length >= minLength,
|
|
25
|
+
placeholderData: keepPreviousData,
|
|
26
|
+
staleTime: 5 * 60 * 1000,
|
|
27
|
+
retry: false,
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
AvroQueryClient.prototype.useSearchAddress = function (address, { focusPointLatitude, focusPointLongitude, minLength = 3, debounceMs = 500, } = {}) {
|
|
31
|
+
const trimmed = address.trim();
|
|
32
|
+
const debouncedAddress = useDebouncedValue(trimmed, debounceMs);
|
|
33
|
+
return useQuery({
|
|
34
|
+
queryKey: ['address', 'search', debouncedAddress, focusPointLatitude, focusPointLongitude],
|
|
35
|
+
queryFn: () => this.searchAddress({
|
|
36
|
+
address: debouncedAddress,
|
|
37
|
+
focus_point_latitude: focusPointLatitude,
|
|
38
|
+
focus_point_longitude: focusPointLongitude,
|
|
39
|
+
}),
|
|
40
|
+
enabled: trimmed.length >= minLength && debouncedAddress.length >= minLength,
|
|
41
|
+
placeholderData: keepPreviousData,
|
|
42
|
+
staleTime: 5 * 60 * 1000,
|
|
43
|
+
retry: false,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
@@ -4,7 +4,12 @@ import { Route } from '../../types/api';
|
|
|
4
4
|
const dedupeJobTasks = (payload) => payload.jobs
|
|
5
5
|
? {
|
|
6
6
|
...payload,
|
|
7
|
-
jobs: payload.jobs.map((job) => job.tasks
|
|
7
|
+
jobs: payload.jobs.map((job) => job.tasks
|
|
8
|
+
? {
|
|
9
|
+
...job,
|
|
10
|
+
tasks: job.tasks.filter((task, index, all) => all.findIndex((t) => t.id === task.id) === index),
|
|
11
|
+
}
|
|
12
|
+
: job),
|
|
8
13
|
}
|
|
9
14
|
: payload;
|
|
10
15
|
AvroQueryClient.prototype.useGetRoutes = function (body, total, onProgress) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ReverseGeocodeResult {
|
|
2
|
+
address: string;
|
|
3
|
+
suggestedName: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Reverse-geocode a coordinate pair via OSM Nominatim. Throws when the
|
|
7
|
+
* lookup fails or returns no result — callers decide the fallback.
|
|
8
|
+
*/
|
|
9
|
+
export declare const reverseGeocode: (lat: number, lng: number) => Promise<ReverseGeocodeResult>;
|
package/dist/geocode.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reverse-geocode a coordinate pair via OSM Nominatim. Throws when the
|
|
3
|
+
* lookup fails or returns no result — callers decide the fallback.
|
|
4
|
+
*/
|
|
5
|
+
export const reverseGeocode = async (lat, lng) => {
|
|
6
|
+
const res = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lng}&format=json&addressdetails=1`);
|
|
7
|
+
if (!res.ok) {
|
|
8
|
+
throw new Error(`Reverse geocode failed: ${res.status}`);
|
|
9
|
+
}
|
|
10
|
+
const data = (await res.json());
|
|
11
|
+
if (!data?.display_name) {
|
|
12
|
+
throw new Error('Reverse geocode returned no result');
|
|
13
|
+
}
|
|
14
|
+
const addr = data.address || {};
|
|
15
|
+
const street = [addr.house_number, addr.road].filter(Boolean).join(' ').trim();
|
|
16
|
+
const city = addr.city || addr.town || addr.village || addr.hamlet;
|
|
17
|
+
const state = addr.state;
|
|
18
|
+
const postcode = addr.postcode;
|
|
19
|
+
const shortAddress = [street, city, state, postcode].filter(Boolean).join(', ');
|
|
20
|
+
const primary = street || city || data.display_name.split(',')[0]?.trim();
|
|
21
|
+
return {
|
|
22
|
+
address: shortAddress || data.display_name,
|
|
23
|
+
suggestedName: primary || data.display_name,
|
|
24
|
+
};
|
|
25
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { MemoryStorage, LocalStorage } from './auth/storage';
|
|
|
8
8
|
import './client/core/xhr';
|
|
9
9
|
import './client/core/fetch';
|
|
10
10
|
import './client/core/utils';
|
|
11
|
+
import './client/hooks/address';
|
|
11
12
|
import './client/hooks/root';
|
|
12
13
|
import './client/hooks/jobs';
|
|
13
14
|
import './client/hooks/routes';
|
|
@@ -35,6 +36,9 @@ import './client/hooks/timecards';
|
|
|
35
36
|
import './client/hooks/waivers';
|
|
36
37
|
import './client/hooks/email';
|
|
37
38
|
export { defaultPassOnFeeMethod } from './billing/fees';
|
|
39
|
+
export { reverseGeocode } from './geocode';
|
|
40
|
+
export { fetchCensusFeatures } from './census';
|
|
41
|
+
export type { ReverseGeocodeResult } from './geocode';
|
|
38
42
|
export * from './types/api';
|
|
39
43
|
export * from './types/auth';
|
|
40
44
|
export * from './types/cache';
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { MemoryStorage, LocalStorage } from './auth/storage';
|
|
|
6
6
|
import './client/core/xhr';
|
|
7
7
|
import './client/core/fetch';
|
|
8
8
|
import './client/core/utils';
|
|
9
|
+
import './client/hooks/address';
|
|
9
10
|
import './client/hooks/root';
|
|
10
11
|
import './client/hooks/jobs';
|
|
11
12
|
import './client/hooks/routes';
|
|
@@ -33,6 +34,8 @@ import './client/hooks/timecards';
|
|
|
33
34
|
import './client/hooks/waivers';
|
|
34
35
|
import './client/hooks/email';
|
|
35
36
|
export { defaultPassOnFeeMethod } from './billing/fees';
|
|
37
|
+
export { reverseGeocode } from './geocode';
|
|
38
|
+
export { fetchCensusFeatures } from './census';
|
|
36
39
|
export * from './types/api';
|
|
37
40
|
export * from './types/auth';
|
|
38
41
|
export * from './types/cache';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single address suggestion, as returned by the backend's
|
|
3
|
+
* /address/autocomplete and /address/search endpoints (Pelias GeoJSON,
|
|
4
|
+
* optionally merged with US Census geocoder matches server-side).
|
|
5
|
+
*/
|
|
6
|
+
export interface AddressFeature {
|
|
7
|
+
type: 'Feature';
|
|
8
|
+
geometry: {
|
|
9
|
+
type: 'Point';
|
|
10
|
+
/** GeoJSON order: [longitude, latitude]. */
|
|
11
|
+
coordinates: [number, number];
|
|
12
|
+
};
|
|
13
|
+
properties: {
|
|
14
|
+
label: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
id?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface AddressFeatureCollection {
|
|
20
|
+
type: 'FeatureCollection';
|
|
21
|
+
features: AddressFeature[];
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/api/Job.js
CHANGED
|
@@ -28,7 +28,7 @@ export class Job {
|
|
|
28
28
|
*/
|
|
29
29
|
this.getServiceDuration = (routeJob) => {
|
|
30
30
|
return routeJob.tasks
|
|
31
|
-
.map((
|
|
31
|
+
.map((rt) => this.tasks.find((t) => t.id === rt.id)?.service ?? 0)
|
|
32
32
|
.reduce((a, b) => a + b, 0);
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
@@ -50,7 +50,7 @@ export class Job {
|
|
|
50
50
|
if (!routeJob) {
|
|
51
51
|
return 0;
|
|
52
52
|
}
|
|
53
|
-
const contextTasks = this.tasks.filter((t) => !t.id || routeJob.tasks.
|
|
53
|
+
const contextTasks = this.tasks.filter((t) => !t.id || routeJob.tasks.some((rt) => rt.id === t.id));
|
|
54
54
|
if (contextTasks.length === 0) {
|
|
55
55
|
return 0;
|
|
56
56
|
}
|
|
@@ -7,16 +7,14 @@ declare module '../../types/api/RouteJob' {
|
|
|
7
7
|
order: number;
|
|
8
8
|
estimated_arrival_time: number;
|
|
9
9
|
scheduled_arrival_time: number;
|
|
10
|
-
tasks:
|
|
10
|
+
tasks: RouteJobTask[];
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
export interface RouteJobTask {
|
|
14
|
+
id: string;
|
|
15
|
+
depends_on: string[];
|
|
16
|
+
}
|
|
13
17
|
export declare class RouteJob {
|
|
14
18
|
constructor(init?: Partial<RouteJob>);
|
|
15
|
-
/**
|
|
16
|
-
* Returns the arrival time the UI should show for this stop:
|
|
17
|
-
* `scheduled_arrival_time` if set (>= 0), otherwise the optimizer's
|
|
18
|
-
* `estimated_arrival_time`. The sentinel value -1 means "no manual
|
|
19
|
-
* schedule, fall back to the optimizer estimate".
|
|
20
|
-
*/
|
|
21
19
|
getPredictedArrival: () => number;
|
|
22
20
|
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
export class RouteJob {
|
|
2
2
|
constructor(init) {
|
|
3
|
-
/**
|
|
4
|
-
* Returns the arrival time the UI should show for this stop:
|
|
5
|
-
* `scheduled_arrival_time` if set (>= 0), otherwise the optimizer's
|
|
6
|
-
* `estimated_arrival_time`. The sentinel value -1 means "no manual
|
|
7
|
-
* schedule, fall back to the optimizer estimate".
|
|
8
|
-
*/
|
|
9
3
|
this.getPredictedArrival = () => {
|
|
10
4
|
return this.scheduled_arrival_time === -1
|
|
11
5
|
? this.estimated_arrival_time
|
|
12
6
|
: this.scheduled_arrival_time;
|
|
13
7
|
};
|
|
14
8
|
Object.assign(this, init);
|
|
9
|
+
this.tasks = (init?.tasks ?? []).map((t) => typeof t === 'string'
|
|
10
|
+
? { id: t, depends_on: [] }
|
|
11
|
+
: { ...t, depends_on: t.depends_on ?? [] });
|
|
15
12
|
}
|
|
16
13
|
}
|
package/dist/types/api.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { _Event } from '../types/api/_Event';
|
|
|
3
3
|
import { Route } from '../types/api/Route';
|
|
4
4
|
export * from '../types/api/_Event';
|
|
5
5
|
export * from '../types/api/AdditionalCharge';
|
|
6
|
+
export * from '../types/api/Address';
|
|
6
7
|
export * from '../types/api/Avro';
|
|
7
8
|
export * from '../types/api/Bill';
|
|
8
9
|
export * from '../types/api/BillPayment';
|
|
@@ -86,7 +87,10 @@ export type RouteScheduleConfig = {
|
|
|
86
87
|
schedules: TeamSchedule[];
|
|
87
88
|
whitelist: string[];
|
|
88
89
|
blacklist: string[];
|
|
89
|
-
tasks:
|
|
90
|
+
tasks: {
|
|
91
|
+
task: string;
|
|
92
|
+
depends_on: string[];
|
|
93
|
+
}[];
|
|
90
94
|
};
|
|
91
95
|
export interface Location {
|
|
92
96
|
accuracy: number;
|
package/dist/types/api.js
CHANGED
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.79";
|
package/dist/version.js
CHANGED