@pyxmate/memory 1.27.0 → 1.27.1
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/chunk-4DXEQC6X.mjs +16 -0
- package/dist/chunk-7IGU3HJO.mjs +70 -0
- package/dist/chunk-7TATCSSN.mjs +650 -0
- package/dist/chunk-QR5K7ETI.mjs +793 -0
- package/dist/chunk-S3CX323Z.mjs +34 -0
- package/dist/chunk-THLUBOGD.mjs +263 -0
- package/dist/chunk-UESIQ47D.mjs +165 -0
- package/dist/chunk-YBPODKB5.mjs +132 -0
- package/dist/cli/pyx-mem.mjs +63 -4226
- package/dist/doctor-AERNUHEZ.mjs +143 -0
- package/dist/insights-PD7Y6QDX.mjs +139 -0
- package/dist/login-4ALCAN4M.mjs +179 -0
- package/dist/login-browser-DO2O2Q2G.mjs +407 -0
- package/dist/login-recovery-AOO76PYX.mjs +97 -0
- package/dist/logout-4CO53LNA.mjs +13 -0
- package/dist/mcp-64KVRH7F.mjs +944 -0
- package/dist/mcp-install-KBB45OB2.mjs +36 -0
- package/dist/overview-COBXHLP3.mjs +88 -0
- package/dist/scaffold-2FSCWF22.mjs +186 -0
- package/dist/status-UHJZLEPL.mjs +74 -0
- package/dist/taxonomy-EKDFDFXW.mjs +103 -0
- package/package.json +1 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KeychainError,
|
|
3
|
+
LockLostError,
|
|
4
|
+
credentialFingerprint,
|
|
5
|
+
saveJournal
|
|
6
|
+
} from "./chunk-7TATCSSN.mjs";
|
|
7
|
+
|
|
8
|
+
// src/cli/lifecycle/settle.ts
|
|
9
|
+
var STARTED_EXPIRY_MARGIN_MS = 15 * 6e4;
|
|
10
|
+
async function settle(keychain, api, journal, lockLost) {
|
|
11
|
+
const holdsLock = () => {
|
|
12
|
+
if (lockLost()) throw new LockLostError();
|
|
13
|
+
};
|
|
14
|
+
const save = async () => {
|
|
15
|
+
holdsLock();
|
|
16
|
+
await saveJournal(keychain, journal);
|
|
17
|
+
};
|
|
18
|
+
const readShared = () => keychain.read().catch((err) => {
|
|
19
|
+
if (err instanceof KeychainError && err.code === "credential-record-invalid") return null;
|
|
20
|
+
throw err;
|
|
21
|
+
});
|
|
22
|
+
const queueRevoke = (key) => {
|
|
23
|
+
const queued = journal.revoke.some(
|
|
24
|
+
(pending) => pending.endpoint === key.endpoint && pending.apiKey === key.apiKey
|
|
25
|
+
);
|
|
26
|
+
if (!queued) journal.revoke.push(key);
|
|
27
|
+
};
|
|
28
|
+
const login = journal.login;
|
|
29
|
+
if (login?.phase === "started") {
|
|
30
|
+
holdsLock();
|
|
31
|
+
if (Date.now() > login.expiresAt + STARTED_EXPIRY_MARGIN_MS || await api.cancel(login)) {
|
|
32
|
+
journal.login = null;
|
|
33
|
+
await save();
|
|
34
|
+
}
|
|
35
|
+
} else if (login?.apiKey !== void 0) {
|
|
36
|
+
const own = { endpoint: login.endpoint, apiKey: login.apiKey };
|
|
37
|
+
const shared = login.phase === "committing" ? await readShared() : null;
|
|
38
|
+
const committed = shared !== null && credentialFingerprint(shared.endpoint, shared.apiKey) === credentialFingerprint(own.endpoint, own.apiKey);
|
|
39
|
+
journal.login = null;
|
|
40
|
+
if (!committed) queueRevoke(own);
|
|
41
|
+
if (login.previous !== void 0 && shared?.apiKey !== login.previous.apiKey) {
|
|
42
|
+
queueRevoke(login.previous);
|
|
43
|
+
}
|
|
44
|
+
await save();
|
|
45
|
+
}
|
|
46
|
+
if (journal.logout !== null) {
|
|
47
|
+
const { fingerprint, revoke } = journal.logout;
|
|
48
|
+
const shared = await readShared();
|
|
49
|
+
if (shared !== null && credentialFingerprint(shared.endpoint, shared.apiKey) === fingerprint) {
|
|
50
|
+
holdsLock();
|
|
51
|
+
await keychain.delete();
|
|
52
|
+
}
|
|
53
|
+
journal.logout = null;
|
|
54
|
+
if (revoke !== null) queueRevoke(revoke);
|
|
55
|
+
await save();
|
|
56
|
+
}
|
|
57
|
+
for (const key of [...journal.revoke]) {
|
|
58
|
+
holdsLock();
|
|
59
|
+
if (await api.revoke(key)) {
|
|
60
|
+
journal.revoke = journal.revoke.filter((pending) => pending !== key);
|
|
61
|
+
journal.revokedAt = Date.now();
|
|
62
|
+
await save();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return journal;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export {
|
|
69
|
+
settle
|
|
70
|
+
};
|