@pleri/olam-cli 0.1.195 → 0.1.198
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/README.md +52 -0
- package/dist/ask/knowledge-pack.generated.d.ts.map +1 -1
- package/dist/ask/knowledge-pack.generated.js +12 -8
- package/dist/ask/knowledge-pack.generated.js.map +1 -1
- package/dist/commands/auth-list-json.d.ts +34 -0
- package/dist/commands/auth-list-json.d.ts.map +1 -1
- package/dist/commands/auth-list-json.js +24 -0
- package/dist/commands/auth-list-json.js.map +1 -1
- package/dist/commands/auth-migrate.d.ts +212 -0
- package/dist/commands/auth-migrate.d.ts.map +1 -0
- package/dist/commands/auth-migrate.js +465 -0
- package/dist/commands/auth-migrate.js.map +1 -0
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +239 -184
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/bootstrap.d.ts +4 -0
- package/dist/commands/bootstrap.d.ts.map +1 -1
- package/dist/commands/bootstrap.js +6 -0
- package/dist/commands/bootstrap.js.map +1 -1
- package/dist/commands/dispatch.d.ts.map +1 -1
- package/dist/commands/dispatch.js +11 -1
- package/dist/commands/dispatch.js.map +1 -1
- package/dist/commands/doctor.d.ts +33 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +299 -12
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/kg-mirror.d.ts +18 -2
- package/dist/commands/kg-mirror.d.ts.map +1 -1
- package/dist/commands/kg-mirror.js +78 -3
- package/dist/commands/kg-mirror.js.map +1 -1
- package/dist/commands/mcp/complete.d.ts +36 -0
- package/dist/commands/mcp/complete.d.ts.map +1 -0
- package/dist/commands/mcp/complete.js +66 -0
- package/dist/commands/mcp/complete.js.map +1 -0
- package/dist/commands/mcp/index.d.ts +1 -1
- package/dist/commands/mcp/index.d.ts.map +1 -1
- package/dist/commands/mcp/index.js +3 -1
- package/dist/commands/mcp/index.js.map +1 -1
- package/dist/commands/memory/bridge.d.ts +1 -1
- package/dist/commands/memory/bridge.d.ts.map +1 -1
- package/dist/commands/memory/bridge.js +2 -6
- package/dist/commands/memory/bridge.js.map +1 -1
- package/dist/commands/memory/secret.d.ts.map +1 -1
- package/dist/commands/memory/secret.js +4 -3
- package/dist/commands/memory/secret.js.map +1 -1
- package/dist/commands/observe.d.ts +3 -3
- package/dist/commands/observe.d.ts.map +1 -1
- package/dist/commands/observe.js +11 -8
- package/dist/commands/observe.js.map +1 -1
- package/dist/commands/runbooks.d.ts.map +1 -1
- package/dist/commands/runbooks.js +77 -10
- package/dist/commands/runbooks.js.map +1 -1
- package/dist/commands/services-tls.d.ts.map +1 -1
- package/dist/commands/services-tls.js +65 -10
- package/dist/commands/services-tls.js.map +1 -1
- package/dist/commands/services.d.ts +35 -1
- package/dist/commands/services.d.ts.map +1 -1
- package/dist/commands/services.js +153 -32
- package/dist/commands/services.js.map +1 -1
- package/dist/commands/setup-phase-8-kg-hook.d.ts +48 -0
- package/dist/commands/setup-phase-8-kg-hook.d.ts.map +1 -0
- package/dist/commands/setup-phase-8-kg-hook.js +93 -0
- package/dist/commands/setup-phase-8-kg-hook.js.map +1 -0
- package/dist/commands/setup-phase-9-memory-bridge.d.ts +36 -0
- package/dist/commands/setup-phase-9-memory-bridge.d.ts.map +1 -0
- package/dist/commands/setup-phase-9-memory-bridge.js +59 -0
- package/dist/commands/setup-phase-9-memory-bridge.js.map +1 -0
- package/dist/commands/setup.d.ts +34 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +372 -32
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/skills-source.d.ts.map +1 -1
- package/dist/commands/skills-source.js +70 -1
- package/dist/commands/skills-source.js.map +1 -1
- package/dist/commands/update.d.ts +24 -0
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +53 -0
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/upgrade.d.ts +5 -0
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +31 -8
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/image-digests.json +8 -8
- package/dist/index.js +4487 -2451
- package/dist/lib/auth-backend.d.ts +168 -0
- package/dist/lib/auth-backend.d.ts.map +1 -0
- package/dist/lib/auth-backend.js +172 -0
- package/dist/lib/auth-backend.js.map +1 -0
- package/dist/lib/auth-list-cache.d.ts +67 -0
- package/dist/lib/auth-list-cache.d.ts.map +1 -0
- package/dist/lib/auth-list-cache.js +84 -0
- package/dist/lib/auth-list-cache.js.map +1 -0
- package/dist/lib/auth-list.d.ts +107 -0
- package/dist/lib/auth-list.d.ts.map +1 -0
- package/dist/lib/auth-list.js +123 -0
- package/dist/lib/auth-list.js.map +1 -0
- package/dist/lib/auth-login.d.ts +92 -0
- package/dist/lib/auth-login.d.ts.map +1 -0
- package/dist/lib/auth-login.js +124 -0
- package/dist/lib/auth-login.js.map +1 -0
- package/dist/lib/auth-mutator-backend.d.ts +54 -0
- package/dist/lib/auth-mutator-backend.d.ts.map +1 -0
- package/dist/lib/auth-mutator-backend.js +62 -0
- package/dist/lib/auth-mutator-backend.js.map +1 -0
- package/dist/lib/auth-remote.d.ts +50 -0
- package/dist/lib/auth-remote.d.ts.map +1 -1
- package/dist/lib/auth-remote.js +84 -2
- package/dist/lib/auth-remote.js.map +1 -1
- package/dist/lib/bootstrap-kubernetes.d.ts +69 -10
- package/dist/lib/bootstrap-kubernetes.d.ts.map +1 -1
- package/dist/lib/bootstrap-kubernetes.js +264 -46
- package/dist/lib/bootstrap-kubernetes.js.map +1 -1
- package/dist/lib/config.d.ts +35 -4
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +82 -11
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/health-probes.d.ts +0 -22
- package/dist/lib/health-probes.d.ts.map +1 -1
- package/dist/lib/health-probes.js +57 -0
- package/dist/lib/health-probes.js.map +1 -1
- package/dist/lib/peripheral-registry.d.ts +11 -0
- package/dist/lib/peripheral-registry.d.ts.map +1 -1
- package/dist/lib/peripheral-registry.js +5 -0
- package/dist/lib/peripheral-registry.js.map +1 -1
- package/dist/lib/plans-client.d.ts.map +1 -1
- package/dist/lib/plans-client.js +6 -3
- package/dist/lib/plans-client.js.map +1 -1
- package/dist/mcp-server.js +138 -6
- package/hermes-bundle/version.json +1 -1
- package/host-cp/k8s/manifests/30-configmap.yaml +4 -0
- package/host-cp/k8s/manifests/50-deployment.yaml +13 -1
- package/host-cp/k8s/manifests/65-tls-secret-template.yaml.tmpl +35 -0
- package/host-cp/k8s/manifests/auth-service/50-deployment.yaml +1 -1
- package/host-cp/k8s/manifests/kg-service/50-deployment.yaml +1 -1
- package/host-cp/k8s/manifests/mcp-auth-service/50-deployment.yaml +1 -1
- package/host-cp/k8s/manifests/memory-service/50-deployment.yaml +1 -1
- package/host-cp/src/dispatch-persister.mjs +157 -0
- package/host-cp/src/pr-nanny.mjs +7 -0
- package/host-cp/src/server.mjs +175 -3
- package/host-cp/src/world-watchdog-pid-lookup.mjs +119 -0
- package/host-cp/src/world-watchdog-probes.mjs +271 -0
- package/host-cp/src/world-watchdog-recovery.mjs +192 -0
- package/host-cp/src/world-watchdog.mjs +313 -0
- package/package.json +1 -1
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* auth-backend — shared backend resolver for `olam auth` subcommands.
|
|
3
|
+
*
|
|
4
|
+
* Phase B (cloud-only-vault) flips the default credential backend across the
|
|
5
|
+
* full CLI auth surface from local (`auth-service` container at 127.0.0.1:9999)
|
|
6
|
+
* to remote (cloud auth-worker, e.g. auth-worker.kaluga.co). This helper is the
|
|
7
|
+
* single seam every auth subcommand calls to determine which backend its
|
|
8
|
+
* action should target.
|
|
9
|
+
*
|
|
10
|
+
* Resolution order (mirrors docs/architecture/cloud-only-vault.md §2 for
|
|
11
|
+
* `withCredential`, adapted to the CLI's --local / --remote flag surface):
|
|
12
|
+
*
|
|
13
|
+
* 1. `--local` AND `--remote` (any form) both passed → throw
|
|
14
|
+
* `ConflictingBackendFlags` (exit 1 in the action handler).
|
|
15
|
+
* 2. `--local` alone → backend='local', emitDeprecationWarning=true
|
|
16
|
+
* (operator explicitly opted out of the new default; warn so they know
|
|
17
|
+
* the flag will eventually be removed).
|
|
18
|
+
* 3. `--remote` (boolean) alone → backend='remote', no warning.
|
|
19
|
+
* 4. `--remote <url>` (string form, back-compat) → backend='remote',
|
|
20
|
+
* explicitRemoteUrl=<url>. No warning. Pre-Phase-B operators were
|
|
21
|
+
* already opting in by typing the URL.
|
|
22
|
+
* 5. `OLAM_CREDENTIAL_BACKEND=local` env → backend='local', NO warning
|
|
23
|
+
* (env-set is the operator's host-wide preference; pestering them on
|
|
24
|
+
* every command is noise).
|
|
25
|
+
* 6. `OLAM_CREDENTIAL_BACKEND=remote` env → backend='remote', no warning.
|
|
26
|
+
* 7. Default → backend='remote' (the Phase B flip).
|
|
27
|
+
*
|
|
28
|
+
* The Phase A `withCredential` selector at
|
|
29
|
+
* `packages/auth-client/src/backends/selector.ts` honours the same env var
|
|
30
|
+
* for the agent runtime; this helper keeps the CLI surface symmetric.
|
|
31
|
+
*
|
|
32
|
+
* ─── Subcommand audit (current backend coupling, pre-Phase-B) ───
|
|
33
|
+
*
|
|
34
|
+
* Every existing `olam auth` subcommand and the code path it currently uses
|
|
35
|
+
* to reach a credential backend. Each is a future caller of `requireBackend`
|
|
36
|
+
* once B2 / B4 land. References are `packages/cli/src/commands/auth.ts` line
|
|
37
|
+
* numbers at HEAD = 3a74bb62 (Phase A complete).
|
|
38
|
+
*
|
|
39
|
+
* login (auth.ts:170-306) — `--remote <url>` already wired to
|
|
40
|
+
* auth-remote.ts `remoteOAuthStart` (auth.ts:178-238).
|
|
41
|
+
* Local path (auth.ts:240-305) uses `AuthClient` against
|
|
42
|
+
* 127.0.0.1:9999. B2 flips the default + adds the
|
|
43
|
+
* interactive confirm prompt + deprecation warning.
|
|
44
|
+
*
|
|
45
|
+
* list (auth.ts:416-509) — `--remote <url>` wired to
|
|
46
|
+
* `remoteListAccounts` + `remoteListServiceTokens`
|
|
47
|
+
* (auth.ts:423-464). Local path (auth.ts:466-508) uses
|
|
48
|
+
* `AuthClient.status()`. B4 flips default + adds 30s TTL
|
|
49
|
+
* cache + `--no-cache`.
|
|
50
|
+
*
|
|
51
|
+
* refresh (auth.ts:323-361) — LOCAL ONLY today. Reads config to
|
|
52
|
+
* detect k8s substrate, then calls `AuthClient.refreshAccount`.
|
|
53
|
+
* No --remote path exists yet. B4 adds a default-remote
|
|
54
|
+
* branch (token-refresh via cloud DO) + `--local` opt-out.
|
|
55
|
+
*
|
|
56
|
+
* disable (auth.ts:124-137) — LOCAL ONLY (AuthClient.disableAccount).
|
|
57
|
+
* B4 adds default-remote branch.
|
|
58
|
+
*
|
|
59
|
+
* enable (auth.ts:139-152) — LOCAL ONLY (AuthClient.enableAccount).
|
|
60
|
+
* B4 adds default-remote branch.
|
|
61
|
+
*
|
|
62
|
+
* status (auth.ts:116-122 — deprecated alias for `olam services
|
|
63
|
+
* status`) AND auth-status.ts:runAuthStatus (the real
|
|
64
|
+
* status implementation invoked by other code paths).
|
|
65
|
+
* LOCAL ONLY (AuthClient.status). B7 doctor sweep covers
|
|
66
|
+
* the cross-backend health view.
|
|
67
|
+
*
|
|
68
|
+
* list-json (auth-list-json.ts) — pure serialiser invoked from
|
|
69
|
+
* `list --json` (auth.ts:481-484). Operates on already-
|
|
70
|
+
* fetched local data. B4 keeps it local-only for now
|
|
71
|
+
* (the JSON wire shape is a local-vault contract).
|
|
72
|
+
*
|
|
73
|
+
* logout (auth.ts:308-321) — LOCAL ONLY (AuthClient.deleteAccount).
|
|
74
|
+
* Out of Phase B scope; tracked for a follow-up plan.
|
|
75
|
+
*
|
|
76
|
+
* remove (auth.ts:154-167) — LOCAL ONLY (AuthClient.deleteAccount).
|
|
77
|
+
* Out of Phase B scope.
|
|
78
|
+
*
|
|
79
|
+
* bind-service-token (auth.ts:363-413) — remote-only by design (CF
|
|
80
|
+
* Access service-token binding). No `requireBackend` needed.
|
|
81
|
+
*
|
|
82
|
+
* migrate-to-remote (auth.ts:511-543) — bridging command from e6; B3
|
|
83
|
+
* replaces this with `olam auth migrate`.
|
|
84
|
+
*
|
|
85
|
+
* rotate-service-token (auth.ts:545-572) — remote-only. No change.
|
|
86
|
+
*
|
|
87
|
+
* doctor (auth.ts:574-614) — remote-only probe today; B7
|
|
88
|
+
* extends to dual-backend health.
|
|
89
|
+
*
|
|
90
|
+
* issue-anthropic-token (auth.ts:616-684) — remote-only. No change.
|
|
91
|
+
*
|
|
92
|
+
* list-anthropic-tokens (auth.ts:686-740) — remote-only. No change.
|
|
93
|
+
*
|
|
94
|
+
* revoke-anthropic-token (auth.ts:742-773) — remote-only. No change.
|
|
95
|
+
*
|
|
96
|
+
* upgrade (registered via registerAuthUpgrade(auth) at
|
|
97
|
+
* auth.ts:775) — separate file; out of Phase B scope.
|
|
98
|
+
*
|
|
99
|
+
* Subcommands flagged "LOCAL ONLY" today are the ones B4 will refactor to
|
|
100
|
+
* route through `requireBackend`. The "remote-only by design" subcommands
|
|
101
|
+
* (bind-service-token, doctor, issue/list/revoke anthropic tokens) keep
|
|
102
|
+
* their `--remote` required flag — they have no local equivalent.
|
|
103
|
+
*/
|
|
104
|
+
/** Discriminant for the resolved credential backend. */
|
|
105
|
+
export type Backend = 'local' | 'remote';
|
|
106
|
+
/**
|
|
107
|
+
* Parsed CLI flags relevant to backend selection. Commander.js gives us
|
|
108
|
+
* `--remote` as boolean OR string depending on the option definition; we
|
|
109
|
+
* support both forms so subcommands can choose:
|
|
110
|
+
*
|
|
111
|
+
* .option('--remote', '...') // boolean
|
|
112
|
+
* .option('--remote <url>', '...') // string (back-compat)
|
|
113
|
+
*
|
|
114
|
+
* Mixed-cardinality subcommands (login, list) historically used the string
|
|
115
|
+
* form; future cleanup may collapse to boolean once the artifact-based
|
|
116
|
+
* default URL discovery (Phase A `~/.olam/cloud-bearer.json`) covers all
|
|
117
|
+
* call sites.
|
|
118
|
+
*/
|
|
119
|
+
export interface BackendResolutionArgs {
|
|
120
|
+
readonly local?: boolean;
|
|
121
|
+
readonly remote?: boolean | string;
|
|
122
|
+
}
|
|
123
|
+
export interface BackendResolution {
|
|
124
|
+
readonly backend: Backend;
|
|
125
|
+
/**
|
|
126
|
+
* When backend='remote' and the operator passed `--remote <url>` (string
|
|
127
|
+
* form), the explicit URL. Subcommands prefer this over auto-discovered
|
|
128
|
+
* defaults (env / artifact / hard-coded fallback).
|
|
129
|
+
*/
|
|
130
|
+
readonly explicitRemoteUrl?: string;
|
|
131
|
+
/**
|
|
132
|
+
* True when the operator passed `--local` on the CLI. Used by callers to
|
|
133
|
+
* emit a single deprecation-warning line to stderr before proceeding.
|
|
134
|
+
* False for `OLAM_CREDENTIAL_BACKEND=local` — that's a host-wide opt-out
|
|
135
|
+
* the operator already understands, no need to nag every command.
|
|
136
|
+
*/
|
|
137
|
+
readonly emitDeprecationWarning: boolean;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Thrown when the operator passes `--local` AND `--remote` to the same
|
|
141
|
+
* subcommand. Both flags express intent — there's no sane way to choose
|
|
142
|
+
* one silently. Action handlers should `printError(err.message); exit 1`.
|
|
143
|
+
*/
|
|
144
|
+
export declare class ConflictingBackendFlags extends Error {
|
|
145
|
+
constructor();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Resolve which credential backend a subcommand should target.
|
|
149
|
+
*
|
|
150
|
+
* See the resolution-order comment at the top of this file for the seven
|
|
151
|
+
* branches. Pure function — no I/O, no side effects, no caching. Cheap
|
|
152
|
+
* enough to call once per subcommand action.
|
|
153
|
+
*
|
|
154
|
+
* Reads `process.env.OLAM_CREDENTIAL_BACKEND` directly so callers don't
|
|
155
|
+
* have to thread it through.
|
|
156
|
+
*/
|
|
157
|
+
export declare function requireBackend(args: BackendResolutionArgs): BackendResolution;
|
|
158
|
+
/**
|
|
159
|
+
* Emit a single deprecation-warning line to the supplied stream. Centralised
|
|
160
|
+
* so the wording stays consistent across every `olam auth` subcommand that
|
|
161
|
+
* accepts `--local`. Returns void; callers may ignore the return.
|
|
162
|
+
*
|
|
163
|
+
* Callers should only invoke this when
|
|
164
|
+
* `resolution.emitDeprecationWarning === true` — gating belongs to the
|
|
165
|
+
* caller so test scaffolding can introspect the resolution without IO.
|
|
166
|
+
*/
|
|
167
|
+
export declare function emitDeprecationWarning(stderr: NodeJS.WritableStream): void;
|
|
168
|
+
//# sourceMappingURL=auth-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-backend.d.ts","sourceRoot":"","sources":["../../src/lib/auth-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsGG;AAEH,wDAAwD;AACxD,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEzC;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CACpC;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,sBAAsB,EAAE,OAAO,CAAC;CAC1C;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;;CAKjD;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,qBAAqB,GAAG,iBAAiB,CAwC7E;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,GAAG,IAAI,CAK1E"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* auth-backend — shared backend resolver for `olam auth` subcommands.
|
|
3
|
+
*
|
|
4
|
+
* Phase B (cloud-only-vault) flips the default credential backend across the
|
|
5
|
+
* full CLI auth surface from local (`auth-service` container at 127.0.0.1:9999)
|
|
6
|
+
* to remote (cloud auth-worker, e.g. auth-worker.kaluga.co). This helper is the
|
|
7
|
+
* single seam every auth subcommand calls to determine which backend its
|
|
8
|
+
* action should target.
|
|
9
|
+
*
|
|
10
|
+
* Resolution order (mirrors docs/architecture/cloud-only-vault.md §2 for
|
|
11
|
+
* `withCredential`, adapted to the CLI's --local / --remote flag surface):
|
|
12
|
+
*
|
|
13
|
+
* 1. `--local` AND `--remote` (any form) both passed → throw
|
|
14
|
+
* `ConflictingBackendFlags` (exit 1 in the action handler).
|
|
15
|
+
* 2. `--local` alone → backend='local', emitDeprecationWarning=true
|
|
16
|
+
* (operator explicitly opted out of the new default; warn so they know
|
|
17
|
+
* the flag will eventually be removed).
|
|
18
|
+
* 3. `--remote` (boolean) alone → backend='remote', no warning.
|
|
19
|
+
* 4. `--remote <url>` (string form, back-compat) → backend='remote',
|
|
20
|
+
* explicitRemoteUrl=<url>. No warning. Pre-Phase-B operators were
|
|
21
|
+
* already opting in by typing the URL.
|
|
22
|
+
* 5. `OLAM_CREDENTIAL_BACKEND=local` env → backend='local', NO warning
|
|
23
|
+
* (env-set is the operator's host-wide preference; pestering them on
|
|
24
|
+
* every command is noise).
|
|
25
|
+
* 6. `OLAM_CREDENTIAL_BACKEND=remote` env → backend='remote', no warning.
|
|
26
|
+
* 7. Default → backend='remote' (the Phase B flip).
|
|
27
|
+
*
|
|
28
|
+
* The Phase A `withCredential` selector at
|
|
29
|
+
* `packages/auth-client/src/backends/selector.ts` honours the same env var
|
|
30
|
+
* for the agent runtime; this helper keeps the CLI surface symmetric.
|
|
31
|
+
*
|
|
32
|
+
* ─── Subcommand audit (current backend coupling, pre-Phase-B) ───
|
|
33
|
+
*
|
|
34
|
+
* Every existing `olam auth` subcommand and the code path it currently uses
|
|
35
|
+
* to reach a credential backend. Each is a future caller of `requireBackend`
|
|
36
|
+
* once B2 / B4 land. References are `packages/cli/src/commands/auth.ts` line
|
|
37
|
+
* numbers at HEAD = 3a74bb62 (Phase A complete).
|
|
38
|
+
*
|
|
39
|
+
* login (auth.ts:170-306) — `--remote <url>` already wired to
|
|
40
|
+
* auth-remote.ts `remoteOAuthStart` (auth.ts:178-238).
|
|
41
|
+
* Local path (auth.ts:240-305) uses `AuthClient` against
|
|
42
|
+
* 127.0.0.1:9999. B2 flips the default + adds the
|
|
43
|
+
* interactive confirm prompt + deprecation warning.
|
|
44
|
+
*
|
|
45
|
+
* list (auth.ts:416-509) — `--remote <url>` wired to
|
|
46
|
+
* `remoteListAccounts` + `remoteListServiceTokens`
|
|
47
|
+
* (auth.ts:423-464). Local path (auth.ts:466-508) uses
|
|
48
|
+
* `AuthClient.status()`. B4 flips default + adds 30s TTL
|
|
49
|
+
* cache + `--no-cache`.
|
|
50
|
+
*
|
|
51
|
+
* refresh (auth.ts:323-361) — LOCAL ONLY today. Reads config to
|
|
52
|
+
* detect k8s substrate, then calls `AuthClient.refreshAccount`.
|
|
53
|
+
* No --remote path exists yet. B4 adds a default-remote
|
|
54
|
+
* branch (token-refresh via cloud DO) + `--local` opt-out.
|
|
55
|
+
*
|
|
56
|
+
* disable (auth.ts:124-137) — LOCAL ONLY (AuthClient.disableAccount).
|
|
57
|
+
* B4 adds default-remote branch.
|
|
58
|
+
*
|
|
59
|
+
* enable (auth.ts:139-152) — LOCAL ONLY (AuthClient.enableAccount).
|
|
60
|
+
* B4 adds default-remote branch.
|
|
61
|
+
*
|
|
62
|
+
* status (auth.ts:116-122 — deprecated alias for `olam services
|
|
63
|
+
* status`) AND auth-status.ts:runAuthStatus (the real
|
|
64
|
+
* status implementation invoked by other code paths).
|
|
65
|
+
* LOCAL ONLY (AuthClient.status). B7 doctor sweep covers
|
|
66
|
+
* the cross-backend health view.
|
|
67
|
+
*
|
|
68
|
+
* list-json (auth-list-json.ts) — pure serialiser invoked from
|
|
69
|
+
* `list --json` (auth.ts:481-484). Operates on already-
|
|
70
|
+
* fetched local data. B4 keeps it local-only for now
|
|
71
|
+
* (the JSON wire shape is a local-vault contract).
|
|
72
|
+
*
|
|
73
|
+
* logout (auth.ts:308-321) — LOCAL ONLY (AuthClient.deleteAccount).
|
|
74
|
+
* Out of Phase B scope; tracked for a follow-up plan.
|
|
75
|
+
*
|
|
76
|
+
* remove (auth.ts:154-167) — LOCAL ONLY (AuthClient.deleteAccount).
|
|
77
|
+
* Out of Phase B scope.
|
|
78
|
+
*
|
|
79
|
+
* bind-service-token (auth.ts:363-413) — remote-only by design (CF
|
|
80
|
+
* Access service-token binding). No `requireBackend` needed.
|
|
81
|
+
*
|
|
82
|
+
* migrate-to-remote (auth.ts:511-543) — bridging command from e6; B3
|
|
83
|
+
* replaces this with `olam auth migrate`.
|
|
84
|
+
*
|
|
85
|
+
* rotate-service-token (auth.ts:545-572) — remote-only. No change.
|
|
86
|
+
*
|
|
87
|
+
* doctor (auth.ts:574-614) — remote-only probe today; B7
|
|
88
|
+
* extends to dual-backend health.
|
|
89
|
+
*
|
|
90
|
+
* issue-anthropic-token (auth.ts:616-684) — remote-only. No change.
|
|
91
|
+
*
|
|
92
|
+
* list-anthropic-tokens (auth.ts:686-740) — remote-only. No change.
|
|
93
|
+
*
|
|
94
|
+
* revoke-anthropic-token (auth.ts:742-773) — remote-only. No change.
|
|
95
|
+
*
|
|
96
|
+
* upgrade (registered via registerAuthUpgrade(auth) at
|
|
97
|
+
* auth.ts:775) — separate file; out of Phase B scope.
|
|
98
|
+
*
|
|
99
|
+
* Subcommands flagged "LOCAL ONLY" today are the ones B4 will refactor to
|
|
100
|
+
* route through `requireBackend`. The "remote-only by design" subcommands
|
|
101
|
+
* (bind-service-token, doctor, issue/list/revoke anthropic tokens) keep
|
|
102
|
+
* their `--remote` required flag — they have no local equivalent.
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* Thrown when the operator passes `--local` AND `--remote` to the same
|
|
106
|
+
* subcommand. Both flags express intent — there's no sane way to choose
|
|
107
|
+
* one silently. Action handlers should `printError(err.message); exit 1`.
|
|
108
|
+
*/
|
|
109
|
+
export class ConflictingBackendFlags extends Error {
|
|
110
|
+
constructor() {
|
|
111
|
+
super('Cannot specify both --local and --remote. Pick one.');
|
|
112
|
+
this.name = 'ConflictingBackendFlags';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Resolve which credential backend a subcommand should target.
|
|
117
|
+
*
|
|
118
|
+
* See the resolution-order comment at the top of this file for the seven
|
|
119
|
+
* branches. Pure function — no I/O, no side effects, no caching. Cheap
|
|
120
|
+
* enough to call once per subcommand action.
|
|
121
|
+
*
|
|
122
|
+
* Reads `process.env.OLAM_CREDENTIAL_BACKEND` directly so callers don't
|
|
123
|
+
* have to thread it through.
|
|
124
|
+
*/
|
|
125
|
+
export function requireBackend(args) {
|
|
126
|
+
const localFlag = args.local === true;
|
|
127
|
+
const remoteFlag = args.remote === true || (typeof args.remote === 'string' && args.remote.length > 0);
|
|
128
|
+
// (1) Conflict — both flags explicit.
|
|
129
|
+
if (localFlag && remoteFlag) {
|
|
130
|
+
throw new ConflictingBackendFlags();
|
|
131
|
+
}
|
|
132
|
+
// (2) Explicit --local opt-out.
|
|
133
|
+
if (localFlag) {
|
|
134
|
+
return { backend: 'local', emitDeprecationWarning: true };
|
|
135
|
+
}
|
|
136
|
+
// (3) Explicit --remote (boolean).
|
|
137
|
+
if (args.remote === true) {
|
|
138
|
+
return { backend: 'remote', emitDeprecationWarning: false };
|
|
139
|
+
}
|
|
140
|
+
// (4) Explicit --remote <url> (string).
|
|
141
|
+
if (typeof args.remote === 'string' && args.remote.length > 0) {
|
|
142
|
+
return {
|
|
143
|
+
backend: 'remote',
|
|
144
|
+
explicitRemoteUrl: args.remote,
|
|
145
|
+
emitDeprecationWarning: false,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
// (5) + (6) Env-set override.
|
|
149
|
+
const env = process.env['OLAM_CREDENTIAL_BACKEND'];
|
|
150
|
+
if (env === 'local') {
|
|
151
|
+
return { backend: 'local', emitDeprecationWarning: false };
|
|
152
|
+
}
|
|
153
|
+
if (env === 'remote') {
|
|
154
|
+
return { backend: 'remote', emitDeprecationWarning: false };
|
|
155
|
+
}
|
|
156
|
+
// (7) Default — Phase B flip: remote.
|
|
157
|
+
return { backend: 'remote', emitDeprecationWarning: false };
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Emit a single deprecation-warning line to the supplied stream. Centralised
|
|
161
|
+
* so the wording stays consistent across every `olam auth` subcommand that
|
|
162
|
+
* accepts `--local`. Returns void; callers may ignore the return.
|
|
163
|
+
*
|
|
164
|
+
* Callers should only invoke this when
|
|
165
|
+
* `resolution.emitDeprecationWarning === true` — gating belongs to the
|
|
166
|
+
* caller so test scaffolding can introspect the resolution without IO.
|
|
167
|
+
*/
|
|
168
|
+
export function emitDeprecationWarning(stderr) {
|
|
169
|
+
stderr.write('warning: --local flag is deprecated. Cloud auth-worker is now the default. ' +
|
|
170
|
+
'See docs/plans/cloud-only-vault/.\n');
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=auth-backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-backend.js","sourceRoot":"","sources":["../../src/lib/auth-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsGG;AAwCH;;;;GAIG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD;QACE,KAAK,CAAC,qDAAqD,CAAC,CAAC;QAC7D,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAA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AQ,EAAE,sBAAsB,EAAE,KAAK,EAAE,CAAC;IAC9D,CAAC;IAED,sCAAsC;IACtC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,KAAK,EAAE,CAAC;AAC9D,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAA6B;IAClE,MAAM,CAAC,KAAK,CACV,6EAA6E;QAC3E,qCAAqC,CACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* auth-list-cache — in-process TTL cache for `olam auth list --remote` results.
|
|
3
|
+
*
|
|
4
|
+
* Phase B (cloud-only-vault) Decision D5 caches remote `auth list` results for
|
|
5
|
+
* 30 seconds in-memory (NOT persisted to disk). The cache keeps interactive
|
|
6
|
+
* runs cheap and lets driver scripts (e.g. `olam doctor` probes that fan out
|
|
7
|
+
* to `auth list` for credential health) avoid hammering the cloud DO.
|
|
8
|
+
*
|
|
9
|
+
* Two-tier read model: `getCachedAuthList` returns a FRESH entry (within TTL),
|
|
10
|
+
* `getStaleAuthList` returns the most recent entry regardless of age — the
|
|
11
|
+
* latter is the offline fallback used when a fresh fetch fails. The command
|
|
12
|
+
* action surfaces staleness to the operator via a `(stale)` annotation +
|
|
13
|
+
* footer warning.
|
|
14
|
+
*
|
|
15
|
+
* Key shape: callers compose a key from (baseUrl, identityHint). A single
|
|
16
|
+
* Map keyed by that string keeps multiple auth-worker targets isolated (an
|
|
17
|
+
* operator running `auth list --remote A` then `--remote B` shouldn't see
|
|
18
|
+
* A's results for B).
|
|
19
|
+
*
|
|
20
|
+
* Not persisted: this cache lives only as long as the CLI process. Phase D
|
|
21
|
+
* may extend to a file-based cache if operator runs frequent short-lived
|
|
22
|
+
* `olam auth list` invocations and pays a real RTT cost — but the in-process
|
|
23
|
+
* model is simpler + correct for the most common cases (interactive use,
|
|
24
|
+
* tight-loop script invocations within a single CLI process).
|
|
25
|
+
*
|
|
26
|
+
* Concurrency: single-threaded JS; no locking needed. Read returns the
|
|
27
|
+
* snapshot at-call-time.
|
|
28
|
+
*/
|
|
29
|
+
/** TTL in milliseconds — 30 seconds per Decision D5. */
|
|
30
|
+
export declare const AUTH_LIST_CACHE_TTL_MS = 30000;
|
|
31
|
+
/**
|
|
32
|
+
* Return the cached entry for `key` when it's within the TTL window.
|
|
33
|
+
* Returns `null` when the entry is missing OR stale. `now` is injectable
|
|
34
|
+
* for deterministic tests; production callers omit it.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getCachedAuthList<T>(key: string, now?: number): {
|
|
37
|
+
result: T;
|
|
38
|
+
fetchedAt: number;
|
|
39
|
+
} | null;
|
|
40
|
+
/**
|
|
41
|
+
* Return the cached entry for `key` regardless of age. Used as the
|
|
42
|
+
* offline fallback when a fresh fetch fails. Returns `null` when the
|
|
43
|
+
* cache has never seen this key.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getStaleAuthList<T>(key: string): {
|
|
46
|
+
result: T;
|
|
47
|
+
fetchedAt: number;
|
|
48
|
+
} | null;
|
|
49
|
+
/**
|
|
50
|
+
* Insert / replace the cached entry for `key`. `now` is injectable for tests.
|
|
51
|
+
*/
|
|
52
|
+
export declare function setCachedAuthList<T>(key: string, result: T, now?: number): void;
|
|
53
|
+
/**
|
|
54
|
+
* Invalidate the entry for `key`. When `key` is omitted, clear the entire
|
|
55
|
+
* cache. Callers use this after a mutation that the next `list` MUST reflect
|
|
56
|
+
* (e.g. an explicit `auth login` succeeded against the same baseUrl) — though
|
|
57
|
+
* for B4 (narrowed) such mutations live on the local backend so callers will
|
|
58
|
+
* mostly leave the cache to expire naturally.
|
|
59
|
+
*/
|
|
60
|
+
export declare function invalidateAuthListCache(key?: string): void;
|
|
61
|
+
/**
|
|
62
|
+
* Test-only: wipes the module-level cache. Production code MUST NOT call
|
|
63
|
+
* this. Tests that share the module across describe blocks call it in a
|
|
64
|
+
* `beforeEach` to keep the cache deterministic.
|
|
65
|
+
*/
|
|
66
|
+
export declare function _resetAuthListCacheForTests(): void;
|
|
67
|
+
//# sourceMappingURL=auth-list-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-list-cache.d.ts","sourceRoot":"","sources":["../../src/lib/auth-list-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,wDAAwD;AACxD,eAAO,MAAM,sBAAsB,QAAS,CAAC;AAS7C;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,GAAG,EAAE,MAAM,EACX,GAAG,GAAE,MAAmB,GACvB;IAAE,MAAM,EAAE,CAAC,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAKzC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,GAAG,EAAE,MAAM,GACV;IAAE,MAAM,EAAE,CAAC,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAIzC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,CAAC,EACT,GAAG,GAAE,MAAmB,GACvB,IAAI,CAEN;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAM1D;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,IAAI,IAAI,CAElD"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* auth-list-cache — in-process TTL cache for `olam auth list --remote` results.
|
|
3
|
+
*
|
|
4
|
+
* Phase B (cloud-only-vault) Decision D5 caches remote `auth list` results for
|
|
5
|
+
* 30 seconds in-memory (NOT persisted to disk). The cache keeps interactive
|
|
6
|
+
* runs cheap and lets driver scripts (e.g. `olam doctor` probes that fan out
|
|
7
|
+
* to `auth list` for credential health) avoid hammering the cloud DO.
|
|
8
|
+
*
|
|
9
|
+
* Two-tier read model: `getCachedAuthList` returns a FRESH entry (within TTL),
|
|
10
|
+
* `getStaleAuthList` returns the most recent entry regardless of age — the
|
|
11
|
+
* latter is the offline fallback used when a fresh fetch fails. The command
|
|
12
|
+
* action surfaces staleness to the operator via a `(stale)` annotation +
|
|
13
|
+
* footer warning.
|
|
14
|
+
*
|
|
15
|
+
* Key shape: callers compose a key from (baseUrl, identityHint). A single
|
|
16
|
+
* Map keyed by that string keeps multiple auth-worker targets isolated (an
|
|
17
|
+
* operator running `auth list --remote A` then `--remote B` shouldn't see
|
|
18
|
+
* A's results for B).
|
|
19
|
+
*
|
|
20
|
+
* Not persisted: this cache lives only as long as the CLI process. Phase D
|
|
21
|
+
* may extend to a file-based cache if operator runs frequent short-lived
|
|
22
|
+
* `olam auth list` invocations and pays a real RTT cost — but the in-process
|
|
23
|
+
* model is simpler + correct for the most common cases (interactive use,
|
|
24
|
+
* tight-loop script invocations within a single CLI process).
|
|
25
|
+
*
|
|
26
|
+
* Concurrency: single-threaded JS; no locking needed. Read returns the
|
|
27
|
+
* snapshot at-call-time.
|
|
28
|
+
*/
|
|
29
|
+
/** TTL in milliseconds — 30 seconds per Decision D5. */
|
|
30
|
+
export const AUTH_LIST_CACHE_TTL_MS = 30_000;
|
|
31
|
+
const cache = new Map();
|
|
32
|
+
/**
|
|
33
|
+
* Return the cached entry for `key` when it's within the TTL window.
|
|
34
|
+
* Returns `null` when the entry is missing OR stale. `now` is injectable
|
|
35
|
+
* for deterministic tests; production callers omit it.
|
|
36
|
+
*/
|
|
37
|
+
export function getCachedAuthList(key, now = Date.now()) {
|
|
38
|
+
const entry = cache.get(key);
|
|
39
|
+
if (!entry)
|
|
40
|
+
return null;
|
|
41
|
+
if (now - entry.fetchedAt > AUTH_LIST_CACHE_TTL_MS)
|
|
42
|
+
return null;
|
|
43
|
+
return { result: entry.result, fetchedAt: entry.fetchedAt };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Return the cached entry for `key` regardless of age. Used as the
|
|
47
|
+
* offline fallback when a fresh fetch fails. Returns `null` when the
|
|
48
|
+
* cache has never seen this key.
|
|
49
|
+
*/
|
|
50
|
+
export function getStaleAuthList(key) {
|
|
51
|
+
const entry = cache.get(key);
|
|
52
|
+
if (!entry)
|
|
53
|
+
return null;
|
|
54
|
+
return { result: entry.result, fetchedAt: entry.fetchedAt };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Insert / replace the cached entry for `key`. `now` is injectable for tests.
|
|
58
|
+
*/
|
|
59
|
+
export function setCachedAuthList(key, result, now = Date.now()) {
|
|
60
|
+
cache.set(key, { result, fetchedAt: now });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Invalidate the entry for `key`. When `key` is omitted, clear the entire
|
|
64
|
+
* cache. Callers use this after a mutation that the next `list` MUST reflect
|
|
65
|
+
* (e.g. an explicit `auth login` succeeded against the same baseUrl) — though
|
|
66
|
+
* for B4 (narrowed) such mutations live on the local backend so callers will
|
|
67
|
+
* mostly leave the cache to expire naturally.
|
|
68
|
+
*/
|
|
69
|
+
export function invalidateAuthListCache(key) {
|
|
70
|
+
if (key === undefined) {
|
|
71
|
+
cache.clear();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
cache.delete(key);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Test-only: wipes the module-level cache. Production code MUST NOT call
|
|
78
|
+
* this. Tests that share the module across describe blocks call it in a
|
|
79
|
+
* `beforeEach` to keep the cache deterministic.
|
|
80
|
+
*/
|
|
81
|
+
export function _resetAuthListCacheForTests() {
|
|
82
|
+
cache.clear();
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=auth-list-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-list-cache.js","sourceRoot":"","sources":["../../src/lib/auth-list-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;G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AAM,UAAU,2BAA2B;IACzC,KAAK,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* auth-list — testable orchestration for `olam auth list` and `auth list --json`.
|
|
3
|
+
*
|
|
4
|
+
* Phase B (cloud-only-vault) Decision D5: `olam auth list` defaults to the
|
|
5
|
+
* cloud auth-worker (cf. B1 / B2). This module:
|
|
6
|
+
*
|
|
7
|
+
* 1. Resolves the backend via B1's `requireBackend`.
|
|
8
|
+
* 2. Resolves the remote URL via the same precedence used by `auth login`
|
|
9
|
+
* (explicit `--remote <url>` > env > file > hard-coded fallback).
|
|
10
|
+
* 3. Consults the in-process TTL cache (30 s per D5) when backend='remote'
|
|
11
|
+
* and `--no-cache` was NOT passed.
|
|
12
|
+
* 4. Falls back to the stale cache when a fresh fetch fails (offline UX).
|
|
13
|
+
* 5. Routes to `AuthClient.status()` on the local backend.
|
|
14
|
+
*
|
|
15
|
+
* The Commander.js action handler in `packages/cli/src/commands/auth.ts`
|
|
16
|
+
* binds the IO touchpoints (cache helpers, fetch, AuthClient) via the
|
|
17
|
+
* `AuthListDeps` struct and consumes the structured `AuthListResult` to
|
|
18
|
+
* render the table or JSON output.
|
|
19
|
+
*
|
|
20
|
+
* Coupling note: the result object holds the raw remote payload (when
|
|
21
|
+
* backend='remote') OR the AuthAccountSummary[] (when backend='local'). The
|
|
22
|
+
* caller picks the right renderer (`renderAuthListJson` for local-JSON,
|
|
23
|
+
* `renderRemoteAuthListJson` for remote-JSON, or a text table for either).
|
|
24
|
+
* This keeps the IO + presentation concerns out of this module while still
|
|
25
|
+
* giving the action a single decision-tree entrypoint.
|
|
26
|
+
*/
|
|
27
|
+
import { AUTH_LIST_CACHE_TTL_MS } from './auth-list-cache.js';
|
|
28
|
+
import type { AccountEntry } from './auth-remote.js';
|
|
29
|
+
import type { AuthAccountSummary } from '@olam/core/src/auth/types.js';
|
|
30
|
+
/** Options parsed from Commander for `olam auth list` and `auth list --json`. */
|
|
31
|
+
export interface AuthListOptions {
|
|
32
|
+
readonly local?: boolean;
|
|
33
|
+
readonly remote?: boolean | string;
|
|
34
|
+
/** When true, bypass the 30 s TTL cache and force a fresh fetch. */
|
|
35
|
+
readonly noCache?: boolean;
|
|
36
|
+
/** Renders the result as JSON instead of the text table. */
|
|
37
|
+
readonly json?: boolean;
|
|
38
|
+
/** CF_Authorization cookie value (manual paste from DevTools). */
|
|
39
|
+
readonly cookie?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Outcome of the remote path: the raw `AccountEntry[]` (post-`remoteListAccounts`
|
|
43
|
+
* normalisation) along with staleness metadata.
|
|
44
|
+
*/
|
|
45
|
+
export interface RemoteListResult {
|
|
46
|
+
readonly mode: 'remote';
|
|
47
|
+
readonly baseUrl: string;
|
|
48
|
+
readonly accounts: ReadonlyArray<AccountEntry>;
|
|
49
|
+
/**
|
|
50
|
+
* True iff the result came from the stale-cache fallback path (a fresh
|
|
51
|
+
* fetch was attempted AND failed). The caller surfaces a `(stale)`
|
|
52
|
+
* annotation + warning footer in this case.
|
|
53
|
+
*/
|
|
54
|
+
readonly stale: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Epoch ms when the payload was originally fetched. Equal to "now" on a
|
|
57
|
+
* fresh fetch / cache hit; older when stale.
|
|
58
|
+
*/
|
|
59
|
+
readonly fetchedAt: number;
|
|
60
|
+
/** Optional error message from the failed fresh fetch (stale path only). */
|
|
61
|
+
readonly fetchError?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface LocalListResult {
|
|
64
|
+
readonly mode: 'local';
|
|
65
|
+
readonly reachable: boolean;
|
|
66
|
+
readonly accounts: ReadonlyArray<AuthAccountSummary>;
|
|
67
|
+
}
|
|
68
|
+
export interface AuthListError {
|
|
69
|
+
readonly mode: 'error';
|
|
70
|
+
readonly exitCode: 1;
|
|
71
|
+
readonly message: string;
|
|
72
|
+
}
|
|
73
|
+
export type AuthListResult = RemoteListResult | LocalListResult | AuthListError;
|
|
74
|
+
/**
|
|
75
|
+
* Injection seam — every IO touchpoint is funnelled through this struct so
|
|
76
|
+
* unit tests assert on orchestration without real HTTP, filesystem reads,
|
|
77
|
+
* or AuthClient round-trips.
|
|
78
|
+
*/
|
|
79
|
+
export interface AuthListDeps {
|
|
80
|
+
readonly readEnv?: (key: string) => string | undefined;
|
|
81
|
+
readonly readAuthWorkerUrlFile?: () => string | null;
|
|
82
|
+
/** Fresh fetch against the remote. Returns the `AccountEntry[]`. */
|
|
83
|
+
readonly fetchRemoteAccounts: (baseUrl: string, cookie?: string) => Promise<ReadonlyArray<AccountEntry>>;
|
|
84
|
+
/** Local backend status — usually `() => new AuthClient().status()`. */
|
|
85
|
+
readonly fetchLocalStatus: () => Promise<{
|
|
86
|
+
reachable: boolean;
|
|
87
|
+
accounts: readonly AuthAccountSummary[];
|
|
88
|
+
}>;
|
|
89
|
+
readonly stderr?: NodeJS.WritableStream;
|
|
90
|
+
/** Test injection for cache TTL semantics; defaults to Date.now(). */
|
|
91
|
+
readonly now?: () => number;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Compose the cache key for a (baseUrl, cookie) pair. The cookie value is
|
|
95
|
+
* included because two operators on the same host (sharing the CLI process,
|
|
96
|
+
* unlikely but possible in CI) may target the same baseUrl with different
|
|
97
|
+
* identities — caching across that boundary would leak one operator's
|
|
98
|
+
* accounts to the other.
|
|
99
|
+
*/
|
|
100
|
+
export declare function authListCacheKey(baseUrl: string, cookie?: string): string;
|
|
101
|
+
/**
|
|
102
|
+
* Run the `olam auth list` decision tree. Tests inject `fetchRemoteAccounts`
|
|
103
|
+
* and `fetchLocalStatus` to capture orchestration.
|
|
104
|
+
*/
|
|
105
|
+
export declare function runAuthList(opts: AuthListOptions, deps: AuthListDeps): Promise<AuthListResult>;
|
|
106
|
+
export { AUTH_LIST_CACHE_TTL_MS };
|
|
107
|
+
//# sourceMappingURL=auth-list.d.ts.map
|
|
@@ -0,0 +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