@ora-ai/cli 0.23.0 → 0.25.0
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/CHANGELOG.md +77 -0
- package/README.md +44 -13
- package/dist/agent-skills/skills-command.d.ts.map +1 -1
- package/dist/agent-skills/skills-command.js +2 -2
- package/dist/agent-skills/skills-command.js.map +1 -1
- package/dist/auth-commands.d.ts +25 -9
- package/dist/auth-commands.d.ts.map +1 -1
- package/dist/auth-commands.js +59 -49
- package/dist/auth-commands.js.map +1 -1
- package/dist/core/auth.d.ts +2 -2
- package/dist/core/auth.d.ts.map +1 -1
- package/dist/core/auth.js +5 -4
- package/dist/core/auth.js.map +1 -1
- package/dist/core/cli-arguments.d.ts +21 -0
- package/dist/core/cli-arguments.d.ts.map +1 -0
- package/dist/core/cli-arguments.js +53 -0
- package/dist/core/cli-arguments.js.map +1 -0
- package/dist/core/config.d.ts +10 -5
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +10 -7
- package/dist/core/config.js.map +1 -1
- package/dist/core/credentials/api-key-credential.d.ts +29 -0
- package/dist/core/credentials/api-key-credential.d.ts.map +1 -0
- package/dist/core/credentials/api-key-credential.js +58 -0
- package/dist/core/credentials/api-key-credential.js.map +1 -0
- package/dist/core/credentials/ci-oidc-credential.d.ts +44 -0
- package/dist/core/credentials/ci-oidc-credential.d.ts.map +1 -0
- package/dist/core/credentials/ci-oidc-credential.js +82 -0
- package/dist/core/credentials/ci-oidc-credential.js.map +1 -0
- package/dist/core/credentials/credential-chain.d.ts +25 -0
- package/dist/core/credentials/credential-chain.d.ts.map +1 -0
- package/dist/core/credentials/credential-chain.js +39 -0
- package/dist/core/credentials/credential-chain.js.map +1 -0
- package/dist/core/credentials/credential.d.ts +73 -0
- package/dist/core/credentials/credential.d.ts.map +1 -0
- package/dist/core/credentials/credential.js +9 -0
- package/dist/core/credentials/credential.js.map +1 -0
- package/dist/core/credentials/device-session-credential.d.ts +27 -0
- package/dist/core/credentials/device-session-credential.d.ts.map +1 -0
- package/dist/core/credentials/device-session-credential.js +78 -0
- package/dist/core/credentials/device-session-credential.js.map +1 -0
- package/dist/core/credentials/identity-lines.d.ts +14 -0
- package/dist/core/credentials/identity-lines.d.ts.map +1 -0
- package/dist/core/credentials/identity-lines.js +45 -0
- package/dist/core/credentials/identity-lines.js.map +1 -0
- package/dist/core/credentials/refusal-words.d.ts +15 -0
- package/dist/core/credentials/refusal-words.d.ts.map +1 -0
- package/dist/core/credentials/refusal-words.js +56 -0
- package/dist/core/credentials/refusal-words.js.map +1 -0
- package/dist/core/credentials/sign-in-areas.d.ts +18 -0
- package/dist/core/credentials/sign-in-areas.d.ts.map +1 -0
- package/dist/core/credentials/sign-in-areas.js +22 -0
- package/dist/core/credentials/sign-in-areas.js.map +1 -0
- package/dist/core/http.d.ts +10 -4
- package/dist/core/http.d.ts.map +1 -1
- package/dist/core/http.js +7 -5
- package/dist/core/http.js.map +1 -1
- package/dist/core/identity.d.ts +11 -0
- package/dist/core/identity.d.ts.map +1 -0
- package/dist/core/identity.js +21 -0
- package/dist/core/identity.js.map +1 -0
- package/dist/core/limit-story.d.ts +11 -0
- package/dist/core/limit-story.d.ts.map +1 -0
- package/dist/core/limit-story.js +16 -0
- package/dist/core/limit-story.js.map +1 -0
- package/dist/core/login.d.ts +5 -3
- package/dist/core/login.d.ts.map +1 -1
- package/dist/core/login.js +5 -3
- package/dist/core/login.js.map +1 -1
- package/dist/core/oauth/metadata.d.ts +24 -0
- package/dist/core/oauth/metadata.d.ts.map +1 -0
- package/dist/core/oauth/metadata.js +99 -0
- package/dist/core/oauth/metadata.js.map +1 -0
- package/dist/core/oauth/oauth-client.d.ts +70 -0
- package/dist/core/oauth/oauth-client.d.ts.map +1 -0
- package/dist/core/oauth/oauth-client.js +136 -0
- package/dist/core/oauth/oauth-client.js.map +1 -0
- package/dist/core/oauth/oauth-error.d.ts +18 -0
- package/dist/core/oauth/oauth-error.d.ts.map +1 -0
- package/dist/core/oauth/oauth-error.js +31 -0
- package/dist/core/oauth/oauth-error.js.map +1 -0
- package/dist/core/oauth/sign-in-error.d.ts +15 -0
- package/dist/core/oauth/sign-in-error.d.ts.map +1 -0
- package/dist/core/oauth/sign-in-error.js +21 -0
- package/dist/core/oauth/sign-in-error.js.map +1 -0
- package/dist/core/oauth/sign-in-target.d.ts +31 -0
- package/dist/core/oauth/sign-in-target.d.ts.map +1 -0
- package/dist/core/oauth/sign-in-target.js +44 -0
- package/dist/core/oauth/sign-in-target.js.map +1 -0
- package/dist/core/output.d.ts +14 -3
- package/dist/core/output.d.ts.map +1 -1
- package/dist/core/output.js +38 -38
- package/dist/core/output.js.map +1 -1
- package/dist/core/retry-after.d.ts +8 -0
- package/dist/core/retry-after.d.ts.map +1 -0
- package/dist/core/retry-after.js +18 -0
- package/dist/core/retry-after.js.map +1 -0
- package/dist/core/run-operation.d.ts +26 -10
- package/dist/core/run-operation.d.ts.map +1 -1
- package/dist/core/run-operation.js +40 -21
- package/dist/core/run-operation.js.map +1 -1
- package/dist/core/session/device-session-auth.d.ts +29 -0
- package/dist/core/session/device-session-auth.d.ts.map +1 -0
- package/dist/core/session/device-session-auth.js +92 -0
- package/dist/core/session/device-session-auth.js.map +1 -0
- package/dist/core/session/file-lock.d.ts +33 -0
- package/dist/core/session/file-lock.d.ts.map +1 -0
- package/dist/core/session/file-lock.js +145 -0
- package/dist/core/session/file-lock.js.map +1 -0
- package/dist/core/session/session-refusals.d.ts +22 -0
- package/dist/core/session/session-refusals.d.ts.map +1 -0
- package/dist/core/session/session-refusals.js +23 -0
- package/dist/core/session/session-refusals.js.map +1 -0
- package/dist/core/session/session-store.d.ts +53 -0
- package/dist/core/session/session-store.d.ts.map +1 -0
- package/dist/core/session/session-store.js +71 -0
- package/dist/core/session/session-store.js.map +1 -0
- package/dist/core/sign-in.d.ts +2 -2
- package/dist/core/sign-in.js +2 -2
- package/dist/core/token-expiry.d.ts +9 -0
- package/dist/core/token-expiry.d.ts.map +1 -0
- package/dist/core/token-expiry.js +11 -0
- package/dist/core/token-expiry.js.map +1 -0
- package/dist/core/url.d.ts +5 -0
- package/dist/core/url.d.ts.map +1 -0
- package/dist/core/url.js +17 -0
- package/dist/core/url.js.map +1 -0
- package/dist/generated/operations.d.ts +2 -1
- package/dist/generated/operations.d.ts.map +1 -1
- package/dist/generated/operations.js +32 -5
- package/dist/generated/operations.js.map +1 -1
- package/dist/generated/types.d.ts +584 -0
- package/dist/generated/types.d.ts.map +1 -1
- package/dist/generated/types.js +1 -1
- package/dist/interactive/menu.d.ts.map +1 -1
- package/dist/interactive/menu.js +4 -2
- package/dist/interactive/menu.js.map +1 -1
- package/dist/interactive/session.d.ts.map +1 -1
- package/dist/interactive/session.js +17 -8
- package/dist/interactive/session.js.map +1 -1
- package/dist/login/browser-opener.d.ts +20 -0
- package/dist/login/browser-opener.d.ts.map +1 -0
- package/dist/login/browser-opener.js +43 -0
- package/dist/login/browser-opener.js.map +1 -0
- package/dist/login/device-flow.d.ts +60 -0
- package/dist/login/device-flow.d.ts.map +1 -0
- package/dist/login/device-flow.js +98 -0
- package/dist/login/device-flow.js.map +1 -0
- package/dist/login/device-login.d.ts +27 -0
- package/dist/login/device-login.d.ts.map +1 -0
- package/dist/login/device-login.js +148 -0
- package/dist/login/device-login.js.map +1 -0
- package/dist/login/device-presenter.d.ts +24 -0
- package/dist/login/device-presenter.d.ts.map +1 -0
- package/dist/login/device-presenter.js +69 -0
- package/dist/login/device-presenter.js.map +1 -0
- package/dist/login/login-command.d.ts +14 -0
- package/dist/login/login-command.d.ts.map +1 -0
- package/dist/login/login-command.js +73 -0
- package/dist/login/login-command.js.map +1 -0
- package/dist/login/login-deps.d.ts +17 -0
- package/dist/login/login-deps.d.ts.map +1 -0
- package/dist/login/login-deps.js +18 -0
- package/dist/login/login-deps.js.map +1 -0
- package/dist/login/piped-input.d.ts +23 -0
- package/dist/login/piped-input.d.ts.map +1 -0
- package/dist/login/piped-input.js +36 -0
- package/dist/login/piped-input.js.map +1 -0
- package/dist/login/requested-scopes.d.ts +22 -0
- package/dist/login/requested-scopes.d.ts.map +1 -0
- package/dist/login/requested-scopes.js +43 -0
- package/dist/login/requested-scopes.js.map +1 -0
- package/dist/program.d.ts +16 -5
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +35 -10
- package/dist/program.js.map +1 -1
- package/dist/study-ci/ci-command.d.ts.map +1 -1
- package/dist/study-ci/ci-command.js +2 -2
- package/dist/study-ci/ci-command.js.map +1 -1
- package/dist/study-ci/ci-rehearse-command.d.ts.map +1 -1
- package/dist/study-ci/ci-rehearse-command.js +2 -2
- package/dist/study-ci/ci-rehearse-command.js.map +1 -1
- package/dist/tunnel/connection-end.d.ts +30 -0
- package/dist/tunnel/connection-end.d.ts.map +1 -0
- package/dist/tunnel/connection-end.js +29 -0
- package/dist/tunnel/connection-end.js.map +1 -0
- package/dist/tunnel-command.d.ts.map +1 -1
- package/dist/tunnel-command.js +24 -8
- package/dist/tunnel-command.js.map +1 -1
- package/package.json +3 -2
- package/dist/core/credential-sources.d.ts +0 -45
- package/dist/core/credential-sources.d.ts.map +0 -1
- package/dist/core/credential-sources.js +0 -65
- package/dist/core/credential-sources.js.map +0 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export function argumentFlag(name) {
|
|
2
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
3
|
+
}
|
|
4
|
+
export function argumentValues(meta, values, flags = {}) {
|
|
5
|
+
const given = {};
|
|
6
|
+
(meta.cliArguments ?? []).forEach((name, i) => {
|
|
7
|
+
const value = values[i] ?? flags[name];
|
|
8
|
+
if (typeof value === "string" && value !== "")
|
|
9
|
+
given[name] = value;
|
|
10
|
+
});
|
|
11
|
+
return given;
|
|
12
|
+
}
|
|
13
|
+
export function combineBody(fileBody, given) {
|
|
14
|
+
if (Object.keys(given).length === 0)
|
|
15
|
+
return { ok: true, body: fileBody };
|
|
16
|
+
if (typeof fileBody !== "object" || fileBody === null || Array.isArray(fileBody))
|
|
17
|
+
return { ok: false };
|
|
18
|
+
return { ok: true, body: { ...fileBody, ...given } };
|
|
19
|
+
}
|
|
20
|
+
function fieldPhrase(meta, name) {
|
|
21
|
+
const head = meta.bodyFields?.find((f) => f.name === name)?.description?.split(", e.g.")[0];
|
|
22
|
+
return head ? head.charAt(0).toLowerCase() + head.slice(1) : name;
|
|
23
|
+
}
|
|
24
|
+
function exampleCommand(meta) {
|
|
25
|
+
const samples = (meta.cliArguments ?? []).map((name) => meta.bodyFields?.find((f) => f.name === name)?.placeholder ?? `<${name}>`);
|
|
26
|
+
return ["ora", ...(meta.commandPath ?? []), ...samples].join(" ");
|
|
27
|
+
}
|
|
28
|
+
export function missingBodyMessage(meta, fallback) {
|
|
29
|
+
const names = meta.cliArguments ?? [];
|
|
30
|
+
if (names.length === 0)
|
|
31
|
+
return fallback;
|
|
32
|
+
return `Missing ${names.map((name) => fieldPhrase(meta, name)).join(" and ")}. For example: ${exampleCommand(meta)}`;
|
|
33
|
+
}
|
|
34
|
+
export function excessArgumentsMessage(meta) {
|
|
35
|
+
const names = meta.cliArguments ?? [];
|
|
36
|
+
const takes = names.length === 1 ? `one ${names[0]}` : names.map((name) => `<${name}>`).join(" ");
|
|
37
|
+
return `ora ${(meta.commandPath ?? []).join(" ")} takes ${takes}.`;
|
|
38
|
+
}
|
|
39
|
+
export function bodyOnCommandLine(meta, body) {
|
|
40
|
+
if (typeof body !== "object" || body === null)
|
|
41
|
+
return { args: [], needsFile: body !== undefined };
|
|
42
|
+
const fields = body;
|
|
43
|
+
const names = meta.cliArguments ?? [];
|
|
44
|
+
const args = [];
|
|
45
|
+
for (const name of names) {
|
|
46
|
+
if (typeof fields[name] !== "string")
|
|
47
|
+
break;
|
|
48
|
+
args.push(fields[name]);
|
|
49
|
+
}
|
|
50
|
+
const taken = new Set(names.slice(0, args.length));
|
|
51
|
+
return { args, needsFile: Object.keys(fields).some((key) => !taken.has(key)) };
|
|
52
|
+
}
|
|
53
|
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GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;AACjF,CAAC"}
|
package/dist/core/config.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Credential + endpoint configuration.
|
|
3
3
|
*
|
|
4
|
-
* ~/.config/ora (XDG-respecting) holds config.json (api key, api url)
|
|
5
|
-
* token.json (
|
|
6
|
-
* a
|
|
7
|
-
*
|
|
4
|
+
* ~/.config/ora (XDG-respecting) holds config.json (api key, api url, auth url),
|
|
5
|
+
* token.json (an api key's cached short-lived token, owned by auth.ts) and
|
|
6
|
+
* session.json (a browser sign-in, owned by session/session-store.ts). All are
|
|
7
|
+
* 0600 in a 0700 dir — keys and refresh tokens are secrets. Every read degrades
|
|
8
|
+
* to "not configured" rather than throwing: a corrupt file must never brick the CLI.
|
|
8
9
|
*
|
|
9
10
|
* Permissions are re-asserted on every write, not just on creation. This hardens
|
|
10
11
|
* pre-existing insecure files (e.g. restored from dotfiles with loose modes).
|
|
@@ -12,15 +13,19 @@
|
|
|
12
13
|
* Precedence (why: CI overrides laptops, flags override everything):
|
|
13
14
|
* api key : ORA_API_KEY env > config.json
|
|
14
15
|
* api url : --api-url flag > ORA_API_URL env > config.json > the spec's server
|
|
16
|
+
* An api key, wherever it comes from, wins over a browser sign-in
|
|
17
|
+
* (credentials/credential-chain.ts resolves which credential a command uses).
|
|
15
18
|
*/
|
|
16
19
|
export interface OraConfig {
|
|
17
20
|
apiKey?: string;
|
|
18
21
|
apiUrl?: string;
|
|
22
|
+
/** The sign-in server's origin, remembered from `ora login --auth-url` (else derived from apiUrl). */
|
|
23
|
+
authUrl?: string;
|
|
19
24
|
}
|
|
20
25
|
export declare function configDir(env?: NodeJS.ProcessEnv): string;
|
|
21
26
|
export declare function readConfig(dir?: string): OraConfig;
|
|
22
27
|
export declare function writeConfig(cfg: OraConfig, dir?: string): void;
|
|
28
|
+
/** Removes every credential file — also one too damaged to be read back as a credential and forgotten properly. */
|
|
23
29
|
export declare function clearCredentials(dir?: string): void;
|
|
24
|
-
export declare function resolveApiKey(cfg: OraConfig, env?: NodeJS.ProcessEnv): string | undefined;
|
|
25
30
|
export declare function resolveApiUrl(cfg: OraConfig, flagValue: string | undefined, embeddedDefault: string, env?: NodeJS.ProcessEnv): string;
|
|
26
31
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,MAAM,WAAW,SAAS;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sGAAsG;IACtG,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,SAAS,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAGtE;AAED,wBAAgB,UAAU,CAAC,GAAG,GAAE,MAAoB,GAAG,SAAS,CAW/D;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,GAAE,MAAoB,GAAG,IAAI,CAK3E;AAED,mHAAmH;AACnH,wBAAgB,gBAAgB,CAAC,GAAG,GAAE,MAAoB,GAAG,IAAI,CAIhE;AAED,wBAAgB,aAAa,CAC3B,GAAG,EAAE,SAAS,EACd,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,eAAe,EAAE,MAAM,EACvB,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,MAAM,CAER"}
|
package/dist/core/config.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Credential + endpoint configuration.
|
|
3
3
|
*
|
|
4
|
-
* ~/.config/ora (XDG-respecting) holds config.json (api key, api url)
|
|
5
|
-
* token.json (
|
|
6
|
-
* a
|
|
7
|
-
*
|
|
4
|
+
* ~/.config/ora (XDG-respecting) holds config.json (api key, api url, auth url),
|
|
5
|
+
* token.json (an api key's cached short-lived token, owned by auth.ts) and
|
|
6
|
+
* session.json (a browser sign-in, owned by session/session-store.ts). All are
|
|
7
|
+
* 0600 in a 0700 dir — keys and refresh tokens are secrets. Every read degrades
|
|
8
|
+
* to "not configured" rather than throwing: a corrupt file must never brick the CLI.
|
|
8
9
|
*
|
|
9
10
|
* Permissions are re-asserted on every write, not just on creation. This hardens
|
|
10
11
|
* pre-existing insecure files (e.g. restored from dotfiles with loose modes).
|
|
@@ -12,6 +13,8 @@
|
|
|
12
13
|
* Precedence (why: CI overrides laptops, flags override everything):
|
|
13
14
|
* api key : ORA_API_KEY env > config.json
|
|
14
15
|
* api url : --api-url flag > ORA_API_URL env > config.json > the spec's server
|
|
16
|
+
* An api key, wherever it comes from, wins over a browser sign-in
|
|
17
|
+
* (credentials/credential-chain.ts resolves which credential a command uses).
|
|
15
18
|
*/
|
|
16
19
|
import { chmodSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
17
20
|
import { homedir } from "node:os";
|
|
@@ -26,6 +29,7 @@ export function readConfig(dir = configDir()) {
|
|
|
26
29
|
return {
|
|
27
30
|
...(typeof parsed.apiKey === "string" ? { apiKey: parsed.apiKey } : {}),
|
|
28
31
|
...(typeof parsed.apiUrl === "string" ? { apiUrl: parsed.apiUrl } : {}),
|
|
32
|
+
...(typeof parsed.authUrl === "string" ? { authUrl: parsed.authUrl } : {}),
|
|
29
33
|
};
|
|
30
34
|
}
|
|
31
35
|
catch {
|
|
@@ -38,12 +42,11 @@ export function writeConfig(cfg, dir = configDir()) {
|
|
|
38
42
|
writeFileSync(join(dir, "config.json"), `${JSON.stringify(cfg, null, 2)}\n`, { mode: 0o600 });
|
|
39
43
|
chmodSync(join(dir, "config.json"), 0o600);
|
|
40
44
|
}
|
|
45
|
+
/** Removes every credential file — also one too damaged to be read back as a credential and forgotten properly. */
|
|
41
46
|
export function clearCredentials(dir = configDir()) {
|
|
42
47
|
rmSync(join(dir, "config.json"), { force: true });
|
|
43
48
|
rmSync(join(dir, "token.json"), { force: true });
|
|
44
|
-
}
|
|
45
|
-
export function resolveApiKey(cfg, env = process.env) {
|
|
46
|
-
return env.ORA_API_KEY || cfg.apiKey;
|
|
49
|
+
rmSync(join(dir, "session.json"), { force: true });
|
|
47
50
|
}
|
|
48
51
|
export function resolveApiUrl(cfg, flagValue, embeddedDefault, env = process.env) {
|
|
49
52
|
return (flagValue || env.ORA_API_URL || cfg.apiUrl || embeddedDefault).replace(/\/+$/, "");
|
package/dist/core/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AASjC,MAAM,UAAU,SAAS,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC5D,MAAM,IAAI,GAAG,GAAG,CAAC,eAAe,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;IAC/D,OAAO,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAc,SAAS,EAAE;IAClD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE,MAAM,CAAC,CAA4B,CAAC;QACrG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E,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,GAAc,EACd,SAA6B,EAC7B,eAAuB,EACvB,MAAyB,OAAO,CAAC,GAAG;IAEpC,OAAO,CAAC,SAAS,IAAI,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,MAAM,IAAI,eAAe,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC7F,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An api key (`ora_sk_…`): from `ORA_API_KEY` (CI wins over a laptop's stored key) or config.json.
|
|
3
|
+
*
|
|
4
|
+
* It works exactly as it always has (auth.ts, untouched): traded for a short-lived token at
|
|
5
|
+
* `POST {apiUrl}/auth/token`, the token cached in token.json until it nears expiry and traded again once when the
|
|
6
|
+
* API answers 401. That exchange is what every Ora serves, so a key signs in against a server with or without
|
|
7
|
+
* browser sign-in; the key itself never travels beyond it. Using a key never clears the cache — the cache is the point.
|
|
8
|
+
*/
|
|
9
|
+
import type { Credential, CredentialAuth, CredentialProvider, CredentialRuntime, IdentityDoors } from "./credential.js";
|
|
10
|
+
export declare class ApiKeyCredential implements Credential {
|
|
11
|
+
readonly apiKey: string;
|
|
12
|
+
readonly source: "ORA_API_KEY" | "config.json";
|
|
13
|
+
readonly kind = "api_key";
|
|
14
|
+
readonly words: import("./credential.js").RefusalWords;
|
|
15
|
+
readonly identityLines: import("./credential.js").IdentityLines;
|
|
16
|
+
constructor(apiKey: string, source: "ORA_API_KEY" | "config.json");
|
|
17
|
+
createAuth(rt: CredentialRuntime): CredentialAuth;
|
|
18
|
+
/** The claims of a token traded just now: proof the key still works, and who it is. */
|
|
19
|
+
readIdentity({ auth }: IdentityDoors): Promise<Record<string, unknown>>;
|
|
20
|
+
/**
|
|
21
|
+
* Its cached token is dropped. A stored key is removed from config.json (the api url and auth url stay); an env key
|
|
22
|
+
* is the environment's to unset.
|
|
23
|
+
*/
|
|
24
|
+
forget(rt: CredentialRuntime): Promise<void>;
|
|
25
|
+
private exchange;
|
|
26
|
+
}
|
|
27
|
+
export declare const envApiKeyProvider: CredentialProvider;
|
|
28
|
+
export declare const storedApiKeyProvider: CredentialProvider;
|
|
29
|
+
//# sourceMappingURL=api-key-credential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-credential.d.ts","sourceRoot":"","sources":["../../../src/core/credentials/api-key-credential.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIxH,qBAAa,gBAAiB,YAAW,UAAU;IAM/C,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa;IANhD,QAAQ,CAAC,IAAI,aAAa;IAC1B,QAAQ,CAAC,KAAK,yCAAiB;IAC/B,QAAQ,CAAC,aAAa,0CAA0B;gBAGrC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,GAAG,aAAa;IAGhD,UAAU,CAAC,EAAE,EAAE,iBAAiB,GAAG,cAAc;IAIjD,uFAAuF;IACjF,YAAY,CAAC,EAAE,IAAI,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAI7E;;;OAGG;IACG,MAAM,CAAC,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOlD,OAAO,CAAC,QAAQ;CAGjB;AAED,eAAO,MAAM,iBAAiB,EAAE,kBAI/B,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,kBAOlC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An api key (`ora_sk_…`): from `ORA_API_KEY` (CI wins over a laptop's stored key) or config.json.
|
|
3
|
+
*
|
|
4
|
+
* It works exactly as it always has (auth.ts, untouched): traded for a short-lived token at
|
|
5
|
+
* `POST {apiUrl}/auth/token`, the token cached in token.json until it nears expiry and traded again once when the
|
|
6
|
+
* API answers 401. That exchange is what every Ora serves, so a key signs in against a server with or without
|
|
7
|
+
* browser sign-in; the key itself never travels beyond it. Using a key never clears the cache — the cache is the point.
|
|
8
|
+
*/
|
|
9
|
+
import { ApiKeyAuth, decodeClaims } from "../auth.js";
|
|
10
|
+
import { readConfig, writeConfig } from "../config.js";
|
|
11
|
+
import { API_KEY_IDENTITY_LINES } from "./identity-lines.js";
|
|
12
|
+
import { API_KEY_WORDS } from "./refusal-words.js";
|
|
13
|
+
export class ApiKeyCredential {
|
|
14
|
+
apiKey;
|
|
15
|
+
source;
|
|
16
|
+
kind = "api_key";
|
|
17
|
+
words = API_KEY_WORDS;
|
|
18
|
+
identityLines = API_KEY_IDENTITY_LINES;
|
|
19
|
+
constructor(apiKey, source) {
|
|
20
|
+
this.apiKey = apiKey;
|
|
21
|
+
this.source = source;
|
|
22
|
+
}
|
|
23
|
+
createAuth(rt) {
|
|
24
|
+
return this.exchange(rt);
|
|
25
|
+
}
|
|
26
|
+
/** The claims of a token traded just now: proof the key still works, and who it is. */
|
|
27
|
+
async readIdentity({ auth }) {
|
|
28
|
+
return decodeClaims(await auth().forceRefresh());
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Its cached token is dropped. A stored key is removed from config.json (the api url and auth url stay); an env key
|
|
32
|
+
* is the environment's to unset.
|
|
33
|
+
*/
|
|
34
|
+
async forget(rt) {
|
|
35
|
+
this.exchange(rt).clearCache();
|
|
36
|
+
if (this.source !== "config.json")
|
|
37
|
+
return;
|
|
38
|
+
const { apiKey: _dropped, ...rest } = readConfig(rt.dir);
|
|
39
|
+
writeConfig(rest, rt.dir);
|
|
40
|
+
}
|
|
41
|
+
exchange(rt) {
|
|
42
|
+
return new ApiKeyAuth({ apiUrl: rt.apiUrl, apiKey: this.apiKey, dir: rt.dir, fetchFn: rt.fetchFn, now: rt.now });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export const envApiKeyProvider = {
|
|
46
|
+
name: "ORA_API_KEY",
|
|
47
|
+
stored: false,
|
|
48
|
+
find: ({ env }) => (env.ORA_API_KEY ? new ApiKeyCredential(env.ORA_API_KEY, "ORA_API_KEY") : null),
|
|
49
|
+
};
|
|
50
|
+
export const storedApiKeyProvider = {
|
|
51
|
+
name: "config.json",
|
|
52
|
+
stored: true,
|
|
53
|
+
find: ({ dir }) => {
|
|
54
|
+
const { apiKey } = readConfig(dir);
|
|
55
|
+
return apiKey ? new ApiKeyCredential(apiKey, "config.json") : null;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=api-key-credential.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-credential.js","sourceRoot":"","sources":["../../../src/core/credentials/api-key-credential.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,OAAO,gBAAgB;IAMhB;IACA;IANF,IAAI,GAAG,SAAS,CAAC;IACjB,KAAK,GAAG,aAAa,CAAC;IACtB,aAAa,GAAG,sBAAsB,CAAC;IAEhD,YACW,MAAc,EACd,MAAqC;QADrC,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAA+B;IAC7C,CAAC;IAEJ,UAAU,C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ACZ,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;QAChB,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACrE,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyless CI sign-in: a CI job names the api key it signs in as (`ORA_API_KEY_ID`, an id, never a secret) and proves
|
|
3
|
+
* which repository it runs for with the identity token its CI system issues it (GitHub Actions today,
|
|
4
|
+
* ../github-actions-sign-in.ts). The key must trust that repository (Settings, API keys, CI sign-in).
|
|
5
|
+
*
|
|
6
|
+
* It works as an api key does (../auth.ts, `TokenExchangeAuth` over that sign-in): traded at `POST {apiUrl}/auth/token`,
|
|
7
|
+
* the token cached in token.json until it nears expiry, a FRESH identity token asked for at every trade (ora accepts
|
|
8
|
+
* one once). The token it gets is the key's own, so it reads, words and is refused exactly as a key is. Nothing is
|
|
9
|
+
* stored, so forgetting it only drops the cached token.
|
|
10
|
+
*/
|
|
11
|
+
import type { Credential, CredentialAuth, CredentialProvider, CredentialRuntime, IdentityDoors } from "./credential.js";
|
|
12
|
+
/** The variable that names the api key a CI job signs in as. Its value is an id, not a secret. */
|
|
13
|
+
export declare const API_KEY_ID_ENV = "ORA_API_KEY_ID";
|
|
14
|
+
/** Overrides the audience a CI identity token is requested for (default: the API origin the CLI is pointed at). */
|
|
15
|
+
export declare const CI_AUDIENCE_ENV = "ORA_CI_AUDIENCE";
|
|
16
|
+
/** What a job brings: the key it signs in as, and how to ask its CI system for an identity token. */
|
|
17
|
+
export interface CiJob {
|
|
18
|
+
apiKeyId: string;
|
|
19
|
+
/** Unset: the API origin the CLI is pointed at. */
|
|
20
|
+
audience?: string;
|
|
21
|
+
requestUrl: string;
|
|
22
|
+
requestToken: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class CiOidcCredential implements Credential {
|
|
25
|
+
private readonly job;
|
|
26
|
+
readonly kind = "ci_oidc";
|
|
27
|
+
readonly source = "ORA_API_KEY_ID";
|
|
28
|
+
readonly words: import("./credential.js").RefusalWords;
|
|
29
|
+
readonly identityLines: import("./credential.js").IdentityLines;
|
|
30
|
+
constructor(job: CiJob);
|
|
31
|
+
createAuth(rt: CredentialRuntime): CredentialAuth;
|
|
32
|
+
/** The claims of a token traded just now: proof the job may still sign in as the key, and who it is. */
|
|
33
|
+
readIdentity({ auth }: IdentityDoors): Promise<Record<string, unknown>>;
|
|
34
|
+
/** Nothing is stored; the cached token is dropped. */
|
|
35
|
+
forget(rt: CredentialRuntime): Promise<void>;
|
|
36
|
+
private exchange;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A job that names a key id. Asked for and unable to work, it says so by name and is never skipped: a key id that is
|
|
40
|
+
* not one, or a job with no identity token to sign in with. An empty value is not set (an action passes unset inputs
|
|
41
|
+
* as empty).
|
|
42
|
+
*/
|
|
43
|
+
export declare const ciKeylessProvider: CredentialProvider;
|
|
44
|
+
//# sourceMappingURL=ci-oidc-credential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ci-oidc-credential.d.ts","sourceRoot":"","sources":["../../../src/core/credentials/ci-oidc-credential.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIxH,kGAAkG;AAClG,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAC/C,mHAAmH;AACnH,eAAO,MAAM,eAAe,oBAAoB,CAAC;AAIjD,qGAAqG;AACrG,MAAM,WAAW,KAAK;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,gBAAiB,YAAW,UAAU;IAOrC,OAAO,CAAC,QAAQ,CAAC,GAAG;IANhC,QAAQ,CAAC,IAAI,aAAa;IAC1B,QAAQ,CAAC,MAAM,oBAAkB;IAEjC,QAAQ,CAAC,KAAK,yCAAiB;IAC/B,QAAQ,CAAC,aAAa,0CAA0B;gBAEnB,GAAG,EAAE,KAAK;IAEvC,UAAU,CAAC,EAAE,EAAE,iBAAiB,GAAG,cAAc;IAIjD,wGAAwG;IAClG,YAAY,CAAC,EAAE,IAAI,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAI7E,sDAAsD;IAChD,MAAM,CAAC,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,OAAO,CAAC,QAAQ;CAUjB;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,kBAwB/B,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyless CI sign-in: a CI job names the api key it signs in as (`ORA_API_KEY_ID`, an id, never a secret) and proves
|
|
3
|
+
* which repository it runs for with the identity token its CI system issues it (GitHub Actions today,
|
|
4
|
+
* ../github-actions-sign-in.ts). The key must trust that repository (Settings, API keys, CI sign-in).
|
|
5
|
+
*
|
|
6
|
+
* It works as an api key does (../auth.ts, `TokenExchangeAuth` over that sign-in): traded at `POST {apiUrl}/auth/token`,
|
|
7
|
+
* the token cached in token.json until it nears expiry, a FRESH identity token asked for at every trade (ora accepts
|
|
8
|
+
* one once). The token it gets is the key's own, so it reads, words and is refused exactly as a key is. Nothing is
|
|
9
|
+
* stored, so forgetting it only drops the cached token.
|
|
10
|
+
*/
|
|
11
|
+
import { TokenExchangeAuth, decodeClaims } from "../auth.js";
|
|
12
|
+
import { GITHUB_ID_TOKEN_REQUEST_TOKEN, GITHUB_ID_TOKEN_REQUEST_URL, githubActionsSignIn, } from "../github-actions-sign-in.js";
|
|
13
|
+
import { API_KEY_IDENTITY_LINES } from "./identity-lines.js";
|
|
14
|
+
import { API_KEY_WORDS } from "./refusal-words.js";
|
|
15
|
+
/** The variable that names the api key a CI job signs in as. Its value is an id, not a secret. */
|
|
16
|
+
export const API_KEY_ID_ENV = "ORA_API_KEY_ID";
|
|
17
|
+
/** Overrides the audience a CI identity token is requested for (default: the API origin the CLI is pointed at). */
|
|
18
|
+
export const CI_AUDIENCE_ENV = "ORA_CI_AUDIENCE";
|
|
19
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
20
|
+
export class CiOidcCredential {
|
|
21
|
+
job;
|
|
22
|
+
kind = "ci_oidc";
|
|
23
|
+
source = API_KEY_ID_ENV;
|
|
24
|
+
// The token is the key's own: refused and worded as a key's (a CI_* refusal gets its own advice there).
|
|
25
|
+
words = API_KEY_WORDS;
|
|
26
|
+
identityLines = API_KEY_IDENTITY_LINES;
|
|
27
|
+
constructor(job) {
|
|
28
|
+
this.job = job;
|
|
29
|
+
}
|
|
30
|
+
createAuth(rt) {
|
|
31
|
+
return this.exchange(rt);
|
|
32
|
+
}
|
|
33
|
+
/** The claims of a token traded just now: proof the job may still sign in as the key, and who it is. */
|
|
34
|
+
async readIdentity({ auth }) {
|
|
35
|
+
return decodeClaims(await auth().forceRefresh());
|
|
36
|
+
}
|
|
37
|
+
/** Nothing is stored; the cached token is dropped. */
|
|
38
|
+
async forget(rt) {
|
|
39
|
+
this.exchange(rt).clearCache();
|
|
40
|
+
}
|
|
41
|
+
exchange(rt) {
|
|
42
|
+
const signIn = githubActionsSignIn({
|
|
43
|
+
apiKeyId: this.job.apiKeyId,
|
|
44
|
+
audience: this.job.audience || rt.apiUrl,
|
|
45
|
+
requestUrl: this.job.requestUrl,
|
|
46
|
+
requestToken: this.job.requestToken,
|
|
47
|
+
fetchFn: rt.fetchFn,
|
|
48
|
+
});
|
|
49
|
+
return new TokenExchangeAuth({ apiUrl: rt.apiUrl, signIn, dir: rt.dir, fetchFn: rt.fetchFn, now: rt.now });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A job that names a key id. Asked for and unable to work, it says so by name and is never skipped: a key id that is
|
|
54
|
+
* not one, or a job with no identity token to sign in with. An empty value is not set (an action passes unset inputs
|
|
55
|
+
* as empty).
|
|
56
|
+
*/
|
|
57
|
+
export const ciKeylessProvider = {
|
|
58
|
+
name: API_KEY_ID_ENV,
|
|
59
|
+
stored: false,
|
|
60
|
+
find: ({ env }) => {
|
|
61
|
+
const apiKeyId = env[API_KEY_ID_ENV]?.trim();
|
|
62
|
+
if (!apiKeyId)
|
|
63
|
+
return null;
|
|
64
|
+
if (!UUID.test(apiKeyId)) {
|
|
65
|
+
return {
|
|
66
|
+
problem: `${API_KEY_ID_ENV} is not an api key id. It is the key's ID (a UUID, shown beside the key in Settings, API keys), not the ora_sk_ secret.`,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const requestUrl = env[GITHUB_ID_TOKEN_REQUEST_URL];
|
|
70
|
+
const requestToken = env[GITHUB_ID_TOKEN_REQUEST_TOKEN];
|
|
71
|
+
if (!requestUrl || !requestToken) {
|
|
72
|
+
return {
|
|
73
|
+
problem: `${API_KEY_ID_ENV} is set, but this job has no identity token to sign in with. ` +
|
|
74
|
+
"In GitHub Actions, give the job `permissions: id-token: write` and run the CLI through the ora study-gate action " +
|
|
75
|
+
`(or pass ${GITHUB_ID_TOKEN_REQUEST_URL} and ${GITHUB_ID_TOKEN_REQUEST_TOKEN} to the step). Anywhere else, set ORA_API_KEY.`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const audience = env[CI_AUDIENCE_ENV]?.trim() || undefined;
|
|
79
|
+
return new CiOidcCredential({ apiKeyId, audience, requestUrl, requestToken });
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=ci-oidc-credential.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ci-oidc-credential.js","sourceRoot":"","sources":["../../../src/core/credentials/ci-oidc-credential.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,kGAAkG;AAClG,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAC/C,mHAAmH;AACnH,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAEjD,MAAM,IAAI,GAAG,iEAAiE,CAAC;AAW/E,MAAM,OAAO,gBAAgB;IAOE;IANpB,IAAI,GAAG,SAAS,CAAC;IACjB,MAAM,GAAG,cAAc,CAAC;IACjC,wGAAwG;IAC/F,KAAK,GAAG,aAAa,CAAC;IACtB,aAAa,GAAG,sBAAsB,CAAC;IAEhD,YAA6B,GAAU;QAAV,QAAG,GAAH,GAAG,CAAO;IAAG,CAAC;IAE3C,UAAU,CAAC,EAAqB;QAC9B,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;IAED,wGAAwG;IACxG,KAAK,CAAC,YAAY,CAAC,EAAE,IAAI,EAAiB;QACxC,OAAO,YAAY,CAAC,MAAM,IAAI,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,sDAAsD;IACtD,KAAK,CAAC,MAAM,CAAC,EAAqB;QAChC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC;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oBACnH,YAAY,2BAA2B,QAAQ,6BAA6B,gDAAgD;aAC/H,CAAC;QACJ,CAAC;QACD,MAAM,QAAQ,GAAG,GAAG,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;QAC3D,OAAO,IAAI,gBAAgB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;IAChF,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which credential a command uses: the first provider that has one, in precedence order.
|
|
3
|
+
*
|
|
4
|
+
* 1. `ORA_API_KEY` in the environment: the most explicit thing a person or a job can say (CI overrides a laptop);
|
|
5
|
+
* 2. keyless CI sign-in (`ORA_API_KEY_ID` in a job that can request its identity token): chosen by naming a key id,
|
|
6
|
+
* with no secret anywhere;
|
|
7
|
+
* 3. whatever `ora login` stored last: an api key or a device sign-in. Signing in one way removes the other, so at
|
|
8
|
+
* most one of the two is ever stored.
|
|
9
|
+
*
|
|
10
|
+
* A provider that was ASKED FOR and cannot work says so (`CredentialProblem`), and the chain stops there: a job that
|
|
11
|
+
* sets `ORA_API_KEY_ID` but has no identity token is told that, by name, and never falls through to a stored key.
|
|
12
|
+
* Adding a way to sign in is one provider here.
|
|
13
|
+
*/
|
|
14
|
+
import { type Credential, type CredentialFinding, type CredentialProvider } from "./credential.js";
|
|
15
|
+
export declare const CREDENTIAL_PROVIDERS: readonly CredentialProvider[];
|
|
16
|
+
export declare function findCredential(ctx: {
|
|
17
|
+
env: NodeJS.ProcessEnv;
|
|
18
|
+
dir: string;
|
|
19
|
+
}, providers?: readonly CredentialProvider[]): CredentialFinding;
|
|
20
|
+
/** Every STORED credential (env keys excluded): what `ora logout` and a fresh `ora login` remove. */
|
|
21
|
+
export declare function storedCredentials(ctx: {
|
|
22
|
+
env: NodeJS.ProcessEnv;
|
|
23
|
+
dir: string;
|
|
24
|
+
}, providers?: readonly CredentialProvider[]): Credential[];
|
|
25
|
+
//# sourceMappingURL=credential-chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-chain.d.ts","sourceRoot":"","sources":["../../../src/core/credentials/credential-chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAuB,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGxH,eAAO,MAAM,oBAAoB,EAAE,SAAS,kBAAkB,EAK7D,CAAC;AAEF,wBAAgB,cAAc,CAC5B,GAAG,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAC5C,SAAS,GAAE,SAAS,kBAAkB,EAAyB,GAC9D,iBAAiB,CAMnB;AAED,qGAAqG;AACrG,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAC5C,SAAS,GAAE,SAAS,kBAAkB,EAAyB,GAC9D,UAAU,EAAE,CAKd"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which credential a command uses: the first provider that has one, in precedence order.
|
|
3
|
+
*
|
|
4
|
+
* 1. `ORA_API_KEY` in the environment: the most explicit thing a person or a job can say (CI overrides a laptop);
|
|
5
|
+
* 2. keyless CI sign-in (`ORA_API_KEY_ID` in a job that can request its identity token): chosen by naming a key id,
|
|
6
|
+
* with no secret anywhere;
|
|
7
|
+
* 3. whatever `ora login` stored last: an api key or a device sign-in. Signing in one way removes the other, so at
|
|
8
|
+
* most one of the two is ever stored.
|
|
9
|
+
*
|
|
10
|
+
* A provider that was ASKED FOR and cannot work says so (`CredentialProblem`), and the chain stops there: a job that
|
|
11
|
+
* sets `ORA_API_KEY_ID` but has no identity token is told that, by name, and never falls through to a stored key.
|
|
12
|
+
* Adding a way to sign in is one provider here.
|
|
13
|
+
*/
|
|
14
|
+
import { envApiKeyProvider, storedApiKeyProvider } from "./api-key-credential.js";
|
|
15
|
+
import { ciKeylessProvider } from "./ci-oidc-credential.js";
|
|
16
|
+
import { isCredentialProblem } from "./credential.js";
|
|
17
|
+
import { deviceSessionProvider } from "./device-session-credential.js";
|
|
18
|
+
export const CREDENTIAL_PROVIDERS = [
|
|
19
|
+
envApiKeyProvider,
|
|
20
|
+
ciKeylessProvider,
|
|
21
|
+
storedApiKeyProvider,
|
|
22
|
+
deviceSessionProvider,
|
|
23
|
+
];
|
|
24
|
+
export function findCredential(ctx, providers = CREDENTIAL_PROVIDERS) {
|
|
25
|
+
for (const provider of providers) {
|
|
26
|
+
const found = provider.find(ctx);
|
|
27
|
+
if (found)
|
|
28
|
+
return found;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
/** Every STORED credential (env keys excluded): what `ora logout` and a fresh `ora login` remove. */
|
|
33
|
+
export function storedCredentials(ctx, providers = CREDENTIAL_PROVIDERS) {
|
|
34
|
+
return providers
|
|
35
|
+
.filter((p) => p.stored)
|
|
36
|
+
.map((p) => p.find(ctx))
|
|
37
|
+
.filter((c) => c !== null && !isCredentialProblem(c));
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=credential-chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-chain.js","sourceRoot":"","sources":["../../../src/core/credentials/credential-chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAoE,MAAM,iBAAiB,CAAC;AACxH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAEvE,MAAM,CAAC,MAAM,oBAAoB,GAAkC;IACjE,iBAAiB;IACjB,iBAAiB;IACjB,oBAAoB;IACpB,qBAAqB;CACtB,CAAC;AAEF,MAAM,UAAU,cAAc,CAC5B,GAA4C,EAC5C,YAA2C,oBAAoB;IAE/D,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;IAC1B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,qGAAqG;AACrG,MAAM,UAAU,iBAAiB,CAC/B,GAA4C,EAC5C,YAA2C,oBAAoB;IAE/D,OAAO,SAAS;SACb,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;SACvB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACvB,MAAM,CAAC,CAAC,CAAC,EAAmB,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the CLI proves who it is, as one interface. Three kinds today — an api key (CI, scripts), a CI job signing in as
|
|
3
|
+
* a key without its secret (keyless CI sign-in), and a browser sign-in (a person at a terminal) — each a Strategy: it builds its own TokenSource, reads and words its own identity, words
|
|
4
|
+
* its own refusals, and knows how to forget itself. Nothing outside credentials/ branches on the kind.
|
|
5
|
+
*/
|
|
6
|
+
import type { HttpClient, TokenSource } from "../http.js";
|
|
7
|
+
export interface CredentialRuntime {
|
|
8
|
+
apiUrl: string;
|
|
9
|
+
dir: string;
|
|
10
|
+
env: NodeJS.ProcessEnv;
|
|
11
|
+
fetchFn?: typeof fetch;
|
|
12
|
+
now?: () => number;
|
|
13
|
+
}
|
|
14
|
+
/** What signs a request: the bearer to send, and a fresh one when the API refuses it. */
|
|
15
|
+
export type CredentialAuth = TokenSource;
|
|
16
|
+
/** What to tell the person when the API refuses this credential. Lines, uncoloured. */
|
|
17
|
+
export interface RefusalWords {
|
|
18
|
+
/** 403 INSUFFICIENT_SCOPE: the scopes the API named, else the command's own; empty when neither says. */
|
|
19
|
+
missingScope(missing: readonly string[]): string[];
|
|
20
|
+
/** 401: the credential no longer authenticates anyone. Worded by the refusal's code, never by its message. */
|
|
21
|
+
signedOut(code: string, message: string): string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The two doors a credential can read its identity through, handed over by the program (its `makeAuth` and
|
|
25
|
+
* `makeClient`, the seams a test fakes). Lazy on purpose: a credential opens only the one it uses.
|
|
26
|
+
*/
|
|
27
|
+
export interface IdentityDoors {
|
|
28
|
+
/** This credential's own token source. */
|
|
29
|
+
auth(): CredentialAuth;
|
|
30
|
+
/** An API client that signs with this credential. */
|
|
31
|
+
client(): Pick<HttpClient, "call">;
|
|
32
|
+
}
|
|
33
|
+
/** `ora whoami`'s lines for an identity, uncoloured. */
|
|
34
|
+
export type IdentityLines = (claims: Record<string, unknown>, apiUrl: string) => string[];
|
|
35
|
+
export interface Credential {
|
|
36
|
+
/** "api_key" | "device_session": for display and --json, never for branching. */
|
|
37
|
+
readonly kind: string;
|
|
38
|
+
/** Where it came from: "ORA_API_KEY", "config.json", "device sign-in". */
|
|
39
|
+
readonly source: string;
|
|
40
|
+
readonly words: RefusalWords;
|
|
41
|
+
/** How `ora whoami` words this credential's identity (identity-lines.ts). */
|
|
42
|
+
readonly identityLines: IdentityLines;
|
|
43
|
+
createAuth(rt: CredentialRuntime): CredentialAuth;
|
|
44
|
+
/**
|
|
45
|
+
* Who this credential is, asked of the server now — the check `ora login` and `ora whoami` make, and the claims
|
|
46
|
+
* `whoami --json` prints. Rejects when the server refuses the credential.
|
|
47
|
+
*/
|
|
48
|
+
readIdentity(doors: IdentityDoors): Promise<Record<string, unknown>>;
|
|
49
|
+
/** Removes what this credential stored (and revokes what can be revoked). Best effort, never throws. */
|
|
50
|
+
forget(rt: CredentialRuntime): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A credential that was ASKED FOR and cannot work: a CI job that names a key id but has no identity token to sign in
|
|
54
|
+
* with. It says why, by name, and the chain stops there: signing in as something other than what was asked for is
|
|
55
|
+
* the failure to avoid.
|
|
56
|
+
*/
|
|
57
|
+
export interface CredentialProblem {
|
|
58
|
+
readonly problem: string;
|
|
59
|
+
}
|
|
60
|
+
/** What a provider found: a credential, a reason the one asked for cannot work, or nothing (null). */
|
|
61
|
+
export type CredentialFinding = Credential | CredentialProblem | null;
|
|
62
|
+
export declare function isCredentialProblem(finding: CredentialFinding): finding is CredentialProblem;
|
|
63
|
+
/** One place a credential can come from. Resolved in precedence order (credential-chain.ts). */
|
|
64
|
+
export interface CredentialProvider {
|
|
65
|
+
readonly name: string;
|
|
66
|
+
/** True when the credential lives in the config dir (what `ora logout` removes); false for the environment's. */
|
|
67
|
+
readonly stored: boolean;
|
|
68
|
+
find(ctx: {
|
|
69
|
+
env: NodeJS.ProcessEnv;
|
|
70
|
+
dir: string;
|
|
71
|
+
}): CredentialFinding;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=credential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../../../src/core/credentials/credential.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE1D,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACp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AM,iBAAiB,GAAG,UAAU,GAAG,iBAAiB,GAAG,IAAI,CAAC;AAEtE,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,IAAI,iBAAiB,CAE5F;AAED,gGAAgG;AAChG,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,iHAAiH;IACjH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,IAAI,CAAC,GAAG,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,iBAAiB,CAAC;CACvE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the CLI proves who it is, as one interface. Three kinds today — an api key (CI, scripts), a CI job signing in as
|
|
3
|
+
* a key without its secret (keyless CI sign-in), and a browser sign-in (a person at a terminal) — each a Strategy: it builds its own TokenSource, reads and words its own identity, words
|
|
4
|
+
* its own refusals, and knows how to forget itself. Nothing outside credentials/ branches on the kind.
|
|
5
|
+
*/
|
|
6
|
+
export function isCredentialProblem(finding) {
|
|
7
|
+
return finding !== null && "problem" in finding;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=credential.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.js","sourceRoot":"","sources":["../../../src/core/credentials/credential.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmEH,MAAM,UAAU,mBAAmB,CAAC,OAA0B;IAC5D,OAAO,OAAO,KAAK,IAAI,IAAI,SAAS,IAAI,OAAO,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A browser sign-in (the device flow, RFC 8628): the person approved this CLI in their browser, and session.json
|
|
3
|
+
* holds the result. Requests carry the session's OAuth access token as it is; the API converts it internally, so
|
|
4
|
+
* the CLI holds no platform token and keeps no token cache for it.
|
|
5
|
+
*/
|
|
6
|
+
import { OAuthClient } from "../oauth/oauth-client.js";
|
|
7
|
+
import { type DeviceSession } from "../session/session-store.js";
|
|
8
|
+
import type { Credential, CredentialAuth, CredentialProvider, CredentialRuntime, IdentityDoors } from "./credential.js";
|
|
9
|
+
/** The session's own authorization server, at the endpoints recorded when it was made. */
|
|
10
|
+
export declare function sessionOAuthClient(session: DeviceSession, rt: Pick<CredentialRuntime, "fetchFn" | "now">): OAuthClient;
|
|
11
|
+
/** Revokes a session's refresh token, which ends its grant. Best effort: false when it could not be revoked. */
|
|
12
|
+
export declare function revokeSession(session: DeviceSession, rt: Pick<CredentialRuntime, "fetchFn" | "now">): Promise<boolean>;
|
|
13
|
+
export declare class DeviceSessionCredential implements Credential {
|
|
14
|
+
readonly session: DeviceSession;
|
|
15
|
+
readonly kind = "device_session";
|
|
16
|
+
readonly source = "device sign-in";
|
|
17
|
+
readonly words: import("./credential.js").RefusalWords;
|
|
18
|
+
readonly identityLines: import("./credential.js").IdentityLines;
|
|
19
|
+
constructor(session: DeviceSession);
|
|
20
|
+
createAuth(rt: CredentialRuntime): CredentialAuth;
|
|
21
|
+
/** What the API says of the access token it is sent: the person, their organization, what they allowed. */
|
|
22
|
+
readIdentity({ client }: IdentityDoors): Promise<Record<string, unknown>>;
|
|
23
|
+
/** Revokes the refresh token (which ends the grant) when the server offers revocation, then removes the session. */
|
|
24
|
+
forget(rt: CredentialRuntime): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export declare const deviceSessionProvider: CredentialProvider;
|
|
27
|
+
//# sourceMappingURL=device-session-credential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device-session-credential.d.ts","sourceRoot":"","sources":["../../../src/core/credentials/device-session-credential.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIxH,0FAA0F;AAC1F,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,GAAG,KAAK,CAAC,GAAG,WAAW,CAUtH;AAED,gHAAgH;AAChH,wBAAsB,aAAa,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAO5H;AAED,qBAAa,uBAAwB,YAAW,UAAU;IAM5C,QAAQ,CAAC,OAAO,EAAE,aAAa;IAL3C,QAAQ,CAAC,IAAI,oBAAoB;IACjC,QAAQ,CAAC,MAAM,oBAAoB;IACnC,QAAQ,CAAC,KAAK,yCAAwB;IACtC,QAAQ,CAAC,aAAa,0CAAoC;gBAErC,OAAO,EAAE,aAAa;IAE3C,UAAU,CAAC,EAAE,EAAE,iBAAiB,GAAG,cAAc;IAejD,2GAA2G;IAC3G,YAAY,CAAC,EAAE,MAAM,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAIzE,oHAAoH;IAC9G,MAAM,CAAC,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAKnD;AAED,eAAO,MAAM,qBAAqB,EAAE,kBAOnC,CAAC"}
|