@geekmidas/envkit 10.0.0-alpha.16 → 10.0.0-alpha.160

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.
@@ -1,8 +1,6 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
2
2
  let lodash_get = require("lodash.get");
3
3
  lodash_get = require_rolldown_runtime.__toESM(lodash_get, 1);
4
- let lodash_set = require("lodash.set");
5
- lodash_set = require_rolldown_runtime.__toESM(lodash_set, 1);
6
4
  let zod_v4 = require("zod/v4");
7
5
  //#region src/formatter.ts
8
6
  /**
@@ -144,12 +142,12 @@ var ConfigParser = class {
144
142
  const currentPath = [...path, key];
145
143
  if (schema instanceof zod_v4.z.ZodType) {
146
144
  const parsed = schema.safeParse(void 0);
147
- if (parsed.success) (0, lodash_set.default)(result, key, parsed.data);
145
+ if (parsed.success) result[key] = parsed.data;
148
146
  else errors.push(...parsed.error.issues.map((issue) => ({
149
147
  ...issue,
150
148
  path: [...currentPath, ...issue.path]
151
149
  })));
152
- } else if (schema) (0, lodash_set.default)(result, key, parseDeep(schema, currentPath));
150
+ } else if (schema) result[key] = parseDeep(schema, currentPath);
153
151
  }
154
152
  return result;
155
153
  };
@@ -343,4 +341,4 @@ Object.defineProperty(exports, "isDevelopment", {
343
341
  }
344
342
  });
345
343
 
346
- //# sourceMappingURL=EnvironmentParser-CmhDxs77.cjs.map
344
+ //# sourceMappingURL=EnvironmentParser-BDC7EQQR.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnvironmentParser-BDC7EQQR.cjs","names":["z","get"],"sources":["../src/formatter.ts","../src/EnvironmentParser.ts"],"sourcesContent":["import type { z } from 'zod/v4';\n\n/**\n * Options for formatting parse errors.\n */\nexport interface FormatOptions {\n\t/** Whether to use colors in output. Defaults to auto-detect TTY. */\n\tcolors?: boolean;\n}\n\n/**\n * ANSI color codes for terminal output.\n */\nconst colors = {\n\treset: '\\x1b[0m',\n\tred: '\\x1b[31m',\n\tyellow: '\\x1b[33m',\n\tcyan: '\\x1b[36m',\n\tdim: '\\x1b[2m',\n\tbold: '\\x1b[1m',\n};\n\n/**\n * Formats a ZodError into a user-friendly string for development.\n *\n * @param error - The ZodError to format\n * @param options - Formatting options\n * @returns Formatted error message\n *\n * @example\n * ```typescript\n * try {\n * config.parse();\n * } catch (error) {\n * if (error instanceof ZodError) {\n * console.error(formatParseError(error));\n * }\n * }\n * ```\n *\n * Output:\n * ```\n * Environment Configuration Failed\n *\n * Missing Variables:\n * DATABASE_URL - Required\n * JWT_SECRET - Required\n *\n * Invalid Values:\n * NODE_ENV = \"invalid\"\n * Expected: \"development\" | \"staging\" | \"production\"\n * ```\n */\nexport function formatParseError(\n\terror: z.ZodError,\n\toptions: FormatOptions = {},\n): string {\n\tconst useColors =\n\t\toptions.colors ?? (process.stdout?.isTTY && process.env.NO_COLOR == null);\n\n\tconst c = useColors\n\t\t? colors\n\t\t: { reset: '', red: '', yellow: '', cyan: '', dim: '', bold: '' };\n\n\tconst missingVars: Array<{ name: string; message: string }> = [];\n\tconst invalidVars: Array<{ name: string; value: unknown; message: string }> =\n\t\t[];\n\n\tfor (const issue of error.issues) {\n\t\t// Extract environment variable name from path or message\n\t\tlet envName = '';\n\t\tif (issue.path.length > 0) {\n\t\t\t// Join the full path with '.' to show nested config keys and env var name\n\t\t\tenvName = issue.path.map(String).join('.');\n\t\t} else {\n\t\t\t// Try to extract from message like 'Environment variable \"NAME\": ...'\n\t\t\tconst match = issue.message.match(/Environment variable \"([^\"]+)\"/);\n\t\t\tif (match?.[1]) {\n\t\t\t\tenvName = match[1];\n\t\t\t}\n\t\t}\n\n\t\t// Determine if this is a missing or invalid value\n\t\t// Use type guard for received property\n\t\tconst received = 'received' in issue ? issue.received : undefined;\n\t\tconst isMissing =\n\t\t\tissue.code === 'invalid_type' &&\n\t\t\t(received === 'undefined' || received === 'null');\n\n\t\tif (isMissing) {\n\t\t\tmissingVars.push({\n\t\t\t\tname: envName || 'Unknown',\n\t\t\t\tmessage: cleanMessage(issue.message),\n\t\t\t});\n\t\t} else {\n\t\t\tinvalidVars.push({\n\t\t\t\tname: envName || 'Unknown',\n\t\t\t\tvalue: received,\n\t\t\t\tmessage: cleanMessage(issue.message),\n\t\t\t});\n\t\t}\n\t}\n\n\tconst lines: string[] = [];\n\n\tlines.push('');\n\tlines.push(`${c.red}${c.bold}Environment Configuration Failed${c.reset}`);\n\tlines.push('');\n\n\tif (missingVars.length > 0) {\n\t\tlines.push(`${c.yellow}Missing Variables:${c.reset}`);\n\t\tfor (const v of missingVars) {\n\t\t\tlines.push(` ${c.cyan}${v.name}${c.reset} ${c.dim}- Required${c.reset}`);\n\t\t}\n\t\tlines.push('');\n\t}\n\n\tif (invalidVars.length > 0) {\n\t\tlines.push(`${c.yellow}Invalid Values:${c.reset}`);\n\t\tfor (const v of invalidVars) {\n\t\t\tconst valueStr =\n\t\t\t\tv.value !== undefined ? ` = ${JSON.stringify(v.value)}` : '';\n\t\t\tlines.push(` ${c.cyan}${v.name}${c.reset}${valueStr}`);\n\t\t\tlines.push(` ${c.dim}${v.message}${c.reset}`);\n\t\t}\n\t\tlines.push('');\n\t}\n\n\treturn lines.join('\\n');\n}\n\n/**\n * Cleans up a Zod error message by removing redundant prefixes.\n */\nfunction cleanMessage(message: string): string {\n\t// Remove \"Environment variable \"NAME\": \" prefix if present\n\treturn message.replace(/^Environment variable \"[^\"]+\": /, '');\n}\n\n/**\n * Checks if the current environment is development.\n */\nexport function isDevelopment(): boolean {\n\tconst nodeEnv = process.env.NODE_ENV?.toLowerCase();\n\treturn nodeEnv == null || nodeEnv === 'development' || nodeEnv === 'dev';\n}\n","import get from 'lodash.get';\nimport { z } from 'zod/v4';\nimport { formatParseError, isDevelopment } from './formatter.js';\n\n/**\n * Parses and validates configuration objects against Zod schemas.\n * Handles nested configurations and aggregates validation errors.\n *\n * @template TResponse - The shape of the configuration object\n */\nexport class ConfigParser<TResponse extends EmptyObject> {\n\t/**\n\t * Creates a new ConfigParser instance.\n\t *\n\t * @param config - The configuration object to parse\n\t * @param envVars - Set of environment variable names that were accessed\n\t */\n\tconstructor(\n\t\tprivate readonly config: TResponse,\n\t\tprivate readonly envVars: Set<string> = new Set(),\n\t) {}\n\t/**\n\t * Parses the config object and validates it against the Zod schemas\n\t * @returns The parsed config object\n\t */\n\tparse(): InferConfig<TResponse> {\n\t\tconst errors: z.core.$ZodIssue[] = [];\n\n\t\tconst parseDeep = <T>(config: T, path: string[] = []) => {\n\t\t\tconst result: EmptyObject = {};\n\n\t\t\tif (config && typeof config !== 'object') {\n\t\t\t\treturn config;\n\t\t\t}\n\n\t\t\tfor (const key in config) {\n\t\t\t\tconst schema = config[key];\n\t\t\t\tconst currentPath = [...path, key];\n\n\t\t\t\tif (schema instanceof z.ZodType) {\n\t\t\t\t\tconst parsed = schema.safeParse(undefined);\n\t\t\t\t\tif (parsed.success) {\n\t\t\t\t\t\tresult[key] = parsed.data;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the schema is invalid, assign the error\n\t\t\t\t\t\terrors.push(\n\t\t\t\t\t\t\t...parsed.error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\tpath: [...currentPath, ...(issue.path as string[])],\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (schema) {\n\t\t\t\t\tresult[key] = parseDeep(schema as EmptyObject, currentPath);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result;\n\t\t};\n\n\t\tconst parsedConfig = parseDeep(\n\t\t\tthis.config,\n\t\t) as unknown as InferConfig<TResponse>;\n\n\t\tif (errors.length > 0) {\n\t\t\tconst zodError = new z.ZodError(errors);\n\t\t\t// In development, log a formatted error message before throwing\n\t\t\tif (isDevelopment()) {\n\t\t\t\tconsole.error(formatParseError(zodError));\n\t\t\t}\n\t\t\tthrow zodError;\n\t\t}\n\n\t\treturn parsedConfig;\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed during config creation.\n\t * This is useful for deployment and configuration management to know which env vars are required.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const config = envParser.create((get) => ({\n\t * dbUrl: get('DATABASE_URL').string(),\n\t * port: get('PORT').number()\n\t * }));\n\t *\n\t * config.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.envVars).sort();\n\t}\n}\n\n/**\n * Parses environment variables with type-safe validation using Zod schemas.\n * Provides a fluent API for defining environment variable schemas with automatic\n * error context enrichment.\n *\n * @template T - The type of the configuration object (typically process.env)\n *\n * @example\n * ```typescript\n * const config = new EnvironmentParser(process.env)\n * .create((get) => ({\n * port: get('PORT').string().transform(Number).default(3000),\n * database: {\n * url: get('DATABASE_URL').string().url()\n * }\n * }))\n * .parse();\n * ```\n */\nexport class EnvironmentParser<T extends EmptyObject> {\n\t/**\n\t * Set to track which environment variable names have been accessed\n\t */\n\tprivate readonly accessedVars: Set<string> = new Set();\n\n\t/**\n\t * Creates a new EnvironmentParser instance.\n\t *\n\t * @param config - The configuration object to parse (typically process.env)\n\t */\n\tconstructor(private readonly config: T) {}\n\n\t/**\n\t * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages\n\t * with environment variable context.\n\t *\n\t * @param schema - The Zod schema to wrap\n\t * @param name - The environment variable name for error context\n\t * @returns A wrapped Zod schema with enhanced error reporting\n\t */\n\tprivate wrapSchema = (schema: z.ZodType, name: string): z.ZodType => {\n\t\t// Create a proxy that intercepts all method calls on the schema\n\t\treturn new Proxy(schema, {\n\t\t\tget: (target, prop) => {\n\t\t\t\tif (prop === 'parse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn target.parse(value);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif (error instanceof z.ZodError) {\n\t\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\t\tconst modifiedIssues = error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t\tthrow new z.ZodError(modifiedIssues);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (prop === 'safeParse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\tconst result = target.safeParse(value);\n\n\t\t\t\t\t\tif (!result.success) {\n\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\tconst modifiedIssues = result.error.issues.map(\n\t\t\t\t\t\t\t\t(issue: z.core.$ZodIssue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tsuccess: false as const,\n\t\t\t\t\t\t\t\terror: new z.ZodError(modifiedIssues),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// For any method that returns a new schema (like transform, optional, etc.),\n\t\t\t\t// wrap the result as well\n\t\t\t\tconst originalProp = target[prop as keyof typeof target];\n\t\t\t\tif (typeof originalProp === 'function') {\n\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\tconst result = originalProp.apply(target, args);\n\t\t\t\t\t\t// If the result is a ZodType, wrap it too\n\t\t\t\t\t\tif (result && typeof result === 'object' && 'parse' in result) {\n\t\t\t\t\t\t\treturn this.wrapSchema(result, name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn originalProp;\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Creates a proxied version of the Zod object that wraps all schema creators\n\t * to provide enhanced error messages with environment variable context.\n\t *\n\t * @param name - The environment variable name\n\t * @returns A proxied Zod object with wrapped schema creators\n\t */\n\tprivate getZodGetter = (name: string) => {\n\t\t// Track that this environment variable was accessed\n\t\tthis.accessedVars.add(name);\n\n\t\t// Return an object that has all Zod schemas but with our wrapper\n\t\treturn new Proxy(\n\t\t\t{ ...z },\n\t\t\t{\n\t\t\t\tget: (target, prop) => {\n\t\t\t\t\t// deno-lint-ignore ban-ts-comment\n\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\tconst value = target[prop];\n\n\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\t// Return a wrapper around each Zod schema creator\n\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\tconst schema = value(...args);\n\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// Handle objects like z.coerce\n\t\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\t\treturn new Proxy(value, {\n\t\t\t\t\t\t\tget: (nestedTarget, nestedProp) => {\n\t\t\t\t\t\t\t\tconst nestedValue =\n\t\t\t\t\t\t\t\t\tnestedTarget[nestedProp as keyof typeof nestedTarget];\n\t\t\t\t\t\t\t\tif (typeof nestedValue === 'function') {\n\t\t\t\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\t\t\t\tconst schema = nestedValue(...args);\n\t\t\t\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn nestedValue;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn value;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t};\n\n\t/**\n\t * Creates a new ConfigParser object that can be used to parse the config object\n\t *\n\t * @param builder - A function that takes a getter function and returns a config object\n\t * @returns A ConfigParser object that can be used to parse the config object\n\t */\n\tcreate<TReturn extends EmptyObject>(\n\t\tbuilder: (get: EnvFetcher) => TReturn,\n\t): ConfigParser<TReturn> {\n\t\tconst config = builder(this.getZodGetter);\n\t\treturn new ConfigParser(config, this.accessedVars);\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed via the getter.\n\t * This is useful for build-time analysis to determine which env vars a service needs.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const sniffer = new EnvironmentParser({});\n\t * service.register(sniffer);\n\t * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.accessedVars).sort();\n\t}\n}\n\n/**\n * Infers the TypeScript type of a configuration object based on its Zod schemas.\n * Recursively processes nested objects and extracts types from Zod schemas.\n *\n * @template T - The configuration object type\n */\nexport type InferConfig<T extends EmptyObject> = {\n\t[K in keyof T]: T[K] extends z.ZodSchema\n\t\t? z.infer<T[K]>\n\t\t: T[K] extends Record<string, unknown>\n\t\t\t? InferConfig<T[K]>\n\t\t\t: T[K];\n};\n\n/**\n * Function type for fetching environment variables with Zod validation.\n * Returns a Zod object scoped to a specific environment variable.\n *\n * @template TPath - The environment variable path type\n * @param name - The environment variable name\n * @returns A Zod object for defining the schema\n */\nexport type EnvFetcher<TPath extends string = string> = (\n\tname: TPath,\n) => typeof z;\n\n/**\n * Function type for building environment configuration objects.\n * Takes an EnvFetcher and returns a configuration object with Zod schemas.\n *\n * @template TResponse - The response configuration object type\n * @param get - The environment variable fetcher function\n * @returns The configuration object with Zod schemas\n */\nexport type EnvironmentBuilder<TResponse extends EmptyObject> = (\n\tget: EnvFetcher,\n) => TResponse;\n\n/**\n * Type alias for a generic object with unknown values.\n * Used as a constraint for configuration objects.\n */\nexport type EmptyObject = Record<string | number | symbol, unknown>;\n"],"mappings":";;;;;;;;AAaA,MAAM,SAAS;CACd,OAAO;CACP,KAAK;CACL,QAAQ;CACR,MAAM;CACN,KAAK;CACL,MAAM;AACP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,iBACf,OACA,UAAyB,CAAC,GACjB;CAIT,MAAM,IAFL,QAAQ,WAAW,QAAQ,QAAQ,SAAS,QAAQ,IAAI,YAAY,QAGlE,SACA;EAAE,OAAO;EAAI,KAAK;EAAI,QAAQ;EAAI,MAAM;EAAI,KAAK;EAAI,MAAM;CAAG;CAEjE,MAAM,cAAwD,CAAC;CAC/D,MAAM,cACL,CAAC;CAEF,KAAK,MAAM,SAAS,MAAM,QAAQ;EAEjC,IAAI,UAAU;EACd,IAAI,MAAM,KAAK,SAAS,GAEvB,UAAU,MAAM,KAAK,IAAI,MAAM,CAAC,CAAC,KAAK,GAAG;OACnC;GAEN,MAAM,QAAQ,MAAM,QAAQ,MAAM,gCAAgC;GAClE,IAAI,QAAQ,IACX,UAAU,MAAM;EAElB;EAIA,MAAM,WAAW,cAAc,QAAQ,MAAM,WAAW,KAAA;EAKxD,IAHC,MAAM,SAAS,mBACd,aAAa,eAAe,aAAa,SAG1C,YAAY,KAAK;GAChB,MAAM,WAAW;GACjB,SAAS,aAAa,MAAM,OAAO;EACpC,CAAC;OAED,YAAY,KAAK;GAChB,MAAM,WAAW;GACjB,OAAO;GACP,SAAS,aAAa,MAAM,OAAO;EACpC,CAAC;CAEH;CAEA,MAAM,QAAkB,CAAC;CAEzB,MAAM,KAAK,EAAE;CACb,MAAM,KAAK,GAAG,EAAE,MAAM,EAAE,KAAK,kC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,MAAM,SAAS,YAAY,GAAG,IAAI;KAClC,OAAO,KAAK,WAAW,QAAQ,IAAI;IACpC;IAED,OAAO;GACR,EACD,CAAC;GAGF,OAAO;EACR,EACD,CACD;CACD;;;;;;;CAQA,OACC,SACwB;EAExB,OAAO,IAAI,aADI,QAAQ,KAAK,YACJ,GAAQ,KAAK,YAAY;CAClD;;;;;;;;;;;;;;CAeA,0BAAoC;EACnC,OAAO,MAAM,KAAK,KAAK,YAAY,CAAC,CAAC,KAAK;CAC3C;AACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"EnvironmentParser-BmJLlm5_.d.cts","names":[],"sources":["../src/EnvironmentParser.ts"],"mappings":";;;;;;;;cAWa,aAAa,kBAAkB;mBAQzB;mBACA;;;;;;;EAFlB,YACkB,QAAQ,WACR,UAAS;;;;;EAM3B,SAAS,YAAY;;;;;;;;;;;;;;;;;EAmErB;;;;;;;;;;;;;;;;;;;;;cAwBY,kBAAkB,UAAU;mBAWX;;;;mBAPZ;;;;;;EAOjB,YAA6B,QAAQ;;;;;;;;;UAU7B;;;;;;;;UA0EA;;;;;;;EAkDR,OAAO,gBAAgB,aACtB,UAAU,KAAK,eAAe,UAC5B,aAAa;;;;;;;;;;;;;;EAkBhB;;;;;;;;KAWW,YAAY,UAAU,kBAChC,WAAW,IAAI,EAAE,WAAW,EAAE,YAC5B,EAAE,MAAM,EAAE,MACV,EAAE,WAAW,0BACZ,YAAY,EAAE,MACd,EAAE;;;;;;;;;KAWK,WAAW,kCACtB,MAAM,iBACK;;;;;KAkBA,cAAc"}
1
+ {"version":3,"file":"EnvironmentParser-BmJLlm5_.d.cts","names":[],"sources":["../src/EnvironmentParser.ts"],"mappings":";;;;;;;;cAUa,aAAa,kBAAkB;mBAQzB;mBACA;;;;;;;EAFlB,YACkB,QAAQ,WACR,UAAS;;;;;EAM3B,SAAS,YAAY;;;;;;;;;;;;;;;;;EAmErB;;;;;;;;;;;;;;;;;;;;;cAwBY,kBAAkB,UAAU;mBAWX;;;;mBAPZ;;;;;;EAOjB,YAA6B,QAAQ;;;;;;;;;UAU7B;;;;;;;;UA0EA;;;;;;;EAkDR,OAAO,gBAAgB,aACtB,UAAU,KAAK,eAAe,UAC5B,aAAa;;;;;;;;;;;;;;EAkBhB;;;;;;;;KAWW,YAAY,UAAU,kBAChC,WAAW,IAAI,EAAE,WAAW,EAAE,YAC5B,EAAE,MAAM,EAAE,MACV,EAAE,WAAW,0BACZ,YAAY,EAAE,MACd,EAAE;;;;;;;;;KAWK,WAAW,kCACtB,MAAM,iBACK;;;;;KAkBA,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"EnvironmentParser-BmJLlm5_.d.mts","names":[],"sources":["../src/EnvironmentParser.ts"],"mappings":";;;;;;;;cAWa,aAAa,kBAAkB;mBAQzB;mBACA;;;;;;;EAFlB,YACkB,QAAQ,WACR,UAAS;;;;;EAM3B,SAAS,YAAY;;;;;;;;;;;;;;;;;EAmErB;;;;;;;;;;;;;;;;;;;;;cAwBY,kBAAkB,UAAU;mBAWX;;;;mBAPZ;;;;;;EAOjB,YAA6B,QAAQ;;;;;;;;;UAU7B;;;;;;;;UA0EA;;;;;;;EAkDR,OAAO,gBAAgB,aACtB,UAAU,KAAK,eAAe,UAC5B,aAAa;;;;;;;;;;;;;;EAkBhB;;;;;;;;KAWW,YAAY,UAAU,kBAChC,WAAW,IAAI,EAAE,WAAW,EAAE,YAC5B,EAAE,MAAM,EAAE,MACV,EAAE,WAAW,0BACZ,YAAY,EAAE,MACd,EAAE;;;;;;;;;KAWK,WAAW,kCACtB,MAAM,iBACK;;;;;KAkBA,cAAc"}
1
+ {"version":3,"file":"EnvironmentParser-BmJLlm5_.d.mts","names":[],"sources":["../src/EnvironmentParser.ts"],"mappings":";;;;;;;;cAUa,aAAa,kBAAkB;mBAQzB;mBACA;;;;;;;EAFlB,YACkB,QAAQ,WACR,UAAS;;;;;EAM3B,SAAS,YAAY;;;;;;;;;;;;;;;;;EAmErB;;;;;;;;;;;;;;;;;;;;;cAwBY,kBAAkB,UAAU;mBAWX;;;;mBAPZ;;;;;;EAOjB,YAA6B,QAAQ;;;;;;;;;UAU7B;;;;;;;;UA0EA;;;;;;;EAkDR,OAAO,gBAAgB,aACtB,UAAU,KAAK,eAAe,UAC5B,aAAa;;;;;;;;;;;;;;EAkBhB;;;;;;;;KAWW,YAAY,UAAU,kBAChC,WAAW,IAAI,EAAE,WAAW,EAAE,YAC5B,EAAE,MAAM,EAAE,MACV,EAAE,WAAW,0BACZ,YAAY,EAAE,MACd,EAAE;;;;;;;;;KAWK,WAAW,kCACtB,MAAM,iBACK;;;;;KAkBA,cAAc"}
@@ -1,5 +1,4 @@
1
1
  import get from "lodash.get";
2
- import set from "lodash.set";
3
2
  import { z } from "zod/v4";
4
3
  //#region src/formatter.ts
5
4
  /**
@@ -141,12 +140,12 @@ var ConfigParser = class {
141
140
  const currentPath = [...path, key];
142
141
  if (schema instanceof z.ZodType) {
143
142
  const parsed = schema.safeParse(void 0);
144
- if (parsed.success) set(result, key, parsed.data);
143
+ if (parsed.success) result[key] = parsed.data;
145
144
  else errors.push(...parsed.error.issues.map((issue) => ({
146
145
  ...issue,
147
146
  path: [...currentPath, ...issue.path]
148
147
  })));
149
- } else if (schema) set(result, key, parseDeep(schema, currentPath));
148
+ } else if (schema) result[key] = parseDeep(schema, currentPath);
150
149
  }
151
150
  return result;
152
151
  };
@@ -317,4 +316,4 @@ var EnvironmentParser = class {
317
316
  //#endregion
318
317
  export { isDevelopment as i, EnvironmentParser as n, formatParseError as r, ConfigParser as t };
319
318
 
320
- //# sourceMappingURL=EnvironmentParser-X6Z-jryw.mjs.map
319
+ //# sourceMappingURL=EnvironmentParser-CQDsYpCJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnvironmentParser-CQDsYpCJ.mjs","names":[],"sources":["../src/formatter.ts","../src/EnvironmentParser.ts"],"sourcesContent":["import type { z } from 'zod/v4';\n\n/**\n * Options for formatting parse errors.\n */\nexport interface FormatOptions {\n\t/** Whether to use colors in output. Defaults to auto-detect TTY. */\n\tcolors?: boolean;\n}\n\n/**\n * ANSI color codes for terminal output.\n */\nconst colors = {\n\treset: '\\x1b[0m',\n\tred: '\\x1b[31m',\n\tyellow: '\\x1b[33m',\n\tcyan: '\\x1b[36m',\n\tdim: '\\x1b[2m',\n\tbold: '\\x1b[1m',\n};\n\n/**\n * Formats a ZodError into a user-friendly string for development.\n *\n * @param error - The ZodError to format\n * @param options - Formatting options\n * @returns Formatted error message\n *\n * @example\n * ```typescript\n * try {\n * config.parse();\n * } catch (error) {\n * if (error instanceof ZodError) {\n * console.error(formatParseError(error));\n * }\n * }\n * ```\n *\n * Output:\n * ```\n * Environment Configuration Failed\n *\n * Missing Variables:\n * DATABASE_URL - Required\n * JWT_SECRET - Required\n *\n * Invalid Values:\n * NODE_ENV = \"invalid\"\n * Expected: \"development\" | \"staging\" | \"production\"\n * ```\n */\nexport function formatParseError(\n\terror: z.ZodError,\n\toptions: FormatOptions = {},\n): string {\n\tconst useColors =\n\t\toptions.colors ?? (process.stdout?.isTTY && process.env.NO_COLOR == null);\n\n\tconst c = useColors\n\t\t? colors\n\t\t: { reset: '', red: '', yellow: '', cyan: '', dim: '', bold: '' };\n\n\tconst missingVars: Array<{ name: string; message: string }> = [];\n\tconst invalidVars: Array<{ name: string; value: unknown; message: string }> =\n\t\t[];\n\n\tfor (const issue of error.issues) {\n\t\t// Extract environment variable name from path or message\n\t\tlet envName = '';\n\t\tif (issue.path.length > 0) {\n\t\t\t// Join the full path with '.' to show nested config keys and env var name\n\t\t\tenvName = issue.path.map(String).join('.');\n\t\t} else {\n\t\t\t// Try to extract from message like 'Environment variable \"NAME\": ...'\n\t\t\tconst match = issue.message.match(/Environment variable \"([^\"]+)\"/);\n\t\t\tif (match?.[1]) {\n\t\t\t\tenvName = match[1];\n\t\t\t}\n\t\t}\n\n\t\t// Determine if this is a missing or invalid value\n\t\t// Use type guard for received property\n\t\tconst received = 'received' in issue ? issue.received : undefined;\n\t\tconst isMissing =\n\t\t\tissue.code === 'invalid_type' &&\n\t\t\t(received === 'undefined' || received === 'null');\n\n\t\tif (isMissing) {\n\t\t\tmissingVars.push({\n\t\t\t\tname: envName || 'Unknown',\n\t\t\t\tmessage: cleanMessage(issue.message),\n\t\t\t});\n\t\t} else {\n\t\t\tinvalidVars.push({\n\t\t\t\tname: envName || 'Unknown',\n\t\t\t\tvalue: received,\n\t\t\t\tmessage: cleanMessage(issue.message),\n\t\t\t});\n\t\t}\n\t}\n\n\tconst lines: string[] = [];\n\n\tlines.push('');\n\tlines.push(`${c.red}${c.bold}Environment Configuration Failed${c.reset}`);\n\tlines.push('');\n\n\tif (missingVars.length > 0) {\n\t\tlines.push(`${c.yellow}Missing Variables:${c.reset}`);\n\t\tfor (const v of missingVars) {\n\t\t\tlines.push(` ${c.cyan}${v.name}${c.reset} ${c.dim}- Required${c.reset}`);\n\t\t}\n\t\tlines.push('');\n\t}\n\n\tif (invalidVars.length > 0) {\n\t\tlines.push(`${c.yellow}Invalid Values:${c.reset}`);\n\t\tfor (const v of invalidVars) {\n\t\t\tconst valueStr =\n\t\t\t\tv.value !== undefined ? ` = ${JSON.stringify(v.value)}` : '';\n\t\t\tlines.push(` ${c.cyan}${v.name}${c.reset}${valueStr}`);\n\t\t\tlines.push(` ${c.dim}${v.message}${c.reset}`);\n\t\t}\n\t\tlines.push('');\n\t}\n\n\treturn lines.join('\\n');\n}\n\n/**\n * Cleans up a Zod error message by removing redundant prefixes.\n */\nfunction cleanMessage(message: string): string {\n\t// Remove \"Environment variable \"NAME\": \" prefix if present\n\treturn message.replace(/^Environment variable \"[^\"]+\": /, '');\n}\n\n/**\n * Checks if the current environment is development.\n */\nexport function isDevelopment(): boolean {\n\tconst nodeEnv = process.env.NODE_ENV?.toLowerCase();\n\treturn nodeEnv == null || nodeEnv === 'development' || nodeEnv === 'dev';\n}\n","import get from 'lodash.get';\nimport { z } from 'zod/v4';\nimport { formatParseError, isDevelopment } from './formatter.js';\n\n/**\n * Parses and validates configuration objects against Zod schemas.\n * Handles nested configurations and aggregates validation errors.\n *\n * @template TResponse - The shape of the configuration object\n */\nexport class ConfigParser<TResponse extends EmptyObject> {\n\t/**\n\t * Creates a new ConfigParser instance.\n\t *\n\t * @param config - The configuration object to parse\n\t * @param envVars - Set of environment variable names that were accessed\n\t */\n\tconstructor(\n\t\tprivate readonly config: TResponse,\n\t\tprivate readonly envVars: Set<string> = new Set(),\n\t) {}\n\t/**\n\t * Parses the config object and validates it against the Zod schemas\n\t * @returns The parsed config object\n\t */\n\tparse(): InferConfig<TResponse> {\n\t\tconst errors: z.core.$ZodIssue[] = [];\n\n\t\tconst parseDeep = <T>(config: T, path: string[] = []) => {\n\t\t\tconst result: EmptyObject = {};\n\n\t\t\tif (config && typeof config !== 'object') {\n\t\t\t\treturn config;\n\t\t\t}\n\n\t\t\tfor (const key in config) {\n\t\t\t\tconst schema = config[key];\n\t\t\t\tconst currentPath = [...path, key];\n\n\t\t\t\tif (schema instanceof z.ZodType) {\n\t\t\t\t\tconst parsed = schema.safeParse(undefined);\n\t\t\t\t\tif (parsed.success) {\n\t\t\t\t\t\tresult[key] = parsed.data;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the schema is invalid, assign the error\n\t\t\t\t\t\terrors.push(\n\t\t\t\t\t\t\t...parsed.error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\tpath: [...currentPath, ...(issue.path as string[])],\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (schema) {\n\t\t\t\t\tresult[key] = parseDeep(schema as EmptyObject, currentPath);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result;\n\t\t};\n\n\t\tconst parsedConfig = parseDeep(\n\t\t\tthis.config,\n\t\t) as unknown as InferConfig<TResponse>;\n\n\t\tif (errors.length > 0) {\n\t\t\tconst zodError = new z.ZodError(errors);\n\t\t\t// In development, log a formatted error message before throwing\n\t\t\tif (isDevelopment()) {\n\t\t\t\tconsole.error(formatParseError(zodError));\n\t\t\t}\n\t\t\tthrow zodError;\n\t\t}\n\n\t\treturn parsedConfig;\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed during config creation.\n\t * This is useful for deployment and configuration management to know which env vars are required.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const config = envParser.create((get) => ({\n\t * dbUrl: get('DATABASE_URL').string(),\n\t * port: get('PORT').number()\n\t * }));\n\t *\n\t * config.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.envVars).sort();\n\t}\n}\n\n/**\n * Parses environment variables with type-safe validation using Zod schemas.\n * Provides a fluent API for defining environment variable schemas with automatic\n * error context enrichment.\n *\n * @template T - The type of the configuration object (typically process.env)\n *\n * @example\n * ```typescript\n * const config = new EnvironmentParser(process.env)\n * .create((get) => ({\n * port: get('PORT').string().transform(Number).default(3000),\n * database: {\n * url: get('DATABASE_URL').string().url()\n * }\n * }))\n * .parse();\n * ```\n */\nexport class EnvironmentParser<T extends EmptyObject> {\n\t/**\n\t * Set to track which environment variable names have been accessed\n\t */\n\tprivate readonly accessedVars: Set<string> = new Set();\n\n\t/**\n\t * Creates a new EnvironmentParser instance.\n\t *\n\t * @param config - The configuration object to parse (typically process.env)\n\t */\n\tconstructor(private readonly config: T) {}\n\n\t/**\n\t * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages\n\t * with environment variable context.\n\t *\n\t * @param schema - The Zod schema to wrap\n\t * @param name - The environment variable name for error context\n\t * @returns A wrapped Zod schema with enhanced error reporting\n\t */\n\tprivate wrapSchema = (schema: z.ZodType, name: string): z.ZodType => {\n\t\t// Create a proxy that intercepts all method calls on the schema\n\t\treturn new Proxy(schema, {\n\t\t\tget: (target, prop) => {\n\t\t\t\tif (prop === 'parse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn target.parse(value);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif (error instanceof z.ZodError) {\n\t\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\t\tconst modifiedIssues = error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t\tthrow new z.ZodError(modifiedIssues);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (prop === 'safeParse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\tconst result = target.safeParse(value);\n\n\t\t\t\t\t\tif (!result.success) {\n\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\tconst modifiedIssues = result.error.issues.map(\n\t\t\t\t\t\t\t\t(issue: z.core.$ZodIssue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tsuccess: false as const,\n\t\t\t\t\t\t\t\terror: new z.ZodError(modifiedIssues),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// For any method that returns a new schema (like transform, optional, etc.),\n\t\t\t\t// wrap the result as well\n\t\t\t\tconst originalProp = target[prop as keyof typeof target];\n\t\t\t\tif (typeof originalProp === 'function') {\n\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\tconst result = originalProp.apply(target, args);\n\t\t\t\t\t\t// If the result is a ZodType, wrap it too\n\t\t\t\t\t\tif (result && typeof result === 'object' && 'parse' in result) {\n\t\t\t\t\t\t\treturn this.wrapSchema(result, name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn originalProp;\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Creates a proxied version of the Zod object that wraps all schema creators\n\t * to provide enhanced error messages with environment variable context.\n\t *\n\t * @param name - The environment variable name\n\t * @returns A proxied Zod object with wrapped schema creators\n\t */\n\tprivate getZodGetter = (name: string) => {\n\t\t// Track that this environment variable was accessed\n\t\tthis.accessedVars.add(name);\n\n\t\t// Return an object that has all Zod schemas but with our wrapper\n\t\treturn new Proxy(\n\t\t\t{ ...z },\n\t\t\t{\n\t\t\t\tget: (target, prop) => {\n\t\t\t\t\t// deno-lint-ignore ban-ts-comment\n\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\tconst value = target[prop];\n\n\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\t// Return a wrapper around each Zod schema creator\n\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\tconst schema = value(...args);\n\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// Handle objects like z.coerce\n\t\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\t\treturn new Proxy(value, {\n\t\t\t\t\t\t\tget: (nestedTarget, nestedProp) => {\n\t\t\t\t\t\t\t\tconst nestedValue =\n\t\t\t\t\t\t\t\t\tnestedTarget[nestedProp as keyof typeof nestedTarget];\n\t\t\t\t\t\t\t\tif (typeof nestedValue === 'function') {\n\t\t\t\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\t\t\t\tconst schema = nestedValue(...args);\n\t\t\t\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn nestedValue;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn value;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t};\n\n\t/**\n\t * Creates a new ConfigParser object that can be used to parse the config object\n\t *\n\t * @param builder - A function that takes a getter function and returns a config object\n\t * @returns A ConfigParser object that can be used to parse the config object\n\t */\n\tcreate<TReturn extends EmptyObject>(\n\t\tbuilder: (get: EnvFetcher) => TReturn,\n\t): ConfigParser<TReturn> {\n\t\tconst config = builder(this.getZodGetter);\n\t\treturn new ConfigParser(config, this.accessedVars);\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed via the getter.\n\t * This is useful for build-time analysis to determine which env vars a service needs.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const sniffer = new EnvironmentParser({});\n\t * service.register(sniffer);\n\t * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.accessedVars).sort();\n\t}\n}\n\n/**\n * Infers the TypeScript type of a configuration object based on its Zod schemas.\n * Recursively processes nested objects and extracts types from Zod schemas.\n *\n * @template T - The configuration object type\n */\nexport type InferConfig<T extends EmptyObject> = {\n\t[K in keyof T]: T[K] extends z.ZodSchema\n\t\t? z.infer<T[K]>\n\t\t: T[K] extends Record<string, unknown>\n\t\t\t? InferConfig<T[K]>\n\t\t\t: T[K];\n};\n\n/**\n * Function type for fetching environment variables with Zod validation.\n * Returns a Zod object scoped to a specific environment variable.\n *\n * @template TPath - The environment variable path type\n * @param name - The environment variable name\n * @returns A Zod object for defining the schema\n */\nexport type EnvFetcher<TPath extends string = string> = (\n\tname: TPath,\n) => typeof z;\n\n/**\n * Function type for building environment configuration objects.\n * Takes an EnvFetcher and returns a configuration object with Zod schemas.\n *\n * @template TResponse - The response configuration object type\n * @param get - The environment variable fetcher function\n * @returns The configuration object with Zod schemas\n */\nexport type EnvironmentBuilder<TResponse extends EmptyObject> = (\n\tget: EnvFetcher,\n) => TResponse;\n\n/**\n * Type alias for a generic object with unknown values.\n * Used as a constraint for configuration objects.\n */\nexport type EmptyObject = Record<string | number | symbol, unknown>;\n"],"mappings":";;;;;;AAaA,MAAM,SAAS;CACd,OAAO;CACP,KAAK;CACL,QAAQ;CACR,MAAM;CACN,KAAK;CACL,MAAM;AACP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,iBACf,OACA,UAAyB,CAAC,GACjB;CAIT,MAAM,IAFL,QAAQ,WAAW,QAAQ,QAAQ,SAAS,QAAQ,IAAI,YAAY,QAGlE,SACA;EAAE,OAAO;EAAI,KAAK;EAAI,QAAQ;EAAI,MAAM;EAAI,KAAK;EAAI,MAAM;CAAG;CAEjE,MAAM,cAAwD,CAAC;CAC/D,MAAM,cACL,CAAC;CAEF,KAAK,MAAM,SAAS,MAAM,QAAQ;EAEjC,IAAI,UAAU;EACd,IAAI,MAAM,KAAK,SAAS,GAEvB,UAAU,MAAM,KAAK,IAAI,MAAM,CAAC,CAAC,KAAK,GAAG;OACnC;GAEN,MAAM,QAAQ,MAAM,QAAQ,MAAM,gCAAgC;GAClE,IAAI,QAAQ,IACX,UAAU,MAAM;EAElB;EAIA,MAAM,WAAW,cAAc,QAAQ,MAAM,WAAW,KAAA;EAKxD,IAHC,MAAM,SAAS,mBACd,aAAa,eAAe,aAAa,SAG1C,YAAY,KAAK;GAChB,MAAM,WAAW;GACjB,SAAS,aAAa,MAAM,OAAO;EACpC,CAAC;OAED,YAAY,KAAK;GAChB,MAAM,WAAW;GACjB,OAAO;GACP,SAAS,aAAa,MAAM,OAAO;EACp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AQ,GAAG,SAAgB;KAC1B,MAAM,SAAS,YAAY,GAAG,IAAI;KAClC,OAAO,KAAK,WAAW,QAAQ,IAAI;IACpC;IAED,OAAO;GACR,EACD,CAAC;GAGF,OAAO;EACR,EACD,CACD;CACD;;;;;;;CAQA,OACC,SACwB;EAExB,OAAO,IAAI,aADI,QAAQ,KAAK,YACJ,GAAQ,KAAK,YAAY;CAClD;;;;;;;;;;;;;;CAeA,0BAAoC;EACnC,OAAO,MAAM,KAAK,KAAK,YAAY,CAAC,CAAC,KAAK;CAC3C;AACD"}
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_EnvironmentParser = require("./EnvironmentParser-CmhDxs77.cjs");
2
+ const require_EnvironmentParser = require("./EnvironmentParser-BDC7EQQR.cjs");
3
3
  let zod_v4 = require("zod/v4");
4
4
  //#region src/SnifferEnvironmentParser.ts
5
5
  /**
@@ -1,4 +1,4 @@
1
- import { t as ConfigParser } from "./EnvironmentParser-X6Z-jryw.mjs";
1
+ import { t as ConfigParser } from "./EnvironmentParser-CQDsYpCJ.mjs";
2
2
  import { z } from "zod/v4";
3
3
  //#region src/SnifferEnvironmentParser.ts
4
4
  /**
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_EnvironmentBuilder = require("./EnvironmentBuilder-wJH3EBbJ.cjs");
3
- const require_EnvironmentParser = require("./EnvironmentParser-CmhDxs77.cjs");
3
+ const require_EnvironmentParser = require("./EnvironmentParser-BDC7EQQR.cjs");
4
4
  exports.ConfigParser = require_EnvironmentParser.ConfigParser;
5
5
  exports.EnvironmentBuilder = require_EnvironmentBuilder.EnvironmentBuilder;
6
6
  exports.EnvironmentParser = require_EnvironmentParser.EnvironmentParser;
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  import { n as environmentCase, t as EnvironmentBuilder } from "./EnvironmentBuilder-Rxq657gm.mjs";
2
- import { i as isDevelopment, n as EnvironmentParser, r as formatParseError, t as ConfigParser } from "./EnvironmentParser-X6Z-jryw.mjs";
2
+ import { i as isDevelopment, n as EnvironmentParser, r as formatParseError, t as ConfigParser } from "./EnvironmentParser-CQDsYpCJ.mjs";
3
3
  export { ConfigParser, EnvironmentBuilder, EnvironmentParser, environmentCase, formatParseError, isDevelopment };
package/dist/sst.cjs CHANGED
@@ -26,6 +26,11 @@ let ResourceType = /* @__PURE__ */ function(ResourceType) {
26
26
  ResourceType["StaticSite"] = "sst:aws:StaticSite";
27
27
  ResourceType["Email"] = "gkm:aws:Email";
28
28
  ResourceType["Cache"] = "gkm:aws:Cache";
29
+ ResourceType["ExternalApi"] = "gkm:aws:ExternalApi";
30
+ ResourceType["Credential"] = "gkm:aws:Credential";
31
+ ResourceType["Encryption"] = "gkm:aws:Encryption";
32
+ ResourceType["WebSocketApi"] = "gkm:aws:WebSocketApi";
33
+ ResourceType["Inbox"] = "gkm:aws:Inbox";
29
34
  return ResourceType;
30
35
  }({});
31
36
  const secretResolver = (name, value) => ({ [name]: value.value });
@@ -51,6 +56,21 @@ const queueResolver = (name, value) => ({
51
56
  [`${name}PublisherConnectionString`]: `sqs://?queueUrl=${encodeURIComponent(value.url)}`
52
57
  });
53
58
  const dynamoResolver = (name, value) => ({ [`${name}Name`]: value.name });
59
+ const externalApiResolver = (name, value) => ({
60
+ [`${name}Url`]: value.url,
61
+ [`${name}Credentials`]: value.credentials
62
+ });
63
+ const credentialResolver = (name, value) => ({ [`${name}Credentials`]: value.credentials });
64
+ const encryptionResolver = (name, value) => ({ [`${name}Url`]: value.url });
65
+ const inboxResolver = (name, value) => ({
66
+ [`${name}Url`]: value.url,
67
+ [`${name}Domain`]: value.domain
68
+ });
69
+ const webSocketApiResolver = (name, value) => ({
70
+ [`${name}Url`]: value.url,
71
+ [`${name}TrustedOrigins`]: value.trustedOrigins,
72
+ [`${name}PublisherConnectionString`]: value.publisherConnectionString
73
+ });
54
74
  const noopResolver = () => ({});
55
75
  /**
56
76
  * Pre-configured resolvers for all SST resource types.
@@ -71,7 +91,12 @@ const sstResolvers = {
71
91
  ["sst:aws:ApiGatewayV2"]: noopResolver,
72
92
  ["sst:aws:SnsTopic"]: topicResolver,
73
93
  ["sst:aws:Dynamo"]: dynamoResolver,
74
- ["sst:aws:Queue"]: queueResolver
94
+ ["sst:aws:Queue"]: queueResolver,
95
+ ["gkm:aws:ExternalApi"]: externalApiResolver,
96
+ ["gkm:aws:Credential"]: credentialResolver,
97
+ ["gkm:aws:Encryption"]: encryptionResolver,
98
+ ["gkm:aws:Inbox"]: inboxResolver,
99
+ ["gkm:aws:WebSocketApi"]: webSocketApiResolver
75
100
  };
76
101
  /**
77
102
  * SST-specific environment builder with built-in resolvers for all known
package/dist/sst.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sst.cjs","names":["EnvironmentBuilder","EnvironmentBuilder"],"sources":["../src/SstEnvironmentBuilder.ts","../src/SstEnvValidator.ts","../src/sst.ts"],"sourcesContent":["import {\n\tEnvironmentBuilder,\n\ttype EnvironmentBuilderOptions,\n\ttype EnvironmentResolver,\n\ttype EnvRecord,\n\ttype InputValue,\n\ttype Resolvers,\n} from './EnvironmentBuilder';\n\n/**\n * Enumeration of supported SST (Serverless Stack Toolkit) resource types.\n * Used to identify and process different AWS and SST resources.\n */\nexport enum ResourceType {\n\t// Legacy format (dot notation)\n\tApiGatewayV2 = 'sst.aws.ApiGatewayV2',\n\tPostgres = 'sst.aws.Postgres',\n\tFunction = 'sst.aws.Function',\n\tObjectStorage = 'sst.aws.Bucket',\n\tVpc = 'sst.aws.Vpc',\n\tSecret = 'sst.sst.Secret',\n\tDynamo = 'sst.aws.Dynamo',\n\tQueue = 'sst.aws.Queue',\n\n\t// Modern format (colon notation)\n\tSSTSecret = 'sst:sst:Secret',\n\tSSTFunction = 'sst:sst:Function',\n\tSSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',\n\tSSTPostgres = 'sst:aws:Postgres',\n\tSSTObjectStorage = 'sst:aws:Bucket',\n\tSnsTopic = 'sst:aws:SnsTopic',\n\tSSTDynamo = 'sst:aws:Dynamo',\n\tSSTQueue = 'sst:aws:Queue',\n\t// A distribution, twice over: a file server and a static site are the same\n\t// infrastructure with different contents behind it, and they are separate\n\t// entries because what they provide is read under different ids, not\n\t// because SST builds them differently.\n\tFileServer = 'sst:aws:Router',\n\tStaticSite = 'sst:aws:StaticSite',\n\t// Neither is an SST component: mail is an IAM chain and a composed URL, and\n\t// a cache is whatever the selected backend turned out to be.\n\tEmail = 'gkm:aws:Email',\n\tCache = 'gkm:aws:Cache',\n}\n\n/**\n * AWS API Gateway V2 resource type.\n * Represents an HTTP/WebSocket API.\n */\nexport type ApiGatewayV2 = {\n\ttype: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;\n\turl: string;\n};\n\n/**\n * PostgreSQL database resource type.\n * Contains all connection details needed to connect to the database.\n */\nexport type Postgres = {\n\ttype: ResourceType.Postgres | ResourceType.SSTPostgres;\n\tdatabase: string;\n\thost: string;\n\tpassword: string;\n\tport: number;\n\tusername: string;\n};\n\n/**\n * AWS Lambda Function resource type.\n */\nexport type Function = {\n\ttype: ResourceType.Function | ResourceType.SSTFunction;\n\tname: string;\n};\n\n/**\n * AWS S3 Bucket resource type.\n */\nexport type Bucket = {\n\ttype: ResourceType.ObjectStorage | ResourceType.SSTObjectStorage;\n\tname: string;\n\t/**\n\t * Supplied by `@geekmidas/cloud`'s ObjectStorage, which widens SST's link to\n\t * carry them — a bucket may not be in the reader's region, and the URL is\n\t * composed where the resource's shape is known.\n\t */\n\tregion?: string;\n\turl?: string;\n};\n\n/**\n * AWS VPC (Virtual Private Cloud) resource type.\n */\nexport type Vpc = {\n\ttype: ResourceType.Vpc;\n\tbastion: string;\n};\n\n/**\n * Secret resource type for storing sensitive values.\n */\nexport type Secret = {\n\ttype: ResourceType.Secret | ResourceType.SSTSecret;\n\tvalue: string;\n};\n\n/**\n * AWS SNS Topic resource type.\n */\nexport type SnsTopic = {\n\ttype: ResourceType.SnsTopic;\n\tarn: string;\n};\n\n/**\n * AWS SQS Queue resource type.\n */\nexport type Queue = {\n\ttype: ResourceType.Queue | ResourceType.SSTQueue;\n\turl: string;\n\tarn: string;\n};\n\n/**\n * AWS DynamoDB Table resource type.\n */\nexport type Dynamo = {\n\ttype: ResourceType.Dynamo | ResourceType.SSTDynamo;\n\tname: string;\n};\n\n/**\n * Union type of all supported SST resource types.\n */\nexport type SstResource =\n\t| ApiGatewayV2\n\t| Postgres\n\t| Function\n\t| Bucket\n\t| Vpc\n\t| Secret\n\t| SnsTopic\n\t| Queue\n\t| Dynamo;\n\n// Value types without the `type` key (for resolver parameters)\ntype SecretValue = Omit<Secret, 'type'>;\ntype PostgresValue = Omit<Postgres, 'type'>;\ntype BucketValue = Omit<Bucket, 'type'>;\ntype SnsTopicValue = Omit<SnsTopic, 'type'>;\ntype QueueValue = Omit<Queue, 'type'>;\ntype DynamoValue = Omit<Dynamo, 'type'>;\n\n/**\n * Function type for processing a specific resource type into environment variables.\n *\n * @template K - The specific resource type (without `type` key)\n * @param name - The resource name\n * @param value - The resource value (without `type` key)\n * @returns Object mapping environment variable names to values\n */\nexport type ResourceProcessor<K> = (name: string, value: K) => EnvRecord;\n\n// SST Resource Resolvers (receive values without `type` key)\n\nconst secretResolver = (name: string, value: SecretValue) => ({\n\t[name]: value.value,\n});\n\nconst postgresResolver = (key: string, value: PostgresValue) => ({\n\t[`${key}Name`]: value.database,\n\t[`${key}Host`]: value.host,\n\t[`${key}Password`]: value.password,\n\t[`${key}Port`]: value.port,\n\t[`${key}Username`]: value.username,\n\t[`${key}Url`]: `postgresql://${encodeURIComponent(value.username)}:${encodeURIComponent(value.password)}@${value.host}:${value.port}/${value.database}`,\n});\n\nconst bucketResolver = (name: string, value: BucketValue) => ({\n\t[`${name}Name`]: value.name,\n\t// The single URL a construct reads. Composed by the component, which knows\n\t// its own shape; this only renames it into env case. Always emitted, even\n\t// when absent, so `resolveEnvKeys` can derive the key from the link's type\n\t// alone — a bucket linked without our component yields an empty one.\n\t[`${name}Url`]: value.url ?? '',\n});\n\nconst topicResolver = (name: string, value: SnsTopicValue) => ({\n\t[`${name}Arn`]: value.arn,\n\t// A publisher connection string for `@geekmidas/events` (SNS); region is\n\t// resolved from the ARN / AWS_REGION at runtime.\n\t[`${name}PublisherConnectionString`]: `sns://?topicArn=${encodeURIComponent(value.arn)}`,\n});\n\nconst queueResolver = (name: string, value: QueueValue) => ({\n\t[`${name}Url`]: value.url,\n\t[`${name}Arn`]: value.arn,\n\t// A publisher connection string for `@geekmidas/events` (SQS); region is\n\t// resolved from the URL / AWS_REGION at runtime.\n\t[`${name}PublisherConnectionString`]: `sqs://?queueUrl=${encodeURIComponent(value.url)}`,\n});\n\nconst dynamoResolver = (name: string, value: DynamoValue) => ({\n\t[`${name}Name`]: value.name,\n});\n\nconst noopResolver = () => ({});\n\n/**\n * Pre-configured resolvers for all SST resource types.\n */\nexport const sstResolvers: Resolvers = {\n\t// Legacy format\n\t[ResourceType.ApiGatewayV2]: noopResolver,\n\t[ResourceType.Function]: noopResolver,\n\t[ResourceType.Vpc]: noopResolver,\n\t[ResourceType.Secret]: secretResolver,\n\t[ResourceType.Postgres]: postgresResolver,\n\t[ResourceType.ObjectStorage]: bucketResolver,\n\t[ResourceType.Dynamo]: dynamoResolver,\n\t[ResourceType.Queue]: queueResolver,\n\n\t// Modern format\n\t[ResourceType.SSTSecret]: secretResolver,\n\t[ResourceType.SSTObjectStorage]: bucketResolver,\n\t[ResourceType.SSTFunction]: noopResolver,\n\t[ResourceType.SSTPostgres]: postgresResolver,\n\t[ResourceType.SSTApiGatewayV2]: noopResolver,\n\t[ResourceType.SnsTopic]: topicResolver,\n\t[ResourceType.SSTDynamo]: dynamoResolver,\n\t[ResourceType.SSTQueue]: queueResolver,\n};\n\n/**\n * All known SST resource type strings.\n */\ntype SstResourceTypeString = `${ResourceType}`;\n\n/**\n * Extracts the `type` string value from an input value.\n */\ntype ExtractType<T> = T extends { type: infer U extends string } ? U : never;\n\n/**\n * Removes the `type` key from an object type.\n */\ntype OmitType<T> = T extends { type: string } ? Omit<T, 'type'> : never;\n\n/**\n * Extracts all unique `type` values from a record (excluding plain strings).\n */\ntype AllTypeValues<TRecord extends Record<string, InputValue>> = {\n\t[K in keyof TRecord]: ExtractType<TRecord[K]>;\n}[keyof TRecord];\n\n/**\n * Extracts only the custom (non-SST) type values from a record.\n */\ntype CustomTypeValues<TRecord extends Record<string, InputValue>> = Exclude<\n\tAllTypeValues<TRecord>,\n\tSstResourceTypeString\n>;\n\n/**\n * For a given type value, finds the corresponding value type (without `type` key).\n */\ntype ValueForType<\n\tTRecord extends Record<string, InputValue>,\n\tTType extends string,\n> = {\n\t[K in keyof TRecord]: TRecord[K] extends { type: TType }\n\t\t? OmitType<TRecord[K]>\n\t\t: never;\n}[keyof TRecord];\n\n/**\n * Generates typed resolvers for custom (non-SST) types in the input record.\n */\ntype CustomResolvers<TRecord extends Record<string, InputValue>> =\n\tCustomTypeValues<TRecord> extends never\n\t\t? Resolvers | undefined\n\t\t: {\n\t\t\t\t[TType in CustomTypeValues<TRecord>]: EnvironmentResolver<\n\t\t\t\t\tValueForType<TRecord, TType>\n\t\t\t\t>;\n\t\t\t};\n\n/**\n * SST-specific environment builder with built-in resolvers for all known\n * SST resource types.\n *\n * Wraps the generic EnvironmentBuilder with pre-configured SST resolvers.\n *\n * @template TRecord - The input record type for type inference\n *\n * @example\n * ```typescript\n * const env = new SstEnvironmentBuilder({\n * database: { type: 'sst:aws:Postgres', host: '...', ... },\n * apiKey: { type: 'sst:sst:Secret', value: 'secret' },\n * appName: 'my-app',\n * }).build();\n *\n * // With custom resolvers (typed based on input)\n * const env = new SstEnvironmentBuilder(\n * {\n * database: postgresResource,\n * custom: { type: 'my-custom' as const, data: 'foo' },\n * },\n * {\n * // TypeScript requires 'my-custom' resolver with typed value\n * 'my-custom': (key, value) => ({ [`${key}Data`]: value.data }),\n * }\n * ).build();\n * ```\n */\nexport class SstEnvironmentBuilder<\n\tTRecord extends Record<string, SstResource | InputValue | string>,\n> {\n\tprivate readonly builder: EnvironmentBuilder<\n\t\tRecord<string, InputValue>,\n\t\tResolvers\n\t>;\n\n\t/**\n\t * Create a new SST environment builder.\n\t *\n\t * @param record - Object containing SST resources, custom resources, and/or string values\n\t * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)\n\t * @param options - Optional configuration options\n\t */\n\tconstructor(\n\t\trecord: TRecord,\n\t\tadditionalResolvers?: CustomResolvers<TRecord>,\n\t\toptions?: EnvironmentBuilderOptions,\n\t) {\n\t\t// Merge resolvers with custom ones taking precedence\n\t\tconst mergedResolvers: Resolvers = additionalResolvers\n\t\t\t? { ...sstResolvers, ...additionalResolvers }\n\t\t\t: sstResolvers;\n\n\t\tthis.builder = new EnvironmentBuilder(\n\t\t\trecord as Record<string, InputValue>,\n\t\t\tmergedResolvers,\n\t\t\toptions,\n\t\t);\n\t}\n\n\t/**\n\t * Build environment variables from the input record.\n\t *\n\t * @returns A record of environment variables\n\t */\n\tbuild(): EnvRecord {\n\t\treturn this.builder.build();\n\t}\n}\n\nexport type {\n\tEnvironmentBuilderOptions,\n\tEnvRecord,\n\tEnvValue,\n} from './EnvironmentBuilder';\n// Re-export useful types\nexport { environmentCase } from './EnvironmentBuilder';\n","import { EnvironmentBuilder, type InputValue } from './EnvironmentBuilder';\nimport { type SstResource, sstResolvers } from './SstEnvironmentBuilder';\n\n/**\n * Variables AWS Lambda injects into the runtime. Always valid on AWS, but never\n * assumed — opt in via `platform: 'aws'` or by spreading {@link AWS_RUNTIME_ENV_VARS}\n * into `whitelist`.\n */\nexport const AWS_RUNTIME_ENV_VARS = [\n\t'AWS_REGION',\n\t'AWS_DEFAULT_REGION',\n\t'AWS_ENDPOINT_URL',\n\t'AWS_ENDPOINT',\n\t'AWS_ACCESS_KEY_ID',\n\t'AWS_SECRET_ACCESS_KEY',\n\t'AWS_SESSION_TOKEN',\n\t'AWS_LAMBDA_FUNCTION_NAME',\n\t'AWS_LAMBDA_FUNCTION_VERSION',\n] as const;\n\n/**\n * Variables GCP injects into Cloud Functions / Cloud Run.\n */\nexport const GCP_RUNTIME_ENV_VARS = [\n\t'GOOGLE_CLOUD_PROJECT',\n\t'GCP_PROJECT',\n\t'FUNCTION_TARGET',\n\t'FUNCTION_SIGNATURE_TYPE',\n\t'K_SERVICE',\n\t'K_REVISION',\n\t'K_CONFIGURATION',\n\t'PORT',\n] as const;\n\n/**\n * Variables Cloudflare exposes to Workers. Workers inject almost nothing into\n * the global env, so this is intentionally minimal.\n */\nexport const CLOUDFLARE_RUNTIME_ENV_VARS = [\n\t'CF_PAGES',\n\t'CF_PAGES_URL',\n] as const;\n\n/**\n * Registry of platform → always-valid runtime variables. Export, don't assume:\n * a caller states the platform it deploys to and the matching set is trusted.\n */\nexport const PLATFORM_ENV_VARS = {\n\taws: AWS_RUNTIME_ENV_VARS,\n\tgcp: GCP_RUNTIME_ENV_VARS,\n\tcloudflare: CLOUDFLARE_RUNTIME_ENV_VARS,\n} as const;\n\nexport type Platform = keyof typeof PLATFORM_ENV_VARS;\n\n/**\n * The always-valid runtime variables for a platform. The \"whitelist construct\":\n * resolve a platform to its set, to spread into `whitelist` or compare against.\n */\nexport function platformEnvVars(platform: Platform): readonly string[] {\n\treturn PLATFORM_ENV_VARS[platform];\n}\n\n/** How many link-provided vars to list in an error before truncating. */\nconst MAX_LISTED_VARS = 8;\n\n/** Minimum similarity for a variable to be offered as a \"did you mean\". */\nconst SUGGESTION_THRESHOLD = 0.3;\n\n/**\n * Input shape for the validator: the same record `SstEnvironmentBuilder`\n * accepts — keyed by resource name, valued by an SST resource (or a plain\n * string for pass-through env vars).\n */\nexport type LinkRecord = Record<string, SstResource | InputValue | string>;\n\nexport interface ValidationResult {\n\tvalid: boolean;\n\t/** Requested variables that are not available (excluding optional `?` vars). */\n\tinvalidVars: string[];\n\t/** Every variable the links + whitelist make available. */\n\tavailableVars: string[];\n\t/** Nearest available matches for each invalid variable (best first). */\n\tsuggestions: Record<string, string[]>;\n}\n\nexport interface EnvValidatorOptions {\n\t/**\n\t * Platform whose runtime-injected variables are always valid. Omit to assume\n\t * none — the validator never bakes in a platform's variables.\n\t */\n\tplatform?: Platform;\n\t/**\n\t * Extra always-valid variables in addition to the platform set — typically\n\t * the keys of a function's explicit `environment`.\n\t */\n\twhitelist?: readonly string[];\n\t/**\n\t * Label for the deployable unit (e.g. a function name), used in error\n\t * messages so a failure points at exactly one unit.\n\t */\n\tcontext?: string;\n}\n\n/**\n * Levenshtein edit distance between two strings.\n */\nfunction levenshtein(a: string, b: string): number {\n\tconst m = a.length;\n\tconst n = b.length;\n\tif (m === 0) return n;\n\tif (n === 0) return m;\n\n\tlet prev = Array.from({ length: n + 1 }, (_, i) => i);\n\n\tfor (let i = 1; i <= m; i++) {\n\t\tconst curr: number[] = [i];\n\t\tfor (let j = 1; j <= n; j++) {\n\t\t\tconst cost = a[i - 1] === b[j - 1] ? 0 : 1;\n\t\t\tconst del = (prev[j] ?? 0) + 1;\n\t\t\tconst ins = (curr[j - 1] ?? 0) + 1;\n\t\t\tconst sub = (prev[j - 1] ?? 0) + cost;\n\t\t\tcurr[j] = Math.min(del, ins, sub);\n\t\t}\n\t\tprev = curr;\n\t}\n\n\treturn prev[n] ?? 0;\n}\n\n/**\n * Similarity in `[0, 1]` combining edit distance with `_`-token overlap, so both\n * near-typos (a missing underscore) and renames (`DATABASE_URL` ~ `DB_URL`,\n * which share the `URL` token) are caught.\n */\nfunction similarity(a: string, b: string): number {\n\tconst editSim = 1 - levenshtein(a, b) / Math.max(a.length, b.length, 1);\n\n\tconst ta = new Set(a.split('_').filter(Boolean));\n\tconst tb = new Set(b.split('_').filter(Boolean));\n\tconst shared = [...ta].filter((t) => tb.has(t)).length;\n\tconst union = new Set([...ta, ...tb]).size || 1;\n\tconst tokenSim = shared / union;\n\n\t// Nudge token-overlap matches ahead of coincidental edit-distance ones, so a\n\t// rename like DATABASE_URL prefers DB_URL (shares `URL`) over DB_PASSWORD.\n\treturn Math.max(editSim, tokenSim * 1.15);\n}\n\n/**\n * Returns the nearest available variables to `missing`, best first, limited to\n * those above {@link SUGGESTION_THRESHOLD}.\n */\nfunction suggestionsFor(\n\tmissing: string,\n\tavailable: readonly string[],\n\tmax = 1,\n): string[] {\n\treturn available\n\t\t.map((candidate) => ({ candidate, score: similarity(missing, candidate) }))\n\t\t.filter((s) => s.score >= SUGGESTION_THRESHOLD)\n\t\t.sort((a, b) => b.score - a.score)\n\t\t.slice(0, max)\n\t\t.map((s) => s.candidate);\n}\n\n/**\n * Thrown when a deployable unit requires environment variables its links do not\n * provide. Carries the structured `missing`/`available`/`suggestions` so callers\n * can inspect the failure programmatically, not just read the message.\n */\nexport class EnvValidationError extends Error {\n\treadonly isEnvValidationError = true;\n\treadonly missing: string[];\n\treadonly available: string[];\n\treadonly suggestions: Record<string, string[]>;\n\treadonly context?: string;\n\n\tconstructor(args: {\n\t\tmissing: string[];\n\t\tavailable: string[];\n\t\tlinkVars: string[];\n\t\tsuggestions: Record<string, string[]>;\n\t\tcontext?: string;\n\t}) {\n\t\tsuper(EnvValidationError.format(args));\n\t\tthis.name = 'EnvValidationError';\n\t\tthis.missing = args.missing;\n\t\tthis.available = args.available;\n\t\tthis.suggestions = args.suggestions;\n\t\tthis.context = args.context;\n\t\t// V8-only; keeps the constructor out of the stack trace.\n\t\t(\n\t\t\tError as unknown as {\n\t\t\t\tcaptureStackTrace?(target: object, ctor?: unknown): void;\n\t\t\t}\n\t\t).captureStackTrace?.(this, EnvValidationError);\n\t}\n\n\tprivate static format(args: {\n\t\tmissing: string[];\n\t\tlinkVars: string[];\n\t\tsuggestions: Record<string, string[]>;\n\t\tcontext?: string;\n\t}): string {\n\t\tconst { missing, linkVars, suggestions, context } = args;\n\t\tconst who = context ? `'${context}'` : 'a deployable unit';\n\n\t\tconst width = Math.max(...missing.map((v) => v.length));\n\t\tconst lines = missing.map((v) => {\n\t\t\tconst hints = suggestions[v] ?? [];\n\t\t\tconst hint = hints.length ? `(did you mean ${hints.join(' or ')}?)` : '';\n\t\t\treturn ` - ${v.padEnd(width)} ${hint}`.trimEnd();\n\t\t});\n\n\t\tlet provided: string;\n\t\tif (linkVars.length === 0) {\n\t\t\tprovided = '(no links provide environment variables)';\n\t\t} else {\n\t\t\tconst shown = linkVars.slice(0, MAX_LISTED_VARS).join(', ');\n\t\t\tconst extra =\n\t\t\t\tlinkVars.length > MAX_LISTED_VARS\n\t\t\t\t\t? ` ...(+${linkVars.length - MAX_LISTED_VARS})`\n\t\t\t\t\t: '';\n\t\t\tprovided = `Provided by links: ${shown}${extra}`;\n\t\t}\n\n\t\treturn `${who} is missing required env vars:\\n${lines.join('\\n')}\\n\\n${provided}`;\n\t}\n}\n\n/**\n * Derives the set of environment-variable **keys** a group of linked resources\n * will produce at runtime — without resolving any value.\n *\n * This reuses the runtime resolvers (`sstResolvers`) via {@link EnvironmentBuilder},\n * so the keys computed here are exactly the keys a deployed function receives:\n * the validator and the runtime resolution share a single source of truth and\n * cannot drift. Because every resolver's output keys depend only on the record\n * key and the resource `type` (never the value), each resource is reduced to\n * `{ type }` before building, so no SST `Output` is ever read.\n *\n * @example\n * resolveEnvKeys({ db: { type: ResourceType.Postgres } });\n * // ['DB_NAME', 'DB_HOST', 'DB_PASSWORD', 'DB_PORT', 'DB_USERNAME', 'DB_URL']\n */\nexport function resolveEnvKeys(record: LinkRecord): string[] {\n\tconst typeOnly: Record<string, InputValue> = {};\n\tfor (const [key, value] of Object.entries(record)) {\n\t\ttypeOnly[key] = typeof value === 'string' ? '' : { type: value.type };\n\t}\n\treturn Object.keys(new EnvironmentBuilder(typeOnly, sstResolvers).build());\n}\n\n/**\n * Validates that the environment variables a deployable unit requires are\n * actually provided by its linked resources — at infra time, before deploy.\n *\n * Available variables are the union of the keys derived from `links`\n * ({@link resolveEnvKeys}), the chosen platform's runtime variables (only when\n * `options.platform` is set — nothing is assumed), and any `options.whitelist`\n * (e.g. the keys of a function's explicit `environment`). A requested variable\n * suffixed with `?` is treated as optional and never causes a failure.\n *\n * @example\n * const validator = new EnvValidator(\n * { db: { type: ResourceType.Postgres } },\n * { platform: 'aws', whitelist: ['APP_NAME'], context: 'orders-fn' },\n * );\n * validator.assert(['DB_HOST', 'AWS_REGION', 'APP_NAME', 'SENTRY_DSN?']); // ok\n * validator.assert(['DATABASE_URL']); // throws EnvValidationError (did you mean DB_URL?)\n */\nexport class EnvValidator {\n\t/** Every variable available — link-derived, platform, and extra whitelist. */\n\treadonly availableVars: string[];\n\t/** Just the variables the links provide (used for error context). */\n\treadonly linkVars: string[];\n\treadonly context?: string;\n\tprivate readonly availableSet: Set<string>;\n\t/** Per-link (record key → its env-var keys), for least-privilege filtering. */\n\tprivate readonly linkVarsByName: Map<string, string[]>;\n\n\tconstructor(links: LinkRecord, options: EnvValidatorOptions = {}) {\n\t\tconst { platform, whitelist = [], context } = options;\n\t\tthis.context = context;\n\t\tthis.linkVarsByName = new Map(\n\t\t\tObject.entries(links).map(([name, value]) => [\n\t\t\t\tname,\n\t\t\t\tresolveEnvKeys({ [name]: value }),\n\t\t\t]),\n\t\t);\n\t\tthis.linkVars = [...this.linkVarsByName.values()].flat();\n\t\tthis.availableVars = [\n\t\t\t...this.linkVars,\n\t\t\t...(platform ? PLATFORM_ENV_VARS[platform] : []),\n\t\t\t...whitelist,\n\t\t];\n\t\tthis.availableSet = new Set(this.availableVars);\n\t}\n\n\t/**\n\t * Returns the names of the links that provide at least one of the requested\n\t * variables — so a construct can attach only the links a unit actually needs\n\t * (least privilege) rather than the whole pool. Trailing `?` is ignored.\n\t */\n\tgetProvidersForEnvVars(requestedEnvVars: readonly string[]): string[] {\n\t\tconst requested = new Set(\n\t\t\trequestedEnvVars.map((v) => (v.endsWith('?') ? v.slice(0, -1) : v)),\n\t\t);\n\t\tconst providers: string[] = [];\n\t\tfor (const [name, vars] of this.linkVarsByName) {\n\t\t\tif (vars.some((v) => requested.has(v))) providers.push(name);\n\t\t}\n\t\treturn providers;\n\t}\n\n\t/**\n\t * Checks every requested variable against the available set. Variables\n\t * ending in `?` are optional and never reported as invalid. Invalid\n\t * variables come back with their nearest available matches.\n\t */\n\tvalidate(requestedEnvVars: readonly string[]): ValidationResult {\n\t\tconst invalidVars = requestedEnvVars.filter((envVar) => {\n\t\t\tif (envVar.endsWith('?')) return false;\n\t\t\treturn !this.availableSet.has(envVar);\n\t\t});\n\n\t\tconst suggestions: Record<string, string[]> = {};\n\t\tfor (const envVar of invalidVars) {\n\t\t\tconst matches = suggestionsFor(envVar, this.availableVars);\n\t\t\tif (matches.length) suggestions[envVar] = matches;\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: invalidVars.length === 0,\n\t\t\tinvalidVars,\n\t\t\tavailableVars: this.availableVars,\n\t\t\tsuggestions,\n\t\t};\n\t}\n\n\t/**\n\t * Asserts that every requested variable is available, throwing an\n\t * {@link EnvValidationError} otherwise. Intended to run in a construct's\n\t * constructor so a misconfigured `sst.config.ts` fails at synth time, before\n\t * any AWS call.\n\t */\n\tassert(requestedEnvVars: readonly string[]): void {\n\t\tconst { valid, invalidVars, suggestions } = this.validate(requestedEnvVars);\n\n\t\tif (!valid) {\n\t\t\tthrow new EnvValidationError({\n\t\t\t\tmissing: invalidVars,\n\t\t\t\tavailable: this.availableVars,\n\t\t\t\tlinkVars: this.linkVars,\n\t\t\t\tsuggestions,\n\t\t\t\tcontext: this.context,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Whether a single variable is available. Does not treat a trailing `?` as\n\t * optional — pass the bare name.\n\t */\n\thas(envVar: string): boolean {\n\t\treturn this.availableSet.has(envVar);\n\t}\n}\n","// Re-export everything from SstEnvironmentBuilder\n\n// Re-export types from EnvironmentBuilder\nexport type {\n\tEnvironmentBuilderOptions,\n\tEnvRecord,\n\tEnvValue,\n} from './EnvironmentBuilder';\n\n// Re-export environmentCase from EnvironmentBuilder\nexport { environmentCase } from './EnvironmentBuilder';\nexport {\n\ttype ApiGatewayV2,\n\ttype Bucket,\n\ttype Dynamo,\n\ttype Function,\n\ttype Postgres,\n\ttype Queue,\n\ttype ResourceProcessor,\n\tResourceType,\n\ttype Secret,\n\ttype SnsTopic,\n\tSstEnvironmentBuilder,\n\ttype SstResource,\n\tsstResolvers,\n\ttype Vpc,\n} from './SstEnvironmentBuilder';\n\nexport {\n\tAWS_RUNTIME_ENV_VARS,\n\tCLOUDFLARE_RUNTIME_ENV_VARS,\n\tEnvValidationError,\n\tEnvValidator,\n\ttype EnvValidatorOptions,\n\tGCP_RUNTIME_ENV_VARS,\n\ttype LinkRecord,\n\tPLATFORM_ENV_VARS,\n\ttype Platform,\n\tplatformEnvVars,\n\tresolveEnvKeys,\n\ttype ValidationResult,\n} from './SstEnvValidator';\n\n// Import for deprecated function\nimport {\n\tSstEnvironmentBuilder,\n\ttype SstResource,\n} from './SstEnvironmentBuilder';\n\n/**\n * @deprecated Use `new SstEnvironmentBuilder(record).build()` instead.\n *\n * Normalizes SST resources and plain strings into environment variables.\n * Processes resources based on their type and converts names to environment case.\n *\n * @param record - Object containing resources and/or string values\n * @returns Normalized environment variables object\n *\n * @example\n * // Old usage (deprecated):\n * normalizeResourceEnv({ database: postgresResource })\n *\n * // New usage:\n * new SstEnvironmentBuilder({ database: postgresResource }).build()\n */\nexport function normalizeResourceEnv(\n\trecord: Record<string, SstResource | string>,\n): Record<string, string | number | boolean | Record<string, unknown>> {\n\treturn new SstEnvironmentBuilder(record).build();\n}\n\n// Keep Resource type as deprecated alias for backwards compatibility\n/**\n * @deprecated Use `SstResource` instead.\n */\nexport type Resource = SstResource;\n"],"mappings":";;;;;;;AAaA,IAAY,eAAL,yBAAA,cAAA;CAEN,aAAA,kBAAA;CACA,aAAA,cAAA;CACA,aAAA,cAAA;CACA,aAAA,mBAAA;CACA,aAAA,SAAA;CACA,aAAA,YAAA;CACA,aAAA,YAAA;CACA,aAAA,WAAA;CAGA,aAAA,eAAA;CACA,aAAA,iBAAA;CACA,aAAA,qBAAA;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;;;;;;;;;;;;;;AC/SA,SAAgB,qBACf,QACsE;CACtE,OAAO,IAAI,sBAAsB,MAAM,CAAC,CAAC,MAAM;AAChD"}
1
+ {"version":3,"file":"sst.cjs","names":["EnvironmentBuilder","EnvironmentBuilder"],"sources":["../src/SstEnvironmentBuilder.ts","../src/SstEnvValidator.ts","../src/sst.ts"],"sourcesContent":["import {\n\tEnvironmentBuilder,\n\ttype EnvironmentBuilderOptions,\n\ttype EnvironmentResolver,\n\ttype EnvRecord,\n\ttype InputValue,\n\ttype Resolvers,\n} from './EnvironmentBuilder';\n\n/**\n * Enumeration of supported SST (Serverless Stack Toolkit) resource types.\n * Used to identify and process different AWS and SST resources.\n */\nexport enum ResourceType {\n\t// Legacy format (dot notation)\n\tApiGatewayV2 = 'sst.aws.ApiGatewayV2',\n\tPostgres = 'sst.aws.Postgres',\n\tFunction = 'sst.aws.Function',\n\tObjectStorage = 'sst.aws.Bucket',\n\tVpc = 'sst.aws.Vpc',\n\tSecret = 'sst.sst.Secret',\n\tDynamo = 'sst.aws.Dynamo',\n\tQueue = 'sst.aws.Queue',\n\n\t// Modern format (colon notation)\n\tSSTSecret = 'sst:sst:Secret',\n\tSSTFunction = 'sst:sst:Function',\n\tSSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',\n\tSSTPostgres = 'sst:aws:Postgres',\n\tSSTObjectStorage = 'sst:aws:Bucket',\n\tSnsTopic = 'sst:aws:SnsTopic',\n\tSSTDynamo = 'sst:aws:Dynamo',\n\tSSTQueue = 'sst:aws:Queue',\n\t// A distribution, twice over: a file server and a static site are the same\n\t// infrastructure with different contents behind it, and they are separate\n\t// entries because what they provide is read under different ids, not\n\t// because SST builds them differently.\n\tFileServer = 'sst:aws:Router',\n\tStaticSite = 'sst:aws:StaticSite',\n\t// Neither is an SST component: mail is an IAM chain and a composed URL, and\n\t// a cache is whatever the selected backend turned out to be.\n\tEmail = 'gkm:aws:Email',\n\tCache = 'gkm:aws:Cache',\n\t// Somebody else's API: an address and the credentials it was issued.\n\tExternalApi = 'gkm:aws:ExternalApi',\n\t// A third party's credentials: stored as an SST secret, read under its own\n\t// key rather than the secret's bare name.\n\tCredential = 'gkm:aws:Credential',\n\t// A KMS key and its HMAC key, handed over as one `kms://` URL.\n\tEncryption = 'gkm:aws:Encryption',\n\t// An API Gateway WebSocket API and the table its connections are kept in:\n\t// where a client opens it, who may, and the `apigateway://` string its\n\t// publisher sends through.\n\tWebSocketApi = 'gkm:aws:WebSocketApi',\n\t// Mail received: where its raw messages are read, and the domain it is\n\t// addressed to — both made by the inbox's provider, not by SST.\n\tInbox = 'gkm:aws:Inbox',\n}\n\n/**\n * AWS API Gateway V2 resource type.\n * Represents an HTTP/WebSocket API.\n */\nexport type ApiGatewayV2 = {\n\ttype: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;\n\turl: string;\n};\n\n/**\n * PostgreSQL database resource type.\n * Contains all connection details needed to connect to the database.\n */\nexport type Postgres = {\n\ttype: ResourceType.Postgres | ResourceType.SSTPostgres;\n\tdatabase: string;\n\thost: string;\n\tpassword: string;\n\tport: number;\n\tusername: string;\n};\n\n/**\n * AWS Lambda Function resource type.\n */\nexport type Function = {\n\ttype: ResourceType.Function | ResourceType.SSTFunction;\n\tname: string;\n};\n\n/**\n * AWS S3 Bucket resource type.\n */\nexport type Bucket = {\n\ttype: ResourceType.ObjectStorage | ResourceType.SSTObjectStorage;\n\tname: string;\n\t/**\n\t * Supplied by `@geekmidas/cloud`'s ObjectStorage, which widens SST's link to\n\t * carry them — a bucket may not be in the reader's region, and the URL is\n\t * composed where the resource's shape is known.\n\t */\n\tregion?: string;\n\turl?: string;\n};\n\n/**\n * AWS VPC (Virtual Private Cloud) resource type.\n */\nexport type Vpc = {\n\ttype: ResourceType.Vpc;\n\tbastion: string;\n};\n\n/**\n * Secret resource type for storing sensitive values.\n */\nexport type Secret = {\n\ttype: ResourceType.Secret | ResourceType.SSTSecret;\n\tvalue: string;\n};\n\n/**\n * AWS SNS Topic resource type.\n */\nexport type SnsTopic = {\n\ttype: ResourceType.SnsTopic;\n\tarn: string;\n};\n\n/**\n * AWS SQS Queue resource type.\n */\nexport type Queue = {\n\ttype: ResourceType.Queue | ResourceType.SSTQueue;\n\turl: string;\n\tarn: string;\n};\n\n/**\n * AWS DynamoDB Table resource type.\n */\nexport type Dynamo = {\n\ttype: ResourceType.Dynamo | ResourceType.SSTDynamo;\n\tname: string;\n};\n\n/**\n * Union type of all supported SST resource types.\n */\nexport type SstResource =\n\t| ApiGatewayV2\n\t| Postgres\n\t| Function\n\t| Bucket\n\t| Vpc\n\t| Secret\n\t| SnsTopic\n\t| Queue\n\t| Dynamo;\n\n// Value types without the `type` key (for resolver parameters)\ntype SecretValue = Omit<Secret, 'type'>;\ntype ExternalApiValue = { url: string; credentials: string };\ntype CredentialValue = { credentials: string };\ntype EncryptionValue = { url: string };\ntype InboxValue = { url: string; domain: string };\ntype WebSocketApiValue = {\n\turl: string;\n\ttrustedOrigins: string;\n\tpublisherConnectionString: string;\n};\ntype PostgresValue = Omit<Postgres, 'type'>;\ntype BucketValue = Omit<Bucket, 'type'>;\ntype SnsTopicValue = Omit<SnsTopic, 'type'>;\ntype QueueValue = Omit<Queue, 'type'>;\ntype DynamoValue = Omit<Dynamo, 'type'>;\n\n/**\n * Function type for processing a specific resource type into environment variables.\n *\n * @template K - The specific resource type (without `type` key)\n * @param name - The resource name\n * @param value - The resource value (without `type` key)\n * @returns Object mapping environment variable names to values\n */\nexport type ResourceProcessor<K> = (name: string, value: K) => EnvRecord;\n\n// SST Resource Resolvers (receive values without `type` key)\n\nconst secretResolver = (name: string, value: SecretValue) => ({\n\t[name]: value.value,\n});\n\nconst postgresResolver = (key: string, value: PostgresValue) => ({\n\t[`${key}Name`]: value.database,\n\t[`${key}Host`]: value.host,\n\t[`${key}Password`]: value.password,\n\t[`${key}Port`]: value.port,\n\t[`${key}Username`]: value.username,\n\t[`${key}Url`]: `postgresql://${encodeURIComponent(value.username)}:${encodeURIComponent(value.password)}@${value.host}:${value.port}/${value.database}`,\n});\n\nconst bucketResolver = (name: string, value: BucketValue) => ({\n\t[`${name}Name`]: value.name,\n\t// The single URL a construct reads. Composed by the component, which knows\n\t// its own shape; this only renames it into env case. Always emitted, even\n\t// when absent, so `resolveEnvKeys` can derive the key from the link's type\n\t// alone — a bucket linked without our component yields an empty one.\n\t[`${name}Url`]: value.url ?? '',\n});\n\nconst topicResolver = (name: string, value: SnsTopicValue) => ({\n\t[`${name}Arn`]: value.arn,\n\t// A publisher connection string for `@geekmidas/events` (SNS); region is\n\t// resolved from the ARN / AWS_REGION at runtime.\n\t[`${name}PublisherConnectionString`]: `sns://?topicArn=${encodeURIComponent(value.arn)}`,\n});\n\nconst queueResolver = (name: string, value: QueueValue) => ({\n\t[`${name}Url`]: value.url,\n\t[`${name}Arn`]: value.arn,\n\t// A publisher connection string for `@geekmidas/events` (SQS); region is\n\t// resolved from the URL / AWS_REGION at runtime.\n\t[`${name}PublisherConnectionString`]: `sqs://?queueUrl=${encodeURIComponent(value.url)}`,\n});\n\nconst dynamoResolver = (name: string, value: DynamoValue) => ({\n\t[`${name}Name`]: value.name,\n});\n\nconst externalApiResolver = (name: string, value: ExternalApiValue) => ({\n\t[`${name}Url`]: value.url,\n\t[`${name}Credentials`]: value.credentials,\n});\n\nconst credentialResolver = (name: string, value: CredentialValue) => ({\n\t[`${name}Credentials`]: value.credentials,\n});\n\nconst encryptionResolver = (name: string, value: EncryptionValue) => ({\n\t[`${name}Url`]: value.url,\n});\n\nconst inboxResolver = (name: string, value: InboxValue) => ({\n\t[`${name}Url`]: value.url,\n\t[`${name}Domain`]: value.domain,\n});\n\nconst webSocketApiResolver = (name: string, value: WebSocketApiValue) => ({\n\t[`${name}Url`]: value.url,\n\t[`${name}TrustedOrigins`]: value.trustedOrigins,\n\t[`${name}PublisherConnectionString`]: value.publisherConnectionString,\n});\n\nconst noopResolver = () => ({});\n\n/**\n * Pre-configured resolvers for all SST resource types.\n */\nexport const sstResolvers: Resolvers = {\n\t// Legacy format\n\t[ResourceType.ApiGatewayV2]: noopResolver,\n\t[ResourceType.Function]: noopResolver,\n\t[ResourceType.Vpc]: noopResolver,\n\t[ResourceType.Secret]: secretResolver,\n\t[ResourceType.Postgres]: postgresResolver,\n\t[ResourceType.ObjectStorage]: bucketResolver,\n\t[ResourceType.Dynamo]: dynamoResolver,\n\t[ResourceType.Queue]: queueResolver,\n\n\t// Modern format\n\t[ResourceType.SSTSecret]: secretResolver,\n\t[ResourceType.SSTObjectStorage]: bucketResolver,\n\t[ResourceType.SSTFunction]: noopResolver,\n\t[ResourceType.SSTPostgres]: postgresResolver,\n\t[ResourceType.SSTApiGatewayV2]: noopResolver,\n\t[ResourceType.SnsTopic]: topicResolver,\n\t[ResourceType.SSTDynamo]: dynamoResolver,\n\t[ResourceType.SSTQueue]: queueResolver,\n\t[ResourceType.ExternalApi]: externalApiResolver,\n\t[ResourceType.Credential]: credentialResolver,\n\t[ResourceType.Encryption]: encryptionResolver,\n\t[ResourceType.Inbox]: inboxResolver,\n\t[ResourceType.WebSocketApi]: webSocketApiResolver,\n};\n\n/**\n * All known SST resource type strings.\n */\ntype SstResourceTypeString = `${ResourceType}`;\n\n/**\n * Extracts the `type` string value from an input value.\n */\ntype ExtractType<T> = T extends { type: infer U extends string } ? U : never;\n\n/**\n * Removes the `type` key from an object type.\n */\ntype OmitType<T> = T extends { type: string } ? Omit<T, 'type'> : never;\n\n/**\n * Extracts all unique `type` values from a record (excluding plain strings).\n */\ntype AllTypeValues<TRecord extends Record<string, InputValue>> = {\n\t[K in keyof TRecord]: ExtractType<TRecord[K]>;\n}[keyof TRecord];\n\n/**\n * Extracts only the custom (non-SST) type values from a record.\n */\ntype CustomTypeValues<TRecord extends Record<string, InputValue>> = Exclude<\n\tAllTypeValues<TRecord>,\n\tSstResourceTypeString\n>;\n\n/**\n * For a given type value, finds the corresponding value type (without `type` key).\n */\ntype ValueForType<\n\tTRecord extends Record<string, InputValue>,\n\tTType extends string,\n> = {\n\t[K in keyof TRecord]: TRecord[K] extends { type: TType }\n\t\t? OmitType<TRecord[K]>\n\t\t: never;\n}[keyof TRecord];\n\n/**\n * Generates typed resolvers for custom (non-SST) types in the input record.\n */\ntype CustomResolvers<TRecord extends Record<string, InputValue>> =\n\tCustomTypeValues<TRecord> extends never\n\t\t? Resolvers | undefined\n\t\t: {\n\t\t\t\t[TType in CustomTypeValues<TRecord>]: EnvironmentResolver<\n\t\t\t\t\tValueForType<TRecord, TType>\n\t\t\t\t>;\n\t\t\t};\n\n/**\n * SST-specific environment builder with built-in resolvers for all known\n * SST resource types.\n *\n * Wraps the generic EnvironmentBuilder with pre-configured SST resolvers.\n *\n * @template TRecord - The input record type for type inference\n *\n * @example\n * ```typescript\n * const env = new SstEnvironmentBuilder({\n * database: { type: 'sst:aws:Postgres', host: '...', ... },\n * apiKey: { type: 'sst:sst:Secret', value: 'secret' },\n * appName: 'my-app',\n * }).build();\n *\n * // With custom resolvers (typed based on input)\n * const env = new SstEnvironmentBuilder(\n * {\n * database: postgresResource,\n * custom: { type: 'my-custom' as const, data: 'foo' },\n * },\n * {\n * // TypeScript requires 'my-custom' resolver with typed value\n * 'my-custom': (key, value) => ({ [`${key}Data`]: value.data }),\n * }\n * ).build();\n * ```\n */\nexport class SstEnvironmentBuilder<\n\tTRecord extends Record<string, SstResource | InputValue | string>,\n> {\n\tprivate readonly builder: EnvironmentBuilder<\n\t\tRecord<string, InputValue>,\n\t\tResolvers\n\t>;\n\n\t/**\n\t * Create a new SST environment builder.\n\t *\n\t * @param record - Object containing SST resources, custom resources, and/or string values\n\t * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)\n\t * @param options - Optional configuration options\n\t */\n\tconstructor(\n\t\trecord: TRecord,\n\t\tadditionalResolvers?: CustomResolvers<TRecord>,\n\t\toptions?: EnvironmentBuilderOptions,\n\t) {\n\t\t// Merge resolvers with custom ones taking precedence\n\t\tconst mergedResolvers: Resolvers = additionalResolvers\n\t\t\t? { ...sstResolvers, ...additionalResolvers }\n\t\t\t: sstResolvers;\n\n\t\tthis.builder = new EnvironmentBuilder(\n\t\t\trecord as Record<string, InputValue>,\n\t\t\tmergedResolvers,\n\t\t\toptions,\n\t\t);\n\t}\n\n\t/**\n\t * Build environment variables from the input record.\n\t *\n\t * @returns A record of environment variables\n\t */\n\tbuild(): EnvRecord {\n\t\treturn this.builder.build();\n\t}\n}\n\nexport type {\n\tEnvironmentBuilderOptions,\n\tEnvRecord,\n\tEnvValue,\n} from './EnvironmentBuilder';\n// Re-export useful types\nexport { environmentCase } from './EnvironmentBuilder';\n","import { EnvironmentBuilder, type InputValue } from './EnvironmentBuilder';\nimport { type SstResource, sstResolvers } from './SstEnvironmentBuilder';\n\n/**\n * Variables AWS Lambda injects into the runtime. Always valid on AWS, but never\n * assumed — opt in via `platform: 'aws'` or by spreading {@link AWS_RUNTIME_ENV_VARS}\n * into `whitelist`.\n */\nexport const AWS_RUNTIME_ENV_VARS = [\n\t'AWS_REGION',\n\t'AWS_DEFAULT_REGION',\n\t'AWS_ENDPOINT_URL',\n\t'AWS_ENDPOINT',\n\t'AWS_ACCESS_KEY_ID',\n\t'AWS_SECRET_ACCESS_KEY',\n\t'AWS_SESSION_TOKEN',\n\t'AWS_LAMBDA_FUNCTION_NAME',\n\t'AWS_LAMBDA_FUNCTION_VERSION',\n] as const;\n\n/**\n * Variables GCP injects into Cloud Functions / Cloud Run.\n */\nexport const GCP_RUNTIME_ENV_VARS = [\n\t'GOOGLE_CLOUD_PROJECT',\n\t'GCP_PROJECT',\n\t'FUNCTION_TARGET',\n\t'FUNCTION_SIGNATURE_TYPE',\n\t'K_SERVICE',\n\t'K_REVISION',\n\t'K_CONFIGURATION',\n\t'PORT',\n] as const;\n\n/**\n * Variables Cloudflare exposes to Workers. Workers inject almost nothing into\n * the global env, so this is intentionally minimal.\n */\nexport const CLOUDFLARE_RUNTIME_ENV_VARS = [\n\t'CF_PAGES',\n\t'CF_PAGES_URL',\n] as const;\n\n/**\n * Registry of platform → always-valid runtime variables. Export, don't assume:\n * a caller states the platform it deploys to and the matching set is trusted.\n */\nexport const PLATFORM_ENV_VARS = {\n\taws: AWS_RUNTIME_ENV_VARS,\n\tgcp: GCP_RUNTIME_ENV_VARS,\n\tcloudflare: CLOUDFLARE_RUNTIME_ENV_VARS,\n} as const;\n\nexport type Platform = keyof typeof PLATFORM_ENV_VARS;\n\n/**\n * The always-valid runtime variables for a platform. The \"whitelist construct\":\n * resolve a platform to its set, to spread into `whitelist` or compare against.\n */\nexport function platformEnvVars(platform: Platform): readonly string[] {\n\treturn PLATFORM_ENV_VARS[platform];\n}\n\n/** How many link-provided vars to list in an error before truncating. */\nconst MAX_LISTED_VARS = 8;\n\n/** Minimum similarity for a variable to be offered as a \"did you mean\". */\nconst SUGGESTION_THRESHOLD = 0.3;\n\n/**\n * Input shape for the validator: the same record `SstEnvironmentBuilder`\n * accepts — keyed by resource name, valued by an SST resource (or a plain\n * string for pass-through env vars).\n */\nexport type LinkRecord = Record<string, SstResource | InputValue | string>;\n\nexport interface ValidationResult {\n\tvalid: boolean;\n\t/** Requested variables that are not available (excluding optional `?` vars). */\n\tinvalidVars: string[];\n\t/** Every variable the links + whitelist make available. */\n\tavailableVars: string[];\n\t/** Nearest available matches for each invalid variable (best first). */\n\tsuggestions: Record<string, string[]>;\n}\n\nexport interface EnvValidatorOptions {\n\t/**\n\t * Platform whose runtime-injected variables are always valid. Omit to assume\n\t * none — the validator never bakes in a platform's variables.\n\t */\n\tplatform?: Platform;\n\t/**\n\t * Extra always-valid variables in addition to the platform set — typically\n\t * the keys of a function's explicit `environment`.\n\t */\n\twhitelist?: readonly string[];\n\t/**\n\t * Label for the deployable unit (e.g. a function name), used in error\n\t * messages so a failure points at exactly one unit.\n\t */\n\tcontext?: string;\n}\n\n/**\n * Levenshtein edit distance between two strings.\n */\nfunction levenshtein(a: string, b: string): number {\n\tconst m = a.length;\n\tconst n = b.length;\n\tif (m === 0) return n;\n\tif (n === 0) return m;\n\n\tlet prev = Array.from({ length: n + 1 }, (_, i) => i);\n\n\tfor (let i = 1; i <= m; i++) {\n\t\tconst curr: number[] = [i];\n\t\tfor (let j = 1; j <= n; j++) {\n\t\t\tconst cost = a[i - 1] === b[j - 1] ? 0 : 1;\n\t\t\tconst del = (prev[j] ?? 0) + 1;\n\t\t\tconst ins = (curr[j - 1] ?? 0) + 1;\n\t\t\tconst sub = (prev[j - 1] ?? 0) + cost;\n\t\t\tcurr[j] = Math.min(del, ins, sub);\n\t\t}\n\t\tprev = curr;\n\t}\n\n\treturn prev[n] ?? 0;\n}\n\n/**\n * Similarity in `[0, 1]` combining edit distance with `_`-token overlap, so both\n * near-typos (a missing underscore) and renames (`DATABASE_URL` ~ `DB_URL`,\n * which share the `URL` token) are caught.\n */\nfunction similarity(a: string, b: string): number {\n\tconst editSim = 1 - levenshtein(a, b) / Math.max(a.length, b.length, 1);\n\n\tconst ta = new Set(a.split('_').filter(Boolean));\n\tconst tb = new Set(b.split('_').filter(Boolean));\n\tconst shared = [...ta].filter((t) => tb.has(t)).length;\n\tconst union = new Set([...ta, ...tb]).size || 1;\n\tconst tokenSim = shared / union;\n\n\t// Nudge token-overlap matches ahead of coincidental edit-distance ones, so a\n\t// rename like DATABASE_URL prefers DB_URL (shares `URL`) over DB_PASSWORD.\n\treturn Math.max(editSim, tokenSim * 1.15);\n}\n\n/**\n * Returns the nearest available variables to `missing`, best first, limited to\n * those above {@link SUGGESTION_THRESHOLD}.\n */\nfunction suggestionsFor(\n\tmissing: string,\n\tavailable: readonly string[],\n\tmax = 1,\n): string[] {\n\treturn available\n\t\t.map((candidate) => ({ candidate, score: similarity(missing, candidate) }))\n\t\t.filter((s) => s.score >= SUGGESTION_THRESHOLD)\n\t\t.sort((a, b) => b.score - a.score)\n\t\t.slice(0, max)\n\t\t.map((s) => s.candidate);\n}\n\n/**\n * Thrown when a deployable unit requires environment variables its links do not\n * provide. Carries the structured `missing`/`available`/`suggestions` so callers\n * can inspect the failure programmatically, not just read the message.\n */\nexport class EnvValidationError extends Error {\n\treadonly isEnvValidationError = true;\n\treadonly missing: string[];\n\treadonly available: string[];\n\treadonly suggestions: Record<string, string[]>;\n\treadonly context?: string;\n\n\tconstructor(args: {\n\t\tmissing: string[];\n\t\tavailable: string[];\n\t\tlinkVars: string[];\n\t\tsuggestions: Record<string, string[]>;\n\t\tcontext?: string;\n\t}) {\n\t\tsuper(EnvValidationError.format(args));\n\t\tthis.name = 'EnvValidationError';\n\t\tthis.missing = args.missing;\n\t\tthis.available = args.available;\n\t\tthis.suggestions = args.suggestions;\n\t\tthis.context = args.context;\n\t\t// V8-only; keeps the constructor out of the stack trace.\n\t\t(\n\t\t\tError as unknown as {\n\t\t\t\tcaptureStackTrace?(target: object, ctor?: unknown): void;\n\t\t\t}\n\t\t).captureStackTrace?.(this, EnvValidationError);\n\t}\n\n\tprivate static format(args: {\n\t\tmissing: string[];\n\t\tlinkVars: string[];\n\t\tsuggestions: Record<string, string[]>;\n\t\tcontext?: string;\n\t}): string {\n\t\tconst { missing, linkVars, suggestions, context } = args;\n\t\tconst who = context ? `'${context}'` : 'a deployable unit';\n\n\t\tconst width = Math.max(...missing.map((v) => v.length));\n\t\tconst lines = missing.map((v) => {\n\t\t\tconst hints = suggestions[v] ?? [];\n\t\t\tconst hint = hints.length ? `(did you mean ${hints.join(' or ')}?)` : '';\n\t\t\treturn ` - ${v.padEnd(width)} ${hint}`.trimEnd();\n\t\t});\n\n\t\tlet provided: string;\n\t\tif (linkVars.length === 0) {\n\t\t\tprovided = '(no links provide environment variables)';\n\t\t} else {\n\t\t\tconst shown = linkVars.slice(0, MAX_LISTED_VARS).join(', ');\n\t\t\tconst extra =\n\t\t\t\tlinkVars.length > MAX_LISTED_VARS\n\t\t\t\t\t? ` ...(+${linkVars.length - MAX_LISTED_VARS})`\n\t\t\t\t\t: '';\n\t\t\tprovided = `Provided by links: ${shown}${extra}`;\n\t\t}\n\n\t\treturn `${who} is missing required env vars:\\n${lines.join('\\n')}\\n\\n${provided}`;\n\t}\n}\n\n/**\n * Derives the set of environment-variable **keys** a group of linked resources\n * will produce at runtime — without resolving any value.\n *\n * This reuses the runtime resolvers (`sstResolvers`) via {@link EnvironmentBuilder},\n * so the keys computed here are exactly the keys a deployed function receives:\n * the validator and the runtime resolution share a single source of truth and\n * cannot drift. Because every resolver's output keys depend only on the record\n * key and the resource `type` (never the value), each resource is reduced to\n * `{ type }` before building, so no SST `Output` is ever read.\n *\n * @example\n * resolveEnvKeys({ db: { type: ResourceType.Postgres } });\n * // ['DB_NAME', 'DB_HOST', 'DB_PASSWORD', 'DB_PORT', 'DB_USERNAME', 'DB_URL']\n */\nexport function resolveEnvKeys(record: LinkRecord): string[] {\n\tconst typeOnly: Record<string, InputValue> = {};\n\tfor (const [key, value] of Object.entries(record)) {\n\t\ttypeOnly[key] = typeof value === 'string' ? '' : { type: value.type };\n\t}\n\treturn Object.keys(new EnvironmentBuilder(typeOnly, sstResolvers).build());\n}\n\n/**\n * Validates that the environment variables a deployable unit requires are\n * actually provided by its linked resources — at infra time, before deploy.\n *\n * Available variables are the union of the keys derived from `links`\n * ({@link resolveEnvKeys}), the chosen platform's runtime variables (only when\n * `options.platform` is set — nothing is assumed), and any `options.whitelist`\n * (e.g. the keys of a function's explicit `environment`). A requested variable\n * suffixed with `?` is treated as optional and never causes a failure.\n *\n * @example\n * const validator = new EnvValidator(\n * { db: { type: ResourceType.Postgres } },\n * { platform: 'aws', whitelist: ['APP_NAME'], context: 'orders-fn' },\n * );\n * validator.assert(['DB_HOST', 'AWS_REGION', 'APP_NAME', 'SENTRY_DSN?']); // ok\n * validator.assert(['DATABASE_URL']); // throws EnvValidationError (did you mean DB_URL?)\n */\nexport class EnvValidator {\n\t/** Every variable available — link-derived, platform, and extra whitelist. */\n\treadonly availableVars: string[];\n\t/** Just the variables the links provide (used for error context). */\n\treadonly linkVars: string[];\n\treadonly context?: string;\n\tprivate readonly availableSet: Set<string>;\n\t/** Per-link (record key → its env-var keys), for least-privilege filtering. */\n\tprivate readonly linkVarsByName: Map<string, string[]>;\n\n\tconstructor(links: LinkRecord, options: EnvValidatorOptions = {}) {\n\t\tconst { platform, whitelist = [], context } = options;\n\t\tthis.context = context;\n\t\tthis.linkVarsByName = new Map(\n\t\t\tObject.entries(links).map(([name, value]) => [\n\t\t\t\tname,\n\t\t\t\tresolveEnvKeys({ [name]: value }),\n\t\t\t]),\n\t\t);\n\t\tthis.linkVars = [...this.linkVarsByName.values()].flat();\n\t\tthis.availableVars = [\n\t\t\t...this.linkVars,\n\t\t\t...(platform ? PLATFORM_ENV_VARS[platform] : []),\n\t\t\t...whitelist,\n\t\t];\n\t\tthis.availableSet = new Set(this.availableVars);\n\t}\n\n\t/**\n\t * Returns the names of the links that provide at least one of the requested\n\t * variables — so a construct can attach only the links a unit actually needs\n\t * (least privilege) rather than the whole pool. Trailing `?` is ignored.\n\t */\n\tgetProvidersForEnvVars(requestedEnvVars: readonly string[]): string[] {\n\t\tconst requested = new Set(\n\t\t\trequestedEnvVars.map((v) => (v.endsWith('?') ? v.slice(0, -1) : v)),\n\t\t);\n\t\tconst providers: string[] = [];\n\t\tfor (const [name, vars] of this.linkVarsByName) {\n\t\t\tif (vars.some((v) => requested.has(v))) providers.push(name);\n\t\t}\n\t\treturn providers;\n\t}\n\n\t/**\n\t * Checks every requested variable against the available set. Variables\n\t * ending in `?` are optional and never reported as invalid. Invalid\n\t * variables come back with their nearest available matches.\n\t */\n\tvalidate(requestedEnvVars: readonly string[]): ValidationResult {\n\t\tconst invalidVars = requestedEnvVars.filter((envVar) => {\n\t\t\tif (envVar.endsWith('?')) return false;\n\t\t\treturn !this.availableSet.has(envVar);\n\t\t});\n\n\t\tconst suggestions: Record<string, string[]> = {};\n\t\tfor (const envVar of invalidVars) {\n\t\t\tconst matches = suggestionsFor(envVar, this.availableVars);\n\t\t\tif (matches.length) suggestions[envVar] = matches;\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: invalidVars.length === 0,\n\t\t\tinvalidVars,\n\t\t\tavailableVars: this.availableVars,\n\t\t\tsuggestions,\n\t\t};\n\t}\n\n\t/**\n\t * Asserts that every requested variable is available, throwing an\n\t * {@link EnvValidationError} otherwise. Intended to run in a construct's\n\t * constructor so a misconfigured `sst.config.ts` fails at synth time, before\n\t * any AWS call.\n\t */\n\tassert(requestedEnvVars: readonly string[]): void {\n\t\tconst { valid, invalidVars, suggestions } = this.validate(requestedEnvVars);\n\n\t\tif (!valid) {\n\t\t\tthrow new EnvValidationError({\n\t\t\t\tmissing: invalidVars,\n\t\t\t\tavailable: this.availableVars,\n\t\t\t\tlinkVars: this.linkVars,\n\t\t\t\tsuggestions,\n\t\t\t\tcontext: this.context,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Whether a single variable is available. Does not treat a trailing `?` as\n\t * optional — pass the bare name.\n\t */\n\thas(envVar: string): boolean {\n\t\treturn this.availableSet.has(envVar);\n\t}\n}\n","// Re-export everything from SstEnvironmentBuilder\n\n// Re-export types from EnvironmentBuilder\nexport type {\n\tEnvironmentBuilderOptions,\n\tEnvRecord,\n\tEnvValue,\n} from './EnvironmentBuilder';\n\n// Re-export environmentCase from EnvironmentBuilder\nexport { environmentCase } from './EnvironmentBuilder';\nexport {\n\ttype ApiGatewayV2,\n\ttype Bucket,\n\ttype Dynamo,\n\ttype Function,\n\ttype Postgres,\n\ttype Queue,\n\ttype ResourceProcessor,\n\tResourceType,\n\ttype Secret,\n\ttype SnsTopic,\n\tSstEnvironmentBuilder,\n\ttype SstResource,\n\tsstResolvers,\n\ttype Vpc,\n} from './SstEnvironmentBuilder';\n\nexport {\n\tAWS_RUNTIME_ENV_VARS,\n\tCLOUDFLARE_RUNTIME_ENV_VARS,\n\tEnvValidationError,\n\tEnvValidator,\n\ttype EnvValidatorOptions,\n\tGCP_RUNTIME_ENV_VARS,\n\ttype LinkRecord,\n\tPLATFORM_ENV_VARS,\n\ttype Platform,\n\tplatformEnvVars,\n\tresolveEnvKeys,\n\ttype ValidationResult,\n} from './SstEnvValidator';\n\n// Import for deprecated function\nimport {\n\tSstEnvironmentBuilder,\n\ttype SstResource,\n} from './SstEnvironmentBuilder';\n\n/**\n * @deprecated Use `new SstEnvironmentBuilder(record).build()` instead.\n *\n * Normalizes SST resources and plain strings into environment variables.\n * Processes resources based on their type and converts names to environment case.\n *\n * @param record - Object containing resources and/or string values\n * @returns Normalized environment variables object\n *\n * @example\n * // Old usage (deprecated):\n * normalizeResourceEnv({ database: postgresResource })\n *\n * // New usage:\n * new SstEnvironmentBuilder({ database: postgresResource }).build()\n */\nexport function normalizeResourceEnv(\n\trecord: Record<string, SstResource | string>,\n): Record<string, string | number | boolean | Record<string, unknown>> {\n\treturn new SstEnvironmentBuilder(record).build();\n}\n\n// Keep Resource type as deprecated alias for backwards compatibility\n/**\n * @deprecated Use `SstResource` instead.\n */\nexport type Resource = SstResource;\n"],"mappings":";;;;;;;AAaA,IAAY,eAAL,yBAAA,cAAA;CAEN,aAAA,kBAAA;CACA,aAAA,cAAA;CACA,aAAA,cAAA;CACA,aAAA,mBAAA;CACA,aAAA,SAAA;CACA,aAAA,YAAA;CACA,aAAA,YAAA;CACA,aAAA,WAAA;CAGA,aAAA,eAAA;CACA,aAAA,iBAAA;CACA,aAAA,qBAAA;CACA,aAAA,iBAAA;CACA,aAAA,sBAAA;CACA,aAAA,cAAA;CACA,aAAA,eAAA;CACA,aAAA,cAAA;CAKA,aAAA,gBAAA;CACA,aAAA,gBAAA;CAGA,aAAA,WAAA;CACA,aAAA,WAAA;CAEA,aAAA,iBAAA;CAGA,aAAA,gBAAA;CAEA,aAAA,gBAAA;CAIA,aAAA,kBAAA;CAGA,aAAA,WAAA;;AACD,EAAA,CAAA,CAAA;AAmIA,MAAM,kBAAkB,MAAc,WAAwB,GAC5D,OAAO,MAAM,MACf;AAEA,MAAM,oBAAoB,KAAa,WAA0B;EAC/D,GAAG,IAAI,QAAQ,MAAM;EACrB,GAAG,IAAI,QAAQ,MAAM;EACrB,GAAG,IAAI,YAAY,MAAM;EACzB,GAA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5B,SAAS;GACT,WAAW,KAAK;GAChB,UAAU,KAAK;GACf;GACA,SAAS,KAAK;EACf,CAAC;CAEH;;;;;CAMA,IAAI,QAAyB;EAC5B,OAAO,KAAK,aAAa,IAAI,MAAM;CACpC;AACD;;;;;;;;;;;;;;;;;;;AC/SA,SAAgB,qBACf,QACsE;CACtE,OAAO,IAAI,sBAAsB,MAAM,CAAC,CAAC,MAAM;AAChD"}
package/dist/sst.d.cts CHANGED
@@ -24,7 +24,12 @@ export declare enum ResourceType {
24
24
  FileServer = "sst:aws:Router",
25
25
  StaticSite = "sst:aws:StaticSite",
26
26
  Email = "gkm:aws:Email",
27
- Cache = "gkm:aws:Cache"
27
+ Cache = "gkm:aws:Cache",
28
+ ExternalApi = "gkm:aws:ExternalApi",
29
+ Credential = "gkm:aws:Credential",
30
+ Encryption = "gkm:aws:Encryption",
31
+ WebSocketApi = "gkm:aws:WebSocketApi",
32
+ Inbox = "gkm:aws:Inbox"
28
33
  }
29
34
  /**
30
35
  * AWS API Gateway V2 resource type.
@@ -1 +1 @@
1
- {"version":3,"file":"sst.d.cts","names":[],"sources":["../src/SstEnvironmentBuilder.ts","../src/SstEnvValidator.ts","../src/sst.ts"],"mappings":";;;;;;oBAaY;EAEX;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAGA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAKA;EACA;EAGA;EACA;;;;;;KAOW;EACX,MAAM,aAAa,eAAe,aAAa;EAC/C;;;;;;KAOW;EACX,MAAM,aAAa,WAAW,aAAa;EAC3C;EACA;EACA;EACA;EACA;;;;;KAMW;EACX,MAAM,aAAa,WAAW,aAAa;EAC3C;;;;;KAMW;EACX,MAAM,aAAa,gBAAgB,aAAa;EAChD;;;;;;EAMA;EACA;;;;;KAMW;EACX,MAAM,aAAa;EACnB;;;;;KAMW;EACX,MAAM,aAAa,SAAS,aAAa;EACzC;;;;;KAMW;EACX,MAAM,aAAa;EACnB;;;;;KAMW;EACX,MAAM,aAAa,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jB,YAAY,OAAO,YAAY,UAAS;;;;;;EAuBxC,uBAAuB;;;;;;EAgBvB,SAAS,sCAAsC;;;;;;;EA0B/C,OAAO;;;;;EAkBP,IAAI;;;;;;;;;;;;;;;;;;;;wBC5SW,qBACf,QAAQ,eAAe,wBACrB,2CAA2C;;;;YAQlC,WAAW"}
1
+ {"version":3,"file":"sst.d.cts","names":[],"sources":["../src/SstEnvironmentBuilder.ts","../src/SstEnvValidator.ts","../src/sst.ts"],"mappings":";;;;;;oBAaY;EAEX;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAGA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAKA;EACA;EAGA;EACA;EAEA;EAGA;EAEA;EAIA;EAGA;;;;;;KAOW;EACX,MAAM,aAAa,eAAe,aAAa;EAC/C;;;;;;KAOW;EACX,MAAM,aAAa,WAAW,aAAa;EAC3C;EACA;EACA;EACA;EACA;;;;;KAMW;EACX,MAAM,aAAa,WAAW,aAAa;EAC3C;;;;;KAMW;EACX,MAAM,aAAa,gBAAgB,aAAa;EAChD;;;;;;EAMA;EACA;;;;;KAMW;EACX,MAAM,aAAa;EACnB;;;;;KAMW;EACX,MAAM,aAAa,SAAS,aAAa;EACzC;;;;;KAMW;EACX,MAAM,aAAa;EACnB;;;;;KAMW;EACX,MAAM,aAAa,QAAQ,aAAa;EACxC;EACA;;;;;KAMW;EACX,MAAM,aAAa,SAAS,aAAa;EACzC;;;;;KAMW,cACT,eACA,WACA,WACA,SACA,MACA,SACA,WACA,QACA;;;;;;;;;KA2BS,kBAAkB,MAAM,cAAc,OAAO,MAAM;;;;qBA0ElD,cAAc;;;;KA8BtB,2BAA2B;;;;KAK3B,YAAY,KAAK;EAAY,YAAY;IAAqB;;;;KAK9D,SAAS,KAAK;EAAY;IAAiB,KAAK;;;;KAKhD,cAAc,gBAAgB,eAAe,kBAChD,WAAW,UAAU,YAAY,QAAQ,aACnC;;;;KAKH,iBAAiB,gBAAgB,eAAe,eAAe,QACnE,cAAc,UACd;;;;KAMI,aACJ,gBAAgB,eAAe,aAC/B,2BAEC,WAAW,UAAU,QAAQ;EAAa,MAAM;IAC9C,SAAS,QAAQ,qBAEb;;;;KAKH,gBAAgB,gBAAgB,eAAe,eACnD,iBAAiB,yBACd,2BAEC,SAAS,iBAAiB,WAAW,oBACrC,aAAa,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAiCd,sBACZ,gBAAgB,eAAe,cAAc;mBAE5B;;;;;;;;EAYjB,YACC,QAAQ,SACR,sBAAsB,gBAAgB,UACtC,UAAU;;;;;;EAmBX,SAAS;;;;;;;;;qBC7YG;;;;qBAeA;;;;;qBAeA;;;;;qBASA;WACZ;WACA;WACA;;KAGW,wBAAwB;;;;;wBAMpB,gBAAgB,UAAU;;;;;;KAe9B,aAAa,eAAe,cAAc;UAErC;EAChB;;EAEA;;EAEA;;EAEA,aAAa;;UAGG;;;;;EAKhB,WAAW;;;;;EAKX;;;;;EAKA;;;;;;;qBAsEY,2BAA2B;WAC9B;WACA;WACA;WACA,aAAa;WACb;EAET,YAAY;IACX;IACA;IACA;IACA,aAAa;IACb;;iBAgBc;;;;;;;;;;;;;;;;;wBA+CA,eAAe,QAAQ;;;;;;;;;;;;;;;;;;;qBA0B1B;;WAEH;;WAEA;WACA;mBACQ;;mBAEA;EAEjB,YAAY,OAAO,YAAY,UAAS;;;;;;EAuBxC,uBAAuB;;;;;;EAgBvB,SAAS,sCAAsC;;;;;;;EA0B/C,OAAO;;;;;EAkBP,IAAI;;;;;;;;;;;;;;;;;;;;wBC5SW,qBACf,QAAQ,eAAe,wBACrB,2CAA2C;;;;YAQlC,WAAW"}
package/dist/sst.d.mts CHANGED
@@ -24,7 +24,12 @@ export declare enum ResourceType {
24
24
  FileServer = "sst:aws:Router",
25
25
  StaticSite = "sst:aws:StaticSite",
26
26
  Email = "gkm:aws:Email",
27
- Cache = "gkm:aws:Cache"
27
+ Cache = "gkm:aws:Cache",
28
+ ExternalApi = "gkm:aws:ExternalApi",
29
+ Credential = "gkm:aws:Credential",
30
+ Encryption = "gkm:aws:Encryption",
31
+ WebSocketApi = "gkm:aws:WebSocketApi",
32
+ Inbox = "gkm:aws:Inbox"
28
33
  }
29
34
  /**
30
35
  * AWS API Gateway V2 resource type.
@@ -1 +1 @@
1
- {"version":3,"file":"sst.d.mts","names":[],"sources":["../src/SstEnvironmentBuilder.ts","../src/SstEnvValidator.ts","../src/sst.ts"],"mappings":";;;;;;oBAaY;EAEX;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAGA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAKA;EACA;EAGA;EACA;;;;;;KAOW;EACX,MAAM,aAAa,eAAe,aAAa;EAC/C;;;;;;KAOW;EACX,MAAM,aAAa,WAAW,aAAa;EAC3C;EACA;EACA;EACA;EACA;;;;;KAMW;EACX,MAAM,aAAa,WAAW,aAAa;EAC3C;;;;;KAMW;EACX,MAAM,aAAa,gBAAgB,aAAa;EAChD;;;;;;EAMA;EACA;;;;;KAMW;EACX,MAAM,aAAa;EACnB;;;;;KAMW;EACX,MAAM,aAAa,SAAS,aAAa;EACzC;;;;;KAMW;EACX,MAAM,aAAa;EACnB;;;;;KAMW;EACX,MAAM,aAAa,QAAQ,aAAa;EACxC;EACA;;;;;KAMW;EACX,MAAM,aAAa,SAAS,aAAa;EACzC;;;;;KAMW,cACT,eACA,WACA,WACA,SACA,MACA,SACA,WACA,QACA;;;;;;;;;KAkBS,kBAAkB,MAAM,cAAc,OAAO,MAAM;;;;qBAkDlD,cAAc;;;;KAyBtB,2BAA2B;;;;KAK3B,YAAY,KAAK;EAAY,YAAY;IAAqB;;;;KAK9D,SAAS,KAAK;EAAY;IAAiB,KAAK;;;;KAKhD,cAAc,gBAAgB,eAAe,kBAChD,WAAW,UAAU,YAAY,QAAQ,aACnC;;;;KAKH,iBAAiB,gBAAgB,eAAe,eAAe,QACnE,cAAc,UACd;;;;KAMI,aACJ,gBAAgB,eAAe,aAC/B,2BAEC,WAAW,UAAU,QAAQ;EAAa,MAAM;IAC9C,SAAS,QAAQ,qBAEb;;;;KAKH,gBAAgB,gBAAgB,eAAe,eACnD,iBAAiB,yBACd,2BAEC,SAAS,iBAAiB,WAAW,oBACrC,aAAa,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAiCd,sBACZ,gBAAgB,eAAe,cAAc;mBAE5B;;;;;;;;EAYjB,YACC,QAAQ,SACR,sBAAsB,gBAAgB,UACtC,UAAU;;;;;;EAmBX,SAAS;;;;;;;;;qBCzVG;;;;qBAeA;;;;;qBAeA;;;;;qBASA;WACZ;WACA;WACA;;KAGW,wBAAwB;;;;;wBAMpB,gBAAgB,UAAU;;;;;;KAe9B,aAAa,eAAe,cAAc;UAErC;EAChB;;EAEA;;EAEA;;EAEA,aAAa;;UAGG;;;;;EAKhB,WAAW;;;;;EAKX;;;;;EAKA;;;;;;;qBAsEY,2BAA2B;WAC9B;WACA;WACA;WACA,aAAa;WACb;EAET,YAAY;IACX;IACA;IACA;IACA,aAAa;IACb;;iBAgBc;;;;;;;;;;;;;;;;;wBA+CA,eAAe,QAAQ;;;;;;;;;;;;;;;;;;;qBA0B1B;;WAEH;;WAEA;WACA;mBACQ;;mBAEA;EAEjB,YAAY,OAAO,YAAY,UAAS;;;;;;EAuBxC,uBAAuB;;;;;;EAgBvB,SAAS,sCAAsC;;;;;;;EA0B/C,OAAO;;;;;EAkBP,IAAI;;;;;;;;;;;;;;;;;;;;wBC5SW,qBACf,QAAQ,eAAe,wBACrB,2CAA2C;;;;YAQlC,WAAW"}
1
+ {"version":3,"file":"sst.d.mts","names":[],"sources":["../src/SstEnvironmentBuilder.ts","../src/SstEnvValidator.ts","../src/sst.ts"],"mappings":";;;;;;oBAaY;EAEX;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAGA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAKA;EACA;EAGA;EACA;EAEA;EAGA;EAEA;EAIA;EAGA;;;;;;KAOW;EACX,MAAM,aAAa,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AU;;;;;;KAe9B,aAAa,eAAe,cAAc;UAErC;EAChB;;EAEA;;EAEA;;EAEA,aAAa;;UAGG;;;;;EAKhB,WAAW;;;;;EAKX;;;;;EAKA;;;;;;;qBAsEY,2BAA2B;WAC9B;WACA;WACA;WACA,aAAa;WACb;EAET,YAAY;IACX;IACA;IACA;IACA,aAAa;IACb;;iBAgBc;;;;;;;;;;;;;;;;;wBA+CA,eAAe,QAAQ;;;;;;;;;;;;;;;;;;;qBA0B1B;;WAEH;;WAEA;WACA;mBACQ;;mBAEA;EAEjB,YAAY,OAAO,YAAY,UAAS;;;;;;EAuBxC,uBAAuB;;;;;;EAgBvB,SAAS,sCAAsC;;;;;;;EA0B/C,OAAO;;;;;EAkBP,IAAI;;;;;;;;;;;;;;;;;;;;wBC5SW,qBACf,QAAQ,eAAe,wBACrB,2CAA2C;;;;YAQlC,WAAW"}
package/dist/sst.mjs CHANGED
@@ -25,6 +25,11 @@ let ResourceType = /* @__PURE__ */ function(ResourceType) {
25
25
  ResourceType["StaticSite"] = "sst:aws:StaticSite";
26
26
  ResourceType["Email"] = "gkm:aws:Email";
27
27
  ResourceType["Cache"] = "gkm:aws:Cache";
28
+ ResourceType["ExternalApi"] = "gkm:aws:ExternalApi";
29
+ ResourceType["Credential"] = "gkm:aws:Credential";
30
+ ResourceType["Encryption"] = "gkm:aws:Encryption";
31
+ ResourceType["WebSocketApi"] = "gkm:aws:WebSocketApi";
32
+ ResourceType["Inbox"] = "gkm:aws:Inbox";
28
33
  return ResourceType;
29
34
  }({});
30
35
  const secretResolver = (name, value) => ({ [name]: value.value });
@@ -50,6 +55,21 @@ const queueResolver = (name, value) => ({
50
55
  [`${name}PublisherConnectionString`]: `sqs://?queueUrl=${encodeURIComponent(value.url)}`
51
56
  });
52
57
  const dynamoResolver = (name, value) => ({ [`${name}Name`]: value.name });
58
+ const externalApiResolver = (name, value) => ({
59
+ [`${name}Url`]: value.url,
60
+ [`${name}Credentials`]: value.credentials
61
+ });
62
+ const credentialResolver = (name, value) => ({ [`${name}Credentials`]: value.credentials });
63
+ const encryptionResolver = (name, value) => ({ [`${name}Url`]: value.url });
64
+ const inboxResolver = (name, value) => ({
65
+ [`${name}Url`]: value.url,
66
+ [`${name}Domain`]: value.domain
67
+ });
68
+ const webSocketApiResolver = (name, value) => ({
69
+ [`${name}Url`]: value.url,
70
+ [`${name}TrustedOrigins`]: value.trustedOrigins,
71
+ [`${name}PublisherConnectionString`]: value.publisherConnectionString
72
+ });
53
73
  const noopResolver = () => ({});
54
74
  /**
55
75
  * Pre-configured resolvers for all SST resource types.
@@ -70,7 +90,12 @@ const sstResolvers = {
70
90
  ["sst:aws:ApiGatewayV2"]: noopResolver,
71
91
  ["sst:aws:SnsTopic"]: topicResolver,
72
92
  ["sst:aws:Dynamo"]: dynamoResolver,
73
- ["sst:aws:Queue"]: queueResolver
93
+ ["sst:aws:Queue"]: queueResolver,
94
+ ["gkm:aws:ExternalApi"]: externalApiResolver,
95
+ ["gkm:aws:Credential"]: credentialResolver,
96
+ ["gkm:aws:Encryption"]: encryptionResolver,
97
+ ["gkm:aws:Inbox"]: inboxResolver,
98
+ ["gkm:aws:WebSocketApi"]: webSocketApiResolver
74
99
  };
75
100
  /**
76
101
  * SST-specific environment builder with built-in resolvers for all known
package/dist/sst.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sst.mjs","names":[],"sources":["../src/SstEnvironmentBuilder.ts","../src/SstEnvValidator.ts","../src/sst.ts"],"sourcesContent":["import {\n\tEnvironmentBuilder,\n\ttype EnvironmentBuilderOptions,\n\ttype EnvironmentResolver,\n\ttype EnvRecord,\n\ttype InputValue,\n\ttype Resolvers,\n} from './EnvironmentBuilder';\n\n/**\n * Enumeration of supported SST (Serverless Stack Toolkit) resource types.\n * Used to identify and process different AWS and SST resources.\n */\nexport enum ResourceType {\n\t// Legacy format (dot notation)\n\tApiGatewayV2 = 'sst.aws.ApiGatewayV2',\n\tPostgres = 'sst.aws.Postgres',\n\tFunction = 'sst.aws.Function',\n\tObjectStorage = 'sst.aws.Bucket',\n\tVpc = 'sst.aws.Vpc',\n\tSecret = 'sst.sst.Secret',\n\tDynamo = 'sst.aws.Dynamo',\n\tQueue = 'sst.aws.Queue',\n\n\t// Modern format (colon notation)\n\tSSTSecret = 'sst:sst:Secret',\n\tSSTFunction = 'sst:sst:Function',\n\tSSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',\n\tSSTPostgres = 'sst:aws:Postgres',\n\tSSTObjectStorage = 'sst:aws:Bucket',\n\tSnsTopic = 'sst:aws:SnsTopic',\n\tSSTDynamo = 'sst:aws:Dynamo',\n\tSSTQueue = 'sst:aws:Queue',\n\t// A distribution, twice over: a file server and a static site are the same\n\t// infrastructure with different contents behind it, and they are separate\n\t// entries because what they provide is read under different ids, not\n\t// because SST builds them differently.\n\tFileServer = 'sst:aws:Router',\n\tStaticSite = 'sst:aws:StaticSite',\n\t// Neither is an SST component: mail is an IAM chain and a composed URL, and\n\t// a cache is whatever the selected backend turned out to be.\n\tEmail = 'gkm:aws:Email',\n\tCache = 'gkm:aws:Cache',\n}\n\n/**\n * AWS API Gateway V2 resource type.\n * Represents an HTTP/WebSocket API.\n */\nexport type ApiGatewayV2 = {\n\ttype: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;\n\turl: string;\n};\n\n/**\n * PostgreSQL database resource type.\n * Contains all connection details needed to connect to the database.\n */\nexport type Postgres = {\n\ttype: ResourceType.Postgres | ResourceType.SSTPostgres;\n\tdatabase: string;\n\thost: string;\n\tpassword: string;\n\tport: number;\n\tusername: string;\n};\n\n/**\n * AWS Lambda Function resource type.\n */\nexport type Function = {\n\ttype: ResourceType.Function | ResourceType.SSTFunction;\n\tname: string;\n};\n\n/**\n * AWS S3 Bucket resource type.\n */\nexport type Bucket = {\n\ttype: ResourceType.ObjectStorage | ResourceType.SSTObjectStorage;\n\tname: string;\n\t/**\n\t * Supplied by `@geekmidas/cloud`'s ObjectStorage, which widens SST's link to\n\t * carry them — a bucket may not be in the reader's region, and the URL is\n\t * composed where the resource's shape is known.\n\t */\n\tregion?: string;\n\turl?: string;\n};\n\n/**\n * AWS VPC (Virtual Private Cloud) resource type.\n */\nexport type Vpc = {\n\ttype: ResourceType.Vpc;\n\tbastion: string;\n};\n\n/**\n * Secret resource type for storing sensitive values.\n */\nexport type Secret = {\n\ttype: ResourceType.Secret | ResourceType.SSTSecret;\n\tvalue: string;\n};\n\n/**\n * AWS SNS Topic resource type.\n */\nexport type SnsTopic = {\n\ttype: ResourceType.SnsTopic;\n\tarn: string;\n};\n\n/**\n * AWS SQS Queue resource type.\n */\nexport type Queue = {\n\ttype: ResourceType.Queue | ResourceType.SSTQueue;\n\turl: string;\n\tarn: string;\n};\n\n/**\n * AWS DynamoDB Table resource type.\n */\nexport type Dynamo = {\n\ttype: ResourceType.Dynamo | ResourceType.SSTDynamo;\n\tname: string;\n};\n\n/**\n * Union type of all supported SST resource types.\n */\nexport type SstResource =\n\t| ApiGatewayV2\n\t| Postgres\n\t| Function\n\t| Bucket\n\t| Vpc\n\t| Secret\n\t| SnsTopic\n\t| Queue\n\t| Dynamo;\n\n// Value types without the `type` key (for resolver parameters)\ntype SecretValue = Omit<Secret, 'type'>;\ntype PostgresValue = Omit<Postgres, 'type'>;\ntype BucketValue = Omit<Bucket, 'type'>;\ntype SnsTopicValue = Omit<SnsTopic, 'type'>;\ntype QueueValue = Omit<Queue, 'type'>;\ntype DynamoValue = Omit<Dynamo, 'type'>;\n\n/**\n * Function type for processing a specific resource type into environment variables.\n *\n * @template K - The specific resource type (without `type` key)\n * @param name - The resource name\n * @param value - The resource value (without `type` key)\n * @returns Object mapping environment variable names to values\n */\nexport type ResourceProcessor<K> = (name: string, value: K) => EnvRecord;\n\n// SST Resource Resolvers (receive values without `type` key)\n\nconst secretResolver = (name: string, value: SecretValue) => ({\n\t[name]: value.value,\n});\n\nconst postgresResolver = (key: string, value: PostgresValue) => ({\n\t[`${key}Name`]: value.database,\n\t[`${key}Host`]: value.host,\n\t[`${key}Password`]: value.password,\n\t[`${key}Port`]: value.port,\n\t[`${key}Username`]: value.username,\n\t[`${key}Url`]: `postgresql://${encodeURIComponent(value.username)}:${encodeURIComponent(value.password)}@${value.host}:${value.port}/${value.database}`,\n});\n\nconst bucketResolver = (name: string, value: BucketValue) => ({\n\t[`${name}Name`]: value.name,\n\t// The single URL a construct reads. Composed by the component, which knows\n\t// its own shape; this only renames it into env case. Always emitted, even\n\t// when absent, so `resolveEnvKeys` can derive the key from the link's type\n\t// alone — a bucket linked without our component yields an empty one.\n\t[`${name}Url`]: value.url ?? '',\n});\n\nconst topicResolver = (name: string, value: SnsTopicValue) => ({\n\t[`${name}Arn`]: value.arn,\n\t// A publisher connection string for `@geekmidas/events` (SNS); region is\n\t// resolved from the ARN / AWS_REGION at runtime.\n\t[`${name}PublisherConnectionString`]: `sns://?topicArn=${encodeURIComponent(value.arn)}`,\n});\n\nconst queueResolver = (name: string, value: QueueValue) => ({\n\t[`${name}Url`]: value.url,\n\t[`${name}Arn`]: value.arn,\n\t// A publisher connection string for `@geekmidas/events` (SQS); region is\n\t// resolved from the URL / AWS_REGION at runtime.\n\t[`${name}PublisherConnectionString`]: `sqs://?queueUrl=${encodeURIComponent(value.url)}`,\n});\n\nconst dynamoResolver = (name: string, value: DynamoValue) => ({\n\t[`${name}Name`]: value.name,\n});\n\nconst noopResolver = () => ({});\n\n/**\n * Pre-configured resolvers for all SST resource types.\n */\nexport const sstResolvers: Resolvers = {\n\t// Legacy format\n\t[ResourceType.ApiGatewayV2]: noopResolver,\n\t[ResourceType.Function]: noopResolver,\n\t[ResourceType.Vpc]: noopResolver,\n\t[ResourceType.Secret]: secretResolver,\n\t[ResourceType.Postgres]: postgresResolver,\n\t[ResourceType.ObjectStorage]: bucketResolver,\n\t[ResourceType.Dynamo]: dynamoResolver,\n\t[ResourceType.Queue]: queueResolver,\n\n\t// Modern format\n\t[ResourceType.SSTSecret]: secretResolver,\n\t[ResourceType.SSTObjectStorage]: bucketResolver,\n\t[ResourceType.SSTFunction]: noopResolver,\n\t[ResourceType.SSTPostgres]: postgresResolver,\n\t[ResourceType.SSTApiGatewayV2]: noopResolver,\n\t[ResourceType.SnsTopic]: topicResolver,\n\t[ResourceType.SSTDynamo]: dynamoResolver,\n\t[ResourceType.SSTQueue]: queueResolver,\n};\n\n/**\n * All known SST resource type strings.\n */\ntype SstResourceTypeString = `${ResourceType}`;\n\n/**\n * Extracts the `type` string value from an input value.\n */\ntype ExtractType<T> = T extends { type: infer U extends string } ? U : never;\n\n/**\n * Removes the `type` key from an object type.\n */\ntype OmitType<T> = T extends { type: string } ? Omit<T, 'type'> : never;\n\n/**\n * Extracts all unique `type` values from a record (excluding plain strings).\n */\ntype AllTypeValues<TRecord extends Record<string, InputValue>> = {\n\t[K in keyof TRecord]: ExtractType<TRecord[K]>;\n}[keyof TRecord];\n\n/**\n * Extracts only the custom (non-SST) type values from a record.\n */\ntype CustomTypeValues<TRecord extends Record<string, InputValue>> = Exclude<\n\tAllTypeValues<TRecord>,\n\tSstResourceTypeString\n>;\n\n/**\n * For a given type value, finds the corresponding value type (without `type` key).\n */\ntype ValueForType<\n\tTRecord extends Record<string, InputValue>,\n\tTType extends string,\n> = {\n\t[K in keyof TRecord]: TRecord[K] extends { type: TType }\n\t\t? OmitType<TRecord[K]>\n\t\t: never;\n}[keyof TRecord];\n\n/**\n * Generates typed resolvers for custom (non-SST) types in the input record.\n */\ntype CustomResolvers<TRecord extends Record<string, InputValue>> =\n\tCustomTypeValues<TRecord> extends never\n\t\t? Resolvers | undefined\n\t\t: {\n\t\t\t\t[TType in CustomTypeValues<TRecord>]: EnvironmentResolver<\n\t\t\t\t\tValueForType<TRecord, TType>\n\t\t\t\t>;\n\t\t\t};\n\n/**\n * SST-specific environment builder with built-in resolvers for all known\n * SST resource types.\n *\n * Wraps the generic EnvironmentBuilder with pre-configured SST resolvers.\n *\n * @template TRecord - The input record type for type inference\n *\n * @example\n * ```typescript\n * const env = new SstEnvironmentBuilder({\n * database: { type: 'sst:aws:Postgres', host: '...', ... },\n * apiKey: { type: 'sst:sst:Secret', value: 'secret' },\n * appName: 'my-app',\n * }).build();\n *\n * // With custom resolvers (typed based on input)\n * const env = new SstEnvironmentBuilder(\n * {\n * database: postgresResource,\n * custom: { type: 'my-custom' as const, data: 'foo' },\n * },\n * {\n * // TypeScript requires 'my-custom' resolver with typed value\n * 'my-custom': (key, value) => ({ [`${key}Data`]: value.data }),\n * }\n * ).build();\n * ```\n */\nexport class SstEnvironmentBuilder<\n\tTRecord extends Record<string, SstResource | InputValue | string>,\n> {\n\tprivate readonly builder: EnvironmentBuilder<\n\t\tRecord<string, InputValue>,\n\t\tResolvers\n\t>;\n\n\t/**\n\t * Create a new SST environment builder.\n\t *\n\t * @param record - Object containing SST resources, custom resources, and/or string values\n\t * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)\n\t * @param options - Optional configuration options\n\t */\n\tconstructor(\n\t\trecord: TRecord,\n\t\tadditionalResolvers?: CustomResolvers<TRecord>,\n\t\toptions?: EnvironmentBuilderOptions,\n\t) {\n\t\t// Merge resolvers with custom ones taking precedence\n\t\tconst mergedResolvers: Resolvers = additionalResolvers\n\t\t\t? { ...sstResolvers, ...additionalResolvers }\n\t\t\t: sstResolvers;\n\n\t\tthis.builder = new EnvironmentBuilder(\n\t\t\trecord as Record<string, InputValue>,\n\t\t\tmergedResolvers,\n\t\t\toptions,\n\t\t);\n\t}\n\n\t/**\n\t * Build environment variables from the input record.\n\t *\n\t * @returns A record of environment variables\n\t */\n\tbuild(): EnvRecord {\n\t\treturn this.builder.build();\n\t}\n}\n\nexport type {\n\tEnvironmentBuilderOptions,\n\tEnvRecord,\n\tEnvValue,\n} from './EnvironmentBuilder';\n// Re-export useful types\nexport { environmentCase } from './EnvironmentBuilder';\n","import { EnvironmentBuilder, type InputValue } from './EnvironmentBuilder';\nimport { type SstResource, sstResolvers } from './SstEnvironmentBuilder';\n\n/**\n * Variables AWS Lambda injects into the runtime. Always valid on AWS, but never\n * assumed — opt in via `platform: 'aws'` or by spreading {@link AWS_RUNTIME_ENV_VARS}\n * into `whitelist`.\n */\nexport const AWS_RUNTIME_ENV_VARS = [\n\t'AWS_REGION',\n\t'AWS_DEFAULT_REGION',\n\t'AWS_ENDPOINT_URL',\n\t'AWS_ENDPOINT',\n\t'AWS_ACCESS_KEY_ID',\n\t'AWS_SECRET_ACCESS_KEY',\n\t'AWS_SESSION_TOKEN',\n\t'AWS_LAMBDA_FUNCTION_NAME',\n\t'AWS_LAMBDA_FUNCTION_VERSION',\n] as const;\n\n/**\n * Variables GCP injects into Cloud Functions / Cloud Run.\n */\nexport const GCP_RUNTIME_ENV_VARS = [\n\t'GOOGLE_CLOUD_PROJECT',\n\t'GCP_PROJECT',\n\t'FUNCTION_TARGET',\n\t'FUNCTION_SIGNATURE_TYPE',\n\t'K_SERVICE',\n\t'K_REVISION',\n\t'K_CONFIGURATION',\n\t'PORT',\n] as const;\n\n/**\n * Variables Cloudflare exposes to Workers. Workers inject almost nothing into\n * the global env, so this is intentionally minimal.\n */\nexport const CLOUDFLARE_RUNTIME_ENV_VARS = [\n\t'CF_PAGES',\n\t'CF_PAGES_URL',\n] as const;\n\n/**\n * Registry of platform → always-valid runtime variables. Export, don't assume:\n * a caller states the platform it deploys to and the matching set is trusted.\n */\nexport const PLATFORM_ENV_VARS = {\n\taws: AWS_RUNTIME_ENV_VARS,\n\tgcp: GCP_RUNTIME_ENV_VARS,\n\tcloudflare: CLOUDFLARE_RUNTIME_ENV_VARS,\n} as const;\n\nexport type Platform = keyof typeof PLATFORM_ENV_VARS;\n\n/**\n * The always-valid runtime variables for a platform. The \"whitelist construct\":\n * resolve a platform to its set, to spread into `whitelist` or compare against.\n */\nexport function platformEnvVars(platform: Platform): readonly string[] {\n\treturn PLATFORM_ENV_VARS[platform];\n}\n\n/** How many link-provided vars to list in an error before truncating. */\nconst MAX_LISTED_VARS = 8;\n\n/** Minimum similarity for a variable to be offered as a \"did you mean\". */\nconst SUGGESTION_THRESHOLD = 0.3;\n\n/**\n * Input shape for the validator: the same record `SstEnvironmentBuilder`\n * accepts — keyed by resource name, valued by an SST resource (or a plain\n * string for pass-through env vars).\n */\nexport type LinkRecord = Record<string, SstResource | InputValue | string>;\n\nexport interface ValidationResult {\n\tvalid: boolean;\n\t/** Requested variables that are not available (excluding optional `?` vars). */\n\tinvalidVars: string[];\n\t/** Every variable the links + whitelist make available. */\n\tavailableVars: string[];\n\t/** Nearest available matches for each invalid variable (best first). */\n\tsuggestions: Record<string, string[]>;\n}\n\nexport interface EnvValidatorOptions {\n\t/**\n\t * Platform whose runtime-injected variables are always valid. Omit to assume\n\t * none — the validator never bakes in a platform's variables.\n\t */\n\tplatform?: Platform;\n\t/**\n\t * Extra always-valid variables in addition to the platform set — typically\n\t * the keys of a function's explicit `environment`.\n\t */\n\twhitelist?: readonly string[];\n\t/**\n\t * Label for the deployable unit (e.g. a function name), used in error\n\t * messages so a failure points at exactly one unit.\n\t */\n\tcontext?: string;\n}\n\n/**\n * Levenshtein edit distance between two strings.\n */\nfunction levenshtein(a: string, b: string): number {\n\tconst m = a.length;\n\tconst n = b.length;\n\tif (m === 0) return n;\n\tif (n === 0) return m;\n\n\tlet prev = Array.from({ length: n + 1 }, (_, i) => i);\n\n\tfor (let i = 1; i <= m; i++) {\n\t\tconst curr: number[] = [i];\n\t\tfor (let j = 1; j <= n; j++) {\n\t\t\tconst cost = a[i - 1] === b[j - 1] ? 0 : 1;\n\t\t\tconst del = (prev[j] ?? 0) + 1;\n\t\t\tconst ins = (curr[j - 1] ?? 0) + 1;\n\t\t\tconst sub = (prev[j - 1] ?? 0) + cost;\n\t\t\tcurr[j] = Math.min(del, ins, sub);\n\t\t}\n\t\tprev = curr;\n\t}\n\n\treturn prev[n] ?? 0;\n}\n\n/**\n * Similarity in `[0, 1]` combining edit distance with `_`-token overlap, so both\n * near-typos (a missing underscore) and renames (`DATABASE_URL` ~ `DB_URL`,\n * which share the `URL` token) are caught.\n */\nfunction similarity(a: string, b: string): number {\n\tconst editSim = 1 - levenshtein(a, b) / Math.max(a.length, b.length, 1);\n\n\tconst ta = new Set(a.split('_').filter(Boolean));\n\tconst tb = new Set(b.split('_').filter(Boolean));\n\tconst shared = [...ta].filter((t) => tb.has(t)).length;\n\tconst union = new Set([...ta, ...tb]).size || 1;\n\tconst tokenSim = shared / union;\n\n\t// Nudge token-overlap matches ahead of coincidental edit-distance ones, so a\n\t// rename like DATABASE_URL prefers DB_URL (shares `URL`) over DB_PASSWORD.\n\treturn Math.max(editSim, tokenSim * 1.15);\n}\n\n/**\n * Returns the nearest available variables to `missing`, best first, limited to\n * those above {@link SUGGESTION_THRESHOLD}.\n */\nfunction suggestionsFor(\n\tmissing: string,\n\tavailable: readonly string[],\n\tmax = 1,\n): string[] {\n\treturn available\n\t\t.map((candidate) => ({ candidate, score: similarity(missing, candidate) }))\n\t\t.filter((s) => s.score >= SUGGESTION_THRESHOLD)\n\t\t.sort((a, b) => b.score - a.score)\n\t\t.slice(0, max)\n\t\t.map((s) => s.candidate);\n}\n\n/**\n * Thrown when a deployable unit requires environment variables its links do not\n * provide. Carries the structured `missing`/`available`/`suggestions` so callers\n * can inspect the failure programmatically, not just read the message.\n */\nexport class EnvValidationError extends Error {\n\treadonly isEnvValidationError = true;\n\treadonly missing: string[];\n\treadonly available: string[];\n\treadonly suggestions: Record<string, string[]>;\n\treadonly context?: string;\n\n\tconstructor(args: {\n\t\tmissing: string[];\n\t\tavailable: string[];\n\t\tlinkVars: string[];\n\t\tsuggestions: Record<string, string[]>;\n\t\tcontext?: string;\n\t}) {\n\t\tsuper(EnvValidationError.format(args));\n\t\tthis.name = 'EnvValidationError';\n\t\tthis.missing = args.missing;\n\t\tthis.available = args.available;\n\t\tthis.suggestions = args.suggestions;\n\t\tthis.context = args.context;\n\t\t// V8-only; keeps the constructor out of the stack trace.\n\t\t(\n\t\t\tError as unknown as {\n\t\t\t\tcaptureStackTrace?(target: object, ctor?: unknown): void;\n\t\t\t}\n\t\t).captureStackTrace?.(this, EnvValidationError);\n\t}\n\n\tprivate static format(args: {\n\t\tmissing: string[];\n\t\tlinkVars: string[];\n\t\tsuggestions: Record<string, string[]>;\n\t\tcontext?: string;\n\t}): string {\n\t\tconst { missing, linkVars, suggestions, context } = args;\n\t\tconst who = context ? `'${context}'` : 'a deployable unit';\n\n\t\tconst width = Math.max(...missing.map((v) => v.length));\n\t\tconst lines = missing.map((v) => {\n\t\t\tconst hints = suggestions[v] ?? [];\n\t\t\tconst hint = hints.length ? `(did you mean ${hints.join(' or ')}?)` : '';\n\t\t\treturn ` - ${v.padEnd(width)} ${hint}`.trimEnd();\n\t\t});\n\n\t\tlet provided: string;\n\t\tif (linkVars.length === 0) {\n\t\t\tprovided = '(no links provide environment variables)';\n\t\t} else {\n\t\t\tconst shown = linkVars.slice(0, MAX_LISTED_VARS).join(', ');\n\t\t\tconst extra =\n\t\t\t\tlinkVars.length > MAX_LISTED_VARS\n\t\t\t\t\t? ` ...(+${linkVars.length - MAX_LISTED_VARS})`\n\t\t\t\t\t: '';\n\t\t\tprovided = `Provided by links: ${shown}${extra}`;\n\t\t}\n\n\t\treturn `${who} is missing required env vars:\\n${lines.join('\\n')}\\n\\n${provided}`;\n\t}\n}\n\n/**\n * Derives the set of environment-variable **keys** a group of linked resources\n * will produce at runtime — without resolving any value.\n *\n * This reuses the runtime resolvers (`sstResolvers`) via {@link EnvironmentBuilder},\n * so the keys computed here are exactly the keys a deployed function receives:\n * the validator and the runtime resolution share a single source of truth and\n * cannot drift. Because every resolver's output keys depend only on the record\n * key and the resource `type` (never the value), each resource is reduced to\n * `{ type }` before building, so no SST `Output` is ever read.\n *\n * @example\n * resolveEnvKeys({ db: { type: ResourceType.Postgres } });\n * // ['DB_NAME', 'DB_HOST', 'DB_PASSWORD', 'DB_PORT', 'DB_USERNAME', 'DB_URL']\n */\nexport function resolveEnvKeys(record: LinkRecord): string[] {\n\tconst typeOnly: Record<string, InputValue> = {};\n\tfor (const [key, value] of Object.entries(record)) {\n\t\ttypeOnly[key] = typeof value === 'string' ? '' : { type: value.type };\n\t}\n\treturn Object.keys(new EnvironmentBuilder(typeOnly, sstResolvers).build());\n}\n\n/**\n * Validates that the environment variables a deployable unit requires are\n * actually provided by its linked resources — at infra time, before deploy.\n *\n * Available variables are the union of the keys derived from `links`\n * ({@link resolveEnvKeys}), the chosen platform's runtime variables (only when\n * `options.platform` is set — nothing is assumed), and any `options.whitelist`\n * (e.g. the keys of a function's explicit `environment`). A requested variable\n * suffixed with `?` is treated as optional and never causes a failure.\n *\n * @example\n * const validator = new EnvValidator(\n * { db: { type: ResourceType.Postgres } },\n * { platform: 'aws', whitelist: ['APP_NAME'], context: 'orders-fn' },\n * );\n * validator.assert(['DB_HOST', 'AWS_REGION', 'APP_NAME', 'SENTRY_DSN?']); // ok\n * validator.assert(['DATABASE_URL']); // throws EnvValidationError (did you mean DB_URL?)\n */\nexport class EnvValidator {\n\t/** Every variable available — link-derived, platform, and extra whitelist. */\n\treadonly availableVars: string[];\n\t/** Just the variables the links provide (used for error context). */\n\treadonly linkVars: string[];\n\treadonly context?: string;\n\tprivate readonly availableSet: Set<string>;\n\t/** Per-link (record key → its env-var keys), for least-privilege filtering. */\n\tprivate readonly linkVarsByName: Map<string, string[]>;\n\n\tconstructor(links: LinkRecord, options: EnvValidatorOptions = {}) {\n\t\tconst { platform, whitelist = [], context } = options;\n\t\tthis.context = context;\n\t\tthis.linkVarsByName = new Map(\n\t\t\tObject.entries(links).map(([name, value]) => [\n\t\t\t\tname,\n\t\t\t\tresolveEnvKeys({ [name]: value }),\n\t\t\t]),\n\t\t);\n\t\tthis.linkVars = [...this.linkVarsByName.values()].flat();\n\t\tthis.availableVars = [\n\t\t\t...this.linkVars,\n\t\t\t...(platform ? PLATFORM_ENV_VARS[platform] : []),\n\t\t\t...whitelist,\n\t\t];\n\t\tthis.availableSet = new Set(this.availableVars);\n\t}\n\n\t/**\n\t * Returns the names of the links that provide at least one of the requested\n\t * variables — so a construct can attach only the links a unit actually needs\n\t * (least privilege) rather than the whole pool. Trailing `?` is ignored.\n\t */\n\tgetProvidersForEnvVars(requestedEnvVars: readonly string[]): string[] {\n\t\tconst requested = new Set(\n\t\t\trequestedEnvVars.map((v) => (v.endsWith('?') ? v.slice(0, -1) : v)),\n\t\t);\n\t\tconst providers: string[] = [];\n\t\tfor (const [name, vars] of this.linkVarsByName) {\n\t\t\tif (vars.some((v) => requested.has(v))) providers.push(name);\n\t\t}\n\t\treturn providers;\n\t}\n\n\t/**\n\t * Checks every requested variable against the available set. Variables\n\t * ending in `?` are optional and never reported as invalid. Invalid\n\t * variables come back with their nearest available matches.\n\t */\n\tvalidate(requestedEnvVars: readonly string[]): ValidationResult {\n\t\tconst invalidVars = requestedEnvVars.filter((envVar) => {\n\t\t\tif (envVar.endsWith('?')) return false;\n\t\t\treturn !this.availableSet.has(envVar);\n\t\t});\n\n\t\tconst suggestions: Record<string, string[]> = {};\n\t\tfor (const envVar of invalidVars) {\n\t\t\tconst matches = suggestionsFor(envVar, this.availableVars);\n\t\t\tif (matches.length) suggestions[envVar] = matches;\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: invalidVars.length === 0,\n\t\t\tinvalidVars,\n\t\t\tavailableVars: this.availableVars,\n\t\t\tsuggestions,\n\t\t};\n\t}\n\n\t/**\n\t * Asserts that every requested variable is available, throwing an\n\t * {@link EnvValidationError} otherwise. Intended to run in a construct's\n\t * constructor so a misconfigured `sst.config.ts` fails at synth time, before\n\t * any AWS call.\n\t */\n\tassert(requestedEnvVars: readonly string[]): void {\n\t\tconst { valid, invalidVars, suggestions } = this.validate(requestedEnvVars);\n\n\t\tif (!valid) {\n\t\t\tthrow new EnvValidationError({\n\t\t\t\tmissing: invalidVars,\n\t\t\t\tavailable: this.availableVars,\n\t\t\t\tlinkVars: this.linkVars,\n\t\t\t\tsuggestions,\n\t\t\t\tcontext: this.context,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Whether a single variable is available. Does not treat a trailing `?` as\n\t * optional — pass the bare name.\n\t */\n\thas(envVar: string): boolean {\n\t\treturn this.availableSet.has(envVar);\n\t}\n}\n","// Re-export everything from SstEnvironmentBuilder\n\n// Re-export types from EnvironmentBuilder\nexport type {\n\tEnvironmentBuilderOptions,\n\tEnvRecord,\n\tEnvValue,\n} from './EnvironmentBuilder';\n\n// Re-export environmentCase from EnvironmentBuilder\nexport { environmentCase } from './EnvironmentBuilder';\nexport {\n\ttype ApiGatewayV2,\n\ttype Bucket,\n\ttype Dynamo,\n\ttype Function,\n\ttype Postgres,\n\ttype Queue,\n\ttype ResourceProcessor,\n\tResourceType,\n\ttype Secret,\n\ttype SnsTopic,\n\tSstEnvironmentBuilder,\n\ttype SstResource,\n\tsstResolvers,\n\ttype Vpc,\n} from './SstEnvironmentBuilder';\n\nexport {\n\tAWS_RUNTIME_ENV_VARS,\n\tCLOUDFLARE_RUNTIME_ENV_VARS,\n\tEnvValidationError,\n\tEnvValidator,\n\ttype EnvValidatorOptions,\n\tGCP_RUNTIME_ENV_VARS,\n\ttype LinkRecord,\n\tPLATFORM_ENV_VARS,\n\ttype Platform,\n\tplatformEnvVars,\n\tresolveEnvKeys,\n\ttype ValidationResult,\n} from './SstEnvValidator';\n\n// Import for deprecated function\nimport {\n\tSstEnvironmentBuilder,\n\ttype SstResource,\n} from './SstEnvironmentBuilder';\n\n/**\n * @deprecated Use `new SstEnvironmentBuilder(record).build()` instead.\n *\n * Normalizes SST resources and plain strings into environment variables.\n * Processes resources based on their type and converts names to environment case.\n *\n * @param record - Object containing resources and/or string values\n * @returns Normalized environment variables object\n *\n * @example\n * // Old usage (deprecated):\n * normalizeResourceEnv({ database: postgresResource })\n *\n * // New usage:\n * new SstEnvironmentBuilder({ database: postgresResource }).build()\n */\nexport function normalizeResourceEnv(\n\trecord: Record<string, SstResource | string>,\n): Record<string, string | number | boolean | Record<string, unknown>> {\n\treturn new SstEnvironmentBuilder(record).build();\n}\n\n// Keep Resource type as deprecated alias for backwards compatibility\n/**\n * @deprec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,EAAE,OAAO,aAAa,gBAAgB,KAAK,SAAS,gBAAgB;EAE1E,IAAI,CAAC,OACJ,MAAM,IAAI,mBAAmB;GAC5B,SAAS;GACT,WAAW,KAAK;GAChB,UAAU,KAAK;GACf;GACA,SAAS,KAAK;EACf,CAAC;CAEH;;;;;CAMA,IAAI,QAAyB;EAC5B,OAAO,KAAK,aAAa,IAAI,MAAM;CACpC;AACD;;;;;;;;;;;;;;;;;;;AC/SA,SAAgB,qBACf,QACsE;CACtE,OAAO,IAAI,sBAAsB,MAAM,CAAC,CAAC,MAAM;AAChD"}
1
+ {"version":3,"file":"sst.mjs","names":[],"sources":["../src/SstEnvironmentBuilder.ts","../src/SstEnvValidator.ts","../src/sst.ts"],"sourcesContent":["import {\n\tEnvironmentBuilder,\n\ttype EnvironmentBuilderOptions,\n\ttype EnvironmentResolver,\n\ttype EnvRecord,\n\ttype InputValue,\n\ttype Resolvers,\n} from './EnvironmentBuilder';\n\n/**\n * Enumeration of supported SST (Serverless Stack Toolkit) resource types.\n * Used to identify and process different AWS and SST resources.\n */\nexport enum ResourceType {\n\t// Legacy format (dot notation)\n\tApiGatewayV2 = 'sst.aws.ApiGatewayV2',\n\tPostgres = 'sst.aws.Postgres',\n\tFunction = 'sst.aws.Function',\n\tObjectStorage = 'sst.aws.Bucket',\n\tVpc = 'sst.aws.Vpc',\n\tSecret = 'sst.sst.Secret',\n\tDynamo = 'sst.aws.Dynamo',\n\tQueue = 'sst.aws.Queue',\n\n\t// Modern format (colon notation)\n\tSSTSecret = 'sst:sst:Secret',\n\tSSTFunction = 'sst:sst:Function',\n\tSSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',\n\tSSTPostgres = 'sst:aws:Postgres',\n\tSSTObjectStorage = 'sst:aws:Bucket',\n\tSnsTopic = 'sst:aws:SnsTopic',\n\tSSTDynamo = 'sst:aws:Dynamo',\n\tSSTQueue = 'sst:aws:Queue',\n\t// A distribution, twice over: a file server and a static site are the same\n\t// infrastructure with different contents behind it, and they are separate\n\t// entries because what they provide is read under different ids, not\n\t// because SST builds them differently.\n\tFileServer = 'sst:aws:Router',\n\tStaticSite = 'sst:aws:StaticSite',\n\t// Neither is an SST component: mail is an IAM chain and a composed URL, and\n\t// a cache is whatever the selected backend turned out to be.\n\tEmail = 'gkm:aws:Email',\n\tCache = 'gkm:aws:Cache',\n\t// Somebody else's API: an address and the credentials it was issued.\n\tExternalApi = 'gkm:aws:ExternalApi',\n\t// A third party's credentials: stored as an SST secret, read under its own\n\t// key rather than the secret's bare name.\n\tCredential = 'gkm:aws:Credential',\n\t// A KMS key and its HMAC key, handed over as one `kms://` URL.\n\tEncryption = 'gkm:aws:Encryption',\n\t// An API Gateway WebSocket API and the table its connections are kept in:\n\t// where a client opens it, who may, and the `apigateway://` string its\n\t// publisher sends through.\n\tWebSocketApi = 'gkm:aws:WebSocketApi',\n\t// Mail received: where its raw messages are read, and the domain it is\n\t// addressed to — both made by the inbox's provider, not by SST.\n\tInbox = 'gkm:aws:Inbox',\n}\n\n/**\n * AWS API Gateway V2 resource type.\n * Represents an HTTP/WebSocket API.\n */\nexport type ApiGatewayV2 = {\n\ttype: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;\n\turl: string;\n};\n\n/**\n * PostgreSQL database resource type.\n * Contains all connection details needed to connect to the database.\n */\nexport type Postgres = {\n\ttype: ResourceType.Postgres | ResourceType.SSTPostgres;\n\tdatabase: string;\n\thost: string;\n\tpassword: string;\n\tport: number;\n\tusername: string;\n};\n\n/**\n * AWS Lambda Function resource type.\n */\nexport type Function = {\n\ttype: ResourceType.Function | ResourceType.SSTFunction;\n\tname: string;\n};\n\n/**\n * AWS S3 Bucket resource type.\n */\nexport type Bucket = {\n\ttype: ResourceType.ObjectStorage | ResourceType.SSTObjectStorage;\n\tname: string;\n\t/**\n\t * Supplied by `@geekmidas/cloud`'s ObjectStorage, which widens SST's link to\n\t * carry them — a bucket may not be in the reader's region, and the URL is\n\t * composed where the resource's shape is known.\n\t */\n\tregion?: string;\n\turl?: string;\n};\n\n/**\n * AWS VPC (Virtual Private Cloud) resource type.\n */\nexport type Vpc = {\n\ttype: ResourceType.Vpc;\n\tbastion: string;\n};\n\n/**\n * Secret resource type for storing sensitive values.\n */\nexport type Secret = {\n\ttype: ResourceType.Secret | ResourceType.SSTSecret;\n\tvalue: string;\n};\n\n/**\n * AWS SNS Topic resource type.\n */\nexport type SnsTopic = {\n\ttype: ResourceType.SnsTopic;\n\tarn: string;\n};\n\n/**\n * AWS SQS Queue resource type.\n */\nexport type Queue = {\n\ttype: ResourceType.Queue | ResourceType.SSTQueue;\n\turl: string;\n\tarn: string;\n};\n\n/**\n * AWS DynamoDB Table resource type.\n */\nexport type Dynamo = {\n\ttype: ResourceType.Dynamo | ResourceType.SSTDynamo;\n\tname: string;\n};\n\n/**\n * Union type of all supported SST resource types.\n */\nexport type SstResource =\n\t| ApiGatewayV2\n\t| Postgres\n\t| Function\n\t| Bucket\n\t| Vpc\n\t| Secret\n\t| SnsTopic\n\t| Queue\n\t| Dynamo;\n\n// Value types without the `type` key (for resolver parameters)\ntype SecretValue = Omit<Secret, 'type'>;\ntype ExternalApiValue = { url: string; credentials: string };\ntype CredentialValue = { credentials: string };\ntype EncryptionValue = { url: string };\ntype InboxValue = { url: string; domain: string };\ntype WebSocketApiValue = {\n\turl: string;\n\ttrustedOrigins: string;\n\tpublisherConnectionString: string;\n};\ntype PostgresValue = Omit<Postgres, 'type'>;\ntype BucketValue = Omit<Bucket, 'type'>;\ntype SnsTopicValue = Omit<SnsTopic, 'type'>;\ntype QueueValue = Omit<Queue, 'type'>;\ntype DynamoValue = Omit<Dynamo, 'type'>;\n\n/**\n * Function type for processing a specific resource type into environment variables.\n *\n * @template K - The specific resource type (without `type` key)\n * @param name - The resource name\n * @param value - The resource value (without `type` key)\n * @returns Object mapping environment variable names to values\n */\nexport type ResourceProcessor<K> = (name: string, value: K) => EnvRecord;\n\n// SST Resource Resolvers (receive values without `type` key)\n\nconst secretResolver = (name: string, value: SecretValue) => ({\n\t[name]: value.value,\n});\n\nconst postgresResolver = (key: string, value: PostgresValue) => ({\n\t[`${key}Name`]: value.database,\n\t[`${key}Host`]: value.host,\n\t[`${key}Password`]: value.password,\n\t[`${key}Port`]: value.port,\n\t[`${key}Username`]: value.username,\n\t[`${key}Url`]: `postgresql://${encodeURIComponent(value.username)}:${encodeURIComponent(value.password)}@${value.host}:${value.port}/${value.database}`,\n});\n\nconst bucketResolver = (name: string, value: BucketValue) => ({\n\t[`${name}Name`]: value.name,\n\t// The single URL a construct reads. Composed by the component, which knows\n\t// its own shape; this only renames it into env case. Always emitted, even\n\t// when absent, so `resolveEnvKeys` can derive the key from the link's type\n\t// alone — a bucket linked without our component yields an empty one.\n\t[`${name}Url`]: value.url ?? '',\n});\n\nconst topicResolver = (name: string, value: SnsTopicValue) => ({\n\t[`${name}Arn`]: value.arn,\n\t// A publisher connection string for `@geekmidas/events` (SNS); region is\n\t// resolved from the ARN / AWS_REGION at runtime.\n\t[`${name}PublisherConnectionString`]: `sns://?topicArn=${encodeURIComponent(value.arn)}`,\n});\n\nconst queueResolver = (name: string, value: QueueValue) => ({\n\t[`${name}Url`]: value.url,\n\t[`${name}Arn`]: value.arn,\n\t// A publisher connection string for `@geekmidas/events` (SQS); region is\n\t// resolved from the URL / AWS_REGION at runtime.\n\t[`${name}PublisherConnectionString`]: `sqs://?queueUrl=${encodeURIComponent(value.url)}`,\n});\n\nconst dynamoResolver = (name: string, value: DynamoValue) => ({\n\t[`${name}Name`]: value.name,\n});\n\nconst externalApiResolver = (name: string, value: ExternalApiValue) => ({\n\t[`${name}Url`]: value.url,\n\t[`${name}Credentials`]: value.credentials,\n});\n\nconst credentialResolver = (name: string, value: CredentialValue) => ({\n\t[`${name}Credentials`]: value.credentials,\n});\n\nconst encryptionResolver = (name: string, value: EncryptionValue) => ({\n\t[`${name}Url`]: value.url,\n});\n\nconst inboxResolver = (name: string, value: InboxValue) => ({\n\t[`${name}Url`]: value.url,\n\t[`${name}Domain`]: value.domain,\n});\n\nconst webSocketApiResolver = (name: string, value: WebSocketApiValue) => ({\n\t[`${name}Url`]: value.url,\n\t[`${name}TrustedOrigins`]: value.trustedOrigins,\n\t[`${name}PublisherConnectionString`]: value.publisherConnectionString,\n});\n\nconst noopResolver = () => ({});\n\n/**\n * Pre-configured resolvers for all SST resource types.\n */\nexport const sstResolvers: Resolvers = {\n\t// Legacy format\n\t[ResourceType.ApiGatewayV2]: noopResolver,\n\t[ResourceType.Function]: noopResolver,\n\t[ResourceType.Vpc]: noopResolver,\n\t[ResourceType.Secret]: secretResolver,\n\t[ResourceType.Postgres]: postgresResolver,\n\t[ResourceType.ObjectStorage]: bucketResolver,\n\t[ResourceType.Dynamo]: dynamoResolver,\n\t[ResourceType.Queue]: queueResolver,\n\n\t// Modern format\n\t[ResourceType.SSTSecret]: secretResolver,\n\t[ResourceType.SSTObjectStorage]: bucketResolver,\n\t[ResourceType.SSTFunction]: noopResolver,\n\t[ResourceType.SSTPostgres]: postgresResolver,\n\t[ResourceType.SSTApiGatewayV2]: noopResolver,\n\t[ResourceType.SnsTopic]: topicResolver,\n\t[ResourceType.SSTDynamo]: dynamoResolver,\n\t[ResourceType.SSTQueue]: queueResolver,\n\t[ResourceType.ExternalApi]: externalApiResolver,\n\t[ResourceType.Credential]: credentialResolver,\n\t[ResourceType.Encryption]: encryptionResolver,\n\t[ResourceType.Inbox]: inboxResolver,\n\t[ResourceType.WebSocketApi]: webSocketApiResolver,\n};\n\n/**\n * All known SST resource type strings.\n */\ntype SstResourceTypeString = `${ResourceType}`;\n\n/**\n * Extracts the `type` string value from an input value.\n */\ntype ExtractType<T> = T extends { type: infer U extends string } ? U : never;\n\n/**\n * Removes the `type` key from an object type.\n */\ntype OmitType<T> = T extends { type: string } ? Omit<T, 'type'> : never;\n\n/**\n * Extracts all unique `type` values from a record (excluding plain strings).\n */\ntype AllTypeValues<TRecord extends Record<string, InputValue>> = {\n\t[K in keyof TRecord]: ExtractType<TRecord[K]>;\n}[keyof TRecord];\n\n/**\n * Extracts only the custom (non-SST) type values from a record.\n */\ntype CustomTypeValues<TRecord extends Record<string, InputValue>> = Exclude<\n\tAllTypeValues<TRecord>,\n\tSstResourceTypeString\n>;\n\n/**\n * For a given type value, finds the corresponding value type (without `type` key).\n */\ntype ValueForType<\n\tTRecord extends Record<string, InputValue>,\n\tTType extends string,\n> = {\n\t[K in keyof TRecord]: TRecord[K] extends { type: TType }\n\t\t? OmitType<TRecord[K]>\n\t\t: never;\n}[keyof TRecord];\n\n/**\n * Generates typed resolvers for custom (non-SST) types in the input record.\n */\ntype CustomResolvers<TRecord extends Record<string, InputValue>> =\n\tCustomTypeValues<TRecord> extends never\n\t\t? Resolvers | undefined\n\t\t: {\n\t\t\t\t[TType in CustomTypeValues<TRecord>]: EnvironmentResolver<\n\t\t\t\t\tValueForType<TRecord, TType>\n\t\t\t\t>;\n\t\t\t};\n\n/**\n * SST-specific environment builder with built-in resolvers for all known\n * SST resource types.\n *\n * Wraps the generic EnvironmentBuilder with pre-configured SST resolvers.\n *\n * @template TRecord - The input record type for type inference\n *\n * @example\n * ```typescript\n * const env = new SstEnvironmentBuilder({\n * database: { type: 'sst:aws:Postgres', host: '...', ... },\n * apiKey: { type: 'sst:sst:Secret', value: 'secret' },\n * appName: 'my-app',\n * }).build();\n *\n * // With custom resolvers (typed based on input)\n * const env = new SstEnvironmentBuilder(\n * {\n * database: postgresResource,\n * custom: { type: 'my-custom' as const, data: 'foo' },\n * },\n * {\n * // TypeScript requires 'my-custom' resolver with typed value\n * 'my-custom': (key, value) => ({ [`${key}Data`]: value.data }),\n * }\n * ).build();\n * ```\n */\nexport class SstEnvironmentBuilder<\n\tTRecord extends Record<string, SstResource | InputValue | string>,\n> {\n\tprivate readonly builder: EnvironmentBuilder<\n\t\tRecord<string, InputValue>,\n\t\tResolvers\n\t>;\n\n\t/**\n\t * Create a new SST environment builder.\n\t *\n\t * @param record - Object containing SST resources, custom resources, and/or string values\n\t * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)\n\t * @param options - Optional configuration options\n\t */\n\tconstructor(\n\t\trecord: TRecord,\n\t\tadditionalResolvers?: CustomResolvers<TRecord>,\n\t\toptions?: EnvironmentBuilderOptions,\n\t) {\n\t\t// Merge resolvers with custom ones taking precedence\n\t\tconst mergedResolvers: Resolvers = additionalResolvers\n\t\t\t? { ...sstResolvers, ...additionalResolvers }\n\t\t\t: sstResolvers;\n\n\t\tthis.builder = new EnvironmentBuilder(\n\t\t\trecord as Record<string, InputValue>,\n\t\t\tmergedResolvers,\n\t\t\toptions,\n\t\t);\n\t}\n\n\t/**\n\t * Build environment variables from the input record.\n\t *\n\t * @returns A record of environment variables\n\t */\n\tbuild(): EnvRecord {\n\t\treturn this.builder.build();\n\t}\n}\n\nexport type {\n\tEnvironmentBuilderOptions,\n\tEnvRecord,\n\tEnvValue,\n} from './EnvironmentBuilder';\n// Re-export useful types\nexport { environmentCase } from './EnvironmentBuilder';\n","import { EnvironmentBuilder, type InputValue } from './EnvironmentBuilder';\nimport { type SstResource, sstResolvers } from './SstEnvironmentBuilder';\n\n/**\n * Variables AWS Lambda injects into the runtime. Always valid on AWS, but never\n * assumed — opt in via `platform: 'aws'` or by spreading {@link AWS_RUNTIME_ENV_VARS}\n * into `whitelist`.\n */\nexport const AWS_RUNTIME_ENV_VARS = [\n\t'AWS_REGION',\n\t'AWS_DEFAULT_REGION',\n\t'AWS_ENDPOINT_URL',\n\t'AWS_ENDPOINT',\n\t'AWS_ACCESS_KEY_ID',\n\t'AWS_SECRET_ACCESS_KEY',\n\t'AWS_SESSION_TOKEN',\n\t'AWS_LAMBDA_FUNCTION_NAME',\n\t'AWS_LAMBDA_FUNCTION_VERSION',\n] as const;\n\n/**\n * Variables GCP injects into Cloud Functions / Cloud Run.\n */\nexport const GCP_RUNTIME_ENV_VARS = [\n\t'GOOGLE_CLOUD_PROJECT',\n\t'GCP_PROJECT',\n\t'FUNCTION_TARGET',\n\t'FUNCTION_SIGNATURE_TYPE',\n\t'K_SERVICE',\n\t'K_REVISION',\n\t'K_CONFIGURATION',\n\t'PORT',\n] as const;\n\n/**\n * Variables Cloudflare exposes to Workers. Workers inject almost nothing into\n * the global env, so this is intentionally minimal.\n */\nexport const CLOUDFLARE_RUNTIME_ENV_VARS = [\n\t'CF_PAGES',\n\t'CF_PAGES_URL',\n] as const;\n\n/**\n * Registry of platform → always-valid runtime variables. Export, don't assume:\n * a caller states the platform it deploys to and the matching set is trusted.\n */\nexport const PLATFORM_ENV_VARS = {\n\taws: AWS_RUNTIME_ENV_VARS,\n\tgcp: GCP_RUNTIME_ENV_VARS,\n\tcloudflare: CLOUDFLARE_RUNTIME_ENV_VARS,\n} as const;\n\nexport type Platform = keyof typeof PLATFORM_ENV_VARS;\n\n/**\n * The always-valid runtime variables for a platform. The \"whitelist construct\":\n * resolve a platform to its set, to spread into `whitelist` or compare against.\n */\nexport function platformEnvVars(platform: Platform): readonly string[] {\n\treturn PLATFORM_ENV_VARS[platform];\n}\n\n/** How many link-provided vars to list in an error before truncating. */\nconst MAX_LISTED_VARS = 8;\n\n/** Minimum similarity for a variable to be offered as a \"did you mean\". */\nconst SUGGESTION_THRESHOLD = 0.3;\n\n/**\n * Input shape for the validator: the same record `SstEnvironmentBuilder`\n * accepts — keyed by resource name, valued by an SST resource (or a plain\n * string for pass-through env vars).\n */\nexport type LinkRecord = Record<string, SstResource | InputValue | string>;\n\nexport interface ValidationResult {\n\tvalid: boolean;\n\t/** Requested variables that are not available (excluding optional `?` vars). */\n\tinvalidVars: string[];\n\t/** Every variable the links + whitelist make available. */\n\tavailableVars: string[];\n\t/** Nearest available matches for each invalid variable (best first). */\n\tsuggestions: Record<string, string[]>;\n}\n\nexport interface EnvValidatorOptions {\n\t/**\n\t * Platform whose runtime-injected variables are always valid. Omit to assume\n\t * none — the validator never bakes in a platform's variables.\n\t */\n\tplatform?: Platform;\n\t/**\n\t * Extra always-valid variables in addition to the platform set — typically\n\t * the keys of a function's explicit `environment`.\n\t */\n\twhitelist?: readonly string[];\n\t/**\n\t * Label for the deployable unit (e.g. a function name), used in error\n\t * messages so a failure points at exactly one unit.\n\t */\n\tcontext?: string;\n}\n\n/**\n * Levenshtein edit distance between two strings.\n */\nfunction levenshtein(a: string, b: string): number {\n\tconst m = a.length;\n\tconst n = b.length;\n\tif (m === 0) return n;\n\tif (n === 0) return m;\n\n\tlet prev = Array.from({ length: n + 1 }, (_, i) => i);\n\n\tfor (let i = 1; i <= m; i++) {\n\t\tconst curr: number[] = [i];\n\t\tfor (let j = 1; j <= n; j++) {\n\t\t\tconst cost = a[i - 1] === b[j - 1] ? 0 : 1;\n\t\t\tconst del = (prev[j] ?? 0) + 1;\n\t\t\tconst ins = (curr[j - 1] ?? 0) + 1;\n\t\t\tconst sub = (prev[j - 1] ?? 0) + cost;\n\t\t\tcurr[j] = Math.min(del, ins, sub);\n\t\t}\n\t\tprev = curr;\n\t}\n\n\treturn prev[n] ?? 0;\n}\n\n/**\n * Similarity in `[0, 1]` combining edit distance with `_`-token overlap, so both\n * near-typos (a missing underscore) and renames (`DATABASE_URL` ~ `DB_URL`,\n * which share the `URL` token) are caught.\n */\nfunction similarity(a: string, b: string): number {\n\tconst editSim = 1 - levenshtein(a, b) / Math.max(a.length, b.length, 1);\n\n\tconst ta = new Set(a.split('_').filter(Boolean));\n\tconst tb = new Set(b.split('_').filter(Boolean));\n\tconst shared = [...ta].filter((t) => tb.has(t)).length;\n\tconst union = new Set([...ta, ...tb]).size || 1;\n\tconst tokenSim = shared / union;\n\n\t// Nudge token-overlap matches ahead of coincidental edit-distance ones, so a\n\t// rename like DATABASE_URL prefers DB_URL (shares `URL`) over DB_PASSWORD.\n\treturn Math.max(editSim, tokenSim * 1.15);\n}\n\n/**\n * Returns the nearest available variables to `missing`, best first, limited to\n * those above {@link SUGGESTION_THRESHOLD}.\n */\nfunction suggestionsFor(\n\tmissing: string,\n\tavailable: readonly string[],\n\tmax = 1,\n): string[] {\n\treturn available\n\t\t.map((candidate) => ({ candidate, score: similarity(missing, candidate) }))\n\t\t.filter((s) => s.score >= SUGGESTION_THRESHOLD)\n\t\t.sort((a, b) => b.score - a.score)\n\t\t.slice(0, max)\n\t\t.map((s) => s.candidate);\n}\n\n/**\n * Thrown when a deployable unit requires environment variables its links do not\n * provide. Carries the structured `missing`/`available`/`suggestions` so callers\n * can inspect the failure programmatically, not just read the message.\n */\nexport class EnvValidationError extends Error {\n\treadonly isEnvValidationError = true;\n\treadonly missing: string[];\n\treadonly available: string[];\n\treadonly suggestions: Record<string, string[]>;\n\treadonly context?: string;\n\n\tconstructor(args: {\n\t\tmissing: string[];\n\t\tavailable: string[];\n\t\tlinkVars: string[];\n\t\tsuggestions: Record<string, string[]>;\n\t\tcontext?: string;\n\t}) {\n\t\tsuper(EnvValidationError.format(args));\n\t\tthis.name = 'EnvValidationError';\n\t\tthis.missing = args.missing;\n\t\tthis.available = args.available;\n\t\tthis.suggestions = args.suggestions;\n\t\tthis.context = args.context;\n\t\t// V8-only; keeps the constructor out of the stack trace.\n\t\t(\n\t\t\tError as unknown as {\n\t\t\t\tcaptureStackTrace?(target: object, ctor?: unknown): void;\n\t\t\t}\n\t\t).captureStackTrace?.(this, EnvValidationError);\n\t}\n\n\tprivate static format(args: {\n\t\tmissing: string[];\n\t\tlinkVars: string[];\n\t\tsuggestions: Record<string, string[]>;\n\t\tcontext?: string;\n\t}): string {\n\t\tconst { missing, linkVars, suggestions, context } = args;\n\t\tconst who = context ? `'${context}'` : 'a deployable unit';\n\n\t\tconst width = Math.max(...missing.map((v) => v.length));\n\t\tconst lines = missing.map((v) => {\n\t\t\tconst hints = suggestions[v] ?? [];\n\t\t\tconst hint = hints.length ? `(did you mean ${hints.join(' or ')}?)` : '';\n\t\t\treturn ` - ${v.padEnd(width)} ${hint}`.trimEnd();\n\t\t});\n\n\t\tlet provided: string;\n\t\tif (linkVars.length === 0) {\n\t\t\tprovided = '(no links provide environment variables)';\n\t\t} else {\n\t\t\tconst shown = linkVars.slice(0, MAX_LISTED_VARS).join(', ');\n\t\t\tconst extra =\n\t\t\t\tlinkVars.length > MAX_LISTED_VARS\n\t\t\t\t\t? ` ...(+${linkVars.length - MAX_LISTED_VARS})`\n\t\t\t\t\t: '';\n\t\t\tprovided = `Provided by links: ${shown}${extra}`;\n\t\t}\n\n\t\treturn `${who} is missing required env vars:\\n${lines.join('\\n')}\\n\\n${provided}`;\n\t}\n}\n\n/**\n * Derives the set of environment-variable **keys** a group of linked resources\n * will produce at runtime — without resolving any value.\n *\n * This reuses the runtime resolvers (`sstResolvers`) via {@link EnvironmentBuilder},\n * so the keys computed here are exactly the keys a deployed function receives:\n * the validator and the runtime resolution share a single source of truth and\n * cannot drift. Because every resolver's output keys depend only on the record\n * key and the resource `type` (never the value), each resource is reduced to\n * `{ type }` before building, so no SST `Output` is ever read.\n *\n * @example\n * resolveEnvKeys({ db: { type: ResourceType.Postgres } });\n * // ['DB_NAME', 'DB_HOST', 'DB_PASSWORD', 'DB_PORT', 'DB_USERNAME', 'DB_URL']\n */\nexport function resolveEnvKeys(record: LinkRecord): string[] {\n\tconst typeOnly: Record<string, InputValue> = {};\n\tfor (const [key, value] of Object.entries(record)) {\n\t\ttypeOnly[key] = typeof value === 'string' ? '' : { type: value.type };\n\t}\n\treturn Object.keys(new EnvironmentBuilder(typeOnly, sstResolvers).build());\n}\n\n/**\n * Validates that the environment variables a deployable unit requires are\n * actually provided by its linked resources — at infra time, before deploy.\n *\n * Available variables are the union of the keys derived from `links`\n * ({@link resolveEnvKeys}), the chosen platform's runtime variables (only when\n * `options.platform` is set — nothing is assumed), and any `options.whitelist`\n * (e.g. the keys of a function's explicit `environment`). A requested variable\n * suffixed with `?` is treated as optional and never causes a failure.\n *\n * @example\n * const validator = new EnvValidator(\n * { db: { type: ResourceType.Postgres } },\n * { platform: 'aws', whitelist: ['APP_NAME'], context: 'orders-fn' },\n * );\n * validator.assert(['DB_HOST', 'AWS_REGION', 'APP_NAME', 'SENTRY_DSN?']); // ok\n * validator.assert(['DATABASE_URL']); // throws EnvValidationError (did you mean DB_URL?)\n */\nexport class EnvValidator {\n\t/** Every variable available — link-derived, platform, and extra whitelist. */\n\treadonly availableVars: string[];\n\t/** Just the variables the links provide (used for error context). */\n\treadonly linkVars: string[];\n\treadonly context?: string;\n\tprivate readonly availableSet: Set<string>;\n\t/** Per-link (record key → its env-var keys), for least-privilege filtering. */\n\tprivate readonly linkVarsByName: Map<string, string[]>;\n\n\tconstructor(links: LinkRecord, options: EnvValidatorOptions = {}) {\n\t\tconst { platform, whitelist = [], context } = options;\n\t\tthis.context = context;\n\t\tthis.linkVarsByName = new Map(\n\t\t\tObject.entries(links).map(([name, value]) => [\n\t\t\t\tname,\n\t\t\t\tresolveEnvKeys({ [name]: value }),\n\t\t\t]),\n\t\t);\n\t\tthis.linkVars = [...this.linkVarsByName.values()].flat();\n\t\tthis.availableVars = [\n\t\t\t...this.linkVars,\n\t\t\t...(platform ? PLATFORM_ENV_VARS[platform] : []),\n\t\t\t...whitelist,\n\t\t];\n\t\tthis.availableSet = new Set(this.availableVars);\n\t}\n\n\t/**\n\t * Returns the names of the links that provide at least one of the requested\n\t * variables — so a construct can attach only the links a unit actually needs\n\t * (least privilege) rather than the whole pool. Trailing `?` is ignored.\n\t */\n\tgetProvidersForEnvVars(requestedEnvVars: readonly string[]): string[] {\n\t\tconst requested = new Set(\n\t\t\trequestedEnvVars.map((v) => (v.endsWith('?') ? v.slice(0, -1) : v)),\n\t\t);\n\t\tconst providers: string[] = [];\n\t\tfor (const [name, vars] of this.linkVarsByName) {\n\t\t\tif (vars.some((v) => requested.has(v))) providers.push(name);\n\t\t}\n\t\treturn providers;\n\t}\n\n\t/**\n\t * Checks every requested variable against the available set. Variables\n\t * ending in `?` are optional and never reported as invalid. Invalid\n\t * variables come back with their nearest available matches.\n\t */\n\tvalidate(requestedEnvVars: readonly string[]): ValidationResult {\n\t\tconst invalidVars = requestedEnvVars.filter((envVar) => {\n\t\t\tif (envVar.endsWith('?')) return false;\n\t\t\treturn !this.availableSet.has(envVar);\n\t\t});\n\n\t\tconst suggestions: Record<string, string[]> = {};\n\t\tfor (const envVar of invalidVars) {\n\t\t\tconst matches = suggestionsFor(envVar, this.availableVars);\n\t\t\tif (matches.length) suggestions[envVar] = matches;\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: invalidVars.length === 0,\n\t\t\tinvalidVars,\n\t\t\tavailableVars: this.availableVars,\n\t\t\tsuggestions,\n\t\t};\n\t}\n\n\t/**\n\t * Asserts that every requested variable is available, throwing an\n\t * {@link EnvValidationError} otherwise. Intended to run in a construct's\n\t * constructor so a misconfigured `sst.config.ts` fails at synth time, before\n\t * any AWS call.\n\t */\n\tassert(requestedEnvVars: readonly string[]): void {\n\t\tconst { valid, invalidVars, suggestions } = this.validate(requestedEnvVars);\n\n\t\tif (!valid) {\n\t\t\tthrow new EnvValidationError({\n\t\t\t\tmissing: invalidVars,\n\t\t\t\tavailable: this.availableVars,\n\t\t\t\tlinkVars: this.linkVars,\n\t\t\t\tsuggestions,\n\t\t\t\tcontext: this.context,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Whether a single variable is available. Does not treat a trailing `?` as\n\t * optional — pass the bare name.\n\t */\n\thas(envVar: string): boolean {\n\t\treturn this.availableSet.has(envVar);\n\t}\n}\n","// Re-export everything from SstEnvironmentBuilder\n\n// Re-export types from EnvironmentBuilder\nexport type {\n\tEnvironmentBuilderOptions,\n\tEnvRecord,\n\tEnvValue,\n} from './EnvironmentBuilder';\n\n// Re-export environmentCase from EnvironmentBuilder\nexport { environmentCase } from './EnvironmentBuilder';\nexport {\n\ttype ApiGatewayV2,\n\ttype Bucket,\n\ttype Dynamo,\n\ttype Function,\n\ttype Postgres,\n\ttype Queue,\n\ttype ResourceProcessor,\n\tResourceType,\n\ttype Secret,\n\ttype SnsTopic,\n\tSstEnvironmentBuilder,\n\ttype SstResource,\n\tsstResolvers,\n\ttype Vpc,\n} from './SstEnvironmentBuilder';\n\nexport {\n\tAWS_RUNTIME_ENV_VARS,\n\tCLOUDFLARE_RUNTIME_ENV_VARS,\n\tEnvValidationError,\n\tEnvValidator,\n\ttype EnvValidatorOptions,\n\tGCP_RUNTIME_ENV_VARS,\n\ttype LinkRecord,\n\tPLATFORM_ENV_VARS,\n\ttype Platform,\n\tplatformEnvVars,\n\tresolveEnvKeys,\n\ttype ValidationResult,\n} from './SstEnvValidator';\n\n// Import for deprecated function\nimport {\n\tSstEnvironmentBuilder,\n\ttype SstResource,\n} from './SstEnvironmentBuilder';\n\n/**\n * @deprecated Use `new SstEnvironmentBuilder(record).build()` instead.\n *\n * Normalizes SST resources and plain strings into environment variables.\n * Processes resources based on their type and converts names to environment case.\n *\n * @param record - Object containing resources and/or string values\n * @returns Normalized environment variables object\n *\n * @example\n * // Old usage (deprecated):\n * normalizeResourceEnv({ database: postgresResource })\n *\n * // New usage:\n * new SstEnvironmentBuilder({ database: postgresResource }).build()\n */\nexport function normalizeResourceEnv(\n\trecord: Record<string, SstResource | string>,\n): Record<string, string | number | boolean | Record<string, unknown>> {\n\treturn new SstEnvironmentBuilder(record).build();\n}\n\n// Keep Resource type as deprecated alias for backwards compatibility\n/**\n * @deprecated Use `SstResource` instead.\n */\nexport type Resource = SstResource;\n"],"mappings":";;;;;;AAaA,IAAY,eAAL,yBAAA,cAAA;CAEN,aAAA,kBAAA;CACA,aAAA,cAAA;CACA,aAAA,cAAA;CACA,aAAA,mBAAA;CACA,aAAA,SAAA;CACA,aAAA,YAAA;CACA,aAAA,YAAA;CACA,aAAA,WAAA;CAGA,aAAA,eAAA;CACA,aAAA,iBAAA;CACA,aAAA,qBAAA;CACA,aAAA,iBAAA;CACA,aAAA,sBAAA;CACA,aAAA,cAAA;CACA,aAAA,eAAA;CACA,aAAA,cAAA;CAKA,aAAA,gBAAA;CACA,aAAA,gBAAA;CAGA,aAAA,WAAA;CACA,aAAA,WAAA;CAEA,aAAA,iBAAA;CAGA,aAAA,gBAAA;CAEA,aAAA,gBAAA;CAIA,aAAA,kBAAA;CAGA,aA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EAEA,OAAO;GACN,OAAO,YAAY,WAAW;GAC9B;GACA,eAAe,KAAK;GACpB;EACD;CACD;;;;;;;CAQA,OAAO,kBAA2C;EACjD,MAAM,EAAE,OAAO,aAAa,gBAAgB,KAAK,SAAS,gBAAgB;EAE1E,IAAI,CAAC,OACJ,MAAM,IAAI,mBAAmB;GAC5B,SAAS;GACT,WAAW,KAAK;GAChB,UAAU,KAAK;GACf;GACA,SAAS,KAAK;EACf,CAAC;CAEH;;;;;CAMA,IAAI,QAAyB;EAC5B,OAAO,KAAK,aAAa,IAAI,MAAM;CACpC;AACD;;;;;;;;;;;;;;;;;;;AC/SA,SAAgB,qBACf,QACsE;CACtE,OAAO,IAAI,sBAAsB,MAAM,CAAC,CAAC,MAAM;AAChD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/envkit",
3
- "version": "10.0.0-alpha.16",
3
+ "version": "10.0.0-alpha.160",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -57,7 +57,6 @@
57
57
  "access": "public"
58
58
  },
59
59
  "dependencies": {
60
- "lodash.set": "~4.3.2",
61
60
  "lodash.get": "~4.4.2",
62
61
  "lodash.snakecase": "~4.1.1"
63
62
  },
@@ -66,9 +65,11 @@
66
65
  },
67
66
  "devDependencies": {
68
67
  "@types/lodash.get": "~4.4.9",
69
- "@types/lodash.set": "~4.3.9",
70
68
  "@types/lodash.snakecase": "~4.1.9",
71
69
  "@types/node": "~24.9.1"
72
70
  },
73
- "peerDependenciesMeta": {}
71
+ "peerDependenciesMeta": {},
72
+ "scripts": {
73
+ "build": "tsdown --config ../../tsdown.config.ts --filter ."
74
+ }
74
75
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"EnvironmentParser-CmhDxs77.cjs","names":["z","get"],"sources":["../src/formatter.ts","../src/EnvironmentParser.ts"],"sourcesContent":["import type { z } from 'zod/v4';\n\n/**\n * Options for formatting parse errors.\n */\nexport interface FormatOptions {\n\t/** Whether to use colors in output. Defaults to auto-detect TTY. */\n\tcolors?: boolean;\n}\n\n/**\n * ANSI color codes for terminal output.\n */\nconst colors = {\n\treset: '\\x1b[0m',\n\tred: '\\x1b[31m',\n\tyellow: '\\x1b[33m',\n\tcyan: '\\x1b[36m',\n\tdim: '\\x1b[2m',\n\tbold: '\\x1b[1m',\n};\n\n/**\n * Formats a ZodError into a user-friendly string for development.\n *\n * @param error - The ZodError to format\n * @param options - Formatting options\n * @returns Formatted error message\n *\n * @example\n * ```typescript\n * try {\n * config.parse();\n * } catch (error) {\n * if (error instanceof ZodError) {\n * console.error(formatParseError(error));\n * }\n * }\n * ```\n *\n * Output:\n * ```\n * Environment Configuration Failed\n *\n * Missing Variables:\n * DATABASE_URL - Required\n * JWT_SECRET - Required\n *\n * Invalid Values:\n * NODE_ENV = \"invalid\"\n * Expected: \"development\" | \"staging\" | \"production\"\n * ```\n */\nexport function formatParseError(\n\terror: z.ZodError,\n\toptions: FormatOptions = {},\n): string {\n\tconst useColors =\n\t\toptions.colors ?? (process.stdout?.isTTY && process.env.NO_COLOR == null);\n\n\tconst c = useColors\n\t\t? colors\n\t\t: { reset: '', red: '', yellow: '', cyan: '', dim: '', bold: '' };\n\n\tconst missingVars: Array<{ name: string; message: string }> = [];\n\tconst invalidVars: Array<{ name: string; value: unknown; message: string }> =\n\t\t[];\n\n\tfor (const issue of error.issues) {\n\t\t// Extract environment variable name from path or message\n\t\tlet envName = '';\n\t\tif (issue.path.length > 0) {\n\t\t\t// Join the full path with '.' to show nested config keys and env var name\n\t\t\tenvName = issue.path.map(String).join('.');\n\t\t} else {\n\t\t\t// Try to extract from message like 'Environment variable \"NAME\": ...'\n\t\t\tconst match = issue.message.match(/Environment variable \"([^\"]+)\"/);\n\t\t\tif (match?.[1]) {\n\t\t\t\tenvName = match[1];\n\t\t\t}\n\t\t}\n\n\t\t// Determine if this is a missing or invalid value\n\t\t// Use type guard for received property\n\t\tconst received = 'received' in issue ? issue.received : undefined;\n\t\tconst isMissing =\n\t\t\tissue.code === 'invalid_type' &&\n\t\t\t(received === 'undefined' || received === 'null');\n\n\t\tif (isMissing) {\n\t\t\tmissingVars.push({\n\t\t\t\tname: envName || 'Unknown',\n\t\t\t\tmessage: cleanMessage(issue.message),\n\t\t\t});\n\t\t} else {\n\t\t\tinvalidVars.push({\n\t\t\t\tname: envName || 'Unknown',\n\t\t\t\tvalue: received,\n\t\t\t\tmessage: cleanMessage(issue.message),\n\t\t\t});\n\t\t}\n\t}\n\n\tconst lines: string[] = [];\n\n\tlines.push('');\n\tlines.push(`${c.red}${c.bold}Environment Configuration Failed${c.reset}`);\n\tlines.push('');\n\n\tif (missingVars.length > 0) {\n\t\tlines.push(`${c.yellow}Missing Variables:${c.reset}`);\n\t\tfor (const v of missingVars) {\n\t\t\tlines.push(` ${c.cyan}${v.name}${c.reset} ${c.dim}- Required${c.reset}`);\n\t\t}\n\t\tlines.push('');\n\t}\n\n\tif (invalidVars.length > 0) {\n\t\tlines.push(`${c.yellow}Invalid Values:${c.reset}`);\n\t\tfor (const v of invalidVars) {\n\t\t\tconst valueStr =\n\t\t\t\tv.value !== undefined ? ` = ${JSON.stringify(v.value)}` : '';\n\t\t\tlines.push(` ${c.cyan}${v.name}${c.reset}${valueStr}`);\n\t\t\tlines.push(` ${c.dim}${v.message}${c.reset}`);\n\t\t}\n\t\tlines.push('');\n\t}\n\n\treturn lines.join('\\n');\n}\n\n/**\n * Cleans up a Zod error message by removing redundant prefixes.\n */\nfunction cleanMessage(message: string): string {\n\t// Remove \"Environment variable \"NAME\": \" prefix if present\n\treturn message.replace(/^Environment variable \"[^\"]+\": /, '');\n}\n\n/**\n * Checks if the current environment is development.\n */\nexport function isDevelopment(): boolean {\n\tconst nodeEnv = process.env.NODE_ENV?.toLowerCase();\n\treturn nodeEnv == null || nodeEnv === 'development' || nodeEnv === 'dev';\n}\n","import get from 'lodash.get';\nimport set from 'lodash.set';\nimport { z } from 'zod/v4';\nimport { formatParseError, isDevelopment } from './formatter.js';\n\n/**\n * Parses and validates configuration objects against Zod schemas.\n * Handles nested configurations and aggregates validation errors.\n *\n * @template TResponse - The shape of the configuration object\n */\nexport class ConfigParser<TResponse extends EmptyObject> {\n\t/**\n\t * Creates a new ConfigParser instance.\n\t *\n\t * @param config - The configuration object to parse\n\t * @param envVars - Set of environment variable names that were accessed\n\t */\n\tconstructor(\n\t\tprivate readonly config: TResponse,\n\t\tprivate readonly envVars: Set<string> = new Set(),\n\t) {}\n\t/**\n\t * Parses the config object and validates it against the Zod schemas\n\t * @returns The parsed config object\n\t */\n\tparse(): InferConfig<TResponse> {\n\t\tconst errors: z.core.$ZodIssue[] = [];\n\n\t\tconst parseDeep = <T>(config: T, path: string[] = []) => {\n\t\t\tconst result: EmptyObject = {};\n\n\t\t\tif (config && typeof config !== 'object') {\n\t\t\t\treturn config;\n\t\t\t}\n\n\t\t\tfor (const key in config) {\n\t\t\t\tconst schema = config[key];\n\t\t\t\tconst currentPath = [...path, key];\n\n\t\t\t\tif (schema instanceof z.ZodType) {\n\t\t\t\t\tconst parsed = schema.safeParse(undefined);\n\t\t\t\t\tif (parsed.success) {\n\t\t\t\t\t\tset(result, key, parsed.data);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the schema is invalid, assign the error\n\t\t\t\t\t\terrors.push(\n\t\t\t\t\t\t\t...parsed.error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\tpath: [...currentPath, ...(issue.path as string[])],\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (schema) {\n\t\t\t\t\tset(result, key, parseDeep(schema as EmptyObject, currentPath));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result;\n\t\t};\n\n\t\tconst parsedConfig = parseDeep(\n\t\t\tthis.config,\n\t\t) as unknown as InferConfig<TResponse>;\n\n\t\tif (errors.length > 0) {\n\t\t\tconst zodError = new z.ZodError(errors);\n\t\t\t// In development, log a formatted error message before throwing\n\t\t\tif (isDevelopment()) {\n\t\t\t\tconsole.error(formatParseError(zodError));\n\t\t\t}\n\t\t\tthrow zodError;\n\t\t}\n\n\t\treturn parsedConfig;\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed during config creation.\n\t * This is useful for deployment and configuration management to know which env vars are required.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const config = envParser.create((get) => ({\n\t * dbUrl: get('DATABASE_URL').string(),\n\t * port: get('PORT').number()\n\t * }));\n\t *\n\t * config.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.envVars).sort();\n\t}\n}\n\n/**\n * Parses environment variables with type-safe validation using Zod schemas.\n * Provides a fluent API for defining environment variable schemas with automatic\n * error context enrichment.\n *\n * @template T - The type of the configuration object (typically process.env)\n *\n * @example\n * ```typescript\n * const config = new EnvironmentParser(process.env)\n * .create((get) => ({\n * port: get('PORT').string().transform(Number).default(3000),\n * database: {\n * url: get('DATABASE_URL').string().url()\n * }\n * }))\n * .parse();\n * ```\n */\nexport class EnvironmentParser<T extends EmptyObject> {\n\t/**\n\t * Set to track which environment variable names have been accessed\n\t */\n\tprivate readonly accessedVars: Set<string> = new Set();\n\n\t/**\n\t * Creates a new EnvironmentParser instance.\n\t *\n\t * @param config - The configuration object to parse (typically process.env)\n\t */\n\tconstructor(private readonly config: T) {}\n\n\t/**\n\t * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages\n\t * with environment variable context.\n\t *\n\t * @param schema - The Zod schema to wrap\n\t * @param name - The environment variable name for error context\n\t * @returns A wrapped Zod schema with enhanced error reporting\n\t */\n\tprivate wrapSchema = (schema: z.ZodType, name: string): z.ZodType => {\n\t\t// Create a proxy that intercepts all method calls on the schema\n\t\treturn new Proxy(schema, {\n\t\t\tget: (target, prop) => {\n\t\t\t\tif (prop === 'parse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn target.parse(value);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif (error instanceof z.ZodError) {\n\t\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\t\tconst modifiedIssues = error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t\tthrow new z.ZodError(modifiedIssues);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (prop === 'safeParse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\tconst result = target.safeParse(value);\n\n\t\t\t\t\t\tif (!result.success) {\n\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\tconst modifiedIssues = result.error.issues.map(\n\t\t\t\t\t\t\t\t(issue: z.core.$ZodIssue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tsuccess: false as const,\n\t\t\t\t\t\t\t\terror: new z.ZodError(modifiedIssues),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// For any method that returns a new schema (like transform, optional, etc.),\n\t\t\t\t// wrap the result as well\n\t\t\t\tconst originalProp = target[prop as keyof typeof target];\n\t\t\t\tif (typeof originalProp === 'function') {\n\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\tconst result = originalProp.apply(target, args);\n\t\t\t\t\t\t// If the result is a ZodType, wrap it too\n\t\t\t\t\t\tif (result && typeof result === 'object' && 'parse' in result) {\n\t\t\t\t\t\t\treturn this.wrapSchema(result, name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn originalProp;\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Creates a proxied version of the Zod object that wraps all schema creators\n\t * to provide enhanced error messages with environment variable context.\n\t *\n\t * @param name - The environment variable name\n\t * @returns A proxied Zod object with wrapped schema creators\n\t */\n\tprivate getZodGetter = (name: string) => {\n\t\t// Track that this environment variable was accessed\n\t\tthis.accessedVars.add(name);\n\n\t\t// Return an object that has all Zod schemas but with our wrapper\n\t\treturn new Proxy(\n\t\t\t{ ...z },\n\t\t\t{\n\t\t\t\tget: (target, prop) => {\n\t\t\t\t\t// deno-lint-ignore ban-ts-comment\n\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\tconst value = target[prop];\n\n\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\t// Return a wrapper around each Zod schema creator\n\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\tconst schema = value(...args);\n\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// Handle objects like z.coerce\n\t\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\t\treturn new Proxy(value, {\n\t\t\t\t\t\t\tget: (nestedTarget, nestedProp) => {\n\t\t\t\t\t\t\t\tconst nestedValue =\n\t\t\t\t\t\t\t\t\tnestedTarget[nestedProp as keyof typeof nestedTarget];\n\t\t\t\t\t\t\t\tif (typeof nestedValue === 'function') {\n\t\t\t\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\t\t\t\tconst schema = nestedValue(...args);\n\t\t\t\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn nestedValue;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn value;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t};\n\n\t/**\n\t * Creates a new ConfigParser object that can be used to parse the config object\n\t *\n\t * @param builder - A function that takes a getter function and returns a config object\n\t * @returns A ConfigParser object that can be used to parse the config object\n\t */\n\tcreate<TReturn extends EmptyObject>(\n\t\tbuilder: (get: EnvFetcher) => TReturn,\n\t): ConfigParser<TReturn> {\n\t\tconst config = builder(this.getZodGetter);\n\t\treturn new ConfigParser(config, this.accessedVars);\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed via the getter.\n\t * This is useful for build-time analysis to determine which env vars a service needs.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const sniffer = new EnvironmentParser({});\n\t * service.register(sniffer);\n\t * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.accessedVars).sort();\n\t}\n}\n\n/**\n * Infers the TypeScript type of a configuration object based on its Zod schemas.\n * Recursively processes nested objects and extracts types from Zod schemas.\n *\n * @template T - The configuration object type\n */\nexport type InferConfig<T extends EmptyObject> = {\n\t[K in keyof T]: T[K] extends z.ZodSchema\n\t\t? z.infer<T[K]>\n\t\t: T[K] extends Record<string, unknown>\n\t\t\t? InferConfig<T[K]>\n\t\t\t: T[K];\n};\n\n/**\n * Function type for fetching environment variables with Zod validation.\n * Returns a Zod object scoped to a specific environment variable.\n *\n * @template TPath - The environment variable path type\n * @param name - The environment variable name\n * @returns A Zod object for defining the schema\n */\nexport type EnvFetcher<TPath extends string = string> = (\n\tname: TPath,\n) => typeof z;\n\n/**\n * Function type for building environment configuration objects.\n * Takes an EnvFetcher and returns a configuration object with Zod schemas.\n *\n * @template TResponse - The response configuration object type\n * @param get - The environment variable fetcher function\n * @returns The configuration object with Zod schemas\n */\nexport type EnvironmentBuilder<TResponse extends EmptyObject> = (\n\tget: EnvFetcher,\n) => TResponse;\n\n/**\n * Type alias for a generic object with unknown values.\n * Used as a constraint for configuration objects.\n */\nexport type EmptyObject = Record<string | number | symbol, unknown>;\n"],"mappings":";;;;;;;;;;AAaA,MAAM,SAAS;CACd,OAAO;CACP,KAAK;CACL,QAAQ;CACR,MAAM;CACN,KAAK;CACL,MAAM;AACP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,iBACf,OACA,UAAyB,CAAC,GACjB;CAIT,MAAM,IAFL,QAAQ,WAAW,QAAQ,QAAQ,SAAS,QAAQ,IAAI,YAAY,QAGlE,SACA;EAAE,OAAO;EAAI,KAAK;EAAI,QAAQ;EAAI,MAAM;EAAI,KAAK;EAAI,MAAM;CAAG;CAEjE,MAAM,cAAwD,CAAC;CAC/D,MAAM,cACL,CAAC;CAEF,KAAK,MAAM,SAAS,MAAM,QAAQ;EAEjC,IAAI,UAAU;EACd,IAAI,MAAM,KAAK,SAAS,GAEvB,UAAU,MAAM,KAAK,IAAI,MAAM,CAAC,CAAC,KAAK,GAAG;OACnC;GAEN,MAAM,QAAQ,MAAM,QAAQ,MAAM,gCAAgC;GAClE,IAAI,QAAQ,IACX,UAAU,MAAM;EAElB;EAIA,MAAM,WAAW,cAAc,QAAQ,MAAM,WAAW,KAAA;EAKxD,IAHC,MAAM,SAAS,mBACd,aAAa,eAAe,aAAa,SAG1C,YAAY,KAAK;GAChB,MAAM,WAAW;GACjB,SAAS,aAAa,MAAM,OAAO;EACpC,CAAC;OAED,YAAY,KAAK;GAChB,MAAM,WAAW;GACjB,OAAO;GACP,SAAS,aAAa,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,OAAO,KAAK,WAAW,QAAQ,IAAI;GACpC;GAID,IAAI,SAAS,OAAO,UAAU,UAC7B,OAAO,IAAI,MAAM,OAAO,EACvB,MAAM,cAAc,eAAe;IAClC,MAAM,cACL,aAAa;IACd,IAAI,OAAO,gBAAgB,YAC1B,QAAQ,GAAG,SAAgB;KAC1B,MAAM,SAAS,YAAY,GAAG,IAAI;KAClC,OAAO,KAAK,WAAW,QAAQ,IAAI;IACpC;IAED,OAAO;GACR,EACD,CAAC;GAGF,OAAO;EACR,EACD,CACD;CACD;;;;;;;CAQA,OACC,SACwB;EAExB,OAAO,IAAI,aADI,QAAQ,KAAK,YACJ,GAAQ,KAAK,YAAY;CAClD;;;;;;;;;;;;;;CAeA,0BAAoC;EACnC,OAAO,MAAM,KAAK,KAAK,YAAY,CAAC,CAAC,KAAK;CAC3C;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"EnvironmentParser-X6Z-jryw.mjs","names":[],"sources":["../src/formatter.ts","../src/EnvironmentParser.ts"],"sourcesContent":["import type { z } from 'zod/v4';\n\n/**\n * Options for formatting parse errors.\n */\nexport interface FormatOptions {\n\t/** Whether to use colors in output. Defaults to auto-detect TTY. */\n\tcolors?: boolean;\n}\n\n/**\n * ANSI color codes for terminal output.\n */\nconst colors = {\n\treset: '\\x1b[0m',\n\tred: '\\x1b[31m',\n\tyellow: '\\x1b[33m',\n\tcyan: '\\x1b[36m',\n\tdim: '\\x1b[2m',\n\tbold: '\\x1b[1m',\n};\n\n/**\n * Formats a ZodError into a user-friendly string for development.\n *\n * @param error - The ZodError to format\n * @param options - Formatting options\n * @returns Formatted error message\n *\n * @example\n * ```typescript\n * try {\n * config.parse();\n * } catch (error) {\n * if (error instanceof ZodError) {\n * console.error(formatParseError(error));\n * }\n * }\n * ```\n *\n * Output:\n * ```\n * Environment Configuration Failed\n *\n * Missing Variables:\n * DATABASE_URL - Required\n * JWT_SECRET - Required\n *\n * Invalid Values:\n * NODE_ENV = \"invalid\"\n * Expected: \"development\" | \"staging\" | \"production\"\n * ```\n */\nexport function formatParseError(\n\terror: z.ZodError,\n\toptions: FormatOptions = {},\n): string {\n\tconst useColors =\n\t\toptions.colors ?? (process.stdout?.isTTY && process.env.NO_COLOR == null);\n\n\tconst c = useColors\n\t\t? colors\n\t\t: { reset: '', red: '', yellow: '', cyan: '', dim: '', bold: '' };\n\n\tconst missingVars: Array<{ name: string; message: string }> = [];\n\tconst invalidVars: Array<{ name: string; value: unknown; message: string }> =\n\t\t[];\n\n\tfor (const issue of error.issues) {\n\t\t// Extract environment variable name from path or message\n\t\tlet envName = '';\n\t\tif (issue.path.length > 0) {\n\t\t\t// Join the full path with '.' to show nested config keys and env var name\n\t\t\tenvName = issue.path.map(String).join('.');\n\t\t} else {\n\t\t\t// Try to extract from message like 'Environment variable \"NAME\": ...'\n\t\t\tconst match = issue.message.match(/Environment variable \"([^\"]+)\"/);\n\t\t\tif (match?.[1]) {\n\t\t\t\tenvName = match[1];\n\t\t\t}\n\t\t}\n\n\t\t// Determine if this is a missing or invalid value\n\t\t// Use type guard for received property\n\t\tconst received = 'received' in issue ? issue.received : undefined;\n\t\tconst isMissing =\n\t\t\tissue.code === 'invalid_type' &&\n\t\t\t(received === 'undefined' || received === 'null');\n\n\t\tif (isMissing) {\n\t\t\tmissingVars.push({\n\t\t\t\tname: envName || 'Unknown',\n\t\t\t\tmessage: cleanMessage(issue.message),\n\t\t\t});\n\t\t} else {\n\t\t\tinvalidVars.push({\n\t\t\t\tname: envName || 'Unknown',\n\t\t\t\tvalue: received,\n\t\t\t\tmessage: cleanMessage(issue.message),\n\t\t\t});\n\t\t}\n\t}\n\n\tconst lines: string[] = [];\n\n\tlines.push('');\n\tlines.push(`${c.red}${c.bold}Environment Configuration Failed${c.reset}`);\n\tlines.push('');\n\n\tif (missingVars.length > 0) {\n\t\tlines.push(`${c.yellow}Missing Variables:${c.reset}`);\n\t\tfor (const v of missingVars) {\n\t\t\tlines.push(` ${c.cyan}${v.name}${c.reset} ${c.dim}- Required${c.reset}`);\n\t\t}\n\t\tlines.push('');\n\t}\n\n\tif (invalidVars.length > 0) {\n\t\tlines.push(`${c.yellow}Invalid Values:${c.reset}`);\n\t\tfor (const v of invalidVars) {\n\t\t\tconst valueStr =\n\t\t\t\tv.value !== undefined ? ` = ${JSON.stringify(v.value)}` : '';\n\t\t\tlines.push(` ${c.cyan}${v.name}${c.reset}${valueStr}`);\n\t\t\tlines.push(` ${c.dim}${v.message}${c.reset}`);\n\t\t}\n\t\tlines.push('');\n\t}\n\n\treturn lines.join('\\n');\n}\n\n/**\n * Cleans up a Zod error message by removing redundant prefixes.\n */\nfunction cleanMessage(message: string): string {\n\t// Remove \"Environment variable \"NAME\": \" prefix if present\n\treturn message.replace(/^Environment variable \"[^\"]+\": /, '');\n}\n\n/**\n * Checks if the current environment is development.\n */\nexport function isDevelopment(): boolean {\n\tconst nodeEnv = process.env.NODE_ENV?.toLowerCase();\n\treturn nodeEnv == null || nodeEnv === 'development' || nodeEnv === 'dev';\n}\n","import get from 'lodash.get';\nimport set from 'lodash.set';\nimport { z } from 'zod/v4';\nimport { formatParseError, isDevelopment } from './formatter.js';\n\n/**\n * Parses and validates configuration objects against Zod schemas.\n * Handles nested configurations and aggregates validation errors.\n *\n * @template TResponse - The shape of the configuration object\n */\nexport class ConfigParser<TResponse extends EmptyObject> {\n\t/**\n\t * Creates a new ConfigParser instance.\n\t *\n\t * @param config - The configuration object to parse\n\t * @param envVars - Set of environment variable names that were accessed\n\t */\n\tconstructor(\n\t\tprivate readonly config: TResponse,\n\t\tprivate readonly envVars: Set<string> = new Set(),\n\t) {}\n\t/**\n\t * Parses the config object and validates it against the Zod schemas\n\t * @returns The parsed config object\n\t */\n\tparse(): InferConfig<TResponse> {\n\t\tconst errors: z.core.$ZodIssue[] = [];\n\n\t\tconst parseDeep = <T>(config: T, path: string[] = []) => {\n\t\t\tconst result: EmptyObject = {};\n\n\t\t\tif (config && typeof config !== 'object') {\n\t\t\t\treturn config;\n\t\t\t}\n\n\t\t\tfor (const key in config) {\n\t\t\t\tconst schema = config[key];\n\t\t\t\tconst currentPath = [...path, key];\n\n\t\t\t\tif (schema instanceof z.ZodType) {\n\t\t\t\t\tconst parsed = schema.safeParse(undefined);\n\t\t\t\t\tif (parsed.success) {\n\t\t\t\t\t\tset(result, key, parsed.data);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the schema is invalid, assign the error\n\t\t\t\t\t\terrors.push(\n\t\t\t\t\t\t\t...parsed.error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\tpath: [...currentPath, ...(issue.path as string[])],\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (schema) {\n\t\t\t\t\tset(result, key, parseDeep(schema as EmptyObject, currentPath));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result;\n\t\t};\n\n\t\tconst parsedConfig = parseDeep(\n\t\t\tthis.config,\n\t\t) as unknown as InferConfig<TResponse>;\n\n\t\tif (errors.length > 0) {\n\t\t\tconst zodError = new z.ZodError(errors);\n\t\t\t// In development, log a formatted error message before throwing\n\t\t\tif (isDevelopment()) {\n\t\t\t\tconsole.error(formatParseError(zodError));\n\t\t\t}\n\t\t\tthrow zodError;\n\t\t}\n\n\t\treturn parsedConfig;\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed during config creation.\n\t * This is useful for deployment and configuration management to know which env vars are required.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const config = envParser.create((get) => ({\n\t * dbUrl: get('DATABASE_URL').string(),\n\t * port: get('PORT').number()\n\t * }));\n\t *\n\t * config.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.envVars).sort();\n\t}\n}\n\n/**\n * Parses environment variables with type-safe validation using Zod schemas.\n * Provides a fluent API for defining environment variable schemas with automatic\n * error context enrichment.\n *\n * @template T - The type of the configuration object (typically process.env)\n *\n * @example\n * ```typescript\n * const config = new EnvironmentParser(process.env)\n * .create((get) => ({\n * port: get('PORT').string().transform(Number).default(3000),\n * database: {\n * url: get('DATABASE_URL').string().url()\n * }\n * }))\n * .parse();\n * ```\n */\nexport class EnvironmentParser<T extends EmptyObject> {\n\t/**\n\t * Set to track which environment variable names have been accessed\n\t */\n\tprivate readonly accessedVars: Set<string> = new Set();\n\n\t/**\n\t * Creates a new EnvironmentParser instance.\n\t *\n\t * @param config - The configuration object to parse (typically process.env)\n\t */\n\tconstructor(private readonly config: T) {}\n\n\t/**\n\t * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages\n\t * with environment variable context.\n\t *\n\t * @param schema - The Zod schema to wrap\n\t * @param name - The environment variable name for error context\n\t * @returns A wrapped Zod schema with enhanced error reporting\n\t */\n\tprivate wrapSchema = (schema: z.ZodType, name: string): z.ZodType => {\n\t\t// Create a proxy that intercepts all method calls on the schema\n\t\treturn new Proxy(schema, {\n\t\t\tget: (target, prop) => {\n\t\t\t\tif (prop === 'parse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn target.parse(value);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif (error instanceof z.ZodError) {\n\t\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\t\tconst modifiedIssues = error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t\tthrow new z.ZodError(modifiedIssues);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (prop === 'safeParse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\tconst result = target.safeParse(value);\n\n\t\t\t\t\t\tif (!result.success) {\n\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\tconst modifiedIssues = result.error.issues.map(\n\t\t\t\t\t\t\t\t(issue: z.core.$ZodIssue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tsuccess: false as const,\n\t\t\t\t\t\t\t\terror: new z.ZodError(modifiedIssues),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// For any method that returns a new schema (like transform, optional, etc.),\n\t\t\t\t// wrap the result as well\n\t\t\t\tconst originalProp = target[prop as keyof typeof target];\n\t\t\t\tif (typeof originalProp === 'function') {\n\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\tconst result = originalProp.apply(target, args);\n\t\t\t\t\t\t// If the result is a ZodType, wrap it too\n\t\t\t\t\t\tif (result && typeof result === 'object' && 'parse' in result) {\n\t\t\t\t\t\t\treturn this.wrapSchema(result, name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn originalProp;\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Creates a proxied version of the Zod object that wraps all schema creators\n\t * to provide enhanced error messages with environment variable context.\n\t *\n\t * @param name - The environment variable name\n\t * @returns A proxied Zod object with wrapped schema creators\n\t */\n\tprivate getZodGetter = (name: string) => {\n\t\t// Track that this environment variable was accessed\n\t\tthis.accessedVars.add(name);\n\n\t\t// Return an object that has all Zod schemas but with our wrapper\n\t\treturn new Proxy(\n\t\t\t{ ...z },\n\t\t\t{\n\t\t\t\tget: (target, prop) => {\n\t\t\t\t\t// deno-lint-ignore ban-ts-comment\n\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\tconst value = target[prop];\n\n\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\t// Return a wrapper around each Zod schema creator\n\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\tconst schema = value(...args);\n\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// Handle objects like z.coerce\n\t\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\t\treturn new Proxy(value, {\n\t\t\t\t\t\t\tget: (nestedTarget, nestedProp) => {\n\t\t\t\t\t\t\t\tconst nestedValue =\n\t\t\t\t\t\t\t\t\tnestedTarget[nestedProp as keyof typeof nestedTarget];\n\t\t\t\t\t\t\t\tif (typeof nestedValue === 'function') {\n\t\t\t\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\t\t\t\tconst schema = nestedValue(...args);\n\t\t\t\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn nestedValue;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn value;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t};\n\n\t/**\n\t * Creates a new ConfigParser object that can be used to parse the config object\n\t *\n\t * @param builder - A function that takes a getter function and returns a config object\n\t * @returns A ConfigParser object that can be used to parse the config object\n\t */\n\tcreate<TReturn extends EmptyObject>(\n\t\tbuilder: (get: EnvFetcher) => TReturn,\n\t): ConfigParser<TReturn> {\n\t\tconst config = builder(this.getZodGetter);\n\t\treturn new ConfigParser(config, this.accessedVars);\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed via the getter.\n\t * This is useful for build-time analysis to determine which env vars a service needs.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const sniffer = new EnvironmentParser({});\n\t * service.register(sniffer);\n\t * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.accessedVars).sort();\n\t}\n}\n\n/**\n * Infers the TypeScript type of a configuration object based on its Zod schemas.\n * Recursively processes nested objects and extracts types from Zod schemas.\n *\n * @template T - The configuration object type\n */\nexport type InferConfig<T extends EmptyObject> = {\n\t[K in keyof T]: T[K] extends z.ZodSchema\n\t\t? z.infer<T[K]>\n\t\t: T[K] extends Record<string, unknown>\n\t\t\t? InferConfig<T[K]>\n\t\t\t: T[K];\n};\n\n/**\n * Function type for fetching environment variables with Zod validation.\n * Returns a Zod object scoped to a specific environment variable.\n *\n * @template TPath - The environment variable path type\n * @param name - The environment variable name\n * @returns A Zod object for defining the schema\n */\nexport type EnvFetcher<TPath extends string = string> = (\n\tname: TPath,\n) => typeof z;\n\n/**\n * Function type for building environment configuration objects.\n * Takes an EnvFetcher and returns a configuration object with Zod schemas.\n *\n * @template TResponse - The response configuration object type\n * @param get - The environment variable fetcher function\n * @returns The configuration object with Zod schemas\n */\nexport type EnvironmentBuilder<TResponse extends EmptyObject> = (\n\tget: EnvFetcher,\n) => TResponse;\n\n/**\n * Type alias for a generic object with unknown values.\n * Used as a constraint for configuration objects.\n */\nexport type EmptyObject = Record<string | number | symbol, unknown>;\n"],"mappings":";;;;;;;AAaA,MAAM,SAAS;CACd,OAAO;CACP,KAAK;CACL,QAAQ;CACR,MAAM;CACN,KAAK;CACL,MAAM;AACP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,iBACf,OACA,UAAyB,CAAC,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