@vite-hub/env 0.4.1 → 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 (43) hide show
  1. package/README.md +3 -3
  2. package/dist/{access-B8lSDip4.js → access-DIErLk3w.js} +2 -3
  3. package/dist/{bridge-Cs9YfQWk.d.ts → bridge-BWwIooe0.d.ts} +0 -12
  4. package/dist/{bridge-error-BhJ77age.js → bridge-error-DEqzARPJ.js} +1 -3
  5. package/dist/bridge.d.ts +1 -1
  6. package/dist/bridge.js +9 -10
  7. package/dist/{cli-BPp7rdcA.d.ts → cli-B-LW6l_J.d.ts} +1 -6
  8. package/dist/cli-CAlHK5nn.js +1354 -0
  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 -5
  13. package/dist/{declarations-C5XR3aKw.d.ts → declarations-DNjO52_s.d.ts} +1 -21
  14. package/dist/{schema-C_a0WZyd.js → declarations-meg4Rmgd.js} +43 -105
  15. package/dist/{object-C7Jt4ez2.js → error-diagnostics-5BceFRdD.js} +57 -14
  16. package/dist/{error-diagnostics-DsDPsST_.js → error-diagnostics-BFzFaXcH.js} +2 -4
  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-nmRu_O3V.d.ts → operation-definition-CqZkx1Rm.d.ts} +8 -6
  26. package/dist/{operations-B1PFpKzy.js → operations-BftegDMd.js} +2 -3
  27. package/dist/operations.d.ts +2 -6
  28. package/dist/operations.js +7 -41
  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-CgKAEAE6.d.ts → server-CPEywepM.d.ts} +1 -12
  37. package/dist/{server-B9-8r6MZ.js → server-pTqnkM7n.js} +213 -168
  38. package/dist/server.d.ts +2 -2
  39. package/dist/server.js +1 -2
  40. package/dist/vite.d.ts +5 -17
  41. package/dist/vite.js +20 -37
  42. package/package.json +11 -10
  43. package/dist/cli-C51D6V-M.js +0 -669
@@ -1,4 +1,3 @@
1
- //#region ../../node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts
2
1
  /** The Standard Typed interface. This is a base type extended by other specs. */
3
2
  interface StandardTypedV1<Input = unknown, Output = Input> {
4
3
  /** The Standard properties. */
@@ -74,8 +73,6 @@ declare namespace StandardSchemaV1 {
74
73
  /** Infers the output type of a Standard. */
75
74
  type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
76
75
  }
77
- //#endregion
78
- //#region ../internal/src/operation-definition.d.ts
79
76
  /** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
80
77
  type OperationKind = "read" | "write" | "destructive";
81
78
  /** The signed-in user of a call. */
@@ -104,6 +101,11 @@ interface OperationAccess {
104
101
  */
105
102
  readonly sections: "all" | readonly string[];
106
103
  readonly user?: OperationUser;
104
+ /**
105
+ * Who signed the call: `"console"` when the ViteHub Console signed it for a person, whose `user` is then a Console
106
+ * account and not an app user, or `"cli"` for a key. Not set for other calls.
107
+ */
108
+ readonly via?: "console" | "cli";
107
109
  }
108
110
  interface OperationContext {
109
111
  /** The checked Console access of the call. */
@@ -166,7 +168,8 @@ interface OperationDefinition<Input, Output> {
166
168
  /** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
167
169
  input: StandardSchemaV1<unknown, Input>;
168
170
  output?: StandardSchemaV1<unknown, Output>;
169
- cli?: {
171
+ /** `false`: no `vitehub` command. The Console and MCP still call the operation. */
172
+ cli?: false | {
170
173
  /** Defaults: namespace = section, command = verb. */
171
174
  namespace?: string;
172
175
  /** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
@@ -207,7 +210,7 @@ interface OperationDefinition<Input, Output> {
207
210
  /** An operation of any input and output, as a registry holds it. */
208
211
  interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "mcp" | "output" | "readOnlyWhen" | "run" | "scope" | "section"> {
209
212
  readOnlyWhen?: (input: never) => boolean;
210
- cli?: {
213
+ cli?: false | {
211
214
  namespace?: string;
212
215
  command?: string;
213
216
  default?: boolean;
@@ -235,5 +238,4 @@ interface OperationContributionEntry {
235
238
  /** `false`: the app already has these operations at runtime. Only tools such as the CLI and `vitehub inspect` read the entry. */
236
239
  runtime?: false;
237
240
  }
238
- //#endregion
239
241
  export { OperationContributionEntry as n, AnyOperation as t };
@@ -1,7 +1,7 @@
1
- import { a as isBlockingServerEnvEntry, c as runWithCloudflareEnv } from "./server-B9-8r6MZ.js";
1
+ import { a as isBlockingServerEnvEntry, c as runWithCloudflareEnv } from "./server-pTqnkM7n.js";
2
2
  import { detectHost } from "@vite-hub/runtime";
3
3
  import { inspectServerEnv } from "#vitehub/env/server";
4
- //#region src/runtime/operations.ts
4
+ // src/runtime/operations.ts
5
5
  function entryOf(entry) {
6
6
  return {
7
7
  ...entry.path === void 0 ? {} : { path: entry.path },
@@ -26,5 +26,4 @@ async function inspectEnvOperation(context) {
26
26
  ...host ? { host } : {}
27
27
  };
28
28
  }
29
- //#endregion
30
29
  export { inspectEnvOperation };
@@ -1,7 +1,6 @@
1
- import { K as ServerEnvInspectionEntry, q as ServerEnvInspectionStatus } from "./bridge-Cs9YfQWk.js";
2
- import { t as AnyOperation } from "./operation-definition-nmRu_O3V.js";
1
+ import { t as AnyOperation } from "./operation-definition-CqZkx1Rm.js";
2
+ import { K as ServerEnvInspectionEntry, q as ServerEnvInspectionStatus } from "./bridge-BWwIooe0.js";
3
3
  import { ViteHubHost } from "@vite-hub/runtime";
4
- //#region src/runtime/operations.d.ts
5
4
  /** One Server Env declaration as the running app sees it. It never holds a value, a preview, or a length. */
6
5
  interface EnvInspectEntry {
7
6
  /** The declaration path, such as `env.server.stripe.key`. */
@@ -29,9 +28,6 @@ interface EnvInspectResult {
29
28
  /** The host that the app runs on, such as `cloudflare`, so a fix can name `vitehub env push --host <host>`. */
30
29
  host?: ViteHubHost;
31
30
  }
32
- //#endregion
33
- //#region src/operations.d.ts
34
31
  /** The `env.*` operations. The Console, the CLI, and agents run them on the signed `POST /_vitehub/rpc` endpoint. */
35
32
  export declare const envOperations: readonly AnyOperation[];
36
- //#endregion
37
33
  export type { EnvInspectEntry, EnvInspectResult };
@@ -1,36 +1,6 @@
1
- import { n as isRecordOrFunction, r as internalErrorDiagnostics } from "./object-C7Jt4ez2.js";
1
+ import { a as isRecordOrFunction, n as standardJsonSchema, t as internalErrorDiagnostics } from "./error-diagnostics-5BceFRdD.js";
2
2
  import * as v from "valibot";
3
- //#region ../internal/src/standard-schema.ts
4
- function readOwn(value, key) {
5
- if (value === null || Object(value) !== value) return;
6
- try {
7
- return Reflect.get(Object(value), key);
8
- } catch {
9
- return;
10
- }
11
- }
12
- /**
13
- * Read a Standard JSON Schema projection without throwing.
14
- *
15
- * Returns `undefined` when the schema has no `~standard.jsonSchema`, when the library cannot represent the type
16
- * (Zod throws for `Date`), or when the projection is not an object. Callers decide how to fall back.
17
- */
18
- function standardJsonSchema(schema, direction, target = "draft-2020-12", libraryOptions) {
19
- const jsonSchema = readOwn(readOwn(schema, "~standard"), "jsonSchema");
20
- const project = readOwn(jsonSchema, direction);
21
- if (typeof project !== "function") return;
22
- try {
23
- const result = project.call(jsonSchema, libraryOptions ? {
24
- target,
25
- libraryOptions
26
- } : { target });
27
- return isRecordOrFunction(result) ? result : void 0;
28
- } catch {
29
- return;
30
- }
31
- }
32
- //#endregion
33
- //#region ../../node_modules/.pnpm/@valibot+to-json-schema@1.8.0_valibot@1.5.0_typescript@6.0.3_/node_modules/@valibot/to-json-schema/dist/index.mjs
3
+ // ../../node_modules/.pnpm/@valibot+to-json-schema@1.8.0_valibot@1.5.0_typescript@6.0.3_/node_modules/@valibot/to-json-schema/dist/index.mjs
34
4
  /**
35
5
  * Adds an error message to the errors array.
36
6
  *
@@ -712,8 +682,7 @@ function toJsonSchema(schema, config) {
712
682
  if (context.referenceMap.size) jsonSchema.$defs = context.definitions;
713
683
  return jsonSchema;
714
684
  }
715
- //#endregion
716
- //#region ../internal/src/valibot.ts
685
+ // ../internal/src/valibot.ts
717
686
  const valibotTargets = /* @__PURE__ */ new Set([
718
687
  "draft-07",
719
688
  "draft-2020-12",
@@ -754,8 +723,7 @@ function withValibotJsonSchema(schema, options = {}) {
754
723
  }
755
724
  };
756
725
  }
757
- //#endregion
758
- //#region ../internal/src/operation-definition.ts
726
+ // ../internal/src/operation-definition.ts
759
727
  const nameFormat = /^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$/;
760
728
  const kinds = /* @__PURE__ */ new Set([
761
729
  "read",
@@ -815,12 +783,11 @@ function isSectionId(section) {
815
783
  function operationInputJsonSchema(operation) {
816
784
  return standardJsonSchema(operation.input, "input") ?? { type: "object" };
817
785
  }
818
- //#endregion
819
- //#region src/operations.ts
820
- const runtime = () => import("./operations-B1PFpKzy.js");
786
+ // src/operations.ts
787
+ const runtime = () => import("./operations-BftegDMd.js");
821
788
  /** The `env.*` operations. The Console, the CLI, and agents run them on the signed `POST /_vitehub/rpc` endpoint. */
822
789
  const envOperations = [defineOperation({
823
- cli: { command: "status" },
790
+ cli: { command: "list" },
824
791
  description: "Show the status of each Server Env value as the running app sees it. Values are never returned.",
825
792
  input: v.strictObject({}),
826
793
  kind: "read",
@@ -829,5 +796,4 @@ const envOperations = [defineOperation({
829
796
  section: "env",
830
797
  user: false
831
798
  })];
832
- //#endregion
833
799
  export { envOperations };
@@ -1,5 +1,3 @@
1
- import { B as PublicEnv } from "../bridge-Cs9YfQWk.js";
2
- //#region src/runtime/public-env.d.ts
1
+ import { B as PublicEnv } from "../bridge-BWwIooe0.js";
3
2
  /** Reads the declared Public Env. Its values are fixed when the app builds. */
4
- export declare function usePublicEnv(): PublicEnv;
5
- //#endregion
3
+ export declare function usePublicEnv(): PublicEnv;
@@ -1,8 +1,7 @@
1
- import { t as envErrorDiagnostics } from "../error-diagnostics-DsDPsST_.js";
2
- //#region src/runtime/public-env.ts
1
+ import { t as envErrorDiagnostics } from "../error-diagnostics-BFzFaXcH.js";
2
+ // src/runtime/public-env.ts
3
3
  /** Reads the declared Public Env. Its values are fixed when the app builds. */
4
4
  function usePublicEnv() {
5
5
  throw envErrorDiagnostics.ENV_NOT_GENERATED({ accessor: "usePublicEnv" });
6
6
  }
7
- //#endregion
8
7
  export { usePublicEnv };
@@ -1,6 +1,5 @@
1
- import { G as ServerEnvInspection, H as ServerEnv, U as ServerEnvDescription, V as ReadonlyServerEnv, t as EnvAccessContext } from "../bridge-Cs9YfQWk.js";
1
+ import { G as ServerEnvInspection, H as ServerEnv, U as ServerEnvDescription, V as ReadonlyServerEnv, t as EnvAccessContext } from "../bridge-BWwIooe0.js";
2
2
  import { ViteHubContext } from "@vite-hub/runtime";
3
- //#region src/runtime/server-env.d.ts
4
3
  interface ServerEnvLoadOptions {
5
4
  access?: EnvAccessContext;
6
5
  signal?: AbortSignal;
@@ -19,4 +18,4 @@ export declare function describeServerEnv(): ServerEnvDescription;
19
18
  export declare function deriveSecret(_purpose: string, _event?: ViteHubContext): Promise<string>;
20
19
  /** Answers the Env bridge requests of the Console. */
21
20
  export declare function manageServerEnv(_request: Request): Promise<Response>;
22
- //#endregion
21
+ export {};
@@ -1,5 +1,5 @@
1
- import { t as envErrorDiagnostics } from "../error-diagnostics-DsDPsST_.js";
2
- //#region src/runtime/server-env.ts
1
+ import { t as envErrorDiagnostics } from "../error-diagnostics-BFzFaXcH.js";
2
+ // src/runtime/server-env.ts
3
3
  function notGenerated(accessor) {
4
4
  throw envErrorDiagnostics.ENV_NOT_GENERATED({ accessor });
5
5
  }
@@ -31,5 +31,4 @@ async function deriveSecret(_purpose, _event) {
31
31
  async function manageServerEnv(_request) {
32
32
  return notGenerated("manageServerEnv");
33
33
  }
34
- //#endregion
35
34
  export { deriveSecret, describeServerEnv, inspectServerEnv, loadServerEnv, manageServerEnv, runWithServerEnv, useServerEnv };
package/dist/seal.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/seal.d.ts
2
1
  /** Stored sealed value format: `hex(iv):hex(ciphertext)`. */
3
2
  export declare const sealedPayloadPattern: RegExp;
4
3
  /** An imported AES-GCM key. */
@@ -13,5 +12,4 @@ export declare function sealKeyId(key: Uint8Array): Promise<string>;
13
12
  */
14
13
  export declare function sealWithKey(key: SealKey, additionalData: Uint8Array<ArrayBuffer>, plaintext: string): Promise<string>;
15
14
  /** Decrypts a value from `sealWithKey`. Fails when the key or `additionalData` differs. */
16
- export declare function unsealWithKey(key: SealKey, additionalData: Uint8Array<ArrayBuffer>, payload: string): Promise<string>;
17
- //#endregion
15
+ export declare function unsealWithKey(key: SealKey, additionalData: Uint8Array<ArrayBuffer>, payload: string): Promise<string>;
package/dist/seal.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ViteHubError } from "@vite-hub/runtime";
2
- //#region src/seal.ts
2
+ // src/seal.ts
3
3
  /** Stored sealed value format: `hex(iv):hex(ciphertext)`. */
4
4
  const sealedPayloadPattern = /^[a-f0-9]{24}:(?:[a-f0-9]{2}){16,}$/;
5
5
  function sealError() {
@@ -48,5 +48,4 @@ async function unsealWithKey(key, additionalData, payload) {
48
48
  });
49
49
  return new TextDecoder("utf-8", { ignoreBOM: true }).decode(value);
50
50
  }
51
- //#endregion
52
51
  export { importSealKey, sealKeyId, sealWithKey, sealedPayloadPattern, unsealWithKey };
@@ -1,4 +1,4 @@
1
- //#region src/secret.ts
1
+ // src/secret.ts
2
2
  const redactedSecret = "<redacted>";
3
3
  var SecretEnv = class {
4
4
  #value;
@@ -22,5 +22,4 @@ var SecretEnv = class {
22
22
  Object.defineProperty(SecretEnv.prototype, Symbol.for("nodejs.util.inspect.custom"), { value() {
23
23
  return redactedSecret;
24
24
  } });
25
- //#endregion
26
25
  export { SecretEnv as t };
@@ -1,6 +1,5 @@
1
- import { A as EnvRuntimeRegistry, G as ServerEnvInspection, K as ServerEnvInspectionEntry, Q as SecretEnv, U as ServerEnvDescription, y as DeepReadonly, z as LoadServerEnvOptions } from "./bridge-Cs9YfQWk.js";
1
+ import { A as EnvRuntimeRegistry, G as ServerEnvInspection, K as ServerEnvInspectionEntry, Q as SecretEnv, U as ServerEnvDescription, y as DeepReadonly, z as LoadServerEnvOptions } from "./bridge-BWwIooe0.js";
2
2
  import { Duration, Result, ViteHubContext, ViteHubContext as ViteHubContext$1 } from "@vite-hub/runtime";
3
- //#region src/schema.d.ts
4
3
  interface StandardSchemaResultSuccess<T = unknown> {
5
4
  issues?: undefined;
6
5
  value: T;
@@ -14,8 +13,6 @@ interface StandardSchemaV1<T = unknown> {
14
13
  };
15
14
  }
16
15
  declare function parseSchema(schema: unknown, value: unknown, label: string): unknown;
17
- //#endregion
18
- //#region src/internal/runtime-env.d.ts
19
16
  type RuntimeEnv = Record<string, unknown>;
20
17
  /**
21
18
  * A request event: an H3 event, another event with Standard Context, or a web `Request`. An H3 event matches `{ req }`
@@ -24,8 +21,6 @@ type RuntimeEnv = Record<string, unknown>;
24
21
  type RequestEvent = Request | ViteHubContext | {
25
22
  readonly req: Request;
26
23
  };
27
- //#endregion
28
- //#region src/seal-uses.d.ts
29
24
  /**
30
25
  * A SQLite, libSQL, or D1 Drizzle database, such as `db` from `vite-hub/database`. The uses of a sealed value live
31
26
  * there, because every instance of the app must see the same count. KV cannot take a use atomically.
@@ -33,8 +28,6 @@ type RequestEvent = Request | ViteHubContext | {
33
28
  interface SealUsesDatabase {
34
29
  all: (query: string) => unknown[] | PromiseLike<unknown[]>;
35
30
  }
36
- //#endregion
37
- //#region src/seal-value.d.ts
38
31
  /** The codes that `unseal()` returns. */
39
32
  type UnsealErrorCode = "ENV_SEAL_EXPIRED" | "ENV_SEAL_INVALID" | "ENV_SEAL_SCHEMA_MISMATCH" | "ENV_SEAL_USED_UP" | "ENV_SEAL_WRONG_PURPOSE";
40
33
  interface UnsealOptions {
@@ -100,8 +93,6 @@ declare function seal(purpose: string, value: unknown, options?: SealOptions): P
100
93
  */
101
94
  declare function unseal<T>(purpose: string, sealed: string, options: UnsealSchemaOptions<T>): Promise<Result<T, UnsealErrorCode>>;
102
95
  declare function unseal(purpose: string, sealed: string, options?: UnsealOptions): Promise<Result<unknown, UnsealErrorCode>>;
103
- //#endregion
104
- //#region src/server.d.ts
105
96
  /**
106
97
  * Run `callback` with `env` as the active Cloudflare bindings. Server Env reads them when a call gets no request
107
98
  * event, such as for the module bindings of `cloudflare:workers` outside a request.
@@ -114,7 +105,6 @@ interface DeriveSecretOptions {
114
105
  /** The root secret. Without it, ViteHub reads `VITEHUB_SECRET`. */
115
106
  root?: string;
116
107
  }
117
- /** The development secret that the Vite plugin generated or selected for one project. Private to the generated module. */
118
108
  interface DevelopmentSecret {
119
109
  envKey?: string;
120
110
  generated?: boolean;
@@ -144,5 +134,4 @@ declare function describeServerEnv(registry: EnvRuntimeRegistry): ServerEnvDescr
144
134
  /** Returns whether an inspection entry makes `loadServerEnv()` fail: invalid, provider error, or required and missing. */
145
135
  declare function isBlockingServerEnvEntry(entry: ServerEnvInspectionEntry): boolean;
146
136
  declare function inspectServerEnv(registry: EnvRuntimeRegistry, event?: ViteHubContext, options?: LoadServerEnvOptions): Promise<ServerEnvInspection>;
147
- //#endregion
148
137
  export { parseSchema as C, StandardSchemaV1 as S, unseal as _, describeServerEnv as a, StandardSchemaResultFailure as b, loadServerEnv as c, SealOptions as d, UnsealErrorCode as f, seal as g, createSealing as h, deriveSecret as i, resolveServerEnv as l, UnsealSchemaOptions as m, ViteHubContext$1 as n, inspectServerEnv as o, UnsealOptions as p, bindServerEnvSchemas as r, isBlockingServerEnvEntry as s, DeriveSecretOptions as t, runWithCloudflareEnv as u, SealUsesDatabase as v, StandardSchemaResultSuccess as x, RequestEvent as y };