repowisestage 0.0.78 → 0.0.80
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/dist/bin/repowise.js +177 -64
- package/package.json +1 -1
package/dist/bin/repowise.js
CHANGED
|
@@ -2382,7 +2382,9 @@ var init_service_installer = __esm({
|
|
|
2382
2382
|
var sidecar_cache_exports = {};
|
|
2383
2383
|
__export(sidecar_cache_exports, {
|
|
2384
2384
|
loadMergedSidecar: () => loadMergedSidecar,
|
|
2385
|
+
loadSidecarEtag: () => loadSidecarEtag,
|
|
2385
2386
|
persistMergedSidecar: () => persistMergedSidecar,
|
|
2387
|
+
persistSidecarEtag: () => persistSidecarEtag,
|
|
2386
2388
|
sidecarCachePaths: () => sidecarCachePaths
|
|
2387
2389
|
});
|
|
2388
2390
|
import { mkdir as mkdir9, readFile as readFile9, readdir as readdir3, stat as stat2, unlink as unlink9, writeFile as writeFile10 } from "fs/promises";
|
|
@@ -2409,8 +2411,8 @@ async function persistMergedSidecar(repoId, commitSha, sidecar) {
|
|
|
2409
2411
|
await mkdir9(repoDir, { recursive: true });
|
|
2410
2412
|
const tmpPath = `${fullPath}.tmp`;
|
|
2411
2413
|
await writeFile10(tmpPath, JSON.stringify(sidecar), "utf-8");
|
|
2412
|
-
const { rename:
|
|
2413
|
-
await
|
|
2414
|
+
const { rename: rename9 } = await import("fs/promises");
|
|
2415
|
+
await rename9(tmpPath, fullPath);
|
|
2414
2416
|
try {
|
|
2415
2417
|
await sweepSidecarDir(repoDir);
|
|
2416
2418
|
} catch {
|
|
@@ -2438,9 +2440,32 @@ async function sweepSidecarDir(repoDir) {
|
|
|
2438
2440
|
await unlink9(join21(repoDir, name));
|
|
2439
2441
|
} catch {
|
|
2440
2442
|
}
|
|
2443
|
+
try {
|
|
2444
|
+
await unlink9(join21(repoDir, `${name}.etag`));
|
|
2445
|
+
} catch {
|
|
2446
|
+
}
|
|
2441
2447
|
}
|
|
2442
2448
|
}
|
|
2443
2449
|
}
|
|
2450
|
+
async function persistSidecarEtag(repoId, commitSha, etag) {
|
|
2451
|
+
const { fullPath, repoDir } = sidecarCachePaths(repoId, commitSha);
|
|
2452
|
+
await mkdir9(repoDir, { recursive: true });
|
|
2453
|
+
const etagPath = `${fullPath}.etag`;
|
|
2454
|
+
const tmpPath = `${etagPath}.tmp`;
|
|
2455
|
+
await writeFile10(tmpPath, etag, "utf-8");
|
|
2456
|
+
const { rename: rename9 } = await import("fs/promises");
|
|
2457
|
+
await rename9(tmpPath, etagPath);
|
|
2458
|
+
}
|
|
2459
|
+
async function loadSidecarEtag(repoId, commitSha) {
|
|
2460
|
+
try {
|
|
2461
|
+
const { fullPath } = sidecarCachePaths(repoId, commitSha);
|
|
2462
|
+
const body = await readFile9(`${fullPath}.etag`, "utf-8");
|
|
2463
|
+
const trimmed = body.trim();
|
|
2464
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
2465
|
+
} catch {
|
|
2466
|
+
return null;
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2444
2469
|
function isValidSidecarEntry(e) {
|
|
2445
2470
|
if (!e || typeof e !== "object")
|
|
2446
2471
|
return false;
|
|
@@ -2576,22 +2601,28 @@ async function uploadSidecarLegacy(req, body, fetchImpl) {
|
|
|
2576
2601
|
}
|
|
2577
2602
|
async function downloadMergedSidecar(req, fetchImpl = fetch) {
|
|
2578
2603
|
const url = `${req.apiUrl.replace(/\/$/, "")}/v1/repos/${encodeURIComponent(req.repoId)}/typed-resolution/${encodeURIComponent(req.commitSha)}`;
|
|
2579
|
-
const
|
|
2580
|
-
|
|
2581
|
-
headers
|
|
2582
|
-
});
|
|
2604
|
+
const headers = { authorization: `Bearer ${req.authToken}` };
|
|
2605
|
+
if (req.ifNoneMatch)
|
|
2606
|
+
headers["if-none-match"] = req.ifNoneMatch;
|
|
2607
|
+
const res = await fetchImpl(url, { method: "GET", headers });
|
|
2608
|
+
if (res.status === 304)
|
|
2609
|
+
return { status: "not-modified" };
|
|
2583
2610
|
if (res.status === 404)
|
|
2584
|
-
return
|
|
2611
|
+
return { status: "absent" };
|
|
2585
2612
|
if (!res.ok) {
|
|
2586
2613
|
throw new Error(`download failed: HTTP ${res.status.toString()}`);
|
|
2587
2614
|
}
|
|
2588
2615
|
const body = await res.json();
|
|
2589
2616
|
if (typeof body.schemaVersion !== "number" || !ACCEPTED_TYPED_RESOLUTION_SCHEMA_VERSIONS.includes(body.schemaVersion)) {
|
|
2590
|
-
return
|
|
2617
|
+
return { status: "absent" };
|
|
2591
2618
|
}
|
|
2592
2619
|
if (!Array.isArray(body.resolutions))
|
|
2593
|
-
return
|
|
2594
|
-
return
|
|
2620
|
+
return { status: "absent" };
|
|
2621
|
+
return {
|
|
2622
|
+
status: "sidecar",
|
|
2623
|
+
sidecar: body,
|
|
2624
|
+
etag: res.headers.get("etag")
|
|
2625
|
+
};
|
|
2595
2626
|
}
|
|
2596
2627
|
function buildSidecarIndex(sidecar) {
|
|
2597
2628
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -6009,6 +6040,16 @@ function createGraphCache(options = {}) {
|
|
|
6009
6040
|
clearTimeout(entry.evictTimer);
|
|
6010
6041
|
delete entry.evictTimer;
|
|
6011
6042
|
}
|
|
6043
|
+
if (entry.sessionCount > 0) {
|
|
6044
|
+
void loadFromDisk(repoId).then((fresh) => {
|
|
6045
|
+
if (entries.get(repoId) === entry) {
|
|
6046
|
+
entry.graph = fresh.graph;
|
|
6047
|
+
entry.loadedMtime = fresh.loadedMtime;
|
|
6048
|
+
}
|
|
6049
|
+
}, () => {
|
|
6050
|
+
});
|
|
6051
|
+
return;
|
|
6052
|
+
}
|
|
6012
6053
|
entries.delete(repoId);
|
|
6013
6054
|
},
|
|
6014
6055
|
stats() {
|
|
@@ -6445,8 +6486,8 @@ function createFileKeyStore(keyPath) {
|
|
|
6445
6486
|
encoding: "utf-8",
|
|
6446
6487
|
mode: 384
|
|
6447
6488
|
});
|
|
6448
|
-
const { rename:
|
|
6449
|
-
await
|
|
6489
|
+
const { rename: rename9 } = await import("fs/promises");
|
|
6490
|
+
await rename9(tmp, keyPath);
|
|
6450
6491
|
cached = fresh;
|
|
6451
6492
|
try {
|
|
6452
6493
|
const s = await stat4(keyPath);
|
|
@@ -6695,9 +6736,9 @@ async function writePendingBatch(watermarkPath, batchId) {
|
|
|
6695
6736
|
await writeFile14(pendingPath(watermarkPath), batchId, { encoding: "utf-8", mode: 384 });
|
|
6696
6737
|
}
|
|
6697
6738
|
async function clearPendingBatch(watermarkPath) {
|
|
6698
|
-
const { unlink:
|
|
6739
|
+
const { unlink: unlink15 } = await import("fs/promises");
|
|
6699
6740
|
try {
|
|
6700
|
-
await
|
|
6741
|
+
await unlink15(pendingPath(watermarkPath));
|
|
6701
6742
|
} catch {
|
|
6702
6743
|
}
|
|
6703
6744
|
}
|
|
@@ -6716,8 +6757,8 @@ async function writeWatermark(path, offset) {
|
|
|
6716
6757
|
await mkdir13(dirname14(path), { recursive: true });
|
|
6717
6758
|
const tmp = `${path}.tmp`;
|
|
6718
6759
|
await writeFile14(tmp, offset.toString() + "\n", { encoding: "utf-8", mode: 384 });
|
|
6719
|
-
const { rename:
|
|
6720
|
-
await
|
|
6760
|
+
const { rename: rename9 } = await import("fs/promises");
|
|
6761
|
+
await rename9(tmp, path);
|
|
6721
6762
|
}
|
|
6722
6763
|
async function isLocallyConsented(flagPath2) {
|
|
6723
6764
|
try {
|
|
@@ -6732,9 +6773,37 @@ async function isLocallyConsented(flagPath2) {
|
|
|
6732
6773
|
// ../listener/dist/mcp/mcp-server.js
|
|
6733
6774
|
init_config_dir();
|
|
6734
6775
|
import { createServer } from "http";
|
|
6735
|
-
import {
|
|
6736
|
-
import {
|
|
6737
|
-
import { createHash as createHash4, randomUUID as
|
|
6776
|
+
import { unlink as unlink12 } from "fs/promises";
|
|
6777
|
+
import { join as join23 } from "path";
|
|
6778
|
+
import { createHash as createHash4, randomUUID as randomUUID4 } from "crypto";
|
|
6779
|
+
|
|
6780
|
+
// ../listener/dist/lib/atomic-write.js
|
|
6781
|
+
import { mkdir as mkdir14, writeFile as writeFile15, chmod as chmod4, rename as rename6, unlink as unlink11, open as open5 } from "fs/promises";
|
|
6782
|
+
import { dirname as dirname15 } from "path";
|
|
6783
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
6784
|
+
async function writeFileAtomic(path, contents, opts = {}) {
|
|
6785
|
+
const mode = opts.mode ?? 384;
|
|
6786
|
+
await mkdir14(dirname15(path), { recursive: true });
|
|
6787
|
+
const tmpPath = `${path}.${randomUUID3()}.tmp`;
|
|
6788
|
+
try {
|
|
6789
|
+
await writeFile15(tmpPath, contents, { encoding: "utf-8", mode });
|
|
6790
|
+
await chmod4(tmpPath, mode);
|
|
6791
|
+
let fh;
|
|
6792
|
+
try {
|
|
6793
|
+
fh = await open5(tmpPath, "r+");
|
|
6794
|
+
await fh.datasync();
|
|
6795
|
+
} finally {
|
|
6796
|
+
await fh?.close();
|
|
6797
|
+
}
|
|
6798
|
+
await rename6(tmpPath, path);
|
|
6799
|
+
} catch (err) {
|
|
6800
|
+
try {
|
|
6801
|
+
await unlink11(tmpPath);
|
|
6802
|
+
} catch {
|
|
6803
|
+
}
|
|
6804
|
+
throw err;
|
|
6805
|
+
}
|
|
6806
|
+
}
|
|
6738
6807
|
|
|
6739
6808
|
// ../listener/dist/mcp/sanitize.js
|
|
6740
6809
|
var MCP_RESPONSE_BYTE_CAP = 200 * 1024;
|
|
@@ -7768,6 +7837,25 @@ async function startMcpServer(options) {
|
|
|
7768
7837
|
const clock = options.clock ?? Date.now;
|
|
7769
7838
|
const requireAuth = options.requireAuth ?? true;
|
|
7770
7839
|
const secretState = { value: createRotatingSecret(clock()) };
|
|
7840
|
+
const endpointFilePath = options.endpointFilePath ?? defaultEndpointFile();
|
|
7841
|
+
let endpointUrl = null;
|
|
7842
|
+
let lastPersistedSecret = null;
|
|
7843
|
+
let suspended = false;
|
|
7844
|
+
let persisting = false;
|
|
7845
|
+
let currentPersist = null;
|
|
7846
|
+
const persistSecretIfStale = () => {
|
|
7847
|
+
const live = secretState.value.current;
|
|
7848
|
+
if (endpointUrl === null || suspended || persisting || live === lastPersistedSecret)
|
|
7849
|
+
return;
|
|
7850
|
+
persisting = true;
|
|
7851
|
+
currentPersist = writeEndpointFileWithRetry(endpointFilePath, endpointUrl, live).then(() => {
|
|
7852
|
+
lastPersistedSecret = live;
|
|
7853
|
+
}).catch((err) => {
|
|
7854
|
+
console.warn("[mcp] endpoint secret persist failed (will retry on next request):", err instanceof Error ? err.message : String(err));
|
|
7855
|
+
}).finally(() => {
|
|
7856
|
+
persisting = false;
|
|
7857
|
+
});
|
|
7858
|
+
};
|
|
7771
7859
|
const server = createServer((req, res) => handleRequest(req, res, options, sessions, {
|
|
7772
7860
|
getSecret: () => secretState.value,
|
|
7773
7861
|
rotate: () => {
|
|
@@ -7775,6 +7863,7 @@ async function startMcpServer(options) {
|
|
|
7775
7863
|
if (next !== secretState.value) {
|
|
7776
7864
|
secretState.value = next;
|
|
7777
7865
|
}
|
|
7866
|
+
persistSecretIfStale();
|
|
7778
7867
|
return secretState.value;
|
|
7779
7868
|
},
|
|
7780
7869
|
requireAuth,
|
|
@@ -7788,38 +7877,34 @@ async function startMcpServer(options) {
|
|
|
7788
7877
|
});
|
|
7789
7878
|
});
|
|
7790
7879
|
const addr = server.address();
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7880
|
+
endpointUrl = `http://127.0.0.1:${addr.port}`;
|
|
7881
|
+
await writeEndpointFileWithRetry(endpointFilePath, endpointUrl, secretState.value.current);
|
|
7882
|
+
lastPersistedSecret = secretState.value.current;
|
|
7794
7883
|
return {
|
|
7795
|
-
endpoint,
|
|
7884
|
+
endpoint: endpointUrl,
|
|
7796
7885
|
port: addr.port,
|
|
7797
7886
|
secret: secretState.value.current,
|
|
7887
|
+
currentSecret: () => secretState.value.current,
|
|
7798
7888
|
close: () => new Promise((resolve5, reject) => {
|
|
7799
7889
|
server.close((err) => err ? reject(err) : resolve5());
|
|
7800
7890
|
}),
|
|
7801
7891
|
suspendEndpoint: async () => {
|
|
7892
|
+
suspended = true;
|
|
7893
|
+
await currentPersist?.catch(() => void 0);
|
|
7894
|
+
lastPersistedSecret = null;
|
|
7802
7895
|
try {
|
|
7803
|
-
await
|
|
7896
|
+
await unlink12(endpointFilePath);
|
|
7804
7897
|
} catch (err) {
|
|
7805
7898
|
if (err.code !== "ENOENT")
|
|
7806
7899
|
throw err;
|
|
7807
7900
|
}
|
|
7808
7901
|
},
|
|
7809
7902
|
resumeEndpoint: async () => {
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
} catch (err) {
|
|
7816
|
-
lastErr = err;
|
|
7817
|
-
if (attempt < 3)
|
|
7818
|
-
await new Promise((r) => setTimeout(r, 100 * attempt));
|
|
7819
|
-
}
|
|
7820
|
-
}
|
|
7821
|
-
throw lastErr;
|
|
7822
|
-
}
|
|
7903
|
+
suspended = false;
|
|
7904
|
+
await writeEndpointFileWithRetry(endpointFilePath, endpointUrl, secretState.value.current);
|
|
7905
|
+
lastPersistedSecret = secretState.value.current;
|
|
7906
|
+
},
|
|
7907
|
+
retryPendingPersist: () => persistSecretIfStale()
|
|
7823
7908
|
};
|
|
7824
7909
|
}
|
|
7825
7910
|
function handleRequest(req, res, options, sessions, secretCtx) {
|
|
@@ -7859,7 +7944,7 @@ function handleRequest(req, res, options, sessions, secretCtx) {
|
|
|
7859
7944
|
if (!body?.repoId)
|
|
7860
7945
|
return sendJson(res, 400, { error: "missing_repoId" });
|
|
7861
7946
|
return options.graphCache.acquire(body.repoId).then(() => {
|
|
7862
|
-
const sessionId =
|
|
7947
|
+
const sessionId = randomUUID4();
|
|
7863
7948
|
sessions.set(sessionId, { repoId: body.repoId });
|
|
7864
7949
|
return sendJson(res, 200, { sessionId });
|
|
7865
7950
|
});
|
|
@@ -8352,11 +8437,21 @@ async function readJson(req) {
|
|
|
8352
8437
|
}
|
|
8353
8438
|
}
|
|
8354
8439
|
async function writeEndpointFile(path, endpoint, secret) {
|
|
8355
|
-
await
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8440
|
+
await writeFileAtomic(path, formatEndpointFile({ endpoint, secret }), { mode: 384 });
|
|
8441
|
+
}
|
|
8442
|
+
async function writeEndpointFileWithRetry(path, endpoint, secret) {
|
|
8443
|
+
let lastErr;
|
|
8444
|
+
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
8445
|
+
try {
|
|
8446
|
+
await writeEndpointFile(path, endpoint, secret);
|
|
8447
|
+
return;
|
|
8448
|
+
} catch (err) {
|
|
8449
|
+
lastErr = err;
|
|
8450
|
+
if (attempt < 3)
|
|
8451
|
+
await new Promise((r) => setTimeout(r, 100 * attempt));
|
|
8452
|
+
}
|
|
8453
|
+
}
|
|
8454
|
+
throw lastErr;
|
|
8360
8455
|
}
|
|
8361
8456
|
function extractBearer(header) {
|
|
8362
8457
|
const raw = Array.isArray(header) ? header[0] : header;
|
|
@@ -10629,16 +10724,28 @@ async function runProducerCycle(input, fetchImpl = fetch) {
|
|
|
10629
10724
|
async function runDownloaderCycle(input, fetchImpl = fetch) {
|
|
10630
10725
|
if (isDisabled())
|
|
10631
10726
|
return null;
|
|
10632
|
-
const
|
|
10727
|
+
const cached = await loadMergedSidecar(input.repoId, input.commitSha);
|
|
10728
|
+
const cachedEtag = cached ? await loadSidecarEtag(input.repoId, input.commitSha) : null;
|
|
10729
|
+
const res = await downloadMergedSidecar({
|
|
10633
10730
|
apiUrl: input.apiUrl,
|
|
10634
10731
|
authToken: input.authToken,
|
|
10635
10732
|
repoId: input.repoId,
|
|
10636
|
-
commitSha: input.commitSha
|
|
10733
|
+
commitSha: input.commitSha,
|
|
10734
|
+
...cachedEtag ? { ifNoneMatch: cachedEtag } : {}
|
|
10637
10735
|
}, fetchImpl);
|
|
10638
|
-
if (
|
|
10736
|
+
if (res.status === "not-modified") {
|
|
10737
|
+
if (!cached || !input.graph?.edges)
|
|
10738
|
+
return { downloaded: false, edgesUpgraded: 0 };
|
|
10739
|
+
const cachedResult = overlayMergedSidecar(input.graph.edges, cached);
|
|
10740
|
+
return { downloaded: false, edgesUpgraded: cachedResult.edgesUpgraded };
|
|
10741
|
+
}
|
|
10742
|
+
if (res.status === "absent")
|
|
10639
10743
|
return { downloaded: false, edgesUpgraded: 0 };
|
|
10744
|
+
const sidecar = res.sidecar;
|
|
10640
10745
|
try {
|
|
10641
10746
|
await persistMergedSidecar(input.repoId, input.commitSha, sidecar);
|
|
10747
|
+
if (res.etag)
|
|
10748
|
+
await persistSidecarEtag(input.repoId, input.commitSha, res.etag);
|
|
10642
10749
|
} catch (persistErr) {
|
|
10643
10750
|
console.warn(`[typed-resolution] persist failed for ${input.repoId}: ${persistErr instanceof Error ? persistErr.message : String(persistErr)}`);
|
|
10644
10751
|
}
|
|
@@ -11318,14 +11425,17 @@ async function runProducerHook(notif, localPath, ctx) {
|
|
|
11318
11425
|
console.warn(`[typed-resolution] producer failed for ${notif.repoId}: ${prodErr instanceof Error ? prodErr.message : String(prodErr)}`);
|
|
11319
11426
|
}
|
|
11320
11427
|
}
|
|
11321
|
-
var processedSideEffectNotifs = /* @__PURE__ */ new
|
|
11428
|
+
var processedSideEffectNotifs = /* @__PURE__ */ new Map();
|
|
11322
11429
|
var MAX_PROCESSED_SIDE_EFFECT_NOTIFS = 512;
|
|
11323
|
-
|
|
11324
|
-
|
|
11430
|
+
var SIDECAR_MERGED_RECHECK_MS = 5 * 60 * 1e3;
|
|
11431
|
+
function alreadyProcessedSideEffect(notificationId, ttlMs) {
|
|
11432
|
+
const now = Date.now();
|
|
11433
|
+
const expiresAt = processedSideEffectNotifs.get(notificationId);
|
|
11434
|
+
if (expiresAt !== void 0 && now < expiresAt)
|
|
11325
11435
|
return true;
|
|
11326
|
-
processedSideEffectNotifs.
|
|
11436
|
+
processedSideEffectNotifs.set(notificationId, ttlMs === void 0 ? Infinity : now + ttlMs);
|
|
11327
11437
|
if (processedSideEffectNotifs.size > MAX_PROCESSED_SIDE_EFFECT_NOTIFS) {
|
|
11328
|
-
const oldest = processedSideEffectNotifs.
|
|
11438
|
+
const oldest = processedSideEffectNotifs.keys().next().value;
|
|
11329
11439
|
if (oldest !== void 0)
|
|
11330
11440
|
processedSideEffectNotifs.delete(oldest);
|
|
11331
11441
|
}
|
|
@@ -11362,6 +11472,8 @@ async function handleGraphReady(notif, ctx) {
|
|
|
11362
11472
|
async function handleSidecarMerged(notif, ctx) {
|
|
11363
11473
|
if (!ctx.typedResolutionHooks || !notif.commitSha)
|
|
11364
11474
|
return;
|
|
11475
|
+
if (alreadyProcessedSideEffect(notif.notificationId, SIDECAR_MERGED_RECHECK_MS))
|
|
11476
|
+
return;
|
|
11365
11477
|
try {
|
|
11366
11478
|
await ctx.typedResolutionHooks.onSidecarMerged(notif.repoId, notif.commitSha);
|
|
11367
11479
|
} catch (dlErr) {
|
|
@@ -11951,6 +12063,7 @@ async function startListener() {
|
|
|
11951
12063
|
}
|
|
11952
12064
|
}
|
|
11953
12065
|
}
|
|
12066
|
+
mcpRuntime?.server?.retryPendingPersist?.();
|
|
11954
12067
|
let anyAuthError = null;
|
|
11955
12068
|
let authErrorGroup = null;
|
|
11956
12069
|
let minPollInterval = pollIntervalMs;
|
|
@@ -12358,7 +12471,7 @@ function getPackageName() {
|
|
|
12358
12471
|
import chalk from "chalk";
|
|
12359
12472
|
|
|
12360
12473
|
// src/lib/config.ts
|
|
12361
|
-
import { readFile as readFile15, writeFile as writeFile17, mkdir as mkdir17, rename as
|
|
12474
|
+
import { readFile as readFile15, writeFile as writeFile17, mkdir as mkdir17, rename as rename7, unlink as unlink13 } from "fs/promises";
|
|
12362
12475
|
import { join as join44 } from "path";
|
|
12363
12476
|
import lockfile6 from "proper-lockfile";
|
|
12364
12477
|
async function getConfig() {
|
|
@@ -12376,10 +12489,10 @@ async function saveConfig(config2) {
|
|
|
12376
12489
|
const tmpPath = path + ".tmp";
|
|
12377
12490
|
try {
|
|
12378
12491
|
await writeFile17(tmpPath, JSON.stringify(config2, null, 2));
|
|
12379
|
-
await
|
|
12492
|
+
await rename7(tmpPath, path);
|
|
12380
12493
|
} catch (err) {
|
|
12381
12494
|
try {
|
|
12382
|
-
await
|
|
12495
|
+
await unlink13(tmpPath);
|
|
12383
12496
|
} catch {
|
|
12384
12497
|
}
|
|
12385
12498
|
throw err;
|
|
@@ -12465,7 +12578,7 @@ import ora from "ora";
|
|
|
12465
12578
|
|
|
12466
12579
|
// src/lib/auth.ts
|
|
12467
12580
|
import { createHash as createHash6, randomBytes as randomBytes3 } from "crypto";
|
|
12468
|
-
import { readFile as readFile16, writeFile as writeFile18, mkdir as mkdir18, chmod as
|
|
12581
|
+
import { readFile as readFile16, writeFile as writeFile18, mkdir as mkdir18, chmod as chmod5, unlink as unlink14, rename as rename8, open as open6 } from "fs/promises";
|
|
12469
12582
|
import http from "http";
|
|
12470
12583
|
import { join as join45 } from "path";
|
|
12471
12584
|
import lockfile7 from "proper-lockfile";
|
|
@@ -12708,16 +12821,16 @@ async function storeCredentials2(credentials) {
|
|
|
12708
12821
|
await writeFile18(tmpPath, JSON.stringify(credentials, null, 2), { mode: 384 });
|
|
12709
12822
|
let fh;
|
|
12710
12823
|
try {
|
|
12711
|
-
fh = await
|
|
12824
|
+
fh = await open6(tmpPath, "r+");
|
|
12712
12825
|
await fh.datasync();
|
|
12713
12826
|
} finally {
|
|
12714
12827
|
await fh?.close();
|
|
12715
12828
|
}
|
|
12716
|
-
await
|
|
12717
|
-
await
|
|
12829
|
+
await rename8(tmpPath, credPath);
|
|
12830
|
+
await chmod5(credPath, 384);
|
|
12718
12831
|
} catch (err) {
|
|
12719
12832
|
try {
|
|
12720
|
-
await
|
|
12833
|
+
await unlink14(tmpPath);
|
|
12721
12834
|
} catch {
|
|
12722
12835
|
}
|
|
12723
12836
|
throw err;
|
|
@@ -12733,7 +12846,7 @@ async function storeCredentials2(credentials) {
|
|
|
12733
12846
|
}
|
|
12734
12847
|
async function clearCredentials() {
|
|
12735
12848
|
try {
|
|
12736
|
-
await
|
|
12849
|
+
await unlink14(join45(getConfigDir2(), "credentials.json"));
|
|
12737
12850
|
} catch (err) {
|
|
12738
12851
|
if (err.code !== "ENOENT") throw err;
|
|
12739
12852
|
}
|
|
@@ -12774,8 +12887,8 @@ async function performLogin() {
|
|
|
12774
12887
|
const authorizeUrl = getAuthorizeUrl(codeChallenge, state);
|
|
12775
12888
|
const callbackPromise = startCallbackServer();
|
|
12776
12889
|
try {
|
|
12777
|
-
const
|
|
12778
|
-
await
|
|
12890
|
+
const open7 = (await import("open")).default;
|
|
12891
|
+
await open7(authorizeUrl);
|
|
12779
12892
|
} catch {
|
|
12780
12893
|
console.log(`
|
|
12781
12894
|
Open this URL in your browser to authenticate:
|
|
@@ -15233,8 +15346,8 @@ Waiting for authentication...`);
|
|
|
15233
15346
|
} else {
|
|
15234
15347
|
spinner.text = "Opening browser for authentication...";
|
|
15235
15348
|
try {
|
|
15236
|
-
const
|
|
15237
|
-
await
|
|
15349
|
+
const open7 = (await import("open")).default;
|
|
15350
|
+
await open7(authorizeUrl);
|
|
15238
15351
|
spinner.text = "Waiting for authentication in browser...";
|
|
15239
15352
|
} catch {
|
|
15240
15353
|
spinner.stop();
|