@ours.network/messenger-server 2.0.0 → 2.0.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/README.md
CHANGED
|
@@ -122,6 +122,23 @@ selectively consumes only those wire IDs. The general consuming `getMessages`
|
|
|
122
122
|
operation is intentionally absent from the REST surface. Duplicate calls are
|
|
123
123
|
harmless because only unread-to-read transitions produce receipt wire IDs.
|
|
124
124
|
|
|
125
|
+
Passive `GET /api/conversations/:contact/page` callers that do not display a chat-list
|
|
126
|
+
preview may pass `preview=none`. The response keeps `preview: ''` and all rows, counts,
|
|
127
|
+
receipts and cursors; older pages avoid the extra newest-message lookup. Omit the option
|
|
128
|
+
for the existing latest-message preview. Contact name/CID resolution is unchanged.
|
|
129
|
+
This opt-in applies to unbound REST pages; resource-bound reads keep their descriptor shape.
|
|
130
|
+
|
|
131
|
+
Contacts snapshots advertise `capabilities.canonicalPeerReads: 1`. Clients with an
|
|
132
|
+
authoritative CID can opt into `GET /api/peers/:cid/page`, `GET /api/peers/:cid/files`
|
|
133
|
+
and `POST /api/peers/:cid/read`. These paths validate an exact 64-character hexadecimal
|
|
134
|
+
CID and bypass name/contact enumeration, even after contact removal. Passive replies
|
|
135
|
+
include `peer: {kind: "cid", cid}`; page previews are omitted. The read command retains
|
|
136
|
+
the existing mutation-intent checks and consumes only unread wire IDs from that exact CID.
|
|
137
|
+
Messages/files resource descriptors opt in with `addressing: "cid"`; their bound reads
|
|
138
|
+
must use the matching peer path, with no change to legacy descriptor/query matching.
|
|
139
|
+
An older server's missing route must not trigger a legacy read fallback. Existing
|
|
140
|
+
name-based/default routes and send/file/command semantics remain unchanged.
|
|
141
|
+
|
|
125
142
|
`GET /api/events` is a bounded SSE invalidation stream:
|
|
126
143
|
|
|
127
144
|
- every connection begins with `sync_required(reason=connected)`;
|
|
@@ -38,7 +38,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
38
38
|
var define_MESSENGER_BUILD_INFO_default;
|
|
39
39
|
var init_define_MESSENGER_BUILD_INFO = __esm({
|
|
40
40
|
"<define:__MESSENGER_BUILD_INFO__>"() {
|
|
41
|
-
define_MESSENGER_BUILD_INFO_default = { name: "@ours.network/messenger-server", version: "2.0.
|
|
41
|
+
define_MESSENGER_BUILD_INFO_default = { name: "@ours.network/messenger-server", version: "2.0.1", sha: "30f29bbec997901e54fb70a1ddf72fd6eb91c509", dirty: false };
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
44
|
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
publicEngineError,
|
|
11
11
|
publicInternalError,
|
|
12
12
|
reportFailure
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-PM5QZQLN.js";
|
|
14
14
|
|
|
15
15
|
// node_modules/bn.js/lib/bn.js
|
|
16
16
|
var require_bn = __commonJS({
|
|
@@ -11181,6 +11181,9 @@ var NotificationOutbox = class {
|
|
|
11181
11181
|
cursor;
|
|
11182
11182
|
checkpoint;
|
|
11183
11183
|
running;
|
|
11184
|
+
again = false;
|
|
11185
|
+
failed = false;
|
|
11186
|
+
closed = false;
|
|
11184
11187
|
timer;
|
|
11185
11188
|
persist(entries, cursor = this.cursor, checkpoint = this.checkpoint) {
|
|
11186
11189
|
const tmp = this.file + ".tmp", fd = openSync(tmp, "w", 384);
|
|
@@ -11223,12 +11226,31 @@ var NotificationOutbox = class {
|
|
|
11223
11226
|
if (!retained.some(same(id))) retained.push({ id, value: { target }, operation: "delete-target" });
|
|
11224
11227
|
this.persist(retained);
|
|
11225
11228
|
}
|
|
11229
|
+
/**
|
|
11230
|
+
* Deliver soon after a durable enqueue instead of at the next recovery tick. A request
|
|
11231
|
+
* during a pass (which iterates its own snapshot) runs one follow-up pass after it;
|
|
11232
|
+
* after a failed pass only the recovery timer retries, so arrivals during an outage
|
|
11233
|
+
* add no attempts.
|
|
11234
|
+
*/
|
|
11235
|
+
prompt() {
|
|
11236
|
+
if (this.closed || this.failed) return;
|
|
11237
|
+
if (this.running) {
|
|
11238
|
+
this.again = true;
|
|
11239
|
+
return;
|
|
11240
|
+
}
|
|
11241
|
+
void this.drain();
|
|
11242
|
+
}
|
|
11226
11243
|
drain() {
|
|
11227
11244
|
return this.running ??= this.drainOnce().finally(() => {
|
|
11228
11245
|
this.running = void 0;
|
|
11246
|
+
if (this.again) {
|
|
11247
|
+
this.again = false;
|
|
11248
|
+
this.prompt();
|
|
11249
|
+
}
|
|
11229
11250
|
});
|
|
11230
11251
|
}
|
|
11231
11252
|
async drainOnce() {
|
|
11253
|
+
this.failed = false;
|
|
11232
11254
|
let attempts = 0;
|
|
11233
11255
|
for (const entry of [...this.entries]) {
|
|
11234
11256
|
if (!supported(entry)) continue;
|
|
@@ -11264,12 +11286,14 @@ var NotificationOutbox = class {
|
|
|
11264
11286
|
if (!response.ok) throw new Error("notification service rejected event");
|
|
11265
11287
|
this.persist(this.entries.filter((e2) => !same(entry.id)(e2)));
|
|
11266
11288
|
} catch {
|
|
11289
|
+
this.failed = true;
|
|
11267
11290
|
this.warn("Notification producer delivery pending; retrying from durable outbox");
|
|
11268
11291
|
break;
|
|
11269
11292
|
}
|
|
11270
11293
|
}
|
|
11271
11294
|
}
|
|
11272
11295
|
async close() {
|
|
11296
|
+
this.closed = true;
|
|
11273
11297
|
clearInterval(this.timer);
|
|
11274
11298
|
await this.running;
|
|
11275
11299
|
}
|
|
@@ -11744,6 +11768,7 @@ var MessengerNotificationProducer = class {
|
|
|
11744
11768
|
wire_id: record.wire_id,
|
|
11745
11769
|
...typeof record.sender_name === "string" ? { sender_name: record.sender_name.slice(0, 512) } : {}
|
|
11746
11770
|
});
|
|
11771
|
+
if (admitted) this.outbox.prompt();
|
|
11747
11772
|
return { status: admitted ? "queued" : "saturated" };
|
|
11748
11773
|
}
|
|
11749
11774
|
retireContact(cid) {
|
|
@@ -12285,7 +12310,7 @@ function projectHistoryPage(contact, history, summary, opts = {}) {
|
|
|
12285
12310
|
unread: summary.unread,
|
|
12286
12311
|
hasMore: history.next_cursor !== null,
|
|
12287
12312
|
nextBefore: history.next_cursor === null ? null : String(history.next_cursor),
|
|
12288
|
-
preview: previewOf(opts.announcedContact ?? contact, messages.at(-1))
|
|
12313
|
+
preview: opts.preview === false ? "" : previewOf(opts.announcedContact ?? contact, messages.at(-1))
|
|
12289
12314
|
};
|
|
12290
12315
|
}
|
|
12291
12316
|
|
|
@@ -12354,10 +12379,11 @@ function canonicalResourceDescriptor(value) {
|
|
|
12354
12379
|
};
|
|
12355
12380
|
if (!value || typeof value !== "object" || Array.isArray(value)) return invalid();
|
|
12356
12381
|
const row = value;
|
|
12357
|
-
if (Object.keys(row).some((key) => !["viewId", "resource", "entityId", "window"].includes(key)) || typeof row.viewId !== "string" || !/^[A-Za-z0-9_-]{1,128}$/.test(row.viewId) || !["contacts", "identity", "messages", "files", "commands"].includes(String(row.resource))) return invalid();
|
|
12382
|
+
if (Object.keys(row).some((key) => !["viewId", "resource", "entityId", "window", "addressing"].includes(key)) || typeof row.viewId !== "string" || !/^[A-Za-z0-9_-]{1,128}$/.test(row.viewId) || !["contacts", "identity", "messages", "files", "commands", "activity"].includes(String(row.resource))) return invalid();
|
|
12358
12383
|
const resource = row.resource;
|
|
12359
12384
|
const scoped = ["messages", "files", "commands"].includes(resource);
|
|
12360
12385
|
if (scoped ? typeof row.entityId !== "string" || !row.entityId : row.entityId !== void 0) return invalid();
|
|
12386
|
+
if (row.addressing !== void 0 && (row.addressing !== "cid" || !["messages", "files"].includes(resource) || !/^[a-f0-9]{64}$/i.test(String(row.entityId)))) return invalid();
|
|
12361
12387
|
if (resource !== "messages" && row.window !== void 0) return invalid();
|
|
12362
12388
|
let window2;
|
|
12363
12389
|
if (resource === "messages") {
|
|
@@ -12371,9 +12397,119 @@ function canonicalResourceDescriptor(value) {
|
|
|
12371
12397
|
...w3.oldestSequence === void 0 ? {} : { oldestSequence: w3.oldestSequence }
|
|
12372
12398
|
};
|
|
12373
12399
|
}
|
|
12374
|
-
return {
|
|
12400
|
+
return {
|
|
12401
|
+
viewId: row.viewId,
|
|
12402
|
+
resource,
|
|
12403
|
+
...scoped ? { entityId: row.entityId } : {},
|
|
12404
|
+
...row.addressing === "cid" ? { addressing: "cid" } : {},
|
|
12405
|
+
...window2 ? { window: window2 } : {}
|
|
12406
|
+
};
|
|
12407
|
+
}
|
|
12408
|
+
var ACTIVITY_READERS = 4;
|
|
12409
|
+
var ACTIVITY_DEADLINE_MS = 5e3;
|
|
12410
|
+
var activitySlots = /* @__PURE__ */ new WeakMap();
|
|
12411
|
+
function slots(client) {
|
|
12412
|
+
let pool = activitySlots.get(client);
|
|
12413
|
+
if (!pool) activitySlots.set(client, pool = { active: 0, waiters: [] });
|
|
12414
|
+
const owned = pool, mine = /* @__PURE__ */ new Set();
|
|
12415
|
+
return {
|
|
12416
|
+
/** False once withdrawn: the projection ended while this reader still waited. */
|
|
12417
|
+
acquire: async () => {
|
|
12418
|
+
while (owned.active >= ACTIVITY_READERS) {
|
|
12419
|
+
const granted = await new Promise((resolve4) => {
|
|
12420
|
+
mine.add(resolve4);
|
|
12421
|
+
owned.waiters.push(resolve4);
|
|
12422
|
+
});
|
|
12423
|
+
if (!granted) return false;
|
|
12424
|
+
}
|
|
12425
|
+
owned.active++;
|
|
12426
|
+
return true;
|
|
12427
|
+
},
|
|
12428
|
+
release: () => {
|
|
12429
|
+
owned.active--;
|
|
12430
|
+
const next = owned.waiters.shift();
|
|
12431
|
+
if (next) {
|
|
12432
|
+
mine.delete(next);
|
|
12433
|
+
next(true);
|
|
12434
|
+
}
|
|
12435
|
+
},
|
|
12436
|
+
withdraw: () => {
|
|
12437
|
+
owned.waiters = owned.waiters.filter((waiter) => !mine.has(waiter));
|
|
12438
|
+
for (const waiter of mine) waiter(false);
|
|
12439
|
+
mine.clear();
|
|
12440
|
+
}
|
|
12441
|
+
};
|
|
12442
|
+
}
|
|
12443
|
+
var contactLists = /* @__PURE__ */ new WeakMap();
|
|
12444
|
+
var listingEpoch = 0;
|
|
12445
|
+
async function contactList(client, since, ended, live) {
|
|
12446
|
+
for (; ; ) {
|
|
12447
|
+
if (!live()) return void 0;
|
|
12448
|
+
const current = contactLists.get(client);
|
|
12449
|
+
if (current && current.epoch > since) return current.read;
|
|
12450
|
+
if (!current) {
|
|
12451
|
+
const listing = { epoch: ++listingEpoch, read: client.listContacts() };
|
|
12452
|
+
contactLists.set(client, listing);
|
|
12453
|
+
const settled = () => {
|
|
12454
|
+
if (contactLists.get(client) === listing) contactLists.delete(client);
|
|
12455
|
+
};
|
|
12456
|
+
listing.read.then(settled, settled);
|
|
12457
|
+
return listing.read;
|
|
12458
|
+
}
|
|
12459
|
+
const waited = await Promise.race([current.read.then(() => true, () => true), ended.then(() => false)]);
|
|
12460
|
+
if (!waited) return void 0;
|
|
12461
|
+
}
|
|
12462
|
+
}
|
|
12463
|
+
async function projectActivity(client, signal, deadlineMs = ACTIVITY_DEADLINE_MS) {
|
|
12464
|
+
signal?.throwIfAborted();
|
|
12465
|
+
const since = listingEpoch;
|
|
12466
|
+
let timer, stop = () => {
|
|
12467
|
+
}, expired = false;
|
|
12468
|
+
const ended = new Promise((resolve4) => {
|
|
12469
|
+
timer = setTimeout(() => {
|
|
12470
|
+
expired = true;
|
|
12471
|
+
resolve4();
|
|
12472
|
+
}, deadlineMs);
|
|
12473
|
+
stop = () => resolve4();
|
|
12474
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
12475
|
+
});
|
|
12476
|
+
const pool = slots(client);
|
|
12477
|
+
const activity = {};
|
|
12478
|
+
let open = true;
|
|
12479
|
+
let contacts = [];
|
|
12480
|
+
try {
|
|
12481
|
+
const listing = contactList(client, since, ended, () => !expired && !signal?.aborted);
|
|
12482
|
+
const listed = await Promise.race([listing, ended.then(() => void 0)]);
|
|
12483
|
+
signal?.throwIfAborted();
|
|
12484
|
+
if (!listed) throw new Error("activity contact list unavailable");
|
|
12485
|
+
contacts = listed.contacts;
|
|
12486
|
+
const queue = contacts.map((contact) => contact.container_id);
|
|
12487
|
+
const reader = async () => {
|
|
12488
|
+
for (; ; ) {
|
|
12489
|
+
if (!await pool.acquire()) return;
|
|
12490
|
+
const cid = open && !expired && !signal?.aborted ? queue.shift() : void 0;
|
|
12491
|
+
if (cid === void 0) return pool.release();
|
|
12492
|
+
try {
|
|
12493
|
+
const newest = (await client.listHistory({ peer_cid: cid, limit: 1 })).items[0];
|
|
12494
|
+
activity[cid] = { at: typeof newest?.date === "string" ? newest.date : "" };
|
|
12495
|
+
} catch {
|
|
12496
|
+
activity[cid] = { unavailable: true };
|
|
12497
|
+
} finally {
|
|
12498
|
+
pool.release();
|
|
12499
|
+
}
|
|
12500
|
+
}
|
|
12501
|
+
};
|
|
12502
|
+
await Promise.race([Promise.all(Array.from({ length: Math.min(ACTIVITY_READERS, queue.length) }, reader)), ended]);
|
|
12503
|
+
} finally {
|
|
12504
|
+
open = false;
|
|
12505
|
+
pool.withdraw();
|
|
12506
|
+
clearTimeout(timer);
|
|
12507
|
+
signal?.removeEventListener("abort", stop);
|
|
12508
|
+
}
|
|
12509
|
+
signal?.throwIfAborted();
|
|
12510
|
+
return { activity: Object.fromEntries(contacts.map((contact) => [contact.container_id, activity[contact.container_id] ?? { unavailable: true }])) };
|
|
12375
12511
|
}
|
|
12376
|
-
async function projectMessageWindow(client, contact, announcedContact, window2, signal) {
|
|
12512
|
+
async function projectMessageWindow(client, contact, announcedContact, window2, signal, options = {}) {
|
|
12377
12513
|
let before;
|
|
12378
12514
|
const rows = [];
|
|
12379
12515
|
let next = null;
|
|
@@ -12388,7 +12524,7 @@ async function projectMessageWindow(client, contact, announcedContact, window2,
|
|
|
12388
12524
|
contact,
|
|
12389
12525
|
{ items: selected, next_cursor: null },
|
|
12390
12526
|
{ total: 0, unread: 0 },
|
|
12391
|
-
{ announcedContact }
|
|
12527
|
+
{ announcedContact, ...options }
|
|
12392
12528
|
).messages));
|
|
12393
12529
|
if (totalBytes > RESOURCE_ASSEMBLY_BYTES) throw new Error("resource assembly limit exceeded");
|
|
12394
12530
|
rows.push(...selected);
|
|
@@ -12405,7 +12541,7 @@ async function projectMessageWindow(client, contact, announcedContact, window2,
|
|
|
12405
12541
|
const summary = await client.getHistorySummary({ peer_cid: contact });
|
|
12406
12542
|
signal.throwIfAborted();
|
|
12407
12543
|
return {
|
|
12408
|
-
...projectHistoryPage(contact, { items: rows, next_cursor: next }, summary, { announcedContact }),
|
|
12544
|
+
...projectHistoryPage(contact, { items: rows, next_cursor: next }, summary, { announcedContact, ...options }),
|
|
12409
12545
|
oldestSequence: rows.at(-1)?.seq ?? window2.oldestSequence ?? null
|
|
12410
12546
|
};
|
|
12411
12547
|
}
|
|
@@ -21516,6 +21652,7 @@ function publicFetchedFiles(value) {
|
|
|
21516
21652
|
function presentContacts(value) {
|
|
21517
21653
|
return {
|
|
21518
21654
|
...value,
|
|
21655
|
+
capabilities: { canonicalPeerReads: 1 },
|
|
21519
21656
|
contacts: value.contacts.map((contact) => ({
|
|
21520
21657
|
...contact,
|
|
21521
21658
|
display_name: contactDisplayName(contact.name)
|
|
@@ -21531,6 +21668,51 @@ async function resolveContact(client, contact) {
|
|
|
21531
21668
|
const row = contacts.contacts.find((item) => item.container_id === contact || item.name === contact);
|
|
21532
21669
|
return { cid: row?.container_id ?? contact, announcedName: row?.name ?? contact };
|
|
21533
21670
|
}
|
|
21671
|
+
function canonicalPeer(cid) {
|
|
21672
|
+
if (!/^[a-f0-9]{64}$/i.test(cid)) throw bad("peer CID must be exactly 64 hexadecimal characters");
|
|
21673
|
+
return { kind: "cid", cid };
|
|
21674
|
+
}
|
|
21675
|
+
async function projectConversationPage(client, contact, query, pin) {
|
|
21676
|
+
if (pin && [...query.keys()].some((key) => !["before", "limit", "preview"].includes(key) || query.getAll(key).length !== 1))
|
|
21677
|
+
throw bad("invalid peer page query");
|
|
21678
|
+
const previews = query.getAll("preview");
|
|
21679
|
+
if (previews.length > 1 || previews.length === 1 && previews[0] !== "none") {
|
|
21680
|
+
throw bad("preview must be omitted or exactly none");
|
|
21681
|
+
}
|
|
21682
|
+
const omitPreview = !!pin || previews.length === 1;
|
|
21683
|
+
const rawLimit = query.get("limit");
|
|
21684
|
+
const limit = rawLimit === null ? DEFAULT_PAGE_LIMIT : Number(rawLimit);
|
|
21685
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 200) {
|
|
21686
|
+
throw new ConversationPageError(`limit must be an integer in 1..200, got ${String(rawLimit)}`);
|
|
21687
|
+
}
|
|
21688
|
+
const peer = pin ? { cid: pin.cid, announcedName: "" } : await resolveContact(client, contact);
|
|
21689
|
+
const before = beforeSequence(query.get("before") ?? void 0);
|
|
21690
|
+
const [history, summary, newest] = await Promise.all([
|
|
21691
|
+
client.listHistory({ peer_cid: peer.cid, before_seq: before, limit }),
|
|
21692
|
+
client.getHistorySummary({ peer_cid: peer.cid }),
|
|
21693
|
+
before === void 0 || omitPreview ? Promise.resolve(null) : client.listHistory({ peer_cid: peer.cid, limit: 1 })
|
|
21694
|
+
]);
|
|
21695
|
+
const projected = projectHistoryPage(contact, history, summary, {
|
|
21696
|
+
announcedContact: peer.announcedName,
|
|
21697
|
+
...omitPreview ? { preview: false } : {}
|
|
21698
|
+
});
|
|
21699
|
+
return {
|
|
21700
|
+
...projected,
|
|
21701
|
+
...newest ? { preview: projectHistoryPage(contact, newest, summary, { announcedContact: peer.announcedName }).preview } : {},
|
|
21702
|
+
...pin ? { peer: pin } : {}
|
|
21703
|
+
};
|
|
21704
|
+
}
|
|
21705
|
+
async function markPeerRead(client, contact, cid) {
|
|
21706
|
+
const unread = (await client.listIncomingMessages()).filter((row) => row.from.id === cid);
|
|
21707
|
+
let marked = 0;
|
|
21708
|
+
for (let offset = 0; offset < unread.length; offset += 200) {
|
|
21709
|
+
const wireIds = unread.slice(offset, offset + 200).map((row) => row.wire_id);
|
|
21710
|
+
if (wireIds.length === 0) continue;
|
|
21711
|
+
const result = await client.getMessages({ wire_ids: wireIds });
|
|
21712
|
+
marked += result.messages.length;
|
|
21713
|
+
}
|
|
21714
|
+
return { contact, marked };
|
|
21715
|
+
}
|
|
21534
21716
|
function beforeSequence(raw) {
|
|
21535
21717
|
if (raw === void 0) return void 0;
|
|
21536
21718
|
const value = Number(raw);
|
|
@@ -21679,12 +21861,13 @@ async function projectCommandResource(client, deps, params) {
|
|
|
21679
21861
|
const peer = await resolveContact(client, params.contact);
|
|
21680
21862
|
return projectCatalog(peer.cid, await client.listContactCommands({ contact: peer.cid }));
|
|
21681
21863
|
}
|
|
21682
|
-
async function projectFilesResource(client, deps, params, signal) {
|
|
21683
|
-
const peer = await resolveContact(client, params.contact);
|
|
21864
|
+
async function projectFilesResource(client, deps, params, signal, pin) {
|
|
21865
|
+
const peer = pin ? { cid: pin.cid } : await resolveContact(client, params.contact);
|
|
21684
21866
|
const files = (await listAllFiles(client, peer.cid, signal, { cid: deps.identityCid, name: deps.config.identity })).reverse();
|
|
21685
21867
|
const versions = /* @__PURE__ */ new Map();
|
|
21686
21868
|
return {
|
|
21687
21869
|
contact: params.contact,
|
|
21870
|
+
...pin ? { peer: pin } : {},
|
|
21688
21871
|
files: files.map((row) => {
|
|
21689
21872
|
const logicalName = row.filename.normalize("NFC").toLocaleLowerCase("en-US");
|
|
21690
21873
|
const version = (versions.get(logicalName) ?? 0) + 1;
|
|
@@ -21705,13 +21888,22 @@ async function projectResourceView(deps, input, signal) {
|
|
|
21705
21888
|
case "identity":
|
|
21706
21889
|
return projectIdentityResource(client, deps);
|
|
21707
21890
|
case "files":
|
|
21708
|
-
return projectFilesResource(
|
|
21891
|
+
return projectFilesResource(
|
|
21892
|
+
client,
|
|
21893
|
+
deps,
|
|
21894
|
+
{ contact: descriptor.entityId },
|
|
21895
|
+
signal,
|
|
21896
|
+
descriptor.addressing === "cid" ? canonicalPeer(descriptor.entityId) : void 0
|
|
21897
|
+
);
|
|
21709
21898
|
case "commands":
|
|
21710
21899
|
return projectCommandResource(client, deps, { contact: descriptor.entityId });
|
|
21900
|
+
case "activity":
|
|
21901
|
+
return projectActivity(client, signal);
|
|
21711
21902
|
case "messages": {
|
|
21712
|
-
const
|
|
21713
|
-
const
|
|
21714
|
-
|
|
21903
|
+
const pin = descriptor.addressing === "cid" ? canonicalPeer(descriptor.entityId) : void 0;
|
|
21904
|
+
const peer = pin ? { cid: pin.cid, announcedName: "" } : await resolveContact(client, descriptor.entityId);
|
|
21905
|
+
const page = await projectMessageWindow(client, peer.cid, peer.announcedName, descriptor.window, signal, pin ? { preview: false } : {});
|
|
21906
|
+
return { ...page, contact: descriptor.entityId, ...pin ? { peer: pin } : {} };
|
|
21715
21907
|
}
|
|
21716
21908
|
}
|
|
21717
21909
|
}
|
|
@@ -21897,30 +22089,13 @@ var ROUTES = {
|
|
|
21897
22089
|
}).messages
|
|
21898
22090
|
};
|
|
21899
22091
|
},
|
|
21900
|
-
"GET /api/conversations/:contact/page": async ({ client, params, query }) =>
|
|
21901
|
-
|
|
21902
|
-
|
|
21903
|
-
|
|
21904
|
-
|
|
21905
|
-
|
|
21906
|
-
}
|
|
21907
|
-
const peer = await resolveContact(client, contact);
|
|
21908
|
-
const before = beforeSequence(query.get("before") ?? void 0);
|
|
21909
|
-
const [history, summary, newest] = await Promise.all([
|
|
21910
|
-
client.listHistory({
|
|
21911
|
-
peer_cid: peer.cid,
|
|
21912
|
-
before_seq: before,
|
|
21913
|
-
limit
|
|
21914
|
-
}),
|
|
21915
|
-
client.getHistorySummary({ peer_cid: peer.cid }),
|
|
21916
|
-
before === void 0 ? Promise.resolve(null) : client.listHistory({ peer_cid: peer.cid, limit: 1 })
|
|
21917
|
-
]);
|
|
21918
|
-
const projected = projectHistoryPage(contact, history, summary, { announcedContact: peer.announcedName });
|
|
21919
|
-
if (!newest) return projected;
|
|
21920
|
-
return {
|
|
21921
|
-
...projected,
|
|
21922
|
-
preview: projectHistoryPage(contact, newest, summary, { announcedContact: peer.announcedName }).preview
|
|
21923
|
-
};
|
|
22092
|
+
"GET /api/conversations/:contact/page": async ({ client, params, query }) => projectConversationPage(client, params.contact, query),
|
|
22093
|
+
// Distinct strict paths fail before mutation on an older service; never alias-fallback.
|
|
22094
|
+
"GET /api/peers/:cid/page": async ({ client, params, query }) => projectConversationPage(client, params.cid, query, canonicalPeer(params.cid)),
|
|
22095
|
+
"GET /api/peers/:cid/files": async ({ client, deps, params }) => projectFilesResource(client, deps, { contact: params.cid }, void 0, canonicalPeer(params.cid)),
|
|
22096
|
+
"POST /api/peers/:cid/read": async ({ client, params }) => {
|
|
22097
|
+
const peer = canonicalPeer(params.cid);
|
|
22098
|
+
return { ...await markPeerRead(client, peer.cid, peer.cid), peer };
|
|
21924
22099
|
},
|
|
21925
22100
|
"GET /api/conversations/:contact/receipts": async ({ client, params }) => {
|
|
21926
22101
|
const peer = await resolveContact(client, params.contact);
|
|
@@ -21941,15 +22116,7 @@ var ROUTES = {
|
|
|
21941
22116
|
// THE HUMAN READ EVENT. The only thing in this server that emits a read receipt.
|
|
21942
22117
|
"POST /api/conversations/:contact/read": async ({ client, params }) => {
|
|
21943
22118
|
const peer = await resolveContact(client, params.contact);
|
|
21944
|
-
|
|
21945
|
-
let marked = 0;
|
|
21946
|
-
for (let offset = 0; offset < unread.length; offset += 200) {
|
|
21947
|
-
const wireIds = unread.slice(offset, offset + 200).map((row) => row.wire_id);
|
|
21948
|
-
if (wireIds.length === 0) continue;
|
|
21949
|
-
const result = await client.getMessages({ wire_ids: wireIds });
|
|
21950
|
-
marked += result.messages.length;
|
|
21951
|
-
}
|
|
21952
|
-
return { contact: params.contact, marked };
|
|
22119
|
+
return markPeerRead(client, params.contact, peer.cid);
|
|
21953
22120
|
},
|
|
21954
22121
|
// The non-consuming inbox summary. Metadata only — it does NOT hand over bodies
|
|
21955
22122
|
// and does NOT mark anything, so it is safe for a frontend in a way getMessages
|
|
@@ -21957,6 +22124,12 @@ var ROUTES = {
|
|
|
21957
22124
|
"GET /api/messages/incoming": async ({ client }) => client.listIncomingMessages(),
|
|
21958
22125
|
// ---- contacts ------------------------------------------------------------
|
|
21959
22126
|
"GET /api/contacts": async ({ client }) => presentContacts(await client.listContacts()),
|
|
22127
|
+
// Last activity per contact for chat-list ordering; no message or file content.
|
|
22128
|
+
"GET /api/activity": async ({ client, res }) => {
|
|
22129
|
+
const lifetime = new AbortController();
|
|
22130
|
+
res.once("close", () => lifetime.abort());
|
|
22131
|
+
return projectActivity(client, lifetime.signal);
|
|
22132
|
+
},
|
|
21960
22133
|
// The old browser surface called this `listContactRoots`. It is not a separate
|
|
21961
22134
|
// operation: roots ride along on the contacts view.
|
|
21962
22135
|
"GET /api/contacts/roots": async ({ client }) => ({ roots: (await client.listContacts()).roots }),
|
|
@@ -22305,9 +22478,9 @@ async function serveApi(req, res, deps) {
|
|
|
22305
22478
|
const [connectionId, viewId, epoch, baselineId] = resourceHeaders.map((values) => values[0]);
|
|
22306
22479
|
const baseline = await resourceService(deps).bound(connectionId, viewId, Number(epoch), baselineId);
|
|
22307
22480
|
const descriptor = baseline.descriptor;
|
|
22308
|
-
const route = descriptor.resource === "contacts" ? "GET /api/contacts" : descriptor.resource === "identity" ? "GET /api/identity" : descriptor.resource === "commands" ? "GET /api/contacts/:contact/commands" : descriptor.resource === "files" ? "GET /api/conversations/:contact/files" : "GET /api/conversations/:contact/page";
|
|
22481
|
+
const route = descriptor.addressing === "cid" ? descriptor.resource === "files" ? "GET /api/peers/:cid/files" : "GET /api/peers/:cid/page" : descriptor.resource === "contacts" ? "GET /api/contacts" : descriptor.resource === "activity" ? "GET /api/activity" : descriptor.resource === "identity" ? "GET /api/identity" : descriptor.resource === "commands" ? "GET /api/contacts/:contact/commands" : descriptor.resource === "files" ? "GET /api/conversations/:contact/files" : "GET /api/conversations/:contact/page";
|
|
22309
22482
|
const allowedQuery = descriptor.resource === "messages" && [...url.searchParams.keys()].every((key) => key === "limit") && (!url.searchParams.has("limit") || url.searchParams.getAll("limit").length === 1 && Number(url.searchParams.get("limit")) === descriptor.window.limit);
|
|
22310
|
-
if (hit.key !== route || descriptor.entityId !== void 0 && descriptor.entityId !== hit.params.contact || url.searchParams.size > 0 && !allowedQuery) throw new ResourceBindingError(409, "resource read descriptor mismatch");
|
|
22483
|
+
if (hit.key !== route || descriptor.entityId !== void 0 && descriptor.entityId !== (hit.params.cid ?? hit.params.contact) || url.searchParams.size > 0 && !allowedQuery) throw new ResourceBindingError(409, "resource read descriptor mismatch");
|
|
22311
22484
|
res.setHeader("X-Resource-Connection", connectionId);
|
|
22312
22485
|
res.setHeader("X-Resource-View", viewId);
|
|
22313
22486
|
res.setHeader("X-Resource-Epoch", epoch);
|
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
normalizeBasePath,
|
|
8
8
|
operatorError,
|
|
9
9
|
reportFailure
|
|
10
|
-
} from "./chunks/chunk-
|
|
10
|
+
} from "./chunks/chunk-PM5QZQLN.js";
|
|
11
11
|
|
|
12
12
|
// src/cli.ts
|
|
13
13
|
init_define_MESSENGER_BUILD_INFO();
|
|
@@ -131,7 +131,7 @@ async function main() {
|
|
|
131
131
|
}
|
|
132
132
|
if (process.argv.length !== 3) throw new ConfigurationError("serve does not accept command-line options");
|
|
133
133
|
const cfg = loadConfig();
|
|
134
|
-
const { start } = await import("./chunks/server-
|
|
134
|
+
const { start } = await import("./chunks/server-4Y24LKPN.js");
|
|
135
135
|
const handle = await start(cfg, BUILD_INFO);
|
|
136
136
|
let closing = false;
|
|
137
137
|
const shutdown = (signal) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ours.network/messenger-server",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Self-hosted Messenger REST/SSE backend for one identity on a shared Ours daemon.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "FSL-1.1-Apache-2.0",
|
|
@@ -33,22 +33,22 @@
|
|
|
33
33
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
34
34
|
"test:startup": "node --import tsx tests/startup-readiness.test.mjs",
|
|
35
35
|
"test:runtime-catalog-candidate": "node --import tsx tests/runtime-command-catalog-reopen-e2e.test.mjs",
|
|
36
|
-
"test:offline": "for f in tests/resource-views.test.mjs tests/resource-connections.test.mjs tests/resource-http.test.mjs tests/workspace-profile-preservation.test.mjs tests/notification-producer.test.mjs tests/notification-contact-retirement.test.mjs tests/notification-outbox-contract.test.mjs tests/workspace-root-retirement.test.mjs tests/base-path.test.mjs tests/build-epoch.test.mjs tests/owner-session.test.mjs tests/v1-runtime.test.mjs tests/typed-commands-core.test.mjs tests/shared-daemon-contract.test.mjs tests/room-envelope-matrix.test.mjs tests/bundle-smoke.test.mjs tests/build-metadata.test.mjs tests/production-security.test.mjs tests/conversation-page.test.mjs tests/media-response.test.mjs tests/html-preview-transform.test.mjs tests/html-preview-response.test.mjs tests/push-store.test.mjs tests/push-store-hardening.test.mjs tests/push-delivery.test.mjs tests/push-queue-saturation.test.mjs tests/events.test.mjs tests/watch-cursor.test.mjs tests/watch-reconcile.test.mjs tests/introduction-send-guard.test.mjs tests/sse-e2e.test.mjs tests/presence.test.mjs tests/static-hosting.test.mjs tests/room-preview.test.mjs; do echo \"# $f\"; node --import tsx \"$f\" || exit 1; done",
|
|
36
|
+
"test:offline": "for f in tests/resource-views.test.mjs tests/resource-connections.test.mjs tests/resource-http.test.mjs tests/resource-activity.test.mjs tests/workspace-profile-preservation.test.mjs tests/notification-producer.test.mjs tests/notification-contact-retirement.test.mjs tests/notification-outbox-contract.test.mjs tests/workspace-root-retirement.test.mjs tests/base-path.test.mjs tests/build-epoch.test.mjs tests/owner-session.test.mjs tests/v1-runtime.test.mjs tests/typed-commands-core.test.mjs tests/shared-daemon-contract.test.mjs tests/room-envelope-matrix.test.mjs tests/bundle-smoke.test.mjs tests/build-metadata.test.mjs tests/production-security.test.mjs tests/conversation-page.test.mjs tests/conversation-preview-option.test.mjs tests/canonical-peer-reads.test.mjs tests/media-response.test.mjs tests/html-preview-transform.test.mjs tests/html-preview-response.test.mjs tests/push-store.test.mjs tests/push-store-hardening.test.mjs tests/push-delivery.test.mjs tests/push-queue-saturation.test.mjs tests/events.test.mjs tests/watch-cursor.test.mjs tests/watch-reconcile.test.mjs tests/introduction-send-guard.test.mjs tests/sse-e2e.test.mjs tests/presence.test.mjs tests/static-hosting.test.mjs tests/room-preview.test.mjs; do echo \"# $f\"; node --import tsx \"$f\" || exit 1; done",
|
|
37
37
|
"test:loopback": "for f in tests/shared-daemon-e2e.test.mjs tests/typed-command-loopback-e2e.test.mjs tests/introduction-send.test.mjs tests/rest-e2e.test.mjs; do echo \"# $f\"; node --import tsx \"$f\" || exit 1; done",
|
|
38
38
|
"test": "npm run build && npm run test:startup && npm run test:offline && npm run test:loopback",
|
|
39
39
|
"test:resource-daemon": "node --import tsx tests/resource-daemon.test.mjs",
|
|
40
|
-
"test:resources": "node --import tsx tests/resource-views.test.mjs && node --import tsx tests/resource-connections.test.mjs && node --import tsx tests/resource-http.test.mjs"
|
|
40
|
+
"test:resources": "node --import tsx tests/resource-views.test.mjs && node --import tsx tests/resource-connections.test.mjs && node --import tsx tests/resource-http.test.mjs && node --import tsx tests/resource-activity.test.mjs"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@eslint-community/regexpp": "4.12.2",
|
|
44
|
-
"@ours.network/sdk": "5.0.
|
|
44
|
+
"@ours.network/sdk": "5.0.1",
|
|
45
45
|
"parse5": "^8.0.1",
|
|
46
46
|
"web-push": "^3.6.7",
|
|
47
47
|
"ws": "^8.21.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@ours.network/cli": "4.0.
|
|
51
|
-
"@ours.network/daemon": "5.0.
|
|
50
|
+
"@ours.network/cli": "4.0.1",
|
|
51
|
+
"@ours.network/daemon": "5.0.1",
|
|
52
52
|
"@playwright/test": "^1.62.1",
|
|
53
53
|
"@types/node": "^20.14.0",
|
|
54
54
|
"@types/web-push": "^3.6.4",
|