@pmate/chat-sdk 0.12.0-next.36 → 0.12.0-next.38
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.
|
@@ -299,6 +299,7 @@ export class ChatSession {
|
|
|
299
299
|
continue;
|
|
300
300
|
const result = { messages: pages.reverse().flat(), hasEarlier: false, complete: true, resetVersion: version };
|
|
301
301
|
await this.messages.expandWindow(threadId, result);
|
|
302
|
+
this.rememberHistoryEdge(threadId, result);
|
|
302
303
|
return result;
|
|
303
304
|
}
|
|
304
305
|
catch (error) {
|
|
@@ -63,7 +63,7 @@ export class MessageClient {
|
|
|
63
63
|
const current = await this.storage.scopeAccess();
|
|
64
64
|
if (!this.closed && (this.scopeVersion < version || current.revoked)) {
|
|
65
65
|
this.denyScope();
|
|
66
|
-
options.onError?.(
|
|
66
|
+
options.onError?.(accessRevoked(), "");
|
|
67
67
|
}
|
|
68
68
|
}).catch(error => options.onError?.(error, ""));
|
|
69
69
|
}
|
|
@@ -76,7 +76,7 @@ export class MessageClient {
|
|
|
76
76
|
if (this.closed || (current && !current.revoked && (current.resetVersion ?? 0) >= denied.version))
|
|
77
77
|
return;
|
|
78
78
|
this.denyView(denied.thread, denied.version);
|
|
79
|
-
options.onError?.(
|
|
79
|
+
options.onError?.(accessRevoked(), denied.thread);
|
|
80
80
|
})();
|
|
81
81
|
}
|
|
82
82
|
else if (event.data?.type === "legacy" && typeof event.data.thread === "string" && this.watches.has(event.data.thread)) {
|
|
@@ -139,7 +139,7 @@ export class MessageClient {
|
|
|
139
139
|
const task = (async () => {
|
|
140
140
|
await this.ensureScope();
|
|
141
141
|
if (this.scopeDenied)
|
|
142
|
-
throw
|
|
142
|
+
throw accessRevoked();
|
|
143
143
|
const local = await this.storage.read(thread, limit);
|
|
144
144
|
if ((local.coverage?.scopeVersion ?? 0) !== this.scopeVersion) {
|
|
145
145
|
this.denyScope();
|
|
@@ -192,6 +192,8 @@ export class MessageClient {
|
|
|
192
192
|
return cached;
|
|
193
193
|
}
|
|
194
194
|
const snapshot = await this.reload(thread);
|
|
195
|
+
if (this.scopeDenied || this.revoked.has(thread))
|
|
196
|
+
throw accessRevoked();
|
|
195
197
|
if (local.coverage?.complete && Date.now() - (local.coverage.syncedAt ?? 0) > (this.options.freshnessMs ?? 30_000)
|
|
196
198
|
&& (typeof navigator === "undefined" || navigator.onLine !== false))
|
|
197
199
|
this.invalidate(thread);
|
|
@@ -211,6 +213,8 @@ export class MessageClient {
|
|
|
211
213
|
}
|
|
212
214
|
async fallback(thread, limit, before) {
|
|
213
215
|
await this.ensureScope();
|
|
216
|
+
if (this.scopeDenied || this.revoked.has(thread))
|
|
217
|
+
throw accessRevoked();
|
|
214
218
|
const page = await this.storage.readFallback(thread, limit, before);
|
|
215
219
|
if ((page.coverage?.scopeVersion ?? 0) !== this.scopeVersion) {
|
|
216
220
|
this.denyScope();
|
|
@@ -310,7 +314,7 @@ export class MessageClient {
|
|
|
310
314
|
if (this.closed || this.closing)
|
|
311
315
|
return Promise.reject(new Error("MESSAGE_CLIENT_UNAVAILABLE"));
|
|
312
316
|
if (this.revoked.has(thread))
|
|
313
|
-
return Promise.reject(
|
|
317
|
+
return Promise.reject(accessRevoked());
|
|
314
318
|
if (messages.length > 1000 || this.pendingRecords + messages.length > 4096)
|
|
315
319
|
return Promise.reject(new Error("MESSAGE_STORAGE_BACKPRESSURE"));
|
|
316
320
|
let bytes = 0;
|
|
@@ -331,7 +335,7 @@ export class MessageClient {
|
|
|
331
335
|
const committed = new Promise((yes, no) => { resolve = yes; reject = no; });
|
|
332
336
|
const enqueue = this.ensureScope().then(() => {
|
|
333
337
|
if (this.closed || this.scopeDenied)
|
|
334
|
-
throw
|
|
338
|
+
throw accessRevoked();
|
|
335
339
|
if (!this.scopeAllowed)
|
|
336
340
|
throw new Error("MESSAGE_SCOPE_NOT_READY");
|
|
337
341
|
const queue = this.writes.get(thread) ?? [];
|
|
@@ -457,7 +461,7 @@ export class MessageClient {
|
|
|
457
461
|
}
|
|
458
462
|
for (;;) {
|
|
459
463
|
if (this.closed || this.scopeDenied || this.revoked.has(thread))
|
|
460
|
-
throw
|
|
464
|
+
throw accessRevoked();
|
|
461
465
|
if (page.resetRequired)
|
|
462
466
|
throw new Error("MESSAGE_SYNC_RESET_REQUIRED");
|
|
463
467
|
await this.persist(thread, page.messages, page.checkpoint, true, after ? undefined : page.nextBefore, Date.now(), version, scopeVersion);
|
|
@@ -500,11 +504,11 @@ export class MessageClient {
|
|
|
500
504
|
async earlier(thread, before, limit = 100, expand = false) {
|
|
501
505
|
await this.ensureScope();
|
|
502
506
|
if (this.scopeDenied)
|
|
503
|
-
throw
|
|
507
|
+
throw accessRevoked();
|
|
504
508
|
if (this.closed)
|
|
505
509
|
throw new Error("MESSAGE_CLIENT_CLOSED");
|
|
506
510
|
if (this.revoked.has(thread))
|
|
507
|
-
throw
|
|
511
|
+
throw accessRevoked();
|
|
508
512
|
try {
|
|
509
513
|
if (!(await this.storage.read(thread, 1)).coverage?.complete) {
|
|
510
514
|
if (typeof navigator !== "undefined" && navigator.onLine === false)
|
|
@@ -571,6 +575,8 @@ export class MessageClient {
|
|
|
571
575
|
await task;
|
|
572
576
|
page = await this.storage.read(thread, limit, before);
|
|
573
577
|
}
|
|
578
|
+
if (this.scopeDenied || this.revoked.has(thread))
|
|
579
|
+
throw accessRevoked();
|
|
574
580
|
return { messages: page.messages, hasEarlier: page.hasEarlier || Boolean(page.coverage?.nextBefore), resetVersion: page.coverage?.resetVersion ?? 0, complete: page.coverage?.complete ?? false };
|
|
575
581
|
}
|
|
576
582
|
denyView(thread, version) {
|
|
@@ -598,7 +604,7 @@ export class MessageClient {
|
|
|
598
604
|
for (const thread of this.watches.keys())
|
|
599
605
|
this.denyView(thread);
|
|
600
606
|
for (const queue of this.writes.values()) {
|
|
601
|
-
queue.forEach(write => write.reject(
|
|
607
|
+
queue.forEach(write => write.reject(accessRevoked()));
|
|
602
608
|
this.release(queue);
|
|
603
609
|
}
|
|
604
610
|
this.writes.clear();
|
|
@@ -625,7 +631,7 @@ export class MessageClient {
|
|
|
625
631
|
const queue = this.writes.get(thread);
|
|
626
632
|
this.writes.delete(thread);
|
|
627
633
|
if (queue) {
|
|
628
|
-
queue.forEach(write => write.reject(
|
|
634
|
+
queue.forEach(write => write.reject(accessRevoked()));
|
|
629
635
|
this.release(queue);
|
|
630
636
|
}
|
|
631
637
|
try {
|
|
@@ -663,3 +669,4 @@ export class MessageClient {
|
|
|
663
669
|
}
|
|
664
670
|
}
|
|
665
671
|
}
|
|
672
|
+
function accessRevoked() { return Object.assign(new Error("MESSAGE_ACCESS_REVOKED"), { status: 403 }); }
|
package/package.json
CHANGED