Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start an email service #2514

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
122 changes: 122 additions & 0 deletions backend-node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env*.local
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Next.js files
.next
next-env.d.ts
out/
public/robots.txt
public/sitemap-0.xml
public/sitemap.xml

# Sentry
.sentryclirc

# Yarn
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
27 changes: 27 additions & 0 deletions backend-node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Flathub Email Service

# Development

First run

```
yarn install
```

You can start the api via

```
yarn dev
```

It should launch on http://localhost:8001

## Email preview

If you want to preview the emails use

```
yarn email-dev
```

Then open http://localhost:3001
96 changes: 96 additions & 0 deletions backend-node/emails/base.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import {
Body,
Container,
Head,
Heading,
Hr,
Html,
Img,
Preview,
Section,
Text,
} from "@react-email/components";
import { Tailwind } from "@react-email/tailwind";
import * as React from "react";

const isProduction = process.env.NODE_ENV === "production";

export function buildAppName(appId?: string, appName?: string) {
if (!appId && !appName) {
return undefined;
}

return appName ? `${appName} (${appId})` : appId;
}

export const Base = ({
children,
subject,
category,
appId,
appName,
previewText,
}: {
children: React.ReactNode;
subject: string;
category: string;
appId?: string;
appName?: string;
previewText: string;
}) => {
const appNameAndId = buildAppName(appId, appName);

let emailReason =
"You are receiving this email because you have an account on Flathub.";

if (category === "developer_invite" && appNameAndId) {
emailReason = `You are receiving this email because someone has invited you to become a developer of the app ${appNameAndId} on Flathub.`;
} else if (appId) {
emailReason = `You are receiving this email because you are a maintainer of the app ${appNameAndId} on Flathub.`;
}

return (
<Html>
<Head />
<Preview>{previewText}</Preview>
<Tailwind
config={{
theme: {
extend: {
colors: {
"flathub-celestial-blue": "rgb(74,144,217)",
},
},
},
}}
>
<Body className="bg-white my-auto mx-auto font-sans px-2">
<Container className="border border-solid border-[#eaeaea] rounded-xl my-[40px] mx-auto p-[20px] max-w-[465px]">
{!isProduction && (
<Section className="p-4 outline outline-flathub-celestial-blue rounded-xl">
This email was sent from a development instance.
</Section>
)}
<Section className="mt-[32px]">
<Img
src={`https://flathub.org/img/logo/logo-horizontal-email.png`}
alt="Flathub"
className="my-0 mx-auto mb-4"
/>
</Section>
<Hr></Hr>
<Heading className="text-black text-[24px] font-normal text-center p-0 my-[30px] mx-0">
{subject}
</Heading>
{children}
<Hr />

<Text className="text-black text-[14px] leading-[24px]">
{emailReason}
</Text>
</Container>
</Body>
</Tailwind>
</Html>
);
};