@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
@@ -14,19 +14,18 @@ export const isServiceAccessToken = (token) => {
14
14
  const parsed = authorizationSchema.safeParse(payload);
15
15
  return parsed.success && !!parsed.data.identities.service;
16
16
  }
17
- catch (_a) {
17
+ catch {
18
18
  return false;
19
19
  }
20
20
  };
21
21
  const withCachedOwnerAndScopes = async (token) => {
22
- var _a;
23
- const ownerId = (_a = token.ownedBy) === null || _a === void 0 ? void 0 : _a.id;
22
+ const ownerId = token.ownedBy?.id;
24
23
  const scopes = parseScopesFromJwt(token.signedToken);
25
24
  if (!ownerId) {
26
- return Object.assign(Object.assign({}, token), { ownedBy: undefined, scopes });
25
+ return { ...token, ownedBy: undefined, scopes };
27
26
  }
28
27
  const owner = await getProfile(ownerId);
29
- return Object.assign(Object.assign({}, token), { ownedBy: owner, scopes });
28
+ return { ...token, ownedBy: owner, scopes };
30
29
  };
31
30
  export const findAccessToken = (id) => allpeepDb().then(({ db }) => accessTokensMapping
32
31
  .find(db, id)
@@ -40,4 +39,4 @@ export const listAccessTokensForProfile = (profile) => allpeepDb().then(async ({
40
39
  .all(db)
41
40
  .then((tokens) => Promise.all(tokens.map(withCachedOwnerAndScopes))));
42
41
  export const listServiceAccessTokens = () => listAccessTokens().then((tokens) => tokens.filter(isServiceAccessToken));
43
- export const isRevoked = async (id) => { var _a; return (await isMaybeRevoked(id)) && !!((_a = (await findAccessToken(id))) === null || _a === void 0 ? void 0 : _a.revokedAt); };
42
+ export const isRevoked = async (id) => (await isMaybeRevoked(id)) && !!(await findAccessToken(id))?.revokedAt;
@@ -5,7 +5,7 @@ import { uuidv7 } from 'uuidv7';
5
5
  import { addToBloomFilter } from './revokations.js';
6
6
  export const createAccessToken = (profile, data) => allpeepDb().then(async ({ db }) => {
7
7
  const id = uuidv7();
8
- const accessToken = await accessTokensMapping.create(db, Object.assign(Object.assign({}, data), { id }));
8
+ const accessToken = await accessTokensMapping.create(db, { ...data, id });
9
9
  if (profile) {
10
10
  await profileAccessTokenConnector(db, profile, accessToken);
11
11
  }
@@ -8,8 +8,7 @@ import { createAccessToken, revokeAccessToken } from './mutations.js';
8
8
  export const verifySignedAccessToken = (token) => jwtUtil()
9
9
  .then((jwt) => jwt.verify(token))
10
10
  .then(async (result) => {
11
- var _a;
12
- if (!((_a = result === null || result === void 0 ? void 0 : result.payload) === null || _a === void 0 ? void 0 : _a.jti)) {
11
+ if (!result?.payload?.jti) {
13
12
  return undefined;
14
13
  }
15
14
  const id = result.payload.jti;
@@ -19,7 +18,6 @@ export const verifySignedAccessToken = (token) => jwtUtil()
19
18
  return result.payload;
20
19
  });
21
20
  export const createSignedAccessToken = async ({ profile, authorization, name, description, expirationTime, }) => {
22
- var _a;
23
21
  const id = uuidv7();
24
22
  const jwt = await jwtUtil();
25
23
  const signedToken = await jwt.sign({
@@ -28,7 +26,7 @@ export const createSignedAccessToken = async ({ profile, authorization, name, de
28
26
  id,
29
27
  });
30
28
  const result = await jwt.verify(signedToken);
31
- if (!((_a = result === null || result === void 0 ? void 0 : result.payload) === null || _a === void 0 ? void 0 : _a.exp)) {
29
+ if (!result?.payload?.exp) {
32
30
  throw new Error('Failed to verify signed token');
33
31
  }
34
32
  const expiresAt = new Date(result.payload.exp * 1000).toISOString();
@@ -42,8 +40,8 @@ export const createSignedAccessToken = async ({ profile, authorization, name, de
42
40
  export const createSignedProfileAccessToken = async ({ profile, account, name, description, scopes = [{ scopeLevel: 'admin', resource: { type: '*', id: '*' } }], expirationTime = '1y', }) => {
43
41
  const authorization = {
44
42
  identities: {
45
- profile: profile === null || profile === void 0 ? void 0 : profile.id,
46
- account: account === null || account === void 0 ? void 0 : account.id,
43
+ profile: profile?.id,
44
+ account: account?.id,
47
45
  },
48
46
  scopes,
49
47
  };
@@ -67,8 +65,7 @@ export const createSignedServiceToken = async ({ scopes, name, description, expi
67
65
  expirationTime,
68
66
  });
69
67
  export const createSignedGuestPass = async (profile, expirationTime = '1d') => {
70
- var _a;
71
- if (!((_a = profile.guestData) === null || _a === void 0 ? void 0 : _a.resource)) {
68
+ if (!profile.guestData?.resource) {
72
69
  throw new Error('Guest pass requires a resource');
73
70
  }
74
71
  const resource = profile.guestData.resource;
@@ -122,8 +119,8 @@ export const createSignedDbToken = (profile) => createSignedAccessToken({
122
119
  export const refreshSignedAccessToken = async (token) => {
123
120
  const jwt = await jwtUtil();
124
121
  const verified = await jwt.verify(token);
125
- const rawPayload = verified === null || verified === void 0 ? void 0 : verified.payload;
126
- if (!(rawPayload === null || rawPayload === void 0 ? void 0 : rawPayload.jti) || typeof rawPayload.jti !== 'string') {
122
+ const rawPayload = verified?.payload;
123
+ if (!rawPayload?.jti || typeof rawPayload.jti !== 'string') {
127
124
  return undefined;
128
125
  }
129
126
  const jti = rawPayload.jti;
@@ -138,7 +135,7 @@ export const refreshSignedAccessToken = async (token) => {
138
135
  }
139
136
  const authorization = authParsed.data;
140
137
  const existing = await findAccessToken(jti);
141
- if (!(existing === null || existing === void 0 ? void 0 : existing.signedToken) || existing.revokedAt) {
138
+ if (!existing?.signedToken || existing.revokedAt) {
142
139
  return undefined;
143
140
  }
144
141
  if (authorization.identities.profile) {
@@ -5,7 +5,7 @@ import { logger } from '../log/index.js';
5
5
  import { getProfiles } from '../profiles/cache.js';
6
6
  import { uuidv7 } from 'uuidv7';
7
7
  export const log = logger('core:accounts');
8
- export const normalizeEmailAddress = (email) => email === null || email === void 0 ? void 0 : email.toLowerCase();
8
+ export const normalizeEmailAddress = (email) => email?.toLowerCase();
9
9
  export const createEmailValidationToken = async (account) => {
10
10
  return jwtUtil().then((jwt) => jwt.sign({
11
11
  payload: { email: account.email },
@@ -33,4 +33,8 @@ export const sendEmailValidationMail = async (account) => {
33
33
  });
34
34
  };
35
35
  export const expandAccount = async (account) => account
36
- ? Object.assign(Object.assign({}, account), { profiles: await getProfiles(account.profiles.map((p) => p.id)) }) : undefined;
36
+ ? {
37
+ ...account,
38
+ profiles: await getProfiles(account.profiles.map((p) => p.id)),
39
+ }
40
+ : undefined;
@@ -10,6 +10,8 @@ import { assignRole, unassignRole } from '../profiles/mutations.js';
10
10
  import { hash } from 'bcrypt';
11
11
  import { profilesMapping } from '../profiles/mapping.js';
12
12
  import { assertProfileCapacity } from '../profiles/capacity.js';
13
+ import { localActorScalars } from '../federation/identity.js';
14
+ import { uuidv7 } from 'uuidv7';
13
15
  import { findRoleByKey } from '../roles/index.js';
14
16
  import { log, normalizeEmailAddress, sendEmailValidationMail, sendWelcomeEmail, } from './helpers.js';
15
17
  import { findAccountByEmail } from './finders.js';
@@ -19,6 +21,26 @@ import { conflict } from '../errors/index.js';
19
21
  import { connector } from '../db/helpers.js';
20
22
  import { hub } from '../events/index.js';
21
23
  import { deletePushSubscription, listPushSubscriptionsByAccount, } from '../pushSubscriptions/index.js';
24
+ const applyCommunityRoleChanges = async (profile, changes) => {
25
+ for (const roleKey of changes.add) {
26
+ const role = await findRoleByKey(roleKey);
27
+ if (role) {
28
+ await assignRole(profile, role);
29
+ }
30
+ else {
31
+ log.error(`Role ${roleKey} missing`);
32
+ }
33
+ }
34
+ for (const roleKey of changes.remove) {
35
+ const role = await findRoleByKey(roleKey);
36
+ if (role) {
37
+ await unassignRole(profile, role);
38
+ }
39
+ else {
40
+ log.error(`Role ${roleKey} missing`);
41
+ }
42
+ }
43
+ };
22
44
  export const createAccount = async (accountCreationData) => {
23
45
  const { db } = await allpeepDb();
24
46
  const coreConfig = await config();
@@ -57,15 +79,19 @@ export const createAccount = async (accountCreationData) => {
57
79
  let profile;
58
80
  if (accountCreationData.profile) {
59
81
  await assertProfileCapacity();
60
- const { handle, displayName, avatar } = accountCreationData.profile;
82
+ const { handle, displayName, avatar, bot } = accountCreationData.profile;
83
+ const profileId = uuidv7();
61
84
  profile = await profilesMapping.create(db, {
85
+ id: profileId,
62
86
  handle,
63
87
  displayName,
64
88
  avatar,
89
+ ...(bot === true ? { bot: true } : {}),
65
90
  activityPub: {
66
91
  domain: coreConfig.activityPub.defaultDomain,
67
92
  },
68
93
  type: 'local',
94
+ ...localActorScalars(profileId, coreConfig.activityPub.defaultDomain),
69
95
  });
70
96
  if (firstAccount && profile) {
71
97
  const ownerRole = await findRoleByKey('owner');
@@ -78,15 +104,11 @@ export const createAccount = async (accountCreationData) => {
78
104
  }
79
105
  else {
80
106
  await hub.emit('profileCreated', profile);
81
- const registrationRoleKeys = communityConf.roles.onRegistration.add;
82
- for (const roleKey of registrationRoleKeys) {
83
- const role = await findRoleByKey(roleKey);
84
- if (role) {
85
- await assignRole(profile, role);
86
- }
87
- else {
88
- log.error(`Role ${roleKey} missing`);
89
- }
107
+ await applyCommunityRoleChanges(profile, communityConf.roles.onRegistration);
108
+ // Authorized/SSO creates skip the validation email, so apply the
109
+ // same promotion humans get after confirming.
110
+ if (emailValidated) {
111
+ await applyCommunityRoleChanges(profile, communityConf.roles.onEmailValidation);
90
112
  }
91
113
  }
92
114
  if (inviteCode) {
@@ -112,9 +134,8 @@ export const createAccount = async (accountCreationData) => {
112
134
  return { account, profile };
113
135
  };
114
136
  export const updateAccount = async (accountData) => {
115
- var _a;
116
137
  const { db } = await allpeepDb();
117
- if (!((_a = accountData === null || accountData === void 0 ? void 0 : accountData.account) === null || _a === void 0 ? void 0 : _a.id)) {
138
+ if (!accountData?.account?.id) {
118
139
  throw new Error('Account ID is missing');
119
140
  }
120
141
  const previousEmail = accountData.account.email;
@@ -163,36 +184,18 @@ export const sendResetPasswordEmail = async (account) => {
163
184
  }));
164
185
  };
165
186
  export const validateEmail = async (token) => {
166
- var _a;
167
187
  const communityConf = await communityConfig();
168
188
  const jwt = await jwtUtil();
169
189
  const { db } = await allpeepDb();
170
190
  try {
171
191
  const validatedToken = await jwt.verify(token);
172
- const email = (_a = validatedToken === null || validatedToken === void 0 ? void 0 : validatedToken.payload) === null || _a === void 0 ? void 0 : _a.email;
173
- const account = await findAccountByEmail(email !== null && email !== void 0 ? email : '');
192
+ const email = validatedToken?.payload?.email;
193
+ const account = await findAccountByEmail(email ?? '');
174
194
  if (account) {
175
195
  await accountsMapping.update(db, account.id, { emailValidated: true });
176
196
  await accountsCache.del(account.id);
177
197
  await accountsCache.del(account.email);
178
- for (const roleKey of communityConf.roles.onEmailValidation.add) {
179
- const role = await findRoleByKey(roleKey);
180
- if (role) {
181
- await assignRole(account.profiles[0], role);
182
- }
183
- else {
184
- log.error(`Role ${roleKey} missing`);
185
- }
186
- }
187
- for (const roleKey of communityConf.roles.onEmailValidation.remove) {
188
- const role = await findRoleByKey(roleKey);
189
- if (role) {
190
- await unassignRole(account.profiles[0], role);
191
- }
192
- else {
193
- log.error(`Role ${roleKey} missing`);
194
- }
195
- }
198
+ await applyCommunityRoleChanges(account.profiles[0], communityConf.roles.onEmailValidation);
196
199
  return true;
197
200
  }
198
201
  }
@@ -11,17 +11,17 @@ export const getAnalyticsCache = async (key) => {
11
11
  return undefined;
12
12
  return JSON.parse(raw);
13
13
  }
14
- catch (_a) {
14
+ catch {
15
15
  return undefined;
16
16
  }
17
17
  };
18
18
  export const setAnalyticsCache = async (key, value, opts) => {
19
19
  try {
20
20
  const redis = await getSharedConnection();
21
- const ttl = (opts === null || opts === void 0 ? void 0 : opts.includesToday) ? OPEN_DAY_TTL_SEC : CLOSED_RANGE_TTL_SEC;
21
+ const ttl = opts?.includesToday ? OPEN_DAY_TTL_SEC : CLOSED_RANGE_TTL_SEC;
22
22
  await redis.set(key, JSON.stringify(value), { EX: ttl });
23
23
  }
24
- catch (_a) {
24
+ catch {
25
25
  // Overview still returns; Redis must not 500 the request.
26
26
  }
27
27
  };
@@ -6,7 +6,7 @@ import { analyticsDailyClicks } from '../db/pg/schema/analytics.js';
6
6
  import { resolveAnalyticsRange } from './dateRange.js';
7
7
  const log = logger('app:analytics:clicks');
8
8
  export const MAX_CLICK_TARGET_LENGTH = 512;
9
- export const MAX_DISTINCT_CLICK_TARGETS_PER_DAY = 5000;
9
+ export const MAX_DISTINCT_CLICK_TARGETS_PER_DAY = 5_000;
10
10
  export const TOP_CLICKS_LIMIT = 25;
11
11
  const SKIP_PAGE_PREFIXES = [
12
12
  '/admin',
@@ -41,7 +41,7 @@ export const normalizePageTarget = (raw) => {
41
41
  pathname = new URL(trimmed, 'https://openpeeps.invalid').pathname || '/';
42
42
  }
43
43
  }
44
- catch (_a) {
44
+ catch {
45
45
  return null;
46
46
  }
47
47
  if (!pathname.startsWith('/'))
@@ -67,7 +67,7 @@ export const normalizeLinkTarget = (raw) => {
67
67
  const path = url.pathname || '/';
68
68
  return truncateCheck(`${url.protocol}//${host}${port}${path}`);
69
69
  }
70
- catch (_a) {
70
+ catch {
71
71
  return null;
72
72
  }
73
73
  };
@@ -80,7 +80,6 @@ export const normalizeClickEvent = (event) => {
80
80
  return target ? { kind: 'link', target } : null;
81
81
  };
82
82
  export const tallyNormalizedClicks = (events) => {
83
- var _a;
84
83
  const counts = new Map();
85
84
  const tallies = new Map();
86
85
  for (const event of events) {
@@ -89,16 +88,13 @@ export const tallyNormalizedClicks = (events) => {
89
88
  continue;
90
89
  const key = `${normalized.kind}\0${normalized.target}`;
91
90
  counts.set(key, normalized);
92
- tallies.set(key, ((_a = tallies.get(key)) !== null && _a !== void 0 ? _a : 0) + 1);
91
+ tallies.set(key, (tallies.get(key) ?? 0) + 1);
93
92
  }
94
- return [...counts.entries()].map(([key, { kind, target }]) => {
95
- var _a;
96
- return ({
97
- kind,
98
- target,
99
- clicks: (_a = tallies.get(key)) !== null && _a !== void 0 ? _a : 0,
100
- });
101
- });
93
+ return [...counts.entries()].map(([key, { kind, target }]) => ({
94
+ kind,
95
+ target,
96
+ clicks: tallies.get(key) ?? 0,
97
+ }));
102
98
  };
103
99
  const incrementExisting = async (day, kind, target, clicks) => {
104
100
  const db = await database();
@@ -124,13 +120,12 @@ const upsertClick = async (day, kind, target, clicks) => {
124
120
  });
125
121
  };
126
122
  const distinctTargetCount = async (day) => {
127
- var _a, _b;
128
123
  const db = await database();
129
124
  const rows = await db
130
125
  .select({ n: count() })
131
126
  .from(analyticsDailyClicks)
132
127
  .where(eq(analyticsDailyClicks.day, day));
133
- return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.n) !== null && _b !== void 0 ? _b : 0);
128
+ return Number(rows[0]?.n ?? 0);
134
129
  };
135
130
  /** Live increment. Does not accept or persist a profile id. */
136
131
  export const recordClickEvents = async (events) => {
@@ -165,13 +160,10 @@ const topClicks = async (from, to, kind) => {
165
160
  .groupBy(analyticsDailyClicks.target)
166
161
  .orderBy(desc(sum(analyticsDailyClicks.clicks)))
167
162
  .limit(TOP_CLICKS_LIMIT);
168
- return rows.map((row) => {
169
- var _a;
170
- return ({
171
- target: row.target,
172
- clicks: Number((_a = row.clicks) !== null && _a !== void 0 ? _a : 0),
173
- });
174
- });
163
+ return rows.map((row) => ({
164
+ target: row.target,
165
+ clicks: Number(row.clicks ?? 0),
166
+ }));
175
167
  };
176
168
  export const getAnalyticsClicks = async (query = {}) => {
177
169
  const range = resolveAnalyticsRange(query);
@@ -13,10 +13,9 @@ const dayBounds = (day) => {
13
13
  return { start, end };
14
14
  };
15
15
  const countScalar = async (db, query) => {
16
- var _a, _b;
17
16
  const result = await db.execute(query);
18
17
  const rows = result.rows;
19
- return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : 0);
18
+ return Number(rows[0]?.c ?? 0);
20
19
  };
21
20
  export const compileAnalyticsDay = async (day) => {
22
21
  const db = await database();
@@ -24,14 +23,16 @@ export const compileAnalyticsDay = async (day) => {
24
23
  const now = new Date().toISOString();
25
24
  const newMembers = await countScalar(db, sql `select count(*)::int as c from profiles
26
25
  where deleted_at is null
26
+ and type = 'local'
27
27
  and created_at >= ${start} and created_at < ${end}`);
28
28
  const posts = await countScalar(db, sql `select count(*)::int as c from posts
29
29
  where deleted_at is null and visibility <> 'direct'
30
30
  and created_at >= ${start} and created_at < ${end}`);
31
31
  const replies = await countScalar(db, sql `select count(*)::int as c from reply_to
32
32
  where created_at >= ${start} and created_at < ${end}`);
33
- const likes = await countScalar(db, sql `select count(*)::int as c from reactions
34
- where created_at >= ${start} and created_at < ${end}`);
33
+ const likes = await countScalar(db, sql `select count(*)::int as c from entries
34
+ where body->>'type' = 'reaction'
35
+ and created_at >= ${start} and created_at < ${end}`);
35
36
  const reposts = await countScalar(db, sql `select count(*)::int as c from repost
36
37
  where created_at >= ${start} and created_at < ${end}`);
37
38
  const bookmarks = await countScalar(db, sql `select count(*)::int as c from bookmarks
@@ -55,8 +56,9 @@ export const compileAnalyticsDay = async (day) => {
55
56
  where deleted_at is null
56
57
  and created_at >= ${start} and created_at < ${end}
57
58
  union
58
- select from_id from reactions
59
- where created_at >= ${start} and created_at < ${end}
59
+ select from_id from entries
60
+ where body->>'type' in ('reaction', 'unreaction')
61
+ and created_at >= ${start} and created_at < ${end}
60
62
  union
61
63
  select from_id from repost
62
64
  where created_at >= ${start} and created_at < ${end}
@@ -129,10 +131,11 @@ export const compileAnalyticsDay = async (day) => {
129
131
  update analytics_daily_by_group g
130
132
  set
131
133
  likes = coalesce((
132
- select count(*)::int from reactions r
133
- join post_groups pg on pg.from_id = r.to_id
134
+ select count(*)::int from entries e
135
+ join post_groups pg on pg.from_id = e.to_id
134
136
  where pg.to_id = g.group_id
135
- and r.created_at >= ${start} and r.created_at < ${end}
137
+ and e.body->>'type' = 'reaction'
138
+ and e.created_at >= ${start} and e.created_at < ${end}
136
139
  ), 0),
137
140
  comments = coalesce((
138
141
  select count(*)::int from reply_to rt
@@ -164,8 +167,9 @@ export const compileAnalyticsDay = async (day) => {
164
167
  select created_at from posts
165
168
  where deleted_at is null and created_at >= ${start} and created_at < ${end}
166
169
  union all
167
- select created_at from reactions
168
- where created_at >= ${start} and created_at < ${end}
170
+ select created_at from entries
171
+ where body->>'type' in ('reaction', 'unreaction')
172
+ and created_at >= ${start} and created_at < ${end}
169
173
  union all
170
174
  select created_at from reply_to
171
175
  where created_at >= ${start} and created_at < ${end}
@@ -243,7 +247,8 @@ export const compileRetentionCohorts = async () => {
243
247
  from (
244
248
  select creator_id as profile_id, created_at from posts where deleted_at is null
245
249
  union all
246
- select from_id, created_at from reactions
250
+ select from_id, created_at from entries
251
+ where body->>'type' in ('reaction', 'unreaction')
247
252
  union all
248
253
  select from_id, created_at from reply_to
249
254
  union all
@@ -18,8 +18,7 @@ const presetBounds = (preset, now) => {
18
18
  }
19
19
  };
20
20
  export const resolveAnalyticsRange = (query = {}, now = new Date()) => {
21
- var _a;
22
- const preset = (_a = query.preset) !== null && _a !== void 0 ? _a : (!query.from && !query.to ? '30d' : undefined);
21
+ const preset = query.preset ?? (!query.from && !query.to ? '30d' : undefined);
23
22
  let fromDate;
24
23
  let toDate;
25
24
  if (query.from && query.to) {
@@ -27,7 +26,7 @@ export const resolveAnalyticsRange = (query = {}, now = new Date()) => {
27
26
  toDate = startOfDay(parseISO(query.to));
28
27
  }
29
28
  else {
30
- const bounds = presetBounds(preset !== null && preset !== void 0 ? preset : '30d', now);
29
+ const bounds = presetBounds(preset ?? '30d', now);
31
30
  fromDate = bounds.from;
32
31
  toDate = bounds.to;
33
32
  }
@@ -166,10 +165,9 @@ export const selectChartBuckets = (from, to) => {
166
165
  export const aggregateSeriesIntoBuckets = (series, buckets) => {
167
166
  const byDay = new Map(series.map((p) => [p.day, p.value]));
168
167
  return buckets.map((bucket) => {
169
- var _a;
170
168
  let value = 0;
171
169
  for (const day of eachUtcDay(bucket.from, bucket.to)) {
172
- value += (_a = byDay.get(day)) !== null && _a !== void 0 ? _a : 0;
170
+ value += byDay.get(day) ?? 0;
173
171
  }
174
172
  return { day: bucket.key, label: bucket.label, value };
175
173
  });
@@ -44,11 +44,10 @@ const [analyticsCompileQueue, analyticsCompileWorker] = queueAndWorker(ANALYTICS
44
44
  },
45
45
  });
46
46
  const maybeEnqueueInitialBackfill = async () => {
47
- var _a;
48
47
  const db = await database();
49
48
  const result = await db.execute(sql `select exists(select 1 from analytics_daily_totals limit 1) as has_rows`);
50
49
  const rows = result.rows;
51
- if ((_a = rows[0]) === null || _a === void 0 ? void 0 : _a.has_rows)
50
+ if (rows[0]?.has_rows)
52
51
  return;
53
52
  const queue = analyticsCompileQueue();
54
53
  const existing = await queue.getJob(INITIAL_BACKFILL_JOB_ID);
@@ -72,8 +71,8 @@ export const ensureAnalyticsSchedules = async () => {
72
71
  };
73
72
  export const enqueueAnalyticsBackfill = async (from, to) => {
74
73
  const defaults = defaultBackfillRange();
75
- const start = from !== null && from !== void 0 ? from : defaults.from;
76
- const end = to !== null && to !== void 0 ? to : defaults.to;
74
+ const start = from ?? defaults.from;
75
+ const end = to ?? defaults.to;
77
76
  const job = await analyticsCompileQueue().add('backfill', {
78
77
  type: 'backfill',
79
78
  from: start,