Skip to content

Commit 20984fb

Browse files
committed
feat(email): Add EmailTemplateManager with renderEmail functionality
Because: * Setting the stage for email rework This commit: * Reworks and ports the functionality to render emails using mjml/ejs to the nestjs framework Closes #PAY-3294
1 parent 9b70776 commit 20984fb

21 files changed

+1035
-3
lines changed

libs/payments/email/.eslintrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": ["../../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
}
17+
]
18+
}

libs/payments/email/.swcrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"jsc": {
3+
"target": "es2017",
4+
"parser": {
5+
"syntax": "typescript",
6+
"decorators": true,
7+
"dynamicImport": true
8+
},
9+
"transform": {
10+
"decoratorMetadata": true,
11+
"legacyDecorator": true
12+
}
13+
}
14+
}

libs/payments/email/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# email
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Building
6+
7+
Run `nx build payments-email` to build the library.
8+
9+
## Running unit tests
10+
11+
Run `nx test payments-email` to execute the unit tests via [Jest](https://jestjs.io).

libs/payments/email/jest.config.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* eslint-disable */
2+
import { readFileSync } from 'fs';
3+
import { Config } from 'jest';
4+
5+
// Reading the SWC compilation config and remove the "exclude"
6+
// for the test files to be compiled by SWC
7+
const { exclude: _, ...swcJestConfig } = JSON.parse(
8+
readFileSync(`${__dirname}/.swcrc`, 'utf-8')
9+
);
10+
11+
// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves.
12+
// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude"
13+
if (swcJestConfig.swcrc === undefined) {
14+
swcJestConfig.swcrc = false;
15+
}
16+
17+
// Uncomment if using global setup/teardown files being transformed via swc
18+
// https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries
19+
// jest needs EsModule Interop to find the default exported setup/teardown functions
20+
// swcJestConfig.module.noInterop = false;
21+
22+
const config: Config = {
23+
displayName: 'payments-email',
24+
preset: '../../../jest.preset.js',
25+
transform: {
26+
'^.+\\.[tj]s$': ['@swc/jest', swcJestConfig],
27+
},
28+
moduleFileExtensions: ['ts', 'js', 'html'],
29+
testEnvironment: 'node',
30+
coverageDirectory: '../../../coverage/libs/payments/email',
31+
reporters: [
32+
'default',
33+
[
34+
'jest-junit',
35+
{
36+
outputDirectory: 'artifacts/tests/payments-email',
37+
outputName: 'payments-email-jest-unit-results.xml',
38+
},
39+
],
40+
],
41+
};
42+
43+
export default config;

libs/payments/email/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "@fxa/payments/email",
3+
"version": "0.0.1"
4+
}

libs/payments/email/project.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "payments-email",
3+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/payments/email/src",
5+
"projectType": "library",
6+
"tags": ["scope:shared:lib:payments"],
7+
"targets": {
8+
"build": {
9+
"executor": "@nx/esbuild:esbuild",
10+
"outputs": ["{options.outputPath}"],
11+
"defaultConfiguration": "production",
12+
"options": {
13+
"main": "libs/payments/email/src/index.ts",
14+
"outputPath": "dist/libs/payments/email",
15+
"outputFileName": "main.js",
16+
"tsConfig": "libs/payments/email/tsconfig.lib.json",
17+
"declaration": true,
18+
"assets": [
19+
{
20+
"glob": "libs/payments/email/README.md",
21+
"input": ".",
22+
"output": "."
23+
}
24+
],
25+
"platform": "node"
26+
},
27+
"configurations": {
28+
"development": {
29+
"minify": false
30+
},
31+
"production": {
32+
"minify": true
33+
}
34+
}
35+
},
36+
"lint": {
37+
"executor": "@nx/eslint:lint",
38+
"outputs": ["{options.outputFile}"],
39+
"options": {
40+
"lintFilePatterns": ["libs/payments/email/**/*.ts"]
41+
}
42+
},
43+
"test-unit": {
44+
"executor": "@nx/jest:jest",
45+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
46+
"options": {
47+
"jestConfig": "libs/payments/email/jest.config.ts"
48+
}
49+
}
50+
}
51+
}

libs/payments/email/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
export * from './lib/emailTemplate.manager';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
import { BaseError } from '@fxa/shared/error';
6+
7+
/**
8+
* EmailTemplateError is not intended for direct use, except for type-checking errors.
9+
* When throwing a new EmailTemplateError, create a unique extension of the class.
10+
*/
11+
export class EmailTemplateError extends BaseError {
12+
constructor(message: string, info: Record<string, any>, cause?: Error) {
13+
super(message, {
14+
info,
15+
cause,
16+
});
17+
this.name = 'EmailTemplateError';
18+
}
19+
}
20+
21+
export class EmailTemplateRetrieveComponentError extends EmailTemplateError {
22+
constructor(path: string, name: string) {
23+
super(`Failed to retrieve email component ${name} from path: ${path}`, {
24+
path,
25+
name,
26+
});
27+
this.name = 'EmailTemplateRetrieveComponentError';
28+
}
29+
}

0 commit comments

Comments
 (0)