@headless-lms/core 0.3.0 → 0.5.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.
- package/dist/assets/events.d.ts +24 -18
- package/dist/assets/file-urls.d.ts +11 -7
- package/dist/assets/file-urls.js +14 -4
- package/dist/assets/file-urls.js.map +1 -1
- package/dist/assets/index.d.ts +5 -4
- package/dist/assets/index.js +4 -3
- package/dist/assets/jobs.d.ts +15 -0
- package/dist/assets/jobs.js +30 -0
- package/dist/assets/jobs.js.map +1 -0
- package/dist/assets/ports.d.ts +37 -17
- package/dist/assets/service.d.ts +30 -15
- package/dist/assets/service.js +229 -59
- package/dist/assets/service.js.map +1 -1
- package/dist/automations/actions.js +2 -63
- package/dist/automations/actions.js.map +1 -1
- package/dist/automations/catalog.d.ts +1 -2
- package/dist/automations/catalog.js +137 -65
- package/dist/automations/catalog.js.map +1 -1
- package/dist/automations/community-derivations.js +20 -20
- package/dist/automations/community-derivations.js.map +1 -1
- package/dist/automations/community-mail.d.ts +36 -20
- package/dist/automations/community-mail.js +32 -24
- package/dist/automations/community-mail.js.map +1 -1
- package/dist/automations/event-permissions.d.ts +12 -0
- package/dist/automations/event-permissions.js +38 -0
- package/dist/automations/event-permissions.js.map +1 -0
- package/dist/automations/events.d.ts +0 -10
- package/dist/automations/index.d.ts +12 -4
- package/dist/automations/index.js +9 -1
- package/dist/automations/notifications/applicable.d.ts +8 -0
- package/dist/automations/notifications/applicable.js +12 -0
- package/dist/automations/notifications/applicable.js.map +1 -0
- package/dist/automations/notifications/debounce.d.ts +25 -0
- package/dist/automations/notifications/debounce.js +93 -0
- package/dist/automations/notifications/debounce.js.map +1 -0
- package/dist/automations/notifications/defaults.d.ts +8 -0
- package/dist/automations/notifications/defaults.js +346 -0
- package/dist/automations/notifications/defaults.js.map +1 -0
- package/dist/automations/notifications/delivery.d.ts +28 -0
- package/dist/automations/notifications/delivery.js +88 -0
- package/dist/automations/notifications/delivery.js.map +1 -0
- package/dist/automations/notifications/processor.d.ts +64 -0
- package/dist/automations/notifications/processor.js +270 -0
- package/dist/automations/notifications/processor.js.map +1 -0
- package/dist/automations/notifications/rules/content.d.ts +6 -0
- package/dist/automations/notifications/rules/content.js +96 -0
- package/dist/automations/notifications/rules/content.js.map +1 -0
- package/dist/automations/notifications/rules/discussion.d.ts +7 -0
- package/dist/automations/notifications/rules/discussion.js +678 -0
- package/dist/automations/notifications/rules/discussion.js.map +1 -0
- package/dist/automations/notifications/rules/entitlements.d.ts +6 -0
- package/dist/automations/notifications/rules/entitlements.js +276 -0
- package/dist/automations/notifications/rules/entitlements.js.map +1 -0
- package/dist/automations/notifications/rules/events.d.ts +9 -0
- package/dist/automations/notifications/rules/events.js +27 -0
- package/dist/automations/notifications/rules/events.js.map +1 -0
- package/dist/automations/notifications/rules/index.d.ts +6 -0
- package/dist/automations/notifications/rules/index.js +15 -0
- package/dist/automations/notifications/rules/index.js.map +1 -0
- package/dist/automations/notifications/rules/organizations.d.ts +6 -0
- package/dist/automations/notifications/rules/organizations.js +35 -0
- package/dist/automations/notifications/rules/organizations.js.map +1 -0
- package/dist/automations/notifications/rules/recipients.d.ts +32 -0
- package/dist/automations/notifications/rules/recipients.js +98 -0
- package/dist/automations/notifications/rules/recipients.js.map +1 -0
- package/dist/automations/notifications/service.d.ts +29 -0
- package/dist/automations/notifications/service.js +45 -0
- package/dist/automations/notifications/service.js.map +1 -0
- package/dist/automations/notifications/types.d.ts +7 -0
- package/dist/automations/notifications/types.js +560 -0
- package/dist/automations/notifications/types.js.map +1 -0
- package/dist/automations/ports.d.ts +134 -21
- package/dist/automations/service.d.ts +30 -30
- package/dist/automations/service.js +111 -144
- package/dist/automations/service.js.map +1 -1
- package/dist/content/event-sight.d.ts +11 -0
- package/dist/content/event-sight.js +11 -0
- package/dist/content/event-sight.js.map +1 -0
- package/dist/content/events.d.ts +437 -46
- package/dist/content/events.js +45 -1
- package/dist/content/events.js.map +1 -1
- package/dist/content/index.d.ts +8 -4
- package/dist/content/index.js +5 -1
- package/dist/content/jobs.d.ts +16 -0
- package/dist/content/jobs.js +37 -0
- package/dist/content/jobs.js.map +1 -0
- package/dist/content/model.d.ts +2 -2
- package/dist/content/notification-categories.d.ts +37 -0
- package/dist/content/notification-categories.js +73 -0
- package/dist/content/notification-categories.js.map +1 -0
- package/dist/content/ports.d.ts +132 -68
- package/dist/content/service.d.ts +100 -68
- package/dist/content/service.js +703 -146
- package/dist/content/service.js.map +1 -1
- package/dist/content/titles.d.ts +25 -0
- package/dist/content/titles.js +82 -0
- package/dist/content/titles.js.map +1 -0
- package/dist/content/types.d.ts +2 -2
- package/dist/discussion/authors.d.ts +4 -2
- package/dist/discussion/authors.js +9 -5
- package/dist/discussion/authors.js.map +1 -1
- package/dist/discussion/chats.d.ts +63 -39
- package/dist/discussion/chats.js +455 -190
- package/dist/discussion/chats.js.map +1 -1
- package/dist/discussion/digests.d.ts +24 -0
- package/dist/discussion/digests.js +104 -0
- package/dist/discussion/digests.js.map +1 -0
- package/dist/discussion/events.d.ts +227 -23
- package/dist/discussion/events.js +114 -19
- package/dist/discussion/events.js.map +1 -1
- package/dist/discussion/index.d.ts +12 -4
- package/dist/discussion/index.js +9 -2
- package/dist/discussion/jobs.d.ts +16 -0
- package/dist/discussion/jobs.js +40 -0
- package/dist/discussion/jobs.js.map +1 -0
- package/dist/discussion/live.d.ts +106 -0
- package/dist/discussion/live.js +642 -0
- package/dist/discussion/live.js.map +1 -0
- package/dist/discussion/mentions.d.ts +11 -0
- package/dist/discussion/mentions.js +35 -0
- package/dist/discussion/mentions.js.map +1 -0
- package/dist/discussion/ports.d.ts +279 -114
- package/dist/discussion/ports.js.map +1 -1
- package/dist/discussion/posts.d.ts +60 -44
- package/dist/discussion/posts.js +453 -287
- package/dist/discussion/posts.js.map +1 -1
- package/dist/discussion/rules.d.ts +18 -0
- package/dist/discussion/rules.js +22 -0
- package/dist/discussion/rules.js.map +1 -0
- package/dist/discussion/service.d.ts +50 -35
- package/dist/discussion/service.js +333 -205
- package/dist/discussion/service.js.map +1 -1
- package/dist/discussion/subscriptions.d.ts +37 -0
- package/dist/discussion/subscriptions.js +115 -0
- package/dist/discussion/subscriptions.js.map +1 -0
- package/dist/discussion/titles.d.ts +28 -0
- package/dist/discussion/titles.js +98 -0
- package/dist/discussion/titles.js.map +1 -0
- package/dist/entitlements/events.d.ts +20 -20
- package/dist/entitlements/index.d.ts +5 -4
- package/dist/entitlements/index.js +3 -2
- package/dist/entitlements/jobs.d.ts +12 -0
- package/dist/entitlements/jobs.js +18 -0
- package/dist/entitlements/jobs.js.map +1 -0
- package/dist/entitlements/model.d.ts +2 -2
- package/dist/entitlements/ports.d.ts +68 -38
- package/dist/entitlements/rules.d.ts +3 -6
- package/dist/entitlements/rules.js +5 -10
- package/dist/entitlements/rules.js.map +1 -1
- package/dist/entitlements/service.d.ts +43 -28
- package/dist/entitlements/service.js +387 -160
- package/dist/entitlements/service.js.map +1 -1
- package/dist/identity/devices.d.ts +30 -0
- package/dist/identity/devices.js +109 -0
- package/dist/identity/devices.js.map +1 -0
- package/dist/identity/index.d.ts +6 -5
- package/dist/identity/index.js +4 -3
- package/dist/identity/model.d.ts +2 -2
- package/dist/identity/notification-settings.d.ts +28 -0
- package/dist/identity/notification-settings.js +114 -0
- package/dist/identity/notification-settings.js.map +1 -0
- package/dist/identity/ports.d.ts +80 -56
- package/dist/identity/service.d.ts +8 -7
- package/dist/identity/service.js +17 -13
- package/dist/identity/service.js.map +1 -1
- package/dist/integrations/ports.d.ts +9 -8
- package/dist/integrations/service.d.ts +9 -8
- package/dist/integrations/service.js +33 -16
- package/dist/integrations/service.js.map +1 -1
- package/dist/organizations/default-roles.d.ts +22 -0
- package/dist/organizations/default-roles.js +89 -0
- package/dist/organizations/default-roles.js.map +1 -0
- package/dist/organizations/effective-permissions.d.ts +45 -0
- package/dist/organizations/effective-permissions.js +113 -0
- package/dist/organizations/effective-permissions.js.map +1 -0
- package/dist/organizations/events.d.ts +320 -181
- package/dist/organizations/events.js +90 -18
- package/dist/organizations/events.js.map +1 -1
- package/dist/organizations/index.d.ts +15 -10
- package/dist/organizations/index.js +8 -3
- package/dist/organizations/members.d.ts +66 -8
- package/dist/organizations/members.js.map +1 -1
- package/dist/organizations/notification-catalog.d.ts +31 -0
- package/dist/organizations/notification-catalog.js +32 -0
- package/dist/organizations/notification-catalog.js.map +1 -0
- package/dist/organizations/notification-categories.d.ts +34 -0
- package/dist/organizations/notification-categories.js +66 -0
- package/dist/organizations/notification-categories.js.map +1 -0
- package/dist/organizations/org-roles.d.ts +33 -0
- package/dist/organizations/org-roles.js +49 -0
- package/dist/organizations/org-roles.js.map +1 -0
- package/dist/organizations/permissions.d.ts +311 -0
- package/dist/organizations/permissions.js +327 -0
- package/dist/organizations/permissions.js.map +1 -0
- package/dist/organizations/ports.d.ts +187 -65
- package/dist/organizations/service.d.ts +104 -35
- package/dist/organizations/service.js +1247 -323
- package/dist/organizations/service.js.map +1 -1
- package/dist/organizations/testing.d.ts +18 -0
- package/dist/organizations/testing.js +37 -0
- package/dist/organizations/testing.js.map +1 -0
- package/dist/organizations/types.d.ts +5 -16
- package/dist/progress/index.d.ts +2 -2
- package/dist/progress/ports.d.ts +11 -3
- package/dist/progress/service.d.ts +6 -5
- package/dist/progress/service.js +23 -8
- package/dist/progress/service.js.map +1 -1
- package/dist/reporting/admin/index.d.ts +6 -4
- package/dist/reporting/admin/model.d.ts +36 -3
- package/dist/reporting/admin/ports.d.ts +39 -14
- package/dist/reporting/admin/service.d.ts +32 -11
- package/dist/reporting/admin/service.js +102 -18
- package/dist/reporting/admin/service.js.map +1 -1
- package/dist/reporting/events/index.d.ts +27 -0
- package/dist/reporting/events/index.js +20 -0
- package/dist/reporting/events/index.js.map +1 -0
- package/dist/reporting/member/calendar.d.ts +11 -0
- package/dist/reporting/member/calendar.js +75 -0
- package/dist/reporting/member/calendar.js.map +1 -0
- package/dist/reporting/member/index.d.ts +3 -2
- package/dist/reporting/member/model.d.ts +80 -26
- package/dist/reporting/member/ports.d.ts +50 -28
- package/dist/reporting/member/service.d.ts +81 -35
- package/dist/reporting/member/service.js +438 -145
- package/dist/reporting/member/service.js.map +1 -1
- package/dist/shared/actor.d.ts +22 -3
- package/dist/shared/errors.d.ts +15 -2
- package/dist/shared/errors.js +21 -2
- package/dist/shared/errors.js.map +1 -1
- package/dist/shared/id.d.ts +7 -0
- package/dist/shared/id.js +8 -1
- package/dist/shared/id.js.map +1 -1
- package/dist/shared/logger.d.ts +2 -1
- package/dist/shared/logger.js +10 -1
- package/dist/shared/logger.js.map +1 -1
- package/dist/shared/mailer.d.ts +11 -1
- package/dist/shared/mailer.js +32 -5
- package/dist/shared/mailer.js.map +1 -1
- package/dist/shared/notification-categories.d.ts +16 -0
- package/dist/shared/notification-categories.js +94 -0
- package/dist/shared/notification-categories.js.map +1 -0
- package/dist/shared/notification-settings.d.ts +14 -0
- package/dist/shared/notification-settings.js +61 -0
- package/dist/shared/notification-settings.js.map +1 -0
- package/dist/shared/ports.d.ts +68 -2
- package/dist/shared/settings.d.ts +2 -1
- package/dist/shared/settings.js +1 -0
- package/dist/shared/settings.js.map +1 -1
- package/dist/types/automations.d.ts +8 -2
- package/dist/types/content.d.ts +2 -2
- package/dist/types/discussion.d.ts +4 -5
- package/dist/types/email-templates.d.ts +119 -6
- package/dist/types/entitlements.d.ts +2 -2
- package/dist/types/identity.d.ts +14 -17
- package/dist/types/index.d.ts +13 -12
- package/dist/types/index.js +2 -1
- package/dist/types/notifications.d.ts +157 -0
- package/dist/types/notifications.js +1 -0
- package/dist/types/organizations.d.ts +3 -2
- package/dist/types/ports.d.ts +8 -1
- package/dist/types/ports.js +7 -1
- package/dist/types/ports.js.map +1 -0
- package/dist/types/schemas/assets.d.ts +5 -5
- package/dist/types/schemas/assets.js +4 -3
- package/dist/types/schemas/assets.js.map +1 -1
- package/dist/types/schemas/automations.d.ts +1 -10
- package/dist/types/schemas/automations.js +1 -3
- package/dist/types/schemas/automations.js.map +1 -1
- package/dist/types/schemas/content.d.ts +596 -11
- package/dist/types/schemas/content.js +225 -9
- package/dist/types/schemas/content.js.map +1 -1
- package/dist/types/schemas/discussion.d.ts +362 -66
- package/dist/types/schemas/discussion.js +123 -15
- package/dist/types/schemas/discussion.js.map +1 -1
- package/dist/types/schemas/entitlements.d.ts +14 -1
- package/dist/types/schemas/entitlements.js +11 -4
- package/dist/types/schemas/entitlements.js.map +1 -1
- package/dist/types/schemas/identity.d.ts +1 -85
- package/dist/types/schemas/identity.js +1 -42
- package/dist/types/schemas/identity.js.map +1 -1
- package/dist/types/schemas/index.d.ts +8 -7
- package/dist/types/schemas/index.js +8 -7
- package/dist/types/schemas/notifications.d.ts +96 -0
- package/dist/types/schemas/notifications.js +57 -0
- package/dist/types/schemas/notifications.js.map +1 -0
- package/dist/types/schemas/organizations.d.ts +96 -60
- package/dist/types/schemas/organizations.js +78 -27
- package/dist/types/schemas/organizations.js.map +1 -1
- package/dist/types/schemas/progress.d.ts +0 -1
- package/dist/types/schemas/progress.js +0 -1
- package/dist/types/schemas/progress.js.map +1 -1
- package/package.json +1 -1
- package/dist/automations/community-notifications.d.ts +0 -16
- package/dist/automations/community-notifications.js +0 -84
- package/dist/automations/community-notifications.js.map +0 -1
- package/dist/automations/seeds.d.ts +0 -17
- package/dist/automations/seeds.js +0 -235
- package/dist/automations/seeds.js.map +0 -1
- package/dist/identity/notifications.d.ts +0 -27
- package/dist/identity/notifications.js +0 -101
- package/dist/identity/notifications.js.map +0 -1
- package/dist/organizations/access-scopes.d.ts +0 -19
- package/dist/organizations/access-scopes.js +0 -89
- package/dist/organizations/access-scopes.js.map +0 -1
- package/dist/organizations/roles.d.ts +0 -19
- package/dist/organizations/roles.js +0 -82
- package/dist/organizations/roles.js.map +0 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { nameMentions } from "../../../discussion/mentions.js";
|
|
2
|
+
import { actorOf, excerpt } from "../../community-mail.js";
|
|
3
|
+
//#region src/automations/notifications/rules/recipients.ts
|
|
4
|
+
const MUTE_PROOF = [
|
|
5
|
+
"subject",
|
|
6
|
+
"moderator",
|
|
7
|
+
"mentioned"
|
|
8
|
+
];
|
|
9
|
+
var Reasons = class {
|
|
10
|
+
byPerson = /* @__PURE__ */ new Map();
|
|
11
|
+
add(orgUserIds, reason) {
|
|
12
|
+
for (const orgUserId of orgUserIds) {
|
|
13
|
+
if (!orgUserId) continue;
|
|
14
|
+
const reasons = this.byPerson.get(orgUserId) ?? [];
|
|
15
|
+
if (!reasons.includes(reason)) reasons.push(reason);
|
|
16
|
+
this.byPerson.set(orgUserId, reasons);
|
|
17
|
+
}
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
ids() {
|
|
21
|
+
return [...this.byPerson.keys()];
|
|
22
|
+
}
|
|
23
|
+
entries() {
|
|
24
|
+
return [...this.byPerson.entries()];
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
async function recipientsOf(reads, orgId, reasons, reach) {
|
|
28
|
+
const excluded = new Set(reach.exclude.filter((id) => Boolean(id)));
|
|
29
|
+
let people = new Map(reasons.entries().filter(([orgUserId]) => !excluded.has(orgUserId)));
|
|
30
|
+
if (people.size > 0 && reach.canOpen) {
|
|
31
|
+
const open = new Set(await reach.canOpen([...people.keys()]));
|
|
32
|
+
people = new Map([...people].filter(([orgUserId]) => open.has(orgUserId)));
|
|
33
|
+
}
|
|
34
|
+
for (const item of reach.mutedOn ?? []) {
|
|
35
|
+
const exposed = [...people].filter(([, held]) => held.some((reason) => !MUTE_PROOF.includes(reason))).map(([orgUserId]) => orgUserId);
|
|
36
|
+
if (exposed.length === 0) break;
|
|
37
|
+
for (const orgUserId of await reads.mutedAmong(orgId, item, exposed, reach.at)) {
|
|
38
|
+
const kept = (people.get(orgUserId) ?? []).filter((reason) => MUTE_PROOF.includes(reason));
|
|
39
|
+
if (kept.length > 0) people.set(orgUserId, kept);
|
|
40
|
+
else people.delete(orgUserId);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (people.size === 0) return [];
|
|
44
|
+
const userIds = await reads.userIdsOf(orgId, [...people.keys()]);
|
|
45
|
+
return [...people].flatMap(([orgUserId, held]) => {
|
|
46
|
+
const userId = userIds[orgUserId];
|
|
47
|
+
return userId ? [{
|
|
48
|
+
orgUserId,
|
|
49
|
+
userId,
|
|
50
|
+
reasons: held
|
|
51
|
+
}] : [];
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function listOf(base, recipients) {
|
|
55
|
+
return recipients.length > 0 ? [{
|
|
56
|
+
...base,
|
|
57
|
+
recipients
|
|
58
|
+
}] : [];
|
|
59
|
+
}
|
|
60
|
+
function eventAt(event) {
|
|
61
|
+
return new Date(event.occurredAt);
|
|
62
|
+
}
|
|
63
|
+
function actorOr(event, fallback) {
|
|
64
|
+
return actorOf(event) ?? fallback;
|
|
65
|
+
}
|
|
66
|
+
async function textExcerpt(reads, orgId, text, max) {
|
|
67
|
+
return excerpt(await nameMentions(text, (orgUserId) => reads.displayName(orgId, orgUserId)), max);
|
|
68
|
+
}
|
|
69
|
+
async function participantNames(reads, orgId, chat) {
|
|
70
|
+
const names = [];
|
|
71
|
+
for (const participant of chat.participants) if (!participant.leftAt) names.push(await reads.displayName(orgId, participant.orgUserId));
|
|
72
|
+
return names;
|
|
73
|
+
}
|
|
74
|
+
async function chatTitle(reads, orgId, chat, senderOrgUserId) {
|
|
75
|
+
if (chat.kind === "direct") return reads.displayName(orgId, senderOrgUserId);
|
|
76
|
+
const names = await participantNames(reads, orgId, chat);
|
|
77
|
+
return names.length > 0 ? names.join(", ") : "Group chat";
|
|
78
|
+
}
|
|
79
|
+
function chatReach(reads, orgId, chat, chatId, actor, at) {
|
|
80
|
+
return {
|
|
81
|
+
exclude: [actor],
|
|
82
|
+
at,
|
|
83
|
+
mutedOn: [{
|
|
84
|
+
type: "chat",
|
|
85
|
+
id: chatId
|
|
86
|
+
}],
|
|
87
|
+
canOpen: async (orgUserIds) => {
|
|
88
|
+
const present = new Set(chat.participants.filter((participant) => participant.leftAt === null).map((participant) => participant.orgUserId));
|
|
89
|
+
const unblocked = [];
|
|
90
|
+
for (const orgUserId of orgUserIds) if (present.has(orgUserId) && !await reads.pairBlocked(orgId, chat.communityId, actor, orgUserId)) unblocked.push(orgUserId);
|
|
91
|
+
return unblocked.length > 0 ? reads.communityMembersAmong(orgId, chat.communityId, unblocked) : [];
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
export { Reasons, actorOr, chatReach, chatTitle, eventAt, listOf, participantNames, recipientsOf, textExcerpt };
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=recipients.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recipients.js","names":[],"sources":["../../../../src/automations/notifications/rules/recipients.ts"],"sourcesContent":["import { nameMentions } from '../../../discussion/index.js';\nimport type { DomainEvent } from '../../../shared/ports.js';\nimport type { Reason, RecipientList, SubjectRef } from '../../../types/index.js';\nimport { actorOf, excerpt } from '../../community-mail.js';\nimport type { NotificationReads } from '../../ports.js';\n\nexport type Recipient = NonNullable<RecipientList['recipients']>[number];\nexport type ListBase = Omit<RecipientList, 'recipients' | 'audience'>;\nexport type Chat = NonNullable<Awaited<ReturnType<NotificationReads['chat']>>>;\n\nconst MUTE_PROOF: Reason[] = ['subject', 'moderator', 'mentioned'];\n\nexport class Reasons {\n private readonly byPerson = new Map<string, Reason[]>();\n\n add(orgUserIds: (string | null | undefined)[], reason: Reason): this {\n for (const orgUserId of orgUserIds) {\n if (!orgUserId) {\n continue;\n }\n const reasons = this.byPerson.get(orgUserId) ?? [];\n if (!reasons.includes(reason)) {\n reasons.push(reason);\n }\n this.byPerson.set(orgUserId, reasons);\n }\n return this;\n }\n\n ids(): string[] {\n return [...this.byPerson.keys()];\n }\n\n entries(): [string, Reason[]][] {\n return [...this.byPerson.entries()];\n }\n}\n\nexport interface Reach {\n exclude: (string | null | undefined)[];\n canOpen?: (orgUserIds: string[]) => Promise<string[]>;\n mutedOn?: SubjectRef[];\n at: Date;\n}\n\nexport async function recipientsOf(\n reads: NotificationReads,\n orgId: string,\n reasons: Reasons,\n reach: Reach,\n): Promise<Recipient[]> {\n const excluded = new Set(reach.exclude.filter((id): id is string => Boolean(id)));\n let people = new Map(reasons.entries().filter(([orgUserId]) => !excluded.has(orgUserId)));\n if (people.size > 0 && reach.canOpen) {\n const open = new Set(await reach.canOpen([...people.keys()]));\n people = new Map([...people].filter(([orgUserId]) => open.has(orgUserId)));\n }\n for (const item of reach.mutedOn ?? []) {\n const exposed = [...people]\n .filter(([, held]) => held.some((reason) => !MUTE_PROOF.includes(reason)))\n .map(([orgUserId]) => orgUserId);\n if (exposed.length === 0) {\n break;\n }\n for (const orgUserId of await reads.mutedAmong(orgId, item, exposed, reach.at)) {\n const kept = (people.get(orgUserId) ?? []).filter((reason) => MUTE_PROOF.includes(reason));\n if (kept.length > 0) {\n people.set(orgUserId, kept);\n } else {\n people.delete(orgUserId);\n }\n }\n }\n if (people.size === 0) {\n return [];\n }\n const userIds = await reads.userIdsOf(orgId, [...people.keys()]);\n return [...people].flatMap(([orgUserId, held]) => {\n const userId = userIds[orgUserId];\n return userId ? [{ orgUserId, userId, reasons: held }] : [];\n });\n}\n\nexport function listOf(base: ListBase, recipients: Recipient[]): RecipientList[] {\n return recipients.length > 0 ? [{ ...base, recipients }] : [];\n}\n\nexport function eventAt(event: DomainEvent): Date {\n return new Date(event.occurredAt);\n}\n\nexport function actorOr(event: DomainEvent, fallback: string | null): string | null {\n return actorOf(event) ?? fallback;\n}\n\nexport async function textExcerpt(\n reads: NotificationReads,\n orgId: string,\n text: string,\n max: number,\n): Promise<string> {\n return excerpt(await nameMentions(text, (orgUserId) => reads.displayName(orgId, orgUserId)), max);\n}\n\nexport async function participantNames(\n reads: NotificationReads,\n orgId: string,\n chat: Chat,\n): Promise<string[]> {\n const names: string[] = [];\n for (const participant of chat.participants) {\n if (!participant.leftAt) {\n names.push(await reads.displayName(orgId, participant.orgUserId));\n }\n }\n return names;\n}\n\nexport async function chatTitle(\n reads: NotificationReads,\n orgId: string,\n chat: Chat,\n senderOrgUserId: string,\n): Promise<string> {\n if (chat.kind === 'direct') {\n return reads.displayName(orgId, senderOrgUserId);\n }\n const names = await participantNames(reads, orgId, chat);\n return names.length > 0 ? names.join(', ') : 'Group chat';\n}\n\nexport function chatReach(\n reads: NotificationReads,\n orgId: string,\n chat: Chat,\n chatId: string,\n actor: string,\n at: Date,\n): Reach {\n return {\n exclude: [actor],\n at,\n mutedOn: [{ type: 'chat', id: chatId }],\n canOpen: async (orgUserIds) => {\n const present = new Set(\n chat.participants\n .filter((participant) => participant.leftAt === null)\n .map((participant) => participant.orgUserId),\n );\n const unblocked: string[] = [];\n for (const orgUserId of orgUserIds) {\n if (\n present.has(orgUserId) &&\n !(await reads.pairBlocked(orgId, chat.communityId, actor, orgUserId))\n ) {\n unblocked.push(orgUserId);\n }\n }\n return unblocked.length > 0\n ? reads.communityMembersAmong(orgId, chat.communityId, unblocked)\n : [];\n },\n };\n}\n"],"mappings":";;;AAUA,MAAM,aAAuB;CAAC;CAAW;CAAa;AAAW;AAEjE,IAAa,UAAb,MAAqB;CACnB,2BAA4B,IAAI,IAAsB;CAEtD,IAAI,YAA2C,QAAsB;EACnE,KAAK,MAAM,aAAa,YAAY;GAClC,IAAI,CAAC,WACH;GAEF,MAAM,UAAU,KAAK,SAAS,IAAI,SAAS,KAAK,CAAC;GACjD,IAAI,CAAC,QAAQ,SAAS,MAAM,GAC1B,QAAQ,KAAK,MAAM;GAErB,KAAK,SAAS,IAAI,WAAW,OAAO;EACtC;EACA,OAAO;CACT;CAEA,MAAgB;EACd,OAAO,CAAC,GAAG,KAAK,SAAS,KAAK,CAAC;CACjC;CAEA,UAAgC;EAC9B,OAAO,CAAC,GAAG,KAAK,SAAS,QAAQ,CAAC;CACpC;AACF;AASA,eAAsB,aACpB,OACA,OACA,SACA,OACsB;CACtB,MAAM,WAAW,IAAI,IAAI,M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K,SAAS;GAG5B,OAAO,UAAU,SAAS,IACtB,MAAM,sBAAsB,OAAO,KAAK,aAAa,SAAS,IAC9D,CAAC;EACP;CACF;AACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Logger } from "../../types/ports.js";
|
|
2
|
+
import { NotificationFilter } from "../../types/notifications.js";
|
|
3
|
+
import "../../types/index.js";
|
|
4
|
+
import "../../shared/ports.js";
|
|
5
|
+
import { MemberActor } from "../../identity/ports.js";
|
|
6
|
+
import "../../identity/index.js";
|
|
7
|
+
import { ListedNotification, NotificationPage, NotificationsRepository, NotificationsService, UnreadCounts } from "../ports.js";
|
|
8
|
+
//#region src/automations/notifications/service.d.ts
|
|
9
|
+
declare class NotificationsServiceImpl implements NotificationsService {
|
|
10
|
+
private readonly repo;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
constructor(params: {
|
|
13
|
+
repo: NotificationsRepository;
|
|
14
|
+
logger?: Logger;
|
|
15
|
+
});
|
|
16
|
+
list(filter: NotificationFilter, page: {
|
|
17
|
+
page: number;
|
|
18
|
+
pageSize: number;
|
|
19
|
+
}, actor: MemberActor): Promise<NotificationPage>;
|
|
20
|
+
get(notificationId: string, actor: MemberActor): Promise<ListedNotification | null>;
|
|
21
|
+
unreadCounts(communityIds: string[], actor: MemberActor): Promise<UnreadCounts>;
|
|
22
|
+
markRead(notificationId: string, actor: MemberActor): Promise<void>;
|
|
23
|
+
markAllRead(filter: NotificationFilter, actor: MemberActor): Promise<{
|
|
24
|
+
marked: number;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { NotificationsServiceImpl };
|
|
29
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { noopLogger } from "../../shared/logger.js";
|
|
2
|
+
import { NotFoundError } from "../../shared/errors.js";
|
|
3
|
+
//#region src/automations/notifications/service.ts
|
|
4
|
+
var NotificationsServiceImpl = class {
|
|
5
|
+
repo;
|
|
6
|
+
logger;
|
|
7
|
+
constructor(params) {
|
|
8
|
+
this.repo = params.repo;
|
|
9
|
+
this.logger = params.logger ?? noopLogger;
|
|
10
|
+
}
|
|
11
|
+
list(filter, page, actor) {
|
|
12
|
+
return this.repo.page(actor.orgId, actor.userId, filter, page);
|
|
13
|
+
}
|
|
14
|
+
get(notificationId, actor) {
|
|
15
|
+
return this.repo.find(actor.orgId, actor.userId, notificationId);
|
|
16
|
+
}
|
|
17
|
+
async unreadCounts(communityIds, actor) {
|
|
18
|
+
const ids = [...new Set(communityIds)];
|
|
19
|
+
const counts = await this.repo.unreadCounts(actor.orgId, actor.userId, ids);
|
|
20
|
+
const byCommunity = new Map(counts.communities.map((row) => [row.communityId, row.unread]));
|
|
21
|
+
return {
|
|
22
|
+
org: counts.org,
|
|
23
|
+
communities: ids.map((communityId) => ({
|
|
24
|
+
communityId,
|
|
25
|
+
unread: byCommunity.get(communityId) ?? 0
|
|
26
|
+
}))
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async markRead(notificationId, actor) {
|
|
30
|
+
if (!await this.repo.markRead(actor.orgId, actor.userId, notificationId, /* @__PURE__ */ new Date())) throw new NotFoundError("Notification", notificationId);
|
|
31
|
+
}
|
|
32
|
+
async markAllRead(filter, actor) {
|
|
33
|
+
const marked = await this.repo.markAllRead(actor.orgId, actor.userId, filter, /* @__PURE__ */ new Date());
|
|
34
|
+
this.logger.debug("notifications marked read", {
|
|
35
|
+
orgId: actor.orgId,
|
|
36
|
+
userId: actor.userId,
|
|
37
|
+
marked
|
|
38
|
+
});
|
|
39
|
+
return { marked };
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
export { NotificationsServiceImpl };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","names":[],"sources":["../../../src/automations/notifications/service.ts"],"sourcesContent":["import { NotFoundError } from '../../shared/errors.js';\nimport { noopLogger } from '../../shared/logger.js';\nimport type { Logger } from '../../shared/ports.js';\nimport type { NotificationFilter } from '../../types/index.js';\nimport type { MemberActor } from '../../identity/index.js';\nimport type {\n ListedNotification,\n NotificationPage,\n NotificationsRepository,\n NotificationsService,\n UnreadCounts,\n} from '../ports.js';\n\nexport class NotificationsServiceImpl implements NotificationsService {\n private readonly repo: NotificationsRepository;\n private readonly logger: Logger;\n\n constructor(params: { repo: NotificationsRepository; logger?: Logger }) {\n this.repo = params.repo;\n this.logger = params.logger ?? noopLogger;\n }\n\n list(\n filter: NotificationFilter,\n page: { page: number; pageSize: number },\n actor: MemberActor,\n ): Promise<NotificationPage> {\n return this.repo.page(actor.orgId, actor.userId, filter, page);\n }\n\n get(notificationId: string, actor: MemberActor): Promise<ListedNotification | null> {\n return this.repo.find(actor.orgId, actor.userId, notificationId);\n }\n\n async unreadCounts(communityIds: string[], actor: MemberActor): Promise<UnreadCounts> {\n const ids = [...new Set(communityIds)];\n const counts = await this.repo.unreadCounts(actor.orgId, actor.userId, ids);\n const byCommunity = new Map(counts.communities.map((row) => [row.communityId, row.unread]));\n return {\n org: counts.org,\n communities: ids.map((communityId) => ({\n communityId,\n unread: byCommunity.get(communityId) ?? 0,\n })),\n };\n }\n\n async markRead(notificationId: string, actor: MemberActor): Promise<void> {\n if (!(await this.repo.markRead(actor.orgId, actor.userId, notificationId, new Date()))) {\n throw new NotFoundError('Notification', notificationId);\n }\n }\n\n async markAllRead(filter: NotificationFilter, actor: MemberActor): Promise<{ marked: number }> {\n const marked = await this.repo.markAllRead(actor.orgId, actor.userId, filter, new Date());\n this.logger.debug('notifications marked read', {\n orgId: actor.orgId,\n userId: actor.userId,\n marked,\n });\n return { marked };\n }\n}\n"],"mappings":";;;AAaA,IAAa,2BAAb,MAAsE;CACpE;CACA;CAEA,YAAY,QAA4D;EACtE,KAAK,OAAO,OAAO;EACnB,KAAK,SAAS,OAAO,UAAU;CACjC;CAEA,KACE,QACA,MACA,OAC2B;EAC3B,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,MAAM,QAAQ,QAAQ,IAAI;CAC/D;CAEA,IAAI,gBAAwB,OAAwD;EAClF,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,MAAM,QAAQ,cAAc;CACjE;CAEA,MAAM,aAAa,cAAwB,OAA2C;EACpF,MAAM,MAAM,CAAC,GAAG,IAAI,IAAI,YAAY,CAAC;EACrC,MAAM,SAAS,MAAM,KAAK,KAAK,aAAa,MAAM,OAAO,MAAM,QAAQ,GAAG;EAC1E,MAAM,cAAc,IAAI,IAAI,OAAO,YAAY,KAAK,QAAQ,CAAC,IAAI,aAAa,IAAI,MAAM,CAAC,CAAC;EAC1F,OAAO;GACL,KAAK,OAAO;GACZ,aAAa,IAAI,KAAK,iBAAiB;IACrC;IACA,QAAQ,YAAY,IAAI,WAAW,KAAK;GAC1C,EAAE;EACJ;CACF;CAEA,MAAM,SAAS,gBAAwB,OAAmC;EACxE,IAAI,CAAE,MAAM,KAAK,KAAK,SAAS,MAAM,OAAO,MAAM,QAAQ,gCAAgB,IAAI,KAAK,CAAC,GAClF,MAAM,IAAI,cAAc,gBAAgB,cAAc;CAE1D;CAEA,MAAM,YAAY,QAA4B,OAAiD;EAC7F,MAAM,SAAS,MAAM,KAAK,KAAK,YAAY,MAAM,OAAO,MAAM,QAAQ,wBAAQ,IAAI,KAAK,CAAC;EACxF,KAAK,OAAO,MAAM,6BAA6B;GAC7C,OAAO,MAAM;GACb,QAAQ,MAAM;GACd;EACF,CAAC;EACD,OAAO,EAAE,OAAO;CAClB;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NotificationTypeDeclaration } from "../../types/notifications.js";
|
|
2
|
+
import "../../types/index.js";
|
|
3
|
+
//#region src/automations/notifications/types.d.ts
|
|
4
|
+
declare const NOTIFICATION_TYPES: NotificationTypeDeclaration[];
|
|
5
|
+
//#endregion
|
|
6
|
+
export { NOTIFICATION_TYPES };
|
|
7
|
+
//# sourceMappingURL=types.d.ts.map
|