@ours.network/messenger-server 2.0.3 → 2.0.4
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.
|
@@ -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.4", sha: "32765660cdbab60aad8d8c2f847e77d48e925180", 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-JNUHR327.js";
|
|
14
14
|
|
|
15
15
|
// node_modules/bn.js/lib/bn.js
|
|
16
16
|
var require_bn = __commonJS({
|
|
@@ -22508,7 +22508,7 @@ import { randomBytes as randomBytes2 } from "node:crypto";
|
|
|
22508
22508
|
// node_modules/@ours.network/sdk/dist/index.js
|
|
22509
22509
|
init_define_MESSENGER_BUILD_INFO();
|
|
22510
22510
|
|
|
22511
|
-
// node_modules/@ours.network/sdk/dist/chunk-
|
|
22511
|
+
// node_modules/@ours.network/sdk/dist/chunk-JGK6W4GI.js
|
|
22512
22512
|
init_define_MESSENGER_BUILD_INFO();
|
|
22513
22513
|
|
|
22514
22514
|
// node_modules/@ours.network/sdk/dist/chunk-GPUVPRIY.js
|
|
@@ -22616,9 +22616,9 @@ var L = 100 * 1024 * 1024;
|
|
|
22616
22616
|
var K = { brokerUrl: "wss://broker1.ours.network", port: 3050, stateDir: E(T(), ".ours"), gcIntervalMs: 36e5, historyMaxBytes: L, apiVisibility: "owner", apiAuthMode: "legacy" };
|
|
22617
22617
|
var $2 = "daemon-token";
|
|
22618
22618
|
|
|
22619
|
-
// node_modules/@ours.network/sdk/dist/chunk-
|
|
22619
|
+
// node_modules/@ours.network/sdk/dist/chunk-JGK6W4GI.js
|
|
22620
22620
|
import { homedir as Te } from "node:os";
|
|
22621
|
-
import { isAbsolute as Oe, join as Se, resolve as
|
|
22621
|
+
import { isAbsolute as Oe, join as Se, resolve as pe } from "node:path";
|
|
22622
22622
|
import { randomBytes as W } from "node:crypto";
|
|
22623
22623
|
import { readFileSync as xe } from "node:fs";
|
|
22624
22624
|
import { homedir as Ne } from "node:os";
|
|
@@ -22643,7 +22643,7 @@ function w2(e2) {
|
|
|
22643
22643
|
if (t.username || t.password || t.hash) throw new Error("Daemon endpoint cannot contain credentials or fragment");
|
|
22644
22644
|
return t.origin + t.pathname.replace(/\/+$/, "") + t.search;
|
|
22645
22645
|
}
|
|
22646
|
-
function
|
|
22646
|
+
function u2(e2, t) {
|
|
22647
22647
|
if (!t.startsWith("/") || t.startsWith("//") || t.includes("#")) throw new Error("Invalid daemon route");
|
|
22648
22648
|
let n = new URL(e2), r = new URL(t, "http://daemon.invalid");
|
|
22649
22649
|
if (n.pathname = n.pathname.replace(/\/+$/, "") + r.pathname, r.search) {
|
|
@@ -22729,7 +22729,7 @@ var F = class {
|
|
|
22729
22729
|
this.leaseToken = t.leaseToken, this.clientPid = t.clientPid ?? process.pid, this.explicitApiToken = t.apiToken, this.credentialPath = t.credentialPath;
|
|
22730
22730
|
let n = t.fetch ?? globalThis.fetch;
|
|
22731
22731
|
this.fetchImpl = (r, i) => {
|
|
22732
|
-
let o = String(r) ===
|
|
22732
|
+
let o = String(r) === u2(this.base, "/api/v1/releaseLease"), s = [i?.signal, o ? t.requestSignal ? AbortSignal.timeout(5e3) : void 0 : t.requestSignal].filter((a) => a != null);
|
|
22733
22733
|
return n(r, { ...i, ...s.length ? { signal: AbortSignal.any(s) } : {} });
|
|
22734
22734
|
};
|
|
22735
22735
|
}
|
|
@@ -22740,7 +22740,7 @@ var F = class {
|
|
|
22740
22740
|
return { "x-ours-session-mode": this.sessionMode, "x-ours-lease-token": this.leaseToken, "x-ours-client-pid": String(this.clientPid), ...n ? { "x-ours-api-token": n } : {}, ...t };
|
|
22741
22741
|
}
|
|
22742
22742
|
async post(t, n, r = false) {
|
|
22743
|
-
let i = await this.fetchImpl(
|
|
22743
|
+
let i = await this.fetchImpl(u2(this.base, `/api/v1/${t}`), { redirect: "error", method: "POST", headers: this.headers({ "content-type": "application/json" }), body: JSON.stringify(n ?? {}), ...r ? { signal: AbortSignal.timeout(5e3) } : {} }), o;
|
|
22744
22744
|
try {
|
|
22745
22745
|
r ? o = await C(i) : o = await i.json();
|
|
22746
22746
|
} catch {
|
|
@@ -22759,7 +22759,7 @@ var F = class {
|
|
|
22759
22759
|
return o;
|
|
22760
22760
|
}
|
|
22761
22761
|
async get(t, n) {
|
|
22762
|
-
let r = await this.fetchImpl(
|
|
22762
|
+
let r = await this.fetchImpl(u2(this.base, t), { redirect: "error", headers: n ? this.headers() : {} }), i;
|
|
22763
22763
|
try {
|
|
22764
22764
|
i = await r.json();
|
|
22765
22765
|
} catch {
|
|
@@ -22770,7 +22770,7 @@ var F = class {
|
|
|
22770
22770
|
return i;
|
|
22771
22771
|
}
|
|
22772
22772
|
async resourcePosition(t, n) {
|
|
22773
|
-
let r = await this.fetchImpl(
|
|
22773
|
+
let r = await this.fetchImpl(u2(this.base, `/identities/${encodeURIComponent(t)}/resource-events?position=1`), { redirect: "error", headers: this.headers(), signal: n.signal });
|
|
22774
22774
|
if (!r.ok) throw new U(r.status);
|
|
22775
22775
|
let i = await C(r);
|
|
22776
22776
|
return le(i), i;
|
|
@@ -22790,7 +22790,7 @@ var F = class {
|
|
|
22790
22790
|
a(1e4);
|
|
22791
22791
|
let y2 = new URLSearchParams();
|
|
22792
22792
|
n.after !== void 0 && (y2.set("after", String(n.after)), y2.set("expectedGeneration", n.expectedGeneration));
|
|
22793
|
-
let h = await this.fetchImpl(
|
|
22793
|
+
let h = await this.fetchImpl(u2(this.base, `/identities/${encodeURIComponent(t)}/resource-events?${y2}`), { redirect: "error", headers: this.headers({ accept: "text/event-stream" }), signal: i });
|
|
22794
22794
|
if (i.aborted) throw h.body?.cancel(), i.reason;
|
|
22795
22795
|
if (!h.ok) throw new U(h.status);
|
|
22796
22796
|
if (!h.body || !h.headers.get("content-type")?.startsWith("text/event-stream")) throw new Error("Invalid resource stream response");
|
|
@@ -22806,11 +22806,11 @@ var F = class {
|
|
|
22806
22806
|
if (!N) break;
|
|
22807
22807
|
let j = v2.slice(0, N.index);
|
|
22808
22808
|
if (v2 = v2.slice(N.index + N[0].length), b2 -= Buffer.byteLength(j) + Buffer.byteLength(N[0]), Buffer.byteLength(j) > 512 * 1024) throw new Error("Resource frame exceeds limit");
|
|
22809
|
-
let oe = j.split(/\r?\n/).filter((
|
|
22809
|
+
let oe = j.split(/\r?\n/).filter((P) => P.startsWith("data:")).map((P) => P.slice(5).trimStart()).join(`
|
|
22810
22810
|
`);
|
|
22811
22811
|
if (!oe) continue;
|
|
22812
22812
|
let R2 = JSON.parse(oe);
|
|
22813
|
-
if (c(), j.split(/\r?\n/).some((
|
|
22813
|
+
if (c(), j.split(/\r?\n/).some((P) => P === "event: auth_required")) throw new U(401);
|
|
22814
22814
|
le(R2);
|
|
22815
22815
|
let K2 = R2.kind;
|
|
22816
22816
|
if (!["ready", "committed", "coverage", "resync"].includes(K2)) throw new Error("Invalid resource frame kind");
|
|
@@ -22826,6 +22826,18 @@ var F = class {
|
|
|
22826
22826
|
clearTimeout(o), r.abort(), i.removeEventListener("abort", g), await m2(), l?.releaseLock();
|
|
22827
22827
|
}
|
|
22828
22828
|
}
|
|
22829
|
+
ensureSessionIdentity(t) {
|
|
22830
|
+
return this.post("ensureSessionIdentity", t);
|
|
22831
|
+
}
|
|
22832
|
+
renameIdentity(t) {
|
|
22833
|
+
return this.post("renameIdentity", t);
|
|
22834
|
+
}
|
|
22835
|
+
promoteIdentity() {
|
|
22836
|
+
return this.post("promoteIdentity", {});
|
|
22837
|
+
}
|
|
22838
|
+
listLocalSessions() {
|
|
22839
|
+
return this.post("listLocalSessions", {});
|
|
22840
|
+
}
|
|
22829
22841
|
createIdentity(t) {
|
|
22830
22842
|
return this.post("createIdentity", t);
|
|
22831
22843
|
}
|
|
@@ -23006,7 +23018,7 @@ var F = class {
|
|
|
23006
23018
|
return this.get("/history-storage", true);
|
|
23007
23019
|
}
|
|
23008
23020
|
async readNotificationPage(t, n = {}) {
|
|
23009
|
-
let r = "/identities/" + encodeURIComponent(t) + "/notifications", i = n.kinds?.length ? "&kinds=" + encodeURIComponent(n.kinds.join(",")) : "", o = n.requestTimeoutMs === void 0 ? n.signal : AbortSignal.any([...n.signal ? [n.signal] : [], AbortSignal.timeout(n.requestTimeoutMs)]), s = await this.fetchImpl(
|
|
23021
|
+
let r = "/identities/" + encodeURIComponent(t) + "/notifications", i = n.kinds?.length ? "&kinds=" + encodeURIComponent(n.kinds.join(",")) : "", o = n.requestTimeoutMs === void 0 ? n.signal : AbortSignal.any([...n.signal ? [n.signal] : [], AbortSignal.timeout(n.requestTimeoutMs)]), s = await this.fetchImpl(u2(this.base, r + "?since=" + encodeURIComponent(String(n.since ?? "tip")) + i), { redirect: "error", headers: this.headers(), signal: o }), a;
|
|
23010
23022
|
try {
|
|
23011
23023
|
a = await s.json();
|
|
23012
23024
|
} catch {
|
|
@@ -23023,7 +23035,7 @@ var F = class {
|
|
|
23023
23035
|
for (; !n.signal?.aborted; ) {
|
|
23024
23036
|
let s;
|
|
23025
23037
|
try {
|
|
23026
|
-
let a = await this.fetchImpl(
|
|
23038
|
+
let a = await this.fetchImpl(u2(this.base, `${i}?since=${r}${o}`), { redirect: "error", headers: this.headers(), signal: n.requestTimeoutMs === void 0 ? n.signal : AbortSignal.any([...n.signal ? [n.signal] : [], AbortSignal.timeout(n.requestTimeoutMs)]) });
|
|
23027
23039
|
try {
|
|
23028
23040
|
s = await a.json();
|
|
23029
23041
|
} catch {
|
|
@@ -23039,7 +23051,7 @@ var F = class {
|
|
|
23039
23051
|
}
|
|
23040
23052
|
}
|
|
23041
23053
|
async fetchFile(t) {
|
|
23042
|
-
let n = await this.fetchImpl(
|
|
23054
|
+
let n = await this.fetchImpl(u2(this.base, `/files/${encodeURIComponent(t)}`), { redirect: "error", headers: this.headers() });
|
|
23043
23055
|
if (!n.ok) {
|
|
23044
23056
|
let r = `HTTP ${n.status}`;
|
|
23045
23057
|
try {
|
|
@@ -23052,7 +23064,7 @@ var F = class {
|
|
|
23052
23064
|
return new Uint8Array(await n.arrayBuffer());
|
|
23053
23065
|
}
|
|
23054
23066
|
async openFile(t) {
|
|
23055
|
-
let n = await this.fetchImpl(
|
|
23067
|
+
let n = await this.fetchImpl(u2(this.base, `/files/${encodeURIComponent(t)}`), { redirect: "error", headers: this.headers() });
|
|
23056
23068
|
if (!n.ok) {
|
|
23057
23069
|
let r = `HTTP ${n.status}`;
|
|
23058
23070
|
try {
|
|
@@ -23068,7 +23080,7 @@ var F = class {
|
|
|
23068
23080
|
async uploadFile(t, n) {
|
|
23069
23081
|
let r = t instanceof Uint8Array ? t.byteLength : n.size;
|
|
23070
23082
|
if (r === void 0) throw new Error("uploadFile: `size` is required when the body is a stream (the route needs Content-Length)");
|
|
23071
|
-
let i = await this.fetchImpl(
|
|
23083
|
+
let i = await this.fetchImpl(u2(this.base, "/files/upload"), { redirect: "error", method: "POST", headers: { ...this.headers(), "x-ours-filename": encodeURIComponent(n.filename), "Content-Type": n.mime || "application/octet-stream", "Content-Length": String(r) }, body: t, ...t instanceof Uint8Array ? {} : { duplex: "half" } });
|
|
23072
23084
|
if (!i.ok) {
|
|
23073
23085
|
let o = `HTTP ${i.status}`;
|
|
23074
23086
|
try {
|
|
@@ -23101,7 +23113,7 @@ var x = class extends Error {
|
|
|
23101
23113
|
function Ae(e2 = process.env) {
|
|
23102
23114
|
if (e2.OURS_CONFIG !== void 0) {
|
|
23103
23115
|
if (!e2.OURS_CONFIG.trim()) throw new x("OURS_CONFIG must name a client profile");
|
|
23104
|
-
return
|
|
23116
|
+
return pe(e2.OURS_CONFIG);
|
|
23105
23117
|
}
|
|
23106
23118
|
return Se(e2.HOME || Te(), ".ours-client", "profile.json");
|
|
23107
23119
|
}
|
|
@@ -23125,9 +23137,9 @@ function Re(e2) {
|
|
|
23125
23137
|
} catch {
|
|
23126
23138
|
return t("endpoint must equal serverUrl/daemon");
|
|
23127
23139
|
}
|
|
23128
|
-
return typeof n.expectedInstanceId != "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(n.expectedInstanceId) ? t("expectedInstanceId must be a lowercase UUID") : typeof n.credentialPath != "string" || !Oe(n.credentialPath) ||
|
|
23140
|
+
return typeof n.expectedInstanceId != "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(n.expectedInstanceId) ? t("expectedInstanceId must be a lowercase UUID") : typeof n.credentialPath != "string" || !Oe(n.credentialPath) || pe(n.credentialPath) !== n.credentialPath ? t("credentialPath must be an absolute normalized path") : Object.freeze({ serverUrl: r, endpoint: i, expectedInstanceId: n.expectedInstanceId, credentialPath: n.credentialPath });
|
|
23129
23141
|
}
|
|
23130
|
-
function
|
|
23142
|
+
function ue(e2 = process.env) {
|
|
23131
23143
|
let t = Ae(e2), n;
|
|
23132
23144
|
try {
|
|
23133
23145
|
n = JSON.parse(m(t).toString("utf8"));
|
|
@@ -23138,14 +23150,14 @@ function pe(e2 = process.env) {
|
|
|
23138
23150
|
if (["OURS_PORT", "OURS_STATE_DIR", "OURS_API_TOKEN", "OURS_DAEMON_ID", "OURS_DAEMON_URL", "OURS_DAEMON_CREDENTIAL_PATH"].some((o) => e2[o]?.trim())) throw new x("remove legacy OURS_PORT/STATE_DIR/API_TOKEN/DAEMON_ID/DAEMON_URL/DAEMON_CREDENTIAL_PATH environment selectors");
|
|
23139
23151
|
return Object.freeze({ ...r, configPath: t });
|
|
23140
23152
|
}
|
|
23141
|
-
var
|
|
23153
|
+
var p = class extends Error {
|
|
23142
23154
|
constructor(n, r) {
|
|
23143
23155
|
super(r);
|
|
23144
23156
|
this.code = n;
|
|
23145
23157
|
this.name = "DaemonSelectionError";
|
|
23146
23158
|
}
|
|
23147
23159
|
};
|
|
23148
|
-
var Y = class extends
|
|
23160
|
+
var Y = class extends p {
|
|
23149
23161
|
constructor(n, r, i = {}) {
|
|
23150
23162
|
super("DAEMON_UNAVAILABLE", `no ours daemon is running at ${D(n)} for state directory ${JSON.stringify(r)}. Install the daemon with \`npm install --global @ours.network/daemon\`, then start the shared daemon with \`ours-daemon start\` or install/start its per-user service through \`ours-daemon install-service\`. SDK applications attach to the shared daemon and do not start an embedded daemon.`);
|
|
23151
23163
|
this.endpoint = n;
|
|
@@ -23155,20 +23167,20 @@ var Y = class extends u2 {
|
|
|
23155
23167
|
};
|
|
23156
23168
|
var me = K.port;
|
|
23157
23169
|
var X = $2;
|
|
23158
|
-
var
|
|
23159
|
-
var
|
|
23170
|
+
var Pe = ".ours";
|
|
23171
|
+
var ke = ["explicit", "environment", "config-file"];
|
|
23160
23172
|
function De(e2 = {}) {
|
|
23161
23173
|
let t = e2.env ?? process.env;
|
|
23162
|
-
if (t.OURS_TLS_CERT !== void 0 || t.OURS_TLS_KEY !== void 0) throw new
|
|
23163
|
-
if (e2.endpoint !== void 0 && new URL(e2.endpoint).protocol !== "http:" && new URL(e2.endpoint).protocol !== "https:") throw new
|
|
23174
|
+
if (t.OURS_TLS_CERT !== void 0 || t.OURS_TLS_KEY !== void 0) throw new p("INCOHERENT_SELECTION", "Daemon TLS is not supported in V1; remove OURS_TLS_CERT/OURS_TLS_KEY and explicitly configure HTTP");
|
|
23175
|
+
if (e2.endpoint !== void 0 && new URL(e2.endpoint).protocol !== "http:" && new URL(e2.endpoint).protocol !== "https:") throw new p("INCOHERENT_SELECTION", "Client requires an HTTP or HTTPS daemon endpoint");
|
|
23164
23176
|
let n = e2.readTextFile ?? ((y2) => xe(y2, "utf8")), r = e2.homeDir ?? Ne(), i = M2(t, "OURS_INSTANCE");
|
|
23165
|
-
if (i !== void 0) throw new
|
|
23177
|
+
if (i !== void 0) throw new p("INCOHERENT_SELECTION", `OURS_INSTANCE=${JSON.stringify(i)} is set, but named daemon instances are not implemented. Select the daemon with an explicit endpoint/port option or with OURS_PORT, and unset OURS_INSTANCE.`);
|
|
23166
23178
|
if (e2.stateDir !== void 0 && e2.expectStateDir !== void 0) {
|
|
23167
23179
|
let y2 = H(e2.stateDir), h = H(e2.expectStateDir);
|
|
23168
|
-
if (y2 !== h) throw new
|
|
23180
|
+
if (y2 !== h) throw new p("INCOHERENT_SELECTION", `stateDir ${JSON.stringify(y2)} and expectStateDir ${JSON.stringify(h)} name different directories. The state directory decides which token is read; the expected one decides which daemon that token may be sent to. Reconcile them, or pass only one.`);
|
|
23169
23181
|
}
|
|
23170
|
-
let o = $e(e2.configPath, M2(t, "OURS_CONFIG")), s = o ? Ue(o.value, n) : {}, a = fe(e2.port, Fe(M2(t, "OURS_PORT")), s.port, me), c = fe(e2.stateDir ?? e2.expectStateDir, M2(t, "OURS_STATE_DIR"), s.stateDir, J(r,
|
|
23171
|
-
Ce({ endpointSelected: e2.endpoint !== void 0 || a.source !== "default", endpointSource: f.source, stateDirIntentional:
|
|
23182
|
+
let o = $e(e2.configPath, M2(t, "OURS_CONFIG")), s = o ? Ue(o.value, n) : {}, a = fe(e2.port, Fe(M2(t, "OURS_PORT")), s.port, me), c = fe(e2.stateDir ?? e2.expectStateDir, M2(t, "OURS_STATE_DIR"), s.stateDir, J(r, Pe)), l = { value: H(c.value), source: c.source }, f = e2.endpoint !== void 0 ? { value: w2(e2.endpoint), source: "explicit" } : { value: `http://127.0.0.1:${a.value}`, source: a.source }, m2 = M2(t, "OURS_API_TOKEN");
|
|
23183
|
+
Ce({ endpointSelected: e2.endpoint !== void 0 || a.source !== "default", endpointSource: f.source, stateDirIntentional: ke.includes(l.source), stateDirSource: l.source, hasExplicitToken: e2.token !== void 0 && e2.token !== "", hasEnvToken: m2 !== void 0, requireExplicitSelection: e2.requireExplicitSelection === true, portSource: a.source });
|
|
23172
23184
|
let g = Le(e2.token, m2, s, l, e2.readTextFile);
|
|
23173
23185
|
return { baseUrl: f, port: a, stateDir: l, expectStateDir: e2.expectStateDir !== void 0 ? H(e2.expectStateDir) : l.value, ...g ? { token: g } : {}, ...o ? { configPath: o } : {} };
|
|
23174
23186
|
}
|
|
@@ -23182,7 +23194,7 @@ function Ce(e2) {
|
|
|
23182
23194
|
if (e2.hasExplicitToken && !e2.stateDirIntentional) throw $3("an explicit token was given, but the state directory is the built-in default, so there would be nothing to assert the daemon against before the token is sent. Pass expectStateDir (or stateDir) naming the state directory that token belongs to.");
|
|
23183
23195
|
}
|
|
23184
23196
|
function $3(e2) {
|
|
23185
|
-
return new
|
|
23197
|
+
return new p("INCOHERENT_SELECTION", e2);
|
|
23186
23198
|
}
|
|
23187
23199
|
function Le(e2, t, n, r, i) {
|
|
23188
23200
|
if (e2 !== void 0 && e2 !== "") return { value: e2, source: "explicit" };
|
|
@@ -23204,33 +23216,33 @@ function Ue(e2, t) {
|
|
|
23204
23216
|
try {
|
|
23205
23217
|
n = t(e2);
|
|
23206
23218
|
} catch {
|
|
23207
|
-
throw new
|
|
23219
|
+
throw new p("CONFIG_UNREADABLE", `the daemon config file ${JSON.stringify(e2)} could not be read.`);
|
|
23208
23220
|
}
|
|
23209
23221
|
let r;
|
|
23210
23222
|
try {
|
|
23211
23223
|
r = JSON.parse(n);
|
|
23212
23224
|
} catch {
|
|
23213
|
-
throw new
|
|
23225
|
+
throw new p("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} is not valid JSON.`);
|
|
23214
23226
|
}
|
|
23215
|
-
if (r === null || typeof r != "object" || Array.isArray(r)) throw new
|
|
23227
|
+
if (r === null || typeof r != "object" || Array.isArray(r)) throw new p("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} is not a JSON object.`);
|
|
23216
23228
|
let i = r, o = {}, s = i.port;
|
|
23217
23229
|
if (s !== void 0) {
|
|
23218
|
-
if (typeof s != "number" || !Number.isInteger(s) || s < 1 || s > 65535) throw new
|
|
23230
|
+
if (typeof s != "number" || !Number.isInteger(s) || s < 1 || s > 65535) throw new p("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} declares an invalid port; expected an integer 1-65535.`);
|
|
23219
23231
|
o.port = s;
|
|
23220
23232
|
}
|
|
23221
23233
|
let a = i.stateDir;
|
|
23222
23234
|
if (a !== void 0) {
|
|
23223
|
-
if (typeof a != "string" || a.trim() === "") throw new
|
|
23235
|
+
if (typeof a != "string" || a.trim() === "") throw new p("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} declares an invalid stateDir; expected a non-empty string.`);
|
|
23224
23236
|
o.stateDir = a;
|
|
23225
23237
|
}
|
|
23226
23238
|
let c = i.apiToken;
|
|
23227
23239
|
if (c !== void 0) {
|
|
23228
|
-
if (typeof c != "string" || c.trim() === "") throw new
|
|
23240
|
+
if (typeof c != "string" || c.trim() === "") throw new p("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} declares an invalid apiToken; expected a non-empty string.`);
|
|
23229
23241
|
o.apiToken = c;
|
|
23230
23242
|
}
|
|
23231
23243
|
let l = i.apiVisibility;
|
|
23232
23244
|
if (l !== void 0) {
|
|
23233
|
-
if (l !== "owner" && l !== "shared" && l !== "open") throw new
|
|
23245
|
+
if (l !== "owner" && l !== "shared" && l !== "open") throw new p("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} declares an unknown apiVisibility ${JSON.stringify(l)}; expected "owner", "shared" or "open".`);
|
|
23234
23246
|
o.apiVisibility = l;
|
|
23235
23247
|
}
|
|
23236
23248
|
return o;
|
|
@@ -23244,7 +23256,7 @@ function M2(e2, t) {
|
|
|
23244
23256
|
function Fe(e2) {
|
|
23245
23257
|
if (e2 === void 0) return;
|
|
23246
23258
|
let t = Number.parseInt(e2, 10);
|
|
23247
|
-
if (!Number.isInteger(t) || t < 1 || t > 65535) throw new
|
|
23259
|
+
if (!Number.isInteger(t) || t < 1 || t > 65535) throw new p("INCOHERENT_SELECTION", `OURS_PORT=${JSON.stringify(e2)} is not a TCP port between 1 and 65535.`);
|
|
23248
23260
|
return t;
|
|
23249
23261
|
}
|
|
23250
23262
|
function fe(e2, t, n, r) {
|
|
@@ -23257,21 +23269,21 @@ function $e(e2, t) {
|
|
|
23257
23269
|
async function Me(e2, t = {}) {
|
|
23258
23270
|
let n = t.fetch ?? globalThis.fetch, r = new AbortController(), i = setTimeout(() => r.abort(), t.timeoutMs ?? 5e3), o;
|
|
23259
23271
|
try {
|
|
23260
|
-
let a = await n(
|
|
23261
|
-
if (!a.ok) throw new
|
|
23272
|
+
let a = await n(u2(e2.baseUrl.value, "/state-dir"), { signal: r.signal, redirect: "error" });
|
|
23273
|
+
if (!a.ok) throw new p("INCOHERENT_SELECTION", `${D(u2(e2.baseUrl.value, "/state-dir"))} answered HTTP ${a.status}, so the daemon at that address could not be identified. Refusing to send a credential to it.`);
|
|
23262
23274
|
o = await a.json();
|
|
23263
23275
|
} catch (a) {
|
|
23264
|
-
throw a instanceof
|
|
23276
|
+
throw a instanceof p ? a : new Y(e2.baseUrl.value, e2.expectStateDir, { cause: a });
|
|
23265
23277
|
} finally {
|
|
23266
23278
|
clearTimeout(i);
|
|
23267
23279
|
}
|
|
23268
23280
|
let s = typeof o.stateDir == "string" ? H(o.stateDir) : null;
|
|
23269
|
-
if (s === null) throw new
|
|
23270
|
-
if (s !== e2.expectStateDir) throw new
|
|
23281
|
+
if (s === null) throw new p("INCOHERENT_SELECTION", `${D(u2(e2.baseUrl.value, "/state-dir"))} did not report a state directory, so this is not an ours daemon or not one this client understands. Refusing to send a credential to it.`);
|
|
23282
|
+
if (s !== e2.expectStateDir) throw new p("INCOHERENT_SELECTION", `the daemon at ${D(e2.baseUrl.value)} owns state directory ${JSON.stringify(s)}, but this selection expects ${JSON.stringify(e2.expectStateDir)}. The token belongs to the expected directory, so it is NOT being sent. Point the endpoint and the state directory at the same daemon.`);
|
|
23271
23283
|
}
|
|
23272
23284
|
async function Q(e2 = {}) {
|
|
23273
23285
|
if (e2.endpoint === void 0 && e2.port === void 0 && e2.stateDir === void 0 && e2.expectStateDir === void 0) {
|
|
23274
|
-
let g =
|
|
23286
|
+
let g = ue({ ...e2.env ?? process.env, ...e2.configPath === void 0 ? {} : { OURS_CONFIG: e2.configPath } });
|
|
23275
23287
|
return Q({ ...e2, endpoint: g.endpoint, expectedInstanceId: g.expectedInstanceId, credentialPath: g.credentialPath, sessionMode: "external", leaseToken: e2.leaseToken ?? W(32).toString("hex"), env: {} });
|
|
23276
23288
|
}
|
|
23277
23289
|
if ("serverCertificate" in e2 && e2.serverCertificate !== void 0) throw new Error("Custom serverCertificate is not supported; HTTPS uses Node certificate trust, including NODE_EXTRA_CA_CERTS");
|
|
@@ -23296,7 +23308,7 @@ async function Q(e2 = {}) {
|
|
|
23296
23308
|
if (i === "external") T2.includes("external-sessions-v1") || T2.push("external-sessions-v1");
|
|
23297
23309
|
else if (T2.includes("external-sessions-v1")) throw new Error("External capabilities require explicit sessionMode: external; refusing local-mode fallback");
|
|
23298
23310
|
{
|
|
23299
|
-
let b2 = await globalThis.fetch(
|
|
23311
|
+
let b2 = await globalThis.fetch(u2(h, "/selection"), { signal: s ? AbortSignal.any([s, AbortSignal.timeout(5e3)]) : AbortSignal.timeout(5e3), redirect: "error" }), _ = await C(b2);
|
|
23300
23312
|
if (!b2.ok || !_ || Object.keys(_).length !== 3 || Object.keys(_).some((O2) => !["schema", "instanceId", "capabilities"].includes(O2)) || _.schema !== 1 || _.instanceId !== a) throw new Error("Daemon instance selection metadata is absent, incompatible or mismatched");
|
|
23301
23313
|
let A2 = _.capabilities;
|
|
23302
23314
|
if (!Array.isArray(A2) || A2.some((O2) => typeof O2 != "string") || T2.some((O2) => !A2.includes(O2))) throw new Error("Daemon does not support the required capabilities; refusing local-mode fallback");
|
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-JNUHR327.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-MC4XRZPS.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.4",
|
|
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",
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@eslint-community/regexpp": "4.12.2",
|
|
44
|
-
"@ours.network/sdk": "
|
|
44
|
+
"@ours.network/sdk": "6.1.0",
|
|
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": "
|
|
51
|
-
"@ours.network/daemon": "
|
|
50
|
+
"@ours.network/cli": "5.1.0",
|
|
51
|
+
"@ours.network/daemon": "6.1.0",
|
|
52
52
|
"@playwright/test": "^1.62.1",
|
|
53
53
|
"@types/node": "^20.14.0",
|
|
54
54
|
"@types/web-push": "^3.6.4",
|