@go-avro/avro-js 0.1.13 → 0.1.15
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.js +4 -1
- package/dist/client/hooks/events.js +10 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/serviceStatus.d.ts +7 -0
- package/dist/serviceStatus.js +11 -0
- package/dist/types/api/DelayEvent.d.ts +1 -1
- package/dist/types/api/Task.d.ts +20 -0
- package/dist/types/api/Task.js +11 -1
- package/dist/types/api.d.ts +3 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -632,12 +632,15 @@ export class AvroQueryClient {
|
|
|
632
632
|
}
|
|
633
633
|
const features = pelias.value?.features ?? [];
|
|
634
634
|
const knownLabels = new Set(features.map((feature) => feature.properties.label.toLowerCase()));
|
|
635
|
+
// Census only answers with exact geocodes of a complete address, so
|
|
636
|
+
// its matches lead; Pelias can fill the list with same-named streets
|
|
637
|
+
// elsewhere and bury the address the user actually typed.
|
|
635
638
|
return {
|
|
636
639
|
...pelias.value,
|
|
637
640
|
type: 'FeatureCollection',
|
|
638
641
|
features: [
|
|
639
|
-
...features,
|
|
640
642
|
...census.filter((feature) => !knownLabels.has(feature.properties.label.toLowerCase())),
|
|
643
|
+
...features,
|
|
641
644
|
],
|
|
642
645
|
};
|
|
643
646
|
}
|
|
@@ -154,8 +154,8 @@ AvroQueryClient.prototype.useCreateDelayEvent = function () {
|
|
|
154
154
|
cost: 0,
|
|
155
155
|
amount: 1,
|
|
156
156
|
});
|
|
157
|
-
//
|
|
158
|
-
//
|
|
157
|
+
// Mirror the server: each delayed task isn't due until the
|
|
158
|
+
// later of its own delay ends and this one does.
|
|
159
159
|
const previousJob = queryClient.getQueryData([
|
|
160
160
|
'jobs',
|
|
161
161
|
delayData.job_id,
|
|
@@ -165,11 +165,14 @@ AvroQueryClient.prototype.useCreateDelayEvent = function () {
|
|
|
165
165
|
...previousJob,
|
|
166
166
|
tasks: previousJob.tasks.map((task) => {
|
|
167
167
|
if (delayData.tasks.includes(task.id ?? '')) {
|
|
168
|
+
const delayUntil = Math.max(task.delay_until != null && task.delay_until > now
|
|
169
|
+
? task.delay_until
|
|
170
|
+
: 0, now + delayData.delay_seconds);
|
|
168
171
|
return {
|
|
169
172
|
...task,
|
|
170
|
-
|
|
173
|
+
delay_until: delayUntil,
|
|
171
174
|
overdue_time: task.overdue_time != null
|
|
172
|
-
? task.overdue_time -
|
|
175
|
+
? Math.min(task.overdue_time, now - delayUntil)
|
|
173
176
|
: task.overdue_time,
|
|
174
177
|
};
|
|
175
178
|
}
|
|
@@ -279,8 +282,10 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
279
282
|
? { ...previousEvent, ...updates }
|
|
280
283
|
: task.last_completed_event
|
|
281
284
|
: task.last_completed_event,
|
|
285
|
+
// Next due a period out, or when an active
|
|
286
|
+
// delay ends if that's later.
|
|
282
287
|
overdue_time: isEnding
|
|
283
|
-
? -(task.frequency ?? 0
|
|
288
|
+
? -Math.max(task.frequency ?? 0, (task.delay_until ?? 0) - Date.now() / 1000)
|
|
284
289
|
: task.overdue_time,
|
|
285
290
|
};
|
|
286
291
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ import './client/hooks/email.js';
|
|
|
43
43
|
export { defaultPassOnFeeMethod } from './billing/fees.js';
|
|
44
44
|
export { reverseGeocode } from './geocode.js';
|
|
45
45
|
export { fetchCensusFeatures } from './census.js';
|
|
46
|
+
export { getDegradedServices } from './serviceStatus.js';
|
|
46
47
|
export { LOCATION_STALE_MINUTES, LOCATION_RECENT_HOURS, isLocationRecent, REPORTING_STATUSES, locationAgeMinutes, isLocationStale, isReportingStatus, isMobileDevice, mobileDevices, userPresence, } from './presence.js';
|
|
47
48
|
export type { UserPresence } from './presence.js';
|
|
48
49
|
export type { ReverseGeocodeResult } from './geocode.js';
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,7 @@ import './client/hooks/email.js';
|
|
|
40
40
|
export { defaultPassOnFeeMethod } from './billing/fees.js';
|
|
41
41
|
export { reverseGeocode } from './geocode.js';
|
|
42
42
|
export { fetchCensusFeatures } from './census.js';
|
|
43
|
+
export { getDegradedServices } from './serviceStatus.js';
|
|
43
44
|
export { LOCATION_STALE_MINUTES, LOCATION_RECENT_HOURS, isLocationRecent, REPORTING_STATUSES, locationAgeMinutes, isLocationStale, isReportingStatus, isMobileDevice, mobileDevices, userPresence, } from './presence.js';
|
|
44
45
|
export * from './types/api.js';
|
|
45
46
|
export * from './types/auth.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiInfo } from './types/api.js';
|
|
2
|
+
/**
|
|
3
|
+
* Display names of the core services the API root reports as anything
|
|
4
|
+
* but ready. A missing `apiInfo` (the root request failed) reports every
|
|
5
|
+
* service, since none of them can be confirmed up.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getDegradedServices: (apiInfo: ApiInfo | undefined) => string[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Display names of the core services the API root reports as anything
|
|
3
|
+
* but ready. A missing `apiInfo` (the root request failed) reports every
|
|
4
|
+
* service, since none of them can be confirmed up.
|
|
5
|
+
*/
|
|
6
|
+
export const getDegradedServices = (apiInfo) => [
|
|
7
|
+
apiInfo?.db_status !== 'ready' && 'Database',
|
|
8
|
+
apiInfo?.pelias_status !== 'ready' && 'Geocoding',
|
|
9
|
+
apiInfo?.vroom_status !== 'ready' && 'Optimization',
|
|
10
|
+
apiInfo?.ors_status !== 'ready' && 'Routing',
|
|
11
|
+
].filter((s) => Boolean(s));
|
|
@@ -2,7 +2,7 @@ import { _Event } from './_Event.js';
|
|
|
2
2
|
declare module './DelayEvent.js' {
|
|
3
3
|
interface DelayEvent extends _Event {
|
|
4
4
|
line_item_type: 'DELAY';
|
|
5
|
-
/** Seconds this delay
|
|
5
|
+
/** Seconds after it was logged that this delay holds its tasks off. */
|
|
6
6
|
delay_seconds: number;
|
|
7
7
|
}
|
|
8
8
|
}
|
package/dist/types/api/Task.d.ts
CHANGED
|
@@ -49,7 +49,17 @@ declare module './Task.js' {
|
|
|
49
49
|
overdue_time: number;
|
|
50
50
|
last_completed_event: _Event | null;
|
|
51
51
|
current_event: _Event | null;
|
|
52
|
+
/**
|
|
53
|
+
* Seconds the due date was pushed back when the server serialized
|
|
54
|
+
* this task. Goes stale in cached responses; prefer `getDelayUntil()`.
|
|
55
|
+
*/
|
|
52
56
|
delay: number;
|
|
57
|
+
/**
|
|
58
|
+
* When (epoch seconds) the latest delay on this task ends, or null.
|
|
59
|
+
* A delay only holds until then; compare against the clock with
|
|
60
|
+
* `getDelayUntil()`.
|
|
61
|
+
*/
|
|
62
|
+
delay_until: number | null;
|
|
53
63
|
skills: string[];
|
|
54
64
|
service: number;
|
|
55
65
|
bill_mode: 'MONTH' | 'SERVICE' | 'NONE';
|
|
@@ -67,12 +77,22 @@ declare module './Task.js' {
|
|
|
67
77
|
route_ids: string[];
|
|
68
78
|
}
|
|
69
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* End (epoch seconds) of a task's delay if it's still in effect, else null.
|
|
82
|
+
* A plain function so it works on spread copies of a Task too.
|
|
83
|
+
*/
|
|
84
|
+
export declare const getTaskDelayUntil: (task: {
|
|
85
|
+
delay_until?: number | null;
|
|
86
|
+
}, now?: number) => number | null;
|
|
70
87
|
export declare class Task {
|
|
71
88
|
constructor(init?: Partial<Task>);
|
|
72
89
|
getStatusLabel: () => "Active" | "Archived" | "Pending Activation" | "Draft" | "Pending Customer Approval" | "Pending Company Approval" | "Pending Payment";
|
|
73
90
|
getUnroutedReasonLabel: () => string | null;
|
|
74
91
|
isOverdue: () => boolean;
|
|
75
92
|
getOverdueLabel: () => string;
|
|
93
|
+
/** End (epoch seconds) of this task's delay if it's still in effect. */
|
|
94
|
+
getDelayUntil: (now?: number) => number | null;
|
|
95
|
+
isDelayed: (now?: number) => boolean;
|
|
76
96
|
getNextDue: () => number | null;
|
|
77
97
|
computeNextTaskState: (isCustomer: boolean, action: "accept" | "modify" | "reject") => TaskStatus;
|
|
78
98
|
getPrepaidEventsRemaining: () => number;
|
package/dist/types/api/Task.js
CHANGED
|
@@ -34,6 +34,11 @@ export const UNROUTED_REASON_LABELS = {
|
|
|
34
34
|
MANDATORY_UNSERVED: 'Far past due and forced onto the day, but the day could not hold it',
|
|
35
35
|
DID_NOT_FIT: 'Did not fit any schedule',
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* End (epoch seconds) of a task's delay if it's still in effect, else null.
|
|
39
|
+
* A plain function so it works on spread copies of a Task too.
|
|
40
|
+
*/
|
|
41
|
+
export const getTaskDelayUntil = (task, now = Date.now() / 1000) => (task.delay_until != null && task.delay_until > now ? task.delay_until : null);
|
|
37
42
|
export class Task {
|
|
38
43
|
constructor(init) {
|
|
39
44
|
this.getStatusLabel = () => {
|
|
@@ -80,10 +85,15 @@ export class Task {
|
|
|
80
85
|
return `${Math.floor(this.overdue_time / 86400)}d overdue`;
|
|
81
86
|
}
|
|
82
87
|
};
|
|
88
|
+
/** End (epoch seconds) of this task's delay if it's still in effect. */
|
|
89
|
+
this.getDelayUntil = (now) => getTaskDelayUntil(this, now);
|
|
90
|
+
this.isDelayed = (now) => this.getDelayUntil(now) !== null;
|
|
83
91
|
this.getNextDue = () => {
|
|
84
92
|
if (this.frequency > 0 && this.status === TaskStatus.ACTIVE) {
|
|
85
93
|
const lastEventTime = this.last_completed_event?.time_ended ?? this.activate_on ?? this.time_created;
|
|
86
|
-
|
|
94
|
+
const due = lastEventTime + this.frequency;
|
|
95
|
+
// A delay holds the task off until it ends, then lapses.
|
|
96
|
+
return Math.max(due, this.getDelayUntil() ?? due);
|
|
87
97
|
}
|
|
88
98
|
return null;
|
|
89
99
|
};
|
package/dist/types/api.d.ts
CHANGED
|
@@ -225,9 +225,9 @@ export type EventUpdatePayload = Partial<Omit<_Event, 'users'>> & {
|
|
|
225
225
|
/**
|
|
226
226
|
* Wire payload for logging a delay (POST /job/{job_id}/delay).
|
|
227
227
|
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
228
|
+
* Each task in `tasks` (and only those) isn't due until
|
|
229
|
+
* `delay_seconds` from now; after that the delay lapses on its own.
|
|
230
|
+
* Overlapping delays don't add up — the latest end wins.
|
|
231
231
|
*/
|
|
232
232
|
export interface DelayEventCreatePayload {
|
|
233
233
|
job_id: string;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AVRO_JS_VERSION = "0.1.
|
|
1
|
+
export declare const AVRO_JS_VERSION = "0.1.15";
|
package/dist/version.js
CHANGED