@vite-hub/env 0.5.0 → 0.5.1

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 (42) hide show
  1. package/README.md +1 -1
  2. package/dist/{access-C5sPO6C2.js → access-DIErLk3w.js} +2 -3
  3. package/dist/{bridge-Cs9YfQWk.d.ts → bridge-BWwIooe0.d.ts} +0 -12
  4. package/dist/{bridge-error-t9bc6xvE.js → bridge-error-DEqzARPJ.js} +1 -2
  5. package/dist/bridge.d.ts +1 -1
  6. package/dist/bridge.js +6 -9
  7. package/dist/{cli-DJtQF4Wi.d.ts → cli-B-LW6l_J.d.ts} +0 -6
  8. package/dist/{cli-BctSFldY.js → cli-CAlHK5nn.js} +12 -21
  9. package/dist/cli.d.ts +3 -6
  10. package/dist/cli.js +1 -2
  11. package/dist/database.d.ts +2 -4
  12. package/dist/database.js +2 -3
  13. package/dist/{declarations-BEL0yvEY.d.ts → declarations-DNjO52_s.d.ts} +1 -3
  14. package/dist/{schema-CnCp0Muw.js → declarations-meg4Rmgd.js} +6 -71
  15. package/dist/{object-DICxAEoH.js → error-diagnostics-5BceFRdD.js} +52 -13
  16. package/dist/{error-diagnostics-CwQGNVnK.js → error-diagnostics-BFzFaXcH.js} +1 -2
  17. package/dist/index.d.ts +3 -13
  18. package/dist/index.js +8 -12
  19. package/dist/internal/agent.d.ts +2 -4
  20. package/dist/internal/agent.js +3 -4
  21. package/dist/internal/connections.d.ts +2 -4
  22. package/dist/internal/connections.js +3 -4
  23. package/dist/internal/server.d.ts +2 -2
  24. package/dist/internal/server.js +1 -2
  25. package/dist/{operation-definition-CI2PJGqu.d.ts → operation-definition-CqZkx1Rm.d.ts} +0 -4
  26. package/dist/{operations-LVaCzpR0.js → operations-BftegDMd.js} +2 -3
  27. package/dist/operations.d.ts +2 -6
  28. package/dist/operations.js +6 -40
  29. package/dist/runtime/public-env.d.ts +2 -4
  30. package/dist/runtime/public-env.js +2 -3
  31. package/dist/runtime/server-env.d.ts +2 -3
  32. package/dist/runtime/server-env.js +2 -3
  33. package/dist/seal.d.ts +1 -3
  34. package/dist/seal.js +1 -2
  35. package/dist/{secret-DJd-fy5T.js → secret-VhbE53Vm.js} +1 -2
  36. package/dist/{server-OvARy_y9.d.ts → server-CPEywepM.d.ts} +1 -11
  37. package/dist/{server-Ct3uvhf9.js → server-pTqnkM7n.js} +209 -152
  38. package/dist/server.d.ts +2 -2
  39. package/dist/server.js +1 -2
  40. package/dist/vite.d.ts +4 -16
  41. package/dist/vite.js +20 -21
  42. package/package.json +11 -10
package/README.md CHANGED
@@ -256,7 +256,7 @@ VITEHUB_RETRIES=3
256
256
  VITEHUB_API_TOKEN=
257
257
  ```
258
258
 
259
- This uses the restricted `env-spec-v1` profile shared with the [Nuxt module](https://nuxt-safe-runtime-config.onmax.me). Its [@env-spec syntax](https://varlock.dev/env-spec/reference/) parser reads static metadata. It does not run Varlock, load developer `.env` files, or evaluate expansions and functions.
259
+ This uses the restricted [`env-spec-v1` profile](https://vitehub.dev/docs/env/env-spec). Its [@env-spec syntax](https://varlock.dev/env-spec/reference/) parser reads static metadata. It does not run Varlock, load developer `.env` files, or evaluate expansions and functions.
260
260
 
261
261
  A nonempty assignment is a real default. `KEY=` has no default; `KEY=""` is an explicit empty string. Put documentation samples in `@example`, which never supplies a value. Review existing example assignments before opting in. All fields default to required and sensitive; the default type is always string, so `CODE=00123` preserves its zeroes.
262
262
 
@@ -1,6 +1,6 @@
1
- import { t as envBridgeError } from "./bridge-error-t9bc6xvE.js";
1
+ import { t as envBridgeError } from "./bridge-error-DEqzARPJ.js";
2
2
  import { defineGrant } from "@vite-hub/runtime/internal/grant";
3
- //#region src/internal/access.ts
3
+ // src/internal/access.ts
4
4
  /** Marks the type of contexts that Env creates. The bridge trusts only the `envAccess` grant registry, not this marker. */
5
5
  const envAccessGrant = Symbol("vitehub.env.access-grant");
6
6
  const envAccess = defineGrant("vitehub.env.access", (authority) => authority.kind === "key" ? Object.freeze({
@@ -50,5 +50,4 @@ function envAccessAuthority(context) {
50
50
  if (!authority) throw envBridgeError("untrusted");
51
51
  return authority;
52
52
  }
53
- //#endregion
54
53
  export { validateEnvActor as i, envIdentifier as n, grantEnvAccess as r, envAccessAuthority as t };
@@ -1,12 +1,9 @@
1
- //#region src/internal/access.d.ts
2
1
  /** Marks the type of contexts that Env creates. The bridge trusts only the `envAccess` grant registry, not this marker. */
3
2
  declare const envAccessGrant: unique symbol;
4
3
  interface EnvAttribution {
5
4
  traceId?: string;
6
5
  invocationId?: string;
7
6
  }
8
- //#endregion
9
- //#region src/secret.d.ts
10
7
  declare class SecretEnv<T = string> {
11
8
  #private;
12
9
  constructor(value: T);
@@ -15,8 +12,6 @@ declare class SecretEnv<T = string> {
15
12
  toJSON(): string;
16
13
  [Symbol.toPrimitive](): string;
17
14
  }
18
- //#endregion
19
- //#region src/http.d.ts
20
15
  interface EnvManagement {
21
16
  bridge: EnvBridge;
22
17
  authenticate(request: Request): EnvAccessContext | null | Promise<EnvAccessContext | null>;
@@ -35,8 +30,6 @@ type EnvManagementResolver = (path: string) => {
35
30
  } | undefined;
36
31
  /** Mount only on a server route. resolve selects declared credentials, never arbitrary store keys. */
37
32
  declare function createEnvBridgeHandler(resolve: EnvManagementResolver): (request: Request, options?: EnvBridgeRequestOptions) => Promise<Response>;
38
- //#endregion
39
- //#region src/types.d.ts
40
33
  type EnvDiagnostics = "off" | "summary" | "trace";
41
34
  type EnvMode = "build" | "runtime";
42
35
  /** Options of `vitehub({ env })` and `hubEnv()`: the Env declarations and how ViteHub resolves them. */
@@ -305,8 +298,6 @@ interface ServerEnvDescription {
305
298
  interface ServerEnvInspection {
306
299
  entries: readonly ServerEnvInspectionEntry[];
307
300
  }
308
- //#endregion
309
- //#region src/auth.d.ts
310
301
  interface EnvHumanSession {
311
302
  user: {
312
303
  id: string;
@@ -336,8 +327,6 @@ interface EnvAuthenticatorOptions<Human extends EnvHumanSession, Agent extends E
336
327
  }
337
328
  /** Authenticate management requests without coupling Env to a particular Better Auth plugin version. */
338
329
  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
330
  type EnvPermission = "inspect" | "preview" | "replace" | "use";
342
331
  interface EnvActor {
343
332
  id: string;
@@ -443,5 +432,4 @@ interface EnvBridge extends EnvProvider {
443
432
  revoke(context: EnvAccessContext, actor: EnvActor, key: string): Promise<void>;
444
433
  }
445
434
  declare function createEnvBridge(options: EnvBridgeOptions): EnvBridge;
446
- //#endregion
447
435
  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 };
@@ -1,6 +1,6 @@
1
1
  import { defineDiagnostics } from "nostics";
2
2
  import { ViteHubError, isViteHubError } from "@vite-hub/runtime";
3
- //#region src/bridge-error.ts
3
+ // src/bridge-error.ts
4
4
  const messages = {
5
5
  denied: "Env access denied.",
6
6
  conflict: "The credential changed. Refresh before replacing it.",
@@ -61,5 +61,4 @@ function sanitizeEnvBridgeError(error) {
61
61
  }
62
62
  return envBridgeError("operation_failed");
63
63
  }
64
- //#endregion
65
64
  export { envBridgeErrorBody as n, sanitizeEnvBridgeError as r, envBridgeError as t };
package/dist/bridge.d.ts CHANGED
@@ -1,2 +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";
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-BWwIooe0.js";
2
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 };
package/dist/bridge.js CHANGED
@@ -1,7 +1,7 @@
1
- import { t as SecretEnv } from "./secret-DJd-fy5T.js";
2
- import { n as envBridgeErrorBody, r as sanitizeEnvBridgeError, t as envBridgeError } from "./bridge-error-t9bc6xvE.js";
3
- import { i as validateEnvActor, n as envIdentifier, r as grantEnvAccess, t as envAccessAuthority } from "./access-C5sPO6C2.js";
4
- //#region src/auth.ts
1
+ import { n as envBridgeErrorBody, r as sanitizeEnvBridgeError, t as envBridgeError } from "./bridge-error-DEqzARPJ.js";
2
+ import { i as validateEnvActor, n as envIdentifier, r as grantEnvAccess, t as envAccessAuthority } from "./access-DIErLk3w.js";
3
+ import { t as SecretEnv } from "./secret-VhbE53Vm.js";
4
+ // src/auth.ts
5
5
  const permissions$1 = [
6
6
  "inspect",
7
7
  "preview",
@@ -42,8 +42,7 @@ function createEnvAuthenticator(options) {
42
42
  }
43
43
  };
44
44
  }
45
- //#endregion
46
- //#region src/http.ts
45
+ // src/http.ts
47
46
  function record(value) {
48
47
  return value !== null && typeof value === "object" && !Array.isArray(value);
49
48
  }
@@ -162,8 +161,7 @@ function createEnvBridgeHandler(resolve) {
162
161
  }
163
162
  };
164
163
  }
165
- //#endregion
166
- //#region src/bridge.ts
164
+ // src/bridge.ts
167
165
  async function safe(run) {
168
166
  try {
169
167
  return await run();
@@ -352,5 +350,4 @@ function createEnvBridge(options) {
352
350
  };
353
351
  return bridge;
354
352
  }
355
- //#endregion
356
353
  export { createEnvAuthenticator, createEnvBridge, createEnvBridgeHandler };
@@ -1,5 +1,4 @@
1
1
  import { Diagnostic } from "nostics";
2
- //#region ../internal/src/host-credentials.d.ts
3
2
  interface HostCliRunResult {
4
3
  exitCode: number | null;
5
4
  stdout: string;
@@ -11,8 +10,6 @@ type HostCliRun = (command: string, args: readonly string[], options: {
11
10
  env: NodeJS.ProcessEnv;
12
11
  signal?: AbortSignal;
13
12
  }) => Promise<HostCliRunResult>;
14
- //#endregion
15
- //#region ../internal/src/provision.d.ts
16
13
  type ProvisionProvider = "cloudflare" | "vercel";
17
14
  interface ProvisionLogger {
18
15
  log: (message: string) => void;
@@ -64,8 +61,6 @@ interface ProvisionStep {
64
61
  /** Describes the Provision State this step records. Runs without network access, also without credentials. */
65
62
  recordedState?: (context: Pick<ProvisionContext, "env">) => ProvisionStateCategory[];
66
63
  }
67
- //#endregion
68
- //#region ../internal/src/cli.d.ts
69
64
  interface ViteHubCliStreams {
70
65
  stderr: {
71
66
  write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
@@ -156,5 +151,4 @@ interface ViteHubCliContributor {
156
151
  publicUrl?: string;
157
152
  }
158
153
  type StdoutWriteCallback = (error?: Error | null) => void;
159
- //#endregion
160
154
  export { ViteHubCliContributor as n, ViteHubCliContext as t };
@@ -1,6 +1,6 @@
1
- import { t as envErrorDiagnostics } from "./error-diagnostics-CwQGNVnK.js";
2
- import { C as deriveViteHubSecret, E as readViteHubSecret, a as isBlockingServerEnvEntry, f as invariant } from "./server-Ct3uvhf9.js";
3
- import { n as isRecordOrFunction, r as internalErrorDiagnostics, t as isRecord } from "./object-DICxAEoH.js";
1
+ import { a as isRecordOrFunction, i as isRecord, t as internalErrorDiagnostics } from "./error-diagnostics-5BceFRdD.js";
2
+ import { S as readViteHubSecret, a as isBlockingServerEnvEntry, f as invariant, y as deriveViteHubSecret } from "./server-pTqnkM7n.js";
3
+ import { t as envErrorDiagnostics } from "./error-diagnostics-BFzFaXcH.js";
4
4
  import { createRequire } from "node:module";
5
5
  import { formatRuntimeDiagnosticError } from "@vite-hub/runtime";
6
6
  import * as v from "valibot";
@@ -9,7 +9,7 @@ import { basename, dirname, join, parse, resolve } from "node:path";
9
9
  import { pathToFileURL } from "node:url";
10
10
  import { tmpdir } from "node:os";
11
11
  import { randomBytes } from "node:crypto";
12
- //#region ../internal/src/cli.ts
12
+ // ../internal/src/cli.ts
13
13
  /** Validate an explicit `--url` before sending a Console request. The caller adds the RPC path. */
14
14
  function appUrlError(url) {
15
15
  let base;
@@ -132,8 +132,7 @@ function findViteHubDevServerUrl(roots, env) {
132
132
  }
133
133
  return env["VITEHUB_DEV_SERVER_URL"] || void 0;
134
134
  }
135
- //#endregion
136
- //#region ../internal/src/build/vite.ts
135
+ // ../internal/src/build/vite.ts
137
136
  const projectRootDirectoryMarkers = [
138
137
  ["server", "agents"],
139
138
  ["server", "channels"],
@@ -244,8 +243,7 @@ function createViteHubEnvImportAliases(root) {
244
243
  [VITEHUB_ENV_DESCRIPTION_ID]: viteHubEnvDescriptionModulePath(root)
245
244
  };
246
245
  }
247
- //#endregion
248
- //#region ../../node_modules/.pnpm/birpc@4.2.0/node_modules/birpc/dist/index.mjs
246
+ // ../../node_modules/.pnpm/birpc@4.2.0/node_modules/birpc/dist/index.mjs
249
247
  function createPromiseWithResolvers() {
250
248
  let resolve;
251
249
  let reject;
@@ -441,8 +439,7 @@ function createBirpc($functions, options) {
441
439
  _promiseInit = on(onMessage);
442
440
  return rpc;
443
441
  }
444
- //#endregion
445
- //#region ../internal/src/operation-rpc.ts
442
+ // ../internal/src/operation-rpc.ts
446
443
  /** Path of the operation RPC under the app. Dev servers and deployed apps serve it the same way, one birpc call per POST. */
447
444
  const operationRpcPath = "/_vitehub/rpc";
448
445
  function text(value) {
@@ -527,8 +524,7 @@ async function callOperationRpc(name, input, send) {
527
524
  };
528
525
  }
529
526
  }
530
- //#endregion
531
- //#region ../internal/src/console-signature.ts
527
+ // ../internal/src/console-signature.ts
532
528
  /**
533
529
  * Signed requests to the Console endpoint of an app, `POST /_vitehub/rpc`. Each caller, such as one Console link or one
534
530
  * CI job, has an Ed25519 key pair. The app keeps only the public keys, in `VITEHUB_CONSOLE_KEY_<NAME>`, so a copy of
@@ -670,8 +666,7 @@ function readConsoleSigningKey(env) {
670
666
  privateKey
671
667
  };
672
668
  }
673
- //#endregion
674
- //#region ../internal/src/operations.ts
669
+ // ../internal/src/operations.ts
675
670
  /** Header that proves the caller is not a browser page. A foreign page cannot send it without a CORS preflight. */
676
671
  const operationRpcHeader = "x-vitehub-console";
677
672
  /** Response header of the local dev RPC. Its value is {@link projectRootHash} of the project that the server runs. */
@@ -838,8 +833,7 @@ async function callOperationFromCli(call, name, input) {
838
833
  url
839
834
  }, name, input);
840
835
  }
841
- //#endregion
842
- //#region ../internal/src/vite-stage.ts
836
+ // ../internal/src/vite-stage.ts
843
837
  /**
844
838
  * Vite's `loadEnv(mode, envDir, "")`: every `.env` value of the mode and the whole shell. With `DEBUG=vite:env`, Vite
845
839
  * logs that result to stderr, secrets included. loadEnv is synchronous, so this drops only the writes of this call.
@@ -912,8 +906,7 @@ async function withViteStageEnvironment(env, callback) {
912
906
  release();
913
907
  }
914
908
  }
915
- //#endregion
916
- //#region src/secret-cli.ts
909
+ // src/secret-cli.ts
917
910
  const generateUsage = "vitehub secret generate";
918
911
  const deriveUsage = "vitehub secret derive <purpose>";
919
912
  const consoleKeyUsage = "vitehub secret console-key [name]";
@@ -1008,8 +1001,7 @@ const secretCliFeatures = [
1008
1001
  usage: consoleKeyUsage
1009
1002
  }
1010
1003
  ];
1011
- //#endregion
1012
- //#region src/cli.ts
1004
+ // src/cli.ts
1013
1005
  const defaultEnvCliStage = "development";
1014
1006
  function usage(command) {
1015
1007
  return command === "list" ? "vitehub env list [--stage <name> | --url <app>] [--json]" : `vitehub env ${command} [--stage <name>] [--json]`;
@@ -1359,5 +1351,4 @@ function createEnvCliContributor(options) {
1359
1351
  name: "secret"
1360
1352
  }] };
1361
1353
  }
1362
- //#endregion
1363
1354
  export { VITEHUB_ENV_SERVER as a, createViteHubEnvImportAliases as c, viteHubEnvAmbientTypesPath as d, viteHubEnvDescriptionModulePath as f, viteHubEnvServerModuleTypesPath as g, viteHubEnvServerModulePath as h, VITEHUB_ENV_PUBLIC_ID as i, isServerEnvironment as l, viteHubEnvPublicModuleTypesPath as m, secretCliFeatures as n, VITEHUB_ENV_SERVER_ID as o, viteHubEnvPublicModulePath as p, loadAllEnv as r, createNoExternalAddition as s, createEnvCliContributor as t, resolveViteHubProjectRoot as u };
package/dist/cli.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { G as ServerEnvInspection, K as ServerEnvInspectionEntry } from "./bridge-Cs9YfQWk.js";
2
- import { n as ViteHubCliContributor, t as ViteHubCliContext } from "./cli-DJtQF4Wi.js";
3
- //#region src/secret-cli.d.ts
1
+ import { n as ViteHubCliContributor, t as ViteHubCliContext } from "./cli-B-LW6l_J.js";
2
+ import { G as ServerEnvInspection, K as ServerEnvInspectionEntry } from "./bridge-BWwIooe0.js";
4
3
  interface SecretCliContext {
5
4
  env: Readonly<Record<string, string | undefined>>;
6
5
  stderr: {
@@ -18,8 +17,6 @@ interface SecretCliFeature {
18
17
  }
19
18
  /** `vitehub secret` features. They read only the process env and never load the project. */
20
19
  export declare const secretCliFeatures: SecretCliFeature[];
21
- //#endregion
22
- //#region src/cli.d.ts
23
20
  export interface EnvCliInspectInput {
24
21
  applicationRoot?: string;
25
22
  env: NodeJS.ProcessEnv;
@@ -38,4 +35,4 @@ export interface EnvCliReport {
38
35
  stage: string;
39
36
  }
40
37
  export declare function createEnvCliContributor(options: EnvCliOptions): ViteHubCliContributor;
41
- //#endregion
38
+ export {};
package/dist/cli.js CHANGED
@@ -1,2 +1 @@
1
- import { n as secretCliFeatures, t as createEnvCliContributor } from "./cli-BctSFldY.js";
2
- export { createEnvCliContributor, secretCliFeatures };
1
+ export { t as createEnvCliContributor, n as secretCliFeatures } from "./cli-CAlHK5nn.js";
@@ -1,6 +1,5 @@
1
- import { d as EnvSecretMetadata, f as EnvSecretStore, r as EnvAccessStore } from "./bridge-Cs9YfQWk.js";
1
+ import { d as EnvSecretMetadata, f as EnvSecretStore, r as EnvAccessStore } from "./bridge-BWwIooe0.js";
2
2
  import { SQL } from "drizzle-orm";
3
- //#region src/database.d.ts
4
3
  export interface EnvDatabase {
5
4
  run(query: SQL): unknown;
6
5
  all(query: SQL): unknown[] | PromiseLike<unknown[]>;
@@ -43,5 +42,4 @@ export declare function createDatabaseEnvStore(options: {
43
42
  encryptionKeys: readonly Uint8Array[];
44
43
  namespace?: string;
45
44
  previews?: boolean;
46
- }): DatabaseEnvStore;
47
- //#endregion
45
+ }): DatabaseEnvStore;
package/dist/database.js CHANGED
@@ -1,9 +1,9 @@
1
- import { t as envBridgeError } from "./bridge-error-t9bc6xvE.js";
1
+ import { t as envBridgeError } from "./bridge-error-DEqzARPJ.js";
2
2
  import { importSealKey, sealKeyId, sealWithKey, sealedPayloadPattern, unsealWithKey } from "./seal.js";
3
3
  import { ViteHubError } from "@vite-hub/runtime";
4
4
  import * as v from "valibot";
5
5
  import { sql } from "drizzle-orm";
6
- //#region src/database.ts
6
+ // src/database.ts
7
7
  const storedPayloadPattern = new RegExp(`^(?:v2:[a-f0-9]{16}:)?${sealedPayloadPattern.source.slice(1, -1)}$`);
8
8
  const identifier = v.pipe(v.string(), v.minLength(1), v.maxLength(512), v.regex(/^[^\u0000-\u001f]+$/));
9
9
  const actor = v.object({
@@ -268,5 +268,4 @@ function createDatabaseEnvStore(options) {
268
268
  }
269
269
  };
270
270
  }
271
- //#endregion
272
271
  export { createDatabaseEnvStore, listDatabaseEnvNamespaces };
@@ -1,5 +1,4 @@
1
- import { F as EnvTypedVariableOptions, L as EnvVariableDeclaration, M as EnvSource, P as EnvSourceResolver, R as EnvVariableOptions, j as EnvSchemaModuleReference } from "./bridge-Cs9YfQWk.js";
2
- //#region src/core/declarations.d.ts
1
+ import { F as EnvTypedVariableOptions, L as EnvVariableDeclaration, M as EnvSource, P as EnvSourceResolver, R as EnvVariableOptions, j as EnvSchemaModuleReference } from "./bridge-BWwIooe0.js";
3
2
  type EnvListItem = boolean | number | string;
4
3
  interface StandardSchemaLike {
5
4
  "~standard": {
@@ -36,5 +35,4 @@ interface EnvNamespace {
36
35
  }) => EnvSource;
37
36
  }
38
37
  declare const env: EnvNamespace;
39
- //#endregion
40
38
  export { env as t };
@@ -1,11 +1,10 @@
1
- import { t as envErrorDiagnostics } from "./error-diagnostics-CwQGNVnK.js";
2
- import { A as envValueTypeName, F as stringValueSchema, M as parseEnvValue, N as readJsonInput, j as listItemKinds } from "./server-Ct3uvhf9.js";
3
- //#region src/internal/runtime-type.ts
1
+ import { t as envErrorDiagnostics } from "./error-diagnostics-BFzFaXcH.js";
2
+ import { D as listItemKinds, E as envValueTypeName, O as parseEnvValue, P as readStandardValidate, j as stringValueSchema, k as readJsonInput } from "./server-pTqnkM7n.js";
3
+ // src/internal/runtime-type.ts
4
4
  function isRuntimeRecord(value) {
5
5
  return typeof value === "object" && value !== null && !Array.isArray(value);
6
6
  }
7
- //#endregion
8
- //#region src/core/declarations.ts
7
+ // src/core/declarations.ts
9
8
  const runtimeSchemaProperty = "__vitehubRuntimeSchema";
10
9
  const runtimeSchemaToken = getRuntimeSchemaToken();
11
10
  const runtimeSchemaParsers = /* @__PURE__ */ new WeakMap();
@@ -182,13 +181,7 @@ function isSchemaModule(value) {
182
181
  return schemaModuleReference(value) !== void 0;
183
182
  }
184
183
  function isStandardSchemaLike(value) {
185
- try {
186
- if (typeof value !== "object" && typeof value !== "function" || value === null) return false;
187
- const standard = Reflect.get(value, "~standard");
188
- return isRuntimeRecord(standard) && typeof standard.validate === "function";
189
- } catch {
190
- return false;
191
- }
184
+ return readStandardValidate(value, "env.json()") !== void 0;
192
185
  }
193
186
  function isDeclaration(value) {
194
187
  try {
@@ -302,62 +295,4 @@ function hasOnlyRuntimeSchemaKeys(schema) {
302
295
  const safeParse = Object.getOwnPropertyDescriptor(schema, "safeParse");
303
296
  return keys.length === 2 && keys.includes(runtimeSchemaProperty) && keys.includes("safeParse") && typeof safeParse?.value === "function";
304
297
  }
305
- //#endregion
306
- //#region src/schema.ts
307
- function parseSchema(schema, value, label) {
308
- if (isSchemaModuleReference(schema)) throw envErrorDiagnostics.ENV_R0029({ message: `[vitehub] ${label} uses env.schemaFrom(), which only env.server supports. Pass the schema object itself.` });
309
- if (isStandardSchema(schema)) {
310
- const result = schema["~standard"].validate(value);
311
- if (isPromiseLike(result)) throw envErrorDiagnostics.ENV_R0014({ message: `[vitehub] ${label} uses an async schema. Env validation currently requires sync schemas.` });
312
- if ("issues" in result && result.issues && result.issues.length > 0) throw envErrorDiagnostics.ENV_R0015({ message: `[vitehub] Invalid ${label}: ${formatIssues(result.issues)}` });
313
- if (!("value" in result)) throw envErrorDiagnostics.ENV_R0016({ message: `[vitehub] Invalid ${label}: ${formatIssues(result.issues)}` });
314
- return result.value;
315
- }
316
- if (isZodLike(schema) && hasSchemaMethod(schema, "safeParse") && typeof schema.safeParse === "function") {
317
- const result = schema.safeParse(value);
318
- if (!result.success) throw envErrorDiagnostics.ENV_R0017({ message: `[vitehub] Invalid ${label}: ${formatIssues(result.error)}` });
319
- return result.data;
320
- }
321
- if (isZodLike(schema) && hasSchemaMethod(schema, "parse") && typeof schema.parse === "function") try {
322
- return schema.parse(value);
323
- } catch (error) {
324
- throw envErrorDiagnostics.ENV_R0018({ message: `[vitehub] Invalid ${label}: ${formatIssues(error)}` });
325
- }
326
- return value;
327
- }
328
- function isSchemaModuleReference(schema) {
329
- return typeof schema === "object" && schema !== null && !Array.isArray(schema) && schema.kind === "schema-module";
330
- }
331
- function isPromiseLike(value) {
332
- return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
333
- }
334
- function isStandardSchema(schema) {
335
- return isZodLike(schema) && hasSchemaMethod(schema, "~standard") && typeof schema["~standard"]?.validate === "function";
336
- }
337
- function isZodLike(schema) {
338
- return typeof schema === "object" && schema !== null;
339
- }
340
- function hasSchemaMethod(schema, method) {
341
- return Object.hasOwn(schema, method) || isZodSchemaMethod(schema, method);
342
- }
343
- function isZodSchemaMethod(schema, method) {
344
- if (!Object.hasOwn(schema, "_zod")) return false;
345
- const metadata = schema._zod;
346
- if (!metadata) return false;
347
- const constructor = metadata?.constr;
348
- return hasSetValue(metadata?.traits, "ZodType") && Object.hasOwn(metadata, "constr") && typeof constructor === "function" && Object.getPrototypeOf(schema) === constructor.prototype && Object.hasOwn(constructor.prototype, method);
349
- }
350
- function hasSetValue(value, entry) {
351
- try {
352
- return Set.prototype.has.call(value, entry);
353
- } catch {
354
- return false;
355
- }
356
- }
357
- function formatIssues(issues) {
358
- if (Array.isArray(issues)) return issues.map((issue) => typeof issue === "string" ? issue : JSON.stringify(issue)).join("; ");
359
- if (issues instanceof Error) return issues.message;
360
- return typeof issues === "string" ? issues : JSON.stringify(issues);
361
- }
362
- //#endregion
363
- export { schemaModuleReference as a, runtimeValueSchema as i, descriptorVariable as n, env as r, parseSchema as t };
298
+ export { schemaModuleReference as i, env as n, runtimeValueSchema as r, descriptorVariable as t };
@@ -1,5 +1,51 @@
1
1
  import { defineDiagnostics } from "nostics";
2
- //#region ../internal/src/error-diagnostics.ts
2
+ // ../internal/src/object.ts
3
+ /** A non-null object that is not an array. Functions do not pass. */
4
+ function isRecord(value) {
5
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6
+ }
7
+ /** A non-null object or a function that is not an array. */
8
+ function isRecordOrFunction(value) {
9
+ return Object(value) === value && !Array.isArray(value);
10
+ }
11
+ // ../internal/src/standard-schema.ts
12
+ function readOwn(value, key) {
13
+ if (value === null || Object(value) !== value) return;
14
+ try {
15
+ return Reflect.get(Object(value), key);
16
+ } catch {
17
+ return;
18
+ }
19
+ }
20
+ /**
21
+ * The issues of a Standard Schema result, or `undefined` when the result has none. The result can be an array that
22
+ * carries its own `issues`, such as ArkType's `ArkErrors`.
23
+ */
24
+ function standardResultIssues(result) {
25
+ const issues = readOwn(result, "issues");
26
+ return Array.isArray(issues) && issues.length > 0 ? issues : void 0;
27
+ }
28
+ /**
29
+ * Read a Standard JSON Schema projection without throwing.
30
+ *
31
+ * Returns `undefined` when the schema has no `~standard.jsonSchema`, when the library cannot represent the type
32
+ * (Zod throws for `Date`), or when the projection is not an object. Callers decide how to fall back.
33
+ */
34
+ function standardJsonSchema(schema, direction, target = "draft-2020-12", libraryOptions) {
35
+ const jsonSchema = readOwn(readOwn(schema, "~standard"), "jsonSchema");
36
+ const project = readOwn(jsonSchema, direction);
37
+ if (typeof project !== "function") return;
38
+ try {
39
+ const result = project.call(jsonSchema, libraryOptions ? {
40
+ target,
41
+ libraryOptions
42
+ } : { target });
43
+ return isRecordOrFunction(result) ? result : void 0;
44
+ } catch {
45
+ return;
46
+ }
47
+ }
48
+ // ../internal/src/error-diagnostics.ts
3
49
  const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
4
50
  const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
5
51
  docsBase: "https://vitehub.dev/docs/development/diagnostics",
@@ -256,6 +302,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
256
302
  why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
257
303
  fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
258
304
  },
305
+ INTERNAL_SITE_TOKEN_TOO_LONG: {
306
+ why: ({ length, maximum }) => `The Site access token is ${length} characters, and an app accepts ${maximum}.`,
307
+ fix: "Open the app with a shorter path, or give the person and the project shorter names, so that the Site access token fits."
308
+ },
259
309
  INTERNAL_SQLITE_ARGUMENT_INVALID: {
260
310
  why: ({ value }) => value === "undefined" ? "undefined cannot be passed as argument to the database" : "Only finite numbers (not Infinity or NaN) can be passed as arguments",
261
311
  fix: "Pass query arguments as finite numbers, strings, booleans, bigints, dates, byte arrays, or null. Replace undefined with null, and check numbers with `Number.isFinite()` before the query."
@@ -270,15 +320,4 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
270
320
  }
271
321
  }
272
322
  });
273
- //#endregion
274
- //#region ../internal/src/object.ts
275
- /** A non-null object that is not an array. Functions do not pass. */
276
- function isRecord(value) {
277
- return typeof value === "object" && value !== null && !Array.isArray(value);
278
- }
279
- /** A non-null object or a function that is not an array. */
280
- function isRecordOrFunction(value) {
281
- return Object(value) === value && !Array.isArray(value);
282
- }
283
- //#endregion
284
- export { isRecordOrFunction as n, internalErrorDiagnostics as r, isRecord as t };
323
+ export { isRecordOrFunction as a, isRecord as i, standardJsonSchema as n, standardResultIssues as r, internalErrorDiagnostics as t };
@@ -1,5 +1,5 @@
1
1
  import { defineDiagnostics } from "nostics";
2
- //#region src/error-diagnostics.ts
2
+ // src/error-diagnostics.ts
3
3
  const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
4
4
  const withFix = (fix) => ({
5
5
  ...dynamicError,
@@ -51,5 +51,4 @@ const envErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
51
51
  }
52
52
  }
53
53
  });
54
- //#endregion
55
54
  export { envErrorDiagnostics as t };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import { A as EnvRuntimeRegistry, B as PublicEnv, C as EnvMode, D as EnvProviderValues, E as EnvProviderContext, F as EnvTypedVariableOptions, G as ServerEnvInspection, H as ServerEnv, I as EnvValueSchema, K as ServerEnvInspectionEntry, L as EnvVariableDeclaration, M as EnvSource, N as EnvSourceContext, O as EnvProviders, P as EnvSourceResolver, Q as SecretEnv, R as EnvVariableOptions, S as EnvDiagnostics, T as EnvProvider, U as ServerEnvDescription, V as ReadonlyServerEnv, W as ServerEnvDescriptionEntry, b as EnvDeclarations, j as EnvSchemaModuleReference, k as EnvRuntimeConfigOptions, q as ServerEnvInspectionStatus, w as EnvOptions, x as EnvDiagnosticEntry, y as DeepReadonly, z as LoadServerEnvOptions } from "./bridge-Cs9YfQWk.js";
2
- import { t as env } from "./declarations-BEL0yvEY.js";
3
- import { C as parseSchema, S as StandardSchemaV1, _ as unseal, b as StandardSchemaResultFailure, d as SealOptions, f as UnsealErrorCode, g as seal, m as UnsealSchemaOptions, p as UnsealOptions, s as isBlockingServerEnvEntry, v as SealUsesDatabase, x as StandardSchemaResultSuccess, y as RequestEvent } from "./server-OvARy_y9.js";
1
+ import { t as env } from "./declarations-DNjO52_s.js";
2
+ import { A as EnvRuntimeRegistry, B as PublicEnv, C as EnvMode, D as EnvProviderValues, E as EnvProviderContext, F as EnvTypedVariableOptions, G as ServerEnvInspection, H as ServerEnv, I as EnvValueSchema, K as ServerEnvInspectionEntry, L as EnvVariableDeclaration, M as EnvSource, N as EnvSourceContext, O as EnvProviders, P as EnvSourceResolver, Q as SecretEnv, R as EnvVariableOptions, S as EnvDiagnostics, T as EnvProvider, U as ServerEnvDescription, V as ReadonlyServerEnv, W as ServerEnvDescriptionEntry, b as EnvDeclarations, j as EnvSchemaModuleReference, k as EnvRuntimeConfigOptions, q as ServerEnvInspectionStatus, w as EnvOptions, x as EnvDiagnosticEntry, y as DeepReadonly, z as LoadServerEnvOptions } from "./bridge-BWwIooe0.js";
3
+ import { C as parseSchema, S as StandardSchemaV1, _ as unseal, b as StandardSchemaResultFailure, d as SealOptions, f as UnsealErrorCode, g as seal, m as UnsealSchemaOptions, p as UnsealOptions, s as isBlockingServerEnvEntry, v as SealUsesDatabase, x as StandardSchemaResultSuccess, y as RequestEvent } from "./server-CPEywepM.js";
4
4
  import { Result, ViteHubError } from "@vite-hub/runtime";
5
5
  import { deriveSecret, describeServerEnv, inspectServerEnv, loadServerEnv, runWithServerEnv, useServerEnv } from "#vitehub/env/server";
6
6
  import { usePublicEnv } from "#vitehub/env/public";
7
- //#region src/presets.d.ts
8
7
  interface OpenWorkflowEnvOptions {
9
8
  namespaceId?: string;
10
9
  schema?: string;
@@ -22,11 +21,7 @@ interface TypesafeEnvOptions {
22
21
  * missing key when it runs, so an application without AI still starts.
23
22
  */
24
23
  export declare function typesafeEnv(options?: TypesafeEnvOptions): EnvRuntimeConfigOptions;
25
- //#endregion
26
- //#region src/provider.d.ts
27
24
  export declare function defineEnvProvider<TEnv extends Record<string, unknown> = Record<string, unknown>, const TProvider extends EnvProvider<TEnv> = EnvProvider<TEnv>>(provider: TProvider): TProvider;
28
- //#endregion
29
- //#region src/service-token.d.ts
30
25
  /** The codes that `checkServiceToken()` returns. */
31
26
  type ServiceTokenErrorCode = "ENV_SERVICE_TOKEN_INVALID" | "ENV_SERVICE_TOKEN_UNSET";
32
27
  /**
@@ -67,8 +62,6 @@ export declare function checkServiceToken(event: ServiceTokenEvent, name: string
67
62
  * ```
68
63
  */
69
64
  export declare function requireServiceToken(event: ServiceTokenEvent, name: string): void;
70
- //#endregion
71
- //#region src/webhook.d.ts
72
65
  /** The codes that `verifyWebhook()` returns. */
73
66
  type WebhookErrorCode = "ENV_WEBHOOK_BODY_INVALID" | "ENV_WEBHOOK_SCHEMA_MISMATCH" | "ENV_WEBHOOK_SECRET_UNSET" | "ENV_WEBHOOK_SIGNATURE_INVALID";
74
67
  /** How `verifyWebhook()` checks the signature. `secret` is the name of the server variable that holds the signing secret. */
@@ -149,8 +142,6 @@ interface SignWebhookOptions {
149
142
  * ```
150
143
  */
151
144
  export declare function signWebhook(body: string | Uint8Array<ArrayBuffer>, options: SignWebhookOptions): Promise<Record<string, string>>;
152
- //#endregion
153
- //#region src/core/errors.d.ts
154
145
  declare const envErrorMessages: {
155
146
  readonly ENV_DECLARATION_INVALID: "[vitehub] Env declaration is invalid.";
156
147
  readonly ENV_ASYNC_REQUIRED: "[vitehub] Server Env requires asynchronous loading.";
@@ -182,5 +173,4 @@ interface EnvErrorDetailsByCode {
182
173
  };
183
174
  }
184
175
  type EnvErrorDetails<TCode extends EnvErrorCode = EnvErrorCode> = EnvErrorDetailsByCode[TCode];
185
- //#endregion
186
176
  export { type DeepReadonly, type EnvDeclarations, type EnvDiagnosticEntry, type EnvDiagnostics, type EnvErrorCode, type EnvErrorDetails, type EnvMode, type EnvOptions, type EnvProvider, type EnvProviderContext, type EnvProviderValues, type EnvProviders, type EnvRuntimeConfigOptions, type EnvRuntimeRegistry, type EnvSchemaModuleReference, type EnvSource, type EnvSourceContext, type EnvSourceIdentifier, type EnvSourceResolver, type EnvTypedVariableOptions, type EnvValueSchema, type EnvVariableDeclaration, type EnvVariableOptions, type LoadServerEnvOptions, type OpenWorkflowEnvOptions, type PublicEnv, type ReadonlyServerEnv, type SealOptions, type SealUsesDatabase, SecretEnv, type ServerEnv, type ServerEnvDescription, type ServerEnvDescriptionEntry, type ServerEnvInspection, type ServerEnvInspectionEntry, type ServerEnvInspectionStatus, type ServiceTokenErrorCode, type ServiceTokenEvent, type SignWebhookOptions, type StandardSchemaResultFailure, type StandardSchemaResultSuccess, type StandardSchemaV1, type TypesafeEnvOptions, type UnsealErrorCode, type UnsealOptions, type UnsealSchemaOptions, type VerifyWebhookOptions, type VerifyWebhookSchemaOptions, type WebhookErrorCode, deriveSecret, describeServerEnv, env, inspectServerEnv, isBlockingServerEnvEntry, loadServerEnv, parseSchema, runWithServerEnv, seal, unseal, usePublicEnv, useServerEnv };