@ai-matrx/messaging 0.16.1 → 0.17.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/CHANGELOG.md +16 -0
- package/dist/index.cjs +24 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -30
- package/dist/index.d.ts +8 -30
- package/dist/index.js +28 -105
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +30 -112
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +8 -30
- package/dist/react.d.ts +8 -30
- package/dist/react.js +32 -108
- package/dist/react.js.map +1 -1
- package/package.json +17 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog — `@ai-matrx/messaging`
|
|
2
2
|
|
|
3
|
+
## 0.17.0 — session identity and global slots have one home
|
|
4
|
+
|
|
5
|
+
- The session reader is `@ai-matrx/data/session-identity`; messaging supplies its words, its
|
|
6
|
+
branded `UserId` and its errors. `createSessionIdentity` (public) keeps its signature and words.
|
|
7
|
+
Test helpers `fakeSession`/`withSession`/`signedInAs` come from `@ai-matrx/data/testing`.
|
|
8
|
+
- Global slots use `@ai-matrx/kit/global-slot`; keys unchanged (`ai-matrx.messaging.*`).
|
|
9
|
+
- New dependency: `@ai-matrx/data` (architecture step 11).
|
|
10
|
+
|
|
11
|
+
Consumer action: none.
|
|
12
|
+
|
|
13
|
+
## 0.16.2
|
|
14
|
+
|
|
15
|
+
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
|
16
|
+
`git diff npm/messaging/v0.16.1..npm/messaging/v0.16.2 -- apps/shared/messaging`).
|
|
17
|
+
No source changes intended and no consumer action required.
|
|
18
|
+
|
|
3
19
|
## 0.16.1
|
|
4
20
|
|
|
5
21
|
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,7 @@ __export(src_exports, {
|
|
|
26
26
|
MESSAGING_SCHEMA: () => MESSAGING_SCHEMA,
|
|
27
27
|
MessagingError: () => MessagingError,
|
|
28
28
|
RPCS: () => RPCS,
|
|
29
|
-
SERVER_SESSION_IDENTITY: () => SERVER_SESSION_IDENTITY,
|
|
29
|
+
SERVER_SESSION_IDENTITY: () => import_session_identity2.SERVER_SESSION_IDENTITY,
|
|
30
30
|
TABLES: () => TABLES,
|
|
31
31
|
asClientMessageId: () => asClientMessageId,
|
|
32
32
|
asConversationId: () => asConversationId,
|
|
@@ -44,7 +44,7 @@ __export(src_exports, {
|
|
|
44
44
|
createMessagingStore: () => createMessagingStore,
|
|
45
45
|
createOutbox: () => createOutbox,
|
|
46
46
|
createReadCache: () => createReadCache,
|
|
47
|
-
createSessionIdentity: () =>
|
|
47
|
+
createSessionIdentity: () => createMessagingSessionIdentity,
|
|
48
48
|
createWebOutboxStorage: () => createWebOutboxStorage,
|
|
49
49
|
effectiveActorKey: () => effectiveActorKey,
|
|
50
50
|
extractReferences: () => extractReferences,
|
|
@@ -585,22 +585,9 @@ function createReadCache(options) {
|
|
|
585
585
|
|
|
586
586
|
// src/core/channels.ts
|
|
587
587
|
var import_realtime = require("@ai-matrx/realtime");
|
|
588
|
-
|
|
589
|
-
// src/core/slot.ts
|
|
590
|
-
var NAMESPACE = "ai-matrx.messaging";
|
|
591
|
-
function globalSlot(name, create) {
|
|
592
|
-
const key = /* @__PURE__ */ Symbol.for(`${NAMESPACE}.${name}`);
|
|
593
|
-
const host = globalThis;
|
|
594
|
-
const existing = host[key];
|
|
595
|
-
if (existing !== void 0) return existing;
|
|
596
|
-
const created = create();
|
|
597
|
-
host[key] = created;
|
|
598
|
-
return created;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
// src/core/channels.ts
|
|
588
|
+
var import_global_slot = require("@ai-matrx/kit/global-slot");
|
|
602
589
|
function namespaces() {
|
|
603
|
-
return globalSlot("channel-namespaces", () => ({
|
|
590
|
+
return (0, import_global_slot.globalSlot)("ai-matrx.messaging.channel-namespaces", () => ({
|
|
604
591
|
inbox: (0, import_realtime.defineChannelNamespace)({
|
|
605
592
|
namespace: "messaging-inbox",
|
|
606
593
|
parts: ["userId"],
|
|
@@ -2095,89 +2082,24 @@ function formatLastSeen(lastSeenMs, now = Date.now()) {
|
|
|
2095
2082
|
}
|
|
2096
2083
|
|
|
2097
2084
|
// src/core/session-identity.ts
|
|
2098
|
-
var
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
const candidate = client.auth;
|
|
2105
|
-
if (candidate === null || typeof candidate !== "object") return null;
|
|
2106
|
-
const auth = candidate;
|
|
2107
|
-
if (typeof auth.getSession !== "function") return null;
|
|
2108
|
-
if (typeof auth.onAuthStateChange !== "function") return null;
|
|
2109
|
-
return auth;
|
|
2110
|
-
}
|
|
2111
|
-
function userIdOf(session) {
|
|
2112
|
-
const id = session?.user?.id;
|
|
2113
|
-
return typeof id === "string" && id.length > 0 ? asUserId(id) : null;
|
|
2114
|
-
}
|
|
2115
|
-
var NO_AUTH_SOURCE = {
|
|
2116
|
-
message: "Messaging cannot tell who is signed in: the Supabase client it was given has no auth session source.",
|
|
2117
|
-
remedy: "Pass your app's browser Supabase client \u2014 the same client it signs in with \u2014 to <MessagingProvider client={...}> or createMessagingRepository({ client }). Messaging reads the acting user from that client's session; there is no prop or option for a user id, on purpose (DD-241)."
|
|
2085
|
+
var import_session_identity = require("@ai-matrx/data/session-identity");
|
|
2086
|
+
var import_session_identity2 = require("@ai-matrx/data/session-identity");
|
|
2087
|
+
var MESSAGING_SESSION_WORDS = {
|
|
2088
|
+
product: "Messaging",
|
|
2089
|
+
noAuthSourceRemedy: "Pass your app's browser Supabase client \u2014 the same client it signs in with \u2014 to <MessagingProvider client={...}> or createMessagingRepository({ client }). Messaging reads the acting user from that client's session; there is no prop or option for a user id, on purpose (DD-241).",
|
|
2090
|
+
unreadableRemedy: "Messages stay unavailable on this device until the session can be read. Reload the page; if it persists, sign in again."
|
|
2118
2091
|
};
|
|
2119
|
-
function
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
if (disposed) return;
|
|
2126
|
-
if (current.state === state && current.userId === userId) return;
|
|
2127
|
-
current = Object.freeze({ state, userId });
|
|
2128
|
-
for (const listener of [...listeners]) listener();
|
|
2129
|
-
};
|
|
2130
|
-
const subscribeOnly = (hasAuthSource) => ({
|
|
2131
|
-
hasAuthSource,
|
|
2132
|
-
snapshot: () => current,
|
|
2133
|
-
subscribe: (listener) => {
|
|
2134
|
-
listeners.add(listener);
|
|
2135
|
-
return () => {
|
|
2136
|
-
listeners.delete(listener);
|
|
2137
|
-
};
|
|
2138
|
-
},
|
|
2139
|
-
dispose: () => {
|
|
2140
|
-
disposed = true;
|
|
2141
|
-
listeners.clear();
|
|
2142
|
-
}
|
|
2092
|
+
function createMessagingSessionIdentity(options) {
|
|
2093
|
+
return (0, import_session_identity.createSessionIdentity)({
|
|
2094
|
+
client: options.client,
|
|
2095
|
+
words: MESSAGING_SESSION_WORDS,
|
|
2096
|
+
toUserId: asUserId,
|
|
2097
|
+
onDiagnostic: options.onDiagnostic
|
|
2143
2098
|
});
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
return subscribeOnly(false);
|
|
2149
|
-
}
|
|
2150
|
-
void (async () => {
|
|
2151
|
-
try {
|
|
2152
|
-
const result = await auth.getSession();
|
|
2153
|
-
publish("resolved", userIdOf(result?.data?.session));
|
|
2154
|
-
} catch (error) {
|
|
2155
|
-
onDiagnostic?.({
|
|
2156
|
-
level: "warn",
|
|
2157
|
-
message: `Messaging could not read the signed-in session: ${String(
|
|
2158
|
-
error?.message ?? error
|
|
2159
|
-
)}`,
|
|
2160
|
-
remedy: "Messages stay unavailable on this device until the session can be read. Reload the page; if it persists, sign in again."
|
|
2161
|
-
});
|
|
2162
|
-
publish("resolved", null);
|
|
2163
|
-
}
|
|
2164
|
-
})();
|
|
2165
|
-
const subscription = auth.onAuthStateChange((_event, session) => {
|
|
2166
|
-
publish("resolved", userIdOf(session));
|
|
2167
|
-
});
|
|
2168
|
-
const base = subscribeOnly(true);
|
|
2169
|
-
return {
|
|
2170
|
-
hasAuthSource: true,
|
|
2171
|
-
snapshot: base.snapshot,
|
|
2172
|
-
subscribe: base.subscribe,
|
|
2173
|
-
dispose: () => {
|
|
2174
|
-
base.dispose();
|
|
2175
|
-
try {
|
|
2176
|
-
subscription.data.subscription.unsubscribe();
|
|
2177
|
-
} catch {
|
|
2178
|
-
}
|
|
2179
|
-
}
|
|
2180
|
-
};
|
|
2099
|
+
}
|
|
2100
|
+
function userIdOf(session) {
|
|
2101
|
+
const id = (0, import_session_identity.sessionUserId)(session);
|
|
2102
|
+
return id === null ? null : asUserId(id);
|
|
2181
2103
|
}
|
|
2182
2104
|
function actingUserIdOf(identity) {
|
|
2183
2105
|
return new Promise((resolve, reject) => {
|
|
@@ -2205,14 +2127,11 @@ function noSignedInUserError() {
|
|
|
2205
2127
|
);
|
|
2206
2128
|
}
|
|
2207
2129
|
function noAuthSourceError() {
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
NO_AUTH_SOURCE.message,
|
|
2211
|
-
NO_AUTH_SOURCE.remedy
|
|
2212
|
-
);
|
|
2130
|
+
const { message, remedy } = (0, import_session_identity.noAuthSourceMessage)(MESSAGING_SESSION_WORDS);
|
|
2131
|
+
return new MessagingError("misconfigured", message, remedy);
|
|
2213
2132
|
}
|
|
2214
2133
|
async function readActingUserId(client) {
|
|
2215
|
-
const auth = authOf(client);
|
|
2134
|
+
const auth = (0, import_session_identity.authOf)(client);
|
|
2216
2135
|
if (auth === null) throw noAuthSourceError();
|
|
2217
2136
|
let session;
|
|
2218
2137
|
try {
|
|
@@ -2221,9 +2140,7 @@ async function readActingUserId(client) {
|
|
|
2221
2140
|
} catch (error) {
|
|
2222
2141
|
throw new MessagingError(
|
|
2223
2142
|
"session-unavailable",
|
|
2224
|
-
|
|
2225
|
-
error?.message ?? error
|
|
2226
|
-
)}`,
|
|
2143
|
+
(0, import_session_identity.unreadableSessionMessage)(MESSAGING_SESSION_WORDS, error),
|
|
2227
2144
|
"Reload the page and try again; if it persists, sign in again.",
|
|
2228
2145
|
error
|
|
2229
2146
|
);
|