@ping-app/ping-openmls-sdk 0.9.2 → 0.10.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.
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ import { M as MessageEnvelope, S as Storage, T as Transport, E as ExpectedOwner,
2
2
  export { u as AddMemberStatus, v as AddMemberVerdict, B as BufferOverflow, w as Bytes, x as CatchupSnapshotEntry, y as ConversationRemoval, z as ConversationUpdate, F as DeviceInfo, G as DeviceRemovalFailure, D as DiscoveredDevice, J as HistoryAppEvent, N as Hlc, O as IdentityRotationFailure, Q as LogGap, V as MessageKind, W as OverflowReason, X as SenderRole, Y as StrandReason, Z as StrandedConversation, _ as WelcomeFailure, $ as WelcomeFailureReason } from './types-B1GFwNXa.cjs';
3
3
  export { IndexedDbStorage } from './storage/indexeddb.cjs';
4
4
  export { WebSocketTransport } from './transport/websocket.cjs';
5
- export { NotificationPreviewOptions, NotificationPreviewSession, openNotificationPreview } from './notification-preview.cjs';
5
+ export { MAX_PREVIEW_PREREQUISITES, NotificationPreviewOptions, NotificationPreviewSession, openNotificationPreview } from './notification-preview.cjs';
6
6
 
7
7
  /**
8
8
  * Ping wire contract version. Bumped on incompatible profile changes.
@@ -174,8 +174,15 @@ interface Conversation {
174
174
  * group-name capability shipped, else the SDK throws. */
175
175
  setConversationName(name: string | null): Promise<void>;
176
176
  /**
177
- * The conversation's MLS GroupContext name, or `undefined` when the meta cache
178
- * has not been primed (call `listConversations()` first).
177
+ * The conversation's MLS GroupContext name as the group holds it now, or
178
+ * `undefined` when the group has none or the client holds no metadata for
179
+ * the conversation (it is not held, or nothing has reported it yet: read it
180
+ * with `readConversationMeta(id)`).
181
+ *
182
+ * Never the name from before a change. The client's copy of a conversation's
183
+ * metadata is replaced before any `onConversationUpdated` listener is told
184
+ * the conversation changed, and before this device's own call that changed
185
+ * it resolves (see `MessagingClient.readConversationMeta`).
179
186
  *
180
187
  * This accessor was MISSING, and hosts reasonably assumed it existed:
181
188
  * `getConversation(id).name` read `undefined` on every call, so any host logic
@@ -186,9 +193,13 @@ interface Conversation {
186
193
  * one-field convenience that hosts were already reaching for.
187
194
  */
188
195
  readonly name?: string | undefined;
189
- /** The conversation's current MLS epoch, or `undefined` when the meta cache
190
- * has not been primed. */
196
+ /** The conversation's current MLS epoch, or `undefined` when the client
197
+ * holds no metadata for the conversation. Never an epoch from before a
198
+ * change the host was already told about. */
191
199
  readonly epoch?: number | undefined;
200
+ /** The whole record, as fresh as `name`. Throws when the client holds no
201
+ * metadata for the conversation: `readConversationMeta(id)` answers `null`
202
+ * instead, and tells "not held" from "not read yet". */
192
203
  meta(): ConversationMeta;
193
204
  }
194
205
  declare class MessagingClient {
@@ -202,6 +213,19 @@ declare class MessagingClient {
202
213
  private readonly fanout;
203
214
  private conversationHandlers;
204
215
  private subscription;
216
+ /**
217
+ * This client's copy of each conversation's metadata, keyed by lowercase-hex
218
+ * conversation id: what a conversation handle's `name`, `epoch` and `meta()`
219
+ * answer from.
220
+ *
221
+ * It is never older than what the host has been told. The worker attaches a
222
+ * conversation's metadata to every change it reports, and {@link handleWorker}
223
+ * stores it before it calls a listener or settles a call; an entry whose
224
+ * conversation changed with no metadata attached is dropped, never kept.
225
+ * Bounded by the conversations the client holds: an entry goes when its
226
+ * conversation is left, dropped or removed, and `listConversations()`
227
+ * replaces the whole map.
228
+ */
205
229
  private metaCache;
206
230
  /**
207
231
  * Per-conversation batching of sequenced live frames: the first frame goes
@@ -550,6 +574,25 @@ declare class MessagingClient {
550
574
  */
551
575
  getConversation(id: ConversationId): Conversation;
552
576
  listConversations(): Promise<ConversationMeta[]>;
577
+ /**
578
+ * ONE conversation's metadata as the group holds it now: the same record as
579
+ * its element of {@link listConversations}, without listing the others.
580
+ * Resolves `null` when this client does not hold the conversation (unknown,
581
+ * dropped, removed, or left). A pure read of local state: nothing is
582
+ * fetched. Rejects for an id that is not 16 bytes.
583
+ *
584
+ * It also brings the conversation handle's `name`, `epoch` and `meta()` to
585
+ * the answer, though they do not need it to be fresh: the client replaces
586
+ * its copy of a conversation's metadata
587
+ * - before any {@link onConversationUpdated} listener is told the
588
+ * conversation changed (a Commit from another member, a join, a page of
589
+ * a catch-up), and
590
+ * - before this device's own call that changed it resolves (a rename, a
591
+ * roles or membership change, a creation, a leave).
592
+ * Use this read for a conversation nothing has reported yet in this
593
+ * session, or to learn that a conversation is no longer held.
594
+ */
595
+ readConversationMeta(id: Uint8Array): Promise<ConversationMeta | null>;
553
596
  /**
554
597
  * Conversations detected as STRANDED during catch-up — a Commit was missed
555
598
  * and the group can no longer advance from local state, so new messages stop
@@ -1083,6 +1126,10 @@ declare class MessagingClient {
1083
1126
  /** Reject every pending call with `error` and forget them. */
1084
1127
  private failPending;
1085
1128
  private conversationProxy;
1129
+ /** Replace this client's copy of one conversation's metadata with what the
1130
+ * worker read; no metadata means the copy is dropped, so the handle answers
1131
+ * "not held" instead of what the group held before. */
1132
+ private storeMeta;
1086
1133
  private call;
1087
1134
  /** Dispatch a worker-side transport proxy call onto the host transport.
1088
1135
  * `sendBatch` is the one method the worker proxy always declares but a
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { M as MessageEnvelope, S as Storage, T as Transport, E as ExpectedOwner,
2
2
  export { u as AddMemberStatus, v as AddMemberVerdict, B as BufferOverflow, w as Bytes, x as CatchupSnapshotEntry, y as ConversationRemoval, z as ConversationUpdate, F as DeviceInfo, G as DeviceRemovalFailure, D as DiscoveredDevice, J as HistoryAppEvent, N as Hlc, O as IdentityRotationFailure, Q as LogGap, V as MessageKind, W as OverflowReason, X as SenderRole, Y as StrandReason, Z as StrandedConversation, _ as WelcomeFailure, $ as WelcomeFailureReason } from './types-B1GFwNXa.js';
3
3
  export { IndexedDbStorage } from './storage/indexeddb.js';
4
4
  export { WebSocketTransport } from './transport/websocket.js';
5
- export { NotificationPreviewOptions, NotificationPreviewSession, openNotificationPreview } from './notification-preview.js';
5
+ export { MAX_PREVIEW_PREREQUISITES, NotificationPreviewOptions, NotificationPreviewSession, openNotificationPreview } from './notification-preview.js';
6
6
 
7
7
  /**
8
8
  * Ping wire contract version. Bumped on incompatible profile changes.
@@ -174,8 +174,15 @@ interface Conversation {
174
174
  * group-name capability shipped, else the SDK throws. */
175
175
  setConversationName(name: string | null): Promise<void>;
176
176
  /**
177
- * The conversation's MLS GroupContext name, or `undefined` when the meta cache
178
- * has not been primed (call `listConversations()` first).
177
+ * The conversation's MLS GroupContext name as the group holds it now, or
178
+ * `undefined` when the group has none or the client holds no metadata for
179
+ * the conversation (it is not held, or nothing has reported it yet: read it
180
+ * with `readConversationMeta(id)`).
181
+ *
182
+ * Never the name from before a change. The client's copy of a conversation's
183
+ * metadata is replaced before any `onConversationUpdated` listener is told
184
+ * the conversation changed, and before this device's own call that changed
185
+ * it resolves (see `MessagingClient.readConversationMeta`).
179
186
  *
180
187
  * This accessor was MISSING, and hosts reasonably assumed it existed:
181
188
  * `getConversation(id).name` read `undefined` on every call, so any host logic
@@ -186,9 +193,13 @@ interface Conversation {
186
193
  * one-field convenience that hosts were already reaching for.
187
194
  */
188
195
  readonly name?: string | undefined;
189
- /** The conversation's current MLS epoch, or `undefined` when the meta cache
190
- * has not been primed. */
196
+ /** The conversation's current MLS epoch, or `undefined` when the client
197
+ * holds no metadata for the conversation. Never an epoch from before a
198
+ * change the host was already told about. */
191
199
  readonly epoch?: number | undefined;
200
+ /** The whole record, as fresh as `name`. Throws when the client holds no
201
+ * metadata for the conversation: `readConversationMeta(id)` answers `null`
202
+ * instead, and tells "not held" from "not read yet". */
192
203
  meta(): ConversationMeta;
193
204
  }
194
205
  declare class MessagingClient {
@@ -202,6 +213,19 @@ declare class MessagingClient {
202
213
  private readonly fanout;
203
214
  private conversationHandlers;
204
215
  private subscription;
216
+ /**
217
+ * This client's copy of each conversation's metadata, keyed by lowercase-hex
218
+ * conversation id: what a conversation handle's `name`, `epoch` and `meta()`
219
+ * answer from.
220
+ *
221
+ * It is never older than what the host has been told. The worker attaches a
222
+ * conversation's metadata to every change it reports, and {@link handleWorker}
223
+ * stores it before it calls a listener or settles a call; an entry whose
224
+ * conversation changed with no metadata attached is dropped, never kept.
225
+ * Bounded by the conversations the client holds: an entry goes when its
226
+ * conversation is left, dropped or removed, and `listConversations()`
227
+ * replaces the whole map.
228
+ */
205
229
  private metaCache;
206
230
  /**
207
231
  * Per-conversation batching of sequenced live frames: the first frame goes
@@ -550,6 +574,25 @@ declare class MessagingClient {
550
574
  */
551
575
  getConversation(id: ConversationId): Conversation;
552
576
  listConversations(): Promise<ConversationMeta[]>;
577
+ /**
578
+ * ONE conversation's metadata as the group holds it now: the same record as
579
+ * its element of {@link listConversations}, without listing the others.
580
+ * Resolves `null` when this client does not hold the conversation (unknown,
581
+ * dropped, removed, or left). A pure read of local state: nothing is
582
+ * fetched. Rejects for an id that is not 16 bytes.
583
+ *
584
+ * It also brings the conversation handle's `name`, `epoch` and `meta()` to
585
+ * the answer, though they do not need it to be fresh: the client replaces
586
+ * its copy of a conversation's metadata
587
+ * - before any {@link onConversationUpdated} listener is told the
588
+ * conversation changed (a Commit from another member, a join, a page of
589
+ * a catch-up), and
590
+ * - before this device's own call that changed it resolves (a rename, a
591
+ * roles or membership change, a creation, a leave).
592
+ * Use this read for a conversation nothing has reported yet in this
593
+ * session, or to learn that a conversation is no longer held.
594
+ */
595
+ readConversationMeta(id: Uint8Array): Promise<ConversationMeta | null>;
553
596
  /**
554
597
  * Conversations detected as STRANDED during catch-up — a Commit was missed
555
598
  * and the group can no longer advance from local state, so new messages stop
@@ -1083,6 +1126,10 @@ declare class MessagingClient {
1083
1126
  /** Reject every pending call with `error` and forget them. */
1084
1127
  private failPending;
1085
1128
  private conversationProxy;
1129
+ /** Replace this client's copy of one conversation's metadata with what the
1130
+ * worker read; no metadata means the copy is dropped, so the handle answers
1131
+ * "not held" instead of what the group held before. */
1132
+ private storeMeta;
1086
1133
  private call;
1087
1134
  /** Dispatch a worker-side transport proxy call onto the host transport.
1088
1135
  * `sendBatch` is the one method the worker proxy always declares but a
package/dist/index.js CHANGED
@@ -609,6 +609,7 @@ function reserveLinearMemory(memory) {
609
609
  }
610
610
 
611
611
  // src/notification-preview.ts
612
+ var MAX_PREVIEW_PREREQUISITES = 64;
612
613
  async function openNotificationPreview(opts) {
613
614
  const now = opts.now ?? (() => Date.now());
614
615
  const scoped = opts.accountNamespace !== void 0 && opts.accountNamespace.length > 0 ? scopeStorage(opts.storage, opts.accountNamespace) : opts.storage;
@@ -633,6 +634,16 @@ async function openNotificationPreview(opts) {
633
634
  const result = client.previewEnvelope(envelope, now());
634
635
  return result ?? null;
635
636
  },
637
+ async previewEnvelopeWithPrerequisites(prerequisites, envelope) {
638
+ if (closed) throw new Error("notification-preview session is closed");
639
+ assertPrerequisiteCount(prerequisites);
640
+ const result = client.previewEnvelopeWithPrerequisites(
641
+ prerequisites,
642
+ envelope,
643
+ now()
644
+ );
645
+ return result ?? null;
646
+ },
636
647
  close() {
637
648
  if (closed) return;
638
649
  closed = true;
@@ -640,6 +651,16 @@ async function openNotificationPreview(opts) {
640
651
  }
641
652
  };
642
653
  }
654
+ function assertPrerequisiteCount(prerequisites) {
655
+ if (!Array.isArray(prerequisites)) {
656
+ throw new Error("notification-preview prerequisites must be an array");
657
+ }
658
+ if (prerequisites.length > MAX_PREVIEW_PREREQUISITES) {
659
+ throw new Error(
660
+ `notification-preview takes at most ${MAX_PREVIEW_PREREQUISITES} prerequisite envelopes`
661
+ );
662
+ }
663
+ }
643
664
  function readOnlyStorage(storage) {
644
665
  const refuse = (op) => Promise.reject(
645
666
  new Error(`notification-preview storage is read-only (attempted ${op})`)
@@ -677,6 +698,19 @@ var MessagingClient = class _MessagingClient {
677
698
  fanout = new MessageFanout();
678
699
  conversationHandlers = /* @__PURE__ */ new Set();
679
700
  subscription = null;
701
+ /**
702
+ * This client's copy of each conversation's metadata, keyed by lowercase-hex
703
+ * conversation id: what a conversation handle's `name`, `epoch` and `meta()`
704
+ * answer from.
705
+ *
706
+ * It is never older than what the host has been told. The worker attaches a
707
+ * conversation's metadata to every change it reports, and {@link handleWorker}
708
+ * stores it before it calls a listener or settles a call; an entry whose
709
+ * conversation changed with no metadata attached is dropped, never kept.
710
+ * Bounded by the conversations the client holds: an entry goes when its
711
+ * conversation is left, dropped or removed, and `listConversations()`
712
+ * replaces the whole map.
713
+ */
680
714
  metaCache = /* @__PURE__ */ new Map();
681
715
  /**
682
716
  * Per-conversation batching of sequenced live frames: the first frame goes
@@ -1464,6 +1498,33 @@ var MessagingClient = class _MessagingClient {
1464
1498
  for (const m of metas) this.metaCache.set(hex(m.id), m);
1465
1499
  return metas;
1466
1500
  }
1501
+ /**
1502
+ * ONE conversation's metadata as the group holds it now: the same record as
1503
+ * its element of {@link listConversations}, without listing the others.
1504
+ * Resolves `null` when this client does not hold the conversation (unknown,
1505
+ * dropped, removed, or left). A pure read of local state: nothing is
1506
+ * fetched. Rejects for an id that is not 16 bytes.
1507
+ *
1508
+ * It also brings the conversation handle's `name`, `epoch` and `meta()` to
1509
+ * the answer, though they do not need it to be fresh: the client replaces
1510
+ * its copy of a conversation's metadata
1511
+ * - before any {@link onConversationUpdated} listener is told the
1512
+ * conversation changed (a Commit from another member, a join, a page of
1513
+ * a catch-up), and
1514
+ * - before this device's own call that changed it resolves (a rename, a
1515
+ * roles or membership change, a creation, a leave).
1516
+ * Use this read for a conversation nothing has reported yet in this
1517
+ * session, or to learn that a conversation is no longer held.
1518
+ */
1519
+ async readConversationMeta(id) {
1520
+ const meta = await this.call({
1521
+ kind: "conversationMeta",
1522
+ id: this.nextId++,
1523
+ conv: id
1524
+ });
1525
+ this.storeMeta(id, meta);
1526
+ return meta ?? null;
1527
+ }
1467
1528
  /**
1468
1529
  * Conversations detected as STRANDED during catch-up — a Commit was missed
1469
1530
  * and the group can no longer advance from local state, so new messages stop
@@ -2316,12 +2377,14 @@ var MessagingClient = class _MessagingClient {
2316
2377
  return {
2317
2378
  id,
2318
2379
  async send(plaintext) {
2380
+ const heldEpoch = self.metaCache.get(hex(id))?.epoch;
2319
2381
  return await self.call({
2320
2382
  kind: "send",
2321
2383
  id: self.nextId++,
2322
2384
  conv: id,
2323
2385
  plaintext,
2324
- nowMs: self.now()
2386
+ nowMs: self.now(),
2387
+ ...heldEpoch !== void 0 ? { heldEpoch } : {}
2325
2388
  });
2326
2389
  },
2327
2390
  async addMembers(entries) {
@@ -2399,8 +2462,8 @@ var MessagingClient = class _MessagingClient {
2399
2462
  });
2400
2463
  },
2401
2464
  /**
2402
- * The conversation's MLS GroupContext name, or `undefined` when the meta
2403
- * cache has not been primed (call `listConversations()`).
2465
+ * The conversation's MLS GroupContext name as the group holds it now, or
2466
+ * `undefined` when it has none or the client holds no metadata for it.
2404
2467
  *
2405
2468
  * This accessor did not exist, and hosts reasonably assumed it did:
2406
2469
  * `getConversation(id).name` read `undefined` on every call, which
@@ -2409,24 +2472,36 @@ var MessagingClient = class _MessagingClient {
2409
2472
  * absent, so a group would materialise unnamed until a best-effort
2410
2473
  * broadcast happened to arrive.
2411
2474
  *
2412
- * A getter rather than a snapshot, so it reflects the cache at read time
2413
- * and never goes stale against a later `listConversations()`.
2475
+ * A getter rather than a snapshot, so it reflects the client's copy at
2476
+ * read time. That copy used to be refilled by `listConversations()`
2477
+ * only, and this answered the name from BEFORE a rename until the host
2478
+ * listed again; it is now replaced with every change the worker reports
2479
+ * (see `metaCache`).
2414
2480
  */
2415
2481
  get name() {
2416
2482
  return self.metaCache.get(hex(id))?.name ?? void 0;
2417
2483
  },
2418
- /** The conversation's current MLS epoch, or `undefined` when the meta
2419
- * cache has not been primed. */
2484
+ /** The conversation's current MLS epoch, or `undefined` when the client
2485
+ * holds no metadata for it. */
2420
2486
  get epoch() {
2421
2487
  return self.metaCache.get(hex(id))?.epoch;
2422
2488
  },
2423
2489
  meta() {
2424
2490
  const cached = self.metaCache.get(hex(id));
2425
- if (!cached) throw new Error("conversation meta not loaded; call listConversations() first");
2491
+ if (!cached) {
2492
+ throw new Error("conversation meta not loaded; call readConversationMeta(id) or listConversations() first");
2493
+ }
2426
2494
  return cached;
2427
2495
  }
2428
2496
  };
2429
2497
  }
2498
+ /** Replace this client's copy of one conversation's metadata with what the
2499
+ * worker read; no metadata means the copy is dropped, so the handle answers
2500
+ * "not held" instead of what the group held before. */
2501
+ storeMeta(id, meta) {
2502
+ if (meta === null || meta === void 0) this.metaCache.delete(hex(id));
2503
+ else this.metaCache.set(hex(id), meta);
2504
+ }
2430
2505
  call(req) {
2431
2506
  if (this.closed) return Promise.reject(new MessagingClientClosedError("closed"));
2432
2507
  return new Promise((resolve, reject) => {
@@ -2480,6 +2555,7 @@ var MessagingClient = class _MessagingClient {
2480
2555
  return;
2481
2556
  }
2482
2557
  case "event.conversation": {
2558
+ this.storeMeta(msg.id, msg.meta);
2483
2559
  for (const h of this.conversationHandlers) {
2484
2560
  try {
2485
2561
  h(msg.id, msg.epoch, msg.sender);
@@ -2491,6 +2567,11 @@ var MessagingClient = class _MessagingClient {
2491
2567
  }
2492
2568
  return;
2493
2569
  }
2570
+ case "cache.conversations": {
2571
+ for (const meta of msg.held) this.storeMeta(meta.id, meta);
2572
+ for (const id of msg.dropped) this.storeMeta(id, null);
2573
+ return;
2574
+ }
2494
2575
  case "storage.call": {
2495
2576
  try {
2496
2577
  const method = this.storage[msg.method];
@@ -2630,6 +2711,7 @@ export {
2630
2711
  HPKE_PQ_ENC_BYTES,
2631
2712
  HPKE_PQ_PUBLIC_KEY_BYTES,
2632
2713
  IndexedDbStorage,
2714
+ MAX_PREVIEW_PREREQUISITES,
2633
2715
  MessagingClient,
2634
2716
  MessagingClientClosedError,
2635
2717
  NOT_PERMITTED_PREFIX,