@openpeepshq/common 0.19.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/common",
3
- "version": "0.19.0",
3
+ "version": "0.28.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -0,0 +1,40 @@
1
+ import { handleRegexBase } from '../types/forbiddenHandles';
2
+
3
+ /**
4
+ * Single source of truth for the article-slug invariants.
5
+ *
6
+ * A slug is a clean, shareable URL segment for an article: 1–100 characters of
7
+ * lowercase alphanumerics separated by single hyphens. Every layer that reads
8
+ * or writes a slug — the data schema, the SEO route parser, the core write
9
+ * path, and the `slug-support` example plugin — must agree on these exact
10
+ * rules, so they live here and are imported everywhere instead of being
11
+ * re-typed.
12
+ *
13
+ * Keep this in sync with the two partial unique indexes on `posts.body` in
14
+ * `platform/core/src/db/pg/schema/documents.ts` (`posts_slug_instance_unique` /
15
+ * `posts_slug_profile_unique`) — they pin the same shape per scope.
16
+ */
17
+ export const ARTICLE_SLUG_MAX_LENGTH = 100;
18
+
19
+ /** `^[a-z0-9]+(?:-[a-z0-9]+)*$` — one or more lowercase-alnum runs, `-`-separated. */
20
+ export const articleSlugPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
21
+
22
+ /**
23
+ * A valid slug: non-empty, within the length cap, and matching the pattern.
24
+ * A bare empty/whitespace-only string is never a slug.
25
+ */
26
+ export const isValidArticleSlug = (slug: string): boolean =>
27
+ slug.length > 0 &&
28
+ slug.length <= ARTICLE_SLUG_MAX_LENGTH &&
29
+ articleSlugPattern.test(slug);
30
+
31
+ /**
32
+ * A value shaped like a profile handle: 1–16 chars of `[a-zA-Z0-9_-]` — the
33
+ * same `handleRegexBase` the handle rules are built from, so a future change
34
+ * to the handle shape keeps this guard in lockstep. The web router's
35
+ * `/:handle` route owns every bare path segment of this shape, so an
36
+ * *instance-scoped* slug must not be handle-shaped or it would collide with a
37
+ * profile URL.
38
+ */
39
+ export const isHandleShapedSlug = (value: string): boolean =>
40
+ new RegExp(`^${handleRegexBase}$`).test(value);
package/src/lib/index.ts CHANGED
@@ -15,6 +15,7 @@ export * from './contentLength';
15
15
  export * from './attachmentHelpers';
16
16
  export * from './resources';
17
17
  export * from './calendarFeedUrl';
18
+ export * from './articleSlug';
18
19
  export * from './eventIcs';
19
20
  export * from './eventTime';
20
21
  export * from './timeZone';
package/src/types/api.ts CHANGED
@@ -461,6 +461,13 @@ export type RemoveParticipantRequest = z.infer<
461
461
  typeof removeParticipantRequestSchema
462
462
  >;
463
463
 
464
+ /** Sets or clears the room-wide host spotlight (LiveKit room metadata). */
465
+ export const jamSpotlightRequestSchema = z.object({
466
+ identity: z.string().uuid().nullable(),
467
+ });
468
+
469
+ export type JamSpotlightRequest = z.infer<typeof jamSpotlightRequestSchema>;
470
+
464
471
  export interface Thread extends PublicPost {
465
472
  children: Thread[];
466
473
  }
@@ -4,6 +4,10 @@ import ISO6391 from 'iso-639-1';
4
4
  import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
5
5
  import { isEndBeforeStart } from '../lib/eventTime';
6
6
  import { hasVisibleText, postContentWithinBudget } from '../lib/contentLength';
7
+ import {
8
+ ARTICLE_SLUG_MAX_LENGTH,
9
+ articleSlugPattern,
10
+ } from '../lib/articleSlug';
7
11
  import { groupRelationships } from './capabilities';
8
12
  import { capabilitiesSchema, reactionEmojiSchema } from './config';
9
13
  import {
@@ -582,6 +586,18 @@ export const articleSchema = noteBaseSchema
582
586
  type: z.literal('article'),
583
587
  image: z.url().optional(),
584
588
  title: z.string().optional(),
589
+ /** Optional clean URL (`/{slug}` or `/{handle}/{slug}`); enforced unique
590
+ * by partial indexes on `posts.body->>'slug'`. Shape/length come from
591
+ * `articleSlug.ts` (single source of truth). */
592
+ slug: z
593
+ .string()
594
+ .min(1)
595
+ .max(ARTICLE_SLUG_MAX_LENGTH)
596
+ .regex(articleSlugPattern)
597
+ .optional(),
598
+ /** `true` = globally unique `/{slug}` route (admin/moderator);
599
+ * defaults to profile-scoped `/{handle}/{slug}`. */
600
+ instanceScoped: z.boolean().optional(),
585
601
  })
586
602
  .openapi('Article');
587
603