@openpeepshq/common 0.1.44 → 0.1.46

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 (77) hide show
  1. package/dist/lib/adminSections.d.ts +4 -0
  2. package/dist/lib/adminSections.js +5 -0
  3. package/dist/lib/capabilitiesHelpers.d.ts +9 -7
  4. package/dist/lib/capabilitiesHelpers.js +21 -13
  5. package/dist/lib/eventIcs.d.ts +17 -0
  6. package/dist/lib/eventIcs.js +138 -2
  7. package/dist/lib/eventRecurrence.d.ts +32 -0
  8. package/dist/lib/eventRecurrence.js +284 -0
  9. package/dist/lib/eventTime.d.ts +29 -0
  10. package/dist/lib/eventTime.js +143 -0
  11. package/dist/lib/federationHosts.d.ts +3 -0
  12. package/dist/lib/federationHosts.js +17 -0
  13. package/dist/lib/feedCursor.d.ts +14 -0
  14. package/dist/lib/feedCursor.js +22 -0
  15. package/dist/lib/feedFormat.d.ts +12 -0
  16. package/dist/lib/feedFormat.js +14 -0
  17. package/dist/lib/groupHelpers.d.ts +63 -41
  18. package/dist/lib/groupHelpers.js +155 -45
  19. package/dist/lib/groupTemplateHelpers.d.ts +16 -0
  20. package/dist/lib/groupTemplateHelpers.js +51 -0
  21. package/dist/lib/index.d.ts +11 -0
  22. package/dist/lib/index.js +11 -0
  23. package/dist/lib/jamHelpers.d.ts +38 -3
  24. package/dist/lib/jamHelpers.js +93 -8
  25. package/dist/lib/legacyThemeRoot.d.ts +3 -0
  26. package/dist/lib/legacyThemeRoot.js +10 -0
  27. package/dist/lib/markdownHelpers.d.ts +22 -0
  28. package/dist/lib/markdownHelpers.js +73 -3
  29. package/dist/lib/postHelpers.d.ts +164 -9
  30. package/dist/lib/postHelpers.js +353 -11
  31. package/dist/lib/profileHelpers.d.ts +11 -0
  32. package/dist/lib/profileHelpers.js +31 -0
  33. package/dist/lib/pushHelpers.d.ts +3 -1
  34. package/dist/lib/pushHelpers.js +13 -0
  35. package/dist/lib/reactions.d.ts +17 -0
  36. package/dist/lib/reactions.js +37 -0
  37. package/dist/lib/scopeHelpers.d.ts +31 -2
  38. package/dist/lib/scopeHelpers.js +37 -3
  39. package/dist/lib/ssoLoginUrl.d.ts +24 -0
  40. package/dist/lib/ssoLoginUrl.js +75 -0
  41. package/dist/lib/ssoProviders.d.ts +72 -0
  42. package/dist/lib/ssoProviders.js +370 -0
  43. package/dist/lib/text.d.ts +2 -0
  44. package/dist/lib/text.js +2 -0
  45. package/dist/lib/timeZone.d.ts +9 -0
  46. package/dist/lib/timeZone.js +44 -0
  47. package/dist/lib/tokenHelpers.d.ts +5 -0
  48. package/dist/lib/tokenHelpers.js +19 -0
  49. package/dist/types/analytics.d.ts +20 -0
  50. package/dist/types/analytics.js +4 -0
  51. package/dist/types/api.d.ts +42669 -10689
  52. package/dist/types/api.js +94 -16
  53. package/dist/types/auth.d.ts +22 -13
  54. package/dist/types/capabilities.d.ts +26 -5
  55. package/dist/types/capabilities.js +95 -1
  56. package/dist/types/config.d.ts +93 -6
  57. package/dist/types/config.js +56 -5
  58. package/dist/types/db.d.ts +1911 -248
  59. package/dist/types/db.js +17 -3
  60. package/dist/types/export.d.ts +120 -0
  61. package/dist/types/export.js +7 -0
  62. package/dist/types/index.d.ts +2 -0
  63. package/dist/types/index.js +2 -0
  64. package/dist/types/internal.d.ts +8313 -2675
  65. package/dist/types/internal.js +16 -1
  66. package/dist/types/models.d.ts +343 -16
  67. package/dist/types/models.js +98 -7
  68. package/dist/types/notifications.d.ts +1 -0
  69. package/dist/types/plugins.d.ts +43 -1
  70. package/dist/types/plugins.js +75 -1
  71. package/dist/types/roleDefaults.d.ts +31 -0
  72. package/dist/types/roleDefaults.js +110 -0
  73. package/dist/types/stats.d.ts +54359 -4718
  74. package/dist/types/stats.js +30 -0
  75. package/dist/types/utils.d.ts +2 -0
  76. package/dist/types/utils.js +1 -3
  77. package/package.json +1 -1
@@ -1,3 +1,55 @@
1
+ import { mentionHandleRegexBase } from '../types/index.js';
2
+ const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
3
+ const mentionPrefix = '(^|[\\s(>])';
4
+ const mentionSuffix = '(?=\\s|$|[.,!?;:])';
5
+ /**
6
+ * Turn `@handle` / known `@displayName` into markdown profile links.
7
+ * Display names are matched exactly (longest first) so apostrophes and other
8
+ * non-letter characters still count when that profile is in `mentions`.
9
+ * Bare `@handle` tokens use the allowed handle charset (letters, digits, `_`, `-`).
10
+ */
11
+ export const linkProfileMentions = (source, mentions = []) => {
12
+ const aliases = mentions.flatMap(({ profile }) => {
13
+ var _a, _b;
14
+ const handle = (_a = profile.handle) === null || _a === void 0 ? void 0 : _a.trim();
15
+ if (!handle)
16
+ return [];
17
+ const names = new Set([handle]);
18
+ const displayName = (_b = profile.displayName) === null || _b === void 0 ? void 0 : _b.trim();
19
+ if (displayName)
20
+ names.add(displayName);
21
+ return [...names].map((name) => ({ name, handle }));
22
+ });
23
+ aliases.sort((a, b) => b.name.length - a.name.length);
24
+ let text = source;
25
+ for (const { name, handle } of aliases) {
26
+ const pattern = new RegExp(`${mentionPrefix}@(${escapeRegExp(name)})${mentionSuffix}`, 'gi');
27
+ text = text.replace(pattern, (_full, prefix, mentioned) => `${prefix}[@${mentioned}](/@${handle})`);
28
+ }
29
+ return text.replace(new RegExp(mentionHandleRegexBase, 'g'), (_full, prefix, handle) => `${prefix}[@${handle}](/@${handle})`);
30
+ };
31
+ export const matchMentionHandles = (text) => {
32
+ if (!text)
33
+ return [];
34
+ const handles = new Set();
35
+ for (const match of text.matchAll(new RegExp(mentionHandleRegexBase, 'g'))) {
36
+ const handle = match[2];
37
+ if (handle)
38
+ handles.add(handle);
39
+ }
40
+ return [...handles];
41
+ };
42
+ /** Readable text for a shortened preview. Drops markdown marks, keeps words. */
43
+ export const markdownPlainText = (markdown) => {
44
+ if (!markdown)
45
+ return '';
46
+ return markdown
47
+ .replace(/```[\s\S]*?```/g, ' ')
48
+ .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
49
+ .replace(/[#>*_~`]+/g, '')
50
+ .replace(/\s+/g, ' ')
51
+ .trim();
52
+ };
1
53
  export const firstNWords = (markdown, n) => {
2
54
  if (!markdown)
3
55
  return '';
@@ -8,11 +60,13 @@ export const firstNWords = (markdown, n) => {
8
60
  let match;
9
61
  while ((match = regex.exec(markdown)) !== null) {
10
62
  // Check if the match is a link or a regular word.
11
- if (match[1]) { // It's a regular word
63
+ if (match[1]) {
64
+ // It's a regular word
12
65
  firstTwelveWords.push(match[1]);
13
66
  wordCount++;
14
67
  }
15
- else { // It's a markdown link - treat it as one word
68
+ else {
69
+ // It's a markdown link - treat it as one word
16
70
  firstTwelveWords.push(match[0]); // Add the entire link string
17
71
  wordCount++;
18
72
  }
@@ -20,5 +74,21 @@ export const firstNWords = (markdown, n) => {
20
74
  break;
21
75
  }
22
76
  }
23
- return firstTwelveWords.join(" ");
77
+ return firstTwelveWords.join(' ');
78
+ };
79
+ /** Average adult reading speed (words per minute). */
80
+ const DEFAULT_WORDS_PER_MINUTE = 210;
81
+ /**
82
+ * Estimate reading time for a markdown article. Strips markdown syntax
83
+ * before counting words, then divides by the words-per-minute rate.
84
+ * Always returns at least 1 for non-empty content.
85
+ */
86
+ export const minutesToRead = (markdown, wordsPerMinute = DEFAULT_WORDS_PER_MINUTE) => {
87
+ if (!markdown)
88
+ return 0;
89
+ const plainText = markdownPlainText(markdown);
90
+ const wordCount = plainText.split(/\s+/).filter(Boolean).length;
91
+ return wordCount === 0
92
+ ? 0
93
+ : Math.max(1, Math.ceil(wordCount / wordsPerMinute));
24
94
  };
@@ -1,14 +1,28 @@
1
- import { Answer, AnswerWithPublicProfile, AuthorizationData, CapabilitiesConfig, Event, GroupWithMeta, PostType, PostDataUnion, PublicPost, PublicProfile, Thread, VisibilityType } from '../types';
1
+ import { Answer, AnswerWithPublicProfile, AuthorizationData, CapabilitiesConfig, Event, GroupWithMeta, PostType, PostDataUnion, PublicPost, PublicProfile, PublicRsvp, RSVP, Thread, VisibilityType } from '../types';
2
2
  export declare const buildThreads: (posts: PublicPost[]) => Thread[];
3
+ export type ThreadPreviewPost = {
4
+ id: string;
5
+ createdAt: string;
6
+ inReplyToId?: string | null;
7
+ replyTo?: ThreadPreviewPost | null;
8
+ };
9
+ export type ThreadPreviewGroup = {
10
+ skippedAncestor: boolean;
11
+ ancestor?: ThreadPreviewPost;
12
+ posts: ThreadPreviewPost[];
13
+ };
14
+ export declare const buildThreadPreview: (rootId: string, replies: ThreadPreviewPost[]) => ThreadPreviewGroup[];
3
15
  export declare const getReactionCount: (post: PublicPost) => Record<"👍", number>;
4
16
  export declare const countVotes: (optionsCount: number, answers: Answer[]) => number[];
5
17
  /** Fill blank poll choices with their placeholder label (e.g. "Option 1"). */
6
18
  export declare const resolvePollOptionContents: (options: readonly string[], fallbackLabel: (index: number) => string) => string[];
19
+ /** Longer choices are rejected by `questionSchema`, so block submit instead. */
20
+ export declare const pollOptionsWithinLimit: (options: readonly string[]) => boolean;
7
21
  export declare const collectVotes: (post: PublicPost) => {
8
22
  voteCounts: number[];
9
23
  votes: AnswerWithPublicProfile[];
10
24
  };
11
- export declare const calculateEffectiveRsvps: (post: PublicPost) => {
25
+ export declare const calculateEffectiveRsvps: (post: PublicPost, recurrenceId?: string) => {
12
26
  response: "no" | "yes" | "tentative" | "removed";
13
27
  profile: {
14
28
  id: string;
@@ -35,7 +49,7 @@ export declare const calculateEffectiveRsvps: (post: PublicPost) => {
35
49
  discoverable?: boolean | undefined;
36
50
  deletedAt?: string | null | undefined;
37
51
  };
38
- roles?: ("none" | "local" | "member" | "admin" | "moderator" | "invited")[] | null | undefined;
52
+ roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
39
53
  }[] | undefined;
40
54
  deletedAt?: string | null | undefined;
41
55
  avatar?: string | null | undefined;
@@ -53,6 +67,10 @@ export declare const calculateEffectiveRsvps: (post: PublicPost) => {
53
67
  locked?: boolean | undefined;
54
68
  bot?: boolean | undefined;
55
69
  discoverable?: boolean | undefined;
70
+ roles?: {
71
+ key: string;
72
+ displayName: string;
73
+ }[] | undefined;
56
74
  fields?: {
57
75
  name: string;
58
76
  value: string;
@@ -61,10 +79,13 @@ export declare const calculateEffectiveRsvps: (post: PublicPost) => {
61
79
  followersCount: number;
62
80
  followingCount: number;
63
81
  } | undefined;
82
+ pinnedPostId?: string | undefined;
83
+ blockedByMe?: boolean | undefined;
64
84
  };
65
85
  createdAt: string;
86
+ recurrenceId?: string | undefined;
66
87
  }[];
67
- export declare const getEffectiveRsvp: (post: PublicPost, profileId: string) => {
88
+ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string, recurrenceId?: string) => {
68
89
  response: "no" | "yes" | "tentative" | "removed";
69
90
  profile: {
70
91
  id: string;
@@ -91,7 +112,7 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string) =>
91
112
  discoverable?: boolean | undefined;
92
113
  deletedAt?: string | null | undefined;
93
114
  };
94
- roles?: ("none" | "local" | "member" | "admin" | "moderator" | "invited")[] | null | undefined;
115
+ roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
95
116
  }[] | undefined;
96
117
  deletedAt?: string | null | undefined;
97
118
  avatar?: string | null | undefined;
@@ -109,6 +130,10 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string) =>
109
130
  locked?: boolean | undefined;
110
131
  bot?: boolean | undefined;
111
132
  discoverable?: boolean | undefined;
133
+ roles?: {
134
+ key: string;
135
+ displayName: string;
136
+ }[] | undefined;
112
137
  fields?: {
113
138
  name: string;
114
139
  value: string;
@@ -117,18 +142,120 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string) =>
117
142
  followersCount: number;
118
143
  followingCount: number;
119
144
  } | undefined;
145
+ pinnedPostId?: string | undefined;
146
+ blockedByMe?: boolean | undefined;
120
147
  };
121
148
  createdAt: string;
149
+ recurrenceId?: string | undefined;
122
150
  } | undefined;
123
- export declare const countYesRsvps: (post: PublicPost) => number;
151
+ export declare const countYesRsvps: (post: PublicPost, recurrenceId?: string) => number;
152
+ export declare const countSeriesYesRsvps: (post: PublicPost) => number;
153
+ /** Current roster: attending guests, plus organizer removals that can be restored. */
154
+ export declare const listedRsvps: (rsvps: PublicRsvp[]) => {
155
+ response: "no" | "yes" | "tentative" | "removed";
156
+ profile: {
157
+ id: string;
158
+ type: "local" | "guest" | "federated";
159
+ createdAt: string;
160
+ updatedAt: string;
161
+ handle: string;
162
+ memberships: {
163
+ group: {
164
+ handle: string;
165
+ capabilities: Record<string, {
166
+ add?: string[] | undefined;
167
+ remove?: string[] | undefined;
168
+ } | undefined>;
169
+ id: string;
170
+ createdAt: string;
171
+ updatedAt: string;
172
+ avatar?: string | null | undefined;
173
+ header?: string | null | undefined;
174
+ displayName?: string | undefined;
175
+ description?: string | undefined;
176
+ rules?: string | undefined;
177
+ pinnedPostId?: string | undefined;
178
+ discoverable?: boolean | undefined;
179
+ deletedAt?: string | null | undefined;
180
+ };
181
+ roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
182
+ }[] | undefined;
183
+ deletedAt?: string | null | undefined;
184
+ avatar?: string | null | undefined;
185
+ header?: string | null | undefined;
186
+ displayName?: string | undefined;
187
+ bio?: string | undefined;
188
+ location?: {
189
+ text: string;
190
+ coordinates?: {
191
+ lat: number;
192
+ lng: number;
193
+ alt?: number | undefined;
194
+ } | undefined;
195
+ } | undefined;
196
+ locked?: boolean | undefined;
197
+ bot?: boolean | undefined;
198
+ discoverable?: boolean | undefined;
199
+ roles?: {
200
+ key: string;
201
+ displayName: string;
202
+ }[] | undefined;
203
+ fields?: {
204
+ name: string;
205
+ value: string;
206
+ }[] | undefined;
207
+ profileStats?: {
208
+ followersCount: number;
209
+ followingCount: number;
210
+ } | undefined;
211
+ pinnedPostId?: string | undefined;
212
+ blockedByMe?: boolean | undefined;
213
+ };
214
+ createdAt: string;
215
+ recurrenceId?: string | undefined;
216
+ }[];
217
+ /** Set only when a member leaves an attending RSVP. A second "no" stays unset. */
218
+ export type RsvpCancelNotice = {
219
+ occurrenceIds: string[];
220
+ series: boolean;
221
+ };
222
+ export declare const isRsvpCancelNotice: (data: unknown) => data is RsvpCancelNotice;
223
+ export declare const rsvpCancelNotice: (post: PublicPost, profileId: string, response: PublicRsvp["response"], occurrenceIds?: string[]) => RsvpCancelNotice | undefined;
224
+ export type RsvpCancellation = {
225
+ profile: PublicRsvp['profile'];
226
+ recurrenceId?: string;
227
+ canceledAt: string;
228
+ series: boolean;
229
+ };
230
+ /** Attending → no transitions, newest first. Later re-RSVPs do not erase them. */
231
+ export declare const listRsvpCancellations: (post: PublicPost) => RsvpCancellation[];
232
+ export declare const rsvpCancelWhenLabels: (post: PublicPost, notice: RsvpCancelNotice) => {
233
+ series: boolean;
234
+ labels: string[];
235
+ };
236
+ export declare const instanceRsvpIdsForProfile: (post: PublicPost, profileId: string) => string[];
237
+ export declare const overlaySeriesRsvpEntries: (response: RSVP["response"], instanceIds: string[]) => RSVP[];
238
+ export declare const seriesYesBlockedByCapacity: (post: PublicPost, profileId: string, now?: Date) => boolean;
239
+ export declare const occurrenceHasCapacity: (post: PublicPost, recurrenceId?: string, profileId?: string) => boolean;
240
+ /** Series Register stays enabled while any upcoming date still has a seat. */
241
+ export declare const recurringEventHasOpenOccurrence: (post: PublicPost, profileId?: string, now?: Date) => boolean;
242
+ /**
243
+ * Series-page RSVP for the Register/Cancel CTA: prefer the default/next date,
244
+ * then any attending instance so a partial RSVP still shows Cancel.
245
+ */
246
+ export declare const displayRsvpForProfile: (post: PublicPost, profileId: string, options?: {
247
+ recurrenceId?: string;
248
+ lockToOccurrence?: boolean;
249
+ now?: Date;
250
+ }) => PublicRsvp | undefined;
124
251
  export declare const isCapacityEvent: (event: Event) => boolean;
125
252
  export declare const parseEventMaxAttendeesInput: (raw: string) => number | undefined;
126
253
  export declare const withoutEventMaxAttendees: <T extends Event>(event: T) => T;
127
254
  export declare const normalizeEventDataForSave: <T extends Event>(event: T) => T;
128
- /** ArangoDB may store null when capacity was cleared; strip for validation/output. */
255
+ /** Null capacity means it was cleared; strip for validation/output. */
129
256
  export declare const normalizeEventDataFromDb: <T extends Event>(event: T) => T;
130
257
  export declare const normalizePostDataFromDb: (data: PostDataUnion) => PostDataUnion;
131
- /** ArangoDB update deep-merges nested `data`; null removes maxAttendees. */
258
+ /** Nested `data` updates send null to remove maxAttendees. */
132
259
  export type EventDbUpdate = Omit<Event, 'maxAttendees'> & {
133
260
  maxAttendees?: number | null;
134
261
  };
@@ -140,9 +267,37 @@ export type JamCapacityJoinBlock = {
140
267
  blocked: true;
141
268
  reason: 'full' | 'rsvp-required' | 'removed';
142
269
  };
143
- export declare const getJamCapacityJoinBlock: (post: PublicPost, profile: Pick<PublicProfile, "id"> | undefined) => JamCapacityJoinBlock;
270
+ export declare const getJamCapacityJoinBlock: (post: PublicPost, profile: Pick<PublicProfile, "id"> | undefined, recurrenceId?: string) => JamCapacityJoinBlock;
144
271
  export declare const canDeletePost: (authData: AuthorizationData, post: PublicPost, config: CapabilitiesConfig) => boolean;
145
272
  export declare const canCreatePost: (authData: AuthorizationData, type: PostType, visibility: VisibilityType, group?: GroupWithMeta) => boolean;
146
273
  export declare const canCreatePostTypeInAnyGroup: (authData: AuthorizationData, type: PostType) => boolean;
147
274
  export declare const canCreatePostTypeWithVisibility: (authData: AuthorizationData, type: PostType, visibility: VisibilityType) => boolean;
148
275
  export declare const canCreatePostType: (authData: AuthorizationData, type: PostType) => boolean;
276
+ export type PostActionAvailability = {
277
+ canReply: boolean;
278
+ canRepost: boolean;
279
+ canReact: boolean;
280
+ };
281
+ /**
282
+ * Whether Reply / Repost / Like should look live. Non-members of a group
283
+ * post stay fully disabled (existing feed rule). Each action also follows
284
+ * the capability the matching write endpoint actually checks: feed replies
285
+ * and reposts need create-*, likes need core-posts-react.
286
+ */
287
+ export declare const getPostActionAvailability: (authData: AuthorizationData, post: PublicPost, config: CapabilitiesConfig) => PostActionAvailability;
288
+ /** Sentinel handle for block-hidden reply tombstones (no name/handle leak). */
289
+ export declare const HIDDEN_AUTHOR_HANDLE = "hidden";
290
+ export declare const toHiddenPost: <T extends {
291
+ data: PostDataUnion;
292
+ profile: PublicProfile;
293
+ }>(post: T) => T & {
294
+ hidden: true;
295
+ };
296
+ export declare const isHiddenPost: (post: {
297
+ hidden?: boolean;
298
+ }) => boolean;
299
+ export declare const isOneToOneWithBlocked: (post: Pick<PublicPost, "visibility" | "audience" | "profile"> & {
300
+ creatorId?: string;
301
+ }, viewer: {
302
+ id: string;
303
+ } | undefined | null, blockedIds?: Set<string> | string[]) => boolean;