@vite-hub/env 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -5
- package/dist/access-B3qzBHye.js +54 -0
- package/dist/auth.d.ts +32 -0
- package/dist/auth.js +44 -0
- package/dist/bridge-CdNdTN1V.d.ts +374 -0
- package/dist/bridge-error-CFuU5zIz.js +65 -0
- package/dist/bridge.d.ts +2 -0
- package/dist/bridge.js +192 -0
- package/dist/cli-CMQPQbii.js +487 -0
- package/dist/cli-DEwcUIe0.d.ts +81 -0
- package/dist/cli.d.ts +41 -0
- package/dist/cli.js +2 -0
- package/dist/database.d.ts +21 -0
- package/dist/database.js +183 -0
- package/dist/declarations-CiRdb1qP.d.ts +32 -0
- package/dist/declarations-DAVgctKD.js +236 -0
- package/dist/error-diagnostics-CrxjYNYr.js +43 -0
- package/dist/http.d.ts +2 -0
- package/dist/http.js +122 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +4 -4
- package/dist/internal/agent.d.ts +5 -0
- package/dist/internal/agent.js +22 -0
- package/dist/internal/connections.d.ts +18 -0
- package/dist/internal/connections.js +31 -0
- package/dist/presets.d.ts +15 -6
- package/dist/presets.js +21 -2
- package/dist/provider.d.ts +3 -4
- package/dist/provider.js +2 -1
- package/dist/schema.d.ts +5 -6
- package/dist/schema.js +26 -8
- package/dist/seal.d.ts +14 -0
- package/dist/seal.js +49 -0
- package/dist/server-DufVswRJ.js +670 -0
- package/dist/server.d.ts +23 -6
- package/dist/server.js +2 -3
- package/dist/values-D_r6V774.js +148 -0
- package/dist/virtual-module.d.ts +7 -3
- package/dist/virtual.d.ts +1 -1
- package/dist/vite.d.ts +27 -14
- package/dist/vite.js +840 -273
- package/package.json +81 -17
- package/dist/declarations-CoMmvRqH.js +0 -159
- package/dist/declarations-U6P3rvxC.d.ts +0 -24
- package/dist/errors-C4Xcs6Fi.js +0 -121
- package/dist/server-C16sFc1E.js +0 -303
- package/dist/types-CsB6DTGE.d.ts +0 -190
package/dist/server.d.ts
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { B as ServerEnvInspection, C as EnvProviders, F as LoadServerEnvOptions, H as ServerEnvInspectionStatus, R as ServerEnvDescription, T as EnvRuntimeRegistry, V as ServerEnvInspectionEntry, m as DeepReadonly, t as EnvAccessContext } from "./bridge-CdNdTN1V.js";
|
|
3
2
|
//#region src/server.d.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Derives a 32-byte hex secret for one purpose from the root app secret, `VITEHUB_SECRET` (or `NUXT_APP_SECRET`).
|
|
5
|
+
* It uses HKDF-SHA256, so the result is stable while the root is unchanged and distinct for every purpose.
|
|
6
|
+
* Namespace the purpose to its owner, such as `my-module:session`. ViteHub reserves the `vitehub:` prefix.
|
|
7
|
+
* Throws `ENV_REQUIRED_MISSING` when no root secret is set, and `ENV_RUNTIME_VALUE_INVALID` when it is shorter than 32 characters.
|
|
8
|
+
*/
|
|
9
|
+
export declare function deriveSecret(purpose: string, event?: unknown, rootOverride?: string, generatedOverride?: boolean, rootEnvKey?: string): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Apps call `useServerEnv()` on hot paths, often once per listed row. The result is reused while every name the
|
|
12
|
+
* registry reads holds the same value, so a call does not copy the whole env and parse each declaration again. Each
|
|
13
|
+
* call still gets its own records.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveServerEnv<TServerEnv extends Record<string, unknown> = Record<string, unknown>>(registry: EnvRuntimeRegistry<TServerEnv>, event?: unknown): TServerEnv;
|
|
16
|
+
export declare function loadServerEnv<TServerEnv extends Record<string, unknown> = Record<string, unknown>>(registry: EnvRuntimeRegistry<TServerEnv>, event?: unknown, options?: LoadServerEnvOptions): Promise<DeepReadonly<TServerEnv>>;
|
|
17
|
+
/** Describe declarations without loading host values or calling providers. */
|
|
18
|
+
export declare function describeServerEnv(registry: EnvRuntimeRegistry): ServerEnvDescription;
|
|
19
|
+
/** Returns whether an inspection entry makes `loadServerEnv()` fail: invalid, provider error, or required and missing. */
|
|
20
|
+
export declare function isBlockingServerEnvEntry(entry: ServerEnvInspectionEntry): boolean;
|
|
21
|
+
export declare function inspectServerEnv(registry: EnvRuntimeRegistry, event?: unknown, options?: LoadServerEnvOptions): Promise<ServerEnvInspection>;
|
|
22
|
+
/** Limit management to safe, declared provider paths. Host variables stay read-only. */
|
|
23
|
+
export declare function createServerEnvManagement(registry: EnvRuntimeRegistry, providers: EnvProviders): (request: Request) => Promise<Response>;
|
|
7
24
|
//#endregion
|
|
8
|
-
export {
|
|
25
|
+
export type { EnvAccessContext, ServerEnvInspection, ServerEnvInspectionEntry, ServerEnvInspectionStatus };
|
package/dist/server.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
|
|
3
|
-
export { inspectServerEnv, loadServerEnv, resolveServerEnv };
|
|
1
|
+
import { a as isBlockingServerEnvEntry, i as inspectServerEnv, n as deriveSecret, o as loadServerEnv, r as describeServerEnv, s as resolveServerEnv, t as createServerEnvManagement } from "./server-DufVswRJ.js";
|
|
2
|
+
export { createServerEnvManagement, deriveSecret, describeServerEnv, inspectServerEnv, isBlockingServerEnvEntry, loadServerEnv, resolveServerEnv };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { hasRuntimeType } from "@vite-hub/runtime/internal/runtime-type";
|
|
2
|
+
//#region src/internal/runtime-type.ts
|
|
3
|
+
function isRuntimeRecord(value) {
|
|
4
|
+
return value !== null && hasRuntimeType(value, "object") && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/core/json-value.ts
|
|
8
|
+
/** JSON values accepted at the environment boundary, without prototype or internal keys. */
|
|
9
|
+
function isEnvSchemaValue(value, depth = 0) {
|
|
10
|
+
if (depth > 64) return false;
|
|
11
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
12
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
13
|
+
if (Array.isArray(value)) return value.every((item) => isEnvSchemaValue(item, depth + 1));
|
|
14
|
+
if (typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) return false;
|
|
15
|
+
return Object.entries(value).every(([key, item]) => ![
|
|
16
|
+
"__proto__",
|
|
17
|
+
"prototype",
|
|
18
|
+
"constructor",
|
|
19
|
+
"__envSchemaUnset"
|
|
20
|
+
].includes(key) && isEnvSchemaValue(item, depth + 1));
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/core/values.ts
|
|
24
|
+
const stringValueSchema = Object.freeze({ kind: "string" });
|
|
25
|
+
/** Parse one host, provider, or default value with a serializable Server Env value schema. */
|
|
26
|
+
function parseEnvValue(schema, input) {
|
|
27
|
+
switch (schema.kind) {
|
|
28
|
+
case "array":
|
|
29
|
+
case "object": {
|
|
30
|
+
let value = input;
|
|
31
|
+
if (typeof value === "string") try {
|
|
32
|
+
value = JSON.parse(value);
|
|
33
|
+
} catch {
|
|
34
|
+
return {
|
|
35
|
+
success: false,
|
|
36
|
+
message: "Expected valid JSON."
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return isEnvSchemaValue(value) && matchesJsonType(schema, value) ? {
|
|
40
|
+
data: typeof input === "string" ? value : structuredClone(value),
|
|
41
|
+
success: true
|
|
42
|
+
} : {
|
|
43
|
+
success: false,
|
|
44
|
+
message: "JSON value does not match the declared type."
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
case "string": return hasRuntimeType(input, "string") && (schema.minLength === void 0 || input.length >= schema.minLength) && (schema.maxLength === void 0 || input.length <= schema.maxLength) ? {
|
|
48
|
+
data: input,
|
|
49
|
+
success: true
|
|
50
|
+
} : {
|
|
51
|
+
message: schema.minLength === void 0 && schema.maxLength === void 0 ? "Expected a string." : "Expected a string within the declared length constraints.",
|
|
52
|
+
success: false
|
|
53
|
+
};
|
|
54
|
+
case "boolean": return parseBoolean(input);
|
|
55
|
+
case "number": return parseNumber(input, schema);
|
|
56
|
+
case "url": return parseUrl(input);
|
|
57
|
+
case "enum": return hasRuntimeType(input, "string") && schema.values.includes(input) ? {
|
|
58
|
+
data: input,
|
|
59
|
+
success: true
|
|
60
|
+
} : {
|
|
61
|
+
message: `Expected one of ${schema.values.map((value) => JSON.stringify(value)).join(", ")}.`,
|
|
62
|
+
success: false
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Return the TypeScript type that a value schema produces. */
|
|
67
|
+
function envValueTypeName(schema) {
|
|
68
|
+
switch (schema.kind) {
|
|
69
|
+
case "array": return `Array<${schema.items ? envValueTypeName(schema.items) : "unknown"}>`;
|
|
70
|
+
case "object": {
|
|
71
|
+
if (!schema.properties) return "Record<string, unknown>";
|
|
72
|
+
const properties = Object.entries(schema.properties);
|
|
73
|
+
return properties.length ? `{ ${properties.map(([key, property]) => `${JSON.stringify(key)}: ${envValueTypeName(property)}`).join("; ")} }` : "Record<string, never>";
|
|
74
|
+
}
|
|
75
|
+
case "enum": return schema.values.map((value) => JSON.stringify(value)).join(" | ");
|
|
76
|
+
case "url": return "string";
|
|
77
|
+
default: return schema.kind;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function parseBoolean(input) {
|
|
81
|
+
if (hasRuntimeType(input, "boolean")) return {
|
|
82
|
+
data: input,
|
|
83
|
+
success: true
|
|
84
|
+
};
|
|
85
|
+
const normalized = hasRuntimeType(input, "string") ? input.trim().toLowerCase() : void 0;
|
|
86
|
+
if (normalized === "true" || normalized === "1") return {
|
|
87
|
+
data: true,
|
|
88
|
+
success: true
|
|
89
|
+
};
|
|
90
|
+
if (normalized === "false" || normalized === "0") return {
|
|
91
|
+
data: false,
|
|
92
|
+
success: true
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
message: "Expected a boolean: true, false, 1, or 0.",
|
|
96
|
+
success: false
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function parseNumber(input, schema) {
|
|
100
|
+
if (schema.decimal && hasRuntimeType(input, "string") && !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(input.trim())) return {
|
|
101
|
+
message: "Expected a finite decimal number.",
|
|
102
|
+
success: false
|
|
103
|
+
};
|
|
104
|
+
const value = hasRuntimeType(input, "string") && input.trim() ? Number(input) : input;
|
|
105
|
+
if (!hasRuntimeType(value, "number") || !Number.isFinite(value)) return {
|
|
106
|
+
message: "Expected a finite number.",
|
|
107
|
+
success: false
|
|
108
|
+
};
|
|
109
|
+
if (schema.isInt && !Number.isSafeInteger(value) || schema.min !== void 0 && value < schema.min || schema.max !== void 0 && value > schema.max) return {
|
|
110
|
+
message: "Expected a number within the declared constraints.",
|
|
111
|
+
success: false
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
data: value,
|
|
115
|
+
success: true
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function parseUrl(input) {
|
|
119
|
+
if (hasRuntimeType(input, "string")) try {
|
|
120
|
+
if (new URL(input).protocol) return {
|
|
121
|
+
data: input,
|
|
122
|
+
success: true
|
|
123
|
+
};
|
|
124
|
+
} catch {}
|
|
125
|
+
return {
|
|
126
|
+
message: "Expected an absolute URL.",
|
|
127
|
+
success: false
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function matchesJsonType(schema, value) {
|
|
131
|
+
switch (schema.kind) {
|
|
132
|
+
case "array": return Array.isArray(value) && (!schema.items || value.every((item) => schema.items && matchesJsonType(schema.items, item)));
|
|
133
|
+
case "object": return value !== null && typeof value === "object" && !Array.isArray(value) && (!schema.properties || Object.keys(value).length === Object.keys(schema.properties).length && Object.entries(schema.properties).every(([key, property]) => Object.hasOwn(value, key) && matchesJsonType(property, Reflect.get(value, key))));
|
|
134
|
+
case "boolean": return typeof value === "boolean";
|
|
135
|
+
case "number": return typeof value === "number" && parseEnvValue(schema, value).success;
|
|
136
|
+
default: return typeof value === "string" && parseEnvValue(schema, value).success;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function schemaContainsEnum(schema) {
|
|
140
|
+
switch (schema.kind) {
|
|
141
|
+
case "enum": return true;
|
|
142
|
+
case "array": return !!schema.items && schemaContainsEnum(schema.items);
|
|
143
|
+
case "object": return Object.values(schema.properties ?? {}).some(schemaContainsEnum);
|
|
144
|
+
default: return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
export { isEnvSchemaValue as a, stringValueSchema as i, parseEnvValue as n, hasRuntimeType as o, schemaContainsEnum as r, isRuntimeRecord as s, envValueTypeName as t };
|
package/dist/virtual-module.d.ts
CHANGED
|
@@ -6,9 +6,13 @@ declare module "#vitehub/env/public" {
|
|
|
6
6
|
|
|
7
7
|
declare module "#vitehub/env/server" {
|
|
8
8
|
export interface ServerEnv extends Record<string, unknown> {}
|
|
9
|
+
export function manageServerEnv(request: Request): Promise<Response>
|
|
10
|
+
export function describeServerEnv(): import("@vite-hub/env").ServerEnvDescription
|
|
9
11
|
export interface ServerEnvInspectionEntry {
|
|
10
12
|
masked: boolean
|
|
11
13
|
path?: string
|
|
14
|
+
provider?: string
|
|
15
|
+
required: boolean
|
|
12
16
|
source: "env" | "literal" | "provider"
|
|
13
17
|
status: "available" | "defaulted" | "error" | "invalid" | "missing"
|
|
14
18
|
}
|
|
@@ -23,8 +27,8 @@ declare module "#vitehub/env/server" {
|
|
|
23
27
|
: T extends object
|
|
24
28
|
? { readonly [TKey in keyof T]: DeepReadonly<T[TKey]> }
|
|
25
29
|
: T
|
|
26
|
-
export function inspectServerEnv(event?: unknown, options?: { signal?: AbortSignal }): Promise<ServerEnvInspection>
|
|
27
|
-
export function loadServerEnv(event?: unknown, options?: { signal?: AbortSignal }): Promise<ReadonlyServerEnv>
|
|
30
|
+
export function inspectServerEnv(event?: unknown, options?: { signal?: AbortSignal; access?: import("@vite-hub/env/bridge").EnvAccessContext }): Promise<ServerEnvInspection>
|
|
31
|
+
export function loadServerEnv(event?: unknown, options?: { signal?: AbortSignal; access?: import("@vite-hub/env/bridge").EnvAccessContext }): Promise<ReadonlyServerEnv>
|
|
28
32
|
export function useServerEnv(event?: unknown): ServerEnv
|
|
29
|
-
export function runWithServerEnv<T>(event: unknown, callback: (env: ReadonlyServerEnv) => T | Promise<T>, options?: { signal?: AbortSignal }): Promise<T>
|
|
33
|
+
export function runWithServerEnv<T>(event: unknown, callback: (env: ReadonlyServerEnv) => T | Promise<T>, options?: { signal?: AbortSignal; access?: import("@vite-hub/env/bridge").EnvAccessContext }): Promise<T>
|
|
30
34
|
}
|
package/dist/virtual.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/// <reference path="./virtual-module.d.ts" />
|
|
2
|
-
export {
|
|
2
|
+
export {}
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { N as EnvViteConfigOptions, T as EnvRuntimeRegistry, v as EnvIntegrationOptions, w as EnvRuntimeConfigOptions } from "./bridge-CdNdTN1V.js";
|
|
2
|
+
import { n as ViteHubCliContributor } from "./cli-DEwcUIe0.js";
|
|
3
|
+
import { t as env } from "./declarations-CiRdb1qP.js";
|
|
3
4
|
import { Plugin, UserConfig } from "vite";
|
|
4
|
-
|
|
5
5
|
//#region ../internal/src/build/vite.d.ts
|
|
6
6
|
declare const VITEHUB_ENV_PUBLIC_ID: "#vitehub/env/public";
|
|
7
7
|
declare const VITEHUB_ENV_SERVER_ID: "#vitehub/env/server";
|
|
@@ -9,14 +9,23 @@ declare const VITEHUB_ENV_SERVER_ID: "#vitehub/env/server";
|
|
|
9
9
|
//#region src/core/resolve.d.ts
|
|
10
10
|
declare function createRuntimeRegistry(declarations: EnvRuntimeConfigOptions | undefined, options?: {
|
|
11
11
|
path?: string;
|
|
12
|
-
prefix?: string;
|
|
12
|
+
prefix?: string | false;
|
|
13
13
|
}): EnvRuntimeRegistry;
|
|
14
14
|
//#endregion
|
|
15
|
+
//#region src/env-schema/importer.d.ts
|
|
16
|
+
interface EnvSchemaOptions {
|
|
17
|
+
prefix?: string;
|
|
18
|
+
/** Exact schema key to output path. Only Server Env supports nested paths. */
|
|
19
|
+
paths?: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
/** Import a committed env-spec-v1 contract. Reads schema metadata, never developer env files. */
|
|
22
|
+
export declare function envSchema(file: string | URL, options?: EnvSchemaOptions): EnvViteConfigOptions;
|
|
23
|
+
//#endregion
|
|
15
24
|
//#region src/vite.d.ts
|
|
16
|
-
declare const ENV_VITE_PLUGIN_NAME = "@vite-hub/env/vite";
|
|
17
|
-
declare const ENV_PUBLIC_ID: typeof VITEHUB_ENV_PUBLIC_ID;
|
|
18
|
-
declare const ENV_SERVER_ID: typeof VITEHUB_ENV_SERVER_ID;
|
|
19
|
-
interface EnvVitePluginAPI {
|
|
25
|
+
export declare const ENV_VITE_PLUGIN_NAME = "@vite-hub/env/vite";
|
|
26
|
+
export declare const ENV_PUBLIC_ID: typeof VITEHUB_ENV_PUBLIC_ID;
|
|
27
|
+
export declare const ENV_SERVER_ID: typeof VITEHUB_ENV_SERVER_ID;
|
|
28
|
+
export interface EnvVitePluginAPI {
|
|
20
29
|
createServerEnvRegistry: (declarations: EnvRuntimeConfigOptions | undefined) => EnvRuntimeRegistry;
|
|
21
30
|
getPublicEnv: () => Record<string, unknown>;
|
|
22
31
|
getServerEnvRegistry: () => EnvRuntimeRegistry;
|
|
@@ -24,20 +33,24 @@ interface EnvVitePluginAPI {
|
|
|
24
33
|
prepareTypes: (config: EnvViteConfigOptions | undefined, viteRoot: string) => Promise<void>;
|
|
25
34
|
resolveProjectRoot: (viteRoot: string) => string;
|
|
26
35
|
}
|
|
27
|
-
type EnvVitePlugin = Plugin & {
|
|
36
|
+
export type EnvVitePlugin = Plugin & {
|
|
28
37
|
api: EnvVitePluginAPI;
|
|
38
|
+
/** Contributes `vitehub env inspect` and `vitehub env check`. */
|
|
39
|
+
vitehub: {
|
|
40
|
+
cli: () => ViteHubCliContributor;
|
|
41
|
+
};
|
|
29
42
|
};
|
|
30
|
-
interface EnvGeneratedPathOptions {
|
|
43
|
+
export interface EnvGeneratedPathOptions {
|
|
31
44
|
projectRoot?: string;
|
|
32
45
|
relativeTo?: string;
|
|
33
46
|
}
|
|
34
|
-
declare function createEnvImportAliases(options?: EnvGeneratedPathOptions): Record<string, string>;
|
|
35
|
-
declare function createEnvTypeScriptPaths(options?: EnvGeneratedPathOptions): Record<string, string[]>;
|
|
36
|
-
declare function hubEnv(options?: EnvIntegrationOptions): EnvVitePlugin;
|
|
47
|
+
export declare function createEnvImportAliases(options?: EnvGeneratedPathOptions): Record<string, string>;
|
|
48
|
+
export declare function createEnvTypeScriptPaths(options?: EnvGeneratedPathOptions): Record<string, string[]>;
|
|
49
|
+
export declare function hubEnv(options?: EnvIntegrationOptions): EnvVitePlugin;
|
|
37
50
|
declare module "vite" {
|
|
38
51
|
interface UserConfig {
|
|
39
52
|
env?: EnvViteConfigOptions;
|
|
40
53
|
}
|
|
41
54
|
}
|
|
42
55
|
//#endregion
|
|
43
|
-
export {
|
|
56
|
+
export { type EnvSchemaOptions, createRuntimeRegistry as createRuntimeEnvRegistry, env };
|