@openpeepshq/core 0.1.31

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 (500) hide show
  1. package/LICENSE +674 -0
  2. package/dist/accessTokens/finders.d.ts +11 -0
  3. package/dist/accessTokens/finders.js +43 -0
  4. package/dist/accessTokens/helpers.d.ts +13 -0
  5. package/dist/accessTokens/helpers.js +15 -0
  6. package/dist/accessTokens/index.d.ts +4 -0
  7. package/dist/accessTokens/index.js +4 -0
  8. package/dist/accessTokens/mapping.d.ts +10 -0
  9. package/dist/accessTokens/mapping.js +25 -0
  10. package/dist/accessTokens/mutations.d.ts +4 -0
  11. package/dist/accessTokens/mutations.js +24 -0
  12. package/dist/accessTokens/revokations.d.ts +2 -0
  13. package/dist/accessTokens/revokations.js +18 -0
  14. package/dist/accessTokens/tokens.d.ts +31 -0
  15. package/dist/accessTokens/tokens.js +174 -0
  16. package/dist/accounts/cache.d.ts +3 -0
  17. package/dist/accounts/cache.js +13 -0
  18. package/dist/accounts/finders.d.ts +6 -0
  19. package/dist/accounts/finders.js +17 -0
  20. package/dist/accounts/helpers.d.ts +7 -0
  21. package/dist/accounts/helpers.js +36 -0
  22. package/dist/accounts/index.d.ts +6 -0
  23. package/dist/accounts/index.js +6 -0
  24. package/dist/accounts/mapping.d.ts +10 -0
  25. package/dist/accounts/mapping.js +28 -0
  26. package/dist/accounts/mutations.d.ts +21 -0
  27. package/dist/accounts/mutations.js +204 -0
  28. package/dist/analytics/cache.d.ts +6 -0
  29. package/dist/analytics/cache.js +29 -0
  30. package/dist/analytics/compile.d.ts +4 -0
  31. package/dist/analytics/compile.js +296 -0
  32. package/dist/analytics/dateRange.d.ts +39 -0
  33. package/dist/analytics/dateRange.js +181 -0
  34. package/dist/analytics/index.d.ts +8 -0
  35. package/dist/analytics/index.js +8 -0
  36. package/dist/analytics/jobs.d.ts +20 -0
  37. package/dist/analytics/jobs.js +84 -0
  38. package/dist/analytics/metrics.d.ts +4 -0
  39. package/dist/analytics/metrics.js +13 -0
  40. package/dist/analytics/pdfReport.d.ts +8 -0
  41. package/dist/analytics/pdfReport.js +821 -0
  42. package/dist/analytics/read.d.ts +6 -0
  43. package/dist/analytics/read.js +696 -0
  44. package/dist/analytics/report.d.ts +293 -0
  45. package/dist/analytics/report.js +153 -0
  46. package/dist/analytics/settings.d.ts +3 -0
  47. package/dist/analytics/settings.js +37 -0
  48. package/dist/backups/index.d.ts +5 -0
  49. package/dist/backups/index.js +260 -0
  50. package/dist/backups/metadata.d.ts +9 -0
  51. package/dist/backups/metadata.js +2 -0
  52. package/dist/config/db.d.ts +7 -0
  53. package/dist/config/db.js +26 -0
  54. package/dist/config/defaults/capabilities.d.ts +2 -0
  55. package/dist/config/defaults/capabilities.js +47 -0
  56. package/dist/config/defaults/community.d.ts +2 -0
  57. package/dist/config/defaults/community.js +41 -0
  58. package/dist/config/defaults/core.d.ts +2 -0
  59. package/dist/config/defaults/core.js +113 -0
  60. package/dist/config/defaults/db.d.ts +6 -0
  61. package/dist/config/defaults/db.js +8 -0
  62. package/dist/config/defaults/logs.d.ts +6 -0
  63. package/dist/config/defaults/logs.js +7 -0
  64. package/dist/config/defaults/redis.d.ts +4 -0
  65. package/dist/config/defaults/redis.js +5 -0
  66. package/dist/config/helpers.d.ts +11 -0
  67. package/dist/config/helpers.js +31 -0
  68. package/dist/config/index.d.ts +392 -0
  69. package/dist/config/index.js +83 -0
  70. package/dist/config/pruneEmptyConfigStrings.d.ts +7 -0
  71. package/dist/config/pruneEmptyConfigStrings.js +29 -0
  72. package/dist/db/aql.d.ts +0 -0
  73. package/dist/db/aql.js +1 -0
  74. package/dist/db/arango.d.ts +2 -0
  75. package/dist/db/arango.js +110 -0
  76. package/dist/db/bootMigrate.d.ts +1 -0
  77. package/dist/db/bootMigrate.js +15 -0
  78. package/dist/db/examples.d.ts +1 -0
  79. package/dist/db/examples.js +13 -0
  80. package/dist/db/explorer/csv.d.ts +1 -0
  81. package/dist/db/explorer/csv.js +18 -0
  82. package/dist/db/explorer/index.d.ts +6 -0
  83. package/dist/db/explorer/index.js +5 -0
  84. package/dist/db/explorer/mutate.d.ts +6 -0
  85. package/dist/db/explorer/mutate.js +66 -0
  86. package/dist/db/explorer/query.d.ts +17 -0
  87. package/dist/db/explorer/query.js +48 -0
  88. package/dist/db/explorer/sql.d.ts +11 -0
  89. package/dist/db/explorer/sql.js +42 -0
  90. package/dist/db/explorer/tables.d.ts +9 -0
  91. package/dist/db/explorer/tables.js +65 -0
  92. package/dist/db/helpers.d.ts +64 -0
  93. package/dist/db/helpers.js +240 -0
  94. package/dist/db/index.d.ts +13 -0
  95. package/dist/db/index.js +15 -0
  96. package/dist/db/init.d.ts +2 -0
  97. package/dist/db/init.js +10 -0
  98. package/dist/db/migration/autoMigrate.d.ts +2 -0
  99. package/dist/db/migration/autoMigrate.js +111 -0
  100. package/dist/db/migration/cli.d.ts +1 -0
  101. package/dist/db/migration/cli.js +56 -0
  102. package/dist/db/migration/detect.d.ts +6 -0
  103. package/dist/db/migration/detect.js +87 -0
  104. package/dist/db/migration/exportArango.d.ts +4 -0
  105. package/dist/db/migration/exportArango.js +80 -0
  106. package/dist/db/migration/importCollections.d.ts +19 -0
  107. package/dist/db/migration/importCollections.js +280 -0
  108. package/dist/db/migration/importPostgres.d.ts +3 -0
  109. package/dist/db/migration/importPostgres.js +18 -0
  110. package/dist/db/migration/shared.d.ts +39 -0
  111. package/dist/db/migration/shared.js +158 -0
  112. package/dist/db/migration/transform.d.ts +18 -0
  113. package/dist/db/migration/transform.js +209 -0
  114. package/dist/db/migration/validate.d.ts +18 -0
  115. package/dist/db/migration/validate.js +69 -0
  116. package/dist/db/pg/client.d.ts +35 -0
  117. package/dist/db/pg/client.js +126 -0
  118. package/dist/db/pg/collections.d.ts +48 -0
  119. package/dist/db/pg/collections.js +53 -0
  120. package/dist/db/pg/filters/common.d.ts +21 -0
  121. package/dist/db/pg/filters/common.js +48 -0
  122. package/dist/db/pg/filters/edges.d.ts +9 -0
  123. package/dist/db/pg/filters/edges.js +10 -0
  124. package/dist/db/pg/filters/groups.d.ts +7 -0
  125. package/dist/db/pg/filters/groups.js +15 -0
  126. package/dist/db/pg/filters/index.d.ts +22 -0
  127. package/dist/db/pg/filters/index.js +35 -0
  128. package/dist/db/pg/filters/notifications.d.ts +6 -0
  129. package/dist/db/pg/filters/notifications.js +10 -0
  130. package/dist/db/pg/filters/posts.d.ts +18 -0
  131. package/dist/db/pg/filters/posts.js +25 -0
  132. package/dist/db/pg/filters/profiles.d.ts +6 -0
  133. package/dist/db/pg/filters/profiles.js +9 -0
  134. package/dist/db/pg/filters/types.d.ts +7 -0
  135. package/dist/db/pg/filters/types.js +5 -0
  136. package/dist/db/pg/helpers.d.ts +19 -0
  137. package/dist/db/pg/helpers.js +67 -0
  138. package/dist/db/pg/map/filters.d.ts +22 -0
  139. package/dist/db/pg/map/filters.js +566 -0
  140. package/dist/db/pg/map/helpers.d.ts +2 -0
  141. package/dist/db/pg/map/helpers.js +2 -0
  142. package/dist/db/pg/map/index.d.ts +46 -0
  143. package/dist/db/pg/map/index.js +93 -0
  144. package/dist/db/pg/map/mutations.d.ts +11 -0
  145. package/dist/db/pg/map/mutations.js +135 -0
  146. package/dist/db/pg/map/queryTypes.d.ts +115 -0
  147. package/dist/db/pg/map/queryTypes.js +1 -0
  148. package/dist/db/pg/map/registry.d.ts +29 -0
  149. package/dist/db/pg/map/registry.js +413 -0
  150. package/dist/db/pg/map/relations.d.ts +28 -0
  151. package/dist/db/pg/map/relations.js +399 -0
  152. package/dist/db/pg/map/search.d.ts +6 -0
  153. package/dist/db/pg/map/search.js +190 -0
  154. package/dist/db/pg/map/types.d.ts +11 -0
  155. package/dist/db/pg/map/types.js +1 -0
  156. package/dist/db/pg/mappers.d.ts +28 -0
  157. package/dist/db/pg/mappers.js +29 -0
  158. package/dist/db/pg/migrate.d.ts +14 -0
  159. package/dist/db/pg/migrate.js +134 -0
  160. package/dist/db/pg/queries/activity.d.ts +10 -0
  161. package/dist/db/pg/queries/activity.js +47 -0
  162. package/dist/db/pg/queries/computed.d.ts +7 -0
  163. package/dist/db/pg/queries/computed.js +19 -0
  164. package/dist/db/pg/queries/derived.d.ts +22 -0
  165. package/dist/db/pg/queries/derived.js +100 -0
  166. package/dist/db/pg/queries/index.d.ts +4 -0
  167. package/dist/db/pg/queries/index.js +4 -0
  168. package/dist/db/pg/queries/sorts.d.ts +10 -0
  169. package/dist/db/pg/queries/sorts.js +9 -0
  170. package/dist/db/pg/schema/analytics.d.ts +998 -0
  171. package/dist/db/pg/schema/analytics.js +110 -0
  172. package/dist/db/pg/schema/base.d.ts +36 -0
  173. package/dist/db/pg/schema/base.js +23 -0
  174. package/dist/db/pg/schema/documents.d.ts +2002 -0
  175. package/dist/db/pg/schema/documents.js +40 -0
  176. package/dist/db/pg/schema/edges.d.ts +2725 -0
  177. package/dist/db/pg/schema/edges.js +34 -0
  178. package/dist/db/pg/schema/index.d.ts +5724 -0
  179. package/dist/db/pg/schema/index.js +7 -0
  180. package/dist/db/pg/sql/0000_bizarre_chat.sql +456 -0
  181. package/dist/db/pg/sql/0001_search_vector.sql +122 -0
  182. package/dist/db/pg/sql/0002_data_migrations_id_text.sql +1 -0
  183. package/dist/db/pg/sql/0003_fix_group_post_visibility.sql +4 -0
  184. package/dist/db/pg/sql/0004_analytics.sql +90 -0
  185. package/dist/db/pg/sql/meta/0000_snapshot.json +3380 -0
  186. package/dist/db/pg/sql/meta/0004_snapshot.json +4114 -0
  187. package/dist/db/pg/sql/meta/_journal.json +41 -0
  188. package/dist/db/replaceHostname.d.ts +1 -0
  189. package/dist/db/replaceHostname.js +88 -0
  190. package/dist/db/types.d.ts +17 -0
  191. package/dist/db/types.js +1 -0
  192. package/dist/email/index.d.ts +9 -0
  193. package/dist/email/index.js +19 -0
  194. package/dist/email/jobs.d.ts +3 -0
  195. package/dist/email/jobs.js +13 -0
  196. package/dist/email/queueStats.d.ts +2 -0
  197. package/dist/email/queueStats.js +27 -0
  198. package/dist/email/registry.d.ts +3 -0
  199. package/dist/email/registry.js +4 -0
  200. package/dist/email/render.d.ts +8 -0
  201. package/dist/email/render.js +34 -0
  202. package/dist/email/send.d.ts +9 -0
  203. package/dist/email/send.js +97 -0
  204. package/dist/email/smtpTest.d.ts +2 -0
  205. package/dist/email/smtpTest.js +26 -0
  206. package/dist/errors/index.d.ts +8 -0
  207. package/dist/errors/index.js +13 -0
  208. package/dist/events/index.d.ts +31 -0
  209. package/dist/events/index.js +66 -0
  210. package/dist/events/once.d.ts +4 -0
  211. package/dist/events/once.js +23 -0
  212. package/dist/groups/finders.d.ts +125 -0
  213. package/dist/groups/finders.js +18 -0
  214. package/dist/groups/helpers.d.ts +227 -0
  215. package/dist/groups/helpers.js +17 -0
  216. package/dist/groups/index.d.ts +3 -0
  217. package/dist/groups/index.js +3 -0
  218. package/dist/groups/mapping.d.ts +188 -0
  219. package/dist/groups/mapping.js +47 -0
  220. package/dist/groups/mutations.d.ts +26 -0
  221. package/dist/groups/mutations.js +41 -0
  222. package/dist/hashtags/finders.d.ts +3 -0
  223. package/dist/hashtags/finders.js +22 -0
  224. package/dist/hashtags/index.d.ts +2 -0
  225. package/dist/hashtags/index.js +2 -0
  226. package/dist/hashtags/mapping.d.ts +4 -0
  227. package/dist/hashtags/mapping.js +5 -0
  228. package/dist/hashtags/mutations.d.ts +0 -0
  229. package/dist/hashtags/mutations.js +1 -0
  230. package/dist/i18n/index.d.ts +14 -0
  231. package/dist/i18n/index.js +53 -0
  232. package/dist/index.d.ts +0 -0
  233. package/dist/index.js +1 -0
  234. package/dist/inviteLinks/finders.d.ts +3 -0
  235. package/dist/inviteLinks/finders.js +5 -0
  236. package/dist/inviteLinks/helpers.d.ts +20 -0
  237. package/dist/inviteLinks/helpers.js +4 -0
  238. package/dist/inviteLinks/index.d.ts +3 -0
  239. package/dist/inviteLinks/index.js +3 -0
  240. package/dist/inviteLinks/mapping.d.ts +10 -0
  241. package/dist/inviteLinks/mapping.js +35 -0
  242. package/dist/inviteLinks/mutations.d.ts +4 -0
  243. package/dist/inviteLinks/mutations.js +39 -0
  244. package/dist/jams/cache.d.ts +9 -0
  245. package/dist/jams/cache.js +13 -0
  246. package/dist/jams/finders.d.ts +23 -0
  247. package/dist/jams/finders.js +24 -0
  248. package/dist/jams/helpers.d.ts +70 -0
  249. package/dist/jams/helpers.js +29 -0
  250. package/dist/jams/index.d.ts +15 -0
  251. package/dist/jams/index.js +108 -0
  252. package/dist/jams/jobs.d.ts +9 -0
  253. package/dist/jams/jobs.js +42 -0
  254. package/dist/jams/livekit.d.ts +24 -0
  255. package/dist/jams/livekit.js +220 -0
  256. package/dist/jams/mapping.d.ts +137 -0
  257. package/dist/jams/mapping.js +35 -0
  258. package/dist/jams/mutations.d.ts +40 -0
  259. package/dist/jams/mutations.js +4 -0
  260. package/dist/jams/recording.d.ts +8 -0
  261. package/dist/jams/recording.js +67 -0
  262. package/dist/jams/recordingUploadAuth.d.ts +9 -0
  263. package/dist/jams/recordingUploadAuth.js +19 -0
  264. package/dist/jams/token.d.ts +4 -0
  265. package/dist/jams/token.js +129 -0
  266. package/dist/jams/waitingRoom.d.ts +5 -0
  267. package/dist/jams/waitingRoom.js +71 -0
  268. package/dist/jobs/index.d.ts +10 -0
  269. package/dist/jobs/index.js +60 -0
  270. package/dist/jobs/jobDetail.d.ts +2 -0
  271. package/dist/jobs/jobDetail.js +31 -0
  272. package/dist/jobs/jobLog.d.ts +18 -0
  273. package/dist/jobs/jobLog.js +61 -0
  274. package/dist/jwt/index.d.ts +10 -0
  275. package/dist/jwt/index.js +43 -0
  276. package/dist/lib/index.d.ts +2 -0
  277. package/dist/lib/index.js +2 -0
  278. package/dist/lib/streams.d.ts +2 -0
  279. package/dist/lib/streams.js +56 -0
  280. package/dist/lib/utils.d.ts +2 -0
  281. package/dist/lib/utils.js +17 -0
  282. package/dist/lib/zodDeepPartial.d.ts +3 -0
  283. package/dist/lib/zodDeepPartial.js +26 -0
  284. package/dist/location/index.d.ts +2 -0
  285. package/dist/location/index.js +28 -0
  286. package/dist/log/index.d.ts +3 -0
  287. package/dist/log/index.js +97 -0
  288. package/dist/mastodon/index.d.ts +4 -0
  289. package/dist/mastodon/index.js +51 -0
  290. package/dist/mastodon/types.d.ts +7579 -0
  291. package/dist/mastodon/types.js +523 -0
  292. package/dist/mastodon/typescript.d.ts +1578 -0
  293. package/dist/mastodon/typescript.js +1 -0
  294. package/dist/media/index.d.ts +40 -0
  295. package/dist/media/index.js +248 -0
  296. package/dist/media/ipfs/index.d.ts +0 -0
  297. package/dist/media/ipfs/index.js +39 -0
  298. package/dist/media/jobs.d.ts +19 -0
  299. package/dist/media/jobs.js +90 -0
  300. package/dist/media/openpeeps/index.d.ts +3 -0
  301. package/dist/media/openpeeps/index.js +131 -0
  302. package/dist/media/processing.d.ts +19 -0
  303. package/dist/media/processing.js +83 -0
  304. package/dist/media/streaming.d.ts +77 -0
  305. package/dist/media/streaming.js +257 -0
  306. package/dist/media/streamingCleanupJobs.d.ts +14 -0
  307. package/dist/media/streamingCleanupJobs.js +47 -0
  308. package/dist/media/streamingJobs.d.ts +5 -0
  309. package/dist/media/streamingJobs.js +329 -0
  310. package/dist/media/streamingPrewarm.d.ts +36 -0
  311. package/dist/media/streamingPrewarm.js +109 -0
  312. package/dist/mediaAttachments/finders.d.ts +1 -0
  313. package/dist/mediaAttachments/finders.js +3 -0
  314. package/dist/mediaAttachments/index.d.ts +5 -0
  315. package/dist/mediaAttachments/index.js +12 -0
  316. package/dist/mediaAttachments/mapping.d.ts +21 -0
  317. package/dist/mediaAttachments/mapping.js +4 -0
  318. package/dist/mediaAttachments/mutations.d.ts +3 -0
  319. package/dist/mediaAttachments/mutations.js +10 -0
  320. package/dist/notifications/defaultNotifications/announcement/index.d.ts +24 -0
  321. package/dist/notifications/defaultNotifications/announcement/index.js +42 -0
  322. package/dist/notifications/defaultNotifications/directMessage/index.d.ts +28 -0
  323. package/dist/notifications/defaultNotifications/directMessage/index.js +69 -0
  324. package/dist/notifications/defaultNotifications/follow/index.d.ts +24 -0
  325. package/dist/notifications/defaultNotifications/follow/index.js +31 -0
  326. package/dist/notifications/defaultNotifications/groupAdded/index.d.ts +18 -0
  327. package/dist/notifications/defaultNotifications/groupAdded/index.js +33 -0
  328. package/dist/notifications/defaultNotifications/groupMemberJoined/index.d.ts +18 -0
  329. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +36 -0
  330. package/dist/notifications/defaultNotifications/groupMemberLeft/index.d.ts +18 -0
  331. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +36 -0
  332. package/dist/notifications/defaultNotifications/index.d.ts +3 -0
  333. package/dist/notifications/defaultNotifications/index.js +43 -0
  334. package/dist/notifications/defaultNotifications/jamModerator/index.d.ts +23 -0
  335. package/dist/notifications/defaultNotifications/jamModerator/index.js +49 -0
  336. package/dist/notifications/defaultNotifications/jamSpeaker/index.d.ts +23 -0
  337. package/dist/notifications/defaultNotifications/jamSpeaker/index.js +47 -0
  338. package/dist/notifications/defaultNotifications/jamStarted/index.d.ts +18 -0
  339. package/dist/notifications/defaultNotifications/jamStarted/index.js +82 -0
  340. package/dist/notifications/defaultNotifications/mention/index.d.ts +24 -0
  341. package/dist/notifications/defaultNotifications/mention/index.js +89 -0
  342. package/dist/notifications/defaultNotifications/newGroupPost/index.d.ts +24 -0
  343. package/dist/notifications/defaultNotifications/newGroupPost/index.js +47 -0
  344. package/dist/notifications/defaultNotifications/newProfile/index.d.ts +24 -0
  345. package/dist/notifications/defaultNotifications/newProfile/index.js +40 -0
  346. package/dist/notifications/defaultNotifications/pollVote/index.d.ts +19 -0
  347. package/dist/notifications/defaultNotifications/pollVote/index.js +40 -0
  348. package/dist/notifications/defaultNotifications/reaction/index.d.ts +18 -0
  349. package/dist/notifications/defaultNotifications/reaction/index.js +43 -0
  350. package/dist/notifications/defaultNotifications/reply/index.d.ts +25 -0
  351. package/dist/notifications/defaultNotifications/reply/index.js +57 -0
  352. package/dist/notifications/defaultNotifications/repost/index.d.ts +18 -0
  353. package/dist/notifications/defaultNotifications/repost/index.js +42 -0
  354. package/dist/notifications/defaultNotifications/rsvp/index.d.ts +19 -0
  355. package/dist/notifications/defaultNotifications/rsvp/index.js +40 -0
  356. package/dist/notifications/fcmCredential.d.ts +14 -0
  357. package/dist/notifications/fcmCredential.js +68 -0
  358. package/dist/notifications/finders.d.ts +7 -0
  359. package/dist/notifications/finders.js +13 -0
  360. package/dist/notifications/firebase.d.ts +1 -0
  361. package/dist/notifications/firebase.js +33 -0
  362. package/dist/notifications/handlers.d.ts +3 -0
  363. package/dist/notifications/handlers.js +6 -0
  364. package/dist/notifications/helpers.d.ts +7 -0
  365. package/dist/notifications/helpers.js +31 -0
  366. package/dist/notifications/index.d.ts +9 -0
  367. package/dist/notifications/index.js +43 -0
  368. package/dist/notifications/jobs.d.ts +2 -0
  369. package/dist/notifications/jobs.js +75 -0
  370. package/dist/notifications/mapping.d.ts +25 -0
  371. package/dist/notifications/mapping.js +25 -0
  372. package/dist/notifications/mutations.d.ts +6 -0
  373. package/dist/notifications/mutations.js +40 -0
  374. package/dist/notifications/push.d.ts +9 -0
  375. package/dist/notifications/push.js +261 -0
  376. package/dist/notifications/pushInvalidation.d.ts +10 -0
  377. package/dist/notifications/pushInvalidation.js +10 -0
  378. package/dist/performance/index.d.ts +24 -0
  379. package/dist/performance/index.js +61 -0
  380. package/dist/plugins/helpers.d.ts +3 -0
  381. package/dist/plugins/helpers.js +72 -0
  382. package/dist/plugins/index.d.ts +10 -0
  383. package/dist/plugins/index.js +84 -0
  384. package/dist/plugins/pluginAuth.d.ts +30 -0
  385. package/dist/plugins/pluginAuth.js +44 -0
  386. package/dist/posts/contextClosure.d.ts +16 -0
  387. package/dist/posts/contextClosure.js +66 -0
  388. package/dist/posts/finders.d.ts +298 -0
  389. package/dist/posts/finders.js +259 -0
  390. package/dist/posts/helpers/filters.d.ts +14 -0
  391. package/dist/posts/helpers/filters.js +39 -0
  392. package/dist/posts/helpers/index.d.ts +837 -0
  393. package/dist/posts/helpers/index.js +117 -0
  394. package/dist/posts/index.d.ts +6 -0
  395. package/dist/posts/index.js +6 -0
  396. package/dist/posts/mapping.d.ts +2187 -0
  397. package/dist/posts/mapping.js +222 -0
  398. package/dist/posts/mutations.d.ts +19 -0
  399. package/dist/posts/mutations.js +202 -0
  400. package/dist/posts/rsvpConfirmationEmail.d.ts +2 -0
  401. package/dist/posts/rsvpConfirmationEmail.js +82 -0
  402. package/dist/processingStats/index.d.ts +3 -0
  403. package/dist/processingStats/index.js +3 -0
  404. package/dist/processingStats/mapping.d.ts +7 -0
  405. package/dist/processingStats/mapping.js +4 -0
  406. package/dist/processingStats/mutations.d.ts +2 -0
  407. package/dist/processingStats/mutations.js +6 -0
  408. package/dist/processingStats/queries.d.ts +4 -0
  409. package/dist/processingStats/queries.js +46 -0
  410. package/dist/profileSettings/cache.d.ts +2 -0
  411. package/dist/profileSettings/cache.js +24 -0
  412. package/dist/profileSettings/finders.d.ts +1 -0
  413. package/dist/profileSettings/finders.js +2 -0
  414. package/dist/profileSettings/index.d.ts +3 -0
  415. package/dist/profileSettings/index.js +3 -0
  416. package/dist/profileSettings/mapping.d.ts +38 -0
  417. package/dist/profileSettings/mapping.js +5 -0
  418. package/dist/profileSettings/mutations.d.ts +3 -0
  419. package/dist/profileSettings/mutations.js +24 -0
  420. package/dist/profiles/cache.d.ts +5 -0
  421. package/dist/profiles/cache.js +19 -0
  422. package/dist/profiles/capacity.d.ts +2 -0
  423. package/dist/profiles/capacity.js +20 -0
  424. package/dist/profiles/export.d.ts +3 -0
  425. package/dist/profiles/export.js +85 -0
  426. package/dist/profiles/finders.d.ts +11 -0
  427. package/dist/profiles/finders.js +39 -0
  428. package/dist/profiles/helpers.d.ts +35 -0
  429. package/dist/profiles/helpers.js +10 -0
  430. package/dist/profiles/index.d.ts +5 -0
  431. package/dist/profiles/index.js +18 -0
  432. package/dist/profiles/mapping.d.ts +157 -0
  433. package/dist/profiles/mapping.js +132 -0
  434. package/dist/profiles/mutations.d.ts +9 -0
  435. package/dist/profiles/mutations.js +75 -0
  436. package/dist/pushSubscriptions/finders.d.ts +187 -0
  437. package/dist/pushSubscriptions/finders.js +6 -0
  438. package/dist/pushSubscriptions/helpers.d.ts +99 -0
  439. package/dist/pushSubscriptions/helpers.js +3 -0
  440. package/dist/pushSubscriptions/index.d.ts +3 -0
  441. package/dist/pushSubscriptions/index.js +3 -0
  442. package/dist/pushSubscriptions/mapping.d.ts +261 -0
  443. package/dist/pushSubscriptions/mapping.js +6 -0
  444. package/dist/pushSubscriptions/mutations.d.ts +95 -0
  445. package/dist/pushSubscriptions/mutations.js +21 -0
  446. package/dist/redis/connection.d.ts +4 -0
  447. package/dist/redis/connection.js +17 -0
  448. package/dist/redis/index.d.ts +1 -0
  449. package/dist/redis/index.js +1 -0
  450. package/dist/reports/finders.d.ts +6 -0
  451. package/dist/reports/finders.js +44 -0
  452. package/dist/reports/helpers.d.ts +21 -0
  453. package/dist/reports/helpers.js +12 -0
  454. package/dist/reports/index.d.ts +3 -0
  455. package/dist/reports/index.js +3 -0
  456. package/dist/reports/mapping.d.ts +9 -0
  457. package/dist/reports/mapping.js +34 -0
  458. package/dist/reports/mutations.d.ts +5 -0
  459. package/dist/reports/mutations.js +16 -0
  460. package/dist/roles/defaults.d.ts +2 -0
  461. package/dist/roles/defaults.js +94 -0
  462. package/dist/roles/finders.d.ts +5 -0
  463. package/dist/roles/finders.js +9 -0
  464. package/dist/roles/index.d.ts +4 -0
  465. package/dist/roles/index.js +4 -0
  466. package/dist/roles/mapping.d.ts +11 -0
  467. package/dist/roles/mapping.js +5 -0
  468. package/dist/roles/mutations.d.ts +4 -0
  469. package/dist/roles/mutations.js +30 -0
  470. package/dist/search/finders.d.ts +47 -0
  471. package/dist/search/finders.js +59 -0
  472. package/dist/search/helpers.d.ts +3 -0
  473. package/dist/search/helpers.js +1 -0
  474. package/dist/search/index.d.ts +1 -0
  475. package/dist/search/index.js +1 -0
  476. package/dist/search/mapping.d.ts +40 -0
  477. package/dist/search/mapping.js +43 -0
  478. package/dist/sentry/index.d.ts +34 -0
  479. package/dist/sentry/index.js +113 -0
  480. package/dist/server/helpers.d.ts +0 -0
  481. package/dist/server/helpers.js +1 -0
  482. package/dist/server/index.d.ts +105 -0
  483. package/dist/server/index.js +64 -0
  484. package/dist/stats/finders.d.ts +16156 -0
  485. package/dist/stats/finders.js +167 -0
  486. package/dist/stats/helpers.d.ts +17 -0
  487. package/dist/stats/helpers.js +34 -0
  488. package/dist/stats/index.d.ts +1 -0
  489. package/dist/stats/index.js +1 -0
  490. package/dist/stats/mapping.d.ts +188 -0
  491. package/dist/stats/mapping.js +19 -0
  492. package/dist/stripe/cache.d.ts +30 -0
  493. package/dist/stripe/cache.js +37 -0
  494. package/dist/stripe/connection.d.ts +5 -0
  495. package/dist/stripe/connection.js +23 -0
  496. package/dist/stripe/helpers.d.ts +25 -0
  497. package/dist/stripe/helpers.js +211 -0
  498. package/dist/stripe/index.d.ts +3 -0
  499. package/dist/stripe/index.js +3 -0
  500. package/package.json +99 -0
@@ -0,0 +1,696 @@
1
+ import { and, asc, desc, gte, lte, min, sql, sum } from 'drizzle-orm';
2
+ import { formatISO, startOfDay } from 'date-fns';
3
+ import { database } from '../db/index.js';
4
+ import { analyticsDailyByGroup, analyticsDailyTotals, analyticsPostViewsDaily, analyticsRetentionCohorts, } from '../db/pg/schema/analytics.js';
5
+ import { groups, posts, profiles } from '../db/pg/schema/documents.js';
6
+ import { analyticsCacheKey, getAnalyticsCache, setAnalyticsCache, } from './cache.js';
7
+ import { aggregateSeriesIntoBuckets, eachUtcDay, resolveAnalyticsRange, selectChartBuckets, } from './dateRange.js';
8
+ import { metricCard, sumSeries } from './metrics.js';
9
+ const POST_TYPE_KEYS = ['jam', 'article', 'note', 'poll', 'event'];
10
+ const todayString = () => formatISO(startOfDay(new Date()), { representation: 'date' });
11
+ const includesToday = (to) => to >= todayString();
12
+ /** Earliest day with compiled analytics — used to bound the `all` preset. */
13
+ const earliestAnalyticsDay = async () => {
14
+ var _a;
15
+ const db = await database();
16
+ const [row] = await db
17
+ .select({ day: min(analyticsDailyTotals.day) })
18
+ .from(analyticsDailyTotals);
19
+ return (_a = row === null || row === void 0 ? void 0 : row.day) !== null && _a !== void 0 ? _a : null;
20
+ };
21
+ const resolveQueryRange = async (query = {}) => {
22
+ const range = resolveAnalyticsRange(query);
23
+ if (range.preset !== 'all')
24
+ return range;
25
+ const earliest = await earliestAnalyticsDay();
26
+ if (!earliest || earliest <= range.from)
27
+ return range;
28
+ return Object.assign(Object.assign({}, resolveAnalyticsRange({ from: earliest, to: range.to })), { preset: 'all' });
29
+ };
30
+ const seriesFromTotals = (days, rows) => {
31
+ const map = new Map(rows.map((r) => [r.day, r.value]));
32
+ return days.map((day) => { var _a; return ({ day, value: (_a = map.get(day)) !== null && _a !== void 0 ? _a : 0 }); });
33
+ };
34
+ const loadTotalsSeries = async (from, to, column) => {
35
+ const db = await database();
36
+ const days = eachUtcDay(from, to);
37
+ const col = analyticsDailyTotals[column];
38
+ const rows = await db
39
+ .select({ day: analyticsDailyTotals.day, value: col })
40
+ .from(analyticsDailyTotals)
41
+ .where(and(gte(analyticsDailyTotals.day, from), lte(analyticsDailyTotals.day, to)))
42
+ .orderBy(asc(analyticsDailyTotals.day));
43
+ return seriesFromTotals(days, rows.map((r) => { var _a; return ({ day: r.day, value: Number((_a = r.value) !== null && _a !== void 0 ? _a : 0) }); }));
44
+ };
45
+ const sumColumn = async (from, to, column) => sumSeries(await loadTotalsSeries(from, to, column));
46
+ const totalMembersAt = async (day) => {
47
+ var _a, _b;
48
+ const db = await database();
49
+ const end = `${day}T23:59:59.999Z`;
50
+ const result = await db.execute(sql `
51
+ select count(*)::int as c from profiles
52
+ where deleted_at is null and created_at <= ${end}
53
+ `);
54
+ const rows = result.rows;
55
+ return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : 0);
56
+ };
57
+ const totalPostsAt = async (day) => {
58
+ var _a, _b;
59
+ const db = await database();
60
+ const end = `${day}T23:59:59.999Z`;
61
+ const result = await db.execute(sql `
62
+ select count(*)::int as c from posts
63
+ where deleted_at is null
64
+ and visibility <> 'direct'
65
+ and created_at <= ${end}
66
+ `);
67
+ const rows = result.rows;
68
+ return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : 0);
69
+ };
70
+ const latestCompiledAt = async (from, to) => {
71
+ var _a, _b;
72
+ const db = await database();
73
+ const rows = await db
74
+ .select({ compiledAt: analyticsDailyTotals.compiledAt })
75
+ .from(analyticsDailyTotals)
76
+ .where(and(gte(analyticsDailyTotals.day, from), lte(analyticsDailyTotals.day, to)))
77
+ .orderBy(desc(analyticsDailyTotals.compiledAt))
78
+ .limit(1);
79
+ return (_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.compiledAt) !== null && _b !== void 0 ? _b : null;
80
+ };
81
+ const groupVisibility = (body) => {
82
+ var _a, _b, _c;
83
+ return ((_c = (_b = (_a = body.capabilities) === null || _a === void 0 ? void 0 : _a.none) === null || _b === void 0 ? void 0 : _b.add) !== null && _c !== void 0 ? _c : []).includes('core-groups-read')
84
+ ? 'public'
85
+ : 'private';
86
+ };
87
+ const groupDisplayName = (body, handle) => { var _a, _b, _c; return (_c = (_b = (_a = body.name) !== null && _a !== void 0 ? _a : body.displayName) !== null && _b !== void 0 ? _b : handle) !== null && _c !== void 0 ? _c : undefined; };
88
+ const enrichGroupRows = async (rows, from, to) => {
89
+ if (rows.length === 0)
90
+ return [];
91
+ const db = await database();
92
+ const start = `${from}T00:00:00.000Z`;
93
+ const end = `${to}T23:59:59.999Z`;
94
+ const ids = rows.map((r) => r.groupId);
95
+ const dayCount = Math.max(1, eachUtcDay(from, to).length);
96
+ const metaResult = await db.execute(sql `
97
+ select
98
+ g.id::text as group_id,
99
+ coalesce((
100
+ select count(*)::int from user_groups ug
101
+ where ug.to_id = g.id::text
102
+ ), 0) as members,
103
+ coalesce((
104
+ select count(*)::int from user_groups ug
105
+ where ug.to_id = g.id::text
106
+ and ug.created_at >= ${start}
107
+ and ug.created_at <= ${end}
108
+ ), 0) as growth,
109
+ coalesce((
110
+ select count(distinct p.creator_id)::int
111
+ from post_groups pg
112
+ join posts p on p.id::text = pg.from_id
113
+ where pg.to_id = g.id::text
114
+ and p.deleted_at is null
115
+ and p.created_at >= ${start}
116
+ and p.created_at <= ${end}
117
+ ), 0) as active_members
118
+ from groups g
119
+ where g.id::text in (${sql.join(ids.map((id) => sql `${id}`), sql `, `)})
120
+ `);
121
+ const metaById = new Map(metaResult.rows.map((r) => {
122
+ var _a, _b, _c;
123
+ return [
124
+ r.group_id,
125
+ {
126
+ members: Number((_a = r.members) !== null && _a !== void 0 ? _a : 0),
127
+ growth: Number((_b = r.growth) !== null && _b !== void 0 ? _b : 0),
128
+ activeMembers: Number((_c = r.active_members) !== null && _c !== void 0 ? _c : 0),
129
+ },
130
+ ];
131
+ }));
132
+ return rows.map((r) => {
133
+ var _a, _b, _c;
134
+ const body = ((_a = r.body) !== null && _a !== void 0 ? _a : {});
135
+ const meta = (_b = metaById.get(r.groupId)) !== null && _b !== void 0 ? _b : {
136
+ members: 0,
137
+ growth: 0,
138
+ activeMembers: 0,
139
+ };
140
+ const engagementRate = r.uniqueViewers <= 0
141
+ ? 0
142
+ : Math.round(((r.likes + r.comments) / r.uniqueViewers) * 1000) / 10;
143
+ return {
144
+ groupId: r.groupId,
145
+ handle: (_c = r.handle) !== null && _c !== void 0 ? _c : undefined,
146
+ name: groupDisplayName(body, r.handle),
147
+ posts: r.posts,
148
+ likes: r.likes,
149
+ comments: r.comments,
150
+ uniqueViewers: r.uniqueViewers,
151
+ activity: r.activity,
152
+ visibility: groupVisibility(body),
153
+ members: meta.members,
154
+ activeMembers: meta.activeMembers,
155
+ engagementRate,
156
+ growth: meta.growth,
157
+ dailyVisits: Math.round(r.uniqueViewers / dayCount),
158
+ };
159
+ });
160
+ };
161
+ const topGroups = async (from, to, limit = 6) => {
162
+ const db = await database();
163
+ const rows = await db
164
+ .select({
165
+ groupId: analyticsDailyByGroup.groupId,
166
+ posts: sum(analyticsDailyByGroup.posts),
167
+ likes: sum(analyticsDailyByGroup.likes),
168
+ comments: sum(analyticsDailyByGroup.comments),
169
+ uniqueViewers: sum(analyticsDailyByGroup.uniqueViewers),
170
+ handle: groups.handle,
171
+ body: groups.body,
172
+ })
173
+ .from(analyticsDailyByGroup)
174
+ .leftJoin(groups, sql `${groups.id}::text = ${analyticsDailyByGroup.groupId}`)
175
+ .where(and(gte(analyticsDailyByGroup.day, from), lte(analyticsDailyByGroup.day, to)))
176
+ .groupBy(analyticsDailyByGroup.groupId, groups.handle, groups.body)
177
+ .orderBy(desc(sql `coalesce(${sum(analyticsDailyByGroup.posts)}, 0)
178
+ + coalesce(${sum(analyticsDailyByGroup.likes)}, 0)
179
+ + coalesce(${sum(analyticsDailyByGroup.comments)}, 0)`))
180
+ .limit(limit);
181
+ return enrichGroupRows(rows.map((r) => {
182
+ var _a, _b, _c, _d;
183
+ const postsCount = Number((_a = r.posts) !== null && _a !== void 0 ? _a : 0);
184
+ const likesCount = Number((_b = r.likes) !== null && _b !== void 0 ? _b : 0);
185
+ const commentsCount = Number((_c = r.comments) !== null && _c !== void 0 ? _c : 0);
186
+ const viewers = Number((_d = r.uniqueViewers) !== null && _d !== void 0 ? _d : 0);
187
+ return {
188
+ groupId: r.groupId,
189
+ handle: r.handle,
190
+ body: r.body,
191
+ posts: postsCount,
192
+ likes: likesCount,
193
+ comments: commentsCount,
194
+ uniqueViewers: viewers,
195
+ activity: postsCount + likesCount + commentsCount,
196
+ };
197
+ }), from, to);
198
+ };
199
+ /** Top groups by new-member joins in range, with bucketed join series. */
200
+ const groupGrowthOverTime = async (from, to, limit = 6) => {
201
+ var _a;
202
+ const db = await database();
203
+ const start = `${from}T00:00:00.000Z`;
204
+ const end = `${to}T23:59:59.999Z`;
205
+ const topResult = await db.execute(sql `
206
+ select
207
+ ug.to_id as group_id,
208
+ count(*)::int as growth,
209
+ g.handle,
210
+ g.body
211
+ from user_groups ug
212
+ left join groups g on g.id::text = ug.to_id
213
+ where ug.created_at >= ${start}
214
+ and ug.created_at <= ${end}
215
+ and (g.deleted_at is null or g.id is null)
216
+ group by ug.to_id, g.handle, g.body
217
+ order by growth desc
218
+ limit ${limit}
219
+ `);
220
+ const topRows = topResult.rows;
221
+ const series = topRows.map((r, i) => {
222
+ var _a, _b;
223
+ const body = ((_a = r.body) !== null && _a !== void 0 ? _a : {});
224
+ return {
225
+ key: `g${i}`,
226
+ groupId: r.group_id,
227
+ name: (_b = groupDisplayName(body, r.handle)) !== null && _b !== void 0 ? _b : r.group_id.slice(0, 8),
228
+ };
229
+ });
230
+ if (series.length === 0) {
231
+ return { series, overTime: [] };
232
+ }
233
+ const idToKey = new Map(series.map((s) => [s.groupId, s.key]));
234
+ const dailyResult = await db.execute(sql `
235
+ select
236
+ ug.to_id as group_id,
237
+ (ug.created_at at time zone 'UTC')::date::text as day,
238
+ count(*)::int as c
239
+ from user_groups ug
240
+ where ug.created_at >= ${start}
241
+ and ug.created_at <= ${end}
242
+ and ug.to_id in (${sql.join(series.map((s) => sql `${s.groupId}`), sql `, `)})
243
+ group by 1, 2
244
+ order by 2
245
+ `);
246
+ const byDayGroup = new Map();
247
+ for (const row of dailyResult.rows) {
248
+ const key = idToKey.get(row.group_id);
249
+ if (!key)
250
+ continue;
251
+ byDayGroup.set(`${row.day}:${key}`, Number((_a = row.c) !== null && _a !== void 0 ? _a : 0));
252
+ }
253
+ const { buckets } = selectChartBuckets(from, to);
254
+ const overTime = buckets.map((bucket) => {
255
+ var _a;
256
+ const values = {};
257
+ for (const s of series)
258
+ values[s.key] = 0;
259
+ for (const day of eachUtcDay(bucket.from, bucket.to)) {
260
+ for (const s of series) {
261
+ values[s.key] += (_a = byDayGroup.get(`${day}:${s.key}`)) !== null && _a !== void 0 ? _a : 0;
262
+ }
263
+ }
264
+ return { day: bucket.key, label: bucket.label, values };
265
+ });
266
+ return { series, overTime };
267
+ };
268
+ const loadPostsByTypeDaily = async (from, to) => {
269
+ const db = await database();
270
+ const start = `${from}T00:00:00.000Z`;
271
+ const end = `${to}T23:59:59.999Z`;
272
+ const result = await db.execute(sql `
273
+ select
274
+ (created_at at time zone 'UTC')::date::text as day,
275
+ case
276
+ when type = 'event'
277
+ and body->'jam' is not null
278
+ and body->'jam' <> 'null'::jsonb
279
+ then 'jam'
280
+ when type = 'question' then 'poll'
281
+ when type = 'article' then 'article'
282
+ when type = 'event' then 'event'
283
+ else 'note'
284
+ end as kind,
285
+ count(*)::int as c
286
+ from posts
287
+ where deleted_at is null
288
+ and visibility <> 'direct'
289
+ and created_at >= ${start}
290
+ and created_at <= ${end}
291
+ group by 1, 2
292
+ order by 1
293
+ `);
294
+ return result.rows.map((r) => {
295
+ var _a;
296
+ return ({
297
+ day: r.day,
298
+ kind: r.kind,
299
+ count: Number((_a = r.c) !== null && _a !== void 0 ? _a : 0),
300
+ });
301
+ });
302
+ };
303
+ const totalGroupsAt = async (day) => {
304
+ var _a, _b;
305
+ const db = await database();
306
+ const end = `${day}T23:59:59.999Z`;
307
+ const result = await db.execute(sql `
308
+ select count(*)::int as c from groups
309
+ where deleted_at is null and created_at <= ${end}
310
+ `);
311
+ const rows = result.rows;
312
+ return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : 0);
313
+ };
314
+ const topMembers = async (from, to, limit = 10) => {
315
+ const db = await database();
316
+ const start = `${from}T00:00:00.000Z`;
317
+ const end = `${to}T23:59:59.999Z`;
318
+ const result = await db.execute(sql `
319
+ with contrib as (
320
+ select creator_id as profile_id from posts
321
+ where deleted_at is null
322
+ and visibility <> 'direct'
323
+ and created_at >= ${start} and created_at <= ${end}
324
+ union all
325
+ select from_id from reactions
326
+ where created_at >= ${start} and created_at <= ${end}
327
+ union all
328
+ select from_id from reply_to
329
+ where created_at >= ${start} and created_at <= ${end}
330
+ union all
331
+ select from_id from repost
332
+ where created_at >= ${start} and created_at <= ${end}
333
+ union all
334
+ select from_id from bookmarks
335
+ where created_at >= ${start} and created_at <= ${end}
336
+ ),
337
+ scored as (
338
+ select profile_id, count(*)::int as contributions
339
+ from contrib
340
+ group by profile_id
341
+ order by contributions desc
342
+ limit ${limit}
343
+ )
344
+ select
345
+ s.profile_id,
346
+ s.contributions,
347
+ p.handle,
348
+ p.body,
349
+ p.created_at,
350
+ coalesce(
351
+ (
352
+ select r.key from has_role hr
353
+ join roles r on r.id::text = hr.to_id
354
+ where hr.from_id = s.profile_id
355
+ order by case r.key
356
+ when 'owner' then 0
357
+ when 'admin' then 1
358
+ when 'moderator' then 2
359
+ else 3
360
+ end
361
+ limit 1
362
+ ),
363
+ 'member'
364
+ ) as role
365
+ from scored s
366
+ join profiles p on p.id::text = s.profile_id
367
+ where p.created_at is not null
368
+ `);
369
+ return result.rows.map((r) => {
370
+ var _a, _b, _c, _d, _e, _f;
371
+ return ({
372
+ profileId: r.profile_id,
373
+ handle: (_a = r.handle) !== null && _a !== void 0 ? _a : r.profile_id.slice(0, 8),
374
+ displayName: (_e = (_c = (_b = r.body) === null || _b === void 0 ? void 0 : _b.displayName) !== null && _c !== void 0 ? _c : (_d = r.body) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : undefined,
375
+ role: r.role,
376
+ joinedAt: typeof r.created_at === 'string'
377
+ ? r.created_at
378
+ : new Date(r.created_at).toISOString(),
379
+ contributions: Number((_f = r.contributions) !== null && _f !== void 0 ? _f : 0),
380
+ });
381
+ });
382
+ };
383
+ const topPostsByViews = async (from, to, limit = 10) => {
384
+ const db = await database();
385
+ const rows = await db
386
+ .select({
387
+ postId: analyticsPostViewsDaily.postId,
388
+ uniqueViewers: sum(analyticsPostViewsDaily.uniqueViewers),
389
+ viewEvents: sum(analyticsPostViewsDaily.viewEvents),
390
+ body: posts.body,
391
+ type: posts.type,
392
+ handle: profiles.handle,
393
+ profileBody: profiles.body,
394
+ })
395
+ .from(analyticsPostViewsDaily)
396
+ .leftJoin(posts, sql `${posts.id}::text = ${analyticsPostViewsDaily.postId}`)
397
+ .leftJoin(profiles, sql `${profiles.id}::text = ${posts.creatorId}`)
398
+ .where(and(gte(analyticsPostViewsDaily.day, from), lte(analyticsPostViewsDaily.day, to)))
399
+ .groupBy(analyticsPostViewsDaily.postId, posts.body, posts.type, profiles.handle, profiles.body)
400
+ .orderBy(desc(sum(analyticsPostViewsDaily.uniqueViewers)))
401
+ .limit(limit);
402
+ return rows.map((r) => {
403
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
404
+ const body = ((_a = r.body) !== null && _a !== void 0 ? _a : {});
405
+ const content = (_f = (_d = (_c = (_b = body.title) !== null && _b !== void 0 ? _b : body.name) !== null && _c !== void 0 ? _c : body.content) !== null && _d !== void 0 ? _d : (_e = body.data) === null || _e === void 0 ? void 0 : _e.content) !== null && _f !== void 0 ? _f : '';
406
+ const postType = r.type === 'event' && body.jam != null
407
+ ? 'jam'
408
+ : r.type === 'question'
409
+ ? 'poll'
410
+ : ((_g = r.type) !== null && _g !== void 0 ? _g : 'note');
411
+ const profileBody = ((_h = r.profileBody) !== null && _h !== void 0 ? _h : {});
412
+ return {
413
+ postId: r.postId,
414
+ snippet: content.slice(0, 120) || undefined,
415
+ authorHandle: (_j = r.handle) !== null && _j !== void 0 ? _j : undefined,
416
+ authorDisplayName: (_l = (_k = profileBody.displayName) !== null && _k !== void 0 ? _k : profileBody.name) !== null && _l !== void 0 ? _l : undefined,
417
+ postType,
418
+ uniqueViewers: Number((_m = r.uniqueViewers) !== null && _m !== void 0 ? _m : 0),
419
+ viewEvents: Number((_o = r.viewEvents) !== null && _o !== void 0 ? _o : 0),
420
+ };
421
+ });
422
+ };
423
+ const withCache = async (section, from, to, build) => {
424
+ const key = analyticsCacheKey(section, from, to);
425
+ const cached = await getAnalyticsCache(key);
426
+ if (cached)
427
+ return cached;
428
+ const value = await build();
429
+ await setAnalyticsCache(key, value, { includesToday: includesToday(to) });
430
+ return value;
431
+ };
432
+ export const getAnalyticsOverview = async (query = {}) => {
433
+ const range = await resolveQueryRange(query);
434
+ return withCache('overview-v5', range.from, range.to, async () => {
435
+ var _a, _b;
436
+ const [activeMembersSeries, postsSeries, likesSeries, commentsSeries, postsByTypeDaily, topGroupRows, groupGrowth, topPostRows, topMemberRows, compiledAt, totalMembers, totalGroups, allTimePosts, prevActive, prevPosts, prevTotalMembers, prevTotalGroups, prevAllTimePosts,] = await Promise.all([
437
+ loadTotalsSeries(range.from, range.to, 'activeMembers'),
438
+ loadTotalsSeries(range.from, range.to, 'posts'),
439
+ loadTotalsSeries(range.from, range.to, 'likes'),
440
+ loadTotalsSeries(range.from, range.to, 'comments'),
441
+ loadPostsByTypeDaily(range.from, range.to),
442
+ topGroups(range.from, range.to),
443
+ groupGrowthOverTime(range.from, range.to),
444
+ topPostsByViews(range.from, range.to),
445
+ topMembers(range.from, range.to),
446
+ latestCompiledAt(range.from, range.to),
447
+ totalMembersAt(range.to),
448
+ totalGroupsAt(range.to),
449
+ totalPostsAt(range.to),
450
+ sumColumn(range.previousFrom, range.previousTo, 'activeMembers'),
451
+ sumColumn(range.previousFrom, range.previousTo, 'posts'),
452
+ totalMembersAt(range.previousTo),
453
+ totalGroupsAt(range.previousTo),
454
+ totalPostsAt(range.previousTo),
455
+ ]);
456
+ const activeMembers = sumSeries(activeMembersSeries);
457
+ const totalPosts = sumSeries(postsSeries);
458
+ const { buckets } = selectChartBuckets(range.from, range.to);
459
+ const typeTotals = Object.fromEntries(POST_TYPE_KEYS.map((k) => [k, 0]));
460
+ const dailyByType = new Map();
461
+ for (const row of postsByTypeDaily) {
462
+ const kind = POST_TYPE_KEYS.includes(row.kind)
463
+ ? row.kind
464
+ : 'note';
465
+ typeTotals[kind] += row.count;
466
+ const dayMap = (_a = dailyByType.get(row.day)) !== null && _a !== void 0 ? _a : {};
467
+ dayMap[kind] = ((_b = dayMap[kind]) !== null && _b !== void 0 ? _b : 0) + row.count;
468
+ dailyByType.set(row.day, dayMap);
469
+ }
470
+ const postsOverTime = buckets.map((bucket) => {
471
+ var _a;
472
+ const point = {
473
+ day: bucket.key,
474
+ label: bucket.label,
475
+ jam: 0,
476
+ article: 0,
477
+ note: 0,
478
+ poll: 0,
479
+ event: 0,
480
+ };
481
+ for (const day of eachUtcDay(bucket.from, bucket.to)) {
482
+ const dayMap = dailyByType.get(day);
483
+ if (!dayMap)
484
+ continue;
485
+ for (const key of POST_TYPE_KEYS) {
486
+ point[key] += (_a = dayMap[key]) !== null && _a !== void 0 ? _a : 0;
487
+ }
488
+ }
489
+ return point;
490
+ });
491
+ const postTypes = POST_TYPE_KEYS.map((type) => ({
492
+ type,
493
+ count: typeTotals[type],
494
+ }));
495
+ const activeUsersSeries = aggregateSeriesIntoBuckets(activeMembersSeries, buckets);
496
+ const engagementRateSeries = postsSeries.map((p, i) => {
497
+ var _a, _b, _c, _d;
498
+ const engagements = ((_b = (_a = likesSeries[i]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = commentsSeries[i]) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0);
499
+ const postCount = p.value;
500
+ return {
501
+ day: p.day,
502
+ value: postCount === 0
503
+ ? 0
504
+ : Math.round((engagements / postCount) * 1000) / 10,
505
+ };
506
+ });
507
+ return {
508
+ range: Object.assign(Object.assign({}, range), { compiledAt }),
509
+ metrics: {
510
+ totalPosts: metricCard('totalPosts', totalPosts, prevPosts, postsSeries),
511
+ allTimePosts: metricCard('allTimePosts', allTimePosts, prevAllTimePosts),
512
+ totalMembers: metricCard('totalMembers', totalMembers, prevTotalMembers),
513
+ activeMembers: metricCard('activeMembers', activeMembers, prevActive, activeMembersSeries),
514
+ totalGroups: metricCard('totalGroups', totalGroups, prevTotalGroups),
515
+ },
516
+ postsOverTime,
517
+ postTypes,
518
+ activeUsersSeries,
519
+ topMembers: topMemberRows,
520
+ topPosts: topPostRows,
521
+ activitySeries: activeMembersSeries,
522
+ engagementRateSeries,
523
+ topGroups: topGroupRows,
524
+ groupGrowthSeries: groupGrowth.series,
525
+ groupGrowthOverTime: groupGrowth.overTime,
526
+ };
527
+ });
528
+ };
529
+ export const getAnalyticsGrowth = async (query = {}) => {
530
+ const range = await resolveQueryRange(query);
531
+ return withCache('growth-v5', range.from, range.to, async () => {
532
+ const db = await database();
533
+ const [newMembersSeries, prevNew, compiledAt, recentRows] = await Promise.all([
534
+ loadTotalsSeries(range.from, range.to, 'newMembers'),
535
+ sumColumn(range.previousFrom, range.previousTo, 'newMembers'),
536
+ latestCompiledAt(range.from, range.to),
537
+ db.execute(sql `
538
+ select p.id, p.handle, p.body, p.created_at,
539
+ case when r.to_id is not null then 'invite' else 'organic' end as channel
540
+ from profiles p
541
+ left join invite_link_redeemers r on r.to_id = p.id::text
542
+ where p.deleted_at is null
543
+ and p.created_at >= ${`${range.from}T00:00:00.000Z`}
544
+ and p.created_at <= ${`${range.to}T23:59:59.999Z`}
545
+ order by p.created_at desc
546
+ limit 25
547
+ `),
548
+ ]);
549
+ const newSignups = sumSeries(newMembersSeries);
550
+ const byDay = new Map(newMembersSeries.map((p) => [p.day, p.value]));
551
+ const signupsByDay = eachUtcDay(range.from, range.to).map((day) => {
552
+ var _a;
553
+ return ({
554
+ day,
555
+ value: (_a = byDay.get(day)) !== null && _a !== void 0 ? _a : 0,
556
+ });
557
+ });
558
+ const recentSignups = recentRows.rows.map((r) => {
559
+ var _a;
560
+ return ({
561
+ profileId: String(r.id),
562
+ handle: r.handle,
563
+ displayName: (_a = r.body) === null || _a === void 0 ? void 0 : _a.displayName,
564
+ joinedAt: r.created_at,
565
+ channel: r.channel,
566
+ });
567
+ });
568
+ return {
569
+ range: Object.assign(Object.assign({}, range), { compiledAt }),
570
+ metrics: {
571
+ newSignups: metricCard('newSignups', newSignups, prevNew, newMembersSeries),
572
+ },
573
+ signupsByDay,
574
+ recentSignups,
575
+ };
576
+ });
577
+ };
578
+ export const getAnalyticsEngagement = async (query = {}) => {
579
+ const range = await resolveQueryRange(query);
580
+ return withCache('engagement-v3', range.from, range.to, async () => {
581
+ const [likesSeries, commentsSeries, repostsSeries, bookmarksSeries, dmsSeries, viewersSeries, impressionsSeries, prevLikes, prevComments, prevReposts, prevBookmarks, prevDms, prevViewers, prevImpressions, groups, compiledAt,] = await Promise.all([
582
+ loadTotalsSeries(range.from, range.to, 'likes'),
583
+ loadTotalsSeries(range.from, range.to, 'comments'),
584
+ loadTotalsSeries(range.from, range.to, 'reposts'),
585
+ loadTotalsSeries(range.from, range.to, 'bookmarks'),
586
+ loadTotalsSeries(range.from, range.to, 'dms'),
587
+ loadTotalsSeries(range.from, range.to, 'uniqueViewers'),
588
+ loadTotalsSeries(range.from, range.to, 'viewEvents'),
589
+ sumColumn(range.previousFrom, range.previousTo, 'likes'),
590
+ sumColumn(range.previousFrom, range.previousTo, 'comments'),
591
+ sumColumn(range.previousFrom, range.previousTo, 'reposts'),
592
+ sumColumn(range.previousFrom, range.previousTo, 'bookmarks'),
593
+ sumColumn(range.previousFrom, range.previousTo, 'dms'),
594
+ sumColumn(range.previousFrom, range.previousTo, 'uniqueViewers'),
595
+ sumColumn(range.previousFrom, range.previousTo, 'viewEvents'),
596
+ topGroups(range.from, range.to),
597
+ latestCompiledAt(range.from, range.to),
598
+ ]);
599
+ const { buckets } = selectChartBuckets(range.from, range.to);
600
+ const likesByBucket = aggregateSeriesIntoBuckets(likesSeries, buckets);
601
+ const commentsByBucket = aggregateSeriesIntoBuckets(commentsSeries, buckets);
602
+ const repostsByBucket = aggregateSeriesIntoBuckets(repostsSeries, buckets);
603
+ const bookmarksByBucket = aggregateSeriesIntoBuckets(bookmarksSeries, buckets);
604
+ const impressionsByPeriod = aggregateSeriesIntoBuckets(impressionsSeries, buckets);
605
+ const engagementOverTime = buckets.map((bucket, i) => {
606
+ var _a, _b, _c, _d, _e, _f, _g, _h;
607
+ return ({
608
+ day: bucket.key,
609
+ label: bucket.label,
610
+ likes: (_b = (_a = likesByBucket[i]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0,
611
+ comments: (_d = (_c = commentsByBucket[i]) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0,
612
+ reposts: (_f = (_e = repostsByBucket[i]) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : 0,
613
+ bookmarks: (_h = (_g = bookmarksByBucket[i]) === null || _g === void 0 ? void 0 : _g.value) !== null && _h !== void 0 ? _h : 0,
614
+ });
615
+ });
616
+ return {
617
+ range: Object.assign(Object.assign({}, range), { compiledAt }),
618
+ metrics: {
619
+ likes: metricCard('likes', sumSeries(likesSeries), prevLikes, likesSeries),
620
+ comments: metricCard('comments', sumSeries(commentsSeries), prevComments, commentsSeries),
621
+ reposts: metricCard('reposts', sumSeries(repostsSeries), prevReposts, repostsSeries),
622
+ bookmarks: metricCard('bookmarks', sumSeries(bookmarksSeries), prevBookmarks, bookmarksSeries),
623
+ dms: metricCard('dms', sumSeries(dmsSeries), prevDms, dmsSeries),
624
+ uniqueViewers: metricCard('uniqueViewers', sumSeries(viewersSeries), prevViewers, viewersSeries),
625
+ impressions: metricCard('impressions', sumSeries(impressionsSeries), prevImpressions, impressionsSeries),
626
+ },
627
+ engagementOverTime,
628
+ impressionsByPeriod,
629
+ postsByGroup: groups,
630
+ };
631
+ });
632
+ };
633
+ export const getAnalyticsRetention = async (query = {}) => {
634
+ const range = await resolveQueryRange(query);
635
+ return withCache('retention-v2', range.from, range.to, async () => {
636
+ const db = await database();
637
+ const [cohortRows, groups, compiledAt] = await Promise.all([
638
+ db
639
+ .select()
640
+ .from(analyticsRetentionCohorts)
641
+ .where(and(gte(analyticsRetentionCohorts.cohortWeek, range.from), lte(analyticsRetentionCohorts.cohortWeek, range.to)))
642
+ .orderBy(asc(analyticsRetentionCohorts.cohortWeek)),
643
+ topGroups(range.from, range.to),
644
+ latestCompiledAt(range.from, range.to),
645
+ ]);
646
+ const rates = cohortRows.map((c) => c.rates);
647
+ const avg = (key) => {
648
+ if (rates.length === 0)
649
+ return 0;
650
+ return (Math.round((rates.reduce((a, r) => { var _a; return a + Number((_a = r[key]) !== null && _a !== void 0 ? _a : 0); }, 0) / rates.length) *
651
+ 10) / 10);
652
+ };
653
+ return {
654
+ range: Object.assign(Object.assign({}, range), { compiledAt }),
655
+ metrics: {
656
+ day1: metricCard('day1', avg('1'), 0),
657
+ day7: metricCard('day7', avg('7'), 0),
658
+ day30: metricCard('day30', avg('30'), 0),
659
+ },
660
+ cohorts: cohortRows.map((c) => {
661
+ var _a;
662
+ return ({
663
+ cohortWeek: c.cohortWeek,
664
+ cohortSize: c.cohortSize,
665
+ rates: ((_a = c.rates) !== null && _a !== void 0 ? _a : {}),
666
+ });
667
+ }),
668
+ retentionByGroup: groups,
669
+ };
670
+ });
671
+ };
672
+ export const exportAnalyticsCsv = async (query = {}) => {
673
+ const overview = await getAnalyticsOverview(query);
674
+ const lines = [
675
+ 'bucket,label,active_members,posts,jams,articles,notes,polls,events',
676
+ ...overview.activeUsersSeries.map((p, i) => {
677
+ var _a, _b, _c, _d, _e;
678
+ const posts = overview.postsOverTime[i];
679
+ const postTotal = posts
680
+ ? posts.jam + posts.article + posts.note + posts.poll + posts.event
681
+ : 0;
682
+ return [
683
+ p.day,
684
+ p.label,
685
+ p.value,
686
+ postTotal,
687
+ (_a = posts === null || posts === void 0 ? void 0 : posts.jam) !== null && _a !== void 0 ? _a : 0,
688
+ (_b = posts === null || posts === void 0 ? void 0 : posts.article) !== null && _b !== void 0 ? _b : 0,
689
+ (_c = posts === null || posts === void 0 ? void 0 : posts.note) !== null && _c !== void 0 ? _c : 0,
690
+ (_d = posts === null || posts === void 0 ? void 0 : posts.poll) !== null && _d !== void 0 ? _d : 0,
691
+ (_e = posts === null || posts === void 0 ? void 0 : posts.event) !== null && _e !== void 0 ? _e : 0,
692
+ ].join(',');
693
+ }),
694
+ ];
695
+ return lines.join('\n');
696
+ };