@pmate/chat-sdk 0.12.0-next.92 → 0.12.0-next.93
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.
|
@@ -92,6 +92,8 @@ export class ChatSession {
|
|
|
92
92
|
this.readers = new MessageReadersClient({ appId: scope.appId, profileId: scope.profileId, token: options.reading.sessionToken, scope, access: () => this.messages.scopeAccess(), onError: options.onError, hubHttpUrl: options.reading.hubHttpUrl, fetch: options.reading.fetch });
|
|
93
93
|
if (options.loadGroup) {
|
|
94
94
|
this.groups = new GroupClient({ local: !!options.inbox, scope, access: () => this.messages.scopeAccess(), load: options.loadGroup, onError: options.onError, onDenied: async (error, _threadId, signal) => {
|
|
95
|
+
if (isScopedGroupDenial(error))
|
|
96
|
+
return true;
|
|
95
97
|
if (error?.status === 403 && options.messages.transport.authorizeScope) {
|
|
96
98
|
try {
|
|
97
99
|
await options.messages.transport.authorizeScope(signal ?? new AbortController().signal);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { scopedGroupDenial } from "./groupDenial.js";
|
|
1
2
|
import { IndexedDbDiscussionStore } from "./messageDiscussionStore.js";
|
|
2
3
|
import { mergeStoredMessage } from "./messageStore.js";
|
|
3
4
|
import { messageThreadRoot } from "./messageThread.js";
|
|
@@ -53,8 +54,11 @@ export function createChatSession(options) {
|
|
|
53
54
|
loadGroup: async (groupId, signal) => {
|
|
54
55
|
if (options.inbox) {
|
|
55
56
|
const group = await options.inbox.store.group(groupId, teamId);
|
|
56
|
-
if (group)
|
|
57
|
+
if (group) {
|
|
58
|
+
if (group.status !== "dissolved" && !group.members?.includes(profileId))
|
|
59
|
+
throw scopedGroupDenial(Object.assign(new Error("GROUP_ACCESS_DENIED"), { status: 403 }));
|
|
57
60
|
return group;
|
|
61
|
+
}
|
|
58
62
|
if (options.inbox.offlineMode() || isOffline())
|
|
59
63
|
throw new Error("GROUP_METADATA_OFFLINE");
|
|
60
64
|
}
|
|
@@ -187,6 +187,7 @@ export declare class IndexedDbInbox {
|
|
|
187
187
|
items: MessageThreadSummary[];
|
|
188
188
|
revision: number;
|
|
189
189
|
}>;
|
|
190
|
+
conversationGroup(thread: string, teamId: string): Promise<import("./socialReadClient.js").SocialGroup | undefined>;
|
|
190
191
|
group(groupId: string, teamId: string): Promise<import("./socialReadClient.js").SocialGroup | undefined>;
|
|
191
192
|
private annotatedBody;
|
|
192
193
|
close(): void;
|
|
@@ -324,6 +324,12 @@ export class IndexedDbInbox {
|
|
|
324
324
|
return { items, revision: Number(cursor?.seq ?? "0") };
|
|
325
325
|
});
|
|
326
326
|
}
|
|
327
|
+
async conversationGroup(thread, teamId) {
|
|
328
|
+
const assignments = (await this.facts.where("[owner+kind]").equals([this.owner, "threadAssigned"]).toArray()).filter(row => row.value.threadId === thread);
|
|
329
|
+
const records = await this.threads.bulkGet([thread, ...assignments.map(row => row.value.sourceThreadId)].map(source => [this.owner, source]));
|
|
330
|
+
const group = records.find(row => row?.kind === "group");
|
|
331
|
+
return group ? this.group(group.targetId, teamId) : undefined;
|
|
332
|
+
}
|
|
327
333
|
async group(groupId, teamId) {
|
|
328
334
|
const assignments = await this.facts.where("[owner+kind]").equals([this.owner, "threadAssigned"]).toArray();
|
|
329
335
|
const controls = (await this.facts.where("[owner+kind]").equals([this.owner, "groupControl"]).toArray()).map(row => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { scopedGroupDenial } from "./groupDenial.js";
|
|
1
2
|
import { inboxSequence } from "./inboxStore.js";
|
|
2
3
|
import { messageThreadRoot } from "./messageThread.js";
|
|
3
4
|
const encode = (cursor) => `ib1:${encodeURIComponent(JSON.stringify(cursor))}`;
|
|
@@ -19,7 +20,17 @@ const cached = (message) => ({ ...message, id: message.messageId, timestamp: mes
|
|
|
19
20
|
export function inboxMessageTransport(inbox, team, root) {
|
|
20
21
|
const db = inbox.store;
|
|
21
22
|
const read = (run) => db.db.transaction("r", [db.cursors, db.messages, db.facts, db.threads], run);
|
|
23
|
+
const authorized = async (thread) => {
|
|
24
|
+
const group = await db.conversationGroup(thread, team);
|
|
25
|
+
if (group?.status === "dissolved")
|
|
26
|
+
return false;
|
|
27
|
+
if (group && !group.members?.includes(db.scope.profileId))
|
|
28
|
+
throw scopedGroupDenial(Object.assign(new Error("GROUP_ACCESS_DENIED"), { status: 403, threadId: thread }));
|
|
29
|
+
return true;
|
|
30
|
+
};
|
|
22
31
|
const rows = async (thread) => {
|
|
32
|
+
if (!await authorized(thread))
|
|
33
|
+
return [];
|
|
23
34
|
const messages = await db.conversationMessages(thread, team);
|
|
24
35
|
const byId = new Map(messages.map(message => [message.messageId, message]));
|
|
25
36
|
return messages.filter(message => {
|
|
@@ -47,7 +58,7 @@ export function inboxMessageTransport(inbox, team, root) {
|
|
|
47
58
|
changes: (thread, after, signal) => read(async () => {
|
|
48
59
|
signal.throwIfAborted();
|
|
49
60
|
const current = await metadata(thread), cursor = decode(after);
|
|
50
|
-
if (!valid(cursor, current) || await db.structureSequence(thread) > inboxSequence(cursor.seq))
|
|
61
|
+
if (!await authorized(thread) || !valid(cursor, current) || await db.structureSequence(thread) > inboxSequence(cursor.seq))
|
|
51
62
|
return { messages: [], checkpoint: encode(current), resetRequired: true };
|
|
52
63
|
const changed = await db.conversationChanges(thread, team, cursor.seq, cursor.id ?? "\uffff");
|
|
53
64
|
const selected = changed.slice(0, 100), hasMore = changed.length > selected.length;
|
package/package.json
CHANGED