@openpeepshq/common 0.1.46 → 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.js +30 -40
- package/dist/lib/csvHelpers.js +1 -1
- package/dist/lib/eventIcs.js +26 -32
- package/dist/lib/eventRecurrence.d.ts +17 -0
- package/dist/lib/eventRecurrence.js +75 -18
- package/dist/lib/eventTime.js +9 -11
- package/dist/lib/groupHelpers.js +13 -34
- package/dist/lib/groupTemplateHelpers.js +6 -10
- package/dist/lib/jamHelpers.js +6 -9
- package/dist/lib/markdownHelpers.js +2 -3
- package/dist/lib/postHelpers.js +70 -97
- package/dist/lib/profileHelpers.js +17 -24
- package/dist/lib/pushHelpers.js +3 -4
- package/dist/lib/scopeHelpers.js +6 -9
- package/dist/lib/ssoLoginUrl.js +4 -6
- package/dist/lib/ssoProviders.js +35 -39
- 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/api.d.ts +1 -0
- package/dist/types/api.js +1 -1
- package/dist/types/config.d.ts +3 -0
- package/dist/types/config.js +3 -0
- package/dist/types/models.js +1 -1
- package/dist/types/plugins.js +2 -2
- 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
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Jam, JamRecording, PublicPost, PublicProfile } from '../types';
|
|
2
|
+
import { normalizeRecurrenceId } from './eventRecurrence';
|
|
3
|
+
|
|
4
|
+
export const jamRoomName = (postId: string, _recurrenceId?: string) => postId;
|
|
5
|
+
|
|
6
|
+
const UUID_PREFIX =
|
|
7
|
+
/^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:_.*)?$/i;
|
|
8
|
+
|
|
9
|
+
export const postIdFromJamRoomName = (roomName: string): string => {
|
|
10
|
+
const match = roomName.match(UUID_PREFIX);
|
|
11
|
+
return match?.[1] ?? roomName;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** Recurring jams use one LiveKit room per event; leftover occurrence rooms still collapse. */
|
|
15
|
+
export const uniquePostsById = <T extends { id: string }>(
|
|
16
|
+
posts: (T | undefined)[],
|
|
17
|
+
): T[] => {
|
|
18
|
+
const seen = new Set<string>();
|
|
19
|
+
const unique: T[] = [];
|
|
20
|
+
for (const post of posts) {
|
|
21
|
+
if (!post || seen.has(post.id)) continue;
|
|
22
|
+
seen.add(post.id);
|
|
23
|
+
unique.push(post);
|
|
24
|
+
}
|
|
25
|
+
return unique;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const getJamUrl = (
|
|
29
|
+
id: string,
|
|
30
|
+
origin: string | undefined,
|
|
31
|
+
occurrence?: string,
|
|
32
|
+
) => {
|
|
33
|
+
if (!id) {
|
|
34
|
+
return '';
|
|
35
|
+
}
|
|
36
|
+
const query = occurrence
|
|
37
|
+
? `?occurrence=${encodeURIComponent(normalizeRecurrenceId(occurrence))}`
|
|
38
|
+
: '';
|
|
39
|
+
if (!origin) return `/events/${id}/jam${query}`;
|
|
40
|
+
return `${origin}/events/${id}/jam${query}`;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const jamFromEvent = (event: PublicPost): Jam | undefined => {
|
|
44
|
+
if (event.data?.type === 'event' && event.data?.jam) {
|
|
45
|
+
return event.data.jam;
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const canModerateJam = (
|
|
51
|
+
profile: Pick<PublicProfile, 'id'> | undefined,
|
|
52
|
+
post: PublicPost,
|
|
53
|
+
) => !!(profile && jamFromEvent(post)?.moderators?.includes(profile.id));
|
|
54
|
+
|
|
55
|
+
/** Host or jam moderator — same gate as the event Attendees tab. */
|
|
56
|
+
export const canViewJamAttendees = (
|
|
57
|
+
profile: Pick<PublicProfile, 'id'> | undefined,
|
|
58
|
+
post: PublicPost,
|
|
59
|
+
) =>
|
|
60
|
+
!!(
|
|
61
|
+
profile &&
|
|
62
|
+
(post.profile.id === profile.id || canModerateJam(profile, post))
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
export const canAccessJamRecordings = (
|
|
66
|
+
profile: Pick<PublicProfile, 'id'> | undefined,
|
|
67
|
+
post: PublicPost,
|
|
68
|
+
) => {
|
|
69
|
+
if (!profile) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
if (post.profile.id === profile.id) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
if (post.data?.type !== 'event') {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const event = post.data;
|
|
79
|
+
if (event.moderators?.includes(profile.id)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return !!event.jam?.moderators?.includes(profile.id);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const jamRecordingAcceptsUpload = (status: string | undefined) =>
|
|
86
|
+
status === 'requested' || status === 'active' || status === 'finalizing';
|
|
87
|
+
|
|
88
|
+
export const isRtmpJamRecording = (recording: { kind?: string | null }) =>
|
|
89
|
+
recording.kind === 'rtmp';
|
|
90
|
+
|
|
91
|
+
export const isFileJamRecording = (recording: { kind?: string | null }) =>
|
|
92
|
+
!isRtmpJamRecording(recording);
|
|
93
|
+
|
|
94
|
+
export const pickActiveFileRecording = <T extends { kind?: string | null }>(
|
|
95
|
+
recordings: T[],
|
|
96
|
+
) => recordings.find(isFileJamRecording);
|
|
97
|
+
|
|
98
|
+
export const pickActiveRtmpStream = <T extends { kind?: string | null }>(
|
|
99
|
+
recordings: T[],
|
|
100
|
+
) => recordings.find(isRtmpJamRecording);
|
|
101
|
+
|
|
102
|
+
export const assembleRtmpUrl = (
|
|
103
|
+
url: string,
|
|
104
|
+
streamKey: string,
|
|
105
|
+
): string | undefined => {
|
|
106
|
+
const base = url.trim().replace(/\/+$/, '');
|
|
107
|
+
const key = streamKey.trim().replace(/^\/+/, '');
|
|
108
|
+
if (!base || !key) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
if (!/^rtmps?:\/\//i.test(base)) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
return `${base}/${key}`;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const rtmpDestinationHost = (rtmpUrl: string): string | undefined => {
|
|
118
|
+
try {
|
|
119
|
+
return new URL(rtmpUrl).hostname || undefined;
|
|
120
|
+
} catch {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export const toRtmpStreamResponse = (recording: JamRecording) => ({
|
|
126
|
+
id: recording.id,
|
|
127
|
+
status: recording.status,
|
|
128
|
+
destinationHost: recording.destinationHost,
|
|
129
|
+
egressId: recording.egressId,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
/** Epoch ms from participant metadata when their hand is up. */
|
|
133
|
+
const raisedHandTimestamp = (metadata?: string): number | undefined => {
|
|
134
|
+
if (!metadata) return undefined;
|
|
135
|
+
try {
|
|
136
|
+
const handRaised = (JSON.parse(metadata) as { handRaised?: unknown })
|
|
137
|
+
.handRaised;
|
|
138
|
+
if (typeof handRaised !== 'string' || handRaised.length === 0) {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
const timestamp = Date.parse(handRaised);
|
|
142
|
+
return Number.isNaN(timestamp) ? undefined : timestamp;
|
|
143
|
+
} catch {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Raised hands first, most recent raise first, so the person who just raised
|
|
150
|
+
* moves to the top of the people list and the top-left of the video grid.
|
|
151
|
+
* Everyone else keeps their relative order.
|
|
152
|
+
*/
|
|
153
|
+
export const sortByRaisedHand = <T>(
|
|
154
|
+
items: readonly T[],
|
|
155
|
+
metadataOf: (item: T) => string | undefined,
|
|
156
|
+
): T[] =>
|
|
157
|
+
[...items].sort((a, b) => {
|
|
158
|
+
const aRaised = raisedHandTimestamp(metadataOf(a));
|
|
159
|
+
const bRaised = raisedHandTimestamp(metadataOf(b));
|
|
160
|
+
if (aRaised === undefined && bRaised === undefined) return 0;
|
|
161
|
+
if (aRaised === undefined) return 1;
|
|
162
|
+
if (bRaised === undefined) return -1;
|
|
163
|
+
return bRaised - aRaised;
|
|
164
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CommunityConfig } from '../types';
|
|
2
|
+
|
|
3
|
+
/** Copy light-mode fields onto theme root for pre-0.1.45 clients. */
|
|
4
|
+
export const withLegacyThemeRoot = (
|
|
5
|
+
theme: CommunityConfig['theme'],
|
|
6
|
+
): CommunityConfig['theme'] => ({
|
|
7
|
+
primaryHex: theme.light.primaryHex,
|
|
8
|
+
logoSmall: theme.light.logoSmall,
|
|
9
|
+
defaultProfileAvatar: theme.light.defaultProfileAvatar,
|
|
10
|
+
defaultGroupAvatar: theme.light.defaultGroupAvatar,
|
|
11
|
+
backgroundAuth: theme.light.backgroundAuth,
|
|
12
|
+
background: theme.light.background,
|
|
13
|
+
...theme,
|
|
14
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { mentionHandleRegexBase } from '../types';
|
|
2
|
+
|
|
3
|
+
const escapeRegExp = (value: string) =>
|
|
4
|
+
value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
5
|
+
|
|
6
|
+
export type MentionProfileRef = {
|
|
7
|
+
profile: { handle?: string | null; displayName?: string | null };
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const mentionPrefix = '(^|[\\s(>])';
|
|
11
|
+
const mentionSuffix = '(?=\\s|$|[.,!?;:])';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Turn `@handle` / known `@displayName` into markdown profile links.
|
|
15
|
+
* Display names are matched exactly (longest first) so apostrophes and other
|
|
16
|
+
* non-letter characters still count when that profile is in `mentions`.
|
|
17
|
+
* Bare `@handle` tokens use the allowed handle charset (letters, digits, `_`, `-`).
|
|
18
|
+
*/
|
|
19
|
+
export const linkProfileMentions = (
|
|
20
|
+
source: string,
|
|
21
|
+
mentions: MentionProfileRef[] = [],
|
|
22
|
+
): string => {
|
|
23
|
+
const aliases = mentions.flatMap(({ profile }) => {
|
|
24
|
+
const handle = profile.handle?.trim();
|
|
25
|
+
if (!handle) return [];
|
|
26
|
+
const names = new Set<string>([handle]);
|
|
27
|
+
const displayName = profile.displayName?.trim();
|
|
28
|
+
if (displayName) names.add(displayName);
|
|
29
|
+
return [...names].map((name) => ({ name, handle }));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
aliases.sort((a, b) => b.name.length - a.name.length);
|
|
33
|
+
|
|
34
|
+
let text = source;
|
|
35
|
+
for (const { name, handle } of aliases) {
|
|
36
|
+
const pattern = new RegExp(
|
|
37
|
+
`${mentionPrefix}@(${escapeRegExp(name)})${mentionSuffix}`,
|
|
38
|
+
'gi',
|
|
39
|
+
);
|
|
40
|
+
text = text.replace(
|
|
41
|
+
pattern,
|
|
42
|
+
(_full, prefix: string, mentioned: string) =>
|
|
43
|
+
`${prefix}[@${mentioned}](/@${handle})`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return text.replace(
|
|
48
|
+
new RegExp(mentionHandleRegexBase, 'g'),
|
|
49
|
+
(_full, prefix: string, handle: string) =>
|
|
50
|
+
`${prefix}[@${handle}](/@${handle})`,
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const matchMentionHandles = (text?: string | null): string[] => {
|
|
55
|
+
if (!text) return [];
|
|
56
|
+
const handles = new Set<string>();
|
|
57
|
+
for (const match of text.matchAll(new RegExp(mentionHandleRegexBase, 'g'))) {
|
|
58
|
+
const handle = match[2];
|
|
59
|
+
if (handle) handles.add(handle);
|
|
60
|
+
}
|
|
61
|
+
return [...handles];
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** Readable text for a shortened preview. Drops markdown marks, keeps words. */
|
|
65
|
+
export const markdownPlainText = (markdown?: string | null): string => {
|
|
66
|
+
if (!markdown) return '';
|
|
67
|
+
return markdown
|
|
68
|
+
.replace(/```[\s\S]*?```/g, ' ')
|
|
69
|
+
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
|
|
70
|
+
.replace(/[#>*_~`]+/g, '')
|
|
71
|
+
.replace(/\s+/g, ' ')
|
|
72
|
+
.trim();
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const firstNWords = (markdown: string | undefined, n: number) => {
|
|
76
|
+
if (!markdown) return '';
|
|
77
|
+
// Regular expression to match words and markdown links.
|
|
78
|
+
const regex = /\[.*?\]\(.*?\)|(\w+)/g;
|
|
79
|
+
|
|
80
|
+
let wordCount = 0;
|
|
81
|
+
const firstTwelveWords = [];
|
|
82
|
+
let match;
|
|
83
|
+
|
|
84
|
+
while ((match = regex.exec(markdown)) !== null) {
|
|
85
|
+
// Check if the match is a link or a regular word.
|
|
86
|
+
if (match[1]) {
|
|
87
|
+
// It's a regular word
|
|
88
|
+
firstTwelveWords.push(match[1]);
|
|
89
|
+
wordCount++;
|
|
90
|
+
} else {
|
|
91
|
+
// It's a markdown link - treat it as one word
|
|
92
|
+
firstTwelveWords.push(match[0]); // Add the entire link string
|
|
93
|
+
wordCount++;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (wordCount >= n) {
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return firstTwelveWords.join(' ');
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** Average adult reading speed (words per minute). */
|
|
105
|
+
const DEFAULT_WORDS_PER_MINUTE = 210;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Estimate reading time for a markdown article. Strips markdown syntax
|
|
109
|
+
* before counting words, then divides by the words-per-minute rate.
|
|
110
|
+
* Always returns at least 1 for non-empty content.
|
|
111
|
+
*/
|
|
112
|
+
export const minutesToRead = (
|
|
113
|
+
markdown: string | undefined,
|
|
114
|
+
wordsPerMinute = DEFAULT_WORDS_PER_MINUTE,
|
|
115
|
+
): number => {
|
|
116
|
+
if (!markdown) return 0;
|
|
117
|
+
const plainText = markdownPlainText(markdown);
|
|
118
|
+
const wordCount = plainText.split(/\s+/).filter(Boolean).length;
|
|
119
|
+
return wordCount === 0
|
|
120
|
+
? 0
|
|
121
|
+
: Math.max(1, Math.ceil(wordCount / wordsPerMinute));
|
|
122
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maximum width (px) we store header/banner images at.
|
|
3
|
+
*
|
|
4
|
+
* Intentionally larger than the web center column (~669px) to leave headroom
|
|
5
|
+
* for other clients and future layout changes. Header uploads are cropped to
|
|
6
|
+
* their aspect ratio and then scaled down to this width if necessary (never
|
|
7
|
+
* upscaled), which keeps banners sharp without bloating storage.
|
|
8
|
+
*/
|
|
9
|
+
export const HEADER_IMAGE_MAX_WIDTH = 800;
|
|
10
|
+
|
|
11
|
+
/** Aspect ratio used for event/article header banners. */
|
|
12
|
+
export const EVENT_HEADER_ASPECT_RATIO = '16:9';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Aspect ratio for profile/group cover banners. Uploads are cropped to this
|
|
16
|
+
* ratio; display containers use the same ratio. Banners that arrive with a
|
|
17
|
+
* different ratio (federation or older uploads) are shown with `object-cover`
|
|
18
|
+
* so they fill the 3:1 banner (center-cropped) rather than being letterboxed
|
|
19
|
+
* with grey gaps.
|
|
20
|
+
*/
|
|
21
|
+
export const PROFILE_GROUP_HEADER_ASPECT_RATIO = '3:1';
|