@aphexcms/cms-core 11.3.0 → 12.0.0-next.20261109084846

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 (227) hide show
  1. package/dist/admin/client-auth.svelte.d.ts +120 -0
  2. package/dist/admin/client-auth.svelte.d.ts.map +1 -0
  3. package/dist/admin/client-auth.svelte.js +14 -0
  4. package/dist/admin/client-config.d.ts +72 -0
  5. package/dist/admin/client-config.d.ts.map +1 -0
  6. package/dist/admin/client-config.js +1 -0
  7. package/dist/admin/settings-header-actions.d.ts +12 -0
  8. package/dist/admin/settings-header-actions.d.ts.map +1 -0
  9. package/dist/admin/settings-header-actions.js +1 -0
  10. package/dist/admin/view-data.d.ts +189 -0
  11. package/dist/admin/view-data.d.ts.map +1 -0
  12. package/dist/admin/view-data.js +1 -0
  13. package/dist/admin.css +6 -0
  14. package/dist/api/invitations.d.ts +2 -2
  15. package/dist/api/invitations.d.ts.map +1 -1
  16. package/dist/api/organizations.d.ts +5 -4
  17. package/dist/api/organizations.d.ts.map +1 -1
  18. package/dist/api/organizations.js +2 -3
  19. package/dist/api/user.d.ts +6 -1
  20. package/dist/api/user.d.ts.map +1 -1
  21. package/dist/api/user.js +7 -0
  22. package/dist/app-augment.d.ts +2 -3
  23. package/dist/app-augment.d.ts.map +1 -1
  24. package/dist/app.d.ts +1 -1
  25. package/dist/auth/auth-errors.d.ts +6 -0
  26. package/dist/auth/auth-errors.d.ts.map +1 -1
  27. package/dist/auth/auth-errors.js +8 -0
  28. package/dist/auth/auth-hooks.d.ts.map +1 -1
  29. package/dist/auth/auth-hooks.js +36 -17
  30. package/dist/auth/invitation-email.d.ts +9 -0
  31. package/dist/auth/invitation-email.d.ts.map +1 -0
  32. package/dist/auth/invitation-email.js +49 -0
  33. package/dist/auth/pages.d.ts +16 -0
  34. package/dist/auth/pages.d.ts.map +1 -0
  35. package/dist/auth/pages.js +23 -0
  36. package/dist/auth/provider.d.ts +31 -1
  37. package/dist/auth/provider.d.ts.map +1 -1
  38. package/dist/client/index.d.ts +5 -0
  39. package/dist/client/index.d.ts.map +1 -1
  40. package/dist/client/index.js +9 -0
  41. package/dist/client/ui.d.ts +16 -0
  42. package/dist/client/ui.d.ts.map +1 -1
  43. package/dist/client/ui.js +26 -1
  44. package/dist/components/AphexStudio.svelte +268 -0
  45. package/dist/components/AphexStudio.svelte.d.ts +16 -0
  46. package/dist/components/AphexStudio.svelte.d.ts.map +1 -0
  47. package/dist/components/admin/AccountSettings.svelte +339 -0
  48. package/dist/components/admin/AccountSettings.svelte.d.ts +8 -0
  49. package/dist/components/admin/AccountSettings.svelte.d.ts.map +1 -0
  50. package/dist/components/admin/AccountSettingsView.svelte +61 -0
  51. package/dist/components/admin/AccountSettingsView.svelte.d.ts +19 -0
  52. package/dist/components/admin/AccountSettingsView.svelte.d.ts.map +1 -0
  53. package/dist/components/admin/ApiKeysSettings.svelte +435 -0
  54. package/dist/components/admin/ApiKeysSettings.svelte.d.ts +15 -0
  55. package/dist/components/admin/ApiKeysSettings.svelte.d.ts.map +1 -0
  56. package/dist/components/admin/AuthPageShell.svelte +32 -0
  57. package/dist/components/admin/AuthPageShell.svelte.d.ts +16 -0
  58. package/dist/components/admin/AuthPageShell.svelte.d.ts.map +1 -0
  59. package/dist/components/admin/CreateOrganization.svelte +158 -0
  60. package/dist/components/admin/CreateOrganization.svelte.d.ts +11 -0
  61. package/dist/components/admin/CreateOrganization.svelte.d.ts.map +1 -0
  62. package/dist/components/admin/DeleteAccountSettings.svelte +124 -0
  63. package/dist/components/admin/DeleteAccountSettings.svelte.d.ts +7 -0
  64. package/dist/components/admin/DeleteAccountSettings.svelte.d.ts.map +1 -0
  65. package/dist/components/admin/DeleteOrganizationSettings.svelte +123 -0
  66. package/dist/components/admin/DeleteOrganizationSettings.svelte.d.ts +11 -0
  67. package/dist/components/admin/DeleteOrganizationSettings.svelte.d.ts.map +1 -0
  68. package/dist/components/admin/DocumentEditor.svelte +92 -22
  69. package/dist/components/admin/DocumentEditor.svelte.d.ts.map +1 -1
  70. package/dist/components/admin/GeneralSettings.svelte +45 -0
  71. package/dist/components/admin/GeneralSettings.svelte.d.ts +10 -0
  72. package/dist/components/admin/GeneralSettings.svelte.d.ts.map +1 -0
  73. package/dist/components/admin/GodModeView.svelte +112 -0
  74. package/dist/components/admin/GodModeView.svelte.d.ts +9 -0
  75. package/dist/components/admin/GodModeView.svelte.d.ts.map +1 -0
  76. package/dist/components/admin/InvitationsView.svelte +277 -0
  77. package/dist/components/admin/InvitationsView.svelte.d.ts +11 -0
  78. package/dist/components/admin/InvitationsView.svelte.d.ts.map +1 -0
  79. package/dist/components/admin/InviteView.svelte +98 -0
  80. package/dist/components/admin/InviteView.svelte.d.ts +9 -0
  81. package/dist/components/admin/InviteView.svelte.d.ts.map +1 -0
  82. package/dist/components/admin/LoginView.svelte +478 -0
  83. package/dist/components/admin/LoginView.svelte.d.ts +5 -0
  84. package/dist/components/admin/LoginView.svelte.d.ts.map +1 -0
  85. package/dist/components/admin/MembersSettings.svelte +25 -3
  86. package/dist/components/admin/MembersSettings.svelte.d.ts +5 -1
  87. package/dist/components/admin/MembersSettings.svelte.d.ts.map +1 -1
  88. package/dist/components/admin/OrganizationSettings.svelte +367 -0
  89. package/dist/components/admin/OrganizationSettings.svelte.d.ts +9 -0
  90. package/dist/components/admin/OrganizationSettings.svelte.d.ts.map +1 -0
  91. package/dist/components/admin/OrganizationsList.svelte +92 -0
  92. package/dist/components/admin/OrganizationsList.svelte.d.ts +8 -0
  93. package/dist/components/admin/OrganizationsList.svelte.d.ts.map +1 -0
  94. package/dist/components/admin/OrganizationsView.svelte +31 -0
  95. package/dist/components/admin/OrganizationsView.svelte.d.ts +9 -0
  96. package/dist/components/admin/OrganizationsView.svelte.d.ts.map +1 -0
  97. package/dist/components/admin/PasswordInput.svelte +43 -0
  98. package/dist/components/admin/PasswordInput.svelte.d.ts +8 -0
  99. package/dist/components/admin/PasswordInput.svelte.d.ts.map +1 -0
  100. package/dist/components/admin/PasswordSettings.svelte +179 -0
  101. package/dist/components/admin/PasswordSettings.svelte.d.ts +4 -0
  102. package/dist/components/admin/PasswordSettings.svelte.d.ts.map +1 -0
  103. package/dist/components/admin/PreferencesSettings.svelte +80 -0
  104. package/dist/components/admin/PreferencesSettings.svelte.d.ts +20 -0
  105. package/dist/components/admin/PreferencesSettings.svelte.d.ts.map +1 -0
  106. package/dist/components/admin/ResetPasswordView.svelte +117 -0
  107. package/dist/components/admin/ResetPasswordView.svelte.d.ts +9 -0
  108. package/dist/components/admin/ResetPasswordView.svelte.d.ts.map +1 -0
  109. package/dist/components/admin/RolesSettings.svelte +360 -0
  110. package/dist/components/admin/RolesSettings.svelte.d.ts +11 -0
  111. package/dist/components/admin/RolesSettings.svelte.d.ts.map +1 -0
  112. package/dist/components/admin/SchemaField.svelte +2 -1
  113. package/dist/components/admin/SchemaField.svelte.d.ts.map +1 -1
  114. package/dist/components/admin/SettingsHeaderActions.svelte +25 -0
  115. package/dist/components/admin/SettingsHeaderActions.svelte.d.ts +8 -0
  116. package/dist/components/admin/SettingsHeaderActions.svelte.d.ts.map +1 -0
  117. package/dist/components/admin/SettingsShell.svelte +136 -0
  118. package/dist/components/admin/SettingsShell.svelte.d.ts +9 -0
  119. package/dist/components/admin/SettingsShell.svelte.d.ts.map +1 -0
  120. package/dist/components/admin/TwoFactorChallengeView.svelte +377 -0
  121. package/dist/components/admin/TwoFactorChallengeView.svelte.d.ts +11 -0
  122. package/dist/components/admin/TwoFactorChallengeView.svelte.d.ts.map +1 -0
  123. package/dist/components/admin/TwoFactorSettings.svelte +436 -0
  124. package/dist/components/admin/TwoFactorSettings.svelte.d.ts +7 -0
  125. package/dist/components/admin/TwoFactorSettings.svelte.d.ts.map +1 -0
  126. package/dist/components/admin/fields/ImageField.svelte +4 -2
  127. package/dist/components/admin/fields/richtext/PortableTextImageView.svelte +3 -2
  128. package/dist/components/admin/fields/richtext/RichtextField.svelte +48 -6
  129. package/dist/components/admin/fields/richtext/RichtextField.svelte.d.ts.map +1 -1
  130. package/dist/components/layout/sidebar/NavUser.svelte +2 -2
  131. package/dist/config.d.ts +2 -1
  132. package/dist/config.d.ts.map +1 -1
  133. package/dist/email/index.d.ts +1 -0
  134. package/dist/email/index.d.ts.map +1 -1
  135. package/dist/email/index.js +2 -0
  136. package/dist/email/interfaces/email.d.ts +2 -0
  137. package/dist/email/interfaces/email.d.ts.map +1 -1
  138. package/dist/email/link-email.d.ts +15 -0
  139. package/dist/email/link-email.d.ts.map +1 -0
  140. package/dist/email/link-email.js +30 -0
  141. package/dist/field-validation/utils.d.ts +29 -0
  142. package/dist/field-validation/utils.d.ts.map +1 -1
  143. package/dist/field-validation/utils.js +138 -5
  144. package/dist/graphql/index.d.ts.map +1 -1
  145. package/dist/graphql/index.js +1 -1
  146. package/dist/hooks.d.ts +6 -3
  147. package/dist/hooks.d.ts.map +1 -1
  148. package/dist/hooks.js +53 -17
  149. package/dist/jobs/recurring.d.ts +4 -1
  150. package/dist/jobs/recurring.d.ts.map +1 -1
  151. package/dist/jobs/recurring.js +28 -0
  152. package/dist/local-api/auth-helpers.d.ts +4 -4
  153. package/dist/local-api/auth-helpers.js +4 -4
  154. package/dist/local-api/collection-api.d.ts +10 -1
  155. package/dist/local-api/collection-api.d.ts.map +1 -1
  156. package/dist/local-api/collection-api.js +25 -7
  157. package/dist/local-api/index.d.ts +1 -1
  158. package/dist/local-api/index.d.ts.map +1 -1
  159. package/dist/local-api/index.js +7 -5
  160. package/dist/local-api/types.d.ts +1 -1
  161. package/dist/preview/perspective.d.ts +1 -1
  162. package/dist/preview/perspective.js +1 -1
  163. package/dist/resolve-config.d.ts +22 -0
  164. package/dist/resolve-config.d.ts.map +1 -0
  165. package/dist/resolve-config.js +106 -0
  166. package/dist/routes/assets-cdn.d.ts +7 -2
  167. package/dist/routes/assets-cdn.d.ts.map +1 -1
  168. package/dist/routes/assets-cdn.js +1 -1
  169. package/dist/server/api/index.d.ts +1 -2
  170. package/dist/server/api/index.d.ts.map +1 -1
  171. package/dist/server/api/index.js +10 -3
  172. package/dist/server/api/openapi/registry.d.ts.map +1 -1
  173. package/dist/server/api/openapi/registry.js +62 -0
  174. package/dist/server/api/routes/api-keys.d.ts +4 -0
  175. package/dist/server/api/routes/api-keys.d.ts.map +1 -0
  176. package/dist/server/api/routes/api-keys.js +88 -0
  177. package/dist/server/api/routes/documents-by-id.d.ts.map +1 -1
  178. package/dist/server/api/routes/documents-by-id.js +16 -1
  179. package/dist/server/api/routes/documents-publish.d.ts.map +1 -1
  180. package/dist/server/api/routes/documents-publish.js +11 -1
  181. package/dist/server/api/routes/documents.d.ts.map +1 -1
  182. package/dist/server/api/routes/documents.js +16 -2
  183. package/dist/server/api/routes/instance-settings.d.ts +4 -0
  184. package/dist/server/api/routes/instance-settings.d.ts.map +1 -0
  185. package/dist/server/api/routes/instance-settings.js +47 -0
  186. package/dist/server/api/routes/invitations.d.ts +9 -0
  187. package/dist/server/api/routes/invitations.d.ts.map +1 -0
  188. package/dist/server/api/routes/invitations.js +79 -0
  189. package/dist/server/api/routes/organizations-invitations.d.ts +0 -6
  190. package/dist/server/api/routes/organizations-invitations.d.ts.map +1 -1
  191. package/dist/server/api/routes/organizations-invitations.js +6 -7
  192. package/dist/server/api/routes/organizations-team.d.ts.map +1 -1
  193. package/dist/server/api/routes/organizations-team.js +2 -52
  194. package/dist/server/api/routes/organizations.d.ts.map +1 -1
  195. package/dist/server/api/routes/organizations.js +35 -9
  196. package/dist/server/core-routes.d.ts +8 -0
  197. package/dist/server/core-routes.d.ts.map +1 -0
  198. package/dist/server/core-routes.js +67 -0
  199. package/dist/server/index.d.ts +5 -1
  200. package/dist/server/index.d.ts.map +1 -1
  201. package/dist/server/index.js +7 -1
  202. package/dist/server/pages/admin.d.ts +24 -0
  203. package/dist/server/pages/admin.d.ts.map +1 -0
  204. package/dist/server/pages/admin.js +468 -0
  205. package/dist/server/queries/organization-team.d.ts +14 -0
  206. package/dist/server/queries/organization-team.d.ts.map +1 -0
  207. package/dist/server/queries/organization-team.js +65 -0
  208. package/dist/server/queries/pending-invitations.d.ts +8 -0
  209. package/dist/server/queries/pending-invitations.d.ts.map +1 -0
  210. package/dist/server/queries/pending-invitations.js +24 -0
  211. package/dist/types/api-key.d.ts +18 -0
  212. package/dist/types/api-key.d.ts.map +1 -0
  213. package/dist/types/api-key.js +1 -0
  214. package/dist/types/auth.d.ts +35 -0
  215. package/dist/types/auth.d.ts.map +1 -1
  216. package/dist/types/capabilities.d.ts +1 -2
  217. package/dist/types/capabilities.d.ts.map +1 -1
  218. package/dist/types/config.d.ts +124 -4
  219. package/dist/types/config.d.ts.map +1 -1
  220. package/dist/types/filters.d.ts +1 -1
  221. package/dist/types/index.d.ts +1 -0
  222. package/dist/types/index.d.ts.map +1 -1
  223. package/dist/types/index.js +1 -0
  224. package/dist/types/organization.d.ts +1 -1
  225. package/dist/vite/index.d.ts.map +1 -1
  226. package/dist/vite/index.js +46 -39
  227. package/package.json +19 -29
@@ -0,0 +1,435 @@
1
+ <script lang="ts">
2
+ import { Badge } from '@aphexcms/ui/shadcn/badge';
3
+ import { Button } from '@aphexcms/ui/shadcn/button';
4
+ import * as Card from '@aphexcms/ui/shadcn/card';
5
+ import * as Alert from '@aphexcms/ui/shadcn/alert';
6
+ import {
7
+ Dialog,
8
+ DialogContent,
9
+ DialogDescription,
10
+ DialogFooter,
11
+ DialogHeader,
12
+ DialogTitle
13
+ } from '@aphexcms/ui/shadcn/dialog';
14
+ import { Input } from '@aphexcms/ui/shadcn/input';
15
+ import { Label } from '@aphexcms/ui/shadcn/label';
16
+ import * as Select from '@aphexcms/ui/shadcn/select';
17
+ import { invalidateAll } from '$app/navigation';
18
+ import { BookOpen, Copy, KeyRound, Plus, Trash2 } from '@lucide/svelte';
19
+ import { toast } from 'svelte-sonner';
20
+ import type { ApiKeySummary } from '../../types/api-key';
21
+ import { apiKeys as apiKeysApi } from '../../api/api-keys';
22
+ import { usePermissions } from '../../permissions-context.svelte';
23
+ import { confirmDialog } from './confirm-dialog/confirm-dialog.svelte';
24
+ import SettingsHeaderActions from './SettingsHeaderActions.svelte';
25
+
26
+ type Props = {
27
+ apiKeys: ApiKeySummary[];
28
+ organizationRole?: string | null;
29
+ /**
30
+ * Path to the rendered API reference, or `null` on an instance that
31
+ * unmounted it (`openapi.docsUi: false`) — resolved server-side so this
32
+ * never links to a 404.
33
+ */
34
+ apiDocsHref?: string | null;
35
+ };
36
+
37
+ // eslint-disable-next-line svelte/no-unused-props
38
+ let { apiKeys, apiDocsHref = null }: Props = $props();
39
+
40
+ const perms = usePermissions();
41
+ const canManageApiKeys = $derived(perms.can('apiKey.manage'));
42
+
43
+ let createDialogOpen = $state(false);
44
+ let newKeyName = $state('');
45
+ let newKeyMode = $state<'read' | 'write'>('read');
46
+ const newKeyPermissions = $derived<('read' | 'write')[]>(
47
+ newKeyMode === 'write' ? ['read', 'write'] : ['read']
48
+ );
49
+ let newKeyExpiresValue = $state('365');
50
+ let newKeyExpiresInDays = $state<number | undefined>(365);
51
+ let createdKey = $state<{ key: string; name: string } | null>(null);
52
+ let isCreating = $state(false);
53
+
54
+ const expirationOptions = [
55
+ { value: '30', label: '30 days' },
56
+ { value: '90', label: '90 days' },
57
+ { value: '365', label: '1 year' },
58
+ { value: 'never', label: 'Never' }
59
+ ];
60
+
61
+ const expirationTriggerContent = $derived(
62
+ expirationOptions.find((opt) => opt.value === newKeyExpiresValue)?.label ?? '1 year'
63
+ );
64
+
65
+ async function createApiKey() {
66
+ if (!newKeyName.trim()) {
67
+ toast.error('Please enter a key name');
68
+ return;
69
+ }
70
+
71
+ isCreating = true;
72
+ try {
73
+ const result = await apiKeysApi.create({
74
+ name: newKeyName.trim(),
75
+ permissions: newKeyPermissions,
76
+ expiresInDays: newKeyExpiresInDays
77
+ });
78
+
79
+ if (!result.success || !result.data) {
80
+ throw new Error(result.error || 'Failed to create API key');
81
+ }
82
+
83
+ createdKey = { key: result.data.apiKey.key, name: result.data.apiKey.name ?? newKeyName };
84
+ newKeyName = '';
85
+ newKeyMode = 'read';
86
+ newKeyExpiresValue = '365';
87
+ newKeyExpiresInDays = 365;
88
+ await invalidateAll();
89
+ } catch (error) {
90
+ toast.error(error instanceof Error ? error.message : 'Failed to create API key');
91
+ } finally {
92
+ isCreating = false;
93
+ }
94
+ }
95
+
96
+ async function deleteApiKey(id: string, name: string) {
97
+ const confirmed = await confirmDialog({
98
+ title: `Delete "${name}"?`,
99
+ description: 'This action cannot be undone. Any integration using this key will lose access.',
100
+ confirmText: 'Delete',
101
+ variant: 'destructive'
102
+ });
103
+ if (!confirmed) return;
104
+
105
+ try {
106
+ const result = await apiKeysApi.remove(id);
107
+ if (!result.success) throw new Error(result.error || 'Failed to delete API key');
108
+ toast.success(`API key "${name}" deleted`);
109
+ await invalidateAll();
110
+ } catch (error) {
111
+ toast.error(error instanceof Error ? error.message : 'Failed to delete API key');
112
+ }
113
+ }
114
+
115
+ function copyToClipboard(text: string) {
116
+ navigator.clipboard.writeText(text);
117
+ toast.success('Copied to clipboard');
118
+ }
119
+
120
+ function formatDate(date: Date | null | undefined) {
121
+ if (!date) return 'Never';
122
+ return new Date(date).toLocaleDateString('en-US', {
123
+ month: 'short',
124
+ day: 'numeric',
125
+ year: 'numeric'
126
+ });
127
+ }
128
+
129
+ function formatPermissions(permissions: ('read' | 'write')[]) {
130
+ return permissions.join(' ');
131
+ }
132
+ </script>
133
+
134
+ {#if canManageApiKeys}
135
+ <SettingsHeaderActions>
136
+ <Button
137
+ size="sm"
138
+ onclick={() => {
139
+ createdKey = null;
140
+ createDialogOpen = true;
141
+ }}
142
+ >
143
+ <Plus class="mr-1.5 h-4 w-4" />
144
+ New token
145
+ </Button>
146
+ </SettingsHeaderActions>
147
+ {/if}
148
+
149
+ <Card.Root>
150
+ <Card.Header class="gap-4">
151
+ <div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
152
+ <div>
153
+ <Card.Title>API keys</Card.Title>
154
+ <Card.Description>Personal and service tokens scoped to this organization.</Card.Description
155
+ >
156
+ </div>
157
+ {#if canManageApiKeys}
158
+ <Dialog bind:open={createDialogOpen}>
159
+ <DialogContent class="sm:max-w-[500px]">
160
+ {#if createdKey}
161
+ <DialogHeader>
162
+ <DialogTitle>API key created</DialogTitle>
163
+ <DialogDescription
164
+ >Save this key securely. You won't be able to see it again.</DialogDescription
165
+ >
166
+ </DialogHeader>
167
+ <div class="space-y-4 py-4">
168
+ <div>
169
+ <Label>Key name</Label>
170
+ <p class="mt-1 text-sm font-medium">{createdKey.name}</p>
171
+ </div>
172
+ <div>
173
+ <Label>API key</Label>
174
+ <div class="mt-1 flex gap-2">
175
+ <Input value={createdKey.key} readonly class="font-mono text-xs" />
176
+ <Button
177
+ size="sm"
178
+ variant="outline"
179
+ onclick={() => copyToClipboard(createdKey!.key)}
180
+ >
181
+ <Copy class="mr-1.5 h-3.5 w-3.5" />
182
+ Copy
183
+ </Button>
184
+ </div>
185
+ </div>
186
+ </div>
187
+ <DialogFooter>
188
+ <Button
189
+ onclick={() => {
190
+ createdKey = null;
191
+ createDialogOpen = false;
192
+ }}>Done</Button
193
+ >
194
+ </DialogFooter>
195
+ {:else}
196
+ <DialogHeader>
197
+ <DialogTitle>Create API key</DialogTitle>
198
+ <DialogDescription>Generate a new token for programmatic access.</DialogDescription>
199
+ </DialogHeader>
200
+ <div class="space-y-4 py-4">
201
+ <div>
202
+ <Label for="key-name">Key name</Label>
203
+ <Input
204
+ id="key-name"
205
+ bind:value={newKeyName}
206
+ placeholder="Production read"
207
+ class="mt-1"
208
+ />
209
+ </div>
210
+ <div>
211
+ <Label>Access level</Label>
212
+ <div class="mt-2 flex gap-2">
213
+ <Button
214
+ variant={newKeyMode === 'read' ? 'default' : 'outline'}
215
+ size="sm"
216
+ onclick={() => (newKeyMode = 'read')}>Read only</Button
217
+ >
218
+ <Button
219
+ variant={newKeyMode === 'write' ? 'default' : 'outline'}
220
+ size="sm"
221
+ onclick={() => (newKeyMode = 'write')}>Read + write</Button
222
+ >
223
+ </div>
224
+ </div>
225
+ <div>
226
+ <Label for="expires">Expires in</Label>
227
+ <Select.Root
228
+ type="single"
229
+ name="expiration"
230
+ bind:value={newKeyExpiresValue}
231
+ onValueChange={(value) => {
232
+ if (value)
233
+ newKeyExpiresInDays = value === 'never' ? undefined : parseInt(value);
234
+ }}
235
+ >
236
+ <Select.Trigger class="mt-1 w-[180px]"
237
+ >{expirationTriggerContent}</Select.Trigger
238
+ >
239
+ <Select.Content>
240
+ <Select.Group>
241
+ {#each expirationOptions as option (option.value)}
242
+ <Select.Item value={option.value} label={option.label}
243
+ >{option.label}</Select.Item
244
+ >
245
+ {/each}
246
+ </Select.Group>
247
+ </Select.Content>
248
+ </Select.Root>
249
+ </div>
250
+ </div>
251
+ <DialogFooter>
252
+ <Button
253
+ variant="outline"
254
+ onclick={() => (createDialogOpen = false)}
255
+ disabled={isCreating}>Cancel</Button
256
+ >
257
+ <Button onclick={createApiKey} disabled={isCreating}
258
+ >{isCreating ? 'Creating...' : 'Create key'}</Button
259
+ >
260
+ </DialogFooter>
261
+ {/if}
262
+ </DialogContent>
263
+ </Dialog>
264
+ {/if}
265
+ </div>
266
+ <Alert.Root class="bg-muted/50 text-muted-foreground px-3 py-2">
267
+ <Alert.Description>
268
+ Tokens are shown once. Treat them like passwords: store them in a secrets manager and never
269
+ commit them to source.
270
+ </Alert.Description>
271
+ </Alert.Root>
272
+ </Card.Header>
273
+
274
+ <Card.Content class="pt-0">
275
+ {#if apiKeys.length === 0}
276
+ <div
277
+ class="border-border flex flex-col items-center justify-center rounded-lg border border-dashed py-12 text-center"
278
+ >
279
+ <div class="bg-muted mb-4 rounded-full p-3">
280
+ <KeyRound class="text-muted-foreground h-6 w-6" />
281
+ </div>
282
+ <p class="text-base font-medium">No API keys yet</p>
283
+ <p class="text-muted-foreground mt-1 text-sm">
284
+ Create a token to access CMS data programmatically.
285
+ </p>
286
+ </div>
287
+ {:else}
288
+ <div class="border-border hidden overflow-hidden rounded-lg border md:block">
289
+ <div
290
+ class="bg-muted/30 text-muted-foreground grid grid-cols-[minmax(140px,1fr)_96px_130px_100px_100px_76px] border-b px-4 py-2 text-xs font-medium tracking-wide uppercase"
291
+ >
292
+ <div>Name</div>
293
+ <div>Token</div>
294
+ <div>Scope</div>
295
+ <div>Created</div>
296
+ <div>Last used</div>
297
+ <div></div>
298
+ </div>
299
+ <div class="divide-y">
300
+ {#each apiKeys as apiKey (apiKey.id)}
301
+ <div
302
+ class="grid grid-cols-[minmax(140px,1fr)_96px_130px_100px_100px_76px] items-center px-4 py-3 text-sm"
303
+ >
304
+ <div class="truncate font-medium">{apiKey.name ?? 'Unnamed key'}</div>
305
+ <div class="text-muted-foreground truncate font-mono text-xs">shown once</div>
306
+ <div>
307
+ <Badge variant="outline" class="font-mono text-xs"
308
+ >{formatPermissions(apiKey.permissions)}</Badge
309
+ >
310
+ </div>
311
+ <div class="text-muted-foreground">{formatDate(apiKey.createdAt)}</div>
312
+ <div class="text-muted-foreground">{formatDate(apiKey.lastRequest)}</div>
313
+ <div class="flex justify-end">
314
+ {#if canManageApiKeys}
315
+ <Button
316
+ variant="outline"
317
+ size="sm"
318
+ onclick={() => deleteApiKey(apiKey.id, apiKey.name ?? 'Unnamed')}>Delete</Button
319
+ >
320
+ {/if}
321
+ </div>
322
+ </div>
323
+ {/each}
324
+ </div>
325
+ </div>
326
+
327
+ <div class="space-y-3 md:hidden">
328
+ {#each apiKeys as apiKey (apiKey.id)}
329
+ <div class="border-border rounded-lg border p-4">
330
+ <div class="flex items-start justify-between gap-3">
331
+ <div class="min-w-0">
332
+ <p class="truncate text-sm font-medium">{apiKey.name ?? 'Unnamed key'}</p>
333
+ <p class="text-muted-foreground mt-1 font-mono text-xs">Token shown once</p>
334
+ </div>
335
+ <Badge variant="outline" class="font-mono text-xs"
336
+ >{formatPermissions(apiKey.permissions)}</Badge
337
+ >
338
+ </div>
339
+ <div class="mt-4 grid grid-cols-2 gap-3 text-sm">
340
+ <div>
341
+ <p class="text-muted-foreground text-xs">Created</p>
342
+ <p class="mt-1">{formatDate(apiKey.createdAt)}</p>
343
+ </div>
344
+ <div>
345
+ <p class="text-muted-foreground text-xs">Last used</p>
346
+ <p class="mt-1">{formatDate(apiKey.lastRequest)}</p>
347
+ </div>
348
+ </div>
349
+ {#if canManageApiKeys}
350
+ <Button
351
+ class="mt-4 w-full"
352
+ variant="outline"
353
+ size="sm"
354
+ onclick={() => deleteApiKey(apiKey.id, apiKey.name ?? 'Unnamed')}
355
+ >
356
+ <Trash2 class="mr-1.5 h-4 w-4" />
357
+ Delete key
358
+ </Button>
359
+ {/if}
360
+ </div>
361
+ {/each}
362
+ </div>
363
+ {/if}
364
+ </Card.Content>
365
+ </Card.Root>
366
+
367
+ <Card.Root class="mt-5">
368
+ <Card.Header>
369
+ <div class="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
370
+ <div class="space-y-1.5">
371
+ <Card.Title class="text-base">API reference</Card.Title>
372
+ <Card.Description
373
+ >Use the key in the <code class="bg-muted rounded px-1 py-0.5 text-xs">x-api-key</code>
374
+ header.</Card.Description
375
+ >
376
+ </div>
377
+
378
+ {#if apiDocsHref}
379
+ <!-- The generated reference describes every endpoint and the exact
380
+ shape of your own documents; the summary below is a starting
381
+ point, not the list. -->
382
+ <Button variant="outline" size="sm" href={apiDocsHref} target="_blank" rel="noopener"
383
+ ><BookOpen class="h-3.5 w-3.5" /> Browse the full API</Button
384
+ >
385
+ {/if}
386
+ </div>
387
+ </Card.Header>
388
+ <Card.Content class="space-y-4">
389
+ <div class="bg-muted relative rounded-md p-3 pr-11">
390
+ <code class="block font-mono text-xs leading-relaxed break-all">
391
+ curl -H "x-api-key: your_key_here"
392
+ https://your-app.com/api/documents?type=&#123;schemaType&#125;
393
+ </code>
394
+ <Button
395
+ variant="ghost"
396
+ size="icon"
397
+ class="absolute top-2 right-2 h-7 w-7"
398
+ onclick={() =>
399
+ copyToClipboard(
400
+ 'curl -H "x-api-key: your_key_here" https://your-app.com/api/documents?type={schemaType}'
401
+ )}
402
+ >
403
+ <Copy class="h-3.5 w-3.5" />
404
+ </Button>
405
+ </div>
406
+
407
+ <div class="grid gap-2 text-sm sm:grid-cols-2">
408
+ <div class="border-border rounded-md border p-3">
409
+ <p class="font-medium">Read endpoints</p>
410
+ <div class="text-muted-foreground mt-2 space-y-1 font-mono text-xs">
411
+ <p>GET /api/documents?type=&#123;type&#125;</p>
412
+ <p>GET /api/documents/&#123;id&#125;</p>
413
+ <p>POST /api/documents/query</p>
414
+ <p>GET /api/assets</p>
415
+ <p>GET /api/schemas</p>
416
+ </div>
417
+ </div>
418
+ <div class="border-border rounded-md border p-3">
419
+ <p class="font-medium">Write endpoints</p>
420
+ <div class="text-muted-foreground mt-2 space-y-1 font-mono text-xs">
421
+ <p>POST /api/documents</p>
422
+ <p>PUT /api/documents/&#123;id&#125;</p>
423
+ <p>DELETE /api/documents/&#123;id&#125;</p>
424
+ <p>POST /api/assets</p>
425
+ </div>
426
+ </div>
427
+ </div>
428
+
429
+ <p class="text-muted-foreground text-xs leading-relaxed">
430
+ Read-only keys can use read endpoints. Write keys can create, update, and delete documents and
431
+ upload assets. <code class="bg-muted rounded px-1 py-0.5">POST /api/documents/query</code> only
432
+ requires read access.
433
+ </p>
434
+ </Card.Content>
435
+ </Card.Root>
@@ -0,0 +1,15 @@
1
+ import type { ApiKeySummary } from '../../types/api-key.js';
2
+ type Props = {
3
+ apiKeys: ApiKeySummary[];
4
+ organizationRole?: string | null;
5
+ /**
6
+ * Path to the rendered API reference, or `null` on an instance that
7
+ * unmounted it (`openapi.docsUi: false`) — resolved server-side so this
8
+ * never links to a 404.
9
+ */
10
+ apiDocsHref?: string | null;
11
+ };
12
+ declare const ApiKeysSettings: import("svelte").Component<Props, {}, "">;
13
+ type ApiKeysSettings = ReturnType<typeof ApiKeysSettings>;
14
+ export default ApiKeysSettings;
15
+ //# sourceMappingURL=ApiKeysSettings.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiKeysSettings.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/components/admin/ApiKeysSettings.svelte.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAOxD,KAAK,KAAK,GAAG;IACZ,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAgWH,QAAA,MAAM,eAAe,2CAAwC,CAAC;AAC9D,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAC1D,eAAe,eAAe,CAAC"}
@@ -0,0 +1,32 @@
1
+ <script lang="ts">
2
+ /**
3
+ * The frame around the signed-out account pages: login, invitation links, password
4
+ * reset and the two-factor challenge. Per-tenant branding applies to all of them, so
5
+ * a page opened from an email looks like the login it leads to.
6
+ */
7
+ import type { Snippet } from 'svelte';
8
+ import type { LoginBranding } from '../../types/auth';
9
+
10
+ let {
11
+ branding,
12
+ title,
13
+ children
14
+ }: { branding: LoginBranding | null; title: string; children: Snippet } = $props();
15
+
16
+ const brandTitle = $derived(branding?.title ?? title);
17
+ // Any CSS color the host returns becomes the page's `--primary`, so buttons and
18
+ // links pick up the tenant's color with no stylesheet per tenant.
19
+ const style = $derived(branding?.accentColor ? `--primary: ${branding.accentColor};` : undefined);
20
+ </script>
21
+
22
+ <div class="bg-muted/40 flex min-h-screen items-center justify-center px-4 py-12" {style}>
23
+ <div class="w-full max-w-md">
24
+ {#if branding?.logoUrl}
25
+ <div class="mb-6 flex justify-center">
26
+ <img src={branding.logoUrl} alt={brandTitle} class="max-h-16 w-auto object-contain" />
27
+ </div>
28
+ {/if}
29
+ {@render children()}
30
+ <p class="text-muted-foreground mt-6 text-center text-xs">{brandTitle}</p>
31
+ </div>
32
+ </div>
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The frame around the signed-out account pages: login, invitation links, password
3
+ * reset and the two-factor challenge. Per-tenant branding applies to all of them, so
4
+ * a page opened from an email looks like the login it leads to.
5
+ */
6
+ import type { Snippet } from 'svelte';
7
+ import type { LoginBranding } from '../../types/auth.js';
8
+ type $$ComponentProps = {
9
+ branding: LoginBranding | null;
10
+ title: string;
11
+ children: Snippet;
12
+ };
13
+ declare const AuthPageShell: import("svelte").Component<$$ComponentProps, {}, "">;
14
+ type AuthPageShell = ReturnType<typeof AuthPageShell>;
15
+ export default AuthPageShell;
16
+ //# sourceMappingURL=AuthPageShell.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthPageShell.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/components/admin/AuthPageShell.svelte.ts"],"names":[],"mappings":"AAGA;;;;OAII;AACJ,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAErD,KAAK,gBAAgB,GAAI;IAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAgC/F,QAAA,MAAM,aAAa,sDAAwC,CAAC;AAC5D,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACtD,eAAe,aAAa,CAAC"}
@@ -0,0 +1,158 @@
1
+ <script lang="ts">
2
+ import { goto, invalidateAll } from '$app/navigation';
3
+ import { Button } from '@aphexcms/ui/shadcn/button';
4
+ import { Input } from '@aphexcms/ui/shadcn/input';
5
+ import { Label } from '@aphexcms/ui/shadcn/label';
6
+ import * as Dialog from '@aphexcms/ui/shadcn/dialog';
7
+ import { organizations } from '../../api/organizations';
8
+
9
+ let {
10
+ startOpen = false,
11
+ parentOption = null
12
+ }: { startOpen?: boolean; parentOption?: { id: string; name: string } | null } = $props();
13
+
14
+ // The organization switcher links here with `?action=create`. Only the first value
15
+ // counts: after that the dialog's own open and close state decides.
16
+ // svelte-ignore state_referenced_locally
17
+ let open = $state(startOpen);
18
+ let name = $state('');
19
+ let insideParent = $state(false);
20
+ let slug = $state('');
21
+ let isSubmitting = $state(false);
22
+ let error = $state<string | null>(null);
23
+
24
+ function generateSlug(text: string): string {
25
+ return text
26
+ .toLowerCase()
27
+ .trim()
28
+ .replace(/[^\w\s-]/g, '')
29
+ .replace(/[\s_-]+/g, '-')
30
+ .replace(/^-+|-+$/g, '');
31
+ }
32
+
33
+ function handleNameInput(event: Event) {
34
+ const target = event.target as HTMLInputElement;
35
+ name = target.value;
36
+ if (!slug || slug === generateSlug(name.slice(0, -1))) {
37
+ slug = generateSlug(name);
38
+ }
39
+ }
40
+
41
+ function handleSlugInput(event: Event) {
42
+ const target = event.target as HTMLInputElement;
43
+ slug = target.value.toLowerCase().replace(/[^a-z0-9-]/g, '');
44
+ }
45
+
46
+ function resetForm() {
47
+ name = '';
48
+ slug = '';
49
+ insideParent = false;
50
+ error = null;
51
+ }
52
+
53
+ async function handleSubmit(event: Event) {
54
+ event.preventDefault();
55
+ error = null;
56
+
57
+ if (!name.trim() || !slug.trim()) {
58
+ error = 'Name and slug are required';
59
+ return;
60
+ }
61
+
62
+ isSubmitting = true;
63
+ try {
64
+ const result = await organizations.create({
65
+ name: name.trim(),
66
+ slug: slug.trim(),
67
+ ...(insideParent && parentOption ? { parentOrganizationId: parentOption.id } : {})
68
+ });
69
+
70
+ if (!result.success || !result.data) {
71
+ throw new Error('Failed to create organization');
72
+ }
73
+
74
+ resetForm();
75
+ open = false;
76
+ await invalidateAll();
77
+ await goto(`/admin?orgId=${result.data.id}`);
78
+ } catch (err) {
79
+ error = err instanceof Error ? err.message : 'Failed to create organization';
80
+ } finally {
81
+ isSubmitting = false;
82
+ }
83
+ }
84
+ </script>
85
+
86
+ <Dialog.Root bind:open onOpenChange={(v) => !v && resetForm()}>
87
+ <Dialog.Trigger>
88
+ {#snippet child({ props })}
89
+ <Button {...props}>Create Organization</Button>
90
+ {/snippet}
91
+ </Dialog.Trigger>
92
+ <Dialog.Content class="sm:max-w-[480px]">
93
+ <Dialog.Header>
94
+ <Dialog.Title>Create Organization</Dialog.Title>
95
+ <Dialog.Description>You'll be its owner, and can invite people to it.</Dialog.Description>
96
+ </Dialog.Header>
97
+ <form onsubmit={handleSubmit} class="grid gap-4 py-4">
98
+ <div>
99
+ <Label for="org-name">Organization name</Label>
100
+ <Input
101
+ id="org-name"
102
+ value={name}
103
+ oninput={handleNameInput}
104
+ placeholder="My Organization"
105
+ disabled={isSubmitting}
106
+ class="mt-1"
107
+ />
108
+ </div>
109
+ <div>
110
+ <Label for="org-slug">Slug</Label>
111
+ <div class="mt-1 flex gap-2">
112
+ <Input
113
+ id="org-slug"
114
+ value={slug}
115
+ oninput={handleSlugInput}
116
+ placeholder="my-organization"
117
+ disabled={isSubmitting}
118
+ class="flex-1"
119
+ />
120
+ <Button
121
+ type="button"
122
+ variant="outline"
123
+ size="sm"
124
+ onclick={() => (slug = generateSlug(name))}
125
+ disabled={!name.trim() || isSubmitting}
126
+ >
127
+ Generate
128
+ </Button>
129
+ </div>
130
+ <p class="text-muted-foreground mt-1 text-xs">
131
+ Lowercase letters, numbers, and hyphens only.
132
+ </p>
133
+ </div>
134
+ {#if parentOption}
135
+ <label class="flex items-center gap-2 text-sm">
136
+ <input type="checkbox" bind:checked={insideParent} disabled={isSubmitting} />
137
+ Create inside {parentOption.name}
138
+ </label>
139
+ {/if}
140
+ {#if error}
141
+ <p class="text-destructive text-sm">{error}</p>
142
+ {/if}
143
+ <Dialog.Footer>
144
+ <Button
145
+ type="button"
146
+ variant="outline"
147
+ onclick={() => (open = false)}
148
+ disabled={isSubmitting}
149
+ >
150
+ Cancel
151
+ </Button>
152
+ <Button type="submit" disabled={isSubmitting || !name.trim()}>
153
+ {isSubmitting ? 'Creating...' : 'Create'}
154
+ </Button>
155
+ </Dialog.Footer>
156
+ </form>
157
+ </Dialog.Content>
158
+ </Dialog.Root>
@@ -0,0 +1,11 @@
1
+ type $$ComponentProps = {
2
+ startOpen?: boolean;
3
+ parentOption?: {
4
+ id: string;
5
+ name: string;
6
+ } | null;
7
+ };
8
+ declare const CreateOrganization: import("svelte").Component<$$ComponentProps, {}, "">;
9
+ type CreateOrganization = ReturnType<typeof CreateOrganization>;
10
+ export default CreateOrganization;
11
+ //# sourceMappingURL=CreateOrganization.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateOrganization.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/components/admin/CreateOrganization.svelte.ts"],"names":[],"mappings":"AAUC,KAAK,gBAAgB,GAAI;IAAE,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;CAAE,CAAC;AAyItG,QAAA,MAAM,kBAAkB,sDAAwC,CAAC;AACjE,KAAK,kBAAkB,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAChE,eAAe,kBAAkB,CAAC"}