@openpeepshq/core 0.26.0 → 0.28.0
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/db/pg/filters/posts.d.ts +4 -0
- package/dist/db/pg/filters/posts.js +5 -1
- package/dist/db/pg/map/filters.js +1 -0
- package/dist/db/pg/map/registry.js +7 -1
- package/dist/db/pg/queries/activity.js +23 -3
- package/dist/db/pg/queries/derived.js +2 -2
- package/dist/db/pg/queries/sorts.d.ts +1 -0
- package/dist/db/pg/queries/sorts.js +1 -0
- package/dist/db/pg/schema/documents.d.ts +17 -0
- package/dist/db/pg/schema/documents.js +6 -0
- package/dist/db/pg/schema/index.d.ts +17 -0
- package/dist/db/pg/sql/0019_posts_published_at.sql +6 -0
- package/dist/db/pg/sql/meta/0019_snapshot.json +4690 -0
- package/dist/db/pg/sql/meta/0022_snapshot.json +29 -2
- package/dist/db/pg/sql/meta/_journal.json +8 -1
- package/dist/events/index.d.ts +2 -0
- package/dist/events/index.js +1 -0
- package/dist/federation/activities.d.ts +25 -0
- package/dist/federation/activities.js +31 -1
- package/dist/federation/discovery.d.ts +70 -0
- package/dist/federation/discovery.js +155 -0
- package/dist/federation/index.d.ts +2 -1
- package/dist/federation/index.js +2 -1
- package/dist/federation/notes.js +2 -2
- package/dist/posts/finders.d.ts +6 -0
- package/dist/posts/finders.js +16 -0
- package/dist/posts/helpers/index.js +2 -0
- package/dist/posts/mapping.d.ts +14 -0
- package/dist/posts/mapping.js +3 -0
- package/dist/posts/mutations.d.ts +9 -0
- package/dist/posts/mutations.js +84 -5
- package/dist/profiles/blocks.d.ts +11 -0
- package/dist/profiles/blocks.js +11 -0
- package/dist/profiles/helpers.d.ts +2 -0
- package/dist/profiles/mutations.js +1 -0
- package/dist/stats/mapping.d.ts +1 -0
- package/package.json +5 -5
package/dist/posts/mutations.js
CHANGED
|
@@ -37,6 +37,19 @@ profile, postData, relations = {}) => {
|
|
|
37
37
|
data = applyArticleSlugPolicy(data, profile);
|
|
38
38
|
}
|
|
39
39
|
const { db } = await allpeepDb();
|
|
40
|
+
// Drafts must not be nested: a reply/repost target could be invisible to
|
|
41
|
+
// others (or a draft), and republishing would leak its visibility.
|
|
42
|
+
if (relations.draft) {
|
|
43
|
+
if (relations.inReplyToId) {
|
|
44
|
+
throw unprocessableRequest({ errorKey: 'error.draftNotReply' });
|
|
45
|
+
}
|
|
46
|
+
if (relations.repostId) {
|
|
47
|
+
throw unprocessableRequest({ errorKey: 'error.draftNotRepost' });
|
|
48
|
+
}
|
|
49
|
+
if (postData.visibility === 'direct') {
|
|
50
|
+
throw unprocessableRequest({ errorKey: 'error.draftNotDirect' });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
40
53
|
const repostedPost = relations.repostId
|
|
41
54
|
? await postsMapping.find(db, relations.repostId)
|
|
42
55
|
: undefined;
|
|
@@ -48,6 +61,17 @@ profile, postData, relations = {}) => {
|
|
|
48
61
|
if (relations.inReplyToId && !repliedToPost) {
|
|
49
62
|
throw notFound({ errorKey: 'error.postDeleted' });
|
|
50
63
|
}
|
|
64
|
+
// A draft parent is invisible to everyone but its author, and the reply
|
|
65
|
+
// would inherit its visibility — replying/reposting to one would leak the
|
|
66
|
+
// hidden post. The by-id finder skips the `publishedAt` default filter, so
|
|
67
|
+
// reject any target that exists but is not yet published. (A deleted reply
|
|
68
|
+
// target is handled above; a non-existent repost target is a no-op.)
|
|
69
|
+
if (repliedToPost && repliedToPost.publishedAt == null) {
|
|
70
|
+
throw unprocessableRequest({ errorKey: 'error.postNotPublished' });
|
|
71
|
+
}
|
|
72
|
+
if (repostedPost && repostedPost.publishedAt == null) {
|
|
73
|
+
throw unprocessableRequest({ errorKey: 'error.postNotPublished' });
|
|
74
|
+
}
|
|
51
75
|
if (repliedToPost) {
|
|
52
76
|
postData.visibility = repliedToPost.visibility;
|
|
53
77
|
}
|
|
@@ -88,6 +112,7 @@ profile, postData, relations = {}) => {
|
|
|
88
112
|
data,
|
|
89
113
|
type: data.type,
|
|
90
114
|
creatorId: profile.id,
|
|
115
|
+
publishedAt: relations.draft ? null : nowIso(),
|
|
91
116
|
});
|
|
92
117
|
await entryConnector(db, profile, post, {
|
|
93
118
|
type: 'create',
|
|
@@ -129,13 +154,49 @@ profile, postData, relations = {}) => {
|
|
|
129
154
|
}
|
|
130
155
|
const newPost = await postsMapping.find(db, post.id);
|
|
131
156
|
const transformedPost = await transformPost(newPost);
|
|
132
|
-
|
|
133
|
-
|
|
157
|
+
// Drafts are invisible to everyone but the author, so none of the
|
|
158
|
+
// publish-time side effects run until `publishPost` fires them once.
|
|
159
|
+
if (relations.draft) {
|
|
160
|
+
return transformedPost;
|
|
134
161
|
}
|
|
135
|
-
|
|
136
|
-
|
|
162
|
+
await announcePostCreation(transformedPost);
|
|
163
|
+
return transformedPost;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Publish-time side effects shared by `createPost` (published immediately)
|
|
167
|
+
* and `publishPost` (draft → published) so the two cannot drift.
|
|
168
|
+
*/
|
|
169
|
+
const announcePostCreation = async (post) => {
|
|
170
|
+
if (post.data?.type === 'event') {
|
|
171
|
+
await rebuildEventOccurrences(post.id, post.data);
|
|
172
|
+
}
|
|
173
|
+
if (post.data?.type === 'question') {
|
|
174
|
+
await schedulePollEnd(post.id, post.data.expiresAt);
|
|
137
175
|
}
|
|
138
|
-
hub.emit('postCreated',
|
|
176
|
+
hub.emit('postCreated', post);
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Publishes a draft post. Validates that the caller is the author and that
|
|
180
|
+
* the post is still unpublished (422 if already published, 403 otherwise);
|
|
181
|
+
* sets `published_at` and fires the shared publish-time side effects once.
|
|
182
|
+
* The intended-visibility re-check (Q4) lives in the UI's publish guard,
|
|
183
|
+
* not here.
|
|
184
|
+
*/
|
|
185
|
+
export const publishPost = async (post, profile) => {
|
|
186
|
+
if (post.publishedAt != null) {
|
|
187
|
+
throw unprocessableRequest({ errorKey: 'error.alreadyPublished' });
|
|
188
|
+
}
|
|
189
|
+
if (post.creatorId !== profile.id && post.profile?.id !== profile.id) {
|
|
190
|
+
throw forbidden({ errorKey: 'error.notDraftOwner' });
|
|
191
|
+
}
|
|
192
|
+
const { db } = await allpeepDb();
|
|
193
|
+
const ts = nowIso();
|
|
194
|
+
await postsMapping.removeDefaultFilter().update(db, post.id, {
|
|
195
|
+
publishedAt: ts,
|
|
196
|
+
});
|
|
197
|
+
const newPost = await postsMapping.find(db, post.id);
|
|
198
|
+
const transformedPost = await transformPost(newPost);
|
|
199
|
+
await announcePostCreation(transformedPost);
|
|
139
200
|
return transformedPost;
|
|
140
201
|
};
|
|
141
202
|
export const updatePost = async (post, profile, data) => {
|
|
@@ -165,6 +226,12 @@ export const updatePost = async (post, profile, data) => {
|
|
|
165
226
|
const newPost = await postsMapping
|
|
166
227
|
.find(db, post.id)
|
|
167
228
|
.then(passThroughUndefined(transformPost));
|
|
229
|
+
// Drafts fire none of the publish-time side effects on edit: occurrences,
|
|
230
|
+
// poll-end jobs, and the `postUpdated` emit all run exactly once when the
|
|
231
|
+
// draft is published via `publishPost` (through `announcePostCreation`).
|
|
232
|
+
if (post.isDraft === true) {
|
|
233
|
+
return newPost;
|
|
234
|
+
}
|
|
168
235
|
if (normalized.type === 'event') {
|
|
169
236
|
await rebuildEventOccurrences(post.id, normalized);
|
|
170
237
|
}
|
|
@@ -178,6 +245,13 @@ export const updatePost = async (post, profile, data) => {
|
|
|
178
245
|
return newPost;
|
|
179
246
|
};
|
|
180
247
|
export const reactToPost = async (post, profile, data) => {
|
|
248
|
+
// A reaction on a draft would store a private entry on an unpublished post
|
|
249
|
+
// (the author's own `self` capabilities let the endpoint through, so this
|
|
250
|
+
// guard is the server-side answer to the UI disabling the control): drafts
|
|
251
|
+
// reject reactions the same way they reject reply/repost targets.
|
|
252
|
+
if (post.isDraft === true) {
|
|
253
|
+
throw unprocessableRequest({ errorKey: 'error.postNotPublished' });
|
|
254
|
+
}
|
|
181
255
|
// Idempotency: one reaction per emoji per profile. Tapping the same emoji
|
|
182
256
|
// twice (a second tab, a stale client, a client retry) must be a no-op —
|
|
183
257
|
// otherwise the entry is stored twice and each row fires `reactionCreated`,
|
|
@@ -281,6 +355,11 @@ export const validatePollVote = (post, data) => {
|
|
|
281
355
|
}
|
|
282
356
|
};
|
|
283
357
|
export const vote = async (profile, post, data) => {
|
|
358
|
+
// Same draft guard as `reactToPost`: a vote would store an answer entry on
|
|
359
|
+
// an unpublished post (including an undo that mutates a prior one).
|
|
360
|
+
if (post.isDraft === true) {
|
|
361
|
+
throw unprocessableRequest({ errorKey: 'error.postNotPublished' });
|
|
362
|
+
}
|
|
284
363
|
validatePollVote(post, data);
|
|
285
364
|
const { db } = await allpeepDb();
|
|
286
365
|
await entryConnector(db, profile, post, {
|
|
@@ -7,6 +7,17 @@ export declare const loadBlockIds: (db: PgDb, profileId: string) => Promise<{
|
|
|
7
7
|
}>;
|
|
8
8
|
export declare const insertBlock: (db: PgDb, fromId: string, toId: string) => Promise<void>;
|
|
9
9
|
export declare const deleteBlock: (db: PgDb, fromId: string, toId: string) => Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Delete both directions of follow edges and pending follow requests between
|
|
12
|
+
* two profiles. Called from `blockProfile`.
|
|
13
|
+
*
|
|
14
|
+
* Deliberately local-only (#241): blocking a profile we federally follow does
|
|
15
|
+
* NOT emit `followDeleted`, so no `Undo(Follow)` is fanned out to remote
|
|
16
|
+
* inboxes — the dropped outbound follow rows would otherwise leave remote
|
|
17
|
+
* hosts believing we still follow. Fan-out Undos on block would add remote
|
|
18
|
+
* calls with no correctness value; the edge is removed locally, which is what
|
|
19
|
+
* the block is for.
|
|
20
|
+
*/
|
|
10
21
|
export declare const dropFollowsBetween: (db: PgDb, a: string, b: string) => Promise<void>;
|
|
11
22
|
export declare const areBlocked: (db: PgDb, a: string, b: string) => Promise<boolean>;
|
|
12
23
|
export declare const hasBlockAmong: (db: PgDb, ids: string[]) => Promise<boolean>;
|
package/dist/profiles/blocks.js
CHANGED
|
@@ -44,6 +44,17 @@ export const deleteBlock = async (db, fromId, toId) => {
|
|
|
44
44
|
};
|
|
45
45
|
const eitherDirection = (a, b) => or(and(eq(follows.fromId, a), eq(follows.toId, b)), and(eq(follows.fromId, b), eq(follows.toId, a)));
|
|
46
46
|
const eitherFollowRequest = (a, b) => or(and(eq(requestsFollow.fromId, a), eq(requestsFollow.toId, b)), and(eq(requestsFollow.fromId, b), eq(requestsFollow.toId, a)));
|
|
47
|
+
/**
|
|
48
|
+
* Delete both directions of follow edges and pending follow requests between
|
|
49
|
+
* two profiles. Called from `blockProfile`.
|
|
50
|
+
*
|
|
51
|
+
* Deliberately local-only (#241): blocking a profile we federally follow does
|
|
52
|
+
* NOT emit `followDeleted`, so no `Undo(Follow)` is fanned out to remote
|
|
53
|
+
* inboxes — the dropped outbound follow rows would otherwise leave remote
|
|
54
|
+
* hosts believing we still follow. Fan-out Undos on block would add remote
|
|
55
|
+
* calls with no correctness value; the edge is removed locally, which is what
|
|
56
|
+
* the block is for.
|
|
57
|
+
*/
|
|
47
58
|
export const dropFollowsBetween = async (db, a, b) => {
|
|
48
59
|
await Promise.all([
|
|
49
60
|
db.delete(follows).where(eitherDirection(a, b)),
|
|
@@ -2,6 +2,7 @@ import { Profile, ProfileWithMeta, Role } from '@openpeepshq/common/types';
|
|
|
2
2
|
import type { PgDb } from '../db/pg/client';
|
|
3
3
|
export declare const followConnector: (db: PgDb, from: Profile, to: Profile, data?: {
|
|
4
4
|
uri?: string | undefined;
|
|
5
|
+
handle?: string | undefined;
|
|
5
6
|
reblogs?: boolean | undefined;
|
|
6
7
|
notify?: boolean | undefined;
|
|
7
8
|
languages?: string[] | undefined;
|
|
@@ -9,6 +10,7 @@ export declare const followConnector: (db: PgDb, from: Profile, to: Profile, dat
|
|
|
9
10
|
id?: string;
|
|
10
11
|
}) => Promise<import("../db/pg/map").WithId<{
|
|
11
12
|
uri?: string | undefined;
|
|
13
|
+
handle?: string | undefined;
|
|
12
14
|
reblogs?: boolean | undefined;
|
|
13
15
|
notify?: boolean | undefined;
|
|
14
16
|
languages?: string[] | undefined;
|
|
@@ -145,6 +145,7 @@ export const followDesignatedProfiles = async (profile, handles) => {
|
|
|
145
145
|
export const unfollow = async (follower, followed) => {
|
|
146
146
|
const { db } = await allpeepDb();
|
|
147
147
|
await followDisconnector(db, follower, followed);
|
|
148
|
+
await hub.emit('followDeleted', follower, followed);
|
|
148
149
|
await Promise.all([clearProfileCache(follower), clearProfileCache(followed)]);
|
|
149
150
|
};
|
|
150
151
|
export const blockProfile = async (blocker, blocked) => {
|
package/dist/stats/mapping.d.ts
CHANGED
|
@@ -241,6 +241,7 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
|
|
|
241
241
|
categoryPath?: string[] | undefined;
|
|
242
242
|
url?: string | undefined;
|
|
243
243
|
} | undefined;
|
|
244
|
+
publishedAt?: string | null | undefined;
|
|
244
245
|
}, DbPost & {
|
|
245
246
|
activityScore: number;
|
|
246
247
|
}, DbPost & {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"dependencies": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"@sentry/node": "^10.78.0",
|
|
10
10
|
"apns2": "^12.2.0",
|
|
11
11
|
"archiver": "^8.0.0",
|
|
12
|
-
"bcrypt": "^
|
|
12
|
+
"bcrypt": "^6.0.0",
|
|
13
13
|
"bullmq": "^5.81.5",
|
|
14
14
|
"cache-manager": "^7.2.4",
|
|
15
15
|
"cacheable": "^2.1.1",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"type-fest": "^4.31.0",
|
|
38
38
|
"uuidv7": "^1.0.2",
|
|
39
39
|
"web-push": "^3.6.7",
|
|
40
|
-
"@openpeepshq/common": "0.
|
|
40
|
+
"@openpeepshq/common": "0.30.0",
|
|
41
41
|
"@openpeepshq/fetch-client": "^0.3.0",
|
|
42
42
|
"@openpeepshq/geocoder": "^0.1.2",
|
|
43
|
-
"@openpeepshq/i18n": "^0.
|
|
43
|
+
"@openpeepshq/i18n": "^0.31.0"
|
|
44
44
|
},
|
|
45
45
|
"main": "dist/index.js",
|
|
46
46
|
"types": "dist/index.d.ts",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
],
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/archiver": "^8.0.0",
|
|
56
|
-
"@types/bcrypt": "^
|
|
56
|
+
"@types/bcrypt": "^6.0.0",
|
|
57
57
|
"@types/express": "^5.0.6",
|
|
58
58
|
"@types/fluent-ffmpeg": "^2.1.27",
|
|
59
59
|
"@types/fs-extra": "^11.0.4",
|