@geekmidas/envkit 10.0.0-alpha.10 → 10.0.0-alpha.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{EnvironmentBuilder-CoBQ9Xp2.d.mts → EnvironmentBuilder-DTZ8o3se.d.cts} +5 -5
- package/dist/EnvironmentBuilder-DTZ8o3se.d.cts.map +1 -0
- package/dist/{EnvironmentBuilder-DeIle4QN.d.cts → EnvironmentBuilder-DTZ8o3se.d.mts} +5 -5
- package/dist/EnvironmentBuilder-DTZ8o3se.d.mts.map +1 -0
- package/dist/{EnvironmentBuilder-C-2fViCT.mjs → EnvironmentBuilder-Rxq657gm.mjs} +4 -5
- package/dist/EnvironmentBuilder-Rxq657gm.mjs.map +1 -0
- package/dist/{EnvironmentBuilder-15SdFJdK.cjs → EnvironmentBuilder-wJH3EBbJ.cjs} +16 -16
- package/dist/EnvironmentBuilder-wJH3EBbJ.cjs.map +1 -0
- package/dist/{EnvironmentParser-DoooZm8n.d.cts → EnvironmentParser-BmJLlm5_.d.cts} +3 -15
- package/dist/EnvironmentParser-BmJLlm5_.d.cts.map +1 -0
- package/dist/{EnvironmentParser-BY1oCUsc.d.mts → EnvironmentParser-BmJLlm5_.d.mts} +3 -15
- package/dist/EnvironmentParser-BmJLlm5_.d.mts.map +1 -0
- package/dist/{EnvironmentParser-Bzg5yXG2.cjs → EnvironmentParser-CmhDxs77.cjs} +34 -34
- package/dist/EnvironmentParser-CmhDxs77.cjs.map +1 -0
- package/dist/{EnvironmentParser-taAKfzT7.mjs → EnvironmentParser-X6Z-jryw.mjs} +10 -12
- package/dist/EnvironmentParser-X6Z-jryw.mjs.map +1 -0
- package/dist/SnifferEnvironmentParser.cjs +5 -7
- package/dist/SnifferEnvironmentParser.cjs.map +1 -1
- package/dist/SnifferEnvironmentParser.d.cts +5 -9
- package/dist/SnifferEnvironmentParser.d.cts.map +1 -1
- package/dist/SnifferEnvironmentParser.d.mts +5 -9
- package/dist/SnifferEnvironmentParser.d.mts.map +1 -1
- package/dist/SnifferEnvironmentParser.mjs +3 -5
- package/dist/SnifferEnvironmentParser.mjs.map +1 -1
- package/dist/credentials.cjs +9 -11
- package/dist/credentials.cjs.map +1 -1
- package/dist/credentials.d.cts +3 -3
- package/dist/credentials.d.cts.map +1 -1
- package/dist/credentials.d.mts +3 -3
- package/dist/credentials.d.mts.map +1 -1
- package/dist/credentials.mjs +4 -8
- package/dist/credentials.mjs.map +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +5 -7
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +5 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -4
- package/dist/{chunk-CUT6urMc.cjs → rolldown-runtime-VH7oDXx4.cjs} +8 -10
- package/dist/sst.cjs +55 -51
- package/dist/sst.cjs.map +1 -1
- package/dist/sst.d.cts +21 -23
- package/dist/sst.d.cts.map +1 -1
- package/dist/sst.d.mts +21 -23
- package/dist/sst.d.mts.map +1 -1
- package/dist/sst.mjs +54 -51
- package/dist/sst.mjs.map +1 -1
- package/package.json +5 -2
- package/dist/EnvironmentBuilder-15SdFJdK.cjs.map +0 -1
- package/dist/EnvironmentBuilder-C-2fViCT.mjs.map +0 -1
- package/dist/EnvironmentBuilder-CoBQ9Xp2.d.mts.map +0 -1
- package/dist/EnvironmentBuilder-DeIle4QN.d.cts.map +0 -1
- package/dist/EnvironmentParser-BY1oCUsc.d.mts.map +0 -1
- package/dist/EnvironmentParser-Bzg5yXG2.cjs.map +0 -1
- package/dist/EnvironmentParser-DoooZm8n.d.cts.map +0 -1
- package/dist/EnvironmentParser-taAKfzT7.mjs.map +0 -1
package/dist/sst.cjs
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_EnvironmentBuilder = require("./EnvironmentBuilder-wJH3EBbJ.cjs");
|
|
3
3
|
//#region src/SstEnvironmentBuilder.ts
|
|
4
4
|
/**
|
|
5
5
|
* Enumeration of supported SST (Serverless Stack Toolkit) resource types.
|
|
6
6
|
* Used to identify and process different AWS and SST resources.
|
|
7
7
|
*/
|
|
8
|
-
let ResourceType = /* @__PURE__ */ function(ResourceType
|
|
9
|
-
ResourceType
|
|
10
|
-
ResourceType
|
|
11
|
-
ResourceType
|
|
12
|
-
ResourceType
|
|
13
|
-
ResourceType
|
|
14
|
-
ResourceType
|
|
15
|
-
ResourceType
|
|
16
|
-
ResourceType
|
|
17
|
-
ResourceType
|
|
18
|
-
ResourceType
|
|
19
|
-
ResourceType
|
|
20
|
-
ResourceType
|
|
21
|
-
ResourceType
|
|
22
|
-
ResourceType
|
|
23
|
-
ResourceType
|
|
24
|
-
ResourceType
|
|
25
|
-
ResourceType
|
|
26
|
-
ResourceType
|
|
27
|
-
ResourceType
|
|
28
|
-
ResourceType
|
|
29
|
-
|
|
8
|
+
let ResourceType = /* @__PURE__ */ function(ResourceType) {
|
|
9
|
+
ResourceType["ApiGatewayV2"] = "sst.aws.ApiGatewayV2";
|
|
10
|
+
ResourceType["Postgres"] = "sst.aws.Postgres";
|
|
11
|
+
ResourceType["Function"] = "sst.aws.Function";
|
|
12
|
+
ResourceType["ObjectStorage"] = "sst.aws.Bucket";
|
|
13
|
+
ResourceType["Vpc"] = "sst.aws.Vpc";
|
|
14
|
+
ResourceType["Secret"] = "sst.sst.Secret";
|
|
15
|
+
ResourceType["Dynamo"] = "sst.aws.Dynamo";
|
|
16
|
+
ResourceType["Queue"] = "sst.aws.Queue";
|
|
17
|
+
ResourceType["SSTSecret"] = "sst:sst:Secret";
|
|
18
|
+
ResourceType["SSTFunction"] = "sst:sst:Function";
|
|
19
|
+
ResourceType["SSTApiGatewayV2"] = "sst:aws:ApiGatewayV2";
|
|
20
|
+
ResourceType["SSTPostgres"] = "sst:aws:Postgres";
|
|
21
|
+
ResourceType["SSTObjectStorage"] = "sst:aws:Bucket";
|
|
22
|
+
ResourceType["SnsTopic"] = "sst:aws:SnsTopic";
|
|
23
|
+
ResourceType["SSTDynamo"] = "sst:aws:Dynamo";
|
|
24
|
+
ResourceType["SSTQueue"] = "sst:aws:Queue";
|
|
25
|
+
ResourceType["FileServer"] = "sst:aws:Router";
|
|
26
|
+
ResourceType["StaticSite"] = "sst:aws:StaticSite";
|
|
27
|
+
ResourceType["Email"] = "gkm:aws:Email";
|
|
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
|
+
return ResourceType;
|
|
30
33
|
}({});
|
|
31
34
|
const secretResolver = (name, value) => ({ [name]: value.value });
|
|
32
35
|
const postgresResolver = (key, value) => ({
|
|
@@ -51,27 +54,36 @@ const queueResolver = (name, value) => ({
|
|
|
51
54
|
[`${name}PublisherConnectionString`]: `sqs://?queueUrl=${encodeURIComponent(value.url)}`
|
|
52
55
|
});
|
|
53
56
|
const dynamoResolver = (name, value) => ({ [`${name}Name`]: value.name });
|
|
57
|
+
const externalApiResolver = (name, value) => ({
|
|
58
|
+
[`${name}Url`]: value.url,
|
|
59
|
+
[`${name}Credentials`]: value.credentials
|
|
60
|
+
});
|
|
61
|
+
const credentialResolver = (name, value) => ({ [`${name}Credentials`]: value.credentials });
|
|
62
|
+
const encryptionResolver = (name, value) => ({ [`${name}Url`]: value.url });
|
|
54
63
|
const noopResolver = () => ({});
|
|
55
64
|
/**
|
|
56
65
|
* Pre-configured resolvers for all SST resource types.
|
|
57
66
|
*/
|
|
58
67
|
const sstResolvers = {
|
|
59
|
-
[
|
|
60
|
-
[
|
|
61
|
-
[
|
|
62
|
-
[
|
|
63
|
-
[
|
|
64
|
-
[
|
|
65
|
-
[
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
[
|
|
69
|
-
[
|
|
70
|
-
[
|
|
71
|
-
[
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
68
|
+
["sst.aws.ApiGatewayV2"]: noopResolver,
|
|
69
|
+
["sst.aws.Function"]: noopResolver,
|
|
70
|
+
["sst.aws.Vpc"]: noopResolver,
|
|
71
|
+
["sst.sst.Secret"]: secretResolver,
|
|
72
|
+
["sst.aws.Postgres"]: postgresResolver,
|
|
73
|
+
["sst.aws.Bucket"]: bucketResolver,
|
|
74
|
+
["sst.aws.Dynamo"]: dynamoResolver,
|
|
75
|
+
["sst.aws.Queue"]: queueResolver,
|
|
76
|
+
["sst:sst:Secret"]: secretResolver,
|
|
77
|
+
["sst:aws:Bucket"]: bucketResolver,
|
|
78
|
+
["sst:sst:Function"]: noopResolver,
|
|
79
|
+
["sst:aws:Postgres"]: postgresResolver,
|
|
80
|
+
["sst:aws:ApiGatewayV2"]: noopResolver,
|
|
81
|
+
["sst:aws:SnsTopic"]: topicResolver,
|
|
82
|
+
["sst:aws:Dynamo"]: dynamoResolver,
|
|
83
|
+
["sst:aws:Queue"]: queueResolver,
|
|
84
|
+
["gkm:aws:ExternalApi"]: externalApiResolver,
|
|
85
|
+
["gkm:aws:Credential"]: credentialResolver,
|
|
86
|
+
["gkm:aws:Encryption"]: encryptionResolver
|
|
75
87
|
};
|
|
76
88
|
/**
|
|
77
89
|
* SST-specific environment builder with built-in resolvers for all known
|
|
@@ -127,7 +139,6 @@ var SstEnvironmentBuilder = class {
|
|
|
127
139
|
return this.builder.build();
|
|
128
140
|
}
|
|
129
141
|
};
|
|
130
|
-
|
|
131
142
|
//#endregion
|
|
132
143
|
//#region src/SstEnvValidator.ts
|
|
133
144
|
/**
|
|
@@ -215,9 +226,7 @@ function similarity(a, b) {
|
|
|
215
226
|
const editSim = 1 - levenshtein(a, b) / Math.max(a.length, b.length, 1);
|
|
216
227
|
const ta = new Set(a.split("_").filter(Boolean));
|
|
217
228
|
const tb = new Set(b.split("_").filter(Boolean));
|
|
218
|
-
const
|
|
219
|
-
const union = new Set([...ta, ...tb]).size || 1;
|
|
220
|
-
const tokenSim = shared / union;
|
|
229
|
+
const tokenSim = [...ta].filter((t) => tb.has(t)).length / ((/* @__PURE__ */ new Set([...ta, ...tb])).size || 1);
|
|
221
230
|
return Math.max(editSim, tokenSim * 1.15);
|
|
222
231
|
}
|
|
223
232
|
/**
|
|
@@ -261,11 +270,7 @@ var EnvValidationError = class EnvValidationError extends Error {
|
|
|
261
270
|
});
|
|
262
271
|
let provided;
|
|
263
272
|
if (linkVars.length === 0) provided = "(no links provide environment variables)";
|
|
264
|
-
else {
|
|
265
|
-
const shown = linkVars.slice(0, MAX_LISTED_VARS).join(", ");
|
|
266
|
-
const extra = linkVars.length > MAX_LISTED_VARS ? ` ...(+${linkVars.length - MAX_LISTED_VARS})` : "";
|
|
267
|
-
provided = `Provided by links: ${shown}${extra}`;
|
|
268
|
-
}
|
|
273
|
+
else provided = `Provided by links: ${linkVars.slice(0, MAX_LISTED_VARS).join(", ")}${linkVars.length > MAX_LISTED_VARS ? ` ...(+${linkVars.length - MAX_LISTED_VARS})` : ""}`;
|
|
269
274
|
return `${who} is missing required env vars:\n${lines.join("\n")}\n\n${provided}`;
|
|
270
275
|
}
|
|
271
276
|
};
|
|
@@ -385,7 +390,6 @@ var EnvValidator = class {
|
|
|
385
390
|
return this.availableSet.has(envVar);
|
|
386
391
|
}
|
|
387
392
|
};
|
|
388
|
-
|
|
389
393
|
//#endregion
|
|
390
394
|
//#region src/sst.ts
|
|
391
395
|
/**
|
|
@@ -407,7 +411,6 @@ var EnvValidator = class {
|
|
|
407
411
|
function normalizeResourceEnv(record) {
|
|
408
412
|
return new SstEnvironmentBuilder(record).build();
|
|
409
413
|
}
|
|
410
|
-
|
|
411
414
|
//#endregion
|
|
412
415
|
exports.AWS_RUNTIME_ENV_VARS = AWS_RUNTIME_ENV_VARS;
|
|
413
416
|
exports.CLOUDFLARE_RUNTIME_ENV_VARS = CLOUDFLARE_RUNTIME_ENV_VARS;
|
|
@@ -422,4 +425,5 @@ exports.normalizeResourceEnv = normalizeResourceEnv;
|
|
|
422
425
|
exports.platformEnvVars = platformEnvVars;
|
|
423
426
|
exports.resolveEnvKeys = resolveEnvKeys;
|
|
424
427
|
exports.sstResolvers = sstResolvers;
|
|
428
|
+
|
|
425
429
|
//# sourceMappingURL=sst.cjs.map
|
package/dist/sst.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sst.cjs","names":["name: string","value: SecretValue","key: string","value: PostgresValue","value: BucketValue","value: SnsTopicValue","value: QueueValue","value: DynamoValue","sstResolvers: Resolvers","record: TRecord","additionalResolvers?: CustomResolvers<TRecord>","options?: EnvironmentBuilderOptions","mergedResolvers: Resolvers","EnvironmentBuilder","platform: Platform","a: string","b: string","curr: number[]","missing: string","available: readonly string[]","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}","args: {\n\t\tmissing: string[];\n\t\tlinkVars: string[];\n\t\tsuggestions: Record<string, string[]>;\n\t\tcontext?: string;\n\t}","provided: string","record: LinkRecord","typeOnly: Record<string, InputValue>","EnvironmentBuilder","links: LinkRecord","options: EnvValidatorOptions","requestedEnvVars: readonly string[]","providers: string[]","suggestions: Record<string, string[]>","envVar: string","record: Record<string, SstResource | string>"],"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,wDAAL;AAEN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAKA;AACA;AAGA;AACA;;AACA;AA0HD,MAAM,iBAAiB,CAACA,MAAcC,WAAwB,GAC5D,OAAO,MAAM,MACd;AAED,MAAM,mBAAmB,CAACC,KAAaC,WAA0B;GAC9D,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,YAAY,MAAM;GACxB,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,YAAY,MAAM;GACxB,EAAE,IAAI,QAAQ,eAAe,mBAAmB,MAAM,SAAS,CAAC,GAAG,mBAAmB,MAAM,SAAS,CAAC,GAAG,MAAM,KAAK,GAAG,MAAM,KAAK,GAAG,MAAM,SAAS;AACtJ;AAED,MAAM,iBAAiB,CAACH,MAAcI,WAAwB;GAC3D,EAAE,KAAK,QAAQ,MAAM;GAKrB,EAAE,KAAK,OAAO,MAAM,OAAO;AAC7B;AAED,MAAM,gBAAgB,CAACJ,MAAcK,WAA0B;GAC5D,EAAE,KAAK,OAAO,MAAM;GAGpB,EAAE,KAAK,8BAA8B,kBAAkB,mBAAmB,MAAM,IAAI,CAAC;AACvF;AAED,MAAM,gBAAgB,CAACL,MAAcM,WAAuB;GACzD,EAAE,KAAK,OAAO,MAAM;GACpB,EAAE,KAAK,OAAO,MAAM;GAGpB,EAAE,KAAK,8BAA8B,kBAAkB,mBAAmB,MAAM,IAAI,CAAC;AACvF;AAED,MAAM,iBAAiB,CAACN,MAAcO,WAAwB,IAC3D,EAAE,KAAK,QAAQ,MAAM,KACvB;AAED,MAAM,eAAe,OAAO,CAAE;;;;AAK9B,MAAaC,eAA0B;EAErC,aAAa,eAAe;EAC5B,aAAa,WAAW;EACxB,aAAa,MAAM;EACnB,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O,YAAY,WAAW;GAC9B;GACA,eAAe,KAAK;GACpB;EACA;CACD;;;;;;;CAQD,OAAOF,kBAA2C;EACjD,MAAM,EAAE,OAAO,aAAa,aAAa,GAAG,KAAK,SAAS,iBAAiB;AAE3E,OAAK,MACJ,OAAM,IAAI,mBAAmB;GAC5B,SAAS;GACT,WAAW,KAAK;GAChB,UAAU,KAAK;GACf;GACA,SAAS,KAAK;EACd;CAEF;;;;;CAMD,IAAIG,QAAyB;AAC5B,SAAO,KAAK,aAAa,IAAI,OAAO;CACpC;AACD;;;;;;;;;;;;;;;;;;;;AC/SD,SAAgB,qBACfC,QACsE;AACtE,QAAO,IAAI,sBAAsB,QAAQ,OAAO;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}\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 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 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};\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;;AACD,EAAA,CAAA,CAAA;AA6HA,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,GAAG,IAAI,QAAQ,MAAM;EACrB,GAAG,IAAI,YAAY,MAAM;EACzB,GAAG,IAAI,OAAO,gBAAgB,mBAAmB,MAAM,QAAQ,EAAE,GAAG,mBAAmB,MAAM,QAAQ,EAAE,GAAG,MAAM,KAAK,GAAG,MAAM,KAAK,GAAG,MAAM;AAC9I;AAEA,MAAM,kBAAkB,MAAc,WAAwB;EAC5D,GAAG,KAAK,QAAQ,MAAM;EAKtB,GAAG,K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ACnE;EACA,MAAM,YAAsB,CAAC;EAC7B,KAAK,MAAM,CAAC,MAAM,SAAS,KAAK,gBAC/B,IAAI,KAAK,MAAM,MAAM,UAAU,IAAI,CAAC,CAAC,GAAG,UAAU,KAAK,IAAI;EAE5D,OAAO;CACR;;;;;;CAOA,SAAS,kBAAuD;EAC/D,MAAM,cAAc,iBAAiB,QAAQ,WAAW;GACvD,IAAI,OAAO,SAAS,GAAG,GAAG,OAAO;GACjC,OAAO,CAAC,KAAK,aAAa,IAAI,MAAM;EACrC,CAAC;EAED,MAAM,cAAwC,CAAC;EAC/C,KAAK,MAAM,UAAU,aAAa;GACjC,MAAM,UAAU,eAAe,QAAQ,KAAK,aAAa;GACzD,IAAI,QAAQ,QAAQ,YAAY,UAAU;EAC3C;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/dist/sst.d.cts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { a as EnvironmentResolver, i as EnvironmentBuilderOptions, n as EnvValue, o as InputValue, s as Resolvers, t as EnvRecord, u as environmentCase } from "./EnvironmentBuilder-DTZ8o3se.cjs";
|
|
3
2
|
//#region src/SstEnvironmentBuilder.d.ts
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Enumeration of supported SST (Serverless Stack Toolkit) resource types.
|
|
7
5
|
* Used to identify and process different AWS and SST resources.
|
|
8
6
|
*/
|
|
9
|
-
declare enum ResourceType {
|
|
7
|
+
export declare enum ResourceType {
|
|
10
8
|
ApiGatewayV2 = "sst.aws.ApiGatewayV2",
|
|
11
9
|
Postgres = "sst.aws.Postgres",
|
|
12
10
|
Function = "sst.aws.Function",
|
|
@@ -27,6 +25,9 @@ declare enum ResourceType {
|
|
|
27
25
|
StaticSite = "sst:aws:StaticSite",
|
|
28
26
|
Email = "gkm:aws:Email",
|
|
29
27
|
Cache = "gkm:aws:Cache",
|
|
28
|
+
ExternalApi = "gkm:aws:ExternalApi",
|
|
29
|
+
Credential = "gkm:aws:Credential",
|
|
30
|
+
Encryption = "gkm:aws:Encryption"
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
33
|
* AWS API Gateway V2 resource type.
|
|
@@ -121,7 +122,7 @@ type ResourceProcessor<K> = (name: string, value: K) => EnvRecord;
|
|
|
121
122
|
/**
|
|
122
123
|
* Pre-configured resolvers for all SST resource types.
|
|
123
124
|
*/
|
|
124
|
-
declare const sstResolvers: Resolvers;
|
|
125
|
+
export declare const sstResolvers: Resolvers;
|
|
125
126
|
/**
|
|
126
127
|
* All known SST resource type strings.
|
|
127
128
|
*/
|
|
@@ -141,7 +142,7 @@ type OmitType<T> = T extends {
|
|
|
141
142
|
/**
|
|
142
143
|
* Extracts all unique `type` values from a record (excluding plain strings).
|
|
143
144
|
*/
|
|
144
|
-
type AllTypeValues<TRecord extends Record<string, InputValue>> = { [K in keyof TRecord]: ExtractType<TRecord[K]
|
|
145
|
+
type AllTypeValues<TRecord extends Record<string, InputValue>> = { [K in keyof TRecord]: ExtractType<TRecord[K]>; }[keyof TRecord];
|
|
145
146
|
/**
|
|
146
147
|
* Extracts only the custom (non-SST) type values from a record.
|
|
147
148
|
*/
|
|
@@ -151,11 +152,11 @@ type CustomTypeValues<TRecord extends Record<string, InputValue>> = Exclude<AllT
|
|
|
151
152
|
*/
|
|
152
153
|
type ValueForType<TRecord extends Record<string, InputValue>, TType extends string> = { [K in keyof TRecord]: TRecord[K] extends {
|
|
153
154
|
type: TType;
|
|
154
|
-
} ? OmitType<TRecord[K]> : never }[keyof TRecord];
|
|
155
|
+
} ? OmitType<TRecord[K]> : never; }[keyof TRecord];
|
|
155
156
|
/**
|
|
156
157
|
* Generates typed resolvers for custom (non-SST) types in the input record.
|
|
157
158
|
*/
|
|
158
|
-
type CustomResolvers<TRecord extends Record<string, InputValue>> = CustomTypeValues<TRecord> extends never ? Resolvers | undefined : { [TType in CustomTypeValues<TRecord>]: EnvironmentResolver<ValueForType<TRecord, TType
|
|
159
|
+
type CustomResolvers<TRecord extends Record<string, InputValue>> = CustomTypeValues<TRecord> extends never ? Resolvers | undefined : { [TType in CustomTypeValues<TRecord>]: EnvironmentResolver<ValueForType<TRecord, TType>>; };
|
|
159
160
|
/**
|
|
160
161
|
* SST-specific environment builder with built-in resolvers for all known
|
|
161
162
|
* SST resource types.
|
|
@@ -185,7 +186,7 @@ type CustomResolvers<TRecord extends Record<string, InputValue>> = CustomTypeVal
|
|
|
185
186
|
* ).build();
|
|
186
187
|
* ```
|
|
187
188
|
*/
|
|
188
|
-
declare class SstEnvironmentBuilder<TRecord extends Record<string, SstResource | InputValue | string>> {
|
|
189
|
+
export declare class SstEnvironmentBuilder<TRecord extends Record<string, SstResource | InputValue | string>> {
|
|
189
190
|
private readonly builder;
|
|
190
191
|
/**
|
|
191
192
|
* Create a new SST environment builder.
|
|
@@ -209,21 +210,21 @@ declare class SstEnvironmentBuilder<TRecord extends Record<string, SstResource |
|
|
|
209
210
|
* assumed — opt in via `platform: 'aws'` or by spreading {@link AWS_RUNTIME_ENV_VARS}
|
|
210
211
|
* into `whitelist`.
|
|
211
212
|
*/
|
|
212
|
-
declare const AWS_RUNTIME_ENV_VARS: readonly [
|
|
213
|
+
export declare const AWS_RUNTIME_ENV_VARS: readonly ['AWS_REGION', 'AWS_DEFAULT_REGION', 'AWS_ENDPOINT_URL', 'AWS_ENDPOINT', 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_SESSION_TOKEN', 'AWS_LAMBDA_FUNCTION_NAME', 'AWS_LAMBDA_FUNCTION_VERSION'];
|
|
213
214
|
/**
|
|
214
215
|
* Variables GCP injects into Cloud Functions / Cloud Run.
|
|
215
216
|
*/
|
|
216
|
-
declare const GCP_RUNTIME_ENV_VARS: readonly [
|
|
217
|
+
export declare const GCP_RUNTIME_ENV_VARS: readonly ['GOOGLE_CLOUD_PROJECT', 'GCP_PROJECT', 'FUNCTION_TARGET', 'FUNCTION_SIGNATURE_TYPE', 'K_SERVICE', 'K_REVISION', 'K_CONFIGURATION', 'PORT'];
|
|
217
218
|
/**
|
|
218
219
|
* Variables Cloudflare exposes to Workers. Workers inject almost nothing into
|
|
219
220
|
* the global env, so this is intentionally minimal.
|
|
220
221
|
*/
|
|
221
|
-
declare const CLOUDFLARE_RUNTIME_ENV_VARS: readonly [
|
|
222
|
+
export declare const CLOUDFLARE_RUNTIME_ENV_VARS: readonly ['CF_PAGES', 'CF_PAGES_URL'];
|
|
222
223
|
/**
|
|
223
224
|
* Registry of platform → always-valid runtime variables. Export, don't assume:
|
|
224
225
|
* a caller states the platform it deploys to and the matching set is trusted.
|
|
225
226
|
*/
|
|
226
|
-
declare const PLATFORM_ENV_VARS: {
|
|
227
|
+
export declare const PLATFORM_ENV_VARS: {
|
|
227
228
|
readonly aws: readonly ["AWS_REGION", "AWS_DEFAULT_REGION", "AWS_ENDPOINT_URL", "AWS_ENDPOINT", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN", "AWS_LAMBDA_FUNCTION_NAME", "AWS_LAMBDA_FUNCTION_VERSION"];
|
|
228
229
|
readonly gcp: readonly ["GOOGLE_CLOUD_PROJECT", "GCP_PROJECT", "FUNCTION_TARGET", "FUNCTION_SIGNATURE_TYPE", "K_SERVICE", "K_REVISION", "K_CONFIGURATION", "PORT"];
|
|
229
230
|
readonly cloudflare: readonly ["CF_PAGES", "CF_PAGES_URL"];
|
|
@@ -233,7 +234,7 @@ type Platform = keyof typeof PLATFORM_ENV_VARS;
|
|
|
233
234
|
* The always-valid runtime variables for a platform. The "whitelist construct":
|
|
234
235
|
* resolve a platform to its set, to spread into `whitelist` or compare against.
|
|
235
236
|
*/
|
|
236
|
-
declare function platformEnvVars(platform: Platform): readonly string[];
|
|
237
|
+
export declare function platformEnvVars(platform: Platform): readonly string[];
|
|
237
238
|
/**
|
|
238
239
|
* Input shape for the validator: the same record `SstEnvironmentBuilder`
|
|
239
240
|
* accepts — keyed by resource name, valued by an SST resource (or a plain
|
|
@@ -271,7 +272,7 @@ interface EnvValidatorOptions {
|
|
|
271
272
|
* provide. Carries the structured `missing`/`available`/`suggestions` so callers
|
|
272
273
|
* can inspect the failure programmatically, not just read the message.
|
|
273
274
|
*/
|
|
274
|
-
declare class EnvValidationError extends Error {
|
|
275
|
+
export declare class EnvValidationError extends Error {
|
|
275
276
|
readonly isEnvValidationError = true;
|
|
276
277
|
readonly missing: string[];
|
|
277
278
|
readonly available: string[];
|
|
@@ -301,7 +302,7 @@ declare class EnvValidationError extends Error {
|
|
|
301
302
|
* resolveEnvKeys({ db: { type: ResourceType.Postgres } });
|
|
302
303
|
* // ['DB_NAME', 'DB_HOST', 'DB_PASSWORD', 'DB_PORT', 'DB_USERNAME', 'DB_URL']
|
|
303
304
|
*/
|
|
304
|
-
declare function resolveEnvKeys(record: LinkRecord): string[];
|
|
305
|
+
export declare function resolveEnvKeys(record: LinkRecord): string[];
|
|
305
306
|
/**
|
|
306
307
|
* Validates that the environment variables a deployable unit requires are
|
|
307
308
|
* actually provided by its linked resources — at infra time, before deploy.
|
|
@@ -320,7 +321,7 @@ declare function resolveEnvKeys(record: LinkRecord): string[];
|
|
|
320
321
|
* validator.assert(['DB_HOST', 'AWS_REGION', 'APP_NAME', 'SENTRY_DSN?']); // ok
|
|
321
322
|
* validator.assert(['DATABASE_URL']); // throws EnvValidationError (did you mean DB_URL?)
|
|
322
323
|
*/
|
|
323
|
-
declare class EnvValidator {
|
|
324
|
+
export declare class EnvValidator {
|
|
324
325
|
/** Every variable available — link-derived, platform, and extra whitelist. */
|
|
325
326
|
readonly availableVars: string[];
|
|
326
327
|
/** Just the variables the links provide (used for error context). */
|
|
@@ -355,7 +356,6 @@ declare class EnvValidator {
|
|
|
355
356
|
*/
|
|
356
357
|
has(envVar: string): boolean;
|
|
357
358
|
}
|
|
358
|
-
//# sourceMappingURL=SstEnvValidator.d.ts.map
|
|
359
359
|
//#endregion
|
|
360
360
|
//#region src/sst.d.ts
|
|
361
361
|
/**
|
|
@@ -374,13 +374,11 @@ declare class EnvValidator {
|
|
|
374
374
|
* // New usage:
|
|
375
375
|
* new SstEnvironmentBuilder({ database: postgresResource }).build()
|
|
376
376
|
*/
|
|
377
|
-
declare function normalizeResourceEnv(record: Record<string, SstResource | string>): Record<string, string | number | boolean | Record<string, unknown>>;
|
|
377
|
+
export declare function normalizeResourceEnv(record: Record<string, SstResource | string>): Record<string, string | number | boolean | Record<string, unknown>>;
|
|
378
378
|
/**
|
|
379
379
|
* @deprecated Use `SstResource` instead.
|
|
380
380
|
*/
|
|
381
|
-
type Resource = SstResource;
|
|
382
|
-
//# sourceMappingURL=sst.d.ts.map
|
|
383
|
-
|
|
381
|
+
export type Resource = SstResource;
|
|
384
382
|
//#endregion
|
|
385
|
-
export {
|
|
383
|
+
export { type ApiGatewayV2, type Bucket, type Dynamo, type EnvRecord, type EnvValidatorOptions, type EnvValue, type EnvironmentBuilderOptions, type Function, type LinkRecord, type Platform, type Postgres, type Queue, type ResourceProcessor, type Secret, type SnsTopic, type SstResource, type ValidationResult, type Vpc, environmentCase };
|
|
386
384
|
//# sourceMappingURL=sst.d.cts.map
|
package/dist/sst.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sst.d.cts","names":[],"sources":["../src/SstEnvironmentBuilder.ts","../src/SstEnvValidator.ts","../src/sst.ts"],"
|
|
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;;;;;;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;;;;;;;;;KAqBS,kBAAkB,MAAM,cAAc,OAAO,MAAM;;;;qBA+DlD,cAAc;;;;KA4BtB,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,i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