@prisma/cli-engine 0.1.1 → 0.2.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/dist/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
- import { $ as Outcome, A as InputStream, At as CommandArgs, B as ExitWithChildStatusOptions, C as BrowserWaitRequest, Ct as TokenStorage, D as PromptSurface, Dt as Args, E as OpenUrlRequest, Et as defineConfigSection, F as TelemetryPayload, G as exitWithChildStatus, H as SpawnOptions, I as EngineCommandSnapshot, J as PackageManagerRunResult, K as PackageManagerId, L as RunSummary, M as OutputStream, Mt as PositionalSpec, N as PRISMA_CONFIG_VERSION, Nt as flag, O as Host, Ot as ArgsSpec, P as Runtime, Pt as positional, Q as Format, R as ChildResult, S as defineSessionCommand, St as ManagementApiClientConfig, T as OpenUrlOutcome, Tt as SectionValidation, U as SpawnRequest, V as SpawnChild, W as SpawnedChild, X as PackageOperations, Y as PackageManagerRunner, Z as Block, _ as ServerCommandDefinition, _t as CredentialOrigin, a as RedirectSpec, at as Text, b as defineCommand, bt as StoredSessions, c as CommandDefinition, ct as Ui, d as CommandNeeds, dt as StreamEvent, et as PRESENTED, f as CompletedEnvelope, ft as StreamMeta, g as NeedsSpec, gt as CredentialManager, h as HelpSpec, ht as CredentialIdentity, i as MountedTree, it as Status, j as LoadedConfig, jt as FlagSpec, k as HostProcess, kt as Char, l as CommandHandler, lt as EngineEvent, m as Handler, mt as Credential, n as CommandFamily, nt as PresentedResult, o as defineCommandFamily, ot as Tone, p as ErroredEnvelope, pt as ActiveCredential, q as PackageManagerRunRequest, r as CommandRedirect, rt as Span, s as AnyCommand, st as TreeNode, t as TelemetryDeclaration, tt as Presentations, u as CommandHelp, ut as Severity, v as SessionCommandDefinition, vt as SERVICE_TOKEN_ENV_VAR, w as CommandContext, wt as ConfigSection, x as defineServerCommand, xt as ManagementApiClient, y as SpawnDeclarations, yt as Session, z as ChildStatusSettlement } from "./report-DID_e0si.js";
1
+ import { $ as Outcome, A as InputStream, At as SERVICE_TOKEN_ENV_VAR, B as ExitWithChildStatusOptions, C as BrowserWaitRequest, Ct as positional, D as PromptSurface, Dt as CredentialIdentity, E as OpenUrlRequest, Et as Credential, F as TelemetryPayload, Ft as ManagementApiClient, G as exitWithChildStatus, H as SpawnOptions, I as EngineCommandSnapshot, It as ManagementApiClientConfig, J as PackageManagerRunResult, K as PackageManagerId, L as RunSummary, Lt as TokenStorage, M as OutputStream, Mt as StoredSessions, N as PRISMA_CONFIG_VERSION, Nt as CredentialRefreshResult, O as Host, Ot as CredentialManager, P as Runtime, Pt as CredentialRefresher, Q as Format, R as ChildResult, S as defineSessionCommand, St as flag, T as OpenUrlOutcome, Tt as ActiveCredential, U as SpawnRequest, V as SpawnChild, W as SpawnedChild, X as PackageOperations, Y as PackageManagerRunner, Z as Block, _ as ServerCommandDefinition, _t as ArgsSpec, a as RedirectSpec, at as Text, b as defineCommand, bt as FlagSpec, c as CommandDefinition, ct as Ui, d as CommandNeeds, dt as StreamEvent, et as PRESENTED, f as CompletedEnvelope, ft as StreamMeta, g as NeedsSpec, gt as Args, h as HelpSpec, ht as defineConfigSection, i as MountedTree, it as Status, j as LoadedConfig, jt as Session, k as HostProcess, kt as CredentialOrigin, l as CommandHandler, lt as EngineEvent, m as Handler, mt as SectionValidation, n as CommandFamily, nt as PresentedResult, o as defineCommandFamily, ot as Tone, p as ErroredEnvelope, pt as ConfigSection, q as PackageManagerRunRequest, r as CommandRedirect, rt as Span, s as AnyCommand, st as TreeNode, t as TelemetryDeclaration, tt as Presentations, u as CommandHelp, ut as Severity, v as SessionCommandDefinition, vt as Char, w as CommandContext, wt as ActiveAccessTokenOptions, x as defineServerCommand, xt as PositionalSpec, y as SpawnDeclarations, yt as CommandArgs, z as ChildStatusSettlement } from "./report-BpE5F1IH.js";
2
2
  import { n as CliStructuredError } from "./protocol-YjqPCCOG.js";
3
3
 
4
+ //#region src/active-access-token.d.ts
5
+ /** Shared implementation used by every CredentialManager. */
6
+ declare function readActiveAccessToken(storage: TokenStorage, refreshCredential: CredentialRefresher | undefined, options: ActiveAccessTokenOptions): Promise<string | null>;
7
+ //#endregion
4
8
  //#region src/cli.d.ts
5
9
  /**
6
10
  * The observation hooks a bin may attach to a run. Deliberately
@@ -129,9 +133,9 @@ declare class EnvironmentCredentialManager implements CredentialManager {
129
133
  endSession(_workspaceId: string): Promise<void>;
130
134
  endAllSessions(): Promise<void>;
131
135
  activeCredentialStorage(): Promise<TokenStorage>;
132
- /** The spawn path's read: the env token passes through directly. It
136
+ /** The delegated path's read: the env token passes through directly. It
133
137
  * is already a snapshot with no refresh token behind it. */
134
- activeAccessToken(): Promise<string | null>;
138
+ activeAccessToken(options: ActiveAccessTokenOptions): Promise<string | null>;
135
139
  }
136
140
  //#endregion
137
141
  //#region src/telemetry/gating.d.ts
@@ -195,4 +199,4 @@ declare function claimedExpiresAt(token: string): Date | undefined;
195
199
  */
196
200
  declare function claimedIdentity(token: string): CredentialIdentity | undefined;
197
201
  //#endregion
198
- export { type ActiveCredential, type AnyCommand, type Args, type ArgsSpec, type Block, type BrowserWaitRequest, type Char, type ChildResult, type ChildStatusSettlement, type Cli, type CliRunHooks, type CommandArgs, type CommandContext, type CommandDefinition, type CommandFamily, type CommandHandler, type CommandHelp, type CommandNeeds, type CommandRedirect, type CompletedEnvelope, type ConfigSection, type Credential, type CredentialIdentity, type CredentialManager, type CredentialOrigin, type CredentialsRequiredReason, type EngineCommandSnapshot, type EngineEvent, EnvironmentCredentialManager, type ErroredEnvelope, type ExitWithChildStatusOptions, type FlagSpec, type Format, type Handler, type HelpSpec, type Host, 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 PackageManagerId, type PackageManagerRunRequest, type PackageManagerRunResult, type PackageManagerRunner, type PackageOperations, type PositionalSpec, type Presentations, type PresentedResult, type PromptSurface, type RedirectSpec, type RunSummary, type Runtime, SERVICE_TOKEN_ENV_VAR, type SectionValidation, type ServerCommandDefinition, type Session, type SessionCommandDefinition, type Severity, type Span, type SpawnChild, type SpawnDeclarations, type SpawnOptions, type SpawnRequest, type SpawnedChild, type Status, type StoredSessions, type StreamEvent, type StreamMeta, type TelemetryDeclaration, type TelemetryPayload, type TelemetryStatus, type TelemetryStatusReason, type Text, type TokenStorage, type Tone, type TreeNode, type Ui, authServiceError, claimedExpiresAt, claimedIdentity, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, definePrismaConfig, defineServerCommand, defineSessionCommand, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional, telemetryCommandGroup };
202
+ export { type ActiveAccessTokenOptions, type ActiveCredential, type AnyCommand, type Args, type ArgsSpec, type Block, type BrowserWaitRequest, type Char, type ChildResult, type ChildStatusSettlement, type Cli, type CliRunHooks, type CommandArgs, type CommandContext, type CommandDefinition, type CommandFamily, type CommandHandler, type CommandHelp, type CommandNeeds, type CommandRedirect, type CompletedEnvelope, type ConfigSection, type Credential, type CredentialIdentity, type CredentialManager, type CredentialOrigin, type CredentialRefreshResult, type CredentialRefresher, type CredentialsRequiredReason, type EngineCommandSnapshot, type EngineEvent, EnvironmentCredentialManager, type ErroredEnvelope, type ExitWithChildStatusOptions, type FlagSpec, type Format, type Handler, type HelpSpec, type Host, 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 PackageManagerId, type PackageManagerRunRequest, type PackageManagerRunResult, type PackageManagerRunner, type PackageOperations, type PositionalSpec, type Presentations, type PresentedResult, type PromptSurface, type RedirectSpec, type RunSummary, type Runtime, SERVICE_TOKEN_ENV_VAR, type SectionValidation, type ServerCommandDefinition, type Session, type SessionCommandDefinition, type Severity, type Span, type SpawnChild, type SpawnDeclarations, type SpawnOptions, type SpawnRequest, type SpawnedChild, type Status, type StoredSessions, type StreamEvent, type StreamMeta, type TelemetryDeclaration, type TelemetryPayload, type TelemetryStatus, type TelemetryStatusReason, type Text, type TokenStorage, type Tone, type TreeNode, type Ui, authServiceError, claimedExpiresAt, claimedIdentity, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, definePrismaConfig, defineServerCommand, defineSessionCommand, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional, readActiveAccessToken, telemetryCommandGroup };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { C as exitWithChildStatus, S as resolveGating, T as positional, _ as noSessionForWorkspaceError, b as userConfigPath, c as loadConfig, d as WORKSPACE_ID_ENV_VAR, f as authServiceError, g as emptyServiceTokenError, h as credentialsRequiredError, i as buildEngine, l as PRISMA_CONFIG_VERSION, m as credentialWorkspaceMismatchError, n as claimedIdentity, o as defineConfig, p as credentialRejectedError, r as credentialWorkspaceId, s as definePrismaConfig, t as claimedExpiresAt, u as SERVICE_TOKEN_ENV_VAR, v as PRESENTED, w as flag, x as writeUserConfig, y as readUserConfig } from "./token-claims-B-rQgBjv.js";
2
- import { i as ok, r as notOk, t as CliStructuredError } from "./protocol-D1CRNkhv.js";
1
+ import { i as ok, r as notOk, t as CliStructuredError } from "./protocol-TtNVkeVS.js";
2
+ import { C as credentialWorkspaceMismatchError, E as noSessionForWorkspaceError, S as credentialRejectedError, T as emptyServiceTokenError, _ as readActiveAccessToken, a as loadConfig, b as credentialWorkspaceId, c as WORKSPACE_ID_ENV_VAR, d as userConfigPath, f as writeUserConfig, g as positional, h as flag, i as definePrismaConfig, l as PRESENTED, m as exitWithChildStatus, o as PRISMA_CONFIG_VERSION, p as resolveGating, r as defineConfig, s as SERVICE_TOKEN_ENV_VAR, t as buildEngine, u as readUserConfig, v as claimedExpiresAt, w as credentialsRequiredError, x as authServiceError, y as claimedIdentity } from "./engine-Az5SU8Aa.js";
3
3
  //#region src/cli.ts
4
4
  /**
5
5
  * Shell-side construction. Group help is declared with the mount.
@@ -161,10 +161,11 @@ var EnvironmentCredentialManager = class {
161
161
  this.#activeStorage ??= this.#buildActiveStorage();
162
162
  return this.#activeStorage;
163
163
  }
164
- /** The spawn path's read: the env token passes through directly. It
164
+ /** The delegated path's read: the env token passes through directly. It
165
165
  * is already a snapshot with no refresh token behind it. */
166
- async activeAccessToken() {
167
- return this.#token() ?? null;
166
+ async activeAccessToken(options) {
167
+ if (await this.activeCredential() === null) return null;
168
+ return readActiveAccessToken(await this.activeCredentialStorage(), void 0, options);
168
169
  }
169
170
  #buildActiveStorage() {
170
171
  const token = this.#token();
@@ -172,7 +173,8 @@ var EnvironmentCredentialManager = class {
172
173
  let tokens = {
173
174
  workspaceId: this.#workspaceId(token) ?? NO_WORKSPACE_NAMED,
174
175
  accessToken: token,
175
- refreshToken: void 0
176
+ refreshToken: void 0,
177
+ expiresAt: claimedExpiresAt(token)
176
178
  };
177
179
  const singleFlight = (fn) => {
178
180
  const queued = this.#refreshLock.then(fn, fn);
@@ -181,8 +183,11 @@ var EnvironmentCredentialManager = class {
181
183
  };
182
184
  return {
183
185
  getTokens: async () => tokens,
184
- setTokens: async (rotated) => {
185
- tokens = rotated;
186
+ setTokens: async (rotated, expiresAt) => {
187
+ tokens = {
188
+ ...rotated,
189
+ expiresAt: claimedExpiresAt(rotated.accessToken) ?? expiresAt ?? tokens?.expiresAt
190
+ };
186
191
  },
187
192
  clearTokens: async () => {
188
193
  tokens = null;
@@ -373,4 +378,4 @@ Telemetry is on by default (opt-out); see ${options.docsUrl}\nfor what is collec
373
378
  };
374
379
  }
375
380
  //#endregion
376
- export { EnvironmentCredentialManager, PRESENTED, PRISMA_CONFIG_VERSION, SERVICE_TOKEN_ENV_VAR, authServiceError, claimedExpiresAt, claimedIdentity, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, definePrismaConfig, defineServerCommand, defineSessionCommand, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional, telemetryCommandGroup };
381
+ export { EnvironmentCredentialManager, PRESENTED, PRISMA_CONFIG_VERSION, SERVICE_TOKEN_ENV_VAR, authServiceError, claimedExpiresAt, claimedIdentity, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, definePrismaConfig, defineServerCommand, defineSessionCommand, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional, readActiveAccessToken, telemetryCommandGroup };
package/dist/protocol.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as okVoid, i as ok, n as STRUCTURED_ERROR, r as notOk, t as CliStructuredError } from "./protocol-D1CRNkhv.js";
1
+ import { a as okVoid, i as ok, n as STRUCTURED_ERROR, r as notOk, t as CliStructuredError } from "./protocol-TtNVkeVS.js";
2
2
  export { CliStructuredError, STRUCTURED_ERROR, notOk, ok, okVoid };
@@ -1,154 +1,26 @@
1
1
  import { i as NextAction, n as CliStructuredError, r as Diagnostic, s as Result } from "./protocol-YjqPCCOG.js";
2
2
  import { ManagementApiClient, TokenStorage } from "@prisma/management-api-sdk";
3
3
 
4
- //#region src/args.d.ts
5
- /**
6
- * Single-character alias, enforced at the type level: `Char<'q'>` is
7
- * 'q'; `Char<'ab'>` is never.
8
- */
9
- type Char<S extends string> = S extends `${string}${infer Rest}` ? Rest extends "" ? S : never : never;
10
- interface FlagSpec<T> {
11
- /** Phantom type carrier for inference; never present at runtime. */
12
- readonly __flag?: T;
13
- }
14
- /**
15
- * Command-declared flags. The shared family (--format/--json,
16
- * --log-level/--verbose, --quiet, --yes, --interactive, --color) is
17
- * engine-injected and reserved. Flags are optional by default
18
- * (requiredString is the exception); positionals are required by
19
- * default (optionalString is the exception).
20
- */
21
- declare const flag: {
22
- string<A extends string = never>(spec: {
23
- brief: string;
24
- placeholder?: string;
25
- alias?: A & Char<A>;
26
- default?: string;
27
- }): FlagSpec<string | undefined>;
28
- requiredString<A extends string = never>(spec: {
29
- brief: string;
30
- placeholder?: string;
31
- alias?: A & Char<A>;
32
- }): FlagSpec<string>;
33
- number<A extends string = never>(spec: {
34
- brief: string;
35
- placeholder?: string;
36
- alias?: A & Char<A>;
37
- default?: number;
38
- }): FlagSpec<number | undefined>;
39
- boolean<A extends string = never>(spec: {
40
- brief: string;
41
- alias?: A & Char<A>;
42
- }): FlagSpec<boolean>;
43
- /**
44
- * A boolean the user can leave unsaid: `--flag`, `--no-flag`, or
45
- * neither, which arrives as undefined. Use it when absence means
46
- * something of its own — "ask me" rather than "no".
47
- */
48
- optionalBoolean<A extends string = never>(spec: {
49
- brief: string;
50
- alias?: A & Char<A>;
51
- }): FlagSpec<boolean | undefined>;
52
- enum<const T extends readonly string[], A extends string = never>(spec: {
53
- brief: string;
54
- values: T;
55
- alias?: A & Char<A>;
56
- default?: T[number];
57
- }): FlagSpec<T[number] | undefined>;
58
- repeated<A extends string = never>(spec: {
59
- brief: string;
60
- placeholder?: string;
61
- alias?: A & Char<A>;
62
- }): FlagSpec<readonly string[]>;
63
- };
64
- interface PositionalSpec<T> {
65
- /** Phantom type carrier for inference; never present at runtime. */
66
- readonly __positional?: T;
67
- }
68
- declare const positional: {
69
- string(spec: {
70
- brief: string;
71
- placeholder: string;
72
- }): PositionalSpec<string>;
73
- optionalString(spec: {
74
- brief: string;
75
- placeholder: string;
76
- }): PositionalSpec<string | undefined>;
77
- /**
78
- * Zero or more trailing values; at most one, declared last (order =
79
- * declaration order; keys must not be integer-like).
80
- */
81
- variadic(spec: {
82
- brief: string;
83
- placeholder: string;
84
- }): PositionalSpec<readonly string[]>;
85
- };
86
- /** The parse SPI: a command's argument surface, one property. */
87
- interface ArgsSpec<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>> {
88
- readonly flags?: TFlags;
89
- readonly positionals?: TPositionals;
90
- }
91
- /**
92
- * The normalized argument surface a definition carries: both namespaces
93
- * always present, empty when the command declares none.
94
- */
95
- interface CommandArgs<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>> {
96
- readonly flags: TFlags;
97
- readonly positionals: TPositionals;
98
- }
99
- /**
100
- * What a handler receives: separate namespaces, symmetric access —
101
- * `args.flags.to`, `args.positionals.name`. Declared flag keys are
102
- * camelCase and transliterate to --kebab-case on the CLI.
103
- */
104
- interface Args<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>> {
105
- readonly flags: { readonly [K in keyof TFlags]: TFlags[K] extends FlagSpec<infer T> ? T : never };
106
- readonly positionals: { readonly [K in keyof TPositionals]: TPositionals[K] extends PositionalSpec<infer T> ? T : never };
107
- }
108
- //#endregion
109
- //#region src/config-section.d.ts
110
- /**
111
- * A command family's named slice of prisma.config.ts. The token couples
112
- * the section name, its validated type, and its total validator. The
113
- * validator owns absence: its input is the raw section value, or
114
- * undefined when the config file has no such section. It returns
115
- * findings; it never throws.
116
- */
117
- interface ConfigSection<T> {
118
- readonly name: string;
119
- readonly validate: (raw: unknown | undefined) => SectionValidation<T>;
120
- }
121
- /**
122
- * Diagnostics on an OK validation are warnings: the engine writes them
123
- * to stderr as commentary (log-level filtered, human and json alike);
124
- * they never enter the stream or the envelope.
125
- */
126
- type SectionValidation<T> = {
127
- readonly ok: true;
128
- readonly value: T;
129
- readonly diagnostics: readonly Diagnostic[];
130
- } | {
131
- readonly ok: false;
132
- readonly diagnostics: readonly Diagnostic[];
133
- };
134
- declare function defineConfigSection<T>(spec: {
135
- readonly name: string;
136
- readonly validate: (raw: unknown | undefined) => SectionValidation<T>;
137
- }): ConfigSection<T>;
138
- //#endregion
139
4
  //#region src/management-api.d.ts
5
+ type SdkTokens = NonNullable<Awaited<ReturnType<TokenStorage["getTokens"]>>>;
6
+ type StoredTokens = SdkTokens & {
7
+ /** The explicit OAuth lifetime when the access token has no exp claim. */readonly expiresAt?: Date;
8
+ };
140
9
  /**
141
10
  * The SDK's typed client, re-exported so consumers never import
142
11
  * @prisma/management-api-sdk directly.
143
12
  */
144
13
  type ManagementApiClient$1 = ManagementApiClient;
145
14
  /**
146
- * The SDK's token-storage contract, re-exported for the same reason.
147
- * CredentialManager.activeCredentialStorage returns one; the engine
148
- * forwards it into SDK client config and reads it only to tell a
149
- * credential that could never be renewed from one that could.
15
+ * The SDK's token-storage contract plus the explicit OAuth expiry the
16
+ * credential manager persists for opaque access tokens. The extra data and
17
+ * optional setTokens argument are structurally compatible with the SDK, which
18
+ * ignores expiry and continues to call setTokens with one argument.
150
19
  */
151
- type TokenStorage$1 = TokenStorage;
20
+ type TokenStorage$1 = Omit<TokenStorage, "getTokens" | "setTokens"> & {
21
+ getTokens(): Promise<StoredTokens | null>;
22
+ setTokens(tokens: SdkTokens, expiresAt?: Date): Promise<void>;
23
+ };
152
24
  /**
153
25
  * SDK client construction config, injected by the bin beside the
154
26
  * credential manager. All four fields: the SDK's refreshing fetch
@@ -161,6 +33,28 @@ interface ManagementApiClientConfig {
161
33
  readonly apiBaseUrl: string;
162
34
  readonly authBaseUrl: string;
163
35
  }
36
+ /**
37
+ * The host-side OAuth exchange the engine may request before handing an
38
+ * access-token snapshot to a child. The refresh token crosses only this
39
+ * in-process seam; it is never added to the child's environment.
40
+ *
41
+ * `invalid` is the token endpoint's definitive `invalid_grant` verdict.
42
+ * Transport failures and every other endpoint failure are thrown so the
43
+ * engine can map them to CLI.AUTH_SERVICE_ERROR without exposing endpoint
44
+ * response text.
45
+ */
46
+ type CredentialRefreshResult = {
47
+ readonly kind: "success";
48
+ readonly accessToken: string;
49
+ readonly refreshToken: string; /** Absolute lifetime reported by the OAuth token endpoint. */
50
+ readonly expiresAt: Date;
51
+ } | {
52
+ readonly kind: "invalid";
53
+ };
54
+ type CredentialRefresher = (request: {
55
+ readonly refreshToken: string;
56
+ readonly signal: AbortSignal;
57
+ }) => Promise<CredentialRefreshResult>;
164
58
  //#endregion
165
59
  //#region src/credential-manager.d.ts
166
60
  /** The environment variables that supply a credential to a process: a
@@ -231,6 +125,12 @@ interface ActiveCredential {
231
125
  readonly identity: CredentialIdentity | undefined;
232
126
  readonly origin: CredentialOrigin;
233
127
  }
128
+ interface ActiveAccessTokenOptions {
129
+ /** Refuse or refresh a token with no more than this lifetime left. */
130
+ readonly minimumValidityMs: number;
131
+ readonly now: Date;
132
+ readonly signal: AbortSignal;
133
+ }
234
134
  /**
235
135
  * Manages the credentials this machine holds: the stored per-workspace
236
136
  * sessions, which one is selected, and the credential this process
@@ -290,14 +190,149 @@ interface CredentialManager {
290
190
  /**
291
191
  * ENGINE-FACING. The active credential's ACCESS token, read fresh on
292
192
  * every call, for handing to a child process that authenticates as
293
- * this process does. Never the refresh token: the child gets a
193
+ * this process does. An OAuth pair inside the caller's minimum
194
+ * validity is refreshed under the refresh lock before its access
195
+ * token is returned. Never the refresh token: the child gets a
294
196
  * snapshot it cannot refresh. Null when the material is gone (the
295
- * session ended). Single consumer: ctx.spawn's credential injection
296
- * (credential-manager-design.md §11.5) — the read builds no second
297
- * API client, so the one-client-per-process invariant holds.
197
+ * session ended).
198
+ */
199
+ activeAccessToken(options: ActiveAccessTokenOptions): Promise<string | null>;
200
+ }
201
+ //#endregion
202
+ //#region src/args.d.ts
203
+ /**
204
+ * Single-character alias, enforced at the type level: `Char<'q'>` is
205
+ * 'q'; `Char<'ab'>` is never.
206
+ */
207
+ type Char<S extends string> = S extends `${string}${infer Rest}` ? Rest extends "" ? S : never : never;
208
+ interface FlagSpec<T> {
209
+ /** Phantom type carrier for inference; never present at runtime. */
210
+ readonly __flag?: T;
211
+ }
212
+ /**
213
+ * Command-declared flags. The shared family (--format/--json,
214
+ * --log-level/--verbose, --quiet, --yes, --interactive, --color) is
215
+ * engine-injected and reserved. Flags are optional by default
216
+ * (requiredString is the exception); positionals are required by
217
+ * default (optionalString is the exception).
218
+ */
219
+ declare const flag: {
220
+ string<A extends string = never>(spec: {
221
+ brief: string;
222
+ placeholder?: string;
223
+ alias?: A & Char<A>;
224
+ default?: string;
225
+ }): FlagSpec<string | undefined>;
226
+ requiredString<A extends string = never>(spec: {
227
+ brief: string;
228
+ placeholder?: string;
229
+ alias?: A & Char<A>;
230
+ }): FlagSpec<string>;
231
+ number<A extends string = never>(spec: {
232
+ brief: string;
233
+ placeholder?: string;
234
+ alias?: A & Char<A>;
235
+ default?: number;
236
+ }): FlagSpec<number | undefined>;
237
+ boolean<A extends string = never>(spec: {
238
+ brief: string;
239
+ alias?: A & Char<A>;
240
+ }): FlagSpec<boolean>;
241
+ /**
242
+ * A boolean the user can leave unsaid: `--flag`, `--no-flag`, or
243
+ * neither, which arrives as undefined. Use it when absence means
244
+ * something of its own — "ask me" rather than "no".
245
+ */
246
+ optionalBoolean<A extends string = never>(spec: {
247
+ brief: string;
248
+ alias?: A & Char<A>;
249
+ }): FlagSpec<boolean | undefined>;
250
+ enum<const T extends readonly string[], A extends string = never>(spec: {
251
+ brief: string;
252
+ values: T;
253
+ alias?: A & Char<A>;
254
+ default?: T[number];
255
+ }): FlagSpec<T[number] | undefined>;
256
+ repeated<A extends string = never>(spec: {
257
+ brief: string;
258
+ placeholder?: string;
259
+ alias?: A & Char<A>;
260
+ }): FlagSpec<readonly string[]>;
261
+ };
262
+ interface PositionalSpec<T> {
263
+ /** Phantom type carrier for inference; never present at runtime. */
264
+ readonly __positional?: T;
265
+ }
266
+ declare const positional: {
267
+ string(spec: {
268
+ brief: string;
269
+ placeholder: string;
270
+ }): PositionalSpec<string>;
271
+ optionalString(spec: {
272
+ brief: string;
273
+ placeholder: string;
274
+ }): PositionalSpec<string | undefined>;
275
+ /**
276
+ * Zero or more trailing values; at most one, declared last (order =
277
+ * declaration order; keys must not be integer-like).
298
278
  */
299
- activeAccessToken(): Promise<string | null>;
279
+ variadic(spec: {
280
+ brief: string;
281
+ placeholder: string;
282
+ }): PositionalSpec<readonly string[]>;
283
+ };
284
+ /** The parse SPI: a command's argument surface, one property. */
285
+ interface ArgsSpec<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>> {
286
+ readonly flags?: TFlags;
287
+ readonly positionals?: TPositionals;
288
+ }
289
+ /**
290
+ * The normalized argument surface a definition carries: both namespaces
291
+ * always present, empty when the command declares none.
292
+ */
293
+ interface CommandArgs<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>> {
294
+ readonly flags: TFlags;
295
+ readonly positionals: TPositionals;
296
+ }
297
+ /**
298
+ * What a handler receives: separate namespaces, symmetric access —
299
+ * `args.flags.to`, `args.positionals.name`. Declared flag keys are
300
+ * camelCase and transliterate to --kebab-case on the CLI.
301
+ */
302
+ interface Args<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>> {
303
+ readonly flags: { readonly [K in keyof TFlags]: TFlags[K] extends FlagSpec<infer T> ? T : never };
304
+ readonly positionals: { readonly [K in keyof TPositionals]: TPositionals[K] extends PositionalSpec<infer T> ? T : never };
305
+ }
306
+ //#endregion
307
+ //#region src/config-section.d.ts
308
+ /**
309
+ * A command family's named slice of prisma.config.ts. The token couples
310
+ * the section name, its validated type, and its total validator. The
311
+ * validator owns absence: its input is the raw section value, or
312
+ * undefined when the config file has no such section. It returns
313
+ * findings; it never throws.
314
+ */
315
+ interface ConfigSection<T> {
316
+ readonly name: string;
317
+ readonly validate: (raw: unknown | undefined) => SectionValidation<T>;
300
318
  }
319
+ /**
320
+ * Diagnostics on an OK validation are warnings: the engine writes them
321
+ * to stderr as commentary (log-level filtered, human and json alike);
322
+ * they never enter the stream or the envelope.
323
+ */
324
+ type SectionValidation<T> = {
325
+ readonly ok: true;
326
+ readonly value: T;
327
+ readonly diagnostics: readonly Diagnostic[];
328
+ } | {
329
+ readonly ok: false;
330
+ readonly diagnostics: readonly Diagnostic[];
331
+ };
332
+ declare function defineConfigSection<T>(spec: {
333
+ readonly name: string;
334
+ readonly validate: (raw: unknown | undefined) => SectionValidation<T>;
335
+ }): ConfigSection<T>;
301
336
  //#endregion
302
337
  //#region src/events.d.ts
303
338
  /**
@@ -606,6 +641,14 @@ interface SpawnRequest {
606
641
  readonly args: readonly string[];
607
642
  readonly cwd: string;
608
643
  readonly env: Readonly<Record<string, string | undefined>>;
644
+ /** "inherit" hands the terminal over unchanged. "diagnostic" MUST
645
+ * route the child's stdout and stderr away from this process's
646
+ * stdout (to the host's diagnostic stream): the engine emits framed
647
+ * NDJSON on stdout in that mode and cannot detect an adapter that
648
+ * ignores this field — inherited child stdout would silently corrupt
649
+ * the stream. Adapters written before this field existed must be
650
+ * updated. */
651
+ readonly output: "inherit" | "diagnostic";
609
652
  }
610
653
  /** How a child ended. A signal-killed child carries `signal` and a null
611
654
  * `exitCode`, and is an abort rather than a failure: exitWithChildStatus
@@ -623,10 +666,11 @@ interface SpawnedChild {
623
666
  readonly kill: (signal: "SIGTERM" | "SIGKILL") => void;
624
667
  }
625
668
  /**
626
- * The Runtime seam. The adapter starts the child with INHERITED stdio,
627
- * in the caller's own process group (POSIX) / console (Windows) — no
628
- * `detached`, no new console — so the terminal delivers Ctrl-C to the
629
- * child natively.
669
+ * The Runtime seam. In human mode the adapter starts the child with
670
+ * inherited stdio, in the caller's own process group (POSIX) / console
671
+ * (Windows). In structured mode stdin remains inherited while stdout and
672
+ * stderr are routed to the host's diagnostic stream, preserving framed
673
+ * stdout. Neither mode detaches or opens a new console.
630
674
  */
631
675
  type SpawnChild = (request: SpawnRequest) => SpawnedChild;
632
676
  /** What a handler passes to ctx.spawn. */
@@ -1218,9 +1262,10 @@ interface NeedsSpec<TConfig> {
1218
1262
  * Fail early with the sign-in error when unauthenticated. The
1219
1263
  * `"child"` form (S3) additionally makes the engine compose the
1220
1264
  * active credential into every child environment
1221
- * (PRISMA_SERVICE_TOKEN, PRISMA_WORKSPACE_ID) and refuse the run
1222
- * before the handler when that credential expires too soon to hand
1223
- * out — a child cannot refresh the snapshot it is given. It
1265
+ * (PRISMA_SERVICE_TOKEN, PRISMA_WORKSPACE_ID). Before the handler it
1266
+ * refreshes a stored OAuth session that expires too soon, or refuses
1267
+ * an unrefreshable credential — a child cannot refresh the snapshot
1268
+ * it is given. It
1224
1269
  * requires `maySpawn` (construction error otherwise) and entails
1225
1270
  * the plain credentials need.
1226
1271
  */
@@ -1253,10 +1298,9 @@ interface CommandNeeds<TConfig> {
1253
1298
  * The terminal-handoff declaration, normalized onto every definition
1254
1299
  * (server commands normalize to false: they own stdio already).
1255
1300
  *
1256
- * `maySpawn` unlocks ctx.spawn and makes the command reject `--json`
1257
- * as soon as the command is known, before anything runs: output
1258
- * delegated to a child process cannot be framed. Handing credentials
1259
- * to the child is a precondition, declared as
1301
+ * `maySpawn` unlocks ctx.spawn. In human mode the child inherits the
1302
+ * terminal; in json mode its output is routed to diagnostics so stdout
1303
+ * remains framed. Handing credentials to the child is a precondition, declared as
1260
1304
  * `needs: { credentials: "child" }`.
1261
1305
  */
1262
1306
  interface SpawnDeclarations {
@@ -1320,10 +1364,9 @@ declare function defineCommand<TFlags extends Record<string, FlagSpec<unknown>>
1320
1364
  * speaks entirely through events, returns Result<void>. No
1321
1365
  * presentation, no exit-code set.
1322
1366
  *
1323
- * A session supports json mode — the event stream is its json surface —
1324
- * UNLESS it declares `maySpawn`, in which case it rejects --json as soon
1325
- * as the command is known, before anything runs (S3): output delegated
1326
- * to a child process cannot be framed. A session that returns
1367
+ * A session supports json mode — the event stream is its json surface.
1368
+ * When it declares `maySpawn`, child output is routed to diagnostics while
1369
+ * the engine retains ownership of structured stdout. A session that returns
1327
1370
  * ok(undefined) exits 0 — or 130/143 when a signal ended the run, which
1328
1371
  * the engine settles from its own record of that signal, not from
1329
1372
  * anything the handler returns; one that returns
@@ -1501,4 +1544,4 @@ interface TelemetryDeclaration {
1501
1544
  readonly docsUrl: string;
1502
1545
  }
1503
1546
  //#endregion
1504
- export { Outcome as $, InputStream as A, CommandArgs as At, ExitWithChildStatusOptions as B, BrowserWaitRequest as C, TokenStorage$1 as Ct, PromptSurface as D, Args as Dt, OpenUrlRequest as E, defineConfigSection as Et, TelemetryPayload as F, exitWithChildStatus as G, SpawnOptions as H, EngineCommandSnapshot as I, PackageManagerRunResult as J, PackageManagerId as K, RunSummary as L, OutputStream as M, PositionalSpec as Mt, PRISMA_CONFIG_VERSION as N, flag as Nt, Host as O, ArgsSpec as Ot, Runtime as P, positional as Pt, Format as Q, ChildResult as R, defineSessionCommand as S, ManagementApiClientConfig as St, OpenUrlOutcome as T, SectionValidation as Tt, SpawnRequest as U, SpawnChild as V, SpawnedChild as W, PackageOperations as X, PackageManagerRunner as Y, Block as Z, ServerCommandDefinition as _, CredentialOrigin as _t, RedirectSpec as a, Text as at, defineCommand as b, StoredSessions as bt, CommandDefinition as c, Ui as ct, CommandNeeds as d, StreamEvent as dt, PRESENTED as et, CompletedEnvelope as f, StreamMeta as ft, NeedsSpec as g, CredentialManager as gt, HelpSpec as h, CredentialIdentity as ht, MountedTree as i, Status as it, LoadedConfig as j, FlagSpec as jt, HostProcess as k, Char as kt, CommandHandler as l, EngineEvent as lt, Handler as m, Credential as mt, CommandFamily as n, PresentedResult as nt, defineCommandFamily as o, Tone as ot, ErroredEnvelope as p, ActiveCredential as pt, PackageManagerRunRequest as q, CommandRedirect as r, Span as rt, AnyCommand as s, TreeNode as st, TelemetryDeclaration as t, Presentations as tt, CommandHelp as u, Severity as ut, SessionCommandDefinition as v, SERVICE_TOKEN_ENV_VAR as vt, CommandContext as w, ConfigSection as wt, defineServerCommand as x, ManagementApiClient$1 as xt, SpawnDeclarations as y, Session as yt, ChildStatusSettlement as z };
1547
+ export { Outcome as $, InputStream as A, SERVICE_TOKEN_ENV_VAR as At, ExitWithChildStatusOptions as B, BrowserWaitRequest as C, positional as Ct, PromptSurface as D, CredentialIdentity as Dt, OpenUrlRequest as E, Credential as Et, TelemetryPayload as F, ManagementApiClient$1 as Ft, exitWithChildStatus as G, SpawnOptions as H, EngineCommandSnapshot as I, ManagementApiClientConfig as It, PackageManagerRunResult as J, PackageManagerId as K, RunSummary as L, TokenStorage$1 as Lt, OutputStream as M, StoredSessions as Mt, PRISMA_CONFIG_VERSION as N, CredentialRefreshResult as Nt, Host as O, CredentialManager as Ot, Runtime as P, CredentialRefresher as Pt, Format as Q, ChildResult as R, defineSessionCommand as S, flag as St, OpenUrlOutcome as T, ActiveCredential as Tt, SpawnRequest as U, SpawnChild as V, SpawnedChild as W, PackageOperations as X, PackageManagerRunner as Y, Block as Z, ServerCommandDefinition as _, ArgsSpec as _t, RedirectSpec as a, Text as at, defineCommand as b, FlagSpec as bt, CommandDefinition as c, Ui as ct, CommandNeeds as d, StreamEvent as dt, PRESENTED as et, CompletedEnvelope as f, StreamMeta as ft, NeedsSpec as g, Args as gt, HelpSpec as h, defineConfigSection as ht, MountedTree as i, Status as it, LoadedConfig as j, Session as jt, HostProcess as k, CredentialOrigin as kt, CommandHandler as l, EngineEvent as lt, Handler as m, SectionValidation as mt, CommandFamily as n, PresentedResult as nt, defineCommandFamily as o, Tone as ot, ErroredEnvelope as p, ConfigSection as pt, PackageManagerRunRequest as q, CommandRedirect as r, Span as rt, AnyCommand as s, TreeNode as st, TelemetryDeclaration as t, Presentations as tt, CommandHelp as u, Severity as ut, SessionCommandDefinition as v, Char as vt, CommandContext as w, ActiveAccessTokenOptions as wt, defineServerCommand as x, PositionalSpec as xt, SpawnDeclarations as y, CommandArgs as yt, ChildStatusSettlement as z };
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Ct as TokenStorage, F as TelemetryPayload, K as PackageManagerId, L as RunSummary, O as Host, P as Runtime, R as ChildResult, St as ManagementApiClientConfig, U as SpawnRequest, V as SpawnChild, Y as PackageManagerRunner, bt as StoredSessions, dt as StreamEvent, gt as CredentialManager, i as MountedTree, lt as EngineEvent, mt as Credential, n as CommandFamily, nt as PresentedResult, pt as ActiveCredential, t as TelemetryDeclaration, xt as ManagementApiClient, yt as Session } from "./report-DID_e0si.js";
1
+ import { Et as Credential, F as TelemetryPayload, Ft as ManagementApiClient, It as ManagementApiClientConfig, K as PackageManagerId, L as RunSummary, Lt as TokenStorage, Mt as StoredSessions, O as Host, Ot as CredentialManager, P as Runtime, Pt as CredentialRefresher, R as ChildResult, Tt as ActiveCredential, U as SpawnRequest, V as SpawnChild, Y as PackageManagerRunner, dt as StreamEvent, i as MountedTree, jt as Session, lt as EngineEvent, n as CommandFamily, nt as PresentedResult, t as TelemetryDeclaration, wt as ActiveAccessTokenOptions } from "./report-BpE5F1IH.js";
2
2
 
3
3
  //#region src/in-memory-credential-manager.d.ts
4
4
  /** A stored session with its credential material — what the manager
@@ -21,6 +21,8 @@ interface InMemoryCredentialManagerSeed {
21
21
  /** The credential PRISMA_SERVICE_TOKEN supplies. Its token may carry
22
22
  * no `workspace_id` claim, and it may carry a refresh token. */
23
23
  readonly environmentCredential?: Credential;
24
+ /** OAuth exchange used when delegated credentials need rotation. */
25
+ readonly refreshCredential?: CredentialRefresher;
24
26
  }
25
27
  /** The whole stored state, readable back after a run. */
26
28
  interface InMemoryCredentialManagerState {
@@ -44,6 +46,7 @@ declare class InMemoryCredentialManager implements CredentialManager {
44
46
  private storedSessions;
45
47
  private selection;
46
48
  private readonly environmentCredential;
49
+ private readonly refreshCredential;
47
50
  private pin;
48
51
  private activeStorage;
49
52
  constructor(seed: InMemoryCredentialManagerSeed);
@@ -61,11 +64,11 @@ declare class InMemoryCredentialManager implements CredentialManager {
61
64
  endSession(workspaceId: string): Promise<void>;
62
65
  endAllSessions(): Promise<void>;
63
66
  activeCredentialStorage(): Promise<TokenStorage>;
64
- /** The spawn path's read: the active credential's access token,
67
+ /** The delegated path's read: the active credential's access token,
65
68
  * fresh on every call, never the refresh token. Null when there is
66
69
  * no active credential to read — storage exists only once
67
70
  * activeCredential() has returned non-null. */
68
- activeAccessToken(): Promise<string | null>;
71
+ activeAccessToken(options: ActiveAccessTokenOptions): Promise<string | null>;
69
72
  private buildActiveStorage;
70
73
  /** The file-backed storage's analogue: the record is read afresh on
71
74
  * every call, never snapshotted. */
@@ -94,6 +97,7 @@ interface SpawnRecord {
94
97
  readonly command: string;
95
98
  readonly args: readonly string[];
96
99
  readonly cwd: string;
100
+ readonly output: SpawnRequest["output"];
97
101
  /** Environment KEYS only. Values are never recorded: a fixture file
98
102
  * must not be able to carry token material. */
99
103
  readonly envKeys: readonly string[];
@@ -191,7 +195,8 @@ declare function createTestCli(spec: {
191
195
  readonly environmentCredential?: Credential;
192
196
  /** The SDK client construction config; defaults point every
193
197
  * endpoint at test.invalid hosts. */
194
- readonly managementApiClientConfig?: ManagementApiClientConfig;
198
+ readonly managementApiClientConfig?: ManagementApiClientConfig; /** OAuth exchange behind delegated-credential preparation. */
199
+ readonly refreshCredential?: CredentialRefresher;
195
200
  /** baseUrl defaults to "https://test.invalid"; when `client` is
196
201
  * supplied, ctx.api IS that object. */
197
202
  readonly managementApi?: {