@rpcbase/server 0.620.0 → 0.622.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.
@@ -114,7 +114,7 @@ var createNotification = async (ctx, input, ability) => {
114
114
  tag: notification.tag,
115
115
  archivedAt: { $exists: false }
116
116
  }, notification, {
117
- new: true,
117
+ returnDocument: "after",
118
118
  upsert: true,
119
119
  sort: {
120
120
  drawerActive: -1,
@@ -146,7 +146,7 @@ var createNotificationsForUser = async (ctx, input, ability) => {
146
146
  tag: document.tag,
147
147
  archivedAt: { $exists: false }
148
148
  }, document, {
149
- new: true,
149
+ returnDocument: "after",
150
150
  upsert: true,
151
151
  sort: {
152
152
  drawerActive: -1,
@@ -1 +1 @@
1
- {"version":3,"file":"notifications.js","names":["routes","Object","entries","import","meta","glob","reduce","Record","acc","path","mod","replace","randomUUID","Ctx","models","IRBNotificationPlatformPayload","AppAbility","NotificationDataPayload","Record","NotificationMetadataPayload","NotificationPlatformPayload","NotificationUrlMode","CreateNotificationInput","userId","topic","tag","title","body","image","url","urlMode","metadata","data","platform","CreateNotificationForUserInput","Omit","CreateNotificationsForUserInput","notifications","normalizeRequiredString","value","name","normalized","trim","Error","normalizeOptionalString","undefined","normalizeUrlMode","isRecord","Boolean","Array","isArray","toNotificationDataString","trimmed","Number","isFinite","String","toString","Date","getTime","toISOString","normalizeNotificationActionLink","normalizedUrl","parsed","URL","search","hash","startsWith","buildNotificationData","input","Pick","link","key","Object","entries","assign","linkMode","keys","length","buildNotificationPlatform","webpush","fcmOptions","createNotificationDocument","deliveryId","drawerActive","createdAt","assertCreateNotificationsForUserInput","createNotification","ctx","ability","Promise","id","can","modelCtx","req","NotificationModel","NotificationDeliveryModel","all","getUnsafe","notification","delivery","create","doc","findOneAndReplace","archivedAt","$exists","new","upsert","sort","updateOne","_id","$set","notificationId","createNotificationsForUser","ids","document","push","Ctx","models","IRBNotification","IRBNotificationSettings","AppAbility","Model","sendEmail","DAY_MS","WEEK_MS","DigestFrequency","NotificationDoc","_id","SettingsDoc","isDuplicateKeyError","error","Boolean","code","markDigestSent","SettingsModel","userId","lastDigestSentAt","Date","Promise","update","$set","result","updateOne","matchedCount","create","digestFrequency","getDigestWindowMs","frequency","formatIso","value","undefined","toISOString","getNotificationLink","notification","dataLink","data","link","trim","platform","Array","isArray","webpush","fcmOptions","buildPreferencesByTopic","settings","Record","emailDigest","record","raw","topicPreferences","pref","topic","sendNotificationsDigestForUser","ctx","ability","force","ok","sent","skippedReason","modelCtx","req","get","NotificationModel","findOne","lean","digestFrequencyRaw","now","windowMs","lastSentAt","since","getTime","preferencesByTopic","disabledTopics","Object","entries","filter","map","query","archivedAt","$exists","readAt","createdAt","$gt","length","$nin","notifications","find","sort","limit","UserModel","getGlobal","user","findById","email","subject","rows","n","title","body","url","line","join","html","emailResult","to","missingTransport","Error","message","skipped"],"sources":["../src/notifications/routes.ts","../src/notifications/createNotification.ts","../src/notifications/digest.ts"],"sourcesContent":["export const routes = Object.entries({\n ...import.meta.glob(\"./api/**/handler.ts\"),\n}).reduce<Record<string, unknown>>((acc, [path, mod]) => {\n acc[path.replace(\"./api/\", \"@rpcbase/server/notifications/api/\")] = mod\n return acc\n}, {})\n\n","import { randomUUID } from \"node:crypto\"\n\nimport type { Ctx } from \"@rpcbase/api\"\nimport { models, type IRBNotificationPlatformPayload } from \"@rpcbase/db\"\nimport type { AppAbility } from \"@rpcbase/db/acl\"\n\n\nexport type NotificationDataPayload = Record<string, string>\nexport type NotificationMetadataPayload = Record<string, unknown>\nexport type NotificationPlatformPayload = IRBNotificationPlatformPayload\nexport type NotificationUrlMode = \"navigate\" | \"merge_current_search\"\n\nexport type CreateNotificationInput = {\n userId: string\n topic?: string\n tag?: string\n title: string\n body?: string\n image?: string\n url?: string\n urlMode?: NotificationUrlMode\n metadata?: NotificationMetadataPayload\n data?: NotificationDataPayload\n platform?: NotificationPlatformPayload\n}\n\nexport type CreateNotificationForUserInput = Omit<CreateNotificationInput, \"userId\">\n\nexport type CreateNotificationsForUserInput = {\n userId: string\n notifications: CreateNotificationForUserInput[]\n}\n\nconst normalizeRequiredString = (value: unknown, name: string): string => {\n const normalized = typeof value === \"string\" ? value.trim() : \"\"\n if (!normalized) {\n throw new Error(`${name} is required`)\n }\n return normalized\n}\n\nconst normalizeOptionalString = (value: string | undefined): string | undefined => {\n const normalized = typeof value === \"string\" ? value.trim() : \"\"\n return normalized || undefined\n}\n\nconst normalizeUrlMode = (value: unknown): NotificationUrlMode => {\n return value === \"merge_current_search\" ? \"merge_current_search\" : \"navigate\"\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n Boolean(value) && typeof value === \"object\" && !Array.isArray(value)\n\nconst toNotificationDataString = (value: unknown): string | undefined => {\n if (typeof value === \"string\") {\n const trimmed = value.trim()\n return trimmed || undefined\n }\n if (typeof value === \"number\" && Number.isFinite(value)) return String(value)\n if (typeof value === \"boolean\") return String(value)\n if (typeof value === \"bigint\") return value.toString()\n if (value instanceof Date && Number.isFinite(value.getTime())) return value.toISOString()\n return undefined\n}\n\nconst normalizeNotificationActionLink = (url: string | undefined, urlMode: NotificationUrlMode): string | undefined => {\n const normalizedUrl = normalizeOptionalString(url)\n if (!normalizedUrl) return undefined\n if (urlMode === \"navigate\") return normalizedUrl\n\n try {\n const parsed = new URL(normalizedUrl, \"https://rpcbase.local/\")\n return `${parsed.search}${parsed.hash}` || undefined\n } catch {\n return normalizedUrl.startsWith(\"?\") ? normalizedUrl : undefined\n }\n}\n\nconst buildNotificationData = (\n input: Pick<CreateNotificationInput, \"data\" | \"metadata\"> & { link?: string; urlMode: NotificationUrlMode },\n): NotificationDataPayload | undefined => {\n const data: NotificationDataPayload = {}\n\n for (const [key, value] of Object.entries(input.metadata ?? {})) {\n const normalized = toNotificationDataString(value)\n if (normalized) {\n data[key] = normalized\n }\n }\n\n if (input.data) {\n Object.assign(data, input.data)\n }\n\n if (input.link) {\n data.link = input.link\n if (input.urlMode !== \"navigate\") {\n data.linkMode = input.urlMode\n }\n }\n\n return Object.keys(data).length > 0 ? data : undefined\n}\n\nconst buildNotificationPlatform = (\n platform: NotificationPlatformPayload | undefined,\n link: string | undefined,\n): NotificationPlatformPayload | undefined => {\n if (!link) return platform\n\n const webpush = isRecord(platform?.webpush) ? platform.webpush : {}\n const fcmOptions = isRecord(webpush.fcmOptions) ? webpush.fcmOptions : {}\n\n return {\n ...platform,\n webpush: {\n ...webpush,\n fcmOptions: {\n ...fcmOptions,\n link,\n },\n },\n }\n}\n\nconst createNotificationDocument = (input: CreateNotificationInput) => {\n const userId = normalizeRequiredString(input.userId, \"createNotification: userId\")\n const title = normalizeRequiredString(input.title, \"createNotification: title\")\n const topic = normalizeOptionalString(input.topic)\n const tag = normalizeOptionalString(input.tag)\n const body = normalizeOptionalString(input.body)\n const image = normalizeOptionalString(input.image)\n const urlMode = normalizeUrlMode(input.urlMode)\n const link = normalizeNotificationActionLink(input.url, urlMode)\n const data = buildNotificationData({ data: input.data, metadata: input.metadata, link, urlMode })\n const platform = buildNotificationPlatform(input.platform, link)\n\n return {\n userId,\n ...(topic ? { topic } : {}),\n ...(tag ? { tag } : {}),\n deliveryId: randomUUID(),\n title,\n ...(body ? { body } : {}),\n ...(image ? { image } : {}),\n ...(data ? { data } : {}),\n ...(platform ? { platform } : {}),\n drawerActive: true,\n createdAt: new Date(),\n }\n}\n\nconst assertCreateNotificationsForUserInput = (input: CreateNotificationsForUserInput): void => {\n if (typeof input.userId !== \"string\" || input.userId.trim().length === 0) {\n throw new Error(\"createNotificationsForUser: userId is required\")\n }\n if (!Array.isArray(input.notifications)) {\n throw new Error(\"createNotificationsForUser: notifications must be an array\")\n }\n}\n\nexport const createNotification = async (\n ctx: Ctx,\n input: CreateNotificationInput,\n ability: AppAbility,\n): Promise<{ id: string }> => {\n if (!ability.can(\"create\", \"RBNotification\")) {\n throw new Error(\"createNotification: forbidden\")\n }\n\n const modelCtx = { req: ctx.req, ability }\n const [NotificationModel, NotificationDeliveryModel] = await Promise.all([\n models.getUnsafe(\"RBNotification\", modelCtx),\n models.getUnsafe(\"RBNotificationDelivery\", modelCtx),\n ])\n const notification = createNotificationDocument(input)\n const delivery = await NotificationDeliveryModel.create(notification)\n const doc = notification.tag\n ? await NotificationModel.findOneAndReplace(\n { userId: notification.userId, tag: notification.tag, archivedAt: { $exists: false } },\n notification,\n { new: true, upsert: true, sort: { drawerActive: -1, createdAt: -1 } },\n )\n : await NotificationModel.create(notification)\n\n if (!doc) {\n throw new Error(\"createNotification: failed to persist notification\")\n }\n\n await NotificationDeliveryModel.updateOne(\n { _id: delivery._id },\n { $set: { notificationId: doc._id.toString() } },\n )\n\n return { id: doc._id.toString() }\n}\n\nexport const createNotificationsForUser = async (\n ctx: Ctx,\n input: CreateNotificationsForUserInput,\n ability: AppAbility,\n): Promise<{ ids: string[] }> => {\n assertCreateNotificationsForUserInput(input)\n if (input.notifications.length === 0) {\n return { ids: [] }\n }\n\n if (!ability.can(\"create\", \"RBNotification\")) {\n throw new Error(\"createNotificationsForUser: forbidden\")\n }\n\n const modelCtx = { req: ctx.req, ability }\n const [NotificationModel, NotificationDeliveryModel] = await Promise.all([\n models.getUnsafe(\"RBNotification\", modelCtx),\n models.getUnsafe(\"RBNotificationDelivery\", modelCtx),\n ])\n const ids: string[] = []\n for (const notification of input.notifications) {\n const document = createNotificationDocument({\n ...notification,\n userId: input.userId,\n })\n const delivery = await NotificationDeliveryModel.create(document)\n const doc = document.tag\n ? await NotificationModel.findOneAndReplace(\n { userId: document.userId, tag: document.tag, archivedAt: { $exists: false } },\n document,\n { new: true, upsert: true, sort: { drawerActive: -1, createdAt: -1 } },\n )\n : await NotificationModel.create(document)\n\n if (!doc) {\n throw new Error(\"createNotificationsForUser: failed to persist notification\")\n }\n await NotificationDeliveryModel.updateOne(\n { _id: delivery._id },\n { $set: { notificationId: doc._id.toString() } },\n )\n ids.push(doc._id.toString())\n }\n\n return { ids }\n}\n","import type { Ctx } from \"@rpcbase/api\"\nimport { models, type IRBNotification, type IRBNotificationSettings } from \"@rpcbase/db\"\nimport type { AppAbility } from \"@rpcbase/db/acl\"\nimport type { Model } from \"mongoose\"\n\nimport { sendEmail } from \"../email\"\n\n\nconst DAY_MS = 24 * 60 * 60 * 1000\nconst WEEK_MS = 7 * DAY_MS\n\ntype DigestFrequency = \"off\" | \"daily\" | \"weekly\"\n\ntype NotificationDoc = IRBNotification & { _id: unknown }\ntype SettingsDoc = IRBNotificationSettings & { _id: unknown }\n\nconst isDuplicateKeyError = (error: unknown): boolean =>\n Boolean(error && typeof error === \"object\" && \"code\" in error && error.code === 11000)\n\nconst markDigestSent = async (\n SettingsModel: Model<IRBNotificationSettings>,\n userId: string,\n lastDigestSentAt: Date,\n): Promise<void> => {\n const update = { $set: { lastDigestSentAt } }\n const result = await SettingsModel.updateOne({ userId }, update)\n if (result.matchedCount > 0) return\n\n try {\n await SettingsModel.create({\n userId,\n digestFrequency: \"weekly\",\n lastDigestSentAt,\n })\n } catch (error) {\n if (!isDuplicateKeyError(error)) throw error\n await SettingsModel.updateOne({ userId }, update)\n }\n}\n\nconst getDigestWindowMs = (frequency: DigestFrequency): number => {\n if (frequency === \"daily\") return DAY_MS\n if (frequency === \"weekly\") return WEEK_MS\n return 0\n}\n\nconst formatIso = (value: unknown): string | undefined => {\n if (!(value instanceof Date)) return undefined\n return value.toISOString()\n}\n\nconst getNotificationLink = (notification: NotificationDoc): string => {\n const dataLink = notification.data?.link?.trim()\n if (dataLink) return dataLink\n\n const platform = notification.platform\n if (!platform || typeof platform !== \"object\" || Array.isArray(platform)) return \"\"\n const webpush = (platform as { webpush?: unknown }).webpush\n if (!webpush || typeof webpush !== \"object\" || Array.isArray(webpush)) return \"\"\n const fcmOptions = (webpush as { fcmOptions?: unknown }).fcmOptions\n if (!fcmOptions || typeof fcmOptions !== \"object\" || Array.isArray(fcmOptions)) return \"\"\n const link = (fcmOptions as { link?: unknown }).link\n return typeof link === \"string\" ? link.trim() : \"\"\n}\n\nconst buildPreferencesByTopic = (settings: SettingsDoc | null): Record<string, { emailDigest: boolean }> => {\n const record: Record<string, { emailDigest: boolean }> = {}\n const raw = settings?.topicPreferences\n if (!Array.isArray(raw)) return record\n for (const pref of raw) {\n if (!pref || typeof pref !== \"object\") continue\n const topic = typeof (pref as { topic?: unknown }).topic === \"string\" ? (pref as { topic: string }).topic.trim() : \"\"\n if (!topic) continue\n const emailDigest = (pref as { emailDigest?: unknown }).emailDigest\n record[topic] = { emailDigest: emailDigest === true }\n }\n return record\n}\n\nexport const sendNotificationsDigestForUser = async (\n ctx: Ctx,\n {\n userId,\n ability,\n force = false,\n }: {\n userId: string\n ability: AppAbility\n force?: boolean\n },\n): Promise<{ ok: true; sent: boolean; skippedReason?: string } | { ok: false; error: string }> => {\n const modelCtx = { req: ctx.req, ability }\n const SettingsModel = await models.get(\n \"RBNotificationSettings\",\n modelCtx,\n ) as Model<IRBNotificationSettings>\n const NotificationModel = await models.get(\"RBNotification\", modelCtx)\n\n const settings = (await SettingsModel.findOne({ userId }).lean()) as SettingsDoc | null\n\n const digestFrequencyRaw = typeof settings?.digestFrequency === \"string\" ? settings.digestFrequency : \"weekly\"\n const digestFrequency: DigestFrequency =\n digestFrequencyRaw === \"daily\" || digestFrequencyRaw === \"weekly\" || digestFrequencyRaw === \"off\"\n ? digestFrequencyRaw\n : \"weekly\"\n\n if (digestFrequency === \"off\") {\n return { ok: true, sent: false, skippedReason: \"digest_off\" }\n }\n\n const now = new Date()\n const windowMs = getDigestWindowMs(digestFrequency)\n const lastSentAt = settings?.lastDigestSentAt instanceof Date ? settings.lastDigestSentAt : null\n const since = lastSentAt ?? new Date(now.getTime() - windowMs)\n\n if (!force && lastSentAt && now.getTime() - lastSentAt.getTime() < windowMs) {\n return { ok: true, sent: false, skippedReason: \"not_due\" }\n }\n\n const preferencesByTopic = buildPreferencesByTopic(settings)\n const disabledTopics = Object.entries(preferencesByTopic)\n .filter(([, pref]) => pref.emailDigest === false)\n .map(([topic]) => topic)\n\n const query: Record<string, unknown> = {\n userId,\n archivedAt: { $exists: false },\n readAt: { $exists: false },\n createdAt: { $gt: since },\n }\n\n if (disabledTopics.length > 0) {\n query.topic = { $nin: disabledTopics }\n }\n\n const notifications = (await NotificationModel.find(query)\n .sort({ createdAt: -1 })\n .limit(50)\n .lean()) as NotificationDoc[]\n\n if (!notifications.length) {\n await markDigestSent(SettingsModel, userId, now)\n return { ok: true, sent: false, skippedReason: \"empty\" }\n }\n\n const UserModel = await models.getGlobal(\"RBUser\", ctx)\n const user = (await UserModel.findById(userId, { email: 1 }).lean()) as { email?: unknown } | null\n const email = typeof user?.email === \"string\" ? user.email.trim() : \"\"\n if (!email) {\n return { ok: true, sent: false, skippedReason: \"missing_email\" }\n }\n\n const subject = \"Notifications digest\"\n const rows = notifications\n .map((n) => {\n const title = typeof n.title === \"string\" ? n.title : \"\"\n const body = typeof n.body === \"string\" ? n.body : \"\"\n const url = getNotificationLink(n)\n const createdAt = formatIso(n.createdAt) ?? \"\"\n const line = url\n ? `<li><strong>${title}</strong><br>${body}<br><a href=\"${url}\">${url}</a><br><small>${createdAt}</small></li>`\n : `<li><strong>${title}</strong><br>${body}<br><small>${createdAt}</small></li>`\n return line\n })\n .join(\"\")\n\n const html = `<div><p>Here is your notifications digest:</p><ul>${rows}</ul></div>`\n\n let emailResult\n try {\n emailResult = await sendEmail(\n { to: email, subject, html },\n { missingTransport: \"skip\" },\n )\n } catch (error) {\n return {\n ok: false,\n error: error instanceof Error ? error.message : \"Email delivery failed\",\n }\n }\n\n await markDigestSent(SettingsModel, userId, now)\n\n return { ok: true, sent: emailResult.skipped !== true, ...(emailResult.skipped ? { skippedReason: \"email_skipped\" } : {}) }\n}\n"],"mappings":";;;;AAAA,IAAaA,SAASC,OAAOC,QAAQ,EACnC,GAAGC,uBAAAA,OAAAA,EAAAA,wCAAAA,OAAAA,yBAAAA,CAAAA,EACL,CAAC,CAAC,CAACG,QAAiCE,KAAK,CAACC,MAAMC,SAAS;CACvDF,IAAIC,KAAKE,QAAQ,UA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EAAElD,eAAe,gBAAgB,IAAI,CAAC;CAAG;AAC5H"}
1
+ {"version":3,"file":"notifications.js","names":["routes","Object","entries","import","meta","glob","reduce","Record","acc","path","mod","replace","randomUUID","Ctx","models","IRBNotificationPlatformPayload","AppAbility","NotificationDataPayload","Record","NotificationMetadataPayload","NotificationPlatformPayload","NotificationUrlMode","CreateNotificationInput","userId","topic","tag","title","body","image","url","urlMode","metadata","data","platform","CreateNotificationForUserInput","Omit","CreateNotificationsForUserInput","notifications","normalizeRequiredString","value","name","normalized","trim","Error","normalizeOptionalString","undefined","normalizeUrlMode","isRecord","Boolean","Array","isArray","toNotificationDataString","trimmed","Number","isFinite","String","toString","Date","getTime","toISOString","normalizeNotificationActionLink","normalizedUrl","parsed","URL","search","hash","startsWith","buildNotificationData","input","Pick","link","key","Object","entries","assign","linkMode","keys","length","buildNotificationPlatform","webpush","fcmOptions","createNotificationDocument","deliveryId","drawerActive","createdAt","assertCreateNotificationsForUserInput","createNotification","ctx","ability","Promise","id","can","modelCtx","req","NotificationModel","NotificationDeliveryModel","all","getUnsafe","notification","delivery","create","doc","findOneAndReplace","archivedAt","$exists","returnDocument","upsert","sort","updateOne","_id","$set","notificationId","createNotificationsForUser","ids","document","push","Ctx","models","IRBNotification","IRBNotificationSettings","AppAbility","Model","sendEmail","DAY_MS","WEEK_MS","DigestFrequency","NotificationDoc","_id","SettingsDoc","isDuplicateKeyError","error","Boolean","code","markDigestSent","SettingsModel","userId","lastDigestSentAt","Date","Promise","update","$set","result","updateOne","matchedCount","create","digestFrequency","getDigestWindowMs","frequency","formatIso","value","undefined","toISOString","getNotificationLink","notification","dataLink","data","link","trim","platform","Array","isArray","webpush","fcmOptions","buildPreferencesByTopic","settings","Record","emailDigest","record","raw","topicPreferences","pref","topic","sendNotificationsDigestForUser","ctx","ability","force","ok","sent","skippedReason","modelCtx","req","get","NotificationModel","findOne","lean","digestFrequencyRaw","now","windowMs","lastSentAt","since","getTime","preferencesByTopic","disabledTopics","Object","entries","filter","map","query","archivedAt","$exists","readAt","createdAt","$gt","length","$nin","notifications","find","sort","limit","UserModel","getGlobal","user","findById","email","subject","rows","n","title","body","url","line","join","html","emailResult","to","missingTransport","Error","message","skipped"],"sources":["../src/notifications/routes.ts","../src/notifications/createNotification.ts","../src/notifications/digest.ts"],"sourcesContent":["export const routes = Object.entries({\n ...import.meta.glob(\"./api/**/handler.ts\"),\n}).reduce<Record<string, unknown>>((acc, [path, mod]) => {\n acc[path.replace(\"./api/\", \"@rpcbase/server/notifications/api/\")] = mod\n return acc\n}, {})\n\n","import { randomUUID } from \"node:crypto\"\n\nimport type { Ctx } from \"@rpcbase/api\"\nimport { models, type IRBNotificationPlatformPayload } from \"@rpcbase/db\"\nimport type { AppAbility } from \"@rpcbase/db/acl\"\n\n\nexport type NotificationDataPayload = Record<string, string>\nexport type NotificationMetadataPayload = Record<string, unknown>\nexport type NotificationPlatformPayload = IRBNotificationPlatformPayload\nexport type NotificationUrlMode = \"navigate\" | \"merge_current_search\"\n\nexport type CreateNotificationInput = {\n userId: string\n topic?: string\n tag?: string\n title: string\n body?: string\n image?: string\n url?: string\n urlMode?: NotificationUrlMode\n metadata?: NotificationMetadataPayload\n data?: NotificationDataPayload\n platform?: NotificationPlatformPayload\n}\n\nexport type CreateNotificationForUserInput = Omit<CreateNotificationInput, \"userId\">\n\nexport type CreateNotificationsForUserInput = {\n userId: string\n notifications: CreateNotificationForUserInput[]\n}\n\nconst normalizeRequiredString = (value: unknown, name: string): string => {\n const normalized = typeof value === \"string\" ? value.trim() : \"\"\n if (!normalized) {\n throw new Error(`${name} is required`)\n }\n return normalized\n}\n\nconst normalizeOptionalString = (value: string | undefined): string | undefined => {\n const normalized = typeof value === \"string\" ? value.trim() : \"\"\n return normalized || undefined\n}\n\nconst normalizeUrlMode = (value: unknown): NotificationUrlMode => {\n return value === \"merge_current_search\" ? \"merge_current_search\" : \"navigate\"\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n Boolean(value) && typeof value === \"object\" && !Array.isArray(value)\n\nconst toNotificationDataString = (value: unknown): string | undefined => {\n if (typeof value === \"string\") {\n const trimmed = value.trim()\n return trimmed || undefined\n }\n if (typeof value === \"number\" && Number.isFinite(value)) return String(value)\n if (typeof value === \"boolean\") return String(value)\n if (typeof value === \"bigint\") return value.toString()\n if (value instanceof Date && Number.isFinite(value.getTime())) return value.toISOString()\n return undefined\n}\n\nconst normalizeNotificationActionLink = (url: string | undefined, urlMode: NotificationUrlMode): string | undefined => {\n const normalizedUrl = normalizeOptionalString(url)\n if (!normalizedUrl) return undefined\n if (urlMode === \"navigate\") return normalizedUrl\n\n try {\n const parsed = new URL(normalizedUrl, \"https://rpcbase.local/\")\n return `${parsed.search}${parsed.hash}` || undefined\n } catch {\n return normalizedUrl.startsWith(\"?\") ? normalizedUrl : undefined\n }\n}\n\nconst buildNotificationData = (\n input: Pick<CreateNotificationInput, \"data\" | \"metadata\"> & { link?: string; urlMode: NotificationUrlMode },\n): NotificationDataPayload | undefined => {\n const data: NotificationDataPayload = {}\n\n for (const [key, value] of Object.entries(input.metadata ?? {})) {\n const normalized = toNotificationDataString(value)\n if (normalized) {\n data[key] = normalized\n }\n }\n\n if (input.data) {\n Object.assign(data, input.data)\n }\n\n if (input.link) {\n data.link = input.link\n if (input.urlMode !== \"navigate\") {\n data.linkMode = input.urlMode\n }\n }\n\n return Object.keys(data).length > 0 ? data : undefined\n}\n\nconst buildNotificationPlatform = (\n platform: NotificationPlatformPayload | undefined,\n link: string | undefined,\n): NotificationPlatformPayload | undefined => {\n if (!link) return platform\n\n const webpush = isRecord(platform?.webpush) ? platform.webpush : {}\n const fcmOptions = isRecord(webpush.fcmOptions) ? webpush.fcmOptions : {}\n\n return {\n ...platform,\n webpush: {\n ...webpush,\n fcmOptions: {\n ...fcmOptions,\n link,\n },\n },\n }\n}\n\nconst createNotificationDocument = (input: CreateNotificationInput) => {\n const userId = normalizeRequiredString(input.userId, \"createNotification: userId\")\n const title = normalizeRequiredString(input.title, \"createNotification: title\")\n const topic = normalizeOptionalString(input.topic)\n const tag = normalizeOptionalString(input.tag)\n const body = normalizeOptionalString(input.body)\n const image = normalizeOptionalString(input.image)\n const urlMode = normalizeUrlMode(input.urlMode)\n const link = normalizeNotificationActionLink(input.url, urlMode)\n const data = buildNotificationData({ data: input.data, metadata: input.metadata, link, urlMode })\n const platform = buildNotificationPlatform(input.platform, link)\n\n return {\n userId,\n ...(topic ? { topic } : {}),\n ...(tag ? { tag } : {}),\n deliveryId: randomUUID(),\n title,\n ...(body ? { body } : {}),\n ...(image ? { image } : {}),\n ...(data ? { data } : {}),\n ...(platform ? { platform } : {}),\n drawerActive: true,\n createdAt: new Date(),\n }\n}\n\nconst assertCreateNotificationsForUserInput = (input: CreateNotificationsForUserInput): void => {\n if (typeof input.userId !== \"string\" || input.userId.trim().length === 0) {\n throw new Error(\"createNotificationsForUser: userId is required\")\n }\n if (!Array.isArray(input.notifications)) {\n throw new Error(\"createNotificationsForUser: notifications must be an array\")\n }\n}\n\nexport const createNotification = async (\n ctx: Ctx,\n input: CreateNotificationInput,\n ability: AppAbility,\n): Promise<{ id: string }> => {\n if (!ability.can(\"create\", \"RBNotification\")) {\n throw new Error(\"createNotification: forbidden\")\n }\n\n const modelCtx = { req: ctx.req, ability }\n const [NotificationModel, NotificationDeliveryModel] = await Promise.all([\n models.getUnsafe(\"RBNotification\", modelCtx),\n models.getUnsafe(\"RBNotificationDelivery\", modelCtx),\n ])\n const notification = createNotificationDocument(input)\n const delivery = await NotificationDeliveryModel.create(notification)\n const doc = notification.tag\n ? await NotificationModel.findOneAndReplace(\n { userId: notification.userId, tag: notification.tag, archivedAt: { $exists: false } },\n notification,\n { returnDocument: \"after\", upsert: true, sort: { drawerActive: -1, createdAt: -1 } },\n )\n : await NotificationModel.create(notification)\n\n if (!doc) {\n throw new Error(\"createNotification: failed to persist notification\")\n }\n\n await NotificationDeliveryModel.updateOne(\n { _id: delivery._id },\n { $set: { notificationId: doc._id.toString() } },\n )\n\n return { id: doc._id.toString() }\n}\n\nexport const createNotificationsForUser = async (\n ctx: Ctx,\n input: CreateNotificationsForUserInput,\n ability: AppAbility,\n): Promise<{ ids: string[] }> => {\n assertCreateNotificationsForUserInput(input)\n if (input.notifications.length === 0) {\n return { ids: [] }\n }\n\n if (!ability.can(\"create\", \"RBNotification\")) {\n throw new Error(\"createNotificationsForUser: forbidden\")\n }\n\n const modelCtx = { req: ctx.req, ability }\n const [NotificationModel, NotificationDeliveryModel] = await Promise.all([\n models.getUnsafe(\"RBNotification\", modelCtx),\n models.getUnsafe(\"RBNotificationDelivery\", modelCtx),\n ])\n const ids: string[] = []\n for (const notification of input.notifications) {\n const document = createNotificationDocument({\n ...notification,\n userId: input.userId,\n })\n const delivery = await NotificationDeliveryModel.create(document)\n const doc = document.tag\n ? await NotificationModel.findOneAndReplace(\n { userId: document.userId, tag: document.tag, archivedAt: { $exists: false } },\n document,\n { returnDocument: \"after\", upsert: true, sort: { drawerActive: -1, createdAt: -1 } },\n )\n : await NotificationModel.create(document)\n\n if (!doc) {\n throw new Error(\"createNotificationsForUser: failed to persist notification\")\n }\n await NotificationDeliveryModel.updateOne(\n { _id: delivery._id },\n { $set: { notificationId: doc._id.toString() } },\n )\n ids.push(doc._id.toString())\n }\n\n return { ids }\n}\n","import type { Ctx } from \"@rpcbase/api\"\nimport { models, type IRBNotification, type IRBNotificationSettings } from \"@rpcbase/db\"\nimport type { AppAbility } from \"@rpcbase/db/acl\"\nimport type { Model } from \"mongoose\"\n\nimport { sendEmail } from \"../email\"\n\n\nconst DAY_MS = 24 * 60 * 60 * 1000\nconst WEEK_MS = 7 * DAY_MS\n\ntype DigestFrequency = \"off\" | \"daily\" | \"weekly\"\n\ntype NotificationDoc = IRBNotification & { _id: unknown }\ntype SettingsDoc = IRBNotificationSettings & { _id: unknown }\n\nconst isDuplicateKeyError = (error: unknown): boolean =>\n Boolean(error && typeof error === \"object\" && \"code\" in error && error.code === 11000)\n\nconst markDigestSent = async (\n SettingsModel: Model<IRBNotificationSettings>,\n userId: string,\n lastDigestSentAt: Date,\n): Promise<void> => {\n const update = { $set: { lastDigestSentAt } }\n const result = await SettingsModel.updateOne({ userId }, update)\n if (result.matchedCount > 0) return\n\n try {\n await SettingsModel.create({\n userId,\n digestFrequency: \"weekly\",\n lastDigestSentAt,\n })\n } catch (error) {\n if (!isDuplicateKeyError(error)) throw error\n await SettingsModel.updateOne({ userId }, update)\n }\n}\n\nconst getDigestWindowMs = (frequency: DigestFrequency): number => {\n if (frequency === \"daily\") return DAY_MS\n if (frequency === \"weekly\") return WEEK_MS\n return 0\n}\n\nconst formatIso = (value: unknown): string | undefined => {\n if (!(value instanceof Date)) return undefined\n return value.toISOString()\n}\n\nconst getNotificationLink = (notification: NotificationDoc): string => {\n const dataLink = notification.data?.link?.trim()\n if (dataLink) return dataLink\n\n const platform = notification.platform\n if (!platform || typeof platform !== \"object\" || Array.isArray(platform)) return \"\"\n const webpush = (platform as { webpush?: unknown }).webpush\n if (!webpush || typeof webpush !== \"object\" || Array.isArray(webpush)) return \"\"\n const fcmOptions = (webpush as { fcmOptions?: unknown }).fcmOptions\n if (!fcmOptions || typeof fcmOptions !== \"object\" || Array.isArray(fcmOptions)) return \"\"\n const link = (fcmOptions as { link?: unknown }).link\n return typeof link === \"string\" ? link.trim() : \"\"\n}\n\nconst buildPreferencesByTopic = (settings: SettingsDoc | null): Record<string, { emailDigest: boolean }> => {\n const record: Record<string, { emailDigest: boolean }> = {}\n const raw = settings?.topicPreferences\n if (!Array.isArray(raw)) return record\n for (const pref of raw) {\n if (!pref || typeof pref !== \"object\") continue\n const topic = typeof (pref as { topic?: unknown }).topic === \"string\" ? (pref as { topic: string }).topic.trim() : \"\"\n if (!topic) continue\n const emailDigest = (pref as { emailDigest?: unknown }).emailDigest\n record[topic] = { emailDigest: emailDigest === true }\n }\n return record\n}\n\nexport const sendNotificationsDigestForUser = async (\n ctx: Ctx,\n {\n userId,\n ability,\n force = false,\n }: {\n userId: string\n ability: AppAbility\n force?: boolean\n },\n): Promise<{ ok: true; sent: boolean; skippedReason?: string } | { ok: false; error: string }> => {\n const modelCtx = { req: ctx.req, ability }\n const SettingsModel = await models.get(\n \"RBNotificationSettings\",\n modelCtx,\n ) as Model<IRBNotificationSettings>\n const NotificationModel = await models.get(\"RBNotification\", modelCtx)\n\n const settings = (await SettingsModel.findOne({ userId }).lean()) as SettingsDoc | null\n\n const digestFrequencyRaw = typeof settings?.digestFrequency === \"string\" ? settings.digestFrequency : \"weekly\"\n const digestFrequency: DigestFrequency =\n digestFrequencyRaw === \"daily\" || digestFrequencyRaw === \"weekly\" || digestFrequencyRaw === \"off\"\n ? digestFrequencyRaw\n : \"weekly\"\n\n if (digestFrequency === \"off\") {\n return { ok: true, sent: false, skippedReason: \"digest_off\" }\n }\n\n const now = new Date()\n const windowMs = getDigestWindowMs(digestFrequency)\n const lastSentAt = settings?.lastDigestSentAt instanceof Date ? settings.lastDigestSentAt : null\n const since = lastSentAt ?? new Date(now.getTime() - windowMs)\n\n if (!force && lastSentAt && now.getTime() - lastSentAt.getTime() < windowMs) {\n return { ok: true, sent: false, skippedReason: \"not_due\" }\n }\n\n const preferencesByTopic = buildPreferencesByTopic(settings)\n const disabledTopics = Object.entries(preferencesByTopic)\n .filter(([, pref]) => pref.emailDigest === false)\n .map(([topic]) => topic)\n\n const query: Record<string, unknown> = {\n userId,\n archivedAt: { $exists: false },\n readAt: { $exists: false },\n createdAt: { $gt: since },\n }\n\n if (disabledTopics.length > 0) {\n query.topic = { $nin: disabledTopics }\n }\n\n const notifications = (await NotificationModel.find(query)\n .sort({ createdAt: -1 })\n .limit(50)\n .lean()) as NotificationDoc[]\n\n if (!notifications.length) {\n await markDigestSent(SettingsModel, userId, now)\n return { ok: true, sent: false, skippedReason: \"empty\" }\n }\n\n const UserModel = await models.getGlobal(\"RBUser\", ctx)\n const user = (await UserModel.findById(userId, { email: 1 }).lean()) as { email?: unknown } | null\n const email = typeof user?.email === \"string\" ? user.email.trim() : \"\"\n if (!email) {\n return { ok: true, sent: false, skippedReason: \"missing_email\" }\n }\n\n const subject = \"Notifications digest\"\n const rows = notifications\n .map((n) => {\n const title = typeof n.title === \"string\" ? n.title : \"\"\n const body = typeof n.body === \"string\" ? n.body : \"\"\n const url = getNotificationLink(n)\n const createdAt = formatIso(n.createdAt) ?? \"\"\n const line = url\n ? `<li><strong>${title}</strong><br>${body}<br><a href=\"${url}\">${url}</a><br><small>${createdAt}</small></li>`\n : `<li><strong>${title}</strong><br>${body}<br><small>${createdAt}</small></li>`\n return line\n })\n .join(\"\")\n\n const html = `<div><p>Here is your notifications digest:</p><ul>${rows}</ul></div>`\n\n let emailResult\n try {\n emailResult = await sendEmail(\n { to: email, subject, html },\n { missingTransport: \"skip\" },\n )\n } catch (error) {\n return {\n ok: false,\n error: error instanceof Error ? error.message : \"Email delivery failed\",\n }\n }\n\n await markDigestSent(SettingsModel, userId, now)\n\n return { ok: true, sent: emailResult.skipped !== true, ...(emailResult.skipped ? { skippedReason: \"email_skipped\" } : {}) }\n}\n"],"mappings":";;;;AAAA,IAAaA,SAASC,OAAOC,QAAQ,EACnC,GAAGC,uBAAAA,OAAAA,EAAAA,wCAAAA,OAAAA,yBAAAA,CAAAA,EACL,CAAC,CAAC,CAACG,QAAiCE,KAAK,CAACC,MAAMC,SAAS;CACvDF,IAAIC,KAAKE,QAAQ,UAAU,oCAAoC,KAAKD;CACpE,OAAOF;AACT,GAAG,CAAC,CAAC;;;AC4BL,IAAM8B,2BAA2BC,OAAgBC,SAAyB;CACxE,MAAMC,aAAa,OAAOF,UAAU,WAAWA,MAAMG,KAAK,IAAI;CAC9D,IAAI,CAACD,YACH,MAAM,IAAIE,MAAM,GAAGH,KAAI,aAAc;CAEvC,OAAOC;AACT;AAEA,IAAMG,2BAA2BL,UAAkD;CAEjF,QADmB,OAAOA,UAAU,WAAWA,MAAMG,KAAK,IAAI,OACzCG,KAAAA;AACvB;AAEA,IAAMC,oBAAoBP,UAAwC;CAChE,OAAOA,UAAU,yBA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