@openpeepshq/common 0.17.0 → 0.19.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/eventIcs.js +26 -6
- package/dist/lib/eventTime.d.ts +12 -3
- package/dist/lib/eventTime.js +12 -3
- package/dist/lib/federationHosts.d.ts +10 -1
- package/dist/lib/federationHosts.js +13 -2
- package/dist/types/api.d.ts +3 -0
- package/dist/types/api.js +2 -0
- package/dist/types/capabilities.d.ts +2 -2
- package/dist/types/capabilities.js +2 -0
- package/dist/types/config.d.ts +3 -0
- package/dist/types/config.js +2 -0
- package/dist/types/notifications.d.ts +1 -0
- package/dist/types/roleDefaults.js +13 -0
- package/package.json +2 -2
- package/src/lib/eventIcs.ts +44 -7
- package/src/lib/eventTime.ts +12 -3
- package/src/lib/federationHosts.ts +28 -2
- package/src/types/api.ts +2 -0
- package/src/types/capabilities.ts +2 -0
- package/src/types/config.ts +2 -0
- package/src/types/roleDefaults.ts +20 -0
package/dist/lib/eventIcs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ical, { ICalCalendarMethod, ICalEventRepeatingFreq, ICalWeekday, } from 'ical-generator';
|
|
2
2
|
import { TZDate } from '@date-fns/tz';
|
|
3
3
|
import { tzlib_get_ical_block } from 'timezones-ical-library';
|
|
4
|
-
import { effectiveEventTimes } from './eventRecurrence.js';
|
|
4
|
+
import { effectiveEventTimes, sameRecurrenceId } from './eventRecurrence.js';
|
|
5
5
|
import { getJamUrl } from './jamHelpers.js';
|
|
6
6
|
import { isIanaTimeZone } from './timeZone.js';
|
|
7
7
|
/**
|
|
@@ -99,6 +99,16 @@ const eventLocation = (post, event, postUrl) => {
|
|
|
99
99
|
}
|
|
100
100
|
return event.url?.trim() || undefined;
|
|
101
101
|
};
|
|
102
|
+
/**
|
|
103
|
+
* The override's own location when one was set for that occurrence;
|
|
104
|
+
* otherwise the series-level location the rest of the builder resolves.
|
|
105
|
+
*/
|
|
106
|
+
const occurrenceLocation = (exception, fallback) => {
|
|
107
|
+
// Only a non-empty (trimmed) exception location overrides the series
|
|
108
|
+
// location; whitespace-only text falls through, matching eventLocation.
|
|
109
|
+
const text = exception?.physicalLocation?.text?.trim();
|
|
110
|
+
return text ? text : fallback;
|
|
111
|
+
};
|
|
102
112
|
const repeatingFreq = {
|
|
103
113
|
DAILY: ICalEventRepeatingFreq.DAILY,
|
|
104
114
|
WEEKLY: ICalEventRepeatingFreq.WEEKLY,
|
|
@@ -194,6 +204,7 @@ export const buildEventIcs = (post, options) => {
|
|
|
194
204
|
for (const exception of event.exceptions ?? []) {
|
|
195
205
|
if (exception.cancelled || !exception.start)
|
|
196
206
|
continue;
|
|
207
|
+
const overrideLocation = occurrenceLocation(exception, location);
|
|
197
208
|
if (event.wholeDay) {
|
|
198
209
|
// Rescheduled all-day occurrence: an all-day override whose day range
|
|
199
210
|
// is the exception's new start day through its end day (inclusive).
|
|
@@ -209,7 +220,7 @@ export const buildEventIcs = (post, options) => {
|
|
|
209
220
|
end: exclusiveEndAfterInclusiveDay(excLastInclusiveYmd),
|
|
210
221
|
summary,
|
|
211
222
|
...(description ? { description } : {}),
|
|
212
|
-
...(
|
|
223
|
+
...(overrideLocation ? { location: overrideLocation } : {}),
|
|
213
224
|
...(link ? { url: link } : {}),
|
|
214
225
|
...stamp,
|
|
215
226
|
recurrenceId: utcDateFromYmd(exception.recurrenceId.slice(0, 10)),
|
|
@@ -227,7 +238,7 @@ export const buildEventIcs = (post, options) => {
|
|
|
227
238
|
...(timeZone ? { timezone: timeZone } : {}),
|
|
228
239
|
summary,
|
|
229
240
|
...(description ? { description } : {}),
|
|
230
|
-
...(
|
|
241
|
+
...(overrideLocation ? { location: overrideLocation } : {}),
|
|
231
242
|
...(link ? { url: link } : {}),
|
|
232
243
|
...stamp,
|
|
233
244
|
recurrenceId: instantInZone(exception.recurrenceId, timeZone),
|
|
@@ -245,6 +256,10 @@ const addOccurrenceEvent = (calendar, post, event, recurrenceId, options) => {
|
|
|
245
256
|
const summary = event.name?.trim() || 'Event';
|
|
246
257
|
const description = event.content?.trim();
|
|
247
258
|
const location = eventLocation(post, event, options?.postUrl);
|
|
259
|
+
// A booked occurrence may be a rescheduled one; its RECURRENCE-ID is the
|
|
260
|
+
// original slot, the key the exception is stored under.
|
|
261
|
+
const exception = event.exceptions?.find((e) => sameRecurrenceId(e.recurrenceId, recurrenceId));
|
|
262
|
+
const occLocation = occurrenceLocation(exception, location);
|
|
248
263
|
const times = effectiveEventTimes(event, recurrenceId);
|
|
249
264
|
const id = `openpeeps-event-${post.id}-${recurrenceId}@openpeepshq`;
|
|
250
265
|
const timeZone = event.wholeDay ? undefined : eventTimeZone(event);
|
|
@@ -258,7 +273,7 @@ const addOccurrenceEvent = (calendar, post, event, recurrenceId, options) => {
|
|
|
258
273
|
end: exclusiveEndAfterInclusiveDay(lastInclusiveYmd),
|
|
259
274
|
summary,
|
|
260
275
|
...(description ? { description } : {}),
|
|
261
|
-
...(
|
|
276
|
+
...(occLocation ? { location: occLocation } : {}),
|
|
262
277
|
...(link ? { url: link } : {}),
|
|
263
278
|
});
|
|
264
279
|
return;
|
|
@@ -274,7 +289,7 @@ const addOccurrenceEvent = (calendar, post, event, recurrenceId, options) => {
|
|
|
274
289
|
...(timeZone ? { timezone: timeZone } : {}),
|
|
275
290
|
summary,
|
|
276
291
|
...(description ? { description } : {}),
|
|
277
|
-
...(
|
|
292
|
+
...(occLocation ? { location: occLocation } : {}),
|
|
278
293
|
...(link ? { url: link } : {}),
|
|
279
294
|
});
|
|
280
295
|
};
|
|
@@ -312,12 +327,17 @@ export const rsvpConfirmationContent = (post, options) => {
|
|
|
312
327
|
const times = occurrenceIds.length > 0
|
|
313
328
|
? effectiveEventTimes(event, occurrenceIds[0])
|
|
314
329
|
: { start: event.start, end: event.end };
|
|
330
|
+
// The first booked occurrence may be a rescheduled one with its own
|
|
331
|
+
// location; otherwise the series location stands.
|
|
332
|
+
const location = occurrenceIds.length > 0
|
|
333
|
+
? occurrenceLocation(event.exceptions?.find((e) => sameRecurrenceId(e.recurrenceId, occurrenceIds[0])), event.physicalLocation?.text?.trim() ?? undefined)
|
|
334
|
+
: (event.physicalLocation?.text?.trim() ?? undefined);
|
|
315
335
|
return {
|
|
316
336
|
ics,
|
|
317
337
|
eventName: event.name?.trim() || 'Event',
|
|
318
338
|
start: times.start,
|
|
319
339
|
end: times.end ?? null,
|
|
320
|
-
location:
|
|
340
|
+
location: location ?? null,
|
|
321
341
|
allDay: event.wholeDay ?? false,
|
|
322
342
|
occurrenceCount: occurrenceIds.length,
|
|
323
343
|
};
|
package/dist/lib/eventTime.d.ts
CHANGED
|
@@ -17,9 +17,18 @@ export declare const utcIsoToWallClockDate: (iso: string, timeZone: string) => D
|
|
|
17
17
|
/** Treat `date`'s local components as wall time in `timeZone`. */
|
|
18
18
|
export declare const wallClockDateToUtcIso: (date: Date, timeZone: string) => string;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
* last resort
|
|
22
|
-
* to the ambient device zone.
|
|
20
|
+
* Canonical statement of the event display-zone precedence: the viewer's zone
|
|
21
|
+
* wins, the event's own zone is the last resort; `undefined` means no
|
|
22
|
+
* resolvable zone (formatters fall through to the ambient device zone).
|
|
23
|
+
*
|
|
24
|
+
* Deliberately kept as the documented, tested reference for that precedence
|
|
25
|
+
* even though no production surface calls it directly today: the React hook
|
|
26
|
+
* `useEventDisplayTimeZone` mirrors this same viewer-over-event rule for the
|
|
27
|
+
* provider-backed profile/community tiers (which this pure helper cannot see),
|
|
28
|
+
* and its final fallback is the event-zone half of this exact expression. If
|
|
29
|
+
* the precedence ever changes, update both — the `eventDisplayTimeZone` tests
|
|
30
|
+
* pin this pure contract while the `FeedEvent` integration test pins the hook
|
|
31
|
+
* chain.
|
|
23
32
|
*/
|
|
24
33
|
export declare const eventDisplayTimeZone: (eventTimeZone?: string | null, viewerTimeZone?: string | null) => string | undefined;
|
|
25
34
|
/** Intl `timeZone` option when `timeZone` is a valid IANA identifier. */
|
package/dist/lib/eventTime.js
CHANGED
|
@@ -99,9 +99,18 @@ export const wallClockDateToUtcIso = (date, timeZone) => {
|
|
|
99
99
|
return zonedDateTimeToUtcIso(local, timeZone) ?? date.toISOString();
|
|
100
100
|
};
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
103
|
-
* last resort
|
|
104
|
-
* to the ambient device zone.
|
|
102
|
+
* Canonical statement of the event display-zone precedence: the viewer's zone
|
|
103
|
+
* wins, the event's own zone is the last resort; `undefined` means no
|
|
104
|
+
* resolvable zone (formatters fall through to the ambient device zone).
|
|
105
|
+
*
|
|
106
|
+
* Deliberately kept as the documented, tested reference for that precedence
|
|
107
|
+
* even though no production surface calls it directly today: the React hook
|
|
108
|
+
* `useEventDisplayTimeZone` mirrors this same viewer-over-event rule for the
|
|
109
|
+
* provider-backed profile/community tiers (which this pure helper cannot see),
|
|
110
|
+
* and its final fallback is the event-zone half of this exact expression. If
|
|
111
|
+
* the precedence ever changes, update both — the `eventDisplayTimeZone` tests
|
|
112
|
+
* pin this pure contract while the `FeedEvent` integration test pins the hook
|
|
113
|
+
* chain.
|
|
105
114
|
*/
|
|
106
115
|
export const eventDisplayTimeZone = (eventTimeZone, viewerTimeZone) => isIanaTimeZone(viewerTimeZone)
|
|
107
116
|
? viewerTimeZone
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
/** Leftmost-label wildcard only: `*.example.com` matches `a.example.com`. */
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const hostMatchesHostPattern: (host: string, pattern: string) => boolean;
|
|
3
3
|
export declare const hostIsAllowed: (host: string, allowedHosts: readonly string[]) => boolean;
|
|
4
|
+
export declare const hostIsBlocked: (host: string, blockedHosts: readonly string[]) => boolean;
|
|
5
|
+
/** A host federates only when it matches the allowlist and no blocklist pattern. */
|
|
6
|
+
export declare const hostFederationAllowed: (host: string, allowedHosts: readonly string[], blockedHosts: readonly string[]) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* True when a sparse config patch touches the `federation` subtree (the
|
|
9
|
+
* allow/blocklist). Detects `{ federation: … }` only — an empty or unrelated
|
|
10
|
+
* patch never returns true, so the extra capability gate is applied narrowly.
|
|
11
|
+
*/
|
|
12
|
+
export declare const patchTouchesFederation: (config: unknown) => boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Leftmost-label wildcard only: `*.example.com` matches `a.example.com`. */
|
|
2
|
-
export const
|
|
2
|
+
export const hostMatchesHostPattern = (host, pattern) => {
|
|
3
3
|
const normalizedHost = host.trim().toLowerCase().replace(/\.$/, '');
|
|
4
4
|
const normalizedPattern = pattern.trim().toLowerCase().replace(/\.$/, '');
|
|
5
5
|
if (!normalizedHost || !normalizedPattern)
|
|
@@ -14,4 +14,15 @@ export const hostMatchesAllowedPattern = (host, pattern) => {
|
|
|
14
14
|
}
|
|
15
15
|
return normalizedHost === normalizedPattern;
|
|
16
16
|
};
|
|
17
|
-
export const hostIsAllowed = (host, allowedHosts) => allowedHosts.some((pattern) =>
|
|
17
|
+
export const hostIsAllowed = (host, allowedHosts) => allowedHosts.some((pattern) => hostMatchesHostPattern(host, pattern));
|
|
18
|
+
export const hostIsBlocked = (host, blockedHosts) => blockedHosts.some((pattern) => hostMatchesHostPattern(host, pattern));
|
|
19
|
+
/** A host federates only when it matches the allowlist and no blocklist pattern. */
|
|
20
|
+
export const hostFederationAllowed = (host, allowedHosts, blockedHosts) => hostIsAllowed(host, allowedHosts) && !hostIsBlocked(host, blockedHosts);
|
|
21
|
+
/**
|
|
22
|
+
* True when a sparse config patch touches the `federation` subtree (the
|
|
23
|
+
* allow/blocklist). Detects `{ federation: … }` only — an empty or unrelated
|
|
24
|
+
* patch never returns true, so the extra capability gate is applied narrowly.
|
|
25
|
+
*/
|
|
26
|
+
export const patchTouchesFederation = (config) => Boolean(config &&
|
|
27
|
+
typeof config === 'object' &&
|
|
28
|
+
'federation' in config);
|
package/dist/types/api.d.ts
CHANGED
|
@@ -38364,6 +38364,9 @@ export declare const serverInfoSchema: z.ZodObject<{
|
|
|
38364
38364
|
build: z.ZodOptional<z.ZodString>;
|
|
38365
38365
|
environment: z.ZodString;
|
|
38366
38366
|
publicContent: z.ZodBoolean;
|
|
38367
|
+
federation: z.ZodObject<{
|
|
38368
|
+
active: z.ZodBoolean;
|
|
38369
|
+
}, z.core.$strip>;
|
|
38367
38370
|
startedAt: z.ZodISODateTime;
|
|
38368
38371
|
uptimeSeconds: z.ZodNumber;
|
|
38369
38372
|
disk: z.ZodNullable<z.ZodObject<{
|
package/dist/types/api.js
CHANGED
|
@@ -214,6 +214,8 @@ export const serverInfoSchema = z.object({
|
|
|
214
214
|
build: z.string().optional(),
|
|
215
215
|
environment: z.string(),
|
|
216
216
|
publicContent: z.boolean(),
|
|
217
|
+
/** Whether this instance syncs with the wider ActivityPub network. Public, sanitized — no peer/allowlist data. */
|
|
218
|
+
federation: z.object({ active: z.boolean() }),
|
|
217
219
|
/** Process start time (ISO). */
|
|
218
220
|
startedAt: z.iso.datetime(),
|
|
219
221
|
uptimeSeconds: z.number().nonnegative(),
|
|
@@ -27,14 +27,14 @@ export type GroupCapability = (typeof groupCapabilities)[number];
|
|
|
27
27
|
export type ProfileCapability = (typeof profileCapabilities)[number];
|
|
28
28
|
export type ReportCapability = (typeof reportCapabilities)[number];
|
|
29
29
|
export type AccessTokenCapability = (typeof accessTokenCapabilities)[number];
|
|
30
|
-
export declare const roleCapabilities: readonly ["core-local", "core-accounts-read", "core-accounts-create", "core-accounts-update", "core-accounts-delete", "core-reports-create", "core-reports-update", "core-groups-create", "core-groups-read", "core-groups-delete", "core-groups-addMember", "core-groups-removeMember", "core-groups-changeMemberRole", "core-posts-create-note-local", "core-posts-create-note-public", "core-posts-create-note-direct", "core-posts-create-note-private", "core-posts-create-event-local", "core-posts-create-event-public", "core-posts-create-event-direct", "core-posts-create-event-private", "core-posts-create-poll-local", "core-posts-create-poll-public", "core-posts-create-poll-direct", "core-posts-create-poll-private", "core-posts-create-article-local", "core-posts-create-article-public", "core-posts-create-article-direct", "core-posts-create-article-private", "core-posts-create-resource-local", "core-posts-create-resource-public", "core-posts-create-resource-direct", "core-posts-create-resource-private", "core-posts-read-local", "core-posts-announce", "core-posts-delete", "core-profiles-read", "core-profiles-roles-update", "core-profiles-delete", "core-profiles-suspend", "core-profiles-update", "core-profiles-impersonate", "core-analytics-read", "core-config-update", "core-config-read", "core-customization-read", "core-customization-update", "core-capabilities-read", "core-capabilities-update", "core-backups-create", "core-backups-read", "core-backups-download", "core-backups-restore", "core-db-access", "core-i18n-update", "core-logs-read", "core-roles-read", "core-roles-update", "core-maintenance-restart", "core-media-read", "core-media-delete", "core-inviteLinks-create", "core-inviteLinks-read", "core-inviteLinks-update", "core-inviteLinks-delete", "core-serviceTokens-create", "core-serviceTokens-read", "core-serviceTokens-update", "core-serviceTokens-delete", "core-plugins-manage"];
|
|
30
|
+
export declare const roleCapabilities: readonly ["core-local", "core-accounts-read", "core-accounts-create", "core-accounts-update", "core-accounts-delete", "core-reports-create", "core-reports-update", "core-groups-create", "core-groups-read", "core-groups-delete", "core-groups-addMember", "core-groups-removeMember", "core-groups-changeMemberRole", "core-posts-create-note-local", "core-posts-create-note-public", "core-posts-create-note-direct", "core-posts-create-note-private", "core-posts-create-event-local", "core-posts-create-event-public", "core-posts-create-event-direct", "core-posts-create-event-private", "core-posts-create-poll-local", "core-posts-create-poll-public", "core-posts-create-poll-direct", "core-posts-create-poll-private", "core-posts-create-article-local", "core-posts-create-article-public", "core-posts-create-article-direct", "core-posts-create-article-private", "core-posts-create-resource-local", "core-posts-create-resource-public", "core-posts-create-resource-direct", "core-posts-create-resource-private", "core-posts-read-local", "core-posts-announce", "core-posts-delete", "core-profiles-read", "core-profiles-roles-update", "core-profiles-delete", "core-profiles-suspend", "core-profiles-update", "core-profiles-impersonate", "core-analytics-read", "core-config-update", "core-config-read", "core-federation-manage", "core-customization-read", "core-customization-update", "core-capabilities-read", "core-capabilities-update", "core-backups-create", "core-backups-read", "core-backups-download", "core-backups-restore", "core-db-access", "core-i18n-update", "core-logs-read", "core-roles-read", "core-roles-update", "core-maintenance-restart", "core-media-read", "core-media-delete", "core-inviteLinks-create", "core-inviteLinks-read", "core-inviteLinks-update", "core-inviteLinks-delete", "core-serviceTokens-create", "core-serviceTokens-read", "core-serviceTokens-update", "core-serviceTokens-delete", "core-plugins-manage"];
|
|
31
31
|
export type RoleCapability = (typeof roleCapabilities)[number];
|
|
32
32
|
/**
|
|
33
33
|
* Capability keys an instance admin can toggle for each role (leaves) plus the
|
|
34
34
|
* wildcard allow-all keys an editor exposes. `*` covers capabilities that do not
|
|
35
35
|
* fall under a `core-<domain>-*` category (e.g. `core-local`).
|
|
36
36
|
*/
|
|
37
|
-
export declare const roleCapabilityEditorKeys: readonly ["core-local", "core-accounts-read", "core-accounts-create", "core-accounts-update", "core-accounts-delete", "core-reports-create", "core-reports-update", "core-groups-create", "core-groups-read", "core-groups-delete", "core-groups-addMember", "core-groups-removeMember", "core-groups-changeMemberRole", "core-posts-create-note-local", "core-posts-create-note-public", "core-posts-create-note-direct", "core-posts-create-note-private", "core-posts-create-event-local", "core-posts-create-event-public", "core-posts-create-event-direct", "core-posts-create-event-private", "core-posts-create-poll-local", "core-posts-create-poll-public", "core-posts-create-poll-direct", "core-posts-create-poll-private", "core-posts-create-article-local", "core-posts-create-article-public", "core-posts-create-article-direct", "core-posts-create-article-private", "core-posts-create-resource-local", "core-posts-create-resource-public", "core-posts-create-resource-direct", "core-posts-create-resource-private", "core-posts-read-local", "core-posts-announce", "core-posts-delete", "core-profiles-read", "core-profiles-roles-update", "core-profiles-delete", "core-profiles-suspend", "core-profiles-update", "core-profiles-impersonate", "core-analytics-read", "core-config-update", "core-config-read", "core-customization-read", "core-customization-update", "core-capabilities-read", "core-capabilities-update", "core-backups-create", "core-backups-read", "core-backups-download", "core-backups-restore", "core-db-access", "core-i18n-update", "core-logs-read", "core-roles-read", "core-roles-update", "core-maintenance-restart", "core-media-read", "core-media-delete", "core-inviteLinks-create", "core-inviteLinks-read", "core-inviteLinks-update", "core-inviteLinks-delete", "core-serviceTokens-create", "core-serviceTokens-read", "core-serviceTokens-update", "core-serviceTokens-delete", "core-plugins-manage", "*", "core-accounts-*", "core-analytics-*", "core-backups-*", "core-capabilities-*", "core-config-*", "core-customization-*", "core-db-*", "core-groups-*", "core-i18n-*", "core-inviteLinks-*", "core-logs-*", "core-maintenance-*", "core-media-*", "core-plugins-*", "core-profiles-*", "core-posts-create-*", "core-posts-*", "core-reports-*", "core-roles-*", "core-serviceTokens-*"];
|
|
37
|
+
export declare const roleCapabilityEditorKeys: readonly ["core-local", "core-accounts-read", "core-accounts-create", "core-accounts-update", "core-accounts-delete", "core-reports-create", "core-reports-update", "core-groups-create", "core-groups-read", "core-groups-delete", "core-groups-addMember", "core-groups-removeMember", "core-groups-changeMemberRole", "core-posts-create-note-local", "core-posts-create-note-public", "core-posts-create-note-direct", "core-posts-create-note-private", "core-posts-create-event-local", "core-posts-create-event-public", "core-posts-create-event-direct", "core-posts-create-event-private", "core-posts-create-poll-local", "core-posts-create-poll-public", "core-posts-create-poll-direct", "core-posts-create-poll-private", "core-posts-create-article-local", "core-posts-create-article-public", "core-posts-create-article-direct", "core-posts-create-article-private", "core-posts-create-resource-local", "core-posts-create-resource-public", "core-posts-create-resource-direct", "core-posts-create-resource-private", "core-posts-read-local", "core-posts-announce", "core-posts-delete", "core-profiles-read", "core-profiles-roles-update", "core-profiles-delete", "core-profiles-suspend", "core-profiles-update", "core-profiles-impersonate", "core-analytics-read", "core-config-update", "core-config-read", "core-federation-manage", "core-customization-read", "core-customization-update", "core-capabilities-read", "core-capabilities-update", "core-backups-create", "core-backups-read", "core-backups-download", "core-backups-restore", "core-db-access", "core-i18n-update", "core-logs-read", "core-roles-read", "core-roles-update", "core-maintenance-restart", "core-media-read", "core-media-delete", "core-inviteLinks-create", "core-inviteLinks-read", "core-inviteLinks-update", "core-inviteLinks-delete", "core-serviceTokens-create", "core-serviceTokens-read", "core-serviceTokens-update", "core-serviceTokens-delete", "core-plugins-manage", "*", "core-accounts-*", "core-analytics-*", "core-backups-*", "core-capabilities-*", "core-config-*", "core-customization-*", "core-db-*", "core-federation-*", "core-groups-*", "core-i18n-*", "core-inviteLinks-*", "core-logs-*", "core-maintenance-*", "core-media-*", "core-plugins-*", "core-profiles-*", "core-posts-create-*", "core-posts-*", "core-reports-*", "core-roles-*", "core-serviceTokens-*"];
|
|
38
38
|
/** Capability keys an admin can toggle per relationship for posts. */
|
|
39
39
|
export declare const postCapabilityEditorKeys: readonly ["core-posts-read", "core-posts-update", "core-posts-delete", "core-posts-vote", "core-posts-react", "core-posts-rsvp", "core-posts-reply", "core-posts-jam-moderate", "core-posts-jam-speak", "core-posts-jam-read", "core-posts-*"];
|
|
40
40
|
/** Capability keys an admin can toggle per relationship for profiles. */
|
|
@@ -167,6 +167,7 @@ export const roleCapabilities = [
|
|
|
167
167
|
'core-analytics-read',
|
|
168
168
|
'core-config-update',
|
|
169
169
|
'core-config-read',
|
|
170
|
+
'core-federation-manage',
|
|
170
171
|
'core-customization-read',
|
|
171
172
|
'core-customization-update',
|
|
172
173
|
'core-capabilities-read',
|
|
@@ -208,6 +209,7 @@ export const roleCapabilityEditorKeys = [
|
|
|
208
209
|
'core-config-*',
|
|
209
210
|
'core-customization-*',
|
|
210
211
|
'core-db-*',
|
|
212
|
+
'core-federation-*',
|
|
211
213
|
'core-groups-*',
|
|
212
214
|
'core-i18n-*',
|
|
213
215
|
'core-inviteLinks-*',
|
package/dist/types/config.d.ts
CHANGED
|
@@ -166,6 +166,7 @@ export declare const coreConfigSchemaFactory: (sanitize?: boolean) => z.ZodObjec
|
|
|
166
166
|
federation: z.ZodObject<{
|
|
167
167
|
active: z.ZodBoolean;
|
|
168
168
|
allowedHosts: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
169
|
+
blockedHosts: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
169
170
|
}, z.core.$strip>;
|
|
170
171
|
activityPub: z.ZodObject<{
|
|
171
172
|
defaultDomain: z.ZodString;
|
|
@@ -349,6 +350,7 @@ export declare const coreConfigSchema: z.ZodObject<{
|
|
|
349
350
|
federation: z.ZodObject<{
|
|
350
351
|
active: z.ZodBoolean;
|
|
351
352
|
allowedHosts: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
353
|
+
blockedHosts: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
352
354
|
}, z.core.$strip>;
|
|
353
355
|
activityPub: z.ZodObject<{
|
|
354
356
|
defaultDomain: z.ZodString;
|
|
@@ -532,6 +534,7 @@ export declare const coreConfigSanitizedSchema: z.ZodObject<{
|
|
|
532
534
|
federation: z.ZodObject<{
|
|
533
535
|
active: z.ZodBoolean;
|
|
534
536
|
allowedHosts: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
537
|
+
blockedHosts: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
535
538
|
}, z.core.$strip>;
|
|
536
539
|
activityPub: z.ZodObject<{
|
|
537
540
|
defaultDomain: z.ZodString;
|
package/dist/types/config.js
CHANGED
|
@@ -136,6 +136,8 @@ export const coreConfigSchemaFactory = (sanitize) => z.object({
|
|
|
136
136
|
active: z.boolean(),
|
|
137
137
|
/** Host patterns (`mastodon.social`, `*.example.com`). Empty = fail closed. */
|
|
138
138
|
allowedHosts: z.array(z.string()).default([]),
|
|
139
|
+
/** Blocked host patterns, same semantics as `allowedHosts`. Deny wins. */
|
|
140
|
+
blockedHosts: z.array(z.string()).default([]),
|
|
139
141
|
}),
|
|
140
142
|
activityPub: z.object({
|
|
141
143
|
defaultDomain: z.string(),
|
|
@@ -150,6 +150,7 @@ export declare const notificationTypeSchema: z.ZodObject<{
|
|
|
150
150
|
"core-analytics-read": "core-analytics-read";
|
|
151
151
|
"core-config-update": "core-config-update";
|
|
152
152
|
"core-config-read": "core-config-read";
|
|
153
|
+
"core-federation-manage": "core-federation-manage";
|
|
153
154
|
"core-customization-read": "core-customization-read";
|
|
154
155
|
"core-customization-update": "core-customization-update";
|
|
155
156
|
"core-capabilities-read": "core-capabilities-read";
|
|
@@ -104,6 +104,15 @@ const adminCanManageMedia = (roles) => roles.map((role) => role.key === 'admin'
|
|
|
104
104
|
},
|
|
105
105
|
}
|
|
106
106
|
: role);
|
|
107
|
+
const adminCanManageFederation = (roles) => roles.map((role) => role.key === 'admin'
|
|
108
|
+
? {
|
|
109
|
+
...role,
|
|
110
|
+
capabilities: {
|
|
111
|
+
add: [...(role.capabilities?.add ?? []), 'core-federation-manage'],
|
|
112
|
+
remove: [...(role.capabilities?.remove ?? [])],
|
|
113
|
+
},
|
|
114
|
+
}
|
|
115
|
+
: role);
|
|
107
116
|
export const roleDefaultsHistory = [
|
|
108
117
|
{
|
|
109
118
|
version: '2026-10-06',
|
|
@@ -113,6 +122,10 @@ export const roleDefaultsHistory = [
|
|
|
113
122
|
version: '2026-10-13',
|
|
114
123
|
roles: versionedRoles('2026-10-13', adminCanManageMedia(builtinRoles)),
|
|
115
124
|
},
|
|
125
|
+
{
|
|
126
|
+
version: '2026-11-26',
|
|
127
|
+
roles: versionedRoles('2026-11-26', adminCanManageFederation(adminCanManageMedia(builtinRoles))),
|
|
128
|
+
},
|
|
116
129
|
];
|
|
117
130
|
/** The current (last) version — the one in use. */
|
|
118
131
|
export const currentRoleDefaults = roleDefaultsHistory[roleDefaultsHistory.length - 1];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@vitest/ui": "^4.1.12",
|
|
64
64
|
"eslint": "^10.14.0",
|
|
65
65
|
"eslint-config-prettier": "^9.1.0",
|
|
66
|
-
"i18next": "^26.
|
|
66
|
+
"i18next": "^26.3.4",
|
|
67
67
|
"livekit-client": "^2.19.2",
|
|
68
68
|
"prettier": "^3.8.1",
|
|
69
69
|
"tsc-alias": "^1.8.16",
|
package/src/lib/eventIcs.ts
CHANGED
|
@@ -5,8 +5,13 @@ import ical, {
|
|
|
5
5
|
} from 'ical-generator';
|
|
6
6
|
import { TZDate } from '@date-fns/tz';
|
|
7
7
|
import { tzlib_get_ical_block } from 'timezones-ical-library';
|
|
8
|
-
import type {
|
|
9
|
-
|
|
8
|
+
import type {
|
|
9
|
+
Event,
|
|
10
|
+
EventOccurrenceException,
|
|
11
|
+
PublicPost,
|
|
12
|
+
RecurrenceWeekday,
|
|
13
|
+
} from '../types';
|
|
14
|
+
import { effectiveEventTimes, sameRecurrenceId } from './eventRecurrence';
|
|
10
15
|
import { getJamUrl } from './jamHelpers';
|
|
11
16
|
import { isIanaTimeZone } from './timeZone';
|
|
12
17
|
|
|
@@ -120,6 +125,20 @@ const eventLocation = (
|
|
|
120
125
|
return event.url?.trim() || undefined;
|
|
121
126
|
};
|
|
122
127
|
|
|
128
|
+
/**
|
|
129
|
+
* The override's own location when one was set for that occurrence;
|
|
130
|
+
* otherwise the series-level location the rest of the builder resolves.
|
|
131
|
+
*/
|
|
132
|
+
const occurrenceLocation = (
|
|
133
|
+
exception: EventOccurrenceException | undefined,
|
|
134
|
+
fallback?: string,
|
|
135
|
+
): string | undefined => {
|
|
136
|
+
// Only a non-empty (trimmed) exception location overrides the series
|
|
137
|
+
// location; whitespace-only text falls through, matching eventLocation.
|
|
138
|
+
const text = exception?.physicalLocation?.text?.trim();
|
|
139
|
+
return text ? text : fallback;
|
|
140
|
+
};
|
|
141
|
+
|
|
123
142
|
const repeatingFreq: Record<
|
|
124
143
|
NonNullable<Event['recurrence']>['freq'],
|
|
125
144
|
ICalEventRepeatingFreq
|
|
@@ -237,6 +256,7 @@ export const buildEventIcs = (
|
|
|
237
256
|
|
|
238
257
|
for (const exception of event.exceptions ?? []) {
|
|
239
258
|
if (exception.cancelled || !exception.start) continue;
|
|
259
|
+
const overrideLocation = occurrenceLocation(exception, location);
|
|
240
260
|
if (event.wholeDay) {
|
|
241
261
|
// Rescheduled all-day occurrence: an all-day override whose day range
|
|
242
262
|
// is the exception's new start day through its end day (inclusive).
|
|
@@ -252,7 +272,7 @@ export const buildEventIcs = (
|
|
|
252
272
|
end: exclusiveEndAfterInclusiveDay(excLastInclusiveYmd),
|
|
253
273
|
summary,
|
|
254
274
|
...(description ? { description } : {}),
|
|
255
|
-
...(
|
|
275
|
+
...(overrideLocation ? { location: overrideLocation } : {}),
|
|
256
276
|
...(link ? { url: link } : {}),
|
|
257
277
|
...stamp,
|
|
258
278
|
recurrenceId: utcDateFromYmd(exception.recurrenceId.slice(0, 10)),
|
|
@@ -269,7 +289,7 @@ export const buildEventIcs = (
|
|
|
269
289
|
...(timeZone ? { timezone: timeZone } : {}),
|
|
270
290
|
summary,
|
|
271
291
|
...(description ? { description } : {}),
|
|
272
|
-
...(
|
|
292
|
+
...(overrideLocation ? { location: overrideLocation } : {}),
|
|
273
293
|
...(link ? { url: link } : {}),
|
|
274
294
|
...stamp,
|
|
275
295
|
recurrenceId: instantInZone(exception.recurrenceId, timeZone),
|
|
@@ -295,6 +315,12 @@ const addOccurrenceEvent = (
|
|
|
295
315
|
const summary = event.name?.trim() || 'Event';
|
|
296
316
|
const description = event.content?.trim();
|
|
297
317
|
const location = eventLocation(post, event, options?.postUrl);
|
|
318
|
+
// A booked occurrence may be a rescheduled one; its RECURRENCE-ID is the
|
|
319
|
+
// original slot, the key the exception is stored under.
|
|
320
|
+
const exception = event.exceptions?.find((e) =>
|
|
321
|
+
sameRecurrenceId(e.recurrenceId, recurrenceId),
|
|
322
|
+
);
|
|
323
|
+
const occLocation = occurrenceLocation(exception, location);
|
|
298
324
|
const times = effectiveEventTimes(event, recurrenceId);
|
|
299
325
|
const id = `openpeeps-event-${post.id}-${recurrenceId}@openpeepshq`;
|
|
300
326
|
const timeZone = event.wholeDay ? undefined : eventTimeZone(event);
|
|
@@ -309,7 +335,7 @@ const addOccurrenceEvent = (
|
|
|
309
335
|
end: exclusiveEndAfterInclusiveDay(lastInclusiveYmd),
|
|
310
336
|
summary,
|
|
311
337
|
...(description ? { description } : {}),
|
|
312
|
-
...(
|
|
338
|
+
...(occLocation ? { location: occLocation } : {}),
|
|
313
339
|
...(link ? { url: link } : {}),
|
|
314
340
|
});
|
|
315
341
|
return;
|
|
@@ -326,7 +352,7 @@ const addOccurrenceEvent = (
|
|
|
326
352
|
...(timeZone ? { timezone: timeZone } : {}),
|
|
327
353
|
summary,
|
|
328
354
|
...(description ? { description } : {}),
|
|
329
|
-
...(
|
|
355
|
+
...(occLocation ? { location: occLocation } : {}),
|
|
330
356
|
...(link ? { url: link } : {}),
|
|
331
357
|
});
|
|
332
358
|
};
|
|
@@ -385,12 +411,23 @@ export const rsvpConfirmationContent = (
|
|
|
385
411
|
occurrenceIds.length > 0
|
|
386
412
|
? effectiveEventTimes(event, occurrenceIds[0])
|
|
387
413
|
: { start: event.start, end: event.end };
|
|
414
|
+
// The first booked occurrence may be a rescheduled one with its own
|
|
415
|
+
// location; otherwise the series location stands.
|
|
416
|
+
const location =
|
|
417
|
+
occurrenceIds.length > 0
|
|
418
|
+
? occurrenceLocation(
|
|
419
|
+
event.exceptions?.find((e) =>
|
|
420
|
+
sameRecurrenceId(e.recurrenceId, occurrenceIds[0]),
|
|
421
|
+
),
|
|
422
|
+
event.physicalLocation?.text?.trim() ?? undefined,
|
|
423
|
+
)
|
|
424
|
+
: (event.physicalLocation?.text?.trim() ?? undefined);
|
|
388
425
|
return {
|
|
389
426
|
ics,
|
|
390
427
|
eventName: event.name?.trim() || 'Event',
|
|
391
428
|
start: times.start,
|
|
392
429
|
end: times.end ?? null,
|
|
393
|
-
location:
|
|
430
|
+
location: location ?? null,
|
|
394
431
|
allDay: event.wholeDay ?? false,
|
|
395
432
|
occurrenceCount: occurrenceIds.length,
|
|
396
433
|
};
|
package/src/lib/eventTime.ts
CHANGED
|
@@ -137,9 +137,18 @@ export const wallClockDateToUtcIso = (date: Date, timeZone: string): string => {
|
|
|
137
137
|
};
|
|
138
138
|
|
|
139
139
|
/**
|
|
140
|
-
*
|
|
141
|
-
* last resort
|
|
142
|
-
* to the ambient device zone.
|
|
140
|
+
* Canonical statement of the event display-zone precedence: the viewer's zone
|
|
141
|
+
* wins, the event's own zone is the last resort; `undefined` means no
|
|
142
|
+
* resolvable zone (formatters fall through to the ambient device zone).
|
|
143
|
+
*
|
|
144
|
+
* Deliberately kept as the documented, tested reference for that precedence
|
|
145
|
+
* even though no production surface calls it directly today: the React hook
|
|
146
|
+
* `useEventDisplayTimeZone` mirrors this same viewer-over-event rule for the
|
|
147
|
+
* provider-backed profile/community tiers (which this pure helper cannot see),
|
|
148
|
+
* and its final fallback is the event-zone half of this exact expression. If
|
|
149
|
+
* the precedence ever changes, update both — the `eventDisplayTimeZone` tests
|
|
150
|
+
* pin this pure contract while the `FeedEvent` integration test pins the hook
|
|
151
|
+
* chain.
|
|
143
152
|
*/
|
|
144
153
|
export const eventDisplayTimeZone = (
|
|
145
154
|
eventTimeZone?: string | null,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Leftmost-label wildcard only: `*.example.com` matches `a.example.com`. */
|
|
2
|
-
export const
|
|
2
|
+
export const hostMatchesHostPattern = (
|
|
3
3
|
host: string,
|
|
4
4
|
pattern: string,
|
|
5
5
|
): boolean => {
|
|
@@ -19,4 +19,30 @@ export const hostIsAllowed = (
|
|
|
19
19
|
host: string,
|
|
20
20
|
allowedHosts: readonly string[],
|
|
21
21
|
): boolean =>
|
|
22
|
-
allowedHosts.some((pattern) =>
|
|
22
|
+
allowedHosts.some((pattern) => hostMatchesHostPattern(host, pattern));
|
|
23
|
+
|
|
24
|
+
export const hostIsBlocked = (
|
|
25
|
+
host: string,
|
|
26
|
+
blockedHosts: readonly string[],
|
|
27
|
+
): boolean =>
|
|
28
|
+
blockedHosts.some((pattern) => hostMatchesHostPattern(host, pattern));
|
|
29
|
+
|
|
30
|
+
/** A host federates only when it matches the allowlist and no blocklist pattern. */
|
|
31
|
+
export const hostFederationAllowed = (
|
|
32
|
+
host: string,
|
|
33
|
+
allowedHosts: readonly string[],
|
|
34
|
+
blockedHosts: readonly string[],
|
|
35
|
+
): boolean =>
|
|
36
|
+
hostIsAllowed(host, allowedHosts) && !hostIsBlocked(host, blockedHosts);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* True when a sparse config patch touches the `federation` subtree (the
|
|
40
|
+
* allow/blocklist). Detects `{ federation: … }` only — an empty or unrelated
|
|
41
|
+
* patch never returns true, so the extra capability gate is applied narrowly.
|
|
42
|
+
*/
|
|
43
|
+
export const patchTouchesFederation = (config: unknown): boolean =>
|
|
44
|
+
Boolean(
|
|
45
|
+
config &&
|
|
46
|
+
typeof config === 'object' &&
|
|
47
|
+
'federation' in (config as Record<string, unknown>),
|
|
48
|
+
);
|
package/src/types/api.ts
CHANGED
|
@@ -341,6 +341,8 @@ export const serverInfoSchema = z.object({
|
|
|
341
341
|
build: z.string().optional(),
|
|
342
342
|
environment: z.string(),
|
|
343
343
|
publicContent: z.boolean(),
|
|
344
|
+
/** Whether this instance syncs with the wider ActivityPub network. Public, sanitized — no peer/allowlist data. */
|
|
345
|
+
federation: z.object({ active: z.boolean() }),
|
|
344
346
|
/** Process start time (ISO). */
|
|
345
347
|
startedAt: z.iso.datetime(),
|
|
346
348
|
uptimeSeconds: z.number().nonnegative(),
|
|
@@ -202,6 +202,7 @@ export const roleCapabilities = [
|
|
|
202
202
|
'core-analytics-read',
|
|
203
203
|
'core-config-update',
|
|
204
204
|
'core-config-read',
|
|
205
|
+
'core-federation-manage',
|
|
205
206
|
'core-customization-read',
|
|
206
207
|
'core-customization-update',
|
|
207
208
|
'core-capabilities-read',
|
|
@@ -246,6 +247,7 @@ export const roleCapabilityEditorKeys = [
|
|
|
246
247
|
'core-config-*',
|
|
247
248
|
'core-customization-*',
|
|
248
249
|
'core-db-*',
|
|
250
|
+
'core-federation-*',
|
|
249
251
|
'core-groups-*',
|
|
250
252
|
'core-i18n-*',
|
|
251
253
|
'core-inviteLinks-*',
|
package/src/types/config.ts
CHANGED
|
@@ -198,6 +198,8 @@ export const coreConfigSchemaFactory = (sanitize?: boolean) =>
|
|
|
198
198
|
active: z.boolean(),
|
|
199
199
|
/** Host patterns (`mastodon.social`, `*.example.com`). Empty = fail closed. */
|
|
200
200
|
allowedHosts: z.array(z.string()).default([]),
|
|
201
|
+
/** Blocked host patterns, same semantics as `allowedHosts`. Deny wins. */
|
|
202
|
+
blockedHosts: z.array(z.string()).default([]),
|
|
201
203
|
}),
|
|
202
204
|
activityPub: z.object({
|
|
203
205
|
defaultDomain: z.string(),
|
|
@@ -126,6 +126,19 @@ const adminCanManageMedia = (roles: RoleData[]): RoleData[] =>
|
|
|
126
126
|
: role,
|
|
127
127
|
);
|
|
128
128
|
|
|
129
|
+
const adminCanManageFederation = (roles: RoleData[]): RoleData[] =>
|
|
130
|
+
roles.map((role) =>
|
|
131
|
+
role.key === 'admin'
|
|
132
|
+
? {
|
|
133
|
+
...role,
|
|
134
|
+
capabilities: {
|
|
135
|
+
add: [...(role.capabilities?.add ?? []), 'core-federation-manage'],
|
|
136
|
+
remove: [...(role.capabilities?.remove ?? [])],
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
: role,
|
|
140
|
+
);
|
|
141
|
+
|
|
129
142
|
export const roleDefaultsHistory: RoleDefaultsVersion[] = [
|
|
130
143
|
{
|
|
131
144
|
version: '2026-10-06',
|
|
@@ -135,6 +148,13 @@ export const roleDefaultsHistory: RoleDefaultsVersion[] = [
|
|
|
135
148
|
version: '2026-10-13',
|
|
136
149
|
roles: versionedRoles('2026-10-13', adminCanManageMedia(builtinRoles)),
|
|
137
150
|
},
|
|
151
|
+
{
|
|
152
|
+
version: '2026-11-26',
|
|
153
|
+
roles: versionedRoles(
|
|
154
|
+
'2026-11-26',
|
|
155
|
+
adminCanManageFederation(adminCanManageMedia(builtinRoles)),
|
|
156
|
+
),
|
|
157
|
+
},
|
|
138
158
|
];
|
|
139
159
|
|
|
140
160
|
/** The current (last) version — the one in use. */
|