@go-avro/avro-js 0.0.78 → 0.0.80
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 +2 -1
- package/dist/client/QueryClient.js +6 -2
- package/dist/client/core/fetch.js +3 -1
- package/dist/client/core/xhr.js +4 -3
- package/dist/client/hooks/address.js +2 -0
- package/dist/client/hooks/routes.js +6 -1
- 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/Task.d.ts +1 -0
- package/dist/types/api.d.ts +4 -1
- package/dist/types/error.d.ts +2 -1
- package/dist/types/error.js +2 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -659,12 +659,13 @@ export declare class AvroQueryClient {
|
|
|
659
659
|
headers?: Record<string, string>;
|
|
660
660
|
progressUpdateCallback?: (loaded: number, total: number) => void;
|
|
661
661
|
}): Promise<T>;
|
|
662
|
-
post<T>({ path, data, cancelToken, headers, progressUpdateCallback, }: {
|
|
662
|
+
post<T>({ path, data, cancelToken, headers, progressUpdateCallback, maxRetries, }: {
|
|
663
663
|
path: string;
|
|
664
664
|
data?: any;
|
|
665
665
|
cancelToken?: CancelToken;
|
|
666
666
|
headers?: Record<string, string>;
|
|
667
667
|
progressUpdateCallback?: (loaded: number, total: number) => void;
|
|
668
|
+
maxRetries?: number;
|
|
668
669
|
}): Promise<T>;
|
|
669
670
|
put<T>({ path, data, cancelToken, headers, progressUpdateCallback, }: {
|
|
670
671
|
path: string;
|
|
@@ -565,8 +565,8 @@ export class AvroQueryClient {
|
|
|
565
565
|
get({ path, cancelToken, headers, progressUpdateCallback, }) {
|
|
566
566
|
return this._xhr('GET', path, null, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
|
|
567
567
|
}
|
|
568
|
-
post({ path, data, cancelToken, headers, progressUpdateCallback, }) {
|
|
569
|
-
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);
|
|
570
570
|
}
|
|
571
571
|
put({ path, data, cancelToken, headers, progressUpdateCallback, }) {
|
|
572
572
|
return this._xhr('PUT', path, data, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
|
|
@@ -930,6 +930,9 @@ export class AvroQueryClient {
|
|
|
930
930
|
...headers,
|
|
931
931
|
'Content-Type': 'application/json',
|
|
932
932
|
},
|
|
933
|
+
// Autocomplete is per-keystroke; retrying a down backend just
|
|
934
|
+
// multiplies the load. The next keystroke is the retry.
|
|
935
|
+
maxRetries: 0,
|
|
933
936
|
});
|
|
934
937
|
if (!include_census) {
|
|
935
938
|
return peliasPromise;
|
|
@@ -967,6 +970,7 @@ export class AvroQueryClient {
|
|
|
967
970
|
...headers,
|
|
968
971
|
'Content-Type': 'application/json',
|
|
969
972
|
},
|
|
973
|
+
maxRetries: 0,
|
|
970
974
|
});
|
|
971
975
|
}
|
|
972
976
|
fetchChats(body = {}, cancelToken, headers = {}) {
|
|
@@ -60,14 +60,16 @@ AvroQueryClient.prototype._fetch = async function (method, path, body, cancelTok
|
|
|
60
60
|
return this._fetch(method, path, body, cancelToken, headers, isIdempotent, retryCount + 1);
|
|
61
61
|
}
|
|
62
62
|
let errorMessage = response.statusText;
|
|
63
|
+
let errorBody;
|
|
63
64
|
try {
|
|
64
65
|
const parsedError = await response.json();
|
|
66
|
+
errorBody = parsedError;
|
|
65
67
|
errorMessage = parsedError.message ?? parsedError.msg ?? errorMessage;
|
|
66
68
|
}
|
|
67
69
|
catch (e) {
|
|
68
70
|
console.error('Ignoring:', e);
|
|
69
71
|
}
|
|
70
|
-
throw new StandardError(response.status, errorMessage);
|
|
72
|
+
throw new StandardError(response.status, errorMessage, errorBody);
|
|
71
73
|
}
|
|
72
74
|
catch (error) {
|
|
73
75
|
if (error instanceof StandardError) {
|
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
|
}
|
|
@@ -24,6 +24,7 @@ AvroQueryClient.prototype.useAutocompleteAddress = function (address, { size = 1
|
|
|
24
24
|
enabled: trimmed.length >= minLength && debouncedAddress.length >= minLength,
|
|
25
25
|
placeholderData: keepPreviousData,
|
|
26
26
|
staleTime: 5 * 60 * 1000,
|
|
27
|
+
retry: false,
|
|
27
28
|
});
|
|
28
29
|
};
|
|
29
30
|
AvroQueryClient.prototype.useSearchAddress = function (address, { focusPointLatitude, focusPointLongitude, minLength = 3, debounceMs = 500, } = {}) {
|
|
@@ -39,5 +40,6 @@ AvroQueryClient.prototype.useSearchAddress = function (address, { focusPointLati
|
|
|
39
40
|
enabled: trimmed.length >= minLength && debouncedAddress.length >= minLength,
|
|
40
41
|
placeholderData: keepPreviousData,
|
|
41
42
|
staleTime: 5 * 60 * 1000,
|
|
43
|
+
retry: false,
|
|
42
44
|
});
|
|
43
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) {
|
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/Task.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ declare module '../../types/api/Task' {
|
|
|
40
40
|
bill_mode: 'MONTH' | 'SERVICE' | 'NONE';
|
|
41
41
|
autobill: boolean;
|
|
42
42
|
price: number;
|
|
43
|
+
last_unrouted_reason: 'NOT_DUE' | 'DEPENDENCY_UNMET' | 'MISSING_SKILLS' | 'OVER_CAPACITY' | 'TRAVEL_TIME' | 'LOW_PRIORITY' | 'DID_NOT_FIT' | null;
|
|
43
44
|
services_remaining: number;
|
|
44
45
|
activate_on: number | null;
|
|
45
46
|
expire_on: number | null;
|
package/dist/types/api.d.ts
CHANGED
|
@@ -87,7 +87,10 @@ export type RouteScheduleConfig = {
|
|
|
87
87
|
schedules: TeamSchedule[];
|
|
88
88
|
whitelist: string[];
|
|
89
89
|
blacklist: string[];
|
|
90
|
-
tasks:
|
|
90
|
+
tasks: {
|
|
91
|
+
task: string;
|
|
92
|
+
depends_on: string[];
|
|
93
|
+
}[];
|
|
91
94
|
};
|
|
92
95
|
export interface Location {
|
|
93
96
|
accuracy: number;
|
package/dist/types/error.d.ts
CHANGED
package/dist/types/error.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.80";
|
package/dist/version.js
CHANGED