node-env-resolver 6.1.1 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +196 -9
- package/dist/audit.cjs +1 -1
- package/dist/audit.js +1 -1
- package/dist/builder.cjs +1 -1
- package/dist/builder.js +1 -1
- package/dist/{chunk-LCW5BDAW.js → chunk-27CQXH2M.js} +1 -1
- package/dist/chunk-5XUR34FH.js +9 -0
- package/dist/chunk-6EWR3WHU.js +1 -0
- package/dist/{chunk-LBBZGOOS.cjs → chunk-AYZL6CFC.cjs} +3 -3
- package/dist/{chunk-KQ2QINQR.js → chunk-CH4V6URL.js} +3 -3
- package/dist/chunk-D6WM53FN.cjs +1 -0
- package/dist/chunk-I7AUKTXE.js +1 -0
- package/dist/chunk-O7NR4K6A.cjs +1 -0
- package/dist/chunk-Y2QEFWEY.cjs +9 -0
- package/dist/{chunk-PNUGGPRS.cjs → chunk-Z3TI2YXP.cjs} +4 -4
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/resolver.cjs +1 -1
- package/dist/resolver.js +1 -1
- package/dist/resolvers.cjs +1 -1
- package/dist/resolvers.js +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.js +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/valibot.cjs +1 -1
- package/dist/valibot.js +1 -1
- package/dist/validators.cjs +1 -1
- package/dist/validators.js +1 -1
- package/dist/web.cjs +3 -3
- package/dist/web.js +1 -1
- package/dist/zod.cjs +1 -1
- package/dist/zod.js +1 -1
- package/package.json +50 -8
- package/dist/chunk-4ZOF2PI4.cjs +0 -1
- package/dist/chunk-4ZYJXIBG.js +0 -9
- package/dist/chunk-5PELJRUQ.js +0 -1
- package/dist/chunk-KIQXH265.cjs +0 -1
- package/dist/chunk-RQBTOG2W.cjs +0 -9
- package/dist/chunk-YOHHFBZN.js +0 -1
package/README.md
CHANGED
|
@@ -12,6 +12,41 @@ Type-safe environment variable resolution with zero dependencies and ultra-small
|
|
|
12
12
|
npm install node-env-resolver
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
### TypeScript Configuration
|
|
16
|
+
|
|
17
|
+
This package uses modern [package.json `exports`](https://nodejs.org/api/packages.html#exports) for subpath imports (like `node-env-resolver/resolvers`). Your `tsconfig.json` must use a modern module resolution strategy.
|
|
18
|
+
|
|
19
|
+
**What to change:**
|
|
20
|
+
|
|
21
|
+
If your `tsconfig.json` has:
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"compilerOptions": {
|
|
25
|
+
"module": "CommonJS",
|
|
26
|
+
"moduleResolution": "node"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Change it to:**
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"compilerOptions": {
|
|
35
|
+
"module": "NodeNext", // Changed from "CommonJS"
|
|
36
|
+
"moduleResolution": "NodeNext" // Changed from "node"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Alternative options:**
|
|
42
|
+
- For bundler projects (Vite, Webpack, etc.): Use `"moduleResolution": "bundler"` (you can keep `"module": "CommonJS"` or use `"ESNext"`)
|
|
43
|
+
- For Node.js projects: Use `"moduleResolution": "node16"` with `"module": "node16"`
|
|
44
|
+
|
|
45
|
+
**Required values:** `"node16"`, `"nodenext"`, or `"bundler"`
|
|
46
|
+
**Not supported:** `"node"` (legacy resolution doesn't understand exports)
|
|
47
|
+
|
|
48
|
+
If you see module resolution errors, see the [Troubleshooting](#troubleshooting) section below.
|
|
49
|
+
|
|
15
50
|
## Quick start (uses process.env)
|
|
16
51
|
|
|
17
52
|
```ts
|
|
@@ -1662,32 +1697,184 @@ if (policyViolations.length > 0) {
|
|
|
1662
1697
|
|
|
1663
1698
|
## Troubleshooting
|
|
1664
1699
|
|
|
1665
|
-
### TypeScript: Cannot find module 'node-env-resolver/validators'
|
|
1700
|
+
### TypeScript: Cannot find module 'node-env-resolver/resolvers' or 'node-env-resolver/validators'
|
|
1666
1701
|
|
|
1667
|
-
|
|
1702
|
+
This package uses modern [package.json `exports`](https://nodejs.org/api/packages.html#exports) for subpath exports (like `node-env-resolver/resolvers`). TypeScript requires a modern module resolution strategy to understand these exports.
|
|
1668
1703
|
|
|
1669
|
-
**
|
|
1704
|
+
**If you see this error:**
|
|
1705
|
+
```
|
|
1706
|
+
Cannot find module 'node-env-resolver/resolvers' or its corresponding type declarations.
|
|
1707
|
+
There are types at '.../node_modules/node-env-resolver/dist/resolvers.d.ts',
|
|
1708
|
+
but this result could not be resolved under your current 'moduleResolution' setting.
|
|
1709
|
+
Consider updating to 'node16', 'nodenext', or 'bundler'.
|
|
1710
|
+
```
|
|
1711
|
+
|
|
1712
|
+
**Solution:** Update your `tsconfig.json` to use a modern module resolution strategy.
|
|
1670
1713
|
|
|
1671
|
-
|
|
1714
|
+
**Example - if your config currently has:**
|
|
1672
1715
|
```json
|
|
1673
1716
|
{
|
|
1674
1717
|
"compilerOptions": {
|
|
1675
|
-
"
|
|
1676
|
-
"
|
|
1718
|
+
"module": "CommonJS",
|
|
1719
|
+
"moduleResolution": "node"
|
|
1677
1720
|
}
|
|
1678
1721
|
}
|
|
1679
1722
|
```
|
|
1680
1723
|
|
|
1681
|
-
|
|
1724
|
+
**Change to one of these options:**
|
|
1725
|
+
|
|
1726
|
+
1. **`moduleResolution: "NodeNext"`** (recommended for most Node.js projects):
|
|
1682
1727
|
```json
|
|
1683
1728
|
{
|
|
1684
1729
|
"compilerOptions": {
|
|
1685
|
-
"
|
|
1730
|
+
"module": "NodeNext", // Changed from "CommonJS"
|
|
1731
|
+
"moduleResolution": "NodeNext" // Changed from "node"
|
|
1686
1732
|
}
|
|
1687
1733
|
}
|
|
1688
1734
|
```
|
|
1689
1735
|
|
|
1690
|
-
|
|
1736
|
+
2. **`moduleResolution: "bundler"`** (for bundler-based projects like Vite, Webpack, etc.):
|
|
1737
|
+
```json
|
|
1738
|
+
{
|
|
1739
|
+
"compilerOptions": {
|
|
1740
|
+
"module": "CommonJS", // Can keep this or use "ESNext"
|
|
1741
|
+
"moduleResolution": "bundler" // Changed from "node"
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
```
|
|
1745
|
+
|
|
1746
|
+
3. **`moduleResolution: "node16"`** (alternative to NodeNext):
|
|
1747
|
+
```json
|
|
1748
|
+
{
|
|
1749
|
+
"compilerOptions": {
|
|
1750
|
+
"module": "node16", // Changed from "CommonJS"
|
|
1751
|
+
"moduleResolution": "node16" // Changed from "node"
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
```
|
|
1755
|
+
|
|
1756
|
+
**Why this is required:**
|
|
1757
|
+
- The legacy `moduleResolution: "node"` strategy doesn't understand package.json `exports` field
|
|
1758
|
+
- Modern resolution strategies (`node16`, `nodenext`, `bundler`) properly support subpath exports
|
|
1759
|
+
- This is a TypeScript configuration requirement, not a runtime issue - your code will run correctly regardless
|
|
1760
|
+
|
|
1761
|
+
**Note:** The runtime will work correctly regardless of TypeScript's resolution mode. This is purely a TypeScript type-checking issue.
|
|
1762
|
+
|
|
1763
|
+
## Testing
|
|
1764
|
+
|
|
1765
|
+
### Recommended: Dependency Injection
|
|
1766
|
+
|
|
1767
|
+
For testable code, accept resolvers as parameters rather than importing them directly:
|
|
1768
|
+
|
|
1769
|
+
```typescript
|
|
1770
|
+
// config.ts - Production code
|
|
1771
|
+
import { resolveAsync, type Resolver } from 'node-env-resolver';
|
|
1772
|
+
import { processEnv } from 'node-env-resolver/resolvers';
|
|
1773
|
+
import { awsSecrets } from 'node-env-resolver-aws';
|
|
1774
|
+
import { string, number } from 'node-env-resolver/validators';
|
|
1775
|
+
|
|
1776
|
+
const schema = {
|
|
1777
|
+
DATABASE_URL: string(),
|
|
1778
|
+
PORT: number({ default: 3000 }),
|
|
1779
|
+
};
|
|
1780
|
+
|
|
1781
|
+
// Accept resolvers as parameter with sensible defaults
|
|
1782
|
+
export async function getConfig(resolvers: Resolver[] = [processEnv(), awsSecrets({ secretId: 'my-app' })]) {
|
|
1783
|
+
return resolveAsync({
|
|
1784
|
+
resolvers: resolvers.map(r => [r, schema])
|
|
1785
|
+
});
|
|
1786
|
+
}
|
|
1787
|
+
```
|
|
1788
|
+
|
|
1789
|
+
```typescript
|
|
1790
|
+
// config.test.ts - Test code
|
|
1791
|
+
import { getConfig } from './config';
|
|
1792
|
+
|
|
1793
|
+
describe('getConfig', () => {
|
|
1794
|
+
it('should resolve environment variables', async () => {
|
|
1795
|
+
// Create a simple inline mock resolver - no jest.mock() needed!
|
|
1796
|
+
const mockResolver = {
|
|
1797
|
+
name: 'test-env',
|
|
1798
|
+
load: async () => ({
|
|
1799
|
+
DATABASE_URL: 'postgres://test:5432/testdb',
|
|
1800
|
+
PORT: '8080',
|
|
1801
|
+
}),
|
|
1802
|
+
loadSync: () => ({
|
|
1803
|
+
DATABASE_URL: 'postgres://test:5432/testdb',
|
|
1804
|
+
PORT: '8080',
|
|
1805
|
+
}),
|
|
1806
|
+
};
|
|
1807
|
+
|
|
1808
|
+
const config = await getConfig([mockResolver]);
|
|
1809
|
+
|
|
1810
|
+
expect(config.DATABASE_URL).toBe('postgres://test:5432/testdb');
|
|
1811
|
+
expect(config.PORT).toBe(8080);
|
|
1812
|
+
});
|
|
1813
|
+
|
|
1814
|
+
it('should use default PORT when not provided', async () => {
|
|
1815
|
+
const mockResolver = {
|
|
1816
|
+
name: 'test-env',
|
|
1817
|
+
load: async () => ({ DATABASE_URL: 'postgres://localhost/db' }),
|
|
1818
|
+
loadSync: () => ({ DATABASE_URL: 'postgres://localhost/db' }),
|
|
1819
|
+
};
|
|
1820
|
+
|
|
1821
|
+
const config = await getConfig([mockResolver]);
|
|
1822
|
+
|
|
1823
|
+
expect(config.PORT).toBe(3000); // default value
|
|
1824
|
+
});
|
|
1825
|
+
});
|
|
1826
|
+
```
|
|
1827
|
+
|
|
1828
|
+
### Creating Mock Resolvers
|
|
1829
|
+
|
|
1830
|
+
A resolver is just an object with `name` and `load`/`loadSync` methods:
|
|
1831
|
+
|
|
1832
|
+
```typescript
|
|
1833
|
+
// Minimal async-only resolver
|
|
1834
|
+
const asyncMock = {
|
|
1835
|
+
name: 'async-mock',
|
|
1836
|
+
load: async () => ({ KEY: 'value' }),
|
|
1837
|
+
};
|
|
1838
|
+
|
|
1839
|
+
// Sync-compatible resolver (works with both resolve() and resolveAsync())
|
|
1840
|
+
const syncMock = {
|
|
1841
|
+
name: 'sync-mock',
|
|
1842
|
+
load: async () => ({ KEY: 'value' }),
|
|
1843
|
+
loadSync: () => ({ KEY: 'value' }),
|
|
1844
|
+
};
|
|
1845
|
+
|
|
1846
|
+
// Dynamic mock that can be configured per-test
|
|
1847
|
+
const createMock = (env: Record<string, string>) => ({
|
|
1848
|
+
name: 'configurable-mock',
|
|
1849
|
+
load: async () => env,
|
|
1850
|
+
loadSync: () => env,
|
|
1851
|
+
});
|
|
1852
|
+
|
|
1853
|
+
// Usage
|
|
1854
|
+
const config = await resolveAsync({
|
|
1855
|
+
resolvers: [[createMock({ API_KEY: 'test-key' }), { API_KEY: string() }]]
|
|
1856
|
+
});
|
|
1857
|
+
```
|
|
1858
|
+
|
|
1859
|
+
### Why Avoid Module Mocking
|
|
1860
|
+
|
|
1861
|
+
Module-level mocking (`jest.mock()`) creates tight coupling between tests and implementation:
|
|
1862
|
+
|
|
1863
|
+
```typescript
|
|
1864
|
+
// ❌ Avoid: Requires mocking internal imports
|
|
1865
|
+
jest.mock('node-env-resolver/resolvers', () => ({
|
|
1866
|
+
processEnv: jest.fn(() => ({ load: jest.fn(), name: 'processEnv' })),
|
|
1867
|
+
}));
|
|
1868
|
+
|
|
1869
|
+
// ✅ Better: Use dependency injection
|
|
1870
|
+
const config = await getConfig([mockResolver]);
|
|
1871
|
+
```
|
|
1872
|
+
|
|
1873
|
+
Benefits of dependency injection:
|
|
1874
|
+
- Tests are simpler and more readable
|
|
1875
|
+
- No need to understand internal module structure
|
|
1876
|
+
- Refactoring production code doesn't break tests
|
|
1877
|
+
- Works with any test framework (Jest, Vitest, Mocha, etc.)
|
|
1691
1878
|
|
|
1692
1879
|
## Error messages
|
|
1693
1880
|
|
package/dist/audit.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkO7NR4K6A_cjs=require('./chunk-O7NR4K6A.cjs');require('./chunk-D6WM53FN.cjs');Object.defineProperty(exports,"attachAuditSession",{enumerable:true,get:function(){return chunkO7NR4K6A_cjs.a}});Object.defineProperty(exports,"clearAuditLog",{enumerable:true,get:function(){return chunkO7NR4K6A_cjs.d}});Object.defineProperty(exports,"getAuditLog",{enumerable:true,get:function(){return chunkO7NR4K6A_cjs.c}});Object.defineProperty(exports,"logAuditEvent",{enumerable:true,get:function(){return chunkO7NR4K6A_cjs.b}});
|
package/dist/audit.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{a as attachAuditSession,d as clearAuditLog,c as getAuditLog,b as logAuditEvent}from'./chunk-6EWR3WHU.js';import'./chunk-I7AUKTXE.js';
|
package/dist/builder.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkZ3TI2YXP_cjs=require('./chunk-Z3TI2YXP.cjs'),chunkY2QEFWEY_cjs=require('./chunk-Y2QEFWEY.cjs');require('./chunk-O7NR4K6A.cjs');var chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');require('./chunk-D6WM53FN.cjs');var i=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolve(){let e=chunkY2QEFWEY_cjs.a(this.localSchema);for(let l of this.layers){let m=chunkY2QEFWEY_cjs.a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a=this.options.extend||[],c=[...s,...r,...a],u=this.options.policies??{};return chunkY2QEFWEY_cjs.c(e,c,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(chunkZ3TI2YXP_cjs.a({expand:true})),s.push(chunk4QOKRJ3F_cjs.a()),s}},n=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolveSync(){let e=chunkY2QEFWEY_cjs.a(this.localSchema);for(let l of this.layers){let m=chunkY2QEFWEY_cjs.a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a=this.options.extend||[],c=[...s,...r,...a],u=this.options.policies??{};return chunkY2QEFWEY_cjs.c(e,c,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(chunkZ3TI2YXP_cjs.a({expand:true})),s.push(chunk4QOKRJ3F_cjs.a()),s}};function y(t,e){return new i(t,e)}function b(t,e){return new n(t,e)}var d=class{builder;simpleResolve=null;constructor(e,s={}){this.builder=new i(e,s);}from(e,s){return this.builder.from(e,s),this}async compose(){return this.builder.resolve()}then(e,s){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.then(e,s)}catch(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.catch(e)}finally(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.finally(e)}},S=class{builder;_resolved=null;_hasComposition=false;constructor(e,s={}){Object.defineProperty(this,"builder",{value:new n(e,s),enumerable:false,writable:true}),Object.defineProperty(this,"_hasComposition",{value:false,enumerable:false,writable:true});let r=this.builder.resolveSync();Object.defineProperty(this,"_resolved",{value:r,enumerable:false,writable:true}),Object.assign(this,r);}from(e,s){return Object.defineProperty(this,"_hasComposition",{value:true,enumerable:false,writable:true}),this.builder.from(e,s),this}compose(){return this._hasComposition&&(this._resolved=this.builder.resolveSync(),Object.assign(this,this._resolved)),this._resolved}valueOf(){return this._resolved}toJSON(){return this._resolved}};exports.EnvBuilder=i;exports.EnvBuilderSync=n;exports.ResolvableBuilder=d;exports.ResolvableBuilderSync=S;exports.env=y;exports.envSync=b;
|
package/dist/builder.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-
|
|
1
|
+
import {a as a$1}from'./chunk-27CQXH2M.js';import {a,c}from'./chunk-5XUR34FH.js';import'./chunk-6EWR3WHU.js';import {a as a$2}from'./chunk-WKIPEKF6.js';import'./chunk-I7AUKTXE.js';var i=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolve(){let e=a(this.localSchema);for(let l of this.layers){let m=a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a$1=this.options.extend||[],c$1=[...s,...r,...a$1],u=this.options.policies??{};return c(e,c$1,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(a$1({expand:true})),s.push(a$2()),s}},n=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolveSync(){let e=a(this.localSchema);for(let l of this.layers){let m=a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a$1=this.options.extend||[],c$1=[...s,...r,...a$1],u=this.options.policies??{};return c(e,c$1,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(a$1({expand:true})),s.push(a$2()),s}};function y(t,e){return new i(t,e)}function b(t,e){return new n(t,e)}var d=class{builder;simpleResolve=null;constructor(e,s={}){this.builder=new i(e,s);}from(e,s){return this.builder.from(e,s),this}async compose(){return this.builder.resolve()}then(e,s){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.then(e,s)}catch(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.catch(e)}finally(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.finally(e)}},S=class{builder;_resolved=null;_hasComposition=false;constructor(e,s={}){Object.defineProperty(this,"builder",{value:new n(e,s),enumerable:false,writable:true}),Object.defineProperty(this,"_hasComposition",{value:false,enumerable:false,writable:true});let r=this.builder.resolveSync();Object.defineProperty(this,"_resolved",{value:r,enumerable:false,writable:true}),Object.assign(this,r);}from(e,s){return Object.defineProperty(this,"_hasComposition",{value:true,enumerable:false,writable:true}),this.builder.from(e,s),this}compose(){return this._hasComposition&&(this._resolved=this.builder.resolveSync(),Object.assign(this,this._resolved)),this._resolved}valueOf(){return this._resolved}toJSON(){return this._resolved}};export{i as EnvBuilder,n as EnvBuilderSync,d as ResolvableBuilder,S as ResolvableBuilderSync,y as env,b as envSync};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {a}from'./chunk-
|
|
1
|
+
import {a}from'./chunk-I7AUKTXE.js';import {existsSync,readFileSync}from'fs';import {resolve,join}from'path';var h=l=>{let a={},e=l.split(`
|
|
2
2
|
`);for(let t=0;t<e.length;t++){let i=e[t]?.trim()??"";if(!i||i[0]==="#")continue;let o=i.indexOf("=");if(o<=0)continue;let n=i.slice(0,o).trim();if(!/^[A-Z_][A-Z0-9_]*$/i.test(n))continue;let r=i.slice(o+1).trim();if(r.length>=2){let s=r[0];(s==='"'||s==="'")&&r[r.length-1]===s&&(r=r.slice(1,-1),s==='"'&&(r=r.replace(/\\n/g,`
|
|
3
3
|
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\\\/g,"\\").replace(/\\"/g,'"').replace(/\\'/g,"'")));}else {let s=r.indexOf("#");s>=0&&(r=r.slice(0,s).trim());}a[n]=r;}return a};function O(l){let a=typeof l=="string"?{path:l,expand:false}:{path:l?.path??".env",expand:l?.expand??false};return {name:a.expand?`dotenv-expand(${a.path})`:`dotenv(${a.path})`,async load(){if(!a.expand){let n=resolve(process.cwd(),a.path);return existsSync(n)?h(readFileSync(n,"utf8")):{}}let e=a.path,t=process.env.NODE_ENV||"development",i=[`${e}.defaults`,e,`${e}.local`,`${e}.${t}`,`${e}.${t}.local`],o={};for(let n of i){let r=resolve(process.cwd(),n);if(existsSync(r))try{o={...o,...h(readFileSync(r,"utf8"))};}catch{}}return o},loadSync(){if(!a.expand){let n=resolve(process.cwd(),a.path);return existsSync(n)?h(readFileSync(n,"utf8")):{}}let e=a.path,t=process.env.NODE_ENV||"development",i=[`${e}.defaults`,e,`${e}.local`,`${e}.${t}`,`${e}.${t}.local`],o={};for(let n of i){let r=resolve(process.cwd(),n);if(existsSync(r))try{o={...o,...h(readFileSync(r,"utf8"))};}catch{}}return o}}}function S(l){let a={path:l?.path??"package.json",fields:l?.fields??["version","name","config"]};return {name:"package.json",async load(){let e=resolve(process.cwd(),a.path);if(!existsSync(e))return {};try{let t=readFileSync(e,"utf8"),i=JSON.parse(t),o={};for(let n of a.fields){let r=i[n];if(r!==void 0)if(n==="config"&&typeof r=="object"){let s=(c,d)=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=`${d}_${f.toUpperCase()}`;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):o[m]=String(p);}};s(r,"CONFIG");}else o[n.toUpperCase()]=String(r);}return o}catch(t){throw new Error(`Failed to read package.json: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=resolve(process.cwd(),a.path);if(!existsSync(e))return {};try{let t=readFileSync(e,"utf8"),i=JSON.parse(t),o={};for(let n of a.fields){let r=i[n];if(r!==void 0)if(n==="config"&&typeof r=="object"){let s=(c,d)=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=`${d}_${f.toUpperCase()}`;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):o[m]=String(p);}};s(r,"CONFIG");}else o[n.toUpperCase()]=String(r);}return o}catch(t){throw new Error(`Failed to read package.json: ${t instanceof Error?t.message:String(t)}`)}}}}function k(l,a){return {name:`http(${l})`,async load(){try{let e=new AbortController,t=a?.timeout??5e3,i=setTimeout(()=>e.abort(),t),o=await fetch(l,{...a,signal:e.signal});if(clearTimeout(i),!o.ok)throw new Error(`HTTP ${o.status}: ${o.statusText}`);let n=await o.json(),r={},s=(c,d="")=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=d?`${d}_${f}`:f;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):r[m.toUpperCase()]=String(p);}};return s(n),r}catch(e){throw e.name==="AbortError"?new Error(`HTTP request timeout after ${a?.timeout??5e3}ms`):new Error(`Failed to fetch config from ${l}: ${e instanceof Error?e.message:String(e)}`)}}}}function R(l="config.json"){return {name:`json(${l})`,async load(){let a=resolve(process.cwd(),l);if(!existsSync(a))return {};try{let e=readFileSync(a,"utf8"),t=JSON.parse(e),i={},o=(n,r="")=>{if(n&&typeof n=="object"&&!Array.isArray(n))for(let[s,c]of Object.entries(n)){let d=r?`${r}_${s}`:s;c&&typeof c=="object"&&!Array.isArray(c)?o(c,d):i[d.toUpperCase()]=String(c);}};return o(t),i}catch(e){throw new Error(`Failed to parse JSON file ${l}: ${e instanceof Error?e.message:String(e)}`)}},loadSync(){let a=resolve(process.cwd(),l);if(!existsSync(a))return {};try{let e=readFileSync(a,"utf8"),t=JSON.parse(e),i={},o=(n,r="")=>{if(n&&typeof n=="object"&&!Array.isArray(n))for(let[s,c]of Object.entries(n)){let d=r?`${r}_${s}`:s;c&&typeof c=="object"&&!Array.isArray(c)?o(c,d):i[d.toUpperCase()]=String(c);}};return o(t),i}catch(e){throw new Error(`Failed to parse JSON file ${l}: ${e instanceof Error?e.message:String(e)}`)}}}}function _(l="/run/secrets"){return {name:`secrets(${l})`,async load(){let{readdirSync:a,statSync:e}=await import('fs'),t=resolve(process.cwd(),l);if(!existsSync(t))return {};try{let i=a(t),o={};for(let n of i){let r=join(t,n);if(!e(r).isFile())continue;let c=n.toUpperCase().replace(/[.-]/g,"_"),d=readFileSync(r,"utf8").trim();o[c]=d;}return o}catch(i){throw new Error(`Failed to read secrets from ${l}: ${i instanceof Error?i.message:String(i)}`)}},loadSync(){let{readdirSync:a$1,statSync:e}=a("fs"),t=resolve(process.cwd(),l);if(!existsSync(t))return {};try{let i=a$1(t),o={};for(let n of i){let r=join(t,n);if(!e(r).isFile())continue;let c=n.toUpperCase().replace(/[.-]/g,"_"),d=readFileSync(r,"utf8").trim();o[c]=d;}return o}catch(i){throw new Error(`Failed to read secrets from ${l}: ${i instanceof Error?i.message:String(i)}`)}}}}function U(l){let a$1=typeof l=="string"?{path:l}:{path:l?.path??"config.yaml"};return {name:`yaml(${a$1.path})`,async load(){let e=join(process.cwd(),a$1.path);if(!existsSync(e))return {};try{let{load:t}=await import('js-yaml'),i=readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`YAML resolver requires 'js-yaml' package. Install it with:
|
|
4
4
|
npm install js-yaml
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {a,b}from'./chunk-6EWR3WHU.js';import {join,resolve}from'path';import {readFileSync}from'fs';function V(l,c){try{let r=resolve(process.cwd(),l);return {valid:!0,value:readFileSync(r,"utf8").trim()}}catch(r){return {valid:false,error:`Failed to read file${c?` for ${c}`:""}: ${r instanceof Error?r.message:String(r)}`}}}var h=b,E=b,I=a;function Z(l){let c={};for(let[r,o]of Object.entries(l))if(typeof o=="function"){let i=o,t=i.__isFileValidator===true;c[r]={type:t?"file":"custom",validator:o,...i.default!==void 0&&{default:i.default},...i.optional!==void 0&&{optional:i.optional},...i.secretsDir!==void 0&&{secretsDir:i.secretsDir}};}else if(typeof o=="string")c[r]={type:"string",default:o,validator:i=>{if(i===""&&!c[r].allowEmpty)throw new Error("String cannot be empty");return i}};else if(typeof o=="number")c[r]={type:"number",default:o,validator:i=>{let t=Number(i);if(isNaN(t))throw new Error(`Invalid number: "${i}"`);return t}};else if(typeof o=="boolean")c[r]={type:"boolean",default:o,validator:i=>{let t=i.toLowerCase();if(["true","1","yes","on"].includes(t))return true;if(["false","0","no","off",""].includes(t))return false;throw new Error(`Invalid boolean: "${i}"`)}};else if(Array.isArray(o)){let i=o.map(String),t=o.__optional===true;c[r]={type:"string",enum:i,optional:t,validator:(m,n)=>{if(!i.includes(m)){let s=n||r;throw new Error(`${s} must be one of: ${i.join(", ")}`)}return m}};}else c[r]=o;return c}function N(l,c){return l.replace(/\$\{([^}]+)\}/g,(r,o)=>c[o]||r)}async function F(l,c,r,o="last",i){let t={},m={};if(o==="last"){let n=await Promise.allSettled(l.map(async s=>({resolver:s,env:s.load?await s.load():{}})));for(let s of n){if(s.status==="rejected"){let u=s.reason;if(h({type:"resolver_error",timestamp:Date.now(),source:"unknown",error:u instanceof Error?u.message:String(u)}),r)throw new Error(`Resolver failed: ${u instanceof Error?u.message:u}`);continue}let{resolver:f,env:d}=s.value;for(let[u,y]of Object.entries(d))y!==void 0&&(t[u]=y,m[u]={source:f.name||"unknown",timestamp:Date.now(),...f.metadata?.cached!==void 0&&{cached:!!f.metadata.cached}});}}else for(let n of l)try{let s=n.load?await n.load():{};for(let[f,d]of Object.entries(s))if(d!==void 0){if(t[f]!==void 0)continue;t[f]=d,m[f]={source:n.name||"unknown",timestamp:Date.now(),...n.metadata?.cached!==void 0&&{cached:!!n.metadata.cached}};}if(i&&i.size>0&&Array.from(i).every(d=>t[d]!==void 0))break}catch(s){if(h({type:"resolver_error",timestamp:Date.now(),source:n.name,error:s instanceof Error?s.message:String(s)}),r)throw new Error(`Resolver ${n.name} failed: ${s instanceof Error?s.message:s}`)}if(c)for(let[n,s]of Object.entries(t))t[n]=N(s,t);return {mergedEnv:t,provenance:m}}function B(l,c,r,o="last",i){let t={},m={};for(let n of l)try{if(!n.loadSync){if(r)throw new Error(`Resolver ${n.name} has no loadSync() method`);continue}let s=n.loadSync();for(let[f,d]of Object.entries(s))if(d!==void 0){if(o==="first"&&t[f]!==void 0)continue;t[f]=d,m[f]={source:n.name||"unknown",timestamp:Date.now(),...n.metadata?.cached!==void 0&&{cached:!!n.metadata.cached}};}if(o==="first"&&i&&i.size>0&&Array.from(i).every(d=>t[d]!==void 0))break}catch(s){if(E({type:"resolver_error",timestamp:Date.now(),source:n.name,error:s instanceof Error?s.message:String(s)}),r)throw new Error(`Resolver ${n.name} failed: ${s instanceof Error?s.message:s}`)}if(c)for(let[n,s]of Object.entries(t))t[n]=N(s,t);return {mergedEnv:t,provenance:m}}function C(l,c,r,o){if(!o)return null;if((process.env.NODE_ENV||"").toLowerCase()==="production"&&r&&r.source.startsWith("dotenv(")){let t=o.allowDotenvInProduction;return t===true?null:Array.isArray(t)?t.includes(l)?null:`${l} cannot be sourced from .env files in production. Use process.env or cloud resolvers. To allow: policies.allowDotenvInProduction: ['${l}'] or set to true for all.`:`${l} cannot be sourced from .env files in production (secure default). Production platforms (Vercel, AWS, etc.) use process.env. To allow .env in production: policies.allowDotenvInProduction: true`}if(o.enforceAllowedSources&&o.enforceAllowedSources[l]&&r){let t=o.enforceAllowedSources[l];if(!t.includes(r.source))return `${l} must be sourced from one of: ${t.join(", ")} (actual: ${r.source})`}return null}function L(l){let c=[],r=/^[A-Za-z_][A-Za-z0-9_]*$/;for(let o of Object.keys(l))r.test(o)||c.push(`Invalid environment variable name: "${o}". Environment variable names must contain only letters, numbers, and underscores, and cannot start with a number.`);return c}function T(l,c){let r={};for(let[o,i]of Object.entries(l)){if(!o.includes(c)){r[o]=i;continue}let t=o.split(c),m=r;for(let s=0;s<t.length-1;s++){let f=t[s].toLowerCase();f in m||(m[f]={}),m=m[f];}let n=t[t.length-1].toLowerCase();m[n]=i;}return r}async function U(l,c,r){let o=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:i=false,strict:t=true,policies:m,enableAudit:n=o,priority:s="last",secretsDir:f}=r,d={},u;n&&(u=I(d));let y=L(l);if(y.length>0)throw n&&h({type:"validation_failure",timestamp:Date.now(),error:`Invalid environment variable names: ${y.join(", ")}`,sessionId:u}),new Error(`Environment validation failed:
|
|
2
|
+
${y.map(e=>` - ${e}`).join(`
|
|
3
|
+
`)}`);let R=new Set(Object.keys(l)),{mergedEnv:S,provenance:w}=await F(c,i,t,s,R),g=[];for(let[e,k]of Object.entries(l)){let p=k,D=S[e],b=C(e,p,w[e],m);if(b){g.push(b),n&&h({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:b,sessionId:u});continue}try{let a;if(D===void 0){let v=p.secretsDir??f;if(p.type==="file"&&v){let _=e.toLowerCase().replace(/_/g,"-"),j=join(v,_),$=V(j,e);$.valid?(a={success:!0,value:$.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):a={success:!1,error:$.error??`Failed to read secret for ${e}`};}else p.default!==void 0?a={success:!0,value:p.default}:p.optional?a={success:!0,value:void 0}:a={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{a={success:!0,value:p.validator(D,e)};}catch(v){a={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else a={success:!0,value:D};a.success?(d[e]=a.value,n&&h({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(a.error),n&&h({type:"validation_failure",timestamp:Date.now(),key:e,error:a.error,sessionId:u}));}catch(a){let v=a instanceof Error?a.message:String(a);g.push(`${e}: ${v}`),n&&h({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw n&&h({type:"validation_failure",timestamp:Date.now(),error:`${g.length} validation error(s)`,metadata:{errorCount:g.length},sessionId:u}),new Error(`Environment validation failed:
|
|
4
|
+
${g.map(e=>` - ${e}`).join(`
|
|
5
|
+
`)}`);return n&&h({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(l).length},sessionId:u}),r.nestedDelimiter?T(d,r.nestedDelimiter):d}function G(l,c,r){let o=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:i=false,strict:t=true,policies:m,enableAudit:n=o,priority:s="last",secretsDir:f}=r,d={},u;n&&(u=I(d));let y=L(l);if(y.length>0)throw n&&E({type:"validation_failure",timestamp:Date.now(),error:`Invalid environment variable names: ${y.join(", ")}`,sessionId:u}),new Error(`Environment validation failed:
|
|
6
|
+
${y.map(e=>` - ${e}`).join(`
|
|
7
|
+
`)}`);let R=new Set(Object.keys(l)),{mergedEnv:S,provenance:w}=B(c,i,t,s,R),g=[];for(let[e,k]of Object.entries(l)){let p=k,D=S[e],b=C(e,p,w[e],m);if(b){g.push(b),n&&E({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:b,sessionId:u});continue}try{let a;if(D===void 0){let v=p.secretsDir??f;if(p.type==="file"&&v){let _=e.toLowerCase().replace(/_/g,"-"),j=join(v,_),$=V(j,e);$.valid?(a={success:!0,value:$.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):a={success:!1,error:$.error??`Failed to read secret for ${e}`};}else p.default!==void 0?a={success:!0,value:p.default}:p.optional?a={success:!0,value:void 0}:a={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{a={success:!0,value:p.validator(D,e)};}catch(v){a={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else a={success:!0,value:D};a.success?(d[e]=a.value,n&&E({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(a.error),n&&E({type:"validation_failure",timestamp:Date.now(),key:e,error:a.error,sessionId:u}));}catch(a){let v=a instanceof Error?a.message:String(a);g.push(`${e}: ${v}`),n&&E({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw n&&E({type:"validation_failure",timestamp:Date.now(),error:`${g.length} validation error(s)`,metadata:{errorCount:g.length},sessionId:u}),new Error(`Environment validation failed:
|
|
8
|
+
${g.map(e=>` - ${e}`).join(`
|
|
9
|
+
`)}`);return n&&E({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(l).length},sessionId:u}),r.nestedDelimiter?T(d,r.nestedDelimiter):d}export{Z as a,U as b,G as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=[];var o=new WeakMap;function r(t){let n=Date.now().toString(36)+Math.random().toString(36).substring(2,9);return o.set(t,n),n}function s(t){e.push(t),e.length>1e3&&e.shift();}function d(t){if(!t)return [...e];let n=o.get(t);return n?e.filter(i=>i.sessionId===n):[]}function u(){e.length=0;}export{r as a,s as b,d as c,u as d};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkY2QEFWEY_cjs=require('./chunk-Y2QEFWEY.cjs'),chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');function v(){return [chunk4QOKRJ3F_cjs.a()]}function h(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&("resolvers"in e||"schema"in e||"options"in e)}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!("resolvers"in e)&&!("schema"in e)&&!("options"in e)}function w(e,t){let o,l,i;if(h(e)){let s=e;if(s.schema)o=s.schema;else if(s.resolvers&&s.resolvers.length>0){o={};for(let[,n]of s.resolvers)Object.assign(o,n);}else throw new Error('resolve() config object must have either a "schema" property or "resolvers" array');l=s.resolvers?s.resolvers.map(([n])=>n):v(),i=s.options;}else if(S(e))o=e,l=v(),i=t;else throw new Error('resolve() expects either a schema object or a config object with "schema" or "resolvers" property');for(let[s,n]of Object.entries(o))if(n&&typeof n=="object"&&"~standard"in n)throw new Error(`\u274C resolve() cannot be used with async validators.
|
|
2
2
|
Variable '${s}' uses a Standard Schema validator (Zod, Valibot, etc.)
|
|
3
3
|
\u{1F4A1} Use resolveAsync() instead, or use shorthand syntax for sync validation.`);for(let s of l)if(!s.loadSync)throw new Error(`\u274C Resolver '${s.name}' does not support synchronous loading.
|
|
4
4
|
All resolvers passed to resolve() must have a loadSync() method.
|
|
5
|
-
\u{1F4A1} Use resolveAsync() for async resolvers, or use a sync-compatible resolver.`);let a=(process.env.NODE_ENV||"").toLowerCase()==="production",r=i?.policies??{},p={interpolate:true,strict:true,enableAudit:a,policies:r,...i},c=
|
|
5
|
+
\u{1F4A1} Use resolveAsync() for async resolvers, or use a sync-compatible resolver.`);let a=(process.env.NODE_ENV||"").toLowerCase()==="production",r=i?.policies??{},p={interpolate:true,strict:true,enableAudit:a,policies:r,...i},c=chunkY2QEFWEY_cjs.a(o);return chunkY2QEFWEY_cjs.c(c,l,p)}async function P(e){let t;if(e.schema)t=e.schema;else if(e.resolvers&&e.resolvers.length>0){t={};for(let[,c]of e.resolvers)Object.assign(t,c);}else throw new Error('resolveAsync() config object must have either a "schema" property or "resolvers" array');let o=e.resolvers?e.resolvers.map(([c])=>c):v(),l=(process.env.NODE_ENV||"").toLowerCase()==="production",i=e.options?.policies??{},a={interpolate:true,strict:true,enableAudit:l,policies:i,...e.options},r=chunkY2QEFWEY_cjs.a(t);return await chunkY2QEFWEY_cjs.b(r,o,a)}function g(e,t){let o,l,i;try{if(h(e)){let s=e;if(s.schema)o=s.schema;else if(s.resolvers&&s.resolvers.length>0){o={};for(let[,n]of s.resolvers)Object.assign(o,n);}else return {success:!1,error:'safeResolve() config object must have either a "schema" property or "resolvers" array'};l=s.resolvers?s.resolvers.map(([n])=>n):v(),i=s.options;}else if(S(e))o=e,l=v(),i=t;else return {success:!1,error:'safeResolve() expects either a schema object or a config object with "schema" or "resolvers" property'};for(let[s,n]of Object.entries(o))if(n&&typeof n=="object"&&"~standard"in n)return {success:!1,error:`\u274C safeResolve() cannot be used with async validators.
|
|
6
6
|
Variable '${s}' uses a Standard Schema validator (Zod, Valibot, etc.)
|
|
7
7
|
\u{1F4A1} Use safeResolveAsync() instead, or use shorthand syntax for sync validation.`};for(let s of l)if(!s.loadSync)return {success:!1,error:`\u274C Resolver '${s.name}' does not support synchronous loading.
|
|
8
8
|
All resolvers passed to safeResolve() must have a loadSync() method.
|
|
9
|
-
\u{1F4A1} Use safeResolveAsync() for async resolvers.`};let a=(process.env.NODE_ENV||"").toLowerCase()==="production",r=i?.policies??{},p={interpolate:!0,strict:!0,enableAudit:a,policies:r,...i},c=
|
|
9
|
+
\u{1F4A1} Use safeResolveAsync() for async resolvers.`};let a=(process.env.NODE_ENV||"").toLowerCase()==="production",r=i?.policies??{},p={interpolate:!0,strict:!0,enableAudit:a,policies:r,...i},c=chunkY2QEFWEY_cjs.a(o);return {success:!0,data:chunkY2QEFWEY_cjs.c(c,l,p)}}catch(a){return {success:false,error:a instanceof Error?a.message:String(a)}}}async function k(e){let t;if(e.schema)t=e.schema;else if(e.resolvers&&e.resolvers.length>0){t={};for(let[,r]of e.resolvers)Object.assign(t,r);}else return {success:false,error:'safeResolveAsync() config object must have either a "schema" property or "resolvers" array'};let o=e.resolvers?e.resolvers.map(([r])=>r):v(),l=(process.env.NODE_ENV||"").toLowerCase()==="production",i=e.options?.policies??{},a={interpolate:true,strict:true,enableAudit:l,policies:i,...e.options};try{let r=chunkY2QEFWEY_cjs.a(t);return {success:!0,data:await chunkY2QEFWEY_cjs.b(r,o,a)}}catch(r){return {success:false,error:r instanceof Error?r.message:String(r)}}}exports.a=w;exports.b=P;exports.c=g;exports.d=k;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {a,c,b}from'./chunk-
|
|
1
|
+
import {a,c,b}from'./chunk-5XUR34FH.js';import {a as a$1}from'./chunk-WKIPEKF6.js';function v(){return [a$1()]}function h(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&("resolvers"in e||"schema"in e||"options"in e)}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!("resolvers"in e)&&!("schema"in e)&&!("options"in e)}function w(e,t){let o,l,i;if(h(e)){let s=e;if(s.schema)o=s.schema;else if(s.resolvers&&s.resolvers.length>0){o={};for(let[,n]of s.resolvers)Object.assign(o,n);}else throw new Error('resolve() config object must have either a "schema" property or "resolvers" array');l=s.resolvers?s.resolvers.map(([n])=>n):v(),i=s.options;}else if(S(e))o=e,l=v(),i=t;else throw new Error('resolve() expects either a schema object or a config object with "schema" or "resolvers" property');for(let[s,n]of Object.entries(o))if(n&&typeof n=="object"&&"~standard"in n)throw new Error(`\u274C resolve() cannot be used with async validators.
|
|
2
2
|
Variable '${s}' uses a Standard Schema validator (Zod, Valibot, etc.)
|
|
3
3
|
\u{1F4A1} Use resolveAsync() instead, or use shorthand syntax for sync validation.`);for(let s of l)if(!s.loadSync)throw new Error(`\u274C Resolver '${s.name}' does not support synchronous loading.
|
|
4
4
|
All resolvers passed to resolve() must have a loadSync() method.
|
|
5
|
-
\u{1F4A1} Use resolveAsync() for async resolvers, or use a sync-compatible resolver.`);let a$1=(process.env.NODE_ENV||"").toLowerCase()==="production",r=i?.policies??{},p={interpolate:true,strict:true,enableAudit:a$1,policies:r,...i},c$1=a(o);return c(c$1,l,p)}async function
|
|
5
|
+
\u{1F4A1} Use resolveAsync() for async resolvers, or use a sync-compatible resolver.`);let a$1=(process.env.NODE_ENV||"").toLowerCase()==="production",r=i?.policies??{},p={interpolate:true,strict:true,enableAudit:a$1,policies:r,...i},c$1=a(o);return c(c$1,l,p)}async function P(e){let t;if(e.schema)t=e.schema;else if(e.resolvers&&e.resolvers.length>0){t={};for(let[,c]of e.resolvers)Object.assign(t,c);}else throw new Error('resolveAsync() config object must have either a "schema" property or "resolvers" array');let o=e.resolvers?e.resolvers.map(([c])=>c):v(),l=(process.env.NODE_ENV||"").toLowerCase()==="production",i=e.options?.policies??{},a$1={interpolate:true,strict:true,enableAudit:l,policies:i,...e.options},r=a(t);return await b(r,o,a$1)}function g(e,t){let o,l,i;try{if(h(e)){let s=e;if(s.schema)o=s.schema;else if(s.resolvers&&s.resolvers.length>0){o={};for(let[,n]of s.resolvers)Object.assign(o,n);}else return {success:!1,error:'safeResolve() config object must have either a "schema" property or "resolvers" array'};l=s.resolvers?s.resolvers.map(([n])=>n):v(),i=s.options;}else if(S(e))o=e,l=v(),i=t;else return {success:!1,error:'safeResolve() expects either a schema object or a config object with "schema" or "resolvers" property'};for(let[s,n]of Object.entries(o))if(n&&typeof n=="object"&&"~standard"in n)return {success:!1,error:`\u274C safeResolve() cannot be used with async validators.
|
|
6
6
|
Variable '${s}' uses a Standard Schema validator (Zod, Valibot, etc.)
|
|
7
7
|
\u{1F4A1} Use safeResolveAsync() instead, or use shorthand syntax for sync validation.`};for(let s of l)if(!s.loadSync)return {success:!1,error:`\u274C Resolver '${s.name}' does not support synchronous loading.
|
|
8
8
|
All resolvers passed to safeResolve() must have a loadSync() method.
|
|
9
|
-
\u{1F4A1} Use safeResolveAsync() for async resolvers.`};let a$1=(process.env.NODE_ENV||"").toLowerCase()==="production",r=i?.policies??{},p={interpolate:!0,strict:!0,enableAudit:a$1,policies:r,...i},c$1=a(o);return {success:!0,data:c(c$1,l,p)}}catch(a){return {success:false,error:a instanceof Error?a.message:String(a)}}}async function
|
|
9
|
+
\u{1F4A1} Use safeResolveAsync() for async resolvers.`};let a$1=(process.env.NODE_ENV||"").toLowerCase()==="production",r=i?.policies??{},p={interpolate:!0,strict:!0,enableAudit:a$1,policies:r,...i},c$1=a(o);return {success:!0,data:c(c$1,l,p)}}catch(a){return {success:false,error:a instanceof Error?a.message:String(a)}}}async function k(e){let t;if(e.schema)t=e.schema;else if(e.resolvers&&e.resolvers.length>0){t={};for(let[,r]of e.resolvers)Object.assign(t,r);}else return {success:false,error:'safeResolveAsync() config object must have either a "schema" property or "resolvers" array'};let o=e.resolvers?e.resolvers.map(([r])=>r):v(),l=(process.env.NODE_ENV||"").toLowerCase()==="production",i=e.options?.policies??{},a$1={interpolate:true,strict:true,enableAudit:l,policies:i,...e.options};try{let r=a(t);return {success:!0,data:await b(r,o,a$1)}}catch(r){return {success:false,error:r instanceof Error?r.message:String(r)}}}export{w as a,P as b,g as c,k as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var d=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});exports.a=d;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var d=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});export{d as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var e=[];var o=new WeakMap;function r(t){let n=Date.now().toString(36)+Math.random().toString(36).substring(2,9);return o.set(t,n),n}function s(t){e.push(t),e.length>1e3&&e.shift();}function d(t){if(!t)return [...e];let n=o.get(t);return n?e.filter(i=>i.sessionId===n):[]}function u(){e.length=0;}exports.a=r;exports.b=s;exports.c=d;exports.d=u;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';var chunkO7NR4K6A_cjs=require('./chunk-O7NR4K6A.cjs'),path=require('path'),fs=require('fs');function V(l,c){try{let r=path.resolve(process.cwd(),l);return {valid:!0,value:fs.readFileSync(r,"utf8").trim()}}catch(r){return {valid:false,error:`Failed to read file${c?` for ${c}`:""}: ${r instanceof Error?r.message:String(r)}`}}}var h=chunkO7NR4K6A_cjs.b,E=chunkO7NR4K6A_cjs.b,I=chunkO7NR4K6A_cjs.a;function Z(l){let c={};for(let[r,o]of Object.entries(l))if(typeof o=="function"){let i=o,t=i.__isFileValidator===true;c[r]={type:t?"file":"custom",validator:o,...i.default!==void 0&&{default:i.default},...i.optional!==void 0&&{optional:i.optional},...i.secretsDir!==void 0&&{secretsDir:i.secretsDir}};}else if(typeof o=="string")c[r]={type:"string",default:o,validator:i=>{if(i===""&&!c[r].allowEmpty)throw new Error("String cannot be empty");return i}};else if(typeof o=="number")c[r]={type:"number",default:o,validator:i=>{let t=Number(i);if(isNaN(t))throw new Error(`Invalid number: "${i}"`);return t}};else if(typeof o=="boolean")c[r]={type:"boolean",default:o,validator:i=>{let t=i.toLowerCase();if(["true","1","yes","on"].includes(t))return true;if(["false","0","no","off",""].includes(t))return false;throw new Error(`Invalid boolean: "${i}"`)}};else if(Array.isArray(o)){let i=o.map(String),t=o.__optional===true;c[r]={type:"string",enum:i,optional:t,validator:(m,n)=>{if(!i.includes(m)){let s=n||r;throw new Error(`${s} must be one of: ${i.join(", ")}`)}return m}};}else c[r]=o;return c}function N(l,c){return l.replace(/\$\{([^}]+)\}/g,(r,o)=>c[o]||r)}async function F(l,c,r,o="last",i){let t={},m={};if(o==="last"){let n=await Promise.allSettled(l.map(async s=>({resolver:s,env:s.load?await s.load():{}})));for(let s of n){if(s.status==="rejected"){let u=s.reason;if(h({type:"resolver_error",timestamp:Date.now(),source:"unknown",error:u instanceof Error?u.message:String(u)}),r)throw new Error(`Resolver failed: ${u instanceof Error?u.message:u}`);continue}let{resolver:f,env:d}=s.value;for(let[u,y]of Object.entries(d))y!==void 0&&(t[u]=y,m[u]={source:f.name||"unknown",timestamp:Date.now(),...f.metadata?.cached!==void 0&&{cached:!!f.metadata.cached}});}}else for(let n of l)try{let s=n.load?await n.load():{};for(let[f,d]of Object.entries(s))if(d!==void 0){if(t[f]!==void 0)continue;t[f]=d,m[f]={source:n.name||"unknown",timestamp:Date.now(),...n.metadata?.cached!==void 0&&{cached:!!n.metadata.cached}};}if(i&&i.size>0&&Array.from(i).every(d=>t[d]!==void 0))break}catch(s){if(h({type:"resolver_error",timestamp:Date.now(),source:n.name,error:s instanceof Error?s.message:String(s)}),r)throw new Error(`Resolver ${n.name} failed: ${s instanceof Error?s.message:s}`)}if(c)for(let[n,s]of Object.entries(t))t[n]=N(s,t);return {mergedEnv:t,provenance:m}}function B(l,c,r,o="last",i){let t={},m={};for(let n of l)try{if(!n.loadSync){if(r)throw new Error(`Resolver ${n.name} has no loadSync() method`);continue}let s=n.loadSync();for(let[f,d]of Object.entries(s))if(d!==void 0){if(o==="first"&&t[f]!==void 0)continue;t[f]=d,m[f]={source:n.name||"unknown",timestamp:Date.now(),...n.metadata?.cached!==void 0&&{cached:!!n.metadata.cached}};}if(o==="first"&&i&&i.size>0&&Array.from(i).every(d=>t[d]!==void 0))break}catch(s){if(E({type:"resolver_error",timestamp:Date.now(),source:n.name,error:s instanceof Error?s.message:String(s)}),r)throw new Error(`Resolver ${n.name} failed: ${s instanceof Error?s.message:s}`)}if(c)for(let[n,s]of Object.entries(t))t[n]=N(s,t);return {mergedEnv:t,provenance:m}}function C(l,c,r,o){if(!o)return null;if((process.env.NODE_ENV||"").toLowerCase()==="production"&&r&&r.source.startsWith("dotenv(")){let t=o.allowDotenvInProduction;return t===true?null:Array.isArray(t)?t.includes(l)?null:`${l} cannot be sourced from .env files in production. Use process.env or cloud resolvers. To allow: policies.allowDotenvInProduction: ['${l}'] or set to true for all.`:`${l} cannot be sourced from .env files in production (secure default). Production platforms (Vercel, AWS, etc.) use process.env. To allow .env in production: policies.allowDotenvInProduction: true`}if(o.enforceAllowedSources&&o.enforceAllowedSources[l]&&r){let t=o.enforceAllowedSources[l];if(!t.includes(r.source))return `${l} must be sourced from one of: ${t.join(", ")} (actual: ${r.source})`}return null}function L(l){let c=[],r=/^[A-Za-z_][A-Za-z0-9_]*$/;for(let o of Object.keys(l))r.test(o)||c.push(`Invalid environment variable name: "${o}". Environment variable names must contain only letters, numbers, and underscores, and cannot start with a number.`);return c}function T(l,c){let r={};for(let[o,i]of Object.entries(l)){if(!o.includes(c)){r[o]=i;continue}let t=o.split(c),m=r;for(let s=0;s<t.length-1;s++){let f=t[s].toLowerCase();f in m||(m[f]={}),m=m[f];}let n=t[t.length-1].toLowerCase();m[n]=i;}return r}async function U(l,c,r){let o=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:i=false,strict:t=true,policies:m,enableAudit:n=o,priority:s="last",secretsDir:f}=r,d={},u;n&&(u=I(d));let y=L(l);if(y.length>0)throw n&&h({type:"validation_failure",timestamp:Date.now(),error:`Invalid environment variable names: ${y.join(", ")}`,sessionId:u}),new Error(`Environment validation failed:
|
|
2
|
+
${y.map(e=>` - ${e}`).join(`
|
|
3
|
+
`)}`);let R=new Set(Object.keys(l)),{mergedEnv:S,provenance:w}=await F(c,i,t,s,R),g=[];for(let[e,k]of Object.entries(l)){let p=k,D=S[e],b=C(e,p,w[e],m);if(b){g.push(b),n&&h({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:b,sessionId:u});continue}try{let a;if(D===void 0){let v=p.secretsDir??f;if(p.type==="file"&&v){let _=e.toLowerCase().replace(/_/g,"-"),j=path.join(v,_),$=V(j,e);$.valid?(a={success:!0,value:$.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):a={success:!1,error:$.error??`Failed to read secret for ${e}`};}else p.default!==void 0?a={success:!0,value:p.default}:p.optional?a={success:!0,value:void 0}:a={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{a={success:!0,value:p.validator(D,e)};}catch(v){a={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else a={success:!0,value:D};a.success?(d[e]=a.value,n&&h({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(a.error),n&&h({type:"validation_failure",timestamp:Date.now(),key:e,error:a.error,sessionId:u}));}catch(a){let v=a instanceof Error?a.message:String(a);g.push(`${e}: ${v}`),n&&h({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw n&&h({type:"validation_failure",timestamp:Date.now(),error:`${g.length} validation error(s)`,metadata:{errorCount:g.length},sessionId:u}),new Error(`Environment validation failed:
|
|
4
|
+
${g.map(e=>` - ${e}`).join(`
|
|
5
|
+
`)}`);return n&&h({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(l).length},sessionId:u}),r.nestedDelimiter?T(d,r.nestedDelimiter):d}function G(l,c,r){let o=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:i=false,strict:t=true,policies:m,enableAudit:n=o,priority:s="last",secretsDir:f}=r,d={},u;n&&(u=I(d));let y=L(l);if(y.length>0)throw n&&E({type:"validation_failure",timestamp:Date.now(),error:`Invalid environment variable names: ${y.join(", ")}`,sessionId:u}),new Error(`Environment validation failed:
|
|
6
|
+
${y.map(e=>` - ${e}`).join(`
|
|
7
|
+
`)}`);let R=new Set(Object.keys(l)),{mergedEnv:S,provenance:w}=B(c,i,t,s,R),g=[];for(let[e,k]of Object.entries(l)){let p=k,D=S[e],b=C(e,p,w[e],m);if(b){g.push(b),n&&E({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:b,sessionId:u});continue}try{let a;if(D===void 0){let v=p.secretsDir??f;if(p.type==="file"&&v){let _=e.toLowerCase().replace(/_/g,"-"),j=path.join(v,_),$=V(j,e);$.valid?(a={success:!0,value:$.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):a={success:!1,error:$.error??`Failed to read secret for ${e}`};}else p.default!==void 0?a={success:!0,value:p.default}:p.optional?a={success:!0,value:void 0}:a={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{a={success:!0,value:p.validator(D,e)};}catch(v){a={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else a={success:!0,value:D};a.success?(d[e]=a.value,n&&E({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(a.error),n&&E({type:"validation_failure",timestamp:Date.now(),key:e,error:a.error,sessionId:u}));}catch(a){let v=a instanceof Error?a.message:String(a);g.push(`${e}: ${v}`),n&&E({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw n&&E({type:"validation_failure",timestamp:Date.now(),error:`${g.length} validation error(s)`,metadata:{errorCount:g.length},sessionId:u}),new Error(`Environment validation failed:
|
|
8
|
+
${g.map(e=>` - ${e}`).join(`
|
|
9
|
+
`)}`);return n&&E({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(l).length},sessionId:u}),r.nestedDelimiter?T(d,r.nestedDelimiter):d}exports.a=Z;exports.b=U;exports.c=G;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkD6WM53FN_cjs=require('./chunk-D6WM53FN.cjs'),fs=require('fs'),path=require('path');var h=l=>{let a={},e=l.split(`
|
|
2
2
|
`);for(let t=0;t<e.length;t++){let i=e[t]?.trim()??"";if(!i||i[0]==="#")continue;let o=i.indexOf("=");if(o<=0)continue;let n=i.slice(0,o).trim();if(!/^[A-Z_][A-Z0-9_]*$/i.test(n))continue;let r=i.slice(o+1).trim();if(r.length>=2){let s=r[0];(s==='"'||s==="'")&&r[r.length-1]===s&&(r=r.slice(1,-1),s==='"'&&(r=r.replace(/\\n/g,`
|
|
3
|
-
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\\\/g,"\\").replace(/\\"/g,'"').replace(/\\'/g,"'")));}else {let s=r.indexOf("#");s>=0&&(r=r.slice(0,s).trim());}a[n]=r;}return a};function O(l){let a=typeof l=="string"?{path:l,expand:false}:{path:l?.path??".env",expand:l?.expand??false};return {name:a.expand?`dotenv-expand(${a.path})`:`dotenv(${a.path})`,async load(){if(!a.expand){let n=path.resolve(process.cwd(),a.path);return fs.existsSync(n)?h(fs.readFileSync(n,"utf8")):{}}let e=a.path,t=process.env.NODE_ENV||"development",i=[`${e}.defaults`,e,`${e}.local`,`${e}.${t}`,`${e}.${t}.local`],o={};for(let n of i){let r=path.resolve(process.cwd(),n);if(fs.existsSync(r))try{o={...o,...h(fs.readFileSync(r,"utf8"))};}catch{}}return o},loadSync(){if(!a.expand){let n=path.resolve(process.cwd(),a.path);return fs.existsSync(n)?h(fs.readFileSync(n,"utf8")):{}}let e=a.path,t=process.env.NODE_ENV||"development",i=[`${e}.defaults`,e,`${e}.local`,`${e}.${t}`,`${e}.${t}.local`],o={};for(let n of i){let r=path.resolve(process.cwd(),n);if(fs.existsSync(r))try{o={...o,...h(fs.readFileSync(r,"utf8"))};}catch{}}return o}}}function S(l){let a={path:l?.path??"package.json",fields:l?.fields??["version","name","config"]};return {name:"package.json",async load(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let t=fs.readFileSync(e,"utf8"),i=JSON.parse(t),o={};for(let n of a.fields){let r=i[n];if(r!==void 0)if(n==="config"&&typeof r=="object"){let s=(c,d)=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=`${d}_${f.toUpperCase()}`;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):o[m]=String(p);}};s(r,"CONFIG");}else o[n.toUpperCase()]=String(r);}return o}catch(t){throw new Error(`Failed to read package.json: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let t=fs.readFileSync(e,"utf8"),i=JSON.parse(t),o={};for(let n of a.fields){let r=i[n];if(r!==void 0)if(n==="config"&&typeof r=="object"){let s=(c,d)=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=`${d}_${f.toUpperCase()}`;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):o[m]=String(p);}};s(r,"CONFIG");}else o[n.toUpperCase()]=String(r);}return o}catch(t){throw new Error(`Failed to read package.json: ${t instanceof Error?t.message:String(t)}`)}}}}function k(l,a){return {name:`http(${l})`,async load(){try{let e=new AbortController,t=a?.timeout??5e3,i=setTimeout(()=>e.abort(),t),o=await fetch(l,{...a,signal:e.signal});if(clearTimeout(i),!o.ok)throw new Error(`HTTP ${o.status}: ${o.statusText}`);let n=await o.json(),r={},s=(c,d="")=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=d?`${d}_${f}`:f;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):r[m.toUpperCase()]=String(p);}};return s(n),r}catch(e){throw e.name==="AbortError"?new Error(`HTTP request timeout after ${a?.timeout??5e3}ms`):new Error(`Failed to fetch config from ${l}: ${e instanceof Error?e.message:String(e)}`)}}}}function R(l="config.json"){return {name:`json(${l})`,async load(){let a=path.resolve(process.cwd(),l);if(!fs.existsSync(a))return {};try{let e=fs.readFileSync(a,"utf8"),t=JSON.parse(e),i={},o=(n,r="")=>{if(n&&typeof n=="object"&&!Array.isArray(n))for(let[s,c]of Object.entries(n)){let d=r?`${r}_${s}`:s;c&&typeof c=="object"&&!Array.isArray(c)?o(c,d):i[d.toUpperCase()]=String(c);}};return o(t),i}catch(e){throw new Error(`Failed to parse JSON file ${l}: ${e instanceof Error?e.message:String(e)}`)}},loadSync(){let a=path.resolve(process.cwd(),l);if(!fs.existsSync(a))return {};try{let e=fs.readFileSync(a,"utf8"),t=JSON.parse(e),i={},o=(n,r="")=>{if(n&&typeof n=="object"&&!Array.isArray(n))for(let[s,c]of Object.entries(n)){let d=r?`${r}_${s}`:s;c&&typeof c=="object"&&!Array.isArray(c)?o(c,d):i[d.toUpperCase()]=String(c);}};return o(t),i}catch(e){throw new Error(`Failed to parse JSON file ${l}: ${e instanceof Error?e.message:String(e)}`)}}}}function _(l="/run/secrets"){return {name:`secrets(${l})`,async load(){let{readdirSync:a,statSync:e}=await import('fs'),t=path.resolve(process.cwd(),l);if(!fs.existsSync(t))return {};try{let i=a(t),o={};for(let n of i){let r=path.join(t,n);if(!e(r).isFile())continue;let c=n.toUpperCase().replace(/[.-]/g,"_"),d=fs.readFileSync(r,"utf8").trim();o[c]=d;}return o}catch(i){throw new Error(`Failed to read secrets from ${l}: ${i instanceof Error?i.message:String(i)}`)}},loadSync(){let{readdirSync:a,statSync:e}=
|
|
3
|
+
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\\\/g,"\\").replace(/\\"/g,'"').replace(/\\'/g,"'")));}else {let s=r.indexOf("#");s>=0&&(r=r.slice(0,s).trim());}a[n]=r;}return a};function O(l){let a=typeof l=="string"?{path:l,expand:false}:{path:l?.path??".env",expand:l?.expand??false};return {name:a.expand?`dotenv-expand(${a.path})`:`dotenv(${a.path})`,async load(){if(!a.expand){let n=path.resolve(process.cwd(),a.path);return fs.existsSync(n)?h(fs.readFileSync(n,"utf8")):{}}let e=a.path,t=process.env.NODE_ENV||"development",i=[`${e}.defaults`,e,`${e}.local`,`${e}.${t}`,`${e}.${t}.local`],o={};for(let n of i){let r=path.resolve(process.cwd(),n);if(fs.existsSync(r))try{o={...o,...h(fs.readFileSync(r,"utf8"))};}catch{}}return o},loadSync(){if(!a.expand){let n=path.resolve(process.cwd(),a.path);return fs.existsSync(n)?h(fs.readFileSync(n,"utf8")):{}}let e=a.path,t=process.env.NODE_ENV||"development",i=[`${e}.defaults`,e,`${e}.local`,`${e}.${t}`,`${e}.${t}.local`],o={};for(let n of i){let r=path.resolve(process.cwd(),n);if(fs.existsSync(r))try{o={...o,...h(fs.readFileSync(r,"utf8"))};}catch{}}return o}}}function S(l){let a={path:l?.path??"package.json",fields:l?.fields??["version","name","config"]};return {name:"package.json",async load(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let t=fs.readFileSync(e,"utf8"),i=JSON.parse(t),o={};for(let n of a.fields){let r=i[n];if(r!==void 0)if(n==="config"&&typeof r=="object"){let s=(c,d)=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=`${d}_${f.toUpperCase()}`;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):o[m]=String(p);}};s(r,"CONFIG");}else o[n.toUpperCase()]=String(r);}return o}catch(t){throw new Error(`Failed to read package.json: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let t=fs.readFileSync(e,"utf8"),i=JSON.parse(t),o={};for(let n of a.fields){let r=i[n];if(r!==void 0)if(n==="config"&&typeof r=="object"){let s=(c,d)=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=`${d}_${f.toUpperCase()}`;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):o[m]=String(p);}};s(r,"CONFIG");}else o[n.toUpperCase()]=String(r);}return o}catch(t){throw new Error(`Failed to read package.json: ${t instanceof Error?t.message:String(t)}`)}}}}function k(l,a){return {name:`http(${l})`,async load(){try{let e=new AbortController,t=a?.timeout??5e3,i=setTimeout(()=>e.abort(),t),o=await fetch(l,{...a,signal:e.signal});if(clearTimeout(i),!o.ok)throw new Error(`HTTP ${o.status}: ${o.statusText}`);let n=await o.json(),r={},s=(c,d="")=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=d?`${d}_${f}`:f;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):r[m.toUpperCase()]=String(p);}};return s(n),r}catch(e){throw e.name==="AbortError"?new Error(`HTTP request timeout after ${a?.timeout??5e3}ms`):new Error(`Failed to fetch config from ${l}: ${e instanceof Error?e.message:String(e)}`)}}}}function R(l="config.json"){return {name:`json(${l})`,async load(){let a=path.resolve(process.cwd(),l);if(!fs.existsSync(a))return {};try{let e=fs.readFileSync(a,"utf8"),t=JSON.parse(e),i={},o=(n,r="")=>{if(n&&typeof n=="object"&&!Array.isArray(n))for(let[s,c]of Object.entries(n)){let d=r?`${r}_${s}`:s;c&&typeof c=="object"&&!Array.isArray(c)?o(c,d):i[d.toUpperCase()]=String(c);}};return o(t),i}catch(e){throw new Error(`Failed to parse JSON file ${l}: ${e instanceof Error?e.message:String(e)}`)}},loadSync(){let a=path.resolve(process.cwd(),l);if(!fs.existsSync(a))return {};try{let e=fs.readFileSync(a,"utf8"),t=JSON.parse(e),i={},o=(n,r="")=>{if(n&&typeof n=="object"&&!Array.isArray(n))for(let[s,c]of Object.entries(n)){let d=r?`${r}_${s}`:s;c&&typeof c=="object"&&!Array.isArray(c)?o(c,d):i[d.toUpperCase()]=String(c);}};return o(t),i}catch(e){throw new Error(`Failed to parse JSON file ${l}: ${e instanceof Error?e.message:String(e)}`)}}}}function _(l="/run/secrets"){return {name:`secrets(${l})`,async load(){let{readdirSync:a,statSync:e}=await import('fs'),t=path.resolve(process.cwd(),l);if(!fs.existsSync(t))return {};try{let i=a(t),o={};for(let n of i){let r=path.join(t,n);if(!e(r).isFile())continue;let c=n.toUpperCase().replace(/[.-]/g,"_"),d=fs.readFileSync(r,"utf8").trim();o[c]=d;}return o}catch(i){throw new Error(`Failed to read secrets from ${l}: ${i instanceof Error?i.message:String(i)}`)}},loadSync(){let{readdirSync:a,statSync:e}=chunkD6WM53FN_cjs.a("fs"),t=path.resolve(process.cwd(),l);if(!fs.existsSync(t))return {};try{let i=a(t),o={};for(let n of i){let r=path.join(t,n);if(!e(r).isFile())continue;let c=n.toUpperCase().replace(/[.-]/g,"_"),d=fs.readFileSync(r,"utf8").trim();o[c]=d;}return o}catch(i){throw new Error(`Failed to read secrets from ${l}: ${i instanceof Error?i.message:String(i)}`)}}}}function U(l){let a=typeof l=="string"?{path:l}:{path:l?.path??"config.yaml"};return {name:`yaml(${a.path})`,async load(){let e=path.join(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{load:t}=await import('js-yaml'),i=fs.readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`YAML resolver requires 'js-yaml' package. Install it with:
|
|
4
4
|
npm install js-yaml
|
|
5
5
|
# or
|
|
6
|
-
pnpm add js-yaml`):new Error(`Failed to parse YAML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=path.join(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{load:t}=
|
|
6
|
+
pnpm add js-yaml`):new Error(`Failed to parse YAML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=path.join(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{load:t}=chunkD6WM53FN_cjs.a("js-yaml"),i=fs.readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`YAML resolver requires 'js-yaml' package. Install it with:
|
|
7
7
|
npm install js-yaml
|
|
8
8
|
# or
|
|
9
9
|
pnpm add js-yaml`):new Error(`Failed to parse YAML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}}}}function C(l){let a=typeof l=="string"?{path:l}:{path:l?.path??"config.toml"};return {name:`toml(${a.path})`,async load(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{parse:t}=await import('smol-toml'),i=fs.readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`TOML resolver requires 'smol-toml' package. Install it with:
|
|
10
10
|
npm install smol-toml
|
|
11
11
|
# or
|
|
12
|
-
pnpm add smol-toml`):new Error(`Failed to parse TOML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{parse:t}=
|
|
12
|
+
pnpm add smol-toml`):new Error(`Failed to parse TOML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{parse:t}=chunkD6WM53FN_cjs.a("smol-toml"),i=fs.readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`TOML resolver requires 'smol-toml' package. Install it with:
|
|
13
13
|
npm install smol-toml
|
|
14
14
|
# or
|
|
15
15
|
pnpm add smol-toml`):new Error(`Failed to parse TOML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}}}}exports.a=O;exports.b=S;exports.c=k;exports.d=R;exports.e=_;exports.f=U;exports.g=C;
|
package/dist/cli.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';require('./chunk-
|
|
1
|
+
'use strict';require('./chunk-D6WM53FN.cjs');function f(g={}){let{argv:s=process.argv.slice(2),prefix:n="--",normalizeKeys:i=true}=g,l=()=>{let t={};for(let r=0;r<s.length;r++){let c=s[r];if(!c.startsWith(n))continue;let e=c.slice(n.length);if(e.includes("=")){let[p,u]=e.split("=",2);e=i?p.replace(/-/g,"_").toUpperCase():p,t[e]=u;continue}let a=i?e.replace(/-/g,"_").toUpperCase():e,o=s[r+1];!o||o.startsWith(n)?t[a]="true":(t[a]=o,r++);}return t};return {name:"cli-args",load(){return Promise.resolve(l())},loadSync(){return l()}}}exports.cliArgs=f;
|
package/dist/cli.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import'./chunk-
|
|
1
|
+
import'./chunk-I7AUKTXE.js';function f(g={}){let{argv:s=process.argv.slice(2),prefix:n="--",normalizeKeys:i=true}=g,l=()=>{let t={};for(let r=0;r<s.length;r++){let c=s[r];if(!c.startsWith(n))continue;let e=c.slice(n.length);if(e.includes("=")){let[p,u]=e.split("=",2);e=i?p.replace(/-/g,"_").toUpperCase():p,t[e]=u;continue}let a=i?e.replace(/-/g,"_").toUpperCase():e,o=s[r+1];!o||o.startsWith(n)?t[a]="true":(t[a]=o,r++);}return t};return {name:"cli-args",load(){return Promise.resolve(l())},loadSync(){return l()}}}export{f as cliArgs};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkAYZL6CFC_cjs=require('./chunk-AYZL6CFC.cjs');require('./chunk-Y2QEFWEY.cjs');var chunkO7NR4K6A_cjs=require('./chunk-O7NR4K6A.cjs');require('./chunk-4QOKRJ3F.cjs');var chunk6D5APQIG_cjs=require('./chunk-6D5APQIG.cjs');require('./chunk-D6WM53FN.cjs');Object.defineProperty(exports,"resolve",{enumerable:true,get:function(){return chunkAYZL6CFC_cjs.a}});Object.defineProperty(exports,"resolveAsync",{enumerable:true,get:function(){return chunkAYZL6CFC_cjs.b}});Object.defineProperty(exports,"safeResolve",{enumerable:true,get:function(){return chunkAYZL6CFC_cjs.c}});Object.defineProperty(exports,"safeResolveAsync",{enumerable:true,get:function(){return chunkAYZL6CFC_cjs.d}});Object.defineProperty(exports,"clearAuditLog",{enumerable:true,get:function(){return chunkO7NR4K6A_cjs.d}});Object.defineProperty(exports,"getAuditLog",{enumerable:true,get:function(){return chunkO7NR4K6A_cjs.c}});Object.defineProperty(exports,"isAsyncOnlyResolver",{enumerable:true,get:function(){return chunk6D5APQIG_cjs.b}});Object.defineProperty(exports,"isSyncResolver",{enumerable:true,get:function(){return chunk6D5APQIG_cjs.a}});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as resolve,b as resolveAsync,c as safeResolve,d as safeResolveAsync}from'./chunk-
|
|
1
|
+
export{a as resolve,b as resolveAsync,c as safeResolve,d as safeResolveAsync}from'./chunk-CH4V6URL.js';import'./chunk-5XUR34FH.js';export{d as clearAuditLog,c as getAuditLog}from'./chunk-6EWR3WHU.js';import'./chunk-WKIPEKF6.js';export{b as isAsyncOnlyResolver,a as isSyncResolver}from'./chunk-HHOS5S5T.js';import'./chunk-I7AUKTXE.js';
|
package/dist/resolver.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkY2QEFWEY_cjs=require('./chunk-Y2QEFWEY.cjs');require('./chunk-O7NR4K6A.cjs'),require('./chunk-D6WM53FN.cjs');Object.defineProperty(exports,"normalizeSchema",{enumerable:true,get:function(){return chunkY2QEFWEY_cjs.a}});Object.defineProperty(exports,"resolveEnvInternal",{enumerable:true,get:function(){return chunkY2QEFWEY_cjs.b}});Object.defineProperty(exports,"resolveEnvInternalSync",{enumerable:true,get:function(){return chunkY2QEFWEY_cjs.c}});
|
package/dist/resolver.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as normalizeSchema,b as resolveEnvInternal,c as resolveEnvInternalSync}from'./chunk-
|
|
1
|
+
export{a as normalizeSchema,b as resolveEnvInternal,c as resolveEnvInternalSync}from'./chunk-5XUR34FH.js';import'./chunk-6EWR3WHU.js';import'./chunk-I7AUKTXE.js';
|
package/dist/resolvers.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkZ3TI2YXP_cjs=require('./chunk-Z3TI2YXP.cjs'),chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');require('./chunk-D6WM53FN.cjs');Object.defineProperty(exports,"dotenv",{enumerable:true,get:function(){return chunkZ3TI2YXP_cjs.a}});Object.defineProperty(exports,"http",{enumerable:true,get:function(){return chunkZ3TI2YXP_cjs.c}});Object.defineProperty(exports,"json",{enumerable:true,get:function(){return chunkZ3TI2YXP_cjs.d}});Object.defineProperty(exports,"packageJson",{enumerable:true,get:function(){return chunkZ3TI2YXP_cjs.b}});Object.defineProperty(exports,"secrets",{enumerable:true,get:function(){return chunkZ3TI2YXP_cjs.e}});Object.defineProperty(exports,"toml",{enumerable:true,get:function(){return chunkZ3TI2YXP_cjs.g}});Object.defineProperty(exports,"yaml",{enumerable:true,get:function(){return chunkZ3TI2YXP_cjs.f}});Object.defineProperty(exports,"processEnv",{enumerable:true,get:function(){return chunk4QOKRJ3F_cjs.a}});
|
package/dist/resolvers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as dotenv,c as http,d as json,b as packageJson,e as secrets,g as toml,f as yaml}from'./chunk-
|
|
1
|
+
export{a as dotenv,c as http,d as json,b as packageJson,e as secrets,g as toml,f as yaml}from'./chunk-27CQXH2M.js';export{a as processEnv}from'./chunk-WKIPEKF6.js';import'./chunk-I7AUKTXE.js';
|
package/dist/types.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var chunk6D5APQIG_cjs=require('./chunk-6D5APQIG.cjs');require('./chunk-
|
|
1
|
+
'use strict';var chunk6D5APQIG_cjs=require('./chunk-6D5APQIG.cjs');require('./chunk-D6WM53FN.cjs');Object.defineProperty(exports,"isAsyncOnlyResolver",{enumerable:true,get:function(){return chunk6D5APQIG_cjs.b}});Object.defineProperty(exports,"isSyncResolver",{enumerable:true,get:function(){return chunk6D5APQIG_cjs.a}});
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{b as isAsyncOnlyResolver,a as isSyncResolver}from'./chunk-HHOS5S5T.js';import'./chunk-
|
|
1
|
+
export{b as isAsyncOnlyResolver,a as isSyncResolver}from'./chunk-HHOS5S5T.js';import'./chunk-I7AUKTXE.js';
|
package/dist/utils.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkAYZL6CFC_cjs=require('./chunk-AYZL6CFC.cjs');require('./chunk-Y2QEFWEY.cjs'),require('./chunk-O7NR4K6A.cjs'),require('./chunk-4QOKRJ3F.cjs'),require('./chunk-6D5APQIG.cjs');var chunkD6WM53FN_cjs=require('./chunk-D6WM53FN.cjs');function T(e,n={}){let{ttl:r=3e5,maxAge:s=36e5,staleWhileRevalidate:o=false}=n,t=null,a={name:`cached(${e.name})`,metadata:{},async load(){let i=Date.now();if(!t||i-t.timestamp>s){let l=e.load?await e.load():{};return t={data:l,timestamp:i},a.metadata={cached:false},l}if(i-t.timestamp<r)return a.metadata={cached:true},t.data;if(o&&!t.refreshPromise){let l=Promise.resolve(e.load?e.load():Promise.resolve({}));return t.refreshPromise=l.then(u=>(t.data=u,t.timestamp=Date.now(),t.refreshPromise=void 0,u)).catch(()=>(t.refreshPromise=void 0,t.data)),a.metadata={cached:true,stale:true},t.data}let d=e.load?await e.load():{};return t={data:d,timestamp:i},a.metadata={cached:false},d}};return a}var p={short:30*1e3,minute:60*1e3,minutes5:300*1e3,minutes15:900*1e3,hour:3600*1e3,hours6:360*60*1e3,day:1440*60*1e3};function C(e={}){return {ttl:e.ttl??p.minutes5,maxAge:e.maxAge??p.hour,staleWhileRevalidate:e.staleWhileRevalidate??true,key:"aws-secrets"}}function b(e,n=3,r=1e3){return {name:`retry(${e.name})`,async load(){let s;for(let o=0;o<=n;o++)try{return e.load?await e.load():{}}catch(t){s=t instanceof Error?t:new Error(String(t)),o<n&&await new Promise(a=>setTimeout(a,r*Math.pow(2,o)));}throw s}}}function x(e,n){let r=n.toUpperCase();return {name:`withPrefix(${e.name}, ${n})`,async load(){let s=e.load?await e.load():{},o={};for(let[t,a]of Object.entries(s))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=a;}else o[t]=a;return o},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let s=e.loadSync(),o={};for(let[t,a]of Object.entries(s))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=a;}else o[t]=a;return o}}}function P(e,n){let r={...e};for(let[s,o]of Object.entries(n))Object.defineProperty(r,s,{get(){return o(e)},enumerable:true,configurable:true});return r}function $(e,n){return {name:`withAliases(${e.name})`,async load(){let r=e.load?await e.load():{};return g(r,n)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let r=e.loadSync();return g(r,n)}}}function g(e,n){let r={...e};for(let[s,o]of Object.entries(n))for(let t of o)if(e[t]!==void 0){r[s]=e[t];break}return r}function S(e,n){return {name:`withTransform(${e.name})`,async load(){let r=e.load?await e.load():{};return h(r,n)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let r=e.loadSync();return h(r,n)}}}function h(e,n){let r={...e};for(let[s,o]of Object.entries(n))if(e[s]!==void 0)try{r[s]=o(e[s]);}catch(t){throw new Error(`Transform failed for ${s}: ${t instanceof Error?t.message:String(t)}`)}return r}function k(e,n){let s=`${n.toUpperCase()}_`;return {name:`withNamespace(${e.name}, ${n})`,async load(){let o=e.load?await e.load():{},t={};for(let[a,i]of Object.entries(o))if(a.toUpperCase().startsWith(s)){let d=a.slice(s.length);t[d]=i;}return t},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let o=e.loadSync(),t={};for(let[a,i]of Object.entries(o))if(a.toUpperCase().startsWith(s)){let d=a.slice(s.length);t[d]=i;}return t}}}function v(e,n){let{onChange:r,debounce:s=100,files:o=[".env"]}=n??{},t,a=null,i=[],d=async()=>{try{return await import('./index.cjs'),t=await chunkAYZL6CFC_cjs.b(e),t}catch(c){throw console.error("[watch] Failed to load config:",c),c}},l=()=>{a&&clearTimeout(a),a=setTimeout(async()=>{try{let c=await d();r?.(c);}catch(c){console.error("[watch] Failed to reload config:",c);}},s);},{watch:u}=chunkD6WM53FN_cjs.a("fs"),{join:y}=chunkD6WM53FN_cjs.a("path");for(let c of o)try{let w=u(y(process.cwd(),c),l);i.push(w);}catch{}return d().catch(console.error),{getConfig:()=>t,stop:()=>{a&&clearTimeout(a);for(let c of i)c.close();}}}exports.TTL=p;exports.awsCache=C;exports.cached=T;exports.retry=b;exports.watch=v;exports.withAliases=$;exports.withComputed=P;exports.withNamespace=k;exports.withPrefix=x;exports.withTransform=S;
|
package/dist/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {b as b$1}from'./chunk-
|
|
1
|
+
import {b as b$1}from'./chunk-CH4V6URL.js';import'./chunk-5XUR34FH.js';import'./chunk-6EWR3WHU.js';import'./chunk-WKIPEKF6.js';import'./chunk-HHOS5S5T.js';import {a}from'./chunk-I7AUKTXE.js';function T(e,n={}){let{ttl:r=3e5,maxAge:s=36e5,staleWhileRevalidate:o=false}=n,t=null,a={name:`cached(${e.name})`,metadata:{},async load(){let i=Date.now();if(!t||i-t.timestamp>s){let l=e.load?await e.load():{};return t={data:l,timestamp:i},a.metadata={cached:false},l}if(i-t.timestamp<r)return a.metadata={cached:true},t.data;if(o&&!t.refreshPromise){let l=Promise.resolve(e.load?e.load():Promise.resolve({}));return t.refreshPromise=l.then(u=>(t.data=u,t.timestamp=Date.now(),t.refreshPromise=void 0,u)).catch(()=>(t.refreshPromise=void 0,t.data)),a.metadata={cached:true,stale:true},t.data}let d=e.load?await e.load():{};return t={data:d,timestamp:i},a.metadata={cached:false},d}};return a}var p={short:30*1e3,minute:60*1e3,minutes5:300*1e3,minutes15:900*1e3,hour:3600*1e3,hours6:360*60*1e3,day:1440*60*1e3};function C(e={}){return {ttl:e.ttl??p.minutes5,maxAge:e.maxAge??p.hour,staleWhileRevalidate:e.staleWhileRevalidate??true,key:"aws-secrets"}}function b(e,n=3,r=1e3){return {name:`retry(${e.name})`,async load(){let s;for(let o=0;o<=n;o++)try{return e.load?await e.load():{}}catch(t){s=t instanceof Error?t:new Error(String(t)),o<n&&await new Promise(a=>setTimeout(a,r*Math.pow(2,o)));}throw s}}}function x(e,n){let r=n.toUpperCase();return {name:`withPrefix(${e.name}, ${n})`,async load(){let s=e.load?await e.load():{},o={};for(let[t,a]of Object.entries(s))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=a;}else o[t]=a;return o},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let s=e.loadSync(),o={};for(let[t,a]of Object.entries(s))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=a;}else o[t]=a;return o}}}function P(e,n){let r={...e};for(let[s,o]of Object.entries(n))Object.defineProperty(r,s,{get(){return o(e)},enumerable:true,configurable:true});return r}function $(e,n){return {name:`withAliases(${e.name})`,async load(){let r=e.load?await e.load():{};return g(r,n)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let r=e.loadSync();return g(r,n)}}}function g(e,n){let r={...e};for(let[s,o]of Object.entries(n))for(let t of o)if(e[t]!==void 0){r[s]=e[t];break}return r}function S(e,n){return {name:`withTransform(${e.name})`,async load(){let r=e.load?await e.load():{};return h(r,n)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let r=e.loadSync();return h(r,n)}}}function h(e,n){let r={...e};for(let[s,o]of Object.entries(n))if(e[s]!==void 0)try{r[s]=o(e[s]);}catch(t){throw new Error(`Transform failed for ${s}: ${t instanceof Error?t.message:String(t)}`)}return r}function k(e,n){let s=`${n.toUpperCase()}_`;return {name:`withNamespace(${e.name}, ${n})`,async load(){let o=e.load?await e.load():{},t={};for(let[a,i]of Object.entries(o))if(a.toUpperCase().startsWith(s)){let d=a.slice(s.length);t[d]=i;}return t},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let o=e.loadSync(),t={};for(let[a,i]of Object.entries(o))if(a.toUpperCase().startsWith(s)){let d=a.slice(s.length);t[d]=i;}return t}}}function v(e,n){let{onChange:r,debounce:s=100,files:o=[".env"]}=n??{},t,a$1=null,i=[],d=async()=>{try{return await import('./index.js'),t=await b$1(e),t}catch(c){throw console.error("[watch] Failed to load config:",c),c}},l=()=>{a$1&&clearTimeout(a$1),a$1=setTimeout(async()=>{try{let c=await d();r?.(c);}catch(c){console.error("[watch] Failed to reload config:",c);}},s);},{watch:u}=a("fs"),{join:y}=a("path");for(let c of o)try{let w=u(y(process.cwd(),c),l);i.push(w);}catch{}return d().catch(console.error),{getConfig:()=>t,stop:()=>{a$1&&clearTimeout(a$1);for(let c of i)c.close();}}}export{p as TTL,C as awsCache,T as cached,b as retry,v as watch,$ as withAliases,P as withComputed,k as withNamespace,x as withPrefix,S as withTransform};
|
package/dist/valibot.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';require('./chunk-
|
|
1
|
+
'use strict';require('./chunk-Z3TI2YXP.cjs');var chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');require('./chunk-D6WM53FN.cjs');async function u(t,n,e){let s={};for(let o of t)try{let r=o.load?await o.load():{};s={...s,...r};}catch(r){if(e)throw new Error(`Resolver ${o.name} failed: ${r instanceof Error?r.message:r}`)}if(n)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,i)=>s[i]||"");return s}function p(t,n,e){let s={};for(let o of t)try{if(!o.loadSync){if(e)throw new Error(`Resolver ${o.name} does not support sync loading`);continue}let r=o.loadSync();s={...s,...r};}catch(r){if(e)throw new Error(`Resolver ${o.name} failed: ${r instanceof Error?r.message:r}`)}if(n)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,i)=>s[i]||"");return s}function f(t){return !t||!Array.isArray(t)?[{path:[],message:"Validation failed",code:"unknown_error"}]:t.map(n=>{if(!n||typeof n!="object")return {path:[],message:"Validation failed",code:"unknown_error"};let e=n;return {path:e.path?.map(s=>s.key)||[],message:e.message||"Validation failed",code:e.type}})}async function d(t,n={}){let{resolvers:e=[chunk4QOKRJ3F_cjs.a()],interpolate:s=false,strict:o=true}=n,r=await u(e,s,o);return t.parseAsync(r)}async function y(t,n={}){try{let{resolvers:e=[chunk4QOKRJ3F_cjs.a()],interpolate:s=!1,strict:o=!0}=n,r=await u(e,s,o),a=await t.safeParseAsync(r);if(a.success)return {success:!0,data:a.output};let i=f(a.issues);return {success:!1,error:i.map(l=>l.message).join(", "),issues:i}}catch(e){return {success:false,error:e instanceof Error?e.message:String(e),issues:[{path:[],message:e instanceof Error?e.message:String(e),code:"resolver_error"}]}}}function g(t,n={}){let{resolvers:e=[chunk4QOKRJ3F_cjs.a()],interpolate:s=false,strict:o=true}=n,r=p(e,s,o);return t.parse(r)}function b(t,n={}){try{let{resolvers:e=[chunk4QOKRJ3F_cjs.a()],interpolate:s=!1,strict:o=!0}=n,r=p(e,s,o),a=t.safeParse(r);if(a.success)return {success:!0,data:a.output};let i=f(a.issues);return {success:!1,error:i.map(l=>l.message).join(", "),issues:i}}catch(e){return {success:false,error:e instanceof Error?e.message:String(e),issues:[{path:[],message:e instanceof Error?e.message:String(e),code:"resolver_error"}]}}}exports.resolveSyncValibot=g;exports.resolveValibot=d;exports.safeResolveSyncValibot=b;exports.safeResolveValibot=y;
|
package/dist/valibot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import'./chunk-
|
|
1
|
+
import'./chunk-27CQXH2M.js';import {a}from'./chunk-WKIPEKF6.js';import'./chunk-I7AUKTXE.js';async function u(t,n,e){let s={};for(let o of t)try{let r=o.load?await o.load():{};s={...s,...r};}catch(r){if(e)throw new Error(`Resolver ${o.name} failed: ${r instanceof Error?r.message:r}`)}if(n)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,i)=>s[i]||"");return s}function p(t,n,e){let s={};for(let o of t)try{if(!o.loadSync){if(e)throw new Error(`Resolver ${o.name} does not support sync loading`);continue}let r=o.loadSync();s={...s,...r};}catch(r){if(e)throw new Error(`Resolver ${o.name} failed: ${r instanceof Error?r.message:r}`)}if(n)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,i)=>s[i]||"");return s}function f(t){return !t||!Array.isArray(t)?[{path:[],message:"Validation failed",code:"unknown_error"}]:t.map(n=>{if(!n||typeof n!="object")return {path:[],message:"Validation failed",code:"unknown_error"};let e=n;return {path:e.path?.map(s=>s.key)||[],message:e.message||"Validation failed",code:e.type}})}async function d(t,n={}){let{resolvers:e=[a()],interpolate:s=false,strict:o=true}=n,r=await u(e,s,o);return t.parseAsync(r)}async function y(t,n={}){try{let{resolvers:e=[a()],interpolate:s=!1,strict:o=!0}=n,r=await u(e,s,o),a$1=await t.safeParseAsync(r);if(a$1.success)return {success:!0,data:a$1.output};let i=f(a$1.issues);return {success:!1,error:i.map(l=>l.message).join(", "),issues:i}}catch(e){return {success:false,error:e instanceof Error?e.message:String(e),issues:[{path:[],message:e instanceof Error?e.message:String(e),code:"resolver_error"}]}}}function g(t,n={}){let{resolvers:e=[a()],interpolate:s=false,strict:o=true}=n,r=p(e,s,o);return t.parse(r)}function b(t,n={}){try{let{resolvers:e=[a()],interpolate:s=!1,strict:o=!0}=n,r=p(e,s,o),a$1=t.safeParse(r);if(a$1.success)return {success:!0,data:a$1.output};let i=f(a$1.issues);return {success:!1,error:i.map(l=>l.message).join(", "),issues:i}}catch(e){return {success:false,error:e instanceof Error?e.message:String(e),issues:[{path:[],message:e instanceof Error?e.message:String(e),code:"resolver_error"}]}}}export{g as resolveSyncValibot,d as resolveValibot,b as safeResolveSyncValibot,y as safeResolveValibot};
|
package/dist/validators.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkD6WM53FN_cjs=require('./chunk-D6WM53FN.cjs');function u(t){if(!/^postgres(ql)?:\/\/.+/.test(t))return {valid:false,error:"Invalid PostgreSQL URL"};try{return new URL(t),{valid:!0}}catch{return {valid:false,error:"Invalid PostgreSQL URL"}}}function p(t){if(!/^mysql:\/\/.+/.test(t))return {valid:false,error:"Invalid MySQL URL"};try{return new URL(t),{valid:!0}}catch{return {valid:false,error:"Invalid MySQL URL"}}}function f(t){return /^mongodb(\+srv)?:\/\/.+/.test(t)?/^mongodb(\+srv)?:\/\/([^@]+@)?[^/]+(\/[^?]*)?(\\?.*)?$/.test(t)?{valid:true}:{valid:false,error:"Invalid MongoDB URL"}:{valid:false,error:"Invalid MongoDB URL"}}function c(t){if(!/^rediss?:\/\/.+/.test(t))return {valid:false,error:"Invalid Redis URL"};try{return new URL(t),{valid:!0}}catch{return {valid:false,error:"Invalid Redis URL"}}}function g(t){try{let n=new URL(t);return ["http:","https:","ws:","wss:","ftp:","ftps:","file:","postgres:","postgresql:","mysql:","mongodb:","redis:","rediss:"].includes(n.protocol)?{valid:!0}:{valid:!1,error:`URL protocol '${n.protocol}' is not allowed`}}catch{return {valid:false,error:"Invalid URL"}}}function m(t){return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(t)?t.length>254?{valid:false,error:"Invalid email"}:{valid:true}:{valid:false,error:"Invalid email"}}function w(t){let n=Number(t);return n!==n||n<1||n>65535?{valid:false,error:"Invalid port"}:{valid:true}}function O(t){let n=Number(t);return n!==n?{valid:false,error:"Invalid number"}:{valid:true}}function R(t){let n=t.toLowerCase();return ["true","1","yes","on","false","0","no","off",""].includes(n)?{valid:true}:{valid:false,error:"Invalid boolean"}}function x(t){let n=new Date(t);if(isNaN(n.getTime()))return {valid:false,error:"Invalid date - cannot parse date value"};if(/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{1,3})?(Z|[+-]\d{2}:\d{2})?)?$/.test(t)){if(/^\d{4}-\d{2}-\d{2}$/.test(t)){let[e,o,a]=t.split("-").map(Number);if(n.getUTCFullYear()!==e||n.getUTCMonth()+1!==o||n.getUTCDate()!==a)return {valid:false,error:"Invalid date value"}}return {valid:true}}return {valid:false,error:"Date must be in ISO 8601 format (YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss.sssZ)"}}function v(t){if(!/^\d+$/.test(t))return {valid:false,error:"Invalid timestamp"};let n=Number(t);return isNaN(n)||n<0?{valid:false,error:"Invalid timestamp"}:n>253402300799?{valid:false,error:"Timestamp too large"}:{valid:true}}function b(t){let n=/^(\d+(?:\.\d+)?)(ms|s|m|h|d)$/,r=/^(?:(\d+(?:\.\d+)?)h)?(?:(\d+(?:\.\d+)?)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+(?:\.\d+)?)ms)?$/,e=t.match(n);if(e){let a=parseFloat(e[1]),s=e[2],l={ms:1,s:1e3,m:60*1e3,h:3600*1e3,d:1440*60*1e3};return {valid:true,value:Math.floor(a*l[s])}}let o=t.match(r);if(o&&o[0]){let a=0;if(o[1]&&(a+=parseFloat(o[1])*60*60*1e3),o[2]&&(a+=parseFloat(o[2])*60*1e3),o[3]&&(a+=parseFloat(o[3])*1e3),o[4]&&(a+=parseFloat(o[4])),a>0)return {valid:true,value:Math.floor(a)}}return {valid:false,error:"Duration must be in format: 5s, 2h, 30m, 1h30m, etc."}}function h(t,n){try{let r=chunkD6WM53FN_cjs.a("fs"),{resolve:e}=chunkD6WM53FN_cjs.a("path"),o=e(process.cwd(),t);return {valid:!0,value:r.readFileSync(o,"utf8").trim()}}catch(r){return {valid:false,error:`Failed to read file${n?` for ${n}`:""}: ${r instanceof Error?r.message:String(r)}`}}}function k(t){let n=(r=>{if(!r.startsWith("http://")&&!r.startsWith("https://"))throw new Error(`Invalid HTTP URL: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function V(t){let n=(r=>{try{return JSON.parse(r)}catch{throw new Error(`Invalid JSON: "${r}"`)}});return t&&(n.default=t.default,n.optional=t.optional),n}function y(t){let n=((r,e)=>{if(r===""&&!t?.allowEmpty)throw new Error("String cannot be empty");if(t?.min!==void 0&&r.length<t.min)throw new Error(`String too short (min: ${t.min})`);if(t?.max!==void 0&&r.length>t.max)throw new Error(`String too long (max: ${t.max})`);if(t?.pattern&&!new RegExp(t.pattern).test(r)){let o=e?`${e} does not match required pattern`:"String does not match pattern";throw new Error(o)}return r});return t&&(n.default=t.default,n.optional=t.optional),n}function $(t){let n=(r=>{let e=Number(r);if(isNaN(e))throw new Error(`Invalid number: "${r}"`);if(t?.min!==void 0&&e<t.min)throw new Error(`Number too small (min: ${t.min})`);if(t?.max!==void 0&&e>t.max)throw new Error(`Number too large (max: ${t.max})`);return e});return t&&(n.default=t.default,n.optional=t.optional),n}function I(t){let n=(r=>{let e=r.toLowerCase();if(["true","1","yes","on"].includes(e))return true;if(["false","0","no","off",""].includes(e))return false;throw new Error(`Invalid boolean: "${r}"`)});return t&&(n.default=t.default,n.optional=t.optional),n}function T(t){let n=(r=>{try{return new URL(r),r}catch{throw new Error(`Invalid URL: "${r}"`)}});return t&&(n.default=t.default,n.optional=t.optional),n}function E(t){let n=(r=>{if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r))throw new Error(`Invalid email: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function L(t){let n=(r=>{let e=Number(r);if(isNaN(e)||e<1||e>65535)throw new Error(`Invalid port: "${r}"`);return e});return t&&(n.default=t.default,n.optional=t.optional),n}function N(t){let n=(r=>{if(!r.startsWith("postgres://")&&!r.startsWith("postgresql://"))throw new Error(`Invalid PostgreSQL URL: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function U(t){let n=(r=>{if(!r.startsWith("mysql://"))throw new Error(`Invalid MySQL URL: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function D(t){let n=(r=>{if(!r.startsWith("mongodb://")&&!r.startsWith("mongodb+srv://"))throw new Error(`Invalid MongoDB URL: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function S(t){let n=(r=>{if(!r.startsWith("redis://")&&!r.startsWith("rediss://"))throw new Error(`Invalid Redis URL: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function M(t){let n=(r=>{if(!r.startsWith("https://"))throw new Error(`Invalid HTTPS URL: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function P(t){let n=(r=>{let e=t?.separator||",";return r.split(e).map(o=>o.trim()).filter(o=>o.length>0)});return t&&(n.default=t.default,n.optional=t.optional),n}function q(t){let n=(r=>{let e=t?.separator||",";return r.split(e).map(o=>{let a=Number(o.trim());if(isNaN(a))throw new Error(`Invalid number in array: "${o}"`);return a})});return t&&(n.default=t.default,n.optional=t.optional),n}function F(t){let n=(r=>{let e=t?.separator||",",o=r.split(e).map(a=>a.trim()).filter(a=>a.length>0);for(let a of o)try{new URL(a);}catch{throw new Error(`Invalid URL in array: "${a}"`)}return o});return t&&(n.default=t.default,n.optional=t.optional),n}function d(t,n){let r=(e=>{if(!t.includes(e))throw new Error(`Invalid value: "${e}". Allowed values: ${t.join(", ")}`);return e});return n&&(r.default=n.default,r.optional=n.optional),r}function A(t,n){return d(t,n)}function W(t){let n=[...t];return n.__optional=true,n}function _(t){let n=(r=>{let e=r.match(/^(\d+)([smhd])$/);if(!e)throw new Error(`Invalid duration: "${r}". Use format like "5s", "2m", "1h", "1d"`);let[,o,a]=e,l={s:1e3,m:6e4,h:36e5,d:864e5}[a];return Number(o)*l});return t&&(n.default=t.default,n.optional=t.optional),n}function Z(t){let n=(r=>{try{let e=chunkD6WM53FN_cjs.a("fs"),{resolve:o}=chunkD6WM53FN_cjs.a("path"),a=o(process.cwd(),r);return e.readFileSync(a,"utf8").trim()}catch(e){throw new Error(`Failed to read file: ${e instanceof Error?e.message:String(e)}`)}});return t&&(n.default=t.default,n.optional=t.optional,n.secretsDir=t.secretsDir),n.__isFileValidator=true,n}function Y(t){let n=(r=>r);return t&&(n.default=t.default,n.optional=t.optional),n}function z(t,n){let r=t;return n&&(r.default=n.default,r.optional=n.optional),r}function C(t){let n=(r=>{if(!/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?)?$/.test(r))throw new Error(`Date must be in ISO 8601 format: "${r}"`);let o=new Date(r);if(isNaN(o.getTime()))throw new Error(`Cannot parse date value: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function Q(t){let n=(r=>{let e=Number(r);if(isNaN(e)||!Number.isInteger(e))throw new Error(`Invalid timestamp: "${r}"`);if(e<0)throw new Error(`Invalid timestamp: "${r}"`);if(e>253402300799)throw new Error(`Timestamp too large: "${r}"`);return e});return t&&(n.default=t.default,n.optional=t.optional),n}
|
|
2
2
|
exports.boolean=I;exports.custom=z;exports.date=C;exports.duration=_;exports.email=E;exports.enumOf=A;exports.file=Z;exports.http=k;exports.https=M;exports.json=V;exports.mongodb=D;exports.mysql=U;exports.number=$;exports.numberArray=q;exports.oneOf=d;exports.optional=W;exports.port=L;exports.postgres=N;exports.redis=S;exports.secret=Y;exports.string=y;exports.stringArray=P;exports.timestamp=Q;exports.url=T;exports.urlArray=F;exports.validateBoolean=R;exports.validateDate=x;exports.validateDuration=b;exports.validateEmail=m;exports.validateFile=h;exports.validateMongodb=f;exports.validateMysql=p;exports.validateNumber=O;exports.validatePort=w;exports.validatePostgres=u;exports.validateRedis=c;exports.validateTimestamp=v;exports.validateUrl=g;
|
package/dist/validators.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a}from'./chunk-
|
|
1
|
+
import {a}from'./chunk-I7AUKTXE.js';function u(t){if(!/^postgres(ql)?:\/\/.+/.test(t))return {valid:false,error:"Invalid PostgreSQL URL"};try{return new URL(t),{valid:!0}}catch{return {valid:false,error:"Invalid PostgreSQL URL"}}}function p(t){if(!/^mysql:\/\/.+/.test(t))return {valid:false,error:"Invalid MySQL URL"};try{return new URL(t),{valid:!0}}catch{return {valid:false,error:"Invalid MySQL URL"}}}function f(t){return /^mongodb(\+srv)?:\/\/.+/.test(t)?/^mongodb(\+srv)?:\/\/([^@]+@)?[^/]+(\/[^?]*)?(\\?.*)?$/.test(t)?{valid:true}:{valid:false,error:"Invalid MongoDB URL"}:{valid:false,error:"Invalid MongoDB URL"}}function c(t){if(!/^rediss?:\/\/.+/.test(t))return {valid:false,error:"Invalid Redis URL"};try{return new URL(t),{valid:!0}}catch{return {valid:false,error:"Invalid Redis URL"}}}function g(t){try{let n=new URL(t);return ["http:","https:","ws:","wss:","ftp:","ftps:","file:","postgres:","postgresql:","mysql:","mongodb:","redis:","rediss:"].includes(n.protocol)?{valid:!0}:{valid:!1,error:`URL protocol '${n.protocol}' is not allowed`}}catch{return {valid:false,error:"Invalid URL"}}}function m(t){return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(t)?t.length>254?{valid:false,error:"Invalid email"}:{valid:true}:{valid:false,error:"Invalid email"}}function w(t){let n=Number(t);return n!==n||n<1||n>65535?{valid:false,error:"Invalid port"}:{valid:true}}function O(t){let n=Number(t);return n!==n?{valid:false,error:"Invalid number"}:{valid:true}}function R(t){let n=t.toLowerCase();return ["true","1","yes","on","false","0","no","off",""].includes(n)?{valid:true}:{valid:false,error:"Invalid boolean"}}function x(t){let n=new Date(t);if(isNaN(n.getTime()))return {valid:false,error:"Invalid date - cannot parse date value"};if(/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{1,3})?(Z|[+-]\d{2}:\d{2})?)?$/.test(t)){if(/^\d{4}-\d{2}-\d{2}$/.test(t)){let[e,o,a]=t.split("-").map(Number);if(n.getUTCFullYear()!==e||n.getUTCMonth()+1!==o||n.getUTCDate()!==a)return {valid:false,error:"Invalid date value"}}return {valid:true}}return {valid:false,error:"Date must be in ISO 8601 format (YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss.sssZ)"}}function v(t){if(!/^\d+$/.test(t))return {valid:false,error:"Invalid timestamp"};let n=Number(t);return isNaN(n)||n<0?{valid:false,error:"Invalid timestamp"}:n>253402300799?{valid:false,error:"Timestamp too large"}:{valid:true}}function b(t){let n=/^(\d+(?:\.\d+)?)(ms|s|m|h|d)$/,r=/^(?:(\d+(?:\.\d+)?)h)?(?:(\d+(?:\.\d+)?)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+(?:\.\d+)?)ms)?$/,e=t.match(n);if(e){let a=parseFloat(e[1]),s=e[2],l={ms:1,s:1e3,m:60*1e3,h:3600*1e3,d:1440*60*1e3};return {valid:true,value:Math.floor(a*l[s])}}let o=t.match(r);if(o&&o[0]){let a=0;if(o[1]&&(a+=parseFloat(o[1])*60*60*1e3),o[2]&&(a+=parseFloat(o[2])*60*1e3),o[3]&&(a+=parseFloat(o[3])*1e3),o[4]&&(a+=parseFloat(o[4])),a>0)return {valid:true,value:Math.floor(a)}}return {valid:false,error:"Duration must be in format: 5s, 2h, 30m, 1h30m, etc."}}function h(t,n){try{let r=a("fs"),{resolve:e}=a("path"),o=e(process.cwd(),t);return {valid:!0,value:r.readFileSync(o,"utf8").trim()}}catch(r){return {valid:false,error:`Failed to read file${n?` for ${n}`:""}: ${r instanceof Error?r.message:String(r)}`}}}function k(t){let n=(r=>{if(!r.startsWith("http://")&&!r.startsWith("https://"))throw new Error(`Invalid HTTP URL: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function V(t){let n=(r=>{try{return JSON.parse(r)}catch{throw new Error(`Invalid JSON: "${r}"`)}});return t&&(n.default=t.default,n.optional=t.optional),n}function y(t){let n=((r,e)=>{if(r===""&&!t?.allowEmpty)throw new Error("String cannot be empty");if(t?.min!==void 0&&r.length<t.min)throw new Error(`String too short (min: ${t.min})`);if(t?.max!==void 0&&r.length>t.max)throw new Error(`String too long (max: ${t.max})`);if(t?.pattern&&!new RegExp(t.pattern).test(r)){let o=e?`${e} does not match required pattern`:"String does not match pattern";throw new Error(o)}return r});return t&&(n.default=t.default,n.optional=t.optional),n}function $(t){let n=(r=>{let e=Number(r);if(isNaN(e))throw new Error(`Invalid number: "${r}"`);if(t?.min!==void 0&&e<t.min)throw new Error(`Number too small (min: ${t.min})`);if(t?.max!==void 0&&e>t.max)throw new Error(`Number too large (max: ${t.max})`);return e});return t&&(n.default=t.default,n.optional=t.optional),n}function I(t){let n=(r=>{let e=r.toLowerCase();if(["true","1","yes","on"].includes(e))return true;if(["false","0","no","off",""].includes(e))return false;throw new Error(`Invalid boolean: "${r}"`)});return t&&(n.default=t.default,n.optional=t.optional),n}function T(t){let n=(r=>{try{return new URL(r),r}catch{throw new Error(`Invalid URL: "${r}"`)}});return t&&(n.default=t.default,n.optional=t.optional),n}function E(t){let n=(r=>{if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r))throw new Error(`Invalid email: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function L(t){let n=(r=>{let e=Number(r);if(isNaN(e)||e<1||e>65535)throw new Error(`Invalid port: "${r}"`);return e});return t&&(n.default=t.default,n.optional=t.optional),n}function N(t){let n=(r=>{if(!r.startsWith("postgres://")&&!r.startsWith("postgresql://"))throw new Error(`Invalid PostgreSQL URL: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function U(t){let n=(r=>{if(!r.startsWith("mysql://"))throw new Error(`Invalid MySQL URL: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function D(t){let n=(r=>{if(!r.startsWith("mongodb://")&&!r.startsWith("mongodb+srv://"))throw new Error(`Invalid MongoDB URL: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function S(t){let n=(r=>{if(!r.startsWith("redis://")&&!r.startsWith("rediss://"))throw new Error(`Invalid Redis URL: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function M(t){let n=(r=>{if(!r.startsWith("https://"))throw new Error(`Invalid HTTPS URL: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function P(t){let n=(r=>{let e=t?.separator||",";return r.split(e).map(o=>o.trim()).filter(o=>o.length>0)});return t&&(n.default=t.default,n.optional=t.optional),n}function q(t){let n=(r=>{let e=t?.separator||",";return r.split(e).map(o=>{let a=Number(o.trim());if(isNaN(a))throw new Error(`Invalid number in array: "${o}"`);return a})});return t&&(n.default=t.default,n.optional=t.optional),n}function F(t){let n=(r=>{let e=t?.separator||",",o=r.split(e).map(a=>a.trim()).filter(a=>a.length>0);for(let a of o)try{new URL(a);}catch{throw new Error(`Invalid URL in array: "${a}"`)}return o});return t&&(n.default=t.default,n.optional=t.optional),n}function d(t,n){let r=(e=>{if(!t.includes(e))throw new Error(`Invalid value: "${e}". Allowed values: ${t.join(", ")}`);return e});return n&&(r.default=n.default,r.optional=n.optional),r}function A(t,n){return d(t,n)}function W(t){let n=[...t];return n.__optional=true,n}function _(t){let n=(r=>{let e=r.match(/^(\d+)([smhd])$/);if(!e)throw new Error(`Invalid duration: "${r}". Use format like "5s", "2m", "1h", "1d"`);let[,o,a]=e,l={s:1e3,m:6e4,h:36e5,d:864e5}[a];return Number(o)*l});return t&&(n.default=t.default,n.optional=t.optional),n}function Z(t){let n=(r=>{try{let e=a("fs"),{resolve:o}=a("path"),a$1=o(process.cwd(),r);return e.readFileSync(a$1,"utf8").trim()}catch(e){throw new Error(`Failed to read file: ${e instanceof Error?e.message:String(e)}`)}});return t&&(n.default=t.default,n.optional=t.optional,n.secretsDir=t.secretsDir),n.__isFileValidator=true,n}function Y(t){let n=(r=>r);return t&&(n.default=t.default,n.optional=t.optional),n}function z(t,n){let r=t;return n&&(r.default=n.default,r.optional=n.optional),r}function C(t){let n=(r=>{if(!/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?)?$/.test(r))throw new Error(`Date must be in ISO 8601 format: "${r}"`);let o=new Date(r);if(isNaN(o.getTime()))throw new Error(`Cannot parse date value: "${r}"`);return r});return t&&(n.default=t.default,n.optional=t.optional),n}function Q(t){let n=(r=>{let e=Number(r);if(isNaN(e)||!Number.isInteger(e))throw new Error(`Invalid timestamp: "${r}"`);if(e<0)throw new Error(`Invalid timestamp: "${r}"`);if(e>253402300799)throw new Error(`Timestamp too large: "${r}"`);return e});return t&&(n.default=t.default,n.optional=t.optional),n}
|
|
2
2
|
export{I as boolean,z as custom,C as date,_ as duration,E as email,A as enumOf,Z as file,k as http,M as https,V as json,D as mongodb,U as mysql,$ as number,q as numberArray,d as oneOf,W as optional,L as port,N as postgres,S as redis,Y as secret,y as string,P as stringArray,Q as timestamp,T as url,F as urlArray,R as validateBoolean,x as validateDate,b as validateDuration,m as validateEmail,h as validateFile,f as validateMongodb,p as validateMysql,O as validateNumber,w as validatePort,u as validatePostgres,c as validateRedis,v as validateTimestamp,g as validateUrl};
|
package/dist/web.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
\u{1F4A1} Only variables prefixed with '${e}' are allowed in client bundles.`);if(process.env.NODE_ENV==="development")throw n;return console.error(n.message),{}}let i={};for(let[n,c]of Object.entries(r))n.startsWith(e)&&(i[n]=c);let f=o.map(n=>[n,i]);return await
|
|
1
|
+
'use strict';var chunkZ3TI2YXP_cjs=require('./chunk-Z3TI2YXP.cjs'),chunkAYZL6CFC_cjs=require('./chunk-AYZL6CFC.cjs');require('./chunk-Y2QEFWEY.cjs'),require('./chunk-O7NR4K6A.cjs');var chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');require('./chunk-6D5APQIG.cjs'),require('./chunk-D6WM53FN.cjs');var h=()=>typeof globalThis.window<"u";async function u(r,v={}){let{resolvers:o=[chunk4QOKRJ3F_cjs.a()],clientPrefix:e="PUBLIC_",strict:m=true}=v,l=Object.keys(r).filter(n=>!n.startsWith(e));if(h()&&l.length>0){let n=new Error(`\u274C Server-only environment variables accessed in browser context: ${l.join(", ")}
|
|
2
|
+
\u{1F4A1} Only variables prefixed with '${e}' are allowed in client bundles.`);if(process.env.NODE_ENV==="development")throw n;return console.error(n.message),{}}let i={};for(let[n,c]of Object.entries(r))n.startsWith(e)&&(i[n]=c);let f=o.map(n=>[n,i]);return await chunkAYZL6CFC_cjs.b({resolvers:f,options:{strict:m}})}async function E(r,v={}){let{resolvers:o=[chunkZ3TI2YXP_cjs.a({expand:true}),chunk4QOKRJ3F_cjs.a()],clientPrefix:e="PUBLIC_",policies:m,interpolate:l,strict:i}=v,s=Object.keys(r.client).filter(t=>!t.startsWith(e));if(s.length>0)throw new Error(`\u274C Client environment variables must be prefixed with '${e}': ${s.join(", ")}
|
|
3
3
|
\u{1F4A1} Rename these variables to start with '${e}' (e.g., ${s[0]} \u2192 ${e}${s[0]})`);let c=Object.keys(r.server).filter(t=>t.startsWith(e));if(c.length>0)throw new Error(`\u274C Server environment variables should not be prefixed with '${e}': ${c.join(", ")}
|
|
4
|
-
\u{1F4A1} These variables will be exposed to the client. Move to client schema or remove prefix.`);let x=o.map(t=>[t,r.server]),T=await
|
|
4
|
+
\u{1F4A1} These variables will be exposed to the client. Move to client schema or remove prefix.`);let x=o.map(t=>[t,r.server]),T=await chunkAYZL6CFC_cjs.b({resolvers:x,options:{policies:m,interpolate:l,strict:i}}),d=o.map(t=>[t,r.client]),y=await chunkAYZL6CFC_cjs.b({resolvers:d,options:{strict:i}});return {server:T,client:y}}h()&&process.env.NODE_ENV==="development"&&console.warn(`\u{1F310} node-env-resolver/web: Running in browser context
|
|
5
5
|
Only variables with your configured prefix will be accessible
|
|
6
6
|
Server-only variables are blocked for security`);exports.resolveClientEnv=u;exports.resolveEnvSplit=E;
|
package/dist/web.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-
|
|
1
|
+
import {a as a$1}from'./chunk-27CQXH2M.js';import {b}from'./chunk-CH4V6URL.js';import'./chunk-5XUR34FH.js';import'./chunk-6EWR3WHU.js';import {a}from'./chunk-WKIPEKF6.js';import'./chunk-HHOS5S5T.js';import'./chunk-I7AUKTXE.js';var h=()=>typeof globalThis.window<"u";async function u(r,v={}){let{resolvers:o=[a()],clientPrefix:e="PUBLIC_",strict:m=true}=v,l=Object.keys(r).filter(n=>!n.startsWith(e));if(h()&&l.length>0){let n=new Error(`\u274C Server-only environment variables accessed in browser context: ${l.join(", ")}
|
|
2
2
|
\u{1F4A1} Only variables prefixed with '${e}' are allowed in client bundles.`);if(process.env.NODE_ENV==="development")throw n;return console.error(n.message),{}}let i={};for(let[n,c]of Object.entries(r))n.startsWith(e)&&(i[n]=c);let f=o.map(n=>[n,i]);return await b({resolvers:f,options:{strict:m}})}async function E(r,v={}){let{resolvers:o=[a$1({expand:true}),a()],clientPrefix:e="PUBLIC_",policies:m,interpolate:l,strict:i}=v,s=Object.keys(r.client).filter(t=>!t.startsWith(e));if(s.length>0)throw new Error(`\u274C Client environment variables must be prefixed with '${e}': ${s.join(", ")}
|
|
3
3
|
\u{1F4A1} Rename these variables to start with '${e}' (e.g., ${s[0]} \u2192 ${e}${s[0]})`);let c=Object.keys(r.server).filter(t=>t.startsWith(e));if(c.length>0)throw new Error(`\u274C Server environment variables should not be prefixed with '${e}': ${c.join(", ")}
|
|
4
4
|
\u{1F4A1} These variables will be exposed to the client. Move to client schema or remove prefix.`);let x=o.map(t=>[t,r.server]),T=await b({resolvers:x,options:{policies:m,interpolate:l,strict:i}}),d=o.map(t=>[t,r.client]),y=await b({resolvers:d,options:{strict:i}});return {server:T,client:y}}h()&&process.env.NODE_ENV==="development"&&console.warn(`\u{1F310} node-env-resolver/web: Running in browser context
|
package/dist/zod.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';require('./chunk-
|
|
1
|
+
'use strict';require('./chunk-Z3TI2YXP.cjs');var chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');require('./chunk-D6WM53FN.cjs');async function u(n,t,e){let s={};for(let o of n)try{let r=o.load?await o.load():{};s={...s,...r};}catch(r){if(e)throw new Error(`Resolver ${o.name} failed: ${r instanceof Error?r.message:r}`)}if(t)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,c)=>s[c]||"");return s}function f(n){if(!n||typeof n!="object")return [{path:[],message:"Validation failed",code:"unknown_error"}];let t=n;return !t.issues||!Array.isArray(t.issues)?[{path:[],message:"Validation failed",code:"unknown_error"}]:t.issues.map(e=>({path:e.path||[],message:e.message,code:e.code}))}async function v(n,t={}){let{resolvers:e=[chunk4QOKRJ3F_cjs.a()],interpolate:s=false,strict:o=true}=t,r=await u(e,s,o);return n.parse(r)}async function g(n,t={}){try{let{resolvers:e=[chunk4QOKRJ3F_cjs.a()],interpolate:s=!1,strict:o=!0}=t,r=await u(e,s,o),a=n.safeParse(r);if(a.success)return {success:!0,data:a.data};let c=f(a.error);return {success:!1,error:c.map(l=>l.message).join(", "),issues:c}}catch(e){return {success:false,error:e instanceof Error?e.message:String(e),issues:[{path:[],message:e instanceof Error?e.message:String(e),code:"resolver_error"}]}}}function p(n,t,e){let s={};for(let o of n)try{if(!o.loadSync){if(e)throw new Error(`Resolver ${o.name} does not support sync loading`);continue}let r=o.loadSync();s={...s,...r};}catch(r){if(e)throw new Error(`Resolver ${o.name} failed: ${r instanceof Error?r.message:r}`)}if(t)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,c)=>s[c]||"");return s}function h(n,t={}){let{resolvers:e=[chunk4QOKRJ3F_cjs.a()],interpolate:s=false,strict:o=true}=t,r=p(e,s,o);return n.parse(r)}function y(n,t={}){try{let{resolvers:e=[chunk4QOKRJ3F_cjs.a()],interpolate:s=!1,strict:o=!0}=t,r=p(e,s,o),a=n.safeParse(r);if(a.success)return {success:!0,data:a.data};let c=f(a.error);return {success:!1,error:c.map(l=>l.message).join(", "),issues:c}}catch(e){return {success:false,error:e instanceof Error?e.message:String(e),issues:[{path:[],message:e instanceof Error?e.message:String(e),code:"resolver_error"}]}}}exports.resolveSyncZod=h;exports.resolveZod=v;exports.safeResolveSyncZod=y;exports.safeResolveZod=g;
|
package/dist/zod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import'./chunk-
|
|
1
|
+
import'./chunk-27CQXH2M.js';import {a}from'./chunk-WKIPEKF6.js';import'./chunk-I7AUKTXE.js';async function u(n,t,e){let s={};for(let o of n)try{let r=o.load?await o.load():{};s={...s,...r};}catch(r){if(e)throw new Error(`Resolver ${o.name} failed: ${r instanceof Error?r.message:r}`)}if(t)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,c)=>s[c]||"");return s}function f(n){if(!n||typeof n!="object")return [{path:[],message:"Validation failed",code:"unknown_error"}];let t=n;return !t.issues||!Array.isArray(t.issues)?[{path:[],message:"Validation failed",code:"unknown_error"}]:t.issues.map(e=>({path:e.path||[],message:e.message,code:e.code}))}async function v(n,t={}){let{resolvers:e=[a()],interpolate:s=false,strict:o=true}=t,r=await u(e,s,o);return n.parse(r)}async function g(n,t={}){try{let{resolvers:e=[a()],interpolate:s=!1,strict:o=!0}=t,r=await u(e,s,o),a$1=n.safeParse(r);if(a$1.success)return {success:!0,data:a$1.data};let c=f(a$1.error);return {success:!1,error:c.map(l=>l.message).join(", "),issues:c}}catch(e){return {success:false,error:e instanceof Error?e.message:String(e),issues:[{path:[],message:e instanceof Error?e.message:String(e),code:"resolver_error"}]}}}function p(n,t,e){let s={};for(let o of n)try{if(!o.loadSync){if(e)throw new Error(`Resolver ${o.name} does not support sync loading`);continue}let r=o.loadSync();s={...s,...r};}catch(r){if(e)throw new Error(`Resolver ${o.name} failed: ${r instanceof Error?r.message:r}`)}if(t)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,c)=>s[c]||"");return s}function h(n,t={}){let{resolvers:e=[a()],interpolate:s=false,strict:o=true}=t,r=p(e,s,o);return n.parse(r)}function y(n,t={}){try{let{resolvers:e=[a()],interpolate:s=!1,strict:o=!0}=t,r=p(e,s,o),a$1=n.safeParse(r);if(a$1.success)return {success:!0,data:a$1.data};let c=f(a$1.error);return {success:!1,error:c.map(l=>l.message).join(", "),issues:c}}catch(e){return {success:false,error:e instanceof Error?e.message:String(e),issues:[{path:[],message:e instanceof Error?e.message:String(e),code:"resolver_error"}]}}}export{h as resolveSyncZod,v as resolveZod,y as safeResolveSyncZod,g as safeResolveZod};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-env-resolver",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"description": "Type-safe environment variable resolver with async resolvers - lightweight, tree-shakeable, no dependencies",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -79,6 +79,43 @@
|
|
|
79
79
|
"default": "./dist/types.js"
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
|
+
"typesVersions": {
|
|
83
|
+
"*": {
|
|
84
|
+
"resolvers": [
|
|
85
|
+
"./dist/resolvers.d.ts"
|
|
86
|
+
],
|
|
87
|
+
"validators": [
|
|
88
|
+
"./dist/validators.d.ts"
|
|
89
|
+
],
|
|
90
|
+
"utils": [
|
|
91
|
+
"./dist/utils.d.ts"
|
|
92
|
+
],
|
|
93
|
+
"builder": [
|
|
94
|
+
"./dist/builder.d.ts"
|
|
95
|
+
],
|
|
96
|
+
"zod": [
|
|
97
|
+
"./dist/zod.d.ts"
|
|
98
|
+
],
|
|
99
|
+
"valibot": [
|
|
100
|
+
"./dist/valibot.d.ts"
|
|
101
|
+
],
|
|
102
|
+
"web": [
|
|
103
|
+
"./dist/web.d.ts"
|
|
104
|
+
],
|
|
105
|
+
"cli": [
|
|
106
|
+
"./dist/cli.d.ts"
|
|
107
|
+
],
|
|
108
|
+
"audit": [
|
|
109
|
+
"./dist/audit.d.ts"
|
|
110
|
+
],
|
|
111
|
+
"resolver": [
|
|
112
|
+
"./dist/resolver.d.ts"
|
|
113
|
+
],
|
|
114
|
+
"types": [
|
|
115
|
+
"./dist/types.d.ts"
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
},
|
|
82
119
|
"files": [
|
|
83
120
|
"dist",
|
|
84
121
|
"README.md"
|
|
@@ -113,6 +150,11 @@
|
|
|
113
150
|
"url": "https://jagreehal.com"
|
|
114
151
|
},
|
|
115
152
|
"license": "MIT",
|
|
153
|
+
"repository": {
|
|
154
|
+
"type": "git",
|
|
155
|
+
"url": "https://github.com/jagreehal/node-env-resolver.git",
|
|
156
|
+
"directory": "packages/node-env-resolver"
|
|
157
|
+
},
|
|
116
158
|
"sideEffects": false,
|
|
117
159
|
"publishConfig": {
|
|
118
160
|
"access": "public"
|
|
@@ -121,16 +163,16 @@
|
|
|
121
163
|
"node": ">=18"
|
|
122
164
|
},
|
|
123
165
|
"devDependencies": {
|
|
124
|
-
"@eslint/js": "^9.39.
|
|
125
|
-
"@types/node": "^
|
|
126
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
127
|
-
"@typescript-eslint/parser": "^8.
|
|
128
|
-
"eslint": "^9.39.
|
|
166
|
+
"@eslint/js": "^9.39.2",
|
|
167
|
+
"@types/node": "^25.0.2",
|
|
168
|
+
"@typescript-eslint/eslint-plugin": "^8.50.0",
|
|
169
|
+
"@typescript-eslint/parser": "^8.50.0",
|
|
170
|
+
"eslint": "^9.39.2",
|
|
129
171
|
"eslint-config-prettier": "^10.1.8",
|
|
130
172
|
"eslint-plugin-import-zod": "^1.2.1",
|
|
131
|
-
"prettier": "^3.
|
|
173
|
+
"prettier": "^3.7.4",
|
|
132
174
|
"tsup": "^8.5.1",
|
|
133
175
|
"typescript": "^5.9.3",
|
|
134
|
-
"vitest": "^4.0.
|
|
176
|
+
"vitest": "^4.0.15"
|
|
135
177
|
}
|
|
136
178
|
}
|
package/dist/chunk-4ZOF2PI4.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';var chunkKIQXH265_cjs=require('./chunk-KIQXH265.cjs');var g={};chunkKIQXH265_cjs.c(g,{attachAuditSession:()=>d,clearAuditLog:()=>c,getAuditLog:()=>a,logAuditEvent:()=>u});function d(t){let n=Date.now().toString(36)+Math.random().toString(36).substring(2,9);return o.set(t,n),n}function u(t){e.push(t),e.length>1e3&&e.shift();}function a(t){if(!t)return [...e];let n=o.get(t);return n?e.filter(i=>i.sessionId===n):[]}function c(){e.length=0;}var e,o,p=chunkKIQXH265_cjs.b(()=>{e=[],o=new WeakMap;});exports.a=d;exports.b=u;exports.c=a;exports.d=c;exports.e=g;exports.f=p;
|
package/dist/chunk-4ZYJXIBG.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {f,e}from'./chunk-YOHHFBZN.js';import {d}from'./chunk-5PELJRUQ.js';import {join,resolve}from'path';import {readFileSync}from'fs';function C(s,l){try{let t=resolve(process.cwd(),s);return {valid:!0,value:readFileSync(t,"utf8").trim()}}catch(t){return {valid:false,error:`Failed to read file${l?` for ${l}`:""}: ${t instanceof Error?t.message:String(t)}`}}}var D=null,h=null;async function E(s){if(!D){let l=await import('./audit.js');D=l.logAuditEvent,h=l.attachAuditSession;}D(s);}function b(s){if(!D)try{let l=(f(),d(e));D=l.logAuditEvent,h=l.attachAuditSession;}catch{return}D&&D(s);}function U(s){let l={};for(let[t,o]of Object.entries(s))if(typeof o=="function"){let a=o,r=a.__isFileValidator===true;l[t]={type:r?"file":"custom",validator:o,...a.default!==void 0&&{default:a.default},...a.optional!==void 0&&{optional:a.optional},...a.secretsDir!==void 0&&{secretsDir:a.secretsDir}};}else if(typeof o=="string")l[t]={type:"string",default:o,validator:a=>{if(a===""&&!l[t].allowEmpty)throw new Error("String cannot be empty");return a}};else if(typeof o=="number")l[t]={type:"number",default:o,validator:a=>{let r=Number(a);if(isNaN(r))throw new Error(`Invalid number: "${a}"`);return r}};else if(typeof o=="boolean")l[t]={type:"boolean",default:o,validator:a=>{let r=a.toLowerCase();if(["true","1","yes","on"].includes(r))return true;if(["false","0","no","off",""].includes(r))return false;throw new Error(`Invalid boolean: "${a}"`)}};else if(Array.isArray(o)){let a=o.map(String),r=o.__optional===true;l[t]={type:"string",enum:a,optional:r,validator:(m,n)=>{if(!a.includes(m)){let i=n||t;throw new Error(`${i} must be one of: ${a.join(", ")}`)}return m}};}else l[t]=o;return l}function L(s,l){return s.replace(/\$\{([^}]+)\}/g,(t,o)=>l[o]||t)}async function B(s,l,t,o="last",a){let r={},m={};if(o==="last"){let n=await Promise.allSettled(s.map(async i=>({resolver:i,env:i.load?await i.load():{}})));for(let i of n){if(i.status==="rejected"){let u=i.reason;if(await E({type:"resolver_error",timestamp:Date.now(),source:"unknown",error:u instanceof Error?u.message:String(u)}),t)throw new Error(`Resolver failed: ${u instanceof Error?u.message:u}`);continue}let{resolver:d,env:f}=i.value;for(let[u,y]of Object.entries(f))y!==void 0&&(r[u]=y,m[u]={source:d.name||"unknown",timestamp:Date.now(),...d.metadata?.cached!==void 0&&{cached:!!d.metadata.cached}});}}else for(let n of s)try{let i=n.load?await n.load():{};for(let[d,f]of Object.entries(i))if(f!==void 0){if(r[d]!==void 0)continue;r[d]=f,m[d]={source:n.name||"unknown",timestamp:Date.now(),...n.metadata?.cached!==void 0&&{cached:!!n.metadata.cached}};}if(a&&a.size>0&&Array.from(a).every(f=>r[f]!==void 0))break}catch(i){if(await E({type:"resolver_error",timestamp:Date.now(),source:n.name,error:i instanceof Error?i.message:String(i)}),t)throw new Error(`Resolver ${n.name} failed: ${i instanceof Error?i.message:i}`)}if(l)for(let[n,i]of Object.entries(r))r[n]=L(i,r);return {mergedEnv:r,provenance:m}}function M(s,l,t,o="last",a){let r={},m={};for(let n of s)try{if(!n.loadSync){if(t)throw new Error(`Resolver ${n.name} has no loadSync() method`);continue}let i=n.loadSync();for(let[d,f]of Object.entries(i))if(f!==void 0){if(o==="first"&&r[d]!==void 0)continue;r[d]=f,m[d]={source:n.name||"unknown",timestamp:Date.now(),...n.metadata?.cached!==void 0&&{cached:!!n.metadata.cached}};}if(o==="first"&&a&&a.size>0&&Array.from(a).every(f=>r[f]!==void 0))break}catch(i){if(b({type:"resolver_error",timestamp:Date.now(),source:n.name,error:i instanceof Error?i.message:String(i)}),t)throw new Error(`Resolver ${n.name} failed: ${i instanceof Error?i.message:i}`)}if(l)for(let[n,i]of Object.entries(r))r[n]=L(i,r);return {mergedEnv:r,provenance:m}}function T(s,l,t,o){if(!o)return null;if((process.env.NODE_ENV||"").toLowerCase()==="production"&&t&&t.source.startsWith("dotenv(")){let r=o.allowDotenvInProduction;return r===true?null:Array.isArray(r)?r.includes(s)?null:`${s} cannot be sourced from .env files in production. Use process.env or cloud resolvers. To allow: policies.allowDotenvInProduction: ['${s}'] or set to true for all.`:`${s} cannot be sourced from .env files in production (secure default). Production platforms (Vercel, AWS, etc.) use process.env. To allow .env in production: policies.allowDotenvInProduction: true`}if(o.enforceAllowedSources&&o.enforceAllowedSources[s]&&t){let r=o.enforceAllowedSources[s];if(!r.includes(t.source))return `${s} must be sourced from one of: ${r.join(", ")} (actual: ${t.source})`}return null}function x(s){let l=[],t=/^[A-Za-z_][A-Za-z0-9_]*$/;for(let o of Object.keys(s))t.test(o)||l.push(`Invalid environment variable name: "${o}". Environment variable names must contain only letters, numbers, and underscores, and cannot start with a number.`);return l}function z(s,l){let t={};for(let[o,a]of Object.entries(s)){if(!o.includes(l)){t[o]=a;continue}let r=o.split(l),m=t;for(let i=0;i<r.length-1;i++){let d=r[i].toLowerCase();d in m||(m[d]={}),m=m[d];}let n=r[r.length-1].toLowerCase();m[n]=a;}return t}async function G(s,l,t){let o=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:a=false,strict:r=true,policies:m,enableAudit:n=o,priority:i="last",secretsDir:d}=t,f={},u;if(n){if(!h){let e=await import('./audit.js');D=e.logAuditEvent,h=e.attachAuditSession;}h&&(u=h(f));}let y=x(s);if(y.length>0)throw n&&await E({type:"validation_failure",timestamp:Date.now(),error:`Invalid environment variable names: ${y.join(", ")}`,sessionId:u}),new Error(`Environment validation failed:
|
|
2
|
-
${y.map(e=>` - ${e}`).join(`
|
|
3
|
-
`)}`);let k=new Set(Object.keys(s)),{mergedEnv:A,provenance:w}=await B(l,a,r,i,k),g=[];for(let[e,_]of Object.entries(s)){let p=_,$=A[e],S=T(e,p,w[e],m);if(S){g.push(S),n&&E({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:S,sessionId:u});continue}try{let c;if($===void 0){let v=p.secretsDir??d;if(p.type==="file"&&v){let j=e.toLowerCase().replace(/_/g,"-"),P=join(v,j),R=C(P,e);R.valid?(c={success:!0,value:R.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):c={success:!1,error:R.error??`Failed to read secret for ${e}`};}else p.default!==void 0?c={success:!0,value:p.default}:p.optional?c={success:!0,value:void 0}:c={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{c={success:!0,value:p.validator($,e)};}catch(v){c={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else c={success:!0,value:$};c.success?(f[e]=c.value,n&&await E({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(c.error),n&&await E({type:"validation_failure",timestamp:Date.now(),key:e,error:c.error,sessionId:u}));}catch(c){let v=c instanceof Error?c.message:String(c);g.push(`${e}: ${v}`),n&&await E({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw n&&await E({type:"validation_failure",timestamp:Date.now(),error:`${g.length} validation error(s)`,metadata:{errorCount:g.length},sessionId:u}),new Error(`Environment validation failed:
|
|
4
|
-
${g.map(e=>` - ${e}`).join(`
|
|
5
|
-
`)}`);return n&&await E({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(s).length},sessionId:u}),t.nestedDelimiter?z(f,t.nestedDelimiter):f}function H(s,l,t){let o=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:a=false,strict:r=true,policies:m,enableAudit:n=o,priority:i="last",secretsDir:d$1}=t,f$1={},u;if(n){if(!h)try{let e$1=(f(),d(e));D=e$1.logAuditEvent,h=e$1.attachAuditSession;}catch{}h&&(u=h(f$1));}let y=x(s);if(y.length>0)throw n&&b({type:"validation_failure",timestamp:Date.now(),error:`Invalid environment variable names: ${y.join(", ")}`,sessionId:u}),new Error(`Environment validation failed:
|
|
6
|
-
${y.map(e=>` - ${e}`).join(`
|
|
7
|
-
`)}`);let k=new Set(Object.keys(s)),{mergedEnv:A,provenance:w}=M(l,a,r,i,k),g=[];for(let[e,_]of Object.entries(s)){let p=_,$=A[e],S=T(e,p,w[e],m);if(S){g.push(S),n&&b({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:S,sessionId:u});continue}try{let c;if($===void 0){let v=p.secretsDir??d$1;if(p.type==="file"&&v){let j=e.toLowerCase().replace(/_/g,"-"),P=join(v,j),R=C(P,e);R.valid?(c={success:!0,value:R.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):c={success:!1,error:R.error??`Failed to read secret for ${e}`};}else p.default!==void 0?c={success:!0,value:p.default}:p.optional?c={success:!0,value:void 0}:c={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{c={success:!0,value:p.validator($,e)};}catch(v){c={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else c={success:!0,value:$};c.success?(f$1[e]=c.value,n&&b({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(c.error),n&&b({type:"validation_failure",timestamp:Date.now(),key:e,error:c.error,sessionId:u}));}catch(c){let v=c instanceof Error?c.message:String(c);g.push(`${e}: ${v}`),n&&b({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw n&&b({type:"validation_failure",timestamp:Date.now(),error:`${g.length} validation error(s)`,metadata:{errorCount:g.length},sessionId:u}),new Error(`Environment validation failed:
|
|
8
|
-
${g.map(e=>` - ${e}`).join(`
|
|
9
|
-
`)}`);return n&&b({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(s).length},sessionId:u}),t.nestedDelimiter?z(f$1,t.nestedDelimiter):f$1}export{U as a,G as b,H as c};
|
package/dist/chunk-5PELJRUQ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var k=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var l=(a,b)=>()=>(a&&(b=a(a=0)),b);var m=(a,b)=>{for(var c in b)e(a,c,{get:b[c],enumerable:true});},j=(a,b,c,f)=>{if(b&&typeof b=="object"||typeof b=="function")for(let d of h(b))!i.call(a,d)&&d!==c&&e(a,d,{get:()=>b[d],enumerable:!(f=g(b,d))||f.enumerable});return a};var n=a=>j(e({},"__esModule",{value:true}),a);export{k as a,l as b,m as c,n as d};
|
package/dist/chunk-KIQXH265.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';var e=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var k=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var l=(a,b)=>()=>(a&&(b=a(a=0)),b);var m=(a,b)=>{for(var c in b)e(a,c,{get:b[c],enumerable:true});},j=(a,b,c,f)=>{if(b&&typeof b=="object"||typeof b=="function")for(let d of h(b))!i.call(a,d)&&d!==c&&e(a,d,{get:()=>b[d],enumerable:!(f=g(b,d))||f.enumerable});return a};var n=a=>j(e({},"__esModule",{value:true}),a);exports.a=k;exports.b=l;exports.c=m;exports.d=n;
|
package/dist/chunk-RQBTOG2W.cjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
'use strict';var chunk4ZOF2PI4_cjs=require('./chunk-4ZOF2PI4.cjs'),chunkKIQXH265_cjs=require('./chunk-KIQXH265.cjs'),path=require('path'),fs=require('fs');function C(s,l){try{let t=path.resolve(process.cwd(),s);return {valid:!0,value:fs.readFileSync(t,"utf8").trim()}}catch(t){return {valid:false,error:`Failed to read file${l?` for ${l}`:""}: ${t instanceof Error?t.message:String(t)}`}}}var D=null,h=null;async function E(s){if(!D){let l=await import('./audit.cjs');D=l.logAuditEvent,h=l.attachAuditSession;}D(s);}function b(s){if(!D)try{let l=(chunk4ZOF2PI4_cjs.f(),chunkKIQXH265_cjs.d(chunk4ZOF2PI4_cjs.e));D=l.logAuditEvent,h=l.attachAuditSession;}catch{return}D&&D(s);}function U(s){let l={};for(let[t,o]of Object.entries(s))if(typeof o=="function"){let a=o,r=a.__isFileValidator===true;l[t]={type:r?"file":"custom",validator:o,...a.default!==void 0&&{default:a.default},...a.optional!==void 0&&{optional:a.optional},...a.secretsDir!==void 0&&{secretsDir:a.secretsDir}};}else if(typeof o=="string")l[t]={type:"string",default:o,validator:a=>{if(a===""&&!l[t].allowEmpty)throw new Error("String cannot be empty");return a}};else if(typeof o=="number")l[t]={type:"number",default:o,validator:a=>{let r=Number(a);if(isNaN(r))throw new Error(`Invalid number: "${a}"`);return r}};else if(typeof o=="boolean")l[t]={type:"boolean",default:o,validator:a=>{let r=a.toLowerCase();if(["true","1","yes","on"].includes(r))return true;if(["false","0","no","off",""].includes(r))return false;throw new Error(`Invalid boolean: "${a}"`)}};else if(Array.isArray(o)){let a=o.map(String),r=o.__optional===true;l[t]={type:"string",enum:a,optional:r,validator:(m,n)=>{if(!a.includes(m)){let i=n||t;throw new Error(`${i} must be one of: ${a.join(", ")}`)}return m}};}else l[t]=o;return l}function L(s,l){return s.replace(/\$\{([^}]+)\}/g,(t,o)=>l[o]||t)}async function B(s,l,t,o="last",a){let r={},m={};if(o==="last"){let n=await Promise.allSettled(s.map(async i=>({resolver:i,env:i.load?await i.load():{}})));for(let i of n){if(i.status==="rejected"){let u=i.reason;if(await E({type:"resolver_error",timestamp:Date.now(),source:"unknown",error:u instanceof Error?u.message:String(u)}),t)throw new Error(`Resolver failed: ${u instanceof Error?u.message:u}`);continue}let{resolver:d,env:f}=i.value;for(let[u,y]of Object.entries(f))y!==void 0&&(r[u]=y,m[u]={source:d.name||"unknown",timestamp:Date.now(),...d.metadata?.cached!==void 0&&{cached:!!d.metadata.cached}});}}else for(let n of s)try{let i=n.load?await n.load():{};for(let[d,f]of Object.entries(i))if(f!==void 0){if(r[d]!==void 0)continue;r[d]=f,m[d]={source:n.name||"unknown",timestamp:Date.now(),...n.metadata?.cached!==void 0&&{cached:!!n.metadata.cached}};}if(a&&a.size>0&&Array.from(a).every(f=>r[f]!==void 0))break}catch(i){if(await E({type:"resolver_error",timestamp:Date.now(),source:n.name,error:i instanceof Error?i.message:String(i)}),t)throw new Error(`Resolver ${n.name} failed: ${i instanceof Error?i.message:i}`)}if(l)for(let[n,i]of Object.entries(r))r[n]=L(i,r);return {mergedEnv:r,provenance:m}}function M(s,l,t,o="last",a){let r={},m={};for(let n of s)try{if(!n.loadSync){if(t)throw new Error(`Resolver ${n.name} has no loadSync() method`);continue}let i=n.loadSync();for(let[d,f]of Object.entries(i))if(f!==void 0){if(o==="first"&&r[d]!==void 0)continue;r[d]=f,m[d]={source:n.name||"unknown",timestamp:Date.now(),...n.metadata?.cached!==void 0&&{cached:!!n.metadata.cached}};}if(o==="first"&&a&&a.size>0&&Array.from(a).every(f=>r[f]!==void 0))break}catch(i){if(b({type:"resolver_error",timestamp:Date.now(),source:n.name,error:i instanceof Error?i.message:String(i)}),t)throw new Error(`Resolver ${n.name} failed: ${i instanceof Error?i.message:i}`)}if(l)for(let[n,i]of Object.entries(r))r[n]=L(i,r);return {mergedEnv:r,provenance:m}}function T(s,l,t,o){if(!o)return null;if((process.env.NODE_ENV||"").toLowerCase()==="production"&&t&&t.source.startsWith("dotenv(")){let r=o.allowDotenvInProduction;return r===true?null:Array.isArray(r)?r.includes(s)?null:`${s} cannot be sourced from .env files in production. Use process.env or cloud resolvers. To allow: policies.allowDotenvInProduction: ['${s}'] or set to true for all.`:`${s} cannot be sourced from .env files in production (secure default). Production platforms (Vercel, AWS, etc.) use process.env. To allow .env in production: policies.allowDotenvInProduction: true`}if(o.enforceAllowedSources&&o.enforceAllowedSources[s]&&t){let r=o.enforceAllowedSources[s];if(!r.includes(t.source))return `${s} must be sourced from one of: ${r.join(", ")} (actual: ${t.source})`}return null}function x(s){let l=[],t=/^[A-Za-z_][A-Za-z0-9_]*$/;for(let o of Object.keys(s))t.test(o)||l.push(`Invalid environment variable name: "${o}". Environment variable names must contain only letters, numbers, and underscores, and cannot start with a number.`);return l}function z(s,l){let t={};for(let[o,a]of Object.entries(s)){if(!o.includes(l)){t[o]=a;continue}let r=o.split(l),m=t;for(let i=0;i<r.length-1;i++){let d=r[i].toLowerCase();d in m||(m[d]={}),m=m[d];}let n=r[r.length-1].toLowerCase();m[n]=a;}return t}async function G(s,l,t){let o=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:a=false,strict:r=true,policies:m,enableAudit:n=o,priority:i="last",secretsDir:d}=t,f={},u;if(n){if(!h){let e=await import('./audit.cjs');D=e.logAuditEvent,h=e.attachAuditSession;}h&&(u=h(f));}let y=x(s);if(y.length>0)throw n&&await E({type:"validation_failure",timestamp:Date.now(),error:`Invalid environment variable names: ${y.join(", ")}`,sessionId:u}),new Error(`Environment validation failed:
|
|
2
|
-
${y.map(e=>` - ${e}`).join(`
|
|
3
|
-
`)}`);let k=new Set(Object.keys(s)),{mergedEnv:A,provenance:w}=await B(l,a,r,i,k),g=[];for(let[e,_]of Object.entries(s)){let p=_,$=A[e],S=T(e,p,w[e],m);if(S){g.push(S),n&&E({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:S,sessionId:u});continue}try{let c;if($===void 0){let v=p.secretsDir??d;if(p.type==="file"&&v){let j=e.toLowerCase().replace(/_/g,"-"),P=path.join(v,j),R=C(P,e);R.valid?(c={success:!0,value:R.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):c={success:!1,error:R.error??`Failed to read secret for ${e}`};}else p.default!==void 0?c={success:!0,value:p.default}:p.optional?c={success:!0,value:void 0}:c={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{c={success:!0,value:p.validator($,e)};}catch(v){c={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else c={success:!0,value:$};c.success?(f[e]=c.value,n&&await E({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(c.error),n&&await E({type:"validation_failure",timestamp:Date.now(),key:e,error:c.error,sessionId:u}));}catch(c){let v=c instanceof Error?c.message:String(c);g.push(`${e}: ${v}`),n&&await E({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw n&&await E({type:"validation_failure",timestamp:Date.now(),error:`${g.length} validation error(s)`,metadata:{errorCount:g.length},sessionId:u}),new Error(`Environment validation failed:
|
|
4
|
-
${g.map(e=>` - ${e}`).join(`
|
|
5
|
-
`)}`);return n&&await E({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(s).length},sessionId:u}),t.nestedDelimiter?z(f,t.nestedDelimiter):f}function H(s,l,t){let o=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:a=false,strict:r=true,policies:m,enableAudit:n=o,priority:i="last",secretsDir:d}=t,f={},u;if(n){if(!h)try{let e=(chunk4ZOF2PI4_cjs.f(),chunkKIQXH265_cjs.d(chunk4ZOF2PI4_cjs.e));D=e.logAuditEvent,h=e.attachAuditSession;}catch{}h&&(u=h(f));}let y=x(s);if(y.length>0)throw n&&b({type:"validation_failure",timestamp:Date.now(),error:`Invalid environment variable names: ${y.join(", ")}`,sessionId:u}),new Error(`Environment validation failed:
|
|
6
|
-
${y.map(e=>` - ${e}`).join(`
|
|
7
|
-
`)}`);let k=new Set(Object.keys(s)),{mergedEnv:A,provenance:w}=M(l,a,r,i,k),g=[];for(let[e,_]of Object.entries(s)){let p=_,$=A[e],S=T(e,p,w[e],m);if(S){g.push(S),n&&b({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:S,sessionId:u});continue}try{let c;if($===void 0){let v=p.secretsDir??d;if(p.type==="file"&&v){let j=e.toLowerCase().replace(/_/g,"-"),P=path.join(v,j),R=C(P,e);R.valid?(c={success:!0,value:R.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):c={success:!1,error:R.error??`Failed to read secret for ${e}`};}else p.default!==void 0?c={success:!0,value:p.default}:p.optional?c={success:!0,value:void 0}:c={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{c={success:!0,value:p.validator($,e)};}catch(v){c={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else c={success:!0,value:$};c.success?(f[e]=c.value,n&&b({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(c.error),n&&b({type:"validation_failure",timestamp:Date.now(),key:e,error:c.error,sessionId:u}));}catch(c){let v=c instanceof Error?c.message:String(c);g.push(`${e}: ${v}`),n&&b({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw n&&b({type:"validation_failure",timestamp:Date.now(),error:`${g.length} validation error(s)`,metadata:{errorCount:g.length},sessionId:u}),new Error(`Environment validation failed:
|
|
8
|
-
${g.map(e=>` - ${e}`).join(`
|
|
9
|
-
`)}`);return n&&b({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(s).length},sessionId:u}),t.nestedDelimiter?z(f,t.nestedDelimiter):f}exports.a=U;exports.b=G;exports.c=H;
|
package/dist/chunk-YOHHFBZN.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import {c as c$1,b}from'./chunk-5PELJRUQ.js';var g={};c$1(g,{attachAuditSession:()=>d,clearAuditLog:()=>c,getAuditLog:()=>a,logAuditEvent:()=>u});function d(t){let n=Date.now().toString(36)+Math.random().toString(36).substring(2,9);return o.set(t,n),n}function u(t){e.push(t),e.length>1e3&&e.shift();}function a(t){if(!t)return [...e];let n=o.get(t);return n?e.filter(i=>i.sessionId===n):[]}function c(){e.length=0;}var e,o,p=b(()=>{e=[],o=new WeakMap;});export{d as a,u as b,a as c,c as d,g as e,p as f};
|