@openpeepshq/core 0.1.32 → 0.1.33
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/analytics/cache.js +12 -7
- 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 +24 -11
- package/dist/analytics/report.d.ts +1 -1
- package/dist/analytics/report.js +9 -2
- package/dist/backups/index.js +6 -3
- package/dist/backups/metadata.d.ts +7 -0
- package/dist/config/defaults/community.js +0 -6
- package/dist/config/defaults/db.d.ts +0 -2
- package/dist/config/defaults/db.js +0 -2
- package/dist/config/index.d.ts +10 -9
- package/dist/db/helpers.d.ts +6 -28
- package/dist/db/helpers.js +19 -149
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.js +4 -0
- package/dist/db/init.js +3 -2
- package/dist/db/migration/detect.d.ts +0 -3
- package/dist/db/migration/detect.js +0 -54
- package/dist/db/migration/importCollections.d.ts +1 -1
- package/dist/db/migration/importCollections.js +22 -6
- package/dist/db/migration/shared.d.ts +0 -4
- package/dist/db/migration/shared.js +0 -7
- package/dist/db/migration/transform.d.ts +2 -0
- package/dist/db/migration/transform.js +23 -0
- package/dist/db/pg/client.js +4 -0
- 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 +1 -0
- package/dist/db/pg/filters/posts.js +11 -1
- package/dist/db/pg/map/filters.js +5 -0
- package/dist/db/pg/map/relations.d.ts +1 -1
- package/dist/db/pg/map/relations.js +89 -41
- package/dist/db/pg/migrate.d.ts +23 -0
- package/dist/db/pg/migrate.js +87 -1
- package/dist/db/pg/schema/documents.d.ts +143 -0
- package/dist/db/pg/schema/documents.js +22 -1
- package/dist/db/pg/schema/edges.d.ts +1 -0
- package/dist/db/pg/schema/edges.js +2 -1
- package/dist/db/pg/schema/index.d.ts +143 -0
- 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/meta/0007_snapshot.json +4179 -0
- package/dist/db/pg/sql/meta/0009_snapshot.json +4299 -0
- package/dist/db/pg/sql/meta/_journal.json +21 -0
- package/dist/db/replaceOrigin.js +6 -0
- package/dist/db/types.d.ts +0 -4
- package/dist/events/index.d.ts +2 -1
- package/dist/events/index.js +54 -33
- package/dist/groups/finders.d.ts +2 -2
- package/dist/groups/helpers.d.ts +6 -6
- package/dist/groups/mapping.d.ts +4 -4
- package/dist/groups/mapping.js +2 -2
- package/dist/groups/mutations.js +1 -1
- 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/finders.d.ts +2 -1
- package/dist/jams/finders.js +18 -7
- package/dist/jams/helpers.d.ts +4 -0
- package/dist/jams/index.d.ts +4 -3
- package/dist/jams/index.js +20 -13
- package/dist/jams/livekit.d.ts +46 -8
- package/dist/jams/livekit.js +103 -21
- package/dist/jams/mapping.d.ts +14 -4
- package/dist/jams/mutations.d.ts +2 -0
- package/dist/jams/rtmp.d.ts +5 -0
- package/dist/jams/rtmp.js +8 -0
- package/dist/jams/token.d.ts +3 -3
- package/dist/jams/token.js +15 -12
- package/dist/jams/waitingRoom.d.ts +6 -6
- package/dist/jams/waitingRoom.js +24 -23
- package/dist/migration/index.d.ts +4 -0
- package/dist/migration/index.js +4 -0
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
- package/dist/notifications/helpers.js +6 -2
- 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 +41 -4
- package/dist/plugins/install.d.ts +20 -0
- package/dist/plugins/install.js +223 -0
- package/dist/plugins/state.d.ts +4 -0
- package/dist/plugins/state.js +29 -0
- package/dist/posts/eventAgenda.d.ts +165 -0
- package/dist/posts/eventAgenda.js +120 -0
- package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
- package/dist/posts/eventOccurrenceJobs.js +23 -0
- package/dist/posts/eventOccurrences.d.ts +4 -0
- package/dist/posts/eventOccurrences.js +40 -0
- package/dist/posts/finders.d.ts +32 -8
- package/dist/posts/finders.js +27 -45
- package/dist/posts/helpers/filters.js +1 -1
- package/dist/posts/helpers/index.d.ts +102 -16
- package/dist/posts/helpers/index.js +33 -20
- package/dist/posts/index.d.ts +3 -0
- package/dist/posts/index.js +3 -0
- package/dist/posts/mapping.d.ts +275 -0
- package/dist/posts/mapping.js +37 -3
- package/dist/posts/mutations.d.ts +1 -1
- package/dist/posts/mutations.js +29 -18
- package/dist/posts/rsvpConfirmationEmail.js +2 -1
- package/dist/posts/unseenCounts.d.ts +2 -0
- package/dist/posts/unseenCounts.js +25 -8
- package/dist/profiles/cache.d.ts +3 -1
- package/dist/profiles/cache.js +9 -1
- package/dist/profiles/helpers.d.ts +5 -5
- package/dist/profiles/index.d.ts +1 -1
- package/dist/profiles/index.js +1 -1
- package/dist/profiles/mapping.d.ts +5 -5
- package/dist/profiles/mutations.js +12 -14
- package/dist/pushSubscriptions/helpers.d.ts +2 -2
- package/dist/pushSubscriptions/mutations.js +13 -1
- package/dist/reports/helpers.d.ts +6 -6
- package/dist/roles/defaults.js +1 -0
- package/dist/server/index.d.ts +7 -7
- package/dist/server/index.js +15 -8
- package/dist/stats/finders.d.ts +1692 -142
- package/dist/stats/mapping.d.ts +21 -0
- package/package.json +4 -9
- 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/exportArango.d.ts +0 -4
- package/dist/db/migration/exportArango.js +0 -80
package/dist/posts/mutations.js
CHANGED
|
@@ -7,9 +7,10 @@ import { postsMapping, repostRelation } from './mapping.js';
|
|
|
7
7
|
import { findGroup } from '../groups/finders.js';
|
|
8
8
|
import { findOrCreateHashtag } from '../hashtags/index.js';
|
|
9
9
|
import { hub } from '../events/index.js';
|
|
10
|
-
import {
|
|
11
|
-
import { canManageEventRsvps, countYesRsvps, eventDataForDbUpdate, getEffectiveRsvp, normalizeEventDataForSave, passThroughUndefined, } from '@openpeepshq/common/lib';
|
|
10
|
+
import { listUnseenGroupPostIds } from './unseenCounts.js';
|
|
11
|
+
import { canManageEventRsvps, countYesRsvps, eventDataForDbUpdate, getEffectiveRsvp, normalizeEventDataForSave, passThroughUndefined, sameRecurrenceId, } from '@openpeepshq/common/lib';
|
|
12
12
|
import { forbidden, unprocessableRequest } from '../errors/index.js';
|
|
13
|
+
import { rebuildEventOccurrences, clearEventOccurrences, } from './eventOccurrences.js';
|
|
13
14
|
export const createPost = async (data, profile, postData, relations = {}) => {
|
|
14
15
|
var _a;
|
|
15
16
|
if (data.type === 'event') {
|
|
@@ -67,6 +68,9 @@ export const createPost = async (data, profile, postData, relations = {}) => {
|
|
|
67
68
|
}
|
|
68
69
|
const newPost = await postsMapping.find(db, post.id);
|
|
69
70
|
const transformedPost = await transformPost(newPost);
|
|
71
|
+
if (data.type === 'event') {
|
|
72
|
+
await rebuildEventOccurrences(transformedPost.id, data);
|
|
73
|
+
}
|
|
70
74
|
hub.emit('postCreated', transformedPost);
|
|
71
75
|
return transformedPost;
|
|
72
76
|
};
|
|
@@ -94,6 +98,9 @@ export const updatePost = async (post, profile, data) => {
|
|
|
94
98
|
const newPost = await postsMapping
|
|
95
99
|
.find(db, post.id)
|
|
96
100
|
.then(passThroughUndefined(transformPost));
|
|
101
|
+
if (normalized.type === 'event') {
|
|
102
|
+
await rebuildEventOccurrences(post.id, normalized);
|
|
103
|
+
}
|
|
97
104
|
hub.emit('postUpdated', newPost);
|
|
98
105
|
return newPost;
|
|
99
106
|
};
|
|
@@ -106,30 +113,23 @@ export const markPostsSeen = async (posts, profile) => {
|
|
|
106
113
|
return;
|
|
107
114
|
const { db } = await allpeepDb();
|
|
108
115
|
const ts = nowIso();
|
|
109
|
-
await db
|
|
110
|
-
.insert(postSeen)
|
|
111
|
-
.values(posts.map((post) => ({
|
|
116
|
+
await db.insert(postSeen).values(posts.map((post) => ({
|
|
112
117
|
id: uuidv7(),
|
|
113
118
|
fromId: profile.id,
|
|
114
119
|
toId: post.id,
|
|
115
120
|
body: {},
|
|
116
121
|
createdAt: ts,
|
|
117
122
|
updatedAt: ts,
|
|
118
|
-
})))
|
|
119
|
-
.onConflictDoNothing({
|
|
120
|
-
target: [postSeen.fromId, postSeen.toId],
|
|
121
|
-
});
|
|
123
|
+
})));
|
|
122
124
|
};
|
|
123
125
|
export const markGroupPostsSeen = async (authData, groupId) => {
|
|
124
126
|
if (!authData.profile) {
|
|
125
127
|
throw new Error('Profile required');
|
|
126
128
|
}
|
|
127
129
|
const profile = authData.profile;
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
await markPostsSeen(unseen, profile);
|
|
132
|
-
}
|
|
130
|
+
const { db } = await allpeepDb();
|
|
131
|
+
const unseenIds = await listUnseenGroupPostIds(db, profile.id, groupId);
|
|
132
|
+
await markPostsSeen(unseenIds.map((id) => ({ id })), profile);
|
|
133
133
|
};
|
|
134
134
|
export const deletePost = async (post, profile) => {
|
|
135
135
|
const { db } = await allpeepDb();
|
|
@@ -144,6 +144,9 @@ export const deletePost = async (post, profile) => {
|
|
|
144
144
|
}));
|
|
145
145
|
await postsMapping.deleteRelations(db, post.id, Object.assign(Object.assign({}, repostRelation), { direction: 'INBOUND' }));
|
|
146
146
|
await postsMapping.delete(db, post.id);
|
|
147
|
+
if (post.type === 'event') {
|
|
148
|
+
await clearEventOccurrences(post.id);
|
|
149
|
+
}
|
|
147
150
|
return postsMapping.find(db, post.id);
|
|
148
151
|
};
|
|
149
152
|
export const vote = (profile, post, data) => allpeepDb().then(({ db }) => entryConnector(db, profile, post, {
|
|
@@ -175,9 +178,9 @@ export const rsvpRespond = async (profile, post, data) => {
|
|
|
175
178
|
});
|
|
176
179
|
}
|
|
177
180
|
if (data.response === 'yes') {
|
|
178
|
-
const currentRsvp = getEffectiveRsvp(post, profile.id);
|
|
181
|
+
const currentRsvp = getEffectiveRsvp(post, profile.id, data.recurrenceId);
|
|
179
182
|
if ((currentRsvp === null || currentRsvp === void 0 ? void 0 : currentRsvp.response) !== 'yes' &&
|
|
180
|
-
countYesRsvps(post) >= maxAttendees) {
|
|
183
|
+
countYesRsvps(post, data.recurrenceId) >= maxAttendees) {
|
|
181
184
|
throw unprocessableRequest({ errorKey: 'error.eventAtCapacity' });
|
|
182
185
|
}
|
|
183
186
|
}
|
|
@@ -185,6 +188,10 @@ export const rsvpRespond = async (profile, post, data) => {
|
|
|
185
188
|
const { db } = await allpeepDb();
|
|
186
189
|
const previousResponse = (_d = [...((_c = post.rsvps) !== null && _c !== void 0 ? _c : [])]
|
|
187
190
|
.filter((rsvp) => rsvp.profile.id === profile.id)
|
|
191
|
+
.filter((rsvp) => data.recurrenceId
|
|
192
|
+
? sameRecurrenceId(rsvp.recurrenceId, data.recurrenceId) ||
|
|
193
|
+
!rsvp.recurrenceId
|
|
194
|
+
: !rsvp.recurrenceId)
|
|
188
195
|
.sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))[0]) === null || _d === void 0 ? void 0 : _d.response;
|
|
189
196
|
await entryConnector(db, profile, post, {
|
|
190
197
|
type: 'rsvp',
|
|
@@ -196,7 +203,7 @@ export const rsvpRespond = async (profile, post, data) => {
|
|
|
196
203
|
previousResponse,
|
|
197
204
|
});
|
|
198
205
|
};
|
|
199
|
-
export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post, response) => {
|
|
206
|
+
export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post, response, recurrenceId) => {
|
|
200
207
|
var _a, _b;
|
|
201
208
|
if (!canManageEventRsvps(actingProfile, post)) {
|
|
202
209
|
throw forbidden({ errorKey: 'forbidden' });
|
|
@@ -207,10 +214,14 @@ export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post,
|
|
|
207
214
|
if (post.type !== 'event') {
|
|
208
215
|
throw unprocessableRequest({ errorKey: 'error.unprocessableRequest' });
|
|
209
216
|
}
|
|
210
|
-
const data = { response };
|
|
217
|
+
const data = { response, recurrenceId };
|
|
211
218
|
const { db } = await allpeepDb();
|
|
212
219
|
const previousResponse = (_b = [...((_a = post.rsvps) !== null && _a !== void 0 ? _a : [])]
|
|
213
220
|
.filter((rsvp) => rsvp.profile.id === targetProfile.id)
|
|
221
|
+
.filter((rsvp) => recurrenceId
|
|
222
|
+
? sameRecurrenceId(rsvp.recurrenceId, recurrenceId) ||
|
|
223
|
+
!rsvp.recurrenceId
|
|
224
|
+
: !rsvp.recurrenceId)
|
|
214
225
|
.sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))[0]) === null || _b === void 0 ? void 0 : _b.response;
|
|
215
226
|
await entryConnector(db, targetProfile, post, {
|
|
216
227
|
type: 'rsvp',
|
|
@@ -13,7 +13,7 @@ const attendingResponses = ['yes', 'tentative'];
|
|
|
13
13
|
* avoid re-sending when someone toggles between yes/maybe.
|
|
14
14
|
*/
|
|
15
15
|
const handleRsvpCreated = async (profileArg, postArg, payloadArg) => {
|
|
16
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
16
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
17
17
|
const profile = profileArg;
|
|
18
18
|
const post = postArg;
|
|
19
19
|
const payload = payloadArg;
|
|
@@ -59,6 +59,7 @@ const handleRsvpCreated = async (profileArg, postArg, payloadArg) => {
|
|
|
59
59
|
end: (_d = event.end) !== null && _d !== void 0 ? _d : null,
|
|
60
60
|
location: (_f = (_e = event.physicalLocation) === null || _e === void 0 ? void 0 : _e.text) !== null && _f !== void 0 ? _f : null,
|
|
61
61
|
allDay: (_g = event.wholeDay) !== null && _g !== void 0 ? _g : false,
|
|
62
|
+
timeZone: (_h = event.timeZone) !== null && _h !== void 0 ? _h : null,
|
|
62
63
|
},
|
|
63
64
|
attachments: [
|
|
64
65
|
{
|
|
@@ -2,6 +2,8 @@ import type { UnseenPostCounts } from '@openpeepshq/common/types';
|
|
|
2
2
|
import type { PgDb } from '../db/pg/client';
|
|
3
3
|
/** Group unseen counts via anti-join (no post hydration). */
|
|
4
4
|
export declare const countUnseenGroupPosts: (db: PgDb, profileId: string, groupIds: string[]) => Promise<Record<string, number>>;
|
|
5
|
+
/** Same posts as {@link countUnseenGroupPosts} for one group (mark-all-read). */
|
|
6
|
+
export declare const listUnseenGroupPostIds: (db: PgDb, profileId: string, groupId: string) => Promise<string[]>;
|
|
5
7
|
/**
|
|
6
8
|
* Direct-message unread counts keyed by conversation root.
|
|
7
9
|
* Walks reply_to to roots without hydrating posts.
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { sql } from 'drizzle-orm';
|
|
2
|
+
/** Shared predicates for group unseen count and mark-all-read. */
|
|
3
|
+
const unseenGroupPostMatch = (profileId) => sql `
|
|
4
|
+
p.visibility <> 'direct'
|
|
5
|
+
AND p.creator_id <> ${profileId}
|
|
6
|
+
AND NOT EXISTS (
|
|
7
|
+
SELECT 1
|
|
8
|
+
FROM post_seen ps
|
|
9
|
+
WHERE ps.from_id = ${profileId}
|
|
10
|
+
AND ps.to_id = p.id::text
|
|
11
|
+
)
|
|
12
|
+
`;
|
|
2
13
|
/** Group unseen counts via anti-join (no post hydration). */
|
|
3
14
|
export const countUnseenGroupPosts = async (db, profileId, groupIds) => {
|
|
4
15
|
const counts = Object.fromEntries(groupIds.map((groupId) => [groupId, 0]));
|
|
@@ -11,14 +22,7 @@ export const countUnseenGroupPosts = async (db, profileId, groupIds) => {
|
|
|
11
22
|
ON p.id::text = pg.from_id
|
|
12
23
|
AND p.deleted_at IS NULL
|
|
13
24
|
WHERE pg.to_id IN (${sql.join(groupIds.map((id) => sql `${id}`), sql `, `)})
|
|
14
|
-
AND
|
|
15
|
-
AND p.creator_id <> ${profileId}
|
|
16
|
-
AND NOT EXISTS (
|
|
17
|
-
SELECT 1
|
|
18
|
-
FROM post_seen ps
|
|
19
|
-
WHERE ps.from_id = ${profileId}
|
|
20
|
-
AND ps.to_id = p.id::text
|
|
21
|
-
)
|
|
25
|
+
AND ${unseenGroupPostMatch(profileId)}
|
|
22
26
|
GROUP BY pg.to_id
|
|
23
27
|
`));
|
|
24
28
|
for (const row of result.rows) {
|
|
@@ -29,6 +33,19 @@ export const countUnseenGroupPosts = async (db, profileId, groupIds) => {
|
|
|
29
33
|
}
|
|
30
34
|
return counts;
|
|
31
35
|
};
|
|
36
|
+
/** Same posts as {@link countUnseenGroupPosts} for one group (mark-all-read). */
|
|
37
|
+
export const listUnseenGroupPostIds = async (db, profileId, groupId) => {
|
|
38
|
+
const result = (await db.execute(sql `
|
|
39
|
+
SELECT p.id::text AS post_id
|
|
40
|
+
FROM post_groups pg
|
|
41
|
+
INNER JOIN posts p
|
|
42
|
+
ON p.id::text = pg.from_id
|
|
43
|
+
AND p.deleted_at IS NULL
|
|
44
|
+
WHERE pg.to_id = ${groupId}
|
|
45
|
+
AND ${unseenGroupPostMatch(profileId)}
|
|
46
|
+
`));
|
|
47
|
+
return result.rows.map((row) => row.post_id).filter((id) => !!id);
|
|
48
|
+
};
|
|
32
49
|
/**
|
|
33
50
|
* Direct-message unread counts keyed by conversation root.
|
|
34
51
|
* Walks reply_to to roots without hydrating posts.
|
package/dist/profiles/cache.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { ProfileWithMeta } from '@openpeepshq/common/types';
|
|
1
|
+
import { Profile, ProfileWithMeta } from '@openpeepshq/common/types';
|
|
2
2
|
export declare const profilesCache: import("cache-manager").Cache;
|
|
3
|
+
export declare const publicProfilesCache: import("cache-manager").Cache;
|
|
4
|
+
export declare const clearProfileCache: (profile: Pick<Profile, "id" | "handle">) => Promise<void>;
|
|
3
5
|
export declare const getProfile: (id: string, ignoreSoftDelete?: boolean) => Promise<ProfileWithMeta | undefined>;
|
|
4
6
|
/** Lean profile for post/feed hydrate — no followers/following trees. */
|
|
5
7
|
export declare const getPublicProfile: (id: string, ignoreSoftDelete?: boolean) => Promise<ProfileWithMeta | undefined>;
|
package/dist/profiles/cache.js
CHANGED
|
@@ -5,10 +5,18 @@ export const profilesCache = createCache({
|
|
|
5
5
|
ttl: 60 * 60 * 1000,
|
|
6
6
|
refreshThreshold: 60 * 1000,
|
|
7
7
|
});
|
|
8
|
-
const publicProfilesCache = createCache({
|
|
8
|
+
export const publicProfilesCache = createCache({
|
|
9
9
|
ttl: 60 * 60 * 1000,
|
|
10
10
|
refreshThreshold: 60 * 1000,
|
|
11
11
|
});
|
|
12
|
+
export const clearProfileCache = async (profile) => {
|
|
13
|
+
await Promise.all([
|
|
14
|
+
profilesCache.del(profile.id),
|
|
15
|
+
profilesCache.del(profile.handle),
|
|
16
|
+
publicProfilesCache.del(profile.id),
|
|
17
|
+
publicProfilesCache.del(`all:${profile.id}`),
|
|
18
|
+
]);
|
|
19
|
+
};
|
|
12
20
|
const withEmptyFollowGraphs = (profile) => {
|
|
13
21
|
var _a, _b, _c, _d;
|
|
14
22
|
return (Object.assign(Object.assign({}, profile), { roles: (_a = profile.roles) !== null && _a !== void 0 ? _a : [], followers: [], following: [], controllers: (_b = profile.controllers) !== null && _b !== void 0 ? _b : [], memberships: (_c = profile.memberships) !== null && _c !== void 0 ? _c : [], profileStats: (_d = profile.profileStats) !== null && _d !== void 0 ? _d : {
|
|
@@ -14,11 +14,11 @@ export declare const followConnector: (db: import("../db").PgDb, from: Profile,
|
|
|
14
14
|
_to: string;
|
|
15
15
|
}>>;
|
|
16
16
|
export declare const followDisconnector: (db: import("../db").PgDb, from: Profile, to: Profile) => Promise<void>;
|
|
17
|
-
export declare const followFinder: (db: import("../db").PgDb, from: Profile, to: Profile) => Promise<
|
|
17
|
+
export declare const followFinder: (db: import("../db").PgDb, from: Profile, to: Profile) => Promise<Record<string, unknown> | undefined>;
|
|
18
18
|
export declare const expandProfiles: (profiles: Profile[]) => Promise<ProfileWithMeta[]>;
|
|
19
|
-
export declare const roleAssigner: (db: import("../db").PgDb, from: Profile, to: Role, data?: {
|
|
19
|
+
export declare const roleAssigner: (db: import("../db").PgDb, from: Profile, to: Role, data?: object & {
|
|
20
20
|
id?: string;
|
|
21
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
21
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
22
22
|
_from: string;
|
|
23
23
|
_to: string;
|
|
24
24
|
}>>;
|
|
@@ -27,9 +27,9 @@ export declare const giveControl: (db: import("../db").PgDb, from: {
|
|
|
27
27
|
id: string;
|
|
28
28
|
}, to: {
|
|
29
29
|
id: string;
|
|
30
|
-
}, data?: {
|
|
30
|
+
}, data?: object & {
|
|
31
31
|
id?: string;
|
|
32
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
32
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
33
33
|
_from: string;
|
|
34
34
|
_to: string;
|
|
35
35
|
}>>;
|
package/dist/profiles/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export * from './mapping';
|
|
|
2
2
|
export * from './mutations';
|
|
3
3
|
export * from './finders';
|
|
4
4
|
export * from './export';
|
|
5
|
-
export { getProfile, getPublicProfile, getProfiles } from './cache';
|
|
5
|
+
export { getProfile, getPublicProfile, getProfiles, clearProfileCache, } from './cache';
|
|
6
6
|
export declare const findNewFreeHandle: (seed: string) => Promise<string>;
|
package/dist/profiles/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export * from './mapping.js';
|
|
|
3
3
|
export * from './mutations.js';
|
|
4
4
|
export * from './finders.js';
|
|
5
5
|
export * from './export.js';
|
|
6
|
-
export { getProfile, getPublicProfile, getProfiles } from './cache.js';
|
|
6
|
+
export { getProfile, getPublicProfile, getProfiles, clearProfileCache, } from './cache.js';
|
|
7
7
|
const sanitizeHandle = (name) => name.replace(/[^a-zA-Z0-9]/g, '-');
|
|
8
8
|
export const findNewFreeHandle = async (seed) => {
|
|
9
9
|
let counter = 2;
|
|
@@ -35,7 +35,7 @@ export declare const baseProfilesMapping: import("../db/pg/map").Mapping<{
|
|
|
35
35
|
guestData?: {
|
|
36
36
|
email?: string | undefined;
|
|
37
37
|
resource?: {
|
|
38
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "
|
|
38
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "webhooks" | "analytics" | "render";
|
|
39
39
|
id?: string | undefined;
|
|
40
40
|
} | undefined;
|
|
41
41
|
} | undefined;
|
|
@@ -73,7 +73,7 @@ export declare const publicProfilesSearchMapping: import("../db/pg/map").Mapping
|
|
|
73
73
|
guestData?: {
|
|
74
74
|
email?: string | undefined;
|
|
75
75
|
resource?: {
|
|
76
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "
|
|
76
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "webhooks" | "analytics" | "render";
|
|
77
77
|
id?: string | undefined;
|
|
78
78
|
} | undefined;
|
|
79
79
|
} | undefined;
|
|
@@ -114,7 +114,7 @@ export declare const publicProfilesMapping: import("../db/pg/map").Mapping<{
|
|
|
114
114
|
guestData?: {
|
|
115
115
|
email?: string | undefined;
|
|
116
116
|
resource?: {
|
|
117
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "
|
|
117
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "webhooks" | "analytics" | "render";
|
|
118
118
|
id?: string | undefined;
|
|
119
119
|
} | undefined;
|
|
120
120
|
} | undefined;
|
|
@@ -151,7 +151,7 @@ export declare const profilesMapping: import("../db/pg/map").Mapping<{
|
|
|
151
151
|
guestData?: {
|
|
152
152
|
email?: string | undefined;
|
|
153
153
|
resource?: {
|
|
154
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "
|
|
154
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "webhooks" | "analytics" | "render";
|
|
155
155
|
id?: string | undefined;
|
|
156
156
|
} | undefined;
|
|
157
157
|
} | undefined;
|
|
@@ -188,7 +188,7 @@ export declare const membersExportMapping: import("../db/pg/map").Mapping<{
|
|
|
188
188
|
guestData?: {
|
|
189
189
|
email?: string | undefined;
|
|
190
190
|
resource?: {
|
|
191
|
-
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "
|
|
191
|
+
type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "jams" | "*" | "webhooks" | "analytics" | "render";
|
|
192
192
|
id?: string | undefined;
|
|
193
193
|
} | undefined;
|
|
194
194
|
} | undefined;
|
|
@@ -4,7 +4,7 @@ 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, clearProfileCache } from './cache.js';
|
|
8
8
|
import { accountsCache } from '../accounts/cache.js';
|
|
9
9
|
import { assertProfileCapacity } from './capacity.js';
|
|
10
10
|
export const createProfile = async (data, controllingAccount) => {
|
|
@@ -54,19 +54,17 @@ export const deleteProfile = async (profileId) => {
|
|
|
54
54
|
await deleteAccessTokensForProfile(db, profileId);
|
|
55
55
|
return profilesMapping.delete(db, profileId);
|
|
56
56
|
};
|
|
57
|
-
export const follow = async (follower, followed, followData) =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.
|
|
67
|
-
|
|
68
|
-
profilesCache.del(followed.id);
|
|
69
|
-
});
|
|
57
|
+
export const follow = async (follower, followed, followData) => {
|
|
58
|
+
const { db } = await allpeepDb();
|
|
59
|
+
await followConnector(db, follower, followed, followData);
|
|
60
|
+
await Promise.all([clearProfileCache(follower), clearProfileCache(followed)]);
|
|
61
|
+
await hub.emit('followCreated', follower, followed);
|
|
62
|
+
};
|
|
63
|
+
export const unfollow = async (follower, followed) => {
|
|
64
|
+
const { db } = await allpeepDb();
|
|
65
|
+
await followDisconnector(db, follower, followed);
|
|
66
|
+
await Promise.all([clearProfileCache(follower), clearProfileCache(followed)]);
|
|
67
|
+
};
|
|
70
68
|
export const assignRole = (profile, role) => allpeepDb()
|
|
71
69
|
.then(({ db }) => roleAssigner(db, profile, role))
|
|
72
70
|
.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,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/defaults.js
CHANGED
package/dist/server/index.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ export declare const serverInfo: () => Promise<{
|
|
|
7
7
|
version: string;
|
|
8
8
|
environment: string;
|
|
9
9
|
publicContent: boolean;
|
|
10
|
+
lastAccessed: string | null;
|
|
10
11
|
communityConfig: {
|
|
11
12
|
theme: {
|
|
12
13
|
base: string;
|
|
13
|
-
primaryHex: string;
|
|
14
14
|
light: {
|
|
15
15
|
primaryHex: string;
|
|
16
16
|
secondaryHex?: string | undefined;
|
|
@@ -37,12 +37,6 @@ export declare const serverInfo: () => Promise<{
|
|
|
37
37
|
};
|
|
38
38
|
icon?: string | undefined;
|
|
39
39
|
mobileIcon?: string | undefined;
|
|
40
|
-
logoFull?: string | undefined;
|
|
41
|
-
logoSmall?: string | undefined;
|
|
42
|
-
defaultProfileAvatar?: string | undefined;
|
|
43
|
-
defaultGroupAvatar?: string | undefined;
|
|
44
|
-
backgroundAuth?: string | undefined;
|
|
45
|
-
background?: string | undefined;
|
|
46
40
|
};
|
|
47
41
|
info: {
|
|
48
42
|
name: string;
|
|
@@ -105,9 +99,15 @@ export declare const serverInfo: () => Promise<{
|
|
|
105
99
|
};
|
|
106
100
|
maxProfiles?: number | undefined;
|
|
107
101
|
sso?: {
|
|
102
|
+
generic: {
|
|
103
|
+
id: string;
|
|
104
|
+
name: string;
|
|
105
|
+
loginLink: string;
|
|
106
|
+
}[];
|
|
108
107
|
oidc: {
|
|
109
108
|
id: string;
|
|
110
109
|
name: string;
|
|
111
110
|
}[];
|
|
111
|
+
onlySSO?: boolean | undefined;
|
|
112
112
|
} | undefined;
|
|
113
113
|
}>;
|
package/dist/server/index.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { publicSsoInfo } 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';
|
|
2
7
|
/** Infer http vs https for absolute URLs (OIDC redirects, emails, media). */
|
|
3
8
|
export const protocolForServerHost = (host, envProtocol = process.env.SERVER_PROTOCOL) => {
|
|
4
9
|
if (envProtocol === 'http' || envProtocol === 'https') {
|
|
@@ -18,12 +23,21 @@ export const protocolForServerHost = (host, envProtocol = process.env.SERVER_PRO
|
|
|
18
23
|
};
|
|
19
24
|
export const serverProtocol = async () => protocolForServerHost((await config()).server.host);
|
|
20
25
|
export const serverRootUrl = async () => `${await serverProtocol()}://${(await config()).server.host}`;
|
|
26
|
+
const lastAccessedFromPostViews = async () => {
|
|
27
|
+
var _a;
|
|
28
|
+
const db = await database();
|
|
29
|
+
const rows = await db
|
|
30
|
+
.select({ last: sql `max(${postSeen.createdAt})` })
|
|
31
|
+
.from(postSeen);
|
|
32
|
+
return normalizeComputedDatetime((_a = rows[0]) === null || _a === void 0 ? void 0 : _a.last);
|
|
33
|
+
};
|
|
21
34
|
export const serverInfo = () => config().then(async (coreConfig) => {
|
|
22
35
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
23
36
|
return ({
|
|
24
37
|
version: coreConfig.version,
|
|
25
38
|
environment: coreConfig.environment,
|
|
26
39
|
publicContent: coreConfig.server.publicContent,
|
|
40
|
+
lastAccessed: await lastAccessedFromPostViews(),
|
|
27
41
|
maxProfiles: coreConfig.server.maxProfiles || undefined,
|
|
28
42
|
communityConfig: Object.assign(Object.assign({}, (await communityConfig())), { settings: Object.assign(Object.assign({}, (await communityConfig()).settings), { openRegistrations: !!coreConfig.server.signUpsOpen }) }),
|
|
29
43
|
jams: {
|
|
@@ -52,13 +66,6 @@ export const serverInfo = () => config().then(async (coreConfig) => {
|
|
|
52
66
|
},
|
|
53
67
|
},
|
|
54
68
|
},
|
|
55
|
-
sso: coreConfig.sso
|
|
56
|
-
? {
|
|
57
|
-
oidc: coreConfig.sso.oidc.map((p) => ({
|
|
58
|
-
id: p.id,
|
|
59
|
-
name: p.name,
|
|
60
|
-
})),
|
|
61
|
-
}
|
|
62
|
-
: undefined,
|
|
69
|
+
sso: publicSsoInfo(coreConfig.sso),
|
|
63
70
|
});
|
|
64
71
|
});
|