@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,14 +1,15 @@
1
1
  import { publicProfileWithActivityScoreSchema, publicPostWithActivityScoreSchema, } from '@openpeepshq/common/types';
2
2
  import { sub } from 'date-fns';
3
+ import { hostResources } from '../server/status.js';
3
4
  import { baseProfilesMapping } from '../profiles/index.js';
4
5
  import { allpeepDb } from '../db/index.js';
5
6
  import { postsMapping, postsWithReplyCountMapping, postsWithReplyToCountMapping, transformPost, } from '../posts/index.js';
6
- import { entriesMapping, followsMapping, postsWithActivityScoreMapping, profileWithActivityScoreMapping, reactionsMapping, repostsMapping, } from './mapping.js';
7
+ import { entriesMapping, followsMapping, postsWithActivityScoreMapping, profileWithActivityScoreMapping, repostsMapping, } from './mapping.js';
7
8
  import { compileStatsWithAll, createdAtFilter } from './helpers.js';
8
9
  import { jamParticipantsMapping, jamSessionStartsMapping, } from '../jams/mapping.js';
9
10
  import { edgeFilters, postFilters, profileFilters } from '../db/pg/filters/index.js';
10
11
  import { sorts } from '../db/pg/queries/index.js';
11
- import { entries, follows, reactions, repost } from '../db/pg/schema/edges.js';
12
+ import { entries, follows, repost } from '../db/pg/schema/edges.js';
12
13
  import { jamEvents, posts, profiles } from '../db/pg/schema/documents.js';
13
14
  export const activeProfilesCount = (db, start, end) => profileWithActivityScoreMapping(start, end)
14
15
  .filter(profileFilters.activityScorePositive(start, end))
@@ -37,7 +38,10 @@ export const postsRepliesCount = (db, start, end) => postsWithReplyToCountMappin
37
38
  .filter({ matches: { replyToCount: 1 } })
38
39
  .count(db);
39
40
  export const postsRepliesStats = () => compileStatsWithAll(postsRepliesCount);
40
- const reactionCount = (db, start, end) => reactionsMapping.filter(createdAtFilter(reactions, start, end)).count(db);
41
+ const reactionCount = (db, start, end) => entriesMapping
42
+ .filter(createdAtFilter(entries, start, end))
43
+ .filter(edgeFilters.entryType('reaction'))
44
+ .count(db);
41
45
  const rsvpCount = (db, start, end) => entriesMapping
42
46
  .filter(createdAtFilter(entries, start, end))
43
47
  .filter(edgeFilters.entryType('rsvp'))
@@ -45,8 +49,7 @@ const rsvpCount = (db, start, end) => entriesMapping
45
49
  const followCount = (db, start, end) => followsMapping.filter(createdAtFilter(follows, start, end)).count(db);
46
50
  const entryCount = (db, start, end) => entriesMapping.filter(createdAtFilter(entries, start, end)).count(db);
47
51
  const repostCount = (db, start, end) => repostsMapping.filter(createdAtFilter(repost, start, end)).count(db);
48
- const interactionsCount = async (db, start, end) => (await reactionCount(db, start, end)) +
49
- (await followCount(db, start, end)) +
52
+ const interactionsCount = async (db, start, end) => (await followCount(db, start, end)) +
50
53
  (await entryCount(db, start, end)) +
51
54
  (await repostCount(db, start, end));
52
55
  export const interactionsStats = () => compileStatsWithAll(interactionsCount);
@@ -117,25 +120,34 @@ const createIntervals = (duration) => {
117
120
  start: sub(new Date(), { days: i + 1 }),
118
121
  end: sub(new Date(), { days: i }),
119
122
  }))
120
- .map((interval) => (Object.assign({ name: interval.start.toISOString().split('T')[0] }, interval)));
123
+ .map((interval) => ({
124
+ name: interval.start.toISOString().split('T')[0],
125
+ ...interval,
126
+ }));
121
127
  case 'P4W':
122
128
  return [0, 1, 2, 3]
123
129
  .map((i) => ({
124
130
  start: sub(new Date(), { days: (i + 1) * 7 }),
125
131
  end: sub(new Date(), { days: i * 7 }),
126
132
  }))
127
- .map((interval) => (Object.assign({ name: `${interval.start.toISOString().split('T')[0]} - ${interval.end.toISOString().split('T')[0]}` }, interval)));
133
+ .map((interval) => ({
134
+ name: `${interval.start.toISOString().split('T')[0]} - ${interval.end.toISOString().split('T')[0]}`,
135
+ ...interval,
136
+ }));
128
137
  case 'P120D':
129
138
  return [0, 1, 2, 3]
130
139
  .map((i) => ({
131
140
  start: sub(new Date(), { days: (i + 1) * 30 }),
132
141
  end: sub(new Date(), { days: i * 30 }),
133
142
  }))
134
- .map((interval) => (Object.assign({ name: `${interval.start.toISOString().split('T')[0]} - ${interval.end.toISOString().split('T')[0]}` }, interval)));
143
+ .map((interval) => ({
144
+ name: `${interval.start.toISOString().split('T')[0]} - ${interval.end.toISOString().split('T')[0]}`,
145
+ ...interval,
146
+ }));
135
147
  }
136
148
  };
137
149
  export const signupsTimeline = (duration) => Promise.all(createIntervals(duration).map((interval) => newProfilesForInterval(interval.start, interval.end).then((count) => ({
138
- name: interval === null || interval === void 0 ? void 0 : interval.name,
150
+ name: interval?.name,
139
151
  count,
140
152
  }))));
141
153
  export const serverStats = async () => ({
@@ -164,4 +176,5 @@ export const serverStats = async () => ({
164
176
  fourMonths: await signupsTimeline('P120D'),
165
177
  },
166
178
  },
179
+ host: await hostResources(),
167
180
  });
@@ -31,4 +31,7 @@ export const compileStats = async (fn) => allpeepDb().then(async ({ db }) => ({
31
31
  lastPeriod: await fn(db, sub(new Date(), { years: 2 }), sub(new Date(), { years: 1 })),
32
32
  },
33
33
  }));
34
- export const compileStatsWithAll = async (fn) => allpeepDb().then(async ({ db }) => (Object.assign(Object.assign({}, (await compileStats(fn))), { all: await fn(db) })));
34
+ export const compileStatsWithAll = async (fn) => allpeepDb().then(async ({ db }) => ({
35
+ ...(await compileStats(fn)),
36
+ all: await fn(db),
37
+ }));
@@ -1,7 +1,7 @@
1
1
  import { DbPost } from '@openpeepshq/common/types';
2
2
  export declare const profileWithActivityScoreMapping: (start?: Date, end?: Date) => import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("@openpeepshq/common").Profile>;
3
3
  export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mapping<{
4
- type: "note" | "question" | "event" | "article";
4
+ type: "resource" | "note" | "question" | "event" | "article";
5
5
  visibility: "local" | "group" | "report" | "public" | "unlisted" | "private" | "direct";
6
6
  creatorId: string;
7
7
  capabilitiesNeeded?: string[] | undefined;
@@ -197,13 +197,50 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
197
197
  language?: string | undefined;
198
198
  image?: string | undefined;
199
199
  title?: string | undefined;
200
+ } | {
201
+ type: "resource";
202
+ title: string;
203
+ resourceKind: "link" | "file" | "video" | "gallery" | "audio";
204
+ content?: string | undefined;
205
+ sensitive?: boolean | undefined;
206
+ spoilerText?: string | undefined;
207
+ attachments?: {
208
+ type: string;
209
+ url: string;
210
+ previewUrl: string | null;
211
+ textUrl: null;
212
+ filename: string;
213
+ meta: {
214
+ usage?: string | undefined;
215
+ focus?: {
216
+ x: number;
217
+ y: number;
218
+ } | undefined;
219
+ mimetype?: string | undefined;
220
+ size?: number | undefined;
221
+ };
222
+ description?: string | undefined;
223
+ blurhash?: string | undefined;
224
+ status?: "failed" | "processing" | "ready" | undefined;
225
+ error?: string | undefined;
226
+ }[] | undefined;
227
+ customEmojis?: {
228
+ shortcode: string;
229
+ url: string;
230
+ staticUrl: string;
231
+ visibleInPicker: boolean;
232
+ category: string;
233
+ }[] | undefined;
234
+ language?: string | undefined;
235
+ tags?: string[] | undefined;
236
+ categoryPath?: string[] | undefined;
237
+ url?: string | undefined;
200
238
  } | undefined;
201
239
  }, DbPost & {
202
240
  activityScore: number;
203
241
  }, DbPost & {
204
242
  activityScore: number;
205
243
  }>;
206
- export declare const reactionsMapping: import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("../db/pg/map").WithId<object>>;
207
244
  export declare const followsMapping: import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("../db/pg/map").WithId<object>>;
208
245
  export declare const entriesMapping: import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("../db/pg/map").WithId<object>>;
209
246
  export declare const repostsMapping: import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("../db/pg/map").WithId<object>>;
@@ -3,10 +3,14 @@ import { baseProfilesMapping } from '../profiles/index.js';
3
3
  import { postsMapping } from '../posts/index.js';
4
4
  import { map } from '../db/pg/map/index.js';
5
5
  import { computedFields } from '../db/pg/queries/index.js';
6
- export const profileWithActivityScoreMapping = (start, end) => map(Object.assign(Object.assign({}, baseProfilesMapping.data()), { activityWindow: { start, end }, computedFields: [computedFields.profileActivityScore({ start, end })] }));
7
- export const postsWithActivityScoreMapping = map(Object.assign(Object.assign({}, postsMapping.data()), { computedFields: [computedFields.postActivityScore()] }));
8
- export const reactionsMapping = map({
9
- collection: collectionInfos.reactionsCollection.name,
6
+ export const profileWithActivityScoreMapping = (start, end) => map({
7
+ ...baseProfilesMapping.data(),
8
+ activityWindow: { start, end },
9
+ computedFields: [computedFields.profileActivityScore({ start, end })],
10
+ });
11
+ export const postsWithActivityScoreMapping = map({
12
+ ...postsMapping.data(),
13
+ computedFields: [computedFields.postActivityScore()],
10
14
  });
11
15
  export const followsMapping = map({
12
16
  collection: collectionInfos.followsCollection.name,
@@ -6,14 +6,13 @@ export const stripeCache = createCache({
6
6
  refreshThreshold: 60 * 60 * 1000,
7
7
  });
8
8
  const loadStripeSubscription = async (customerId) => {
9
- var _a, _b, _c, _d, _e, _f;
10
9
  const subscriptions = await getStripe().then((stripe) => stripe.subscriptions.list({
11
10
  customer: customerId,
12
11
  limit: 1,
13
12
  status: 'all',
14
13
  expand: ['data.default_payment_method'],
15
14
  }));
16
- if (!(subscriptions === null || subscriptions === void 0 ? void 0 : subscriptions.data) || (subscriptions === null || subscriptions === void 0 ? void 0 : subscriptions.data.length) === 0) {
15
+ if (!subscriptions?.data || subscriptions?.data.length === 0) {
17
16
  return { status: 'none' };
18
17
  }
19
18
  const subscription = subscriptions.data[0];
@@ -21,14 +20,14 @@ const loadStripeSubscription = async (customerId) => {
21
20
  subscriptionId: subscription.id,
22
21
  status: subscription.status,
23
22
  priceId: subscription.items.data[0].price.id,
24
- currentPeriodEnd: (_a = subscription.ended_at) !== null && _a !== void 0 ? _a : null,
25
- currentPeriodStart: (_b = subscription.start_date) !== null && _b !== void 0 ? _b : null,
23
+ currentPeriodEnd: subscription.ended_at ?? null,
24
+ currentPeriodStart: subscription.start_date ?? null,
26
25
  cancelAtPeriodEnd: subscription.cancel_at_period_end,
27
26
  paymentMethod: subscription.default_payment_method &&
28
27
  typeof subscription.default_payment_method !== 'string'
29
28
  ? {
30
- brand: (_d = (_c = subscription.default_payment_method.card) === null || _c === void 0 ? void 0 : _c.brand) !== null && _d !== void 0 ? _d : null,
31
- last4: (_f = (_e = subscription.default_payment_method.card) === null || _e === void 0 ? void 0 : _e.last4) !== null && _f !== void 0 ? _f : null,
29
+ brand: subscription.default_payment_method.card?.brand ?? null,
30
+ last4: subscription.default_payment_method.card?.last4 ?? null,
32
31
  }
33
32
  : null,
34
33
  };
@@ -1,18 +1,17 @@
1
1
  import Stripe from 'stripe';
2
2
  import { config } from '../config/index.js';
3
3
  import { hub } from '../events/index.js';
4
- export const initStripeWithCredentials = (data) => (data === null || data === void 0 ? void 0 : data.publishableKey) || (data === null || data === void 0 ? void 0 : data.secretKey) || (data === null || data === void 0 ? void 0 : data.webhookSecret)
5
- ? new Stripe(data === null || data === void 0 ? void 0 : data.secretKey, { apiVersion: '2025-07-30.basil' })
4
+ export const initStripeWithCredentials = (data) => data?.publishableKey || data?.secretKey || data?.webhookSecret
5
+ ? new Stripe(data?.secretKey, { apiVersion: '2025-07-30.basil' })
6
6
  : undefined;
7
7
  export const initStripe = async () => {
8
- var _a;
9
8
  hub.on('configUpdated', (namespace, name) => {
10
9
  if (namespace === 'openpeeps' && name === 'core') {
11
10
  _stripe = null;
12
11
  }
13
12
  });
14
13
  const cfg = await config();
15
- return initStripeWithCredentials((_a = cfg.payments) === null || _a === void 0 ? void 0 : _a.stripe);
14
+ return initStripeWithCredentials(cfg.payments?.stripe);
16
15
  };
17
16
  let _stripe = null;
18
17
  export const getStripe = async () => {
@@ -4,22 +4,19 @@ import { getUserStripeSubscription, refreshStripeSubscription, stripeCache, } fr
4
4
  import { findProfileSettings, updateProfileSettings } from '../profileSettings/index.js';
5
5
  import { getStripe, initStripeWithCredentials } from './connection.js';
6
6
  export const getStripeDetails = async () => {
7
- var _a;
8
7
  const cfg = await config();
9
- const data = (_a = cfg.payments) === null || _a === void 0 ? void 0 : _a.stripe;
8
+ const data = cfg.payments?.stripe;
10
9
  const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
11
10
  const success_url = `${protocol}://${cfg.server.host}/payment/success`;
12
11
  const cancel_url = `${protocol}://${cfg.server.host}/auth/login`;
13
12
  const portal_return_url = `${protocol}://${cfg.server.host}/settings/billing`;
14
- return Object.assign(Object.assign({}, data), { success_url, cancel_url, portal_return_url });
13
+ return { ...data, success_url, cancel_url, portal_return_url };
15
14
  };
16
15
  export const stripeMembershipActive = async () => {
17
- var _a;
18
16
  const data = await getStripeDetails();
19
- return !!((_a = data === null || data === void 0 ? void 0 : data.paidMembership) === null || _a === void 0 ? void 0 : _a.enabled);
17
+ return !!data?.paidMembership?.enabled;
20
18
  };
21
19
  const getPrices = async (stripeInstance, productId = '', limit = 1) => {
22
- var _a, _b;
23
20
  if (!productId) {
24
21
  throw new Error('[STRIPE_PRICE][ERROR] No productId found');
25
22
  }
@@ -31,13 +28,13 @@ const getPrices = async (stripeInstance, productId = '', limit = 1) => {
31
28
  }
32
29
  const defaultPriceId = typeof product.default_price === 'string'
33
30
  ? product.default_price
34
- : ((_b = (_a = product.default_price) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null);
31
+ : (product.default_price?.id ?? null);
35
32
  if (defaultPriceId && limit === 1) {
36
33
  try {
37
34
  const price = await stripeInstance.prices.retrieve(defaultPriceId);
38
35
  return { data: [price] };
39
36
  }
40
- catch (_c) {
37
+ catch {
41
38
  return { data: [] };
42
39
  }
43
40
  }
@@ -51,7 +48,7 @@ const getPrices = async (stripeInstance, productId = '', limit = 1) => {
51
48
  };
52
49
  export const testStripeCredentials = async (data) => {
53
50
  try {
54
- const credentials = Object.assign(Object.assign({}, (await getStripeDetails())), data);
51
+ const credentials = { ...(await getStripeDetails()), ...data };
55
52
  const stripe = initStripeWithCredentials(credentials);
56
53
  if (!stripe) {
57
54
  return {
@@ -60,14 +57,14 @@ export const testStripeCredentials = async (data) => {
60
57
  };
61
58
  }
62
59
  const { paidMembership } = credentials;
63
- const productId = paidMembership === null || paidMembership === void 0 ? void 0 : paidMembership.productId;
60
+ const productId = paidMembership?.productId;
64
61
  if (!productId) {
65
62
  return {
66
63
  success: false,
67
64
  key: 'configuration.server.stripe.errors.noProductId',
68
65
  };
69
66
  }
70
- const prices = await getPrices(stripe, paidMembership === null || paidMembership === void 0 ? void 0 : paidMembership.productId, 1);
67
+ const prices = await getPrices(stripe, paidMembership?.productId, 1);
71
68
  if (prices.data.length === 0) {
72
69
  return {
73
70
  success: false,
@@ -92,7 +89,7 @@ export const createStripeCustomerPortal = async (stripeId) => {
92
89
  }));
93
90
  return session.url;
94
91
  }
95
- catch (_a) { }
92
+ catch { }
96
93
  };
97
94
  export const createStripeCustomer = async (profile, account) => {
98
95
  const profileSettings = await findProfileSettings(profile.id);
@@ -134,10 +131,9 @@ const allowedEvents = [
134
131
  'payment_intent.canceled',
135
132
  ];
136
133
  export const processEvent = async (event) => {
137
- var _a;
138
134
  if (!allowedEvents.includes(event.type))
139
135
  return;
140
- const { customer: customerId } = (_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.object;
136
+ const { customer: customerId } = event?.data?.object;
141
137
  if (typeof customerId !== 'string') {
142
138
  throw new Error(`[STRIPE HOOK][CANCER] ID isn't string.\nEvent type: ${event.type}`);
143
139
  }
@@ -167,14 +163,13 @@ export const checkSubscription = async (profile, account, refresh = false) => {
167
163
  return true;
168
164
  };
169
165
  export const createStripeCheckoutUrl = async (profile, account) => {
170
- var _a;
171
166
  const stripeCustomerId = await getOrCreateStripeCustomerId(profile, account);
172
167
  if (!stripeCustomerId) {
173
168
  throw new Error('[STRIPE_CHECKOUT][ERROR] No stripe customer id found');
174
169
  }
175
170
  const { paidMembership, success_url, cancel_url } = (await getStripeDetails());
176
- const productId = paidMembership === null || paidMembership === void 0 ? void 0 : paidMembership.productId;
177
- const trialPeriodDays = (_a = paidMembership === null || paidMembership === void 0 ? void 0 : paidMembership.trialPeriodDays) !== null && _a !== void 0 ? _a : 0;
171
+ const productId = paidMembership?.productId;
172
+ const trialPeriodDays = paidMembership?.trialPeriodDays ?? 0;
178
173
  const prices = await getPrices(await getStripe(), productId, 1);
179
174
  const line_items = prices.data.map((price) => ({
180
175
  price: price.id,
@@ -186,7 +181,7 @@ export const createStripeCheckoutUrl = async (profile, account) => {
186
181
  try {
187
182
  const res = await getUserStripeSubscription(stripeCustomerId);
188
183
  let successUrl = success_url;
189
- if (res !== null && (res === null || res === void 0 ? void 0 : res.status) !== 'none') {
184
+ if (res !== null && res?.status !== 'none') {
190
185
  successUrl = `${success_url}?user=true`;
191
186
  }
192
187
  const subscription_data = trialPeriodDays > 0
@@ -205,7 +200,7 @@ export const createStripeCheckoutUrl = async (profile, account) => {
205
200
  subscription_data,
206
201
  allow_promotion_codes: true,
207
202
  }))
208
- .then((session) => { var _a; return (_a = session.url) !== null && _a !== void 0 ? _a : undefined; });
203
+ .then((session) => session.url ?? undefined);
209
204
  }
210
- catch (_b) { }
205
+ catch { }
211
206
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/core",
3
- "version": "0.1.33",
3
+ "version": "0.1.35",
4
4
  "type": "module",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "dependencies": {
@@ -37,11 +37,10 @@
37
37
  "type-fest": "^4.31.0",
38
38
  "uuidv7": "^1.0.2",
39
39
  "web-push": "^3.6.7",
40
- "zod": "^4.4.3",
41
- "@openpeepshq/geocoder": "^0.1.2",
42
- "@openpeepshq/fetch-client": "^0.1.7",
43
- "@openpeepshq/common": "0.1.45",
44
- "@openpeepshq/i18n": "^0.1.9"
40
+ "@openpeepshq/common": "0.3.1",
41
+ "@openpeepshq/fetch-client": "^0.2.1",
42
+ "@openpeepshq/i18n": "^0.1.12",
43
+ "@openpeepshq/geocoder": "^0.1.2"
45
44
  },
46
45
  "main": "dist/index.js",
47
46
  "types": "dist/index.d.ts",
@@ -86,7 +85,6 @@
86
85
  "build": "tsc && tsc-alias && rm -rf dist/db/pg/sql && cp -r src/db/pg/sql dist/db/pg/sql",
87
86
  "build:watch": "tsc && tsc-alias && (concurrently \"tsc -w\" \"tsc-alias -w\")",
88
87
  "uuidv7": "node -e 'import(\"uuidv7\").then(u => console.log(u.uuidv7()))'",
89
- "create-migration": "node create-migration.js",
90
88
  "db:generate": "drizzle-kit generate",
91
89
  "db:migrate": "drizzle-kit migrate",
92
90
  "db:studio": "drizzle-kit studio"
@@ -1,3 +0,0 @@
1
- declare const isUndefinedTableError: (err: unknown) => boolean;
2
- export declare const tableCount: (collection: string) => Promise<number>;
3
- export { isUndefinedTableError };
@@ -1,33 +0,0 @@
1
- import { getTableName, sql } from 'drizzle-orm';
2
- import { pgDb } from '../pg/client.js';
3
- import { getTableForCollection } from '../pg/map/registry.js';
4
- const isUndefinedTableError = (err) => {
5
- const candidates = [
6
- err,
7
- err && typeof err === 'object' && 'cause' in err
8
- ? err.cause
9
- : undefined,
10
- ];
11
- return candidates.some((candidate) => candidate &&
12
- typeof candidate === 'object' &&
13
- 'code' in candidate &&
14
- candidate.code === '42P01');
15
- };
16
- export const tableCount = async (collection) => {
17
- var _a, _b;
18
- const table = getTableForCollection(collection);
19
- const tableName = getTableName(table);
20
- const db = pgDb();
21
- try {
22
- const result = await db.execute(sql.raw(`SELECT COUNT(*)::text AS count FROM "${tableName}"`));
23
- return Number((_b = (_a = result.rows[0]) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0);
24
- }
25
- catch (err) {
26
- // Missing table ⇒ treat as empty so callers can remigrate / auto-import.
27
- if (isUndefinedTableError(err)) {
28
- return 0;
29
- }
30
- throw err;
31
- }
32
- };
33
- export { isUndefinedTableError };
@@ -1,3 +0,0 @@
1
- export declare const importPostgres: (exportDir?: string, options?: {
2
- closeConnection?: boolean;
3
- }) => Promise<Record<string, number>>;
@@ -1,18 +0,0 @@
1
- import { logger } from '../../log/index.js';
2
- import { closePostgres } from '../pg/client.js';
3
- import { assertExportDir, collectionsDir, exportDirFromEnv, readManifest, writeImportStats, } from './shared.js';
4
- import { importAllArangoCollections } from './importCollections.js';
5
- const log = logger('core:migration:import');
6
- export const importPostgres = async (exportDir = exportDirFromEnv(), options = {}) => {
7
- var _a;
8
- const closeConnection = (_a = options.closeConnection) !== null && _a !== void 0 ? _a : true;
9
- await assertExportDir(exportDir);
10
- const manifest = await readManifest(exportDir);
11
- log.info('Importing export from %s (exported %s)', exportDir, manifest.exportedAt);
12
- const { imported } = await importAllArangoCollections(collectionsDir(exportDir));
13
- await writeImportStats(exportDir, imported);
14
- if (closeConnection) {
15
- await closePostgres();
16
- }
17
- return imported;
18
- };
@@ -1,20 +0,0 @@
1
- /** Postgres uuid compares case-insensitively; normalize so dedupe matches. */
2
- export declare const normalizeImportId: (value: unknown) => string | undefined;
3
- export declare const arangoDocToModel: (doc: Record<string, unknown>) => Record<string, unknown>;
4
- export type ImportContext = {
5
- postCreatorIdByPostId?: Map<string, string>;
6
- /** Empty-name / duplicate-name hashtags: old id → kept id, or '' if dropped. */
7
- hashtagIdRemap?: Map<string, string>;
8
- };
9
- /** Pre-scan entries edges so legacy posts without creatorId can be imported. */
10
- export declare const buildPostCreatorIdByPostId: (collectionsDir: string) => Promise<Map<string, string>>;
11
- /**
12
- * Legacy Arango groups used discoverable/locked flags; capabilities were added
13
- * later via an Arango-only data migration that never runs on Postgres restores.
14
- */
15
- export declare const capabilitiesFromLegacyGroupFlags: (data: Record<string, unknown>) => Record<string, unknown> | undefined;
16
- export declare const normalizeGroupMembershipRoles: (roles: unknown) => unknown;
17
- export declare const normalizeGroupCapabilityMap: (capabilities: Record<string, unknown>) => Record<string, unknown>;
18
- export declare const arangoDocToDocumentRow: (collection: string, doc: Record<string, unknown>, context?: ImportContext) => Record<string, unknown>;
19
- export declare const arangoDocToEdgeRow: (collection: string, doc: Record<string, unknown>) => Record<string, unknown>;
20
- export declare const isEdgeCollection: (collection: string) => boolean;