@ora-ai/cli 0.23.0 → 0.24.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.
Files changed (184) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +44 -13
  3. package/dist/agent-skills/skills-command.d.ts.map +1 -1
  4. package/dist/agent-skills/skills-command.js +2 -2
  5. package/dist/agent-skills/skills-command.js.map +1 -1
  6. package/dist/auth-commands.d.ts +25 -9
  7. package/dist/auth-commands.d.ts.map +1 -1
  8. package/dist/auth-commands.js +59 -49
  9. package/dist/auth-commands.js.map +1 -1
  10. package/dist/core/auth.d.ts +2 -2
  11. package/dist/core/auth.d.ts.map +1 -1
  12. package/dist/core/auth.js +5 -4
  13. package/dist/core/auth.js.map +1 -1
  14. package/dist/core/config.d.ts +10 -5
  15. package/dist/core/config.d.ts.map +1 -1
  16. package/dist/core/config.js +10 -7
  17. package/dist/core/config.js.map +1 -1
  18. package/dist/core/credentials/api-key-credential.d.ts +29 -0
  19. package/dist/core/credentials/api-key-credential.d.ts.map +1 -0
  20. package/dist/core/credentials/api-key-credential.js +58 -0
  21. package/dist/core/credentials/api-key-credential.js.map +1 -0
  22. package/dist/core/credentials/ci-oidc-credential.d.ts +44 -0
  23. package/dist/core/credentials/ci-oidc-credential.d.ts.map +1 -0
  24. package/dist/core/credentials/ci-oidc-credential.js +82 -0
  25. package/dist/core/credentials/ci-oidc-credential.js.map +1 -0
  26. package/dist/core/credentials/credential-chain.d.ts +25 -0
  27. package/dist/core/credentials/credential-chain.d.ts.map +1 -0
  28. package/dist/core/credentials/credential-chain.js +39 -0
  29. package/dist/core/credentials/credential-chain.js.map +1 -0
  30. package/dist/core/credentials/credential.d.ts +73 -0
  31. package/dist/core/credentials/credential.d.ts.map +1 -0
  32. package/dist/core/credentials/credential.js +9 -0
  33. package/dist/core/credentials/credential.js.map +1 -0
  34. package/dist/core/credentials/device-session-credential.d.ts +27 -0
  35. package/dist/core/credentials/device-session-credential.d.ts.map +1 -0
  36. package/dist/core/credentials/device-session-credential.js +78 -0
  37. package/dist/core/credentials/device-session-credential.js.map +1 -0
  38. package/dist/core/credentials/identity-lines.d.ts +14 -0
  39. package/dist/core/credentials/identity-lines.d.ts.map +1 -0
  40. package/dist/core/credentials/identity-lines.js +45 -0
  41. package/dist/core/credentials/identity-lines.js.map +1 -0
  42. package/dist/core/credentials/refusal-words.d.ts +15 -0
  43. package/dist/core/credentials/refusal-words.d.ts.map +1 -0
  44. package/dist/core/credentials/refusal-words.js +56 -0
  45. package/dist/core/credentials/refusal-words.js.map +1 -0
  46. package/dist/core/credentials/sign-in-areas.d.ts +18 -0
  47. package/dist/core/credentials/sign-in-areas.d.ts.map +1 -0
  48. package/dist/core/credentials/sign-in-areas.js +22 -0
  49. package/dist/core/credentials/sign-in-areas.js.map +1 -0
  50. package/dist/core/http.d.ts +10 -4
  51. package/dist/core/http.d.ts.map +1 -1
  52. package/dist/core/http.js +7 -5
  53. package/dist/core/http.js.map +1 -1
  54. package/dist/core/identity.d.ts +11 -0
  55. package/dist/core/identity.d.ts.map +1 -0
  56. package/dist/core/identity.js +21 -0
  57. package/dist/core/identity.js.map +1 -0
  58. package/dist/core/login.d.ts +5 -3
  59. package/dist/core/login.d.ts.map +1 -1
  60. package/dist/core/login.js +5 -3
  61. package/dist/core/login.js.map +1 -1
  62. package/dist/core/oauth/metadata.d.ts +24 -0
  63. package/dist/core/oauth/metadata.d.ts.map +1 -0
  64. package/dist/core/oauth/metadata.js +99 -0
  65. package/dist/core/oauth/metadata.js.map +1 -0
  66. package/dist/core/oauth/oauth-client.d.ts +70 -0
  67. package/dist/core/oauth/oauth-client.d.ts.map +1 -0
  68. package/dist/core/oauth/oauth-client.js +136 -0
  69. package/dist/core/oauth/oauth-client.js.map +1 -0
  70. package/dist/core/oauth/oauth-error.d.ts +18 -0
  71. package/dist/core/oauth/oauth-error.d.ts.map +1 -0
  72. package/dist/core/oauth/oauth-error.js +31 -0
  73. package/dist/core/oauth/oauth-error.js.map +1 -0
  74. package/dist/core/oauth/sign-in-error.d.ts +15 -0
  75. package/dist/core/oauth/sign-in-error.d.ts.map +1 -0
  76. package/dist/core/oauth/sign-in-error.js +21 -0
  77. package/dist/core/oauth/sign-in-error.js.map +1 -0
  78. package/dist/core/oauth/sign-in-target.d.ts +31 -0
  79. package/dist/core/oauth/sign-in-target.d.ts.map +1 -0
  80. package/dist/core/oauth/sign-in-target.js +44 -0
  81. package/dist/core/oauth/sign-in-target.js.map +1 -0
  82. package/dist/core/output.d.ts +14 -3
  83. package/dist/core/output.d.ts.map +1 -1
  84. package/dist/core/output.js +35 -31
  85. package/dist/core/output.js.map +1 -1
  86. package/dist/core/retry-after.d.ts +8 -0
  87. package/dist/core/retry-after.d.ts.map +1 -0
  88. package/dist/core/retry-after.js +18 -0
  89. package/dist/core/retry-after.js.map +1 -0
  90. package/dist/core/run-operation.d.ts +23 -9
  91. package/dist/core/run-operation.d.ts.map +1 -1
  92. package/dist/core/run-operation.js +25 -14
  93. package/dist/core/run-operation.js.map +1 -1
  94. package/dist/core/session/device-session-auth.d.ts +29 -0
  95. package/dist/core/session/device-session-auth.d.ts.map +1 -0
  96. package/dist/core/session/device-session-auth.js +92 -0
  97. package/dist/core/session/device-session-auth.js.map +1 -0
  98. package/dist/core/session/file-lock.d.ts +33 -0
  99. package/dist/core/session/file-lock.d.ts.map +1 -0
  100. package/dist/core/session/file-lock.js +145 -0
  101. package/dist/core/session/file-lock.js.map +1 -0
  102. package/dist/core/session/session-refusals.d.ts +22 -0
  103. package/dist/core/session/session-refusals.d.ts.map +1 -0
  104. package/dist/core/session/session-refusals.js +23 -0
  105. package/dist/core/session/session-refusals.js.map +1 -0
  106. package/dist/core/session/session-store.d.ts +53 -0
  107. package/dist/core/session/session-store.d.ts.map +1 -0
  108. package/dist/core/session/session-store.js +71 -0
  109. package/dist/core/session/session-store.js.map +1 -0
  110. package/dist/core/sign-in.d.ts +2 -2
  111. package/dist/core/sign-in.js +2 -2
  112. package/dist/core/token-expiry.d.ts +9 -0
  113. package/dist/core/token-expiry.d.ts.map +1 -0
  114. package/dist/core/token-expiry.js +11 -0
  115. package/dist/core/token-expiry.js.map +1 -0
  116. package/dist/core/url.d.ts +5 -0
  117. package/dist/core/url.d.ts.map +1 -0
  118. package/dist/core/url.js +17 -0
  119. package/dist/core/url.js.map +1 -0
  120. package/dist/generated/operations.d.ts +1 -1
  121. package/dist/generated/operations.js +2 -2
  122. package/dist/generated/types.d.ts +289 -0
  123. package/dist/generated/types.d.ts.map +1 -1
  124. package/dist/generated/types.js +1 -1
  125. package/dist/interactive/menu.d.ts.map +1 -1
  126. package/dist/interactive/menu.js +4 -2
  127. package/dist/interactive/menu.js.map +1 -1
  128. package/dist/interactive/session.d.ts.map +1 -1
  129. package/dist/interactive/session.js +13 -6
  130. package/dist/interactive/session.js.map +1 -1
  131. package/dist/login/browser-opener.d.ts +20 -0
  132. package/dist/login/browser-opener.d.ts.map +1 -0
  133. package/dist/login/browser-opener.js +43 -0
  134. package/dist/login/browser-opener.js.map +1 -0
  135. package/dist/login/device-flow.d.ts +60 -0
  136. package/dist/login/device-flow.d.ts.map +1 -0
  137. package/dist/login/device-flow.js +98 -0
  138. package/dist/login/device-flow.js.map +1 -0
  139. package/dist/login/device-login.d.ts +27 -0
  140. package/dist/login/device-login.d.ts.map +1 -0
  141. package/dist/login/device-login.js +148 -0
  142. package/dist/login/device-login.js.map +1 -0
  143. package/dist/login/device-presenter.d.ts +24 -0
  144. package/dist/login/device-presenter.d.ts.map +1 -0
  145. package/dist/login/device-presenter.js +69 -0
  146. package/dist/login/device-presenter.js.map +1 -0
  147. package/dist/login/login-command.d.ts +14 -0
  148. package/dist/login/login-command.d.ts.map +1 -0
  149. package/dist/login/login-command.js +73 -0
  150. package/dist/login/login-command.js.map +1 -0
  151. package/dist/login/login-deps.d.ts +17 -0
  152. package/dist/login/login-deps.d.ts.map +1 -0
  153. package/dist/login/login-deps.js +18 -0
  154. package/dist/login/login-deps.js.map +1 -0
  155. package/dist/login/piped-input.d.ts +23 -0
  156. package/dist/login/piped-input.d.ts.map +1 -0
  157. package/dist/login/piped-input.js +36 -0
  158. package/dist/login/piped-input.js.map +1 -0
  159. package/dist/login/requested-scopes.d.ts +22 -0
  160. package/dist/login/requested-scopes.d.ts.map +1 -0
  161. package/dist/login/requested-scopes.js +43 -0
  162. package/dist/login/requested-scopes.js.map +1 -0
  163. package/dist/program.d.ts +16 -5
  164. package/dist/program.d.ts.map +1 -1
  165. package/dist/program.js +15 -7
  166. package/dist/program.js.map +1 -1
  167. package/dist/study-ci/ci-command.d.ts.map +1 -1
  168. package/dist/study-ci/ci-command.js +2 -2
  169. package/dist/study-ci/ci-command.js.map +1 -1
  170. package/dist/study-ci/ci-rehearse-command.d.ts.map +1 -1
  171. package/dist/study-ci/ci-rehearse-command.js +2 -2
  172. package/dist/study-ci/ci-rehearse-command.js.map +1 -1
  173. package/dist/tunnel/connection-end.d.ts +30 -0
  174. package/dist/tunnel/connection-end.d.ts.map +1 -0
  175. package/dist/tunnel/connection-end.js +29 -0
  176. package/dist/tunnel/connection-end.js.map +1 -0
  177. package/dist/tunnel-command.d.ts.map +1 -1
  178. package/dist/tunnel-command.js +24 -8
  179. package/dist/tunnel-command.js.map +1 -1
  180. package/package.json +3 -2
  181. package/dist/core/credential-sources.d.ts +0 -45
  182. package/dist/core/credential-sources.d.ts.map +0 -1
  183. package/dist/core/credential-sources.js +0 -65
  184. package/dist/core/credential-sources.js.map +0 -1
@@ -0,0 +1,136 @@
1
+ /**
2
+ * The CLI as an OAuth public client of Ora's authorization server: device authorization (RFC 8628), the token
3
+ * endpoint (device-code polling and refresh, RFC 6749 §6) and revocation (RFC 7009). Form-encoded, `client_id` in
4
+ * the body (a public client has no secret), and `resource` (RFC 8707) on every token request so each access token is
5
+ * bound to the public API's audience.
6
+ *
7
+ * No loop, no sleep, no presentation here: one call is one HTTP exchange. The polling cadence and the renewal of an
8
+ * expired code live in login/device-flow.ts.
9
+ */
10
+ import { isHttpUrl } from "../url.js";
11
+ import { OAuthError, oauthErrorFrom } from "./oauth-error.js";
12
+ export const DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
13
+ /** RFC 8628 §3.2: when the server names no interval, poll every 5 seconds. */
14
+ const DEFAULT_INTERVAL_S = 5;
15
+ /** An access token whose response omits `expires_in` is treated as short-lived. */
16
+ const DEFAULT_ACCESS_TOKEN_TTL_S = 300;
17
+ /**
18
+ * How long one exchange with the sign-in server may take. It must stay well under the refresh lock's stale window
19
+ * (session/file-lock.ts, DEFAULT_STALE_MS; oauth-client.test.ts holds the two apart): a refresh that hung longer would
20
+ * have its lock broken by a second `ora` process, which would then send the same refresh token — a replay, which
21
+ * ends the whole sign-in.
22
+ */
23
+ export const OAUTH_REQUEST_TIMEOUT_MS = 15_000;
24
+ export class OAuthClient {
25
+ deps;
26
+ constructor(deps) {
27
+ this.deps = deps;
28
+ }
29
+ /** POST device_authorization_endpoint: a device code for this client, these scopes, this audience. */
30
+ async startDeviceAuthorization(req) {
31
+ const endpoint = this.deps.endpoints.deviceAuthorizationEndpoint;
32
+ if (!endpoint) {
33
+ throw new OAuthError("unsupported_grant_type", "this sign-in server does not offer device sign-in", 400);
34
+ }
35
+ const body = await this.post(endpoint, { client_id: this.deps.clientId, scope: req.scope, resource: req.resource });
36
+ const deviceCode = str(body.device_code);
37
+ const userCode = str(body.user_code);
38
+ const verificationUri = isHttpUrl(body.verification_uri) ? body.verification_uri : undefined;
39
+ if (!deviceCode || !userCode || !verificationUri) {
40
+ throw new OAuthError("invalid_response", "the device authorization response is missing a required field", 502);
41
+ }
42
+ const expiresIn = num(body.expires_in);
43
+ if (expiresIn === undefined) {
44
+ throw new OAuthError("invalid_response", "the device authorization response has no expires_in", 502);
45
+ }
46
+ return {
47
+ deviceCode,
48
+ userCode,
49
+ verificationUri,
50
+ ...(isHttpUrl(body.verification_uri_complete) ? { verificationUriComplete: body.verification_uri_complete } : {}),
51
+ expiresAt: this.deps.now() + expiresIn * 1000,
52
+ intervalMs: (num(body.interval) ?? DEFAULT_INTERVAL_S) * 1000,
53
+ };
54
+ }
55
+ /** One poll of the token endpoint. Pending and slow_down are answers, not errors; every other OAuth error throws. */
56
+ async pollDeviceToken(authorization, resource) {
57
+ try {
58
+ const body = await this.post(this.deps.endpoints.tokenEndpoint, {
59
+ grant_type: DEVICE_CODE_GRANT,
60
+ device_code: authorization.deviceCode,
61
+ client_id: this.deps.clientId,
62
+ resource,
63
+ });
64
+ return { kind: "tokens", tokens: this.tokenSet(body) };
65
+ }
66
+ catch (err) {
67
+ if (err instanceof OAuthError && err.error === "authorization_pending")
68
+ return { kind: "pending" };
69
+ if (err instanceof OAuthError && err.error === "slow_down")
70
+ return { kind: "slow_down" };
71
+ throw err;
72
+ }
73
+ }
74
+ /** Refresh: the server rotates the refresh token, so the caller MUST store the one this returns. */
75
+ async refresh(refreshToken, resource) {
76
+ const body = await this.post(this.deps.endpoints.tokenEndpoint, {
77
+ grant_type: "refresh_token",
78
+ refresh_token: refreshToken,
79
+ client_id: this.deps.clientId,
80
+ resource,
81
+ });
82
+ return this.tokenSet(body);
83
+ }
84
+ /** Best-effort revocation (RFC 7009 answers 200 even for an unknown token). False when the server has no endpoint. */
85
+ async revoke(token, hint) {
86
+ const endpoint = this.deps.endpoints.revocationEndpoint;
87
+ if (!endpoint)
88
+ return false;
89
+ await this.post(endpoint, { token, token_type_hint: hint, client_id: this.deps.clientId });
90
+ return true;
91
+ }
92
+ tokenSet(body) {
93
+ const accessToken = str(body.access_token);
94
+ if (!accessToken)
95
+ throw new OAuthError("invalid_response", "the token response has no access_token", 502);
96
+ const tokenType = str(body.token_type);
97
+ if (tokenType && tokenType.toLowerCase() !== "bearer") {
98
+ throw new OAuthError("invalid_response", `unsupported token type "${tokenType}"`, 502);
99
+ }
100
+ const refreshToken = str(body.refresh_token);
101
+ const scope = str(body.scope);
102
+ return {
103
+ accessToken,
104
+ expiresAt: this.deps.now() + (num(body.expires_in) ?? DEFAULT_ACCESS_TOKEN_TTL_S) * 1000,
105
+ ...(refreshToken ? { refreshToken } : {}),
106
+ ...(scope ? { scope } : {}),
107
+ };
108
+ }
109
+ async post(url, params) {
110
+ const res = await this.deps.fetchFn(url, {
111
+ method: "POST",
112
+ headers: { "content-type": "application/x-www-form-urlencoded", accept: "application/json" },
113
+ body: new URLSearchParams(params).toString(),
114
+ signal: AbortSignal.timeout(OAUTH_REQUEST_TIMEOUT_MS),
115
+ });
116
+ if (!res.ok)
117
+ throw await oauthErrorFrom(res);
118
+ const text = await res.text();
119
+ if (!text)
120
+ return {};
121
+ try {
122
+ const parsed = JSON.parse(text);
123
+ return typeof parsed === "object" && parsed !== null ? parsed : {};
124
+ }
125
+ catch {
126
+ throw new OAuthError("invalid_response", "the sign-in server answered something that is not JSON", 502);
127
+ }
128
+ }
129
+ }
130
+ function str(value) {
131
+ return typeof value === "string" && value.length > 0 ? value : undefined;
132
+ }
133
+ function num(value) {
134
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
135
+ }
136
+ //# sourceMappingURL=oauth-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-client.js","sourceRoot":"","sources":["../../../src/core/oauth/oauth-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,CAAC,MAAM,iBAAiB,GAAG,8CAA8C,CAAC;AAEhF,8EAA8E;AAC9E,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,mFAAmF;AACnF,MAAM,0BAA0B,GAAG,GAAG,CAAC;AACvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAmC/C,MAAM,OAAO,WAAW;IACO;IAA7B,YAA6B,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;IAAG,CAAC;IA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AAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC;AAED,SAAS,GAAG,CAAC,KAAc;IACzB,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9F,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * An OAuth error response (RFC 6749 §5.2, RFC 8628 §3.5): `{error, error_description?}`. `error` is the protocol's
3
+ * own code — `authorization_pending`, `slow_down`, `access_denied`, `expired_token`, `invalid_grant`, … — and is
4
+ * what callers branch on; the description is for people. `retryAfter` is the response's `Retry-After`, in seconds.
5
+ */
6
+ export declare class OAuthError extends Error {
7
+ readonly error: string;
8
+ readonly description: string | undefined;
9
+ readonly status: number;
10
+ readonly retryAfter?: number | undefined;
11
+ constructor(error: string, description: string | undefined, status: number, retryAfter?: number | undefined);
12
+ }
13
+ /**
14
+ * Reads an error response body into an OAuthError; a body that isn't one (the ingress's plain-text 429, an HTML 502)
15
+ * becomes `server_error`, keeping the status and `Retry-After`.
16
+ */
17
+ export declare function oauthErrorFrom(res: Response): Promise<OAuthError>;
18
+ //# sourceMappingURL=oauth-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-error.d.ts","sourceRoot":"","sources":["../../../src/core/oauth/oauth-error.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,KAAK;IAEjC,QAAQ,CAAC,KAAK,EAAE,MAAM;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM;gBAHnB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,MAAM,YAAA;CAK/B;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAUvE"}
@@ -0,0 +1,31 @@
1
+ import { retryAfterSeconds } from "../retry-after.js";
2
+ /**
3
+ * An OAuth error response (RFC 6749 §5.2, RFC 8628 §3.5): `{error, error_description?}`. `error` is the protocol's
4
+ * own code — `authorization_pending`, `slow_down`, `access_denied`, `expired_token`, `invalid_grant`, … — and is
5
+ * what callers branch on; the description is for people. `retryAfter` is the response's `Retry-After`, in seconds.
6
+ */
7
+ export class OAuthError extends Error {
8
+ error;
9
+ description;
10
+ status;
11
+ retryAfter;
12
+ constructor(error, description, status, retryAfter) {
13
+ super(description ? `${error}: ${description}` : error);
14
+ this.error = error;
15
+ this.description = description;
16
+ this.status = status;
17
+ this.retryAfter = retryAfter;
18
+ this.name = "OAuthError";
19
+ }
20
+ }
21
+ /**
22
+ * Reads an error response body into an OAuthError; a body that isn't one (the ingress's plain-text 429, an HTML 502)
23
+ * becomes `server_error`, keeping the status and `Retry-After`.
24
+ */
25
+ export async function oauthErrorFrom(res) {
26
+ const body = (await res.json().catch(() => ({})));
27
+ const error = typeof body.error === "string" && body.error.length > 0 ? body.error : "server_error";
28
+ const description = typeof body.error_description === "string" ? body.error_description : undefined;
29
+ return new OAuthError(error, description ?? (error === "server_error" ? `HTTP ${res.status}` : undefined), res.status, retryAfterSeconds(res.headers.get("retry-after")));
30
+ }
31
+ //# sourceMappingURL=oauth-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-error.js","sourceRoot":"","sources":["../../../src/core/oauth/oauth-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;GAIG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IAExB;IACA;IACA;IACA;IAJX,YACW,KAAa,EACb,WAA+B,EAC/B,MAAc,EACd,UAAmB;QAE5B,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,KAAK,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAL/C,UAAK,GAAL,KAAK,CAAQ;QACb,gBAAW,GAAX,WAAW,CAAoB;QAC/B,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAS;QAG5B,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAa;IAChD,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAqD,CAAC;IACtG,MAAM,KAAK,GAAG,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC;IACpG,MAAM,WAAW,GAAG,OAAO,IAAI,CAAC,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAAC;IACpG,OAAO,IAAI,UAAU,CACnB,KAAK,EACL,WAAW,IAAI,CAAC,KAAK,KAAK,cAAc,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,EAC5E,GAAG,CAAC,MAAM,EACV,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAClD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Signing in did not complete: the sign-in server is unreachable, the code was declined, the codes kept expiring.
3
+ * Unlike an AuthError (a credential the platform refused), there is no credential yet — so it renders as its own
4
+ * sentence, never as "your sign-in no longer works".
5
+ */
6
+ export declare class SignInError extends Error {
7
+ readonly code: string;
8
+ constructor(message: string, code: string);
9
+ }
10
+ /**
11
+ * The server asked has no browser sign-in to offer: an Ora that predates it (no sign-in document, or one without a
12
+ * device endpoint). Not a fault to retry — api keys work there as they always have, so the message says how.
13
+ */
14
+ export declare function signInNotOffered(issuer: string): SignInError;
15
+ //# sourceMappingURL=sign-in-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign-in-error.d.ts","sourceRoot":"","sources":["../../../src/core/oauth/sign-in-error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAGlC,QAAQ,CAAC,IAAI,EAAE,MAAM;gBADrB,OAAO,EAAE,MAAM,EACN,IAAI,EAAE,MAAM;CAKxB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAK5D"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Signing in did not complete: the sign-in server is unreachable, the code was declined, the codes kept expiring.
3
+ * Unlike an AuthError (a credential the platform refused), there is no credential yet — so it renders as its own
4
+ * sentence, never as "your sign-in no longer works".
5
+ */
6
+ export class SignInError extends Error {
7
+ code;
8
+ constructor(message, code) {
9
+ super(message);
10
+ this.code = code;
11
+ this.name = "SignInError";
12
+ }
13
+ }
14
+ /**
15
+ * The server asked has no browser sign-in to offer: an Ora that predates it (no sign-in document, or one without a
16
+ * device endpoint). Not a fault to retry — api keys work there as they always have, so the message says how.
17
+ */
18
+ export function signInNotOffered(issuer) {
19
+ return new SignInError(`This server does not offer browser sign-in yet (asked ${issuer}). Sign in with an api key instead: ora login --api-key`, "SIGN_IN_NOT_OFFERED");
20
+ }
21
+ //# sourceMappingURL=sign-in-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign-in-error.js","sourceRoot":"","sources":["../../../src/core/oauth/sign-in-error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAGzB;IAFX,YACE,OAAe,EACN,IAAY;QAErB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,SAAI,GAAJ,IAAI,CAAQ;QAGrB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,OAAO,IAAI,WAAW,CACpB,yDAAyD,MAAM,yDAAyD,EACxH,qBAAqB,CACtB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Where device sign-in goes, for a given API: the authorization server (the issuer, `account.<domain>`), the client
3
+ * the CLI signs in as, and the audience its tokens are for (the public API's origin).
4
+ *
5
+ * Precedence, like the api url's (config.ts): `--auth-url` flag > `ORA_AUTH_URL` env > config.json `authUrl` > the
6
+ * issuer DERIVED from the api url — `api.<domain>` → `account.<domain>`, the platform's host convention
7
+ * (`https://api.ora.ai` → `https://account.ora.ai`, dev `http://api.ora.localhost:8081` →
8
+ * `http://account.ora.localhost:8081`).
9
+ */
10
+ /**
11
+ * The CLI's own client id. Every published CLI is the first-party public client (no secret) the authorization server
12
+ * knows by this id, so it is a constant, not a setting.
13
+ */
14
+ export declare const CLI_CLIENT_ID = "ora-cli";
15
+ export interface SignInTarget {
16
+ issuer: string;
17
+ clientId: string;
18
+ /** RFC 8707 resource: the public API's canonical origin, every access token's audience. */
19
+ resource: string;
20
+ }
21
+ /** `https://API.ora.ai/` → `https://api.ora.ai`: lowercase scheme and host, no path, no trailing slash. */
22
+ export declare function apiResource(apiUrl: string): string;
23
+ /** `api.<domain>` → `account.<domain>`, keeping scheme and port. Null when the host does not start with `api.`. */
24
+ export declare function deriveIssuer(apiUrl: string): string | null;
25
+ export declare function resolveSignInTarget(opts: {
26
+ apiUrl: string;
27
+ authUrlFlag?: string;
28
+ configAuthUrl?: string;
29
+ env: NodeJS.ProcessEnv;
30
+ }): SignInTarget;
31
+ //# sourceMappingURL=sign-in-target.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign-in-target.d.ts","sourceRoot":"","sources":["../../../src/core/oauth/sign-in-target.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH;;;GAGG;AACH,eAAO,MAAM,aAAa,YAAY,CAAC;AAEvC,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,2FAA2F;IAC3F,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,2GAA2G;AAC3G,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAIlD;AAED,mHAAmH;AACnH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK1D;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;CACxB,GAAG,YAAY,CAcf"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Where device sign-in goes, for a given API: the authorization server (the issuer, `account.<domain>`), the client
3
+ * the CLI signs in as, and the audience its tokens are for (the public API's origin).
4
+ *
5
+ * Precedence, like the api url's (config.ts): `--auth-url` flag > `ORA_AUTH_URL` env > config.json `authUrl` > the
6
+ * issuer DERIVED from the api url — `api.<domain>` → `account.<domain>`, the platform's host convention
7
+ * (`https://api.ora.ai` → `https://account.ora.ai`, dev `http://api.ora.localhost:8081` →
8
+ * `http://account.ora.localhost:8081`).
9
+ */
10
+ import { SignInError } from "./sign-in-error.js";
11
+ import { parseUrl } from "../url.js";
12
+ /**
13
+ * The CLI's own client id. Every published CLI is the first-party public client (no secret) the authorization server
14
+ * knows by this id, so it is a constant, not a setting.
15
+ */
16
+ export const CLI_CLIENT_ID = "ora-cli";
17
+ /** `https://API.ora.ai/` → `https://api.ora.ai`: lowercase scheme and host, no path, no trailing slash. */
18
+ export function apiResource(apiUrl) {
19
+ const url = parseUrl(apiUrl);
20
+ if (!url)
21
+ throw new SignInError(`"${apiUrl}" is not a valid API URL`, "INVALID_API_URL");
22
+ return `${url.protocol}//${url.host.toLowerCase()}`;
23
+ }
24
+ /** `api.<domain>` → `account.<domain>`, keeping scheme and port. Null when the host does not start with `api.`. */
25
+ export function deriveIssuer(apiUrl) {
26
+ const url = parseUrl(apiUrl);
27
+ if (!url || !/^api\./i.test(url.hostname))
28
+ return null;
29
+ const host = url.host.replace(/^api\./i, "account.");
30
+ return `${url.protocol}//${host.toLowerCase()}`;
31
+ }
32
+ export function resolveSignInTarget(opts) {
33
+ const explicit = opts.authUrlFlag || opts.env.ORA_AUTH_URL || opts.configAuthUrl;
34
+ const issuer = (explicit || deriveIssuer(opts.apiUrl))?.replace(/\/+$/, "");
35
+ if (!issuer) {
36
+ throw new SignInError(`Can't tell where to sign in for ${opts.apiUrl}. Pass --auth-url (Ora's account origin), or use an api key: ora login --api-key`, "AUTH_URL_REQUIRED");
37
+ }
38
+ return {
39
+ issuer,
40
+ clientId: CLI_CLIENT_ID,
41
+ resource: apiResource(opts.apiUrl),
42
+ };
43
+ }
44
+ //# sourceMappingURL=sign-in-target.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign-in-target.js","sourceRoot":"","sources":["../../../src/core/oauth/sign-in-target.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AASvC,2GAA2G;AAC3G,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC7B,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,WAAW,CAAC,IAAI,MAAM,0BAA0B,EAAE,iBAAiB,CAAC,CAAC;IACzF,OAAO,GAAG,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;AACtD,CAAC;AAED,mHAAmH;AACnH,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC7B,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IACvD,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACrD,OAAO,GAAG,GAAG,CAAC,QAAQ,KAAK,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAKnC;IACC,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,GAAG,CAAC,YAAY,IAAI,IAAI,CAAC,aAAa,CAAC;IACjF,MAAM,MAAM,GAAG,CAAC,QAAQ,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC5E,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,WAAW,CACnB,mCAAmC,IAAI,CAAC,MAAM,kFAAkF,EAChI,mBAAmB,CACpB,CAAC;IACJ,CAAC;IACD,OAAO;QACL,MAAM;QACN,QAAQ,EAAE,aAAa;QACvB,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;KACnC,CAAC;AACJ,CAAC"}
@@ -5,15 +5,26 @@
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 "../render/index.js";
11
14
  import type { OutputMode } from "../render/mode.js";
15
+ import type { RefusalWords } from "./credentials/credential.js";
12
16
  export declare function renderResult(data: unknown, opts: {
13
17
  mode: OutputMode;
14
18
  }): string;
15
- export declare function renderError(err: unknown, ctx?: {
19
+ export interface RenderErrorContext {
16
20
  scope?: string | null;
17
21
  mode?: OutputMode;
18
- }): string;
22
+ /**
23
+ * The refused credential's own words (credentials/refusal-words.ts), bound by the caller that met the error
24
+ * (run-operation.ts callerOf). Without them a refusal is told as the API said it, with no advice: an error met with
25
+ * no credential resolved is no credential's refusal, and is never worded for one kind of credential.
26
+ */
27
+ words?: RefusalWords;
28
+ }
29
+ export declare function renderError(err: unknown, ctx?: RenderErrorContext): string;
19
30
  //# sourceMappingURL=output.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/core/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAOpD,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GAAG,MAAM,CAO9E;AAwCD,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,CAAC,EAAE,UAAU,CAAA;CAAO,GAAG,MAAM,CAKxG"}
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/core/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAIhE,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GAAG,MAAM,CAO9E;AAwCD,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB;;;;OAIG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,GAAE,kBAAuB,GAAG,MAAM,CAS9E"}
@@ -5,7 +5,10 @@
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";
11
14
  import "../render/index.js"; // side-effect: registers the four rich renderers (Task 6)
@@ -14,6 +17,7 @@ import { sanitizeDeep, sanitizeTerminalText } from "../render/sanitize.js";
14
17
  import { MAX_COLUMNS, cell, columnWidths, padLine, rowCountLabel } from "../render/table.js";
15
18
  import { AuthError } from "./auth.js";
16
19
  import { ApiError } from "./http.js";
20
+ import { SignInError } from "./oauth/sign-in-error.js";
17
21
  export function renderResult(data, opts) {
18
22
  if (opts.mode === "json")
19
23
  return JSON.stringify(data, null, 2);
@@ -65,8 +69,11 @@ export function renderError(err, ctx = {}) {
65
69
  return renderErrorJson(err);
66
70
  if (err instanceof ApiError)
67
71
  return renderApiError(err, ctx);
68
- if (err instanceof AuthError)
69
- return authFailureStory(err.code, err.message);
72
+ if (err instanceof AuthError) {
73
+ return ctx.words
74
+ ? refusalStory(ctx.words.signedOut(err.code, err.message))
75
+ : chalk.red(`Authentication failed (${err.code}): ${err.message}`);
76
+ }
70
77
  return chalk.red(err instanceof Error ? err.message : String(err));
71
78
  }
72
79
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
@@ -74,31 +81,35 @@ const isRecord = (value) => typeof value === "object" && value !== null && !Arra
74
81
  * --json's error line (stderr, one line): the API's own error body as it was sent, so a script reads
75
82
  * exactly the fields a client generated from the public doc reads — `code`, `details`, an Autopilot
76
83
  * refusal's `details.issues[].refusal.wave` / `.blockedBy`. A failure the API did not answer in JSON (a
77
- * refused key exchange, a missing key, an unreadable --file, a non-JSON 502) gets the same house shape,
78
- * `{error, code}`. Plain and rich modes never come here.
84
+ * refused key exchange, a sign-in that did not complete, a missing credential, an unreadable --file, a
85
+ * non-JSON 502) gets the same house shape, `{error, code}`. Plain and rich modes never come here.
79
86
  */
80
87
  function renderErrorJson(err) {
81
88
  if (err instanceof ApiError && isRecord(err.body) && Object.keys(err.body).length > 0)
82
89
  return JSON.stringify(err.body);
83
- if (err instanceof ApiError || err instanceof AuthError)
90
+ if (err instanceof ApiError || err instanceof AuthError || err instanceof SignInError) {
84
91
  return JSON.stringify({ error: err.message, code: err.code });
92
+ }
85
93
  return JSON.stringify({ error: err instanceof Error ? err.message : String(err), code: "CLI_ERROR" });
86
94
  }
87
- /**
88
- * What to do about a failed sign-in, by its code: the first entry that matches. A keyless CI job has no key to
89
- * log in with, so telling it to `ora login` would send its owner the wrong way.
90
- */
91
- const AUTH_HINTS = [
92
- { matches: (code) => code === "CI_IDENTITY_UNAVAILABLE", hint: "Give the job `permissions: id-token: write`, then run it again." },
93
- {
94
- matches: (code) => code.startsWith("CI_"),
95
- hint: "Check that the api key trusts this repository, ref and environment (Settings, API keys, CI sign-in), and that ORA_API_KEY_ID is that key's ID.",
96
- },
97
- { matches: () => true, hint: "Run `ora login` with a valid api key." },
98
- ];
99
- function authFailureStory(code, message) {
100
- const hint = AUTH_HINTS.find((entry) => entry.matches(code)).hint;
101
- return [chalk.red(`Authentication failed (${code}): ${message}`), hint].join("\n");
95
+ /** The scopes a 403 names (`details.missing`), else the command's own; none when neither says. */
96
+ function missingScopes(err, commandScope) {
97
+ const named = err.details?.missing;
98
+ if (Array.isArray(named) && named.length > 0)
99
+ return named.map(String);
100
+ return commandScope ? [commandScope] : [];
101
+ }
102
+ /** A credential's refusal (its own words, uncoloured): the first line is the headline, the rest say what to do. */
103
+ function refusalStory(lines) {
104
+ return [chalk.red(lines[0] ?? ""), ...lines.slice(1)].join("\n");
105
+ }
106
+ /** A refusal of the credential itself, in its own words; null for any other answer. */
107
+ function credentialRefusal(err, words, commandScope) {
108
+ if (err.status === 403 && err.code === "INSUFFICIENT_SCOPE")
109
+ return words.missingScope(missingScopes(err, commandScope));
110
+ if (err.status === 401)
111
+ return words.signedOut(err.code, err.message);
112
+ return null;
102
113
  }
103
114
  function renderApiError(err, ctx) {
104
115
  if (err.status === 402) {
@@ -110,16 +121,9 @@ function renderApiError(err, ctx) {
110
121
  "Upgrade your plan (ora dashboard → Billing) or reduce usage.",
111
122
  ].join("\n");
112
123
  }
113
- if (err.status === 403 && err.code === "INSUFFICIENT_SCOPE") {
114
- const fromDetails = err.details?.missing;
115
- const missing = Array.isArray(fromDetails) && fromDetails.length > 0 ? fromDetails.join(", ") : (ctx.scope ?? "unknown");
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);
124
+ const refusal = ctx.words ? credentialRefusal(err, ctx.words, ctx.scope) : null;
125
+ if (refusal)
126
+ return refusalStory(refusal);
123
127
  if (err.status === 429) {
124
128
  const retryAfter = err.details?.retryAfter;
125
129
  if (typeof retryAfter === "string") {
@@ -1 +1 @@
1
- {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/core/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,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,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,UAAU,YAAY,CAAC,IAAa,EAAE,IAA0B;IACpE,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC/D,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAC/D,6EAA6E;IAC7E,6EAA6E;IAC7E,+DAA+D;IAC/D,OAAO,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,WAAW,CAAC,IAAa;IAChC,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAChC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC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B,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 { SignIn } from "./sign-in.js";
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 call signs in with, and where it goes. */
16
- export interface Credentials {
17
- apiUrl: string;
18
- signIn: SignIn;
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 how a call signs in (credential-sources.ts decides which source) and the api url, or reports why it
22
- * cannot and returns null. Shared by runOperation and the auth commands (login/whoami both need the same story).
23
- * `mode` "json" reports it as a JSON line.
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): Credentials | null;
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. */