@openpeepshq/core 0.17.0 → 0.19.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.
@@ -134,6 +134,13 @@
134
134
  "when": 1795038881063,
135
135
  "tag": "0018_add_calendar_feed_tokens",
136
136
  "breakpoints": true
137
+ },
138
+ {
139
+ "idx": 22,
140
+ "version": "7",
141
+ "when": 1795656890705,
142
+ "tag": "0022_add_article_slug_indexes",
143
+ "breakpoints": true
137
144
  }
138
145
  ]
139
146
  }
@@ -25,7 +25,7 @@ export declare const addMember: (db: import("../db").PgDb, from: {
25
25
  discoverable?: boolean | undefined;
26
26
  deletedAt?: string | null | undefined;
27
27
  };
28
- roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
28
+ roles?: ("admin" | "none" | "local" | "member" | "moderator" | "owner" | "invited")[] | null | undefined;
29
29
  }[] | undefined;
30
30
  deletedAt?: string | null | undefined;
31
31
  avatar?: string | null | undefined;
@@ -77,11 +77,11 @@ export declare const addMember: (db: import("../db").PgDb, from: {
77
77
  lastPostAt?: string | null | undefined;
78
78
  deletedAt?: string | null | undefined;
79
79
  }, data?: {
80
- roles?: ("local" | "member" | "none" | "owner" | "moderator" | "admin" | "invited")[] | null | undefined;
80
+ roles?: ("local" | "member" | "none" | "owner" | "admin" | "moderator" | "invited")[] | null | undefined;
81
81
  } & {
82
82
  id?: string;
83
83
  }) => Promise<import("../db/pg/map").WithId<{
84
- roles?: ("local" | "member" | "none" | "owner" | "moderator" | "admin" | "invited")[] | null | undefined;
84
+ roles?: ("local" | "member" | "none" | "owner" | "admin" | "moderator" | "invited")[] | null | undefined;
85
85
  } & {
86
86
  _from: string;
87
87
  _to: string;
@@ -111,7 +111,7 @@ export declare const removeMember: (db: import("../db").PgDb, from: {
111
111
  discoverable?: boolean | undefined;
112
112
  deletedAt?: string | null | undefined;
113
113
  };
114
- roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
114
+ roles?: ("admin" | "none" | "local" | "member" | "moderator" | "owner" | "invited")[] | null | undefined;
115
115
  }[] | undefined;
116
116
  deletedAt?: string | null | undefined;
117
117
  avatar?: string | null | undefined;
@@ -188,7 +188,7 @@ export declare const updateMember: (db: import("../db").PgDb, from: {
188
188
  discoverable?: boolean | undefined;
189
189
  deletedAt?: string | null | undefined;
190
190
  };
191
- roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
191
+ roles?: ("admin" | "none" | "local" | "member" | "moderator" | "owner" | "invited")[] | null | undefined;
192
192
  }[] | undefined;
193
193
  deletedAt?: string | null | undefined;
194
194
  avatar?: string | null | undefined;
@@ -240,6 +240,6 @@ export declare const updateMember: (db: import("../db").PgDb, from: {
240
240
  lastPostAt?: string | null | undefined;
241
241
  deletedAt?: string | null | undefined;
242
242
  }, data?: {
243
- roles?: ("local" | "member" | "none" | "owner" | "moderator" | "admin" | "invited")[] | null | undefined;
243
+ roles?: ("local" | "member" | "none" | "owner" | "admin" | "moderator" | "invited")[] | null | undefined;
244
244
  } | undefined) => Promise<void>;
245
245
  export declare const canSeeGroupFilter: (profile?: ProfileWithMeta) => PgFilter<GroupWithMeta> | undefined;
@@ -2,6 +2,17 @@ import { AuthorizationData, PostWithMeta, Post, PostType, Profile, DbPost, DbBas
2
2
  import { ProfileWithMeta } from '@openpeepshq/common/types';
3
3
  import type { Mapping, ObjectSort, PgFilter } from '../db/pg/map';
4
4
  export declare const findPost: (id: string, authData?: AuthorizationData) => Promise<PostWithMeta | undefined>;
5
+ /**
6
+ * Resolve an article by its slug. Instance-scoped slugs are globally unique;
7
+ * profile-scoped slugs are unique per creator. The query mirrors the two
8
+ * partial unique indexes added in `0022_add_article_slug_indexes.sql`, so a
9
+ * matching row is always the only row that could own the slug.
10
+ *
11
+ * Pass `profileHandle` to resolve a profile-scoped slug against that profile;
12
+ * pass `instanceScoped: true` to resolve a globally-unique slug; omit both for
13
+ * an unscoped profile-scoped lookup (matches any creator).
14
+ */
15
+ export declare const findPostBySlug: (slug: string, profileHandle?: string, instanceScoped?: boolean) => Promise<PostWithMeta | null>;
5
16
  /** Lean post load for capability checks (no nested reply/repost). */
6
17
  export declare const findPostsForAuth: (ids: string[], authData?: AuthorizationData) => Promise<PostWithMeta[]>;
7
18
  export declare const postContext: (authData: AuthorizationData, id: string, depth: number, direction: "ancestors" | "descendents", contextMapping?: Mapping<DbPost>) => Promise<PostWithMeta[]>;
@@ -217,6 +228,8 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
217
228
  language?: string | undefined;
218
229
  image?: string | undefined;
219
230
  title?: string | undefined;
231
+ slug?: string | undefined;
232
+ instanceScoped?: boolean | undefined;
220
233
  } | {
221
234
  type: "resource";
222
235
  title: string;
@@ -1,7 +1,10 @@
1
+ import { sql } from 'drizzle-orm';
1
2
  import { parseFeedFormat } from '@openpeepshq/common';
2
3
  import { blockedPairIds, isBlockedPair, isOneToOneDm, participantIds, } from '@openpeepshq/common/lib';
3
4
  import { allpeepDb, collectionInfos } from '../db/index.js';
5
+ import { posts } from '../db/pg/schema/index.js';
4
6
  import { edgeFilters, postFilters } from '../db/pg/filters/index.js';
7
+ import { findProfileByHandle } from '../profiles/finders.js';
5
8
  import { contextRelation, conversationLeavesMappingForProfile, postContextMappingForProfile, postsAuthMapping, postsMappingForProfile, repostsOfPostRelationForProfile, postIdsMapping, } from './mapping.js';
6
9
  import { audienceConnectionFinder, localFeedFilter, mentionsConnectionFinder, myFeedFilter, myFeedGroupMembershipFilter, toFilteredPostsList, transformPost, } from './helpers/index.js';
7
10
  import { addActivityStart, addQuerySort, addStart, sortOldestFirst, } from '../db/helpers.js';
@@ -43,6 +46,51 @@ export const findPost = async (id, authData) => {
43
46
  .then((post) => (post ? transformPost(post, profile) : undefined))
44
47
  .then((post) => hideBlockedAuthorPost(post, profile));
45
48
  };
49
+ /**
50
+ * Resolve an article by its slug. Instance-scoped slugs are globally unique;
51
+ * profile-scoped slugs are unique per creator. The query mirrors the two
52
+ * partial unique indexes added in `0022_add_article_slug_indexes.sql`, so a
53
+ * matching row is always the only row that could own the slug.
54
+ *
55
+ * Pass `profileHandle` to resolve a profile-scoped slug against that profile;
56
+ * pass `instanceScoped: true` to resolve a globally-unique slug; omit both for
57
+ * an unscoped profile-scoped lookup (matches any creator).
58
+ */
59
+ export const findPostBySlug = async (slug, profileHandle, instanceScoped) => {
60
+ let profileId;
61
+ if (profileHandle && !instanceScoped) {
62
+ const profile = await findProfileByHandle(profileHandle);
63
+ profileId = profile?.id;
64
+ // A profile-scoped slug under a non-existent profile cannot resolve.
65
+ if (!profileId)
66
+ return null;
67
+ }
68
+ const bodySlug = sql.raw(`posts.body ->> 'slug'`);
69
+ const bodyInstanceScoped = sql.raw(`posts.body ->> 'instanceScoped'`);
70
+ const conditions = sql `
71
+ ${posts.type} = 'article' AND ${posts.deletedAt} IS NULL AND ${bodySlug} = ${slug}
72
+ `;
73
+ // Scope predicates match the two partial unique indexes
74
+ // (`posts_slug_instance_unique` / `posts_slug_profile_unique`) exactly, so
75
+ // the planner can use them. `instanceScoped` is schema-constrained to a
76
+ // boolean, so the profile set is precisely `NULL` or `'false'`.
77
+ const scope = instanceScoped
78
+ ? sql `${bodyInstanceScoped} = 'true'`
79
+ : sql `(${bodyInstanceScoped} IS NULL OR ${bodyInstanceScoped} = 'false')`;
80
+ const creator = profileId
81
+ ? sql ` AND ${posts.creatorId} = ${profileId}`
82
+ : sql ``;
83
+ const rows = await allpeepDb().then(({ db }) => db
84
+ .select()
85
+ .from(posts)
86
+ .where(sql `${conditions} AND (${scope})${creator}`)
87
+ .limit(1));
88
+ const row = rows[0];
89
+ if (!row)
90
+ return null;
91
+ const post = await transformPost(row);
92
+ return hideBlockedAuthorPost(post, undefined) ?? null;
93
+ };
46
94
  /** Lean post load for capability checks (no nested reply/repost). */
47
95
  export const findPostsForAuth = async (ids, authData) => {
48
96
  if (ids.length === 0)
@@ -208,6 +208,8 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
208
208
  language?: string | undefined;
209
209
  image?: string | undefined;
210
210
  title?: string | undefined;
211
+ slug?: string | undefined;
212
+ instanceScoped?: boolean | undefined;
211
213
  } | {
212
214
  type: "resource";
213
215
  title: string;
@@ -444,6 +446,8 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
444
446
  language?: string | undefined;
445
447
  image?: string | undefined;
446
448
  title?: string | undefined;
449
+ slug?: string | undefined;
450
+ instanceScoped?: boolean | undefined;
447
451
  } | {
448
452
  type: "resource";
449
453
  title: string;
@@ -710,6 +714,8 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
710
714
  language?: string | undefined;
711
715
  image?: string | undefined;
712
716
  title?: string | undefined;
717
+ slug?: string | undefined;
718
+ instanceScoped?: boolean | undefined;
713
719
  } | {
714
720
  type: "resource";
715
721
  title: string;
@@ -946,6 +952,8 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
946
952
  language?: string | undefined;
947
953
  image?: string | undefined;
948
954
  title?: string | undefined;
955
+ slug?: string | undefined;
956
+ instanceScoped?: boolean | undefined;
949
957
  } | {
950
958
  type: "resource";
951
959
  title: string;
@@ -1,5 +1,6 @@
1
1
  export * from './finders';
2
2
  export * from './mutations';
3
+ export * from './slugPolicy';
3
4
  export * from './mapping';
4
5
  export { CONTEXT_NODE_CAP, collectReplyClosureIds, loadReplyContextPosts, } from './contextClosure';
5
6
  export { loadThreadPreviewReplies, THREAD_PREVIEW_LIMIT, } from './threadPreview';
@@ -1,5 +1,6 @@
1
1
  export * from './finders.js';
2
2
  export * from './mutations.js';
3
+ export * from './slugPolicy.js';
3
4
  export * from './mapping.js';
4
5
  export { CONTEXT_NODE_CAP, collectReplyClosureIds, loadReplyContextPosts, } from './contextClosure.js';
5
6
  export { loadThreadPreviewReplies, THREAD_PREVIEW_LIMIT, } from './threadPreview.js';
@@ -208,6 +208,8 @@ export declare const threadPreviewMappingForProfile: (profile?: {
208
208
  language?: string | undefined;
209
209
  image?: string | undefined;
210
210
  title?: string | undefined;
211
+ slug?: string | undefined;
212
+ instanceScoped?: boolean | undefined;
211
213
  } | {
212
214
  type: "resource";
213
215
  title: string;
@@ -456,6 +458,8 @@ export declare const postsWithReplyCountMapping: Mapping<{
456
458
  language?: string | undefined;
457
459
  image?: string | undefined;
458
460
  title?: string | undefined;
461
+ slug?: string | undefined;
462
+ instanceScoped?: boolean | undefined;
459
463
  } | {
460
464
  type: "resource";
461
465
  title: string;
@@ -699,6 +703,8 @@ export declare const postsWithReplyCountMapping: Mapping<{
699
703
  language?: string | undefined;
700
704
  image?: string | undefined;
701
705
  title?: string | undefined;
706
+ slug?: string | undefined;
707
+ instanceScoped?: boolean | undefined;
702
708
  } | {
703
709
  type: "resource";
704
710
  title: string;
@@ -946,6 +952,8 @@ export declare const postsWithReplyCountMapping: Mapping<{
946
952
  language?: string | undefined;
947
953
  image?: string | undefined;
948
954
  title?: string | undefined;
955
+ slug?: string | undefined;
956
+ instanceScoped?: boolean | undefined;
949
957
  } | {
950
958
  type: "resource";
951
959
  title: string;
@@ -1190,6 +1198,8 @@ export declare const postsWithReplyToCountMapping: Mapping<{
1190
1198
  language?: string | undefined;
1191
1199
  image?: string | undefined;
1192
1200
  title?: string | undefined;
1201
+ slug?: string | undefined;
1202
+ instanceScoped?: boolean | undefined;
1193
1203
  } | {
1194
1204
  type: "resource";
1195
1205
  title: string;
@@ -1433,6 +1443,8 @@ export declare const postsWithReplyToCountMapping: Mapping<{
1433
1443
  language?: string | undefined;
1434
1444
  image?: string | undefined;
1435
1445
  title?: string | undefined;
1446
+ slug?: string | undefined;
1447
+ instanceScoped?: boolean | undefined;
1436
1448
  } | {
1437
1449
  type: "resource";
1438
1450
  title: string;
@@ -1680,6 +1692,8 @@ export declare const postsWithReplyToCountMapping: Mapping<{
1680
1692
  language?: string | undefined;
1681
1693
  image?: string | undefined;
1682
1694
  title?: string | undefined;
1695
+ slug?: string | undefined;
1696
+ instanceScoped?: boolean | undefined;
1683
1697
  } | {
1684
1698
  type: "resource";
1685
1699
  title: string;
@@ -1924,6 +1938,8 @@ export declare const postsMapping: Mapping<{
1924
1938
  language?: string | undefined;
1925
1939
  image?: string | undefined;
1926
1940
  title?: string | undefined;
1941
+ slug?: string | undefined;
1942
+ instanceScoped?: boolean | undefined;
1927
1943
  } | {
1928
1944
  type: "resource";
1929
1945
  title: string;
@@ -2165,6 +2181,8 @@ export declare const postsAuthMapping: Mapping<{
2165
2181
  language?: string | undefined;
2166
2182
  image?: string | undefined;
2167
2183
  title?: string | undefined;
2184
+ slug?: string | undefined;
2185
+ instanceScoped?: boolean | undefined;
2168
2186
  } | {
2169
2187
  type: "resource";
2170
2188
  title: string;
@@ -2407,6 +2425,8 @@ export declare const postsMappingForProfile: (profile?: {
2407
2425
  language?: string | undefined;
2408
2426
  image?: string | undefined;
2409
2427
  title?: string | undefined;
2428
+ slug?: string | undefined;
2429
+ instanceScoped?: boolean | undefined;
2410
2430
  } | {
2411
2431
  type: "resource";
2412
2432
  title: string;
@@ -2649,6 +2669,8 @@ export declare const postContextMappingForProfile: (profile?: {
2649
2669
  language?: string | undefined;
2650
2670
  image?: string | undefined;
2651
2671
  title?: string | undefined;
2672
+ slug?: string | undefined;
2673
+ instanceScoped?: boolean | undefined;
2652
2674
  } | {
2653
2675
  type: "resource";
2654
2676
  title: string;
@@ -2890,6 +2912,8 @@ export declare const conversationLeavesMapping: Mapping<{
2890
2912
  language?: string | undefined;
2891
2913
  image?: string | undefined;
2892
2914
  title?: string | undefined;
2915
+ slug?: string | undefined;
2916
+ instanceScoped?: boolean | undefined;
2893
2917
  } | {
2894
2918
  type: "resource";
2895
2919
  title: string;
@@ -3132,6 +3156,8 @@ export declare const conversationLeavesMappingForProfile: (profile?: {
3132
3156
  language?: string | undefined;
3133
3157
  image?: string | undefined;
3134
3158
  title?: string | undefined;
3159
+ slug?: string | undefined;
3160
+ instanceScoped?: boolean | undefined;
3135
3161
  } | {
3136
3162
  type: "resource";
3137
3163
  title: string;
@@ -3372,6 +3398,8 @@ export declare const postIdsMapping: Mapping<{
3372
3398
  language?: string | undefined;
3373
3399
  image?: string | undefined;
3374
3400
  title?: string | undefined;
3401
+ slug?: string | undefined;
3402
+ instanceScoped?: boolean | undefined;
3375
3403
  } | {
3376
3404
  type: "resource";
3377
3405
  title: string;
@@ -209,6 +209,8 @@ export declare const retractReaction: (post: PostWithMeta, profile: Profile, dat
209
209
  language?: string | undefined;
210
210
  image?: string | undefined;
211
211
  title?: string | undefined;
212
+ slug?: string | undefined;
213
+ instanceScoped?: boolean | undefined;
212
214
  } | {
213
215
  type: "resource";
214
216
  title: string;
@@ -445,6 +447,8 @@ export declare const retractReaction: (post: PostWithMeta, profile: Profile, dat
445
447
  language?: string | undefined;
446
448
  image?: string | undefined;
447
449
  title?: string | undefined;
450
+ slug?: string | undefined;
451
+ instanceScoped?: boolean | undefined;
448
452
  } | {
449
453
  type: "resource";
450
454
  title: string;
@@ -9,6 +9,7 @@ import { bumpConversationActivity } from './activity.js';
9
9
  import { findGroup } from '../groups/finders.js';
10
10
  import { findLatestThreadPostId, listOneToOneConversationRootLeaves, } from './conversationQueries.js';
11
11
  import { findPost, findPostsForAuth } from './finders.js';
12
+ import { applyArticleSlugPolicy } from './slugPolicy.js';
12
13
  import { profilesCache } from '../profiles/cache.js';
13
14
  import { findOrCreateHashtag } from '../hashtags/index.js';
14
15
  import { hub } from '../events/index.js';
@@ -30,6 +31,11 @@ profile, postData, relations = {}) => {
30
31
  if (data.type === 'event') {
31
32
  data = normalizeEventDataForSave(data);
32
33
  }
34
+ if (data.type === 'article') {
35
+ // Server-side slug permission model (instance-scoped is role-gated,
36
+ // handle-shaped slugs are unresolvable). See `applyArticleSlugPolicy`.
37
+ data = applyArticleSlugPolicy(data, profile);
38
+ }
33
39
  const { db } = await allpeepDb();
34
40
  const repostedPost = relations.repostId
35
41
  ? await postsMapping.find(db, relations.repostId)
@@ -136,7 +142,9 @@ export const updatePost = async (post, profile, data) => {
136
142
  const previousEvent = post.data?.type === 'event' ? post.data : undefined;
137
143
  const normalized = data.type === 'event'
138
144
  ? withoutCommunityJamNotifyEveryone(normalizeEventDataForSave(data), post.visibility, profile.roles)
139
- : data;
145
+ : data.type === 'article'
146
+ ? applyArticleSlugPolicy(data, profile)
147
+ : data;
140
148
  const dataForDb = normalized.type === 'event'
141
149
  ? eventDataForDbUpdate(previousEvent, normalized)
142
150
  : normalized;
@@ -0,0 +1,20 @@
1
+ import type { Article, Profile, Role } from '@openpeepshq/common/types';
2
+ /**
3
+ * Enforce the slug permission model on an article body at write time:
4
+ *
5
+ * - `instanceScoped` is dropped unless the caller holds an
6
+ * instance-scoped role, so a normal member can never claim a
7
+ * globally-unique `/{slug}` route.
8
+ * - A *handle-shaped* slug is dropped when the effective scope is
9
+ * instance-scoped: an `/{slug}` route of that shape is owned by the
10
+ * web router's `/:handle` route, so it would never resolve. Profile-scoped
11
+ * slugs keep their second `/{handle}` segment and resolve fine.
12
+ *
13
+ * Returns the (possibly stripped) data. Stripping rather than throwing keeps
14
+ * the post saveable when the plugin (or a stale client) sends a field the
15
+ * caller may not use; the uniqueness indexes remain the data-consistency
16
+ * backstop.
17
+ */
18
+ export declare const applyArticleSlugPolicy: (data: Article, profile: Profile & {
19
+ roles?: Role[];
20
+ }) => Article;
@@ -0,0 +1,42 @@
1
+ import { isHandleShapedSlug } from '@openpeepshq/common/lib';
2
+ /**
3
+ * Roles allowed to claim an *instance-scoped* article slug (a globally unique
4
+ * `/{slug}` route). Mirrors the `slug-support` plugin's `instanceScopedRoles`
5
+ * default; the plugin is the friendly UI gate, this is the server-side
6
+ * containment so the permission model cannot be bypassed by writing
7
+ * `instanceScoped: true` straight into the post body through the core
8
+ * endpoints (which parse the extended `articleSchema`).
9
+ */
10
+ const INSTANCE_SCOPED_ROLES = ['admin', 'moderator'];
11
+ const hasInstanceScopedRole = (profile) => (profile.roles ?? []).some((role) => INSTANCE_SCOPED_ROLES.includes(role.key));
12
+ /**
13
+ * Enforce the slug permission model on an article body at write time:
14
+ *
15
+ * - `instanceScoped` is dropped unless the caller holds an
16
+ * instance-scoped role, so a normal member can never claim a
17
+ * globally-unique `/{slug}` route.
18
+ * - A *handle-shaped* slug is dropped when the effective scope is
19
+ * instance-scoped: an `/{slug}` route of that shape is owned by the
20
+ * web router's `/:handle` route, so it would never resolve. Profile-scoped
21
+ * slugs keep their second `/{handle}` segment and resolve fine.
22
+ *
23
+ * Returns the (possibly stripped) data. Stripping rather than throwing keeps
24
+ * the post saveable when the plugin (or a stale client) sends a field the
25
+ * caller may not use; the uniqueness indexes remain the data-consistency
26
+ * backstop.
27
+ */
28
+ export const applyArticleSlugPolicy = (data, profile) => {
29
+ if (!data.slug)
30
+ return data;
31
+ const next = { ...data };
32
+ // Instance scope is role-gated; a member's `instanceScoped: true` is dropped.
33
+ const instanceScoped = data.instanceScoped === true && hasInstanceScopedRole(profile);
34
+ next.instanceScoped = instanceScoped ? true : undefined;
35
+ // A *handle-shaped* slug is only dropped when the effective scope is
36
+ // instance-scoped: an `/{slug}` route of that shape collides with the
37
+ // web router's `/:handle` route and could never resolve. A profile-scoped
38
+ // `/{handle}/{slug}` has a second segment, so it resolves fine and is kept.
39
+ if (instanceScoped && isHandleShapedSlug(next.slug))
40
+ delete next.slug;
41
+ return next;
42
+ };
package/dist/seo/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { capabilitiesConfig } from '../config/index.js';
2
2
  import { findGroupByHandle, listGroups } from '../groups/index.js';
3
- import { findPost, listPosts } from '../posts/index.js';
3
+ import { findPost, findPostBySlug, listPosts } from '../posts/index.js';
4
4
  import { canReadPost } from '../posts/helpers/filters.js';
5
5
  import { findProfileByHandle, listProfiles } from '../profiles/index.js';
6
6
  import { getSharedConnection } from '../redis/index.js';
@@ -56,6 +56,23 @@ export const crawlableEntries = async ({ indexProfiles, }) => {
56
56
  path: `/posts/${post.id}`,
57
57
  updatedAt: post.updatedAt,
58
58
  })),
59
+ // Slug URLs for articles that have one — both spellings point at the
60
+ // same content, but only the canonical one (instance- or profile-scoped)
61
+ // goes in the sitemap.
62
+ ...posts.flatMap((post) => {
63
+ const slug = 'slug' in post.data ? post.data.slug : undefined;
64
+ if (!slug)
65
+ return [];
66
+ const instanceScoped = 'instanceScoped' in post.data
67
+ ? post.data.instanceScoped === true
68
+ : false;
69
+ if (instanceScoped)
70
+ return [{ path: `/${slug}`, updatedAt: post.updatedAt }];
71
+ const handle = post.profile?.handle;
72
+ return handle
73
+ ? [{ path: `/${handle}/${slug}`, updatedAt: post.updatedAt }]
74
+ : [];
75
+ }),
59
76
  ...groups.slice(0, PER_KIND_LIMIT).map((group) => ({
60
77
  path: `/groups/@${group.handle}`,
61
78
  updatedAt: group.updatedAt,
@@ -73,33 +90,14 @@ const resolveMeta = async (pathname, indexProfiles) => {
73
90
  const route = seoRoute(pathname, { indexProfiles });
74
91
  if (!route)
75
92
  return { meta: null };
76
- if (route.kind === 'post') {
77
- const post = await findPost(route.handle);
78
- // findPost has no visibility gate of its own — `toFilteredPostsList` applies
79
- // it for lists — so the read rule is re-applied here rather than trusted.
80
- if (!post ||
81
- !(await canReadPost(await capabilitiesConfig(), ANONYMOUS)(post)))
82
- return { meta: null };
83
- const body = 'content' in post.data
84
- ? post.data.content
85
- : 'name' in post.data
86
- ? post.data.name
87
- : '';
88
- const heading = 'title' in post.data && post.data.title
89
- ? post.data.title
90
- : excerpt(body, post.profile?.displayName ?? 'Post');
91
- return {
92
- meta: {
93
- title: heading,
94
- description: excerpt(body, heading),
95
- kind: 'post',
96
- datePublished: post.createdAt,
97
- dateModified: post.updatedAt,
98
- authorName: post.profile?.displayName ||
99
- (post.profile?.handle ? `@${post.profile.handle}` : undefined),
100
- },
101
- };
102
- }
93
+ // Slug routes are articles, so the post branch below resolves them; a
94
+ // slug lookup fails (undefined) when no matching article exists, which the
95
+ // null check in the post branch already handles.
96
+ const foundPost = route.kind === 'post'
97
+ ? await findPost(route.handle)
98
+ : route.kind === 'slug'
99
+ ? await findPostBySlug(route.slug, route.handle, route.instanceScoped)
100
+ : undefined;
103
101
  if (route.kind === 'group') {
104
102
  const group = await findGroupByHandle(route.handle);
105
103
  // Groups have no visibility column; this mirrors
@@ -114,13 +112,40 @@ const resolveMeta = async (pathname, indexProfiles) => {
114
112
  },
115
113
  };
116
114
  }
117
- const profile = await findProfileByHandle(route.handle);
118
- if (!profile)
115
+ if (route.kind === 'profile') {
116
+ const profile = await findProfileByHandle(route.handle);
117
+ if (!profile)
118
+ return { meta: null };
119
+ return {
120
+ meta: {
121
+ title: profile.displayName || `@${profile.handle}`,
122
+ description: excerpt(profile.bio, `@${profile.handle}`),
123
+ },
124
+ };
125
+ }
126
+ const post = foundPost;
127
+ // findPost has no visibility gate of its own — `toFilteredPostsList` applies
128
+ // it for lists — so the read rule is re-applied here rather than trusted.
129
+ if (!post ||
130
+ !(await canReadPost(await capabilitiesConfig(), ANONYMOUS)(post)))
119
131
  return { meta: null };
132
+ const body = 'content' in post.data
133
+ ? post.data.content
134
+ : 'name' in post.data
135
+ ? post.data.name
136
+ : '';
137
+ const heading = 'title' in post.data && post.data.title
138
+ ? post.data.title
139
+ : excerpt(body, post.profile?.displayName ?? 'Post');
120
140
  return {
121
141
  meta: {
122
- title: profile.displayName || `@${profile.handle}`,
123
- description: excerpt(profile.bio, `@${profile.handle}`),
142
+ title: heading,
143
+ description: excerpt(body, heading),
144
+ kind: 'post',
145
+ datePublished: post.createdAt,
146
+ dateModified: post.updatedAt,
147
+ authorName: post.profile?.displayName ||
148
+ (post.profile?.handle ? `@${post.profile.handle}` : undefined),
124
149
  },
125
150
  };
126
151
  };
@@ -1,13 +1,39 @@
1
- /**
2
- * Pure parsing of the content routes the crawler layer recognises. Kept free of
3
- * data-layer imports so the rules are unit-testable and so this can be loaded
4
- * where opening a database connection would be wrong.
5
- */
6
- export type SeoRouteKind = 'post' | 'group' | 'profile';
1
+ export type SeoRouteKind = 'post' | 'group' | 'profile' | 'slug';
7
2
  export type SeoRoute = {
8
- kind: SeoRouteKind;
3
+ kind: 'post';
4
+ handle: string;
5
+ } | {
6
+ kind: 'group';
7
+ handle: string;
8
+ } | {
9
+ kind: 'profile';
9
10
  handle: string;
11
+ } | {
12
+ kind: 'slug';
13
+ /** The article slug as written in the path. */
14
+ slug: string;
15
+ /** Profile-scoped slugs resolve against this profile's handle. */
16
+ handle?: string;
17
+ instanceScoped: boolean;
10
18
  };
19
+ /**
20
+ * Top-level segments that own a route in the web app and therefore can never
21
+ * be a slug path. Kept in sync with `platform/web` routes.
22
+ */
23
+ export declare const RESERVED_TOP_LEVEL_ROUTES: string[];
24
+ /**
25
+ * A profile handle is 1–16 characters of `[a-zA-Z0-9_-]`, so the web router's
26
+ * `/:handle` route owns every bare slug-shaped segment of length ≤ 16 (a slug
27
+ * is lowercase/digits/hyphens only, a subset of handle shape). Such a segment
28
+ * can never resolve as an instance-scoped slug — `/my-slug` loads the profile
29
+ * page for handle `my-slug`, or 404s. Longer slug-shaped segments can be no
30
+ * handle, so only those qualify as instance slugs. The plugin's availability
31
+ * check enforces the same rule at write time. The shape is shared from
32
+ * `@openpeepshq/common/lib` (single source of truth).
33
+ */
34
+ export declare const isHandleShaped: (value: string) => boolean;
35
+ /** Profile sub-routes the web router owns under `/:handle/<x>`. */
36
+ export declare const RESERVED_PROFILE_SUBROUTES: string[];
11
37
  /**
12
38
  * A trailing slash addresses the same page as the bare path; `webNavigator`
13
39
  * never emits one, so the canonical spelling has none. Tolerating it here stops