@frigear-nu/notify 0.0.11 → 0.1.1
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/dist/module.d.mts +40 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +16 -1
- package/dist/runtime/server/utils/dispatch.js +3 -1
- package/dist/types.d.mts +1 -1
- package/package.json +7 -4
package/dist/module.d.mts
CHANGED
|
@@ -39,8 +39,40 @@ interface EmailNotification<M = NotificationMeta> {
|
|
|
39
39
|
text?: string;
|
|
40
40
|
/** Address replies should go to (the `Reply-To` header). */
|
|
41
41
|
replyTo?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Template to render this email from instead of `subject`/`body`/`text`, when a renderer is
|
|
44
|
+
* installed (`@frigear-nu/email-templates` listens on the `notify:email` hook). Without one,
|
|
45
|
+
* the notification goes out as built, so `subject` and `body` are always the fallback.
|
|
46
|
+
*/
|
|
47
|
+
template?: EmailTemplateRef;
|
|
42
48
|
meta?: M;
|
|
43
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* A template to render an email from: its name (the template's file name, e.g. `auth-magic-link`)
|
|
52
|
+
* and the props to render it with. Deliberately untyped here: the names only exist once a
|
|
53
|
+
* renderer has scanned the templates (see `sendEmailTemplate` in `@frigear-nu/email-templates`).
|
|
54
|
+
*/
|
|
55
|
+
type EmailTemplateRef = {
|
|
56
|
+
name: string;
|
|
57
|
+
props?: Record<string, unknown>;
|
|
58
|
+
/** Locale to render with, when the renderer has i18n. */
|
|
59
|
+
locale?: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* A directory of email templates (top-level `*.vue` files, named by file name) that a module
|
|
63
|
+
* ships, registered through the `notify:email:templates` Nuxt hook. Only used when a renderer
|
|
64
|
+
* (`@frigear-nu/email-templates`) is installed; host templates with the same name win.
|
|
65
|
+
*/
|
|
66
|
+
type EmailTemplateSource = {
|
|
67
|
+
dir: string;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Passed to the `notify:email` Nitro hook before an email is handed to the driver. Listeners may
|
|
71
|
+
* replace or mutate `notification`, e.g. to render `notification.template`.
|
|
72
|
+
*/
|
|
73
|
+
type NotifyEmailContext = {
|
|
74
|
+
notification: EmailNotification;
|
|
75
|
+
};
|
|
44
76
|
/**
|
|
45
77
|
* A driver is anything that knows how to actually deliver an `EmailNotification` - log it,
|
|
46
78
|
* hand it to Resend, talk to an SMTP server, etc. Keeping the signature this small makes it
|
|
@@ -96,8 +128,15 @@ declare module '@nuxt/schema' {
|
|
|
96
128
|
interface RuntimeConfig {
|
|
97
129
|
notify: NotifyRuntimeConfig;
|
|
98
130
|
}
|
|
131
|
+
interface NuxtHooks {
|
|
132
|
+
/**
|
|
133
|
+
* Modules push the directories of email templates they ship (see `EmailTemplateSource`).
|
|
134
|
+
* Called by `@frigear-nu/email-templates`; without it, nothing reads them.
|
|
135
|
+
*/
|
|
136
|
+
'notify:email:templates': (sources: EmailTemplateSource[]) => void | Promise<void>;
|
|
137
|
+
}
|
|
99
138
|
}
|
|
100
139
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
101
140
|
|
|
102
141
|
export { _default as default };
|
|
103
|
-
export type { EmailDriver, EmailNotification, ModuleOptions, SMSDriver, SMSNotification, SimpleDriver, SimpleNotification };
|
|
142
|
+
export type { EmailDriver, EmailNotification, EmailTemplateRef, EmailTemplateSource, ModuleOptions, NotifyEmailContext, SMSDriver, SMSNotification, SimpleDriver, SimpleNotification };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addServerImportsDir, addServerTemplate
|
|
1
|
+
import { defineNuxtModule, createResolver, addTypeTemplate, addServerImportsDir, addServerTemplate } from '@nuxt/kit';
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
import { joinURL } from 'ufo';
|
|
4
4
|
|
|
@@ -56,6 +56,21 @@ const module$1 = defineNuxtModule({
|
|
|
56
56
|
registerServerDriver("email-driver", "EmailDriver", emailBuiltin ? "auto" : emailDriver, { auto: AUTO_EMAIL_DRIVER });
|
|
57
57
|
registerServerDriver("sms-driver", "SMSDriver", options.sms?.driver ?? "log");
|
|
58
58
|
registerServerDriver("simple-driver", "SimpleDriver", options.simple?.driver ?? "log");
|
|
59
|
+
addTypeTemplate({
|
|
60
|
+
filename: "types/notify-hooks.d.ts",
|
|
61
|
+
getContents: () => `declare module 'nitropack/types' {
|
|
62
|
+
interface NitroRuntimeHooks {
|
|
63
|
+
/**
|
|
64
|
+
* Called by \`dispatchEmailNotification\` before the driver sends the email. Listeners may
|
|
65
|
+
* replace \`ctx.notification\`, e.g. \`@frigear-nu/email-templates\` renders its \`template\`.
|
|
66
|
+
*/
|
|
67
|
+
'notify:email': (ctx: import(${JSON.stringify(resolver.resolve("./types"))}).NotifyEmailContext) => void | Promise<void>
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export {}
|
|
72
|
+
`
|
|
73
|
+
}, { nitro: true, nuxt: true });
|
|
59
74
|
addServerImportsDir(resolver.resolve("./runtime/server/utils"));
|
|
60
75
|
}
|
|
61
76
|
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import smsDriver from "#notify/sms-driver";
|
|
2
2
|
import simpleDriver from "#notify/simple-driver";
|
|
3
3
|
export async function dispatchEmailNotification(notification) {
|
|
4
|
-
|
|
4
|
+
const context = { notification };
|
|
5
|
+
await useNitroApp().hooks.callHook("notify:email", context);
|
|
6
|
+
return import("#notify/email-driver").then(({ default: emailDriver }) => emailDriver(context.notification));
|
|
5
7
|
}
|
|
6
8
|
export async function dispatchSMSNotification(notification) {
|
|
7
9
|
await smsDriver(notification);
|
package/dist/types.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { default } from './module.mjs'
|
|
2
2
|
|
|
3
|
-
export { type EmailDriver, type EmailNotification, type ModuleOptions, type SMSDriver, type SMSNotification, type SimpleDriver, type SimpleNotification } from './module.mjs'
|
|
3
|
+
export { type EmailDriver, type EmailNotification, type EmailTemplateRef, type EmailTemplateSource, type ModuleOptions, type NotifyEmailContext, type SMSDriver, type SMSNotification, type SimpleDriver, type SimpleNotification } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/notify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Email, SMS and generic notification dispatch (pluggable drivers) Nuxt module, shared across Frigear modules.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,13 +15,16 @@
|
|
|
15
15
|
".": {
|
|
16
16
|
"types": "./dist/types.d.mts",
|
|
17
17
|
"import": "./dist/module.mjs"
|
|
18
|
+
},
|
|
19
|
+
"./types": {
|
|
20
|
+
"types": "./dist/types.d.mts"
|
|
18
21
|
}
|
|
19
22
|
},
|
|
20
23
|
"files": [
|
|
21
24
|
"dist"
|
|
22
25
|
],
|
|
23
26
|
"dependencies": {
|
|
24
|
-
"@nuxt/kit": "^4.6.
|
|
27
|
+
"@nuxt/kit": "^4.6.1",
|
|
25
28
|
"defu": "^6.1.7",
|
|
26
29
|
"ufo": "^1.6.4"
|
|
27
30
|
},
|
|
@@ -29,12 +32,12 @@
|
|
|
29
32
|
"@nuxt/devtools": "^3.4.2",
|
|
30
33
|
"@nuxt/eslint-config": "^1.17.0",
|
|
31
34
|
"@nuxt/module-builder": "^1.0.3",
|
|
32
|
-
"@nuxt/schema": "^4.6.
|
|
35
|
+
"@nuxt/schema": "^4.6.1",
|
|
33
36
|
"@nuxt/test-utils": "^4.3.2",
|
|
34
37
|
"eslint": "^10.12.0",
|
|
35
38
|
"typescript": "^6.0.3",
|
|
36
39
|
"nuxt": "^4.6.1",
|
|
37
|
-
"vitest": "^5.0.
|
|
40
|
+
"vitest": "^5.0.2",
|
|
38
41
|
"vue-tsc": "^3.3.11"
|
|
39
42
|
},
|
|
40
43
|
"scripts": {
|