@go-avro/avro-js 1.6.1-rc1 → 1.6.1

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.
@@ -11,8 +11,6 @@ export declare class AuthManager {
11
11
  private tokenRefreshedCallbacks;
12
12
  private tokenRefreshFailedCallbacks;
13
13
  private refreshing;
14
- /** Bumped on every login and logout; see refreshTokens. */
15
- private generation;
16
14
  constructor({ baseUrl, storage }: {
17
15
  baseUrl: string;
18
16
  storage: Cache | Cache[];
@@ -45,8 +43,6 @@ export declare class AuthManager {
45
43
  * failure notifies `onTokenRefreshFailed` listeners (→ logout).
46
44
  */
47
45
  refreshTokens(): Promise<Tokens>;
48
- /** Start a new session: in-flight refreshes of the old one are void. */
49
- private newSession;
50
46
  setTokens(tokens: Tokens): Promise<void>;
51
47
  setCache(data: Partial<CacheData> | Object): Promise<void>;
52
48
  getCache(key?: keyof CacheData | string): Promise<CacheData[keyof CacheData] | Object | string | null>;
@@ -13,8 +13,6 @@ export class AuthManager {
13
13
  this.tokenRefreshedCallbacks = [];
14
14
  this.tokenRefreshFailedCallbacks = [];
15
15
  this.refreshing = null;
16
- /** Bumped on every login and logout; see refreshTokens. */
17
- this.generation = 0;
18
16
  this.storages = Array.isArray(storage) ? storage : [storage];
19
17
  if (this.storages.length === 0) {
20
18
  throw new Error('At least one token storage must be provided');
@@ -164,16 +162,9 @@ export class AuthManager {
164
162
  refreshTokens() {
165
163
  if (this.refreshing)
166
164
  return this.refreshing;
167
- const generation = this.generation;
168
165
  this.refreshing = (async () => {
169
166
  try {
170
167
  const newToken = await this.fetchNewTokens();
171
- // A logout or a new login while this was in flight: these
172
- // tokens belong to the old session, so never store them.
173
- // Not an auth status: that would log out the new session.
174
- if (generation !== this.generation) {
175
- throw new StandardError(0, 'Session changed during token refresh');
176
- }
177
168
  await Promise.all(this.storages.map((s) => s.set(newToken)));
178
169
  this.tokenRefreshedCallbacks.forEach((cb) => {
179
170
  if (newToken?.access_token)
@@ -182,8 +173,7 @@ export class AuthManager {
182
173
  return newToken;
183
174
  }
184
175
  catch (err) {
185
- // Only the current session's failure means "log out".
186
- if (isDefinitiveAuthFailure(err) && generation === this.generation) {
176
+ if (isDefinitiveAuthFailure(err)) {
187
177
  this.tokenRefreshFailedCallbacks.forEach((cb) => {
188
178
  try {
189
179
  cb();
@@ -196,20 +186,12 @@ export class AuthManager {
196
186
  throw err;
197
187
  }
198
188
  finally {
199
- // A newer session may already have its own refresh running.
200
- if (generation === this.generation)
201
- this.refreshing = null;
189
+ this.refreshing = null;
202
190
  }
203
191
  })();
204
192
  return this.refreshing;
205
193
  }
206
- /** Start a new session: in-flight refreshes of the old one are void. */
207
- newSession() {
208
- this.generation++;
209
- this.refreshing = null;
210
- }
211
194
  async setTokens(tokens) {
212
- this.newSession();
213
195
  await Promise.all(this.storages.map((s) => s.set(tokens)));
214
196
  }
215
197
  async setCache(data) {
@@ -227,7 +209,6 @@ export class AuthManager {
227
209
  return null;
228
210
  }
229
211
  async clearCache() {
230
- this.newSession();
231
212
  await Promise.all(this.storages.map((s) => s.clear()));
232
213
  }
233
214
  async getCompanyId() {
@@ -433,17 +433,7 @@ export class AvroQueryClient {
433
433
  const known = this._companyVersions.get(companyId);
434
434
  this._companyVersions.set(companyId, ack.version);
435
435
  this._persister?.setCompanyVersion(companyId, ack.version);
436
- if (known === undefined) {
437
- // First join: nothing to compare with, and changes made
438
- // between the initial REST loads and joining the room
439
- // were never delivered. Refresh what loaded before now
440
- // once; later joins compare versions instead.
441
- const joinedAt = Date.now();
442
- this._queryClient?.invalidateQueries({
443
- predicate: (q) => q.state.dataUpdatedAt > 0 && q.state.dataUpdatedAt < joinedAt,
444
- });
445
- }
446
- else if (known !== ack.version) {
436
+ if (known !== undefined && known !== ack.version) {
447
437
  this._queryClient?.invalidateQueries();
448
438
  }
449
439
  });
@@ -2,7 +2,7 @@ import { useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
2
2
  import { AvroQueryClient } from '../QueryClient.js';
3
3
  import { restoreNs, snapshotNs, seedDetails, removeOptimisticRow } from '../cache.js';
4
4
  import { keys, matchesList } from '../realtime.js';
5
- import { constructEvent, DelayEvent, Job, LineItemStatus, Task, getTaskOverdueTime, } from '../../types/api.js';
5
+ import { constructEvent, DelayEvent, Job, LineItemStatus, Task, } from '../../types/api.js';
6
6
  const isJobsQuery = (q) => q.queryKey[0] === 'jobs';
7
7
  const isEventsQuery = (q) => q.queryKey[0] === 'events';
8
8
  const isEventsQueryFor = (item) => (q) => q.queryKey[0] === 'events' && matchesList('event', q.queryKey, item) === 'match';
@@ -179,19 +179,12 @@ AvroQueryClient.prototype.useCreateDelayEvent = function () {
179
179
  const delayUntil = Math.max(task.delay_until != null && task.delay_until > now
180
180
  ? task.delay_until
181
181
  : 0, now + delayData.delay_seconds);
182
- if (task.overdue_time == null) {
183
- return new Task({ ...task, delay_until: delayUntil });
184
- }
185
- // `delay` is how far the delay holds the task back,
186
- // so the snapshot catches up once it lapses.
187
- const live = getTaskOverdueTime(task, now);
188
- const held = Math.min(live, now - delayUntil);
189
182
  return new Task({
190
183
  ...task,
191
184
  delay_until: delayUntil,
192
- delay: live - held,
193
- overdue_time: held,
194
- overdue_at: now,
185
+ overdue_time: task.overdue_time != null
186
+ ? Math.min(task.overdue_time, now - delayUntil)
187
+ : task.overdue_time,
195
188
  });
196
189
  }
197
190
  return task;
@@ -43,13 +43,7 @@ export interface EntitySpec {
43
43
  export declare function constructJob(raw: any): Job;
44
44
  export declare const REGISTRY: Record<string, EntitySpec>;
45
45
  export declare function removeEntity(qc: QueryClient, ns: string, id: string): void;
46
- /**
47
- * Write an entity into its detail entry and every list it belongs in.
48
- * `company` is the company the change came from: list scopes are company
49
- * ids, so another company's lists are left alone (a member of two
50
- * companies keeps both companies' lists cached).
51
- */
52
- export declare function upsertEntity(qc: QueryClient, spec: EntitySpec, item: any, company?: string | null): void;
46
+ export declare function upsertEntity(qc: QueryClient, spec: EntitySpec, item: any): void;
53
47
  export declare function matchesList(type: string, key: readonly unknown[], item: any): ListMatch;
54
48
  export declare function invalidateType(qc: QueryClient, spec: EntitySpec): void;
55
49
  export declare class ChangeApplier {
@@ -65,8 +59,6 @@ export declare class ChangeApplier {
65
59
  */
66
60
  private seq;
67
61
  private latest;
68
- /** Company each pending `type:id` change came from (see upsertEntity). */
69
- private companyOf;
70
62
  private inflight;
71
63
  constructor(client: AvroQueryClient, qc: QueryClient);
72
64
  private mark;
@@ -311,13 +311,7 @@ export function removeEntity(qc, ns, id) {
311
311
  qc.removeQueries({ queryKey: keys.detail(ns, id), exact: true });
312
312
  qc.setQueriesData({ predicate: (q) => q.queryKey[0] === ns && isListKey(q.queryKey) }, (old) => (old ? mapList(old, (items) => items.filter((x) => x?.id !== id)) : old));
313
313
  }
314
- /**
315
- * Write an entity into its detail entry and every list it belongs in.
316
- * `company` is the company the change came from: list scopes are company
317
- * ids, so another company's lists are left alone (a member of two
318
- * companies keeps both companies' lists cached).
319
- */
320
- export function upsertEntity(qc, spec, item, company) {
314
+ export function upsertEntity(qc, spec, item) {
321
315
  const id = item?.id;
322
316
  if (!id)
323
317
  return;
@@ -327,9 +321,6 @@ export function upsertEntity(qc, spec, item, company) {
327
321
  .findAll({ predicate: (q) => q.queryKey[0] === spec.ns && isListKey(q.queryKey) });
328
322
  for (const query of lists) {
329
323
  const key = query.queryKey;
330
- const scope = listScope(key);
331
- if (company && scope && scope !== company)
332
- continue;
333
324
  const verdict = spec.listMatch
334
325
  ? spec.listMatch(listFilters(key), item, listScope(key))
335
326
  : searchAware(listFilters(key));
@@ -389,8 +380,6 @@ export class ChangeApplier {
389
380
  */
390
381
  this.seq = 0;
391
382
  this.latest = new Map();
392
- /** Company each pending `type:id` change came from (see upsertEntity). */
393
- this.companyOf = new Map();
394
383
  this.inflight = new Map();
395
384
  }
396
385
  mark(type, id) {
@@ -407,7 +396,6 @@ export class ChangeApplier {
407
396
  }
408
397
  apply(payload) {
409
398
  const entries = Array.isArray(payload?.changes) ? payload.changes : [];
410
- const company = payload?.company ?? null;
411
399
  for (const entry of entries) {
412
400
  const spec = REGISTRY[entry.type];
413
401
  if (!spec)
@@ -429,11 +417,10 @@ export class ChangeApplier {
429
417
  }
430
418
  if (entry.data !== undefined && entry.data !== null) {
431
419
  this.markApplied(entry.type, entry.id);
432
- upsertEntity(this.qc, spec, spec.construct ? spec.construct(entry.data) : entry.data, company);
420
+ upsertEntity(this.qc, spec, spec.construct ? spec.construct(entry.data) : entry.data);
433
421
  spec.alsoInvalidate?.forEach((k) => this.qc.invalidateQueries({ queryKey: [...k] }));
434
422
  continue;
435
423
  }
436
- this.companyOf.set(`${entry.type}:${entry.id}`, company);
437
424
  this.enqueue(entry.type, entry.id);
438
425
  }
439
426
  }
@@ -488,10 +475,8 @@ export class ChangeApplier {
488
475
  return;
489
476
  }
490
477
  this.inflight.delete(key);
491
- if (current(id)) {
478
+ if (current(id))
492
479
  this.latest.delete(key);
493
- this.companyOf.delete(key);
494
- }
495
480
  };
496
481
  ids.forEach((id) => {
497
482
  const key = `${type}:${id}`;
@@ -543,7 +528,7 @@ export class ChangeApplier {
543
528
  for (const [id, raw] of found) {
544
529
  if (!current(id))
545
530
  continue;
546
- upsertEntity(this.qc, spec, spec.construct ? spec.construct(raw) : raw, this.companyOf.get(`${type}:${id}`));
531
+ upsertEntity(this.qc, spec, spec.construct ? spec.construct(raw) : raw);
547
532
  }
548
533
  for (const id of gone) {
549
534
  if (current(id))
@@ -566,7 +551,6 @@ export class ChangeApplier {
566
551
  clearTimeout(this.timer);
567
552
  this.timer = null;
568
553
  this.pending.clear();
569
- this.companyOf.clear();
570
554
  this.latest.clear();
571
555
  this.inflight.clear();
572
556
  }
@@ -3,15 +3,21 @@ export interface Email {
3
3
  id: string;
4
4
  company_id: string;
5
5
  name: string;
6
+ mail_server: string;
7
+ mail_port: number;
6
8
  mail_username: string;
9
+ mail_password: string | null;
7
10
  mail_default_sender: string;
11
+ mail_use_tls: boolean;
12
+ mail_use_ssl: boolean;
8
13
  mail_api_key: string;
9
14
  is_company_wide: boolean;
10
15
  users: User[];
11
- type: 'OUTLOOK' | 'GMAIL';
16
+ type: 'OUTLOOK' | 'SMTP' | 'GMAIL';
12
17
  /**
13
- * False when the account's grant was revoked or expired: sends fail
14
- * until someone signs in again.
18
+ * False when an OAuth (Outlook/Gmail) account's grant was revoked or
19
+ * expired: sends fail until someone signs in again. Always true for
20
+ * SMTP accounts.
15
21
  */
16
22
  connected: boolean;
17
23
  }
@@ -19,7 +19,7 @@ export interface EmailError {
19
19
  * raised before any provider could be selected (e.g. missing
20
20
  * billing email, no recipients).
21
21
  */
22
- provider: 'outlook' | 'gmail' | 'unknown';
22
+ provider: 'outlook' | 'gmail' | 'smtp' | 'unknown';
23
23
  }
24
24
  export type EmailType = 'bill' | 'proposal' | 'job' | 'generic';
25
25
  export interface EmailSucceededPayload {
@@ -1,5 +1,5 @@
1
1
  import { assignData } from './assignData.js';
2
- import { Task, TaskStatus, getTaskOverdueness } from './Task.js';
2
+ import { Task, TaskStatus } from './Task.js';
3
3
  import { RouteJob } from './RouteJob.js';
4
4
  export class Job {
5
5
  constructor(init) {
@@ -11,14 +11,11 @@ export class Job {
11
11
  if (activeTasks.length === 0) {
12
12
  return 'N/A';
13
13
  }
14
- const now = Date.now() / 1000;
15
- const live = (t) => getTaskOverdueness(t, now);
16
14
  const mostOverdueTask = activeTasks.reduce((mostOverdue, t) => {
17
- const overdueness = live(t);
18
- if (!overdueness || overdueness <= 0) {
15
+ if (!t.overdueness || t.overdueness <= 0) {
19
16
  return mostOverdue;
20
17
  }
21
- if (!mostOverdue || overdueness > (live(mostOverdue) ?? 0)) {
18
+ if (!mostOverdue || t.overdueness > (mostOverdue.overdueness ?? 0)) {
22
19
  return t;
23
20
  }
24
21
  return mostOverdue;
@@ -45,19 +45,8 @@ declare module './Task.js' {
45
45
  time_updated: number | null;
46
46
  status: TaskStatus;
47
47
  created_by: UserCompanyAssociation | null;
48
- /**
49
- * Overdueness as of `overdue_at`. It grows with time while nothing
50
- * in the database changes, so no realtime event refreshes it:
51
- * prefer `getOverdueness()`.
52
- */
53
48
  overdueness: number | null;
54
- /** Seconds overdue as of `overdue_at`; prefer `getOverdueTime()`. */
55
49
  overdue_time: number;
56
- /**
57
- * When (epoch seconds) `overdueness`/`overdue_time` were computed:
58
- * when the server payload arrived, unless the copy carried one.
59
- */
60
- overdue_at: number;
61
50
  last_completed_event: _Event | null;
62
51
  current_event: _Event | null;
63
52
  /**
@@ -95,25 +84,12 @@ declare module './Task.js' {
95
84
  export declare const getTaskDelayUntil: (task: {
96
85
  delay_until?: number | null;
97
86
  }, now?: number) => number | null;
98
- /**
99
- * Seconds overdue at `now`, rolled forward from the server's snapshot.
100
- * Mirrors the backend: the clock only moves the value forward, except that
101
- * a delay stops counting once it has ended.
102
- */
103
- type OverdueSnapshot = Partial<Pick<Task, 'overdueness' | 'overdue_time' | 'overdue_at' | 'delay' | 'delay_until' | 'status' | 'frequency' | 'priority'>>;
104
- export declare const getTaskOverdueTime: (task: OverdueSnapshot, now?: number) => number;
105
- /** The backend's overdueness formula, evaluated at `now`. */
106
- export declare const getTaskOverdueness: (task: OverdueSnapshot, now?: number) => number | null;
107
87
  export declare class Task {
108
88
  constructor(init?: Partial<Task>);
109
89
  getStatusLabel: () => "Active" | "Archived" | "Pending Activation" | "Draft" | "Pending Customer Approval" | "Pending Company Approval" | "Pending Payment";
110
90
  getUnroutedReasonLabel: () => string | null;
111
- /** Seconds overdue right now (negative: due in that many seconds). */
112
- getOverdueTime: (now?: number) => number;
113
- /** Overdueness right now; null when the server reported none. */
114
- getOverdueness: (now?: number) => number | null;
115
- isOverdue: (now?: number) => boolean;
116
- getOverdueLabel: (now?: number) => string;
91
+ isOverdue: () => boolean;
92
+ getOverdueLabel: () => string;
117
93
  /** End (epoch seconds) of this task's delay if it's still in effect. */
118
94
  getDelayUntil: (now?: number) => number | null;
119
95
  isDelayed: (now?: number) => boolean;
@@ -123,4 +99,3 @@ export declare class Task {
123
99
  getPrepaidMonthsRemaining: () => number;
124
100
  isDone: (route: Route) => boolean;
125
101
  }
126
- export {};
@@ -40,32 +40,6 @@ export const UNROUTED_REASON_LABELS = {
40
40
  * A plain function so it works on spread copies of a Task too.
41
41
  */
42
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
- };
69
43
  export class Task {
70
44
  constructor(init) {
71
45
  this.getStatusLabel = () => {
@@ -93,28 +67,23 @@ export class Task {
93
67
  return null;
94
68
  return UNROUTED_REASON_LABELS[this.last_unrouted_reason] ?? this.last_unrouted_reason;
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
+ this.isOverdue = () => {
101
71
  return (this.status === TaskStatus.ACTIVE &&
102
72
  this.overdue_time !== undefined &&
103
- this.getOverdueTime(now) > 0);
73
+ this.overdue_time > 0);
104
74
  };
105
- this.getOverdueLabel = (now) => {
106
- const overdueTime = this.getOverdueTime(now);
75
+ this.getOverdueLabel = () => {
107
76
  if (this.overdueness === null || this.status !== TaskStatus.ACTIVE) {
108
77
  return this.getStatusLabel();
109
78
  }
110
- else if (overdueTime <= 0) {
111
- return `In ${Math.abs(Math.round(overdueTime / 86400))}d`;
79
+ else if (this.overdue_time <= 0) {
80
+ return `In ${Math.abs(Math.round(this.overdue_time / 86400))}d`;
112
81
  }
113
- else if (overdueTime < 86400) {
82
+ else if (this.overdue_time < 86400) {
114
83
  return '< 1d overdue';
115
84
  }
116
85
  else {
117
- return `${Math.floor(overdueTime / 86400)}d overdue`;
86
+ return `${Math.floor(this.overdue_time / 86400)}d overdue`;
118
87
  }
119
88
  };
120
89
  /** End (epoch seconds) of this task's delay if it's still in effect. */
@@ -186,10 +155,6 @@ export class Task {
186
155
  return (this.last_completed_event?.time_ended ?? 0) >= cutoff;
187
156
  };
188
157
  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;
193
158
  if (init?.prepayments) {
194
159
  this.prepayments = init.prepayments.map((p) => new Prepayment(p));
195
160
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "1.6.1-rc1";
1
+ export declare const AVRO_JS_VERSION = "1.6.1";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // AUTO-GENERATED by scripts/gen-version.js — do not edit by hand.
2
2
  // Regenerated from package.json by the `prebuild` npm hook.
3
- export const AVRO_JS_VERSION = '1.6.1-rc1';
3
+ export const AVRO_JS_VERSION = '1.6.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "1.6.1-rc1",
3
+ "version": "1.6.1",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",