@aphexcms/cms-core 11.3.0 → 12.0.0-next.20261109083516
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/admin/client-auth.svelte.d.ts +120 -0
- package/dist/admin/client-auth.svelte.d.ts.map +1 -0
- package/dist/admin/client-auth.svelte.js +14 -0
- package/dist/admin/client-config.d.ts +72 -0
- package/dist/admin/client-config.d.ts.map +1 -0
- package/dist/admin/client-config.js +1 -0
- package/dist/admin/settings-header-actions.d.ts +12 -0
- package/dist/admin/settings-header-actions.d.ts.map +1 -0
- package/dist/admin/settings-header-actions.js +1 -0
- package/dist/admin/view-data.d.ts +189 -0
- package/dist/admin/view-data.d.ts.map +1 -0
- package/dist/admin/view-data.js +1 -0
- package/dist/admin.css +6 -0
- package/dist/api/invitations.d.ts +2 -2
- package/dist/api/invitations.d.ts.map +1 -1
- package/dist/api/organizations.d.ts +5 -4
- package/dist/api/organizations.d.ts.map +1 -1
- package/dist/api/organizations.js +2 -3
- package/dist/api/user.d.ts +6 -1
- package/dist/api/user.d.ts.map +1 -1
- package/dist/api/user.js +7 -0
- package/dist/app-augment.d.ts +2 -3
- package/dist/app-augment.d.ts.map +1 -1
- package/dist/app.d.ts +1 -1
- package/dist/auth/auth-errors.d.ts +6 -0
- package/dist/auth/auth-errors.d.ts.map +1 -1
- package/dist/auth/auth-errors.js +8 -0
- package/dist/auth/auth-hooks.d.ts.map +1 -1
- package/dist/auth/auth-hooks.js +36 -17
- package/dist/auth/invitation-email.d.ts +9 -0
- package/dist/auth/invitation-email.d.ts.map +1 -0
- package/dist/auth/invitation-email.js +49 -0
- package/dist/auth/pages.d.ts +16 -0
- package/dist/auth/pages.d.ts.map +1 -0
- package/dist/auth/pages.js +23 -0
- package/dist/auth/provider.d.ts +31 -1
- package/dist/auth/provider.d.ts.map +1 -1
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +9 -0
- package/dist/client/ui.d.ts +16 -0
- package/dist/client/ui.d.ts.map +1 -1
- package/dist/client/ui.js +26 -1
- package/dist/components/AphexStudio.svelte +268 -0
- package/dist/components/AphexStudio.svelte.d.ts +16 -0
- package/dist/components/AphexStudio.svelte.d.ts.map +1 -0
- package/dist/components/admin/AccountSettings.svelte +339 -0
- package/dist/components/admin/AccountSettings.svelte.d.ts +8 -0
- package/dist/components/admin/AccountSettings.svelte.d.ts.map +1 -0
- package/dist/components/admin/AccountSettingsView.svelte +61 -0
- package/dist/components/admin/AccountSettingsView.svelte.d.ts +19 -0
- package/dist/components/admin/AccountSettingsView.svelte.d.ts.map +1 -0
- package/dist/components/admin/ApiKeysSettings.svelte +435 -0
- package/dist/components/admin/ApiKeysSettings.svelte.d.ts +15 -0
- package/dist/components/admin/ApiKeysSettings.svelte.d.ts.map +1 -0
- package/dist/components/admin/AuthPageShell.svelte +32 -0
- package/dist/components/admin/AuthPageShell.svelte.d.ts +16 -0
- package/dist/components/admin/AuthPageShell.svelte.d.ts.map +1 -0
- package/dist/components/admin/CreateOrganization.svelte +158 -0
- package/dist/components/admin/CreateOrganization.svelte.d.ts +11 -0
- package/dist/components/admin/CreateOrganization.svelte.d.ts.map +1 -0
- package/dist/components/admin/DeleteAccountSettings.svelte +124 -0
- package/dist/components/admin/DeleteAccountSettings.svelte.d.ts +7 -0
- package/dist/components/admin/DeleteAccountSettings.svelte.d.ts.map +1 -0
- package/dist/components/admin/DeleteOrganizationSettings.svelte +123 -0
- package/dist/components/admin/DeleteOrganizationSettings.svelte.d.ts +11 -0
- package/dist/components/admin/DeleteOrganizationSettings.svelte.d.ts.map +1 -0
- package/dist/components/admin/DocumentEditor.svelte +92 -22
- package/dist/components/admin/DocumentEditor.svelte.d.ts.map +1 -1
- package/dist/components/admin/GeneralSettings.svelte +45 -0
- package/dist/components/admin/GeneralSettings.svelte.d.ts +10 -0
- package/dist/components/admin/GeneralSettings.svelte.d.ts.map +1 -0
- package/dist/components/admin/GodModeView.svelte +112 -0
- package/dist/components/admin/GodModeView.svelte.d.ts +9 -0
- package/dist/components/admin/GodModeView.svelte.d.ts.map +1 -0
- package/dist/components/admin/InvitationsView.svelte +277 -0
- package/dist/components/admin/InvitationsView.svelte.d.ts +11 -0
- package/dist/components/admin/InvitationsView.svelte.d.ts.map +1 -0
- package/dist/components/admin/InviteView.svelte +98 -0
- package/dist/components/admin/InviteView.svelte.d.ts +9 -0
- package/dist/components/admin/InviteView.svelte.d.ts.map +1 -0
- package/dist/components/admin/LoginView.svelte +478 -0
- package/dist/components/admin/LoginView.svelte.d.ts +5 -0
- package/dist/components/admin/LoginView.svelte.d.ts.map +1 -0
- package/dist/components/admin/MembersSettings.svelte +25 -3
- package/dist/components/admin/MembersSettings.svelte.d.ts +5 -1
- package/dist/components/admin/MembersSettings.svelte.d.ts.map +1 -1
- package/dist/components/admin/OrganizationSettings.svelte +367 -0
- package/dist/components/admin/OrganizationSettings.svelte.d.ts +9 -0
- package/dist/components/admin/OrganizationSettings.svelte.d.ts.map +1 -0
- package/dist/components/admin/OrganizationsList.svelte +92 -0
- package/dist/components/admin/OrganizationsList.svelte.d.ts +8 -0
- package/dist/components/admin/OrganizationsList.svelte.d.ts.map +1 -0
- package/dist/components/admin/OrganizationsView.svelte +31 -0
- package/dist/components/admin/OrganizationsView.svelte.d.ts +9 -0
- package/dist/components/admin/OrganizationsView.svelte.d.ts.map +1 -0
- package/dist/components/admin/PasswordInput.svelte +43 -0
- package/dist/components/admin/PasswordInput.svelte.d.ts +8 -0
- package/dist/components/admin/PasswordInput.svelte.d.ts.map +1 -0
- package/dist/components/admin/PasswordSettings.svelte +179 -0
- package/dist/components/admin/PasswordSettings.svelte.d.ts +4 -0
- package/dist/components/admin/PasswordSettings.svelte.d.ts.map +1 -0
- package/dist/components/admin/PreferencesSettings.svelte +80 -0
- package/dist/components/admin/PreferencesSettings.svelte.d.ts +20 -0
- package/dist/components/admin/PreferencesSettings.svelte.d.ts.map +1 -0
- package/dist/components/admin/ResetPasswordView.svelte +117 -0
- package/dist/components/admin/ResetPasswordView.svelte.d.ts +9 -0
- package/dist/components/admin/ResetPasswordView.svelte.d.ts.map +1 -0
- package/dist/components/admin/RolesSettings.svelte +360 -0
- package/dist/components/admin/RolesSettings.svelte.d.ts +11 -0
- package/dist/components/admin/RolesSettings.svelte.d.ts.map +1 -0
- package/dist/components/admin/SchemaField.svelte +2 -1
- package/dist/components/admin/SchemaField.svelte.d.ts.map +1 -1
- package/dist/components/admin/SettingsHeaderActions.svelte +25 -0
- package/dist/components/admin/SettingsHeaderActions.svelte.d.ts +8 -0
- package/dist/components/admin/SettingsHeaderActions.svelte.d.ts.map +1 -0
- package/dist/components/admin/SettingsShell.svelte +136 -0
- package/dist/components/admin/SettingsShell.svelte.d.ts +9 -0
- package/dist/components/admin/SettingsShell.svelte.d.ts.map +1 -0
- package/dist/components/admin/TwoFactorChallengeView.svelte +377 -0
- package/dist/components/admin/TwoFactorChallengeView.svelte.d.ts +11 -0
- package/dist/components/admin/TwoFactorChallengeView.svelte.d.ts.map +1 -0
- package/dist/components/admin/TwoFactorSettings.svelte +436 -0
- package/dist/components/admin/TwoFactorSettings.svelte.d.ts +7 -0
- package/dist/components/admin/TwoFactorSettings.svelte.d.ts.map +1 -0
- package/dist/components/admin/fields/ImageField.svelte +4 -2
- package/dist/components/admin/fields/richtext/PortableTextImageView.svelte +3 -2
- package/dist/components/admin/fields/richtext/RichtextField.svelte +48 -6
- package/dist/components/admin/fields/richtext/RichtextField.svelte.d.ts.map +1 -1
- package/dist/components/layout/sidebar/NavUser.svelte +2 -2
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/email/index.d.ts +1 -0
- package/dist/email/index.d.ts.map +1 -1
- package/dist/email/index.js +2 -0
- package/dist/email/interfaces/email.d.ts +2 -0
- package/dist/email/interfaces/email.d.ts.map +1 -1
- package/dist/email/link-email.d.ts +15 -0
- package/dist/email/link-email.d.ts.map +1 -0
- package/dist/email/link-email.js +30 -0
- package/dist/field-validation/utils.d.ts +29 -0
- package/dist/field-validation/utils.d.ts.map +1 -1
- package/dist/field-validation/utils.js +138 -5
- package/dist/graphql/index.d.ts.map +1 -1
- package/dist/graphql/index.js +1 -1
- package/dist/hooks.d.ts +6 -3
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +53 -17
- package/dist/jobs/recurring.d.ts +4 -1
- package/dist/jobs/recurring.d.ts.map +1 -1
- package/dist/jobs/recurring.js +28 -0
- package/dist/local-api/auth-helpers.d.ts +4 -4
- package/dist/local-api/auth-helpers.js +4 -4
- package/dist/local-api/collection-api.d.ts +10 -1
- package/dist/local-api/collection-api.d.ts.map +1 -1
- package/dist/local-api/collection-api.js +25 -7
- package/dist/local-api/index.d.ts +1 -1
- package/dist/local-api/index.d.ts.map +1 -1
- package/dist/local-api/index.js +7 -5
- package/dist/local-api/types.d.ts +1 -1
- package/dist/preview/perspective.d.ts +1 -1
- package/dist/preview/perspective.js +1 -1
- package/dist/resolve-config.d.ts +22 -0
- package/dist/resolve-config.d.ts.map +1 -0
- package/dist/resolve-config.js +106 -0
- package/dist/routes/assets-cdn.d.ts +7 -2
- package/dist/routes/assets-cdn.d.ts.map +1 -1
- package/dist/routes/assets-cdn.js +1 -1
- package/dist/server/api/index.d.ts +1 -2
- package/dist/server/api/index.d.ts.map +1 -1
- package/dist/server/api/index.js +10 -3
- package/dist/server/api/openapi/registry.d.ts.map +1 -1
- package/dist/server/api/openapi/registry.js +62 -0
- package/dist/server/api/routes/api-keys.d.ts +4 -0
- package/dist/server/api/routes/api-keys.d.ts.map +1 -0
- package/dist/server/api/routes/api-keys.js +88 -0
- package/dist/server/api/routes/documents-by-id.d.ts.map +1 -1
- package/dist/server/api/routes/documents-by-id.js +16 -1
- package/dist/server/api/routes/documents-publish.d.ts.map +1 -1
- package/dist/server/api/routes/documents-publish.js +11 -1
- package/dist/server/api/routes/documents.d.ts.map +1 -1
- package/dist/server/api/routes/documents.js +16 -2
- package/dist/server/api/routes/instance-settings.d.ts +4 -0
- package/dist/server/api/routes/instance-settings.d.ts.map +1 -0
- package/dist/server/api/routes/instance-settings.js +47 -0
- package/dist/server/api/routes/invitations.d.ts +9 -0
- package/dist/server/api/routes/invitations.d.ts.map +1 -0
- package/dist/server/api/routes/invitations.js +79 -0
- package/dist/server/api/routes/organizations-invitations.d.ts +0 -6
- package/dist/server/api/routes/organizations-invitations.d.ts.map +1 -1
- package/dist/server/api/routes/organizations-invitations.js +6 -7
- package/dist/server/api/routes/organizations-team.d.ts.map +1 -1
- package/dist/server/api/routes/organizations-team.js +2 -52
- package/dist/server/api/routes/organizations.d.ts.map +1 -1
- package/dist/server/api/routes/organizations.js +35 -9
- package/dist/server/core-routes.d.ts +8 -0
- package/dist/server/core-routes.d.ts.map +1 -0
- package/dist/server/core-routes.js +67 -0
- package/dist/server/index.d.ts +5 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +7 -1
- package/dist/server/pages/admin.d.ts +24 -0
- package/dist/server/pages/admin.d.ts.map +1 -0
- package/dist/server/pages/admin.js +468 -0
- package/dist/server/queries/organization-team.d.ts +14 -0
- package/dist/server/queries/organization-team.d.ts.map +1 -0
- package/dist/server/queries/organization-team.js +65 -0
- package/dist/server/queries/pending-invitations.d.ts +8 -0
- package/dist/server/queries/pending-invitations.d.ts.map +1 -0
- package/dist/server/queries/pending-invitations.js +24 -0
- package/dist/types/api-key.d.ts +18 -0
- package/dist/types/api-key.d.ts.map +1 -0
- package/dist/types/api-key.js +1 -0
- package/dist/types/auth.d.ts +35 -0
- package/dist/types/auth.d.ts.map +1 -1
- package/dist/types/capabilities.d.ts +1 -2
- package/dist/types/capabilities.d.ts.map +1 -1
- package/dist/types/config.d.ts +124 -4
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/filters.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/organization.d.ts +1 -1
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +46 -39
- package/package.json +19 -29
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import { error, redirect } from '@sveltejs/kit';
|
|
2
|
+
import { isAccepted, isExpired } from '../../auth/invitation-status.js';
|
|
3
|
+
import { isViewer } from '../../types/auth.js';
|
|
4
|
+
import { hasCapability } from '../../types/capabilities.js';
|
|
5
|
+
import { getOrganizationTeam } from '../queries/organization-team.js';
|
|
6
|
+
import { getPendingInvitations } from '../queries/pending-invitations.js';
|
|
7
|
+
import { isApiDocsEnabled, API_DOCS_PATH } from '../../api/docs-ui.js';
|
|
8
|
+
import { isInstanceUnclaimed } from '../../auth/bootstrap.js';
|
|
9
|
+
/**
|
|
10
|
+
* The single SSR load behind the embedded `/admin/[...path]` catch-all. It
|
|
11
|
+
* switches on the rest param and returns the payload for the matching view,
|
|
12
|
+
* discriminated by `view` so `<AphexStudio>` knows what to mount.
|
|
13
|
+
*
|
|
14
|
+
* This is the "feed the routes" half of embedded Aphex: a host wires it in one
|
|
15
|
+
* line (`export const load = createAdminLoad()`), and every admin view a release
|
|
16
|
+
* adds is served without the host touching a file.
|
|
17
|
+
*
|
|
18
|
+
* A route the host defines under `/admin` wins over this catch-all, and gets none of
|
|
19
|
+
* the admin's chrome, because the sidebar belongs to `<AphexStudio>`.
|
|
20
|
+
*/
|
|
21
|
+
export function createAdminLoad() {
|
|
22
|
+
return async function load(event) {
|
|
23
|
+
const view = await loadView(event);
|
|
24
|
+
const standalone = STANDALONE_VIEWS.has(view.view);
|
|
25
|
+
const auth = event.locals.aphexAuth;
|
|
26
|
+
const hasShell = !standalone && auth?.type === 'session';
|
|
27
|
+
return {
|
|
28
|
+
...view,
|
|
29
|
+
title: event.locals.aphexCMS.config.customization?.branding?.title,
|
|
30
|
+
standalone,
|
|
31
|
+
shell: hasShell ? await loadShell(event.locals, auth) : null,
|
|
32
|
+
rbac: hasShell
|
|
33
|
+
? { role: auth.organizationRole ?? null, capabilities: auth.capabilities ?? [] }
|
|
34
|
+
: undefined
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const STANDALONE_VIEWS = new Set([
|
|
39
|
+
'login',
|
|
40
|
+
'invitations',
|
|
41
|
+
'invite',
|
|
42
|
+
'reset-password',
|
|
43
|
+
'two-factor'
|
|
44
|
+
]);
|
|
45
|
+
/** Everything after `/admin/<prefix>/`, or null when the path is something else. */
|
|
46
|
+
function tokenAfter(path, prefix) {
|
|
47
|
+
return path.startsWith(`${prefix}/`) ? path.slice(prefix.length + 1) || null : null;
|
|
48
|
+
}
|
|
49
|
+
async function loadView(event) {
|
|
50
|
+
// `/admin` → path '' (rest param matches zero segments). Trim any trailing
|
|
51
|
+
// slash so `/admin/activity/` and `/admin/activity` resolve the same view.
|
|
52
|
+
const path = (event.params.path ?? '').replace(/\/+$/, '');
|
|
53
|
+
const auth = event.locals.aphexAuth;
|
|
54
|
+
// The account pages come first: these are the paths the auth hook lets through
|
|
55
|
+
// without a full session (`isPublicAdminPath`).
|
|
56
|
+
const inviteToken = tokenAfter(path, 'invite');
|
|
57
|
+
if (inviteToken)
|
|
58
|
+
return loadInvite(event.locals, event.url, inviteToken);
|
|
59
|
+
if (path === 'invitations')
|
|
60
|
+
return loadInvitations(event.locals, event.url);
|
|
61
|
+
const resetToken = tokenAfter(path, 'reset-password');
|
|
62
|
+
if (resetToken) {
|
|
63
|
+
if (auth)
|
|
64
|
+
throw redirect(302, '/admin');
|
|
65
|
+
return {
|
|
66
|
+
view: 'reset-password',
|
|
67
|
+
token: resetToken,
|
|
68
|
+
branding: await resolveLoginBranding(event.locals, event.url)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (path === 'two-factor')
|
|
72
|
+
return loadTwoFactor(event);
|
|
73
|
+
// Login folds into the one admin catch-all (Payload-style). An
|
|
74
|
+
// unauthenticated request to any `/admin/*` URL renders the login view in
|
|
75
|
+
// place rather than redirecting to a host-owned route — so auth adds zero
|
|
76
|
+
// host files. An authenticated user hitting `/admin/login` is sent on to the
|
|
77
|
+
// studio. (The auth hook carries any `?error=` code here via a one-time
|
|
78
|
+
// redirect to `/admin/login`; see `handleAuthHook`.)
|
|
79
|
+
if (!auth) {
|
|
80
|
+
return loadLogin(event.locals, event.url);
|
|
81
|
+
}
|
|
82
|
+
if (path === 'login') {
|
|
83
|
+
throw redirect(302, '/admin');
|
|
84
|
+
}
|
|
85
|
+
switch (path) {
|
|
86
|
+
case '':
|
|
87
|
+
return loadStudio(event.locals, auth);
|
|
88
|
+
case 'activity':
|
|
89
|
+
// ActivityView fetches /api/jobs and /api/events client-side; the
|
|
90
|
+
// session + capability it needs come from the shell.
|
|
91
|
+
return { view: 'activity' };
|
|
92
|
+
case 'settings': {
|
|
93
|
+
// General (organization identity + danger zone). Requires org.settings;
|
|
94
|
+
// without it, send to the profile page (always available) so the default
|
|
95
|
+
// settings URL never lands on a locked view.
|
|
96
|
+
if (auth.type !== 'session') {
|
|
97
|
+
throw error(401, 'Session authentication required');
|
|
98
|
+
}
|
|
99
|
+
if (!hasCapability(auth, 'org.settings')) {
|
|
100
|
+
throw redirect(302, '/admin/settings/account');
|
|
101
|
+
}
|
|
102
|
+
const { databaseAdapter } = event.locals.aphexCMS;
|
|
103
|
+
const [organization, memberRows] = await Promise.all([
|
|
104
|
+
databaseAdapter.findOrganizationById(auth.organizationId),
|
|
105
|
+
databaseAdapter.findOrganizationMembers(auth.organizationId)
|
|
106
|
+
]);
|
|
107
|
+
return {
|
|
108
|
+
view: 'settings',
|
|
109
|
+
tab: 'general',
|
|
110
|
+
organization,
|
|
111
|
+
memberCount: memberRows.length,
|
|
112
|
+
canDelete: auth.organizationRole === 'owner'
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
case 'settings/account': {
|
|
116
|
+
// Profile + preferences + security. 2FA availability is derived from the
|
|
117
|
+
// host's auth features (surfaced via config.auth.features) and whether an
|
|
118
|
+
// email adapter exists — no app-only auth-config import.
|
|
119
|
+
if (auth.type !== 'session') {
|
|
120
|
+
throw error(401, 'Session authentication required');
|
|
121
|
+
}
|
|
122
|
+
const { databaseAdapter, authFeatures, emailAdapter, auth: provider } = event.locals.aphexCMS;
|
|
123
|
+
// Name/image come from the user row, not the cached session cookie, so a
|
|
124
|
+
// just-edited profile doesn't read back stale. The row wins wholesale
|
|
125
|
+
// when present (an absent image means "removed", not "unchanged").
|
|
126
|
+
const profile = provider ? await provider.getUserById(auth.user.id) : null;
|
|
127
|
+
const user = profile
|
|
128
|
+
? { ...auth.user, name: profile.name, image: profile.image }
|
|
129
|
+
: auth.user;
|
|
130
|
+
const userProfile = await databaseAdapter.findUserProfileById(auth.user.id);
|
|
131
|
+
const userPreferences = userProfile?.preferences ?? null;
|
|
132
|
+
let hasChildOrganizations = false;
|
|
133
|
+
if (auth.organizationId && databaseAdapter.hierarchyEnabled) {
|
|
134
|
+
const childOrgs = await databaseAdapter.getChildOrganizations(auth.organizationId);
|
|
135
|
+
hasChildOrganizations = childOrgs.length > 0;
|
|
136
|
+
}
|
|
137
|
+
const { totpAvailable } = availableTwoFactorMethods(authFeatures, emailAdapter);
|
|
138
|
+
return {
|
|
139
|
+
view: 'settings',
|
|
140
|
+
tab: 'account',
|
|
141
|
+
user,
|
|
142
|
+
userPreferences,
|
|
143
|
+
hasChildOrganizations,
|
|
144
|
+
totpAvailable
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
case 'settings/members': {
|
|
148
|
+
// Members is SSR'd (not onMount-fetched) via the shared team query —
|
|
149
|
+
// the same code the HTTP route serves.
|
|
150
|
+
if (auth.type !== 'session') {
|
|
151
|
+
throw error(401, 'Session authentication required');
|
|
152
|
+
}
|
|
153
|
+
const team = await getOrganizationTeam(event.locals.aphexCMS, auth, event.url.origin);
|
|
154
|
+
return { view: 'settings', tab: 'members', team };
|
|
155
|
+
}
|
|
156
|
+
case 'settings/roles': {
|
|
157
|
+
if (auth.type !== 'session') {
|
|
158
|
+
throw error(401, 'Session authentication required');
|
|
159
|
+
}
|
|
160
|
+
const { rolesService, databaseAdapter, partResolver } = event.locals.aphexCMS;
|
|
161
|
+
const [roles, memberRows] = await Promise.all([
|
|
162
|
+
rolesService.listRoles(auth.organizationId),
|
|
163
|
+
databaseAdapter.findOrganizationMembers(auth.organizationId)
|
|
164
|
+
]);
|
|
165
|
+
// Pre-compute per-role member counts so the panel needs no user/org join.
|
|
166
|
+
const roleMemberCounts = {};
|
|
167
|
+
for (const m of memberRows) {
|
|
168
|
+
roleMemberCounts[m.role] = (roleMemberCounts[m.role] ?? 0) + 1;
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
view: 'settings',
|
|
172
|
+
tab: 'roles',
|
|
173
|
+
roles,
|
|
174
|
+
capabilityCatalog: partResolver.capabilityCatalog(),
|
|
175
|
+
roleMemberCounts
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
case 'settings/api-keys': {
|
|
179
|
+
// Personal + service tokens, scoped to the caller's organization. The
|
|
180
|
+
// listing comes through the AuthProvider port (host owns better-auth);
|
|
181
|
+
// the key secret is never returned — it exists once, at creation.
|
|
182
|
+
if (auth.type !== 'session') {
|
|
183
|
+
throw error(401, 'Session authentication required');
|
|
184
|
+
}
|
|
185
|
+
if (!hasCapability(auth, 'apiKey.manage')) {
|
|
186
|
+
throw error(403, 'You do not have permission to manage API keys');
|
|
187
|
+
}
|
|
188
|
+
const { auth: provider, config } = event.locals.aphexCMS;
|
|
189
|
+
const allKeys = provider?.listApiKeys ? await provider.listApiKeys(auth.user.id) : [];
|
|
190
|
+
// Keys carry their owning org in metadata; show only this org's.
|
|
191
|
+
const apiKeys = allKeys.filter((key) => key.organizationId === auth.organizationId);
|
|
192
|
+
return {
|
|
193
|
+
view: 'settings',
|
|
194
|
+
tab: 'api-keys',
|
|
195
|
+
apiKeys,
|
|
196
|
+
organizationRole: auth.organizationRole ?? null,
|
|
197
|
+
// Resolved here rather than assumed in the component: the reference is
|
|
198
|
+
// unmounted on an instance that opts out, and a link to a 404 is worse
|
|
199
|
+
// than no link. Same predicate the route itself mounts on.
|
|
200
|
+
apiDocsHref: isApiDocsEnabled(config) ? API_DOCS_PATH : null
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
case 'settings/plugins':
|
|
204
|
+
// PluginSettingsPanel renders app-provided plugins (passed to
|
|
205
|
+
// AphexStudio as a prop) and reads/writes its own settings via the API.
|
|
206
|
+
return { view: 'settings', tab: 'plugins' };
|
|
207
|
+
case 'organizations':
|
|
208
|
+
if (auth.type !== 'session') {
|
|
209
|
+
throw error(401, 'Session authentication required');
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
view: 'organizations',
|
|
213
|
+
organizations: await loadUserOrganizations(event.locals, auth),
|
|
214
|
+
parentOption: await loadParentOption(event.locals, auth)
|
|
215
|
+
};
|
|
216
|
+
case 'god-mode':
|
|
217
|
+
requireSuperAdmin(auth);
|
|
218
|
+
return { view: 'god-mode', tab: 'general' };
|
|
219
|
+
case 'god-mode/organizations': {
|
|
220
|
+
requireSuperAdmin(auth);
|
|
221
|
+
const { databaseAdapter } = event.locals.aphexCMS;
|
|
222
|
+
const [organizations, instanceSettings] = await Promise.all([
|
|
223
|
+
databaseAdapter.findAllOrganizations(),
|
|
224
|
+
databaseAdapter.getInstanceSettings()
|
|
225
|
+
]);
|
|
226
|
+
return {
|
|
227
|
+
view: 'god-mode',
|
|
228
|
+
tab: 'organizations',
|
|
229
|
+
organizations: await Promise.all(organizations.map((organization) => describeOrganization(event.locals, organization, { role: 'owner', isActive: false }))),
|
|
230
|
+
allowUserOrgCreation: instanceSettings.allowUserOrgCreation ?? false
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
default:
|
|
234
|
+
throw error(404, `Unknown admin route: /admin/${path}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/** Everything the sidebar shows, from the session and the database. */
|
|
238
|
+
async function loadShell(locals, auth) {
|
|
239
|
+
const { databaseAdapter, aiProvider } = locals.aphexCMS;
|
|
240
|
+
const [memberships, canCreate, faviconUrl] = await Promise.all([
|
|
241
|
+
databaseAdapter.findUserOrganizations(auth.user.id),
|
|
242
|
+
canCreateOrganization(locals, auth),
|
|
243
|
+
resolveFavicon(locals, auth)
|
|
244
|
+
]);
|
|
245
|
+
const organizations = memberships.map(({ organization, member }) => ({
|
|
246
|
+
id: organization.id,
|
|
247
|
+
name: organization.name,
|
|
248
|
+
slug: organization.slug,
|
|
249
|
+
role: member.role,
|
|
250
|
+
isActive: organization.id === auth.organizationId,
|
|
251
|
+
metadata: organization.metadata
|
|
252
|
+
}));
|
|
253
|
+
return {
|
|
254
|
+
auth,
|
|
255
|
+
organizations,
|
|
256
|
+
activeOrganization: organizations.find((organization) => organization.isActive),
|
|
257
|
+
canCreateOrganization: canCreate,
|
|
258
|
+
// The assistant's route 404s with no provider, so don't offer it.
|
|
259
|
+
agentEnabled: Boolean(aiProvider),
|
|
260
|
+
faviconUrl
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/** A branding lookup must never take the admin down, so a resolver that throws means none. */
|
|
264
|
+
async function resolveFavicon(locals, auth) {
|
|
265
|
+
const favicon = locals.aphexCMS.config.customization?.branding?.favicon;
|
|
266
|
+
if (typeof favicon !== 'function')
|
|
267
|
+
return favicon ?? null;
|
|
268
|
+
try {
|
|
269
|
+
return (await favicon({ aphex: locals.aphexCMS, auth })) ?? null;
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async function loadParentOption(locals, auth) {
|
|
276
|
+
const { databaseAdapter } = locals.aphexCMS;
|
|
277
|
+
if (!databaseAdapter.hierarchyEnabled || !hasCapability(auth, 'org.settings'))
|
|
278
|
+
return null;
|
|
279
|
+
const organization = await databaseAdapter.findOrganizationById(auth.organizationId);
|
|
280
|
+
return organization ? { id: organization.id, name: organization.name } : null;
|
|
281
|
+
}
|
|
282
|
+
async function canCreateOrganization(locals, auth) {
|
|
283
|
+
if (auth.user.role === 'super_admin')
|
|
284
|
+
return true;
|
|
285
|
+
const settings = await locals.aphexCMS.databaseAdapter.getInstanceSettings();
|
|
286
|
+
return settings.allowUserOrgCreation ?? false;
|
|
287
|
+
}
|
|
288
|
+
function requireSuperAdmin(auth) {
|
|
289
|
+
if (auth.type !== 'session' || auth.user.role !== 'super_admin') {
|
|
290
|
+
throw redirect(302, '/admin');
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
async function describeOrganization(locals, organization, membership) {
|
|
294
|
+
const { databaseAdapter, auth: provider } = locals.aphexCMS;
|
|
295
|
+
const members = await databaseAdapter.findOrganizationMembers(organization.id);
|
|
296
|
+
const owner = members.find((member) => member.role === 'owner');
|
|
297
|
+
const ownerUser = owner ? await provider?.getUserById(owner.userId) : null;
|
|
298
|
+
return {
|
|
299
|
+
id: organization.id,
|
|
300
|
+
name: organization.name,
|
|
301
|
+
slug: organization.slug,
|
|
302
|
+
...membership,
|
|
303
|
+
memberCount: members.length,
|
|
304
|
+
ownerEmail: ownerUser?.email
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
async function loadUserOrganizations(locals, auth) {
|
|
308
|
+
const memberships = await locals.aphexCMS.databaseAdapter.findUserOrganizations(auth.user.id);
|
|
309
|
+
return Promise.all(memberships.map(({ organization, member }) => describeOrganization(locals, organization, {
|
|
310
|
+
role: member.role,
|
|
311
|
+
isActive: organization.id === auth.organizationId
|
|
312
|
+
})));
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Login view payload. Reads only `locals.aphexCMS`, so the unauthenticated path
|
|
316
|
+
* stays fully core-owned — the facts the view can't derive in the browser
|
|
317
|
+
* (whether the instance is unclaimed, whether verification is required, where
|
|
318
|
+
* sign-up lands) are resolved here.
|
|
319
|
+
*/
|
|
320
|
+
async function loadLogin(locals, url) {
|
|
321
|
+
const { databaseAdapter, authFeatures } = locals.aphexCMS;
|
|
322
|
+
const unclaimed = await isInstanceUnclaimed(databaseAdapter);
|
|
323
|
+
const branding = await resolveLoginBranding(locals, url);
|
|
324
|
+
return {
|
|
325
|
+
view: 'login',
|
|
326
|
+
requireEmailVerification: authFeatures?.requireEmailVerification ?? false,
|
|
327
|
+
unclaimed,
|
|
328
|
+
// The bootstrap owner gets an organization during their first session;
|
|
329
|
+
// every later account must explicitly review pending invitations.
|
|
330
|
+
signUpDestination: unclaimed ? '/admin' : '/admin/invitations',
|
|
331
|
+
branding
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Per-tenant branding, resolved pre-auth from the request (host owns the
|
|
336
|
+
* subdomain→org policy). A resolver that throws or returns nothing falls back to the
|
|
337
|
+
* default, because a branding lookup must never block someone from getting in.
|
|
338
|
+
*/
|
|
339
|
+
async function resolveLoginBranding(locals, url) {
|
|
340
|
+
const { databaseAdapter, config } = locals.aphexCMS;
|
|
341
|
+
const resolveBranding = config.auth?.loginBranding;
|
|
342
|
+
if (!resolveBranding)
|
|
343
|
+
return null;
|
|
344
|
+
try {
|
|
345
|
+
return (await resolveBranding({ url, host: url.host, databaseAdapter })) ?? null;
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Email needs an adapter behind it, and TOTP comes back if dropping it would leave no
|
|
353
|
+
* factor at all, because a challenge offering nothing is a locked account.
|
|
354
|
+
*/
|
|
355
|
+
function availableTwoFactorMethods(features, emailAdapter) {
|
|
356
|
+
const methods = features?.twoFactorMethods ?? ['totp', 'email'];
|
|
357
|
+
const otpAvailable = methods.includes('email') && emailAdapter != null;
|
|
358
|
+
return { otpAvailable, totpAvailable: methods.includes('totp') || !otpAvailable };
|
|
359
|
+
}
|
|
360
|
+
async function loadTwoFactor(event) {
|
|
361
|
+
if (event.locals.aphexAuth)
|
|
362
|
+
throw redirect(302, '/admin');
|
|
363
|
+
const { auth: provider, authFeatures, emailAdapter } = event.locals.aphexCMS;
|
|
364
|
+
if (provider?.hasPendingTwoFactor?.(event.request) === false) {
|
|
365
|
+
throw redirect(302, '/admin/login?error=two_factor_expired');
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
view: 'two-factor',
|
|
369
|
+
...availableTwoFactorMethods(authFeatures, emailAdapter),
|
|
370
|
+
branding: await resolveLoginBranding(event.locals, event.url)
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
async function loadInvitations(locals, url) {
|
|
374
|
+
const auth = locals.aphexAuth;
|
|
375
|
+
if (!auth || auth.type === 'api_key')
|
|
376
|
+
throw redirect(302, '/admin/login');
|
|
377
|
+
return {
|
|
378
|
+
view: 'invitations',
|
|
379
|
+
pendingInvitations: await getPendingInvitations(locals.aphexCMS.databaseAdapter, auth.user.email),
|
|
380
|
+
hasOrganization: auth.type === 'session',
|
|
381
|
+
canCreateOrganization: await canCreateOrganization(locals, auth),
|
|
382
|
+
userEmail: auth.user.email,
|
|
383
|
+
branding: await resolveLoginBranding(locals, url)
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
async function loadInvite(locals, url, token) {
|
|
387
|
+
const { databaseAdapter } = locals.aphexCMS;
|
|
388
|
+
const auth = locals.aphexAuth;
|
|
389
|
+
const branding = await resolveLoginBranding(locals, url);
|
|
390
|
+
const base = {
|
|
391
|
+
view: 'invite',
|
|
392
|
+
token,
|
|
393
|
+
branding
|
|
394
|
+
};
|
|
395
|
+
const closed = { ...base, invitation: null, organization: null };
|
|
396
|
+
const invitation = await databaseAdapter.findInvitationByToken(token);
|
|
397
|
+
if (!invitation)
|
|
398
|
+
return { ...closed, status: 'invalid' };
|
|
399
|
+
if (isAccepted(invitation))
|
|
400
|
+
return { ...closed, status: 'already_accepted' };
|
|
401
|
+
if (isExpired(invitation))
|
|
402
|
+
return { ...closed, status: 'expired' };
|
|
403
|
+
const organization = await databaseAdapter.findOrganizationById(invitation.organizationId);
|
|
404
|
+
const details = {
|
|
405
|
+
...base,
|
|
406
|
+
invitation: { email: invitation.email, role: invitation.role },
|
|
407
|
+
organization: organization ? { name: organization.name, slug: organization.slug } : null
|
|
408
|
+
};
|
|
409
|
+
// Signed in, with or without an organization yet: this is what gets them one.
|
|
410
|
+
if (auth && auth.type !== 'api_key') {
|
|
411
|
+
if (auth.user.email.toLowerCase() !== invitation.email.toLowerCase()) {
|
|
412
|
+
return { ...details, status: 'email_mismatch' };
|
|
413
|
+
}
|
|
414
|
+
await databaseAdapter.acceptInvitation(token, auth.user.id);
|
|
415
|
+
await databaseAdapter.updateUserSession(auth.user.id, invitation.organizationId);
|
|
416
|
+
throw redirect(302, '/admin');
|
|
417
|
+
}
|
|
418
|
+
return { ...details, status: 'open' };
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Studio view (structure / vision / media) payload. Reads only `locals.aphexCMS`
|
|
422
|
+
* and the session, so it is fully core-owned — no app wiring beyond the mount.
|
|
423
|
+
*/
|
|
424
|
+
async function loadStudio(locals, auth) {
|
|
425
|
+
try {
|
|
426
|
+
const { cmsEngine, databaseAdapter } = locals.aphexCMS;
|
|
427
|
+
// A schema that failed validation at boot is surfaced as a banner rather
|
|
428
|
+
// than a crash, so the editor can still see what's wrong.
|
|
429
|
+
const schemaError = locals.aphexCMS.schemaError;
|
|
430
|
+
if (schemaError) {
|
|
431
|
+
return {
|
|
432
|
+
view: 'studio',
|
|
433
|
+
documentTypes: [],
|
|
434
|
+
schemaError: { message: schemaError.message },
|
|
435
|
+
graphqlSettings: null,
|
|
436
|
+
isReadOnly: false,
|
|
437
|
+
userPreferences: null
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
const documentTypes = await cmsEngine.listDocumentTypes();
|
|
441
|
+
const userProfile = await databaseAdapter.findUserProfileById(auth.type === 'session' ? auth.user.id : '');
|
|
442
|
+
const userPreferences = userProfile?.preferences ?? null;
|
|
443
|
+
// GraphQL is built in and on by default; the shape matches AdminApp's prop.
|
|
444
|
+
const graphqlSettings = locals.aphexCMS?.graphqlSettings ?? null;
|
|
445
|
+
// Viewers see the admin read-only. API-key sessions never render the admin.
|
|
446
|
+
const isReadOnly = auth.type === 'session' ? isViewer(auth) : false;
|
|
447
|
+
return {
|
|
448
|
+
view: 'studio',
|
|
449
|
+
documentTypes,
|
|
450
|
+
schemaError: null,
|
|
451
|
+
graphqlSettings,
|
|
452
|
+
isReadOnly,
|
|
453
|
+
userPreferences
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
catch (err) {
|
|
457
|
+
return {
|
|
458
|
+
view: 'studio',
|
|
459
|
+
documentTypes: [],
|
|
460
|
+
schemaError: {
|
|
461
|
+
message: err instanceof Error ? err.message : 'Unknown schema error'
|
|
462
|
+
},
|
|
463
|
+
graphqlSettings: null,
|
|
464
|
+
isReadOnly: false,
|
|
465
|
+
userPreferences: null
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CMSInstances } from '../../hooks.js';
|
|
2
|
+
import type { SessionAuth } from '../../types/auth.js';
|
|
3
|
+
import type { OrganizationTeam } from '../../types/organization.js';
|
|
4
|
+
/**
|
|
5
|
+
* Everything the members settings page shows, in one query: members with their
|
|
6
|
+
* user profile, pending invitations (with the accept link for callers who can
|
|
7
|
+
* invite), the invitable roles, and whether email is configured.
|
|
8
|
+
*
|
|
9
|
+
* Called by **both** the SSR load helper (`loadMembersPage`) and the Hono
|
|
10
|
+
* route (`GET /organizations/team`), so the page and the HTTP API (MCP, agents,
|
|
11
|
+
* tests) read the exact same code.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getOrganizationTeam(services: CMSInstances, auth: SessionAuth, origin: string): Promise<OrganizationTeam>;
|
|
14
|
+
//# sourceMappingURL=organization-team.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organization-team.d.ts","sourceRoot":"","sources":["../../../src/lib/server/queries/organization-team.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAA8B,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE7F;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACxC,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,MAAM,GACZ,OAAO,CAAC,gBAAgB,CAAC,CAyD3B"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { hasCapability } from '../../types/capabilities.js';
|
|
2
|
+
import { isPendingInvitation } from '../../auth/invitation-status.js';
|
|
3
|
+
import { invitationUrl } from '../../auth/pages.js';
|
|
4
|
+
import { cmsLogger } from '../../utils/logger.js';
|
|
5
|
+
/**
|
|
6
|
+
* Everything the members settings page shows, in one query: members with their
|
|
7
|
+
* user profile, pending invitations (with the accept link for callers who can
|
|
8
|
+
* invite), the invitable roles, and whether email is configured.
|
|
9
|
+
*
|
|
10
|
+
* Called by **both** the SSR load helper (`loadMembersPage`) and the Hono
|
|
11
|
+
* route (`GET /organizations/team`), so the page and the HTTP API (MCP, agents,
|
|
12
|
+
* tests) read the exact same code.
|
|
13
|
+
*/
|
|
14
|
+
export async function getOrganizationTeam(services, auth, origin) {
|
|
15
|
+
const { config, databaseAdapter, rolesService, auth: authProvider, emailAdapter } = services;
|
|
16
|
+
const canInvite = hasCapability(auth, 'member.invite');
|
|
17
|
+
const [memberRows, invitationRows, roles] = await Promise.all([
|
|
18
|
+
databaseAdapter.findOrganizationMembers(auth.organizationId),
|
|
19
|
+
databaseAdapter.findOrganizationInvitations(auth.organizationId),
|
|
20
|
+
rolesService.listRoles(auth.organizationId)
|
|
21
|
+
]);
|
|
22
|
+
// The user table belongs to the auth provider, not the CMS, so profiles
|
|
23
|
+
// come through the provider one by one. Orgs are small; this is fine.
|
|
24
|
+
// A member whose user row is gone is dropped rather than shown blank.
|
|
25
|
+
const members = [];
|
|
26
|
+
if (authProvider) {
|
|
27
|
+
await Promise.all(memberRows.map(async (member) => {
|
|
28
|
+
try {
|
|
29
|
+
const user = await authProvider.getUserById(member.userId);
|
|
30
|
+
if (!user)
|
|
31
|
+
return;
|
|
32
|
+
members.push({
|
|
33
|
+
member,
|
|
34
|
+
user: {
|
|
35
|
+
id: user.id,
|
|
36
|
+
email: user.email,
|
|
37
|
+
name: user.name ?? null,
|
|
38
|
+
image: user.image ?? null
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
cmsLogger.warn(`Failed to resolve user ${member.userId} for team listing:`, error);
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
// Promise.all settles in completion order — restore a stable listing.
|
|
48
|
+
members.sort((a, b) => new Date(a.member.createdAt).getTime() - new Date(b.member.createdAt).getTime());
|
|
49
|
+
return {
|
|
50
|
+
currentUserId: auth.user.id,
|
|
51
|
+
members,
|
|
52
|
+
invitations: invitationRows
|
|
53
|
+
.filter((inv) => isPendingInvitation(inv))
|
|
54
|
+
.map((inv) => ({
|
|
55
|
+
id: inv.id,
|
|
56
|
+
email: inv.email,
|
|
57
|
+
role: inv.role,
|
|
58
|
+
...(canInvite ? { inviteUrl: invitationUrl(config, origin, inv.token) } : {})
|
|
59
|
+
})),
|
|
60
|
+
inviteRoles: roles
|
|
61
|
+
.filter((r) => r.name !== 'owner')
|
|
62
|
+
.map((r) => ({ name: r.name, description: r.description })),
|
|
63
|
+
emailConfigured: emailAdapter != null
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PendingInvitation } from '../../api/invitations.js';
|
|
2
|
+
import type { DatabaseAdapter } from '../../db/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* The invitations waiting for this address, newest first, with their organization's
|
|
5
|
+
* name. Used by both the invitations view and `GET /invitations`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getPendingInvitations(databaseAdapter: DatabaseAdapter, email: string): Promise<PendingInvitation[]>;
|
|
8
|
+
//# sourceMappingURL=pending-invitations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending-invitations.d.ts","sourceRoot":"","sources":["../../../src/lib/server/queries/pending-invitations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;;GAGG;AACH,wBAAsB,qBAAqB,CAC1C,eAAe,EAAE,eAAe,EAChC,KAAK,EAAE,MAAM,GACX,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAqB9B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isPendingInvitation } from '../../auth/invitation-status.js';
|
|
2
|
+
/**
|
|
3
|
+
* The invitations waiting for this address, newest first, with their organization's
|
|
4
|
+
* name. Used by both the invitations view and `GET /invitations`.
|
|
5
|
+
*/
|
|
6
|
+
export async function getPendingInvitations(databaseAdapter, email) {
|
|
7
|
+
const invitations = await databaseAdapter.findInvitationsByEmail(email);
|
|
8
|
+
const pending = invitations
|
|
9
|
+
.filter((invitation) => isPendingInvitation(invitation))
|
|
10
|
+
.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
11
|
+
return Promise.all(pending.map(async (invitation) => {
|
|
12
|
+
const organization = await databaseAdapter.findOrganizationById(invitation.organizationId);
|
|
13
|
+
return {
|
|
14
|
+
id: invitation.id,
|
|
15
|
+
organizationId: invitation.organizationId,
|
|
16
|
+
organizationName: organization?.name ?? 'Unknown',
|
|
17
|
+
organizationSlug: organization?.slug ?? '',
|
|
18
|
+
role: invitation.role,
|
|
19
|
+
email: invitation.email,
|
|
20
|
+
expiresAt: invitation.expiresAt,
|
|
21
|
+
createdAt: invitation.createdAt
|
|
22
|
+
};
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single API key as the admin surfaces it — the safe, display-only projection
|
|
3
|
+
* of the provider's key row. Never carries the secret (that exists once, at
|
|
4
|
+
* creation). Shared by the `AuthProvider.listApiKeys` port, the settings load,
|
|
5
|
+
* and the `ApiKeysSettings` panel so the shape can't drift between them.
|
|
6
|
+
*/
|
|
7
|
+
export interface ApiKeySummary {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string | null;
|
|
10
|
+
/** Coarse scopes stored in the key's metadata. */
|
|
11
|
+
permissions: ('read' | 'write')[];
|
|
12
|
+
/** Owning organization (from metadata); used to scope the listing. */
|
|
13
|
+
organizationId?: string;
|
|
14
|
+
createdAt: Date | null;
|
|
15
|
+
lastRequest: Date | null;
|
|
16
|
+
expiresAt: Date | null;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=api-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.d.ts","sourceRoot":"","sources":["../../src/lib/types/api-key.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,kDAAkD;IAClD,WAAW,EAAE,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;IAClC,sEAAsE;IACtE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/auth.d.ts
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
import type { CMSUser } from './user.js';
|
|
2
2
|
import type { OrganizationRole } from './organization.js';
|
|
3
|
+
/** A second factor the sign-in challenge can offer. */
|
|
4
|
+
export type TwoFactorMethod = 'totp' | 'email';
|
|
5
|
+
/**
|
|
6
|
+
* Auth-provider feature flags the admin UI branches on, surfaced from the
|
|
7
|
+
* host's auth config through `CMSConfig.auth.features` to `CMSInstances`.
|
|
8
|
+
*
|
|
9
|
+
* Auth itself stays host-owned (ports & adapters — see `AuthProvider`); this is
|
|
10
|
+
* only the small set of *facts* the core admin needs to decide which controls to
|
|
11
|
+
* render (e.g. whether to show the TOTP setup or the account-deletion zone). It
|
|
12
|
+
* lets settings panels live in core without reaching into app-only auth config.
|
|
13
|
+
*/
|
|
14
|
+
export interface AuthFeatures {
|
|
15
|
+
/** Second factors offered at sign-in. Email also requires an email adapter. */
|
|
16
|
+
twoFactorMethods: TwoFactorMethod[];
|
|
17
|
+
/** Whether a user may delete their own account (Account → Danger zone). */
|
|
18
|
+
allowAccountDeletion: boolean;
|
|
19
|
+
/** Whether a verified email is required before sign-in. */
|
|
20
|
+
requireEmailVerification: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Per-tenant login branding, resolved *before* a session exists (so it can't come
|
|
24
|
+
* from auth — the host keys it off the request, e.g. a subdomain). Plain data so
|
|
25
|
+
* it can travel in the login view's SSR payload. The resolver that produces it
|
|
26
|
+
* (`CMSConfig.auth.loginBranding`) lives server-side in config.
|
|
27
|
+
*/
|
|
28
|
+
export interface LoginBranding {
|
|
29
|
+
/** Overrides the client config's `title` on the login screen. */
|
|
30
|
+
title?: string;
|
|
31
|
+
/** A short line under the title (e.g. "Acme Billing Portal"). */
|
|
32
|
+
tagline?: string;
|
|
33
|
+
/** Logo shown above the card. Must be reachable without auth (public URL). */
|
|
34
|
+
logoUrl?: string;
|
|
35
|
+
/** Any CSS color; applied as the login's `--primary` accent (buttons, links). */
|
|
36
|
+
accentColor?: string;
|
|
37
|
+
}
|
|
3
38
|
export interface SessionAuth {
|
|
4
39
|
type: 'session';
|
|
5
40
|
user: CMSUser;
|
package/dist/types/auth.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