sst 2.13.1 → 2.13.2

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.
@@ -13,6 +13,7 @@ import { SsrFunction } from "./SsrFunction.js";
13
13
  import { EdgeFunction } from "./EdgeFunction.js";
14
14
  import { SsrSite } from "./SsrSite.js";
15
15
  import { toCdkSize } from "./util/size.js";
16
+ import { toCdkDuration } from "./util/duration.js";
16
17
  /**
17
18
  * The `NextjsSite` construct is a higher level CDK construct that makes it easy to create a Next.js app.
18
19
  * @example
@@ -198,13 +199,17 @@ export class NextjsSite extends SsrSite {
198
199
  * - Cache-Control: public, max-age=0, must-revalidate
199
200
  * - x-vercel-cache: MISS
200
201
  */
201
- const { cdk } = this.props;
202
+ const { timeout, cdk } = this.props;
202
203
  const cfDistributionProps = cdk?.distribution || {};
203
204
  const s3Origin = new S3Origin(this.cdk.bucket);
204
205
  const serverFnUrl = this.serverLambdaForRegional.addFunctionUrl({
205
206
  authType: FunctionUrlAuthType.NONE,
206
207
  });
207
- const serverOrigin = new HttpOrigin(Fn.parseDomainName(serverFnUrl.url));
208
+ const serverOrigin = new HttpOrigin(Fn.parseDomainName(serverFnUrl.url), {
209
+ readTimeout: typeof timeout === "string"
210
+ ? toCdkDuration(timeout)
211
+ : CdkDuration.seconds(timeout),
212
+ });
208
213
  const cachePolicy = cdk?.serverCachePolicy ??
209
214
  this.buildServerCachePolicy([
210
215
  "accept",
@@ -244,7 +249,7 @@ export class NextjsSite extends SsrSite {
244
249
  "next-router-state-tree",
245
250
  ]);
246
251
  const originRequestPolicy = this.buildServerOriginRequestPolicy();
247
- const functionVersion = this.serverLambdaForEdge.currentVersion;
252
+ const functionVersion = this.serverEdgeFunction.currentVersion;
248
253
  const serverBehavior = this.buildServerBehaviorForEdge(functionVersion, s3Origin, cachePolicy, originRequestPolicy);
249
254
  return new Distribution(this, "Distribution", {
250
255
  // these values can be overwritten by cfDistributionProps
@@ -214,7 +214,8 @@ export declare class SsrSite extends Construct implements SSTConstruct {
214
214
  protected props: SsrSiteNormalizedProps;
215
215
  private doNotDeploy;
216
216
  protected buildConfig: SsrBuildConfig;
217
- protected serverLambdaForEdge?: EdgeFunction;
217
+ protected serverEdgeFunction?: EdgeFunction;
218
+ private serverLambdaForEdge?;
218
219
  protected serverLambdaForRegional?: CdkFunction;
219
220
  private serverLambdaForDev?;
220
221
  private bucket;
@@ -300,6 +301,7 @@ export declare class SsrSite extends Construct implements SSTConstruct {
300
301
  protected createRoute53Records(): void;
301
302
  private getS3ContentReplaceValues;
302
303
  private validateSiteExists;
304
+ private validateTimeout;
303
305
  private writeTypesFile;
304
306
  protected generateBuildId(): string;
305
307
  }
@@ -25,6 +25,7 @@ import { SsrFunction } from "./SsrFunction.js";
25
25
  import { getBuildCmdEnvironment, } from "./BaseSite.js";
26
26
  import { HttpsRedirect } from "./cdk/website-redirect.js";
27
27
  import { DnsValidatedCertificate } from "./cdk/dns-validated-certificate.js";
28
+ import { toCdkDuration } from "./util/duration.js";
28
29
  import { attachPermissionsToRole } from "./util/permission.js";
29
30
  import { getParameterPath, } from "./util/functionBinding.js";
30
31
  import { useProject } from "../project.js";
@@ -45,6 +46,7 @@ export class SsrSite extends Construct {
45
46
  props;
46
47
  doNotDeploy;
47
48
  buildConfig;
49
+ serverEdgeFunction;
48
50
  serverLambdaForEdge;
49
51
  serverLambdaForRegional;
50
52
  serverLambdaForDev;
@@ -70,6 +72,7 @@ export class SsrSite extends Construct {
70
72
  !stack.isActive || (app.mode === "dev" && !this.props.dev?.deploy);
71
73
  this.buildConfig = this.initBuildConfig();
72
74
  this.validateSiteExists();
75
+ this.validateTimeout();
73
76
  this.writeTypesFile();
74
77
  useSites().add(id, this.constructor.name, this.props);
75
78
  if (this.doNotDeploy) {
@@ -85,7 +88,11 @@ export class SsrSite extends Construct {
85
88
  this.bucket = this.createS3Bucket();
86
89
  // Create Server functions
87
90
  if (this.props.edge) {
88
- this.serverLambdaForEdge = this.createFunctionForEdge();
91
+ this.serverEdgeFunction = this.createFunctionForEdge();
92
+ this.serverLambdaForEdge = CdkFunction.fromFunctionAttributes(this, "IEdgeFunction", {
93
+ functionArn: this.serverEdgeFunction.functionArn,
94
+ role: this.serverEdgeFunction.role,
95
+ });
89
96
  this.createFunctionPermissionsForEdge();
90
97
  }
91
98
  else {
@@ -147,7 +154,7 @@ export class SsrSite extends Construct {
147
154
  if (this.doNotDeploy)
148
155
  return;
149
156
  return {
150
- function: this.serverLambdaForRegional,
157
+ function: this.serverLambdaForEdge || this.serverLambdaForRegional,
151
158
  bucket: this.bucket,
152
159
  distribution: this.distribution,
153
160
  hostedZone: this.hostedZone,
@@ -167,13 +174,10 @@ export class SsrSite extends Construct {
167
174
  * ```
168
175
  */
169
176
  attachPermissions(permissions) {
170
- this.serverLambdaForEdge?.attachPermissions(permissions);
171
- if (this.serverLambdaForDev) {
172
- attachPermissionsToRole(this.serverLambdaForDev.role, permissions);
173
- }
174
- if (this.serverLambdaForRegional) {
175
- attachPermissionsToRole(this.serverLambdaForRegional.role, permissions);
176
- }
177
+ const server = this.serverLambdaForEdge ||
178
+ this.serverLambdaForRegional ||
179
+ this.serverLambdaForDev;
180
+ attachPermissionsToRole(server?.role, permissions);
177
181
  }
178
182
  /** @internal */
179
183
  getConstructMetadata() {
@@ -535,14 +539,18 @@ function handler(event) {
535
539
  return domainNames;
536
540
  }
537
541
  buildDefaultBehaviorForRegional() {
538
- const { cdk } = this.props;
542
+ const { timeout, cdk } = this.props;
539
543
  const cfDistributionProps = cdk?.distribution || {};
540
544
  const fnUrl = this.serverLambdaForRegional.addFunctionUrl({
541
545
  authType: FunctionUrlAuthType.NONE,
542
546
  });
543
547
  return {
544
548
  viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
545
- origin: new HttpOrigin(Fn.parseDomainName(fnUrl.url)),
549
+ origin: new HttpOrigin(Fn.parseDomainName(fnUrl.url), {
550
+ readTimeout: typeof timeout === "string"
551
+ ? toCdkDuration(timeout)
552
+ : CdkDuration.seconds(timeout),
553
+ }),
546
554
  allowedMethods: AllowedMethods.ALLOW_ALL,
547
555
  cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
548
556
  compress: true,
@@ -577,7 +585,7 @@ function handler(event) {
577
585
  {
578
586
  includeBody: true,
579
587
  eventType: LambdaEdgeEventType.ORIGIN_REQUEST,
580
- functionVersion: this.serverLambdaForEdge.currentVersion,
588
+ functionVersion: this.serverEdgeFunction.currentVersion,
581
589
  },
582
590
  ...(cfDistributionProps.defaultBehavior?.edgeLambdas || []),
583
591
  ],
@@ -817,6 +825,18 @@ function handler(event) {
817
825
  throw new Error(`No site found at "${path.resolve(sitePath)}"`);
818
826
  }
819
827
  }
828
+ validateTimeout() {
829
+ const { edge, timeout } = this.props;
830
+ const num = typeof timeout === "number"
831
+ ? timeout
832
+ : toCdkDuration(timeout).toSeconds();
833
+ const limit = edge ? 30 : 180;
834
+ if (num > limit) {
835
+ throw new Error(edge
836
+ ? `Timeout must be less than or equal to 30 seconds when the "edge" flag is enabled.`
837
+ : `Timeout must be less than or equal to 180 seconds.`);
838
+ }
839
+ }
820
840
  writeTypesFile() {
821
841
  const typesPath = path.resolve(this.props.path, this.buildConfig.typesPath, "sst-env.d.ts");
822
842
  // Do not override the types file if it already exists
@@ -32,7 +32,8 @@ export declare function AuthHandler<Providers extends Record<string, Adapter<any
32
32
  clients: () => Promise<Record<string, string>>;
33
33
  onAuthorize?: (event: APIGatewayProxyEventV2) => Promise<void | keyof Providers>;
34
34
  onSuccess: (input: Result, response: typeof onSuccessResponse) => Promise<ReturnType<(typeof onSuccessResponse)[keyof typeof onSuccessResponse]>>;
35
- onError: () => Promise<APIGatewayProxyStructuredResultV2>;
35
+ onIndex?: (event: APIGatewayProxyEventV2) => Promise<APIGatewayProxyStructuredResultV2>;
36
+ onError?: () => Promise<APIGatewayProxyStructuredResultV2>;
36
37
  }): (event: APIGatewayProxyEventV2, context: import("aws-lambda").Context) => Promise<APIGatewayProxyStructuredResultV2>;
37
38
  export type SessionCreateInput = SessionValue & Partial<SignerOptions>;
38
39
  export {};
@@ -36,6 +36,9 @@ export function AuthHandler(input) {
36
36
  return ApiHandler(async (evt) => {
37
37
  const step = usePathParam("step");
38
38
  if (!step) {
39
+ if (input.onIndex) {
40
+ return input.onIndex(evt);
41
+ }
39
42
  const clients = await input.clients();
40
43
  return {
41
44
  statusCode: 200,
@@ -251,7 +254,12 @@ export function AuthHandler(input) {
251
254
  }
252
255
  }
253
256
  if (result.type === "error") {
254
- return input.onError();
257
+ if (input.onError)
258
+ return input.onError();
259
+ return {
260
+ statusCode: 400,
261
+ body: "an error has occured",
262
+ };
255
263
  }
256
264
  });
257
265
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.13.1",
4
+ "version": "2.13.2",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
@@ -178694,6 +178694,7 @@ async function AuthKeys(cfnRequest) {
178694
178694
  new import_client_ssm.PutParameterCommand({
178695
178695
  Name: privatePath,
178696
178696
  Value: privateKey,
178697
+ Overwrite: true,
178697
178698
  Type: "SecureString"
178698
178699
  })
178699
178700
  ),
@@ -178701,6 +178702,7 @@ async function AuthKeys(cfnRequest) {
178701
178702
  new import_client_ssm.PutParameterCommand({
178702
178703
  Name: publicPath,
178703
178704
  Value: publicKey,
178705
+ Overwrite: true,
178704
178706
  Type: "SecureString"
178705
178707
  })
178706
178708
  )