@openpeepshq/core 0.1.33 → 0.1.35

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 (297) hide show
  1. package/dist/accessTokens/finders.js +5 -6
  2. package/dist/accessTokens/mutations.js +1 -1
  3. package/dist/accessTokens/tokens.js +8 -11
  4. package/dist/accounts/helpers.js +6 -2
  5. package/dist/accounts/mutations.js +36 -33
  6. package/dist/analytics/cache.js +3 -3
  7. package/dist/analytics/clicks.js +14 -22
  8. package/dist/analytics/compile.js +17 -12
  9. package/dist/analytics/dateRange.js +3 -5
  10. package/dist/analytics/jobs.js +3 -4
  11. package/dist/analytics/pdfReport.js +45 -61
  12. package/dist/analytics/privacy.js +1 -1
  13. package/dist/analytics/read.js +164 -140
  14. package/dist/analytics/report.d.ts +22 -1
  15. package/dist/analytics/report.js +2 -3
  16. package/dist/analytics/settings.js +3 -4
  17. package/dist/backups/index.js +82 -25
  18. package/dist/backups/metadata.d.ts +2 -3
  19. package/dist/backups/metadata.js +6 -2
  20. package/dist/config/db.js +2 -4
  21. package/dist/config/defaults/capabilities.js +13 -2
  22. package/dist/config/defaults/community.js +8 -3
  23. package/dist/config/defaults/core.d.ts +1 -1
  24. package/dist/config/defaults/core.js +16 -8
  25. package/dist/config/index.d.ts +22 -0
  26. package/dist/config/index.js +15 -11
  27. package/dist/db/explorer/query.js +9 -8
  28. package/dist/db/explorer/sql.js +8 -8
  29. package/dist/db/helpers.d.ts +1 -0
  30. package/dist/db/helpers.js +25 -7
  31. package/dist/db/index.d.ts +1 -1
  32. package/dist/db/index.js +1 -0
  33. package/dist/db/init.js +2 -3
  34. package/dist/db/migration/importCollections.d.ts +14 -9
  35. package/dist/db/migration/importCollections.js +121 -174
  36. package/dist/db/migration/shared.d.ts +2 -33
  37. package/dist/db/migration/shared.js +17 -87
  38. package/dist/db/pg/client.js +4 -7
  39. package/dist/db/pg/collections.d.ts +2 -2
  40. package/dist/db/pg/collections.js +2 -2
  41. package/dist/db/pg/filters/index.js +1 -1
  42. package/dist/db/pg/filters/posts.d.ts +12 -0
  43. package/dist/db/pg/filters/posts.js +30 -4
  44. package/dist/db/pg/filters/profiles.d.ts +1 -0
  45. package/dist/db/pg/filters/profiles.js +2 -1
  46. package/dist/db/pg/helpers.js +2 -14
  47. package/dist/db/pg/map/filters.js +40 -10
  48. package/dist/db/pg/map/helpers.js +5 -1
  49. package/dist/db/pg/map/index.js +46 -51
  50. package/dist/db/pg/map/mutations.js +65 -25
  51. package/dist/db/pg/map/registry.d.ts +5 -0
  52. package/dist/db/pg/map/registry.js +133 -56
  53. package/dist/db/pg/map/relations.js +76 -68
  54. package/dist/db/pg/map/search.js +15 -37
  55. package/dist/db/pg/mappers.js +13 -7
  56. package/dist/db/pg/migrate.d.ts +1 -2
  57. package/dist/db/pg/migrate.js +8 -9
  58. package/dist/db/pg/queries/activity.js +5 -5
  59. package/dist/db/pg/queries/derived.js +8 -12
  60. package/dist/db/pg/queries/sorts.d.ts +1 -0
  61. package/dist/db/pg/queries/sorts.js +4 -0
  62. package/dist/db/pg/schema/documents.d.ts +279 -41
  63. package/dist/db/pg/schema/documents.js +136 -22
  64. package/dist/db/pg/schema/edges.d.ts +116 -7
  65. package/dist/db/pg/schema/edges.js +9 -2
  66. package/dist/db/pg/schema/index.d.ts +362 -15
  67. package/dist/db/pg/schema/index.js +5 -1
  68. package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
  69. package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
  70. package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
  71. package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
  72. package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
  73. package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
  74. package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
  75. package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
  76. package/dist/db/pg/sql/meta/_journal.json +49 -0
  77. package/dist/db/replaceOrigin.js +1 -1
  78. package/dist/email/queueStats.js +8 -11
  79. package/dist/email/render.js +14 -3
  80. package/dist/email/send.js +19 -17
  81. package/dist/email/smtpTest.js +10 -6
  82. package/dist/errors/index.js +1 -1
  83. package/dist/events/index.d.ts +4 -0
  84. package/dist/events/index.js +1 -0
  85. package/dist/events/once.js +2 -4
  86. package/dist/federation/activities.d.ts +17 -0
  87. package/dist/federation/activities.js +25 -0
  88. package/dist/federation/identity.d.ts +16 -0
  89. package/dist/federation/identity.js +52 -0
  90. package/dist/federation/index.d.ts +4 -0
  91. package/dist/federation/index.js +3 -0
  92. package/dist/federation/profiles.d.ts +3 -0
  93. package/dist/federation/profiles.js +14 -0
  94. package/dist/groups/finders.d.ts +2 -1
  95. package/dist/groups/helpers.d.ts +18 -0
  96. package/dist/groups/helpers.js +1 -2
  97. package/dist/groups/mapping.d.ts +4 -2
  98. package/dist/groups/mutations.js +1 -1
  99. package/dist/hashtags/finders.d.ts +6 -3
  100. package/dist/hashtags/finders.js +2 -0
  101. package/dist/hashtags/helpers.d.ts +8 -0
  102. package/dist/hashtags/helpers.js +4 -0
  103. package/dist/hashtags/index.d.ts +2 -0
  104. package/dist/hashtags/index.js +2 -0
  105. package/dist/hashtags/mutations.d.ts +3 -0
  106. package/dist/hashtags/mutations.js +13 -1
  107. package/dist/i18n/index.d.ts +1 -1
  108. package/dist/i18n/index.js +3 -1
  109. package/dist/i18n/pluginLocales.d.ts +6 -0
  110. package/dist/i18n/pluginLocales.js +15 -0
  111. package/dist/inviteLinks/mutations.js +2 -3
  112. package/dist/jams/export.d.ts +19 -0
  113. package/dist/jams/export.js +58 -0
  114. package/dist/jams/finders.js +4 -1
  115. package/dist/jams/health.d.ts +10 -0
  116. package/dist/jams/health.js +50 -0
  117. package/dist/jams/helpers.d.ts +2 -2
  118. package/dist/jams/helpers.js +6 -2
  119. package/dist/jams/index.d.ts +2 -0
  120. package/dist/jams/index.js +25 -18
  121. package/dist/jams/jobs.js +2 -3
  122. package/dist/jams/livekit.d.ts +49 -4
  123. package/dist/jams/livekit.js +62 -45
  124. package/dist/jams/mapping.d.ts +3 -3
  125. package/dist/jams/mutations.d.ts +1 -1
  126. package/dist/jams/recording.d.ts +10 -0
  127. package/dist/jams/recording.js +33 -1
  128. package/dist/jams/token.d.ts +13 -1
  129. package/dist/jams/token.js +25 -18
  130. package/dist/jams/waitingRoom.js +1 -1
  131. package/dist/jobs/index.d.ts +1 -0
  132. package/dist/jobs/index.js +9 -3
  133. package/dist/jobs/jobDetail.js +6 -12
  134. package/dist/jobs/jobLog.js +2 -3
  135. package/dist/lib/streams.js +4 -39
  136. package/dist/lib/zodDeepPartial.d.ts +1 -1
  137. package/dist/lib/zodDeepPartial.js +1 -1
  138. package/dist/log/index.js +13 -29
  139. package/dist/media/index.d.ts +1 -1
  140. package/dist/media/index.js +73 -12
  141. package/dist/media/jobs.js +1 -2
  142. package/dist/media/openpeeps/index.js +11 -46
  143. package/dist/media/processing.js +25 -11
  144. package/dist/media/streaming.js +5 -5
  145. package/dist/media/streamingCleanupJobs.js +1 -2
  146. package/dist/media/streamingJobs.js +3 -4
  147. package/dist/media/streamingPrewarm.js +7 -11
  148. package/dist/mediaAttachments/index.js +6 -2
  149. package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
  150. package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
  151. package/dist/notifications/defaultNotifications/follow/index.js +15 -18
  152. package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
  153. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
  154. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
  155. package/dist/notifications/defaultNotifications/index.js +4 -0
  156. package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
  157. package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
  158. package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
  159. package/dist/notifications/defaultNotifications/mention/index.js +20 -24
  160. package/dist/notifications/defaultNotifications/newGroupPost/index.js +11 -6
  161. package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
  162. package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
  163. package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
  164. package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
  165. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +17 -0
  166. package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
  167. package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
  168. package/dist/notifications/defaultNotifications/reply/index.js +21 -22
  169. package/dist/notifications/defaultNotifications/repost/index.js +16 -20
  170. package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
  171. package/dist/notifications/defaultNotifications/rsvp/index.js +31 -18
  172. package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
  173. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +82 -0
  174. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
  175. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
  176. package/dist/notifications/fcmCredential.js +1 -1
  177. package/dist/notifications/finders.js +1 -1
  178. package/dist/notifications/helpers.js +13 -10
  179. package/dist/notifications/jobs.js +10 -5
  180. package/dist/notifications/mutations.js +8 -1
  181. package/dist/notifications/push.js +11 -16
  182. package/dist/performance/index.js +3 -3
  183. package/dist/plugins/helpers.js +3 -6
  184. package/dist/plugins/index.js +39 -4
  185. package/dist/plugins/install.d.ts +28 -9
  186. package/dist/plugins/install.js +302 -56
  187. package/dist/plugins/pluginAuth.d.ts +1 -1
  188. package/dist/plugins/pluginAuth.js +13 -10
  189. package/dist/plugins/state.js +2 -3
  190. package/dist/posts/activity.d.ts +9 -0
  191. package/dist/posts/activity.js +34 -0
  192. package/dist/posts/contextClosure.d.ts +1 -9
  193. package/dist/posts/contextClosure.js +14 -44
  194. package/dist/posts/conversationQueries.d.ts +7 -0
  195. package/dist/posts/conversationQueries.js +76 -4
  196. package/dist/posts/eventAgenda.d.ts +1 -0
  197. package/dist/posts/eventAgenda.js +17 -8
  198. package/dist/posts/eventOccurrenceJobs.js +7 -2
  199. package/dist/posts/eventOccurrences.d.ts +6 -0
  200. package/dist/posts/eventOccurrences.js +22 -1
  201. package/dist/posts/finders.d.ts +56 -9
  202. package/dist/posts/finders.js +84 -23
  203. package/dist/posts/helpers/filters.js +13 -9
  204. package/dist/posts/helpers/index.d.ts +179 -14
  205. package/dist/posts/helpers/index.js +70 -34
  206. package/dist/posts/index.d.ts +5 -2
  207. package/dist/posts/index.js +5 -2
  208. package/dist/posts/mapping.d.ts +765 -30
  209. package/dist/posts/mapping.js +74 -31
  210. package/dist/posts/mutations.d.ts +516 -3
  211. package/dist/posts/mutations.js +179 -41
  212. package/dist/posts/pollEnd.d.ts +3 -0
  213. package/dist/posts/pollEnd.js +4 -0
  214. package/dist/posts/pollEndJobs.d.ts +8 -0
  215. package/dist/posts/pollEndJobs.js +49 -0
  216. package/dist/posts/replyClosure.d.ts +10 -0
  217. package/dist/posts/replyClosure.js +43 -0
  218. package/dist/posts/rsvpConfirmationEmail.js +23 -15
  219. package/dist/posts/threadPreview.d.ts +8 -0
  220. package/dist/posts/threadPreview.js +44 -0
  221. package/dist/posts/unseenCounts.js +4 -1
  222. package/dist/processingStats/queries.js +6 -7
  223. package/dist/profileSettings/cache.js +21 -5
  224. package/dist/profileSettings/mapping.d.ts +2 -0
  225. package/dist/profiles/activityQueries.d.ts +5 -0
  226. package/dist/profiles/activityQueries.js +85 -0
  227. package/dist/profiles/activitySummary.d.ts +3 -0
  228. package/dist/profiles/activitySummary.js +82 -0
  229. package/dist/profiles/blocks.d.ts +12 -0
  230. package/dist/profiles/blocks.js +73 -0
  231. package/dist/profiles/cache.d.ts +1 -0
  232. package/dist/profiles/cache.js +30 -10
  233. package/dist/profiles/export.js +30 -39
  234. package/dist/profiles/finders.d.ts +2 -1
  235. package/dist/profiles/finders.js +15 -8
  236. package/dist/profiles/helpers.d.ts +2 -0
  237. package/dist/profiles/index.d.ts +2 -0
  238. package/dist/profiles/index.js +2 -0
  239. package/dist/profiles/mapping.d.ts +10 -5
  240. package/dist/profiles/mapping.js +13 -1
  241. package/dist/profiles/mutations.d.ts +8 -4
  242. package/dist/profiles/mutations.js +31 -4
  243. package/dist/redis/connection.d.ts +2 -0
  244. package/dist/redis/connection.js +25 -6
  245. package/dist/reports/helpers.js +7 -3
  246. package/dist/roles/index.d.ts +1 -1
  247. package/dist/roles/index.js +1 -1
  248. package/dist/roles/mapping.d.ts +1 -0
  249. package/dist/roles/mutations.js +85 -3
  250. package/dist/search/finders.js +15 -3
  251. package/dist/search/helpers.js +1 -1
  252. package/dist/search/mapping.d.ts +1 -1
  253. package/dist/search/mapping.js +6 -2
  254. package/dist/sentry/index.js +9 -11
  255. package/dist/seo/index.d.ts +50 -0
  256. package/dist/seo/index.js +145 -0
  257. package/dist/seo/route.d.ts +18 -0
  258. package/dist/seo/route.js +19 -0
  259. package/dist/server/index.d.ts +19 -0
  260. package/dist/server/index.js +31 -14
  261. package/dist/server/stablePublicServerInfo.d.ts +17 -0
  262. package/dist/server/stablePublicServerInfo.js +37 -0
  263. package/dist/server/status.d.ts +25 -0
  264. package/dist/server/status.js +97 -0
  265. package/dist/session/index.js +2 -2
  266. package/dist/stats/finders.d.ts +1 -17681
  267. package/dist/stats/finders.js +22 -9
  268. package/dist/stats/helpers.js +4 -1
  269. package/dist/stats/mapping.d.ts +39 -2
  270. package/dist/stats/mapping.js +8 -4
  271. package/dist/stripe/cache.js +5 -6
  272. package/dist/stripe/connection.js +3 -4
  273. package/dist/stripe/helpers.js +15 -20
  274. package/package.json +5 -7
  275. package/dist/db/migration/detect.d.ts +0 -3
  276. package/dist/db/migration/detect.js +0 -33
  277. package/dist/db/migration/importPostgres.d.ts +0 -3
  278. package/dist/db/migration/importPostgres.js +0 -18
  279. package/dist/db/migration/transform.d.ts +0 -20
  280. package/dist/db/migration/transform.js +0 -232
  281. package/dist/db/migration/validate.d.ts +0 -18
  282. package/dist/db/migration/validate.js +0 -69
  283. package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
  284. package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
  285. package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
  286. package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
  287. package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
  288. package/dist/mastodon/index.d.ts +0 -4
  289. package/dist/mastodon/index.js +0 -51
  290. package/dist/mastodon/types.d.ts +0 -7579
  291. package/dist/mastodon/types.js +0 -523
  292. package/dist/mastodon/typescript.d.ts +0 -1578
  293. package/dist/mastodon/typescript.js +0 -1
  294. package/dist/migration/index.d.ts +0 -4
  295. package/dist/migration/index.js +0 -4
  296. package/dist/roles/defaults.d.ts +0 -2
  297. package/dist/roles/defaults.js +0 -95
@@ -0,0 +1,24 @@
1
+ import { type ExpandedNotification } from '@openpeepshq/common/types';
2
+ declare const _default: {
3
+ type: string;
4
+ event: string;
5
+ defaultSettings: {
6
+ readonly create: true;
7
+ readonly push: true;
8
+ readonly email: true;
9
+ };
10
+ eventHandler: (senderProfile: unknown, post: unknown, data: unknown) => Promise<void>;
11
+ pushRenderer: (notification: ExpandedNotification) => Promise<{
12
+ title: string;
13
+ options: {
14
+ body: string;
15
+ icon: string;
16
+ actions: {
17
+ action: string;
18
+ title: string;
19
+ }[];
20
+ };
21
+ invalidateQueries: string[][];
22
+ }>;
23
+ };
24
+ export default _default;
@@ -0,0 +1,82 @@
1
+ import { notificationAll, } from '@openpeepshq/common/types';
2
+ import { getProfileAvatar, isRsvpCancelNotice, profileName, rsvpCancelWhenLabels, rsvpTargetsPastEvent, } from '@openpeepshq/common/lib';
3
+ import { maybeCreateNotification } from '@openpeepshq/core/notifications';
4
+ import { findProfile, listGroupMembers } from '@openpeepshq/core/profiles';
5
+ import { communityConfig } from '../../../config/index.js';
6
+ import { PUSH_INVALIDATE } from '../../pushInvalidation.js';
7
+ import { rsvpCancelRecipients } from './recipients.js';
8
+ const eventName = (post) => post?.data?.type === 'event' ? post.data.name?.trim() : undefined;
9
+ const whenText = (post, notice) => {
10
+ if (!post)
11
+ return '';
12
+ const when = rsvpCancelWhenLabels(post, notice);
13
+ if (when.series)
14
+ return 'All dates in the series';
15
+ return when.labels.join(', ');
16
+ };
17
+ const eventHandler = async (senderProfile, post, data) => {
18
+ const mergedPost = post;
19
+ const fromProfile = senderProfile;
20
+ const cancel = data?.cancel;
21
+ if (!isRsvpCancelNotice(cancel))
22
+ return;
23
+ if (mergedPost.type !== 'event' || mergedPost.data?.type !== 'event') {
24
+ return;
25
+ }
26
+ const event = mergedPost.data;
27
+ if (rsvpTargetsPastEvent(event, cancel.series ? undefined : { occurrenceIds: cancel.occurrenceIds })) {
28
+ return;
29
+ }
30
+ const moderatorIds = [
31
+ ...(event.moderators ?? []),
32
+ ...(event.jam?.moderators ?? []),
33
+ ];
34
+ const moderators = (await Promise.all(moderatorIds.map((id) => findProfile(id)))).filter((profile) => !!profile);
35
+ const groupAdmins = mergedPost.group
36
+ ? (await listGroupMembers(mergedPost.group))
37
+ .filter((member) => member.roles?.includes('owner') || member.roles?.includes('admin'))
38
+ .map((member) => member.profile)
39
+ : [];
40
+ const recipients = rsvpCancelRecipients([mergedPost.profile, ...moderators, ...groupAdmins], fromProfile.id);
41
+ for (const recipient of recipients) {
42
+ await maybeCreateNotification(recipient, {
43
+ type: 'rsvpCanceled',
44
+ postId: mergedPost.id,
45
+ fromProfileId: fromProfile.id,
46
+ ...(mergedPost.groupId ? { groupId: mergedPost.groupId } : {}),
47
+ data: cancel,
48
+ });
49
+ }
50
+ };
51
+ const pushRenderer = async (notification) => {
52
+ const notice = isRsvpCancelNotice(notification.data)
53
+ ? notification.data
54
+ : { occurrenceIds: [], series: false };
55
+ const name = eventName(notification.post ?? undefined);
56
+ const when = whenText(notification.post ?? undefined, notice);
57
+ return {
58
+ title: `${profileName(notification.senderProfile)} canceled their RSVP`,
59
+ options: {
60
+ body: [name, when].filter(Boolean).join(' · '),
61
+ icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
62
+ actions: [
63
+ {
64
+ action: `goto:/posts/${notification.post?.id}`,
65
+ title: 'View event',
66
+ },
67
+ ],
68
+ },
69
+ invalidateQueries: [
70
+ PUSH_INVALIDATE.posts,
71
+ PUSH_INVALIDATE.notifications,
72
+ PUSH_INVALIDATE.notificationStats,
73
+ ],
74
+ };
75
+ };
76
+ export default {
77
+ type: 'rsvpCanceled',
78
+ event: 'rsvpCreated',
79
+ defaultSettings: notificationAll,
80
+ eventHandler,
81
+ pushRenderer,
82
+ };
@@ -0,0 +1,4 @@
1
+ /** One notification per person. The member who canceled is not notified. */
2
+ export declare const rsvpCancelRecipients: <T extends {
3
+ id: string;
4
+ }>(profiles: T[], actorId: string) => T[];
@@ -0,0 +1,11 @@
1
+ /** One notification per person. The member who canceled is not notified. */
2
+ export const rsvpCancelRecipients = (profiles, actorId) => {
3
+ const seen = new Set();
4
+ return profiles.filter((profile) => {
5
+ if (!profile.id || profile.id === actorId || seen.has(profile.id)) {
6
+ return false;
7
+ }
8
+ seen.add(profile.id);
9
+ return true;
10
+ });
11
+ };
@@ -51,7 +51,7 @@ export const createFcmCredential = (serviceAccount, agent) => {
51
51
  return {
52
52
  getAccessToken: async () => {
53
53
  const now = Date.now();
54
- if (cached && cached.expiresAt > now + 60000) {
54
+ if (cached && cached.expiresAt > now + 60_000) {
55
55
  return {
56
56
  access_token: cached.access_token,
57
57
  expires_in: Math.floor((cached.expiresAt - now) / 1000),
@@ -3,7 +3,7 @@ import { addStart, filterAndTransform } from '../db/helpers.js';
3
3
  import { baseListNotifications, expandNotification, unreadNotifications, unseenNotifications, } from './helpers.js';
4
4
  export const findNotification = (profile, notificationId) => allpeepDb()
5
5
  .then(({ db }) => baseListNotifications(profile).find(db, notificationId))
6
- .then((notification) => (notification === null || notification === void 0 ? void 0 : notification.profileId) === profile.id
6
+ .then((notification) => notification?.profileId === profile.id
7
7
  ? expandNotification(notification)
8
8
  : undefined);
9
9
  export const listNotificationsByProfile = (profile, { start, limit = 100 } = { limit: 100 }) => allpeepDb().then(({ db }) => filterAndTransform(addStart(baseListNotifications(profile), start), db, { transform: expandNotification, limit }));
@@ -8,23 +8,26 @@ import { getProfile } from '../profiles/cache.js';
8
8
  import { transformPost } from '../posts/index.js';
9
9
  import { notificationHandlers } from './handlers.js';
10
10
  export const baseListNotifications = (profile) => notificationsMapping.filter(notificationFilters.forProfile(profile.id));
11
- export const notificationSettings = (profileSettings, type) => {
12
- var _a, _b, _c, _d;
13
- return (_d = (_b = (_a = profileSettings === null || profileSettings === void 0 ? void 0 : profileSettings.notifications) === null || _a === void 0 ? void 0 : _a[type]) !== null && _b !== void 0 ? _b : (_c = defaultNotificationTypes.find((t) => t.type === type)) === null || _c === void 0 ? void 0 : _c.defaultSettings) !== null && _d !== void 0 ? _d : notificationDefaults;
14
- };
11
+ export const notificationSettings = (profileSettings, type) => profileSettings?.notifications?.[type] ??
12
+ defaultNotificationTypes.find((t) => t.type === type)?.defaultSettings ??
13
+ notificationDefaults;
15
14
  export const expandNotification = async (notification) => {
16
- var _a, _b;
17
- const intermediateNotification = Object.assign(Object.assign({}, notification), {
15
+ const intermediateNotification = {
16
+ ...notification,
18
17
  // Include soft-deleted senders so anonymizeProfileIfDeleted can tombstone
19
18
  // them; otherwise fromProfileId resolves to undefined and the UI falls
20
19
  // back to an uninterpolated "{{profileName}} …" string.
21
20
  senderProfile: notification.fromProfileId
22
21
  ? anonymizeProfileIfDeleted(await getProfile(notification.fromProfileId, true))
23
- : undefined, post: notification.post
22
+ : undefined,
23
+ post: notification.post
24
24
  ? await transformPost(notification.post)
25
- : undefined, recipientProfile: (await getProfile(notification.profileId)) });
26
- return ((await ((_b = (_a = notificationHandlers
27
- .get(notification.type)) === null || _a === void 0 ? void 0 : _a.expander) === null || _b === void 0 ? void 0 : _b.call(_a, intermediateNotification))) || intermediateNotification);
25
+ : undefined,
26
+ recipientProfile: (await getProfile(notification.profileId)),
27
+ };
28
+ return ((await notificationHandlers
29
+ .get(notification.type)
30
+ ?.expander?.(intermediateNotification)) || intermediateNotification);
28
31
  };
29
32
  const baseStatNotificationsMapping = (profile) => unexpandedNotificationsMapping.filter(notificationFilters.forProfile(profile.id));
30
33
  export const unseenNotifications = (profile) => allpeepDb().then(({ db }) => baseStatNotificationsMapping(profile)
@@ -12,12 +12,11 @@ import { logger } from '../log/index.js';
12
12
  import { publishSessionEvent } from '../session/index.js';
13
13
  const log = logger('core:notifications:worker');
14
14
  const [notificationQueue, notificationWorker] = queueAndWorker('process-notification', async (job) => {
15
- var _a, _b;
16
15
  const notification = job.data;
17
16
  const jobLog = jobLogger(job);
18
17
  await logStep(jobLog, log, `Processing notification ${notification.id} (type=${notification.type}) ` +
19
18
  `for profile ${notification.recipientProfile.id} ` +
20
- `(attempt ${job.attemptsMade + 1}/${(_a = job.opts.attempts) !== null && _a !== void 0 ? _a : 1})`);
19
+ `(attempt ${job.attemptsMade + 1}/${job.opts.attempts ?? 1})`);
21
20
  const profile = await findProfile(notification.recipientProfile.id);
22
21
  if (!profile) {
23
22
  await logFailure(jobLog, log, `Profile ${notification.recipientProfile.id} not found; skipping notification ${notification.id}`);
@@ -42,7 +41,12 @@ const [notificationQueue, notificationWorker] = queueAndWorker('process-notifica
42
41
  await mailer.send({
43
42
  template: `notification-${notification.type}`,
44
43
  to: account.email,
45
- locals: notification,
44
+ locals: {
45
+ ...notification,
46
+ ...(profileSettings.timeZone
47
+ ? { timeZone: profileSettings.timeZone }
48
+ : {}),
49
+ },
46
50
  });
47
51
  await logStep(jobLog, log, `Queued email notification to ${account.email}`);
48
52
  }
@@ -52,8 +56,9 @@ const [notificationQueue, notificationWorker] = queueAndWorker('process-notifica
52
56
  }
53
57
  if (push) {
54
58
  try {
55
- const pushNotification = await ((_b = notificationHandlers
56
- .get(notification.type)) === null || _b === void 0 ? void 0 : _b.pushRenderer(notification));
59
+ const pushNotification = await notificationHandlers
60
+ .get(notification.type)
61
+ ?.pushRenderer(notification);
57
62
  if (pushNotification && !sessionPublished) {
58
63
  sessionPublished = true;
59
64
  await publishSessionEvent(profile.id, {
@@ -4,6 +4,7 @@ import { notificationFilters } from '../db/pg/filters/index.js';
4
4
  import { baseListNotifications, expandNotification, notificationSettings, } from './helpers.js';
5
5
  import { hub } from '../events/index.js';
6
6
  import { findProfile } from '../profiles/index.js';
7
+ import { isBlockedPair } from '@openpeepshq/common/lib';
7
8
  import { logger } from '../log/index.js';
8
9
  import { findProfileSettings } from '../profileSettings/index.js';
9
10
  const log = logger('openpeeps:notifications');
@@ -25,6 +26,9 @@ export const maybeCreateNotification = async (profile, data) => {
25
26
  log.error(`Profile ${profile.id} not found`);
26
27
  return;
27
28
  }
29
+ if (data.fromProfileId && isBlockedPair(fullProfile, data.fromProfileId)) {
30
+ return;
31
+ }
28
32
  const profileSettings = await findProfileSettings(profile.id);
29
33
  if (!profileSettings) {
30
34
  log.error(`profileSettings ${profile.id} not found`);
@@ -32,7 +36,10 @@ export const maybeCreateNotification = async (profile, data) => {
32
36
  }
33
37
  const settings = notificationSettings(profileSettings, type);
34
38
  if (settings.create) {
35
- const notificationData = Object.assign(Object.assign({}, data), { profileId: profile.id });
39
+ const notificationData = {
40
+ ...data,
41
+ profileId: profile.id,
42
+ };
36
43
  const notification = await allpeepDb().then(({ db }) => notificationsMapping.create(db, notificationData));
37
44
  const expandedNotification = await expandNotification(notification);
38
45
  await hub.emit('notificationCreated', expandedNotification);
@@ -21,7 +21,7 @@ const describeSubscription = (subscription) => {
21
21
  try {
22
22
  host = new URL(subscription.endpoint).host;
23
23
  }
24
- catch (_a) {
24
+ catch {
25
25
  // keep 'unknown'
26
26
  }
27
27
  return `web sub=${subscription.id} endpoint=${host}`;
@@ -82,14 +82,11 @@ const sendAppIOSPushNotifications = async (subscriptions, payload, notification,
82
82
  return;
83
83
  const serializedPayload = JSON.stringify(payload);
84
84
  const { iosClient, Notification } = await getIOSPushClient();
85
- const notifications = subscriptions.map(({ apnToken }) => {
86
- var _a;
87
- return new Notification(apnToken, {
88
- badge: Number(((_a = notification === null || notification === void 0 ? void 0 : notification.options) === null || _a === void 0 ? void 0 : _a.badge) || '1'),
89
- alert: notification === null || notification === void 0 ? void 0 : notification.title,
90
- data: { payload: serializedPayload },
91
- });
92
- });
85
+ const notifications = subscriptions.map(({ apnToken }) => new Notification(apnToken, {
86
+ badge: Number(notification?.options?.badge || '1'),
87
+ alert: notification?.title,
88
+ data: { payload: serializedPayload },
89
+ }));
93
90
  await logStep(jobLog, log, `Sending APNs push to ${subscriptions.length} device(s)`);
94
91
  let results;
95
92
  try {
@@ -117,7 +114,6 @@ const sendAppIOSPushNotifications = async (subscriptions, payload, notification,
117
114
  };
118
115
  const describeFcmTarget = (account, subscription) => `account ${account.id} (${account.email}); ${describeSubscription(subscription)}`;
119
116
  const sendAppFCMPushNotifications = async (subscriptions, payload, notification, account, jobLog) => {
120
- var _a, _b;
121
117
  if (subscriptions.length === 0)
122
118
  return;
123
119
  const serializedPayload = JSON.stringify(payload);
@@ -142,8 +138,8 @@ const sendAppFCMPushNotifications = async (subscriptions, payload, notification,
142
138
  contentAvailable: true,
143
139
  priority: 'high',
144
140
  alert: notification.title,
145
- badge: Number(((_a = notification === null || notification === void 0 ? void 0 : notification.options) === null || _a === void 0 ? void 0 : _a.badge) || '1'),
146
- data: (_b = notification === null || notification === void 0 ? void 0 : notification.options) === null || _b === void 0 ? void 0 : _b.data,
141
+ badge: Number(notification?.options?.badge || '1'),
142
+ data: notification?.options?.data,
147
143
  },
148
144
  },
149
145
  },
@@ -200,12 +196,11 @@ export const doPush = async (notification, notificationStats, account, jobLog) =
200
196
  await logStep(jobLog, log, `Sending web push to ${describeSubscription(subscription)}`);
201
197
  await sendWebPushNotification(subscription, payloadData)
202
198
  .then(async (result) => {
203
- var _a;
204
199
  if (result && result.statusCode >= 400) {
205
200
  await logFailure(jobLog, log, `web push to ${describeSubscription(subscription)} returned status ${result.statusCode}`);
206
201
  return;
207
202
  }
208
- await logStep(jobLog, log, `Web push delivered to ${describeSubscription(subscription)} (status ${(_a = result === null || result === void 0 ? void 0 : result.statusCode) !== null && _a !== void 0 ? _a : 'n/a'})`);
203
+ await logStep(jobLog, log, `Web push delivered to ${describeSubscription(subscription)} (status ${result?.statusCode ?? 'n/a'})`);
209
204
  })
210
205
  .catch(async (error) => {
211
206
  await logFailure(jobLog, log, `web push to ${describeSubscription(subscription)} failed; removing dead subscription`, error);
@@ -239,7 +234,7 @@ export const sendTestPushNotification = async (account, profile, subscriptionKey
239
234
  const subscriptions = await listPushSubscriptionsByAccount(account);
240
235
  const webSubscription = subscriptions
241
236
  .filter((s) => s.type === 'web')
242
- .find((s) => { var _a; return ((_a = s === null || s === void 0 ? void 0 : s.keys) === null || _a === void 0 ? void 0 : _a.auth) === subscriptionKey; });
237
+ .find((s) => s?.keys?.auth === subscriptionKey);
243
238
  if (webSubscription) {
244
239
  await sendWebPushNotification(webSubscription, payload)
245
240
  .catch(async (error) => {
@@ -248,7 +243,7 @@ export const sendTestPushNotification = async (account, profile, subscriptionKey
248
243
  throw error;
249
244
  })
250
245
  .then((r) => {
251
- if (!(r === null || r === void 0 ? void 0 : r.statusCode) || r.statusCode >= 400)
246
+ if (!r?.statusCode || r.statusCode >= 400)
252
247
  log.error(r);
253
248
  });
254
249
  return;
@@ -15,7 +15,7 @@ export const dbTimingEnabled = () => process.env.PERF_DB_TIMING === '1' || proce
15
15
  const SLOW_REQUEST_BUFFER_SIZE = 100;
16
16
  const slowRequests = [];
17
17
  export const recordSlowRequest = (record) => {
18
- slowRequests.unshift(Object.assign(Object.assign({}, record), { at: new Date().toISOString() }));
18
+ slowRequests.unshift({ ...record, at: new Date().toISOString() });
19
19
  if (slowRequests.length > SLOW_REQUEST_BUFFER_SIZE) {
20
20
  slowRequests.length = SLOW_REQUEST_BUFFER_SIZE;
21
21
  }
@@ -36,7 +36,7 @@ export const withSpan = async (name, fn, attributes) => Sentry.startSpan({ name,
36
36
  finally {
37
37
  const durationMs = performance.now() - start;
38
38
  if (durationMs >= slowSpanMs()) {
39
- log.warn(Object.assign({ name, durationMs }, attributes), 'slow span');
39
+ log.warn({ name, durationMs, ...attributes }, 'slow span');
40
40
  }
41
41
  }
42
42
  });
@@ -47,7 +47,7 @@ export const truncateSql = (sqlText, max = 240) => {
47
47
  if (sqlText && typeof sqlText === 'object' && 'text' in sqlText) {
48
48
  return truncateSql(sqlText.text, max);
49
49
  }
50
- return String(sqlText !== null && sqlText !== void 0 ? sqlText : '');
50
+ return String(sqlText ?? '');
51
51
  }
52
52
  const compact = sqlText.replace(/\s+/g, ' ').trim();
53
53
  return compact.length > max ? `${compact.slice(0, max)}…` : compact;
@@ -2,10 +2,8 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { logger } from '../log/index.js';
4
4
  const log = logger('core:plugins');
5
- export const isPluginEnabled = (info) => {
6
- var _a;
7
- return ((_a = info.openpeeps) === null || _a === void 0 ? void 0 : _a.enabled) !== false;
8
- };
5
+ export const isPluginEnabled = (info) => info.openpeeps
6
+ ?.enabled !== false;
9
7
  export const sortByDependencies = (pluginInfos) => {
10
8
  const pluginKeys = pluginInfos.map(([key]) => key);
11
9
  const packageNameToKey = new Map(pluginInfos
@@ -69,13 +67,12 @@ export const enumeratePluginInfos = async (pluginsPath) => {
69
67
  // root `package.json`'s `openpeeps.plugins` array (paths relative to the repo
70
68
  // root), keeping example/demo plugins opt-in.
71
69
  export const enumerateReferencedPluginInfos = (rootPackageJsonPath) => {
72
- var _a, _b;
73
70
  if (!fs.existsSync(rootPackageJsonPath)) {
74
71
  return [];
75
72
  }
76
73
  const rootPackageJson = JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf-8'));
77
74
  const repoRoot = path.dirname(rootPackageJsonPath);
78
- return ((_b = (_a = rootPackageJson.openpeeps) === null || _a === void 0 ? void 0 : _a.plugins) !== null && _b !== void 0 ? _b : []).map((relativePath) => {
75
+ return (rootPackageJson.openpeeps?.plugins ?? []).map((relativePath) => {
79
76
  const pluginPath = path.join(repoRoot, relativePath);
80
77
  const key = path.join('examples', path.basename(pluginPath));
81
78
  const info = JSON.parse(fs.readFileSync(path.join(pluginPath, 'package.json'), 'utf-8'));
@@ -1,9 +1,12 @@
1
1
  import { hub, VALID_EVENT_KEYS } from '../events/index.js';
2
2
  import { defaultConfig, registerConfigSchema } from '../config/index.js';
3
- import { pluginManifestSchema } from '@openpeepshq/common';
3
+ import { i18nResourceSchema, pluginManifestSchema } from '@openpeepshq/common';
4
+ import path from 'node:path';
4
5
  import { enumeratePluginInfos, enumerateReferencedPluginInfos, isPluginEnabled, sortByDependencies, } from './helpers.js';
5
6
  import { getPluginStateOverrides } from './state.js';
7
+ import { selfHealInstalledPlugins } from './install.js';
6
8
  import { logger } from '../log/index.js';
9
+ import { clearPluginLocales, registerPluginLocales } from '../i18n/index.js';
7
10
  export * from './pluginAuth.js';
8
11
  export * from './state.js';
9
12
  export * from './install.js';
@@ -26,6 +29,7 @@ const clearPluginState = () => {
26
29
  loadedModules.clear();
27
30
  pluginManifests.clear();
28
31
  pluginUnsubscribers.clear();
32
+ clearPluginLocales();
29
33
  initialized = false;
30
34
  };
31
35
  export const initializePlugins = async () => {
@@ -34,10 +38,20 @@ export const initializePlugins = async () => {
34
38
  }
35
39
  const { plugins: { path: pluginsPath, rootPackageJsonPath }, } = await defaultConfig;
36
40
  const stateOverrides = await getPluginStateOverrides();
41
+ // Re-fetch admin-installed plugins whose files are missing (e.g. the
42
+ // plugins path is not a persistent volume and the container was recreated).
43
+ // Never let a failed heal take the boot down — the plugin is surfaced as a
44
+ // failed entry below so an admin can see why and re-install it.
45
+ let healFailures = {};
46
+ try {
47
+ healFailures = await selfHealInstalledPlugins();
48
+ }
49
+ catch (e) {
50
+ log.error(e, 'Plugin self-heal failed; continuing without it.');
51
+ }
37
52
  const loadPlugin = async (key, info, pluginPath) => {
38
- var _a, _b;
39
53
  const [namespace, name] = key.split('/');
40
- const displayName = typeof ((_a = info === null || info === void 0 ? void 0 : info.config) === null || _a === void 0 ? void 0 : _a.displayName) === 'string'
54
+ const displayName = typeof info?.config?.displayName === 'string'
41
55
  ? info.config.displayName
42
56
  : key;
43
57
  const plugin = {
@@ -50,7 +64,7 @@ export const initializePlugins = async () => {
50
64
  // DB override (set via the admin toggle) takes precedence over the
51
65
  // static `openpeeps.enabled` package.json gate; a missing override
52
66
  // falls back to the static gate.
53
- const enabled = (_b = stateOverrides[key]) !== null && _b !== void 0 ? _b : isPluginEnabled(info);
67
+ const enabled = stateOverrides[key] ?? isPluginEnabled(info);
54
68
  if (!enabled) {
55
69
  log.info(`Skipping disabled plugin "${displayName}" (key: ${key}).`);
56
70
  plugin.status = 'disabled';
@@ -89,6 +103,15 @@ export const initializePlugins = async () => {
89
103
  if ('manifest' in pluginModule) {
90
104
  pluginManifests.set(key, pluginManifestSchema.parse(pluginModule.manifest));
91
105
  }
106
+ if ('locales' in pluginModule) {
107
+ const parsed = i18nResourceSchema.safeParse(pluginModule.locales);
108
+ if (parsed.success) {
109
+ registerPluginLocales(key, parsed.data);
110
+ }
111
+ else {
112
+ log.warn(`${plugin.key} locales export is invalid. Skipping translations.`);
113
+ }
114
+ }
92
115
  plugin.status = 'loaded';
93
116
  }
94
117
  catch (e) {
@@ -106,6 +129,18 @@ export const initializePlugins = async () => {
106
129
  for (const [key, info, pluginPath] of sortedInfos) {
107
130
  await loadPlugin(key, info, pluginPath);
108
131
  }
132
+ for (const [key, reason] of Object.entries(healFailures)) {
133
+ const [namespace, name] = key.split('/');
134
+ loadedPlugins.set(key, {
135
+ key,
136
+ namespace,
137
+ name,
138
+ info: { name: key },
139
+ path: path.join(pluginsPath, key),
140
+ status: 'failed',
141
+ error: reason,
142
+ });
143
+ }
109
144
  initialized = true;
110
145
  return Object.fromEntries(loadedPlugins.entries());
111
146
  };
@@ -1,13 +1,23 @@
1
- type InstallSource = {
2
- type: 'npm';
3
- package: string;
4
- version?: string;
5
- } | {
6
- type: 'git';
7
- url: string;
8
- ref?: string;
1
+ import type { PluginInstallSource } from '@openpeepshq/common/types';
2
+ type InstalledPluginRecord = {
3
+ /** Redacted source label (npm:pkg@ver or git:url#ref); never the credentials. */
4
+ source: string;
5
+ /** True when the install required credentials that are not stored. */
6
+ requiresAuth: boolean;
7
+ installedAt: string;
8
+ installedBy?: string;
9
9
  };
10
- export declare const installPlugin: (source: InstallSource, installedBy?: string) => Promise<{
10
+ type InstalledPluginsBody = Record<string, InstalledPluginRecord>;
11
+ export declare const getInstalledPlugins: () => Promise<InstalledPluginsBody>;
12
+ export declare const linkHostPeerDependencies: (installDir: string, names: string[]) => Promise<{
13
+ success: true;
14
+ } | {
15
+ success: false;
16
+ error: string;
17
+ }>;
18
+ export declare const installPlugin: (source: PluginInstallSource, installedBy?: string, options?: {
19
+ selfHeal?: boolean;
20
+ }) => Promise<{
11
21
  success: boolean;
12
22
  pluginKey?: string;
13
23
  error?: string;
@@ -16,5 +26,14 @@ export declare const uninstallPlugin: (pluginKey: string, uninstalledBy?: string
16
26
  success: boolean;
17
27
  error?: string;
18
28
  }>;
29
+ /**
30
+ * Re-downloads admin-installed plugins whose files are missing from the
31
+ * plugins directory (e.g. after a container recreate whose plugins path was
32
+ * not a persistent volume). Credentials are not stored, so plugins installed
33
+ * from private sources cannot be re-fetched — they are reported for manual
34
+ * re-install instead. Returns pluginKey -> reason for every plugin that is
35
+ * still unavailable after the attempt.
36
+ */
37
+ export declare const selfHealInstalledPlugins: () => Promise<Record<string, string>>;
19
38
  export declare const getInstalledPluginKeys: () => Promise<string[]>;
20
39
  export {};