@openpeepshq/common 0.1.44 → 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.
Files changed (47) hide show
  1. package/dist/lib/adminSections.d.ts +4 -0
  2. package/dist/lib/adminSections.js +5 -0
  3. package/dist/lib/capabilitiesHelpers.d.ts +7 -7
  4. package/dist/lib/capabilitiesHelpers.js +4 -11
  5. package/dist/lib/eventIcs.js +56 -2
  6. package/dist/lib/eventRecurrence.d.ts +30 -0
  7. package/dist/lib/eventRecurrence.js +279 -0
  8. package/dist/lib/eventTime.d.ts +22 -0
  9. package/dist/lib/eventTime.js +127 -0
  10. package/dist/lib/groupHelpers.d.ts +63 -41
  11. package/dist/lib/groupHelpers.js +155 -45
  12. package/dist/lib/groupTemplateHelpers.d.ts +16 -0
  13. package/dist/lib/groupTemplateHelpers.js +51 -0
  14. package/dist/lib/index.d.ts +4 -0
  15. package/dist/lib/index.js +4 -0
  16. package/dist/lib/jamHelpers.d.ts +28 -2
  17. package/dist/lib/jamHelpers.js +56 -8
  18. package/dist/lib/markdownHelpers.d.ts +14 -0
  19. package/dist/lib/markdownHelpers.js +41 -0
  20. package/dist/lib/postHelpers.d.ts +22 -6
  21. package/dist/lib/postHelpers.js +49 -10
  22. package/dist/lib/pushHelpers.d.ts +3 -1
  23. package/dist/lib/pushHelpers.js +13 -0
  24. package/dist/lib/ssoLoginUrl.d.ts +24 -0
  25. package/dist/lib/ssoLoginUrl.js +75 -0
  26. package/dist/lib/text.d.ts +2 -0
  27. package/dist/lib/text.js +2 -0
  28. package/dist/lib/tokenHelpers.d.ts +5 -0
  29. package/dist/lib/tokenHelpers.js +19 -0
  30. package/dist/types/api.d.ts +2384 -350
  31. package/dist/types/api.js +43 -13
  32. package/dist/types/auth.d.ts +2 -7
  33. package/dist/types/capabilities.d.ts +11 -4
  34. package/dist/types/capabilities.js +44 -1
  35. package/dist/types/config.d.ts +15 -24
  36. package/dist/types/config.js +10 -8
  37. package/dist/types/db.d.ts +738 -66
  38. package/dist/types/db.js +3 -3
  39. package/dist/types/internal.d.ts +6189 -2604
  40. package/dist/types/internal.js +10 -1
  41. package/dist/types/models.d.ts +280 -9
  42. package/dist/types/models.js +59 -5
  43. package/dist/types/notifications.d.ts +1 -0
  44. package/dist/types/plugins.d.ts +21 -1
  45. package/dist/types/plugins.js +9 -1
  46. package/dist/types/stats.d.ts +1284 -184
  47. 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 '';
@@ -4,11 +4,13 @@ export declare const getReactionCount: (post: PublicPost) => Record<"👍", numb
4
4
  export declare const countVotes: (optionsCount: number, answers: Answer[]) => number[];
5
5
  /** Fill blank poll choices with their placeholder label (e.g. "Option 1"). */
6
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;
7
9
  export declare const collectVotes: (post: PublicPost) => {
8
10
  voteCounts: number[];
9
11
  votes: AnswerWithPublicProfile[];
10
12
  };
11
- export declare const calculateEffectiveRsvps: (post: PublicPost) => {
13
+ export declare const calculateEffectiveRsvps: (post: PublicPost, recurrenceId?: string) => {
12
14
  response: "no" | "yes" | "tentative" | "removed";
13
15
  profile: {
14
16
  id: string;
@@ -35,7 +37,7 @@ export declare const calculateEffectiveRsvps: (post: PublicPost) => {
35
37
  discoverable?: boolean | undefined;
36
38
  deletedAt?: string | null | undefined;
37
39
  };
38
- roles?: ("none" | "local" | "member" | "admin" | "moderator" | "invited")[] | null | undefined;
40
+ roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
39
41
  }[] | undefined;
40
42
  deletedAt?: string | null | undefined;
41
43
  avatar?: string | null | undefined;
@@ -63,8 +65,9 @@ export declare const calculateEffectiveRsvps: (post: PublicPost) => {
63
65
  } | undefined;
64
66
  };
65
67
  createdAt: string;
68
+ recurrenceId?: string | undefined;
66
69
  }[];
67
- export declare const getEffectiveRsvp: (post: PublicPost, profileId: string) => {
70
+ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string, recurrenceId?: string) => {
68
71
  response: "no" | "yes" | "tentative" | "removed";
69
72
  profile: {
70
73
  id: string;
@@ -91,7 +94,7 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string) =>
91
94
  discoverable?: boolean | undefined;
92
95
  deletedAt?: string | null | undefined;
93
96
  };
94
- roles?: ("none" | "local" | "member" | "admin" | "moderator" | "invited")[] | null | undefined;
97
+ roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
95
98
  }[] | undefined;
96
99
  deletedAt?: string | null | undefined;
97
100
  avatar?: string | null | undefined;
@@ -119,8 +122,9 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string) =>
119
122
  } | undefined;
120
123
  };
121
124
  createdAt: string;
125
+ recurrenceId?: string | undefined;
122
126
  } | undefined;
123
- export declare const countYesRsvps: (post: PublicPost) => number;
127
+ export declare const countYesRsvps: (post: PublicPost, recurrenceId?: string) => number;
124
128
  export declare const isCapacityEvent: (event: Event) => boolean;
125
129
  export declare const parseEventMaxAttendeesInput: (raw: string) => number | undefined;
126
130
  export declare const withoutEventMaxAttendees: <T extends Event>(event: T) => T;
@@ -140,9 +144,21 @@ export type JamCapacityJoinBlock = {
140
144
  blocked: true;
141
145
  reason: 'full' | 'rsvp-required' | 'removed';
142
146
  };
143
- 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;
144
148
  export declare const canDeletePost: (authData: AuthorizationData, post: PublicPost, config: CapabilitiesConfig) => boolean;
145
149
  export declare const canCreatePost: (authData: AuthorizationData, type: PostType, visibility: VisibilityType, group?: GroupWithMeta) => boolean;
146
150
  export declare const canCreatePostTypeInAnyGroup: (authData: AuthorizationData, type: PostType) => boolean;
147
151
  export declare const canCreatePostTypeWithVisibility: (authData: AuthorizationData, type: PostType, visibility: VisibilityType) => boolean;
148
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;
@@ -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';
@@ -32,6 +33,8 @@ export const resolvePollOptionContents = (options, fallbackLabel) => options.map
32
33
  const trimmed = text.trim();
33
34
  return trimmed.length > 0 ? trimmed : fallbackLabel(index);
34
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);
35
38
  export const collectVotes = (post) => {
36
39
  if (post.type !== 'question') {
37
40
  return {
@@ -57,16 +60,30 @@ export const collectVotes = (post) => {
57
60
  voteCounts,
58
61
  };
59
62
  };
60
- const latestRsvpPerProfile = (rsvps) => {
61
- const rsvpsByProfile = groupBy(rsvps, (r) => r.profile.id);
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);
62
74
  return Object.values(rsvpsByProfile).map((profileRsvps) => {
63
- const sorted = profileRsvps.sort(dateSorter());
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());
64
81
  return sorted[sorted.length - 1];
65
82
  });
66
83
  };
67
- export const calculateEffectiveRsvps = (post) => latestRsvpPerProfile(post.rsvps || []);
68
- export const getEffectiveRsvp = (post, profileId) => calculateEffectiveRsvps(post).find((r) => r.profile.id === profileId);
69
- 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;
70
87
  export const isCapacityEvent = (event) => !!event.maxAttendees;
71
88
  export const parseEventMaxAttendeesInput = (raw) => {
72
89
  const trimmed = raw.trim();
@@ -104,7 +121,7 @@ export const eventDataForDbUpdate = (previous, normalized) => {
104
121
  };
105
122
  export const canManageEventRsvps = (profile, post) => !!(profile &&
106
123
  (post.profile.id === profile.id || canModerateJam(profile, post)));
107
- export const getJamCapacityJoinBlock = (post, profile) => {
124
+ export const getJamCapacityJoinBlock = (post, profile, recurrenceId) => {
108
125
  var _a;
109
126
  const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
110
127
  if (!(event === null || event === void 0 ? void 0 : event.maxAttendees) || !(profile === null || profile === void 0 ? void 0 : profile.id)) {
@@ -113,14 +130,14 @@ export const getJamCapacityJoinBlock = (post, profile) => {
113
130
  if (canModerateJam(profile, post)) {
114
131
  return { blocked: false };
115
132
  }
116
- const myRsvp = getEffectiveRsvp(post, profile.id);
133
+ const myRsvp = getEffectiveRsvp(post, profile.id, recurrenceId);
117
134
  if ((myRsvp === null || myRsvp === void 0 ? void 0 : myRsvp.response) === 'yes') {
118
135
  return { blocked: false };
119
136
  }
120
137
  if ((myRsvp === null || myRsvp === void 0 ? void 0 : myRsvp.response) === 'removed') {
121
138
  return { blocked: true, reason: 'removed' };
122
139
  }
123
- if (countYesRsvps(post) >= event.maxAttendees) {
140
+ if (countYesRsvps(post, recurrenceId) >= event.maxAttendees) {
124
141
  return { blocked: true, reason: 'full' };
125
142
  }
126
143
  return { blocked: true, reason: 'rsvp-required' };
@@ -161,3 +178,25 @@ export const canCreatePostTypeWithVisibility = (authData, type, visibility) => {
161
178
  });
162
179
  };
163
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
+ };
@@ -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;
@@ -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
+ };
@@ -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
@@ -1,3 +1,5 @@
1
+ /** Compact unread badge label. 3+ digits overflow a 20px circle; ∞ fits. */
2
+ export const formatBadgeCount = (count) => count > 99 ? '∞' : String(count);
1
3
  export const truncateText = (text, maxLength = 15) => {
2
4
  if (!text)
3
5
  return '';
@@ -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
@@ -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