@frigear-nu/notify 0.3.1 → 0.3.3
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
CHANGED
|
@@ -240,9 +240,13 @@ type NotifyUserInput = {
|
|
|
240
240
|
template?: EmailTemplateRef;
|
|
241
241
|
meta?: Record<string, unknown>;
|
|
242
242
|
};
|
|
243
|
-
/**
|
|
243
|
+
/**
|
|
244
|
+
* The text of an SMS, or one per locale (the recipient's locale picks it). `meta` goes to the SMS driver, after
|
|
245
|
+
* `source` (the topic's module: `shifts` for `shifts.reminder`) and `topic`, so an SMS log can say who sent it.
|
|
246
|
+
*/
|
|
244
247
|
sms?: {
|
|
245
248
|
body: Translated;
|
|
249
|
+
meta?: Record<string, unknown>;
|
|
246
250
|
};
|
|
247
251
|
/** The push notification, through notify's push driver (`dispatchPushNotification`). */
|
|
248
252
|
push?: {
|
|
@@ -250,6 +254,7 @@ type NotifyUserInput = {
|
|
|
250
254
|
body: Translated;
|
|
251
255
|
url?: string;
|
|
252
256
|
data?: Record<string, string>;
|
|
257
|
+
meta?: Record<string, unknown>;
|
|
253
258
|
};
|
|
254
259
|
};
|
|
255
260
|
type NotifyUserResult = {
|
package/dist/module.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ChannelSettings, NotificationChannelsDto, NotificationTopic, NotifyUserInput, NotifyUserResult } from '../../../types.js';
|
|
2
2
|
/** The topics modules registered with `extendNotificationTopics`. */
|
|
3
3
|
export declare const registeredNotificationTopics: () => readonly NotificationTopic[];
|
|
4
|
+
/** The module of a topic: its first segment (`shifts` for `shifts.reminder`). */
|
|
5
|
+
export declare const notificationTopicSource: (topicId: string) => string;
|
|
4
6
|
export declare const findNotificationTopic: (id: string) => NotificationTopic | undefined;
|
|
5
7
|
/** Every registered topic with what applies to the user (their choice, or the topic's defaults). */
|
|
6
8
|
export declare function readNotificationChannels(userId: number): Promise<NotificationChannelsDto>;
|
|
@@ -9,6 +9,7 @@ function warnOnce(key, message) {
|
|
|
9
9
|
console.warn(`[@frigear-nu/notify] ${message}`);
|
|
10
10
|
}
|
|
11
11
|
export const registeredNotificationTopics = () => topics;
|
|
12
|
+
export const notificationTopicSource = (topicId) => topicId.split(".")[0] || topicId;
|
|
12
13
|
export const findNotificationTopic = (id) => topics.find((topic) => topic.id === id);
|
|
13
14
|
async function readStoredChoices(userId) {
|
|
14
15
|
if (!choicesStore) {
|
|
@@ -58,6 +59,7 @@ export async function notifyUser(userId, input) {
|
|
|
58
59
|
}
|
|
59
60
|
const [recipient, choices] = await Promise.all([recipientStore.findRecipient(userId), readStoredChoices(userId)]);
|
|
60
61
|
const settings = resolveChannelSettings(topic, choices[topic.id]);
|
|
62
|
+
const origin = { source: notificationTopicSource(topic.id), topic: topic.id };
|
|
61
63
|
const locale = recipient?.locale || "en";
|
|
62
64
|
const run = async (channel, send) => {
|
|
63
65
|
if (!offered.includes(channel) || !settings[channel]) {
|
|
@@ -91,18 +93,19 @@ export async function notifyUser(userId, input) {
|
|
|
91
93
|
...replyTo !== void 0 ? { replyTo } : {},
|
|
92
94
|
...headers !== void 0 ? { headers } : {},
|
|
93
95
|
...template !== void 0 ? { template: template.locale || !recipient.locale ? template : { ...template, locale: recipient.locale } } : {},
|
|
94
|
-
|
|
96
|
+
meta: { topic: topic.id, ...meta }
|
|
95
97
|
});
|
|
96
98
|
return true;
|
|
97
99
|
});
|
|
98
100
|
await run("sms", async () => {
|
|
99
101
|
if (!recipient?.phone || !input.sms) return false;
|
|
100
|
-
await dispatchSMSNotification({ to: recipient.phone, body: readTranslated(input.sms.body, locale) });
|
|
102
|
+
await dispatchSMSNotification({ to: recipient.phone, body: readTranslated(input.sms.body, locale), meta: { ...origin, ...input.sms.meta } });
|
|
101
103
|
return true;
|
|
102
104
|
});
|
|
103
105
|
await run("push", async () => {
|
|
104
106
|
if (!input.push) return false;
|
|
105
|
-
const
|
|
107
|
+
const { meta, ...push } = input.push;
|
|
108
|
+
const sent = await dispatchPushNotification({ userIds: [userId], ...push, meta: { ...origin, ...meta } });
|
|
106
109
|
return sent === void 0 || sent.sent > 0;
|
|
107
110
|
});
|
|
108
111
|
return result;
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/notify",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Email, SMS, push and generic notification dispatch (pluggable drivers), and notifyUser: per-user channel choices over a topic registry. Shared across Frigear modules.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"frigear-module",
|
|
8
|
+
"nuxt-module"
|
|
9
|
+
],
|
|
6
10
|
"license": "MIT",
|
|
7
11
|
"homepage": "https://docs.frigear.dev/modules/communication/notify",
|
|
8
12
|
"repository": {
|
|
@@ -30,7 +34,7 @@
|
|
|
30
34
|
],
|
|
31
35
|
"dependencies": {
|
|
32
36
|
"@nuxt/kit": "^4.6.4",
|
|
33
|
-
"@frigear-nu/module-kit": "^1.3.
|
|
37
|
+
"@frigear-nu/module-kit": "^1.3.13",
|
|
34
38
|
"defu": "^6.1.7",
|
|
35
39
|
"ufo": "^1.6.4"
|
|
36
40
|
},
|