@openpeepshq/common 0.1.45 → 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 (62) hide show
  1. package/dist/lib/capabilitiesHelpers.d.ts +9 -7
  2. package/dist/lib/capabilitiesHelpers.js +17 -2
  3. package/dist/lib/eventIcs.d.ts +17 -0
  4. package/dist/lib/eventIcs.js +82 -0
  5. package/dist/lib/eventRecurrence.d.ts +2 -0
  6. package/dist/lib/eventRecurrence.js +9 -4
  7. package/dist/lib/eventTime.d.ts +7 -0
  8. package/dist/lib/eventTime.js +16 -0
  9. package/dist/lib/federationHosts.d.ts +3 -0
  10. package/dist/lib/federationHosts.js +17 -0
  11. package/dist/lib/feedCursor.d.ts +14 -0
  12. package/dist/lib/feedCursor.js +22 -0
  13. package/dist/lib/feedFormat.d.ts +12 -0
  14. package/dist/lib/feedFormat.js +14 -0
  15. package/dist/lib/index.d.ts +7 -0
  16. package/dist/lib/index.js +7 -0
  17. package/dist/lib/jamHelpers.d.ts +11 -2
  18. package/dist/lib/jamHelpers.js +37 -0
  19. package/dist/lib/legacyThemeRoot.d.ts +3 -0
  20. package/dist/lib/legacyThemeRoot.js +10 -0
  21. package/dist/lib/markdownHelpers.d.ts +8 -0
  22. package/dist/lib/markdownHelpers.js +32 -3
  23. package/dist/lib/postHelpers.d.ts +142 -3
  24. package/dist/lib/postHelpers.js +307 -4
  25. package/dist/lib/profileHelpers.d.ts +11 -0
  26. package/dist/lib/profileHelpers.js +31 -0
  27. package/dist/lib/reactions.d.ts +17 -0
  28. package/dist/lib/reactions.js +37 -0
  29. package/dist/lib/scopeHelpers.d.ts +31 -2
  30. package/dist/lib/scopeHelpers.js +37 -3
  31. package/dist/lib/ssoProviders.d.ts +72 -0
  32. package/dist/lib/ssoProviders.js +370 -0
  33. package/dist/lib/timeZone.d.ts +9 -0
  34. package/dist/lib/timeZone.js +44 -0
  35. package/dist/types/analytics.d.ts +20 -0
  36. package/dist/types/analytics.js +4 -0
  37. package/dist/types/api.d.ts +41799 -11853
  38. package/dist/types/api.js +52 -4
  39. package/dist/types/auth.d.ts +20 -6
  40. package/dist/types/capabilities.d.ts +15 -1
  41. package/dist/types/capabilities.js +51 -0
  42. package/dist/types/config.d.ts +96 -0
  43. package/dist/types/config.js +53 -4
  44. package/dist/types/db.d.ts +1155 -164
  45. package/dist/types/db.js +14 -0
  46. package/dist/types/export.d.ts +120 -0
  47. package/dist/types/export.js +7 -0
  48. package/dist/types/index.d.ts +2 -0
  49. package/dist/types/index.js +2 -0
  50. package/dist/types/internal.d.ts +2577 -524
  51. package/dist/types/internal.js +6 -0
  52. package/dist/types/models.d.ts +63 -7
  53. package/dist/types/models.js +39 -2
  54. package/dist/types/plugins.d.ts +22 -0
  55. package/dist/types/plugins.js +66 -0
  56. package/dist/types/roleDefaults.d.ts +31 -0
  57. package/dist/types/roleDefaults.js +110 -0
  58. package/dist/types/stats.d.ts +54606 -6065
  59. package/dist/types/stats.js +30 -0
  60. package/dist/types/utils.d.ts +2 -0
  61. package/dist/types/utils.js +1 -3
  62. package/package.json +1 -1
@@ -7,6 +7,8 @@ export declare const checkCapabilities: (neededCapabilities: string[], presentCa
7
7
  missingCapabilities: string[];
8
8
  };
9
9
  export declare const mergeCapabilities: (capabilities?: Partial<Capabilities>[]) => Capabilities;
10
+ /** Order-independent equality check for two capability add/remove lists. */
11
+ export declare const capabilitySetsEqual: (a: string[] | undefined, b: string[] | undefined) => boolean;
10
12
  export declare const checkRoleCapabilities: (roles: Role[] | undefined, neededCapabilities: string[]) => {
11
13
  success: boolean;
12
14
  missingCapabilities: string[];
@@ -37,7 +39,7 @@ export declare const checkGroupCapabilities: (authData: AuthorizationData, neede
37
39
  missingCapabilities: string[];
38
40
  missingScope: {
39
41
  resource: {
40
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
42
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
41
43
  id?: string | undefined;
42
44
  };
43
45
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -48,7 +50,7 @@ export declare const checkPostCapabilities: (authData: AuthorizationData, needed
48
50
  missingCapabilities: string[];
49
51
  missingScope: {
50
52
  resource: {
51
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
53
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
52
54
  id?: string | undefined;
53
55
  };
54
56
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -59,7 +61,7 @@ export declare const checkProfileCapabilities: (authData: AuthorizationData, nee
59
61
  missingCapabilities: string[];
60
62
  missingScope: {
61
63
  resource: {
62
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
64
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
63
65
  id?: string | undefined;
64
66
  };
65
67
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -70,7 +72,7 @@ export declare const checkReportCapabilities: (authData: AuthorizationData, need
70
72
  missingCapabilities: string[];
71
73
  missingScope: {
72
74
  resource: {
73
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
75
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
74
76
  id?: string | undefined;
75
77
  };
76
78
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -81,7 +83,7 @@ export declare const checkAccessTokenCapabilities: (authData: AuthorizationData,
81
83
  missingCapabilities: string[];
82
84
  missingScope: {
83
85
  resource: {
84
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
86
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
85
87
  id?: string | undefined;
86
88
  };
87
89
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -92,7 +94,7 @@ export declare const checkAccountCapabilities: (authData: AuthorizationData, nee
92
94
  missingCapabilities: string[];
93
95
  missingScope: {
94
96
  resource: {
95
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
97
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
96
98
  id?: string | undefined;
97
99
  };
98
100
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -110,7 +112,7 @@ export declare const checkAccountCreateAuthorization: (authData: AuthorizationDa
110
112
  missingCapabilities: string[];
111
113
  missingScope: {
112
114
  resource: {
113
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
115
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
114
116
  id?: string | undefined;
115
117
  };
116
118
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -1,4 +1,5 @@
1
- import { calculateRequiredScope, scopeMatches, withPublicPostReadScopes, withPublicGroupReadScopes, } from './scopeHelpers.js';
1
+ import { calculateRequiredScope, scopeMatches, withPublicPostReadScopes, withPublicGroupReadScopes, withPublicProfileReadScopes, } from './scopeHelpers.js';
2
+ import { viewerBlockedTarget, targetBlockedViewer } from './profileHelpers.js';
2
3
  export const checkCapabilities = (neededCapabilities, presentCapabilities = {
3
4
  add: [],
4
5
  remove: [],
@@ -23,6 +24,14 @@ export const mergeCapabilities = (capabilities) => {
23
24
  ],
24
25
  };
25
26
  };
27
+ /** Order-independent equality check for two capability add/remove lists. */
28
+ export const capabilitySetsEqual = (a, b) => {
29
+ const sa = new Set(a !== null && a !== void 0 ? a : []);
30
+ const sb = new Set(b !== null && b !== void 0 ? b : []);
31
+ if (sa.size !== sb.size)
32
+ return false;
33
+ return [...sa].every((value) => sb.has(value));
34
+ };
26
35
  export const checkRoleCapabilities = (roles = [], neededCapabilities) => checkCapabilities(neededCapabilities, mergeCapabilities(roles.map((r) => r.capabilities)));
27
36
  /** Any of these matching `roles` shows the Administration row (submenu is separate UX). */
28
37
  export const ADMIN_SIDEBAR_MENU_CAPABILITIES = [
@@ -72,6 +81,12 @@ export const getProfileRelationships = (authData, otherProfile) => {
72
81
  if (profile === null || profile === void 0 ? void 0 : profile.following.map((f) => f.id).includes(otherProfile === null || otherProfile === void 0 ? void 0 : otherProfile.id)) {
73
82
  relationships.push('following');
74
83
  }
84
+ if (viewerBlockedTarget(profile, otherProfile === null || otherProfile === void 0 ? void 0 : otherProfile.id)) {
85
+ relationships.push('blocked');
86
+ }
87
+ if (targetBlockedViewer(profile, otherProfile === null || otherProfile === void 0 ? void 0 : otherProfile.id)) {
88
+ relationships.push('blocked-by');
89
+ }
75
90
  return relationships;
76
91
  };
77
92
  export const getPostRelationships = (authData, post) => {
@@ -211,7 +226,7 @@ export const checkPostCapabilities = (authData, neededCapabilities, post, config
211
226
  ]);
212
227
  return checkCapabilitiesWithCalculatedScope(capabilities, withPublicPostReadScopes(authData, post, neededCapabilities), neededCapabilities, { type: 'posts', id: post.id });
213
228
  };
214
- export const checkProfileCapabilities = (authData, neededCapabilities, targetProfile, config) => checkCapabilitiesWithCalculatedScope(getProfileCapabilities(authData, targetProfile, config), authData, neededCapabilities, { type: 'profiles', id: targetProfile.id });
229
+ export const checkProfileCapabilities = (authData, neededCapabilities, targetProfile, config) => checkCapabilitiesWithCalculatedScope(getProfileCapabilities(authData, targetProfile, config), withPublicProfileReadScopes(authData, targetProfile, neededCapabilities, config), neededCapabilities, { type: 'profiles', id: targetProfile.id });
215
230
  export const checkReportCapabilities = (authData, neededCapabilities, report, config) => checkCapabilitiesWithCalculatedScope(getReportCapabilities(authData, report, config), authData, neededCapabilities, { type: 'reports', id: report.id });
216
231
  export const checkAccessTokenCapabilities = (authData, neededCapabilities, accessToken, config) => checkCapabilitiesWithExplicitScope(getAccessTokenCapabilities(authData, accessToken, config), authData, neededCapabilities, { scopeLevel: 'admin', resource: { type: 'self' } });
217
232
  export const checkAccountCapabilities = (authData, neededCapabilities, targetAccount) => checkCapabilitiesWithExplicitScope(getAccountCapabilities(authData, targetAccount), authData, neededCapabilities, { scopeLevel: 'admin', resource: { type: 'self' } });
@@ -2,3 +2,20 @@ import type { PublicPost } from '../types';
2
2
  export declare const buildEventIcs: (post: PublicPost, options?: {
3
3
  postUrl?: string;
4
4
  }) => string | null;
5
+ /** Attendance ICS: discrete booked dates, or the series definition when none. */
6
+ export declare const buildRsvpIcs: (post: PublicPost, options?: {
7
+ postUrl?: string;
8
+ occurrenceIds?: string[];
9
+ }) => string | null;
10
+ export declare const rsvpConfirmationContent: (post: PublicPost, options: {
11
+ postUrl: string;
12
+ occurrenceIds?: string[];
13
+ }) => {
14
+ ics: string;
15
+ eventName: string;
16
+ start: string;
17
+ end: string | null;
18
+ location: string | null;
19
+ allDay: boolean;
20
+ occurrenceCount: number;
21
+ } | null;
@@ -1,4 +1,5 @@
1
1
  import ical, { ICalCalendarMethod, ICalEventRepeatingFreq, ICalWeekday, } from 'ical-generator';
2
+ import { effectiveEventTimes } from './eventRecurrence.js';
2
3
  import { getJamUrl } from './jamHelpers.js';
3
4
  const utcDateFromYmd = (yyyyMmDd) => {
4
5
  const [y, m, d] = yyyyMmDd.split('-').map(Number);
@@ -135,3 +136,84 @@ export const buildEventIcs = (post, options) => {
135
136
  }
136
137
  return calendar.toString() + '\r\n';
137
138
  };
139
+ const addOccurrenceEvent = (calendar, post, event, recurrenceId, options) => {
140
+ var _a, _b, _c, _d, _e;
141
+ const link = (_a = event.url) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.postUrl;
142
+ const summary = ((_b = event.name) === null || _b === void 0 ? void 0 : _b.trim()) || 'Event';
143
+ const description = (_c = event.content) === null || _c === void 0 ? void 0 : _c.trim();
144
+ const location = eventLocation(post, event, options === null || options === void 0 ? void 0 : options.postUrl);
145
+ const times = effectiveEventTimes(event, recurrenceId);
146
+ const id = `openpeeps-event-${post.id}-${recurrenceId}@openpeepshq`;
147
+ if (event.wholeDay) {
148
+ const startYmd = times.start.slice(0, 10);
149
+ const lastInclusiveYmd = (_e = (_d = times.end) === null || _d === void 0 ? void 0 : _d.slice(0, 10)) !== null && _e !== void 0 ? _e : startYmd;
150
+ calendar.createEvent({
151
+ id,
152
+ allDay: true,
153
+ start: utcDateFromYmd(startYmd),
154
+ end: exclusiveEndAfterInclusiveDay(lastInclusiveYmd),
155
+ summary,
156
+ ...(description ? { description } : {}),
157
+ ...(location ? { location } : {}),
158
+ ...(link ? { url: link } : {}),
159
+ });
160
+ return;
161
+ }
162
+ const start = new Date(times.start);
163
+ const end = times.end
164
+ ? new Date(times.end)
165
+ : new Date(start.getTime() + 60 * 60 * 1000);
166
+ calendar.createEvent({
167
+ id,
168
+ start,
169
+ end,
170
+ summary,
171
+ ...(description ? { description } : {}),
172
+ ...(location ? { location } : {}),
173
+ ...(link ? { url: link } : {}),
174
+ });
175
+ };
176
+ /** Attendance ICS: discrete booked dates, or the series definition when none. */
177
+ export const buildRsvpIcs = (post, options) => {
178
+ var _a, _b, _c;
179
+ const occurrenceIds = (_b = (_a = options === null || options === void 0 ? void 0 : options.occurrenceIds) === null || _a === void 0 ? void 0 : _a.filter(Boolean)) !== null && _b !== void 0 ? _b : [];
180
+ if (!occurrenceIds.length) {
181
+ return buildEventIcs(post, { postUrl: options === null || options === void 0 ? void 0 : options.postUrl });
182
+ }
183
+ if (post.type !== 'event' || ((_c = post.data) === null || _c === void 0 ? void 0 : _c.type) !== 'event') {
184
+ return null;
185
+ }
186
+ const event = post.data;
187
+ const calendar = ical({
188
+ prodId: '//OpenPeeps//Event//EN',
189
+ method: ICalCalendarMethod.PUBLISH,
190
+ scale: 'GREGORIAN',
191
+ });
192
+ for (const recurrenceId of occurrenceIds) {
193
+ addOccurrenceEvent(calendar, post, event, recurrenceId, options);
194
+ }
195
+ return calendar.toString() + '\r\n';
196
+ };
197
+ export const rsvpConfirmationContent = (post, options) => {
198
+ var _a, _b, _c, _d, _e, _f, _g, _h;
199
+ if (post.type !== 'event' || ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) !== 'event') {
200
+ return null;
201
+ }
202
+ const ics = buildRsvpIcs(post, options);
203
+ if (!ics)
204
+ return null;
205
+ const event = post.data;
206
+ const occurrenceIds = (_c = (_b = options.occurrenceIds) === null || _b === void 0 ? void 0 : _b.filter(Boolean)) !== null && _c !== void 0 ? _c : [];
207
+ const times = occurrenceIds.length > 0
208
+ ? effectiveEventTimes(event, occurrenceIds[0])
209
+ : { start: event.start, end: event.end };
210
+ return {
211
+ ics,
212
+ eventName: ((_d = event.name) === null || _d === void 0 ? void 0 : _d.trim()) || 'Event',
213
+ start: times.start,
214
+ end: (_e = times.end) !== null && _e !== void 0 ? _e : null,
215
+ location: (_g = (_f = event.physicalLocation) === null || _f === void 0 ? void 0 : _f.text) !== null && _g !== void 0 ? _g : null,
216
+ allDay: (_h = event.wholeDay) !== null && _h !== void 0 ? _h : false,
217
+ occurrenceCount: occurrenceIds.length,
218
+ };
219
+ };
@@ -21,6 +21,8 @@ export declare const expandEventOccurrences: (event: Event, window: {
21
21
  to: Date;
22
22
  }) => ExpandedOccurrence[];
23
23
  export declare const occurrencesForIndex: (event: Event, now?: Date) => ExpandedOccurrence[];
24
+ export declare const listRsvpOccurrences: (event: Event, now?: Date) => ExpandedOccurrence[];
25
+ export declare const defaultRsvpRecurrenceId: (event: Event, queryId?: string, now?: Date) => string | undefined;
24
26
  export declare const previewUpcomingOccurrences: (event: Event, count?: number, now?: Date) => ExpandedOccurrence[];
25
27
  export declare const effectiveEventTimes: (event: Event, recurrenceId?: string) => {
26
28
  start: string;
@@ -177,12 +177,17 @@ export const occurrencesForIndex = (event, now = new Date()) => {
177
177
  to: new Date(now.getTime() + OCCURRENCE_HORIZON_MS),
178
178
  });
179
179
  };
180
- export const previewUpcomingOccurrences = (event, count = 3, now = new Date()) => expandEventOccurrences(event, {
180
+ export const listRsvpOccurrences = (event, now = new Date()) => expandEventOccurrences(event, {
181
181
  from: now,
182
182
  to: new Date(now.getTime() + OCCURRENCE_HORIZON_MS),
183
- })
184
- .filter((occurrence) => !occurrence.cancelled)
185
- .slice(0, count);
183
+ }).filter((occurrence) => !occurrence.cancelled);
184
+ export const defaultRsvpRecurrenceId = (event, queryId, now = new Date()) => {
185
+ var _a;
186
+ if (queryId)
187
+ return normalizeRecurrenceId(queryId);
188
+ return (_a = listRsvpOccurrences(event, now)[0]) === null || _a === void 0 ? void 0 : _a.recurrenceId;
189
+ };
190
+ export const previewUpcomingOccurrences = (event, count = 3, now = new Date()) => listRsvpOccurrences(event, now).slice(0, count);
186
191
  export const effectiveEventTimes = (event, recurrenceId) => {
187
192
  if (!recurrenceId) {
188
193
  return { start: event.start, end: event.end };
@@ -14,6 +14,13 @@ export declare const reinterpretIsoInTimeZone: (iso: string | undefined, fromTim
14
14
  export declare const utcIsoToWallClockDate: (iso: string, timeZone: string) => Date;
15
15
  /** Treat `date`'s local components as wall time in `timeZone`. */
16
16
  export declare const wallClockDateToUtcIso: (date: Date, timeZone: string) => string;
17
+ /** Intl `timeZone` option when `timeZone` is a valid IANA identifier. */
18
+ export declare const eventTimeZoneOptions: (timeZone?: string | null) => Pick<Intl.DateTimeFormatOptions, "timeZone">;
19
+ /** Clock time in the event timezone, always including a short zone name. */
20
+ export declare const formatEventClockTime: (iso: string, options?: {
21
+ timeZone?: string | null;
22
+ locale?: string;
23
+ }) => string;
17
24
  export declare const formatEventWhen: (start: string, options?: {
18
25
  end?: string | null;
19
26
  timeZone?: string | null;
@@ -1,3 +1,4 @@
1
+ import { isIanaTimeZone } from './timeZone.js';
1
2
  const DATETIME_LOCAL_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?$/;
2
3
  const partNumber = (parts, type) => { var _a; return Number((_a = parts.find((part) => part.type === type)) === null || _a === void 0 ? void 0 : _a.value); };
3
4
  /** Milliseconds to add to UTC to get wall time in `timeZone` at `utcMs`. */
@@ -97,6 +98,21 @@ export const wallClockDateToUtcIso = (date, timeZone) => {
97
98
  const local = `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}T${pad2(date.getHours())}:${pad2(date.getMinutes())}`;
98
99
  return (_a = zonedDateTimeToUtcIso(local, timeZone)) !== null && _a !== void 0 ? _a : date.toISOString();
99
100
  };
101
+ /** Intl `timeZone` option when `timeZone` is a valid IANA identifier. */
102
+ export const eventTimeZoneOptions = (timeZone) => {
103
+ const resolved = isIanaTimeZone(timeZone) ? timeZone : undefined;
104
+ return resolved ? { timeZone: resolved } : {};
105
+ };
106
+ /** Clock time in the event timezone, always including a short zone name. */
107
+ export const formatEventClockTime = (iso, options) => {
108
+ const timeZone = eventTimeZoneOptions(options === null || options === void 0 ? void 0 : options.timeZone).timeZone;
109
+ return new Date(iso).toLocaleTimeString(options === null || options === void 0 ? void 0 : options.locale, {
110
+ hour: '2-digit',
111
+ minute: '2-digit',
112
+ timeZoneName: 'short',
113
+ ...(timeZone ? { timeZone } : {}),
114
+ });
115
+ };
100
116
  export const formatEventWhen = (start, options) => {
101
117
  const timeZone = (options === null || options === void 0 ? void 0 : options.timeZone) || undefined;
102
118
  const dateOptions = {
@@ -0,0 +1,3 @@
1
+ /** Leftmost-label wildcard only: `*.example.com` matches `a.example.com`. */
2
+ export declare const hostMatchesAllowedPattern: (host: string, pattern: string) => boolean;
3
+ export declare const hostIsAllowed: (host: string, allowedHosts: readonly string[]) => boolean;
@@ -0,0 +1,17 @@
1
+ /** Leftmost-label wildcard only: `*.example.com` matches `a.example.com`. */
2
+ export const hostMatchesAllowedPattern = (host, pattern) => {
3
+ const normalizedHost = host.trim().toLowerCase().replace(/\.$/, '');
4
+ const normalizedPattern = pattern.trim().toLowerCase().replace(/\.$/, '');
5
+ if (!normalizedHost || !normalizedPattern)
6
+ return false;
7
+ if (normalizedPattern === '*')
8
+ return false;
9
+ if (normalizedPattern.startsWith('*.')) {
10
+ const suffix = normalizedPattern.slice(2);
11
+ if (!suffix.includes('.'))
12
+ return false;
13
+ return normalizedHost === suffix || normalizedHost.endsWith(`.${suffix}`);
14
+ }
15
+ return normalizedHost === normalizedPattern;
16
+ };
17
+ export const hostIsAllowed = (host, allowedHosts) => allowedHosts.some((pattern) => hostMatchesAllowedPattern(host, pattern));
@@ -0,0 +1,14 @@
1
+ export type FeedCursor = {
2
+ id: string;
3
+ lastActivityAt?: string;
4
+ };
5
+ /**
6
+ * Timeline feeds page by `(lastActivityAt DESC, id DESC)`. Encode both in
7
+ * `start` so a later bump cannot skip or duplicate rows across pages.
8
+ * Id-sorted feeds (profile, bookmarks, hashtags) still work: they read `id`.
9
+ */
10
+ export declare const encodeFeedCursor: (post: {
11
+ id?: string;
12
+ lastActivityAt?: string | null;
13
+ }) => string | undefined;
14
+ export declare const parseFeedCursor: (start?: string) => FeedCursor | undefined;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Timeline feeds page by `(lastActivityAt DESC, id DESC)`. Encode both in
3
+ * `start` so a later bump cannot skip or duplicate rows across pages.
4
+ * Id-sorted feeds (profile, bookmarks, hashtags) still work: they read `id`.
5
+ */
6
+ export const encodeFeedCursor = (post) => {
7
+ if (!post.id)
8
+ return undefined;
9
+ return post.lastActivityAt ? `${post.lastActivityAt}|${post.id}` : post.id;
10
+ };
11
+ export const parseFeedCursor = (start) => {
12
+ if (!start)
13
+ return undefined;
14
+ const sep = start.lastIndexOf('|');
15
+ if (sep <= 0)
16
+ return { id: start };
17
+ const lastActivityAt = start.slice(0, sep);
18
+ const id = start.slice(sep + 1);
19
+ if (!id)
20
+ return { id: start };
21
+ return { id, lastActivityAt };
22
+ };
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ export declare const FEED_FORMAT_OPTIONS: readonly ["threaded", "linear"];
3
+ export declare const feedFormatSchema: z.ZodEnum<{
4
+ threaded: "threaded";
5
+ linear: "linear";
6
+ }>;
7
+ export type FeedFormat = z.infer<typeof feedFormatSchema>;
8
+ export declare const DEFAULT_FEED_FORMAT: FeedFormat;
9
+ export declare const isFeedFormat: (value: string | null | undefined) => value is FeedFormat;
10
+ export declare const parseFeedFormat: (value?: string | null) => FeedFormat;
11
+ /** Profile default, then community default, then threaded. */
12
+ export declare const resolveFeedFormat: (profileFormat?: string | null, communityFormat?: string | null) => FeedFormat;
@@ -0,0 +1,14 @@
1
+ import { z } from 'zod';
2
+ export const FEED_FORMAT_OPTIONS = ['threaded', 'linear'];
3
+ export const feedFormatSchema = z.enum(FEED_FORMAT_OPTIONS);
4
+ export const DEFAULT_FEED_FORMAT = 'threaded';
5
+ export const isFeedFormat = (value) => value === 'threaded' || value === 'linear';
6
+ export const parseFeedFormat = (value) => isFeedFormat(value) ? value : DEFAULT_FEED_FORMAT;
7
+ /** Profile default, then community default, then threaded. */
8
+ export const resolveFeedFormat = (profileFormat, communityFormat) => {
9
+ if (isFeedFormat(profileFormat))
10
+ return profileFormat;
11
+ if (isFeedFormat(communityFormat))
12
+ return communityFormat;
13
+ return DEFAULT_FEED_FORMAT;
14
+ };
@@ -1,7 +1,10 @@
1
1
  export * from './utils';
2
+ export * from './legacyThemeRoot';
2
3
  export * from './profileHelpers';
3
4
  export * from './text';
4
5
  export * from './postHelpers';
6
+ export * from './feedCursor';
7
+ export * from './feedFormat';
5
8
  export * from './capabilitiesHelpers';
6
9
  export * from './adminSections';
7
10
  export * from './groupHelpers';
@@ -11,6 +14,7 @@ export * from './markdownHelpers';
11
14
  export * from './attachmentHelpers';
12
15
  export * from './eventIcs';
13
16
  export * from './eventTime';
17
+ export * from './timeZone';
14
18
  export * from './eventRecurrence';
15
19
  export * from './tokenHelpers';
16
20
  export * from './jamHelpers';
@@ -20,3 +24,6 @@ export * from './mediaDimensions';
20
24
  export * from './csvHelpers';
21
25
  export * from './reportHelpers';
22
26
  export * from './ssoLoginUrl';
27
+ export * from './ssoProviders';
28
+ export * from './federationHosts';
29
+ export * from './reactions';
package/dist/lib/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  export * from './utils.js';
2
+ export * from './legacyThemeRoot.js';
2
3
  export * from './profileHelpers.js';
3
4
  export * from './text.js';
4
5
  export * from './postHelpers.js';
6
+ export * from './feedCursor.js';
7
+ export * from './feedFormat.js';
5
8
  export * from './capabilitiesHelpers.js';
6
9
  export * from './adminSections.js';
7
10
  export * from './groupHelpers.js';
@@ -11,6 +14,7 @@ export * from './markdownHelpers.js';
11
14
  export * from './attachmentHelpers.js';
12
15
  export * from './eventIcs.js';
13
16
  export * from './eventTime.js';
17
+ export * from './timeZone.js';
14
18
  export * from './eventRecurrence.js';
15
19
  export * from './tokenHelpers.js';
16
20
  export * from './jamHelpers.js';
@@ -20,3 +24,6 @@ export * from './mediaDimensions.js';
20
24
  export * from './csvHelpers.js';
21
25
  export * from './reportHelpers.js';
22
26
  export * from './ssoLoginUrl.js';
27
+ export * from './ssoProviders.js';
28
+ export * from './federationHosts.js';
29
+ export * from './reactions.js';
@@ -8,7 +8,10 @@ export declare const uniquePostsById: <T extends {
8
8
  export declare const getJamUrl: (id: string, origin: string | undefined, occurrence?: string) => string;
9
9
  export declare const jamFromEvent: (event: PublicPost) => Jam | undefined;
10
10
  export declare const canModerateJam: (profile: Pick<PublicProfile, "id"> | undefined, post: PublicPost) => boolean;
11
- export declare const canAccessJamRecordings: (profile: PublicProfile | undefined, post: PublicPost) => boolean;
11
+ /** Host or jam moderator — same gate as the event Attendees tab. */
12
+ export declare const canViewJamAttendees: (profile: Pick<PublicProfile, "id"> | undefined, post: PublicPost) => boolean;
13
+ export declare const canAccessJamRecordings: (profile: Pick<PublicProfile, "id"> | undefined, post: PublicPost) => boolean;
14
+ export declare const jamRecordingAcceptsUpload: (status: string | undefined) => status is "requested" | "active" | "finalizing";
12
15
  export declare const isRtmpJamRecording: (recording: {
13
16
  kind?: string | null;
14
17
  }) => boolean;
@@ -25,7 +28,13 @@ export declare const assembleRtmpUrl: (url: string, streamKey: string) => string
25
28
  export declare const rtmpDestinationHost: (rtmpUrl: string) => string | undefined;
26
29
  export declare const toRtmpStreamResponse: (recording: JamRecording) => {
27
30
  id: string;
28
- status: "active" | "failed" | "requested" | "completed";
31
+ status: "active" | "failed" | "requested" | "finalizing" | "completed";
29
32
  destinationHost: string | undefined;
30
33
  egressId: string | undefined;
31
34
  };
35
+ /**
36
+ * Raised hands first, most recent raise first, so the person who just raised
37
+ * moves to the top of the people list and the top-left of the video grid.
38
+ * Everyone else keeps their relative order.
39
+ */
40
+ export declare const sortByRaisedHand: <T>(items: readonly T[], metadataOf: (item: T) => string | undefined) => T[];
@@ -37,6 +37,9 @@ export const jamFromEvent = (event) => {
37
37
  return undefined;
38
38
  };
39
39
  export const canModerateJam = (profile, post) => { var _a, _b; return !!(profile && ((_b = (_a = jamFromEvent(post)) === null || _a === void 0 ? void 0 : _a.moderators) === null || _b === void 0 ? void 0 : _b.includes(profile.id))); };
40
+ /** Host or jam moderator — same gate as the event Attendees tab. */
41
+ export const canViewJamAttendees = (profile, post) => !!(profile &&
42
+ (post.profile.id === profile.id || canModerateJam(profile, post)));
40
43
  export const canAccessJamRecordings = (profile, post) => {
41
44
  var _a, _b, _c, _d;
42
45
  if (!profile) {
@@ -54,6 +57,7 @@ export const canAccessJamRecordings = (profile, post) => {
54
57
  }
55
58
  return !!((_d = (_c = event.jam) === null || _c === void 0 ? void 0 : _c.moderators) === null || _d === void 0 ? void 0 : _d.includes(profile.id));
56
59
  };
60
+ export const jamRecordingAcceptsUpload = (status) => status === 'requested' || status === 'active' || status === 'finalizing';
57
61
  export const isRtmpJamRecording = (recording) => recording.kind === 'rtmp';
58
62
  export const isFileJamRecording = (recording) => !isRtmpJamRecording(recording);
59
63
  export const pickActiveFileRecording = (recordings) => recordings.find(isFileJamRecording);
@@ -83,3 +87,36 @@ export const toRtmpStreamResponse = (recording) => ({
83
87
  destinationHost: recording.destinationHost,
84
88
  egressId: recording.egressId,
85
89
  });
90
+ /** Epoch ms from participant metadata when their hand is up. */
91
+ const raisedHandTimestamp = (metadata) => {
92
+ if (!metadata)
93
+ return undefined;
94
+ try {
95
+ const handRaised = JSON.parse(metadata)
96
+ .handRaised;
97
+ if (typeof handRaised !== 'string' || handRaised.length === 0) {
98
+ return undefined;
99
+ }
100
+ const timestamp = Date.parse(handRaised);
101
+ return Number.isNaN(timestamp) ? undefined : timestamp;
102
+ }
103
+ catch {
104
+ return undefined;
105
+ }
106
+ };
107
+ /**
108
+ * Raised hands first, most recent raise first, so the person who just raised
109
+ * moves to the top of the people list and the top-left of the video grid.
110
+ * Everyone else keeps their relative order.
111
+ */
112
+ export const sortByRaisedHand = (items, metadataOf) => [...items].sort((a, b) => {
113
+ const aRaised = raisedHandTimestamp(metadataOf(a));
114
+ const bRaised = raisedHandTimestamp(metadataOf(b));
115
+ if (aRaised === undefined && bRaised === undefined)
116
+ return 0;
117
+ if (aRaised === undefined)
118
+ return 1;
119
+ if (bRaised === undefined)
120
+ return -1;
121
+ return bRaised - aRaised;
122
+ });
@@ -0,0 +1,3 @@
1
+ import type { CommunityConfig } from '../types';
2
+ /** Copy light-mode fields onto theme root for pre-0.1.45 clients. */
3
+ export declare const withLegacyThemeRoot: (theme: CommunityConfig["theme"]) => CommunityConfig["theme"];
@@ -0,0 +1,10 @@
1
+ /** Copy light-mode fields onto theme root for pre-0.1.45 clients. */
2
+ export const withLegacyThemeRoot = (theme) => ({
3
+ primaryHex: theme.light.primaryHex,
4
+ logoSmall: theme.light.logoSmall,
5
+ defaultProfileAvatar: theme.light.defaultProfileAvatar,
6
+ defaultGroupAvatar: theme.light.defaultGroupAvatar,
7
+ backgroundAuth: theme.light.backgroundAuth,
8
+ background: theme.light.background,
9
+ ...theme,
10
+ });
@@ -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;
@@ -39,6 +39,17 @@ export const matchMentionHandles = (text) => {
39
39
  }
40
40
  return [...handles];
41
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
+ };
42
53
  export const firstNWords = (markdown, n) => {
43
54
  if (!markdown)
44
55
  return '';
@@ -49,11 +60,13 @@ export const firstNWords = (markdown, n) => {
49
60
  let match;
50
61
  while ((match = regex.exec(markdown)) !== null) {
51
62
  // Check if the match is a link or a regular word.
52
- if (match[1]) { // It's a regular word
63
+ if (match[1]) {
64
+ // It's a regular word
53
65
  firstTwelveWords.push(match[1]);
54
66
  wordCount++;
55
67
  }
56
- else { // It's a markdown link - treat it as one word
68
+ else {
69
+ // It's a markdown link - treat it as one word
57
70
  firstTwelveWords.push(match[0]); // Add the entire link string
58
71
  wordCount++;
59
72
  }
@@ -61,5 +74,21 @@ export const firstNWords = (markdown, n) => {
61
74
  break;
62
75
  }
63
76
  }
64
- 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));
65
94
  };