Add a contact form to the resume (#1)
All checks were successful
release / Publish to Cloudflare Pages (push) Successful in 1m6s

Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
2025-02-03 18:10:09 +10:30
parent fd4f30e33f
commit e0c12292cd
17 changed files with 3869 additions and 9 deletions

2446
contact-email-worker/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,20 @@
{
"name": "royal-leaf-c03c",
"version": "0.0.0",
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"start": "wrangler dev",
"cf-typegen": "wrangler types"
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.6.4",
"@cloudflare/workers-types": "^4.20250129.0",
"typescript": "^5.5.2",
"wrangler": "^3.107.2"
},
"dependencies": {
"mimetext": "^3.0.27"
}
}

View File

@@ -0,0 +1,56 @@
import { EmailMessage } from "cloudflare:email";
import { WorkerEntrypoint } from "cloudflare:workers";
import { createMimeMessage } from "mimetext";
const formatEmptyString = (s: string) => s ?? "Not Specified";
interface EmailDetails {
fullName: string;
organisation: string;
email: string;
mobile: string;
message: string;
}
export default class SendEmailWorker extends WorkerEntrypoint<Env> {
async fetch() {
return new Response("Unimplemented");
}
async sendEmail({
fullName,
organisation,
email,
mobile,
message,
}: EmailDetails) {
const msg = createMimeMessage();
msg.setSender({
name: "Michael Pivato Contact Form",
addr: "contact@michaelpivato.dev",
});
msg.setRecipient("contact@michaelpivato.dev");
msg.setSubject(`Message from ${fullName ?? email}`);
msg.addMessage({
contentType: "text/plain",
data: `You've received a new message from ${fullName ?? email}.
Full Name: ${formatEmptyString(fullName)}
Organisation: ${formatEmptyString(organisation)}
Email: ${formatEmptyString(email)}
Mobile: ${formatEmptyString(mobile)}
Message:
${message}`,
});
try {
const cfMessage = new EmailMessage(
"contact@michaelpivato.dev",
"contact@michaelpivato.dev",
msg.asRaw()
);
await this.env.SEB.send(cfMessage);
} catch (e) {
throw e;
}
}
}

View File

@@ -0,0 +1,46 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "es2021",
/* Specify a set of bundled library declaration files that describe the target runtime environment. */
"lib": ["es2021"],
/* Specify what JSX code is generated. */
"jsx": "react-jsx",
/* Specify what module code is generated. */
"module": "es2022",
/* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "Bundler",
/* Specify type package names to be included without being referenced in a source file. */
"types": [
"@cloudflare/workers-types/2023-07-01"
],
/* Enable importing .json files */
"resolveJsonModule": true,
/* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
"allowJs": true,
/* Enable error reporting in type-checked JavaScript files. */
"checkJs": false,
/* Disable emitting files from a compilation. */
"noEmit": true,
/* Ensure that each file can be safely transpiled without relying on other imports. */
"isolatedModules": true,
/* Allow 'import x from y' when a module doesn't have a default export. */
"allowSyntheticDefaultImports": true,
/* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true,
/* Enable all strict type-checking options. */
"strict": true,
/* Skip type checking all .d.ts files. */
"skipLibCheck": true
},
"exclude": ["test"],
"include": ["worker-configuration.d.ts", "src/**/*.ts"]
}

View File

@@ -0,0 +1,5 @@
// Generated by Wrangler by running `wrangler types`
interface Env {
SEB: SendEmail;
}

View File

@@ -0,0 +1,14 @@
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "contact-email",
"main": "src/index.ts",
"compatibility_date": "2025-01-29",
"observability": {
"enabled": true
},
"send_email": [
{ "name": "SEB", "destination_address": "contact@michaelpivato.dev" }
],
"workers_dev": false,
"compatibility_flags": ["nodejs_compat"]
}