@openpeepshq/common 0.18.0 → 0.20.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.
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Single source of truth for the article-slug invariants.
3
+ *
4
+ * A slug is a clean, shareable URL segment for an article: 1–100 characters of
5
+ * lowercase alphanumerics separated by single hyphens. Every layer that reads
6
+ * or writes a slug — the data schema, the SEO route parser, the core write
7
+ * path, and the `slug-support` example plugin — must agree on these exact
8
+ * rules, so they live here and are imported everywhere instead of being
9
+ * re-typed.
10
+ *
11
+ * Keep this in sync with the two partial unique indexes on `posts.body` in
12
+ * `platform/core/src/db/pg/schema/documents.ts` (`posts_slug_instance_unique` /
13
+ * `posts_slug_profile_unique`) — they pin the same shape per scope.
14
+ */
15
+ export declare const ARTICLE_SLUG_MAX_LENGTH = 100;
16
+ /** `^[a-z0-9]+(?:-[a-z0-9]+)*$` — one or more lowercase-alnum runs, `-`-separated. */
17
+ export declare const articleSlugPattern: RegExp;
18
+ /**
19
+ * A valid slug: non-empty, within the length cap, and matching the pattern.
20
+ * A bare empty/whitespace-only string is never a slug.
21
+ */
22
+ export declare const isValidArticleSlug: (slug: string) => boolean;
23
+ /**
24
+ * A value shaped like a profile handle: 1–16 chars of `[a-zA-Z0-9_-]` — the
25
+ * same `handleRegexBase` the handle rules are built from, so a future change
26
+ * to the handle shape keeps this guard in lockstep. The web router's
27
+ * `/:handle` route owns every bare path segment of this shape, so an
28
+ * *instance-scoped* slug must not be handle-shaped or it would collide with a
29
+ * profile URL.
30
+ */
31
+ export declare const isHandleShapedSlug: (value: string) => boolean;
@@ -0,0 +1,34 @@
1
+ import { handleRegexBase } from '../types/forbiddenHandles.js';
2
+ /**
3
+ * Single source of truth for the article-slug invariants.
4
+ *
5
+ * A slug is a clean, shareable URL segment for an article: 1–100 characters of
6
+ * lowercase alphanumerics separated by single hyphens. Every layer that reads
7
+ * or writes a slug — the data schema, the SEO route parser, the core write
8
+ * path, and the `slug-support` example plugin — must agree on these exact
9
+ * rules, so they live here and are imported everywhere instead of being
10
+ * re-typed.
11
+ *
12
+ * Keep this in sync with the two partial unique indexes on `posts.body` in
13
+ * `platform/core/src/db/pg/schema/documents.ts` (`posts_slug_instance_unique` /
14
+ * `posts_slug_profile_unique`) — they pin the same shape per scope.
15
+ */
16
+ export const ARTICLE_SLUG_MAX_LENGTH = 100;
17
+ /** `^[a-z0-9]+(?:-[a-z0-9]+)*$` — one or more lowercase-alnum runs, `-`-separated. */
18
+ export const articleSlugPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
19
+ /**
20
+ * A valid slug: non-empty, within the length cap, and matching the pattern.
21
+ * A bare empty/whitespace-only string is never a slug.
22
+ */
23
+ export const isValidArticleSlug = (slug) => slug.length > 0 &&
24
+ slug.length <= ARTICLE_SLUG_MAX_LENGTH &&
25
+ articleSlugPattern.test(slug);
26
+ /**
27
+ * A value shaped like a profile handle: 1–16 chars of `[a-zA-Z0-9_-]` — the
28
+ * same `handleRegexBase` the handle rules are built from, so a future change
29
+ * to the handle shape keeps this guard in lockstep. The web router's
30
+ * `/:handle` route owns every bare path segment of this shape, so an
31
+ * *instance-scoped* slug must not be handle-shaped or it would collide with a
32
+ * profile URL.
33
+ */
34
+ export const isHandleShapedSlug = (value) => new RegExp(`^${handleRegexBase}$`).test(value);
@@ -48,7 +48,7 @@ export declare const checkGroupCapabilities: (authData: AuthorizationData, neede
48
48
  missingCapabilities: string[];
49
49
  missingScope: {
50
50
  resource: {
51
- type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
51
+ type: "db" | "self" | "*" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
52
52
  id?: string | undefined;
53
53
  };
54
54
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -59,7 +59,7 @@ export declare const checkPostCapabilities: (authData: AuthorizationData, needed
59
59
  missingCapabilities: string[];
60
60
  missingScope: {
61
61
  resource: {
62
- type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
62
+ type: "db" | "self" | "*" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
63
63
  id?: string | undefined;
64
64
  };
65
65
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -70,7 +70,7 @@ export declare const checkProfileCapabilities: (authData: AuthorizationData, nee
70
70
  missingCapabilities: string[];
71
71
  missingScope: {
72
72
  resource: {
73
- type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
73
+ type: "db" | "self" | "*" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
74
74
  id?: string | undefined;
75
75
  };
76
76
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -81,7 +81,7 @@ export declare const checkReportCapabilities: (authData: AuthorizationData, need
81
81
  missingCapabilities: string[];
82
82
  missingScope: {
83
83
  resource: {
84
- type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
84
+ type: "db" | "self" | "*" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
85
85
  id?: string | undefined;
86
86
  };
87
87
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -92,7 +92,7 @@ export declare const checkAccessTokenCapabilities: (authData: AuthorizationData,
92
92
  missingCapabilities: string[];
93
93
  missingScope: {
94
94
  resource: {
95
- type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
95
+ type: "db" | "self" | "*" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
96
96
  id?: string | undefined;
97
97
  };
98
98
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -103,7 +103,7 @@ export declare const checkAccountCapabilities: (authData: AuthorizationData, nee
103
103
  missingCapabilities: string[];
104
104
  missingScope: {
105
105
  resource: {
106
- type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
106
+ type: "db" | "self" | "*" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
107
107
  id?: string | undefined;
108
108
  };
109
109
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -121,7 +121,7 @@ export declare const checkAccountCreateAuthorization: (authData: AuthorizationDa
121
121
  missingCapabilities: string[];
122
122
  missingScope: {
123
123
  resource: {
124
- type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
124
+ type: "db" | "self" | "*" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
125
125
  id?: string | undefined;
126
126
  };
127
127
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -40,7 +40,7 @@ export declare const groupOwnerRemovalBlocked: ({ targetRoles, ownerCount, }: {
40
40
  targetRoles?: RoleList;
41
41
  ownerCount: number;
42
42
  }) => boolean;
43
- export declare const assignableGroupRoles: (actorIsOwner: boolean) => ("member" | "moderator" | "admin" | "owner")[];
43
+ export declare const assignableGroupRoles: (actorIsOwner: boolean) => ("admin" | "member" | "moderator" | "owner")[];
44
44
  export declare const groupRolesForAssignment: (role: (typeof defaultGroupRoles)[number]) => GroupRelationship[];
45
45
  export declare const canChangeMemberRole: (profile: ProfileWithMeta, group: GroupWithMeta) => boolean;
46
46
  export declare const canAddMember: (profile: ProfileWithMeta, group: GroupWithMeta) => boolean;
@@ -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/dist/lib/index.js CHANGED
@@ -15,6 +15,7 @@ export * from './contentLength.js';
15
15
  export * from './attachmentHelpers.js';
16
16
  export * from './resources.js';
17
17
  export * from './calendarFeedUrl.js';
18
+ export * from './articleSlug.js';
18
19
  export * from './eventIcs.js';
19
20
  export * from './eventTime.js';
20
21
  export * from './timeZone.js';
@@ -49,7 +49,7 @@ export declare const calculateEffectiveRsvps: (post: PublicPost, recurrenceId?:
49
49
  discoverable?: boolean | undefined;
50
50
  deletedAt?: string | null | undefined;
51
51
  };
52
- roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
52
+ roles?: ("admin" | "none" | "local" | "member" | "moderator" | "owner" | "invited")[] | null | undefined;
53
53
  }[] | undefined;
54
54
  deletedAt?: string | null | undefined;
55
55
  avatar?: string | null | undefined;
@@ -114,7 +114,7 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string, rec
114
114
  discoverable?: boolean | undefined;
115
115
  deletedAt?: string | null | undefined;
116
116
  };
117
- roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
117
+ roles?: ("admin" | "none" | "local" | "member" | "moderator" | "owner" | "invited")[] | null | undefined;
118
118
  }[] | undefined;
119
119
  deletedAt?: string | null | undefined;
120
120
  avatar?: string | null | undefined;
@@ -182,7 +182,7 @@ export declare const listedRsvps: (rsvps: PublicRsvp[]) => {
182
182
  discoverable?: boolean | undefined;
183
183
  deletedAt?: string | null | undefined;
184
184
  };
185
- roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
185
+ roles?: ("admin" | "none" | "local" | "member" | "moderator" | "owner" | "invited")[] | null | undefined;
186
186
  }[] | undefined;
187
187
  deletedAt?: string | null | undefined;
188
188
  avatar?: string | null | undefined;