@essentialai/cogent-bridge-bundled 3.23.3 → 3.23.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cogent-bridge.mjs +636 -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.4") {
|
|
26393
|
+
return "3.23.4";
|
|
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
|
{
|
|
@@ -37178,8 +37497,8 @@ var require_cookies = __commonJS({
|
|
|
37178
37497
|
if (urlparts.hostname !== cookie.domain && (cookie.domain.charAt(0) !== "." || ("." + urlparts.hostname).substr(-cookie.domain.length) !== cookie.domain)) {
|
|
37179
37498
|
return false;
|
|
37180
37499
|
}
|
|
37181
|
-
let
|
|
37182
|
-
if (
|
|
37500
|
+
let path24 = this.getPath(urlparts.pathname);
|
|
37501
|
+
if (path24.substr(0, cookie.path.length) !== cookie.path) {
|
|
37183
37502
|
return false;
|
|
37184
37503
|
}
|
|
37185
37504
|
if (cookie.secure && urlparts.protocol !== "https:") {
|
|
@@ -37239,16 +37558,16 @@ var require_cookies = __commonJS({
|
|
|
37239
37558
|
* @returns {String} Normalized path
|
|
37240
37559
|
*/
|
|
37241
37560
|
getPath(pathname) {
|
|
37242
|
-
let
|
|
37243
|
-
|
|
37244
|
-
|
|
37245
|
-
if (
|
|
37246
|
-
|
|
37561
|
+
let path24 = (pathname || "/").split("/");
|
|
37562
|
+
path24.pop();
|
|
37563
|
+
path24 = path24.join("/").trim();
|
|
37564
|
+
if (path24.charAt(0) !== "/") {
|
|
37565
|
+
path24 = "/" + path24;
|
|
37247
37566
|
}
|
|
37248
|
-
if (
|
|
37249
|
-
|
|
37567
|
+
if (path24.substr(-1) !== "/") {
|
|
37568
|
+
path24 += "/";
|
|
37250
37569
|
}
|
|
37251
|
-
return
|
|
37570
|
+
return path24;
|
|
37252
37571
|
}
|
|
37253
37572
|
};
|
|
37254
37573
|
module.exports = Cookies;
|
|
@@ -37549,15 +37868,15 @@ var require_shared = __commonJS({
|
|
|
37549
37868
|
"use strict";
|
|
37550
37869
|
var urllib = __require("url");
|
|
37551
37870
|
var util2 = __require("util");
|
|
37552
|
-
var
|
|
37871
|
+
var fs22 = __require("fs");
|
|
37553
37872
|
var nmfetch = require_fetch();
|
|
37554
37873
|
var dns = __require("dns");
|
|
37555
37874
|
var net = __require("net");
|
|
37556
|
-
var
|
|
37875
|
+
var os17 = __require("os");
|
|
37557
37876
|
var DNS_TTL = 5 * 60 * 1e3;
|
|
37558
37877
|
var networkInterfaces;
|
|
37559
37878
|
try {
|
|
37560
|
-
networkInterfaces =
|
|
37879
|
+
networkInterfaces = os17.networkInterfaces();
|
|
37561
37880
|
} catch (err) {
|
|
37562
37881
|
}
|
|
37563
37882
|
module.exports.networkInterfaces = networkInterfaces;
|
|
@@ -37935,7 +38254,7 @@ var require_shared = __commonJS({
|
|
|
37935
38254
|
}
|
|
37936
38255
|
return callback(null, parsedDataUri.data);
|
|
37937
38256
|
} else if (content.path) {
|
|
37938
|
-
return resolveStream(
|
|
38257
|
+
return resolveStream(fs22.createReadStream(content.path), callback);
|
|
37939
38258
|
}
|
|
37940
38259
|
}
|
|
37941
38260
|
if (typeof data[key].content === "string" && !["utf8", "usascii", "ascii"].includes(encoding)) {
|
|
@@ -38059,7 +38378,7 @@ var require_shared = __commonJS({
|
|
|
38059
38378
|
var require_mime_types = __commonJS({
|
|
38060
38379
|
"node_modules/nodemailer/lib/mime-funcs/mime-types.js"(exports, module) {
|
|
38061
38380
|
"use strict";
|
|
38062
|
-
var
|
|
38381
|
+
var path24 = __require("path");
|
|
38063
38382
|
var defaultMimeType = "application/octet-stream";
|
|
38064
38383
|
var defaultExtension = "bin";
|
|
38065
38384
|
var mimeTypes = /* @__PURE__ */ new Map([
|
|
@@ -40117,7 +40436,7 @@ var require_mime_types = __commonJS({
|
|
|
40117
40436
|
if (!filename) {
|
|
40118
40437
|
return defaultMimeType;
|
|
40119
40438
|
}
|
|
40120
|
-
let parsed =
|
|
40439
|
+
let parsed = path24.parse(filename);
|
|
40121
40440
|
let extension = (parsed.ext.substr(1) || parsed.name || "").split("?").shift().trim().toLowerCase();
|
|
40122
40441
|
let value = defaultMimeType;
|
|
40123
40442
|
if (extensions.has(extension)) {
|
|
@@ -41518,8 +41837,8 @@ var require_le_unix = __commonJS({
|
|
|
41518
41837
|
var require_mime_node = __commonJS({
|
|
41519
41838
|
"node_modules/nodemailer/lib/mime-node/index.js"(exports, module) {
|
|
41520
41839
|
"use strict";
|
|
41521
|
-
var
|
|
41522
|
-
var
|
|
41840
|
+
var crypto12 = __require("crypto");
|
|
41841
|
+
var fs22 = __require("fs");
|
|
41523
41842
|
var punycode = require_punycode();
|
|
41524
41843
|
var PassThrough = __require("stream").PassThrough;
|
|
41525
41844
|
var shared = require_shared();
|
|
@@ -41535,7 +41854,7 @@ var require_mime_node = __commonJS({
|
|
|
41535
41854
|
constructor(contentType, options) {
|
|
41536
41855
|
this.nodeCounter = 0;
|
|
41537
41856
|
options = options || {};
|
|
41538
|
-
this.baseBoundary = options.baseBoundary ||
|
|
41857
|
+
this.baseBoundary = options.baseBoundary || crypto12.randomBytes(8).toString("hex");
|
|
41539
41858
|
this.boundaryPrefix = options.boundaryPrefix || "--_NmP";
|
|
41540
41859
|
this.disableFileAccess = !!options.disableFileAccess;
|
|
41541
41860
|
this.disableUrlAccess = !!options.disableUrlAccess;
|
|
@@ -42234,7 +42553,7 @@ var require_mime_node = __commonJS({
|
|
|
42234
42553
|
setImmediate(() => contentStream.emit("error", new Error("File access rejected for " + content.path)));
|
|
42235
42554
|
return contentStream;
|
|
42236
42555
|
}
|
|
42237
|
-
return
|
|
42556
|
+
return fs22.createReadStream(content.path);
|
|
42238
42557
|
} else if (content && typeof content.href === "string") {
|
|
42239
42558
|
if (this.disableUrlAccess) {
|
|
42240
42559
|
contentStream = new PassThrough();
|
|
@@ -42478,8 +42797,8 @@ var require_mime_node = __commonJS({
|
|
|
42478
42797
|
_generateMessageId() {
|
|
42479
42798
|
return "<" + [2, 2, 2, 6].reduce(
|
|
42480
42799
|
// crux to generate UUID-like random strings
|
|
42481
|
-
(prev, len) => prev + "-" +
|
|
42482
|
-
|
|
42800
|
+
(prev, len) => prev + "-" + crypto12.randomBytes(len).toString("hex"),
|
|
42801
|
+
crypto12.randomBytes(4).toString("hex")
|
|
42483
42802
|
) + "@" + // try to use the domain of the FROM address or fallback to server hostname
|
|
42484
42803
|
(this.getEnvelope().from || this.hostname || "localhost").split("@").pop() + ">";
|
|
42485
42804
|
}
|
|
@@ -43070,14 +43389,14 @@ var require_relaxed_body = __commonJS({
|
|
|
43070
43389
|
"node_modules/nodemailer/lib/dkim/relaxed-body.js"(exports, module) {
|
|
43071
43390
|
"use strict";
|
|
43072
43391
|
var Transform = __require("stream").Transform;
|
|
43073
|
-
var
|
|
43392
|
+
var crypto12 = __require("crypto");
|
|
43074
43393
|
var RelaxedBody = class extends Transform {
|
|
43075
43394
|
constructor(options) {
|
|
43076
43395
|
super();
|
|
43077
43396
|
options = options || {};
|
|
43078
43397
|
this.chunkBuffer = [];
|
|
43079
43398
|
this.chunkBufferLen = 0;
|
|
43080
|
-
this.bodyHash =
|
|
43399
|
+
this.bodyHash = crypto12.createHash(options.hashAlgo || "sha1");
|
|
43081
43400
|
this.remainder = "";
|
|
43082
43401
|
this.byteLength = 0;
|
|
43083
43402
|
this.debug = options.debug;
|
|
@@ -43180,7 +43499,7 @@ var require_sign = __commonJS({
|
|
|
43180
43499
|
"use strict";
|
|
43181
43500
|
var punycode = require_punycode();
|
|
43182
43501
|
var mimeFuncs = require_mime_funcs();
|
|
43183
|
-
var
|
|
43502
|
+
var crypto12 = __require("crypto");
|
|
43184
43503
|
module.exports = (headers, hashAlgo, bodyHash, options) => {
|
|
43185
43504
|
options = options || {};
|
|
43186
43505
|
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 +43508,7 @@ var require_sign = __commonJS({
|
|
|
43189
43508
|
let dkimHeader = generateDKIMHeader(options.domainName, options.keySelector, canonicalizedHeaderData.fieldNames, hashAlgo, bodyHash);
|
|
43190
43509
|
let signer, signature;
|
|
43191
43510
|
canonicalizedHeaderData.headers += "dkim-signature:" + relaxedHeaderLine(dkimHeader);
|
|
43192
|
-
signer =
|
|
43511
|
+
signer = crypto12.createSign(("rsa-" + hashAlgo).toUpperCase());
|
|
43193
43512
|
signer.update(canonicalizedHeaderData.headers);
|
|
43194
43513
|
try {
|
|
43195
43514
|
signature = signer.sign(options.privateKey, "base64");
|
|
@@ -43255,9 +43574,9 @@ var require_dkim = __commonJS({
|
|
|
43255
43574
|
var RelaxedBody = require_relaxed_body();
|
|
43256
43575
|
var sign = require_sign();
|
|
43257
43576
|
var PassThrough = __require("stream").PassThrough;
|
|
43258
|
-
var
|
|
43259
|
-
var
|
|
43260
|
-
var
|
|
43577
|
+
var fs22 = __require("fs");
|
|
43578
|
+
var path24 = __require("path");
|
|
43579
|
+
var crypto12 = __require("crypto");
|
|
43261
43580
|
var DKIM_ALGO = "sha256";
|
|
43262
43581
|
var MAX_MESSAGE_SIZE = 128 * 1024;
|
|
43263
43582
|
var DKIMSigner = class {
|
|
@@ -43270,7 +43589,7 @@ var require_dkim = __commonJS({
|
|
|
43270
43589
|
this.chunks = [];
|
|
43271
43590
|
this.chunklen = 0;
|
|
43272
43591
|
this.readPos = 0;
|
|
43273
|
-
this.cachePath = this.cacheDir ?
|
|
43592
|
+
this.cachePath = this.cacheDir ? path24.join(this.cacheDir, "message." + Date.now() + "-" + crypto12.randomBytes(14).toString("hex")) : false;
|
|
43274
43593
|
this.cache = false;
|
|
43275
43594
|
this.headers = false;
|
|
43276
43595
|
this.bodyHash = false;
|
|
@@ -43290,10 +43609,10 @@ var require_dkim = __commonJS({
|
|
|
43290
43609
|
if (!this.cache || !this.cachePath) {
|
|
43291
43610
|
return;
|
|
43292
43611
|
}
|
|
43293
|
-
|
|
43612
|
+
fs22.unlink(this.cachePath, () => false);
|
|
43294
43613
|
}
|
|
43295
43614
|
createReadCache() {
|
|
43296
|
-
this.cache =
|
|
43615
|
+
this.cache = fs22.createReadStream(this.cachePath);
|
|
43297
43616
|
this.cache.once("error", (err) => {
|
|
43298
43617
|
this.cleanup();
|
|
43299
43618
|
this.output.emit("error", err);
|
|
@@ -43349,7 +43668,7 @@ var require_dkim = __commonJS({
|
|
|
43349
43668
|
}
|
|
43350
43669
|
createWriteCache() {
|
|
43351
43670
|
this.output.usingCache = true;
|
|
43352
|
-
this.cache =
|
|
43671
|
+
this.cache = fs22.createWriteStream(this.cachePath);
|
|
43353
43672
|
this.cache.once("error", (err) => {
|
|
43354
43673
|
this.cleanup();
|
|
43355
43674
|
this.relaxedBody.unpipe(this.cache);
|
|
@@ -43826,7 +44145,7 @@ var require_mailer = __commonJS({
|
|
|
43826
44145
|
var MailMessage = require_mail_message();
|
|
43827
44146
|
var net = __require("net");
|
|
43828
44147
|
var dns = __require("dns");
|
|
43829
|
-
var
|
|
44148
|
+
var crypto12 = __require("crypto");
|
|
43830
44149
|
var Mail = class extends EventEmitter {
|
|
43831
44150
|
constructor(transporter, options, defaults) {
|
|
43832
44151
|
super();
|
|
@@ -44150,7 +44469,7 @@ var require_mailer = __commonJS({
|
|
|
44150
44469
|
}
|
|
44151
44470
|
let cidCounter = 0;
|
|
44152
44471
|
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 =
|
|
44472
|
+
let cid = crypto12.randomBytes(10).toString("hex") + "@localhost";
|
|
44154
44473
|
if (!mail.data.attachments) {
|
|
44155
44474
|
mail.data.attachments = [];
|
|
44156
44475
|
}
|
|
@@ -44276,8 +44595,8 @@ var require_smtp_connection = __commonJS({
|
|
|
44276
44595
|
var EventEmitter = __require("events").EventEmitter;
|
|
44277
44596
|
var net = __require("net");
|
|
44278
44597
|
var tls = __require("tls");
|
|
44279
|
-
var
|
|
44280
|
-
var
|
|
44598
|
+
var os17 = __require("os");
|
|
44599
|
+
var crypto12 = __require("crypto");
|
|
44281
44600
|
var DataStream = require_data_stream();
|
|
44282
44601
|
var PassThrough = __require("stream").PassThrough;
|
|
44283
44602
|
var shared = require_shared();
|
|
@@ -44288,7 +44607,7 @@ var require_smtp_connection = __commonJS({
|
|
|
44288
44607
|
var SMTPConnection = class extends EventEmitter {
|
|
44289
44608
|
constructor(options) {
|
|
44290
44609
|
super(options);
|
|
44291
|
-
this.id =
|
|
44610
|
+
this.id = crypto12.randomBytes(8).toString("base64").replace(/\W/g, "");
|
|
44292
44611
|
this.stage = "init";
|
|
44293
44612
|
this.options = options || {};
|
|
44294
44613
|
this.secureConnection = !!this.options.secure;
|
|
@@ -45381,7 +45700,7 @@ var require_smtp_connection = __commonJS({
|
|
|
45381
45700
|
} else {
|
|
45382
45701
|
challengeString = challengeMatch[1];
|
|
45383
45702
|
}
|
|
45384
|
-
let base64decoded = Buffer.from(challengeString, "base64").toString("ascii"), hmacMD5 =
|
|
45703
|
+
let base64decoded = Buffer.from(challengeString, "base64").toString("ascii"), hmacMD5 = crypto12.createHmac("md5", this._auth.credentials.pass);
|
|
45385
45704
|
hmacMD5.update(base64decoded);
|
|
45386
45705
|
let prepended = this._auth.credentials.user + " " + hmacMD5.digest("hex");
|
|
45387
45706
|
this._responseActions.push((str2) => {
|
|
@@ -45669,7 +45988,7 @@ var require_smtp_connection = __commonJS({
|
|
|
45669
45988
|
_getHostname() {
|
|
45670
45989
|
let defaultHostname;
|
|
45671
45990
|
try {
|
|
45672
|
-
defaultHostname =
|
|
45991
|
+
defaultHostname = os17.hostname() || "";
|
|
45673
45992
|
} catch (err) {
|
|
45674
45993
|
defaultHostname = "localhost";
|
|
45675
45994
|
}
|
|
@@ -45692,7 +46011,7 @@ var require_xoauth2 = __commonJS({
|
|
|
45692
46011
|
"use strict";
|
|
45693
46012
|
var Stream = __require("stream").Stream;
|
|
45694
46013
|
var nmfetch = require_fetch();
|
|
45695
|
-
var
|
|
46014
|
+
var crypto12 = __require("crypto");
|
|
45696
46015
|
var shared = require_shared();
|
|
45697
46016
|
var XOAuth2 = class extends Stream {
|
|
45698
46017
|
constructor(options, logger2) {
|
|
@@ -45983,7 +46302,7 @@ var require_xoauth2 = __commonJS({
|
|
|
45983
46302
|
*/
|
|
45984
46303
|
jwtSignRS256(payload) {
|
|
45985
46304
|
payload = ['{"alg":"RS256","typ":"JWT"}', JSON.stringify(payload)].map((val) => this.toBase64URL(val)).join(".");
|
|
45986
|
-
let signature =
|
|
46305
|
+
let signature = crypto12.createSign("RSA-SHA256").update(payload).sign(this.options.privateKey);
|
|
45987
46306
|
return payload + "." + this.toBase64URL(signature);
|
|
45988
46307
|
}
|
|
45989
46308
|
};
|
|
@@ -48238,13 +48557,13 @@ var require_nodemailer = __commonJS({
|
|
|
48238
48557
|
});
|
|
48239
48558
|
|
|
48240
48559
|
// src/mail/mail-sender.ts
|
|
48241
|
-
import
|
|
48242
|
-
import
|
|
48560
|
+
import fs20 from "node:fs/promises";
|
|
48561
|
+
import path21 from "node:path";
|
|
48243
48562
|
async function buildAndSendMail(sender, creds, params) {
|
|
48244
48563
|
const attachments = [];
|
|
48245
48564
|
for (const p of params.attachmentPaths ?? []) {
|
|
48246
|
-
const content = await
|
|
48247
|
-
attachments.push({ filename:
|
|
48565
|
+
const content = await fs20.readFile(p);
|
|
48566
|
+
attachments.push({ filename: path21.basename(p), content });
|
|
48248
48567
|
}
|
|
48249
48568
|
const { messageId } = await sender.send({
|
|
48250
48569
|
from: creds.address,
|
|
@@ -48633,8 +48952,8 @@ var require_req = __commonJS({
|
|
|
48633
48952
|
if (req.originalUrl) {
|
|
48634
48953
|
_req.url = req.originalUrl;
|
|
48635
48954
|
} else {
|
|
48636
|
-
const
|
|
48637
|
-
_req.url = typeof
|
|
48955
|
+
const path24 = req.path;
|
|
48956
|
+
_req.url = typeof path24 === "string" ? path24 : req.url ? req.url.path || req.url : void 0;
|
|
48638
48957
|
}
|
|
48639
48958
|
if (req.query) {
|
|
48640
48959
|
_req.query = req.query;
|
|
@@ -48799,14 +49118,14 @@ var require_redact = __commonJS({
|
|
|
48799
49118
|
}
|
|
48800
49119
|
return obj;
|
|
48801
49120
|
}
|
|
48802
|
-
function parsePath(
|
|
49121
|
+
function parsePath(path24) {
|
|
48803
49122
|
const parts = [];
|
|
48804
49123
|
let current = "";
|
|
48805
49124
|
let inBrackets = false;
|
|
48806
49125
|
let inQuotes = false;
|
|
48807
49126
|
let quoteChar = "";
|
|
48808
|
-
for (let i = 0; i <
|
|
48809
|
-
const char =
|
|
49127
|
+
for (let i = 0; i < path24.length; i++) {
|
|
49128
|
+
const char = path24[i];
|
|
48810
49129
|
if (!inBrackets && char === ".") {
|
|
48811
49130
|
if (current) {
|
|
48812
49131
|
parts.push(current);
|
|
@@ -48937,10 +49256,10 @@ var require_redact = __commonJS({
|
|
|
48937
49256
|
return current;
|
|
48938
49257
|
}
|
|
48939
49258
|
function redactPaths(obj, paths, censor, remove = false) {
|
|
48940
|
-
for (const
|
|
48941
|
-
const parts = parsePath(
|
|
49259
|
+
for (const path24 of paths) {
|
|
49260
|
+
const parts = parsePath(path24);
|
|
48942
49261
|
if (parts.includes("*")) {
|
|
48943
|
-
redactWildcardPath(obj, parts, censor,
|
|
49262
|
+
redactWildcardPath(obj, parts, censor, path24, remove);
|
|
48944
49263
|
} else {
|
|
48945
49264
|
if (remove) {
|
|
48946
49265
|
removeKey(obj, parts);
|
|
@@ -49025,8 +49344,8 @@ var require_redact = __commonJS({
|
|
|
49025
49344
|
}
|
|
49026
49345
|
} else {
|
|
49027
49346
|
if (afterWildcard.includes("*")) {
|
|
49028
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
49029
|
-
const fullPath = [...pathArray.slice(0, pathLength), ...
|
|
49347
|
+
const wrappedCensor = typeof censor === "function" ? (value, path24) => {
|
|
49348
|
+
const fullPath = [...pathArray.slice(0, pathLength), ...path24];
|
|
49030
49349
|
return censor(value, fullPath);
|
|
49031
49350
|
} : censor;
|
|
49032
49351
|
redactWildcardPath(current, afterWildcard, wrappedCensor, originalPath, remove);
|
|
@@ -49061,8 +49380,8 @@ var require_redact = __commonJS({
|
|
|
49061
49380
|
return null;
|
|
49062
49381
|
}
|
|
49063
49382
|
const pathStructure = /* @__PURE__ */ new Map();
|
|
49064
|
-
for (const
|
|
49065
|
-
const parts = parsePath(
|
|
49383
|
+
for (const path24 of pathsToClone) {
|
|
49384
|
+
const parts = parsePath(path24);
|
|
49066
49385
|
let current = pathStructure;
|
|
49067
49386
|
for (let i = 0; i < parts.length; i++) {
|
|
49068
49387
|
const part = parts[i];
|
|
@@ -49114,24 +49433,24 @@ var require_redact = __commonJS({
|
|
|
49114
49433
|
}
|
|
49115
49434
|
return cloneSelectively(obj, pathStructure);
|
|
49116
49435
|
}
|
|
49117
|
-
function validatePath(
|
|
49118
|
-
if (typeof
|
|
49436
|
+
function validatePath(path24) {
|
|
49437
|
+
if (typeof path24 !== "string") {
|
|
49119
49438
|
throw new Error("Paths must be (non-empty) strings");
|
|
49120
49439
|
}
|
|
49121
|
-
if (
|
|
49440
|
+
if (path24 === "") {
|
|
49122
49441
|
throw new Error("Invalid redaction path ()");
|
|
49123
49442
|
}
|
|
49124
|
-
if (
|
|
49125
|
-
throw new Error(`Invalid redaction path (${
|
|
49443
|
+
if (path24.includes("..")) {
|
|
49444
|
+
throw new Error(`Invalid redaction path (${path24})`);
|
|
49126
49445
|
}
|
|
49127
|
-
if (
|
|
49128
|
-
throw new Error(`Invalid redaction path (${
|
|
49446
|
+
if (path24.includes(",")) {
|
|
49447
|
+
throw new Error(`Invalid redaction path (${path24})`);
|
|
49129
49448
|
}
|
|
49130
49449
|
let bracketCount = 0;
|
|
49131
49450
|
let inQuotes = false;
|
|
49132
49451
|
let quoteChar = "";
|
|
49133
|
-
for (let i = 0; i <
|
|
49134
|
-
const char =
|
|
49452
|
+
for (let i = 0; i < path24.length; i++) {
|
|
49453
|
+
const char = path24[i];
|
|
49135
49454
|
if ((char === '"' || char === "'") && bracketCount > 0) {
|
|
49136
49455
|
if (!inQuotes) {
|
|
49137
49456
|
inQuotes = true;
|
|
@@ -49145,20 +49464,20 @@ var require_redact = __commonJS({
|
|
|
49145
49464
|
} else if (char === "]" && !inQuotes) {
|
|
49146
49465
|
bracketCount--;
|
|
49147
49466
|
if (bracketCount < 0) {
|
|
49148
|
-
throw new Error(`Invalid redaction path (${
|
|
49467
|
+
throw new Error(`Invalid redaction path (${path24})`);
|
|
49149
49468
|
}
|
|
49150
49469
|
}
|
|
49151
49470
|
}
|
|
49152
49471
|
if (bracketCount !== 0) {
|
|
49153
|
-
throw new Error(`Invalid redaction path (${
|
|
49472
|
+
throw new Error(`Invalid redaction path (${path24})`);
|
|
49154
49473
|
}
|
|
49155
49474
|
}
|
|
49156
49475
|
function validatePaths(paths) {
|
|
49157
49476
|
if (!Array.isArray(paths)) {
|
|
49158
49477
|
throw new TypeError("paths must be an array");
|
|
49159
49478
|
}
|
|
49160
|
-
for (const
|
|
49161
|
-
validatePath(
|
|
49479
|
+
for (const path24 of paths) {
|
|
49480
|
+
validatePath(path24);
|
|
49162
49481
|
}
|
|
49163
49482
|
}
|
|
49164
49483
|
function slowRedact(options = {}) {
|
|
@@ -49326,8 +49645,8 @@ var require_redaction = __commonJS({
|
|
|
49326
49645
|
if (shape[k] === null) {
|
|
49327
49646
|
o[k] = (value) => topCensor(value, [k]);
|
|
49328
49647
|
} else {
|
|
49329
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
49330
|
-
return censor(value, [k, ...
|
|
49648
|
+
const wrappedCensor = typeof censor === "function" ? (value, path24) => {
|
|
49649
|
+
return censor(value, [k, ...path24]);
|
|
49331
49650
|
} : censor;
|
|
49332
49651
|
o[k] = Redact({
|
|
49333
49652
|
paths: shape[k],
|
|
@@ -49511,7 +49830,7 @@ var require_atomic_sleep = __commonJS({
|
|
|
49511
49830
|
"node_modules/atomic-sleep/index.js"(exports, module) {
|
|
49512
49831
|
"use strict";
|
|
49513
49832
|
if (typeof SharedArrayBuffer !== "undefined" && typeof Atomics !== "undefined") {
|
|
49514
|
-
let
|
|
49833
|
+
let sleep4 = function(ms) {
|
|
49515
49834
|
const valid = ms > 0 && ms < Infinity;
|
|
49516
49835
|
if (valid === false) {
|
|
49517
49836
|
if (typeof ms !== "number" && typeof ms !== "bigint") {
|
|
@@ -49522,9 +49841,9 @@ var require_atomic_sleep = __commonJS({
|
|
|
49522
49841
|
Atomics.wait(nil, 0, 0, Number(ms));
|
|
49523
49842
|
};
|
|
49524
49843
|
const nil = new Int32Array(new SharedArrayBuffer(4));
|
|
49525
|
-
module.exports =
|
|
49844
|
+
module.exports = sleep4;
|
|
49526
49845
|
} else {
|
|
49527
|
-
let
|
|
49846
|
+
let sleep4 = function(ms) {
|
|
49528
49847
|
const valid = ms > 0 && ms < Infinity;
|
|
49529
49848
|
if (valid === false) {
|
|
49530
49849
|
if (typeof ms !== "number" && typeof ms !== "bigint") {
|
|
@@ -49536,7 +49855,7 @@ var require_atomic_sleep = __commonJS({
|
|
|
49536
49855
|
while (target > Date.now()) {
|
|
49537
49856
|
}
|
|
49538
49857
|
};
|
|
49539
|
-
module.exports =
|
|
49858
|
+
module.exports = sleep4;
|
|
49540
49859
|
}
|
|
49541
49860
|
}
|
|
49542
49861
|
});
|
|
@@ -49545,11 +49864,11 @@ var require_atomic_sleep = __commonJS({
|
|
|
49545
49864
|
var require_sonic_boom = __commonJS({
|
|
49546
49865
|
"node_modules/sonic-boom/index.js"(exports, module) {
|
|
49547
49866
|
"use strict";
|
|
49548
|
-
var
|
|
49867
|
+
var fs22 = __require("fs");
|
|
49549
49868
|
var EventEmitter = __require("events");
|
|
49550
49869
|
var inherits = __require("util").inherits;
|
|
49551
|
-
var
|
|
49552
|
-
var
|
|
49870
|
+
var path24 = __require("path");
|
|
49871
|
+
var sleep4 = require_atomic_sleep();
|
|
49553
49872
|
var assert2 = __require("assert");
|
|
49554
49873
|
var BUSY_WRITE_TIMEOUT = 100;
|
|
49555
49874
|
var kEmptyBuffer = Buffer.allocUnsafe(0);
|
|
@@ -49602,20 +49921,20 @@ var require_sonic_boom = __commonJS({
|
|
|
49602
49921
|
const mode = sonic.mode;
|
|
49603
49922
|
if (sonic.sync) {
|
|
49604
49923
|
try {
|
|
49605
|
-
if (sonic.mkdir)
|
|
49606
|
-
const fd =
|
|
49924
|
+
if (sonic.mkdir) fs22.mkdirSync(path24.dirname(file), { recursive: true });
|
|
49925
|
+
const fd = fs22.openSync(file, flags, mode);
|
|
49607
49926
|
fileOpened(null, fd);
|
|
49608
49927
|
} catch (err) {
|
|
49609
49928
|
fileOpened(err);
|
|
49610
49929
|
throw err;
|
|
49611
49930
|
}
|
|
49612
49931
|
} else if (sonic.mkdir) {
|
|
49613
|
-
|
|
49932
|
+
fs22.mkdir(path24.dirname(file), { recursive: true }, (err) => {
|
|
49614
49933
|
if (err) return fileOpened(err);
|
|
49615
|
-
|
|
49934
|
+
fs22.open(file, flags, mode, fileOpened);
|
|
49616
49935
|
});
|
|
49617
49936
|
} else {
|
|
49618
|
-
|
|
49937
|
+
fs22.open(file, flags, mode, fileOpened);
|
|
49619
49938
|
}
|
|
49620
49939
|
}
|
|
49621
49940
|
function SonicBoom(opts) {
|
|
@@ -49656,8 +49975,8 @@ var require_sonic_boom = __commonJS({
|
|
|
49656
49975
|
this.flush = flushBuffer;
|
|
49657
49976
|
this.flushSync = flushBufferSync;
|
|
49658
49977
|
this._actualWrite = actualWriteBuffer;
|
|
49659
|
-
fsWriteSync = () =>
|
|
49660
|
-
fsWrite = () =>
|
|
49978
|
+
fsWriteSync = () => fs22.writeSync(this.fd, this._writingBuf);
|
|
49979
|
+
fsWrite = () => fs22.write(this.fd, this._writingBuf, this.release);
|
|
49661
49980
|
} else if (contentMode === void 0 || contentMode === kContentModeUtf8) {
|
|
49662
49981
|
this._writingBuf = "";
|
|
49663
49982
|
this.write = write;
|
|
@@ -49666,15 +49985,15 @@ var require_sonic_boom = __commonJS({
|
|
|
49666
49985
|
this._actualWrite = actualWrite;
|
|
49667
49986
|
fsWriteSync = () => {
|
|
49668
49987
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
49669
|
-
return
|
|
49988
|
+
return fs22.writeSync(this.fd, this._writingBuf);
|
|
49670
49989
|
}
|
|
49671
|
-
return
|
|
49990
|
+
return fs22.writeSync(this.fd, this._writingBuf, "utf8");
|
|
49672
49991
|
};
|
|
49673
49992
|
fsWrite = () => {
|
|
49674
49993
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
49675
|
-
return
|
|
49994
|
+
return fs22.write(this.fd, this._writingBuf, this.release);
|
|
49676
49995
|
}
|
|
49677
|
-
return
|
|
49996
|
+
return fs22.write(this.fd, this._writingBuf, "utf8", this.release);
|
|
49678
49997
|
};
|
|
49679
49998
|
} else {
|
|
49680
49999
|
throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
|
|
@@ -49695,7 +50014,7 @@ var require_sonic_boom = __commonJS({
|
|
|
49695
50014
|
if ((err.code === "EAGAIN" || err.code === "EBUSY") && this.retryEAGAIN(err, this._writingBuf.length, this._len - this._writingBuf.length)) {
|
|
49696
50015
|
if (this.sync) {
|
|
49697
50016
|
try {
|
|
49698
|
-
|
|
50017
|
+
sleep4(BUSY_WRITE_TIMEOUT);
|
|
49699
50018
|
this.release(void 0, 0);
|
|
49700
50019
|
} catch (err2) {
|
|
49701
50020
|
this.release(err2);
|
|
@@ -49731,7 +50050,7 @@ var require_sonic_boom = __commonJS({
|
|
|
49731
50050
|
}
|
|
49732
50051
|
}
|
|
49733
50052
|
if (this._fsync) {
|
|
49734
|
-
|
|
50053
|
+
fs22.fsyncSync(this.fd);
|
|
49735
50054
|
}
|
|
49736
50055
|
const len = this._len;
|
|
49737
50056
|
if (this._reopening) {
|
|
@@ -49845,7 +50164,7 @@ var require_sonic_boom = __commonJS({
|
|
|
49845
50164
|
const onDrain = () => {
|
|
49846
50165
|
if (!this._fsync) {
|
|
49847
50166
|
try {
|
|
49848
|
-
|
|
50167
|
+
fs22.fsync(this.fd, (err) => {
|
|
49849
50168
|
this._flushPending = false;
|
|
49850
50169
|
cb(err);
|
|
49851
50170
|
});
|
|
@@ -49947,7 +50266,7 @@ var require_sonic_boom = __commonJS({
|
|
|
49947
50266
|
const fd = this.fd;
|
|
49948
50267
|
this.once("ready", () => {
|
|
49949
50268
|
if (fd !== this.fd) {
|
|
49950
|
-
|
|
50269
|
+
fs22.close(fd, (err) => {
|
|
49951
50270
|
if (err) {
|
|
49952
50271
|
return this.emit("error", err);
|
|
49953
50272
|
}
|
|
@@ -49996,7 +50315,7 @@ var require_sonic_boom = __commonJS({
|
|
|
49996
50315
|
buf = this._bufs[0];
|
|
49997
50316
|
}
|
|
49998
50317
|
try {
|
|
49999
|
-
const n = Buffer.isBuffer(buf) ?
|
|
50318
|
+
const n = Buffer.isBuffer(buf) ? fs22.writeSync(this.fd, buf) : fs22.writeSync(this.fd, buf, "utf8");
|
|
50000
50319
|
const releasedBufObj = releaseWritingBuf(buf, this._len, n);
|
|
50001
50320
|
buf = releasedBufObj.writingBuf;
|
|
50002
50321
|
this._len = releasedBufObj.len;
|
|
@@ -50008,11 +50327,11 @@ var require_sonic_boom = __commonJS({
|
|
|
50008
50327
|
if (shouldRetry && !this.retryEAGAIN(err, buf.length, this._len - buf.length)) {
|
|
50009
50328
|
throw err;
|
|
50010
50329
|
}
|
|
50011
|
-
|
|
50330
|
+
sleep4(BUSY_WRITE_TIMEOUT);
|
|
50012
50331
|
}
|
|
50013
50332
|
}
|
|
50014
50333
|
try {
|
|
50015
|
-
|
|
50334
|
+
fs22.fsyncSync(this.fd);
|
|
50016
50335
|
} catch {
|
|
50017
50336
|
}
|
|
50018
50337
|
}
|
|
@@ -50033,7 +50352,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50033
50352
|
buf = mergeBuf(this._bufs[0], this._lens[0]);
|
|
50034
50353
|
}
|
|
50035
50354
|
try {
|
|
50036
|
-
const n =
|
|
50355
|
+
const n = fs22.writeSync(this.fd, buf);
|
|
50037
50356
|
buf = buf.subarray(n);
|
|
50038
50357
|
this._len = Math.max(this._len - n, 0);
|
|
50039
50358
|
if (buf.length <= 0) {
|
|
@@ -50045,7 +50364,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50045
50364
|
if (shouldRetry && !this.retryEAGAIN(err, buf.length, this._len - buf.length)) {
|
|
50046
50365
|
throw err;
|
|
50047
50366
|
}
|
|
50048
|
-
|
|
50367
|
+
sleep4(BUSY_WRITE_TIMEOUT);
|
|
50049
50368
|
}
|
|
50050
50369
|
}
|
|
50051
50370
|
}
|
|
@@ -50061,13 +50380,13 @@ var require_sonic_boom = __commonJS({
|
|
|
50061
50380
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : this._bufs.shift() || "";
|
|
50062
50381
|
if (this.sync) {
|
|
50063
50382
|
try {
|
|
50064
|
-
const written = Buffer.isBuffer(this._writingBuf) ?
|
|
50383
|
+
const written = Buffer.isBuffer(this._writingBuf) ? fs22.writeSync(this.fd, this._writingBuf) : fs22.writeSync(this.fd, this._writingBuf, "utf8");
|
|
50065
50384
|
release(null, written);
|
|
50066
50385
|
} catch (err) {
|
|
50067
50386
|
release(err);
|
|
50068
50387
|
}
|
|
50069
50388
|
} else {
|
|
50070
|
-
|
|
50389
|
+
fs22.write(this.fd, this._writingBuf, release);
|
|
50071
50390
|
}
|
|
50072
50391
|
}
|
|
50073
50392
|
function actualWriteBuffer() {
|
|
@@ -50076,7 +50395,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50076
50395
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
|
|
50077
50396
|
if (this.sync) {
|
|
50078
50397
|
try {
|
|
50079
|
-
const written =
|
|
50398
|
+
const written = fs22.writeSync(this.fd, this._writingBuf);
|
|
50080
50399
|
release(null, written);
|
|
50081
50400
|
} catch (err) {
|
|
50082
50401
|
release(err);
|
|
@@ -50085,7 +50404,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50085
50404
|
if (kCopyBuffer) {
|
|
50086
50405
|
this._writingBuf = Buffer.from(this._writingBuf);
|
|
50087
50406
|
}
|
|
50088
|
-
|
|
50407
|
+
fs22.write(this.fd, this._writingBuf, release);
|
|
50089
50408
|
}
|
|
50090
50409
|
}
|
|
50091
50410
|
function actualClose(sonic) {
|
|
@@ -50101,12 +50420,12 @@ var require_sonic_boom = __commonJS({
|
|
|
50101
50420
|
sonic._lens = [];
|
|
50102
50421
|
assert2(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
|
|
50103
50422
|
try {
|
|
50104
|
-
|
|
50423
|
+
fs22.fsync(sonic.fd, closeWrapped);
|
|
50105
50424
|
} catch {
|
|
50106
50425
|
}
|
|
50107
50426
|
function closeWrapped() {
|
|
50108
50427
|
if (sonic.fd !== 1 && sonic.fd !== 2) {
|
|
50109
|
-
|
|
50428
|
+
fs22.close(sonic.fd, done);
|
|
50110
50429
|
} else {
|
|
50111
50430
|
done();
|
|
50112
50431
|
}
|
|
@@ -50880,7 +51199,7 @@ var require_transport = __commonJS({
|
|
|
50880
51199
|
var getCallers = require_caller();
|
|
50881
51200
|
var { join: join2, isAbsolute, sep } = __require("node:path");
|
|
50882
51201
|
var { fileURLToPath } = __require("node:url");
|
|
50883
|
-
var
|
|
51202
|
+
var sleep4 = require_atomic_sleep();
|
|
50884
51203
|
var onExit = require_on_exit_leak_free();
|
|
50885
51204
|
var ThreadStream = require_thread_stream();
|
|
50886
51205
|
function setupOnExit(stream) {
|
|
@@ -50942,15 +51261,15 @@ var require_transport = __commonJS({
|
|
|
50942
51261
|
if (!unquoted) {
|
|
50943
51262
|
return false;
|
|
50944
51263
|
}
|
|
50945
|
-
let
|
|
50946
|
-
if (
|
|
51264
|
+
let path24 = unquoted;
|
|
51265
|
+
if (path24.startsWith("file://")) {
|
|
50947
51266
|
try {
|
|
50948
|
-
|
|
51267
|
+
path24 = fileURLToPath(path24);
|
|
50949
51268
|
} catch {
|
|
50950
51269
|
return false;
|
|
50951
51270
|
}
|
|
50952
51271
|
}
|
|
50953
|
-
return isAbsolute(
|
|
51272
|
+
return isAbsolute(path24) && !existsSync(path24);
|
|
50954
51273
|
}
|
|
50955
51274
|
function stripQuotes(value) {
|
|
50956
51275
|
const first = value[0];
|
|
@@ -51003,7 +51322,7 @@ var require_transport = __commonJS({
|
|
|
51003
51322
|
return;
|
|
51004
51323
|
}
|
|
51005
51324
|
stream.flushSync();
|
|
51006
|
-
|
|
51325
|
+
sleep4(100);
|
|
51007
51326
|
stream.end();
|
|
51008
51327
|
}
|
|
51009
51328
|
return stream;
|
|
@@ -52644,7 +52963,7 @@ var require_multistream = __commonJS({
|
|
|
52644
52963
|
var require_pino = __commonJS({
|
|
52645
52964
|
"node_modules/pino/pino.js"(exports, module) {
|
|
52646
52965
|
"use strict";
|
|
52647
|
-
var
|
|
52966
|
+
var os17 = __require("node:os");
|
|
52648
52967
|
var stdSerializers = require_pino_std_serializers();
|
|
52649
52968
|
var caller = require_caller();
|
|
52650
52969
|
var redaction = require_redaction();
|
|
@@ -52691,7 +53010,7 @@ var require_pino = __commonJS({
|
|
|
52691
53010
|
} = symbols;
|
|
52692
53011
|
var { epochTime, nullTime } = time3;
|
|
52693
53012
|
var { pid } = process;
|
|
52694
|
-
var hostname2 =
|
|
53013
|
+
var hostname2 = os17.hostname();
|
|
52695
53014
|
var defaultErrorSerializer = stdSerializers.err;
|
|
52696
53015
|
var defaultOptions2 = {
|
|
52697
53016
|
level: "info",
|
|
@@ -85017,15 +85336,15 @@ var require_tools2 = __commonJS({
|
|
|
85017
85336
|
* @param {String} path - Mailbox path to encode
|
|
85018
85337
|
* @returns {String} Encoded mailbox path
|
|
85019
85338
|
*/
|
|
85020
|
-
encodePath(connection,
|
|
85021
|
-
|
|
85022
|
-
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(
|
|
85339
|
+
encodePath(connection, path24) {
|
|
85340
|
+
path24 = (path24 || "").toString();
|
|
85341
|
+
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(path24)) {
|
|
85023
85342
|
try {
|
|
85024
|
-
|
|
85343
|
+
path24 = iconv.encode(path24, "utf-7-imap").toString();
|
|
85025
85344
|
} catch {
|
|
85026
85345
|
}
|
|
85027
85346
|
}
|
|
85028
|
-
return
|
|
85347
|
+
return path24;
|
|
85029
85348
|
},
|
|
85030
85349
|
/**
|
|
85031
85350
|
* Decodes a mailbox path from modified UTF-7 if the server does not support UTF8=ACCEPT.
|
|
@@ -85034,15 +85353,15 @@ var require_tools2 = __commonJS({
|
|
|
85034
85353
|
* @param {String} path - Mailbox path to decode
|
|
85035
85354
|
* @returns {String} Decoded mailbox path
|
|
85036
85355
|
*/
|
|
85037
|
-
decodePath(connection,
|
|
85038
|
-
|
|
85039
|
-
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(
|
|
85356
|
+
decodePath(connection, path24) {
|
|
85357
|
+
path24 = (path24 || "").toString();
|
|
85358
|
+
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(path24)) {
|
|
85040
85359
|
try {
|
|
85041
|
-
|
|
85360
|
+
path24 = iconv.decode(Buffer.from(path24), "utf-7-imap").toString();
|
|
85042
85361
|
} catch {
|
|
85043
85362
|
}
|
|
85044
85363
|
}
|
|
85045
|
-
return
|
|
85364
|
+
return path24;
|
|
85046
85365
|
},
|
|
85047
85366
|
/**
|
|
85048
85367
|
* Normalizes a mailbox path by joining array segments with the namespace delimiter,
|
|
@@ -85053,17 +85372,17 @@ var require_tools2 = __commonJS({
|
|
|
85053
85372
|
* @param {Boolean} [skipNamespace] - If true, skips prepending the namespace prefix
|
|
85054
85373
|
* @returns {String} Normalized mailbox path
|
|
85055
85374
|
*/
|
|
85056
|
-
normalizePath(connection,
|
|
85057
|
-
if (Array.isArray(
|
|
85058
|
-
|
|
85375
|
+
normalizePath(connection, path24, skipNamespace) {
|
|
85376
|
+
if (Array.isArray(path24)) {
|
|
85377
|
+
path24 = path24.join(connection.namespace && connection.namespace.delimiter || "");
|
|
85059
85378
|
}
|
|
85060
|
-
if (
|
|
85379
|
+
if (path24.toUpperCase() === "INBOX") {
|
|
85061
85380
|
return "INBOX";
|
|
85062
85381
|
}
|
|
85063
|
-
if (!skipNamespace && connection.namespace && connection.namespace.prefix && !
|
|
85064
|
-
|
|
85382
|
+
if (!skipNamespace && connection.namespace && connection.namespace.prefix && !path24.startsWith(connection.namespace.prefix)) {
|
|
85383
|
+
path24 = connection.namespace.prefix + path24;
|
|
85065
85384
|
}
|
|
85066
|
-
return
|
|
85385
|
+
return path24;
|
|
85067
85386
|
},
|
|
85068
85387
|
/**
|
|
85069
85388
|
* Compares two mailbox paths for equality after normalization.
|
|
@@ -85394,14 +85713,14 @@ var require_tools2 = __commonJS({
|
|
|
85394
85713
|
}
|
|
85395
85714
|
}
|
|
85396
85715
|
if (map.emailId || map.uid) {
|
|
85397
|
-
let
|
|
85398
|
-
if (/[\u0080-\uffff]/.test(
|
|
85716
|
+
let path24 = mailbox.path;
|
|
85717
|
+
if (/[\u0080-\uffff]/.test(path24)) {
|
|
85399
85718
|
try {
|
|
85400
|
-
|
|
85719
|
+
path24 = iconv.encode(path24, "utf-7-imap").toString();
|
|
85401
85720
|
} catch {
|
|
85402
85721
|
}
|
|
85403
85722
|
}
|
|
85404
|
-
map.id = map.emailId || createHash2("md5").update([
|
|
85723
|
+
map.id = map.emailId || createHash2("md5").update([path24, mailbox.uidValidity?.toString() || "", map.uid.toString()].join(":")).digest("hex");
|
|
85405
85724
|
}
|
|
85406
85725
|
if (map.flags) {
|
|
85407
85726
|
let flagColor = tools.getFlagColor(map.flags);
|
|
@@ -85576,16 +85895,16 @@ var require_tools2 = __commonJS({
|
|
|
85576
85895
|
* @returns {Object} Parsed body structure tree with part numbers, types, parameters, and child nodes
|
|
85577
85896
|
*/
|
|
85578
85897
|
parseBodystructure(entry) {
|
|
85579
|
-
let walk = (node,
|
|
85580
|
-
|
|
85898
|
+
let walk = (node, path24) => {
|
|
85899
|
+
path24 = path24 || [];
|
|
85581
85900
|
let curNode = {}, i = 0, part = 0;
|
|
85582
|
-
if (
|
|
85583
|
-
curNode.part =
|
|
85901
|
+
if (path24.length) {
|
|
85902
|
+
curNode.part = path24.join(".");
|
|
85584
85903
|
}
|
|
85585
85904
|
if (Array.isArray(node[0])) {
|
|
85586
85905
|
curNode.childNodes = [];
|
|
85587
85906
|
while (Array.isArray(node[i])) {
|
|
85588
|
-
curNode.childNodes.push(walk(node[i],
|
|
85907
|
+
curNode.childNodes.push(walk(node[i], path24.concat(++part)));
|
|
85589
85908
|
i++;
|
|
85590
85909
|
}
|
|
85591
85910
|
curNode.type = "multipart/" + ((node[i++] || {}).value || "").toString().toLowerCase();
|
|
@@ -85628,7 +85947,7 @@ var require_tools2 = __commonJS({
|
|
|
85628
85947
|
// the encapsulated message shares the part number with its wrapper.
|
|
85629
85948
|
// Distinction is via suffixes: path.MIME = wrapper headers,
|
|
85630
85949
|
// path.HEADER = encapsulated message headers.
|
|
85631
|
-
walk(node[i],
|
|
85950
|
+
walk(node[i], path24)
|
|
85632
85951
|
];
|
|
85633
85952
|
}
|
|
85634
85953
|
i++;
|
|
@@ -87590,14 +87909,14 @@ var require_select = __commonJS({
|
|
|
87590
87909
|
// update into a silent no-op for the rest of the session.
|
|
87591
87910
|
permanentflags: { key: "permanentFlags", parse: (value) => Array.isArray(value) && new Set(value) }
|
|
87592
87911
|
});
|
|
87593
|
-
module.exports = async (connection,
|
|
87912
|
+
module.exports = async (connection, path24, options) => {
|
|
87594
87913
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
87595
87914
|
return;
|
|
87596
87915
|
}
|
|
87597
87916
|
options = options || {};
|
|
87598
|
-
|
|
87599
|
-
if (!connection.folders.has(
|
|
87600
|
-
let folders = await connection.run("LIST", "",
|
|
87917
|
+
path24 = normalizePath(connection, path24);
|
|
87918
|
+
if (!connection.folders.has(path24)) {
|
|
87919
|
+
let folders = await connection.run("LIST", "", path24);
|
|
87601
87920
|
if (!folders) {
|
|
87602
87921
|
throw new Error("Failed to fetch folders");
|
|
87603
87922
|
}
|
|
@@ -87605,10 +87924,10 @@ var require_select = __commonJS({
|
|
|
87605
87924
|
connection.folders.set(folder.path, folder);
|
|
87606
87925
|
});
|
|
87607
87926
|
}
|
|
87608
|
-
let folderListData = connection.folders.has(
|
|
87927
|
+
let folderListData = connection.folders.has(path24) ? connection.folders.get(path24) : false;
|
|
87609
87928
|
let response;
|
|
87610
87929
|
try {
|
|
87611
|
-
let map = { path:
|
|
87930
|
+
let map = { path: path24 };
|
|
87612
87931
|
if (folderListData) {
|
|
87613
87932
|
["delimiter", "specialUse", "subscribed", "listed"].forEach((key) => {
|
|
87614
87933
|
if (folderListData[key]) {
|
|
@@ -87627,7 +87946,7 @@ var require_select = __commonJS({
|
|
|
87627
87946
|
]);
|
|
87628
87947
|
map.qresync = true;
|
|
87629
87948
|
}
|
|
87630
|
-
let encodedPath = encodePath(connection,
|
|
87949
|
+
let encodedPath = encodePath(connection, path24);
|
|
87631
87950
|
let selectCommand = {
|
|
87632
87951
|
command: !options.readOnly ? "SELECT" : "EXAMINE",
|
|
87633
87952
|
/* c8 ignore next */
|
|
@@ -87687,12 +88006,12 @@ var require_select = __commonJS({
|
|
|
87687
88006
|
// since the client's last known state. Only received when QRESYNC was requested.
|
|
87688
88007
|
// A dummy mailbox object is passed because the mailbox isn't officially open yet.
|
|
87689
88008
|
VANISHED: async (untagged) => {
|
|
87690
|
-
await connection.untaggedVanished(untagged, { path:
|
|
88009
|
+
await connection.untaggedVanished(untagged, { path: path24, uidNext: false, uidValidity: false });
|
|
87691
88010
|
},
|
|
87692
88011
|
// Untagged FETCH during SELECT/EXAMINE: only occurs with QRESYNC, delivering
|
|
87693
88012
|
// updated flags for messages that changed since the client's last modseq.
|
|
87694
88013
|
FETCH: async (untagged) => {
|
|
87695
|
-
await connection.untaggedFetch(untagged, { path:
|
|
88014
|
+
await connection.untaggedFetch(untagged, { path: path24, uidNext: false, uidValidity: false });
|
|
87696
88015
|
}
|
|
87697
88016
|
}
|
|
87698
88017
|
});
|
|
@@ -87706,13 +88025,13 @@ var require_select = __commonJS({
|
|
|
87706
88025
|
}
|
|
87707
88026
|
let currentMailbox = connection.mailbox;
|
|
87708
88027
|
connection.mailbox = false;
|
|
87709
|
-
if (currentMailbox && currentMailbox.path !==
|
|
88028
|
+
if (currentMailbox && currentMailbox.path !== path24) {
|
|
87710
88029
|
connection.emit("mailboxClose", currentMailbox);
|
|
87711
88030
|
}
|
|
87712
88031
|
connection.mailbox = map;
|
|
87713
88032
|
connection.currentSelectCommand = selectCommand;
|
|
87714
88033
|
connection.state = connection.states.SELECTED;
|
|
87715
|
-
if (!currentMailbox || currentMailbox.path !==
|
|
88034
|
+
if (!currentMailbox || currentMailbox.path !== path24) {
|
|
87716
88035
|
connection.emit("mailboxOpen", connection.mailbox);
|
|
87717
88036
|
}
|
|
87718
88037
|
response.next();
|
|
@@ -87927,17 +88246,17 @@ var require_create = __commonJS({
|
|
|
87927
88246
|
"node_modules/imapflow/lib/commands/create.js"(exports, module) {
|
|
87928
88247
|
"use strict";
|
|
87929
88248
|
var { encodePath, normalizePath, getStatusCode, enhanceCommandError } = require_tools2();
|
|
87930
|
-
module.exports = async (connection,
|
|
88249
|
+
module.exports = async (connection, path24) => {
|
|
87931
88250
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
87932
88251
|
return;
|
|
87933
88252
|
}
|
|
87934
|
-
|
|
88253
|
+
path24 = normalizePath(connection, path24);
|
|
87935
88254
|
let response;
|
|
87936
88255
|
try {
|
|
87937
88256
|
let map = {
|
|
87938
|
-
path:
|
|
88257
|
+
path: path24
|
|
87939
88258
|
};
|
|
87940
|
-
response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection,
|
|
88259
|
+
response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection, path24) }]);
|
|
87941
88260
|
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
88261
|
if (section) {
|
|
87943
88262
|
let key;
|
|
@@ -87963,13 +88282,13 @@ var require_create = __commonJS({
|
|
|
87963
88282
|
}
|
|
87964
88283
|
map.created = true;
|
|
87965
88284
|
response.next();
|
|
87966
|
-
await connection.run("SUBSCRIBE",
|
|
88285
|
+
await connection.run("SUBSCRIBE", path24);
|
|
87967
88286
|
return map;
|
|
87968
88287
|
} catch (err) {
|
|
87969
88288
|
let errorCode = getStatusCode(err.response);
|
|
87970
88289
|
if (errorCode === "ALREADYEXISTS") {
|
|
87971
88290
|
return {
|
|
87972
|
-
path:
|
|
88291
|
+
path: path24,
|
|
87973
88292
|
created: false
|
|
87974
88293
|
};
|
|
87975
88294
|
}
|
|
@@ -87986,20 +88305,20 @@ var require_delete = __commonJS({
|
|
|
87986
88305
|
"node_modules/imapflow/lib/commands/delete.js"(exports, module) {
|
|
87987
88306
|
"use strict";
|
|
87988
88307
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
87989
|
-
module.exports = async (connection,
|
|
88308
|
+
module.exports = async (connection, path24) => {
|
|
87990
88309
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
87991
88310
|
return;
|
|
87992
88311
|
}
|
|
87993
|
-
|
|
87994
|
-
if (connection.state === connection.states.SELECTED && connection.mailbox.path ===
|
|
88312
|
+
path24 = normalizePath(connection, path24);
|
|
88313
|
+
if (connection.state === connection.states.SELECTED && connection.mailbox.path === path24) {
|
|
87995
88314
|
await connection.run("CLOSE");
|
|
87996
88315
|
}
|
|
87997
88316
|
let response;
|
|
87998
88317
|
try {
|
|
87999
88318
|
let map = {
|
|
88000
|
-
path:
|
|
88319
|
+
path: path24
|
|
88001
88320
|
};
|
|
88002
|
-
response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection,
|
|
88321
|
+
response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection, path24) }]);
|
|
88003
88322
|
response.next();
|
|
88004
88323
|
return map;
|
|
88005
88324
|
} catch (err) {
|
|
@@ -88016,23 +88335,23 @@ var require_rename = __commonJS({
|
|
|
88016
88335
|
"node_modules/imapflow/lib/commands/rename.js"(exports, module) {
|
|
88017
88336
|
"use strict";
|
|
88018
88337
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88019
|
-
module.exports = async (connection,
|
|
88338
|
+
module.exports = async (connection, path24, newPath) => {
|
|
88020
88339
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88021
88340
|
return;
|
|
88022
88341
|
}
|
|
88023
|
-
|
|
88342
|
+
path24 = normalizePath(connection, path24);
|
|
88024
88343
|
newPath = normalizePath(connection, newPath);
|
|
88025
|
-
if (connection.state === connection.states.SELECTED && connection.mailbox.path ===
|
|
88344
|
+
if (connection.state === connection.states.SELECTED && connection.mailbox.path === path24) {
|
|
88026
88345
|
await connection.run("CLOSE");
|
|
88027
88346
|
}
|
|
88028
88347
|
let response;
|
|
88029
88348
|
try {
|
|
88030
88349
|
let map = {
|
|
88031
|
-
path:
|
|
88350
|
+
path: path24,
|
|
88032
88351
|
newPath
|
|
88033
88352
|
};
|
|
88034
88353
|
response = await connection.exec("RENAME", [
|
|
88035
|
-
{ type: "ATOM", value: encodePath(connection,
|
|
88354
|
+
{ type: "ATOM", value: encodePath(connection, path24) },
|
|
88036
88355
|
{ type: "ATOM", value: encodePath(connection, newPath) }
|
|
88037
88356
|
]);
|
|
88038
88357
|
response.next();
|
|
@@ -88079,14 +88398,14 @@ var require_subscribe = __commonJS({
|
|
|
88079
88398
|
"node_modules/imapflow/lib/commands/subscribe.js"(exports, module) {
|
|
88080
88399
|
"use strict";
|
|
88081
88400
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88082
|
-
module.exports = async (connection,
|
|
88401
|
+
module.exports = async (connection, path24) => {
|
|
88083
88402
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88084
88403
|
return;
|
|
88085
88404
|
}
|
|
88086
|
-
|
|
88405
|
+
path24 = normalizePath(connection, path24);
|
|
88087
88406
|
let response;
|
|
88088
88407
|
try {
|
|
88089
|
-
response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection,
|
|
88408
|
+
response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path24) }]);
|
|
88090
88409
|
response.next();
|
|
88091
88410
|
return true;
|
|
88092
88411
|
} catch (err) {
|
|
@@ -88103,14 +88422,14 @@ var require_unsubscribe = __commonJS({
|
|
|
88103
88422
|
"node_modules/imapflow/lib/commands/unsubscribe.js"(exports, module) {
|
|
88104
88423
|
"use strict";
|
|
88105
88424
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88106
|
-
module.exports = async (connection,
|
|
88425
|
+
module.exports = async (connection, path24) => {
|
|
88107
88426
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88108
88427
|
return;
|
|
88109
88428
|
}
|
|
88110
|
-
|
|
88429
|
+
path24 = normalizePath(connection, path24);
|
|
88111
88430
|
let response;
|
|
88112
88431
|
try {
|
|
88113
|
-
response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection,
|
|
88432
|
+
response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path24) }]);
|
|
88114
88433
|
response.next();
|
|
88115
88434
|
return true;
|
|
88116
88435
|
} catch (err) {
|
|
@@ -88916,11 +89235,11 @@ var require_status = __commonJS({
|
|
|
88916
89235
|
var { encodePath, normalizePath, buildStatusQueryAttributes, isRev2Active } = require_tools2();
|
|
88917
89236
|
var { parseStatusList } = require_status_fields();
|
|
88918
89237
|
var MAILBOX_UPDATERS = {
|
|
88919
|
-
messages: (value, connection,
|
|
89238
|
+
messages: (value, connection, path24) => {
|
|
88920
89239
|
let prevCount = connection.mailbox.exists;
|
|
88921
89240
|
if (prevCount !== value) {
|
|
88922
89241
|
connection.mailbox.exists = value;
|
|
88923
|
-
connection.emit("exists", { path:
|
|
89242
|
+
connection.emit("exists", { path: path24, count: value, prevCount });
|
|
88924
89243
|
}
|
|
88925
89244
|
},
|
|
88926
89245
|
uidNext: (value, connection) => {
|
|
@@ -88930,28 +89249,28 @@ var require_status = __commonJS({
|
|
|
88930
89249
|
connection.mailbox.highestModseq = value;
|
|
88931
89250
|
}
|
|
88932
89251
|
};
|
|
88933
|
-
module.exports = async (connection,
|
|
88934
|
-
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !
|
|
89252
|
+
module.exports = async (connection, path24, query) => {
|
|
89253
|
+
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path24) {
|
|
88935
89254
|
return false;
|
|
88936
89255
|
}
|
|
88937
|
-
|
|
88938
|
-
let encodedPath = encodePath(connection,
|
|
89256
|
+
path24 = normalizePath(connection, path24);
|
|
89257
|
+
let encodedPath = encodePath(connection, path24);
|
|
88939
89258
|
let attributes = [{ type: encodedPath.indexOf("&") >= 0 ? "STRING" : "ATOM", value: encodedPath }];
|
|
88940
89259
|
let queryAttributes = buildStatusQueryAttributes(connection, query);
|
|
88941
89260
|
let syntheticRecent = query && query.recent && isRev2Active(connection);
|
|
88942
89261
|
if (!queryAttributes.length) {
|
|
88943
|
-
return syntheticRecent ? { path:
|
|
89262
|
+
return syntheticRecent ? { path: path24, recent: 0 } : false;
|
|
88944
89263
|
}
|
|
88945
89264
|
attributes.push(queryAttributes);
|
|
88946
89265
|
let response;
|
|
88947
89266
|
try {
|
|
88948
|
-
let map = { path:
|
|
89267
|
+
let map = { path: path24 };
|
|
88949
89268
|
response = await connection.exec("STATUS", attributes, {
|
|
88950
89269
|
untagged: {
|
|
88951
89270
|
// STATUS response: * STATUS <mailbox> (<key> <value> <key> <value> ...)
|
|
88952
89271
|
// Parsed as alternating key-value pairs (i % 2 pattern).
|
|
88953
89272
|
STATUS: async (untagged) => {
|
|
88954
|
-
let updateCurrent = connection.state === connection.states.SELECTED &&
|
|
89273
|
+
let updateCurrent = connection.state === connection.states.SELECTED && path24 === connection.mailbox.path;
|
|
88955
89274
|
let list = untagged.attributes && Array.isArray(untagged.attributes[1]) ? untagged.attributes[1] : false;
|
|
88956
89275
|
if (!list) {
|
|
88957
89276
|
return;
|
|
@@ -88959,7 +89278,7 @@ var require_status = __commonJS({
|
|
|
88959
89278
|
parseStatusList(list, (key, value) => {
|
|
88960
89279
|
map[key] = value;
|
|
88961
89280
|
if (updateCurrent && MAILBOX_UPDATERS[key]) {
|
|
88962
|
-
MAILBOX_UPDATERS[key](value, connection,
|
|
89281
|
+
MAILBOX_UPDATERS[key](value, connection, path24);
|
|
88963
89282
|
}
|
|
88964
89283
|
});
|
|
88965
89284
|
}
|
|
@@ -88972,9 +89291,9 @@ var require_status = __commonJS({
|
|
|
88972
89291
|
return map;
|
|
88973
89292
|
} catch (err) {
|
|
88974
89293
|
if (err.responseStatus === "NO") {
|
|
88975
|
-
let folders = await connection.run("LIST", "",
|
|
89294
|
+
let folders = await connection.run("LIST", "", path24, { listOnly: true });
|
|
88976
89295
|
if (folders && !folders.length) {
|
|
88977
|
-
let error2 = new Error(`Mailbox doesn't exist: ${
|
|
89296
|
+
let error2 = new Error(`Mailbox doesn't exist: ${path24}`);
|
|
88978
89297
|
error2.code = "NotFound";
|
|
88979
89298
|
error2.response = err;
|
|
88980
89299
|
throw error2;
|
|
@@ -89121,15 +89440,15 @@ var require_quota = __commonJS({
|
|
|
89121
89440
|
"node_modules/imapflow/lib/commands/quota.js"(exports, module) {
|
|
89122
89441
|
"use strict";
|
|
89123
89442
|
var { encodePath, normalizePath, enhanceCommandError, parseUintValue, isUnsafeKey } = require_tools2();
|
|
89124
|
-
module.exports = async (connection,
|
|
89125
|
-
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !
|
|
89443
|
+
module.exports = async (connection, path24) => {
|
|
89444
|
+
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path24) {
|
|
89126
89445
|
return;
|
|
89127
89446
|
}
|
|
89128
89447
|
if (!connection.capabilities.has("QUOTA")) {
|
|
89129
89448
|
return false;
|
|
89130
89449
|
}
|
|
89131
|
-
|
|
89132
|
-
let map = { path:
|
|
89450
|
+
path24 = normalizePath(connection, path24);
|
|
89451
|
+
let map = { path: path24 };
|
|
89133
89452
|
let processQuotaResponse = (untagged) => {
|
|
89134
89453
|
let attributes = untagged.attributes && untagged.attributes[1];
|
|
89135
89454
|
if (!attributes || !attributes.length) {
|
|
@@ -89169,7 +89488,7 @@ var require_quota = __commonJS({
|
|
|
89169
89488
|
let quotaFound = false;
|
|
89170
89489
|
let response;
|
|
89171
89490
|
try {
|
|
89172
|
-
response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection,
|
|
89491
|
+
response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection, path24) }], {
|
|
89173
89492
|
untagged: {
|
|
89174
89493
|
// QUOTAROOT response tells us which quota root applies to this mailbox.
|
|
89175
89494
|
// A mailbox may have zero or one quota root.
|
|
@@ -89312,15 +89631,15 @@ var require_idle = __commonJS({
|
|
|
89312
89631
|
}
|
|
89313
89632
|
}
|
|
89314
89633
|
async function pollOnce2(connection, session) {
|
|
89315
|
-
let
|
|
89634
|
+
let path24 = connection.mailbox && connection.mailbox.path;
|
|
89316
89635
|
switch (connection.missingIdleCommand) {
|
|
89317
89636
|
case "SELECT":
|
|
89318
89637
|
connection.log.debug({ src: "c", msg: `Running SELECT to detect changes in folder`, cid: connection.id });
|
|
89319
|
-
await connection.runInternal("SELECT",
|
|
89638
|
+
await connection.runInternal("SELECT", path24, { readOnly: session.selectCommand.command === "EXAMINE" });
|
|
89320
89639
|
break;
|
|
89321
89640
|
case "STATUS": {
|
|
89322
89641
|
connection.log.debug({ src: "c", msg: `Running STATUS to detect changes in folder`, cid: connection.id });
|
|
89323
|
-
let status = await connection.runInternal("STATUS",
|
|
89642
|
+
let status = await connection.runInternal("STATUS", path24, {
|
|
89324
89643
|
messages: true,
|
|
89325
89644
|
uidNext: true,
|
|
89326
89645
|
uidValidity: true,
|
|
@@ -89613,7 +89932,7 @@ var require_imap_flow = __commonJS({
|
|
|
89613
89932
|
"use strict";
|
|
89614
89933
|
var tls = __require("tls");
|
|
89615
89934
|
var net = __require("net");
|
|
89616
|
-
var
|
|
89935
|
+
var crypto12 = __require("crypto");
|
|
89617
89936
|
var { EventEmitter } = __require("events");
|
|
89618
89937
|
var logger2 = require_logger();
|
|
89619
89938
|
var libmime = require_libmime();
|
|
@@ -89920,7 +90239,7 @@ var require_imap_flow = __commonJS({
|
|
|
89920
90239
|
this.emit("error", err);
|
|
89921
90240
|
}
|
|
89922
90241
|
getRandomId() {
|
|
89923
|
-
let rid = BigInt("0x" +
|
|
90242
|
+
let rid = BigInt("0x" + crypto12.randomBytes(13).toString("hex")).toString(36);
|
|
89924
90243
|
if (rid.length < 20) {
|
|
89925
90244
|
rid = "0".repeat(20 - rid.length) + rid;
|
|
89926
90245
|
}
|
|
@@ -91007,12 +91326,12 @@ var require_imap_flow = __commonJS({
|
|
|
91007
91326
|
this.emit("flags", updateEvent);
|
|
91008
91327
|
}
|
|
91009
91328
|
}
|
|
91010
|
-
async ensureSelectedMailbox(
|
|
91011
|
-
if (!
|
|
91329
|
+
async ensureSelectedMailbox(path24) {
|
|
91330
|
+
if (!path24) {
|
|
91012
91331
|
return false;
|
|
91013
91332
|
}
|
|
91014
|
-
if (!this.mailbox || !comparePaths(this, this.mailbox.path,
|
|
91015
|
-
return await this.mailboxOpen(
|
|
91333
|
+
if (!this.mailbox || !comparePaths(this, this.mailbox.path, path24)) {
|
|
91334
|
+
return await this.mailboxOpen(path24);
|
|
91016
91335
|
}
|
|
91017
91336
|
return true;
|
|
91018
91337
|
}
|
|
@@ -91427,9 +91746,9 @@ var require_imap_flow = __commonJS({
|
|
|
91427
91746
|
* let quota = await client.getQuota();
|
|
91428
91747
|
* console.log(quota.storage.used, quota.storage.limit)
|
|
91429
91748
|
*/
|
|
91430
|
-
async getQuota(
|
|
91431
|
-
|
|
91432
|
-
return await this.run("QUOTA",
|
|
91749
|
+
async getQuota(path24) {
|
|
91750
|
+
path24 = path24 || "INBOX";
|
|
91751
|
+
return await this.run("QUOTA", path24);
|
|
91433
91752
|
}
|
|
91434
91753
|
/**
|
|
91435
91754
|
* @typedef {Object} ListResponse
|
|
@@ -91539,8 +91858,8 @@ var require_imap_flow = __commonJS({
|
|
|
91539
91858
|
* console.log(info.path);
|
|
91540
91859
|
* // "INBOX.parent.child" // assumes "INBOX." as namespace prefix and "." as delimiter
|
|
91541
91860
|
*/
|
|
91542
|
-
async mailboxCreate(
|
|
91543
|
-
return await this.run("CREATE",
|
|
91861
|
+
async mailboxCreate(path24) {
|
|
91862
|
+
return await this.run("CREATE", path24);
|
|
91544
91863
|
}
|
|
91545
91864
|
/**
|
|
91546
91865
|
* @typedef {Object} MailboxRenameResponse
|
|
@@ -91561,8 +91880,8 @@ var require_imap_flow = __commonJS({
|
|
|
91561
91880
|
* console.log(info.newPath);
|
|
91562
91881
|
* // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
|
|
91563
91882
|
*/
|
|
91564
|
-
async mailboxRename(
|
|
91565
|
-
return await this.run("RENAME",
|
|
91883
|
+
async mailboxRename(path24, newPath) {
|
|
91884
|
+
return await this.run("RENAME", path24, newPath);
|
|
91566
91885
|
}
|
|
91567
91886
|
/**
|
|
91568
91887
|
* @typedef {Object} MailboxDeleteResponse
|
|
@@ -91581,8 +91900,8 @@ var require_imap_flow = __commonJS({
|
|
|
91581
91900
|
* console.log(info.path);
|
|
91582
91901
|
* // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
|
|
91583
91902
|
*/
|
|
91584
|
-
async mailboxDelete(
|
|
91585
|
-
return await this.run("DELETE",
|
|
91903
|
+
async mailboxDelete(path24) {
|
|
91904
|
+
return await this.run("DELETE", path24);
|
|
91586
91905
|
}
|
|
91587
91906
|
/**
|
|
91588
91907
|
* Subscribes to a mailbox
|
|
@@ -91593,8 +91912,8 @@ var require_imap_flow = __commonJS({
|
|
|
91593
91912
|
* @example
|
|
91594
91913
|
* await client.mailboxSubscribe('Important stuff ❗️');
|
|
91595
91914
|
*/
|
|
91596
|
-
async mailboxSubscribe(
|
|
91597
|
-
return await this.run("SUBSCRIBE",
|
|
91915
|
+
async mailboxSubscribe(path24) {
|
|
91916
|
+
return await this.run("SUBSCRIBE", path24);
|
|
91598
91917
|
}
|
|
91599
91918
|
/**
|
|
91600
91919
|
* Unsubscribes from a mailbox
|
|
@@ -91605,8 +91924,8 @@ var require_imap_flow = __commonJS({
|
|
|
91605
91924
|
* @example
|
|
91606
91925
|
* await client.mailboxUnsubscribe('Important stuff ❗️');
|
|
91607
91926
|
*/
|
|
91608
|
-
async mailboxUnsubscribe(
|
|
91609
|
-
return await this.run("UNSUBSCRIBE",
|
|
91927
|
+
async mailboxUnsubscribe(path24) {
|
|
91928
|
+
return await this.run("UNSUBSCRIBE", path24);
|
|
91610
91929
|
}
|
|
91611
91930
|
/**
|
|
91612
91931
|
* Opens a mailbox to access messages. You can perform message operations only against an opened mailbox.
|
|
@@ -91624,8 +91943,8 @@ var require_imap_flow = __commonJS({
|
|
|
91624
91943
|
* console.log(mailbox.exists);
|
|
91625
91944
|
* // 125
|
|
91626
91945
|
*/
|
|
91627
|
-
async mailboxOpen(
|
|
91628
|
-
return await this.run("SELECT",
|
|
91946
|
+
async mailboxOpen(path24, options) {
|
|
91947
|
+
return await this.run("SELECT", path24, options);
|
|
91629
91948
|
}
|
|
91630
91949
|
/**
|
|
91631
91950
|
* Closes a previously opened mailbox
|
|
@@ -91672,8 +91991,8 @@ var require_imap_flow = __commonJS({
|
|
|
91672
91991
|
* console.log(status.unseen);
|
|
91673
91992
|
* // 123
|
|
91674
91993
|
*/
|
|
91675
|
-
async status(
|
|
91676
|
-
return await this.run("STATUS",
|
|
91994
|
+
async status(path24, query) {
|
|
91995
|
+
return await this.run("STATUS", path24, query);
|
|
91677
91996
|
}
|
|
91678
91997
|
/**
|
|
91679
91998
|
* Starts listening for new or deleted messages from the currently opened mailbox. Only required if {@link ImapFlow#disableAutoIdle} is set to `true`
|
|
@@ -91927,8 +92246,8 @@ var require_imap_flow = __commonJS({
|
|
|
91927
92246
|
* @example
|
|
91928
92247
|
* await client.append('INBOX', rawMessageBuffer, ['\\Seen'], new Date(2000, 1, 1));
|
|
91929
92248
|
*/
|
|
91930
|
-
async append(
|
|
91931
|
-
return await this.run("APPEND",
|
|
92249
|
+
async append(path24, content, flags, idate) {
|
|
92250
|
+
return await this.run("APPEND", path24, content, flags, idate) || false;
|
|
91932
92251
|
}
|
|
91933
92252
|
/**
|
|
91934
92253
|
* @typedef {Object} CopyResponseObject
|
|
@@ -92772,7 +93091,7 @@ var require_imap_flow = __commonJS({
|
|
|
92772
93091
|
await new Promise((resolve2) => setImmediate(resolve2));
|
|
92773
93092
|
}
|
|
92774
93093
|
const lock = this.locks.shift();
|
|
92775
|
-
const { resolve, reject, path:
|
|
93094
|
+
const { resolve, reject, path: path24, options, lockId } = lock;
|
|
92776
93095
|
if (lock.acquireTimer) {
|
|
92777
93096
|
clearTimeout(lock.acquireTimer);
|
|
92778
93097
|
lock.acquireTimer = null;
|
|
@@ -92788,7 +93107,7 @@ var require_imap_flow = __commonJS({
|
|
|
92788
93107
|
this.log.warn({
|
|
92789
93108
|
msg: "Mailbox lock held for a long time",
|
|
92790
93109
|
lockId: lock.lockId,
|
|
92791
|
-
path:
|
|
93110
|
+
path: path24,
|
|
92792
93111
|
heldFor: Date.now() - lock.heldAt,
|
|
92793
93112
|
/* c8 ignore next */
|
|
92794
93113
|
// the held-lock-warning diagnostic with a description set is a timing-dependent log detail
|
|
@@ -92824,52 +93143,52 @@ var require_imap_flow = __commonJS({
|
|
|
92824
93143
|
}
|
|
92825
93144
|
};
|
|
92826
93145
|
if (!this.usable || !this.socket || this.socket.destroyed) {
|
|
92827
|
-
this.log.trace({ msg: "Failed to acquire mailbox lock", path:
|
|
93146
|
+
this.log.trace({ msg: "Failed to acquire mailbox lock", path: path24, lockId, idling: this.idling });
|
|
92828
93147
|
let error2 = new Error("Connection not available");
|
|
92829
93148
|
error2.code = "NoConnection";
|
|
92830
93149
|
reject(error2);
|
|
92831
93150
|
continue;
|
|
92832
93151
|
}
|
|
92833
|
-
if (this.mailbox && this.mailbox.path ===
|
|
93152
|
+
if (this.mailbox && this.mailbox.path === path24 && !!this.mailbox.readOnly === !!options.readOnly) {
|
|
92834
93153
|
this.log.trace({
|
|
92835
93154
|
msg: "Mailbox lock acquired [existing]",
|
|
92836
|
-
path:
|
|
93155
|
+
path: path24,
|
|
92837
93156
|
lockId,
|
|
92838
93157
|
idling: this.idling,
|
|
92839
93158
|
...options.description && { description: options.description }
|
|
92840
93159
|
});
|
|
92841
93160
|
this.currentLock = lock;
|
|
92842
93161
|
armHeldTimer();
|
|
92843
|
-
resolve({ path:
|
|
93162
|
+
resolve({ path: path24, release });
|
|
92844
93163
|
break;
|
|
92845
93164
|
}
|
|
92846
93165
|
try {
|
|
92847
|
-
await this.mailboxOpen(
|
|
93166
|
+
await this.mailboxOpen(path24, options);
|
|
92848
93167
|
this.log.trace({
|
|
92849
93168
|
msg: "Mailbox lock acquired [selected]",
|
|
92850
|
-
path:
|
|
93169
|
+
path: path24,
|
|
92851
93170
|
lockId,
|
|
92852
93171
|
idling: this.idling,
|
|
92853
93172
|
...options.description && { description: options.description }
|
|
92854
93173
|
});
|
|
92855
93174
|
this.currentLock = lock;
|
|
92856
93175
|
armHeldTimer();
|
|
92857
|
-
resolve({ path:
|
|
93176
|
+
resolve({ path: path24, release });
|
|
92858
93177
|
break;
|
|
92859
93178
|
} catch (err) {
|
|
92860
93179
|
if (err.responseStatus === "NO") {
|
|
92861
93180
|
try {
|
|
92862
|
-
let folders = await this.run("LIST", "",
|
|
93181
|
+
let folders = await this.run("LIST", "", path24, { listOnly: true });
|
|
92863
93182
|
if (!folders || !folders.length) {
|
|
92864
93183
|
err.mailboxMissing = true;
|
|
92865
93184
|
}
|
|
92866
93185
|
} catch (E) {
|
|
92867
|
-
this.log.trace({ msg: "Failed to verify failed mailbox", path:
|
|
93186
|
+
this.log.trace({ msg: "Failed to verify failed mailbox", path: path24, err: E });
|
|
92868
93187
|
}
|
|
92869
93188
|
}
|
|
92870
93189
|
this.log.trace({
|
|
92871
93190
|
msg: "Failed to acquire mailbox lock",
|
|
92872
|
-
path:
|
|
93191
|
+
path: path24,
|
|
92873
93192
|
lockId,
|
|
92874
93193
|
idling: this.idling,
|
|
92875
93194
|
...options.description && { description: options.description },
|
|
@@ -92908,13 +93227,13 @@ var require_imap_flow = __commonJS({
|
|
|
92908
93227
|
* lock.release();
|
|
92909
93228
|
* }
|
|
92910
93229
|
*/
|
|
92911
|
-
getMailboxLock(
|
|
93230
|
+
getMailboxLock(path24, options) {
|
|
92912
93231
|
options = options || {};
|
|
92913
|
-
|
|
93232
|
+
path24 = normalizePath(this, path24);
|
|
92914
93233
|
let lockId = ++this.lockCounter;
|
|
92915
93234
|
this.log.trace({
|
|
92916
93235
|
msg: "Requesting lock",
|
|
92917
|
-
path:
|
|
93236
|
+
path: path24,
|
|
92918
93237
|
lockId,
|
|
92919
93238
|
...options.description && { description: options.description },
|
|
92920
93239
|
activeLock: this.currentLock ? {
|
|
@@ -92923,7 +93242,7 @@ var require_imap_flow = __commonJS({
|
|
|
92923
93242
|
} : null
|
|
92924
93243
|
});
|
|
92925
93244
|
let lockPromise = new Promise((resolve, reject) => {
|
|
92926
|
-
let lockEntry = { resolve, reject, path:
|
|
93245
|
+
let lockEntry = { resolve, reject, path: path24, options, lockId };
|
|
92927
93246
|
this.locks.push(lockEntry);
|
|
92928
93247
|
if (Number(options.acquireTimeout) > 0) {
|
|
92929
93248
|
lockEntry.acquireTimer = setTimeout(() => {
|
|
@@ -93012,16 +93331,16 @@ var require_imap_flow = __commonJS({
|
|
|
93012
93331
|
});
|
|
93013
93332
|
|
|
93014
93333
|
// src/mail/mail-fetcher.ts
|
|
93015
|
-
import
|
|
93016
|
-
import
|
|
93334
|
+
import fs21 from "node:fs/promises";
|
|
93335
|
+
import path22 from "node:path";
|
|
93017
93336
|
async function saveAttachments(attachments, downloadDir) {
|
|
93018
93337
|
if (attachments.length === 0) return [];
|
|
93019
|
-
await
|
|
93338
|
+
await fs21.mkdir(downloadDir, { recursive: true });
|
|
93020
93339
|
const saved = [];
|
|
93021
93340
|
for (const a of attachments) {
|
|
93022
|
-
const name =
|
|
93023
|
-
const savedPath =
|
|
93024
|
-
await
|
|
93341
|
+
const name = path22.basename(a.filename) || "attachment";
|
|
93342
|
+
const savedPath = path22.join(downloadDir, name);
|
|
93343
|
+
await fs21.writeFile(savedPath, a.content);
|
|
93025
93344
|
saved.push({ filename: name, savedPath, size: a.content.length });
|
|
93026
93345
|
}
|
|
93027
93346
|
return saved;
|
|
@@ -93151,8 +93470,8 @@ var init_mail_fetcher = __esm({
|
|
|
93151
93470
|
});
|
|
93152
93471
|
|
|
93153
93472
|
// src/tools/fetch-mail.ts
|
|
93154
|
-
import
|
|
93155
|
-
import
|
|
93473
|
+
import os16 from "node:os";
|
|
93474
|
+
import path23 from "node:path";
|
|
93156
93475
|
function registerFetchMailTool(server, deps = {}) {
|
|
93157
93476
|
const makeFetcher = deps.fetcherFactory ?? ((creds) => new ImapflowMailFetcher(creds));
|
|
93158
93477
|
server.registerTool(
|
|
@@ -93214,7 +93533,7 @@ var init_fetch_mail = __esm({
|
|
|
93214
93533
|
init_mail_fetcher();
|
|
93215
93534
|
init_auth_error();
|
|
93216
93535
|
init_validate();
|
|
93217
|
-
DEFAULT_DOWNLOAD_DIR =
|
|
93536
|
+
DEFAULT_DOWNLOAD_DIR = path23.join(os16.homedir(), ".cogent", "mail-downloads");
|
|
93218
93537
|
}
|
|
93219
93538
|
});
|
|
93220
93539
|
|