@vite-hub/env 0.0.3 → 0.0.4

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -6,75 +6,168 @@
6
6
  <img alt="Vite" src="https://img.shields.io/badge/Vite-public%20env-646cff?style=flat-square">
7
7
  </p>
8
8
 
9
- `@vite-hub/env` declares environment values once, then generates typed public and server env access.
9
+ `@vite-hub/env` declares environment values once, then generates typed public and server-oriented access plus untyped build-time replacements for Vite applications.
10
+
11
+ Most applications install `vite-hub` and enable Env through the framework preset. Install this owner package directly when a library or focused Vite integration needs Env without the rest of ViteHub.
10
12
 
11
13
  ## Install
12
14
 
13
15
  ```sh
14
16
  pnpm add @vite-hub/env
17
+ pnpm add -D vite
15
18
  ```
16
19
 
17
- ## Minimal API
20
+ ## Choose an Env section
21
+
22
+ | Section | Read when | Visible to client code | Use it for |
23
+ | ------------ | ------------------------- | ---------------------- | --------------------------------------------------------------- |
24
+ | `env.public` | Build time | Yes | Browser-safe application configuration. |
25
+ | `env.define` | Build transform | Yes, where bundled | Untyped compile-time replacements such as a release identifier. |
26
+ | `env.server` | Request or server runtime | By caller convention | Host-supplied server configuration and source-only credentials. |
27
+
28
+ ## First result
18
29
 
19
30
  ```ts
20
31
  // vite.config.ts
21
- import { env, hubEnv } from "@vite-hub/env/vite"
22
- import { defineConfig } from "vite"
32
+ import { env, hubEnv } from "@vite-hub/env/vite";
33
+ import { defineConfig } from "vite";
23
34
 
24
35
  export default defineConfig({
25
- plugins: [hubEnv({ prefix: "VITEHUB_" })],
36
+ plugins: [hubEnv()],
26
37
  env: {
27
38
  public: {
28
39
  appName: env({ default: "ViteHub App", mode: "build" }),
29
40
  },
30
- server: {
31
- airtableToken: env({ secret: true }),
32
- },
33
41
  },
34
- })
42
+ });
35
43
  ```
36
44
 
37
45
  ```ts
38
46
  // app/env.ts
39
- import { publicEnv } from "#vitehub/env/public"
47
+ import { usePublicEnv } from "#vitehub/env/public";
40
48
 
41
- export const appName = publicEnv.appName
49
+ console.log(usePublicEnv().appName); // ViteHub App
50
+ ```
51
+
52
+ Run that file through the application's Vite dev or build pipeline. `hubEnv()` generates the stable `#vitehub/env/public` module and its field-level types; it is not a package import that plain Node resolves outside the configured application.
53
+
54
+ Add `.vitehub/types/**/*.d.ts` to the application's `tsconfig.json` `include` list when TypeScript should see the generated fields.
55
+
56
+ ## Read a server secret
57
+
58
+ Declare a secret under `env.server`, then read it only from server code:
59
+
60
+ ```ts
61
+ // vite.config.ts
62
+ import { env, hubEnv } from "@vite-hub/env/vite";
63
+ import { defineConfig } from "vite";
64
+
65
+ export default defineConfig({
66
+ plugins: [hubEnv()],
67
+ env: {
68
+ server: {
69
+ airtableToken: env({
70
+ secret: true,
71
+ source: env.source("AIRTABLE_TOKEN"),
72
+ }),
73
+ },
74
+ },
75
+ });
42
76
  ```
43
77
 
44
78
  ```ts
45
79
  // server/sync.ts
46
- import { useServerEnv } from "#vitehub/env/server"
80
+ import { useServerEnv } from "#vitehub/env/server";
47
81
 
48
82
  export async function sync(event: unknown) {
49
- const { airtableToken } = useServerEnv(event)
83
+ const { airtableToken } = useServerEnv(event);
50
84
 
51
85
  await fetch("https://api.airtable.com/v0/app/table", {
52
86
  headers: { Authorization: `Bearer ${airtableToken.unseal()}` },
53
- })
87
+ });
88
+ }
89
+ ```
90
+
91
+ ## External runtime values
92
+
93
+ Use a read-only Env provider when application credentials live outside the host environment. Keep the provider's bootstrap credential in Kubernetes, Cloudflare, or the current host, then load the external values as one operation-scoped snapshot.
94
+
95
+ ```ts
96
+ // vite.config.ts
97
+ import { env, hubEnv } from "@vite-hub/env/vite"
98
+
99
+ export default {
100
+ plugins: [hubEnv({
101
+ providers: { credentials: "./server/env/credentials.ts" },
102
+ })],
103
+ env: {
104
+ server: {
105
+ gatewayKey: env({ secret: true }),
106
+ githubToken: env({
107
+ secret: true,
108
+ source: env.provider("credentials", "github/token"),
109
+ }),
110
+ },
111
+ },
54
112
  }
55
113
  ```
56
114
 
115
+ ```ts
116
+ // server/env/credentials.ts
117
+ import { defineEnvProvider } from "@vite-hub/env/provider"
118
+ import type { SecretEnv } from "@vite-hub/env/secret"
119
+
120
+ export default defineEnvProvider<{ gatewayKey: SecretEnv<string> }>({
121
+ async read({ env, keys, signal }) {
122
+ const response = await fetch("https://credentials.internal/env", {
123
+ headers: { authorization: `Bearer ${env.gatewayKey.unseal()}` },
124
+ signal,
125
+ })
126
+ const values = await response.json() as Record<string, string | undefined>
127
+ return Object.fromEntries(keys.map(key => [key, values[key]]))
128
+ },
129
+ })
130
+ ```
131
+
132
+ ```ts
133
+ import { loadServerEnv } from "#vitehub/env/server"
134
+
135
+ const snapshot = await loadServerEnv()
136
+ const githubToken = snapshot.githubToken.unseal()
137
+ ```
138
+
139
+ Each `loadServerEnv()` call batches requested keys once per provider and returns a fresh frozen snapshot. ViteHub does not cache across loads, so rotation appears on the next load. `useServerEnv()` stays synchronous for host-backed and literal values; provider-backed values require `loadServerEnv()` or `runWithServerEnv()`.
140
+
141
+ The generated `#vitehub/env/server` module is not blocked from client builds. Keep its imports in server-only entry points, and supply credentials through `env.source(...)` without literals or defaults; static values and defaults can be serialized into the generated module.
142
+
143
+ `SecretEnv` renders as `<redacted>` in string conversion, JSON, and Node inspection. Call `unseal()` only at the provider boundary that needs the raw value. Redaction is type friction, not complete leak prevention: never return, log, trace, or place an unsealed value in Agent input.
144
+
57
145
  ## Structured errors
58
146
 
59
147
  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.
60
148
 
149
+ Install the shared runtime package before inspecting structured errors:
150
+
151
+ ```sh
152
+ pnpm add @vite-hub/runtime
153
+ ```
154
+
61
155
  ```ts
62
- import { getViteHubErrorShape } from "@vite-hub/runtime"
156
+ import { getViteHubErrorShape } from "@vite-hub/runtime";
63
157
 
64
158
  try {
65
- await resolveVaultEnv()
66
- }
67
- catch (error) {
159
+ await resolveVaultEnv();
160
+ } catch (error) {
68
161
  if (getViteHubErrorShape(error)?.code === "ENV_SOURCE_FAILED") {
69
- console.error("Env source failed")
162
+ console.error("Env source failed");
70
163
  }
71
- throw error
164
+ throw error;
72
165
  }
73
166
  ```
74
167
 
75
168
  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.
76
169
 
77
- ## Vite Integration
170
+ ## Generated modules
78
171
 
79
172
  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
173
 
@@ -83,7 +176,7 @@ Use `hubEnv()` in Vite to resolve public/build env, generate `#vitehub/env/publi
83
176
  For hosts that do not consume Vite plugin aliases directly, compose the generated modules explicitly:
84
177
 
85
178
  ```ts
86
- import { createEnvImportAliases, createEnvTypeScriptPaths, hubEnv } from "@vite-hub/env/vite"
179
+ import { createEnvImportAliases, createEnvTypeScriptPaths, hubEnv } from "@vite-hub/env/vite";
87
180
 
88
181
  export default {
89
182
  nitro: {
@@ -99,7 +192,9 @@ export default {
99
192
  vite: {
100
193
  plugins: [hubEnv()],
101
194
  },
102
- }
195
+ };
103
196
  ```
104
197
 
105
- Learn more at [vitehub.dev](https://vitehub.dev).
198
+ Public Env and `env.define` values are compiled into client bundles. Never put credentials in either section. The host still owns secret storage and injection; Env owns declarations, resolution, generated accessors, validation, and default redaction.
199
+
200
+ Read the complete [Env guide](https://vitehub.dev/docs/server-primitives/env), the [host support matrix](https://vitehub.dev/docs/frameworks-hosts/support-matrix), and the project's [pre-1.0 security policy](https://github.com/vite-hub/vitehub/blob/main/SECURITY.md).
@@ -88,6 +88,17 @@ function packageJson(path) {
88
88
  serializable: true
89
89
  };
90
90
  }
91
+ function provider(provider, key) {
92
+ if (typeof provider !== "string" || !/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(provider.trim())) throw new TypeError("env.provider() requires a provider name that starts with a letter and contains only letters, numbers, underscores, or hyphens.");
93
+ if (typeof key !== "string" || !key.trim() || key.length > 512) throw new TypeError("env.provider() requires a non-empty provider key.");
94
+ return {
95
+ key: key.trim(),
96
+ kind: "provider",
97
+ label: "provider",
98
+ provider: provider.trim(),
99
+ serializable: true
100
+ };
101
+ }
91
102
  function variable(options = {}) {
92
103
  if (typeof options !== "object" || options === null || Array.isArray(options)) throw new TypeError("env() only accepts a single options object.");
93
104
  if (options.optional && typeof options.required !== "undefined") throw new TypeError("env() cannot use both optional and required.");
@@ -122,11 +133,15 @@ const env = Object.assign(variable, {
122
133
  gitSha,
123
134
  gitTag,
124
135
  packageJson,
136
+ provider,
125
137
  source,
126
138
  variable
127
139
  });
128
140
  function isDefaultStringEnvVariable(declaration) {
129
- return defaultStringSchemas.get(declaration) === declaration.schema || declaration[defaultStringSchemaProperty] === defaultStringSchemaToken && typeof declaration.schema === "object" && declaration.schema !== null && declaration.schema[defaultStringSchemaProperty] === defaultStringSchemaToken && hasOnlyDefaultStringSchemaKeys(declaration.schema);
141
+ const declarationToken = Object.getOwnPropertyDescriptor(declaration, defaultStringSchemaProperty)?.value;
142
+ const schemaObject = typeof declaration.schema === "object" && declaration.schema !== null ? declaration.schema : void 0;
143
+ const schemaToken = schemaObject ? Object.getOwnPropertyDescriptor(schemaObject, defaultStringSchemaProperty)?.value : void 0;
144
+ return defaultStringSchemas.get(declaration) === declaration.schema || declarationToken === defaultStringSchemaToken && schemaToken === defaultStringSchemaToken && schemaObject !== void 0 && hasOnlyDefaultStringSchemaKeys(schemaObject);
130
145
  }
131
146
  function getDefaultStringSchemaToken() {
132
147
  const tokenKey = Symbol.for("vitehub.env.defaultRuntimeSchemaToken");
@@ -1,4 +1,4 @@
1
- import { c as EnvSource, d as EnvVariableDeclaration, f as EnvVariableOptions, u as EnvSourceResolver } from "./types-FcnPKias.js";
1
+ import { _ as EnvVariableOptions, g as EnvVariableDeclaration, h as EnvSourceResolver, p as EnvSource } from "./types-CsB6DTGE.js";
2
2
 
3
3
  //#region src/core/declarations.d.ts
4
4
  interface EnvNamespace {
@@ -15,6 +15,7 @@ interface EnvNamespace {
15
15
  }) => EnvSource;
16
16
  gitTag: () => EnvSource;
17
17
  packageJson: (path: string) => EnvSource;
18
+ provider: (provider: string, key: string) => EnvSource;
18
19
  source: (name: string | string[]) => EnvSource;
19
20
  variable: (options?: EnvVariableOptions) => EnvVariableDeclaration;
20
21
  }
@@ -2,6 +2,7 @@ import { ViteHubError } from "@vite-hub/runtime";
2
2
  //#region src/core/errors.ts
3
3
  const envErrorMessages = {
4
4
  ENV_DECLARATION_INVALID: "[vitehub] Env declaration is invalid.",
5
+ ENV_ASYNC_REQUIRED: "[vitehub] Server Env requires asynchronous loading.",
5
6
  ENV_REQUIRED_MISSING: "[vitehub] Required Env value is missing.",
6
7
  ENV_RUNTIME_VALUE_INVALID: "[vitehub] Runtime Env value is invalid.",
7
8
  ENV_SOURCE_FAILED: "[vitehub] Env source resolution failed."
@@ -14,7 +15,8 @@ const envSourceIdentifierSet = new Set([
14
15
  "git:ref",
15
16
  "git:sha",
16
17
  "git:tag",
17
- "package.json"
18
+ "package.json",
19
+ "provider"
18
20
  ]);
19
21
  function invalidOptions() {
20
22
  throw new TypeError("[vitehub] Invalid Env error options.");
@@ -47,6 +49,13 @@ function invalidEnvDeclaration(path, diagnostic) {
47
49
  details: optionalPath(path)
48
50
  });
49
51
  }
52
+ function asyncServerEnvRequired(path) {
53
+ return createEnvError({
54
+ cause: /* @__PURE__ */ new TypeError(`Server Env at ${path} uses env.provider(). Use loadServerEnv() or runWithServerEnv().`),
55
+ code: "ENV_ASYNC_REQUIRED",
56
+ details: optionalPath(path)
57
+ });
58
+ }
50
59
  function missingRequiredEnv(source, diagnostic, path) {
51
60
  const pathDetails = optionalPath(path);
52
61
  return createEnvError({
@@ -90,11 +99,11 @@ function normalizeDetails(code, details) {
90
99
  if (details === void 0) return void 0;
91
100
  if (typeof details !== "object" || details === null || Array.isArray(details)) invalidOptions();
92
101
  const normalized = {};
93
- if (code === "ENV_DECLARATION_INVALID" || code === "ENV_REQUIRED_MISSING") {
102
+ if (code === "ENV_ASYNC_REQUIRED" || code === "ENV_DECLARATION_INVALID" || code === "ENV_REQUIRED_MISSING") {
94
103
  const path = safePath(own(details, "path"));
95
104
  if (path) normalized.path = path;
96
105
  }
97
- if (code !== "ENV_DECLARATION_INVALID") {
106
+ if (code !== "ENV_ASYNC_REQUIRED" && code !== "ENV_DECLARATION_INVALID") {
98
107
  const source = own(details, "source");
99
108
  if (envSourceIdentifierSet.has(source)) normalized.source = source;
100
109
  }
@@ -109,4 +118,4 @@ function safePath(path) {
109
118
  return /^(?:env|runtime)(?:\.[A-Za-z_$][A-Za-z0-9_$-]{0,63}){0,8}$/.test(path) ? path : void 0;
110
119
  }
111
120
  //#endregion
112
- export { missingRequiredEnv as a, isAbortError as i, invalidEnvDeclaration as n, invalidRuntimeEnvValue as r, envSourceFailed as t };
121
+ export { isAbortError as a, invalidRuntimeEnvValue as i, envSourceFailed as n, missingRequiredEnv as o, invalidEnvDeclaration as r, asyncServerEnvRequired as t };
package/dist/index.d.ts CHANGED
@@ -1,22 +1,27 @@
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";
1
+ import { t as SecretEnv } from "./secret-C2191nAa.js";
2
+ import { C as ServerEnvInspection, S as ServerEnv, T as ServerEnvInspectionStatus, _ as EnvVariableOptions, a as EnvIntegrationOptions, b as LoadServerEnvOptions, c as EnvProviderContext, d as EnvRuntimeConfigOptions, f as EnvRuntimeRegistry, g as EnvVariableDeclaration, h as EnvSourceResolver, i as EnvDiagnostics, l as EnvProviderValues, m as EnvSourceContext, n as EnvConfigOptions, o as EnvMode, p as EnvSource, r as EnvDiagnosticEntry, s as EnvProvider, t as DeepReadonly, u as EnvProviders, v as EnvViteConfigOptions, w as ServerEnvInspectionEntry, x as PublicEnv, y as EnvViteUserConfig } from "./types-CsB6DTGE.js";
3
+ import { t as env } from "./declarations-U6P3rvxC.js";
3
4
  import { openWorkflowEnv } from "./presets.js";
4
5
  import { StandardSchemaV1, parseSchema } from "./schema.js";
5
- import { SecretEnv } from "./secret.js";
6
- import { resolveServerEnv } from "./server.js";
6
+ import { defineEnvProvider } from "./provider.js";
7
+ import { inspectServerEnv, loadServerEnv, resolveServerEnv } from "./server.js";
7
8
  import { ViteHubError } from "@vite-hub/runtime";
8
9
 
9
10
  //#region src/core/errors.d.ts
10
11
  declare const envErrorMessages: {
11
12
  readonly ENV_DECLARATION_INVALID: "[vitehub] Env declaration is invalid.";
13
+ readonly ENV_ASYNC_REQUIRED: "[vitehub] Server Env requires asynchronous loading.";
12
14
  readonly ENV_REQUIRED_MISSING: "[vitehub] Required Env value is missing.";
13
15
  readonly ENV_RUNTIME_VALUE_INVALID: "[vitehub] Runtime Env value is invalid.";
14
16
  readonly ENV_SOURCE_FAILED: "[vitehub] Env source resolution failed.";
15
17
  };
16
- declare const envSourceIdentifiers: readonly ["custom", "env", "git:branch", "git:commit", "git:ref", "git:sha", "git:tag", "package.json"];
18
+ declare const envSourceIdentifiers: readonly ["custom", "env", "git:branch", "git:commit", "git:ref", "git:sha", "git:tag", "package.json", "provider"];
17
19
  type EnvErrorCode = keyof typeof envErrorMessages;
18
20
  type EnvSourceIdentifier = typeof envSourceIdentifiers[number];
19
21
  interface EnvErrorDetailsByCode {
22
+ ENV_ASYNC_REQUIRED: {
23
+ path?: string;
24
+ };
20
25
  ENV_DECLARATION_INVALID: {
21
26
  path?: string;
22
27
  };
@@ -33,4 +38,4 @@ interface EnvErrorDetailsByCode {
33
38
  }
34
39
  type EnvErrorDetails<TCode extends EnvErrorCode = EnvErrorCode> = EnvErrorDetailsByCode[TCode];
35
40
  //#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 };
41
+ export { type DeepReadonly, type EnvConfigOptions, type EnvDiagnosticEntry, type EnvDiagnostics, type EnvErrorCode, type EnvErrorDetails, type EnvIntegrationOptions, type EnvMode, type EnvProvider, type EnvProviderContext, type EnvProviderValues, type EnvProviders, type EnvRuntimeConfigOptions, type EnvRuntimeRegistry, type EnvSource, type EnvSourceContext, type EnvSourceIdentifier, type EnvSourceResolver, type EnvVariableDeclaration, type EnvVariableOptions, type EnvViteConfigOptions, type EnvViteUserConfig, type LoadServerEnvOptions, type PublicEnv, SecretEnv, type ServerEnv, type ServerEnvInspection, type ServerEnvInspectionEntry, type ServerEnvInspectionStatus, type StandardSchemaV1, defineEnvProvider, env, inspectServerEnv, loadServerEnv, openWorkflowEnv, parseSchema, resolveServerEnv };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
- import { n as env } from "./declarations-Cy5XamUA.js";
1
+ import { n as env } from "./declarations-CoMmvRqH.js";
2
2
  import { openWorkflowEnv } from "./presets.js";
3
3
  import { parseSchema } from "./schema.js";
4
4
  import { SecretEnv } from "./secret.js";
5
- import { t as resolveServerEnv } from "./server-B2Dp8Nc0.js";
6
- export { SecretEnv, env, openWorkflowEnv, parseSchema, resolveServerEnv };
5
+ import { defineEnvProvider } from "./provider.js";
6
+ import { n as loadServerEnv, r as resolveServerEnv, t as inspectServerEnv } from "./server-C16sFc1E.js";
7
+ export { SecretEnv, defineEnvProvider, env, inspectServerEnv, loadServerEnv, openWorkflowEnv, parseSchema, resolveServerEnv };
package/dist/presets.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { o as EnvRuntimeConfigOptions } from "./types-FcnPKias.js";
1
+ import { d as EnvRuntimeConfigOptions } from "./types-CsB6DTGE.js";
2
2
 
3
3
  //#region src/presets.d.ts
4
4
  interface OpenWorkflowEnvOptions {
package/dist/presets.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as env } from "./declarations-Cy5XamUA.js";
1
+ import { n as env } from "./declarations-CoMmvRqH.js";
2
2
  //#region src/presets.ts
3
3
  function openWorkflowEnv(options = {}) {
4
4
  return {
@@ -0,0 +1,6 @@
1
+ import { c as EnvProviderContext, l as EnvProviderValues, s as EnvProvider } from "./types-CsB6DTGE.js";
2
+
3
+ //#region src/provider.d.ts
4
+ declare function defineEnvProvider<TEnv extends Record<string, unknown> = Record<string, unknown>, const TProvider extends EnvProvider<TEnv> = EnvProvider<TEnv>>(provider: TProvider): TProvider;
5
+ //#endregion
6
+ export { type EnvProvider, type EnvProviderContext, type EnvProviderValues, defineEnvProvider };
@@ -0,0 +1,7 @@
1
+ //#region src/provider.ts
2
+ function defineEnvProvider(provider) {
3
+ if (typeof provider !== "object" || provider === null || Array.isArray(provider) || typeof provider.read !== "function") throw new TypeError("[vitehub] defineEnvProvider() requires a provider with a read({ env, keys, signal }) method.");
4
+ return provider;
5
+ }
6
+ //#endregion
7
+ export { defineEnvProvider };
@@ -0,0 +1,11 @@
1
+ //#region src/secret.d.ts
2
+ declare class SecretEnv<T = string> {
3
+ #private;
4
+ constructor(value: T);
5
+ unseal(): T;
6
+ toString(): string;
7
+ toJSON(): string;
8
+ [Symbol.toPrimitive](): string;
9
+ }
10
+ //#endregion
11
+ export { SecretEnv as t };
package/dist/secret.d.ts CHANGED
@@ -1,11 +1,2 @@
1
- //#region src/secret.d.ts
2
- declare class SecretEnv<T = string> {
3
- #private;
4
- constructor(value: T);
5
- unseal(): T;
6
- toString(): string;
7
- toJSON(): string;
8
- [Symbol.toPrimitive](): string;
9
- }
10
- //#endregion
1
+ import { t as SecretEnv } from "./secret-C2191nAa.js";
11
2
  export { SecretEnv };