@rpcbase/server 0.474.0 → 0.476.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 (33) hide show
  1. package/dist/email-DEw8keax.js +8041 -0
  2. package/dist/handler-BITFtEr_.js +396 -0
  3. package/dist/{handler-D6oN38vE.js → handler-BYVnU9H-.js} +1 -1
  4. package/dist/{handler-ybYk2VTq.js → handler-CHuOXAtH.js} +5 -5
  5. package/dist/{handler-CGko2pJM.js → handler-DEEir2xV.js} +2 -2
  6. package/dist/{index-dlSIqvl2.js → index-Ckx0UHs6.js} +3 -3
  7. package/dist/index.js +70 -8107
  8. package/dist/notifications/api/notifications/handler.d.ts +4 -0
  9. package/dist/notifications/api/notifications/handler.d.ts.map +1 -0
  10. package/dist/notifications/api/notifications/index.d.ts +168 -0
  11. package/dist/notifications/api/notifications/index.d.ts.map +1 -0
  12. package/dist/notifications/api/notifications/shared.d.ts +6 -0
  13. package/dist/notifications/api/notifications/shared.d.ts.map +1 -0
  14. package/dist/notifications/createNotification.d.ts +13 -0
  15. package/dist/notifications/createNotification.d.ts.map +1 -0
  16. package/dist/notifications/digest.d.ts +13 -0
  17. package/dist/notifications/digest.d.ts.map +1 -0
  18. package/dist/notifications/routes.d.ts +2 -0
  19. package/dist/notifications/routes.d.ts.map +1 -0
  20. package/dist/notifications.d.ts +4 -0
  21. package/dist/notifications.d.ts.map +1 -0
  22. package/dist/notifications.js +126 -0
  23. package/dist/rts/api/changes/handler.d.ts +2 -2
  24. package/dist/rts/api/changes/handler.d.ts.map +1 -1
  25. package/dist/rts.js +2 -2
  26. package/dist/{schemas-CyxqObur.js → schemas-DI7ewltq.js} +112 -1
  27. package/dist/{shared-8XhCreJo.js → shared-Chfrv8o6.js} +2 -2
  28. package/dist/types/index.d.ts +2 -2
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/dist/uploads/api/file-uploads/shared.d.ts +1 -1
  31. package/dist/uploads/api/file-uploads/shared.d.ts.map +1 -1
  32. package/dist/uploads.js +1 -1
  33. package/package.json +6 -1
@@ -0,0 +1,4 @@
1
+ import { Api } from '../../../../../api/src';
2
+ declare const _default: (api: Api) => void;
3
+ export default _default;
4
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/notifications/api/notifications/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAmB,MAAM,cAAc,CAAA;yBAsYnC,KAAK,GAAG;AAAxB,wBASC"}
@@ -0,0 +1,168 @@
1
+ import { z } from '../../../../../vite/node_modules/zod';
2
+ export declare const ListRoute = "/api/rb/notifications";
3
+ export declare const CreateRoute = "/api/rb/notifications/create";
4
+ export declare const MarkReadRoute = "/api/rb/notifications/:notificationId/read";
5
+ export declare const ArchiveRoute = "/api/rb/notifications/:notificationId/archive";
6
+ export declare const MarkAllReadRoute = "/api/rb/notifications/mark-all-read";
7
+ export declare const SettingsRoute = "/api/rb/notifications/settings";
8
+ export declare const DigestRunRoute = "/api/rb/notifications/digest/run";
9
+ export declare const listRequestSchema: z.ZodObject<{
10
+ includeArchived: z.ZodOptional<z.ZodBoolean>;
11
+ unreadOnly: z.ZodOptional<z.ZodBoolean>;
12
+ limit: z.ZodOptional<z.ZodNumber>;
13
+ markSeen: z.ZodOptional<z.ZodBoolean>;
14
+ }, z.core.$strip>;
15
+ export type ListRequestPayload = z.infer<typeof listRequestSchema>;
16
+ export declare const createRequestSchema: z.ZodObject<{
17
+ topic: z.ZodOptional<z.ZodString>;
18
+ title: z.ZodString;
19
+ body: z.ZodOptional<z.ZodString>;
20
+ url: z.ZodOptional<z.ZodString>;
21
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
22
+ }, z.core.$strip>;
23
+ export type CreateRequestPayload = z.infer<typeof createRequestSchema>;
24
+ export declare const notificationSchema: z.ZodObject<{
25
+ id: z.ZodString;
26
+ topic: z.ZodOptional<z.ZodString>;
27
+ title: z.ZodString;
28
+ body: z.ZodOptional<z.ZodString>;
29
+ url: z.ZodOptional<z.ZodString>;
30
+ createdAt: z.ZodString;
31
+ seenAt: z.ZodOptional<z.ZodString>;
32
+ readAt: z.ZodOptional<z.ZodString>;
33
+ archivedAt: z.ZodOptional<z.ZodString>;
34
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
35
+ }, z.core.$strip>;
36
+ export type NotificationPayload = z.infer<typeof notificationSchema>;
37
+ export declare const listResponseSchema: z.ZodObject<{
38
+ ok: z.ZodBoolean;
39
+ error: z.ZodOptional<z.ZodString>;
40
+ notifications: z.ZodOptional<z.ZodArray<z.ZodObject<{
41
+ id: z.ZodString;
42
+ topic: z.ZodOptional<z.ZodString>;
43
+ title: z.ZodString;
44
+ body: z.ZodOptional<z.ZodString>;
45
+ url: z.ZodOptional<z.ZodString>;
46
+ createdAt: z.ZodString;
47
+ seenAt: z.ZodOptional<z.ZodString>;
48
+ readAt: z.ZodOptional<z.ZodString>;
49
+ archivedAt: z.ZodOptional<z.ZodString>;
50
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
51
+ }, z.core.$strip>>>;
52
+ unreadCount: z.ZodOptional<z.ZodNumber>;
53
+ unseenCount: z.ZodOptional<z.ZodNumber>;
54
+ }, z.core.$strip>;
55
+ export type ListResponsePayload = z.infer<typeof listResponseSchema>;
56
+ export declare const createResponseSchema: z.ZodObject<{
57
+ ok: z.ZodBoolean;
58
+ error: z.ZodOptional<z.ZodString>;
59
+ id: z.ZodOptional<z.ZodString>;
60
+ }, z.core.$strip>;
61
+ export type CreateResponsePayload = z.infer<typeof createResponseSchema>;
62
+ export declare const markReadResponseSchema: z.ZodObject<{
63
+ ok: z.ZodBoolean;
64
+ error: z.ZodOptional<z.ZodString>;
65
+ }, z.core.$strip>;
66
+ export type MarkReadResponsePayload = z.infer<typeof markReadResponseSchema>;
67
+ export declare const archiveResponseSchema: z.ZodObject<{
68
+ ok: z.ZodBoolean;
69
+ error: z.ZodOptional<z.ZodString>;
70
+ }, z.core.$strip>;
71
+ export type ArchiveResponsePayload = z.infer<typeof archiveResponseSchema>;
72
+ export declare const markAllReadResponseSchema: z.ZodObject<{
73
+ ok: z.ZodBoolean;
74
+ error: z.ZodOptional<z.ZodString>;
75
+ }, z.core.$strip>;
76
+ export type MarkAllReadResponsePayload = z.infer<typeof markAllReadResponseSchema>;
77
+ export declare const digestFrequencySchema: z.ZodEnum<{
78
+ off: "off";
79
+ daily: "daily";
80
+ weekly: "weekly";
81
+ }>;
82
+ export type DigestFrequency = z.infer<typeof digestFrequencySchema>;
83
+ export declare const topicPreferenceSchema: z.ZodObject<{
84
+ topic: z.ZodString;
85
+ inApp: z.ZodBoolean;
86
+ emailDigest: z.ZodBoolean;
87
+ push: z.ZodBoolean;
88
+ }, z.core.$strip>;
89
+ export type TopicPreferencePayload = z.infer<typeof topicPreferenceSchema>;
90
+ export declare const settingsSchema: z.ZodObject<{
91
+ digestFrequency: z.ZodEnum<{
92
+ off: "off";
93
+ daily: "daily";
94
+ weekly: "weekly";
95
+ }>;
96
+ topicPreferences: z.ZodArray<z.ZodObject<{
97
+ topic: z.ZodString;
98
+ inApp: z.ZodBoolean;
99
+ emailDigest: z.ZodBoolean;
100
+ push: z.ZodBoolean;
101
+ }, z.core.$strip>>;
102
+ lastDigestSentAt: z.ZodOptional<z.ZodString>;
103
+ }, z.core.$strip>;
104
+ export type SettingsPayload = z.infer<typeof settingsSchema>;
105
+ export declare const settingsResponseSchema: z.ZodObject<{
106
+ ok: z.ZodBoolean;
107
+ error: z.ZodOptional<z.ZodString>;
108
+ settings: z.ZodOptional<z.ZodObject<{
109
+ digestFrequency: z.ZodEnum<{
110
+ off: "off";
111
+ daily: "daily";
112
+ weekly: "weekly";
113
+ }>;
114
+ topicPreferences: z.ZodArray<z.ZodObject<{
115
+ topic: z.ZodString;
116
+ inApp: z.ZodBoolean;
117
+ emailDigest: z.ZodBoolean;
118
+ push: z.ZodBoolean;
119
+ }, z.core.$strip>>;
120
+ lastDigestSentAt: z.ZodOptional<z.ZodString>;
121
+ }, z.core.$strip>>;
122
+ }, z.core.$strip>;
123
+ export type SettingsResponsePayload = z.infer<typeof settingsResponseSchema>;
124
+ export declare const updateSettingsRequestSchema: z.ZodObject<{
125
+ digestFrequency: z.ZodOptional<z.ZodEnum<{
126
+ off: "off";
127
+ daily: "daily";
128
+ weekly: "weekly";
129
+ }>>;
130
+ topicPreferences: z.ZodOptional<z.ZodArray<z.ZodObject<{
131
+ topic: z.ZodString;
132
+ inApp: z.ZodBoolean;
133
+ emailDigest: z.ZodBoolean;
134
+ push: z.ZodBoolean;
135
+ }, z.core.$strip>>>;
136
+ }, z.core.$strip>;
137
+ export type UpdateSettingsRequestPayload = z.infer<typeof updateSettingsRequestSchema>;
138
+ export declare const updateSettingsResponseSchema: z.ZodObject<{
139
+ ok: z.ZodBoolean;
140
+ error: z.ZodOptional<z.ZodString>;
141
+ settings: z.ZodOptional<z.ZodObject<{
142
+ digestFrequency: z.ZodEnum<{
143
+ off: "off";
144
+ daily: "daily";
145
+ weekly: "weekly";
146
+ }>;
147
+ topicPreferences: z.ZodArray<z.ZodObject<{
148
+ topic: z.ZodString;
149
+ inApp: z.ZodBoolean;
150
+ emailDigest: z.ZodBoolean;
151
+ push: z.ZodBoolean;
152
+ }, z.core.$strip>>;
153
+ lastDigestSentAt: z.ZodOptional<z.ZodString>;
154
+ }, z.core.$strip>>;
155
+ }, z.core.$strip>;
156
+ export type UpdateSettingsResponsePayload = z.infer<typeof updateSettingsResponseSchema>;
157
+ export declare const digestRunRequestSchema: z.ZodObject<{
158
+ force: z.ZodOptional<z.ZodBoolean>;
159
+ }, z.core.$strip>;
160
+ export type DigestRunRequestPayload = z.infer<typeof digestRunRequestSchema>;
161
+ export declare const digestRunResponseSchema: z.ZodObject<{
162
+ ok: z.ZodBoolean;
163
+ error: z.ZodOptional<z.ZodString>;
164
+ sent: z.ZodOptional<z.ZodBoolean>;
165
+ skippedReason: z.ZodOptional<z.ZodString>;
166
+ }, z.core.$strip>;
167
+ export type DigestRunResponsePayload = z.infer<typeof digestRunResponseSchema>;
168
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/notifications/api/notifications/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,eAAO,MAAM,SAAS,0BAA0B,CAAA;AAChD,eAAO,MAAM,WAAW,iCAAiC,CAAA;AACzD,eAAO,MAAM,aAAa,+CAA+C,CAAA;AACzE,eAAO,MAAM,YAAY,kDAAkD,CAAA;AAC3E,eAAO,MAAM,gBAAgB,wCAAwC,CAAA;AACrE,eAAO,MAAM,aAAa,mCAAmC,CAAA;AAC7D,eAAO,MAAM,cAAc,qCAAqC,CAAA;AAEhE,eAAO,MAAM,iBAAiB;;;;;iBAK5B,CAAA;AAEF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAElE,eAAO,MAAM,mBAAmB;;;;;;iBAM9B,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAEtE,eAAO,MAAM,kBAAkB;;;;;;;;;;;iBAW7B,CAAA;AAEF,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAEpE,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;iBAM7B,CAAA;AAEF,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAEpE,eAAO,MAAM,oBAAoB;;;;iBAI/B,CAAA;AAEF,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAA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C,CAAA;AAEF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAE5E,eAAO,MAAM,uBAAuB;;;;;iBAKlC,CAAA;AAEF,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { Ctx } from '../../../../../api/src';
2
+ export declare const getSessionUser: (ctx: Ctx) => {
3
+ userId: string;
4
+ tenantId: string;
5
+ } | null;
6
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../../src/notifications/api/notifications/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAQvC,eAAO,MAAM,cAAc,GAAI,KAAK,GAAG;;;QAgBtC,CAAA"}
@@ -0,0 +1,13 @@
1
+ import { Ctx } from '../../../api/src';
2
+ export type CreateNotificationInput = {
3
+ userId: string;
4
+ topic?: string;
5
+ title: string;
6
+ body?: string;
7
+ url?: string;
8
+ metadata?: Record<string, unknown>;
9
+ };
10
+ export declare const createNotification: (ctx: Ctx, input: CreateNotificationInput) => Promise<{
11
+ id: string;
12
+ }>;
13
+ //# sourceMappingURL=createNotification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNotification.d.ts","sourceRoot":"","sources":["../../src/notifications/createNotification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAIvC,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC,CAAA;AAED,eAAO,MAAM,kBAAkB,GAC7B,KAAK,GAAG,EACR,OAAO,uBAAuB,KAC7B,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAyBxB,CAAA"}
@@ -0,0 +1,13 @@
1
+ import { Ctx } from '../../../api/src';
2
+ export declare const sendNotificationsDigestForUser: (ctx: Ctx, { userId, force, }: {
3
+ userId: string;
4
+ force?: boolean;
5
+ }) => Promise<{
6
+ ok: true;
7
+ sent: boolean;
8
+ skippedReason?: string;
9
+ } | {
10
+ ok: false;
11
+ error: string;
12
+ }>;
13
+ //# sourceMappingURL=digest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../../src/notifications/digest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAuCvC,eAAO,MAAM,8BAA8B,GACzC,KAAK,GAAG,EACR,oBAGG;IACD,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,KACA,OAAO,CAAC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CA0F5F,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const routes: Record<string, unknown>;
2
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/notifications/routes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,yBAKb,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './notifications/routes';
2
+ export * from './notifications/createNotification';
3
+ export * from './notifications/digest';
4
+ //# sourceMappingURL=notifications.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notifications.d.ts","sourceRoot":"","sources":["../src/notifications.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,oCAAoC,CAAA;AAClD,cAAc,wBAAwB,CAAA"}
@@ -0,0 +1,126 @@
1
+ import { loadModel, loadRbModel } from "@rpcbase/db";
2
+ import { s as sendEmail } from "./email-DEw8keax.js";
3
+ const routes = Object.entries({
4
+ .../* @__PURE__ */ Object.assign({ "./api/notifications/handler.ts": () => import("./handler-BITFtEr_.js") })
5
+ }).reduce((acc, [path, mod]) => {
6
+ acc[path.replace("./api/", "@rpcbase/server/notifications/api/")] = mod;
7
+ return acc;
8
+ }, {});
9
+ const createNotification = async (ctx, input) => {
10
+ const userId = input.userId.trim();
11
+ const title = input.title.trim();
12
+ if (!userId) {
13
+ throw new Error("createNotification: userId is required");
14
+ }
15
+ if (!title) {
16
+ throw new Error("createNotification: title is required");
17
+ }
18
+ const topic = typeof input.topic === "string" ? input.topic.trim() : "";
19
+ const body = typeof input.body === "string" ? input.body.trim() : "";
20
+ const url = typeof input.url === "string" ? input.url.trim() : "";
21
+ const NotificationModel = await loadModel("RBNotification", ctx);
22
+ const doc = await NotificationModel.create({
23
+ userId,
24
+ ...topic ? { topic } : {},
25
+ title,
26
+ ...body ? { body } : {},
27
+ ...url ? { url } : {},
28
+ ...input.metadata ? { metadata: input.metadata } : {}
29
+ });
30
+ return { id: doc._id.toString() };
31
+ };
32
+ const DAY_MS = 24 * 60 * 60 * 1e3;
33
+ const WEEK_MS = 7 * DAY_MS;
34
+ const getDigestWindowMs = (frequency) => {
35
+ if (frequency === "daily") return DAY_MS;
36
+ if (frequency === "weekly") return WEEK_MS;
37
+ return 0;
38
+ };
39
+ const formatIso = (value) => {
40
+ if (!(value instanceof Date)) return void 0;
41
+ return value.toISOString();
42
+ };
43
+ const buildPreferencesByTopic = (settings) => {
44
+ const record = {};
45
+ const raw = settings?.topicPreferences;
46
+ if (!Array.isArray(raw)) return record;
47
+ for (const pref of raw) {
48
+ if (!pref || typeof pref !== "object") continue;
49
+ const topic = typeof pref.topic === "string" ? pref.topic.trim() : "";
50
+ if (!topic) continue;
51
+ const emailDigest = pref.emailDigest;
52
+ record[topic] = { emailDigest: emailDigest === true };
53
+ }
54
+ return record;
55
+ };
56
+ const sendNotificationsDigestForUser = async (ctx, {
57
+ userId,
58
+ force = false
59
+ }) => {
60
+ const SettingsModel = await loadModel("RBNotificationSettings", ctx);
61
+ const NotificationModel = await loadModel("RBNotification", ctx);
62
+ const settings = await SettingsModel.findOne({ userId }).lean();
63
+ const digestFrequencyRaw = typeof settings?.digestFrequency === "string" ? settings.digestFrequency : "weekly";
64
+ const digestFrequency = digestFrequencyRaw === "daily" || digestFrequencyRaw === "weekly" || digestFrequencyRaw === "off" ? digestFrequencyRaw : "weekly";
65
+ if (digestFrequency === "off") {
66
+ return { ok: true, sent: false, skippedReason: "digest_off" };
67
+ }
68
+ const now = /* @__PURE__ */ new Date();
69
+ const windowMs = getDigestWindowMs(digestFrequency);
70
+ const lastSentAt = settings?.lastDigestSentAt instanceof Date ? settings.lastDigestSentAt : null;
71
+ const since = lastSentAt ?? new Date(now.getTime() - windowMs);
72
+ if (!force && lastSentAt && now.getTime() - lastSentAt.getTime() < windowMs) {
73
+ return { ok: true, sent: false, skippedReason: "not_due" };
74
+ }
75
+ const preferencesByTopic = buildPreferencesByTopic(settings);
76
+ const disabledTopics = Object.entries(preferencesByTopic).filter(([, pref]) => pref.emailDigest === false).map(([topic]) => topic);
77
+ const query = {
78
+ userId,
79
+ archivedAt: { $exists: false },
80
+ readAt: { $exists: false },
81
+ createdAt: { $gt: since }
82
+ };
83
+ if (disabledTopics.length > 0) {
84
+ query.topic = { $nin: disabledTopics };
85
+ }
86
+ const notifications = await NotificationModel.find(query).sort({ createdAt: -1 }).limit(50).lean();
87
+ if (!notifications.length) {
88
+ await SettingsModel.updateOne(
89
+ { userId },
90
+ { $set: { lastDigestSentAt: now }, $setOnInsert: { userId, digestFrequency: "weekly" } },
91
+ { upsert: true }
92
+ );
93
+ return { ok: true, sent: false, skippedReason: "empty" };
94
+ }
95
+ const UserModel = await loadRbModel("RBUser", ctx);
96
+ const user = await UserModel.findById(userId, { email: 1 }).lean();
97
+ const email = typeof user?.email === "string" ? user.email.trim() : "";
98
+ if (!email) {
99
+ return { ok: true, sent: false, skippedReason: "missing_email" };
100
+ }
101
+ const subject = "Notifications digest";
102
+ const rows = notifications.map((n) => {
103
+ const title = typeof n.title === "string" ? n.title : "";
104
+ const body = typeof n.body === "string" ? n.body : "";
105
+ const url = typeof n.url === "string" ? n.url : "";
106
+ const createdAt = formatIso(n.createdAt) ?? "";
107
+ const line = url ? `<li><strong>${title}</strong><br>${body}<br><a href="${url}">${url}</a><br><small>${createdAt}</small></li>` : `<li><strong>${title}</strong><br>${body}<br><small>${createdAt}</small></li>`;
108
+ return line;
109
+ }).join("");
110
+ const html = `<div><p>Here is your notifications digest:</p><ul>${rows}</ul></div>`;
111
+ const emailResult = await sendEmail({ to: email, subject, html });
112
+ if (emailResult.error) {
113
+ return { ok: false, error: emailResult.error };
114
+ }
115
+ await SettingsModel.updateOne(
116
+ { userId },
117
+ { $set: { lastDigestSentAt: now }, $setOnInsert: { userId, digestFrequency: "weekly" } },
118
+ { upsert: true }
119
+ );
120
+ return { ok: true, sent: emailResult.skipped !== true, ...emailResult.skipped ? { skippedReason: "email_skipped" } : {} };
121
+ };
122
+ export {
123
+ createNotification,
124
+ routes,
125
+ sendNotificationsDigestForUser
126
+ };
@@ -1,8 +1,8 @@
1
1
  import { Api } from '../../../../../api/src';
2
2
  type SessionUser = {
3
3
  id?: string;
4
- current_tenant_id?: string;
5
- signed_in_tenants?: string[];
4
+ currentTenantId?: string;
5
+ signedInTenants?: string[];
6
6
  };
7
7
  declare const _default: (api: Api<SessionUser>) => void;
8
8
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/rts/api/changes/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAmB,MAAM,cAAc,CAAA;AAOnD,KAAK,WAAW,GAAG;IACjB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC7B,CAAA;yBA0He,KAAK,GAAG,CAAC,WAAW,CAAC;AAArC,wBAEC"}
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/rts/api/changes/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAmB,MAAM,cAAc,CAAA;AAOnD,KAAK,WAAW,GAAG;IACjB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;CAC3B,CAAA;yBA0He,KAAK,GAAG,CAAC,WAAW,CAAC;AAArC,wBAEC"}
package/dist/rts.js CHANGED
@@ -1,6 +1,6 @@
1
- import { i, n, r } from "./index-dlSIqvl2.js";
1
+ import { i, n, r } from "./index-Ckx0UHs6.js";
2
2
  const routes = Object.entries({
3
- .../* @__PURE__ */ Object.assign({ "./api/changes/handler.ts": () => import("./handler-ybYk2VTq.js") })
3
+ .../* @__PURE__ */ Object.assign({ "./api/changes/handler.ts": () => import("./handler-CHuOXAtH.js") })
4
4
  }).reduce((acc, [path, mod]) => {
5
5
  acc[path.replace("./api/", "@rpcbase/server/rts/api/")] = mod;
6
6
  return acc;
@@ -1898,6 +1898,101 @@ function handleIntersectionResults(result, left, right) {
1898
1898
  result.value = merged.data;
1899
1899
  return result;
1900
1900
  }
1901
+ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
1902
+ $ZodType.init(inst, def);
1903
+ inst._zod.parse = (payload, ctx) => {
1904
+ const input = payload.value;
1905
+ if (!isPlainObject(input)) {
1906
+ payload.issues.push({
1907
+ expected: "record",
1908
+ code: "invalid_type",
1909
+ input,
1910
+ inst
1911
+ });
1912
+ return payload;
1913
+ }
1914
+ const proms = [];
1915
+ const values = def.keyType._zod.values;
1916
+ if (values) {
1917
+ payload.value = {};
1918
+ const recordKeys = /* @__PURE__ */ new Set();
1919
+ for (const key of values) {
1920
+ if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
1921
+ recordKeys.add(typeof key === "number" ? key.toString() : key);
1922
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1923
+ if (result instanceof Promise) {
1924
+ proms.push(result.then((result2) => {
1925
+ if (result2.issues.length) {
1926
+ payload.issues.push(...prefixIssues(key, result2.issues));
1927
+ }
1928
+ payload.value[key] = result2.value;
1929
+ }));
1930
+ } else {
1931
+ if (result.issues.length) {
1932
+ payload.issues.push(...prefixIssues(key, result.issues));
1933
+ }
1934
+ payload.value[key] = result.value;
1935
+ }
1936
+ }
1937
+ }
1938
+ let unrecognized;
1939
+ for (const key in input) {
1940
+ if (!recordKeys.has(key)) {
1941
+ unrecognized = unrecognized ?? [];
1942
+ unrecognized.push(key);
1943
+ }
1944
+ }
1945
+ if (unrecognized && unrecognized.length > 0) {
1946
+ payload.issues.push({
1947
+ code: "unrecognized_keys",
1948
+ input,
1949
+ inst,
1950
+ keys: unrecognized
1951
+ });
1952
+ }
1953
+ } else {
1954
+ payload.value = {};
1955
+ for (const key of Reflect.ownKeys(input)) {
1956
+ if (key === "__proto__")
1957
+ continue;
1958
+ const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1959
+ if (keyResult instanceof Promise) {
1960
+ throw new Error("Async schemas not supported in object keys currently");
1961
+ }
1962
+ if (keyResult.issues.length) {
1963
+ payload.issues.push({
1964
+ code: "invalid_key",
1965
+ origin: "record",
1966
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
1967
+ input: key,
1968
+ path: [key],
1969
+ inst
1970
+ });
1971
+ payload.value[keyResult.value] = keyResult.value;
1972
+ continue;
1973
+ }
1974
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1975
+ if (result instanceof Promise) {
1976
+ proms.push(result.then((result2) => {
1977
+ if (result2.issues.length) {
1978
+ payload.issues.push(...prefixIssues(key, result2.issues));
1979
+ }
1980
+ payload.value[keyResult.value] = result2.value;
1981
+ }));
1982
+ } else {
1983
+ if (result.issues.length) {
1984
+ payload.issues.push(...prefixIssues(key, result.issues));
1985
+ }
1986
+ payload.value[keyResult.value] = result.value;
1987
+ }
1988
+ }
1989
+ }
1990
+ if (proms.length) {
1991
+ return Promise.all(proms).then(() => payload);
1992
+ }
1993
+ return payload;
1994
+ };
1995
+ });
1901
1996
  const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
1902
1997
  $ZodType.init(inst, def);
1903
1998
  const values = getEnumValues(def.entries);
@@ -3081,6 +3176,20 @@ function intersection(left, right) {
3081
3176
  right
3082
3177
  });
3083
3178
  }
3179
+ const ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
3180
+ $ZodRecord.init(inst, def);
3181
+ ZodType.init(inst, def);
3182
+ inst.keyType = def.keyType;
3183
+ inst.valueType = def.valueType;
3184
+ });
3185
+ function record(keyType, valueType, params) {
3186
+ return new ZodRecord({
3187
+ type: "record",
3188
+ keyType,
3189
+ valueType,
3190
+ ...normalizeParams(params)
3191
+ });
3192
+ }
3084
3193
  const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
3085
3194
  $ZodEnum.init(inst, def);
3086
3195
  ZodType.init(inst, def);
@@ -3280,5 +3389,7 @@ export {
3280
3389
  boolean as b,
3281
3390
  number as n,
3282
3391
  object as o,
3283
- string as s
3392
+ record as r,
3393
+ string as s,
3394
+ unknown as u
3284
3395
  };
@@ -34,7 +34,7 @@ const getUserId = (ctx) => {
34
34
  return normalized ? normalized : null;
35
35
  };
36
36
  const getTenantId = (ctx) => {
37
- const rawSession = ctx.req.session?.user?.current_tenant_id;
37
+ const rawSession = ctx.req.session?.user?.currentTenantId;
38
38
  const sessionTenantId = typeof rawSession === "string" ? rawSession.trim() : "";
39
39
  const userId = getUserId(ctx);
40
40
  const rawQuery = ctx.req.query?.["rb-tenant-id"];
@@ -51,7 +51,7 @@ const getModelCtx = (_ctx, tenantId) => ({
51
51
  req: {
52
52
  session: {
53
53
  user: {
54
- current_tenant_id: tenantId
54
+ currentTenantId: tenantId
55
55
  }
56
56
  }
57
57
  }
@@ -1,6 +1,6 @@
1
1
  export type SessionUser = {
2
2
  id: string;
3
- current_tenant_id: string;
4
- signed_in_tenants: string[];
3
+ currentTenantId: string;
4
+ signedInTenants: string[];
5
5
  };
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAA"}
@@ -3,7 +3,7 @@ import { IRBUploadChunk, IRBUploadSession, LoadModelCtx } from '../../../../../d
3
3
  import { Model } from '../../../../../vite/node_modules/mongoose';
4
4
  export type SessionUser = {
5
5
  id?: string;
6
- current_tenant_id?: string;
6
+ currentTenantId?: string;
7
7
  };
8
8
  export type UploadSessionDoc = IRBUploadSession;
9
9
  export type UploadChunkDoc = Omit<IRBUploadChunk, "data"> & {
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../../src/uploads/api/file-uploads/shared.ts"],"names":[],"mapp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M,aAAa,QAAO,MAAsE,CAAA;AAEvG,eAAO,MAAM,SAAS,GAAI,KAAK,GAAG,CAAC,WAAW,CAAC,KAAG,MAAM,GAAG,IAK1D,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,KAAK,GAAG,CAAC,WAAW,CAAC,KAAG,MAAM,GAAG,IAgB5D,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,KAAG,MAAyD,CAAA;AAEzG,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,MAAoC,CAAA;AAEvF,eAAO,MAAM,WAAW,GAAI,MAAM,GAAG,CAAC,WAAW,CAAC,EAAE,UAAU,MAAM,KAAG,YAQrE,CAAA;AAEF,eAAO,MAAM,eAAe,GAAI,SAAS,OAAO,KAAG,MAAM,GAAG,IAI3D,CAAA;AAED,eAAO,MAAM,mBAAmB,GAC9B,eAAe,KAAK,CAAC,gBAAgB,CAAC,EACtC,aAAa,KAAK,CAAC,cAAc,CAAC,KACjC,OAAO,CAAC,IAAI,CAUd,CAAA;AAQD,eAAO,MAAM,gBAAgB,GAAI,KAAK,GAAG,CAAC,WAAW,CAAC,KAAG,MAAM,GAAG,IAIjE,CAAA;AAWD,eAAO,MAAM,oBAAoB,GAC/B,KAAK,GAAG,CAAC,WAAW,CAAC,EACrB,SAAS,IAAI,CAAC,gBAAgB,EAAE,QAAQ,GAAG,cAAc,CAAC,KACzD;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAe/C,CAAA"}
package/dist/uploads.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const routes = Object.entries({
2
- .../* @__PURE__ */ Object.assign({ "./api/file-uploads/handler.ts": () => import("./handler-CGko2pJM.js"), "./api/files/handler.ts": () => import("./handler-D6oN38vE.js") })
2
+ .../* @__PURE__ */ Object.assign({ "./api/file-uploads/handler.ts": () => import("./handler-DEEir2xV.js"), "./api/files/handler.ts": () => import("./handler-BYVnU9H-.js") })
3
3
  }).reduce((acc, [path, mod]) => {
4
4
  acc[path.replace("./api/", "@rpcbase/server/uploads/api/")] = mod;
5
5
  return acc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.474.0",
3
+ "version": "0.476.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -22,6 +22,11 @@
22
22
  "types": "./dist/uploads.d.ts",
23
23
  "import": "./dist/uploads.js",
24
24
  "default": "./dist/uploads.js"
25
+ },
26
+ "./notifications": {
27
+ "types": "./dist/notifications.d.ts",
28
+ "import": "./dist/notifications.js",
29
+ "default": "./dist/notifications.js"
25
30
  }
26
31
  },
27
32
  "scripts": {