@openpeepshq/common 0.1.44 → 0.1.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) 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 +9 -7
  4. package/dist/lib/capabilitiesHelpers.js +21 -13
  5. package/dist/lib/eventIcs.d.ts +17 -0
  6. package/dist/lib/eventIcs.js +138 -2
  7. package/dist/lib/eventRecurrence.d.ts +32 -0
  8. package/dist/lib/eventRecurrence.js +284 -0
  9. package/dist/lib/eventTime.d.ts +29 -0
  10. package/dist/lib/eventTime.js +143 -0
  11. package/dist/lib/federationHosts.d.ts +3 -0
  12. package/dist/lib/federationHosts.js +17 -0
  13. package/dist/lib/feedCursor.d.ts +14 -0
  14. package/dist/lib/feedCursor.js +22 -0
  15. package/dist/lib/feedFormat.d.ts +12 -0
  16. package/dist/lib/feedFormat.js +14 -0
  17. package/dist/lib/groupHelpers.d.ts +63 -41
  18. package/dist/lib/groupHelpers.js +155 -45
  19. package/dist/lib/groupTemplateHelpers.d.ts +16 -0
  20. package/dist/lib/groupTemplateHelpers.js +51 -0
  21. package/dist/lib/index.d.ts +11 -0
  22. package/dist/lib/index.js +11 -0
  23. package/dist/lib/jamHelpers.d.ts +38 -3
  24. package/dist/lib/jamHelpers.js +93 -8
  25. package/dist/lib/legacyThemeRoot.d.ts +3 -0
  26. package/dist/lib/legacyThemeRoot.js +10 -0
  27. package/dist/lib/markdownHelpers.d.ts +22 -0
  28. package/dist/lib/markdownHelpers.js +73 -3
  29. package/dist/lib/postHelpers.d.ts +164 -9
  30. package/dist/lib/postHelpers.js +353 -11
  31. package/dist/lib/profileHelpers.d.ts +11 -0
  32. package/dist/lib/profileHelpers.js +31 -0
  33. package/dist/lib/pushHelpers.d.ts +3 -1
  34. package/dist/lib/pushHelpers.js +13 -0
  35. package/dist/lib/reactions.d.ts +17 -0
  36. package/dist/lib/reactions.js +37 -0
  37. package/dist/lib/scopeHelpers.d.ts +31 -2
  38. package/dist/lib/scopeHelpers.js +37 -3
  39. package/dist/lib/ssoLoginUrl.d.ts +24 -0
  40. package/dist/lib/ssoLoginUrl.js +75 -0
  41. package/dist/lib/ssoProviders.d.ts +72 -0
  42. package/dist/lib/ssoProviders.js +370 -0
  43. package/dist/lib/text.d.ts +2 -0
  44. package/dist/lib/text.js +2 -0
  45. package/dist/lib/timeZone.d.ts +9 -0
  46. package/dist/lib/timeZone.js +44 -0
  47. package/dist/lib/tokenHelpers.d.ts +5 -0
  48. package/dist/lib/tokenHelpers.js +19 -0
  49. package/dist/types/analytics.d.ts +20 -0
  50. package/dist/types/analytics.js +4 -0
  51. package/dist/types/api.d.ts +42669 -10689
  52. package/dist/types/api.js +94 -16
  53. package/dist/types/auth.d.ts +22 -13
  54. package/dist/types/capabilities.d.ts +26 -5
  55. package/dist/types/capabilities.js +95 -1
  56. package/dist/types/config.d.ts +93 -6
  57. package/dist/types/config.js +56 -5
  58. package/dist/types/db.d.ts +1911 -248
  59. package/dist/types/db.js +17 -3
  60. package/dist/types/export.d.ts +120 -0
  61. package/dist/types/export.js +7 -0
  62. package/dist/types/index.d.ts +2 -0
  63. package/dist/types/index.js +2 -0
  64. package/dist/types/internal.d.ts +8313 -2675
  65. package/dist/types/internal.js +16 -1
  66. package/dist/types/models.d.ts +343 -16
  67. package/dist/types/models.js +98 -7
  68. package/dist/types/notifications.d.ts +1 -0
  69. package/dist/types/plugins.d.ts +43 -1
  70. package/dist/types/plugins.js +75 -1
  71. package/dist/types/roleDefaults.d.ts +31 -0
  72. package/dist/types/roleDefaults.js +110 -0
  73. package/dist/types/stats.d.ts +54359 -4718
  74. package/dist/types/stats.js +30 -0
  75. package/dist/types/utils.d.ts +2 -0
  76. package/dist/types/utils.js +1 -3
  77. package/package.json +1 -1
@@ -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
+ };
@@ -0,0 +1,72 @@
1
+ import { type CoreConfig } from '../types';
2
+ export declare const SSO_OIDC_KINDS: readonly ["oidc", "github", "gitlab", "gitlab-selfhosted", "google", "entra", "auth0", "keycloak", "authentik", "okta", "discord", "pocketid"];
3
+ export type SsoOidcKind = (typeof SSO_OIDC_KINDS)[number];
4
+ export type SsoProviderKind = SsoOidcKind | 'generic';
5
+ export declare const SSO_ADD_KINDS: readonly ["gitlab", "gitlab-selfhosted", "github", "google", "entra", "discord", "auth0", "okta", "keycloak", "authentik", "pocketid", "oidc", "generic"];
6
+ export type OidcProvider = CoreConfig['sso']['oidc'][number];
7
+ export type GenericProvider = CoreConfig['sso']['generic'][number];
8
+ export type OidcClaimMapping = NonNullable<OidcProvider['claimMapping']>;
9
+ export type OidcEndpoints = {
10
+ authorizationUrl: string;
11
+ tokenUrl: string;
12
+ userinfoUrl: string;
13
+ emailsUrl?: string;
14
+ jwksUri?: string;
15
+ scope: string;
16
+ claimMapping: OidcClaimMapping;
17
+ };
18
+ export type TemplateFieldNeed = false | 'optional' | 'required';
19
+ export type OidcTemplateNeeds = {
20
+ instanceUrl: TemplateFieldNeed;
21
+ tenant: TemplateFieldNeed;
22
+ };
23
+ export declare const ssoOidcKind: (provider: {
24
+ kind?: string;
25
+ }) => SsoOidcKind;
26
+ export declare const oidcTemplateNeeds: (kind: SsoProviderKind) => OidcTemplateNeeds;
27
+ export declare const isSsoAddKind: (value: string) => value is SsoProviderKind;
28
+ export declare const ssoKindDefaultId: (kind: SsoProviderKind) => string;
29
+ export declare const uniqueSsoProviderId: (base: string, used: Iterable<string>) => string;
30
+ export declare const ssoKindDefaultName: (kind: SsoProviderKind) => string;
31
+ export declare const githubOidcEndpoints: (instanceUrl?: string) => OidcEndpoints;
32
+ export declare const gitlabOidcEndpoints: (instanceUrl?: string) => OidcEndpoints;
33
+ export declare const oidcEndpoints: (kind: SsoOidcKind, fields?: {
34
+ instanceUrl?: string;
35
+ tenant?: string;
36
+ }) => OidcEndpoints | undefined;
37
+ export type OidcProviderFields = {
38
+ id: string;
39
+ name: string;
40
+ instanceUrl?: string;
41
+ tenant?: string;
42
+ clientId: string;
43
+ clientSecret?: string;
44
+ scope?: string;
45
+ approvalRequired?: boolean;
46
+ authorizationUrl?: string;
47
+ tokenUrl?: string;
48
+ userinfoUrl?: string;
49
+ emailsUrl?: string;
50
+ jwksUri?: string;
51
+ claimMapping?: OidcProvider['claimMapping'];
52
+ };
53
+ export declare const applyOidcProvider: (kind: SsoOidcKind, fields: OidcProviderFields) => OidcProvider;
54
+ export declare const applyGenericProvider: (fields: {
55
+ id: string;
56
+ name: string;
57
+ loginLink?: string;
58
+ profileUrl: string;
59
+ authHeader?: string;
60
+ emailPath: string;
61
+ handlePath?: string;
62
+ displayNamePath?: string;
63
+ avatarPath?: string;
64
+ createAccounts?: boolean;
65
+ createProfiles?: boolean;
66
+ }) => GenericProvider;
67
+ export declare const githubEmailsUrl: (provider: OidcProvider) => string | undefined;
68
+ export declare const discordAvatarUrl: (claims: Record<string, unknown>) => string | undefined;
69
+ export declare const pickOAuthEmail: (emails: unknown) => string | undefined;
70
+ export declare const parseOAuthTokenBody: (body: string, contentType: string | null) => Record<string, unknown>;
71
+ /** Keep stored secrets when a sanitized patch still carries the placeholder. */
72
+ export declare const restorePasswordPlaceholders: (incoming: unknown, existing: unknown) => unknown;
@@ -0,0 +1,370 @@
1
+ import { passwordPlaceHolder } from '../types/index.js';
2
+ export const SSO_OIDC_KINDS = [
3
+ 'oidc',
4
+ 'github',
5
+ 'gitlab',
6
+ 'gitlab-selfhosted',
7
+ 'google',
8
+ 'entra',
9
+ 'auth0',
10
+ 'keycloak',
11
+ 'authentik',
12
+ 'okta',
13
+ 'discord',
14
+ 'pocketid',
15
+ ];
16
+ export const SSO_ADD_KINDS = [
17
+ 'gitlab',
18
+ 'gitlab-selfhosted',
19
+ 'github',
20
+ 'google',
21
+ 'entra',
22
+ 'discord',
23
+ 'auth0',
24
+ 'okta',
25
+ 'keycloak',
26
+ 'authentik',
27
+ 'pocketid',
28
+ 'oidc',
29
+ 'generic',
30
+ ];
31
+ const stripSlash = (url) => url.replace(/\/$/, '');
32
+ const withHttps = (url) => {
33
+ const trimmed = stripSlash(url.trim());
34
+ if (!trimmed)
35
+ return '';
36
+ return /^https?:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
37
+ };
38
+ const isGitHubDotCom = (web) => /^https?:\/\/(www\.)?github\.com$/i.test(web);
39
+ const oidcClaims = (handle = 'preferred_username', displayName = 'name', avatar = 'picture') => ({
40
+ email: 'email',
41
+ handle,
42
+ displayName,
43
+ avatar,
44
+ });
45
+ export const ssoOidcKind = (provider) => SSO_OIDC_KINDS.includes(provider.kind)
46
+ ? provider.kind
47
+ : 'oidc';
48
+ export const oidcTemplateNeeds = (kind) => {
49
+ switch (kind) {
50
+ case 'github':
51
+ return { instanceUrl: 'optional', tenant: false };
52
+ case 'gitlab-selfhosted':
53
+ case 'auth0':
54
+ case 'okta':
55
+ case 'pocketid':
56
+ return {
57
+ instanceUrl: 'required',
58
+ tenant: kind === 'okta' ? 'optional' : false,
59
+ };
60
+ case 'keycloak':
61
+ case 'authentik':
62
+ return { instanceUrl: 'required', tenant: 'required' };
63
+ case 'entra':
64
+ return { instanceUrl: false, tenant: 'optional' };
65
+ default:
66
+ return { instanceUrl: false, tenant: false };
67
+ }
68
+ };
69
+ export const isSsoAddKind = (value) => SSO_ADD_KINDS.includes(value);
70
+ export const ssoKindDefaultId = (kind) => {
71
+ switch (kind) {
72
+ case 'gitlab-selfhosted':
73
+ return 'gitlab';
74
+ case 'entra':
75
+ return 'microsoft';
76
+ default:
77
+ return kind;
78
+ }
79
+ };
80
+ export const uniqueSsoProviderId = (base, used) => {
81
+ const taken = new Set(used);
82
+ if (!taken.has(base))
83
+ return base;
84
+ let n = 2;
85
+ while (taken.has(`${base}-${n}`))
86
+ n += 1;
87
+ return `${base}-${n}`;
88
+ };
89
+ export const ssoKindDefaultName = (kind) => {
90
+ switch (kind) {
91
+ case 'gitlab':
92
+ case 'gitlab-selfhosted':
93
+ return 'GitLab';
94
+ case 'github':
95
+ return 'GitHub';
96
+ case 'google':
97
+ return 'Google';
98
+ case 'entra':
99
+ return 'Microsoft';
100
+ case 'discord':
101
+ return 'Discord';
102
+ case 'auth0':
103
+ return 'Auth0';
104
+ case 'okta':
105
+ return 'Okta';
106
+ case 'keycloak':
107
+ return 'Keycloak';
108
+ case 'authentik':
109
+ return 'Authentik';
110
+ case 'pocketid':
111
+ return 'Pocket ID';
112
+ default:
113
+ return '';
114
+ }
115
+ };
116
+ export const githubOidcEndpoints = (instanceUrl) => {
117
+ const web = withHttps(instanceUrl || '') || 'https://github.com';
118
+ const api = isGitHubDotCom(web) ? 'https://api.github.com' : `${web}/api/v3`;
119
+ return {
120
+ authorizationUrl: `${web}/login/oauth/authorize`,
121
+ tokenUrl: `${web}/login/oauth/access_token`,
122
+ userinfoUrl: `${api}/user`,
123
+ emailsUrl: `${api}/user/emails`,
124
+ scope: 'read:user user:email',
125
+ claimMapping: oidcClaims('login', 'name', 'avatar_url'),
126
+ };
127
+ };
128
+ export const gitlabOidcEndpoints = (instanceUrl) => {
129
+ const base = withHttps(instanceUrl || '') || 'https://gitlab.com';
130
+ return {
131
+ authorizationUrl: `${base}/oauth/authorize`,
132
+ tokenUrl: `${base}/oauth/token`,
133
+ userinfoUrl: `${base}/oauth/userinfo`,
134
+ jwksUri: `${base}/oauth/discovery/keys`,
135
+ scope: 'openid email profile',
136
+ claimMapping: oidcClaims('nickname'),
137
+ };
138
+ };
139
+ export const oidcEndpoints = (kind, fields = {}) => {
140
+ var _a;
141
+ const instance = withHttps(fields.instanceUrl || '');
142
+ const tenant = (_a = fields.tenant) === null || _a === void 0 ? void 0 : _a.trim();
143
+ switch (kind) {
144
+ case 'github':
145
+ return githubOidcEndpoints(fields.instanceUrl);
146
+ case 'gitlab':
147
+ case 'gitlab-selfhosted':
148
+ return gitlabOidcEndpoints(kind === 'gitlab-selfhosted' ? instance : fields.instanceUrl);
149
+ case 'google':
150
+ return {
151
+ authorizationUrl: 'https://accounts.google.com/o/oauth2/v2/auth',
152
+ tokenUrl: 'https://oauth2.googleapis.com/token',
153
+ userinfoUrl: 'https://openidconnect.googleapis.com/v1/userinfo',
154
+ jwksUri: 'https://www.googleapis.com/oauth2/v3/certs',
155
+ scope: 'openid email profile',
156
+ claimMapping: oidcClaims('email'),
157
+ };
158
+ case 'entra': {
159
+ const directory = tenant || 'common';
160
+ return {
161
+ authorizationUrl: `https://login.microsoftonline.com/${directory}/oauth2/v2.0/authorize`,
162
+ tokenUrl: `https://login.microsoftonline.com/${directory}/oauth2/v2.0/token`,
163
+ userinfoUrl: 'https://graph.microsoft.com/oidc/userinfo',
164
+ jwksUri: `https://login.microsoftonline.com/${directory}/discovery/v2.0/keys`,
165
+ scope: 'openid email profile',
166
+ claimMapping: oidcClaims(),
167
+ };
168
+ }
169
+ case 'auth0':
170
+ return {
171
+ authorizationUrl: `${instance}/authorize`,
172
+ tokenUrl: `${instance}/oauth/token`,
173
+ userinfoUrl: `${instance}/userinfo`,
174
+ jwksUri: `${instance}/.well-known/jwks.json`,
175
+ scope: 'openid email profile',
176
+ claimMapping: oidcClaims(),
177
+ };
178
+ case 'keycloak': {
179
+ const realm = `${instance}/realms/${tenant || 'master'}`;
180
+ return {
181
+ authorizationUrl: `${realm}/protocol/openid-connect/auth`,
182
+ tokenUrl: `${realm}/protocol/openid-connect/token`,
183
+ userinfoUrl: `${realm}/protocol/openid-connect/userinfo`,
184
+ jwksUri: `${realm}/protocol/openid-connect/certs`,
185
+ scope: 'openid email profile',
186
+ claimMapping: oidcClaims(),
187
+ };
188
+ }
189
+ case 'authentik':
190
+ return {
191
+ authorizationUrl: `${instance}/application/o/authorize/`,
192
+ tokenUrl: `${instance}/application/o/token/`,
193
+ userinfoUrl: `${instance}/application/o/userinfo/`,
194
+ jwksUri: tenant
195
+ ? `${instance}/application/o/${tenant}/jwks/`
196
+ : undefined,
197
+ scope: 'openid email profile',
198
+ claimMapping: oidcClaims(),
199
+ };
200
+ case 'okta': {
201
+ const server = tenant || 'default';
202
+ return {
203
+ authorizationUrl: `${instance}/oauth2/${server}/v1/authorize`,
204
+ tokenUrl: `${instance}/oauth2/${server}/v1/token`,
205
+ userinfoUrl: `${instance}/oauth2/${server}/v1/userinfo`,
206
+ jwksUri: `${instance}/oauth2/${server}/v1/keys`,
207
+ scope: 'openid email profile',
208
+ claimMapping: oidcClaims(),
209
+ };
210
+ }
211
+ case 'discord':
212
+ return {
213
+ authorizationUrl: 'https://discord.com/api/oauth2/authorize',
214
+ tokenUrl: 'https://discord.com/api/oauth2/token',
215
+ userinfoUrl: 'https://discord.com/api/users/@me',
216
+ scope: 'identify email',
217
+ claimMapping: oidcClaims('username', 'global_name', 'avatar'),
218
+ };
219
+ case 'pocketid':
220
+ return {
221
+ authorizationUrl: `${instance}/authorize`,
222
+ tokenUrl: `${instance}/api/oidc/token`,
223
+ userinfoUrl: `${instance}/api/oidc/userinfo`,
224
+ jwksUri: `${instance}/.well-known/jwks.json`,
225
+ scope: 'openid email profile',
226
+ claimMapping: oidcClaims(),
227
+ };
228
+ default:
229
+ return undefined;
230
+ }
231
+ };
232
+ export const applyOidcProvider = (kind, fields) => {
233
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
234
+ const tpl = oidcEndpoints(kind, fields);
235
+ if (tpl) {
236
+ return {
237
+ kind,
238
+ id: fields.id.trim(),
239
+ name: fields.name.trim(),
240
+ instanceUrl: ((_a = fields.instanceUrl) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
241
+ tenant: ((_b = fields.tenant) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
242
+ clientId: fields.clientId.trim(),
243
+ clientSecret: fields.clientSecret,
244
+ approvalRequired: fields.approvalRequired,
245
+ scope: ((_c = fields.scope) === null || _c === void 0 ? void 0 : _c.trim()) || tpl.scope,
246
+ authorizationUrl: tpl.authorizationUrl,
247
+ tokenUrl: tpl.tokenUrl,
248
+ userinfoUrl: tpl.userinfoUrl,
249
+ emailsUrl: tpl.emailsUrl,
250
+ jwksUri: tpl.jwksUri,
251
+ claimMapping: tpl.claimMapping,
252
+ };
253
+ }
254
+ return {
255
+ kind: 'oidc',
256
+ id: fields.id.trim(),
257
+ name: fields.name.trim(),
258
+ clientId: fields.clientId.trim(),
259
+ clientSecret: fields.clientSecret,
260
+ approvalRequired: fields.approvalRequired,
261
+ scope: ((_d = fields.scope) === null || _d === void 0 ? void 0 : _d.trim()) || 'openid email profile',
262
+ authorizationUrl: ((_e = fields.authorizationUrl) === null || _e === void 0 ? void 0 : _e.trim()) || '',
263
+ tokenUrl: ((_f = fields.tokenUrl) === null || _f === void 0 ? void 0 : _f.trim()) || '',
264
+ userinfoUrl: ((_g = fields.userinfoUrl) === null || _g === void 0 ? void 0 : _g.trim()) || '',
265
+ emailsUrl: ((_h = fields.emailsUrl) === null || _h === void 0 ? void 0 : _h.trim()) || undefined,
266
+ jwksUri: ((_j = fields.jwksUri) === null || _j === void 0 ? void 0 : _j.trim()) || undefined,
267
+ claimMapping: {
268
+ email: ((_k = fields.claimMapping) === null || _k === void 0 ? void 0 : _k.email) || 'email',
269
+ handle: ((_l = fields.claimMapping) === null || _l === void 0 ? void 0 : _l.handle) || 'preferred_username',
270
+ displayName: ((_m = fields.claimMapping) === null || _m === void 0 ? void 0 : _m.displayName) || 'name',
271
+ avatar: ((_o = fields.claimMapping) === null || _o === void 0 ? void 0 : _o.avatar) || 'picture',
272
+ },
273
+ };
274
+ };
275
+ export const applyGenericProvider = (fields) => {
276
+ var _a, _b, _c, _d, _e;
277
+ return ({
278
+ id: fields.id.trim(),
279
+ name: fields.name.trim(),
280
+ loginLink: ((_a = fields.loginLink) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
281
+ userProfileRequest: {
282
+ url: fields.profileUrl.trim(),
283
+ authHeader: ((_b = fields.authHeader) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
284
+ },
285
+ userProfilePaths: {
286
+ email: fields.emailPath.trim(),
287
+ handle: ((_c = fields.handlePath) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
288
+ displayName: ((_d = fields.displayNamePath) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
289
+ avatar: ((_e = fields.avatarPath) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
290
+ },
291
+ createAccounts: fields.createAccounts,
292
+ createProfiles: fields.createProfiles,
293
+ });
294
+ };
295
+ export const githubEmailsUrl = (provider) => provider.emailsUrl ||
296
+ (ssoOidcKind(provider) === 'github'
297
+ ? githubOidcEndpoints(provider.instanceUrl).emailsUrl
298
+ : undefined);
299
+ export const discordAvatarUrl = (claims) => {
300
+ const id = claims.id;
301
+ if (typeof id !== 'string' || !id)
302
+ return undefined;
303
+ const avatar = claims.avatar;
304
+ if (typeof avatar === 'string' && avatar) {
305
+ const format = avatar.startsWith('a_') ? 'gif' : 'png';
306
+ return `https://cdn.discordapp.com/avatars/${id}/${avatar}.${format}`;
307
+ }
308
+ const discriminator = typeof claims.discriminator === 'string' ? claims.discriminator : '0';
309
+ const index = discriminator === '0'
310
+ ? Number(BigInt(id) >> BigInt(22)) % 6
311
+ : Number.parseInt(discriminator, 10) % 5;
312
+ return `https://cdn.discordapp.com/embed/avatars/${Number.isFinite(index) ? index : 0}.png`;
313
+ };
314
+ export const pickOAuthEmail = (emails) => {
315
+ var _a, _b, _c, _d, _e;
316
+ if (!Array.isArray(emails))
317
+ return undefined;
318
+ const rows = emails.flatMap((entry) => {
319
+ if (!entry || typeof entry !== 'object')
320
+ return [];
321
+ const email = entry.email;
322
+ if (typeof email !== 'string' || !email.includes('@'))
323
+ return [];
324
+ return [
325
+ {
326
+ email,
327
+ primary: !!entry.primary,
328
+ verified: entry.verified !== false,
329
+ },
330
+ ];
331
+ });
332
+ return ((_d = (_b = (_a = rows.find((row) => row.primary && row.verified)) === null || _a === void 0 ? void 0 : _a.email) !== null && _b !== void 0 ? _b : (_c = rows.find((row) => row.verified)) === null || _c === void 0 ? void 0 : _c.email) !== null && _d !== void 0 ? _d : (_e = rows[0]) === null || _e === void 0 ? void 0 : _e.email);
333
+ };
334
+ export const parseOAuthTokenBody = (body, contentType) => {
335
+ const trimmed = body.trim();
336
+ const type = contentType !== null && contentType !== void 0 ? contentType : '';
337
+ if (type.includes('application/json') || trimmed.startsWith('{')) {
338
+ return JSON.parse(trimmed);
339
+ }
340
+ return Object.fromEntries(new URLSearchParams(trimmed));
341
+ };
342
+ const isRecord = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
343
+ const recordId = (value) => {
344
+ if (!isRecord(value) || typeof value.id !== 'string')
345
+ return undefined;
346
+ return value.id;
347
+ };
348
+ /** Keep stored secrets when a sanitized patch still carries the placeholder. */
349
+ export const restorePasswordPlaceholders = (incoming, existing) => {
350
+ if (incoming === passwordPlaceHolder) {
351
+ return existing === undefined ? incoming : existing;
352
+ }
353
+ if (Array.isArray(incoming)) {
354
+ const existingArr = Array.isArray(existing) ? existing : [];
355
+ return incoming.map((item, index) => {
356
+ const id = recordId(item);
357
+ const match = id
358
+ ? existingArr.find((entry) => recordId(entry) === id)
359
+ : existingArr[index];
360
+ return restorePasswordPlaceholders(item, match);
361
+ });
362
+ }
363
+ if (isRecord(incoming) && isRecord(existing)) {
364
+ return Object.fromEntries(Object.entries(incoming).map(([key, value]) => [
365
+ key,
366
+ restorePasswordPlaceholders(value, existing[key]),
367
+ ]));
368
+ }
369
+ return incoming;
370
+ };
@@ -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 '';
@@ -0,0 +1,9 @@
1
+ export declare const FALLBACK_TIME_ZONE = "UTC";
2
+ export declare const isIanaTimeZone: (value: string | null | undefined) => value is string;
3
+ export declare const browserTimeZone: () => string;
4
+ export declare const ianaTimeZones: () => string[];
5
+ /**
6
+ * Profile timezone, then community timezone, then `fallback` (browser TZ
7
+ * when omitted; emails pass UTC so the worker host TZ is never used).
8
+ */
9
+ export declare const resolveTimeZone: (profileTimeZone?: string | null, communityDefault?: string | null, fallback?: string | null) => string;
@@ -0,0 +1,44 @@
1
+ export const FALLBACK_TIME_ZONE = 'UTC';
2
+ export const isIanaTimeZone = (value) => {
3
+ if (!value)
4
+ return false;
5
+ try {
6
+ new Intl.DateTimeFormat('en-US', { timeZone: value }).format();
7
+ return true;
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ };
13
+ export const browserTimeZone = () => {
14
+ try {
15
+ const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
16
+ return isIanaTimeZone(timeZone) ? timeZone : FALLBACK_TIME_ZONE;
17
+ }
18
+ catch {
19
+ return FALLBACK_TIME_ZONE;
20
+ }
21
+ };
22
+ export const ianaTimeZones = () => {
23
+ const supportedValuesOf = Intl.supportedValuesOf;
24
+ if (typeof supportedValuesOf === 'function') {
25
+ return supportedValuesOf('timeZone');
26
+ }
27
+ const timeZone = browserTimeZone();
28
+ return timeZone === FALLBACK_TIME_ZONE
29
+ ? [FALLBACK_TIME_ZONE]
30
+ : [timeZone, FALLBACK_TIME_ZONE];
31
+ };
32
+ /**
33
+ * Profile timezone, then community timezone, then `fallback` (browser TZ
34
+ * when omitted; emails pass UTC so the worker host TZ is never used).
35
+ */
36
+ export const resolveTimeZone = (profileTimeZone, communityDefault, fallback) => {
37
+ if (isIanaTimeZone(profileTimeZone))
38
+ return profileTimeZone;
39
+ if (isIanaTimeZone(communityDefault))
40
+ return communityDefault;
41
+ if (isIanaTimeZone(fallback))
42
+ return fallback;
43
+ return browserTimeZone();
44
+ };
@@ -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
@@ -215,6 +215,26 @@ export declare const analyticsOverviewSchema: z.ZodObject<{
215
215
  value: z.ZodNumber;
216
216
  }, z.core.$strip>>>;
217
217
  }, z.core.$strip>;
218
+ verifiedMembers: z.ZodObject<{
219
+ key: z.ZodString;
220
+ value: z.ZodNumber;
221
+ previousValue: z.ZodNumber;
222
+ deltaPct: z.ZodNullable<z.ZodNumber>;
223
+ series: z.ZodOptional<z.ZodArray<z.ZodObject<{
224
+ day: z.ZodString;
225
+ value: z.ZodNumber;
226
+ }, z.core.$strip>>>;
227
+ }, z.core.$strip>;
228
+ unverifiedMembers: z.ZodObject<{
229
+ key: z.ZodString;
230
+ value: z.ZodNumber;
231
+ previousValue: z.ZodNumber;
232
+ deltaPct: z.ZodNullable<z.ZodNumber>;
233
+ series: z.ZodOptional<z.ZodArray<z.ZodObject<{
234
+ day: z.ZodString;
235
+ value: z.ZodNumber;
236
+ }, z.core.$strip>>>;
237
+ }, z.core.$strip>;
218
238
  activeMembers: z.ZodObject<{
219
239
  key: z.ZodString;
220
240
  value: z.ZodNumber;