@krak-stack/auth 0.1.55 → 0.1.57

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.
@@ -5,16 +5,17 @@ import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
5
5
  import {} from "@tanstack/react-table";
6
6
  import { Effect, Option, Schema } from "effect";
7
7
  import { AsyncResult, Atom } from "effect/unstable/reactivity";
8
- import { Building2, Check, ChevronsUpDown, Copy, KeyRound, LogOut, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
8
+ import { ArrowLeft, Building2, Check, ChevronsUpDown, Copy, KeyRound, LogOut, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
9
9
  import { createContext, useContext, useEffect, useEffectEvent, useRef, useState, } from "react";
10
10
  import { DataTable, DataTableRelationshipCell, } from "@/components/ui/data-table";
11
- import { ErrorMessage, ImageField, SelectField, SubmitButton, SubmitError, TextField, } from "@/components/ui/effect-form";
11
+ import { ErrorMessage, ImageField, SelectField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@/components/ui/effect-form";
12
12
  import { EditingLocaleSwitcher } from "@/components/ui/editing-locale-switcher";
13
13
  import { AppBrand } from "@/components/ui/app-brand";
14
14
  import { Field, FieldLabel, FieldSet } from "@/components/ui/field";
15
15
  import { Input } from "@/components/ui/input";
16
16
  import { Badge } from "@/components/ui/badge";
17
17
  import { Button } from "@/components/ui/button";
18
+ import { CopyButton } from "@/components/ui/copy-button";
18
19
  import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
19
20
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
20
21
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
@@ -23,14 +24,17 @@ import { OrganizationEmail, OrganizationAddress, OrganizationMetadata, Organizat
23
24
  import { isOrganizationRole, normalizeOrganizationRole, normalizeOrganizationRoles, organizationRoles, } from "../roles";
24
25
  import { authClientApi } from "./auth-client-api";
25
26
  import { useKrakstackAuth } from "./auth-provider";
26
- import { createApiKey } from "./api-key";
27
+ import { createApiKey, parseApiKeyReferrers } from "./api-key";
28
+ import { ApiKeyEditForm } from "./api-key-edit-form";
29
+ import { ApiKeyRateLimit, apiKeyUsagePercent } from "./api-key-rate-limit";
30
+ import { ApiKeyReferrers } from "./api-key-referrers";
27
31
  import { useOpenedOnce } from "./hooks";
28
32
  import { invitationDisplayStatus, isInvitationExpired, useInvitationExpirationClock, } from "./invitation-expiration";
29
33
  import { ExtraUploadedAsset } from "../extra/schema";
30
34
  import { assetPath, assetUrl, cn } from "./utils";
31
35
  const messages = {
32
36
  en: {
33
- api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
37
+ organization_back: "Back",
34
38
  organization_contact: "Contact methods",
35
39
  organization_contact_add_email: "Add email",
36
40
  organization_contact_add_phone: "Add phone",
@@ -102,6 +106,7 @@ const messages = {
102
106
  organization_member_role_error: "Could not update the member role.",
103
107
  organization_member_user: "User",
104
108
  organization_members_description: "Review active members, update roles, and remove access when needed.",
109
+ organization_members_dialog_description: "Manage members and invitations for {name}.",
105
110
  organization_members_empty: "No members found.",
106
111
  organization_members_heading: "Organization members",
107
112
  organization_members_load_error: "Could not load organization members.",
@@ -122,24 +127,47 @@ const messages = {
122
127
  organization_translation_name: "Name",
123
128
  organization_update_error: "Could not update the organization.",
124
129
  table_empty: "No results.",
130
+ user_api_key_back: "Back",
131
+ user_api_key_create_description: "Configure a new API key for this organization.",
125
132
  user_api_key_create_error: "Could not create the API key.",
133
+ user_api_key_create_title: "Create API key",
134
+ user_api_key_copied: "Copied",
135
+ user_api_key_copy: "Copy",
126
136
  user_api_key_created_description: "Copy this key now. You will not be able to see it again.",
127
137
  user_api_key_created_title: "API key created",
128
138
  user_api_key_delete_error: "Could not delete the API key.",
129
139
  user_api_key_disabled: "Disabled",
140
+ user_api_key_edit_description: "Update the key name, status, and allowed referrers.",
141
+ user_api_key_edit_title: "Edit API key",
130
142
  user_api_key_enabled: "Enabled",
131
143
  user_api_key_hidden: "Secret hidden",
132
144
  user_api_key_name: "Key name",
145
+ user_api_key_rate_limit: "Rate limit",
146
+ user_api_key_referrers: "Allowed referrers (optional)",
147
+ user_api_key_referrers_any: "Any referrer",
148
+ user_api_key_referrers_column: "Referrers",
149
+ user_api_key_referrers_description: "Enter any number of URLs, separated by commas or new lines. Leave empty to allow any referrer.",
150
+ user_api_key_referrers_error: "{referrer} is not a valid HTTP(S) URL.",
151
+ user_api_key_referrers_placeholder: "https://app.example.com\nhttps://admin.example.com",
133
152
  user_api_key_starts_with: "Starts with {start}",
134
153
  user_api_key_status: "Status",
154
+ user_api_key_unlimited: "Unlimited",
155
+ user_api_key_update_error: "Could not update the API key.",
156
+ user_api_key_usage: "API key usage",
157
+ user_api_key_window_days: "{count}d",
158
+ user_api_key_window_hours: "{count}h",
159
+ user_api_key_window_minutes: "{count}m",
160
+ user_api_key_window_none: "None",
161
+ user_api_key_window_seconds: "{count}s",
135
162
  user_api_keys_load_error: "Could not load API keys.",
163
+ user_api_keys_organization_description: "Create and manage API keys for {name}.",
136
164
  user_api_keys_title: "API keys",
137
165
  user_button_api_keys: "API keys",
138
166
  user_delete: "Delete",
139
167
  user_loading: "Loading...",
140
168
  },
141
169
  fr: {
142
- api_key_rate_limit_notice: "Les clés API sont soumises aux mêmes limites de débit que votre compte.",
170
+ organization_back: "Retour",
143
171
  organization_contact: "Moyens de contact",
144
172
  organization_contact_add_email: "Ajouter un courriel",
145
173
  organization_contact_add_phone: "Ajouter un téléphone",
@@ -211,6 +239,7 @@ const messages = {
211
239
  organization_member_role_error: "Impossible de modifier le rôle du membre.",
212
240
  organization_member_user: "Utilisateur",
213
241
  organization_members_description: "Consultez les membres actifs, modifiez les rôles et retirez les accès au besoin.",
242
+ organization_members_dialog_description: "Gérez les membres et les invitations de {name}.",
214
243
  organization_members_empty: "Aucun membre trouvé.",
215
244
  organization_members_heading: "Membres de l'organisation",
216
245
  organization_members_load_error: "Impossible de charger les membres de l'organisation.",
@@ -231,17 +260,40 @@ const messages = {
231
260
  organization_translation_name: "Nom",
232
261
  organization_update_error: "Impossible de mettre à jour l'organisation.",
233
262
  table_empty: "Aucun résultat.",
263
+ user_api_key_back: "Retour",
264
+ user_api_key_create_description: "Configurez une nouvelle clé API pour cette organisation.",
234
265
  user_api_key_create_error: "Impossible de créer la clé API.",
266
+ user_api_key_create_title: "Créer une clé API",
267
+ user_api_key_copied: "Copié",
268
+ user_api_key_copy: "Copier",
235
269
  user_api_key_created_description: "Copiez cette clé maintenant. Vous ne pourrez plus la voir.",
236
270
  user_api_key_created_title: "Clé API créée",
237
271
  user_api_key_delete_error: "Impossible de supprimer la clé API.",
238
272
  user_api_key_disabled: "Désactivée",
273
+ user_api_key_edit_description: "Mettez à jour le nom, le statut et les référents autorisés de la clé.",
274
+ user_api_key_edit_title: "Modifier la clé API",
239
275
  user_api_key_enabled: "Activée",
240
276
  user_api_key_hidden: "Secret masqué",
241
277
  user_api_key_name: "Nom de la clé",
278
+ user_api_key_rate_limit: "Limite de débit",
279
+ user_api_key_referrers: "Référents autorisés (facultatifs)",
280
+ user_api_key_referrers_any: "Tout référent",
281
+ user_api_key_referrers_column: "Référents",
282
+ user_api_key_referrers_description: "Saisissez autant d'URL que nécessaire, séparées par des virgules ou des sauts de ligne. Laissez vide pour autoriser tout référent.",
283
+ user_api_key_referrers_error: "{referrer} n'est pas une URL HTTP(S) valide.",
284
+ user_api_key_referrers_placeholder: "https://app.example.com\nhttps://admin.example.com",
242
285
  user_api_key_starts_with: "Commence par {start}",
243
286
  user_api_key_status: "Statut",
287
+ user_api_key_unlimited: "Illimitée",
288
+ user_api_key_update_error: "Impossible de mettre à jour la clé API.",
289
+ user_api_key_usage: "Utilisation de la clé API",
290
+ user_api_key_window_days: "{count} j",
291
+ user_api_key_window_hours: "{count} h",
292
+ user_api_key_window_minutes: "{count} min",
293
+ user_api_key_window_none: "Aucune",
294
+ user_api_key_window_seconds: "{count} s",
244
295
  user_api_keys_load_error: "Impossible de charger les clés API.",
296
+ user_api_keys_organization_description: "Créez et gérez les clés API de {name}.",
245
297
  user_api_keys_title: "Clés API",
246
298
  user_button_api_keys: "Clés API",
247
299
  user_delete: "Supprimer",
@@ -479,7 +531,9 @@ const organizationFormFields = {
479
531
  const inviteMemberFormBuilder = FormBuilder.empty
480
532
  .addField("email", Schema.NonEmptyString)
481
533
  .addField("role", Schema.String);
482
- const apiKeyFormBuilder = FormBuilder.empty.addField("name", Schema.NonEmptyString);
534
+ const apiKeyFormBuilder = FormBuilder.empty
535
+ .addField("name", Schema.NonEmptyString)
536
+ .addField("referrers", Schema.String);
483
537
  const slugify = (value) => value
484
538
  .trim()
485
539
  .toLowerCase()
@@ -886,14 +940,14 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
886
940
  setDialog((current) => open ? "manage" : current === "manage" ? null : current);
887
941
  }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-2xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() }), _jsx("div", { className: "pt-2", children: _jsx(EditingLocaleSwitcher, { value: editingOrganizationLocale, onValueChange: setEditingOrganizationLocale }) })] }), _jsx(Separator, {}), activeOrganization.data && canUpdateOrganization ? (_jsx(EditOrganizationSection, { authClient: authClient, baseUrl: baseUrl, editingLocale: editingOrganizationLocale, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
888
942
  setDialog((current) => open ? "members" : current === "members" ? null : current);
889
- }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_members_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationMembersManager, { authClient: authClient, baseUrl: baseUrl, canManageMembers: canManageApiKeys, organization: activeOrganization.data, currentUserId: session.data.user.id, active: dialog === "members", onLeft: async () => {
890
- setDialog(null);
891
- auth?.refreshAuth();
892
- await refresh();
893
- onChange?.(null);
894
- } })) : null] }) }), _jsx(Dialog, { open: dialog === "apiKeys" && canManageApiKeys, onOpenChange: (open) => {
943
+ }, children: _jsx(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: activeOrganization.data ? (_jsx(OrganizationMembersManager, { authClient: authClient, baseUrl: baseUrl, canManageMembers: canManageApiKeys, organization: activeOrganization.data, currentUserId: session.data.user.id, active: dialog === "members", onLeft: async () => {
944
+ setDialog(null);
945
+ auth?.refreshAuth();
946
+ await refresh();
947
+ onChange?.(null);
948
+ } })) : null }) }), _jsx(Dialog, { open: dialog === "apiKeys" && canManageApiKeys, onOpenChange: (open) => {
895
949
  setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
896
- }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_api_keys_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationApiKeyManager, { authClient: authClient, organization: activeOrganization.data, active: dialog === "apiKeys" && canManageApiKeys })) : null] }) }), _jsx(Dialog, { open: dialog === "invitations" && canViewOrganizationInvitations, onOpenChange: (open) => {
950
+ }, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: activeOrganization.data ? (_jsx(OrganizationApiKeyManager, { authClient: authClient, organization: activeOrganization.data, active: dialog === "apiKeys" && canManageApiKeys })) : null }) }), _jsx(Dialog, { open: dialog === "invitations" && canViewOrganizationInvitations, onOpenChange: (open) => {
897
951
  setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
898
952
  }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }), _jsx(Separator, {}), _jsx(UserInvitationsManager, { authClient: authClient, baseUrl: baseUrl, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, ...(activeOrganization.data
899
953
  ? { activeOrganizationId: activeOrganization.data.id }
@@ -1161,6 +1215,7 @@ function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, org
1161
1215
  : emptyOrganizationMembersAtom;
1162
1216
  const membersResult = useAtomValue(membersAtom);
1163
1217
  const refreshMembers = useAtomRefresh(membersAtom);
1218
+ const [inviting, setInviting] = useState(false);
1164
1219
  const [error, setError] = useState(null);
1165
1220
  const [cancellingInvitationId, setCancellingInvitationId] = useState(null);
1166
1221
  const [leavingOrganization, setLeavingOrganization] = useState(false);
@@ -1223,8 +1278,10 @@ function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, org
1223
1278
  const resetInvitation = useAtomSet(inviteForm.reset);
1224
1279
  const inviteResult = useAtomValue(inviteForm.submit);
1225
1280
  useEffect(() => {
1226
- if (AsyncResult.isSuccess(inviteResult))
1227
- resetInvitation();
1281
+ if (!AsyncResult.isSuccess(inviteResult))
1282
+ return;
1283
+ resetInvitation();
1284
+ setInviting(false);
1228
1285
  }, [inviteResult, resetInvitation]);
1229
1286
  const updateRole = async (member, role) => {
1230
1287
  setError(null);
@@ -1286,45 +1343,51 @@ function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, org
1286
1343
  }
1287
1344
  refreshMembers();
1288
1345
  };
1289
- return (_jsxs("div", { className: "flex min-w-0 flex-col gap-5", children: [canInviteMembers ? (_jsx("div", { className: "min-h-40 rounded-lg border p-4", children: _jsx(inviteForm.Initialize, { defaultValues: { email: "", role: "member" }, children: _jsxs("form", { className: "grid gap-4 sm:grid-cols-[minmax(0,1fr)_12rem_auto] sm:items-end", onSubmit: (event) => {
1290
- event.preventDefault();
1291
- event.stopPropagation();
1292
- submitInvitation();
1293
- }, children: [_jsxs("div", { className: "sm:col-span-3", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium", children: [_jsx(UserPlus, { className: "size-4" }), m.organization_invite_member_title()] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invite_member_description() })] }), _jsx(inviteForm.email, { label: m.organization_member_email(), placeholder: "teammate@example.com", type: "email", required: true }), _jsx(inviteForm.role, { label: m.organization_member_role(), options: organizationRoles.map((role) => ({
1294
- label: organizationRoleLabel(role, m),
1295
- value: role,
1296
- })) }), _jsx("div", { className: "self-end", children: _jsx(SubmitButton, { form: inviteForm }) }), _jsx(SubmitError, { result: inviteResult })] }) }) })) : null, membersError ? (_jsx("p", { className: "text-destructive text-sm", children: membersError })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_members_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_members_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: memberColumns({
1297
- m,
1298
- baseUrl,
1299
- canChangeRoles: canManageMembers,
1300
- onRoleChange: updateRole,
1301
- }), data: displayedMembers, features: {
1302
- export: { baseName: `${organization.slug}-members` },
1303
- gallery: false,
1304
- rowActions: {
1305
- items: memberRowActions({
1346
+ return (_jsxs(_Fragment, { children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: inviting
1347
+ ? m.organization_invite_member_title()
1348
+ : m.organization_members_title() }), _jsx(DialogDescription, { children: inviting
1349
+ ? m.organization_invite_member_description()
1350
+ : m.organization_members_dialog_description({
1351
+ name: organization.name,
1352
+ }) }), inviting ? (_jsxs(Button, { className: "mt-2 w-fit", onClick: () => setInviting(false), type: "button", variant: "secondary", children: [_jsx(ArrowLeft, {}), m.organization_back()] })) : canInviteMembers ? (_jsxs(Button, { className: "mt-2 w-fit", onClick: () => setInviting(true), type: "button", children: [_jsx(UserPlus, {}), m.organization_invite_member_title()] })) : null] }), _jsx(Separator, {}), _jsxs("div", { className: "flex min-w-0 flex-col gap-5", children: [inviting ? (_jsx(inviteForm.Initialize, { defaultValues: { email: "", role: "member" }, children: _jsxs("form", { className: "grid gap-4 sm:grid-cols-[minmax(0,1fr)_12rem_auto] sm:items-end", onSubmit: (event) => {
1353
+ event.preventDefault();
1354
+ event.stopPropagation();
1355
+ submitInvitation();
1356
+ }, children: [_jsx(inviteForm.email, { label: m.organization_member_email(), placeholder: "teammate@example.com", type: "email", required: true }), _jsx(inviteForm.role, { label: m.organization_member_role(), options: organizationRoles.map((role) => ({
1357
+ label: organizationRoleLabel(role, m),
1358
+ value: role,
1359
+ })) }), _jsx("div", { className: "self-end", children: _jsx(SubmitButton, { form: inviteForm }) }), _jsx(SubmitError, { result: inviteResult })] }) })) : null, !inviting && membersError ? (_jsx("p", { className: "text-destructive text-sm", children: membersError })) : null, !inviting && error ? (_jsx("p", { className: "text-destructive text-sm", children: error })) : null, !inviting ? (_jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_members_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_members_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: memberColumns({
1306
1360
  m,
1307
- canRemoveMembers,
1308
- currentUserId,
1309
- leavingOrganization,
1310
- onLeave: leaveOrganization,
1311
- onRemove: removeMember,
1312
- }),
1313
- },
1314
- }, searchState: "local", state: { empty: m.organization_members_empty(), loading } }) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_invitations_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invitations_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: invitationColumns({
1315
- m,
1316
- now: invitationNow,
1317
- }), data: invitations, features: {
1318
- export: { baseName: `${organization.slug}-invitations` },
1319
- gallery: false,
1320
- rowActions: {
1321
- items: invitationRowActions({
1361
+ baseUrl,
1362
+ canChangeRoles: canManageMembers,
1363
+ onRoleChange: updateRole,
1364
+ }), data: displayedMembers, features: {
1365
+ export: { baseName: `${organization.slug}-members` },
1366
+ gallery: false,
1367
+ rowActions: {
1368
+ items: memberRowActions({
1369
+ m,
1370
+ canRemoveMembers,
1371
+ currentUserId,
1372
+ leavingOrganization,
1373
+ onLeave: leaveOrganization,
1374
+ onRemove: removeMember,
1375
+ }),
1376
+ },
1377
+ }, searchState: "local", state: { empty: m.organization_members_empty(), loading } }) })] })) : null, !inviting ? (_jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_invitations_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invitations_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: invitationColumns({
1322
1378
  m,
1323
- cancellingInvitationId,
1324
- onCancel: cancelInvitation,
1325
- }),
1326
- },
1327
- }, searchState: "local", state: { empty: m.organization_invitations_empty(), loading } }) })] })] }));
1379
+ now: invitationNow,
1380
+ }), data: invitations, features: {
1381
+ export: { baseName: `${organization.slug}-invitations` },
1382
+ gallery: false,
1383
+ rowActions: {
1384
+ items: invitationRowActions({
1385
+ m,
1386
+ cancellingInvitationId,
1387
+ onCancel: cancelInvitation,
1388
+ }),
1389
+ },
1390
+ }, searchState: "local", state: { empty: m.organization_invitations_empty(), loading } }) })] })) : null] })] }));
1328
1391
  }
1329
1392
  const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
1330
1393
  {
@@ -1427,6 +1490,8 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
1427
1490
  const keysResult = useAtomValue(keysAtom);
1428
1491
  const refreshKeys = useAtomRefresh(keysAtom);
1429
1492
  const [createdKey, setCreatedKey] = useState(null);
1493
+ const [creating, setCreating] = useState(false);
1494
+ const [editingKey, setEditingKey] = useState(null);
1430
1495
  const [error, setError] = useState(null);
1431
1496
  const keys = AsyncResult.match(keysResult, {
1432
1497
  onInitial: () => [],
@@ -1440,7 +1505,7 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
1440
1505
  });
1441
1506
  const loading = keysResult._tag === "Initial";
1442
1507
  const [createForm] = useState(() => FormReact.make(apiKeyFormBuilder, {
1443
- fields: { name: TextField },
1508
+ fields: { name: TextField, referrers: TextAreaField },
1444
1509
  onSubmit: (_, { decoded: value }) => Effect.tryPromise({
1445
1510
  try: async () => {
1446
1511
  setCreatedKey(null);
@@ -1448,6 +1513,7 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
1448
1513
  configId: "organization",
1449
1514
  organizationId: organization.id,
1450
1515
  name: value.name.trim(),
1516
+ referrers: parseApiKeyReferrers(value.referrers, m.user_api_key_referrers_error()),
1451
1517
  }, m.user_api_key_create_error());
1452
1518
  setCreatedKey(created.key);
1453
1519
  refreshKeys();
@@ -1476,20 +1542,59 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
1476
1542
  }
1477
1543
  refreshKeys();
1478
1544
  };
1479
- return (_jsxs("div", { className: "flex flex-col gap-5", children: [_jsx(createForm.Initialize, { defaultValues: { name: "" }, children: _jsxs("form", { className: "flex max-w-xl flex-col gap-4", onSubmit: (event) => {
1480
- event.preventDefault();
1481
- event.stopPropagation();
1482
- submitApiKey();
1483
- }, children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.api_key_rate_limit_notice() }), _jsx(createForm.name, { label: m.user_api_key_name(), required: true }), _jsx(SubmitError, { result: createResult }), _jsx(SubmitButton, { form: createForm })] }) }), createdKey ? (_jsxs("div", { className: "flex flex-col gap-2 rounded-lg border p-4", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium", children: [_jsx(KeyRound, {}), m.user_api_key_created_title()] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_api_key_created_description() }), _jsx("code", { className: "bg-muted overflow-x-auto rounded-md p-3 text-sm", children: createdKey })] })) : null, keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsx(Separator, {}), _jsx(DataTable, { columns: apiKeyColumns({ m }), data: keys, features: {
1484
- export: { baseName: `${organization.slug}-api-keys` },
1485
- gallery: false,
1486
- rowActions: {
1487
- items: apiKeyRowActions({ m, onDelete: deleteKey }),
1488
- },
1489
- }, searchState: "local", state: {
1490
- empty: loading ? m.user_loading() : m.table_empty(),
1491
- loading,
1492
- } })] }));
1545
+ return (_jsxs(_Fragment, { children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: editingKey
1546
+ ? m.user_api_key_edit_title()
1547
+ : createdKey
1548
+ ? m.user_api_key_created_title()
1549
+ : creating
1550
+ ? m.user_api_key_create_title()
1551
+ : m.user_api_keys_title() }), _jsx(DialogDescription, { children: editingKey
1552
+ ? m.user_api_key_edit_description()
1553
+ : createdKey
1554
+ ? m.user_api_key_created_description()
1555
+ : creating
1556
+ ? m.user_api_key_create_description()
1557
+ : m.user_api_keys_organization_description({
1558
+ name: organization.name,
1559
+ }) }), creating || editingKey ? (_jsxs(Button, { className: "mt-2 w-fit", onClick: () => {
1560
+ setCreating(false);
1561
+ setCreatedKey(null);
1562
+ setEditingKey(null);
1563
+ }, type: "button", variant: "secondary", children: [_jsx(ArrowLeft, {}), m.user_api_key_back()] })) : (_jsxs(Button, { className: "mt-2 w-fit", onClick: () => {
1564
+ setCreatedKey(null);
1565
+ setCreating(true);
1566
+ }, type: "button", children: [_jsx(Plus, {}), m.user_api_key_create_title()] }))] }), _jsx(Separator, {}), _jsxs("div", { className: "flex min-w-0 flex-col gap-5", children: [creating && !createdKey ? (_jsx("section", { className: "w-full", children: _jsx(createForm.Initialize, { defaultValues: { name: "", referrers: "" }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
1567
+ event.preventDefault();
1568
+ event.stopPropagation();
1569
+ submitApiKey();
1570
+ }, children: [_jsx(createForm.name, { label: m.user_api_key_name(), required: true }), _jsx(createForm.referrers, { label: m.user_api_key_referrers(), description: m.user_api_key_referrers_description(), placeholder: m.user_api_key_referrers_placeholder(), rows: 3 }), _jsx(SubmitError, { result: createResult }), _jsx(SubmitButton, { form: createForm })] }) }) })) : null, creating && createdKey ? (_jsx("div", { className: "flex min-w-0 flex-col gap-3", children: _jsxs("div", { className: "bg-muted/50 flex min-w-0 items-center justify-between gap-3 rounded-md border px-3 py-2", children: [_jsx("code", { className: "block min-w-0 flex-1 overflow-x-auto text-sm whitespace-nowrap", children: createdKey }), _jsx(CopyButton, { className: "shrink-0", messages: {
1571
+ copied: m.user_api_key_copied(),
1572
+ copy: m.user_api_key_copy(),
1573
+ }, value: createdKey, variant: "ghost" })] }) })) : null, !creating && !editingKey && keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, !creating && !editingKey && error ? (_jsx("p", { className: "text-destructive text-sm", children: error })) : null, !creating && !editingKey ? (_jsx("div", { className: "max-w-full min-w-0 overflow-x-hidden", children: _jsx(DataTable, { columns: apiKeyColumns({ m }), data: keys, features: {
1574
+ export: { baseName: `${organization.slug}-api-keys` },
1575
+ gallery: false,
1576
+ rowActions: {
1577
+ items: apiKeyRowActions({
1578
+ m,
1579
+ onDelete: deleteKey,
1580
+ onEdit: (key) => setEditingKey(key),
1581
+ }),
1582
+ },
1583
+ }, searchState: "local", state: {
1584
+ empty: loading ? m.user_loading() : m.table_empty(),
1585
+ loading,
1586
+ } }) })) : null, editingKey ? (_jsx(ApiKeyEditForm, { authClient: authClient, configId: "organization", keyData: editingKey, messages: {
1587
+ enabled: m.user_api_key_enabled(),
1588
+ name: m.user_api_key_name(),
1589
+ referrers: m.user_api_key_referrers(),
1590
+ referrersDescription: m.user_api_key_referrers_description(),
1591
+ referrersError: m.user_api_key_referrers_error(),
1592
+ referrersPlaceholder: m.user_api_key_referrers_placeholder(),
1593
+ updateError: m.user_api_key_update_error(),
1594
+ }, onSaved: () => {
1595
+ refreshKeys();
1596
+ setEditingKey(null);
1597
+ } }, editingKey.id)) : null] })] }));
1493
1598
  }
1494
1599
  const apiKeyColumns = ({ m, }) => [
1495
1600
  {
@@ -1506,8 +1611,34 @@ const apiKeyColumns = ({ m, }) => [
1506
1611
  ? m.user_api_key_enabled()
1507
1612
  : m.user_api_key_disabled() })),
1508
1613
  },
1614
+ {
1615
+ id: "referrers",
1616
+ accessorFn: (keyData) => keyData.metadata,
1617
+ header: m.user_api_key_referrers_column(),
1618
+ cell: ({ row }) => (_jsx(ApiKeyReferrers, { metadata: row.original.metadata, unrestrictedLabel: m.user_api_key_referrers_any() })),
1619
+ },
1620
+ {
1621
+ id: "rateLimit",
1622
+ accessorFn: apiKeyUsagePercent,
1623
+ header: m.user_api_key_rate_limit(),
1624
+ cell: ({ row }) => (_jsx(ApiKeyRateLimit, { keyData: row.original, messages: {
1625
+ disabled: m.user_api_key_disabled(),
1626
+ none: m.user_api_key_window_none(),
1627
+ unlimited: m.user_api_key_unlimited(),
1628
+ usage: m.user_api_key_usage(),
1629
+ windowDays: (count) => m.user_api_key_window_days({ count }),
1630
+ windowHours: (count) => m.user_api_key_window_hours({ count }),
1631
+ windowMinutes: (count) => m.user_api_key_window_minutes({ count }),
1632
+ windowSeconds: (count) => m.user_api_key_window_seconds({ count }),
1633
+ } })),
1634
+ },
1509
1635
  ];
1510
- const apiKeyRowActions = ({ m, onDelete, }) => [
1636
+ const apiKeyRowActions = ({ m, onDelete, onEdit, }) => [
1637
+ {
1638
+ name: m.user_api_key_edit_title(),
1639
+ icon: _jsx(PencilIcon, {}),
1640
+ onClick: onEdit,
1641
+ },
1511
1642
  {
1512
1643
  name: m.user_delete(),
1513
1644
  icon: _jsx(Trash2, {}),
@@ -3,7 +3,6 @@ import { DropdownMenuContent } from "@/components/ui/dropdown-menu";
3
3
  import type { AuthUiClient } from "./auth-client";
4
4
  declare const messages: {
5
5
  readonly en: {
6
- readonly api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.";
7
6
  readonly table_empty: "No results.";
8
7
  readonly user_account_cancel: "Cancel";
9
8
  readonly user_account_confirm_revoke: "Revoke account";
@@ -35,18 +34,38 @@ declare const messages: {
35
34
  readonly user_accounts_title: "Accounts";
36
35
  readonly user_api_key_copied: "Copied";
37
36
  readonly user_api_key_copy: "Copy";
37
+ readonly user_api_key_back: "Back";
38
+ readonly user_api_key_create_description: "Configure a new API key for your user account.";
38
39
  readonly user_api_key_create_error: "Could not create the API key.";
40
+ readonly user_api_key_create_title: "Create API key";
39
41
  readonly user_api_key_created_description: "Copy this key now. You will not be able to see it again.";
40
42
  readonly user_api_key_created_title: "API key created";
41
43
  readonly user_api_key_delete_error: "Could not delete the API key.";
42
44
  readonly user_api_key_disabled: "Disabled";
45
+ readonly user_api_key_edit_description: "Update the key name, status, and allowed referrers.";
46
+ readonly user_api_key_edit_title: "Edit API key";
43
47
  readonly user_api_key_enabled: "Enabled";
44
48
  readonly user_api_key_hidden: "Secret hidden";
45
49
  readonly user_api_key_name: "Key name";
46
50
  readonly user_api_key_no_permissions: "No permissions";
47
51
  readonly user_api_key_permissions: "Permissions";
48
52
  readonly user_api_key_permissions_description: "Choose the permissions this API key should receive.";
53
+ readonly user_api_key_rate_limit: "Rate limit";
54
+ readonly user_api_key_referrers: "Allowed referrers (optional)";
55
+ readonly user_api_key_referrers_any: "Any referrer";
56
+ readonly user_api_key_referrers_column: "Referrers";
57
+ readonly user_api_key_referrers_description: "Enter any number of URLs, separated by commas or new lines. Leave empty to allow any referrer.";
58
+ readonly user_api_key_referrers_error: "{referrer} is not a valid HTTP(S) URL.";
59
+ readonly user_api_key_referrers_placeholder: "https://app.example.com\nhttps://admin.example.com";
49
60
  readonly user_api_key_status: "Status";
61
+ readonly user_api_key_unlimited: "Unlimited";
62
+ readonly user_api_key_update_error: "Could not update the API key.";
63
+ readonly user_api_key_usage: "API key usage";
64
+ readonly user_api_key_window_days: "{count}d";
65
+ readonly user_api_key_window_hours: "{count}h";
66
+ readonly user_api_key_window_minutes: "{count}m";
67
+ readonly user_api_key_window_none: "None";
68
+ readonly user_api_key_window_seconds: "{count}s";
50
69
  readonly user_api_keys_description: "Create and manage API keys for your user account.";
51
70
  readonly user_api_keys_export_file_name: "api-keys.csv";
52
71
  readonly user_api_keys_load_error: "Could not load API keys.";
@@ -91,7 +110,6 @@ declare const messages: {
91
110
  readonly user_two_factor_verify_error: "Could not verify the code.";
92
111
  };
93
112
  readonly fr: {
94
- readonly api_key_rate_limit_notice: "Les clés API sont soumises aux mêmes limites de débit que votre compte.";
95
113
  readonly table_empty: "Aucun résultat.";
96
114
  readonly user_account_cancel: "Annuler";
97
115
  readonly user_account_confirm_revoke: "Révoquer le compte";
@@ -123,18 +141,38 @@ declare const messages: {
123
141
  readonly user_accounts_title: "Comptes";
124
142
  readonly user_api_key_copied: "Copié";
125
143
  readonly user_api_key_copy: "Copier";
144
+ readonly user_api_key_back: "Retour";
145
+ readonly user_api_key_create_description: "Configurez une nouvelle clé API pour votre compte utilisateur.";
126
146
  readonly user_api_key_create_error: "Impossible de créer la clé API.";
147
+ readonly user_api_key_create_title: "Créer une clé API";
127
148
  readonly user_api_key_created_description: "Copiez cette clé maintenant. Vous ne pourrez plus la voir.";
128
149
  readonly user_api_key_created_title: "Clé API créée";
129
150
  readonly user_api_key_delete_error: "Impossible de supprimer la clé API.";
130
151
  readonly user_api_key_disabled: "Désactivée";
152
+ readonly user_api_key_edit_description: "Mettez à jour le nom, le statut et les référents autorisés de la clé.";
153
+ readonly user_api_key_edit_title: "Modifier la clé API";
131
154
  readonly user_api_key_enabled: "Activée";
132
155
  readonly user_api_key_hidden: "Secret masqué";
133
156
  readonly user_api_key_name: "Nom de la clé";
134
157
  readonly user_api_key_no_permissions: "Aucune autorisation";
135
158
  readonly user_api_key_permissions: "Autorisations";
136
159
  readonly user_api_key_permissions_description: "Choisissez les autorisations que cette clé API doit recevoir.";
160
+ readonly user_api_key_rate_limit: "Limite de débit";
161
+ readonly user_api_key_referrers: "Référents autorisés (facultatifs)";
162
+ readonly user_api_key_referrers_any: "Tout référent";
163
+ readonly user_api_key_referrers_column: "Référents";
164
+ readonly user_api_key_referrers_description: "Saisissez autant d'URL que nécessaire, séparées par des virgules ou des sauts de ligne. Laissez vide pour autoriser tout référent.";
165
+ readonly user_api_key_referrers_error: "{referrer} n'est pas une URL HTTP(S) valide.";
166
+ readonly user_api_key_referrers_placeholder: "https://app.example.com\nhttps://admin.example.com";
137
167
  readonly user_api_key_status: "Statut";
168
+ readonly user_api_key_unlimited: "Illimitée";
169
+ readonly user_api_key_update_error: "Impossible de mettre à jour la clé API.";
170
+ readonly user_api_key_usage: "Utilisation de la clé API";
171
+ readonly user_api_key_window_days: "{count} j";
172
+ readonly user_api_key_window_hours: "{count} h";
173
+ readonly user_api_key_window_minutes: "{count} min";
174
+ readonly user_api_key_window_none: "Aucune";
175
+ readonly user_api_key_window_seconds: "{count} s";
138
176
  readonly user_api_keys_description: "Créez et gérez des clés API pour votre compte utilisateur.";
139
177
  readonly user_api_keys_export_file_name: "cles-api.csv";
140
178
  readonly user_api_keys_load_error: "Impossible de charger les clés API.";