@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
package/dist/core/output.js
CHANGED
|
@@ -5,15 +5,20 @@
|
|
|
5
5
|
* trajectory/insight/journey/run-list renderers — render/index.ts), falling
|
|
6
6
|
* back to the same plain rendering when none of them claims the payload.
|
|
7
7
|
* renderError is where the CLI earns its keep: the 402 paywall and 403 scope
|
|
8
|
-
* stories are precomputed guidance, not bare codes
|
|
8
|
+
* stories are precomputed guidance, not bare codes — worded for the credential
|
|
9
|
+
* that was refused (an api key is told to mint one, a browser sign-in to sign
|
|
10
|
+
* in again: credentials/refusal-words.ts). The words come bound to the caller
|
|
11
|
+
* that met the error (run-operation.ts callerOf); there is no default kind.
|
|
9
12
|
*/
|
|
10
13
|
import chalk from "chalk";
|
|
14
|
+
import { limitStory } from "./limit-story.js";
|
|
11
15
|
import "../render/index.js"; // side-effect: registers the four rich renderers (Task 6)
|
|
12
16
|
import { renderRich } from "../render/registry.js";
|
|
13
17
|
import { sanitizeDeep, sanitizeTerminalText } from "../render/sanitize.js";
|
|
14
18
|
import { MAX_COLUMNS, cell, columnWidths, padLine, rowCountLabel } from "../render/table.js";
|
|
15
19
|
import { AuthError } from "./auth.js";
|
|
16
20
|
import { ApiError } from "./http.js";
|
|
21
|
+
import { SignInError } from "./oauth/sign-in-error.js";
|
|
17
22
|
export function renderResult(data, opts) {
|
|
18
23
|
if (opts.mode === "json")
|
|
19
24
|
return JSON.stringify(data, null, 2);
|
|
@@ -65,8 +70,11 @@ export function renderError(err, ctx = {}) {
|
|
|
65
70
|
return renderErrorJson(err);
|
|
66
71
|
if (err instanceof ApiError)
|
|
67
72
|
return renderApiError(err, ctx);
|
|
68
|
-
if (err instanceof AuthError)
|
|
69
|
-
return
|
|
73
|
+
if (err instanceof AuthError) {
|
|
74
|
+
return ctx.words
|
|
75
|
+
? refusalStory(ctx.words.signedOut(err.code, err.message))
|
|
76
|
+
: chalk.red(`Authentication failed (${err.code}): ${err.message}`);
|
|
77
|
+
}
|
|
70
78
|
return chalk.red(err instanceof Error ? err.message : String(err));
|
|
71
79
|
}
|
|
72
80
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -74,52 +82,44 @@ const isRecord = (value) => typeof value === "object" && value !== null && !Arra
|
|
|
74
82
|
* --json's error line (stderr, one line): the API's own error body as it was sent, so a script reads
|
|
75
83
|
* exactly the fields a client generated from the public doc reads — `code`, `details`, an Autopilot
|
|
76
84
|
* refusal's `details.issues[].refusal.wave` / `.blockedBy`. A failure the API did not answer in JSON (a
|
|
77
|
-
* refused key exchange, a missing
|
|
78
|
-
* `{error, code}`. Plain and rich modes never come here.
|
|
85
|
+
* refused key exchange, a sign-in that did not complete, a missing credential, an unreadable --file, a
|
|
86
|
+
* non-JSON 502) gets the same house shape, `{error, code}`. Plain and rich modes never come here.
|
|
79
87
|
*/
|
|
80
88
|
function renderErrorJson(err) {
|
|
81
89
|
if (err instanceof ApiError && isRecord(err.body) && Object.keys(err.body).length > 0)
|
|
82
90
|
return JSON.stringify(err.body);
|
|
83
|
-
if (err instanceof ApiError || err instanceof AuthError)
|
|
91
|
+
if (err instanceof ApiError || err instanceof AuthError || err instanceof SignInError) {
|
|
84
92
|
return JSON.stringify({ error: err.message, code: err.code });
|
|
93
|
+
}
|
|
85
94
|
return JSON.stringify({ error: err instanceof Error ? err.message : String(err), code: "CLI_ERROR" });
|
|
86
95
|
}
|
|
87
|
-
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
/** The scopes a 403 names (`details.missing`), else the command's own; none when neither says. */
|
|
97
|
+
function missingScopes(err, commandScope) {
|
|
98
|
+
const named = err.details?.missing;
|
|
99
|
+
if (Array.isArray(named) && named.length > 0)
|
|
100
|
+
return named.map(String);
|
|
101
|
+
return commandScope ? [commandScope] : [];
|
|
102
|
+
}
|
|
103
|
+
/** A credential's refusal (its own words, uncoloured): the first line is the headline, the rest say what to do. */
|
|
104
|
+
function refusalStory(lines) {
|
|
105
|
+
return [chalk.red(lines[0] ?? ""), ...lines.slice(1)].join("\n");
|
|
106
|
+
}
|
|
107
|
+
/** A refusal of the credential itself, in its own words; null for any other answer. */
|
|
108
|
+
function credentialRefusal(err, words, commandScope) {
|
|
109
|
+
if (err.status === 403 && err.code === "INSUFFICIENT_SCOPE")
|
|
110
|
+
return words.missingScope(missingScopes(err, commandScope));
|
|
111
|
+
if (err.status === 401)
|
|
112
|
+
return words.signedOut(err.code, err.message);
|
|
113
|
+
return null;
|
|
102
114
|
}
|
|
103
115
|
function renderApiError(err, ctx) {
|
|
104
116
|
if (err.status === 402) {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
return [
|
|
108
|
-
chalk.red(sentence),
|
|
109
|
-
...(typeof used === "number" && typeof limit === "number" ? [`Used ${used} of ${limit}.`] : []),
|
|
110
|
-
"Upgrade your plan (ora dashboard → Billing) or reduce usage.",
|
|
111
|
-
].join("\n");
|
|
117
|
+
const story = limitStory(`Limit exceeded: ${err.message}`, err.details);
|
|
118
|
+
return [chalk.red(story.headline), ...story.lines].join("\n");
|
|
112
119
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return [
|
|
117
|
-
chalk.red(`This api key is missing the required scope: ${missing}`),
|
|
118
|
-
"Mint a key with that scope (ora dashboard → Settings → API keys), then `ora login` again.",
|
|
119
|
-
].join("\n");
|
|
120
|
-
}
|
|
121
|
-
if (err.status === 401)
|
|
122
|
-
return authFailureStory(err.code, err.message);
|
|
120
|
+
const refusal = ctx.words ? credentialRefusal(err, ctx.words, ctx.scope) : null;
|
|
121
|
+
if (refusal)
|
|
122
|
+
return refusalStory(refusal);
|
|
123
123
|
if (err.status === 429) {
|
|
124
124
|
const retryAfter = err.details?.retryAfter;
|
|
125
125
|
if (typeof retryAfter === "string") {
|
package/dist/core/output.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/core/output.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/core/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,oBAAoB,CAAC,CAAC,0DAA0D;AAGvF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,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,GAAG,kBAAkB,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC;KAChD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,kBAAkB,CAAC,OAA4C,EAAE,QAAiB;IACzF,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,IAAI,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7C,KAAK,MAAM,KAAK,IAAI,KAAmD,EAAE,CAAC;gBACxE,MAAM,IAAI,GAAG,GAAG,KAAK,CAAC,IAAI,IAAI,QAAQ,KAAK,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;gBACpF,IAAI,IAAI,KAAK,QAAQ;oBAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;YAC9D,CAAC;YACD,SAAS;QACX,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `Retry-After` header (RFC 9110 §10.2.3) as whole seconds to wait: delta-seconds as sent (the ingress's per-IP
|
|
3
|
+
* limiter sends those), an HTTP-date as the seconds until it (never negative), and anything else — absent or
|
|
4
|
+
* unreadable — undefined. Read for the sign-in server's answers (core/oauth/oauth-error.ts), so a browser sign-in
|
|
5
|
+
* told to wait polls no sooner than it was asked to.
|
|
6
|
+
*/
|
|
7
|
+
export declare function retryAfterSeconds(header: string | null | undefined, now?: number): number | undefined;
|
|
8
|
+
//# sourceMappingURL=retry-after.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-after.d.ts","sourceRoot":"","sources":["../../src/core/retry-after.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG,GAAE,MAAmB,GAAG,MAAM,GAAG,SAAS,CAOjH"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `Retry-After` header (RFC 9110 §10.2.3) as whole seconds to wait: delta-seconds as sent (the ingress's per-IP
|
|
3
|
+
* limiter sends those), an HTTP-date as the seconds until it (never negative), and anything else — absent or
|
|
4
|
+
* unreadable — undefined. Read for the sign-in server's answers (core/oauth/oauth-error.ts), so a browser sign-in
|
|
5
|
+
* told to wait polls no sooner than it was asked to.
|
|
6
|
+
*/
|
|
7
|
+
export function retryAfterSeconds(header, now = Date.now()) {
|
|
8
|
+
const value = header?.trim();
|
|
9
|
+
if (!value)
|
|
10
|
+
return undefined;
|
|
11
|
+
if (/^\d+$/.test(value))
|
|
12
|
+
return Number(value);
|
|
13
|
+
if (!/[a-z]/i.test(value))
|
|
14
|
+
return undefined;
|
|
15
|
+
const at = Date.parse(value);
|
|
16
|
+
return Number.isFinite(at) ? Math.max(0, Math.ceil((at - now) / 1000)) : undefined;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=retry-after.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-after.js","sourceRoot":"","sources":["../../src/core/retry-after.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAiC,EAAE,MAAc,IAAI,CAAC,GAAG,EAAE;IAC3F,MAAM,KAAK,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5C,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7B,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrF,CAAC"}
|
|
@@ -8,21 +8,35 @@
|
|
|
8
8
|
* generated/operations.ts — no runtime edge back to program.ts, so this
|
|
9
9
|
* module stays a leaf auth-commands.ts and session.ts can both depend on.
|
|
10
10
|
*/
|
|
11
|
-
import type
|
|
11
|
+
import { type Credential } from "./credentials/credential.js";
|
|
12
|
+
import { type RenderErrorContext } from "./output.js";
|
|
12
13
|
import { type OperationMeta } from "../generated/operations.js";
|
|
13
14
|
import type { ResolvedDeps } from "../program.js";
|
|
14
15
|
import { type OutputMode } from "../render/mode.js";
|
|
15
|
-
/** What a
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
/** What rendering a caller's error may still say: the output mode, and the command's own scope. */
|
|
17
|
+
export type CallerErrorContext = Omit<RenderErrorContext, "words">;
|
|
18
|
+
/**
|
|
19
|
+
* Who is calling, and where: the resolved api url and the credential (credentials/credential-chain.ts) that signs
|
|
20
|
+
* every request — and how an error met while calling as it is told. Made by callerOf, so the wording is bound where
|
|
21
|
+
* the credential is resolved: a refusal is never worded for another kind of credential.
|
|
22
|
+
*/
|
|
23
|
+
export interface CallerCredentials {
|
|
24
|
+
readonly apiUrl: string;
|
|
25
|
+
readonly credential: Credential;
|
|
26
|
+
/** An error met while calling as this credential (output.ts): a refusal in the credential's own words. */
|
|
27
|
+
renderError(err: unknown, ctx?: CallerErrorContext): string;
|
|
19
28
|
}
|
|
29
|
+
/** The caller for `credential` at `apiUrl`, its errors rendered in the credential's own words. */
|
|
30
|
+
export declare function callerOf(apiUrl: string, credential: Credential): CallerCredentials;
|
|
31
|
+
/** The one "not signed in" sentence, shared with every door that needs a credential before it calls. */
|
|
32
|
+
export declare const NOT_SIGNED_IN_MESSAGE = "Not signed in. Run `ora login` (or set ORA_API_KEY for CI).";
|
|
20
33
|
/**
|
|
21
|
-
* Resolves
|
|
22
|
-
*
|
|
23
|
-
* `mode` "json" reports it as
|
|
34
|
+
* Resolves the credential + api url for a call, or reports why there is none and returns null: nothing to sign in
|
|
35
|
+
* with, or a credential that was asked for and cannot work (a CI job naming a key id with no identity token), in its
|
|
36
|
+
* own words. Shared by runOperation and the auth commands (whoami needs the same story). `mode` "json" reports it as
|
|
37
|
+
* a JSON line.
|
|
24
38
|
*/
|
|
25
|
-
export declare function credentials(deps: ResolvedDeps, apiUrlFlag: string | undefined, mode?: OutputMode):
|
|
39
|
+
export declare function credentials(deps: ResolvedDeps, apiUrlFlag: string | undefined, mode?: OutputMode): CallerCredentials | null;
|
|
26
40
|
/** Substitutes `{param}` placeholders in a path template with URI-encoded positionals, in declared order. */
|
|
27
41
|
export declare function buildPath(meta: Pick<OperationMeta, "pathTemplate" | "pathParams">, positionals: string[]): string;
|
|
28
42
|
/** Builds the query object from parsed commander opts, converting each param to its declared kind and omitting absent values. */
|
|
@@ -61,5 +75,7 @@ export declare const MISSING_BODY_MESSAGE = "This command requires a JSON body:
|
|
|
61
75
|
* silently dispatches the request with the bad body dropped while still
|
|
62
76
|
* exiting non-zero (the desync a future optional-body op would hit).
|
|
63
77
|
*/
|
|
64
|
-
export declare function readBody(file: string | undefined, meta: Pick<OperationMeta, "bodyRequired"
|
|
78
|
+
export declare function readBody(file: string | undefined, meta: Pick<OperationMeta, "bodyRequired" | "cliArguments" | "bodyFields"> & {
|
|
79
|
+
commandPath?: readonly string[];
|
|
80
|
+
}, deps: Pick<ResolvedDeps, "errOut">, mode?: OutputMode, given?: Record<string, string>): ReadBodyResult;
|
|
65
81
|
//# sourceMappingURL=run-operation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-operation.d.ts","sourceRoot":"","sources":["../../src/core/run-operation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"run-operation.d.ts","sourceRoot":"","sources":["../../src/core/run-operation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEnF,OAAO,EAA6B,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjF,OAAO,EAAQ,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAqB,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAIvE,mGAAmG;AACnG,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;AAEnE;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,0GAA0G;IAC1G,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAAC;CAC7D;AAED,kGAAkG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AAO,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAE/E,mLAAmL;AACnL,eAAO,MAAM,oBAAoB,gFAA8E,CAAC;AAEhH;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,cAAc,GAAG,cAAc,GAAG,YAAY,CAAC,GAAG;IAAE,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,EAC/G,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,EAClC,IAAI,CAAC,EAAE,UAAU,EACjB,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACjC,cAAc,CAyBhB"}
|
|
@@ -9,29 +9,41 @@
|
|
|
9
9
|
* module stays a leaf auth-commands.ts and session.ts can both depend on.
|
|
10
10
|
*/
|
|
11
11
|
import { readFileSync } from "node:fs";
|
|
12
|
+
import { combineBody, missingBodyMessage } from "./cli-arguments.js";
|
|
12
13
|
import { readConfig, resolveApiUrl } from "./config.js";
|
|
13
|
-
import {
|
|
14
|
+
import { isCredentialProblem } from "./credentials/credential.js";
|
|
15
|
+
import { findCredential } from "./credentials/credential-chain.js";
|
|
14
16
|
import { renderError, renderResult } from "./output.js";
|
|
15
17
|
import { readSse } from "./sse.js";
|
|
16
18
|
import { SPEC } from "../generated/operations.js";
|
|
17
19
|
import { resolveOutputMode } from "../render/mode.js";
|
|
18
20
|
import { renderEventStream } from "../watch.js";
|
|
19
21
|
import { watchResult } from "../watchers.js";
|
|
22
|
+
/** The caller for `credential` at `apiUrl`, its errors rendered in the credential's own words. */
|
|
23
|
+
export function callerOf(apiUrl, credential) {
|
|
24
|
+
return {
|
|
25
|
+
apiUrl,
|
|
26
|
+
credential,
|
|
27
|
+
renderError: (err, ctx = {}) => renderError(err, { ...ctx, words: credential.words }),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** The one "not signed in" sentence, shared with every door that needs a credential before it calls. */
|
|
31
|
+
export const NOT_SIGNED_IN_MESSAGE = "Not signed in. Run `ora login` (or set ORA_API_KEY for CI).";
|
|
20
32
|
/**
|
|
21
|
-
* Resolves
|
|
22
|
-
*
|
|
23
|
-
* `mode` "json" reports it as
|
|
33
|
+
* Resolves the credential + api url for a call, or reports why there is none and returns null: nothing to sign in
|
|
34
|
+
* with, or a credential that was asked for and cannot work (a CI job naming a key id with no identity token), in its
|
|
35
|
+
* own words. Shared by runOperation and the auth commands (whoami needs the same story). `mode` "json" reports it as
|
|
36
|
+
* a JSON line.
|
|
24
37
|
*/
|
|
25
38
|
export function credentials(deps, apiUrlFlag, mode) {
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return null;
|
|
39
|
+
const apiUrl = resolveApiUrl(readConfig(deps.dir), apiUrlFlag, SPEC.server, deps.env);
|
|
40
|
+
const found = findCredential({ env: deps.env, dir: deps.dir });
|
|
41
|
+
if (found === null || isCredentialProblem(found)) {
|
|
42
|
+
deps.errOut(renderError(new Error(found ? found.problem : NOT_SIGNED_IN_MESSAGE), { mode }));
|
|
43
|
+
process.exitCode = 1;
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return callerOf(apiUrl, found);
|
|
35
47
|
}
|
|
36
48
|
/** Substitutes `{param}` placeholders in a path template with URI-encoded positionals, in declared order. */
|
|
37
49
|
export function buildPath(meta, positionals) {
|
|
@@ -87,7 +99,7 @@ export async function runOperation(meta, values, deps) {
|
|
|
87
99
|
deps.out(renderResult(data, { mode }));
|
|
88
100
|
}
|
|
89
101
|
catch (err) {
|
|
90
|
-
deps.errOut(renderError(err, { scope: meta.scope, mode }));
|
|
102
|
+
deps.errOut(creds.renderError(err, { scope: meta.scope, mode }));
|
|
91
103
|
process.exitCode = 1;
|
|
92
104
|
}
|
|
93
105
|
}
|
|
@@ -103,18 +115,25 @@ export const MISSING_BODY_MESSAGE = 'This command requires a JSON body: pass --f
|
|
|
103
115
|
* silently dispatches the request with the bad body dropped while still
|
|
104
116
|
* exiting non-zero (the desync a future optional-body op would hit).
|
|
105
117
|
*/
|
|
106
|
-
export function readBody(file, meta, deps, mode) {
|
|
118
|
+
export function readBody(file, meta, deps, mode, given = {}) {
|
|
119
|
+
const usageError = (message) => {
|
|
120
|
+
deps.errOut(renderError(new Error(message), { mode }));
|
|
121
|
+
process.exitCode = 2;
|
|
122
|
+
return { kind: "error" };
|
|
123
|
+
};
|
|
107
124
|
if (!file) {
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return
|
|
112
|
-
}
|
|
125
|
+
if (Object.keys(given).length > 0)
|
|
126
|
+
return { kind: "ok", body: given };
|
|
127
|
+
if (meta.bodyRequired)
|
|
128
|
+
return usageError(missingBodyMessage(meta, MISSING_BODY_MESSAGE));
|
|
113
129
|
return { kind: "ok", body: undefined };
|
|
114
130
|
}
|
|
115
131
|
try {
|
|
116
132
|
const raw = file === "-" ? readFileSync(0, "utf8") : readFileSync(file, "utf8");
|
|
117
|
-
|
|
133
|
+
const combined = combineBody(JSON.parse(raw), given);
|
|
134
|
+
if (!combined.ok)
|
|
135
|
+
return usageError(`The JSON body in ${file === "-" ? "stdin" : file} must be an object to combine with the arguments.`);
|
|
136
|
+
return { kind: "ok", body: combined.body };
|
|
118
137
|
}
|
|
119
138
|
catch (err) {
|
|
120
139
|
deps.errOut(renderError(new Error(`Could not read JSON body from ${file === "-" ? "stdin" : file}: ${err.message}`), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-operation.js","sourceRoot":"","sources":["../../src/core/run-operation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,M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AC,CAAC;QACrB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { TokenSet } from "../oauth/oauth-client.js";
|
|
2
|
+
import type { DeviceSession, SessionStorage } from "./session-store.js";
|
|
3
|
+
/** The one capability this needs from the authorization server: turn a session's refresh token into new tokens. */
|
|
4
|
+
export interface SessionRefresher {
|
|
5
|
+
refresh(session: DeviceSession): Promise<TokenSet>;
|
|
6
|
+
}
|
|
7
|
+
export interface DeviceSessionAuthDeps {
|
|
8
|
+
apiUrl: string;
|
|
9
|
+
store: SessionStorage;
|
|
10
|
+
refresher: SessionRefresher;
|
|
11
|
+
now?: () => number;
|
|
12
|
+
}
|
|
13
|
+
export declare class DeviceSessionAuth {
|
|
14
|
+
private readonly deps;
|
|
15
|
+
private readonly now;
|
|
16
|
+
constructor(deps: DeviceSessionAuthDeps);
|
|
17
|
+
getToken(): Promise<string>;
|
|
18
|
+
/** `rejectedToken`: the access token the API just refused, so one another process already replaced is not renewed twice. */
|
|
19
|
+
forceRefresh(rejectedToken?: string): Promise<string>;
|
|
20
|
+
/** The stored session — only for the API it was made for: its access token never travels to another one. */
|
|
21
|
+
private session;
|
|
22
|
+
/** Is `session` still the sign-in on disk? False once another `ora login` replaced it, or `ora logout` removed it. */
|
|
23
|
+
private stillStored;
|
|
24
|
+
/** The stored sign-in is no longer the one this request started with: nothing of it is touched; the command is retried. */
|
|
25
|
+
private changed;
|
|
26
|
+
/** The session with a usable access token: as-is while it is fresh (unless `force`), else refreshed under the lock. */
|
|
27
|
+
private fresh;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=device-session-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device-session-auth.d.ts","sourceRoot":"","sources":["../../../src/core/session/device-session-auth.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGzD,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAExE,mHAAmH;AACnH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACpD;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,cAAc,CAAC;IACtB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,qBAAa,iBAAiB;IAGhB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;gBAEN,IAAI,EAAE,qBAAqB;IAIlD,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IAIjC,4HAA4H;IACtH,YAAY,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI3D,4GAA4G;IAC5G,OAAO,CAAC,OAAO;IAaf,sHAAsH;IACtH,OAAO,CAAC,WAAW;IAInB,2HAA2H;IAC3H,OAAO,CAAC,OAAO;IAIf,uHAAuH;YACzG,KAAK;CAkCpB"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A browser sign-in as a TokenSource: the session's OAuth access token is the bearer, sent to the API as it is (the
|
|
3
|
+
* API turns it into its own short-lived token — the CLI never sees or stores that one). When it nears expiry, or the
|
|
4
|
+
* API refuses it, it is renewed with the session's refresh token.
|
|
5
|
+
*
|
|
6
|
+
* The authorization server ROTATES refresh tokens: each one works once. So a refresh happens under the session lock
|
|
7
|
+
* (session-store.ts → file-lock.ts), and under the lock the session is read again first — a second `ora` process
|
|
8
|
+
* that waited finds the tokens the first one stored and uses them instead of replaying a spent refresh token, which
|
|
9
|
+
* would end the whole sign-in.
|
|
10
|
+
*
|
|
11
|
+
* A refresh only ever touches the session it started from. `ora login` in another terminal can replace the stored
|
|
12
|
+
* sign-in while this one's refresh is on the wire (and ends the old grant once the new one works): the answer to a
|
|
13
|
+
* refresh that then fails, or succeeds a moment too late, must not delete or overwrite that NEW sign-in.
|
|
14
|
+
*/
|
|
15
|
+
import { AuthError } from "../auth.js";
|
|
16
|
+
import { OAuthError } from "../oauth/oauth-error.js";
|
|
17
|
+
import { stillFresh } from "../token-expiry.js";
|
|
18
|
+
import { SESSION_REFUSAL, SIGN_IN_AGAIN } from "./session-refusals.js";
|
|
19
|
+
export class DeviceSessionAuth {
|
|
20
|
+
deps;
|
|
21
|
+
now;
|
|
22
|
+
constructor(deps) {
|
|
23
|
+
this.deps = deps;
|
|
24
|
+
this.now = deps.now ?? Date.now;
|
|
25
|
+
}
|
|
26
|
+
async getToken() {
|
|
27
|
+
return (await this.fresh(this.session(), false)).accessToken;
|
|
28
|
+
}
|
|
29
|
+
/** `rejectedToken`: the access token the API just refused, so one another process already replaced is not renewed twice. */
|
|
30
|
+
async forceRefresh(rejectedToken) {
|
|
31
|
+
return (await this.fresh(this.session(), true, rejectedToken)).accessToken;
|
|
32
|
+
}
|
|
33
|
+
/** The stored session — only for the API it was made for: its access token never travels to another one. */
|
|
34
|
+
session() {
|
|
35
|
+
const session = this.deps.store.read();
|
|
36
|
+
if (!session)
|
|
37
|
+
throw new AuthError(`You're not signed in. ${SIGN_IN_AGAIN}`, 401, SESSION_REFUSAL.notSignedIn);
|
|
38
|
+
if (session.apiUrl !== this.deps.apiUrl) {
|
|
39
|
+
throw new AuthError(`You're signed in to ${session.apiUrl}, not ${this.deps.apiUrl}. Run \`ora login --api-url ${this.deps.apiUrl}\`.`, 401, SESSION_REFUSAL.signedInElsewhere);
|
|
40
|
+
}
|
|
41
|
+
return session;
|
|
42
|
+
}
|
|
43
|
+
/** Is `session` still the sign-in on disk? False once another `ora login` replaced it, or `ora logout` removed it. */
|
|
44
|
+
stillStored(session) {
|
|
45
|
+
return this.deps.store.read()?.id === session.id;
|
|
46
|
+
}
|
|
47
|
+
/** The stored sign-in is no longer the one this request started with: nothing of it is touched; the command is retried. */
|
|
48
|
+
changed() {
|
|
49
|
+
return new AuthError("Your sign-in changed while this request was waiting. Retry the command.", 409, SESSION_REFUSAL.changed);
|
|
50
|
+
}
|
|
51
|
+
/** The session with a usable access token: as-is while it is fresh (unless `force`), else refreshed under the lock. */
|
|
52
|
+
async fresh(session, force, rejectedToken) {
|
|
53
|
+
if (!force && stillFresh(session.accessTokenExpiresAt, this.now()))
|
|
54
|
+
return session;
|
|
55
|
+
return this.deps.store.withLock(async () => {
|
|
56
|
+
const latest = this.session();
|
|
57
|
+
if (latest.id !== session.id)
|
|
58
|
+
throw this.changed();
|
|
59
|
+
const refreshedElsewhere = latest.accessToken !== (rejectedToken ?? session.accessToken) && stillFresh(latest.accessTokenExpiresAt, this.now());
|
|
60
|
+
if (refreshedElsewhere)
|
|
61
|
+
return latest;
|
|
62
|
+
if (!latest.refreshToken)
|
|
63
|
+
throw new AuthError(`Your sign-in has expired. ${SIGN_IN_AGAIN}`, 401, SESSION_REFUSAL.expired);
|
|
64
|
+
let tokens;
|
|
65
|
+
try {
|
|
66
|
+
tokens = await this.deps.refresher.refresh(latest);
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
if (err instanceof OAuthError && err.error === "invalid_grant") {
|
|
70
|
+
if (this.stillStored(latest)) {
|
|
71
|
+
this.deps.store.clear();
|
|
72
|
+
throw new AuthError(`Your sign-in has ended (revoked or expired). ${SIGN_IN_AGAIN}`, 401, SESSION_REFUSAL.ended);
|
|
73
|
+
}
|
|
74
|
+
throw this.changed();
|
|
75
|
+
}
|
|
76
|
+
throw err;
|
|
77
|
+
}
|
|
78
|
+
if (!this.stillStored(latest))
|
|
79
|
+
throw this.changed();
|
|
80
|
+
const next = {
|
|
81
|
+
...latest,
|
|
82
|
+
accessToken: tokens.accessToken,
|
|
83
|
+
accessTokenExpiresAt: tokens.expiresAt,
|
|
84
|
+
refreshToken: tokens.refreshToken ?? latest.refreshToken,
|
|
85
|
+
scope: tokens.scope ?? latest.scope,
|
|
86
|
+
};
|
|
87
|
+
this.deps.store.write(next);
|
|
88
|
+
return next;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=device-session-auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device-session-auth.js","sourceRoot":"","sources":["../../../src/core/session/device-session-auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAevE,MAAM,OAAO,iBAAiB;IAGC;IAFZ,GAAG,CAAe;IAEnC,YAA6B,IAA2B;QAA3B,SAAI,GAAJ,IAAI,CAAuB;QACtD,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,OAAO,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC;IAC/D,CAAC;IAED,4HAA4H;IAC5H,KAAK,CAAC,YAAY,CAAC,aAAsB;QACvC,OAAO,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC;IAC7E,CAAC;IAED,4GAA4G;IACpG,OAAO;QACb,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QACvC,IAAI,CAAC,OAAO;YAAE,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I,CAAC,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cross-process advisory lock: a lock FILE created with O_EXCL (`wx`), removed when the work ends. Two `ora`
|
|
3
|
+
* processes refreshing one sign-in at the same moment would each send the same refresh token, and the authorization
|
|
4
|
+
* server rotates refresh tokens — the second use is a replay, which revokes the whole grant. Serializing the refresh
|
|
5
|
+
* is what keeps a second terminal from signing the person out.
|
|
6
|
+
*
|
|
7
|
+
* A lock older than `staleMs` belongs to a process that died (or was suspended, a laptop closed) mid-work, and is
|
|
8
|
+
* broken. Each holder therefore writes a token of its own into the file and removes the file only while it still
|
|
9
|
+
* holds that token: a suspended holder that wakes after its lock was broken finds its successor's token there, and
|
|
10
|
+
* leaves it — removing it would let a third process in beside the second.
|
|
11
|
+
*
|
|
12
|
+
* Every removal of the lock is serialized by a second O_EXCL file (`<lock>.break`): a waiter breaking a stale lock,
|
|
13
|
+
* and a holder letting go of its own. Two waiters that both judged a dead lock stale would otherwise race — one
|
|
14
|
+
* removes it and takes a fresh lock, the other then removes THAT fresh lock — and a holder checking its token could
|
|
15
|
+
* have the lock broken and retaken between the check and the removal. Holding the breaker, a waiter re-checks
|
|
16
|
+
* staleness and a holder re-checks its token before removing anything. A waiter gives up after `waitMs` with an
|
|
17
|
+
* error rather than hanging.
|
|
18
|
+
*/
|
|
19
|
+
/** A lock older than this belongs to a holder that died (or was suspended) mid-work, and is broken. */
|
|
20
|
+
export declare const DEFAULT_STALE_MS = 30000;
|
|
21
|
+
/** How long a waiter waits for the lock before it gives up with an error. */
|
|
22
|
+
export declare const DEFAULT_WAIT_MS = 20000;
|
|
23
|
+
/** How often a waiter, or a holder letting go, tries again. */
|
|
24
|
+
export declare const DEFAULT_RETRY_MS = 100;
|
|
25
|
+
export interface FileLockOptions {
|
|
26
|
+
staleMs?: number;
|
|
27
|
+
waitMs?: number;
|
|
28
|
+
retryMs?: number;
|
|
29
|
+
now?: () => number;
|
|
30
|
+
sleep?: (ms: number) => Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export declare function withFileLock<T>(path: string, work: () => Promise<T>, opts?: FileLockOptions): Promise<T>;
|
|
33
|
+
//# sourceMappingURL=file-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-lock.d.ts","sourceRoot":"","sources":["../../../src/core/session/file-lock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,uGAAuG;AACvG,eAAO,MAAM,gBAAgB,QAAS,CAAC;AACvC,6EAA6E;AAC7E,eAAO,MAAM,eAAe,QAAS,CAAC;AACtC,+DAA+D;AAC/D,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAIpC,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AA4FD,wBAAsB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,GAAE,eAAoB,GAAG,OAAO,CAAC,CAAC,CAAC,CA2BlH"}
|