sst 2.39.7 → 2.39.9

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.
@@ -60,12 +60,10 @@ export declare class AstroSite extends SsrSite {
60
60
  edgeFunction?: string | undefined;
61
61
  }[];
62
62
  errorResponses?: import("aws-cdk-lib/aws-cloudfront").ErrorResponse[] | undefined;
63
- cachePolicyAllowedHeaders?: string[] | undefined;
64
- buildId?: string | undefined;
65
- warmerConfig?: {
66
- function: string;
67
- schedule?: import("aws-cdk-lib/aws-events").Schedule | undefined;
63
+ serverCachePolicy?: {
64
+ allowedHeaders?: string[] | undefined;
68
65
  } | undefined;
66
+ buildId?: string | undefined;
69
67
  };
70
68
  getConstructMetadata(): {
71
69
  data: {
@@ -217,12 +217,10 @@ export declare class NextjsSite extends SsrSite {
217
217
  edgeFunction?: "edgeServer" | undefined;
218
218
  }[];
219
219
  errorResponses?: import("aws-cdk-lib/aws-cloudfront").ErrorResponse[] | undefined;
220
- cachePolicyAllowedHeaders?: string[] | undefined;
221
- buildId?: string | undefined;
222
- warmerConfig?: {
223
- function: string;
224
- schedule?: import("aws-cdk-lib/aws-events").Schedule | undefined;
220
+ serverCachePolicy?: {
221
+ allowedHeaders?: string[] | undefined;
225
222
  } | undefined;
223
+ buildId?: string | undefined;
226
224
  };
227
225
  private createRevalidationQueue;
228
226
  private createRevalidationTable;
@@ -233,11 +233,10 @@ export class NextjsSite extends SsrSite {
233
233
  origin: "s3",
234
234
  })),
235
235
  ],
236
- cachePolicyAllowedHeaders: DEFAULT_CACHE_POLICY_ALLOWED_HEADERS,
237
- buildId: this.getBuildId(),
238
- warmerConfig: {
239
- function: path.join(sitePath, ".open-next", "warmer-function"),
236
+ serverCachePolicy: {
237
+ allowedHeaders: DEFAULT_CACHE_POLICY_ALLOWED_HEADERS,
240
238
  },
239
+ buildId: this.getBuildId(),
241
240
  });
242
241
  }
243
242
  createRevalidationQueue() {
@@ -86,12 +86,10 @@ export declare class RemixSite extends SsrSite {
86
86
  edgeFunction?: "edgeServer" | undefined;
87
87
  }[];
88
88
  errorResponses?: import("aws-cdk-lib/aws-cloudfront").ErrorResponse[] | undefined;
89
- cachePolicyAllowedHeaders?: string[] | undefined;
90
- buildId?: string | undefined;
91
- warmerConfig?: {
92
- function: string;
93
- schedule?: import("aws-cdk-lib/aws-events").Schedule | undefined;
89
+ serverCachePolicy?: {
90
+ allowedHeaders?: string[] | undefined;
94
91
  } | undefined;
92
+ buildId?: string | undefined;
95
93
  };
96
94
  protected getServerModuleFormat(): "cjs" | "esm";
97
95
  private createServerLambdaBundle;
@@ -68,12 +68,10 @@ export declare class SolidStartSite extends SsrSite {
68
68
  edgeFunction?: "edgeServer" | undefined;
69
69
  }[];
70
70
  errorResponses?: import("aws-cdk-lib/aws-cloudfront").ErrorResponse[] | undefined;
71
- cachePolicyAllowedHeaders?: string[] | undefined;
72
- buildId?: string | undefined;
73
- warmerConfig?: {
74
- function: string;
75
- schedule?: import("aws-cdk-lib/aws-events").Schedule | undefined;
71
+ serverCachePolicy?: {
72
+ allowedHeaders?: string[] | undefined;
76
73
  } | undefined;
74
+ buildId?: string | undefined;
77
75
  };
78
76
  getConstructMetadata(): {
79
77
  data: {
@@ -274,10 +274,10 @@ export class SsrFunction extends Construct {
274
274
  const newHandlerFunction = "handler";
275
275
  await fs.writeFile(path.join(bundle, handlerDir, `${newHandlerName}.mjs`), streaming
276
276
  ? [
277
- `export const ${newHandlerFunction} = awslambda.streamifyResponse(async (event, context) => {`,
277
+ `export const ${newHandlerFunction} = awslambda.streamifyResponse(async (event, responseStream, context) => {`,
278
278
  ...injections,
279
279
  ` const { ${oldHandlerFunction}: rawHandler} = await import("./${oldHandlerName}.mjs");`,
280
- ` return rawHandler(event, context);`,
280
+ ` return rawHandler(event, responseStream);`,
281
281
  `});`,
282
282
  ].join("\n")
283
283
  : [
@@ -3,7 +3,6 @@ import { Bucket, BucketProps, IBucket } from "aws-cdk-lib/aws-s3";
3
3
  import { Function as CdkFunction, FunctionProps as CdkFunctionProps } from "aws-cdk-lib/aws-lambda";
4
4
  import { ICachePolicy, IResponseHeadersPolicy, ViewerProtocolPolicy, AllowedMethods, CachePolicyProps, ErrorResponse } from "aws-cdk-lib/aws-cloudfront";
5
5
  import { S3OriginProps } from "aws-cdk-lib/aws-cloudfront-origins";
6
- import { Schedule } from "aws-cdk-lib/aws-events";
7
6
  import { DistributionDomainProps } from "./Distribution.js";
8
7
  import { SSTConstruct } from "./Construct.js";
9
8
  import { NodeJSProps, FunctionProps } from "./Function.js";
@@ -391,6 +390,10 @@ export interface SsrSiteProps {
391
390
  */
392
391
  viewerProtocolPolicy?: ViewerProtocolPolicy;
393
392
  server?: Pick<CdkFunctionProps, "layers" | "vpc" | "vpcSubnets" | "securityGroups" | "allowAllOutbound" | "allowPublicSubnet" | "architecture" | "logRetention"> & Pick<FunctionProps, "copyFiles">;
393
+ /**
394
+ * @hidden Need to fix tsdoc generation to support the `Plan` type
395
+ */
396
+ transform?: (args: Plan) => void;
394
397
  };
395
398
  }
396
399
  type SsrSiteInvalidationNormalizedProps = Exclude<SsrSiteProps["invalidation"], undefined>;
@@ -488,12 +491,10 @@ export declare abstract class SsrSite extends Construct implements SSTConstruct
488
491
  edgeFunction?: keyof EdgeFunctions;
489
492
  }[];
490
493
  errorResponses?: ErrorResponse[];
491
- cachePolicyAllowedHeaders?: string[];
492
- buildId?: string;
493
- warmerConfig?: {
494
- function: string;
495
- schedule?: Schedule;
494
+ serverCachePolicy?: {
495
+ allowedHeaders?: string[];
496
496
  };
497
+ buildId?: string;
497
498
  }): {
498
499
  cloudFrontFunctions?: CloudFrontFunctions | undefined;
499
500
  edgeFunctions?: EdgeFunctions | undefined;
@@ -508,12 +509,10 @@ export declare abstract class SsrSite extends Construct implements SSTConstruct
508
509
  edgeFunction?: keyof EdgeFunctions;
509
510
  }[];
510
511
  errorResponses?: ErrorResponse[] | undefined;
511
- cachePolicyAllowedHeaders?: string[] | undefined;
512
- buildId?: string | undefined;
513
- warmerConfig?: {
514
- function: string;
515
- schedule?: Schedule | undefined;
512
+ serverCachePolicy?: {
513
+ allowedHeaders?: string[] | undefined;
516
514
  } | undefined;
515
+ buildId?: string | undefined;
517
516
  };
518
517
  }
519
518
  export declare const useSites: () => {
@@ -95,6 +95,7 @@ export class SsrSite extends Construct {
95
95
  // Build app
96
96
  buildApp();
97
97
  const plan = this.plan(bucket);
98
+ transformPlan();
98
99
  validateTimeout();
99
100
  // Create CloudFront
100
101
  const cfFunctions = createCloudFrontFunctions();
@@ -186,6 +187,9 @@ export class SsrSite extends Construct {
186
187
  ...cdk?.bucket,
187
188
  });
188
189
  }
190
+ function transformPlan() {
191
+ cdk?.transform?.(plan);
192
+ }
189
193
  function createServerFunctionForDev() {
190
194
  const role = new Role(self, "ServerFunctionRole", {
191
195
  assumedBy: new CompositePrincipal(new AccountPrincipal(app.account), new ServicePrincipal("lambda.amazonaws.com")),
@@ -219,8 +223,7 @@ export class SsrSite extends Construct {
219
223
  // Create warmer function
220
224
  const warmer = new CdkFunction(self, "WarmerFunction", {
221
225
  description: "SSR warmer",
222
- code: Code.fromAsset(plan.warmerConfig?.function ??
223
- path.join(__dirname, "../support/ssr-warmer")),
226
+ code: Code.fromAsset(path.join(__dirname, "../support/ssr-warmer")),
224
227
  runtime: Runtime.NODEJS_18_X,
225
228
  handler: "index.handler",
226
229
  timeout: CdkDuration.minutes(15),
@@ -233,7 +236,7 @@ export class SsrSite extends Construct {
233
236
  ssrFunctions[0].grantInvoke(warmer);
234
237
  // Create cron job
235
238
  new Rule(self, "WarmerRule", {
236
- schedule: plan.warmerConfig?.schedule ?? Schedule.rate(CdkDuration.minutes(5)),
239
+ schedule: Schedule.rate(CdkDuration.minutes(5)),
237
240
  targets: [new LambdaFunction(warmer, { retryAttempts: 0 })],
238
241
  });
239
242
  // Create custom resource to prewarm on deploy
@@ -452,7 +455,7 @@ function handler(event) {
452
455
  ...cdk?.server,
453
456
  streaming: props.streaming,
454
457
  injections: [
455
- ...(warm ? [useServerFunctionWarmingInjection()] : []),
458
+ ...(warm ? [useServerFunctionWarmingInjection(props.streaming)] : []),
456
459
  ...(props.injections || []),
457
460
  ],
458
461
  prefetchSecrets: regional?.prefetchSecrets,
@@ -632,7 +635,7 @@ function handler(event) {
632
635
  return singletonUrlSigner;
633
636
  }
634
637
  function useServerBehaviorCachePolicy() {
635
- const allowedHeaders = plan.cachePolicyAllowedHeaders || [];
638
+ const allowedHeaders = plan.serverCachePolicy?.allowedHeaders ?? [];
636
639
  singletonCachePolicy =
637
640
  singletonCachePolicy ??
638
641
  new CachePolicy(self, "ServerCache", SsrSite.buildDefaultServerCachePolicyProps(allowedHeaders));
@@ -645,15 +648,24 @@ function handler(event) {
645
648
  OriginRequestPolicy.fromOriginRequestPolicyId(self, "ServerOriginRequestPolicy", "b689b0a8-53d0-40ab-baf2-68738e2966ac");
646
649
  return singletonOriginRequestPolicy;
647
650
  }
648
- function useServerFunctionWarmingInjection() {
649
- return `
650
- if (event.type === "warmer") {
651
- return new Promise((resolve) => {
652
- setTimeout(() => {
653
- resolve({ serverId: "server-" + Math.random().toString(36).slice(2, 8) });
654
- }, event.delay);
655
- });
656
- }`;
651
+ function useServerFunctionWarmingInjection(streaming) {
652
+ return [
653
+ `if (event.type === "warmer") {`,
654
+ ` const p = new Promise((resolve) => {`,
655
+ ` setTimeout(() => {`,
656
+ ` resolve({ serverId: "server-" + Math.random().toString(36).slice(2, 8) });`,
657
+ ` }, event.delay);`,
658
+ ` });`,
659
+ ...(streaming
660
+ ? [
661
+ ` const response = await p;`,
662
+ ` responseStream.write(JSON.stringify(response));`,
663
+ ` responseStream.end();`,
664
+ ` return;`,
665
+ ]
666
+ : [` return p;`]),
667
+ `}`,
668
+ ].join("\n");
657
669
  }
658
670
  function getS3FileOptions(copy) {
659
671
  const fileOptions = [];
@@ -99,12 +99,10 @@ export declare class SvelteKitSite extends SsrSite {
99
99
  edgeFunction?: "edgeServer" | undefined;
100
100
  }[];
101
101
  errorResponses?: import("aws-cdk-lib/aws-cloudfront").ErrorResponse[] | undefined;
102
- cachePolicyAllowedHeaders?: string[] | undefined;
103
- buildId?: string | undefined;
104
- warmerConfig?: {
105
- function: string;
106
- schedule?: import("aws-cdk-lib/aws-events").Schedule | undefined;
102
+ serverCachePolicy?: {
103
+ allowedHeaders?: string[] | undefined;
107
104
  } | undefined;
105
+ buildId?: string | undefined;
108
106
  };
109
107
  getConstructMetadata(): {
110
108
  data: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.39.7",
4
+ "version": "2.39.9",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
@@ -120,7 +120,7 @@
120
120
  "@types/ws": "^8.5.3",
121
121
  "@types/yargs": "^17.0.13",
122
122
  "archiver": "^5.3.1",
123
- "astro-sst": "2.39.7",
123
+ "astro-sst": "2.39.9",
124
124
  "async": "^3.2.4",
125
125
  "tsx": "^3.12.1",
126
126
  "typescript": "^5.2.2",