@openpeepshq/common 0.1.45 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/capabilitiesHelpers.d.ts +9 -7
- package/dist/lib/capabilitiesHelpers.js +17 -2
- package/dist/lib/eventIcs.d.ts +17 -0
- package/dist/lib/eventIcs.js +82 -0
- package/dist/lib/eventRecurrence.d.ts +2 -0
- package/dist/lib/eventRecurrence.js +9 -4
- package/dist/lib/eventTime.d.ts +7 -0
- package/dist/lib/eventTime.js +16 -0
- package/dist/lib/federationHosts.d.ts +3 -0
- package/dist/lib/federationHosts.js +17 -0
- package/dist/lib/feedCursor.d.ts +14 -0
- package/dist/lib/feedCursor.js +22 -0
- package/dist/lib/feedFormat.d.ts +12 -0
- package/dist/lib/feedFormat.js +14 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/index.js +7 -0
- package/dist/lib/jamHelpers.d.ts +11 -2
- package/dist/lib/jamHelpers.js +37 -0
- package/dist/lib/legacyThemeRoot.d.ts +3 -0
- package/dist/lib/legacyThemeRoot.js +10 -0
- package/dist/lib/markdownHelpers.d.ts +8 -0
- package/dist/lib/markdownHelpers.js +32 -3
- package/dist/lib/postHelpers.d.ts +142 -3
- package/dist/lib/postHelpers.js +307 -4
- package/dist/lib/profileHelpers.d.ts +11 -0
- package/dist/lib/profileHelpers.js +31 -0
- package/dist/lib/reactions.d.ts +17 -0
- package/dist/lib/reactions.js +37 -0
- package/dist/lib/scopeHelpers.d.ts +31 -2
- package/dist/lib/scopeHelpers.js +37 -3
- package/dist/lib/ssoProviders.d.ts +72 -0
- package/dist/lib/ssoProviders.js +370 -0
- package/dist/lib/timeZone.d.ts +9 -0
- package/dist/lib/timeZone.js +44 -0
- package/dist/types/analytics.d.ts +20 -0
- package/dist/types/analytics.js +4 -0
- package/dist/types/api.d.ts +41799 -11853
- package/dist/types/api.js +52 -4
- package/dist/types/auth.d.ts +20 -6
- package/dist/types/capabilities.d.ts +15 -1
- package/dist/types/capabilities.js +51 -0
- package/dist/types/config.d.ts +96 -0
- package/dist/types/config.js +53 -4
- package/dist/types/db.d.ts +1155 -164
- package/dist/types/db.js +14 -0
- package/dist/types/export.d.ts +120 -0
- package/dist/types/export.js +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/internal.d.ts +2577 -524
- package/dist/types/internal.js +6 -0
- package/dist/types/models.d.ts +63 -7
- package/dist/types/models.js +39 -2
- package/dist/types/plugins.d.ts +22 -0
- package/dist/types/plugins.js +66 -0
- package/dist/types/roleDefaults.d.ts +31 -0
- package/dist/types/roleDefaults.js +110 -0
- package/dist/types/stats.d.ts +54606 -6065
- package/dist/types/stats.js +30 -0
- package/dist/types/utils.d.ts +2 -0
- package/dist/types/utils.js +1 -3
- package/package.json +1 -1
|
@@ -8,8 +8,21 @@ export declare const scopeMatches: ({ scopes, requiredScope, }: {
|
|
|
8
8
|
requiredScope: Scope;
|
|
9
9
|
}) => boolean;
|
|
10
10
|
export declare const getPublicPostReadScope: (postId: string) => Scope;
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Posts with `public` visibility — and posts in groups that grant the needed
|
|
13
|
+
* *-read caps to `none` — are readable without auth; grant read scope for
|
|
14
|
+
* that post id (same pattern as {@link withPublicGroupReadScopes}).
|
|
15
|
+
*/
|
|
16
|
+
export declare const withPublicPostReadScopes: (authData: AuthorizationData, post: Pick<PublicPost, "id" | "visibility"> & {
|
|
17
|
+
/** Only the group's `none` capabilities matter for the public check. */
|
|
18
|
+
group?: {
|
|
19
|
+
capabilities?: {
|
|
20
|
+
none?: {
|
|
21
|
+
add?: string[];
|
|
22
|
+
};
|
|
23
|
+
} | null;
|
|
24
|
+
} | null;
|
|
25
|
+
}, neededCapabilities: string[]) => AuthorizationData;
|
|
13
26
|
export declare const getPublicGroupReadScope: (groupId: string) => Scope;
|
|
14
27
|
/**
|
|
15
28
|
* Groups that grant the needed *-read caps to relationship `none` are readable
|
|
@@ -23,3 +36,19 @@ export declare const withPublicGroupReadScopes: (authData: AuthorizationData, gr
|
|
|
23
36
|
};
|
|
24
37
|
} | null;
|
|
25
38
|
}, neededCapabilities: string[]) => AuthorizationData;
|
|
39
|
+
export declare const getPublicProfileReadScope: (profileId: string) => Scope;
|
|
40
|
+
/**
|
|
41
|
+
* Profiles whose capabilities config grants the needed *-read caps to
|
|
42
|
+
* relationship `none` are readable without auth (same pattern as
|
|
43
|
+
* {@link withPublicGroupReadScopes}). Community-wide `publicContent` is
|
|
44
|
+
* still enforced by `ensureAccess` on the profile endpoints.
|
|
45
|
+
*/
|
|
46
|
+
export declare const withPublicProfileReadScopes: (authData: AuthorizationData, profile: {
|
|
47
|
+
id: string;
|
|
48
|
+
}, neededCapabilities: string[], config: {
|
|
49
|
+
profile?: {
|
|
50
|
+
none?: {
|
|
51
|
+
add?: string[];
|
|
52
|
+
};
|
|
53
|
+
} | null;
|
|
54
|
+
}) => AuthorizationData;
|
package/dist/lib/scopeHelpers.js
CHANGED
|
@@ -45,11 +45,19 @@ export const getPublicPostReadScope = (postId) => ({
|
|
|
45
45
|
scopeLevel: 'read',
|
|
46
46
|
resource: { type: 'posts', id: postId },
|
|
47
47
|
});
|
|
48
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Posts with `public` visibility — and posts in groups that grant the needed
|
|
50
|
+
* *-read caps to `none` — are readable without auth; grant read scope for
|
|
51
|
+
* that post id (same pattern as {@link withPublicGroupReadScopes}).
|
|
52
|
+
*/
|
|
49
53
|
export const withPublicPostReadScopes = (authData, post, neededCapabilities) => {
|
|
50
54
|
var _a;
|
|
51
|
-
if (
|
|
52
|
-
|
|
55
|
+
if (!neededCapabilities.every((c) => c.endsWith('-read'))) {
|
|
56
|
+
return authData;
|
|
57
|
+
}
|
|
58
|
+
const publicGroupPost = post.visibility === 'group' &&
|
|
59
|
+
neededCapabilities.every((c) => { var _a, _b, _c, _d, _e; return (_e = (_d = (_c = (_b = (_a = post.group) === null || _a === void 0 ? void 0 : _a.capabilities) === null || _b === void 0 ? void 0 : _b.none) === null || _c === void 0 ? void 0 : _c.add) === null || _d === void 0 ? void 0 : _d.includes(c)) !== null && _e !== void 0 ? _e : false; });
|
|
60
|
+
if (post.visibility !== 'public' && !publicGroupPost) {
|
|
53
61
|
return authData;
|
|
54
62
|
}
|
|
55
63
|
const publicReadScope = getPublicPostReadScope(post.id);
|
|
@@ -83,3 +91,29 @@ export const withPublicGroupReadScopes = (authData, group, neededCapabilities) =
|
|
|
83
91
|
}
|
|
84
92
|
return { ...authData, scopes: [...scopes, publicReadScope] };
|
|
85
93
|
};
|
|
94
|
+
export const getPublicProfileReadScope = (profileId) => ({
|
|
95
|
+
scopeLevel: 'read',
|
|
96
|
+
resource: { type: 'profiles', id: profileId },
|
|
97
|
+
});
|
|
98
|
+
/**
|
|
99
|
+
* Profiles whose capabilities config grants the needed *-read caps to
|
|
100
|
+
* relationship `none` are readable without auth (same pattern as
|
|
101
|
+
* {@link withPublicGroupReadScopes}). Community-wide `publicContent` is
|
|
102
|
+
* still enforced by `ensureAccess` on the profile endpoints.
|
|
103
|
+
*/
|
|
104
|
+
export const withPublicProfileReadScopes = (authData, profile, neededCapabilities, config) => {
|
|
105
|
+
var _a, _b, _c, _d;
|
|
106
|
+
if (!neededCapabilities.every((c) => c.endsWith('-read'))) {
|
|
107
|
+
return authData;
|
|
108
|
+
}
|
|
109
|
+
const noneAdd = (_c = (_b = (_a = config.profile) === null || _a === void 0 ? void 0 : _a.none) === null || _b === void 0 ? void 0 : _b.add) !== null && _c !== void 0 ? _c : [];
|
|
110
|
+
if (!neededCapabilities.every((c) => noneAdd.includes(c))) {
|
|
111
|
+
return authData;
|
|
112
|
+
}
|
|
113
|
+
const publicReadScope = getPublicProfileReadScope(profile.id);
|
|
114
|
+
const scopes = (_d = authData.scopes) !== null && _d !== void 0 ? _d : [];
|
|
115
|
+
if (scopeMatches({ scopes, requiredScope: publicReadScope })) {
|
|
116
|
+
return authData;
|
|
117
|
+
}
|
|
118
|
+
return { ...authData, scopes: [...scopes, publicReadScope] };
|
|
119
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -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;
|
package/dist/types/analytics.js
CHANGED
|
@@ -134,6 +134,10 @@ export const analyticsOverviewSchema = z.object({
|
|
|
134
134
|
/** Cumulative posts created on or before the range end. */
|
|
135
135
|
allTimePosts: analyticsMetricCardSchema,
|
|
136
136
|
totalMembers: analyticsMetricCardSchema,
|
|
137
|
+
/** Cumulative local members with a verified email, on or before the range end. */
|
|
138
|
+
verifiedMembers: analyticsMetricCardSchema,
|
|
139
|
+
/** Cumulative local members with an unverified email, on or before the range end. */
|
|
140
|
+
unverifiedMembers: analyticsMetricCardSchema,
|
|
137
141
|
activeMembers: analyticsMetricCardSchema,
|
|
138
142
|
totalGroups: analyticsMetricCardSchema,
|
|
139
143
|
}),
|