@openpeepshq/common 0.3.2 → 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.
- package/dist/lib/adminSections.d.ts +4 -0
- package/dist/lib/adminSections.js +5 -0
- package/dist/lib/attachmentHelpers.js +5 -1
- package/dist/lib/capabilitiesHelpers.d.ts +9 -0
- package/dist/lib/capabilitiesHelpers.js +9 -0
- package/dist/lib/csvHelpers.d.ts +2 -0
- package/dist/lib/csvHelpers.js +13 -0
- package/dist/lib/eventRecurrence.d.ts +11 -1
- package/dist/lib/eventRecurrence.js +23 -13
- package/dist/lib/eventWaitlist.d.ts +58 -0
- package/dist/lib/eventWaitlist.js +217 -0
- package/dist/lib/groupHelpers.d.ts +5 -0
- package/dist/lib/groupHelpers.js +16 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/lib/markdownHelpers.d.ts +12 -3
- package/dist/lib/markdownHelpers.js +115 -6
- package/dist/lib/postHelpers.d.ts +27 -5
- package/dist/lib/postHelpers.js +73 -11
- package/dist/lib/profileHelpers.d.ts +12 -2
- package/dist/lib/profileHelpers.js +19 -2
- package/dist/lib/resources.d.ts +29 -1
- package/dist/lib/resources.js +74 -2
- package/dist/lib/utils.js +11 -11
- package/dist/types/admin-livekit.d.ts +23 -0
- package/dist/types/admin-livekit.js +18 -0
- package/dist/types/admin-media.d.ts +41 -0
- package/dist/types/admin-media.js +20 -0
- package/dist/types/api.d.ts +19945 -3526
- package/dist/types/api.js +16 -10
- package/dist/types/capabilities.d.ts +2 -2
- package/dist/types/capabilities.js +3 -0
- package/dist/types/config.d.ts +15 -0
- package/dist/types/config.js +14 -2
- package/dist/types/db.d.ts +65 -22
- package/dist/types/forbiddenHandles.d.ts +28 -0
- package/dist/types/forbiddenHandles.js +75 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/internal.d.ts +163 -44
- package/dist/types/models.d.ts +46 -14
- package/dist/types/models.js +38 -28
- package/dist/types/notifications.d.ts +2 -0
- package/dist/types/notifications.js +4 -2
- package/dist/types/roleDefaults.js +109 -95
- package/dist/types/stats.d.ts +348 -108
- package/package.json +7 -6
- package/src/lib/adminSections.ts +5 -0
- package/src/lib/attachmentHelpers.ts +18 -12
- package/src/lib/capabilitiesHelpers.ts +15 -0
- package/src/lib/csvHelpers.ts +19 -3
- package/src/lib/eventRecurrence.ts +33 -19
- package/src/lib/eventWaitlist.ts +325 -0
- package/src/lib/groupHelpers.ts +25 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/markdownHelpers.ts +121 -7
- package/src/lib/postHelpers.ts +102 -13
- package/src/lib/profileHelpers.ts +31 -2
- package/src/lib/resources.ts +105 -2
- package/src/lib/utils.ts +40 -31
- package/src/types/admin-livekit.ts +24 -0
- package/src/types/admin-media.ts +29 -0
- package/src/types/api.ts +20 -10
- package/src/types/auth.ts +2 -2
- package/src/types/capabilities.ts +3 -0
- package/src/types/config.ts +19 -10
- package/src/types/forbiddenHandles.ts +103 -0
- package/src/types/index.ts +2 -0
- package/src/types/models.ts +70 -33
- package/src/types/notifications.ts +7 -7
- package/src/types/roleDefaults.ts +115 -96
- package/src/types/stripe.ts +3 -1
|
@@ -56,6 +56,19 @@ export const markdownPlainText = (markdown) => {
|
|
|
56
56
|
.replace(/\s+/g, ' ')
|
|
57
57
|
.trim();
|
|
58
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* Removes inline images (`` and `![alt]`) from markdown while
|
|
61
|
+
* leaving all other formatting intact. Used to keep abbreviated previews to
|
|
62
|
+
* text+basic formatting and put the full (image-bearing) content in an overlay.
|
|
63
|
+
*/
|
|
64
|
+
export const stripMarkdownImages = (markdown) => {
|
|
65
|
+
if (!markdown)
|
|
66
|
+
return '';
|
|
67
|
+
return markdown
|
|
68
|
+
.replace(/\[!\[[^\]]*\]\([^)]*\)\]\([^)]*\)/g, '')
|
|
69
|
+
.replace(/!\[[^\]]*\]\([^)]*\)/g, ' ')
|
|
70
|
+
.replace(/!\[[^\]]*\]/g, '');
|
|
71
|
+
};
|
|
59
72
|
export const firstNWords = (markdown, n) => {
|
|
60
73
|
if (!markdown)
|
|
61
74
|
return '';
|
|
@@ -84,9 +97,12 @@ export const firstNWords = (markdown, n) => {
|
|
|
84
97
|
};
|
|
85
98
|
/**
|
|
86
99
|
* Truncates markdown to at most `maxBlocks` block-level regions, then to
|
|
87
|
-
* `maxChars` characters at a word boundary.
|
|
88
|
-
*
|
|
89
|
-
* the
|
|
100
|
+
* `maxChars` characters at a word boundary. Protected inline constructs — links,
|
|
101
|
+
* images and inline code spans — are never severed: a construct that would not
|
|
102
|
+
* fit whole is omitted (along with what follows), so the result is always valid
|
|
103
|
+
* markdown. Emphasis markers and inline-code backticks left open by a word-boundary
|
|
104
|
+
* cut are closed, so renderers never emit raw markup leaking into copy. An
|
|
105
|
+
* ellipsis is appended only when the content was actually shortened.
|
|
90
106
|
*/
|
|
91
107
|
export const truncateMarkdown = (markdown, maxBlocks, maxChars) => {
|
|
92
108
|
if (!markdown)
|
|
@@ -103,12 +119,105 @@ export const truncateMarkdown = (markdown, maxBlocks, maxChars) => {
|
|
|
103
119
|
if (content.length <= maxChars) {
|
|
104
120
|
return hadMoreBlocks ? `${content}…` : content;
|
|
105
121
|
}
|
|
106
|
-
|
|
122
|
+
return `${closeOpenInline(sliceMarkdownTo(content, maxChars))}…`;
|
|
123
|
+
};
|
|
124
|
+
/** Inline constructs kept whole so truncation never breaks their syntax. */
|
|
125
|
+
const PROTECTED_RE = /(`[^`]+`)|(!\[[^\]]*\]\([^)]*\))|(\[[^\]]*\]\([^)]*\))/g;
|
|
126
|
+
/**
|
|
127
|
+
* Walks `content` accumulating plain text (cuttable at a word boundary) and
|
|
128
|
+
* protected spans (kept whole). A protected span that would not fit in the
|
|
129
|
+
* remaining budget ends the snippet instead of being severed.
|
|
130
|
+
*/
|
|
131
|
+
const sliceMarkdownTo = (content, maxChars) => {
|
|
132
|
+
let out = '';
|
|
133
|
+
let pos = 0;
|
|
134
|
+
while (pos < content.length) {
|
|
135
|
+
PROTECTED_RE.lastIndex = pos;
|
|
136
|
+
const match = PROTECTED_RE.exec(content);
|
|
137
|
+
const spanStart = match ? match.index : content.length;
|
|
138
|
+
const plain = content.slice(pos, spanStart);
|
|
139
|
+
const room = maxChars - out.length;
|
|
140
|
+
if (room <= 0)
|
|
141
|
+
break;
|
|
142
|
+
if (plain.length <= room) {
|
|
143
|
+
out += plain;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
out += cutAtWordBoundary(plain, room);
|
|
147
|
+
return out.trimEnd();
|
|
148
|
+
}
|
|
149
|
+
if (match) {
|
|
150
|
+
const span = match[0];
|
|
151
|
+
if (out.length + span.length <= maxChars) {
|
|
152
|
+
out += span;
|
|
153
|
+
pos = match.index + span.length;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
// Whole span doesn't fit — drop it (and the rest) rather than sever it.
|
|
157
|
+
return out.trimEnd();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
pos = content.length;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return out.trimEnd();
|
|
165
|
+
};
|
|
166
|
+
const cutAtWordBoundary = (text, max) => {
|
|
167
|
+
const candidate = text.slice(0, max);
|
|
107
168
|
const lastBreak = Math.max(candidate.lastIndexOf(' '), candidate.lastIndexOf('\n'), candidate.lastIndexOf('\t'));
|
|
108
169
|
if (lastBreak > 0) {
|
|
109
|
-
return
|
|
170
|
+
return text.slice(0, lastBreak).trimEnd();
|
|
171
|
+
}
|
|
172
|
+
return candidate;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Best-effort repair: closes emphasis runs and inline-code backticks left
|
|
176
|
+
* dangling by a cut inside their span. List-marker asterisks at the start of a
|
|
177
|
+
* line are treated as plain text, not emphasis.
|
|
178
|
+
*/
|
|
179
|
+
const closeOpenInline = (snippet) => {
|
|
180
|
+
const closers = [];
|
|
181
|
+
let inCode = false;
|
|
182
|
+
let i = 0;
|
|
183
|
+
while (i < snippet.length) {
|
|
184
|
+
const ch = snippet[i];
|
|
185
|
+
const atLineStart = i === 0 || snippet[i - 1] === '\n';
|
|
186
|
+
if (ch === '`') {
|
|
187
|
+
inCode = !inCode;
|
|
188
|
+
i++;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (inCode) {
|
|
192
|
+
i++;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (!atLineStart && (ch === '*' || ch === '_' || ch === '~')) {
|
|
196
|
+
let j = i + 1;
|
|
197
|
+
while (j < snippet.length && snippet[j] === ch)
|
|
198
|
+
j++;
|
|
199
|
+
const marker = snippet.slice(i, j);
|
|
200
|
+
// A lone '~' is not emphasis; treat length-1 tilde as plain text.
|
|
201
|
+
if (ch === '~' && marker.length < 2) {
|
|
202
|
+
i++;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const opener = marker.length >= 2 ? marker.slice(0, 2) : marker;
|
|
206
|
+
if (closers[closers.length - 1] === opener) {
|
|
207
|
+
closers.pop();
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
closers.push(opener);
|
|
211
|
+
}
|
|
212
|
+
i = j;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
i++;
|
|
110
216
|
}
|
|
111
|
-
|
|
217
|
+
if (closers.length === 0 && !inCode)
|
|
218
|
+
return snippet;
|
|
219
|
+
const tail = closers.reverse().join('') + (inCode ? '`' : '');
|
|
220
|
+
return `${snippet}${tail}`;
|
|
112
221
|
};
|
|
113
222
|
/** Average adult reading speed (words per minute). */
|
|
114
223
|
const DEFAULT_WORDS_PER_MINUTE = 210;
|
|
@@ -23,7 +23,7 @@ export declare const collectVotes: (post: PublicPost) => {
|
|
|
23
23
|
votes: AnswerWithPublicProfile[];
|
|
24
24
|
};
|
|
25
25
|
export declare const calculateEffectiveRsvps: (post: PublicPost, recurrenceId?: string) => {
|
|
26
|
-
response: "no" | "yes" | "tentative" | "removed";
|
|
26
|
+
response: "no" | "yes" | "tentative" | "removed" | "waitlist";
|
|
27
27
|
profile: {
|
|
28
28
|
id: string;
|
|
29
29
|
type: "local" | "guest" | "federated";
|
|
@@ -84,9 +84,11 @@ export declare const calculateEffectiveRsvps: (post: PublicPost, recurrenceId?:
|
|
|
84
84
|
};
|
|
85
85
|
createdAt: string;
|
|
86
86
|
recurrenceId?: string | undefined;
|
|
87
|
+
waitlistJoinedAt?: string | undefined;
|
|
88
|
+
offerExpiresAt?: string | undefined;
|
|
87
89
|
}[];
|
|
88
90
|
export declare const getEffectiveRsvp: (post: PublicPost, profileId: string, recurrenceId?: string) => {
|
|
89
|
-
response: "no" | "yes" | "tentative" | "removed";
|
|
91
|
+
response: "no" | "yes" | "tentative" | "removed" | "waitlist";
|
|
90
92
|
profile: {
|
|
91
93
|
id: string;
|
|
92
94
|
type: "local" | "guest" | "federated";
|
|
@@ -147,12 +149,14 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string, rec
|
|
|
147
149
|
};
|
|
148
150
|
createdAt: string;
|
|
149
151
|
recurrenceId?: string | undefined;
|
|
152
|
+
waitlistJoinedAt?: string | undefined;
|
|
153
|
+
offerExpiresAt?: string | undefined;
|
|
150
154
|
} | undefined;
|
|
151
155
|
export declare const countYesRsvps: (post: PublicPost, recurrenceId?: string) => number;
|
|
152
156
|
export declare const countSeriesYesRsvps: (post: PublicPost) => number;
|
|
153
157
|
/** Current roster: attending guests, plus organizer removals that can be restored. */
|
|
154
158
|
export declare const listedRsvps: (rsvps: PublicRsvp[]) => {
|
|
155
|
-
response: "no" | "yes" | "tentative" | "removed";
|
|
159
|
+
response: "no" | "yes" | "tentative" | "removed" | "waitlist";
|
|
156
160
|
profile: {
|
|
157
161
|
id: string;
|
|
158
162
|
type: "local" | "guest" | "federated";
|
|
@@ -213,6 +217,8 @@ export declare const listedRsvps: (rsvps: PublicRsvp[]) => {
|
|
|
213
217
|
};
|
|
214
218
|
createdAt: string;
|
|
215
219
|
recurrenceId?: string | undefined;
|
|
220
|
+
waitlistJoinedAt?: string | undefined;
|
|
221
|
+
offerExpiresAt?: string | undefined;
|
|
216
222
|
}[];
|
|
217
223
|
/** Set only when a member leaves an attending RSVP. A second "no" stays unset. */
|
|
218
224
|
export type RsvpCancelNotice = {
|
|
@@ -249,15 +255,20 @@ export declare const displayRsvpForProfile: (post: PublicPost, profileId: string
|
|
|
249
255
|
now?: Date;
|
|
250
256
|
}) => PublicRsvp | undefined;
|
|
251
257
|
export declare const isCapacityEvent: (event: Event) => boolean;
|
|
258
|
+
export declare const DEFAULT_WAITLIST_OFFER_MINUTES = 60;
|
|
259
|
+
export declare const MAX_WAITLIST_OFFER_MINUTES: number;
|
|
252
260
|
export declare const parseEventMaxAttendeesInput: (raw: string) => number | undefined;
|
|
261
|
+
export declare const normalizeWaitlistOfferMinutes: (value: number | null | undefined) => number | undefined;
|
|
262
|
+
export declare const parseEventWaitlistOfferMinutesInput: (raw: string) => number | undefined;
|
|
253
263
|
export declare const withoutEventMaxAttendees: <T extends Event>(event: T) => T;
|
|
254
264
|
export declare const normalizeEventDataForSave: <T extends Event>(event: T) => T;
|
|
255
265
|
/** Null capacity means it was cleared; strip for validation/output. */
|
|
256
266
|
export declare const normalizeEventDataFromDb: <T extends Event>(event: T) => T;
|
|
257
267
|
export declare const normalizePostDataFromDb: (data: PostDataUnion) => PostDataUnion;
|
|
258
|
-
/** Nested `data` updates send null to remove
|
|
259
|
-
export type EventDbUpdate = Omit<Event, 'maxAttendees'> & {
|
|
268
|
+
/** Nested `data` updates send null to remove cleared capacity fields. */
|
|
269
|
+
export type EventDbUpdate = Omit<Event, 'maxAttendees' | 'waitlistOfferMinutes'> & {
|
|
260
270
|
maxAttendees?: number | null;
|
|
271
|
+
waitlistOfferMinutes?: number | null;
|
|
261
272
|
};
|
|
262
273
|
export declare const eventDataForDbUpdate: (previous: Event | undefined, normalized: Event) => EventDbUpdate;
|
|
263
274
|
export declare const canManageEventRsvps: (profile: Pick<PublicProfile, "id"> | undefined, post: PublicPost) => boolean;
|
|
@@ -296,8 +307,19 @@ export declare const toHiddenPost: <T extends {
|
|
|
296
307
|
export declare const isHiddenPost: (post: {
|
|
297
308
|
hidden?: boolean;
|
|
298
309
|
}) => boolean;
|
|
310
|
+
export declare const participantIds: (post: Pick<PublicPost, "audience" | "profile"> & {
|
|
311
|
+
creatorId?: string;
|
|
312
|
+
}) => Set<string>;
|
|
313
|
+
/** Direct message between exactly two participants. */
|
|
314
|
+
export declare const isOneToOneDm: (post: Pick<PublicPost, "visibility" | "audience" | "profile"> & {
|
|
315
|
+
creatorId?: string;
|
|
316
|
+
}) => boolean;
|
|
299
317
|
export declare const isOneToOneWithBlocked: (post: Pick<PublicPost, "visibility" | "audience" | "profile"> & {
|
|
300
318
|
creatorId?: string;
|
|
301
319
|
}, viewer: {
|
|
302
320
|
id: string;
|
|
303
321
|
} | undefined | null, blockedIds?: Set<string> | string[]) => boolean;
|
|
322
|
+
/** First usable text field of a post, whitespace-collapsed and truncated. */
|
|
323
|
+
export declare const messagePreviewText: (message: PublicPost, maxLength?: number) => string;
|
|
324
|
+
/** Display names of a post's audience minus the viewer, comma-joined. */
|
|
325
|
+
export declare const conversationLabel: (message: PublicPost, viewerId?: string) => string;
|
package/dist/lib/postHelpers.js
CHANGED
|
@@ -5,6 +5,7 @@ import { formatEventWhen } from './eventTime.js';
|
|
|
5
5
|
import { checkGroupCapabilities, checkPostCapabilities, checkRoleCapabilities, } from './capabilitiesHelpers.js';
|
|
6
6
|
import { scopeMatches } from './scopeHelpers.js';
|
|
7
7
|
import { countBy, dateSorter, groupBy, transformValues } from './utils.js';
|
|
8
|
+
import { truncateText } from './text.js';
|
|
8
9
|
const buildThread = (rootPost, postList) => ({
|
|
9
10
|
...rootPost,
|
|
10
11
|
children: postList
|
|
@@ -272,8 +273,7 @@ export const seriesYesBlockedByCapacity = (post, profileId, now = new Date()) =>
|
|
|
272
273
|
if (!event || !maxAttendees || !event.recurrence)
|
|
273
274
|
return false;
|
|
274
275
|
const occurrences = listRsvpOccurrences(event, now);
|
|
275
|
-
//
|
|
276
|
-
// occurrence started before `now`), fall back to the series-level count.
|
|
276
|
+
// No open date left (the current one has ended and nothing follows).
|
|
277
277
|
if (occurrences.length === 0) {
|
|
278
278
|
const current = getEffectiveRsvp(post, profileId);
|
|
279
279
|
if (current?.response !== 'yes' &&
|
|
@@ -316,6 +316,11 @@ export const recurringEventHasOpenOccurrence = (post, profileId, now = new Date(
|
|
|
316
316
|
*/
|
|
317
317
|
export const displayRsvpForProfile = (post, profileId, options) => {
|
|
318
318
|
const event = post.data?.type === 'event' ? post.data : undefined;
|
|
319
|
+
// One-time events have no occurrences. Older claims stamped the start time
|
|
320
|
+
// onto some RSVPs; a newer unscoped waitlist must still be the current one.
|
|
321
|
+
if (event && !event.recurrence) {
|
|
322
|
+
return getEffectiveRsvp(post, profileId);
|
|
323
|
+
}
|
|
319
324
|
const scopedId = options?.lockToOccurrence
|
|
320
325
|
? options.recurrenceId
|
|
321
326
|
: event
|
|
@@ -336,6 +341,8 @@ export const displayRsvpForProfile = (post, profileId, options) => {
|
|
|
336
341
|
return scoped;
|
|
337
342
|
};
|
|
338
343
|
export const isCapacityEvent = (event) => !!event.maxAttendees;
|
|
344
|
+
export const DEFAULT_WAITLIST_OFFER_MINUTES = 60;
|
|
345
|
+
export const MAX_WAITLIST_OFFER_MINUTES = 7 * 24 * 60;
|
|
339
346
|
export const parseEventMaxAttendeesInput = (raw) => {
|
|
340
347
|
const trimmed = raw.trim();
|
|
341
348
|
if (!trimmed)
|
|
@@ -343,8 +350,22 @@ export const parseEventMaxAttendeesInput = (raw) => {
|
|
|
343
350
|
const parsed = Number.parseInt(trimmed, 10);
|
|
344
351
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
|
|
345
352
|
};
|
|
353
|
+
export const normalizeWaitlistOfferMinutes = (value) => {
|
|
354
|
+
if (value == null || !Number.isFinite(value))
|
|
355
|
+
return undefined;
|
|
356
|
+
const minutes = Math.trunc(value);
|
|
357
|
+
if (minutes < 1 || minutes > MAX_WAITLIST_OFFER_MINUTES)
|
|
358
|
+
return undefined;
|
|
359
|
+
return minutes;
|
|
360
|
+
};
|
|
361
|
+
export const parseEventWaitlistOfferMinutesInput = (raw) => {
|
|
362
|
+
const trimmed = raw.trim();
|
|
363
|
+
if (!trimmed)
|
|
364
|
+
return undefined;
|
|
365
|
+
return normalizeWaitlistOfferMinutes(Number.parseInt(trimmed, 10));
|
|
366
|
+
};
|
|
346
367
|
export const withoutEventMaxAttendees = (event) => {
|
|
347
|
-
const { maxAttendees: _, ...rest } = event;
|
|
368
|
+
const { maxAttendees: _, waitlistOfferMinutes: __, ...rest } = event;
|
|
348
369
|
return rest;
|
|
349
370
|
};
|
|
350
371
|
export const normalizeEventDataForSave = (event) => {
|
|
@@ -354,21 +375,34 @@ export const normalizeEventDataForSave = (event) => {
|
|
|
354
375
|
maxAttendees < 1) {
|
|
355
376
|
return withoutEventMaxAttendees(event);
|
|
356
377
|
}
|
|
357
|
-
|
|
378
|
+
const minutes = normalizeWaitlistOfferMinutes(event.waitlistOfferMinutes);
|
|
379
|
+
const { waitlistOfferMinutes: _, ...rest } = event;
|
|
380
|
+
return {
|
|
381
|
+
...rest,
|
|
382
|
+
maxAttendees: Math.trunc(maxAttendees),
|
|
383
|
+
...(minutes != null ? { waitlistOfferMinutes: minutes } : {}),
|
|
384
|
+
};
|
|
358
385
|
};
|
|
359
386
|
/** Null capacity means it was cleared; strip for validation/output. */
|
|
360
387
|
export const normalizeEventDataFromDb = (event) => {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
388
|
+
const { maxAttendees, waitlistOfferMinutes, ...rest } = event;
|
|
389
|
+
return {
|
|
390
|
+
...rest,
|
|
391
|
+
...(maxAttendees != null ? { maxAttendees } : {}),
|
|
392
|
+
...(waitlistOfferMinutes != null ? { waitlistOfferMinutes } : {}),
|
|
393
|
+
};
|
|
365
394
|
};
|
|
366
395
|
export const normalizePostDataFromDb = (data) => data.type === 'event' ? normalizeEventDataFromDb(data) : data;
|
|
367
396
|
export const eventDataForDbUpdate = (previous, normalized) => {
|
|
397
|
+
let next = normalized;
|
|
368
398
|
if (previous?.maxAttendees != null && !('maxAttendees' in normalized)) {
|
|
369
|
-
|
|
399
|
+
next = { ...next, maxAttendees: null };
|
|
400
|
+
}
|
|
401
|
+
if (previous?.waitlistOfferMinutes != null &&
|
|
402
|
+
!('waitlistOfferMinutes' in normalized)) {
|
|
403
|
+
next = { ...next, waitlistOfferMinutes: null };
|
|
370
404
|
}
|
|
371
|
-
return
|
|
405
|
+
return next;
|
|
372
406
|
};
|
|
373
407
|
export const canManageEventRsvps = (profile, post) => !!(profile &&
|
|
374
408
|
(post.profile.id === profile.id || canModerateJam(profile, post)));
|
|
@@ -390,6 +424,13 @@ export const getJamCapacityJoinBlock = (post, profile, recurrenceId) => {
|
|
|
390
424
|
if (countYesRsvps(post, recurrenceId) >= event.maxAttendees) {
|
|
391
425
|
return { blocked: true, reason: 'full' };
|
|
392
426
|
}
|
|
427
|
+
// A freed seat stays reserved for the waitlist unless this profile holds the offer.
|
|
428
|
+
const waiting = calculateEffectiveRsvps(post, recurrenceId).filter((rsvp) => rsvp.response === 'waitlist' && rsvp.profile.type !== 'federated');
|
|
429
|
+
const mine = waiting.find((rsvp) => rsvp.profile.id === profile.id);
|
|
430
|
+
const offerOpen = !!mine?.offerExpiresAt && Date.parse(mine.offerExpiresAt) > Date.now();
|
|
431
|
+
if (waiting.length > 0 && !offerOpen) {
|
|
432
|
+
return { blocked: true, reason: 'full' };
|
|
433
|
+
}
|
|
393
434
|
return { blocked: true, reason: 'rsvp-required' };
|
|
394
435
|
};
|
|
395
436
|
export const canDeletePost = (authData, post, config) => checkPostCapabilities(authData, ['core-posts-delete'], post, config).success;
|
|
@@ -459,13 +500,15 @@ export const toHiddenPost = (post) => ({
|
|
|
459
500
|
},
|
|
460
501
|
});
|
|
461
502
|
export const isHiddenPost = (post) => !!post.hidden;
|
|
462
|
-
const participantIds = (post) => {
|
|
503
|
+
export const participantIds = (post) => {
|
|
463
504
|
const ids = new Set((post.audience ?? []).map((member) => member.id).filter(Boolean));
|
|
464
505
|
const creatorId = post.creatorId ?? post.profile?.id;
|
|
465
506
|
if (creatorId)
|
|
466
507
|
ids.add(creatorId);
|
|
467
508
|
return ids;
|
|
468
509
|
};
|
|
510
|
+
/** Direct message between exactly two participants. */
|
|
511
|
+
export const isOneToOneDm = (post) => post.visibility === 'direct' && participantIds(post).size === 2;
|
|
469
512
|
export const isOneToOneWithBlocked = (post, viewer, blockedIds) => {
|
|
470
513
|
if (!viewer || post.visibility !== 'direct')
|
|
471
514
|
return false;
|
|
@@ -476,3 +519,22 @@ export const isOneToOneWithBlocked = (post, viewer, blockedIds) => {
|
|
|
476
519
|
others.delete(viewer.id);
|
|
477
520
|
return others.size === 1 && blocked.has([...others][0]);
|
|
478
521
|
};
|
|
522
|
+
/** First usable text field of a post, whitespace-collapsed and truncated. */
|
|
523
|
+
export const messagePreviewText = (message, maxLength = 160) => {
|
|
524
|
+
const data = message.data;
|
|
525
|
+
if (!data || typeof data !== 'object')
|
|
526
|
+
return '';
|
|
527
|
+
const text = 'content' in data && typeof data.content === 'string' && data.content
|
|
528
|
+
? data.content
|
|
529
|
+
: 'name' in data && typeof data.name === 'string'
|
|
530
|
+
? data.name
|
|
531
|
+
: 'title' in data && typeof data.title === 'string'
|
|
532
|
+
? data.title
|
|
533
|
+
: '';
|
|
534
|
+
return truncateText(text.replace(/\s+/g, ' ').trim(), maxLength);
|
|
535
|
+
};
|
|
536
|
+
/** Display names of a post's audience minus the viewer, comma-joined. */
|
|
537
|
+
export const conversationLabel = (message, viewerId) => (message.audience ?? [])
|
|
538
|
+
.filter((profile) => profile.id !== viewerId)
|
|
539
|
+
.map((profile) => profile.displayName || `@${profile.handle}`)
|
|
540
|
+
.join(', ');
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import type { GroupWithMeta, InviteLinkWithMeta, ProfileSettings, ProfileWithMeta, PublicProfile, StripeSubscriptionData } from '../types';
|
|
2
2
|
export declare const PROFILE_DISPLAY_NAME_MAX_LENGTH = 30;
|
|
3
|
-
/** Public sentinel shown for soft-deleted
|
|
4
|
-
export declare const DELETED_AUTHOR_DISPLAY_NAME = "Deleted
|
|
3
|
+
/** Public sentinel shown for soft-deleted profiles (API + clients). */
|
|
4
|
+
export declare const DELETED_AUTHOR_DISPLAY_NAME = "Deleted Profile";
|
|
5
5
|
export declare const DELETED_AUTHOR_HANDLE = "deleted";
|
|
6
6
|
export declare const clampProfileDisplayName: (displayName: string | undefined | null) => string | undefined;
|
|
7
7
|
export declare const isDeletedProfile: (profile: {
|
|
8
8
|
deletedAt?: string | null;
|
|
9
9
|
} | undefined | null) => boolean;
|
|
10
|
+
type DeletedProfileIdentity = {
|
|
11
|
+
deletedAt?: string | null;
|
|
12
|
+
displayName?: unknown;
|
|
13
|
+
handle?: unknown;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Deleted rows keep their original handle (the column is unique) and may have
|
|
17
|
+
* no display name. Public hydration fills in the sentinel when it is missing.
|
|
18
|
+
*/
|
|
19
|
+
export declare const withDeletedProfileIdentity: <T extends DeletedProfileIdentity>(profile: T) => T;
|
|
10
20
|
/**
|
|
11
21
|
* Strip PII from a soft-deleted profile for public API / UI surfaces.
|
|
12
22
|
* Keeps id + timestamps (including deletedAt) so clients can detect the state.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const containsIgnoreCase = (candidate, query) => candidate.toLowerCase().indexOf(query.toLowerCase()) > -1;
|
|
2
2
|
export const PROFILE_DISPLAY_NAME_MAX_LENGTH = 30;
|
|
3
|
-
/** Public sentinel shown for soft-deleted
|
|
4
|
-
export const DELETED_AUTHOR_DISPLAY_NAME = 'Deleted
|
|
3
|
+
/** Public sentinel shown for soft-deleted profiles (API + clients). */
|
|
4
|
+
export const DELETED_AUTHOR_DISPLAY_NAME = 'Deleted Profile';
|
|
5
5
|
export const DELETED_AUTHOR_HANDLE = 'deleted';
|
|
6
6
|
export const clampProfileDisplayName = (displayName) => {
|
|
7
7
|
if (!displayName)
|
|
@@ -10,6 +10,23 @@ export const clampProfileDisplayName = (displayName) => {
|
|
|
10
10
|
return clamped || undefined;
|
|
11
11
|
};
|
|
12
12
|
export const isDeletedProfile = (profile) => !!profile?.deletedAt;
|
|
13
|
+
/**
|
|
14
|
+
* Deleted rows keep their original handle (the column is unique) and may have
|
|
15
|
+
* no display name. Public hydration fills in the sentinel when it is missing.
|
|
16
|
+
*/
|
|
17
|
+
export const withDeletedProfileIdentity = (profile) => {
|
|
18
|
+
if (!isDeletedProfile(profile))
|
|
19
|
+
return profile;
|
|
20
|
+
if (profile.displayName === DELETED_AUTHOR_DISPLAY_NAME &&
|
|
21
|
+
profile.handle === DELETED_AUTHOR_HANDLE) {
|
|
22
|
+
return profile;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
...profile,
|
|
26
|
+
displayName: DELETED_AUTHOR_DISPLAY_NAME,
|
|
27
|
+
handle: DELETED_AUTHOR_HANDLE,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
13
30
|
/**
|
|
14
31
|
* Strip PII from a soft-deleted profile for public API / UI surfaces.
|
|
15
32
|
* Keeps id + timestamps (including deletedAt) so clients can detect the state.
|
package/dist/lib/resources.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { RESOURCE_TITLE_MAX_LENGTH, type MediaAttachmentData, type ResourceKind, type VisibilityType } from '../types/models';
|
|
2
|
+
export { RESOURCE_TITLE_MAX_LENGTH };
|
|
3
|
+
export declare const isValidResourceUrl: (url: string | undefined) => boolean;
|
|
2
4
|
export declare const RESOURCE_KINDS: readonly ["video", "file", "gallery", "audio", "link"];
|
|
3
5
|
export declare const attachmentMediaKind: (att: Pick<MediaAttachmentData, "type" | "meta">) => "image" | "video" | "audio" | "file";
|
|
4
6
|
export declare const resourceHasRequiredMedia: (resource: {
|
|
@@ -6,6 +8,32 @@ export declare const resourceHasRequiredMedia: (resource: {
|
|
|
6
8
|
url?: string;
|
|
7
9
|
attachments?: MediaAttachmentData[];
|
|
8
10
|
}) => boolean;
|
|
11
|
+
export declare const RESOURCE_FORM_ISSUES: readonly ["title", "titleLength", "url", "media", "audience", "group"];
|
|
12
|
+
export type ResourceFormIssue = (typeof RESOURCE_FORM_ISSUES)[number];
|
|
13
|
+
export declare const resourceFormIssues: (input: {
|
|
14
|
+
title?: string;
|
|
15
|
+
resourceKind: ResourceKind;
|
|
16
|
+
url?: string;
|
|
17
|
+
attachments?: MediaAttachmentData[];
|
|
18
|
+
visibility?: string | null;
|
|
19
|
+
audience?: readonly unknown[] | null;
|
|
20
|
+
groupId?: string | null;
|
|
21
|
+
}) => ResourceFormIssue[];
|
|
22
|
+
/**
|
|
23
|
+
* Draft visibility the profile may actually post with. A group-only author
|
|
24
|
+
* starts on Specific Group; a single postable group is preselected. Pass
|
|
25
|
+
* `postableGroupIds: null` while memberships are still loading so an existing
|
|
26
|
+
* group choice is not cleared.
|
|
27
|
+
*/
|
|
28
|
+
export declare const resourceVisibilityForCapabilities: (input: {
|
|
29
|
+
visibility?: string | null;
|
|
30
|
+
groupId?: string | null;
|
|
31
|
+
allowed: readonly VisibilityType[];
|
|
32
|
+
postableGroupIds: readonly string[] | null;
|
|
33
|
+
}) => {
|
|
34
|
+
visibility: VisibilityType;
|
|
35
|
+
groupId?: string;
|
|
36
|
+
};
|
|
9
37
|
export type CategoryNode = {
|
|
10
38
|
name: string;
|
|
11
39
|
path: string[];
|
package/dist/lib/resources.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { RESOURCE_TITLE_MAX_LENGTH, visibilityTypeValues, } from '../types/models.js';
|
|
3
|
+
export { RESOURCE_TITLE_MAX_LENGTH };
|
|
4
|
+
/** Matches `resourcePostSchema.url` (`z.url()`), after trimming. */
|
|
5
|
+
const resourceUrlSchema = z.url();
|
|
6
|
+
export const isValidResourceUrl = (url) => {
|
|
7
|
+
const trimmed = url?.trim() ?? '';
|
|
8
|
+
if (!trimmed)
|
|
9
|
+
return false;
|
|
10
|
+
return resourceUrlSchema.safeParse(trimmed).success;
|
|
11
|
+
};
|
|
1
12
|
export const RESOURCE_KINDS = [
|
|
2
13
|
'video',
|
|
3
14
|
'file',
|
|
@@ -17,8 +28,9 @@ export const attachmentMediaKind = (att) => {
|
|
|
17
28
|
return 'file';
|
|
18
29
|
};
|
|
19
30
|
export const resourceHasRequiredMedia = (resource) => {
|
|
20
|
-
if (resource.resourceKind === 'link')
|
|
21
|
-
return
|
|
31
|
+
if (resource.resourceKind === 'link') {
|
|
32
|
+
return isValidResourceUrl(resource.url);
|
|
33
|
+
}
|
|
22
34
|
const need = resource.resourceKind === 'gallery'
|
|
23
35
|
? 'image'
|
|
24
36
|
: resource.resourceKind === 'video'
|
|
@@ -28,6 +40,66 @@ export const resourceHasRequiredMedia = (resource) => {
|
|
|
28
40
|
: 'file';
|
|
29
41
|
return (resource.attachments ?? []).some((att) => attachmentMediaKind(att) === need);
|
|
30
42
|
};
|
|
43
|
+
export const RESOURCE_FORM_ISSUES = [
|
|
44
|
+
'title',
|
|
45
|
+
'titleLength',
|
|
46
|
+
'url',
|
|
47
|
+
'media',
|
|
48
|
+
'audience',
|
|
49
|
+
'group',
|
|
50
|
+
];
|
|
51
|
+
export const resourceFormIssues = (input) => {
|
|
52
|
+
const issues = [];
|
|
53
|
+
if (!input.title?.trim())
|
|
54
|
+
issues.push('title');
|
|
55
|
+
else if (input.title.length > RESOURCE_TITLE_MAX_LENGTH) {
|
|
56
|
+
issues.push('titleLength');
|
|
57
|
+
}
|
|
58
|
+
if (input.resourceKind === 'link') {
|
|
59
|
+
if (!isValidResourceUrl(input.url))
|
|
60
|
+
issues.push('url');
|
|
61
|
+
}
|
|
62
|
+
else if (!resourceHasRequiredMedia(input)) {
|
|
63
|
+
issues.push('media');
|
|
64
|
+
}
|
|
65
|
+
if (input.visibility === 'direct' && !input.audience?.length) {
|
|
66
|
+
issues.push('audience');
|
|
67
|
+
}
|
|
68
|
+
if (input.visibility === 'group' && !input.groupId) {
|
|
69
|
+
issues.push('group');
|
|
70
|
+
}
|
|
71
|
+
return issues;
|
|
72
|
+
};
|
|
73
|
+
const isVisibility = (value) => !!value && visibilityTypeValues.includes(value);
|
|
74
|
+
/**
|
|
75
|
+
* Draft visibility the profile may actually post with. A group-only author
|
|
76
|
+
* starts on Specific Group; a single postable group is preselected. Pass
|
|
77
|
+
* `postableGroupIds: null` while memberships are still loading so an existing
|
|
78
|
+
* group choice is not cleared.
|
|
79
|
+
*/
|
|
80
|
+
export const resourceVisibilityForCapabilities = (input) => {
|
|
81
|
+
const current = isVisibility(input.visibility) ? input.visibility : 'local';
|
|
82
|
+
const fallback = input.allowed[0];
|
|
83
|
+
if (!fallback) {
|
|
84
|
+
return { visibility: current, groupId: input.groupId ?? undefined };
|
|
85
|
+
}
|
|
86
|
+
const keep = input.allowed.includes(current) ? current : fallback;
|
|
87
|
+
if (keep !== 'group')
|
|
88
|
+
return { visibility: keep };
|
|
89
|
+
if (input.postableGroupIds == null) {
|
|
90
|
+
return { visibility: 'group', groupId: input.groupId ?? undefined };
|
|
91
|
+
}
|
|
92
|
+
const kept = input.groupId && input.postableGroupIds.includes(input.groupId)
|
|
93
|
+
? input.groupId
|
|
94
|
+
: undefined;
|
|
95
|
+
return {
|
|
96
|
+
visibility: 'group',
|
|
97
|
+
groupId: kept ??
|
|
98
|
+
(input.postableGroupIds.length === 1
|
|
99
|
+
? input.postableGroupIds[0]
|
|
100
|
+
: undefined),
|
|
101
|
+
};
|
|
102
|
+
};
|
|
31
103
|
export const categoryTreeFromPaths = (paths) => {
|
|
32
104
|
const root = [];
|
|
33
105
|
for (const path of paths) {
|
package/dist/lib/utils.js
CHANGED
|
@@ -111,25 +111,25 @@ export const formatTimeStamp = (timestamp, startDate) => {
|
|
|
111
111
|
};
|
|
112
112
|
const getMode = (config, profileSettings, systemTheme) => {
|
|
113
113
|
if (profileSettings) {
|
|
114
|
-
if (profileSettings.theme ===
|
|
114
|
+
if (profileSettings.theme === 'system') {
|
|
115
115
|
return systemTheme;
|
|
116
116
|
}
|
|
117
|
-
else if (profileSettings?.theme ===
|
|
118
|
-
return
|
|
117
|
+
else if (profileSettings?.theme === 'dark') {
|
|
118
|
+
return 'dark';
|
|
119
119
|
}
|
|
120
|
-
else if (profileSettings?.theme ===
|
|
121
|
-
return
|
|
120
|
+
else if (profileSettings?.theme === 'light') {
|
|
121
|
+
return 'light';
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
return config.theme.base === 'OpenpeepsDark' ? 'dark' : 'light';
|
|
125
125
|
};
|
|
126
|
-
export const getTheme = (config, profileSettings, systemTheme = getSystemTheme()) => getMode(config, profileSettings, systemTheme) === 'dark'
|
|
127
|
-
{ ...config.theme.dark, dark: true }
|
|
128
|
-
{ ...config.theme.light, dark: false };
|
|
126
|
+
export const getTheme = (config, profileSettings, systemTheme = getSystemTheme()) => getMode(config, profileSettings, systemTheme) === 'dark'
|
|
127
|
+
? { ...config.theme.dark, dark: true }
|
|
128
|
+
: { ...config.theme.light, dark: false };
|
|
129
129
|
export const getSystemTheme = () => {
|
|
130
|
-
if (typeof window !==
|
|
131
|
-
const systemIsDark = window.matchMedia(
|
|
132
|
-
return systemIsDark ?
|
|
130
|
+
if (typeof window !== 'undefined' && window.matchMedia) {
|
|
131
|
+
const systemIsDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
132
|
+
return systemIsDark ? 'dark' : 'light';
|
|
133
133
|
}
|
|
134
134
|
return 'light';
|
|
135
135
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const livekitDiagnosisCheckIdSchema: z.ZodEnum<{
|
|
3
|
+
url: "url";
|
|
4
|
+
apiKey: "apiKey";
|
|
5
|
+
apiSecret: "apiSecret";
|
|
6
|
+
reachable: "reachable";
|
|
7
|
+
}>;
|
|
8
|
+
export declare const livekitDiagnosisSchema: z.ZodObject<{
|
|
9
|
+
connected: z.ZodBoolean;
|
|
10
|
+
recordingEnabled: z.ZodBoolean;
|
|
11
|
+
url: z.ZodOptional<z.ZodString>;
|
|
12
|
+
error: z.ZodOptional<z.ZodString>;
|
|
13
|
+
checks: z.ZodArray<z.ZodObject<{
|
|
14
|
+
id: z.ZodEnum<{
|
|
15
|
+
url: "url";
|
|
16
|
+
apiKey: "apiKey";
|
|
17
|
+
apiSecret: "apiSecret";
|
|
18
|
+
reachable: "reachable";
|
|
19
|
+
}>;
|
|
20
|
+
ok: z.ZodBoolean;
|
|
21
|
+
}, z.core.$strip>>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
export type LivekitDiagnosis = z.infer<typeof livekitDiagnosisSchema>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const livekitDiagnosisCheckIdSchema = z.enum([
|
|
3
|
+
'url',
|
|
4
|
+
'apiKey',
|
|
5
|
+
'apiSecret',
|
|
6
|
+
'reachable',
|
|
7
|
+
]);
|
|
8
|
+
export const livekitDiagnosisSchema = z.object({
|
|
9
|
+
connected: z.boolean(),
|
|
10
|
+
recordingEnabled: z.boolean(),
|
|
11
|
+
url: z.string().optional(),
|
|
12
|
+
/** Last probe failure. Credentials are redacted before this is returned. */
|
|
13
|
+
error: z.string().optional(),
|
|
14
|
+
checks: z.array(z.object({
|
|
15
|
+
id: livekitDiagnosisCheckIdSchema,
|
|
16
|
+
ok: z.boolean(),
|
|
17
|
+
})),
|
|
18
|
+
});
|