@essentialai/cogent-bridge-bundled 3.23.7 → 3.23.8
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 +445 -376
- 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: path26, errorMaps, issueData } = params;
|
|
1263
|
+
const fullPath = [...path26, ...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, path26, key) {
|
|
1544
1544
|
this._cachedPath = [];
|
|
1545
1545
|
this.parent = parent;
|
|
1546
1546
|
this.data = value;
|
|
1547
|
-
this._path =
|
|
1547
|
+
this._path = path26;
|
|
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, path26) {
|
|
5000
|
+
if (!path26)
|
|
5001
5001
|
return obj;
|
|
5002
|
-
return
|
|
5002
|
+
return path26.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(path26, 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(path26);
|
|
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(path26) {
|
|
17062
|
+
let input = path26;
|
|
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 [path26, query] = wsComponent.resourceName.split("?");
|
|
17262
|
+
wsComponent.path = path26 && path26 !== "/" ? path26 : 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, fs24, 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, fs24[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: path26, errorMaps, issueData } = params;
|
|
21733
|
+
const fullPath = [...path26, ...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, path26, key) {
|
|
21888
21888
|
this._cachedPath = [];
|
|
21889
21889
|
this.parent = parent;
|
|
21890
21890
|
this.data = value;
|
|
21891
|
-
this._path =
|
|
21891
|
+
this._path = path26;
|
|
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.8") {
|
|
26393
|
+
return "3.23.8";
|
|
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 path26 = 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(path26, 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 path26 = 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(path26, {});
|
|
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 path26 = PATHS.peers.replace(":sessionId", this.sessionId);
|
|
27899
|
+
const result = await this.http.get(path26);
|
|
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 path26 = PATHS.heartbeat.replace(":sessionId", this.sessionId);
|
|
27908
|
+
await this.http.post(path26, { 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 path26 = 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(path26, 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 path26 = 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(path26, 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 path26 = 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(path26, 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(path26, query) {
|
|
28130
|
+
const url = new URL(path26, 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(path26, body) {
|
|
28146
|
+
const url = new URL(path26, 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(path26, body) {
|
|
28165
|
+
const url = new URL(path26, 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(path26, body) {
|
|
28191
|
+
const url = new URL(path26, this.baseUrl);
|
|
28192
28192
|
const headers = {
|
|
28193
28193
|
"Authorization": `Bearer ${this.token}`
|
|
28194
28194
|
};
|
|
@@ -32087,6 +32087,44 @@ var init_wrapper = __esm({
|
|
|
32087
32087
|
}
|
|
32088
32088
|
});
|
|
32089
32089
|
|
|
32090
|
+
// src/cloud/poll-cursor.ts
|
|
32091
|
+
import fs11 from "node:fs";
|
|
32092
|
+
import os8 from "node:os";
|
|
32093
|
+
import path12 from "node:path";
|
|
32094
|
+
function pollCursorPath(sessionId, peerId) {
|
|
32095
|
+
return path12.join(os8.homedir(), ".cogent", "poll-cursors", `${safe(sessionId)}.${safe(peerId)}.json`);
|
|
32096
|
+
}
|
|
32097
|
+
function loadPollCursor(sessionId, peerId) {
|
|
32098
|
+
if (!sessionId || !peerId) return null;
|
|
32099
|
+
try {
|
|
32100
|
+
const raw = JSON.parse(fs11.readFileSync(pollCursorPath(sessionId, peerId), "utf-8"));
|
|
32101
|
+
return typeof raw?.lastMessageId === "string" && raw.lastMessageId ? raw.lastMessageId : null;
|
|
32102
|
+
} catch {
|
|
32103
|
+
return null;
|
|
32104
|
+
}
|
|
32105
|
+
}
|
|
32106
|
+
function savePollCursor(sessionId, peerId, lastMessageId) {
|
|
32107
|
+
if (!sessionId || !peerId || !lastMessageId) return;
|
|
32108
|
+
const p = pollCursorPath(sessionId, peerId);
|
|
32109
|
+
try {
|
|
32110
|
+
fs11.mkdirSync(path12.dirname(p), { recursive: true });
|
|
32111
|
+
fs11.writeFileSync(
|
|
32112
|
+
p,
|
|
32113
|
+
JSON.stringify({ lastMessageId, updatedAt: (/* @__PURE__ */ new Date()).toISOString() })
|
|
32114
|
+
);
|
|
32115
|
+
} catch (err) {
|
|
32116
|
+
logger.debug(`poll-cursor: could not persist (${err.message})`);
|
|
32117
|
+
}
|
|
32118
|
+
}
|
|
32119
|
+
var safe;
|
|
32120
|
+
var init_poll_cursor = __esm({
|
|
32121
|
+
"src/cloud/poll-cursor.ts"() {
|
|
32122
|
+
"use strict";
|
|
32123
|
+
init_logger();
|
|
32124
|
+
safe = (s) => String(s).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
32125
|
+
}
|
|
32126
|
+
});
|
|
32127
|
+
|
|
32090
32128
|
// src/cloud/ws-client.ts
|
|
32091
32129
|
var CloudWsClient;
|
|
32092
32130
|
var init_ws_client = __esm({
|
|
@@ -32096,6 +32134,7 @@ var init_ws_client = __esm({
|
|
|
32096
32134
|
init_backoff();
|
|
32097
32135
|
init_ws_frames();
|
|
32098
32136
|
init_logger();
|
|
32137
|
+
init_poll_cursor();
|
|
32099
32138
|
CloudWsClient = class {
|
|
32100
32139
|
ws = null;
|
|
32101
32140
|
state = "disconnected";
|
|
@@ -32104,6 +32143,34 @@ var init_ws_client = __esm({
|
|
|
32104
32143
|
pollTimer = null;
|
|
32105
32144
|
pingTimer = null;
|
|
32106
32145
|
lastMessageId = null;
|
|
32146
|
+
/**
|
|
32147
|
+
* Advance the poll cursor AND persist it.
|
|
32148
|
+
*
|
|
32149
|
+
* Every assignment must go through here. `lastMessageId` was in-memory only, so a restart sent
|
|
32150
|
+
* no cursor and the relay replayed the whole channel ("If lastMessageId is not provided (first
|
|
32151
|
+
* poll), returns all messages") — re-injecting days-old broadcasts on every restart.
|
|
32152
|
+
*/
|
|
32153
|
+
advanceCursor(id) {
|
|
32154
|
+
if (!id) return;
|
|
32155
|
+
this.lastMessageId = id;
|
|
32156
|
+
savePollCursor(this.opts.sessionId, this.opts.peerId, id);
|
|
32157
|
+
}
|
|
32158
|
+
/**
|
|
32159
|
+
* Seed the cursor from disk when this process has not consumed anything yet.
|
|
32160
|
+
*
|
|
32161
|
+
* Only ever fills a NULL cursor: a live in-memory position is always newer than the stored one,
|
|
32162
|
+
* so it must never be overwritten by a restore.
|
|
32163
|
+
*/
|
|
32164
|
+
restoreCursor() {
|
|
32165
|
+
if (this.lastMessageId) return;
|
|
32166
|
+
const stored = loadPollCursor(this.opts.sessionId, this.opts.peerId);
|
|
32167
|
+
if (stored) {
|
|
32168
|
+
this.lastMessageId = stored;
|
|
32169
|
+
logger.info(
|
|
32170
|
+
`CloudWsClient: resuming from stored poll cursor (${stored.slice(0, 8)}\u2026) \u2014 the channel backlog before it has already been consumed and will not be replayed.`
|
|
32171
|
+
);
|
|
32172
|
+
}
|
|
32173
|
+
}
|
|
32107
32174
|
lastWsError = null;
|
|
32108
32175
|
connectionGeneration = 0;
|
|
32109
32176
|
opts;
|
|
@@ -32126,6 +32193,7 @@ var init_ws_client = __esm({
|
|
|
32126
32193
|
* Guards against empty peerId -- call setPeerId() first.
|
|
32127
32194
|
*/
|
|
32128
32195
|
connect() {
|
|
32196
|
+
this.restoreCursor();
|
|
32129
32197
|
if (!this.opts.peerId) {
|
|
32130
32198
|
logger.warn(
|
|
32131
32199
|
"CloudWsClient: Cannot connect WebSocket without peerId. Call setPeerId() first."
|
|
@@ -32277,7 +32345,7 @@ var init_ws_client = __esm({
|
|
|
32277
32345
|
* Update the last seen message ID (e.g., from HttpBackend operations).
|
|
32278
32346
|
*/
|
|
32279
32347
|
updateLastMessageId(id) {
|
|
32280
|
-
this.
|
|
32348
|
+
this.advanceCursor(id);
|
|
32281
32349
|
}
|
|
32282
32350
|
/**
|
|
32283
32351
|
* Update the auth token for reconnection.
|
|
@@ -32355,13 +32423,13 @@ var init_ws_client = __esm({
|
|
|
32355
32423
|
switch (frame.type) {
|
|
32356
32424
|
case "message":
|
|
32357
32425
|
this.opts.onMessage(frame.payload);
|
|
32358
|
-
this.
|
|
32426
|
+
this.advanceCursor(frame.payload.id);
|
|
32359
32427
|
break;
|
|
32360
32428
|
case "queued_messages": {
|
|
32361
32429
|
const msgs = frame.payload.messages;
|
|
32362
32430
|
this.opts.onMessages(msgs);
|
|
32363
32431
|
if (msgs.length > 0) {
|
|
32364
|
-
this.
|
|
32432
|
+
this.advanceCursor(msgs[msgs.length - 1].id);
|
|
32365
32433
|
}
|
|
32366
32434
|
break;
|
|
32367
32435
|
}
|
|
@@ -32391,19 +32459,20 @@ var init_ws_client = __esm({
|
|
|
32391
32459
|
}
|
|
32392
32460
|
startPolling() {
|
|
32393
32461
|
if (this.pollTimer) return;
|
|
32462
|
+
this.restoreCursor();
|
|
32394
32463
|
const poll = async () => {
|
|
32395
32464
|
try {
|
|
32396
|
-
const
|
|
32465
|
+
const path26 = `/api/sessions/${this.opts.sessionId}/poll`;
|
|
32397
32466
|
const query = {
|
|
32398
32467
|
peerId: this.opts.peerId
|
|
32399
32468
|
};
|
|
32400
32469
|
if (this.lastMessageId) {
|
|
32401
32470
|
query.lastMessageId = this.lastMessageId;
|
|
32402
32471
|
}
|
|
32403
|
-
const result = await this.opts.http.get(
|
|
32472
|
+
const result = await this.opts.http.get(path26, query);
|
|
32404
32473
|
if (result.messages && result.messages.length > 0) {
|
|
32405
32474
|
this.opts.onMessages(result.messages);
|
|
32406
|
-
this.
|
|
32475
|
+
this.advanceCursor(result.messages[result.messages.length - 1].id);
|
|
32407
32476
|
}
|
|
32408
32477
|
} catch (err) {
|
|
32409
32478
|
logger.warn(
|
|
@@ -32457,9 +32526,9 @@ var init_cloud = __esm({
|
|
|
32457
32526
|
|
|
32458
32527
|
// src/services/codex-cli.ts
|
|
32459
32528
|
import { spawn as spawn2 } from "node:child_process";
|
|
32460
|
-
import
|
|
32461
|
-
import
|
|
32462
|
-
import
|
|
32529
|
+
import fs12 from "node:fs/promises";
|
|
32530
|
+
import os9 from "node:os";
|
|
32531
|
+
import path13 from "node:path";
|
|
32463
32532
|
import { randomUUID } from "node:crypto";
|
|
32464
32533
|
import { createReadStream } from "node:fs";
|
|
32465
32534
|
import { createInterface as createInterface2 } from "node:readline";
|
|
@@ -32487,7 +32556,7 @@ function execCodex(sessionId, message, cwd, timeoutMs) {
|
|
|
32487
32556
|
const config2 = getConfig();
|
|
32488
32557
|
const effectiveTimeout = timeoutMs ?? config2.COGENT_TIMEOUT_MS;
|
|
32489
32558
|
const truncated = config2.COGENT_CHAR_LIMIT > 0 && message.length > config2.COGENT_CHAR_LIMIT ? message.slice(0, config2.COGENT_CHAR_LIMIT) + "\n...[truncated]" : message;
|
|
32490
|
-
const lastMsgFile =
|
|
32559
|
+
const lastMsgFile = path13.join(os9.tmpdir(), `cogent-codex-${randomUUID()}.txt`);
|
|
32491
32560
|
const args = [
|
|
32492
32561
|
"exec",
|
|
32493
32562
|
"resume",
|
|
@@ -32515,7 +32584,7 @@ function execCodex(sessionId, message, cwd, timeoutMs) {
|
|
|
32515
32584
|
resolve(result);
|
|
32516
32585
|
}
|
|
32517
32586
|
};
|
|
32518
|
-
const cleanupFile = () =>
|
|
32587
|
+
const cleanupFile = () => fs12.rm(lastMsgFile, { force: true }).catch(() => {
|
|
32519
32588
|
});
|
|
32520
32589
|
const timer = setTimeout(async () => {
|
|
32521
32590
|
killed = true;
|
|
@@ -32566,7 +32635,7 @@ function execCodex(sessionId, message, cwd, timeoutMs) {
|
|
|
32566
32635
|
}
|
|
32567
32636
|
let fileMessage = "";
|
|
32568
32637
|
try {
|
|
32569
|
-
fileMessage = await
|
|
32638
|
+
fileMessage = await fs12.readFile(lastMsgFile, "utf8");
|
|
32570
32639
|
} catch {
|
|
32571
32640
|
fileMessage = "";
|
|
32572
32641
|
}
|
|
@@ -32587,12 +32656,12 @@ async function listRolloutFiles(root) {
|
|
|
32587
32656
|
async function walk(dir) {
|
|
32588
32657
|
let entries;
|
|
32589
32658
|
try {
|
|
32590
|
-
entries = await
|
|
32659
|
+
entries = await fs12.readdir(dir, { withFileTypes: true });
|
|
32591
32660
|
} catch {
|
|
32592
32661
|
return;
|
|
32593
32662
|
}
|
|
32594
32663
|
for (const e of entries) {
|
|
32595
|
-
const full =
|
|
32664
|
+
const full = path13.join(dir, e.name);
|
|
32596
32665
|
if (e.isDirectory()) await walk(full);
|
|
32597
32666
|
else if (e.isFile() && e.name.endsWith(".jsonl")) out.push(full);
|
|
32598
32667
|
}
|
|
@@ -32624,19 +32693,19 @@ async function readSessionMeta(file) {
|
|
|
32624
32693
|
}
|
|
32625
32694
|
}
|
|
32626
32695
|
function codexSessionsRoot() {
|
|
32627
|
-
return
|
|
32696
|
+
return path13.join(codexHomeDir(), "sessions");
|
|
32628
32697
|
}
|
|
32629
32698
|
async function cwdCanonicals(cwd) {
|
|
32630
|
-
const resolved =
|
|
32699
|
+
const resolved = path13.resolve(cwd);
|
|
32631
32700
|
const forms = /* @__PURE__ */ new Set([resolved]);
|
|
32632
32701
|
try {
|
|
32633
|
-
forms.add(await
|
|
32702
|
+
forms.add(await fs12.realpath(resolved));
|
|
32634
32703
|
} catch {
|
|
32635
32704
|
}
|
|
32636
32705
|
return forms;
|
|
32637
32706
|
}
|
|
32638
32707
|
function metaCwdMatches(metaCwd, forms) {
|
|
32639
|
-
return forms.has(
|
|
32708
|
+
return forms.has(path13.resolve(metaCwd));
|
|
32640
32709
|
}
|
|
32641
32710
|
async function detectCurrentCodexSession(cwd) {
|
|
32642
32711
|
try {
|
|
@@ -32644,7 +32713,7 @@ async function detectCurrentCodexSession(cwd) {
|
|
|
32644
32713
|
const files = await listRolloutFiles(codexSessionsRoot());
|
|
32645
32714
|
const withStats = await Promise.all(
|
|
32646
32715
|
files.map(async (f) => {
|
|
32647
|
-
const stat = await
|
|
32716
|
+
const stat = await fs12.stat(f);
|
|
32648
32717
|
return { file: f, mtimeMs: stat.mtimeMs };
|
|
32649
32718
|
})
|
|
32650
32719
|
);
|
|
@@ -32663,7 +32732,7 @@ async function listCodexCandidates(cwd) {
|
|
|
32663
32732
|
const forms = await cwdCanonicals(cwd);
|
|
32664
32733
|
const files = await listRolloutFiles(codexSessionsRoot());
|
|
32665
32734
|
const withStats = await Promise.all(
|
|
32666
|
-
files.map(async (f) => ({ file: f, mtimeMs: (await
|
|
32735
|
+
files.map(async (f) => ({ file: f, mtimeMs: (await fs12.stat(f)).mtimeMs }))
|
|
32667
32736
|
);
|
|
32668
32737
|
const bySession = /* @__PURE__ */ new Map();
|
|
32669
32738
|
for (const { file, mtimeMs } of withStats) {
|
|
@@ -32703,12 +32772,12 @@ var init_codex_cli = __esm({
|
|
|
32703
32772
|
});
|
|
32704
32773
|
|
|
32705
32774
|
// src/services/codex-app-server.ts
|
|
32706
|
-
import
|
|
32775
|
+
import path14 from "node:path";
|
|
32707
32776
|
import { statSync } from "node:fs";
|
|
32708
|
-
import
|
|
32777
|
+
import fs13 from "node:fs/promises";
|
|
32709
32778
|
import { spawn as spawn3, spawnSync } from "node:child_process";
|
|
32710
32779
|
function appServerSocketPath(codexHome = codexHomeDir()) {
|
|
32711
|
-
return
|
|
32780
|
+
return path14.join(codexHome, "app-server-control", "app-server-control.sock");
|
|
32712
32781
|
}
|
|
32713
32782
|
function appServerDaemonRunning(codexHome = codexHomeDir()) {
|
|
32714
32783
|
try {
|
|
@@ -32956,7 +33025,7 @@ var init_codex_app_server = __esm({
|
|
|
32956
33025
|
});
|
|
32957
33026
|
defaultSocketExists = async (p) => {
|
|
32958
33027
|
try {
|
|
32959
|
-
await
|
|
33028
|
+
await fs13.stat(p);
|
|
32960
33029
|
return true;
|
|
32961
33030
|
} catch {
|
|
32962
33031
|
return false;
|
|
@@ -33122,14 +33191,14 @@ var init_exec_remote = __esm({
|
|
|
33122
33191
|
// src/services/wake-log.ts
|
|
33123
33192
|
import { execFileSync } from "node:child_process";
|
|
33124
33193
|
import crypto4 from "node:crypto";
|
|
33125
|
-
import
|
|
33126
|
-
import
|
|
33127
|
-
import
|
|
33194
|
+
import fs14 from "node:fs";
|
|
33195
|
+
import os10 from "node:os";
|
|
33196
|
+
import path15 from "node:path";
|
|
33128
33197
|
function hashCwd2(cwd) {
|
|
33129
|
-
return crypto4.createHash("sha256").update(
|
|
33198
|
+
return crypto4.createHash("sha256").update(path15.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33130
33199
|
}
|
|
33131
33200
|
function wakeLogPath(cwd) {
|
|
33132
|
-
return
|
|
33201
|
+
return path15.join(os10.homedir(), ".cogent", "wake-log", `${hashCwd2(cwd)}.jsonl`);
|
|
33133
33202
|
}
|
|
33134
33203
|
function git(cwd, args) {
|
|
33135
33204
|
return execFileSync("git", ["-C", cwd, ...args], {
|
|
@@ -33173,13 +33242,13 @@ function preview(message) {
|
|
|
33173
33242
|
function appendWakeRecord(record2, cwd) {
|
|
33174
33243
|
const target = wakeLogPath(cwd);
|
|
33175
33244
|
try {
|
|
33176
|
-
|
|
33245
|
+
fs14.mkdirSync(path15.dirname(target), { recursive: true });
|
|
33177
33246
|
const row = {
|
|
33178
33247
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
33179
33248
|
...record2,
|
|
33180
33249
|
messagePreview: preview(record2.messagePreview ?? "")
|
|
33181
33250
|
};
|
|
33182
|
-
|
|
33251
|
+
fs14.appendFileSync(target, `${JSON.stringify(row)}
|
|
33183
33252
|
`);
|
|
33184
33253
|
pruneIfNeeded(target);
|
|
33185
33254
|
} catch {
|
|
@@ -33187,20 +33256,20 @@ function appendWakeRecord(record2, cwd) {
|
|
|
33187
33256
|
}
|
|
33188
33257
|
function pruneIfNeeded(target) {
|
|
33189
33258
|
try {
|
|
33190
|
-
const lines =
|
|
33259
|
+
const lines = fs14.readFileSync(target, "utf-8").split("\n").filter((l) => l.length > 0);
|
|
33191
33260
|
if (lines.length <= WAKE_LOG_MAX_RECORDS) return;
|
|
33192
33261
|
const kept = lines.slice(lines.length - WAKE_LOG_MAX_RECORDS);
|
|
33193
33262
|
const tmp = `${target}.tmp-${process.pid}`;
|
|
33194
|
-
|
|
33263
|
+
fs14.writeFileSync(tmp, `${kept.join("\n")}
|
|
33195
33264
|
`);
|
|
33196
|
-
|
|
33265
|
+
fs14.renameSync(tmp, target);
|
|
33197
33266
|
} catch {
|
|
33198
33267
|
}
|
|
33199
33268
|
}
|
|
33200
33269
|
function readWakeLog(cwd, limit) {
|
|
33201
33270
|
let lines;
|
|
33202
33271
|
try {
|
|
33203
|
-
lines =
|
|
33272
|
+
lines = fs14.readFileSync(wakeLogPath(cwd), "utf-8").split("\n").filter((l) => l.length > 0);
|
|
33204
33273
|
} catch {
|
|
33205
33274
|
return [];
|
|
33206
33275
|
}
|
|
@@ -33313,14 +33382,14 @@ var init_session_resolver = __esm({
|
|
|
33313
33382
|
|
|
33314
33383
|
// src/services/wake-inflight.ts
|
|
33315
33384
|
import crypto5 from "node:crypto";
|
|
33316
|
-
import
|
|
33317
|
-
import
|
|
33318
|
-
import
|
|
33385
|
+
import fs15 from "node:fs";
|
|
33386
|
+
import os11 from "node:os";
|
|
33387
|
+
import path16 from "node:path";
|
|
33319
33388
|
function hashCwd3(cwd) {
|
|
33320
|
-
return crypto5.createHash("sha256").update(
|
|
33389
|
+
return crypto5.createHash("sha256").update(path16.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33321
33390
|
}
|
|
33322
33391
|
function wakeInflightPath(peerId, cwd = process.cwd()) {
|
|
33323
|
-
return
|
|
33392
|
+
return path16.join(os11.homedir(), ".cogent", "wake-inflight", `${hashCwd3(cwd)}.${safe2(peerId)}.json`);
|
|
33324
33393
|
}
|
|
33325
33394
|
function ttlMs() {
|
|
33326
33395
|
let timeout = 3e5;
|
|
@@ -33333,17 +33402,17 @@ function ttlMs() {
|
|
|
33333
33402
|
}
|
|
33334
33403
|
function readFileSafe(p) {
|
|
33335
33404
|
try {
|
|
33336
|
-
const parsed = JSON.parse(
|
|
33405
|
+
const parsed = JSON.parse(fs15.readFileSync(p, "utf-8"));
|
|
33337
33406
|
return parsed && typeof parsed === "object" && parsed.messages ? parsed : { messages: {} };
|
|
33338
33407
|
} catch {
|
|
33339
33408
|
return { messages: {} };
|
|
33340
33409
|
}
|
|
33341
33410
|
}
|
|
33342
33411
|
function writeAtomic(p, data) {
|
|
33343
|
-
|
|
33412
|
+
fs15.mkdirSync(path16.dirname(p), { recursive: true });
|
|
33344
33413
|
const tmp = `${p}.${process.pid}.tmp`;
|
|
33345
|
-
|
|
33346
|
-
|
|
33414
|
+
fs15.writeFileSync(tmp, JSON.stringify(data, null, 2) + "\n", "utf-8");
|
|
33415
|
+
fs15.renameSync(tmp, p);
|
|
33347
33416
|
}
|
|
33348
33417
|
function prune(f, now) {
|
|
33349
33418
|
for (const [id, rec] of Object.entries(f.messages)) {
|
|
@@ -33383,7 +33452,7 @@ function clearWakeInFlight(peerId, messageId, cwd = process.cwd()) {
|
|
|
33383
33452
|
logger.debug(`wake-inflight: could not clear ${messageId}: ${err}`);
|
|
33384
33453
|
}
|
|
33385
33454
|
}
|
|
33386
|
-
var INFLIGHT_MAX_MS, INFLIGHT_TIMEOUT_FACTOR,
|
|
33455
|
+
var INFLIGHT_MAX_MS, INFLIGHT_TIMEOUT_FACTOR, safe2;
|
|
33387
33456
|
var init_wake_inflight = __esm({
|
|
33388
33457
|
"src/services/wake-inflight.ts"() {
|
|
33389
33458
|
"use strict";
|
|
@@ -33391,24 +33460,24 @@ var init_wake_inflight = __esm({
|
|
|
33391
33460
|
init_logger();
|
|
33392
33461
|
INFLIGHT_MAX_MS = 18e5;
|
|
33393
33462
|
INFLIGHT_TIMEOUT_FACTOR = 3;
|
|
33394
|
-
|
|
33463
|
+
safe2 = (s) => String(s).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
33395
33464
|
}
|
|
33396
33465
|
});
|
|
33397
33466
|
|
|
33398
33467
|
// src/services/wake-claim.ts
|
|
33399
33468
|
import crypto6 from "node:crypto";
|
|
33400
|
-
import
|
|
33401
|
-
import
|
|
33402
|
-
import
|
|
33469
|
+
import fs16 from "node:fs";
|
|
33470
|
+
import os12 from "node:os";
|
|
33471
|
+
import path17 from "node:path";
|
|
33403
33472
|
function hashCwd4(cwd) {
|
|
33404
|
-
return crypto6.createHash("sha256").update(
|
|
33473
|
+
return crypto6.createHash("sha256").update(path17.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33405
33474
|
}
|
|
33406
33475
|
function wakeClaimPath(peerId, messageId, cwd = process.cwd()) {
|
|
33407
|
-
return
|
|
33408
|
-
|
|
33476
|
+
return path17.join(
|
|
33477
|
+
os12.homedir(),
|
|
33409
33478
|
".cogent",
|
|
33410
33479
|
"wake-claims",
|
|
33411
|
-
`${hashCwd4(cwd)}.${
|
|
33480
|
+
`${hashCwd4(cwd)}.${safe3(peerId)}.${safe3(messageId)}.json`
|
|
33412
33481
|
);
|
|
33413
33482
|
}
|
|
33414
33483
|
function ttlMs2() {
|
|
@@ -33435,22 +33504,22 @@ function claimWake(peerId, messageId, cwd = process.cwd()) {
|
|
|
33435
33504
|
const now = Date.now();
|
|
33436
33505
|
const body = () => JSON.stringify({ pid: process.pid, startedAt: now, expiresAt: now + ttlMs2() });
|
|
33437
33506
|
try {
|
|
33438
|
-
|
|
33507
|
+
fs16.mkdirSync(path17.dirname(p), { recursive: true });
|
|
33439
33508
|
try {
|
|
33440
|
-
|
|
33509
|
+
fs16.writeFileSync(p, body(), { flag: "wx" });
|
|
33441
33510
|
return true;
|
|
33442
33511
|
} catch (err) {
|
|
33443
33512
|
if (err?.code !== "EEXIST") throw err;
|
|
33444
33513
|
}
|
|
33445
33514
|
let held = null;
|
|
33446
33515
|
try {
|
|
33447
|
-
held = JSON.parse(
|
|
33516
|
+
held = JSON.parse(fs16.readFileSync(p, "utf-8"));
|
|
33448
33517
|
} catch {
|
|
33449
33518
|
held = null;
|
|
33450
33519
|
}
|
|
33451
33520
|
const expired = !held || typeof held.expiresAt !== "number" || held.expiresAt <= now;
|
|
33452
33521
|
if (!held || expired || !holderAlive(held.pid)) {
|
|
33453
|
-
|
|
33522
|
+
fs16.writeFileSync(p, body());
|
|
33454
33523
|
logger.debug(`wake-claim: took over an abandoned claim for ${messageId}`);
|
|
33455
33524
|
return true;
|
|
33456
33525
|
}
|
|
@@ -33465,11 +33534,11 @@ function claimWake(peerId, messageId, cwd = process.cwd()) {
|
|
|
33465
33534
|
}
|
|
33466
33535
|
function releaseWake(peerId, messageId, cwd = process.cwd()) {
|
|
33467
33536
|
try {
|
|
33468
|
-
|
|
33537
|
+
fs16.unlinkSync(wakeClaimPath(peerId, messageId, cwd));
|
|
33469
33538
|
} catch {
|
|
33470
33539
|
}
|
|
33471
33540
|
}
|
|
33472
|
-
var CLAIM_MAX_MS, CLAIM_TIMEOUT_FACTOR,
|
|
33541
|
+
var CLAIM_MAX_MS, CLAIM_TIMEOUT_FACTOR, safe3;
|
|
33473
33542
|
var init_wake_claim = __esm({
|
|
33474
33543
|
"src/services/wake-claim.ts"() {
|
|
33475
33544
|
"use strict";
|
|
@@ -33477,20 +33546,20 @@ var init_wake_claim = __esm({
|
|
|
33477
33546
|
init_logger();
|
|
33478
33547
|
CLAIM_MAX_MS = 18e5;
|
|
33479
33548
|
CLAIM_TIMEOUT_FACTOR = 3;
|
|
33480
|
-
|
|
33549
|
+
safe3 = (s) => String(s).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
33481
33550
|
}
|
|
33482
33551
|
});
|
|
33483
33552
|
|
|
33484
33553
|
// src/services/wake-lock.ts
|
|
33485
33554
|
import crypto7 from "node:crypto";
|
|
33486
|
-
import
|
|
33487
|
-
import
|
|
33488
|
-
import
|
|
33555
|
+
import fs17 from "node:fs";
|
|
33556
|
+
import os13 from "node:os";
|
|
33557
|
+
import path18 from "node:path";
|
|
33489
33558
|
function hashCwd5(cwd) {
|
|
33490
|
-
return crypto7.createHash("sha256").update(
|
|
33559
|
+
return crypto7.createHash("sha256").update(path18.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33491
33560
|
}
|
|
33492
33561
|
function wakeLockPath(cwd = process.cwd()) {
|
|
33493
|
-
return
|
|
33562
|
+
return path18.join(os13.homedir(), ".cogent", "wake-locks", `${hashCwd5(cwd)}.json`);
|
|
33494
33563
|
}
|
|
33495
33564
|
function leaseTtlMs() {
|
|
33496
33565
|
let timeout = 3e5;
|
|
@@ -33521,7 +33590,7 @@ function holderAlive2(pid) {
|
|
|
33521
33590
|
}
|
|
33522
33591
|
function readHolder(p) {
|
|
33523
33592
|
try {
|
|
33524
|
-
const held = JSON.parse(
|
|
33593
|
+
const held = JSON.parse(fs17.readFileSync(p, "utf-8"));
|
|
33525
33594
|
if (!held || typeof held.expiresAt !== "number") return null;
|
|
33526
33595
|
return held;
|
|
33527
33596
|
} catch {
|
|
@@ -33568,7 +33637,7 @@ async function acquireWakeLock(cwd = process.cwd(), sessionId = "unknown", opts
|
|
|
33568
33637
|
} };
|
|
33569
33638
|
};
|
|
33570
33639
|
try {
|
|
33571
|
-
|
|
33640
|
+
fs17.mkdirSync(path18.dirname(p), { recursive: true });
|
|
33572
33641
|
} catch (err) {
|
|
33573
33642
|
return failOpen(`cannot create lock dir (${err.message})`);
|
|
33574
33643
|
}
|
|
@@ -33581,7 +33650,7 @@ async function acquireWakeLock(cwd = process.cwd(), sessionId = "unknown", opts
|
|
|
33581
33650
|
expiresAt: now + leaseTtlMs()
|
|
33582
33651
|
});
|
|
33583
33652
|
try {
|
|
33584
|
-
|
|
33653
|
+
fs17.writeFileSync(p, body, { flag: "wx" });
|
|
33585
33654
|
if (contended) {
|
|
33586
33655
|
logger.info(
|
|
33587
33656
|
`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.`
|
|
@@ -33596,7 +33665,7 @@ async function acquireWakeLock(cwd = process.cwd(), sessionId = "unknown", opts
|
|
|
33596
33665
|
const held = readHolder(p);
|
|
33597
33666
|
if (!held || held.expiresAt <= now || !holderAlive2(held.pid)) {
|
|
33598
33667
|
try {
|
|
33599
|
-
|
|
33668
|
+
fs17.writeFileSync(p, body);
|
|
33600
33669
|
} catch (err) {
|
|
33601
33670
|
return failOpen(`cannot steal abandoned lock (${err.message})`);
|
|
33602
33671
|
}
|
|
@@ -33619,7 +33688,7 @@ async function acquireWakeLock(cwd = process.cwd(), sessionId = "unknown", opts
|
|
|
33619
33688
|
}
|
|
33620
33689
|
function releaseWakeLock(cwd = process.cwd()) {
|
|
33621
33690
|
try {
|
|
33622
|
-
|
|
33691
|
+
fs17.unlinkSync(wakeLockPath(cwd));
|
|
33623
33692
|
} catch {
|
|
33624
33693
|
}
|
|
33625
33694
|
}
|
|
@@ -33639,14 +33708,14 @@ var init_wake_lock = __esm({
|
|
|
33639
33708
|
|
|
33640
33709
|
// src/services/wake-ownership.ts
|
|
33641
33710
|
import crypto8 from "node:crypto";
|
|
33642
|
-
import
|
|
33643
|
-
import
|
|
33644
|
-
import
|
|
33711
|
+
import fs18 from "node:fs";
|
|
33712
|
+
import os14 from "node:os";
|
|
33713
|
+
import path19 from "node:path";
|
|
33645
33714
|
function hashCwd6(cwd) {
|
|
33646
|
-
return crypto8.createHash("sha256").update(
|
|
33715
|
+
return crypto8.createHash("sha256").update(path19.resolve(cwd)).digest("hex").slice(0, 16);
|
|
33647
33716
|
}
|
|
33648
33717
|
function bridgeDirFor(cwd, peerId) {
|
|
33649
|
-
return
|
|
33718
|
+
return path19.join(os14.homedir(), ".cogent", "bridges", `${hashCwd6(cwd)}.${safe4(peerId)}`);
|
|
33650
33719
|
}
|
|
33651
33720
|
function pidAlive(pid) {
|
|
33652
33721
|
if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return false;
|
|
@@ -33661,23 +33730,23 @@ function pidAlive(pid) {
|
|
|
33661
33730
|
function announceBridge(cwd, peerId, version2, endpoint) {
|
|
33662
33731
|
const dir = bridgeDirFor(cwd, peerId);
|
|
33663
33732
|
try {
|
|
33664
|
-
|
|
33733
|
+
fs18.mkdirSync(dir, { recursive: true });
|
|
33665
33734
|
const entry = {
|
|
33666
33735
|
pid: process.pid,
|
|
33667
33736
|
startedAt: PROCESS_STARTED_AT,
|
|
33668
33737
|
version: version2,
|
|
33669
33738
|
peerId,
|
|
33670
33739
|
endpoint,
|
|
33671
|
-
cwd:
|
|
33740
|
+
cwd: path19.resolve(cwd)
|
|
33672
33741
|
};
|
|
33673
|
-
|
|
33742
|
+
fs18.writeFileSync(path19.join(dir, `${process.pid}.json`), JSON.stringify(entry));
|
|
33674
33743
|
} catch (err) {
|
|
33675
33744
|
logger.debug(`wake-ownership: could not announce this bridge (${err.message})`);
|
|
33676
33745
|
}
|
|
33677
33746
|
}
|
|
33678
33747
|
function withdrawBridge(cwd, peerId) {
|
|
33679
33748
|
try {
|
|
33680
|
-
|
|
33749
|
+
fs18.unlinkSync(path19.join(bridgeDirFor(cwd, peerId), `${process.pid}.json`));
|
|
33681
33750
|
} catch {
|
|
33682
33751
|
}
|
|
33683
33752
|
}
|
|
@@ -33685,23 +33754,23 @@ function listLiveBridges(cwd, peerId) {
|
|
|
33685
33754
|
const dir = bridgeDirFor(cwd, peerId);
|
|
33686
33755
|
let names;
|
|
33687
33756
|
try {
|
|
33688
|
-
names =
|
|
33757
|
+
names = fs18.readdirSync(dir);
|
|
33689
33758
|
} catch {
|
|
33690
33759
|
return [];
|
|
33691
33760
|
}
|
|
33692
33761
|
const live = [];
|
|
33693
33762
|
for (const name of names) {
|
|
33694
33763
|
if (!name.endsWith(".json")) continue;
|
|
33695
|
-
const p =
|
|
33764
|
+
const p = path19.join(dir, name);
|
|
33696
33765
|
let entry = null;
|
|
33697
33766
|
try {
|
|
33698
|
-
entry = JSON.parse(
|
|
33767
|
+
entry = JSON.parse(fs18.readFileSync(p, "utf-8"));
|
|
33699
33768
|
} catch {
|
|
33700
33769
|
entry = null;
|
|
33701
33770
|
}
|
|
33702
33771
|
if (!entry || !pidAlive(entry.pid) || typeof entry.startedAt !== "number") {
|
|
33703
33772
|
try {
|
|
33704
|
-
|
|
33773
|
+
fs18.unlinkSync(p);
|
|
33705
33774
|
} catch {
|
|
33706
33775
|
}
|
|
33707
33776
|
continue;
|
|
@@ -33731,20 +33800,20 @@ function checkWakeOwnership(cwd, peerId) {
|
|
|
33731
33800
|
}
|
|
33732
33801
|
return { isOwner: true, liveCount: live.length + 1 };
|
|
33733
33802
|
}
|
|
33734
|
-
var PROCESS_STARTED_AT,
|
|
33803
|
+
var PROCESS_STARTED_AT, safe4;
|
|
33735
33804
|
var init_wake_ownership = __esm({
|
|
33736
33805
|
"src/services/wake-ownership.ts"() {
|
|
33737
33806
|
"use strict";
|
|
33738
33807
|
init_logger();
|
|
33739
33808
|
PROCESS_STARTED_AT = Date.now() - Math.floor(process.uptime() * 1e3);
|
|
33740
|
-
|
|
33809
|
+
safe4 = (s) => String(s).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
33741
33810
|
}
|
|
33742
33811
|
});
|
|
33743
33812
|
|
|
33744
33813
|
// src/services/stale-bridge-reaper.ts
|
|
33745
33814
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
33746
|
-
import
|
|
33747
|
-
import
|
|
33815
|
+
import fs19 from "node:fs";
|
|
33816
|
+
import path20 from "node:path";
|
|
33748
33817
|
function isBridgeCommand(argv) {
|
|
33749
33818
|
if (!argv) return false;
|
|
33750
33819
|
if (/\.test\.|-test\.mjs|scripts\//.test(argv)) return false;
|
|
@@ -33785,7 +33854,7 @@ function listProcesses() {
|
|
|
33785
33854
|
function processCwd(pid) {
|
|
33786
33855
|
try {
|
|
33787
33856
|
if (process.platform === "linux") {
|
|
33788
|
-
return
|
|
33857
|
+
return path20.resolve(fs19.readlinkSync(`/proc/${pid}/cwd`));
|
|
33789
33858
|
}
|
|
33790
33859
|
if (process.platform === "darwin") {
|
|
33791
33860
|
const out = execFileSync2("lsof", ["-a", "-d", "cwd", "-p", String(pid), "-Fn"], {
|
|
@@ -33794,7 +33863,7 @@ function processCwd(pid) {
|
|
|
33794
33863
|
stdio: ["ignore", "pipe", "ignore"]
|
|
33795
33864
|
});
|
|
33796
33865
|
const line = out.split("\n").find((l) => l.startsWith("n"));
|
|
33797
|
-
return line ?
|
|
33866
|
+
return line ? path20.resolve(line.slice(1)) : null;
|
|
33798
33867
|
}
|
|
33799
33868
|
} catch {
|
|
33800
33869
|
}
|
|
@@ -33802,9 +33871,9 @@ function processCwd(pid) {
|
|
|
33802
33871
|
}
|
|
33803
33872
|
function canonicalPath(p) {
|
|
33804
33873
|
try {
|
|
33805
|
-
return
|
|
33874
|
+
return fs19.realpathSync(path20.resolve(p));
|
|
33806
33875
|
} catch {
|
|
33807
|
-
return
|
|
33876
|
+
return path20.resolve(p);
|
|
33808
33877
|
}
|
|
33809
33878
|
}
|
|
33810
33879
|
function ancestorsOf(pid, procs) {
|
|
@@ -33820,9 +33889,9 @@ function ancestorsOf(pid, procs) {
|
|
|
33820
33889
|
function announcedPidsFor(cwd) {
|
|
33821
33890
|
const pids = /* @__PURE__ */ new Set();
|
|
33822
33891
|
try {
|
|
33823
|
-
const base =
|
|
33824
|
-
const prefix =
|
|
33825
|
-
for (const dir of
|
|
33892
|
+
const base = path20.dirname(bridgeDirFor(cwd, "x"));
|
|
33893
|
+
const prefix = path20.basename(bridgeDirFor(cwd, "x")).split(".")[0];
|
|
33894
|
+
for (const dir of fs19.readdirSync(base)) {
|
|
33826
33895
|
if (!dir.startsWith(`${prefix}.`)) continue;
|
|
33827
33896
|
const peerId = dir.slice(prefix.length + 1);
|
|
33828
33897
|
for (const e of listLiveBridges(cwd, peerId)) pids.add(e.pid);
|
|
@@ -35267,9 +35336,9 @@ __export(startup_exports, {
|
|
|
35267
35336
|
setInboxNotifier: () => setInboxNotifier,
|
|
35268
35337
|
triggerReRegistration: () => triggerReRegistration
|
|
35269
35338
|
});
|
|
35270
|
-
import
|
|
35271
|
-
import
|
|
35272
|
-
import
|
|
35339
|
+
import os15 from "node:os";
|
|
35340
|
+
import path21 from "node:path";
|
|
35341
|
+
import fs20 from "node:fs/promises";
|
|
35273
35342
|
import readline2 from "node:readline";
|
|
35274
35343
|
import { execFile as execFile5 } from "node:child_process";
|
|
35275
35344
|
import { promisify as promisify4 } from "node:util";
|
|
@@ -35287,7 +35356,7 @@ function bindInboxNotifier() {
|
|
|
35287
35356
|
}
|
|
35288
35357
|
async function loadPersistedConfig() {
|
|
35289
35358
|
try {
|
|
35290
|
-
const raw = await
|
|
35359
|
+
const raw = await fs20.readFile(PERSIST_PATH, "utf-8");
|
|
35291
35360
|
return JSON.parse(raw);
|
|
35292
35361
|
} catch {
|
|
35293
35362
|
return {};
|
|
@@ -35295,7 +35364,7 @@ async function loadPersistedConfig() {
|
|
|
35295
35364
|
}
|
|
35296
35365
|
async function savePersistedConfig(config2) {
|
|
35297
35366
|
try {
|
|
35298
|
-
await
|
|
35367
|
+
await fs20.writeFile(PERSIST_PATH, JSON.stringify(config2, null, 2) + "\n", "utf-8");
|
|
35299
35368
|
} catch (err) {
|
|
35300
35369
|
const msg = err instanceof Error ? err.message : String(err);
|
|
35301
35370
|
logger.warn(`Could not save config to ${PERSIST_PATH}: ${msg}`);
|
|
@@ -35330,11 +35399,11 @@ First run detected. Where should cogent-bridge store its data?
|
|
|
35330
35399
|
});
|
|
35331
35400
|
}
|
|
35332
35401
|
async function validateStateDir(statePath) {
|
|
35333
|
-
await
|
|
35334
|
-
const testFile =
|
|
35402
|
+
await fs20.mkdir(statePath, { recursive: true });
|
|
35403
|
+
const testFile = path21.join(statePath, ".write-test");
|
|
35335
35404
|
try {
|
|
35336
|
-
await
|
|
35337
|
-
await
|
|
35405
|
+
await fs20.writeFile(testFile, "test", "utf-8");
|
|
35406
|
+
await fs20.unlink(testFile);
|
|
35338
35407
|
} catch {
|
|
35339
35408
|
throw new BridgeError(
|
|
35340
35409
|
"STARTUP_FAILED" /* STARTUP_FAILED */,
|
|
@@ -35522,10 +35591,10 @@ async function runStartup() {
|
|
|
35522
35591
|
if (envStatePath) {
|
|
35523
35592
|
statePath = envStatePath;
|
|
35524
35593
|
} else {
|
|
35525
|
-
const defaultPath =
|
|
35594
|
+
const defaultPath = path21.join(os15.homedir(), ".cogent");
|
|
35526
35595
|
statePath = await firstRunPrompt(defaultPath);
|
|
35527
35596
|
}
|
|
35528
|
-
if (!envStatePath && statePath !==
|
|
35597
|
+
if (!envStatePath && statePath !== path21.join(os15.homedir(), ".cogent")) {
|
|
35529
35598
|
process.env.COGENT_STATE_PATH = statePath;
|
|
35530
35599
|
} else if (!envStatePath) {
|
|
35531
35600
|
process.env.COGENT_STATE_PATH = statePath;
|
|
@@ -35589,7 +35658,7 @@ async function runStartup() {
|
|
|
35589
35658
|
}
|
|
35590
35659
|
initLogger(
|
|
35591
35660
|
config2.COGENT_LOG_LEVEL,
|
|
35592
|
-
|
|
35661
|
+
path21.join(config2.COGENT_STATE_PATH, "logs")
|
|
35593
35662
|
);
|
|
35594
35663
|
if (isCloud && effectiveSessionId && effectiveToken) {
|
|
35595
35664
|
cloudInbox = new MessageInbox();
|
|
@@ -35651,7 +35720,7 @@ var init_startup = __esm({
|
|
|
35651
35720
|
init_auto_relay();
|
|
35652
35721
|
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;
|
|
35653
35722
|
execFileAsync3 = promisify4(execFile5);
|
|
35654
|
-
PERSIST_PATH =
|
|
35723
|
+
PERSIST_PATH = path21.join(os15.homedir(), ".cogent-config.json");
|
|
35655
35724
|
legacyWarnEmitted = false;
|
|
35656
35725
|
cloudWsClient = null;
|
|
35657
35726
|
cloudInbox = null;
|
|
@@ -35666,12 +35735,12 @@ var init_startup = __esm({
|
|
|
35666
35735
|
|
|
35667
35736
|
// src/cloud/mail-credential-store.ts
|
|
35668
35737
|
import crypto9 from "node:crypto";
|
|
35669
|
-
import
|
|
35670
|
-
import
|
|
35671
|
-
import
|
|
35738
|
+
import fs21 from "node:fs/promises";
|
|
35739
|
+
import path22 from "node:path";
|
|
35740
|
+
import os16 from "node:os";
|
|
35672
35741
|
function defaultMailCredentialPath(cwd = process.cwd()) {
|
|
35673
|
-
const hash = crypto9.createHash("sha256").update(
|
|
35674
|
-
return
|
|
35742
|
+
const hash = crypto9.createHash("sha256").update(path22.resolve(cwd)).digest("hex").slice(0, 16);
|
|
35743
|
+
return path22.join(os16.homedir(), ".cogent", "mail-credentials", `${hash}.json`);
|
|
35675
35744
|
}
|
|
35676
35745
|
function resolveMailCredentialPath(credentialPath) {
|
|
35677
35746
|
if (credentialPath) return credentialPath;
|
|
@@ -35682,16 +35751,16 @@ function resolveMailCredentialPath(credentialPath) {
|
|
|
35682
35751
|
async function loadMailCredentials(credentialPath) {
|
|
35683
35752
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35684
35753
|
try {
|
|
35685
|
-
return JSON.parse(await
|
|
35754
|
+
return JSON.parse(await fs21.readFile(filePath, "utf-8"));
|
|
35686
35755
|
} catch {
|
|
35687
35756
|
return null;
|
|
35688
35757
|
}
|
|
35689
35758
|
}
|
|
35690
35759
|
async function saveMailCredentials(creds, credentialPath) {
|
|
35691
35760
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35692
|
-
await
|
|
35693
|
-
await
|
|
35694
|
-
await
|
|
35761
|
+
await fs21.mkdir(path22.dirname(filePath), { recursive: true, mode: 448 });
|
|
35762
|
+
await fs21.writeFile(filePath, JSON.stringify(creds, null, 2) + "\n", { encoding: "utf-8", mode: 384 });
|
|
35763
|
+
await fs21.chmod(filePath, 384);
|
|
35695
35764
|
}
|
|
35696
35765
|
async function persistProvisionedMailbox(mailbox, credentialPath) {
|
|
35697
35766
|
if (!mailbox?.address || !mailbox.password) return false;
|
|
@@ -35712,7 +35781,7 @@ async function persistProvisionedMailbox(mailbox, credentialPath) {
|
|
|
35712
35781
|
async function clearMailCredentials(credentialPath) {
|
|
35713
35782
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35714
35783
|
try {
|
|
35715
|
-
await
|
|
35784
|
+
await fs21.unlink(filePath);
|
|
35716
35785
|
} catch (err) {
|
|
35717
35786
|
if (err.code !== "ENOENT") throw err;
|
|
35718
35787
|
}
|
|
@@ -37723,8 +37792,8 @@ var require_cookies = __commonJS({
|
|
|
37723
37792
|
if (urlparts.hostname !== cookie.domain && (cookie.domain.charAt(0) !== "." || ("." + urlparts.hostname).substr(-cookie.domain.length) !== cookie.domain)) {
|
|
37724
37793
|
return false;
|
|
37725
37794
|
}
|
|
37726
|
-
let
|
|
37727
|
-
if (
|
|
37795
|
+
let path26 = this.getPath(urlparts.pathname);
|
|
37796
|
+
if (path26.substr(0, cookie.path.length) !== cookie.path) {
|
|
37728
37797
|
return false;
|
|
37729
37798
|
}
|
|
37730
37799
|
if (cookie.secure && urlparts.protocol !== "https:") {
|
|
@@ -37784,16 +37853,16 @@ var require_cookies = __commonJS({
|
|
|
37784
37853
|
* @returns {String} Normalized path
|
|
37785
37854
|
*/
|
|
37786
37855
|
getPath(pathname) {
|
|
37787
|
-
let
|
|
37788
|
-
|
|
37789
|
-
|
|
37790
|
-
if (
|
|
37791
|
-
|
|
37856
|
+
let path26 = (pathname || "/").split("/");
|
|
37857
|
+
path26.pop();
|
|
37858
|
+
path26 = path26.join("/").trim();
|
|
37859
|
+
if (path26.charAt(0) !== "/") {
|
|
37860
|
+
path26 = "/" + path26;
|
|
37792
37861
|
}
|
|
37793
|
-
if (
|
|
37794
|
-
|
|
37862
|
+
if (path26.substr(-1) !== "/") {
|
|
37863
|
+
path26 += "/";
|
|
37795
37864
|
}
|
|
37796
|
-
return
|
|
37865
|
+
return path26;
|
|
37797
37866
|
}
|
|
37798
37867
|
};
|
|
37799
37868
|
module.exports = Cookies;
|
|
@@ -38094,15 +38163,15 @@ var require_shared = __commonJS({
|
|
|
38094
38163
|
"use strict";
|
|
38095
38164
|
var urllib = __require("url");
|
|
38096
38165
|
var util2 = __require("util");
|
|
38097
|
-
var
|
|
38166
|
+
var fs24 = __require("fs");
|
|
38098
38167
|
var nmfetch = require_fetch();
|
|
38099
38168
|
var dns = __require("dns");
|
|
38100
38169
|
var net = __require("net");
|
|
38101
|
-
var
|
|
38170
|
+
var os18 = __require("os");
|
|
38102
38171
|
var DNS_TTL = 5 * 60 * 1e3;
|
|
38103
38172
|
var networkInterfaces;
|
|
38104
38173
|
try {
|
|
38105
|
-
networkInterfaces =
|
|
38174
|
+
networkInterfaces = os18.networkInterfaces();
|
|
38106
38175
|
} catch (err) {
|
|
38107
38176
|
}
|
|
38108
38177
|
module.exports.networkInterfaces = networkInterfaces;
|
|
@@ -38480,7 +38549,7 @@ var require_shared = __commonJS({
|
|
|
38480
38549
|
}
|
|
38481
38550
|
return callback(null, parsedDataUri.data);
|
|
38482
38551
|
} else if (content.path) {
|
|
38483
|
-
return resolveStream(
|
|
38552
|
+
return resolveStream(fs24.createReadStream(content.path), callback);
|
|
38484
38553
|
}
|
|
38485
38554
|
}
|
|
38486
38555
|
if (typeof data[key].content === "string" && !["utf8", "usascii", "ascii"].includes(encoding)) {
|
|
@@ -38604,7 +38673,7 @@ var require_shared = __commonJS({
|
|
|
38604
38673
|
var require_mime_types = __commonJS({
|
|
38605
38674
|
"node_modules/nodemailer/lib/mime-funcs/mime-types.js"(exports, module) {
|
|
38606
38675
|
"use strict";
|
|
38607
|
-
var
|
|
38676
|
+
var path26 = __require("path");
|
|
38608
38677
|
var defaultMimeType = "application/octet-stream";
|
|
38609
38678
|
var defaultExtension = "bin";
|
|
38610
38679
|
var mimeTypes = /* @__PURE__ */ new Map([
|
|
@@ -40662,7 +40731,7 @@ var require_mime_types = __commonJS({
|
|
|
40662
40731
|
if (!filename) {
|
|
40663
40732
|
return defaultMimeType;
|
|
40664
40733
|
}
|
|
40665
|
-
let parsed =
|
|
40734
|
+
let parsed = path26.parse(filename);
|
|
40666
40735
|
let extension = (parsed.ext.substr(1) || parsed.name || "").split("?").shift().trim().toLowerCase();
|
|
40667
40736
|
let value = defaultMimeType;
|
|
40668
40737
|
if (extensions.has(extension)) {
|
|
@@ -42064,7 +42133,7 @@ var require_mime_node = __commonJS({
|
|
|
42064
42133
|
"node_modules/nodemailer/lib/mime-node/index.js"(exports, module) {
|
|
42065
42134
|
"use strict";
|
|
42066
42135
|
var crypto12 = __require("crypto");
|
|
42067
|
-
var
|
|
42136
|
+
var fs24 = __require("fs");
|
|
42068
42137
|
var punycode = require_punycode();
|
|
42069
42138
|
var PassThrough = __require("stream").PassThrough;
|
|
42070
42139
|
var shared = require_shared();
|
|
@@ -42779,7 +42848,7 @@ var require_mime_node = __commonJS({
|
|
|
42779
42848
|
setImmediate(() => contentStream.emit("error", new Error("File access rejected for " + content.path)));
|
|
42780
42849
|
return contentStream;
|
|
42781
42850
|
}
|
|
42782
|
-
return
|
|
42851
|
+
return fs24.createReadStream(content.path);
|
|
42783
42852
|
} else if (content && typeof content.href === "string") {
|
|
42784
42853
|
if (this.disableUrlAccess) {
|
|
42785
42854
|
contentStream = new PassThrough();
|
|
@@ -43800,8 +43869,8 @@ var require_dkim = __commonJS({
|
|
|
43800
43869
|
var RelaxedBody = require_relaxed_body();
|
|
43801
43870
|
var sign = require_sign();
|
|
43802
43871
|
var PassThrough = __require("stream").PassThrough;
|
|
43803
|
-
var
|
|
43804
|
-
var
|
|
43872
|
+
var fs24 = __require("fs");
|
|
43873
|
+
var path26 = __require("path");
|
|
43805
43874
|
var crypto12 = __require("crypto");
|
|
43806
43875
|
var DKIM_ALGO = "sha256";
|
|
43807
43876
|
var MAX_MESSAGE_SIZE = 128 * 1024;
|
|
@@ -43815,7 +43884,7 @@ var require_dkim = __commonJS({
|
|
|
43815
43884
|
this.chunks = [];
|
|
43816
43885
|
this.chunklen = 0;
|
|
43817
43886
|
this.readPos = 0;
|
|
43818
|
-
this.cachePath = this.cacheDir ?
|
|
43887
|
+
this.cachePath = this.cacheDir ? path26.join(this.cacheDir, "message." + Date.now() + "-" + crypto12.randomBytes(14).toString("hex")) : false;
|
|
43819
43888
|
this.cache = false;
|
|
43820
43889
|
this.headers = false;
|
|
43821
43890
|
this.bodyHash = false;
|
|
@@ -43835,10 +43904,10 @@ var require_dkim = __commonJS({
|
|
|
43835
43904
|
if (!this.cache || !this.cachePath) {
|
|
43836
43905
|
return;
|
|
43837
43906
|
}
|
|
43838
|
-
|
|
43907
|
+
fs24.unlink(this.cachePath, () => false);
|
|
43839
43908
|
}
|
|
43840
43909
|
createReadCache() {
|
|
43841
|
-
this.cache =
|
|
43910
|
+
this.cache = fs24.createReadStream(this.cachePath);
|
|
43842
43911
|
this.cache.once("error", (err) => {
|
|
43843
43912
|
this.cleanup();
|
|
43844
43913
|
this.output.emit("error", err);
|
|
@@ -43894,7 +43963,7 @@ var require_dkim = __commonJS({
|
|
|
43894
43963
|
}
|
|
43895
43964
|
createWriteCache() {
|
|
43896
43965
|
this.output.usingCache = true;
|
|
43897
|
-
this.cache =
|
|
43966
|
+
this.cache = fs24.createWriteStream(this.cachePath);
|
|
43898
43967
|
this.cache.once("error", (err) => {
|
|
43899
43968
|
this.cleanup();
|
|
43900
43969
|
this.relaxedBody.unpipe(this.cache);
|
|
@@ -44821,7 +44890,7 @@ var require_smtp_connection = __commonJS({
|
|
|
44821
44890
|
var EventEmitter = __require("events").EventEmitter;
|
|
44822
44891
|
var net = __require("net");
|
|
44823
44892
|
var tls = __require("tls");
|
|
44824
|
-
var
|
|
44893
|
+
var os18 = __require("os");
|
|
44825
44894
|
var crypto12 = __require("crypto");
|
|
44826
44895
|
var DataStream = require_data_stream();
|
|
44827
44896
|
var PassThrough = __require("stream").PassThrough;
|
|
@@ -46214,7 +46283,7 @@ var require_smtp_connection = __commonJS({
|
|
|
46214
46283
|
_getHostname() {
|
|
46215
46284
|
let defaultHostname;
|
|
46216
46285
|
try {
|
|
46217
|
-
defaultHostname =
|
|
46286
|
+
defaultHostname = os18.hostname() || "";
|
|
46218
46287
|
} catch (err) {
|
|
46219
46288
|
defaultHostname = "localhost";
|
|
46220
46289
|
}
|
|
@@ -48783,13 +48852,13 @@ var require_nodemailer = __commonJS({
|
|
|
48783
48852
|
});
|
|
48784
48853
|
|
|
48785
48854
|
// src/mail/mail-sender.ts
|
|
48786
|
-
import
|
|
48787
|
-
import
|
|
48855
|
+
import fs22 from "node:fs/promises";
|
|
48856
|
+
import path23 from "node:path";
|
|
48788
48857
|
async function buildAndSendMail(sender, creds, params) {
|
|
48789
48858
|
const attachments = [];
|
|
48790
48859
|
for (const p of params.attachmentPaths ?? []) {
|
|
48791
|
-
const content = await
|
|
48792
|
-
attachments.push({ filename:
|
|
48860
|
+
const content = await fs22.readFile(p);
|
|
48861
|
+
attachments.push({ filename: path23.basename(p), content });
|
|
48793
48862
|
}
|
|
48794
48863
|
const { messageId } = await sender.send({
|
|
48795
48864
|
from: creds.address,
|
|
@@ -49178,8 +49247,8 @@ var require_req = __commonJS({
|
|
|
49178
49247
|
if (req.originalUrl) {
|
|
49179
49248
|
_req.url = req.originalUrl;
|
|
49180
49249
|
} else {
|
|
49181
|
-
const
|
|
49182
|
-
_req.url = typeof
|
|
49250
|
+
const path26 = req.path;
|
|
49251
|
+
_req.url = typeof path26 === "string" ? path26 : req.url ? req.url.path || req.url : void 0;
|
|
49183
49252
|
}
|
|
49184
49253
|
if (req.query) {
|
|
49185
49254
|
_req.query = req.query;
|
|
@@ -49344,14 +49413,14 @@ var require_redact = __commonJS({
|
|
|
49344
49413
|
}
|
|
49345
49414
|
return obj;
|
|
49346
49415
|
}
|
|
49347
|
-
function parsePath(
|
|
49416
|
+
function parsePath(path26) {
|
|
49348
49417
|
const parts = [];
|
|
49349
49418
|
let current = "";
|
|
49350
49419
|
let inBrackets = false;
|
|
49351
49420
|
let inQuotes = false;
|
|
49352
49421
|
let quoteChar = "";
|
|
49353
|
-
for (let i = 0; i <
|
|
49354
|
-
const char =
|
|
49422
|
+
for (let i = 0; i < path26.length; i++) {
|
|
49423
|
+
const char = path26[i];
|
|
49355
49424
|
if (!inBrackets && char === ".") {
|
|
49356
49425
|
if (current) {
|
|
49357
49426
|
parts.push(current);
|
|
@@ -49482,10 +49551,10 @@ var require_redact = __commonJS({
|
|
|
49482
49551
|
return current;
|
|
49483
49552
|
}
|
|
49484
49553
|
function redactPaths(obj, paths, censor, remove = false) {
|
|
49485
|
-
for (const
|
|
49486
|
-
const parts = parsePath(
|
|
49554
|
+
for (const path26 of paths) {
|
|
49555
|
+
const parts = parsePath(path26);
|
|
49487
49556
|
if (parts.includes("*")) {
|
|
49488
|
-
redactWildcardPath(obj, parts, censor,
|
|
49557
|
+
redactWildcardPath(obj, parts, censor, path26, remove);
|
|
49489
49558
|
} else {
|
|
49490
49559
|
if (remove) {
|
|
49491
49560
|
removeKey(obj, parts);
|
|
@@ -49570,8 +49639,8 @@ var require_redact = __commonJS({
|
|
|
49570
49639
|
}
|
|
49571
49640
|
} else {
|
|
49572
49641
|
if (afterWildcard.includes("*")) {
|
|
49573
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
49574
|
-
const fullPath = [...pathArray.slice(0, pathLength), ...
|
|
49642
|
+
const wrappedCensor = typeof censor === "function" ? (value, path26) => {
|
|
49643
|
+
const fullPath = [...pathArray.slice(0, pathLength), ...path26];
|
|
49575
49644
|
return censor(value, fullPath);
|
|
49576
49645
|
} : censor;
|
|
49577
49646
|
redactWildcardPath(current, afterWildcard, wrappedCensor, originalPath, remove);
|
|
@@ -49606,8 +49675,8 @@ var require_redact = __commonJS({
|
|
|
49606
49675
|
return null;
|
|
49607
49676
|
}
|
|
49608
49677
|
const pathStructure = /* @__PURE__ */ new Map();
|
|
49609
|
-
for (const
|
|
49610
|
-
const parts = parsePath(
|
|
49678
|
+
for (const path26 of pathsToClone) {
|
|
49679
|
+
const parts = parsePath(path26);
|
|
49611
49680
|
let current = pathStructure;
|
|
49612
49681
|
for (let i = 0; i < parts.length; i++) {
|
|
49613
49682
|
const part = parts[i];
|
|
@@ -49659,24 +49728,24 @@ var require_redact = __commonJS({
|
|
|
49659
49728
|
}
|
|
49660
49729
|
return cloneSelectively(obj, pathStructure);
|
|
49661
49730
|
}
|
|
49662
|
-
function validatePath(
|
|
49663
|
-
if (typeof
|
|
49731
|
+
function validatePath(path26) {
|
|
49732
|
+
if (typeof path26 !== "string") {
|
|
49664
49733
|
throw new Error("Paths must be (non-empty) strings");
|
|
49665
49734
|
}
|
|
49666
|
-
if (
|
|
49735
|
+
if (path26 === "") {
|
|
49667
49736
|
throw new Error("Invalid redaction path ()");
|
|
49668
49737
|
}
|
|
49669
|
-
if (
|
|
49670
|
-
throw new Error(`Invalid redaction path (${
|
|
49738
|
+
if (path26.includes("..")) {
|
|
49739
|
+
throw new Error(`Invalid redaction path (${path26})`);
|
|
49671
49740
|
}
|
|
49672
|
-
if (
|
|
49673
|
-
throw new Error(`Invalid redaction path (${
|
|
49741
|
+
if (path26.includes(",")) {
|
|
49742
|
+
throw new Error(`Invalid redaction path (${path26})`);
|
|
49674
49743
|
}
|
|
49675
49744
|
let bracketCount = 0;
|
|
49676
49745
|
let inQuotes = false;
|
|
49677
49746
|
let quoteChar = "";
|
|
49678
|
-
for (let i = 0; i <
|
|
49679
|
-
const char =
|
|
49747
|
+
for (let i = 0; i < path26.length; i++) {
|
|
49748
|
+
const char = path26[i];
|
|
49680
49749
|
if ((char === '"' || char === "'") && bracketCount > 0) {
|
|
49681
49750
|
if (!inQuotes) {
|
|
49682
49751
|
inQuotes = true;
|
|
@@ -49690,20 +49759,20 @@ var require_redact = __commonJS({
|
|
|
49690
49759
|
} else if (char === "]" && !inQuotes) {
|
|
49691
49760
|
bracketCount--;
|
|
49692
49761
|
if (bracketCount < 0) {
|
|
49693
|
-
throw new Error(`Invalid redaction path (${
|
|
49762
|
+
throw new Error(`Invalid redaction path (${path26})`);
|
|
49694
49763
|
}
|
|
49695
49764
|
}
|
|
49696
49765
|
}
|
|
49697
49766
|
if (bracketCount !== 0) {
|
|
49698
|
-
throw new Error(`Invalid redaction path (${
|
|
49767
|
+
throw new Error(`Invalid redaction path (${path26})`);
|
|
49699
49768
|
}
|
|
49700
49769
|
}
|
|
49701
49770
|
function validatePaths(paths) {
|
|
49702
49771
|
if (!Array.isArray(paths)) {
|
|
49703
49772
|
throw new TypeError("paths must be an array");
|
|
49704
49773
|
}
|
|
49705
|
-
for (const
|
|
49706
|
-
validatePath(
|
|
49774
|
+
for (const path26 of paths) {
|
|
49775
|
+
validatePath(path26);
|
|
49707
49776
|
}
|
|
49708
49777
|
}
|
|
49709
49778
|
function slowRedact(options = {}) {
|
|
@@ -49871,8 +49940,8 @@ var require_redaction = __commonJS({
|
|
|
49871
49940
|
if (shape[k] === null) {
|
|
49872
49941
|
o[k] = (value) => topCensor(value, [k]);
|
|
49873
49942
|
} else {
|
|
49874
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
49875
|
-
return censor(value, [k, ...
|
|
49943
|
+
const wrappedCensor = typeof censor === "function" ? (value, path26) => {
|
|
49944
|
+
return censor(value, [k, ...path26]);
|
|
49876
49945
|
} : censor;
|
|
49877
49946
|
o[k] = Redact({
|
|
49878
49947
|
paths: shape[k],
|
|
@@ -50090,10 +50159,10 @@ var require_atomic_sleep = __commonJS({
|
|
|
50090
50159
|
var require_sonic_boom = __commonJS({
|
|
50091
50160
|
"node_modules/sonic-boom/index.js"(exports, module) {
|
|
50092
50161
|
"use strict";
|
|
50093
|
-
var
|
|
50162
|
+
var fs24 = __require("fs");
|
|
50094
50163
|
var EventEmitter = __require("events");
|
|
50095
50164
|
var inherits = __require("util").inherits;
|
|
50096
|
-
var
|
|
50165
|
+
var path26 = __require("path");
|
|
50097
50166
|
var sleep4 = require_atomic_sleep();
|
|
50098
50167
|
var assert2 = __require("assert");
|
|
50099
50168
|
var BUSY_WRITE_TIMEOUT = 100;
|
|
@@ -50147,20 +50216,20 @@ var require_sonic_boom = __commonJS({
|
|
|
50147
50216
|
const mode = sonic.mode;
|
|
50148
50217
|
if (sonic.sync) {
|
|
50149
50218
|
try {
|
|
50150
|
-
if (sonic.mkdir)
|
|
50151
|
-
const fd =
|
|
50219
|
+
if (sonic.mkdir) fs24.mkdirSync(path26.dirname(file), { recursive: true });
|
|
50220
|
+
const fd = fs24.openSync(file, flags, mode);
|
|
50152
50221
|
fileOpened(null, fd);
|
|
50153
50222
|
} catch (err) {
|
|
50154
50223
|
fileOpened(err);
|
|
50155
50224
|
throw err;
|
|
50156
50225
|
}
|
|
50157
50226
|
} else if (sonic.mkdir) {
|
|
50158
|
-
|
|
50227
|
+
fs24.mkdir(path26.dirname(file), { recursive: true }, (err) => {
|
|
50159
50228
|
if (err) return fileOpened(err);
|
|
50160
|
-
|
|
50229
|
+
fs24.open(file, flags, mode, fileOpened);
|
|
50161
50230
|
});
|
|
50162
50231
|
} else {
|
|
50163
|
-
|
|
50232
|
+
fs24.open(file, flags, mode, fileOpened);
|
|
50164
50233
|
}
|
|
50165
50234
|
}
|
|
50166
50235
|
function SonicBoom(opts) {
|
|
@@ -50201,8 +50270,8 @@ var require_sonic_boom = __commonJS({
|
|
|
50201
50270
|
this.flush = flushBuffer;
|
|
50202
50271
|
this.flushSync = flushBufferSync;
|
|
50203
50272
|
this._actualWrite = actualWriteBuffer;
|
|
50204
|
-
fsWriteSync = () =>
|
|
50205
|
-
fsWrite = () =>
|
|
50273
|
+
fsWriteSync = () => fs24.writeSync(this.fd, this._writingBuf);
|
|
50274
|
+
fsWrite = () => fs24.write(this.fd, this._writingBuf, this.release);
|
|
50206
50275
|
} else if (contentMode === void 0 || contentMode === kContentModeUtf8) {
|
|
50207
50276
|
this._writingBuf = "";
|
|
50208
50277
|
this.write = write;
|
|
@@ -50211,15 +50280,15 @@ var require_sonic_boom = __commonJS({
|
|
|
50211
50280
|
this._actualWrite = actualWrite;
|
|
50212
50281
|
fsWriteSync = () => {
|
|
50213
50282
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
50214
|
-
return
|
|
50283
|
+
return fs24.writeSync(this.fd, this._writingBuf);
|
|
50215
50284
|
}
|
|
50216
|
-
return
|
|
50285
|
+
return fs24.writeSync(this.fd, this._writingBuf, "utf8");
|
|
50217
50286
|
};
|
|
50218
50287
|
fsWrite = () => {
|
|
50219
50288
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
50220
|
-
return
|
|
50289
|
+
return fs24.write(this.fd, this._writingBuf, this.release);
|
|
50221
50290
|
}
|
|
50222
|
-
return
|
|
50291
|
+
return fs24.write(this.fd, this._writingBuf, "utf8", this.release);
|
|
50223
50292
|
};
|
|
50224
50293
|
} else {
|
|
50225
50294
|
throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
|
|
@@ -50276,7 +50345,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50276
50345
|
}
|
|
50277
50346
|
}
|
|
50278
50347
|
if (this._fsync) {
|
|
50279
|
-
|
|
50348
|
+
fs24.fsyncSync(this.fd);
|
|
50280
50349
|
}
|
|
50281
50350
|
const len = this._len;
|
|
50282
50351
|
if (this._reopening) {
|
|
@@ -50390,7 +50459,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50390
50459
|
const onDrain = () => {
|
|
50391
50460
|
if (!this._fsync) {
|
|
50392
50461
|
try {
|
|
50393
|
-
|
|
50462
|
+
fs24.fsync(this.fd, (err) => {
|
|
50394
50463
|
this._flushPending = false;
|
|
50395
50464
|
cb(err);
|
|
50396
50465
|
});
|
|
@@ -50492,7 +50561,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50492
50561
|
const fd = this.fd;
|
|
50493
50562
|
this.once("ready", () => {
|
|
50494
50563
|
if (fd !== this.fd) {
|
|
50495
|
-
|
|
50564
|
+
fs24.close(fd, (err) => {
|
|
50496
50565
|
if (err) {
|
|
50497
50566
|
return this.emit("error", err);
|
|
50498
50567
|
}
|
|
@@ -50541,7 +50610,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50541
50610
|
buf = this._bufs[0];
|
|
50542
50611
|
}
|
|
50543
50612
|
try {
|
|
50544
|
-
const n = Buffer.isBuffer(buf) ?
|
|
50613
|
+
const n = Buffer.isBuffer(buf) ? fs24.writeSync(this.fd, buf) : fs24.writeSync(this.fd, buf, "utf8");
|
|
50545
50614
|
const releasedBufObj = releaseWritingBuf(buf, this._len, n);
|
|
50546
50615
|
buf = releasedBufObj.writingBuf;
|
|
50547
50616
|
this._len = releasedBufObj.len;
|
|
@@ -50557,7 +50626,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50557
50626
|
}
|
|
50558
50627
|
}
|
|
50559
50628
|
try {
|
|
50560
|
-
|
|
50629
|
+
fs24.fsyncSync(this.fd);
|
|
50561
50630
|
} catch {
|
|
50562
50631
|
}
|
|
50563
50632
|
}
|
|
@@ -50578,7 +50647,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50578
50647
|
buf = mergeBuf(this._bufs[0], this._lens[0]);
|
|
50579
50648
|
}
|
|
50580
50649
|
try {
|
|
50581
|
-
const n =
|
|
50650
|
+
const n = fs24.writeSync(this.fd, buf);
|
|
50582
50651
|
buf = buf.subarray(n);
|
|
50583
50652
|
this._len = Math.max(this._len - n, 0);
|
|
50584
50653
|
if (buf.length <= 0) {
|
|
@@ -50606,13 +50675,13 @@ var require_sonic_boom = __commonJS({
|
|
|
50606
50675
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : this._bufs.shift() || "";
|
|
50607
50676
|
if (this.sync) {
|
|
50608
50677
|
try {
|
|
50609
|
-
const written = Buffer.isBuffer(this._writingBuf) ?
|
|
50678
|
+
const written = Buffer.isBuffer(this._writingBuf) ? fs24.writeSync(this.fd, this._writingBuf) : fs24.writeSync(this.fd, this._writingBuf, "utf8");
|
|
50610
50679
|
release(null, written);
|
|
50611
50680
|
} catch (err) {
|
|
50612
50681
|
release(err);
|
|
50613
50682
|
}
|
|
50614
50683
|
} else {
|
|
50615
|
-
|
|
50684
|
+
fs24.write(this.fd, this._writingBuf, release);
|
|
50616
50685
|
}
|
|
50617
50686
|
}
|
|
50618
50687
|
function actualWriteBuffer() {
|
|
@@ -50621,7 +50690,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50621
50690
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
|
|
50622
50691
|
if (this.sync) {
|
|
50623
50692
|
try {
|
|
50624
|
-
const written =
|
|
50693
|
+
const written = fs24.writeSync(this.fd, this._writingBuf);
|
|
50625
50694
|
release(null, written);
|
|
50626
50695
|
} catch (err) {
|
|
50627
50696
|
release(err);
|
|
@@ -50630,7 +50699,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50630
50699
|
if (kCopyBuffer) {
|
|
50631
50700
|
this._writingBuf = Buffer.from(this._writingBuf);
|
|
50632
50701
|
}
|
|
50633
|
-
|
|
50702
|
+
fs24.write(this.fd, this._writingBuf, release);
|
|
50634
50703
|
}
|
|
50635
50704
|
}
|
|
50636
50705
|
function actualClose(sonic) {
|
|
@@ -50646,12 +50715,12 @@ var require_sonic_boom = __commonJS({
|
|
|
50646
50715
|
sonic._lens = [];
|
|
50647
50716
|
assert2(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
|
|
50648
50717
|
try {
|
|
50649
|
-
|
|
50718
|
+
fs24.fsync(sonic.fd, closeWrapped);
|
|
50650
50719
|
} catch {
|
|
50651
50720
|
}
|
|
50652
50721
|
function closeWrapped() {
|
|
50653
50722
|
if (sonic.fd !== 1 && sonic.fd !== 2) {
|
|
50654
|
-
|
|
50723
|
+
fs24.close(sonic.fd, done);
|
|
50655
50724
|
} else {
|
|
50656
50725
|
done();
|
|
50657
50726
|
}
|
|
@@ -51487,15 +51556,15 @@ var require_transport = __commonJS({
|
|
|
51487
51556
|
if (!unquoted) {
|
|
51488
51557
|
return false;
|
|
51489
51558
|
}
|
|
51490
|
-
let
|
|
51491
|
-
if (
|
|
51559
|
+
let path26 = unquoted;
|
|
51560
|
+
if (path26.startsWith("file://")) {
|
|
51492
51561
|
try {
|
|
51493
|
-
|
|
51562
|
+
path26 = fileURLToPath(path26);
|
|
51494
51563
|
} catch {
|
|
51495
51564
|
return false;
|
|
51496
51565
|
}
|
|
51497
51566
|
}
|
|
51498
|
-
return isAbsolute(
|
|
51567
|
+
return isAbsolute(path26) && !existsSync(path26);
|
|
51499
51568
|
}
|
|
51500
51569
|
function stripQuotes(value) {
|
|
51501
51570
|
const first = value[0];
|
|
@@ -53189,7 +53258,7 @@ var require_multistream = __commonJS({
|
|
|
53189
53258
|
var require_pino = __commonJS({
|
|
53190
53259
|
"node_modules/pino/pino.js"(exports, module) {
|
|
53191
53260
|
"use strict";
|
|
53192
|
-
var
|
|
53261
|
+
var os18 = __require("node:os");
|
|
53193
53262
|
var stdSerializers = require_pino_std_serializers();
|
|
53194
53263
|
var caller = require_caller();
|
|
53195
53264
|
var redaction = require_redaction();
|
|
@@ -53236,7 +53305,7 @@ var require_pino = __commonJS({
|
|
|
53236
53305
|
} = symbols;
|
|
53237
53306
|
var { epochTime, nullTime } = time3;
|
|
53238
53307
|
var { pid } = process;
|
|
53239
|
-
var hostname2 =
|
|
53308
|
+
var hostname2 = os18.hostname();
|
|
53240
53309
|
var defaultErrorSerializer = stdSerializers.err;
|
|
53241
53310
|
var defaultOptions2 = {
|
|
53242
53311
|
level: "info",
|
|
@@ -85562,15 +85631,15 @@ var require_tools2 = __commonJS({
|
|
|
85562
85631
|
* @param {String} path - Mailbox path to encode
|
|
85563
85632
|
* @returns {String} Encoded mailbox path
|
|
85564
85633
|
*/
|
|
85565
|
-
encodePath(connection,
|
|
85566
|
-
|
|
85567
|
-
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(
|
|
85634
|
+
encodePath(connection, path26) {
|
|
85635
|
+
path26 = (path26 || "").toString();
|
|
85636
|
+
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(path26)) {
|
|
85568
85637
|
try {
|
|
85569
|
-
|
|
85638
|
+
path26 = iconv.encode(path26, "utf-7-imap").toString();
|
|
85570
85639
|
} catch {
|
|
85571
85640
|
}
|
|
85572
85641
|
}
|
|
85573
|
-
return
|
|
85642
|
+
return path26;
|
|
85574
85643
|
},
|
|
85575
85644
|
/**
|
|
85576
85645
|
* Decodes a mailbox path from modified UTF-7 if the server does not support UTF8=ACCEPT.
|
|
@@ -85579,15 +85648,15 @@ var require_tools2 = __commonJS({
|
|
|
85579
85648
|
* @param {String} path - Mailbox path to decode
|
|
85580
85649
|
* @returns {String} Decoded mailbox path
|
|
85581
85650
|
*/
|
|
85582
|
-
decodePath(connection,
|
|
85583
|
-
|
|
85584
|
-
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(
|
|
85651
|
+
decodePath(connection, path26) {
|
|
85652
|
+
path26 = (path26 || "").toString();
|
|
85653
|
+
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(path26)) {
|
|
85585
85654
|
try {
|
|
85586
|
-
|
|
85655
|
+
path26 = iconv.decode(Buffer.from(path26), "utf-7-imap").toString();
|
|
85587
85656
|
} catch {
|
|
85588
85657
|
}
|
|
85589
85658
|
}
|
|
85590
|
-
return
|
|
85659
|
+
return path26;
|
|
85591
85660
|
},
|
|
85592
85661
|
/**
|
|
85593
85662
|
* Normalizes a mailbox path by joining array segments with the namespace delimiter,
|
|
@@ -85598,17 +85667,17 @@ var require_tools2 = __commonJS({
|
|
|
85598
85667
|
* @param {Boolean} [skipNamespace] - If true, skips prepending the namespace prefix
|
|
85599
85668
|
* @returns {String} Normalized mailbox path
|
|
85600
85669
|
*/
|
|
85601
|
-
normalizePath(connection,
|
|
85602
|
-
if (Array.isArray(
|
|
85603
|
-
|
|
85670
|
+
normalizePath(connection, path26, skipNamespace) {
|
|
85671
|
+
if (Array.isArray(path26)) {
|
|
85672
|
+
path26 = path26.join(connection.namespace && connection.namespace.delimiter || "");
|
|
85604
85673
|
}
|
|
85605
|
-
if (
|
|
85674
|
+
if (path26.toUpperCase() === "INBOX") {
|
|
85606
85675
|
return "INBOX";
|
|
85607
85676
|
}
|
|
85608
|
-
if (!skipNamespace && connection.namespace && connection.namespace.prefix && !
|
|
85609
|
-
|
|
85677
|
+
if (!skipNamespace && connection.namespace && connection.namespace.prefix && !path26.startsWith(connection.namespace.prefix)) {
|
|
85678
|
+
path26 = connection.namespace.prefix + path26;
|
|
85610
85679
|
}
|
|
85611
|
-
return
|
|
85680
|
+
return path26;
|
|
85612
85681
|
},
|
|
85613
85682
|
/**
|
|
85614
85683
|
* Compares two mailbox paths for equality after normalization.
|
|
@@ -85939,14 +86008,14 @@ var require_tools2 = __commonJS({
|
|
|
85939
86008
|
}
|
|
85940
86009
|
}
|
|
85941
86010
|
if (map.emailId || map.uid) {
|
|
85942
|
-
let
|
|
85943
|
-
if (/[\u0080-\uffff]/.test(
|
|
86011
|
+
let path26 = mailbox.path;
|
|
86012
|
+
if (/[\u0080-\uffff]/.test(path26)) {
|
|
85944
86013
|
try {
|
|
85945
|
-
|
|
86014
|
+
path26 = iconv.encode(path26, "utf-7-imap").toString();
|
|
85946
86015
|
} catch {
|
|
85947
86016
|
}
|
|
85948
86017
|
}
|
|
85949
|
-
map.id = map.emailId || createHash2("md5").update([
|
|
86018
|
+
map.id = map.emailId || createHash2("md5").update([path26, mailbox.uidValidity?.toString() || "", map.uid.toString()].join(":")).digest("hex");
|
|
85950
86019
|
}
|
|
85951
86020
|
if (map.flags) {
|
|
85952
86021
|
let flagColor = tools.getFlagColor(map.flags);
|
|
@@ -86121,16 +86190,16 @@ var require_tools2 = __commonJS({
|
|
|
86121
86190
|
* @returns {Object} Parsed body structure tree with part numbers, types, parameters, and child nodes
|
|
86122
86191
|
*/
|
|
86123
86192
|
parseBodystructure(entry) {
|
|
86124
|
-
let walk = (node,
|
|
86125
|
-
|
|
86193
|
+
let walk = (node, path26) => {
|
|
86194
|
+
path26 = path26 || [];
|
|
86126
86195
|
let curNode = {}, i = 0, part = 0;
|
|
86127
|
-
if (
|
|
86128
|
-
curNode.part =
|
|
86196
|
+
if (path26.length) {
|
|
86197
|
+
curNode.part = path26.join(".");
|
|
86129
86198
|
}
|
|
86130
86199
|
if (Array.isArray(node[0])) {
|
|
86131
86200
|
curNode.childNodes = [];
|
|
86132
86201
|
while (Array.isArray(node[i])) {
|
|
86133
|
-
curNode.childNodes.push(walk(node[i],
|
|
86202
|
+
curNode.childNodes.push(walk(node[i], path26.concat(++part)));
|
|
86134
86203
|
i++;
|
|
86135
86204
|
}
|
|
86136
86205
|
curNode.type = "multipart/" + ((node[i++] || {}).value || "").toString().toLowerCase();
|
|
@@ -86173,7 +86242,7 @@ var require_tools2 = __commonJS({
|
|
|
86173
86242
|
// the encapsulated message shares the part number with its wrapper.
|
|
86174
86243
|
// Distinction is via suffixes: path.MIME = wrapper headers,
|
|
86175
86244
|
// path.HEADER = encapsulated message headers.
|
|
86176
|
-
walk(node[i],
|
|
86245
|
+
walk(node[i], path26)
|
|
86177
86246
|
];
|
|
86178
86247
|
}
|
|
86179
86248
|
i++;
|
|
@@ -88135,14 +88204,14 @@ var require_select = __commonJS({
|
|
|
88135
88204
|
// update into a silent no-op for the rest of the session.
|
|
88136
88205
|
permanentflags: { key: "permanentFlags", parse: (value) => Array.isArray(value) && new Set(value) }
|
|
88137
88206
|
});
|
|
88138
|
-
module.exports = async (connection,
|
|
88207
|
+
module.exports = async (connection, path26, options) => {
|
|
88139
88208
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88140
88209
|
return;
|
|
88141
88210
|
}
|
|
88142
88211
|
options = options || {};
|
|
88143
|
-
|
|
88144
|
-
if (!connection.folders.has(
|
|
88145
|
-
let folders = await connection.run("LIST", "",
|
|
88212
|
+
path26 = normalizePath(connection, path26);
|
|
88213
|
+
if (!connection.folders.has(path26)) {
|
|
88214
|
+
let folders = await connection.run("LIST", "", path26);
|
|
88146
88215
|
if (!folders) {
|
|
88147
88216
|
throw new Error("Failed to fetch folders");
|
|
88148
88217
|
}
|
|
@@ -88150,10 +88219,10 @@ var require_select = __commonJS({
|
|
|
88150
88219
|
connection.folders.set(folder.path, folder);
|
|
88151
88220
|
});
|
|
88152
88221
|
}
|
|
88153
|
-
let folderListData = connection.folders.has(
|
|
88222
|
+
let folderListData = connection.folders.has(path26) ? connection.folders.get(path26) : false;
|
|
88154
88223
|
let response;
|
|
88155
88224
|
try {
|
|
88156
|
-
let map = { path:
|
|
88225
|
+
let map = { path: path26 };
|
|
88157
88226
|
if (folderListData) {
|
|
88158
88227
|
["delimiter", "specialUse", "subscribed", "listed"].forEach((key) => {
|
|
88159
88228
|
if (folderListData[key]) {
|
|
@@ -88172,7 +88241,7 @@ var require_select = __commonJS({
|
|
|
88172
88241
|
]);
|
|
88173
88242
|
map.qresync = true;
|
|
88174
88243
|
}
|
|
88175
|
-
let encodedPath = encodePath(connection,
|
|
88244
|
+
let encodedPath = encodePath(connection, path26);
|
|
88176
88245
|
let selectCommand = {
|
|
88177
88246
|
command: !options.readOnly ? "SELECT" : "EXAMINE",
|
|
88178
88247
|
/* c8 ignore next */
|
|
@@ -88232,12 +88301,12 @@ var require_select = __commonJS({
|
|
|
88232
88301
|
// since the client's last known state. Only received when QRESYNC was requested.
|
|
88233
88302
|
// A dummy mailbox object is passed because the mailbox isn't officially open yet.
|
|
88234
88303
|
VANISHED: async (untagged) => {
|
|
88235
|
-
await connection.untaggedVanished(untagged, { path:
|
|
88304
|
+
await connection.untaggedVanished(untagged, { path: path26, uidNext: false, uidValidity: false });
|
|
88236
88305
|
},
|
|
88237
88306
|
// Untagged FETCH during SELECT/EXAMINE: only occurs with QRESYNC, delivering
|
|
88238
88307
|
// updated flags for messages that changed since the client's last modseq.
|
|
88239
88308
|
FETCH: async (untagged) => {
|
|
88240
|
-
await connection.untaggedFetch(untagged, { path:
|
|
88309
|
+
await connection.untaggedFetch(untagged, { path: path26, uidNext: false, uidValidity: false });
|
|
88241
88310
|
}
|
|
88242
88311
|
}
|
|
88243
88312
|
});
|
|
@@ -88251,13 +88320,13 @@ var require_select = __commonJS({
|
|
|
88251
88320
|
}
|
|
88252
88321
|
let currentMailbox = connection.mailbox;
|
|
88253
88322
|
connection.mailbox = false;
|
|
88254
|
-
if (currentMailbox && currentMailbox.path !==
|
|
88323
|
+
if (currentMailbox && currentMailbox.path !== path26) {
|
|
88255
88324
|
connection.emit("mailboxClose", currentMailbox);
|
|
88256
88325
|
}
|
|
88257
88326
|
connection.mailbox = map;
|
|
88258
88327
|
connection.currentSelectCommand = selectCommand;
|
|
88259
88328
|
connection.state = connection.states.SELECTED;
|
|
88260
|
-
if (!currentMailbox || currentMailbox.path !==
|
|
88329
|
+
if (!currentMailbox || currentMailbox.path !== path26) {
|
|
88261
88330
|
connection.emit("mailboxOpen", connection.mailbox);
|
|
88262
88331
|
}
|
|
88263
88332
|
response.next();
|
|
@@ -88472,17 +88541,17 @@ var require_create = __commonJS({
|
|
|
88472
88541
|
"node_modules/imapflow/lib/commands/create.js"(exports, module) {
|
|
88473
88542
|
"use strict";
|
|
88474
88543
|
var { encodePath, normalizePath, getStatusCode, enhanceCommandError } = require_tools2();
|
|
88475
|
-
module.exports = async (connection,
|
|
88544
|
+
module.exports = async (connection, path26) => {
|
|
88476
88545
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88477
88546
|
return;
|
|
88478
88547
|
}
|
|
88479
|
-
|
|
88548
|
+
path26 = normalizePath(connection, path26);
|
|
88480
88549
|
let response;
|
|
88481
88550
|
try {
|
|
88482
88551
|
let map = {
|
|
88483
|
-
path:
|
|
88552
|
+
path: path26
|
|
88484
88553
|
};
|
|
88485
|
-
response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection,
|
|
88554
|
+
response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection, path26) }]);
|
|
88486
88555
|
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;
|
|
88487
88556
|
if (section) {
|
|
88488
88557
|
let key;
|
|
@@ -88508,13 +88577,13 @@ var require_create = __commonJS({
|
|
|
88508
88577
|
}
|
|
88509
88578
|
map.created = true;
|
|
88510
88579
|
response.next();
|
|
88511
|
-
await connection.run("SUBSCRIBE",
|
|
88580
|
+
await connection.run("SUBSCRIBE", path26);
|
|
88512
88581
|
return map;
|
|
88513
88582
|
} catch (err) {
|
|
88514
88583
|
let errorCode = getStatusCode(err.response);
|
|
88515
88584
|
if (errorCode === "ALREADYEXISTS") {
|
|
88516
88585
|
return {
|
|
88517
|
-
path:
|
|
88586
|
+
path: path26,
|
|
88518
88587
|
created: false
|
|
88519
88588
|
};
|
|
88520
88589
|
}
|
|
@@ -88531,20 +88600,20 @@ var require_delete = __commonJS({
|
|
|
88531
88600
|
"node_modules/imapflow/lib/commands/delete.js"(exports, module) {
|
|
88532
88601
|
"use strict";
|
|
88533
88602
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88534
|
-
module.exports = async (connection,
|
|
88603
|
+
module.exports = async (connection, path26) => {
|
|
88535
88604
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88536
88605
|
return;
|
|
88537
88606
|
}
|
|
88538
|
-
|
|
88539
|
-
if (connection.state === connection.states.SELECTED && connection.mailbox.path ===
|
|
88607
|
+
path26 = normalizePath(connection, path26);
|
|
88608
|
+
if (connection.state === connection.states.SELECTED && connection.mailbox.path === path26) {
|
|
88540
88609
|
await connection.run("CLOSE");
|
|
88541
88610
|
}
|
|
88542
88611
|
let response;
|
|
88543
88612
|
try {
|
|
88544
88613
|
let map = {
|
|
88545
|
-
path:
|
|
88614
|
+
path: path26
|
|
88546
88615
|
};
|
|
88547
|
-
response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection,
|
|
88616
|
+
response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection, path26) }]);
|
|
88548
88617
|
response.next();
|
|
88549
88618
|
return map;
|
|
88550
88619
|
} catch (err) {
|
|
@@ -88561,23 +88630,23 @@ var require_rename = __commonJS({
|
|
|
88561
88630
|
"node_modules/imapflow/lib/commands/rename.js"(exports, module) {
|
|
88562
88631
|
"use strict";
|
|
88563
88632
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88564
|
-
module.exports = async (connection,
|
|
88633
|
+
module.exports = async (connection, path26, newPath) => {
|
|
88565
88634
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88566
88635
|
return;
|
|
88567
88636
|
}
|
|
88568
|
-
|
|
88637
|
+
path26 = normalizePath(connection, path26);
|
|
88569
88638
|
newPath = normalizePath(connection, newPath);
|
|
88570
|
-
if (connection.state === connection.states.SELECTED && connection.mailbox.path ===
|
|
88639
|
+
if (connection.state === connection.states.SELECTED && connection.mailbox.path === path26) {
|
|
88571
88640
|
await connection.run("CLOSE");
|
|
88572
88641
|
}
|
|
88573
88642
|
let response;
|
|
88574
88643
|
try {
|
|
88575
88644
|
let map = {
|
|
88576
|
-
path:
|
|
88645
|
+
path: path26,
|
|
88577
88646
|
newPath
|
|
88578
88647
|
};
|
|
88579
88648
|
response = await connection.exec("RENAME", [
|
|
88580
|
-
{ type: "ATOM", value: encodePath(connection,
|
|
88649
|
+
{ type: "ATOM", value: encodePath(connection, path26) },
|
|
88581
88650
|
{ type: "ATOM", value: encodePath(connection, newPath) }
|
|
88582
88651
|
]);
|
|
88583
88652
|
response.next();
|
|
@@ -88624,14 +88693,14 @@ var require_subscribe = __commonJS({
|
|
|
88624
88693
|
"node_modules/imapflow/lib/commands/subscribe.js"(exports, module) {
|
|
88625
88694
|
"use strict";
|
|
88626
88695
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88627
|
-
module.exports = async (connection,
|
|
88696
|
+
module.exports = async (connection, path26) => {
|
|
88628
88697
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88629
88698
|
return;
|
|
88630
88699
|
}
|
|
88631
|
-
|
|
88700
|
+
path26 = normalizePath(connection, path26);
|
|
88632
88701
|
let response;
|
|
88633
88702
|
try {
|
|
88634
|
-
response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection,
|
|
88703
|
+
response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path26) }]);
|
|
88635
88704
|
response.next();
|
|
88636
88705
|
return true;
|
|
88637
88706
|
} catch (err) {
|
|
@@ -88648,14 +88717,14 @@ var require_unsubscribe = __commonJS({
|
|
|
88648
88717
|
"node_modules/imapflow/lib/commands/unsubscribe.js"(exports, module) {
|
|
88649
88718
|
"use strict";
|
|
88650
88719
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88651
|
-
module.exports = async (connection,
|
|
88720
|
+
module.exports = async (connection, path26) => {
|
|
88652
88721
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88653
88722
|
return;
|
|
88654
88723
|
}
|
|
88655
|
-
|
|
88724
|
+
path26 = normalizePath(connection, path26);
|
|
88656
88725
|
let response;
|
|
88657
88726
|
try {
|
|
88658
|
-
response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection,
|
|
88727
|
+
response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path26) }]);
|
|
88659
88728
|
response.next();
|
|
88660
88729
|
return true;
|
|
88661
88730
|
} catch (err) {
|
|
@@ -89461,11 +89530,11 @@ var require_status = __commonJS({
|
|
|
89461
89530
|
var { encodePath, normalizePath, buildStatusQueryAttributes, isRev2Active } = require_tools2();
|
|
89462
89531
|
var { parseStatusList } = require_status_fields();
|
|
89463
89532
|
var MAILBOX_UPDATERS = {
|
|
89464
|
-
messages: (value, connection,
|
|
89533
|
+
messages: (value, connection, path26) => {
|
|
89465
89534
|
let prevCount = connection.mailbox.exists;
|
|
89466
89535
|
if (prevCount !== value) {
|
|
89467
89536
|
connection.mailbox.exists = value;
|
|
89468
|
-
connection.emit("exists", { path:
|
|
89537
|
+
connection.emit("exists", { path: path26, count: value, prevCount });
|
|
89469
89538
|
}
|
|
89470
89539
|
},
|
|
89471
89540
|
uidNext: (value, connection) => {
|
|
@@ -89475,28 +89544,28 @@ var require_status = __commonJS({
|
|
|
89475
89544
|
connection.mailbox.highestModseq = value;
|
|
89476
89545
|
}
|
|
89477
89546
|
};
|
|
89478
|
-
module.exports = async (connection,
|
|
89479
|
-
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !
|
|
89547
|
+
module.exports = async (connection, path26, query) => {
|
|
89548
|
+
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path26) {
|
|
89480
89549
|
return false;
|
|
89481
89550
|
}
|
|
89482
|
-
|
|
89483
|
-
let encodedPath = encodePath(connection,
|
|
89551
|
+
path26 = normalizePath(connection, path26);
|
|
89552
|
+
let encodedPath = encodePath(connection, path26);
|
|
89484
89553
|
let attributes = [{ type: encodedPath.indexOf("&") >= 0 ? "STRING" : "ATOM", value: encodedPath }];
|
|
89485
89554
|
let queryAttributes = buildStatusQueryAttributes(connection, query);
|
|
89486
89555
|
let syntheticRecent = query && query.recent && isRev2Active(connection);
|
|
89487
89556
|
if (!queryAttributes.length) {
|
|
89488
|
-
return syntheticRecent ? { path:
|
|
89557
|
+
return syntheticRecent ? { path: path26, recent: 0 } : false;
|
|
89489
89558
|
}
|
|
89490
89559
|
attributes.push(queryAttributes);
|
|
89491
89560
|
let response;
|
|
89492
89561
|
try {
|
|
89493
|
-
let map = { path:
|
|
89562
|
+
let map = { path: path26 };
|
|
89494
89563
|
response = await connection.exec("STATUS", attributes, {
|
|
89495
89564
|
untagged: {
|
|
89496
89565
|
// STATUS response: * STATUS <mailbox> (<key> <value> <key> <value> ...)
|
|
89497
89566
|
// Parsed as alternating key-value pairs (i % 2 pattern).
|
|
89498
89567
|
STATUS: async (untagged) => {
|
|
89499
|
-
let updateCurrent = connection.state === connection.states.SELECTED &&
|
|
89568
|
+
let updateCurrent = connection.state === connection.states.SELECTED && path26 === connection.mailbox.path;
|
|
89500
89569
|
let list = untagged.attributes && Array.isArray(untagged.attributes[1]) ? untagged.attributes[1] : false;
|
|
89501
89570
|
if (!list) {
|
|
89502
89571
|
return;
|
|
@@ -89504,7 +89573,7 @@ var require_status = __commonJS({
|
|
|
89504
89573
|
parseStatusList(list, (key, value) => {
|
|
89505
89574
|
map[key] = value;
|
|
89506
89575
|
if (updateCurrent && MAILBOX_UPDATERS[key]) {
|
|
89507
|
-
MAILBOX_UPDATERS[key](value, connection,
|
|
89576
|
+
MAILBOX_UPDATERS[key](value, connection, path26);
|
|
89508
89577
|
}
|
|
89509
89578
|
});
|
|
89510
89579
|
}
|
|
@@ -89517,9 +89586,9 @@ var require_status = __commonJS({
|
|
|
89517
89586
|
return map;
|
|
89518
89587
|
} catch (err) {
|
|
89519
89588
|
if (err.responseStatus === "NO") {
|
|
89520
|
-
let folders = await connection.run("LIST", "",
|
|
89589
|
+
let folders = await connection.run("LIST", "", path26, { listOnly: true });
|
|
89521
89590
|
if (folders && !folders.length) {
|
|
89522
|
-
let error2 = new Error(`Mailbox doesn't exist: ${
|
|
89591
|
+
let error2 = new Error(`Mailbox doesn't exist: ${path26}`);
|
|
89523
89592
|
error2.code = "NotFound";
|
|
89524
89593
|
error2.response = err;
|
|
89525
89594
|
throw error2;
|
|
@@ -89666,15 +89735,15 @@ var require_quota = __commonJS({
|
|
|
89666
89735
|
"node_modules/imapflow/lib/commands/quota.js"(exports, module) {
|
|
89667
89736
|
"use strict";
|
|
89668
89737
|
var { encodePath, normalizePath, enhanceCommandError, parseUintValue, isUnsafeKey } = require_tools2();
|
|
89669
|
-
module.exports = async (connection,
|
|
89670
|
-
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !
|
|
89738
|
+
module.exports = async (connection, path26) => {
|
|
89739
|
+
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path26) {
|
|
89671
89740
|
return;
|
|
89672
89741
|
}
|
|
89673
89742
|
if (!connection.capabilities.has("QUOTA")) {
|
|
89674
89743
|
return false;
|
|
89675
89744
|
}
|
|
89676
|
-
|
|
89677
|
-
let map = { path:
|
|
89745
|
+
path26 = normalizePath(connection, path26);
|
|
89746
|
+
let map = { path: path26 };
|
|
89678
89747
|
let processQuotaResponse = (untagged) => {
|
|
89679
89748
|
let attributes = untagged.attributes && untagged.attributes[1];
|
|
89680
89749
|
if (!attributes || !attributes.length) {
|
|
@@ -89714,7 +89783,7 @@ var require_quota = __commonJS({
|
|
|
89714
89783
|
let quotaFound = false;
|
|
89715
89784
|
let response;
|
|
89716
89785
|
try {
|
|
89717
|
-
response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection,
|
|
89786
|
+
response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection, path26) }], {
|
|
89718
89787
|
untagged: {
|
|
89719
89788
|
// QUOTAROOT response tells us which quota root applies to this mailbox.
|
|
89720
89789
|
// A mailbox may have zero or one quota root.
|
|
@@ -89857,15 +89926,15 @@ var require_idle = __commonJS({
|
|
|
89857
89926
|
}
|
|
89858
89927
|
}
|
|
89859
89928
|
async function pollOnce2(connection, session) {
|
|
89860
|
-
let
|
|
89929
|
+
let path26 = connection.mailbox && connection.mailbox.path;
|
|
89861
89930
|
switch (connection.missingIdleCommand) {
|
|
89862
89931
|
case "SELECT":
|
|
89863
89932
|
connection.log.debug({ src: "c", msg: `Running SELECT to detect changes in folder`, cid: connection.id });
|
|
89864
|
-
await connection.runInternal("SELECT",
|
|
89933
|
+
await connection.runInternal("SELECT", path26, { readOnly: session.selectCommand.command === "EXAMINE" });
|
|
89865
89934
|
break;
|
|
89866
89935
|
case "STATUS": {
|
|
89867
89936
|
connection.log.debug({ src: "c", msg: `Running STATUS to detect changes in folder`, cid: connection.id });
|
|
89868
|
-
let status = await connection.runInternal("STATUS",
|
|
89937
|
+
let status = await connection.runInternal("STATUS", path26, {
|
|
89869
89938
|
messages: true,
|
|
89870
89939
|
uidNext: true,
|
|
89871
89940
|
uidValidity: true,
|
|
@@ -91552,12 +91621,12 @@ var require_imap_flow = __commonJS({
|
|
|
91552
91621
|
this.emit("flags", updateEvent);
|
|
91553
91622
|
}
|
|
91554
91623
|
}
|
|
91555
|
-
async ensureSelectedMailbox(
|
|
91556
|
-
if (!
|
|
91624
|
+
async ensureSelectedMailbox(path26) {
|
|
91625
|
+
if (!path26) {
|
|
91557
91626
|
return false;
|
|
91558
91627
|
}
|
|
91559
|
-
if (!this.mailbox || !comparePaths(this, this.mailbox.path,
|
|
91560
|
-
return await this.mailboxOpen(
|
|
91628
|
+
if (!this.mailbox || !comparePaths(this, this.mailbox.path, path26)) {
|
|
91629
|
+
return await this.mailboxOpen(path26);
|
|
91561
91630
|
}
|
|
91562
91631
|
return true;
|
|
91563
91632
|
}
|
|
@@ -91972,9 +92041,9 @@ var require_imap_flow = __commonJS({
|
|
|
91972
92041
|
* let quota = await client.getQuota();
|
|
91973
92042
|
* console.log(quota.storage.used, quota.storage.limit)
|
|
91974
92043
|
*/
|
|
91975
|
-
async getQuota(
|
|
91976
|
-
|
|
91977
|
-
return await this.run("QUOTA",
|
|
92044
|
+
async getQuota(path26) {
|
|
92045
|
+
path26 = path26 || "INBOX";
|
|
92046
|
+
return await this.run("QUOTA", path26);
|
|
91978
92047
|
}
|
|
91979
92048
|
/**
|
|
91980
92049
|
* @typedef {Object} ListResponse
|
|
@@ -92084,8 +92153,8 @@ var require_imap_flow = __commonJS({
|
|
|
92084
92153
|
* console.log(info.path);
|
|
92085
92154
|
* // "INBOX.parent.child" // assumes "INBOX." as namespace prefix and "." as delimiter
|
|
92086
92155
|
*/
|
|
92087
|
-
async mailboxCreate(
|
|
92088
|
-
return await this.run("CREATE",
|
|
92156
|
+
async mailboxCreate(path26) {
|
|
92157
|
+
return await this.run("CREATE", path26);
|
|
92089
92158
|
}
|
|
92090
92159
|
/**
|
|
92091
92160
|
* @typedef {Object} MailboxRenameResponse
|
|
@@ -92106,8 +92175,8 @@ var require_imap_flow = __commonJS({
|
|
|
92106
92175
|
* console.log(info.newPath);
|
|
92107
92176
|
* // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
|
|
92108
92177
|
*/
|
|
92109
|
-
async mailboxRename(
|
|
92110
|
-
return await this.run("RENAME",
|
|
92178
|
+
async mailboxRename(path26, newPath) {
|
|
92179
|
+
return await this.run("RENAME", path26, newPath);
|
|
92111
92180
|
}
|
|
92112
92181
|
/**
|
|
92113
92182
|
* @typedef {Object} MailboxDeleteResponse
|
|
@@ -92126,8 +92195,8 @@ var require_imap_flow = __commonJS({
|
|
|
92126
92195
|
* console.log(info.path);
|
|
92127
92196
|
* // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
|
|
92128
92197
|
*/
|
|
92129
|
-
async mailboxDelete(
|
|
92130
|
-
return await this.run("DELETE",
|
|
92198
|
+
async mailboxDelete(path26) {
|
|
92199
|
+
return await this.run("DELETE", path26);
|
|
92131
92200
|
}
|
|
92132
92201
|
/**
|
|
92133
92202
|
* Subscribes to a mailbox
|
|
@@ -92138,8 +92207,8 @@ var require_imap_flow = __commonJS({
|
|
|
92138
92207
|
* @example
|
|
92139
92208
|
* await client.mailboxSubscribe('Important stuff ❗️');
|
|
92140
92209
|
*/
|
|
92141
|
-
async mailboxSubscribe(
|
|
92142
|
-
return await this.run("SUBSCRIBE",
|
|
92210
|
+
async mailboxSubscribe(path26) {
|
|
92211
|
+
return await this.run("SUBSCRIBE", path26);
|
|
92143
92212
|
}
|
|
92144
92213
|
/**
|
|
92145
92214
|
* Unsubscribes from a mailbox
|
|
@@ -92150,8 +92219,8 @@ var require_imap_flow = __commonJS({
|
|
|
92150
92219
|
* @example
|
|
92151
92220
|
* await client.mailboxUnsubscribe('Important stuff ❗️');
|
|
92152
92221
|
*/
|
|
92153
|
-
async mailboxUnsubscribe(
|
|
92154
|
-
return await this.run("UNSUBSCRIBE",
|
|
92222
|
+
async mailboxUnsubscribe(path26) {
|
|
92223
|
+
return await this.run("UNSUBSCRIBE", path26);
|
|
92155
92224
|
}
|
|
92156
92225
|
/**
|
|
92157
92226
|
* Opens a mailbox to access messages. You can perform message operations only against an opened mailbox.
|
|
@@ -92169,8 +92238,8 @@ var require_imap_flow = __commonJS({
|
|
|
92169
92238
|
* console.log(mailbox.exists);
|
|
92170
92239
|
* // 125
|
|
92171
92240
|
*/
|
|
92172
|
-
async mailboxOpen(
|
|
92173
|
-
return await this.run("SELECT",
|
|
92241
|
+
async mailboxOpen(path26, options) {
|
|
92242
|
+
return await this.run("SELECT", path26, options);
|
|
92174
92243
|
}
|
|
92175
92244
|
/**
|
|
92176
92245
|
* Closes a previously opened mailbox
|
|
@@ -92217,8 +92286,8 @@ var require_imap_flow = __commonJS({
|
|
|
92217
92286
|
* console.log(status.unseen);
|
|
92218
92287
|
* // 123
|
|
92219
92288
|
*/
|
|
92220
|
-
async status(
|
|
92221
|
-
return await this.run("STATUS",
|
|
92289
|
+
async status(path26, query) {
|
|
92290
|
+
return await this.run("STATUS", path26, query);
|
|
92222
92291
|
}
|
|
92223
92292
|
/**
|
|
92224
92293
|
* Starts listening for new or deleted messages from the currently opened mailbox. Only required if {@link ImapFlow#disableAutoIdle} is set to `true`
|
|
@@ -92472,8 +92541,8 @@ var require_imap_flow = __commonJS({
|
|
|
92472
92541
|
* @example
|
|
92473
92542
|
* await client.append('INBOX', rawMessageBuffer, ['\\Seen'], new Date(2000, 1, 1));
|
|
92474
92543
|
*/
|
|
92475
|
-
async append(
|
|
92476
|
-
return await this.run("APPEND",
|
|
92544
|
+
async append(path26, content, flags, idate) {
|
|
92545
|
+
return await this.run("APPEND", path26, content, flags, idate) || false;
|
|
92477
92546
|
}
|
|
92478
92547
|
/**
|
|
92479
92548
|
* @typedef {Object} CopyResponseObject
|
|
@@ -93317,7 +93386,7 @@ var require_imap_flow = __commonJS({
|
|
|
93317
93386
|
await new Promise((resolve2) => setImmediate(resolve2));
|
|
93318
93387
|
}
|
|
93319
93388
|
const lock = this.locks.shift();
|
|
93320
|
-
const { resolve, reject, path:
|
|
93389
|
+
const { resolve, reject, path: path26, options, lockId } = lock;
|
|
93321
93390
|
if (lock.acquireTimer) {
|
|
93322
93391
|
clearTimeout(lock.acquireTimer);
|
|
93323
93392
|
lock.acquireTimer = null;
|
|
@@ -93333,7 +93402,7 @@ var require_imap_flow = __commonJS({
|
|
|
93333
93402
|
this.log.warn({
|
|
93334
93403
|
msg: "Mailbox lock held for a long time",
|
|
93335
93404
|
lockId: lock.lockId,
|
|
93336
|
-
path:
|
|
93405
|
+
path: path26,
|
|
93337
93406
|
heldFor: Date.now() - lock.heldAt,
|
|
93338
93407
|
/* c8 ignore next */
|
|
93339
93408
|
// the held-lock-warning diagnostic with a description set is a timing-dependent log detail
|
|
@@ -93369,52 +93438,52 @@ var require_imap_flow = __commonJS({
|
|
|
93369
93438
|
}
|
|
93370
93439
|
};
|
|
93371
93440
|
if (!this.usable || !this.socket || this.socket.destroyed) {
|
|
93372
|
-
this.log.trace({ msg: "Failed to acquire mailbox lock", path:
|
|
93441
|
+
this.log.trace({ msg: "Failed to acquire mailbox lock", path: path26, lockId, idling: this.idling });
|
|
93373
93442
|
let error2 = new Error("Connection not available");
|
|
93374
93443
|
error2.code = "NoConnection";
|
|
93375
93444
|
reject(error2);
|
|
93376
93445
|
continue;
|
|
93377
93446
|
}
|
|
93378
|
-
if (this.mailbox && this.mailbox.path ===
|
|
93447
|
+
if (this.mailbox && this.mailbox.path === path26 && !!this.mailbox.readOnly === !!options.readOnly) {
|
|
93379
93448
|
this.log.trace({
|
|
93380
93449
|
msg: "Mailbox lock acquired [existing]",
|
|
93381
|
-
path:
|
|
93450
|
+
path: path26,
|
|
93382
93451
|
lockId,
|
|
93383
93452
|
idling: this.idling,
|
|
93384
93453
|
...options.description && { description: options.description }
|
|
93385
93454
|
});
|
|
93386
93455
|
this.currentLock = lock;
|
|
93387
93456
|
armHeldTimer();
|
|
93388
|
-
resolve({ path:
|
|
93457
|
+
resolve({ path: path26, release });
|
|
93389
93458
|
break;
|
|
93390
93459
|
}
|
|
93391
93460
|
try {
|
|
93392
|
-
await this.mailboxOpen(
|
|
93461
|
+
await this.mailboxOpen(path26, options);
|
|
93393
93462
|
this.log.trace({
|
|
93394
93463
|
msg: "Mailbox lock acquired [selected]",
|
|
93395
|
-
path:
|
|
93464
|
+
path: path26,
|
|
93396
93465
|
lockId,
|
|
93397
93466
|
idling: this.idling,
|
|
93398
93467
|
...options.description && { description: options.description }
|
|
93399
93468
|
});
|
|
93400
93469
|
this.currentLock = lock;
|
|
93401
93470
|
armHeldTimer();
|
|
93402
|
-
resolve({ path:
|
|
93471
|
+
resolve({ path: path26, release });
|
|
93403
93472
|
break;
|
|
93404
93473
|
} catch (err) {
|
|
93405
93474
|
if (err.responseStatus === "NO") {
|
|
93406
93475
|
try {
|
|
93407
|
-
let folders = await this.run("LIST", "",
|
|
93476
|
+
let folders = await this.run("LIST", "", path26, { listOnly: true });
|
|
93408
93477
|
if (!folders || !folders.length) {
|
|
93409
93478
|
err.mailboxMissing = true;
|
|
93410
93479
|
}
|
|
93411
93480
|
} catch (E) {
|
|
93412
|
-
this.log.trace({ msg: "Failed to verify failed mailbox", path:
|
|
93481
|
+
this.log.trace({ msg: "Failed to verify failed mailbox", path: path26, err: E });
|
|
93413
93482
|
}
|
|
93414
93483
|
}
|
|
93415
93484
|
this.log.trace({
|
|
93416
93485
|
msg: "Failed to acquire mailbox lock",
|
|
93417
|
-
path:
|
|
93486
|
+
path: path26,
|
|
93418
93487
|
lockId,
|
|
93419
93488
|
idling: this.idling,
|
|
93420
93489
|
...options.description && { description: options.description },
|
|
@@ -93453,13 +93522,13 @@ var require_imap_flow = __commonJS({
|
|
|
93453
93522
|
* lock.release();
|
|
93454
93523
|
* }
|
|
93455
93524
|
*/
|
|
93456
|
-
getMailboxLock(
|
|
93525
|
+
getMailboxLock(path26, options) {
|
|
93457
93526
|
options = options || {};
|
|
93458
|
-
|
|
93527
|
+
path26 = normalizePath(this, path26);
|
|
93459
93528
|
let lockId = ++this.lockCounter;
|
|
93460
93529
|
this.log.trace({
|
|
93461
93530
|
msg: "Requesting lock",
|
|
93462
|
-
path:
|
|
93531
|
+
path: path26,
|
|
93463
93532
|
lockId,
|
|
93464
93533
|
...options.description && { description: options.description },
|
|
93465
93534
|
activeLock: this.currentLock ? {
|
|
@@ -93468,7 +93537,7 @@ var require_imap_flow = __commonJS({
|
|
|
93468
93537
|
} : null
|
|
93469
93538
|
});
|
|
93470
93539
|
let lockPromise = new Promise((resolve, reject) => {
|
|
93471
|
-
let lockEntry = { resolve, reject, path:
|
|
93540
|
+
let lockEntry = { resolve, reject, path: path26, options, lockId };
|
|
93472
93541
|
this.locks.push(lockEntry);
|
|
93473
93542
|
if (Number(options.acquireTimeout) > 0) {
|
|
93474
93543
|
lockEntry.acquireTimer = setTimeout(() => {
|
|
@@ -93557,16 +93626,16 @@ var require_imap_flow = __commonJS({
|
|
|
93557
93626
|
});
|
|
93558
93627
|
|
|
93559
93628
|
// src/mail/mail-fetcher.ts
|
|
93560
|
-
import
|
|
93561
|
-
import
|
|
93629
|
+
import fs23 from "node:fs/promises";
|
|
93630
|
+
import path24 from "node:path";
|
|
93562
93631
|
async function saveAttachments(attachments, downloadDir) {
|
|
93563
93632
|
if (attachments.length === 0) return [];
|
|
93564
|
-
await
|
|
93633
|
+
await fs23.mkdir(downloadDir, { recursive: true });
|
|
93565
93634
|
const saved = [];
|
|
93566
93635
|
for (const a of attachments) {
|
|
93567
|
-
const name =
|
|
93568
|
-
const savedPath =
|
|
93569
|
-
await
|
|
93636
|
+
const name = path24.basename(a.filename) || "attachment";
|
|
93637
|
+
const savedPath = path24.join(downloadDir, name);
|
|
93638
|
+
await fs23.writeFile(savedPath, a.content);
|
|
93570
93639
|
saved.push({ filename: name, savedPath, size: a.content.length });
|
|
93571
93640
|
}
|
|
93572
93641
|
return saved;
|
|
@@ -93696,8 +93765,8 @@ var init_mail_fetcher = __esm({
|
|
|
93696
93765
|
});
|
|
93697
93766
|
|
|
93698
93767
|
// src/tools/fetch-mail.ts
|
|
93699
|
-
import
|
|
93700
|
-
import
|
|
93768
|
+
import os17 from "node:os";
|
|
93769
|
+
import path25 from "node:path";
|
|
93701
93770
|
function registerFetchMailTool(server, deps = {}) {
|
|
93702
93771
|
const makeFetcher = deps.fetcherFactory ?? ((creds) => new ImapflowMailFetcher(creds));
|
|
93703
93772
|
server.registerTool(
|
|
@@ -93759,7 +93828,7 @@ var init_fetch_mail = __esm({
|
|
|
93759
93828
|
init_mail_fetcher();
|
|
93760
93829
|
init_auth_error();
|
|
93761
93830
|
init_validate();
|
|
93762
|
-
DEFAULT_DOWNLOAD_DIR =
|
|
93831
|
+
DEFAULT_DOWNLOAD_DIR = path25.join(os17.homedir(), ".cogent", "mail-downloads");
|
|
93763
93832
|
}
|
|
93764
93833
|
});
|
|
93765
93834
|
|