@krak-stack/auth 0.1.21 → 0.1.23

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.
@@ -166,6 +166,8 @@ type OrganizationSwitcherProps = {
166
166
  baseUrl?: string | undefined;
167
167
  side?: ComponentProps<typeof DropdownMenuContent>["side"];
168
168
  className?: string;
169
+ defaultDialog?: OrganizationSwitcherDialog | null;
170
+ hideTrigger?: boolean;
169
171
  renderUnauthenticated?: () => ReactNode;
170
172
  locked?: boolean;
171
173
  messages?: OrganizationSwitcherMessages;
@@ -181,5 +183,5 @@ type OrganizationSummary = {
181
183
  metadata?: unknown;
182
184
  };
183
185
  export type OrganizationSwitcherDialog = "create" | "manage" | "members" | "apiKeys" | "invitations";
184
- export declare function OrganizationSwitcher({ authClient, baseUrl, side, className, renderUnauthenticated, locked, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }: OrganizationSwitcherProps): import("react").JSX.Element;
186
+ export declare function OrganizationSwitcher({ authClient, baseUrl, side, className, defaultDialog, hideTrigger, renderUnauthenticated, locked, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }: OrganizationSwitcherProps): import("react").JSX.Element;
185
187
  export {};
@@ -4,7 +4,7 @@ import {} from "@tanstack/react-table";
4
4
  import { Schema } from "effect";
5
5
  import { Building2, Check, ChevronsUpDown, KeyRound, Mail, PencilIcon, Plus, Trash2, UserPlus, Users, X, } from "lucide-react";
6
6
  import { createContext, useContext, useEffect, useEffectEvent, useState, } from "react";
7
- import { createDataTableActionsColumn, DataTable, } from "@/components/ui/data-table";
7
+ import { DataTable } from "@/components/ui/data-table";
8
8
  import { EditingLocaleSwitcher } from "@/components/ui/editing-locale-switcher";
9
9
  import { AppBrand } from "@/components/ui/app-brand";
10
10
  import { useAppForm } from "@/components/ui/form";
@@ -342,13 +342,13 @@ const organizationMetadataFromForm = async (authClient, value, m) => {
342
342
  }
343
343
  return { translations };
344
344
  };
345
- export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", className, renderUnauthenticated, locked = false, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }) {
345
+ export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", className, defaultDialog = null, hideTrigger = false, renderUnauthenticated, locked = false, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }) {
346
346
  const labels = organizationSwitcherMessages(messages);
347
347
  const m = organizationMessageFns(labels);
348
348
  const session = authClient.useSession();
349
349
  const organizations = authClient.useListOrganizations();
350
350
  const activeOrganization = authClient.useActiveOrganization();
351
- const [uncontrolledDialog, setUncontrolledDialog] = useState(null);
351
+ const [uncontrolledDialog, setUncontrolledDialog] = useState(defaultDialog);
352
352
  const dialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
353
353
  const sessionUserId = session.data?.user.id;
354
354
  const [userInvitations, setUserInvitations] = useState([]);
@@ -376,6 +376,7 @@ export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", cla
376
376
  setUncontrolledDialog(nextDialog);
377
377
  onDialogChange?.(nextDialog);
378
378
  };
379
+ const openCreate = () => setDialog("create");
379
380
  useEffect(() => {
380
381
  if (!sessionUserId)
381
382
  return;
@@ -409,7 +410,7 @@ export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", cla
409
410
  }
410
411
  };
411
412
  const activeDisplay = organizationDisplay(active ?? null, m, baseUrl);
412
- return (_jsxs(OrganizationMessagesContext.Provider, { value: m, children: [_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "ghost", className: cn("h-11 w-full justify-between gap-2 !px-1 !py-0 group-data-[collapsible=icon]:size-8 group-data-[collapsible=icon]:justify-start group-data-[collapsible=icon]:!p-0", className), children: [_jsx(AppBrand, { to: null, label: activeName
413
+ return (_jsxs(OrganizationMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "ghost", className: cn("h-11 w-full justify-between gap-2 !px-1 !py-0 group-data-[collapsible=icon]:size-8 group-data-[collapsible=icon]:justify-start group-data-[collapsible=icon]:!p-0", className), children: [_jsx(AppBrand, { to: null, label: activeName
413
414
  ? activeDisplay.name
414
415
  : m.organization_switcher_label(), subtitle: activeDisplay.subtitle, icon: Building2, variant: "sidebar", className: "min-w-0 flex-1 !p-0 text-left group-data-[collapsible=icon]:flex-none group-data-[collapsible=icon]:justify-start", ...(activeDisplay.image
415
416
  ? { imageSrc: activeDisplay.image }
@@ -428,20 +429,21 @@ export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", cla
428
429
  }, 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));
429
430
  })) : !locked && !organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: active
430
431
  ? m.organization_switcher_no_other_organizations()
431
- : m.organization_switcher_empty() })) : null, _jsx(DropdownMenuSeparator, {}), !locked ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("create"), children: [_jsx(Plus, {}), m.organization_create_title()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => {
432
+ : m.organization_switcher_empty() })) : null, _jsx(DropdownMenuSeparator, {}), !locked ? (_jsxs(DropdownMenuItem, { onClick: openCreate, children: [_jsx(Plus, {}), m.organization_create_title()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => {
432
433
  setDialog("invitations");
433
434
  void loadUserInvitations();
434
- }, 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] })] }), activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _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) => {
435
+ }, 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] })] }), activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _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) => {
435
436
  setDialog((current) => open ? "create" : current === "create" ? null : current);
436
437
  }, 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) => {
437
- onCreate?.(organization);
438
438
  setDialog(null);
439
439
  const activeResult = await authClient.organization.setActive({
440
440
  organizationId: organization.id,
441
441
  });
442
442
  await refresh();
443
- if (!activeResult.error)
443
+ if (!activeResult.error) {
444
+ onCreate?.(organization);
444
445
  onChange?.(organization);
446
+ }
445
447
  } })] }) }), _jsx(Dialog, { open: dialog === "manage", onOpenChange: (open) => {
446
448
  setDialog((current) => open ? "manage" : current === "manage" ? null : current);
447
449
  }, 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) => {
@@ -484,12 +486,14 @@ function UserInvitationsManager({ authClient, invitations, loading, error, activ
484
486
  };
485
487
  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({
486
488
  m,
489
+ }), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_user_invitations_empty(), exportFileName: "organization-invitations.csv", features: { gallery: false }, rowActions: userInvitationRowActions({
490
+ m,
487
491
  actingInvitationId,
488
492
  onAccept: acceptInvitation,
489
493
  onReject: rejectInvitation,
490
- }), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_user_invitations_empty(), exportFileName: "organization-invitations.csv", features: { gallery: false } })] }));
494
+ }) })] }));
491
495
  }
492
- const userInvitationColumns = ({ m, actingInvitationId, onAccept, onReject, }) => [
496
+ const userInvitationColumns = ({ m, }) => [
493
497
  {
494
498
  accessorKey: "organizationName",
495
499
  header: m.organization_invitation_organization(),
@@ -510,21 +514,21 @@ const userInvitationColumns = ({ m, actingInvitationId, onAccept, onReject, }) =
510
514
  header: m.organization_invitation_expires(),
511
515
  cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.expiresAt) })),
512
516
  },
513
- createDataTableActionsColumn([
514
- {
515
- name: m.organization_invitation_accept(),
516
- icon: _jsx(Check, {}),
517
- visible: (invitation) => actingInvitationId !== invitation.id,
518
- onClick: onAccept,
519
- },
520
- {
521
- name: m.organization_invitation_reject(),
522
- icon: _jsx(X, {}),
523
- variant: "destructive",
524
- visible: (invitation) => actingInvitationId !== invitation.id,
525
- onClick: onReject,
526
- },
527
- ]),
517
+ ];
518
+ const userInvitationRowActions = ({ m, actingInvitationId, onAccept, onReject, }) => [
519
+ {
520
+ name: m.organization_invitation_accept(),
521
+ icon: _jsx(Check, {}),
522
+ visible: (invitation) => actingInvitationId !== invitation.id,
523
+ onClick: onAccept,
524
+ },
525
+ {
526
+ name: m.organization_invitation_reject(),
527
+ icon: _jsx(X, {}),
528
+ variant: "destructive",
529
+ visible: (invitation) => actingInvitationId !== invitation.id,
530
+ onClick: onReject,
531
+ },
528
532
  ];
529
533
  function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated, }) {
530
534
  const m = useOrganizationMessages();
@@ -799,17 +803,21 @@ function OrganizationMembersManager({ authClient, organization, currentUserId, }
799
803
  value: role,
800
804
  })) })) }), _jsx("div", { className: "self-end", children: _jsx(inviteForm.SubmitButton, {}) }), _jsx(inviteForm.FormError, {})] }) }), error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsxs("section", { className: "flex 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(DataTable, { columns: memberColumns({
801
805
  m,
802
- currentUserId,
803
806
  updatingMemberId,
804
- onRemove: removeMember,
805
807
  onRoleChange: updateRole,
806
- }), data: members, emptyLabel: loading ? m.user_loading() : m.organization_members_empty(), exportFileName: `${organization.slug}-members.csv`, features: { gallery: false } })] }), _jsxs("section", { className: "flex 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(DataTable, { columns: invitationColumns({
808
+ }), data: members, emptyLabel: loading ? m.user_loading() : m.organization_members_empty(), exportFileName: `${organization.slug}-members.csv`, features: { gallery: false }, rowActions: memberRowActions({
809
+ m,
810
+ currentUserId,
811
+ onRemove: removeMember,
812
+ }) })] }), _jsxs("section", { className: "flex 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(DataTable, { columns: invitationColumns({
813
+ m,
814
+ }), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_invitations_empty(), exportFileName: `${organization.slug}-invitations.csv`, features: { gallery: false }, rowActions: invitationRowActions({
807
815
  m,
808
816
  cancellingInvitationId,
809
817
  onCancel: cancelInvitation,
810
- }), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_invitations_empty(), exportFileName: `${organization.slug}-invitations.csv`, features: { gallery: false } })] })] }));
818
+ }) })] })] }));
811
819
  }
812
- const memberColumns = ({ m, currentUserId, updatingMemberId, onRemove, onRoleChange, }) => [
820
+ const memberColumns = ({ m, updatingMemberId, onRoleChange, }) => [
813
821
  {
814
822
  id: "user",
815
823
  header: m.organization_member_user(),
@@ -836,17 +844,17 @@ const memberColumns = ({ m, currentUserId, updatingMemberId, onRemove, onRoleCha
836
844
  header: m.organization_member_joined(),
837
845
  cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.createdAt) })),
838
846
  },
839
- createDataTableActionsColumn([
840
- {
841
- name: m.organization_member_remove(),
842
- icon: _jsx(Trash2, {}),
843
- variant: "destructive",
844
- visible: (member) => member.userId !== currentUserId,
845
- onClick: onRemove,
846
- },
847
- ]),
848
847
  ];
849
- const invitationColumns = ({ m, cancellingInvitationId, onCancel, }) => [
848
+ const memberRowActions = ({ m, currentUserId, onRemove, }) => [
849
+ {
850
+ name: m.organization_member_remove(),
851
+ icon: _jsx(Trash2, {}),
852
+ variant: "destructive",
853
+ visible: (member) => member.userId !== currentUserId,
854
+ onClick: onRemove,
855
+ },
856
+ ];
857
+ const invitationColumns = ({ m, }) => [
850
858
  {
851
859
  accessorKey: "email",
852
860
  header: m.organization_member_email(),
@@ -867,15 +875,15 @@ const invitationColumns = ({ m, cancellingInvitationId, onCancel, }) => [
867
875
  header: m.organization_invitation_expires(),
868
876
  cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.expiresAt) })),
869
877
  },
870
- createDataTableActionsColumn([
871
- {
872
- name: m.organization_invitation_cancel(),
873
- icon: _jsx(Trash2, {}),
874
- variant: "destructive",
875
- visible: (invitation) => cancellingInvitationId !== invitation.id,
876
- onClick: onCancel,
877
- },
878
- ]),
878
+ ];
879
+ const invitationRowActions = ({ m, cancellingInvitationId, onCancel, }) => [
880
+ {
881
+ name: m.organization_invitation_cancel(),
882
+ icon: _jsx(Trash2, {}),
883
+ variant: "destructive",
884
+ visible: (invitation) => cancellingInvitationId !== invitation.id,
885
+ onClick: onCancel,
886
+ },
879
887
  ];
880
888
  function OrganizationApiKeyManager({ authClient, organization, }) {
881
889
  const m = useOrganizationMessages();
@@ -939,9 +947,9 @@ function OrganizationApiKeyManager({ authClient, organization, }) {
939
947
  event.preventDefault();
940
948
  event.stopPropagation();
941
949
  createForm.handleSubmit();
942
- }, 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, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsx(Separator, {}), _jsx(DataTable, { columns: apiKeyColumns({ m, onDelete: deleteKey }), data: keys, emptyLabel: loading ? m.user_loading() : m.table_empty(), exportFileName: `${organization.slug}-api-keys.csv`, features: { gallery: false } })] }));
950
+ }, 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, 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 }) })] }));
943
951
  }
944
- const apiKeyColumns = ({ m, onDelete, }) => [
952
+ const apiKeyColumns = ({ m, }) => [
945
953
  {
946
954
  accessorKey: "name",
947
955
  header: m.user_api_key_name(),
@@ -956,12 +964,12 @@ const apiKeyColumns = ({ m, onDelete, }) => [
956
964
  ? m.user_api_key_enabled()
957
965
  : m.user_api_key_disabled() })),
958
966
  },
959
- createDataTableActionsColumn([
960
- {
961
- name: m.user_delete(),
962
- icon: _jsx(Trash2, {}),
963
- variant: "destructive",
964
- onClick: onDelete,
965
- },
966
- ]),
967
+ ];
968
+ const apiKeyRowActions = ({ m, onDelete, }) => [
969
+ {
970
+ name: m.user_delete(),
971
+ icon: _jsx(Trash2, {}),
972
+ variant: "destructive",
973
+ onClick: onDelete,
974
+ },
967
975
  ];
@@ -172,6 +172,8 @@ type UserDropdownProps = {
172
172
  baseUrl?: string | undefined;
173
173
  signOutRedirect?: string;
174
174
  side?: ComponentProps<typeof DropdownMenuContent>["side"];
175
+ defaultDialog?: UserButtonDialog | null;
176
+ hideTrigger?: boolean;
175
177
  renderUnauthenticated?: () => ReactNode;
176
178
  apiKeyPermissions?: Record<string, string[]>;
177
179
  messages?: UserButtonMessages;
@@ -179,5 +181,5 @@ type UserDropdownProps = {
179
181
  onDialogChange?: (dialog: UserButtonDialog | null) => void;
180
182
  };
181
183
  export type UserButtonDialog = "account" | "security" | "apiKeys";
182
- export declare const UserButton: ({ authClient, baseUrl, signOutRedirect, side, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }: UserDropdownProps) => import("react").JSX.Element;
184
+ export declare const UserButton: ({ authClient, baseUrl, signOutRedirect, side, defaultDialog, hideTrigger, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }: UserDropdownProps) => import("react").JSX.Element;
183
185
  export {};
@@ -4,7 +4,7 @@ import { useNavigate, useRouterState, } from "@tanstack/react-router";
4
4
  import { Check, Copy, KeyRound, LogOutIcon, ShieldCheck, Trash2, UserCircleIcon, UserIcon, } from "lucide-react";
5
5
  import { QRCode } from "react-qr-code";
6
6
  import { createContext, useContext, useEffect, useEffectEvent, useState, } from "react";
7
- import { createDataTableActionsColumn, DataTable, } from "@/components/ui/data-table";
7
+ import { DataTable } from "@/components/ui/data-table";
8
8
  import { AppBrand } from "@/components/ui/app-brand";
9
9
  import { useAppForm } from "@/components/ui/form";
10
10
  import { Badge } from "@/components/ui/badge";
@@ -186,19 +186,16 @@ const getLocale = () => (globalThis.document?.documentElement.lang ||
186
186
  .startsWith("fr")
187
187
  ? "fr"
188
188
  : "en";
189
- const interpolate = (value, params) => params
190
- ? value.replace(/\{([^}]+)\}/g, (_, key) => String(params[key] ?? `{${key}}`))
191
- : value;
192
189
  const userButtonMessages = (overrides) => ({
193
190
  ...(getLocale().startsWith("fr") ? messages.fr : messages.en),
194
191
  ...overrides,
195
192
  });
196
- const userButtonMessageFns = (labels) => {
197
- const localized = labels;
198
- return new Proxy({}, {
199
- get: (_target, key) => (params) => interpolate(localized[key], params),
200
- });
201
- };
193
+ const interpolate = (value, params) => params
194
+ ? value.replace(/\{([^}]+)\}/g, (_, key) => String(params[key] ?? `{${key}}`))
195
+ : value;
196
+ const userButtonMessageFns = (labels) => new Proxy({}, {
197
+ get: (_target, key) => (params) => interpolate(labels[key], params),
198
+ });
202
199
  const UserButtonMessagesContext = createContext(userButtonMessageFns(userButtonMessages()));
203
200
  const useUserButtonMessages = () => useContext(UserButtonMessagesContext);
204
201
  const isFile = (value) => value instanceof File;
@@ -218,7 +215,7 @@ const presignUserImageUpload = async (authClient, file, m) => {
218
215
  }
219
216
  return { uploadUrl, url };
220
217
  };
221
- export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side = "bottom", renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }) => {
218
+ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side = "bottom", defaultDialog = null, hideTrigger = false, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }) => {
222
219
  const labels = userButtonMessages(messages);
223
220
  const m = userButtonMessageFns(labels);
224
221
  const navigate = useNavigate();
@@ -226,7 +223,7 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
226
223
  select: (state) => `${import.meta.env.VITE_SITE_URL}${state.location.href}`,
227
224
  });
228
225
  const { data: session, isPending, refetch } = authClient.useSession();
229
- const [uncontrolledDialog, setUncontrolledDialog] = useState(null);
226
+ const [uncontrolledDialog, setUncontrolledDialog] = useState(defaultDialog);
230
227
  const settingsDialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
231
228
  const [formError, setFormError] = useState(null);
232
229
  const setSettingsDialog = (next) => {
@@ -279,7 +276,7 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
279
276
  await refetch();
280
277
  setSettingsDialog(null);
281
278
  };
282
- return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", children: [_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: [_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, {}), _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, {}), _jsxs(DropdownMenuItem, { onClick: signOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] })] }) })] }), _jsx(Dialog, { open: settingsDialog === "account", onOpenChange: (open) => {
279
+ return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", children: [_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: [_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, {}), _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, {}), _jsxs(DropdownMenuItem, { onClick: signOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] })] }) })] })), _jsx(Dialog, { open: settingsDialog === "account", onOpenChange: (open) => {
283
280
  setSettingsDialog((current) => open ? "account" : current === "account" ? null : current);
284
281
  }, 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: {
285
282
  name: displayName ?? "",
@@ -703,9 +700,9 @@ function ApiKeyManager({ authClient, permissions = {}, }) {
703
700
  event.preventDefault();
704
701
  event.stopPropagation();
705
702
  createForm.handleSubmit();
706
- }, 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, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsx(Separator, {}), _jsx(DataTable, { columns: apiKeyColumns({ m, onDelete: deleteKey }), data: keys, emptyLabel: loading ? m.user_loading() : m.table_empty(), exportFileName: m.user_api_keys_export_file_name(), features: { gallery: false } })] }));
703
+ }, 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, 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 }) })] }));
707
704
  }
708
- const apiKeyColumns = ({ m, onDelete, }) => [
705
+ const apiKeyColumns = ({ m, }) => [
709
706
  {
710
707
  accessorKey: "name",
711
708
  header: m.user_api_key_name(),
@@ -729,14 +726,14 @@ const apiKeyColumns = ({ m, onDelete, }) => [
729
726
  return (_jsx("div", { className: "flex max-w-sm flex-wrap gap-1.5", children: permissions.map((permission) => (_jsx(Badge, { variant: "secondary", children: permission }, permission))) }));
730
727
  },
731
728
  },
732
- createDataTableActionsColumn([
733
- {
734
- name: m.user_delete(),
735
- icon: _jsx(Trash2, {}),
736
- variant: "destructive",
737
- onClick: onDelete,
738
- },
739
- ]),
729
+ ];
730
+ const apiKeyRowActions = ({ m, onDelete, }) => [
731
+ {
732
+ name: m.user_delete(),
733
+ icon: _jsx(Trash2, {}),
734
+ variant: "destructive",
735
+ onClick: onDelete,
736
+ },
740
737
  ];
741
738
  const getPermissionId = (resource, action) => `${resource}:${action}`;
742
739
  const isPermissionRecord = (permissions) => typeof permissions === "object" &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [