vintasend-pug 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [{src,scripts}/**.{ts,json,js}]
4
+ end_of_line = crlf
5
+ charset = utf-8
6
+ trim_trailing_whitespace = true
7
+ insert_final_newline = true
8
+ indent_style = space
9
+ indent_size = 2
package/biome.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3
+ "vcs": {
4
+ "enabled": false,
5
+ "clientKind": "git",
6
+ "useIgnoreFile": false
7
+ },
8
+ "files": {
9
+ "ignoreUnknown": false,
10
+ "ignore": []
11
+ },
12
+ "formatter": {
13
+ "enabled": true,
14
+ "indentStyle": "space",
15
+ "indentWidth": 2,
16
+ "lineWidth": 100
17
+ },
18
+ "organizeImports": {
19
+ "enabled": true
20
+ },
21
+ "linter": {
22
+ "enabled": true,
23
+ "rules": {
24
+ "recommended": true
25
+ }
26
+ },
27
+ "javascript": {
28
+ "formatter": {
29
+ "quoteStyle": "single",
30
+ "semicolons": "always",
31
+ "trailingCommas": "all"
32
+ }
33
+ }
34
+ }
package/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { PugEmailTemplateRenderer } from './pug-email-template-renderer';
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "vintasend-pug",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "",
10
+ "license": "ISC",
11
+ "dependencies": {
12
+ "pug": "^3.0.3",
13
+ "vintasend": "^0.1.0"
14
+ },
15
+ "devDependencies": {
16
+ "@types/pug": "^2.0.10"
17
+ }
18
+ }
@@ -0,0 +1,34 @@
1
+ import type { ContextGenerator } from 'vintasend/src/services/notification-context-registry';
2
+ import type {
3
+ BaseEmailTemplateRenderer,
4
+ EmailTemplate,
5
+ } from 'vintasend/src/services/notification-template-renderers/base-email-template-renderer';
6
+ import type { JsonObject } from 'vintasend/src/types/json-values';
7
+ import type { Notification } from 'vintasend/src/types/notification';
8
+
9
+ import pug from 'pug';
10
+
11
+ export class PugEmailTemplateRenderer<AvailableContexts extends Record<string, ContextGenerator>>
12
+ implements BaseEmailTemplateRenderer<AvailableContexts>
13
+ {
14
+ constructor(private options: pug.Options = {}) {}
15
+
16
+ render(
17
+ notification: Notification<AvailableContexts>,
18
+ context: JsonObject,
19
+ ): Promise<EmailTemplate> {
20
+ const bodyTemplate = pug.compileFile(notification.bodyTemplate, this.options);
21
+
22
+ if (!notification.subjectTemplate) {
23
+ throw new Error('Subject template is required');
24
+ }
25
+
26
+ const subjectTemplate = pug.compileFile(notification.subjectTemplate, this.options);
27
+ return new Promise((resolve) => {
28
+ resolve({
29
+ subject: subjectTemplate(context || {}),
30
+ body: bodyTemplate(context || {}),
31
+ });
32
+ });
33
+ }
34
+ }