@openpeepshq/common 0.1.43 → 0.1.45
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 +7 -7
- package/dist/lib/capabilitiesHelpers.js +4 -11
- package/dist/lib/eventIcs.js +56 -2
- package/dist/lib/eventRecurrence.d.ts +30 -0
- package/dist/lib/eventRecurrence.js +279 -0
- package/dist/lib/eventTime.d.ts +22 -0
- package/dist/lib/eventTime.js +127 -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 +5 -0
- package/dist/lib/index.js +5 -0
- package/dist/lib/jamHelpers.d.ts +28 -2
- package/dist/lib/jamHelpers.js +56 -8
- package/dist/lib/markdownHelpers.d.ts +14 -0
- package/dist/lib/markdownHelpers.js +41 -0
- package/dist/lib/postHelpers.d.ts +24 -6
- package/dist/lib/postHelpers.js +79 -21
- package/dist/lib/profileHelpers.d.ts +11 -0
- package/dist/lib/profileHelpers.js +29 -0
- package/dist/lib/pushHelpers.d.ts +3 -1
- package/dist/lib/pushHelpers.js +13 -0
- package/dist/lib/reportHelpers.d.ts +2 -0
- package/dist/lib/reportHelpers.js +2 -0
- package/dist/lib/ssoLoginUrl.d.ts +24 -0
- package/dist/lib/ssoLoginUrl.js +75 -0
- package/dist/lib/text.d.ts +2 -0
- package/dist/lib/text.js +2 -0
- package/dist/lib/tokenHelpers.d.ts +5 -0
- package/dist/lib/tokenHelpers.js +19 -0
- package/dist/lib/utils.d.ts +4 -0
- package/dist/types/analytics.d.ts +86 -0
- package/dist/types/analytics.js +21 -0
- package/dist/types/api.d.ts +2392 -355
- package/dist/types/api.js +44 -18
- package/dist/types/auth.d.ts +2 -7
- package/dist/types/capabilities.d.ts +11 -4
- package/dist/types/capabilities.js +44 -1
- package/dist/types/config.d.ts +50 -24
- package/dist/types/config.js +28 -15
- package/dist/types/db.d.ts +738 -66
- package/dist/types/db.js +3 -3
- package/dist/types/internal.d.ts +6189 -2604
- package/dist/types/internal.js +10 -1
- package/dist/types/models.d.ts +280 -9
- package/dist/types/models.js +59 -5
- package/dist/types/notifications.d.ts +39 -1
- package/dist/types/notifications.js +12 -0
- package/dist/types/plugins.d.ts +21 -1
- package/dist/types/plugins.js +9 -1
- package/dist/types/stats.d.ts +1284 -184
- package/package.json +1 -1
|
@@ -1 +1,15 @@
|
|
|
1
|
+
export type MentionProfileRef = {
|
|
2
|
+
profile: {
|
|
3
|
+
handle?: string | null;
|
|
4
|
+
displayName?: string | null;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Turn `@handle` / known `@displayName` into markdown profile links.
|
|
9
|
+
* Display names are matched exactly (longest first) so apostrophes and other
|
|
10
|
+
* non-letter characters still count when that profile is in `mentions`.
|
|
11
|
+
* Bare `@handle` tokens use the allowed handle charset (letters, digits, `_`, `-`).
|
|
12
|
+
*/
|
|
13
|
+
export declare const linkProfileMentions: (source: string, mentions?: MentionProfileRef[]) => string;
|
|
14
|
+
export declare const matchMentionHandles: (text?: string | null) => string[];
|
|
1
15
|
export declare const firstNWords: (markdown: string | undefined, n: number) => string;
|
|
@@ -1,3 +1,44 @@
|
|
|
1
|
+
import { mentionHandleRegexBase } from '../types/index.js';
|
|
2
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3
|
+
const mentionPrefix = '(^|[\\s(>])';
|
|
4
|
+
const mentionSuffix = '(?=\\s|$|[.,!?;:])';
|
|
5
|
+
/**
|
|
6
|
+
* Turn `@handle` / known `@displayName` into markdown profile links.
|
|
7
|
+
* Display names are matched exactly (longest first) so apostrophes and other
|
|
8
|
+
* non-letter characters still count when that profile is in `mentions`.
|
|
9
|
+
* Bare `@handle` tokens use the allowed handle charset (letters, digits, `_`, `-`).
|
|
10
|
+
*/
|
|
11
|
+
export const linkProfileMentions = (source, mentions = []) => {
|
|
12
|
+
const aliases = mentions.flatMap(({ profile }) => {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
const handle = (_a = profile.handle) === null || _a === void 0 ? void 0 : _a.trim();
|
|
15
|
+
if (!handle)
|
|
16
|
+
return [];
|
|
17
|
+
const names = new Set([handle]);
|
|
18
|
+
const displayName = (_b = profile.displayName) === null || _b === void 0 ? void 0 : _b.trim();
|
|
19
|
+
if (displayName)
|
|
20
|
+
names.add(displayName);
|
|
21
|
+
return [...names].map((name) => ({ name, handle }));
|
|
22
|
+
});
|
|
23
|
+
aliases.sort((a, b) => b.name.length - a.name.length);
|
|
24
|
+
let text = source;
|
|
25
|
+
for (const { name, handle } of aliases) {
|
|
26
|
+
const pattern = new RegExp(`${mentionPrefix}@(${escapeRegExp(name)})${mentionSuffix}`, 'gi');
|
|
27
|
+
text = text.replace(pattern, (_full, prefix, mentioned) => `${prefix}[@${mentioned}](/@${handle})`);
|
|
28
|
+
}
|
|
29
|
+
return text.replace(new RegExp(mentionHandleRegexBase, 'g'), (_full, prefix, handle) => `${prefix}[@${handle}](/@${handle})`);
|
|
30
|
+
};
|
|
31
|
+
export const matchMentionHandles = (text) => {
|
|
32
|
+
if (!text)
|
|
33
|
+
return [];
|
|
34
|
+
const handles = new Set();
|
|
35
|
+
for (const match of text.matchAll(new RegExp(mentionHandleRegexBase, 'g'))) {
|
|
36
|
+
const handle = match[2];
|
|
37
|
+
if (handle)
|
|
38
|
+
handles.add(handle);
|
|
39
|
+
}
|
|
40
|
+
return [...handles];
|
|
41
|
+
};
|
|
1
42
|
export const firstNWords = (markdown, n) => {
|
|
2
43
|
if (!markdown)
|
|
3
44
|
return '';
|
|
@@ -2,11 +2,15 @@ import { Answer, AnswerWithPublicProfile, AuthorizationData, CapabilitiesConfig,
|
|
|
2
2
|
export declare const buildThreads: (posts: PublicPost[]) => Thread[];
|
|
3
3
|
export declare const getReactionCount: (post: PublicPost) => Record<"👍", number>;
|
|
4
4
|
export declare const countVotes: (optionsCount: number, answers: Answer[]) => number[];
|
|
5
|
+
/** Fill blank poll choices with their placeholder label (e.g. "Option 1"). */
|
|
6
|
+
export declare const resolvePollOptionContents: (options: readonly string[], fallbackLabel: (index: number) => string) => string[];
|
|
7
|
+
/** Longer choices are rejected by `questionSchema`, so block submit instead. */
|
|
8
|
+
export declare const pollOptionsWithinLimit: (options: readonly string[]) => boolean;
|
|
5
9
|
export declare const collectVotes: (post: PublicPost) => {
|
|
6
10
|
voteCounts: number[];
|
|
7
11
|
votes: AnswerWithPublicProfile[];
|
|
8
12
|
};
|
|
9
|
-
export declare const calculateEffectiveRsvps: (post: PublicPost) => {
|
|
13
|
+
export declare const calculateEffectiveRsvps: (post: PublicPost, recurrenceId?: string) => {
|
|
10
14
|
response: "no" | "yes" | "tentative" | "removed";
|
|
11
15
|
profile: {
|
|
12
16
|
id: string;
|
|
@@ -33,7 +37,7 @@ export declare const calculateEffectiveRsvps: (post: PublicPost) => {
|
|
|
33
37
|
discoverable?: boolean | undefined;
|
|
34
38
|
deletedAt?: string | null | undefined;
|
|
35
39
|
};
|
|
36
|
-
roles?: ("none" | "local" | "member" | "admin" | "
|
|
40
|
+
roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
|
|
37
41
|
}[] | undefined;
|
|
38
42
|
deletedAt?: string | null | undefined;
|
|
39
43
|
avatar?: string | null | undefined;
|
|
@@ -61,8 +65,9 @@ export declare const calculateEffectiveRsvps: (post: PublicPost) => {
|
|
|
61
65
|
} | undefined;
|
|
62
66
|
};
|
|
63
67
|
createdAt: string;
|
|
68
|
+
recurrenceId?: string | undefined;
|
|
64
69
|
}[];
|
|
65
|
-
export declare const getEffectiveRsvp: (post: PublicPost, profileId: string) => {
|
|
70
|
+
export declare const getEffectiveRsvp: (post: PublicPost, profileId: string, recurrenceId?: string) => {
|
|
66
71
|
response: "no" | "yes" | "tentative" | "removed";
|
|
67
72
|
profile: {
|
|
68
73
|
id: string;
|
|
@@ -89,7 +94,7 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string) =>
|
|
|
89
94
|
discoverable?: boolean | undefined;
|
|
90
95
|
deletedAt?: string | null | undefined;
|
|
91
96
|
};
|
|
92
|
-
roles?: ("none" | "local" | "member" | "admin" | "
|
|
97
|
+
roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
|
|
93
98
|
}[] | undefined;
|
|
94
99
|
deletedAt?: string | null | undefined;
|
|
95
100
|
avatar?: string | null | undefined;
|
|
@@ -117,8 +122,9 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string) =>
|
|
|
117
122
|
} | undefined;
|
|
118
123
|
};
|
|
119
124
|
createdAt: string;
|
|
125
|
+
recurrenceId?: string | undefined;
|
|
120
126
|
} | undefined;
|
|
121
|
-
export declare const countYesRsvps: (post: PublicPost) => number;
|
|
127
|
+
export declare const countYesRsvps: (post: PublicPost, recurrenceId?: string) => number;
|
|
122
128
|
export declare const isCapacityEvent: (event: Event) => boolean;
|
|
123
129
|
export declare const parseEventMaxAttendeesInput: (raw: string) => number | undefined;
|
|
124
130
|
export declare const withoutEventMaxAttendees: <T extends Event>(event: T) => T;
|
|
@@ -138,9 +144,21 @@ export type JamCapacityJoinBlock = {
|
|
|
138
144
|
blocked: true;
|
|
139
145
|
reason: 'full' | 'rsvp-required' | 'removed';
|
|
140
146
|
};
|
|
141
|
-
export declare const getJamCapacityJoinBlock: (post: PublicPost, profile: Pick<PublicProfile, "id"> | undefined) => JamCapacityJoinBlock;
|
|
147
|
+
export declare const getJamCapacityJoinBlock: (post: PublicPost, profile: Pick<PublicProfile, "id"> | undefined, recurrenceId?: string) => JamCapacityJoinBlock;
|
|
142
148
|
export declare const canDeletePost: (authData: AuthorizationData, post: PublicPost, config: CapabilitiesConfig) => boolean;
|
|
143
149
|
export declare const canCreatePost: (authData: AuthorizationData, type: PostType, visibility: VisibilityType, group?: GroupWithMeta) => boolean;
|
|
144
150
|
export declare const canCreatePostTypeInAnyGroup: (authData: AuthorizationData, type: PostType) => boolean;
|
|
145
151
|
export declare const canCreatePostTypeWithVisibility: (authData: AuthorizationData, type: PostType, visibility: VisibilityType) => boolean;
|
|
146
152
|
export declare const canCreatePostType: (authData: AuthorizationData, type: PostType) => boolean;
|
|
153
|
+
export type PostActionAvailability = {
|
|
154
|
+
canReply: boolean;
|
|
155
|
+
canRepost: boolean;
|
|
156
|
+
canReact: boolean;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Whether Reply / Repost / Like should look live. Non-members of a group
|
|
160
|
+
* post stay fully disabled (existing feed rule). Each action also follows
|
|
161
|
+
* the capability the matching write endpoint actually checks: feed replies
|
|
162
|
+
* and reposts need create-*, likes need core-posts-react.
|
|
163
|
+
*/
|
|
164
|
+
export declare const getPostActionAvailability: (authData: AuthorizationData, post: PublicPost, config: CapabilitiesConfig) => PostActionAvailability;
|
package/dist/lib/postHelpers.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { visibilityTypeValues, } from '../types/index.js';
|
|
1
|
+
import { POLL_OPTION_MAX_LENGTH, visibilityTypeValues, } from '../types/index.js';
|
|
2
2
|
import { canModerateJam } from './jamHelpers.js';
|
|
3
|
+
import { sameRecurrenceId } from './eventRecurrence.js';
|
|
3
4
|
import { checkGroupCapabilities, checkPostCapabilities, checkRoleCapabilities, } from './capabilitiesHelpers.js';
|
|
4
5
|
import { scopeMatches } from './scopeHelpers.js';
|
|
5
6
|
import { countBy, dateSorter, groupBy, transformValues } from './utils.js';
|
|
@@ -27,6 +28,13 @@ export const countVotes = (optionsCount, answers) => {
|
|
|
27
28
|
}
|
|
28
29
|
return voteCounts;
|
|
29
30
|
};
|
|
31
|
+
/** Fill blank poll choices with their placeholder label (e.g. "Option 1"). */
|
|
32
|
+
export const resolvePollOptionContents = (options, fallbackLabel) => options.map((text, index) => {
|
|
33
|
+
const trimmed = text.trim();
|
|
34
|
+
return trimmed.length > 0 ? trimmed : fallbackLabel(index);
|
|
35
|
+
});
|
|
36
|
+
/** Longer choices are rejected by `questionSchema`, so block submit instead. */
|
|
37
|
+
export const pollOptionsWithinLimit = (options) => options.every((text) => text.trim().length <= POLL_OPTION_MAX_LENGTH);
|
|
30
38
|
export const collectVotes = (post) => {
|
|
31
39
|
if (post.type !== 'question') {
|
|
32
40
|
return {
|
|
@@ -52,16 +60,30 @@ export const collectVotes = (post) => {
|
|
|
52
60
|
voteCounts,
|
|
53
61
|
};
|
|
54
62
|
};
|
|
55
|
-
const latestRsvpPerProfile = (rsvps) => {
|
|
56
|
-
const
|
|
63
|
+
const latestRsvpPerProfile = (rsvps, recurrenceId) => {
|
|
64
|
+
const scoped = rsvps.filter((rsvp) => {
|
|
65
|
+
if (recurrenceId) {
|
|
66
|
+
if (rsvp.recurrenceId) {
|
|
67
|
+
return sameRecurrenceId(rsvp.recurrenceId, recurrenceId);
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
return !rsvp.recurrenceId;
|
|
72
|
+
});
|
|
73
|
+
const rsvpsByProfile = groupBy(scoped, (r) => r.profile.id);
|
|
57
74
|
return Object.values(rsvpsByProfile).map((profileRsvps) => {
|
|
58
|
-
const
|
|
75
|
+
const instanceRsvps = recurrenceId
|
|
76
|
+
? profileRsvps.filter((rsvp) => sameRecurrenceId(rsvp.recurrenceId, recurrenceId))
|
|
77
|
+
: [];
|
|
78
|
+
const seriesRsvps = profileRsvps.filter((rsvp) => !rsvp.recurrenceId);
|
|
79
|
+
const pool = recurrenceId && instanceRsvps.length > 0 ? instanceRsvps : seriesRsvps;
|
|
80
|
+
const sorted = pool.sort(dateSorter());
|
|
59
81
|
return sorted[sorted.length - 1];
|
|
60
82
|
});
|
|
61
83
|
};
|
|
62
|
-
export const calculateEffectiveRsvps = (post) => latestRsvpPerProfile(post.rsvps || []);
|
|
63
|
-
export const getEffectiveRsvp = (post, profileId) => calculateEffectiveRsvps(post).find((r) => r.profile.id === profileId);
|
|
64
|
-
export const countYesRsvps = (post) => calculateEffectiveRsvps(post).filter((r) => r.response === 'yes').length;
|
|
84
|
+
export const calculateEffectiveRsvps = (post, recurrenceId) => latestRsvpPerProfile(post.rsvps || [], recurrenceId).filter((rsvp) => !!rsvp);
|
|
85
|
+
export const getEffectiveRsvp = (post, profileId, recurrenceId) => calculateEffectiveRsvps(post, recurrenceId).find((r) => r.profile.id === profileId);
|
|
86
|
+
export const countYesRsvps = (post, recurrenceId) => calculateEffectiveRsvps(post, recurrenceId).filter((r) => r.response === 'yes').length;
|
|
65
87
|
export const isCapacityEvent = (event) => !!event.maxAttendees;
|
|
66
88
|
export const parseEventMaxAttendeesInput = (raw) => {
|
|
67
89
|
const trimmed = raw.trim();
|
|
@@ -92,15 +114,14 @@ export const normalizeEventDataFromDb = (event) => {
|
|
|
92
114
|
};
|
|
93
115
|
export const normalizePostDataFromDb = (data) => data.type === 'event' ? normalizeEventDataFromDb(data) : data;
|
|
94
116
|
export const eventDataForDbUpdate = (previous, normalized) => {
|
|
95
|
-
if ((previous === null || previous === void 0 ? void 0 : previous.maxAttendees) != null &&
|
|
96
|
-
!('maxAttendees' in normalized)) {
|
|
117
|
+
if ((previous === null || previous === void 0 ? void 0 : previous.maxAttendees) != null && !('maxAttendees' in normalized)) {
|
|
97
118
|
return { ...normalized, maxAttendees: null };
|
|
98
119
|
}
|
|
99
120
|
return normalized;
|
|
100
121
|
};
|
|
101
122
|
export const canManageEventRsvps = (profile, post) => !!(profile &&
|
|
102
123
|
(post.profile.id === profile.id || canModerateJam(profile, post)));
|
|
103
|
-
export const getJamCapacityJoinBlock = (post, profile) => {
|
|
124
|
+
export const getJamCapacityJoinBlock = (post, profile, recurrenceId) => {
|
|
104
125
|
var _a;
|
|
105
126
|
const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
|
|
106
127
|
if (!(event === null || event === void 0 ? void 0 : event.maxAttendees) || !(profile === null || profile === void 0 ? void 0 : profile.id)) {
|
|
@@ -109,14 +130,14 @@ export const getJamCapacityJoinBlock = (post, profile) => {
|
|
|
109
130
|
if (canModerateJam(profile, post)) {
|
|
110
131
|
return { blocked: false };
|
|
111
132
|
}
|
|
112
|
-
const myRsvp = getEffectiveRsvp(post, profile.id);
|
|
133
|
+
const myRsvp = getEffectiveRsvp(post, profile.id, recurrenceId);
|
|
113
134
|
if ((myRsvp === null || myRsvp === void 0 ? void 0 : myRsvp.response) === 'yes') {
|
|
114
135
|
return { blocked: false };
|
|
115
136
|
}
|
|
116
137
|
if ((myRsvp === null || myRsvp === void 0 ? void 0 : myRsvp.response) === 'removed') {
|
|
117
138
|
return { blocked: true, reason: 'removed' };
|
|
118
139
|
}
|
|
119
|
-
if (countYesRsvps(post) >= event.maxAttendees) {
|
|
140
|
+
if (countYesRsvps(post, recurrenceId) >= event.maxAttendees) {
|
|
120
141
|
return { blocked: true, reason: 'full' };
|
|
121
142
|
}
|
|
122
143
|
return { blocked: true, reason: 'rsvp-required' };
|
|
@@ -124,21 +145,58 @@ export const getJamCapacityJoinBlock = (post, profile) => {
|
|
|
124
145
|
export const canDeletePost = (authData, post, config) => checkPostCapabilities(authData, ['core-posts-delete'], post, config).success;
|
|
125
146
|
export const canCreatePost = (authData, type, visibility, group) => {
|
|
126
147
|
var _a;
|
|
127
|
-
return visibility === 'group'
|
|
128
|
-
!!group &&
|
|
129
|
-
|
|
130
|
-
|
|
148
|
+
return visibility === 'group'
|
|
149
|
+
? !!group &&
|
|
150
|
+
checkGroupCapabilities(authData, [`core-posts-create-${type}`], group)
|
|
151
|
+
.success
|
|
152
|
+
: checkRoleCapabilities((_a = authData.profile) === null || _a === void 0 ? void 0 : _a.roles, [
|
|
153
|
+
`core-posts-create-${type}-${visibility}`,
|
|
154
|
+
]).success &&
|
|
155
|
+
scopeMatches({
|
|
156
|
+
scopes: authData.scopes,
|
|
157
|
+
requiredScope: { scopeLevel: 'write', resource: { type: 'posts' } },
|
|
158
|
+
});
|
|
131
159
|
};
|
|
132
160
|
export const canCreatePostTypeInAnyGroup = (authData, type) => {
|
|
133
161
|
var _a, _b;
|
|
134
|
-
return scopeMatches({
|
|
162
|
+
return scopeMatches({
|
|
163
|
+
scopes: authData.scopes,
|
|
164
|
+
requiredScope: { scopeLevel: 'write', resource: { type: 'groups' } },
|
|
165
|
+
}) &&
|
|
135
166
|
!!((_b = (_a = authData.profile) === null || _a === void 0 ? void 0 : _a.memberships) === null || _b === void 0 ? void 0 : _b.some((m) => checkGroupCapabilities(authData, [`core-posts-create-${type}`], m.group).success));
|
|
136
167
|
};
|
|
137
168
|
export const canCreatePostTypeWithVisibility = (authData, type, visibility) => {
|
|
138
169
|
var _a;
|
|
139
|
-
return visibility === 'group'
|
|
140
|
-
canCreatePostTypeInAnyGroup(authData, type)
|
|
141
|
-
checkRoleCapabilities((_a = authData.profile) === null || _a === void 0 ? void 0 : _a.roles, [
|
|
142
|
-
|
|
170
|
+
return visibility === 'group'
|
|
171
|
+
? canCreatePostTypeInAnyGroup(authData, type)
|
|
172
|
+
: checkRoleCapabilities((_a = authData.profile) === null || _a === void 0 ? void 0 : _a.roles, [
|
|
173
|
+
`core-posts-create-${type}-${visibility}`,
|
|
174
|
+
]).success &&
|
|
175
|
+
scopeMatches({
|
|
176
|
+
scopes: authData.scopes,
|
|
177
|
+
requiredScope: { scopeLevel: 'write', resource: { type: 'posts' } },
|
|
178
|
+
});
|
|
143
179
|
};
|
|
144
180
|
export const canCreatePostType = (authData, type) => visibilityTypeValues.some((visibility) => canCreatePostTypeWithVisibility(authData, type, visibility));
|
|
181
|
+
/**
|
|
182
|
+
* Whether Reply / Repost / Like should look live. Non-members of a group
|
|
183
|
+
* post stay fully disabled (existing feed rule). Each action also follows
|
|
184
|
+
* the capability the matching write endpoint actually checks: feed replies
|
|
185
|
+
* and reposts need create-*, likes need core-posts-react.
|
|
186
|
+
*/
|
|
187
|
+
export const getPostActionAvailability = (authData, post, config) => {
|
|
188
|
+
var _a, _b, _c;
|
|
189
|
+
const isGroupPost = !!post.groupId || !!post.group;
|
|
190
|
+
const membershipExists = !!((_b = (_a = authData.profile) === null || _a === void 0 ? void 0 : _a.memberships) === null || _b === void 0 ? void 0 : _b.some((m) => { var _a; return m.group.id === ((_a = post.group) === null || _a === void 0 ? void 0 : _a.id) || m.group.id === post.groupId; }));
|
|
191
|
+
if (isGroupPost && !membershipExists) {
|
|
192
|
+
return { canReply: false, canRepost: false, canReact: false };
|
|
193
|
+
}
|
|
194
|
+
const canReply = checkPostCapabilities(authData, ['core-posts-reply'], post, config)
|
|
195
|
+
.success &&
|
|
196
|
+
canCreatePost(authData, 'note', post.visibility, (_c = post.group) !== null && _c !== void 0 ? _c : undefined);
|
|
197
|
+
const canReact = checkPostCapabilities(authData, ['core-posts-react'], post, config).success;
|
|
198
|
+
const canRepost = post.group
|
|
199
|
+
? checkGroupCapabilities(authData, [`core-posts-create-${post.type}`], post.group).success
|
|
200
|
+
: canCreatePost(authData, post.type, post.visibility);
|
|
201
|
+
return { canReply, canRepost, canReact };
|
|
202
|
+
};
|
|
@@ -13,6 +13,17 @@ export declare const isDeletedProfile: (profile: {
|
|
|
13
13
|
*/
|
|
14
14
|
export declare const toPublicDeletedProfile: <T extends PublicProfile>(profile: T) => T;
|
|
15
15
|
export declare const anonymizeProfileIfDeleted: <T extends PublicProfile>(profile: T | undefined | null) => T | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Tombstone for internal `ProfileWithMeta` surfaces (e.g. moderation reports).
|
|
18
|
+
* Built explicitly rather than by spreading the original so no PII of the
|
|
19
|
+
* deleted account (email/controllers, social graph, time zone, guest data)
|
|
20
|
+
* can leak, while still satisfying `profileWithMetaSchema` — unlike
|
|
21
|
+
* {@link toPublicDeletedProfile}, whose stripped shape is only valid for the
|
|
22
|
+
* looser `publicProfileSchema`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const toDeletedProfileWithMeta: (profile: ProfileWithMeta) => ProfileWithMeta;
|
|
25
|
+
/** Tombstone a `ProfileWithMeta` only when it is soft-deleted. */
|
|
26
|
+
export declare const tombstoneProfileWithMetaIfDeleted: (profile: ProfileWithMeta | undefined) => ProfileWithMeta | undefined;
|
|
16
27
|
export declare const profileName: (profile?: PublicProfile) => string | undefined;
|
|
17
28
|
export declare const matchesQuery: (profile: PublicProfile | GroupWithMeta | undefined, query: string, queryOptions?: {
|
|
18
29
|
handle: boolean;
|
|
@@ -34,6 +34,35 @@ export const anonymizeProfileIfDeleted = (profile) => {
|
|
|
34
34
|
return undefined;
|
|
35
35
|
return isDeletedProfile(profile) ? toPublicDeletedProfile(profile) : profile;
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Tombstone for internal `ProfileWithMeta` surfaces (e.g. moderation reports).
|
|
39
|
+
* Built explicitly rather than by spreading the original so no PII of the
|
|
40
|
+
* deleted account (email/controllers, social graph, time zone, guest data)
|
|
41
|
+
* can leak, while still satisfying `profileWithMetaSchema` — unlike
|
|
42
|
+
* {@link toPublicDeletedProfile}, whose stripped shape is only valid for the
|
|
43
|
+
* looser `publicProfileSchema`.
|
|
44
|
+
*/
|
|
45
|
+
export const toDeletedProfileWithMeta = (profile) => ({
|
|
46
|
+
id: profile.id,
|
|
47
|
+
type: profile.type,
|
|
48
|
+
createdAt: profile.createdAt,
|
|
49
|
+
updatedAt: profile.updatedAt,
|
|
50
|
+
deletedAt: profile.deletedAt,
|
|
51
|
+
handle: DELETED_AUTHOR_HANDLE,
|
|
52
|
+
displayName: DELETED_AUTHOR_DISPLAY_NAME,
|
|
53
|
+
avatar: null,
|
|
54
|
+
header: null,
|
|
55
|
+
roles: [],
|
|
56
|
+
followers: [],
|
|
57
|
+
following: [],
|
|
58
|
+
controllers: [],
|
|
59
|
+
memberships: [],
|
|
60
|
+
profileStats: { followersCount: 0, followingCount: 0 },
|
|
61
|
+
});
|
|
62
|
+
/** Tombstone a `ProfileWithMeta` only when it is soft-deleted. */
|
|
63
|
+
export const tombstoneProfileWithMetaIfDeleted = (profile) => profile && isDeletedProfile(profile)
|
|
64
|
+
? toDeletedProfileWithMeta(profile)
|
|
65
|
+
: profile;
|
|
37
66
|
export const profileName = (profile) => (profile === null || profile === void 0 ? void 0 : profile.displayName) || (profile === null || profile === void 0 ? void 0 : profile.handle);
|
|
38
67
|
export const matchesQuery = (profile, query, queryOptions = { handle: true, displayName: true }) => !!(profile &&
|
|
39
68
|
(query.startsWith('@')
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { PushSubscription } from '../types';
|
|
1
|
+
import type { PushSubscription, PushSubscriptionData } from '../types';
|
|
2
2
|
export declare const pushSubscriptionDeviceName: (subscription: PushSubscription) => string | undefined;
|
|
3
|
+
/** Identity used to send a push. Duplicate keys mean duplicate notifications. */
|
|
4
|
+
export declare const pushSubscriptionDeliveryKey: (subscription: PushSubscriptionData) => string;
|
|
3
5
|
export declare const pushSubscriptionEndpoint: (subscription: PushSubscription) => string | undefined;
|
|
4
6
|
export declare const pushSubscriptionIsMobile: (subscription: PushSubscription) => boolean;
|
package/dist/lib/pushHelpers.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
export const pushSubscriptionDeviceName = (subscription) => 'deviceName' in subscription ? subscription.deviceName : undefined;
|
|
2
|
+
/** Identity used to send a push. Duplicate keys mean duplicate notifications. */
|
|
3
|
+
export const pushSubscriptionDeliveryKey = (subscription) => {
|
|
4
|
+
switch (subscription.type) {
|
|
5
|
+
case 'web':
|
|
6
|
+
return `web:${subscription.endpoint}`;
|
|
7
|
+
case 'webhook':
|
|
8
|
+
return `webhook:${subscription.url}`;
|
|
9
|
+
case 'apn':
|
|
10
|
+
return `apn:${subscription.apnToken}`;
|
|
11
|
+
case 'fcm':
|
|
12
|
+
return `fcm:${subscription.fcmToken}`;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
2
15
|
export const pushSubscriptionEndpoint = (subscription) => 'endpoint' in subscription ? subscription.endpoint : undefined;
|
|
3
16
|
export const pushSubscriptionIsMobile = (subscription) => {
|
|
4
17
|
var _a;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CoreConfig, ServerInfo } from '../types';
|
|
2
|
+
/** Query param that keeps the native password form when `sso.onlySSO` is set. */
|
|
3
|
+
export declare const LOCAL_LOGIN_PARAM = "local";
|
|
4
|
+
export type SsoLoginDestination = {
|
|
5
|
+
href: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
testId: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const isAllowedSsoLoginUrl: (url: string) => boolean;
|
|
10
|
+
export declare const oidcAuthorizePath: (id: string) => string;
|
|
11
|
+
export declare const ssoLoginDestinations: (sso: Pick<NonNullable<ServerInfo["sso"]>, "generic" | "oidc"> | undefined) => SsoLoginDestination[];
|
|
12
|
+
export type OnlySsoView = {
|
|
13
|
+
mode: 'form';
|
|
14
|
+
} | {
|
|
15
|
+
mode: 'redirect';
|
|
16
|
+
href: string;
|
|
17
|
+
} | {
|
|
18
|
+
mode: 'chooser';
|
|
19
|
+
destinations: SsoLoginDestination[];
|
|
20
|
+
};
|
|
21
|
+
export declare const resolveOnlySsoView: (sso: ServerInfo["sso"], searchParams: {
|
|
22
|
+
has: (name: string) => boolean;
|
|
23
|
+
}) => OnlySsoView;
|
|
24
|
+
export declare const publicSsoInfo: (sso: CoreConfig["sso"]) => ServerInfo["sso"];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** Query param that keeps the native password form when `sso.onlySSO` is set. */
|
|
2
|
+
export const LOCAL_LOGIN_PARAM = 'local';
|
|
3
|
+
export const isAllowedSsoLoginUrl = (url) => {
|
|
4
|
+
const trimmed = url.trim();
|
|
5
|
+
if (!trimmed)
|
|
6
|
+
return false;
|
|
7
|
+
if (trimmed.startsWith('/') && !trimmed.startsWith('//'))
|
|
8
|
+
return true;
|
|
9
|
+
try {
|
|
10
|
+
const parsed = new URL(trimmed);
|
|
11
|
+
return parsed.protocol === 'http:' || parsed.protocol === 'https:';
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const oidcAuthorizePath = (id) => `/api/openpeeps/core/v1/sso/oidc/${encodeURIComponent(id)}/authorize`;
|
|
18
|
+
export const ssoLoginDestinations = (sso) => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const destinations = [];
|
|
21
|
+
for (const provider of (_a = sso === null || sso === void 0 ? void 0 : sso.generic) !== null && _a !== void 0 ? _a : []) {
|
|
22
|
+
destinations.push({
|
|
23
|
+
href: provider.loginLink,
|
|
24
|
+
name: provider.name,
|
|
25
|
+
testId: `auth-login-generic-${provider.id}`,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
for (const provider of (_b = sso === null || sso === void 0 ? void 0 : sso.oidc) !== null && _b !== void 0 ? _b : []) {
|
|
29
|
+
destinations.push({
|
|
30
|
+
href: oidcAuthorizePath(provider.id),
|
|
31
|
+
name: provider.name,
|
|
32
|
+
testId: `auth-login-oidc-${provider.id}`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return destinations;
|
|
36
|
+
};
|
|
37
|
+
export const resolveOnlySsoView = (sso, searchParams) => {
|
|
38
|
+
if (!(sso === null || sso === void 0 ? void 0 : sso.onlySSO) || searchParams.has(LOCAL_LOGIN_PARAM)) {
|
|
39
|
+
return { mode: 'form' };
|
|
40
|
+
}
|
|
41
|
+
const destinations = ssoLoginDestinations(sso);
|
|
42
|
+
const [only] = destinations;
|
|
43
|
+
if (only && destinations.length === 1) {
|
|
44
|
+
return { mode: 'redirect', href: only.href };
|
|
45
|
+
}
|
|
46
|
+
return { mode: 'chooser', destinations };
|
|
47
|
+
};
|
|
48
|
+
export const publicSsoInfo = (sso) => {
|
|
49
|
+
const oidc = sso.oidc.map((provider) => ({
|
|
50
|
+
id: provider.id,
|
|
51
|
+
name: provider.name,
|
|
52
|
+
}));
|
|
53
|
+
const generic = sso.generic.flatMap((provider) => {
|
|
54
|
+
var _a;
|
|
55
|
+
const loginLink = (_a = provider.loginLink) === null || _a === void 0 ? void 0 : _a.trim();
|
|
56
|
+
if (!loginLink || !isAllowedSsoLoginUrl(loginLink))
|
|
57
|
+
return [];
|
|
58
|
+
return [
|
|
59
|
+
{
|
|
60
|
+
id: provider.id,
|
|
61
|
+
name: provider.name,
|
|
62
|
+
loginLink,
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
});
|
|
66
|
+
const onlySSO = !!sso.onlySSO;
|
|
67
|
+
if (oidc.length === 0 && generic.length === 0 && !onlySSO) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
oidc,
|
|
72
|
+
generic,
|
|
73
|
+
...(onlySSO ? { onlySSO: true } : {}),
|
|
74
|
+
};
|
|
75
|
+
};
|
package/dist/lib/text.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** Compact unread badge label. 3+ digits overflow a 20px circle; ∞ fits. */
|
|
2
|
+
export declare const formatBadgeCount: (count: number) => string;
|
|
1
3
|
export declare const truncateText: (text?: string | null, maxLength?: number) => string;
|
|
2
4
|
export declare const randomString: (length: number, characters?: string) => string;
|
|
3
5
|
export declare const capitalizeFirstLetter: (string: string) => string;
|
package/dist/lib/text.js
CHANGED
|
@@ -11,6 +11,11 @@ export declare const parseScopesFromJwt: (token: string | undefined | null) => S
|
|
|
11
11
|
* (e.g. jam observer / egress links). These cannot load `profiles/current`.
|
|
12
12
|
*/
|
|
13
13
|
export declare const isServiceOnlyJwt: (token: string | undefined | null) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* True for guest-pass JWTs: a profile identity with no account (1d TTL).
|
|
16
|
+
* These must not use the login JWT refresh path or `/accounts/current`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const isAccountlessJwt: (token: string | undefined | null) => boolean;
|
|
14
19
|
/**
|
|
15
20
|
* True when the token has a numeric `exp`, is not expired yet, and seconds until expiry is at least
|
|
16
21
|
* `minRemainingSeconds`. Non-finite or negative `minRemainingSeconds` yields false. Invalid or undecodable
|
package/dist/lib/tokenHelpers.js
CHANGED
|
@@ -36,6 +36,25 @@ export const isServiceOnlyJwt = (token) => {
|
|
|
36
36
|
return false;
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* True for guest-pass JWTs: a profile identity with no account (1d TTL).
|
|
41
|
+
* These must not use the login JWT refresh path or `/accounts/current`.
|
|
42
|
+
*/
|
|
43
|
+
export const isAccountlessJwt = (token) => {
|
|
44
|
+
if (!(token === null || token === void 0 ? void 0 : token.trim())) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const parsed = authorizationSchema.safeParse(decodeJwt(token));
|
|
49
|
+
if (!parsed.success)
|
|
50
|
+
return false;
|
|
51
|
+
const { profile, account, service } = parsed.data.identities;
|
|
52
|
+
return !!profile && !account && !service;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
39
58
|
/**
|
|
40
59
|
* True when the token has a numeric `exp`, is not expired yet, and seconds until expiry is at least
|
|
41
60
|
* `minRemainingSeconds`. Non-finite or negative `minRemainingSeconds` yields false. Invalid or undecodable
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -29,6 +29,10 @@ export declare const formatTimeStamp: (timestamp: number | null, startDate?: num
|
|
|
29
29
|
export declare const getTheme: (config: CommunityConfig, profileSettings?: ProfileSettings, systemTheme?: "dark" | "light") => {
|
|
30
30
|
dark: boolean;
|
|
31
31
|
primaryHex: string;
|
|
32
|
+
secondaryHex?: string | undefined;
|
|
33
|
+
fontFamily?: string | undefined;
|
|
34
|
+
buttonRadius?: string | undefined;
|
|
35
|
+
radius?: string | undefined;
|
|
32
36
|
logoSmall?: string | undefined;
|
|
33
37
|
defaultProfileAvatar?: string | undefined;
|
|
34
38
|
defaultGroupAvatar?: string | undefined;
|