@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.
@@ -0,0 +1,16 @@
1
+ // src/cli/exit-codes.ts
2
+ var EXIT = {
3
+ OK: 0,
4
+ DOCTOR_FAIL: 1,
5
+ USAGE: 2,
6
+ NOT_LOGGED_IN: 3,
7
+ CRED_UNAVAILABLE: 4,
8
+ PROVIDER_BROKEN: 5,
9
+ BUSY: 6,
10
+ CLEANUP_PENDING: 7,
11
+ CANCELLED: 8
12
+ };
13
+
14
+ export {
15
+ EXIT
16
+ };
@@ -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
+ };