@quintal/environment 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("zod");function f(r){return Object.entries(r).reduce((n,[t,e])=>(typeof e=="string"||typeof e>"u"?n[t]=e:"value"in e?n[t]=e.value||void 0:n[t]=f(e),n),{})}function l(r,n){const t=Object.entries(r).reduce((e,[u,i])=>(typeof i=="string"||typeof i>"u"?e[u]=a.z.string():"value"in i?(!i.isServerOnly||n)&&(e[u]=i.schema??a.z.string()):e[u]=l(i,n),e),{});return a.z.object(t)}function d(r,n,t,e,u){return new Proxy(r,{get(i,s){const c=n[s];if(!c)return;if(typeof c=="string")return c;const o=u?`${u}.${s}`:s;return"value"in c?c.isServerOnly&&!t?e(o):i[s]:d(r[s],n[s],t,e,o)}})}function v(r){const n=r.isServer??typeof window>"u",t=r.onValidationError??(c=>{throw new Error(`❌ Invalid environment variables:
2
- ${a.z.prettifyError(c)}`)}),e=r.onAccessError??(c=>{throw new Error(`❌ Attempted to access server-side environment variable '${c}' on the client`)}),u=l(r.values,n),i=f(r.values),s=u.safeParse(i);return s.success?d(s.data,r.values,n,e):t(s.error)}exports.createEnvironment=v;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("zod");function f(r){return Object.entries(r).reduce((n,[t,e])=>(typeof e=="string"||typeof e>"u"?n[t]=e:"value"in e?n[t]=e.value||void 0:n[t]=f(e),n),{})}function l(r,n){const t=Object.entries(r).reduce((e,[c,i])=>(typeof i=="string"||typeof i>"u"?e[c]=a.z.string():"value"in i?(!i.isServerOnly||n)&&(e[c]=i.schema??a.z.string()):e[c]=l(i,n),e),{});return a.z.object(t)}function d(r,n,t,e,c){return new Proxy(r,{get(i,s){const u=n[s];if(!u)return;if(typeof u=="string")return u;const o=c?`${c}.${s}`:s;return"value"in u?u.isServerOnly&&!t?e(o):i[s]:d(r[s],n[s],t,e,o)}})}function v(r){if(r.isDisabled)return null;const n=r.isServer??typeof window>"u",t=r.onValidationError??(u=>{throw new Error(`❌ Invalid environment variables:
2
+ ${a.z.prettifyError(u)}`)}),e=r.onAccessError??(u=>{throw new Error(`❌ Attempted to access server-side environment variable '${u}' on the client`)}),c=l(r.values,n),i=f(r.values),s=c.safeParse(i);return s.success?d(s.data,r.values,n,e):t(s.error)}exports.createEnvironment=v;
package/.dist/index.d.ts CHANGED
@@ -4,6 +4,12 @@ import { ZodType } from 'zod';
4
4
  export declare function createEnvironment<TEnvValues extends EnvValues>(opts: CreateEnvironmentOptions<TEnvValues>): UnwrapEnvValues<TEnvValues>;
5
5
 
6
6
  declare type CreateEnvironmentOptions<TEnvValues extends EnvValues> = {
7
+ /**
8
+ * Whether or not the environment variable validation should be disabled.
9
+ * Enabling this option will make `createEnvironment` return `null`.
10
+ * @defaultValue false
11
+ */
12
+ isDisabled?: boolean;
7
13
  /**
8
14
  * Whether or not the application is running on the server.
9
15
  * @defaultValue typeof window === 'undefined'
package/.dist/index.mjs CHANGED
@@ -1,43 +1,44 @@
1
- import { z as a } from "zod";
2
- function f(r) {
1
+ import { z as c } from "zod";
2
+ function o(r) {
3
3
  return Object.entries(r).reduce(
4
- (n, [t, e]) => (typeof e == "string" || typeof e > "u" ? n[t] = e : "value" in e ? n[t] = e.value || void 0 : n[t] = f(e), n),
4
+ (n, [t, e]) => (typeof e == "string" || typeof e > "u" ? n[t] = e : "value" in e ? n[t] = e.value || void 0 : n[t] = o(e), n),
5
5
  {}
6
6
  );
7
7
  }
8
8
  function l(r, n) {
9
9
  const t = Object.entries(r).reduce(
10
- (e, [u, i]) => (typeof i == "string" || typeof i > "u" ? e[u] = a.string() : "value" in i ? (!i.isServerOnly || n) && (e[u] = i.schema ?? a.string()) : e[u] = l(i, n), e),
10
+ (e, [a, i]) => (typeof i == "string" || typeof i > "u" ? e[a] = c.string() : "value" in i ? (!i.isServerOnly || n) && (e[a] = i.schema ?? c.string()) : e[a] = l(i, n), e),
11
11
  {}
12
12
  );
13
- return a.object(t);
13
+ return c.object(t);
14
14
  }
15
- function d(r, n, t, e, u) {
15
+ function d(r, n, t, e, a) {
16
16
  return new Proxy(r, {
17
17
  get(i, s) {
18
- const c = n[s];
19
- if (!c) return;
20
- if (typeof c == "string") return c;
21
- const o = u ? `${u}.${s}` : s;
22
- return "value" in c ? c.isServerOnly && !t ? e(o) : i[s] : d(
18
+ const u = n[s];
19
+ if (!u) return;
20
+ if (typeof u == "string") return u;
21
+ const f = a ? `${a}.${s}` : s;
22
+ return "value" in u ? u.isServerOnly && !t ? e(f) : i[s] : d(
23
23
  r[s],
24
24
  n[s],
25
25
  t,
26
26
  e,
27
- o
27
+ f
28
28
  );
29
29
  }
30
30
  });
31
31
  }
32
32
  function y(r) {
33
- const n = r.isServer ?? typeof window > "u", t = r.onValidationError ?? ((c) => {
33
+ if (r.isDisabled) return null;
34
+ const n = r.isServer ?? typeof window > "u", t = r.onValidationError ?? ((u) => {
34
35
  throw new Error(`❌ Invalid environment variables:
35
- ${a.prettifyError(c)}`);
36
- }), e = r.onAccessError ?? ((c) => {
36
+ ${c.prettifyError(u)}`);
37
+ }), e = r.onAccessError ?? ((u) => {
37
38
  throw new Error(
38
- `❌ Attempted to access server-side environment variable '${c}' on the client`
39
+ `❌ Attempted to access server-side environment variable '${u}' on the client`
39
40
  );
40
- }), u = l(r.values, n), i = f(r.values), s = u.safeParse(i);
41
+ }), a = l(r.values, n), i = o(r.values), s = a.safeParse(i);
41
42
  return s.success ? d(
42
43
  s.data,
43
44
  r.values,
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Quintal Web Solutions
3
+ Copyright (c) 2026 Quintal Web Solutions
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintal/environment",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "license": "MIT",
5
5
  "description": "Framework-agnostic environment variable validation for TypeScript powered by Zod",
6
6
  "keywords": [