@openpeepshq/core 0.5.0 → 0.5.2

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.
@@ -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;
@@ -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>;
@@ -14,13 +14,14 @@ export type CrawlableMeta = {
14
14
  authorName?: string;
15
15
  };
16
16
  /**
17
- * Metadata plus whether the route could render at all, so the server can answer
18
- * 404 for a content path that will never show anything to a crawler instead of
19
- * a 200 community shell.
17
+ * Metadata for a content page when resolvable and anonymously readable; `null`
18
+ * when the entity is missing or unreadable (an anonymous fetch must not be
19
+ * able to tell those two apart — that would leak which ids exist). Renderers
20
+ * answer every content route with a 200 shell and let `noindex` carry the
21
+ * "not for crawlers" signal instead of a status code.
20
22
  */
21
23
  export type SpaMeta = {
22
24
  meta: CrawlableMeta | null;
23
- notFound: boolean;
24
25
  };
25
26
  export { seoRoute, type SeoRoute, type SeoRouteKind } from './route';
26
27
  /** Publicly readable pages, newest first. Events are posts and have no route of
@@ -35,10 +36,11 @@ export declare const crawlableEntries: ({ indexProfiles, }: {
35
36
  indexProfiles: boolean;
36
37
  }) => Promise<CrawlableEntry[]>;
37
38
  /**
38
- * Metadata for a content route, plus whether it can render at all, so a shared
39
- * post is not described to every crawler as the community homepage and an
40
- * unknown id is not served as a 200. Negatives are cached as well: a bot
41
- * probing unknown ids should not turn each request into a query. Profile
39
+ * Metadata for a content route, or null when the entity is missing or not
40
+ * anonymously readable, so a shared post is not described to every crawler as
41
+ * the community homepage. Missing and unreadable resolve to the same null so an
42
+ * anonymous fetcher cannot distinguish them. Negatives are cached as well: a
43
+ * bot probing unknown ids should not turn each request into a query. Profile
42
44
  * metadata additionally requires the `indexProfiles` flag.
43
45
  */
44
46
  export declare const spaMetaForPath: (pathname: string, { indexProfiles }: {
package/dist/seo/index.js CHANGED
@@ -12,10 +12,10 @@ export { seoRoute } from './route.js';
12
12
  * cap is what keeps a crawler sweep from turning into a full content scan.
13
13
  */
14
14
  const PER_KIND_LIMIT = 1_000;
15
- // Versioned because the cached shape gained `notFound` and later the
16
- // JSON-LD fields: an old entry must never be read as the new one during a
17
- // rolling restart.
18
- const META_CACHE_PREFIX = 'seo:meta:v3:';
15
+ // Versioned because the semantics changed: `null` no longer implies a route
16
+ // that cannot render, so an old entry must never be read as the new one during
17
+ // a rolling restart.
18
+ const META_CACHE_PREFIX = 'seo:meta:v5:';
19
19
  const META_TTL_SECONDS = 5 * 60;
20
20
  /**
21
21
  * An anonymous visitor: no profile, no scopes. That is the whole access rule.
@@ -69,14 +69,14 @@ export const crawlableEntries = async ({ indexProfiles, }) => {
69
69
  const resolveMeta = async (pathname, indexProfiles) => {
70
70
  const route = seoRoute(pathname, { indexProfiles });
71
71
  if (!route)
72
- return { meta: null, notFound: false };
72
+ return { meta: null };
73
73
  if (route.kind === 'post') {
74
74
  const post = await findPost(route.handle);
75
75
  // findPost has no visibility gate of its own — `toFilteredPostsList` applies
76
76
  // it for lists — so the read rule is re-applied here rather than trusted.
77
77
  if (!post ||
78
78
  !(await canReadPost(await capabilitiesConfig(), ANONYMOUS)(post)))
79
- return { meta: null, notFound: true };
79
+ return { meta: null };
80
80
  const body = 'content' in post.data
81
81
  ? post.data.content
82
82
  : 'name' in post.data
@@ -95,7 +95,6 @@ const resolveMeta = async (pathname, indexProfiles) => {
95
95
  authorName: post.profile?.displayName ||
96
96
  (post.profile?.handle ? `@${post.profile.handle}` : undefined),
97
97
  },
98
- notFound: false,
99
98
  };
100
99
  }
101
100
  if (route.kind === 'group') {
@@ -103,32 +102,31 @@ const resolveMeta = async (pathname, indexProfiles) => {
103
102
  // Groups have no visibility column; this mirrors
104
103
  // `groupFilters.publiclyReadable()`, which reads the same capability.
105
104
  if (!group?.capabilities?.none?.add?.includes('core-groups-read'))
106
- return { meta: null, notFound: true };
105
+ return { meta: null };
107
106
  const groupTitle = group.displayName || `@${group.handle}`;
108
107
  return {
109
108
  meta: {
110
109
  title: groupTitle,
111
110
  description: excerpt(group.description, groupTitle),
112
111
  },
113
- notFound: false,
114
112
  };
115
113
  }
116
114
  const profile = await findProfileByHandle(route.handle);
117
115
  if (!profile)
118
- return { meta: null, notFound: true };
116
+ return { meta: null };
119
117
  return {
120
118
  meta: {
121
119
  title: profile.displayName || `@${profile.handle}`,
122
120
  description: excerpt(profile.bio, `@${profile.handle}`),
123
121
  },
124
- notFound: false,
125
122
  };
126
123
  };
127
124
  /**
128
- * Metadata for a content route, plus whether it can render at all, so a shared
129
- * post is not described to every crawler as the community homepage and an
130
- * unknown id is not served as a 200. Negatives are cached as well: a bot
131
- * probing unknown ids should not turn each request into a query. Profile
125
+ * Metadata for a content route, or null when the entity is missing or not
126
+ * anonymously readable, so a shared post is not described to every crawler as
127
+ * the community homepage. Missing and unreadable resolve to the same null so an
128
+ * anonymous fetcher cannot distinguish them. Negatives are cached as well: a
129
+ * bot probing unknown ids should not turn each request into a query. Profile
132
130
  * metadata additionally requires the `indexProfiles` flag.
133
131
  */
134
132
  export const spaMetaForPath = async (pathname, { indexProfiles }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/core",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
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.6.0",
41
- "@openpeepshq/geocoder": "^0.1.2",
42
40
  "@openpeepshq/fetch-client": "^0.2.1",
43
- "@openpeepshq/i18n": "^0.5.0"
41
+ "@openpeepshq/common": "0.6.3",
42
+ "@openpeepshq/geocoder": "^0.1.2",
43
+ "@openpeepshq/i18n": "^0.7.0"
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",
70
- "drizzle-kit": "^0.31.1",
71
- "eslint": "^10.1.0",
68
+ "concurrently": "^9.2.5",
69
+ "drizzle-kit": "^0.31.11",
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": {