@openpeepshq/common 0.1.45 → 0.2.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/dist/lib/adminSections.js +1 -1
- package/dist/lib/capabilitiesHelpers.d.ts +9 -7
- package/dist/lib/capabilitiesHelpers.js +43 -38
- package/dist/lib/csvHelpers.js +1 -1
- package/dist/lib/eventIcs.d.ts +17 -0
- package/dist/lib/eventIcs.js +91 -15
- package/dist/lib/eventRecurrence.d.ts +19 -0
- package/dist/lib/eventRecurrence.js +82 -20
- package/dist/lib/eventTime.d.ts +7 -0
- package/dist/lib/eventTime.js +23 -9
- package/dist/lib/federationHosts.d.ts +3 -0
- package/dist/lib/federationHosts.js +17 -0
- package/dist/lib/feedCursor.d.ts +14 -0
- package/dist/lib/feedCursor.js +22 -0
- package/dist/lib/feedFormat.d.ts +12 -0
- package/dist/lib/feedFormat.js +14 -0
- package/dist/lib/groupHelpers.js +13 -34
- package/dist/lib/groupTemplateHelpers.js +6 -10
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/index.js +7 -0
- package/dist/lib/jamHelpers.d.ts +11 -2
- package/dist/lib/jamHelpers.js +43 -9
- package/dist/lib/legacyThemeRoot.d.ts +3 -0
- package/dist/lib/legacyThemeRoot.js +10 -0
- package/dist/lib/markdownHelpers.d.ts +8 -0
- package/dist/lib/markdownHelpers.js +34 -6
- package/dist/lib/postHelpers.d.ts +142 -3
- package/dist/lib/postHelpers.js +323 -47
- package/dist/lib/profileHelpers.d.ts +11 -0
- package/dist/lib/profileHelpers.js +34 -10
- package/dist/lib/pushHelpers.js +3 -4
- package/dist/lib/reactions.d.ts +17 -0
- package/dist/lib/reactions.js +37 -0
- package/dist/lib/scopeHelpers.d.ts +31 -2
- package/dist/lib/scopeHelpers.js +39 -8
- package/dist/lib/ssoLoginUrl.js +4 -6
- package/dist/lib/ssoProviders.d.ts +72 -0
- package/dist/lib/ssoProviders.js +366 -0
- package/dist/lib/timeZone.d.ts +9 -0
- package/dist/lib/timeZone.js +44 -0
- package/dist/lib/tokenHelpers.js +5 -5
- package/dist/lib/utils.js +6 -7
- package/dist/types/admin-db.js +1 -1
- package/dist/types/analytics.d.ts +20 -0
- package/dist/types/analytics.js +4 -0
- package/dist/types/api.d.ts +41800 -11853
- package/dist/types/api.js +53 -5
- package/dist/types/auth.d.ts +20 -6
- package/dist/types/capabilities.d.ts +15 -1
- package/dist/types/capabilities.js +51 -0
- package/dist/types/config.d.ts +99 -0
- package/dist/types/config.js +56 -4
- package/dist/types/db.d.ts +1155 -164
- package/dist/types/db.js +14 -0
- package/dist/types/export.d.ts +120 -0
- package/dist/types/export.js +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/internal.d.ts +2577 -524
- package/dist/types/internal.js +6 -0
- package/dist/types/models.d.ts +63 -7
- package/dist/types/models.js +40 -3
- package/dist/types/plugins.d.ts +22 -0
- package/dist/types/plugins.js +66 -0
- package/dist/types/roleDefaults.d.ts +31 -0
- package/dist/types/roleDefaults.js +110 -0
- package/dist/types/stats.d.ts +54606 -6065
- package/dist/types/stats.js +30 -0
- package/dist/types/utils.d.ts +2 -0
- package/dist/types/utils.js +1 -3
- package/dist/zod.d.ts +1 -0
- package/dist/zod.js +1 -0
- package/package.json +36 -6
- package/src/index.ts +4 -0
- package/src/lib/adminSections.ts +84 -0
- package/src/lib/attachmentHelpers.ts +14 -0
- package/src/lib/capabilitiesHelpers.ts +532 -0
- package/src/lib/colors.ts +20 -0
- package/src/lib/csvHelpers.ts +31 -0
- package/src/lib/eventIcs.ts +265 -0
- package/src/lib/eventRecurrence.ts +495 -0
- package/src/lib/eventTime.ts +206 -0
- package/src/lib/federationHosts.ts +22 -0
- package/src/lib/feedCursor.ts +27 -0
- package/src/lib/feedFormat.ts +24 -0
- package/src/lib/groupHelpers.ts +421 -0
- package/src/lib/groupTemplateHelpers.ts +83 -0
- package/src/lib/index.ts +29 -0
- package/src/lib/jamHelpers.ts +164 -0
- package/src/lib/legacyThemeRoot.ts +14 -0
- package/src/lib/markdownHelpers.ts +122 -0
- package/src/lib/mediaDimensions.ts +21 -0
- package/src/lib/postHelpers.ts +783 -0
- package/src/lib/profileHelpers.ts +220 -0
- package/src/lib/pushHelpers.ts +34 -0
- package/src/lib/reactions.ts +52 -0
- package/src/lib/reportHelpers.ts +7 -0
- package/src/lib/scopeHelpers.ts +176 -0
- package/src/lib/ssoLoginUrl.ts +93 -0
- package/src/lib/ssoProviders.ts +472 -0
- package/src/lib/text.ts +26 -0
- package/src/lib/timeZone.ts +52 -0
- package/src/lib/tokenHelpers.ts +119 -0
- package/src/lib/utils.ts +322 -0
- package/src/types/admin-db.ts +74 -0
- package/src/types/admin-email.ts +55 -0
- package/src/types/admin-jobs.ts +17 -0
- package/src/types/admin-performance.ts +20 -0
- package/src/types/analytics.ts +318 -0
- package/src/types/api.ts +871 -0
- package/src/types/apple-app-site-association.ts +54 -0
- package/src/types/auth.ts +22 -0
- package/src/types/capabilities.ts +280 -0
- package/src/types/config.ts +546 -0
- package/src/types/db.ts +138 -0
- package/src/types/export.ts +10 -0
- package/src/types/index.ts +20 -0
- package/src/types/internal.ts +338 -0
- package/src/types/models.ts +939 -0
- package/src/types/notifications.ts +92 -0
- package/src/types/plugins.ts +150 -0
- package/src/types/roleDefaults.ts +132 -0
- package/src/types/stats.ts +195 -0
- package/src/types/stripe.ts +45 -0
- package/src/types/utils.ts +100 -0
- package/src/zod.ts +1 -0
|
@@ -12,4 +12,12 @@ export type MentionProfileRef = {
|
|
|
12
12
|
*/
|
|
13
13
|
export declare const linkProfileMentions: (source: string, mentions?: MentionProfileRef[]) => string;
|
|
14
14
|
export declare const matchMentionHandles: (text?: string | null) => string[];
|
|
15
|
+
/** Readable text for a shortened preview. Drops markdown marks, keeps words. */
|
|
16
|
+
export declare const markdownPlainText: (markdown?: string | null) => string;
|
|
15
17
|
export declare const firstNWords: (markdown: string | undefined, n: number) => string;
|
|
18
|
+
/**
|
|
19
|
+
* Estimate reading time for a markdown article. Strips markdown syntax
|
|
20
|
+
* before counting words, then divides by the words-per-minute rate.
|
|
21
|
+
* Always returns at least 1 for non-empty content.
|
|
22
|
+
*/
|
|
23
|
+
export declare const minutesToRead: (markdown: string | undefined, wordsPerMinute?: number) => number;
|
|
@@ -10,12 +10,11 @@ const mentionSuffix = '(?=\\s|$|[.,!?;:])';
|
|
|
10
10
|
*/
|
|
11
11
|
export const linkProfileMentions = (source, mentions = []) => {
|
|
12
12
|
const aliases = mentions.flatMap(({ profile }) => {
|
|
13
|
-
|
|
14
|
-
const handle = (_a = profile.handle) === null || _a === void 0 ? void 0 : _a.trim();
|
|
13
|
+
const handle = profile.handle?.trim();
|
|
15
14
|
if (!handle)
|
|
16
15
|
return [];
|
|
17
16
|
const names = new Set([handle]);
|
|
18
|
-
const displayName =
|
|
17
|
+
const displayName = profile.displayName?.trim();
|
|
19
18
|
if (displayName)
|
|
20
19
|
names.add(displayName);
|
|
21
20
|
return [...names].map((name) => ({ name, handle }));
|
|
@@ -39,6 +38,17 @@ export const matchMentionHandles = (text) => {
|
|
|
39
38
|
}
|
|
40
39
|
return [...handles];
|
|
41
40
|
};
|
|
41
|
+
/** Readable text for a shortened preview. Drops markdown marks, keeps words. */
|
|
42
|
+
export const markdownPlainText = (markdown) => {
|
|
43
|
+
if (!markdown)
|
|
44
|
+
return '';
|
|
45
|
+
return markdown
|
|
46
|
+
.replace(/```[\s\S]*?```/g, ' ')
|
|
47
|
+
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
|
|
48
|
+
.replace(/[#>*_~`]+/g, '')
|
|
49
|
+
.replace(/\s+/g, ' ')
|
|
50
|
+
.trim();
|
|
51
|
+
};
|
|
42
52
|
export const firstNWords = (markdown, n) => {
|
|
43
53
|
if (!markdown)
|
|
44
54
|
return '';
|
|
@@ -49,11 +59,13 @@ export const firstNWords = (markdown, n) => {
|
|
|
49
59
|
let match;
|
|
50
60
|
while ((match = regex.exec(markdown)) !== null) {
|
|
51
61
|
// Check if the match is a link or a regular word.
|
|
52
|
-
if (match[1]) {
|
|
62
|
+
if (match[1]) {
|
|
63
|
+
// It's a regular word
|
|
53
64
|
firstTwelveWords.push(match[1]);
|
|
54
65
|
wordCount++;
|
|
55
66
|
}
|
|
56
|
-
else {
|
|
67
|
+
else {
|
|
68
|
+
// It's a markdown link - treat it as one word
|
|
57
69
|
firstTwelveWords.push(match[0]); // Add the entire link string
|
|
58
70
|
wordCount++;
|
|
59
71
|
}
|
|
@@ -61,5 +73,21 @@ export const firstNWords = (markdown, n) => {
|
|
|
61
73
|
break;
|
|
62
74
|
}
|
|
63
75
|
}
|
|
64
|
-
return firstTwelveWords.join(
|
|
76
|
+
return firstTwelveWords.join(' ');
|
|
77
|
+
};
|
|
78
|
+
/** Average adult reading speed (words per minute). */
|
|
79
|
+
const DEFAULT_WORDS_PER_MINUTE = 210;
|
|
80
|
+
/**
|
|
81
|
+
* Estimate reading time for a markdown article. Strips markdown syntax
|
|
82
|
+
* before counting words, then divides by the words-per-minute rate.
|
|
83
|
+
* Always returns at least 1 for non-empty content.
|
|
84
|
+
*/
|
|
85
|
+
export const minutesToRead = (markdown, wordsPerMinute = DEFAULT_WORDS_PER_MINUTE) => {
|
|
86
|
+
if (!markdown)
|
|
87
|
+
return 0;
|
|
88
|
+
const plainText = markdownPlainText(markdown);
|
|
89
|
+
const wordCount = plainText.split(/\s+/).filter(Boolean).length;
|
|
90
|
+
return wordCount === 0
|
|
91
|
+
? 0
|
|
92
|
+
: Math.max(1, Math.ceil(wordCount / wordsPerMinute));
|
|
65
93
|
};
|
|
@@ -1,5 +1,17 @@
|
|
|
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"). */
|
|
@@ -55,6 +67,10 @@ export declare const calculateEffectiveRsvps: (post: PublicPost, recurrenceId?:
|
|
|
55
67
|
locked?: boolean | undefined;
|
|
56
68
|
bot?: boolean | undefined;
|
|
57
69
|
discoverable?: boolean | undefined;
|
|
70
|
+
roles?: {
|
|
71
|
+
key: string;
|
|
72
|
+
displayName: string;
|
|
73
|
+
}[] | undefined;
|
|
58
74
|
fields?: {
|
|
59
75
|
name: string;
|
|
60
76
|
value: string;
|
|
@@ -63,6 +79,8 @@ export declare const calculateEffectiveRsvps: (post: PublicPost, recurrenceId?:
|
|
|
63
79
|
followersCount: number;
|
|
64
80
|
followingCount: number;
|
|
65
81
|
} | undefined;
|
|
82
|
+
pinnedPostId?: string | undefined;
|
|
83
|
+
blockedByMe?: boolean | undefined;
|
|
66
84
|
};
|
|
67
85
|
createdAt: string;
|
|
68
86
|
recurrenceId?: string | undefined;
|
|
@@ -112,6 +130,10 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string, rec
|
|
|
112
130
|
locked?: boolean | undefined;
|
|
113
131
|
bot?: boolean | undefined;
|
|
114
132
|
discoverable?: boolean | undefined;
|
|
133
|
+
roles?: {
|
|
134
|
+
key: string;
|
|
135
|
+
displayName: string;
|
|
136
|
+
}[] | undefined;
|
|
115
137
|
fields?: {
|
|
116
138
|
name: string;
|
|
117
139
|
value: string;
|
|
@@ -120,19 +142,120 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string, rec
|
|
|
120
142
|
followersCount: number;
|
|
121
143
|
followingCount: number;
|
|
122
144
|
} | undefined;
|
|
145
|
+
pinnedPostId?: string | undefined;
|
|
146
|
+
blockedByMe?: boolean | undefined;
|
|
123
147
|
};
|
|
124
148
|
createdAt: string;
|
|
125
149
|
recurrenceId?: string | undefined;
|
|
126
150
|
} | undefined;
|
|
127
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;
|
|
128
251
|
export declare const isCapacityEvent: (event: Event) => boolean;
|
|
129
252
|
export declare const parseEventMaxAttendeesInput: (raw: string) => number | undefined;
|
|
130
253
|
export declare const withoutEventMaxAttendees: <T extends Event>(event: T) => T;
|
|
131
254
|
export declare const normalizeEventDataForSave: <T extends Event>(event: T) => T;
|
|
132
|
-
/**
|
|
255
|
+
/** Null capacity means it was cleared; strip for validation/output. */
|
|
133
256
|
export declare const normalizeEventDataFromDb: <T extends Event>(event: T) => T;
|
|
134
257
|
export declare const normalizePostDataFromDb: (data: PostDataUnion) => PostDataUnion;
|
|
135
|
-
/**
|
|
258
|
+
/** Nested `data` updates send null to remove maxAttendees. */
|
|
136
259
|
export type EventDbUpdate = Omit<Event, 'maxAttendees'> & {
|
|
137
260
|
maxAttendees?: number | null;
|
|
138
261
|
};
|
|
@@ -162,3 +285,19 @@ export type PostActionAvailability = {
|
|
|
162
285
|
* and reposts need create-*, likes need core-posts-react.
|
|
163
286
|
*/
|
|
164
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;
|