sst 2.5.7 → 2.5.8

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.
@@ -0,0 +1,15 @@
1
+ /// <reference types="yargs" />
2
+ import type { Program } from "../../program.js";
3
+ export declare const load: (program: Program) => import("yargs").Argv<{
4
+ stage: string | undefined;
5
+ } & {
6
+ profile: string | undefined;
7
+ } & {
8
+ region: string | undefined;
9
+ } & {
10
+ verbose: boolean | undefined;
11
+ } & {
12
+ role: string | undefined;
13
+ } & {
14
+ filename: string;
15
+ }>;
@@ -0,0 +1,41 @@
1
+ export const load = (program) => program.command("load <filename>", "Loads secrets from an .env file", (yargs) => yargs.positional("filename", {
2
+ type: "string",
3
+ demandOption: true,
4
+ }), async (args) => {
5
+ const { Config } = await import("../../../config.js");
6
+ const { Colors } = await import("../../colors.js");
7
+ const { blue } = await import("colorette");
8
+ const { createSpinner } = await import("../../spinner.js");
9
+ const { parse } = await import("dotenv");
10
+ const fs = await import("fs/promises");
11
+ // Parse .env file
12
+ const fileContent = await fs.readFile(args.filename, "utf-8");
13
+ const envVars = parse(fileContent);
14
+ // Set secrets
15
+ const setting = createSpinner(` Setting secrets from "${args.filename}"`).start();
16
+ for (const [key, value] of Object.entries(envVars)) {
17
+ await Config.setSecret({ key, value });
18
+ }
19
+ setting.succeed();
20
+ // Restart functions & sites
21
+ const envNames = Object.keys(envVars);
22
+ const restarting = createSpinner(` Restarting all resources using ${blue(envNames.join(", "))}...`).start();
23
+ const { edgeSites, sites, placeholderSites, functions } = await Config.restart(envNames);
24
+ restarting.stop().clear();
25
+ const siteCount = sites.length + placeholderSites.length;
26
+ if (siteCount > 0) {
27
+ Colors.line(Colors.success(`✔ `), siteCount === 1
28
+ ? `Reloaded ${siteCount} site`
29
+ : `Reloaded ${siteCount} sites`);
30
+ }
31
+ const functionCount = functions.length;
32
+ if (functionCount > 0) {
33
+ Colors.line(Colors.success(`✔ `), functionCount === 1
34
+ ? `Reloaded ${functionCount} function`
35
+ : `Reloaded ${functionCount} functions`);
36
+ }
37
+ edgeSites.forEach(({ id, type }) => {
38
+ Colors.line(Colors.primary(`➜ `), `Redeploy the "${id}" ${type} to use the new secret`);
39
+ });
40
+ process.exit(0);
41
+ });
@@ -1,5 +1,6 @@
1
1
  import { get } from "./get.js";
2
2
  import { list } from "./list.js";
3
+ import { load } from "./load.js";
3
4
  import { remove } from "./remove.js";
4
5
  import { set } from "./set.js";
5
6
  export function secrets(program) {
@@ -7,6 +8,7 @@ export function secrets(program) {
7
8
  yargs.demandCommand(1);
8
9
  set(yargs);
9
10
  get(yargs);
11
+ load(yargs);
10
12
  list(yargs);
11
13
  remove(yargs);
12
14
  return yargs;
@@ -27,7 +27,7 @@ export const set = (program) => program.command("set <name> <value>", "Set the v
27
27
  setting.succeed();
28
28
  // Restart functions & sites
29
29
  const restarting = createSpinner(` Reloading all resources using ${blue(args.name)}...`).start();
30
- const { edgeSites, sites, placeholderSites, functions } = await Config.restart(args.name);
30
+ const { edgeSites, sites, placeholderSites, functions } = await Config.restart([args.name]);
31
31
  restarting.stop().clear();
32
32
  const siteCount = sites.length + placeholderSites.length;
33
33
  if (siteCount > 0) {
package/config.d.ts CHANGED
@@ -46,7 +46,7 @@ export declare namespace Config {
46
46
  key: string;
47
47
  fallback?: boolean;
48
48
  }): Promise<void>;
49
- function restart(key: string): Promise<{
49
+ function restart(keys: string[]): Promise<{
50
50
  edgeSites: SsrSiteMetadata[];
51
51
  sites: SsrSiteMetadata[];
52
52
  placeholderSites: SsrSiteMetadata[];
package/config.js CHANGED
@@ -115,7 +115,7 @@ export var Config;
115
115
  }));
116
116
  }
117
117
  Config.removeSecret = removeSecret;
118
- async function restart(key) {
118
+ async function restart(keys) {
119
119
  const metadata = await Stacks.metadata();
120
120
  const siteData = Object.values(metadata)
121
121
  .flat()
@@ -123,7 +123,7 @@ export var Config;
123
123
  c.type === "NextjsSite" ||
124
124
  c.type === "RemixSite" ||
125
125
  c.type === "SolidStartSite")
126
- .filter((c) => c.data.secrets.includes(key));
126
+ .filter((c) => keys.some((key) => c.data.secrets.includes(key)));
127
127
  const siteDataPlaceholder = siteData.filter((c) => c.data.mode === "placeholder");
128
128
  const siteDataEdge = siteData
129
129
  .filter((c) => c.data.mode === "deployed")
@@ -137,7 +137,7 @@ export var Config;
137
137
  .filter((c) => c.type === "Function")
138
138
  // filter out SSR functions for sites
139
139
  .filter((c) => !regionalSiteArns.includes(c.data.arn))
140
- .filter((c) => c.data.secrets.includes(key));
140
+ .filter((c) => keys.some((key) => c.data.secrets.includes(key)));
141
141
  // Restart sites
142
142
  const restartedSites = (await Promise.all(siteDataRegional.map(async (s) => {
143
143
  const restarted = await restartFunction(s.data.server);
@@ -26,7 +26,7 @@ const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
26
26
  export class NextjsSite extends SsrSite {
27
27
  constructor(scope, id, props) {
28
28
  super(scope, id, {
29
- buildCommand: "npx --yes open-next@^0.9.0 build",
29
+ buildCommand: "npx --yes open-next@~1.1.0 build",
30
30
  ...props,
31
31
  });
32
32
  }
@@ -203,6 +203,7 @@ export class NextjsSite extends SsrSite {
203
203
  buildServerBehaviorForRegional(serverOrigin, cachePolicy, originRequestPolicy) {
204
204
  return {
205
205
  viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
206
+ functionAssociations: this.buildBehaviorFunctionAssociations(),
206
207
  origin: serverOrigin,
207
208
  allowedMethods: AllowedMethods.ALLOW_ALL,
208
209
  cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
@@ -214,6 +215,7 @@ export class NextjsSite extends SsrSite {
214
215
  buildServerBehaviorForEdge(functionVersion, s3Origin, cachePolicy, originRequestPolicy) {
215
216
  return {
216
217
  viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
218
+ functionAssociations: this.buildBehaviorFunctionAssociations(),
217
219
  origin: s3Origin,
218
220
  allowedMethods: AllowedMethods.ALLOW_ALL,
219
221
  cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
@@ -268,6 +270,7 @@ export class NextjsSite extends SsrSite {
268
270
  return {
269
271
  origin: fallbackOriginGroup,
270
272
  viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
273
+ functionAssociations: this.buildBehaviorFunctionAssociations(),
271
274
  compress: true,
272
275
  cachePolicy,
273
276
  originRequestPolicy,
@@ -279,6 +282,7 @@ export class NextjsSite extends SsrSite {
279
282
  const cfDistributionProps = cdk?.distribution || {};
280
283
  return {
281
284
  viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
285
+ functionAssociations: this.buildBehaviorFunctionAssociations(),
282
286
  origin: s3Origin,
283
287
  allowedMethods: AllowedMethods.ALLOW_ALL,
284
288
  cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
@@ -2,7 +2,7 @@ import { Construct } from "constructs";
2
2
  import { Bucket, BucketProps, IBucket } from "aws-cdk-lib/aws-s3";
3
3
  import { Function as CdkFunction, FunctionProps } from "aws-cdk-lib/aws-lambda";
4
4
  import { IHostedZone } from "aws-cdk-lib/aws-route53";
5
- import { Distribution, ICachePolicy, BehaviorOptions, CachePolicy } from "aws-cdk-lib/aws-cloudfront";
5
+ import { Distribution, ICachePolicy, BehaviorOptions, CachePolicy, Function as CfFunction, FunctionEventType as CfFunctionEventType } from "aws-cdk-lib/aws-cloudfront";
6
6
  import { ICertificate } from "aws-cdk-lib/aws-certificatemanager";
7
7
  import { SSTConstruct } from "./Construct.js";
8
8
  import { NodeJSProps, Function } from "./Function.js";
@@ -201,6 +201,7 @@ export declare class SsrSite extends Construct implements SSTConstruct {
201
201
  protected serverLambdaForRegional?: CdkFunction;
202
202
  private serverLambdaForDev?;
203
203
  private bucket;
204
+ private cfFunction;
204
205
  private distribution;
205
206
  private hostedZone?;
206
207
  private certificate?;
@@ -262,12 +263,16 @@ export declare class SsrSite extends Construct implements SSTConstruct {
262
263
  private createFunctionPermissionsForRegional;
263
264
  private createFunctionPermissionsForEdge;
264
265
  private validateCloudFrontDistributionSettings;
266
+ private createCloudFrontFunction;
265
267
  protected createCloudFrontDistributionForRegional(): Distribution;
266
268
  protected createCloudFrontDistributionForEdge(): Distribution;
267
269
  protected buildDistributionDomainNames(): string[];
268
270
  protected buildDefaultBehaviorForRegional(): BehaviorOptions;
269
271
  private buildDefaultBehaviorForEdge;
270
- private buildBehaviorFunctionAssociations;
272
+ protected buildBehaviorFunctionAssociations(): {
273
+ eventType: CfFunctionEventType;
274
+ function: CfFunction;
275
+ }[];
271
276
  private buildStaticFileBehaviors;
272
277
  protected buildServerCachePolicy(): CachePolicy;
273
278
  protected buildServerOriginRequestPolicy(): import("aws-cdk-lib/aws-cloudfront").IOriginRequestPolicy;
@@ -49,6 +49,7 @@ export class SsrSite extends Construct {
49
49
  serverLambdaForRegional;
50
50
  serverLambdaForDev;
51
51
  bucket;
52
+ cfFunction;
52
53
  distribution;
53
54
  hostedZone;
54
55
  certificate;
@@ -73,7 +74,7 @@ export class SsrSite extends Construct {
73
74
  useSites().add(id, this.constructor.name, this.props);
74
75
  if (this.doNotDeploy) {
75
76
  // @ts-ignore
76
- this.bucket = this.distribution = null;
77
+ this.cfFunction = this.bucket = this.distribution = null;
77
78
  this.serverLambdaForDev = this.createFunctionForDev();
78
79
  return;
79
80
  }
@@ -101,6 +102,7 @@ export class SsrSite extends Construct {
101
102
  const s3deployCR = this.createS3Deployment(cliLayer, assets, assetFileOptions);
102
103
  // Create CloudFront
103
104
  this.validateCloudFrontDistributionSettings();
105
+ this.cfFunction = this.createCloudFrontFunction();
104
106
  this.distribution = this.props.edge
105
107
  ? this.createCloudFrontDistributionForEdge()
106
108
  : this.createCloudFrontDistributionForRegional();
@@ -458,6 +460,16 @@ export class SsrSite extends Construct {
458
460
  throw new Error(`Do not configure the "cfDistribution.domainNames". Use the "customDomain" to configure the domain name.`);
459
461
  }
460
462
  }
463
+ createCloudFrontFunction() {
464
+ return new CfFunction(this, "CloudFrontFunction", {
465
+ code: CfFunctionCode.fromInline(`
466
+ function handler(event) {
467
+ var request = event.request;
468
+ request.headers["x-forwarded-host"] = request.headers.host;
469
+ return request;
470
+ }`),
471
+ });
472
+ }
461
473
  createCloudFrontDistributionForRegional() {
462
474
  const { cdk } = this.props;
463
475
  const cfDistributionProps = cdk?.distribution || {};
@@ -560,14 +572,7 @@ export class SsrSite extends Construct {
560
572
  return [
561
573
  {
562
574
  eventType: CfFunctionEventType.VIEWER_REQUEST,
563
- function: new CfFunction(this, "CloudFrontFunction", {
564
- code: CfFunctionCode.fromInline(`
565
- function handler(event) {
566
- var request = event.request;
567
- request.headers["x-forwarded-host"] = request.headers.host;
568
- return request;
569
- }`),
570
- }),
575
+ function: this.cfFunction,
571
576
  },
572
577
  ];
573
578
  }
@@ -17,7 +17,7 @@ declare function JobControl<Name extends keyof JobResources>(name: Name): {
17
17
  *
18
18
  * @example
19
19
  * ```ts
20
- * declare module "@serverless-stack/node/job" {
20
+ * declare module "sst/node/job" {
21
21
  * export interface JobTypes {
22
22
  * MyJob: {
23
23
  * title: string;
package/node/job/index.js CHANGED
@@ -31,7 +31,7 @@ function JobControl(name) {
31
31
  *
32
32
  * @example
33
33
  * ```ts
34
- * declare module "@serverless-stack/node/job" {
34
+ * declare module "sst/node/job" {
35
35
  * export interface JobTypes {
36
36
  * MyJob: {
37
37
  * title: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.5.7",
3
+ "version": "2.5.8",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },
package/sst.mjs CHANGED
@@ -6698,18 +6698,18 @@ var init_config = __esm({
6698
6698
  );
6699
6699
  }
6700
6700
  Config2.removeSecret = removeSecret;
6701
- async function restart(key) {
6701
+ async function restart(keys) {
6702
6702
  const metadata3 = await stacks_exports.metadata();
6703
6703
  const siteData = Object.values(metadata3).flat().filter(
6704
6704
  (c) => c.type === "AstroSite" || c.type === "NextjsSite" || c.type === "RemixSite" || c.type === "SolidStartSite"
6705
- ).filter((c) => c.data.secrets.includes(key));
6705
+ ).filter((c) => keys.some((key) => c.data.secrets.includes(key)));
6706
6706
  const siteDataPlaceholder = siteData.filter(
6707
6707
  (c) => c.data.mode === "placeholder"
6708
6708
  );
6709
6709
  const siteDataEdge = siteData.filter((c) => c.data.mode === "deployed").filter((c) => c.data.edge);
6710
6710
  const siteDataRegional = siteData.filter((c) => c.data.mode === "deployed").filter((c) => !c.data.edge);
6711
6711
  const regionalSiteArns = siteData.map((s) => s.data.server);
6712
- const functionData = Object.values(metadata3).flat().filter((c) => c.type === "Function").filter((c) => !regionalSiteArns.includes(c.data.arn)).filter((c) => c.data.secrets.includes(key));
6712
+ const functionData = Object.values(metadata3).flat().filter((c) => c.type === "Function").filter((c) => !regionalSiteArns.includes(c.data.arn)).filter((c) => keys.some((key) => c.data.secrets.includes(key)));
6713
6713
  const restartedSites = (await Promise.all(
6714
6714
  siteDataRegional.map(async (s) => {
6715
6715
  const restarted = await restartFunction(s.data.server);
@@ -7721,6 +7721,60 @@ var list = (program2) => program2.command(
7721
7721
  }
7722
7722
  );
7723
7723
 
7724
+ // src/cli/commands/secrets/load.ts
7725
+ var load2 = (program2) => program2.command(
7726
+ "load <filename>",
7727
+ "Loads secrets from an .env file",
7728
+ (yargs2) => yargs2.positional("filename", {
7729
+ type: "string",
7730
+ demandOption: true
7731
+ }),
7732
+ async (args) => {
7733
+ const { Config: Config2 } = await Promise.resolve().then(() => (init_config(), config_exports));
7734
+ const { Colors: Colors2 } = await Promise.resolve().then(() => (init_colors(), colors_exports));
7735
+ const { blue: blue4 } = await import("colorette");
7736
+ const { createSpinner: createSpinner2 } = await Promise.resolve().then(() => (init_spinner(), spinner_exports));
7737
+ const { parse: parse2 } = await import("dotenv");
7738
+ const fs18 = await import("fs/promises");
7739
+ const fileContent = await fs18.readFile(args.filename, "utf-8");
7740
+ const envVars = parse2(fileContent);
7741
+ const setting = createSpinner2(
7742
+ ` Setting secrets from "${args.filename}"`
7743
+ ).start();
7744
+ for (const [key, value] of Object.entries(envVars)) {
7745
+ await Config2.setSecret({ key, value });
7746
+ }
7747
+ setting.succeed();
7748
+ const envNames = Object.keys(envVars);
7749
+ const restarting = createSpinner2(
7750
+ ` Restarting all resources using ${blue4(envNames.join(", "))}...`
7751
+ ).start();
7752
+ const { edgeSites, sites, placeholderSites, functions } = await Config2.restart(envNames);
7753
+ restarting.stop().clear();
7754
+ const siteCount = sites.length + placeholderSites.length;
7755
+ if (siteCount > 0) {
7756
+ Colors2.line(
7757
+ Colors2.success(`\u2714 `),
7758
+ siteCount === 1 ? `Reloaded ${siteCount} site` : `Reloaded ${siteCount} sites`
7759
+ );
7760
+ }
7761
+ const functionCount = functions.length;
7762
+ if (functionCount > 0) {
7763
+ Colors2.line(
7764
+ Colors2.success(`\u2714 `),
7765
+ functionCount === 1 ? `Reloaded ${functionCount} function` : `Reloaded ${functionCount} functions`
7766
+ );
7767
+ }
7768
+ edgeSites.forEach(({ id, type }) => {
7769
+ Colors2.line(
7770
+ Colors2.primary(`\u279C `),
7771
+ `Redeploy the "${id}" ${type} to use the new secret`
7772
+ );
7773
+ });
7774
+ process.exit(0);
7775
+ }
7776
+ );
7777
+
7724
7778
  // src/cli/commands/secrets/remove.ts
7725
7779
  var remove3 = (program2) => program2.command(
7726
7780
  "remove <name>",
@@ -7779,7 +7833,7 @@ var set = (program2) => program2.command(
7779
7833
  const restarting = createSpinner2(
7780
7834
  ` Reloading all resources using ${blue4(args.name)}...`
7781
7835
  ).start();
7782
- const { edgeSites, sites, placeholderSites, functions } = await Config2.restart(args.name);
7836
+ const { edgeSites, sites, placeholderSites, functions } = await Config2.restart([args.name]);
7783
7837
  restarting.stop().clear();
7784
7838
  const siteCount = sites.length + placeholderSites.length;
7785
7839
  if (siteCount > 0) {
@@ -7811,6 +7865,7 @@ function secrets(program2) {
7811
7865
  yargs2.demandCommand(1);
7812
7866
  set(yargs2);
7813
7867
  get(yargs2);
7868
+ load2(yargs2);
7814
7869
  list(yargs2);
7815
7870
  remove3(yargs2);
7816
7871
  return yargs2;