sst 2.0.0-rc.9 → 2.0.0

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 (242) hide show
  1. package/bootstrap.d.ts +2 -4
  2. package/bootstrap.js +208 -61
  3. package/bus.d.ts +3 -3
  4. package/bus.js +1 -1
  5. package/cache.js +1 -1
  6. package/cdk/cloudformation-deployments-wrapper.d.ts +3 -0
  7. package/cdk/cloudformation-deployments-wrapper.js +117 -0
  8. package/cdk/cloudformation-deployments.d.ts +19 -4
  9. package/cdk/deploy-stack.d.ts +17 -2
  10. package/cdk/deploy-stack.js +6 -1
  11. package/cli/colors.d.ts +28 -0
  12. package/cli/colors.js +27 -0
  13. package/cli/commands/bind.d.ts +4 -0
  14. package/cli/commands/bind.js +10 -7
  15. package/cli/commands/bootstrap.d.ts +13 -0
  16. package/cli/commands/bootstrap.js +11 -0
  17. package/cli/commands/build.d.ts +6 -2
  18. package/cli/commands/build.js +13 -8
  19. package/cli/commands/console.d.ts +5 -1
  20. package/cli/commands/console.js +8 -6
  21. package/cli/commands/deploy.d.ts +4 -2
  22. package/cli/commands/deploy.js +69 -29
  23. package/cli/commands/dev.d.ts +5 -1
  24. package/cli/commands/dev.js +157 -79
  25. package/cli/commands/diff.d.ts +15 -0
  26. package/cli/commands/diff.js +61 -0
  27. package/cli/commands/env.d.ts +5 -1
  28. package/cli/commands/env.js +14 -15
  29. package/cli/commands/plugins/kysely.js +13 -5
  30. package/cli/commands/plugins/pothos.js +9 -4
  31. package/cli/commands/remove.d.ts +4 -0
  32. package/cli/commands/remove.js +26 -18
  33. package/cli/commands/secrets/get.d.ts +7 -3
  34. package/cli/commands/secrets/get.js +11 -24
  35. package/cli/commands/secrets/list.d.ts +6 -2
  36. package/cli/commands/secrets/list.js +15 -7
  37. package/cli/commands/secrets/remove.d.ts +8 -4
  38. package/cli/commands/secrets/remove.js +18 -16
  39. package/cli/commands/secrets/secrets.js +3 -3
  40. package/cli/commands/secrets/set.d.ts +8 -6
  41. package/cli/commands/secrets/set.js +16 -33
  42. package/cli/commands/telemetry.d.ts +15 -0
  43. package/cli/commands/telemetry.js +17 -0
  44. package/cli/commands/transform.d.ts +15 -0
  45. package/cli/commands/transform.js +55 -0
  46. package/cli/commands/update.d.ts +6 -2
  47. package/cli/commands/update.js +41 -33
  48. package/cli/commands/version.d.ts +13 -0
  49. package/cli/commands/version.js +7 -0
  50. package/cli/local/router.d.ts +6 -6
  51. package/cli/local/router.js +3 -3
  52. package/cli/local/server.d.ts +5 -3
  53. package/cli/local/server.js +21 -14
  54. package/cli/program.d.ts +5 -1
  55. package/cli/program.js +29 -5
  56. package/cli/spinner.js +2 -0
  57. package/cli/sst.js +35 -23
  58. package/cli/telemetry/environment.d.ts +1 -1
  59. package/cli/telemetry/environment.js +1 -1
  60. package/cli/terminal.d.ts +1 -0
  61. package/cli/terminal.js +8 -0
  62. package/cli/ui/deploy.d.ts +3 -2
  63. package/cli/ui/deploy.js +106 -106
  64. package/cli/ui/functions.d.ts +2 -0
  65. package/cli/ui/functions.js +132 -0
  66. package/cli/ui/header.d.ts +5 -0
  67. package/cli/ui/header.js +16 -0
  68. package/cli/ui/stack.d.ts +1 -0
  69. package/cli/ui/stack.js +6 -0
  70. package/config.d.ts +1 -1
  71. package/config.js +8 -8
  72. package/constructs/Api.d.ts +3 -71
  73. package/constructs/Api.js +3 -42
  74. package/constructs/ApiGatewayV1Api.d.ts +3 -3
  75. package/constructs/ApiGatewayV1Api.js +4 -3
  76. package/constructs/App.d.ts +2 -22
  77. package/constructs/App.js +12 -25
  78. package/constructs/AppSyncApi.d.ts +4 -5
  79. package/constructs/AppSyncApi.js +8 -5
  80. package/constructs/AstroSite.d.ts +2 -3
  81. package/constructs/AstroSite.js +43 -53
  82. package/constructs/Auth.js +27 -16
  83. package/constructs/BaseSite.d.ts +10 -10
  84. package/constructs/BaseSite.js +2 -2
  85. package/constructs/Cognito.js +28 -28
  86. package/constructs/EdgeFunction.d.ts +6 -4
  87. package/constructs/EdgeFunction.js +56 -59
  88. package/constructs/EventBus.js +1 -1
  89. package/constructs/Function.d.ts +4 -44
  90. package/constructs/Function.js +14 -50
  91. package/constructs/FunctionalStack.d.ts +2 -2
  92. package/constructs/Job.d.ts +23 -63
  93. package/constructs/Job.js +11 -32
  94. package/constructs/Metadata.d.ts +18 -20
  95. package/constructs/NextjsSite.d.ts +21 -5
  96. package/constructs/NextjsSite.js +67 -101
  97. package/constructs/Queue.js +10 -10
  98. package/constructs/RDS.d.ts +1 -1
  99. package/constructs/RDS.js +1 -1
  100. package/constructs/RemixSite.d.ts +0 -2
  101. package/constructs/RemixSite.js +20 -20
  102. package/constructs/Script.js +1 -1
  103. package/constructs/Secret.js +5 -3
  104. package/constructs/SolidStartSite.d.ts +2 -3
  105. package/constructs/SolidStartSite.js +42 -52
  106. package/constructs/SsrFunction.d.ts +22 -0
  107. package/constructs/SsrFunction.js +113 -0
  108. package/constructs/SsrSite.d.ts +104 -104
  109. package/constructs/SsrSite.js +196 -217
  110. package/constructs/Stack.d.ts +1 -20
  111. package/constructs/Stack.js +3 -65
  112. package/constructs/StaticSite.d.ts +33 -53
  113. package/constructs/StaticSite.js +92 -118
  114. package/constructs/Table.d.ts +1 -1
  115. package/constructs/Table.js +4 -4
  116. package/constructs/Topic.js +1 -1
  117. package/constructs/cdk/certificate-base.d.ts +18 -0
  118. package/constructs/cdk/certificate-base.js +26 -0
  119. package/constructs/cdk/dns-validated-certificate.d.ts +77 -0
  120. package/constructs/cdk/dns-validated-certificate.js +125 -0
  121. package/constructs/cdk/website-redirect.d.ts +53 -0
  122. package/constructs/cdk/website-redirect.js +77 -0
  123. package/constructs/deferred_task.d.ts +1 -1
  124. package/constructs/deprecated/NextjsSite.js +8 -6
  125. package/constructs/index.d.ts +0 -6
  126. package/constructs/index.js +0 -6
  127. package/constructs/util/apiGatewayV1AccessLog.d.ts +1 -1
  128. package/constructs/util/apiGatewayV2AccessLog.js +4 -4
  129. package/constructs/util/apiGatewayV2Domain.js +9 -2
  130. package/constructs/util/appSyncApiDomain.d.ts +1 -1
  131. package/constructs/util/appSyncApiDomain.js +9 -15
  132. package/constructs/util/duration.d.ts +1 -1
  133. package/constructs/util/functionBinding.js +1 -1
  134. package/constructs/util/permission.d.ts +3 -3
  135. package/constructs/util/permission.js +16 -18
  136. package/constructs/util/size.d.ts +1 -1
  137. package/constructs/util/warning.js +2 -2
  138. package/context/context.d.ts +2 -2
  139. package/context/context.js +4 -4
  140. package/context/handler.d.ts +1 -1
  141. package/credentials.d.ts +1 -1
  142. package/credentials.js +42 -6
  143. package/index.d.ts +1 -0
  144. package/index.js +1 -0
  145. package/iot.js +6 -2
  146. package/logger.js +3 -1
  147. package/node/api/index.d.ts +2 -3
  148. package/node/api/index.js +8 -2
  149. package/node/auth/adapter/adapter.d.ts +1 -1
  150. package/node/auth/adapter/facebook.js +1 -1
  151. package/node/auth/adapter/github.js +4 -4
  152. package/node/auth/adapter/google.d.ts +1 -1
  153. package/node/auth/adapter/google.js +2 -2
  154. package/node/auth/adapter/twitch.js +1 -1
  155. package/node/auth/session.d.ts +1 -1
  156. package/node/config/index.d.ts +2 -2
  157. package/node/config/index.js +3 -8
  158. package/node/job/index.d.ts +2 -2
  159. package/node/site/index.js +3 -5
  160. package/package.json +26 -21
  161. package/pothos.js +1 -0
  162. package/project.d.ts +47 -0
  163. package/{app.js → project.js} +60 -53
  164. package/runtime/handlers/dotnet.d.ts +1 -1
  165. package/runtime/handlers/dotnet.js +4 -4
  166. package/runtime/handlers/go.d.ts +1 -1
  167. package/runtime/handlers/go.js +3 -3
  168. package/runtime/handlers/java.d.ts +1 -1
  169. package/runtime/handlers/java.js +4 -4
  170. package/runtime/handlers/node.d.ts +1 -1
  171. package/runtime/handlers/node.js +60 -39
  172. package/runtime/handlers/python.d.ts +1 -1
  173. package/runtime/handlers/python.js +3 -3
  174. package/runtime/handlers.js +15 -12
  175. package/runtime/iot.js +3 -0
  176. package/runtime/runtime.d.ts +4 -0
  177. package/runtime/server.d.ts +3 -3
  178. package/runtime/server.js +11 -5
  179. package/runtime/workers.d.ts +4 -2
  180. package/runtime/workers.js +13 -3
  181. package/site-env.js +2 -1
  182. package/sst.mjs +6357 -20848
  183. package/stacks/app-metadata.d.ts +7 -0
  184. package/stacks/app-metadata.js +78 -0
  185. package/stacks/assembly.d.ts +1 -0
  186. package/stacks/assembly.js +4 -0
  187. package/stacks/build.d.ts +1 -1
  188. package/stacks/build.js +41 -48
  189. package/stacks/deploy.d.ts +1 -0
  190. package/stacks/deploy.js +128 -7
  191. package/stacks/diff.d.ts +8 -0
  192. package/stacks/diff.js +62 -0
  193. package/stacks/index.d.ts +3 -0
  194. package/stacks/index.js +3 -0
  195. package/stacks/metadata.d.ts +2 -0
  196. package/stacks/metadata.js +14 -12
  197. package/stacks/monitor.d.ts +8 -3
  198. package/stacks/monitor.js +38 -4
  199. package/stacks/remove.js +0 -4
  200. package/stacks/synth.d.ts +1 -0
  201. package/stacks/synth.js +27 -13
  202. package/support/base-site-archiver.mjs +1 -1
  203. package/support/bootstrap-metadata-function/index.mjs +68740 -0
  204. package/support/bridge/bridge.mjs +28 -28
  205. package/support/certificate-requestor/index.js +549 -0
  206. package/support/custom-resources/index.mjs +3824 -26567
  207. package/support/dotnet6-bootstrap/release/dotnet-bootstrap.deps.json +1 -1
  208. package/support/dotnet6-bootstrap/release/dotnet-bootstrap.runtimeconfig.json +1 -1
  209. package/support/edge-function/edge-lambda.mjs +2 -2
  210. package/support/job-invoker/index.mjs +26 -0
  211. package/support/nodejs-runtime/index.mjs +75 -72
  212. package/support/rds-migrator/index.mjs +22 -23
  213. package/support/remix-site-function/edge-server.js +1 -1
  214. package/support/script-function/index.mjs +30485 -0
  215. package/support/{edge-function-code-replacer → sls-nextjs-site-function-code-replacer}/lambda-code-updater.py +0 -0
  216. package/support/ssr-site-function-archiver.mjs +96 -0
  217. package/watcher.js +1 -1
  218. package/app.d.ts +0 -36
  219. package/constructs/DebugApp.d.ts +0 -49
  220. package/constructs/DebugApp.js +0 -63
  221. package/constructs/DebugStack.d.ts +0 -34
  222. package/constructs/DebugStack.js +0 -132
  223. package/constructs/GraphQLApi.d.ts +0 -98
  224. package/constructs/GraphQLApi.js +0 -80
  225. package/constructs/ReactStaticSite.d.ts +0 -20
  226. package/constructs/ReactStaticSite.js +0 -54
  227. package/constructs/Script/cfn-response.d.ts +0 -19
  228. package/constructs/Script/cfn-response.js +0 -77
  229. package/constructs/Script/index.d.ts +0 -1
  230. package/constructs/Script/index.js +0 -78
  231. package/constructs/Script/outbound.d.ts +0 -10
  232. package/constructs/Script/outbound.js +0 -42
  233. package/constructs/Script/util.d.ts +0 -2
  234. package/constructs/Script/util.js +0 -11
  235. package/constructs/ViteStaticSite.d.ts +0 -32
  236. package/constructs/ViteStaticSite.js +0 -66
  237. package/support/astro-site-html-stub/index.html +0 -99
  238. package/support/base-site-archiver.cjs +0 -116
  239. package/support/nextjs-site-html-stub/index.html +0 -99
  240. package/support/remix-site-html-stub/index.html +0 -99
  241. package/support/solid-start-site-html-stub/index.html +0 -99
  242. package/support/static-site-stub/index.html +0 -90
package/watcher.js CHANGED
@@ -2,7 +2,7 @@ import { Context } from "./context/context.js";
2
2
  import chokidar from "chokidar";
3
3
  import { useBus } from "./bus.js";
4
4
  import path from "path";
5
- import { useProject } from "./app.js";
5
+ import { useProject } from "./project.js";
6
6
  export const useWatcher = Context.memo(() => {
7
7
  const project = useProject();
8
8
  const bus = useBus();
package/app.d.ts DELETED
@@ -1,36 +0,0 @@
1
- export interface Project {
2
- name: string;
3
- region: string;
4
- stage?: string;
5
- profile?: string;
6
- main?: string;
7
- ssmPrefix?: string;
8
- }
9
- declare const DEFAULTS: {
10
- readonly main: "stacks/index.ts";
11
- readonly stage: undefined;
12
- readonly ssmPrefix: undefined;
13
- };
14
- declare type ProjectWithDefaults = Project & Required<{
15
- [key in keyof typeof DEFAULTS]: Exclude<Project[key], undefined>;
16
- }> & {
17
- version: string;
18
- paths: {
19
- root: string;
20
- out: string;
21
- artifacts: string;
22
- };
23
- };
24
- export declare const ProjectContext: {
25
- use(): ProjectWithDefaults;
26
- provide(value: ProjectWithDefaults): void;
27
- };
28
- export declare function useProject(): ProjectWithDefaults;
29
- interface GlobalOptions {
30
- profile?: string;
31
- stage?: string;
32
- root?: string;
33
- region?: string;
34
- }
35
- export declare function initProject(globals: GlobalOptions): Promise<void>;
36
- export {};
@@ -1,49 +0,0 @@
1
- import { App, StageSynthesisOptions } from "aws-cdk-lib";
2
- import { CloudAssembly } from "aws-cdk-lib/cx-api";
3
- /**
4
- * Deploy props for apps.
5
- */
6
- export interface DebugAppDeployProps {
7
- /**
8
- * The app name, used to prefix stacks.
9
- */
10
- name: string;
11
- /**
12
- * The stage to deploy this app to.
13
- */
14
- stage: string;
15
- /**
16
- * The region to deploy this app to.
17
- */
18
- region: string;
19
- }
20
- /**
21
- * The DebugApp construct is used internally by SST to create the resources needed to power Live Lambda Development.
22
- */
23
- export declare class DebugApp extends App {
24
- /**
25
- * The name of the app. This comes from the `name` in your `sst.json`.
26
- */
27
- readonly name: string;
28
- /**
29
- * The stage the app is being deployed to. If this is not specified as the [`--stage`](/packages/sst.md#--stage) option, it'll default to the stage configured during the initial run of the SST CLI.
30
- */
31
- readonly stage: string;
32
- /**
33
- * The region the app is being deployed to. If this is not specified as the [`--region`](/packages/sst.md#--region) option in the SST CLI, it'll default to the `region` in your `sst.json`.
34
- */
35
- readonly region: string;
36
- /**
37
- * The AWS account the app is being deployed to. This comes from the IAM credentials being used to run the SST CLI.
38
- */
39
- readonly account: string;
40
- /**
41
- * @internal
42
- */
43
- constructor(deployProps: DebugAppDeployProps);
44
- synth(options?: StageSynthesisOptions): CloudAssembly;
45
- /**
46
- * Use this method to prefix resource names in your stacks to make sure they don't thrash when deployed to different stages in the same AWS account. This method will prefix a given resource name with the stage and app name. Using the format `${stage}-${name}-${logicalName}`.
47
- */
48
- logicalPrefixedName(logicalName: string): string;
49
- }
@@ -1,63 +0,0 @@
1
- import { App } from "aws-cdk-lib";
2
- import { isStackConstruct, isSSTDebugStack } from "./Construct.js";
3
- /**
4
- * The DebugApp construct is used internally by SST to create the resources needed to power Live Lambda Development.
5
- */
6
- export class DebugApp extends App {
7
- /**
8
- * The name of the app. This comes from the `name` in your `sst.json`.
9
- */
10
- name;
11
- /**
12
- * The stage the app is being deployed to. If this is not specified as the [`--stage`](/packages/sst.md#--stage) option, it'll default to the stage configured during the initial run of the SST CLI.
13
- */
14
- stage;
15
- /**
16
- * The region the app is being deployed to. If this is not specified as the [`--region`](/packages/sst.md#--region) option in the SST CLI, it'll default to the `region` in your `sst.json`.
17
- */
18
- region;
19
- /**
20
- * The AWS account the app is being deployed to. This comes from the IAM credentials being used to run the SST CLI.
21
- */
22
- account;
23
- /**
24
- * @internal
25
- */
26
- constructor(deployProps) {
27
- super();
28
- this.name = deployProps.name;
29
- this.stage = deployProps.stage;
30
- this.region = deployProps.region;
31
- this.account = process.env.CDK_DEFAULT_ACCOUNT || "my-account";
32
- }
33
- synth(options = {}) {
34
- // Check app has stack
35
- const stacks = this.node.children.filter((child) => isSSTDebugStack(child));
36
- if (stacks.length > 1) {
37
- console.error(`Error: You can only create 1 DebugStack inside the "debugApp()" callback.\n`);
38
- process.exit(1);
39
- }
40
- if (stacks.length === 0) {
41
- console.error(`Error: The "debugApp()" callback is not creating a DebugStack.\n`);
42
- process.exit(1);
43
- }
44
- for (const child of this.node.children) {
45
- if (isStackConstruct(child)) {
46
- // Stack names need to be parameterized with the stage name
47
- if (!child.stackName.startsWith(`${this.stage}-`) &&
48
- !child.stackName.endsWith(`-${this.stage}`) &&
49
- child.stackName.indexOf(`-${this.stage}-`) === -1) {
50
- console.error(`Error: Stack "${child.stackName}" is not parameterized with the stage name. The stack name needs to either start with "$stage-", end in "-$stage", or contain the stage name "-$stage-".\n`);
51
- process.exit(1);
52
- }
53
- }
54
- }
55
- return super.synth(options);
56
- }
57
- /**
58
- * Use this method to prefix resource names in your stacks to make sure they don't thrash when deployed to different stages in the same AWS account. This method will prefix a given resource name with the stage and app name. Using the format `${stage}-${name}-${logicalName}`.
59
- */
60
- logicalPrefixedName(logicalName) {
61
- return `${this.stage}-${this.name}-${logicalName}`;
62
- }
63
- }
@@ -1,34 +0,0 @@
1
- import { Construct } from "constructs";
2
- import * as cdk from "aws-cdk-lib";
3
- import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
4
- /**
5
- * Stack properties for the DebugStack.
6
- */
7
- export interface DebugStackProps extends cdk.StackProps {
8
- /**
9
- * S3 bucket to store large websocket payloads.
10
- */
11
- payloadBucketArn?: string;
12
- /**
13
- * Lambda function props for WebSocket request handlers.
14
- */
15
- websocketHandlerRoleArn?: string;
16
- cdk?: {
17
- /**
18
- * Override the settings of the internally created DynamoDB table
19
- */
20
- table?: Omit<dynamodb.TableProps, "partitionKey" | "sortKey">;
21
- };
22
- }
23
- /**
24
- * The `DebugStack` construct is used internally to create the resources needed to power Live Lambda Development. Note that, the `DebugStack` construct should only be created inside the [`DebugApp`](DebugApp).
25
- */
26
- export declare class DebugStack extends cdk.Stack {
27
- readonly stage: string;
28
- private readonly api;
29
- private readonly table;
30
- private readonly bucket;
31
- constructor(scope: Construct, id: string, props?: DebugStackProps);
32
- private addApiRoute;
33
- private static checkForEnvInProps;
34
- }
@@ -1,132 +0,0 @@
1
- import * as path from "path";
2
- import url from "url";
3
- import * as cdk from "aws-cdk-lib";
4
- import * as s3 from "aws-cdk-lib/aws-s3";
5
- import * as iam from "aws-cdk-lib/aws-iam";
6
- import * as logs from "aws-cdk-lib/aws-logs";
7
- import * as lambda from "aws-cdk-lib/aws-lambda";
8
- import * as apig from "aws-cdk-lib/aws-apigatewayv2";
9
- import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
10
- const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
11
- /**
12
- * The `DebugStack` construct is used internally to create the resources needed to power Live Lambda Development. Note that, the `DebugStack` construct should only be created inside the [`DebugApp`](DebugApp).
13
- */
14
- export class DebugStack extends cdk.Stack {
15
- stage;
16
- api;
17
- table;
18
- bucket;
19
- constructor(scope, id, props) {
20
- const app = scope.node.root;
21
- const stackId = app.logicalPrefixedName(id);
22
- DebugStack.checkForEnvInProps(id, props);
23
- super(scope, stackId, {
24
- ...props,
25
- env: {
26
- account: app.account,
27
- region: app.region,
28
- },
29
- });
30
- this.stage = app.stage;
31
- // Create connection table
32
- this.table = new dynamodb.Table(this, "Table", {
33
- partitionKey: { name: "pk", type: dynamodb.AttributeType.STRING },
34
- billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
35
- removalPolicy: cdk.RemovalPolicy.DESTROY,
36
- ...props?.cdk?.table,
37
- });
38
- // Create S3 bucket for storing large payloads
39
- this.bucket = props?.payloadBucketArn
40
- ? s3.Bucket.fromBucketArn(this, "Bucket", props.payloadBucketArn)
41
- : new s3.Bucket(this, "Bucket", {
42
- lifecycleRules: [
43
- {
44
- expiration: cdk.Duration.days(1),
45
- prefix: "payloads/",
46
- },
47
- ],
48
- encryption: s3.BucketEncryption.S3_MANAGED,
49
- removalPolicy: cdk.RemovalPolicy.DESTROY,
50
- autoDeleteObjects: true,
51
- blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
52
- });
53
- // Create API
54
- this.api = new apig.CfnApi(this, "Api", {
55
- name: `${this.stackName}-api`,
56
- protocolType: "WEBSOCKET",
57
- routeSelectionExpression: "$request.body.action",
58
- });
59
- new apig.CfnStage(this, "ApiStage", {
60
- apiId: this.api.ref,
61
- autoDeploy: true,
62
- stageName: this.stage,
63
- });
64
- // Create API routes
65
- const role = props?.websocketHandlerRoleArn
66
- ? iam.Role.fromRoleArn(this, "HandlerRole", props.websocketHandlerRoleArn)
67
- : undefined;
68
- this.addApiRoute("Connect", "$connect", "wsConnect.main", role);
69
- this.addApiRoute("Disconnect", "$disconnect", "wsDisconnect.main", role);
70
- this.addApiRoute("Default", "$default", "wsDefault.main", role);
71
- // Stack Output
72
- new cdk.CfnOutput(this, "Endpoint", {
73
- value: `${this.api.attrApiEndpoint}/${this.stage}`,
74
- });
75
- new cdk.CfnOutput(this, "BucketArn", {
76
- value: this.bucket.bucketArn,
77
- });
78
- new cdk.CfnOutput(this, "BucketName", {
79
- value: this.bucket.bucketName,
80
- });
81
- }
82
- addApiRoute(id, routeKey, handler, role) {
83
- // Create execution policy
84
- const policyStatement = new iam.PolicyStatement();
85
- policyStatement.addAllResources();
86
- policyStatement.addActions("apigateway:*", "dynamodb:*", "execute-api:ManageConnections");
87
- // Create Lambda
88
- const lambdaFunc = new lambda.Function(this, id, {
89
- code: lambda.Code.fromAsset(path.join(__dirname, "../assets/DebugStack")),
90
- handler,
91
- runtime: lambda.Runtime.NODEJS_16_X,
92
- timeout: cdk.Duration.seconds(10),
93
- memorySize: 256,
94
- logRetention: logs.RetentionDays.ONE_WEEK,
95
- logRetentionRole: role,
96
- environment: {
97
- TABLE_NAME: this.table.tableName,
98
- },
99
- role,
100
- initialPolicy: [policyStatement],
101
- });
102
- lambdaFunc.addPermission(`${id}Permission`, {
103
- principal: new iam.ServicePrincipal("apigateway.amazonaws.com"),
104
- });
105
- // Create API integrations
106
- const integration = new apig.CfnIntegration(this, `${id}Integration`, {
107
- apiId: this.api.ref,
108
- integrationType: "AWS_PROXY",
109
- integrationUri: `arn:${this.partition}:apigateway:${this.region}:lambda:path/2015-03-31/functions/${lambdaFunc.functionArn}/invocations`,
110
- });
111
- // Create API routes
112
- new apig.CfnRoute(this, `${id}Route`, {
113
- apiId: this.api.ref,
114
- routeKey,
115
- authorizationType: "NONE",
116
- target: `integrations/${integration.ref}`,
117
- });
118
- }
119
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
- static checkForEnvInProps(id, props) {
121
- if (props && props.env) {
122
- let envS = "";
123
- try {
124
- envS = " (" + JSON.stringify(props.env) + ")";
125
- }
126
- catch (e) {
127
- // Ignore
128
- }
129
- throw new Error(`Do not set the "env" prop while initializing "${id}" stack${envS}. Use the "AWS_PROFILE" environment variable and "--region" CLI option instead.`);
130
- }
131
- }
132
- }
@@ -1,98 +0,0 @@
1
- import { HttpRouteIntegration } from "@aws-cdk/aws-apigatewayv2-alpha";
2
- import { Construct } from "constructs";
3
- import { Api, ApiFunctionRouteProps, ApiProps } from "./Api.js";
4
- import { Function as Fn, FunctionDefinition } from "./Function.js";
5
- export interface GraphQLApiProps extends Omit<ApiProps, "routes"> {
6
- /**
7
- * Path to graphql-codegen configuration file
8
- *
9
- * @example
10
- * ```js
11
- * new GraphQLApi(stack, "api", {
12
- * codegen: "./graphql/codegen.yml"
13
- * })
14
- * ```
15
- */
16
- codegen?: string;
17
- /**
18
- * Path to function that will be invoked to resolve GraphQL queries.
19
- *
20
- * @example
21
- * ```js
22
- * new GraphQLApi(stack, "api", {
23
- * codegen: "./graphql/codegen.yml"
24
- * })
25
- * ```
26
- */
27
- server: FunctionDefinition;
28
- rootPath?: string;
29
- }
30
- /**
31
- * The `GraphQLApi` construct is a higher level CDK construct that makes it easy to create GraphQL servers with AWS Lambda.
32
- *
33
- * @example
34
- *
35
- * ```js
36
- * import { GraphQLApi } from "@serverless-stack/resources";
37
- *
38
- * new GraphQLApi(stack, "Api", {
39
- * server: "src/graphql.handler",
40
- * });
41
- * ```
42
- */
43
- export declare class GraphQLApi extends Api {
44
- private readonly codegen?;
45
- private lambdaIntegration?;
46
- private rootPath?;
47
- constructor(scope: Construct, id: string, props: GraphQLApiProps);
48
- get serverFunction(): Fn;
49
- protected createFunctionIntegration(scope: Construct, routeKey: string, routeProps: ApiFunctionRouteProps<string>, postfixName: string): HttpRouteIntegration;
50
- getConstructMetadata(): {
51
- data: {
52
- graphql: true;
53
- codegen: string | undefined;
54
- url: string | undefined;
55
- httpApiId: string;
56
- customDomainUrl: string | undefined;
57
- routes: ({
58
- type: "function";
59
- route: string;
60
- fn: {
61
- node: string;
62
- stack: string;
63
- } | undefined;
64
- schema?: undefined;
65
- output?: undefined;
66
- commands?: undefined;
67
- } | {
68
- type: "pothos";
69
- route: string;
70
- fn: {
71
- node: string;
72
- stack: string;
73
- } | undefined;
74
- schema: string | undefined;
75
- output: string | undefined;
76
- commands: string[] | undefined;
77
- } | {
78
- type: "graphql";
79
- route: string;
80
- fn: {
81
- node: string;
82
- stack: string;
83
- } | undefined;
84
- schema: string | undefined;
85
- output: string | undefined;
86
- commands: string[] | undefined;
87
- } | {
88
- type: "lambda_function" | "url" | "alb";
89
- route: string;
90
- fn?: undefined;
91
- schema?: undefined;
92
- output?: undefined;
93
- commands?: undefined;
94
- })[];
95
- };
96
- type: "Api";
97
- };
98
- }
@@ -1,80 +0,0 @@
1
- import { App } from "./App.js";
2
- import spawn from "cross-spawn";
3
- import { Api } from "./Api.js";
4
- /**
5
- * The `GraphQLApi` construct is a higher level CDK construct that makes it easy to create GraphQL servers with AWS Lambda.
6
- *
7
- * @example
8
- *
9
- * ```js
10
- * import { GraphQLApi } from "@serverless-stack/resources";
11
- *
12
- * new GraphQLApi(stack, "Api", {
13
- * server: "src/graphql.handler",
14
- * });
15
- * ```
16
- */
17
- export class GraphQLApi extends Api {
18
- codegen;
19
- lambdaIntegration;
20
- rootPath;
21
- constructor(scope, id, props) {
22
- if ("routes" in props || !props.server) {
23
- throw new Error(`Please use the "server" option instead of the "routes" to configure the handler for the "${id}" GraphQLApi`);
24
- }
25
- if (props.codegen) {
26
- const app = App.of(scope);
27
- if (!app.local) {
28
- const result = spawn.sync("npx", ["graphql-codegen", "-c", props.codegen], {
29
- stdio: "inherit",
30
- });
31
- if (result.status !== 0) {
32
- throw new Error(`Failed to generate the schema for the "${id}" GraphQLApi`);
33
- }
34
- }
35
- }
36
- const rootPath = props.rootPath || "/";
37
- super(scope, id, {
38
- ...props,
39
- routes: {
40
- [`GET ${rootPath}`]: { function: props.server },
41
- [`POST ${rootPath}`]: { function: props.server },
42
- },
43
- });
44
- this.rootPath = rootPath;
45
- this.codegen = props.codegen;
46
- }
47
- get serverFunction() {
48
- const serverFn = this.getFunction(`GET ${this.rootPath}`);
49
- // This should never happen
50
- if (!serverFn) {
51
- throw new Error(`Failed to get "serverFunction" in the "${this.node.id}" GraphQLApi`);
52
- }
53
- return serverFn;
54
- }
55
- // Note: We want to create 1 Lambda handling both the GET and POST request.
56
- // This design is based on this discussion on GitHub
57
- // https://github.com/serverless-stack/sst/issues/601
58
- // Also Note: We cannot use the "ANY /" route because if authorization
59
- // were provided, the OPTIONS route will be protected. This
60
- // causes CORS to fail.
61
- // Solution: We will override the createFunctionIntegration() function, and
62
- // it will re-use the same Route Integration for all routes.
63
- createFunctionIntegration(scope, routeKey, routeProps, postfixName) {
64
- if (!this.lambdaIntegration) {
65
- this.lambdaIntegration = super.createFunctionIntegration(scope, routeKey, routeProps, postfixName);
66
- }
67
- return this.lambdaIntegration;
68
- }
69
- getConstructMetadata() {
70
- const parent = super.getConstructMetadata();
71
- return {
72
- ...parent,
73
- data: {
74
- ...parent.data,
75
- graphql: true,
76
- codegen: this.codegen,
77
- },
78
- };
79
- }
80
- }
@@ -1,20 +0,0 @@
1
- import { Construct } from "constructs";
2
- import { StaticSite, StaticSiteProps } from "./StaticSite.js";
3
- import { SSTConstruct } from "./Construct.js";
4
- export declare type ReactStaticSiteProps = StaticSiteProps;
5
- /**
6
- * The `ReactStaticSite` construct is a higher level CDK construct that makes it easy to create a React single page app.
7
- *
8
- * @example
9
- *
10
- * Deploys a Create React App in the `path/to/src` directory.
11
- *
12
- * ```js
13
- * new ReactStaticSite(stack, "ReactSite", {
14
- * path: "path/to/src",
15
- * });
16
- * ```
17
- */
18
- export declare class ReactStaticSite extends StaticSite implements SSTConstruct {
19
- constructor(scope: Construct, id: string, props: ReactStaticSiteProps);
20
- }
@@ -1,54 +0,0 @@
1
- import * as path from "path";
2
- import fs from "fs";
3
- import { StaticSite } from "./StaticSite.js";
4
- /////////////////////
5
- // Construct
6
- /////////////////////
7
- /**
8
- * The `ReactStaticSite` construct is a higher level CDK construct that makes it easy to create a React single page app.
9
- *
10
- * @example
11
- *
12
- * Deploys a Create React App in the `path/to/src` directory.
13
- *
14
- * ```js
15
- * new ReactStaticSite(stack, "ReactSite", {
16
- * path: "path/to/src",
17
- * });
18
- * ```
19
- */
20
- export class ReactStaticSite extends StaticSite {
21
- constructor(scope, id, props) {
22
- const { path: sitePath, environment } = props || {};
23
- // Validate environment
24
- Object.keys(environment || {}).forEach((key) => {
25
- if (!key.startsWith("REACT_APP_")) {
26
- throw new Error(`Environment variables in the "${id}" ReactStaticSite must start with "REACT_APP_".`);
27
- }
28
- });
29
- // generate buildCommand
30
- let defaultBuildCommand = "npm run build";
31
- if (fs.existsSync(path.join(sitePath, "yarn.lock"))) {
32
- defaultBuildCommand = "yarn build";
33
- }
34
- super(scope, id, {
35
- indexPage: "index.html",
36
- errorPage: "redirect_to_index_page",
37
- buildCommand: defaultBuildCommand,
38
- buildOutput: "build",
39
- fileOptions: [
40
- {
41
- exclude: "*",
42
- include: "*.html",
43
- cacheControl: "max-age=0,no-cache,no-store,must-revalidate",
44
- },
45
- {
46
- exclude: "*",
47
- include: ["*.js", "*.css"],
48
- cacheControl: "max-age=31536000,public,immutable",
49
- },
50
- ],
51
- ...props,
52
- });
53
- }
54
- }
@@ -1,19 +0,0 @@
1
- export declare const CREATE_FAILED_PHYSICAL_ID_MARKER = "AWSCDK::CustomResourceProviderFramework::CREATE_FAILED";
2
- export declare const MISSING_PHYSICAL_ID_MARKER = "AWSCDK::CustomResourceProviderFramework::MISSING_PHYSICAL_ID";
3
- export interface CloudFormationResponseOptions {
4
- readonly reason?: string;
5
- readonly noEcho?: boolean;
6
- }
7
- export interface CloudFormationEventContext {
8
- StackId: string;
9
- RequestId: string;
10
- PhysicalResourceId?: string;
11
- LogicalResourceId: string;
12
- ResponseURL: string;
13
- Data?: any;
14
- }
15
- export declare function submitResponse(status: "SUCCESS" | "FAILED", event: CloudFormationEventContext, options?: CloudFormationResponseOptions): Promise<void>;
16
- export declare const includeStackTraces = true;
17
- export declare function safeHandler(block: (event: any) => Promise<void>): (event: any) => Promise<void>;
18
- export declare class Retry extends Error {
19
- }
@@ -1,77 +0,0 @@
1
- /* eslint-disable max-len */
2
- /* eslint-disable no-console */
3
- import url from "url";
4
- import { httpRequest } from "./outbound.js";
5
- import { log } from "./util.js";
6
- export const CREATE_FAILED_PHYSICAL_ID_MARKER = "AWSCDK::CustomResourceProviderFramework::CREATE_FAILED";
7
- export const MISSING_PHYSICAL_ID_MARKER = "AWSCDK::CustomResourceProviderFramework::MISSING_PHYSICAL_ID";
8
- export async function submitResponse(status, event, options = {}) {
9
- const json = {
10
- Status: status,
11
- Reason: options.reason || status,
12
- StackId: event.StackId,
13
- RequestId: event.RequestId,
14
- PhysicalResourceId: event.PhysicalResourceId || MISSING_PHYSICAL_ID_MARKER,
15
- LogicalResourceId: event.LogicalResourceId,
16
- NoEcho: options.noEcho,
17
- Data: event.Data,
18
- };
19
- log("submit response to cloudformation", json);
20
- const responseBody = JSON.stringify(json);
21
- const parsedUrl = url.parse(event.ResponseURL);
22
- await httpRequest({
23
- hostname: parsedUrl.hostname,
24
- path: parsedUrl.path,
25
- method: "PUT",
26
- headers: {
27
- "content-type": "",
28
- "content-length": responseBody.length,
29
- },
30
- }, responseBody);
31
- }
32
- export const includeStackTraces = true; // for unit tests
33
- export function safeHandler(block) {
34
- return async (event) => {
35
- // ignore DELETE event when the physical resource ID is the marker that
36
- // indicates that this DELETE is a subsequent DELETE to a failed CREATE
37
- // operation.
38
- if (event.RequestType === "Delete" &&
39
- event.PhysicalResourceId === CREATE_FAILED_PHYSICAL_ID_MARKER) {
40
- log("ignoring DELETE event caused by a failed CREATE event");
41
- await submitResponse("SUCCESS", event);
42
- return;
43
- }
44
- try {
45
- await block(event);
46
- }
47
- catch (e) {
48
- // tell waiter state machine to retry
49
- if (e instanceof Retry) {
50
- log("retry requested by handler");
51
- throw e;
52
- }
53
- if (!event.PhysicalResourceId) {
54
- // special case: if CREATE fails, which usually implies, we usually don't
55
- // have a physical resource id. in this case, the subsequent DELETE
56
- // operation does not have any meaning, and will likely fail as well. to
57
- // address this, we use a marker so the provider framework can simply
58
- // ignore the subsequent DELETE.
59
- if (event.RequestType === "Create") {
60
- log("CREATE failed, responding with a marker physical resource id so that the subsequent DELETE will be ignored");
61
- event.PhysicalResourceId = CREATE_FAILED_PHYSICAL_ID_MARKER;
62
- }
63
- else {
64
- // otherwise, if PhysicalResourceId is not specified, something is
65
- // terribly wrong because all other events should have an ID.
66
- log(`ERROR: Malformed event. "PhysicalResourceId" is required: ${JSON.stringify(event)}`);
67
- }
68
- }
69
- // this is an actual error, fail the activity altogether and exist.
70
- await submitResponse("FAILED", event, {
71
- reason: includeStackTraces ? e.stack : e.message,
72
- });
73
- }
74
- };
75
- }
76
- export class Retry extends Error {
77
- }
@@ -1 +0,0 @@
1
- export declare const handler: (event: any) => Promise<void>;