@openpeepshq/common 0.1.46 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/adminSections.js +1 -1
- package/dist/lib/capabilitiesHelpers.js +30 -40
- package/dist/lib/csvHelpers.js +1 -1
- package/dist/lib/eventIcs.js +26 -32
- package/dist/lib/eventRecurrence.d.ts +17 -0
- package/dist/lib/eventRecurrence.js +75 -18
- package/dist/lib/eventTime.js +9 -11
- package/dist/lib/groupHelpers.js +13 -34
- package/dist/lib/groupTemplateHelpers.js +6 -10
- package/dist/lib/jamHelpers.js +6 -9
- package/dist/lib/markdownHelpers.js +2 -3
- package/dist/lib/postHelpers.js +70 -97
- package/dist/lib/profileHelpers.js +17 -24
- package/dist/lib/pushHelpers.js +3 -4
- package/dist/lib/scopeHelpers.js +6 -9
- package/dist/lib/ssoLoginUrl.js +4 -6
- package/dist/lib/ssoProviders.js +35 -39
- package/dist/lib/tokenHelpers.js +5 -5
- package/dist/lib/utils.js +6 -7
- package/dist/types/admin-db.js +1 -1
- package/dist/types/api.d.ts +1 -0
- package/dist/types/api.js +1 -1
- package/dist/types/config.d.ts +3 -0
- package/dist/types/config.js +3 -0
- package/dist/types/models.js +1 -1
- package/dist/types/plugins.js +2 -2
- package/dist/zod.d.ts +1 -0
- package/dist/zod.js +1 -0
- package/package.json +36 -6
- package/src/index.ts +4 -0
- package/src/lib/adminSections.ts +84 -0
- package/src/lib/attachmentHelpers.ts +14 -0
- package/src/lib/capabilitiesHelpers.ts +532 -0
- package/src/lib/colors.ts +20 -0
- package/src/lib/csvHelpers.ts +31 -0
- package/src/lib/eventIcs.ts +265 -0
- package/src/lib/eventRecurrence.ts +495 -0
- package/src/lib/eventTime.ts +206 -0
- package/src/lib/federationHosts.ts +22 -0
- package/src/lib/feedCursor.ts +27 -0
- package/src/lib/feedFormat.ts +24 -0
- package/src/lib/groupHelpers.ts +421 -0
- package/src/lib/groupTemplateHelpers.ts +83 -0
- package/src/lib/index.ts +29 -0
- package/src/lib/jamHelpers.ts +164 -0
- package/src/lib/legacyThemeRoot.ts +14 -0
- package/src/lib/markdownHelpers.ts +122 -0
- package/src/lib/mediaDimensions.ts +21 -0
- package/src/lib/postHelpers.ts +783 -0
- package/src/lib/profileHelpers.ts +220 -0
- package/src/lib/pushHelpers.ts +34 -0
- package/src/lib/reactions.ts +52 -0
- package/src/lib/reportHelpers.ts +7 -0
- package/src/lib/scopeHelpers.ts +176 -0
- package/src/lib/ssoLoginUrl.ts +93 -0
- package/src/lib/ssoProviders.ts +472 -0
- package/src/lib/text.ts +26 -0
- package/src/lib/timeZone.ts +52 -0
- package/src/lib/tokenHelpers.ts +119 -0
- package/src/lib/utils.ts +322 -0
- package/src/types/admin-db.ts +74 -0
- package/src/types/admin-email.ts +55 -0
- package/src/types/admin-jobs.ts +17 -0
- package/src/types/admin-performance.ts +20 -0
- package/src/types/analytics.ts +318 -0
- package/src/types/api.ts +871 -0
- package/src/types/apple-app-site-association.ts +54 -0
- package/src/types/auth.ts +22 -0
- package/src/types/capabilities.ts +280 -0
- package/src/types/config.ts +546 -0
- package/src/types/db.ts +138 -0
- package/src/types/export.ts +10 -0
- package/src/types/index.ts +20 -0
- package/src/types/internal.ts +338 -0
- package/src/types/models.ts +939 -0
- package/src/types/notifications.ts +92 -0
- package/src/types/plugins.ts +150 -0
- package/src/types/roleDefaults.ts +132 -0
- package/src/types/stats.ts +195 -0
- package/src/types/stripe.ts +45 -0
- package/src/types/utils.ts +100 -0
- package/src/zod.ts +1 -0
package/dist/lib/groupHelpers.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { defaultGroupAdminCapabilityAdds, defaultGroupOwnerCapabilityAdds, defaultGroupRoles, } from '../types/capabilities.js';
|
|
2
2
|
import { checkCapabilities, getGroupCapabilitiesByRoles, } from './capabilitiesHelpers.js';
|
|
3
3
|
import { profileName } from './profileHelpers.js';
|
|
4
|
-
const withModerator = (member) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
...(((_b = member.remove) === null || _b === void 0 ? void 0 : _b.length) ? { remove: member.remove } : {}),
|
|
9
|
-
});
|
|
10
|
-
};
|
|
4
|
+
const withModerator = (member) => ({
|
|
5
|
+
add: [...(member.add ?? []), 'core-posts-delete'],
|
|
6
|
+
...(member.remove?.length ? { remove: member.remove } : {}),
|
|
7
|
+
});
|
|
11
8
|
const ownerCapabilities = {
|
|
12
9
|
add: [...defaultGroupOwnerCapabilityAdds],
|
|
13
10
|
};
|
|
@@ -15,7 +12,7 @@ const adminCapabilities = {
|
|
|
15
12
|
add: [...defaultGroupAdminCapabilityAdds],
|
|
16
13
|
};
|
|
17
14
|
const containsIgnoreCase = (candidate, query) => candidate.toLowerCase().indexOf(query.toLowerCase()) > -1;
|
|
18
|
-
export const groupName = (group) =>
|
|
15
|
+
export const groupName = (group) => group?.displayName || group?.handle || '';
|
|
19
16
|
export const matchesGroupQuery = (group, query, queryOptions = { handle: true, displayName: true, description: false }) => (queryOptions.handle && containsIgnoreCase(group.handle, query)) ||
|
|
20
17
|
(queryOptions.displayName &&
|
|
21
18
|
group.displayName &&
|
|
@@ -23,15 +20,9 @@ export const matchesGroupQuery = (group, query, queryOptions = { handle: true, d
|
|
|
23
20
|
(queryOptions.description &&
|
|
24
21
|
group.description &&
|
|
25
22
|
containsIgnoreCase(group.description, query));
|
|
26
|
-
export const sortGroupMembers = (members) =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
export const groupMembershipHasRole = (roles, role) => (roles !== null && roles !== void 0 ? roles : []).includes(role);
|
|
31
|
-
export const actorIsGroupOwner = (profile, groupId) => {
|
|
32
|
-
var _a, _b;
|
|
33
|
-
return groupMembershipHasRole((_b = (_a = profile.memberships) === null || _a === void 0 ? void 0 : _a.find((m) => m.group.id === groupId)) === null || _b === void 0 ? void 0 : _b.roles, 'owner');
|
|
34
|
-
};
|
|
23
|
+
export const sortGroupMembers = (members) => members?.sort((a, b) => profileName(a.profile).localeCompare(profileName(b.profile))) ?? [];
|
|
24
|
+
export const groupMembershipHasRole = (roles, role) => (roles ?? []).includes(role);
|
|
25
|
+
export const actorIsGroupOwner = (profile, groupId) => groupMembershipHasRole(profile.memberships?.find((m) => m.group.id === groupId)?.roles, 'owner');
|
|
35
26
|
export const countGroupOwners = (members) => members.filter((m) => groupMembershipHasRole(m.roles, 'owner')).length;
|
|
36
27
|
export const groupRoleChangeBlocked = ({ actorIsOwner, currentRoles, nextRoles, ownerCount, }) => {
|
|
37
28
|
const wasOwner = groupMembershipHasRole(currentRoles, 'owner');
|
|
@@ -49,25 +40,13 @@ export const assignableGroupRoles = (actorIsOwner) => actorIsOwner
|
|
|
49
40
|
? [...defaultGroupRoles]
|
|
50
41
|
: defaultGroupRoles.filter((role) => role !== 'owner');
|
|
51
42
|
export const groupRolesForAssignment = (role) => (role === 'member' ? ['member'] : ['member', role]);
|
|
52
|
-
export const canChangeMemberRole = (profile, group) =>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
export const canAddMember = (profile, group) => {
|
|
57
|
-
var _a, _b, _c;
|
|
58
|
-
return checkCapabilities(['core-groups-addMember'], getGroupCapabilitiesByRoles((_c = (_b = (_a = profile.memberships) === null || _a === void 0 ? void 0 : _a.find((m) => m.group.id === group.id)) === null || _b === void 0 ? void 0 : _b.roles) !== null && _c !== void 0 ? _c : [], group)).success;
|
|
59
|
-
};
|
|
60
|
-
export const canRemoveMember = (profile, group) => {
|
|
61
|
-
var _a, _b, _c;
|
|
62
|
-
return checkCapabilities(['core-groups-removeMember'], getGroupCapabilitiesByRoles((_c = (_b = (_a = profile.memberships) === null || _a === void 0 ? void 0 : _a.find((m) => m.group.id === group.id)) === null || _b === void 0 ? void 0 : _b.roles) !== null && _c !== void 0 ? _c : [], group)).success;
|
|
63
|
-
};
|
|
43
|
+
export const canChangeMemberRole = (profile, group) => checkCapabilities(['core-groups-changeMemberRole'], getGroupCapabilitiesByRoles(profile.memberships?.find((m) => m.group.id === group.id)?.roles ?? [], group)).success;
|
|
44
|
+
export const canAddMember = (profile, group) => checkCapabilities(['core-groups-addMember'], getGroupCapabilitiesByRoles(profile.memberships?.find((m) => m.group.id === group.id)?.roles ?? [], group)).success;
|
|
45
|
+
export const canRemoveMember = (profile, group) => checkCapabilities(['core-groups-removeMember'], getGroupCapabilitiesByRoles(profile.memberships?.find((m) => m.group.id === group.id)?.roles ?? [], group)).success;
|
|
64
46
|
export const isGroupDiscoverable = (group) => checkCapabilities(['core-groups-read'], getGroupCapabilitiesByRoles(['none'], group)).success;
|
|
65
47
|
/** Posts are only readable by explicit group members (not public/local). */
|
|
66
|
-
export const hasMemberOnlyPostsVisibility = (capabilities) =>
|
|
67
|
-
|
|
68
|
-
return !((_b = (_a = capabilities === null || capabilities === void 0 ? void 0 : capabilities.none) === null || _a === void 0 ? void 0 : _a.add) === null || _b === void 0 ? void 0 : _b.includes('core-posts-read')) &&
|
|
69
|
-
!((_d = (_c = capabilities === null || capabilities === void 0 ? void 0 : capabilities.local) === null || _c === void 0 ? void 0 : _c.add) === null || _d === void 0 ? void 0 : _d.includes('core-posts-read'));
|
|
70
|
-
};
|
|
48
|
+
export const hasMemberOnlyPostsVisibility = (capabilities) => !capabilities?.none?.add?.includes('core-posts-read') &&
|
|
49
|
+
!capabilities?.local?.add?.includes('core-posts-read');
|
|
71
50
|
export const groupCapabilityTemplates = {
|
|
72
51
|
defaultGroup: {
|
|
73
52
|
name: 'defaultGroup',
|
|
@@ -14,19 +14,15 @@ const TEMPLATE_RELATIONSHIPS = [
|
|
|
14
14
|
'admin',
|
|
15
15
|
'owner',
|
|
16
16
|
];
|
|
17
|
-
const normalizeBucket = (bucket) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
remove: [...((_b = bucket === null || bucket === void 0 ? void 0 : bucket.remove) !== null && _b !== void 0 ? _b : [])].sort(),
|
|
22
|
-
});
|
|
23
|
-
};
|
|
17
|
+
const normalizeBucket = (bucket) => ({
|
|
18
|
+
add: [...(bucket?.add ?? [])].sort(),
|
|
19
|
+
remove: [...(bucket?.remove ?? [])].sort(),
|
|
20
|
+
});
|
|
24
21
|
export const normalizeGroupCapabilitiesForMatch = (capabilities) => {
|
|
25
|
-
var _a, _b;
|
|
26
22
|
const normalized = {};
|
|
27
23
|
for (const relationship of TEMPLATE_RELATIONSHIPS) {
|
|
28
|
-
const bucket = capabilities
|
|
29
|
-
if (!
|
|
24
|
+
const bucket = capabilities?.[relationship];
|
|
25
|
+
if (!bucket?.add?.length && !bucket?.remove?.length)
|
|
30
26
|
continue;
|
|
31
27
|
normalized[relationship] = normalizeBucket(bucket);
|
|
32
28
|
}
|
package/dist/lib/jamHelpers.js
CHANGED
|
@@ -2,9 +2,8 @@ import { normalizeRecurrenceId } from './eventRecurrence.js';
|
|
|
2
2
|
export const jamRoomName = (postId, _recurrenceId) => postId;
|
|
3
3
|
const UUID_PREFIX = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:_.*)?$/i;
|
|
4
4
|
export const postIdFromJamRoomName = (roomName) => {
|
|
5
|
-
var _a;
|
|
6
5
|
const match = roomName.match(UUID_PREFIX);
|
|
7
|
-
return
|
|
6
|
+
return match?.[1] ?? roomName;
|
|
8
7
|
};
|
|
9
8
|
/** Recurring jams use one LiveKit room per event; leftover occurrence rooms still collapse. */
|
|
10
9
|
export const uniquePostsById = (posts) => {
|
|
@@ -30,32 +29,30 @@ export const getJamUrl = (id, origin, occurrence) => {
|
|
|
30
29
|
return `${origin}/events/${id}/jam${query}`;
|
|
31
30
|
};
|
|
32
31
|
export const jamFromEvent = (event) => {
|
|
33
|
-
|
|
34
|
-
if (((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' && ((_b = event.data) === null || _b === void 0 ? void 0 : _b.jam)) {
|
|
32
|
+
if (event.data?.type === 'event' && event.data?.jam) {
|
|
35
33
|
return event.data.jam;
|
|
36
34
|
}
|
|
37
35
|
return undefined;
|
|
38
36
|
};
|
|
39
|
-
export const canModerateJam = (profile, post) =>
|
|
37
|
+
export const canModerateJam = (profile, post) => !!(profile && jamFromEvent(post)?.moderators?.includes(profile.id));
|
|
40
38
|
/** Host or jam moderator — same gate as the event Attendees tab. */
|
|
41
39
|
export const canViewJamAttendees = (profile, post) => !!(profile &&
|
|
42
40
|
(post.profile.id === profile.id || canModerateJam(profile, post)));
|
|
43
41
|
export const canAccessJamRecordings = (profile, post) => {
|
|
44
|
-
var _a, _b, _c, _d;
|
|
45
42
|
if (!profile) {
|
|
46
43
|
return false;
|
|
47
44
|
}
|
|
48
45
|
if (post.profile.id === profile.id) {
|
|
49
46
|
return true;
|
|
50
47
|
}
|
|
51
|
-
if (
|
|
48
|
+
if (post.data?.type !== 'event') {
|
|
52
49
|
return false;
|
|
53
50
|
}
|
|
54
51
|
const event = post.data;
|
|
55
|
-
if (
|
|
52
|
+
if (event.moderators?.includes(profile.id)) {
|
|
56
53
|
return true;
|
|
57
54
|
}
|
|
58
|
-
return !!
|
|
55
|
+
return !!event.jam?.moderators?.includes(profile.id);
|
|
59
56
|
};
|
|
60
57
|
export const jamRecordingAcceptsUpload = (status) => status === 'requested' || status === 'active' || status === 'finalizing';
|
|
61
58
|
export const isRtmpJamRecording = (recording) => recording.kind === 'rtmp';
|
|
@@ -10,12 +10,11 @@ const mentionSuffix = '(?=\\s|$|[.,!?;:])';
|
|
|
10
10
|
*/
|
|
11
11
|
export const linkProfileMentions = (source, mentions = []) => {
|
|
12
12
|
const aliases = mentions.flatMap(({ profile }) => {
|
|
13
|
-
|
|
14
|
-
const handle = (_a = profile.handle) === null || _a === void 0 ? void 0 : _a.trim();
|
|
13
|
+
const handle = profile.handle?.trim();
|
|
15
14
|
if (!handle)
|
|
16
15
|
return [];
|
|
17
16
|
const names = new Set([handle]);
|
|
18
|
-
const displayName =
|
|
17
|
+
const displayName = profile.displayName?.trim();
|
|
19
18
|
if (displayName)
|
|
20
19
|
names.add(displayName);
|
|
21
20
|
return [...names].map((name) => ({ name, handle }));
|
package/dist/lib/postHelpers.js
CHANGED
|
@@ -15,17 +15,15 @@ export const buildThreads = (posts) => posts
|
|
|
15
15
|
.filter((p) => !posts.find((p2) => p2.id === p.inReplyToId))
|
|
16
16
|
.map((post) => buildThread(post, posts))
|
|
17
17
|
.sort(dateSorter());
|
|
18
|
-
const parentIdOf = (post) =>
|
|
18
|
+
const parentIdOf = (post) => post.inReplyToId ?? post.replyTo?.id;
|
|
19
19
|
export const buildThreadPreview = (rootId, replies) => {
|
|
20
|
-
var _a;
|
|
21
20
|
const sorted = [...replies].sort((a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id));
|
|
22
21
|
if (!sorted.length)
|
|
23
22
|
return [];
|
|
24
23
|
const ids = new Set(sorted.map((post) => post.id));
|
|
25
24
|
const parent = new Map(sorted.map((post) => [post.id, post.id]));
|
|
26
25
|
const find = (id) => {
|
|
27
|
-
|
|
28
|
-
const current = (_a = parent.get(id)) !== null && _a !== void 0 ? _a : id;
|
|
26
|
+
const current = parent.get(id) ?? id;
|
|
29
27
|
if (current !== id) {
|
|
30
28
|
const root = find(current);
|
|
31
29
|
parent.set(id, root);
|
|
@@ -47,24 +45,23 @@ export const buildThreadPreview = (rootId, replies) => {
|
|
|
47
45
|
const grouped = new Map();
|
|
48
46
|
for (const post of sorted) {
|
|
49
47
|
const key = find(post.id);
|
|
50
|
-
const list =
|
|
48
|
+
const list = grouped.get(key) ?? [];
|
|
51
49
|
list.push(post);
|
|
52
50
|
grouped.set(key, list);
|
|
53
51
|
}
|
|
54
52
|
return [...grouped.values()]
|
|
55
53
|
.map((posts) => {
|
|
56
|
-
|
|
57
|
-
const start = (_a = posts.find((post) => {
|
|
54
|
+
const start = posts.find((post) => {
|
|
58
55
|
const parentId = parentIdOf(post);
|
|
59
56
|
return !parentId || !ids.has(parentId);
|
|
60
|
-
})
|
|
57
|
+
}) ?? posts[0];
|
|
61
58
|
const ordered = [];
|
|
62
59
|
const used = new Set();
|
|
63
60
|
let current = start;
|
|
64
61
|
while (current && !used.has(current.id)) {
|
|
65
62
|
ordered.push(current);
|
|
66
63
|
used.add(current.id);
|
|
67
|
-
current = posts.find((post) => parentIdOf(post) ===
|
|
64
|
+
current = posts.find((post) => parentIdOf(post) === current?.id && !used.has(post.id));
|
|
68
65
|
}
|
|
69
66
|
for (const post of posts) {
|
|
70
67
|
if (!used.has(post.id))
|
|
@@ -72,7 +69,7 @@ export const buildThreadPreview = (rootId, replies) => {
|
|
|
72
69
|
}
|
|
73
70
|
const startParentId = parentIdOf(start);
|
|
74
71
|
const ancestor = startParentId && startParentId !== rootId
|
|
75
|
-
? (
|
|
72
|
+
? (start.replyTo ?? undefined)
|
|
76
73
|
: undefined;
|
|
77
74
|
const skippedAncestor = !!(ancestor &&
|
|
78
75
|
ancestor.inReplyToId &&
|
|
@@ -80,9 +77,8 @@ export const buildThreadPreview = (rootId, replies) => {
|
|
|
80
77
|
return { skippedAncestor, ancestor, posts: ordered };
|
|
81
78
|
})
|
|
82
79
|
.sort((a, b) => {
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
const bKey = (_h = (_f = (_e = b.ancestor) === null || _e === void 0 ? void 0 : _e.createdAt) !== null && _f !== void 0 ? _f : (_g = b.posts[0]) === null || _g === void 0 ? void 0 : _g.createdAt) !== null && _h !== void 0 ? _h : '';
|
|
80
|
+
const aKey = a.ancestor?.createdAt ?? a.posts[0]?.createdAt ?? '';
|
|
81
|
+
const bKey = b.ancestor?.createdAt ?? b.posts[0]?.createdAt ?? '';
|
|
86
82
|
return aKey.localeCompare(bKey);
|
|
87
83
|
});
|
|
88
84
|
};
|
|
@@ -158,11 +154,8 @@ const latestRsvpPerProfile = (rsvps, recurrenceId) => {
|
|
|
158
154
|
export const calculateEffectiveRsvps = (post, recurrenceId) => latestRsvpPerProfile(post.rsvps || [], recurrenceId).filter((rsvp) => !!rsvp);
|
|
159
155
|
export const getEffectiveRsvp = (post, profileId, recurrenceId) => calculateEffectiveRsvps(post, recurrenceId).find((r) => r.profile.id === profileId);
|
|
160
156
|
export const countYesRsvps = (post, recurrenceId) => calculateEffectiveRsvps(post, recurrenceId).filter((r) => r.response === 'yes').length;
|
|
161
|
-
export const countSeriesYesRsvps = (post) =>
|
|
162
|
-
|
|
163
|
-
return ((_a = post.rsvps) !== null && _a !== void 0 ? _a : []).filter((r) => !r.recurrenceId && r.response === 'yes')
|
|
164
|
-
.length;
|
|
165
|
-
};
|
|
157
|
+
export const countSeriesYesRsvps = (post) => (post.rsvps ?? []).filter((r) => !r.recurrenceId && r.response === 'yes')
|
|
158
|
+
.length;
|
|
166
159
|
const attendingResponse = (response) => response === 'yes' || response === 'tentative';
|
|
167
160
|
/** Current roster: attending guests, plus organizer removals that can be restored. */
|
|
168
161
|
export const listedRsvps = (rsvps) => rsvps.filter((rsvp) => rsvp.response === 'yes' ||
|
|
@@ -177,24 +170,23 @@ export const isRsvpCancelNotice = (data) => {
|
|
|
177
170
|
notice.occurrenceIds.every((id) => typeof id === 'string'));
|
|
178
171
|
};
|
|
179
172
|
export const rsvpCancelNotice = (post, profileId, response, occurrenceIds) => {
|
|
180
|
-
var _a, _b;
|
|
181
173
|
if (response !== 'no')
|
|
182
174
|
return undefined;
|
|
183
|
-
const event =
|
|
175
|
+
const event = post.data?.type === 'event' ? post.data : undefined;
|
|
184
176
|
if (!event)
|
|
185
177
|
return undefined;
|
|
186
|
-
if (occurrenceIds
|
|
187
|
-
const canceled = occurrenceIds.filter((id) =>
|
|
178
|
+
if (occurrenceIds?.length) {
|
|
179
|
+
const canceled = occurrenceIds.filter((id) => attendingResponse(getEffectiveRsvp(post, profileId, id)?.response));
|
|
188
180
|
if (!canceled.length)
|
|
189
181
|
return undefined;
|
|
190
182
|
return { occurrenceIds: canceled, series: false };
|
|
191
183
|
}
|
|
192
|
-
if (attendingResponse(
|
|
184
|
+
if (attendingResponse(getEffectiveRsvp(post, profileId)?.response)) {
|
|
193
185
|
return { occurrenceIds: [], series: isRecurringEvent(event) };
|
|
194
186
|
}
|
|
195
187
|
if (!event.recurrence)
|
|
196
188
|
return undefined;
|
|
197
|
-
const canceled = instanceRsvpIdsForProfile(post, profileId).filter((id) =>
|
|
189
|
+
const canceled = instanceRsvpIdsForProfile(post, profileId).filter((id) => attendingResponse(getEffectiveRsvp(post, profileId, id)?.response));
|
|
198
190
|
if (!canceled.length)
|
|
199
191
|
return undefined;
|
|
200
192
|
return { occurrenceIds: canceled, series: false };
|
|
@@ -202,13 +194,12 @@ export const rsvpCancelNotice = (post, profileId, response, occurrenceIds) => {
|
|
|
202
194
|
const instanceRsvpKey = (profileId, recurrenceId) => `${profileId}|${normalizeRecurrenceId(recurrenceId)}`;
|
|
203
195
|
/** Attending → no transitions, newest first. Later re-RSVPs do not erase them. */
|
|
204
196
|
export const listRsvpCancellations = (post) => {
|
|
205
|
-
|
|
206
|
-
const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
|
|
197
|
+
const event = post.data?.type === 'event' ? post.data : undefined;
|
|
207
198
|
const recurring = event ? isRecurringEvent(event) : false;
|
|
208
199
|
const seriesResponse = new Map();
|
|
209
200
|
const instanceResponse = new Map();
|
|
210
201
|
const records = [];
|
|
211
|
-
for (const rsvp of [...(
|
|
202
|
+
for (const rsvp of [...(post.rsvps ?? [])].sort(dateSorter())) {
|
|
212
203
|
const profileId = rsvp.profile.id;
|
|
213
204
|
if (rsvp.response === 'no') {
|
|
214
205
|
if (rsvp.recurrenceId) {
|
|
@@ -243,8 +234,7 @@ export const listRsvpCancellations = (post) => {
|
|
|
243
234
|
return records.reverse();
|
|
244
235
|
};
|
|
245
236
|
export const rsvpCancelWhenLabels = (post, notice) => {
|
|
246
|
-
|
|
247
|
-
const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
|
|
237
|
+
const event = post.data?.type === 'event' ? post.data : undefined;
|
|
248
238
|
if (!event || notice.series)
|
|
249
239
|
return { series: notice.series, labels: [] };
|
|
250
240
|
const format = (start, end) => formatEventWhen(start, {
|
|
@@ -264,9 +254,8 @@ export const rsvpCancelWhenLabels = (post, notice) => {
|
|
|
264
254
|
};
|
|
265
255
|
};
|
|
266
256
|
export const instanceRsvpIdsForProfile = (post, profileId) => {
|
|
267
|
-
var _a;
|
|
268
257
|
const ids = new Set();
|
|
269
|
-
for (const rsvp of
|
|
258
|
+
for (const rsvp of post.rsvps ?? []) {
|
|
270
259
|
if (rsvp.profile.id !== profileId || !rsvp.recurrenceId)
|
|
271
260
|
continue;
|
|
272
261
|
ids.add(normalizeRecurrenceId(rsvp.recurrenceId));
|
|
@@ -278,9 +267,8 @@ export const overlaySeriesRsvpEntries = (response, instanceIds) => [
|
|
|
278
267
|
...instanceIds.map((recurrenceId) => ({ response, recurrenceId })),
|
|
279
268
|
];
|
|
280
269
|
export const seriesYesBlockedByCapacity = (post, profileId, now = new Date()) => {
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
const maxAttendees = event === null || event === void 0 ? void 0 : event.maxAttendees;
|
|
270
|
+
const event = post.data?.type === 'event' ? post.data : undefined;
|
|
271
|
+
const maxAttendees = event?.maxAttendees;
|
|
284
272
|
if (!event || !maxAttendees || !event.recurrence)
|
|
285
273
|
return false;
|
|
286
274
|
const occurrences = listRsvpOccurrences(event, now);
|
|
@@ -288,7 +276,7 @@ export const seriesYesBlockedByCapacity = (post, profileId, now = new Date()) =>
|
|
|
288
276
|
// occurrence started before `now`), fall back to the series-level count.
|
|
289
277
|
if (occurrences.length === 0) {
|
|
290
278
|
const current = getEffectiveRsvp(post, profileId);
|
|
291
|
-
if (
|
|
279
|
+
if (current?.response !== 'yes' &&
|
|
292
280
|
countSeriesYesRsvps(post) >= maxAttendees) {
|
|
293
281
|
return true;
|
|
294
282
|
}
|
|
@@ -296,27 +284,25 @@ export const seriesYesBlockedByCapacity = (post, profileId, now = new Date()) =>
|
|
|
296
284
|
}
|
|
297
285
|
return occurrences.some((occurrence) => {
|
|
298
286
|
const current = getEffectiveRsvp(post, profileId, occurrence.recurrenceId);
|
|
299
|
-
if (
|
|
287
|
+
if (current?.response === 'yes')
|
|
300
288
|
return false;
|
|
301
289
|
return countYesRsvps(post, occurrence.recurrenceId) >= maxAttendees;
|
|
302
290
|
});
|
|
303
291
|
};
|
|
304
292
|
export const occurrenceHasCapacity = (post, recurrenceId, profileId) => {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if (!(event === null || event === void 0 ? void 0 : event.maxAttendees))
|
|
293
|
+
const event = post.data?.type === 'event' ? post.data : undefined;
|
|
294
|
+
if (!event?.maxAttendees)
|
|
308
295
|
return true;
|
|
309
296
|
if (profileId) {
|
|
310
297
|
const current = getEffectiveRsvp(post, profileId, recurrenceId);
|
|
311
|
-
if (
|
|
298
|
+
if (current?.response === 'yes')
|
|
312
299
|
return true;
|
|
313
300
|
}
|
|
314
301
|
return countYesRsvps(post, recurrenceId) < event.maxAttendees;
|
|
315
302
|
};
|
|
316
303
|
/** Series Register stays enabled while any upcoming date still has a seat. */
|
|
317
304
|
export const recurringEventHasOpenOccurrence = (post, profileId, now = new Date()) => {
|
|
318
|
-
|
|
319
|
-
const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
|
|
305
|
+
const event = post.data?.type === 'event' ? post.data : undefined;
|
|
320
306
|
if (!event)
|
|
321
307
|
return false;
|
|
322
308
|
if (!event.recurrence) {
|
|
@@ -329,20 +315,19 @@ export const recurringEventHasOpenOccurrence = (post, profileId, now = new Date(
|
|
|
329
315
|
* then any attending instance so a partial RSVP still shows Cancel.
|
|
330
316
|
*/
|
|
331
317
|
export const displayRsvpForProfile = (post, profileId, options) => {
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
const scopedId = (options === null || options === void 0 ? void 0 : options.lockToOccurrence)
|
|
318
|
+
const event = post.data?.type === 'event' ? post.data : undefined;
|
|
319
|
+
const scopedId = options?.lockToOccurrence
|
|
335
320
|
? options.recurrenceId
|
|
336
321
|
: event
|
|
337
|
-
? defaultRsvpRecurrenceId(event, options
|
|
338
|
-
: options
|
|
322
|
+
? defaultRsvpRecurrenceId(event, options?.recurrenceId, options?.now)
|
|
323
|
+
: options?.recurrenceId;
|
|
339
324
|
const scoped = getEffectiveRsvp(post, profileId, scopedId);
|
|
340
|
-
if (options
|
|
325
|
+
if (options?.lockToOccurrence)
|
|
341
326
|
return scoped;
|
|
342
327
|
if (scoped && scoped.response !== 'no')
|
|
343
328
|
return scoped;
|
|
344
|
-
if (event
|
|
345
|
-
for (const occurrence of listRsvpOccurrences(event, options
|
|
329
|
+
if (event?.recurrence) {
|
|
330
|
+
for (const occurrence of listRsvpOccurrences(event, options?.now)) {
|
|
346
331
|
const instance = getEffectiveRsvp(post, profileId, occurrence.recurrenceId);
|
|
347
332
|
if (instance && instance.response !== 'no')
|
|
348
333
|
return instance;
|
|
@@ -380,7 +365,7 @@ export const normalizeEventDataFromDb = (event) => {
|
|
|
380
365
|
};
|
|
381
366
|
export const normalizePostDataFromDb = (data) => data.type === 'event' ? normalizeEventDataFromDb(data) : data;
|
|
382
367
|
export const eventDataForDbUpdate = (previous, normalized) => {
|
|
383
|
-
if (
|
|
368
|
+
if (previous?.maxAttendees != null && !('maxAttendees' in normalized)) {
|
|
384
369
|
return { ...normalized, maxAttendees: null };
|
|
385
370
|
}
|
|
386
371
|
return normalized;
|
|
@@ -388,19 +373,18 @@ export const eventDataForDbUpdate = (previous, normalized) => {
|
|
|
388
373
|
export const canManageEventRsvps = (profile, post) => !!(profile &&
|
|
389
374
|
(post.profile.id === profile.id || canModerateJam(profile, post)));
|
|
390
375
|
export const getJamCapacityJoinBlock = (post, profile, recurrenceId) => {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
if (!(event === null || event === void 0 ? void 0 : event.maxAttendees) || !(profile === null || profile === void 0 ? void 0 : profile.id)) {
|
|
376
|
+
const event = post.data?.type === 'event' ? post.data : undefined;
|
|
377
|
+
if (!event?.maxAttendees || !profile?.id) {
|
|
394
378
|
return { blocked: false };
|
|
395
379
|
}
|
|
396
380
|
if (canModerateJam(profile, post)) {
|
|
397
381
|
return { blocked: false };
|
|
398
382
|
}
|
|
399
383
|
const myRsvp = getEffectiveRsvp(post, profile.id, recurrenceId);
|
|
400
|
-
if (
|
|
384
|
+
if (myRsvp?.response === 'yes') {
|
|
401
385
|
return { blocked: false };
|
|
402
386
|
}
|
|
403
|
-
if (
|
|
387
|
+
if (myRsvp?.response === 'removed') {
|
|
404
388
|
return { blocked: true, reason: 'removed' };
|
|
405
389
|
}
|
|
406
390
|
if (countYesRsvps(post, recurrenceId) >= event.maxAttendees) {
|
|
@@ -409,40 +393,31 @@ export const getJamCapacityJoinBlock = (post, profile, recurrenceId) => {
|
|
|
409
393
|
return { blocked: true, reason: 'rsvp-required' };
|
|
410
394
|
};
|
|
411
395
|
export const canDeletePost = (authData, post, config) => checkPostCapabilities(authData, ['core-posts-delete'], post, config).success;
|
|
412
|
-
export const canCreatePost = (authData, type, visibility, group) =>
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
? canCreatePostTypeInAnyGroup(authData, type)
|
|
438
|
-
: checkRoleCapabilities((_a = authData.profile) === null || _a === void 0 ? void 0 : _a.roles, [
|
|
439
|
-
`core-posts-create-${type}-${visibility}`,
|
|
440
|
-
]).success &&
|
|
441
|
-
scopeMatches({
|
|
442
|
-
scopes: authData.scopes,
|
|
443
|
-
requiredScope: { scopeLevel: 'write', resource: { type: 'posts' } },
|
|
444
|
-
});
|
|
445
|
-
};
|
|
396
|
+
export const canCreatePost = (authData, type, visibility, group) => visibility === 'group'
|
|
397
|
+
? !!group &&
|
|
398
|
+
checkGroupCapabilities(authData, [`core-posts-create-${type}`], group)
|
|
399
|
+
.success
|
|
400
|
+
: checkRoleCapabilities(authData.profile?.roles, [
|
|
401
|
+
`core-posts-create-${type}-${visibility}`,
|
|
402
|
+
]).success &&
|
|
403
|
+
scopeMatches({
|
|
404
|
+
scopes: authData.scopes,
|
|
405
|
+
requiredScope: { scopeLevel: 'write', resource: { type: 'posts' } },
|
|
406
|
+
});
|
|
407
|
+
export const canCreatePostTypeInAnyGroup = (authData, type) => scopeMatches({
|
|
408
|
+
scopes: authData.scopes,
|
|
409
|
+
requiredScope: { scopeLevel: 'write', resource: { type: 'groups' } },
|
|
410
|
+
}) &&
|
|
411
|
+
!!authData.profile?.memberships?.some((m) => checkGroupCapabilities(authData, [`core-posts-create-${type}`], m.group).success);
|
|
412
|
+
export const canCreatePostTypeWithVisibility = (authData, type, visibility) => visibility === 'group'
|
|
413
|
+
? canCreatePostTypeInAnyGroup(authData, type)
|
|
414
|
+
: checkRoleCapabilities(authData.profile?.roles, [
|
|
415
|
+
`core-posts-create-${type}-${visibility}`,
|
|
416
|
+
]).success &&
|
|
417
|
+
scopeMatches({
|
|
418
|
+
scopes: authData.scopes,
|
|
419
|
+
requiredScope: { scopeLevel: 'write', resource: { type: 'posts' } },
|
|
420
|
+
});
|
|
446
421
|
export const canCreatePostType = (authData, type) => visibilityTypeValues.some((visibility) => canCreatePostTypeWithVisibility(authData, type, visibility));
|
|
447
422
|
/**
|
|
448
423
|
* Whether Reply / Repost / Like should look live. Non-members of a group
|
|
@@ -451,15 +426,14 @@ export const canCreatePostType = (authData, type) => visibilityTypeValues.some((
|
|
|
451
426
|
* and reposts need create-*, likes need core-posts-react.
|
|
452
427
|
*/
|
|
453
428
|
export const getPostActionAvailability = (authData, post, config) => {
|
|
454
|
-
var _a, _b, _c;
|
|
455
429
|
const isGroupPost = !!post.groupId || !!post.group;
|
|
456
|
-
const membershipExists = !!
|
|
430
|
+
const membershipExists = !!authData.profile?.memberships?.some((m) => m.group.id === post.group?.id || m.group.id === post.groupId);
|
|
457
431
|
if (isGroupPost && !membershipExists) {
|
|
458
432
|
return { canReply: false, canRepost: false, canReact: false };
|
|
459
433
|
}
|
|
460
434
|
const canReply = checkPostCapabilities(authData, ['core-posts-reply'], post, config)
|
|
461
435
|
.success &&
|
|
462
|
-
canCreatePost(authData, 'note', post.visibility,
|
|
436
|
+
canCreatePost(authData, 'note', post.visibility, post.group ?? undefined);
|
|
463
437
|
const canReact = checkPostCapabilities(authData, ['core-posts-react'], post, config).success;
|
|
464
438
|
const canRepost = post.group
|
|
465
439
|
? checkGroupCapabilities(authData, [`core-posts-create-${post.type}`], post.group).success
|
|
@@ -486,9 +460,8 @@ export const toHiddenPost = (post) => ({
|
|
|
486
460
|
});
|
|
487
461
|
export const isHiddenPost = (post) => !!post.hidden;
|
|
488
462
|
const participantIds = (post) => {
|
|
489
|
-
|
|
490
|
-
const
|
|
491
|
-
const creatorId = (_b = post.creatorId) !== null && _b !== void 0 ? _b : (_c = post.profile) === null || _c === void 0 ? void 0 : _c.id;
|
|
463
|
+
const ids = new Set((post.audience ?? []).map((member) => member.id).filter(Boolean));
|
|
464
|
+
const creatorId = post.creatorId ?? post.profile?.id;
|
|
492
465
|
if (creatorId)
|
|
493
466
|
ids.add(creatorId);
|
|
494
467
|
return ids;
|
|
@@ -496,7 +469,7 @@ const participantIds = (post) => {
|
|
|
496
469
|
export const isOneToOneWithBlocked = (post, viewer, blockedIds) => {
|
|
497
470
|
if (!viewer || post.visibility !== 'direct')
|
|
498
471
|
return false;
|
|
499
|
-
const blocked = blockedIds instanceof Set ? blockedIds : new Set(blockedIds
|
|
472
|
+
const blocked = blockedIds instanceof Set ? blockedIds : new Set(blockedIds ?? []);
|
|
500
473
|
if (!blocked.size)
|
|
501
474
|
return false;
|
|
502
475
|
const others = participantIds(post);
|
|
@@ -9,7 +9,7 @@ export const clampProfileDisplayName = (displayName) => {
|
|
|
9
9
|
const clamped = displayName.slice(0, PROFILE_DISPLAY_NAME_MAX_LENGTH);
|
|
10
10
|
return clamped || undefined;
|
|
11
11
|
};
|
|
12
|
-
export const isDeletedProfile = (profile) => !!
|
|
12
|
+
export const isDeletedProfile = (profile) => !!profile?.deletedAt;
|
|
13
13
|
/**
|
|
14
14
|
* Strip PII from a soft-deleted profile for public API / UI surfaces.
|
|
15
15
|
* Keeps id + timestamps (including deletedAt) so clients can detect the state.
|
|
@@ -68,7 +68,7 @@ export const toDeletedProfileWithMeta = (profile) => ({
|
|
|
68
68
|
export const tombstoneProfileWithMetaIfDeleted = (profile) => profile && isDeletedProfile(profile)
|
|
69
69
|
? toDeletedProfileWithMeta(profile)
|
|
70
70
|
: profile;
|
|
71
|
-
export const profileName = (profile) =>
|
|
71
|
+
export const profileName = (profile) => profile?.displayName || profile?.handle;
|
|
72
72
|
export const matchesQuery = (profile, query, queryOptions = { handle: true, displayName: true }) => !!(profile &&
|
|
73
73
|
(query.startsWith('@')
|
|
74
74
|
? profile.handle && containsIgnoreCase(profile.handle, query.substring(1))
|
|
@@ -81,7 +81,7 @@ export const matchesQuery = (profile, query, queryOptions = { handle: true, disp
|
|
|
81
81
|
export const inviteLinkMatchesQuery = (inviteLink, query, queryOptions = { handle: true, displayName: true, slug: true, group: true }) => {
|
|
82
82
|
const profile = inviteLink.profile;
|
|
83
83
|
if (query.startsWith('@')) {
|
|
84
|
-
return !!(
|
|
84
|
+
return !!(profile?.handle && containsIgnoreCase(profile.handle, query.substring(1)));
|
|
85
85
|
}
|
|
86
86
|
const groupMatches = queryOptions.group &&
|
|
87
87
|
inviteLink.groups.some((group) => containsIgnoreCase(group.handle, query) ||
|
|
@@ -98,31 +98,24 @@ export const inviteLinkMatchesQuery = (inviteLink, query, queryOptions = { handl
|
|
|
98
98
|
inviteLink.slug &&
|
|
99
99
|
containsIgnoreCase(inviteLink.slug, query)))));
|
|
100
100
|
};
|
|
101
|
-
export const sortProfiles = (profiles) =>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
export const isStripeActive = (sub) => (sub === null || sub === void 0 ? void 0 : sub.status) === 'active' || (sub === null || sub === void 0 ? void 0 : sub.status) === 'trialing';
|
|
106
|
-
export const getStripeCustomerId = (profileSettings) => { var _a; return (_a = profileSettings === null || profileSettings === void 0 ? void 0 : profileSettings.stripeSettings) === null || _a === void 0 ? void 0 : _a.customerId; };
|
|
101
|
+
export const sortProfiles = (profiles) => profiles?.sort((a, b) => profileName(a).localeCompare(profileName(b))) ?? [];
|
|
102
|
+
export const isStripeActive = (sub) => sub?.status === 'active' || sub?.status === 'trialing';
|
|
103
|
+
export const getStripeCustomerId = (profileSettings) => profileSettings?.stripeSettings?.customerId;
|
|
107
104
|
export const isOwnerProfile = (profile) => {
|
|
108
|
-
return profile
|
|
109
|
-
};
|
|
110
|
-
export const blockedPairIds = (profile) => {
|
|
111
|
-
var _a, _b;
|
|
112
|
-
return [
|
|
113
|
-
...new Set([
|
|
114
|
-
...((_a = profile === null || profile === void 0 ? void 0 : profile.blockingIds) !== null && _a !== void 0 ? _a : []),
|
|
115
|
-
...((_b = profile === null || profile === void 0 ? void 0 : profile.blockedByIds) !== null && _b !== void 0 ? _b : []),
|
|
116
|
-
]),
|
|
117
|
-
];
|
|
105
|
+
return profile?.roles.some((role) => role.key === 'owner');
|
|
118
106
|
};
|
|
107
|
+
export const blockedPairIds = (profile) => [
|
|
108
|
+
...new Set([
|
|
109
|
+
...(profile?.blockingIds ?? []),
|
|
110
|
+
...(profile?.blockedByIds ?? []),
|
|
111
|
+
]),
|
|
112
|
+
];
|
|
119
113
|
export const isBlockedPair = (profile, otherId) => !!otherId && blockedPairIds(profile).includes(otherId);
|
|
120
|
-
export const viewerBlockedTarget = (profile, otherId) =>
|
|
121
|
-
export const targetBlockedViewer = (profile, otherId) =>
|
|
114
|
+
export const viewerBlockedTarget = (profile, otherId) => !!otherId && (profile?.blockingIds ?? []).includes(otherId);
|
|
115
|
+
export const targetBlockedViewer = (profile, otherId) => !!otherId && (profile?.blockedByIds ?? []).includes(otherId);
|
|
122
116
|
export const sharesControllingAccount = (a, b) => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return ((_b = a.controllers) !== null && _b !== void 0 ? _b : []).some((account) => otherIds.has(account.id));
|
|
117
|
+
const otherIds = new Set((b.controllers ?? []).map((account) => account.id));
|
|
118
|
+
return (a.controllers ?? []).some((account) => otherIds.has(account.id));
|
|
126
119
|
};
|
|
127
120
|
export const toBlockedProfileStub = (profile) => ({
|
|
128
121
|
id: profile.id,
|
package/dist/lib/pushHelpers.js
CHANGED
|
@@ -13,7 +13,6 @@ export const pushSubscriptionDeliveryKey = (subscription) => {
|
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
export const pushSubscriptionEndpoint = (subscription) => 'endpoint' in subscription ? subscription.endpoint : undefined;
|
|
16
|
-
export const pushSubscriptionIsMobile = (subscription) =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
16
|
+
export const pushSubscriptionIsMobile = (subscription) => pushSubscriptionDeviceName(subscription)
|
|
17
|
+
?.toLowerCase()
|
|
18
|
+
.match(/phone|android|mobile|ios/) != null;
|