@vite-hub/env 0.1.0 → 0.3.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.
Files changed (61) hide show
  1. package/README.md +178 -33
  2. package/dist/{access-B3qzBHye.js → access-B8lSDip4.js} +1 -1
  3. package/dist/{bridge-CdNdTN1V.d.ts → bridge-Cs9YfQWk.d.ts} +111 -38
  4. package/dist/{bridge-error-CFuU5zIz.js → bridge-error-BhJ77age.js} +14 -13
  5. package/dist/bridge.d.ts +2 -2
  6. package/dist/bridge.js +168 -6
  7. package/dist/cli-BPp7rdcA.d.ts +159 -0
  8. package/dist/{cli-CMQPQbii.js → cli-DLpY0QAo.js} +212 -30
  9. package/dist/cli.d.ts +2 -2
  10. package/dist/cli.js +1 -1
  11. package/dist/database.d.ts +29 -3
  12. package/dist/database.js +106 -15
  13. package/dist/declarations-C5XR3aKw.d.ts +58 -0
  14. package/dist/error-diagnostics-B8RFjQ1V.js +56 -0
  15. package/dist/index.d.ts +145 -10
  16. package/dist/index.js +240 -7
  17. package/dist/internal/agent.d.ts +1 -1
  18. package/dist/internal/agent.js +2 -2
  19. package/dist/internal/connections.d.ts +1 -1
  20. package/dist/internal/connections.js +2 -2
  21. package/dist/internal/server.d.ts +3 -0
  22. package/dist/internal/server.js +2 -0
  23. package/dist/object-_dlsZ4lP.js +276 -0
  24. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  25. package/dist/operations-X1w--wds.js +30 -0
  26. package/dist/operations.d.ts +37 -0
  27. package/dist/operations.js +833 -0
  28. package/dist/runtime/public-env.d.ts +5 -0
  29. package/dist/runtime/public-env.js +8 -0
  30. package/dist/runtime/server-env.d.ts +22 -0
  31. package/dist/runtime/server-env.js +35 -0
  32. package/dist/schema-DMZ1_yhY.js +360 -0
  33. package/dist/seal.d.ts +8 -5
  34. package/dist/seal.js +9 -6
  35. package/dist/{secret.js → secret-DJd-fy5T.js} +1 -1
  36. package/dist/server-ChNL_Xc3.js +1279 -0
  37. package/dist/server-Dd8bjIKd.d.ts +145 -0
  38. package/dist/server.d.ts +3 -25
  39. package/dist/server.js +2 -2
  40. package/dist/virtual-module.d.ts +6 -6
  41. package/dist/vite.d.ts +59 -14
  42. package/dist/vite.js +304 -115
  43. package/package.json +27 -38
  44. package/dist/auth.d.ts +0 -32
  45. package/dist/auth.js +0 -44
  46. package/dist/cli-DEwcUIe0.d.ts +0 -81
  47. package/dist/declarations-CiRdb1qP.d.ts +0 -32
  48. package/dist/declarations-DAVgctKD.js +0 -236
  49. package/dist/error-diagnostics-CrxjYNYr.js +0 -43
  50. package/dist/http.d.ts +0 -2
  51. package/dist/http.js +0 -122
  52. package/dist/presets.d.ts +0 -20
  53. package/dist/presets.js +0 -44
  54. package/dist/provider.d.ts +0 -5
  55. package/dist/provider.js +0 -8
  56. package/dist/schema.d.ts +0 -15
  57. package/dist/schema.js +0 -55
  58. package/dist/secret-C2191nAa.d.ts +0 -11
  59. package/dist/secret.d.ts +0 -2
  60. package/dist/server-DufVswRJ.js +0 -670
  61. package/dist/values-D_r6V774.js +0 -148
package/dist/http.js DELETED
@@ -1,122 +0,0 @@
1
- import { n as envBridgeErrorBody, r as sanitizeEnvBridgeError, t as envBridgeError } from "./bridge-error-CFuU5zIz.js";
2
- //#region src/http.ts
3
- function record(value) {
4
- return value !== null && typeof value === "object" && !Array.isArray(value);
5
- }
6
- function actor(value) {
7
- if (!record(value) || typeof value.id !== "string" || value.kind !== "user" && value.kind !== "agent" && value.kind !== "service") throw envBridgeError("invalid");
8
- return {
9
- id: value.id,
10
- kind: value.kind
11
- };
12
- }
13
- const permissions = [
14
- "inspect",
15
- "preview",
16
- "replace",
17
- "use"
18
- ];
19
- async function body(request) {
20
- const reader = request.body?.getReader();
21
- if (!reader) throw envBridgeError("invalid");
22
- const decoder = new TextDecoder();
23
- let size = 0;
24
- let text = "";
25
- try {
26
- while (true) {
27
- const chunk = await reader.read();
28
- if (chunk.done) break;
29
- size += chunk.value.byteLength;
30
- if (size > 65536) {
31
- await reader.cancel();
32
- throw envBridgeError("invalid");
33
- }
34
- text += decoder.decode(chunk.value, { stream: true });
35
- }
36
- const value = JSON.parse(text + decoder.decode());
37
- if (!record(value)) throw envBridgeError("invalid");
38
- return value;
39
- } catch {
40
- throw envBridgeError("invalid");
41
- } finally {
42
- reader.releaseLock();
43
- }
44
- }
45
- function response(value, status = 200) {
46
- return Response.json(value, {
47
- status,
48
- headers: {
49
- "cache-control": "no-store",
50
- "x-content-type-options": "nosniff",
51
- "x-robots-tag": "noindex, nofollow"
52
- }
53
- });
54
- }
55
- /** Mount only on a server route. resolve selects declared credentials, never arbitrary store keys. */
56
- function createEnvBridgeHandler(resolve) {
57
- return async (request) => {
58
- if (request.method !== "POST") return response({ message: "Method not allowed." }, 405);
59
- const origin = request.headers.get("origin");
60
- if (origin ? origin !== new URL(request.url).origin : !/^Bearer\s+\S+$/i.test(request.headers.get("authorization") ?? "")) return response({ message: "Request origin is not allowed." }, 403);
61
- try {
62
- const input = await body(request);
63
- if (typeof input.path !== "string" || input.path.length > 256) throw envBridgeError("invalid");
64
- const target = resolve(input.path);
65
- if (!target) return response({ message: "This variable is not managed." }, 404);
66
- const context = await target.management.authenticate(request);
67
- if (!context) return response({ message: "Authentication required." }, 401);
68
- const { bridge } = target.management;
69
- const key = target.key;
70
- switch (input.action) {
71
- case "permissions": return response({
72
- permissions: await bridge.permissions(context, key),
73
- admin: Boolean(context.admin && !context.scope)
74
- });
75
- case "inspect": return response({
76
- metadata: await bridge.inspect(context, key) ?? null,
77
- permissions: await bridge.permissions(context, key),
78
- admin: Boolean(context.admin && !context.scope)
79
- });
80
- case "preview": {
81
- const metadata = await bridge.preview(context, key);
82
- return response({ metadata: metadata ? { preview: metadata.preview } : null });
83
- }
84
- case "replace": {
85
- if (typeof input.value !== "string" || !(input.expectedRevision === null || typeof input.expectedRevision === "string")) throw envBridgeError("invalid");
86
- const result = await bridge.replace(context, {
87
- key,
88
- value: input.value,
89
- expectedRevision: input.expectedRevision
90
- });
91
- return response({
92
- revision: result.revision,
93
- updatedAt: result.updatedAt,
94
- activation: result.activation
95
- });
96
- }
97
- case "activity":
98
- if (input.before !== void 0 && typeof input.before !== "string") throw envBridgeError("invalid");
99
- return response({ events: await bridge.activity(context, key, input.before) });
100
- case "grants": return response({ grants: await bridge.grants(context, key) });
101
- case "grant":
102
- if (!Array.isArray(input.permissions) || input.permissions.some((value) => !permissions.includes(value))) throw envBridgeError("invalid");
103
- await bridge.grant(context, {
104
- actor: actor(input.actor),
105
- key,
106
- permissions: input.permissions
107
- });
108
- return response({ ok: true });
109
- case "revoke":
110
- await bridge.revoke(context, actor(input.actor), key);
111
- return response({ ok: true });
112
- default: throw envBridgeError("invalid");
113
- }
114
- } catch (error) {
115
- const safe = sanitizeEnvBridgeError(error);
116
- const status = safe.code === "ENV_BRIDGE_DENIED" ? 403 : safe.code === "ENV_BRIDGE_CONFLICT" ? 409 : safe.code === "ENV_BRIDGE_INVALID" ? 400 : 503;
117
- return response(envBridgeErrorBody(safe), status);
118
- }
119
- };
120
- }
121
- //#endregion
122
- export { createEnvBridgeHandler };
package/dist/presets.d.ts DELETED
@@ -1,20 +0,0 @@
1
- import { w as EnvRuntimeConfigOptions } from "./bridge-CdNdTN1V.js";
2
- //#region src/presets.d.ts
3
- export interface OpenWorkflowEnvOptions {
4
- namespaceId?: string;
5
- schema?: string;
6
- workerConcurrency?: string;
7
- }
8
- export declare function openWorkflowEnv(options?: OpenWorkflowEnvOptions): EnvRuntimeConfigOptions;
9
- export interface TypesafeEnvOptions {
10
- /** Default model when `TYPESAFE_DEFAULT_MODEL` is not set. Default: `jev-latest`. */
11
- model?: string;
12
- }
13
- /**
14
- * Declares the Server Env of the `typesafe()` AI gateway from `vite-hub/gateways`: Secret `apiKey`
15
- * (`TYPESAFE_API_KEY`) and `model` (`TYPESAFE_DEFAULT_MODEL`). `defineAgent({ driver: { ask } })`, `llmGate()`, and
16
- * `llmRoute()` use `typesafe()` when they get no other gateway. The values are optional here: Jev diagnoses a
17
- * missing key when it runs, so an application without AI still starts.
18
- */
19
- export declare function typesafeEnv(options?: TypesafeEnvOptions): EnvRuntimeConfigOptions;
20
- //#endregion
package/dist/presets.js DELETED
@@ -1,44 +0,0 @@
1
- import { n as env } from "./declarations-DAVgctKD.js";
2
- //#region src/presets.ts
3
- function openWorkflowEnv(options = {}) {
4
- return {
5
- namespaceId: env({
6
- default: options.namespaceId || "production",
7
- source: env.source("OPENWORKFLOW_NAMESPACE_ID")
8
- }),
9
- postgresUrl: env({
10
- optional: true,
11
- secret: true,
12
- source: env.source(["OPENWORKFLOW_POSTGRES_URL", "DATABASE_URL"])
13
- }),
14
- schema: env({
15
- default: options.schema || "openworkflow",
16
- source: env.source("OPENWORKFLOW_SCHEMA")
17
- }),
18
- workerConcurrency: env({
19
- default: options.workerConcurrency || "10",
20
- source: env.source("OPENWORKFLOW_WORKER_CONCURRENCY")
21
- })
22
- };
23
- }
24
- /**
25
- * Declares the Server Env of the `typesafe()` AI gateway from `vite-hub/gateways`: Secret `apiKey`
26
- * (`TYPESAFE_API_KEY`) and `model` (`TYPESAFE_DEFAULT_MODEL`). `defineAgent({ driver: { ask } })`, `llmGate()`, and
27
- * `llmRoute()` use `typesafe()` when they get no other gateway. The values are optional here: Jev diagnoses a
28
- * missing key when it runs, so an application without AI still starts.
29
- */
30
- function typesafeEnv(options = {}) {
31
- return {
32
- apiKey: env({
33
- optional: true,
34
- secret: true,
35
- source: env.source("TYPESAFE_API_KEY")
36
- }),
37
- model: env({
38
- default: options.model || "jev-latest",
39
- source: env.source("TYPESAFE_DEFAULT_MODEL")
40
- })
41
- };
42
- }
43
- //#endregion
44
- export { openWorkflowEnv, typesafeEnv };
@@ -1,5 +0,0 @@
1
- import { S as EnvProviderValues, b as EnvProvider, x as EnvProviderContext } from "./bridge-CdNdTN1V.js";
2
- //#region src/provider.d.ts
3
- export declare function defineEnvProvider<TEnv extends Record<string, unknown> = Record<string, unknown>, const TProvider extends EnvProvider<TEnv> = EnvProvider<TEnv>>(provider: TProvider): TProvider;
4
- //#endregion
5
- export type { EnvProvider, EnvProviderContext, EnvProviderValues };
package/dist/provider.js DELETED
@@ -1,8 +0,0 @@
1
- import { t as envErrorDiagnostics } from "./error-diagnostics-CrxjYNYr.js";
2
- //#region src/provider.ts
3
- function defineEnvProvider(provider) {
4
- if (typeof provider !== "object" || provider === null || Array.isArray(provider) || typeof provider.read !== "function") throw envErrorDiagnostics.ENV_R0013({ message: "[vitehub] defineEnvProvider() requires a provider with a read({ env, keys, signal }) method." });
5
- return provider;
6
- }
7
- //#endregion
8
- export { defineEnvProvider };
package/dist/schema.d.ts DELETED
@@ -1,15 +0,0 @@
1
- //#region src/schema.d.ts
2
- export interface StandardSchemaResultSuccess<T = unknown> {
3
- issues?: undefined;
4
- value: T;
5
- }
6
- export interface StandardSchemaResultFailure {
7
- issues: readonly unknown[];
8
- }
9
- export interface StandardSchemaV1<T = unknown> {
10
- "~standard": {
11
- validate: (input: unknown) => StandardSchemaResultSuccess<T> | StandardSchemaResultFailure | Promise<StandardSchemaResultSuccess<T> | StandardSchemaResultFailure>;
12
- };
13
- }
14
- export declare function parseSchema(schema: unknown, value: unknown, label: string): unknown;
15
- //#endregion
package/dist/schema.js DELETED
@@ -1,55 +0,0 @@
1
- import { t as envErrorDiagnostics } from "./error-diagnostics-CrxjYNYr.js";
2
- //#region src/schema.ts
3
- function parseSchema(schema, value, label) {
4
- if (isStandardSchema(schema)) {
5
- const result = schema["~standard"].validate(value);
6
- if (isPromiseLike(result)) throw envErrorDiagnostics.ENV_R0014({ message: `[vitehub] ${label} uses an async schema. Env validation currently requires sync schemas.` });
7
- if ("issues" in result && result.issues && result.issues.length > 0) throw envErrorDiagnostics.ENV_R0015({ message: `[vitehub] Invalid ${label}: ${formatIssues(result.issues)}` });
8
- if (!("value" in result)) throw envErrorDiagnostics.ENV_R0016({ message: `[vitehub] Invalid ${label}: ${formatIssues(result.issues)}` });
9
- return result.value;
10
- }
11
- if (isZodLike(schema) && hasSchemaMethod(schema, "safeParse") && typeof schema.safeParse === "function") {
12
- const result = schema.safeParse(value);
13
- if (!result.success) throw envErrorDiagnostics.ENV_R0017({ message: `[vitehub] Invalid ${label}: ${formatIssues(result.error)}` });
14
- return result.data;
15
- }
16
- if (isZodLike(schema) && hasSchemaMethod(schema, "parse") && typeof schema.parse === "function") try {
17
- return schema.parse(value);
18
- } catch (error) {
19
- throw envErrorDiagnostics.ENV_R0018({ message: `[vitehub] Invalid ${label}: ${formatIssues(error)}` });
20
- }
21
- return value;
22
- }
23
- function isPromiseLike(value) {
24
- return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
25
- }
26
- function isStandardSchema(schema) {
27
- return isZodLike(schema) && hasSchemaMethod(schema, "~standard") && typeof schema["~standard"]?.validate === "function";
28
- }
29
- function isZodLike(schema) {
30
- return typeof schema === "object" && schema !== null;
31
- }
32
- function hasSchemaMethod(schema, method) {
33
- return Object.hasOwn(schema, method) || isZodSchemaMethod(schema, method);
34
- }
35
- function isZodSchemaMethod(schema, method) {
36
- if (!Object.hasOwn(schema, "_zod")) return false;
37
- const metadata = schema._zod;
38
- if (!metadata) return false;
39
- const constructor = metadata?.constr;
40
- return hasSetValue(metadata?.traits, "ZodType") && Object.hasOwn(metadata, "constr") && typeof constructor === "function" && Object.getPrototypeOf(schema) === constructor.prototype && Object.hasOwn(constructor.prototype, method);
41
- }
42
- function hasSetValue(value, entry) {
43
- try {
44
- return Set.prototype.has.call(value, entry);
45
- } catch {
46
- return false;
47
- }
48
- }
49
- function formatIssues(issues) {
50
- if (Array.isArray(issues)) return issues.map((issue) => typeof issue === "string" ? issue : JSON.stringify(issue)).join("; ");
51
- if (issues instanceof Error) return issues.message;
52
- return typeof issues === "string" ? issues : JSON.stringify(issues);
53
- }
54
- //#endregion
55
- export { parseSchema };
@@ -1,11 +0,0 @@
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 DELETED
@@ -1,2 +0,0 @@
1
- import { t as SecretEnv } from "./secret-C2191nAa.js";
2
- export { SecretEnv };