@openpeepshq/core 0.1.33 → 0.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accessTokens/finders.js +5 -6
- package/dist/accessTokens/mutations.js +1 -1
- package/dist/accessTokens/tokens.js +8 -11
- package/dist/accounts/helpers.js +6 -2
- package/dist/accounts/mutations.js +36 -33
- package/dist/analytics/cache.js +3 -3
- package/dist/analytics/clicks.js +14 -22
- package/dist/analytics/compile.js +17 -12
- package/dist/analytics/dateRange.js +3 -5
- package/dist/analytics/jobs.js +3 -4
- package/dist/analytics/pdfReport.js +45 -61
- package/dist/analytics/privacy.js +1 -1
- package/dist/analytics/read.js +164 -140
- package/dist/analytics/report.d.ts +22 -1
- package/dist/analytics/report.js +2 -3
- package/dist/analytics/settings.js +3 -4
- package/dist/backups/index.js +82 -25
- package/dist/backups/metadata.d.ts +2 -3
- package/dist/backups/metadata.js +6 -2
- package/dist/config/db.js +2 -4
- package/dist/config/defaults/capabilities.js +13 -2
- package/dist/config/defaults/community.js +8 -3
- package/dist/config/defaults/core.d.ts +1 -1
- package/dist/config/defaults/core.js +16 -8
- package/dist/config/index.d.ts +22 -0
- package/dist/config/index.js +15 -11
- package/dist/db/explorer/query.js +9 -8
- package/dist/db/explorer/sql.js +8 -8
- package/dist/db/helpers.d.ts +1 -0
- package/dist/db/helpers.js +25 -7
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +1 -0
- package/dist/db/init.js +2 -3
- package/dist/db/migration/importCollections.d.ts +14 -9
- package/dist/db/migration/importCollections.js +121 -174
- package/dist/db/migration/shared.d.ts +2 -33
- package/dist/db/migration/shared.js +17 -87
- package/dist/db/pg/client.js +4 -7
- package/dist/db/pg/collections.d.ts +2 -2
- package/dist/db/pg/collections.js +2 -2
- package/dist/db/pg/filters/index.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +12 -0
- package/dist/db/pg/filters/posts.js +30 -4
- package/dist/db/pg/filters/profiles.d.ts +1 -0
- package/dist/db/pg/filters/profiles.js +2 -1
- package/dist/db/pg/helpers.js +2 -14
- package/dist/db/pg/map/filters.js +40 -10
- package/dist/db/pg/map/helpers.js +5 -1
- package/dist/db/pg/map/index.js +46 -51
- package/dist/db/pg/map/mutations.js +65 -25
- package/dist/db/pg/map/registry.d.ts +5 -0
- package/dist/db/pg/map/registry.js +133 -56
- package/dist/db/pg/map/relations.js +76 -68
- package/dist/db/pg/map/search.js +15 -37
- package/dist/db/pg/mappers.js +13 -7
- package/dist/db/pg/migrate.d.ts +1 -2
- package/dist/db/pg/migrate.js +8 -9
- package/dist/db/pg/queries/activity.js +5 -5
- package/dist/db/pg/queries/derived.js +8 -12
- package/dist/db/pg/queries/sorts.d.ts +1 -0
- package/dist/db/pg/queries/sorts.js +4 -0
- package/dist/db/pg/schema/documents.d.ts +279 -41
- package/dist/db/pg/schema/documents.js +136 -22
- package/dist/db/pg/schema/edges.d.ts +116 -7
- package/dist/db/pg/schema/edges.js +9 -2
- package/dist/db/pg/schema/index.d.ts +362 -15
- package/dist/db/pg/schema/index.js +5 -1
- package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
- package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
- package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
- package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
- package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
- package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
- package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
- package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
- package/dist/db/pg/sql/meta/_journal.json +49 -0
- package/dist/db/replaceOrigin.js +1 -1
- package/dist/email/queueStats.js +8 -11
- package/dist/email/render.js +14 -3
- package/dist/email/send.js +19 -17
- package/dist/email/smtpTest.js +10 -6
- package/dist/errors/index.js +1 -1
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.js +1 -0
- package/dist/events/once.js +2 -4
- package/dist/federation/activities.d.ts +17 -0
- package/dist/federation/activities.js +25 -0
- package/dist/federation/identity.d.ts +16 -0
- package/dist/federation/identity.js +52 -0
- package/dist/federation/index.d.ts +4 -0
- package/dist/federation/index.js +3 -0
- package/dist/federation/profiles.d.ts +3 -0
- package/dist/federation/profiles.js +14 -0
- package/dist/groups/finders.d.ts +2 -1
- package/dist/groups/helpers.d.ts +18 -0
- package/dist/groups/helpers.js +1 -2
- package/dist/groups/mapping.d.ts +4 -2
- package/dist/groups/mutations.js +1 -1
- package/dist/hashtags/finders.d.ts +6 -3
- package/dist/hashtags/finders.js +2 -0
- package/dist/hashtags/helpers.d.ts +8 -0
- package/dist/hashtags/helpers.js +4 -0
- package/dist/hashtags/index.d.ts +2 -0
- package/dist/hashtags/index.js +2 -0
- package/dist/hashtags/mutations.d.ts +3 -0
- package/dist/hashtags/mutations.js +13 -1
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +3 -1
- package/dist/i18n/pluginLocales.d.ts +6 -0
- package/dist/i18n/pluginLocales.js +15 -0
- package/dist/inviteLinks/mutations.js +2 -3
- package/dist/jams/export.d.ts +19 -0
- package/dist/jams/export.js +58 -0
- package/dist/jams/finders.js +4 -1
- package/dist/jams/health.d.ts +10 -0
- package/dist/jams/health.js +50 -0
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/helpers.js +6 -2
- package/dist/jams/index.d.ts +2 -0
- package/dist/jams/index.js +25 -18
- package/dist/jams/jobs.js +2 -3
- package/dist/jams/livekit.d.ts +49 -4
- package/dist/jams/livekit.js +62 -45
- package/dist/jams/mapping.d.ts +3 -3
- package/dist/jams/mutations.d.ts +1 -1
- package/dist/jams/recording.d.ts +10 -0
- package/dist/jams/recording.js +33 -1
- package/dist/jams/token.d.ts +13 -1
- package/dist/jams/token.js +25 -18
- package/dist/jams/waitingRoom.js +1 -1
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +9 -3
- package/dist/jobs/jobDetail.js +6 -12
- package/dist/jobs/jobLog.js +2 -3
- package/dist/lib/streams.js +4 -39
- package/dist/lib/zodDeepPartial.d.ts +1 -1
- package/dist/lib/zodDeepPartial.js +1 -1
- package/dist/log/index.js +13 -29
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +73 -12
- package/dist/media/jobs.js +1 -2
- package/dist/media/openpeeps/index.js +11 -46
- package/dist/media/processing.js +25 -11
- package/dist/media/streaming.js +5 -5
- package/dist/media/streamingCleanupJobs.js +1 -2
- package/dist/media/streamingJobs.js +3 -4
- package/dist/media/streamingPrewarm.js +7 -11
- package/dist/mediaAttachments/index.js +6 -2
- package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
- package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
- package/dist/notifications/defaultNotifications/follow/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
- package/dist/notifications/defaultNotifications/index.js +4 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
- package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
- package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
- package/dist/notifications/defaultNotifications/mention/index.js +20 -24
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +11 -6
- package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
- package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.js +17 -0
- package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
- package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
- package/dist/notifications/defaultNotifications/reply/index.js +21 -22
- package/dist/notifications/defaultNotifications/repost/index.js +16 -20
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
- package/dist/notifications/defaultNotifications/rsvp/index.js +31 -18
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +82 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
- package/dist/notifications/fcmCredential.js +1 -1
- package/dist/notifications/finders.js +1 -1
- package/dist/notifications/helpers.js +13 -10
- package/dist/notifications/jobs.js +10 -5
- package/dist/notifications/mutations.js +8 -1
- package/dist/notifications/push.js +11 -16
- package/dist/performance/index.js +3 -3
- package/dist/plugins/helpers.js +3 -6
- package/dist/plugins/index.js +39 -4
- package/dist/plugins/install.d.ts +28 -9
- package/dist/plugins/install.js +302 -56
- package/dist/plugins/pluginAuth.d.ts +1 -1
- package/dist/plugins/pluginAuth.js +13 -10
- package/dist/plugins/state.js +2 -3
- package/dist/posts/activity.d.ts +9 -0
- package/dist/posts/activity.js +34 -0
- package/dist/posts/contextClosure.d.ts +1 -9
- package/dist/posts/contextClosure.js +14 -44
- package/dist/posts/conversationQueries.d.ts +7 -0
- package/dist/posts/conversationQueries.js +76 -4
- package/dist/posts/eventAgenda.d.ts +1 -0
- package/dist/posts/eventAgenda.js +17 -8
- package/dist/posts/eventOccurrenceJobs.js +7 -2
- package/dist/posts/eventOccurrences.d.ts +6 -0
- package/dist/posts/eventOccurrences.js +22 -1
- package/dist/posts/finders.d.ts +56 -9
- package/dist/posts/finders.js +84 -23
- package/dist/posts/helpers/filters.js +13 -9
- package/dist/posts/helpers/index.d.ts +179 -14
- package/dist/posts/helpers/index.js +70 -34
- package/dist/posts/index.d.ts +5 -2
- package/dist/posts/index.js +5 -2
- package/dist/posts/mapping.d.ts +765 -30
- package/dist/posts/mapping.js +74 -31
- package/dist/posts/mutations.d.ts +516 -3
- package/dist/posts/mutations.js +179 -41
- package/dist/posts/pollEnd.d.ts +3 -0
- package/dist/posts/pollEnd.js +4 -0
- package/dist/posts/pollEndJobs.d.ts +8 -0
- package/dist/posts/pollEndJobs.js +49 -0
- package/dist/posts/replyClosure.d.ts +10 -0
- package/dist/posts/replyClosure.js +43 -0
- package/dist/posts/rsvpConfirmationEmail.js +23 -15
- package/dist/posts/threadPreview.d.ts +8 -0
- package/dist/posts/threadPreview.js +44 -0
- package/dist/posts/unseenCounts.js +4 -1
- package/dist/processingStats/queries.js +6 -7
- package/dist/profileSettings/cache.js +21 -5
- package/dist/profileSettings/mapping.d.ts +2 -0
- package/dist/profiles/activityQueries.d.ts +5 -0
- package/dist/profiles/activityQueries.js +85 -0
- package/dist/profiles/activitySummary.d.ts +3 -0
- package/dist/profiles/activitySummary.js +82 -0
- package/dist/profiles/blocks.d.ts +12 -0
- package/dist/profiles/blocks.js +73 -0
- package/dist/profiles/cache.d.ts +1 -0
- package/dist/profiles/cache.js +30 -10
- package/dist/profiles/export.js +30 -39
- package/dist/profiles/finders.d.ts +2 -1
- package/dist/profiles/finders.js +15 -8
- package/dist/profiles/helpers.d.ts +2 -0
- package/dist/profiles/index.d.ts +2 -0
- package/dist/profiles/index.js +2 -0
- package/dist/profiles/mapping.d.ts +10 -5
- package/dist/profiles/mapping.js +13 -1
- package/dist/profiles/mutations.d.ts +8 -4
- package/dist/profiles/mutations.js +31 -4
- package/dist/redis/connection.d.ts +2 -0
- package/dist/redis/connection.js +25 -6
- package/dist/reports/helpers.js +7 -3
- package/dist/roles/index.d.ts +1 -1
- package/dist/roles/index.js +1 -1
- package/dist/roles/mapping.d.ts +1 -0
- package/dist/roles/mutations.js +85 -3
- package/dist/search/finders.js +15 -3
- package/dist/search/helpers.js +1 -1
- package/dist/search/mapping.d.ts +1 -1
- package/dist/search/mapping.js +6 -2
- package/dist/sentry/index.js +9 -11
- package/dist/seo/index.d.ts +50 -0
- package/dist/seo/index.js +145 -0
- package/dist/seo/route.d.ts +18 -0
- package/dist/seo/route.js +19 -0
- package/dist/server/index.d.ts +19 -0
- package/dist/server/index.js +31 -14
- package/dist/server/stablePublicServerInfo.d.ts +17 -0
- package/dist/server/stablePublicServerInfo.js +37 -0
- package/dist/server/status.d.ts +25 -0
- package/dist/server/status.js +97 -0
- package/dist/session/index.js +2 -2
- package/dist/stats/finders.d.ts +1 -17681
- package/dist/stats/finders.js +22 -9
- package/dist/stats/helpers.js +4 -1
- package/dist/stats/mapping.d.ts +39 -2
- package/dist/stats/mapping.js +8 -4
- package/dist/stripe/cache.js +5 -6
- package/dist/stripe/connection.js +3 -4
- package/dist/stripe/helpers.js +15 -20
- package/package.json +5 -7
- package/dist/db/migration/detect.d.ts +0 -3
- package/dist/db/migration/detect.js +0 -33
- package/dist/db/migration/importPostgres.d.ts +0 -3
- package/dist/db/migration/importPostgres.js +0 -18
- package/dist/db/migration/transform.d.ts +0 -20
- package/dist/db/migration/transform.js +0 -232
- package/dist/db/migration/validate.d.ts +0 -18
- package/dist/db/migration/validate.js +0 -69
- package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
- package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
- package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
- package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
- package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
- package/dist/mastodon/index.d.ts +0 -4
- package/dist/mastodon/index.js +0 -51
- package/dist/mastodon/types.d.ts +0 -7579
- package/dist/mastodon/types.js +0 -523
- package/dist/mastodon/typescript.d.ts +0 -1578
- package/dist/mastodon/typescript.js +0 -1
- package/dist/migration/index.d.ts +0 -4
- package/dist/migration/index.js +0 -4
- package/dist/roles/defaults.d.ts +0 -2
- package/dist/roles/defaults.js +0 -95
package/dist/stats/finders.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { publicProfileWithActivityScoreSchema, publicPostWithActivityScoreSchema, } from '@openpeepshq/common/types';
|
|
2
2
|
import { sub } from 'date-fns';
|
|
3
|
+
import { hostResources } from '../server/status.js';
|
|
3
4
|
import { baseProfilesMapping } from '../profiles/index.js';
|
|
4
5
|
import { allpeepDb } from '../db/index.js';
|
|
5
6
|
import { postsMapping, postsWithReplyCountMapping, postsWithReplyToCountMapping, transformPost, } from '../posts/index.js';
|
|
6
|
-
import { entriesMapping, followsMapping, postsWithActivityScoreMapping, profileWithActivityScoreMapping,
|
|
7
|
+
import { entriesMapping, followsMapping, postsWithActivityScoreMapping, profileWithActivityScoreMapping, repostsMapping, } from './mapping.js';
|
|
7
8
|
import { compileStatsWithAll, createdAtFilter } from './helpers.js';
|
|
8
9
|
import { jamParticipantsMapping, jamSessionStartsMapping, } from '../jams/mapping.js';
|
|
9
10
|
import { edgeFilters, postFilters, profileFilters } from '../db/pg/filters/index.js';
|
|
10
11
|
import { sorts } from '../db/pg/queries/index.js';
|
|
11
|
-
import { entries, follows,
|
|
12
|
+
import { entries, follows, repost } from '../db/pg/schema/edges.js';
|
|
12
13
|
import { jamEvents, posts, profiles } from '../db/pg/schema/documents.js';
|
|
13
14
|
export const activeProfilesCount = (db, start, end) => profileWithActivityScoreMapping(start, end)
|
|
14
15
|
.filter(profileFilters.activityScorePositive(start, end))
|
|
@@ -37,7 +38,10 @@ export const postsRepliesCount = (db, start, end) => postsWithReplyToCountMappin
|
|
|
37
38
|
.filter({ matches: { replyToCount: 1 } })
|
|
38
39
|
.count(db);
|
|
39
40
|
export const postsRepliesStats = () => compileStatsWithAll(postsRepliesCount);
|
|
40
|
-
const reactionCount = (db, start, end) =>
|
|
41
|
+
const reactionCount = (db, start, end) => entriesMapping
|
|
42
|
+
.filter(createdAtFilter(entries, start, end))
|
|
43
|
+
.filter(edgeFilters.entryType('reaction'))
|
|
44
|
+
.count(db);
|
|
41
45
|
const rsvpCount = (db, start, end) => entriesMapping
|
|
42
46
|
.filter(createdAtFilter(entries, start, end))
|
|
43
47
|
.filter(edgeFilters.entryType('rsvp'))
|
|
@@ -45,8 +49,7 @@ const rsvpCount = (db, start, end) => entriesMapping
|
|
|
45
49
|
const followCount = (db, start, end) => followsMapping.filter(createdAtFilter(follows, start, end)).count(db);
|
|
46
50
|
const entryCount = (db, start, end) => entriesMapping.filter(createdAtFilter(entries, start, end)).count(db);
|
|
47
51
|
const repostCount = (db, start, end) => repostsMapping.filter(createdAtFilter(repost, start, end)).count(db);
|
|
48
|
-
const interactionsCount = async (db, start, end) => (await
|
|
49
|
-
(await followCount(db, start, end)) +
|
|
52
|
+
const interactionsCount = async (db, start, end) => (await followCount(db, start, end)) +
|
|
50
53
|
(await entryCount(db, start, end)) +
|
|
51
54
|
(await repostCount(db, start, end));
|
|
52
55
|
export const interactionsStats = () => compileStatsWithAll(interactionsCount);
|
|
@@ -117,25 +120,34 @@ const createIntervals = (duration) => {
|
|
|
117
120
|
start: sub(new Date(), { days: i + 1 }),
|
|
118
121
|
end: sub(new Date(), { days: i }),
|
|
119
122
|
}))
|
|
120
|
-
.map((interval) => (
|
|
123
|
+
.map((interval) => ({
|
|
124
|
+
name: interval.start.toISOString().split('T')[0],
|
|
125
|
+
...interval,
|
|
126
|
+
}));
|
|
121
127
|
case 'P4W':
|
|
122
128
|
return [0, 1, 2, 3]
|
|
123
129
|
.map((i) => ({
|
|
124
130
|
start: sub(new Date(), { days: (i + 1) * 7 }),
|
|
125
131
|
end: sub(new Date(), { days: i * 7 }),
|
|
126
132
|
}))
|
|
127
|
-
.map((interval) => (
|
|
133
|
+
.map((interval) => ({
|
|
134
|
+
name: `${interval.start.toISOString().split('T')[0]} - ${interval.end.toISOString().split('T')[0]}`,
|
|
135
|
+
...interval,
|
|
136
|
+
}));
|
|
128
137
|
case 'P120D':
|
|
129
138
|
return [0, 1, 2, 3]
|
|
130
139
|
.map((i) => ({
|
|
131
140
|
start: sub(new Date(), { days: (i + 1) * 30 }),
|
|
132
141
|
end: sub(new Date(), { days: i * 30 }),
|
|
133
142
|
}))
|
|
134
|
-
.map((interval) => (
|
|
143
|
+
.map((interval) => ({
|
|
144
|
+
name: `${interval.start.toISOString().split('T')[0]} - ${interval.end.toISOString().split('T')[0]}`,
|
|
145
|
+
...interval,
|
|
146
|
+
}));
|
|
135
147
|
}
|
|
136
148
|
};
|
|
137
149
|
export const signupsTimeline = (duration) => Promise.all(createIntervals(duration).map((interval) => newProfilesForInterval(interval.start, interval.end).then((count) => ({
|
|
138
|
-
name: interval
|
|
150
|
+
name: interval?.name,
|
|
139
151
|
count,
|
|
140
152
|
}))));
|
|
141
153
|
export const serverStats = async () => ({
|
|
@@ -164,4 +176,5 @@ export const serverStats = async () => ({
|
|
|
164
176
|
fourMonths: await signupsTimeline('P120D'),
|
|
165
177
|
},
|
|
166
178
|
},
|
|
179
|
+
host: await hostResources(),
|
|
167
180
|
});
|
package/dist/stats/helpers.js
CHANGED
|
@@ -31,4 +31,7 @@ export const compileStats = async (fn) => allpeepDb().then(async ({ db }) => ({
|
|
|
31
31
|
lastPeriod: await fn(db, sub(new Date(), { years: 2 }), sub(new Date(), { years: 1 })),
|
|
32
32
|
},
|
|
33
33
|
}));
|
|
34
|
-
export const compileStatsWithAll = async (fn) => allpeepDb().then(async ({ db }) => (
|
|
34
|
+
export const compileStatsWithAll = async (fn) => allpeepDb().then(async ({ db }) => ({
|
|
35
|
+
...(await compileStats(fn)),
|
|
36
|
+
all: await fn(db),
|
|
37
|
+
}));
|
package/dist/stats/mapping.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DbPost } from '@openpeepshq/common/types';
|
|
2
2
|
export declare const profileWithActivityScoreMapping: (start?: Date, end?: Date) => import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("@openpeepshq/common").Profile>;
|
|
3
3
|
export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mapping<{
|
|
4
|
-
type: "note" | "question" | "event" | "article";
|
|
4
|
+
type: "resource" | "note" | "question" | "event" | "article";
|
|
5
5
|
visibility: "local" | "group" | "report" | "public" | "unlisted" | "private" | "direct";
|
|
6
6
|
creatorId: string;
|
|
7
7
|
capabilitiesNeeded?: string[] | undefined;
|
|
@@ -197,13 +197,50 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
|
|
|
197
197
|
language?: string | undefined;
|
|
198
198
|
image?: string | undefined;
|
|
199
199
|
title?: string | undefined;
|
|
200
|
+
} | {
|
|
201
|
+
type: "resource";
|
|
202
|
+
title: string;
|
|
203
|
+
resourceKind: "link" | "file" | "video" | "gallery" | "audio";
|
|
204
|
+
content?: string | undefined;
|
|
205
|
+
sensitive?: boolean | undefined;
|
|
206
|
+
spoilerText?: string | undefined;
|
|
207
|
+
attachments?: {
|
|
208
|
+
type: string;
|
|
209
|
+
url: string;
|
|
210
|
+
previewUrl: string | null;
|
|
211
|
+
textUrl: null;
|
|
212
|
+
filename: string;
|
|
213
|
+
meta: {
|
|
214
|
+
usage?: string | undefined;
|
|
215
|
+
focus?: {
|
|
216
|
+
x: number;
|
|
217
|
+
y: number;
|
|
218
|
+
} | undefined;
|
|
219
|
+
mimetype?: string | undefined;
|
|
220
|
+
size?: number | undefined;
|
|
221
|
+
};
|
|
222
|
+
description?: string | undefined;
|
|
223
|
+
blurhash?: string | undefined;
|
|
224
|
+
status?: "failed" | "processing" | "ready" | undefined;
|
|
225
|
+
error?: string | undefined;
|
|
226
|
+
}[] | undefined;
|
|
227
|
+
customEmojis?: {
|
|
228
|
+
shortcode: string;
|
|
229
|
+
url: string;
|
|
230
|
+
staticUrl: string;
|
|
231
|
+
visibleInPicker: boolean;
|
|
232
|
+
category: string;
|
|
233
|
+
}[] | undefined;
|
|
234
|
+
language?: string | undefined;
|
|
235
|
+
tags?: string[] | undefined;
|
|
236
|
+
categoryPath?: string[] | undefined;
|
|
237
|
+
url?: string | undefined;
|
|
200
238
|
} | undefined;
|
|
201
239
|
}, DbPost & {
|
|
202
240
|
activityScore: number;
|
|
203
241
|
}, DbPost & {
|
|
204
242
|
activityScore: number;
|
|
205
243
|
}>;
|
|
206
|
-
export declare const reactionsMapping: import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("../db/pg/map").WithId<object>>;
|
|
207
244
|
export declare const followsMapping: import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("../db/pg/map").WithId<object>>;
|
|
208
245
|
export declare const entriesMapping: import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("../db/pg/map").WithId<object>>;
|
|
209
246
|
export declare const repostsMapping: import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("../db/pg/map").WithId<object>>;
|
package/dist/stats/mapping.js
CHANGED
|
@@ -3,10 +3,14 @@ import { baseProfilesMapping } from '../profiles/index.js';
|
|
|
3
3
|
import { postsMapping } from '../posts/index.js';
|
|
4
4
|
import { map } from '../db/pg/map/index.js';
|
|
5
5
|
import { computedFields } from '../db/pg/queries/index.js';
|
|
6
|
-
export const profileWithActivityScoreMapping = (start, end) => map(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export const profileWithActivityScoreMapping = (start, end) => map({
|
|
7
|
+
...baseProfilesMapping.data(),
|
|
8
|
+
activityWindow: { start, end },
|
|
9
|
+
computedFields: [computedFields.profileActivityScore({ start, end })],
|
|
10
|
+
});
|
|
11
|
+
export const postsWithActivityScoreMapping = map({
|
|
12
|
+
...postsMapping.data(),
|
|
13
|
+
computedFields: [computedFields.postActivityScore()],
|
|
10
14
|
});
|
|
11
15
|
export const followsMapping = map({
|
|
12
16
|
collection: collectionInfos.followsCollection.name,
|
package/dist/stripe/cache.js
CHANGED
|
@@ -6,14 +6,13 @@ export const stripeCache = createCache({
|
|
|
6
6
|
refreshThreshold: 60 * 60 * 1000,
|
|
7
7
|
});
|
|
8
8
|
const loadStripeSubscription = async (customerId) => {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f;
|
|
10
9
|
const subscriptions = await getStripe().then((stripe) => stripe.subscriptions.list({
|
|
11
10
|
customer: customerId,
|
|
12
11
|
limit: 1,
|
|
13
12
|
status: 'all',
|
|
14
13
|
expand: ['data.default_payment_method'],
|
|
15
14
|
}));
|
|
16
|
-
if (!
|
|
15
|
+
if (!subscriptions?.data || subscriptions?.data.length === 0) {
|
|
17
16
|
return { status: 'none' };
|
|
18
17
|
}
|
|
19
18
|
const subscription = subscriptions.data[0];
|
|
@@ -21,14 +20,14 @@ const loadStripeSubscription = async (customerId) => {
|
|
|
21
20
|
subscriptionId: subscription.id,
|
|
22
21
|
status: subscription.status,
|
|
23
22
|
priceId: subscription.items.data[0].price.id,
|
|
24
|
-
currentPeriodEnd:
|
|
25
|
-
currentPeriodStart:
|
|
23
|
+
currentPeriodEnd: subscription.ended_at ?? null,
|
|
24
|
+
currentPeriodStart: subscription.start_date ?? null,
|
|
26
25
|
cancelAtPeriodEnd: subscription.cancel_at_period_end,
|
|
27
26
|
paymentMethod: subscription.default_payment_method &&
|
|
28
27
|
typeof subscription.default_payment_method !== 'string'
|
|
29
28
|
? {
|
|
30
|
-
brand:
|
|
31
|
-
last4:
|
|
29
|
+
brand: subscription.default_payment_method.card?.brand ?? null,
|
|
30
|
+
last4: subscription.default_payment_method.card?.last4 ?? null,
|
|
32
31
|
}
|
|
33
32
|
: null,
|
|
34
33
|
};
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import Stripe from 'stripe';
|
|
2
2
|
import { config } from '../config/index.js';
|
|
3
3
|
import { hub } from '../events/index.js';
|
|
4
|
-
export const initStripeWithCredentials = (data) =>
|
|
5
|
-
? new Stripe(data
|
|
4
|
+
export const initStripeWithCredentials = (data) => data?.publishableKey || data?.secretKey || data?.webhookSecret
|
|
5
|
+
? new Stripe(data?.secretKey, { apiVersion: '2025-07-30.basil' })
|
|
6
6
|
: undefined;
|
|
7
7
|
export const initStripe = async () => {
|
|
8
|
-
var _a;
|
|
9
8
|
hub.on('configUpdated', (namespace, name) => {
|
|
10
9
|
if (namespace === 'openpeeps' && name === 'core') {
|
|
11
10
|
_stripe = null;
|
|
12
11
|
}
|
|
13
12
|
});
|
|
14
13
|
const cfg = await config();
|
|
15
|
-
return initStripeWithCredentials(
|
|
14
|
+
return initStripeWithCredentials(cfg.payments?.stripe);
|
|
16
15
|
};
|
|
17
16
|
let _stripe = null;
|
|
18
17
|
export const getStripe = async () => {
|
package/dist/stripe/helpers.js
CHANGED
|
@@ -4,22 +4,19 @@ import { getUserStripeSubscription, refreshStripeSubscription, stripeCache, } fr
|
|
|
4
4
|
import { findProfileSettings, updateProfileSettings } from '../profileSettings/index.js';
|
|
5
5
|
import { getStripe, initStripeWithCredentials } from './connection.js';
|
|
6
6
|
export const getStripeDetails = async () => {
|
|
7
|
-
var _a;
|
|
8
7
|
const cfg = await config();
|
|
9
|
-
const data =
|
|
8
|
+
const data = cfg.payments?.stripe;
|
|
10
9
|
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
|
|
11
10
|
const success_url = `${protocol}://${cfg.server.host}/payment/success`;
|
|
12
11
|
const cancel_url = `${protocol}://${cfg.server.host}/auth/login`;
|
|
13
12
|
const portal_return_url = `${protocol}://${cfg.server.host}/settings/billing`;
|
|
14
|
-
return
|
|
13
|
+
return { ...data, success_url, cancel_url, portal_return_url };
|
|
15
14
|
};
|
|
16
15
|
export const stripeMembershipActive = async () => {
|
|
17
|
-
var _a;
|
|
18
16
|
const data = await getStripeDetails();
|
|
19
|
-
return !!
|
|
17
|
+
return !!data?.paidMembership?.enabled;
|
|
20
18
|
};
|
|
21
19
|
const getPrices = async (stripeInstance, productId = '', limit = 1) => {
|
|
22
|
-
var _a, _b;
|
|
23
20
|
if (!productId) {
|
|
24
21
|
throw new Error('[STRIPE_PRICE][ERROR] No productId found');
|
|
25
22
|
}
|
|
@@ -31,13 +28,13 @@ const getPrices = async (stripeInstance, productId = '', limit = 1) => {
|
|
|
31
28
|
}
|
|
32
29
|
const defaultPriceId = typeof product.default_price === 'string'
|
|
33
30
|
? product.default_price
|
|
34
|
-
: (
|
|
31
|
+
: (product.default_price?.id ?? null);
|
|
35
32
|
if (defaultPriceId && limit === 1) {
|
|
36
33
|
try {
|
|
37
34
|
const price = await stripeInstance.prices.retrieve(defaultPriceId);
|
|
38
35
|
return { data: [price] };
|
|
39
36
|
}
|
|
40
|
-
catch
|
|
37
|
+
catch {
|
|
41
38
|
return { data: [] };
|
|
42
39
|
}
|
|
43
40
|
}
|
|
@@ -51,7 +48,7 @@ const getPrices = async (stripeInstance, productId = '', limit = 1) => {
|
|
|
51
48
|
};
|
|
52
49
|
export const testStripeCredentials = async (data) => {
|
|
53
50
|
try {
|
|
54
|
-
const credentials =
|
|
51
|
+
const credentials = { ...(await getStripeDetails()), ...data };
|
|
55
52
|
const stripe = initStripeWithCredentials(credentials);
|
|
56
53
|
if (!stripe) {
|
|
57
54
|
return {
|
|
@@ -60,14 +57,14 @@ export const testStripeCredentials = async (data) => {
|
|
|
60
57
|
};
|
|
61
58
|
}
|
|
62
59
|
const { paidMembership } = credentials;
|
|
63
|
-
const productId = paidMembership
|
|
60
|
+
const productId = paidMembership?.productId;
|
|
64
61
|
if (!productId) {
|
|
65
62
|
return {
|
|
66
63
|
success: false,
|
|
67
64
|
key: 'configuration.server.stripe.errors.noProductId',
|
|
68
65
|
};
|
|
69
66
|
}
|
|
70
|
-
const prices = await getPrices(stripe, paidMembership
|
|
67
|
+
const prices = await getPrices(stripe, paidMembership?.productId, 1);
|
|
71
68
|
if (prices.data.length === 0) {
|
|
72
69
|
return {
|
|
73
70
|
success: false,
|
|
@@ -92,7 +89,7 @@ export const createStripeCustomerPortal = async (stripeId) => {
|
|
|
92
89
|
}));
|
|
93
90
|
return session.url;
|
|
94
91
|
}
|
|
95
|
-
catch
|
|
92
|
+
catch { }
|
|
96
93
|
};
|
|
97
94
|
export const createStripeCustomer = async (profile, account) => {
|
|
98
95
|
const profileSettings = await findProfileSettings(profile.id);
|
|
@@ -134,10 +131,9 @@ const allowedEvents = [
|
|
|
134
131
|
'payment_intent.canceled',
|
|
135
132
|
];
|
|
136
133
|
export const processEvent = async (event) => {
|
|
137
|
-
var _a;
|
|
138
134
|
if (!allowedEvents.includes(event.type))
|
|
139
135
|
return;
|
|
140
|
-
const { customer: customerId } =
|
|
136
|
+
const { customer: customerId } = event?.data?.object;
|
|
141
137
|
if (typeof customerId !== 'string') {
|
|
142
138
|
throw new Error(`[STRIPE HOOK][CANCER] ID isn't string.\nEvent type: ${event.type}`);
|
|
143
139
|
}
|
|
@@ -167,14 +163,13 @@ export const checkSubscription = async (profile, account, refresh = false) => {
|
|
|
167
163
|
return true;
|
|
168
164
|
};
|
|
169
165
|
export const createStripeCheckoutUrl = async (profile, account) => {
|
|
170
|
-
var _a;
|
|
171
166
|
const stripeCustomerId = await getOrCreateStripeCustomerId(profile, account);
|
|
172
167
|
if (!stripeCustomerId) {
|
|
173
168
|
throw new Error('[STRIPE_CHECKOUT][ERROR] No stripe customer id found');
|
|
174
169
|
}
|
|
175
170
|
const { paidMembership, success_url, cancel_url } = (await getStripeDetails());
|
|
176
|
-
const productId = paidMembership
|
|
177
|
-
const trialPeriodDays =
|
|
171
|
+
const productId = paidMembership?.productId;
|
|
172
|
+
const trialPeriodDays = paidMembership?.trialPeriodDays ?? 0;
|
|
178
173
|
const prices = await getPrices(await getStripe(), productId, 1);
|
|
179
174
|
const line_items = prices.data.map((price) => ({
|
|
180
175
|
price: price.id,
|
|
@@ -186,7 +181,7 @@ export const createStripeCheckoutUrl = async (profile, account) => {
|
|
|
186
181
|
try {
|
|
187
182
|
const res = await getUserStripeSubscription(stripeCustomerId);
|
|
188
183
|
let successUrl = success_url;
|
|
189
|
-
if (res !== null &&
|
|
184
|
+
if (res !== null && res?.status !== 'none') {
|
|
190
185
|
successUrl = `${success_url}?user=true`;
|
|
191
186
|
}
|
|
192
187
|
const subscription_data = trialPeriodDays > 0
|
|
@@ -205,7 +200,7 @@ export const createStripeCheckoutUrl = async (profile, account) => {
|
|
|
205
200
|
subscription_data,
|
|
206
201
|
allow_promotion_codes: true,
|
|
207
202
|
}))
|
|
208
|
-
.then((session) =>
|
|
203
|
+
.then((session) => session.url ?? undefined);
|
|
209
204
|
}
|
|
210
|
-
catch
|
|
205
|
+
catch { }
|
|
211
206
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"dependencies": {
|
|
@@ -37,11 +37,10 @@
|
|
|
37
37
|
"type-fest": "^4.31.0",
|
|
38
38
|
"uuidv7": "^1.0.2",
|
|
39
39
|
"web-push": "^3.6.7",
|
|
40
|
-
"
|
|
41
|
-
"@openpeepshq/
|
|
42
|
-
"@openpeepshq/
|
|
43
|
-
"@openpeepshq/
|
|
44
|
-
"@openpeepshq/i18n": "^0.1.9"
|
|
40
|
+
"@openpeepshq/common": "0.3.1",
|
|
41
|
+
"@openpeepshq/fetch-client": "^0.2.1",
|
|
42
|
+
"@openpeepshq/i18n": "^0.1.12",
|
|
43
|
+
"@openpeepshq/geocoder": "^0.1.2"
|
|
45
44
|
},
|
|
46
45
|
"main": "dist/index.js",
|
|
47
46
|
"types": "dist/index.d.ts",
|
|
@@ -86,7 +85,6 @@
|
|
|
86
85
|
"build": "tsc && tsc-alias && rm -rf dist/db/pg/sql && cp -r src/db/pg/sql dist/db/pg/sql",
|
|
87
86
|
"build:watch": "tsc && tsc-alias && (concurrently \"tsc -w\" \"tsc-alias -w\")",
|
|
88
87
|
"uuidv7": "node -e 'import(\"uuidv7\").then(u => console.log(u.uuidv7()))'",
|
|
89
|
-
"create-migration": "node create-migration.js",
|
|
90
88
|
"db:generate": "drizzle-kit generate",
|
|
91
89
|
"db:migrate": "drizzle-kit migrate",
|
|
92
90
|
"db:studio": "drizzle-kit studio"
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { getTableName, sql } from 'drizzle-orm';
|
|
2
|
-
import { pgDb } from '../pg/client.js';
|
|
3
|
-
import { getTableForCollection } from '../pg/map/registry.js';
|
|
4
|
-
const isUndefinedTableError = (err) => {
|
|
5
|
-
const candidates = [
|
|
6
|
-
err,
|
|
7
|
-
err && typeof err === 'object' && 'cause' in err
|
|
8
|
-
? err.cause
|
|
9
|
-
: undefined,
|
|
10
|
-
];
|
|
11
|
-
return candidates.some((candidate) => candidate &&
|
|
12
|
-
typeof candidate === 'object' &&
|
|
13
|
-
'code' in candidate &&
|
|
14
|
-
candidate.code === '42P01');
|
|
15
|
-
};
|
|
16
|
-
export const tableCount = async (collection) => {
|
|
17
|
-
var _a, _b;
|
|
18
|
-
const table = getTableForCollection(collection);
|
|
19
|
-
const tableName = getTableName(table);
|
|
20
|
-
const db = pgDb();
|
|
21
|
-
try {
|
|
22
|
-
const result = await db.execute(sql.raw(`SELECT COUNT(*)::text AS count FROM "${tableName}"`));
|
|
23
|
-
return Number((_b = (_a = result.rows[0]) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0);
|
|
24
|
-
}
|
|
25
|
-
catch (err) {
|
|
26
|
-
// Missing table ⇒ treat as empty so callers can remigrate / auto-import.
|
|
27
|
-
if (isUndefinedTableError(err)) {
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
throw err;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
export { isUndefinedTableError };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { logger } from '../../log/index.js';
|
|
2
|
-
import { closePostgres } from '../pg/client.js';
|
|
3
|
-
import { assertExportDir, collectionsDir, exportDirFromEnv, readManifest, writeImportStats, } from './shared.js';
|
|
4
|
-
import { importAllArangoCollections } from './importCollections.js';
|
|
5
|
-
const log = logger('core:migration:import');
|
|
6
|
-
export const importPostgres = async (exportDir = exportDirFromEnv(), options = {}) => {
|
|
7
|
-
var _a;
|
|
8
|
-
const closeConnection = (_a = options.closeConnection) !== null && _a !== void 0 ? _a : true;
|
|
9
|
-
await assertExportDir(exportDir);
|
|
10
|
-
const manifest = await readManifest(exportDir);
|
|
11
|
-
log.info('Importing export from %s (exported %s)', exportDir, manifest.exportedAt);
|
|
12
|
-
const { imported } = await importAllArangoCollections(collectionsDir(exportDir));
|
|
13
|
-
await writeImportStats(exportDir, imported);
|
|
14
|
-
if (closeConnection) {
|
|
15
|
-
await closePostgres();
|
|
16
|
-
}
|
|
17
|
-
return imported;
|
|
18
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/** Postgres uuid compares case-insensitively; normalize so dedupe matches. */
|
|
2
|
-
export declare const normalizeImportId: (value: unknown) => string | undefined;
|
|
3
|
-
export declare const arangoDocToModel: (doc: Record<string, unknown>) => Record<string, unknown>;
|
|
4
|
-
export type ImportContext = {
|
|
5
|
-
postCreatorIdByPostId?: Map<string, string>;
|
|
6
|
-
/** Empty-name / duplicate-name hashtags: old id → kept id, or '' if dropped. */
|
|
7
|
-
hashtagIdRemap?: Map<string, string>;
|
|
8
|
-
};
|
|
9
|
-
/** Pre-scan entries edges so legacy posts without creatorId can be imported. */
|
|
10
|
-
export declare const buildPostCreatorIdByPostId: (collectionsDir: string) => Promise<Map<string, string>>;
|
|
11
|
-
/**
|
|
12
|
-
* Legacy Arango groups used discoverable/locked flags; capabilities were added
|
|
13
|
-
* later via an Arango-only data migration that never runs on Postgres restores.
|
|
14
|
-
*/
|
|
15
|
-
export declare const capabilitiesFromLegacyGroupFlags: (data: Record<string, unknown>) => Record<string, unknown> | undefined;
|
|
16
|
-
export declare const normalizeGroupMembershipRoles: (roles: unknown) => unknown;
|
|
17
|
-
export declare const normalizeGroupCapabilityMap: (capabilities: Record<string, unknown>) => Record<string, unknown>;
|
|
18
|
-
export declare const arangoDocToDocumentRow: (collection: string, doc: Record<string, unknown>, context?: ImportContext) => Record<string, unknown>;
|
|
19
|
-
export declare const arangoDocToEdgeRow: (collection: string, doc: Record<string, unknown>) => Record<string, unknown>;
|
|
20
|
-
export declare const isEdgeCollection: (collection: string) => boolean;
|