@frigear-nu/email-templates 0.0.0-stage → 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.
Files changed (40) hide show
  1. package/README.md +4 -2
  2. package/dist/module.d.mts +28 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +132 -0
  5. package/dist/runtime/components/EmailButton.d.vue.ts +18 -0
  6. package/dist/runtime/components/EmailButton.vue +17 -0
  7. package/dist/runtime/components/EmailButton.vue.d.ts +18 -0
  8. package/dist/runtime/components/EmailDivider.d.vue.ts +3 -0
  9. package/dist/runtime/components/EmailDivider.vue +7 -0
  10. package/dist/runtime/components/EmailDivider.vue.d.ts +3 -0
  11. package/dist/runtime/components/EmailFooter.d.vue.ts +13 -0
  12. package/dist/runtime/components/EmailFooter.vue +14 -0
  13. package/dist/runtime/components/EmailFooter.vue.d.ts +13 -0
  14. package/dist/runtime/components/EmailHeader.d.vue.ts +7 -0
  15. package/dist/runtime/components/EmailHeader.vue +39 -0
  16. package/dist/runtime/components/EmailHeader.vue.d.ts +7 -0
  17. package/dist/runtime/components/EmailHeading.d.vue.ts +17 -0
  18. package/dist/runtime/components/EmailHeading.vue +13 -0
  19. package/dist/runtime/components/EmailHeading.vue.d.ts +17 -0
  20. package/dist/runtime/components/EmailLayout.d.vue.ts +20 -0
  21. package/dist/runtime/components/EmailLayout.vue +54 -0
  22. package/dist/runtime/components/EmailLayout.vue.d.ts +20 -0
  23. package/dist/runtime/components/EmailLinkFallback.d.vue.ts +16 -0
  24. package/dist/runtime/components/EmailLinkFallback.vue +15 -0
  25. package/dist/runtime/components/EmailLinkFallback.vue.d.ts +16 -0
  26. package/dist/runtime/components/EmailText.d.vue.ts +17 -0
  27. package/dist/runtime/components/EmailText.vue +18 -0
  28. package/dist/runtime/components/EmailText.vue.d.ts +17 -0
  29. package/dist/runtime/components/index.d.ts +8 -0
  30. package/dist/runtime/components/index.js +8 -0
  31. package/dist/runtime/components/theme.d.ts +17 -0
  32. package/dist/runtime/components/theme.js +27 -0
  33. package/dist/runtime/server/plugins/notify-email.d.ts +7 -0
  34. package/dist/runtime/server/plugins/notify-email.js +21 -0
  35. package/dist/runtime/server/utils/email-templates.d.ts +25 -0
  36. package/dist/runtime/server/utils/email-templates.js +24 -0
  37. package/dist/runtime/types.d.ts +44 -0
  38. package/dist/runtime/types.js +0 -0
  39. package/dist/types.d.mts +5 -0
  40. package/package.json +73 -3
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # @frigear-nu/email-templates
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Vue email templates for `@frigear-nu/notify`, rendered with [nuxt-email-renderer](https://nuxtemail.com): a typed `sendEmailTemplate(name, props, message)` for the host, and module emails (auth, users, subscriptions) rendered from templates the host can override by file name.
4
+
5
+ See the [documentation](../../apps/docs/content/4.modules/20.email-templates.md) for usage.
@@ -0,0 +1,28 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { EmailTemplatesRuntimeConfig } from '../dist/runtime/types.js';
3
+ export { EmailTemplateName, EmailTemplateProps, EmailTemplates, EmailTemplatesRuntimeConfig, RenderedEmailTemplate } from '../dist/runtime/types.js';
4
+
5
+ /** Branding for the shared components (`@frigear-nu/email-templates/components`). All of it can be set at runtime too. */
6
+ type ModuleOptions = {
7
+ /** Logo alt text, and the header text when there is no logo. Default `'Frigear'`. */
8
+ brandName?: string;
9
+ /** Logo in the header: absolute, or a path resolved against `siteUrl`. No logo when unset. */
10
+ logoUrl?: string;
11
+ /** Base URL for a relative `logoUrl`. */
12
+ siteUrl?: string;
13
+ /** Button and alert colours. Default `#2563eb` / `#dc2626`. */
14
+ colors?: Partial<EmailTemplatesRuntimeConfig['colors']>;
15
+ };
16
+
17
+ declare module 'nuxt/schema' {
18
+ interface NuxtConfig {
19
+ emailTemplates?: ModuleOptions;
20
+ }
21
+ interface RuntimeConfig {
22
+ emailTemplates: EmailTemplatesRuntimeConfig;
23
+ }
24
+ }
25
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
26
+
27
+ export { _default as default };
28
+ export type { ModuleOptions };
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@frigear-nu/email-templates",
3
+ "configKey": "emailTemplates",
4
+ "version": "0.1.0",
5
+ "builder": {
6
+ "@nuxt/module-builder": "1.0.3",
7
+ "unbuild": "unknown"
8
+ }
9
+ }
@@ -0,0 +1,132 @@
1
+ import { defineNuxtModule, createResolver, updateTemplates, addTypeTemplate, addServerImportsDir, addServerPlugin } from '@nuxt/kit';
2
+ import { registerModule, inlineModuleRuntime } from '@frigear-nu/module-kit/utils';
3
+ import { defu } from 'defu';
4
+ import { existsSync, readdirSync, statSync } from 'node:fs';
5
+ import { resolve, join, basename, extname } from 'node:path';
6
+
7
+ function scanTemplateDir(dir) {
8
+ if (!existsSync(dir)) return [];
9
+ return readdirSync(dir).filter((file) => file.endsWith(".vue") && statSync(join(dir, file)).isFile()).map((filename) => {
10
+ const name = basename(filename, extname(filename));
11
+ return {
12
+ name,
13
+ filename,
14
+ displayName: name.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/([A-Z])([A-Z][a-z])/g, "$1 $2").trim(),
15
+ importPath: `#email-templates/${name}`,
16
+ filePath: join(dir, filename)
17
+ };
18
+ });
19
+ }
20
+ function layerTemplateDirs(nuxt) {
21
+ const emailsDir = nuxt.options.nuxtEmailRenderer?.emailsDir;
22
+ const dirs = [];
23
+ for (const layer of nuxt.options._layers) {
24
+ const candidates = [
25
+ ...emailsDir ? [resolve(layer.cwd, emailsDir)] : [],
26
+ join(layer.cwd, "app", "emails"),
27
+ join(layer.cwd, "emails")
28
+ ];
29
+ const dir = candidates.find((candidate) => existsSync(candidate));
30
+ if (dir) dirs.push(dir);
31
+ }
32
+ return dirs;
33
+ }
34
+ function mergeTemplates(moduleDirs, layerDirs) {
35
+ const templates = {};
36
+ for (const dir of [...moduleDirs, ...[...layerDirs].reverse()]) {
37
+ for (const template of scanTemplateDir(dir)) templates[template.name] = template;
38
+ }
39
+ return templates;
40
+ }
41
+ function templatesVirtualModule(templates) {
42
+ const entries = Object.values(templates);
43
+ return [
44
+ ...entries.map((template, index) => `import Template${index} from ${JSON.stringify(template.filePath)}`),
45
+ "",
46
+ `export const emailTemplates = {
47
+ ${entries.map((template, index) => ` ${JSON.stringify(template.name)}: Template${index}`).join(",\n")}
48
+ }`,
49
+ "",
50
+ `export const emailTemplateMapping = ${JSON.stringify(templates, null, 2)}`,
51
+ "",
52
+ "export function getEmailTemplate(name) {\n return emailTemplates[name]\n}",
53
+ ""
54
+ ].join("\n");
55
+ }
56
+
57
+ const module$1 = defineNuxtModule({
58
+ meta: { name: "@frigear-nu/email-templates", configKey: "emailTemplates" },
59
+ defaults: {},
60
+ moduleDependencies: {
61
+ "@frigear-nu/module-kit": { version: ">=0.0.1" },
62
+ "@frigear-nu/notify": { version: ">=0.1.0" },
63
+ // Keeps Shiki (`ECodeBlock`) out of the server bundle unless the host turns it back on.
64
+ "nuxt-email-renderer": { version: ">=2.11.0", defaults: { codeHighlighting: false } }
65
+ },
66
+ async setup(options, nuxt) {
67
+ registerModule("@frigear-nu/email-templates", nuxt);
68
+ const resolver = createResolver(import.meta.url);
69
+ const runtimeConfig = nuxt.options.runtimeConfig;
70
+ runtimeConfig.emailTemplates = defu(runtimeConfig.emailTemplates, {
71
+ brandName: options.brandName ?? "Frigear",
72
+ logoUrl: options.logoUrl ?? "",
73
+ siteUrl: options.siteUrl ?? "",
74
+ colors: { primary: options.colors?.primary ?? "#2563eb", danger: options.colors?.danger ?? "#dc2626" }
75
+ });
76
+ nuxt.options.alias["@frigear-nu/email-templates/components"] = resolver.resolve("./runtime/components");
77
+ const collectModuleDirs = async () => {
78
+ const sources = [];
79
+ await nuxt.callHook("notify:email:templates", sources);
80
+ return [...new Set(sources.map((source) => source.dir))];
81
+ };
82
+ const collectTemplates = async () => mergeTemplates(await collectModuleDirs(), layerTemplateDirs(nuxt));
83
+ nuxt.hook("modules:done", () => {
84
+ nuxt.hook("nitro:config", async (nitroConfig) => {
85
+ const moduleDirs = await collectModuleDirs();
86
+ nitroConfig.virtual ||= {};
87
+ nitroConfig.virtual["#email-templates"] = templatesVirtualModule(mergeTemplates(moduleDirs, layerTemplateDirs(nuxt)));
88
+ nitroConfig.externals ||= {};
89
+ nitroConfig.externals.inline = [...nitroConfig.externals.inline ?? [], ...moduleDirs];
90
+ const emailsStorage = nitroConfig.devStorage?.emails;
91
+ if (emailsStorage && emailsStorage.driver === "fs" && !emailsStorage.base) delete nitroConfig.devStorage.emails;
92
+ });
93
+ });
94
+ if (nuxt.options.dev) {
95
+ const moduleDirs = await collectModuleDirs();
96
+ nuxt.options.watch.push(...moduleDirs.map((dir) => `${dir}/**/*.vue`));
97
+ nuxt.hook("builder:watch", async (event, path) => {
98
+ if ((event === "add" || event === "unlink") && path.endsWith(".vue")) {
99
+ await updateTemplates({ filter: (template) => template.filename === "types/email-templates.d.ts" });
100
+ }
101
+ });
102
+ }
103
+ addTypeTemplate({
104
+ filename: "types/email-templates.d.ts",
105
+ getContents: async () => {
106
+ const templates = Object.values(await collectTemplates());
107
+ const types = JSON.stringify(resolver.resolve("./runtime/types"));
108
+ return `import type { TemplateComponentProps } from ${types}
109
+
110
+ declare module ${types} {
111
+ interface EmailTemplates {
112
+ ${templates.map((template) => ` ${JSON.stringify(template.name)}: TemplateComponentProps<typeof import(${JSON.stringify(template.filePath)}).default>`).join("\n")}
113
+ }
114
+ }
115
+ `;
116
+ }
117
+ }, { nitro: true, nuxt: true });
118
+ addTypeTemplate({
119
+ filename: "types/email-templates-virtual.d.ts",
120
+ getContents: () => `declare module '#email-templates' {
121
+ export const emailTemplates: Record<string, import('vue').Component>
122
+ export const emailTemplateMapping: Record<string, import(${JSON.stringify(resolver.resolve("./runtime/types"))}).EmailTemplateFile>
123
+ }
124
+ `
125
+ }, { nitro: true, nuxt: true });
126
+ addServerImportsDir(resolver.resolve("./runtime/server/utils"));
127
+ addServerPlugin(resolver.resolve("./runtime/server/plugins/notify-email"));
128
+ inlineModuleRuntime(nuxt, resolver);
129
+ }
130
+ });
131
+
132
+ export { module$1 as default };
@@ -0,0 +1,18 @@
1
+ type __VLS_Props = {
2
+ href: string;
3
+ /** `danger` for security actions. */
4
+ color?: 'primary' | 'danger';
5
+ };
6
+ declare var __VLS_8: {};
7
+ type __VLS_Slots = {} & {
8
+ default?: (props: typeof __VLS_8) => any;
9
+ };
10
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
12
+ declare const _default: typeof __VLS_export;
13
+ export default _default;
14
+ type __VLS_WithSlots<T, S> = T & {
15
+ new (): {
16
+ $slots: S;
17
+ };
18
+ };
@@ -0,0 +1,17 @@
1
+ <script setup>
2
+ import { useEmailTheme } from "./theme";
3
+ defineProps({
4
+ href: { type: String, required: true },
5
+ color: { type: String, required: false, default: "primary" }
6
+ });
7
+ const theme = useEmailTheme();
8
+ </script>
9
+
10
+ <template>
11
+ <EButton
12
+ :href="href"
13
+ :style="{ backgroundColor: color === 'danger' ? theme.danger : theme.primary, borderRadius: '4px', color: '#ffffff', fontSize: '16px', fontWeight: '600', marginBottom: '16px', padding: '8px 16px' }"
14
+ >
15
+ <slot />
16
+ </EButton>
17
+ </template>
@@ -0,0 +1,18 @@
1
+ type __VLS_Props = {
2
+ href: string;
3
+ /** `danger` for security actions. */
4
+ color?: 'primary' | 'danger';
5
+ };
6
+ declare var __VLS_8: {};
7
+ type __VLS_Slots = {} & {
8
+ default?: (props: typeof __VLS_8) => any;
9
+ };
10
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
12
+ declare const _default: typeof __VLS_export;
13
+ export default _default;
14
+ type __VLS_WithSlots<T, S> = T & {
15
+ new (): {
16
+ $slots: S;
17
+ };
18
+ };
@@ -0,0 +1,3 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;
@@ -0,0 +1,7 @@
1
+ <script setup>
2
+ import { tokens } from "./theme";
3
+ </script>
4
+
5
+ <template>
6
+ <hr :style="{ border: 'none', borderTop: `1px solid ${tokens.border}`, margin: '16px 0', width: '100%' }">
7
+ </template>
@@ -0,0 +1,3 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;
@@ -0,0 +1,13 @@
1
+ declare var __VLS_12: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_12) => any;
4
+ };
5
+ declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
9
+ type __VLS_WithSlots<T, S> = T & {
10
+ new (): {
11
+ $slots: S;
12
+ };
13
+ };
@@ -0,0 +1,14 @@
1
+ <script setup>
2
+ import EmailDivider from "./EmailDivider.vue";
3
+ import EmailText from "./EmailText.vue";
4
+ </script>
5
+
6
+ <template>
7
+ <EmailDivider />
8
+ <EmailText
9
+ variant="small"
10
+ style="margin: 0"
11
+ >
12
+ <slot>This email was sent automatically for security reasons.</slot>
13
+ </EmailText>
14
+ </template>
@@ -0,0 +1,13 @@
1
+ declare var __VLS_12: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_12) => any;
4
+ };
5
+ declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
9
+ type __VLS_WithSlots<T, S> = T & {
10
+ new (): {
11
+ $slots: S;
12
+ };
13
+ };
@@ -0,0 +1,7 @@
1
+ type __VLS_Props = {
2
+ /** Overrides the configured logo. */
3
+ logoUrl?: string;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
6
+ declare const _default: typeof __VLS_export;
7
+ export default _default;
@@ -0,0 +1,39 @@
1
+ <script setup>
2
+ import { computed } from "vue";
3
+ import { tokens, useEmailTheme } from "./theme";
4
+ const props = defineProps({
5
+ logoUrl: { type: String, required: false }
6
+ });
7
+ const theme = useEmailTheme();
8
+ const src = computed(() => props.logoUrl || theme.logoUrl);
9
+ </script>
10
+
11
+ <template>
12
+ <table
13
+ role="presentation"
14
+ width="100%"
15
+ cellspacing="0"
16
+ cellpadding="0"
17
+ border="0"
18
+ :style="{ backgroundColor: tokens.page, borderRadius: '6px', marginBottom: '24px' }"
19
+ >
20
+ <tr>
21
+ <td
22
+ align="center"
23
+ style="padding: 20px"
24
+ >
25
+ <EImg
26
+ v-if="src"
27
+ :src="src"
28
+ :alt="theme.brandName"
29
+ width="150"
30
+ style="margin: 0 auto"
31
+ />
32
+ <span
33
+ v-else
34
+ :style="{ color: tokens.heading, fontSize: '24px', fontWeight: '700', lineHeight: '32px' }"
35
+ >{{ theme.brandName }}</span>
36
+ </td>
37
+ </tr>
38
+ </table>
39
+ </template>
@@ -0,0 +1,7 @@
1
+ type __VLS_Props = {
2
+ /** Overrides the configured logo. */
3
+ logoUrl?: string;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
6
+ declare const _default: typeof __VLS_export;
7
+ export default _default;
@@ -0,0 +1,17 @@
1
+ type __VLS_Props = {
2
+ /** `danger` for security alerts. */
3
+ tone?: 'default' | 'danger';
4
+ };
5
+ declare var __VLS_1: {};
6
+ type __VLS_Slots = {} & {
7
+ default?: (props: typeof __VLS_1) => any;
8
+ };
9
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
13
+ type __VLS_WithSlots<T, S> = T & {
14
+ new (): {
15
+ $slots: S;
16
+ };
17
+ };
@@ -0,0 +1,13 @@
1
+ <script setup>
2
+ import { tokens, useEmailTheme } from "./theme";
3
+ defineProps({
4
+ tone: { type: String, required: false, default: "default" }
5
+ });
6
+ const theme = useEmailTheme();
7
+ </script>
8
+
9
+ <template>
10
+ <h2 :style="{ color: tone === 'danger' ? theme.danger : tokens.heading, fontSize: '20px', fontWeight: '700', lineHeight: '28px', margin: '0 0 16px' }">
11
+ <slot />
12
+ </h2>
13
+ </template>
@@ -0,0 +1,17 @@
1
+ type __VLS_Props = {
2
+ /** `danger` for security alerts. */
3
+ tone?: 'default' | 'danger';
4
+ };
5
+ declare var __VLS_1: {};
6
+ type __VLS_Slots = {} & {
7
+ default?: (props: typeof __VLS_1) => any;
8
+ };
9
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
13
+ type __VLS_WithSlots<T, S> = T & {
14
+ new (): {
15
+ $slots: S;
16
+ };
17
+ };
@@ -0,0 +1,20 @@
1
+ type __VLS_Props = {
2
+ /** Inbox preview line shown after the subject. */
3
+ preview?: string;
4
+ lang?: string;
5
+ };
6
+ declare var __VLS_30: {}, __VLS_32: {};
7
+ type __VLS_Slots = {} & {
8
+ default?: (props: typeof __VLS_30) => any;
9
+ } & {
10
+ footer?: (props: typeof __VLS_32) => any;
11
+ };
12
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
13
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
14
+ declare const _default: typeof __VLS_export;
15
+ export default _default;
16
+ type __VLS_WithSlots<T, S> = T & {
17
+ new (): {
18
+ $slots: S;
19
+ };
20
+ };
@@ -0,0 +1,54 @@
1
+ <script setup>
2
+ import { tokens } from "./theme";
3
+ import EmailFooter from "./EmailFooter.vue";
4
+ import EmailHeader from "./EmailHeader.vue";
5
+ defineProps({
6
+ preview: { type: String, required: false, default: void 0 },
7
+ lang: { type: String, required: false, default: "en" }
8
+ });
9
+ </script>
10
+
11
+ <template>
12
+ <EHtml :lang="lang">
13
+ <EHead />
14
+ <EPreview v-if="preview">
15
+ {{ preview }}
16
+ </EPreview>
17
+ <EBody :style="{ backgroundColor: tokens.page, margin: '0', padding: '0', fontFamily: tokens.font }">
18
+ <table
19
+ role="presentation"
20
+ width="100%"
21
+ cellspacing="0"
22
+ cellpadding="0"
23
+ border="0"
24
+ :style="{ backgroundColor: tokens.page }"
25
+ >
26
+ <tr>
27
+ <td
28
+ align="center"
29
+ style="padding: 16px"
30
+ >
31
+ <table
32
+ role="presentation"
33
+ width="100%"
34
+ cellspacing="0"
35
+ cellpadding="0"
36
+ border="0"
37
+ :style="{ maxWidth: '512px', backgroundColor: tokens.card, border: `1px solid ${tokens.border}`, borderRadius: '8px', boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)' }"
38
+ >
39
+ <tr>
40
+ <td style="padding: 24px; text-align: left">
41
+ <EmailHeader />
42
+ <slot />
43
+ <slot name="footer">
44
+ <EmailFooter />
45
+ </slot>
46
+ </td>
47
+ </tr>
48
+ </table>
49
+ </td>
50
+ </tr>
51
+ </table>
52
+ </EBody>
53
+ </EHtml>
54
+ </template>
@@ -0,0 +1,20 @@
1
+ type __VLS_Props = {
2
+ /** Inbox preview line shown after the subject. */
3
+ preview?: string;
4
+ lang?: string;
5
+ };
6
+ declare var __VLS_30: {}, __VLS_32: {};
7
+ type __VLS_Slots = {} & {
8
+ default?: (props: typeof __VLS_30) => any;
9
+ } & {
10
+ footer?: (props: typeof __VLS_32) => any;
11
+ };
12
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
13
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
14
+ declare const _default: typeof __VLS_export;
15
+ export default _default;
16
+ type __VLS_WithSlots<T, S> = T & {
17
+ new (): {
18
+ $slots: S;
19
+ };
20
+ };
@@ -0,0 +1,16 @@
1
+ type __VLS_Props = {
2
+ href: string;
3
+ };
4
+ declare var __VLS_8: {};
5
+ type __VLS_Slots = {} & {
6
+ default?: (props: typeof __VLS_8) => any;
7
+ };
8
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
10
+ declare const _default: typeof __VLS_export;
11
+ export default _default;
12
+ type __VLS_WithSlots<T, S> = T & {
13
+ new (): {
14
+ $slots: S;
15
+ };
16
+ };
@@ -0,0 +1,15 @@
1
+ <script setup>
2
+ import EmailText from "./EmailText.vue";
3
+ defineProps({
4
+ href: { type: String, required: true }
5
+ });
6
+ </script>
7
+
8
+ <template>
9
+ <EmailText variant="muted">
10
+ <slot>Or copy this link to your browser:</slot> <a
11
+ :href="href"
12
+ style="color: inherit; text-decoration: underline"
13
+ >{{ href }}</a>
14
+ </EmailText>
15
+ </template>
@@ -0,0 +1,16 @@
1
+ type __VLS_Props = {
2
+ href: string;
3
+ };
4
+ declare var __VLS_8: {};
5
+ type __VLS_Slots = {} & {
6
+ default?: (props: typeof __VLS_8) => any;
7
+ };
8
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
10
+ declare const _default: typeof __VLS_export;
11
+ export default _default;
12
+ type __VLS_WithSlots<T, S> = T & {
13
+ new (): {
14
+ $slots: S;
15
+ };
16
+ };
@@ -0,0 +1,17 @@
1
+ type __VLS_Props = {
2
+ /** `muted` for secondary text, `small` for fine print. */
3
+ variant?: 'default' | 'muted' | 'small';
4
+ };
5
+ declare var __VLS_1: {};
6
+ type __VLS_Slots = {} & {
7
+ default?: (props: typeof __VLS_1) => any;
8
+ };
9
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
13
+ type __VLS_WithSlots<T, S> = T & {
14
+ new (): {
15
+ $slots: S;
16
+ };
17
+ };
@@ -0,0 +1,18 @@
1
+ <script setup>
2
+ import { computed } from "vue";
3
+ import { tokens } from "./theme";
4
+ const props = defineProps({
5
+ variant: { type: String, required: false, default: "default" }
6
+ });
7
+ const style = computed(() => ({
8
+ default: { color: tokens.text, fontSize: "16px", lineHeight: "24px" },
9
+ muted: { color: tokens.muted, fontSize: "14px", lineHeight: "20px", wordBreak: "break-word" },
10
+ small: { color: tokens.faint, fontSize: "12px", lineHeight: "16px" }
11
+ })[props.variant]);
12
+ </script>
13
+
14
+ <template>
15
+ <p :style="{ ...style, margin: '0 0 16px' }">
16
+ <slot />
17
+ </p>
18
+ </template>
@@ -0,0 +1,17 @@
1
+ type __VLS_Props = {
2
+ /** `muted` for secondary text, `small` for fine print. */
3
+ variant?: 'default' | 'muted' | 'small';
4
+ };
5
+ declare var __VLS_1: {};
6
+ type __VLS_Slots = {} & {
7
+ default?: (props: typeof __VLS_1) => any;
8
+ };
9
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
13
+ type __VLS_WithSlots<T, S> = T & {
14
+ new (): {
15
+ $slots: S;
16
+ };
17
+ };
@@ -0,0 +1,8 @@
1
+ export { default as EmailLayout } from './EmailLayout.vue.js';
2
+ export { default as EmailHeader } from './EmailHeader.vue.js';
3
+ export { default as EmailHeading } from './EmailHeading.vue.js';
4
+ export { default as EmailText } from './EmailText.vue.js';
5
+ export { default as EmailButton } from './EmailButton.vue.js';
6
+ export { default as EmailLinkFallback } from './EmailLinkFallback.vue.js';
7
+ export { default as EmailDivider } from './EmailDivider.vue.js';
8
+ export { default as EmailFooter } from './EmailFooter.vue.js';
@@ -0,0 +1,8 @@
1
+ export { default as EmailLayout } from "./EmailLayout.vue";
2
+ export { default as EmailHeader } from "./EmailHeader.vue";
3
+ export { default as EmailHeading } from "./EmailHeading.vue";
4
+ export { default as EmailText } from "./EmailText.vue";
5
+ export { default as EmailButton } from "./EmailButton.vue";
6
+ export { default as EmailLinkFallback } from "./EmailLinkFallback.vue";
7
+ export { default as EmailDivider } from "./EmailDivider.vue";
8
+ export { default as EmailFooter } from "./EmailFooter.vue";
@@ -0,0 +1,17 @@
1
+ export declare const tokens: {
2
+ page: string;
3
+ card: string;
4
+ border: string;
5
+ text: string;
6
+ heading: string;
7
+ muted: string;
8
+ faint: string;
9
+ font: string;
10
+ };
11
+ /** Brand settings from `emailTemplates` options / `NUXT_EMAIL_TEMPLATES_*`. Read inside the renderer's SSR app. */
12
+ export declare function useEmailTheme(): {
13
+ brandName: string;
14
+ logoUrl: string;
15
+ primary: string;
16
+ danger: string;
17
+ };
@@ -0,0 +1,27 @@
1
+ import { useRuntimeConfig } from "nitropack/runtime";
2
+ export const tokens = {
3
+ page: "#f3f4f6",
4
+ // gray-100
5
+ card: "#ffffff",
6
+ border: "#e5e7eb",
7
+ // gray-200
8
+ text: "#374151",
9
+ // gray-700
10
+ heading: "#111827",
11
+ // gray-900
12
+ muted: "#6b7280",
13
+ // gray-500
14
+ faint: "#9ca3af",
15
+ // gray-400
16
+ font: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif"
17
+ };
18
+ export function useEmailTheme() {
19
+ const config = useRuntimeConfig().emailTemplates ?? {};
20
+ const logoUrl = config.logoUrl ? /^https?:\/\//.test(config.logoUrl) ? config.logoUrl : `${(config.siteUrl ?? "").replace(/\/$/, "")}${config.logoUrl}` : "";
21
+ return {
22
+ brandName: config.brandName || "Frigear",
23
+ logoUrl,
24
+ primary: config.colors?.primary || "#2563eb",
25
+ danger: config.colors?.danger || "#dc2626"
26
+ };
27
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Renders notifications that name a template (`notification.template`, set by modules for the
3
+ * emails they send) before notify hands them to the driver. A template that is missing or fails to
4
+ * render leaves the notification as built, so the module's plain fallback still goes out.
5
+ */
6
+ declare const _default: any;
7
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import { emailTemplates } from "#email-templates";
2
+ export default defineNitroPlugin((nitroApp) => {
3
+ nitroApp.hooks.hook("notify:email", async (context) => {
4
+ const template = context.notification.template;
5
+ if (!template || !(template.name in emailTemplates)) return;
6
+ try {
7
+ const name = template.name;
8
+ const rendered = await renderEmailTemplate(name, template.props ?? {}, {
9
+ locale: template.locale
10
+ });
11
+ context.notification = {
12
+ ...context.notification,
13
+ subject: rendered.subject ?? context.notification.subject,
14
+ body: rendered.body,
15
+ text: rendered.text ?? context.notification.text
16
+ };
17
+ } catch (error) {
18
+ console.error(`[@frigear-nu/email-templates] Rendering "${template.name}" failed; sending the fallback.`, error);
19
+ }
20
+ });
21
+ });
@@ -0,0 +1,25 @@
1
+ import type { EmailNotification } from '@frigear-nu/notify/types';
2
+ import type { EmailTemplateName, EmailTemplateProps, RenderedEmailTemplate } from '../../types.js';
3
+ export type RenderEmailTemplateOptions = {
4
+ /** Locale to render with, when `@nuxtjs/i18n` is installed. */
5
+ locale?: string;
6
+ /** Also render a plain-text body. Defaults to `true`. */
7
+ text?: boolean;
8
+ };
9
+ export type SendEmailTemplateMessage = Omit<EmailNotification, 'subject' | 'body' | 'text' | 'template'> & {
10
+ /** Overrides the template's `<ESubject>`. Required when the template has none. */
11
+ subject?: string;
12
+ /** A plain-text body of your own, or `false` to send HTML only. Rendered from the template by default. */
13
+ text?: string | false;
14
+ locale?: string;
15
+ };
16
+ /**
17
+ * Renders an email template (an SFC in `app/emails`, or one a module ships) to HTML, plus plain
18
+ * text unless `text: false`. Throws a 404 error when no template has that name.
19
+ */
20
+ export declare function renderEmailTemplate<N extends EmailTemplateName>(name: N, props: EmailTemplateProps<N>, options?: RenderEmailTemplateOptions): Promise<RenderedEmailTemplate>;
21
+ /**
22
+ * Renders an email template and sends it through `@frigear-nu/notify`'s configured driver. The
23
+ * subject comes from the template's `<ESubject>` unless `message.subject` is given.
24
+ */
25
+ export declare function sendEmailTemplate<N extends EmailTemplateName>(name: N, props: EmailTemplateProps<N>, message: SendEmailTemplateMessage): Promise<any>;
@@ -0,0 +1,24 @@
1
+ const toParts = (rendered) => typeof rendered === "string" ? { content: rendered, subject: void 0 } : { content: rendered.html, subject: rendered.subject };
2
+ export async function renderEmailTemplate(name, props, options = {}) {
3
+ const renderProps = props;
4
+ const html = toParts(await renderEmailComponent(name, renderProps, { locale: options.locale }));
5
+ if (!html.content.replace(/<!DOCTYPE[^>]*>/i, "").trim()) {
6
+ throw new Error(`[@frigear-nu/email-templates] Template "${name}" rendered nothing.`);
7
+ }
8
+ const text = options.text === false ? void 0 : toParts(await renderEmailComponent(name, renderProps, { locale: options.locale, plainText: true })).content;
9
+ return { subject: html.subject, body: html.content, text };
10
+ }
11
+ export async function sendEmailTemplate(name, props, message) {
12
+ const { subject: subjectOverride, text: textOverride, locale, ...rest } = message;
13
+ const rendered = await renderEmailTemplate(name, props, { locale, text: textOverride === void 0 });
14
+ const subject = subjectOverride ?? rendered.subject;
15
+ if (!subject) {
16
+ throw new Error(`[@frigear-nu/email-templates] Template "${name}" has no <ESubject>; pass \`subject\` to sendEmailTemplate.`);
17
+ }
18
+ return dispatchEmailNotification({
19
+ ...rest,
20
+ subject,
21
+ body: rendered.body,
22
+ text: textOverride === false ? void 0 : textOverride ?? rendered.text
23
+ });
24
+ }
@@ -0,0 +1,44 @@
1
+ import type { AllowedComponentProps, VNodeProps } from 'vue';
2
+ /**
3
+ * Template name -> props. Augmented by `.nuxt/types/email-templates.d.ts` from every template the
4
+ * renderer will see: module templates (`notify:email:templates`) and the host's/layers' `app/emails`.
5
+ */
6
+ export interface EmailTemplates {
7
+ }
8
+ export type EmailTemplateName = keyof EmailTemplates & string;
9
+ export type EmailTemplateProps<N extends EmailTemplateName> = EmailTemplates[N];
10
+ /** The props a template component declares (same as nuxt-email-renderer's `ExtractComponentProps`). */
11
+ export type TemplateComponentProps<TComponent> = TComponent extends new () => {
12
+ $props: infer P;
13
+ } ? Omit<P, keyof VNodeProps | keyof AllowedComponentProps> : never;
14
+ /** A scanned template file. Same shape as nuxt-email-renderer's template mapping entries. */
15
+ export type EmailTemplateFile = {
16
+ name: string;
17
+ filename: string;
18
+ displayName: string;
19
+ importPath: string;
20
+ filePath: string;
21
+ };
22
+ export type RenderedEmailTemplate = {
23
+ /** From the template's `<ESubject>`, when it has one. */
24
+ subject?: string;
25
+ /** HTML body. */
26
+ body: string;
27
+ /** Plain-text body, unless rendering it was turned off. */
28
+ text?: string;
29
+ };
30
+ /** Private `runtimeConfig.emailTemplates`, overridable through `NUXT_EMAIL_TEMPLATES_*` env vars. */
31
+ export type EmailTemplatesRuntimeConfig = {
32
+ /** `NUXT_EMAIL_TEMPLATES_BRAND_NAME`: logo alt text, and the header when there is no logo. */
33
+ brandName: string;
34
+ /** `NUXT_EMAIL_TEMPLATES_LOGO_URL`: absolute, or a path resolved against `siteUrl` (e.g. `/logo.png`). */
35
+ logoUrl: string;
36
+ /** `NUXT_EMAIL_TEMPLATES_SITE_URL`: base URL for a relative `logoUrl`. */
37
+ siteUrl: string;
38
+ colors: {
39
+ /** `NUXT_EMAIL_TEMPLATES_COLORS_PRIMARY`: buttons. */
40
+ primary: string;
41
+ /** `NUXT_EMAIL_TEMPLATES_COLORS_DANGER`: security alerts. */
42
+ danger: string;
43
+ };
44
+ };
File without changes
@@ -0,0 +1,5 @@
1
+ export { type EmailTemplateName, type EmailTemplateProps, type EmailTemplates, type EmailTemplatesRuntimeConfig, type RenderedEmailTemplate } from '../dist/runtime/types.js'
2
+
3
+ export { default } from './module.mjs'
4
+
5
+ export { type ModuleOptions } from './module.mjs'
package/package.json CHANGED
@@ -1,6 +1,76 @@
1
1
  {
2
2
  "name": "@frigear-nu/email-templates",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Vue email templates for @frigear-nu/notify, rendered with nuxt-email-renderer: typed sendEmailTemplate for hosts, module-owned templates hosts can override.",
5
+ "homepage": "https://docs.frigear.dev/modules/email-templates",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/frigear-nu/frigear-nu.git",
9
+ "directory": "packages/email-templates"
10
+ },
11
+ "license": "MIT",
12
+ "type": "module",
13
+ "main": "./dist/module.mjs",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/types.d.mts",
17
+ "import": "./dist/module.mjs",
18
+ "default": "./dist/module.mjs"
19
+ },
20
+ "./components": {
21
+ "types": "./dist/runtime/components/index.d.ts",
22
+ "import": "./dist/runtime/components/index.js",
23
+ "default": "./dist/runtime/components/index.js"
24
+ },
25
+ "./types": {
26
+ "types": "./dist/types.d.mts"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "workspaces": [
33
+ "playground"
34
+ ],
35
+ "dependencies": {
36
+ "@frigear-nu/module-kit": "1.2.0",
37
+ "@frigear-nu/notify": "0.2.0",
38
+ "@nuxt/kit": "^4.6.1",
39
+ "defu": "^6.1.7",
40
+ "nuxt-email-renderer": "^2.11.2"
41
+ },
42
+ "devDependencies": {
43
+ "@nuxt/devtools": "^3.4.2",
44
+ "@nuxt/eslint-config": "^1.17.0",
45
+ "@nuxt/module-builder": "^1.0.3",
46
+ "@nuxt/schema": "^4.6.1",
47
+ "@nuxt/test-utils": "^4.3.2",
48
+ "@types/node": "^26.6.5",
49
+ "changelogen": "^0.6.2",
50
+ "eslint": "^10.12.0",
51
+ "nuxt": "^4.6.1",
52
+ "typescript": "^6.0.3",
53
+ "vitest": "^5.0.2",
54
+ "vue-tsc": "^3.3.11"
55
+ },
56
+ "scripts": {
57
+ "postinstall": "nuxt-module-build build --stub && nuxt prepare",
58
+ "build": "nuxt-module-build build",
59
+ "dev": "npm run dev:prepare && nuxt dev playground",
60
+ "dev:build": "nuxt build playground",
61
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
62
+ "release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
63
+ "lint": "eslint .",
64
+ "lint:fix": "eslint . --fix",
65
+ "test": "vitest run",
66
+ "test:watch": "vitest watch",
67
+ "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
68
+ },
69
+ "typesVersions": {
70
+ "*": {
71
+ ".": [
72
+ "./dist/types.d.mts"
73
+ ]
74
+ }
75
+ }
6
76
  }