@openpeepshq/common 0.4.0 → 0.5.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.
Files changed (69) hide show
  1. package/dist/lib/adminSections.d.ts +4 -0
  2. package/dist/lib/adminSections.js +5 -0
  3. package/dist/lib/attachmentHelpers.js +5 -1
  4. package/dist/lib/capabilitiesHelpers.d.ts +9 -0
  5. package/dist/lib/capabilitiesHelpers.js +9 -0
  6. package/dist/lib/csvHelpers.d.ts +2 -0
  7. package/dist/lib/csvHelpers.js +13 -0
  8. package/dist/lib/eventRecurrence.d.ts +9 -0
  9. package/dist/lib/eventRecurrence.js +17 -9
  10. package/dist/lib/eventWaitlist.d.ts +58 -0
  11. package/dist/lib/eventWaitlist.js +217 -0
  12. package/dist/lib/index.d.ts +1 -0
  13. package/dist/lib/index.js +1 -0
  14. package/dist/lib/markdownHelpers.d.ts +12 -3
  15. package/dist/lib/markdownHelpers.js +115 -6
  16. package/dist/lib/postHelpers.d.ts +27 -5
  17. package/dist/lib/postHelpers.js +72 -9
  18. package/dist/lib/profileHelpers.d.ts +12 -2
  19. package/dist/lib/profileHelpers.js +19 -2
  20. package/dist/lib/resources.d.ts +29 -1
  21. package/dist/lib/resources.js +74 -2
  22. package/dist/lib/utils.js +11 -11
  23. package/dist/types/admin-livekit.d.ts +23 -0
  24. package/dist/types/admin-livekit.js +18 -0
  25. package/dist/types/admin-media.d.ts +41 -0
  26. package/dist/types/admin-media.js +20 -0
  27. package/dist/types/api.d.ts +19945 -3526
  28. package/dist/types/api.js +15 -9
  29. package/dist/types/capabilities.d.ts +2 -2
  30. package/dist/types/capabilities.js +3 -0
  31. package/dist/types/config.d.ts +3 -0
  32. package/dist/types/config.js +6 -0
  33. package/dist/types/db.d.ts +65 -22
  34. package/dist/types/forbiddenHandles.d.ts +28 -0
  35. package/dist/types/forbiddenHandles.js +75 -0
  36. package/dist/types/index.d.ts +2 -0
  37. package/dist/types/index.js +2 -0
  38. package/dist/types/internal.d.ts +163 -44
  39. package/dist/types/models.d.ts +28 -14
  40. package/dist/types/models.js +27 -28
  41. package/dist/types/notifications.d.ts +2 -0
  42. package/dist/types/notifications.js +4 -2
  43. package/dist/types/roleDefaults.js +109 -95
  44. package/dist/types/stats.d.ts +348 -108
  45. package/package.json +7 -6
  46. package/src/lib/adminSections.ts +5 -0
  47. package/src/lib/attachmentHelpers.ts +18 -12
  48. package/src/lib/capabilitiesHelpers.ts +15 -0
  49. package/src/lib/csvHelpers.ts +19 -3
  50. package/src/lib/eventRecurrence.ts +19 -10
  51. package/src/lib/eventWaitlist.ts +325 -0
  52. package/src/lib/index.ts +1 -0
  53. package/src/lib/markdownHelpers.ts +121 -7
  54. package/src/lib/postHelpers.ts +101 -11
  55. package/src/lib/profileHelpers.ts +31 -2
  56. package/src/lib/resources.ts +105 -2
  57. package/src/lib/utils.ts +40 -31
  58. package/src/types/admin-livekit.ts +24 -0
  59. package/src/types/admin-media.ts +29 -0
  60. package/src/types/api.ts +19 -9
  61. package/src/types/auth.ts +2 -2
  62. package/src/types/capabilities.ts +3 -0
  63. package/src/types/config.ts +6 -0
  64. package/src/types/forbiddenHandles.ts +103 -0
  65. package/src/types/index.ts +2 -0
  66. package/src/types/models.ts +53 -33
  67. package/src/types/notifications.ts +7 -7
  68. package/src/types/roleDefaults.ts +115 -96
  69. package/src/types/stripe.ts +3 -1
@@ -0,0 +1,103 @@
1
+ import { z } from 'zod';
2
+
3
+ export const handleRegexBase = '[a-zA-Z0-9_-]{1,16}';
4
+
5
+ export const handleRegex = new RegExp(`^${handleRegexBase}$`);
6
+
7
+ export const HANDLE_RESERVED_MESSAGE = 'Handle is reserved';
8
+
9
+ /**
10
+ * Platform routes and system names. Always reserved. Community config can add
11
+ * names, but these stay in code so an admin cannot delete them.
12
+ */
13
+ export const forbiddenHandles = [
14
+ 'admin',
15
+ 'allpeep',
16
+ 'api',
17
+ 'app',
18
+ 'auth',
19
+ 'config',
20
+ 'core',
21
+ 'db',
22
+ 'email',
23
+ 'federation',
24
+ 'jam',
25
+ 'media',
26
+ 'network',
27
+ 'plugins',
28
+ 'undefined',
29
+ 'jamStarted',
30
+ 'jamSpeaker',
31
+ 'jamModerator',
32
+ 'new',
33
+ ];
34
+
35
+ const defaultForbiddenHandles = new Set(
36
+ forbiddenHandles.map((handle) => handle.toLowerCase()),
37
+ );
38
+
39
+ export const normalizeForbiddenHandle = (value: string) =>
40
+ value.trim().toLowerCase();
41
+
42
+ export const isDefaultForbiddenHandle = (value: string) =>
43
+ defaultForbiddenHandles.has(normalizeForbiddenHandle(value));
44
+
45
+ /** Exact username match, case-insensitive. `additional` is the community list. */
46
+ export const isForbiddenHandle = (
47
+ value: string,
48
+ additional?: readonly string[],
49
+ ) => {
50
+ const normalized = normalizeForbiddenHandle(value);
51
+ if (!normalized) return false;
52
+ if (defaultForbiddenHandles.has(normalized)) return true;
53
+ return (additional ?? []).some(
54
+ (entry) => normalizeForbiddenHandle(entry) === normalized,
55
+ );
56
+ };
57
+
58
+ export type AdditionalForbiddenHandleIssue =
59
+ | 'empty'
60
+ | 'invalid'
61
+ | 'builtIn'
62
+ | 'duplicate';
63
+
64
+ export const classifyAdditionalForbiddenHandle = (
65
+ raw: string,
66
+ existing: readonly string[] = [],
67
+ ): AdditionalForbiddenHandleIssue | null => {
68
+ const value = normalizeForbiddenHandle(raw);
69
+ if (!value) return 'empty';
70
+ if (!handleRegex.test(value)) return 'invalid';
71
+ if (isDefaultForbiddenHandle(value)) return 'builtIn';
72
+ if (existing.some((entry) => normalizeForbiddenHandle(entry) === value)) {
73
+ return 'duplicate';
74
+ }
75
+ return null;
76
+ };
77
+
78
+ /**
79
+ * Community-added names only. Built-in names, blanks, duplicates, and values
80
+ * that can never match a handle are dropped so they cannot be stored or deleted.
81
+ */
82
+ export const collectAdditionalForbiddenHandles = (
83
+ values: readonly string[],
84
+ ) => {
85
+ const issues: {
86
+ index: number;
87
+ issue: Extract<AdditionalForbiddenHandleIssue, 'empty' | 'invalid'>;
88
+ }[] = [];
89
+ const handles: string[] = [];
90
+ values.forEach((raw, index) => {
91
+ const issue = classifyAdditionalForbiddenHandle(raw, handles);
92
+ if (issue === 'empty' || issue === 'invalid') {
93
+ issues.push({ index, issue });
94
+ return;
95
+ }
96
+ if (issue) return;
97
+ handles.push(normalizeForbiddenHandle(raw));
98
+ });
99
+ return { handles, issues };
100
+ };
101
+
102
+ /** Stored as given. PATCH normalizes before save; reads stay a plain string list. */
103
+ export const additionalForbiddenHandlesSchema = z.array(z.string());
@@ -15,6 +15,8 @@ export * from './notifications';
15
15
  export * from './stripe';
16
16
  export * from './db';
17
17
  export * from './admin-email';
18
+ export * from './admin-media';
18
19
  export * from './admin-jobs';
19
20
  export * from './admin-db';
20
21
  export * from './admin-performance';
22
+ export * from './admin-livekit';
@@ -4,38 +4,37 @@ import ISO6391 from 'iso-639-1';
4
4
  import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
5
5
  import { groupRelationships } from './capabilities';
6
6
  import { capabilitiesSchema } from './config';
7
+ import {
8
+ HANDLE_RESERVED_MESSAGE,
9
+ additionalForbiddenHandlesSchema,
10
+ classifyAdditionalForbiddenHandle,
11
+ collectAdditionalForbiddenHandles,
12
+ forbiddenHandles,
13
+ handleRegex,
14
+ handleRegexBase,
15
+ isDefaultForbiddenHandle,
16
+ isForbiddenHandle,
17
+ normalizeForbiddenHandle,
18
+ } from './forbiddenHandles';
19
+
20
+ export {
21
+ HANDLE_RESERVED_MESSAGE,
22
+ additionalForbiddenHandlesSchema,
23
+ classifyAdditionalForbiddenHandle,
24
+ collectAdditionalForbiddenHandles,
25
+ forbiddenHandles,
26
+ handleRegex,
27
+ handleRegexBase,
28
+ isDefaultForbiddenHandle,
29
+ isForbiddenHandle,
30
+ normalizeForbiddenHandle,
31
+ };
7
32
 
8
33
  extendZodWithOpenApi(z);
9
34
 
10
- export const handleRegexBase = '[a-zA-Z0-9_-]{1,16}';
11
-
12
- export const handleRegex = new RegExp(`^${handleRegexBase}$`);
13
-
14
35
  /** `@handle` using the allowed handle charset. No `\\b` — hyphens are not word chars. */
15
36
  export const mentionHandleRegexBase = `(^|[\\s(>])@(${handleRegexBase})(?=\\s|$|[.,!?;:])`;
16
37
 
17
- export const forbiddenHandles = [
18
- 'admin',
19
- 'allpeep',
20
- 'api',
21
- 'app',
22
- 'auth',
23
- 'config',
24
- 'core',
25
- 'db',
26
- 'email',
27
- 'federation',
28
- 'jam',
29
- 'media',
30
- 'network',
31
- 'plugins',
32
- 'undefined',
33
- 'jamStarted',
34
- 'jamSpeaker',
35
- 'jamModerator',
36
- 'new',
37
- ];
38
-
39
38
  export const baseSchemaShape = {
40
39
  createdAt: z.iso.datetime(),
41
40
  updatedAt: z.iso.datetime(),
@@ -212,8 +211,8 @@ export type ProfileSettings = Model<ProfileSettingsData>;
212
211
 
213
212
  export const accountNameSchema = z
214
213
  .string()
215
- .refine((value: string) => !forbiddenHandles.includes(value.toLowerCase()), {
216
- message: 'Handle is reserved',
214
+ .refine((value: string) => !isForbiddenHandle(value), {
215
+ message: HANDLE_RESERVED_MESSAGE,
217
216
  })
218
217
  .refine((value: string) => handleRegex.test(value ?? ''), {
219
218
  message:
@@ -540,10 +539,13 @@ export const articleSchema = noteSchema
540
539
 
541
540
  export type Article = z.infer<typeof articleSchema>;
542
541
 
542
+ /** Resource titles are library headings, so they stay much shorter than the description. */
543
+ export const RESOURCE_TITLE_MAX_LENGTH = 200;
544
+
543
545
  export const resourcePostSchema = noteSchema
544
546
  .extend({
545
547
  type: z.literal('resource'),
546
- title: z.string(),
548
+ title: z.string().max(RESOURCE_TITLE_MAX_LENGTH),
547
549
  tags: z.array(z.string().min(1)).optional(),
548
550
  categoryPath: z.array(z.string().min(1)).optional(),
549
551
  resourceKind: resourceKindSchema,
@@ -609,6 +611,8 @@ export const eventSchema = noteSchema
609
611
  end: eventIsoDatetimeSchema.optional(),
610
612
  wholeDay: z.boolean(),
611
613
  maxAttendees: z.number().int().positive().optional(),
614
+ /** Minutes the next waitlisted member has to claim a freed seat. */
615
+ waitlistOfferMinutes: z.number().int().positive().max(10080).optional(),
612
616
  attendeeListPublic: z.boolean().optional(),
613
617
  moderators: z.string().uuid().array().optional(),
614
618
  jam: jamSchema.optional(),
@@ -617,6 +621,10 @@ export const eventSchema = noteSchema
617
621
  recurrence: eventRecurrenceSchema.optional(),
618
622
  exceptions: eventOccurrenceExceptionSchema.array().optional(),
619
623
  })
624
+ .refine((data) => !data.end || new Date(data.end) > new Date(data.start), {
625
+ message: 'events.form.endBeforeStart',
626
+ path: ['end'],
627
+ })
620
628
  .openapi('Event');
621
629
 
622
630
  export type Event = z.infer<typeof eventSchema>;
@@ -651,18 +659,30 @@ export const answerSchema = z
651
659
 
652
660
  export type Answer = z.infer<typeof answerSchema>;
653
661
 
654
- export const rsvpResponseSchema = z.enum(['yes', 'no', 'tentative', 'removed']);
662
+ export const rsvpResponseSchema = z.enum([
663
+ 'yes',
664
+ 'no',
665
+ 'tentative',
666
+ 'removed',
667
+ 'waitlist',
668
+ ]);
655
669
  export type RsvpResponse = z.infer<typeof rsvpResponseSchema>;
656
670
 
657
671
  export const rsvpSchema = z.object({
658
672
  response: rsvpResponseSchema,
659
673
  recurrenceId: eventIsoDatetimeSchema.optional(),
674
+ /** Queue position. Copied onto later offer entries so a new write stays in line. */
675
+ waitlistJoinedAt: eventIsoDatetimeSchema.optional(),
676
+ /** When the current spot offer expires. Server-set; ignored on RSVP requests. */
677
+ offerExpiresAt: eventIsoDatetimeSchema.optional(),
660
678
  });
661
679
  export type RSVP = z.infer<typeof rsvpSchema>;
662
680
 
663
- export const rsvpRequestSchema = rsvpSchema.extend({
664
- recurrenceIds: z.array(eventIsoDatetimeSchema).min(1).optional(),
665
- });
681
+ export const rsvpRequestSchema = rsvpSchema
682
+ .omit({ waitlistJoinedAt: true, offerExpiresAt: true })
683
+ .extend({
684
+ recurrenceIds: z.array(eventIsoDatetimeSchema).min(1).optional(),
685
+ });
666
686
  export type RsvpRequest = z.infer<typeof rsvpRequestSchema>;
667
687
 
668
688
  export const entryReactionDataSchema = z.object({
@@ -68,11 +68,13 @@ export interface NotificationHandler {
68
68
  export const notificationTypeSchema = z.object({
69
69
  type: z.string(),
70
70
  requiredCapabilities: z.enum(roleCapabilities).array().optional(),
71
- defaultSettings: z.object({
72
- create: z.boolean(),
73
- push: z.boolean(),
74
- email: z.boolean(),
75
- }).optional(),
71
+ defaultSettings: z
72
+ .object({
73
+ create: z.boolean(),
74
+ push: z.boolean(),
75
+ email: z.boolean(),
76
+ })
77
+ .optional(),
76
78
  });
77
79
 
78
80
  export type NotificationType = z.infer<typeof notificationTypeSchema>;
@@ -88,5 +90,3 @@ export const notificationAll = {
88
90
  push: true,
89
91
  email: true,
90
92
  } as const;
91
-
92
-
@@ -16,105 +16,124 @@ export interface RoleDefaultsVersion {
16
16
  const versionedRoles = (version: string, roles: RoleData[]): RoleData[] =>
17
17
  roles.map((role) => ({ ...role, baseVersion: version }));
18
18
 
19
+ const builtinRoles: RoleData[] = [
20
+ {
21
+ key: 'owner',
22
+ displayName: 'Owner',
23
+ capabilities: { add: ['*'], remove: [] },
24
+ default: true,
25
+ description: 'The owner of this community can do everything',
26
+ },
27
+ {
28
+ key: 'admin',
29
+ displayName: 'Admin',
30
+ capabilities: {
31
+ add: [
32
+ 'core-accounts-*',
33
+ 'core-reports-*',
34
+ 'core-groups-*',
35
+ 'core-posts-*',
36
+ 'core-profiles-*',
37
+ 'core-customization-*',
38
+ 'core-backups-*',
39
+ 'core-i18n-*',
40
+ 'core-logs-*',
41
+ 'core-roles-read',
42
+ 'core-maintenance-restart',
43
+ 'core-inviteLinks-*',
44
+ 'core-analytics-read',
45
+ 'core-plugins-*',
46
+ ],
47
+ remove: [],
48
+ },
49
+ default: true,
50
+ description: 'An admin of the community',
51
+ },
52
+ {
53
+ key: 'moderator',
54
+ displayName: 'Moderator',
55
+ capabilities: {
56
+ add: [
57
+ 'core-posts-delete',
58
+ 'core-posts-pin-globally',
59
+ 'core-posts-announce',
60
+ 'core-profiles-suspend',
61
+ 'core-accounts-read',
62
+ 'core-profiles-read',
63
+ 'core-groups-read',
64
+ 'core-inviteLinks-read',
65
+ 'core-reports-read',
66
+ 'core-reports-update',
67
+ 'core-analytics-read',
68
+ 'core-local',
69
+ 'core-posts-create-*',
70
+ 'core-groups-create',
71
+ 'core-reports-create',
72
+ ],
73
+ remove: [],
74
+ },
75
+ default: true,
76
+ description: 'A moderator of the community',
77
+ },
78
+ {
79
+ key: 'member',
80
+ displayName: 'Member',
81
+ capabilities: {
82
+ add: [
83
+ 'core-local',
84
+ 'core-posts-create-*',
85
+ 'core-groups-create',
86
+ 'core-reports-create',
87
+ ],
88
+ remove: [],
89
+ },
90
+ default: true,
91
+ description: 'A member of the community',
92
+ },
93
+ {
94
+ key: 'pendingmember',
95
+ displayName: 'Pending Member',
96
+ capabilities: {
97
+ add: ['core-local'],
98
+ remove: [],
99
+ },
100
+ default: true,
101
+ description: 'A member of the community that has not been approved yet',
102
+ },
103
+ {
104
+ key: 'limitedmember',
105
+ displayName: 'Limited Member',
106
+ capabilities: {
107
+ add: [],
108
+ remove: [],
109
+ },
110
+ default: true,
111
+ description:
112
+ 'A member of the community that can only partcipate in group they are added to',
113
+ },
114
+ ];
115
+
116
+ const adminCanManageMedia = (roles: RoleData[]): RoleData[] =>
117
+ roles.map((role) =>
118
+ role.key === 'admin'
119
+ ? {
120
+ ...role,
121
+ capabilities: {
122
+ add: [...(role.capabilities?.add ?? []), 'core-media-*'],
123
+ remove: [...(role.capabilities?.remove ?? [])],
124
+ },
125
+ }
126
+ : role,
127
+ );
128
+
19
129
  export const roleDefaultsHistory: RoleDefaultsVersion[] = [
20
130
  {
21
131
  version: '2026-10-06',
22
- roles: versionedRoles('2026-10-06', [
23
- {
24
- key: 'owner',
25
- displayName: 'Owner',
26
- capabilities: { add: ['*'], remove: [] },
27
- default: true,
28
- description: 'The owner of this community can do everything',
29
- },
30
- {
31
- key: 'admin',
32
- displayName: 'Admin',
33
- capabilities: {
34
- add: [
35
- 'core-accounts-*',
36
- 'core-reports-*',
37
- 'core-groups-*',
38
- 'core-posts-*',
39
- 'core-profiles-*',
40
- 'core-customization-*',
41
- 'core-backups-*',
42
- 'core-i18n-*',
43
- 'core-logs-*',
44
- 'core-roles-read',
45
- 'core-maintenance-restart',
46
- 'core-inviteLinks-*',
47
- 'core-analytics-read',
48
- 'core-plugins-*',
49
- ],
50
- remove: [],
51
- },
52
- default: true,
53
- description: 'An admin of the community',
54
- },
55
- {
56
- key: 'moderator',
57
- displayName: 'Moderator',
58
- capabilities: {
59
- add: [
60
- 'core-posts-delete',
61
- 'core-posts-pin-globally',
62
- 'core-posts-announce',
63
- 'core-profiles-suspend',
64
- 'core-accounts-read',
65
- 'core-profiles-read',
66
- 'core-groups-read',
67
- 'core-inviteLinks-read',
68
- 'core-reports-read',
69
- 'core-reports-update',
70
- 'core-analytics-read',
71
- 'core-local',
72
- 'core-posts-create-*',
73
- 'core-groups-create',
74
- 'core-reports-create',
75
- ],
76
- remove: [],
77
- },
78
- default: true,
79
- description: 'A moderator of the community',
80
- },
81
- {
82
- key: 'member',
83
- displayName: 'Member',
84
- capabilities: {
85
- add: [
86
- 'core-local',
87
- 'core-posts-create-*',
88
- 'core-groups-create',
89
- 'core-reports-create',
90
- ],
91
- remove: [],
92
- },
93
- default: true,
94
- description: 'A member of the community',
95
- },
96
- {
97
- key: 'pendingmember',
98
- displayName: 'Pending Member',
99
- capabilities: {
100
- add: ['core-local'],
101
- remove: [],
102
- },
103
- default: true,
104
- description: 'A member of the community that has not been approved yet',
105
- },
106
- {
107
- key: 'limitedmember',
108
- displayName: 'Limited Member',
109
- capabilities: {
110
- add: [],
111
- remove: [],
112
- },
113
- default: true,
114
- description:
115
- 'A member of the community that can only partcipate in group they are added to',
116
- },
117
- ]),
132
+ roles: versionedRoles('2026-10-06', builtinRoles),
133
+ },
134
+ {
135
+ version: '2026-10-13',
136
+ roles: versionedRoles('2026-10-13', adminCanManageMedia(builtinRoles)),
118
137
  },
119
138
  ];
120
139
 
@@ -39,7 +39,9 @@ export const stripeCustomerPortalResponseSchema =
39
39
  url: z.string().optional(),
40
40
  });
41
41
 
42
- export type StripeSubscriptionData = z.infer<typeof stripeSubscriptionDataSchema>;
42
+ export type StripeSubscriptionData = z.infer<
43
+ typeof stripeSubscriptionDataSchema
44
+ >;
43
45
  export type StripeCustomerPortalResponseSchema = z.infer<
44
46
  typeof stripeCustomerPortalResponseSchema
45
47
  >;