@go-avro/avro-js 0.1.15 → 1.6.1-rc1
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/auth/AuthManager.d.ts +32 -0
- package/dist/auth/AuthManager.js +138 -43
- package/dist/client/QueryClient.d.ts +68 -2
- package/dist/client/QueryClient.js +310 -96
- package/dist/client/cache.d.ts +24 -0
- package/dist/client/cache.js +51 -0
- package/dist/client/core/fetch.js +58 -49
- package/dist/client/core/policy.d.ts +17 -0
- package/dist/client/core/policy.js +35 -0
- package/dist/client/core/xhr.js +16 -14
- package/dist/client/hooks/bills.js +10 -14
- package/dist/client/hooks/catalog_items.js +18 -8
- package/dist/client/hooks/chats.js +2 -8
- package/dist/client/hooks/companies.js +11 -5
- package/dist/client/hooks/events.js +56 -47
- package/dist/client/hooks/groups.js +11 -26
- package/dist/client/hooks/jobs.js +3 -8
- package/dist/client/hooks/labels.js +11 -26
- package/dist/client/hooks/messages.js +21 -24
- package/dist/client/hooks/months.js +28 -22
- package/dist/client/hooks/payouts.js +3 -8
- package/dist/client/hooks/prepayments.js +28 -22
- package/dist/client/hooks/proposal.js +1 -0
- package/dist/client/hooks/routes.js +8 -6
- package/dist/client/hooks/sessions.js +21 -31
- package/dist/client/hooks/skills.js +6 -4
- package/dist/client/hooks/teams.js +6 -4
- package/dist/client/hooks/timecards.js +7 -7
- package/dist/client/hooks/waivers.js +6 -4
- package/dist/client/persist.js +21 -2
- package/dist/client/realtime.d.ts +21 -1
- package/dist/client/realtime.js +183 -51
- package/dist/types/api/Bill.js +2 -1
- package/dist/types/api/Company.d.ts +2 -0
- package/dist/types/api/Email.d.ts +3 -9
- package/dist/types/api/EmailNotification.d.ts +1 -1
- package/dist/types/api/Job.js +8 -4
- package/dist/types/api/LineItem.d.ts +4 -0
- package/dist/types/api/LineItem.js +10 -2
- package/dist/types/api/Prepayment.js +2 -1
- package/dist/types/api/Route.js +2 -1
- package/dist/types/api/RouteJob.js +2 -1
- package/dist/types/api/Session.js +2 -1
- package/dist/types/api/Task.d.ts +27 -2
- package/dist/types/api/Task.js +44 -8
- package/dist/types/api/_Event.js +2 -1
- package/dist/types/api/assignData.d.ts +9 -0
- package/dist/types/api/assignData.js +17 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -2
package/dist/types/api/Task.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assignData } from './assignData.js';
|
|
1
2
|
import { Prepayment } from './Prepayment.js';
|
|
2
3
|
export const TaskStatus = {
|
|
3
4
|
PENDING_CUSTOMER: 'PENDING_CUSTOMER',
|
|
@@ -39,6 +40,32 @@ export const UNROUTED_REASON_LABELS = {
|
|
|
39
40
|
* A plain function so it works on spread copies of a Task too.
|
|
40
41
|
*/
|
|
41
42
|
export const getTaskDelayUntil = (task, now = Date.now() / 1000) => (task.delay_until != null && task.delay_until > now ? task.delay_until : null);
|
|
43
|
+
export const getTaskOverdueTime = (task, now = Date.now() / 1000) => {
|
|
44
|
+
if (task.overdue_time == null)
|
|
45
|
+
return 0;
|
|
46
|
+
const at = task.overdue_at ?? now;
|
|
47
|
+
let time = task.overdue_time + Math.max(now - at, 0);
|
|
48
|
+
// The snapshot subtracted a delay that has since lapsed.
|
|
49
|
+
if (task.delay_until != null && task.delay_until > at && task.delay_until <= now) {
|
|
50
|
+
time += task.delay ?? 0;
|
|
51
|
+
}
|
|
52
|
+
return time;
|
|
53
|
+
};
|
|
54
|
+
/** The backend's overdueness formula, evaluated at `now`. */
|
|
55
|
+
export const getTaskOverdueness = (task, now = Date.now() / 1000) => {
|
|
56
|
+
if (task.overdueness == null || task.status !== TaskStatus.ACTIVE) {
|
|
57
|
+
return task.overdueness ?? null;
|
|
58
|
+
}
|
|
59
|
+
const overdueTime = getTaskOverdueTime(task, now);
|
|
60
|
+
if (task.frequency && task.frequency > 0) {
|
|
61
|
+
// overdue_time counts from the due date; overdueness from the
|
|
62
|
+
// last service, one period earlier.
|
|
63
|
+
const scalar = task.priority ? 3 : 1;
|
|
64
|
+
const ratio = Math.max((overdueTime + task.frequency) / task.frequency, 0.01);
|
|
65
|
+
return Math.min(ratio * scalar, task.priority ? 10 : 3);
|
|
66
|
+
}
|
|
67
|
+
return overdueTime / (86400 * (task.priority ? 1 : 7));
|
|
68
|
+
};
|
|
42
69
|
export class Task {
|
|
43
70
|
constructor(init) {
|
|
44
71
|
this.getStatusLabel = () => {
|
|
@@ -66,23 +93,28 @@ export class Task {
|
|
|
66
93
|
return null;
|
|
67
94
|
return UNROUTED_REASON_LABELS[this.last_unrouted_reason] ?? this.last_unrouted_reason;
|
|
68
95
|
};
|
|
69
|
-
|
|
96
|
+
/** Seconds overdue right now (negative: due in that many seconds). */
|
|
97
|
+
this.getOverdueTime = (now) => getTaskOverdueTime(this, now);
|
|
98
|
+
/** Overdueness right now; null when the server reported none. */
|
|
99
|
+
this.getOverdueness = (now) => getTaskOverdueness(this, now);
|
|
100
|
+
this.isOverdue = (now) => {
|
|
70
101
|
return (this.status === TaskStatus.ACTIVE &&
|
|
71
102
|
this.overdue_time !== undefined &&
|
|
72
|
-
this.
|
|
103
|
+
this.getOverdueTime(now) > 0);
|
|
73
104
|
};
|
|
74
|
-
this.getOverdueLabel = () => {
|
|
105
|
+
this.getOverdueLabel = (now) => {
|
|
106
|
+
const overdueTime = this.getOverdueTime(now);
|
|
75
107
|
if (this.overdueness === null || this.status !== TaskStatus.ACTIVE) {
|
|
76
108
|
return this.getStatusLabel();
|
|
77
109
|
}
|
|
78
|
-
else if (
|
|
79
|
-
return `In ${Math.abs(Math.round(
|
|
110
|
+
else if (overdueTime <= 0) {
|
|
111
|
+
return `In ${Math.abs(Math.round(overdueTime / 86400))}d`;
|
|
80
112
|
}
|
|
81
|
-
else if (
|
|
113
|
+
else if (overdueTime < 86400) {
|
|
82
114
|
return '< 1d overdue';
|
|
83
115
|
}
|
|
84
116
|
else {
|
|
85
|
-
return `${Math.floor(
|
|
117
|
+
return `${Math.floor(overdueTime / 86400)}d overdue`;
|
|
86
118
|
}
|
|
87
119
|
};
|
|
88
120
|
/** End (epoch seconds) of this task's delay if it's still in effect. */
|
|
@@ -153,7 +185,11 @@ export class Task {
|
|
|
153
185
|
const cutoff = Math.floor(routeDay.getTime() / 1000);
|
|
154
186
|
return (this.last_completed_event?.time_ended ?? 0) >= cutoff;
|
|
155
187
|
};
|
|
156
|
-
|
|
188
|
+
assignData(this, init);
|
|
189
|
+
// Payloads from the server carry no timestamp: they were computed
|
|
190
|
+
// just now. Copies keep the one they were made with.
|
|
191
|
+
if (this.overdue_at == null)
|
|
192
|
+
this.overdue_at = Date.now() / 1000;
|
|
157
193
|
if (init?.prepayments) {
|
|
158
194
|
this.prepayments = init.prepayments.map((p) => new Prepayment(p));
|
|
159
195
|
}
|
package/dist/types/api/_Event.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assignData } from './assignData.js';
|
|
1
2
|
import { LineItem } from './LineItem.js';
|
|
2
3
|
export class _Event extends LineItem {
|
|
3
4
|
constructor(init) {
|
|
@@ -6,7 +7,7 @@ export class _Event extends LineItem {
|
|
|
6
7
|
const additionalChargesCost = this.additional_charges.reduce((acc, charge) => acc + (charge.cost ?? 0) * (charge.amount ?? 0), 0);
|
|
7
8
|
return this.cost * this.amount + additionalChargesCost;
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
+
assignData(this, init);
|
|
10
11
|
this.breaks = init?.breaks ?? [];
|
|
11
12
|
this.images = init?.images ?? [];
|
|
12
13
|
this.tasks = init?.tasks ?? [];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy an init object's data onto a model instance.
|
|
3
|
+
*
|
|
4
|
+
* Model methods are arrow-function class fields bound to their own
|
|
5
|
+
* instance. Rebuilding a model from a spread of another instance
|
|
6
|
+
* (`new Job({ ...job, ...updates })`) would otherwise copy the old
|
|
7
|
+
* instance's methods, which keep reading the old object.
|
|
8
|
+
*/
|
|
9
|
+
export declare function assignData<T extends object>(target: T, init?: Partial<T>): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy an init object's data onto a model instance.
|
|
3
|
+
*
|
|
4
|
+
* Model methods are arrow-function class fields bound to their own
|
|
5
|
+
* instance. Rebuilding a model from a spread of another instance
|
|
6
|
+
* (`new Job({ ...job, ...updates })`) would otherwise copy the old
|
|
7
|
+
* instance's methods, which keep reading the old object.
|
|
8
|
+
*/
|
|
9
|
+
export function assignData(target, init) {
|
|
10
|
+
if (!init)
|
|
11
|
+
return;
|
|
12
|
+
for (const [key, value] of Object.entries(init)) {
|
|
13
|
+
if (typeof value === 'function')
|
|
14
|
+
continue;
|
|
15
|
+
target[key] = value;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AVRO_JS_VERSION = "
|
|
1
|
+
export declare const AVRO_JS_VERSION = "1.6.1-rc1";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@go-avro/avro-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.6.1-rc1",
|
|
4
4
|
"description": "JS client for Avro backend integration.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"license": "CC-BY-SA-4.0",
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@eslint/js": "^9.39.4",
|
|
39
|
+
"@tanstack/react-query": "^5.90.2",
|
|
39
40
|
"@types/react": "^19.2.2",
|
|
40
41
|
"@types/uuid": "^10.0.0",
|
|
41
42
|
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
|
@@ -46,10 +47,15 @@
|
|
|
46
47
|
"eslint-plugin-react": "^7.37.5",
|
|
47
48
|
"globals": "^17.6.0",
|
|
48
49
|
"prettier": "^3.8.3",
|
|
50
|
+
"react": "^19.0.0",
|
|
49
51
|
"tsc-alias": "^1.8.17",
|
|
50
52
|
"typescript": "^5.8.3",
|
|
51
53
|
"typescript-eslint": "^8.38.0"
|
|
52
54
|
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@tanstack/react-query": "^5.90.2",
|
|
57
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
58
|
+
},
|
|
53
59
|
"files": [
|
|
54
60
|
"dist"
|
|
55
61
|
],
|
|
@@ -57,7 +63,6 @@
|
|
|
57
63
|
"access": "public"
|
|
58
64
|
},
|
|
59
65
|
"dependencies": {
|
|
60
|
-
"@tanstack/react-query": "^5.90.2",
|
|
61
66
|
"socket.io-client": "^4.8.1",
|
|
62
67
|
"uuid": "^14.0.0"
|
|
63
68
|
}
|