@openpeepshq/common 0.1.44 → 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.
- package/dist/lib/adminSections.d.ts +4 -0
- package/dist/lib/adminSections.js +5 -0
- package/dist/lib/capabilitiesHelpers.d.ts +9 -7
- package/dist/lib/capabilitiesHelpers.js +21 -13
- package/dist/lib/eventIcs.d.ts +17 -0
- package/dist/lib/eventIcs.js +138 -2
- package/dist/lib/eventRecurrence.d.ts +32 -0
- package/dist/lib/eventRecurrence.js +284 -0
- package/dist/lib/eventTime.d.ts +29 -0
- package/dist/lib/eventTime.js +143 -0
- package/dist/lib/federationHosts.d.ts +3 -0
- package/dist/lib/federationHosts.js +17 -0
- package/dist/lib/feedCursor.d.ts +14 -0
- package/dist/lib/feedCursor.js +22 -0
- package/dist/lib/feedFormat.d.ts +12 -0
- package/dist/lib/feedFormat.js +14 -0
- package/dist/lib/groupHelpers.d.ts +63 -41
- package/dist/lib/groupHelpers.js +155 -45
- package/dist/lib/groupTemplateHelpers.d.ts +16 -0
- package/dist/lib/groupTemplateHelpers.js +51 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/lib/index.js +11 -0
- package/dist/lib/jamHelpers.d.ts +38 -3
- package/dist/lib/jamHelpers.js +93 -8
- package/dist/lib/legacyThemeRoot.d.ts +3 -0
- package/dist/lib/legacyThemeRoot.js +10 -0
- package/dist/lib/markdownHelpers.d.ts +22 -0
- package/dist/lib/markdownHelpers.js +73 -3
- package/dist/lib/postHelpers.d.ts +164 -9
- package/dist/lib/postHelpers.js +353 -11
- package/dist/lib/profileHelpers.d.ts +11 -0
- package/dist/lib/profileHelpers.js +31 -0
- package/dist/lib/pushHelpers.d.ts +3 -1
- package/dist/lib/pushHelpers.js +13 -0
- package/dist/lib/reactions.d.ts +17 -0
- package/dist/lib/reactions.js +37 -0
- package/dist/lib/scopeHelpers.d.ts +31 -2
- package/dist/lib/scopeHelpers.js +37 -3
- package/dist/lib/ssoLoginUrl.d.ts +24 -0
- package/dist/lib/ssoLoginUrl.js +75 -0
- package/dist/lib/ssoProviders.d.ts +72 -0
- package/dist/lib/ssoProviders.js +370 -0
- package/dist/lib/text.d.ts +2 -0
- package/dist/lib/text.js +2 -0
- package/dist/lib/timeZone.d.ts +9 -0
- package/dist/lib/timeZone.js +44 -0
- package/dist/lib/tokenHelpers.d.ts +5 -0
- package/dist/lib/tokenHelpers.js +19 -0
- package/dist/types/analytics.d.ts +20 -0
- package/dist/types/analytics.js +4 -0
- package/dist/types/api.d.ts +42669 -10689
- package/dist/types/api.js +94 -16
- package/dist/types/auth.d.ts +22 -13
- package/dist/types/capabilities.d.ts +26 -5
- package/dist/types/capabilities.js +95 -1
- package/dist/types/config.d.ts +93 -6
- package/dist/types/config.js +56 -5
- package/dist/types/db.d.ts +1911 -248
- package/dist/types/db.js +17 -3
- package/dist/types/export.d.ts +120 -0
- package/dist/types/export.js +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/internal.d.ts +8313 -2675
- package/dist/types/internal.js +16 -1
- package/dist/types/models.d.ts +343 -16
- package/dist/types/models.js +98 -7
- package/dist/types/notifications.d.ts +1 -0
- package/dist/types/plugins.d.ts +43 -1
- package/dist/types/plugins.js +75 -1
- package/dist/types/roleDefaults.d.ts +31 -0
- package/dist/types/roleDefaults.js +110 -0
- package/dist/types/stats.d.ts +54359 -4718
- package/dist/types/stats.js +30 -0
- package/dist/types/utils.d.ts +2 -0
- package/dist/types/utils.js +1 -3
- package/package.json +1 -1
|
@@ -32,6 +32,10 @@ export declare const adminSections: readonly [{
|
|
|
32
32
|
readonly key: "apiKeys";
|
|
33
33
|
readonly path: "/admin/api-keys";
|
|
34
34
|
readonly capabilities: readonly ["core-serviceTokens-read"];
|
|
35
|
+
}, {
|
|
36
|
+
readonly key: "plugins";
|
|
37
|
+
readonly path: "/admin/plugins";
|
|
38
|
+
readonly capabilities: readonly ["core-plugins-manage"];
|
|
35
39
|
}, {
|
|
36
40
|
readonly key: "configuration";
|
|
37
41
|
readonly path: "/admin/configuration";
|
|
@@ -40,6 +40,11 @@ export const adminSections = [
|
|
|
40
40
|
path: '/admin/api-keys',
|
|
41
41
|
capabilities: ['core-serviceTokens-read'],
|
|
42
42
|
},
|
|
43
|
+
{
|
|
44
|
+
key: 'plugins',
|
|
45
|
+
path: '/admin/plugins',
|
|
46
|
+
capabilities: ['core-plugins-manage'],
|
|
47
|
+
},
|
|
43
48
|
{
|
|
44
49
|
key: 'configuration',
|
|
45
50
|
path: '/admin/configuration',
|
|
@@ -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" | "
|
|
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" | "
|
|
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" | "
|
|
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" | "
|
|
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" | "
|
|
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" | "
|
|
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" | "
|
|
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 = [
|
|
@@ -53,17 +62,10 @@ export const localOrNone = (authData) => {
|
|
|
53
62
|
return ['none'];
|
|
54
63
|
};
|
|
55
64
|
export const getGroupRelationships = (authData, group) => {
|
|
56
|
-
var _a, _b;
|
|
57
|
-
const
|
|
58
|
-
if (profile) {
|
|
59
|
-
return [
|
|
60
|
-
'local',
|
|
61
|
-
'none',
|
|
62
|
-
...((_b = (_a = profile.memberships.find((m) => m.group.id === group.id)) === null || _a === void 0 ? void 0 : _a.roles) !== null && _b !== void 0 ? _b : []),
|
|
63
|
-
];
|
|
64
|
-
}
|
|
65
|
-
if (authData.service) {
|
|
66
|
-
return ['local', 'none'];
|
|
65
|
+
var _a, _b, _c;
|
|
66
|
+
const membershipRoles = (_c = (_b = (_a = authData.profile) === null || _a === void 0 ? void 0 : _a.memberships.find((m) => m.group.id === group.id)) === null || _b === void 0 ? void 0 : _b.roles) !== null && _c !== void 0 ? _c : [];
|
|
67
|
+
if (authData.profile || authData.service) {
|
|
68
|
+
return [...localOrNone(authData), ...membershipRoles];
|
|
67
69
|
}
|
|
68
70
|
return ['none'];
|
|
69
71
|
};
|
|
@@ -79,6 +81,12 @@ export const getProfileRelationships = (authData, otherProfile) => {
|
|
|
79
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)) {
|
|
80
82
|
relationships.push('following');
|
|
81
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
|
+
}
|
|
82
90
|
return relationships;
|
|
83
91
|
};
|
|
84
92
|
export const getPostRelationships = (authData, post) => {
|
|
@@ -218,7 +226,7 @@ export const checkPostCapabilities = (authData, neededCapabilities, post, config
|
|
|
218
226
|
]);
|
|
219
227
|
return checkCapabilitiesWithCalculatedScope(capabilities, withPublicPostReadScopes(authData, post, neededCapabilities), neededCapabilities, { type: 'posts', id: post.id });
|
|
220
228
|
};
|
|
221
|
-
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 });
|
|
222
230
|
export const checkReportCapabilities = (authData, neededCapabilities, report, config) => checkCapabilitiesWithCalculatedScope(getReportCapabilities(authData, report, config), authData, neededCapabilities, { type: 'reports', id: report.id });
|
|
223
231
|
export const checkAccessTokenCapabilities = (authData, neededCapabilities, accessToken, config) => checkCapabilitiesWithExplicitScope(getAccessTokenCapabilities(authData, accessToken, config), authData, neededCapabilities, { scopeLevel: 'admin', resource: { type: 'self' } });
|
|
224
232
|
export const checkAccountCapabilities = (authData, neededCapabilities, targetAccount) => checkCapabilitiesWithExplicitScope(getAccountCapabilities(authData, targetAccount), authData, neededCapabilities, { scopeLevel: 'admin', resource: { type: 'self' } });
|
package/dist/lib/eventIcs.d.ts
CHANGED
|
@@ -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;
|
package/dist/lib/eventIcs.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import ical, { ICalCalendarMethod } from 'ical-generator';
|
|
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);
|
|
@@ -35,8 +36,41 @@ const eventLocation = (post, event, postUrl) => {
|
|
|
35
36
|
}
|
|
36
37
|
return ((_c = event.url) === null || _c === void 0 ? void 0 : _c.trim()) || undefined;
|
|
37
38
|
};
|
|
39
|
+
const repeatingFreq = {
|
|
40
|
+
DAILY: ICalEventRepeatingFreq.DAILY,
|
|
41
|
+
WEEKLY: ICalEventRepeatingFreq.WEEKLY,
|
|
42
|
+
MONTHLY: ICalEventRepeatingFreq.MONTHLY,
|
|
43
|
+
};
|
|
44
|
+
const repeatingWeekday = {
|
|
45
|
+
MO: ICalWeekday.MO,
|
|
46
|
+
TU: ICalWeekday.TU,
|
|
47
|
+
WE: ICalWeekday.WE,
|
|
48
|
+
TH: ICalWeekday.TH,
|
|
49
|
+
FR: ICalWeekday.FR,
|
|
50
|
+
SA: ICalWeekday.SA,
|
|
51
|
+
SU: ICalWeekday.SU,
|
|
52
|
+
};
|
|
53
|
+
const repeatingOptions = (event) => {
|
|
54
|
+
var _a, _b, _c;
|
|
55
|
+
const recurrence = event.recurrence;
|
|
56
|
+
if (!recurrence)
|
|
57
|
+
return undefined;
|
|
58
|
+
const exclude = ((_a = event.exceptions) !== null && _a !== void 0 ? _a : [])
|
|
59
|
+
.filter((exception) => exception.cancelled)
|
|
60
|
+
.map((exception) => new Date(exception.recurrenceId));
|
|
61
|
+
return {
|
|
62
|
+
freq: repeatingFreq[recurrence.freq],
|
|
63
|
+
interval: (_b = recurrence.interval) !== null && _b !== void 0 ? _b : 1,
|
|
64
|
+
...(((_c = recurrence.byDay) === null || _c === void 0 ? void 0 : _c.length)
|
|
65
|
+
? { byDay: recurrence.byDay.map((day) => repeatingWeekday[day]) }
|
|
66
|
+
: {}),
|
|
67
|
+
...(recurrence.until ? { until: new Date(recurrence.until) } : {}),
|
|
68
|
+
...(recurrence.count ? { count: recurrence.count } : {}),
|
|
69
|
+
...(exclude.length ? { exclude } : {}),
|
|
70
|
+
};
|
|
71
|
+
};
|
|
38
72
|
export const buildEventIcs = (post, options) => {
|
|
39
|
-
var _a, _b, _c, _d, _e, _f;
|
|
73
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
40
74
|
if (post.type !== 'event' || ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) !== 'event') {
|
|
41
75
|
return null;
|
|
42
76
|
}
|
|
@@ -50,6 +84,7 @@ export const buildEventIcs = (post, options) => {
|
|
|
50
84
|
const summary = ((_c = event.name) === null || _c === void 0 ? void 0 : _c.trim()) || 'Event';
|
|
51
85
|
const description = (_d = event.content) === null || _d === void 0 ? void 0 : _d.trim();
|
|
52
86
|
const location = eventLocation(post, event, options === null || options === void 0 ? void 0 : options.postUrl);
|
|
87
|
+
const repeating = repeatingOptions(event);
|
|
53
88
|
if (event.wholeDay) {
|
|
54
89
|
const startYmd = event.start.slice(0, 10);
|
|
55
90
|
const lastInclusiveYmd = (_f = (_e = event.end) === null || _e === void 0 ? void 0 : _e.slice(0, 10)) !== null && _f !== void 0 ? _f : startYmd;
|
|
@@ -62,6 +97,7 @@ export const buildEventIcs = (post, options) => {
|
|
|
62
97
|
...(description ? { description } : {}),
|
|
63
98
|
...(location ? { location } : {}),
|
|
64
99
|
...(link ? { url: link } : {}),
|
|
100
|
+
...(repeating ? { repeating } : {}),
|
|
65
101
|
});
|
|
66
102
|
}
|
|
67
103
|
else {
|
|
@@ -77,7 +113,107 @@ export const buildEventIcs = (post, options) => {
|
|
|
77
113
|
...(description ? { description } : {}),
|
|
78
114
|
...(location ? { location } : {}),
|
|
79
115
|
...(link ? { url: link } : {}),
|
|
116
|
+
...(repeating ? { repeating } : {}),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
for (const exception of (_g = event.exceptions) !== null && _g !== void 0 ? _g : []) {
|
|
120
|
+
if (exception.cancelled || !exception.start)
|
|
121
|
+
continue;
|
|
122
|
+
const start = new Date(exception.start);
|
|
123
|
+
const end = exception.end
|
|
124
|
+
? new Date(exception.end)
|
|
125
|
+
: new Date(start.getTime() + 60 * 60 * 1000);
|
|
126
|
+
calendar.createEvent({
|
|
127
|
+
id: `openpeeps-event-${post.id}-${exception.recurrenceId}@openpeepshq`,
|
|
128
|
+
start,
|
|
129
|
+
end,
|
|
130
|
+
summary,
|
|
131
|
+
...(description ? { description } : {}),
|
|
132
|
+
...(location ? { location } : {}),
|
|
133
|
+
...(link ? { url: link } : {}),
|
|
134
|
+
recurrenceId: new Date(exception.recurrenceId),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return calendar.toString() + '\r\n';
|
|
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 } : {}),
|
|
80
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);
|
|
81
194
|
}
|
|
82
195
|
return calendar.toString() + '\r\n';
|
|
83
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
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Event, EventOccurrenceException, EventRecurrence, RecurrenceWeekday } from '../types';
|
|
2
|
+
export type EventRecurrenceTranslate = (key: string, options?: {
|
|
3
|
+
defaultValue?: string;
|
|
4
|
+
[key: string]: string | number | undefined;
|
|
5
|
+
}) => string;
|
|
6
|
+
export declare const OCCURRENCE_HORIZON_MS: number;
|
|
7
|
+
export type ExpandedOccurrence = {
|
|
8
|
+
recurrenceId: string;
|
|
9
|
+
start: string;
|
|
10
|
+
end?: string;
|
|
11
|
+
cancelled: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare const normalizeRecurrenceId: (value: string) => string;
|
|
14
|
+
export declare const sameRecurrenceId: (a?: string, b?: string) => boolean;
|
|
15
|
+
export declare const isRecurringEvent: (event: Event) => boolean;
|
|
16
|
+
export declare const eventDurationMs: (event: Event) => number | undefined;
|
|
17
|
+
export declare const weekdayFromDate: (date: Date) => RecurrenceWeekday;
|
|
18
|
+
export declare const parseOccurrenceQuery: (value?: string | null) => string | undefined;
|
|
19
|
+
export declare const expandEventOccurrences: (event: Event, window: {
|
|
20
|
+
from: Date;
|
|
21
|
+
to: Date;
|
|
22
|
+
}) => ExpandedOccurrence[];
|
|
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;
|
|
26
|
+
export declare const previewUpcomingOccurrences: (event: Event, count?: number, now?: Date) => ExpandedOccurrence[];
|
|
27
|
+
export declare const effectiveEventTimes: (event: Event, recurrenceId?: string) => {
|
|
28
|
+
start: string;
|
|
29
|
+
end?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare const upsertEventException: (event: Event, exception: EventOccurrenceException) => Event;
|
|
32
|
+
export declare const formatEventRecurrence: (recurrence: EventRecurrence | undefined, t: EventRecurrenceTranslate, start?: string) => string;
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { addDays, addMonths, addWeeks, differenceInCalendarWeeks, getDay, } from 'date-fns';
|
|
2
|
+
const WEEKDAY_ORDER = [
|
|
3
|
+
'MO',
|
|
4
|
+
'TU',
|
|
5
|
+
'WE',
|
|
6
|
+
'TH',
|
|
7
|
+
'FR',
|
|
8
|
+
'SA',
|
|
9
|
+
'SU',
|
|
10
|
+
];
|
|
11
|
+
export const OCCURRENCE_HORIZON_MS = 365 * 24 * 60 * 60 * 1000;
|
|
12
|
+
const WEEKDAY_INDEX = {
|
|
13
|
+
SU: 0,
|
|
14
|
+
MO: 1,
|
|
15
|
+
TU: 2,
|
|
16
|
+
WE: 3,
|
|
17
|
+
TH: 4,
|
|
18
|
+
FR: 5,
|
|
19
|
+
SA: 6,
|
|
20
|
+
};
|
|
21
|
+
const INDEX_WEEKDAY = [
|
|
22
|
+
'SU',
|
|
23
|
+
'MO',
|
|
24
|
+
'TU',
|
|
25
|
+
'WE',
|
|
26
|
+
'TH',
|
|
27
|
+
'FR',
|
|
28
|
+
'SA',
|
|
29
|
+
];
|
|
30
|
+
export const normalizeRecurrenceId = (value) => {
|
|
31
|
+
const date = new Date(value);
|
|
32
|
+
if (Number.isNaN(date.getTime())) {
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
return date.toISOString();
|
|
36
|
+
};
|
|
37
|
+
export const sameRecurrenceId = (a, b) => {
|
|
38
|
+
if (!a || !b)
|
|
39
|
+
return false;
|
|
40
|
+
return normalizeRecurrenceId(a) === normalizeRecurrenceId(b);
|
|
41
|
+
};
|
|
42
|
+
export const isRecurringEvent = (event) => !!event.recurrence;
|
|
43
|
+
export const eventDurationMs = (event) => {
|
|
44
|
+
if (!event.end)
|
|
45
|
+
return undefined;
|
|
46
|
+
const ms = new Date(event.end).getTime() - new Date(event.start).getTime();
|
|
47
|
+
return Number.isFinite(ms) && ms >= 0 ? ms : undefined;
|
|
48
|
+
};
|
|
49
|
+
const toIso = (date) => date.toISOString();
|
|
50
|
+
const applyDuration = (start, durationMs) => {
|
|
51
|
+
if (durationMs == null)
|
|
52
|
+
return undefined;
|
|
53
|
+
return toIso(new Date(start.getTime() + durationMs));
|
|
54
|
+
};
|
|
55
|
+
const exceptionById = (event) => {
|
|
56
|
+
var _a;
|
|
57
|
+
const map = new Map();
|
|
58
|
+
for (const exception of (_a = event.exceptions) !== null && _a !== void 0 ? _a : []) {
|
|
59
|
+
map.set(normalizeRecurrenceId(exception.recurrenceId), exception);
|
|
60
|
+
}
|
|
61
|
+
return map;
|
|
62
|
+
};
|
|
63
|
+
export const weekdayFromDate = (date) => INDEX_WEEKDAY[getDay(date)];
|
|
64
|
+
export const parseOccurrenceQuery = (value) => {
|
|
65
|
+
if (!value)
|
|
66
|
+
return undefined;
|
|
67
|
+
const date = new Date(value);
|
|
68
|
+
if (Number.isNaN(date.getTime()))
|
|
69
|
+
return undefined;
|
|
70
|
+
return date.toISOString();
|
|
71
|
+
};
|
|
72
|
+
const nextByFreq = (date, freq, interval) => {
|
|
73
|
+
if (freq === 'DAILY')
|
|
74
|
+
return addDays(date, interval);
|
|
75
|
+
if (freq === 'WEEKLY')
|
|
76
|
+
return addWeeks(date, interval);
|
|
77
|
+
return addMonths(date, interval);
|
|
78
|
+
};
|
|
79
|
+
const generateRawStarts = (event, untilBound) => {
|
|
80
|
+
var _a, _b, _c;
|
|
81
|
+
const recurrence = event.recurrence;
|
|
82
|
+
const dtstart = new Date(event.start);
|
|
83
|
+
if (!recurrence) {
|
|
84
|
+
return [dtstart];
|
|
85
|
+
}
|
|
86
|
+
const interval = (_a = recurrence.interval) !== null && _a !== void 0 ? _a : 1;
|
|
87
|
+
const until = recurrence.until ? new Date(recurrence.until) : undefined;
|
|
88
|
+
const hardStop = until && until < untilBound ? until : untilBound;
|
|
89
|
+
const starts = [];
|
|
90
|
+
const pushIfValid = (date) => {
|
|
91
|
+
if (date.getTime() < dtstart.getTime())
|
|
92
|
+
return;
|
|
93
|
+
if (date.getTime() > hardStop.getTime())
|
|
94
|
+
return;
|
|
95
|
+
starts.push(date);
|
|
96
|
+
};
|
|
97
|
+
if (recurrence.freq === 'WEEKLY' && ((_c = (_b = recurrence.byDay) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0) {
|
|
98
|
+
const byDays = new Set(recurrence.byDay);
|
|
99
|
+
let cursor = dtstart;
|
|
100
|
+
while (cursor.getTime() <= hardStop.getTime()) {
|
|
101
|
+
if (byDays.has(weekdayFromDate(cursor)) &&
|
|
102
|
+
differenceInCalendarWeeks(cursor, dtstart) % interval === 0) {
|
|
103
|
+
pushIfValid(cursor);
|
|
104
|
+
}
|
|
105
|
+
if (recurrence.count && starts.length >= recurrence.count)
|
|
106
|
+
break;
|
|
107
|
+
cursor = addDays(cursor, 1);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
let cursor = dtstart;
|
|
112
|
+
while (cursor.getTime() <= hardStop.getTime()) {
|
|
113
|
+
pushIfValid(cursor);
|
|
114
|
+
if (recurrence.count && starts.length >= recurrence.count)
|
|
115
|
+
break;
|
|
116
|
+
cursor = nextByFreq(cursor, recurrence.freq, interval);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const unique = [
|
|
120
|
+
...new Map(starts.map((date) => [date.getTime(), date])).values(),
|
|
121
|
+
].sort((a, b) => a.getTime() - b.getTime());
|
|
122
|
+
return recurrence.count ? unique.slice(0, recurrence.count) : unique;
|
|
123
|
+
};
|
|
124
|
+
const decorateOccurrence = (originalStart, event, exceptions, durationMs) => {
|
|
125
|
+
var _a, _b, _c;
|
|
126
|
+
const recurrenceId = toIso(originalStart);
|
|
127
|
+
const exception = exceptions.get(recurrenceId);
|
|
128
|
+
if (exception === null || exception === void 0 ? void 0 : exception.cancelled) {
|
|
129
|
+
return {
|
|
130
|
+
recurrenceId,
|
|
131
|
+
start: (_a = exception.start) !== null && _a !== void 0 ? _a : recurrenceId,
|
|
132
|
+
end: (_b = exception.end) !== null && _b !== void 0 ? _b : applyDuration(originalStart, durationMs),
|
|
133
|
+
cancelled: true,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (exception === null || exception === void 0 ? void 0 : exception.start) {
|
|
137
|
+
const start = new Date(exception.start);
|
|
138
|
+
return {
|
|
139
|
+
recurrenceId,
|
|
140
|
+
start: toIso(start),
|
|
141
|
+
end: (_c = exception.end) !== null && _c !== void 0 ? _c : applyDuration(start, durationMs),
|
|
142
|
+
cancelled: false,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
recurrenceId,
|
|
147
|
+
start: recurrenceId,
|
|
148
|
+
end: applyDuration(originalStart, durationMs),
|
|
149
|
+
cancelled: false,
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
export const expandEventOccurrences = (event, window) => {
|
|
153
|
+
const durationMs = eventDurationMs(event);
|
|
154
|
+
const exceptions = exceptionById(event);
|
|
155
|
+
const rawStarts = generateRawStarts(event, window.to);
|
|
156
|
+
return rawStarts
|
|
157
|
+
.map((start) => decorateOccurrence(start, event, exceptions, durationMs))
|
|
158
|
+
.filter((occurrence) => {
|
|
159
|
+
const start = new Date(occurrence.start);
|
|
160
|
+
const end = occurrence.end ? new Date(occurrence.end) : start;
|
|
161
|
+
return end >= window.from && start <= window.to;
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
export const occurrencesForIndex = (event, now = new Date()) => {
|
|
165
|
+
if (!event.recurrence) {
|
|
166
|
+
return [
|
|
167
|
+
{
|
|
168
|
+
recurrenceId: normalizeRecurrenceId(event.start),
|
|
169
|
+
start: normalizeRecurrenceId(event.start),
|
|
170
|
+
end: event.end ? normalizeRecurrenceId(event.end) : undefined,
|
|
171
|
+
cancelled: false,
|
|
172
|
+
},
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
return expandEventOccurrences(event, {
|
|
176
|
+
from: new Date(now.getTime() - OCCURRENCE_HORIZON_MS),
|
|
177
|
+
to: new Date(now.getTime() + OCCURRENCE_HORIZON_MS),
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
export const listRsvpOccurrences = (event, now = new Date()) => expandEventOccurrences(event, {
|
|
181
|
+
from: now,
|
|
182
|
+
to: new Date(now.getTime() + OCCURRENCE_HORIZON_MS),
|
|
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);
|
|
191
|
+
export const effectiveEventTimes = (event, recurrenceId) => {
|
|
192
|
+
if (!recurrenceId) {
|
|
193
|
+
return { start: event.start, end: event.end };
|
|
194
|
+
}
|
|
195
|
+
const window = {
|
|
196
|
+
from: new Date(new Date(recurrenceId).getTime() - OCCURRENCE_HORIZON_MS),
|
|
197
|
+
to: new Date(new Date(recurrenceId).getTime() + OCCURRENCE_HORIZON_MS),
|
|
198
|
+
};
|
|
199
|
+
const match = expandEventOccurrences(event, window).find((occurrence) => sameRecurrenceId(occurrence.recurrenceId, recurrenceId));
|
|
200
|
+
if (!match || match.cancelled) {
|
|
201
|
+
return { start: event.start, end: event.end };
|
|
202
|
+
}
|
|
203
|
+
return { start: match.start, end: match.end };
|
|
204
|
+
};
|
|
205
|
+
export const upsertEventException = (event, exception) => {
|
|
206
|
+
var _a;
|
|
207
|
+
const recurrenceId = normalizeRecurrenceId(exception.recurrenceId);
|
|
208
|
+
const rest = ((_a = event.exceptions) !== null && _a !== void 0 ? _a : []).filter((existing) => !sameRecurrenceId(existing.recurrenceId, recurrenceId));
|
|
209
|
+
return {
|
|
210
|
+
...event,
|
|
211
|
+
exceptions: [...rest, { ...exception, recurrenceId }],
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
const sortWeekdays = (days) => [...days].sort((a, b) => WEEKDAY_ORDER.indexOf(a) - WEEKDAY_ORDER.indexOf(b));
|
|
215
|
+
const formatUntilDate = (until) => new Date(until).toLocaleDateString(undefined, {
|
|
216
|
+
month: 'short',
|
|
217
|
+
day: 'numeric',
|
|
218
|
+
year: 'numeric',
|
|
219
|
+
});
|
|
220
|
+
const formatWeekdayLabels = (days, t) => sortWeekdays(days)
|
|
221
|
+
.map((day) => t(`events.form.repeat.day.${day}`, { defaultValue: day }))
|
|
222
|
+
.join(', ');
|
|
223
|
+
const formatRecurrencePattern = (recurrence, t, start) => {
|
|
224
|
+
var _a, _b;
|
|
225
|
+
const interval = (_a = recurrence.interval) !== null && _a !== void 0 ? _a : 1;
|
|
226
|
+
if (recurrence.freq === 'DAILY') {
|
|
227
|
+
return interval === 1
|
|
228
|
+
? t('events.repeat.daily', { defaultValue: 'Daily' })
|
|
229
|
+
: t('events.repeat.everyNDays', {
|
|
230
|
+
defaultValue: 'Every {{count}} days',
|
|
231
|
+
count: interval,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
if (recurrence.freq === 'MONTHLY') {
|
|
235
|
+
return interval === 1
|
|
236
|
+
? t('events.repeat.monthly', { defaultValue: 'Monthly' })
|
|
237
|
+
: t('events.repeat.everyNMonths', {
|
|
238
|
+
defaultValue: 'Every {{count}} months',
|
|
239
|
+
count: interval,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
const days = ((_b = recurrence.byDay) === null || _b === void 0 ? void 0 : _b.length) && recurrence.byDay.length > 0
|
|
243
|
+
? recurrence.byDay
|
|
244
|
+
: start
|
|
245
|
+
? [weekdayFromDate(new Date(start))]
|
|
246
|
+
: [];
|
|
247
|
+
const dayLabels = formatWeekdayLabels(days, t);
|
|
248
|
+
if (dayLabels) {
|
|
249
|
+
return interval === 1
|
|
250
|
+
? t('events.repeat.weeklyOn', {
|
|
251
|
+
defaultValue: 'Weekly on {{days}}',
|
|
252
|
+
days: dayLabels,
|
|
253
|
+
})
|
|
254
|
+
: t('events.repeat.everyNWeeksOn', {
|
|
255
|
+
defaultValue: 'Every {{count}} weeks on {{days}}',
|
|
256
|
+
count: interval,
|
|
257
|
+
days: dayLabels,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
return interval === 1
|
|
261
|
+
? t('events.repeat.weekly', { defaultValue: 'Weekly' })
|
|
262
|
+
: t('events.repeat.everyNWeeks', {
|
|
263
|
+
defaultValue: 'Every {{count}} weeks',
|
|
264
|
+
count: interval,
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
export const formatEventRecurrence = (recurrence, t, start) => {
|
|
268
|
+
if (!recurrence)
|
|
269
|
+
return '';
|
|
270
|
+
const pattern = formatRecurrencePattern(recurrence, t, start);
|
|
271
|
+
if (recurrence.until) {
|
|
272
|
+
return `${pattern} ${t('events.repeat.until', {
|
|
273
|
+
defaultValue: 'until {{date}}',
|
|
274
|
+
date: formatUntilDate(recurrence.until),
|
|
275
|
+
})}`;
|
|
276
|
+
}
|
|
277
|
+
if (recurrence.count) {
|
|
278
|
+
return `${pattern}, ${t('events.repeat.times', {
|
|
279
|
+
defaultValue: '{{count}} times',
|
|
280
|
+
count: recurrence.count,
|
|
281
|
+
})}`;
|
|
282
|
+
}
|
|
283
|
+
return pattern;
|
|
284
|
+
};
|