@prisma/cli-engine 0.0.1 → 0.0.2
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/dist/{engine-DXE014TZ.js → engine-vF4FiZqo.js} +474 -113
- package/dist/index.d.ts +45 -2
- package/dist/index.js +3 -2
- package/dist/{protocol-DGUfR-Ni.d.ts → protocol-CpZLdxML.d.ts} +5 -1
- package/dist/protocol.d.ts +1 -1
- package/dist/{run-summary-CPpYAYtS.d.ts → run-summary-CZITSYO_.d.ts} +267 -32
- package/dist/testing.d.ts +105 -4
- package/dist/testing.js +389 -79
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as TokenStorage, A as OpenUrlRequest, B as EngineEvent, C as LoadedConfig, D as BrowserWaitRequest, E as Runtime, F as PRESENTED, G as Credential, H as StreamEvent, I as Presentations, J as CredentialOrigin, K as CredentialIdentity, L as PresentedResult, M as Block, N as Format, O as CommandContext, P as Outcome, Q as ManagementApiClientConfig, R as TreeNode, S as InputStream, T as PRISMA_CONFIG_VERSION, U as StreamMeta, V as Severity, W as ActiveCredential, X as StoredSessions, Y as Session, Z as ManagementApiClient, _ as SessionCommandDefinition, a as defineCommandFamily, at as Char, b as defineSessionCommand, c as CommandHandler, ct as PositionalSpec, d as CompletedEnvelope, et as ConfigSection, f as ErroredEnvelope, g as ServerCommandDefinition, h as NeedsSpec, i as MountedTree, it as ArgsSpec, j as PromptSurface, k as OpenUrlOutcome, l as CommandHelp, lt as flag, m as HelpSpec, n as RunSummary, nt as defineConfigSection, o as AnyCommand, ot as CommandArgs, p as Handler, q as CredentialManager, r as CommandFamily, rt as Args, s as CommandDefinition, st as FlagSpec, t as EngineCommandSnapshot, tt as SectionValidation, u as CommandNeeds, ut as positional, v as defineCommand, w as OutputStream, x as HostProcess, y as defineServerCommand, z as Ui } from "./run-summary-CZITSYO_.js";
|
|
2
|
+
import { n as CliStructuredError } from "./protocol-CpZLdxML.js";
|
|
2
3
|
|
|
3
4
|
//#region src/cli.d.ts
|
|
4
5
|
/**
|
|
@@ -54,4 +55,46 @@ declare function defineConfig<T extends Record<string, unknown>>(config: T): T &
|
|
|
54
55
|
*/
|
|
55
56
|
declare function loadConfig(cwd: string): Promise<LoadedConfig>;
|
|
56
57
|
//#endregion
|
|
57
|
-
|
|
58
|
+
//#region src/credential-errors.d.ts
|
|
59
|
+
type CredentialsRequiredReason = "unauthenticated" | "expired" | "session-ended" | "sessions-held-none-selected";
|
|
60
|
+
/**
|
|
61
|
+
* The single constructor of CLI.CREDENTIALS_REQUIRED. Raised
|
|
62
|
+
* identically by the needs check, ctx.session, and the engine's
|
|
63
|
+
* request path.
|
|
64
|
+
*/
|
|
65
|
+
declare function credentialsRequiredError(reason?: CredentialsRequiredReason): CliStructuredError;
|
|
66
|
+
/**
|
|
67
|
+
* A refresh attempt failed transiently (the auth service, not the
|
|
68
|
+
* credentials): nothing was cleared, and signing in again is not the
|
|
69
|
+
* fix.
|
|
70
|
+
*/
|
|
71
|
+
declare function authServiceError(): CliStructuredError;
|
|
72
|
+
/**
|
|
73
|
+
* The credential in force was rejected and could never be renewed — it
|
|
74
|
+
* carries no refresh token. The ONE place wording differs by origin;
|
|
75
|
+
* nothing else compares against `origin.source`.
|
|
76
|
+
*/
|
|
77
|
+
declare function credentialRejectedError(origin: CredentialOrigin, envVar: string): CliStructuredError;
|
|
78
|
+
/**
|
|
79
|
+
* The env var that supplies a session is set to a blank value. The one
|
|
80
|
+
* structured error for it, raised identically by currentSession(), the
|
|
81
|
+
* needs check, and the engine's request path.
|
|
82
|
+
*/
|
|
83
|
+
declare function emptyServiceTokenError(spec: {
|
|
84
|
+
readonly envVar: string;
|
|
85
|
+
}): CliStructuredError;
|
|
86
|
+
/**
|
|
87
|
+
* No session exists for the named workspace. Sessions are created by
|
|
88
|
+
* `prisma auth login` alone — `workspace use` selects among the ones
|
|
89
|
+
* you have.
|
|
90
|
+
*/
|
|
91
|
+
declare function noSessionForWorkspaceError(workspaceRef: string): CliStructuredError;
|
|
92
|
+
/**
|
|
93
|
+
* The management API rejected the env-supplied service token (401).
|
|
94
|
+
* There is no refresh for it and nothing stored is cleared.
|
|
95
|
+
*/
|
|
96
|
+
declare function serviceTokenRejectedError(spec: {
|
|
97
|
+
readonly envVar: string;
|
|
98
|
+
}): CliStructuredError;
|
|
99
|
+
//#endregion
|
|
100
|
+
export { type ActiveCredential, type AnyCommand, type Args, type ArgsSpec, type Block, type BrowserWaitRequest, type Char, type Cli, type CliRunHooks, type CommandArgs, type CommandContext, type CommandDefinition, type CommandFamily, type CommandHandler, type CommandHelp, type CommandNeeds, type CompletedEnvelope, type ConfigSection, type Credential, type CredentialIdentity, type CredentialManager, type CredentialOrigin, type CredentialsRequiredReason, type EngineCommandSnapshot, type EngineEvent, type ErroredEnvelope, type FlagSpec, type Format, type Handler, type HelpSpec, type HostProcess, type InputStream, type LoadedConfig, type ManagementApiClient, type ManagementApiClientConfig, type MountedTree, type NeedsSpec, type OpenUrlOutcome, type OpenUrlRequest, type Outcome, type OutputStream, PRESENTED, PRISMA_CONFIG_VERSION, type PositionalSpec, type Presentations, type PresentedResult, type PromptSurface, type RunSummary, type Runtime, type SectionValidation, type ServerCommandDefinition, type Session, type SessionCommandDefinition, type Severity, type StoredSessions, type StreamEvent, type StreamMeta, type TokenStorage, type TreeNode, type Ui, authServiceError, createCli, credentialRejectedError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, emptyServiceTokenError, flag, loadConfig, noSessionForWorkspaceError, positional, serviceTokenRejectedError };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as
|
|
1
|
+
import { a as emptyServiceTokenError, c as PRESENTED, i as credentialsRequiredError, l as flag, n as authServiceError, o as noSessionForWorkspaceError, r as credentialRejectedError, s as serviceTokenRejectedError, t as buildEngine, u as positional } from "./engine-vF4FiZqo.js";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
@@ -52,6 +52,7 @@ function defineCommand(def) {
|
|
|
52
52
|
args: normalizeArgs(def.args),
|
|
53
53
|
needs: normalizeNeeds(def.needs),
|
|
54
54
|
exitCodes: def.exitCodes ?? {},
|
|
55
|
+
managesCredentials: def.managesCredentials ?? false,
|
|
55
56
|
handler: def.handler
|
|
56
57
|
});
|
|
57
58
|
}
|
|
@@ -197,4 +198,4 @@ function defineConfigSection(spec) {
|
|
|
197
198
|
});
|
|
198
199
|
}
|
|
199
200
|
//#endregion
|
|
200
|
-
export { PRESENTED, PRISMA_CONFIG_VERSION, createCli, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, flag, loadConfig, positional };
|
|
201
|
+
export { PRESENTED, PRISMA_CONFIG_VERSION, authServiceError, createCli, credentialRejectedError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, emptyServiceTokenError, flag, loadConfig, noSessionForWorkspaceError, positional, serviceTokenRejectedError };
|
|
@@ -27,10 +27,14 @@ interface Diagnostic {
|
|
|
27
27
|
* The typed agent-facing follow-up action.
|
|
28
28
|
*/
|
|
29
29
|
interface NextAction {
|
|
30
|
-
readonly kind: "run-command" | "user-choice" | "edit-file" | "done";
|
|
30
|
+
readonly kind: "run-command" | "open-url" | "user-choice" | "edit-file" | "done";
|
|
31
31
|
readonly label: string;
|
|
32
32
|
readonly command?: string;
|
|
33
33
|
readonly commands?: readonly string[];
|
|
34
|
+
/** The address an `open-url` action sends the user to. A URL is not
|
|
35
|
+
* a command: putting one in `command` tells a consumer to execute
|
|
36
|
+
* it. */
|
|
37
|
+
readonly url?: string;
|
|
34
38
|
readonly reason?: string;
|
|
35
39
|
}
|
|
36
40
|
/**
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as NotOk, c as notOk, i as NextAction, l as ok, n as CliStructuredError, o as Ok, r as Diagnostic, s as Result, t as CliErrorEnvelope, u as okVoid } from "./protocol-
|
|
1
|
+
import { a as NotOk, c as notOk, i as NextAction, l as ok, n as CliStructuredError, o as Ok, r as Diagnostic, s as Result, t as CliErrorEnvelope, u as okVoid } from "./protocol-CpZLdxML.js";
|
|
2
2
|
export { type CliErrorEnvelope, CliStructuredError, type Diagnostic, type NextAction, type NotOk, type Ok, type Result, notOk, ok, okVoid };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as NextAction, n as CliStructuredError, r as Diagnostic, s as Result } from "./protocol-
|
|
2
|
-
import { ManagementApiClient } from "@prisma/management-api-sdk";
|
|
1
|
+
import { i as NextAction, n as CliStructuredError, r as Diagnostic, s as Result } from "./protocol-CpZLdxML.js";
|
|
2
|
+
import { ManagementApiClient, TokenStorage } from "@prisma/management-api-sdk";
|
|
3
3
|
|
|
4
4
|
//#region src/args.d.ts
|
|
5
5
|
/**
|
|
@@ -127,6 +127,150 @@ declare function defineConfigSection<T>(spec: {
|
|
|
127
127
|
readonly validate: (raw: unknown | undefined) => SectionValidation<T>;
|
|
128
128
|
}): ConfigSection<T>;
|
|
129
129
|
//#endregion
|
|
130
|
+
//#region src/management-api.d.ts
|
|
131
|
+
/**
|
|
132
|
+
* The SDK's typed client, re-exported so consumers never import
|
|
133
|
+
* @prisma/management-api-sdk directly.
|
|
134
|
+
*/
|
|
135
|
+
type ManagementApiClient$1 = ManagementApiClient;
|
|
136
|
+
/**
|
|
137
|
+
* The SDK's token-storage contract, re-exported for the same reason.
|
|
138
|
+
* CredentialManager.activeCredentialStorage returns one; the engine
|
|
139
|
+
* forwards it into SDK client config and reads it only to tell a
|
|
140
|
+
* credential that could never be renewed from one that could.
|
|
141
|
+
*/
|
|
142
|
+
type TokenStorage$1 = TokenStorage;
|
|
143
|
+
/**
|
|
144
|
+
* SDK client construction config, injected by the bin beside the
|
|
145
|
+
* credential manager. All four fields: the SDK's refreshing fetch
|
|
146
|
+
* requires the full config even though only login paths read
|
|
147
|
+
* redirectUri.
|
|
148
|
+
*/
|
|
149
|
+
interface ManagementApiClientConfig {
|
|
150
|
+
readonly clientId: string;
|
|
151
|
+
readonly redirectUri: string;
|
|
152
|
+
readonly apiBaseUrl: string;
|
|
153
|
+
readonly authBaseUrl: string;
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/credential-manager.d.ts
|
|
157
|
+
/**
|
|
158
|
+
* The proof material. Seen by the login flow (which mints it),
|
|
159
|
+
* createSession (which stores it), and the engine (which authenticates
|
|
160
|
+
* with it). Never reaches a command.
|
|
161
|
+
*/
|
|
162
|
+
interface Credential {
|
|
163
|
+
readonly token: string;
|
|
164
|
+
readonly refreshToken: string | undefined;
|
|
165
|
+
readonly expiresAt: Date | undefined;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* A stored logged-in-ness for one workspace — the only thing called a
|
|
169
|
+
* session. It is what `sessions()` lists, what `selectSession` selects,
|
|
170
|
+
* and what `endSession` ends. The credential behind it is internal.
|
|
171
|
+
*/
|
|
172
|
+
interface Session {
|
|
173
|
+
readonly workspaceId: string;
|
|
174
|
+
readonly workspaceName: string | undefined;
|
|
175
|
+
/** The stored ACCESS TOKEN's expiry, which rotation changes — not a
|
|
176
|
+
* deadline on the logged-in-ness. */
|
|
177
|
+
readonly expiresAt: Date | undefined;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The stored sessions and which one is selected, read together: reads
|
|
181
|
+
* take no lock, so two reads could straddle a write and disagree.
|
|
182
|
+
* `selectedWorkspaceId` always names one of the listed sessions or is
|
|
183
|
+
* absent — a dangling selection never escapes the manager.
|
|
184
|
+
*/
|
|
185
|
+
interface StoredSessions {
|
|
186
|
+
readonly sessions: readonly Session[];
|
|
187
|
+
readonly selectedWorkspaceId: string | undefined;
|
|
188
|
+
}
|
|
189
|
+
/** Who the active credential belongs to, decoded from its own claims by
|
|
190
|
+
* the manager so no command ever holds a token to decode. */
|
|
191
|
+
interface CredentialIdentity {
|
|
192
|
+
readonly userId: string | undefined;
|
|
193
|
+
readonly email: string | undefined;
|
|
194
|
+
/** Only an online lookup supplies this; a token's claims do not
|
|
195
|
+
* carry it. */
|
|
196
|
+
readonly name: string | undefined;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Where the active credential came from — a question about the
|
|
200
|
+
* resolution, not about a session.
|
|
201
|
+
*/
|
|
202
|
+
interface CredentialOrigin {
|
|
203
|
+
/** Exists to be PRINTED: it feeds whoami's `source` field verbatim.
|
|
204
|
+
* Outside whoami's renderer and the credential-rejected error,
|
|
205
|
+
* comparing against this is a defect. */
|
|
206
|
+
readonly source: "stored" | "environment";
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* What this process authenticates as. Carries no token material.
|
|
210
|
+
*/
|
|
211
|
+
interface ActiveCredential {
|
|
212
|
+
/** Absent when nothing names it — an environment token whose claims
|
|
213
|
+
* carry no workspace. Never the empty string. */
|
|
214
|
+
readonly workspaceId: string | undefined;
|
|
215
|
+
readonly workspaceName: string | undefined;
|
|
216
|
+
readonly expiresAt: Date | undefined;
|
|
217
|
+
readonly identity: CredentialIdentity | undefined;
|
|
218
|
+
readonly origin: CredentialOrigin;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Manages the credentials this machine holds: the stored per-workspace
|
|
222
|
+
* sessions, which one is selected, and the credential this process
|
|
223
|
+
* authenticates as. Custody only — never opens a browser, never
|
|
224
|
+
* prompts, never talks to the user. Env is a construction input;
|
|
225
|
+
* nothing below the manager reads process.env. It resolves no user
|
|
226
|
+
* input: commands resolve refs against `sessions()` and pass a
|
|
227
|
+
* workspace id.
|
|
228
|
+
*/
|
|
229
|
+
interface CredentialManager {
|
|
230
|
+
/**
|
|
231
|
+
* What this process authenticates as. The DECISION — which
|
|
232
|
+
* credential, and from where — is pinned at first read; the material
|
|
233
|
+
* is read through the storage on every call, so a session replaced by
|
|
234
|
+
* another process still resolves. Local-only: never touches the
|
|
235
|
+
* network.
|
|
236
|
+
*/
|
|
237
|
+
activeCredential(): Promise<ActiveCredential | null>;
|
|
238
|
+
/** The stored sessions and the selection, read fresh. Local-only. */
|
|
239
|
+
sessions(): Promise<StoredSessions>;
|
|
240
|
+
/**
|
|
241
|
+
* Login's write. The caller names the workspace that identifies the
|
|
242
|
+
* session; for workspace-bound credentials the manager verifies the
|
|
243
|
+
* workspace_id claim matches and refuses on mismatch. Upserts by
|
|
244
|
+
* workspaceId and selects it. The workspace name is fetched
|
|
245
|
+
* best-effort after the write — failure leaves it undefined, never
|
|
246
|
+
* fails login.
|
|
247
|
+
*/
|
|
248
|
+
createSession(credential: Credential, workspaceId: string): Promise<Session>;
|
|
249
|
+
/**
|
|
250
|
+
* Select a session. Refuses a workspace with no session: there is no
|
|
251
|
+
* state in which it would afterwards be selected. Never sees the
|
|
252
|
+
* environment credential.
|
|
253
|
+
*/
|
|
254
|
+
selectSession(workspaceId: string): Promise<Session>;
|
|
255
|
+
/**
|
|
256
|
+
* End one workspace's session. Idempotent — a workspace with no
|
|
257
|
+
* session is already in the state this asks for. Clears the selection
|
|
258
|
+
* if it named that session; never auto-promotes another.
|
|
259
|
+
*/
|
|
260
|
+
endSession(workspaceId: string): Promise<void>;
|
|
261
|
+
/** End every session and clear the selection. */
|
|
262
|
+
endAllSessions(): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* ENGINE-FACING. Where the SDK reads and writes the active
|
|
265
|
+
* credential's tokens: file-backed for a stored session, memory-backed
|
|
266
|
+
* for one with no home record. Zero-argument because process pinning
|
|
267
|
+
* already ruled there is one credential per process, and an
|
|
268
|
+
* environment credential may have no workspace id to key on. Only
|
|
269
|
+
* valid once `activeCredential()` has returned non-null.
|
|
270
|
+
*/
|
|
271
|
+
activeCredentialStorage(): Promise<TokenStorage$1>;
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
130
274
|
//#region src/events.d.ts
|
|
131
275
|
/**
|
|
132
276
|
* The commentary severity scale; also the log-level axis. Distinct from
|
|
@@ -218,13 +362,6 @@ interface StreamMeta {
|
|
|
218
362
|
readonly timestamp: string;
|
|
219
363
|
}
|
|
220
364
|
//#endregion
|
|
221
|
-
//#region src/management-api.d.ts
|
|
222
|
-
/**
|
|
223
|
-
* The SDK's typed client, re-exported so consumers never import
|
|
224
|
-
* @prisma/management-api-sdk directly.
|
|
225
|
-
*/
|
|
226
|
-
type ManagementApiClient$1 = ManagementApiClient;
|
|
227
|
-
//#endregion
|
|
228
365
|
//#region src/presentation.d.ts
|
|
229
366
|
type Format = "human" | "json";
|
|
230
367
|
/**
|
|
@@ -323,10 +460,6 @@ interface Ui {
|
|
|
323
460
|
}
|
|
324
461
|
//#endregion
|
|
325
462
|
//#region src/context.d.ts
|
|
326
|
-
interface Credentials {
|
|
327
|
-
/** Opaque to the engine; shape owned by the Cloud auth library. */
|
|
328
|
-
readonly token: string;
|
|
329
|
-
}
|
|
330
463
|
/** The handler context — the whole world arrives as one argument. */
|
|
331
464
|
interface CommandContext<TConfig = undefined, TCode extends number = never> {
|
|
332
465
|
/**
|
|
@@ -341,23 +474,36 @@ interface CommandContext<TConfig = undefined, TCode extends number = never> {
|
|
|
341
474
|
*/
|
|
342
475
|
readonly present: <T>(outcome: Outcome<T, TCode>, presentations: Presentations) => PresentedResult<T>;
|
|
343
476
|
/**
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
477
|
+
* What this process authenticates as (the manager's pinned
|
|
478
|
+
* credential), or null when signed out. Carries no token material.
|
|
479
|
+
* Read-only and local-only — safe to call anywhere; never touches
|
|
480
|
+
* the network. Throws the same structured errors the needs check
|
|
481
|
+
* raises for broken-but-not-signed-out states (sessions held, none
|
|
482
|
+
* selected).
|
|
347
483
|
*/
|
|
348
|
-
readonly
|
|
484
|
+
readonly activeCredential: () => Promise<ActiveCredential | null>;
|
|
349
485
|
/**
|
|
350
|
-
* The Management API client
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
486
|
+
* The Management API client, constructed and owned by the ENGINE:
|
|
487
|
+
* the pinned credential's client, built on first method call, once
|
|
488
|
+
* per run. A request made while signed out throws the structured
|
|
489
|
+
* CLI.CREDENTIALS_REQUIRED error (the same constructor the
|
|
490
|
+
* needs.credentials check uses).
|
|
355
491
|
*/
|
|
356
492
|
readonly api: ManagementApiClient$1;
|
|
357
493
|
/** The one way to emit while running. */
|
|
358
494
|
readonly report: (event: EngineEvent) => void;
|
|
359
495
|
/** Interactive input. */
|
|
360
496
|
readonly prompt: PromptSurface;
|
|
497
|
+
/**
|
|
498
|
+
* Shows the user a URL and, in an interactive session, opens it in
|
|
499
|
+
* their browser. Always announces the URL on the commentary channel
|
|
500
|
+
* (an `endpoint` event: a stderr line in human mode, a frame in json
|
|
501
|
+
* mode), so a non-interactive run — which never opens anything — can
|
|
502
|
+
* still be completed by hand. Never fails: a browser that could not
|
|
503
|
+
* be opened reports `opened: false`. To wait for the user to finish
|
|
504
|
+
* something in that browser, use prompt.browserWait.
|
|
505
|
+
*/
|
|
506
|
+
readonly openUrl: (request: OpenUrlRequest) => Promise<OpenUrlOutcome>;
|
|
361
507
|
/**
|
|
362
508
|
* Fires on Ctrl-C/SIGTERM (engine-owned; a second signal force-exits
|
|
363
509
|
* through the runtime's exit proxy). Session commands run until it
|
|
@@ -379,6 +525,33 @@ interface CommandContext<TConfig = undefined, TCode extends number = never> {
|
|
|
379
525
|
*/
|
|
380
526
|
readonly requireDependency: (specifier: string) => Promise<Result<void, CliStructuredError>>;
|
|
381
527
|
}
|
|
528
|
+
interface OpenUrlRequest {
|
|
529
|
+
readonly url: string;
|
|
530
|
+
/** The announcement label — what the URL is for, in the user's
|
|
531
|
+
* terms ("Finish signing in"). */
|
|
532
|
+
readonly message: string;
|
|
533
|
+
}
|
|
534
|
+
interface OpenUrlOutcome {
|
|
535
|
+
/** False whenever the browser was not launched: a non-interactive
|
|
536
|
+
* session, a host with no opener wired, or an opener that failed. */
|
|
537
|
+
readonly opened: boolean;
|
|
538
|
+
}
|
|
539
|
+
interface BrowserWaitRequest {
|
|
540
|
+
readonly url: string;
|
|
541
|
+
/** The announcement label — what the user is being sent to do. */
|
|
542
|
+
readonly message: string;
|
|
543
|
+
/**
|
|
544
|
+
* Asks whether the user has finished. The engine calls it on its own
|
|
545
|
+
* interval and passes ctx.signal, so a poll that makes a request can
|
|
546
|
+
* abort with the command.
|
|
547
|
+
*/
|
|
548
|
+
readonly poll: (signal: AbortSignal) => Promise<boolean>;
|
|
549
|
+
/** Milliseconds to keep polling before giving up. */
|
|
550
|
+
readonly timeout: number;
|
|
551
|
+
/** Milliseconds between polls. Defaults to the engine's own
|
|
552
|
+
* interval; a command with its own configurable cadence passes it. */
|
|
553
|
+
readonly interval?: number;
|
|
554
|
+
}
|
|
382
555
|
/**
|
|
383
556
|
* Prompts. Every prompt resolves to its answered value directly.
|
|
384
557
|
* Failures THROW engine-internal structured errors the engine catches
|
|
@@ -400,10 +573,20 @@ interface PromptSurface {
|
|
|
400
573
|
}) => Promise<boolean>;
|
|
401
574
|
/**
|
|
402
575
|
* A question requiring explicit consent — never inferable.
|
|
403
|
-
* Structurally undefaultable: no default parameter exists, so --yes
|
|
404
|
-
* Enter-through
|
|
576
|
+
* Structurally undefaultable: no default parameter exists, so --yes
|
|
577
|
+
* and Enter-through can never satisfy it.
|
|
578
|
+
*
|
|
579
|
+
* `token` is the natural noun of what is being consented to — an app
|
|
580
|
+
* name, a hostname. Supplying one changes both halves of the prompt:
|
|
581
|
+
* interactively the user must type the token exactly instead of
|
|
582
|
+
* answering yes/no, and non-interactively the consent is granted by
|
|
583
|
+
* `--confirm <token>` on the command line (one `--confirm` value per
|
|
584
|
+
* consent). Without a token there is no non-interactive way to
|
|
585
|
+
* consent at all.
|
|
405
586
|
*/
|
|
406
|
-
readonly consent: (question: string
|
|
587
|
+
readonly consent: (question: string, opts?: {
|
|
588
|
+
readonly token?: string;
|
|
589
|
+
}) => Promise<boolean>;
|
|
407
590
|
readonly select: <T extends string>(question: string, options: ReadonlyArray<{
|
|
408
591
|
value: T;
|
|
409
592
|
label: string;
|
|
@@ -414,6 +597,20 @@ interface PromptSurface {
|
|
|
414
597
|
readonly placeholder?: string;
|
|
415
598
|
readonly default?: string;
|
|
416
599
|
}) => Promise<string>;
|
|
600
|
+
/**
|
|
601
|
+
* Sends the user to a URL and waits for them to finish there:
|
|
602
|
+
* announces the URL, opens the browser, then polls until `poll`
|
|
603
|
+
* returns true. Resolves when it does; throws the structured timeout
|
|
604
|
+
* error when `timeout` elapses first, and the usual prompt-cancelled
|
|
605
|
+
* error (exit 3) on Ctrl-C.
|
|
606
|
+
*
|
|
607
|
+
* Non-interactively it throws the interaction-required error before
|
|
608
|
+
* opening or polling anything, with the URL in the message so the
|
|
609
|
+
* user can finish by hand. A command that cannot do anything useful
|
|
610
|
+
* without an interactive terminal should declare `needs.interaction`
|
|
611
|
+
* instead and fail before it starts.
|
|
612
|
+
*/
|
|
613
|
+
readonly browserWait: (request: BrowserWaitRequest) => Promise<void>;
|
|
417
614
|
}
|
|
418
615
|
//#endregion
|
|
419
616
|
//#region src/runtime.d.ts
|
|
@@ -458,7 +655,27 @@ interface Runtime {
|
|
|
458
655
|
* the unified loader. Tests hand in fixtures.
|
|
459
656
|
*/
|
|
460
657
|
readonly config: LoadedConfig;
|
|
461
|
-
|
|
658
|
+
/**
|
|
659
|
+
* The credential manager the bin wires. It is the only source of
|
|
660
|
+
* the needs check, ctx.activeCredential, and ctx.api; absent means
|
|
661
|
+
* this host has no credentials at all, and every command that needs
|
|
662
|
+
* them fails as signed out.
|
|
663
|
+
*/
|
|
664
|
+
readonly credentialManager?: CredentialManager;
|
|
665
|
+
/**
|
|
666
|
+
* SDK client construction config the bin injects beside the
|
|
667
|
+
* manager; the engine builds ctx.api from it. Required whenever a
|
|
668
|
+
* credentialManager is wired.
|
|
669
|
+
*/
|
|
670
|
+
readonly managementApiClientConfig?: ManagementApiClientConfig;
|
|
671
|
+
/**
|
|
672
|
+
* Opens a URL in the user's browser, wired by the bin (the login
|
|
673
|
+
* flow's opener). The engine calls it only for interactive sessions,
|
|
674
|
+
* treats a throw as "did not open", and never fails a command over
|
|
675
|
+
* it. Absent means this host cannot open a browser: the engine
|
|
676
|
+
* announces the URL instead.
|
|
677
|
+
*/
|
|
678
|
+
readonly openUrl?: (url: string) => Promise<void> | void;
|
|
462
679
|
/** Management API endpoint config; the bin derives baseUrl from env. */
|
|
463
680
|
readonly managementApi: {
|
|
464
681
|
readonly baseUrl: string;
|
|
@@ -584,7 +801,7 @@ interface CommandNeeds<TConfig> {
|
|
|
584
801
|
readonly dependencies: readonly string[];
|
|
585
802
|
readonly interaction: boolean;
|
|
586
803
|
}
|
|
587
|
-
interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined, TCode extends number = never> {
|
|
804
|
+
interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined, TCode extends number = never, TManagesCredentials extends boolean = false> {
|
|
588
805
|
readonly kind: "result-command";
|
|
589
806
|
readonly help: CommandHelp;
|
|
590
807
|
readonly args: CommandArgs<TFlags, TPositionals>;
|
|
@@ -596,6 +813,14 @@ interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = R
|
|
|
596
813
|
* exits 0/1/2/3 and the outcome carries no exitCode.
|
|
597
814
|
*/
|
|
598
815
|
readonly exitCodes: Readonly<Record<TCode, string>>;
|
|
816
|
+
/**
|
|
817
|
+
* A CAPABILITY, not a need: when true, ctx.credentialManager appears
|
|
818
|
+
* on the context. Declaring it never fails a run — this is
|
|
819
|
+
* documentation and testability, not enforcement. Declared by
|
|
820
|
+
* exactly the auth commands that operate ON the credential
|
|
821
|
+
* machinery.
|
|
822
|
+
*/
|
|
823
|
+
readonly managesCredentials: TManagesCredentials;
|
|
599
824
|
/**
|
|
600
825
|
* The handler function, referenced directly — never a dynamic import
|
|
601
826
|
* (operator ruling, 2026-08-09). A handler that needs heavy
|
|
@@ -603,11 +828,21 @@ interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = R
|
|
|
603
828
|
* handler defined in another file is imported statically and
|
|
604
829
|
* annotated CommandHandler<typeof def>.
|
|
605
830
|
*/
|
|
606
|
-
readonly handler: Handler<TFlags, TPositionals, TConfig, TCode>;
|
|
831
|
+
readonly handler: Handler<TFlags, TPositionals, TConfig, TCode, TManagesCredentials>;
|
|
607
832
|
}
|
|
608
|
-
type Handler<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>, TConfig, TCode extends number = never> = (args: Args<TFlags, TPositionals>, ctx: CommandContext<TConfig, TCode>
|
|
833
|
+
type Handler<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>, TConfig, TCode extends number = never, TManagesCredentials extends boolean = false> = (args: Args<TFlags, TPositionals>, ctx: CommandContext<TConfig, TCode> & (TManagesCredentials extends true ? {
|
|
834
|
+
readonly credentialManager: CredentialManager;
|
|
835
|
+
} : unknown)) => Promise<Result<PresentedResult<unknown>, CliStructuredError>>;
|
|
609
836
|
/** For impl files: `const run: CommandHandler<typeof migrateCommand> = …` */
|
|
610
|
-
type CommandHandler<D> = D extends CommandDefinition<infer F, infer P, infer C, infer K> ? Handler<F, P, C, K> : never;
|
|
837
|
+
type CommandHandler<D> = D extends CommandDefinition<infer F, infer P, infer C, infer K, infer M> ? Handler<F, P, C, K, M> : never;
|
|
838
|
+
declare function defineCommand<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined, TCode extends number = never>(def: {
|
|
839
|
+
readonly help: HelpSpec;
|
|
840
|
+
readonly args?: ArgsSpec<TFlags, TPositionals>;
|
|
841
|
+
readonly needs?: NeedsSpec<TConfig>;
|
|
842
|
+
readonly exitCodes?: Readonly<Record<TCode, string>>;
|
|
843
|
+
readonly managesCredentials: true;
|
|
844
|
+
readonly handler: Handler<TFlags, TPositionals, TConfig, TCode, true>;
|
|
845
|
+
}): CommandDefinition<TFlags, TPositionals, TConfig, TCode, true>;
|
|
611
846
|
declare function defineCommand<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined, TCode extends number = never>(def: {
|
|
612
847
|
readonly help: HelpSpec;
|
|
613
848
|
readonly args?: ArgsSpec<TFlags, TPositionals>;
|
|
@@ -667,7 +902,7 @@ declare function defineServerCommand<TFlags extends Record<string, FlagSpec<unkn
|
|
|
667
902
|
* concrete types travel through each definition's generics, not through
|
|
668
903
|
* this union.
|
|
669
904
|
*/
|
|
670
|
-
type AnyCommand = (Omit<CommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown, number>, "handler"> & {
|
|
905
|
+
type AnyCommand = (Omit<CommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown, number, boolean>, "handler"> & {
|
|
671
906
|
readonly handler: unknown;
|
|
672
907
|
}) | (Omit<SessionCommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown>, "handler"> & {
|
|
673
908
|
readonly handler: unknown;
|
|
@@ -784,4 +1019,4 @@ interface RunSummary {
|
|
|
784
1019
|
readonly snapshot: EngineCommandSnapshot;
|
|
785
1020
|
}
|
|
786
1021
|
//#endregion
|
|
787
|
-
export {
|
|
1022
|
+
export { TokenStorage$1 as $, OpenUrlRequest as A, EngineEvent as B, LoadedConfig as C, BrowserWaitRequest as D, Runtime as E, PRESENTED as F, Credential as G, StreamEvent as H, Presentations as I, CredentialOrigin as J, CredentialIdentity as K, PresentedResult as L, Block as M, Format as N, CommandContext as O, Outcome as P, ManagementApiClientConfig as Q, TreeNode as R, InputStream as S, PRISMA_CONFIG_VERSION as T, StreamMeta as U, Severity as V, ActiveCredential as W, StoredSessions as X, Session as Y, ManagementApiClient$1 as Z, SessionCommandDefinition as _, defineCommandFamily as a, Char as at, defineSessionCommand as b, CommandHandler as c, PositionalSpec as ct, CompletedEnvelope as d, ConfigSection as et, ErroredEnvelope as f, ServerCommandDefinition as g, NeedsSpec as h, MountedTree as i, ArgsSpec as it, PromptSurface as j, OpenUrlOutcome as k, CommandHelp as l, flag as lt, HelpSpec as m, RunSummary as n, defineConfigSection as nt, AnyCommand as o, CommandArgs as ot, Handler as p, CredentialManager as q, CommandFamily as r, Args as rt, CommandDefinition as s, FlagSpec as st, EngineCommandSnapshot as t, SectionValidation as tt, CommandNeeds as u, positional as ut, defineCommand as v, OutputStream as w, HostProcess as x, defineServerCommand as y, Ui as z };
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,7 +1,87 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as TokenStorage, B as EngineEvent, G as Credential, H as StreamEvent, L as PresentedResult, Q as ManagementApiClientConfig, W as ActiveCredential, X as StoredSessions, Y as Session, Z as ManagementApiClient, i as MountedTree, n as RunSummary, q as CredentialManager, r as CommandFamily } from "./run-summary-CZITSYO_.js";
|
|
2
2
|
|
|
3
|
+
//#region src/in-memory-credential-manager.d.ts
|
|
4
|
+
/** A stored session with its credential material — what the manager
|
|
5
|
+
* holds, seeded in and read back out. Mirrors the state file's
|
|
6
|
+
* records. */
|
|
7
|
+
interface SessionRecord {
|
|
8
|
+
readonly workspaceId: string;
|
|
9
|
+
readonly workspaceName: string | undefined;
|
|
10
|
+
readonly credential: Credential;
|
|
11
|
+
}
|
|
12
|
+
interface InMemoryCredentialManagerSeed {
|
|
13
|
+
/** Stored sessions, mirroring the state file's records. */
|
|
14
|
+
readonly sessions?: readonly SessionRecord[];
|
|
15
|
+
/** The stored selection — the workspace whose session is used where
|
|
16
|
+
* a session is needed. */
|
|
17
|
+
readonly selectedWorkspaceId?: string;
|
|
18
|
+
/** Convenience seed: runs createSession's real claims derivation.
|
|
19
|
+
* The token must be a JWT with `workspace_id` (use mintTestJwt). */
|
|
20
|
+
readonly credential?: Credential;
|
|
21
|
+
/** The credential PRISMA_SERVICE_TOKEN supplies. Its token may carry
|
|
22
|
+
* no `workspace_id` claim, and it may carry a refresh token. */
|
|
23
|
+
readonly environmentCredential?: Credential;
|
|
24
|
+
}
|
|
25
|
+
/** The whole stored state, readable back after a run. */
|
|
26
|
+
interface InMemoryCredentialManagerState {
|
|
27
|
+
readonly sessions: readonly SessionRecord[];
|
|
28
|
+
readonly selectedWorkspaceId: string | undefined;
|
|
29
|
+
}
|
|
30
|
+
/** Mints an unsigned JWT whose payload is exactly `claims` — the
|
|
31
|
+
* harness's claim source (`sub`, `workspace_id`, `exp`, `email`). */
|
|
32
|
+
declare function mintTestJwt(claims: Readonly<Record<string, unknown>>): string;
|
|
33
|
+
/**
|
|
34
|
+
* The harness's mutable in-memory CredentialManager: the same
|
|
35
|
+
* interface commands see, with the whole stored state readable back
|
|
36
|
+
* after a run, and the design's process pinning — which credential
|
|
37
|
+
* this process acts as is fixed at the first activeCredential() read,
|
|
38
|
+
* while the material behind it is re-read on every call. No
|
|
39
|
+
* persistence, no locking — those belong to the real manager and its
|
|
40
|
+
* own tests.
|
|
41
|
+
*/
|
|
42
|
+
declare class InMemoryCredentialManager implements CredentialManager {
|
|
43
|
+
private storedSessions;
|
|
44
|
+
private selection;
|
|
45
|
+
private readonly environmentCredential;
|
|
46
|
+
private pin;
|
|
47
|
+
private activeStorage;
|
|
48
|
+
constructor(seed: InMemoryCredentialManagerSeed);
|
|
49
|
+
state(): InMemoryCredentialManagerState;
|
|
50
|
+
/** Applies a write as ANOTHER process would: the stored state
|
|
51
|
+
* changes, but this process's pinned decision does not move. */
|
|
52
|
+
overwriteStoredState(state: {
|
|
53
|
+
readonly sessions?: readonly SessionRecord[];
|
|
54
|
+
readonly selectedWorkspaceId?: string | undefined;
|
|
55
|
+
}): void;
|
|
56
|
+
activeCredential(): Promise<ActiveCredential | null>;
|
|
57
|
+
sessions(): Promise<StoredSessions>;
|
|
58
|
+
createSession(credential: Credential, workspaceId: string): Promise<Session>;
|
|
59
|
+
selectSession(workspaceId: string): Promise<Session>;
|
|
60
|
+
endSession(workspaceId: string): Promise<void>;
|
|
61
|
+
endAllSessions(): Promise<void>;
|
|
62
|
+
activeCredentialStorage(): Promise<TokenStorage>;
|
|
63
|
+
private buildActiveStorage;
|
|
64
|
+
/** The file-backed storage's analogue: the record is read afresh on
|
|
65
|
+
* every call, never snapshotted. */
|
|
66
|
+
private storedSessionStorage;
|
|
67
|
+
private removeRecord;
|
|
68
|
+
private resolvePin;
|
|
69
|
+
/** The selection the manager will admit to: one that names a stored
|
|
70
|
+
* session, or none. A dangling selection never escapes. */
|
|
71
|
+
private resolvedSelection;
|
|
72
|
+
private credentialForPin;
|
|
73
|
+
private requireEnvironmentCredential;
|
|
74
|
+
private applyCreateSession;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
3
77
|
//#region src/testing.d.ts
|
|
4
78
|
interface TestCli {
|
|
79
|
+
/**
|
|
80
|
+
* The mutable in-memory credential manager backing the runs — the
|
|
81
|
+
* whole stored state (sessions with their credentials, the
|
|
82
|
+
* selection) is readable back after a run via state().
|
|
83
|
+
*/
|
|
84
|
+
readonly credentialManager: InMemoryCredentialManager;
|
|
5
85
|
run(argv: readonly string[], opts?: {
|
|
6
86
|
readonly stdin?: string;
|
|
7
87
|
/**
|
|
@@ -53,15 +133,36 @@ declare function createTestCli(spec: {
|
|
|
53
133
|
readonly brief: string;
|
|
54
134
|
}>>;
|
|
55
135
|
readonly config?: Readonly<Record<string, unknown>>;
|
|
56
|
-
|
|
136
|
+
/** Convenience manager seed: createSession runs its real claims
|
|
137
|
+
* derivation on this credential (mint the token with mintTestJwt). */
|
|
138
|
+
readonly credential?: Credential; /** Stored sessions, mirroring the state file's records. */
|
|
139
|
+
readonly sessions?: readonly SessionRecord[]; /** The stored selection. */
|
|
140
|
+
readonly selectedWorkspaceId?: string;
|
|
141
|
+
/** The credential PRISMA_SERVICE_TOKEN supplies. Its access token is
|
|
142
|
+
* also exported to each run's env as PRISMA_SERVICE_TOKEN
|
|
143
|
+
* (overridable per run). */
|
|
144
|
+
readonly environmentCredential?: Credential;
|
|
145
|
+
/** The SDK client construction config; defaults point every
|
|
146
|
+
* endpoint at test.invalid hosts. */
|
|
147
|
+
readonly managementApiClientConfig?: ManagementApiClientConfig;
|
|
57
148
|
/** baseUrl defaults to "https://test.invalid"; when `client` is
|
|
58
149
|
* supplied, ctx.api IS that object. */
|
|
59
150
|
readonly managementApi?: {
|
|
60
151
|
readonly baseUrl?: string;
|
|
61
152
|
readonly client?: ManagementApiClient;
|
|
62
153
|
};
|
|
63
|
-
readonly packageManager?: "npm" | "pnpm" | "yarn" | "bun" | "unknown";
|
|
154
|
+
readonly packageManager?: "npm" | "pnpm" | "yarn" | "bun" | "unknown";
|
|
155
|
+
/** Fixed clock for deterministic stream timestamps; a clock that
|
|
156
|
+
* advances also drives prompt.browserWait's timeout. */
|
|
64
157
|
readonly now?: () => Date;
|
|
158
|
+
/** The browser opener behind ctx.openUrl and prompt.browserWait.
|
|
159
|
+
* Defaults to one that succeeds without doing anything; pass a spy
|
|
160
|
+
* to assert what was opened, or a thrower to exercise the
|
|
161
|
+
* could-not-open path. */
|
|
162
|
+
readonly openUrl?: (url: string) => Promise<void> | void;
|
|
163
|
+
/** Waiting is instant under test whatever this does; pass a spy to
|
|
164
|
+
* assert the interval a poll loop asked for. */
|
|
165
|
+
readonly delay?: (ms: number, signal: AbortSignal) => Promise<void>;
|
|
65
166
|
}): TestCli;
|
|
66
167
|
//#endregion
|
|
67
|
-
export { type TestCli, createTestCli };
|
|
168
|
+
export { InMemoryCredentialManager, type InMemoryCredentialManagerSeed, type InMemoryCredentialManagerState, type SessionRecord, type TestCli, createTestCli, mintTestJwt };
|