@krak-stack/auth 0.1.43 → 0.1.45
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/README.md +10 -2
- package/dist/admin/api.group.d.ts +17 -12
- package/dist/admin/schema.d.ts +16 -12
- package/dist/admin/schema.js +4 -0
- package/dist/api.d.ts +316 -222
- package/dist/api.js +1 -1
- package/dist/better-auth/api.group.d.ts +33 -1
- package/dist/better-auth/api.group.js +15 -1
- package/dist/better-auth/schema.d.ts +36 -0
- package/dist/better-auth/schema.js +56 -0
- package/dist/components/admin-organizations.d.ts +1 -1
- package/dist/components/admin-organizations.js +17 -12
- package/dist/components/admin-users.d.ts +1 -1
- package/dist/components/admin-users.js +81 -6
- package/dist/components/auth-client-api.d.ts +139 -77
- package/dist/components/auth-client.js +3 -1
- package/dist/components/auth-provider.d.ts +17 -15
- package/dist/components/auth-provider.js +16 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/organization-switcher.d.ts +5 -2
- package/dist/components/organization-switcher.js +96 -45
- package/dist/components/user-button.js +8 -17
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/roles.d.ts +10 -0
- package/dist/roles.js +31 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.js +2 -0
- package/dist/service.d.ts +500 -424
- package/package.json +5 -1
|
@@ -5,8 +5,8 @@ import {} from "@tanstack/react-table";
|
|
|
5
5
|
import { Effect, Schema } from "effect";
|
|
6
6
|
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
7
7
|
import { Building2, Check, ChevronsUpDown, Copy, KeyRound, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
|
|
8
|
-
import { createContext, useContext, useEffect, useState, } from "react";
|
|
9
|
-
import { DataTable } from "@/components/ui/data-table";
|
|
8
|
+
import { createContext, useContext, useEffect, useEffectEvent, useRef, useState, } from "react";
|
|
9
|
+
import { DataTable, DataTableRelationshipCell, } from "@/components/ui/data-table";
|
|
10
10
|
import { EditingLocaleSwitcher } from "@/components/ui/editing-locale-switcher";
|
|
11
11
|
import { AppBrand } from "@/components/ui/app-brand";
|
|
12
12
|
import { useAppForm } from "@/components/ui/form";
|
|
@@ -14,11 +14,11 @@ import { Badge } from "@/components/ui/badge";
|
|
|
14
14
|
import { Button } from "@/components/ui/button";
|
|
15
15
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
|
16
16
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
17
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
|
|
18
17
|
import { Separator } from "@/components/ui/separator";
|
|
19
18
|
import { OrganizationMetadata, } from "@krak-stack/auth/schema";
|
|
19
|
+
import { hasAnyRole, isOrganizationRole, normalizeOrganizationRole, normalizeOrganizationRoles, organizationRoles, } from "../roles";
|
|
20
20
|
import { authClientApi } from "./auth-client-api";
|
|
21
|
-
import {
|
|
21
|
+
import { useKrakstackAuth } from "./auth-provider";
|
|
22
22
|
import { createApiKey } from "./api-key";
|
|
23
23
|
import { useOpenedOnce } from "./hooks";
|
|
24
24
|
import { ExtraUploadedAsset } from "../extra/schema";
|
|
@@ -75,6 +75,7 @@ const messages = {
|
|
|
75
75
|
organization_role_admin: "Admin",
|
|
76
76
|
organization_role_member: "Member",
|
|
77
77
|
organization_role_owner: "Owner",
|
|
78
|
+
organization_role_support: "Support",
|
|
78
79
|
organization_slug: "Organization slug",
|
|
79
80
|
organization_slug_description: "Leave blank to generate one from the name.",
|
|
80
81
|
organization_switcher_empty: "You do not belong to any organizations yet.",
|
|
@@ -154,6 +155,7 @@ const messages = {
|
|
|
154
155
|
organization_role_admin: "Admin",
|
|
155
156
|
organization_role_member: "Membre",
|
|
156
157
|
organization_role_owner: "Propriétaire",
|
|
158
|
+
organization_role_support: "Support",
|
|
157
159
|
organization_slug: "Slug de l'organisation",
|
|
158
160
|
organization_slug_description: "Laissez vide pour en générer un à partir du nom.",
|
|
159
161
|
organization_switcher_empty: "Vous n'appartenez encore à aucune organisation.",
|
|
@@ -209,7 +211,7 @@ const userInvitationsAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make
|
|
|
209
211
|
throw new Error(result.error.message ??
|
|
210
212
|
"Could not load organization invitations.");
|
|
211
213
|
}
|
|
212
|
-
return result.data ?? [];
|
|
214
|
+
return (result.data ?? []).filter((invitation) => invitation.status === "pending");
|
|
213
215
|
},
|
|
214
216
|
catch: (error) => error,
|
|
215
217
|
}))));
|
|
@@ -233,7 +235,7 @@ const organizationMembersAtom = Atom.family((authClient) => Atom.family((organiz
|
|
|
233
235
|
}
|
|
234
236
|
return {
|
|
235
237
|
members: membersResult.data?.members ?? [],
|
|
236
|
-
invitations: invitationsResult.data ?? [],
|
|
238
|
+
invitations: (invitationsResult.data ?? []).filter((invitation) => invitation.status === "pending"),
|
|
237
239
|
};
|
|
238
240
|
},
|
|
239
241
|
catch: (error) => error,
|
|
@@ -336,14 +338,14 @@ const organizationLogoFromForm = async (value, m, uploadImage) => {
|
|
|
336
338
|
return assetPath(value);
|
|
337
339
|
return null;
|
|
338
340
|
};
|
|
339
|
-
const organizationRoles = ["owner", "admin", "member"];
|
|
340
|
-
const normalizeOrganizationRole = (role) => role === "owner" || role === "admin" || role === "member" ? role : "member";
|
|
341
341
|
const organizationRoleLabel = (role, m) => {
|
|
342
342
|
switch (normalizeOrganizationRole(role)) {
|
|
343
343
|
case "owner":
|
|
344
344
|
return m.organization_role_owner();
|
|
345
345
|
case "admin":
|
|
346
346
|
return m.organization_role_admin();
|
|
347
|
+
case "support":
|
|
348
|
+
return m.organization_role_support();
|
|
347
349
|
case "member":
|
|
348
350
|
return m.organization_role_member();
|
|
349
351
|
}
|
|
@@ -379,14 +381,18 @@ const organizationMetadataFromForm = async (value, m, uploadImage) => {
|
|
|
379
381
|
}
|
|
380
382
|
return { translations };
|
|
381
383
|
};
|
|
382
|
-
export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side = "bottom", className, defaultDialog = null, hideTrigger = false, renderUnauthenticated, locked = false, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }) {
|
|
383
|
-
const
|
|
384
|
-
const authClient = providedAuthClient ??
|
|
384
|
+
export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side = "bottom", className, defaultDialog = null, hideTrigger = false, menuActions, renderUnauthenticated, locked = false, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }) {
|
|
385
|
+
const auth = useKrakstackAuth();
|
|
386
|
+
const authClient = providedAuthClient ?? auth?.authClient;
|
|
387
|
+
if (!authClient) {
|
|
388
|
+
throw new Error("KrakstackAuthProvider is required to use authClient.");
|
|
389
|
+
}
|
|
385
390
|
const labels = organizationSwitcherMessages(messages);
|
|
386
391
|
const m = organizationMessageFns(labels);
|
|
387
392
|
const session = authClient.useSession();
|
|
388
393
|
const organizations = authClient.useListOrganizations();
|
|
389
394
|
const activeOrganization = authClient.useActiveOrganization();
|
|
395
|
+
const lastAuthRefreshVersion = useRef(auth?.authRefreshVersion ?? 0);
|
|
390
396
|
const [uncontrolledDialog, setUncontrolledDialog] = useState(defaultDialog);
|
|
391
397
|
const dialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
|
|
392
398
|
const invitationsAtom = session.data
|
|
@@ -405,6 +411,8 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
405
411
|
onSuccess: () => null,
|
|
406
412
|
});
|
|
407
413
|
const loadingUserInvitations = invitationsResult._tag === "Initial";
|
|
414
|
+
const activeMemberRole = normalizeOrganizationRole(activeOrganization.data?.members.find((member) => member.userId === session.data?.user.id)?.role);
|
|
415
|
+
const canManageApiKeys = activeMemberRole === "owner" || activeMemberRole === "admin";
|
|
408
416
|
const setDialog = (next) => {
|
|
409
417
|
const nextDialog = typeof next === "function" ? next(dialog) : next;
|
|
410
418
|
if (nextDialog === dialog)
|
|
@@ -414,6 +422,21 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
414
422
|
onDialogChange?.(nextDialog);
|
|
415
423
|
};
|
|
416
424
|
const openCreate = () => setDialog("create");
|
|
425
|
+
const refresh = async () => {
|
|
426
|
+
await organizations.refetch();
|
|
427
|
+
await activeOrganization.refetch();
|
|
428
|
+
await session.refetch();
|
|
429
|
+
};
|
|
430
|
+
const refreshOnSessionChanged = useEffectEvent(() => {
|
|
431
|
+
void refresh();
|
|
432
|
+
});
|
|
433
|
+
useEffect(() => {
|
|
434
|
+
const version = auth?.authRefreshVersion ?? 0;
|
|
435
|
+
if (version === lastAuthRefreshVersion.current)
|
|
436
|
+
return;
|
|
437
|
+
lastAuthRefreshVersion.current = version;
|
|
438
|
+
refreshOnSessionChanged();
|
|
439
|
+
}, [auth?.authRefreshVersion]);
|
|
417
440
|
if (!session.data) {
|
|
418
441
|
return _jsx(_Fragment, { children: renderUnauthenticated?.() });
|
|
419
442
|
}
|
|
@@ -423,11 +446,6 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
423
446
|
? (organizations.data?.filter((organization) => organization.id !== active?.id) ?? [])
|
|
424
447
|
: [];
|
|
425
448
|
const hasOrganizationListItems = organizations.isPending || Boolean(organizations.error) || !locked;
|
|
426
|
-
const refresh = async () => {
|
|
427
|
-
await organizations.refetch();
|
|
428
|
-
await activeOrganization.refetch();
|
|
429
|
-
await session.refetch();
|
|
430
|
-
};
|
|
431
449
|
const refreshAfterInvitationAction = async (previousActiveId) => {
|
|
432
450
|
refreshUserInvitations();
|
|
433
451
|
await refresh();
|
|
@@ -448,7 +466,7 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
448
466
|
? { imageSrc: activeDisplay.image }
|
|
449
467
|
: {}) }), _jsx(ChevronsUpDown, { className: "text-muted-foreground size-4 shrink-0 group-data-[collapsible=icon]:hidden" })] }) }), _jsx(DropdownMenuContent, { className: "min-w-64 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: activeDisplay.name, subtitle: activeDisplay.subtitle, icon: Building2, variant: "sidebar", className: "px-1 py-1.5 text-left text-sm", ...(activeDisplay.image
|
|
450
468
|
? { imageSrc: activeDisplay.image }
|
|
451
|
-
: {}) }) }), hasOrganizationListItems ? _jsx(DropdownMenuSeparator, {}) : null, organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: m.organization_loading() })) : null, organizations.error ? (_jsx(DropdownMenuItem, { disabled: true, children: organizations.error.message })) : null, !locked && selectableOrganizations.length ? (selectableOrganizations.map((organization) => {
|
|
469
|
+
: {}) }) }), menuActions ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), menuActions] })) : null, hasOrganizationListItems ? _jsx(DropdownMenuSeparator, {}) : null, organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: m.organization_loading() })) : null, organizations.error ? (_jsx(DropdownMenuItem, { disabled: true, children: organizations.error.message })) : null, !locked && selectableOrganizations.length ? (selectableOrganizations.map((organization) => {
|
|
452
470
|
const display = organizationDisplay(organization, m, baseUrl);
|
|
453
471
|
return (_jsx(DropdownMenuItem, { onClick: async () => {
|
|
454
472
|
const result = await authClient.organization.setActive({
|
|
@@ -461,11 +479,11 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
461
479
|
}, children: _jsx(AppBrand, { to: null, label: display.name, subtitle: display.subtitle, icon: Building2, className: "w-full text-left [&>div:first-child]:size-7", ...(display.image ? { imageSrc: display.image } : {}) }) }, organization.id));
|
|
462
480
|
})) : !locked && !organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: active
|
|
463
481
|
? m.organization_switcher_no_other_organizations()
|
|
464
|
-
: m.organization_switcher_empty() })) : null, _jsx(DropdownMenuSeparator, {}),
|
|
465
|
-
|
|
466
|
-
|
|
482
|
+
: m.organization_switcher_empty() })) : null, !locked ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onClick: openCreate, children: [_jsx(Plus, {}), m.organization_create_title()] }), _jsxs(DropdownMenuItem, { onClick: () => {
|
|
483
|
+
setDialog("invitations");
|
|
484
|
+
}, children: [_jsx(Mail, {}), _jsxs("span", { className: "flex flex-1 items-center justify-between gap-3", children: [m.organization_user_invitations_title(), userInvitations.length ? (_jsx(Badge, { variant: "secondary", children: userInvitations.length })) : null] })] })] })) : null, activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onClick: () => {
|
|
467
485
|
void navigator.clipboard.writeText(activeOrganization.data.id);
|
|
468
|
-
}, children: [_jsx(Copy, {}), m.organization_copy_id()] }), _jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] }), _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), _jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })] })) : null] }) })] })), _jsx(Dialog, { open: dialog === "create", onOpenChange: (open) => {
|
|
486
|
+
}, children: [_jsx(Copy, {}), m.organization_copy_id()] }), _jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] }), _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), canManageApiKeys ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })) : null] })) : null] }) })] })), _jsx(Dialog, { open: dialog === "create", onOpenChange: (open) => {
|
|
469
487
|
setDialog((current) => open ? "create" : current === "create" ? null : current);
|
|
470
488
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_create_title() }), _jsx(DialogDescription, { children: m.organization_create_description() })] }), _jsx(Separator, {}), _jsx(CreateOrganizationSection, { authClient: authClient, baseUrl: baseUrl, onCreated: async (organization) => {
|
|
471
489
|
setDialog(null);
|
|
@@ -481,9 +499,9 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
481
499
|
setDialog((current) => open ? "manage" : current === "manage" ? null : current);
|
|
482
500
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(EditOrganizationSection, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
|
|
483
501
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
484
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-
|
|
502
|
+
}, 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, organization: activeOrganization.data, currentUserId: session.data.user.id, active: dialog === "members" })) : null] }) }), _jsx(Dialog, { open: dialog === "apiKeys" && canManageApiKeys, onOpenChange: (open) => {
|
|
485
503
|
setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
486
|
-
}, 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" })) : null] }) }), _jsx(Dialog, { open: dialog === "invitations", onOpenChange: (open) => {
|
|
504
|
+
}, 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" && !locked, onOpenChange: (open) => {
|
|
487
505
|
setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
|
|
488
506
|
}, 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, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, activeOrganizationId: activeOrganization.data?.id, onActionComplete: refreshAfterInvitationAction })] }) })] }));
|
|
489
507
|
}
|
|
@@ -519,7 +537,7 @@ function UserInvitationsManager({ authClient, invitations, loading, error, activ
|
|
|
519
537
|
};
|
|
520
538
|
return (_jsxs("section", { className: "flex flex-col gap-4", children: [error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, actionError ? (_jsx("p", { className: "text-destructive text-sm", children: actionError })) : null, _jsx(DataTable, { columns: userInvitationColumns({
|
|
521
539
|
m,
|
|
522
|
-
}), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_user_invitations_empty(), exportFileName: "organization-invitations.csv", features: { gallery: false }, rowActions: userInvitationRowActions({
|
|
540
|
+
}), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_user_invitations_empty(), exportFileName: "organization-invitations.csv", features: { gallery: false }, searchState: "local", rowActions: userInvitationRowActions({
|
|
523
541
|
m,
|
|
524
542
|
actingInvitationId,
|
|
525
543
|
onAccept: acceptInvitation,
|
|
@@ -746,12 +764,23 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
746
764
|
});
|
|
747
765
|
const members = membersData.members;
|
|
748
766
|
const invitations = membersData.invitations;
|
|
767
|
+
const [memberRoleOverrides, setMemberRoleOverrides] = useState({});
|
|
768
|
+
const displayedMembers = members.map((member) => ({
|
|
769
|
+
...member,
|
|
770
|
+
role: memberRoleOverrides[member.id] ?? member.role,
|
|
771
|
+
}));
|
|
749
772
|
const membersError = AsyncResult.match(membersResult, {
|
|
750
773
|
onInitial: () => null,
|
|
751
774
|
onFailure: () => m.organization_members_load_error(),
|
|
752
775
|
onSuccess: () => null,
|
|
753
776
|
});
|
|
754
777
|
const loading = membersResult._tag === "Initial";
|
|
778
|
+
const currentMemberRole = displayedMembers.find((member) => member.userId === currentUserId)?.role;
|
|
779
|
+
const canChangeMemberRoles = hasAnyRole(currentMemberRole, [
|
|
780
|
+
"owner",
|
|
781
|
+
"admin",
|
|
782
|
+
]);
|
|
783
|
+
const canRemoveMembers = canChangeMemberRoles;
|
|
755
784
|
const inviteForm = useAppForm({
|
|
756
785
|
defaultValues: { email: "", role: "member" },
|
|
757
786
|
onSubmit: async ({ value, formApi }) => {
|
|
@@ -775,19 +804,26 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
775
804
|
},
|
|
776
805
|
});
|
|
777
806
|
const updateRole = async (member, role) => {
|
|
778
|
-
setUpdatingMemberId(member.id);
|
|
779
807
|
setError(null);
|
|
808
|
+
const nextRole = Array.isArray(role)
|
|
809
|
+
? Array.from(new Set(role)).join(",")
|
|
810
|
+
: normalizeOrganizationRole(role);
|
|
811
|
+
setMemberRoleOverrides((current) => ({
|
|
812
|
+
...current,
|
|
813
|
+
[member.id]: nextRole,
|
|
814
|
+
}));
|
|
780
815
|
const result = await authClient.organization.updateMemberRole({
|
|
781
816
|
memberId: member.id,
|
|
782
|
-
role,
|
|
817
|
+
role: Array.isArray(role) ? role : normalizeOrganizationRole(role),
|
|
783
818
|
organizationId: organization.id,
|
|
784
819
|
});
|
|
785
|
-
setUpdatingMemberId(null);
|
|
786
820
|
if (result.error) {
|
|
821
|
+
setMemberRoleOverrides((current) => ({
|
|
822
|
+
...current,
|
|
823
|
+
[member.id]: member.role,
|
|
824
|
+
}));
|
|
787
825
|
setError(result.error.message ?? m.organization_member_role_error());
|
|
788
|
-
return;
|
|
789
826
|
}
|
|
790
|
-
refreshMembers();
|
|
791
827
|
};
|
|
792
828
|
const removeMember = async (member) => {
|
|
793
829
|
setUpdatingMemberId(member.id);
|
|
@@ -823,24 +859,25 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
823
859
|
}, 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.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.organization_member_email(), placeholder: "teammate@example.com", type: "email", required: true })) }), _jsx(inviteForm.AppField, { name: "role", children: (field) => (_jsx(field.SelectField, { label: m.organization_member_role(), options: organizationRoles.map((role) => ({
|
|
824
860
|
label: organizationRoleLabel(role, m),
|
|
825
861
|
value: role,
|
|
826
|
-
})) })) }), _jsx("div", { className: "self-end", children: _jsx(inviteForm.SubmitButton, {}) }), _jsx(inviteForm.FormError, {})] }) }), 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: "min-w-0 overflow-x-auto", children: _jsx(DataTable, { columns: memberColumns({
|
|
862
|
+
})) })) }), _jsx("div", { className: "self-end", children: _jsx(inviteForm.SubmitButton, {}) }), _jsx(inviteForm.FormError, {})] }) }), 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({
|
|
827
863
|
m,
|
|
828
864
|
baseUrl,
|
|
829
|
-
|
|
865
|
+
canChangeRoles: canChangeMemberRoles,
|
|
830
866
|
onRoleChange: updateRole,
|
|
831
|
-
}), data:
|
|
867
|
+
}), data: displayedMembers, emptyLabel: loading ? m.user_loading() : m.organization_members_empty(), exportFileName: `${organization.slug}-members.csv`, features: { gallery: false }, searchState: "local", rowActions: memberRowActions({
|
|
832
868
|
m,
|
|
869
|
+
canRemoveMembers,
|
|
833
870
|
currentUserId,
|
|
834
871
|
onRemove: removeMember,
|
|
835
|
-
}) }) })] }), _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: "min-w-0 overflow-x-auto", children: _jsx(DataTable, { columns: invitationColumns({
|
|
872
|
+
}) }) })] }), _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({
|
|
836
873
|
m,
|
|
837
|
-
}), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_invitations_empty(), exportFileName: `${organization.slug}-invitations.csv`, features: { gallery: false }, rowActions: invitationRowActions({
|
|
874
|
+
}), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_invitations_empty(), exportFileName: `${organization.slug}-invitations.csv`, features: { gallery: false }, searchState: "local", rowActions: invitationRowActions({
|
|
838
875
|
m,
|
|
839
876
|
cancellingInvitationId,
|
|
840
877
|
onCancel: cancelInvitation,
|
|
841
878
|
}) }) })] })] }));
|
|
842
879
|
}
|
|
843
|
-
const memberColumns = ({ m, baseUrl,
|
|
880
|
+
const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
|
|
844
881
|
{
|
|
845
882
|
id: "user",
|
|
846
883
|
header: m.organization_member_user(),
|
|
@@ -854,15 +891,27 @@ const memberColumns = ({ m, baseUrl, updatingMemberId, onRoleChange, }) => [
|
|
|
854
891
|
header: m.organization_member_role(),
|
|
855
892
|
cell: ({ row }) => {
|
|
856
893
|
const member = row.original;
|
|
857
|
-
const
|
|
858
|
-
|
|
894
|
+
const roles = normalizeOrganizationRoles(member.role);
|
|
895
|
+
const roleOptions = roles.map((role) => ({
|
|
896
|
+
label: organizationRoleLabel(role, m),
|
|
897
|
+
value: role,
|
|
898
|
+
}));
|
|
899
|
+
if (!canChangeRoles) {
|
|
900
|
+
return (_jsx("div", { className: "flex flex-wrap gap-1", children: roleOptions.map((role) => (_jsx(Badge, { variant: "secondary", children: role.label }, role.value))) }));
|
|
901
|
+
}
|
|
902
|
+
return (_jsx(DataTableRelationshipCell, { emptyLabel: m.organization_member_role(), manageLabel: m.organization_member_role(), options: organizationRoles.map((role) => ({
|
|
859
903
|
label: organizationRoleLabel(role, m),
|
|
860
904
|
value: role,
|
|
861
|
-
})), value:
|
|
862
|
-
if (value
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
},
|
|
905
|
+
})), value: roleOptions, onAdd: (value) => {
|
|
906
|
+
if (!isOrganizationRole(value))
|
|
907
|
+
return;
|
|
908
|
+
onRoleChange(member, Array.from(new Set([...roles, value])));
|
|
909
|
+
}, onRemove: (value) => {
|
|
910
|
+
if (!isOrganizationRole(value))
|
|
911
|
+
return;
|
|
912
|
+
const nextRoles = roles.filter((role) => role !== value);
|
|
913
|
+
onRoleChange(member, nextRoles.length > 0 ? nextRoles : ["member"]);
|
|
914
|
+
} }));
|
|
866
915
|
},
|
|
867
916
|
},
|
|
868
917
|
{
|
|
@@ -871,12 +920,14 @@ const memberColumns = ({ m, baseUrl, updatingMemberId, onRoleChange, }) => [
|
|
|
871
920
|
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.createdAt) })),
|
|
872
921
|
},
|
|
873
922
|
];
|
|
874
|
-
const memberRowActions = ({ m, currentUserId, onRemove, }) => [
|
|
923
|
+
const memberRowActions = ({ m, canRemoveMembers, currentUserId, onRemove, }) => [
|
|
875
924
|
{
|
|
876
925
|
name: m.organization_member_remove(),
|
|
877
926
|
icon: _jsx(Trash2, {}),
|
|
878
927
|
variant: "destructive",
|
|
879
|
-
visible: (member) =>
|
|
928
|
+
visible: (member) => canRemoveMembers &&
|
|
929
|
+
member.userId !== currentUserId &&
|
|
930
|
+
normalizeOrganizationRole(member.role) !== "owner",
|
|
880
931
|
onClick: onRemove,
|
|
881
932
|
},
|
|
882
933
|
];
|
|
@@ -974,7 +1025,7 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
|
|
|
974
1025
|
event.preventDefault();
|
|
975
1026
|
event.stopPropagation();
|
|
976
1027
|
createForm.handleSubmit();
|
|
977
|
-
}, children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.api_key_rate_limit_notice() }), _jsx(createForm.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.user_api_key_name(), required: true })) }), _jsx(createForm.FormError, {}), _jsx(createForm.SubmitButton, {})] }) }), 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, emptyLabel: loading ? m.user_loading() : m.table_empty(), exportFileName: `${organization.slug}-api-keys.csv`, features: { gallery: false }, rowActions: apiKeyRowActions({ m, onDelete: deleteKey }) })] }));
|
|
1028
|
+
}, children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.api_key_rate_limit_notice() }), _jsx(createForm.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.user_api_key_name(), required: true })) }), _jsx(createForm.FormError, {}), _jsx(createForm.SubmitButton, {})] }) }), 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, emptyLabel: loading ? m.user_loading() : m.table_empty(), exportFileName: `${organization.slug}-api-keys.csv`, features: { gallery: false }, searchState: "local", rowActions: apiKeyRowActions({ m, onDelete: deleteKey }) })] }));
|
|
978
1029
|
}
|
|
979
1030
|
const apiKeyColumns = ({ m, }) => [
|
|
980
1031
|
{
|
|
@@ -18,18 +18,13 @@ import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLeg
|
|
|
18
18
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
19
19
|
import { Separator } from "@/components/ui/separator";
|
|
20
20
|
import { authClientApi } from "./auth-client-api";
|
|
21
|
-
import {
|
|
21
|
+
import { useKrakstackAuth } from "./auth-provider";
|
|
22
22
|
import { createApiKey } from "./api-key";
|
|
23
23
|
import { useOpenedOnce } from "./hooks";
|
|
24
24
|
import { ExtraUploadedAsset } from "../extra/schema";
|
|
25
25
|
import { assetPath, assetUrl } from "./utils";
|
|
26
26
|
import { AdminOrganizationsTable } from "./admin-organizations";
|
|
27
27
|
import { AdminUsersTable } from "./admin-users";
|
|
28
|
-
const defaultAdminTableSearch = {
|
|
29
|
-
page: 0,
|
|
30
|
-
pageSize: 10,
|
|
31
|
-
globalFilter: "",
|
|
32
|
-
};
|
|
33
28
|
const messages = {
|
|
34
29
|
en: {
|
|
35
30
|
api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
|
|
@@ -270,8 +265,10 @@ const userApiKeysAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make(Eff
|
|
|
270
265
|
const emptyApiKeysAtom = Atom.make(Effect.succeed([]));
|
|
271
266
|
export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRedirect = "/", side = "bottom", defaultDialog = null, hideTrigger = false, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }) => {
|
|
272
267
|
const auth = useKrakstackAuth();
|
|
273
|
-
const
|
|
274
|
-
|
|
268
|
+
const authClient = providedAuthClient ?? auth?.authClient;
|
|
269
|
+
if (!authClient) {
|
|
270
|
+
throw new Error("KrakstackAuthProvider is required to use authClient.");
|
|
271
|
+
}
|
|
275
272
|
const labels = userButtonMessages(messages);
|
|
276
273
|
const m = userButtonMessageFns(labels);
|
|
277
274
|
const projectConfig = auth?.projectConfig ?? null;
|
|
@@ -279,12 +276,6 @@ export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRed
|
|
|
279
276
|
const currentSiteHref = useRouterState({
|
|
280
277
|
select: (state) => `${import.meta.env.VITE_SITE_URL}${state.location.href}`,
|
|
281
278
|
});
|
|
282
|
-
const adminTableSearch = useRouterState({
|
|
283
|
-
select: (state) => ({
|
|
284
|
-
...defaultAdminTableSearch,
|
|
285
|
-
...state.location.search,
|
|
286
|
-
}),
|
|
287
|
-
});
|
|
288
279
|
const { data: session, isPending, refetch } = authClient.useSession();
|
|
289
280
|
const [uncontrolledDialog, setUncontrolledDialog] = useState(defaultDialog);
|
|
290
281
|
const [isStoppingImpersonation, setIsStoppingImpersonation] = useState(false);
|
|
@@ -386,13 +377,13 @@ export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRed
|
|
|
386
377
|
setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
387
378
|
}, 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: m.user_api_keys_description() })] }), _jsx(Separator, {}), _jsx(ApiKeyManager, { authClient: authClient, active: settingsDialog === "apiKeys", permissions: apiKeyPermissions ?? {} })] }) }), isAdmin ? (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: settingsDialog === "adminUsers", onOpenChange: (open) => {
|
|
388
379
|
setSettingsDialog((current) => open ? "adminUsers" : current === "adminUsers" ? null : current);
|
|
389
|
-
}, 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, {
|
|
380
|
+
}, 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) => {
|
|
390
381
|
setSettingsDialog((current) => open
|
|
391
382
|
? "adminOrganizations"
|
|
392
383
|
: current === "adminOrganizations"
|
|
393
384
|
? null
|
|
394
385
|
: current);
|
|
395
|
-
}, 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_organizations() }), _jsx(DialogDescription, { children: m.user_button_admin_organizations_description() })] }), _jsx(Separator, {}), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(AdminOrganizationsTable, {
|
|
386
|
+
}, 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_organizations() }), _jsx(DialogDescription, { children: m.user_button_admin_organizations_description() })] }), _jsx(Separator, {}), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(AdminOrganizationsTable, {}) })] }) })] })) : null] }));
|
|
396
387
|
};
|
|
397
388
|
function ConnectedAccounts({ authClient, baseUrl, accountCache, googleEnabled, currentSiteHref, navigate, }) {
|
|
398
389
|
const m = useUserButtonMessages();
|
|
@@ -770,7 +761,7 @@ function ApiKeyManager({ authClient, active, permissions = {}, }) {
|
|
|
770
761
|
event.preventDefault();
|
|
771
762
|
event.stopPropagation();
|
|
772
763
|
createForm.handleSubmit();
|
|
773
|
-
}, children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.api_key_rate_limit_notice() }), _jsx(createForm.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.user_api_key_name(), required: true })) }), 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(createForm.FormError, {}), _jsx(createForm.SubmitButton, {})] }) }), 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() }), _jsxs("div", { className: "grid min-w-0 gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center", children: [_jsx("code", { className: "bg-muted block max-w-full overflow-x-auto rounded-md p-3 text-sm whitespace-nowrap", children: createdKey }), _jsxs(Button, { type: "button", variant: "outline", onClick: copyCreatedKey, className: "self-start sm:self-auto", children: [copiedKey ? _jsx(Check, {}) : _jsx(Copy, {}), copiedKey ? m.user_api_key_copied() : m.user_api_key_copy()] })] })] })) : 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, emptyLabel: loading ? m.user_loading() : m.table_empty(), exportFileName: m.user_api_keys_export_file_name(), features: { gallery: false }, rowActions: apiKeyRowActions({ m, onDelete: deleteKey }) })] }));
|
|
764
|
+
}, children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.api_key_rate_limit_notice() }), _jsx(createForm.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.user_api_key_name(), required: true })) }), 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(createForm.FormError, {}), _jsx(createForm.SubmitButton, {})] }) }), 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() }), _jsxs("div", { className: "grid min-w-0 gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center", children: [_jsx("code", { className: "bg-muted block max-w-full overflow-x-auto rounded-md p-3 text-sm whitespace-nowrap", children: createdKey }), _jsxs(Button, { type: "button", variant: "outline", onClick: copyCreatedKey, className: "self-start sm:self-auto", children: [copiedKey ? _jsx(Check, {}) : _jsx(Copy, {}), copiedKey ? m.user_api_key_copied() : m.user_api_key_copy()] })] })] })) : 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, emptyLabel: loading ? m.user_loading() : m.table_empty(), exportFileName: m.user_api_keys_export_file_name(), features: { gallery: false }, searchState: "local", rowActions: apiKeyRowActions({ m, onDelete: deleteKey }) })] }));
|
|
774
765
|
}
|
|
775
766
|
const apiKeyColumns = ({ m, }) => [
|
|
776
767
|
{
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export * from "./schema";
|
|
2
2
|
export * as Query from "./query";
|
|
3
|
+
export * as Roles from "./roles";
|
|
3
4
|
export { AuthClientApi, AuthServiceApi } from "./api";
|
|
4
5
|
export { AuthService, type AuthServiceLayerOptions } from "./service";
|
|
5
6
|
export { AuthClientConfig } from "./config";
|
|
6
7
|
export { proxyAuthRequest } from "./server/proxy";
|
|
7
|
-
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, type AuthUiClient, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type UserButtonDialog, useAuthClient, useAdminUsersTotal, } from "./components";
|
|
8
|
+
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, type AuthUiClient, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type OrganizationSwitcherProps, type UserButtonDialog, useAuthClient, useAdminUsersTotal, } from "./components";
|
|
8
9
|
export * as BetterAuth from "./better-auth/api.group";
|
|
9
10
|
export * as Extra from "./extra/api.group";
|
|
10
11
|
export * as Server from "./server";
|
package/dist/index.js
CHANGED
package/dist/roles.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const organizationRoles: readonly ["owner", "admin", "support", "member"];
|
|
2
|
+
export type OrganizationRole = (typeof organizationRoles)[number];
|
|
3
|
+
export declare const organizationImpersonationRoles: readonly ["owner", "admin", "support"];
|
|
4
|
+
export declare const globalAdminRoles: readonly ["admin"];
|
|
5
|
+
export type GlobalAdminRole = (typeof globalAdminRoles)[number];
|
|
6
|
+
export declare const parseRoleList: (role: unknown) => string[];
|
|
7
|
+
export declare const hasAnyRole: (role: unknown, roles: readonly string[]) => boolean;
|
|
8
|
+
export declare const isOrganizationRole: (role: string) => role is OrganizationRole;
|
|
9
|
+
export declare const normalizeOrganizationRole: (role: unknown) => OrganizationRole;
|
|
10
|
+
export declare const normalizeOrganizationRoles: (role: unknown) => OrganizationRole[];
|
package/dist/roles.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const organizationRoles = [
|
|
2
|
+
"owner",
|
|
3
|
+
"admin",
|
|
4
|
+
"support",
|
|
5
|
+
"member",
|
|
6
|
+
];
|
|
7
|
+
export const organizationImpersonationRoles = [
|
|
8
|
+
"owner",
|
|
9
|
+
"admin",
|
|
10
|
+
"support",
|
|
11
|
+
];
|
|
12
|
+
export const globalAdminRoles = ["admin"];
|
|
13
|
+
export const parseRoleList = (role) => typeof role === "string"
|
|
14
|
+
? role
|
|
15
|
+
.split(",")
|
|
16
|
+
.map((item) => item.trim())
|
|
17
|
+
.filter(Boolean)
|
|
18
|
+
: [];
|
|
19
|
+
export const hasAnyRole = (role, roles) => {
|
|
20
|
+
const allowed = new Set(roles);
|
|
21
|
+
return parseRoleList(role).some((item) => allowed.has(item));
|
|
22
|
+
};
|
|
23
|
+
export const isOrganizationRole = (role) => organizationRoles.includes(role);
|
|
24
|
+
export const normalizeOrganizationRole = (role) => {
|
|
25
|
+
const [firstRole] = parseRoleList(role).filter(isOrganizationRole);
|
|
26
|
+
return firstRole ?? "member";
|
|
27
|
+
};
|
|
28
|
+
export const normalizeOrganizationRoles = (role) => {
|
|
29
|
+
const roles = parseRoleList(role).filter(isOrganizationRole);
|
|
30
|
+
return roles.length > 0 ? Array.from(new Set(roles)) : ["member"];
|
|
31
|
+
};
|
package/dist/schema.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare const Session: Schema.Struct<{
|
|
|
21
21
|
readonly userAgent: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
22
22
|
readonly userId: Schema.String;
|
|
23
23
|
readonly impersonatedBy: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
24
|
+
readonly impersonatedByOrganizationId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
24
25
|
readonly activeOrganizationId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
25
26
|
}>;
|
|
26
27
|
export declare const OrganizationLocale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
|
package/dist/schema.js
CHANGED
|
@@ -39,6 +39,7 @@ export const Session = Schema.Struct({
|
|
|
39
39
|
userAgent: Schema.optional(Schema.NullOr(Schema.String)),
|
|
40
40
|
userId: Schema.String,
|
|
41
41
|
impersonatedBy: Schema.optional(Schema.NullOr(Schema.String)),
|
|
42
|
+
impersonatedByOrganizationId: Schema.optional(Schema.NullOr(Schema.String)),
|
|
42
43
|
activeOrganizationId: Schema.optional(Schema.NullOr(Schema.String)),
|
|
43
44
|
}).annotate({
|
|
44
45
|
identifier: "Session",
|
|
@@ -55,6 +56,7 @@ export const Session = Schema.Struct({
|
|
|
55
56
|
userAgent: "Mozilla/5.0",
|
|
56
57
|
userId: "user_1",
|
|
57
58
|
impersonatedBy: null,
|
|
59
|
+
impersonatedByOrganizationId: null,
|
|
58
60
|
activeOrganizationId: "org_1",
|
|
59
61
|
},
|
|
60
62
|
],
|