@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,821 @@
|
|
|
1
|
+
import PDFDocument from 'pdfkit';
|
|
2
|
+
const PAGE = { width: 612, height: 792 };
|
|
3
|
+
const MARGIN = 40;
|
|
4
|
+
const CONTENT_WIDTH = PAGE.width - MARGIN * 2;
|
|
5
|
+
const BOTTOM = PAGE.height - MARGIN;
|
|
6
|
+
const COLORS = {
|
|
7
|
+
ink: '#111827',
|
|
8
|
+
muted: '#6b7280',
|
|
9
|
+
border: '#e5e7eb',
|
|
10
|
+
soft: '#f3f4f6',
|
|
11
|
+
card: '#f9fafb',
|
|
12
|
+
white: '#ffffff',
|
|
13
|
+
accent: '#2563eb',
|
|
14
|
+
positive: '#059669',
|
|
15
|
+
negative: '#dc2626',
|
|
16
|
+
};
|
|
17
|
+
const GRAY_STACK = ['#111827', '#4b5563', '#6b7280', '#9ca3af', '#d1d5db'];
|
|
18
|
+
const GROUP_COLORS = [
|
|
19
|
+
'#2563eb',
|
|
20
|
+
'#059669',
|
|
21
|
+
'#d97706',
|
|
22
|
+
'#dc2626',
|
|
23
|
+
'#0891b2',
|
|
24
|
+
'#7c3aed',
|
|
25
|
+
];
|
|
26
|
+
const POST_TYPE_META = [
|
|
27
|
+
{ key: 'jam', label: 'Jams', color: '#111827' },
|
|
28
|
+
{ key: 'article', label: 'Articles', color: '#4b5563' },
|
|
29
|
+
{ key: 'note', label: 'Notes', color: '#9ca3af' },
|
|
30
|
+
{ key: 'poll', label: 'Polls', color: '#d1d5db' },
|
|
31
|
+
{ key: 'event', label: 'Events', color: '#6b7280' },
|
|
32
|
+
];
|
|
33
|
+
const ENGAGEMENT_SERIES = [
|
|
34
|
+
{ key: 'likes', label: 'Likes', color: '#111827' },
|
|
35
|
+
{ key: 'reposts', label: 'Shares', color: '#4b5563' },
|
|
36
|
+
{ key: 'bookmarks', label: 'Bookmarks', color: '#6b7280' },
|
|
37
|
+
{ key: 'comments', label: 'Replies', color: '#9ca3af' },
|
|
38
|
+
];
|
|
39
|
+
/** Single-line text that must not trigger pdfkit auto page-breaks. */
|
|
40
|
+
const writeText = (doc, text, x, y, options = {}) => {
|
|
41
|
+
var _a;
|
|
42
|
+
doc.text(text, x, y, Object.assign(Object.assign({ lineBreak: false }, options), { height: (_a = options.height) !== null && _a !== void 0 ? _a : 12 }));
|
|
43
|
+
};
|
|
44
|
+
const formatNum = (n) => Number.isFinite(n) ? Math.round(n).toLocaleString('en-US') : '0';
|
|
45
|
+
const formatDelta = (deltaPct) => {
|
|
46
|
+
if (deltaPct == null)
|
|
47
|
+
return null;
|
|
48
|
+
const sign = deltaPct > 0 ? '+' : '';
|
|
49
|
+
return `${sign}${deltaPct}%`;
|
|
50
|
+
};
|
|
51
|
+
const averageSeries = (series) => {
|
|
52
|
+
if (!(series === null || series === void 0 ? void 0 : series.length))
|
|
53
|
+
return 0;
|
|
54
|
+
return (Math.round((series.reduce((acc, p) => acc + p.value, 0) / series.length) * 10) / 10);
|
|
55
|
+
};
|
|
56
|
+
const utcDayCount = (from, to) => {
|
|
57
|
+
const start = Date.parse(`${from}T00:00:00.000Z`);
|
|
58
|
+
const end = Date.parse(`${to}T00:00:00.000Z`);
|
|
59
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || end < start)
|
|
60
|
+
return 1;
|
|
61
|
+
return Math.round((end - start) / 86400000) + 1;
|
|
62
|
+
};
|
|
63
|
+
const ratePct = (numerator, denominator) => denominator <= 0 ? 0 : Math.round((numerator / denominator) * 1000) / 10;
|
|
64
|
+
const truncate = (text, max) => text.length <= max ? text : `${text.slice(0, max - 1)}…`;
|
|
65
|
+
const cumulativeGrowth = (points, series) => {
|
|
66
|
+
const running = Object.fromEntries(series.map((s) => [s.key, 0]));
|
|
67
|
+
return points.map((p) => {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
for (const s of series) {
|
|
70
|
+
running[s.key] = ((_a = running[s.key]) !== null && _a !== void 0 ? _a : 0) + ((_b = p.values[s.key]) !== null && _b !== void 0 ? _b : 0);
|
|
71
|
+
}
|
|
72
|
+
return { label: p.label, values: Object.assign({}, running) };
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
const createDoc = () => new PDFDocument({
|
|
76
|
+
size: 'LETTER',
|
|
77
|
+
margin: MARGIN,
|
|
78
|
+
compress: false,
|
|
79
|
+
info: {
|
|
80
|
+
Title: 'Community analytics report',
|
|
81
|
+
Author: 'OpenPeeps',
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
const bufferFromDoc = (doc) => new Promise((resolve, reject) => {
|
|
85
|
+
const chunks = [];
|
|
86
|
+
doc.on('data', (chunk) => chunks.push(chunk));
|
|
87
|
+
doc.on('end', () => resolve(Buffer.concat(chunks)));
|
|
88
|
+
doc.on('error', reject);
|
|
89
|
+
});
|
|
90
|
+
const drawFooter = (layout) => {
|
|
91
|
+
const { doc, pageIndex, period } = layout;
|
|
92
|
+
doc.fontSize(8).fillColor(COLORS.muted);
|
|
93
|
+
writeText(doc, period, MARGIN, PAGE.height - 28, {
|
|
94
|
+
width: CONTENT_WIDTH / 2,
|
|
95
|
+
align: 'left',
|
|
96
|
+
});
|
|
97
|
+
writeText(doc, `Page ${pageIndex}`, MARGIN, PAGE.height - 28, {
|
|
98
|
+
width: CONTENT_WIDTH,
|
|
99
|
+
align: 'right',
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
const newPage = (layout, sectionTitle) => {
|
|
103
|
+
drawFooter(layout);
|
|
104
|
+
layout.doc.addPage();
|
|
105
|
+
layout.pageIndex += 1;
|
|
106
|
+
layout.y = MARGIN;
|
|
107
|
+
if (sectionTitle)
|
|
108
|
+
layout.sectionTitle = sectionTitle;
|
|
109
|
+
drawPageChrome(layout);
|
|
110
|
+
};
|
|
111
|
+
const ensureSpace = (layout, needed) => {
|
|
112
|
+
if (layout.y + needed <= BOTTOM - 20)
|
|
113
|
+
return;
|
|
114
|
+
newPage(layout);
|
|
115
|
+
};
|
|
116
|
+
const drawPageChrome = (layout) => {
|
|
117
|
+
const { doc, sectionTitle, period } = layout;
|
|
118
|
+
doc.fontSize(18).fillColor(COLORS.ink).font('Helvetica-Bold');
|
|
119
|
+
writeText(doc, sectionTitle, MARGIN, layout.y, { width: CONTENT_WIDTH });
|
|
120
|
+
layout.y += 22;
|
|
121
|
+
doc.fontSize(9).fillColor(COLORS.muted).font('Helvetica');
|
|
122
|
+
writeText(doc, `Period ${period}`, MARGIN, layout.y, {
|
|
123
|
+
width: CONTENT_WIDTH,
|
|
124
|
+
});
|
|
125
|
+
layout.y += 16;
|
|
126
|
+
doc
|
|
127
|
+
.moveTo(MARGIN, layout.y)
|
|
128
|
+
.lineTo(MARGIN + CONTENT_WIDTH, layout.y)
|
|
129
|
+
.strokeColor(COLORS.border)
|
|
130
|
+
.lineWidth(1)
|
|
131
|
+
.stroke();
|
|
132
|
+
layout.y += 16;
|
|
133
|
+
};
|
|
134
|
+
const drawSectionTitle = (layout, title) => {
|
|
135
|
+
ensureSpace(layout, 28);
|
|
136
|
+
layout.doc.fontSize(11).fillColor(COLORS.ink).font('Helvetica-Bold');
|
|
137
|
+
writeText(layout.doc, title, MARGIN, layout.y, { width: CONTENT_WIDTH });
|
|
138
|
+
layout.y += 18;
|
|
139
|
+
layout.doc.font('Helvetica');
|
|
140
|
+
};
|
|
141
|
+
const drawMetricCards = (layout, cards) => {
|
|
142
|
+
const cols = Math.min(4, cards.length);
|
|
143
|
+
const gap = 8;
|
|
144
|
+
const cardW = (CONTENT_WIDTH - gap * (cols - 1)) / cols;
|
|
145
|
+
const cardH = 58;
|
|
146
|
+
const rows = Math.ceil(cards.length / cols);
|
|
147
|
+
ensureSpace(layout, rows * (cardH + gap));
|
|
148
|
+
cards.forEach((card, i) => {
|
|
149
|
+
var _a;
|
|
150
|
+
const col = i % cols;
|
|
151
|
+
const row = Math.floor(i / cols);
|
|
152
|
+
const x = MARGIN + col * (cardW + gap);
|
|
153
|
+
const y = layout.y + row * (cardH + gap);
|
|
154
|
+
layout.doc
|
|
155
|
+
.roundedRect(x, y, cardW, cardH, 6)
|
|
156
|
+
.fillAndStroke(COLORS.card, COLORS.border);
|
|
157
|
+
layout.doc.fontSize(8).fillColor(COLORS.muted).font('Helvetica');
|
|
158
|
+
writeText(layout.doc, card.label.toUpperCase(), x + 10, y + 8, {
|
|
159
|
+
width: cardW - 20,
|
|
160
|
+
ellipsis: true,
|
|
161
|
+
});
|
|
162
|
+
layout.doc.fontSize(16).fillColor(COLORS.ink).font('Helvetica-Bold');
|
|
163
|
+
writeText(layout.doc, card.value, x + 10, y + 22, {
|
|
164
|
+
width: cardW - 20,
|
|
165
|
+
height: 18,
|
|
166
|
+
});
|
|
167
|
+
const delta = formatDelta(card.deltaPct);
|
|
168
|
+
const sub = (_a = card.subtitle) !== null && _a !== void 0 ? _a : '';
|
|
169
|
+
const line = [delta, sub].filter(Boolean).join(' | ');
|
|
170
|
+
if (line) {
|
|
171
|
+
layout.doc
|
|
172
|
+
.fontSize(8)
|
|
173
|
+
.fillColor(card.deltaPct != null && card.deltaPct > 0
|
|
174
|
+
? COLORS.positive
|
|
175
|
+
: card.deltaPct != null && card.deltaPct < 0
|
|
176
|
+
? COLORS.negative
|
|
177
|
+
: COLORS.muted)
|
|
178
|
+
.font('Helvetica');
|
|
179
|
+
writeText(layout.doc, line, x + 10, y + 42, {
|
|
180
|
+
width: cardW - 20,
|
|
181
|
+
ellipsis: true,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
layout.y += rows * (cardH + gap) + 8;
|
|
186
|
+
layout.doc.font('Helvetica').fillColor(COLORS.ink);
|
|
187
|
+
};
|
|
188
|
+
const chartFrame = (layout, height) => {
|
|
189
|
+
ensureSpace(layout, height + 8);
|
|
190
|
+
const frame = { x: MARGIN, y: layout.y, w: CONTENT_WIDTH, h: height };
|
|
191
|
+
layout.doc
|
|
192
|
+
.roundedRect(frame.x, frame.y, frame.w, frame.h, 6)
|
|
193
|
+
.fillAndStroke(COLORS.white, COLORS.border);
|
|
194
|
+
layout.y += height + 12;
|
|
195
|
+
return frame;
|
|
196
|
+
};
|
|
197
|
+
const drawBarChart = (layout, points, height = 160) => {
|
|
198
|
+
const frame = chartFrame(layout, height);
|
|
199
|
+
const pad = { t: 16, r: 12, b: 28, l: 36 };
|
|
200
|
+
const plotW = frame.w - pad.l - pad.r;
|
|
201
|
+
const plotH = frame.h - pad.t - pad.b;
|
|
202
|
+
const max = Math.max(1, ...points.map((p) => p.value));
|
|
203
|
+
const barGap = 4;
|
|
204
|
+
const barW = points.length
|
|
205
|
+
? Math.max(4, (plotW - barGap * (points.length - 1)) / points.length)
|
|
206
|
+
: plotW;
|
|
207
|
+
layout.doc
|
|
208
|
+
.moveTo(frame.x + pad.l, frame.y + pad.t)
|
|
209
|
+
.lineTo(frame.x + pad.l, frame.y + pad.t + plotH)
|
|
210
|
+
.lineTo(frame.x + pad.l + plotW, frame.y + pad.t + plotH)
|
|
211
|
+
.strokeColor(COLORS.border)
|
|
212
|
+
.lineWidth(0.75)
|
|
213
|
+
.stroke();
|
|
214
|
+
points.forEach((p, i) => {
|
|
215
|
+
const h = (p.value / max) * plotH;
|
|
216
|
+
const x = frame.x + pad.l + i * (barW + barGap);
|
|
217
|
+
const y = frame.y + pad.t + plotH - h;
|
|
218
|
+
layout.doc.rect(x, y, barW, h).fill(COLORS.ink);
|
|
219
|
+
layout.doc.fontSize(7).fillColor(COLORS.muted);
|
|
220
|
+
writeText(layout.doc, truncate(p.label, 8), x - 2, frame.y + pad.t + plotH + 6, {
|
|
221
|
+
width: barW + 4,
|
|
222
|
+
align: 'center',
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
layout.doc.fontSize(7).fillColor(COLORS.muted);
|
|
226
|
+
writeText(layout.doc, formatNum(max), frame.x + 4, frame.y + pad.t - 2, {
|
|
227
|
+
width: pad.l - 6,
|
|
228
|
+
align: 'right',
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
const drawStackedBarChart = (layout, points, height = 170) => {
|
|
232
|
+
const frame = chartFrame(layout, height);
|
|
233
|
+
const pad = { t: 16, r: 12, b: 40, l: 36 };
|
|
234
|
+
const plotW = frame.w - pad.l - pad.r;
|
|
235
|
+
const plotH = frame.h - pad.t - pad.b;
|
|
236
|
+
const totals = points.map((p) => p.jam + p.article + p.note + p.poll + p.event);
|
|
237
|
+
const max = Math.max(1, ...totals);
|
|
238
|
+
const barGap = 4;
|
|
239
|
+
const barW = points.length
|
|
240
|
+
? Math.max(4, (plotW - barGap * (points.length - 1)) / points.length)
|
|
241
|
+
: plotW;
|
|
242
|
+
const keys = POST_TYPE_META;
|
|
243
|
+
points.forEach((p, i) => {
|
|
244
|
+
let stacked = 0;
|
|
245
|
+
const x = frame.x + pad.l + i * (barW + barGap);
|
|
246
|
+
for (const meta of keys) {
|
|
247
|
+
const v = p[meta.key];
|
|
248
|
+
if (v <= 0)
|
|
249
|
+
continue;
|
|
250
|
+
const h = (v / max) * plotH;
|
|
251
|
+
const y = frame.y + pad.t + plotH - stacked - h;
|
|
252
|
+
layout.doc.rect(x, y, barW, h).fill(meta.color);
|
|
253
|
+
stacked += h;
|
|
254
|
+
}
|
|
255
|
+
layout.doc.fontSize(7).fillColor(COLORS.muted);
|
|
256
|
+
writeText(layout.doc, truncate(p.label, 8), x - 2, frame.y + pad.t + plotH + 6, {
|
|
257
|
+
width: barW + 4,
|
|
258
|
+
align: 'center',
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
let legendX = frame.x + pad.l;
|
|
262
|
+
const legendY = frame.y + frame.h - 16;
|
|
263
|
+
for (const meta of keys) {
|
|
264
|
+
layout.doc.rect(legendX, legendY, 8, 8).fill(meta.color);
|
|
265
|
+
layout.doc.fontSize(7).fillColor(COLORS.muted);
|
|
266
|
+
writeText(layout.doc, meta.label, legendX + 11, legendY - 1);
|
|
267
|
+
legendX += 11 + layout.doc.widthOfString(meta.label) + 12;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
const drawLineChart = (layout, points, height = 150, color = COLORS.accent) => {
|
|
271
|
+
const frame = chartFrame(layout, height);
|
|
272
|
+
const pad = { t: 16, r: 12, b: 28, l: 36 };
|
|
273
|
+
const plotW = frame.w - pad.l - pad.r;
|
|
274
|
+
const plotH = frame.h - pad.t - pad.b;
|
|
275
|
+
const max = Math.max(1, ...points.map((p) => p.value));
|
|
276
|
+
layout.doc
|
|
277
|
+
.moveTo(frame.x + pad.l, frame.y + pad.t + plotH)
|
|
278
|
+
.lineTo(frame.x + pad.l + plotW, frame.y + pad.t + plotH)
|
|
279
|
+
.strokeColor(COLORS.border)
|
|
280
|
+
.lineWidth(0.75)
|
|
281
|
+
.stroke();
|
|
282
|
+
if (points.length === 0)
|
|
283
|
+
return;
|
|
284
|
+
const coords = points.map((p, i) => {
|
|
285
|
+
const x = frame.x +
|
|
286
|
+
pad.l +
|
|
287
|
+
(points.length === 1 ? plotW / 2 : (i / (points.length - 1)) * plotW);
|
|
288
|
+
const y = frame.y + pad.t + plotH - (p.value / max) * plotH;
|
|
289
|
+
return { x, y, label: p.label };
|
|
290
|
+
});
|
|
291
|
+
layout.doc
|
|
292
|
+
.moveTo(coords[0].x, coords[0].y)
|
|
293
|
+
.strokeColor(color)
|
|
294
|
+
.lineWidth(1.75);
|
|
295
|
+
for (let i = 1; i < coords.length; i++) {
|
|
296
|
+
layout.doc.lineTo(coords[i].x, coords[i].y);
|
|
297
|
+
}
|
|
298
|
+
layout.doc.stroke();
|
|
299
|
+
const labelStep = Math.max(1, Math.floor(points.length / 8));
|
|
300
|
+
coords.forEach((c, i) => {
|
|
301
|
+
if (i % labelStep !== 0 && i !== coords.length - 1)
|
|
302
|
+
return;
|
|
303
|
+
layout.doc.fontSize(7).fillColor(COLORS.muted);
|
|
304
|
+
writeText(layout.doc, truncate(c.label, 8), c.x - 16, frame.y + pad.t + plotH + 6, {
|
|
305
|
+
width: 32,
|
|
306
|
+
align: 'center',
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
};
|
|
310
|
+
const drawMultiLineChart = (layout, points, series, height = 180) => {
|
|
311
|
+
const frame = chartFrame(layout, height);
|
|
312
|
+
const pad = { t: 16, r: 12, b: 44, l: 36 };
|
|
313
|
+
const plotW = frame.w - pad.l - pad.r;
|
|
314
|
+
const plotH = frame.h - pad.t - pad.b;
|
|
315
|
+
const max = Math.max(1, ...points.flatMap((p) => series.map((s) => { var _a; return (_a = p.values[s.key]) !== null && _a !== void 0 ? _a : 0; })));
|
|
316
|
+
layout.doc
|
|
317
|
+
.moveTo(frame.x + pad.l, frame.y + pad.t + plotH)
|
|
318
|
+
.lineTo(frame.x + pad.l + plotW, frame.y + pad.t + plotH)
|
|
319
|
+
.strokeColor(COLORS.border)
|
|
320
|
+
.lineWidth(0.75)
|
|
321
|
+
.stroke();
|
|
322
|
+
if (points.length === 0)
|
|
323
|
+
return;
|
|
324
|
+
for (const s of series) {
|
|
325
|
+
const coords = points.map((p, i) => {
|
|
326
|
+
var _a;
|
|
327
|
+
const x = frame.x +
|
|
328
|
+
pad.l +
|
|
329
|
+
(points.length === 1 ? plotW / 2 : (i / (points.length - 1)) * plotW);
|
|
330
|
+
const y = frame.y + pad.t + plotH - (((_a = p.values[s.key]) !== null && _a !== void 0 ? _a : 0) / max) * plotH;
|
|
331
|
+
return { x, y };
|
|
332
|
+
});
|
|
333
|
+
layout.doc
|
|
334
|
+
.moveTo(coords[0].x, coords[0].y)
|
|
335
|
+
.strokeColor(s.color)
|
|
336
|
+
.lineWidth(1.75);
|
|
337
|
+
for (let i = 1; i < coords.length; i++) {
|
|
338
|
+
layout.doc.lineTo(coords[i].x, coords[i].y);
|
|
339
|
+
}
|
|
340
|
+
layout.doc.stroke();
|
|
341
|
+
}
|
|
342
|
+
const labelStep = Math.max(1, Math.floor(points.length / 8));
|
|
343
|
+
points.forEach((p, i) => {
|
|
344
|
+
if (i % labelStep !== 0 && i !== points.length - 1)
|
|
345
|
+
return;
|
|
346
|
+
const x = frame.x +
|
|
347
|
+
pad.l +
|
|
348
|
+
(points.length === 1 ? plotW / 2 : (i / (points.length - 1)) * plotW);
|
|
349
|
+
layout.doc.fontSize(7).fillColor(COLORS.muted);
|
|
350
|
+
writeText(layout.doc, truncate(p.label, 8), x - 16, frame.y + pad.t + plotH + 6, {
|
|
351
|
+
width: 32,
|
|
352
|
+
align: 'center',
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
let legendX = frame.x + pad.l;
|
|
356
|
+
const legendY = frame.y + frame.h - 16;
|
|
357
|
+
for (const s of series) {
|
|
358
|
+
layout.doc.circle(legendX + 3, legendY + 3, 3).fill(s.color);
|
|
359
|
+
layout.doc.fontSize(7).fillColor(COLORS.ink);
|
|
360
|
+
writeText(layout.doc, truncate(s.label, 18), legendX + 10, legendY - 1);
|
|
361
|
+
legendX += 10 + layout.doc.widthOfString(truncate(s.label, 18)) + 14;
|
|
362
|
+
if (legendX > frame.x + frame.w - 80)
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
const drawStackedAreaAsBars = (layout, points, height = 170) => {
|
|
367
|
+
const frame = chartFrame(layout, height);
|
|
368
|
+
const pad = { t: 16, r: 12, b: 40, l: 36 };
|
|
369
|
+
const plotW = frame.w - pad.l - pad.r;
|
|
370
|
+
const plotH = frame.h - pad.t - pad.b;
|
|
371
|
+
const totals = points.map((p) => p.likes + p.comments + p.reposts + p.bookmarks);
|
|
372
|
+
const max = Math.max(1, ...totals);
|
|
373
|
+
const barGap = 3;
|
|
374
|
+
const barW = points.length
|
|
375
|
+
? Math.max(3, (plotW - barGap * (points.length - 1)) / points.length)
|
|
376
|
+
: plotW;
|
|
377
|
+
points.forEach((p, i) => {
|
|
378
|
+
let stacked = 0;
|
|
379
|
+
const x = frame.x + pad.l + i * (barW + barGap);
|
|
380
|
+
for (const meta of ENGAGEMENT_SERIES) {
|
|
381
|
+
const v = p[meta.key];
|
|
382
|
+
if (v <= 0)
|
|
383
|
+
continue;
|
|
384
|
+
const h = (v / max) * plotH;
|
|
385
|
+
const y = frame.y + pad.t + plotH - stacked - h;
|
|
386
|
+
layout.doc.rect(x, y, barW, h).fill(meta.color);
|
|
387
|
+
stacked += h;
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
const labelStep = Math.max(1, Math.floor(points.length / 8));
|
|
391
|
+
points.forEach((p, i) => {
|
|
392
|
+
if (i % labelStep !== 0 && i !== points.length - 1)
|
|
393
|
+
return;
|
|
394
|
+
const x = frame.x + pad.l + i * (barW + barGap);
|
|
395
|
+
layout.doc.fontSize(7).fillColor(COLORS.muted);
|
|
396
|
+
writeText(layout.doc, truncate(p.label, 8), x - 4, frame.y + pad.t + plotH + 6, {
|
|
397
|
+
width: barW + 8,
|
|
398
|
+
align: 'center',
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
let legendX = frame.x + pad.l;
|
|
402
|
+
const legendY = frame.y + frame.h - 16;
|
|
403
|
+
for (const meta of ENGAGEMENT_SERIES) {
|
|
404
|
+
layout.doc.rect(legendX, legendY, 8, 8).fill(meta.color);
|
|
405
|
+
layout.doc.fontSize(7).fillColor(COLORS.muted);
|
|
406
|
+
writeText(layout.doc, meta.label, legendX + 11, legendY - 1);
|
|
407
|
+
legendX += 11 + layout.doc.widthOfString(meta.label) + 12;
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
const drawHorizontalBars = (layout, rows) => {
|
|
411
|
+
var _a;
|
|
412
|
+
const max = Math.max(1, ...rows.map((r) => r.value));
|
|
413
|
+
const rowH = 22;
|
|
414
|
+
ensureSpace(layout, rows.length * rowH + 20);
|
|
415
|
+
for (const row of rows) {
|
|
416
|
+
ensureSpace(layout, rowH);
|
|
417
|
+
layout.doc.fontSize(9).fillColor(COLORS.ink);
|
|
418
|
+
writeText(layout.doc, row.label, MARGIN, layout.y, { width: 100 });
|
|
419
|
+
const barX = MARGIN + 110;
|
|
420
|
+
const barW = CONTENT_WIDTH - 180;
|
|
421
|
+
layout.doc.roundedRect(barX, layout.y + 2, barW, 10, 3).fill(COLORS.soft);
|
|
422
|
+
layout.doc
|
|
423
|
+
.roundedRect(barX, layout.y + 2, (row.value / max) * barW, 10, 3)
|
|
424
|
+
.fill(row.color);
|
|
425
|
+
layout.doc.fontSize(9).fillColor(COLORS.muted);
|
|
426
|
+
writeText(layout.doc, `${formatNum(row.value)}${(_a = row.suffix) !== null && _a !== void 0 ? _a : ''}`, barX + barW + 8, layout.y, { width: 60, align: 'right' });
|
|
427
|
+
layout.y += rowH;
|
|
428
|
+
}
|
|
429
|
+
layout.y += 8;
|
|
430
|
+
};
|
|
431
|
+
const drawDayHeatmap = (layout, cells) => {
|
|
432
|
+
if (cells.length === 0) {
|
|
433
|
+
layout.doc.fontSize(9).fillColor(COLORS.muted);
|
|
434
|
+
writeText(layout.doc, 'No signup data in this period', MARGIN, layout.y);
|
|
435
|
+
layout.y += 24;
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
const cellSize = 10;
|
|
439
|
+
const gap = 2;
|
|
440
|
+
const cols = Math.min(28, Math.ceil(Math.sqrt(cells.length * 2)));
|
|
441
|
+
const rows = Math.ceil(cells.length / cols);
|
|
442
|
+
const max = Math.max(1, ...cells.map((c) => c.value));
|
|
443
|
+
ensureSpace(layout, rows * (cellSize + gap) + 24);
|
|
444
|
+
cells.forEach((c, i) => {
|
|
445
|
+
const col = i % cols;
|
|
446
|
+
const row = Math.floor(i / cols);
|
|
447
|
+
const x = MARGIN + col * (cellSize + gap);
|
|
448
|
+
const y = layout.y + row * (cellSize + gap);
|
|
449
|
+
const t = c.value / max;
|
|
450
|
+
const shade = Math.round(255 - t * 180);
|
|
451
|
+
const fill = `#${shade.toString(16).padStart(2, '0').repeat(3)}`;
|
|
452
|
+
layout.doc
|
|
453
|
+
.rect(x, y, cellSize, cellSize)
|
|
454
|
+
.fill(c.value === 0 ? COLORS.soft : fill);
|
|
455
|
+
});
|
|
456
|
+
layout.y += rows * (cellSize + gap) + 12;
|
|
457
|
+
layout.doc.fontSize(8).fillColor(COLORS.muted);
|
|
458
|
+
writeText(layout.doc, 'Darker cells = more signups that day', MARGIN, layout.y);
|
|
459
|
+
layout.y += 16;
|
|
460
|
+
};
|
|
461
|
+
const drawTable = (layout, columns, rows) => {
|
|
462
|
+
var _a, _b;
|
|
463
|
+
const headerH = 18;
|
|
464
|
+
const rowH = 16;
|
|
465
|
+
ensureSpace(layout, headerH + rowH * Math.min(rows.length, 3) + 8);
|
|
466
|
+
const drawHeader = () => {
|
|
467
|
+
var _a;
|
|
468
|
+
layout.doc.rect(MARGIN, layout.y, CONTENT_WIDTH, headerH).fill(COLORS.soft);
|
|
469
|
+
let x = MARGIN + 6;
|
|
470
|
+
for (const col of columns) {
|
|
471
|
+
layout.doc.fontSize(8).fillColor(COLORS.muted).font('Helvetica-Bold');
|
|
472
|
+
writeText(layout.doc, col.header.toUpperCase(), x, layout.y + 5, {
|
|
473
|
+
width: col.width - 8,
|
|
474
|
+
align: (_a = col.align) !== null && _a !== void 0 ? _a : 'left',
|
|
475
|
+
});
|
|
476
|
+
x += col.width;
|
|
477
|
+
}
|
|
478
|
+
layout.y += headerH;
|
|
479
|
+
layout.doc.font('Helvetica');
|
|
480
|
+
};
|
|
481
|
+
drawHeader();
|
|
482
|
+
for (const row of rows) {
|
|
483
|
+
if (layout.y + rowH + 2 > BOTTOM - 20) {
|
|
484
|
+
newPage(layout);
|
|
485
|
+
drawHeader();
|
|
486
|
+
}
|
|
487
|
+
let x = MARGIN + 6;
|
|
488
|
+
for (const col of columns) {
|
|
489
|
+
layout.doc.fontSize(8).fillColor(COLORS.ink);
|
|
490
|
+
writeText(layout.doc, (_a = row[col.key]) !== null && _a !== void 0 ? _a : '', x, layout.y + 3, {
|
|
491
|
+
width: col.width - 8,
|
|
492
|
+
align: (_b = col.align) !== null && _b !== void 0 ? _b : 'left',
|
|
493
|
+
ellipsis: true,
|
|
494
|
+
});
|
|
495
|
+
x += col.width;
|
|
496
|
+
}
|
|
497
|
+
layout.y += rowH;
|
|
498
|
+
layout.doc
|
|
499
|
+
.moveTo(MARGIN, layout.y)
|
|
500
|
+
.lineTo(MARGIN + CONTENT_WIDTH, layout.y)
|
|
501
|
+
.strokeColor(COLORS.border)
|
|
502
|
+
.lineWidth(0.5)
|
|
503
|
+
.stroke();
|
|
504
|
+
}
|
|
505
|
+
layout.y += 12;
|
|
506
|
+
};
|
|
507
|
+
const startSection = (layout, title) => {
|
|
508
|
+
newPage(layout, title);
|
|
509
|
+
};
|
|
510
|
+
const drawOverviewPage = (layout, overview) => {
|
|
511
|
+
layout.sectionTitle = 'Overview';
|
|
512
|
+
drawPageChrome(layout);
|
|
513
|
+
drawMetricCards(layout, [
|
|
514
|
+
{
|
|
515
|
+
label: 'Total members',
|
|
516
|
+
value: formatNum(overview.metrics.totalMembers.value),
|
|
517
|
+
deltaPct: overview.metrics.totalMembers.deltaPct,
|
|
518
|
+
subtitle: 'All-time',
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
label: 'Active members',
|
|
522
|
+
value: formatNum(overview.metrics.activeMembers.value),
|
|
523
|
+
deltaPct: overview.metrics.activeMembers.deltaPct,
|
|
524
|
+
subtitle: 'This period',
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
label: 'Posts',
|
|
528
|
+
value: formatNum(overview.metrics.totalPosts.value),
|
|
529
|
+
deltaPct: overview.metrics.totalPosts.deltaPct,
|
|
530
|
+
subtitle: 'This period',
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
label: 'Groups',
|
|
534
|
+
value: formatNum(overview.metrics.totalGroups.value),
|
|
535
|
+
deltaPct: overview.metrics.totalGroups.deltaPct,
|
|
536
|
+
subtitle: 'All-time',
|
|
537
|
+
},
|
|
538
|
+
]);
|
|
539
|
+
drawSectionTitle(layout, 'Posts over time');
|
|
540
|
+
drawStackedBarChart(layout, overview.postsOverTime);
|
|
541
|
+
drawSectionTitle(layout, 'Active users');
|
|
542
|
+
drawLineChart(layout, overview.activeUsersSeries.map((p) => ({
|
|
543
|
+
label: p.label,
|
|
544
|
+
value: p.value,
|
|
545
|
+
})));
|
|
546
|
+
drawSectionTitle(layout, 'Top members');
|
|
547
|
+
drawTable(layout, [
|
|
548
|
+
{ key: 'member', header: 'Member', width: 180 },
|
|
549
|
+
{ key: 'role', header: 'Role', width: 100 },
|
|
550
|
+
{ key: 'joined', header: 'Joined', width: 100 },
|
|
551
|
+
{ key: 'contrib', header: 'Contributions', width: 152, align: 'right' },
|
|
552
|
+
], overview.topMembers.slice(0, 8).map((m) => {
|
|
553
|
+
var _a, _b;
|
|
554
|
+
return ({
|
|
555
|
+
member: truncate((_a = m.displayName) !== null && _a !== void 0 ? _a : m.handle, 28),
|
|
556
|
+
role: (_b = m.role) !== null && _b !== void 0 ? _b : 'member',
|
|
557
|
+
joined: m.joinedAt.slice(0, 10),
|
|
558
|
+
contrib: formatNum(m.contributions),
|
|
559
|
+
});
|
|
560
|
+
}));
|
|
561
|
+
drawSectionTitle(layout, 'Top posts');
|
|
562
|
+
drawTable(layout, [
|
|
563
|
+
{ key: 'post', header: 'Post', width: 260 },
|
|
564
|
+
{ key: 'author', header: 'Author', width: 140 },
|
|
565
|
+
{ key: 'views', header: 'Viewers', width: 132, align: 'right' },
|
|
566
|
+
], overview.topPosts.slice(0, 8).map((p) => {
|
|
567
|
+
var _a, _b, _c;
|
|
568
|
+
return ({
|
|
569
|
+
post: truncate((_a = p.snippet) !== null && _a !== void 0 ? _a : p.postId, 42),
|
|
570
|
+
author: truncate((_c = (_b = p.authorDisplayName) !== null && _b !== void 0 ? _b : p.authorHandle) !== null && _c !== void 0 ? _c : '—', 22),
|
|
571
|
+
views: formatNum(p.uniqueViewers),
|
|
572
|
+
});
|
|
573
|
+
}));
|
|
574
|
+
};
|
|
575
|
+
const drawMembersPage = (layout, overview, growth) => {
|
|
576
|
+
var _a;
|
|
577
|
+
startSection(layout, 'Members');
|
|
578
|
+
const engagementRate = averageSeries(overview.engagementRateSeries);
|
|
579
|
+
drawMetricCards(layout, [
|
|
580
|
+
{
|
|
581
|
+
label: 'Total members',
|
|
582
|
+
value: formatNum(overview.metrics.totalMembers.value),
|
|
583
|
+
deltaPct: overview.metrics.totalMembers.deltaPct,
|
|
584
|
+
subtitle: 'All-time',
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
label: 'New members',
|
|
588
|
+
value: formatNum(growth.metrics.newSignups.value),
|
|
589
|
+
deltaPct: growth.metrics.newSignups.deltaPct,
|
|
590
|
+
subtitle: 'This period',
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
label: 'Active members',
|
|
594
|
+
value: formatNum(overview.metrics.activeMembers.value),
|
|
595
|
+
deltaPct: overview.metrics.activeMembers.deltaPct,
|
|
596
|
+
subtitle: 'This period',
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
label: 'Engagement rate',
|
|
600
|
+
value: `${engagementRate}%`,
|
|
601
|
+
subtitle: 'This period',
|
|
602
|
+
},
|
|
603
|
+
]);
|
|
604
|
+
drawSectionTitle(layout, 'Signups by day');
|
|
605
|
+
const signupsByDay = growth.signupsByDay.length > 0
|
|
606
|
+
? growth.signupsByDay
|
|
607
|
+
: ((_a = growth.metrics.newSignups.series) !== null && _a !== void 0 ? _a : []).map((p) => ({
|
|
608
|
+
day: p.day,
|
|
609
|
+
value: p.value,
|
|
610
|
+
}));
|
|
611
|
+
drawDayHeatmap(layout, signupsByDay);
|
|
612
|
+
drawSectionTitle(layout, 'Recent signups');
|
|
613
|
+
drawTable(layout, [
|
|
614
|
+
{ key: 'member', header: 'Member', width: 180 },
|
|
615
|
+
{ key: 'channel', header: 'Channel', width: 140 },
|
|
616
|
+
{ key: 'joined', header: 'Joined', width: 212 },
|
|
617
|
+
], growth.recentSignups.slice(0, 12).map((s) => {
|
|
618
|
+
var _a;
|
|
619
|
+
return ({
|
|
620
|
+
member: truncate((_a = s.displayName) !== null && _a !== void 0 ? _a : s.handle, 28),
|
|
621
|
+
channel: s.channel,
|
|
622
|
+
joined: s.joinedAt.slice(0, 10),
|
|
623
|
+
});
|
|
624
|
+
}));
|
|
625
|
+
};
|
|
626
|
+
const drawContentPage = (layout, overview) => {
|
|
627
|
+
startSection(layout, 'Content');
|
|
628
|
+
const postsThisPeriod = overview.metrics.totalPosts.value;
|
|
629
|
+
const days = utcDayCount(overview.range.from, overview.range.to);
|
|
630
|
+
const avgPostsPerDay = Math.round((postsThisPeriod / days) * 10) / 10;
|
|
631
|
+
drawMetricCards(layout, [
|
|
632
|
+
{
|
|
633
|
+
label: 'Total posts',
|
|
634
|
+
value: formatNum(overview.metrics.allTimePosts.value),
|
|
635
|
+
deltaPct: overview.metrics.allTimePosts.deltaPct,
|
|
636
|
+
subtitle: 'All-time',
|
|
637
|
+
},
|
|
638
|
+
{
|
|
639
|
+
label: 'Posts this period',
|
|
640
|
+
value: formatNum(postsThisPeriod),
|
|
641
|
+
deltaPct: overview.metrics.totalPosts.deltaPct,
|
|
642
|
+
subtitle: 'This period',
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
label: 'Avg posts / day',
|
|
646
|
+
value: String(avgPostsPerDay),
|
|
647
|
+
subtitle: 'This period',
|
|
648
|
+
},
|
|
649
|
+
]);
|
|
650
|
+
drawSectionTitle(layout, 'Posts by period');
|
|
651
|
+
drawBarChart(layout, overview.postsOverTime.map((p) => ({
|
|
652
|
+
label: p.label,
|
|
653
|
+
value: p.jam + p.article + p.note + p.poll + p.event,
|
|
654
|
+
})));
|
|
655
|
+
drawSectionTitle(layout, 'Content distribution');
|
|
656
|
+
const typeRows = POST_TYPE_META.map((meta) => {
|
|
657
|
+
var _a;
|
|
658
|
+
const found = overview.postTypes.find((p) => p.type === meta.key);
|
|
659
|
+
return {
|
|
660
|
+
label: meta.label,
|
|
661
|
+
value: (_a = found === null || found === void 0 ? void 0 : found.count) !== null && _a !== void 0 ? _a : 0,
|
|
662
|
+
color: meta.color,
|
|
663
|
+
};
|
|
664
|
+
}).filter((r) => r.value > 0);
|
|
665
|
+
drawHorizontalBars(layout, typeRows);
|
|
666
|
+
};
|
|
667
|
+
const drawEngagementPage = (layout, engagement) => {
|
|
668
|
+
startSection(layout, 'Engagement');
|
|
669
|
+
drawMetricCards(layout, [
|
|
670
|
+
{
|
|
671
|
+
label: 'Likes',
|
|
672
|
+
value: formatNum(engagement.metrics.likes.value),
|
|
673
|
+
deltaPct: engagement.metrics.likes.deltaPct,
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
label: 'Replies',
|
|
677
|
+
value: formatNum(engagement.metrics.comments.value),
|
|
678
|
+
deltaPct: engagement.metrics.comments.deltaPct,
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
label: 'Shares',
|
|
682
|
+
value: formatNum(engagement.metrics.reposts.value),
|
|
683
|
+
deltaPct: engagement.metrics.reposts.deltaPct,
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
label: 'Bookmarks',
|
|
687
|
+
value: formatNum(engagement.metrics.bookmarks.value),
|
|
688
|
+
deltaPct: engagement.metrics.bookmarks.deltaPct,
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
label: 'DMs',
|
|
692
|
+
value: formatNum(engagement.metrics.dms.value),
|
|
693
|
+
deltaPct: engagement.metrics.dms.deltaPct,
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
label: 'Unique viewers',
|
|
697
|
+
value: formatNum(engagement.metrics.uniqueViewers.value),
|
|
698
|
+
deltaPct: engagement.metrics.uniqueViewers.deltaPct,
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
label: 'Impressions',
|
|
702
|
+
value: formatNum(engagement.metrics.impressions.value),
|
|
703
|
+
deltaPct: engagement.metrics.impressions.deltaPct,
|
|
704
|
+
},
|
|
705
|
+
]);
|
|
706
|
+
drawSectionTitle(layout, 'Engagement over time');
|
|
707
|
+
drawStackedAreaAsBars(layout, engagement.engagementOverTime);
|
|
708
|
+
drawSectionTitle(layout, 'Views / impressions by period');
|
|
709
|
+
drawBarChart(layout, engagement.impressionsByPeriod.map((p) => ({
|
|
710
|
+
label: p.label,
|
|
711
|
+
value: p.value,
|
|
712
|
+
})), 150);
|
|
713
|
+
drawSectionTitle(layout, 'Engagement rate breakdown');
|
|
714
|
+
const views = engagement.metrics.impressions.value;
|
|
715
|
+
drawHorizontalBars(layout, [
|
|
716
|
+
{
|
|
717
|
+
label: 'Like rate',
|
|
718
|
+
value: ratePct(engagement.metrics.likes.value, views),
|
|
719
|
+
color: GRAY_STACK[0],
|
|
720
|
+
suffix: '%',
|
|
721
|
+
},
|
|
722
|
+
{
|
|
723
|
+
label: 'Share rate',
|
|
724
|
+
value: ratePct(engagement.metrics.reposts.value, views),
|
|
725
|
+
color: GRAY_STACK[1],
|
|
726
|
+
suffix: '%',
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
label: 'Bookmark rate',
|
|
730
|
+
value: ratePct(engagement.metrics.bookmarks.value, views),
|
|
731
|
+
color: GRAY_STACK[2],
|
|
732
|
+
suffix: '%',
|
|
733
|
+
},
|
|
734
|
+
{
|
|
735
|
+
label: 'Comment rate',
|
|
736
|
+
value: ratePct(engagement.metrics.comments.value, views),
|
|
737
|
+
color: GRAY_STACK[3],
|
|
738
|
+
suffix: '%',
|
|
739
|
+
},
|
|
740
|
+
{
|
|
741
|
+
label: 'Overall',
|
|
742
|
+
value: ratePct(engagement.metrics.likes.value +
|
|
743
|
+
engagement.metrics.reposts.value +
|
|
744
|
+
engagement.metrics.bookmarks.value +
|
|
745
|
+
engagement.metrics.comments.value, views),
|
|
746
|
+
color: COLORS.accent,
|
|
747
|
+
suffix: '%',
|
|
748
|
+
},
|
|
749
|
+
]);
|
|
750
|
+
};
|
|
751
|
+
const drawGroupsPage = (layout, overview) => {
|
|
752
|
+
startSection(layout, 'Groups');
|
|
753
|
+
drawSectionTitle(layout, 'Top groups by activity');
|
|
754
|
+
drawTable(layout, [
|
|
755
|
+
{ key: 'group', header: 'Group', width: 160 },
|
|
756
|
+
{ key: 'visibility', header: 'Visibility', width: 70 },
|
|
757
|
+
{ key: 'members', header: 'Members', width: 90, align: 'right' },
|
|
758
|
+
{ key: 'posts', header: 'Posts', width: 60, align: 'right' },
|
|
759
|
+
{ key: 'engagement', header: 'Engagement', width: 80, align: 'right' },
|
|
760
|
+
{ key: 'growth', header: 'Growth', width: 72, align: 'right' },
|
|
761
|
+
], overview.topGroups.map((g) => {
|
|
762
|
+
var _a, _b;
|
|
763
|
+
return ({
|
|
764
|
+
group: truncate((_b = (_a = g.name) !== null && _a !== void 0 ? _a : g.handle) !== null && _b !== void 0 ? _b : g.groupId, 24),
|
|
765
|
+
visibility: g.visibility === 'public' ? 'Public' : 'Private',
|
|
766
|
+
members: `${formatNum(g.members)} / ${formatNum(g.activeMembers)}`,
|
|
767
|
+
posts: formatNum(g.posts),
|
|
768
|
+
engagement: `${g.engagementRate}%`,
|
|
769
|
+
growth: g.growth > 0 ? `+${g.growth}` : String(g.growth),
|
|
770
|
+
});
|
|
771
|
+
}));
|
|
772
|
+
drawSectionTitle(layout, 'Group growth (new members, cumulative)');
|
|
773
|
+
const series = overview.groupGrowthSeries.map((s, i) => ({
|
|
774
|
+
key: s.key,
|
|
775
|
+
label: s.name,
|
|
776
|
+
color: GROUP_COLORS[i % GROUP_COLORS.length],
|
|
777
|
+
}));
|
|
778
|
+
const points = cumulativeGrowth(overview.groupGrowthOverTime, overview.groupGrowthSeries);
|
|
779
|
+
if (series.length === 0) {
|
|
780
|
+
layout.doc.fontSize(9).fillColor(COLORS.muted);
|
|
781
|
+
writeText(layout.doc, 'No group membership growth in this period', MARGIN, layout.y);
|
|
782
|
+
layout.y += 20;
|
|
783
|
+
}
|
|
784
|
+
else {
|
|
785
|
+
drawMultiLineChart(layout, points, series);
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
/** Multi-page visual PDF mirroring the analytics tabs. */
|
|
789
|
+
export const buildAnalyticsPdf = async (data) => {
|
|
790
|
+
const doc = createDoc();
|
|
791
|
+
const pending = bufferFromDoc(doc);
|
|
792
|
+
const period = `${data.overview.range.from} to ${data.overview.range.to}`;
|
|
793
|
+
const layout = {
|
|
794
|
+
doc,
|
|
795
|
+
y: MARGIN,
|
|
796
|
+
pageIndex: 1,
|
|
797
|
+
period,
|
|
798
|
+
sectionTitle: 'Overview',
|
|
799
|
+
};
|
|
800
|
+
// Cover strip on first page before section chrome
|
|
801
|
+
doc.fontSize(10).fillColor(COLORS.muted).font('Helvetica');
|
|
802
|
+
writeText(doc, 'OpenPeeps - Community analytics', MARGIN, layout.y, {
|
|
803
|
+
width: CONTENT_WIDTH,
|
|
804
|
+
});
|
|
805
|
+
layout.y += 16;
|
|
806
|
+
doc.fontSize(22).fillColor(COLORS.ink).font('Helvetica-Bold');
|
|
807
|
+
writeText(doc, 'Analytics report', MARGIN, layout.y, {
|
|
808
|
+
width: CONTENT_WIDTH,
|
|
809
|
+
height: 26,
|
|
810
|
+
});
|
|
811
|
+
layout.y += 28;
|
|
812
|
+
doc.font('Helvetica');
|
|
813
|
+
drawOverviewPage(layout, data.overview);
|
|
814
|
+
drawMembersPage(layout, data.overview, data.growth);
|
|
815
|
+
drawContentPage(layout, data.overview);
|
|
816
|
+
drawEngagementPage(layout, data.engagement);
|
|
817
|
+
drawGroupsPage(layout, data.overview);
|
|
818
|
+
drawFooter(layout);
|
|
819
|
+
doc.end();
|
|
820
|
+
return pending;
|
|
821
|
+
};
|