sst 2.3.7 → 2.4.1
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/cli/commands/bind.js +61 -48
- package/constructs/EdgeFunction.js +13 -1
- package/constructs/NextjsSite.d.ts +12 -5
- package/constructs/NextjsSite.js +149 -102
- package/constructs/SsrSite.d.ts +7 -8
- package/constructs/SsrSite.js +13 -14
- package/node/actor/index.d.ts +29 -0
- package/node/actor/index.js +17 -0
- package/node/util/index.js +12 -1
- package/package.json +1 -1
- package/sst.mjs +61 -50
- package/support/bootstrap-metadata-function/index.mjs +238 -238
- package/support/custom-resources/index.mjs +238 -238
- package/util/error.d.ts +3 -0
- package/util/error.js +6 -0
package/constructs/SsrSite.js
CHANGED
|
@@ -466,9 +466,9 @@ export class SsrSite extends Construct {
|
|
|
466
466
|
// these values can NOT be overwritten by cfDistributionProps
|
|
467
467
|
domainNames: this.buildDistributionDomainNames(),
|
|
468
468
|
certificate: this.certificate,
|
|
469
|
-
defaultBehavior: this.
|
|
469
|
+
defaultBehavior: this.buildDefaultBehaviorForRegional(),
|
|
470
470
|
additionalBehaviors: {
|
|
471
|
-
...this.
|
|
471
|
+
...this.buildStaticFileBehaviors(s3Origin),
|
|
472
472
|
...(cfDistributionProps.additionalBehaviors || {}),
|
|
473
473
|
},
|
|
474
474
|
});
|
|
@@ -485,9 +485,9 @@ export class SsrSite extends Construct {
|
|
|
485
485
|
// these values can NOT be overwritten by cfDistributionProps
|
|
486
486
|
domainNames: this.buildDistributionDomainNames(),
|
|
487
487
|
certificate: this.certificate,
|
|
488
|
-
defaultBehavior: this.
|
|
488
|
+
defaultBehavior: this.buildDefaultBehaviorForEdge(s3Origin),
|
|
489
489
|
additionalBehaviors: {
|
|
490
|
-
...this.
|
|
490
|
+
...this.buildStaticFileBehaviors(s3Origin),
|
|
491
491
|
...(cfDistributionProps.additionalBehaviors || {}),
|
|
492
492
|
},
|
|
493
493
|
});
|
|
@@ -511,7 +511,7 @@ export class SsrSite extends Construct {
|
|
|
511
511
|
}
|
|
512
512
|
return domainNames;
|
|
513
513
|
}
|
|
514
|
-
|
|
514
|
+
buildDefaultBehaviorForRegional() {
|
|
515
515
|
const { cdk } = this.props;
|
|
516
516
|
const cfDistributionProps = cdk?.distribution || {};
|
|
517
517
|
const fnUrl = this.serverLambdaForRegional.addFunctionUrl({
|
|
@@ -524,12 +524,12 @@ export class SsrSite extends Construct {
|
|
|
524
524
|
allowedMethods: AllowedMethods.ALLOW_ALL,
|
|
525
525
|
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
526
526
|
compress: true,
|
|
527
|
-
cachePolicy: cdk?.serverCachePolicy ?? this.
|
|
528
|
-
originRequestPolicy: this.
|
|
527
|
+
cachePolicy: cdk?.serverCachePolicy ?? this.buildServerCachePolicy(),
|
|
528
|
+
originRequestPolicy: this.buildServerOriginRequestPolicy(),
|
|
529
529
|
...(cfDistributionProps.defaultBehavior || {}),
|
|
530
530
|
};
|
|
531
531
|
}
|
|
532
|
-
|
|
532
|
+
buildDefaultBehaviorForEdge(origin) {
|
|
533
533
|
const { cdk } = this.props;
|
|
534
534
|
const cfDistributionProps = cdk?.distribution || {};
|
|
535
535
|
return {
|
|
@@ -539,10 +539,9 @@ export class SsrSite extends Construct {
|
|
|
539
539
|
allowedMethods: AllowedMethods.ALLOW_ALL,
|
|
540
540
|
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
541
541
|
compress: true,
|
|
542
|
-
cachePolicy: cdk?.serverCachePolicy ?? this.
|
|
543
|
-
originRequestPolicy: this.
|
|
542
|
+
cachePolicy: cdk?.serverCachePolicy ?? this.buildServerCachePolicy(),
|
|
543
|
+
originRequestPolicy: this.buildServerOriginRequestPolicy(),
|
|
544
544
|
...(cfDistributionProps.defaultBehavior || {}),
|
|
545
|
-
// concatenate edgeLambdas
|
|
546
545
|
edgeLambdas: [
|
|
547
546
|
{
|
|
548
547
|
includeBody: true,
|
|
@@ -568,7 +567,7 @@ function handler(event) {
|
|
|
568
567
|
},
|
|
569
568
|
];
|
|
570
569
|
}
|
|
571
|
-
|
|
570
|
+
buildStaticFileBehaviors(origin) {
|
|
572
571
|
const { cdk } = this.props;
|
|
573
572
|
// Create additional behaviours for statics
|
|
574
573
|
const staticBehaviourOptions = {
|
|
@@ -592,7 +591,7 @@ function handler(event) {
|
|
|
592
591
|
}
|
|
593
592
|
return staticsBehaviours;
|
|
594
593
|
}
|
|
595
|
-
|
|
594
|
+
buildServerCachePolicy() {
|
|
596
595
|
return new CachePolicy(this, "ServerCache", {
|
|
597
596
|
queryStringBehavior: CacheQueryStringBehavior.all(),
|
|
598
597
|
headerBehavior: CacheHeaderBehavior.none(),
|
|
@@ -605,7 +604,7 @@ function handler(event) {
|
|
|
605
604
|
comment: "SST server response cache policy",
|
|
606
605
|
});
|
|
607
606
|
}
|
|
608
|
-
|
|
607
|
+
buildServerOriginRequestPolicy() {
|
|
609
608
|
// CloudFront's Managed-AllViewerExceptHostHeader policy
|
|
610
609
|
return OriginRequestPolicy.fromOriginRequestPolicyId(this, "ServerOriginRequestPolicy", "b689b0a8-53d0-40ab-baf2-68738e2966ac");
|
|
611
610
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SSTError } from "../../util/error.js";
|
|
2
|
+
interface Definition {
|
|
3
|
+
type: string;
|
|
4
|
+
properties: Record<string, any>;
|
|
5
|
+
}
|
|
6
|
+
export declare class WrongActorError extends SSTError {
|
|
7
|
+
}
|
|
8
|
+
export declare function createActors<T extends Definition>(): {
|
|
9
|
+
useActor: () => T | {
|
|
10
|
+
type: "public";
|
|
11
|
+
properties: {};
|
|
12
|
+
};
|
|
13
|
+
provideActor: (value: T | {
|
|
14
|
+
type: "public";
|
|
15
|
+
properties: {};
|
|
16
|
+
}) => void;
|
|
17
|
+
assertActor<T_1 extends (T | {
|
|
18
|
+
type: "public";
|
|
19
|
+
properties: {};
|
|
20
|
+
})["type"]>(type: T_1): (Extract<T, {
|
|
21
|
+
type: T_1;
|
|
22
|
+
}> | Extract<{
|
|
23
|
+
type: "public";
|
|
24
|
+
properties: {};
|
|
25
|
+
}, {
|
|
26
|
+
type: T_1;
|
|
27
|
+
}>)["properties"];
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context } from "../../context/context.js";
|
|
2
|
+
import { SSTError } from "../../util/error.js";
|
|
3
|
+
export class WrongActorError extends SSTError {
|
|
4
|
+
}
|
|
5
|
+
export function createActors() {
|
|
6
|
+
const ctx = Context.create();
|
|
7
|
+
return {
|
|
8
|
+
useActor: ctx.use,
|
|
9
|
+
provideActor: ctx.provide,
|
|
10
|
+
assertActor(type) {
|
|
11
|
+
const actor = ctx.use();
|
|
12
|
+
if (actor.type === type)
|
|
13
|
+
return actor.properties;
|
|
14
|
+
throw new WrongActorError(`Expected actor type "${type} but got "${actor.type}"`);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
package/node/util/index.js
CHANGED
|
@@ -9,7 +9,10 @@ const ssm = new SSMClient({ region: process.env.SST_REGION });
|
|
|
9
9
|
// }
|
|
10
10
|
// }
|
|
11
11
|
let allVariables = {};
|
|
12
|
-
await
|
|
12
|
+
// NOTE: in some setups, top level await must be assigned to a variable,
|
|
13
|
+
// otherwise it would throw a top level await error.
|
|
14
|
+
// https://discord.com/channels/983865673656705025/1089184080534446110
|
|
15
|
+
const _placeholder = await parseEnvironment();
|
|
13
16
|
export function createProxy(constructName) {
|
|
14
17
|
return new Proxy({}, {
|
|
15
18
|
get(target, prop) {
|
|
@@ -87,6 +90,14 @@ async function fetchValuesFromSSM(variablesFromSsm) {
|
|
|
87
90
|
const variable = parseSsmFallbackPath(item.Name);
|
|
88
91
|
storeVariable(variable, item.Value);
|
|
89
92
|
});
|
|
93
|
+
// Throw error if any values are missing
|
|
94
|
+
const missingSecrets = fallbackResults.invalidParams
|
|
95
|
+
.map((name) => parseSsmFallbackPath(name))
|
|
96
|
+
.filter((variable) => variable.constructName === "Secret")
|
|
97
|
+
.map((variable) => variable.constructId);
|
|
98
|
+
if (missingSecrets.length > 0) {
|
|
99
|
+
throw new Error(`The following secrets were not found: ${missingSecrets.join(", ")}`);
|
|
100
|
+
}
|
|
90
101
|
}
|
|
91
102
|
async function loadSecrets(paths) {
|
|
92
103
|
// Split paths into chunks of 10
|
package/package.json
CHANGED
package/sst.mjs
CHANGED
|
@@ -7077,12 +7077,11 @@ Are you sure you want to run this stage in dev mode? [y/N] `,
|
|
|
7077
7077
|
// src/cli/commands/bind.ts
|
|
7078
7078
|
init_error();
|
|
7079
7079
|
import path18 from "path";
|
|
7080
|
-
var
|
|
7080
|
+
var SSR_SITE_CONFIG = {
|
|
7081
7081
|
NextjsSite: "next.config",
|
|
7082
7082
|
AstroSite: "astro.config",
|
|
7083
7083
|
RemixSite: "remix.config",
|
|
7084
7084
|
SolidStartSite: "vite.config",
|
|
7085
|
-
StaticSite: "vite.config",
|
|
7086
7085
|
SlsNextjsSite: "next.config"
|
|
7087
7086
|
};
|
|
7088
7087
|
var bind = (program2) => program2.command(
|
|
@@ -7098,6 +7097,7 @@ var bind = (program2) => program2.command(
|
|
|
7098
7097
|
const { useBus: useBus2 } = await Promise.resolve().then(() => (init_bus(), bus_exports));
|
|
7099
7098
|
const { useIOT: useIOT2 } = await Promise.resolve().then(() => (init_iot(), iot_exports));
|
|
7100
7099
|
const { Colors: Colors2 } = await Promise.resolve().then(() => (init_colors(), colors_exports));
|
|
7100
|
+
const { Logger: Logger2 } = await Promise.resolve().then(() => (init_logger(), logger_exports));
|
|
7101
7101
|
if (args._[0] === "env") {
|
|
7102
7102
|
Colors2.line(
|
|
7103
7103
|
Colors2.warning(
|
|
@@ -7111,17 +7111,18 @@ var bind = (program2) => program2.command(
|
|
|
7111
7111
|
const bus = useBus2();
|
|
7112
7112
|
const project = useProject2();
|
|
7113
7113
|
const command = args.command?.join(" ");
|
|
7114
|
-
const
|
|
7114
|
+
const isSsrSite = await isRunningInSsrSite();
|
|
7115
7115
|
let p;
|
|
7116
7116
|
let timer;
|
|
7117
|
-
let
|
|
7117
|
+
let siteConfigCache;
|
|
7118
7118
|
if (!command) {
|
|
7119
7119
|
throw new VisibleError(
|
|
7120
|
-
`Command is required, e.g. sst bind ${
|
|
7120
|
+
`Command is required, e.g. sst bind ${isSsrSite ? "next dev" : "env"}`
|
|
7121
7121
|
);
|
|
7122
7122
|
}
|
|
7123
7123
|
const initialMetadata = await getSiteMetadata();
|
|
7124
|
-
if (!initialMetadata) {
|
|
7124
|
+
if (!initialMetadata && !isSsrSite) {
|
|
7125
|
+
Logger2.debug("Running in script mode.");
|
|
7125
7126
|
return await bindScript();
|
|
7126
7127
|
}
|
|
7127
7128
|
await bindSite("init");
|
|
@@ -7135,9 +7136,9 @@ var bind = (program2) => program2.command(
|
|
|
7135
7136
|
);
|
|
7136
7137
|
bus.subscribe("config.secret.updated", (payload) => {
|
|
7137
7138
|
const secretName = payload.properties.name;
|
|
7138
|
-
if (
|
|
7139
|
+
if (siteConfigCache?.secrets === void 0)
|
|
7139
7140
|
return;
|
|
7140
|
-
if (!
|
|
7141
|
+
if (!siteConfigCache.secrets.includes(secretName))
|
|
7141
7142
|
return;
|
|
7142
7143
|
Colors2.line(
|
|
7143
7144
|
`
|
|
@@ -7146,21 +7147,28 @@ var bind = (program2) => program2.command(
|
|
|
7146
7147
|
);
|
|
7147
7148
|
bindSite("secrets_updated");
|
|
7148
7149
|
});
|
|
7149
|
-
async function
|
|
7150
|
+
async function isRunningInSsrSite() {
|
|
7150
7151
|
const { existsAsync: existsAsync3 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
|
|
7152
|
+
const { readFile } = await import("fs/promises");
|
|
7151
7153
|
const results = await Promise.all(
|
|
7152
|
-
Object.values(
|
|
7153
|
-
(config) => [".js", ".cjs", ".mjs", ".ts"].map(
|
|
7154
|
-
|
|
7155
|
-
|
|
7154
|
+
Object.values(SSR_SITE_CONFIG).map(
|
|
7155
|
+
(config) => [".js", ".cjs", ".mjs", ".ts"].map(async (ext) => {
|
|
7156
|
+
const exists = await existsAsync3(`${config}${ext}`);
|
|
7157
|
+
if (exists && config === "vite.config") {
|
|
7158
|
+
const content = await readFile(`${config}${ext}`);
|
|
7159
|
+
return content.includes("solid-start");
|
|
7160
|
+
}
|
|
7161
|
+
return exists;
|
|
7162
|
+
})
|
|
7156
7163
|
).flat()
|
|
7157
7164
|
);
|
|
7158
7165
|
return results.some(Boolean);
|
|
7159
7166
|
}
|
|
7160
7167
|
async function bindSite(reason) {
|
|
7161
|
-
const
|
|
7168
|
+
const siteMetadata = reason === "init" ? initialMetadata : await getSiteMetadataUntilAvailable();
|
|
7169
|
+
const siteConfig = await parseSiteConfig(siteMetadata);
|
|
7162
7170
|
if (reason === "metadata_updated") {
|
|
7163
|
-
if (areEnvsSame(
|
|
7171
|
+
if (areEnvsSame(siteConfig.envs, siteConfigCache?.envs || {}))
|
|
7164
7172
|
return;
|
|
7165
7173
|
Colors2.line(
|
|
7166
7174
|
`
|
|
@@ -7168,9 +7176,9 @@ var bind = (program2) => program2.command(
|
|
|
7168
7176
|
`SST resources have been updated. Restarting \`${command}\`...`
|
|
7169
7177
|
);
|
|
7170
7178
|
}
|
|
7171
|
-
|
|
7172
|
-
if (
|
|
7173
|
-
const credentials = await assumeSsrRole(
|
|
7179
|
+
siteConfigCache = siteConfig;
|
|
7180
|
+
if (siteConfig.role) {
|
|
7181
|
+
const credentials = await assumeSsrRole(siteConfig.role);
|
|
7174
7182
|
if (credentials) {
|
|
7175
7183
|
const expireAt = credentials.Expiration.getTime() - 6e4;
|
|
7176
7184
|
clearTimeout(timer);
|
|
@@ -7183,7 +7191,7 @@ var bind = (program2) => program2.command(
|
|
|
7183
7191
|
bindSite("iam_expired");
|
|
7184
7192
|
}, expireAt - Date.now());
|
|
7185
7193
|
runCommand({
|
|
7186
|
-
...
|
|
7194
|
+
...siteConfig.envs,
|
|
7187
7195
|
AWS_ACCESS_KEY_ID: credentials.AccessKeyId,
|
|
7188
7196
|
AWS_SECRET_ACCESS_KEY: credentials.SecretAccessKey,
|
|
7189
7197
|
AWS_SESSION_TOKEN: credentials.SessionToken
|
|
@@ -7192,7 +7200,7 @@ var bind = (program2) => program2.command(
|
|
|
7192
7200
|
}
|
|
7193
7201
|
}
|
|
7194
7202
|
runCommand({
|
|
7195
|
-
...
|
|
7203
|
+
...siteConfig.envs,
|
|
7196
7204
|
...await localIamCredentials()
|
|
7197
7205
|
});
|
|
7198
7206
|
}
|
|
@@ -7203,22 +7211,30 @@ var bind = (program2) => program2.command(
|
|
|
7203
7211
|
...await localIamCredentials()
|
|
7204
7212
|
});
|
|
7205
7213
|
}
|
|
7206
|
-
async function
|
|
7207
|
-
const { metadata: metadata3 } = await Promise.resolve().then(() => (init_metadata(), metadata_exports));
|
|
7208
|
-
const { createSpinner: createSpinner2 } = await Promise.resolve().then(() => (init_spinner(), spinner_exports));
|
|
7214
|
+
async function parseSiteConfig(metadata3) {
|
|
7209
7215
|
const { LambdaClient: LambdaClient2, GetFunctionCommand } = await import("@aws-sdk/client-lambda");
|
|
7210
7216
|
const { useAWSClient: useAWSClient2 } = await Promise.resolve().then(() => (init_credentials(), credentials_exports));
|
|
7217
|
+
const isBindSupported = metadata3.type !== "StaticSite" && metadata3.type !== "SlsNextjsSite";
|
|
7218
|
+
if (!isBindSupported) {
|
|
7219
|
+
return { envs: metadata3.data.environment };
|
|
7220
|
+
}
|
|
7221
|
+
const lambda = useAWSClient2(LambdaClient2);
|
|
7222
|
+
const { Configuration: functionConfig } = await lambda.send(
|
|
7223
|
+
new GetFunctionCommand({
|
|
7224
|
+
FunctionName: metadata3.data.server
|
|
7225
|
+
})
|
|
7226
|
+
);
|
|
7227
|
+
return {
|
|
7228
|
+
role: functionConfig?.Role,
|
|
7229
|
+
envs: functionConfig?.Environment?.Variables || {},
|
|
7230
|
+
secrets: metadata3.data.secrets
|
|
7231
|
+
};
|
|
7232
|
+
}
|
|
7233
|
+
async function getSiteMetadataUntilAvailable() {
|
|
7234
|
+
const { createSpinner: createSpinner2 } = await Promise.resolve().then(() => (init_spinner(), spinner_exports));
|
|
7211
7235
|
const spinner = createSpinner2({});
|
|
7212
7236
|
while (true) {
|
|
7213
|
-
const
|
|
7214
|
-
const data2 = Object.values(metadataData).flat().filter(
|
|
7215
|
-
(c) => Boolean(c)
|
|
7216
|
-
).filter((c) => Boolean(SITE_CONFIG[c.type])).find(
|
|
7217
|
-
(c) => path18.resolve(project.paths.root, c.data.path) === process.cwd()
|
|
7218
|
-
);
|
|
7219
|
-
if (!data2 && !isFrontend) {
|
|
7220
|
-
return;
|
|
7221
|
-
}
|
|
7237
|
+
const data2 = await getSiteMetadata();
|
|
7222
7238
|
if (!data2) {
|
|
7223
7239
|
spinner.start(
|
|
7224
7240
|
"Make sure `sst dev` is running..."
|
|
@@ -7235,25 +7251,22 @@ var bind = (program2) => program2.command(
|
|
|
7235
7251
|
continue;
|
|
7236
7252
|
}
|
|
7237
7253
|
spinner.isSpinning && spinner.stop().clear();
|
|
7238
|
-
|
|
7239
|
-
return { envs: data2.data.environment };
|
|
7240
|
-
}
|
|
7241
|
-
const lambda = useAWSClient2(LambdaClient2);
|
|
7242
|
-
const { Configuration: functionConfig } = await lambda.send(
|
|
7243
|
-
new GetFunctionCommand({
|
|
7244
|
-
FunctionName: data2.data.server
|
|
7245
|
-
})
|
|
7246
|
-
);
|
|
7247
|
-
return {
|
|
7248
|
-
role: functionConfig?.Role,
|
|
7249
|
-
envs: functionConfig?.Environment?.Variables || {},
|
|
7250
|
-
secrets: data2.data.secrets
|
|
7251
|
-
};
|
|
7254
|
+
return data2;
|
|
7252
7255
|
}
|
|
7253
7256
|
}
|
|
7257
|
+
async function getSiteMetadata() {
|
|
7258
|
+
const { metadata: metadata3 } = await Promise.resolve().then(() => (init_metadata(), metadata_exports));
|
|
7259
|
+
const metadataData = await metadata3();
|
|
7260
|
+
return Object.values(metadataData).flat().filter(
|
|
7261
|
+
(c) => Boolean(c)
|
|
7262
|
+
).filter(
|
|
7263
|
+
(c) => c.type === "StaticSite" || Boolean(SSR_SITE_CONFIG[c.type])
|
|
7264
|
+
).find(
|
|
7265
|
+
(c) => path18.resolve(project.paths.root, c.data.path) === process.cwd()
|
|
7266
|
+
);
|
|
7267
|
+
}
|
|
7254
7268
|
async function assumeSsrRole(roleArn) {
|
|
7255
7269
|
const { STSClient: STSClient2, AssumeRoleCommand } = await import("@aws-sdk/client-sts");
|
|
7256
|
-
const { Logger: Logger2 } = await Promise.resolve().then(() => (init_logger(), logger_exports));
|
|
7257
7270
|
const { useAWSClient: useAWSClient2 } = await Promise.resolve().then(() => (init_credentials(), credentials_exports));
|
|
7258
7271
|
const sts = useAWSClient2(STSClient2);
|
|
7259
7272
|
const assumeRole = async (duration) => {
|
|
@@ -7280,9 +7293,7 @@ var bind = (program2) => program2.command(
|
|
|
7280
7293
|
}
|
|
7281
7294
|
}
|
|
7282
7295
|
Colors2.line(
|
|
7283
|
-
|
|
7284
|
-
`Failed to assume SSR role ${roleArn}. Falling back to using local IAM credentials.`
|
|
7285
|
-
)
|
|
7296
|
+
"Using local IAM credentials since `sst dev` is not running."
|
|
7286
7297
|
);
|
|
7287
7298
|
Logger2.debug(`Failed to assume ${roleArn}.`, err);
|
|
7288
7299
|
}
|