@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
@@ -1,5 +1,5 @@
1
1
  import { SEND_EMAIL_QUEUE_NAME, sendEmailQueue } from './jobs.js';
2
- const n = (record, key) => { var _a; return (_a = record[key]) !== null && _a !== void 0 ? _a : 0; };
2
+ const n = (record, key) => record[key] ?? 0;
3
3
  export const getSendEmailQueueStats = async () => {
4
4
  const queue = sendEmailQueue();
5
5
  const raw = await queue.getJobCounts();
@@ -13,15 +13,12 @@ export const getSendEmailQueueStats = async () => {
13
13
  delayed: n(raw, 'delayed'),
14
14
  prioritized: n(raw, 'prioritized'),
15
15
  },
16
- recentFailures: failedJobs.map((j) => {
17
- var _a, _b, _c;
18
- return ({
19
- queue: SEND_EMAIL_QUEUE_NAME,
20
- id: (_a = j.id) !== null && _a !== void 0 ? _a : null,
21
- name: j.name,
22
- failedReason: (_b = j.failedReason) !== null && _b !== void 0 ? _b : '',
23
- finishedOn: (_c = j.finishedOn) !== null && _c !== void 0 ? _c : null,
24
- });
25
- }),
16
+ recentFailures: failedJobs.map((j) => ({
17
+ queue: SEND_EMAIL_QUEUE_NAME,
18
+ id: j.id ?? null,
19
+ name: j.name,
20
+ failedReason: j.failedReason ?? '',
21
+ finishedOn: j.finishedOn ?? null,
22
+ })),
26
23
  };
27
24
  };
@@ -1,19 +1,26 @@
1
+ import { FALLBACK_TIME_ZONE, resolveTimeZone } from '@openpeepshq/common/lib';
1
2
  import { communityConfig, config } from '../config/index.js';
2
3
  import { convert } from 'html-to-text';
3
4
  import { registeredTemplates } from './registry.js';
4
5
  import { serverRootUrl } from '../server/index.js';
5
6
  import { initI18nEmailContext } from '../i18n/index.js';
6
- const globals = async () => {
7
+ const localTimeZone = (locals) => {
8
+ const value = locals?.timeZone;
9
+ return typeof value === 'string' ? value : undefined;
10
+ };
11
+ const globals = async (locals) => {
7
12
  const serverConfig = await config();
8
13
  const rootUrl = await serverRootUrl();
14
+ const community = await communityConfig();
9
15
  return {
10
- communityConfig: await communityConfig(),
16
+ communityConfig: community,
11
17
  serverData: {
12
18
  rootUrl,
13
19
  iosUrl: serverConfig.apps.ios.url,
14
20
  androidUrl: serverConfig.apps.android.url,
15
21
  },
16
22
  i18nContext: await initI18nEmailContext(),
23
+ timeZone: resolveTimeZone(localTimeZone(locals), community.settings?.defaultTimeZone, FALLBACK_TIME_ZONE),
17
24
  };
18
25
  };
19
26
  export const render = async (emailData) => {
@@ -22,7 +29,11 @@ export const render = async (emailData) => {
22
29
  if (!render) {
23
30
  throw Error(`No renderer registered for ${emailData.template}`);
24
31
  }
25
- const { html, subject } = await render(Object.assign(Object.assign({}, emailData), { globals: await globals(), locals: locals || {} }));
32
+ const { html, subject } = await render({
33
+ ...emailData,
34
+ globals: await globals(locals),
35
+ locals: locals || {},
36
+ });
26
37
  const text = convert(html);
27
38
  return {
28
39
  to: emailData.to,
@@ -10,16 +10,15 @@ const logStep = async (log, message) => {
10
10
  serverLog.info(message);
11
11
  };
12
12
  const formatTransportSummary = (transportConfig) => {
13
- var _a;
14
13
  if (!transportConfig)
15
14
  return '(no transport config)';
16
15
  const { host, port, secure, auth } = transportConfig;
17
16
  return JSON.stringify({
18
- host: host !== null && host !== void 0 ? host : null,
19
- port: port !== null && port !== void 0 ? port : null,
20
- secure: secure !== null && secure !== void 0 ? secure : null,
21
- authUser: (_a = auth === null || auth === void 0 ? void 0 : auth.user) !== null && _a !== void 0 ? _a : null,
22
- authPass: (auth === null || auth === void 0 ? void 0 : auth.pass) ? '[set]' : auth ? '[empty]' : null,
17
+ host: host ?? null,
18
+ port: port ?? null,
19
+ secure: secure ?? null,
20
+ authUser: auth?.user ?? null,
21
+ authPass: auth?.pass ? '[set]' : auth ? '[empty]' : null,
23
22
  });
24
23
  };
25
24
  const formatErrorDetail = (err) => {
@@ -48,11 +47,10 @@ const logFailure = async (log, err) => {
48
47
  }
49
48
  };
50
49
  export const sendEmail = async (emailData, coreConfig, options) => {
51
- var _a, _b, _c, _d, _e, _f;
52
- const log = options === null || options === void 0 ? void 0 : options.log;
53
- const localKeys = Object.keys((_a = emailData.locals) !== null && _a !== void 0 ? _a : {});
50
+ const log = options?.log;
51
+ const localKeys = Object.keys(emailData.locals ?? {});
54
52
  await logStep(log, `Template "${emailData.template}" → ${emailData.to}${localKeys.length ? ` (locals: ${localKeys.join(', ')})` : ''}`);
55
- await logStep(log, `defaultFrom=${(_b = coreConfig.email.defaultFrom) !== null && _b !== void 0 ? _b : '(unset)'}`);
53
+ await logStep(log, `defaultFrom=${coreConfig.email.defaultFrom ?? '(unset)'}`);
56
54
  await logStep(log, `SMTP transport: ${formatTransportSummary(coreConfig.email.transportConfig)}`);
57
55
  let renderedEmail;
58
56
  await logStep(log, 'Render in-process (worker templates)');
@@ -72,11 +70,16 @@ export const sendEmail = async (emailData, coreConfig, options) => {
72
70
  }
73
71
  const emailTransport = nodemailer.createTransport(coreConfig.email.transportConfig);
74
72
  try {
75
- const result = await emailTransport.sendMail(Object.assign(Object.assign({ from, replyTo: communityConf.info.contactEmail }, renderedEmail), (((_c = emailData.attachments) === null || _c === void 0 ? void 0 : _c.length)
76
- ? { attachments: emailData.attachments }
77
- : {})));
78
- await logStep(log, `SMTP accepted message (messageId: ${(_d = result.messageId) !== null && _d !== void 0 ? _d : 'n/a'}, response: ${(_e = result.response) !== null && _e !== void 0 ? _e : 'n/a'})`);
79
- if ((_f = result.rejected) === null || _f === void 0 ? void 0 : _f.length) {
73
+ const result = await emailTransport.sendMail({
74
+ from,
75
+ replyTo: communityConf.info.contactEmail,
76
+ ...renderedEmail,
77
+ ...(emailData.attachments?.length
78
+ ? { attachments: emailData.attachments }
79
+ : {}),
80
+ });
81
+ await logStep(log, `SMTP accepted message (messageId: ${result.messageId ?? 'n/a'}, response: ${result.response ?? 'n/a'})`);
82
+ if (result.rejected?.length) {
80
83
  await logStep(log, `SMTP rejected recipients: ${result.rejected.join(', ')}`);
81
84
  }
82
85
  return result;
@@ -87,10 +90,9 @@ export const sendEmail = async (emailData, coreConfig, options) => {
87
90
  }
88
91
  };
89
92
  export const send = async (job) => {
90
- var _a;
91
93
  const log = (message) => job.log(message).then(() => undefined);
92
94
  const attempt = job.attemptsMade + 1;
93
- await logStep(log, `Job ${job.id} started (attempt ${attempt}/${(_a = job.opts.attempts) !== null && _a !== void 0 ? _a : 1}, name="${job.name}")`);
95
+ await logStep(log, `Job ${job.id} started (attempt ${attempt}/${job.opts.attempts ?? 1}, name="${job.name}")`);
94
96
  const coreConfig = await config();
95
97
  await logStep(log, 'Loaded core config');
96
98
  return sendEmail(job.data, coreConfig, { log });
@@ -3,24 +3,28 @@ import { passwordPlaceHolder } from '@openpeepshq/common/types';
3
3
  import { config } from '../config/index.js';
4
4
  import { sendEmail } from './send.js';
5
5
  const mergeEmailForTest = (base, override) => {
6
- var _a, _b, _c;
7
6
  if (!override) {
8
7
  return base;
9
8
  }
10
9
  const merged = deepmerge(base, override);
11
- const pass = (_b = (_a = override.transportConfig) === null || _a === void 0 ? void 0 : _a.auth) === null || _b === void 0 ? void 0 : _b.pass;
10
+ const pass = override.transportConfig?.auth?.pass;
12
11
  if (pass === undefined || pass === '' || pass === passwordPlaceHolder) {
13
- merged.transportConfig = Object.assign(Object.assign({}, merged.transportConfig), { auth: Object.assign(Object.assign({}, merged.transportConfig.auth), { pass: (_c = base.transportConfig.auth) === null || _c === void 0 ? void 0 : _c.pass }) });
12
+ merged.transportConfig = {
13
+ ...merged.transportConfig,
14
+ auth: {
15
+ ...merged.transportConfig.auth,
16
+ pass: base.transportConfig.auth?.pass,
17
+ },
18
+ };
14
19
  }
15
20
  return merged;
16
21
  };
17
22
  export const sendSmtpTestEmail = async (input) => {
18
- var _a;
19
23
  const saved = await config();
20
24
  const emailSettings = mergeEmailForTest(saved.email, input.email);
21
- if (!((_a = emailSettings.defaultFrom) === null || _a === void 0 ? void 0 : _a.trim())) {
25
+ if (!emailSettings.defaultFrom?.trim()) {
22
26
  throw new Error('defaultFrom is required to send mail');
23
27
  }
24
- const draftConfig = Object.assign(Object.assign({}, saved), { email: emailSettings });
28
+ const draftConfig = { ...saved, email: emailSettings };
25
29
  await sendEmail({ to: input.to, template: 'test' }, draftConfig);
26
30
  };
@@ -10,4 +10,4 @@ export const notFound = ({ errorKey = 'notFound', parameters, }) => allPeepError
10
10
  export const conflict = ({ errorKey = 'conflict', parameters, }) => allPeepError({ code: 409, errorKey, parameters });
11
11
  export const unprocessableRequest = ({ errorKey = 'unprocessableRequest', parameters, }) => allPeepError({ code: 422, errorKey, parameters });
12
12
  export const internalError = ({ errorKey = 'internalError', parameters, }) => allPeepError({ code: 500, errorKey, parameters });
13
- export const isOpenpeepsError = (o) => o === null || o === void 0 ? void 0 : o.__allPeepError__;
13
+ export const isOpenpeepsError = (o) => o?.__allPeepError__;
@@ -1,3 +1,4 @@
1
+ import type { RsvpCancelNotice } from '@openpeepshq/common/lib';
1
2
  import type { Profile, EntryData, PostWithMeta, Notification, ReactionData, JamRecordingWithMeta, RSVP, RsvpResponse } from '@openpeepshq/common/types';
2
3
  export type CoreEvents = {
3
4
  profileCreated: (profile: Profile) => void;
@@ -10,12 +11,15 @@ export type CoreEvents = {
10
11
  rsvpCreated: (profile: Profile, post: PostWithMeta, data: {
11
12
  type: 'rsvp';
12
13
  data: RSVP;
14
+ occurrenceIds?: string[];
13
15
  previousResponse?: RsvpResponse;
16
+ cancel?: RsvpCancelNotice;
14
17
  }) => void;
15
18
  postAnnounced: (post: PostWithMeta) => void;
16
19
  configUpdated: (namespace: string, name: string) => void;
17
20
  /** Profile settings changed — clear in-process caches in all services. */
18
21
  profileSettingsUpdated: (profileId: string) => void;
22
+ pollEnded: (post: PostWithMeta) => void;
19
23
  };
20
24
  export type CoreEventKey = keyof CoreEvents;
21
25
  export declare const VALID_EVENT_KEYS: CoreEventKey[];
@@ -16,6 +16,7 @@ const validEventKeyMap = {
16
16
  postAnnounced: true,
17
17
  configUpdated: true,
18
18
  profileSettingsUpdated: true,
19
+ pollEnded: true,
19
20
  };
20
21
  export const VALID_EVENT_KEYS = Object.keys(validEventKeyMap);
21
22
  let connectionPromise = undefined;
@@ -1,19 +1,17 @@
1
1
  import { queueAndWorker } from '../jobs/index.js';
2
2
  export const registeredHandlers = new Map();
3
3
  export const registerOnceHandler = (qualifiedEventType, handler) => {
4
- var _a;
5
4
  if (registeredHandlers.has(qualifiedEventType)) {
6
- (_a = registeredHandlers.get(qualifiedEventType)) === null || _a === void 0 ? void 0 : _a.push(handler);
5
+ registeredHandlers.get(qualifiedEventType)?.push(handler);
7
6
  }
8
7
  else {
9
8
  registeredHandlers.set(qualifiedEventType, [handler]);
10
9
  }
11
10
  };
12
11
  const [onceQueue, onceWorker] = queueAndWorker('once', async (job) => {
13
- var _a;
14
12
  const event = job.name;
15
13
  const args = job.data;
16
- return Promise.all(((_a = registeredHandlers.get(event)) !== null && _a !== void 0 ? _a : []).map((handler) => handler(...args)));
14
+ return Promise.all((registeredHandlers.get(event) ?? []).map((handler) => handler(...args)));
17
15
  }, {
18
16
  defaultJobOptions: {
19
17
  removeOnComplete: { age: 3600 }, // Remove successful tasks after 1 hour
@@ -0,0 +1,17 @@
1
+ export type ApActivityDirection = 'in' | 'out';
2
+ export type ApActivity = {
3
+ uri: string;
4
+ type: string;
5
+ actorUri: string;
6
+ objectUri?: string | null;
7
+ direction: ApActivityDirection;
8
+ };
9
+ export declare const recordApActivity: (activity: ApActivity) => Promise<void>;
10
+ export declare const findApActivityByUri: (uri: string) => Promise<{
11
+ uri: string;
12
+ type: string;
13
+ actorUri: string;
14
+ objectUri: string | null;
15
+ direction: string;
16
+ createdAt: string;
17
+ }>;
@@ -0,0 +1,25 @@
1
+ import { eq } from 'drizzle-orm';
2
+ import { pgDb } from '../db/pg/client.js';
3
+ import { apActivities } from '../db/pg/schema/documents.js';
4
+ export const recordApActivity = async (activity) => {
5
+ const db = pgDb();
6
+ await db
7
+ .insert(apActivities)
8
+ .values({
9
+ uri: activity.uri,
10
+ type: activity.type,
11
+ actorUri: activity.actorUri,
12
+ objectUri: activity.objectUri ?? null,
13
+ direction: activity.direction,
14
+ })
15
+ .onConflictDoNothing();
16
+ };
17
+ export const findApActivityByUri = async (uri) => {
18
+ const db = pgDb();
19
+ const [row] = await db
20
+ .select()
21
+ .from(apActivities)
22
+ .where(eq(apActivities.uri, uri))
23
+ .limit(1);
24
+ return row;
25
+ };
@@ -0,0 +1,16 @@
1
+ export declare const actorUri: (domain: string, profileId: string) => string;
2
+ export declare const objectUri: (domain: string, postId: string) => string;
3
+ export declare const generateActorKeyPair: () => import("crypto").KeyPairSyncResult<string, string>;
4
+ export declare const localActorScalars: (profileId: string, domain: string) => {
5
+ uri: string;
6
+ inboxUrl: string;
7
+ publicKeyPem: string;
8
+ privateKeyPem: string;
9
+ keyId: string;
10
+ };
11
+ export declare const localObjectScalars: (postId: string, domain: string, inReplyToId?: string | null) => {
12
+ uri: string;
13
+ inReplyToUri: string | null;
14
+ };
15
+ /** Fill actor/object URIs and local RSA keys after schema migrate. */
16
+ export declare const backfillLocalFederationIdentities: () => Promise<void>;
@@ -0,0 +1,52 @@
1
+ import { generateKeyPairSync } from 'node:crypto';
2
+ import { and, eq, isNull, sql } from 'drizzle-orm';
3
+ import { pgDb } from '../db/pg/client.js';
4
+ import { profiles } from '../db/pg/schema/documents.js';
5
+ export const actorUri = (domain, profileId) => `https://${domain}/ap/users/${profileId}`;
6
+ export const objectUri = (domain, postId) => `https://${domain}/ap/objects/${postId}`;
7
+ export const generateActorKeyPair = () => generateKeyPairSync('rsa', {
8
+ modulusLength: 2048,
9
+ publicKeyEncoding: { type: 'spki', format: 'pem' },
10
+ privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
11
+ });
12
+ export const localActorScalars = (profileId, domain) => {
13
+ const uri = actorUri(domain, profileId);
14
+ const keys = generateActorKeyPair();
15
+ return {
16
+ uri,
17
+ inboxUrl: `${uri}/inbox`,
18
+ publicKeyPem: keys.publicKey,
19
+ privateKeyPem: keys.privateKey,
20
+ keyId: `${uri}#main-key`,
21
+ };
22
+ };
23
+ export const localObjectScalars = (postId, domain, inReplyToId) => ({
24
+ uri: objectUri(domain, postId),
25
+ inReplyToUri: inReplyToId ? objectUri(domain, inReplyToId) : null,
26
+ });
27
+ const federationDomain = () => process.env.ACTIVITY_PUB_DEFAULT_DOMAIN || 'localhost';
28
+ /** Fill actor/object URIs and local RSA keys after schema migrate. */
29
+ export const backfillLocalFederationIdentities = async () => {
30
+ const db = pgDb();
31
+ const domain = federationDomain();
32
+ const locals = await db
33
+ .select({ id: profiles.id })
34
+ .from(profiles)
35
+ .where(and(eq(profiles.type, 'local'), isNull(profiles.uri), isNull(profiles.deletedAt)));
36
+ for (const row of locals) {
37
+ await db
38
+ .update(profiles)
39
+ .set(localActorScalars(row.id, domain))
40
+ .where(eq(profiles.id, row.id));
41
+ }
42
+ await db.execute(sql `UPDATE posts SET uri = ${`https://${domain}/ap/objects/`} || id::text WHERE uri IS NULL`);
43
+ await db.execute(sql `
44
+ UPDATE posts p
45
+ SET in_reply_to_uri = parent.uri
46
+ FROM reply_to rt
47
+ JOIN posts parent ON parent.id::text = rt.to_id
48
+ WHERE rt.from_id = p.id::text
49
+ AND p.in_reply_to_uri IS NULL
50
+ AND parent.uri IS NOT NULL
51
+ `);
52
+ };
@@ -0,0 +1,4 @@
1
+ export { findApActivityByUri, recordApActivity } from './activities';
2
+ export type { ApActivity, ApActivityDirection } from './activities';
3
+ export { actorUri, backfillLocalFederationIdentities, generateActorKeyPair, localActorScalars, localObjectScalars, objectUri, } from './identity';
4
+ export { findProfileByHandleAndDomain, findProfileByUri } from './profiles';
@@ -0,0 +1,3 @@
1
+ export { findApActivityByUri, recordApActivity } from './activities.js';
2
+ export { actorUri, backfillLocalFederationIdentities, generateActorKeyPair, localActorScalars, localObjectScalars, objectUri, } from './identity.js';
3
+ export { findProfileByHandleAndDomain, findProfileByUri } from './profiles.js';
@@ -0,0 +1,3 @@
1
+ import type { ProfileWithMeta } from '@openpeepshq/common/types';
2
+ export declare const findProfileByUri: (uri: string) => Promise<ProfileWithMeta | undefined>;
3
+ export declare const findProfileByHandleAndDomain: (handle: string, domain: string) => Promise<ProfileWithMeta | undefined>;
@@ -0,0 +1,14 @@
1
+ import { allpeepDb } from '../db/index.js';
2
+ import { profilesMapping } from '../profiles/mapping.js';
3
+ export const findProfileByUri = async (uri) => {
4
+ const { db } = await allpeepDb();
5
+ return profilesMapping.findOneBy(db, {
6
+ matches: { uri },
7
+ });
8
+ };
9
+ export const findProfileByHandleAndDomain = async (handle, domain) => {
10
+ const { db } = await allpeepDb();
11
+ return profilesMapping.findOneBy(db, {
12
+ matches: { handle, activityPub: { domain } },
13
+ });
14
+ };
@@ -107,10 +107,11 @@ export declare const listAdminGroups: () => Promise<{
107
107
  guestData?: {
108
108
  email?: string | undefined;
109
109
  resource?: {
110
- type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "webhooks" | "analytics" | "render";
110
+ type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "*" | "jams" | "webhooks" | "analytics" | "render";
111
111
  id?: string | undefined;
112
112
  } | undefined;
113
113
  } | undefined;
114
+ pinnedPostId?: string | undefined;
114
115
  deletedAt?: string | null | undefined;
115
116
  }[];
116
117
  avatar?: string | null | undefined;
@@ -43,6 +43,10 @@ export declare const addMember: (db: import("../db").PgDb, from: {
43
43
  locked?: boolean | undefined;
44
44
  bot?: boolean | undefined;
45
45
  discoverable?: boolean | undefined;
46
+ roles?: {
47
+ key: string;
48
+ displayName: string;
49
+ }[] | undefined;
46
50
  fields?: {
47
51
  name: string;
48
52
  value: string;
@@ -51,6 +55,8 @@ export declare const addMember: (db: import("../db").PgDb, from: {
51
55
  followersCount: number;
52
56
  followingCount: number;
53
57
  } | undefined;
58
+ pinnedPostId?: string | undefined;
59
+ blockedByMe?: boolean | undefined;
54
60
  }, to: {
55
61
  handle: string;
56
62
  capabilities: Record<string, {
@@ -123,6 +129,10 @@ export declare const removeMember: (db: import("../db").PgDb, from: {
123
129
  locked?: boolean | undefined;
124
130
  bot?: boolean | undefined;
125
131
  discoverable?: boolean | undefined;
132
+ roles?: {
133
+ key: string;
134
+ displayName: string;
135
+ }[] | undefined;
126
136
  fields?: {
127
137
  name: string;
128
138
  value: string;
@@ -131,6 +141,8 @@ export declare const removeMember: (db: import("../db").PgDb, from: {
131
141
  followersCount: number;
132
142
  followingCount: number;
133
143
  } | undefined;
144
+ pinnedPostId?: string | undefined;
145
+ blockedByMe?: boolean | undefined;
134
146
  }, to: {
135
147
  handle: string;
136
148
  capabilities: Record<string, {
@@ -194,6 +206,10 @@ export declare const updateMember: (db: import("../db").PgDb, from: {
194
206
  locked?: boolean | undefined;
195
207
  bot?: boolean | undefined;
196
208
  discoverable?: boolean | undefined;
209
+ roles?: {
210
+ key: string;
211
+ displayName: string;
212
+ }[] | undefined;
197
213
  fields?: {
198
214
  name: string;
199
215
  value: string;
@@ -202,6 +218,8 @@ export declare const updateMember: (db: import("../db").PgDb, from: {
202
218
  followersCount: number;
203
219
  followingCount: number;
204
220
  } | undefined;
221
+ pinnedPostId?: string | undefined;
222
+ blockedByMe?: boolean | undefined;
205
223
  }, to: {
206
224
  handle: string;
207
225
  capabilities: Record<string, {
@@ -6,8 +6,7 @@ export const addMember = connector(collectionInfos.profilesCollection, collectio
6
6
  export const removeMember = disconnector(collectionInfos.profilesCollection, collectionInfos.groupsCollection, collectionInfos.userGroupsCollection);
7
7
  export const updateMember = connectionUpdater(collectionInfos.profilesCollection, collectionInfos.groupsCollection, collectionInfos.userGroupsCollection);
8
8
  export const canSeeGroupFilter = (profile) => {
9
- var _a;
10
- if (checkRoleCapabilities((_a = profile === null || profile === void 0 ? void 0 : profile.roles) !== null && _a !== void 0 ? _a : [], ['core-groups-read']).success) {
9
+ if (checkRoleCapabilities(profile?.roles ?? [], ['core-groups-read']).success) {
11
10
  return undefined;
12
11
  }
13
12
  if (!profile || !isLocal(profile)) {
@@ -109,10 +109,11 @@ export declare const adminGroupsMapping: import("../db/pg/map").Mapping<{
109
109
  guestData?: {
110
110
  email?: string | undefined;
111
111
  resource?: {
112
- type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "webhooks" | "analytics" | "render";
112
+ type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "*" | "jams" | "webhooks" | "analytics" | "render";
113
113
  id?: string | undefined;
114
114
  } | undefined;
115
115
  } | undefined;
116
+ pinnedPostId?: string | undefined;
116
117
  deletedAt?: string | null | undefined;
117
118
  }[];
118
119
  avatar?: string | null | undefined;
@@ -170,10 +171,11 @@ export declare const adminGroupsMapping: import("../db/pg/map").Mapping<{
170
171
  guestData?: {
171
172
  email?: string | undefined;
172
173
  resource?: {
173
- type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "webhooks" | "analytics" | "render";
174
+ type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "*" | "jams" | "webhooks" | "analytics" | "render";
174
175
  id?: string | undefined;
175
176
  } | undefined;
176
177
  } | undefined;
178
+ pinnedPostId?: string | undefined;
177
179
  deletedAt?: string | null | undefined;
178
180
  }[];
179
181
  avatar?: string | null | undefined;
@@ -13,7 +13,7 @@ export const createGroup = async (groupData, profile, members = []) => {
13
13
  roles: ['owner'],
14
14
  });
15
15
  profilesCache.del(profile.id);
16
- const filteredMembers = members === null || members === void 0 ? void 0 : members.filter((member) => member.id !== profile.id);
16
+ const filteredMembers = members?.filter((member) => member.id !== profile.id);
17
17
  const uniqueMembers = filteredMembers
18
18
  ? Array.from(new Set(filteredMembers.map((m) => m.id))).map((id) => filteredMembers.find((m) => m.id === id))
19
19
  : [];
@@ -1,3 +1,6 @@
1
- export declare const findHashtag: (id: string) => Promise<import("@openpeepshq/common").Hashtag | undefined>;
2
- export declare const findHashtagByTag: (tag: string) => Promise<import("@openpeepshq/common").Hashtag | undefined>;
3
- export declare const findOrCreateHashtag: (tag: string) => Promise<import("@openpeepshq/common").Hashtag>;
1
+ import type { Hashtag, ProfileWithMeta } from '@openpeepshq/common/types';
2
+ export declare const findHashtag: (id: string) => Promise<Hashtag | undefined>;
3
+ export declare const findHashtagByTag: (tag: string) => Promise<Hashtag | undefined>;
4
+ export declare const findOrCreateHashtag: (tag: string) => Promise<Hashtag>;
5
+ export declare const listFollowedHashtags: (profile: ProfileWithMeta) => Hashtag[];
6
+ export declare const isFollowingHashtag: (profile: ProfileWithMeta, hashtag: Pick<Hashtag, "id">) => boolean;
@@ -20,3 +20,5 @@ export const findOrCreateHashtag = async (tag) => {
20
20
  }
21
21
  return hashtagsMapping.create(db, { tag: normalizedTag });
22
22
  };
23
+ export const listFollowedHashtags = (profile) => profile.followedHashtags ?? [];
24
+ export const isFollowingHashtag = (profile, hashtag) => profile.followedHashtags?.some((h) => h.id === hashtag.id) ?? false;
@@ -0,0 +1,8 @@
1
+ import type { Hashtag, Profile } from '@openpeepshq/common/types';
2
+ export declare const profileHashtagConnector: (db: import("../db").PgDb, from: Profile, to: Hashtag, data?: object & {
3
+ id?: string;
4
+ }) => Promise<import("../db/pg/map").WithId<object & {
5
+ _from: string;
6
+ _to: string;
7
+ }>>;
8
+ export declare const profileHashtagDisconnector: (db: import("../db").PgDb, from: Profile, to: Hashtag) => Promise<void>;
@@ -0,0 +1,4 @@
1
+ import { connector, disconnector } from '../db/helpers.js';
2
+ import { collectionInfos } from '../db/index.js';
3
+ export const profileHashtagConnector = connector(collectionInfos.profilesCollection, collectionInfos.hashtagsCollection, collectionInfos.profileHashtagsCollection);
4
+ export const profileHashtagDisconnector = disconnector(collectionInfos.profilesCollection, collectionInfos.hashtagsCollection, collectionInfos.profileHashtagsCollection);
@@ -1,2 +1,4 @@
1
1
  export * from './finders';
2
2
  export * from './mapping';
3
+ export * from './mutations';
4
+ export * from './helpers';
@@ -1,2 +1,4 @@
1
1
  export * from './finders.js';
2
2
  export * from './mapping.js';
3
+ export * from './mutations.js';
4
+ export * from './helpers.js';
@@ -0,0 +1,3 @@
1
+ import type { Hashtag, Profile } from '@openpeepshq/common/types';
2
+ export declare const followHashtag: (profile: Profile, hashtag: Hashtag) => Promise<void>;
3
+ export declare const unfollowHashtag: (profile: Profile, hashtag: Hashtag) => Promise<void>;
@@ -1 +1,13 @@
1
- "use strict";
1
+ import { allpeepDb } from '../db/index.js';
2
+ import { clearProfileCache } from '../profiles/cache.js';
3
+ import { profileHashtagConnector, profileHashtagDisconnector } from './helpers.js';
4
+ export const followHashtag = async (profile, hashtag) => {
5
+ const { db } = await allpeepDb();
6
+ await profileHashtagConnector(db, profile, hashtag);
7
+ await clearProfileCache(profile);
8
+ };
9
+ export const unfollowHashtag = async (profile, hashtag) => {
10
+ const { db } = await allpeepDb();
11
+ await profileHashtagDisconnector(db, profile, hashtag);
12
+ await clearProfileCache(profile);
13
+ };
@@ -1,5 +1,6 @@
1
1
  import type { Resource, ResourceLanguage } from 'i18next';
2
2
  import type { i18n } from 'i18next';
3
+ export { clearPluginLocales, mergeHostAndPluginLocales, registerPluginLocales, } from './pluginLocales';
3
4
  interface I18nContext {
4
5
  i18n: i18n;
5
6
  t: i18n['t'];
@@ -11,4 +12,3 @@ export declare const i18nWithPlugins: () => Promise<Resource>;
11
12
  export declare const i18nComplete: () => Promise<Resource>;
12
13
  export declare const updateI18nOverrides: (resources: Resource) => Promise<void>;
13
14
  export declare const initI18nEmailContext: (lng?: string) => Promise<I18nContext>;
14
- export {};
@@ -6,12 +6,14 @@ import { nowIso } from '../db/pg/mappers.js';
6
6
  import { uuidv7 } from 'uuidv7';
7
7
  import i18next from 'i18next';
8
8
  import Backend from 'i18next-fs-backend';
9
+ import { mergeHostAndPluginLocales, registeredPluginLocales, } from './pluginLocales.js';
10
+ export { clearPluginLocales, mergeHostAndPluginLocales, registerPluginLocales, } from './pluginLocales.js';
9
11
  const I18N_NAMESPACE = 'translation';
10
12
  export const i18nOverrides = () => allpeepDb().then(async ({ db }) => {
11
13
  const rows = await db.select().from(i18nEntries);
12
14
  return Object.fromEntries(rows.map((row) => [row.locale, row.body]));
13
15
  });
14
- export const i18nWithPlugins = async () => i18nextResources;
16
+ export const i18nWithPlugins = async () => mergeHostAndPluginLocales(i18nextResources, registeredPluginLocales());
15
17
  export const i18nComplete = async () => deepmerge(await i18nWithPlugins(), await i18nOverrides());
16
18
  export const updateI18nOverrides = async (resources) => allpeepDb().then(async ({ db }) => {
17
19
  const ts = nowIso();
@@ -0,0 +1,6 @@
1
+ import type { Resource } from 'i18next';
2
+ export declare const registerPluginLocales: (pluginKey: string, locales: Resource) => void;
3
+ export declare const clearPluginLocales: () => void;
4
+ export declare const registeredPluginLocales: () => Resource[];
5
+ /** Plugin packs first, host last so plugins cannot overwrite host strings. */
6
+ export declare const mergeHostAndPluginLocales: (host: Resource, pluginLocales: readonly Resource[]) => Resource;
@@ -0,0 +1,15 @@
1
+ import { deepmerge } from 'deepmerge-ts';
2
+ const pluginLocaleRegistry = new Map();
3
+ export const registerPluginLocales = (pluginKey, locales) => {
4
+ pluginLocaleRegistry.set(pluginKey, locales);
5
+ };
6
+ export const clearPluginLocales = () => {
7
+ pluginLocaleRegistry.clear();
8
+ };
9
+ export const registeredPluginLocales = () => [
10
+ ...pluginLocaleRegistry.values(),
11
+ ];
12
+ /** Plugin packs first, host last so plugins cannot overwrite host strings. */
13
+ export const mergeHostAndPluginLocales = (host, pluginLocales) => pluginLocales.length === 0
14
+ ? host
15
+ : deepmerge(...pluginLocales, host);