@vite-hub/env 0.0.4 → 0.3.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 (57) hide show
  1. package/README.md +288 -23
  2. package/dist/access-B8lSDip4.js +54 -0
  3. package/dist/bridge-Cs9YfQWk.d.ts +447 -0
  4. package/dist/bridge-error-BhJ77age.js +66 -0
  5. package/dist/bridge.d.ts +2 -0
  6. package/dist/bridge.js +354 -0
  7. package/dist/cli-BPp7rdcA.d.ts +159 -0
  8. package/dist/cli-DLpY0QAo.js +669 -0
  9. package/dist/cli.d.ts +41 -0
  10. package/dist/cli.js +2 -0
  11. package/dist/database.d.ts +47 -0
  12. package/dist/database.js +274 -0
  13. package/dist/declarations-C5XR3aKw.d.ts +58 -0
  14. package/dist/error-diagnostics-B8RFjQ1V.js +56 -0
  15. package/dist/index.d.ts +146 -11
  16. package/dist/index.js +240 -7
  17. package/dist/internal/agent.d.ts +5 -0
  18. package/dist/internal/agent.js +22 -0
  19. package/dist/internal/connections.d.ts +18 -0
  20. package/dist/internal/connections.js +31 -0
  21. package/dist/internal/server.d.ts +3 -0
  22. package/dist/internal/server.js +2 -0
  23. package/dist/object-_dlsZ4lP.js +276 -0
  24. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  25. package/dist/operations-X1w--wds.js +30 -0
  26. package/dist/operations.d.ts +37 -0
  27. package/dist/operations.js +833 -0
  28. package/dist/runtime/public-env.d.ts +5 -0
  29. package/dist/runtime/public-env.js +8 -0
  30. package/dist/runtime/server-env.d.ts +22 -0
  31. package/dist/runtime/server-env.js +35 -0
  32. package/dist/schema-DMZ1_yhY.js +360 -0
  33. package/dist/seal.d.ts +17 -0
  34. package/dist/seal.js +52 -0
  35. package/dist/{secret.js → secret-DJd-fy5T.js} +1 -1
  36. package/dist/server-ChNL_Xc3.js +1279 -0
  37. package/dist/server-Dd8bjIKd.d.ts +145 -0
  38. package/dist/server.d.ts +3 -8
  39. package/dist/server.js +2 -3
  40. package/dist/virtual-module.d.ts +9 -5
  41. package/dist/virtual.d.ts +1 -1
  42. package/dist/vite.d.ts +79 -21
  43. package/dist/vite.js +1095 -339
  44. package/package.json +81 -28
  45. package/dist/declarations-CoMmvRqH.js +0 -159
  46. package/dist/declarations-U6P3rvxC.d.ts +0 -24
  47. package/dist/errors-C4Xcs6Fi.js +0 -121
  48. package/dist/presets.d.ts +0 -11
  49. package/dist/presets.js +0 -25
  50. package/dist/provider.d.ts +0 -6
  51. package/dist/provider.js +0 -7
  52. package/dist/schema.d.ts +0 -16
  53. package/dist/schema.js +0 -37
  54. package/dist/secret-C2191nAa.d.ts +0 -11
  55. package/dist/secret.d.ts +0 -2
  56. package/dist/server-C16sFc1E.js +0 -303
  57. package/dist/types-CsB6DTGE.d.ts +0 -190
@@ -0,0 +1,447 @@
1
+ //#region src/internal/access.d.ts
2
+ /** Marks the type of contexts that Env creates. The bridge trusts only the `envAccess` grant registry, not this marker. */
3
+ declare const envAccessGrant: unique symbol;
4
+ interface EnvAttribution {
5
+ traceId?: string;
6
+ invocationId?: string;
7
+ }
8
+ //#endregion
9
+ //#region src/secret.d.ts
10
+ declare class SecretEnv<T = string> {
11
+ #private;
12
+ constructor(value: T);
13
+ unseal(): T;
14
+ toString(): string;
15
+ toJSON(): string;
16
+ [Symbol.toPrimitive](): string;
17
+ }
18
+ //#endregion
19
+ //#region src/http.d.ts
20
+ interface EnvManagement {
21
+ bridge: EnvBridge;
22
+ authenticate(request: Request): EnvAccessContext | null | Promise<EnvAccessContext | null>;
23
+ }
24
+ /**
25
+ * Options that server code passes to one management request. A request never sets them.
26
+ * `allowedOrigin` is a browser origin that the caller already accepted for this request, such as the Console with a
27
+ * verified bearer token from `console.origins`. The bridge still authenticates the request and checks permissions.
28
+ */
29
+ interface EnvBridgeRequestOptions {
30
+ allowedOrigin?: string;
31
+ }
32
+ type EnvManagementResolver = (path: string) => {
33
+ key: string;
34
+ management: EnvManagement;
35
+ } | undefined;
36
+ /** Mount only on a server route. resolve selects declared credentials, never arbitrary store keys. */
37
+ declare function createEnvBridgeHandler(resolve: EnvManagementResolver): (request: Request, options?: EnvBridgeRequestOptions) => Promise<Response>;
38
+ //#endregion
39
+ //#region src/types.d.ts
40
+ type EnvDiagnostics = "off" | "summary" | "trace";
41
+ type EnvMode = "build" | "runtime";
42
+ /** Options of `vitehub({ env })` and `hubEnv()`: the Env declarations and how ViteHub resolves them. */
43
+ interface EnvOptions extends EnvDeclarations {
44
+ diagnostics?: EnvDiagnostics;
45
+ /**
46
+ * Prefix of canonical variable names. Every env-backed declaration first reads the prefix plus its
47
+ * path in upper snake case, then its conventional names. Defaults to `"VITEHUB_"`. `false` disables it.
48
+ */
49
+ prefix?: string | false;
50
+ projectRoot?: string;
51
+ providers?: Record<string, string>;
52
+ runtimeImports?: EnvRuntimeImportSpecifiers;
53
+ }
54
+ interface EnvRuntimeImportSpecifiers {
55
+ secret?: string;
56
+ server?: string;
57
+ }
58
+ interface EnvSourceContext {
59
+ build: {
60
+ timestamp: () => string;
61
+ };
62
+ env: Record<string, string | undefined>;
63
+ git: {
64
+ /** Reads `GIT_BRANCH`, then `GITHUB_HEAD_REF`, then `GITHUB_REF_NAME` on a GitHub branch ref, then local Git. */
65
+ branch: () => Promise<string>;
66
+ /** Reads `GIT_SHA`, then `GITHUB_SHA`, then local Git. */
67
+ commit: (options?: {
68
+ short?: boolean;
69
+ }) => Promise<string>;
70
+ /** Reads `GIT_TAG`, then `GITHUB_REF_NAME` on a GitHub tag ref, then local Git. */
71
+ tag: () => Promise<string | undefined>;
72
+ };
73
+ mode: EnvMode;
74
+ packageJson: () => Promise<Record<string, unknown>>;
75
+ rootDir: string;
76
+ }
77
+ type EnvSourceResolver = (context: EnvSourceContext) => unknown | Promise<unknown>;
78
+ type EnvSource = {
79
+ kind: "custom";
80
+ label: string;
81
+ resolver: EnvSourceResolver;
82
+ serializable: false;
83
+ } | {
84
+ kind: "env";
85
+ label: string;
86
+ name: string;
87
+ names?: string[];
88
+ /** The canonical name, `VITEHUB_<PATH>`, which the ordered names read first. */
89
+ canonical?: string | false;
90
+ serializable: true;
91
+ } | {
92
+ kind: "git-branch";
93
+ label: "git:branch";
94
+ serializable: true;
95
+ } | {
96
+ kind: "git-commit";
97
+ label: "git:commit";
98
+ serializable: true;
99
+ short?: boolean;
100
+ } | {
101
+ kind: "git-tag";
102
+ label: "git:tag";
103
+ serializable: true;
104
+ } | {
105
+ kind: "build-timestamp";
106
+ label: "build:timestamp";
107
+ serializable: true;
108
+ } | {
109
+ kind: "package-json";
110
+ label: string;
111
+ path: string;
112
+ serializable: true;
113
+ } | {
114
+ key: string;
115
+ kind: "provider";
116
+ label: "provider";
117
+ provider: string;
118
+ serializable: true;
119
+ };
120
+ interface EnvVariableDeclaration {
121
+ default?: unknown;
122
+ kind: "env-variable";
123
+ mode: EnvMode;
124
+ required: boolean;
125
+ schema: unknown;
126
+ secret: boolean;
127
+ source?: EnvSource;
128
+ type?: string;
129
+ }
130
+ interface EnvVariableBaseOptions {
131
+ mode?: EnvMode;
132
+ schema?: unknown;
133
+ secret?: boolean;
134
+ source?: EnvSource | EnvSourceResolver;
135
+ type?: string;
136
+ }
137
+ /**
138
+ * A value is required by default. `optional: true` lets it be missing.
139
+ * A `default` makes the value always present, so it cannot be combined with `optional: true`.
140
+ */
141
+ type EnvRequirednessOptions<TValue> = {
142
+ default?: TValue;
143
+ optional?: false;
144
+ } | {
145
+ default?: never;
146
+ optional: true;
147
+ };
148
+ type EnvVariableOptions = EnvVariableBaseOptions & EnvRequirednessOptions<unknown>;
149
+ /** Options for `env.boolean()`, `env.number()`, `env.enum()`, `env.list()`, and `env.json()`. The helper owns the parser and type. */
150
+ type EnvTypedVariableOptions<TValue> = Omit<EnvVariableBaseOptions, "schema" | "type"> & EnvRequirednessOptions<TValue>;
151
+ /** Serializable parser for one Server Env value. Host and provider values are strings before parsing. */
152
+ type EnvValueSchema = {
153
+ kind: "boolean";
154
+ } | {
155
+ kind: "enum";
156
+ values: readonly string[];
157
+ } | {
158
+ kind: "number";
159
+ min?: number;
160
+ max?: number;
161
+ isInt?: boolean;
162
+ decimal?: boolean;
163
+ } | {
164
+ kind: "string";
165
+ minLength?: number;
166
+ maxLength?: number;
167
+ } | {
168
+ kind: "url";
169
+ } | {
170
+ kind: "array";
171
+ items?: EnvValueSchema;
172
+ } | {
173
+ kind: "object";
174
+ properties?: Record<string, EnvValueSchema>;
175
+ } | {
176
+ kind: "list";
177
+ items?: EnvValueSchema;
178
+ } | {
179
+ kind: "json";
180
+ };
181
+ /**
182
+ * A Standard Schema that the server build imports from a module. Server Env runs it on the raw value when it resolves,
183
+ * so refinements and transforms work. Create it with `env.schemaFrom()`.
184
+ */
185
+ interface EnvSchemaModuleReference {
186
+ kind: "schema-module";
187
+ /** Module specifier. A relative path resolves from the project root, like `hubEnv({ providers })`. */
188
+ module: string;
189
+ /** Name of the export that holds the schema. */
190
+ export: string;
191
+ /** `json` parses a string value as JSON before the schema runs. `env.json()` sets it. */
192
+ input?: "json";
193
+ }
194
+ type EnvBuildStaticValue = null | string | number | boolean | EnvBuildStaticValue[];
195
+ type EnvBuildConfigValue = EnvBuildConfigOptions | EnvBuildStaticValue | EnvVariableDeclaration;
196
+ interface EnvBuildConfigOptions {
197
+ [key: string]: EnvBuildConfigValue;
198
+ }
199
+ /** Declarations of Public Env, Server Env, and build-time replacements. */
200
+ interface EnvDeclarations {
201
+ /** Values that replace identifiers at build time. */
202
+ define?: Record<string, EnvBuildConfigValue>;
203
+ /** Public Env, resolved at build time and readable in browser code. Each declaration uses `mode: "build"`. */
204
+ public?: Record<string, EnvVariableDeclaration>;
205
+ /** Server Env, resolved at runtime and readable only in server code. */
206
+ server?: EnvRuntimeConfigOptions;
207
+ }
208
+ type EnvRuntimeStaticValue = null | string | number | boolean | EnvRuntimeStaticValue[];
209
+ type EnvRuntimeConfigValue = EnvRuntimeConfigOptions | EnvRuntimeStaticValue | EnvVariableDeclaration;
210
+ interface EnvRuntimeConfigOptions {
211
+ [key: string]: EnvRuntimeConfigValue;
212
+ }
213
+ interface EnvDiagnosticEntry {
214
+ exposed: string;
215
+ key: string;
216
+ masked: boolean;
217
+ mode: EnvMode;
218
+ source: string;
219
+ status: "defaulted" | "missing" | "valid";
220
+ timing: string;
221
+ type?: string;
222
+ }
223
+ interface EnvRegistryEntry {
224
+ default?: unknown;
225
+ required: boolean;
226
+ schema?: EnvValueSchema;
227
+ schemaModule?: EnvSchemaModuleReference;
228
+ secret: boolean;
229
+ source: Extract<EnvSource, {
230
+ kind: "env" | "provider";
231
+ }>;
232
+ }
233
+ interface EnvRuntimeLiteralEntry {
234
+ kind: "literal";
235
+ value: EnvRuntimeStaticValue;
236
+ }
237
+ type EnvRuntimeRegistryValue = EnvRegistryEntry | EnvRuntimeLiteralEntry | EnvRuntimeRegistry;
238
+ declare const serverEnvType: unique symbol;
239
+ interface EnvRuntimeRegistry<TServerEnv extends Record<string, unknown> = Record<string, unknown>> {
240
+ [key: string]: EnvRuntimeRegistryValue;
241
+ readonly [serverEnvType]?: (value: TServerEnv) => void;
242
+ }
243
+ /** Server Env. ViteHub generates its fields from the Env declarations into `.vitehub/types/`. */
244
+ interface ServerEnv {}
245
+ /** Public Env. ViteHub generates its fields from the Env declarations into `.vitehub/types/`. */
246
+ interface PublicEnv {}
247
+ type ReadonlyServerEnv = DeepReadonly<ServerEnv>;
248
+ interface EnvProviderContext<TEnv extends Record<string, unknown> = Record<string, unknown>> {
249
+ env: DeepReadonly<TEnv>;
250
+ access?: EnvAccessContext;
251
+ signal?: AbortSignal;
252
+ }
253
+ type EnvProviderValues = Readonly<Record<string, string | undefined>>;
254
+ interface EnvProvider<TEnv extends Record<string, unknown> = Record<string, unknown>> {
255
+ management?: EnvManagement;
256
+ read(input: EnvProviderContext<TEnv> & {
257
+ keys: readonly string[];
258
+ }): EnvProviderValues | Promise<EnvProviderValues>;
259
+ }
260
+ type EnvProviders = Record<string, EnvProvider>;
261
+ interface LoadServerEnvOptions {
262
+ access?: EnvAccessContext;
263
+ providers?: EnvProviders;
264
+ signal?: AbortSignal;
265
+ }
266
+ type DeepReadonly<T> = T extends SecretEnv<unknown> ? T : T extends ((...args: infer TArguments) => infer TResult) ? (...args: TArguments) => TResult : T extends object ? { readonly [TKey in keyof T]: DeepReadonly<T[TKey]>; } : T;
267
+ type ServerEnvInspectionStatus = "available" | "defaulted" | "error" | "invalid" | "missing";
268
+ interface ServerEnvInspectionEntry {
269
+ /** The declaration is secret. Inspection never returns values. */
270
+ masked: boolean;
271
+ /** The host variable names of an env declaration, in read order. See `ServerEnvDescriptionEntry.names`. */
272
+ names?: readonly string[];
273
+ /** The host variable name that supplied the value, one of `names`. Omitted when no name is set. */
274
+ name?: string;
275
+ path?: string;
276
+ /** Provider alias for provider-backed declarations. */
277
+ provider?: string;
278
+ required: boolean;
279
+ source: "env" | "literal" | "provider";
280
+ status: ServerEnvInspectionStatus;
281
+ /** Which kind of variable name supplied an env value: the canonical `VITEHUB_<PATH>` name, or a conventional name. */
282
+ via?: "canonical" | "conventional";
283
+ /** The canonical name and a conventional name are both set to different values. The canonical name wins. */
284
+ conflict?: true;
285
+ }
286
+ interface ServerEnvDescriptionEntry {
287
+ path?: string;
288
+ /**
289
+ * The host variable names of an env declaration, in read order: the canonical name such as `VITEHUB_CLIPROXY_API_KEY`
290
+ * first, unless `canonical: false` or `prefix: false` disables it, then the `env.source()` names or the unprefixed path
291
+ * name. The first name that is set supplies the value. Omitted for literal and provider declarations.
292
+ */
293
+ names?: readonly string[];
294
+ source: "env" | "literal" | "provider";
295
+ provider?: string;
296
+ secret: boolean;
297
+ required: boolean;
298
+ hasDefault: boolean;
299
+ /** TypeScript type of the parsed value, for example `boolean` or `"draft" | "send"`. Omitted for literals. */
300
+ type?: string;
301
+ }
302
+ interface ServerEnvDescription {
303
+ entries: readonly ServerEnvDescriptionEntry[];
304
+ }
305
+ interface ServerEnvInspection {
306
+ entries: readonly ServerEnvInspectionEntry[];
307
+ }
308
+ //#endregion
309
+ //#region src/auth.d.ts
310
+ interface EnvHumanSession {
311
+ user: {
312
+ id: string;
313
+ };
314
+ }
315
+ interface EnvAgentSession {
316
+ agent: {
317
+ id: string;
318
+ };
319
+ }
320
+ type EnvAgentScope = EnvAccessScope;
321
+ interface EnvAuthenticatorOptions<Human extends EnvHumanSession, Agent extends EnvAgentSession> {
322
+ /** Pass Better Auth's auth.api.getSession, preserving the incoming headers. */
323
+ getSession(input: {
324
+ headers: Headers;
325
+ }): Promise<Human | null>;
326
+ /** Application policy; authentication alone never grants administrator access. */
327
+ isAdmin(session: Human): boolean | Promise<boolean>;
328
+ agents?: {
329
+ /** Must verify the credential, e.g. auth.api.getAgentSession from Agent Auth. */
330
+ getSession(input: {
331
+ headers: Headers;
332
+ }): Promise<Agent | null>;
333
+ /** Map verified capability grants AND their constraints to exact store keys. */
334
+ scope(session: Agent): EnvAgentScope | null | Promise<EnvAgentScope | null>;
335
+ };
336
+ }
337
+ /** Authenticate management requests without coupling Env to a particular Better Auth plugin version. */
338
+ declare function createEnvAuthenticator<Human extends EnvHumanSession, Agent extends EnvAgentSession = EnvAgentSession>(options: EnvAuthenticatorOptions<Human, Agent>): (request: Request) => Promise<EnvAccessContext | null>;
339
+ //#endregion
340
+ //#region src/bridge.d.ts
341
+ type EnvPermission = "inspect" | "preview" | "replace" | "use";
342
+ interface EnvActor {
343
+ id: string;
344
+ kind: "user" | "agent" | "service";
345
+ }
346
+ /** A ceiling over durable grants, from a verified Agent token. */
347
+ type EnvAccessScope = readonly {
348
+ readonly key: string;
349
+ readonly permissions: readonly EnvPermission[];
350
+ }[];
351
+ /**
352
+ * A frozen context that only Env creates. Use the type in application code, but get the value from
353
+ * `createEnvAuthenticator()`, the bridge runtime, or a ViteHub integration. Keep it in trusted request code.
354
+ */
355
+ interface EnvAccessContext {
356
+ readonly [envAccessGrant]: true;
357
+ readonly actor: Readonly<EnvActor>;
358
+ /** Only `createEnvAuthenticator()` creates an administrator context. */
359
+ readonly admin?: true;
360
+ /** Optional credential/permission ceiling from a verified agent token. */
361
+ readonly scope?: EnvAccessScope;
362
+ readonly traceId?: string;
363
+ readonly invocationId?: string;
364
+ }
365
+ interface EnvGrant {
366
+ actor: EnvActor;
367
+ key: string;
368
+ permissions: readonly EnvPermission[];
369
+ }
370
+ interface EnvSecretMetadata {
371
+ revision: string;
372
+ updatedAt: string;
373
+ preview?: string;
374
+ }
375
+ interface EnvReplacement extends EnvSecretMetadata {
376
+ activation: "next-resolution" | "restart" | "deploy";
377
+ }
378
+ interface EnvSecretStore {
379
+ inspect(key: string): Promise<EnvSecretMetadata | undefined>;
380
+ read(key: string): Promise<{
381
+ value: string;
382
+ revision?: string;
383
+ } | undefined>;
384
+ replace(input: {
385
+ key: string;
386
+ value: string;
387
+ expectedRevision: string | null;
388
+ }): Promise<EnvReplacement>;
389
+ }
390
+ interface EnvActivity {
391
+ id: string;
392
+ operationId: string;
393
+ timestamp: string;
394
+ actor: EnvActor;
395
+ key: string;
396
+ /** `remove`: a store deleted the key, such as the env values of a Console. The bridge never writes it. */
397
+ action: "inspect" | "preview" | "replace" | "remove" | "resolve" | "use" | "grant" | "revoke";
398
+ outcome: "started" | "succeeded" | "failed" | "denied";
399
+ revision?: string;
400
+ operation?: string;
401
+ target?: EnvActor;
402
+ permissions?: readonly EnvPermission[];
403
+ traceId?: string;
404
+ invocationId?: string;
405
+ }
406
+ interface EnvAccessStore {
407
+ append(event: EnvActivity): Promise<void>;
408
+ activity(input: {
409
+ key: string;
410
+ before?: string;
411
+ limit: number;
412
+ }): Promise<readonly EnvActivity[]>;
413
+ grants(key: string): Promise<readonly EnvGrant[]>;
414
+ setGrant(grant: EnvGrant): Promise<void>;
415
+ revokeGrant(actor: EnvActor, key: string): Promise<void>;
416
+ }
417
+ interface EnvBridgeOptions {
418
+ secrets: EnvSecretStore;
419
+ access: EnvAccessStore;
420
+ /** The identity of this runtime. Reads without an explicit access context get only its durable grants. */
421
+ runtimeActor: EnvActor;
422
+ /** Optional trace and invocation IDs for runtime reads, from trusted invocation context. */
423
+ runtimeAttribution?: () => EnvAttribution | undefined | Promise<EnvAttribution | undefined>;
424
+ /** Export already persisted events, for example through evlog. */
425
+ emit?: (event: EnvActivity) => void | Promise<void>;
426
+ }
427
+ interface EnvBridge extends EnvProvider {
428
+ permissions(context: EnvAccessContext, key: string): Promise<readonly EnvPermission[]>;
429
+ inspect(context: EnvAccessContext, key: string): Promise<EnvSecretMetadata | undefined>;
430
+ preview(context: EnvAccessContext, key: string): Promise<Pick<EnvSecretMetadata, "preview"> | undefined>;
431
+ replace(context: EnvAccessContext, input: {
432
+ key: string;
433
+ value: string;
434
+ expectedRevision: string | null;
435
+ }): Promise<EnvReplacement>;
436
+ /** Run with the read secret and its revision, when the store provides one. */
437
+ use<T>(context: EnvAccessContext, key: string, operation: string, run: (secret: SecretEnv<string>, metadata?: Readonly<{
438
+ revision?: string;
439
+ }>) => T | Promise<T>): Promise<T>;
440
+ activity(context: EnvAccessContext, key: string, before?: string): Promise<readonly EnvActivity[]>;
441
+ grants(context: EnvAccessContext, key: string): Promise<readonly EnvGrant[]>;
442
+ grant(context: EnvAccessContext, grant: EnvGrant): Promise<void>;
443
+ revoke(context: EnvAccessContext, actor: EnvActor, key: string): Promise<void>;
444
+ }
445
+ declare function createEnvBridge(options: EnvBridgeOptions): EnvBridge;
446
+ //#endregion
447
+ export { EnvAttribution as $, EnvRuntimeRegistry as A, PublicEnv as B, EnvMode as C, EnvProviderValues as D, EnvProviderContext as E, EnvTypedVariableOptions as F, ServerEnvInspection as G, ServerEnv as H, EnvValueSchema as I, EnvBridgeRequestOptions as J, ServerEnvInspectionEntry as K, EnvVariableDeclaration as L, EnvSource as M, EnvSourceContext as N, EnvProviders as O, EnvSourceResolver as P, SecretEnv as Q, EnvVariableOptions as R, EnvDiagnostics as S, EnvProvider as T, ServerEnvDescription as U, ReadonlyServerEnv as V, ServerEnvDescriptionEntry as W, EnvManagementResolver as X, EnvManagement as Y, createEnvBridgeHandler as Z, EnvHumanSession as _, EnvActor as a, EnvDeclarations as b, EnvGrant as c, EnvSecretMetadata as d, EnvSecretStore as f, EnvAuthenticatorOptions as g, EnvAgentSession as h, EnvActivity as i, EnvSchemaModuleReference as j, EnvRuntimeConfigOptions as k, EnvPermission as l, EnvAgentScope as m, EnvAccessScope as n, EnvBridge as o, createEnvBridge as p, ServerEnvInspectionStatus as q, EnvAccessStore as r, EnvBridgeOptions as s, EnvAccessContext as t, EnvReplacement as u, createEnvAuthenticator as v, EnvOptions as w, EnvDiagnosticEntry as x, DeepReadonly as y, LoadServerEnvOptions as z };
@@ -0,0 +1,66 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ import { ViteHubError, isViteHubError } from "@vite-hub/runtime";
3
+ //#region src/bridge-error.ts
4
+ const messages = {
5
+ denied: "Env access denied.",
6
+ conflict: "The credential changed. Refresh before replacing it.",
7
+ missing: "Credential unavailable.",
8
+ invalid: "Invalid Env request.",
9
+ operation_failed: "Env operation failed.",
10
+ audit_failed: "Env activity could not be persisted.",
11
+ untrusted: "Env did not create this access context."
12
+ };
13
+ function envBridgeError(code) {
14
+ return new ViteHubError(`ENV_BRIDGE_${code.toUpperCase()}`, messages[code]);
15
+ }
16
+ const guidance = (fix) => ({
17
+ why: ({ message }) => message,
18
+ fix
19
+ });
20
+ /** Repair guidance that the management route adds to each bridge error body. */
21
+ const envBridgeDiagnostics = /*#__PURE__*/ defineDiagnostics({
22
+ docsBase: "https://vitehub.dev/docs/env/diagnostics",
23
+ codes: {
24
+ ENV_BRIDGE_DENIED: guidance("Ask an Env admin to grant the permission for this key."),
25
+ ENV_BRIDGE_CONFLICT: guidance("Reload the credential details, then replace it again."),
26
+ ENV_BRIDGE_MISSING: guidance("Store a value for this credential first."),
27
+ ENV_BRIDGE_INVALID: guidance("Check the request fields and the stored value limits, then send it again."),
28
+ ENV_BRIDGE_OPERATION_FAILED: guidance("Try again. If this continues, read the server logs for this request."),
29
+ ENV_BRIDGE_AUDIT_FAILED: guidance("Check the Env activity store, then try again."),
30
+ ENV_BRIDGE_UNTRUSTED: guidance("Create the access context with the Env bridge authenticate function.")
31
+ }
32
+ });
33
+ /** The JSON error body of a sanitized bridge error: `code`, `message` (the why), `fix`, and `docs`. */
34
+ function envBridgeErrorBody(error) {
35
+ const code = error.code;
36
+ if (!isEnvBridgeDiagnosticCode(code)) return {
37
+ code,
38
+ message: error.message
39
+ };
40
+ const diagnostic = envBridgeDiagnostics[code]({ message: error.message });
41
+ return {
42
+ code,
43
+ docs: diagnostic.docs,
44
+ fix: diagnostic.fix,
45
+ message: error.message
46
+ };
47
+ }
48
+ function isEnvBridgeDiagnosticCode(code) {
49
+ return Object.keys(envBridgeDiagnostics).includes(code);
50
+ }
51
+ function sanitizeEnvBridgeError(error) {
52
+ if (isViteHubError(error)) {
53
+ for (const code of [
54
+ "denied",
55
+ "conflict",
56
+ "missing",
57
+ "invalid",
58
+ "operation_failed",
59
+ "audit_failed",
60
+ "untrusted"
61
+ ]) if (error.code === `ENV_BRIDGE_${code.toUpperCase()}`) return envBridgeError(code);
62
+ }
63
+ return envBridgeError("operation_failed");
64
+ }
65
+ //#endregion
66
+ export { envBridgeErrorBody as n, sanitizeEnvBridgeError as r, envBridgeError as t };
@@ -0,0 +1,2 @@
1
+ import { J as EnvBridgeRequestOptions, X as EnvManagementResolver, Y as EnvManagement, Z as createEnvBridgeHandler, _ as EnvHumanSession, a as EnvActor, c as EnvGrant, d as EnvSecretMetadata, f as EnvSecretStore, g as EnvAuthenticatorOptions, h as EnvAgentSession, i as EnvActivity, l as EnvPermission, m as EnvAgentScope, n as EnvAccessScope, o as EnvBridge, p as createEnvBridge, r as EnvAccessStore, s as EnvBridgeOptions, t as EnvAccessContext, u as EnvReplacement, v as createEnvAuthenticator } from "./bridge-Cs9YfQWk.js";
2
+ export { EnvAccessContext, EnvAccessScope, EnvAccessStore, EnvActivity, EnvActor, type EnvAgentScope, type EnvAgentSession, type EnvAuthenticatorOptions, EnvBridge, EnvBridgeOptions, type EnvBridgeRequestOptions, EnvGrant, type EnvHumanSession, type EnvManagement, type EnvManagementResolver, EnvPermission, EnvReplacement, EnvSecretMetadata, EnvSecretStore, createEnvAuthenticator, createEnvBridge, createEnvBridgeHandler };