@openpeepshq/core 0.1.34 → 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 +13 -8
- package/dist/analytics/cache.js +3 -3
- package/dist/analytics/clicks.js +14 -22
- package/dist/analytics/compile.js +1 -2
- 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 +116 -135
- package/dist/analytics/report.d.ts +2 -1
- package/dist/analytics/report.js +2 -3
- package/dist/analytics/settings.js +3 -4
- package/dist/backups/index.js +13 -16
- package/dist/backups/metadata.js +1 -1
- package/dist/config/db.js +2 -4
- package/dist/config/defaults/community.js +1 -0
- package/dist/config/defaults/core.js +13 -8
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +9 -11
- package/dist/db/explorer/query.js +9 -8
- package/dist/db/explorer/sql.js +8 -8
- package/dist/db/helpers.js +15 -5
- package/dist/db/migration/importCollections.js +15 -18
- package/dist/db/migration/shared.js +15 -35
- package/dist/db/pg/client.js +4 -7
- package/dist/db/pg/filters/index.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +2 -0
- package/dist/db/pg/filters/posts.js +2 -0
- package/dist/db/pg/helpers.js +2 -14
- package/dist/db/pg/map/filters.js +8 -8
- 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 +56 -21
- package/dist/db/pg/map/registry.js +87 -50
- package/dist/db/pg/map/relations.js +67 -63
- package/dist/db/pg/map/search.js +15 -37
- package/dist/db/pg/mappers.js +13 -7
- package/dist/db/pg/migrate.js +2 -3
- package/dist/db/pg/queries/activity.js +2 -2
- package/dist/db/pg/queries/derived.js +8 -12
- package/dist/db/pg/schema/documents.js +119 -18
- package/dist/db/pg/schema/edges.js +7 -1
- package/dist/db/pg/schema/index.js +5 -1
- package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
- package/dist/db/pg/sql/meta/_journal.json +8 -1
- package/dist/db/replaceOrigin.js +1 -1
- package/dist/email/queueStats.js +8 -11
- package/dist/email/render.js +7 -4
- package/dist/email/send.js +19 -17
- package/dist/email/smtpTest.js +10 -6
- package/dist/errors/index.js +1 -1
- package/dist/events/once.js +2 -4
- package/dist/federation/activities.js +1 -2
- package/dist/groups/helpers.js +1 -2
- package/dist/groups/mutations.js +1 -1
- package/dist/hashtags/finders.js +2 -2
- package/dist/inviteLinks/mutations.js +2 -3
- package/dist/jams/export.js +5 -7
- package/dist/jams/finders.js +4 -1
- package/dist/jams/health.d.ts +6 -4
- package/dist/jams/health.js +15 -11
- package/dist/jams/helpers.js +6 -2
- package/dist/jams/index.js +2 -2
- package/dist/jams/jobs.js +1 -2
- package/dist/jams/livekit.js +8 -8
- package/dist/jams/recording.js +1 -1
- package/dist/jams/token.js +13 -17
- package/dist/jobs/index.js +7 -6
- package/dist/jobs/jobDetail.js +5 -6
- 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.js +50 -4
- package/dist/media/jobs.js +1 -2
- package/dist/media/openpeeps/index.js +11 -46
- package/dist/media/processing.js +7 -4
- 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 +14 -17
- 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/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 +6 -7
- package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
- package/dist/notifications/defaultNotifications/pollEnded/index.js +21 -21
- package/dist/notifications/defaultNotifications/pollEnded/recipients.js +2 -3
- 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.js +24 -18
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +20 -13
- 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 -7
- package/dist/notifications/mutations.js +4 -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 +2 -3
- package/dist/plugins/install.js +31 -17
- package/dist/plugins/pluginAuth.js +3 -4
- package/dist/plugins/state.js +2 -3
- package/dist/posts/activity.js +1 -2
- package/dist/posts/contextClosure.js +1 -2
- package/dist/posts/conversationQueries.js +2 -4
- package/dist/posts/eventAgenda.js +8 -5
- package/dist/posts/eventOccurrences.js +2 -2
- package/dist/posts/finders.d.ts +42 -2
- package/dist/posts/finders.js +21 -9
- package/dist/posts/helpers/filters.js +2 -3
- package/dist/posts/helpers/index.d.ts +152 -0
- package/dist/posts/helpers/index.js +43 -27
- package/dist/posts/mapping.d.ts +546 -14
- package/dist/posts/mapping.js +60 -18
- package/dist/posts/mutations.d.ts +76 -0
- package/dist/posts/mutations.js +46 -31
- package/dist/posts/pollEnd.js +3 -6
- package/dist/posts/rsvpConfirmationEmail.js +18 -8
- package/dist/posts/threadPreview.js +1 -1
- package/dist/processingStats/queries.js +6 -7
- package/dist/profileSettings/cache.js +1 -2
- package/dist/profiles/activitySummary.js +23 -28
- package/dist/profiles/cache.js +15 -8
- package/dist/profiles/export.js +30 -39
- package/dist/profiles/finders.js +7 -5
- package/dist/profiles/mutations.js +3 -5
- package/dist/redis/connection.js +1 -1
- package/dist/reports/helpers.js +7 -3
- package/dist/roles/mutations.js +20 -21
- package/dist/search/finders.js +15 -3
- package/dist/search/helpers.js +1 -1
- 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 +1 -0
- package/dist/server/index.js +16 -11
- package/dist/server/status.js +6 -7
- package/dist/session/index.js +2 -2
- package/dist/stats/finders.js +13 -4
- package/dist/stats/helpers.js +4 -1
- package/dist/stats/mapping.d.ts +39 -1
- package/dist/stats/mapping.js +9 -2
- 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 -6
package/dist/server/index.js
CHANGED
|
@@ -27,15 +27,13 @@ export const protocolForServerHost = (host, envProtocol = process.env.SERVER_PRO
|
|
|
27
27
|
export const serverProtocol = async () => protocolForServerHost((await config()).server.host);
|
|
28
28
|
export const serverRootUrl = async () => `${await serverProtocol()}://${(await config()).server.host}`;
|
|
29
29
|
const lastAccessedFromPostViews = async () => {
|
|
30
|
-
var _a;
|
|
31
30
|
const db = await database();
|
|
32
31
|
const rows = await db
|
|
33
32
|
.select({ last: sql `max(${postSeen.createdAt})` })
|
|
34
33
|
.from(postSeen);
|
|
35
|
-
return normalizeComputedDatetime(
|
|
34
|
+
return normalizeComputedDatetime(rows[0]?.last);
|
|
36
35
|
};
|
|
37
36
|
export const serverInfo = () => config().then(async (coreConfig) => {
|
|
38
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
39
37
|
const [lastAccessed, disk, community] = await Promise.all([
|
|
40
38
|
lastAccessedFromPostViews(),
|
|
41
39
|
diskUsage(coreConfig.media.storage.params.path),
|
|
@@ -43,7 +41,7 @@ export const serverInfo = () => config().then(async (coreConfig) => {
|
|
|
43
41
|
]);
|
|
44
42
|
return {
|
|
45
43
|
version: coreConfig.version,
|
|
46
|
-
build:
|
|
44
|
+
build: process.env.BUILD?.trim() || undefined,
|
|
47
45
|
environment: coreConfig.environment,
|
|
48
46
|
publicContent: coreConfig.server.publicContent,
|
|
49
47
|
startedAt: processStartedAt,
|
|
@@ -51,7 +49,14 @@ export const serverInfo = () => config().then(async (coreConfig) => {
|
|
|
51
49
|
disk,
|
|
52
50
|
lastAccessed,
|
|
53
51
|
maxProfiles: coreConfig.server.maxProfiles || undefined,
|
|
54
|
-
communityConfig:
|
|
52
|
+
communityConfig: {
|
|
53
|
+
...community,
|
|
54
|
+
theme: withLegacyThemeRoot(community.theme),
|
|
55
|
+
settings: {
|
|
56
|
+
...community.settings,
|
|
57
|
+
openRegistrations: !!coreConfig.server.signUpsOpen,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
55
60
|
jams: {
|
|
56
61
|
livekit: {
|
|
57
62
|
url: coreConfig.jams.livekit.url,
|
|
@@ -65,16 +70,16 @@ export const serverInfo = () => config().then(async (coreConfig) => {
|
|
|
65
70
|
publicKey: coreConfig.vapid.publicKey,
|
|
66
71
|
},
|
|
67
72
|
sentryConfig: {
|
|
68
|
-
enabled: !!
|
|
69
|
-
!!
|
|
70
|
-
dsn:
|
|
71
|
-
replayEnabled: !!
|
|
72
|
-
!!
|
|
73
|
+
enabled: !!coreConfig.services?.sentry?.enabled &&
|
|
74
|
+
!!coreConfig.services?.sentry?.dsn,
|
|
75
|
+
dsn: coreConfig.services?.sentry?.dsn,
|
|
76
|
+
replayEnabled: !!coreConfig.services?.sentry?.replayEnabled &&
|
|
77
|
+
!!coreConfig.services?.sentry?.dsn,
|
|
73
78
|
},
|
|
74
79
|
payments: {
|
|
75
80
|
stripe: {
|
|
76
81
|
paidMembership: {
|
|
77
|
-
enabled: !!
|
|
82
|
+
enabled: !!coreConfig.payments?.stripe?.paidMembership?.enabled,
|
|
78
83
|
},
|
|
79
84
|
},
|
|
80
85
|
},
|
package/dist/server/status.js
CHANGED
|
@@ -2,7 +2,7 @@ import { readdir, stat, statfs } from 'node:fs/promises';
|
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
export const processStartedAt = new Date(Date.now() - process.uptime() * 1000).toISOString();
|
|
5
|
-
const FOLDER_SIZE_CACHE_MS =
|
|
5
|
+
const FOLDER_SIZE_CACHE_MS = 30_000;
|
|
6
6
|
let folderSizeCache = null;
|
|
7
7
|
/** Sum of regular files under dir. Skips unreadable entries. */
|
|
8
8
|
export const folderSize = async (dir) => {
|
|
@@ -11,7 +11,7 @@ export const folderSize = async (dir) => {
|
|
|
11
11
|
try {
|
|
12
12
|
entries = await readdir(dir, { withFileTypes: true });
|
|
13
13
|
}
|
|
14
|
-
catch
|
|
14
|
+
catch {
|
|
15
15
|
return 0;
|
|
16
16
|
}
|
|
17
17
|
for (const entry of entries) {
|
|
@@ -27,7 +27,7 @@ export const folderSize = async (dir) => {
|
|
|
27
27
|
total += (await stat(full)).size;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
catch
|
|
30
|
+
catch {
|
|
31
31
|
// Skip entries we cannot stat (permissions, races).
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -56,7 +56,7 @@ export const diskUsage = async (mediaPath) => {
|
|
|
56
56
|
const folderBytes = await cachedFolderSize(mediaPath);
|
|
57
57
|
return { folderBytes, totalBytes, freeBytes };
|
|
58
58
|
}
|
|
59
|
-
catch
|
|
59
|
+
catch {
|
|
60
60
|
return null;
|
|
61
61
|
}
|
|
62
62
|
};
|
|
@@ -85,14 +85,13 @@ export const memoryUsage = (totalBytes = os.totalmem(), freeBytes = os.freemem()
|
|
|
85
85
|
};
|
|
86
86
|
const CPU_SAMPLE_MS = 50;
|
|
87
87
|
export const hostResources = async (wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))) => {
|
|
88
|
-
var _a, _b;
|
|
89
88
|
const memory = memoryUsage();
|
|
90
89
|
const previous = cpuTimes();
|
|
91
90
|
await wait(CPU_SAMPLE_MS);
|
|
92
91
|
const cpuPercent = Math.round(cpuUsedPercent(previous, cpuTimes()) * 10) / 10;
|
|
93
92
|
return {
|
|
94
|
-
memoryUsedBytes:
|
|
95
|
-
memoryTotalBytes:
|
|
93
|
+
memoryUsedBytes: memory?.usedBytes ?? 0,
|
|
94
|
+
memoryTotalBytes: memory?.totalBytes ?? 0,
|
|
96
95
|
cpuUsedPercent: cpuPercent,
|
|
97
96
|
};
|
|
98
97
|
};
|
package/dist/session/index.js
CHANGED
|
@@ -50,9 +50,9 @@ export const getSessionPresence = async (profileId) => {
|
|
|
50
50
|
const connections = Object.entries(raw).flatMap(([connectionId, value]) => {
|
|
51
51
|
try {
|
|
52
52
|
const parsed = JSON.parse(value);
|
|
53
|
-
return [
|
|
53
|
+
return [{ connectionId, ...parsed }];
|
|
54
54
|
}
|
|
55
|
-
catch
|
|
55
|
+
catch {
|
|
56
56
|
return [];
|
|
57
57
|
}
|
|
58
58
|
});
|
package/dist/stats/finders.js
CHANGED
|
@@ -120,25 +120,34 @@ const createIntervals = (duration) => {
|
|
|
120
120
|
start: sub(new Date(), { days: i + 1 }),
|
|
121
121
|
end: sub(new Date(), { days: i }),
|
|
122
122
|
}))
|
|
123
|
-
.map((interval) => (
|
|
123
|
+
.map((interval) => ({
|
|
124
|
+
name: interval.start.toISOString().split('T')[0],
|
|
125
|
+
...interval,
|
|
126
|
+
}));
|
|
124
127
|
case 'P4W':
|
|
125
128
|
return [0, 1, 2, 3]
|
|
126
129
|
.map((i) => ({
|
|
127
130
|
start: sub(new Date(), { days: (i + 1) * 7 }),
|
|
128
131
|
end: sub(new Date(), { days: i * 7 }),
|
|
129
132
|
}))
|
|
130
|
-
.map((interval) => (
|
|
133
|
+
.map((interval) => ({
|
|
134
|
+
name: `${interval.start.toISOString().split('T')[0]} - ${interval.end.toISOString().split('T')[0]}`,
|
|
135
|
+
...interval,
|
|
136
|
+
}));
|
|
131
137
|
case 'P120D':
|
|
132
138
|
return [0, 1, 2, 3]
|
|
133
139
|
.map((i) => ({
|
|
134
140
|
start: sub(new Date(), { days: (i + 1) * 30 }),
|
|
135
141
|
end: sub(new Date(), { days: i * 30 }),
|
|
136
142
|
}))
|
|
137
|
-
.map((interval) => (
|
|
143
|
+
.map((interval) => ({
|
|
144
|
+
name: `${interval.start.toISOString().split('T')[0]} - ${interval.end.toISOString().split('T')[0]}`,
|
|
145
|
+
...interval,
|
|
146
|
+
}));
|
|
138
147
|
}
|
|
139
148
|
};
|
|
140
149
|
export const signupsTimeline = (duration) => Promise.all(createIntervals(duration).map((interval) => newProfilesForInterval(interval.start, interval.end).then((count) => ({
|
|
141
|
-
name: interval
|
|
150
|
+
name: interval?.name,
|
|
142
151
|
count,
|
|
143
152
|
}))));
|
|
144
153
|
export const serverStats = async () => ({
|
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,6 +197,44 @@ 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;
|
package/dist/stats/mapping.js
CHANGED
|
@@ -3,8 +3,15 @@ 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
|
-
|
|
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()],
|
|
14
|
+
});
|
|
8
15
|
export const followsMapping = map({
|
|
9
16
|
collection: collectionInfos.followsCollection.name,
|
|
10
17
|
});
|
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/i18n": "^0.1.
|
|
43
|
-
"@openpeepshq/geocoder": "^0.1.2"
|
|
44
|
-
"@openpeepshq/fetch-client": "^0.1.7"
|
|
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",
|