@openpeepshq/core 0.1.34 → 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 (165) 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 +13 -8
  6. package/dist/analytics/cache.js +3 -3
  7. package/dist/analytics/clicks.js +14 -22
  8. package/dist/analytics/compile.js +1 -2
  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 +116 -135
  14. package/dist/analytics/report.d.ts +2 -1
  15. package/dist/analytics/report.js +2 -3
  16. package/dist/analytics/settings.js +3 -4
  17. package/dist/backups/index.js +13 -16
  18. package/dist/backups/metadata.js +1 -1
  19. package/dist/config/db.js +2 -4
  20. package/dist/config/defaults/community.js +1 -0
  21. package/dist/config/defaults/core.js +13 -8
  22. package/dist/config/index.d.ts +1 -0
  23. package/dist/config/index.js +9 -11
  24. package/dist/db/explorer/query.js +9 -8
  25. package/dist/db/explorer/sql.js +8 -8
  26. package/dist/db/helpers.js +15 -5
  27. package/dist/db/migration/importCollections.js +15 -18
  28. package/dist/db/migration/shared.js +15 -35
  29. package/dist/db/pg/client.js +4 -7
  30. package/dist/db/pg/filters/index.js +1 -1
  31. package/dist/db/pg/filters/posts.d.ts +2 -0
  32. package/dist/db/pg/filters/posts.js +2 -0
  33. package/dist/db/pg/helpers.js +2 -14
  34. package/dist/db/pg/map/filters.js +8 -8
  35. package/dist/db/pg/map/helpers.js +5 -1
  36. package/dist/db/pg/map/index.js +46 -51
  37. package/dist/db/pg/map/mutations.js +56 -21
  38. package/dist/db/pg/map/registry.js +87 -50
  39. package/dist/db/pg/map/relations.js +67 -63
  40. package/dist/db/pg/map/search.js +15 -37
  41. package/dist/db/pg/mappers.js +13 -7
  42. package/dist/db/pg/migrate.js +2 -3
  43. package/dist/db/pg/queries/activity.js +2 -2
  44. package/dist/db/pg/queries/derived.js +8 -12
  45. package/dist/db/pg/schema/documents.js +119 -18
  46. package/dist/db/pg/schema/edges.js +7 -1
  47. package/dist/db/pg/schema/index.js +5 -1
  48. package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
  49. package/dist/db/pg/sql/meta/_journal.json +8 -1
  50. package/dist/db/replaceOrigin.js +1 -1
  51. package/dist/email/queueStats.js +8 -11
  52. package/dist/email/render.js +7 -4
  53. package/dist/email/send.js +19 -17
  54. package/dist/email/smtpTest.js +10 -6
  55. package/dist/errors/index.js +1 -1
  56. package/dist/events/once.js +2 -4
  57. package/dist/federation/activities.js +1 -2
  58. package/dist/groups/helpers.js +1 -2
  59. package/dist/groups/mutations.js +1 -1
  60. package/dist/hashtags/finders.js +2 -2
  61. package/dist/inviteLinks/mutations.js +2 -3
  62. package/dist/jams/export.js +5 -7
  63. package/dist/jams/finders.js +4 -1
  64. package/dist/jams/health.d.ts +6 -4
  65. package/dist/jams/health.js +15 -11
  66. package/dist/jams/helpers.js +6 -2
  67. package/dist/jams/index.js +2 -2
  68. package/dist/jams/jobs.js +1 -2
  69. package/dist/jams/livekit.js +8 -8
  70. package/dist/jams/recording.js +1 -1
  71. package/dist/jams/token.js +13 -17
  72. package/dist/jobs/index.js +7 -6
  73. package/dist/jobs/jobDetail.js +5 -6
  74. package/dist/jobs/jobLog.js +2 -3
  75. package/dist/lib/streams.js +4 -39
  76. package/dist/lib/zodDeepPartial.d.ts +1 -1
  77. package/dist/lib/zodDeepPartial.js +1 -1
  78. package/dist/log/index.js +13 -29
  79. package/dist/media/index.js +50 -4
  80. package/dist/media/jobs.js +1 -2
  81. package/dist/media/openpeeps/index.js +11 -46
  82. package/dist/media/processing.js +7 -4
  83. package/dist/media/streaming.js +5 -5
  84. package/dist/media/streamingCleanupJobs.js +1 -2
  85. package/dist/media/streamingJobs.js +3 -4
  86. package/dist/media/streamingPrewarm.js +7 -11
  87. package/dist/mediaAttachments/index.js +6 -2
  88. package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
  89. package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
  90. package/dist/notifications/defaultNotifications/follow/index.js +14 -17
  91. package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
  92. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
  93. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
  94. package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
  95. package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
  96. package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
  97. package/dist/notifications/defaultNotifications/mention/index.js +20 -24
  98. package/dist/notifications/defaultNotifications/newGroupPost/index.js +6 -7
  99. package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
  100. package/dist/notifications/defaultNotifications/pollEnded/index.js +21 -21
  101. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +2 -3
  102. package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
  103. package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
  104. package/dist/notifications/defaultNotifications/reply/index.js +21 -22
  105. package/dist/notifications/defaultNotifications/repost/index.js +16 -20
  106. package/dist/notifications/defaultNotifications/rsvp/index.js +24 -18
  107. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +20 -13
  108. package/dist/notifications/fcmCredential.js +1 -1
  109. package/dist/notifications/finders.js +1 -1
  110. package/dist/notifications/helpers.js +13 -10
  111. package/dist/notifications/jobs.js +10 -7
  112. package/dist/notifications/mutations.js +4 -1
  113. package/dist/notifications/push.js +11 -16
  114. package/dist/performance/index.js +3 -3
  115. package/dist/plugins/helpers.js +3 -6
  116. package/dist/plugins/index.js +2 -3
  117. package/dist/plugins/install.js +31 -17
  118. package/dist/plugins/pluginAuth.js +3 -4
  119. package/dist/plugins/state.js +2 -3
  120. package/dist/posts/activity.js +1 -2
  121. package/dist/posts/contextClosure.js +1 -2
  122. package/dist/posts/conversationQueries.js +2 -4
  123. package/dist/posts/eventAgenda.js +8 -5
  124. package/dist/posts/eventOccurrences.js +2 -2
  125. package/dist/posts/finders.d.ts +42 -2
  126. package/dist/posts/finders.js +21 -9
  127. package/dist/posts/helpers/filters.js +2 -3
  128. package/dist/posts/helpers/index.d.ts +152 -0
  129. package/dist/posts/helpers/index.js +43 -27
  130. package/dist/posts/mapping.d.ts +546 -14
  131. package/dist/posts/mapping.js +60 -18
  132. package/dist/posts/mutations.d.ts +76 -0
  133. package/dist/posts/mutations.js +46 -31
  134. package/dist/posts/pollEnd.js +3 -6
  135. package/dist/posts/rsvpConfirmationEmail.js +18 -8
  136. package/dist/posts/threadPreview.js +1 -1
  137. package/dist/processingStats/queries.js +6 -7
  138. package/dist/profileSettings/cache.js +1 -2
  139. package/dist/profiles/activitySummary.js +23 -28
  140. package/dist/profiles/cache.js +15 -8
  141. package/dist/profiles/export.js +30 -39
  142. package/dist/profiles/finders.js +7 -5
  143. package/dist/profiles/mutations.js +3 -5
  144. package/dist/redis/connection.js +1 -1
  145. package/dist/reports/helpers.js +7 -3
  146. package/dist/roles/mutations.js +20 -21
  147. package/dist/search/finders.js +15 -3
  148. package/dist/search/helpers.js +1 -1
  149. package/dist/sentry/index.js +9 -11
  150. package/dist/seo/index.d.ts +50 -0
  151. package/dist/seo/index.js +145 -0
  152. package/dist/seo/route.d.ts +18 -0
  153. package/dist/seo/route.js +19 -0
  154. package/dist/server/index.d.ts +1 -0
  155. package/dist/server/index.js +16 -11
  156. package/dist/server/status.js +6 -7
  157. package/dist/session/index.js +2 -2
  158. package/dist/stats/finders.js +13 -4
  159. package/dist/stats/helpers.js +4 -1
  160. package/dist/stats/mapping.d.ts +39 -1
  161. package/dist/stats/mapping.js +9 -2
  162. package/dist/stripe/cache.js +5 -6
  163. package/dist/stripe/connection.js +3 -4
  164. package/dist/stripe/helpers.js +15 -20
  165. package/package.json +5 -6
@@ -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,9 +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: Object.assign(Object.assign({}, notification), (profileSettings.timeZone
46
- ? { timeZone: profileSettings.timeZone }
47
- : {})),
44
+ locals: {
45
+ ...notification,
46
+ ...(profileSettings.timeZone
47
+ ? { timeZone: profileSettings.timeZone }
48
+ : {}),
49
+ },
48
50
  });
49
51
  await logStep(jobLog, log, `Queued email notification to ${account.email}`);
50
52
  }
@@ -54,8 +56,9 @@ const [notificationQueue, notificationWorker] = queueAndWorker('process-notifica
54
56
  }
55
57
  if (push) {
56
58
  try {
57
- const pushNotification = await ((_b = notificationHandlers
58
- .get(notification.type)) === null || _b === void 0 ? void 0 : _b.pushRenderer(notification));
59
+ const pushNotification = await notificationHandlers
60
+ .get(notification.type)
61
+ ?.pushRenderer(notification);
59
62
  if (pushNotification && !sessionPublished) {
60
63
  sessionPublished = true;
61
64
  await publishSessionEvent(profile.id, {
@@ -36,7 +36,10 @@ export const maybeCreateNotification = async (profile, data) => {
36
36
  }
37
37
  const settings = notificationSettings(profileSettings, type);
38
38
  if (settings.create) {
39
- const notificationData = Object.assign(Object.assign({}, data), { profileId: profile.id });
39
+ const notificationData = {
40
+ ...data,
41
+ profileId: profile.id,
42
+ };
40
43
  const notification = await allpeepDb().then(({ db }) => notificationsMapping.create(db, notificationData));
41
44
  const expandedNotification = await expandNotification(notification);
42
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'));
@@ -50,9 +50,8 @@ export const initializePlugins = async () => {
50
50
  log.error(e, 'Plugin self-heal failed; continuing without it.');
51
51
  }
52
52
  const loadPlugin = async (key, info, pluginPath) => {
53
- var _a, _b;
54
53
  const [namespace, name] = key.split('/');
55
- 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'
56
55
  ? info.config.displayName
57
56
  : key;
58
57
  const plugin = {
@@ -65,7 +64,7 @@ export const initializePlugins = async () => {
65
64
  // DB override (set via the admin toggle) takes precedence over the
66
65
  // static `openpeeps.enabled` package.json gate; a missing override
67
66
  // falls back to the static gate.
68
- const enabled = (_b = stateOverrides[key]) !== null && _b !== void 0 ? _b : isPluginEnabled(info);
67
+ const enabled = stateOverrides[key] ?? isPluginEnabled(info);
69
68
  if (!enabled) {
70
69
  log.info(`Skipping disabled plugin "${displayName}" (key: ${key}).`);
71
70
  plugin.status = 'disabled';
@@ -11,21 +11,23 @@ import { eq } from 'drizzle-orm';
11
11
  import { setPluginEnabledOverride } from './state.js';
12
12
  const log = logger('core:plugins:install');
13
13
  const requireFromHost = createRequire(new URL('../../package.json', import.meta.url));
14
- const MAX_COMMAND_OUTPUT = 16000;
14
+ const MAX_COMMAND_OUTPUT = 16_000;
15
15
  const INSTALLED_PLUGINS_KEY = 'openpeeps-installed-plugins';
16
16
  export const getInstalledPlugins = async () => {
17
- var _a, _b;
18
17
  const { db } = await allpeepDb();
19
18
  const rows = await db
20
19
  .select()
21
20
  .from(configs)
22
21
  .where(eq(configs.key, INSTALLED_PLUGINS_KEY))
23
22
  .limit(1);
24
- return (_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.body) !== null && _b !== void 0 ? _b : {};
23
+ return rows[0]?.body ?? {};
25
24
  };
26
25
  const setInstalledPlugin = async (pluginKey, source, requiresAuth, installedBy) => {
27
26
  const installed = await getInstalledPlugins();
28
- const body = Object.assign(Object.assign({}, installed), { [pluginKey]: { source, requiresAuth, installedAt: nowIso(), installedBy } });
27
+ const body = {
28
+ ...installed,
29
+ [pluginKey]: { source, requiresAuth, installedAt: nowIso(), installedBy },
30
+ };
29
31
  const ts = nowIso();
30
32
  const { db } = await allpeepDb();
31
33
  await db
@@ -57,7 +59,17 @@ const removeInstalledPlugin = async (pluginKey) => {
57
59
  const runCommand = (command, args, cwd, environment = {}) => new Promise((resolve) => {
58
60
  const child = spawn(command, args, {
59
61
  cwd,
60
- env: Object.assign({ HOME: process.env.HOME, LANG: process.env.LANG, LC_ALL: process.env.LC_ALL, NODE_EXTRA_CA_CERTS: process.env.NODE_EXTRA_CA_CERTS, PATH: process.env.PATH, SSL_CERT_DIR: process.env.SSL_CERT_DIR, SSL_CERT_FILE: process.env.SSL_CERT_FILE, TMPDIR: process.env.TMPDIR }, environment),
62
+ env: {
63
+ HOME: process.env.HOME,
64
+ LANG: process.env.LANG,
65
+ LC_ALL: process.env.LC_ALL,
66
+ NODE_EXTRA_CA_CERTS: process.env.NODE_EXTRA_CA_CERTS,
67
+ PATH: process.env.PATH,
68
+ SSL_CERT_DIR: process.env.SSL_CERT_DIR,
69
+ SSL_CERT_FILE: process.env.SSL_CERT_FILE,
70
+ TMPDIR: process.env.TMPDIR,
71
+ ...environment,
72
+ },
61
73
  shell: false,
62
74
  });
63
75
  let stdout = '';
@@ -69,7 +81,7 @@ const runCommand = (command, args, cwd, environment = {}) => new Promise((resolv
69
81
  stderr += chunk.toString();
70
82
  });
71
83
  child.on('close', (exitCode) => {
72
- resolve({ exitCode: exitCode !== null && exitCode !== void 0 ? exitCode : 1, stdout, stderr });
84
+ resolve({ exitCode: exitCode ?? 1, stdout, stderr });
73
85
  });
74
86
  child.on('error', (err) => {
75
87
  resolve({ exitCode: 1, stdout, stderr: String(err) });
@@ -157,7 +169,7 @@ const resolveHostPackage = async (name) => {
157
169
  return current;
158
170
  }
159
171
  }
160
- catch (_a) {
172
+ catch {
161
173
  // Keep walking toward the filesystem root.
162
174
  }
163
175
  const parent = path.dirname(current);
@@ -173,7 +185,7 @@ export const linkHostPeerDependencies = async (installDir, names) => {
173
185
  try {
174
186
  resolved = await resolveHostPackage(name);
175
187
  }
176
- catch (_a) {
188
+ catch {
177
189
  return {
178
190
  success: false,
179
191
  error: `Host does not provide peer dependency "${name}".`,
@@ -187,11 +199,10 @@ export const linkHostPeerDependencies = async (installDir, names) => {
187
199
  return { success: true };
188
200
  };
189
201
  const writeNpmConfig = async (tempDir, auth) => {
190
- var _a;
191
202
  if (!auth) {
192
203
  return {};
193
204
  }
194
- const registry = new URL((_a = auth.registry) !== null && _a !== void 0 ? _a : 'https://registry.npmjs.org/');
205
+ const registry = new URL(auth.registry ?? 'https://registry.npmjs.org/');
195
206
  const registryUrl = registry.toString().replace(/\/?$/, '/');
196
207
  const authPath = registry.pathname.replace(/\/?$/, '/');
197
208
  const configPath = path.join(tempDir, '.npmrc');
@@ -245,7 +256,6 @@ const writeGitAuth = async (tempDir, auth) => {
245
256
  };
246
257
  };
247
258
  export const installPlugin = async (source, installedBy, options) => {
248
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
249
259
  const pluginsDir = await getPluginDir();
250
260
  const label = sourceLabel(source);
251
261
  const secrets = sourceSecrets(source);
@@ -300,8 +310,13 @@ export const installPlugin = async (source, installedBy, options) => {
300
310
  // Read package.json to determine namespace/name
301
311
  const pkgJsonRaw = await fs.readFile(path.join(installDir, 'package.json'), 'utf-8');
302
312
  const pkgJson = JSON.parse(pkgJsonRaw);
303
- const namespace = (_e = (_b = (_a = pkgJson.openpeeps) === null || _a === void 0 ? void 0 : _a.namespace) !== null && _b !== void 0 ? _b : (_d = (_c = pkgJson.name) === null || _c === void 0 ? void 0 : _c.split('/')[0]) === null || _d === void 0 ? void 0 : _d.replace(/^@/, '')) !== null && _e !== void 0 ? _e : 'custom';
304
- const name = (_l = (_j = (_g = (_f = pkgJson.openpeeps) === null || _f === void 0 ? void 0 : _f.name) !== null && _g !== void 0 ? _g : (_h = pkgJson.name) === null || _h === void 0 ? void 0 : _h.split('/')[1]) !== null && _j !== void 0 ? _j : (_k = pkgJson.name) === null || _k === void 0 ? void 0 : _k.replace(/^@[^/]+\//, '')) !== null && _l !== void 0 ? _l : 'plugin';
313
+ const namespace = pkgJson.openpeeps?.namespace ??
314
+ pkgJson.name?.split('/')[0]?.replace(/^@/, '') ??
315
+ 'custom';
316
+ const name = pkgJson.openpeeps?.name ??
317
+ pkgJson.name?.split('/')[1] ??
318
+ pkgJson.name?.replace(/^@[^/]+\//, '') ??
319
+ 'plugin';
305
320
  const pluginKey = `${namespace}/${name}`;
306
321
  const destDir = path.join(pluginsDir, namespace, name);
307
322
  // Check if already exists in the plugins dir (built-in)
@@ -324,7 +339,7 @@ export const installPlugin = async (source, installedBy, options) => {
324
339
  }
325
340
  }
326
341
  // Build the plugin if it has a build script
327
- if ((_m = pkgJson.scripts) === null || _m === void 0 ? void 0 : _m.build) {
342
+ if (pkgJson.scripts?.build) {
328
343
  log.info(`Building plugin ${pluginKey}...`);
329
344
  const buildDeps = await runCommand('npm', ['install', '--omit=peer'], installDir, npmEnvironment);
330
345
  if (buildDeps.exitCode !== 0) {
@@ -356,7 +371,7 @@ export const installPlugin = async (source, installedBy, options) => {
356
371
  await fs.rm(destDir, { recursive: true, force: true });
357
372
  await fs.cp(installDir, destDir, { recursive: true });
358
373
  await setInstalledPlugin(pluginKey, label, secrets.length > 0, installedBy);
359
- if (options === null || options === void 0 ? void 0 : options.selfHeal) {
374
+ if (options?.selfHeal) {
360
375
  // Re-downloading an already-reviewed plugin keeps its enabled state.
361
376
  log.info(`Self-healed plugin ${pluginKey} (re-downloaded from ${label}).`);
362
377
  }
@@ -409,7 +424,6 @@ export const uninstallPlugin = async (pluginKey, uninstalledBy) => {
409
424
  * still unavailable after the attempt.
410
425
  */
411
426
  export const selfHealInstalledPlugins = async () => {
412
- var _a;
413
427
  const installed = await getInstalledPlugins();
414
428
  const pluginsDir = await getPluginDir();
415
429
  const failures = {};
@@ -438,7 +452,7 @@ export const selfHealInstalledPlugins = async () => {
438
452
  selfHeal: true,
439
453
  });
440
454
  if (!result.success) {
441
- log.error(new Error((_a = result.error) !== null && _a !== void 0 ? _a : 'unknown error'), `Self-heal failed for plugin ${pluginKey}.`);
455
+ log.error(new Error(result.error ?? 'unknown error'), `Self-heal failed for plugin ${pluginKey}.`);
442
456
  failures[pluginKey] = `Automatic re-download failed: ${result.error}`;
443
457
  }
444
458
  }
@@ -17,7 +17,6 @@ import { jwtUtil } from '../jwt/index.js';
17
17
  * stronger guarantees or the handle should perform their own lookup.
18
18
  */
19
19
  export const ensurePluginAuth = () => async (req, res, next) => {
20
- var _a;
21
20
  // Express 5's RequestHandler type requires `void | Promise<void>` — never
22
21
  // `return res...`, which types as `Promise<Response>` and fails overload
23
22
  // resolution wherever this middleware is passed to router.post/get/etc.
@@ -34,15 +33,15 @@ export const ensurePluginAuth = () => async (req, res, next) => {
34
33
  try {
35
34
  const jwt = await jwtUtil();
36
35
  const verified = await jwt.verify(token);
37
- const payload = verified === null || verified === void 0 ? void 0 : verified.payload;
38
- if (!((_a = payload === null || payload === void 0 ? void 0 : payload.identities) === null || _a === void 0 ? void 0 : _a.profile)) {
36
+ const payload = verified?.payload;
37
+ if (!payload?.identities?.profile) {
39
38
  res.status(401).json({ success: false, message: 'Invalid token' });
40
39
  return;
41
40
  }
42
41
  req.pluginProfile = { id: payload.identities.profile };
43
42
  next();
44
43
  }
45
- catch (_b) {
44
+ catch {
46
45
  res.status(401).json({ success: false, message: 'Unauthorized' });
47
46
  }
48
47
  };
@@ -8,16 +8,15 @@ import { nowIso } from '../db/pg/mappers.js';
8
8
  // one — this is a small, boot-time-read key/value document, not a relation.
9
9
  const PLUGIN_STATE_KEY = 'openpeeps-plugin-state';
10
10
  export const getPluginStateOverrides = () => allpeepDb().then(async ({ db }) => {
11
- var _a, _b;
12
11
  const rows = await db
13
12
  .select()
14
13
  .from(configs)
15
14
  .where(eq(configs.key, PLUGIN_STATE_KEY))
16
15
  .limit(1);
17
- return (_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.body) !== null && _b !== void 0 ? _b : {};
16
+ return rows[0]?.body ?? {};
18
17
  });
19
18
  export const setPluginEnabledOverride = (pluginKey, enabled) => getPluginStateOverrides().then((overrides) => {
20
- const body = Object.assign(Object.assign({}, overrides), { [pluginKey]: enabled });
19
+ const body = { ...overrides, [pluginKey]: enabled };
21
20
  const ts = nowIso();
22
21
  return allpeepDb().then(({ db }) => db
23
22
  .insert(configs)
@@ -3,7 +3,6 @@ import { sql } from 'drizzle-orm';
3
3
  * Walk outbound `reply_to` until there is no parent. A root post is itself.
4
4
  */
5
5
  export const findReplyRootId = async (db, postId) => {
6
- var _a, _b;
7
6
  const result = (await db.execute(sql `
8
7
  WITH RECURSIVE walk AS (
9
8
  SELECT ${postId}::text AS node_id, 0 AS depth
@@ -18,7 +17,7 @@ export const findReplyRootId = async (db, postId) => {
18
17
  ORDER BY depth DESC
19
18
  LIMIT 1
20
19
  `));
21
- return (_b = (_a = result.rows[0]) === null || _a === void 0 ? void 0 : _a.node_id) !== null && _b !== void 0 ? _b : postId;
20
+ return result.rows[0]?.node_id ?? postId;
22
21
  };
23
22
  /** Bump conversation ordering without changing `created_at` or `updated_at`. */
24
23
  export const touchPostActivity = async (db, postId) => {
@@ -8,7 +8,6 @@ import { CONTEXT_NODE_CAP, collectReplyClosureIds } from './replyClosure.js';
8
8
  export { CONTEXT_NODE_CAP, collectReplyClosureIds } from './replyClosure.js';
9
9
  /** Load and hydrate posts in a reply closure, then ACL-filter + transform. */
10
10
  export const loadReplyContextPosts = async (authData, startId, direction, mapping, { maxDepth = 9999, limit = CONTEXT_NODE_CAP, } = {}) => {
11
- var _a, _b;
12
11
  const { db } = await allpeepDb();
13
12
  const mapData = mapping.data();
14
13
  const ids = await collectReplyClosureIds(db, startId, direction, {
@@ -28,7 +27,7 @@ export const loadReplyContextPosts = async (authData, startId, direction, mappin
28
27
  const transformed = await transformPost(post, authData.profile, {
29
28
  embedThreadPreview: false,
30
29
  });
31
- const creatorId = (_a = transformed.creatorId) !== null && _a !== void 0 ? _a : (_b = transformed.profile) === null || _b === void 0 ? void 0 : _b.id;
30
+ const creatorId = transformed.creatorId ?? transformed.profile?.id;
32
31
  if (creatorId && pair.has(creatorId)) {
33
32
  if (direction === 'descendents') {
34
33
  posts.push(toHiddenPost(transformed));
@@ -55,7 +55,6 @@ export const listConversationRootLeafPairs = async (db, profileId) => {
55
55
  };
56
56
  /** Newest post id in a reply thread (root included); uuidv7-ordered. */
57
57
  export const findLatestThreadPostId = async (rootId) => {
58
- var _a, _b;
59
58
  const { db } = await allpeepDb();
60
59
  const result = (await db.execute(sql `
61
60
  WITH RECURSIVE t AS (
@@ -73,10 +72,9 @@ export const findLatestThreadPostId = async (rootId) => {
73
72
  ORDER BY id DESC
74
73
  LIMIT 1
75
74
  `));
76
- return (_b = (_a = result.rows[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : rootId;
75
+ return result.rows[0]?.id ?? rootId;
77
76
  };
78
77
  const hydrateLeanPostsByIds = async (authData, ids) => {
79
- var _a, _b;
80
78
  if (!ids.length)
81
79
  return new Map();
82
80
  const { db } = await allpeepDb();
@@ -91,7 +89,7 @@ const hydrateLeanPostsByIds = async (authData, ids) => {
91
89
  const transformed = await transformPost(post, authData.profile, {
92
90
  embedThreadPreview: false,
93
91
  });
94
- const creatorId = (_a = transformed.creatorId) !== null && _a !== void 0 ? _a : (_b = transformed.profile) === null || _b === void 0 ? void 0 : _b.id;
92
+ const creatorId = transformed.creatorId ?? transformed.profile?.id;
95
93
  if (creatorId && pair.has(creatorId)) {
96
94
  byId.set(transformed.id, toHiddenPost(transformed));
97
95
  continue;
@@ -39,7 +39,7 @@ const eventAgendaConditions = ({ window, now, jamOnly, mine, groupId, profileId,
39
39
  if (groupId) {
40
40
  conditions.push(sql `EXISTS (SELECT 1 FROM ${postGroups} WHERE ${postGroups.fromId} = ${posts.id}::text AND ${postGroups.toId} = ${groupId})`);
41
41
  }
42
- if (excludeCreatorIds === null || excludeCreatorIds === void 0 ? void 0 : excludeCreatorIds.length) {
42
+ if (excludeCreatorIds?.length) {
43
43
  conditions.push(notInArray(posts.creatorId, excludeCreatorIds));
44
44
  }
45
45
  return conditions;
@@ -94,7 +94,6 @@ const loadPostsByIds = async (ids, authData) => {
94
94
  .map((post) => [post.id, post]));
95
95
  };
96
96
  export const listEventAgenda = async (authData, window, { offset = 0, limit = 100, jamOnly = false, mine = false, groupId, } = {}) => {
97
- var _a;
98
97
  const { db } = await allpeepDb();
99
98
  const now = new Date().toISOString();
100
99
  const rows = await eventAgendaOccurrenceQuery(db, {
@@ -105,7 +104,7 @@ export const listEventAgenda = async (authData, window, { offset = 0, limit = 10
105
104
  jamOnly,
106
105
  mine,
107
106
  groupId,
108
- profileId: (_a = authData.profile) === null || _a === void 0 ? void 0 : _a.id,
107
+ profileId: authData.profile?.id,
109
108
  excludeCreatorIds: blockedPairIds(authData.profile),
110
109
  });
111
110
  const postsById = await loadPostsByIds([...new Set(rows.map((row) => row.postId))], authData);
@@ -119,8 +118,12 @@ export const listEventAgenda = async (authData, window, { offset = 0, limit = 10
119
118
  if (!occurrenceRecurrenceId || !occurrenceStart)
120
119
  return [];
121
120
  return [
122
- Object.assign(Object.assign(Object.assign({}, post), { occurrenceRecurrenceId,
123
- occurrenceStart }), (occurrenceEnd ? { occurrenceEnd } : {})),
121
+ {
122
+ ...post,
123
+ occurrenceRecurrenceId,
124
+ occurrenceStart,
125
+ ...(occurrenceEnd ? { occurrenceEnd } : {}),
126
+ },
124
127
  ];
125
128
  });
126
129
  };
@@ -36,7 +36,7 @@ export const backfillMissingEventOccurrences = async () => {
36
36
  let rebuilt = 0;
37
37
  for (const row of rows) {
38
38
  const event = row.body;
39
- if ((event === null || event === void 0 ? void 0 : event.type) !== 'event' || !event.start)
39
+ if (event?.type !== 'event' || !event.start)
40
40
  continue;
41
41
  await rebuildEventOccurrences(row.id, event);
42
42
  rebuilt += 1;
@@ -52,7 +52,7 @@ export const rebuildRecurringEventOccurrences = async () => {
52
52
  let rebuilt = 0;
53
53
  for (const row of rows) {
54
54
  const event = row.body;
55
- if ((event === null || event === void 0 ? void 0 : event.type) !== 'event' || !event.start)
55
+ if (event?.type !== 'event' || !event.start)
56
56
  continue;
57
57
  await rebuildEventOccurrences(row.id, event);
58
58
  rebuilt += 1;