@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.
- package/dist/admin/api.group.d.ts +7 -0
- package/dist/admin/api.group.js +1 -1
- package/dist/admin/schema.d.ts +2 -0
- package/dist/admin/schema.js +4 -0
- package/dist/api.d.ts +9 -0
- package/dist/components/admin-organizations.js +2 -1
- package/dist/components/admin-users.js +2 -1
- package/dist/components/api-key-edit-form.d.ts +20 -0
- package/dist/components/api-key-edit-form.js +50 -0
- package/dist/components/api-key-rate-limit.d.ts +18 -0
- package/dist/components/api-key-rate-limit.js +29 -0
- package/dist/components/api-key-referrers.d.ts +8 -0
- package/dist/components/api-key-referrers.js +24 -0
- package/dist/components/api-key.d.ts +1 -0
- package/dist/components/api-key.js +20 -1
- package/dist/components/auth-client-api.d.ts +8 -0
- package/dist/components/organization-switcher.d.ts +50 -2
- package/dist/components/organization-switcher.js +199 -68
- package/dist/components/user-button.d.ts +40 -2
- package/dist/components/user-button.js +134 -33
- package/dist/extra/api.group.d.ts +1 -0
- package/dist/extra/schema.d.ts +1 -0
- package/dist/extra/schema.js +2 -0
- package/dist/service.d.ts +2 -0
- package/package.json +1 -1
|
@@ -5,22 +5,26 @@ import {} from "@tanstack/react-table";
|
|
|
5
5
|
import { useNavigate, useRouterState, } from "@tanstack/react-router";
|
|
6
6
|
import { Effect, Schema } from "effect";
|
|
7
7
|
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
8
|
-
import {
|
|
8
|
+
import { ArrowLeft, Building2, KeyRound, Loader2, LogOutIcon, Pencil, Plus, ShieldCheck, StopCircle, Trash2, UserCircleIcon, Users, UserIcon, } from "lucide-react";
|
|
9
9
|
import { QRCode } from "react-qr-code";
|
|
10
10
|
import { createContext, useContext, useRef, useState, } from "react";
|
|
11
11
|
import { DataTable } from "@/components/ui/data-table";
|
|
12
12
|
import { AppBrand } from "@/components/ui/app-brand";
|
|
13
|
-
import { effectFormMessages, ImageField, SubmitButton, SubmitError, TextField, } from "@/components/ui/effect-form";
|
|
13
|
+
import { effectFormMessages, ImageField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@/components/ui/effect-form";
|
|
14
14
|
import { Badge } from "@/components/ui/badge";
|
|
15
15
|
import { Button } from "@/components/ui/button";
|
|
16
16
|
import { Checkbox } from "@/components/ui/checkbox";
|
|
17
|
+
import { CopyButton } from "@/components/ui/copy-button";
|
|
17
18
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
|
18
19
|
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLegend, FieldSet, } from "@/components/ui/field";
|
|
19
20
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
20
21
|
import { Separator } from "@/components/ui/separator";
|
|
21
22
|
import { authClientApi } from "./auth-client-api";
|
|
22
23
|
import { useKrakstackAuth } from "./auth-provider";
|
|
23
|
-
import { createApiKey } from "./api-key";
|
|
24
|
+
import { createApiKey, parseApiKeyReferrers } from "./api-key";
|
|
25
|
+
import { ApiKeyEditForm } from "./api-key-edit-form";
|
|
26
|
+
import { ApiKeyRateLimit, apiKeyUsagePercent } from "./api-key-rate-limit";
|
|
27
|
+
import { ApiKeyReferrers } from "./api-key-referrers";
|
|
24
28
|
import { useOpenedOnce } from "./hooks";
|
|
25
29
|
import { ExtraUploadedAsset } from "../extra/schema";
|
|
26
30
|
import { assetPath, assetUrl } from "./utils";
|
|
@@ -28,7 +32,6 @@ import { AdminOrganizationsTable } from "./admin-organizations";
|
|
|
28
32
|
import { AdminUsersTable } from "./admin-users";
|
|
29
33
|
const messages = {
|
|
30
34
|
en: {
|
|
31
|
-
api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
|
|
32
35
|
table_empty: "No results.",
|
|
33
36
|
user_account_cancel: "Cancel",
|
|
34
37
|
user_account_confirm_revoke: "Revoke account",
|
|
@@ -60,18 +63,38 @@ const messages = {
|
|
|
60
63
|
user_accounts_title: "Accounts",
|
|
61
64
|
user_api_key_copied: "Copied",
|
|
62
65
|
user_api_key_copy: "Copy",
|
|
66
|
+
user_api_key_back: "Back",
|
|
67
|
+
user_api_key_create_description: "Configure a new API key for your user account.",
|
|
63
68
|
user_api_key_create_error: "Could not create the API key.",
|
|
69
|
+
user_api_key_create_title: "Create API key",
|
|
64
70
|
user_api_key_created_description: "Copy this key now. You will not be able to see it again.",
|
|
65
71
|
user_api_key_created_title: "API key created",
|
|
66
72
|
user_api_key_delete_error: "Could not delete the API key.",
|
|
67
73
|
user_api_key_disabled: "Disabled",
|
|
74
|
+
user_api_key_edit_description: "Update the key name, status, and allowed referrers.",
|
|
75
|
+
user_api_key_edit_title: "Edit API key",
|
|
68
76
|
user_api_key_enabled: "Enabled",
|
|
69
77
|
user_api_key_hidden: "Secret hidden",
|
|
70
78
|
user_api_key_name: "Key name",
|
|
71
79
|
user_api_key_no_permissions: "No permissions",
|
|
72
80
|
user_api_key_permissions: "Permissions",
|
|
73
81
|
user_api_key_permissions_description: "Choose the permissions this API key should receive.",
|
|
82
|
+
user_api_key_rate_limit: "Rate limit",
|
|
83
|
+
user_api_key_referrers: "Allowed referrers (optional)",
|
|
84
|
+
user_api_key_referrers_any: "Any referrer",
|
|
85
|
+
user_api_key_referrers_column: "Referrers",
|
|
86
|
+
user_api_key_referrers_description: "Enter any number of URLs, separated by commas or new lines. Leave empty to allow any referrer.",
|
|
87
|
+
user_api_key_referrers_error: "{referrer} is not a valid HTTP(S) URL.",
|
|
88
|
+
user_api_key_referrers_placeholder: "https://app.example.com\nhttps://admin.example.com",
|
|
74
89
|
user_api_key_status: "Status",
|
|
90
|
+
user_api_key_unlimited: "Unlimited",
|
|
91
|
+
user_api_key_update_error: "Could not update the API key.",
|
|
92
|
+
user_api_key_usage: "API key usage",
|
|
93
|
+
user_api_key_window_days: "{count}d",
|
|
94
|
+
user_api_key_window_hours: "{count}h",
|
|
95
|
+
user_api_key_window_minutes: "{count}m",
|
|
96
|
+
user_api_key_window_none: "None",
|
|
97
|
+
user_api_key_window_seconds: "{count}s",
|
|
75
98
|
user_api_keys_description: "Create and manage API keys for your user account.",
|
|
76
99
|
user_api_keys_export_file_name: "api-keys.csv",
|
|
77
100
|
user_api_keys_load_error: "Could not load API keys.",
|
|
@@ -116,7 +139,6 @@ const messages = {
|
|
|
116
139
|
user_two_factor_verify_error: "Could not verify the code.",
|
|
117
140
|
},
|
|
118
141
|
fr: {
|
|
119
|
-
api_key_rate_limit_notice: "Les clés API sont soumises aux mêmes limites de débit que votre compte.",
|
|
120
142
|
table_empty: "Aucun résultat.",
|
|
121
143
|
user_account_cancel: "Annuler",
|
|
122
144
|
user_account_confirm_revoke: "Révoquer le compte",
|
|
@@ -148,18 +170,38 @@ const messages = {
|
|
|
148
170
|
user_accounts_title: "Comptes",
|
|
149
171
|
user_api_key_copied: "Copié",
|
|
150
172
|
user_api_key_copy: "Copier",
|
|
173
|
+
user_api_key_back: "Retour",
|
|
174
|
+
user_api_key_create_description: "Configurez une nouvelle clé API pour votre compte utilisateur.",
|
|
151
175
|
user_api_key_create_error: "Impossible de créer la clé API.",
|
|
176
|
+
user_api_key_create_title: "Créer une clé API",
|
|
152
177
|
user_api_key_created_description: "Copiez cette clé maintenant. Vous ne pourrez plus la voir.",
|
|
153
178
|
user_api_key_created_title: "Clé API créée",
|
|
154
179
|
user_api_key_delete_error: "Impossible de supprimer la clé API.",
|
|
155
180
|
user_api_key_disabled: "Désactivée",
|
|
181
|
+
user_api_key_edit_description: "Mettez à jour le nom, le statut et les référents autorisés de la clé.",
|
|
182
|
+
user_api_key_edit_title: "Modifier la clé API",
|
|
156
183
|
user_api_key_enabled: "Activée",
|
|
157
184
|
user_api_key_hidden: "Secret masqué",
|
|
158
185
|
user_api_key_name: "Nom de la clé",
|
|
159
186
|
user_api_key_no_permissions: "Aucune autorisation",
|
|
160
187
|
user_api_key_permissions: "Autorisations",
|
|
161
188
|
user_api_key_permissions_description: "Choisissez les autorisations que cette clé API doit recevoir.",
|
|
189
|
+
user_api_key_rate_limit: "Limite de débit",
|
|
190
|
+
user_api_key_referrers: "Référents autorisés (facultatifs)",
|
|
191
|
+
user_api_key_referrers_any: "Tout référent",
|
|
192
|
+
user_api_key_referrers_column: "Référents",
|
|
193
|
+
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.",
|
|
194
|
+
user_api_key_referrers_error: "{referrer} n'est pas une URL HTTP(S) valide.",
|
|
195
|
+
user_api_key_referrers_placeholder: "https://app.example.com\nhttps://admin.example.com",
|
|
162
196
|
user_api_key_status: "Statut",
|
|
197
|
+
user_api_key_unlimited: "Illimitée",
|
|
198
|
+
user_api_key_update_error: "Impossible de mettre à jour la clé API.",
|
|
199
|
+
user_api_key_usage: "Utilisation de la clé API",
|
|
200
|
+
user_api_key_window_days: "{count} j",
|
|
201
|
+
user_api_key_window_hours: "{count} h",
|
|
202
|
+
user_api_key_window_minutes: "{count} min",
|
|
203
|
+
user_api_key_window_none: "Aucune",
|
|
204
|
+
user_api_key_window_seconds: "{count} s",
|
|
163
205
|
user_api_keys_description: "Créez et gérez des clés API pour votre compte utilisateur.",
|
|
164
206
|
user_api_keys_export_file_name: "cles-api.csv",
|
|
165
207
|
user_api_keys_load_error: "Impossible de charger les clés API.",
|
|
@@ -237,7 +279,9 @@ const userFormBuilder = FormBuilder.empty
|
|
|
237
279
|
.addField("name", Schema.NonEmptyString)
|
|
238
280
|
.addField("image", Schema.UndefinedOr(Schema.NullOr(Schema.Union([Schema.String, Schema.instanceOf(File)]))));
|
|
239
281
|
const totpCodeFormBuilder = FormBuilder.empty.addField("code", Schema.NonEmptyString);
|
|
240
|
-
const apiKeyFormBuilder = FormBuilder.empty
|
|
282
|
+
const apiKeyFormBuilder = FormBuilder.empty
|
|
283
|
+
.addField("name", Schema.NonEmptyString)
|
|
284
|
+
.addField("referrers", Schema.String);
|
|
241
285
|
const isFile = (value) => value instanceof File;
|
|
242
286
|
const decodeUploadedAsset = Schema.decodeUnknownPromise(ExtraUploadedAsset);
|
|
243
287
|
const uploadUserImageAsset = async (file, m, uploadUserImage) => {
|
|
@@ -374,7 +418,7 @@ export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRed
|
|
|
374
418
|
};
|
|
375
419
|
return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", children: [displayImage ? (_jsx("img", { src: displayImage, alt: displayName || displayEmail, className: "size-full rounded-md object-cover" })) : (_jsx(UserIcon, { className: "size-4.5" })), _jsx("span", { className: "sr-only", children: m.user_button_aria_label() })] }) }), _jsx(DropdownMenuContent, { className: "w-56 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [isImpersonating ? (_jsx("div", { className: "px-1 py-0.5", children: _jsx(Badge, { variant: "secondary", className: "text-xs font-normal", children: m.user_button_impersonating() }) })) : null, _jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: displayName || displayEmail, subtitle: displayName ? displayEmail : m.user_button_account(), icon: UserIcon, className: "px-1 py-1.5 text-left text-sm", ...(displayImage ? { imageSrc: displayImage } : {}) }) }), _jsx(DropdownMenuSeparator, {}), canManageUserSettings ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { disabled: isPending, onClick: () => setSettingsDialog("account"), children: [_jsx(UserCircleIcon, {}), m.user_button_account()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("security"), children: [_jsx(ShieldCheck, {}), m.user_button_security()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] }), _jsx(DropdownMenuSeparator, {})] })) : null, (isAdmin && canUseAdminSettings) || isImpersonating ? (_jsxs(_Fragment, { children: [isAdmin && canUseAdminSettings ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminUsers"), children: [_jsx(Users, {}), m.user_button_admin_users()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminOrganizations"), children: [_jsx(Building2, {}), m.user_button_admin_organizations()] })] })) : null, isImpersonating ? (_jsxs(DropdownMenuItem, { disabled: isStoppingImpersonation, onClick: stopImpersonating, children: [_jsx(StopCircle, {}), m.user_button_stop_impersonating()] })) : null, _jsx(DropdownMenuSeparator, {})] })) : null, _jsxs(DropdownMenuItem, { onClick: signOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] })] }) })] })), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "account", onOpenChange: (open) => {
|
|
376
420
|
setSettingsDialog((current) => open ? "account" : current === "account" ? null : current);
|
|
377
|
-
}, 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_form_title() }), _jsx(DialogDescription, { children: m.user_form_description() })] }), _jsx(Separator, {}), isPending ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : (_jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(UserForm, { defaultValues: {
|
|
421
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_form_title() }), _jsx(DialogDescription, { children: m.user_form_description() })] }), _jsx(Separator, {}), isPending ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : (_jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(UserForm, { defaultValues: {
|
|
378
422
|
name: displayName ?? "",
|
|
379
423
|
image: displayImage || null,
|
|
380
424
|
}, error: formError, onSubmit: async (data) => {
|
|
@@ -390,7 +434,7 @@ export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRed
|
|
|
390
434
|
setSettingsDialog((current) => open ? "security" : current === "security" ? null : current);
|
|
391
435
|
}, 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_security_title() }), _jsx(DialogDescription, { children: m.user_security_description() })] }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(PasswordSettings, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache }), _jsx(Separator, {}), _jsx(AccountSecuritySettings, { authClient: authClient, accountCache: accountCache })] })] }) }), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "apiKeys", onOpenChange: (open) => {
|
|
392
436
|
setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
393
|
-
}, children:
|
|
437
|
+
}, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: _jsx(ApiKeyManager, { authClient: authClient, active: settingsDialog === "apiKeys", permissions: apiKeyPermissions ?? {} }) }) }), isAdmin ? (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: settingsDialog === "adminUsers", onOpenChange: (open) => {
|
|
394
438
|
setSettingsDialog((current) => open ? "adminUsers" : current === "adminUsers" ? null : current);
|
|
395
439
|
}, children: _jsxs(DialogContent, { className: "flex h-[85vh] flex-col overflow-y-auto sm:max-w-6xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_button_admin_users() }), _jsx(DialogDescription, { children: m.user_button_admin_users_description() })] }), _jsx(Separator, {}), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(AdminUsersTable, {}) })] }) }), _jsx(Dialog, { open: settingsDialog === "adminOrganizations", onOpenChange: (open) => {
|
|
396
440
|
setSettingsDialog((current) => open
|
|
@@ -716,7 +760,8 @@ function ApiKeyManager({ authClient, active, permissions = {}, }) {
|
|
|
716
760
|
const keysResult = useAtomValue(keysAtom);
|
|
717
761
|
const refreshKeys = useAtomRefresh(keysAtom);
|
|
718
762
|
const [createdKey, setCreatedKey] = useState(null);
|
|
719
|
-
const [
|
|
763
|
+
const [creating, setCreating] = useState(false);
|
|
764
|
+
const [editingKey, setEditingKey] = useState(null);
|
|
720
765
|
const [error, setError] = useState(null);
|
|
721
766
|
const permissionOptions = getPermissionOptions(permissions);
|
|
722
767
|
const [selectedPermissions, setSelectedPermissions] = useState({});
|
|
@@ -736,16 +781,16 @@ function ApiKeyManager({ authClient, active, permissions = {}, }) {
|
|
|
736
781
|
permissionOptionsRef.current = permissionOptions;
|
|
737
782
|
selectedPermissionsRef.current = selectedPermissions;
|
|
738
783
|
const [createForm] = useState(() => FormReact.make(apiKeyFormBuilder, {
|
|
739
|
-
fields: { name: TextField },
|
|
784
|
+
fields: { name: TextField, referrers: TextAreaField },
|
|
740
785
|
mode: { validation: "onSubmit" },
|
|
741
786
|
onSubmit: (_, { decoded }) => Effect.tryPromise({
|
|
742
787
|
try: async () => {
|
|
743
788
|
setCreatedKey(null);
|
|
744
|
-
setCopiedKey(false);
|
|
745
789
|
const created = await createApiKey({
|
|
746
790
|
configId: "user",
|
|
747
791
|
name: decoded.name.trim(),
|
|
748
792
|
permissions: getSelectedPermissionObject(permissionOptionsRef.current, selectedPermissionsRef.current),
|
|
793
|
+
referrers: parseApiKeyReferrers(decoded.referrers, m.user_api_key_referrers_error()),
|
|
749
794
|
}, m.user_api_key_create_error());
|
|
750
795
|
setCreatedKey(created.key);
|
|
751
796
|
resetCreateForm();
|
|
@@ -763,13 +808,6 @@ function ApiKeyManager({ authClient, active, permissions = {}, }) {
|
|
|
763
808
|
const togglePermission = (id, checked) => {
|
|
764
809
|
setSelectedPermissions((current) => ({ ...current, [id]: checked }));
|
|
765
810
|
};
|
|
766
|
-
const copyCreatedKey = async () => {
|
|
767
|
-
if (!createdKey)
|
|
768
|
-
return;
|
|
769
|
-
await navigator.clipboard.writeText(createdKey);
|
|
770
|
-
setCopiedKey(true);
|
|
771
|
-
window.setTimeout(() => setCopiedKey(false), 2000);
|
|
772
|
-
};
|
|
773
811
|
const deleteKey = async (key) => {
|
|
774
812
|
const result = await authClient.apiKey.delete({
|
|
775
813
|
configId: "user",
|
|
@@ -781,20 +819,57 @@ function ApiKeyManager({ authClient, active, permissions = {}, }) {
|
|
|
781
819
|
}
|
|
782
820
|
refreshKeys();
|
|
783
821
|
};
|
|
784
|
-
return (_jsxs(
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
822
|
+
return (_jsxs(_Fragment, { children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: editingKey
|
|
823
|
+
? m.user_api_key_edit_title()
|
|
824
|
+
: createdKey
|
|
825
|
+
? m.user_api_key_created_title()
|
|
826
|
+
: creating
|
|
827
|
+
? m.user_api_key_create_title()
|
|
828
|
+
: m.user_api_keys_title() }), _jsx(DialogDescription, { children: editingKey
|
|
829
|
+
? m.user_api_key_edit_description()
|
|
830
|
+
: createdKey
|
|
831
|
+
? m.user_api_key_created_description()
|
|
832
|
+
: creating
|
|
833
|
+
? m.user_api_key_create_description()
|
|
834
|
+
: m.user_api_keys_description() }), creating || editingKey ? (_jsxs(Button, { className: "mt-2 w-fit", onClick: () => {
|
|
835
|
+
setCreating(false);
|
|
836
|
+
setCreatedKey(null);
|
|
837
|
+
setEditingKey(null);
|
|
838
|
+
}, type: "button", variant: "secondary", children: [_jsx(ArrowLeft, {}), m.user_api_key_back()] })) : (_jsxs(Button, { className: "mt-2 w-fit", onClick: () => {
|
|
839
|
+
setCreatedKey(null);
|
|
840
|
+
setCreating(true);
|
|
841
|
+
}, 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) => {
|
|
842
|
+
event.preventDefault();
|
|
843
|
+
event.stopPropagation();
|
|
844
|
+
submitCreateForm();
|
|
845
|
+
}, 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 }), permissionOptions.length > 0 ? (_jsxs(FieldSet, { children: [_jsx(FieldLegend, { children: m.user_api_key_permissions() }), _jsx(FieldDescription, { children: m.user_api_key_permissions_description() }), _jsx(FieldGroup, { "data-slot": "checkbox-group", className: "gap-3", children: permissionOptions.map((permission) => (_jsxs(Field, { orientation: "horizontal", children: [_jsx(Checkbox, { id: permission.id, checked: selectedPermissions[permission.id] ?? false, onCheckedChange: (checked) => togglePermission(permission.id, checked) }), _jsx(FieldContent, { children: _jsx(FieldLabel, { htmlFor: permission.id, children: permission.id }) })] }, permission.id))) })] })) : null, _jsx(SubmitError, { result: createSubmitResult }), _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: {
|
|
846
|
+
copied: m.user_api_key_copied(),
|
|
847
|
+
copy: m.user_api_key_copy(),
|
|
848
|
+
}, 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: {
|
|
849
|
+
export: { baseName: m.user_api_keys_export_file_name() },
|
|
850
|
+
gallery: false,
|
|
851
|
+
rowActions: {
|
|
852
|
+
items: apiKeyRowActions({
|
|
853
|
+
m,
|
|
854
|
+
onDelete: deleteKey,
|
|
855
|
+
onEdit: (key) => setEditingKey(key),
|
|
856
|
+
}),
|
|
857
|
+
},
|
|
858
|
+
}, searchState: "local", state: {
|
|
859
|
+
empty: loading ? m.user_loading() : m.table_empty(),
|
|
860
|
+
loading,
|
|
861
|
+
} }) })) : null, editingKey ? (_jsx(ApiKeyEditForm, { authClient: authClient, configId: "user", keyData: editingKey, messages: {
|
|
862
|
+
enabled: m.user_api_key_enabled(),
|
|
863
|
+
name: m.user_api_key_name(),
|
|
864
|
+
referrers: m.user_api_key_referrers(),
|
|
865
|
+
referrersDescription: m.user_api_key_referrers_description(),
|
|
866
|
+
referrersError: m.user_api_key_referrers_error(),
|
|
867
|
+
referrersPlaceholder: m.user_api_key_referrers_placeholder(),
|
|
868
|
+
updateError: m.user_api_key_update_error(),
|
|
869
|
+
}, onSaved: () => {
|
|
870
|
+
refreshKeys();
|
|
871
|
+
setEditingKey(null);
|
|
872
|
+
} }, editingKey.id)) : null] })] }));
|
|
798
873
|
}
|
|
799
874
|
const apiKeyColumns = ({ m, }) => [
|
|
800
875
|
{
|
|
@@ -809,6 +884,27 @@ const apiKeyColumns = ({ m, }) => [
|
|
|
809
884
|
? m.user_api_key_enabled()
|
|
810
885
|
: m.user_api_key_disabled() })),
|
|
811
886
|
},
|
|
887
|
+
{
|
|
888
|
+
id: "referrers",
|
|
889
|
+
accessorFn: (keyData) => keyData.metadata,
|
|
890
|
+
header: m.user_api_key_referrers_column(),
|
|
891
|
+
cell: ({ row }) => (_jsx(ApiKeyReferrers, { metadata: row.original.metadata, unrestrictedLabel: m.user_api_key_referrers_any() })),
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
id: "rateLimit",
|
|
895
|
+
accessorFn: apiKeyUsagePercent,
|
|
896
|
+
header: m.user_api_key_rate_limit(),
|
|
897
|
+
cell: ({ row }) => (_jsx(ApiKeyRateLimit, { keyData: row.original, messages: {
|
|
898
|
+
disabled: m.user_api_key_disabled(),
|
|
899
|
+
none: m.user_api_key_window_none(),
|
|
900
|
+
unlimited: m.user_api_key_unlimited(),
|
|
901
|
+
usage: m.user_api_key_usage(),
|
|
902
|
+
windowDays: (count) => m.user_api_key_window_days({ count }),
|
|
903
|
+
windowHours: (count) => m.user_api_key_window_hours({ count }),
|
|
904
|
+
windowMinutes: (count) => m.user_api_key_window_minutes({ count }),
|
|
905
|
+
windowSeconds: (count) => m.user_api_key_window_seconds({ count }),
|
|
906
|
+
} })),
|
|
907
|
+
},
|
|
812
908
|
{
|
|
813
909
|
accessorKey: "permissions",
|
|
814
910
|
header: m.user_api_key_permissions(),
|
|
@@ -821,7 +917,12 @@ const apiKeyColumns = ({ m, }) => [
|
|
|
821
917
|
},
|
|
822
918
|
},
|
|
823
919
|
];
|
|
824
|
-
const apiKeyRowActions = ({ m, onDelete, }) => [
|
|
920
|
+
const apiKeyRowActions = ({ m, onDelete, onEdit, }) => [
|
|
921
|
+
{
|
|
922
|
+
name: m.user_api_key_edit_title(),
|
|
923
|
+
icon: _jsx(Pencil, {}),
|
|
924
|
+
onClick: onEdit,
|
|
925
|
+
},
|
|
825
926
|
{
|
|
826
927
|
name: m.user_delete(),
|
|
827
928
|
icon: _jsx(Trash2, {}),
|
|
@@ -7,6 +7,7 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
|
|
|
7
7
|
readonly name: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
|
|
8
8
|
readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
9
9
|
readonly permissions: import("effect/Schema").optional<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>;
|
|
10
|
+
readonly referrers: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").String>>;
|
|
10
11
|
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
|
|
11
12
|
readonly id: import("effect/Schema").String;
|
|
12
13
|
readonly key: import("effect/Schema").String;
|
package/dist/extra/schema.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare const ExtraCreateApiKeyPayload: Schema.Struct<{
|
|
|
20
20
|
readonly name: Schema.optional<Schema.NonEmptyString>;
|
|
21
21
|
readonly organizationId: Schema.optional<Schema.String>;
|
|
22
22
|
readonly permissions: Schema.optional<Schema.$Record<Schema.String, Schema.$Array<Schema.String>>>;
|
|
23
|
+
readonly referrers: Schema.optional<Schema.$Array<Schema.String>>;
|
|
23
24
|
}>;
|
|
24
25
|
export declare const ExtraCreateApiKeyResponse: Schema.Struct<{
|
|
25
26
|
readonly id: Schema.String;
|
package/dist/extra/schema.js
CHANGED
|
@@ -47,6 +47,7 @@ export const ExtraCreateApiKeyPayload = Schema.Struct({
|
|
|
47
47
|
name: Schema.optional(Schema.NonEmptyString),
|
|
48
48
|
organizationId: Schema.optional(Schema.String),
|
|
49
49
|
permissions: Schema.optional(ExtraApiKeyPermissions),
|
|
50
|
+
referrers: Schema.optional(Schema.Array(Schema.String)),
|
|
50
51
|
}).annotate({
|
|
51
52
|
identifier: "ExtraCreateApiKeyPayload",
|
|
52
53
|
title: "Extra create API key payload",
|
|
@@ -56,6 +57,7 @@ export const ExtraCreateApiKeyPayload = Schema.Struct({
|
|
|
56
57
|
configId: "user",
|
|
57
58
|
name: "Production key",
|
|
58
59
|
permissions: { projects: ["read"] },
|
|
60
|
+
referrers: ["https://app.example.com"],
|
|
59
61
|
},
|
|
60
62
|
],
|
|
61
63
|
});
|
package/dist/service.d.ts
CHANGED
|
@@ -111,6 +111,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
111
111
|
readonly permissions?: {
|
|
112
112
|
readonly [x: string]: readonly string[];
|
|
113
113
|
} | undefined;
|
|
114
|
+
readonly referrers?: readonly string[] | undefined;
|
|
114
115
|
};
|
|
115
116
|
readonly responseMode?: Mode;
|
|
116
117
|
}) => Effect.Effect<HttpApiClient.Client.Response<import("effect/Schema").Struct.ReadonlySide<{
|
|
@@ -728,6 +729,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
728
729
|
readonly permissions?: {
|
|
729
730
|
readonly [x: string]: readonly string[];
|
|
730
731
|
} | undefined;
|
|
732
|
+
readonly referrers?: readonly string[] | undefined;
|
|
731
733
|
};
|
|
732
734
|
readonly responseMode?: Mode;
|
|
733
735
|
}) => Effect.Effect<HttpApiClient.Client.Response<import("effect/Schema").Struct.ReadonlySide<{
|