@mikstack/notifications 0.1.0 → 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/index.d.ts +3 -3
- package/dist/index.js +3 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ interface InAppContent {
|
|
|
13
13
|
icon?: string;
|
|
14
14
|
}
|
|
15
15
|
interface ChannelSendParams {
|
|
16
|
-
userId: string;
|
|
16
|
+
userId: string | null;
|
|
17
17
|
type: string;
|
|
18
18
|
content: EmailContent | InAppContent;
|
|
19
19
|
recipientEmail?: string;
|
|
@@ -48,11 +48,11 @@ interface NotificationDefinition<TKey extends string = string, TData = unknown>
|
|
|
48
48
|
type NotificationDefinitions = Record<string, NotificationDefinition<string, never>>;
|
|
49
49
|
type SendParams<TDefs extends NotificationDefinitions> = { [K in keyof TDefs & string]: TDefs[K] extends NotificationDefinition<string, infer TData> ? TData extends Record<string, never> ? {
|
|
50
50
|
type: K;
|
|
51
|
-
userId
|
|
51
|
+
userId?: string;
|
|
52
52
|
recipientEmail?: string;
|
|
53
53
|
} : {
|
|
54
54
|
type: K;
|
|
55
|
-
userId
|
|
55
|
+
userId?: string;
|
|
56
56
|
data: TData;
|
|
57
57
|
recipientEmail?: string;
|
|
58
58
|
} : never }[keyof TDefs & string];
|
package/dist/index.js
CHANGED
|
@@ -182,7 +182,7 @@ function createNotifications(config) {
|
|
|
182
182
|
const def = notifications[params.type];
|
|
183
183
|
if (!def) throw new NotificationError(`Notification type "${params.type}" is not defined.`);
|
|
184
184
|
let userPrefs = [];
|
|
185
|
-
if (!def.critical) userPrefs = await getPreferences({
|
|
185
|
+
if (!def.critical && params.userId) userPrefs = await getPreferences({
|
|
186
186
|
db,
|
|
187
187
|
schema,
|
|
188
188
|
tableNames,
|
|
@@ -202,7 +202,7 @@ function createNotifications(config) {
|
|
|
202
202
|
schema,
|
|
203
203
|
tableNames
|
|
204
204
|
}, {
|
|
205
|
-
userId: params.userId,
|
|
205
|
+
userId: params.userId ?? null,
|
|
206
206
|
type: params.type,
|
|
207
207
|
channel: channelName,
|
|
208
208
|
content,
|
|
@@ -312,6 +312,7 @@ function inAppChannel() {
|
|
|
312
312
|
init(ctx) {
|
|
313
313
|
const table = getTable(ctx.schema, ctx.tableNames.inAppNotification, "inAppNotification");
|
|
314
314
|
return { async send(params) {
|
|
315
|
+
if (!params.userId) return {};
|
|
315
316
|
const content = params.content;
|
|
316
317
|
const id = crypto.randomUUID();
|
|
317
318
|
await ctx.db.insert(table).values({
|