@essentialai/cogent-bridge-bundled 3.23.3 → 3.23.5
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/cogent-bridge.mjs +649 -317
- package/package.json +1 -1
package/cogent-bridge.mjs
CHANGED
|
@@ -1259,8 +1259,8 @@ var init_parseUtil = __esm({
|
|
|
1259
1259
|
init_errors();
|
|
1260
1260
|
init_en();
|
|
1261
1261
|
makeIssue = (params) => {
|
|
1262
|
-
const { data, path:
|
|
1263
|
-
const fullPath = [...
|
|
1262
|
+
const { data, path: path24, errorMaps, issueData } = params;
|
|
1263
|
+
const fullPath = [...path24, ...issueData.path || []];
|
|
1264
1264
|
const fullIssue = {
|
|
1265
1265
|
...issueData,
|
|
1266
1266
|
path: fullPath
|
|
@@ -1540,11 +1540,11 @@ var init_types = __esm({
|
|
|
1540
1540
|
init_parseUtil();
|
|
1541
1541
|
init_util();
|
|
1542
1542
|
ParseInputLazyPath = class {
|
|
1543
|
-
constructor(parent, value,
|
|
1543
|
+
constructor(parent, value, path24, key) {
|
|
1544
1544
|
this._cachedPath = [];
|
|
1545
1545
|
this.parent = parent;
|
|
1546
1546
|
this.data = value;
|
|
1547
|
-
this._path =
|
|
1547
|
+
this._path = path24;
|
|
1548
1548
|
this._key = key;
|
|
1549
1549
|
}
|
|
1550
1550
|
get path() {
|
|
@@ -4996,10 +4996,10 @@ function assignProp(target, prop, value) {
|
|
|
4996
4996
|
configurable: true
|
|
4997
4997
|
});
|
|
4998
4998
|
}
|
|
4999
|
-
function getElementAtPath(obj,
|
|
5000
|
-
if (!
|
|
4999
|
+
function getElementAtPath(obj, path24) {
|
|
5000
|
+
if (!path24)
|
|
5001
5001
|
return obj;
|
|
5002
|
-
return
|
|
5002
|
+
return path24.reduce((acc, key) => acc?.[key], obj);
|
|
5003
5003
|
}
|
|
5004
5004
|
function promiseAllObject(promisesObj) {
|
|
5005
5005
|
const keys = Object.keys(promisesObj);
|
|
@@ -5248,11 +5248,11 @@ function aborted(x, startIndex = 0) {
|
|
|
5248
5248
|
}
|
|
5249
5249
|
return false;
|
|
5250
5250
|
}
|
|
5251
|
-
function prefixIssues(
|
|
5251
|
+
function prefixIssues(path24, issues) {
|
|
5252
5252
|
return issues.map((iss) => {
|
|
5253
5253
|
var _a;
|
|
5254
5254
|
(_a = iss).path ?? (_a.path = []);
|
|
5255
|
-
iss.path.unshift(
|
|
5255
|
+
iss.path.unshift(path24);
|
|
5256
5256
|
return iss;
|
|
5257
5257
|
});
|
|
5258
5258
|
}
|
|
@@ -17058,8 +17058,8 @@ var require_utils = __commonJS({
|
|
|
17058
17058
|
}
|
|
17059
17059
|
return ind;
|
|
17060
17060
|
}
|
|
17061
|
-
function removeDotSegments(
|
|
17062
|
-
let input =
|
|
17061
|
+
function removeDotSegments(path24) {
|
|
17062
|
+
let input = path24;
|
|
17063
17063
|
const output = [];
|
|
17064
17064
|
let nextSlash = -1;
|
|
17065
17065
|
let len = 0;
|
|
@@ -17258,8 +17258,8 @@ var require_schemes = __commonJS({
|
|
|
17258
17258
|
wsComponent.secure = void 0;
|
|
17259
17259
|
}
|
|
17260
17260
|
if (wsComponent.resourceName) {
|
|
17261
|
-
const [
|
|
17262
|
-
wsComponent.path =
|
|
17261
|
+
const [path24, query] = wsComponent.resourceName.split("?");
|
|
17262
|
+
wsComponent.path = path24 && path24 !== "/" ? path24 : void 0;
|
|
17263
17263
|
wsComponent.query = query;
|
|
17264
17264
|
wsComponent.resourceName = void 0;
|
|
17265
17265
|
}
|
|
@@ -20612,12 +20612,12 @@ var require_dist = __commonJS({
|
|
|
20612
20612
|
throw new Error(`Unknown format "${name}"`);
|
|
20613
20613
|
return f;
|
|
20614
20614
|
};
|
|
20615
|
-
function addFormats(ajv, list,
|
|
20615
|
+
function addFormats(ajv, list, fs22, exportName) {
|
|
20616
20616
|
var _a;
|
|
20617
20617
|
var _b;
|
|
20618
20618
|
(_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
|
|
20619
20619
|
for (const f of list)
|
|
20620
|
-
ajv.addFormat(f,
|
|
20620
|
+
ajv.addFormat(f, fs22[f]);
|
|
20621
20621
|
}
|
|
20622
20622
|
module.exports = exports = formatsPlugin;
|
|
20623
20623
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -21729,8 +21729,8 @@ var require_parseUtil = __commonJS({
|
|
|
21729
21729
|
var errors_js_1 = require_errors2();
|
|
21730
21730
|
var en_js_1 = __importDefault(require_en());
|
|
21731
21731
|
var makeIssue2 = (params) => {
|
|
21732
|
-
const { data, path:
|
|
21733
|
-
const fullPath = [...
|
|
21732
|
+
const { data, path: path24, errorMaps, issueData } = params;
|
|
21733
|
+
const fullPath = [...path24, ...issueData.path || []];
|
|
21734
21734
|
const fullIssue = {
|
|
21735
21735
|
...issueData,
|
|
21736
21736
|
path: fullPath
|
|
@@ -21884,11 +21884,11 @@ var require_types2 = __commonJS({
|
|
|
21884
21884
|
var parseUtil_js_1 = require_parseUtil();
|
|
21885
21885
|
var util_js_1 = require_util2();
|
|
21886
21886
|
var ParseInputLazyPath2 = class {
|
|
21887
|
-
constructor(parent, value,
|
|
21887
|
+
constructor(parent, value, path24, key) {
|
|
21888
21888
|
this._cachedPath = [];
|
|
21889
21889
|
this.parent = parent;
|
|
21890
21890
|
this.data = value;
|
|
21891
|
-
this._path =
|
|
21891
|
+
this._path = path24;
|
|
21892
21892
|
this._key = key;
|
|
21893
21893
|
}
|
|
21894
21894
|
get path() {
|
|
@@ -26389,8 +26389,8 @@ var init_stdio2 = __esm({
|
|
|
26389
26389
|
// src/constants.ts
|
|
26390
26390
|
import { createRequire } from "node:module";
|
|
26391
26391
|
function resolveVersion() {
|
|
26392
|
-
if ("3.23.
|
|
26393
|
-
return "3.23.
|
|
26392
|
+
if ("3.23.5") {
|
|
26393
|
+
return "3.23.5";
|
|
26394
26394
|
}
|
|
26395
26395
|
try {
|
|
26396
26396
|
const require2 = createRequire(import.meta.url);
|
|
@@ -27826,7 +27826,7 @@ var init_http_backend = __esm({
|
|
|
27826
27826
|
* in cloud mode we ignore it and use this.sessionId (the cloud session).
|
|
27827
27827
|
*/
|
|
27828
27828
|
async registerPeer(peerId, _sessionId, cwd, label, clientVersion, mode, _channelSessionId, capabilities, workspaceId, threadId, peerSecret) {
|
|
27829
|
-
const
|
|
27829
|
+
const path24 = PATHS.peers.replace(":sessionId", this.sessionId);
|
|
27830
27830
|
const body = {
|
|
27831
27831
|
peerId,
|
|
27832
27832
|
cwd,
|
|
@@ -27857,7 +27857,7 @@ var init_http_backend = __esm({
|
|
|
27857
27857
|
if (peerSecret !== void 0 && await relaySupports(this.http, "peer-ownership")) {
|
|
27858
27858
|
body.peerSecret = peerSecret;
|
|
27859
27859
|
}
|
|
27860
|
-
return this.http.post(
|
|
27860
|
+
return this.http.post(path24, body);
|
|
27861
27861
|
}
|
|
27862
27862
|
/**
|
|
27863
27863
|
* Deregister a peer from the cloud session.
|
|
@@ -27869,9 +27869,9 @@ var init_http_backend = __esm({
|
|
|
27869
27869
|
* local mail creds. A 404 (peer not found) resolves to `{ removed: false, ... }`, not a throw.
|
|
27870
27870
|
*/
|
|
27871
27871
|
async deregisterPeer(peerId) {
|
|
27872
|
-
const
|
|
27872
|
+
const path24 = PATHS.peer.replace(":sessionId", this.sessionId).replace(":peerId", peerId);
|
|
27873
27873
|
try {
|
|
27874
|
-
const headers = await this.http.delete(
|
|
27874
|
+
const headers = await this.http.delete(path24, {});
|
|
27875
27875
|
const mailboxDeprovisioned = headers.get(MAILBOX_DEPROVISIONED_HEADER) === "true";
|
|
27876
27876
|
return { removed: true, mailboxDeprovisioned };
|
|
27877
27877
|
} catch (err) {
|
|
@@ -27895,8 +27895,8 @@ var init_http_backend = __esm({
|
|
|
27895
27895
|
* GET /api/sessions/:sessionId/peers
|
|
27896
27896
|
*/
|
|
27897
27897
|
async listPeers() {
|
|
27898
|
-
const
|
|
27899
|
-
const result = await this.http.get(
|
|
27898
|
+
const path24 = PATHS.peers.replace(":sessionId", this.sessionId);
|
|
27899
|
+
const result = await this.http.get(path24);
|
|
27900
27900
|
return result.peers;
|
|
27901
27901
|
}
|
|
27902
27902
|
/**
|
|
@@ -27904,8 +27904,8 @@ var init_http_backend = __esm({
|
|
|
27904
27904
|
* Calls the lightweight heartbeat endpoint on the cloud relay server.
|
|
27905
27905
|
*/
|
|
27906
27906
|
async updateLastSeen(peerId) {
|
|
27907
|
-
const
|
|
27908
|
-
await this.http.post(
|
|
27907
|
+
const path24 = PATHS.heartbeat.replace(":sessionId", this.sessionId);
|
|
27908
|
+
await this.http.post(path24, { peerId });
|
|
27909
27909
|
}
|
|
27910
27910
|
/**
|
|
27911
27911
|
* Record a message in the cloud session.
|
|
@@ -27916,7 +27916,7 @@ var init_http_backend = __esm({
|
|
|
27916
27916
|
* the input record to construct a full MessageRecord.
|
|
27917
27917
|
*/
|
|
27918
27918
|
async recordMessage(record2) {
|
|
27919
|
-
const
|
|
27919
|
+
const path24 = PATHS.messages.replace(":sessionId", this.sessionId);
|
|
27920
27920
|
const body = {
|
|
27921
27921
|
fromPeerId: record2.fromPeerId,
|
|
27922
27922
|
toPeerId: record2.toPeerId,
|
|
@@ -27939,7 +27939,7 @@ var init_http_backend = __esm({
|
|
|
27939
27939
|
if (record2.attachments && record2.attachments.length > 0) {
|
|
27940
27940
|
body.attachments = record2.attachments;
|
|
27941
27941
|
}
|
|
27942
|
-
const resp = await this.http.post(
|
|
27942
|
+
const resp = await this.http.post(path24, body);
|
|
27943
27943
|
return {
|
|
27944
27944
|
...record2,
|
|
27945
27945
|
id: resp.id,
|
|
@@ -27953,7 +27953,7 @@ var init_http_backend = __esm({
|
|
|
27953
27953
|
* Supports optional peerId filter and limit (default 300).
|
|
27954
27954
|
*/
|
|
27955
27955
|
async getHistory(peerId, limit, includeRelayEchoes, metadataOnly, dedupInferredEchoes) {
|
|
27956
|
-
const
|
|
27956
|
+
const path24 = PATHS.messages.replace(":sessionId", this.sessionId);
|
|
27957
27957
|
const query = {};
|
|
27958
27958
|
if (peerId) {
|
|
27959
27959
|
query.peerId = peerId;
|
|
@@ -27968,7 +27968,7 @@ var init_http_backend = __esm({
|
|
|
27968
27968
|
if (dedupInferredEchoes) {
|
|
27969
27969
|
query.dedupInferredEchoes = "true";
|
|
27970
27970
|
}
|
|
27971
|
-
const result = await this.http.get(
|
|
27971
|
+
const result = await this.http.get(path24, query);
|
|
27972
27972
|
return result.messages;
|
|
27973
27973
|
}
|
|
27974
27974
|
/**
|
|
@@ -27979,12 +27979,12 @@ var init_http_backend = __esm({
|
|
|
27979
27979
|
* so that get-history shows the actual response (not null).
|
|
27980
27980
|
*/
|
|
27981
27981
|
async updateMessageResponse(messageId, response, durationMs, pending) {
|
|
27982
|
-
const
|
|
27982
|
+
const path24 = PATHS.message.replace(":sessionId", this.sessionId).replace(":messageId", messageId);
|
|
27983
27983
|
const body = { response, durationMs };
|
|
27984
27984
|
if (pending === true) {
|
|
27985
27985
|
body.pending = true;
|
|
27986
27986
|
}
|
|
27987
|
-
await this.http.patch(
|
|
27987
|
+
await this.http.patch(path24, body);
|
|
27988
27988
|
}
|
|
27989
27989
|
/**
|
|
27990
27990
|
* Validate a session.
|
|
@@ -28126,8 +28126,8 @@ var init_http_client = __esm({
|
|
|
28126
28126
|
* Perform an authenticated GET request.
|
|
28127
28127
|
* Appends query parameters to the URL if provided.
|
|
28128
28128
|
*/
|
|
28129
|
-
async get(
|
|
28130
|
-
const url = new URL(
|
|
28129
|
+
async get(path24, query) {
|
|
28130
|
+
const url = new URL(path24, this.baseUrl);
|
|
28131
28131
|
if (query) {
|
|
28132
28132
|
for (const [k, v] of Object.entries(query)) {
|
|
28133
28133
|
url.searchParams.set(k, v);
|
|
@@ -28142,8 +28142,8 @@ var init_http_client = __esm({
|
|
|
28142
28142
|
/**
|
|
28143
28143
|
* Perform an authenticated POST request with a JSON body.
|
|
28144
28144
|
*/
|
|
28145
|
-
async post(
|
|
28146
|
-
const url = new URL(
|
|
28145
|
+
async post(path24, body) {
|
|
28146
|
+
const url = new URL(path24, this.baseUrl);
|
|
28147
28147
|
const resp = await this.fetchWithTimeout(url, {
|
|
28148
28148
|
method: "POST",
|
|
28149
28149
|
headers: this.headers(),
|
|
@@ -28161,8 +28161,8 @@ var init_http_client = __esm({
|
|
|
28161
28161
|
* Perform an authenticated PATCH request with a JSON body.
|
|
28162
28162
|
* Used to update existing resources (e.g., message response fields).
|
|
28163
28163
|
*/
|
|
28164
|
-
async patch(
|
|
28165
|
-
const url = new URL(
|
|
28164
|
+
async patch(path24, body) {
|
|
28165
|
+
const url = new URL(path24, this.baseUrl);
|
|
28166
28166
|
const resp = await this.fetchWithTimeout(url, {
|
|
28167
28167
|
method: "PATCH",
|
|
28168
28168
|
headers: this.headers(),
|
|
@@ -28187,8 +28187,8 @@ var init_http_client = __esm({
|
|
|
28187
28187
|
* "Malformed JSON in request body" 400 from cogent-server <=3.1.2 when
|
|
28188
28188
|
* any client (including third-party tools) DELETEd a peer without a body.
|
|
28189
28189
|
*/
|
|
28190
|
-
async delete(
|
|
28191
|
-
const url = new URL(
|
|
28190
|
+
async delete(path24, body) {
|
|
28191
|
+
const url = new URL(path24, this.baseUrl);
|
|
28192
28192
|
const headers = {
|
|
28193
28193
|
"Authorization": `Bearer ${this.token}`
|
|
28194
28194
|
};
|
|
@@ -32393,14 +32393,14 @@ var init_ws_client = __esm({
|
|
|
32393
32393
|
if (this.pollTimer) return;
|
|
32394
32394
|
const poll = async () => {
|
|
32395
32395
|
try {
|
|
32396
|
-
const
|
|
32396
|
+
const path24 = `/api/sessions/${this.opts.sessionId}/poll`;
|
|
32397
32397
|
const query = {
|
|
32398
32398
|
peerId: this.opts.peerId
|
|
32399
32399
|
};
|
|
32400
32400
|
if (this.lastMessageId) {
|
|
32401
32401
|
query.lastMessageId = this.lastMessageId;
|
|
32402
32402
|
}
|
|
32403
|
-
const result = await this.opts.http.get(
|
|
32403
|
+
const result = await this.opts.http.get(path24, query);
|
|
32404
32404
|
if (result.messages && result.messages.length > 0) {
|
|
32405
32405
|
this.opts.onMessages(result.messages);
|
|
32406
32406
|
this.lastMessageId = result.messages[result.messages.length - 1].id;
|
|
@@ -33481,6 +33481,266 @@ var init_wake_claim = __esm({
|
|
|
33481
33481
|
}
|
|
33482
33482
|
});
|
|
33483
33483
|
|
|
33484
|
+
// src/services/wake-lock.ts
|
|
33485
|
+
import crypto7 from "node:crypto";
|
|
33486
|
+
import fs16 from "node:fs";
|
|
33487
|
+
import os12 from "node:os";
|
|
33488
|
+
import path17 from "node:path";
|
|
33489
|
+
function hashCwd5(cwd) {
|
|
33490
|
+
return crypto7.createHash("sha256").update(path17.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33491
|
+
}
|
|
33492
|
+
function wakeLockPath(cwd = process.cwd()) {
|
|
33493
|
+
return path17.join(os12.homedir(), ".cogent", "wake-locks", `${hashCwd5(cwd)}.json`);
|
|
33494
|
+
}
|
|
33495
|
+
function leaseTtlMs() {
|
|
33496
|
+
let timeout = 3e5;
|
|
33497
|
+
try {
|
|
33498
|
+
const c2 = getConfig()?.COGENT_TIMEOUT_MS;
|
|
33499
|
+
if (typeof c2 === "number" && Number.isFinite(c2) && c2 > 0) timeout = c2;
|
|
33500
|
+
} catch {
|
|
33501
|
+
}
|
|
33502
|
+
return Math.min(timeout * LEASE_TIMEOUT_FACTOR, WAKE_LOCK_MAX_MS);
|
|
33503
|
+
}
|
|
33504
|
+
function defaultMaxWaitMs() {
|
|
33505
|
+
try {
|
|
33506
|
+
const c2 = getConfig()?.COGENT_TIMEOUT_MS;
|
|
33507
|
+
if (typeof c2 === "number" && Number.isFinite(c2) && c2 > 0) return c2;
|
|
33508
|
+
} catch {
|
|
33509
|
+
}
|
|
33510
|
+
return 3e5;
|
|
33511
|
+
}
|
|
33512
|
+
function holderAlive2(pid) {
|
|
33513
|
+
if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return false;
|
|
33514
|
+
if (pid === process.pid) return heldDepth > 0;
|
|
33515
|
+
try {
|
|
33516
|
+
process.kill(pid, 0);
|
|
33517
|
+
return true;
|
|
33518
|
+
} catch (err) {
|
|
33519
|
+
return err?.code === "EPERM";
|
|
33520
|
+
}
|
|
33521
|
+
}
|
|
33522
|
+
function readHolder(p) {
|
|
33523
|
+
try {
|
|
33524
|
+
const held = JSON.parse(fs16.readFileSync(p, "utf-8"));
|
|
33525
|
+
if (!held || typeof held.expiresAt !== "number") return null;
|
|
33526
|
+
return held;
|
|
33527
|
+
} catch {
|
|
33528
|
+
return null;
|
|
33529
|
+
}
|
|
33530
|
+
}
|
|
33531
|
+
async function acquireWakeLock(cwd = process.cwd(), sessionId = "unknown", opts = {}) {
|
|
33532
|
+
const p = wakeLockPath(cwd);
|
|
33533
|
+
const maxWaitMs = opts.maxWaitMs ?? defaultMaxWaitMs();
|
|
33534
|
+
const started = Date.now();
|
|
33535
|
+
let contended = false;
|
|
33536
|
+
if (heldDepth > 0) {
|
|
33537
|
+
heldDepth++;
|
|
33538
|
+
let released = false;
|
|
33539
|
+
return {
|
|
33540
|
+
acquired: true,
|
|
33541
|
+
waitedMs: 0,
|
|
33542
|
+
contended: false,
|
|
33543
|
+
release: () => {
|
|
33544
|
+
if (released) return;
|
|
33545
|
+
released = true;
|
|
33546
|
+
heldDepth--;
|
|
33547
|
+
}
|
|
33548
|
+
};
|
|
33549
|
+
}
|
|
33550
|
+
const lease = () => {
|
|
33551
|
+
heldDepth++;
|
|
33552
|
+
let released = false;
|
|
33553
|
+
return {
|
|
33554
|
+
acquired: true,
|
|
33555
|
+
waitedMs: Date.now() - started,
|
|
33556
|
+
contended,
|
|
33557
|
+
release: () => {
|
|
33558
|
+
if (released) return;
|
|
33559
|
+
released = true;
|
|
33560
|
+
heldDepth--;
|
|
33561
|
+
if (heldDepth === 0) releaseWakeLock(cwd);
|
|
33562
|
+
}
|
|
33563
|
+
};
|
|
33564
|
+
};
|
|
33565
|
+
const failOpen = (why) => {
|
|
33566
|
+
logger.warn(`wake-lock: ${why} \u2014 waking anyway (fail-open)`);
|
|
33567
|
+
return { acquired: true, waitedMs: Date.now() - started, contended, release: () => {
|
|
33568
|
+
} };
|
|
33569
|
+
};
|
|
33570
|
+
try {
|
|
33571
|
+
fs16.mkdirSync(path17.dirname(p), { recursive: true });
|
|
33572
|
+
} catch (err) {
|
|
33573
|
+
return failOpen(`cannot create lock dir (${err.message})`);
|
|
33574
|
+
}
|
|
33575
|
+
for (; ; ) {
|
|
33576
|
+
const now = Date.now();
|
|
33577
|
+
const body = JSON.stringify({
|
|
33578
|
+
pid: process.pid,
|
|
33579
|
+
sessionId,
|
|
33580
|
+
startedAt: now,
|
|
33581
|
+
expiresAt: now + leaseTtlMs()
|
|
33582
|
+
});
|
|
33583
|
+
try {
|
|
33584
|
+
fs16.writeFileSync(p, body, { flag: "wx" });
|
|
33585
|
+
if (contended) {
|
|
33586
|
+
logger.info(
|
|
33587
|
+
`Auto-relay: waited ${Date.now() - started}ms for another bridge process to finish its turn in this checkout before resuming \u2014 turns are serialised, not overlapping.`
|
|
33588
|
+
);
|
|
33589
|
+
}
|
|
33590
|
+
return lease();
|
|
33591
|
+
} catch (err) {
|
|
33592
|
+
if (err?.code !== "EEXIST") {
|
|
33593
|
+
return failOpen(`cannot write lock (${err.message})`);
|
|
33594
|
+
}
|
|
33595
|
+
}
|
|
33596
|
+
const held = readHolder(p);
|
|
33597
|
+
if (!held || held.expiresAt <= now || !holderAlive2(held.pid)) {
|
|
33598
|
+
try {
|
|
33599
|
+
fs16.writeFileSync(p, body);
|
|
33600
|
+
} catch (err) {
|
|
33601
|
+
return failOpen(`cannot steal abandoned lock (${err.message})`);
|
|
33602
|
+
}
|
|
33603
|
+
logger.debug(`wake-lock: took over an abandoned lease in ${cwd}`);
|
|
33604
|
+
return lease();
|
|
33605
|
+
}
|
|
33606
|
+
if (!contended) {
|
|
33607
|
+
contended = true;
|
|
33608
|
+
logger.info(
|
|
33609
|
+
`Auto-relay: pid ${held.pid} is already running an agent turn in this checkout (session ${held.sessionId}) \u2014 waiting for it rather than running a second resume over the same worktree. Two bridge processes are live for this cwd; if that is unexpected, check for a stale one left behind by a plugin update.`
|
|
33610
|
+
);
|
|
33611
|
+
}
|
|
33612
|
+
if (Date.now() - started >= maxWaitMs) {
|
|
33613
|
+
return failOpen(
|
|
33614
|
+
`pid ${held.pid} still holds this checkout after ${Date.now() - started}ms`
|
|
33615
|
+
);
|
|
33616
|
+
}
|
|
33617
|
+
await sleep3(POLL_MS);
|
|
33618
|
+
}
|
|
33619
|
+
}
|
|
33620
|
+
function releaseWakeLock(cwd = process.cwd()) {
|
|
33621
|
+
try {
|
|
33622
|
+
fs16.unlinkSync(wakeLockPath(cwd));
|
|
33623
|
+
} catch {
|
|
33624
|
+
}
|
|
33625
|
+
}
|
|
33626
|
+
var WAKE_LOCK_MAX_MS, LEASE_TIMEOUT_FACTOR, POLL_MS, heldDepth, sleep3;
|
|
33627
|
+
var init_wake_lock = __esm({
|
|
33628
|
+
"src/services/wake-lock.ts"() {
|
|
33629
|
+
"use strict";
|
|
33630
|
+
init_config();
|
|
33631
|
+
init_logger();
|
|
33632
|
+
WAKE_LOCK_MAX_MS = 18e5;
|
|
33633
|
+
LEASE_TIMEOUT_FACTOR = 3;
|
|
33634
|
+
POLL_MS = 250;
|
|
33635
|
+
heldDepth = 0;
|
|
33636
|
+
sleep3 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
33637
|
+
}
|
|
33638
|
+
});
|
|
33639
|
+
|
|
33640
|
+
// src/services/wake-ownership.ts
|
|
33641
|
+
import crypto8 from "node:crypto";
|
|
33642
|
+
import fs17 from "node:fs";
|
|
33643
|
+
import os13 from "node:os";
|
|
33644
|
+
import path18 from "node:path";
|
|
33645
|
+
function hashCwd6(cwd) {
|
|
33646
|
+
return crypto8.createHash("sha256").update(path18.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33647
|
+
}
|
|
33648
|
+
function bridgeDirFor(cwd, peerId) {
|
|
33649
|
+
return path18.join(os13.homedir(), ".cogent", "bridges", `${hashCwd6(cwd)}.${safe3(peerId)}`);
|
|
33650
|
+
}
|
|
33651
|
+
function pidAlive(pid) {
|
|
33652
|
+
if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return false;
|
|
33653
|
+
if (pid === process.pid) return true;
|
|
33654
|
+
try {
|
|
33655
|
+
process.kill(pid, 0);
|
|
33656
|
+
return true;
|
|
33657
|
+
} catch (err) {
|
|
33658
|
+
return err?.code === "EPERM";
|
|
33659
|
+
}
|
|
33660
|
+
}
|
|
33661
|
+
function announceBridge(cwd, peerId, version2, endpoint) {
|
|
33662
|
+
const dir = bridgeDirFor(cwd, peerId);
|
|
33663
|
+
try {
|
|
33664
|
+
fs17.mkdirSync(dir, { recursive: true });
|
|
33665
|
+
const entry = {
|
|
33666
|
+
pid: process.pid,
|
|
33667
|
+
startedAt: PROCESS_STARTED_AT,
|
|
33668
|
+
version: version2,
|
|
33669
|
+
peerId,
|
|
33670
|
+
endpoint,
|
|
33671
|
+
cwd: path18.resolve(cwd)
|
|
33672
|
+
};
|
|
33673
|
+
fs17.writeFileSync(path18.join(dir, `${process.pid}.json`), JSON.stringify(entry));
|
|
33674
|
+
} catch (err) {
|
|
33675
|
+
logger.debug(`wake-ownership: could not announce this bridge (${err.message})`);
|
|
33676
|
+
}
|
|
33677
|
+
}
|
|
33678
|
+
function withdrawBridge(cwd, peerId) {
|
|
33679
|
+
try {
|
|
33680
|
+
fs17.unlinkSync(path18.join(bridgeDirFor(cwd, peerId), `${process.pid}.json`));
|
|
33681
|
+
} catch {
|
|
33682
|
+
}
|
|
33683
|
+
}
|
|
33684
|
+
function listLiveBridges(cwd, peerId) {
|
|
33685
|
+
const dir = bridgeDirFor(cwd, peerId);
|
|
33686
|
+
let names;
|
|
33687
|
+
try {
|
|
33688
|
+
names = fs17.readdirSync(dir);
|
|
33689
|
+
} catch {
|
|
33690
|
+
return [];
|
|
33691
|
+
}
|
|
33692
|
+
const live = [];
|
|
33693
|
+
for (const name of names) {
|
|
33694
|
+
if (!name.endsWith(".json")) continue;
|
|
33695
|
+
const p = path18.join(dir, name);
|
|
33696
|
+
let entry = null;
|
|
33697
|
+
try {
|
|
33698
|
+
entry = JSON.parse(fs17.readFileSync(p, "utf-8"));
|
|
33699
|
+
} catch {
|
|
33700
|
+
entry = null;
|
|
33701
|
+
}
|
|
33702
|
+
if (!entry || !pidAlive(entry.pid) || typeof entry.startedAt !== "number") {
|
|
33703
|
+
try {
|
|
33704
|
+
fs17.unlinkSync(p);
|
|
33705
|
+
} catch {
|
|
33706
|
+
}
|
|
33707
|
+
continue;
|
|
33708
|
+
}
|
|
33709
|
+
live.push(entry);
|
|
33710
|
+
}
|
|
33711
|
+
live.sort((a, b) => b.startedAt - a.startedAt || b.pid - a.pid);
|
|
33712
|
+
return live;
|
|
33713
|
+
}
|
|
33714
|
+
function checkWakeOwnership(cwd, peerId) {
|
|
33715
|
+
let live;
|
|
33716
|
+
try {
|
|
33717
|
+
live = listLiveBridges(cwd, peerId);
|
|
33718
|
+
} catch (err) {
|
|
33719
|
+
logger.warn(`wake-ownership: could not read bridge registry (${err.message}) \u2014 assuming ownership`);
|
|
33720
|
+
return { isOwner: true, liveCount: 1 };
|
|
33721
|
+
}
|
|
33722
|
+
if (live.length === 0) return { isOwner: true, liveCount: 0 };
|
|
33723
|
+
const owner = live[0];
|
|
33724
|
+
if (owner.pid === process.pid) return { isOwner: true, liveCount: live.length };
|
|
33725
|
+
if (live.some((e) => e.pid === process.pid)) {
|
|
33726
|
+
return {
|
|
33727
|
+
isOwner: false,
|
|
33728
|
+
owner: { pid: owner.pid, version: owner.version, endpoint: owner.endpoint },
|
|
33729
|
+
liveCount: live.length
|
|
33730
|
+
};
|
|
33731
|
+
}
|
|
33732
|
+
return { isOwner: true, liveCount: live.length + 1 };
|
|
33733
|
+
}
|
|
33734
|
+
var PROCESS_STARTED_AT, safe3;
|
|
33735
|
+
var init_wake_ownership = __esm({
|
|
33736
|
+
"src/services/wake-ownership.ts"() {
|
|
33737
|
+
"use strict";
|
|
33738
|
+
init_logger();
|
|
33739
|
+
PROCESS_STARTED_AT = Date.now() - Math.floor(process.uptime() * 1e3);
|
|
33740
|
+
safe3 = (s) => String(s).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
33741
|
+
}
|
|
33742
|
+
});
|
|
33743
|
+
|
|
33484
33744
|
// src/services/auto-relay.ts
|
|
33485
33745
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
33486
33746
|
function buildStatusNotice(status, peerId, traceId) {
|
|
@@ -33621,6 +33881,9 @@ var init_auto_relay = __esm({
|
|
|
33621
33881
|
init_codex_cli();
|
|
33622
33882
|
init_wake_inflight();
|
|
33623
33883
|
init_wake_claim();
|
|
33884
|
+
init_wake_lock();
|
|
33885
|
+
init_wake_ownership();
|
|
33886
|
+
init_constants();
|
|
33624
33887
|
init_logger();
|
|
33625
33888
|
init_npm_update_check();
|
|
33626
33889
|
RELAY_STATUS = {
|
|
@@ -33667,6 +33930,8 @@ var init_auto_relay = __esm({
|
|
|
33667
33930
|
*/
|
|
33668
33931
|
localLabel = null;
|
|
33669
33932
|
processing = false;
|
|
33933
|
+
/** Senders already told this bridge is superseded — one notice each, not one per message. */
|
|
33934
|
+
supersededNotified = /* @__PURE__ */ new Set();
|
|
33670
33935
|
queue = [];
|
|
33671
33936
|
// Message ids to be handled inject-only (full-group-chat awareness) rather than
|
|
33672
33937
|
// full-wake+reply. Shares the `processing` lock + `queue` so an awareness inject
|
|
@@ -33713,6 +33978,8 @@ var init_auto_relay = __esm({
|
|
|
33713
33978
|
logger.info(
|
|
33714
33979
|
`Auto-relay configured for peer ${peerId} (session: ${sessionId}, pinned: ${this.pinnedSessionId}, mode: ${this.localMode}, label: ${this.localLabel})`
|
|
33715
33980
|
);
|
|
33981
|
+
announceBridge(cwd, peerId, CLIENT_VERSION, getConfig().COGENT_ENDPOINT ?? "local");
|
|
33982
|
+
this.supersededNotified.clear();
|
|
33716
33983
|
}
|
|
33717
33984
|
/**
|
|
33718
33985
|
* Emit one content-free wake-trace line (ids/decisions/timings only — NEVER
|
|
@@ -34077,6 +34344,13 @@ var init_auto_relay = __esm({
|
|
|
34077
34344
|
);
|
|
34078
34345
|
}
|
|
34079
34346
|
}
|
|
34347
|
+
if (this.localPeerId && this.localCwd) {
|
|
34348
|
+
const own = checkWakeOwnership(this.localCwd, this.localPeerId);
|
|
34349
|
+
if (!own.isOwner) {
|
|
34350
|
+
await this._reportSuperseded(msg, own.owner);
|
|
34351
|
+
return;
|
|
34352
|
+
}
|
|
34353
|
+
}
|
|
34080
34354
|
if (this.localPeerId && !this.awarenessOnly.has(msg.id)) {
|
|
34081
34355
|
if (!claimWake(this.localPeerId, msg.id, this.localCwd ?? process.cwd())) {
|
|
34082
34356
|
return;
|
|
@@ -34107,6 +34381,40 @@ var init_auto_relay = __esm({
|
|
|
34107
34381
|
}
|
|
34108
34382
|
}
|
|
34109
34383
|
}
|
|
34384
|
+
/**
|
|
34385
|
+
* Tell the sender we are a LEFTOVER bridge and are not answering — instead of going silent.
|
|
34386
|
+
*
|
|
34387
|
+
* Silence is the failure mode this codebase treats as worst: it is indistinguishable from
|
|
34388
|
+
* "nothing to do". A superseded bridge is usually reachable on a channel the newer bridge is NOT
|
|
34389
|
+
* on (the measured case had the ghost on the FREE relay and the live one on TEAM), so without
|
|
34390
|
+
* this the sender would wait forever with no explanation.
|
|
34391
|
+
*
|
|
34392
|
+
* Once per sender per process — a leftover that is being messaged steadily must not turn into a
|
|
34393
|
+
* notice generator.
|
|
34394
|
+
*/
|
|
34395
|
+
async _reportSuperseded(msg, owner) {
|
|
34396
|
+
const who = owner ? `pid ${owner.pid} (v${owner.version}, ${owner.endpoint})` : "a newer bridge";
|
|
34397
|
+
logger.warn(
|
|
34398
|
+
`Auto-relay: NOT waking for ${msg.fromPeerId} \u2014 this bridge (pid ${process.pid}, v${CLIENT_VERSION}) has been superseded for peer "${this.localPeerId}" in this checkout by ${who}. It is a leftover process; the newer bridge is answering. Standing down.`
|
|
34399
|
+
);
|
|
34400
|
+
if (this.supersededNotified.has(msg.fromPeerId)) return;
|
|
34401
|
+
this.supersededNotified.add(msg.fromPeerId);
|
|
34402
|
+
try {
|
|
34403
|
+
await getBackend().recordMessage({
|
|
34404
|
+
fromPeerId: this.localPeerId,
|
|
34405
|
+
toPeerId: msg.fromPeerId,
|
|
34406
|
+
message: `\u26A0\uFE0F "${this.localPeerId}" is not answering on this channel: this bridge process is a leftover (v${CLIENT_VERSION}) that a newer one has replaced in the same checkout. Send to the agent on its current channel instead.`,
|
|
34407
|
+
response: null,
|
|
34408
|
+
durationMs: 0,
|
|
34409
|
+
success: false,
|
|
34410
|
+
error: "BRIDGE_SUPERSEDED",
|
|
34411
|
+
isRelayEcho: true,
|
|
34412
|
+
traceId: msg.traceId
|
|
34413
|
+
});
|
|
34414
|
+
} catch (err) {
|
|
34415
|
+
logger.error(`Auto-relay: failed to record superseded notice: ${err}`);
|
|
34416
|
+
}
|
|
34417
|
+
}
|
|
34110
34418
|
/**
|
|
34111
34419
|
* Dispatch a message under the `processing` lock: an awareness-marked broadcast is
|
|
34112
34420
|
* inject-only (see, no reply); everything else is a full wake+reply. Routing both
|
|
@@ -34222,6 +34530,7 @@ var init_auto_relay = __esm({
|
|
|
34222
34530
|
let wakeExitCode = null;
|
|
34223
34531
|
let refused = false;
|
|
34224
34532
|
let threw = false;
|
|
34533
|
+
let wakeLease = null;
|
|
34225
34534
|
try {
|
|
34226
34535
|
const res = await this.refreshSessionId();
|
|
34227
34536
|
this._trace(traceId, "resolved", {
|
|
@@ -34260,6 +34569,7 @@ var init_auto_relay = __esm({
|
|
|
34260
34569
|
decision: res.decision,
|
|
34261
34570
|
confidence: res.confidence
|
|
34262
34571
|
});
|
|
34572
|
+
wakeLease = await acquireWakeLock(this.localCwd, this.localSessionId);
|
|
34263
34573
|
treeBefore = captureTreeState(this.localCwd);
|
|
34264
34574
|
const result = await execRemote(
|
|
34265
34575
|
getConfig().COGENT_PLATFORM,
|
|
@@ -34348,6 +34658,7 @@ var init_auto_relay = __esm({
|
|
|
34348
34658
|
});
|
|
34349
34659
|
}
|
|
34350
34660
|
} finally {
|
|
34661
|
+
wakeLease?.release();
|
|
34351
34662
|
this._recordWake(msg, traceId, {
|
|
34352
34663
|
outcome: threw ? "threw" : refused ? "refused" : replied ? "replied" : "failed",
|
|
34353
34664
|
exitCode: wakeExitCode,
|
|
@@ -34436,6 +34747,7 @@ var init_auto_relay = __esm({
|
|
|
34436
34747
|
} catch {
|
|
34437
34748
|
}
|
|
34438
34749
|
const formatted = formatInjectOnlyMessage(fromLabel, msg.fromPeerId, msg.message, msg.attachments);
|
|
34750
|
+
const lease = await acquireWakeLock(this.localCwd, this.localSessionId);
|
|
34439
34751
|
try {
|
|
34440
34752
|
await this.refreshSessionId();
|
|
34441
34753
|
const result = await execRemote(
|
|
@@ -34451,6 +34763,8 @@ var init_auto_relay = __esm({
|
|
|
34451
34763
|
}
|
|
34452
34764
|
} catch (err) {
|
|
34453
34765
|
logger.error(`Auto-relay: inject-only execRemote threw: ${err}`);
|
|
34766
|
+
} finally {
|
|
34767
|
+
lease.release();
|
|
34454
34768
|
}
|
|
34455
34769
|
}
|
|
34456
34770
|
/**
|
|
@@ -34471,6 +34785,7 @@ var init_auto_relay = __esm({
|
|
|
34471
34785
|
} catch {
|
|
34472
34786
|
}
|
|
34473
34787
|
const formatted = formatPeerBroadcastNotice(fromLabel, msg.fromPeerId, msg.message, msg.attachments);
|
|
34788
|
+
const lease = await acquireWakeLock(this.localCwd, this.localSessionId);
|
|
34474
34789
|
try {
|
|
34475
34790
|
await this.refreshSessionId();
|
|
34476
34791
|
const result = await execRemote(
|
|
@@ -34486,6 +34801,8 @@ var init_auto_relay = __esm({
|
|
|
34486
34801
|
}
|
|
34487
34802
|
} catch (err) {
|
|
34488
34803
|
logger.error(`Auto-relay: peer-broadcast awareness inject execRemote threw: ${err}`);
|
|
34804
|
+
} finally {
|
|
34805
|
+
lease.release();
|
|
34489
34806
|
}
|
|
34490
34807
|
}
|
|
34491
34808
|
/**
|
|
@@ -34526,8 +34843,10 @@ var init_auto_relay = __esm({
|
|
|
34526
34843
|
}
|
|
34527
34844
|
this.deliveryAckWaiters.clear();
|
|
34528
34845
|
this.recentAcks.clear();
|
|
34846
|
+
if (this.localCwd && this.localPeerId) withdrawBridge(this.localCwd, this.localPeerId);
|
|
34529
34847
|
this.queue = [];
|
|
34530
34848
|
this.awarenessOnly.clear();
|
|
34849
|
+
this.supersededNotified.clear();
|
|
34531
34850
|
this.localPeerId = null;
|
|
34532
34851
|
this.localSessionId = null;
|
|
34533
34852
|
this.localCwd = null;
|
|
@@ -34781,9 +35100,9 @@ __export(startup_exports, {
|
|
|
34781
35100
|
setInboxNotifier: () => setInboxNotifier,
|
|
34782
35101
|
triggerReRegistration: () => triggerReRegistration
|
|
34783
35102
|
});
|
|
34784
|
-
import
|
|
34785
|
-
import
|
|
34786
|
-
import
|
|
35103
|
+
import os14 from "node:os";
|
|
35104
|
+
import path19 from "node:path";
|
|
35105
|
+
import fs18 from "node:fs/promises";
|
|
34787
35106
|
import readline2 from "node:readline";
|
|
34788
35107
|
import { execFile as execFile5 } from "node:child_process";
|
|
34789
35108
|
import { promisify as promisify4 } from "node:util";
|
|
@@ -34801,7 +35120,7 @@ function bindInboxNotifier() {
|
|
|
34801
35120
|
}
|
|
34802
35121
|
async function loadPersistedConfig() {
|
|
34803
35122
|
try {
|
|
34804
|
-
const raw = await
|
|
35123
|
+
const raw = await fs18.readFile(PERSIST_PATH, "utf-8");
|
|
34805
35124
|
return JSON.parse(raw);
|
|
34806
35125
|
} catch {
|
|
34807
35126
|
return {};
|
|
@@ -34809,7 +35128,7 @@ async function loadPersistedConfig() {
|
|
|
34809
35128
|
}
|
|
34810
35129
|
async function savePersistedConfig(config2) {
|
|
34811
35130
|
try {
|
|
34812
|
-
await
|
|
35131
|
+
await fs18.writeFile(PERSIST_PATH, JSON.stringify(config2, null, 2) + "\n", "utf-8");
|
|
34813
35132
|
} catch (err) {
|
|
34814
35133
|
const msg = err instanceof Error ? err.message : String(err);
|
|
34815
35134
|
logger.warn(`Could not save config to ${PERSIST_PATH}: ${msg}`);
|
|
@@ -34844,11 +35163,11 @@ First run detected. Where should cogent-bridge store its data?
|
|
|
34844
35163
|
});
|
|
34845
35164
|
}
|
|
34846
35165
|
async function validateStateDir(statePath) {
|
|
34847
|
-
await
|
|
34848
|
-
const testFile =
|
|
35166
|
+
await fs18.mkdir(statePath, { recursive: true });
|
|
35167
|
+
const testFile = path19.join(statePath, ".write-test");
|
|
34849
35168
|
try {
|
|
34850
|
-
await
|
|
34851
|
-
await
|
|
35169
|
+
await fs18.writeFile(testFile, "test", "utf-8");
|
|
35170
|
+
await fs18.unlink(testFile);
|
|
34852
35171
|
} catch {
|
|
34853
35172
|
throw new BridgeError(
|
|
34854
35173
|
"STARTUP_FAILED" /* STARTUP_FAILED */,
|
|
@@ -35036,10 +35355,10 @@ async function runStartup() {
|
|
|
35036
35355
|
if (envStatePath) {
|
|
35037
35356
|
statePath = envStatePath;
|
|
35038
35357
|
} else {
|
|
35039
|
-
const defaultPath =
|
|
35358
|
+
const defaultPath = path19.join(os14.homedir(), ".cogent");
|
|
35040
35359
|
statePath = await firstRunPrompt(defaultPath);
|
|
35041
35360
|
}
|
|
35042
|
-
if (!envStatePath && statePath !==
|
|
35361
|
+
if (!envStatePath && statePath !== path19.join(os14.homedir(), ".cogent")) {
|
|
35043
35362
|
process.env.COGENT_STATE_PATH = statePath;
|
|
35044
35363
|
} else if (!envStatePath) {
|
|
35045
35364
|
process.env.COGENT_STATE_PATH = statePath;
|
|
@@ -35103,7 +35422,7 @@ async function runStartup() {
|
|
|
35103
35422
|
}
|
|
35104
35423
|
initLogger(
|
|
35105
35424
|
config2.COGENT_LOG_LEVEL,
|
|
35106
|
-
|
|
35425
|
+
path19.join(config2.COGENT_STATE_PATH, "logs")
|
|
35107
35426
|
);
|
|
35108
35427
|
if (isCloud && effectiveSessionId && effectiveToken) {
|
|
35109
35428
|
cloudInbox = new MessageInbox();
|
|
@@ -35165,7 +35484,7 @@ var init_startup = __esm({
|
|
|
35165
35484
|
init_auto_relay();
|
|
35166
35485
|
UUID_V4_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
35167
35486
|
execFileAsync3 = promisify4(execFile5);
|
|
35168
|
-
PERSIST_PATH =
|
|
35487
|
+
PERSIST_PATH = path19.join(os14.homedir(), ".cogent-config.json");
|
|
35169
35488
|
legacyWarnEmitted = false;
|
|
35170
35489
|
cloudWsClient = null;
|
|
35171
35490
|
cloudInbox = null;
|
|
@@ -35179,13 +35498,13 @@ var init_startup = __esm({
|
|
|
35179
35498
|
});
|
|
35180
35499
|
|
|
35181
35500
|
// src/cloud/mail-credential-store.ts
|
|
35182
|
-
import
|
|
35183
|
-
import
|
|
35184
|
-
import
|
|
35185
|
-
import
|
|
35501
|
+
import crypto9 from "node:crypto";
|
|
35502
|
+
import fs19 from "node:fs/promises";
|
|
35503
|
+
import path20 from "node:path";
|
|
35504
|
+
import os15 from "node:os";
|
|
35186
35505
|
function defaultMailCredentialPath(cwd = process.cwd()) {
|
|
35187
|
-
const hash =
|
|
35188
|
-
return
|
|
35506
|
+
const hash = crypto9.createHash("sha256").update(path20.resolve(cwd)).digest("hex").slice(0, 16);
|
|
35507
|
+
return path20.join(os15.homedir(), ".cogent", "mail-credentials", `${hash}.json`);
|
|
35189
35508
|
}
|
|
35190
35509
|
function resolveMailCredentialPath(credentialPath) {
|
|
35191
35510
|
if (credentialPath) return credentialPath;
|
|
@@ -35196,16 +35515,16 @@ function resolveMailCredentialPath(credentialPath) {
|
|
|
35196
35515
|
async function loadMailCredentials(credentialPath) {
|
|
35197
35516
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35198
35517
|
try {
|
|
35199
|
-
return JSON.parse(await
|
|
35518
|
+
return JSON.parse(await fs19.readFile(filePath, "utf-8"));
|
|
35200
35519
|
} catch {
|
|
35201
35520
|
return null;
|
|
35202
35521
|
}
|
|
35203
35522
|
}
|
|
35204
35523
|
async function saveMailCredentials(creds, credentialPath) {
|
|
35205
35524
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35206
|
-
await
|
|
35207
|
-
await
|
|
35208
|
-
await
|
|
35525
|
+
await fs19.mkdir(path20.dirname(filePath), { recursive: true, mode: 448 });
|
|
35526
|
+
await fs19.writeFile(filePath, JSON.stringify(creds, null, 2) + "\n", { encoding: "utf-8", mode: 384 });
|
|
35527
|
+
await fs19.chmod(filePath, 384);
|
|
35209
35528
|
}
|
|
35210
35529
|
async function persistProvisionedMailbox(mailbox, credentialPath) {
|
|
35211
35530
|
if (!mailbox?.address || !mailbox.password) return false;
|
|
@@ -35226,7 +35545,7 @@ async function persistProvisionedMailbox(mailbox, credentialPath) {
|
|
|
35226
35545
|
async function clearMailCredentials(credentialPath) {
|
|
35227
35546
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35228
35547
|
try {
|
|
35229
|
-
await
|
|
35548
|
+
await fs19.unlink(filePath);
|
|
35230
35549
|
} catch (err) {
|
|
35231
35550
|
if (err.code !== "ENOENT") throw err;
|
|
35232
35551
|
}
|
|
@@ -35241,7 +35560,7 @@ var init_mail_credential_store = __esm({
|
|
|
35241
35560
|
});
|
|
35242
35561
|
|
|
35243
35562
|
// src/tools/register-peer.ts
|
|
35244
|
-
import
|
|
35563
|
+
import crypto10 from "node:crypto";
|
|
35245
35564
|
function unresolvedSessionReason(r) {
|
|
35246
35565
|
if (r.sessionId) return null;
|
|
35247
35566
|
return r.candidateCount === 0 ? "no-candidates" : "ambiguous";
|
|
@@ -35307,7 +35626,7 @@ function registerRegisterPeerTool(server) {
|
|
|
35307
35626
|
}
|
|
35308
35627
|
}
|
|
35309
35628
|
if (!cloudSessionId) {
|
|
35310
|
-
autoSecret =
|
|
35629
|
+
autoSecret = crypto10.randomBytes(16).toString("hex");
|
|
35311
35630
|
const resp = await fetch(
|
|
35312
35631
|
`${endpoint}/api/sessions`,
|
|
35313
35632
|
{
|
|
@@ -36689,7 +37008,7 @@ var init_wake_log2 = __esm({
|
|
|
36689
37008
|
});
|
|
36690
37009
|
|
|
36691
37010
|
// src/tools/create-session.ts
|
|
36692
|
-
import
|
|
37011
|
+
import crypto11 from "node:crypto";
|
|
36693
37012
|
function registerCreateSessionTool(server) {
|
|
36694
37013
|
server.registerTool(
|
|
36695
37014
|
"cogent_create_session",
|
|
@@ -36720,7 +37039,7 @@ function registerCreateSessionTool(server) {
|
|
|
36720
37039
|
)
|
|
36721
37040
|
);
|
|
36722
37041
|
}
|
|
36723
|
-
const sessionSecret = secret ??
|
|
37042
|
+
const sessionSecret = secret ?? crypto11.randomBytes(16).toString("hex");
|
|
36724
37043
|
const resp = await fetch(
|
|
36725
37044
|
`${config2.COGENT_ENDPOINT}/api/sessions`,
|
|
36726
37045
|
{
|
|
@@ -36898,11 +37217,24 @@ function registerJoinSessionTool(server) {
|
|
|
36898
37217
|
);
|
|
36899
37218
|
}
|
|
36900
37219
|
const data = await resp.json();
|
|
37220
|
+
let carried = {};
|
|
37221
|
+
try {
|
|
37222
|
+
const prior = await loadCredentials();
|
|
37223
|
+
if (prior && prior.endpoint === endpoint && prior.sessionId === data.sessionId) {
|
|
37224
|
+
carried = {
|
|
37225
|
+
...prior.peerId ? { peerId: prior.peerId } : {},
|
|
37226
|
+
...prior.peerSecret ? { peerSecret: prior.peerSecret } : {}
|
|
37227
|
+
};
|
|
37228
|
+
}
|
|
37229
|
+
} catch (err) {
|
|
37230
|
+
logger.debug(`join-session: could not read prior credentials: ${err.message}`);
|
|
37231
|
+
}
|
|
36901
37232
|
await saveCredentials({
|
|
36902
37233
|
endpoint,
|
|
36903
37234
|
sessionId: data.sessionId,
|
|
36904
37235
|
token: data.token,
|
|
36905
37236
|
label: resolvedLabel ?? data.label,
|
|
37237
|
+
...carried,
|
|
36906
37238
|
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
36907
37239
|
});
|
|
36908
37240
|
markJoinedInProcess();
|
|
@@ -37178,8 +37510,8 @@ var require_cookies = __commonJS({
|
|
|
37178
37510
|
if (urlparts.hostname !== cookie.domain && (cookie.domain.charAt(0) !== "." || ("." + urlparts.hostname).substr(-cookie.domain.length) !== cookie.domain)) {
|
|
37179
37511
|
return false;
|
|
37180
37512
|
}
|
|
37181
|
-
let
|
|
37182
|
-
if (
|
|
37513
|
+
let path24 = this.getPath(urlparts.pathname);
|
|
37514
|
+
if (path24.substr(0, cookie.path.length) !== cookie.path) {
|
|
37183
37515
|
return false;
|
|
37184
37516
|
}
|
|
37185
37517
|
if (cookie.secure && urlparts.protocol !== "https:") {
|
|
@@ -37239,16 +37571,16 @@ var require_cookies = __commonJS({
|
|
|
37239
37571
|
* @returns {String} Normalized path
|
|
37240
37572
|
*/
|
|
37241
37573
|
getPath(pathname) {
|
|
37242
|
-
let
|
|
37243
|
-
|
|
37244
|
-
|
|
37245
|
-
if (
|
|
37246
|
-
|
|
37574
|
+
let path24 = (pathname || "/").split("/");
|
|
37575
|
+
path24.pop();
|
|
37576
|
+
path24 = path24.join("/").trim();
|
|
37577
|
+
if (path24.charAt(0) !== "/") {
|
|
37578
|
+
path24 = "/" + path24;
|
|
37247
37579
|
}
|
|
37248
|
-
if (
|
|
37249
|
-
|
|
37580
|
+
if (path24.substr(-1) !== "/") {
|
|
37581
|
+
path24 += "/";
|
|
37250
37582
|
}
|
|
37251
|
-
return
|
|
37583
|
+
return path24;
|
|
37252
37584
|
}
|
|
37253
37585
|
};
|
|
37254
37586
|
module.exports = Cookies;
|
|
@@ -37549,15 +37881,15 @@ var require_shared = __commonJS({
|
|
|
37549
37881
|
"use strict";
|
|
37550
37882
|
var urllib = __require("url");
|
|
37551
37883
|
var util2 = __require("util");
|
|
37552
|
-
var
|
|
37884
|
+
var fs22 = __require("fs");
|
|
37553
37885
|
var nmfetch = require_fetch();
|
|
37554
37886
|
var dns = __require("dns");
|
|
37555
37887
|
var net = __require("net");
|
|
37556
|
-
var
|
|
37888
|
+
var os17 = __require("os");
|
|
37557
37889
|
var DNS_TTL = 5 * 60 * 1e3;
|
|
37558
37890
|
var networkInterfaces;
|
|
37559
37891
|
try {
|
|
37560
|
-
networkInterfaces =
|
|
37892
|
+
networkInterfaces = os17.networkInterfaces();
|
|
37561
37893
|
} catch (err) {
|
|
37562
37894
|
}
|
|
37563
37895
|
module.exports.networkInterfaces = networkInterfaces;
|
|
@@ -37935,7 +38267,7 @@ var require_shared = __commonJS({
|
|
|
37935
38267
|
}
|
|
37936
38268
|
return callback(null, parsedDataUri.data);
|
|
37937
38269
|
} else if (content.path) {
|
|
37938
|
-
return resolveStream(
|
|
38270
|
+
return resolveStream(fs22.createReadStream(content.path), callback);
|
|
37939
38271
|
}
|
|
37940
38272
|
}
|
|
37941
38273
|
if (typeof data[key].content === "string" && !["utf8", "usascii", "ascii"].includes(encoding)) {
|
|
@@ -38059,7 +38391,7 @@ var require_shared = __commonJS({
|
|
|
38059
38391
|
var require_mime_types = __commonJS({
|
|
38060
38392
|
"node_modules/nodemailer/lib/mime-funcs/mime-types.js"(exports, module) {
|
|
38061
38393
|
"use strict";
|
|
38062
|
-
var
|
|
38394
|
+
var path24 = __require("path");
|
|
38063
38395
|
var defaultMimeType = "application/octet-stream";
|
|
38064
38396
|
var defaultExtension = "bin";
|
|
38065
38397
|
var mimeTypes = /* @__PURE__ */ new Map([
|
|
@@ -40117,7 +40449,7 @@ var require_mime_types = __commonJS({
|
|
|
40117
40449
|
if (!filename) {
|
|
40118
40450
|
return defaultMimeType;
|
|
40119
40451
|
}
|
|
40120
|
-
let parsed =
|
|
40452
|
+
let parsed = path24.parse(filename);
|
|
40121
40453
|
let extension = (parsed.ext.substr(1) || parsed.name || "").split("?").shift().trim().toLowerCase();
|
|
40122
40454
|
let value = defaultMimeType;
|
|
40123
40455
|
if (extensions.has(extension)) {
|
|
@@ -41518,8 +41850,8 @@ var require_le_unix = __commonJS({
|
|
|
41518
41850
|
var require_mime_node = __commonJS({
|
|
41519
41851
|
"node_modules/nodemailer/lib/mime-node/index.js"(exports, module) {
|
|
41520
41852
|
"use strict";
|
|
41521
|
-
var
|
|
41522
|
-
var
|
|
41853
|
+
var crypto12 = __require("crypto");
|
|
41854
|
+
var fs22 = __require("fs");
|
|
41523
41855
|
var punycode = require_punycode();
|
|
41524
41856
|
var PassThrough = __require("stream").PassThrough;
|
|
41525
41857
|
var shared = require_shared();
|
|
@@ -41535,7 +41867,7 @@ var require_mime_node = __commonJS({
|
|
|
41535
41867
|
constructor(contentType, options) {
|
|
41536
41868
|
this.nodeCounter = 0;
|
|
41537
41869
|
options = options || {};
|
|
41538
|
-
this.baseBoundary = options.baseBoundary ||
|
|
41870
|
+
this.baseBoundary = options.baseBoundary || crypto12.randomBytes(8).toString("hex");
|
|
41539
41871
|
this.boundaryPrefix = options.boundaryPrefix || "--_NmP";
|
|
41540
41872
|
this.disableFileAccess = !!options.disableFileAccess;
|
|
41541
41873
|
this.disableUrlAccess = !!options.disableUrlAccess;
|
|
@@ -42234,7 +42566,7 @@ var require_mime_node = __commonJS({
|
|
|
42234
42566
|
setImmediate(() => contentStream.emit("error", new Error("File access rejected for " + content.path)));
|
|
42235
42567
|
return contentStream;
|
|
42236
42568
|
}
|
|
42237
|
-
return
|
|
42569
|
+
return fs22.createReadStream(content.path);
|
|
42238
42570
|
} else if (content && typeof content.href === "string") {
|
|
42239
42571
|
if (this.disableUrlAccess) {
|
|
42240
42572
|
contentStream = new PassThrough();
|
|
@@ -42478,8 +42810,8 @@ var require_mime_node = __commonJS({
|
|
|
42478
42810
|
_generateMessageId() {
|
|
42479
42811
|
return "<" + [2, 2, 2, 6].reduce(
|
|
42480
42812
|
// crux to generate UUID-like random strings
|
|
42481
|
-
(prev, len) => prev + "-" +
|
|
42482
|
-
|
|
42813
|
+
(prev, len) => prev + "-" + crypto12.randomBytes(len).toString("hex"),
|
|
42814
|
+
crypto12.randomBytes(4).toString("hex")
|
|
42483
42815
|
) + "@" + // try to use the domain of the FROM address or fallback to server hostname
|
|
42484
42816
|
(this.getEnvelope().from || this.hostname || "localhost").split("@").pop() + ">";
|
|
42485
42817
|
}
|
|
@@ -43070,14 +43402,14 @@ var require_relaxed_body = __commonJS({
|
|
|
43070
43402
|
"node_modules/nodemailer/lib/dkim/relaxed-body.js"(exports, module) {
|
|
43071
43403
|
"use strict";
|
|
43072
43404
|
var Transform = __require("stream").Transform;
|
|
43073
|
-
var
|
|
43405
|
+
var crypto12 = __require("crypto");
|
|
43074
43406
|
var RelaxedBody = class extends Transform {
|
|
43075
43407
|
constructor(options) {
|
|
43076
43408
|
super();
|
|
43077
43409
|
options = options || {};
|
|
43078
43410
|
this.chunkBuffer = [];
|
|
43079
43411
|
this.chunkBufferLen = 0;
|
|
43080
|
-
this.bodyHash =
|
|
43412
|
+
this.bodyHash = crypto12.createHash(options.hashAlgo || "sha1");
|
|
43081
43413
|
this.remainder = "";
|
|
43082
43414
|
this.byteLength = 0;
|
|
43083
43415
|
this.debug = options.debug;
|
|
@@ -43180,7 +43512,7 @@ var require_sign = __commonJS({
|
|
|
43180
43512
|
"use strict";
|
|
43181
43513
|
var punycode = require_punycode();
|
|
43182
43514
|
var mimeFuncs = require_mime_funcs();
|
|
43183
|
-
var
|
|
43515
|
+
var crypto12 = __require("crypto");
|
|
43184
43516
|
module.exports = (headers, hashAlgo, bodyHash, options) => {
|
|
43185
43517
|
options = options || {};
|
|
43186
43518
|
let defaultFieldNames = "From:Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive";
|
|
@@ -43189,7 +43521,7 @@ var require_sign = __commonJS({
|
|
|
43189
43521
|
let dkimHeader = generateDKIMHeader(options.domainName, options.keySelector, canonicalizedHeaderData.fieldNames, hashAlgo, bodyHash);
|
|
43190
43522
|
let signer, signature;
|
|
43191
43523
|
canonicalizedHeaderData.headers += "dkim-signature:" + relaxedHeaderLine(dkimHeader);
|
|
43192
|
-
signer =
|
|
43524
|
+
signer = crypto12.createSign(("rsa-" + hashAlgo).toUpperCase());
|
|
43193
43525
|
signer.update(canonicalizedHeaderData.headers);
|
|
43194
43526
|
try {
|
|
43195
43527
|
signature = signer.sign(options.privateKey, "base64");
|
|
@@ -43255,9 +43587,9 @@ var require_dkim = __commonJS({
|
|
|
43255
43587
|
var RelaxedBody = require_relaxed_body();
|
|
43256
43588
|
var sign = require_sign();
|
|
43257
43589
|
var PassThrough = __require("stream").PassThrough;
|
|
43258
|
-
var
|
|
43259
|
-
var
|
|
43260
|
-
var
|
|
43590
|
+
var fs22 = __require("fs");
|
|
43591
|
+
var path24 = __require("path");
|
|
43592
|
+
var crypto12 = __require("crypto");
|
|
43261
43593
|
var DKIM_ALGO = "sha256";
|
|
43262
43594
|
var MAX_MESSAGE_SIZE = 128 * 1024;
|
|
43263
43595
|
var DKIMSigner = class {
|
|
@@ -43270,7 +43602,7 @@ var require_dkim = __commonJS({
|
|
|
43270
43602
|
this.chunks = [];
|
|
43271
43603
|
this.chunklen = 0;
|
|
43272
43604
|
this.readPos = 0;
|
|
43273
|
-
this.cachePath = this.cacheDir ?
|
|
43605
|
+
this.cachePath = this.cacheDir ? path24.join(this.cacheDir, "message." + Date.now() + "-" + crypto12.randomBytes(14).toString("hex")) : false;
|
|
43274
43606
|
this.cache = false;
|
|
43275
43607
|
this.headers = false;
|
|
43276
43608
|
this.bodyHash = false;
|
|
@@ -43290,10 +43622,10 @@ var require_dkim = __commonJS({
|
|
|
43290
43622
|
if (!this.cache || !this.cachePath) {
|
|
43291
43623
|
return;
|
|
43292
43624
|
}
|
|
43293
|
-
|
|
43625
|
+
fs22.unlink(this.cachePath, () => false);
|
|
43294
43626
|
}
|
|
43295
43627
|
createReadCache() {
|
|
43296
|
-
this.cache =
|
|
43628
|
+
this.cache = fs22.createReadStream(this.cachePath);
|
|
43297
43629
|
this.cache.once("error", (err) => {
|
|
43298
43630
|
this.cleanup();
|
|
43299
43631
|
this.output.emit("error", err);
|
|
@@ -43349,7 +43681,7 @@ var require_dkim = __commonJS({
|
|
|
43349
43681
|
}
|
|
43350
43682
|
createWriteCache() {
|
|
43351
43683
|
this.output.usingCache = true;
|
|
43352
|
-
this.cache =
|
|
43684
|
+
this.cache = fs22.createWriteStream(this.cachePath);
|
|
43353
43685
|
this.cache.once("error", (err) => {
|
|
43354
43686
|
this.cleanup();
|
|
43355
43687
|
this.relaxedBody.unpipe(this.cache);
|
|
@@ -43826,7 +44158,7 @@ var require_mailer = __commonJS({
|
|
|
43826
44158
|
var MailMessage = require_mail_message();
|
|
43827
44159
|
var net = __require("net");
|
|
43828
44160
|
var dns = __require("dns");
|
|
43829
|
-
var
|
|
44161
|
+
var crypto12 = __require("crypto");
|
|
43830
44162
|
var Mail = class extends EventEmitter {
|
|
43831
44163
|
constructor(transporter, options, defaults) {
|
|
43832
44164
|
super();
|
|
@@ -44150,7 +44482,7 @@ var require_mailer = __commonJS({
|
|
|
44150
44482
|
}
|
|
44151
44483
|
let cidCounter = 0;
|
|
44152
44484
|
html = (html || "").toString().replace(/(<img\b[^<>]{0,1024} src\s{0,20}=[\s"']{0,20})(data:([^;]+);[^"'>\s]+)/gi, (match, prefix, dataUri, mimeType) => {
|
|
44153
|
-
let cid =
|
|
44485
|
+
let cid = crypto12.randomBytes(10).toString("hex") + "@localhost";
|
|
44154
44486
|
if (!mail.data.attachments) {
|
|
44155
44487
|
mail.data.attachments = [];
|
|
44156
44488
|
}
|
|
@@ -44276,8 +44608,8 @@ var require_smtp_connection = __commonJS({
|
|
|
44276
44608
|
var EventEmitter = __require("events").EventEmitter;
|
|
44277
44609
|
var net = __require("net");
|
|
44278
44610
|
var tls = __require("tls");
|
|
44279
|
-
var
|
|
44280
|
-
var
|
|
44611
|
+
var os17 = __require("os");
|
|
44612
|
+
var crypto12 = __require("crypto");
|
|
44281
44613
|
var DataStream = require_data_stream();
|
|
44282
44614
|
var PassThrough = __require("stream").PassThrough;
|
|
44283
44615
|
var shared = require_shared();
|
|
@@ -44288,7 +44620,7 @@ var require_smtp_connection = __commonJS({
|
|
|
44288
44620
|
var SMTPConnection = class extends EventEmitter {
|
|
44289
44621
|
constructor(options) {
|
|
44290
44622
|
super(options);
|
|
44291
|
-
this.id =
|
|
44623
|
+
this.id = crypto12.randomBytes(8).toString("base64").replace(/\W/g, "");
|
|
44292
44624
|
this.stage = "init";
|
|
44293
44625
|
this.options = options || {};
|
|
44294
44626
|
this.secureConnection = !!this.options.secure;
|
|
@@ -45381,7 +45713,7 @@ var require_smtp_connection = __commonJS({
|
|
|
45381
45713
|
} else {
|
|
45382
45714
|
challengeString = challengeMatch[1];
|
|
45383
45715
|
}
|
|
45384
|
-
let base64decoded = Buffer.from(challengeString, "base64").toString("ascii"), hmacMD5 =
|
|
45716
|
+
let base64decoded = Buffer.from(challengeString, "base64").toString("ascii"), hmacMD5 = crypto12.createHmac("md5", this._auth.credentials.pass);
|
|
45385
45717
|
hmacMD5.update(base64decoded);
|
|
45386
45718
|
let prepended = this._auth.credentials.user + " " + hmacMD5.digest("hex");
|
|
45387
45719
|
this._responseActions.push((str2) => {
|
|
@@ -45669,7 +46001,7 @@ var require_smtp_connection = __commonJS({
|
|
|
45669
46001
|
_getHostname() {
|
|
45670
46002
|
let defaultHostname;
|
|
45671
46003
|
try {
|
|
45672
|
-
defaultHostname =
|
|
46004
|
+
defaultHostname = os17.hostname() || "";
|
|
45673
46005
|
} catch (err) {
|
|
45674
46006
|
defaultHostname = "localhost";
|
|
45675
46007
|
}
|
|
@@ -45692,7 +46024,7 @@ var require_xoauth2 = __commonJS({
|
|
|
45692
46024
|
"use strict";
|
|
45693
46025
|
var Stream = __require("stream").Stream;
|
|
45694
46026
|
var nmfetch = require_fetch();
|
|
45695
|
-
var
|
|
46027
|
+
var crypto12 = __require("crypto");
|
|
45696
46028
|
var shared = require_shared();
|
|
45697
46029
|
var XOAuth2 = class extends Stream {
|
|
45698
46030
|
constructor(options, logger2) {
|
|
@@ -45983,7 +46315,7 @@ var require_xoauth2 = __commonJS({
|
|
|
45983
46315
|
*/
|
|
45984
46316
|
jwtSignRS256(payload) {
|
|
45985
46317
|
payload = ['{"alg":"RS256","typ":"JWT"}', JSON.stringify(payload)].map((val) => this.toBase64URL(val)).join(".");
|
|
45986
|
-
let signature =
|
|
46318
|
+
let signature = crypto12.createSign("RSA-SHA256").update(payload).sign(this.options.privateKey);
|
|
45987
46319
|
return payload + "." + this.toBase64URL(signature);
|
|
45988
46320
|
}
|
|
45989
46321
|
};
|
|
@@ -48238,13 +48570,13 @@ var require_nodemailer = __commonJS({
|
|
|
48238
48570
|
});
|
|
48239
48571
|
|
|
48240
48572
|
// src/mail/mail-sender.ts
|
|
48241
|
-
import
|
|
48242
|
-
import
|
|
48573
|
+
import fs20 from "node:fs/promises";
|
|
48574
|
+
import path21 from "node:path";
|
|
48243
48575
|
async function buildAndSendMail(sender, creds, params) {
|
|
48244
48576
|
const attachments = [];
|
|
48245
48577
|
for (const p of params.attachmentPaths ?? []) {
|
|
48246
|
-
const content = await
|
|
48247
|
-
attachments.push({ filename:
|
|
48578
|
+
const content = await fs20.readFile(p);
|
|
48579
|
+
attachments.push({ filename: path21.basename(p), content });
|
|
48248
48580
|
}
|
|
48249
48581
|
const { messageId } = await sender.send({
|
|
48250
48582
|
from: creds.address,
|
|
@@ -48633,8 +48965,8 @@ var require_req = __commonJS({
|
|
|
48633
48965
|
if (req.originalUrl) {
|
|
48634
48966
|
_req.url = req.originalUrl;
|
|
48635
48967
|
} else {
|
|
48636
|
-
const
|
|
48637
|
-
_req.url = typeof
|
|
48968
|
+
const path24 = req.path;
|
|
48969
|
+
_req.url = typeof path24 === "string" ? path24 : req.url ? req.url.path || req.url : void 0;
|
|
48638
48970
|
}
|
|
48639
48971
|
if (req.query) {
|
|
48640
48972
|
_req.query = req.query;
|
|
@@ -48799,14 +49131,14 @@ var require_redact = __commonJS({
|
|
|
48799
49131
|
}
|
|
48800
49132
|
return obj;
|
|
48801
49133
|
}
|
|
48802
|
-
function parsePath(
|
|
49134
|
+
function parsePath(path24) {
|
|
48803
49135
|
const parts = [];
|
|
48804
49136
|
let current = "";
|
|
48805
49137
|
let inBrackets = false;
|
|
48806
49138
|
let inQuotes = false;
|
|
48807
49139
|
let quoteChar = "";
|
|
48808
|
-
for (let i = 0; i <
|
|
48809
|
-
const char =
|
|
49140
|
+
for (let i = 0; i < path24.length; i++) {
|
|
49141
|
+
const char = path24[i];
|
|
48810
49142
|
if (!inBrackets && char === ".") {
|
|
48811
49143
|
if (current) {
|
|
48812
49144
|
parts.push(current);
|
|
@@ -48937,10 +49269,10 @@ var require_redact = __commonJS({
|
|
|
48937
49269
|
return current;
|
|
48938
49270
|
}
|
|
48939
49271
|
function redactPaths(obj, paths, censor, remove = false) {
|
|
48940
|
-
for (const
|
|
48941
|
-
const parts = parsePath(
|
|
49272
|
+
for (const path24 of paths) {
|
|
49273
|
+
const parts = parsePath(path24);
|
|
48942
49274
|
if (parts.includes("*")) {
|
|
48943
|
-
redactWildcardPath(obj, parts, censor,
|
|
49275
|
+
redactWildcardPath(obj, parts, censor, path24, remove);
|
|
48944
49276
|
} else {
|
|
48945
49277
|
if (remove) {
|
|
48946
49278
|
removeKey(obj, parts);
|
|
@@ -49025,8 +49357,8 @@ var require_redact = __commonJS({
|
|
|
49025
49357
|
}
|
|
49026
49358
|
} else {
|
|
49027
49359
|
if (afterWildcard.includes("*")) {
|
|
49028
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
49029
|
-
const fullPath = [...pathArray.slice(0, pathLength), ...
|
|
49360
|
+
const wrappedCensor = typeof censor === "function" ? (value, path24) => {
|
|
49361
|
+
const fullPath = [...pathArray.slice(0, pathLength), ...path24];
|
|
49030
49362
|
return censor(value, fullPath);
|
|
49031
49363
|
} : censor;
|
|
49032
49364
|
redactWildcardPath(current, afterWildcard, wrappedCensor, originalPath, remove);
|
|
@@ -49061,8 +49393,8 @@ var require_redact = __commonJS({
|
|
|
49061
49393
|
return null;
|
|
49062
49394
|
}
|
|
49063
49395
|
const pathStructure = /* @__PURE__ */ new Map();
|
|
49064
|
-
for (const
|
|
49065
|
-
const parts = parsePath(
|
|
49396
|
+
for (const path24 of pathsToClone) {
|
|
49397
|
+
const parts = parsePath(path24);
|
|
49066
49398
|
let current = pathStructure;
|
|
49067
49399
|
for (let i = 0; i < parts.length; i++) {
|
|
49068
49400
|
const part = parts[i];
|
|
@@ -49114,24 +49446,24 @@ var require_redact = __commonJS({
|
|
|
49114
49446
|
}
|
|
49115
49447
|
return cloneSelectively(obj, pathStructure);
|
|
49116
49448
|
}
|
|
49117
|
-
function validatePath(
|
|
49118
|
-
if (typeof
|
|
49449
|
+
function validatePath(path24) {
|
|
49450
|
+
if (typeof path24 !== "string") {
|
|
49119
49451
|
throw new Error("Paths must be (non-empty) strings");
|
|
49120
49452
|
}
|
|
49121
|
-
if (
|
|
49453
|
+
if (path24 === "") {
|
|
49122
49454
|
throw new Error("Invalid redaction path ()");
|
|
49123
49455
|
}
|
|
49124
|
-
if (
|
|
49125
|
-
throw new Error(`Invalid redaction path (${
|
|
49456
|
+
if (path24.includes("..")) {
|
|
49457
|
+
throw new Error(`Invalid redaction path (${path24})`);
|
|
49126
49458
|
}
|
|
49127
|
-
if (
|
|
49128
|
-
throw new Error(`Invalid redaction path (${
|
|
49459
|
+
if (path24.includes(",")) {
|
|
49460
|
+
throw new Error(`Invalid redaction path (${path24})`);
|
|
49129
49461
|
}
|
|
49130
49462
|
let bracketCount = 0;
|
|
49131
49463
|
let inQuotes = false;
|
|
49132
49464
|
let quoteChar = "";
|
|
49133
|
-
for (let i = 0; i <
|
|
49134
|
-
const char =
|
|
49465
|
+
for (let i = 0; i < path24.length; i++) {
|
|
49466
|
+
const char = path24[i];
|
|
49135
49467
|
if ((char === '"' || char === "'") && bracketCount > 0) {
|
|
49136
49468
|
if (!inQuotes) {
|
|
49137
49469
|
inQuotes = true;
|
|
@@ -49145,20 +49477,20 @@ var require_redact = __commonJS({
|
|
|
49145
49477
|
} else if (char === "]" && !inQuotes) {
|
|
49146
49478
|
bracketCount--;
|
|
49147
49479
|
if (bracketCount < 0) {
|
|
49148
|
-
throw new Error(`Invalid redaction path (${
|
|
49480
|
+
throw new Error(`Invalid redaction path (${path24})`);
|
|
49149
49481
|
}
|
|
49150
49482
|
}
|
|
49151
49483
|
}
|
|
49152
49484
|
if (bracketCount !== 0) {
|
|
49153
|
-
throw new Error(`Invalid redaction path (${
|
|
49485
|
+
throw new Error(`Invalid redaction path (${path24})`);
|
|
49154
49486
|
}
|
|
49155
49487
|
}
|
|
49156
49488
|
function validatePaths(paths) {
|
|
49157
49489
|
if (!Array.isArray(paths)) {
|
|
49158
49490
|
throw new TypeError("paths must be an array");
|
|
49159
49491
|
}
|
|
49160
|
-
for (const
|
|
49161
|
-
validatePath(
|
|
49492
|
+
for (const path24 of paths) {
|
|
49493
|
+
validatePath(path24);
|
|
49162
49494
|
}
|
|
49163
49495
|
}
|
|
49164
49496
|
function slowRedact(options = {}) {
|
|
@@ -49326,8 +49658,8 @@ var require_redaction = __commonJS({
|
|
|
49326
49658
|
if (shape[k] === null) {
|
|
49327
49659
|
o[k] = (value) => topCensor(value, [k]);
|
|
49328
49660
|
} else {
|
|
49329
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
49330
|
-
return censor(value, [k, ...
|
|
49661
|
+
const wrappedCensor = typeof censor === "function" ? (value, path24) => {
|
|
49662
|
+
return censor(value, [k, ...path24]);
|
|
49331
49663
|
} : censor;
|
|
49332
49664
|
o[k] = Redact({
|
|
49333
49665
|
paths: shape[k],
|
|
@@ -49511,7 +49843,7 @@ var require_atomic_sleep = __commonJS({
|
|
|
49511
49843
|
"node_modules/atomic-sleep/index.js"(exports, module) {
|
|
49512
49844
|
"use strict";
|
|
49513
49845
|
if (typeof SharedArrayBuffer !== "undefined" && typeof Atomics !== "undefined") {
|
|
49514
|
-
let
|
|
49846
|
+
let sleep4 = function(ms) {
|
|
49515
49847
|
const valid = ms > 0 && ms < Infinity;
|
|
49516
49848
|
if (valid === false) {
|
|
49517
49849
|
if (typeof ms !== "number" && typeof ms !== "bigint") {
|
|
@@ -49522,9 +49854,9 @@ var require_atomic_sleep = __commonJS({
|
|
|
49522
49854
|
Atomics.wait(nil, 0, 0, Number(ms));
|
|
49523
49855
|
};
|
|
49524
49856
|
const nil = new Int32Array(new SharedArrayBuffer(4));
|
|
49525
|
-
module.exports =
|
|
49857
|
+
module.exports = sleep4;
|
|
49526
49858
|
} else {
|
|
49527
|
-
let
|
|
49859
|
+
let sleep4 = function(ms) {
|
|
49528
49860
|
const valid = ms > 0 && ms < Infinity;
|
|
49529
49861
|
if (valid === false) {
|
|
49530
49862
|
if (typeof ms !== "number" && typeof ms !== "bigint") {
|
|
@@ -49536,7 +49868,7 @@ var require_atomic_sleep = __commonJS({
|
|
|
49536
49868
|
while (target > Date.now()) {
|
|
49537
49869
|
}
|
|
49538
49870
|
};
|
|
49539
|
-
module.exports =
|
|
49871
|
+
module.exports = sleep4;
|
|
49540
49872
|
}
|
|
49541
49873
|
}
|
|
49542
49874
|
});
|
|
@@ -49545,11 +49877,11 @@ var require_atomic_sleep = __commonJS({
|
|
|
49545
49877
|
var require_sonic_boom = __commonJS({
|
|
49546
49878
|
"node_modules/sonic-boom/index.js"(exports, module) {
|
|
49547
49879
|
"use strict";
|
|
49548
|
-
var
|
|
49880
|
+
var fs22 = __require("fs");
|
|
49549
49881
|
var EventEmitter = __require("events");
|
|
49550
49882
|
var inherits = __require("util").inherits;
|
|
49551
|
-
var
|
|
49552
|
-
var
|
|
49883
|
+
var path24 = __require("path");
|
|
49884
|
+
var sleep4 = require_atomic_sleep();
|
|
49553
49885
|
var assert2 = __require("assert");
|
|
49554
49886
|
var BUSY_WRITE_TIMEOUT = 100;
|
|
49555
49887
|
var kEmptyBuffer = Buffer.allocUnsafe(0);
|
|
@@ -49602,20 +49934,20 @@ var require_sonic_boom = __commonJS({
|
|
|
49602
49934
|
const mode = sonic.mode;
|
|
49603
49935
|
if (sonic.sync) {
|
|
49604
49936
|
try {
|
|
49605
|
-
if (sonic.mkdir)
|
|
49606
|
-
const fd =
|
|
49937
|
+
if (sonic.mkdir) fs22.mkdirSync(path24.dirname(file), { recursive: true });
|
|
49938
|
+
const fd = fs22.openSync(file, flags, mode);
|
|
49607
49939
|
fileOpened(null, fd);
|
|
49608
49940
|
} catch (err) {
|
|
49609
49941
|
fileOpened(err);
|
|
49610
49942
|
throw err;
|
|
49611
49943
|
}
|
|
49612
49944
|
} else if (sonic.mkdir) {
|
|
49613
|
-
|
|
49945
|
+
fs22.mkdir(path24.dirname(file), { recursive: true }, (err) => {
|
|
49614
49946
|
if (err) return fileOpened(err);
|
|
49615
|
-
|
|
49947
|
+
fs22.open(file, flags, mode, fileOpened);
|
|
49616
49948
|
});
|
|
49617
49949
|
} else {
|
|
49618
|
-
|
|
49950
|
+
fs22.open(file, flags, mode, fileOpened);
|
|
49619
49951
|
}
|
|
49620
49952
|
}
|
|
49621
49953
|
function SonicBoom(opts) {
|
|
@@ -49656,8 +49988,8 @@ var require_sonic_boom = __commonJS({
|
|
|
49656
49988
|
this.flush = flushBuffer;
|
|
49657
49989
|
this.flushSync = flushBufferSync;
|
|
49658
49990
|
this._actualWrite = actualWriteBuffer;
|
|
49659
|
-
fsWriteSync = () =>
|
|
49660
|
-
fsWrite = () =>
|
|
49991
|
+
fsWriteSync = () => fs22.writeSync(this.fd, this._writingBuf);
|
|
49992
|
+
fsWrite = () => fs22.write(this.fd, this._writingBuf, this.release);
|
|
49661
49993
|
} else if (contentMode === void 0 || contentMode === kContentModeUtf8) {
|
|
49662
49994
|
this._writingBuf = "";
|
|
49663
49995
|
this.write = write;
|
|
@@ -49666,15 +49998,15 @@ var require_sonic_boom = __commonJS({
|
|
|
49666
49998
|
this._actualWrite = actualWrite;
|
|
49667
49999
|
fsWriteSync = () => {
|
|
49668
50000
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
49669
|
-
return
|
|
50001
|
+
return fs22.writeSync(this.fd, this._writingBuf);
|
|
49670
50002
|
}
|
|
49671
|
-
return
|
|
50003
|
+
return fs22.writeSync(this.fd, this._writingBuf, "utf8");
|
|
49672
50004
|
};
|
|
49673
50005
|
fsWrite = () => {
|
|
49674
50006
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
49675
|
-
return
|
|
50007
|
+
return fs22.write(this.fd, this._writingBuf, this.release);
|
|
49676
50008
|
}
|
|
49677
|
-
return
|
|
50009
|
+
return fs22.write(this.fd, this._writingBuf, "utf8", this.release);
|
|
49678
50010
|
};
|
|
49679
50011
|
} else {
|
|
49680
50012
|
throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
|
|
@@ -49695,7 +50027,7 @@ var require_sonic_boom = __commonJS({
|
|
|
49695
50027
|
if ((err.code === "EAGAIN" || err.code === "EBUSY") && this.retryEAGAIN(err, this._writingBuf.length, this._len - this._writingBuf.length)) {
|
|
49696
50028
|
if (this.sync) {
|
|
49697
50029
|
try {
|
|
49698
|
-
|
|
50030
|
+
sleep4(BUSY_WRITE_TIMEOUT);
|
|
49699
50031
|
this.release(void 0, 0);
|
|
49700
50032
|
} catch (err2) {
|
|
49701
50033
|
this.release(err2);
|
|
@@ -49731,7 +50063,7 @@ var require_sonic_boom = __commonJS({
|
|
|
49731
50063
|
}
|
|
49732
50064
|
}
|
|
49733
50065
|
if (this._fsync) {
|
|
49734
|
-
|
|
50066
|
+
fs22.fsyncSync(this.fd);
|
|
49735
50067
|
}
|
|
49736
50068
|
const len = this._len;
|
|
49737
50069
|
if (this._reopening) {
|
|
@@ -49845,7 +50177,7 @@ var require_sonic_boom = __commonJS({
|
|
|
49845
50177
|
const onDrain = () => {
|
|
49846
50178
|
if (!this._fsync) {
|
|
49847
50179
|
try {
|
|
49848
|
-
|
|
50180
|
+
fs22.fsync(this.fd, (err) => {
|
|
49849
50181
|
this._flushPending = false;
|
|
49850
50182
|
cb(err);
|
|
49851
50183
|
});
|
|
@@ -49947,7 +50279,7 @@ var require_sonic_boom = __commonJS({
|
|
|
49947
50279
|
const fd = this.fd;
|
|
49948
50280
|
this.once("ready", () => {
|
|
49949
50281
|
if (fd !== this.fd) {
|
|
49950
|
-
|
|
50282
|
+
fs22.close(fd, (err) => {
|
|
49951
50283
|
if (err) {
|
|
49952
50284
|
return this.emit("error", err);
|
|
49953
50285
|
}
|
|
@@ -49996,7 +50328,7 @@ var require_sonic_boom = __commonJS({
|
|
|
49996
50328
|
buf = this._bufs[0];
|
|
49997
50329
|
}
|
|
49998
50330
|
try {
|
|
49999
|
-
const n = Buffer.isBuffer(buf) ?
|
|
50331
|
+
const n = Buffer.isBuffer(buf) ? fs22.writeSync(this.fd, buf) : fs22.writeSync(this.fd, buf, "utf8");
|
|
50000
50332
|
const releasedBufObj = releaseWritingBuf(buf, this._len, n);
|
|
50001
50333
|
buf = releasedBufObj.writingBuf;
|
|
50002
50334
|
this._len = releasedBufObj.len;
|
|
@@ -50008,11 +50340,11 @@ var require_sonic_boom = __commonJS({
|
|
|
50008
50340
|
if (shouldRetry && !this.retryEAGAIN(err, buf.length, this._len - buf.length)) {
|
|
50009
50341
|
throw err;
|
|
50010
50342
|
}
|
|
50011
|
-
|
|
50343
|
+
sleep4(BUSY_WRITE_TIMEOUT);
|
|
50012
50344
|
}
|
|
50013
50345
|
}
|
|
50014
50346
|
try {
|
|
50015
|
-
|
|
50347
|
+
fs22.fsyncSync(this.fd);
|
|
50016
50348
|
} catch {
|
|
50017
50349
|
}
|
|
50018
50350
|
}
|
|
@@ -50033,7 +50365,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50033
50365
|
buf = mergeBuf(this._bufs[0], this._lens[0]);
|
|
50034
50366
|
}
|
|
50035
50367
|
try {
|
|
50036
|
-
const n =
|
|
50368
|
+
const n = fs22.writeSync(this.fd, buf);
|
|
50037
50369
|
buf = buf.subarray(n);
|
|
50038
50370
|
this._len = Math.max(this._len - n, 0);
|
|
50039
50371
|
if (buf.length <= 0) {
|
|
@@ -50045,7 +50377,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50045
50377
|
if (shouldRetry && !this.retryEAGAIN(err, buf.length, this._len - buf.length)) {
|
|
50046
50378
|
throw err;
|
|
50047
50379
|
}
|
|
50048
|
-
|
|
50380
|
+
sleep4(BUSY_WRITE_TIMEOUT);
|
|
50049
50381
|
}
|
|
50050
50382
|
}
|
|
50051
50383
|
}
|
|
@@ -50061,13 +50393,13 @@ var require_sonic_boom = __commonJS({
|
|
|
50061
50393
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : this._bufs.shift() || "";
|
|
50062
50394
|
if (this.sync) {
|
|
50063
50395
|
try {
|
|
50064
|
-
const written = Buffer.isBuffer(this._writingBuf) ?
|
|
50396
|
+
const written = Buffer.isBuffer(this._writingBuf) ? fs22.writeSync(this.fd, this._writingBuf) : fs22.writeSync(this.fd, this._writingBuf, "utf8");
|
|
50065
50397
|
release(null, written);
|
|
50066
50398
|
} catch (err) {
|
|
50067
50399
|
release(err);
|
|
50068
50400
|
}
|
|
50069
50401
|
} else {
|
|
50070
|
-
|
|
50402
|
+
fs22.write(this.fd, this._writingBuf, release);
|
|
50071
50403
|
}
|
|
50072
50404
|
}
|
|
50073
50405
|
function actualWriteBuffer() {
|
|
@@ -50076,7 +50408,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50076
50408
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
|
|
50077
50409
|
if (this.sync) {
|
|
50078
50410
|
try {
|
|
50079
|
-
const written =
|
|
50411
|
+
const written = fs22.writeSync(this.fd, this._writingBuf);
|
|
50080
50412
|
release(null, written);
|
|
50081
50413
|
} catch (err) {
|
|
50082
50414
|
release(err);
|
|
@@ -50085,7 +50417,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50085
50417
|
if (kCopyBuffer) {
|
|
50086
50418
|
this._writingBuf = Buffer.from(this._writingBuf);
|
|
50087
50419
|
}
|
|
50088
|
-
|
|
50420
|
+
fs22.write(this.fd, this._writingBuf, release);
|
|
50089
50421
|
}
|
|
50090
50422
|
}
|
|
50091
50423
|
function actualClose(sonic) {
|
|
@@ -50101,12 +50433,12 @@ var require_sonic_boom = __commonJS({
|
|
|
50101
50433
|
sonic._lens = [];
|
|
50102
50434
|
assert2(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
|
|
50103
50435
|
try {
|
|
50104
|
-
|
|
50436
|
+
fs22.fsync(sonic.fd, closeWrapped);
|
|
50105
50437
|
} catch {
|
|
50106
50438
|
}
|
|
50107
50439
|
function closeWrapped() {
|
|
50108
50440
|
if (sonic.fd !== 1 && sonic.fd !== 2) {
|
|
50109
|
-
|
|
50441
|
+
fs22.close(sonic.fd, done);
|
|
50110
50442
|
} else {
|
|
50111
50443
|
done();
|
|
50112
50444
|
}
|
|
@@ -50880,7 +51212,7 @@ var require_transport = __commonJS({
|
|
|
50880
51212
|
var getCallers = require_caller();
|
|
50881
51213
|
var { join: join2, isAbsolute, sep } = __require("node:path");
|
|
50882
51214
|
var { fileURLToPath } = __require("node:url");
|
|
50883
|
-
var
|
|
51215
|
+
var sleep4 = require_atomic_sleep();
|
|
50884
51216
|
var onExit = require_on_exit_leak_free();
|
|
50885
51217
|
var ThreadStream = require_thread_stream();
|
|
50886
51218
|
function setupOnExit(stream) {
|
|
@@ -50942,15 +51274,15 @@ var require_transport = __commonJS({
|
|
|
50942
51274
|
if (!unquoted) {
|
|
50943
51275
|
return false;
|
|
50944
51276
|
}
|
|
50945
|
-
let
|
|
50946
|
-
if (
|
|
51277
|
+
let path24 = unquoted;
|
|
51278
|
+
if (path24.startsWith("file://")) {
|
|
50947
51279
|
try {
|
|
50948
|
-
|
|
51280
|
+
path24 = fileURLToPath(path24);
|
|
50949
51281
|
} catch {
|
|
50950
51282
|
return false;
|
|
50951
51283
|
}
|
|
50952
51284
|
}
|
|
50953
|
-
return isAbsolute(
|
|
51285
|
+
return isAbsolute(path24) && !existsSync(path24);
|
|
50954
51286
|
}
|
|
50955
51287
|
function stripQuotes(value) {
|
|
50956
51288
|
const first = value[0];
|
|
@@ -51003,7 +51335,7 @@ var require_transport = __commonJS({
|
|
|
51003
51335
|
return;
|
|
51004
51336
|
}
|
|
51005
51337
|
stream.flushSync();
|
|
51006
|
-
|
|
51338
|
+
sleep4(100);
|
|
51007
51339
|
stream.end();
|
|
51008
51340
|
}
|
|
51009
51341
|
return stream;
|
|
@@ -52644,7 +52976,7 @@ var require_multistream = __commonJS({
|
|
|
52644
52976
|
var require_pino = __commonJS({
|
|
52645
52977
|
"node_modules/pino/pino.js"(exports, module) {
|
|
52646
52978
|
"use strict";
|
|
52647
|
-
var
|
|
52979
|
+
var os17 = __require("node:os");
|
|
52648
52980
|
var stdSerializers = require_pino_std_serializers();
|
|
52649
52981
|
var caller = require_caller();
|
|
52650
52982
|
var redaction = require_redaction();
|
|
@@ -52691,7 +53023,7 @@ var require_pino = __commonJS({
|
|
|
52691
53023
|
} = symbols;
|
|
52692
53024
|
var { epochTime, nullTime } = time3;
|
|
52693
53025
|
var { pid } = process;
|
|
52694
|
-
var hostname2 =
|
|
53026
|
+
var hostname2 = os17.hostname();
|
|
52695
53027
|
var defaultErrorSerializer = stdSerializers.err;
|
|
52696
53028
|
var defaultOptions2 = {
|
|
52697
53029
|
level: "info",
|
|
@@ -85017,15 +85349,15 @@ var require_tools2 = __commonJS({
|
|
|
85017
85349
|
* @param {String} path - Mailbox path to encode
|
|
85018
85350
|
* @returns {String} Encoded mailbox path
|
|
85019
85351
|
*/
|
|
85020
|
-
encodePath(connection,
|
|
85021
|
-
|
|
85022
|
-
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(
|
|
85352
|
+
encodePath(connection, path24) {
|
|
85353
|
+
path24 = (path24 || "").toString();
|
|
85354
|
+
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(path24)) {
|
|
85023
85355
|
try {
|
|
85024
|
-
|
|
85356
|
+
path24 = iconv.encode(path24, "utf-7-imap").toString();
|
|
85025
85357
|
} catch {
|
|
85026
85358
|
}
|
|
85027
85359
|
}
|
|
85028
|
-
return
|
|
85360
|
+
return path24;
|
|
85029
85361
|
},
|
|
85030
85362
|
/**
|
|
85031
85363
|
* Decodes a mailbox path from modified UTF-7 if the server does not support UTF8=ACCEPT.
|
|
@@ -85034,15 +85366,15 @@ var require_tools2 = __commonJS({
|
|
|
85034
85366
|
* @param {String} path - Mailbox path to decode
|
|
85035
85367
|
* @returns {String} Decoded mailbox path
|
|
85036
85368
|
*/
|
|
85037
|
-
decodePath(connection,
|
|
85038
|
-
|
|
85039
|
-
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(
|
|
85369
|
+
decodePath(connection, path24) {
|
|
85370
|
+
path24 = (path24 || "").toString();
|
|
85371
|
+
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(path24)) {
|
|
85040
85372
|
try {
|
|
85041
|
-
|
|
85373
|
+
path24 = iconv.decode(Buffer.from(path24), "utf-7-imap").toString();
|
|
85042
85374
|
} catch {
|
|
85043
85375
|
}
|
|
85044
85376
|
}
|
|
85045
|
-
return
|
|
85377
|
+
return path24;
|
|
85046
85378
|
},
|
|
85047
85379
|
/**
|
|
85048
85380
|
* Normalizes a mailbox path by joining array segments with the namespace delimiter,
|
|
@@ -85053,17 +85385,17 @@ var require_tools2 = __commonJS({
|
|
|
85053
85385
|
* @param {Boolean} [skipNamespace] - If true, skips prepending the namespace prefix
|
|
85054
85386
|
* @returns {String} Normalized mailbox path
|
|
85055
85387
|
*/
|
|
85056
|
-
normalizePath(connection,
|
|
85057
|
-
if (Array.isArray(
|
|
85058
|
-
|
|
85388
|
+
normalizePath(connection, path24, skipNamespace) {
|
|
85389
|
+
if (Array.isArray(path24)) {
|
|
85390
|
+
path24 = path24.join(connection.namespace && connection.namespace.delimiter || "");
|
|
85059
85391
|
}
|
|
85060
|
-
if (
|
|
85392
|
+
if (path24.toUpperCase() === "INBOX") {
|
|
85061
85393
|
return "INBOX";
|
|
85062
85394
|
}
|
|
85063
|
-
if (!skipNamespace && connection.namespace && connection.namespace.prefix && !
|
|
85064
|
-
|
|
85395
|
+
if (!skipNamespace && connection.namespace && connection.namespace.prefix && !path24.startsWith(connection.namespace.prefix)) {
|
|
85396
|
+
path24 = connection.namespace.prefix + path24;
|
|
85065
85397
|
}
|
|
85066
|
-
return
|
|
85398
|
+
return path24;
|
|
85067
85399
|
},
|
|
85068
85400
|
/**
|
|
85069
85401
|
* Compares two mailbox paths for equality after normalization.
|
|
@@ -85394,14 +85726,14 @@ var require_tools2 = __commonJS({
|
|
|
85394
85726
|
}
|
|
85395
85727
|
}
|
|
85396
85728
|
if (map.emailId || map.uid) {
|
|
85397
|
-
let
|
|
85398
|
-
if (/[\u0080-\uffff]/.test(
|
|
85729
|
+
let path24 = mailbox.path;
|
|
85730
|
+
if (/[\u0080-\uffff]/.test(path24)) {
|
|
85399
85731
|
try {
|
|
85400
|
-
|
|
85732
|
+
path24 = iconv.encode(path24, "utf-7-imap").toString();
|
|
85401
85733
|
} catch {
|
|
85402
85734
|
}
|
|
85403
85735
|
}
|
|
85404
|
-
map.id = map.emailId || createHash2("md5").update([
|
|
85736
|
+
map.id = map.emailId || createHash2("md5").update([path24, mailbox.uidValidity?.toString() || "", map.uid.toString()].join(":")).digest("hex");
|
|
85405
85737
|
}
|
|
85406
85738
|
if (map.flags) {
|
|
85407
85739
|
let flagColor = tools.getFlagColor(map.flags);
|
|
@@ -85576,16 +85908,16 @@ var require_tools2 = __commonJS({
|
|
|
85576
85908
|
* @returns {Object} Parsed body structure tree with part numbers, types, parameters, and child nodes
|
|
85577
85909
|
*/
|
|
85578
85910
|
parseBodystructure(entry) {
|
|
85579
|
-
let walk = (node,
|
|
85580
|
-
|
|
85911
|
+
let walk = (node, path24) => {
|
|
85912
|
+
path24 = path24 || [];
|
|
85581
85913
|
let curNode = {}, i = 0, part = 0;
|
|
85582
|
-
if (
|
|
85583
|
-
curNode.part =
|
|
85914
|
+
if (path24.length) {
|
|
85915
|
+
curNode.part = path24.join(".");
|
|
85584
85916
|
}
|
|
85585
85917
|
if (Array.isArray(node[0])) {
|
|
85586
85918
|
curNode.childNodes = [];
|
|
85587
85919
|
while (Array.isArray(node[i])) {
|
|
85588
|
-
curNode.childNodes.push(walk(node[i],
|
|
85920
|
+
curNode.childNodes.push(walk(node[i], path24.concat(++part)));
|
|
85589
85921
|
i++;
|
|
85590
85922
|
}
|
|
85591
85923
|
curNode.type = "multipart/" + ((node[i++] || {}).value || "").toString().toLowerCase();
|
|
@@ -85628,7 +85960,7 @@ var require_tools2 = __commonJS({
|
|
|
85628
85960
|
// the encapsulated message shares the part number with its wrapper.
|
|
85629
85961
|
// Distinction is via suffixes: path.MIME = wrapper headers,
|
|
85630
85962
|
// path.HEADER = encapsulated message headers.
|
|
85631
|
-
walk(node[i],
|
|
85963
|
+
walk(node[i], path24)
|
|
85632
85964
|
];
|
|
85633
85965
|
}
|
|
85634
85966
|
i++;
|
|
@@ -87590,14 +87922,14 @@ var require_select = __commonJS({
|
|
|
87590
87922
|
// update into a silent no-op for the rest of the session.
|
|
87591
87923
|
permanentflags: { key: "permanentFlags", parse: (value) => Array.isArray(value) && new Set(value) }
|
|
87592
87924
|
});
|
|
87593
|
-
module.exports = async (connection,
|
|
87925
|
+
module.exports = async (connection, path24, options) => {
|
|
87594
87926
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
87595
87927
|
return;
|
|
87596
87928
|
}
|
|
87597
87929
|
options = options || {};
|
|
87598
|
-
|
|
87599
|
-
if (!connection.folders.has(
|
|
87600
|
-
let folders = await connection.run("LIST", "",
|
|
87930
|
+
path24 = normalizePath(connection, path24);
|
|
87931
|
+
if (!connection.folders.has(path24)) {
|
|
87932
|
+
let folders = await connection.run("LIST", "", path24);
|
|
87601
87933
|
if (!folders) {
|
|
87602
87934
|
throw new Error("Failed to fetch folders");
|
|
87603
87935
|
}
|
|
@@ -87605,10 +87937,10 @@ var require_select = __commonJS({
|
|
|
87605
87937
|
connection.folders.set(folder.path, folder);
|
|
87606
87938
|
});
|
|
87607
87939
|
}
|
|
87608
|
-
let folderListData = connection.folders.has(
|
|
87940
|
+
let folderListData = connection.folders.has(path24) ? connection.folders.get(path24) : false;
|
|
87609
87941
|
let response;
|
|
87610
87942
|
try {
|
|
87611
|
-
let map = { path:
|
|
87943
|
+
let map = { path: path24 };
|
|
87612
87944
|
if (folderListData) {
|
|
87613
87945
|
["delimiter", "specialUse", "subscribed", "listed"].forEach((key) => {
|
|
87614
87946
|
if (folderListData[key]) {
|
|
@@ -87627,7 +87959,7 @@ var require_select = __commonJS({
|
|
|
87627
87959
|
]);
|
|
87628
87960
|
map.qresync = true;
|
|
87629
87961
|
}
|
|
87630
|
-
let encodedPath = encodePath(connection,
|
|
87962
|
+
let encodedPath = encodePath(connection, path24);
|
|
87631
87963
|
let selectCommand = {
|
|
87632
87964
|
command: !options.readOnly ? "SELECT" : "EXAMINE",
|
|
87633
87965
|
/* c8 ignore next */
|
|
@@ -87687,12 +88019,12 @@ var require_select = __commonJS({
|
|
|
87687
88019
|
// since the client's last known state. Only received when QRESYNC was requested.
|
|
87688
88020
|
// A dummy mailbox object is passed because the mailbox isn't officially open yet.
|
|
87689
88021
|
VANISHED: async (untagged) => {
|
|
87690
|
-
await connection.untaggedVanished(untagged, { path:
|
|
88022
|
+
await connection.untaggedVanished(untagged, { path: path24, uidNext: false, uidValidity: false });
|
|
87691
88023
|
},
|
|
87692
88024
|
// Untagged FETCH during SELECT/EXAMINE: only occurs with QRESYNC, delivering
|
|
87693
88025
|
// updated flags for messages that changed since the client's last modseq.
|
|
87694
88026
|
FETCH: async (untagged) => {
|
|
87695
|
-
await connection.untaggedFetch(untagged, { path:
|
|
88027
|
+
await connection.untaggedFetch(untagged, { path: path24, uidNext: false, uidValidity: false });
|
|
87696
88028
|
}
|
|
87697
88029
|
}
|
|
87698
88030
|
});
|
|
@@ -87706,13 +88038,13 @@ var require_select = __commonJS({
|
|
|
87706
88038
|
}
|
|
87707
88039
|
let currentMailbox = connection.mailbox;
|
|
87708
88040
|
connection.mailbox = false;
|
|
87709
|
-
if (currentMailbox && currentMailbox.path !==
|
|
88041
|
+
if (currentMailbox && currentMailbox.path !== path24) {
|
|
87710
88042
|
connection.emit("mailboxClose", currentMailbox);
|
|
87711
88043
|
}
|
|
87712
88044
|
connection.mailbox = map;
|
|
87713
88045
|
connection.currentSelectCommand = selectCommand;
|
|
87714
88046
|
connection.state = connection.states.SELECTED;
|
|
87715
|
-
if (!currentMailbox || currentMailbox.path !==
|
|
88047
|
+
if (!currentMailbox || currentMailbox.path !== path24) {
|
|
87716
88048
|
connection.emit("mailboxOpen", connection.mailbox);
|
|
87717
88049
|
}
|
|
87718
88050
|
response.next();
|
|
@@ -87927,17 +88259,17 @@ var require_create = __commonJS({
|
|
|
87927
88259
|
"node_modules/imapflow/lib/commands/create.js"(exports, module) {
|
|
87928
88260
|
"use strict";
|
|
87929
88261
|
var { encodePath, normalizePath, getStatusCode, enhanceCommandError } = require_tools2();
|
|
87930
|
-
module.exports = async (connection,
|
|
88262
|
+
module.exports = async (connection, path24) => {
|
|
87931
88263
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
87932
88264
|
return;
|
|
87933
88265
|
}
|
|
87934
|
-
|
|
88266
|
+
path24 = normalizePath(connection, path24);
|
|
87935
88267
|
let response;
|
|
87936
88268
|
try {
|
|
87937
88269
|
let map = {
|
|
87938
|
-
path:
|
|
88270
|
+
path: path24
|
|
87939
88271
|
};
|
|
87940
|
-
response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection,
|
|
88272
|
+
response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection, path24) }]);
|
|
87941
88273
|
let section = response.response.attributes && response.response.attributes[0] && response.response.attributes[0].section && response.response.attributes[0].section.length ? response.response.attributes[0].section : false;
|
|
87942
88274
|
if (section) {
|
|
87943
88275
|
let key;
|
|
@@ -87963,13 +88295,13 @@ var require_create = __commonJS({
|
|
|
87963
88295
|
}
|
|
87964
88296
|
map.created = true;
|
|
87965
88297
|
response.next();
|
|
87966
|
-
await connection.run("SUBSCRIBE",
|
|
88298
|
+
await connection.run("SUBSCRIBE", path24);
|
|
87967
88299
|
return map;
|
|
87968
88300
|
} catch (err) {
|
|
87969
88301
|
let errorCode = getStatusCode(err.response);
|
|
87970
88302
|
if (errorCode === "ALREADYEXISTS") {
|
|
87971
88303
|
return {
|
|
87972
|
-
path:
|
|
88304
|
+
path: path24,
|
|
87973
88305
|
created: false
|
|
87974
88306
|
};
|
|
87975
88307
|
}
|
|
@@ -87986,20 +88318,20 @@ var require_delete = __commonJS({
|
|
|
87986
88318
|
"node_modules/imapflow/lib/commands/delete.js"(exports, module) {
|
|
87987
88319
|
"use strict";
|
|
87988
88320
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
87989
|
-
module.exports = async (connection,
|
|
88321
|
+
module.exports = async (connection, path24) => {
|
|
87990
88322
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
87991
88323
|
return;
|
|
87992
88324
|
}
|
|
87993
|
-
|
|
87994
|
-
if (connection.state === connection.states.SELECTED && connection.mailbox.path ===
|
|
88325
|
+
path24 = normalizePath(connection, path24);
|
|
88326
|
+
if (connection.state === connection.states.SELECTED && connection.mailbox.path === path24) {
|
|
87995
88327
|
await connection.run("CLOSE");
|
|
87996
88328
|
}
|
|
87997
88329
|
let response;
|
|
87998
88330
|
try {
|
|
87999
88331
|
let map = {
|
|
88000
|
-
path:
|
|
88332
|
+
path: path24
|
|
88001
88333
|
};
|
|
88002
|
-
response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection,
|
|
88334
|
+
response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection, path24) }]);
|
|
88003
88335
|
response.next();
|
|
88004
88336
|
return map;
|
|
88005
88337
|
} catch (err) {
|
|
@@ -88016,23 +88348,23 @@ var require_rename = __commonJS({
|
|
|
88016
88348
|
"node_modules/imapflow/lib/commands/rename.js"(exports, module) {
|
|
88017
88349
|
"use strict";
|
|
88018
88350
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88019
|
-
module.exports = async (connection,
|
|
88351
|
+
module.exports = async (connection, path24, newPath) => {
|
|
88020
88352
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88021
88353
|
return;
|
|
88022
88354
|
}
|
|
88023
|
-
|
|
88355
|
+
path24 = normalizePath(connection, path24);
|
|
88024
88356
|
newPath = normalizePath(connection, newPath);
|
|
88025
|
-
if (connection.state === connection.states.SELECTED && connection.mailbox.path ===
|
|
88357
|
+
if (connection.state === connection.states.SELECTED && connection.mailbox.path === path24) {
|
|
88026
88358
|
await connection.run("CLOSE");
|
|
88027
88359
|
}
|
|
88028
88360
|
let response;
|
|
88029
88361
|
try {
|
|
88030
88362
|
let map = {
|
|
88031
|
-
path:
|
|
88363
|
+
path: path24,
|
|
88032
88364
|
newPath
|
|
88033
88365
|
};
|
|
88034
88366
|
response = await connection.exec("RENAME", [
|
|
88035
|
-
{ type: "ATOM", value: encodePath(connection,
|
|
88367
|
+
{ type: "ATOM", value: encodePath(connection, path24) },
|
|
88036
88368
|
{ type: "ATOM", value: encodePath(connection, newPath) }
|
|
88037
88369
|
]);
|
|
88038
88370
|
response.next();
|
|
@@ -88079,14 +88411,14 @@ var require_subscribe = __commonJS({
|
|
|
88079
88411
|
"node_modules/imapflow/lib/commands/subscribe.js"(exports, module) {
|
|
88080
88412
|
"use strict";
|
|
88081
88413
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88082
|
-
module.exports = async (connection,
|
|
88414
|
+
module.exports = async (connection, path24) => {
|
|
88083
88415
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88084
88416
|
return;
|
|
88085
88417
|
}
|
|
88086
|
-
|
|
88418
|
+
path24 = normalizePath(connection, path24);
|
|
88087
88419
|
let response;
|
|
88088
88420
|
try {
|
|
88089
|
-
response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection,
|
|
88421
|
+
response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path24) }]);
|
|
88090
88422
|
response.next();
|
|
88091
88423
|
return true;
|
|
88092
88424
|
} catch (err) {
|
|
@@ -88103,14 +88435,14 @@ var require_unsubscribe = __commonJS({
|
|
|
88103
88435
|
"node_modules/imapflow/lib/commands/unsubscribe.js"(exports, module) {
|
|
88104
88436
|
"use strict";
|
|
88105
88437
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88106
|
-
module.exports = async (connection,
|
|
88438
|
+
module.exports = async (connection, path24) => {
|
|
88107
88439
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88108
88440
|
return;
|
|
88109
88441
|
}
|
|
88110
|
-
|
|
88442
|
+
path24 = normalizePath(connection, path24);
|
|
88111
88443
|
let response;
|
|
88112
88444
|
try {
|
|
88113
|
-
response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection,
|
|
88445
|
+
response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path24) }]);
|
|
88114
88446
|
response.next();
|
|
88115
88447
|
return true;
|
|
88116
88448
|
} catch (err) {
|
|
@@ -88916,11 +89248,11 @@ var require_status = __commonJS({
|
|
|
88916
89248
|
var { encodePath, normalizePath, buildStatusQueryAttributes, isRev2Active } = require_tools2();
|
|
88917
89249
|
var { parseStatusList } = require_status_fields();
|
|
88918
89250
|
var MAILBOX_UPDATERS = {
|
|
88919
|
-
messages: (value, connection,
|
|
89251
|
+
messages: (value, connection, path24) => {
|
|
88920
89252
|
let prevCount = connection.mailbox.exists;
|
|
88921
89253
|
if (prevCount !== value) {
|
|
88922
89254
|
connection.mailbox.exists = value;
|
|
88923
|
-
connection.emit("exists", { path:
|
|
89255
|
+
connection.emit("exists", { path: path24, count: value, prevCount });
|
|
88924
89256
|
}
|
|
88925
89257
|
},
|
|
88926
89258
|
uidNext: (value, connection) => {
|
|
@@ -88930,28 +89262,28 @@ var require_status = __commonJS({
|
|
|
88930
89262
|
connection.mailbox.highestModseq = value;
|
|
88931
89263
|
}
|
|
88932
89264
|
};
|
|
88933
|
-
module.exports = async (connection,
|
|
88934
|
-
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !
|
|
89265
|
+
module.exports = async (connection, path24, query) => {
|
|
89266
|
+
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path24) {
|
|
88935
89267
|
return false;
|
|
88936
89268
|
}
|
|
88937
|
-
|
|
88938
|
-
let encodedPath = encodePath(connection,
|
|
89269
|
+
path24 = normalizePath(connection, path24);
|
|
89270
|
+
let encodedPath = encodePath(connection, path24);
|
|
88939
89271
|
let attributes = [{ type: encodedPath.indexOf("&") >= 0 ? "STRING" : "ATOM", value: encodedPath }];
|
|
88940
89272
|
let queryAttributes = buildStatusQueryAttributes(connection, query);
|
|
88941
89273
|
let syntheticRecent = query && query.recent && isRev2Active(connection);
|
|
88942
89274
|
if (!queryAttributes.length) {
|
|
88943
|
-
return syntheticRecent ? { path:
|
|
89275
|
+
return syntheticRecent ? { path: path24, recent: 0 } : false;
|
|
88944
89276
|
}
|
|
88945
89277
|
attributes.push(queryAttributes);
|
|
88946
89278
|
let response;
|
|
88947
89279
|
try {
|
|
88948
|
-
let map = { path:
|
|
89280
|
+
let map = { path: path24 };
|
|
88949
89281
|
response = await connection.exec("STATUS", attributes, {
|
|
88950
89282
|
untagged: {
|
|
88951
89283
|
// STATUS response: * STATUS <mailbox> (<key> <value> <key> <value> ...)
|
|
88952
89284
|
// Parsed as alternating key-value pairs (i % 2 pattern).
|
|
88953
89285
|
STATUS: async (untagged) => {
|
|
88954
|
-
let updateCurrent = connection.state === connection.states.SELECTED &&
|
|
89286
|
+
let updateCurrent = connection.state === connection.states.SELECTED && path24 === connection.mailbox.path;
|
|
88955
89287
|
let list = untagged.attributes && Array.isArray(untagged.attributes[1]) ? untagged.attributes[1] : false;
|
|
88956
89288
|
if (!list) {
|
|
88957
89289
|
return;
|
|
@@ -88959,7 +89291,7 @@ var require_status = __commonJS({
|
|
|
88959
89291
|
parseStatusList(list, (key, value) => {
|
|
88960
89292
|
map[key] = value;
|
|
88961
89293
|
if (updateCurrent && MAILBOX_UPDATERS[key]) {
|
|
88962
|
-
MAILBOX_UPDATERS[key](value, connection,
|
|
89294
|
+
MAILBOX_UPDATERS[key](value, connection, path24);
|
|
88963
89295
|
}
|
|
88964
89296
|
});
|
|
88965
89297
|
}
|
|
@@ -88972,9 +89304,9 @@ var require_status = __commonJS({
|
|
|
88972
89304
|
return map;
|
|
88973
89305
|
} catch (err) {
|
|
88974
89306
|
if (err.responseStatus === "NO") {
|
|
88975
|
-
let folders = await connection.run("LIST", "",
|
|
89307
|
+
let folders = await connection.run("LIST", "", path24, { listOnly: true });
|
|
88976
89308
|
if (folders && !folders.length) {
|
|
88977
|
-
let error2 = new Error(`Mailbox doesn't exist: ${
|
|
89309
|
+
let error2 = new Error(`Mailbox doesn't exist: ${path24}`);
|
|
88978
89310
|
error2.code = "NotFound";
|
|
88979
89311
|
error2.response = err;
|
|
88980
89312
|
throw error2;
|
|
@@ -89121,15 +89453,15 @@ var require_quota = __commonJS({
|
|
|
89121
89453
|
"node_modules/imapflow/lib/commands/quota.js"(exports, module) {
|
|
89122
89454
|
"use strict";
|
|
89123
89455
|
var { encodePath, normalizePath, enhanceCommandError, parseUintValue, isUnsafeKey } = require_tools2();
|
|
89124
|
-
module.exports = async (connection,
|
|
89125
|
-
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !
|
|
89456
|
+
module.exports = async (connection, path24) => {
|
|
89457
|
+
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path24) {
|
|
89126
89458
|
return;
|
|
89127
89459
|
}
|
|
89128
89460
|
if (!connection.capabilities.has("QUOTA")) {
|
|
89129
89461
|
return false;
|
|
89130
89462
|
}
|
|
89131
|
-
|
|
89132
|
-
let map = { path:
|
|
89463
|
+
path24 = normalizePath(connection, path24);
|
|
89464
|
+
let map = { path: path24 };
|
|
89133
89465
|
let processQuotaResponse = (untagged) => {
|
|
89134
89466
|
let attributes = untagged.attributes && untagged.attributes[1];
|
|
89135
89467
|
if (!attributes || !attributes.length) {
|
|
@@ -89169,7 +89501,7 @@ var require_quota = __commonJS({
|
|
|
89169
89501
|
let quotaFound = false;
|
|
89170
89502
|
let response;
|
|
89171
89503
|
try {
|
|
89172
|
-
response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection,
|
|
89504
|
+
response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection, path24) }], {
|
|
89173
89505
|
untagged: {
|
|
89174
89506
|
// QUOTAROOT response tells us which quota root applies to this mailbox.
|
|
89175
89507
|
// A mailbox may have zero or one quota root.
|
|
@@ -89312,15 +89644,15 @@ var require_idle = __commonJS({
|
|
|
89312
89644
|
}
|
|
89313
89645
|
}
|
|
89314
89646
|
async function pollOnce2(connection, session) {
|
|
89315
|
-
let
|
|
89647
|
+
let path24 = connection.mailbox && connection.mailbox.path;
|
|
89316
89648
|
switch (connection.missingIdleCommand) {
|
|
89317
89649
|
case "SELECT":
|
|
89318
89650
|
connection.log.debug({ src: "c", msg: `Running SELECT to detect changes in folder`, cid: connection.id });
|
|
89319
|
-
await connection.runInternal("SELECT",
|
|
89651
|
+
await connection.runInternal("SELECT", path24, { readOnly: session.selectCommand.command === "EXAMINE" });
|
|
89320
89652
|
break;
|
|
89321
89653
|
case "STATUS": {
|
|
89322
89654
|
connection.log.debug({ src: "c", msg: `Running STATUS to detect changes in folder`, cid: connection.id });
|
|
89323
|
-
let status = await connection.runInternal("STATUS",
|
|
89655
|
+
let status = await connection.runInternal("STATUS", path24, {
|
|
89324
89656
|
messages: true,
|
|
89325
89657
|
uidNext: true,
|
|
89326
89658
|
uidValidity: true,
|
|
@@ -89613,7 +89945,7 @@ var require_imap_flow = __commonJS({
|
|
|
89613
89945
|
"use strict";
|
|
89614
89946
|
var tls = __require("tls");
|
|
89615
89947
|
var net = __require("net");
|
|
89616
|
-
var
|
|
89948
|
+
var crypto12 = __require("crypto");
|
|
89617
89949
|
var { EventEmitter } = __require("events");
|
|
89618
89950
|
var logger2 = require_logger();
|
|
89619
89951
|
var libmime = require_libmime();
|
|
@@ -89920,7 +90252,7 @@ var require_imap_flow = __commonJS({
|
|
|
89920
90252
|
this.emit("error", err);
|
|
89921
90253
|
}
|
|
89922
90254
|
getRandomId() {
|
|
89923
|
-
let rid = BigInt("0x" +
|
|
90255
|
+
let rid = BigInt("0x" + crypto12.randomBytes(13).toString("hex")).toString(36);
|
|
89924
90256
|
if (rid.length < 20) {
|
|
89925
90257
|
rid = "0".repeat(20 - rid.length) + rid;
|
|
89926
90258
|
}
|
|
@@ -91007,12 +91339,12 @@ var require_imap_flow = __commonJS({
|
|
|
91007
91339
|
this.emit("flags", updateEvent);
|
|
91008
91340
|
}
|
|
91009
91341
|
}
|
|
91010
|
-
async ensureSelectedMailbox(
|
|
91011
|
-
if (!
|
|
91342
|
+
async ensureSelectedMailbox(path24) {
|
|
91343
|
+
if (!path24) {
|
|
91012
91344
|
return false;
|
|
91013
91345
|
}
|
|
91014
|
-
if (!this.mailbox || !comparePaths(this, this.mailbox.path,
|
|
91015
|
-
return await this.mailboxOpen(
|
|
91346
|
+
if (!this.mailbox || !comparePaths(this, this.mailbox.path, path24)) {
|
|
91347
|
+
return await this.mailboxOpen(path24);
|
|
91016
91348
|
}
|
|
91017
91349
|
return true;
|
|
91018
91350
|
}
|
|
@@ -91427,9 +91759,9 @@ var require_imap_flow = __commonJS({
|
|
|
91427
91759
|
* let quota = await client.getQuota();
|
|
91428
91760
|
* console.log(quota.storage.used, quota.storage.limit)
|
|
91429
91761
|
*/
|
|
91430
|
-
async getQuota(
|
|
91431
|
-
|
|
91432
|
-
return await this.run("QUOTA",
|
|
91762
|
+
async getQuota(path24) {
|
|
91763
|
+
path24 = path24 || "INBOX";
|
|
91764
|
+
return await this.run("QUOTA", path24);
|
|
91433
91765
|
}
|
|
91434
91766
|
/**
|
|
91435
91767
|
* @typedef {Object} ListResponse
|
|
@@ -91539,8 +91871,8 @@ var require_imap_flow = __commonJS({
|
|
|
91539
91871
|
* console.log(info.path);
|
|
91540
91872
|
* // "INBOX.parent.child" // assumes "INBOX." as namespace prefix and "." as delimiter
|
|
91541
91873
|
*/
|
|
91542
|
-
async mailboxCreate(
|
|
91543
|
-
return await this.run("CREATE",
|
|
91874
|
+
async mailboxCreate(path24) {
|
|
91875
|
+
return await this.run("CREATE", path24);
|
|
91544
91876
|
}
|
|
91545
91877
|
/**
|
|
91546
91878
|
* @typedef {Object} MailboxRenameResponse
|
|
@@ -91561,8 +91893,8 @@ var require_imap_flow = __commonJS({
|
|
|
91561
91893
|
* console.log(info.newPath);
|
|
91562
91894
|
* // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
|
|
91563
91895
|
*/
|
|
91564
|
-
async mailboxRename(
|
|
91565
|
-
return await this.run("RENAME",
|
|
91896
|
+
async mailboxRename(path24, newPath) {
|
|
91897
|
+
return await this.run("RENAME", path24, newPath);
|
|
91566
91898
|
}
|
|
91567
91899
|
/**
|
|
91568
91900
|
* @typedef {Object} MailboxDeleteResponse
|
|
@@ -91581,8 +91913,8 @@ var require_imap_flow = __commonJS({
|
|
|
91581
91913
|
* console.log(info.path);
|
|
91582
91914
|
* // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
|
|
91583
91915
|
*/
|
|
91584
|
-
async mailboxDelete(
|
|
91585
|
-
return await this.run("DELETE",
|
|
91916
|
+
async mailboxDelete(path24) {
|
|
91917
|
+
return await this.run("DELETE", path24);
|
|
91586
91918
|
}
|
|
91587
91919
|
/**
|
|
91588
91920
|
* Subscribes to a mailbox
|
|
@@ -91593,8 +91925,8 @@ var require_imap_flow = __commonJS({
|
|
|
91593
91925
|
* @example
|
|
91594
91926
|
* await client.mailboxSubscribe('Important stuff ❗️');
|
|
91595
91927
|
*/
|
|
91596
|
-
async mailboxSubscribe(
|
|
91597
|
-
return await this.run("SUBSCRIBE",
|
|
91928
|
+
async mailboxSubscribe(path24) {
|
|
91929
|
+
return await this.run("SUBSCRIBE", path24);
|
|
91598
91930
|
}
|
|
91599
91931
|
/**
|
|
91600
91932
|
* Unsubscribes from a mailbox
|
|
@@ -91605,8 +91937,8 @@ var require_imap_flow = __commonJS({
|
|
|
91605
91937
|
* @example
|
|
91606
91938
|
* await client.mailboxUnsubscribe('Important stuff ❗️');
|
|
91607
91939
|
*/
|
|
91608
|
-
async mailboxUnsubscribe(
|
|
91609
|
-
return await this.run("UNSUBSCRIBE",
|
|
91940
|
+
async mailboxUnsubscribe(path24) {
|
|
91941
|
+
return await this.run("UNSUBSCRIBE", path24);
|
|
91610
91942
|
}
|
|
91611
91943
|
/**
|
|
91612
91944
|
* Opens a mailbox to access messages. You can perform message operations only against an opened mailbox.
|
|
@@ -91624,8 +91956,8 @@ var require_imap_flow = __commonJS({
|
|
|
91624
91956
|
* console.log(mailbox.exists);
|
|
91625
91957
|
* // 125
|
|
91626
91958
|
*/
|
|
91627
|
-
async mailboxOpen(
|
|
91628
|
-
return await this.run("SELECT",
|
|
91959
|
+
async mailboxOpen(path24, options) {
|
|
91960
|
+
return await this.run("SELECT", path24, options);
|
|
91629
91961
|
}
|
|
91630
91962
|
/**
|
|
91631
91963
|
* Closes a previously opened mailbox
|
|
@@ -91672,8 +92004,8 @@ var require_imap_flow = __commonJS({
|
|
|
91672
92004
|
* console.log(status.unseen);
|
|
91673
92005
|
* // 123
|
|
91674
92006
|
*/
|
|
91675
|
-
async status(
|
|
91676
|
-
return await this.run("STATUS",
|
|
92007
|
+
async status(path24, query) {
|
|
92008
|
+
return await this.run("STATUS", path24, query);
|
|
91677
92009
|
}
|
|
91678
92010
|
/**
|
|
91679
92011
|
* Starts listening for new or deleted messages from the currently opened mailbox. Only required if {@link ImapFlow#disableAutoIdle} is set to `true`
|
|
@@ -91927,8 +92259,8 @@ var require_imap_flow = __commonJS({
|
|
|
91927
92259
|
* @example
|
|
91928
92260
|
* await client.append('INBOX', rawMessageBuffer, ['\\Seen'], new Date(2000, 1, 1));
|
|
91929
92261
|
*/
|
|
91930
|
-
async append(
|
|
91931
|
-
return await this.run("APPEND",
|
|
92262
|
+
async append(path24, content, flags, idate) {
|
|
92263
|
+
return await this.run("APPEND", path24, content, flags, idate) || false;
|
|
91932
92264
|
}
|
|
91933
92265
|
/**
|
|
91934
92266
|
* @typedef {Object} CopyResponseObject
|
|
@@ -92772,7 +93104,7 @@ var require_imap_flow = __commonJS({
|
|
|
92772
93104
|
await new Promise((resolve2) => setImmediate(resolve2));
|
|
92773
93105
|
}
|
|
92774
93106
|
const lock = this.locks.shift();
|
|
92775
|
-
const { resolve, reject, path:
|
|
93107
|
+
const { resolve, reject, path: path24, options, lockId } = lock;
|
|
92776
93108
|
if (lock.acquireTimer) {
|
|
92777
93109
|
clearTimeout(lock.acquireTimer);
|
|
92778
93110
|
lock.acquireTimer = null;
|
|
@@ -92788,7 +93120,7 @@ var require_imap_flow = __commonJS({
|
|
|
92788
93120
|
this.log.warn({
|
|
92789
93121
|
msg: "Mailbox lock held for a long time",
|
|
92790
93122
|
lockId: lock.lockId,
|
|
92791
|
-
path:
|
|
93123
|
+
path: path24,
|
|
92792
93124
|
heldFor: Date.now() - lock.heldAt,
|
|
92793
93125
|
/* c8 ignore next */
|
|
92794
93126
|
// the held-lock-warning diagnostic with a description set is a timing-dependent log detail
|
|
@@ -92824,52 +93156,52 @@ var require_imap_flow = __commonJS({
|
|
|
92824
93156
|
}
|
|
92825
93157
|
};
|
|
92826
93158
|
if (!this.usable || !this.socket || this.socket.destroyed) {
|
|
92827
|
-
this.log.trace({ msg: "Failed to acquire mailbox lock", path:
|
|
93159
|
+
this.log.trace({ msg: "Failed to acquire mailbox lock", path: path24, lockId, idling: this.idling });
|
|
92828
93160
|
let error2 = new Error("Connection not available");
|
|
92829
93161
|
error2.code = "NoConnection";
|
|
92830
93162
|
reject(error2);
|
|
92831
93163
|
continue;
|
|
92832
93164
|
}
|
|
92833
|
-
if (this.mailbox && this.mailbox.path ===
|
|
93165
|
+
if (this.mailbox && this.mailbox.path === path24 && !!this.mailbox.readOnly === !!options.readOnly) {
|
|
92834
93166
|
this.log.trace({
|
|
92835
93167
|
msg: "Mailbox lock acquired [existing]",
|
|
92836
|
-
path:
|
|
93168
|
+
path: path24,
|
|
92837
93169
|
lockId,
|
|
92838
93170
|
idling: this.idling,
|
|
92839
93171
|
...options.description && { description: options.description }
|
|
92840
93172
|
});
|
|
92841
93173
|
this.currentLock = lock;
|
|
92842
93174
|
armHeldTimer();
|
|
92843
|
-
resolve({ path:
|
|
93175
|
+
resolve({ path: path24, release });
|
|
92844
93176
|
break;
|
|
92845
93177
|
}
|
|
92846
93178
|
try {
|
|
92847
|
-
await this.mailboxOpen(
|
|
93179
|
+
await this.mailboxOpen(path24, options);
|
|
92848
93180
|
this.log.trace({
|
|
92849
93181
|
msg: "Mailbox lock acquired [selected]",
|
|
92850
|
-
path:
|
|
93182
|
+
path: path24,
|
|
92851
93183
|
lockId,
|
|
92852
93184
|
idling: this.idling,
|
|
92853
93185
|
...options.description && { description: options.description }
|
|
92854
93186
|
});
|
|
92855
93187
|
this.currentLock = lock;
|
|
92856
93188
|
armHeldTimer();
|
|
92857
|
-
resolve({ path:
|
|
93189
|
+
resolve({ path: path24, release });
|
|
92858
93190
|
break;
|
|
92859
93191
|
} catch (err) {
|
|
92860
93192
|
if (err.responseStatus === "NO") {
|
|
92861
93193
|
try {
|
|
92862
|
-
let folders = await this.run("LIST", "",
|
|
93194
|
+
let folders = await this.run("LIST", "", path24, { listOnly: true });
|
|
92863
93195
|
if (!folders || !folders.length) {
|
|
92864
93196
|
err.mailboxMissing = true;
|
|
92865
93197
|
}
|
|
92866
93198
|
} catch (E) {
|
|
92867
|
-
this.log.trace({ msg: "Failed to verify failed mailbox", path:
|
|
93199
|
+
this.log.trace({ msg: "Failed to verify failed mailbox", path: path24, err: E });
|
|
92868
93200
|
}
|
|
92869
93201
|
}
|
|
92870
93202
|
this.log.trace({
|
|
92871
93203
|
msg: "Failed to acquire mailbox lock",
|
|
92872
|
-
path:
|
|
93204
|
+
path: path24,
|
|
92873
93205
|
lockId,
|
|
92874
93206
|
idling: this.idling,
|
|
92875
93207
|
...options.description && { description: options.description },
|
|
@@ -92908,13 +93240,13 @@ var require_imap_flow = __commonJS({
|
|
|
92908
93240
|
* lock.release();
|
|
92909
93241
|
* }
|
|
92910
93242
|
*/
|
|
92911
|
-
getMailboxLock(
|
|
93243
|
+
getMailboxLock(path24, options) {
|
|
92912
93244
|
options = options || {};
|
|
92913
|
-
|
|
93245
|
+
path24 = normalizePath(this, path24);
|
|
92914
93246
|
let lockId = ++this.lockCounter;
|
|
92915
93247
|
this.log.trace({
|
|
92916
93248
|
msg: "Requesting lock",
|
|
92917
|
-
path:
|
|
93249
|
+
path: path24,
|
|
92918
93250
|
lockId,
|
|
92919
93251
|
...options.description && { description: options.description },
|
|
92920
93252
|
activeLock: this.currentLock ? {
|
|
@@ -92923,7 +93255,7 @@ var require_imap_flow = __commonJS({
|
|
|
92923
93255
|
} : null
|
|
92924
93256
|
});
|
|
92925
93257
|
let lockPromise = new Promise((resolve, reject) => {
|
|
92926
|
-
let lockEntry = { resolve, reject, path:
|
|
93258
|
+
let lockEntry = { resolve, reject, path: path24, options, lockId };
|
|
92927
93259
|
this.locks.push(lockEntry);
|
|
92928
93260
|
if (Number(options.acquireTimeout) > 0) {
|
|
92929
93261
|
lockEntry.acquireTimer = setTimeout(() => {
|
|
@@ -93012,16 +93344,16 @@ var require_imap_flow = __commonJS({
|
|
|
93012
93344
|
});
|
|
93013
93345
|
|
|
93014
93346
|
// src/mail/mail-fetcher.ts
|
|
93015
|
-
import
|
|
93016
|
-
import
|
|
93347
|
+
import fs21 from "node:fs/promises";
|
|
93348
|
+
import path22 from "node:path";
|
|
93017
93349
|
async function saveAttachments(attachments, downloadDir) {
|
|
93018
93350
|
if (attachments.length === 0) return [];
|
|
93019
|
-
await
|
|
93351
|
+
await fs21.mkdir(downloadDir, { recursive: true });
|
|
93020
93352
|
const saved = [];
|
|
93021
93353
|
for (const a of attachments) {
|
|
93022
|
-
const name =
|
|
93023
|
-
const savedPath =
|
|
93024
|
-
await
|
|
93354
|
+
const name = path22.basename(a.filename) || "attachment";
|
|
93355
|
+
const savedPath = path22.join(downloadDir, name);
|
|
93356
|
+
await fs21.writeFile(savedPath, a.content);
|
|
93025
93357
|
saved.push({ filename: name, savedPath, size: a.content.length });
|
|
93026
93358
|
}
|
|
93027
93359
|
return saved;
|
|
@@ -93151,8 +93483,8 @@ var init_mail_fetcher = __esm({
|
|
|
93151
93483
|
});
|
|
93152
93484
|
|
|
93153
93485
|
// src/tools/fetch-mail.ts
|
|
93154
|
-
import
|
|
93155
|
-
import
|
|
93486
|
+
import os16 from "node:os";
|
|
93487
|
+
import path23 from "node:path";
|
|
93156
93488
|
function registerFetchMailTool(server, deps = {}) {
|
|
93157
93489
|
const makeFetcher = deps.fetcherFactory ?? ((creds) => new ImapflowMailFetcher(creds));
|
|
93158
93490
|
server.registerTool(
|
|
@@ -93214,7 +93546,7 @@ var init_fetch_mail = __esm({
|
|
|
93214
93546
|
init_mail_fetcher();
|
|
93215
93547
|
init_auth_error();
|
|
93216
93548
|
init_validate();
|
|
93217
|
-
DEFAULT_DOWNLOAD_DIR =
|
|
93549
|
+
DEFAULT_DOWNLOAD_DIR = path23.join(os16.homedir(), ".cogent", "mail-downloads");
|
|
93218
93550
|
}
|
|
93219
93551
|
});
|
|
93220
93552
|
|