@openpeepshq/core 0.4.11 → 0.5.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.
@@ -58,6 +58,7 @@ export declare const communityConfig: () => Promise<{
58
58
  contactEmail?: string | undefined;
59
59
  privacyPolicy?: string | undefined;
60
60
  termsAndConditions?: string | undefined;
61
+ bugReportUrl?: string | undefined;
61
62
  };
62
63
  content: {
63
64
  aboutPage?: string | undefined;
@@ -32,6 +32,19 @@ const vertexCollectionFor = (relation) => {
32
32
  const edgeCollectionName = (edge) => typeof edge === 'string' ? edge : edge.name;
33
33
  const parentEdgeColumn = (relation) => relation.direction === 'INBOUND' ? 'toId' : 'fromId';
34
34
  const vertexEdgeColumn = (relation) => relation.direction === 'INBOUND' ? 'fromId' : 'toId';
35
+ /**
36
+ * Build the edge-condition SQL fragment from a relation's edgeFilter so every
37
+ * edge query applies the same filter.
38
+ *
39
+ * Returns `undefined` when there is no edgeFilter to apply, and the caller
40
+ * must handle that case (usually by pushing the fragment into the edge
41
+ * conditions passed to `and(...)`).
42
+ */
43
+ const edgeFilterCondition = (relation, edgeTableRef) => typeof relation.edgeFilter === 'string'
44
+ ? applyDateRangeToEdgeSql(edgeTableRef, relation.edgeFilter)
45
+ : isSqlFilter(relation.edgeFilter)
46
+ ? relation.edgeFilter.where
47
+ : undefined;
35
48
  export const fetchRowsByIds = async (db, collection, ids, softDelete) => {
36
49
  if (!ids.length)
37
50
  return [];
@@ -151,11 +164,7 @@ const attachRelation = async (db, _parentCollection, docs, relation) => {
151
164
  return docs;
152
165
  const parentCol = edgeTable[parentEdgeColumn(relation)];
153
166
  const edgeConditions = [inArray(parentCol, parentIds)];
154
- const edgeExtraFilter = typeof relation.edgeFilter === 'string'
155
- ? applyDateRangeToEdgeSql(edgeTableRef, relation.edgeFilter)
156
- : isSqlFilter(relation.edgeFilter)
157
- ? relation.edgeFilter.where
158
- : undefined;
167
+ const edgeExtraFilter = edgeFilterCondition(relation, edgeTableRef);
159
168
  if (edgeExtraFilter)
160
169
  edgeConditions.push(edgeExtraFilter);
161
170
  const edgeRows = await db
@@ -291,10 +300,14 @@ const traverseRelation = async (db, startId, relation) => {
291
300
  break;
292
301
  const parentCol = edgeTable[parentEdgeColumn(relation)];
293
302
  const vertexCol = vertexEdgeColumn(relation);
303
+ const edgeConditions = [inArray(parentCol, frontier)];
304
+ const edgeExtraFilter = edgeFilterCondition(relation, edgeTableRef);
305
+ if (edgeExtraFilter)
306
+ edgeConditions.push(edgeExtraFilter);
294
307
  const edgeRows = await db
295
308
  .select()
296
309
  .from(edgeTableRef)
297
- .where(inArray(parentCol, frontier));
310
+ .where(and(...edgeConditions));
298
311
  if (!edgeRows.length)
299
312
  break;
300
313
  let vertexIds = [
@@ -404,10 +417,14 @@ export const relationsFrom = async (db, start, _parentCollection, relation) => {
404
417
  const edgeTableRef = getEdgeTable(edgeCollectionName(relation.edgeCollection));
405
418
  const edgeTable = asTable(edgeTableRef);
406
419
  const parentCol = edgeTable[parentEdgeColumn(relation)];
420
+ const edgeConditions = [eq(parentCol, start.id)];
421
+ const edgeExtraFilter = edgeFilterCondition(relation, edgeTableRef);
422
+ if (edgeExtraFilter)
423
+ edgeConditions.push(edgeExtraFilter);
407
424
  const edgeRows = await db
408
425
  .select()
409
426
  .from(edgeTableRef)
410
- .where(eq(parentCol, start.id));
427
+ .where(and(...edgeConditions));
411
428
  if (relation.count) {
412
429
  return [{ count: edgeRows.length }];
413
430
  }
@@ -431,6 +448,9 @@ export const relationsFrom = async (db, start, _parentCollection, relation) => {
431
448
  };
432
449
  export const evaluateDerived = async (db, doc, derived) => derived.resolve(db, doc);
433
450
  export const deleteRelationsFor = async (db, startId, relation) => {
451
+ // Deliberately filterless: callers rely on removing every edge of this
452
+ // relation (e.g. deleting all reposts of a post), so Relation.edgeFilter
453
+ // must not narrow the enumeration here.
434
454
  const edgeTableRef = getEdgeTable(edgeCollectionName(relation.edgeCollection));
435
455
  const edgeTable = asTable(edgeTableRef);
436
456
  const parentCol = edgeTable[parentEdgeColumn(relation)];
@@ -5,5 +5,5 @@ export type SendEmailOptions = {
5
5
  /** Writes to BullMQ job logs when processing a queued email. */
6
6
  log?: EmailJobLog;
7
7
  };
8
- export declare const sendEmail: (emailData: EmailOptions, coreConfig: CoreConfig, options?: SendEmailOptions) => Promise<import("nodemailer/lib/smtp-transport").SentMessageInfo>;
9
- export declare const send: (job: Job<EmailOptions>) => Promise<import("nodemailer/lib/smtp-transport").SentMessageInfo>;
8
+ export declare const sendEmail: (emailData: EmailOptions, coreConfig: CoreConfig, options?: SendEmailOptions) => Promise<import("nodemailer").SMTPSentMessageInfo>;
9
+ export declare const send: (job: Job<EmailOptions>) => Promise<import("nodemailer").SMTPSentMessageInfo>;
@@ -107,7 +107,7 @@ export declare const listAdminGroups: () => Promise<{
107
107
  guestData?: {
108
108
  email?: string | undefined;
109
109
  resource?: {
110
- type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
110
+ type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
111
111
  id?: string | undefined;
112
112
  } | undefined;
113
113
  } | undefined;
@@ -109,7 +109,7 @@ export declare const adminGroupsMapping: import("../db/pg/map").Mapping<{
109
109
  guestData?: {
110
110
  email?: string | undefined;
111
111
  resource?: {
112
- type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
112
+ type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
113
113
  id?: string | undefined;
114
114
  } | undefined;
115
115
  } | undefined;
@@ -171,7 +171,7 @@ export declare const adminGroupsMapping: import("../db/pg/map").Mapping<{
171
171
  guestData?: {
172
172
  email?: string | undefined;
173
173
  resource?: {
174
- type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
174
+ type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
175
175
  id?: string | undefined;
176
176
  } | undefined;
177
177
  } | undefined;
@@ -1,11 +1,15 @@
1
+ import type { ExpandedNotification } from '@openpeepshq/common/types';
1
2
  declare const _default: {
2
3
  type: string;
3
4
  event: string;
4
- pushRenderer: (notification: import("@openpeepshq/common").ExpandedNotification) => Promise<{
5
+ pushRenderer: (notification: ExpandedNotification) => Promise<{
5
6
  title: string;
6
7
  options: {
7
8
  body: string | undefined;
8
9
  icon: string;
10
+ data: {
11
+ url: string;
12
+ };
9
13
  actions: {
10
14
  action: string;
11
15
  title: string;
@@ -13,6 +17,7 @@ declare const _default: {
13
17
  };
14
18
  invalidateQueries: string[][];
15
19
  }>;
20
+ expander: (notification: ExpandedNotification) => Promise<ExpandedNotification>;
16
21
  eventHandler: (...eventData: unknown[]) => Promise<void>;
17
22
  };
18
23
  export default _default;
@@ -1,40 +1,75 @@
1
1
  import { findProfile } from '@openpeepshq/core/profiles';
2
2
  import { maybeCreateNotification } from '@openpeepshq/core/notifications';
3
3
  import { getProfileAvatar, profileName } from '@openpeepshq/common/lib';
4
+ import { getConversationByEnd } from '@openpeepshq/core/posts';
4
5
  import { communityConfig } from '../../../config/index.js';
5
6
  import { PUSH_INVALIDATE } from '../../pushInvalidation.js';
6
- export default {
7
- type: 'reaction',
8
- event: 'reactionCreated',
9
- pushRenderer: async (notification) => ({
7
+ const pushRenderer = async (notification) => {
8
+ const reaction = notification.data.reaction;
9
+ const direct = notification.post?.visibility === 'direct';
10
+ const path = direct
11
+ ? `/conversations/${notification.data
12
+ .conversationStart?.id}`
13
+ : `/posts/${notification.post?.id}`;
14
+ return {
10
15
  title: profileName(notification.senderProfile) +
11
16
  ' reacted with ' +
12
- notification.data.reaction +
13
- ' to your post',
17
+ reaction +
18
+ (direct ? ' to your message' : ' to your post'),
14
19
  options: {
15
- body: notification.post?.data?.content,
20
+ // DM content is never previewed in notifications.
21
+ body: direct ? undefined : notification.post?.data?.content,
16
22
  icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
23
+ data: { url: path },
17
24
  actions: [
18
25
  {
19
- action: `goto:/posts/${notification.post?.id}`,
20
- title: 'Go to post',
26
+ action: `goto:${path}`,
27
+ title: direct ? 'Go to thread' : 'Go to post',
21
28
  },
22
29
  ],
23
30
  },
24
- invalidateQueries: [PUSH_INVALIDATE.posts],
25
- }),
26
- eventHandler: async (...eventData) => {
27
- const [profile, post, data] = eventData;
28
- const recipientProfile = await findProfile(post.profile.id);
29
- if (recipientProfile && recipientProfile?.id !== profile.id) {
30
- await maybeCreateNotification(recipientProfile, {
31
- type: 'reaction',
32
- fromProfileId: profile.id,
33
- postId: post.id,
34
- data: {
35
- reaction: data.reaction,
36
- },
37
- });
38
- }
39
- },
31
+ // DM threads are cached under `conversations` keys; feed posts only
32
+ // need `posts` invalidated.
33
+ invalidateQueries: [
34
+ PUSH_INVALIDATE.posts,
35
+ ...(direct ? [PUSH_INVALIDATE.conversations] : []),
36
+ ],
37
+ };
38
+ };
39
+ const expander = async (notification) => {
40
+ const post = notification.post;
41
+ if (!post || post.visibility !== 'direct')
42
+ return notification;
43
+ const conversationStart = (await getConversationByEnd(post, {
44
+ profile: notification.recipientProfile,
45
+ scopes: [],
46
+ }))[0];
47
+ return {
48
+ ...notification,
49
+ data: {
50
+ ...notification.data,
51
+ conversationStart,
52
+ },
53
+ };
54
+ };
55
+ const eventHandler = async (...eventData) => {
56
+ const [profile, post, data] = eventData;
57
+ const recipientProfile = await findProfile(post.profile.id);
58
+ if (recipientProfile && recipientProfile?.id !== profile.id) {
59
+ await maybeCreateNotification(recipientProfile, {
60
+ type: 'reaction',
61
+ fromProfileId: profile.id,
62
+ postId: post.id,
63
+ data: {
64
+ reaction: data.reaction,
65
+ },
66
+ });
67
+ }
68
+ };
69
+ export default {
70
+ type: 'reaction',
71
+ event: 'reactionCreated',
72
+ pushRenderer,
73
+ expander,
74
+ eventHandler,
40
75
  };
@@ -373,6 +373,13 @@ export declare const getConversationByStart: (post: PostWithMeta, authData: Auth
373
373
  }) => Promise<PostWithMeta[]>;
374
374
  /** Newest post across all roots of a 1:1 conversation (uuidv7-ordered). */
375
375
  export declare const findLatestOneToOnePostId: (post: PostWithMeta) => Promise<string>;
376
+ /**
377
+ * Newest post of the conversation containing `post`; its audience defines
378
+ * the current participants. Leavers stay in the audience of older posts but
379
+ * are excluded from this one. 1:1 conversations span all roots of the pair,
380
+ * group conversations stay within `post`'s thread.
381
+ */
382
+ export declare const findLatestConversationPost: (post: PostWithMeta, authData: AuthorizationData) => Promise<PostWithMeta | undefined>;
376
383
  /** Full ancestor/descendant trees for post detail (CTE + lean mapping). */
377
384
  export declare const getPostContext: (post: PostWithMeta, authData: AuthorizationData) => Promise<{
378
385
  ancestors: PostWithMeta[];
@@ -13,7 +13,8 @@ import { profilesMapping } from '../profiles/mapping.js';
13
13
  import { CONTEXT_NODE_CAP, loadReplyContextPosts } from './contextClosure.js';
14
14
  import { withSpan } from '../performance/index.js';
15
15
  import { queryUnseenPostCounts } from './unseenCounts.js';
16
- import { getConversationThread, getOneToOneConversation, listOneToOneConversationPostIds, } from './conversationQueries.js';
16
+ import { findLatestThreadPostId, getConversationThread, getOneToOneConversation, listOneToOneConversationPostIds, } from './conversationQueries.js';
17
+ import { findReplyRootId } from './activity.js';
17
18
  import { fetchRowsByIds, hydrateMapData } from '../db/pg/map/relations.js';
18
19
  import { listEventAgenda } from './eventAgenda.js';
19
20
  /**
@@ -306,6 +307,22 @@ export const findLatestOneToOnePostId = async (post) => {
306
307
  const ids = await listOneToOneConversationPostIds(db, profileAId, profileBId);
307
308
  return ids[ids.length - 1] ?? post.id;
308
309
  };
310
+ /**
311
+ * Newest post of the conversation containing `post`; its audience defines
312
+ * the current participants. Leavers stay in the audience of older posts but
313
+ * are excluded from this one. 1:1 conversations span all roots of the pair,
314
+ * group conversations stay within `post`'s thread.
315
+ */
316
+ export const findLatestConversationPost = async (post, authData) => {
317
+ const { db } = await allpeepDb();
318
+ const lastPostId = isOneToOneDm(post)
319
+ ? await findLatestOneToOnePostId(post)
320
+ : await findLatestThreadPostId(await findReplyRootId(db, post.id));
321
+ if (lastPostId === post.id)
322
+ return post;
323
+ const [lastPost] = await findPostsForAuth([lastPostId], authData);
324
+ return lastPost;
325
+ };
309
326
  /** Full ancestor/descendant trees for post detail (CTE + lean mapping). */
310
327
  export const getPostContext = async (post, authData) => {
311
328
  const mapping = sortOldestFirst(postContextMappingForProfile(authData.profile));
@@ -94,6 +94,9 @@ export const transformPost = async (post, currentProfile, options = {}) => {
94
94
  const entries = allEntries.filter((entry) => !isReactionHistoryEntry(entry.type));
95
95
  const reactions = currentReactionsFromEntries(allEntries)
96
96
  .filter((item) => item.reaction === AP_LIKE_REACTION)
97
+ // Privacy boundary: hide reactions from blocked pairs (either direction),
98
+ // mirroring how blocked creators are tombstoned via withBlockTombstone.
99
+ .filter((item) => !currentProfile || !isBlockedPair(currentProfile, item.profile.id))
97
100
  .map((item) => ({
98
101
  reaction: AP_LIKE_REACTION,
99
102
  profile: item.profile,
@@ -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: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
38
+ type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
39
39
  id?: string | undefined;
40
40
  } | undefined;
41
41
  } | undefined;
@@ -74,7 +74,7 @@ export declare const publicProfilesSearchMapping: import("../db/pg/map").Mapping
74
74
  guestData?: {
75
75
  email?: string | undefined;
76
76
  resource?: {
77
- type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
77
+ type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
78
78
  id?: string | undefined;
79
79
  } | undefined;
80
80
  } | undefined;
@@ -116,7 +116,7 @@ export declare const publicProfilesMapping: import("../db/pg/map").Mapping<{
116
116
  guestData?: {
117
117
  email?: string | undefined;
118
118
  resource?: {
119
- type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
119
+ type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
120
120
  id?: string | undefined;
121
121
  } | undefined;
122
122
  } | undefined;
@@ -154,7 +154,7 @@ export declare const profilesMapping: import("../db/pg/map").Mapping<{
154
154
  guestData?: {
155
155
  email?: string | undefined;
156
156
  resource?: {
157
- type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
157
+ type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
158
158
  id?: string | undefined;
159
159
  } | undefined;
160
160
  } | undefined;
@@ -192,7 +192,7 @@ export declare const membersExportMapping: import("../db/pg/map").Mapping<{
192
192
  guestData?: {
193
193
  email?: string | undefined;
194
194
  resource?: {
195
- type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
195
+ type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
196
196
  id?: string | undefined;
197
197
  } | undefined;
198
198
  } | undefined;
@@ -5,5 +5,5 @@ export declare const reportsMapping: import("../db/pg/map").Mapping<{
5
5
  uri?: string | undefined;
6
6
  forward?: boolean | undefined;
7
7
  ruleIds?: number[] | undefined;
8
- resolution?: "remove" | "warn" | "other" | "ignore" | "ban" | undefined;
8
+ resolution?: "remove" | "other" | "warn" | "ignore" | "ban" | undefined;
9
9
  }, ReportWithMeta, ReportWithMeta>;
@@ -59,6 +59,7 @@ export declare const serverInfo: () => Promise<{
59
59
  contactEmail?: string | undefined;
60
60
  privacyPolicy?: string | undefined;
61
61
  termsAndConditions?: string | undefined;
62
+ bugReportUrl?: string | undefined;
62
63
  };
63
64
  content: {
64
65
  aboutPage?: string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/core",
3
- "version": "0.4.11",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "dependencies": {
@@ -15,9 +15,9 @@
15
15
  "cacheable": "^2.1.1",
16
16
  "change-case": "^5.4.4",
17
17
  "date-fns": "^4.1.0",
18
- "deepmerge-ts": "^7.1.3",
18
+ "deepmerge-ts": "^8.0.2",
19
19
  "dotenv": "^16.4.7",
20
- "drizzle-orm": "^0.44.2",
20
+ "drizzle-orm": "^0.45.2",
21
21
  "extract-zip": "^2.0.1",
22
22
  "firebase-admin": "^13.4.0",
23
23
  "fluent-ffmpeg": "^2.1.3",
@@ -26,21 +26,21 @@
26
26
  "i18next-fs-backend": "^2.6.6",
27
27
  "jose": "^5.9.6",
28
28
  "livekit-server-sdk": "^2.15.4",
29
- "nodemailer": "^6.9.16",
29
+ "nodemailer": "^10.0.0",
30
30
  "pdfkit": "^0.19.1",
31
31
  "pg": "^8.16.0",
32
32
  "redis": "^4.7.0",
33
33
  "safe-json-stringify": "^1.2.0",
34
- "sharp": "^0.33.5",
34
+ "sharp": "^0.35.5",
35
35
  "stripe": "^18.4.0",
36
36
  "tweetnacl": "^1.0.3",
37
37
  "type-fest": "^4.31.0",
38
38
  "uuidv7": "^1.0.2",
39
39
  "web-push": "^3.6.7",
40
- "@openpeepshq/common": "0.5.12",
40
+ "@openpeepshq/common": "0.6.1",
41
+ "@openpeepshq/i18n": "^0.7.0",
41
42
  "@openpeepshq/geocoder": "^0.1.2",
42
- "@openpeepshq/fetch-client": "^0.2.1",
43
- "@openpeepshq/i18n": "^0.4.11"
43
+ "@openpeepshq/fetch-client": "^0.2.1"
44
44
  },
45
45
  "main": "dist/index.js",
46
46
  "types": "dist/index.d.ts",
@@ -59,23 +59,22 @@
59
59
  "@types/fs-extra": "^11.0.4",
60
60
  "@types/html-to-text": "^9.0.4",
61
61
  "@types/node": "^22.19.17",
62
- "@types/nodemailer": "^6.4.17",
63
62
  "@types/pdfkit": "^0.17.6",
64
63
  "@types/pg": "^8.15.4",
65
64
  "@types/safe-json-stringify": "^1.1.5",
66
65
  "@types/web-push": "^3.6.4",
67
66
  "@typescript-eslint/eslint-plugin": "^8.72.0",
68
67
  "@typescript-eslint/parser": "^8.72.0",
69
- "concurrently": "^9.1.2",
68
+ "concurrently": "^9.2.5",
70
69
  "drizzle-kit": "^0.31.1",
71
- "eslint": "^10.1.0",
70
+ "eslint": "^10.14.0",
72
71
  "eslint-config-prettier": "^9.1.0",
73
72
  "google-auth-library": "^10.7.0",
74
73
  "i18next": "^24.2.3",
75
74
  "prettier": "^3.4.2",
76
75
  "tsc-alias": "^1.8.10",
77
76
  "typescript": "^6.0.2",
78
- "vitest": "^2.1.8",
77
+ "vitest": "^4.1.12",
79
78
  "@eslint/js": "^9.17.0"
80
79
  },
81
80
  "scripts": {