Skip to content

The open alternative to Salesforce, designed for AI.

Move emails to dedicated package (#3542)

martmulle358d677f9ca
diff --git a/package.json b/package.json
index d97c2991063..dd912557dbf 100644
--- a/package.json
+++ b/package.json
@@ -261,6 +261,9 @@
"vite-plugin-checker": "^0.6.2",
"vite-plugin-svgr": "^4.2.0"
},
+ "scripts": {
+ "postinstall": "yarn nx run twenty-emails:build"
+ },
"engines": {
"node": "^18.17.1",
"npm": "please-use-yarn",
@@ -278,6 +281,7 @@
"packages/twenty-front",
"packages/twenty-docs",
"packages/twenty-server",
+ "packages/twenty-emails",
"packages/twenty-utils",
"packages/twenty-zapier",
"packages/twenty-website",
diff --git a/packages/twenty-emails/.gitignore b/packages/twenty-emails/.gitignore
new file mode 100644
index 00000000000..1521c8b7652
--- /dev/null
+++ b/packages/twenty-emails/.gitignore
@@ -0,0 +1 @@
+dist
diff --git a/packages/twenty-emails/package.json b/packages/twenty-emails/package.json
new file mode 100644
index 00000000000..679802f08bc
--- /dev/null
+++ b/packages/twenty-emails/package.json
@@ -0,0 +1,18 @@
+{
+ "name": "twenty-emails",
+ "version": "0.1.0",
+ "description": "",
+ "author": "",
+ "private": true,
+ "license": "AGPL-3.0",
+ "main": "./dist/index.js",
+ "scripts": {
+ "nx": "NX_DEFAULT_PROJECT=twenty-emails node ../../node_modules/nx/bin/nx.js",
+ "build": "tsup"
+ },
+ "engines": {
+ "node": "^18.17.1",
+ "npm": "please-use-yarn",
+ "yarn": "^4.0.2"
+ }
+}
diff --git a/packages/twenty-server/src/emails/common-style.ts b/packages/twenty-emails/src/common-style.ts
similarity index 100%
rename from packages/twenty-server/src/emails/common-style.ts
rename to packages/twenty-emails/src/common-style.ts
diff --git a/packages/twenty-server/src/emails/components/BaseEmail.tsx b/packages/twenty-emails/src/components/BaseEmail.tsx
similarity index 72%
rename from packages/twenty-server/src/emails/components/BaseEmail.tsx
rename to packages/twenty-emails/src/components/BaseEmail.tsx
index 6717f0e5797..eda27ac978a 100644
--- a/packages/twenty-server/src/emails/components/BaseEmail.tsx
+++ b/packages/twenty-emails/src/components/BaseEmail.tsx
@@ -1,8 +1,7 @@
import * as React from 'react';
import { Container, Html } from '@react-email/components';
-
-import { BaseHead } from 'src/emails/components/BaseHead';
-import { Logo } from 'src/emails/components/Logo';
+import { BaseHead } from 'src/components/BaseHead';
+import { Logo } from 'src/components/Logo';
export const BaseEmail = ({ children }) => {
return (
diff --git a/packages/twenty-server/src/emails/components/BaseHead.tsx b/packages/twenty-emails/src/components/BaseHead.tsx
similarity index 90%
rename from packages/twenty-server/src/emails/components/BaseHead.tsx
rename to packages/twenty-emails/src/components/BaseHead.tsx
index 6d3c92be139..def13457474 100644
--- a/packages/twenty-server/src/emails/components/BaseHead.tsx
+++ b/packages/twenty-emails/src/components/BaseHead.tsx
@@ -1,7 +1,6 @@
-import { Font, Head } from '@react-email/components';
import * as React from 'react';
-
-import { emailTheme } from 'src/emails/common-style';
+import { Font, Head } from '@react-email/components';
+import { emailTheme } from 'src/common-style';
export const BaseHead = () => {
return (
diff --git a/packages/twenty-server/src/emails/components/CallToAction.tsx b/packages/twenty-emails/src/components/CallToAction.tsx
similarity index 92%
rename from packages/twenty-server/src/emails/components/CallToAction.tsx
rename to packages/twenty-emails/src/components/CallToAction.tsx
index 77489992369..54448280136 100644
--- a/packages/twenty-server/src/emails/components/CallToAction.tsx
+++ b/packages/twenty-emails/src/components/CallToAction.tsx
@@ -1,7 +1,6 @@
-import { Button } from '@react-email/button';
import * as React from 'react';
-
-import { emailTheme } from 'src/emails/common-style';
+import { Button } from '@react-email/button';
+import { emailTheme } from 'src/common-style';
const callToActionStyle = {
display: 'flex',
padding: '8px 32px',
diff --git a/packages/twenty-server/src/emails/components/HighlightedText.tsx b/packages/twenty-emails/src/components/HighlightedText.tsx
similarity index 92%
rename from packages/twenty-server/src/emails/components/HighlightedText.tsx
rename to packages/twenty-emails/src/components/HighlightedText.tsx
index 75010e017c1..22a362ef766 100644
--- a/packages/twenty-server/src/emails/components/HighlightedText.tsx
+++ b/packages/twenty-emails/src/components/HighlightedText.tsx
@@ -1,9 +1,8 @@
import * as React from 'react';
+import { Column } from '@react-email/components';
import { Row } from '@react-email/row';
import { Text } from '@react-email/text';
-import { Column } from '@react-email/components';
-
-import { emailTheme } from 'src/emails/common-style';
+import { emailTheme } from 'src/common-style';
const rowStyle = {
display: 'flex',
diff --git a/packages/twenty-server/src/emails/components/Logo.tsx b/packages/twenty-emails/src/components/Logo.tsx
similarity index 100%
rename from packages/twenty-server/src/emails/components/Logo.tsx
rename to packages/twenty-emails/src/components/Logo.tsx
diff --git a/packages/twenty-server/src/emails/components/MainText.tsx b/packages/twenty-emails/src/components/MainText.tsx
similarity index 85%
rename from packages/twenty-server/src/emails/components/MainText.tsx
rename to packages/twenty-emails/src/components/MainText.tsx
index 8412c2bd94f..acc9ffd9c23 100644
--- a/packages/twenty-server/src/emails/components/MainText.tsx
+++ b/packages/twenty-emails/src/components/MainText.tsx
@@ -1,7 +1,6 @@
-import { Text } from '@react-email/text';
import * as React from 'react';
-
-import { emailTheme } from 'src/emails/common-style';
+import { Text } from '@react-email/text';
+import { emailTheme } from 'src/common-style';
const mainTextStyle = {
fontSize: emailTheme.font.size.md,
diff --git a/packages/twenty-server/src/emails/components/Title.tsx b/packages/twenty-emails/src/components/Title.tsx
similarity index 100%
rename from packages/twenty-server/src/emails/components/Title.tsx
rename to packages/twenty-emails/src/components/Title.tsx
diff --git a/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspaces.email.tsx b/packages/twenty-emails/src/emails/clean-inactive-workspaces.email.tsx
similarity index 80%
rename from packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspaces.email.tsx
rename to packages/twenty-emails/src/emails/clean-inactive-workspaces.email.tsx
index fa7420ef94e..2d012c39f9a 100644
--- a/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspaces.email.tsx
+++ b/packages/twenty-emails/src/emails/clean-inactive-workspaces.email.tsx
@@ -1,10 +1,9 @@
import * as React from 'react';
-
-import { HighlightedText } from 'src/emails/components/HighlightedText';
-import { MainText } from 'src/emails/components/MainText';
-import { Title } from 'src/emails/components/Title';
-import { BaseEmail } from 'src/emails/components/BaseEmail';
-import { CallToAction } from 'src/emails/components/CallToAction';
+import { BaseEmail } from 'src/components/BaseEmail';
+import { CallToAction } from 'src/components/CallToAction';
+import { HighlightedText } from 'src/components/HighlightedText';
+import { MainText } from 'src/components/MainText';
+import { Title } from 'src/components/Title';
type CleanInactiveWorkspaceEmailData = {
daysLeft: number;
diff --git a/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/delete-inactive-workspaces.email.tsx b/packages/twenty-emails/src/emails/delete-inactive-workspaces.email.tsx
similarity index 66%
rename from packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/delete-inactive-workspaces.email.tsx
rename to packages/twenty-emails/src/emails/delete-inactive-workspaces.email.tsx
index 7686696af68..15aadf0cb0b 100644
--- a/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/delete-inactive-workspaces.email.tsx
+++ b/packages/twenty-emails/src/emails/delete-inactive-workspaces.email.tsx
@@ -1,10 +1,9 @@
import * as React from 'react';
-
-import { HighlightedText } from 'src/emails/components/HighlightedText';
-import { MainText } from 'src/emails/components/MainText';
-import { Title } from 'src/emails/components/Title';
-import { BaseEmail } from 'src/emails/components/BaseEmail';
-import { CallToAction } from 'src/emails/components/CallToAction';
+import { BaseEmail } from 'src/components/BaseEmail';
+import { CallToAction } from 'src/components/CallToAction';
+import { HighlightedText } from 'src/components/HighlightedText';
+import { MainText } from 'src/components/MainText';
+import { Title } from 'src/components/Title';
type DeleteInactiveWorkspaceEmailData = {
daysSinceDead: number;
diff --git a/packages/twenty-emails/tsconfig.json b/packages/twenty-emails/tsconfig.json
new file mode 100644
index 00000000000..84c44e20bc6
--- /dev/null
+++ b/packages/twenty-emails/tsconfig.json
@@ -0,0 +1,7 @@
+{
+ "compilerOptions": {
+ "module": "commonjs",
+ "baseUrl": "./",
+ "jsx": "react-jsx"
+ }
+}
diff --git a/packages/twenty-emails/tsup.config.ts b/packages/twenty-emails/tsup.config.ts
new file mode 100644
index 00000000000..177033ccd3a
--- /dev/null
+++ b/packages/twenty-emails/tsup.config.ts
@@ -0,0 +1,9 @@
+import { defineConfig } from 'tsup';
+
+export default defineConfig([
+ {
+ entry: { index: './tsup.index.tsx' },
+ format: ['cjs', 'esm'],
+ dts: true,
+ },
+]);
diff --git a/packages/twenty-emails/tsup.index.tsx b/packages/twenty-emails/tsup.index.tsx
new file mode 100644
index 00000000000..e816bb7363b
--- /dev/null
+++ b/packages/twenty-emails/tsup.index.tsx
@@ -0,0 +1,2 @@
+export * from './src/emails/clean-inactive-workspaces.email';
+export * from './src/emails/delete-inactive-workspaces.email';
diff --git a/packages/twenty-server/package.json b/packages/twenty-server/package.json
index 40fa1767b21..fb9ec7eacf0 100644
--- a/packages/twenty-server/package.json
+++ b/packages/twenty-server/package.json
@@ -37,7 +37,8 @@
"@graphql-yoga/nestjs": "patch:@graphql-yoga/[email protected]#./patches/@graphql-yoga+nestjs+2.1.0.patch",
"@nestjs/graphql": "patch:@nestjs/[email protected]#./patches/@nestjs+graphql+12.0.8.patch",
"@ptc-org/nestjs-query-graphql": "patch:@ptc-org/[email protected]#./patches/@ptc-org+nestjs-query-graphql+4.2.0.patch",
- "class-validator": "patch:class-validator@^0.14.0#./patches/class-validator+0.14.0.patch"
+ "class-validator": "patch:class-validator@^0.14.0#./patches/class-validator+0.14.0.patch",
+ "twenty-emails": "workspace:*"
},
"engines": {
"node": "^18.17.1",
diff --git a/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspace.job.ts b/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspace.job.ts
index 88159758d5c..2c574ea0027 100644
--- a/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspace.job.ts
+++ b/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspace.job.ts
@@ -3,6 +3,10 @@ import { InjectRepository } from '@nestjs/typeorm';
import { render } from '@react-email/render';
import { Repository } from 'typeorm';
+import {
+ CleanInactiveWorkspaceEmail,
+ DeleteInactiveWorkspaceEmail,
+} from 'twenty-emails';
import { MessageQueueJob } from 'src/integrations/message-queue/interfaces/message-queue-job.interface';
@@ -12,14 +16,12 @@ import { TypeORMService } from 'src/database/typeorm/typeorm.service';
import { DataSourceEntity } from 'src/metadata/data-source/data-source.entity';
import { UserService } from 'src/core/user/services/user.service';
import { EmailService } from 'src/integrations/email/email.service';
-import CleanInactiveWorkspaceEmail from 'src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspaces.email';
import { EnvironmentService } from 'src/integrations/environment/environment.service';
import {
FeatureFlagEntity,
FeatureFlagKeys,
} from 'src/core/feature-flag/feature-flag.entity';
import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity';
-import DeleteInactiveWorkspaceEmail from 'src/workspace/cron/clean-inactive-workspaces/delete-inactive-workspaces.email';
import { computeObjectTargetTable } from 'src/workspace/utils/compute-object-target-table.util';
const MILLISECONDS_IN_ONE_DAY = 1000 * 3600 * 24;
diff --git a/packages/twenty-server/tsconfig.json b/packages/twenty-server/tsconfig.json
index 6acfb191b4e..f5993c2161e 100644
--- a/packages/twenty-server/tsconfig.json
+++ b/packages/twenty-server/tsconfig.json
@@ -22,7 +22,6 @@
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"resolveJsonModule": true,
- "types": ["jest", "node"],
- "jsx": "react-jsx"
+ "types": ["jest", "node"]
}
}
diff --git a/yarn.lock b/yarn.lock
index 9aa5a029299..92903d064ce 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -42367,6 +42367,12 @@ __metadata:
languageName: unknown
linkType: soft
+"twenty-emails@workspace:*, twenty-emails@workspace:packages/twenty-emails":
+ version: 0.0.0-use.local
+ resolution: "twenty-emails@workspace:packages/twenty-emails"
+ languageName: unknown
+ linkType: soft
+
"twenty-front@workspace:packages/twenty-front":
version: 0.0.0-use.local
resolution: "twenty-front@workspace:packages/twenty-front"
@@ -42381,6 +42387,7 @@ __metadata:
"@nestjs/graphql": "patch:@nestjs/[email protected]#./patches/@nestjs+graphql+12.0.8.patch"
"@ptc-org/nestjs-query-graphql": "patch:@ptc-org/[email protected]#./patches/@ptc-org+nestjs-query-graphql+4.2.0.patch"
class-validator: "patch:class-validator@^0.14.0#./patches/class-validator+0.14.0.patch"
+ twenty-emails: "workspace:*"
languageName: unknown
linkType: soft