sst 2.5.4 → 2.5.6

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.
Files changed (54) hide show
  1. package/cli/commands/bind.js +89 -64
  2. package/cli/commands/version.js +1 -0
  3. package/config.js +10 -10
  4. package/constructs/Api.d.ts +1 -1
  5. package/constructs/Api.js +1 -1
  6. package/constructs/ApiGatewayV1Api.d.ts +1 -1
  7. package/constructs/ApiGatewayV1Api.js +1 -1
  8. package/constructs/AppSyncApi.d.ts +1 -1
  9. package/constructs/AppSyncApi.js +1 -1
  10. package/constructs/Auth.d.ts +1 -1
  11. package/constructs/Auth.js +1 -1
  12. package/constructs/Bucket.d.ts +1 -1
  13. package/constructs/Bucket.js +1 -1
  14. package/constructs/Cognito.d.ts +1 -1
  15. package/constructs/Cognito.js +1 -1
  16. package/constructs/Cron.d.ts +1 -1
  17. package/constructs/Cron.js +1 -1
  18. package/constructs/EventBus.d.ts +1 -1
  19. package/constructs/EventBus.js +1 -1
  20. package/constructs/Function.d.ts +1 -1
  21. package/constructs/Function.js +1 -1
  22. package/constructs/Job.d.ts +38 -2
  23. package/constructs/Job.js +4 -2
  24. package/constructs/KinesisStream.d.ts +1 -1
  25. package/constructs/KinesisStream.js +1 -1
  26. package/constructs/Parameter.d.ts +1 -1
  27. package/constructs/Parameter.js +1 -1
  28. package/constructs/Queue.d.ts +1 -1
  29. package/constructs/Queue.js +1 -1
  30. package/constructs/RDS.d.ts +2 -2
  31. package/constructs/RDS.js +1 -1
  32. package/constructs/Script.d.ts +2 -2
  33. package/constructs/Script.js +1 -1
  34. package/constructs/Secret.d.ts +1 -1
  35. package/constructs/Secret.js +1 -1
  36. package/constructs/SsrSite.js +5 -1
  37. package/constructs/Stack.d.ts +1 -1
  38. package/constructs/Stack.js +1 -1
  39. package/constructs/StaticSite.d.ts +1 -1
  40. package/constructs/StaticSite.js +1 -1
  41. package/constructs/Table.d.ts +1 -1
  42. package/constructs/Table.js +1 -1
  43. package/constructs/Topic.d.ts +1 -1
  44. package/constructs/Topic.js +1 -1
  45. package/constructs/WebSocketApi.d.ts +1 -1
  46. package/constructs/WebSocketApi.js +1 -1
  47. package/constructs/future/Auth.d.ts +1 -1
  48. package/constructs/future/Auth.js +1 -1
  49. package/package.json +1 -1
  50. package/project.d.ts +7 -0
  51. package/project.js +35 -8
  52. package/sst.mjs +126 -82
  53. package/support/bootstrap-metadata-function/index.mjs +238 -238
  54. package/support/custom-resources/index.mjs +238 -238
@@ -8,7 +8,7 @@ export interface ScriptProps {
8
8
  *
9
9
  * @example
10
10
  * ```js
11
- * import { Script } from "@serverless-stack/resources";
11
+ * import { Script } from "sst/constructs";
12
12
  *
13
13
  * new Script(stack, "Script", {
14
14
  * onCreate: "src/script.create",
@@ -76,7 +76,7 @@ export interface ScriptProps {
76
76
  * @example
77
77
  *
78
78
  * ```js
79
- * import { Script } from "@serverless-stack/resources";
79
+ * import { Script } from "sst/constructs";
80
80
  *
81
81
  * new Script(stack, "Script", {
82
82
  * onCreate: "src/function.create",
@@ -14,7 +14,7 @@ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
14
14
  * @example
15
15
  *
16
16
  * ```js
17
- * import { Script } from "@serverless-stack/resources";
17
+ * import { Script } from "sst/constructs";
18
18
  *
19
19
  * new Script(stack, "Script", {
20
20
  * onCreate: "src/function.create",
@@ -8,7 +8,7 @@ import { FunctionBindingProps } from "./util/functionBinding.js";
8
8
  * ### Using the minimal config
9
9
  *
10
10
  * ```js
11
- * import { Config } from "@serverless-stack/resources";
11
+ * import { Config } from "sst/constructs";
12
12
  *
13
13
  * new Config.Secret(stack, "STRIPE_KEY");
14
14
  * ```
@@ -8,7 +8,7 @@ import { getParameterPath, getParameterFallbackPath, } from "./util/functionBind
8
8
  * ### Using the minimal config
9
9
  *
10
10
  * ```js
11
- * import { Config } from "@serverless-stack/resources";
11
+ * import { Config } from "sst/constructs";
12
12
  *
13
13
  * new Config.Secret(stack, "STRIPE_KEY");
14
14
  * ```
@@ -165,10 +165,11 @@ export class SsrSite extends Construct {
165
165
  * ```
166
166
  */
167
167
  attachPermissions(permissions) {
168
+ this.serverLambdaForDev?.attachPermissions(permissions);
169
+ this.serverLambdaForEdge?.attachPermissions(permissions);
168
170
  if (this.serverLambdaForRegional) {
169
171
  attachPermissionsToRole(this.serverLambdaForRegional.role, permissions);
170
172
  }
171
- this.serverLambdaForEdge?.attachPermissions(permissions);
172
173
  }
173
174
  /** @internal */
174
175
  getConstructMetadata() {
@@ -432,6 +433,9 @@ export class SsrSite extends Construct {
432
433
  environment,
433
434
  permissions,
434
435
  role,
436
+ // Force enable live dev to prevent the function handler to be built
437
+ // in the case user set "enableLiveDev: false" on the app or stack.
438
+ enableLiveDev: true,
435
439
  });
436
440
  fn._doNotAllowOthersToBind = true;
437
441
  return fn;
@@ -11,7 +11,7 @@ export type StackProps = cdk.StackProps;
11
11
  * @example
12
12
  *
13
13
  * ```js
14
- * import { StackContext } from "@serverless-stack/resources";
14
+ * import { StackContext } from "sst/constructs";
15
15
  *
16
16
  * export function MyStack({ stack }: StackContext) {
17
17
  * // Define your stack
@@ -13,7 +13,7 @@ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
13
13
  * @example
14
14
  *
15
15
  * ```js
16
- * import { StackContext } from "@serverless-stack/resources";
16
+ * import { StackContext } from "sst/constructs";
17
17
  *
18
18
  * export function MyStack({ stack }: StackContext) {
19
19
  * // Define your stack
@@ -273,7 +273,7 @@ export interface StaticSiteCdkDistributionProps extends BaseSiteCdkDistributionP
273
273
  * Deploys a plain HTML website in the `path/to/src` directory.
274
274
  *
275
275
  * ```js
276
- * import { StaticSite } from "@serverless-stack/resources";
276
+ * import { StaticSite } from "sst/constructs";
277
277
  *
278
278
  * new StaticSite(stack, "Site", {
279
279
  * path: "path/to/src",
@@ -34,7 +34,7 @@ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
34
34
  * Deploys a plain HTML website in the `path/to/src` directory.
35
35
  *
36
36
  * ```js
37
- * import { StaticSite } from "@serverless-stack/resources";
37
+ * import { StaticSite } from "sst/constructs";
38
38
  *
39
39
  * new StaticSite(stack, "Site", {
40
40
  * path: "path/to/src",
@@ -259,7 +259,7 @@ export interface TableProps {
259
259
  * Deploys a plain HTML website in the `path/to/src` directory.
260
260
  *
261
261
  * ```js
262
- * import { Table } from "@serverless-stack/resources";
262
+ * import { Table } from "sst/constructs";
263
263
  *
264
264
  * new Table(stack, "Notes", {
265
265
  * fields: {
@@ -15,7 +15,7 @@ import { Function as Fn, } from "./Function.js";
15
15
  * Deploys a plain HTML website in the `path/to/src` directory.
16
16
  *
17
17
  * ```js
18
- * import { Table } from "@serverless-stack/resources";
18
+ * import { Table } from "sst/constructs";
19
19
  *
20
20
  * new Table(stack, "Notes", {
21
21
  * fields: {
@@ -117,7 +117,7 @@ export interface TopicProps {
117
117
  * @example
118
118
  *
119
119
  * ```js
120
- * import { Topic } from "@serverless-stack/resources";
120
+ * import { Topic } from "sst/constructs";
121
121
  *
122
122
  * new Topic(stack, "Topic", {
123
123
  * subscribers: {
@@ -13,7 +13,7 @@ import { Queue } from "./Queue.js";
13
13
  * @example
14
14
  *
15
15
  * ```js
16
- * import { Topic } from "@serverless-stack/resources";
16
+ * import { Topic } from "sst/constructs";
17
17
  *
18
18
  * new Topic(stack, "Topic", {
19
19
  * subscribers: {
@@ -202,7 +202,7 @@ export interface WebSocketApiCdkStageProps extends Omit<apig.WebSocketStageProps
202
202
  *
203
203
  * @example
204
204
  * ```js
205
- * import { WebSocketApi } from "@serverless-stack/resources";
205
+ * import { WebSocketApi } from "sst/constructs";
206
206
  *
207
207
  * new WebSocketApi(stack, "Api", {
208
208
  * routes: {
@@ -18,7 +18,7 @@ import * as apigV2AccessLog from "./util/apiGatewayV2AccessLog.js";
18
18
  *
19
19
  * @example
20
20
  * ```js
21
- * import { WebSocketApi } from "@serverless-stack/resources";
21
+ * import { WebSocketApi } from "sst/constructs";
22
22
  *
23
23
  * new WebSocketApi(stack, "Api", {
24
24
  * routes: {
@@ -55,7 +55,7 @@ export interface ApiAttachmentProps {
55
55
  * SST Auth is a lightweight authentication solution for your applications. With a simple set of configuration you can deploy a function attached to your API that can handle various authentication flows. *
56
56
  * @example
57
57
  * ```
58
- * import { Auth } from "@serverless-stack/resources"
58
+ * import { Auth } from "sst/constructs"
59
59
  *
60
60
  * new Auth(stack, "auth", {
61
61
  * authenticator: "functions/authenticator.handler"
@@ -9,7 +9,7 @@ import { CustomResource } from "aws-cdk-lib";
9
9
  * SST Auth is a lightweight authentication solution for your applications. With a simple set of configuration you can deploy a function attached to your API that can handle various authentication flows. *
10
10
  * @example
11
11
  * ```
12
- * import { Auth } from "@serverless-stack/resources"
12
+ * import { Auth } from "sst/constructs"
13
13
  *
14
14
  * new Auth(stack, "auth", {
15
15
  * authenticator: "functions/authenticator.handler"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.5.4",
3
+ "version": "2.5.6",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },
package/project.d.ts CHANGED
@@ -33,6 +33,7 @@ interface Project {
33
33
  }>;
34
34
  version: string;
35
35
  cdkVersion: string;
36
+ constructsVersion: string;
36
37
  paths: {
37
38
  root: string;
38
39
  config: string;
@@ -55,4 +56,10 @@ interface GlobalOptions {
55
56
  region?: string;
56
57
  }
57
58
  export declare function initProject(globals: GlobalOptions): Promise<void>;
59
+ declare function sanitizeStageName(stage: string): string;
60
+ declare function isValidStageName(stage: string): boolean;
61
+ export declare const exportedForTesting: {
62
+ sanitizeStageName: typeof sanitizeStageName;
63
+ isValidStageName: typeof isValidStageName;
64
+ };
58
65
  export {};
package/project.js CHANGED
@@ -47,12 +47,16 @@ export async function initProject(globals) {
47
47
  config.stage ||
48
48
  (await usePersonalStage(out)) ||
49
49
  (await promptPersonalStage(out));
50
- const [version, cdkVersion] = await (async () => {
50
+ const [version, cdkVersion, constructsVersion] = await (async () => {
51
51
  try {
52
52
  const packageJson = JSON.parse(await fs
53
53
  .readFile(url.fileURLToPath(new URL("./package.json", import.meta.url)))
54
54
  .then((x) => x.toString()));
55
- return [packageJson.version, packageJson.dependencies["aws-cdk-lib"]];
55
+ return [
56
+ packageJson.version,
57
+ packageJson.dependencies["aws-cdk-lib"],
58
+ packageJson.dependencies["constructs"],
59
+ ];
56
60
  }
57
61
  catch {
58
62
  return ["unknown", "unknown"];
@@ -61,6 +65,7 @@ export async function initProject(globals) {
61
65
  const project = {
62
66
  version,
63
67
  cdkVersion,
68
+ constructsVersion,
64
69
  config: {
65
70
  ...config,
66
71
  stage,
@@ -112,21 +117,29 @@ async function usePersonalStage(out) {
112
117
  return;
113
118
  }
114
119
  }
115
- async function promptPersonalStage(out) {
120
+ async function promptPersonalStage(out, isRetry) {
116
121
  const readline = await import("readline");
117
122
  const rl = readline.createInterface({
118
123
  input: process.stdin,
119
124
  output: process.stdout,
120
125
  });
121
- return new Promise((resolve) => {
122
- const suggested = os.userInfo().username;
123
- rl.question(`Please enter a name you’d like to use for your personal stage. Or hit enter to use ${blue(suggested)}: `, async (input) => {
126
+ const stage = await new Promise((resolve) => {
127
+ const suggested = sanitizeStageName(os.userInfo().username) || "local";
128
+ const instruction = !isRetry
129
+ ? `Please enter a name you’d like to use for your personal stage.`
130
+ : `Please enter a name that starts with a letter, followed by letters, numbers, or hyphens.`;
131
+ rl.question(`${instruction} Or hit enter to use ${blue(suggested)}: `, async (input) => {
124
132
  rl.close();
125
- const result = input || suggested;
126
- await fs.writeFile(path.join(out, "stage"), result);
133
+ const result = input === "" ? suggested : input;
127
134
  resolve(result);
128
135
  });
129
136
  });
137
+ // Validate stage name
138
+ if (isValidStageName(stage)) {
139
+ await fs.writeFile(path.join(out, "stage"), stage);
140
+ return stage;
141
+ }
142
+ return await promptPersonalStage(out, true);
130
143
  }
131
144
  async function findRoot() {
132
145
  async function find(dir) {
@@ -143,3 +156,17 @@ async function findRoot() {
143
156
  const result = await find(process.cwd());
144
157
  return result;
145
158
  }
159
+ function sanitizeStageName(stage) {
160
+ return (stage
161
+ .replace(/[^A-Za-z0-9-]/g, "-")
162
+ .replace(/--+/g, "-")
163
+ .replace(/^[^A-Za-z]/, "")
164
+ .replace(/-$/, "") || "local");
165
+ }
166
+ function isValidStageName(stage) {
167
+ return Boolean(stage.match(/^[A-Za-z][A-Za-z0-9-]*$/));
168
+ }
169
+ export const exportedForTesting = {
170
+ sanitizeStageName,
171
+ isValidStageName,
172
+ };