@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.
Files changed (307) hide show
  1. package/dist/assets/events.d.ts +24 -18
  2. package/dist/assets/file-urls.d.ts +11 -7
  3. package/dist/assets/file-urls.js +14 -4
  4. package/dist/assets/file-urls.js.map +1 -1
  5. package/dist/assets/index.d.ts +5 -4
  6. package/dist/assets/index.js +4 -3
  7. package/dist/assets/jobs.d.ts +15 -0
  8. package/dist/assets/jobs.js +30 -0
  9. package/dist/assets/jobs.js.map +1 -0
  10. package/dist/assets/ports.d.ts +37 -17
  11. package/dist/assets/service.d.ts +30 -15
  12. package/dist/assets/service.js +229 -59
  13. package/dist/assets/service.js.map +1 -1
  14. package/dist/automations/actions.js +2 -63
  15. package/dist/automations/actions.js.map +1 -1
  16. package/dist/automations/catalog.d.ts +1 -2
  17. package/dist/automations/catalog.js +137 -65
  18. package/dist/automations/catalog.js.map +1 -1
  19. package/dist/automations/community-derivations.js +20 -20
  20. package/dist/automations/community-derivations.js.map +1 -1
  21. package/dist/automations/community-mail.d.ts +36 -20
  22. package/dist/automations/community-mail.js +32 -24
  23. package/dist/automations/community-mail.js.map +1 -1
  24. package/dist/automations/event-permissions.d.ts +12 -0
  25. package/dist/automations/event-permissions.js +38 -0
  26. package/dist/automations/event-permissions.js.map +1 -0
  27. package/dist/automations/events.d.ts +0 -10
  28. package/dist/automations/index.d.ts +12 -4
  29. package/dist/automations/index.js +9 -1
  30. package/dist/automations/notifications/applicable.d.ts +8 -0
  31. package/dist/automations/notifications/applicable.js +12 -0
  32. package/dist/automations/notifications/applicable.js.map +1 -0
  33. package/dist/automations/notifications/debounce.d.ts +25 -0
  34. package/dist/automations/notifications/debounce.js +93 -0
  35. package/dist/automations/notifications/debounce.js.map +1 -0
  36. package/dist/automations/notifications/defaults.d.ts +8 -0
  37. package/dist/automations/notifications/defaults.js +346 -0
  38. package/dist/automations/notifications/defaults.js.map +1 -0
  39. package/dist/automations/notifications/delivery.d.ts +28 -0
  40. package/dist/automations/notifications/delivery.js +88 -0
  41. package/dist/automations/notifications/delivery.js.map +1 -0
  42. package/dist/automations/notifications/processor.d.ts +64 -0
  43. package/dist/automations/notifications/processor.js +270 -0
  44. package/dist/automations/notifications/processor.js.map +1 -0
  45. package/dist/automations/notifications/rules/content.d.ts +6 -0
  46. package/dist/automations/notifications/rules/content.js +96 -0
  47. package/dist/automations/notifications/rules/content.js.map +1 -0
  48. package/dist/automations/notifications/rules/discussion.d.ts +7 -0
  49. package/dist/automations/notifications/rules/discussion.js +678 -0
  50. package/dist/automations/notifications/rules/discussion.js.map +1 -0
  51. package/dist/automations/notifications/rules/entitlements.d.ts +6 -0
  52. package/dist/automations/notifications/rules/entitlements.js +276 -0
  53. package/dist/automations/notifications/rules/entitlements.js.map +1 -0
  54. package/dist/automations/notifications/rules/events.d.ts +9 -0
  55. package/dist/automations/notifications/rules/events.js +27 -0
  56. package/dist/automations/notifications/rules/events.js.map +1 -0
  57. package/dist/automations/notifications/rules/index.d.ts +6 -0
  58. package/dist/automations/notifications/rules/index.js +15 -0
  59. package/dist/automations/notifications/rules/index.js.map +1 -0
  60. package/dist/automations/notifications/rules/organizations.d.ts +6 -0
  61. package/dist/automations/notifications/rules/organizations.js +35 -0
  62. package/dist/automations/notifications/rules/organizations.js.map +1 -0
  63. package/dist/automations/notifications/rules/recipients.d.ts +32 -0
  64. package/dist/automations/notifications/rules/recipients.js +98 -0
  65. package/dist/automations/notifications/rules/recipients.js.map +1 -0
  66. package/dist/automations/notifications/service.d.ts +29 -0
  67. package/dist/automations/notifications/service.js +45 -0
  68. package/dist/automations/notifications/service.js.map +1 -0
  69. package/dist/automations/notifications/types.d.ts +7 -0
  70. package/dist/automations/notifications/types.js +560 -0
  71. package/dist/automations/notifications/types.js.map +1 -0
  72. package/dist/automations/ports.d.ts +134 -21
  73. package/dist/automations/service.d.ts +30 -30
  74. package/dist/automations/service.js +111 -144
  75. package/dist/automations/service.js.map +1 -1
  76. package/dist/content/event-sight.d.ts +11 -0
  77. package/dist/content/event-sight.js +11 -0
  78. package/dist/content/event-sight.js.map +1 -0
  79. package/dist/content/events.d.ts +437 -46
  80. package/dist/content/events.js +45 -1
  81. package/dist/content/events.js.map +1 -1
  82. package/dist/content/index.d.ts +8 -4
  83. package/dist/content/index.js +5 -1
  84. package/dist/content/jobs.d.ts +16 -0
  85. package/dist/content/jobs.js +37 -0
  86. package/dist/content/jobs.js.map +1 -0
  87. package/dist/content/model.d.ts +2 -2
  88. package/dist/content/notification-categories.d.ts +37 -0
  89. package/dist/content/notification-categories.js +73 -0
  90. package/dist/content/notification-categories.js.map +1 -0
  91. package/dist/content/ports.d.ts +132 -68
  92. package/dist/content/service.d.ts +100 -68
  93. package/dist/content/service.js +703 -146
  94. package/dist/content/service.js.map +1 -1
  95. package/dist/content/titles.d.ts +25 -0
  96. package/dist/content/titles.js +82 -0
  97. package/dist/content/titles.js.map +1 -0
  98. package/dist/content/types.d.ts +2 -2
  99. package/dist/discussion/authors.d.ts +4 -2
  100. package/dist/discussion/authors.js +9 -5
  101. package/dist/discussion/authors.js.map +1 -1
  102. package/dist/discussion/chats.d.ts +63 -39
  103. package/dist/discussion/chats.js +455 -190
  104. package/dist/discussion/chats.js.map +1 -1
  105. package/dist/discussion/digests.d.ts +24 -0
  106. package/dist/discussion/digests.js +104 -0
  107. package/dist/discussion/digests.js.map +1 -0
  108. package/dist/discussion/events.d.ts +227 -23
  109. package/dist/discussion/events.js +114 -19
  110. package/dist/discussion/events.js.map +1 -1
  111. package/dist/discussion/index.d.ts +12 -4
  112. package/dist/discussion/index.js +9 -2
  113. package/dist/discussion/jobs.d.ts +16 -0
  114. package/dist/discussion/jobs.js +40 -0
  115. package/dist/discussion/jobs.js.map +1 -0
  116. package/dist/discussion/live.d.ts +106 -0
  117. package/dist/discussion/live.js +642 -0
  118. package/dist/discussion/live.js.map +1 -0
  119. package/dist/discussion/mentions.d.ts +11 -0
  120. package/dist/discussion/mentions.js +35 -0
  121. package/dist/discussion/mentions.js.map +1 -0
  122. package/dist/discussion/ports.d.ts +279 -114
  123. package/dist/discussion/ports.js.map +1 -1
  124. package/dist/discussion/posts.d.ts +60 -44
  125. package/dist/discussion/posts.js +453 -287
  126. package/dist/discussion/posts.js.map +1 -1
  127. package/dist/discussion/rules.d.ts +18 -0
  128. package/dist/discussion/rules.js +22 -0
  129. package/dist/discussion/rules.js.map +1 -0
  130. package/dist/discussion/service.d.ts +50 -35
  131. package/dist/discussion/service.js +333 -205
  132. package/dist/discussion/service.js.map +1 -1
  133. package/dist/discussion/subscriptions.d.ts +37 -0
  134. package/dist/discussion/subscriptions.js +115 -0
  135. package/dist/discussion/subscriptions.js.map +1 -0
  136. package/dist/discussion/titles.d.ts +28 -0
  137. package/dist/discussion/titles.js +98 -0
  138. package/dist/discussion/titles.js.map +1 -0
  139. package/dist/entitlements/events.d.ts +20 -20
  140. package/dist/entitlements/index.d.ts +5 -4
  141. package/dist/entitlements/index.js +3 -2
  142. package/dist/entitlements/jobs.d.ts +12 -0
  143. package/dist/entitlements/jobs.js +18 -0
  144. package/dist/entitlements/jobs.js.map +1 -0
  145. package/dist/entitlements/model.d.ts +2 -2
  146. package/dist/entitlements/ports.d.ts +68 -38
  147. package/dist/entitlements/rules.d.ts +3 -6
  148. package/dist/entitlements/rules.js +5 -10
  149. package/dist/entitlements/rules.js.map +1 -1
  150. package/dist/entitlements/service.d.ts +43 -28
  151. package/dist/entitlements/service.js +387 -160
  152. package/dist/entitlements/service.js.map +1 -1
  153. package/dist/identity/devices.d.ts +30 -0
  154. package/dist/identity/devices.js +109 -0
  155. package/dist/identity/devices.js.map +1 -0
  156. package/dist/identity/index.d.ts +6 -5
  157. package/dist/identity/index.js +4 -3
  158. package/dist/identity/model.d.ts +2 -2
  159. package/dist/identity/notification-settings.d.ts +28 -0
  160. package/dist/identity/notification-settings.js +114 -0
  161. package/dist/identity/notification-settings.js.map +1 -0
  162. package/dist/identity/ports.d.ts +80 -56
  163. package/dist/identity/service.d.ts +8 -7
  164. package/dist/identity/service.js +17 -13
  165. package/dist/identity/service.js.map +1 -1
  166. package/dist/integrations/ports.d.ts +9 -8
  167. package/dist/integrations/service.d.ts +9 -8
  168. package/dist/integrations/service.js +33 -16
  169. package/dist/integrations/service.js.map +1 -1
  170. package/dist/organizations/default-roles.d.ts +22 -0
  171. package/dist/organizations/default-roles.js +89 -0
  172. package/dist/organizations/default-roles.js.map +1 -0
  173. package/dist/organizations/effective-permissions.d.ts +45 -0
  174. package/dist/organizations/effective-permissions.js +113 -0
  175. package/dist/organizations/effective-permissions.js.map +1 -0
  176. package/dist/organizations/events.d.ts +320 -181
  177. package/dist/organizations/events.js +90 -18
  178. package/dist/organizations/events.js.map +1 -1
  179. package/dist/organizations/index.d.ts +15 -10
  180. package/dist/organizations/index.js +8 -3
  181. package/dist/organizations/members.d.ts +66 -8
  182. package/dist/organizations/members.js.map +1 -1
  183. package/dist/organizations/notification-catalog.d.ts +31 -0
  184. package/dist/organizations/notification-catalog.js +32 -0
  185. package/dist/organizations/notification-catalog.js.map +1 -0
  186. package/dist/organizations/notification-categories.d.ts +34 -0
  187. package/dist/organizations/notification-categories.js +66 -0
  188. package/dist/organizations/notification-categories.js.map +1 -0
  189. package/dist/organizations/org-roles.d.ts +33 -0
  190. package/dist/organizations/org-roles.js +49 -0
  191. package/dist/organizations/org-roles.js.map +1 -0
  192. package/dist/organizations/permissions.d.ts +311 -0
  193. package/dist/organizations/permissions.js +327 -0
  194. package/dist/organizations/permissions.js.map +1 -0
  195. package/dist/organizations/ports.d.ts +187 -65
  196. package/dist/organizations/service.d.ts +104 -35
  197. package/dist/organizations/service.js +1247 -323
  198. package/dist/organizations/service.js.map +1 -1
  199. package/dist/organizations/testing.d.ts +18 -0
  200. package/dist/organizations/testing.js +37 -0
  201. package/dist/organizations/testing.js.map +1 -0
  202. package/dist/organizations/types.d.ts +5 -16
  203. package/dist/progress/index.d.ts +2 -2
  204. package/dist/progress/ports.d.ts +11 -3
  205. package/dist/progress/service.d.ts +6 -5
  206. package/dist/progress/service.js +23 -8
  207. package/dist/progress/service.js.map +1 -1
  208. package/dist/reporting/admin/index.d.ts +6 -4
  209. package/dist/reporting/admin/model.d.ts +36 -3
  210. package/dist/reporting/admin/ports.d.ts +39 -14
  211. package/dist/reporting/admin/service.d.ts +32 -11
  212. package/dist/reporting/admin/service.js +102 -18
  213. package/dist/reporting/admin/service.js.map +1 -1
  214. package/dist/reporting/events/index.d.ts +27 -0
  215. package/dist/reporting/events/index.js +20 -0
  216. package/dist/reporting/events/index.js.map +1 -0
  217. package/dist/reporting/member/calendar.d.ts +11 -0
  218. package/dist/reporting/member/calendar.js +75 -0
  219. package/dist/reporting/member/calendar.js.map +1 -0
  220. package/dist/reporting/member/index.d.ts +3 -2
  221. package/dist/reporting/member/model.d.ts +80 -26
  222. package/dist/reporting/member/ports.d.ts +50 -28
  223. package/dist/reporting/member/service.d.ts +81 -35
  224. package/dist/reporting/member/service.js +438 -145
  225. package/dist/reporting/member/service.js.map +1 -1
  226. package/dist/shared/actor.d.ts +22 -3
  227. package/dist/shared/errors.d.ts +15 -2
  228. package/dist/shared/errors.js +21 -2
  229. package/dist/shared/errors.js.map +1 -1
  230. package/dist/shared/id.d.ts +7 -0
  231. package/dist/shared/id.js +8 -1
  232. package/dist/shared/id.js.map +1 -1
  233. package/dist/shared/logger.d.ts +2 -1
  234. package/dist/shared/logger.js +10 -1
  235. package/dist/shared/logger.js.map +1 -1
  236. package/dist/shared/mailer.d.ts +11 -1
  237. package/dist/shared/mailer.js +32 -5
  238. package/dist/shared/mailer.js.map +1 -1
  239. package/dist/shared/notification-categories.d.ts +16 -0
  240. package/dist/shared/notification-categories.js +94 -0
  241. package/dist/shared/notification-categories.js.map +1 -0
  242. package/dist/shared/notification-settings.d.ts +14 -0
  243. package/dist/shared/notification-settings.js +61 -0
  244. package/dist/shared/notification-settings.js.map +1 -0
  245. package/dist/shared/ports.d.ts +68 -2
  246. package/dist/shared/settings.d.ts +2 -1
  247. package/dist/shared/settings.js +1 -0
  248. package/dist/shared/settings.js.map +1 -1
  249. package/dist/types/automations.d.ts +8 -2
  250. package/dist/types/content.d.ts +2 -2
  251. package/dist/types/discussion.d.ts +4 -5
  252. package/dist/types/email-templates.d.ts +119 -6
  253. package/dist/types/entitlements.d.ts +2 -2
  254. package/dist/types/identity.d.ts +14 -17
  255. package/dist/types/index.d.ts +13 -12
  256. package/dist/types/index.js +2 -1
  257. package/dist/types/notifications.d.ts +157 -0
  258. package/dist/types/notifications.js +1 -0
  259. package/dist/types/organizations.d.ts +3 -2
  260. package/dist/types/ports.d.ts +8 -1
  261. package/dist/types/ports.js +7 -1
  262. package/dist/types/ports.js.map +1 -0
  263. package/dist/types/schemas/assets.d.ts +5 -5
  264. package/dist/types/schemas/assets.js +4 -3
  265. package/dist/types/schemas/assets.js.map +1 -1
  266. package/dist/types/schemas/automations.d.ts +1 -10
  267. package/dist/types/schemas/automations.js +1 -3
  268. package/dist/types/schemas/automations.js.map +1 -1
  269. package/dist/types/schemas/content.d.ts +596 -11
  270. package/dist/types/schemas/content.js +225 -9
  271. package/dist/types/schemas/content.js.map +1 -1
  272. package/dist/types/schemas/discussion.d.ts +362 -66
  273. package/dist/types/schemas/discussion.js +123 -15
  274. package/dist/types/schemas/discussion.js.map +1 -1
  275. package/dist/types/schemas/entitlements.d.ts +14 -1
  276. package/dist/types/schemas/entitlements.js +11 -4
  277. package/dist/types/schemas/entitlements.js.map +1 -1
  278. package/dist/types/schemas/identity.d.ts +1 -85
  279. package/dist/types/schemas/identity.js +1 -42
  280. package/dist/types/schemas/identity.js.map +1 -1
  281. package/dist/types/schemas/index.d.ts +8 -7
  282. package/dist/types/schemas/index.js +8 -7
  283. package/dist/types/schemas/notifications.d.ts +96 -0
  284. package/dist/types/schemas/notifications.js +57 -0
  285. package/dist/types/schemas/notifications.js.map +1 -0
  286. package/dist/types/schemas/organizations.d.ts +96 -60
  287. package/dist/types/schemas/organizations.js +78 -27
  288. package/dist/types/schemas/organizations.js.map +1 -1
  289. package/dist/types/schemas/progress.d.ts +0 -1
  290. package/dist/types/schemas/progress.js +0 -1
  291. package/dist/types/schemas/progress.js.map +1 -1
  292. package/package.json +1 -1
  293. package/dist/automations/community-notifications.d.ts +0 -16
  294. package/dist/automations/community-notifications.js +0 -84
  295. package/dist/automations/community-notifications.js.map +0 -1
  296. package/dist/automations/seeds.d.ts +0 -17
  297. package/dist/automations/seeds.js +0 -235
  298. package/dist/automations/seeds.js.map +0 -1
  299. package/dist/identity/notifications.d.ts +0 -27
  300. package/dist/identity/notifications.js +0 -101
  301. package/dist/identity/notifications.js.map +0 -1
  302. package/dist/organizations/access-scopes.d.ts +0 -19
  303. package/dist/organizations/access-scopes.js +0 -89
  304. package/dist/organizations/access-scopes.js.map +0 -1
  305. package/dist/organizations/roles.d.ts +0 -19
  306. package/dist/organizations/roles.js +0 -82
  307. package/dist/organizations/roles.js.map +0 -1
@@ -1,42 +1,155 @@
1
1
  import { DomainEvent, Page } from "../types/shared.js";
2
+ import { Event } from "../types/schemas/content.js";
2
3
  import { Automation, AutomationKind, AutomationRun, AutomationRunsQuery, AutomationsQuery, AvailableActions, AvailableTriggers, CreateAutomationInput, CreateWebhookInput, CreatedWebhook, UpdateAutomationInput, UpdateWebhookInput, Webhook, WebhookSecret } from "../types/schemas/automations.js";
3
- import { AutomationDispatch, AutomationEngine, AutomationExecutor, ScheduledAutomation, WebhookRequest, WebhookResponse, WebhookSender } from "../types/automations.js";
4
+ import { AutomationDispatch, AutomationEngine, AutomationExecutor, DeliveryDispatch, ScheduledAutomation, WebhookRequest, WebhookResponse, WebhookSender } from "../types/automations.js";
5
+ import { Delivery, NotificationCategory, NotificationFilter, RecipientList, StoredNotification, SubjectRef } from "../types/notifications.js";
4
6
  import "../types/index.js";
7
+ import { Actor } from "../shared/actor.js";
5
8
  import { CredentialStore, OutboxAppender, UnitOfWork } from "../shared/ports.js";
6
9
  import "./model.js";
10
+ import "../content/index.js";
7
11
  import "./types.js";
12
+ import { MemberActor } from "../identity/ports.js";
13
+ import "../identity/index.js";
14
+ import { CommunityMailReads } from "./community-mail.js";
8
15
  //#region src/automations/ports.d.ts
9
16
  type NewAutomation = CreateAutomationInput & {
10
17
  kind: AutomationKind;
11
- source?: 'system' | 'user';
12
18
  };
19
+ interface NotificationCategories {
20
+ listFor(orgId: string, communityId: string | null): Promise<NotificationCategory[]>;
21
+ }
22
+ interface NotificationReads extends Omit<CommunityMailReads, 'recentMessageRecipients'> {
23
+ threadParticipants(orgId: string, item: SubjectRef): Promise<string[]>;
24
+ mutedAmong(orgId: string, item: SubjectRef, orgUserIds: string[], at: Date): Promise<string[]>;
25
+ communityMembers(orgId: string, communityId: string): Promise<string[]>;
26
+ switchedOn(orgId: string, communityId: string, category: string, spaceId: string | null): Promise<string[]>;
27
+ courseMembers(orgId: string, courseId: string): Promise<string[]>;
28
+ event(orgId: string, eventId: string): Promise<Event | null>;
29
+ eventAttendees(orgId: string, eventId: string): Promise<string[]>;
30
+ contentLostBy(orgId: string, grant: {
31
+ orgUserId: string;
32
+ contentId: string | null;
33
+ bundleId: string | null;
34
+ }): Promise<string[]>;
35
+ activity(orgId: string, activityId: string): Promise<{
36
+ title: string;
37
+ moduleTitle: string;
38
+ courseId: string;
39
+ courseTitle: string;
40
+ } | null>;
41
+ userIdsOf(orgId: string, orgUserIds: string[]): Promise<Record<string, string>>;
42
+ emailOf(orgId: string, userId: string): Promise<string | null>;
43
+ message(orgId: string, messageId: string): Promise<{
44
+ orgUserId: string;
45
+ chatId: string;
46
+ body: string;
47
+ } | null>;
48
+ postsPublished(orgId: string, communityId: string, from: Date, to: Date): Promise<{
49
+ postId: string;
50
+ spaceId: string;
51
+ title: string;
52
+ authorName: string;
53
+ spaceName: string;
54
+ commentCount: number;
55
+ }[]>;
56
+ unreadInChat(orgId: string, chatId: string, orgUserId: string): Promise<{
57
+ count: number;
58
+ latest: {
59
+ messageId: string;
60
+ senderOrgUserId: string;
61
+ body: string;
62
+ } | null;
63
+ }>;
64
+ }
65
+ type RecipientRule = (event: DomainEvent, reads: NotificationReads) => Promise<RecipientList[]>;
66
+ interface ChatDebounce {
67
+ arm(orgId: string, list: RecipientList, occurredAt: Date): Promise<void>;
68
+ mentioned(orgId: string, userId: string, chatId: string): Promise<void>;
69
+ }
70
+ interface NewNotification extends Omit<StoredNotification, 'orgId'> {
71
+ sourceEventId: string | null;
72
+ inApp: boolean;
73
+ }
74
+ interface NewDelivery {
75
+ id: string;
76
+ notificationId: string;
77
+ channel: string;
78
+ }
79
+ type ListedNotification = StoredNotification & {
80
+ readAt: Date | null;
81
+ };
82
+ interface NotificationPage {
83
+ items: ListedNotification[];
84
+ total: number;
85
+ unreadCount: number;
86
+ }
87
+ interface UnreadCounts {
88
+ org: number;
89
+ communities: {
90
+ communityId: string;
91
+ unread: number;
92
+ }[];
93
+ }
94
+ interface NotificationsService {
95
+ list(filter: NotificationFilter, page: {
96
+ page: number;
97
+ pageSize: number;
98
+ }, actor: MemberActor): Promise<NotificationPage>;
99
+ get(notificationId: string, actor: MemberActor): Promise<ListedNotification | null>;
100
+ unreadCounts(communityIds: string[], actor: MemberActor): Promise<UnreadCounts>;
101
+ markRead(notificationId: string, actor: MemberActor): Promise<void>;
102
+ markAllRead(filter: NotificationFilter, actor: MemberActor): Promise<{
103
+ marked: number;
104
+ }>;
105
+ }
106
+ interface NotificationsRepository {
107
+ insert(orgId: string, rows: NewNotification[], deliveries: NewDelivery[]): Promise<void>;
108
+ pendingDeliveriesForEvent(orgId: string, sourceEventId: string): Promise<{
109
+ id: string;
110
+ }[]>;
111
+ findDelivery(orgId: string, deliveryId: string): Promise<{
112
+ delivery: Delivery;
113
+ notification: StoredNotification;
114
+ } | null>;
115
+ markSent(orgId: string, deliveryId: string, at: Date): Promise<void>;
116
+ recordError(orgId: string, deliveryId: string, error: string): Promise<void>;
117
+ markFailed(orgId: string, deliveryId: string, error: string): Promise<void>;
118
+ page(orgId: string, userId: string, filter: NotificationFilter, page: {
119
+ page: number;
120
+ pageSize: number;
121
+ }): Promise<NotificationPage>;
122
+ find(orgId: string, userId: string, notificationId: string): Promise<ListedNotification | null>;
123
+ unreadCounts(orgId: string, userId: string, communityIds: string[]): Promise<UnreadCounts>;
124
+ markRead(orgId: string, userId: string, notificationId: string, at: Date): Promise<boolean>;
125
+ markAllRead(orgId: string, userId: string, filter: NotificationFilter, at: Date): Promise<number>;
126
+ }
13
127
  /** A run row before persistence assigns its id and event_id. */
14
128
  type NewAutomationRun = Omit<AutomationRun, 'id' | 'eventId'>;
15
129
  interface AutomationsService {
16
- /** Matches `event` against enabled automations and dispatches a run per match; never throws. */
130
+ /** Dispatches a run per enabled automation the event matches, then runs the notification process; throws only when the notification process fails, so the outbox redelivers. */
17
131
  handle(event: DomainEvent): Promise<void>;
18
132
  /** Built-in action types plus every loaded integration's declared actions. */
19
- availableActions(): AvailableActions;
133
+ availableActions(actor: Actor): AvailableActions;
20
134
  /** The domain event types an automation may react to. */
21
- availableTriggers(): AvailableTriggers;
22
- list(orgId: string, query?: AutomationsQuery): Promise<Automation[]>;
23
- get(orgId: string, id: string): Promise<Automation | null>;
24
- create(orgId: string, input: CreateAutomationInput): Promise<Automation>;
25
- update(orgId: string, id: string, input: UpdateAutomationInput): Promise<Automation | null>;
26
- delete(orgId: string, id: string): Promise<boolean>;
27
- listRuns(orgId: string, automationId: string, query: AutomationRunsQuery): Promise<Page<AutomationRun>>;
28
- rerun(orgId: string, automationId: string, runId: string): Promise<AutomationRun>;
29
- listWebhooks(orgId: string): Promise<Webhook[]>;
30
- getWebhook(orgId: string, id: string): Promise<Webhook | null>;
31
- createWebhook(orgId: string, input: CreateWebhookInput): Promise<CreatedWebhook>;
32
- updateWebhook(orgId: string, id: string, input: UpdateWebhookInput): Promise<Webhook | null>;
33
- deleteWebhook(orgId: string, id: string): Promise<boolean>;
34
- revealWebhookSecret(orgId: string, id: string): Promise<WebhookSecret | null>;
35
- rotateWebhookSecret(orgId: string, id: string): Promise<WebhookSecret | null>;
135
+ availableTriggers(actor: Actor): AvailableTriggers;
136
+ list(query: AutomationsQuery | undefined, actor: Actor): Promise<Automation[]>;
137
+ get(id: string, actor: Actor): Promise<Automation>;
138
+ create(input: CreateAutomationInput, actor: Actor): Promise<Automation>;
139
+ update(id: string, input: UpdateAutomationInput, actor: Actor): Promise<Automation>;
140
+ delete(id: string, actor: Actor): Promise<void>;
141
+ listRuns(automationId: string, query: AutomationRunsQuery, actor: Actor): Promise<Page<AutomationRun>>;
142
+ rerun(automationId: string, runId: string, actor: Actor): Promise<AutomationRun>;
143
+ listWebhooks(actor: Actor): Promise<Webhook[]>;
144
+ getWebhook(id: string, actor: Actor): Promise<Webhook>;
145
+ createWebhook(input: CreateWebhookInput, actor: Actor): Promise<CreatedWebhook>;
146
+ updateWebhook(id: string, input: UpdateWebhookInput, actor: Actor): Promise<Webhook>;
147
+ deleteWebhook(id: string, actor: Actor): Promise<void>;
148
+ revealWebhookSecret(id: string, actor: Actor): Promise<WebhookSecret>;
149
+ rotateWebhookSecret(id: string, actor: Actor): Promise<WebhookSecret>;
36
150
  }
37
151
  interface AutomationsRepository {
38
152
  insert(orgId: string, input: NewAutomation): Promise<Automation>;
39
- insertSeed(orgId: string, input: NewAutomation): Promise<Automation | null>;
40
153
  update(orgId: string, id: string, patch: UpdateAutomationInput): Promise<Automation | null>;
41
154
  /** Returns the deleted row (the event snapshot), or null if it didn't exist. */
42
155
  delete(orgId: string, id: string): Promise<Automation | null>;
@@ -71,5 +184,5 @@ interface AutomationsTxScope {
71
184
  }
72
185
  type AutomationsUnitOfWork = UnitOfWork<AutomationsTxScope>;
73
186
  //#endregion
74
- export { type AutomationDispatch, type AutomationEngine, type AutomationExecutor, AutomationRunsRepository, AutomationsRepository, AutomationsService, AutomationsTxScope, AutomationsUnitOfWork, NewAutomation, NewAutomationRun, type WebhookRequest, type WebhookResponse, type WebhookSender };
187
+ export { type AutomationDispatch, type AutomationEngine, type AutomationExecutor, AutomationRunsRepository, AutomationsRepository, AutomationsService, AutomationsTxScope, AutomationsUnitOfWork, ChatDebounce, type DeliveryDispatch, ListedNotification, NewAutomation, NewAutomationRun, NewDelivery, NewNotification, NotificationCategories, NotificationPage, NotificationReads, NotificationsRepository, NotificationsService, RecipientRule, UnreadCounts, type WebhookRequest, type WebhookResponse, type WebhookSender };
75
188
  //# sourceMappingURL=ports.d.ts.map
@@ -1,16 +1,17 @@
1
1
  import { DomainEvent, Page } from "../types/shared.js";
2
2
  import { Logger } from "../types/ports.js";
3
3
  import { Automation, AutomationActionResult, AutomationRun, AutomationRunsQuery, AutomationsQuery, AvailableActions, AvailableTriggers, CreateAutomationInput, CreateWebhookInput, CreatedWebhook, UpdateAutomationInput, UpdateWebhookInput, Webhook, WebhookSecret } from "../types/schemas/automations.js";
4
- import { AutomationDispatch, AutomationEngine, AutomationExecutor, ScheduledAutomation, WebhookSender } from "../types/automations.js";
4
+ import { AutomationDispatch, AutomationEngine, AutomationExecutor, DeliveryDispatch, ScheduledAutomation, WebhookSender } from "../types/automations.js";
5
5
  import "../types/index.js";
6
+ import { Actor } from "../shared/actor.js";
6
7
  import { CredentialStore } from "../shared/ports.js";
7
8
  import "./model.js";
8
- import { NotificationDesk } from "../identity/ports.js";
9
9
  import { Mailer, MailerLookups } from "../shared/mailer.js";
10
- import "../identity/index.js";
11
10
  import "./types.js";
12
11
  import { AutomationRunsRepository, AutomationsRepository, AutomationsService, AutomationsUnitOfWork } from "./ports.js";
13
- import { CommunityMailReads, GrantWriter, ScheduledWork } from "./community-mail.js";
12
+ import { CommunityMailReads, GrantWriter } from "./community-mail.js";
13
+ import { NotificationDelivery } from "./notifications/delivery.js";
14
+ import { NotificationProcessor } from "./notifications/processor.js";
14
15
  import { IntegrationsService } from "../integrations/ports.js";
15
16
  import "../integrations/index.js";
16
17
  //#region src/automations/service.d.ts
@@ -24,12 +25,13 @@ type AutomationsServiceParams = {
24
25
  mailer: Pick<Mailer, 'send'>;
25
26
  lookups: MailerLookups;
26
27
  integrations: Pick<IntegrationsService, 'available'>;
28
+ systemActor: (orgId: string) => Actor;
27
29
  credentials: CredentialStore;
28
30
  webhooks: WebhookSender;
29
31
  mail: Omit<CommunityMailReads, 'recentMessageRecipients'>;
30
32
  grants: GrantWriter;
31
- desk: NotificationDesk;
32
- scheduledWork: ScheduledWork;
33
+ delivery: Pick<NotificationDelivery, 'run'>;
34
+ processor: Pick<NotificationProcessor, 'process'>;
33
35
  logger?: Logger;
34
36
  };
35
37
  declare class AutomationsServiceImpl implements AutomationsService, AutomationExecutor {
@@ -40,48 +42,46 @@ declare class AutomationsServiceImpl implements AutomationsService, AutomationEx
40
42
  private readonly mailer;
41
43
  private readonly lookups;
42
44
  private readonly integrations;
45
+ private readonly systemActor;
43
46
  private readonly credentials;
44
47
  private readonly webhooks;
45
48
  private readonly mail;
46
49
  private readonly grants;
47
- private readonly desk;
48
- private readonly scheduledWork;
50
+ private readonly delivery;
51
+ private readonly processor;
49
52
  private readonly logger;
50
53
  constructor(params: AutomationsServiceParams);
51
54
  handle(event: DomainEvent): Promise<void>;
52
- private seedsFor;
53
- private seedFor;
54
55
  private reconcileSchedules;
55
56
  private safeListByTrigger;
56
57
  private dispatchOne;
57
58
  private openRun;
58
59
  private dispatchFor;
59
- /** Best-effort: logs and never rethrows — `handle` must never throw. */
60
+ /** Best-effort: logs and never rethrows, so an org automation never fails `handle`. */
60
61
  private recordFailure;
61
62
  runAction(d: AutomationDispatch, index: number): Promise<AutomationActionResult>;
63
+ runDelivery(d: DeliveryDispatch, lastAttempt: boolean): Promise<void>;
62
64
  listSchedules(): Promise<ScheduledAutomation[]>;
63
65
  fireSchedule(orgId: string, automationId: string, at: Date): Promise<void>;
64
- private scheduleHasWork;
65
- private pendingWork;
66
66
  finalize(d: AutomationDispatch, results: AutomationActionResult[]): Promise<void>;
67
67
  private logOutcome;
68
- create(orgId: string, input: CreateAutomationInput): Promise<Automation>;
69
- update(orgId: string, id: string, input: UpdateAutomationInput): Promise<Automation | null>;
70
- delete(orgId: string, id: string): Promise<boolean>;
71
- list(orgId: string, query?: AutomationsQuery): Promise<Automation[]>;
72
- get(orgId: string, id: string): Promise<Automation | null>;
73
- listRuns(orgId: string, automationId: string, query: AutomationRunsQuery): Promise<Page<AutomationRun>>;
74
- rerun(orgId: string, automationId: string, runId: string): Promise<AutomationRun>;
75
- listWebhooks(orgId: string): Promise<Webhook[]>;
76
- getWebhook(orgId: string, id: string): Promise<Webhook | null>;
77
- createWebhook(orgId: string, input: CreateWebhookInput): Promise<CreatedWebhook>;
78
- updateWebhook(orgId: string, id: string, input: UpdateWebhookInput): Promise<Webhook | null>;
79
- deleteWebhook(orgId: string, id: string): Promise<boolean>;
80
- revealWebhookSecret(orgId: string, id: string): Promise<WebhookSecret | null>;
81
- rotateWebhookSecret(orgId: string, id: string): Promise<WebhookSecret | null>;
82
- private findWebhook;
83
- availableActions(): AvailableActions;
84
- availableTriggers(): AvailableTriggers;
68
+ create(input: CreateAutomationInput, actor: Actor): Promise<Automation>;
69
+ update(id: string, input: UpdateAutomationInput, actor: Actor): Promise<Automation>;
70
+ delete(id: string, actor: Actor): Promise<void>;
71
+ list(query: AutomationsQuery | undefined, actor: Actor): Promise<Automation[]>;
72
+ get(id: string, actor: Actor): Promise<Automation>;
73
+ listRuns(automationId: string, query: AutomationRunsQuery, actor: Actor): Promise<Page<AutomationRun>>;
74
+ rerun(automationId: string, runId: string, actor: Actor): Promise<AutomationRun>;
75
+ listWebhooks(actor: Actor): Promise<Webhook[]>;
76
+ getWebhook(id: string, actor: Actor): Promise<Webhook>;
77
+ createWebhook(input: CreateWebhookInput, actor: Actor): Promise<CreatedWebhook>;
78
+ updateWebhook(id: string, input: UpdateWebhookInput, actor: Actor): Promise<Webhook>;
79
+ deleteWebhook(id: string, actor: Actor): Promise<void>;
80
+ revealWebhookSecret(id: string, actor: Actor): Promise<WebhookSecret>;
81
+ rotateWebhookSecret(id: string, actor: Actor): Promise<WebhookSecret>;
82
+ private requireWebhook;
83
+ availableActions(actor: Actor): AvailableActions;
84
+ availableTriggers(actor: Actor): AvailableTriggers;
85
85
  }
86
86
  //#endregion
87
87
  export { AutomationsServiceImpl, AutomationsServiceParams };