@openpeepshq/core 0.27.0 → 0.28.1
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/federation/notes.js +2 -2
- package/dist/jams/mutations.d.ts +12 -0
- package/dist/jams/mutations.js +38 -0
- 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/stats/mapping.d.ts +1 -0
- package/package.json +5 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "4a5587e2-755d-42e0-a8e0-4940132dbb19",
|
|
3
|
-
"prevId": "
|
|
3
|
+
"prevId": "cbe40fa6-6a27-404d-82fd-48551e54d6d2",
|
|
4
4
|
"version": "7",
|
|
5
5
|
"dialect": "postgresql",
|
|
6
6
|
"tables": {
|
|
@@ -899,6 +899,12 @@
|
|
|
899
899
|
"type": "timestamp with time zone",
|
|
900
900
|
"primaryKey": false,
|
|
901
901
|
"notNull": false
|
|
902
|
+
},
|
|
903
|
+
"published_at": {
|
|
904
|
+
"name": "published_at",
|
|
905
|
+
"type": "timestamp with time zone",
|
|
906
|
+
"primaryKey": false,
|
|
907
|
+
"notNull": false
|
|
902
908
|
}
|
|
903
909
|
},
|
|
904
910
|
"indexes": {
|
|
@@ -1050,6 +1056,27 @@
|
|
|
1050
1056
|
"concurrently": false,
|
|
1051
1057
|
"method": "btree",
|
|
1052
1058
|
"with": {}
|
|
1059
|
+
},
|
|
1060
|
+
"posts_creator_published_idx": {
|
|
1061
|
+
"name": "posts_creator_published_idx",
|
|
1062
|
+
"columns": [
|
|
1063
|
+
{
|
|
1064
|
+
"expression": "creator_id",
|
|
1065
|
+
"isExpression": false,
|
|
1066
|
+
"asc": true,
|
|
1067
|
+
"nulls": "last"
|
|
1068
|
+
},
|
|
1069
|
+
{
|
|
1070
|
+
"expression": "published_at",
|
|
1071
|
+
"isExpression": false,
|
|
1072
|
+
"asc": true,
|
|
1073
|
+
"nulls": "last"
|
|
1074
|
+
}
|
|
1075
|
+
],
|
|
1076
|
+
"isUnique": false,
|
|
1077
|
+
"concurrently": false,
|
|
1078
|
+
"method": "btree",
|
|
1079
|
+
"with": {}
|
|
1053
1080
|
}
|
|
1054
1081
|
},
|
|
1055
1082
|
"foreignKeys": {},
|
|
@@ -4698,4 +4725,4 @@
|
|
|
4698
4725
|
"schemas": {},
|
|
4699
4726
|
"tables": {}
|
|
4700
4727
|
}
|
|
4701
|
-
}
|
|
4728
|
+
}
|
|
@@ -135,6 +135,13 @@
|
|
|
135
135
|
"tag": "0018_add_calendar_feed_tokens",
|
|
136
136
|
"breakpoints": true
|
|
137
137
|
},
|
|
138
|
+
{
|
|
139
|
+
"idx": 19,
|
|
140
|
+
"version": "7",
|
|
141
|
+
"when": 1795336252623,
|
|
142
|
+
"tag": "0019_posts_published_at",
|
|
143
|
+
"breakpoints": true
|
|
144
|
+
},
|
|
138
145
|
{
|
|
139
146
|
"idx": 22,
|
|
140
147
|
"version": "7",
|
|
@@ -143,4 +150,4 @@
|
|
|
143
150
|
"breakpoints": true
|
|
144
151
|
}
|
|
145
152
|
]
|
|
146
|
-
}
|
|
153
|
+
}
|
package/dist/federation/notes.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { and, eq, isNull } from 'drizzle-orm';
|
|
1
|
+
import { and, eq, isNotNull, isNull } from 'drizzle-orm';
|
|
2
2
|
import { pgDb } from '../db/pg/client.js';
|
|
3
3
|
import { posts } from '../db/pg/schema/documents.js';
|
|
4
4
|
export const loadPublicNote = async (postId) => {
|
|
@@ -15,7 +15,7 @@ export const loadPublicNote = async (postId) => {
|
|
|
15
15
|
deletedAt: posts.deletedAt,
|
|
16
16
|
})
|
|
17
17
|
.from(posts)
|
|
18
|
-
.where(and(eq(posts.id, postId), isNull(posts.deletedAt)))
|
|
18
|
+
.where(and(eq(posts.id, postId), isNull(posts.deletedAt), isNotNull(posts.publishedAt)))
|
|
19
19
|
.limit(1);
|
|
20
20
|
if (!row || row.type !== 'note' || row.visibility !== 'public')
|
|
21
21
|
return null;
|
package/dist/jams/mutations.d.ts
CHANGED
|
@@ -40,3 +40,15 @@ export declare const updateJamRecording: (recordingId: string, recording: Partia
|
|
|
40
40
|
_from: string;
|
|
41
41
|
_to: string;
|
|
42
42
|
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Soft-deletes a jam chat message and blanks its content.
|
|
45
|
+
*
|
|
46
|
+
* Only the jam host, a jam moderator, or the message author may delete. The
|
|
47
|
+
* `deletedAt` soft-delete flag is what hides the row from every consumer
|
|
48
|
+
* (`listJamEvents`, attendance, export) — those all go through the
|
|
49
|
+
* soft-delete-filtered mappings; blanking `content` is belt-and-braces so no
|
|
50
|
+
* path that bypasses the flag can resurrect the text. `jamId` and `type` are
|
|
51
|
+
* re-checked server-side so an id pointing at a different jam or a non-message
|
|
52
|
+
* event (join/leave/start/…) is a 404, never a cross-jam write.
|
|
53
|
+
*/
|
|
54
|
+
export declare const deleteJamEvent: (actorId: string, jamId: string, jamEventId: string) => Promise<boolean>;
|
package/dist/jams/mutations.js
CHANGED
|
@@ -1,4 +1,42 @@
|
|
|
1
|
+
import { jamFromEvent } from '@openpeepshq/common/lib';
|
|
2
|
+
import { forbidden, notFound } from '../errors/index.js';
|
|
1
3
|
import { allpeepDb } from '../db/index.js';
|
|
4
|
+
import { findPost } from '../posts/index.js';
|
|
2
5
|
import { jamEventsMapping, jamRecordingsMapping } from './mapping.js';
|
|
3
6
|
export const createJamEvent = (jamEvent) => allpeepDb().then(({ db }) => jamEventsMapping.create(db, jamEvent));
|
|
4
7
|
export const updateJamRecording = (recordingId, recording) => allpeepDb().then(({ db }) => jamRecordingsMapping.update(db, recordingId, recording));
|
|
8
|
+
/**
|
|
9
|
+
* Soft-deletes a jam chat message and blanks its content.
|
|
10
|
+
*
|
|
11
|
+
* Only the jam host, a jam moderator, or the message author may delete. The
|
|
12
|
+
* `deletedAt` soft-delete flag is what hides the row from every consumer
|
|
13
|
+
* (`listJamEvents`, attendance, export) — those all go through the
|
|
14
|
+
* soft-delete-filtered mappings; blanking `content` is belt-and-braces so no
|
|
15
|
+
* path that bypasses the flag can resurrect the text. `jamId` and `type` are
|
|
16
|
+
* re-checked server-side so an id pointing at a different jam or a non-message
|
|
17
|
+
* event (join/leave/start/…) is a 404, never a cross-jam write.
|
|
18
|
+
*/
|
|
19
|
+
export const deleteJamEvent = async (actorId, jamId, jamEventId) => {
|
|
20
|
+
const { db } = await allpeepDb();
|
|
21
|
+
// ignoreSoftDelete: a re-delete must be a no-op 404, not a re-mutation.
|
|
22
|
+
const jamEvent = await jamEventsMapping.find(db, jamEventId, {
|
|
23
|
+
ignoreSoftDelete: true,
|
|
24
|
+
});
|
|
25
|
+
if (!jamEvent || jamEvent.jamId !== jamId || jamEvent.type !== 'message') {
|
|
26
|
+
throw notFound({ errorKey: 'error.jamNotFound', parameters: { jamId } });
|
|
27
|
+
}
|
|
28
|
+
const jamPost = await findPost(jamId);
|
|
29
|
+
const jam = jamPost ? jamFromEvent(jamPost) : undefined;
|
|
30
|
+
if (!jamPost || !jam) {
|
|
31
|
+
throw notFound({ errorKey: 'error.jamNotFound', parameters: { jamId } });
|
|
32
|
+
}
|
|
33
|
+
const isHost = jamPost.profile.id === actorId;
|
|
34
|
+
const isModerator = jam.moderators?.includes(actorId) ?? false;
|
|
35
|
+
const isAuthor = jamEvent.profileId === actorId;
|
|
36
|
+
if (!isHost && !isModerator && !isAuthor) {
|
|
37
|
+
throw forbidden({ errorKey: 'error.forbidden' });
|
|
38
|
+
}
|
|
39
|
+
await jamEventsMapping.update(db, jamEventId, { content: '' });
|
|
40
|
+
await jamEventsMapping.delete(db, jamEventId);
|
|
41
|
+
return true;
|
|
42
|
+
};
|
package/dist/posts/finders.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ export declare const findPost: (id: string, authData?: AuthorizationData) => Pro
|
|
|
13
13
|
* an unscoped profile-scoped lookup (matches any creator).
|
|
14
14
|
*/
|
|
15
15
|
export declare const findPostBySlug: (slug: string, profileHandle?: string, instanceScoped?: boolean) => Promise<PostWithMeta | null>;
|
|
16
|
+
/** The author's unpublished drafts, most-recently-edited first. */
|
|
17
|
+
export declare const listMyDrafts: (profile: ProfileWithMeta, options?: {
|
|
18
|
+
limit?: number;
|
|
19
|
+
offset?: number;
|
|
20
|
+
}) => Promise<PostWithMeta[]>;
|
|
16
21
|
/** Lean post load for capability checks (no nested reply/repost). */
|
|
17
22
|
export declare const findPostsForAuth: (ids: string[], authData?: AuthorizationData) => Promise<PostWithMeta[]>;
|
|
18
23
|
export declare const postContext: (authData: AuthorizationData, id: string, depth: number, direction: "ancestors" | "descendents", contextMapping?: Mapping<DbPost>) => Promise<PostWithMeta[]>;
|
|
@@ -269,6 +274,7 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
|
|
|
269
274
|
categoryPath?: string[] | undefined;
|
|
270
275
|
url?: string | undefined;
|
|
271
276
|
} | undefined;
|
|
277
|
+
publishedAt?: string | null | undefined;
|
|
272
278
|
}, DbPost, DbPost>;
|
|
273
279
|
export declare const listPosts: (authData: AuthorizationData, { start, limit, filter, }?: {
|
|
274
280
|
start?: string;
|
package/dist/posts/finders.js
CHANGED
|
@@ -91,6 +91,22 @@ export const findPostBySlug = async (slug, profileHandle, instanceScoped) => {
|
|
|
91
91
|
const post = await transformPost(row);
|
|
92
92
|
return hideBlockedAuthorPost(post, undefined) ?? null;
|
|
93
93
|
};
|
|
94
|
+
/** The author's unpublished drafts, most-recently-edited first. */
|
|
95
|
+
export const listMyDrafts = async (profile, options = {}) => {
|
|
96
|
+
const { limit = 100, offset = 0 } = options;
|
|
97
|
+
const mapping = postsMappingForProfile(profile)
|
|
98
|
+
.removeDefaultFilter()
|
|
99
|
+
.filter(postFilters.drafts())
|
|
100
|
+
.filter(postFilters.creatorId(profile.id))
|
|
101
|
+
// "Newest" = most-recently-edited (updatedAt, not createdAt), so a draft
|
|
102
|
+
// bubbles to the top after an edit — matching how the feed orders posts.
|
|
103
|
+
.sort(sorts.updatedAtDesc);
|
|
104
|
+
return toFilteredPostsList(mapping, {
|
|
105
|
+
authData: { profile, scopes: [] },
|
|
106
|
+
limit,
|
|
107
|
+
offset,
|
|
108
|
+
});
|
|
109
|
+
};
|
|
94
110
|
/** Lean post load for capability checks (no nested reply/repost). */
|
|
95
111
|
export const findPostsForAuth = async (ids, authData) => {
|
|
96
112
|
if (ids.length === 0)
|
|
@@ -126,6 +126,8 @@ export const transformPost = async (post, currentProfile, options = {}) => {
|
|
|
126
126
|
const latestReplies = (await Promise.all(preview.replies.map((reply) => transformPost(reply, currentProfile, nested)))).filter((reply) => !!reply.profile);
|
|
127
127
|
return {
|
|
128
128
|
...post,
|
|
129
|
+
publishedAt: post.publishedAt ?? undefined,
|
|
130
|
+
isDraft: post.publishedAt == null,
|
|
129
131
|
data: post.data ? normalizePostDataFromDb(post.data) : post.data,
|
|
130
132
|
seen: currentProfile ? post.seen : undefined,
|
|
131
133
|
replyTo: post.replyTo
|
package/dist/posts/mapping.d.ts
CHANGED
|
@@ -249,6 +249,7 @@ export declare const threadPreviewMappingForProfile: (profile?: {
|
|
|
249
249
|
categoryPath?: string[] | undefined;
|
|
250
250
|
url?: string | undefined;
|
|
251
251
|
} | undefined;
|
|
252
|
+
publishedAt?: string | null | undefined;
|
|
252
253
|
}, DbPost, DbPost>;
|
|
253
254
|
export declare const repostRelation: RelationWithMapping<DbBasePost>;
|
|
254
255
|
export declare const repostRelationForProfile: (profile?: {
|
|
@@ -499,6 +500,7 @@ export declare const postsWithReplyCountMapping: Mapping<{
|
|
|
499
500
|
categoryPath?: string[] | undefined;
|
|
500
501
|
url?: string | undefined;
|
|
501
502
|
} | undefined;
|
|
503
|
+
publishedAt?: string | null | undefined;
|
|
502
504
|
}, {
|
|
503
505
|
createdAt: string;
|
|
504
506
|
updatedAt: string;
|
|
@@ -744,6 +746,7 @@ export declare const postsWithReplyCountMapping: Mapping<{
|
|
|
744
746
|
categoryPath?: string[] | undefined;
|
|
745
747
|
url?: string | undefined;
|
|
746
748
|
} | undefined;
|
|
749
|
+
publishedAt?: string | null | undefined;
|
|
747
750
|
} & {
|
|
748
751
|
id: string;
|
|
749
752
|
} & {
|
|
@@ -993,6 +996,7 @@ export declare const postsWithReplyCountMapping: Mapping<{
|
|
|
993
996
|
categoryPath?: string[] | undefined;
|
|
994
997
|
url?: string | undefined;
|
|
995
998
|
} | undefined;
|
|
999
|
+
publishedAt?: string | null | undefined;
|
|
996
1000
|
} & {
|
|
997
1001
|
id: string;
|
|
998
1002
|
} & {
|
|
@@ -1239,6 +1243,7 @@ export declare const postsWithReplyToCountMapping: Mapping<{
|
|
|
1239
1243
|
categoryPath?: string[] | undefined;
|
|
1240
1244
|
url?: string | undefined;
|
|
1241
1245
|
} | undefined;
|
|
1246
|
+
publishedAt?: string | null | undefined;
|
|
1242
1247
|
}, {
|
|
1243
1248
|
createdAt: string;
|
|
1244
1249
|
updatedAt: string;
|
|
@@ -1484,6 +1489,7 @@ export declare const postsWithReplyToCountMapping: Mapping<{
|
|
|
1484
1489
|
categoryPath?: string[] | undefined;
|
|
1485
1490
|
url?: string | undefined;
|
|
1486
1491
|
} | undefined;
|
|
1492
|
+
publishedAt?: string | null | undefined;
|
|
1487
1493
|
} & {
|
|
1488
1494
|
id: string;
|
|
1489
1495
|
} & {
|
|
@@ -1733,6 +1739,7 @@ export declare const postsWithReplyToCountMapping: Mapping<{
|
|
|
1733
1739
|
categoryPath?: string[] | undefined;
|
|
1734
1740
|
url?: string | undefined;
|
|
1735
1741
|
} | undefined;
|
|
1742
|
+
publishedAt?: string | null | undefined;
|
|
1736
1743
|
} & {
|
|
1737
1744
|
id: string;
|
|
1738
1745
|
} & {
|
|
@@ -1979,6 +1986,7 @@ export declare const postsMapping: Mapping<{
|
|
|
1979
1986
|
categoryPath?: string[] | undefined;
|
|
1980
1987
|
url?: string | undefined;
|
|
1981
1988
|
} | undefined;
|
|
1989
|
+
publishedAt?: string | null | undefined;
|
|
1982
1990
|
}, DbPost, DbPost>;
|
|
1983
1991
|
/** Auth / mark-seen: post graph without nested replyTo/repost hydrate. */
|
|
1984
1992
|
export declare const postsAuthMapping: Mapping<{
|
|
@@ -2222,6 +2230,7 @@ export declare const postsAuthMapping: Mapping<{
|
|
|
2222
2230
|
categoryPath?: string[] | undefined;
|
|
2223
2231
|
url?: string | undefined;
|
|
2224
2232
|
} | undefined;
|
|
2233
|
+
publishedAt?: string | null | undefined;
|
|
2225
2234
|
}, DbPost, DbPost>;
|
|
2226
2235
|
export declare const postsMappingForProfile: (profile?: {
|
|
2227
2236
|
id: string;
|
|
@@ -2466,6 +2475,7 @@ export declare const postsMappingForProfile: (profile?: {
|
|
|
2466
2475
|
categoryPath?: string[] | undefined;
|
|
2467
2476
|
url?: string | undefined;
|
|
2468
2477
|
} | undefined;
|
|
2478
|
+
publishedAt?: string | null | undefined;
|
|
2469
2479
|
}, DbPost, DbPost>;
|
|
2470
2480
|
export declare const postContextMappingForProfile: (profile?: {
|
|
2471
2481
|
id: string;
|
|
@@ -2710,6 +2720,7 @@ export declare const postContextMappingForProfile: (profile?: {
|
|
|
2710
2720
|
categoryPath?: string[] | undefined;
|
|
2711
2721
|
url?: string | undefined;
|
|
2712
2722
|
} | undefined;
|
|
2723
|
+
publishedAt?: string | null | undefined;
|
|
2713
2724
|
}, DbPost, DbPost>;
|
|
2714
2725
|
export declare const contextRelation: (depth: number, direction: "ancestors" | "descendents", contextMapping?: Mapping<DbPost>) => RelationWithMapping<DbPost>;
|
|
2715
2726
|
export declare const conversationLeavesMapping: Mapping<{
|
|
@@ -2953,6 +2964,7 @@ export declare const conversationLeavesMapping: Mapping<{
|
|
|
2953
2964
|
categoryPath?: string[] | undefined;
|
|
2954
2965
|
url?: string | undefined;
|
|
2955
2966
|
} | undefined;
|
|
2967
|
+
publishedAt?: string | null | undefined;
|
|
2956
2968
|
}, DbPost, DbPost>;
|
|
2957
2969
|
export declare const conversationLeavesMappingForProfile: (profile?: {
|
|
2958
2970
|
id: string;
|
|
@@ -3197,6 +3209,7 @@ export declare const conversationLeavesMappingForProfile: (profile?: {
|
|
|
3197
3209
|
categoryPath?: string[] | undefined;
|
|
3198
3210
|
url?: string | undefined;
|
|
3199
3211
|
} | undefined;
|
|
3212
|
+
publishedAt?: string | null | undefined;
|
|
3200
3213
|
}, DbPost, DbPost>;
|
|
3201
3214
|
export declare const postIdsMapping: Mapping<{
|
|
3202
3215
|
type: "resource" | "note" | "question" | "event" | "article";
|
|
@@ -3439,6 +3452,7 @@ export declare const postIdsMapping: Mapping<{
|
|
|
3439
3452
|
categoryPath?: string[] | undefined;
|
|
3440
3453
|
url?: string | undefined;
|
|
3441
3454
|
} | undefined;
|
|
3455
|
+
publishedAt?: string | null | undefined;
|
|
3442
3456
|
}, {
|
|
3443
3457
|
id: string;
|
|
3444
3458
|
}, {
|
package/dist/posts/mapping.js
CHANGED
|
@@ -113,6 +113,9 @@ const basePostFilterRelations = [
|
|
|
113
113
|
const preFilterMapData = {
|
|
114
114
|
collection: 'posts',
|
|
115
115
|
softDelete: true,
|
|
116
|
+
// Drafts (unpublished) are excluded from every shared post query by default.
|
|
117
|
+
// The drafts finder opts out via `removeDefaultFilter()`.
|
|
118
|
+
defaultFilter: postFilters.published(),
|
|
116
119
|
};
|
|
117
120
|
const basePostMapData = {
|
|
118
121
|
...preFilterMapData,
|
|
@@ -7,7 +7,16 @@ export declare const createPost: (data: PostDataUnion, profile: Profile & {
|
|
|
7
7
|
repostId?: string;
|
|
8
8
|
audience?: Profile[] | null;
|
|
9
9
|
groupId?: string | null;
|
|
10
|
+
draft?: boolean;
|
|
10
11
|
}) => Promise<PostWithMeta>;
|
|
12
|
+
/**
|
|
13
|
+
* Publishes a draft post. Validates that the caller is the author and that
|
|
14
|
+
* the post is still unpublished (422 if already published, 403 otherwise);
|
|
15
|
+
* sets `published_at` and fires the shared publish-time side effects once.
|
|
16
|
+
* The intended-visibility re-check (Q4) lives in the UI's publish guard,
|
|
17
|
+
* not here.
|
|
18
|
+
*/
|
|
19
|
+
export declare const publishPost: (post: PostWithMeta, profile: Profile) => Promise<PostWithMeta>;
|
|
11
20
|
export declare const updatePost: (post: PostWithMeta, profile: Profile & {
|
|
12
21
|
roles?: Role[];
|
|
13
22
|
}, data: PostDataUnion) => Promise<PostWithMeta>;
|
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, {
|
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.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"dependencies": {
|
|
@@ -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.
|
|
41
|
-
"@openpeepshq/
|
|
42
|
-
"@openpeepshq/
|
|
43
|
-
"@openpeepshq/
|
|
40
|
+
"@openpeepshq/common": "0.30.0",
|
|
41
|
+
"@openpeepshq/i18n": "^0.31.1",
|
|
42
|
+
"@openpeepshq/geocoder": "^0.1.2",
|
|
43
|
+
"@openpeepshq/fetch-client": "^0.3.0"
|
|
44
44
|
},
|
|
45
45
|
"main": "dist/index.js",
|
|
46
46
|
"types": "dist/index.d.ts",
|