@arkenv/nextjs 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +89 -0
  2. package/dist/client.cjs +2 -0
  3. package/dist/client.cjs.map +1 -0
  4. package/dist/client.d.cts +23 -0
  5. package/dist/client.d.cts.map +1 -0
  6. package/dist/client.d.ts +23 -0
  7. package/dist/client.d.ts.map +1 -0
  8. package/dist/client.js +2 -0
  9. package/dist/client.js.map +1 -0
  10. package/dist/config.cjs +38 -0
  11. package/dist/config.cjs.map +1 -0
  12. package/dist/config.d.cts +71 -0
  13. package/dist/config.d.cts.map +1 -0
  14. package/dist/config.d.ts +71 -0
  15. package/dist/config.d.ts.map +1 -0
  16. package/dist/config.js +38 -0
  17. package/dist/config.js.map +1 -0
  18. package/dist/create-env-BfXQtLQM.js +2 -0
  19. package/dist/create-env-BfXQtLQM.js.map +1 -0
  20. package/dist/create-env-DDWVuzwL.cjs +2 -0
  21. package/dist/create-env-DDWVuzwL.cjs.map +1 -0
  22. package/dist/index-Bn3pRiJy.d.ts +187 -0
  23. package/dist/index-Bn3pRiJy.d.ts.map +1 -0
  24. package/dist/index-C6bpQ5GU.d.cts +187 -0
  25. package/dist/index-C6bpQ5GU.d.cts.map +1 -0
  26. package/dist/index.cjs +1 -1
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +10 -8
  29. package/dist/index.d.cts.map +1 -1
  30. package/dist/index.d.ts +10 -8
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +1 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/react-server.cjs +1 -1
  35. package/dist/react-server.cjs.map +1 -1
  36. package/dist/react-server.d.cts +10 -8
  37. package/dist/react-server.d.cts.map +1 -1
  38. package/dist/react-server.d.ts +10 -8
  39. package/dist/react-server.d.ts.map +1 -1
  40. package/dist/react-server.js +1 -1
  41. package/dist/react-server.js.map +1 -1
  42. package/dist/server.cjs +2 -0
  43. package/dist/server.cjs.map +1 -0
  44. package/dist/server.d.cts +22 -0
  45. package/dist/server.d.cts.map +1 -0
  46. package/dist/server.d.ts +23 -0
  47. package/dist/server.d.ts.map +1 -0
  48. package/dist/server.js +2 -0
  49. package/dist/server.js.map +1 -0
  50. package/dist/shared.cjs +2 -0
  51. package/dist/shared.cjs.map +1 -0
  52. package/dist/shared.d.cts +17 -0
  53. package/dist/shared.d.cts.map +1 -0
  54. package/dist/shared.d.ts +17 -0
  55. package/dist/shared.d.ts.map +1 -0
  56. package/dist/shared.js +2 -0
  57. package/dist/shared.js.map +1 -0
  58. package/dist/types-BN4fEChy.d.ts +12 -0
  59. package/dist/types-BN4fEChy.d.ts.map +1 -0
  60. package/dist/types-DBqiLw5v.d.cts +12 -0
  61. package/dist/types-DBqiLw5v.d.cts.map +1 -0
  62. package/package.json +77 -5
  63. package/dist/create-env-NTGNQN-0.cjs +0 -2
  64. package/dist/create-env-NTGNQN-0.cjs.map +0 -1
  65. package/dist/create-env-u3WlRe7_.js +0 -2
  66. package/dist/create-env-u3WlRe7_.js.map +0 -1
  67. package/dist/index-Bu2HxG6d.d.cts +0 -90
  68. package/dist/index-Bu2HxG6d.d.cts.map +0 -1
  69. package/dist/index-DLivsH0-.d.ts +0 -90
  70. package/dist/index-DLivsH0-.d.ts.map +0 -1
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @arkenv/nextjs
2
+
3
+ ArkEnv integration for Next.js. Provides a typesafe, zero-dependency (except peer dependencies) environment variable parser and validator for Next.js applications, with automatic code generation to eliminate manual `runtimeEnv` boilerplate.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @arkenv/nextjs arktype
9
+ ```
10
+
11
+ ## Setup & Codegen
12
+
13
+ Next.js requires client-side environment variables to be statically destructured (`process.env.NEXT_PUBLIC_...`) to allow static inlining during bundling.
14
+
15
+ To automate this, `@arkenv/nextjs/config` provides `withArkEnv`, which statically extracts your keys and writes a tailored factory in `generated/env.gen.ts`.
16
+
17
+ ### 1. Configure `next.config.ts`
18
+
19
+ Wrap your Next.js configuration in `withArkEnv`:
20
+
21
+ ```typescript
22
+ // next.config.ts
23
+ import { withArkEnv } from "@arkenv/nextjs/config";
24
+ import type { NextConfig } from "next";
25
+
26
+ const nextConfig: NextConfig = {
27
+ // Your standard Next.js config options
28
+ };
29
+
30
+ export default withArkEnv(nextConfig);
31
+ ```
32
+
33
+ ### 2. Define your schema in `env.ts`
34
+
35
+ Import `createEnv` from the generated `./generated/env.gen` file instead of the package:
36
+
37
+ ```typescript
38
+ // src/env.ts
39
+ import { createEnv } from "./generated/env.gen";
40
+
41
+ export const env = createEnv({
42
+ server: {
43
+ DATABASE_URL: "string",
44
+ STRIPE_API_KEY: "string",
45
+ },
46
+ client: {
47
+ NEXT_PUBLIC_API_URL: "string.host",
48
+ },
49
+ shared: {
50
+ NODE_ENV: "string",
51
+ },
52
+ });
53
+ ```
54
+
55
+ *Note: For the best DX and CI/CD compatibility, we recommend committing `generated/env.gen.ts` to source control.*
56
+
57
+ ---
58
+
59
+ ## Customizing Paths
60
+
61
+ If you want to keep generated files in a separate subdirectory (like `src/generated/`), you can specify the `schemaPath` and `outputPath` options in `next.config.ts`:
62
+
63
+ ```typescript
64
+ // next.config.ts
65
+ import { withArkEnv } from "@arkenv/nextjs/config";
66
+ import type { NextConfig } from "next";
67
+
68
+ const nextConfig: NextConfig = {
69
+ reactStrictMode: true,
70
+ };
71
+
72
+ export default withArkEnv(nextConfig, {
73
+ schemaPath: "src/env.ts",
74
+ outputPath: "src/generated/env.gen.ts"
75
+ });
76
+ ```
77
+
78
+ Then, import from the custom location:
79
+
80
+ ```typescript
81
+ // src/env.ts
82
+ import { createEnv } from "./generated/env.gen";
83
+
84
+ export const env = createEnv({
85
+ client: {
86
+ NEXT_PUBLIC_API_URL: "string",
87
+ }
88
+ });
89
+ ```
@@ -0,0 +1,2 @@
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./create-env-DDWVuzwL.cjs`);require(`./config.cjs`);let t=require(`arkenv`);function n(t,n){if(t&&typeof t==`object`&&(`runtimeEnv`in t||`client`in t||`shared`in t)){if(`server`in t)throw Error(`client entry point only accepts 'client' and 'shared' schemas.`);return e.t(t,!1)}return e.t(t,n,{isServer:!1})}const r=n;exports.createEnv=n,exports.default=r,Object.defineProperty(exports,`type`,{enumerable:!0,get:function(){return t.type}});
2
+ //# sourceMappingURL=client.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.cjs","names":["createEnvInternal","arkenv"],"sources":["../src/client.ts"],"sourcesContent":["import type { $ } from \"@repo/scope\";\nimport type { SchemaShape } from \"@repo/types\";\nimport type { EnvSchema } from \"arkenv\";\nimport type { type as at, distill } from \"arktype\";\nimport { createEnvInternal } from \"./create-env\";\nimport type { MergeExtends } from \"./types\";\n\n/**\n * Create a validated, type-safe environment configuration for Next.js applications (Client entry point).\n */\nexport function createEnv<\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, unknown>;\n\t},\n): Readonly<distill.Out<at.infer<TSchema, $>> & MergeExtends<TExtends>>;\n\nexport function createEnv<\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 createEnv(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 createEnvInternal(schemaOrOptions, false);\n\t}\n\n\treturn createEnvInternal(schemaOrOptions, optionsOrIsServer, {\n\t\tisServer: false,\n\t});\n}\n\nexport { type } from \"arkenv\";\n\nconst arkenv = createEnv;\nexport default arkenv;\n"],"mappings":"4LAuCA,SAAgB,EAAU,EAAsB,EAA8B,CAQ7E,GANC,GACA,OAAO,GAAoB,WAC1B,eAAgB,GAChB,WAAY,GACZ,WAAY,GAEA,CACb,GAAI,WAAY,EACf,MAAU,MACT,iEACA,CAEF,OAAOA,EAAAA,EAAkB,EAAiB,GAAM,CAGjD,OAAOA,EAAAA,EAAkB,EAAiB,EAAmB,CAC5D,SAAU,GACV,CAAC,CAKH,MAAMC,EAAS"}
@@ -0,0 +1,23 @@
1
+ import { r as $, t as SchemaShape } from "./index-C6bpQ5GU.cjs";
2
+ import { t as MergeExtends } from "./types-DBqiLw5v.cjs";
3
+ import { distill, type as type$1 } from "arktype";
4
+ import { EnvSchema, type } from "arkenv";
5
+
6
+ //#region src/client.d.ts
7
+ /**
8
+ * Create a validated, type-safe environment configuration for Next.js applications (Client entry point).
9
+ */
10
+ declare function createEnv<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
+ extends?: [...TExtends];
12
+ runtimeEnv?: Record<keyof TSchema | string, unknown>;
13
+ }): Readonly<distill.Out<type$1.infer<TSchema, $>> & MergeExtends<TExtends>>;
14
+ declare function createEnv<const TClient extends SchemaShape = {}, const TShared extends SchemaShape = {}, const TExtends extends readonly unknown[] = []>(options: {
15
+ client?: EnvSchema<TClient> & { [K in keyof TClient]: K extends `NEXT_PUBLIC_${string}` ? unknown : never };
16
+ shared?: EnvSchema<TShared>;
17
+ extends?: [...TExtends];
18
+ runtimeEnv: Record<keyof TClient | keyof TShared, unknown> & Record<string, unknown>;
19
+ }): Readonly<distill.Out<type$1.infer<TClient & TShared, $>> & MergeExtends<TExtends>>;
20
+ declare const arkenv: typeof createEnv;
21
+ //#endregion
22
+ export { createEnv, arkenv as default, type };
23
+ //# sourceMappingURL=client.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.cts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;;;AAUA;;iBAAgB,SAAA,uBACO,WAAA,sDAAA,CAGtB,MAAA,EAAQ,SAAA,CAAU,OAAA,kBACL,OAAA,GAAU,CAAA,sDAEvB,OAAA;EACC,OAAA,OAAc,QAAA;EACd,UAAA,GAAa,MAAA,OAAa,OAAA;AAAA,IAEzB,QAAA,CAAS,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,OAAA,EAAS,CAAA,KAAM,YAAA,CAAa,QAAA;AAAA,iBAE7C,SAAA,uBACO,WAAA,6BACA,WAAA,sDAAA,CAErB,OAAA;EACD,MAAA,GAAS,SAAA,CAAU,OAAA,kBACN,OAAA,GAAU,CAAA;EAEvB,MAAA,GAAS,SAAA,CAAU,OAAA;EACnB,OAAA,OAAc,QAAA;EACd,UAAA,EAAY,MAAA,OAAa,OAAA,SAAgB,OAAA,aACxC,MAAA;AAAA,IACE,QAAA,CACH,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,OAAA,GAAU,OAAA,EAAS,CAAA,KAAM,YAAA,CAAa,QAAA;AAAA,cA2BtD,MAAA,SAAM,SAAA"}
@@ -0,0 +1,23 @@
1
+ import { r as $, t as SchemaShape } from "./index-Bn3pRiJy.js";
2
+ import { t as MergeExtends } from "./types-BN4fEChy.js";
3
+ import { EnvSchema, type } from "arkenv";
4
+ import { distill, type as type$1 } from "arktype";
5
+
6
+ //#region src/client.d.ts
7
+ /**
8
+ * Create a validated, type-safe environment configuration for Next.js applications (Client entry point).
9
+ */
10
+ declare function createEnv<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
+ extends?: [...TExtends];
12
+ runtimeEnv?: Record<keyof TSchema | string, unknown>;
13
+ }): Readonly<distill.Out<type$1.infer<TSchema, $>> & MergeExtends<TExtends>>;
14
+ declare function createEnv<const TClient extends SchemaShape = {}, const TShared extends SchemaShape = {}, const TExtends extends readonly unknown[] = []>(options: {
15
+ client?: EnvSchema<TClient> & { [K in keyof TClient]: K extends `NEXT_PUBLIC_${string}` ? unknown : never };
16
+ shared?: EnvSchema<TShared>;
17
+ extends?: [...TExtends];
18
+ runtimeEnv: Record<keyof TClient | keyof TShared, unknown> & Record<string, unknown>;
19
+ }): Readonly<distill.Out<type$1.infer<TClient & TShared, $>> & MergeExtends<TExtends>>;
20
+ declare const arkenv: typeof createEnv;
21
+ //#endregion
22
+ export { createEnv, arkenv as default, type };
23
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;;;AAUA;;iBAAgB,SAAA,uBACO,WAAA,sDAAA,CAGtB,MAAA,EAAQ,SAAA,CAAU,OAAA,kBACL,OAAA,GAAU,CAAA,sDAEvB,OAAA;EACC,OAAA,OAAc,QAAA;EACd,UAAA,GAAa,MAAA,OAAa,OAAA;AAAA,IAEzB,QAAA,CAAS,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,OAAA,EAAS,CAAA,KAAM,YAAA,CAAa,QAAA;AAAA,iBAE7C,SAAA,uBACO,WAAA,6BACA,WAAA,sDAAA,CAErB,OAAA;EACD,MAAA,GAAS,SAAA,CAAU,OAAA,kBACN,OAAA,GAAU,CAAA;EAEvB,MAAA,GAAS,SAAA,CAAU,OAAA;EACnB,OAAA,OAAc,QAAA;EACd,UAAA,EAAY,MAAA,OAAa,OAAA,SAAgB,OAAA,aACxC,MAAA;AAAA,IACE,QAAA,CACH,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,OAAA,GAAU,OAAA,EAAS,CAAA,KAAM,YAAA,CAAa,QAAA;AAAA,cA2BtD,MAAA,SAAM,SAAA"}
package/dist/client.js ADDED
@@ -0,0 +1,2 @@
1
+ import{t as e}from"./create-env-BfXQtLQM.js";import{type as t}from"arkenv";function n(t,n){if(t&&typeof t==`object`&&(`runtimeEnv`in t||`client`in t||`shared`in t)){if(`server`in t)throw Error(`client entry point only accepts 'client' and 'shared' schemas.`);return e(t,!1)}return e(t,n,{isServer:!1})}const r=n;export{n as createEnv,r as default,t as type};
2
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { $ } from \"@repo/scope\";\nimport type { SchemaShape } from \"@repo/types\";\nimport type { EnvSchema } from \"arkenv\";\nimport type { type as at, distill } from \"arktype\";\nimport { createEnvInternal } from \"./create-env\";\nimport type { MergeExtends } from \"./types\";\n\n/**\n * Create a validated, type-safe environment configuration for Next.js applications (Client entry point).\n */\nexport function createEnv<\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, unknown>;\n\t},\n): Readonly<distill.Out<at.infer<TSchema, $>> & MergeExtends<TExtends>>;\n\nexport function createEnv<\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 createEnv(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 createEnvInternal(schemaOrOptions, false);\n\t}\n\n\treturn createEnvInternal(schemaOrOptions, optionsOrIsServer, {\n\t\tisServer: false,\n\t});\n}\n\nexport { type } from \"arkenv\";\n\nconst arkenv = createEnv;\nexport default arkenv;\n"],"mappings":"2EAuCA,SAAgB,EAAU,EAAsB,EAA8B,CAQ7E,GANC,GACA,OAAO,GAAoB,WAC1B,eAAgB,GAChB,WAAY,GACZ,WAAY,GAEA,CACb,GAAI,WAAY,EACf,MAAU,MACT,iEACA,CAEF,OAAO,EAAkB,EAAiB,GAAM,CAGjD,OAAO,EAAkB,EAAiB,EAAmB,CAC5D,SAAU,GACV,CAAC,CAKH,MAAM,EAAS"}
@@ -0,0 +1,38 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});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));let c=require(`node:fs`);c=s(c,1);let l=require(`node:path`);l=s(l,1);let u=require(`chokidar`),d=!1;function f(e,t){let n=t?.schemaPath?l.default.resolve(t.schemaPath):p();if(!n||!c.default.existsSync(n))throw Error(`[ArkEnv] Could not find schema file at ${t?.schemaPath||`src/env.ts or env.ts`}. Please specify 'schemaPath' in withArkEnv options.`);let r=l.default.dirname(n),i=l.default.join(r,`generated`,`env.gen.ts`),a=t?.outputPath?l.default.resolve(t.outputPath):i;try{h(n,a)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`[ArkEnv] Failed to generate env.gen.ts: ${t}`)}return(process.env.NODE_ENV===`development`||process.env.NEXT_PHASE===`phase-development-server`)&&m(n,a),e}function p(){let e=[l.default.join(process.cwd(),`src`,`env.ts`),l.default.join(process.cwd(),`env.ts`)];for(let t of e)if(c.default.existsSync(t))return t;return null}function m(e,t){if(!d){d=!0;try{(0,u.watch)(e,{ignoreInitial:!0}).on(`change`,()=>{try{h(e,t)}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[ArkEnv Watcher] Failed to regenerate env.gen.ts: ${t}`)}})}catch(t){let n=t instanceof Error?t.message:String(t);console.error(`[ArkEnv Watcher] Failed to start watch on ${e}: ${n}`)}}}function h(e,t){let{clientKeys:n,sharedKeys:r}=g(c.default.readFileSync(e,`utf-8`)),i=y(n,r),a=l.default.dirname(t);c.default.existsSync(a)||c.default.mkdirSync(a,{recursive:!0});let o=!0;c.default.existsSync(t)&&c.default.readFileSync(t,`utf-8`)===i&&(o=!1),o&&c.default.writeFileSync(t,i,`utf-8`)}function g(e){let t=[],n=[],r=_(e,`client`);r&&t.push(...v(r));let i=_(e,`shared`);return i&&n.push(...v(i)),{clientKeys:t,sharedKeys:n}}function _(e,t){let n=RegExp(`\\b${t}\\s*:\\s*(?:[a-zA-Z0-9_$.]+\\s*\\(\\s*)?\\{`,`g`);if(!n.exec(e))return null;let r=n.lastIndex,i=1,a=r,o=null,s=null;for(;a<e.length&&i>0;){let t=e[a],n=e[a+1];if(s===`single`){(t===`
2
+ `||t===`\r`)&&(s=null),a++;continue}if(s===`multi`){if(t===`*`&&n===`/`){s=null,a+=2;continue}a++;continue}if(o){t===o&&e[a-1]!==`\\`&&(o=null),a++;continue}if(t===`/`&&n===`/`){s=`single`,a+=2;continue}if(t===`/`&&n===`*`){s=`multi`,a+=2;continue}if(t===`'`||t===`"`||t==="`"){o=t,a++;continue}t===`{`?i++:t===`}`&&i--,a++}return i===0?e.slice(r,a-1):null}function v(e){let t=[],n=null,r=null,i=``,a=``,o=0;for(let s=0;s<e.length;s++){let c=e[s],l=e[s+1];if(r===`single`){(c===`
3
+ `||c===`\r`)&&(r=null);continue}if(r===`multi`){c===`*`&&l===`/`&&(r=null,s++);continue}if(n){c===n&&e[s-1]!==`\\`?(n=null,a=i,i=``):i+=c;continue}if(c===`/`&&l===`/`){r=`single`,s++;continue}if(c===`/`&&l===`*`){r=`multi`,s++;continue}if(c===`'`||c===`"`||c==="`"){n=c,i=``;continue}if(c===`{`){o++,i=``,a=``;continue}if(c===`}`){o--,i=``,a=``;continue}if(c===`:`){if(o===0){let e=i.trim()||a.trim();e&&t.push(e)}i=``,a=``;continue}/[a-zA-Z0-9_$]/.test(c)?i+=c:(c===`,`||c===`
4
+ `||c===`\r`)&&(i=``,a=``)}return t}function y(e,t){return`/* eslint-disable */
5
+ // prettier-ignore
6
+ // biome-ignore format: auto-generated
7
+ /**
8
+ * @file env.gen.ts
9
+ * @note This file is auto-generated by ArkEnv. DO NOT EDIT DIRECTLY.
10
+ * @see https://arkenv.js.org
11
+ */
12
+
13
+ import { createEnv as coreCreateEnv } from "@arkenv/nextjs";
14
+ import type { Infer } from "@arkenv/nextjs";
15
+
16
+ export { type } from "@arkenv/nextjs";
17
+
18
+ export function createEnv<
19
+ const TServer extends Record<string, any> = {},
20
+ const TClient extends Record<string, any> = {},
21
+ const TShared extends Record<string, any> = {},
22
+ >(options: {
23
+ server?: TServer;
24
+ client?: TClient & {
25
+ [K in keyof TClient]: K extends \`NEXT_PUBLIC_\${string}\` ? unknown : never;
26
+ };
27
+ shared?: TShared;
28
+ }): Readonly<Infer<TServer & TClient & TShared>> {
29
+ return coreCreateEnv({
30
+ ...options,
31
+ runtimeEnv: {
32
+ ${Array.from(new Set([...e,...t])).map(e=>`\t\t\t${e}: process.env.${e},`).join(`
33
+ `)}
34
+ },
35
+ } as any) as any;
36
+ }
37
+ `}exports.extractKeys=g,exports.runCodegen=h,exports.t=s,exports.withArkEnv=f;
38
+ //# sourceMappingURL=config.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.cjs","names":["path","fs"],"sources":["../src/config.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { watch as chokidarWatch } from \"chokidar\";\n\n/**\n * Configuration options for the ArkEnv Next.js integration.\n *\n * @example\n * ```ts\n * const configOptions: ArkEnvConfigOptions = {\n * schemaPath: \"./src/env.ts\",\n * outputPath: \"./src/generated/env.gen.ts\"\n * };\n * ```\n */\nexport type ArkEnvConfigOptions = {\n\t/**\n\t * Specify the path to the schema definition file.\n\t *\n\t * Defaults to searching for `\"src/env.ts\"` or `\"env.ts\"` in the project root.\n\t *\n\t * @default \"src/env.ts\"\n\t * @example\n\t * ```ts\n\t * export default withArkEnv(nextConfig, {\n\t * schemaPath: \"./src/env.ts\"\n\t * });\n\t * ```\n\t */\n\tschemaPath?: string;\n\n\t/**\n\t * Specify the path where the generated file (`env.gen.ts`) should be written.\n\t *\n\t * Defaults to `\"generated/env.gen.ts\"` in the same directory as the schema file.\n\t *\n\t * @default \"[schemaDirectory]/generated/env.gen.ts\"\n\t * @example\n\t * ```ts\n\t * export default withArkEnv(nextConfig, {\n\t * outputPath: \"./src/generated/env.gen.ts\"\n\t * });\n\t * ```\n\t */\n\toutputPath?: string;\n};\n\nlet watcherInitialized = false;\n\n/**\n * Wrap a Next.js configuration object to automatically generate the `runtimeEnv` block in `env.gen.ts`.\n *\n * @param nextConfig The Next.js configuration object or function\n * @param options Optional configuration paths for schema and output files\n * @returns The Next.js configuration object unchanged\n * @throws An error if the schema file cannot be found or if code generation fails\n */\nexport function withArkEnv<T>(nextConfig: T, options?: ArkEnvConfigOptions): T {\n\t// 1. Locate the env.ts schema file\n\tconst schemaPath = options?.schemaPath\n\t\t? path.resolve(options.schemaPath)\n\t\t: findSchemaPath();\n\tif (!schemaPath || !fs.existsSync(schemaPath)) {\n\t\tthrow new Error(\n\t\t\t`[ArkEnv] Could not find schema file at ${\n\t\t\t\toptions?.schemaPath || \"src/env.ts or env.ts\"\n\t\t\t}. Please specify 'schemaPath' in withArkEnv options.`,\n\t\t);\n\t}\n\n\t// 2. Determine outputPath (defaults to generated/env.gen.ts in the same directory as schemaPath)\n\tconst defaultOutputDir = path.dirname(schemaPath);\n\tconst defaultOutputPath = path.join(\n\t\tdefaultOutputDir,\n\t\t\"generated\",\n\t\t\"env.gen.ts\",\n\t);\n\tconst outputPath = options?.outputPath\n\t\t? path.resolve(options.outputPath)\n\t\t: defaultOutputPath;\n\n\t// 3. Run initial code generation\n\ttry {\n\t\trunCodegen(schemaPath, outputPath);\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(`[ArkEnv] Failed to generate env.gen.ts: ${message}`);\n\t}\n\n\t// 4. Initialize development file watcher if in dev mode\n\t// Note: We check process.env.NODE_ENV or standard Next dev runtime markers\n\tconst isDev =\n\t\tprocess.env.NODE_ENV === \"development\" ||\n\t\tprocess.env.NEXT_PHASE === \"phase-development-server\";\n\tif (isDev) {\n\t\twatchSchema(schemaPath, outputPath);\n\t}\n\n\treturn nextConfig;\n}\n\n/**\n * Find the path to the schema file in the project.\n *\n * @returns The absolute path to the schema file, or null if not found\n */\nfunction findSchemaPath(): string | null {\n\tconst possiblePaths = [\n\t\tpath.join(process.cwd(), \"src\", \"env.ts\"),\n\t\tpath.join(process.cwd(), \"env.ts\"),\n\t];\n\tfor (const p of possiblePaths) {\n\t\tif (fs.existsSync(p)) return p;\n\t}\n\treturn null;\n}\n\n/**\n * Watch the schema file for changes and trigger codegen.\n *\n * @param schemaPath The absolute path to the schema file\n * @param outputPath The absolute path to the generated output file\n */\nfunction watchSchema(schemaPath: string, outputPath: string) {\n\tif (watcherInitialized) return;\n\twatcherInitialized = true;\n\n\ttry {\n\t\tchokidarWatch(schemaPath, { ignoreInitial: true }).on(\"change\", () => {\n\t\t\ttry {\n\t\t\t\trunCodegen(schemaPath, outputPath);\n\t\t\t} catch (err: unknown) {\n\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\t// biome-ignore lint/suspicious/noConsole: watcher errors must be logged\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[ArkEnv Watcher] Failed to regenerate env.gen.ts: ${message}`,\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t} catch (err: unknown) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t// biome-ignore lint/suspicious/noConsole: watcher errors must be logged\n\t\tconsole.error(\n\t\t\t`[ArkEnv Watcher] Failed to start watch on ${schemaPath}: ${message}`,\n\t\t);\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\n * @param outputPath The absolute path to the generated output file\n */\nexport function runCodegen(schemaPath: string, outputPath: string) {\n\tconst fileContent = fs.readFileSync(schemaPath, \"utf-8\");\n\tconst { clientKeys, sharedKeys } = extractKeys(fileContent);\n\n\tconst generatedCode = generateFactoryCode(clientKeys, sharedKeys);\n\n\t// Ensure parent directory exists\n\tconst outputDir = path.dirname(outputPath);\n\tif (!fs.existsSync(outputDir)) {\n\t\tfs.mkdirSync(outputDir, { recursive: true });\n\t}\n\n\t// Write if changed to avoid unnecessary filesystem/watcher triggers\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\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} {\n\tconst clientKeys: string[] = [];\n\tconst sharedKeys: string[] = [];\n\n\t// Extract client block\n\tconst clientBlock = extractBlock(content, \"client\");\n\tif (clientBlock) {\n\t\tclientKeys.push(...parseBlockKeys(clientBlock));\n\t}\n\n\t// Extract shared block\n\tconst sharedBlock = extractBlock(content, \"shared\");\n\tif (sharedBlock) {\n\t\tsharedKeys.push(...parseBlockKeys(sharedBlock));\n\t}\n\n\treturn { clientKeys, sharedKeys };\n}\n\n/**\n * Extract a specific block from the schema content by name.\n *\n * @param content The schema file string content\n * @param blockName The name of the block to extract (e.g., 'client' or 'shared')\n * @returns The contents of the block, or null if not found\n */\nfunction extractBlock(content: string, blockName: string): string | null {\n\t// Find \"\\bblockName\\s*:\\s*{\" or \"\\bblockName\\s*:\\s*type({\"\n\tconst regex = new RegExp(\n\t\t`\\\\b${blockName}\\\\s*:\\\\s*(?:[a-zA-Z0-9_$.]+\\\\s*\\\\(\\\\s*)?\\\\{`,\n\t\t\"g\",\n\t);\n\tconst match = regex.exec(content);\n\tif (!match) return null;\n\n\tconst startIndex = regex.lastIndex;\n\tlet braceCount = 1;\n\tlet index = startIndex;\n\tlet inString: string | null = null;\n\tlet inComment: \"single\" | \"multi\" | null = null;\n\n\twhile (index < content.length && braceCount > 0) {\n\t\tconst char = content[index];\n\t\tconst nextChar = content[index + 1];\n\n\t\tif (inComment === \"single\") {\n\t\t\tif (char === \"\\n\" || char === \"\\r\") inComment = null;\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (inComment === \"multi\") {\n\t\t\tif (char === \"*\" && nextChar === \"/\") {\n\t\t\t\tinComment = null;\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (inString) {\n\t\t\tif (char === inString && content[index - 1] !== \"\\\\\") {\n\t\t\t\tinString = null;\n\t\t\t}\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"/\" && nextChar === \"/\") {\n\t\t\tinComment = \"single\";\n\t\t\tindex += 2;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === \"/\" && nextChar === \"*\") {\n\t\t\tinComment = \"multi\";\n\t\t\tindex += 2;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === \"'\" || char === '\"' || char === \"`\") {\n\t\t\tinString = char;\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"{\") {\n\t\t\tbraceCount++;\n\t\t} else if (char === \"}\") {\n\t\t\tbraceCount--;\n\t\t}\n\t\tindex++;\n\t}\n\n\tif (braceCount === 0) {\n\t\treturn content.slice(startIndex, index - 1);\n\t}\n\n\treturn null;\n}\n\n/**\n * Parse environment variable keys from a block's content.\n *\n * @param blockContent The raw content of the block\n * @returns An array of parsed environment variable keys\n */\nfunction parseBlockKeys(blockContent: string): string[] {\n\tconst keys: string[] = [];\n\tlet inString: string | null = null;\n\tlet inComment: \"single\" | \"multi\" | null = null;\n\tlet currentToken = \"\";\n\tlet lastStringContent = \"\";\n\tlet braceDepth = 0;\n\n\tfor (let i = 0; i < blockContent.length; i++) {\n\t\tconst char = blockContent[i];\n\t\tconst nextChar = blockContent[i + 1];\n\n\t\tif (inComment === \"single\") {\n\t\t\tif (char === \"\\n\" || char === \"\\r\") inComment = null;\n\t\t\tcontinue;\n\t\t}\n\t\tif (inComment === \"multi\") {\n\t\t\tif (char === \"*\" && nextChar === \"/\") {\n\t\t\t\tinComment = null;\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (inString) {\n\t\t\tif (char === inString && blockContent[i - 1] !== \"\\\\\") {\n\t\t\t\tinString = null;\n\t\t\t\tlastStringContent = currentToken;\n\t\t\t\tcurrentToken = \"\";\n\t\t\t} else {\n\t\t\t\tcurrentToken += char;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Start comments/strings\n\t\tif (char === \"/\" && nextChar === \"/\") {\n\t\t\tinComment = \"single\";\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === \"/\" && nextChar === \"*\") {\n\t\t\tinComment = \"multi\";\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === \"'\" || char === '\"' || char === \"`\") {\n\t\t\tinString = char;\n\t\t\tcurrentToken = \"\";\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"{\") {\n\t\t\tbraceDepth++;\n\t\t\tcurrentToken = \"\";\n\t\t\tlastStringContent = \"\";\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === \"}\") {\n\t\t\tbraceDepth--;\n\t\t\tcurrentToken = \"\";\n\t\t\tlastStringContent = \"\";\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \":\") {\n\t\t\tif (braceDepth === 0) {\n\t\t\t\tconst key = currentToken.trim() || lastStringContent.trim();\n\t\t\t\tif (key) {\n\t\t\t\t\tkeys.push(key);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcurrentToken = \"\";\n\t\t\tlastStringContent = \"\";\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (/[a-zA-Z0-9_$]/.test(char)) {\n\t\t\tcurrentToken += char;\n\t\t} else if (char === \",\" || char === \"\\n\" || char === \"\\r\") {\n\t\t\tcurrentToken = \"\";\n\t\t\tlastStringContent = \"\";\n\t\t}\n\t}\n\n\treturn keys;\n}\n\n/**\n * Generate the TypeScript factory code for the tailored createEnv helper.\n *\n * @param clientKeys The client environment variable keys\n * @param sharedKeys The shared environment variable keys\n * @returns The generated TypeScript source code string\n */\nfunction generateFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst allKeys = Array.from(new Set([...clientKeys, ...sharedKeys]));\n\tconst runtimeEnvLines = allKeys\n\t\t.map((key) => `\\t\\t\\t${key}: process.env.${key},`)\n\t\t.join(\"\\n\");\n\n\treturn `/* eslint-disable */\n// prettier-ignore\n// biome-ignore format: auto-generated\n/**\n * @file env.gen.ts\n * @note This file is auto-generated by ArkEnv. DO NOT EDIT DIRECTLY.\n * @see https://arkenv.js.org\n */\n\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs\";\nimport type { Infer } from \"@arkenv/nextjs\";\n\nexport { type } from \"@arkenv/nextjs\";\n\nexport function createEnv<\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}): Readonly<Infer<TServer & TClient & TShared>> {\n\treturn coreCreateEnv({\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any) as any;\n}\n`;\n}\n"],"mappings":"ioBA+CI,EAAqB,GAUzB,SAAgB,EAAc,EAAe,EAAkC,CAE9E,IAAM,EAAa,GAAS,WACzBA,EAAAA,QAAK,QAAQ,EAAQ,WAAW,CAChC,GAAgB,CACnB,GAAI,CAAC,GAAc,CAACC,EAAAA,QAAG,WAAW,EAAW,CAC5C,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;;;;;;;;;;;;;;;;EALS,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,EAAY,GAAG,EAAW,CAAC,CACnC,CAC7B,IAAK,GAAQ,SAAS,EAAI,gBAAgB,EAAI,GAAG,CACjD,KAAK;EA8BS,CAAC"}
@@ -0,0 +1,71 @@
1
+ //#region src/config.d.ts
2
+ /**
3
+ * Configuration options for the ArkEnv Next.js integration.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * const configOptions: ArkEnvConfigOptions = {
8
+ * schemaPath: "./src/env.ts",
9
+ * outputPath: "./src/generated/env.gen.ts"
10
+ * };
11
+ * ```
12
+ */
13
+ type ArkEnvConfigOptions = {
14
+ /**
15
+ * Specify the path to the schema definition file.
16
+ *
17
+ * Defaults to searching for `"src/env.ts"` or `"env.ts"` in the project root.
18
+ *
19
+ * @default "src/env.ts"
20
+ * @example
21
+ * ```ts
22
+ * export default withArkEnv(nextConfig, {
23
+ * schemaPath: "./src/env.ts"
24
+ * });
25
+ * ```
26
+ */
27
+ schemaPath?: string;
28
+ /**
29
+ * Specify the path where the generated file (`env.gen.ts`) should be written.
30
+ *
31
+ * Defaults to `"generated/env.gen.ts"` in the same directory as the schema file.
32
+ *
33
+ * @default "[schemaDirectory]/generated/env.gen.ts"
34
+ * @example
35
+ * ```ts
36
+ * export default withArkEnv(nextConfig, {
37
+ * outputPath: "./src/generated/env.gen.ts"
38
+ * });
39
+ * ```
40
+ */
41
+ outputPath?: string;
42
+ };
43
+ /**
44
+ * Wrap a Next.js configuration object to automatically generate the `runtimeEnv` block in `env.gen.ts`.
45
+ *
46
+ * @param nextConfig The Next.js configuration object or function
47
+ * @param options Optional configuration paths for schema and output files
48
+ * @returns The Next.js configuration object unchanged
49
+ * @throws An error if the schema file cannot be found or if code generation fails
50
+ */
51
+ declare function withArkEnv<T>(nextConfig: T, options?: ArkEnvConfigOptions): T;
52
+ /**
53
+ * Run code generation to read the schema file and generate the env.gen.ts factory.
54
+ *
55
+ * @param schemaPath The absolute path to the schema file
56
+ * @param outputPath The absolute path to the generated output file
57
+ */
58
+ declare function runCodegen(schemaPath: string, outputPath: string): void;
59
+ /**
60
+ * Statically extract client and shared keys from the schema content.
61
+ *
62
+ * @param content The schema file string content
63
+ * @returns An object containing the extracted client and shared keys
64
+ */
65
+ declare function extractKeys(content: string): {
66
+ clientKeys: string[];
67
+ sharedKeys: string[];
68
+ };
69
+ //#endregion
70
+ export { ArkEnvConfigOptions, extractKeys, runCodegen, withArkEnv };
71
+ //# sourceMappingURL=config.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.cts","names":[],"sources":["../src/config.ts"],"mappings":";;AAeA;;;;;AA0CA;;;;;KA1CY,mBAAA;EA0CkE;;;;;;;;;;AAiG9E;;;EA7HC,UAAA;EA6HgE;AAgCjE;;;;;;;;;;;;EA9IC,UAAA;AAAA;;;;;;;;;iBAae,UAAA,GAAA,CAAc,UAAA,EAAY,CAAA,EAAG,OAAA,GAAU,mBAAA,GAAsB,CAAA;;;;;;;iBAiG7D,UAAA,CAAW,UAAA,UAAoB,UAAA;;;;;;;iBAgC/B,WAAA,CAAY,OAAA;EAC3B,UAAA;EACA,UAAA;AAAA"}
@@ -0,0 +1,71 @@
1
+ //#region src/config.d.ts
2
+ /**
3
+ * Configuration options for the ArkEnv Next.js integration.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * const configOptions: ArkEnvConfigOptions = {
8
+ * schemaPath: "./src/env.ts",
9
+ * outputPath: "./src/generated/env.gen.ts"
10
+ * };
11
+ * ```
12
+ */
13
+ type ArkEnvConfigOptions = {
14
+ /**
15
+ * Specify the path to the schema definition file.
16
+ *
17
+ * Defaults to searching for `"src/env.ts"` or `"env.ts"` in the project root.
18
+ *
19
+ * @default "src/env.ts"
20
+ * @example
21
+ * ```ts
22
+ * export default withArkEnv(nextConfig, {
23
+ * schemaPath: "./src/env.ts"
24
+ * });
25
+ * ```
26
+ */
27
+ schemaPath?: string;
28
+ /**
29
+ * Specify the path where the generated file (`env.gen.ts`) should be written.
30
+ *
31
+ * Defaults to `"generated/env.gen.ts"` in the same directory as the schema file.
32
+ *
33
+ * @default "[schemaDirectory]/generated/env.gen.ts"
34
+ * @example
35
+ * ```ts
36
+ * export default withArkEnv(nextConfig, {
37
+ * outputPath: "./src/generated/env.gen.ts"
38
+ * });
39
+ * ```
40
+ */
41
+ outputPath?: string;
42
+ };
43
+ /**
44
+ * Wrap a Next.js configuration object to automatically generate the `runtimeEnv` block in `env.gen.ts`.
45
+ *
46
+ * @param nextConfig The Next.js configuration object or function
47
+ * @param options Optional configuration paths for schema and output files
48
+ * @returns The Next.js configuration object unchanged
49
+ * @throws An error if the schema file cannot be found or if code generation fails
50
+ */
51
+ declare function withArkEnv<T>(nextConfig: T, options?: ArkEnvConfigOptions): T;
52
+ /**
53
+ * Run code generation to read the schema file and generate the env.gen.ts factory.
54
+ *
55
+ * @param schemaPath The absolute path to the schema file
56
+ * @param outputPath The absolute path to the generated output file
57
+ */
58
+ declare function runCodegen(schemaPath: string, outputPath: string): void;
59
+ /**
60
+ * Statically extract client and shared keys from the schema content.
61
+ *
62
+ * @param content The schema file string content
63
+ * @returns An object containing the extracted client and shared keys
64
+ */
65
+ declare function extractKeys(content: string): {
66
+ clientKeys: string[];
67
+ sharedKeys: string[];
68
+ };
69
+ //#endregion
70
+ export { ArkEnvConfigOptions, extractKeys, runCodegen, withArkEnv };
71
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","names":[],"sources":["../src/config.ts"],"mappings":";;AAeA;;;;;AA0CA;;;;;KA1CY,mBAAA;EA0CkE;;;;;;;;;;AAiG9E;;;EA7HC,UAAA;EA6HgE;AAgCjE;;;;;;;;;;;;EA9IC,UAAA;AAAA;;;;;;;;;iBAae,UAAA,GAAA,CAAc,UAAA,EAAY,CAAA,EAAG,OAAA,GAAU,mBAAA,GAAsB,CAAA;;;;;;;iBAiG7D,UAAA,CAAW,UAAA,UAAoB,UAAA;;;;;;;iBAgC/B,WAAA,CAAY,OAAA;EAC3B,UAAA;EACA,UAAA;AAAA"}
package/dist/config.js ADDED
@@ -0,0 +1,38 @@
1
+ import e from"node:fs";import t from"node:path";import{watch as n}from"chokidar";let r=!1;function i(n,r){let i=r?.schemaPath?t.resolve(r.schemaPath):a();if(!i||!e.existsSync(i))throw Error(`[ArkEnv] Could not find schema file at ${r?.schemaPath||`src/env.ts or env.ts`}. Please specify 'schemaPath' in withArkEnv options.`);let c=t.dirname(i),l=t.join(c,`generated`,`env.gen.ts`),u=r?.outputPath?t.resolve(r.outputPath):l;try{s(i,u)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`[ArkEnv] Failed to generate env.gen.ts: ${t}`)}return(process.env.NODE_ENV===`development`||process.env.NEXT_PHASE===`phase-development-server`)&&o(i,u),n}function a(){let n=[t.join(process.cwd(),`src`,`env.ts`),t.join(process.cwd(),`env.ts`)];for(let t of n)if(e.existsSync(t))return t;return null}function o(e,t){if(!r){r=!0;try{n(e,{ignoreInitial:!0}).on(`change`,()=>{try{s(e,t)}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[ArkEnv Watcher] Failed to regenerate env.gen.ts: ${t}`)}})}catch(t){let n=t instanceof Error?t.message:String(t);console.error(`[ArkEnv Watcher] Failed to start watch on ${e}: ${n}`)}}}function s(n,r){let{clientKeys:i,sharedKeys:a}=c(e.readFileSync(n,`utf-8`)),o=d(i,a),s=t.dirname(r);e.existsSync(s)||e.mkdirSync(s,{recursive:!0});let l=!0;e.existsSync(r)&&e.readFileSync(r,`utf-8`)===o&&(l=!1),l&&e.writeFileSync(r,o,`utf-8`)}function c(e){let t=[],n=[],r=l(e,`client`);r&&t.push(...u(r));let i=l(e,`shared`);return i&&n.push(...u(i)),{clientKeys:t,sharedKeys:n}}function l(e,t){let n=RegExp(`\\b${t}\\s*:\\s*(?:[a-zA-Z0-9_$.]+\\s*\\(\\s*)?\\{`,`g`);if(!n.exec(e))return null;let r=n.lastIndex,i=1,a=r,o=null,s=null;for(;a<e.length&&i>0;){let t=e[a],n=e[a+1];if(s===`single`){(t===`
2
+ `||t===`\r`)&&(s=null),a++;continue}if(s===`multi`){if(t===`*`&&n===`/`){s=null,a+=2;continue}a++;continue}if(o){t===o&&e[a-1]!==`\\`&&(o=null),a++;continue}if(t===`/`&&n===`/`){s=`single`,a+=2;continue}if(t===`/`&&n===`*`){s=`multi`,a+=2;continue}if(t===`'`||t===`"`||t==="`"){o=t,a++;continue}t===`{`?i++:t===`}`&&i--,a++}return i===0?e.slice(r,a-1):null}function u(e){let t=[],n=null,r=null,i=``,a=``,o=0;for(let s=0;s<e.length;s++){let c=e[s],l=e[s+1];if(r===`single`){(c===`
3
+ `||c===`\r`)&&(r=null);continue}if(r===`multi`){c===`*`&&l===`/`&&(r=null,s++);continue}if(n){c===n&&e[s-1]!==`\\`?(n=null,a=i,i=``):i+=c;continue}if(c===`/`&&l===`/`){r=`single`,s++;continue}if(c===`/`&&l===`*`){r=`multi`,s++;continue}if(c===`'`||c===`"`||c==="`"){n=c,i=``;continue}if(c===`{`){o++,i=``,a=``;continue}if(c===`}`){o--,i=``,a=``;continue}if(c===`:`){if(o===0){let e=i.trim()||a.trim();e&&t.push(e)}i=``,a=``;continue}/[a-zA-Z0-9_$]/.test(c)?i+=c:(c===`,`||c===`
4
+ `||c===`\r`)&&(i=``,a=``)}return t}function d(e,t){return`/* eslint-disable */
5
+ // prettier-ignore
6
+ // biome-ignore format: auto-generated
7
+ /**
8
+ * @file env.gen.ts
9
+ * @note This file is auto-generated by ArkEnv. DO NOT EDIT DIRECTLY.
10
+ * @see https://arkenv.js.org
11
+ */
12
+
13
+ import { createEnv as coreCreateEnv } from "@arkenv/nextjs";
14
+ import type { Infer } from "@arkenv/nextjs";
15
+
16
+ export { type } from "@arkenv/nextjs";
17
+
18
+ export function createEnv<
19
+ const TServer extends Record<string, any> = {},
20
+ const TClient extends Record<string, any> = {},
21
+ const TShared extends Record<string, any> = {},
22
+ >(options: {
23
+ server?: TServer;
24
+ client?: TClient & {
25
+ [K in keyof TClient]: K extends \`NEXT_PUBLIC_\${string}\` ? unknown : never;
26
+ };
27
+ shared?: TShared;
28
+ }): Readonly<Infer<TServer & TClient & TShared>> {
29
+ return coreCreateEnv({
30
+ ...options,
31
+ runtimeEnv: {
32
+ ${Array.from(new Set([...e,...t])).map(e=>`\t\t\t${e}: process.env.${e},`).join(`
33
+ `)}
34
+ },
35
+ } as any) as any;
36
+ }
37
+ `}export{c as extractKeys,s as runCodegen,i as withArkEnv};
38
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { watch as chokidarWatch } from \"chokidar\";\n\n/**\n * Configuration options for the ArkEnv Next.js integration.\n *\n * @example\n * ```ts\n * const configOptions: ArkEnvConfigOptions = {\n * schemaPath: \"./src/env.ts\",\n * outputPath: \"./src/generated/env.gen.ts\"\n * };\n * ```\n */\nexport type ArkEnvConfigOptions = {\n\t/**\n\t * Specify the path to the schema definition file.\n\t *\n\t * Defaults to searching for `\"src/env.ts\"` or `\"env.ts\"` in the project root.\n\t *\n\t * @default \"src/env.ts\"\n\t * @example\n\t * ```ts\n\t * export default withArkEnv(nextConfig, {\n\t * schemaPath: \"./src/env.ts\"\n\t * });\n\t * ```\n\t */\n\tschemaPath?: string;\n\n\t/**\n\t * Specify the path where the generated file (`env.gen.ts`) should be written.\n\t *\n\t * Defaults to `\"generated/env.gen.ts\"` in the same directory as the schema file.\n\t *\n\t * @default \"[schemaDirectory]/generated/env.gen.ts\"\n\t * @example\n\t * ```ts\n\t * export default withArkEnv(nextConfig, {\n\t * outputPath: \"./src/generated/env.gen.ts\"\n\t * });\n\t * ```\n\t */\n\toutputPath?: string;\n};\n\nlet watcherInitialized = false;\n\n/**\n * Wrap a Next.js configuration object to automatically generate the `runtimeEnv` block in `env.gen.ts`.\n *\n * @param nextConfig The Next.js configuration object or function\n * @param options Optional configuration paths for schema and output files\n * @returns The Next.js configuration object unchanged\n * @throws An error if the schema file cannot be found or if code generation fails\n */\nexport function withArkEnv<T>(nextConfig: T, options?: ArkEnvConfigOptions): T {\n\t// 1. Locate the env.ts schema file\n\tconst schemaPath = options?.schemaPath\n\t\t? path.resolve(options.schemaPath)\n\t\t: findSchemaPath();\n\tif (!schemaPath || !fs.existsSync(schemaPath)) {\n\t\tthrow new Error(\n\t\t\t`[ArkEnv] Could not find schema file at ${\n\t\t\t\toptions?.schemaPath || \"src/env.ts or env.ts\"\n\t\t\t}. Please specify 'schemaPath' in withArkEnv options.`,\n\t\t);\n\t}\n\n\t// 2. Determine outputPath (defaults to generated/env.gen.ts in the same directory as schemaPath)\n\tconst defaultOutputDir = path.dirname(schemaPath);\n\tconst defaultOutputPath = path.join(\n\t\tdefaultOutputDir,\n\t\t\"generated\",\n\t\t\"env.gen.ts\",\n\t);\n\tconst outputPath = options?.outputPath\n\t\t? path.resolve(options.outputPath)\n\t\t: defaultOutputPath;\n\n\t// 3. Run initial code generation\n\ttry {\n\t\trunCodegen(schemaPath, outputPath);\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(`[ArkEnv] Failed to generate env.gen.ts: ${message}`);\n\t}\n\n\t// 4. Initialize development file watcher if in dev mode\n\t// Note: We check process.env.NODE_ENV or standard Next dev runtime markers\n\tconst isDev =\n\t\tprocess.env.NODE_ENV === \"development\" ||\n\t\tprocess.env.NEXT_PHASE === \"phase-development-server\";\n\tif (isDev) {\n\t\twatchSchema(schemaPath, outputPath);\n\t}\n\n\treturn nextConfig;\n}\n\n/**\n * Find the path to the schema file in the project.\n *\n * @returns The absolute path to the schema file, or null if not found\n */\nfunction findSchemaPath(): string | null {\n\tconst possiblePaths = [\n\t\tpath.join(process.cwd(), \"src\", \"env.ts\"),\n\t\tpath.join(process.cwd(), \"env.ts\"),\n\t];\n\tfor (const p of possiblePaths) {\n\t\tif (fs.existsSync(p)) return p;\n\t}\n\treturn null;\n}\n\n/**\n * Watch the schema file for changes and trigger codegen.\n *\n * @param schemaPath The absolute path to the schema file\n * @param outputPath The absolute path to the generated output file\n */\nfunction watchSchema(schemaPath: string, outputPath: string) {\n\tif (watcherInitialized) return;\n\twatcherInitialized = true;\n\n\ttry {\n\t\tchokidarWatch(schemaPath, { ignoreInitial: true }).on(\"change\", () => {\n\t\t\ttry {\n\t\t\t\trunCodegen(schemaPath, outputPath);\n\t\t\t} catch (err: unknown) {\n\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\t// biome-ignore lint/suspicious/noConsole: watcher errors must be logged\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[ArkEnv Watcher] Failed to regenerate env.gen.ts: ${message}`,\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t} catch (err: unknown) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t// biome-ignore lint/suspicious/noConsole: watcher errors must be logged\n\t\tconsole.error(\n\t\t\t`[ArkEnv Watcher] Failed to start watch on ${schemaPath}: ${message}`,\n\t\t);\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\n * @param outputPath The absolute path to the generated output file\n */\nexport function runCodegen(schemaPath: string, outputPath: string) {\n\tconst fileContent = fs.readFileSync(schemaPath, \"utf-8\");\n\tconst { clientKeys, sharedKeys } = extractKeys(fileContent);\n\n\tconst generatedCode = generateFactoryCode(clientKeys, sharedKeys);\n\n\t// Ensure parent directory exists\n\tconst outputDir = path.dirname(outputPath);\n\tif (!fs.existsSync(outputDir)) {\n\t\tfs.mkdirSync(outputDir, { recursive: true });\n\t}\n\n\t// Write if changed to avoid unnecessary filesystem/watcher triggers\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\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} {\n\tconst clientKeys: string[] = [];\n\tconst sharedKeys: string[] = [];\n\n\t// Extract client block\n\tconst clientBlock = extractBlock(content, \"client\");\n\tif (clientBlock) {\n\t\tclientKeys.push(...parseBlockKeys(clientBlock));\n\t}\n\n\t// Extract shared block\n\tconst sharedBlock = extractBlock(content, \"shared\");\n\tif (sharedBlock) {\n\t\tsharedKeys.push(...parseBlockKeys(sharedBlock));\n\t}\n\n\treturn { clientKeys, sharedKeys };\n}\n\n/**\n * Extract a specific block from the schema content by name.\n *\n * @param content The schema file string content\n * @param blockName The name of the block to extract (e.g., 'client' or 'shared')\n * @returns The contents of the block, or null if not found\n */\nfunction extractBlock(content: string, blockName: string): string | null {\n\t// Find \"\\bblockName\\s*:\\s*{\" or \"\\bblockName\\s*:\\s*type({\"\n\tconst regex = new RegExp(\n\t\t`\\\\b${blockName}\\\\s*:\\\\s*(?:[a-zA-Z0-9_$.]+\\\\s*\\\\(\\\\s*)?\\\\{`,\n\t\t\"g\",\n\t);\n\tconst match = regex.exec(content);\n\tif (!match) return null;\n\n\tconst startIndex = regex.lastIndex;\n\tlet braceCount = 1;\n\tlet index = startIndex;\n\tlet inString: string | null = null;\n\tlet inComment: \"single\" | \"multi\" | null = null;\n\n\twhile (index < content.length && braceCount > 0) {\n\t\tconst char = content[index];\n\t\tconst nextChar = content[index + 1];\n\n\t\tif (inComment === \"single\") {\n\t\t\tif (char === \"\\n\" || char === \"\\r\") inComment = null;\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (inComment === \"multi\") {\n\t\t\tif (char === \"*\" && nextChar === \"/\") {\n\t\t\t\tinComment = null;\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (inString) {\n\t\t\tif (char === inString && content[index - 1] !== \"\\\\\") {\n\t\t\t\tinString = null;\n\t\t\t}\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"/\" && nextChar === \"/\") {\n\t\t\tinComment = \"single\";\n\t\t\tindex += 2;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === \"/\" && nextChar === \"*\") {\n\t\t\tinComment = \"multi\";\n\t\t\tindex += 2;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === \"'\" || char === '\"' || char === \"`\") {\n\t\t\tinString = char;\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"{\") {\n\t\t\tbraceCount++;\n\t\t} else if (char === \"}\") {\n\t\t\tbraceCount--;\n\t\t}\n\t\tindex++;\n\t}\n\n\tif (braceCount === 0) {\n\t\treturn content.slice(startIndex, index - 1);\n\t}\n\n\treturn null;\n}\n\n/**\n * Parse environment variable keys from a block's content.\n *\n * @param blockContent The raw content of the block\n * @returns An array of parsed environment variable keys\n */\nfunction parseBlockKeys(blockContent: string): string[] {\n\tconst keys: string[] = [];\n\tlet inString: string | null = null;\n\tlet inComment: \"single\" | \"multi\" | null = null;\n\tlet currentToken = \"\";\n\tlet lastStringContent = \"\";\n\tlet braceDepth = 0;\n\n\tfor (let i = 0; i < blockContent.length; i++) {\n\t\tconst char = blockContent[i];\n\t\tconst nextChar = blockContent[i + 1];\n\n\t\tif (inComment === \"single\") {\n\t\t\tif (char === \"\\n\" || char === \"\\r\") inComment = null;\n\t\t\tcontinue;\n\t\t}\n\t\tif (inComment === \"multi\") {\n\t\t\tif (char === \"*\" && nextChar === \"/\") {\n\t\t\t\tinComment = null;\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (inString) {\n\t\t\tif (char === inString && blockContent[i - 1] !== \"\\\\\") {\n\t\t\t\tinString = null;\n\t\t\t\tlastStringContent = currentToken;\n\t\t\t\tcurrentToken = \"\";\n\t\t\t} else {\n\t\t\t\tcurrentToken += char;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Start comments/strings\n\t\tif (char === \"/\" && nextChar === \"/\") {\n\t\t\tinComment = \"single\";\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === \"/\" && nextChar === \"*\") {\n\t\t\tinComment = \"multi\";\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === \"'\" || char === '\"' || char === \"`\") {\n\t\t\tinString = char;\n\t\t\tcurrentToken = \"\";\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"{\") {\n\t\t\tbraceDepth++;\n\t\t\tcurrentToken = \"\";\n\t\t\tlastStringContent = \"\";\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === \"}\") {\n\t\t\tbraceDepth--;\n\t\t\tcurrentToken = \"\";\n\t\t\tlastStringContent = \"\";\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \":\") {\n\t\t\tif (braceDepth === 0) {\n\t\t\t\tconst key = currentToken.trim() || lastStringContent.trim();\n\t\t\t\tif (key) {\n\t\t\t\t\tkeys.push(key);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcurrentToken = \"\";\n\t\t\tlastStringContent = \"\";\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (/[a-zA-Z0-9_$]/.test(char)) {\n\t\t\tcurrentToken += char;\n\t\t} else if (char === \",\" || char === \"\\n\" || char === \"\\r\") {\n\t\t\tcurrentToken = \"\";\n\t\t\tlastStringContent = \"\";\n\t\t}\n\t}\n\n\treturn keys;\n}\n\n/**\n * Generate the TypeScript factory code for the tailored createEnv helper.\n *\n * @param clientKeys The client environment variable keys\n * @param sharedKeys The shared environment variable keys\n * @returns The generated TypeScript source code string\n */\nfunction generateFactoryCode(\n\tclientKeys: string[],\n\tsharedKeys: string[],\n): string {\n\tconst allKeys = Array.from(new Set([...clientKeys, ...sharedKeys]));\n\tconst runtimeEnvLines = allKeys\n\t\t.map((key) => `\\t\\t\\t${key}: process.env.${key},`)\n\t\t.join(\"\\n\");\n\n\treturn `/* eslint-disable */\n// prettier-ignore\n// biome-ignore format: auto-generated\n/**\n * @file env.gen.ts\n * @note This file is auto-generated by ArkEnv. DO NOT EDIT DIRECTLY.\n * @see https://arkenv.js.org\n */\n\nimport { createEnv as coreCreateEnv } from \"@arkenv/nextjs\";\nimport type { Infer } from \"@arkenv/nextjs\";\n\nexport { type } from \"@arkenv/nextjs\";\n\nexport function createEnv<\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}): Readonly<Infer<TServer & TClient & TShared>> {\n\treturn coreCreateEnv({\n\t\t...options,\n\t\truntimeEnv: {\n${runtimeEnvLines}\n\t\t},\n\t} as any) as any;\n}\n`;\n}\n"],"mappings":"iFA+CA,IAAI,EAAqB,GAUzB,SAAgB,EAAc,EAAe,EAAkC,CAE9E,IAAM,EAAa,GAAS,WACzB,EAAK,QAAQ,EAAQ,WAAW,CAChC,GAAgB,CACnB,GAAI,CAAC,GAAc,CAAC,EAAG,WAAW,EAAW,CAC5C,MAAU,MACT,0CACC,GAAS,YAAc,uBACvB,sDACD,CAIF,IAAM,EAAmB,EAAK,QAAQ,EAAW,CAC3C,EAAoB,EAAK,KAC9B,EACA,YACA,aACA,CACK,EAAa,GAAS,WACzB,EAAK,QAAQ,EAAQ,WAAW,CAChC,EAGH,GAAI,CACH,EAAW,EAAY,EAAW,OAC1B,EAAgB,CACxB,IAAM,EAAU,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,CACtE,MAAU,MAAM,2CAA2C,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ED,GAAI,IAAc,QAAS,CACtB,IAAS,KAAO,IAAa,MAChC,EAAY,KACZ,KAED,SAGD,GAAI,EAAU,CACT,IAAS,GAAY,EAAa,EAAI,KAAO,MAChD,EAAW,KACX,EAAoB,EACpB,EAAe,IAEf,GAAgB,EAEjB,SAID,GAAI,IAAS,KAAO,IAAa,IAAK,CACrC,EAAY,SACZ,IACA,SAED,GAAI,IAAS,KAAO,IAAa,IAAK,CACrC,EAAY,QACZ,IACA,SAED,GAAI,IAAS,KAAO,IAAS,KAAO,IAAS,IAAK,CACjD,EAAW,EACX,EAAe,GACf,SAGD,GAAI,IAAS,IAAK,CACjB,IACA,EAAe,GACf,EAAoB,GACpB,SAED,GAAI,IAAS,IAAK,CACjB,IACA,EAAe,GACf,EAAoB,GACpB,SAGD,GAAI,IAAS,IAAK,CACjB,GAAI,IAAe,EAAG,CACrB,IAAM,EAAM,EAAa,MAAM,EAAI,EAAkB,MAAM,CACvD,GACH,EAAK,KAAK,EAAI,CAGhB,EAAe,GACf,EAAoB,GACpB,SAGG,gBAAgB,KAAK,EAAK,CAC7B,GAAgB,GACN,IAAS,KAAO,IAAS;GAAQ,IAAS,QACpD,EAAe,GACf,EAAoB,IAItB,OAAO,EAUR,SAAS,EACR,EACA,EACS,CAMT,MAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;EALS,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,EAAY,GAAG,EAAW,CAAC,CACnC,CAC7B,IAAK,GAAQ,SAAS,EAAI,gBAAgB,EAAI,GAAG,CACjD,KAAK;EA8BS,CAAC"}
@@ -0,0 +1,2 @@
1
+ import{createEnv as e}from"arkenv";const t=Symbol.for(`arkenv.extended_env`),n=Symbol.for(`arkenv.keys`),r=Symbol.for(`arkenv.server_only_keys`);function i(e){if(!e||typeof e!=`object`&&typeof e!=`function`)return[];if(e.json&&typeof e.json==`object`&&e.json.domain===`object`){let t=[];if(Array.isArray(e.json.required))for(let n of e.json.required)n&&typeof n==`object`&&`key`in n&&t.push(n.key);if(Array.isArray(e.json.optional))for(let n of e.json.optional)n&&typeof n==`object`&&`key`in n&&t.push(n.key);return t}return`shape`in e&&e.shape&&typeof e.shape==`object`?Object.keys(e.shape):`entries`in e&&e.entries&&typeof e.entries==`object`?Object.keys(e.entries):Object.keys(e)}function a(a,o,s){let c={},l={},u={},d=[],f={},p=!1;if(typeof o==`boolean`)c=a.server||{},l=a.client||{},u=a.shared||{},d=a.extends||[],f=a.runtimeEnv||{},p=o;else{let e=a||{},t=o||{};d=t.extends||[],f=t.runtimeEnv||{},p=!!s?.isServer,s?.isShared?u=e:p?c=e:l=e}let m={},h=new Set,g=new Set;for(let e of Object.keys(c))h.add(e),!(e in l)&&!(e in u)&&g.add(e);for(let e of Object.keys(l))h.add(e);for(let e of Object.keys(u))h.add(e);let _={};if(d&&Array.isArray(d)){for(let a of d)if(a&&(typeof a==`object`||typeof a==`function`)){let o=a[t];if(o){m={...m,...o};let e=a[n];if(e instanceof Set)for(let t of e)h.add(t);let t=a[r];if(t instanceof Set)for(let e of t)g.add(e)}else{for(let e of Object.keys(m))m[e]!==void 0&&(_[e]=String(m[e]));for(let e of Object.keys(f))f[e]!==void 0&&(_[e]=f[e]);if(p)for(let e of Object.keys(c))_[e]===void 0&&process.env[e]!==void 0&&(_[e]=process.env[e]);let t=e(a,{env:_});m={...m,...t};let n=i(a);for(let e of n)h.add(e),p&&!e.startsWith(`NEXT_PUBLIC_`)&&!s?.isShared&&g.add(e)}}}for(let e of Object.keys(l))g.delete(e);for(let e of Object.keys(u))g.delete(e);for(let e of Object.keys(l))if(!e.startsWith(`NEXT_PUBLIC_`))throw Error(`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${e}`);let v=[...Object.keys(l),...Object.keys(u)];for(let e of v)if(!(e in f))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(f))if(!h.has(e))throw Error(`Environment variable '${e}' is passed to runtimeEnv but is not defined in the schema.`);for(let e of Object.keys(m))m[e]!==void 0&&(_[e]=String(m[e]));for(let e of Object.keys(f))f[e]!==void 0&&(_[e]=f[e]);if(p)for(let e of Object.keys(c))_[e]===void 0&&process.env[e]!==void 0&&(_[e]=process.env[e]);let y=e(p?{...c,...l,...u}:{...l,...u},{env:_}),b={...m,...y};return new Proxy(b,{get(e,i,a){if(i===t)return e;if(i===n)return h;if(i===r)return g;if(typeof i==`symbol`)return Reflect.get(e,i,a);if(typeof i==`string`){if(g.has(i)&&!p)throw Error(`Accessing server-side environment variable '${i}' on the client is not allowed.`);if(!h.has(i)&&!(i in Object.prototype)&&!(i===`__esModule`||i===`$$typeof`||i===`toJSON`||i===`inspect`))throw Error(`Environment variable '${i}' is not defined in the schema.`)}return Reflect.get(e,i,a)}})}export{a as t};
2
+ //# sourceMappingURL=create-env-BfXQtLQM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-env-BfXQtLQM.js","names":["coreCreateEnv"],"sources":["../src/create-env.ts"],"sourcesContent":["import type { SchemaShape } from \"@repo/types\";\nimport { createEnv as coreCreateEnv } from \"arkenv\";\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\nfunction getSchemaKeys(schema: any): string[] {\n\tif (!schema || (typeof schema !== \"object\" && typeof schema !== \"function\")) {\n\t\treturn [];\n\t}\n\n\t// ArkType Type\n\tif (\n\t\tschema.json &&\n\t\ttypeof schema.json === \"object\" &&\n\t\tschema.json.domain === \"object\"\n\t) {\n\t\tconst keys: string[] = [];\n\t\tif (Array.isArray(schema.json.required)) {\n\t\t\tfor (const r of schema.json.required) {\n\t\t\t\tif (r && typeof r === \"object\" && \"key\" in r) {\n\t\t\t\t\tkeys.push(r.key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (Array.isArray(schema.json.optional)) {\n\t\t\tfor (const o of schema.json.optional) {\n\t\t\t\tif (o && typeof o === \"object\" && \"key\" in o) {\n\t\t\t\t\tkeys.push(o.key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn keys;\n\t}\n\n\t// Zod schema\n\tif (\"shape\" in schema && schema.shape && typeof schema.shape === \"object\") {\n\t\treturn Object.keys(schema.shape);\n\t}\n\n\t// Valibot schema\n\tif (\n\t\t\"entries\" in schema &&\n\t\tschema.entries &&\n\t\ttypeof schema.entries === \"object\"\n\t) {\n\t\treturn Object.keys(schema.entries);\n\t}\n\n\t// Plain object schema\n\treturn Object.keys(schema);\n}\n\n/**\n * Validate and wrap environment variables in a security proxy.\n *\n * @internal\n */\nexport function createEnvInternal(\n\tschemaOrOptions: any,\n\toptionsOrIsServer: any,\n\tcontext?: { isServer: boolean; isShared?: boolean },\n): unknown {\n\tlet server: SchemaShape = {};\n\tlet client: Record<string, unknown> = {};\n\tlet shared: SchemaShape = {};\n\tlet extendsList: unknown[] = [];\n\tlet runtimeEnv: Record<string, unknown> = {};\n\tlet isServer = false;\n\n\tif (typeof optionsOrIsServer === \"boolean\") {\n\t\t// Old nested schema behavior (backward compatible)\n\t\tserver = schemaOrOptions.server || {};\n\t\tclient = schemaOrOptions.client || {};\n\t\tshared = schemaOrOptions.shared || {};\n\t\textendsList = schemaOrOptions.extends || [];\n\t\truntimeEnv = schemaOrOptions.runtimeEnv || {};\n\t\tisServer = optionsOrIsServer;\n\t} else {\n\t\t// New flat schema behavior\n\t\tconst flatSchema = schemaOrOptions || {};\n\t\tconst options = optionsOrIsServer || {};\n\t\textendsList = options.extends || [];\n\t\truntimeEnv = options.runtimeEnv || {};\n\t\tisServer = !!context?.isServer;\n\n\t\tif (context?.isShared) {\n\t\t\tshared = flatSchema;\n\t\t} else if (isServer) {\n\t\t\tserver = flatSchema;\n\t\t} else {\n\t\t\tclient = flatSchema;\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, string | undefined> = {};\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 any)[EXTENDED_ENV];\n\t\t\t\tif (raw) {\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...raw };\n\n\t\t\t\t\tconst extKeys = (ext as any)[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 any)[SERVER_ONLY_KEYS];\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] = String(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] as string;\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 = coreCreateEnv(ext as any, { env: combinedEnv });\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...validated };\n\n\t\t\t\t\tconst extKeys = getSchemaKeys(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 if we are on the server, it's not a public key,\n\t\t\t\t\t\t// and we aren't explicitly inside the shared entry point.\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] = String(extendedEnvValues[key]);\n\t\t}\n\t}\n\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\tcombinedEnv[key] = runtimeEnv[key] as string;\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 = coreCreateEnv(schema as any, { env: combinedEnv });\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(\n\t\t\t\t\t\t`Accessing server-side environment variable '${prop}' on the client is not allowed.`,\n\t\t\t\t\t);\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":"mCAGA,MAAa,EAAe,OAAO,IAAI,sBAAsB,CAChD,EAAW,OAAO,IAAI,cAAc,CACpC,EAAmB,OAAO,IAAI,0BAA0B,CAErE,SAAS,EAAc,EAAuB,CAC7C,GAAI,CAAC,GAAW,OAAO,GAAW,UAAY,OAAO,GAAW,WAC/D,MAAO,EAAE,CAIV,GACC,EAAO,MACP,OAAO,EAAO,MAAS,UACvB,EAAO,KAAK,SAAW,SACtB,CACD,IAAM,EAAiB,EAAE,CACzB,GAAI,MAAM,QAAQ,EAAO,KAAK,SAAS,KACjC,IAAM,KAAK,EAAO,KAAK,SACvB,GAAK,OAAO,GAAM,UAAY,QAAS,GAC1C,EAAK,KAAK,EAAE,IAAI,CAInB,GAAI,MAAM,QAAQ,EAAO,KAAK,SAAS,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AS,UACT,IAAS,WAGT,MAAU,MACT,yBAAyB,EAAK,iCAC9B,CAIJ,OAAO,QAAQ,IAAI,EAAQ,EAAM,EAAS,EAE3C,CAAC"}
@@ -0,0 +1,2 @@
1
+ require(`./config.cjs`);let e=require(`arkenv`);const t=Symbol.for(`arkenv.extended_env`),n=Symbol.for(`arkenv.keys`),r=Symbol.for(`arkenv.server_only_keys`);function i(e){if(!e||typeof e!=`object`&&typeof e!=`function`)return[];if(e.json&&typeof e.json==`object`&&e.json.domain===`object`){let t=[];if(Array.isArray(e.json.required))for(let n of e.json.required)n&&typeof n==`object`&&`key`in n&&t.push(n.key);if(Array.isArray(e.json.optional))for(let n of e.json.optional)n&&typeof n==`object`&&`key`in n&&t.push(n.key);return t}return`shape`in e&&e.shape&&typeof e.shape==`object`?Object.keys(e.shape):`entries`in e&&e.entries&&typeof e.entries==`object`?Object.keys(e.entries):Object.keys(e)}function a(a,o,s){let c={},l={},u={},d=[],f={},p=!1;if(typeof o==`boolean`)c=a.server||{},l=a.client||{},u=a.shared||{},d=a.extends||[],f=a.runtimeEnv||{},p=o;else{let e=a||{},t=o||{};d=t.extends||[],f=t.runtimeEnv||{},p=!!s?.isServer,s?.isShared?u=e:p?c=e:l=e}let m={},h=new Set,g=new Set;for(let e of Object.keys(c))h.add(e),!(e in l)&&!(e in u)&&g.add(e);for(let e of Object.keys(l))h.add(e);for(let e of Object.keys(u))h.add(e);let _={};if(d&&Array.isArray(d)){for(let a of d)if(a&&(typeof a==`object`||typeof a==`function`)){let o=a[t];if(o){m={...m,...o};let e=a[n];if(e instanceof Set)for(let t of e)h.add(t);let t=a[r];if(t instanceof Set)for(let e of t)g.add(e)}else{for(let e of Object.keys(m))m[e]!==void 0&&(_[e]=String(m[e]));for(let e of Object.keys(f))f[e]!==void 0&&(_[e]=f[e]);if(p)for(let e of Object.keys(c))_[e]===void 0&&process.env[e]!==void 0&&(_[e]=process.env[e]);let t=(0,e.createEnv)(a,{env:_});m={...m,...t};let n=i(a);for(let e of n)h.add(e),p&&!e.startsWith(`NEXT_PUBLIC_`)&&!s?.isShared&&g.add(e)}}}for(let e of Object.keys(l))g.delete(e);for(let e of Object.keys(u))g.delete(e);for(let e of Object.keys(l))if(!e.startsWith(`NEXT_PUBLIC_`))throw Error(`Client-side environment variables must be prefixed with 'NEXT_PUBLIC_'. Found invalid key: ${e}`);let v=[...Object.keys(l),...Object.keys(u)];for(let e of v)if(!(e in f))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(f))if(!h.has(e))throw Error(`Environment variable '${e}' is passed to runtimeEnv but is not defined in the schema.`);for(let e of Object.keys(m))m[e]!==void 0&&(_[e]=String(m[e]));for(let e of Object.keys(f))f[e]!==void 0&&(_[e]=f[e]);if(p)for(let e of Object.keys(c))_[e]===void 0&&process.env[e]!==void 0&&(_[e]=process.env[e]);let y=(0,e.createEnv)(p?{...c,...l,...u}:{...l,...u},{env:_}),b={...m,...y};return new Proxy(b,{get(e,i,a){if(i===t)return e;if(i===n)return h;if(i===r)return g;if(typeof i==`symbol`)return Reflect.get(e,i,a);if(typeof i==`string`){if(g.has(i)&&!p)throw Error(`Accessing server-side environment variable '${i}' on the client is not allowed.`);if(!h.has(i)&&!(i in Object.prototype)&&!(i===`__esModule`||i===`$$typeof`||i===`toJSON`||i===`inspect`))throw Error(`Environment variable '${i}' is not defined in the schema.`)}return Reflect.get(e,i,a)}})}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return a}});
2
+ //# sourceMappingURL=create-env-DDWVuzwL.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-env-DDWVuzwL.cjs","names":[],"sources":["../src/create-env.ts"],"sourcesContent":["import type { SchemaShape } from \"@repo/types\";\nimport { createEnv as coreCreateEnv } from \"arkenv\";\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\nfunction getSchemaKeys(schema: any): string[] {\n\tif (!schema || (typeof schema !== \"object\" && typeof schema !== \"function\")) {\n\t\treturn [];\n\t}\n\n\t// ArkType Type\n\tif (\n\t\tschema.json &&\n\t\ttypeof schema.json === \"object\" &&\n\t\tschema.json.domain === \"object\"\n\t) {\n\t\tconst keys: string[] = [];\n\t\tif (Array.isArray(schema.json.required)) {\n\t\t\tfor (const r of schema.json.required) {\n\t\t\t\tif (r && typeof r === \"object\" && \"key\" in r) {\n\t\t\t\t\tkeys.push(r.key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (Array.isArray(schema.json.optional)) {\n\t\t\tfor (const o of schema.json.optional) {\n\t\t\t\tif (o && typeof o === \"object\" && \"key\" in o) {\n\t\t\t\t\tkeys.push(o.key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn keys;\n\t}\n\n\t// Zod schema\n\tif (\"shape\" in schema && schema.shape && typeof schema.shape === \"object\") {\n\t\treturn Object.keys(schema.shape);\n\t}\n\n\t// Valibot schema\n\tif (\n\t\t\"entries\" in schema &&\n\t\tschema.entries &&\n\t\ttypeof schema.entries === \"object\"\n\t) {\n\t\treturn Object.keys(schema.entries);\n\t}\n\n\t// Plain object schema\n\treturn Object.keys(schema);\n}\n\n/**\n * Validate and wrap environment variables in a security proxy.\n *\n * @internal\n */\nexport function createEnvInternal(\n\tschemaOrOptions: any,\n\toptionsOrIsServer: any,\n\tcontext?: { isServer: boolean; isShared?: boolean },\n): unknown {\n\tlet server: SchemaShape = {};\n\tlet client: Record<string, unknown> = {};\n\tlet shared: SchemaShape = {};\n\tlet extendsList: unknown[] = [];\n\tlet runtimeEnv: Record<string, unknown> = {};\n\tlet isServer = false;\n\n\tif (typeof optionsOrIsServer === \"boolean\") {\n\t\t// Old nested schema behavior (backward compatible)\n\t\tserver = schemaOrOptions.server || {};\n\t\tclient = schemaOrOptions.client || {};\n\t\tshared = schemaOrOptions.shared || {};\n\t\textendsList = schemaOrOptions.extends || [];\n\t\truntimeEnv = schemaOrOptions.runtimeEnv || {};\n\t\tisServer = optionsOrIsServer;\n\t} else {\n\t\t// New flat schema behavior\n\t\tconst flatSchema = schemaOrOptions || {};\n\t\tconst options = optionsOrIsServer || {};\n\t\textendsList = options.extends || [];\n\t\truntimeEnv = options.runtimeEnv || {};\n\t\tisServer = !!context?.isServer;\n\n\t\tif (context?.isShared) {\n\t\t\tshared = flatSchema;\n\t\t} else if (isServer) {\n\t\t\tserver = flatSchema;\n\t\t} else {\n\t\t\tclient = flatSchema;\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, string | undefined> = {};\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 any)[EXTENDED_ENV];\n\t\t\t\tif (raw) {\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...raw };\n\n\t\t\t\t\tconst extKeys = (ext as any)[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 any)[SERVER_ONLY_KEYS];\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] = String(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] as string;\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 = coreCreateEnv(ext as any, { env: combinedEnv });\n\t\t\t\t\textendedEnvValues = { ...extendedEnvValues, ...validated };\n\n\t\t\t\t\tconst extKeys = getSchemaKeys(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 if we are on the server, it's not a public key,\n\t\t\t\t\t\t// and we aren't explicitly inside the shared entry point.\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] = String(extendedEnvValues[key]);\n\t\t}\n\t}\n\n\tfor (const key of Object.keys(runtimeEnv)) {\n\t\tif (runtimeEnv[key] !== undefined) {\n\t\t\tcombinedEnv[key] = runtimeEnv[key] as string;\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 = coreCreateEnv(schema as any, { env: combinedEnv });\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(\n\t\t\t\t\t\t`Accessing server-side environment variable '${prop}' on the client is not allowed.`,\n\t\t\t\t\t);\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":"gDAGA,MAAa,EAAe,OAAO,IAAI,sBAAsB,CAChD,EAAW,O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