@openpeepshq/core 0.1.32 → 0.1.34
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/helpers.d.ts +2 -2
- package/dist/accessTokens/tokens.js +14 -7
- package/dist/accounts/mutations.d.ts +2 -2
- package/dist/accounts/mutations.js +33 -35
- package/dist/analytics/cache.js +12 -7
- package/dist/analytics/compile.js +16 -10
- package/dist/analytics/pdfReport.d.ts +1 -0
- package/dist/analytics/pdfReport.js +5 -4
- package/dist/analytics/privacy.d.ts +18 -0
- package/dist/analytics/privacy.js +10 -0
- package/dist/analytics/read.js +75 -19
- package/dist/analytics/report.d.ts +21 -1
- package/dist/analytics/report.js +9 -2
- package/dist/backups/index.js +78 -15
- package/dist/backups/metadata.d.ts +8 -2
- package/dist/backups/metadata.js +6 -2
- package/dist/config/defaults/capabilities.js +13 -2
- package/dist/config/defaults/community.js +7 -9
- package/dist/config/defaults/core.d.ts +1 -1
- package/dist/config/defaults/core.js +3 -0
- package/dist/config/defaults/db.d.ts +0 -2
- package/dist/config/defaults/db.js +0 -2
- package/dist/config/index.d.ts +25 -3
- package/dist/config/index.js +7 -1
- package/dist/db/helpers.d.ts +7 -28
- package/dist/db/helpers.js +30 -152
- package/dist/db/index.d.ts +3 -1
- package/dist/db/index.js +5 -0
- package/dist/db/init.js +2 -2
- package/dist/db/migration/importCollections.d.ts +15 -10
- package/dist/db/migration/importCollections.js +121 -155
- package/dist/db/migration/shared.d.ts +2 -37
- package/dist/db/migration/shared.js +2 -59
- package/dist/db/pg/client.js +4 -0
- package/dist/db/pg/collections.d.ts +2 -2
- package/dist/db/pg/collections.js +2 -2
- package/dist/db/pg/filters/edges.d.ts +1 -1
- package/dist/db/pg/filters/edges.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +11 -0
- package/dist/db/pg/filters/posts.js +37 -3
- package/dist/db/pg/filters/profiles.d.ts +1 -0
- package/dist/db/pg/filters/profiles.js +2 -1
- package/dist/db/pg/map/filters.js +37 -2
- package/dist/db/pg/map/mutations.js +13 -8
- package/dist/db/pg/map/registry.d.ts +5 -0
- package/dist/db/pg/map/registry.js +64 -24
- package/dist/db/pg/map/relations.d.ts +1 -1
- package/dist/db/pg/map/relations.js +98 -46
- package/dist/db/pg/migrate.d.ts +22 -0
- package/dist/db/pg/migrate.js +88 -2
- package/dist/db/pg/queries/activity.js +3 -3
- 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 +422 -41
- package/dist/db/pg/schema/documents.js +43 -9
- package/dist/db/pg/schema/edges.d.ts +117 -7
- package/dist/db/pg/schema/edges.js +4 -2
- package/dist/db/pg/schema/index.d.ts +505 -15
- package/dist/db/pg/sql/0007_shallow_oracle.sql +3 -0
- package/dist/db/pg/sql/0008_group_owner_roles.sql +31 -0
- package/dist/db/pg/sql/0009_event_occurrences.sql +26 -0
- 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/meta/{0006_snapshot.json → 0015_snapshot.json} +393 -39
- package/dist/db/pg/sql/meta/_journal.json +64 -1
- package/dist/db/replaceOrigin.js +6 -0
- package/dist/db/types.d.ts +0 -4
- package/dist/email/render.js +11 -3
- package/dist/events/index.d.ts +6 -1
- package/dist/events/index.js +55 -33
- package/dist/federation/activities.d.ts +17 -0
- package/dist/federation/activities.js +26 -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 +3 -2
- package/dist/groups/helpers.d.ts +24 -6
- package/dist/groups/mapping.d.ts +6 -4
- package/dist/groups/mapping.js +2 -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/helpers.d.ts +4 -4
- package/dist/jams/cache.d.ts +1 -1
- package/dist/jams/cache.js +2 -1
- package/dist/jams/export.d.ts +19 -0
- package/dist/jams/export.js +60 -0
- package/dist/jams/finders.d.ts +2 -1
- package/dist/jams/finders.js +18 -7
- package/dist/jams/health.d.ts +8 -0
- package/dist/jams/health.js +46 -0
- package/dist/jams/helpers.d.ts +6 -2
- package/dist/jams/index.d.ts +6 -3
- package/dist/jams/index.js +41 -27
- package/dist/jams/jobs.js +1 -1
- package/dist/jams/livekit.d.ts +93 -10
- package/dist/jams/livekit.js +151 -52
- package/dist/jams/mapping.d.ts +17 -7
- package/dist/jams/mutations.d.ts +3 -1
- package/dist/jams/recording.d.ts +10 -0
- package/dist/jams/recording.js +32 -0
- package/dist/jams/rtmp.d.ts +5 -0
- package/dist/jams/rtmp.js +8 -0
- package/dist/jams/token.d.ts +15 -3
- package/dist/jams/token.js +30 -16
- package/dist/jams/waitingRoom.d.ts +6 -6
- package/dist/jams/waitingRoom.js +24 -23
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +6 -1
- package/dist/jobs/jobDetail.js +1 -6
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +23 -8
- package/dist/media/processing.js +18 -7
- package/dist/notifications/defaultNotifications/follow/index.js +2 -2
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
- package/dist/notifications/defaultNotifications/index.js +4 -0
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +12 -6
- 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 +18 -0
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
- package/dist/notifications/defaultNotifications/rsvp/index.js +7 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +75 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
- package/dist/notifications/helpers.js +6 -2
- package/dist/notifications/jobs.js +3 -1
- package/dist/notifications/mutations.js +4 -0
- package/dist/notifications/push.js +11 -4
- package/dist/plugins/helpers.d.ts +1 -0
- package/dist/plugins/helpers.js +1 -8
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/index.js +78 -5
- package/dist/plugins/install.d.ts +39 -0
- package/dist/plugins/install.js +455 -0
- package/dist/plugins/pluginAuth.d.ts +1 -1
- package/dist/plugins/pluginAuth.js +10 -6
- package/dist/plugins/state.d.ts +4 -0
- package/dist/plugins/state.js +29 -0
- package/dist/posts/activity.d.ts +9 -0
- package/dist/posts/activity.js +35 -0
- package/dist/posts/contextClosure.d.ts +1 -9
- package/dist/posts/contextClosure.js +15 -44
- package/dist/posts/conversationQueries.d.ts +7 -0
- package/dist/posts/conversationQueries.js +76 -2
- package/dist/posts/eventAgenda.d.ts +166 -0
- package/dist/posts/eventAgenda.js +126 -0
- package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
- package/dist/posts/eventOccurrenceJobs.js +28 -0
- package/dist/posts/eventOccurrences.d.ts +10 -0
- package/dist/posts/eventOccurrences.js +61 -0
- package/dist/posts/finders.d.ts +47 -16
- package/dist/posts/finders.js +93 -62
- package/dist/posts/helpers/filters.js +14 -9
- package/dist/posts/helpers/index.d.ts +129 -30
- package/dist/posts/helpers/index.js +66 -33
- package/dist/posts/index.d.ts +7 -1
- package/dist/posts/index.js +7 -1
- package/dist/posts/mapping.d.ts +491 -13
- package/dist/posts/mapping.js +45 -10
- package/dist/posts/mutations.d.ts +441 -4
- package/dist/posts/mutations.js +177 -43
- package/dist/posts/pollEnd.d.ts +3 -0
- package/dist/posts/pollEnd.js +7 -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 +14 -15
- package/dist/posts/threadPreview.d.ts +8 -0
- package/dist/posts/threadPreview.js +44 -0
- package/dist/posts/unseenCounts.d.ts +2 -0
- package/dist/posts/unseenCounts.js +28 -8
- package/dist/profileSettings/cache.js +22 -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 +87 -0
- package/dist/profiles/blocks.d.ts +12 -0
- package/dist/profiles/blocks.js +73 -0
- package/dist/profiles/cache.d.ts +4 -1
- package/dist/profiles/cache.js +28 -7
- package/dist/profiles/finders.d.ts +2 -1
- package/dist/profiles/finders.js +8 -3
- package/dist/profiles/helpers.d.ts +7 -5
- package/dist/profiles/index.d.ts +3 -1
- package/dist/profiles/index.js +3 -1
- 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 +42 -15
- package/dist/pushSubscriptions/helpers.d.ts +2 -2
- package/dist/pushSubscriptions/mutations.js +13 -1
- package/dist/redis/connection.d.ts +2 -0
- package/dist/redis/connection.js +25 -6
- package/dist/reports/helpers.d.ts +6 -6
- 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 +86 -3
- package/dist/search/mapping.d.ts +1 -1
- package/dist/search/mapping.js +6 -2
- package/dist/server/index.d.ts +19 -1
- package/dist/server/index.js +37 -18
- 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 +98 -0
- package/dist/stats/finders.d.ts +1 -16131
- package/dist/stats/finders.js +9 -5
- package/dist/stats/mapping.d.ts +21 -1
- package/dist/stats/mapping.js +0 -3
- package/package.json +6 -12
- package/dist/db/arango.d.ts +0 -2
- package/dist/db/arango.js +0 -110
- package/dist/db/migration/autoMigrate.d.ts +0 -2
- package/dist/db/migration/autoMigrate.js +0 -111
- package/dist/db/migration/cli.d.ts +0 -1
- package/dist/db/migration/cli.js +0 -56
- package/dist/db/migration/detect.d.ts +0 -6
- package/dist/db/migration/detect.js +0 -87
- package/dist/db/migration/exportArango.d.ts +0 -4
- package/dist/db/migration/exportArango.js +0 -80
- 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 -18
- package/dist/db/migration/transform.js +0 -209
- 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/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/roles/defaults.d.ts +0 -2
- package/dist/roles/defaults.js +0 -94
|
@@ -4,13 +4,20 @@ import { followConnector, followDisconnector, giveControl, roleAssigner, roleUna
|
|
|
4
4
|
import { hub } from '../events/index.js';
|
|
5
5
|
import { randomString } from '@openpeepshq/common/lib';
|
|
6
6
|
import { deleteAccessTokensForProfile } from '../accessTokens/helpers.js';
|
|
7
|
-
import { profilesCache, getProfile } from './cache.js';
|
|
7
|
+
import { profilesCache, getProfile, getPublicProfile, clearProfileCache, } from './cache.js';
|
|
8
8
|
import { accountsCache } from '../accounts/cache.js';
|
|
9
9
|
import { assertProfileCapacity } from './capacity.js';
|
|
10
|
+
import { deleteBlock, dropFollowsBetween, insertBlock, listBlockingIds, } from './blocks.js';
|
|
11
|
+
import { localActorScalars } from '../federation/identity.js';
|
|
12
|
+
import { uuidv7 } from 'uuidv7';
|
|
10
13
|
export const createProfile = async (data, controllingAccount) => {
|
|
14
|
+
var _a;
|
|
11
15
|
await assertProfileCapacity();
|
|
12
16
|
const db = await allpeepDb().then((db) => db.db);
|
|
13
|
-
const
|
|
17
|
+
const id = uuidv7();
|
|
18
|
+
const domain = (_a = data.activityPub) === null || _a === void 0 ? void 0 : _a.domain;
|
|
19
|
+
const actor = data.type === 'local' && domain ? localActorScalars(id, domain) : {};
|
|
20
|
+
const profile = await profilesMapping.create(db, Object.assign(Object.assign(Object.assign({}, data), { id }), actor));
|
|
14
21
|
if (controllingAccount) {
|
|
15
22
|
await giveControl(db, controllingAccount, profile);
|
|
16
23
|
await accountsCache.del(controllingAccount.id);
|
|
@@ -37,6 +44,11 @@ export const updateProfile = async (profileId, data) => {
|
|
|
37
44
|
}
|
|
38
45
|
return profilesMapping.update(db, profileId, data);
|
|
39
46
|
};
|
|
47
|
+
export const pinPostOnProfile = async (profile, pinnedPostId) => {
|
|
48
|
+
const updated = await updateProfile(profile.id, { pinnedPostId });
|
|
49
|
+
await clearProfileCache(profile);
|
|
50
|
+
return updated;
|
|
51
|
+
};
|
|
40
52
|
export const deleteProfile = async (profileId) => {
|
|
41
53
|
var _a, _b;
|
|
42
54
|
const db = await allpeepDb().then((db) => db.db);
|
|
@@ -54,19 +66,34 @@ export const deleteProfile = async (profileId) => {
|
|
|
54
66
|
await deleteAccessTokensForProfile(db, profileId);
|
|
55
67
|
return profilesMapping.delete(db, profileId);
|
|
56
68
|
};
|
|
57
|
-
export const follow = async (follower, followed, followData) =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
69
|
+
export const follow = async (follower, followed, followData) => {
|
|
70
|
+
const { db } = await allpeepDb();
|
|
71
|
+
await followConnector(db, follower, followed, followData);
|
|
72
|
+
await Promise.all([clearProfileCache(follower), clearProfileCache(followed)]);
|
|
73
|
+
await hub.emit('followCreated', follower, followed);
|
|
74
|
+
};
|
|
75
|
+
export const unfollow = async (follower, followed) => {
|
|
76
|
+
const { db } = await allpeepDb();
|
|
77
|
+
await followDisconnector(db, follower, followed);
|
|
78
|
+
await Promise.all([clearProfileCache(follower), clearProfileCache(followed)]);
|
|
79
|
+
};
|
|
80
|
+
export const blockProfile = async (blocker, blocked) => {
|
|
81
|
+
const { db } = await allpeepDb();
|
|
82
|
+
await insertBlock(db, blocker.id, blocked.id);
|
|
83
|
+
await dropFollowsBetween(db, blocker.id, blocked.id);
|
|
84
|
+
await Promise.all([clearProfileCache(blocker), clearProfileCache(blocked)]);
|
|
85
|
+
};
|
|
86
|
+
export const unblockProfile = async (blocker, blocked) => {
|
|
87
|
+
const { db } = await allpeepDb();
|
|
88
|
+
await deleteBlock(db, blocker.id, blocked.id);
|
|
89
|
+
await Promise.all([clearProfileCache(blocker), clearProfileCache(blocked)]);
|
|
90
|
+
};
|
|
91
|
+
export const listBlockedProfiles = async (profile) => {
|
|
92
|
+
const { db } = await allpeepDb();
|
|
93
|
+
const ids = await listBlockingIds(db, profile.id);
|
|
94
|
+
const profiles = await Promise.all(ids.map((id) => getPublicProfile(id)));
|
|
95
|
+
return profiles.filter((item) => !!item);
|
|
96
|
+
};
|
|
70
97
|
export const assignRole = (profile, role) => allpeepDb()
|
|
71
98
|
.then(({ db }) => roleAssigner(db, profile, role))
|
|
72
99
|
.then(() => profilesCache.del(profile.id));
|
|
@@ -91,9 +91,9 @@ export declare const pushSubscriptionAccountConnector: (db: import("../db").PgDb
|
|
|
91
91
|
};
|
|
92
92
|
} | undefined;
|
|
93
93
|
deletedAt?: string | null | undefined;
|
|
94
|
-
}, data?: {
|
|
94
|
+
}, data?: object & {
|
|
95
95
|
id?: string;
|
|
96
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
96
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
97
97
|
_from: string;
|
|
98
98
|
_to: string;
|
|
99
99
|
}>>;
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { pushSubscriptionsMapping } from './mapping.js';
|
|
2
2
|
import { allpeepDb } from '../db/index.js';
|
|
3
3
|
import { pushSubscriptionAccountConnector } from './helpers.js';
|
|
4
|
+
const uniqueCredential = (data) => {
|
|
5
|
+
switch (data.type) {
|
|
6
|
+
case 'web':
|
|
7
|
+
return { type: data.type, endpoint: data.endpoint };
|
|
8
|
+
case 'webhook':
|
|
9
|
+
return { type: data.type, url: data.url };
|
|
10
|
+
case 'apn':
|
|
11
|
+
return { type: data.type, apnToken: data.apnToken };
|
|
12
|
+
case 'fcm':
|
|
13
|
+
return { type: data.type, fcmToken: data.fcmToken };
|
|
14
|
+
}
|
|
15
|
+
};
|
|
4
16
|
export const createPushSubscription = async (account, data) => {
|
|
5
17
|
const db = await allpeepDb().then((db) => db.db);
|
|
6
18
|
const existingPushSubscription = await pushSubscriptionsMapping
|
|
7
19
|
.filter({
|
|
8
|
-
matches: data,
|
|
20
|
+
matches: uniqueCredential(data),
|
|
9
21
|
})
|
|
10
22
|
.first(db);
|
|
11
23
|
if (existingPushSubscription) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { RedisClientType } from 'redis';
|
|
2
2
|
export declare const getConnection: () => Promise<RedisClientType>;
|
|
3
3
|
export declare const disconnect: (conn: RedisClientType) => Promise<void>;
|
|
4
|
+
/** CLI exit: hub.on / getSharedConnection leave node-redis sockets open. */
|
|
5
|
+
export declare const closeRedisConnections: () => Promise<void>;
|
|
4
6
|
export declare const getSharedConnection: () => Promise<RedisClientType>;
|
package/dist/redis/connection.js
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
import { createClient } from 'redis';
|
|
2
2
|
import { defaultConfig } from '../config/defaults/core.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const clients = new Set();
|
|
4
|
+
export const getConnection = () => {
|
|
5
|
+
const client = createClient({
|
|
6
|
+
url: `redis://${defaultConfig.redis.host}:6379`,
|
|
7
|
+
});
|
|
8
|
+
client.on('error', console.log);
|
|
9
|
+
clients.add(client);
|
|
10
|
+
return client.connect();
|
|
11
|
+
};
|
|
8
12
|
export const disconnect = async (conn) => {
|
|
9
|
-
|
|
13
|
+
if (conn.isOpen) {
|
|
14
|
+
await conn.disconnect().catch(console.error);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/** CLI exit: hub.on / getSharedConnection leave node-redis sockets open. */
|
|
18
|
+
export const closeRedisConnections = async () => {
|
|
19
|
+
connection = undefined;
|
|
20
|
+
await Promise.all([...clients].map(async (conn) => {
|
|
21
|
+
try {
|
|
22
|
+
await conn.disconnect();
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
// already closed
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
28
|
+
clients.clear();
|
|
10
29
|
};
|
|
11
30
|
let connection;
|
|
12
31
|
export const getSharedConnection = async () => {
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { PostWithMeta, ReportWithMeta, ProfileWithMeta } from '@openpeepshq/common/types';
|
|
2
2
|
export declare const transformReport: (report: ReportWithMeta) => Promise<ReportWithMeta>;
|
|
3
3
|
export declare const transformReports: (reports: ReportWithMeta[]) => Promise<ReportWithMeta[]>;
|
|
4
|
-
export declare const createdReportConnector: (db: import("../db").PgDb, from: ProfileWithMeta, to: ReportWithMeta, data?: {
|
|
4
|
+
export declare const createdReportConnector: (db: import("../db").PgDb, from: ProfileWithMeta, to: ReportWithMeta, data?: object & {
|
|
5
5
|
id?: string;
|
|
6
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
6
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
7
7
|
_from: string;
|
|
8
8
|
_to: string;
|
|
9
9
|
}>>;
|
|
10
|
-
export declare const reportedProfileConnector: (db: import("../db").PgDb, from: ReportWithMeta, to: ProfileWithMeta, data?: {
|
|
10
|
+
export declare const reportedProfileConnector: (db: import("../db").PgDb, from: ReportWithMeta, to: ProfileWithMeta, data?: object & {
|
|
11
11
|
id?: string;
|
|
12
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
12
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
13
13
|
_from: string;
|
|
14
14
|
_to: string;
|
|
15
15
|
}>>;
|
|
16
|
-
export declare const reportedPostsConnector: (db: import("../db").PgDb, from: ReportWithMeta, to: PostWithMeta, data?: {
|
|
16
|
+
export declare const reportedPostsConnector: (db: import("../db").PgDb, from: ReportWithMeta, to: PostWithMeta, data?: object & {
|
|
17
17
|
id?: string;
|
|
18
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
18
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
19
19
|
_from: string;
|
|
20
20
|
_to: string;
|
|
21
21
|
}>>;
|
package/dist/roles/index.d.ts
CHANGED
package/dist/roles/index.js
CHANGED
package/dist/roles/mapping.d.ts
CHANGED
package/dist/roles/mutations.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { currentRoleDefaults, defaultRoles, findRoleDefaultsVersion, } from '@openpeepshq/common/types';
|
|
2
|
+
import { capabilitySetsEqual } from '@openpeepshq/common/lib';
|
|
3
|
+
import { findRole, findRoleByKey } from './finders.js';
|
|
3
4
|
import { allpeepDb } from '../db/index.js';
|
|
4
5
|
import { conflict } from '../errors/index.js';
|
|
5
6
|
import { rolesMapping } from './mapping.js';
|
|
@@ -14,8 +15,73 @@ export const createRole = (roleData) => allpeepDb().then(async ({ db }) => {
|
|
|
14
15
|
}
|
|
15
16
|
return rolesMapping.create(db, roleData);
|
|
16
17
|
});
|
|
18
|
+
const capabilitiesMatchFactory = (capabilities, factoryRole) => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
return capabilitySetsEqual(capabilities === null || capabilities === void 0 ? void 0 : capabilities.add, (_a = factoryRole.capabilities) === null || _a === void 0 ? void 0 : _a.add) &&
|
|
21
|
+
capabilitySetsEqual(capabilities === null || capabilities === void 0 ? void 0 : capabilities.remove, (_b = factoryRole.capabilities) === null || _b === void 0 ? void 0 : _b.remove);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Effective default flag for a write: an explicit `true` wins, and
|
|
25
|
+
* capabilities that exactly match the system defaults re-adopt the role as a
|
|
26
|
+
* default role even when the stored flag says otherwise — so future system
|
|
27
|
+
* default updates flow into it. Such an adoption also re-anchors the role to
|
|
28
|
+
* the current defaults version when the write does not set one explicitly.
|
|
29
|
+
*/
|
|
30
|
+
const withDefaultAdoption = (existingRole, roleData) => {
|
|
31
|
+
var _a;
|
|
32
|
+
const factoryRole = defaultRoles.find((role) => { var _a; return role.key === ((_a = roleData.key) !== null && _a !== void 0 ? _a : existingRole === null || existingRole === void 0 ? void 0 : existingRole.key); });
|
|
33
|
+
if (!factoryRole)
|
|
34
|
+
return roleData;
|
|
35
|
+
const matchesFactory = capabilitiesMatchFactory((_a = roleData.capabilities) !== null && _a !== void 0 ? _a : existingRole === null || existingRole === void 0 ? void 0 : existingRole.capabilities, factoryRole);
|
|
36
|
+
const isDefault = roleData.default === true || matchesFactory;
|
|
37
|
+
return Object.assign(Object.assign(Object.assign({}, roleData), { default: isDefault }), (matchesFactory && roleData.baseVersion === undefined
|
|
38
|
+
? { baseVersion: currentRoleDefaults.version }
|
|
39
|
+
: {}));
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Applies the base→current delta of the system defaults to a capability
|
|
43
|
+
* list: capabilities the defaults gained are added, capabilities the
|
|
44
|
+
* defaults dropped are removed, everything else is kept.
|
|
45
|
+
*/
|
|
46
|
+
const applyCapabilityDelta = (capabilities, base, current) => {
|
|
47
|
+
const delta = (list, from, to) => {
|
|
48
|
+
const removed = (from !== null && from !== void 0 ? from : []).filter((c) => !(to !== null && to !== void 0 ? to : []).includes(c));
|
|
49
|
+
const added = (to !== null && to !== void 0 ? to : []).filter((c) => !(from !== null && from !== void 0 ? from : []).includes(c));
|
|
50
|
+
return [
|
|
51
|
+
...(list !== null && list !== void 0 ? list : []).filter((c) => !removed.includes(c)),
|
|
52
|
+
...added.filter((c) => !(list !== null && list !== void 0 ? list : []).includes(c)),
|
|
53
|
+
];
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
add: delta(capabilities === null || capabilities === void 0 ? void 0 : capabilities.add, base === null || base === void 0 ? void 0 : base.add, current === null || current === void 0 ? void 0 : current.add),
|
|
57
|
+
remove: delta(capabilities === null || capabilities === void 0 ? void 0 : capabilities.remove, base === null || base === void 0 ? void 0 : base.remove, current === null || current === void 0 ? void 0 : current.remove),
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Rebase patch for a customized built-in role anchored at an older defaults
|
|
62
|
+
* version, or null when nothing changed. The set delta is transitive, so a
|
|
63
|
+
* stale anchor still rebases correctly when intermediate versions left this
|
|
64
|
+
* role untouched — the anchor only moves when capabilities actually change.
|
|
65
|
+
*/
|
|
66
|
+
const rebaseRoleToCurrentDefaults = (existingRole, factoryRole) => {
|
|
67
|
+
var _a, _b, _c;
|
|
68
|
+
const baseVersion = existingRole.baseVersion;
|
|
69
|
+
if (!baseVersion || baseVersion === currentRoleDefaults.version) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const baseRole = (_a = findRoleDefaultsVersion(baseVersion)) === null || _a === void 0 ? void 0 : _a.roles.find((role) => role.key === factoryRole.key);
|
|
73
|
+
if (!baseRole)
|
|
74
|
+
return null;
|
|
75
|
+
const capabilities = applyCapabilityDelta(existingRole.capabilities, baseRole.capabilities, factoryRole.capabilities);
|
|
76
|
+
const unchanged = capabilitySetsEqual((_b = existingRole.capabilities) === null || _b === void 0 ? void 0 : _b.add, capabilities.add) &&
|
|
77
|
+
capabilitySetsEqual((_c = existingRole.capabilities) === null || _c === void 0 ? void 0 : _c.remove, capabilities.remove);
|
|
78
|
+
if (unchanged)
|
|
79
|
+
return null;
|
|
80
|
+
return { capabilities, baseVersion: currentRoleDefaults.version };
|
|
81
|
+
};
|
|
17
82
|
export const updateRole = (id, roleData) => allpeepDb().then(async ({ db }) => {
|
|
18
|
-
const
|
|
83
|
+
const existingRole = await findRole(id);
|
|
84
|
+
const role = await rolesMapping.update(db, id, withDefaultAdoption(existingRole, roleData));
|
|
19
85
|
await profilesCache.clear();
|
|
20
86
|
return role;
|
|
21
87
|
});
|
|
@@ -25,8 +91,25 @@ export const setDefaultRoles = async () => {
|
|
|
25
91
|
if (!existingRole) {
|
|
26
92
|
await createRole(role);
|
|
27
93
|
}
|
|
94
|
+
else if (capabilitiesMatchFactory(existingRole.capabilities, role)) {
|
|
95
|
+
if (!existingRole.default) {
|
|
96
|
+
// Re-adopt roles that are exactly at the system defaults: only the
|
|
97
|
+
// flag and baseVersion are written, so the name and description are
|
|
98
|
+
// preserved.
|
|
99
|
+
await updateRole(existingRole.id, { default: true });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
28
102
|
else if (existingRole.default) {
|
|
103
|
+
// Default-flagged roles are system-managed: keep them in sync with the
|
|
104
|
+
// current factory so newly introduced capabilities reach them.
|
|
29
105
|
await updateRole(existingRole.id, role);
|
|
30
106
|
}
|
|
107
|
+
else {
|
|
108
|
+
// Customized built-in roles keep their edits; only merge in what the
|
|
109
|
+
// system defaults gained since their baseVersion.
|
|
110
|
+
const rebased = rebaseRoleToCurrentDefaults(existingRole, role);
|
|
111
|
+
if (rebased)
|
|
112
|
+
await updateRole(existingRole.id, rebased);
|
|
113
|
+
}
|
|
31
114
|
}
|
|
32
115
|
};
|
package/dist/search/mapping.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare const groupSearchMapping: (profile: ProfileWithMeta, query: strin
|
|
|
22
22
|
};
|
|
23
23
|
score: number;
|
|
24
24
|
}>;
|
|
25
|
-
export declare const profileSearchMapping: (
|
|
25
|
+
export declare const profileSearchMapping: (profile: ProfileWithMeta, query: string) => import("../db/pg/map").PgQueryResult<{
|
|
26
26
|
data: ProfileWithMeta;
|
|
27
27
|
score: number;
|
|
28
28
|
}>;
|
package/dist/search/mapping.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
import { blockedPairIds } from '@openpeepshq/common/lib';
|
|
1
2
|
import { groupsMapping } from '../groups/index.js';
|
|
2
3
|
import { canSeeGroupFilter } from '../groups/helpers.js';
|
|
3
4
|
import { publicProfilesSearchMapping } from '../profiles/mapping.js';
|
|
4
5
|
import { baseListPosts } from '../posts/finders.js';
|
|
5
|
-
import { postFilters } from '../db/pg/filters/index.js';
|
|
6
|
+
import { postFilters, profileFilters } from '../db/pg/filters/index.js';
|
|
6
7
|
export const groupSearchMapping = (profile, query) => groupsMapping.filter(canSeeGroupFilter(profile)).fulltextSearch({
|
|
7
8
|
view: 'groupSearch',
|
|
8
9
|
analyzer: 'text_en',
|
|
9
10
|
fields: ['handle', 'displayName', 'description', 'rules'],
|
|
10
11
|
query,
|
|
11
12
|
});
|
|
12
|
-
export const profileSearchMapping = (
|
|
13
|
+
export const profileSearchMapping = (profile, query) => publicProfilesSearchMapping
|
|
14
|
+
.filter(profileFilters.notGuest())
|
|
15
|
+
.filter(profileFilters.notIdIn(blockedPairIds(profile)))
|
|
16
|
+
.fulltextSearch({
|
|
13
17
|
view: 'profileSearch',
|
|
14
18
|
analyzer: 'text_en',
|
|
15
19
|
fields: ['handle', 'displayName', 'bio', 'location.text', 'fields.value'],
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { SERVER_INFO_BUCKET_MS, roundDownUptimeSeconds, stablePublicServerInfo, } from './stablePublicServerInfo';
|
|
1
2
|
export type DurationType = 'yesterday' | 'today' | 'last7Days' | 'last30Days' | 'last90Days';
|
|
2
3
|
/** Infer http vs https for absolute URLs (OIDC redirects, emails, media). */
|
|
3
4
|
export declare const protocolForServerHost: (host: string, envProtocol?: string | undefined) => "http" | "https";
|
|
@@ -7,10 +8,17 @@ export declare const serverInfo: () => Promise<{
|
|
|
7
8
|
version: string;
|
|
8
9
|
environment: string;
|
|
9
10
|
publicContent: boolean;
|
|
11
|
+
startedAt: string;
|
|
12
|
+
uptimeSeconds: number;
|
|
13
|
+
disk: {
|
|
14
|
+
folderBytes: number;
|
|
15
|
+
freeBytes: number;
|
|
16
|
+
totalBytes: number;
|
|
17
|
+
} | null;
|
|
18
|
+
lastAccessed: string | null;
|
|
10
19
|
communityConfig: {
|
|
11
20
|
theme: {
|
|
12
21
|
base: string;
|
|
13
|
-
primaryHex: string;
|
|
14
22
|
light: {
|
|
15
23
|
primaryHex: string;
|
|
16
24
|
secondaryHex?: string | undefined;
|
|
@@ -37,6 +45,7 @@ export declare const serverInfo: () => Promise<{
|
|
|
37
45
|
};
|
|
38
46
|
icon?: string | undefined;
|
|
39
47
|
mobileIcon?: string | undefined;
|
|
48
|
+
primaryHex?: string | undefined;
|
|
40
49
|
logoFull?: string | undefined;
|
|
41
50
|
logoSmall?: string | undefined;
|
|
42
51
|
defaultProfileAvatar?: string | undefined;
|
|
@@ -61,6 +70,8 @@ export declare const serverInfo: () => Promise<{
|
|
|
61
70
|
settings: {
|
|
62
71
|
openRegistrations: boolean;
|
|
63
72
|
defaultLanguage?: string | undefined;
|
|
73
|
+
defaultTimeZone?: string | undefined;
|
|
74
|
+
defaultFeedFormat?: "threaded" | "linear" | undefined;
|
|
64
75
|
};
|
|
65
76
|
roles: {
|
|
66
77
|
onRegistration: {
|
|
@@ -103,11 +114,18 @@ export declare const serverInfo: () => Promise<{
|
|
|
103
114
|
};
|
|
104
115
|
};
|
|
105
116
|
};
|
|
117
|
+
build?: string | undefined;
|
|
106
118
|
maxProfiles?: number | undefined;
|
|
107
119
|
sso?: {
|
|
120
|
+
generic: {
|
|
121
|
+
id: string;
|
|
122
|
+
name: string;
|
|
123
|
+
loginLink: string;
|
|
124
|
+
}[];
|
|
108
125
|
oidc: {
|
|
109
126
|
id: string;
|
|
110
127
|
name: string;
|
|
111
128
|
}[];
|
|
129
|
+
onlySSO?: boolean | undefined;
|
|
112
130
|
} | undefined;
|
|
113
131
|
}>;
|
package/dist/server/index.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { publicSsoInfo, withLegacyThemeRoot } from '@openpeepshq/common/lib';
|
|
1
3
|
import { communityConfig, config } from '../config/index.js';
|
|
4
|
+
import { database } from '../db/index.js';
|
|
5
|
+
import { normalizeComputedDatetime } from '../db/pg/mappers.js';
|
|
6
|
+
import { postSeen } from '../db/pg/schema/index.js';
|
|
7
|
+
import { diskUsage, processStartedAt } from './status.js';
|
|
8
|
+
import { roundDownUptimeSeconds } from './stablePublicServerInfo.js';
|
|
9
|
+
export { SERVER_INFO_BUCKET_MS, roundDownUptimeSeconds, stablePublicServerInfo, } from './stablePublicServerInfo.js';
|
|
2
10
|
/** Infer http vs https for absolute URLs (OIDC redirects, emails, media). */
|
|
3
11
|
export const protocolForServerHost = (host, envProtocol = process.env.SERVER_PROTOCOL) => {
|
|
4
12
|
if (envProtocol === 'http' || envProtocol === 'https') {
|
|
@@ -18,14 +26,32 @@ export const protocolForServerHost = (host, envProtocol = process.env.SERVER_PRO
|
|
|
18
26
|
};
|
|
19
27
|
export const serverProtocol = async () => protocolForServerHost((await config()).server.host);
|
|
20
28
|
export const serverRootUrl = async () => `${await serverProtocol()}://${(await config()).server.host}`;
|
|
29
|
+
const lastAccessedFromPostViews = async () => {
|
|
30
|
+
var _a;
|
|
31
|
+
const db = await database();
|
|
32
|
+
const rows = await db
|
|
33
|
+
.select({ last: sql `max(${postSeen.createdAt})` })
|
|
34
|
+
.from(postSeen);
|
|
35
|
+
return normalizeComputedDatetime((_a = rows[0]) === null || _a === void 0 ? void 0 : _a.last);
|
|
36
|
+
};
|
|
21
37
|
export const serverInfo = () => config().then(async (coreConfig) => {
|
|
22
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
23
|
-
|
|
38
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
39
|
+
const [lastAccessed, disk, community] = await Promise.all([
|
|
40
|
+
lastAccessedFromPostViews(),
|
|
41
|
+
diskUsage(coreConfig.media.storage.params.path),
|
|
42
|
+
communityConfig(),
|
|
43
|
+
]);
|
|
44
|
+
return {
|
|
24
45
|
version: coreConfig.version,
|
|
46
|
+
build: ((_a = process.env.BUILD) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
|
|
25
47
|
environment: coreConfig.environment,
|
|
26
48
|
publicContent: coreConfig.server.publicContent,
|
|
49
|
+
startedAt: processStartedAt,
|
|
50
|
+
uptimeSeconds: roundDownUptimeSeconds(Math.floor(process.uptime())),
|
|
51
|
+
disk,
|
|
52
|
+
lastAccessed,
|
|
27
53
|
maxProfiles: coreConfig.server.maxProfiles || undefined,
|
|
28
|
-
communityConfig: Object.assign(Object.assign({},
|
|
54
|
+
communityConfig: Object.assign(Object.assign({}, community), { theme: withLegacyThemeRoot(community.theme), settings: Object.assign(Object.assign({}, community.settings), { openRegistrations: !!coreConfig.server.signUpsOpen }) }),
|
|
29
55
|
jams: {
|
|
30
56
|
livekit: {
|
|
31
57
|
url: coreConfig.jams.livekit.url,
|
|
@@ -39,26 +65,19 @@ export const serverInfo = () => config().then(async (coreConfig) => {
|
|
|
39
65
|
publicKey: coreConfig.vapid.publicKey,
|
|
40
66
|
},
|
|
41
67
|
sentryConfig: {
|
|
42
|
-
enabled: !!((
|
|
43
|
-
!!((
|
|
44
|
-
dsn: (
|
|
45
|
-
replayEnabled: !!((
|
|
46
|
-
!!((
|
|
68
|
+
enabled: !!((_c = (_b = coreConfig.services) === null || _b === void 0 ? void 0 : _b.sentry) === null || _c === void 0 ? void 0 : _c.enabled) &&
|
|
69
|
+
!!((_e = (_d = coreConfig.services) === null || _d === void 0 ? void 0 : _d.sentry) === null || _e === void 0 ? void 0 : _e.dsn),
|
|
70
|
+
dsn: (_g = (_f = coreConfig.services) === null || _f === void 0 ? void 0 : _f.sentry) === null || _g === void 0 ? void 0 : _g.dsn,
|
|
71
|
+
replayEnabled: !!((_j = (_h = coreConfig.services) === null || _h === void 0 ? void 0 : _h.sentry) === null || _j === void 0 ? void 0 : _j.replayEnabled) &&
|
|
72
|
+
!!((_l = (_k = coreConfig.services) === null || _k === void 0 ? void 0 : _k.sentry) === null || _l === void 0 ? void 0 : _l.dsn),
|
|
47
73
|
},
|
|
48
74
|
payments: {
|
|
49
75
|
stripe: {
|
|
50
76
|
paidMembership: {
|
|
51
|
-
enabled: !!((
|
|
77
|
+
enabled: !!((_p = (_o = (_m = coreConfig.payments) === null || _m === void 0 ? void 0 : _m.stripe) === null || _o === void 0 ? void 0 : _o.paidMembership) === null || _p === void 0 ? void 0 : _p.enabled),
|
|
52
78
|
},
|
|
53
79
|
},
|
|
54
80
|
},
|
|
55
|
-
sso: coreConfig.sso
|
|
56
|
-
|
|
57
|
-
oidc: coreConfig.sso.oidc.map((p) => ({
|
|
58
|
-
id: p.id,
|
|
59
|
-
name: p.name,
|
|
60
|
-
})),
|
|
61
|
-
}
|
|
62
|
-
: undefined,
|
|
63
|
-
});
|
|
81
|
+
sso: publicSsoInfo(coreConfig.sso),
|
|
82
|
+
};
|
|
64
83
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shipped RN clients remount auth when /server/info identity changes.
|
|
3
|
+
* Round volatile clocks down to the current 10-minute wall-clock bucket
|
|
4
|
+
* so successive JSON payloads stay deep-equal.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SERVER_INFO_BUCKET_MS: number;
|
|
7
|
+
export declare const roundDownTo: (value: number, step: number) => number;
|
|
8
|
+
export declare const serverInfoBucketStart: (now?: number) => number;
|
|
9
|
+
export declare const roundDownUptimeSeconds: (uptimeSeconds: number) => number;
|
|
10
|
+
export declare const createStableLoader: <T>(bucketMs?: number) => {
|
|
11
|
+
get: (load: () => Promise<T>, now?: number) => Promise<T>;
|
|
12
|
+
reset: () => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const stablePublicServerInfo: {
|
|
15
|
+
get: (load: () => Promise<unknown>, now?: number) => Promise<unknown>;
|
|
16
|
+
reset: () => void;
|
|
17
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shipped RN clients remount auth when /server/info identity changes.
|
|
3
|
+
* Round volatile clocks down to the current 10-minute wall-clock bucket
|
|
4
|
+
* so successive JSON payloads stay deep-equal.
|
|
5
|
+
*/
|
|
6
|
+
export const SERVER_INFO_BUCKET_MS = 10 * 60 * 1000;
|
|
7
|
+
export const roundDownTo = (value, step) => Math.floor(value / step) * step;
|
|
8
|
+
export const serverInfoBucketStart = (now = Date.now()) => roundDownTo(now, SERVER_INFO_BUCKET_MS);
|
|
9
|
+
export const roundDownUptimeSeconds = (uptimeSeconds) => roundDownTo(Math.max(0, uptimeSeconds), SERVER_INFO_BUCKET_MS / 1000);
|
|
10
|
+
export const createStableLoader = (bucketMs = SERVER_INFO_BUCKET_MS) => {
|
|
11
|
+
let snapshot = null;
|
|
12
|
+
let inflight = null;
|
|
13
|
+
const get = async (load, now = Date.now()) => {
|
|
14
|
+
const bucket = roundDownTo(now, bucketMs);
|
|
15
|
+
if (snapshot && snapshot.at === bucket) {
|
|
16
|
+
return snapshot.value;
|
|
17
|
+
}
|
|
18
|
+
if (inflight) {
|
|
19
|
+
return inflight;
|
|
20
|
+
}
|
|
21
|
+
inflight = load()
|
|
22
|
+
.then((value) => {
|
|
23
|
+
snapshot = { at: bucket, value };
|
|
24
|
+
return value;
|
|
25
|
+
})
|
|
26
|
+
.finally(() => {
|
|
27
|
+
inflight = null;
|
|
28
|
+
});
|
|
29
|
+
return inflight;
|
|
30
|
+
};
|
|
31
|
+
const reset = () => {
|
|
32
|
+
snapshot = null;
|
|
33
|
+
inflight = null;
|
|
34
|
+
};
|
|
35
|
+
return { get, reset };
|
|
36
|
+
};
|
|
37
|
+
export const stablePublicServerInfo = createStableLoader();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import type { HostResourceStats } from '@openpeepshq/common/types';
|
|
3
|
+
export declare const processStartedAt: string;
|
|
4
|
+
export type MediaDiskUsage = {
|
|
5
|
+
folderBytes: number;
|
|
6
|
+
totalBytes: number;
|
|
7
|
+
freeBytes: number;
|
|
8
|
+
};
|
|
9
|
+
/** Sum of regular files under dir. Skips unreadable entries. */
|
|
10
|
+
export declare const folderSize: (dir: string) => Promise<number>;
|
|
11
|
+
/** Media-folder byte size plus free space on that volume. Null if unreadable. */
|
|
12
|
+
export declare const diskUsage: (mediaPath: string) => Promise<MediaDiskUsage | null>;
|
|
13
|
+
export type CpuTimes = {
|
|
14
|
+
idle: number;
|
|
15
|
+
total: number;
|
|
16
|
+
};
|
|
17
|
+
export declare const cpuTimes: (cpus?: Array<{
|
|
18
|
+
times: os.CpuInfo["times"];
|
|
19
|
+
}>) => CpuTimes;
|
|
20
|
+
export declare const cpuUsedPercent: (previous: CpuTimes, next: CpuTimes) => number;
|
|
21
|
+
export declare const memoryUsage: (totalBytes?: number, freeBytes?: number) => {
|
|
22
|
+
usedBytes: number;
|
|
23
|
+
totalBytes: number;
|
|
24
|
+
} | null;
|
|
25
|
+
export declare const hostResources: (wait?: (ms: number) => Promise<void>) => Promise<HostResourceStats>;
|