@vite-hub/env 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -4,7 +4,6 @@
4
4
  <a href="https://vitehub.dev"><img alt="ViteHub" src="https://img.shields.io/badge/ViteHub-vitehub.dev-646cff?style=flat-square"></a>
5
5
  <img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-ready-3178c6?style=flat-square">
6
6
  <img alt="Vite" src="https://img.shields.io/badge/Vite-public%20env-646cff?style=flat-square">
7
- <img alt="Nitro" src="https://img.shields.io/badge/Nitro-server%20env-00dc82?style=flat-square">
8
7
  </p>
9
8
 
10
9
  `@vite-hub/env` declares environment values once, then generates typed public and server env access.
@@ -19,50 +18,88 @@ pnpm add @vite-hub/env
19
18
 
20
19
  ```ts
21
20
  // vite.config.ts
22
- import { env, envVite } from "@vite-hub/env/vite"
21
+ import { env, hubEnv } from "@vite-hub/env/vite"
23
22
  import { defineConfig } from "vite"
24
23
 
25
24
  export default defineConfig({
26
- plugins: [envVite({ prefix: "VITEHUB_" })],
25
+ plugins: [hubEnv({ prefix: "VITEHUB_" })],
27
26
  env: {
28
27
  public: {
29
28
  appName: env({ default: "ViteHub App", mode: "build" }),
30
29
  },
30
+ server: {
31
+ airtableToken: env({ secret: true }),
32
+ },
31
33
  },
32
34
  })
33
35
  ```
34
36
 
35
37
  ```ts
36
- // nitro.config.ts
37
- import { env, envNitro } from "@vite-hub/env/nitro"
38
- import { defineNitroConfig } from "nitro/config"
38
+ // app/env.ts
39
+ import { publicEnv } from "#vitehub/env/public"
39
40
 
40
- export default defineNitroConfig({
41
- modules: [envNitro()],
42
- env: {
43
- auth: {
44
- token: env({ secret: true }),
45
- },
46
- },
47
- })
41
+ export const appName = publicEnv.appName
48
42
  ```
49
43
 
50
44
  ```ts
51
- // server/api/config.get.ts
45
+ // server/sync.ts
52
46
  import { useServerEnv } from "#vitehub/env/server"
53
- import { defineEventHandler } from "h3"
54
47
 
55
- export default defineEventHandler((event) => {
56
- const env = useServerEnv(event)
48
+ export async function sync(event: unknown) {
49
+ const { airtableToken } = useServerEnv(event)
50
+
51
+ await fetch("https://api.airtable.com/v0/app/table", {
52
+ headers: { Authorization: `Bearer ${airtableToken.unseal()}` },
53
+ })
54
+ }
55
+ ```
56
+
57
+ ## Structured errors
58
+
59
+ ViteHub-owned Env resolution failures use the shared `ViteHubError` contract with Env-specific codes. Custom source resolvers keep application-owned errors unchanged, so callers can preserve their own error contract without translating it through ViteHub.
57
60
 
58
- return {
59
- hasAuthToken: Boolean(env.auth.token.unseal()),
61
+ ```ts
62
+ import { getViteHubErrorShape } from "@vite-hub/runtime"
63
+
64
+ try {
65
+ await resolveVaultEnv()
66
+ }
67
+ catch (error) {
68
+ if (getViteHubErrorShape(error)?.code === "ENV_SOURCE_FAILED") {
69
+ console.error("Env source failed")
60
70
  }
61
- })
71
+ throw error
72
+ }
62
73
  ```
63
74
 
64
- ## Vite and Nitro
75
+ Each `EnvErrorCode` owns a fixed public message and a bounded details shape. Source details use stable identifiers such as `git:branch`, `package.json`, `env`, or `custom`; raw variable names, package paths, and provider diagnostics stay behind `cause`, which `toJSON()` omits. Cancellation and existing `ViteHubError` instances pass through unchanged. Invalid `env()` calls remain `TypeError`, and `parseSchema()` keeps the schema library's ordinary error boundary.
65
76
 
66
- Vite handles public/build env and generates `#vitehub/env/public`. Nitro handles server/runtime env, secret values, and `#vitehub/env/server`. Cloudflare secrets can be marked as required during Nitro setup.
77
+ ## Vite Integration
78
+
79
+ Use `hubEnv()` in Vite to resolve public/build env, generate `#vitehub/env/public` and `#vitehub/env/server`, and keep environment declarations close to the app config. Runtime secrets are read from the host environment at request time and are wrapped in `SecretEnv` until explicitly unsealed.
80
+
81
+ `hubEnv()` writes generated env runtime modules to `.vitehub/env/` and generated env types to `.vitehub/types/env.d.ts`. Add `.vitehub/types/**/*.d.ts` to your `tsconfig.json` include list when TypeScript should see app-specific Public Env and Server Env fields.
82
+
83
+ For hosts that do not consume Vite plugin aliases directly, compose the generated modules explicitly:
84
+
85
+ ```ts
86
+ import { createEnvImportAliases, createEnvTypeScriptPaths, hubEnv } from "@vite-hub/env/vite"
87
+
88
+ export default {
89
+ nitro: {
90
+ alias: createEnvImportAliases(),
91
+ },
92
+ typescript: {
93
+ tsConfig: {
94
+ compilerOptions: {
95
+ paths: createEnvTypeScriptPaths({ relativeTo: ".nuxt" }),
96
+ },
97
+ },
98
+ },
99
+ vite: {
100
+ plugins: [hubEnv()],
101
+ },
102
+ }
103
+ ```
67
104
 
68
105
  Learn more at [vitehub.dev](https://vitehub.dev).
@@ -1,13 +1,19 @@
1
- import { d as EnvSourceResolver, f as EnvVariableDeclaration, l as EnvSource, p as EnvVariableOptions } from "./types-DnbiD9KN.js";
1
+ import { c as EnvSource, d as EnvVariableDeclaration, f as EnvVariableOptions, u as EnvSourceResolver } from "./types-FcnPKias.js";
2
2
 
3
3
  //#region src/core/declarations.d.ts
4
4
  interface EnvNamespace {
5
5
  (options?: EnvVariableOptions): EnvVariableDeclaration;
6
+ buildTimestamp: () => EnvSource;
6
7
  custom: (label: string, resolver: EnvSourceResolver) => EnvSource;
7
8
  gitBranch: () => EnvSource;
8
9
  gitCommit: (options?: {
9
10
  short?: boolean;
10
11
  }) => EnvSource;
12
+ gitRef: () => EnvSource;
13
+ gitSha: (options?: {
14
+ short?: boolean;
15
+ }) => EnvSource;
16
+ gitTag: () => EnvSource;
11
17
  packageJson: (path: string) => EnvSource;
12
18
  source: (name: string | string[]) => EnvSource;
13
19
  variable: (options?: EnvVariableOptions) => EnvVariableDeclaration;
@@ -51,6 +51,35 @@ function gitCommit(options = {}) {
51
51
  short: options.short
52
52
  };
53
53
  }
54
+ function gitRef() {
55
+ return {
56
+ kind: "git-ref",
57
+ label: "git:ref",
58
+ serializable: true
59
+ };
60
+ }
61
+ function gitSha(options = {}) {
62
+ return {
63
+ kind: "git-sha",
64
+ label: "git:sha",
65
+ serializable: true,
66
+ short: options.short
67
+ };
68
+ }
69
+ function gitTag() {
70
+ return {
71
+ kind: "git-tag",
72
+ label: "git:tag",
73
+ serializable: true
74
+ };
75
+ }
76
+ function buildTimestamp() {
77
+ return {
78
+ kind: "build-timestamp",
79
+ label: "build:timestamp",
80
+ serializable: true
81
+ };
82
+ }
54
83
  function packageJson(path) {
55
84
  return {
56
85
  kind: "package-json",
@@ -85,9 +114,13 @@ function variable(options = {}) {
85
114
  return declaration;
86
115
  }
87
116
  const env = Object.assign(variable, {
117
+ buildTimestamp,
88
118
  custom,
89
119
  gitBranch,
90
120
  gitCommit,
121
+ gitRef,
122
+ gitSha,
123
+ gitTag,
91
124
  packageJson,
92
125
  source,
93
126
  variable
@@ -0,0 +1,112 @@
1
+ import { ViteHubError } from "@vite-hub/runtime";
2
+ //#region src/core/errors.ts
3
+ const envErrorMessages = {
4
+ ENV_DECLARATION_INVALID: "[vitehub] Env declaration is invalid.",
5
+ ENV_REQUIRED_MISSING: "[vitehub] Required Env value is missing.",
6
+ ENV_RUNTIME_VALUE_INVALID: "[vitehub] Runtime Env value is invalid.",
7
+ ENV_SOURCE_FAILED: "[vitehub] Env source resolution failed."
8
+ };
9
+ const envSourceIdentifierSet = new Set([
10
+ "custom",
11
+ "env",
12
+ "git:branch",
13
+ "git:commit",
14
+ "git:ref",
15
+ "git:sha",
16
+ "git:tag",
17
+ "package.json"
18
+ ]);
19
+ function invalidOptions() {
20
+ throw new TypeError("[vitehub] Invalid Env error options.");
21
+ }
22
+ function own(value, key) {
23
+ if (typeof value !== "object" || value === null || Array.isArray(value)) invalidOptions();
24
+ try {
25
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
26
+ if (descriptor === void 0) return void 0;
27
+ if (!("value" in descriptor)) invalidOptions();
28
+ return descriptor.value;
29
+ } catch {
30
+ invalidOptions();
31
+ }
32
+ }
33
+ function createEnvError(options) {
34
+ const code = own(options, "code");
35
+ if (typeof code !== "string" || !Object.hasOwn(envErrorMessages, code)) invalidOptions();
36
+ const cause = own(options, "cause");
37
+ const details = normalizeDetails(code, own(options, "details"));
38
+ return new ViteHubError(code, envErrorMessages[code], {
39
+ ...cause === void 0 ? {} : { cause },
40
+ ...details === void 0 ? {} : { details }
41
+ });
42
+ }
43
+ function invalidEnvDeclaration(path, diagnostic) {
44
+ return createEnvError({
45
+ cause: new TypeError(diagnostic),
46
+ code: "ENV_DECLARATION_INVALID",
47
+ details: optionalPath(path)
48
+ });
49
+ }
50
+ function missingRequiredEnv(source, diagnostic, path) {
51
+ const pathDetails = optionalPath(path);
52
+ return createEnvError({
53
+ cause: new Error(diagnostic),
54
+ code: "ENV_REQUIRED_MISSING",
55
+ details: {
56
+ ...pathDetails,
57
+ source: publicSourceIdentifier(source)
58
+ }
59
+ });
60
+ }
61
+ function invalidRuntimeEnvValue(source, diagnostic) {
62
+ return createEnvError({
63
+ cause: new TypeError(diagnostic),
64
+ code: "ENV_RUNTIME_VALUE_INVALID",
65
+ details: { source: publicSourceIdentifier(source) }
66
+ });
67
+ }
68
+ function envSourceFailed(source, cause) {
69
+ return createEnvError({
70
+ cause,
71
+ code: "ENV_SOURCE_FAILED",
72
+ details: { source: publicSourceIdentifier(source) }
73
+ });
74
+ }
75
+ function isAbortError(value) {
76
+ if ((typeof value !== "object" || value === null) && typeof value !== "function") return false;
77
+ try {
78
+ return value.name === "AbortError";
79
+ } catch {
80
+ return false;
81
+ }
82
+ }
83
+ function publicSourceIdentifier(source) {
84
+ if (envSourceIdentifierSet.has(source)) return source;
85
+ if (source.startsWith("env:")) return "env";
86
+ if (source.startsWith("package.json:")) return "package.json";
87
+ return "custom";
88
+ }
89
+ function normalizeDetails(code, details) {
90
+ if (details === void 0) return void 0;
91
+ if (typeof details !== "object" || details === null || Array.isArray(details)) invalidOptions();
92
+ const normalized = {};
93
+ if (code === "ENV_DECLARATION_INVALID" || code === "ENV_REQUIRED_MISSING") {
94
+ const path = safePath(own(details, "path"));
95
+ if (path) normalized.path = path;
96
+ }
97
+ if (code !== "ENV_DECLARATION_INVALID") {
98
+ const source = own(details, "source");
99
+ if (envSourceIdentifierSet.has(source)) normalized.source = source;
100
+ }
101
+ return Object.keys(normalized).length ? normalized : void 0;
102
+ }
103
+ function optionalPath(path) {
104
+ const normalized = safePath(path);
105
+ return normalized ? { path: normalized } : {};
106
+ }
107
+ function safePath(path) {
108
+ if (typeof path !== "string" || path.length > 256) return void 0;
109
+ return /^(?:env|runtime)(?:\.[A-Za-z_$][A-Za-z0-9_$-]{0,63}){0,8}$/.test(path) ? path : void 0;
110
+ }
111
+ //#endregion
112
+ export { missingRequiredEnv as a, isAbortError as i, invalidEnvDeclaration as n, invalidRuntimeEnvValue as r, envSourceFailed as t };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,36 @@
1
- import { _ as ServerEnv, a as EnvMode, c as EnvRuntimeRegistry, d as EnvSourceResolver, f as EnvVariableDeclaration, g as PublicEnv, h as EnvViteUserConfig, i as EnvIntegrationOptions, l as EnvSource, m as EnvViteConfigOptions, n as EnvDiagnosticEntry, o as EnvNitroConfigOptions, p as EnvVariableOptions, r as EnvDiagnostics, s as EnvNitroUserConfig, t as EnvConfigOptions, u as EnvSourceContext } from "./types-DnbiD9KN.js";
2
- import { t as env } from "./declarations-DIq2gG-8.js";
1
+ import { a as EnvMode, c as EnvSource, d as EnvVariableDeclaration, f as EnvVariableOptions, g as ServerEnv, h as PublicEnv, i as EnvIntegrationOptions, l as EnvSourceContext, m as EnvViteUserConfig, n as EnvDiagnosticEntry, o as EnvRuntimeConfigOptions, p as EnvViteConfigOptions, r as EnvDiagnostics, s as EnvRuntimeRegistry, t as EnvConfigOptions, u as EnvSourceResolver } from "./types-FcnPKias.js";
2
+ import { t as env } from "./declarations-BIBfEwer.js";
3
3
  import { openWorkflowEnv } from "./presets.js";
4
4
  import { StandardSchemaV1, parseSchema } from "./schema.js";
5
5
  import { SecretEnv } from "./secret.js";
6
- export { type EnvConfigOptions, type EnvDiagnosticEntry, type EnvDiagnostics, type EnvIntegrationOptions, type EnvMode, type EnvNitroConfigOptions, type EnvNitroUserConfig, type EnvRuntimeRegistry, type EnvSource, type EnvSourceContext, type EnvSourceResolver, type EnvVariableDeclaration, type EnvVariableOptions, type EnvViteConfigOptions, type EnvViteUserConfig, type PublicEnv, SecretEnv, type ServerEnv, type StandardSchemaV1, env, openWorkflowEnv, parseSchema };
6
+ import { resolveServerEnv } from "./server.js";
7
+ import { ViteHubError } from "@vite-hub/runtime";
8
+
9
+ //#region src/core/errors.d.ts
10
+ declare const envErrorMessages: {
11
+ readonly ENV_DECLARATION_INVALID: "[vitehub] Env declaration is invalid.";
12
+ readonly ENV_REQUIRED_MISSING: "[vitehub] Required Env value is missing.";
13
+ readonly ENV_RUNTIME_VALUE_INVALID: "[vitehub] Runtime Env value is invalid.";
14
+ readonly ENV_SOURCE_FAILED: "[vitehub] Env source resolution failed.";
15
+ };
16
+ declare const envSourceIdentifiers: readonly ["custom", "env", "git:branch", "git:commit", "git:ref", "git:sha", "git:tag", "package.json"];
17
+ type EnvErrorCode = keyof typeof envErrorMessages;
18
+ type EnvSourceIdentifier = typeof envSourceIdentifiers[number];
19
+ interface EnvErrorDetailsByCode {
20
+ ENV_DECLARATION_INVALID: {
21
+ path?: string;
22
+ };
23
+ ENV_REQUIRED_MISSING: {
24
+ path?: string;
25
+ source?: EnvSourceIdentifier;
26
+ };
27
+ ENV_RUNTIME_VALUE_INVALID: {
28
+ source?: EnvSourceIdentifier;
29
+ };
30
+ ENV_SOURCE_FAILED: {
31
+ source?: EnvSourceIdentifier;
32
+ };
33
+ }
34
+ type EnvErrorDetails<TCode extends EnvErrorCode = EnvErrorCode> = EnvErrorDetailsByCode[TCode];
35
+ //#endregion
36
+ export { type EnvConfigOptions, type EnvDiagnosticEntry, type EnvDiagnostics, type EnvErrorCode, type EnvErrorDetails, type EnvIntegrationOptions, type EnvMode, type EnvRuntimeConfigOptions, type EnvRuntimeRegistry, type EnvSource, type EnvSourceContext, type EnvSourceIdentifier, type EnvSourceResolver, type EnvVariableDeclaration, type EnvVariableOptions, type EnvViteConfigOptions, type EnvViteUserConfig, type PublicEnv, SecretEnv, type ServerEnv, type StandardSchemaV1, env, openWorkflowEnv, parseSchema, resolveServerEnv };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
- import { n as env } from "./declarations-DgJVnQyx.js";
1
+ import { n as env } from "./declarations-Cy5XamUA.js";
2
2
  import { openWorkflowEnv } from "./presets.js";
3
3
  import { parseSchema } from "./schema.js";
4
4
  import { SecretEnv } from "./secret.js";
5
- export { SecretEnv, env, openWorkflowEnv, parseSchema };
5
+ import { t as resolveServerEnv } from "./server-B2Dp8Nc0.js";
6
+ export { SecretEnv, env, openWorkflowEnv, parseSchema, resolveServerEnv };
package/dist/presets.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { o as EnvNitroConfigOptions } from "./types-DnbiD9KN.js";
1
+ import { o as EnvRuntimeConfigOptions } from "./types-FcnPKias.js";
2
2
 
3
3
  //#region src/presets.d.ts
4
4
  interface OpenWorkflowEnvOptions {
@@ -6,6 +6,6 @@ interface OpenWorkflowEnvOptions {
6
6
  schema?: string;
7
7
  workerConcurrency?: string;
8
8
  }
9
- declare function openWorkflowEnv(options?: OpenWorkflowEnvOptions): EnvNitroConfigOptions;
9
+ declare function openWorkflowEnv(options?: OpenWorkflowEnvOptions): EnvRuntimeConfigOptions;
10
10
  //#endregion
11
11
  export { OpenWorkflowEnvOptions, openWorkflowEnv };
package/dist/presets.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as env } from "./declarations-DgJVnQyx.js";
1
+ import { n as env } from "./declarations-Cy5XamUA.js";
2
2
  //#region src/presets.ts
3
3
  function openWorkflowEnv(options = {}) {
4
4
  return {
@@ -0,0 +1,59 @@
1
+ import { SecretEnv } from "./secret.js";
2
+ import { a as missingRequiredEnv, r as invalidRuntimeEnvValue } from "./errors-RUmAFDJn.js";
3
+ import { AsyncLocalStorage } from "node:async_hooks";
4
+ const activeEnvStorage = new AsyncLocalStorage();
5
+ function getActiveCloudflareEnv() {
6
+ const scoped = activeEnvStorage.getStore();
7
+ return scoped ? scoped.env : globalThis.__env__;
8
+ }
9
+ function getCloudflareEnv(event) {
10
+ const target = event;
11
+ return target?.env || target?.context?.cloudflare?.env || target?.context?._platform?.cloudflare?.env || target?.req?.runtime?.cloudflare?.env || getActiveCloudflareEnv();
12
+ }
13
+ //#endregion
14
+ //#region src/server.ts
15
+ function isRecord(value) {
16
+ return typeof value === "object" && value !== null && !Array.isArray(value);
17
+ }
18
+ function isRuntimeLiteralEntry(value) {
19
+ return isRecord(value) && value.kind === "literal";
20
+ }
21
+ function isRuntimeEnvEntry(value) {
22
+ return isRecord(value) && isRecord(value.source) && typeof value.source.name === "string" && typeof value.required === "boolean" && typeof value.secret === "boolean";
23
+ }
24
+ function processEnv() {
25
+ return typeof process === "object" && process && process.env ? process.env : {};
26
+ }
27
+ function runtimeEnv(event) {
28
+ return {
29
+ ...processEnv(),
30
+ ...getCloudflareEnv(event)
31
+ };
32
+ }
33
+ function readRuntimeSource(entry, env) {
34
+ for (const name of entry.source.names || [entry.source.name]) if (Object.hasOwn(env, name) && typeof env[name] !== "undefined") return {
35
+ found: true,
36
+ value: env[name]
37
+ };
38
+ return { found: false };
39
+ }
40
+ function resolveRegistryValue(value, env) {
41
+ if (isRuntimeLiteralEntry(value)) return value.value;
42
+ if (isRuntimeEnvEntry(value)) {
43
+ const source = readRuntimeSource(value, env);
44
+ const resolved = source.found ? source.value : value.default;
45
+ if (typeof resolved === "undefined") {
46
+ if (value.required) throw missingRequiredEnv(value.source.label, `Missing Runtime Env from ${value.source.label}.`);
47
+ return;
48
+ }
49
+ if (typeof resolved !== "string") throw invalidRuntimeEnvValue(value.source.label, `Runtime Env from ${value.source.label} must resolve to a string.`);
50
+ return value.secret ? new SecretEnv(resolved) : resolved;
51
+ }
52
+ if (!isRecord(value)) return;
53
+ return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, resolveRegistryValue(child, env)]));
54
+ }
55
+ function resolveServerEnv(registry, event) {
56
+ return resolveRegistryValue(registry, runtimeEnv(event));
57
+ }
58
+ //#endregion
59
+ export { resolveServerEnv as t };
@@ -0,0 +1,6 @@
1
+ import { s as EnvRuntimeRegistry } from "./types-FcnPKias.js";
2
+
3
+ //#region src/server.d.ts
4
+ declare function resolveServerEnv<TServerEnv extends Record<string, unknown> = Record<string, unknown>>(registry: EnvRuntimeRegistry, event?: unknown): TServerEnv;
5
+ //#endregion
6
+ export { resolveServerEnv };
package/dist/server.js ADDED
@@ -0,0 +1,3 @@
1
+ import "./secret.js";
2
+ import { t as resolveServerEnv } from "./server-B2Dp8Nc0.js";
3
+ export { resolveServerEnv };
@@ -4,14 +4,28 @@ type EnvMode = "build" | "runtime";
4
4
  interface EnvIntegrationOptions {
5
5
  diagnostics?: EnvDiagnostics;
6
6
  prefix?: string;
7
+ projectRoot?: string;
8
+ runtimeImports?: EnvRuntimeImportSpecifiers;
9
+ }
10
+ interface EnvRuntimeImportSpecifiers {
11
+ secret?: string;
12
+ server?: string;
7
13
  }
8
14
  interface EnvSourceContext {
15
+ build: {
16
+ timestamp: () => string;
17
+ };
9
18
  env: Record<string, string | undefined>;
10
19
  git: {
11
20
  branch: () => Promise<string>;
12
21
  commit: (options?: {
13
22
  short?: boolean;
14
23
  }) => Promise<string>;
24
+ ref: () => Promise<string>;
25
+ sha: (options?: {
26
+ short?: boolean;
27
+ }) => Promise<string>;
28
+ tag: () => Promise<string | undefined>;
15
29
  };
16
30
  mode: EnvMode;
17
31
  packageJson: () => Promise<Record<string, unknown>>;
@@ -38,6 +52,23 @@ type EnvSource = {
38
52
  label: "git:commit";
39
53
  serializable: true;
40
54
  short?: boolean;
55
+ } | {
56
+ kind: "git-ref";
57
+ label: "git:ref";
58
+ serializable: true;
59
+ } | {
60
+ kind: "git-sha";
61
+ label: "git:sha";
62
+ serializable: true;
63
+ short?: boolean;
64
+ } | {
65
+ kind: "git-tag";
66
+ label: "git:tag";
67
+ serializable: true;
68
+ } | {
69
+ kind: "build-timestamp";
70
+ label: "build:timestamp";
71
+ serializable: true;
41
72
  } | {
42
73
  kind: "package-json";
43
74
  label: string;
@@ -64,22 +95,25 @@ interface EnvVariableOptions {
64
95
  source?: EnvSource | EnvSourceResolver;
65
96
  type?: string;
66
97
  }
98
+ type EnvBuildStaticValue = null | string | number | boolean | EnvBuildStaticValue[];
99
+ type EnvBuildConfigValue = EnvBuildConfigOptions | EnvBuildStaticValue | EnvVariableDeclaration;
100
+ interface EnvBuildConfigOptions {
101
+ [key: string]: EnvBuildConfigValue;
102
+ }
67
103
  interface EnvViteConfigOptions {
68
- define?: Record<string, EnvVariableDeclaration>;
104
+ define?: Record<string, EnvBuildConfigValue>;
69
105
  public?: Record<string, EnvVariableDeclaration>;
106
+ server?: EnvRuntimeConfigOptions;
70
107
  }
71
- type EnvNitroStaticValue = null | string | number | boolean | EnvNitroStaticValue[];
72
- type EnvNitroConfigValue = EnvNitroConfigOptions | EnvNitroStaticValue | EnvVariableDeclaration;
73
- interface EnvNitroConfigOptions {
74
- [key: string]: EnvNitroConfigValue;
108
+ type EnvRuntimeStaticValue = null | string | number | boolean | EnvRuntimeStaticValue[];
109
+ type EnvRuntimeConfigValue = EnvRuntimeConfigOptions | EnvRuntimeStaticValue | EnvVariableDeclaration;
110
+ interface EnvRuntimeConfigOptions {
111
+ [key: string]: EnvRuntimeConfigValue;
75
112
  }
76
- type EnvConfigOptions = EnvViteConfigOptions | EnvNitroConfigOptions;
113
+ type EnvConfigOptions = EnvViteConfigOptions;
77
114
  interface EnvViteUserConfig {
78
115
  env?: EnvViteConfigOptions;
79
116
  }
80
- interface EnvNitroUserConfig {
81
- env?: EnvNitroConfigOptions;
82
- }
83
117
  interface EnvDiagnosticEntry {
84
118
  exposed: string;
85
119
  key: string;
@@ -105,7 +139,7 @@ interface EnvRuntimeSchema {
105
139
  }
106
140
  interface EnvRuntimeLiteralEntry {
107
141
  kind: "literal";
108
- value: EnvNitroStaticValue;
142
+ value: EnvRuntimeStaticValue;
109
143
  }
110
144
  type EnvRuntimeRegistryValue = EnvRegistryEntry | EnvRuntimeLiteralEntry | EnvRuntimeRegistry;
111
145
  interface EnvRuntimeRegistry {
@@ -116,4 +150,4 @@ interface ServerEnv {
116
150
  }
117
151
  type PublicEnv = Record<string, unknown>;
118
152
  //#endregion
119
- export { ServerEnv as _, EnvMode as a, EnvRuntimeRegistry as c, EnvSourceResolver as d, EnvVariableDeclaration as f, PublicEnv as g, EnvViteUserConfig as h, EnvIntegrationOptions as i, EnvSource as l, EnvViteConfigOptions as m, EnvDiagnosticEntry as n, EnvNitroConfigOptions as o, EnvVariableOptions as p, EnvDiagnostics as r, EnvNitroUserConfig as s, EnvConfigOptions as t, EnvSourceContext as u };
153
+ export { EnvMode as a, EnvSource as c, EnvVariableDeclaration as d, EnvVariableOptions as f, ServerEnv as g, PublicEnv as h, EnvIntegrationOptions as i, EnvSourceContext as l, EnvViteUserConfig as m, EnvDiagnosticEntry as n, EnvRuntimeConfigOptions as o, EnvViteConfigOptions as p, EnvDiagnostics as r, EnvRuntimeRegistry as s, EnvConfigOptions as t, EnvSourceResolver as u };
package/dist/virtual.d.ts CHANGED
@@ -4,4 +4,12 @@ declare module "#vitehub/env/public" {
4
4
  export function usePublicEnv(): PublicEnv
5
5
  }
6
6
 
7
+ declare module "#vitehub/env/server" {
8
+ import type { SecretEnv } from "@vite-hub/env/secret"
9
+
10
+ export interface ServerEnv extends Record<string, unknown> {}
11
+ export function useServerEnv(event?: unknown): ServerEnv
12
+ export function runWithServerEnv<T>(event: unknown, callback: (env: ServerEnv) => T | Promise<T>): Promise<T>
13
+ }
14
+
7
15
  export {}
package/dist/vite.d.ts CHANGED
@@ -1,21 +1,33 @@
1
- import { i as EnvIntegrationOptions, m as EnvViteConfigOptions } from "./types-DnbiD9KN.js";
2
- import { t as env } from "./declarations-DIq2gG-8.js";
1
+ import { i as EnvIntegrationOptions, p as EnvViteConfigOptions, s as EnvRuntimeRegistry } from "./types-FcnPKias.js";
2
+ import { t as env } from "./declarations-BIBfEwer.js";
3
3
  import { Plugin } from "vite";
4
4
 
5
+ //#region ../internal/src/build/vite.d.ts
6
+ declare const VITEHUB_ENV_PUBLIC_ID: "#vitehub/env/public";
7
+ declare const VITEHUB_ENV_SERVER_ID: "#vitehub/env/server";
8
+ //#endregion
5
9
  //#region src/vite.d.ts
6
10
  declare const ENV_VITE_PLUGIN_NAME = "@vite-hub/env/vite";
7
- declare const ENV_PUBLIC_ID = "#vitehub/env/public";
11
+ declare const ENV_PUBLIC_ID: typeof VITEHUB_ENV_PUBLIC_ID;
12
+ declare const ENV_SERVER_ID: typeof VITEHUB_ENV_SERVER_ID;
8
13
  interface EnvVitePluginAPI {
9
14
  getPublicEnv: () => Record<string, unknown>;
15
+ getServerEnvRegistry: () => EnvRuntimeRegistry;
10
16
  }
11
17
  type EnvVitePlugin = Plugin & {
12
18
  api: EnvVitePluginAPI;
13
19
  };
14
- declare function envVite(options?: EnvIntegrationOptions): EnvVitePlugin;
20
+ interface EnvGeneratedPathOptions {
21
+ projectRoot?: string;
22
+ relativeTo?: string;
23
+ }
24
+ declare function createEnvImportAliases(options?: EnvGeneratedPathOptions): Record<string, string>;
25
+ declare function createEnvTypeScriptPaths(options?: EnvGeneratedPathOptions): Record<string, string[]>;
26
+ declare function hubEnv(options?: EnvIntegrationOptions): EnvVitePlugin;
15
27
  declare module "vite" {
16
28
  interface UserConfig {
17
29
  env?: EnvViteConfigOptions;
18
30
  }
19
31
  }
20
32
  //#endregion
21
- export { ENV_PUBLIC_ID, ENV_VITE_PLUGIN_NAME, EnvVitePlugin, EnvVitePluginAPI, env, envVite };
33
+ export { ENV_PUBLIC_ID, ENV_SERVER_ID, ENV_VITE_PLUGIN_NAME, EnvGeneratedPathOptions, EnvVitePlugin, EnvVitePluginAPI, createEnvImportAliases, createEnvTypeScriptPaths, env, hubEnv };