@arkenv/nextjs 1.0.0-alpha.10 → 1.0.0-alpha.12
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 +10 -1
- package/dist/arkenv-internal-QxkUlA5J.cjs +2 -0
- package/dist/arkenv-internal-QxkUlA5J.cjs.map +1 -0
- package/dist/arkenv-internal-Ws3srax6.js +2 -0
- package/dist/arkenv-internal-Ws3srax6.js.map +1 -0
- package/dist/auto-extend-CYzZnEvT.cjs +2 -0
- package/dist/auto-extend-CYzZnEvT.cjs.map +1 -0
- package/dist/auto-extend-DjiqIbgM.js +2 -0
- package/dist/auto-extend-DjiqIbgM.js.map +1 -0
- package/dist/client.cjs +1 -1
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +3 -3
- package/dist/client.d.ts +3 -3
- package/dist/client.js +1 -1
- package/dist/client.js.map +1 -1
- package/dist/config/index.cjs +1 -1
- package/dist/config/index.d.cts +2 -2
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +1 -1
- package/dist/config-Deut5Vf8.js +99 -0
- package/dist/config-Deut5Vf8.js.map +1 -0
- package/dist/config-Oq8dsEPM.cjs +99 -0
- package/dist/config-Oq8dsEPM.cjs.map +1 -0
- package/dist/empty-client-env.cjs +2 -0
- package/dist/empty-client-env.cjs.map +1 -0
- package/dist/empty-client-env.d.cts +10 -0
- package/dist/empty-client-env.d.cts.map +1 -0
- package/dist/empty-client-env.d.ts +10 -0
- package/dist/empty-client-env.d.ts.map +1 -0
- package/dist/empty-client-env.js +2 -0
- package/dist/empty-client-env.js.map +1 -0
- package/dist/{index-96RGPyfa.d.cts → index-BS1wAitS.d.cts} +91 -31
- package/dist/{index-96RGPyfa.d.cts.map → index-BS1wAitS.d.cts.map} +1 -1
- package/dist/{index-BFQlm61W.d.ts → index-CBjJM83X.d.ts} +54 -14
- package/dist/index-CBjJM83X.d.ts.map +1 -0
- package/dist/{index-bjEZwPUt.d.ts → index-Cq_qJ68V.d.ts} +91 -31
- package/dist/{index-bjEZwPUt.d.ts.map → index-Cq_qJ68V.d.ts.map} +1 -1
- package/dist/{index-CNzwVE5N.d.cts → index-RdYGBD_V.d.cts} +54 -14
- package/dist/index-RdYGBD_V.d.cts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +12 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/react-server.cjs +1 -1
- package/dist/react-server.cjs.map +1 -1
- package/dist/react-server.d.cts +11 -5
- package/dist/react-server.d.cts.map +1 -1
- package/dist/react-server.d.ts +12 -6
- package/dist/react-server.d.ts.map +1 -1
- package/dist/react-server.js +1 -1
- package/dist/react-server.js.map +1 -1
- package/dist/{script-7FFqInPq.d.ts → script-Cy9x6rp9.d.ts} +1 -1
- package/dist/{script-7FFqInPq.d.ts.map → script-Cy9x6rp9.d.ts.map} +1 -1
- package/dist/{script-D-MYC2Uf.cjs → script-DAdH4IEa.cjs} +2 -2
- package/dist/{script-D-MYC2Uf.cjs.map → script-DAdH4IEa.cjs.map} +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +24 -5
- package/dist/server.d.cts.map +1 -1
- package/dist/server.d.ts +24 -5
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/standard/client.cjs +1 -1
- package/dist/standard/client.cjs.map +1 -1
- package/dist/standard/client.d.cts +3 -3
- package/dist/standard/client.d.ts +3 -3
- package/dist/standard/client.js +1 -1
- package/dist/standard/client.js.map +1 -1
- package/dist/standard/config.cjs +1 -1
- package/dist/standard/config.cjs.map +1 -1
- package/dist/standard/config.d.cts +6 -5
- package/dist/standard/config.d.cts.map +1 -1
- package/dist/standard/config.d.ts +6 -5
- package/dist/standard/config.d.ts.map +1 -1
- package/dist/standard/config.js +1 -1
- package/dist/standard/config.js.map +1 -1
- package/dist/standard/index.cjs +1 -1
- package/dist/standard/index.cjs.map +1 -1
- package/dist/standard/index.d.cts +4 -4
- package/dist/standard/index.d.ts +4 -4
- package/dist/standard/index.js +1 -1
- package/dist/standard/index.js.map +1 -1
- package/dist/standard/server.cjs +1 -1
- package/dist/standard/server.cjs.map +1 -1
- package/dist/standard/server.d.cts +27 -7
- package/dist/standard/server.d.cts.map +1 -1
- package/dist/standard/server.d.ts +28 -7
- package/dist/standard/server.d.ts.map +1 -1
- package/dist/standard/server.js +1 -1
- package/dist/standard/server.js.map +1 -1
- package/dist/standard/shared.cjs +1 -1
- package/dist/standard/shared.cjs.map +1 -1
- package/dist/standard/shared.d.cts +2 -2
- package/dist/standard/shared.d.ts +2 -2
- package/dist/standard/shared.js +1 -1
- package/dist/standard/shared.js.map +1 -1
- package/dist/strict-client-env-CHDTZoLe.js +6 -0
- package/dist/strict-client-env-CHDTZoLe.js.map +1 -0
- package/dist/strict-client-env-MouPnkRr.cjs +6 -0
- package/dist/strict-client-env-MouPnkRr.cjs.map +1 -0
- package/dist/{types-BzMGTYWv.d.ts → types-BfMBbrMm.d.ts} +2 -2
- package/dist/{types-BzMGTYWv.d.ts.map → types-BfMBbrMm.d.ts.map} +1 -1
- package/dist/{types-44R9mgTa.d.cts → types-BlRHnQwj.d.cts} +2 -2
- package/dist/{types-44R9mgTa.d.cts.map → types-BlRHnQwj.d.cts.map} +1 -1
- package/package.json +12 -5
- package/dist/arkenv-internal-Cll5pV_F.cjs +0 -2
- package/dist/arkenv-internal-Cll5pV_F.cjs.map +0 -1
- package/dist/arkenv-internal-DEN5DTmX.js +0 -2
- package/dist/arkenv-internal-DEN5DTmX.js.map +0 -1
- package/dist/config-CStvXoN3.cjs +0 -93
- package/dist/config-CStvXoN3.cjs.map +0 -1
- package/dist/config-D2j45WDh.js +0 -93
- package/dist/config-D2j45WDh.js.map +0 -1
- package/dist/index-BFQlm61W.d.ts.map +0 -1
- package/dist/index-CNzwVE5N.d.cts.map +0 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ ArkEnv integration for Next.js. Provides a typesafe, zero-dependency (except pee
|
|
|
8
8
|
pnpm add @arkenv/nextjs @arkenv/core arktype
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
For Zod, Valibot, or other Standard Schema validators **without** ArkType, install `@arkenv/standard` instead of `@arkenv/core`/`arktype`, and use `@arkenv/nextjs/standard` (and `@arkenv/nextjs/standard/config` for `withArkEnv`). See the [Standard Schema docs](https://arkenv.
|
|
11
|
+
For Zod, Valibot, or other Standard Schema validators **without** ArkType, install `@arkenv/standard` instead of `@arkenv/core`/`arktype`, and use `@arkenv/nextjs/standard` (and `@arkenv/nextjs/standard/config` for `withArkEnv`). See the [Standard Schema docs](https://arkenv.js.org/docs/core-concepts/standard-schema).
|
|
12
12
|
|
|
13
13
|
## Setup & Codegen
|
|
14
14
|
|
|
@@ -32,6 +32,15 @@ const nextConfig: NextConfig = {
|
|
|
32
32
|
export default withArkEnv(nextConfig);
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
Function-form configs (sync or async) are supported:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
export default withArkEnv(async (phase, { defaultConfig }) => ({
|
|
39
|
+
...defaultConfig,
|
|
40
|
+
reactStrictMode: phase !== "phase-test",
|
|
41
|
+
}));
|
|
42
|
+
```
|
|
43
|
+
|
|
35
44
|
### 2. Define your schema in `env.ts`
|
|
36
45
|
|
|
37
46
|
Import `arkenv` from the generated `./generated/env.gen` file instead of the package:
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`./dist-Bof1Std7.cjs`);function t(e){return`Do not access server-only key '${e}' on the client since it will leak sensitive data (prevented by ArkEnv)`}const n=Symbol.for(`arkenv.extended_env`),r=Symbol.for(`arkenv.keys`),i=Symbol.for(`arkenv.server_only_keys`);let a=!1;function o(o,s,c,l,u){let d={},f={},p={},m=[],h={},g=!1;if(typeof s==`boolean`){process.env.NODE_ENV===`development`&&!a&&(a=!0,e.i(`Deprecated: The nested layout structure (specifying 'server', 'client', or 'shared' keys in arkenv) is deprecated and will be removed in the next major version. Please migrate to the flat layout. See guide: https://arkenv.js.org/docs/guides/frameworks/nextjs`));let t=o;d=t?.server||{},f=t?.client||{},p=t?.shared||{},m=t?.extends||[],h=t?.runtimeEnv||{},g=globalThis.__arkenv_force_server__===!0||!!s}else{let e=o||{},t=s||{};if(m=t.extends||[],h=t.runtimeEnv||{},g=globalThis.__arkenv_force_server__===!0||!!c?.isServer,c?.isShared)p=e;else if(c?.strictLayout===`client`)f=e;else if(c?.strictLayout===`server`)d=e;else{let n=t.exposeToClient||t.expose||t.shared||[];for(let t of Object.keys(e))n.includes(t)||t===`NODE_ENV`?p[t]=e[t]:t.startsWith(`NEXT_PUBLIC_`)?f[t]=e[t]:d[t]=e[t]}}let _={},v=new Set,y=new Set;for(let e of Object.keys(d))v.add(e),!(e in f)&&!(e in p)&&y.add(e);for(let e of Object.keys(f))v.add(e);for(let e of Object.keys(p))v.add(e);let b={};if(m&&Array.isArray(m)){for(let e of m)if(e&&(typeof e==`object`||typeof e==`function`)){let t=e[n];if(t){_={..._,...t};let n=e[r];if(n instanceof Set)for(let e of n)v.add(e);let a=e[i];if(a instanceof Set)for(let e of a)y.add(e)}else{for(let e of Object.keys(_))_[e]!==void 0&&(b[e]=_[e]);for(let e of Object.keys(h))h[e]!==void 0&&(b[e]=h[e]);if(g)for(let e of Object.keys(d))b[e]===void 0&&process.env[e]!==void 0&&(b[e]=process.env[e]);let t=l(e,{env:b,safe:!1});_={..._,...t};let n=u(e);for(let e of n)v.add(e),g&&!e.startsWith(`NEXT_PUBLIC_`)&&!c?.isShared&&y.add(e)}}}for(let e of Object.keys(f))y.delete(e);for(let e of Object.keys(p))y.delete(e);for(let e of Object.keys(f))if(!e.startsWith(`NEXT_PUBLIC_`))throw Error(`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${e}`);let x=[...Object.keys(f),...Object.keys(p)];for(let e of x)if(!(e in h))throw Error(`Missing key in runtimeEnv: ${e}. All client and shared environment variables must be explicitly destructured in runtimeEnv.`);for(let e of Object.keys(h))if(!v.has(e))throw Error(`Environment variable '${e}' is passed to runtimeEnv but is not defined in the schema.`);for(let e of Object.keys(_))_[e]!==void 0&&(b[e]=_[e]);let S=typeof globalThis<`u`?globalThis.__arkenv_env__:void 0;for(let e of Object.keys(h))h[e]!==void 0&&(b[e]=h[e]),S&&S[e]!==void 0&&(e.startsWith(`NEXT_PUBLIC_`)||e in f||e in p)&&(b[e]=S[e]);if(g)for(let e of Object.keys(d))b[e]===void 0&&process.env[e]!==void 0&&(b[e]=process.env[e]);let C=l(g?{...d,...f,...p}:{...f,...p},{env:b,safe:!1}),w={..._,...C};return new Proxy(w,{get(e,a,o){if(a===n)return e;if(a===r)return v;if(a===i)return y;if(typeof a==`symbol`)return Reflect.get(e,a,o);if(typeof a==`string`){if(y.has(a)&&!g)throw Error(t(a));if(!v.has(a)&&!(a in Object.prototype)&&!(a===`__esModule`||a===`$$typeof`||a===`toJSON`||a===`inspect`))throw Error(`Environment variable '${a}' is not defined in the schema.`)}return Reflect.get(e,a,o)}})}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return o}});
|
|
2
|
+
//# sourceMappingURL=arkenv-internal-QxkUlA5J.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arkenv-internal-QxkUlA5J.cjs","names":[],"sources":["../../internal/utils/dist/boundary-access-error.js","../src/arkenv-internal.ts"],"sourcesContent":["//#region src/utils/boundary-access-error.ts\n/**\n* `error.name` for the validation class {@link ArkEnvError}.\n*/\nconst ARKENV_ERROR_NAME = \"ArkEnvError\";\n/**\n* Build the message for a client read of a server-only env key.\n*\n* Native `Error` (name stays `\"Error\"`). Next.js taint voice\n* (`Do not … since it will leak`) plus a last-place breadcrumb\n* (`(prevented by ArkEnv)`) so agents can attribute the throw.\n* No trailing period. Shared across Next, Nuxt, Vite, and Bun —\n* \"on the client\", not \"Client Components\".\n*\n* @param key The server-only environment variable name\n* @returns The boundary access error message\n*/\nfunction boundaryAccessErrorMessage(key) {\n\treturn `Do not access server-only key '${key}' on the client since it will leak sensitive data (prevented by ArkEnv)`;\n}\n\n//#endregion\nexport { ARKENV_ERROR_NAME, boundaryAccessErrorMessage };\n//# sourceMappingURL=boundary-access-error.js.map","import { logBuildWarning } from \"@repo/log\";\nimport type { Dict, SchemaShape } from \"@repo/types\";\nimport { boundaryAccessErrorMessage } from \"@repo/utils/boundary-access-error\";\n\nexport const EXTENDED_ENV = Symbol.for(\"arkenv.extended_env\");\nexport const ENV_KEYS = Symbol.for(\"arkenv.keys\");\nexport const SERVER_ONLY_KEYS = Symbol.for(\"arkenv.server_only_keys\");\n\nexport type LegacyNestedSchema = {\n\tserver?: SchemaShape;\n\tclient?: SchemaShape;\n\tshared?: SchemaShape;\n\textends?: readonly unknown[];\n\truntimeEnv?: Dict<string>;\n};\n\nexport type FlatSchemaOptions = {\n\textends?: readonly unknown[];\n\truntimeEnv?: Dict<string>;\n\t/**\n\t * @deprecated Use `exposeToClient` instead.\n\t */\n\texpose?: readonly string[];\n\t/**\n\t * @deprecated Use `exposeToClient` instead.\n\t */\n\tshared?: readonly string[];\n\texposeToClient?: readonly string[];\n};\n\nlet hasWarnedLegacy = false;\n\n/**\n * Validate and wrap environment variables in a security proxy.\n *\n * @internal\n */\nexport function arkenvInternal(\n\tschemaOrOptions: SchemaShape | LegacyNestedSchema | null | undefined,\n\toptionsOrIsServer: FlatSchemaOptions | boolean | null | undefined,\n\tcontext:\n\t\t| {\n\t\t\t\tisServer: boolean;\n\t\t\t\tisShared?: boolean;\n\t\t\t\tstrictLayout?: \"client\" | \"server\";\n\t\t }\n\t\t| undefined,\n\t/**\n\t * The core arkenv validation function (either `@arkenv/core` or `@arkenv/standard`).\n\t */\n\tcoreArkenv: (schema: any, config?: any) => Record<string, unknown>,\n\t/**\n\t * Extracts the declared key names from a schema object.\n\t */\n\tgetSchemaKeysArg: (schema: SchemaShape) => string[],\n): unknown {\n\tlet server: SchemaShape = {};\n\tlet client: SchemaShape = {};\n\tlet shared: SchemaShape = {};\n\tlet extendsList: readonly unknown[] = [];\n\tlet runtimeEnv: Dict<string> = {};\n\tlet isServer = false;\n\n\tif (typeof optionsOrIsServer === \"boolean\") {\n\t\tif (process.env.NODE_ENV === \"development\" && !hasWarnedLegacy) {\n\t\t\thasWarnedLegacy = true;\n\t\t\tlogBuildWarning(\n\t\t\t\t\"Deprecated: The nested layout structure (specifying 'server', 'client', or 'shared' keys in arkenv) is deprecated and will be removed in the next major version. Please migrate to the flat layout. See guide: https://arkenv.js.org/docs/guides/frameworks/nextjs\",\n\t\t\t);\n\t\t}\n\t\t// Old nested schema behavior (backward compatible)\n\t\tconst legacySchema = schemaOrOptions as\n\t\t\t| LegacyNestedSchema\n\t\t\t| null\n\t\t\t| undefined;\n\t\tserver = (legacySchema?.server || {}) as SchemaShape;\n\t\tclient = (legacySchema?.client || {}) as SchemaShape;\n\t\tshared = (legacySchema?.shared || {}) as SchemaShape;\n\t\textendsList = legacySchema?.extends || [];\n\t\truntimeEnv = (legacySchema?.runtimeEnv || {}) as Dict<string>;\n\t\tisServer =\n\t\t\t(globalThis as any).__arkenv_force_server__ === true ||\n\t\t\t!!optionsOrIsServer;\n\t} else {\n\t\t// New flat schema behavior\n\t\tconst flatSchema = (schemaOrOptions || {}) as SchemaShape;\n\t\tconst options = optionsOrIsServer || {};\n\t\textendsList = options.extends || [];\n\t\truntimeEnv = (options.runtimeEnv || {}) as Dict<string>;\n\t\tisServer =\n\t\t\t(globalThis as any).__arkenv_force_server__ === true ||\n\t\t\t!!context?.isServer;\n\n\t\tif (context?.isShared) {\n\t\t\tshared = flatSchema;\n\t\t} else if (context?.strictLayout === \"client\") {\n\t\t\tclient = flatSchema;\n\t\t} else if (context?.strictLayout === \"server\") {\n\t\t\tserver = flatSchema;\n\t\t} else {\n\t\t\tconst exposedKeys =\n\t\t\t\toptions.exposeToClient || options.expose || options.shared || [];\n\t\t\tfor (const key of Object.keys(flatSchema)) {\n\t\t\t\t// NODE_ENV is implicitly shared as Next.js automatically inlines and replaces references to process.env.NODE_ENV in browser bundles.\n\t\t\t\t// See: https://nextjs.org/docs/app/guides/environment-variables\n\t\t\t\tif (exposedKeys.includes(key) || key === \"NODE_ENV\") {\n\t\t\t\t\tshared[key] = flatSchema[key];\n\t\t\t\t} else if (key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\t\t\tclient[key] = flatSchema[key];\n\t\t\t\t} else {\n\t\t\t\t\tserver[key] = flatSchema[key];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlet extendedEnvValues: Record<string, unknown> = {};\n\tconst allKeys = new Set<string>();\n\tconst serverOnlyKeys = new Set<string>();\n\n\t// Add local keys\n\tfor (const key of Object.keys(server)) {\n\t\tallKeys.add(key);\n\t\tif (!(key in client) && !(key in shared)) {\n\t\t\tserverOnlyKeys.add(key);\n\t\t}\n\t}\n\tfor (const key of Object.keys(client)) {\n\t\tallKeys.add(key);\n\t}\n\tfor (const key of Object.keys(shared)) {\n\t\tallKeys.add(key);\n\t}\n\n\t// Prepare combined environment for core validation\n\tconst combinedEnv: Record<string, unknown> = {};\n\n\t// Process extended environments\n\tif (extendsList && Array.isArray(extendsList)) {\n\t\tfor (const ext of extendsList) {\n\t\t\tif (ext && (typeof ext === \"object\" || typeof ext === \"function\")) {\n\t\t\t\tconst raw = (ext as Record<string | symbol, unknown>)[EXTENDED_ENV];\n\t\t\t\tif (raw) {\n\t\t\t\t\textendedEnvValues = {\n\t\t\t\t\t\t...extendedEnvValues,\n\t\t\t\t\t\t...(raw as Record<string, unknown>),\n\t\t\t\t\t};\n\n\t\t\t\t\tconst extKeys = (ext as Record<string | symbol, unknown>)[ENV_KEYS];\n\t\t\t\t\tif (extKeys instanceof Set) {\n\t\t\t\t\t\tfor (const key of extKeys) allKeys.add(key);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst extServerOnly = (ext as Record<string | symbol, unknown>)[\n\t\t\t\t\t\tSERVER_ONLY_KEYS\n\t\t\t\t\t];\n\t\t\t\t\tif (extServerOnly instanceof Set) {\n\t\t\t\t\t\tfor (const key of extServerOnly) serverOnlyKeys.add(key);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Prepare what we have so far for validating the extended schema\n\t\t\t\t\tfor (const key of Object.keys(extendedEnvValues)) {\n\t\t\t\t\t\tif (extendedEnvValues[key] !== undefined) {\n\t\t\t\t\t\t\tcombinedEnv[key] = extendedEnvValues[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (const key of Object.keys(runtimeEnv)) {\n\t\t\t\t\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\t\t\t\t\tcombinedEnv[key] = runtimeEnv[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (isServer) {\n\t\t\t\t\t\tfor (const key of Object.keys(server)) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tcombinedEnv[key] === undefined &&\n\t\t\t\t\t\t\t\tprocess.env[key] !== undefined\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcombinedEnv[key] = process.env[key];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst validated = coreArkenv(ext as SchemaShape, {\n\t\t\t\t\t\tenv: combinedEnv as Dict<string>,\n\t\t\t\t\t\tsafe: false,\n\t\t\t\t\t});\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...validated };\n\n\t\t\t\t\tconst extKeys = getSchemaKeysArg(ext);\n\t\t\t\t\tfor (const key of extKeys) {\n\t\t\t\t\t\tallKeys.add(key);\n\t\t\t\t\t\t// Only classify as server-only when running on the server and the key is not public.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tisServer &&\n\t\t\t\t\t\t\t!key.startsWith(\"NEXT_PUBLIC_\") &&\n\t\t\t\t\t\t\t!context?.isShared\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tserverOnlyKeys.add(key);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Remove keys from serverOnlyKeys if they are defined as client or shared locally\n\tfor (const key of Object.keys(client)) {\n\t\tserverOnlyKeys.delete(key);\n\t}\n\tfor (const key of Object.keys(shared)) {\n\t\tserverOnlyKeys.delete(key);\n\t}\n\n\t// Validate options\n\t// For client keys, check prefix\n\tfor (const key of Object.keys(client)) {\n\t\tif (!key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\tthrow new Error(\n\t\t\t\t`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${key}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check runtimeEnv has all local client and shared keys\n\tconst requiredKeys = [...Object.keys(client), ...Object.keys(shared)];\n\tfor (const key of requiredKeys) {\n\t\tif (!(key in runtimeEnv)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Missing key in runtimeEnv: ${key}. All client and shared environment variables must be explicitly destructured in runtimeEnv.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check runtimeEnv does not have any keys not defined in the schema (allKeys)\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (!allKeys.has(key)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Environment variable '${key}' is passed to runtimeEnv but is not defined in the schema.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Build final combinedEnv\n\tfor (const key of Object.keys(extendedEnvValues)) {\n\t\tif (extendedEnvValues[key] !== undefined) {\n\t\t\tcombinedEnv[key] = extendedEnvValues[key];\n\t\t}\n\t}\n\n\tconst globalEnv =\n\t\ttypeof globalThis !== \"undefined\"\n\t\t\t? (globalThis as any).__arkenv_env__\n\t\t\t: undefined;\n\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\tcombinedEnv[key] = runtimeEnv[key];\n\t\t}\n\t\tif (globalEnv && globalEnv[key] !== undefined) {\n\t\t\tif (key.startsWith(\"NEXT_PUBLIC_\") || key in client || key in shared) {\n\t\t\t\tcombinedEnv[key] = globalEnv[key];\n\t\t\t}\n\t\t}\n\t}\n\n\tif (isServer) {\n\t\t// Fallback server keys to process.env if omitted or undefined\n\t\tfor (const key of Object.keys(server)) {\n\t\t\tif (combinedEnv[key] === undefined && process.env[key] !== undefined) {\n\t\t\t\tcombinedEnv[key] = process.env[key];\n\t\t\t}\n\t\t}\n\t}\n\n\t// Select schema based on environment\n\tconst schema = isServer\n\t\t? { ...server, ...client, ...shared }\n\t\t: { ...client, ...shared };\n\n\t// Run core validation\n\tconst validated = coreArkenv(schema as SchemaShape, {\n\t\tenv: combinedEnv as Dict<string>,\n\t\tsafe: false,\n\t});\n\n\tconst mergedValidated = { ...extendedEnvValues, ...validated };\n\n\t// Return a Proxy wrapper\n\treturn new Proxy(mergedValidated, {\n\t\tget(target, prop, receiver) {\n\t\t\tif (prop === EXTENDED_ENV) {\n\t\t\t\treturn target;\n\t\t\t}\n\t\t\tif (prop === ENV_KEYS) {\n\t\t\t\treturn allKeys;\n\t\t\t}\n\t\t\tif (prop === SERVER_ONLY_KEYS) {\n\t\t\t\treturn serverOnlyKeys;\n\t\t\t}\n\n\t\t\t// Always allow symbol properties (Symbol.iterator, Symbol.toStringTag, etc.)\n\t\t\tif (typeof prop === \"symbol\") {\n\t\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t\t}\n\n\t\t\tif (typeof prop === \"string\") {\n\t\t\t\tif (serverOnlyKeys.has(prop) && !isServer) {\n\t\t\t\t\tthrow new Error(boundaryAccessErrorMessage(prop));\n\t\t\t\t}\n\n\t\t\t\t// Allow schema keys and standard Object prototype properties\n\t\t\t\tif (!allKeys.has(prop) && !(prop in Object.prototype)) {\n\t\t\t\t\t// Fallback for bundler/framework-specific properties that bypass the prototype\n\t\t\t\t\tconst isCommonKey =\n\t\t\t\t\t\tprop === \"__esModule\" ||\n\t\t\t\t\t\tprop === \"$$typeof\" ||\n\t\t\t\t\t\tprop === \"toJSON\" ||\n\t\t\t\t\t\tprop === \"inspect\";\n\n\t\t\t\t\tif (!isCommonKey) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Environment variable '${prop}' is not defined in the schema.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t},\n\t});\n}\n"],"mappings":"uCAiBA,SAAS,EAA2B,EAAK,CACxC,MAAO,kCAAkC,EAAI,yECd9C,MAAa,EAAe,OAAO,IAAI,sBAAsB,CAChD,EAAW,OAAO,IAAI,cAAc,CACpC,EAAmB,OAAO,IAAI,0BAA0B,CAwBrE,IAAI,EAAkB,GAOtB,SAAgB,EACf,EACA,EACA,EAUA,EAIA,EACU,CACV,IAAI,EAAsB,EAAE,CACxB,EAAsB,EAAE,CACxB,EAAsB,EAAE,CACxB,EAAkC,EAAE,CACpC,EAA2B,EAAE,CAC7B,EAAW,GAEf,GAAI,OAAO,GAAsB,UAAW,CACvC,QAAQ,IAAI,WAAa,eAAiB,CAAC,IAC9C,EAAkB,GAClB,EAAA,EACC,qQACA,EAGF,IAAM,EAAe,EAIrB,EAAU,GAAc,QAAU,EAAE,CACpC,EAAU,GAAc,QAAU,EAAE,CACpC,EAAU,GAAc,QAAU,EAAE,CACpC,EAAc,GAAc,SAAW,EAAE,CACzC,EAAc,GAAc,YAAc,EAAE,CAC5C,EACE,WAAmB,0BAA4B,IAChD,CAAC,CAAC,MACG,CAEN,IAAM,EAAc,GAAmB,EAAE,CACnC,EAAU,GAAqB,EAAE,CAOvC,GANA,EAAc,EAAQ,SAAW,EAAE,CACnC,EAAc,EAAQ,YAAc,EAAE,CACtC,EACE,WAAmB,0BAA4B,IAChD,CAAC,CAAC,GAA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a,EAAU,KAAS,IAAA,KAC/B,EAAI,WAAW,eAAe,EAAI,KAAO,GAAU,KAAO,KAC7D,EAAY,GAAO,EAAU,IAKhC,GAAI,MAEE,IAAM,KAAO,OAAO,KAAK,EAAO,CAChC,EAAY,KAAS,IAAA,IAAa,QAAQ,IAAI,KAAS,IAAA,KAC1D,EAAY,GAAO,QAAQ,IAAI,IAWlC,IAAM,EAAY,EALH,EACZ,CAAE,GAAG,EAAQ,GAAG,EAAQ,GAAG,EAAQ,CACnC,CAAE,GAAG,EAAQ,GAAG,EAAQ,CAGyB,CACnD,IAAK,EACL,KAAM,GACN,CAAC,CAEI,EAAkB,CAAE,GAAG,EAAmB,GAAG,EAAW,CAG9D,OAAO,IAAI,MAAM,EAAiB,CACjC,IAAI,EAAQ,EAAM,EAAU,CAC3B,GAAI,IAAS,EACZ,OAAO,EAER,GAAI,IAAS,EACZ,OAAO,EAER,GAAI,IAAS,EACZ,OAAO,EAIR,GAAI,OAAO,GAAS,SACnB,OAAO,QAAQ,IAAI,EAAQ,EAAM,EAAS,CAG3C,GAAI,OAAO,GAAS,SAAU,CAC7B,GAAI,EAAe,IAAI,EAAK,EAAI,CAAC,EAChC,MAAU,MAAM,EAA2B,EAAK,CAAC,CAIlD,GAAI,CAAC,EAAQ,IAAI,EAAK,EAAI,EAAE,KAAQ,OAAO,YAQtC,EALH,IAAS,cACT,IAAS,YACT,IAAS,UACT,IAAS,WAGT,MAAU,MACT,yBAAyB,EAAK,iCAC9B,CAIJ,OAAO,QAAQ,IAAI,EAAQ,EAAM,EAAS,EAE3C,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{i as e}from"./dist-DimRGXOV.js";function t(e){return`Do not access server-only key '${e}' on the client since it will leak sensitive data (prevented by ArkEnv)`}const n=Symbol.for(`arkenv.extended_env`),r=Symbol.for(`arkenv.keys`),i=Symbol.for(`arkenv.server_only_keys`);let a=!1;function o(o,s,c,l,u){let d={},f={},p={},m=[],h={},g=!1;if(typeof s==`boolean`){process.env.NODE_ENV===`development`&&!a&&(a=!0,e(`Deprecated: The nested layout structure (specifying 'server', 'client', or 'shared' keys in arkenv) is deprecated and will be removed in the next major version. Please migrate to the flat layout. See guide: https://arkenv.js.org/docs/guides/frameworks/nextjs`));let t=o;d=t?.server||{},f=t?.client||{},p=t?.shared||{},m=t?.extends||[],h=t?.runtimeEnv||{},g=globalThis.__arkenv_force_server__===!0||!!s}else{let e=o||{},t=s||{};if(m=t.extends||[],h=t.runtimeEnv||{},g=globalThis.__arkenv_force_server__===!0||!!c?.isServer,c?.isShared)p=e;else if(c?.strictLayout===`client`)f=e;else if(c?.strictLayout===`server`)d=e;else{let n=t.exposeToClient||t.expose||t.shared||[];for(let t of Object.keys(e))n.includes(t)||t===`NODE_ENV`?p[t]=e[t]:t.startsWith(`NEXT_PUBLIC_`)?f[t]=e[t]:d[t]=e[t]}}let _={},v=new Set,y=new Set;for(let e of Object.keys(d))v.add(e),!(e in f)&&!(e in p)&&y.add(e);for(let e of Object.keys(f))v.add(e);for(let e of Object.keys(p))v.add(e);let b={};if(m&&Array.isArray(m)){for(let e of m)if(e&&(typeof e==`object`||typeof e==`function`)){let t=e[n];if(t){_={..._,...t};let n=e[r];if(n instanceof Set)for(let e of n)v.add(e);let a=e[i];if(a instanceof Set)for(let e of a)y.add(e)}else{for(let e of Object.keys(_))_[e]!==void 0&&(b[e]=_[e]);for(let e of Object.keys(h))h[e]!==void 0&&(b[e]=h[e]);if(g)for(let e of Object.keys(d))b[e]===void 0&&process.env[e]!==void 0&&(b[e]=process.env[e]);let t=l(e,{env:b,safe:!1});_={..._,...t};let n=u(e);for(let e of n)v.add(e),g&&!e.startsWith(`NEXT_PUBLIC_`)&&!c?.isShared&&y.add(e)}}}for(let e of Object.keys(f))y.delete(e);for(let e of Object.keys(p))y.delete(e);for(let e of Object.keys(f))if(!e.startsWith(`NEXT_PUBLIC_`))throw Error(`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${e}`);let x=[...Object.keys(f),...Object.keys(p)];for(let e of x)if(!(e in h))throw Error(`Missing key in runtimeEnv: ${e}. All client and shared environment variables must be explicitly destructured in runtimeEnv.`);for(let e of Object.keys(h))if(!v.has(e))throw Error(`Environment variable '${e}' is passed to runtimeEnv but is not defined in the schema.`);for(let e of Object.keys(_))_[e]!==void 0&&(b[e]=_[e]);let S=typeof globalThis<`u`?globalThis.__arkenv_env__:void 0;for(let e of Object.keys(h))h[e]!==void 0&&(b[e]=h[e]),S&&S[e]!==void 0&&(e.startsWith(`NEXT_PUBLIC_`)||e in f||e in p)&&(b[e]=S[e]);if(g)for(let e of Object.keys(d))b[e]===void 0&&process.env[e]!==void 0&&(b[e]=process.env[e]);let C=l(g?{...d,...f,...p}:{...f,...p},{env:b,safe:!1}),w={..._,...C};return new Proxy(w,{get(e,a,o){if(a===n)return e;if(a===r)return v;if(a===i)return y;if(typeof a==`symbol`)return Reflect.get(e,a,o);if(typeof a==`string`){if(y.has(a)&&!g)throw Error(t(a));if(!v.has(a)&&!(a in Object.prototype)&&!(a===`__esModule`||a===`$$typeof`||a===`toJSON`||a===`inspect`))throw Error(`Environment variable '${a}' is not defined in the schema.`)}return Reflect.get(e,a,o)}})}export{o as t};
|
|
2
|
+
//# sourceMappingURL=arkenv-internal-Ws3srax6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arkenv-internal-Ws3srax6.js","names":[],"sources":["../../internal/utils/dist/boundary-access-error.js","../src/arkenv-internal.ts"],"sourcesContent":["//#region src/utils/boundary-access-error.ts\n/**\n* `error.name` for the validation class {@link ArkEnvError}.\n*/\nconst ARKENV_ERROR_NAME = \"ArkEnvError\";\n/**\n* Build the message for a client read of a server-only env key.\n*\n* Native `Error` (name stays `\"Error\"`). Next.js taint voice\n* (`Do not … since it will leak`) plus a last-place breadcrumb\n* (`(prevented by ArkEnv)`) so agents can attribute the throw.\n* No trailing period. Shared across Next, Nuxt, Vite, and Bun —\n* \"on the client\", not \"Client Components\".\n*\n* @param key The server-only environment variable name\n* @returns The boundary access error message\n*/\nfunction boundaryAccessErrorMessage(key) {\n\treturn `Do not access server-only key '${key}' on the client since it will leak sensitive data (prevented by ArkEnv)`;\n}\n\n//#endregion\nexport { ARKENV_ERROR_NAME, boundaryAccessErrorMessage };\n//# sourceMappingURL=boundary-access-error.js.map","import { logBuildWarning } from \"@repo/log\";\nimport type { Dict, SchemaShape } from \"@repo/types\";\nimport { boundaryAccessErrorMessage } from \"@repo/utils/boundary-access-error\";\n\nexport const EXTENDED_ENV = Symbol.for(\"arkenv.extended_env\");\nexport const ENV_KEYS = Symbol.for(\"arkenv.keys\");\nexport const SERVER_ONLY_KEYS = Symbol.for(\"arkenv.server_only_keys\");\n\nexport type LegacyNestedSchema = {\n\tserver?: SchemaShape;\n\tclient?: SchemaShape;\n\tshared?: SchemaShape;\n\textends?: readonly unknown[];\n\truntimeEnv?: Dict<string>;\n};\n\nexport type FlatSchemaOptions = {\n\textends?: readonly unknown[];\n\truntimeEnv?: Dict<string>;\n\t/**\n\t * @deprecated Use `exposeToClient` instead.\n\t */\n\texpose?: readonly string[];\n\t/**\n\t * @deprecated Use `exposeToClient` instead.\n\t */\n\tshared?: readonly string[];\n\texposeToClient?: readonly string[];\n};\n\nlet hasWarnedLegacy = false;\n\n/**\n * Validate and wrap environment variables in a security proxy.\n *\n * @internal\n */\nexport function arkenvInternal(\n\tschemaOrOptions: SchemaShape | LegacyNestedSchema | null | undefined,\n\toptionsOrIsServer: FlatSchemaOptions | boolean | null | undefined,\n\tcontext:\n\t\t| {\n\t\t\t\tisServer: boolean;\n\t\t\t\tisShared?: boolean;\n\t\t\t\tstrictLayout?: \"client\" | \"server\";\n\t\t }\n\t\t| undefined,\n\t/**\n\t * The core arkenv validation function (either `@arkenv/core` or `@arkenv/standard`).\n\t */\n\tcoreArkenv: (schema: any, config?: any) => Record<string, unknown>,\n\t/**\n\t * Extracts the declared key names from a schema object.\n\t */\n\tgetSchemaKeysArg: (schema: SchemaShape) => string[],\n): unknown {\n\tlet server: SchemaShape = {};\n\tlet client: SchemaShape = {};\n\tlet shared: SchemaShape = {};\n\tlet extendsList: readonly unknown[] = [];\n\tlet runtimeEnv: Dict<string> = {};\n\tlet isServer = false;\n\n\tif (typeof optionsOrIsServer === \"boolean\") {\n\t\tif (process.env.NODE_ENV === \"development\" && !hasWarnedLegacy) {\n\t\t\thasWarnedLegacy = true;\n\t\t\tlogBuildWarning(\n\t\t\t\t\"Deprecated: The nested layout structure (specifying 'server', 'client', or 'shared' keys in arkenv) is deprecated and will be removed in the next major version. Please migrate to the flat layout. See guide: https://arkenv.js.org/docs/guides/frameworks/nextjs\",\n\t\t\t);\n\t\t}\n\t\t// Old nested schema behavior (backward compatible)\n\t\tconst legacySchema = schemaOrOptions as\n\t\t\t| LegacyNestedSchema\n\t\t\t| null\n\t\t\t| undefined;\n\t\tserver = (legacySchema?.server || {}) as SchemaShape;\n\t\tclient = (legacySchema?.client || {}) as SchemaShape;\n\t\tshared = (legacySchema?.shared || {}) as SchemaShape;\n\t\textendsList = legacySchema?.extends || [];\n\t\truntimeEnv = (legacySchema?.runtimeEnv || {}) as Dict<string>;\n\t\tisServer =\n\t\t\t(globalThis as any).__arkenv_force_server__ === true ||\n\t\t\t!!optionsOrIsServer;\n\t} else {\n\t\t// New flat schema behavior\n\t\tconst flatSchema = (schemaOrOptions || {}) as SchemaShape;\n\t\tconst options = optionsOrIsServer || {};\n\t\textendsList = options.extends || [];\n\t\truntimeEnv = (options.runtimeEnv || {}) as Dict<string>;\n\t\tisServer =\n\t\t\t(globalThis as any).__arkenv_force_server__ === true ||\n\t\t\t!!context?.isServer;\n\n\t\tif (context?.isShared) {\n\t\t\tshared = flatSchema;\n\t\t} else if (context?.strictLayout === \"client\") {\n\t\t\tclient = flatSchema;\n\t\t} else if (context?.strictLayout === \"server\") {\n\t\t\tserver = flatSchema;\n\t\t} else {\n\t\t\tconst exposedKeys =\n\t\t\t\toptions.exposeToClient || options.expose || options.shared || [];\n\t\t\tfor (const key of Object.keys(flatSchema)) {\n\t\t\t\t// NODE_ENV is implicitly shared as Next.js automatically inlines and replaces references to process.env.NODE_ENV in browser bundles.\n\t\t\t\t// See: https://nextjs.org/docs/app/guides/environment-variables\n\t\t\t\tif (exposedKeys.includes(key) || key === \"NODE_ENV\") {\n\t\t\t\t\tshared[key] = flatSchema[key];\n\t\t\t\t} else if (key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\t\t\tclient[key] = flatSchema[key];\n\t\t\t\t} else {\n\t\t\t\t\tserver[key] = flatSchema[key];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlet extendedEnvValues: Record<string, unknown> = {};\n\tconst allKeys = new Set<string>();\n\tconst serverOnlyKeys = new Set<string>();\n\n\t// Add local keys\n\tfor (const key of Object.keys(server)) {\n\t\tallKeys.add(key);\n\t\tif (!(key in client) && !(key in shared)) {\n\t\t\tserverOnlyKeys.add(key);\n\t\t}\n\t}\n\tfor (const key of Object.keys(client)) {\n\t\tallKeys.add(key);\n\t}\n\tfor (const key of Object.keys(shared)) {\n\t\tallKeys.add(key);\n\t}\n\n\t// Prepare combined environment for core validation\n\tconst combinedEnv: Record<string, unknown> = {};\n\n\t// Process extended environments\n\tif (extendsList && Array.isArray(extendsList)) {\n\t\tfor (const ext of extendsList) {\n\t\t\tif (ext && (typeof ext === \"object\" || typeof ext === \"function\")) {\n\t\t\t\tconst raw = (ext as Record<string | symbol, unknown>)[EXTENDED_ENV];\n\t\t\t\tif (raw) {\n\t\t\t\t\textendedEnvValues = {\n\t\t\t\t\t\t...extendedEnvValues,\n\t\t\t\t\t\t...(raw as Record<string, unknown>),\n\t\t\t\t\t};\n\n\t\t\t\t\tconst extKeys = (ext as Record<string | symbol, unknown>)[ENV_KEYS];\n\t\t\t\t\tif (extKeys instanceof Set) {\n\t\t\t\t\t\tfor (const key of extKeys) allKeys.add(key);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst extServerOnly = (ext as Record<string | symbol, unknown>)[\n\t\t\t\t\t\tSERVER_ONLY_KEYS\n\t\t\t\t\t];\n\t\t\t\t\tif (extServerOnly instanceof Set) {\n\t\t\t\t\t\tfor (const key of extServerOnly) serverOnlyKeys.add(key);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Prepare what we have so far for validating the extended schema\n\t\t\t\t\tfor (const key of Object.keys(extendedEnvValues)) {\n\t\t\t\t\t\tif (extendedEnvValues[key] !== undefined) {\n\t\t\t\t\t\t\tcombinedEnv[key] = extendedEnvValues[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (const key of Object.keys(runtimeEnv)) {\n\t\t\t\t\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\t\t\t\t\tcombinedEnv[key] = runtimeEnv[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (isServer) {\n\t\t\t\t\t\tfor (const key of Object.keys(server)) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tcombinedEnv[key] === undefined &&\n\t\t\t\t\t\t\t\tprocess.env[key] !== undefined\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcombinedEnv[key] = process.env[key];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst validated = coreArkenv(ext as SchemaShape, {\n\t\t\t\t\t\tenv: combinedEnv as Dict<string>,\n\t\t\t\t\t\tsafe: false,\n\t\t\t\t\t});\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...validated };\n\n\t\t\t\t\tconst extKeys = getSchemaKeysArg(ext);\n\t\t\t\t\tfor (const key of extKeys) {\n\t\t\t\t\t\tallKeys.add(key);\n\t\t\t\t\t\t// Only classify as server-only when running on the server and the key is not public.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tisServer &&\n\t\t\t\t\t\t\t!key.startsWith(\"NEXT_PUBLIC_\") &&\n\t\t\t\t\t\t\t!context?.isShared\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tserverOnlyKeys.add(key);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Remove keys from serverOnlyKeys if they are defined as client or shared locally\n\tfor (const key of Object.keys(client)) {\n\t\tserverOnlyKeys.delete(key);\n\t}\n\tfor (const key of Object.keys(shared)) {\n\t\tserverOnlyKeys.delete(key);\n\t}\n\n\t// Validate options\n\t// For client keys, check prefix\n\tfor (const key of Object.keys(client)) {\n\t\tif (!key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\tthrow new Error(\n\t\t\t\t`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${key}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check runtimeEnv has all local client and shared keys\n\tconst requiredKeys = [...Object.keys(client), ...Object.keys(shared)];\n\tfor (const key of requiredKeys) {\n\t\tif (!(key in runtimeEnv)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Missing key in runtimeEnv: ${key}. All client and shared environment variables must be explicitly destructured in runtimeEnv.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check runtimeEnv does not have any keys not defined in the schema (allKeys)\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (!allKeys.has(key)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Environment variable '${key}' is passed to runtimeEnv but is not defined in the schema.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Build final combinedEnv\n\tfor (const key of Object.keys(extendedEnvValues)) {\n\t\tif (extendedEnvValues[key] !== undefined) {\n\t\t\tcombinedEnv[key] = extendedEnvValues[key];\n\t\t}\n\t}\n\n\tconst globalEnv =\n\t\ttypeof globalThis !== \"undefined\"\n\t\t\t? (globalThis as any).__arkenv_env__\n\t\t\t: undefined;\n\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\tcombinedEnv[key] = runtimeEnv[key];\n\t\t}\n\t\tif (globalEnv && globalEnv[key] !== undefined) {\n\t\t\tif (key.startsWith(\"NEXT_PUBLIC_\") || key in client || key in shared) {\n\t\t\t\tcombinedEnv[key] = globalEnv[key];\n\t\t\t}\n\t\t}\n\t}\n\n\tif (isServer) {\n\t\t// Fallback server keys to process.env if omitted or undefined\n\t\tfor (const key of Object.keys(server)) {\n\t\t\tif (combinedEnv[key] === undefined && process.env[key] !== undefined) {\n\t\t\t\tcombinedEnv[key] = process.env[key];\n\t\t\t}\n\t\t}\n\t}\n\n\t// Select schema based on environment\n\tconst schema = isServer\n\t\t? { ...server, ...client, ...shared }\n\t\t: { ...client, ...shared };\n\n\t// Run core validation\n\tconst validated = coreArkenv(schema as SchemaShape, {\n\t\tenv: combinedEnv as Dict<string>,\n\t\tsafe: false,\n\t});\n\n\tconst mergedValidated = { ...extendedEnvValues, ...validated };\n\n\t// Return a Proxy wrapper\n\treturn new Proxy(mergedValidated, {\n\t\tget(target, prop, receiver) {\n\t\t\tif (prop === EXTENDED_ENV) {\n\t\t\t\treturn target;\n\t\t\t}\n\t\t\tif (prop === ENV_KEYS) {\n\t\t\t\treturn allKeys;\n\t\t\t}\n\t\t\tif (prop === SERVER_ONLY_KEYS) {\n\t\t\t\treturn serverOnlyKeys;\n\t\t\t}\n\n\t\t\t// Always allow symbol properties (Symbol.iterator, Symbol.toStringTag, etc.)\n\t\t\tif (typeof prop === \"symbol\") {\n\t\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t\t}\n\n\t\t\tif (typeof prop === \"string\") {\n\t\t\t\tif (serverOnlyKeys.has(prop) && !isServer) {\n\t\t\t\t\tthrow new Error(boundaryAccessErrorMessage(prop));\n\t\t\t\t}\n\n\t\t\t\t// Allow schema keys and standard Object prototype properties\n\t\t\t\tif (!allKeys.has(prop) && !(prop in Object.prototype)) {\n\t\t\t\t\t// Fallback for bundler/framework-specific properties that bypass the prototype\n\t\t\t\t\tconst isCommonKey =\n\t\t\t\t\t\tprop === \"__esModule\" ||\n\t\t\t\t\t\tprop === \"$$typeof\" ||\n\t\t\t\t\t\tprop === \"toJSON\" ||\n\t\t\t\t\t\tprop === \"inspect\";\n\n\t\t\t\t\tif (!isCommonKey) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Environment variable '${prop}' is not defined in the schema.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t},\n\t});\n}\n"],"mappings":"uCAiBA,SAAS,EAA2B,EAAK,CACxC,MAAO,kCAAkC,EAAI,yECd9C,MAAa,EAAe,OAAO,IAAI,sBAAsB,CAChD,EAAW,OAAO,IAAI,cAAc,CACpC,EAAmB,OAAO,IAAI,0BAA0B,CAwBrE,IAAI,EAAkB,GAOtB,SAAgB,EACf,EACA,EACA,EAUA,EAIA,EACU,CACV,IAAI,EAAsB,EAAE,CACxB,EAAsB,EAAE,CACxB,EAAsB,EAAE,CACxB,EAAkC,EAAE,CACpC,EAA2B,EAAE,CAC7B,EAAW,GAEf,GAAI,OAAO,GAAsB,UAAW,CACvC,QAAQ,IAAI,WAAa,eAAiB,CAAC,IAC9C,EAAkB,GAClB,EACC,qQACA,EAGF,IAAM,EAAe,EAIrB,EAAU,GAAc,QAAU,EAAE,CACpC,EAAU,GAAc,QAAU,EAAE,CACpC,EAAU,GAAc,QAAU,EAAE,CACpC,EAAc,GAAc,SAAW,EAAE,CACzC,EAAc,GAAc,YAAc,EAAE,CAC5C,EACE,WAAmB,0BAA4B,IAChD,CAAC,CAAC,MACG,CAEN,IAAM,EAAc,GAAmB,EAAE,CACnC,EAAU,GAAqB,EAAE,CAOvC,GANA,EAAc,EAAQ,SAAW,EAAE,CACnC,EAAc,EAAQ,YAAc,EAAE,CACtC,EACE,WAAmB,0BAA4B,IAChD,CAAC,CAAC,GAAS,SAER,GAAS,SACZ,EAAS,UACC,GAAS,eAAiB,SACpC,EAAS,UACC,GA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,KAAO,KAC7D,EAAY,GAAO,EAAU,IAKhC,GAAI,MAEE,IAAM,KAAO,OAAO,KAAK,EAAO,CAChC,EAAY,KAAS,IAAA,IAAa,QAAQ,IAAI,KAAS,IAAA,KAC1D,EAAY,GAAO,QAAQ,IAAI,IAWlC,IAAM,EAAY,EALH,EACZ,CAAE,GAAG,EAAQ,GAAG,EAAQ,GAAG,EAAQ,CACnC,CAAE,GAAG,EAAQ,GAAG,EAAQ,CAGyB,CACnD,IAAK,EACL,KAAM,GACN,CAAC,CAEI,EAAkB,CAAE,GAAG,EAAmB,GAAG,EAAW,CAG9D,OAAO,IAAI,MAAM,EAAiB,CACjC,IAAI,EAAQ,EAAM,EAAU,CAC3B,GAAI,IAAS,EACZ,OAAO,EAER,GAAI,IAAS,EACZ,OAAO,EAER,GAAI,IAAS,EACZ,OAAO,EAIR,GAAI,OAAO,GAAS,SACnB,OAAO,QAAQ,IAAI,EAAQ,EAAM,EAAS,CAG3C,GAAI,OAAO,GAAS,SAAU,CAC7B,GAAI,EAAe,IAAI,EAAK,EAAI,CAAC,EAChC,MAAU,MAAM,EAA2B,EAAK,CAAC,CAIlD,GAAI,CAAC,EAAQ,IAAI,EAAK,EAAI,EAAE,KAAQ,OAAO,YAQtC,EALH,IAAS,cACT,IAAS,YACT,IAAS,UACT,IAAS,WAGT,MAAU,MACT,yBAAyB,EAAK,iCAC9B,CAIJ,OAAO,QAAQ,IAAI,EAAQ,EAAM,EAAS,EAE3C,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`./strict-client-env-MouPnkRr.cjs`);function t(t,n){return typeof t==`boolean`||t!=null&&`extends`in t||!e.n()?t:{...t??{},extends:[n()]}}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
2
|
+
//# sourceMappingURL=auto-extend-CYzZnEvT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-extend-CYzZnEvT.cjs","names":["isStrictLayoutActive"],"sources":["../src/auto-extend.ts"],"sourcesContent":["import type { FlatSchemaOptions } from \"./arkenv-internal\";\nimport { isStrictLayoutActive } from \"./strict-client-env\";\n\n/**\n * Apply strict-layout auto-extend when `extends` is omitted.\n *\n * @param optionsOrIsServer Flat options, legacy boolean, or undefined\n * @param resolveExtendTarget Lazy resolver for the default extend target\n * @returns Options with auto-extend applied when appropriate\n */\nexport function withAutoExtend(\n\toptionsOrIsServer: FlatSchemaOptions | boolean | null | undefined,\n\tresolveExtendTarget: () => unknown,\n): FlatSchemaOptions | boolean | null | undefined {\n\tif (typeof optionsOrIsServer === \"boolean\") {\n\t\treturn optionsOrIsServer;\n\t}\n\n\tif (optionsOrIsServer != null && \"extends\" in optionsOrIsServer) {\n\t\treturn optionsOrIsServer;\n\t}\n\n\tif (!isStrictLayoutActive()) {\n\t\treturn optionsOrIsServer;\n\t}\n\n\treturn {\n\t\t...(optionsOrIsServer ?? {}),\n\t\textends: [resolveExtendTarget()],\n\t};\n}\n"],"mappings":"oDAUA,SAAgB,EACf,EACA,EACiD,CAajD,OAZI,OAAO,GAAsB,WAI7B,GAAqB,MAAQ,YAAa,GAI1C,CAACA,EAAAA,GAAsB,CACnB,EAGD,CACN,GAAI,GAAqB,EAAE,CAC3B,QAAS,CAAC,GAAqB,CAAC,CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-extend-DjiqIbgM.js","names":[],"sources":["../src/auto-extend.ts"],"sourcesContent":["import type { FlatSchemaOptions } from \"./arkenv-internal\";\nimport { isStrictLayoutActive } from \"./strict-client-env\";\n\n/**\n * Apply strict-layout auto-extend when `extends` is omitted.\n *\n * @param optionsOrIsServer Flat options, legacy boolean, or undefined\n * @param resolveExtendTarget Lazy resolver for the default extend target\n * @returns Options with auto-extend applied when appropriate\n */\nexport function withAutoExtend(\n\toptionsOrIsServer: FlatSchemaOptions | boolean | null | undefined,\n\tresolveExtendTarget: () => unknown,\n): FlatSchemaOptions | boolean | null | undefined {\n\tif (typeof optionsOrIsServer === \"boolean\") {\n\t\treturn optionsOrIsServer;\n\t}\n\n\tif (optionsOrIsServer != null && \"extends\" in optionsOrIsServer) {\n\t\treturn optionsOrIsServer;\n\t}\n\n\tif (!isStrictLayoutActive()) {\n\t\treturn optionsOrIsServer;\n\t}\n\n\treturn {\n\t\t...(optionsOrIsServer ?? {}),\n\t\textends: [resolveExtendTarget()],\n\t};\n}\n"],"mappings":"oDAUA,SAAgB,EACf,EACA,EACiD,CAajD,OAZI,OAAO,GAAsB,WAI7B,GAAqB,MAAQ,YAAa,GAI1C,CAAC,GAAsB,CACnB,EAGD,CACN,GAAI,GAAqB,EAAE,CAC3B,QAAS,CAAC,GAAqB,CAAC,CAChC"}
|
package/dist/client.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`./config-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`./config-Oq8dsEPM.cjs`);const e=require(`./arkenv-internal-QxkUlA5J.cjs`);let t=require(`@arkenv/core`);function n(n,r){if(n&&typeof n==`object`&&(`runtimeEnv`in n||`client`in n||`shared`in n)){if(`server`in n)throw Error(`client entry point only accepts 'client' and 'shared' schemas.`);return e.t(n,!1,void 0,t.arkenv,t.getSchemaKeys)}return e.t(n,r,{isServer:!1,strictLayout:`client`},t.arkenv,t.getSchemaKeys)}exports.arkenv=n,exports.default=n;
|
|
2
2
|
//# sourceMappingURL=client.cjs.map
|
package/dist/client.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.cjs","names":["arkenvInternal","coreArkenv","getSchemaKeys"],"sources":["../src/client.ts"],"sourcesContent":["import type { EnvSchema } from \"@arkenv/core\";\nimport { arkenv as coreArkenv, getSchemaKeys } from \"@arkenv/core\";\nimport type { $ } from \"@repo/scope\";\nimport type { Dict, SchemaShape } from \"@repo/types\";\nimport type { type as at, distill } from \"arktype\";\nimport { arkenvInternal } from \"./arkenv-internal\";\nimport type { MergeExtends } from \"./types\";\n\n/**\n * Create a validated,
|
|
1
|
+
{"version":3,"file":"client.cjs","names":["arkenvInternal","coreArkenv","getSchemaKeys"],"sources":["../src/client.ts"],"sourcesContent":["import type { EnvSchema } from \"@arkenv/core\";\nimport { arkenv as coreArkenv, getSchemaKeys } from \"@arkenv/core\";\nimport type { $ } from \"@repo/scope\";\nimport type { Dict, SchemaShape } from \"@repo/types\";\nimport type { type as at, distill } from \"arktype\";\nimport { arkenvInternal } from \"./arkenv-internal\";\nimport type { MergeExtends } from \"./types\";\n\n/**\n * Create a validated, typesafe environment configuration for Next.js applications (Client entry point).\n */\nexport function arkenv<\n\tconst TSchema extends SchemaShape = {},\n\tconst TExtends extends readonly unknown[] = [],\n>(\n\tschema: EnvSchema<TSchema> & {\n\t\t[K in keyof TSchema]: K extends `NEXT_PUBLIC_${string}` ? unknown : never;\n\t},\n\toptions?: {\n\t\textends?: [...TExtends];\n\t\truntimeEnv: Record<keyof TSchema, string | undefined> & Dict<string>;\n\t},\n): Readonly<distill.Out<at.infer<TSchema, $>> & MergeExtends<TExtends>>;\n\n/**\n * @deprecated Use the unified flat layout signature instead: `arkenv(schema, options)`\n */\nexport function arkenv<\n\tconst TClient extends SchemaShape = {},\n\tconst TShared extends SchemaShape = {},\n\tconst TExtends extends readonly unknown[] = [],\n>(options: {\n\tclient?: EnvSchema<TClient> & {\n\t\t[K in keyof TClient]: K extends `NEXT_PUBLIC_${string}` ? unknown : never;\n\t};\n\tshared?: EnvSchema<TShared>;\n\textends?: [...TExtends];\n\truntimeEnv: Record<keyof TClient | keyof TShared, unknown> &\n\t\tRecord<string, unknown>;\n}): Readonly<\n\tdistill.Out<at.infer<TClient & TShared, $>> & MergeExtends<TExtends>\n>;\n\nexport function arkenv(schemaOrOptions: any, optionsOrIsServer?: any): any {\n\tconst isLegacy =\n\t\tschemaOrOptions &&\n\t\ttypeof schemaOrOptions === \"object\" &&\n\t\t(\"runtimeEnv\" in schemaOrOptions ||\n\t\t\t\"client\" in schemaOrOptions ||\n\t\t\t\"shared\" in schemaOrOptions);\n\n\tif (isLegacy) {\n\t\tif (\"server\" in schemaOrOptions) {\n\t\t\tthrow new Error(\n\t\t\t\t\"client entry point only accepts 'client' and 'shared' schemas.\",\n\t\t\t);\n\t\t}\n\t\treturn arkenvInternal(\n\t\t\tschemaOrOptions,\n\t\t\tfalse,\n\t\t\tundefined,\n\t\t\tcoreArkenv,\n\t\t\tgetSchemaKeys,\n\t\t);\n\t}\n\n\treturn arkenvInternal(\n\t\tschemaOrOptions,\n\t\toptionsOrIsServer,\n\t\t{ isServer: false, strictLayout: \"client\" },\n\t\tcoreArkenv,\n\t\tgetSchemaKeys,\n\t);\n}\n\nexport default arkenv;\n"],"mappings":"gNA2CA,SAAgB,EAAO,EAAsB,EAA8B,CAQ1E,GANC,GACA,OAAO,GAAoB,WAC1B,eAAgB,GAChB,WAAY,GACZ,WAAY,GAEA,CACb,GAAI,WAAY,EACf,MAAU,MACT,iEACA,CAEF,OAAOA,EAAAA,EACN,EACA,GACA,IAAA,GACAC,EAAAA,OACAC,EAAAA,cACA,CAGF,OAAOF,EAAAA,EACN,EACA,EACA,CAAE,SAAU,GAAO,aAAc,SAAU,CAC3CC,EAAAA,OACAC,EAAAA,cACA"}
|
package/dist/client.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { a as $, i as Dict, t as SchemaShape } from "./index-
|
|
2
|
-
import { t as MergeExtends } from "./types-
|
|
1
|
+
import { a as $, i as Dict, t as SchemaShape } from "./index-BS1wAitS.cjs";
|
|
2
|
+
import { t as MergeExtends } from "./types-BlRHnQwj.cjs";
|
|
3
3
|
import { EnvSchema } from "@arkenv/core";
|
|
4
4
|
import { distill, type } from "arktype";
|
|
5
5
|
|
|
6
6
|
//#region src/client.d.ts
|
|
7
7
|
/**
|
|
8
|
-
* Create a validated,
|
|
8
|
+
* Create a validated, typesafe environment configuration for Next.js applications (Client entry point).
|
|
9
9
|
*/
|
|
10
10
|
declare function arkenv<const TSchema extends SchemaShape = {}, const TExtends extends readonly unknown[] = []>(schema: EnvSchema<TSchema> & { [K in keyof TSchema]: K extends `NEXT_PUBLIC_${string}` ? unknown : never }, options?: {
|
|
11
11
|
extends?: [...TExtends];
|
package/dist/client.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { a as $, i as Dict, t as SchemaShape } from "./index-
|
|
2
|
-
import { t as MergeExtends } from "./types-
|
|
1
|
+
import { a as $, i as Dict, t as SchemaShape } from "./index-Cq_qJ68V.js";
|
|
2
|
+
import { t as MergeExtends } from "./types-BfMBbrMm.js";
|
|
3
3
|
import { EnvSchema } from "@arkenv/core";
|
|
4
4
|
import { distill, type } from "arktype";
|
|
5
5
|
|
|
6
6
|
//#region src/client.d.ts
|
|
7
7
|
/**
|
|
8
|
-
* Create a validated,
|
|
8
|
+
* Create a validated, typesafe environment configuration for Next.js applications (Client entry point).
|
|
9
9
|
*/
|
|
10
10
|
declare function arkenv<const TSchema extends SchemaShape = {}, const TExtends extends readonly unknown[] = []>(schema: EnvSchema<TSchema> & { [K in keyof TSchema]: K extends `NEXT_PUBLIC_${string}` ? unknown : never }, options?: {
|
|
11
11
|
extends?: [...TExtends];
|
package/dist/client.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./arkenv-internal-
|
|
1
|
+
import{t as e}from"./arkenv-internal-Ws3srax6.js";import{arkenv as t,getSchemaKeys as n}from"@arkenv/core";function r(r,i){if(r&&typeof r==`object`&&(`runtimeEnv`in r||`client`in r||`shared`in r)){if(`server`in r)throw Error(`client entry point only accepts 'client' and 'shared' schemas.`);return e(r,!1,void 0,t,n)}return e(r,i,{isServer:!1,strictLayout:`client`},t,n)}export{r as arkenv,r as default};
|
|
2
2
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":["coreArkenv"],"sources":["../src/client.ts"],"sourcesContent":["import type { EnvSchema } from \"@arkenv/core\";\nimport { arkenv as coreArkenv, getSchemaKeys } from \"@arkenv/core\";\nimport type { $ } from \"@repo/scope\";\nimport type { Dict, SchemaShape } from \"@repo/types\";\nimport type { type as at, distill } from \"arktype\";\nimport { arkenvInternal } from \"./arkenv-internal\";\nimport type { MergeExtends } from \"./types\";\n\n/**\n * Create a validated,
|
|
1
|
+
{"version":3,"file":"client.js","names":["coreArkenv"],"sources":["../src/client.ts"],"sourcesContent":["import type { EnvSchema } from \"@arkenv/core\";\nimport { arkenv as coreArkenv, getSchemaKeys } from \"@arkenv/core\";\nimport type { $ } from \"@repo/scope\";\nimport type { Dict, SchemaShape } from \"@repo/types\";\nimport type { type as at, distill } from \"arktype\";\nimport { arkenvInternal } from \"./arkenv-internal\";\nimport type { MergeExtends } from \"./types\";\n\n/**\n * Create a validated, typesafe environment configuration for Next.js applications (Client entry point).\n */\nexport function arkenv<\n\tconst TSchema extends SchemaShape = {},\n\tconst TExtends extends readonly unknown[] = [],\n>(\n\tschema: EnvSchema<TSchema> & {\n\t\t[K in keyof TSchema]: K extends `NEXT_PUBLIC_${string}` ? unknown : never;\n\t},\n\toptions?: {\n\t\textends?: [...TExtends];\n\t\truntimeEnv: Record<keyof TSchema, string | undefined> & Dict<string>;\n\t},\n): Readonly<distill.Out<at.infer<TSchema, $>> & MergeExtends<TExtends>>;\n\n/**\n * @deprecated Use the unified flat layout signature instead: `arkenv(schema, options)`\n */\nexport function arkenv<\n\tconst TClient extends SchemaShape = {},\n\tconst TShared extends SchemaShape = {},\n\tconst TExtends extends readonly unknown[] = [],\n>(options: {\n\tclient?: EnvSchema<TClient> & {\n\t\t[K in keyof TClient]: K extends `NEXT_PUBLIC_${string}` ? unknown : never;\n\t};\n\tshared?: EnvSchema<TShared>;\n\textends?: [...TExtends];\n\truntimeEnv: Record<keyof TClient | keyof TShared, unknown> &\n\t\tRecord<string, unknown>;\n}): Readonly<\n\tdistill.Out<at.infer<TClient & TShared, $>> & MergeExtends<TExtends>\n>;\n\nexport function arkenv(schemaOrOptions: any, optionsOrIsServer?: any): any {\n\tconst isLegacy =\n\t\tschemaOrOptions &&\n\t\ttypeof schemaOrOptions === \"object\" &&\n\t\t(\"runtimeEnv\" in schemaOrOptions ||\n\t\t\t\"client\" in schemaOrOptions ||\n\t\t\t\"shared\" in schemaOrOptions);\n\n\tif (isLegacy) {\n\t\tif (\"server\" in schemaOrOptions) {\n\t\t\tthrow new Error(\n\t\t\t\t\"client entry point only accepts 'client' and 'shared' schemas.\",\n\t\t\t);\n\t\t}\n\t\treturn arkenvInternal(\n\t\t\tschemaOrOptions,\n\t\t\tfalse,\n\t\t\tundefined,\n\t\t\tcoreArkenv,\n\t\t\tgetSchemaKeys,\n\t\t);\n\t}\n\n\treturn arkenvInternal(\n\t\tschemaOrOptions,\n\t\toptionsOrIsServer,\n\t\t{ isServer: false, strictLayout: \"client\" },\n\t\tcoreArkenv,\n\t\tgetSchemaKeys,\n\t);\n}\n\nexport default arkenv;\n"],"mappings":"2GA2CA,SAAgB,EAAO,EAAsB,EAA8B,CAQ1E,GANC,GACA,OAAO,GAAoB,WAC1B,eAAgB,GAChB,WAAY,GACZ,WAAY,GAEA,CACb,GAAI,WAAY,EACf,MAAU,MACT,iEACA,CAEF,OAAO,EACN,EACA,GACA,IAAA,GACAA,EACA,EACA,CAGF,OAAO,EACN,EACA,EACA,CAAE,SAAU,GAAO,aAAc,SAAU,CAC3CA,EACA,EACA"}
|
package/dist/config/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../config-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../config-Oq8dsEPM.cjs`);let t=require(`@arkenv/build`);exports.extractClientKeys=t.extractClientKeys,exports.extractKeys=e.i,exports.extractSharedKeys=t.extractSharedKeys,exports.runCodegen=e.r,exports.setupArkEnv=e.t,exports.withArkEnv=e.n;
|
package/dist/config/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as extractKeys, i as withArkEnv, n as extractSharedKeys, o as runCodegen, r as setupArkEnv, s as ArkEnvConfigOptions, t as extractClientKeys } from "../index-
|
|
2
|
-
export { ArkEnvConfigOptions, extractClientKeys, extractKeys, extractSharedKeys, runCodegen, setupArkEnv, withArkEnv };
|
|
1
|
+
import { a as extractKeys, c as NextConfigContext, i as withArkEnv, l as NextConfigFactory, n as extractSharedKeys, o as runCodegen, r as setupArkEnv, s as ArkEnvConfigOptions, t as extractClientKeys } from "../index-RdYGBD_V.cjs";
|
|
2
|
+
export { ArkEnvConfigOptions, NextConfigContext, NextConfigFactory, extractClientKeys, extractKeys, extractSharedKeys, runCodegen, setupArkEnv, withArkEnv };
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as extractKeys, i as withArkEnv, n as extractSharedKeys, o as runCodegen, r as setupArkEnv, s as ArkEnvConfigOptions, t as extractClientKeys } from "../index-
|
|
2
|
-
export { ArkEnvConfigOptions, extractClientKeys, extractKeys, extractSharedKeys, runCodegen, setupArkEnv, withArkEnv };
|
|
1
|
+
import { a as extractKeys, c as NextConfigContext, i as withArkEnv, l as NextConfigFactory, n as extractSharedKeys, o as runCodegen, r as setupArkEnv, s as ArkEnvConfigOptions, t as extractClientKeys } from "../index-CBjJM83X.js";
|
|
2
|
+
export { ArkEnvConfigOptions, NextConfigContext, NextConfigFactory, extractClientKeys, extractKeys, extractSharedKeys, runCodegen, setupArkEnv, withArkEnv };
|
package/dist/config/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,i as t,n,o as r,r as i,t as a}from"../config-
|
|
1
|
+
import{a as e,i as t,n,o as r,r as i,t as a}from"../config-Deut5Vf8.js";export{a as extractClientKeys,r as extractKeys,n as extractSharedKeys,e as runCodegen,i as setupArkEnv,t as withArkEnv};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import{n as e,r as t,t as n}from"./dist-DimRGXOV.js";import{r,t as i}from"./strict-client-env-CHDTZoLe.js";import{extractBlock as a,extractClientKeys as o,extractClientKeys as s,extractSharedKeys as c,extractSharedKeys as l,findSchemaPath as u,formatMissingSchemaError as d,parseBlockKeys as f,resolveLayout as p,watchSchema as m}from"@arkenv/build";import h from"node:fs";import g from"node:path";import{fileURLToPath as _}from"node:url";import{createJiti as v}from"jiti";function y(e){let t=e.match(/exposeToClient\s*:\s*\[([\s\S]*?)\]/)||e.match(/expose\s*:\s*\[([\s\S]*?)\]/)||e.match(/shared\s*:\s*\[([\s\S]*?)\]/);if(!t)return[];let n=[];for(let e of t[1].matchAll(/['"`](.*?)['"`]/g))n.push(e[1]);return n}function b(e){let t=/\b(?:arkenv|createEnv)\s*\(/g;for(;t.exec(e)!==null;){let n=1,r=t.lastIndex,i=null,a=null,o=0,s=0,c=[],l=``;for(;r<e.length&&n>0;){let t=e[r],u=e[r+1];if(a===`single`){(t===`
|
|
2
|
+
`||t===`\r`)&&(a=null),l+=t,r++;continue}if(a===`multi`){if(t===`*`&&u===`/`){a=null,l+=`*/`,r+=2;continue}l+=t,r++;continue}if(i){t===i&&e[r-1]!==`\\`&&(i=null),l+=t,r++;continue}if(t===`/`&&u===`/`){a=`single`,l+=`//`,r+=2;continue}if(t===`/`&&u===`*`){a=`multi`,l+=`/*`,r+=2;continue}if(t===`'`||t===`"`||t==="`"){i=t,l+=t,r++;continue}if(t===`(`?n++:t===`)`?n--:t===`{`?o++:t===`}`?o--:t===`[`?s++:t===`]`&&s--,n===0){c.push(l);break}t===`,`&&n===1&&o===0&&s===0?(c.push(l),l=``):l+=t,r++}if(n===0&&c.length>0)return{schemaArg:c[0].trim(),optionsArg:c[1]?c[1].trim():null}}return null}function x(e){let t=[],n=[],r=b(e);if(!r)return{clientKeys:t,sharedKeys:n,isLegacy:!1};let i=f(r.schemaArg.replace(/^\{/,``).replace(/\}$/,``).trim()),o=i.includes(`client`)||i.includes(`server`)||i.includes(`shared`);if(o){let e=a(r.schemaArg,`client`);e&&t.push(...f(e));let i=a(r.schemaArg,`shared`);return i&&n.push(...f(i)),{clientKeys:t,sharedKeys:n,isLegacy:o}}let s=r.optionsArg?y(r.optionsArg):[];for(let e of i){if(s.includes(e)||e===`NODE_ENV`){n.push(e);continue}e.startsWith(`NEXT_PUBLIC_`)&&t.push(e)}return{clientKeys:t,sharedKeys:n,isLegacy:o}}function S(e,t){return Array.from(new Set([...e,...t])).map(e=>`\t\t\t${e}: typeof window !== "undefined" ? (globalThis as any).__arkenv_env__?.${e} ?? process.env.${e} : process.env.${e},`).join(`
|
|
3
|
+
`)}const C=`/* eslint-disable */
|
|
4
|
+
// biome-ignore format: auto-generated
|
|
5
|
+
// Generated by ArkEnv. DO NOT EDIT DIRECTLY.
|
|
6
|
+
`,w=`
|
|
7
|
+
export default arkenv;
|
|
8
|
+
`;function T(e,t,n){let r=S(e,t);return`${C}
|
|
9
|
+
import { arkenv as coreArkenv } from "${n?`@arkenv/nextjs/standard`:`@arkenv/nextjs`}";
|
|
10
|
+
|
|
11
|
+
export function arkenv<
|
|
12
|
+
const TServer extends Record<string, any> = {},
|
|
13
|
+
const TClient extends Record<string, any> = {},
|
|
14
|
+
const TShared extends Record<string, any> = {},
|
|
15
|
+
>(options: {
|
|
16
|
+
server?: TServer;
|
|
17
|
+
client?: TClient & {
|
|
18
|
+
[K in keyof TClient]: K extends \`NEXT_PUBLIC_\${string}\` ? unknown : never;
|
|
19
|
+
};
|
|
20
|
+
shared?: TShared;
|
|
21
|
+
}) {
|
|
22
|
+
return coreArkenv({
|
|
23
|
+
...options,
|
|
24
|
+
runtimeEnv: {
|
|
25
|
+
${r}
|
|
26
|
+
},
|
|
27
|
+
} as any) as any;
|
|
28
|
+
}
|
|
29
|
+
${w}`}function E(e,t,n){let r=S(e,t);return`${C}
|
|
30
|
+
import { arkenv as coreArkenv } from "${n?`@arkenv/nextjs/standard`:`@arkenv/nextjs`}";${n?``:`
|
|
31
|
+
import type { type as at, distill } from "arktype";`}
|
|
32
|
+
|
|
33
|
+
export function arkenv<
|
|
34
|
+
const TSchema extends Record<string, unknown> & { runtimeEnv?: never } = {},
|
|
35
|
+
const TExpose extends keyof TSchema = never,
|
|
36
|
+
const TExtends extends readonly unknown[] = [],
|
|
37
|
+
>(
|
|
38
|
+
schema: TSchema,
|
|
39
|
+
options?: {
|
|
40
|
+
/**
|
|
41
|
+
* Custom environment variables to expose to the client bundle.
|
|
42
|
+
* By default, variables prefixed with \`NEXT_PUBLIC_\` and \`NODE_ENV\` are exposed automatically.
|
|
43
|
+
* Use this option to expose custom variables that do not have the \`NEXT_PUBLIC_\` prefix.
|
|
44
|
+
*/
|
|
45
|
+
exposeToClient?: readonly TExpose[];
|
|
46
|
+
extends?: [...TExtends];
|
|
47
|
+
},
|
|
48
|
+
): ${n?`Readonly<TSchema>`:`Readonly<distill.Out<at.infer<TSchema>>>`} {
|
|
49
|
+
const env = coreArkenv(schema as any, {
|
|
50
|
+
...options,
|
|
51
|
+
runtimeEnv: {
|
|
52
|
+
${r}
|
|
53
|
+
},
|
|
54
|
+
} as any);
|
|
55
|
+
return env${n?``:` as unknown as Readonly<distill.Out<at.infer<TSchema>>>`};
|
|
56
|
+
}
|
|
57
|
+
${w}`}function D(e,t){let n=`../client`;if(e&&t){let r=g.dirname(t),i=g.relative(r,e).replace(/\\/g,`/`).replace(/\.tsx?$/,``);n=i.startsWith(`.`)?i:`./${i}`}return`${C}
|
|
58
|
+
declare module "#arkenv/client-env" {
|
|
59
|
+
export { env } from "${n}";
|
|
60
|
+
}
|
|
61
|
+
`}function O(e,t,n){let r=S(e,t);return`${C}
|
|
62
|
+
import { arkenv as coreArkenv } from "${n?`@arkenv/nextjs/standard/client`:`@arkenv/nextjs/client`}";${n?``:`
|
|
63
|
+
import type { Infer } from "@arkenv/core";`}
|
|
64
|
+
|
|
65
|
+
type ResolveExtend<T> = [Infer<T>] extends [never] ? T : Infer<T>;
|
|
66
|
+
|
|
67
|
+
type UnionToIntersection<U> = (
|
|
68
|
+
U extends any ? (k: U) => void : never
|
|
69
|
+
) extends (k: infer I) => void
|
|
70
|
+
? I
|
|
71
|
+
: never;
|
|
72
|
+
|
|
73
|
+
type MergeExtends<TExtends extends readonly unknown[] | undefined> =
|
|
74
|
+
TExtends extends readonly unknown[]
|
|
75
|
+
? UnionToIntersection<ResolveExtend<TExtends[number]>>
|
|
76
|
+
: {};
|
|
77
|
+
|
|
78
|
+
export function arkenv<
|
|
79
|
+
const TSchema extends Record<string, any> = {},
|
|
80
|
+
const TExtends extends readonly unknown[] = [],
|
|
81
|
+
>(
|
|
82
|
+
schema: TSchema & {
|
|
83
|
+
[K in keyof TSchema]: K extends \`NEXT_PUBLIC_\${string}\` ? unknown : never;
|
|
84
|
+
},
|
|
85
|
+
options?: {
|
|
86
|
+
extends?: [...TExtends];
|
|
87
|
+
},
|
|
88
|
+
): ${n?`Readonly<TSchema & MergeExtends<TExtends>>`:`Readonly<Infer<TSchema> & MergeExtends<TExtends>>`} {
|
|
89
|
+
return coreArkenv(schema as any, {
|
|
90
|
+
...options,
|
|
91
|
+
runtimeEnv: {
|
|
92
|
+
${r}
|
|
93
|
+
},
|
|
94
|
+
} as any);
|
|
95
|
+
}
|
|
96
|
+
${w}`}let k=!1;function A(e,t){return e===`flat`?`simple`:e===`simple`?process.env.NODE_ENV!==`development`||k?`simple`:(k=!0,t.logBuildWarning(`The 'simple' layout option is deprecated and will be removed in the next major version. Use 'flat' instead.`),`simple`):e}function j(e,t){return t?!0:e.includes(`@arkenv/standard`)||e.includes(`arkenv/standard`)}function M(t,n,r,i,a){let{layout:s,baseDir:l}=p(t,A(r,e(a))),u=``;if(s===`strict`){let e=g.join(l,`client.ts`),t=g.join(l,`internal`,`shared.ts`),n=h.existsSync(e)?h.readFileSync(e,`utf-8`):``,r=h.existsSync(t)?h.readFileSync(t,`utf-8`):``,a=j(n,i)||j(r,i);u=O(o(n),c(r),a)}else{let e=h.readFileSync(t,`utf-8`),n=j(e,i),{clientKeys:r,sharedKeys:a,isLegacy:o}=x(e);u=o?T(r,a,n):E(r,a,n)}let d=g.dirname(n);h.existsSync(d)||h.mkdirSync(d,{recursive:!0});let f=!0;h.existsSync(n)&&h.readFileSync(n,`utf-8`)===u&&(f=!1),f&&h.writeFileSync(n,u,`utf-8`);let m=g.join(d,`index.ts`),_=`export * from "./env.gen";
|
|
97
|
+
export { default } from "./env.gen";
|
|
98
|
+
`;if(g.basename(d)===`.arkenv`||!h.existsSync(m)){let e=!0;h.existsSync(m)&&h.readFileSync(m,`utf-8`)===_&&(e=!1),e&&h.writeFileSync(m,_,`utf-8`)}if(s===`strict`&&l){let e=g.join(g.dirname(n),`arkenv-client-env.d.ts`),t=D(g.join(l,`client.ts`),n),r=!0;h.existsSync(e)&&h.readFileSync(e,`utf-8`)===t&&(r=!1),r&&h.writeFileSync(e,t,`utf-8`)}}function N(e,t,n){if(Array.isArray(e)){let r=e.filter(e=>e.name!==t);return r.push({name:t,alias:n}),r}return{...e??{},[t]:n}}function P(e,t,n=`#arkenv/client-env`){let r=e.webpack,i=(e,i)=>{let a=r?r(e,i)??e:e;a.resolve=a.resolve??{},a.resolve.alias=N(a.resolve.alias,n,t);let o=i.webpack?.DefinePlugin;return o&&(a.plugins=a.plugins??[],a.plugins.push(new o({__ARKENV_STRICT_LAYOUT__:JSON.stringify(!0)}))),a},a=g.isAbsolute(t)?`./${g.relative(process.cwd(),t).replace(/\\/g,`/`)}`:t.startsWith(`.`)?t:`./${t}`,o=e.turbopack??{},s={...o.resolveAlias??{},[n]:a},c=e.experimental,l=c?{...c,...c.turbo?{turbo:{...c.turbo,resolveAlias:{...c.turbo.resolveAlias??{},[n]:a}}}:{}}:void 0,u={...e,webpack:i,env:{...e.env??{},ARKENV_STRICT_LAYOUT:`true`},turbopack:{...o,resolveAlias:s}};return l&&(u.experimental=l),u}function F(e){for(let t of[e,g.join(e,`..`)]){let e=g.join(t,`mock-server-only.ts`);if(h.existsSync(e))return e;let n=g.join(t,`mock-server-only.js`);if(h.existsSync(n))return n}return g.join(e,`mock-server-only.js`)}function I(e){for(let t of[e,g.join(e,`..`)]){let e=g.join(t,`empty-client-env.ts`);if(h.existsSync(e))return e;let n=g.join(t,`empty-client-env.js`);if(h.existsSync(n))return n}return g.join(e,`empty-client-env.js`)}function L(e){if(h.existsSync(e))return!0;let t=g.extname(e);if(!t)return!1;let n=e.slice(0,-t.length);return h.existsSync(n)}function R(a,o){let s=e(a),c=a?.schemaPath?g.resolve(a.schemaPath):u();if(!c||!L(c))throw Error(d({schemaPath:a?.schemaPath,optionsHint:`setupArkEnv options`}));let{layout:l,baseDir:f}=p(c,A(a?.layout,s)),y=l===`strict`&&f?g.join(f,`client.ts`):void 0;if(y&&!h.existsSync(y))throw Error(r(y,f));function b(e,t,n){if(n===`strict`&&t){let e=t;return g.basename(e)===`env`&&(e=g.dirname(e)),g.basename(e)===`src`&&(e=g.dirname(e)),e}let r=g.dirname(e);return g.basename(r)===`src`&&(r=g.dirname(r)),r}let x=b(c,f,l),S=g.join(x,`.arkenv`,`env.gen.ts`),C=a?.outputPath?g.resolve(a.outputPath):S,w=a?.codegen??!0;if(w)try{M(c,C,l,a?.standard,a)}catch(e){let n=e instanceof Error?e.message:String(e);throw Error(t(`Failed to generate env.gen.ts: ${n}`))}if(a?.validate??!0){let e=globalThis;try{e.__arkenv_force_server__=!0;let t=l===`strict`&&f?g.join(f,`server.ts`):c,n=typeof __filename<`u`?__filename:import.meta.url?_(import.meta.url):``,r=g.dirname(n),a=F(r),s=I(r),u=v(t,{moduleCache:!1,fsCache:!1,tsconfigPaths:!0,alias:{"server-only":a,"./script":a,"./script.tsx":a,[i]:y&&h.existsSync(y)?y:s,...o?._jitiAliases}});if(l===`strict`&&y){e.__ARKENV_STRICT_LAYOUT__=!0;let t=u(y);e.__ARKENV_CLIENT_ENV__=t.env??t.default?.env??t}u(t)}catch(e){s.logBuildError(`Environment validation failed:`),s.logBuildErrorDetail(e instanceof Error?e.message:String(e)),s.logBuildErrorBlankLine(),process.exit(1)}finally{delete e.__arkenv_force_server__,delete e.__ARKENV_STRICT_LAYOUT__,delete e.__ARKENV_CLIENT_ENV__}}return(process.env.NODE_ENV===`development`||process.env.NEXT_PHASE===`phase-development-server`)&&w&&m(l===`strict`&&f?[g.join(f,`internal`,`shared.ts`),g.join(f,`client.ts`),g.join(f,`server.ts`)].filter(h.existsSync):[c],()=>{M(c,C,l,a?.standard,a)},n(a)),{resolvedLayout:l,baseDir:f,clientEnvPath:y,outputPath:C}}function z(e,t,n){let{resolvedLayout:r,clientEnvPath:a,outputPath:o}=n,s=e;r===`strict`&&a&&(s=P(s,a,i));let c=process.cwd(),l=o??(t?.outputPath?g.resolve(t.outputPath):g.join(c,`.arkenv`,`env.gen.ts`)),u=`./${g.relative(c,l).replace(/\\/g,`/`)}`,d={...s.turbopack,resolveAlias:{".arkenv/env.gen":u,".arkenv/env.gen.ts":u,".arkenv":u,".arkenv/index":u,".arkenv/index.ts":u,"#arkenv/env":u,"@/.arkenv":u,"@/.arkenv/env.gen":u,...s.turbopack?.resolveAlias}},f=s.webpack,p=(e,t)=>{let n=e;return n.resolve=n.resolve??{},n.resolve.alias={...n.resolve.alias,".arkenv/env.gen":l,".arkenv/env.gen.ts":l,".arkenv":l,".arkenv/index":l,".arkenv/index.ts":l,"#arkenv/env":l,"@/.arkenv":l,"@/.arkenv/env.gen":l},typeof f==`function`?f(n,t):n};return{...s,turbopack:d,webpack:p}}function B(e,t){return typeof e==`function`?async(n,r)=>{let i=R(t);return z(await e(n,r),t,i)}:e&&typeof e==`object`?z(e,t,R(t)):e}export{M as a,B as i,l as n,x as o,R as r,s as t};
|
|
99
|
+
//# sourceMappingURL=config-Deut5Vf8.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-Deut5Vf8.js","names":["resolveBuildLog","resolveBuildLog","formatBuildError","resolveLoggerFromOptions"],"sources":["../src/config/extract.ts","../src/config/generate.ts","../src/config/layout.ts","../src/config/codegen.ts","../src/config/strict-layout-aliases.ts","../src/config/setup.ts"],"sourcesContent":["import { extractBlock, parseBlockKeys } from \"@arkenv/build\";\n\nfunction parseExposeKeys(optionsArg: string): string[] {\n\tconst exposeMatch =\n\t\toptionsArg.match(/exposeToClient\\s*:\\s*\\[([\\s\\S]*?)\\]/) ||\n\t\toptionsArg.match(/expose\\s*:\\s*\\[([\\s\\S]*?)\\]/) ||\n\t\toptionsArg.match(/shared\\s*:\\s*\\[([\\s\\S]*?)\\]/);\n\tif (!exposeMatch) return [];\n\n\tconst keys: string[] = [];\n\tfor (const match of exposeMatch[1].matchAll(/['\"`](.*?)['\"`]/g)) {\n\t\tkeys.push(match[1]);\n\t}\n\treturn keys;\n}\n\nfunction extractCallArguments(\n\tcontent: string,\n): { schemaArg: string; optionsArg: string | null } | null {\n\tconst regex = /\\b(?:arkenv|createEnv)\\s*\\(/g;\n\twhile (regex.exec(content) !== null) {\n\t\tlet parenCount = 1;\n\t\tlet index = regex.lastIndex;\n\t\tlet inString: string | null = null;\n\t\tlet inComment: \"single\" | \"multi\" | null = null;\n\t\tlet braceCount = 0;\n\t\tlet bracketCount = 0;\n\n\t\tconst args: string[] = [];\n\t\tlet currentArg = \"\";\n\n\t\twhile (index < content.length && parenCount > 0) {\n\t\t\tconst char = content[index];\n\t\t\tconst nextChar = content[index + 1];\n\n\t\t\tif (inComment === \"single\") {\n\t\t\t\tif (char === \"\\n\" || char === \"\\r\") inComment = null;\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (inComment === \"multi\") {\n\t\t\t\tif (char === \"*\" && nextChar === \"/\") {\n\t\t\t\t\tinComment = null;\n\t\t\t\t\tcurrentArg += \"*/\";\n\t\t\t\t\tindex += 2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (inString) {\n\t\t\t\tif (char === inString && content[index - 1] !== \"\\\\\") {\n\t\t\t\t\tinString = null;\n\t\t\t\t}\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (char === \"/\" && nextChar === \"/\") {\n\t\t\t\tinComment = \"single\";\n\t\t\t\tcurrentArg += \"//\";\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === \"/\" && nextChar === \"*\") {\n\t\t\t\tinComment = \"multi\";\n\t\t\t\tcurrentArg += \"/*\";\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === \"'\" || char === '\"' || char === \"`\") {\n\t\t\t\tinString = char;\n\t\t\t\tcurrentArg += char;\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (char === \"(\") {\n\t\t\t\tparenCount++;\n\t\t\t} else if (char === \")\") {\n\t\t\t\tparenCount--;\n\t\t\t} else if (char === \"{\") {\n\t\t\t\tbraceCount++;\n\t\t\t} else if (char === \"}\") {\n\t\t\t\tbraceCount--;\n\t\t\t} else if (char === \"[\") {\n\t\t\t\tbracketCount++;\n\t\t\t} else if (char === \"]\") {\n\t\t\t\tbracketCount--;\n\t\t\t}\n\n\t\t\tif (parenCount === 0) {\n\t\t\t\targs.push(currentArg);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tchar === \",\" &&\n\t\t\t\tparenCount === 1 &&\n\t\t\t\tbraceCount === 0 &&\n\t\t\t\tbracketCount === 0\n\t\t\t) {\n\t\t\t\targs.push(currentArg);\n\t\t\t\tcurrentArg = \"\";\n\t\t\t} else {\n\t\t\t\tcurrentArg += char;\n\t\t\t}\n\t\t\tindex++;\n\t\t}\n\n\t\tif (parenCount === 0 && args.length > 0) {\n\t\t\treturn {\n\t\t\t\tschemaArg: args[0].trim(),\n\t\t\t\toptionsArg: args[1] ? args[1].trim() : null,\n\t\t\t};\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n * Statically extract client and shared keys from the schema content.\n *\n * @param content The schema file string content\n * @returns An object containing the extracted client and shared keys\n */\nexport function extractKeys(content: string): {\n\tclientKeys: string[];\n\tsharedKeys: string[];\n\tisLegacy?: boolean;\n} {\n\tconst clientKeys: string[] = [];\n\tconst sharedKeys: string[] = [];\n\n\tconst args = extractCallArguments(content);\n\tif (!args) {\n\t\treturn { clientKeys, sharedKeys, isLegacy: false };\n\t}\n\n\tconst trimmedSchema = args.schemaArg\n\t\t.replace(/^\\{/, \"\")\n\t\t.replace(/\\}$/, \"\")\n\t\t.trim();\n\tconst topKeys = parseBlockKeys(trimmedSchema);\n\tconst isLegacy =\n\t\ttopKeys.includes(\"client\") ||\n\t\ttopKeys.includes(\"server\") ||\n\t\ttopKeys.includes(\"shared\");\n\n\tif (isLegacy) {\n\t\tconst clientBlock = extractBlock(args.schemaArg, \"client\");\n\t\tif (clientBlock) clientKeys.push(...parseBlockKeys(clientBlock));\n\t\tconst sharedBlock = extractBlock(args.schemaArg, \"shared\");\n\t\tif (sharedBlock) sharedKeys.push(...parseBlockKeys(sharedBlock));\n\t\treturn { clientKeys, sharedKeys, isLegacy };\n\t}\n\n\tconst optionExposedKeys = args.optionsArg\n\t\t? parseExposeKeys(args.optionsArg)\n\t\t: [];\n\n\tfor (const key of topKeys) {\n\t\tif (optionExposedKeys.includes(key) || key === \"NODE_ENV\") {\n\t\t\tsharedKeys.push(key);\n\t\t\tcontinue;\n\t\t}\n\t\tif (key.startsWith(\"NEXT_PUBLIC_\")) {\n\t\t\tclientKeys.push(key);\n\t\t}\n\t}\n\n\treturn { clientKeys, sharedKeys, isLegacy };\n}\n","import path from \"node:path\";\n\nfunction generateRuntimeEnvLines(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst allKeys = Array.from(new Set([...clientKeys, ...sharedKeys]));\n\treturn allKeys\n\t\t.map(\n\t\t\t(key) =>\n\t\t\t\t`\\t\\t\\t${key}: typeof window !== \"undefined\" ? (globalThis as any).__arkenv_env__?.${key} ?? process.env.${key} : process.env.${key},`,\n\t\t)\n\t\t.join(\"\\n\");\n}\n\nconst GENERATED_HEADER = `/* eslint-disable */\n// biome-ignore format: auto-generated\n// Generated by ArkEnv. DO NOT EDIT DIRECTLY.\n`;\n\nconst GENERATED_FOOTER = `\nexport default arkenv;\n`;\n\nexport function generateFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n\tisStandard?: boolean,\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\tconst importPath = isStandard ? \"@arkenv/nextjs/standard\" : \"@arkenv/nextjs\";\n\tconst coreName = \"arkenv\";\n\tconst callPrefix = \"coreArkenv\";\n\n\treturn `${GENERATED_HEADER}\nimport { ${coreName} as coreArkenv } from \"${importPath}\";\n\nexport function arkenv<\n\tconst TServer extends Record<string, any> = {},\n\tconst TClient extends Record<string, any> = {},\n\tconst TShared extends Record<string, any> = {},\n>(options: {\n\tserver?: TServer;\n\tclient?: TClient & {\n\t\t[K in keyof TClient]: K extends \\`NEXT_PUBLIC_\\${string}\\` ? unknown : never;\n\t};\n\tshared?: TShared;\n}) {\n\treturn ${callPrefix}({\n\t\t...options,\n\t\truntimeEnv: {\n\t\t\t${runtimeEnvLines}\n\t\t},\n\t} as any) as any;\n}\n${GENERATED_FOOTER}`;\n}\n\nexport function generateFlatFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n\tisStandard?: boolean,\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\tconst importPath = isStandard ? \"@arkenv/nextjs/standard\" : \"@arkenv/nextjs\";\n\tconst coreName = \"arkenv\";\n\tconst typeImport = isStandard\n\t\t? \"\"\n\t\t: '\\nimport type { type as at, distill } from \"arktype\";';\n\tconst returnType = isStandard\n\t\t? \"Readonly<TSchema>\"\n\t\t: \"Readonly<distill.Out<at.infer<TSchema>>>\";\n\tconst castReturn = isStandard\n\t\t? \"\"\n\t\t: \" as unknown as Readonly<distill.Out<at.infer<TSchema>>>\";\n\tconst callPrefix = \"coreArkenv\";\n\n\treturn `${GENERATED_HEADER}\nimport { ${coreName} as coreArkenv } from \"${importPath}\";${typeImport}\n\nexport function arkenv<\n\tconst TSchema extends Record<string, unknown> & { runtimeEnv?: never } = {},\n\tconst TExpose extends keyof TSchema = never,\n\tconst TExtends extends readonly unknown[] = [],\n>(\n\tschema: TSchema,\n\toptions?: {\n\t\t/**\n\t\t * Custom environment variables to expose to the client bundle.\n\t\t * By default, variables prefixed with \\`NEXT_PUBLIC_\\` and \\`NODE_ENV\\` are exposed automatically.\n\t\t * Use this option to expose custom variables that do not have the \\`NEXT_PUBLIC_\\` prefix.\n\t\t */\n\t\texposeToClient?: readonly TExpose[];\n\t\textends?: [...TExtends];\n\t},\n): ${returnType} {\n\tconst env = ${callPrefix}(schema as any, {\n\t\t...options,\n\t\truntimeEnv: {\n\t\t\t${runtimeEnvLines}\n\t\t},\n\t} as any);\n\treturn env${castReturn};\n}\n${GENERATED_FOOTER}`;\n}\n\n/**\n * Ambient module declaration so `#arkenv/client-env` resolves to the project's\n * `env/client.ts` for `AutoClientEnv` type inference on `@arkenv/nextjs/server`.\n *\n * @returns Generated `.d.ts` source\n */\nexport function generateClientEnvAmbientDeclaration(\n\tclientPath?: string,\n\toutputPath?: string,\n): string {\n\tlet importTarget = \"../client\";\n\tif (clientPath && outputPath) {\n\t\tconst ambientDir = path.dirname(outputPath);\n\t\tconst rel = path.relative(ambientDir, clientPath).replace(/\\\\/g, \"/\");\n\t\tconst cleanRel = rel.replace(/\\.tsx?$/, \"\");\n\t\timportTarget = cleanRel.startsWith(\".\") ? cleanRel : `./${cleanRel}`;\n\t}\n\treturn `${GENERATED_HEADER}\ndeclare module \"#arkenv/client-env\" {\n\texport { env } from \"${importTarget}\";\n}\n`;\n}\n\nexport function generateClientFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n\tisStandard?: boolean,\n): string {\n\tconst runtimeEnvLines = generateRuntimeEnvLines(clientKeys, sharedKeys);\n\tconst importPath = isStandard\n\t\t? \"@arkenv/nextjs/standard/client\"\n\t\t: \"@arkenv/nextjs/client\";\n\tconst coreName = \"arkenv\";\n\tconst typeImport = isStandard\n\t\t? \"\"\n\t\t: '\\nimport type { Infer } from \"@arkenv/core\";';\n\tconst callPrefix = \"coreArkenv\";\n\tconst returnType = isStandard\n\t\t? \"Readonly<TSchema & MergeExtends<TExtends>>\"\n\t\t: \"Readonly<Infer<TSchema> & MergeExtends<TExtends>>\";\n\n\treturn `${GENERATED_HEADER}\nimport { ${coreName} as coreArkenv } from \"${importPath}\";${typeImport}\n\ntype ResolveExtend<T> = [Infer<T>] extends [never] ? T : Infer<T>;\n\ntype UnionToIntersection<U> = (\n\tU extends any ? (k: U) => void : never\n) extends (k: infer I) => void\n\t? I\n\t: never;\n\ntype MergeExtends<TExtends extends readonly unknown[] | undefined> =\n\tTExtends extends readonly unknown[]\n\t\t? UnionToIntersection<ResolveExtend<TExtends[number]>>\n\t\t: {};\n\nexport function arkenv<\n\tconst TSchema extends Record<string, any> = {},\n\tconst TExtends extends readonly unknown[] = [],\n>(\n\tschema: TSchema & {\n\t\t[K in keyof TSchema]: K extends \\`NEXT_PUBLIC_\\${string}\\` ? unknown : never;\n\t},\n\toptions?: {\n\t\textends?: [...TExtends];\n\t},\n): ${returnType} {\n\treturn ${callPrefix}(schema as any, {\n\t\t...options,\n\t\truntimeEnv: {\n\t\t\t${runtimeEnvLines}\n\t\t},\n\t} as any);\n}\n${GENERATED_FOOTER}`;\n}\n","import type { BuildLogHelpers } from \"@repo/log\";\nimport type { ArkEnvConfigOptions } from \"./types\";\n\nlet hasWarnedSimpleLayout = false;\n\nexport function normalizeLayout(\n\tlayout: ArkEnvConfigOptions[\"layout\"],\n\tbuildLog: BuildLogHelpers,\n): \"simple\" | \"strict\" | undefined {\n\tif (layout === \"flat\") return \"simple\";\n\tif (layout !== \"simple\") return layout;\n\n\tconst isDev = process.env.NODE_ENV === \"development\";\n\tif (!isDev || hasWarnedSimpleLayout) return \"simple\";\n\n\thasWarnedSimpleLayout = true;\n\tbuildLog.logBuildWarning(\n\t\t\"The 'simple' layout option is deprecated and will be removed in the next major version. Use 'flat' instead.\",\n\t);\n\treturn \"simple\";\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n\textractClientKeys,\n\textractSharedKeys,\n\tresolveLayout,\n} from \"@arkenv/build\";\nimport { resolveBuildLog } from \"@repo/log\";\nimport { extractKeys } from \"./extract\";\nimport {\n\tgenerateClientEnvAmbientDeclaration,\n\tgenerateClientFactoryCode,\n\tgenerateFactoryCode,\n\tgenerateFlatFactoryCode,\n} from \"./generate\";\nimport { normalizeLayout } from \"./layout\";\nimport type { ArkEnvConfigOptions } from \"./types\";\n\nfunction detectStandard(content: string, forceStandard?: boolean): boolean {\n\tif (forceStandard) return true;\n\treturn (\n\t\tcontent.includes(\"@arkenv/standard\") || content.includes(\"arkenv/standard\")\n\t);\n}\n\n/**\n * Run code generation to read the schema file and generate the env.gen.ts factory.\n *\n * @param schemaPath The absolute path to the schema file or directory\n * @param outputPath The absolute path to the generated output file\n * @param layoutOption The explicit layout to use; auto-detected from the filesystem when omitted\n * @param forceStandard Force standard mode code generation\n * @throws An error if strict layout files are missing when `layoutOption` is `\"strict\"`\n */\nexport function runCodegen(\n\tschemaPath: string,\n\toutputPath: string,\n\tlayoutOption?: ArkEnvConfigOptions[\"layout\"],\n\tforceStandard?: boolean,\n\tlogOptions?: Pick<ArkEnvConfigOptions, \"logger\" | \"logLevel\">,\n) {\n\tconst normalizedLayout = normalizeLayout(\n\t\tlayoutOption,\n\t\tresolveBuildLog(logOptions),\n\t);\n\n\tconst { layout: resolvedLayout, baseDir } = resolveLayout(\n\t\tschemaPath,\n\t\tnormalizedLayout,\n\t);\n\n\tlet generatedCode = \"\";\n\tif (resolvedLayout === \"strict\") {\n\t\tconst clientPath = path.join(baseDir, \"client.ts\");\n\t\tconst sharedPath = path.join(baseDir, \"internal\", \"shared.ts\");\n\n\t\tconst clientContent = fs.existsSync(clientPath)\n\t\t\t? fs.readFileSync(clientPath, \"utf-8\")\n\t\t\t: \"\";\n\t\tconst sharedContent = fs.existsSync(sharedPath)\n\t\t\t? fs.readFileSync(sharedPath, \"utf-8\")\n\t\t\t: \"\";\n\n\t\tconst isStandard =\n\t\t\tdetectStandard(clientContent, forceStandard) ||\n\t\t\tdetectStandard(sharedContent, forceStandard);\n\n\t\tconst clientKeys = extractClientKeys(clientContent);\n\t\tconst sharedKeys = extractSharedKeys(sharedContent);\n\n\t\tgeneratedCode = generateClientFactoryCode(\n\t\t\tclientKeys,\n\t\t\tsharedKeys,\n\t\t\tisStandard,\n\t\t);\n\t} else {\n\t\tconst fileContent = fs.readFileSync(schemaPath, \"utf-8\");\n\t\tconst isStandard = detectStandard(fileContent, forceStandard);\n\n\t\tconst { clientKeys, sharedKeys, isLegacy } = extractKeys(fileContent);\n\t\tif (isLegacy) {\n\t\t\tgeneratedCode = generateFactoryCode(clientKeys, sharedKeys, isStandard);\n\t\t} else {\n\t\t\tgeneratedCode = generateFlatFactoryCode(\n\t\t\t\tclientKeys,\n\t\t\t\tsharedKeys,\n\t\t\t\tisStandard,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst outputDir = path.dirname(outputPath);\n\tif (!fs.existsSync(outputDir)) {\n\t\tfs.mkdirSync(outputDir, { recursive: true });\n\t}\n\n\tlet shouldWrite = true;\n\tif (fs.existsSync(outputPath)) {\n\t\tconst existingContent = fs.readFileSync(outputPath, \"utf-8\");\n\t\tif (existingContent === generatedCode) {\n\t\t\tshouldWrite = false;\n\t\t}\n\t}\n\n\tif (shouldWrite) {\n\t\tfs.writeFileSync(outputPath, generatedCode, \"utf-8\");\n\t}\n\n\tconst barrelPath = path.join(outputDir, \"index.ts\");\n\tconst barrelCode = `export * from \"./env.gen\";\\nexport { default } from \"./env.gen\";\\n`;\n\tif (path.basename(outputDir) === \".arkenv\" || !fs.existsSync(barrelPath)) {\n\t\tlet shouldWriteBarrel = true;\n\t\tif (fs.existsSync(barrelPath)) {\n\t\t\tif (fs.readFileSync(barrelPath, \"utf-8\") === barrelCode) {\n\t\t\t\tshouldWriteBarrel = false;\n\t\t\t}\n\t\t}\n\t\tif (shouldWriteBarrel) {\n\t\t\tfs.writeFileSync(barrelPath, barrelCode, \"utf-8\");\n\t\t}\n\t}\n\n\tif (resolvedLayout === \"strict\" && baseDir) {\n\t\tconst ambientPath = path.join(\n\t\t\tpath.dirname(outputPath),\n\t\t\t\"arkenv-client-env.d.ts\",\n\t\t);\n\t\tconst clientPath = path.join(baseDir, \"client.ts\");\n\t\tconst ambientCode = generateClientEnvAmbientDeclaration(\n\t\t\tclientPath,\n\t\t\toutputPath,\n\t\t);\n\t\tlet shouldWriteAmbient = true;\n\t\tif (fs.existsSync(ambientPath)) {\n\t\t\tif (fs.readFileSync(ambientPath, \"utf-8\") === ambientCode) {\n\t\t\t\tshouldWriteAmbient = false;\n\t\t\t}\n\t\t}\n\t\tif (shouldWriteAmbient) {\n\t\t\tfs.writeFileSync(ambientPath, ambientCode, \"utf-8\");\n\t\t}\n\t}\n}\n","import path from \"node:path\";\nimport type { CLIENT_ENV_SPECIFIER } from \"../strict-client-env\";\n\ntype WebpackConfigLike = {\n\tresolve?: {\n\t\talias?:\n\t\t\t| Record<string, string | false | string[]>\n\t\t\t| Array<{ name: string; alias: string | false | string[] }>;\n\t};\n\tplugins?: unknown[];\n};\n\ntype WebpackLike = {\n\tDefinePlugin: new (definitions: Record<string, string>) => unknown;\n};\n\ntype WebpackContextLike = {\n\twebpack?: WebpackLike;\n};\n\ntype TurbopackResolveAlias = Record<string, string | string[]>;\n\ntype NextConfigLike = {\n\twebpack?: (\n\t\tconfig: WebpackConfigLike,\n\t\tcontext: WebpackContextLike,\n\t) => WebpackConfigLike | undefined;\n\tturbopack?: {\n\t\tresolveAlias?: TurbopackResolveAlias;\n\t\t[key: string]: unknown;\n\t};\n\texperimental?: {\n\t\tturbo?: {\n\t\t\tresolveAlias?: TurbopackResolveAlias;\n\t\t\t[key: string]: unknown;\n\t\t};\n\t\t[key: string]: unknown;\n\t};\n\tenv?: Record<string, string | undefined>;\n\t[key: string]: unknown;\n};\n\n/**\n * Merge `#arkenv/client-env` into a webpack `resolve.alias` value (object or array form).\n *\n * @param alias Existing webpack resolve.alias\n * @param specifier Virtual module specifier\n * @param target Absolute path to the project client env module\n * @returns Updated alias value\n */\nfunction mergeWebpackAlias(\n\talias:\n\t\t| Record<string, string | false | string[]>\n\t\t| Array<{ name: string; alias: string | false | string[] }>\n\t\t| undefined,\n\tspecifier: string,\n\ttarget: string,\n):\n\t| Record<string, string | false | string[]>\n\t| Array<{ name: string; alias: string | false | string[] }> {\n\tif (Array.isArray(alias)) {\n\t\tconst next = alias.filter((entry) => entry.name !== specifier);\n\t\tnext.push({ name: specifier, alias: target });\n\t\treturn next;\n\t}\n\treturn {\n\t\t...(alias ?? {}),\n\t\t[specifier]: target,\n\t};\n}\n\n/**\n * Apply webpack + Turbopack aliases and a compile-time strict-layout flag.\n *\n * Chains any existing `webpack` function on the user config. Turbopack aliases\n * are written to both `turbopack.resolveAlias` (Next 15+) and\n * `experimental.turbo.resolveAlias` for older configs.\n *\n * @param nextConfig User Next.js config object\n * @param clientEnvPath Absolute path to `env/client.ts`\n * @param specifier Virtual module specifier (typically `#arkenv/client-env`)\n * @returns Next config with strict-layout alias wiring\n */\nexport function applyStrictLayoutAliases<T extends NextConfigLike>(\n\tnextConfig: T,\n\tclientEnvPath: string,\n\tspecifier: typeof CLIENT_ENV_SPECIFIER | string = \"#arkenv/client-env\",\n): T {\n\tconst previousWebpack = nextConfig.webpack;\n\n\tconst webpack = (config: WebpackConfigLike, context: WebpackContextLike) => {\n\t\tconst resolved = previousWebpack\n\t\t\t? (previousWebpack(config, context) ?? config)\n\t\t\t: config;\n\t\tresolved.resolve = resolved.resolve ?? {};\n\t\tresolved.resolve.alias = mergeWebpackAlias(\n\t\t\tresolved.resolve.alias,\n\t\t\tspecifier,\n\t\t\tclientEnvPath,\n\t\t);\n\n\t\tconst DefinePlugin = context.webpack?.DefinePlugin;\n\t\tif (DefinePlugin) {\n\t\t\tresolved.plugins = resolved.plugins ?? [];\n\t\t\tresolved.plugins.push(\n\t\t\t\tnew DefinePlugin({\n\t\t\t\t\t__ARKENV_STRICT_LAYOUT__: JSON.stringify(true),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn resolved;\n\t};\n\n\tconst turbopackTarget = path.isAbsolute(clientEnvPath)\n\t\t? `./${path.relative(process.cwd(), clientEnvPath).replace(/\\\\/g, \"/\")}`\n\t\t: clientEnvPath.startsWith(\".\")\n\t\t\t? clientEnvPath\n\t\t\t: `./${clientEnvPath}`;\n\n\tconst existingTurbopack = nextConfig.turbopack ?? {};\n\tconst turbopackResolveAlias: TurbopackResolveAlias = {\n\t\t...(existingTurbopack.resolveAlias ?? {}),\n\t\t[specifier]: turbopackTarget,\n\t};\n\n\tconst existingExperimental = nextConfig.experimental;\n\tconst experimental = existingExperimental\n\t\t? {\n\t\t\t\t...existingExperimental,\n\t\t\t\t...(existingExperimental.turbo\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tturbo: {\n\t\t\t\t\t\t\t\t...existingExperimental.turbo,\n\t\t\t\t\t\t\t\tresolveAlias: {\n\t\t\t\t\t\t\t\t\t...(existingExperimental.turbo.resolveAlias ?? {}),\n\t\t\t\t\t\t\t\t\t[specifier]: turbopackTarget,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t}\n\t\t: undefined;\n\n\t// Spread as a plain object. Callers must pass a resolved config object —\n\t// `withArkEnv` awaits function-form `next.config` before calling this.\n\tconst result: Record<string, unknown> = {\n\t\t...nextConfig,\n\t\twebpack,\n\t\t// Turbopack / non-webpack paths: surface the flag via Next env inlining.\n\t\t// Note: Next.js forbids keys with __ prefix in nextConfig.env, so we use\n\t\t// ARKENV_STRICT_LAYOUT (no underscores) here. The webpack DefinePlugin\n\t\t// path uses __ARKENV_STRICT_LAYOUT__ as a compile-time literal, which is fine.\n\t\tenv: {\n\t\t\t...(nextConfig.env ?? {}),\n\t\t\tARKENV_STRICT_LAYOUT: \"true\",\n\t\t},\n\t\tturbopack: {\n\t\t\t...existingTurbopack,\n\t\t\tresolveAlias: turbopackResolveAlias,\n\t\t},\n\t};\n\n\tif (experimental) {\n\t\tresult.experimental = experimental;\n\t}\n\n\treturn result as T;\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n\tfindSchemaPath,\n\tformatMissingSchemaError,\n\tresolveLayout,\n\twatchSchema,\n} from \"@arkenv/build\";\nimport {\n\tformatBuildError,\n\tresolveBuildLog,\n\tresolveLoggerFromOptions,\n} from \"@repo/log\";\nimport { createJiti } from \"jiti\";\nimport {\n\tCLIENT_ENV_SPECIFIER,\n\tmissingClientTsError,\n} from \"../strict-client-env\";\nimport { runCodegen } from \"./codegen\";\nimport { normalizeLayout } from \"./layout\";\nimport { applyStrictLayoutAliases } from \"./strict-layout-aliases\";\nimport type {\n\tArkEnvConfigOptions,\n\tNextConfigContext,\n\tNextConfigFactory,\n} from \"./types\";\n\nfunction resolveMockServerOnlyPath(moduleDir: string): string {\n\tfor (const base of [moduleDir, path.join(moduleDir, \"..\")]) {\n\t\tconst tsPath = path.join(base, \"mock-server-only.ts\");\n\t\tif (fs.existsSync(tsPath)) {\n\t\t\treturn tsPath;\n\t\t}\n\t\tconst jsPath = path.join(base, \"mock-server-only.js\");\n\t\tif (fs.existsSync(jsPath)) {\n\t\t\treturn jsPath;\n\t\t}\n\t}\n\n\treturn path.join(moduleDir, \"mock-server-only.js\");\n}\n\nfunction resolveEmptyClientEnvPath(moduleDir: string): string {\n\tfor (const base of [moduleDir, path.join(moduleDir, \"..\")]) {\n\t\tconst tsPath = path.join(base, \"empty-client-env.ts\");\n\t\tif (fs.existsSync(tsPath)) {\n\t\t\treturn tsPath;\n\t\t}\n\t\tconst jsPath = path.join(base, \"empty-client-env.js\");\n\t\tif (fs.existsSync(jsPath)) {\n\t\t\treturn jsPath;\n\t\t}\n\t}\n\n\treturn path.join(moduleDir, \"empty-client-env.js\");\n}\n\nfunction schemaPathExists(schemaPath: string): boolean {\n\tif (fs.existsSync(schemaPath)) return true;\n\n\tconst ext = path.extname(schemaPath);\n\tif (!ext) return false;\n\n\tconst baseWithoutExt = schemaPath.slice(0, -ext.length);\n\treturn fs.existsSync(baseWithoutExt);\n}\n\ntype SetupResult = {\n\tresolvedLayout: \"flat\" | \"strict\" | \"simple\";\n\tbaseDir: string | undefined;\n\tclientEnvPath: string | undefined;\n\toutputPath: string;\n};\n\n/**\n * Run ArkEnv codegen and setup without wrapping nextConfig.\n *\n * @param options Optional configuration paths for schema and output files\n * @param internalOptions Optional configuration for internal testing hooks\n * @returns Resolved layout paths used by `withArkEnv` for alias registration\n * @throws An error if the schema file cannot be found or if code generation fails\n */\nexport function setupArkEnv(\n\toptions?: ArkEnvConfigOptions,\n\tinternalOptions?: { _jitiAliases?: Record<string, string> },\n): SetupResult {\n\tconst buildLog = resolveBuildLog(options);\n\n\tconst schemaPath = options?.schemaPath\n\t\t? path.resolve(options.schemaPath)\n\t\t: findSchemaPath();\n\n\tif (!schemaPath || !schemaPathExists(schemaPath)) {\n\t\tthrow new Error(\n\t\t\tformatMissingSchemaError({\n\t\t\t\tschemaPath: options?.schemaPath,\n\t\t\t\toptionsHint: \"setupArkEnv options\",\n\t\t\t}),\n\t\t);\n\t}\n\n\tconst normalizedLayout = normalizeLayout(options?.layout, buildLog);\n\n\tconst { layout: resolvedLayout, baseDir } = resolveLayout(\n\t\tschemaPath,\n\t\tnormalizedLayout,\n\t);\n\n\tconst clientEnvPath =\n\t\tresolvedLayout === \"strict\" && baseDir\n\t\t\t? path.join(baseDir, \"client.ts\")\n\t\t\t: undefined;\n\n\tif (clientEnvPath && !fs.existsSync(clientEnvPath)) {\n\t\tthrow new Error(missingClientTsError(clientEnvPath, baseDir!));\n\t}\n\n\tfunction resolveProjectRoot(\n\t\tschema: string,\n\t\tbase?: string,\n\t\tlayout?: string,\n\t): string {\n\t\tif (layout === \"strict\" && base) {\n\t\t\tlet dir = base;\n\t\t\tif (path.basename(dir) === \"env\") {\n\t\t\t\tdir = path.dirname(dir);\n\t\t\t}\n\t\t\tif (path.basename(dir) === \"src\") {\n\t\t\t\tdir = path.dirname(dir);\n\t\t\t}\n\t\t\treturn dir;\n\t\t}\n\t\tlet dir = path.dirname(schema);\n\t\tif (path.basename(dir) === \"src\") {\n\t\t\tdir = path.dirname(dir);\n\t\t}\n\t\treturn dir;\n\t}\n\n\tconst projectRoot = resolveProjectRoot(schemaPath, baseDir, resolvedLayout);\n\tconst defaultOutputPath = path.join(projectRoot, \".arkenv\", \"env.gen.ts\");\n\tconst outputPath = options?.outputPath\n\t\t? path.resolve(options.outputPath)\n\t\t: defaultOutputPath;\n\n\tconst codegen = options?.codegen ?? true;\n\tif (codegen) {\n\t\ttry {\n\t\t\trunCodegen(\n\t\t\t\tschemaPath,\n\t\t\t\toutputPath,\n\t\t\t\tresolvedLayout,\n\t\t\t\toptions?.standard,\n\t\t\t\toptions,\n\t\t\t);\n\t\t} catch (error: unknown) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(\n\t\t\t\tformatBuildError(`Failed to generate env.gen.ts: ${message}`),\n\t\t\t);\n\t\t}\n\t}\n\n\tconst runValidation = options?.validate ?? true;\n\tif (runValidation) {\n\t\tconst g = globalThis as {\n\t\t\t__arkenv_force_server__?: boolean;\n\t\t\t__ARKENV_STRICT_LAYOUT__?: boolean;\n\t\t\t__ARKENV_CLIENT_ENV__?: unknown;\n\t\t};\n\t\ttry {\n\t\t\tg.__arkenv_force_server__ = true;\n\t\t\tconst fileToEvaluate =\n\t\t\t\tresolvedLayout === \"strict\" && baseDir\n\t\t\t\t\t? path.join(baseDir, \"server.ts\")\n\t\t\t\t\t: schemaPath;\n\n\t\t\tconst filenameForJiti =\n\t\t\t\ttypeof __filename !== \"undefined\"\n\t\t\t\t\t? __filename\n\t\t\t\t\t: typeof import.meta !== \"undefined\" && import.meta.url\n\t\t\t\t\t\t? fileURLToPath(import.meta.url)\n\t\t\t\t\t\t: \"\";\n\t\t\tconst dir = path.dirname(filenameForJiti);\n\t\t\tconst mockServerOnlyPath = resolveMockServerOnlyPath(dir);\n\t\t\tconst emptyClientEnvPath = resolveEmptyClientEnvPath(dir);\n\n\t\t\tconst aliases: Record<string, string> = {\n\t\t\t\t\"server-only\": mockServerOnlyPath,\n\t\t\t\t\"./script\": mockServerOnlyPath,\n\t\t\t\t\"./script.tsx\": mockServerOnlyPath,\n\t\t\t\t[CLIENT_ENV_SPECIFIER]:\n\t\t\t\t\tclientEnvPath && fs.existsSync(clientEnvPath)\n\t\t\t\t\t\t? clientEnvPath\n\t\t\t\t\t\t: emptyClientEnvPath,\n\t\t\t\t...internalOptions?._jitiAliases,\n\t\t\t};\n\n\t\t\tconst jiti = createJiti(fileToEvaluate, {\n\t\t\t\tmoduleCache: false,\n\t\t\t\tfsCache: false,\n\t\t\t\ttsconfigPaths: true,\n\t\t\t\talias: aliases,\n\t\t\t});\n\n\t\t\tif (resolvedLayout === \"strict\" && clientEnvPath) {\n\t\t\t\tg.__ARKENV_STRICT_LAYOUT__ = true;\n\t\t\t\tconst clientMod = jiti(clientEnvPath) as {\n\t\t\t\t\tenv?: unknown;\n\t\t\t\t\tdefault?: { env?: unknown };\n\t\t\t\t};\n\t\t\t\tg.__ARKENV_CLIENT_ENV__ =\n\t\t\t\t\tclientMod.env ?? clientMod.default?.env ?? clientMod;\n\t\t\t}\n\n\t\t\tjiti(fileToEvaluate);\n\t\t} catch (error: unknown) {\n\t\t\tbuildLog.logBuildError(\"Environment validation failed:\");\n\t\t\tbuildLog.logBuildErrorDetail(\n\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t);\n\t\t\tbuildLog.logBuildErrorBlankLine();\n\t\t\tprocess.exit(1);\n\t\t} finally {\n\t\t\tdelete g.__arkenv_force_server__;\n\t\t\tdelete g.__ARKENV_STRICT_LAYOUT__;\n\t\t\tdelete g.__ARKENV_CLIENT_ENV__;\n\t\t}\n\t}\n\n\tconst isDev =\n\t\tprocess.env.NODE_ENV === \"development\" ||\n\t\tprocess.env.NEXT_PHASE === \"phase-development-server\";\n\tif (isDev && codegen) {\n\t\tconst watchPaths =\n\t\t\tresolvedLayout === \"strict\" && baseDir\n\t\t\t\t? [\n\t\t\t\t\t\tpath.join(baseDir, \"internal\", \"shared.ts\"),\n\t\t\t\t\t\tpath.join(baseDir, \"client.ts\"),\n\t\t\t\t\t\tpath.join(baseDir, \"server.ts\"),\n\t\t\t\t\t].filter(fs.existsSync)\n\t\t\t\t: [schemaPath];\n\t\twatchSchema(\n\t\t\twatchPaths,\n\t\t\t() => {\n\t\t\t\trunCodegen(\n\t\t\t\t\tschemaPath,\n\t\t\t\t\toutputPath,\n\t\t\t\t\tresolvedLayout,\n\t\t\t\t\toptions?.standard,\n\t\t\t\t\toptions,\n\t\t\t\t);\n\t\t\t},\n\t\t\tresolveLoggerFromOptions(options),\n\t\t);\n\t}\n\n\treturn {\n\t\tresolvedLayout,\n\t\tbaseDir,\n\t\tclientEnvPath,\n\t\toutputPath,\n\t};\n}\n\ntype AliasableNextConfig = Record<string, unknown> & {\n\tturbopack?: {\n\t\tresolveAlias?: Record<string, unknown>;\n\t\t[key: string]: unknown;\n\t};\n\twebpack?: (webpackConfig: never, context: never) => unknown;\n};\n\n/**\n * Apply strict-layout and virtual `.arkenv/` aliases to a resolved Next.js config object.\n *\n * @param configObj The resolved Next.js configuration object\n * @param options Optional configuration paths for schema and output files\n * @param setup Result of `setupArkEnv` for the current invocation\n * @returns The configuration object with webpack and Turbopack aliases\n */\nfunction applyArkEnvAliases<T extends object>(\n\tconfigObj: T,\n\toptions: ArkEnvConfigOptions | undefined,\n\tsetup: SetupResult,\n): T {\n\tconst { resolvedLayout, clientEnvPath, outputPath: targetGenPath } = setup;\n\tlet currentConfig = configObj as AliasableNextConfig;\n\n\tif (resolvedLayout === \"strict\" && clientEnvPath) {\n\t\tcurrentConfig = applyStrictLayoutAliases(\n\t\t\tcurrentConfig as never,\n\t\t\tclientEnvPath,\n\t\t\tCLIENT_ENV_SPECIFIER,\n\t\t) as AliasableNextConfig;\n\t}\n\n\tconst rootDir = process.cwd();\n\tconst targetGenPathToUse =\n\t\ttargetGenPath ??\n\t\t(options?.outputPath\n\t\t\t? path.resolve(options.outputPath)\n\t\t\t: path.join(rootDir, \".arkenv\", \"env.gen.ts\"));\n\tconst relativeGenPath = `./${path.relative(rootDir, targetGenPathToUse).replace(/\\\\/g, \"/\")}`;\n\n\tconst turbopack = {\n\t\t...currentConfig.turbopack,\n\t\tresolveAlias: {\n\t\t\t\".arkenv/env.gen\": relativeGenPath,\n\t\t\t\".arkenv/env.gen.ts\": relativeGenPath,\n\t\t\t\".arkenv\": relativeGenPath,\n\t\t\t\".arkenv/index\": relativeGenPath,\n\t\t\t\".arkenv/index.ts\": relativeGenPath,\n\t\t\t\"#arkenv/env\": relativeGenPath,\n\t\t\t\"@/.arkenv\": relativeGenPath,\n\t\t\t\"@/.arkenv/env.gen\": relativeGenPath,\n\t\t\t...currentConfig.turbopack?.resolveAlias,\n\t\t},\n\t};\n\n\tconst previousWebpack = currentConfig.webpack;\n\tconst webpack = (webpackConfig: never, context: never) => {\n\t\tconst resolvedConfig = webpackConfig as {\n\t\t\tresolve?: { alias?: Record<string, unknown> };\n\t\t};\n\t\tresolvedConfig.resolve = resolvedConfig.resolve ?? {};\n\t\tresolvedConfig.resolve.alias = {\n\t\t\t...resolvedConfig.resolve.alias,\n\t\t\t\".arkenv/env.gen\": targetGenPathToUse,\n\t\t\t\".arkenv/env.gen.ts\": targetGenPathToUse,\n\t\t\t\".arkenv\": targetGenPathToUse,\n\t\t\t\".arkenv/index\": targetGenPathToUse,\n\t\t\t\".arkenv/index.ts\": targetGenPathToUse,\n\t\t\t\"#arkenv/env\": targetGenPathToUse,\n\t\t\t\"@/.arkenv\": targetGenPathToUse,\n\t\t\t\"@/.arkenv/env.gen\": targetGenPathToUse,\n\t\t};\n\t\tif (typeof previousWebpack === \"function\") {\n\t\t\treturn previousWebpack(resolvedConfig as never, context);\n\t\t}\n\t\treturn resolvedConfig;\n\t};\n\n\treturn {\n\t\t...currentConfig,\n\t\tturbopack,\n\t\twebpack,\n\t} as unknown as T;\n}\n\n/**\n * Wrap a Next.js configuration object or function to generate `runtimeEnv` in\n * `env.gen.ts`, register `#arkenv/client-env` in strict layout for auto-extend,\n * and configure Turbopack/Webpack aliases for virtualized `.arkenv/` placement.\n *\n * Function-form configs (sync or async) are preserved: ArkEnv awaits the user's\n * factory, then applies aliases to the resolved object.\n *\n * @param nextConfig The Next.js configuration object or `(phase, context)` factory\n * @param options Optional configuration paths for schema and output files\n * @returns The Next.js configuration object, or an async factory that resolves to it\n * @throws An error if the schema file cannot be found or if code generation fails\n *\n * @example\n * ```ts\n * export default withArkEnv({ reactStrictMode: true });\n *\n * export default withArkEnv(async (phase, { defaultConfig }) => ({\n * ...defaultConfig,\n * reactStrictMode: phase !== \"phase-test\",\n * }));\n * ```\n */\nexport function withArkEnv<T extends object>(\n\tnextConfig: NextConfigFactory<T>,\n\toptions?: ArkEnvConfigOptions,\n): (phase: string, context: NextConfigContext) => Promise<T>;\nexport function withArkEnv<T extends object>(\n\tnextConfig: T,\n\toptions?: ArkEnvConfigOptions,\n): T;\nexport function withArkEnv<T extends object>(\n\tnextConfig: T | NextConfigFactory<T>,\n\toptions?: ArkEnvConfigOptions,\n): T | ((phase: string, context: NextConfigContext) => Promise<T>) {\n\tif (typeof nextConfig === \"function\") {\n\t\treturn async (phase: string, context: NextConfigContext) => {\n\t\t\tconst setup = setupArkEnv(options);\n\t\t\tconst resolved = await nextConfig(phase, context);\n\t\t\treturn applyArkEnvAliases(resolved, options, setup);\n\t\t};\n\t}\n\n\tif (nextConfig && typeof nextConfig === \"object\") {\n\t\tconst setup = setupArkEnv(options);\n\t\treturn applyArkEnvAliases(nextConfig, options, setup);\n\t}\n\n\treturn nextConfig;\n}\n"],"mappings":"ydAEA,SAAS,EAAgB,EAA8B,CACtD,IAAM,EACL,EAAW,MAAM,sCAAsC,EACvD,EAAW,MAAM,8BAA8B,EAC/C,EAAW,MAAM,8BAA8B,CAChD,GAAI,CAAC,EAAa,MAAO,EAAE,CAE3B,IAAM,EAAiB,EAAE,CACzB,IAAK,IAAM,KAAS,EAAY,GAAG,SAAS,mBAAmB,CAC9D,EAAK,KAAK,EAAM,GAAG,CAEpB,OAAO,EAGR,SAAS,EACR,EAC0D,CAC1D,IAAM,EAAQ,+BACd,KAAO,EAAM,KAAK,EAAQ,GAAK,MAAM,CACpC,IAAI,EAAa,EACb,EAAQ,EAAM,UACd,EAA0B,KAC1B,EAAuC,KACvC,EAAa,EACb,EAAe,EAEb,EAAiB,EAAE,CACrB,EAAa,GAEjB,KAAO,EAAQ,EAAQ,QAAU,EAAa,GAAG,CAChD,IAAM,EAAO,EAAQ,GACf,EAAW,EAAQ,EAAQ,GAEjC,GAAI,IAAc,SAAU,EACvB,IAAS;GAAQ,IAAS,QAAM,EAAY,MAChD,GAAc,EACd,IACA,SAED,GAAI,IAAc,QAAS,CAC1B,GAAI,IAAS,KAAO,IAAa,IAAK,CACrC,EAAY,KACZ,GAAc,KACd,GAAS,EACT,SAED,GAAc,EACd,IACA,SAGD,GAAI,EAAU,CACT,IAAS,GAAY,EAAQ,EAAQ,KAAO,OAC/C,EAAW,MAEZ,GAAc,EACd,IACA,SAGD,GAAI,IAAS,KAAO,IAAa,IAAK,CACrC,EAAY,SACZ,GAAc,KACd,GAAS,EACT,SAED,GAAI,IAAS,KAAO,IAAa,IAAK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AW,EAAO,EAAQ,CACb,EAAS,EAAM,EAIjD,GAAc,OAAO,GAAe,SAEhC,EAAmB,EAAY,EADxB,EAAY,EAC0B,CAAC,CAG/C"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=require(`./dist-Bof1Std7.cjs`),l=require(`./strict-client-env-MouPnkRr.cjs`);let u=require(`@arkenv/build`),d=require(`node:fs`);d=s(d,1);let f=require(`node:path`);f=s(f,1);let p=require(`node:url`),m=require(`jiti`);function h(e){let t=e.match(/exposeToClient\s*:\s*\[([\s\S]*?)\]/)||e.match(/expose\s*:\s*\[([\s\S]*?)\]/)||e.match(/shared\s*:\s*\[([\s\S]*?)\]/);if(!t)return[];let n=[];for(let e of t[1].matchAll(/['"`](.*?)['"`]/g))n.push(e[1]);return n}function g(e){let t=/\b(?:arkenv|createEnv)\s*\(/g;for(;t.exec(e)!==null;){let n=1,r=t.lastIndex,i=null,a=null,o=0,s=0,c=[],l=``;for(;r<e.length&&n>0;){let t=e[r],u=e[r+1];if(a===`single`){(t===`
|
|
2
|
+
`||t===`\r`)&&(a=null),l+=t,r++;continue}if(a===`multi`){if(t===`*`&&u===`/`){a=null,l+=`*/`,r+=2;continue}l+=t,r++;continue}if(i){t===i&&e[r-1]!==`\\`&&(i=null),l+=t,r++;continue}if(t===`/`&&u===`/`){a=`single`,l+=`//`,r+=2;continue}if(t===`/`&&u===`*`){a=`multi`,l+=`/*`,r+=2;continue}if(t===`'`||t===`"`||t==="`"){i=t,l+=t,r++;continue}if(t===`(`?n++:t===`)`?n--:t===`{`?o++:t===`}`?o--:t===`[`?s++:t===`]`&&s--,n===0){c.push(l);break}t===`,`&&n===1&&o===0&&s===0?(c.push(l),l=``):l+=t,r++}if(n===0&&c.length>0)return{schemaArg:c[0].trim(),optionsArg:c[1]?c[1].trim():null}}return null}function _(e){let t=[],n=[],r=g(e);if(!r)return{clientKeys:t,sharedKeys:n,isLegacy:!1};let i=(0,u.parseBlockKeys)(r.schemaArg.replace(/^\{/,``).replace(/\}$/,``).trim()),a=i.includes(`client`)||i.includes(`server`)||i.includes(`shared`);if(a){let e=(0,u.extractBlock)(r.schemaArg,`client`);e&&t.push(...(0,u.parseBlockKeys)(e));let i=(0,u.extractBlock)(r.schemaArg,`shared`);return i&&n.push(...(0,u.parseBlockKeys)(i)),{clientKeys:t,sharedKeys:n,isLegacy:a}}let o=r.optionsArg?h(r.optionsArg):[];for(let e of i){if(o.includes(e)||e===`NODE_ENV`){n.push(e);continue}e.startsWith(`NEXT_PUBLIC_`)&&t.push(e)}return{clientKeys:t,sharedKeys:n,isLegacy:a}}function v(e,t){return Array.from(new Set([...e,...t])).map(e=>`\t\t\t${e}: typeof window !== "undefined" ? (globalThis as any).__arkenv_env__?.${e} ?? process.env.${e} : process.env.${e},`).join(`
|
|
3
|
+
`)}const y=`/* eslint-disable */
|
|
4
|
+
// biome-ignore format: auto-generated
|
|
5
|
+
// Generated by ArkEnv. DO NOT EDIT DIRECTLY.
|
|
6
|
+
`,b=`
|
|
7
|
+
export default arkenv;
|
|
8
|
+
`;function x(e,t,n){let r=v(e,t);return`${y}
|
|
9
|
+
import { arkenv as coreArkenv } from "${n?`@arkenv/nextjs/standard`:`@arkenv/nextjs`}";
|
|
10
|
+
|
|
11
|
+
export function arkenv<
|
|
12
|
+
const TServer extends Record<string, any> = {},
|
|
13
|
+
const TClient extends Record<string, any> = {},
|
|
14
|
+
const TShared extends Record<string, any> = {},
|
|
15
|
+
>(options: {
|
|
16
|
+
server?: TServer;
|
|
17
|
+
client?: TClient & {
|
|
18
|
+
[K in keyof TClient]: K extends \`NEXT_PUBLIC_\${string}\` ? unknown : never;
|
|
19
|
+
};
|
|
20
|
+
shared?: TShared;
|
|
21
|
+
}) {
|
|
22
|
+
return coreArkenv({
|
|
23
|
+
...options,
|
|
24
|
+
runtimeEnv: {
|
|
25
|
+
${r}
|
|
26
|
+
},
|
|
27
|
+
} as any) as any;
|
|
28
|
+
}
|
|
29
|
+
${b}`}function S(e,t,n){let r=v(e,t);return`${y}
|
|
30
|
+
import { arkenv as coreArkenv } from "${n?`@arkenv/nextjs/standard`:`@arkenv/nextjs`}";${n?``:`
|
|
31
|
+
import type { type as at, distill } from "arktype";`}
|
|
32
|
+
|
|
33
|
+
export function arkenv<
|
|
34
|
+
const TSchema extends Record<string, unknown> & { runtimeEnv?: never } = {},
|
|
35
|
+
const TExpose extends keyof TSchema = never,
|
|
36
|
+
const TExtends extends readonly unknown[] = [],
|
|
37
|
+
>(
|
|
38
|
+
schema: TSchema,
|
|
39
|
+
options?: {
|
|
40
|
+
/**
|
|
41
|
+
* Custom environment variables to expose to the client bundle.
|
|
42
|
+
* By default, variables prefixed with \`NEXT_PUBLIC_\` and \`NODE_ENV\` are exposed automatically.
|
|
43
|
+
* Use this option to expose custom variables that do not have the \`NEXT_PUBLIC_\` prefix.
|
|
44
|
+
*/
|
|
45
|
+
exposeToClient?: readonly TExpose[];
|
|
46
|
+
extends?: [...TExtends];
|
|
47
|
+
},
|
|
48
|
+
): ${n?`Readonly<TSchema>`:`Readonly<distill.Out<at.infer<TSchema>>>`} {
|
|
49
|
+
const env = coreArkenv(schema as any, {
|
|
50
|
+
...options,
|
|
51
|
+
runtimeEnv: {
|
|
52
|
+
${r}
|
|
53
|
+
},
|
|
54
|
+
} as any);
|
|
55
|
+
return env${n?``:` as unknown as Readonly<distill.Out<at.infer<TSchema>>>`};
|
|
56
|
+
}
|
|
57
|
+
${b}`}function C(e,t){let n=`../client`;if(e&&t){let r=f.default.dirname(t),i=f.default.relative(r,e).replace(/\\/g,`/`).replace(/\.tsx?$/,``);n=i.startsWith(`.`)?i:`./${i}`}return`${y}
|
|
58
|
+
declare module "#arkenv/client-env" {
|
|
59
|
+
export { env } from "${n}";
|
|
60
|
+
}
|
|
61
|
+
`}function w(e,t,n){let r=v(e,t);return`${y}
|
|
62
|
+
import { arkenv as coreArkenv } from "${n?`@arkenv/nextjs/standard/client`:`@arkenv/nextjs/client`}";${n?``:`
|
|
63
|
+
import type { Infer } from "@arkenv/core";`}
|
|
64
|
+
|
|
65
|
+
type ResolveExtend<T> = [Infer<T>] extends [never] ? T : Infer<T>;
|
|
66
|
+
|
|
67
|
+
type UnionToIntersection<U> = (
|
|
68
|
+
U extends any ? (k: U) => void : never
|
|
69
|
+
) extends (k: infer I) => void
|
|
70
|
+
? I
|
|
71
|
+
: never;
|
|
72
|
+
|
|
73
|
+
type MergeExtends<TExtends extends readonly unknown[] | undefined> =
|
|
74
|
+
TExtends extends readonly unknown[]
|
|
75
|
+
? UnionToIntersection<ResolveExtend<TExtends[number]>>
|
|
76
|
+
: {};
|
|
77
|
+
|
|
78
|
+
export function arkenv<
|
|
79
|
+
const TSchema extends Record<string, any> = {},
|
|
80
|
+
const TExtends extends readonly unknown[] = [],
|
|
81
|
+
>(
|
|
82
|
+
schema: TSchema & {
|
|
83
|
+
[K in keyof TSchema]: K extends \`NEXT_PUBLIC_\${string}\` ? unknown : never;
|
|
84
|
+
},
|
|
85
|
+
options?: {
|
|
86
|
+
extends?: [...TExtends];
|
|
87
|
+
},
|
|
88
|
+
): ${n?`Readonly<TSchema & MergeExtends<TExtends>>`:`Readonly<Infer<TSchema> & MergeExtends<TExtends>>`} {
|
|
89
|
+
return coreArkenv(schema as any, {
|
|
90
|
+
...options,
|
|
91
|
+
runtimeEnv: {
|
|
92
|
+
${r}
|
|
93
|
+
},
|
|
94
|
+
} as any);
|
|
95
|
+
}
|
|
96
|
+
${b}`}let T=!1;function E(e,t){return e===`flat`?`simple`:e===`simple`?process.env.NODE_ENV!==`development`||T?`simple`:(T=!0,t.logBuildWarning(`The 'simple' layout option is deprecated and will be removed in the next major version. Use 'flat' instead.`),`simple`):e}function D(e,t){return t?!0:e.includes(`@arkenv/standard`)||e.includes(`arkenv/standard`)}function O(e,t,n,r,i){let{layout:a,baseDir:o}=(0,u.resolveLayout)(e,E(n,c.n(i))),s=``;if(a===`strict`){let e=f.default.join(o,`client.ts`),t=f.default.join(o,`internal`,`shared.ts`),n=d.default.existsSync(e)?d.default.readFileSync(e,`utf-8`):``,i=d.default.existsSync(t)?d.default.readFileSync(t,`utf-8`):``,a=D(n,r)||D(i,r);s=w((0,u.extractClientKeys)(n),(0,u.extractSharedKeys)(i),a)}else{let t=d.default.readFileSync(e,`utf-8`),n=D(t,r),{clientKeys:i,sharedKeys:a,isLegacy:o}=_(t);s=o?x(i,a,n):S(i,a,n)}let l=f.default.dirname(t);d.default.existsSync(l)||d.default.mkdirSync(l,{recursive:!0});let p=!0;d.default.existsSync(t)&&d.default.readFileSync(t,`utf-8`)===s&&(p=!1),p&&d.default.writeFileSync(t,s,`utf-8`);let m=f.default.join(l,`index.ts`),h=`export * from "./env.gen";
|
|
97
|
+
export { default } from "./env.gen";
|
|
98
|
+
`;if(f.default.basename(l)===`.arkenv`||!d.default.existsSync(m)){let e=!0;d.default.existsSync(m)&&d.default.readFileSync(m,`utf-8`)===h&&(e=!1),e&&d.default.writeFileSync(m,h,`utf-8`)}if(a===`strict`&&o){let e=f.default.join(f.default.dirname(t),`arkenv-client-env.d.ts`),n=C(f.default.join(o,`client.ts`),t),r=!0;d.default.existsSync(e)&&d.default.readFileSync(e,`utf-8`)===n&&(r=!1),r&&d.default.writeFileSync(e,n,`utf-8`)}}function k(e,t,n){if(Array.isArray(e)){let r=e.filter(e=>e.name!==t);return r.push({name:t,alias:n}),r}return{...e??{},[t]:n}}function A(e,t,n=`#arkenv/client-env`){let r=e.webpack,i=(e,i)=>{let a=r?r(e,i)??e:e;a.resolve=a.resolve??{},a.resolve.alias=k(a.resolve.alias,n,t);let o=i.webpack?.DefinePlugin;return o&&(a.plugins=a.plugins??[],a.plugins.push(new o({__ARKENV_STRICT_LAYOUT__:JSON.stringify(!0)}))),a},a=f.default.isAbsolute(t)?`./${f.default.relative(process.cwd(),t).replace(/\\/g,`/`)}`:t.startsWith(`.`)?t:`./${t}`,o=e.turbopack??{},s={...o.resolveAlias??{},[n]:a},c=e.experimental,l=c?{...c,...c.turbo?{turbo:{...c.turbo,resolveAlias:{...c.turbo.resolveAlias??{},[n]:a}}}:{}}:void 0,u={...e,webpack:i,env:{...e.env??{},ARKENV_STRICT_LAYOUT:`true`},turbopack:{...o,resolveAlias:s}};return l&&(u.experimental=l),u}function j(e){for(let t of[e,f.default.join(e,`..`)]){let e=f.default.join(t,`mock-server-only.ts`);if(d.default.existsSync(e))return e;let n=f.default.join(t,`mock-server-only.js`);if(d.default.existsSync(n))return n}return f.default.join(e,`mock-server-only.js`)}function M(e){for(let t of[e,f.default.join(e,`..`)]){let e=f.default.join(t,`empty-client-env.ts`);if(d.default.existsSync(e))return e;let n=f.default.join(t,`empty-client-env.js`);if(d.default.existsSync(n))return n}return f.default.join(e,`empty-client-env.js`)}function N(e){if(d.default.existsSync(e))return!0;let t=f.default.extname(e);if(!t)return!1;let n=e.slice(0,-t.length);return d.default.existsSync(n)}function P(e,t){let n=c.n(e),r=e?.schemaPath?f.default.resolve(e.schemaPath):(0,u.findSchemaPath)();if(!r||!N(r))throw Error((0,u.formatMissingSchemaError)({schemaPath:e?.schemaPath,optionsHint:`setupArkEnv options`}));let{layout:i,baseDir:a}=(0,u.resolveLayout)(r,E(e?.layout,n)),o=i===`strict`&&a?f.default.join(a,`client.ts`):void 0;if(o&&!d.default.existsSync(o))throw Error(l.r(o,a));function s(e,t,n){if(n===`strict`&&t){let e=t;return f.default.basename(e)===`env`&&(e=f.default.dirname(e)),f.default.basename(e)===`src`&&(e=f.default.dirname(e)),e}let r=f.default.dirname(e);return f.default.basename(r)===`src`&&(r=f.default.dirname(r)),r}let h=s(r,a,i),g=f.default.join(h,`.arkenv`,`env.gen.ts`),_=e?.outputPath?f.default.resolve(e.outputPath):g,v=e?.codegen??!0;if(v)try{O(r,_,i,e?.standard,e)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(c.r(`Failed to generate env.gen.ts: ${t}`))}if(e?.validate??!0){let e=globalThis;try{e.__arkenv_force_server__=!0;let n=i===`strict`&&a?f.default.join(a,`server.ts`):r,s=typeof __filename<`u`?__filename:require(`url`).pathToFileURL(__filename).href?(0,p.fileURLToPath)(require(`url`).pathToFileURL(__filename).href):``,c=f.default.dirname(s),u=j(c),h=M(c),g=(0,m.createJiti)(n,{moduleCache:!1,fsCache:!1,tsconfigPaths:!0,alias:{"server-only":u,"./script":u,"./script.tsx":u,[l.t]:o&&d.default.existsSync(o)?o:h,...t?._jitiAliases}});if(i===`strict`&&o){e.__ARKENV_STRICT_LAYOUT__=!0;let t=g(o);e.__ARKENV_CLIENT_ENV__=t.env??t.default?.env??t}g(n)}catch(e){n.logBuildError(`Environment validation failed:`),n.logBuildErrorDetail(e instanceof Error?e.message:String(e)),n.logBuildErrorBlankLine(),process.exit(1)}finally{delete e.__arkenv_force_server__,delete e.__ARKENV_STRICT_LAYOUT__,delete e.__ARKENV_CLIENT_ENV__}}return(process.env.NODE_ENV===`development`||process.env.NEXT_PHASE===`phase-development-server`)&&v&&(0,u.watchSchema)(i===`strict`&&a?[f.default.join(a,`internal`,`shared.ts`),f.default.join(a,`client.ts`),f.default.join(a,`server.ts`)].filter(d.default.existsSync):[r],()=>{O(r,_,i,e?.standard,e)},c.t(e)),{resolvedLayout:i,baseDir:a,clientEnvPath:o,outputPath:_}}function F(e,t,n){let{resolvedLayout:r,clientEnvPath:i,outputPath:a}=n,o=e;r===`strict`&&i&&(o=A(o,i,l.t));let s=process.cwd(),c=a??(t?.outputPath?f.default.resolve(t.outputPath):f.default.join(s,`.arkenv`,`env.gen.ts`)),u=`./${f.default.relative(s,c).replace(/\\/g,`/`)}`,d={...o.turbopack,resolveAlias:{".arkenv/env.gen":u,".arkenv/env.gen.ts":u,".arkenv":u,".arkenv/index":u,".arkenv/index.ts":u,"#arkenv/env":u,"@/.arkenv":u,"@/.arkenv/env.gen":u,...o.turbopack?.resolveAlias}},p=o.webpack,m=(e,t)=>{let n=e;return n.resolve=n.resolve??{},n.resolve.alias={...n.resolve.alias,".arkenv/env.gen":c,".arkenv/env.gen.ts":c,".arkenv":c,".arkenv/index":c,".arkenv/index.ts":c,"#arkenv/env":c,"@/.arkenv":c,"@/.arkenv/env.gen":c},typeof p==`function`?p(n,t):n};return{...o,turbopack:d,webpack:m}}function I(e,t){return typeof e==`function`?async(n,r)=>{let i=P(t);return F(await e(n,r),t,i)}:e&&typeof e==`object`?F(e,t,P(t)):e}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return P}});
|
|
99
|
+
//# sourceMappingURL=config-Oq8dsEPM.cjs.map
|