From 5c10f3276a98129d5b788f2e5ab77ae4600dc5f1 Mon Sep 17 00:00:00 2001 From: Daniel Naab Date: Fri, 27 Oct 2023 15:10:48 -0500 Subject: [PATCH] Initial form and AWS lambda backend * Update infra dependencies * Remove Astro from root package.json * Update dependencies * Split Docassemble out of AppStack; rename root ID, to avoid resource naming restrictions (names that start with a number) * Add AWS lambda for a forms service backend. * Wire a sample HTML form to the lambda form service backend. * Remove layout from page components. --- apps/cli/package.json | 2 +- apps/form-service/.gitignore | 1 + apps/form-service/package.json | 18 + apps/form-service/src/index.ts | 33 + apps/form-service/tsconfig.json | 16 + apps/spotlight/package.json | 5 +- .../spotlight/src/layouts/ContentLayout.astro | 28 + apps/spotlight/src/layouts/Layout.astro | 38 +- apps/spotlight/src/pages/form-sample.astro | 31 + apps/spotlight/src/pages/index.astro | 33 +- infra/package.json | 12 +- infra/src/app-stack.ts | 82 +- infra/src/docassemble.ts | 85 + infra/src/form-service.ts | 82 + infra/src/index.ts | 2 +- package.json | 16 +- packages/dependency-graph/package.json | 2 +- packages/design/package.json | 2 +- packages/docassemble/package.json | 2 +- pnpm-lock.yaml | 1645 ++++++----------- 20 files changed, 890 insertions(+), 1245 deletions(-) create mode 100644 apps/form-service/.gitignore create mode 100644 apps/form-service/package.json create mode 100644 apps/form-service/src/index.ts create mode 100644 apps/form-service/tsconfig.json create mode 100644 apps/spotlight/src/layouts/ContentLayout.astro create mode 100644 apps/spotlight/src/pages/form-sample.astro create mode 100644 infra/src/docassemble.ts create mode 100644 infra/src/form-service.ts diff --git a/apps/cli/package.json b/apps/cli/package.json index 18475c53..d908cfc2 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -13,6 +13,6 @@ "@atj/interviews": "workspace:*", "@atj/dependency-graph": "workspace:*", "@atj/docassemble": "workspace:*", - "commander": "^11.0.0" + "commander": "^11.1.0" } } diff --git a/apps/form-service/.gitignore b/apps/form-service/.gitignore new file mode 100644 index 00000000..849ddff3 --- /dev/null +++ b/apps/form-service/.gitignore @@ -0,0 +1 @@ +dist/ diff --git a/apps/form-service/package.json b/apps/form-service/package.json new file mode 100644 index 00000000..abf8d1b2 --- /dev/null +++ b/apps/form-service/package.json @@ -0,0 +1,18 @@ +{ + "name": "@atj/form-service", + "private": true, + "description": "backend service for handling submitted forms", + "main": "src/index.ts", + "scripts": { + "build": "esbuild src/index.ts --bundle --minify --sourcemap --platform=node --target=es2020 --outfile=dist/index.js", + "build:client": "tsup src/* --env.NODE_ENV production --dts-resolve", + "clean": "rm -rf dist tsconfig.tsbuildinfo" + }, + "dependencies": { + "@atj/interviews": "workspace:*" + }, + "devDependencies": { + "@types/aws-lambda": "^8.10.109", + "esbuild": "^0.19.5" + } +} diff --git a/apps/form-service/src/index.ts b/apps/form-service/src/index.ts new file mode 100644 index 00000000..c85bc3d0 --- /dev/null +++ b/apps/form-service/src/index.ts @@ -0,0 +1,33 @@ +import { APIGatewayEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; + +export const lambdaHandler = async ( + event: APIGatewayEvent, + context: Context +): Promise => { + if (!event.body) { + const response: APIGatewayProxyResult = { + statusCode: 400, + body: JSON.stringify({ message: 'Request body is missing.' }), + }; + return response; + } + + const body = Buffer.from(event.body, 'base64').toString('utf-8'); + const formData = new URLSearchParams(body); + const fullName = formData.get('full_name'); + if (!fullName) { + const response: APIGatewayProxyResult = { + statusCode: 400, + body: JSON.stringify({ + message: 'Full name is required.', + }), + }; + return response; + } + + const response: APIGatewayProxyResult = { + statusCode: 200, + body: JSON.stringify({ message: `Hello, ${fullName}!` }), + }; + return response; +}; diff --git a/apps/form-service/tsconfig.json b/apps/form-service/tsconfig.json new file mode 100644 index 00000000..23707a42 --- /dev/null +++ b/apps/form-service/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "dist", + "emitDeclarationOnly": true, + "rootDir": "src" + }, + "include": [ + "src/**/*" + ], + "references": [ + { + "path": "../../packages/interviews" + } + ] +} diff --git a/apps/spotlight/package.json b/apps/spotlight/package.json index 7a1ed814..d28c665b 100644 --- a/apps/spotlight/package.json +++ b/apps/spotlight/package.json @@ -15,13 +15,12 @@ "@atj/docassemble": "workspace:*", "@atj/documents": "workspace:*", "@atj/interviews": "workspace:*", - "@uswds/uswds": "^3.6.0", - "astro": "^3.3.0", + "astro": "^3.3.3", "react": "^18.2.0", "react-dom": "^18.2.0" }, "devDependencies": { "@astrojs/check": "^0.2.1", - "@types/react": "^18.2.21" + "@types/react": "^18.2.33" } } diff --git a/apps/spotlight/src/layouts/ContentLayout.astro b/apps/spotlight/src/layouts/ContentLayout.astro new file mode 100644 index 00000000..2026a996 --- /dev/null +++ b/apps/spotlight/src/layouts/ContentLayout.astro @@ -0,0 +1,28 @@ +--- +import { type AppContext } from '../context'; +import Layout from '../layouts/Layout.astro'; + +interface Props { + title: string; + context: AppContext; +} +const { context, title } = Astro.props; +--- + + +
+
+
+
+
+
+ +
+
+
+
+
+
+
diff --git a/apps/spotlight/src/layouts/Layout.astro b/apps/spotlight/src/layouts/Layout.astro index 9f3ee869..54a029ac 100644 --- a/apps/spotlight/src/layouts/Layout.astro +++ b/apps/spotlight/src/layouts/Layout.astro @@ -1,15 +1,15 @@ --- -import '../styles.css' +import '../styles.css'; import Footer from '../components/Footer.astro'; import UsaBanner from '../components/UsaBanner.astro'; -import { type GithubRepository } from '../lib/github'; +import { type AppContext } from '../context'; interface Props { title: string; - github: GithubRepository; + context: AppContext; } -const { github, title } = Astro.props; +const { context, title } = Astro.props; --- @@ -17,11 +17,29 @@ const { github, title } = Astro.props; - - - - - + + + + + {title} @@ -29,6 +47,6 @@ const { github, title } = Astro.props; -