@rpcbase/server 0.594.0 → 0.596.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 (61) hide show
  1. package/dist/convertHeifToWebp-BT1n72DQ.js +148 -0
  2. package/dist/convertHeifToWebp-BT1n72DQ.js.map +1 -0
  3. package/dist/email-Co1GNjlT.js +7204 -0
  4. package/dist/email-Co1GNjlT.js.map +1 -0
  5. package/dist/handler-BqlcQ9sE.js +245 -0
  6. package/dist/handler-BqlcQ9sE.js.map +1 -0
  7. package/dist/handler-C92_gJkX.js +743 -0
  8. package/dist/handler-C92_gJkX.js.map +1 -0
  9. package/dist/handler-CapJTGzc.js +795 -0
  10. package/dist/handler-CapJTGzc.js.map +1 -0
  11. package/dist/handler-Fk-5fOSm.js +119 -0
  12. package/dist/handler-Fk-5fOSm.js.map +1 -0
  13. package/dist/htmlTemplate.d.ts +16 -0
  14. package/dist/htmlTemplate.d.ts.map +1 -0
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +5140 -5286
  18. package/dist/index.js.map +1 -1
  19. package/dist/notifications.js +273 -382
  20. package/dist/notifications.js.map +1 -1
  21. package/dist/postProcessors-iffHvje4.js +89 -0
  22. package/dist/postProcessors-iffHvje4.js.map +1 -0
  23. package/dist/queryWindow-DP8zD0lb.js +555 -0
  24. package/dist/queryWindow-DP8zD0lb.js.map +1 -0
  25. package/dist/render_resend-B1SSQ4f7.js +7 -0
  26. package/dist/render_resend-B1SSQ4f7.js.map +1 -0
  27. package/dist/rts/index.js +990 -1207
  28. package/dist/rts/index.js.map +1 -1
  29. package/dist/schemas-B2fUvgYo.js +4151 -0
  30. package/dist/schemas-B2fUvgYo.js.map +1 -0
  31. package/dist/shared-DfrVDSp0.js +79 -0
  32. package/dist/shared-DfrVDSp0.js.map +1 -0
  33. package/dist/ssrMiddleware.d.ts +7 -3
  34. package/dist/ssrMiddleware.d.ts.map +1 -1
  35. package/dist/uploads/worker.js +139 -168
  36. package/dist/uploads/worker.js.map +1 -1
  37. package/dist/uploads.js +12 -22
  38. package/dist/uploads.js.map +1 -1
  39. package/package.json +1 -1
  40. package/dist/convertHeifToWebp-C-DGXZ2k.js +0 -169
  41. package/dist/convertHeifToWebp-C-DGXZ2k.js.map +0 -1
  42. package/dist/email-BCf24GmK.js +0 -8071
  43. package/dist/email-BCf24GmK.js.map +0 -1
  44. package/dist/handler-BqoKvylN.js +0 -147
  45. package/dist/handler-BqoKvylN.js.map +0 -1
  46. package/dist/handler-CUOJ51-w.js +0 -903
  47. package/dist/handler-CUOJ51-w.js.map +0 -1
  48. package/dist/handler-D-XdgeG_.js +0 -986
  49. package/dist/handler-D-XdgeG_.js.map +0 -1
  50. package/dist/handler-F0gFTzvh.js +0 -275
  51. package/dist/handler-F0gFTzvh.js.map +0 -1
  52. package/dist/postProcessors-D27fGZP0.js +0 -107
  53. package/dist/postProcessors-D27fGZP0.js.map +0 -1
  54. package/dist/queryWindow-Cdr7K-S1.js +0 -714
  55. package/dist/queryWindow-Cdr7K-S1.js.map +0 -1
  56. package/dist/render_resend_false-MiC__Smr.js +0 -6
  57. package/dist/render_resend_false-MiC__Smr.js.map +0 -1
  58. package/dist/schemas-Drf83ni9.js +0 -4517
  59. package/dist/schemas-Drf83ni9.js.map +0 -1
  60. package/dist/shared-CJrm9Wjp.js +0 -104
  61. package/dist/shared-CJrm9Wjp.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler-C92_gJkX.js","names":["Ctx","NotificationSessionUser","id","currentTenantId","getSessionUser","ctx","rawSessionUser","req","session","user","userId","trim","tenantId","res","status","z","ListRoute","CreateRoute","MarkReadRoute","MarkReadByUrlRoute","ArchiveRoute","MarkAllReadRoute","SettingsRoute","DigestRunRoute","listRequestSchema","object","includeArchived","boolean","optional","unreadOnly","limit","number","int","min","max","markSeen","ListRequestPayload","infer","notificationDataSchema","record","string","notificationPlatformPayloadSchema","webpush","unknown","fcmOptions","android","apns","passthrough","NotificationPlatformPayload","createRequestStringSchema","trim","notificationUrlModeSchema","enum","notificationContentFieldsSchema","title","body","image","createRequestSchema","topic","tag","url","urlMode","metadata","data","platform","CreateRequestPayload","normalizeNotificationActionUrl","origin","raw","base","URL","parsed","pathname","search","normalizeNotificationActionLink","hash","notificationSchema","id","deliveryId","shape","createdAt","seenAt","readAt","archivedAt","NotificationPayload","listResponseSchema","ok","error","notifications","array","unreadCount","unseenCount","ListResponsePayload","createResponseSchema","CreateResponsePayload","markReadResponseSchema","MarkReadResponsePayload","markReadByUrlRequestSchema","MarkReadByUrlRequestPayload","markReadByUrlResponseSchema","matchedCount","modifiedCount","MarkReadByUrlResponsePayload","archiveResponseSchema","ArchiveResponsePayload","markAllReadResponseSchema","MarkAllReadResponsePayload","digestFrequencySchema","DigestFrequency","topicPreferenceSchema","inApp","emailDigest","push","TopicPreferencePayload","settingsSchema","digestFrequency","topicPreferences","lastDigestSentAt","SettingsPayload","settingsResponseSchema","settings","SettingsResponsePayload","updateSettingsRequestSchema","UpdateSettingsRequestPayload","updateSettingsResponseSchema","UpdateSettingsResponsePayload","digestRunRequestSchema","force","DigestRunRequestPayload","digestRunResponseSchema","sent","skippedReason","DigestRunResponsePayload","Api","ApiHandler","Ctx","models","IRBNotification","IRBNotificationSettings","buildAbilityFromSession","getAccessibleByQuery","createNotification","sendNotificationsDigestForUser","getSessionUser","Notifications","NotificationDoc","_id","NotificationActionDoc","Pick","SettingsDoc","NotificationActionLink","link","urlMode","toIso","value","Date","toISOString","undefined","isRecord","Record","Boolean","Array","isArray","toStringMap","entries","Object","filter","entry","length","fromEntries","getForwardedHeaderValue","raw","split","trim","getRequestOrigin","ctx","protocol","req","headers","host","get","getNotificationActionLinks","notification","links","data","push","linkMode","platformWebpush","platform","webpush","fcmOptions","actionSearchParamsMatchTargetUrl","actionUrl","targetUrl","origin","base","URL","action","target","key","searchParams","from","keys","notificationActionLinkMatchesUrl","normalizeNotificationActionUrl","buildDisabledTopics","settings","topicPreferences","map","pref","topic","enabled","listNotifications","ListRequestPayload","ListResponsePayload","payload","session","ok","error","ability","tenantId","can","res","status","parsed","listRequestSchema","safeParse","success","userId","includeArchived","unreadOnly","limit","markSeen","SettingsModel","findOne","lean","disabledTopics","NotificationModel","queryFilters","archivedAt","$exists","readAt","$nin","query","$and","notifications","find","sort","createdAt","unseenQueryFilters","seenAt","unseenQuery","unreadQueryFilters","unreadQuery","unreadCount","unseenCount","Promise","all","countDocuments","now","updateMany","$set","listResponseSchema","parse","n","id","String","tag","deliveryId","title","body","image","createNotificationForCurrentUser","CreateRequestPayload","CreateResponsePayload","createRequestSchema","actionLink","url","normalizeNotificationActionLink","created","metadata","createResponseSchema","markRead","MarkReadResponsePayload","_payload","notificationId","params","updateOne","markReadByUrl","MarkReadByUrlRequestPayload","MarkReadByUrlResponsePayload","markReadByUrlRequestSchema","$or","$type","candidates","select","matchingIds","some","markReadByUrlResponseSchema","matchedCount","modifiedCount","result","$in","markAllRead","MarkAllReadResponsePayload","archiveNotification","ArchiveResponsePayload","drawerActive","getSettings","SettingsResponsePayload","digestFrequencyRaw","digestFrequency","DigestFrequency","inApp","emailDigest","settingsResponseSchema","lastDigestSentAt","updateSettings","UpdateSettingsRequestPayload","UpdateSettingsResponsePayload","updateSettingsRequestSchema","nextValues","seen","Set","next","has","add","ops","$setOnInsert","findOneAndUpdate","upsert","returnDocument","setDefaultsOnInsert","updateSettingsResponseSchema","runDigest","DigestRunRequestPayload","DigestRunResponsePayload","digestRunRequestSchema","force","sent","skippedReason","api","post","ListRoute","CreateRoute","MarkReadRoute","MarkReadByUrlRoute","MarkAllReadRoute","ArchiveRoute","SettingsRoute","put","DigestRunRoute"],"sources":["../src/notifications/api/notifications/shared.ts","../src/notifications/api/notifications/index.ts","../src/notifications/api/notifications/handler.ts"],"sourcesContent":["import type { Ctx } from \"@rpcbase/api\"\n\n\ntype NotificationSessionUser = {\n id?: unknown\n currentTenantId?: unknown\n}\n\nexport const getSessionUser = (ctx: Ctx) => {\n const rawSessionUser = (ctx.req.session as { user?: NotificationSessionUser } | null | undefined)?.user\n const userId = typeof rawSessionUser?.id === \"string\" ? rawSessionUser.id.trim() : \"\"\n const tenantId = typeof rawSessionUser?.currentTenantId === \"string\" ? rawSessionUser.currentTenantId.trim() : \"\"\n\n if (!userId) {\n ctx.res.status(401)\n return null\n }\n\n if (!tenantId) {\n ctx.res.status(400)\n return null\n }\n\n return { userId, tenantId }\n}\n\n","import { z } from \"zod\"\n\n\nexport const ListRoute = \"/api/rb/notifications\"\nexport const CreateRoute = \"/api/rb/notifications/create\"\nexport const MarkReadRoute = \"/api/rb/notifications/:notificationId/read\"\nexport const MarkReadByUrlRoute = \"/api/rb/notifications/mark-read-by-url\"\nexport const ArchiveRoute = \"/api/rb/notifications/:notificationId/archive\"\nexport const MarkAllReadRoute = \"/api/rb/notifications/mark-all-read\"\nexport const SettingsRoute = \"/api/rb/notifications/settings\"\nexport const DigestRunRoute = \"/api/rb/notifications/digest/run\"\n\nexport const listRequestSchema = z.object({\n includeArchived: z.boolean().optional(),\n unreadOnly: z.boolean().optional(),\n limit: z.number().int().min(1).max(200).optional(),\n markSeen: z.boolean().optional(),\n})\n\nexport type ListRequestPayload = z.infer<typeof listRequestSchema>\n\nexport const notificationDataSchema = z.record(z.string(), z.string())\n\nexport const notificationPlatformPayloadSchema = z.object({\n webpush: z.record(z.string(), z.unknown()).optional(),\n fcmOptions: z.record(z.string(), z.unknown()).optional(),\n android: z.record(z.string(), z.unknown()).optional(),\n apns: z.record(z.string(), z.unknown()).optional(),\n}).passthrough()\n\nexport type NotificationPlatformPayload = z.infer<typeof notificationPlatformPayloadSchema>\n\nconst createRequestStringSchema = z.string().trim()\nconst notificationUrlModeSchema = z.enum([\"navigate\", \"merge_current_search\"])\n\nexport const notificationContentFieldsSchema = z.object({\n title: z.string().min(1),\n body: z.string().optional(),\n image: z.string().optional(),\n})\n\nexport const createRequestSchema = z.object({\n topic: createRequestStringSchema.min(1).optional(),\n tag: createRequestStringSchema.min(1).optional(),\n title: createRequestStringSchema.min(1),\n body: createRequestStringSchema.optional(),\n image: createRequestStringSchema.optional(),\n url: createRequestStringSchema.min(1).optional(),\n urlMode: notificationUrlModeSchema.optional(),\n metadata: z.record(z.string(), z.unknown()).optional(),\n data: notificationDataSchema.optional(),\n platform: notificationPlatformPayloadSchema.optional(),\n})\n\nexport type CreateRequestPayload = z.infer<typeof createRequestSchema>\n\nexport const normalizeNotificationActionUrl = (url: string, origin: string): string | null => {\n const raw = url.trim()\n if (!raw) return null\n\n try {\n const base = new URL(origin)\n const parsed = new URL(raw, base)\n if (parsed.origin !== base.origin) return null\n return `${parsed.pathname}${parsed.search}`\n } catch {\n return null\n }\n}\n\nexport const normalizeNotificationActionLink = (\n url: string,\n origin: string,\n urlMode: z.infer<typeof notificationUrlModeSchema> = \"navigate\",\n): string | null => {\n const raw = url.trim()\n if (!raw) return null\n\n try {\n const base = new URL(origin)\n const parsed = new URL(raw, base)\n if (parsed.origin !== base.origin) return null\n if (urlMode === \"navigate\") return `${parsed.pathname}${parsed.search}${parsed.hash}`\n return `${parsed.search}${parsed.hash}` || null\n } catch {\n return null\n }\n}\n\nexport const notificationSchema = z.object({\n id: z.string(),\n topic: z.string().optional(),\n tag: z.string().optional(),\n deliveryId: z.string().optional(),\n title: notificationContentFieldsSchema.shape.title,\n body: notificationContentFieldsSchema.shape.body,\n image: notificationContentFieldsSchema.shape.image,\n data: notificationDataSchema.optional(),\n platform: notificationPlatformPayloadSchema.optional(),\n createdAt: z.string(),\n seenAt: z.string().optional(),\n readAt: z.string().optional(),\n archivedAt: z.string().optional(),\n})\n\nexport type NotificationPayload = z.infer<typeof notificationSchema>\n\nexport const listResponseSchema = z.object({\n ok: z.boolean(),\n error: z.string().optional(),\n notifications: z.array(notificationSchema).optional(),\n unreadCount: z.number().int().min(0).optional(),\n unseenCount: z.number().int().min(0).optional(),\n})\n\nexport type ListResponsePayload = z.infer<typeof listResponseSchema>\n\nexport const createResponseSchema = z.object({\n ok: z.boolean(),\n error: z.string().optional(),\n id: z.string().optional(),\n})\n\nexport type CreateResponsePayload = z.infer<typeof createResponseSchema>\n\nexport const markReadResponseSchema = z.object({\n ok: z.boolean(),\n error: z.string().optional(),\n})\n\nexport type MarkReadResponsePayload = z.infer<typeof markReadResponseSchema>\n\nexport const markReadByUrlRequestSchema = z.object({\n url: z.string().trim().min(1),\n})\n\nexport type MarkReadByUrlRequestPayload = z.infer<typeof markReadByUrlRequestSchema>\n\nexport const markReadByUrlResponseSchema = z.object({\n ok: z.boolean(),\n error: z.string().optional(),\n matchedCount: z.number().int().min(0).optional(),\n modifiedCount: z.number().int().min(0).optional(),\n})\n\nexport type MarkReadByUrlResponsePayload = z.infer<typeof markReadByUrlResponseSchema>\n\nexport const archiveResponseSchema = z.object({\n ok: z.boolean(),\n error: z.string().optional(),\n})\n\nexport type ArchiveResponsePayload = z.infer<typeof archiveResponseSchema>\n\nexport const markAllReadResponseSchema = z.object({\n ok: z.boolean(),\n error: z.string().optional(),\n})\n\nexport type MarkAllReadResponsePayload = z.infer<typeof markAllReadResponseSchema>\n\nexport const digestFrequencySchema = z.enum([\"off\", \"daily\", \"weekly\"])\n\nexport type DigestFrequency = z.infer<typeof digestFrequencySchema>\n\nexport const topicPreferenceSchema = z.object({\n topic: z.string(),\n inApp: z.boolean(),\n emailDigest: z.boolean(),\n push: z.boolean(),\n})\n\nexport type TopicPreferencePayload = z.infer<typeof topicPreferenceSchema>\n\nexport const settingsSchema = z.object({\n digestFrequency: digestFrequencySchema,\n topicPreferences: z.array(topicPreferenceSchema),\n lastDigestSentAt: z.string().optional(),\n})\n\nexport type SettingsPayload = z.infer<typeof settingsSchema>\n\nexport const settingsResponseSchema = z.object({\n ok: z.boolean(),\n error: z.string().optional(),\n settings: settingsSchema.optional(),\n})\n\nexport type SettingsResponsePayload = z.infer<typeof settingsResponseSchema>\n\nexport const updateSettingsRequestSchema = z.object({\n digestFrequency: digestFrequencySchema.optional(),\n topicPreferences: z.array(topicPreferenceSchema).optional(),\n})\n\nexport type UpdateSettingsRequestPayload = z.infer<typeof updateSettingsRequestSchema>\n\nexport const updateSettingsResponseSchema = z.object({\n ok: z.boolean(),\n error: z.string().optional(),\n settings: settingsSchema.optional(),\n})\n\nexport type UpdateSettingsResponsePayload = z.infer<typeof updateSettingsResponseSchema>\n\nexport const digestRunRequestSchema = z.object({\n force: z.boolean().optional(),\n})\n\nexport type DigestRunRequestPayload = z.infer<typeof digestRunRequestSchema>\n\nexport const digestRunResponseSchema = z.object({\n ok: z.boolean(),\n error: z.string().optional(),\n sent: z.boolean().optional(),\n skippedReason: z.string().optional(),\n})\n\nexport type DigestRunResponsePayload = z.infer<typeof digestRunResponseSchema>\n","import { Api, type ApiHandler, type Ctx } from \"@rpcbase/api\"\nimport { models, type IRBNotification, type IRBNotificationSettings } from \"@rpcbase/db\"\nimport { buildAbilityFromSession, getAccessibleByQuery } from \"@rpcbase/db/acl\"\n\nimport { createNotification } from \"../../createNotification\"\nimport { sendNotificationsDigestForUser } from \"../../digest\"\nimport { getSessionUser } from \"./shared\"\n\nimport * as Notifications from \"./index\"\n\n\ntype NotificationDoc = IRBNotification & { _id: unknown }\ntype NotificationActionDoc = Pick<NotificationDoc, \"_id\" | \"data\" | \"platform\">\ntype SettingsDoc = IRBNotificationSettings & { _id: unknown }\ntype NotificationActionLink = {\n link: string\n urlMode: \"navigate\" | \"merge_current_search\"\n}\n\nconst toIso = (value: unknown): string | undefined => (value instanceof Date ? value.toISOString() : undefined)\nconst isRecord = (value: unknown): value is Record<string, unknown> => Boolean(value) && typeof value === \"object\" && !Array.isArray(value)\n\nconst toStringMap = (value: unknown): Record<string, string> | undefined => {\n if (!isRecord(value)) return undefined\n const entries = Object.entries(value)\n .filter((entry): entry is [string, string] => typeof entry[1] === \"string\")\n return entries.length > 0 ? Object.fromEntries(entries) : undefined\n}\n\nconst getForwardedHeaderValue = (value: unknown): string | undefined => {\n const raw = Array.isArray(value) ? value[0] : value\n if (typeof raw !== \"string\") return undefined\n return raw.split(\",\")[0]?.trim() || undefined\n}\n\nconst getRequestOrigin = (ctx: Ctx): string => {\n const protocol = getForwardedHeaderValue(ctx.req.headers[\"x-forwarded-proto\"]) ?? ctx.req.protocol\n const host = getForwardedHeaderValue(ctx.req.headers[\"x-forwarded-host\"]) ?? ctx.req.get(\"host\")\n\n return protocol && host ? `${protocol}://${host}` : \"\"\n}\n\nconst getNotificationActionLinks = (notification: NotificationActionDoc): NotificationActionLink[] => {\n const links: NotificationActionLink[] = []\n\n if (typeof notification.data?.link === \"string\") {\n links.push({\n link: notification.data.link,\n urlMode: notification.data.linkMode === \"merge_current_search\" ? \"merge_current_search\" : \"navigate\",\n })\n }\n\n const platformWebpush = notification.platform?.webpush\n if (platformWebpush && typeof platformWebpush === \"object\" && !Array.isArray(platformWebpush)) {\n const fcmOptions = (platformWebpush as { fcmOptions?: unknown }).fcmOptions\n if (fcmOptions && typeof fcmOptions === \"object\" && !Array.isArray(fcmOptions)) {\n const link = (fcmOptions as { link?: unknown }).link\n if (typeof link === \"string\") {\n links.push({ link, urlMode: \"navigate\" })\n }\n }\n }\n\n return links\n}\n\nconst actionSearchParamsMatchTargetUrl = (actionUrl: string, targetUrl: string, origin: string): boolean => {\n try {\n const base = new URL(origin)\n const action = new URL(actionUrl, base)\n const target = new URL(targetUrl, base)\n for (const [key, value] of action.searchParams) {\n if (target.searchParams.get(key) !== value) return false\n }\n return Array.from(action.searchParams.keys()).length > 0\n } catch {\n return false\n }\n}\n\nconst notificationActionLinkMatchesUrl = (\n action: NotificationActionLink,\n targetUrl: string,\n origin: string,\n): boolean => {\n if (action.urlMode === \"merge_current_search\") {\n return actionSearchParamsMatchTargetUrl(action.link, targetUrl, origin)\n }\n\n return Notifications.normalizeNotificationActionUrl(action.link, origin) === targetUrl\n}\n\nconst buildDisabledTopics = (\n settings: SettingsDoc | null,\n key: \"inApp\" | \"emailDigest\",\n): string[] => {\n const raw = settings?.topicPreferences\n if (!Array.isArray(raw) || raw.length === 0) return []\n\n return raw\n .map((pref) => {\n if (!pref || typeof pref !== \"object\") return null\n const topic = typeof (pref as { topic?: unknown }).topic === \"string\" ? (pref as { topic: string }).topic.trim() : \"\"\n if (!topic) return null\n const enabled = (pref as Record<string, unknown>)[key] === true\n return enabled ? null : topic\n })\n .filter((topic): topic is string => Boolean(topic))\n}\n\nconst listNotifications: ApiHandler<Notifications.ListRequestPayload, Notifications.ListResponsePayload> = async(\n payload,\n ctx,\n) => {\n const session = getSessionUser(ctx)\n if (!session) {\n return { ok: false, error: \"unauthorized\" }\n }\n\n const ability = buildAbilityFromSession({ tenantId: session.tenantId, session: ctx.req.session })\n if (!ability.can(\"read\", \"RBNotification\")) {\n ctx.res.status(403)\n return { ok: false, error: \"forbidden\" }\n }\n\n const parsed = Notifications.listRequestSchema.safeParse(payload)\n if (!parsed.success) {\n ctx.res.status(400)\n return { ok: false, error: \"invalid_payload\" }\n }\n\n const { userId } = session\n const includeArchived = parsed.data.includeArchived === true\n const unreadOnly = parsed.data.unreadOnly === true\n const limit = parsed.data.limit ?? 50\n const markSeen = parsed.data.markSeen === true\n\n const SettingsModel = await models.get(\"RBNotificationSettings\", { req: ctx.req, ability })\n const settings = (await SettingsModel.findOne({ userId }).lean()) as SettingsDoc | null\n const disabledTopics = buildDisabledTopics(settings, \"inApp\")\n\n const NotificationModel = await models.get(\"RBNotification\", { req: ctx.req, ability })\n\n const queryFilters: Record<string, unknown>[] = [\n { userId },\n getAccessibleByQuery(ability, \"read\", \"RBNotification\"),\n ]\n if (!includeArchived) queryFilters.push({ archivedAt: { $exists: false } })\n if (unreadOnly) queryFilters.push({ readAt: { $exists: false } })\n if (disabledTopics.length > 0) queryFilters.push({ topic: { $nin: disabledTopics } })\n const query: Record<string, unknown> = { $and: queryFilters }\n\n const notifications = (await NotificationModel.find(query)\n .sort({ createdAt: -1 })\n .limit(limit)\n .lean()) as NotificationDoc[]\n\n const unseenQueryFilters: Record<string, unknown>[] = [\n { userId },\n { archivedAt: { $exists: false } },\n { seenAt: { $exists: false } },\n getAccessibleByQuery(ability, \"read\", \"RBNotification\"),\n ]\n if (disabledTopics.length > 0) unseenQueryFilters.push({ topic: { $nin: disabledTopics } })\n const unseenQuery: Record<string, unknown> = { $and: unseenQueryFilters }\n\n const unreadQueryFilters: Record<string, unknown>[] = [\n { userId },\n { archivedAt: { $exists: false } },\n { readAt: { $exists: false } },\n getAccessibleByQuery(ability, \"read\", \"RBNotification\"),\n ]\n if (disabledTopics.length > 0) unreadQueryFilters.push({ topic: { $nin: disabledTopics } })\n const unreadQuery: Record<string, unknown> = { $and: unreadQueryFilters }\n\n const [unreadCount, unseenCount] = await Promise.all([\n NotificationModel.countDocuments(unreadQuery),\n NotificationModel.countDocuments(unseenQuery),\n ])\n\n const now = markSeen ? new Date() : null\n if (now && unseenCount > 0) {\n await NotificationModel.updateMany(unseenQuery, { $set: { seenAt: now } })\n }\n\n return Notifications.listResponseSchema.parse({\n ok: true,\n notifications: notifications.map((n) => ({\n id: String(n._id),\n topic: typeof n.topic === \"string\" ? n.topic : undefined,\n tag: typeof n.tag === \"string\" ? n.tag : undefined,\n deliveryId: typeof n.deliveryId === \"string\" ? n.deliveryId : undefined,\n title: typeof n.title === \"string\" ? n.title : \"\",\n body: typeof n.body === \"string\" ? n.body : undefined,\n image: typeof n.image === \"string\" ? n.image : undefined,\n data: toStringMap(n.data),\n platform: isRecord(n.platform) ? n.platform : undefined,\n createdAt: toIso(n.createdAt) ?? new Date().toISOString(),\n seenAt: toIso(n.seenAt) ?? (now && !n.archivedAt && !n.seenAt ? now.toISOString() : undefined),\n readAt: toIso(n.readAt),\n archivedAt: toIso(n.archivedAt),\n })),\n unreadCount,\n unseenCount: now ? 0 : unseenCount,\n })\n}\n\nconst createNotificationForCurrentUser: ApiHandler<Notifications.CreateRequestPayload, Notifications.CreateResponsePayload> = async(\n payload,\n ctx,\n) => {\n const session = getSessionUser(ctx)\n if (!session) {\n return { ok: false, error: \"unauthorized\" }\n }\n\n const ability = buildAbilityFromSession({ tenantId: session.tenantId, session: ctx.req.session })\n if (!ability.can(\"create\", \"RBNotification\")) {\n ctx.res.status(403)\n return { ok: false, error: \"forbidden\" }\n }\n\n const parsed = Notifications.createRequestSchema.safeParse(payload)\n if (!parsed.success) {\n ctx.res.status(400)\n return { ok: false, error: \"invalid_payload\" }\n }\n\n const origin = getRequestOrigin(ctx)\n const actionLink = parsed.data.url\n ? Notifications.normalizeNotificationActionLink(parsed.data.url, origin, parsed.data.urlMode) ?? undefined\n : undefined\n if (parsed.data.url && !actionLink) {\n ctx.res.status(400)\n return { ok: false, error: \"invalid_payload\" }\n }\n\n const created = await createNotification(ctx, {\n userId: session.userId,\n topic: parsed.data.topic,\n tag: parsed.data.tag,\n title: parsed.data.title,\n body: parsed.data.body,\n image: parsed.data.image,\n url: actionLink,\n urlMode: parsed.data.urlMode,\n metadata: parsed.data.metadata,\n data: parsed.data.data,\n platform: parsed.data.platform,\n }, ability)\n\n return Notifications.createResponseSchema.parse({ ok: true, id: created.id })\n}\n\nconst markRead: ApiHandler<unknown, Notifications.MarkReadResponsePayload> = async(\n _payload,\n ctx,\n) => {\n const session = getSessionUser(ctx)\n if (!session) {\n return { ok: false, error: \"unauthorized\" }\n }\n\n const ability = buildAbilityFromSession({ tenantId: session.tenantId, session: ctx.req.session })\n if (!ability.can(\"update\", \"RBNotification\")) {\n ctx.res.status(403)\n return { ok: false, error: \"forbidden\" }\n }\n\n const notificationId = typeof ctx.req.params.notificationId === \"string\" ? ctx.req.params.notificationId.trim() : \"\"\n if (!notificationId) {\n ctx.res.status(400)\n return { ok: false, error: \"missing_notification_id\" }\n }\n\n const NotificationModel = await models.get(\"RBNotification\", { req: ctx.req, ability })\n const now = new Date()\n\n try {\n await NotificationModel.updateOne(\n { $and: [{ _id: notificationId }, { archivedAt: { $exists: false } }, getAccessibleByQuery(ability, \"update\", \"RBNotification\")] },\n { $set: { readAt: now, seenAt: now } },\n )\n } catch {\n ctx.res.status(400)\n return { ok: false, error: \"invalid_notification_id\" }\n }\n\n return { ok: true }\n}\n\nconst markReadByUrl: ApiHandler<Notifications.MarkReadByUrlRequestPayload, Notifications.MarkReadByUrlResponsePayload> = async(\n payload,\n ctx,\n) => {\n const session = getSessionUser(ctx)\n if (!session) {\n return { ok: false, error: \"unauthorized\" }\n }\n\n const ability = buildAbilityFromSession({ tenantId: session.tenantId, session: ctx.req.session })\n if (!ability.can(\"update\", \"RBNotification\")) {\n ctx.res.status(403)\n return { ok: false, error: \"forbidden\" }\n }\n\n const parsed = Notifications.markReadByUrlRequestSchema.safeParse(payload)\n if (!parsed.success) {\n ctx.res.status(400)\n return { ok: false, error: \"invalid_payload\" }\n }\n\n const origin = getRequestOrigin(ctx)\n const targetUrl = Notifications.normalizeNotificationActionUrl(parsed.data.url, origin)\n if (!targetUrl) {\n ctx.res.status(400)\n return { ok: false, error: \"invalid_payload\" }\n }\n\n const NotificationModel = await models.get(\"RBNotification\", { req: ctx.req, ability })\n const query: Record<string, unknown> = {\n $and: [\n { userId: session.userId },\n { archivedAt: { $exists: false } },\n { readAt: { $exists: false } },\n {\n $or: [\n { \"data.link\": { $type: \"string\" } },\n { \"platform.webpush.fcmOptions.link\": { $type: \"string\" } },\n ],\n },\n getAccessibleByQuery(ability, \"update\", \"RBNotification\"),\n ],\n }\n\n const candidates = (await NotificationModel.find(query)\n .select({ _id: 1, data: 1, platform: 1 })\n .lean()) as NotificationActionDoc[]\n\n const matchingIds = candidates\n .filter((notification) =>\n getNotificationActionLinks(notification).some((action) =>\n notificationActionLinkMatchesUrl(action, targetUrl, origin),\n ),\n )\n .map((notification) => notification._id)\n\n if (matchingIds.length === 0) {\n return Notifications.markReadByUrlResponseSchema.parse({\n ok: true,\n matchedCount: 0,\n modifiedCount: 0,\n })\n }\n\n const now = new Date()\n const result = await NotificationModel.updateMany(\n {\n $and: [\n { _id: { $in: matchingIds } },\n { userId: session.userId },\n { archivedAt: { $exists: false } },\n { readAt: { $exists: false } },\n getAccessibleByQuery(ability, \"update\", \"RBNotification\"),\n ],\n },\n { $set: { readAt: now, seenAt: now } },\n )\n\n const modifiedCount = typeof result.modifiedCount === \"number\" ? result.modifiedCount : matchingIds.length\n\n return Notifications.markReadByUrlResponseSchema.parse({\n ok: true,\n matchedCount: matchingIds.length,\n modifiedCount,\n })\n}\n\nconst markAllRead: ApiHandler<unknown, Notifications.MarkAllReadResponsePayload> = async(\n _payload,\n ctx,\n) => {\n const session = getSessionUser(ctx)\n if (!session) {\n return { ok: false, error: \"unauthorized\" }\n }\n\n const ability = buildAbilityFromSession({ tenantId: session.tenantId, session: ctx.req.session })\n if (!ability.can(\"update\", \"RBNotification\")) {\n ctx.res.status(403)\n return { ok: false, error: \"forbidden\" }\n }\n\n const SettingsModel = await models.get(\"RBNotificationSettings\", { req: ctx.req, ability })\n const settings = (await SettingsModel.findOne({ userId: session.userId }).lean()) as SettingsDoc | null\n const disabledTopics = buildDisabledTopics(settings, \"inApp\")\n\n const NotificationModel = await models.get(\"RBNotification\", { req: ctx.req, ability })\n\n const queryFilters: Record<string, unknown>[] = [\n { userId: session.userId },\n { archivedAt: { $exists: false } },\n { readAt: { $exists: false } },\n getAccessibleByQuery(ability, \"update\", \"RBNotification\"),\n ]\n if (disabledTopics.length > 0) queryFilters.push({ topic: { $nin: disabledTopics } })\n const query: Record<string, unknown> = { $and: queryFilters }\n\n const now = new Date()\n await NotificationModel.updateMany(query, { $set: { readAt: now, seenAt: now } })\n\n return { ok: true }\n}\n\nconst archiveNotification: ApiHandler<unknown, Notifications.ArchiveResponsePayload> = async(\n _payload,\n ctx,\n) => {\n const session = getSessionUser(ctx)\n if (!session) {\n return { ok: false, error: \"unauthorized\" }\n }\n\n const ability = buildAbilityFromSession({ tenantId: session.tenantId, session: ctx.req.session })\n if (!ability.can(\"update\", \"RBNotification\")) {\n ctx.res.status(403)\n return { ok: false, error: \"forbidden\" }\n }\n\n const notificationId = typeof ctx.req.params.notificationId === \"string\" ? ctx.req.params.notificationId.trim() : \"\"\n if (!notificationId) {\n ctx.res.status(400)\n return { ok: false, error: \"missing_notification_id\" }\n }\n\n const NotificationModel = await models.get(\"RBNotification\", { req: ctx.req, ability })\n\n try {\n await NotificationModel.updateOne(\n { $and: [{ _id: notificationId }, { archivedAt: { $exists: false } }, getAccessibleByQuery(ability, \"update\", \"RBNotification\")] },\n { $set: { archivedAt: new Date(), drawerActive: false } },\n )\n } catch {\n ctx.res.status(400)\n return { ok: false, error: \"invalid_notification_id\" }\n }\n\n return { ok: true }\n}\n\nconst getSettings: ApiHandler<unknown, Notifications.SettingsResponsePayload> = async(\n _payload,\n ctx,\n) => {\n const session = getSessionUser(ctx)\n if (!session) {\n return { ok: false, error: \"unauthorized\" }\n }\n\n const ability = buildAbilityFromSession({ tenantId: session.tenantId, session: ctx.req.session })\n if (!ability.can(\"read\", \"RBNotificationSettings\")) {\n ctx.res.status(403)\n return { ok: false, error: \"forbidden\" }\n }\n\n const SettingsModel = await models.get(\"RBNotificationSettings\", { req: ctx.req, ability })\n const settings = (await SettingsModel.findOne(\n { $and: [{ userId: session.userId }, getAccessibleByQuery(ability, \"read\", \"RBNotificationSettings\")] },\n ).lean()) as SettingsDoc | null\n\n const digestFrequencyRaw = typeof settings?.digestFrequency === \"string\" ? settings.digestFrequency : \"weekly\"\n const digestFrequency: Notifications.DigestFrequency =\n digestFrequencyRaw === \"off\" || digestFrequencyRaw === \"daily\" || digestFrequencyRaw === \"weekly\"\n ? digestFrequencyRaw\n : \"weekly\"\n\n const topicPreferences = Array.isArray(settings?.topicPreferences)\n ? settings!.topicPreferences.map((pref) => ({\n topic: typeof pref.topic === \"string\" ? pref.topic : \"\",\n inApp: pref.inApp === true,\n emailDigest: pref.emailDigest === true,\n push: pref.push === true,\n })).filter((pref) => pref.topic.length > 0)\n : []\n\n return Notifications.settingsResponseSchema.parse({\n ok: true,\n settings: {\n digestFrequency,\n topicPreferences,\n lastDigestSentAt: toIso(settings?.lastDigestSentAt),\n },\n })\n}\n\nconst updateSettings: ApiHandler<Notifications.UpdateSettingsRequestPayload, Notifications.UpdateSettingsResponsePayload> = async(\n payload,\n ctx,\n) => {\n const session = getSessionUser(ctx)\n if (!session) {\n return { ok: false, error: \"unauthorized\" }\n }\n\n const ability = buildAbilityFromSession({ tenantId: session.tenantId, session: ctx.req.session })\n if (!ability.can(\"update\", \"RBNotificationSettings\")) {\n ctx.res.status(403)\n return { ok: false, error: \"forbidden\" }\n }\n\n const parsed = Notifications.updateSettingsRequestSchema.safeParse(payload)\n if (!parsed.success) {\n ctx.res.status(400)\n return { ok: false, error: \"invalid_payload\" }\n }\n\n const SettingsModel = await models.get(\"RBNotificationSettings\", { req: ctx.req, ability })\n const nextValues: Record<string, unknown> = {}\n\n if (parsed.data.digestFrequency) {\n nextValues.digestFrequency = parsed.data.digestFrequency\n }\n\n if (parsed.data.topicPreferences) {\n const seen = new Set<string>()\n const next = parsed.data.topicPreferences\n .map((pref) => ({\n topic: pref.topic.trim(),\n inApp: pref.inApp,\n emailDigest: pref.emailDigest,\n push: pref.push,\n }))\n .filter((pref) => pref.topic.length > 0)\n .filter((pref) => {\n if (seen.has(pref.topic)) return false\n seen.add(pref.topic)\n return true\n })\n\n nextValues.topicPreferences = next\n }\n\n const ops: Record<string, unknown> = {\n $setOnInsert: { userId: session.userId },\n }\n\n if (Object.keys(nextValues).length > 0) {\n ops.$set = nextValues\n }\n\n const settings = (await SettingsModel.findOneAndUpdate(\n { $and: [{ userId: session.userId }, getAccessibleByQuery(ability, \"update\", \"RBNotificationSettings\")] },\n ops,\n { upsert: true, returnDocument: \"after\", setDefaultsOnInsert: true },\n ).lean()) as SettingsDoc | null\n\n const digestFrequencyRaw = typeof settings?.digestFrequency === \"string\" ? settings.digestFrequency : \"weekly\"\n const digestFrequency: Notifications.DigestFrequency =\n digestFrequencyRaw === \"off\" || digestFrequencyRaw === \"daily\" || digestFrequencyRaw === \"weekly\"\n ? digestFrequencyRaw\n : \"weekly\"\n\n const topicPreferences = Array.isArray(settings?.topicPreferences)\n ? settings!.topicPreferences.map((pref) => ({\n topic: typeof pref.topic === \"string\" ? pref.topic : \"\",\n inApp: pref.inApp === true,\n emailDigest: pref.emailDigest === true,\n push: pref.push === true,\n })).filter((pref) => pref.topic.length > 0)\n : []\n\n return Notifications.updateSettingsResponseSchema.parse({\n ok: true,\n settings: {\n digestFrequency,\n topicPreferences,\n lastDigestSentAt: toIso(settings?.lastDigestSentAt),\n },\n })\n}\n\nconst runDigest: ApiHandler<Notifications.DigestRunRequestPayload, Notifications.DigestRunResponsePayload> = async(\n payload,\n ctx,\n) => {\n const session = getSessionUser(ctx)\n if (!session) {\n return { ok: false, error: \"unauthorized\" }\n }\n\n const ability = buildAbilityFromSession({ tenantId: session.tenantId, session: ctx.req.session })\n if (!ability.can(\"read\", \"RBNotification\")) {\n ctx.res.status(403)\n return { ok: false, error: \"forbidden\" }\n }\n\n const parsed = Notifications.digestRunRequestSchema.safeParse(payload)\n if (!parsed.success) {\n ctx.res.status(400)\n return { ok: false, error: \"invalid_payload\" }\n }\n\n const result = await sendNotificationsDigestForUser(ctx, {\n userId: session.userId,\n ability,\n force: parsed.data.force === true,\n })\n\n if (!result.ok) {\n ctx.res.status(500)\n return { ok: false, error: result.error }\n }\n\n return {\n ok: true,\n sent: result.sent,\n ...(result.skippedReason ? { skippedReason: result.skippedReason } : {}),\n }\n}\n\nexport default (api: Api) => {\n api.post(Notifications.ListRoute, listNotifications)\n api.post(Notifications.CreateRoute, createNotificationForCurrentUser)\n api.post(Notifications.MarkReadRoute, markRead)\n api.post(Notifications.MarkReadByUrlRoute, markReadByUrl)\n api.post(Notifications.MarkAllReadRoute, markAllRead)\n api.post(Notifications.ArchiveRoute, archiveNotification)\n api.get(Notifications.SettingsRoute, getSettings)\n api.put(Notifications.SettingsRoute, updateSettings)\n api.post(Notifications.DigestRunRoute, runDigest)\n}\n"],"mappings":";;;;;AAQA,IAAaI,kBAAkBC,QAAa;CAC1C,MAAMC,iBAAkBD,IAAIE,IAAIC,SAAmEC;CACnG,MA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