@go-avro/avro-js 1.6.6-rc9 → 1.7.0
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/chat.d.ts +25 -0
- package/dist/chat.js +47 -0
- package/dist/client/QueryClient.d.ts +108 -26
- package/dist/client/QueryClient.js +103 -59
- package/dist/client/cache.d.ts +4 -0
- package/dist/client/cache.js +19 -0
- package/dist/client/core/uploads.js +226 -0
- package/dist/client/hooks/bills.js +15 -13
- package/dist/client/hooks/catalog_items.js +16 -4
- package/dist/client/hooks/chats.js +26 -0
- package/dist/client/hooks/devices.js +17 -3
- package/dist/client/hooks/messages.js +54 -1
- package/dist/client/hooks/routes.js +4 -1
- package/dist/client/hooks/teams.js +4 -1
- package/dist/client/hooks/{proposal_terms.js → terms.js} +14 -14
- package/dist/client/realtime.d.ts +26 -3
- package/dist/client/realtime.js +93 -16
- package/dist/client/requests.d.ts +7 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/types/api/AuditLog.d.ts +1 -1
- package/dist/types/api/Avro.d.ts +5 -0
- package/dist/types/api/CatalogItem.d.ts +3 -1
- package/dist/types/api/Company.d.ts +0 -2
- package/dist/types/api/Job.js +11 -2
- package/dist/types/api/MemberState.d.ts +3 -0
- package/dist/types/api/Notification.d.ts +39 -0
- package/dist/types/api/Proposal.d.ts +2 -2
- package/dist/types/api/Task.d.ts +16 -0
- package/dist/types/api/Task.js +30 -3
- package/dist/types/api/{ProposalTerms.d.ts → Terms.d.ts} +3 -3
- package/dist/types/api/Terms.js +1 -0
- package/dist/types/api.d.ts +1 -1
- package/dist/types/api.js +1 -1
- package/dist/types/client.d.ts +125 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- /package/dist/client/{hooks/proposal_terms.d.ts → core/uploads.d.ts} +0 -0
- /package/dist/{types/api/ProposalTerms.js → client/hooks/terms.d.ts} +0 -0
package/dist/client/realtime.js
CHANGED
|
@@ -29,6 +29,11 @@ export const VIEWER_SCOPE = 'mine';
|
|
|
29
29
|
export function listScope(key) {
|
|
30
30
|
return typeof key[2] === 'string' ? key[2] : '';
|
|
31
31
|
}
|
|
32
|
+
/** The signed-in user's id, from the cached self profile (`['user']`). */
|
|
33
|
+
function viewerIdOf(qc) {
|
|
34
|
+
const id = qc.getQueryData(['user'])?.id;
|
|
35
|
+
return typeof id === 'string' ? id : undefined;
|
|
36
|
+
}
|
|
32
37
|
function searchAware(filters) {
|
|
33
38
|
const q = filters.query;
|
|
34
39
|
return typeof q === 'string' && q.length > 0 ? 'unknown' : 'match';
|
|
@@ -72,6 +77,15 @@ function matchJobs(filters, item) {
|
|
|
72
77
|
}
|
|
73
78
|
return searchAware(filters);
|
|
74
79
|
}
|
|
80
|
+
function matchCatalogItems(filters, item) {
|
|
81
|
+
if (typeof filters.industry === 'string' && filters.industry !== item.industry) {
|
|
82
|
+
return 'nomatch';
|
|
83
|
+
}
|
|
84
|
+
if (typeof filters.archived === 'boolean' && filters.archived !== item.archived) {
|
|
85
|
+
return 'nomatch';
|
|
86
|
+
}
|
|
87
|
+
return searchAware(filters);
|
|
88
|
+
}
|
|
75
89
|
function isPaidStatus(status) {
|
|
76
90
|
return status === 'PAID' || status === 'PREPAID' || status === 'EXTERNALLY_PAID';
|
|
77
91
|
}
|
|
@@ -130,10 +144,15 @@ function matchBills(filters, item) {
|
|
|
130
144
|
return 'unknown';
|
|
131
145
|
return searchAware(filters);
|
|
132
146
|
}
|
|
133
|
-
function matchSessions(filters, item, scope) {
|
|
134
|
-
// "mine"
|
|
135
|
-
|
|
136
|
-
|
|
147
|
+
function matchSessions(filters, item, scope, viewerId) {
|
|
148
|
+
// "mine" is GET /session: the viewer's own open sessions. Without
|
|
149
|
+
// knowing the viewer, every session change in the company would
|
|
150
|
+
// refetch it on every client.
|
|
151
|
+
if (scope === VIEWER_SCOPE) {
|
|
152
|
+
if (!viewerId)
|
|
153
|
+
return 'unknown';
|
|
154
|
+
return item.user_id === viewerId && !item.time_ended ? 'match' : 'nomatch';
|
|
155
|
+
}
|
|
137
156
|
// `unknown_ids` on the sessions endpoint means "fetch exactly these".
|
|
138
157
|
const wanted = filters.unknown_ids;
|
|
139
158
|
if (Array.isArray(wanted) && wanted.length > 0) {
|
|
@@ -193,6 +212,8 @@ const ALL_LINE_ITEM_STATUSES = { unbilled: true, billed: true, paid: true };
|
|
|
193
212
|
/** Single-entity GET (404/403 is treated as gone by the applier). */
|
|
194
213
|
const getOne = (path) => (client, id) => client.get({ path: path(id) });
|
|
195
214
|
const COMPANY_EMBEDS = [['companies'], ['/company/list']];
|
|
215
|
+
/** Finance, bill, event and revenue aggregates all read line items and bills. */
|
|
216
|
+
const ANALYTICS = [['analytics']];
|
|
196
217
|
export const REGISTRY = {
|
|
197
218
|
job: {
|
|
198
219
|
ns: 'jobs',
|
|
@@ -205,6 +226,7 @@ export const REGISTRY = {
|
|
|
205
226
|
construct: constructEvent,
|
|
206
227
|
fetchMany: bulk('fetchEvents', ALL_LINE_ITEM_STATUSES),
|
|
207
228
|
listMatch: matchLineItems,
|
|
229
|
+
refreshThrottled: ANALYTICS,
|
|
208
230
|
},
|
|
209
231
|
route: {
|
|
210
232
|
ns: 'routes',
|
|
@@ -233,11 +255,10 @@ export const REGISTRY = {
|
|
|
233
255
|
listMatch: searchAware,
|
|
234
256
|
alsoInvalidate: COMPANY_EMBEDS,
|
|
235
257
|
},
|
|
236
|
-
// No single-item GET exists: catalog items only live on the company.
|
|
237
258
|
catalog_item: {
|
|
238
259
|
ns: 'catalog_items',
|
|
239
|
-
|
|
240
|
-
|
|
260
|
+
fetchMany: bulk('fetchCatalogItems'),
|
|
261
|
+
listMatch: matchCatalogItems,
|
|
241
262
|
},
|
|
242
263
|
proposal: {
|
|
243
264
|
ns: 'proposals',
|
|
@@ -245,32 +266,35 @@ export const REGISTRY = {
|
|
|
245
266
|
fetchOne: (client, id) => client.get({ path: `/proposal/${id}` }),
|
|
246
267
|
alsoInvalidate: [['tasks']],
|
|
247
268
|
},
|
|
248
|
-
|
|
249
|
-
ns: '
|
|
250
|
-
fetchOne: (client, id) => client.get({ path: `/
|
|
269
|
+
terms: {
|
|
270
|
+
ns: 'terms',
|
|
271
|
+
fetchOne: (client, id) => client.get({ path: `/terms/${id}` }),
|
|
251
272
|
},
|
|
252
273
|
month: {
|
|
253
274
|
ns: 'months',
|
|
254
275
|
fetchMany: bulk('fetchMonths', ALL_LINE_ITEM_STATUSES),
|
|
255
276
|
listMatch: matchLineItems,
|
|
277
|
+
refreshThrottled: ANALYTICS,
|
|
256
278
|
},
|
|
257
279
|
prepayment: {
|
|
258
280
|
ns: 'prepayments',
|
|
259
281
|
fetchMany: bulk('fetchPrepayments', ALL_LINE_ITEM_STATUSES),
|
|
260
282
|
listMatch: matchLineItems,
|
|
283
|
+
refreshThrottled: ANALYTICS,
|
|
261
284
|
},
|
|
262
285
|
bill: {
|
|
263
286
|
ns: 'bills',
|
|
264
287
|
construct: (d) => new Bill(d),
|
|
265
288
|
fetchMany: bulk('fetchBills'),
|
|
266
289
|
listMatch: matchBills,
|
|
290
|
+
refreshThrottled: ANALYTICS,
|
|
267
291
|
},
|
|
268
292
|
session: {
|
|
269
293
|
ns: 'sessions',
|
|
270
294
|
construct: (raw) => new Session(raw),
|
|
271
295
|
fetchMany: bulk('fetchSessions'),
|
|
272
296
|
listMatch: matchSessions,
|
|
273
|
-
|
|
297
|
+
refreshThrottled: [['analytics', 'sessions']],
|
|
274
298
|
},
|
|
275
299
|
checkin: { ns: 'checkins', listMatch: matchCheckins },
|
|
276
300
|
waiver: { ns: 'waivers', fetchMany: bulk('fetchWaivers'), listMatch: searchAware },
|
|
@@ -288,8 +312,10 @@ export const REGISTRY = {
|
|
|
288
312
|
alsoInvalidate: [['/company/list'], ['companies', 'current']],
|
|
289
313
|
},
|
|
290
314
|
member: { ns: 'members', invalidateOnly: true, alsoInvalidate: [['users', 'company']] },
|
|
315
|
+
// Sent to the user's own room only. Their rows in member lists
|
|
316
|
+
// refresh through the `member` changes sent alongside.
|
|
291
317
|
user: { ns: 'users', invalidateOnly: true, alsoInvalidate: [['user']] },
|
|
292
|
-
plan: { ns: 'plans', invalidateOnly: true },
|
|
318
|
+
plan: { ns: 'plans', invalidateOnly: true, refreshThrottled: ANALYTICS },
|
|
293
319
|
};
|
|
294
320
|
function mapList(data, fn) {
|
|
295
321
|
if (Array.isArray(data))
|
|
@@ -336,13 +362,14 @@ export function upsertEntity(qc, spec, item, company) {
|
|
|
336
362
|
const lists = qc
|
|
337
363
|
.getQueryCache()
|
|
338
364
|
.findAll({ predicate: (q) => q.queryKey[0] === spec.ns && isListKey(q.queryKey) });
|
|
365
|
+
const viewerId = viewerIdOf(qc);
|
|
339
366
|
for (const query of lists) {
|
|
340
367
|
const key = query.queryKey;
|
|
341
368
|
const scope = listScope(key);
|
|
342
369
|
if (company && scope && scope !== company && scope !== VIEWER_SCOPE)
|
|
343
370
|
continue;
|
|
344
371
|
const verdict = spec.listMatch
|
|
345
|
-
? spec.listMatch(listFilters(key), item,
|
|
372
|
+
? spec.listMatch(listFilters(key), item, scope, viewerId)
|
|
346
373
|
: searchAware(listFilters(key));
|
|
347
374
|
if (verdict === 'unknown') {
|
|
348
375
|
qc.invalidateQueries({ queryKey: key, exact: true });
|
|
@@ -361,12 +388,12 @@ export function upsertEntity(qc, spec, item, company) {
|
|
|
361
388
|
});
|
|
362
389
|
}
|
|
363
390
|
}
|
|
364
|
-
export function matchesList(type, key, item) {
|
|
391
|
+
export function matchesList(type, key, item, viewerId) {
|
|
365
392
|
const spec = REGISTRY[type];
|
|
366
393
|
if (!spec || !isListKey(key))
|
|
367
394
|
return 'nomatch';
|
|
368
395
|
return spec.listMatch
|
|
369
|
-
? spec.listMatch(listFilters(key), item, listScope(key))
|
|
396
|
+
? spec.listMatch(listFilters(key), item, listScope(key), viewerId)
|
|
370
397
|
: searchAware(listFilters(key));
|
|
371
398
|
}
|
|
372
399
|
export function invalidateType(qc, spec) {
|
|
@@ -388,6 +415,9 @@ export function retryDenied(qc) {
|
|
|
388
415
|
// ─── Applying batches ───────────────────────────────────────────────
|
|
389
416
|
const FETCH_COALESCE_MS = 50;
|
|
390
417
|
const FETCH_CHUNK = 100;
|
|
418
|
+
/** Aggregates (analytics) refresh at most this often per client. */
|
|
419
|
+
export const THROTTLED_REFRESH_MS = 60000;
|
|
420
|
+
const REFRESH_JITTER_MS = 5000;
|
|
391
421
|
/** A fetch failure that means "this entity is gone or no longer visible". */
|
|
392
422
|
function isGoneError(err) {
|
|
393
423
|
const status = err?.status;
|
|
@@ -399,9 +429,15 @@ function dropFromLists(qc, ns, id) {
|
|
|
399
429
|
qc.invalidateQueries({ queryKey: keys.detail(ns, id), exact: true });
|
|
400
430
|
}
|
|
401
431
|
export class ChangeApplier {
|
|
402
|
-
|
|
432
|
+
/**
|
|
433
|
+
* @param refreshMembers fetches the named members and patches them
|
|
434
|
+
* into the member lists (the same path presence uses), so a
|
|
435
|
+
* change to one member doesn't re-download every member.
|
|
436
|
+
*/
|
|
437
|
+
constructor(client, qc, refreshMembers) {
|
|
403
438
|
this.client = client;
|
|
404
439
|
this.qc = qc;
|
|
440
|
+
this.refreshMembers = refreshMembers;
|
|
405
441
|
this.pending = new Map();
|
|
406
442
|
this.timer = null;
|
|
407
443
|
/**
|
|
@@ -415,6 +451,28 @@ export class ChangeApplier {
|
|
|
415
451
|
/** Company each pending `type:id` change came from (see upsertEntity). */
|
|
416
452
|
this.companyOf = new Map();
|
|
417
453
|
this.inflight = new Map();
|
|
454
|
+
/** Last run time and pending trailing timer per throttled key. */
|
|
455
|
+
this.lastRefresh = new Map();
|
|
456
|
+
this.refreshTimers = new Map();
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Refresh `key` now if it hasn't refreshed within the window,
|
|
460
|
+
* otherwise once when the window ends. Leading runs are jittered so
|
|
461
|
+
* clients that all received the same change don't refetch in step.
|
|
462
|
+
*/
|
|
463
|
+
refreshThrottled(key) {
|
|
464
|
+
const id = JSON.stringify(key);
|
|
465
|
+
if (this.refreshTimers.has(id))
|
|
466
|
+
return;
|
|
467
|
+
const last = this.lastRefresh.get(id);
|
|
468
|
+
const wait = last === undefined || Date.now() - last >= THROTTLED_REFRESH_MS
|
|
469
|
+
? Math.random() * REFRESH_JITTER_MS
|
|
470
|
+
: last + THROTTLED_REFRESH_MS - Date.now();
|
|
471
|
+
this.refreshTimers.set(id, setTimeout(() => {
|
|
472
|
+
this.refreshTimers.delete(id);
|
|
473
|
+
this.lastRefresh.set(id, Date.now());
|
|
474
|
+
void this.qc.invalidateQueries({ queryKey: [...key] });
|
|
475
|
+
}, wait));
|
|
418
476
|
}
|
|
419
477
|
mark(type, id) {
|
|
420
478
|
this.latest.set(`${type}:${id}`, ++this.seq);
|
|
@@ -435,6 +493,22 @@ export class ChangeApplier {
|
|
|
435
493
|
const spec = REGISTRY[entry.type];
|
|
436
494
|
if (!spec)
|
|
437
495
|
continue;
|
|
496
|
+
spec.refreshThrottled?.forEach((k) => this.refreshThrottled(k));
|
|
497
|
+
// A named member: patch just that row on every client. No id
|
|
498
|
+
// (joins, leaves, group-wide permission edits) still means the
|
|
499
|
+
// whole list.
|
|
500
|
+
if (entry.type === 'member' && entry.id && this.refreshMembers) {
|
|
501
|
+
this.refreshMembers([entry.id]);
|
|
502
|
+
retryDenied(this.qc);
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
// The viewer's own profile; their member rows follow via
|
|
506
|
+
// `member` changes, so don't refetch the whole users namespace.
|
|
507
|
+
if (entry.type === 'user' && entry.id) {
|
|
508
|
+
this.qc.invalidateQueries({ queryKey: ['user'] });
|
|
509
|
+
this.qc.invalidateQueries({ queryKey: keys.detail('users', entry.id) });
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
438
512
|
if (entry.op === 'invalidate' || spec.invalidateOnly) {
|
|
439
513
|
invalidateType(this.qc, spec);
|
|
440
514
|
if (entry.type === 'member')
|
|
@@ -590,6 +664,9 @@ export class ChangeApplier {
|
|
|
590
664
|
if (this.timer)
|
|
591
665
|
clearTimeout(this.timer);
|
|
592
666
|
this.timer = null;
|
|
667
|
+
this.refreshTimers.forEach(clearTimeout);
|
|
668
|
+
this.refreshTimers.clear();
|
|
669
|
+
this.lastRefresh.clear();
|
|
593
670
|
this.pending.clear();
|
|
594
671
|
this.companyOf.clear();
|
|
595
672
|
this.latest.clear();
|
|
@@ -293,6 +293,7 @@ export interface CatalogItemUpdatePayload {
|
|
|
293
293
|
industry?: CatalogIndustry | (string & {});
|
|
294
294
|
/** A `CatalogPriceFormat` name, matched like `industry`. */
|
|
295
295
|
price_format?: CatalogPriceFormat | (string & {});
|
|
296
|
+
archived?: boolean;
|
|
296
297
|
/** Integer seconds between services; null clears it. */
|
|
297
298
|
recommended_frequency?: number | null;
|
|
298
299
|
/** Unix seconds (>= 0); null clears it. */
|
|
@@ -301,7 +302,7 @@ export interface CatalogItemUpdatePayload {
|
|
|
301
302
|
recommended_expire_on?: number | null;
|
|
302
303
|
/** Skill GUIDs; replaces the item's skills. */
|
|
303
304
|
skills?: string[];
|
|
304
|
-
/**
|
|
305
|
+
/** Terms GUIDs; replaces the item's suggested terms. */
|
|
305
306
|
terms?: string[];
|
|
306
307
|
/** Replaces the item's payment options. */
|
|
307
308
|
payment_options?: PaymentOptionInput[];
|
|
@@ -423,6 +424,11 @@ export interface TaskWritePayload {
|
|
|
423
424
|
payment_options?: PaymentOptionInput[];
|
|
424
425
|
/** Price in integer cents; -1 means unset. */
|
|
425
426
|
price?: number;
|
|
427
|
+
/**
|
|
428
|
+
* Units (or square feet) priced into `price` and the payment options; at
|
|
429
|
+
* least 1, null clears. Informational: prices are totals.
|
|
430
|
+
*/
|
|
431
|
+
quantity?: number | null;
|
|
426
432
|
priority?: boolean;
|
|
427
433
|
/** Null unlinks the catalog item. */
|
|
428
434
|
catalog_item_id?: string | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export type { KeyValueStore, QueryPersistOptions } from './client/persist.js';
|
|
|
11
11
|
import './client/core/xhr.js';
|
|
12
12
|
import './client/core/fetch.js';
|
|
13
13
|
import './client/core/utils.js';
|
|
14
|
+
import './client/core/uploads.js';
|
|
14
15
|
import './client/hooks/address.js';
|
|
15
16
|
import './client/hooks/root.js';
|
|
16
17
|
import './client/hooks/jobs.js';
|
|
@@ -37,11 +38,13 @@ import './client/hooks/labels.js';
|
|
|
37
38
|
import './client/hooks/groups.js';
|
|
38
39
|
import './client/hooks/skills.js';
|
|
39
40
|
import './client/hooks/proposal.js';
|
|
40
|
-
import './client/hooks/
|
|
41
|
+
import './client/hooks/terms.js';
|
|
41
42
|
import './client/hooks/timecards.js';
|
|
42
43
|
import './client/hooks/waivers.js';
|
|
43
44
|
import './client/hooks/email.js';
|
|
44
45
|
export { defaultPassOnFeeMethod } from './billing/fees.js';
|
|
46
|
+
export { REACTION_CODE_POINTS, reactionGlyph, groupReactions, messageTime, isChatUnread, } from './chat.js';
|
|
47
|
+
export type { ReactionGroup } from './chat.js';
|
|
45
48
|
export { reverseGeocode } from './geocode.js';
|
|
46
49
|
export { fetchCensusFeatures } from './census.js';
|
|
47
50
|
export { getDegradedServices } from './serviceStatus.js';
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { QueryPersister, IndexedDBStore, MemoryKeyValueStore, defaultKeyValueSto
|
|
|
7
7
|
import './client/core/xhr.js';
|
|
8
8
|
import './client/core/fetch.js';
|
|
9
9
|
import './client/core/utils.js';
|
|
10
|
+
import './client/core/uploads.js';
|
|
10
11
|
import './client/hooks/address.js';
|
|
11
12
|
import './client/hooks/root.js';
|
|
12
13
|
import './client/hooks/jobs.js';
|
|
@@ -33,11 +34,12 @@ import './client/hooks/labels.js';
|
|
|
33
34
|
import './client/hooks/groups.js';
|
|
34
35
|
import './client/hooks/skills.js';
|
|
35
36
|
import './client/hooks/proposal.js';
|
|
36
|
-
import './client/hooks/
|
|
37
|
+
import './client/hooks/terms.js';
|
|
37
38
|
import './client/hooks/timecards.js';
|
|
38
39
|
import './client/hooks/waivers.js';
|
|
39
40
|
import './client/hooks/email.js';
|
|
40
41
|
export { defaultPassOnFeeMethod } from './billing/fees.js';
|
|
42
|
+
export { REACTION_CODE_POINTS, reactionGlyph, groupReactions, messageTime, isChatUnread, } from './chat.js';
|
|
41
43
|
export { reverseGeocode } from './geocode.js';
|
|
42
44
|
export { fetchCensusFeatures } from './census.js';
|
|
43
45
|
export { getDegradedServices } from './serviceStatus.js';
|
|
@@ -12,7 +12,7 @@ export interface AuditLogEntry {
|
|
|
12
12
|
time: number | null;
|
|
13
13
|
actor: string;
|
|
14
14
|
actor_id: string | null;
|
|
15
|
-
entity_type: 'JOB' | 'TASK' | 'EVENT' | 'BILL' | 'COMPANY' | 'MEMBER' | 'GROUP';
|
|
15
|
+
entity_type: 'JOB' | 'TASK' | 'EVENT' | 'BILL' | 'PAYMENT' | 'COMPANY' | 'MEMBER' | 'GROUP';
|
|
16
16
|
entity_id: string | null;
|
|
17
17
|
entity_label: string;
|
|
18
18
|
action: 'CREATED' | 'UPDATED' | 'DELETED';
|
package/dist/types/api/Avro.d.ts
CHANGED
|
@@ -165,6 +165,11 @@ export interface ErrorLogEntry {
|
|
|
165
165
|
status?: number | null;
|
|
166
166
|
message: string | null;
|
|
167
167
|
traceback?: string | null;
|
|
168
|
+
/**
|
|
169
|
+
* Per-field problems of a rejected request (`"field: problem"`). A
|
|
170
|
+
* string when the list was too long and was stored truncated.
|
|
171
|
+
*/
|
|
172
|
+
errors?: string[] | string | null;
|
|
168
173
|
stack?: string | null;
|
|
169
174
|
fatal?: boolean | null;
|
|
170
175
|
platform?: string | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PaymentOption } from './PaymentOption.js';
|
|
2
2
|
export type CatalogIndustry = 'LAWNCARE' | 'SNOW_REMOVAL' | 'CLEANING' | 'OTHER';
|
|
3
|
-
export type CatalogPriceFormat = 'FLAT_RATE' | 'PER_SQFT';
|
|
3
|
+
export type CatalogPriceFormat = 'FLAT_RATE' | 'PER_SQFT' | 'PER_UNIT';
|
|
4
4
|
export interface CatalogItem {
|
|
5
5
|
id: string;
|
|
6
6
|
name: string;
|
|
@@ -8,6 +8,8 @@ export interface CatalogItem {
|
|
|
8
8
|
description: string;
|
|
9
9
|
industry: CatalogIndustry;
|
|
10
10
|
price_format: CatalogPriceFormat;
|
|
11
|
+
/** Hidden from new proposals and the public catalog; kept for tasks. */
|
|
12
|
+
archived: boolean;
|
|
11
13
|
payment_options: PaymentOption[];
|
|
12
14
|
recommended_frequency: number | null;
|
|
13
15
|
recommended_activate_on: number | null;
|
|
@@ -6,7 +6,6 @@ import { PaymentType } from './PaymentType.js';
|
|
|
6
6
|
import { Plan } from './Plan.js';
|
|
7
7
|
import { PlanPayment } from './PlanPayment.js';
|
|
8
8
|
import { Skill } from './Skill.js';
|
|
9
|
-
import { CatalogItem } from './CatalogItem.js';
|
|
10
9
|
export interface Company {
|
|
11
10
|
id: string;
|
|
12
11
|
name: string;
|
|
@@ -14,7 +13,6 @@ export interface Company {
|
|
|
14
13
|
address: string;
|
|
15
14
|
emails: Email[];
|
|
16
15
|
skills: Skill[];
|
|
17
|
-
catalog_items: CatalogItem[];
|
|
18
16
|
time_created: number | null;
|
|
19
17
|
time_updated: number | null;
|
|
20
18
|
/** Null without `can_read_company`. */
|
package/dist/types/api/Job.js
CHANGED
|
@@ -50,7 +50,10 @@ export class Job {
|
|
|
50
50
|
if (!this.tasks || this.tasks.length === 0) {
|
|
51
51
|
return 0;
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
// This route's stop: a job on several routes visits different tasks
|
|
54
|
+
// on each. Fall back to any stop if the route's isn't loaded.
|
|
55
|
+
const routeJob = this.routes.find((r) => r.job_id === this.id && r.route_id === route.id) ??
|
|
56
|
+
this.routes.find((r) => r.job_id === this.id);
|
|
54
57
|
if (!routeJob) {
|
|
55
58
|
return 0;
|
|
56
59
|
}
|
|
@@ -58,7 +61,13 @@ export class Job {
|
|
|
58
61
|
if (contextTasks.length === 0) {
|
|
59
62
|
return 0;
|
|
60
63
|
}
|
|
61
|
-
|
|
64
|
+
// Progress counts only what this visit should do: tasks not due until
|
|
65
|
+
// after the route's next visit (or inactive) are left out entirely.
|
|
66
|
+
const due = contextTasks.filter((t) => t.isDueOn?.(route) ?? true);
|
|
67
|
+
if (due.length === 0) {
|
|
68
|
+
return 1;
|
|
69
|
+
}
|
|
70
|
+
return due.filter((t) => t.isDone?.(route)).length / due.length;
|
|
62
71
|
};
|
|
63
72
|
this.isDone = (route) => {
|
|
64
73
|
return this.portionDone(route) === 1;
|
|
@@ -2,6 +2,9 @@ import { Friendship } from './Friendship.js';
|
|
|
2
2
|
export interface MemberState {
|
|
3
3
|
/** The participant's user id. */
|
|
4
4
|
id: string;
|
|
5
|
+
/** Shown to fellow members even when the member list hides them. */
|
|
6
|
+
first_name?: string;
|
|
7
|
+
last_name?: string;
|
|
5
8
|
state: 'pending' | 'rejected' | 'typing' | 'present' | 'absent';
|
|
6
9
|
friendship: Friendship | null;
|
|
7
10
|
last_message_read_at: number | null;
|
|
@@ -15,6 +15,45 @@ export interface NotificationCreated {
|
|
|
15
15
|
id: string;
|
|
16
16
|
email_errors: NotificationEmailError[];
|
|
17
17
|
}
|
|
18
|
+
/** One part of a notification email (`CreateNotificationPayload`). */
|
|
19
|
+
export interface NotificationBodyPart {
|
|
20
|
+
/** MIME type; `image/*` parts name an uploaded file in `content`. */
|
|
21
|
+
type: string;
|
|
22
|
+
/** The text itself, or the form field name of an uploaded file. */
|
|
23
|
+
content: string;
|
|
24
|
+
/** Inline attachment bytes (base64) instead of an uploaded file. */
|
|
25
|
+
content_b64?: string;
|
|
26
|
+
}
|
|
27
|
+
/** The JSON body of `POST /email/<id>` (`sendEmailMessage`). */
|
|
28
|
+
export interface SendEmailPayload {
|
|
29
|
+
to: string[];
|
|
30
|
+
/** Display names, paired with `to`. */
|
|
31
|
+
to_alias?: string[];
|
|
32
|
+
from?: string;
|
|
33
|
+
from_alias?: string;
|
|
34
|
+
reply_to?: string;
|
|
35
|
+
reply_to_alias?: string;
|
|
36
|
+
subject: string;
|
|
37
|
+
body_parts?: NotificationBodyPart[];
|
|
38
|
+
}
|
|
39
|
+
/** The JSON body of `POST /company/<id>/notification`. */
|
|
40
|
+
export interface CreateNotificationPayload {
|
|
41
|
+
notification: {
|
|
42
|
+
subject: string;
|
|
43
|
+
body: string;
|
|
44
|
+
body_parts?: NotificationBodyPart[];
|
|
45
|
+
};
|
|
46
|
+
/** User ids to notify besides the event's job subscribers. */
|
|
47
|
+
users?: string[];
|
|
48
|
+
/** Sending mailbox; omitted sends no email. */
|
|
49
|
+
email?: string;
|
|
50
|
+
event?: string;
|
|
51
|
+
/** Save the image parts as the event's photos. */
|
|
52
|
+
image_upload_mode?: boolean;
|
|
53
|
+
is_offer?: boolean;
|
|
54
|
+
/** In cents. */
|
|
55
|
+
amount?: number;
|
|
56
|
+
}
|
|
18
57
|
/** A notification sent within a company (`GET /notification/<id>`). */
|
|
19
58
|
export interface CompanyNotification {
|
|
20
59
|
id: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TermsVersion } from './Terms.js';
|
|
2
2
|
import { Task } from './Task.js';
|
|
3
3
|
export interface Proposal {
|
|
4
4
|
id: string;
|
|
@@ -6,7 +6,7 @@ export interface Proposal {
|
|
|
6
6
|
job_id: string;
|
|
7
7
|
expire_on: number | null;
|
|
8
8
|
expired: boolean;
|
|
9
|
-
terms:
|
|
9
|
+
terms: TermsVersion[];
|
|
10
10
|
accepted_at: number | null;
|
|
11
11
|
tasks: Task[];
|
|
12
12
|
}
|
package/dist/types/api/Task.d.ts
CHANGED
|
@@ -75,6 +75,14 @@ declare module './Task.js' {
|
|
|
75
75
|
bill_mode: 'MONTH' | 'SERVICE' | 'NONE';
|
|
76
76
|
autobill: boolean;
|
|
77
77
|
price: number;
|
|
78
|
+
/**
|
|
79
|
+
* Units (or square feet) priced into `price` and the payment options,
|
|
80
|
+
* for `PER_UNIT` / `PER_SQFT` catalog items; null otherwise. Prices are
|
|
81
|
+
* already totals, so never multiply by this.
|
|
82
|
+
*/
|
|
83
|
+
quantity: number | null;
|
|
84
|
+
/** What `quantity` counts; null when there is no quantity. */
|
|
85
|
+
quantity_unit: 'UNIT' | 'SQFT' | null;
|
|
78
86
|
last_unrouted_reason: UnroutedReason | null;
|
|
79
87
|
services_remaining: number;
|
|
80
88
|
activate_on: number | null;
|
|
@@ -123,5 +131,13 @@ export declare class Task {
|
|
|
123
131
|
getPrepaidEventsRemaining: () => number;
|
|
124
132
|
getPrepaidMonthsRemaining: () => number;
|
|
125
133
|
isDone: (route: Route) => boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Whether this visit of `route` should do the task: it's active and
|
|
136
|
+
* either done on the route's day or due before the route's next visit.
|
|
137
|
+
* A task repeating less often than its route (biweekly edging on a
|
|
138
|
+
* weekly route) is not due on its off-weeks, so a stop's progress
|
|
139
|
+
* leaves it out instead of showing the stop as partly done.
|
|
140
|
+
*/
|
|
141
|
+
isDueOn: (route: Route) => boolean;
|
|
126
142
|
}
|
|
127
143
|
export {};
|
package/dist/types/api/Task.js
CHANGED
|
@@ -66,6 +66,12 @@ export const getTaskOverdueness = (task, now = Date.now() / 1000) => {
|
|
|
66
66
|
}
|
|
67
67
|
return overdueTime / (86400 * (task.priority ? 1 : 7));
|
|
68
68
|
};
|
|
69
|
+
/** Local midnight starting the day of the route's current occurrence. */
|
|
70
|
+
function routeDayStart(route) {
|
|
71
|
+
const day = new Date((route.start_time ?? 0) * 1000);
|
|
72
|
+
day.setHours(0, 0, 0, 0);
|
|
73
|
+
return day;
|
|
74
|
+
}
|
|
69
75
|
export class Task {
|
|
70
76
|
constructor(init) {
|
|
71
77
|
this.getStatusLabel = () => {
|
|
@@ -182,11 +188,32 @@ export class Task {
|
|
|
182
188
|
// an early-started visit that finishes a few minutes before
|
|
183
189
|
// route.start_time) while still rejecting stale events from previous
|
|
184
190
|
// occurrences. Applies to both recurring and one-shot tasks.
|
|
185
|
-
const
|
|
186
|
-
routeDay.setHours(0, 0, 0, 0);
|
|
187
|
-
const cutoff = Math.floor(routeDay.getTime() / 1000);
|
|
191
|
+
const cutoff = Math.floor(routeDayStart(route).getTime() / 1000);
|
|
188
192
|
return (this.last_completed_event?.time_ended ?? 0) >= cutoff;
|
|
189
193
|
};
|
|
194
|
+
/**
|
|
195
|
+
* Whether this visit of `route` should do the task: it's active and
|
|
196
|
+
* either done on the route's day or due before the route's next visit.
|
|
197
|
+
* A task repeating less often than its route (biweekly edging on a
|
|
198
|
+
* weekly route) is not due on its off-weeks, so a stop's progress
|
|
199
|
+
* leaves it out instead of showing the stop as partly done.
|
|
200
|
+
*/
|
|
201
|
+
this.isDueOn = (route) => {
|
|
202
|
+
if (this.status !== TaskStatus.ACTIVE)
|
|
203
|
+
return false;
|
|
204
|
+
if (this.isDone(route))
|
|
205
|
+
return true;
|
|
206
|
+
const nextDue = this.getNextDue();
|
|
207
|
+
if (nextDue == null)
|
|
208
|
+
return true;
|
|
209
|
+
const routeDayEnd = routeDayStart(route);
|
|
210
|
+
routeDayEnd.setDate(routeDayEnd.getDate() + 1);
|
|
211
|
+
const nextVisit = route.getNextOccurrence(routeDayEnd);
|
|
212
|
+
// One-off routes have no next visit: then only the route's day counts.
|
|
213
|
+
const horizon = nextVisit ? new Date(nextVisit) : routeDayEnd;
|
|
214
|
+
horizon.setHours(0, 0, 0, 0);
|
|
215
|
+
return nextDue < Math.floor(horizon.getTime() / 1000);
|
|
216
|
+
};
|
|
190
217
|
assignData(this, init);
|
|
191
218
|
// Payloads from the server carry no timestamp: they were computed
|
|
192
219
|
// just now. Copies keep the one they were made with.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface TermsVersion {
|
|
2
2
|
id: string;
|
|
3
3
|
terms_id: string;
|
|
4
4
|
name: string;
|
|
@@ -6,12 +6,12 @@ export interface ProposalTermsVersion {
|
|
|
6
6
|
body: string;
|
|
7
7
|
time_created: number | null;
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
9
|
+
export interface Terms {
|
|
10
10
|
id: string;
|
|
11
11
|
company_id: string;
|
|
12
12
|
name: string | null;
|
|
13
13
|
archived: boolean;
|
|
14
|
-
current_version:
|
|
14
|
+
current_version: TermsVersion | null;
|
|
15
15
|
time_created: number | null;
|
|
16
16
|
time_updated: number | null;
|
|
17
17
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/api.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export * from './api/PlanPayment.js';
|
|
|
36
36
|
export * from './api/Prepayment.js';
|
|
37
37
|
export * from './api/ProcessingFeeLineItem.js';
|
|
38
38
|
export * from './api/Proposal.js';
|
|
39
|
-
export * from './api/
|
|
39
|
+
export * from './api/Terms.js';
|
|
40
40
|
export * from './api/Reaction.js';
|
|
41
41
|
export * from './api/Route.js';
|
|
42
42
|
export * from './api/RouteJob.js';
|
package/dist/types/api.js
CHANGED
|
@@ -34,7 +34,7 @@ export * from './api/PlanPayment.js';
|
|
|
34
34
|
export * from './api/Prepayment.js';
|
|
35
35
|
export * from './api/ProcessingFeeLineItem.js';
|
|
36
36
|
export * from './api/Proposal.js';
|
|
37
|
-
export * from './api/
|
|
37
|
+
export * from './api/Terms.js';
|
|
38
38
|
export * from './api/Reaction.js';
|
|
39
39
|
export * from './api/Route.js';
|
|
40
40
|
export * from './api/RouteJob.js';
|