@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.
- package/LICENSE +674 -0
- package/dist/accessTokens/finders.d.ts +11 -0
- package/dist/accessTokens/finders.js +43 -0
- package/dist/accessTokens/helpers.d.ts +13 -0
- package/dist/accessTokens/helpers.js +15 -0
- package/dist/accessTokens/index.d.ts +4 -0
- package/dist/accessTokens/index.js +4 -0
- package/dist/accessTokens/mapping.d.ts +10 -0
- package/dist/accessTokens/mapping.js +25 -0
- package/dist/accessTokens/mutations.d.ts +4 -0
- package/dist/accessTokens/mutations.js +24 -0
- package/dist/accessTokens/revokations.d.ts +2 -0
- package/dist/accessTokens/revokations.js +18 -0
- package/dist/accessTokens/tokens.d.ts +31 -0
- package/dist/accessTokens/tokens.js +174 -0
- package/dist/accounts/cache.d.ts +3 -0
- package/dist/accounts/cache.js +13 -0
- package/dist/accounts/finders.d.ts +6 -0
- package/dist/accounts/finders.js +17 -0
- package/dist/accounts/helpers.d.ts +7 -0
- package/dist/accounts/helpers.js +36 -0
- package/dist/accounts/index.d.ts +6 -0
- package/dist/accounts/index.js +6 -0
- package/dist/accounts/mapping.d.ts +10 -0
- package/dist/accounts/mapping.js +28 -0
- package/dist/accounts/mutations.d.ts +21 -0
- package/dist/accounts/mutations.js +204 -0
- package/dist/analytics/cache.d.ts +6 -0
- package/dist/analytics/cache.js +29 -0
- package/dist/analytics/compile.d.ts +4 -0
- package/dist/analytics/compile.js +296 -0
- package/dist/analytics/dateRange.d.ts +39 -0
- package/dist/analytics/dateRange.js +181 -0
- package/dist/analytics/index.d.ts +8 -0
- package/dist/analytics/index.js +8 -0
- package/dist/analytics/jobs.d.ts +20 -0
- package/dist/analytics/jobs.js +84 -0
- package/dist/analytics/metrics.d.ts +4 -0
- package/dist/analytics/metrics.js +13 -0
- package/dist/analytics/pdfReport.d.ts +8 -0
- package/dist/analytics/pdfReport.js +821 -0
- package/dist/analytics/read.d.ts +6 -0
- package/dist/analytics/read.js +696 -0
- package/dist/analytics/report.d.ts +293 -0
- package/dist/analytics/report.js +153 -0
- package/dist/analytics/settings.d.ts +3 -0
- package/dist/analytics/settings.js +37 -0
- package/dist/backups/index.d.ts +5 -0
- package/dist/backups/index.js +260 -0
- package/dist/backups/metadata.d.ts +9 -0
- package/dist/backups/metadata.js +2 -0
- package/dist/config/db.d.ts +7 -0
- package/dist/config/db.js +26 -0
- package/dist/config/defaults/capabilities.d.ts +2 -0
- package/dist/config/defaults/capabilities.js +47 -0
- package/dist/config/defaults/community.d.ts +2 -0
- package/dist/config/defaults/community.js +41 -0
- package/dist/config/defaults/core.d.ts +2 -0
- package/dist/config/defaults/core.js +113 -0
- package/dist/config/defaults/db.d.ts +6 -0
- package/dist/config/defaults/db.js +8 -0
- package/dist/config/defaults/logs.d.ts +6 -0
- package/dist/config/defaults/logs.js +7 -0
- package/dist/config/defaults/redis.d.ts +4 -0
- package/dist/config/defaults/redis.js +5 -0
- package/dist/config/helpers.d.ts +11 -0
- package/dist/config/helpers.js +31 -0
- package/dist/config/index.d.ts +392 -0
- package/dist/config/index.js +83 -0
- package/dist/config/pruneEmptyConfigStrings.d.ts +7 -0
- package/dist/config/pruneEmptyConfigStrings.js +29 -0
- package/dist/db/aql.d.ts +0 -0
- package/dist/db/aql.js +1 -0
- package/dist/db/arango.d.ts +2 -0
- package/dist/db/arango.js +110 -0
- package/dist/db/bootMigrate.d.ts +1 -0
- package/dist/db/bootMigrate.js +15 -0
- package/dist/db/examples.d.ts +1 -0
- package/dist/db/examples.js +13 -0
- package/dist/db/explorer/csv.d.ts +1 -0
- package/dist/db/explorer/csv.js +18 -0
- package/dist/db/explorer/index.d.ts +6 -0
- package/dist/db/explorer/index.js +5 -0
- package/dist/db/explorer/mutate.d.ts +6 -0
- package/dist/db/explorer/mutate.js +66 -0
- package/dist/db/explorer/query.d.ts +17 -0
- package/dist/db/explorer/query.js +48 -0
- package/dist/db/explorer/sql.d.ts +11 -0
- package/dist/db/explorer/sql.js +42 -0
- package/dist/db/explorer/tables.d.ts +9 -0
- package/dist/db/explorer/tables.js +65 -0
- package/dist/db/helpers.d.ts +64 -0
- package/dist/db/helpers.js +240 -0
- package/dist/db/index.d.ts +13 -0
- package/dist/db/index.js +15 -0
- package/dist/db/init.d.ts +2 -0
- package/dist/db/init.js +10 -0
- package/dist/db/migration/autoMigrate.d.ts +2 -0
- package/dist/db/migration/autoMigrate.js +111 -0
- package/dist/db/migration/cli.d.ts +1 -0
- package/dist/db/migration/cli.js +56 -0
- package/dist/db/migration/detect.d.ts +6 -0
- package/dist/db/migration/detect.js +87 -0
- package/dist/db/migration/exportArango.d.ts +4 -0
- package/dist/db/migration/exportArango.js +80 -0
- package/dist/db/migration/importCollections.d.ts +19 -0
- package/dist/db/migration/importCollections.js +280 -0
- package/dist/db/migration/importPostgres.d.ts +3 -0
- package/dist/db/migration/importPostgres.js +18 -0
- package/dist/db/migration/shared.d.ts +39 -0
- package/dist/db/migration/shared.js +158 -0
- package/dist/db/migration/transform.d.ts +18 -0
- package/dist/db/migration/transform.js +209 -0
- package/dist/db/migration/validate.d.ts +18 -0
- package/dist/db/migration/validate.js +69 -0
- package/dist/db/pg/client.d.ts +35 -0
- package/dist/db/pg/client.js +126 -0
- package/dist/db/pg/collections.d.ts +48 -0
- package/dist/db/pg/collections.js +53 -0
- package/dist/db/pg/filters/common.d.ts +21 -0
- package/dist/db/pg/filters/common.js +48 -0
- package/dist/db/pg/filters/edges.d.ts +9 -0
- package/dist/db/pg/filters/edges.js +10 -0
- package/dist/db/pg/filters/groups.d.ts +7 -0
- package/dist/db/pg/filters/groups.js +15 -0
- package/dist/db/pg/filters/index.d.ts +22 -0
- package/dist/db/pg/filters/index.js +35 -0
- package/dist/db/pg/filters/notifications.d.ts +6 -0
- package/dist/db/pg/filters/notifications.js +10 -0
- package/dist/db/pg/filters/posts.d.ts +18 -0
- package/dist/db/pg/filters/posts.js +25 -0
- package/dist/db/pg/filters/profiles.d.ts +6 -0
- package/dist/db/pg/filters/profiles.js +9 -0
- package/dist/db/pg/filters/types.d.ts +7 -0
- package/dist/db/pg/filters/types.js +5 -0
- package/dist/db/pg/helpers.d.ts +19 -0
- package/dist/db/pg/helpers.js +67 -0
- package/dist/db/pg/map/filters.d.ts +22 -0
- package/dist/db/pg/map/filters.js +566 -0
- package/dist/db/pg/map/helpers.d.ts +2 -0
- package/dist/db/pg/map/helpers.js +2 -0
- package/dist/db/pg/map/index.d.ts +46 -0
- package/dist/db/pg/map/index.js +93 -0
- package/dist/db/pg/map/mutations.d.ts +11 -0
- package/dist/db/pg/map/mutations.js +135 -0
- package/dist/db/pg/map/queryTypes.d.ts +115 -0
- package/dist/db/pg/map/queryTypes.js +1 -0
- package/dist/db/pg/map/registry.d.ts +29 -0
- package/dist/db/pg/map/registry.js +413 -0
- package/dist/db/pg/map/relations.d.ts +28 -0
- package/dist/db/pg/map/relations.js +399 -0
- package/dist/db/pg/map/search.d.ts +6 -0
- package/dist/db/pg/map/search.js +190 -0
- package/dist/db/pg/map/types.d.ts +11 -0
- package/dist/db/pg/map/types.js +1 -0
- package/dist/db/pg/mappers.d.ts +28 -0
- package/dist/db/pg/mappers.js +29 -0
- package/dist/db/pg/migrate.d.ts +14 -0
- package/dist/db/pg/migrate.js +134 -0
- package/dist/db/pg/queries/activity.d.ts +10 -0
- package/dist/db/pg/queries/activity.js +47 -0
- package/dist/db/pg/queries/computed.d.ts +7 -0
- package/dist/db/pg/queries/computed.js +19 -0
- package/dist/db/pg/queries/derived.d.ts +22 -0
- package/dist/db/pg/queries/derived.js +100 -0
- package/dist/db/pg/queries/index.d.ts +4 -0
- package/dist/db/pg/queries/index.js +4 -0
- package/dist/db/pg/queries/sorts.d.ts +10 -0
- package/dist/db/pg/queries/sorts.js +9 -0
- package/dist/db/pg/schema/analytics.d.ts +998 -0
- package/dist/db/pg/schema/analytics.js +110 -0
- package/dist/db/pg/schema/base.d.ts +36 -0
- package/dist/db/pg/schema/base.js +23 -0
- package/dist/db/pg/schema/documents.d.ts +2002 -0
- package/dist/db/pg/schema/documents.js +40 -0
- package/dist/db/pg/schema/edges.d.ts +2725 -0
- package/dist/db/pg/schema/edges.js +34 -0
- package/dist/db/pg/schema/index.d.ts +5724 -0
- package/dist/db/pg/schema/index.js +7 -0
- package/dist/db/pg/sql/0000_bizarre_chat.sql +456 -0
- package/dist/db/pg/sql/0001_search_vector.sql +122 -0
- package/dist/db/pg/sql/0002_data_migrations_id_text.sql +1 -0
- package/dist/db/pg/sql/0003_fix_group_post_visibility.sql +4 -0
- package/dist/db/pg/sql/0004_analytics.sql +90 -0
- package/dist/db/pg/sql/meta/0000_snapshot.json +3380 -0
- package/dist/db/pg/sql/meta/0004_snapshot.json +4114 -0
- package/dist/db/pg/sql/meta/_journal.json +41 -0
- package/dist/db/replaceHostname.d.ts +1 -0
- package/dist/db/replaceHostname.js +88 -0
- package/dist/db/types.d.ts +17 -0
- package/dist/db/types.js +1 -0
- package/dist/email/index.d.ts +9 -0
- package/dist/email/index.js +19 -0
- package/dist/email/jobs.d.ts +3 -0
- package/dist/email/jobs.js +13 -0
- package/dist/email/queueStats.d.ts +2 -0
- package/dist/email/queueStats.js +27 -0
- package/dist/email/registry.d.ts +3 -0
- package/dist/email/registry.js +4 -0
- package/dist/email/render.d.ts +8 -0
- package/dist/email/render.js +34 -0
- package/dist/email/send.d.ts +9 -0
- package/dist/email/send.js +97 -0
- package/dist/email/smtpTest.d.ts +2 -0
- package/dist/email/smtpTest.js +26 -0
- package/dist/errors/index.d.ts +8 -0
- package/dist/errors/index.js +13 -0
- package/dist/events/index.d.ts +31 -0
- package/dist/events/index.js +66 -0
- package/dist/events/once.d.ts +4 -0
- package/dist/events/once.js +23 -0
- package/dist/groups/finders.d.ts +125 -0
- package/dist/groups/finders.js +18 -0
- package/dist/groups/helpers.d.ts +227 -0
- package/dist/groups/helpers.js +17 -0
- package/dist/groups/index.d.ts +3 -0
- package/dist/groups/index.js +3 -0
- package/dist/groups/mapping.d.ts +188 -0
- package/dist/groups/mapping.js +47 -0
- package/dist/groups/mutations.d.ts +26 -0
- package/dist/groups/mutations.js +41 -0
- package/dist/hashtags/finders.d.ts +3 -0
- package/dist/hashtags/finders.js +22 -0
- package/dist/hashtags/index.d.ts +2 -0
- package/dist/hashtags/index.js +2 -0
- package/dist/hashtags/mapping.d.ts +4 -0
- package/dist/hashtags/mapping.js +5 -0
- package/dist/hashtags/mutations.d.ts +0 -0
- package/dist/hashtags/mutations.js +1 -0
- package/dist/i18n/index.d.ts +14 -0
- package/dist/i18n/index.js +53 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +1 -0
- package/dist/inviteLinks/finders.d.ts +3 -0
- package/dist/inviteLinks/finders.js +5 -0
- package/dist/inviteLinks/helpers.d.ts +20 -0
- package/dist/inviteLinks/helpers.js +4 -0
- package/dist/inviteLinks/index.d.ts +3 -0
- package/dist/inviteLinks/index.js +3 -0
- package/dist/inviteLinks/mapping.d.ts +10 -0
- package/dist/inviteLinks/mapping.js +35 -0
- package/dist/inviteLinks/mutations.d.ts +4 -0
- package/dist/inviteLinks/mutations.js +39 -0
- package/dist/jams/cache.d.ts +9 -0
- package/dist/jams/cache.js +13 -0
- package/dist/jams/finders.d.ts +23 -0
- package/dist/jams/finders.js +24 -0
- package/dist/jams/helpers.d.ts +70 -0
- package/dist/jams/helpers.js +29 -0
- package/dist/jams/index.d.ts +15 -0
- package/dist/jams/index.js +108 -0
- package/dist/jams/jobs.d.ts +9 -0
- package/dist/jams/jobs.js +42 -0
- package/dist/jams/livekit.d.ts +24 -0
- package/dist/jams/livekit.js +220 -0
- package/dist/jams/mapping.d.ts +137 -0
- package/dist/jams/mapping.js +35 -0
- package/dist/jams/mutations.d.ts +40 -0
- package/dist/jams/mutations.js +4 -0
- package/dist/jams/recording.d.ts +8 -0
- package/dist/jams/recording.js +67 -0
- package/dist/jams/recordingUploadAuth.d.ts +9 -0
- package/dist/jams/recordingUploadAuth.js +19 -0
- package/dist/jams/token.d.ts +4 -0
- package/dist/jams/token.js +129 -0
- package/dist/jams/waitingRoom.d.ts +5 -0
- package/dist/jams/waitingRoom.js +71 -0
- package/dist/jobs/index.d.ts +10 -0
- package/dist/jobs/index.js +60 -0
- package/dist/jobs/jobDetail.d.ts +2 -0
- package/dist/jobs/jobDetail.js +31 -0
- package/dist/jobs/jobLog.d.ts +18 -0
- package/dist/jobs/jobLog.js +61 -0
- package/dist/jwt/index.d.ts +10 -0
- package/dist/jwt/index.js +43 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +2 -0
- package/dist/lib/streams.d.ts +2 -0
- package/dist/lib/streams.js +56 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +17 -0
- package/dist/lib/zodDeepPartial.d.ts +3 -0
- package/dist/lib/zodDeepPartial.js +26 -0
- package/dist/location/index.d.ts +2 -0
- package/dist/location/index.js +28 -0
- package/dist/log/index.d.ts +3 -0
- package/dist/log/index.js +97 -0
- package/dist/mastodon/index.d.ts +4 -0
- package/dist/mastodon/index.js +51 -0
- package/dist/mastodon/types.d.ts +7579 -0
- package/dist/mastodon/types.js +523 -0
- package/dist/mastodon/typescript.d.ts +1578 -0
- package/dist/mastodon/typescript.js +1 -0
- package/dist/media/index.d.ts +40 -0
- package/dist/media/index.js +248 -0
- package/dist/media/ipfs/index.d.ts +0 -0
- package/dist/media/ipfs/index.js +39 -0
- package/dist/media/jobs.d.ts +19 -0
- package/dist/media/jobs.js +90 -0
- package/dist/media/openpeeps/index.d.ts +3 -0
- package/dist/media/openpeeps/index.js +131 -0
- package/dist/media/processing.d.ts +19 -0
- package/dist/media/processing.js +83 -0
- package/dist/media/streaming.d.ts +77 -0
- package/dist/media/streaming.js +257 -0
- package/dist/media/streamingCleanupJobs.d.ts +14 -0
- package/dist/media/streamingCleanupJobs.js +47 -0
- package/dist/media/streamingJobs.d.ts +5 -0
- package/dist/media/streamingJobs.js +329 -0
- package/dist/media/streamingPrewarm.d.ts +36 -0
- package/dist/media/streamingPrewarm.js +109 -0
- package/dist/mediaAttachments/finders.d.ts +1 -0
- package/dist/mediaAttachments/finders.js +3 -0
- package/dist/mediaAttachments/index.d.ts +5 -0
- package/dist/mediaAttachments/index.js +12 -0
- package/dist/mediaAttachments/mapping.d.ts +21 -0
- package/dist/mediaAttachments/mapping.js +4 -0
- package/dist/mediaAttachments/mutations.d.ts +3 -0
- package/dist/mediaAttachments/mutations.js +10 -0
- package/dist/notifications/defaultNotifications/announcement/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/announcement/index.js +42 -0
- package/dist/notifications/defaultNotifications/directMessage/index.d.ts +28 -0
- package/dist/notifications/defaultNotifications/directMessage/index.js +69 -0
- package/dist/notifications/defaultNotifications/follow/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/follow/index.js +31 -0
- package/dist/notifications/defaultNotifications/groupAdded/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/groupAdded/index.js +33 -0
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +36 -0
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +36 -0
- package/dist/notifications/defaultNotifications/index.d.ts +3 -0
- package/dist/notifications/defaultNotifications/index.js +43 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.d.ts +23 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.js +49 -0
- package/dist/notifications/defaultNotifications/jamSpeaker/index.d.ts +23 -0
- package/dist/notifications/defaultNotifications/jamSpeaker/index.js +47 -0
- package/dist/notifications/defaultNotifications/jamStarted/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/jamStarted/index.js +82 -0
- package/dist/notifications/defaultNotifications/mention/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/mention/index.js +89 -0
- package/dist/notifications/defaultNotifications/newGroupPost/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +47 -0
- package/dist/notifications/defaultNotifications/newProfile/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/newProfile/index.js +40 -0
- package/dist/notifications/defaultNotifications/pollVote/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/pollVote/index.js +40 -0
- package/dist/notifications/defaultNotifications/reaction/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/reaction/index.js +43 -0
- package/dist/notifications/defaultNotifications/reply/index.d.ts +25 -0
- package/dist/notifications/defaultNotifications/reply/index.js +57 -0
- package/dist/notifications/defaultNotifications/repost/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/repost/index.js +42 -0
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/rsvp/index.js +40 -0
- package/dist/notifications/fcmCredential.d.ts +14 -0
- package/dist/notifications/fcmCredential.js +68 -0
- package/dist/notifications/finders.d.ts +7 -0
- package/dist/notifications/finders.js +13 -0
- package/dist/notifications/firebase.d.ts +1 -0
- package/dist/notifications/firebase.js +33 -0
- package/dist/notifications/handlers.d.ts +3 -0
- package/dist/notifications/handlers.js +6 -0
- package/dist/notifications/helpers.d.ts +7 -0
- package/dist/notifications/helpers.js +31 -0
- package/dist/notifications/index.d.ts +9 -0
- package/dist/notifications/index.js +43 -0
- package/dist/notifications/jobs.d.ts +2 -0
- package/dist/notifications/jobs.js +75 -0
- package/dist/notifications/mapping.d.ts +25 -0
- package/dist/notifications/mapping.js +25 -0
- package/dist/notifications/mutations.d.ts +6 -0
- package/dist/notifications/mutations.js +40 -0
- package/dist/notifications/push.d.ts +9 -0
- package/dist/notifications/push.js +261 -0
- package/dist/notifications/pushInvalidation.d.ts +10 -0
- package/dist/notifications/pushInvalidation.js +10 -0
- package/dist/performance/index.d.ts +24 -0
- package/dist/performance/index.js +61 -0
- package/dist/plugins/helpers.d.ts +3 -0
- package/dist/plugins/helpers.js +72 -0
- package/dist/plugins/index.d.ts +10 -0
- package/dist/plugins/index.js +84 -0
- package/dist/plugins/pluginAuth.d.ts +30 -0
- package/dist/plugins/pluginAuth.js +44 -0
- package/dist/posts/contextClosure.d.ts +16 -0
- package/dist/posts/contextClosure.js +66 -0
- package/dist/posts/finders.d.ts +298 -0
- package/dist/posts/finders.js +259 -0
- package/dist/posts/helpers/filters.d.ts +14 -0
- package/dist/posts/helpers/filters.js +39 -0
- package/dist/posts/helpers/index.d.ts +837 -0
- package/dist/posts/helpers/index.js +117 -0
- package/dist/posts/index.d.ts +6 -0
- package/dist/posts/index.js +6 -0
- package/dist/posts/mapping.d.ts +2187 -0
- package/dist/posts/mapping.js +222 -0
- package/dist/posts/mutations.d.ts +19 -0
- package/dist/posts/mutations.js +202 -0
- package/dist/posts/rsvpConfirmationEmail.d.ts +2 -0
- package/dist/posts/rsvpConfirmationEmail.js +82 -0
- package/dist/processingStats/index.d.ts +3 -0
- package/dist/processingStats/index.js +3 -0
- package/dist/processingStats/mapping.d.ts +7 -0
- package/dist/processingStats/mapping.js +4 -0
- package/dist/processingStats/mutations.d.ts +2 -0
- package/dist/processingStats/mutations.js +6 -0
- package/dist/processingStats/queries.d.ts +4 -0
- package/dist/processingStats/queries.js +46 -0
- package/dist/profileSettings/cache.d.ts +2 -0
- package/dist/profileSettings/cache.js +24 -0
- package/dist/profileSettings/finders.d.ts +1 -0
- package/dist/profileSettings/finders.js +2 -0
- package/dist/profileSettings/index.d.ts +3 -0
- package/dist/profileSettings/index.js +3 -0
- package/dist/profileSettings/mapping.d.ts +38 -0
- package/dist/profileSettings/mapping.js +5 -0
- package/dist/profileSettings/mutations.d.ts +3 -0
- package/dist/profileSettings/mutations.js +24 -0
- package/dist/profiles/cache.d.ts +5 -0
- package/dist/profiles/cache.js +19 -0
- package/dist/profiles/capacity.d.ts +2 -0
- package/dist/profiles/capacity.js +20 -0
- package/dist/profiles/export.d.ts +3 -0
- package/dist/profiles/export.js +85 -0
- package/dist/profiles/finders.d.ts +11 -0
- package/dist/profiles/finders.js +39 -0
- package/dist/profiles/helpers.d.ts +35 -0
- package/dist/profiles/helpers.js +10 -0
- package/dist/profiles/index.d.ts +5 -0
- package/dist/profiles/index.js +18 -0
- package/dist/profiles/mapping.d.ts +157 -0
- package/dist/profiles/mapping.js +132 -0
- package/dist/profiles/mutations.d.ts +9 -0
- package/dist/profiles/mutations.js +75 -0
- package/dist/pushSubscriptions/finders.d.ts +187 -0
- package/dist/pushSubscriptions/finders.js +6 -0
- package/dist/pushSubscriptions/helpers.d.ts +99 -0
- package/dist/pushSubscriptions/helpers.js +3 -0
- package/dist/pushSubscriptions/index.d.ts +3 -0
- package/dist/pushSubscriptions/index.js +3 -0
- package/dist/pushSubscriptions/mapping.d.ts +261 -0
- package/dist/pushSubscriptions/mapping.js +6 -0
- package/dist/pushSubscriptions/mutations.d.ts +95 -0
- package/dist/pushSubscriptions/mutations.js +21 -0
- package/dist/redis/connection.d.ts +4 -0
- package/dist/redis/connection.js +17 -0
- package/dist/redis/index.d.ts +1 -0
- package/dist/redis/index.js +1 -0
- package/dist/reports/finders.d.ts +6 -0
- package/dist/reports/finders.js +44 -0
- package/dist/reports/helpers.d.ts +21 -0
- package/dist/reports/helpers.js +12 -0
- package/dist/reports/index.d.ts +3 -0
- package/dist/reports/index.js +3 -0
- package/dist/reports/mapping.d.ts +9 -0
- package/dist/reports/mapping.js +34 -0
- package/dist/reports/mutations.d.ts +5 -0
- package/dist/reports/mutations.js +16 -0
- package/dist/roles/defaults.d.ts +2 -0
- package/dist/roles/defaults.js +94 -0
- package/dist/roles/finders.d.ts +5 -0
- package/dist/roles/finders.js +9 -0
- package/dist/roles/index.d.ts +4 -0
- package/dist/roles/index.js +4 -0
- package/dist/roles/mapping.d.ts +11 -0
- package/dist/roles/mapping.js +5 -0
- package/dist/roles/mutations.d.ts +4 -0
- package/dist/roles/mutations.js +30 -0
- package/dist/search/finders.d.ts +47 -0
- package/dist/search/finders.js +59 -0
- package/dist/search/helpers.d.ts +3 -0
- package/dist/search/helpers.js +1 -0
- package/dist/search/index.d.ts +1 -0
- package/dist/search/index.js +1 -0
- package/dist/search/mapping.d.ts +40 -0
- package/dist/search/mapping.js +43 -0
- package/dist/sentry/index.d.ts +34 -0
- package/dist/sentry/index.js +113 -0
- package/dist/server/helpers.d.ts +0 -0
- package/dist/server/helpers.js +1 -0
- package/dist/server/index.d.ts +105 -0
- package/dist/server/index.js +64 -0
- package/dist/stats/finders.d.ts +16156 -0
- package/dist/stats/finders.js +167 -0
- package/dist/stats/helpers.d.ts +17 -0
- package/dist/stats/helpers.js +34 -0
- package/dist/stats/index.d.ts +1 -0
- package/dist/stats/index.js +1 -0
- package/dist/stats/mapping.d.ts +188 -0
- package/dist/stats/mapping.js +19 -0
- package/dist/stripe/cache.d.ts +30 -0
- package/dist/stripe/cache.js +37 -0
- package/dist/stripe/connection.d.ts +5 -0
- package/dist/stripe/connection.js +23 -0
- package/dist/stripe/helpers.d.ts +25 -0
- package/dist/stripe/helpers.js +211 -0
- package/dist/stripe/index.d.ts +3 -0
- package/dist/stripe/index.js +3 -0
- package/package.json +99 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { createSignedProfileAccessToken } from '../accessTokens/tokens.js';
|
|
2
|
+
import { jwtUtil } from '../jwt/index.js';
|
|
3
|
+
import { serverRootUrl } from '../server/index.js';
|
|
4
|
+
import { emailService } from '../email/index.js';
|
|
5
|
+
import { allpeepDb, collectionInfos } from '../db/index.js';
|
|
6
|
+
import { communityConfig, config } from '../config/index.js';
|
|
7
|
+
import { accountsMapping } from './mapping.js';
|
|
8
|
+
import { accountsCache } from './cache.js';
|
|
9
|
+
import { assignRole, unassignRole } from '../profiles/mutations.js';
|
|
10
|
+
import { hash } from 'bcrypt';
|
|
11
|
+
import { profilesMapping } from '../profiles/mapping.js';
|
|
12
|
+
import { assertProfileCapacity } from '../profiles/capacity.js';
|
|
13
|
+
import { findRoleByKey } from '../roles/index.js';
|
|
14
|
+
import { log, normalizeEmailAddress, sendEmailValidationMail, sendWelcomeEmail, } from './helpers.js';
|
|
15
|
+
import { findAccountByEmail } from './finders.js';
|
|
16
|
+
import { inviteLinksMapping } from '../inviteLinks/mapping.js';
|
|
17
|
+
import { redeemInviteLink } from '../inviteLinks/mutations.js';
|
|
18
|
+
import { conflict } from '../errors/index.js';
|
|
19
|
+
import { connector } from '../db/helpers.js';
|
|
20
|
+
import { hub } from '../events/index.js';
|
|
21
|
+
import { deletePushSubscription, listPushSubscriptionsByAccount, } from '../pushSubscriptions/index.js';
|
|
22
|
+
export const createAccount = async (accountCreationData) => {
|
|
23
|
+
const { db } = await allpeepDb();
|
|
24
|
+
const coreConfig = await config();
|
|
25
|
+
const communityConf = await communityConfig();
|
|
26
|
+
const { email, password, emailValidated = false, inviteCode, } = accountCreationData;
|
|
27
|
+
const normalizedEmail = normalizeEmailAddress(email); // We know that email is not undefined because of the schema
|
|
28
|
+
const firstAccount = (await accountsMapping.count(db)) === 0;
|
|
29
|
+
if (await findAccountByEmail(normalizedEmail)) {
|
|
30
|
+
throw conflict({
|
|
31
|
+
errorKey: 'emailAlreadyTaken',
|
|
32
|
+
parameters: { email: normalizedEmail },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (accountCreationData.profile &&
|
|
36
|
+
(await profilesMapping.findOneBy(db, {
|
|
37
|
+
matches: {
|
|
38
|
+
handle: accountCreationData.profile.handle,
|
|
39
|
+
activityPub: { domain: coreConfig.activityPub.defaultDomain },
|
|
40
|
+
},
|
|
41
|
+
}))) {
|
|
42
|
+
throw conflict({
|
|
43
|
+
errorKey: 'handleAlreadyTaken',
|
|
44
|
+
parameters: {
|
|
45
|
+
handle: accountCreationData.profile.handle,
|
|
46
|
+
domain: coreConfig.activityPub.defaultDomain,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const account = await accountsMapping.create(db, {
|
|
51
|
+
email: normalizedEmail,
|
|
52
|
+
passwordHash: await hash(password, 1024),
|
|
53
|
+
emailValidated,
|
|
54
|
+
});
|
|
55
|
+
await accountsCache.del(normalizedEmail);
|
|
56
|
+
await accountsCache.del(account.id);
|
|
57
|
+
let profile;
|
|
58
|
+
if (accountCreationData.profile) {
|
|
59
|
+
await assertProfileCapacity();
|
|
60
|
+
const { handle, displayName, avatar } = accountCreationData.profile;
|
|
61
|
+
profile = await profilesMapping.create(db, {
|
|
62
|
+
handle,
|
|
63
|
+
displayName,
|
|
64
|
+
avatar,
|
|
65
|
+
activityPub: {
|
|
66
|
+
domain: coreConfig.activityPub.defaultDomain,
|
|
67
|
+
},
|
|
68
|
+
type: 'local',
|
|
69
|
+
});
|
|
70
|
+
if (firstAccount && profile) {
|
|
71
|
+
const ownerRole = await findRoleByKey('owner');
|
|
72
|
+
if (ownerRole) {
|
|
73
|
+
await assignRole(profile, ownerRole);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
log.error('Owner role missing');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
await hub.emit('profileCreated', profile);
|
|
81
|
+
const registrationRoleKeys = communityConf.roles.onRegistration.add;
|
|
82
|
+
for (const roleKey of registrationRoleKeys) {
|
|
83
|
+
const role = await findRoleByKey(roleKey);
|
|
84
|
+
if (role) {
|
|
85
|
+
await assignRole(profile, role);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
log.error(`Role ${roleKey} missing`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (inviteCode) {
|
|
93
|
+
// validate invite code
|
|
94
|
+
const inviteLink = await inviteLinksMapping.findOneBy(db, {
|
|
95
|
+
matches: { slug: inviteCode },
|
|
96
|
+
});
|
|
97
|
+
if (inviteLink) {
|
|
98
|
+
await redeemInviteLink(inviteLink, profile);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
log.error(`Invalid invite code ${inviteCode}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
await giveControl(db, account, profile);
|
|
105
|
+
await accountsCache.del(account.id);
|
|
106
|
+
await accountsCache.del(account.email);
|
|
107
|
+
}
|
|
108
|
+
await sendWelcomeEmail(account);
|
|
109
|
+
if (account && !emailValidated) {
|
|
110
|
+
await sendEmailValidationMail(account);
|
|
111
|
+
}
|
|
112
|
+
return { account, profile };
|
|
113
|
+
};
|
|
114
|
+
export const updateAccount = async (accountData) => {
|
|
115
|
+
var _a;
|
|
116
|
+
const { db } = await allpeepDb();
|
|
117
|
+
if (!((_a = accountData === null || accountData === void 0 ? void 0 : accountData.account) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
118
|
+
throw new Error('Account ID is missing');
|
|
119
|
+
}
|
|
120
|
+
const previousEmail = accountData.account.email;
|
|
121
|
+
const updatedEmail = normalizeEmailAddress(accountData.email);
|
|
122
|
+
const account = await accountsMapping.update(db, accountData.account.id, {
|
|
123
|
+
email: updatedEmail,
|
|
124
|
+
passwordHash: accountData.password
|
|
125
|
+
? await hash(accountData.password, 12)
|
|
126
|
+
: undefined,
|
|
127
|
+
emailValidated: accountData.emailValidated,
|
|
128
|
+
});
|
|
129
|
+
await accountsCache.del(accountData.account.id);
|
|
130
|
+
await accountsCache.del(previousEmail);
|
|
131
|
+
if (updatedEmail) {
|
|
132
|
+
await accountsCache.del(updatedEmail);
|
|
133
|
+
}
|
|
134
|
+
if (account && accountData.emailValidated === false) {
|
|
135
|
+
await sendEmailValidationMail(account);
|
|
136
|
+
}
|
|
137
|
+
return { account };
|
|
138
|
+
};
|
|
139
|
+
export const deleteAccount = async (account) => {
|
|
140
|
+
const { db } = await allpeepDb();
|
|
141
|
+
await accountsMapping.delete(db, account.id);
|
|
142
|
+
await accountsCache.del(account.id);
|
|
143
|
+
await accountsCache.del(account.email);
|
|
144
|
+
const subscriptions = await listPushSubscriptionsByAccount(account);
|
|
145
|
+
await Promise.all(subscriptions.map(async (sub) => await deletePushSubscription(sub.id)));
|
|
146
|
+
};
|
|
147
|
+
export const sendResetPasswordEmail = async (account) => {
|
|
148
|
+
const token = await createSignedProfileAccessToken({
|
|
149
|
+
account,
|
|
150
|
+
name: 'reset-password',
|
|
151
|
+
scopes: [
|
|
152
|
+
{ scopeLevel: 'admin', resource: { type: 'profiles', id: account.id } },
|
|
153
|
+
],
|
|
154
|
+
expirationTime: '1d',
|
|
155
|
+
});
|
|
156
|
+
const resetPasswordLink = `${await serverRootUrl()}/auth/reset-password#token=${token.signedToken}`;
|
|
157
|
+
await emailService().then((mailer) => mailer.send({
|
|
158
|
+
to: account.email,
|
|
159
|
+
locals: {
|
|
160
|
+
resetPasswordLink,
|
|
161
|
+
},
|
|
162
|
+
template: 'resetPassword',
|
|
163
|
+
}));
|
|
164
|
+
};
|
|
165
|
+
export const validateEmail = async (token) => {
|
|
166
|
+
var _a;
|
|
167
|
+
const communityConf = await communityConfig();
|
|
168
|
+
const jwt = await jwtUtil();
|
|
169
|
+
const { db } = await allpeepDb();
|
|
170
|
+
try {
|
|
171
|
+
const validatedToken = await jwt.verify(token);
|
|
172
|
+
const email = (_a = validatedToken === null || validatedToken === void 0 ? void 0 : validatedToken.payload) === null || _a === void 0 ? void 0 : _a.email;
|
|
173
|
+
const account = await findAccountByEmail(email !== null && email !== void 0 ? email : '');
|
|
174
|
+
if (account) {
|
|
175
|
+
await accountsMapping.update(db, account.id, { emailValidated: true });
|
|
176
|
+
await accountsCache.del(account.id);
|
|
177
|
+
await accountsCache.del(account.email);
|
|
178
|
+
for (const roleKey of communityConf.roles.onEmailValidation.add) {
|
|
179
|
+
const role = await findRoleByKey(roleKey);
|
|
180
|
+
if (role) {
|
|
181
|
+
await assignRole(account.profiles[0], role);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
log.error(`Role ${roleKey} missing`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
for (const roleKey of communityConf.roles.onEmailValidation.remove) {
|
|
188
|
+
const role = await findRoleByKey(roleKey);
|
|
189
|
+
if (role) {
|
|
190
|
+
await unassignRole(account.profiles[0], role);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
log.error(`Role ${roleKey} missing`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch (e) {
|
|
200
|
+
log.error(e, 'Error confirming email.');
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
export const giveControl = connector(collectionInfos.accountsCollection, collectionInfos.profilesCollection, collectionInfos.controlsCollection);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const analyticsCacheKey: (section: string, from: string, to: string) => string;
|
|
2
|
+
export declare const getAnalyticsCache: <T>(key: string) => Promise<T | undefined>;
|
|
3
|
+
export declare const setAnalyticsCache: (key: string, value: unknown, opts?: {
|
|
4
|
+
includesToday?: boolean;
|
|
5
|
+
}) => Promise<void>;
|
|
6
|
+
export declare const invalidateAnalyticsCache: () => Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getSharedConnection } from '../redis/index.js';
|
|
2
|
+
const KEY_PREFIX = 'analytics:v4:';
|
|
3
|
+
const OPEN_DAY_TTL_SEC = 60 * 60;
|
|
4
|
+
const CLOSED_RANGE_TTL_SEC = 60 * 60 * 6;
|
|
5
|
+
export const analyticsCacheKey = (section, from, to) => `${KEY_PREFIX}${section}:${from}:${to}`;
|
|
6
|
+
export const getAnalyticsCache = async (key) => {
|
|
7
|
+
const redis = await getSharedConnection();
|
|
8
|
+
const raw = await redis.get(key);
|
|
9
|
+
if (!raw)
|
|
10
|
+
return undefined;
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(raw);
|
|
13
|
+
}
|
|
14
|
+
catch (_a) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export const setAnalyticsCache = async (key, value, opts) => {
|
|
19
|
+
const redis = await getSharedConnection();
|
|
20
|
+
const ttl = (opts === null || opts === void 0 ? void 0 : opts.includesToday) ? OPEN_DAY_TTL_SEC : CLOSED_RANGE_TTL_SEC;
|
|
21
|
+
await redis.set(key, JSON.stringify(value), { EX: ttl });
|
|
22
|
+
};
|
|
23
|
+
export const invalidateAnalyticsCache = async () => {
|
|
24
|
+
const redis = await getSharedConnection();
|
|
25
|
+
const keys = await redis.keys(`${KEY_PREFIX}*`);
|
|
26
|
+
if (keys.length === 0)
|
|
27
|
+
return;
|
|
28
|
+
await redis.del(keys);
|
|
29
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const compileAnalyticsDay: (day: string) => Promise<void>;
|
|
2
|
+
export declare const compileRetentionCohorts: () => Promise<void>;
|
|
3
|
+
export declare const compileRecentAnalytics: () => Promise<void>;
|
|
4
|
+
export declare const backfillAnalytics: (fromDay: string, toDay: string) => Promise<number>;
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { formatISO, startOfDay, subDays } from 'date-fns';
|
|
3
|
+
import { database } from '../db/index.js';
|
|
4
|
+
import { analyticsDailyTotals } from '../db/pg/schema/analytics.js';
|
|
5
|
+
import { logger } from '../log/index.js';
|
|
6
|
+
import { invalidateAnalyticsCache } from './cache.js';
|
|
7
|
+
const log = logger('app:analytics:compile');
|
|
8
|
+
const dayString = (d) => formatISO(startOfDay(d), { representation: 'date' });
|
|
9
|
+
const dayBounds = (day) => {
|
|
10
|
+
const start = `${day}T00:00:00.000Z`;
|
|
11
|
+
const next = dayString(subDays(new Date(`${day}T00:00:00.000Z`), -1));
|
|
12
|
+
const end = `${next}T00:00:00.000Z`;
|
|
13
|
+
return { start, end };
|
|
14
|
+
};
|
|
15
|
+
const countScalar = async (db, query) => {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const result = await db.execute(query);
|
|
18
|
+
const rows = result.rows;
|
|
19
|
+
return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : 0);
|
|
20
|
+
};
|
|
21
|
+
export const compileAnalyticsDay = async (day) => {
|
|
22
|
+
const db = await database();
|
|
23
|
+
const { start, end } = dayBounds(day);
|
|
24
|
+
const now = new Date().toISOString();
|
|
25
|
+
const newMembers = await countScalar(db, sql `select count(*)::int as c from profiles
|
|
26
|
+
where deleted_at is null
|
|
27
|
+
and created_at >= ${start} and created_at < ${end}`);
|
|
28
|
+
const posts = await countScalar(db, sql `select count(*)::int as c from posts
|
|
29
|
+
where deleted_at is null and visibility <> 'direct'
|
|
30
|
+
and created_at >= ${start} and created_at < ${end}`);
|
|
31
|
+
const replies = await countScalar(db, sql `select count(*)::int as c from reply_to
|
|
32
|
+
where created_at >= ${start} and created_at < ${end}`);
|
|
33
|
+
const likes = await countScalar(db, sql `select count(*)::int as c from reactions
|
|
34
|
+
where created_at >= ${start} and created_at < ${end}`);
|
|
35
|
+
const reposts = await countScalar(db, sql `select count(*)::int as c from repost
|
|
36
|
+
where created_at >= ${start} and created_at < ${end}`);
|
|
37
|
+
const bookmarks = await countScalar(db, sql `select count(*)::int as c from bookmarks
|
|
38
|
+
where created_at >= ${start} and created_at < ${end}`);
|
|
39
|
+
const comments = replies;
|
|
40
|
+
const dms = await countScalar(db, sql `select count(*)::int as c from posts
|
|
41
|
+
where deleted_at is null and visibility = 'direct'
|
|
42
|
+
and created_at >= ${start} and created_at < ${end}`);
|
|
43
|
+
const uniqueViewers = await countScalar(db, sql `select count(distinct from_id)::int as c from post_seen
|
|
44
|
+
where created_at >= ${start} and created_at < ${end}`);
|
|
45
|
+
const viewEvents = await countScalar(db, sql `select count(*)::int as c from post_seen
|
|
46
|
+
where created_at >= ${start} and created_at < ${end}`);
|
|
47
|
+
const jamSessions = await countScalar(db, sql `select count(*)::int as c from jam_events
|
|
48
|
+
where deleted_at is null and body->>'type' = 'start'
|
|
49
|
+
and created_at >= ${start} and created_at < ${end}`);
|
|
50
|
+
const jamParticipants = await countScalar(db, sql `select count(*)::int as c from jam_events
|
|
51
|
+
where deleted_at is null and body->>'type' = 'join'
|
|
52
|
+
and created_at >= ${start} and created_at < ${end}`);
|
|
53
|
+
const activeMembers = await countScalar(db, sql `select count(*)::int as c from (
|
|
54
|
+
select creator_id as profile_id from posts
|
|
55
|
+
where deleted_at is null
|
|
56
|
+
and created_at >= ${start} and created_at < ${end}
|
|
57
|
+
union
|
|
58
|
+
select from_id from reactions
|
|
59
|
+
where created_at >= ${start} and created_at < ${end}
|
|
60
|
+
union
|
|
61
|
+
select from_id from repost
|
|
62
|
+
where created_at >= ${start} and created_at < ${end}
|
|
63
|
+
union
|
|
64
|
+
select from_id from reply_to
|
|
65
|
+
where created_at >= ${start} and created_at < ${end}
|
|
66
|
+
union
|
|
67
|
+
select from_id from bookmarks
|
|
68
|
+
where created_at >= ${start} and created_at < ${end}
|
|
69
|
+
) active`);
|
|
70
|
+
await db
|
|
71
|
+
.insert(analyticsDailyTotals)
|
|
72
|
+
.values({
|
|
73
|
+
day,
|
|
74
|
+
newMembers,
|
|
75
|
+
activeMembers,
|
|
76
|
+
posts,
|
|
77
|
+
replies,
|
|
78
|
+
likes,
|
|
79
|
+
reposts,
|
|
80
|
+
bookmarks,
|
|
81
|
+
comments,
|
|
82
|
+
dms,
|
|
83
|
+
uniqueViewers,
|
|
84
|
+
viewEvents,
|
|
85
|
+
jamSessions,
|
|
86
|
+
jamParticipants,
|
|
87
|
+
compiledAt: now,
|
|
88
|
+
})
|
|
89
|
+
.onConflictDoUpdate({
|
|
90
|
+
target: analyticsDailyTotals.day,
|
|
91
|
+
set: {
|
|
92
|
+
newMembers,
|
|
93
|
+
activeMembers,
|
|
94
|
+
posts,
|
|
95
|
+
replies,
|
|
96
|
+
likes,
|
|
97
|
+
reposts,
|
|
98
|
+
bookmarks,
|
|
99
|
+
comments,
|
|
100
|
+
dms,
|
|
101
|
+
uniqueViewers,
|
|
102
|
+
viewEvents,
|
|
103
|
+
jamSessions,
|
|
104
|
+
jamParticipants,
|
|
105
|
+
compiledAt: now,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
await db.execute(sql `delete from analytics_daily_by_group where day = ${day}`);
|
|
109
|
+
await db.execute(sql `
|
|
110
|
+
insert into analytics_daily_by_group
|
|
111
|
+
(id, day, group_id, posts, likes, comments, unique_viewers, compiled_at)
|
|
112
|
+
select
|
|
113
|
+
gen_random_uuid(),
|
|
114
|
+
${day},
|
|
115
|
+
pg.to_id,
|
|
116
|
+
count(distinct p.id)::int,
|
|
117
|
+
0,
|
|
118
|
+
0,
|
|
119
|
+
0,
|
|
120
|
+
${now}
|
|
121
|
+
from post_groups pg
|
|
122
|
+
join posts p on p.id::text = pg.from_id
|
|
123
|
+
where p.deleted_at is null
|
|
124
|
+
and p.created_at >= ${start} and p.created_at < ${end}
|
|
125
|
+
group by pg.to_id
|
|
126
|
+
`);
|
|
127
|
+
// Likes/comments attributed via posts in the group (best-effort).
|
|
128
|
+
await db.execute(sql `
|
|
129
|
+
update analytics_daily_by_group g
|
|
130
|
+
set
|
|
131
|
+
likes = coalesce((
|
|
132
|
+
select count(*)::int from reactions r
|
|
133
|
+
join post_groups pg on pg.from_id = r.to_id
|
|
134
|
+
where pg.to_id = g.group_id
|
|
135
|
+
and r.created_at >= ${start} and r.created_at < ${end}
|
|
136
|
+
), 0),
|
|
137
|
+
comments = coalesce((
|
|
138
|
+
select count(*)::int from reply_to rt
|
|
139
|
+
join post_groups pg on pg.from_id = rt.to_id
|
|
140
|
+
where pg.to_id = g.group_id
|
|
141
|
+
and rt.created_at >= ${start} and rt.created_at < ${end}
|
|
142
|
+
), 0),
|
|
143
|
+
unique_viewers = coalesce((
|
|
144
|
+
select count(distinct ps.from_id)::int from post_seen ps
|
|
145
|
+
join post_groups pg on pg.from_id = ps.to_id
|
|
146
|
+
where pg.to_id = g.group_id
|
|
147
|
+
and ps.created_at >= ${start} and ps.created_at < ${end}
|
|
148
|
+
), 0),
|
|
149
|
+
compiled_at = ${now}
|
|
150
|
+
where g.day = ${day}
|
|
151
|
+
`);
|
|
152
|
+
await db.execute(sql `delete from analytics_daily_activity_heatmap where day = ${day}`);
|
|
153
|
+
await db.execute(sql `
|
|
154
|
+
insert into analytics_daily_activity_heatmap
|
|
155
|
+
(id, day, dow, hour, activity_count, compiled_at)
|
|
156
|
+
select
|
|
157
|
+
gen_random_uuid(),
|
|
158
|
+
${day},
|
|
159
|
+
extract(dow from created_at at time zone 'UTC')::int,
|
|
160
|
+
extract(hour from created_at at time zone 'UTC')::int,
|
|
161
|
+
count(*)::int,
|
|
162
|
+
${now}
|
|
163
|
+
from (
|
|
164
|
+
select created_at from posts
|
|
165
|
+
where deleted_at is null and created_at >= ${start} and created_at < ${end}
|
|
166
|
+
union all
|
|
167
|
+
select created_at from reactions
|
|
168
|
+
where created_at >= ${start} and created_at < ${end}
|
|
169
|
+
union all
|
|
170
|
+
select created_at from reply_to
|
|
171
|
+
where created_at >= ${start} and created_at < ${end}
|
|
172
|
+
union all
|
|
173
|
+
select created_at from repost
|
|
174
|
+
where created_at >= ${start} and created_at < ${end}
|
|
175
|
+
) activity
|
|
176
|
+
group by 3, 4
|
|
177
|
+
`);
|
|
178
|
+
await db.execute(sql `delete from analytics_daily_signups_by_channel where day = ${day}`);
|
|
179
|
+
await db.execute(sql `
|
|
180
|
+
insert into analytics_daily_signups_by_channel
|
|
181
|
+
(id, day, channel, count, compiled_at)
|
|
182
|
+
select
|
|
183
|
+
gen_random_uuid(),
|
|
184
|
+
${day},
|
|
185
|
+
case when r.from_id is not null then 'invite' else 'organic' end,
|
|
186
|
+
count(*)::int,
|
|
187
|
+
${now}
|
|
188
|
+
from profiles p
|
|
189
|
+
left join invite_link_redeemers r on r.to_id = p.id::text
|
|
190
|
+
where p.deleted_at is null
|
|
191
|
+
and p.created_at >= ${start} and p.created_at < ${end}
|
|
192
|
+
group by 3
|
|
193
|
+
`);
|
|
194
|
+
await db.execute(sql `delete from analytics_post_views_daily where day = ${day}`);
|
|
195
|
+
await db.execute(sql `
|
|
196
|
+
insert into analytics_post_views_daily
|
|
197
|
+
(id, day, post_id, unique_viewers, view_events, compiled_at)
|
|
198
|
+
select
|
|
199
|
+
gen_random_uuid(),
|
|
200
|
+
${day},
|
|
201
|
+
to_id,
|
|
202
|
+
count(distinct from_id)::int,
|
|
203
|
+
count(*)::int,
|
|
204
|
+
${now}
|
|
205
|
+
from post_seen
|
|
206
|
+
where created_at >= ${start} and created_at < ${end}
|
|
207
|
+
group by to_id
|
|
208
|
+
`);
|
|
209
|
+
log.info(`Compiled analytics for ${day}`);
|
|
210
|
+
};
|
|
211
|
+
export const compileRetentionCohorts = async () => {
|
|
212
|
+
const db = await database();
|
|
213
|
+
const now = new Date().toISOString();
|
|
214
|
+
// Cohort week = date_trunc week of profile created_at; rates at ages 1/7/30.
|
|
215
|
+
await db.execute(sql `delete from analytics_retention_cohorts`);
|
|
216
|
+
await db.execute(sql `
|
|
217
|
+
insert into analytics_retention_cohorts
|
|
218
|
+
(id, cohort_week, cohort_size, rates, compiled_at)
|
|
219
|
+
with cohorts as (
|
|
220
|
+
select
|
|
221
|
+
(date_trunc('week', created_at at time zone 'UTC'))::date as cohort_week,
|
|
222
|
+
id::text as profile_id,
|
|
223
|
+
created_at
|
|
224
|
+
from profiles
|
|
225
|
+
where deleted_at is null
|
|
226
|
+
and created_at >= (now() - interval '26 weeks')
|
|
227
|
+
),
|
|
228
|
+
sized as (
|
|
229
|
+
select cohort_week, count(*)::int as cohort_size
|
|
230
|
+
from cohorts
|
|
231
|
+
group by cohort_week
|
|
232
|
+
),
|
|
233
|
+
retained as (
|
|
234
|
+
select
|
|
235
|
+
c.cohort_week,
|
|
236
|
+
count(distinct case when a.day_offset = 1 then c.profile_id end)::int as d1,
|
|
237
|
+
count(distinct case when a.day_offset = 7 then c.profile_id end)::int as d7,
|
|
238
|
+
count(distinct case when a.day_offset = 30 then c.profile_id end)::int as d30
|
|
239
|
+
from cohorts c
|
|
240
|
+
left join lateral (
|
|
241
|
+
select distinct
|
|
242
|
+
extract(day from (act.created_at - c.created_at))::int as day_offset
|
|
243
|
+
from (
|
|
244
|
+
select creator_id as profile_id, created_at from posts where deleted_at is null
|
|
245
|
+
union all
|
|
246
|
+
select from_id, created_at from reactions
|
|
247
|
+
union all
|
|
248
|
+
select from_id, created_at from reply_to
|
|
249
|
+
union all
|
|
250
|
+
select from_id, created_at from repost
|
|
251
|
+
union all
|
|
252
|
+
select from_id, created_at from bookmarks
|
|
253
|
+
) act
|
|
254
|
+
where act.profile_id = c.profile_id
|
|
255
|
+
and extract(day from (act.created_at - c.created_at))::int in (1, 7, 30)
|
|
256
|
+
) a on true
|
|
257
|
+
group by c.cohort_week
|
|
258
|
+
)
|
|
259
|
+
select
|
|
260
|
+
gen_random_uuid(),
|
|
261
|
+
s.cohort_week,
|
|
262
|
+
s.cohort_size,
|
|
263
|
+
jsonb_build_object(
|
|
264
|
+
'1', case when s.cohort_size = 0 then 0
|
|
265
|
+
else round((coalesce(r.d1, 0)::numeric / s.cohort_size) * 100, 2) end,
|
|
266
|
+
'7', case when s.cohort_size = 0 then 0
|
|
267
|
+
else round((coalesce(r.d7, 0)::numeric / s.cohort_size) * 100, 2) end,
|
|
268
|
+
'30', case when s.cohort_size = 0 then 0
|
|
269
|
+
else round((coalesce(r.d30, 0)::numeric / s.cohort_size) * 100, 2) end
|
|
270
|
+
),
|
|
271
|
+
${now}
|
|
272
|
+
from sized s
|
|
273
|
+
left join retained r on r.cohort_week = s.cohort_week
|
|
274
|
+
`);
|
|
275
|
+
log.info('Compiled retention cohorts');
|
|
276
|
+
};
|
|
277
|
+
export const compileRecentAnalytics = async () => {
|
|
278
|
+
const today = dayString(new Date());
|
|
279
|
+
const yesterday = dayString(subDays(new Date(), 1));
|
|
280
|
+
await compileAnalyticsDay(yesterday);
|
|
281
|
+
await compileAnalyticsDay(today);
|
|
282
|
+
await invalidateAnalyticsCache();
|
|
283
|
+
};
|
|
284
|
+
export const backfillAnalytics = async (fromDay, toDay) => {
|
|
285
|
+
let cursor = startOfDay(new Date(`${fromDay}T00:00:00.000Z`));
|
|
286
|
+
const end = startOfDay(new Date(`${toDay}T00:00:00.000Z`));
|
|
287
|
+
let count = 0;
|
|
288
|
+
while (cursor <= end) {
|
|
289
|
+
await compileAnalyticsDay(dayString(cursor));
|
|
290
|
+
count += 1;
|
|
291
|
+
cursor = subDays(cursor, -1);
|
|
292
|
+
}
|
|
293
|
+
await compileRetentionCohorts();
|
|
294
|
+
await invalidateAnalyticsCache();
|
|
295
|
+
return count;
|
|
296
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AnalyticsDateQuery, AnalyticsRangeMeta } from '@openpeepshq/common/types';
|
|
2
|
+
export type ResolvedAnalyticsRange = AnalyticsRangeMeta & {
|
|
3
|
+
fromDate: Date;
|
|
4
|
+
toDate: Date;
|
|
5
|
+
previousFromDate: Date;
|
|
6
|
+
previousToDate: Date;
|
|
7
|
+
};
|
|
8
|
+
export declare const resolveAnalyticsRange: (query?: AnalyticsDateQuery, now?: Date) => ResolvedAnalyticsRange;
|
|
9
|
+
export declare const eachUtcDay: (from: string, to: string) => string[];
|
|
10
|
+
export type ChartBucketUnit = 'day' | 'week' | 'month' | 'year';
|
|
11
|
+
export type ChartBucket = {
|
|
12
|
+
key: string;
|
|
13
|
+
label: string;
|
|
14
|
+
from: string;
|
|
15
|
+
to: string;
|
|
16
|
+
};
|
|
17
|
+
/** Map inclusive day count → chart grain. */
|
|
18
|
+
export declare const unitForDayCount: (dayCount: number) => ChartBucketUnit;
|
|
19
|
+
/**
|
|
20
|
+
* Choose day / week / month / year buckets from the range length:
|
|
21
|
+
* 1–14d → days, 15–90d → weeks, 91–800d → months, >800d → years.
|
|
22
|
+
*/
|
|
23
|
+
export declare const selectChartBuckets: (from: string, to: string) => {
|
|
24
|
+
unit: ChartBucketUnit;
|
|
25
|
+
buckets: ChartBucket[];
|
|
26
|
+
};
|
|
27
|
+
export declare const aggregateSeriesIntoBuckets: (series: Array<{
|
|
28
|
+
day: string;
|
|
29
|
+
value: number;
|
|
30
|
+
}>, buckets: ChartBucket[]) => Array<{
|
|
31
|
+
day: string;
|
|
32
|
+
label: string;
|
|
33
|
+
value: number;
|
|
34
|
+
}>;
|
|
35
|
+
/** @internal exposed for tests */
|
|
36
|
+
export declare const _chartBucketInternals: {
|
|
37
|
+
buildBuckets: (unit: ChartBucketUnit, fromDate: Date, toDate: Date) => ChartBucket[];
|
|
38
|
+
unitForDayCount: (dayCount: number) => ChartBucketUnit;
|
|
39
|
+
};
|