@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,11 @@
|
|
|
1
|
+
import { AccessToken, AccessTokenWithMeta, ProfileWithMeta, Scope } from '@openpeepshq/common/types';
|
|
2
|
+
type AccessTokenWithScopes = AccessTokenWithMeta & {
|
|
3
|
+
scopes?: Scope[];
|
|
4
|
+
};
|
|
5
|
+
export declare const isServiceAccessToken: (token: AccessToken) => boolean;
|
|
6
|
+
export declare const findAccessToken: (id: string) => Promise<AccessTokenWithScopes | undefined>;
|
|
7
|
+
export declare const listAccessTokens: () => Promise<AccessTokenWithScopes[]>;
|
|
8
|
+
export declare const listAccessTokensForProfile: (profile: ProfileWithMeta) => Promise<AccessTokenWithScopes[]>;
|
|
9
|
+
export declare const listServiceAccessTokens: () => Promise<AccessTokenWithScopes[]>;
|
|
10
|
+
export declare const isRevoked: (id: string) => Promise<boolean>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { authorizationSchema, } from '@openpeepshq/common/types';
|
|
2
|
+
import { decodeJwtPayloadUnverified, parseScopesFromJwt, } from '@openpeepshq/common';
|
|
3
|
+
import { allpeepDb } from '../db/index.js';
|
|
4
|
+
import { getProfile } from '../profiles/cache.js';
|
|
5
|
+
import { profilesMapping } from '../profiles/mapping.js';
|
|
6
|
+
import { accessTokensMapping, profileAccessTokensRelation } from './mapping.js';
|
|
7
|
+
import { isMaybeRevoked } from './revokations.js';
|
|
8
|
+
export const isServiceAccessToken = (token) => {
|
|
9
|
+
if (!token.signedToken) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const payload = decodeJwtPayloadUnverified(token.signedToken);
|
|
14
|
+
const parsed = authorizationSchema.safeParse(payload);
|
|
15
|
+
return parsed.success && !!parsed.data.identities.service;
|
|
16
|
+
}
|
|
17
|
+
catch (_a) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const withCachedOwnerAndScopes = async (token) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const ownerId = (_a = token.ownedBy) === null || _a === void 0 ? void 0 : _a.id;
|
|
24
|
+
const scopes = parseScopesFromJwt(token.signedToken);
|
|
25
|
+
if (!ownerId) {
|
|
26
|
+
return Object.assign(Object.assign({}, token), { ownedBy: undefined, scopes });
|
|
27
|
+
}
|
|
28
|
+
const owner = await getProfile(ownerId);
|
|
29
|
+
return Object.assign(Object.assign({}, token), { ownedBy: owner, scopes });
|
|
30
|
+
};
|
|
31
|
+
export const findAccessToken = (id) => allpeepDb().then(({ db }) => accessTokensMapping
|
|
32
|
+
.find(db, id)
|
|
33
|
+
.then((t) => (t ? withCachedOwnerAndScopes(t) : undefined)));
|
|
34
|
+
export const listAccessTokens = () => allpeepDb().then(async ({ db }) => {
|
|
35
|
+
const tokens = await accessTokensMapping.all(db);
|
|
36
|
+
return Promise.all(tokens.map(withCachedOwnerAndScopes));
|
|
37
|
+
});
|
|
38
|
+
export const listAccessTokensForProfile = (profile) => allpeepDb().then(async ({ db }) => profilesMapping
|
|
39
|
+
.relationsFrom(profile, profileAccessTokensRelation)
|
|
40
|
+
.all(db)
|
|
41
|
+
.then((tokens) => Promise.all(tokens.map(withCachedOwnerAndScopes))));
|
|
42
|
+
export const listServiceAccessTokens = () => listAccessTokens().then((tokens) => tokens.filter(isServiceAccessToken));
|
|
43
|
+
export const isRevoked = async (id) => { var _a; return (await isMaybeRevoked(id)) && !!((_a = (await findAccessToken(id))) === null || _a === void 0 ? void 0 : _a.revokedAt); };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PgDb } from '../db/pg/client';
|
|
2
|
+
export declare const profileAccessTokenConnector: (db: PgDb, from: {
|
|
3
|
+
id: string;
|
|
4
|
+
}, to: {
|
|
5
|
+
id: string;
|
|
6
|
+
}, data?: {
|
|
7
|
+
id?: string;
|
|
8
|
+
}) => Promise<import("../db/pg/map").WithId<{
|
|
9
|
+
_from: string;
|
|
10
|
+
_to: string;
|
|
11
|
+
}>>;
|
|
12
|
+
export declare const removeEdgesForAccessToken: (db: PgDb, accessTokenId: string) => Promise<void>;
|
|
13
|
+
export declare const deleteAccessTokensForProfile: (db: PgDb, profileId: string) => Promise<void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { eq } from 'drizzle-orm';
|
|
2
|
+
import { connector } from '../db/helpers.js';
|
|
3
|
+
import { profileAccessTokens } from '../db/pg/schema/edges.js';
|
|
4
|
+
import { collectionInfos } from '../db/index.js';
|
|
5
|
+
import { profilesMapping } from '../profiles/mapping.js';
|
|
6
|
+
import { profileAccessTokensRelation } from './mapping.js';
|
|
7
|
+
export const profileAccessTokenConnector = connector(collectionInfos.profilesCollection, collectionInfos.accessTokensCollection, collectionInfos.profileAccessTokensCollection);
|
|
8
|
+
export const removeEdgesForAccessToken = async (db, accessTokenId) => {
|
|
9
|
+
await db
|
|
10
|
+
.delete(profileAccessTokens)
|
|
11
|
+
.where(eq(profileAccessTokens.toId, accessTokenId));
|
|
12
|
+
};
|
|
13
|
+
export const deleteAccessTokensForProfile = async (db, profileId) => {
|
|
14
|
+
await profilesMapping.deleteRelations(db, profileId, profileAccessTokensRelation);
|
|
15
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RelationWithMapping } from '../db/pg/map';
|
|
2
|
+
import { AccessToken } from '@openpeepshq/common/types';
|
|
3
|
+
export declare const accessTokensMapping: import("../db/pg/map").Mapping<{
|
|
4
|
+
name: string;
|
|
5
|
+
signedToken: string;
|
|
6
|
+
description?: string | undefined;
|
|
7
|
+
revokedAt?: string | null | undefined;
|
|
8
|
+
expiresAt?: string | null | undefined;
|
|
9
|
+
}, AccessToken, AccessToken>;
|
|
10
|
+
export declare const profileAccessTokensRelation: RelationWithMapping<AccessToken>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { map } from '../db/pg/map/index.js';
|
|
2
|
+
import { collectionInfos } from '../db/index.js';
|
|
3
|
+
import { baseProfilesMapping } from '../profiles/mapping.js';
|
|
4
|
+
const accessTokensCollection = collectionInfos.accessTokensCollection.name;
|
|
5
|
+
const profileAccessTokensEdge = collectionInfos.profileAccessTokensCollection.name;
|
|
6
|
+
const accessTokenOwnedByRelation = {
|
|
7
|
+
alias: 'ownedBy',
|
|
8
|
+
edgeCollection: profileAccessTokensEdge,
|
|
9
|
+
direction: 'INBOUND',
|
|
10
|
+
skipEdge: true,
|
|
11
|
+
cardinality: 'one',
|
|
12
|
+
mapping: baseProfilesMapping.data(),
|
|
13
|
+
};
|
|
14
|
+
export const accessTokensMapping = map({
|
|
15
|
+
collection: accessTokensCollection,
|
|
16
|
+
relations: [accessTokenOwnedByRelation],
|
|
17
|
+
});
|
|
18
|
+
export const profileAccessTokensRelation = {
|
|
19
|
+
alias: 'accessTokens',
|
|
20
|
+
edgeCollection: profileAccessTokensEdge,
|
|
21
|
+
direction: 'OUTBOUND',
|
|
22
|
+
skipEdge: true,
|
|
23
|
+
cardinality: 'many',
|
|
24
|
+
mapping: accessTokensMapping.data(),
|
|
25
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AccessTokenData, ProfileWithMeta } from '@openpeepshq/common/types';
|
|
2
|
+
export declare const createAccessToken: (profile: ProfileWithMeta | undefined, data: AccessTokenData) => Promise<import("@openpeepshq/common").AccessToken>;
|
|
3
|
+
export declare const deleteAccessToken: (id: string) => Promise<void>;
|
|
4
|
+
export declare const revokeAccessToken: (id: string) => Promise<import("@openpeepshq/common").AccessToken>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { allpeepDb } from '../db/index.js';
|
|
2
|
+
import { profileAccessTokenConnector, removeEdgesForAccessToken, } from './helpers.js';
|
|
3
|
+
import { accessTokensMapping } from './mapping.js';
|
|
4
|
+
import { uuidv7 } from 'uuidv7';
|
|
5
|
+
import { addToBloomFilter } from './revokations.js';
|
|
6
|
+
export const createAccessToken = (profile, data) => allpeepDb().then(async ({ db }) => {
|
|
7
|
+
const id = uuidv7();
|
|
8
|
+
const accessToken = await accessTokensMapping.create(db, Object.assign(Object.assign({}, data), { id }));
|
|
9
|
+
if (profile) {
|
|
10
|
+
await profileAccessTokenConnector(db, profile, accessToken);
|
|
11
|
+
}
|
|
12
|
+
return accessToken;
|
|
13
|
+
});
|
|
14
|
+
export const deleteAccessToken = (id) => allpeepDb().then(async ({ db }) => {
|
|
15
|
+
await removeEdgesForAccessToken(db, id);
|
|
16
|
+
return accessTokensMapping.delete(db, id);
|
|
17
|
+
});
|
|
18
|
+
export const revokeAccessToken = (id) => allpeepDb().then(async ({ db }) => {
|
|
19
|
+
const accessToken = await accessTokensMapping.update(db, id, {
|
|
20
|
+
revokedAt: new Date().toISOString(),
|
|
21
|
+
});
|
|
22
|
+
addToBloomFilter(id);
|
|
23
|
+
return accessToken;
|
|
24
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getConnection } from '../redis/index.js';
|
|
2
|
+
const revocationsBloomFilterKey = 'revocations:bloom-filter';
|
|
3
|
+
const initRevocationsBloomFilter = async () => {
|
|
4
|
+
const connection = await getConnection();
|
|
5
|
+
if (!(await connection.exists(revocationsBloomFilterKey))) {
|
|
6
|
+
await connection.bf.reserve(revocationsBloomFilterKey, 0.01, 1000);
|
|
7
|
+
}
|
|
8
|
+
return connection;
|
|
9
|
+
};
|
|
10
|
+
let bfConnection = undefined;
|
|
11
|
+
const getBloomFilterConnection = async () => {
|
|
12
|
+
if (!bfConnection) {
|
|
13
|
+
bfConnection = await initRevocationsBloomFilter();
|
|
14
|
+
}
|
|
15
|
+
return bfConnection;
|
|
16
|
+
};
|
|
17
|
+
export const addToBloomFilter = (id) => getBloomFilterConnection().then((redis) => redis.bf.add(revocationsBloomFilterKey, id));
|
|
18
|
+
export const isMaybeRevoked = (id) => getBloomFilterConnection().then((redis) => redis.bf.exists(revocationsBloomFilterKey, id));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AccessToken, AccountWithMeta, Authorization, ProfileWithMeta, Scope } from '@openpeepshq/common/types';
|
|
2
|
+
export declare const verifySignedAccessToken: (token: string) => Promise<Authorization | undefined>;
|
|
3
|
+
export declare const createSignedAccessToken: ({ profile, authorization, name, description, expirationTime, }: {
|
|
4
|
+
profile?: ProfileWithMeta;
|
|
5
|
+
name: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
authorization: Authorization;
|
|
8
|
+
expirationTime: string;
|
|
9
|
+
}) => Promise<AccessToken>;
|
|
10
|
+
export declare const createSignedProfileAccessToken: ({ profile, account, name, description, scopes, expirationTime, }: {
|
|
11
|
+
profile?: ProfileWithMeta;
|
|
12
|
+
account?: AccountWithMeta;
|
|
13
|
+
name: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
scopes?: [Scope, ...Scope[]];
|
|
16
|
+
expirationTime: string;
|
|
17
|
+
}) => Promise<AccessToken>;
|
|
18
|
+
export declare const createSignedServiceToken: ({ scopes, name, description, expirationTime, }: {
|
|
19
|
+
scopes: Scope[];
|
|
20
|
+
name: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
expirationTime: string;
|
|
23
|
+
}) => Promise<AccessToken>;
|
|
24
|
+
export declare const createSignedGuestPass: (profile: ProfileWithMeta, expirationTime?: string) => Promise<AccessToken>;
|
|
25
|
+
export declare const createSignedDbToken: (profile: ProfileWithMeta) => Promise<AccessToken>;
|
|
26
|
+
/**
|
|
27
|
+
* Issues a new JWT with the same {@link Authorization} (profile/account/service identities and scopes)
|
|
28
|
+
* as the presented token. Requires a valid, unexpired JWT (EdDSA + standard `exp` checks), then checks
|
|
29
|
+
* revocation and revokes the old token record.
|
|
30
|
+
*/
|
|
31
|
+
export declare const refreshSignedAccessToken: (token: string) => Promise<AccessToken | undefined>;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { authorizationSchema, } from '@openpeepshq/common/types';
|
|
2
|
+
import { uuidv7 } from 'uuidv7';
|
|
3
|
+
import { findAccount } from '../accounts/finders.js';
|
|
4
|
+
import { jwtUtil } from '../jwt/index.js';
|
|
5
|
+
import { findProfile } from '../profiles/finders.js';
|
|
6
|
+
import { findAccessToken, isRevoked } from './finders.js';
|
|
7
|
+
import { createAccessToken, revokeAccessToken } from './mutations.js';
|
|
8
|
+
export const verifySignedAccessToken = (token) => jwtUtil()
|
|
9
|
+
.then((jwt) => jwt.verify(token))
|
|
10
|
+
.then(async (result) => {
|
|
11
|
+
var _a;
|
|
12
|
+
if (!((_a = result === null || result === void 0 ? void 0 : result.payload) === null || _a === void 0 ? void 0 : _a.jti)) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const id = result.payload.jti;
|
|
16
|
+
if (!id || (await isRevoked(id))) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return result.payload;
|
|
20
|
+
});
|
|
21
|
+
export const createSignedAccessToken = async ({ profile, authorization, name, description, expirationTime, }) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const id = uuidv7();
|
|
24
|
+
const jwt = await jwtUtil();
|
|
25
|
+
const signedToken = await jwt.sign({
|
|
26
|
+
payload: authorization,
|
|
27
|
+
expirationTime,
|
|
28
|
+
id,
|
|
29
|
+
});
|
|
30
|
+
const result = await jwt.verify(signedToken);
|
|
31
|
+
if (!((_a = result === null || result === void 0 ? void 0 : result.payload) === null || _a === void 0 ? void 0 : _a.exp)) {
|
|
32
|
+
throw new Error('Failed to verify signed token');
|
|
33
|
+
}
|
|
34
|
+
const expiresAt = new Date(result.payload.exp * 1000).toISOString();
|
|
35
|
+
return createAccessToken(profile, {
|
|
36
|
+
name,
|
|
37
|
+
description,
|
|
38
|
+
signedToken,
|
|
39
|
+
expiresAt,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
export const createSignedProfileAccessToken = async ({ profile, account, name, description, scopes = [{ scopeLevel: 'admin', resource: { type: '*', id: '*' } }], expirationTime = '1y', }) => {
|
|
43
|
+
const authorization = {
|
|
44
|
+
identities: {
|
|
45
|
+
profile: profile === null || profile === void 0 ? void 0 : profile.id,
|
|
46
|
+
account: account === null || account === void 0 ? void 0 : account.id,
|
|
47
|
+
},
|
|
48
|
+
scopes,
|
|
49
|
+
};
|
|
50
|
+
return createSignedAccessToken({
|
|
51
|
+
profile,
|
|
52
|
+
authorization,
|
|
53
|
+
name,
|
|
54
|
+
description,
|
|
55
|
+
expirationTime,
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
export const createSignedServiceToken = async ({ scopes, name, description, expirationTime = '1y', }) => createSignedAccessToken({
|
|
59
|
+
name,
|
|
60
|
+
description,
|
|
61
|
+
authorization: {
|
|
62
|
+
identities: {
|
|
63
|
+
service: uuidv7(),
|
|
64
|
+
},
|
|
65
|
+
scopes,
|
|
66
|
+
},
|
|
67
|
+
expirationTime,
|
|
68
|
+
});
|
|
69
|
+
export const createSignedGuestPass = async (profile, expirationTime = '1d') => {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
if (!((_a = profile.guestData) === null || _a === void 0 ? void 0 : _a.resource)) {
|
|
72
|
+
throw new Error('Guest pass requires a resource');
|
|
73
|
+
}
|
|
74
|
+
return createSignedAccessToken({
|
|
75
|
+
profile,
|
|
76
|
+
name: profile.handle,
|
|
77
|
+
authorization: {
|
|
78
|
+
identities: {
|
|
79
|
+
profile: profile.id,
|
|
80
|
+
},
|
|
81
|
+
scopes: [
|
|
82
|
+
{
|
|
83
|
+
scopeLevel: 'read',
|
|
84
|
+
resource: (_b = profile.guestData) === null || _b === void 0 ? void 0 : _b.resource,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
expirationTime,
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
export const createSignedDbToken = (profile) => createSignedAccessToken({
|
|
92
|
+
profile,
|
|
93
|
+
name: 'db-admin',
|
|
94
|
+
expirationTime: '1h',
|
|
95
|
+
authorization: {
|
|
96
|
+
identities: {
|
|
97
|
+
profile: profile.id,
|
|
98
|
+
},
|
|
99
|
+
scopes: [
|
|
100
|
+
{
|
|
101
|
+
scopeLevel: 'admin',
|
|
102
|
+
resource: {
|
|
103
|
+
type: 'db',
|
|
104
|
+
id: uuidv7(),
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* Issues a new JWT with the same {@link Authorization} (profile/account/service identities and scopes)
|
|
112
|
+
* as the presented token. Requires a valid, unexpired JWT (EdDSA + standard `exp` checks), then checks
|
|
113
|
+
* revocation and revokes the old token record.
|
|
114
|
+
*/
|
|
115
|
+
export const refreshSignedAccessToken = async (token) => {
|
|
116
|
+
const jwt = await jwtUtil();
|
|
117
|
+
const verified = await jwt.verify(token);
|
|
118
|
+
const rawPayload = verified === null || verified === void 0 ? void 0 : verified.payload;
|
|
119
|
+
if (!(rawPayload === null || rawPayload === void 0 ? void 0 : rawPayload.jti) || typeof rawPayload.jti !== 'string') {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
const jti = rawPayload.jti;
|
|
123
|
+
if (await isRevoked(jti)) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
const exp = typeof rawPayload.exp === 'number' ? rawPayload.exp : undefined;
|
|
127
|
+
const iat = typeof rawPayload.iat === 'number' ? rawPayload.iat : undefined;
|
|
128
|
+
const authParsed = authorizationSchema.safeParse(rawPayload);
|
|
129
|
+
if (!authParsed.success) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
const authorization = authParsed.data;
|
|
133
|
+
const existing = await findAccessToken(jti);
|
|
134
|
+
if (!(existing === null || existing === void 0 ? void 0 : existing.signedToken) || existing.revokedAt) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
if (authorization.identities.profile) {
|
|
138
|
+
const p = await findProfile(authorization.identities.profile);
|
|
139
|
+
if (!p || p.deletedAt) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (authorization.identities.account) {
|
|
144
|
+
const a = await findAccount(authorization.identities.account);
|
|
145
|
+
if (!a || a.deletedAt) {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
let ttlSec;
|
|
150
|
+
if (existing.expiresAt && existing.createdAt) {
|
|
151
|
+
ttlSec = Math.floor((new Date(existing.expiresAt).getTime() -
|
|
152
|
+
new Date(existing.createdAt).getTime()) /
|
|
153
|
+
1000);
|
|
154
|
+
}
|
|
155
|
+
else if (exp !== undefined && iat !== undefined) {
|
|
156
|
+
ttlSec = exp - iat;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
ttlSec = 7 * 24 * 60 * 60;
|
|
160
|
+
}
|
|
161
|
+
const expirationTime = `${ttlSec}s`;
|
|
162
|
+
const profile = authorization.identities.profile
|
|
163
|
+
? await findProfile(authorization.identities.profile)
|
|
164
|
+
: undefined;
|
|
165
|
+
const accessToken = await createSignedAccessToken({
|
|
166
|
+
profile,
|
|
167
|
+
authorization,
|
|
168
|
+
name: existing.name,
|
|
169
|
+
description: existing.description,
|
|
170
|
+
expirationTime,
|
|
171
|
+
});
|
|
172
|
+
await revokeAccessToken(jti);
|
|
173
|
+
return accessToken;
|
|
174
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createCache } from 'cache-manager';
|
|
2
|
+
import { allpeepDb } from '../db/index.js';
|
|
3
|
+
import { accountsMapping } from './mapping.js';
|
|
4
|
+
import { expandAccount } from './helpers.js';
|
|
5
|
+
export const accountsCache = createCache({
|
|
6
|
+
ttl: 60 * 60 * 1000,
|
|
7
|
+
refreshThreshold: 60 * 1000,
|
|
8
|
+
});
|
|
9
|
+
export const getAccount = async (id, ignoreSoftDelete = false) => accountsCache.wrap(id, () => allpeepDb()
|
|
10
|
+
.then(({ db }) => ignoreSoftDelete
|
|
11
|
+
? accountsMapping.ignoreSoftDelete().find(db, id)
|
|
12
|
+
: accountsMapping.find(db, id))
|
|
13
|
+
.then(expandAccount));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Profile } from '@openpeepshq/common/types';
|
|
2
|
+
export declare const findAccount: (id: string) => Promise<import("@openpeepshq/common").AccountWithMeta | undefined>;
|
|
3
|
+
export declare const findAccountByEmail: (email: string) => Promise<import("@openpeepshq/common").AccountWithMeta | undefined>;
|
|
4
|
+
export declare const existsAccountByEmail: (email: string) => Promise<boolean>;
|
|
5
|
+
export declare const findByProfile: (profile: Profile) => Promise<import("@openpeepshq/common").AccountWithMeta[]>;
|
|
6
|
+
export declare const listAccounts: () => Promise<Promise<import("@openpeepshq/common").AccountWithMeta | undefined>[]>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { allpeepDb } from '../db/index.js';
|
|
2
|
+
import { accountsMapping } from './mapping.js';
|
|
3
|
+
import { profilesMapping } from '../profiles/mapping.js';
|
|
4
|
+
import { profileAccountRelation } from '../profiles/mapping.js';
|
|
5
|
+
import { getAccount } from './cache.js';
|
|
6
|
+
import { expandAccount } from './helpers.js';
|
|
7
|
+
export const findAccount = (id) => getAccount(id);
|
|
8
|
+
export const findAccountByEmail = (email) => allpeepDb()
|
|
9
|
+
.then(({ db }) => accountsMapping.findOneBy(db, { matches: { email } }))
|
|
10
|
+
.then(expandAccount);
|
|
11
|
+
export const existsAccountByEmail = (email) => allpeepDb()
|
|
12
|
+
.then(({ db }) => accountsMapping.ignoreSoftDelete().findOneBy(db, { matches: { email } }))
|
|
13
|
+
.then(Boolean);
|
|
14
|
+
export const findByProfile = (profile) => allpeepDb().then(({ db }) => profilesMapping.relationsFrom(profile, profileAccountRelation).all(db));
|
|
15
|
+
export const listAccounts = () => allpeepDb()
|
|
16
|
+
.then(({ db }) => accountsMapping.all(db))
|
|
17
|
+
.then((accounts) => accounts.map(expandAccount));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AccountWithMeta } from '@openpeepshq/common/types';
|
|
2
|
+
export declare const log: import("@openpeepshq/common").Logger;
|
|
3
|
+
export declare const normalizeEmailAddress: (email?: string) => string | undefined;
|
|
4
|
+
export declare const createEmailValidationToken: (account: AccountWithMeta) => Promise<string>;
|
|
5
|
+
export declare const sendWelcomeEmail: (account: AccountWithMeta) => Promise<void>;
|
|
6
|
+
export declare const sendEmailValidationMail: (account: AccountWithMeta) => Promise<void>;
|
|
7
|
+
export declare const expandAccount: (account?: AccountWithMeta) => Promise<AccountWithMeta | undefined>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jwtUtil } from '../jwt/index.js';
|
|
2
|
+
import { emailService } from '../email/index.js';
|
|
3
|
+
import { serverRootUrl } from '../server/index.js';
|
|
4
|
+
import { logger } from '../log/index.js';
|
|
5
|
+
import { getProfiles } from '../profiles/cache.js';
|
|
6
|
+
import { uuidv7 } from 'uuidv7';
|
|
7
|
+
export const log = logger('core:accounts');
|
|
8
|
+
export const normalizeEmailAddress = (email) => email === null || email === void 0 ? void 0 : email.toLowerCase();
|
|
9
|
+
export const createEmailValidationToken = async (account) => {
|
|
10
|
+
return jwtUtil().then((jwt) => jwt.sign({
|
|
11
|
+
payload: { email: account.email },
|
|
12
|
+
expirationTime: '2d',
|
|
13
|
+
id: uuidv7(),
|
|
14
|
+
}));
|
|
15
|
+
};
|
|
16
|
+
export const sendWelcomeEmail = async (account) => {
|
|
17
|
+
const email = await emailService();
|
|
18
|
+
await email.send({
|
|
19
|
+
template: 'welcome',
|
|
20
|
+
to: account.email,
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
export const sendEmailValidationMail = async (account) => {
|
|
24
|
+
const emailValidationToken = await createEmailValidationToken(account);
|
|
25
|
+
const email = await emailService();
|
|
26
|
+
const emailValidationLink = `${await serverRootUrl()}/auth/validate-email?token=${emailValidationToken}`;
|
|
27
|
+
await email.send({
|
|
28
|
+
template: 'validateEmail',
|
|
29
|
+
locals: {
|
|
30
|
+
emailValidationLink,
|
|
31
|
+
},
|
|
32
|
+
to: account.email,
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export const expandAccount = async (account) => account
|
|
36
|
+
? Object.assign(Object.assign({}, account), { profiles: await getProfiles(account.profiles.map((p) => p.id)) }) : undefined;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Account } from '@openpeepshq/common/types';
|
|
2
|
+
export { accountsMapping } from './mapping';
|
|
3
|
+
export { sendEmailValidationMail } from './helpers';
|
|
4
|
+
export * from './mutations';
|
|
5
|
+
export * from './finders';
|
|
6
|
+
export declare const checkPassword: (account: Account, password: string) => Promise<boolean>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { compare } from 'bcrypt';
|
|
2
|
+
export { accountsMapping } from './mapping.js';
|
|
3
|
+
export { sendEmailValidationMail } from './helpers.js';
|
|
4
|
+
export * from './mutations.js';
|
|
5
|
+
export * from './finders.js';
|
|
6
|
+
export const checkPassword = async (account, password) => compare(password, account.passwordHash);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RelationWithMapping } from '../db/pg/map';
|
|
2
|
+
import { AccountWithMeta, ProfileWithMeta, PushSubscription } from '@openpeepshq/common/types';
|
|
3
|
+
export declare const profileAccountRelation: RelationWithMapping<ProfileWithMeta>;
|
|
4
|
+
export declare const pushSubscriptionsRelation: RelationWithMapping<PushSubscription>;
|
|
5
|
+
export declare const accountsMapping: import("../db/pg/map").Mapping<{
|
|
6
|
+
email: string;
|
|
7
|
+
passwordHash: string;
|
|
8
|
+
emailValidated?: boolean | undefined;
|
|
9
|
+
guest?: boolean | undefined;
|
|
10
|
+
}, AccountWithMeta, AccountWithMeta>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { map } from '../db/pg/map/index.js';
|
|
2
|
+
import { pushSubscriptionsMapping } from '../pushSubscriptions/mapping.js';
|
|
3
|
+
export const profileAccountRelation = {
|
|
4
|
+
alias: 'profiles',
|
|
5
|
+
edgeCollection: 'controls',
|
|
6
|
+
direction: 'OUTBOUND',
|
|
7
|
+
skipEdge: true,
|
|
8
|
+
mapping: {
|
|
9
|
+
collection: 'profiles',
|
|
10
|
+
softDelete: true,
|
|
11
|
+
},
|
|
12
|
+
cardinality: 'many',
|
|
13
|
+
};
|
|
14
|
+
export const pushSubscriptionsRelation = {
|
|
15
|
+
alias: 'pushSubscriptions',
|
|
16
|
+
edgeCollection: 'accountToPushSubscription',
|
|
17
|
+
direction: 'OUTBOUND',
|
|
18
|
+
skipEdge: true,
|
|
19
|
+
mapping: pushSubscriptionsMapping
|
|
20
|
+
.removeRelation((r) => r.edgeCollection === 'accountToPushSubscription')
|
|
21
|
+
.data(),
|
|
22
|
+
cardinality: 'many',
|
|
23
|
+
};
|
|
24
|
+
export const accountsMapping = map({
|
|
25
|
+
collection: 'accounts',
|
|
26
|
+
postFilterRelations: [profileAccountRelation, pushSubscriptionsRelation],
|
|
27
|
+
softDelete: false,
|
|
28
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Account, AccountCreationData, AccountUpdateData, AccountWithMeta, ProfileWithMeta } from '@openpeepshq/common/types';
|
|
2
|
+
export declare const createAccount: (accountCreationData: AccountCreationData) => Promise<{
|
|
3
|
+
account: AccountWithMeta;
|
|
4
|
+
profile: ProfileWithMeta | undefined;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const updateAccount: (accountData: AccountUpdateData) => Promise<{
|
|
7
|
+
account: AccountWithMeta;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const deleteAccount: (account: Account) => Promise<void>;
|
|
10
|
+
export declare const sendResetPasswordEmail: (account: AccountWithMeta) => Promise<void>;
|
|
11
|
+
export declare const validateEmail: (token: string) => Promise<boolean | undefined>;
|
|
12
|
+
export declare const giveControl: (db: import("../db").PgDb, from: {
|
|
13
|
+
id: string;
|
|
14
|
+
}, to: {
|
|
15
|
+
id: string;
|
|
16
|
+
}, data?: {
|
|
17
|
+
id?: string;
|
|
18
|
+
}) => Promise<import("../db/pg/map").WithId<{
|
|
19
|
+
_from: string;
|
|
20
|
+
_to: string;
|
|
21
|
+
}>>;
|