node-env-resolver 0.0.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +221 -85
  2. package/dist/audit.d.ts +16 -0
  3. package/dist/audit.d.ts.map +1 -0
  4. package/dist/audit.js +1 -0
  5. package/dist/audit.test.d.ts +2 -0
  6. package/dist/audit.test.d.ts.map +1 -0
  7. package/dist/builder.d.ts +146 -0
  8. package/dist/builder.d.ts.map +1 -0
  9. package/dist/builder.js +1 -0
  10. package/dist/composition.test.d.ts +7 -0
  11. package/dist/composition.test.d.ts.map +1 -0
  12. package/dist/index.d.ts +99 -4
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +5 -20
  15. package/dist/index.test.d.ts +2 -0
  16. package/dist/index.test.d.ts.map +1 -0
  17. package/dist/providers.d.ts +11 -0
  18. package/dist/providers.d.ts.map +1 -0
  19. package/dist/resolver.d.ts +17 -0
  20. package/dist/resolver.d.ts.map +1 -0
  21. package/dist/resolver.js +5 -0
  22. package/dist/resolvers.d.ts +11 -0
  23. package/dist/resolvers.d.ts.map +1 -0
  24. package/dist/resolvers.js +3 -0
  25. package/dist/standard-schema.d.ts +32 -0
  26. package/dist/standard-schema.d.ts.map +1 -0
  27. package/dist/standard-schema.js +3 -0
  28. package/dist/type-override.test.d.ts +2 -0
  29. package/dist/type-override.test.d.ts.map +1 -0
  30. package/dist/types.d.ts +66 -0
  31. package/dist/types.d.ts.map +1 -0
  32. package/dist/types.js +0 -0
  33. package/dist/utils.d.ts +41 -0
  34. package/dist/utils.d.ts.map +1 -0
  35. package/dist/utils.js +1 -0
  36. package/dist/utils.test.d.ts +2 -0
  37. package/dist/utils.test.d.ts.map +1 -0
  38. package/dist/validators.d.ts +68 -0
  39. package/dist/validators.d.ts.map +1 -0
  40. package/dist/validators.js +1 -0
  41. package/dist/web.d.ts +51 -0
  42. package/dist/web.d.ts.map +1 -0
  43. package/dist/web.js +6 -0
  44. package/dist/zod.d.ts +51 -0
  45. package/dist/zod.d.ts.map +1 -0
  46. package/dist/zod.js +1 -0
  47. package/package.json +88 -28
  48. package/dist/chunk-AST3HVOG.js +0 -148
  49. package/dist/chunk-UQYMDWOU.js +0 -13
  50. package/dist/chunk-XC5PWSNR.js +0 -37
  51. package/dist/esm/chunk-AST3HVOG.js +0 -144
  52. package/dist/esm/chunk-UQYMDWOU.js +0 -11
  53. package/dist/esm/chunk-XC5PWSNR.js +0 -35
  54. package/dist/esm/index.js +0 -3
  55. package/dist/esm/resolve.js +0 -2
  56. package/dist/esm/resolveZod.js +0 -2
  57. package/dist/index-6c4171f8.d.ts +0 -27
  58. package/dist/resolve.d.ts +0 -6
  59. package/dist/resolve.js +0 -15
  60. package/dist/resolveZod.d.ts +0 -7
  61. package/dist/resolveZod.js +0 -15
package/dist/zod.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Zod integration for node-env-resolver
3
+ * Import from 'node-env-resolver/zod' to use this
4
+ */
5
+ import { type Resolver, type PolicyOptions } from './index.js';
6
+ export type InferZodOutput<T> = T extends {
7
+ parse: (input: unknown) => infer R;
8
+ } ? R : never;
9
+ /**
10
+ * Convert a Zod schema to Standard Schema format
11
+ */
12
+ export declare function zodToStandardSchema<T extends {
13
+ safeParseAsync: (input: unknown) => Promise<{
14
+ success: boolean;
15
+ data?: unknown;
16
+ error?: {
17
+ issues: Array<{
18
+ message: string;
19
+ path: unknown[];
20
+ }>;
21
+ };
22
+ }>;
23
+ }>(zodSchema: T): {
24
+ '~standard': {
25
+ version: 1;
26
+ vendor: string;
27
+ validate: (value: unknown) => Promise<{
28
+ value: unknown;
29
+ issues?: undefined;
30
+ } | {
31
+ issues: {
32
+ message: string;
33
+ path: unknown[];
34
+ }[];
35
+ value?: undefined;
36
+ }>;
37
+ types: {
38
+ input: unknown;
39
+ output: InferZodOutput<T>;
40
+ };
41
+ };
42
+ };
43
+ export declare function resolveEnvWithZod<TSchema extends {
44
+ parse: (input: unknown) => unknown;
45
+ }>(zodSchema: TSchema, options?: {
46
+ resolvers?: Resolver[];
47
+ interpolate?: boolean;
48
+ strict?: boolean;
49
+ policies?: PolicyOptions;
50
+ }): Promise<InferZodOutput<TSchema>>;
51
+ //# sourceMappingURL=zod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACO,KAAK,QAAQ,EAAE,KAAK,aAAa,EAC9C,MAAM,YAAY,CAAC;AAqBpB,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAE7F;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS;IAAE,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE;YAAE,MAAM,EAAE,KAAK,CAAC;gBAAE,OAAO,EAAE,MAAM,CAAC;gBAAC,IAAI,EAAE,OAAO,EAAE,CAAA;aAAE,CAAC,CAAA;SAAE,CAAA;KAAE,CAAC,CAAA;CAAE,EAAE,SAAS,EAAE,CAAC;;;;0BAKpL,OAAO;;;;;;;;;;;mBAgBhB,OAAO;oBACN,cAAc,CAAC,CAAC,CAAC;;;EAItC;AAED,wBAAsB,iBAAiB,CAAC,OAAO,SAAS;IAAE,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAA;CAAE,EAC5F,SAAS,EAAE,OAAO,EAClB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,aAAa,CAAA;CAAO,GAC1G,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAIlC"}
package/dist/zod.js ADDED
@@ -0,0 +1 @@
1
+ import {processEnv}from'./index.js';async function u(o,t,r){let e={};for(const s of o)try{const n=await s.load();e={...e,...n};}catch(n){if(r)throw new Error(`Resolver ${s.name} failed: ${n instanceof Error?n.message:n}`)}if(t)for(const[s,n]of Object.entries(e))e[s]=n.replace(/\$\{([^}]+)\}/g,(c,a)=>e[a]||"");return e}function l(o){return {"~standard":{version:1,vendor:"zod",validate:async t=>{const r=await o.safeParseAsync(t);return r.success?{value:r.data}:{issues:r.error?.issues.map(e=>({message:e.message,path:e.path}))||[{message:"Zod validation failed",path:[]}]}},types:{input:{},output:{}}}}}async function d(o,t={}){const{resolvers:r=[processEnv()],interpolate:e=false,strict:s=true}=t,n=await u(r,e,s);return o.parse(n)}export{d as resolveEnvWithZod,l as zodToStandardSchema};
package/package.json CHANGED
@@ -1,17 +1,73 @@
1
1
  {
2
2
  "name": "node-env-resolver",
3
- "version": "0.0.0",
4
- "description": "Resolves environment variables for Node.js applications",
3
+ "version": "1.0.0",
4
+ "description": "Type-safe environment variable resolver with async resolvers - lightweight, tree-shakeable, no dependencies",
5
+ "type": "module",
5
6
  "main": "./dist/index.js",
6
- "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./builder": {
14
+ "import": "./dist/builder.js",
15
+ "types": "./dist/builder.d.ts"
16
+ },
17
+ "./zod": {
18
+ "import": "./dist/zod.js",
19
+ "types": "./dist/zod.d.ts"
20
+ },
21
+ "./standard-schema": {
22
+ "import": "./dist/standard-schema.js",
23
+ "types": "./dist/standard-schema.d.ts"
24
+ },
25
+ "./web": {
26
+ "import": "./dist/web.js",
27
+ "types": "./dist/web.d.ts"
28
+ },
29
+ "./resolvers": {
30
+ "import": "./dist/resolvers.js",
31
+ "types": "./dist/resolvers.d.ts"
32
+ },
33
+ "./utils": {
34
+ "import": "./dist/utils.js",
35
+ "types": "./dist/utils.d.ts"
36
+ },
37
+ "./validators": {
38
+ "import": "./dist/validators.js",
39
+ "types": "./dist/validators.d.ts"
40
+ },
41
+ "./audit": {
42
+ "import": "./dist/audit.js",
43
+ "types": "./dist/audit.d.ts"
44
+ },
45
+ "./resolver": {
46
+ "import": "./dist/resolver.js",
47
+ "types": "./dist/resolver.d.ts"
48
+ },
49
+ "./types": {
50
+ "import": "./dist/types.js",
51
+ "types": "./dist/types.d.ts"
52
+ }
53
+ },
8
54
  "files": [
9
- "dist"
55
+ "dist",
56
+ "README.md"
10
57
  ],
11
58
  "keywords": [
12
- "node",
59
+ "environment",
60
+ "env",
61
+ "config",
62
+ "typescript",
13
63
  "aws-secrets",
14
- "local-env"
64
+ "aws-ssm",
65
+ "vault",
66
+ "doppler",
67
+ "type-safe",
68
+ "tree-shaking",
69
+ "lambda",
70
+ "serverless"
15
71
  ],
16
72
  "author": {
17
73
  "name": "Jagvinder Singh Reehal",
@@ -19,31 +75,35 @@
19
75
  "url": "https://jagreehal.com"
20
76
  },
21
77
  "license": "MIT",
22
- "dependencies": {
23
- "@aws-sdk/client-secrets-manager": "^3.259.0",
24
- "zod": "^3.20.2"
78
+ "sideEffects": false,
79
+ "publishConfig": {
80
+ "access": "public"
81
+ },
82
+ "engines": {
83
+ "node": ">=18"
25
84
  },
26
85
  "devDependencies": {
27
- "@types/jest": "^29.4.0",
28
- "@types/node": "^18.11.18",
29
- "@changesets/cli": "^2.26.0",
30
- "@typescript-eslint/eslint-plugin": "^5.49.0",
31
- "@typescript-eslint/parser": "^5.49.0",
32
- "eslint": "^8.33.0",
33
- "eslint-config-prettier": "^8.6.0",
34
- "jest": "^29.4.1",
35
- "prettier": "^2.8.3",
36
- "ts-jest": "^29.0.5",
37
- "tsup": "^6.5.0",
38
- "typescript": "^4.9.4"
86
+ "@eslint/js": "^9.37.0",
87
+ "@types/node": "^24.7.0",
88
+ "@typescript-eslint/eslint-plugin": "^8.46.0",
89
+ "@typescript-eslint/parser": "^8.46.0",
90
+ "eslint": "^9.37.0",
91
+ "eslint-config-prettier": "^10.1.8",
92
+ "prettier": "^3.6.2",
93
+ "tsup": "^8.5.0",
94
+ "typescript": "^5.9.3",
95
+ "vitest": "^3.2.4"
96
+ },
97
+ "dependencies": {
98
+ "@standard-schema/spec": "^1.0.0"
39
99
  },
40
100
  "scripts": {
41
- "build": "tsup",
42
- "changeset": "changeset",
43
- "format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",
44
- "lint": "eslint --ext .js,.ts ./src",
45
- "prerelease": "npm run lint && npm run build && npm run test",
46
- "release": "changeset publish",
47
- "test": "jest --coverage"
101
+ "build": "NODE_ENV=production tsup && tsc --emitDeclarationOnly",
102
+ "build:dev": "tsup",
103
+ "build:dts": "tsc --emitDeclarationOnly",
104
+ "typecheck": "tsc -p tsconfig.json --noEmit",
105
+ "lint": "eslint src/",
106
+ "test": "vitest run",
107
+ "format": "prettier --write \"**/*.{ts,tsx,md}\""
48
108
  }
49
109
  }
@@ -1,148 +0,0 @@
1
- 'use strict';
2
-
3
- var clientSecretsManager = require('@aws-sdk/client-secrets-manager');
4
-
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
- var __spreadValues = (a, b) => {
11
- for (var prop in b || (b = {}))
12
- if (__hasOwnProp.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- if (__getOwnPropSymbols)
15
- for (var prop of __getOwnPropSymbols(b)) {
16
- if (__propIsEnum.call(b, prop))
17
- __defNormalProp(a, prop, b[prop]);
18
- }
19
- return a;
20
- };
21
- var __async = (__this, __arguments, generator) => {
22
- return new Promise((resolve, reject) => {
23
- var fulfilled = (value) => {
24
- try {
25
- step(generator.next(value));
26
- } catch (e) {
27
- reject(e);
28
- }
29
- };
30
- var rejected = (value) => {
31
- try {
32
- step(generator.throw(value));
33
- } catch (e) {
34
- reject(e);
35
- }
36
- };
37
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
38
- step((generator = generator.apply(__this, __arguments)).next());
39
- });
40
- };
41
-
42
- // src/resolvers/aws-secrets/utils.ts
43
- function mapAwsSecretConfigFromEnv() {
44
- return {
45
- secretId: process.env.AWS_SECRET_ID,
46
- awsConfig: {
47
- region: process.env.AWS_DEFAULT_REGION,
48
- credentials: {
49
- accessKeyId: process.env.AWS_ACCESS_KEY_ID,
50
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
51
- }
52
- }
53
- };
54
- }
55
- function validateAwsSecretsConfig(config) {
56
- if (!config.secretId) {
57
- throw new Error("AWS_SECRET_ID environment variable is missing");
58
- }
59
- if (!config.awsConfig.region) {
60
- throw new Error("AWS_DEFAULT_REGION environment variable is missing");
61
- }
62
- if (!config.awsConfig.credentials.accessKeyId) {
63
- throw new Error("AWS_ACCESS_KEY_ID environment variable is missing");
64
- }
65
- if (!config.awsConfig.credentials.secretAccessKey) {
66
- throw new Error("AWS_SECRET_ACCESS_KEY environment variable is missing");
67
- }
68
- return config;
69
- }
70
-
71
- // src/resolvers/aws-secrets/index.ts
72
- function resolveAwsSecrets(props) {
73
- return __async(this, null, function* () {
74
- const { secretId, awsConfig } = props;
75
- const secretsManagerClient = new clientSecretsManager.SecretsManagerClient(awsConfig);
76
- const getSecretCommand = new clientSecretsManager.GetSecretValueCommand({
77
- SecretId: secretId
78
- });
79
- const { SecretString } = yield secretsManagerClient.send(getSecretCommand);
80
- if (!SecretString) {
81
- throw new Error("SecretString is undefined");
82
- }
83
- return JSON.parse(SecretString);
84
- });
85
- }
86
- function configResolver() {
87
- return __async(this, null, function* () {
88
- return resolveAwsSecrets(
89
- validateAwsSecretsConfig(mapAwsSecretConfigFromEnv())
90
- );
91
- });
92
- }
93
-
94
- // src/resolvers/local/index.ts
95
- function configResolver2() {
96
- return __async(this, null, function* () {
97
- return Promise.resolve(process.env);
98
- });
99
- }
100
-
101
- // src/lib/resolver.ts
102
- var resolverLookUp = {
103
- local: configResolver2,
104
- "aws-secrets": configResolver
105
- };
106
- function resolveEnvs(resolveProps = "local") {
107
- return __async(this, null, function* () {
108
- const resolverFunctions = mapResolvePropsToResolverFunctions(resolveProps);
109
- const resolversEnvs = yield Promise.all(
110
- resolverFunctions.map((resolverFunction) => {
111
- return resolverFunction();
112
- })
113
- );
114
- return resolversEnvs.reduce((envs, resolverEnvs) => {
115
- return __spreadValues(__spreadValues({}, envs), resolverEnvs);
116
- }, {});
117
- });
118
- }
119
- function lookUpResolver(name) {
120
- const resolver = resolverLookUp[name];
121
- if (!resolver) {
122
- throw new Error(`Resolver function for "${name}" not found.`);
123
- }
124
- return resolver;
125
- }
126
- function mapResolvePropsToResolverFunctions(resolveProps) {
127
- if (typeof resolveProps === "function") {
128
- return [resolveProps];
129
- }
130
- if (typeof resolveProps === "string") {
131
- return [lookUpResolver(resolveProps)];
132
- }
133
- return resolveProps.map((prop) => {
134
- if (typeof prop === "function") {
135
- return prop;
136
- }
137
- if (typeof prop === "string") {
138
- return lookUpResolver(prop);
139
- }
140
- throw new Error(
141
- `Expected a resolver function or string, but received: ${prop}`
142
- );
143
- });
144
- }
145
-
146
- exports.__async = __async;
147
- exports.resolveAwsSecrets = resolveAwsSecrets;
148
- exports.resolveEnvs = resolveEnvs;
@@ -1,13 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkAST3HVOG_js = require('./chunk-AST3HVOG.js');
4
-
5
- // src/resolveZod.ts
6
- function resolveZod(schema, resolveProps = "local") {
7
- return chunkAST3HVOG_js.__async(this, null, function* () {
8
- const envValues = yield chunkAST3HVOG_js.resolveEnvs(resolveProps);
9
- return schema.parse(envValues);
10
- });
11
- }
12
-
13
- exports.resolveZod = resolveZod;
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkAST3HVOG_js = require('./chunk-AST3HVOG.js');
4
-
5
- // src/utils/index.ts
6
- function findMissingEntries(envKeys, envsToResolveKeys) {
7
- const intersect = envsToResolveKeys.filter(
8
- (entry) => envKeys.includes(entry)
9
- );
10
- return envsToResolveKeys.filter((entry) => !intersect.includes(entry));
11
- }
12
- function resolveEnvValues(envValues, envsToResolve, resolveOptions) {
13
- const envKeys = Array.isArray(envsToResolve) ? envsToResolve : Object.keys(envsToResolve);
14
- if (resolveOptions == null ? void 0 : resolveOptions.strict) {
15
- const missingEntries = findMissingEntries(envKeys, Object.keys(envValues));
16
- if (missingEntries.length) {
17
- const error = `Could not find value for the following envs: ${missingEntries.join(
18
- ", "
19
- )}`;
20
- throw new Error(error);
21
- }
22
- }
23
- return envKeys.reduce((env, key) => {
24
- env[key] = envValues[key];
25
- return env;
26
- }, /* @__PURE__ */ Object.create(null));
27
- }
28
-
29
- // src/resolve.ts
30
- function resolve(_0) {
31
- return chunkAST3HVOG_js.__async(this, arguments, function* (envsToResolve, resolveProps = "local", resolveOptions = { strict: true }) {
32
- const envValues = yield chunkAST3HVOG_js.resolveEnvs(resolveProps);
33
- return resolveEnvValues(envValues, envsToResolve, resolveOptions);
34
- });
35
- }
36
-
37
- exports.resolve = resolve;
@@ -1,144 +0,0 @@
1
- import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __async = (__this, __arguments, generator) => {
20
- return new Promise((resolve, reject) => {
21
- var fulfilled = (value) => {
22
- try {
23
- step(generator.next(value));
24
- } catch (e) {
25
- reject(e);
26
- }
27
- };
28
- var rejected = (value) => {
29
- try {
30
- step(generator.throw(value));
31
- } catch (e) {
32
- reject(e);
33
- }
34
- };
35
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
- step((generator = generator.apply(__this, __arguments)).next());
37
- });
38
- };
39
-
40
- // src/resolvers/aws-secrets/utils.ts
41
- function mapAwsSecretConfigFromEnv() {
42
- return {
43
- secretId: process.env.AWS_SECRET_ID,
44
- awsConfig: {
45
- region: process.env.AWS_DEFAULT_REGION,
46
- credentials: {
47
- accessKeyId: process.env.AWS_ACCESS_KEY_ID,
48
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
49
- }
50
- }
51
- };
52
- }
53
- function validateAwsSecretsConfig(config) {
54
- if (!config.secretId) {
55
- throw new Error("AWS_SECRET_ID environment variable is missing");
56
- }
57
- if (!config.awsConfig.region) {
58
- throw new Error("AWS_DEFAULT_REGION environment variable is missing");
59
- }
60
- if (!config.awsConfig.credentials.accessKeyId) {
61
- throw new Error("AWS_ACCESS_KEY_ID environment variable is missing");
62
- }
63
- if (!config.awsConfig.credentials.secretAccessKey) {
64
- throw new Error("AWS_SECRET_ACCESS_KEY environment variable is missing");
65
- }
66
- return config;
67
- }
68
-
69
- // src/resolvers/aws-secrets/index.ts
70
- function resolveAwsSecrets(props) {
71
- return __async(this, null, function* () {
72
- const { secretId, awsConfig } = props;
73
- const secretsManagerClient = new SecretsManagerClient(awsConfig);
74
- const getSecretCommand = new GetSecretValueCommand({
75
- SecretId: secretId
76
- });
77
- const { SecretString } = yield secretsManagerClient.send(getSecretCommand);
78
- if (!SecretString) {
79
- throw new Error("SecretString is undefined");
80
- }
81
- return JSON.parse(SecretString);
82
- });
83
- }
84
- function configResolver() {
85
- return __async(this, null, function* () {
86
- return resolveAwsSecrets(
87
- validateAwsSecretsConfig(mapAwsSecretConfigFromEnv())
88
- );
89
- });
90
- }
91
-
92
- // src/resolvers/local/index.ts
93
- function configResolver2() {
94
- return __async(this, null, function* () {
95
- return Promise.resolve(process.env);
96
- });
97
- }
98
-
99
- // src/lib/resolver.ts
100
- var resolverLookUp = {
101
- local: configResolver2,
102
- "aws-secrets": configResolver
103
- };
104
- function resolveEnvs(resolveProps = "local") {
105
- return __async(this, null, function* () {
106
- const resolverFunctions = mapResolvePropsToResolverFunctions(resolveProps);
107
- const resolversEnvs = yield Promise.all(
108
- resolverFunctions.map((resolverFunction) => {
109
- return resolverFunction();
110
- })
111
- );
112
- return resolversEnvs.reduce((envs, resolverEnvs) => {
113
- return __spreadValues(__spreadValues({}, envs), resolverEnvs);
114
- }, {});
115
- });
116
- }
117
- function lookUpResolver(name) {
118
- const resolver = resolverLookUp[name];
119
- if (!resolver) {
120
- throw new Error(`Resolver function for "${name}" not found.`);
121
- }
122
- return resolver;
123
- }
124
- function mapResolvePropsToResolverFunctions(resolveProps) {
125
- if (typeof resolveProps === "function") {
126
- return [resolveProps];
127
- }
128
- if (typeof resolveProps === "string") {
129
- return [lookUpResolver(resolveProps)];
130
- }
131
- return resolveProps.map((prop) => {
132
- if (typeof prop === "function") {
133
- return prop;
134
- }
135
- if (typeof prop === "string") {
136
- return lookUpResolver(prop);
137
- }
138
- throw new Error(
139
- `Expected a resolver function or string, but received: ${prop}`
140
- );
141
- });
142
- }
143
-
144
- export { __async, resolveAwsSecrets, resolveEnvs };
@@ -1,11 +0,0 @@
1
- import { __async, resolveEnvs } from './chunk-AST3HVOG.js';
2
-
3
- // src/resolveZod.ts
4
- function resolveZod(schema, resolveProps = "local") {
5
- return __async(this, null, function* () {
6
- const envValues = yield resolveEnvs(resolveProps);
7
- return schema.parse(envValues);
8
- });
9
- }
10
-
11
- export { resolveZod };
@@ -1,35 +0,0 @@
1
- import { __async, resolveEnvs } from './chunk-AST3HVOG.js';
2
-
3
- // src/utils/index.ts
4
- function findMissingEntries(envKeys, envsToResolveKeys) {
5
- const intersect = envsToResolveKeys.filter(
6
- (entry) => envKeys.includes(entry)
7
- );
8
- return envsToResolveKeys.filter((entry) => !intersect.includes(entry));
9
- }
10
- function resolveEnvValues(envValues, envsToResolve, resolveOptions) {
11
- const envKeys = Array.isArray(envsToResolve) ? envsToResolve : Object.keys(envsToResolve);
12
- if (resolveOptions == null ? void 0 : resolveOptions.strict) {
13
- const missingEntries = findMissingEntries(envKeys, Object.keys(envValues));
14
- if (missingEntries.length) {
15
- const error = `Could not find value for the following envs: ${missingEntries.join(
16
- ", "
17
- )}`;
18
- throw new Error(error);
19
- }
20
- }
21
- return envKeys.reduce((env, key) => {
22
- env[key] = envValues[key];
23
- return env;
24
- }, /* @__PURE__ */ Object.create(null));
25
- }
26
-
27
- // src/resolve.ts
28
- function resolve(_0) {
29
- return __async(this, arguments, function* (envsToResolve, resolveProps = "local", resolveOptions = { strict: true }) {
30
- const envValues = yield resolveEnvs(resolveProps);
31
- return resolveEnvValues(envValues, envsToResolve, resolveOptions);
32
- });
33
- }
34
-
35
- export { resolve };
package/dist/esm/index.js DELETED
@@ -1,3 +0,0 @@
1
- export { resolve } from './chunk-XC5PWSNR.js';
2
- export { resolveZod } from './chunk-UQYMDWOU.js';
3
- export { resolveAwsSecrets } from './chunk-AST3HVOG.js';
@@ -1,2 +0,0 @@
1
- export { resolve } from './chunk-XC5PWSNR.js';
2
- export { resolveAwsSecrets } from './chunk-AST3HVOG.js';
@@ -1,2 +0,0 @@
1
- export { resolveZod } from './chunk-UQYMDWOU.js';
2
- export { resolveAwsSecrets } from './chunk-AST3HVOG.js';
@@ -1,27 +0,0 @@
1
- interface ResolverFunction {
2
- (): Promise<EnvValues>;
3
- }
4
- type EnvValues = {
5
- [key: string]: string | undefined;
6
- };
7
- type ResolveOptions = {
8
- strict?: boolean;
9
- };
10
- type EnvsToResolve = string[] | EnvValues;
11
- type ResolveProps = string | ResolverFunction | (string | ResolverFunction)[];
12
-
13
- type AwsConfig = {
14
- region: string;
15
- credentials: {
16
- accessKeyId: string;
17
- secretAccessKey: string;
18
- };
19
- };
20
- type ResolveAwsSecretsProps = {
21
- secretId: string;
22
- awsConfig: AwsConfig;
23
- };
24
-
25
- declare function resolveAwsSecrets(props: ResolveAwsSecretsProps): Promise<EnvValues>;
26
-
27
- export { EnvValues as E, ResolverFunction as R, ResolveOptions as a, EnvsToResolve as b, ResolveProps as c, resolveAwsSecrets as r };
package/dist/resolve.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { b as EnvsToResolve, c as ResolveProps, a as ResolveOptions, E as EnvValues } from './index-6c4171f8.js';
2
- export { R as ResolverFunction, r as resolveAwsSecrets } from './index-6c4171f8.js';
3
-
4
- declare function resolve(envsToResolve: EnvsToResolve, resolveProps?: ResolveProps, resolveOptions?: ResolveOptions): Promise<EnvValues>;
5
-
6
- export { EnvValues, EnvsToResolve, ResolveOptions, ResolveProps, resolve };
package/dist/resolve.js DELETED
@@ -1,15 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkXC5PWSNR_js = require('./chunk-XC5PWSNR.js');
4
- var chunkAST3HVOG_js = require('./chunk-AST3HVOG.js');
5
-
6
-
7
-
8
- Object.defineProperty(exports, 'resolve', {
9
- enumerable: true,
10
- get: function () { return chunkXC5PWSNR_js.resolve; }
11
- });
12
- Object.defineProperty(exports, 'resolveAwsSecrets', {
13
- enumerable: true,
14
- get: function () { return chunkAST3HVOG_js.resolveAwsSecrets; }
15
- });
@@ -1,7 +0,0 @@
1
- import { z } from 'zod';
2
- import { c as ResolveProps } from './index-6c4171f8.js';
3
- export { E as EnvValues, b as EnvsToResolve, a as ResolveOptions, R as ResolverFunction, r as resolveAwsSecrets } from './index-6c4171f8.js';
4
-
5
- declare function resolveZod<T>(schema: z.ZodSchema<T>, resolveProps?: ResolveProps): Promise<T>;
6
-
7
- export { ResolveProps, resolveZod };