@krak-stack/auth 0.2.0 → 0.2.1

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.
@@ -1,7 +1,7 @@
1
1
  import { Effect } from "effect";
2
2
  import { FetchHttpClient, HttpClient } from "effect/unstable/http";
3
3
  import { AtomHttpApi } from "effect/unstable/reactivity";
4
- import { HttpApiClient } from "effect/unstable/httpapi";
4
+ import { HttpApi, HttpApiClient } from "effect/unstable/httpapi";
5
5
  import { AuthClientApi } from "../api.js";
6
6
  import { defaultBaseUrl } from "../config.js";
7
7
  const authClientApiUrl = (baseUrl) => {
@@ -15,12 +15,16 @@ export const authHttpClient = (baseUrl) => HttpApiClient.make(AuthClientApi, {
15
15
  baseUrl: authClientApiUrl(baseUrl),
16
16
  transformClient: withCredentials,
17
17
  }).pipe(Effect.provide(FetchHttpClient.layer));
18
- const createAuthClientApiClient = (key) => AtomHttpApi.Service()(`AuthClientApi:${key}`, {
19
- api: AuthClientApi,
20
- baseUrl: key,
21
- httpClient: FetchHttpClient.layer,
22
- transformClient: withCredentials,
23
- });
18
+ const createAuthClientApiClient = (key) => {
19
+ class AuthClientApiClient extends AtomHttpApi.Service()(`AuthClientApi:${key}`, {
20
+ api: AuthClientApi,
21
+ baseUrl: key,
22
+ httpClient: FetchHttpClient.layer,
23
+ transformClient: withCredentials,
24
+ }) {
25
+ }
26
+ return AuthClientApiClient;
27
+ };
24
28
  const authClientApis = new Map();
25
29
  export const authClientApi = (baseUrl) => {
26
30
  const key = authClientApiUrl(baseUrl);
@@ -258,6 +258,7 @@ export function Signin(props) {
258
258
  return () => window.clearInterval(interval);
259
259
  }, [emailOtpResendAvailableAt]);
260
260
  const [form] = useState(() => FormReact.make(signinFormBuilder, {
261
+ runtime: authClientApi(baseUrl).runtime,
261
262
  fields: { email: TextField, password: TextField, otp: OtpField },
262
263
  mode: { validation: "onSubmit" },
263
264
  onSubmit: (action, { decoded: value }) => Effect.gen(function* () {
@@ -340,7 +341,7 @@ export function Signin(props) {
340
341
  }));
341
342
  const submit = useAtomSet(form.submit);
342
343
  const submitResult = useAtomValue(form.submit);
343
- const [socialSignIn] = useState(() => Atom.fn((provider) => Effect.gen(function* () {
344
+ const [socialSignIn] = useState(() => authClientApi(baseUrl).runtime.fn((provider) => Effect.gen(function* () {
344
345
  const payload = oauthQuery
345
346
  ? {
346
347
  provider,
@@ -441,6 +442,7 @@ export function VerifyEmail(props) {
441
442
  const onNavigate = (target) => navigateTarget(target, navigate);
442
443
  const [resent, setResent] = useState(false);
443
444
  const [form] = useState(() => FormReact.make(verifyEmailFormBuilder, {
445
+ runtime: authClientApi(baseUrl).runtime,
444
446
  fields: { email: TextField, otp: OtpField },
445
447
  mode: { validation: "onSubmit" },
446
448
  onSubmit: (action, { decoded: value }) => Effect.gen(function* () {
@@ -488,6 +490,7 @@ export function ForgotPassword(props) {
488
490
  const initialEmail = getSearchParam(searchString, "email")?.trim() ?? "";
489
491
  const [submitted, setSubmitted] = useState(false);
490
492
  const [form] = useState(() => FormReact.make(forgotPasswordFormBuilder, {
493
+ runtime: authClientApi(baseUrl).runtime,
491
494
  fields: { email: TextField },
492
495
  mode: { validation: "onSubmit" },
493
496
  onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
@@ -521,6 +524,7 @@ function ResetPasswordForm({ token, ...props }) {
521
524
  const navigate = useNavigate();
522
525
  const onSuccess = () => navigate({ to: "/sign-in" });
523
526
  const [form] = useState(() => FormReact.make(resetPasswordFormBuilder, {
527
+ runtime: authClientApi(baseUrl).runtime,
524
528
  fields: { password: TextField },
525
529
  mode: { validation: "onSubmit" },
526
530
  onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
@@ -554,6 +558,7 @@ export function TwoFactor(props) {
554
558
  const [mode, setMode] = useState("totp");
555
559
  const [emailCodeSent, setEmailCodeSent] = useState(false);
556
560
  const [form] = useState(() => FormReact.make(twoFactorFormBuilder, {
561
+ runtime: authClientApi(baseUrl).runtime,
557
562
  fields: { code: AuthCodeField, trustDevice: CheckboxField },
558
563
  mode: { validation: "onSubmit" },
559
564
  onSubmit: (action, { decoded: value }) => Effect.gen(function* () {
@@ -23,19 +23,19 @@ export type KrakstackAuthContextValue = {
23
23
  export declare const listenForSessionRevalidation: (target: EventTarget, revalidate: () => void) => () => void;
24
24
  export declare function KrakstackAuthProvider({ children, locale, baseUrl, projectId, access, accessLabels, }: KrakstackAuthProviderProps): import("react").JSX.Element;
25
25
  export declare const useKrakstackAuth: () => KrakstackAuthContextValue | null;
26
- export declare const useKrakstackAuthProjectConfig: () => import("effect/Schema").Struct.ReadonlySide<{
27
- readonly projectKey: import("effect/Schema").String;
28
- readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
29
- readonly logoUrl: import("effect/Schema").NullOr<import("effect/Schema").String>;
30
- readonly authDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
31
- readonly rootDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
32
- readonly themeCss: import("effect/Schema").NullOr<import("effect/Schema").String>;
33
- readonly authOptions: import("effect/Schema").Struct<{
34
- readonly emailPassword: import("effect/Schema").Boolean;
35
- readonly emailOtp: import("effect/Schema").Boolean;
36
- readonly google: import("effect/Schema").Boolean;
37
- }>;
38
- }, "Type"> | null;
26
+ export declare const useKrakstackAuthProjectConfig: () => {
27
+ readonly projectKey: string;
28
+ readonly name: string | null;
29
+ readonly logoUrl: string | null;
30
+ readonly authDomain: string | null;
31
+ readonly rootDomain: string | null;
32
+ readonly themeCss: string | null;
33
+ readonly authOptions: {
34
+ readonly emailPassword: boolean;
35
+ readonly emailOtp: boolean;
36
+ readonly google: boolean;
37
+ };
38
+ } | null;
39
39
  export declare const usePermissions: () => {
40
40
  loading: boolean;
41
41
  permissions: Set<string>;
@@ -60,7 +60,7 @@ const organizationDisplayName = (invitation, organization, fallback) => organiza
60
60
  invitation?.organization?.name ??
61
61
  invitation?.organizationName ??
62
62
  fallback;
63
- const acceptInvitationAtom = Atom.family((baseUrl) => Atom.fn(({ invitationId, organizationId, onFailure, onSuccess, }, get) => Effect.gen(function* () {
63
+ const acceptInvitationAtom = Atom.family((baseUrl) => authClientApi(baseUrl).runtime.fn(({ invitationId, organizationId, onFailure, onSuccess, }, get) => Effect.gen(function* () {
64
64
  const client = yield* authHttpClient(baseUrl);
65
65
  yield* client.auth.organizationAcceptInvitation({
66
66
  payload: { invitationId },
@@ -102,7 +102,7 @@ const accessAtom = Atom.family((baseUrl) => Atom.family((key) => {
102
102
  userId: Schema.optional(Schema.String),
103
103
  }));
104
104
  const { locale, organizationId } = Schema.decodeUnknownSync(AccessKey)(key);
105
- return Atom.keepAlive(Atom.make((get) => Effect.gen(function* () {
105
+ return Atom.keepAlive(authClientApi(baseUrl).runtime.atom((get) => Effect.gen(function* () {
106
106
  const client = yield* authHttpClient(baseUrl);
107
107
  const allowed = yield* client.auth
108
108
  .organizationSetActive({ payload: { organizationId } })
@@ -558,7 +558,7 @@ const organizationFailureMessage = (cause, fallback) => {
558
558
  };
559
559
  const decodeUploadedAsset = Schema.decodeUnknownEffect(ExtraUploadedAsset);
560
560
  const OrganizationMetadataRecord = Schema.Record(Schema.String, Schema.Json);
561
- const normalizeOrganizationMetadata = (metadata) => Schema.encodeUnknownEffect(Schema.UnknownFromJsonString)(metadata).pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.fromJsonString(OrganizationMetadataRecord))));
561
+ const normalizeOrganizationMetadata = (metadata) => Schema.decodeUnknownEffect(Schema.fromJsonString(OrganizationMetadataRecord))(metadata);
562
562
  const uploadImageAsset = (file, m, uploadImage) => {
563
563
  const payload = new FormData();
564
564
  payload.append("file", file);
@@ -1033,11 +1033,11 @@ function UserInvitationsManager({ baseUrl, invitations, loading, error, activeOr
1033
1033
  setActingInvitationId(null);
1034
1034
  }
1035
1035
  };
1036
- return (_jsxs("section", { className: "flex min-w-0 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("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: userInvitationColumns({
1036
+ return (_jsxs("section", { className: "flex min-w-0 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("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columnDefs: userInvitationColumns({
1037
1037
  baseUrl,
1038
1038
  m,
1039
1039
  now: invitationNow,
1040
- }), data: invitations, features: {
1040
+ }), rowData: invitations, features: {
1041
1041
  export: { baseName: "organization-invitations" },
1042
1042
  gallery: false,
1043
1043
  rowActions: {
@@ -1049,7 +1049,7 @@ function UserInvitationsManager({ baseUrl, invitations, loading, error, activeOr
1049
1049
  onReject: rejectInvitation,
1050
1050
  }),
1051
1051
  },
1052
- }, searchState: "local", state: {
1052
+ }, status: {
1053
1053
  empty: loading
1054
1054
  ? m.user_loading()
1055
1055
  : m.organization_user_invitations_empty(),
@@ -1058,24 +1058,24 @@ function UserInvitationsManager({ baseUrl, invitations, loading, error, activeOr
1058
1058
  }
1059
1059
  const userInvitationColumns = ({ baseUrl, m, now, }) => [
1060
1060
  {
1061
- accessorKey: "organizationName",
1062
- header: m.organization_invitation_organization(),
1063
- cell: ({ row }) => (_jsx(InvitationOrganizationBrand, { baseUrl: baseUrl, invitation: row.original })),
1061
+ field: "organizationName",
1062
+ headerName: m.organization_invitation_organization(),
1063
+ cellRenderer: ({ data }) => (_jsx(InvitationOrganizationBrand, { baseUrl: baseUrl, invitation: data })),
1064
1064
  },
1065
1065
  {
1066
- accessorKey: "role",
1067
- header: m.organization_member_role(),
1068
- cell: ({ row }) => (_jsx(Badge, { variant: "secondary", children: organizationRoleLabel(row.original.role, m) })),
1066
+ field: "role",
1067
+ headerName: m.organization_member_role(),
1068
+ cellRenderer: ({ data }) => (_jsx(Badge, { variant: "secondary", children: organizationRoleLabel(data.role, m) })),
1069
1069
  },
1070
1070
  {
1071
- accessorKey: "status",
1072
- header: m.organization_invitation_status(),
1073
- cell: ({ row }) => (_jsx(Badge, { variant: isInvitationExpired(row.original, now) ? "destructive" : "default", children: invitationStatusLabel(invitationDisplayStatus(row.original, now), m) })),
1071
+ field: "status",
1072
+ headerName: m.organization_invitation_status(),
1073
+ cellRenderer: ({ data }) => (_jsx(Badge, { variant: isInvitationExpired(data, now) ? "destructive" : "default", children: invitationStatusLabel(invitationDisplayStatus(data, now), m) })),
1074
1074
  },
1075
1075
  {
1076
- accessorKey: "expiresAt",
1077
- header: m.organization_invitation_expires(),
1078
- cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.expiresAt) })),
1076
+ field: "expiresAt",
1077
+ headerName: m.organization_invitation_expires(),
1078
+ cellRenderer: ({ data }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(data.expiresAt) })),
1079
1079
  },
1080
1080
  ];
1081
1081
  function InvitationOrganizationBrand({ baseUrl, invitation, }) {
@@ -1112,6 +1112,7 @@ function EditOrganizationSection({ baseUrl, editingLocale, organization, onUpdat
1112
1112
  const [defaultLocale] = useState(currentOrganizationLocale);
1113
1113
  const defaultValues = organizationFormDefaults(organization, baseUrl);
1114
1114
  const [form] = useState(() => FormReact.make(organizationFormBuilder, {
1115
+ runtime: authClientApi(baseUrl).runtime,
1115
1116
  fields: organizationFormFields,
1116
1117
  onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
1117
1118
  const name = organizationNameFromForm(value, defaultLocale);
@@ -1174,6 +1175,7 @@ function CreateOrganizationSection({ baseUrl, editingLocale, organizations, onCr
1174
1175
  const [defaultLocale] = useState(currentOrganizationLocale);
1175
1176
  const defaultValues = organizationFormDefaults(undefined, baseUrl);
1176
1177
  const [form] = useState(() => FormReact.make(organizationFormBuilder, {
1178
+ runtime: authClientApi(baseUrl).runtime,
1177
1179
  fields: organizationFormFields,
1178
1180
  onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
1179
1181
  const name = organizationNameFromForm(value, defaultLocale);
@@ -1328,6 +1330,7 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
1328
1330
  });
1329
1331
  }, [currentInvitations, currentMembers]);
1330
1332
  const [inviteForm] = useState(() => FormReact.make(inviteMemberFormBuilder, {
1333
+ runtime: authClientApi(baseUrl).runtime,
1331
1334
  fields: {
1332
1335
  email: TextField,
1333
1336
  role: SelectField,
@@ -1441,12 +1444,12 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
1441
1444
  }, children: [_jsx(inviteForm.email, { label: m.organization_member_email(), placeholder: "teammate@example.com", type: "email", required: true }), _jsx(inviteForm.role, { label: m.organization_member_role(), options: organizationRoles.map((role) => ({
1442
1445
  label: organizationRoleLabel(role, m),
1443
1446
  value: role,
1444
- })) }), _jsx("div", { className: "self-end", children: _jsx(SubmitButton, { form: inviteForm }) }), _jsx(SubmitError, { result: inviteResult })] }) })) : null, !inviting && loadError ? (_jsx("p", { className: "text-destructive text-sm", children: loadError })) : null, !inviting && error ? (_jsx("p", { className: "text-destructive text-sm", children: error })) : null, !inviting ? (_jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_members_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_members_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: memberColumns({
1447
+ })) }), _jsx("div", { className: "self-end", children: _jsx(SubmitButton, { form: inviteForm }) }), _jsx(SubmitError, { result: inviteResult })] }) })) : null, !inviting && loadError ? (_jsx("p", { className: "text-destructive text-sm", children: loadError })) : null, !inviting && error ? (_jsx("p", { className: "text-destructive text-sm", children: error })) : null, !inviting ? (_jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_members_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_members_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columnDefs: memberColumns({
1445
1448
  m,
1446
1449
  baseUrl,
1447
1450
  canChangeRoles: canManageMembers,
1448
1451
  onRoleChange: updateRole,
1449
- }), data: displayedMembers, features: {
1452
+ }), rowData: displayedMembers, features: {
1450
1453
  export: { baseName: `${organization.slug}-members` },
1451
1454
  gallery: false,
1452
1455
  rowActions: {
@@ -1459,10 +1462,10 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
1459
1462
  onRemove: removeMember,
1460
1463
  }),
1461
1464
  },
1462
- }, searchState: "local", state: { empty: m.organization_members_empty(), loading } }) })] })) : null, !inviting ? (_jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_invitations_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invitations_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: invitationColumns({
1465
+ }, status: { empty: m.organization_members_empty(), loading } }) })] })) : null, !inviting ? (_jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_invitations_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invitations_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columnDefs: invitationColumns({
1463
1466
  m,
1464
1467
  now: invitationNow,
1465
- }), data: invitations, features: {
1468
+ }), rowData: invitations, features: {
1466
1469
  export: { baseName: `${organization.slug}-invitations` },
1467
1470
  gallery: false,
1468
1471
  rowActions: {
@@ -1472,22 +1475,22 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
1472
1475
  onCancel: cancelInvitation,
1473
1476
  }),
1474
1477
  },
1475
- }, searchState: "local", state: { empty: m.organization_invitations_empty(), loading } }) })] })) : null] })] }));
1478
+ }, status: { empty: m.organization_invitations_empty(), loading } }) })] })) : null] })] }));
1476
1479
  }
1477
1480
  const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
1478
1481
  {
1479
- id: "user",
1480
- header: m.organization_member_user(),
1481
- cell: ({ row }) => {
1482
- const image = assetUrl(row.original.user.image, baseUrl);
1483
- return (_jsx(AppBrand, { to: null, label: row.original.user.name, subtitle: row.original.user.email, icon: UserIcon, className: "min-w-0", ...(image ? { imageSrc: image } : {}) }));
1482
+ colId: "user",
1483
+ headerName: m.organization_member_user(),
1484
+ cellRenderer: ({ data }) => {
1485
+ const image = assetUrl(data.user.image, baseUrl);
1486
+ return (_jsx(AppBrand, { to: null, label: data.user.name, subtitle: data.user.email, icon: UserIcon, className: "min-w-0", ...(image ? { imageSrc: image } : {}) }));
1484
1487
  },
1485
1488
  },
1486
1489
  {
1487
- accessorKey: "role",
1488
- header: m.organization_member_role(),
1489
- cell: ({ row }) => {
1490
- const member = row.original;
1490
+ field: "role",
1491
+ headerName: m.organization_member_role(),
1492
+ cellRenderer: ({ data }) => {
1493
+ const member = data;
1491
1494
  const roles = normalizeOrganizationRoles(member.role);
1492
1495
  const roleOptions = roles.map((role) => ({
1493
1496
  label: organizationRoleLabel(role, m),
@@ -1512,9 +1515,9 @@ const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
1512
1515
  },
1513
1516
  },
1514
1517
  {
1515
- accessorKey: "createdAt",
1516
- header: m.organization_member_joined(),
1517
- cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.createdAt) })),
1518
+ field: "createdAt",
1519
+ headerName: m.organization_member_joined(),
1520
+ cellRenderer: ({ data }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(data.createdAt) })),
1518
1521
  },
1519
1522
  ];
1520
1523
  const memberRowActions = ({ m, canRemoveMembers, currentUserId, leavingOrganization, onLeave, onRemove, }) => [
@@ -1537,24 +1540,24 @@ const memberRowActions = ({ m, canRemoveMembers, currentUserId, leavingOrganizat
1537
1540
  ];
1538
1541
  const invitationColumns = ({ m, now, }) => [
1539
1542
  {
1540
- accessorKey: "email",
1541
- header: m.organization_member_email(),
1542
- cell: ({ row }) => (_jsx("p", { className: "truncate font-medium", children: row.original.email })),
1543
+ field: "email",
1544
+ headerName: m.organization_member_email(),
1545
+ cellRenderer: ({ data }) => (_jsx("p", { className: "truncate font-medium", children: data.email })),
1543
1546
  },
1544
1547
  {
1545
- accessorKey: "role",
1546
- header: m.organization_member_role(),
1547
- cell: ({ row }) => (_jsx(Badge, { variant: "secondary", children: organizationRoleLabel(row.original.role, m) })),
1548
+ field: "role",
1549
+ headerName: m.organization_member_role(),
1550
+ cellRenderer: ({ data }) => (_jsx(Badge, { variant: "secondary", children: organizationRoleLabel(data.role, m) })),
1548
1551
  },
1549
1552
  {
1550
- accessorKey: "status",
1551
- header: m.organization_invitation_status(),
1552
- cell: ({ row }) => (_jsx(Badge, { variant: isInvitationExpired(row.original, now) ? "destructive" : "default", children: invitationStatusLabel(invitationDisplayStatus(row.original, now), m) })),
1553
+ field: "status",
1554
+ headerName: m.organization_invitation_status(),
1555
+ cellRenderer: ({ data }) => (_jsx(Badge, { variant: isInvitationExpired(data, now) ? "destructive" : "default", children: invitationStatusLabel(invitationDisplayStatus(data, now), m) })),
1553
1556
  },
1554
1557
  {
1555
- accessorKey: "expiresAt",
1556
- header: m.organization_invitation_expires(),
1557
- cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.expiresAt) })),
1558
+ field: "expiresAt",
1559
+ headerName: m.organization_invitation_expires(),
1560
+ cellRenderer: ({ data }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(data.expiresAt) })),
1558
1561
  },
1559
1562
  ];
1560
1563
  const invitationRowActions = ({ m, cancellingInvitationId, onCancel, }) => [
@@ -1596,6 +1599,7 @@ function OrganizationApiKeyManager({ baseUrl, organization, active, permissionLa
1596
1599
  });
1597
1600
  const loading = keysResult._tag === "Initial";
1598
1601
  const [createForm] = useState(() => FormReact.make(apiKeyFormBuilder, {
1602
+ runtime: authClientApi(baseUrl).runtime,
1599
1603
  fields: { name: TextField, referrers: TextAreaField },
1600
1604
  onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
1601
1605
  yield* Effect.sync(() => setCreatedKey(null));
@@ -1669,7 +1673,7 @@ function OrganizationApiKeyManager({ baseUrl, organization, active, permissionLa
1669
1673
  }, children: [_jsx(createForm.name, { label: m.user_api_key_name(), required: true }), _jsx(createForm.referrers, { label: m.user_api_key_referrers(), description: m.user_api_key_referrers_description(), placeholder: m.user_api_key_referrers_placeholder(), rows: 3 }), _jsx(ApiKeyPermissions, { description: m.user_api_key_permissions_description(), idPrefix: "organization-create", permissions: permissions, labels: permissionLabels, selected: selectedPermissions, title: m.user_api_key_permissions(), onChange: togglePermission }), _jsx(SubmitError, { result: createResult }), _jsx(SubmitButton, { form: createForm })] }) }) })) : null, creating && createdKey ? (_jsx("div", { className: "flex min-w-0 flex-col gap-3", children: _jsxs("div", { className: "bg-muted/50 flex min-w-0 items-center justify-between gap-3 rounded-md border px-3 py-2", children: [_jsx("code", { className: "block min-w-0 flex-1 overflow-x-auto text-sm whitespace-nowrap", children: createdKey }), _jsx(CopyButton, { className: "shrink-0", messages: {
1670
1674
  copied: m.user_api_key_copied(),
1671
1675
  copy: m.user_api_key_copy(),
1672
- }, 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: {
1676
+ }, 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, { columnDefs: apiKeyColumns({ m }), rowData: keys, features: {
1673
1677
  export: { baseName: `${organization.slug}-api-keys` },
1674
1678
  gallery: false,
1675
1679
  rowActions: {
@@ -1679,7 +1683,7 @@ function OrganizationApiKeyManager({ baseUrl, organization, active, permissionLa
1679
1683
  onEdit: (key) => setEditingKey(key),
1680
1684
  }),
1681
1685
  },
1682
- }, searchState: "local", state: {
1686
+ }, status: {
1683
1687
  empty: loading ? m.user_loading() : m.table_empty(),
1684
1688
  loading,
1685
1689
  } }) })) : null, editingKey ? (_jsx(OrganizationApiKeyEditForm, { baseUrl: baseUrl, keyData: editingKey, permissions: permissions, permissionLabels: permissionLabels, messages: {
@@ -1716,6 +1720,7 @@ function OrganizationApiKeyEditForm({ baseUrl, keyData, messages, permissions, p
1716
1720
  permissionOptionsRef.current = permissionOptions;
1717
1721
  permissionsRef.current = permissions;
1718
1722
  const [form] = useState(() => FormReact.make(editApiKeyFormBuilder, {
1723
+ runtime: authClientApi(baseUrl).runtime,
1719
1724
  fields: {
1720
1725
  name: TextField,
1721
1726
  enabled: CheckboxField,
@@ -1769,39 +1774,37 @@ function OrganizationApiKeyEditForm({ baseUrl, keyData, messages, permissions, p
1769
1774
  }
1770
1775
  const apiKeyColumns = ({ m, }) => [
1771
1776
  {
1772
- accessorKey: "name",
1773
- header: m.user_api_key_name(),
1774
- cell: ({ row }) => (_jsxs("div", { className: "min-w-0", children: [_jsx("p", { className: "truncate font-medium", children: row.original.name }), _jsx("p", { className: "text-muted-foreground text-sm", children: row.original.start
1775
- ? m.user_api_key_starts_with({ start: row.original.start })
1777
+ field: "name",
1778
+ headerName: m.user_api_key_name(),
1779
+ cellRenderer: ({ data }) => (_jsxs("div", { className: "min-w-0", children: [_jsx("p", { className: "truncate font-medium", children: data.name }), _jsx("p", { className: "text-muted-foreground text-sm", children: data.start
1780
+ ? m.user_api_key_starts_with({ start: data.start })
1776
1781
  : m.user_api_key_hidden() })] })),
1777
1782
  },
1778
1783
  {
1779
- accessorKey: "enabled",
1780
- header: m.user_api_key_status(),
1781
- cell: ({ row }) => (_jsx(Badge, { variant: row.original.enabled ? "default" : "secondary", children: row.original.enabled
1782
- ? m.user_api_key_enabled()
1783
- : m.user_api_key_disabled() })),
1784
+ field: "enabled",
1785
+ headerName: m.user_api_key_status(),
1786
+ cellRenderer: ({ data }) => (_jsx(Badge, { variant: data.enabled ? "default" : "secondary", children: data.enabled ? m.user_api_key_enabled() : m.user_api_key_disabled() })),
1784
1787
  },
1785
1788
  {
1786
- id: "permissions",
1787
- accessorFn: (keyData) => keyData.permissions,
1788
- header: m.user_api_key_permissions(),
1789
- cell: ({ row }) => {
1790
- const values = organizationApiKeyFormattedPermissions(row.original.permissions);
1789
+ colId: "permissions",
1790
+ valueGetter: ({ data }) => data.permissions,
1791
+ headerName: m.user_api_key_permissions(),
1792
+ cellRenderer: ({ data }) => {
1793
+ const values = organizationApiKeyFormattedPermissions(data.permissions);
1791
1794
  return values.length > 0 ? (_jsx("div", { className: "flex flex-wrap gap-1", children: values.map((value) => (_jsx(Badge, { variant: "outline", children: value }, value))) })) : (_jsx("span", { className: "text-muted-foreground text-sm", children: m.user_api_key_no_permissions() }));
1792
1795
  },
1793
1796
  },
1794
1797
  {
1795
- id: "referrers",
1796
- accessorFn: (keyData) => keyData.metadata,
1797
- header: m.user_api_key_referrers_column(),
1798
- cell: ({ row }) => (_jsx(ApiKeyReferrers, { metadata: row.original.metadata, unrestrictedLabel: m.user_api_key_referrers_any() })),
1798
+ colId: "referrers",
1799
+ valueGetter: ({ data }) => data.metadata,
1800
+ headerName: m.user_api_key_referrers_column(),
1801
+ cellRenderer: ({ data }) => (_jsx(ApiKeyReferrers, { metadata: data.metadata, unrestrictedLabel: m.user_api_key_referrers_any() })),
1799
1802
  },
1800
1803
  {
1801
- id: "rateLimit",
1802
- accessorFn: apiKeyUsagePercent,
1803
- header: m.user_api_key_rate_limit(),
1804
- cell: ({ row }) => (_jsx(ApiKeyRateLimit, { keyData: row.original, messages: {
1804
+ colId: "rateLimit",
1805
+ valueGetter: ({ data }) => apiKeyUsagePercent(data),
1806
+ headerName: m.user_api_key_rate_limit(),
1807
+ cellRenderer: ({ data }) => (_jsx(ApiKeyRateLimit, { keyData: data, messages: {
1805
1808
  disabled: m.user_api_key_disabled(),
1806
1809
  none: m.user_api_key_window_none(),
1807
1810
  unlimited: m.user_api_key_unlimited(),
@@ -348,10 +348,10 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
348
348
  const refreshAccounts = shouldLoadAccounts
349
349
  ? refreshLoadedAccounts
350
350
  : refreshEmptyAccounts;
351
- const [signOutAction] = useState(() => Atom.fn(({ baseUrl, redirectUrl, }) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.signOut()), Effect.tap(() => Effect.sync(notifyAuthChange)), Effect.flatMap(() => Effect.tryPromise(() => navigate({ href: redirectUrl }))))));
351
+ const [signOutAction] = useState(() => authClientApi(resolvedBaseUrl).runtime.fn(({ baseUrl, redirectUrl, }) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.signOut()), Effect.tap(() => Effect.sync(notifyAuthChange)), Effect.flatMap(() => Effect.tryPromise(() => navigate({ href: redirectUrl }))))));
352
352
  const signOut = useAtomSet(signOutAction);
353
353
  const signOutResult = useAtomValue(signOutAction);
354
- const [stopImpersonatingAction] = useState(() => Atom.fn((input) => Effect.gen(function* () {
354
+ const [stopImpersonatingAction] = useState(() => authClientApi(resolvedBaseUrl).runtime.fn((input) => Effect.gen(function* () {
355
355
  setIsStoppingImpersonation(true);
356
356
  yield* authHttpClient(input.baseUrl).pipe(Effect.flatMap((client) => client.auth.adminStopImpersonating()), Effect.tap(() => Effect.sync(notifyAuthChange)), Effect.tap(() => Effect.sync(input.refreshSession)), Effect.flatMap(() => Effect.tryPromise(() => navigate({ href: input.currentSiteHref }))), Effect.ensuring(Effect.sync(() => setIsStoppingImpersonation(false))));
357
357
  })));
@@ -450,7 +450,7 @@ function ConnectedAccounts({ baseUrl, accountCache, googleEnabled, currentSiteHr
450
450
  const [error, setError] = useState(null);
451
451
  const [isLinking, setIsLinking] = useState(false);
452
452
  const [revokingAccount, setRevokingAccount] = useState(null);
453
- const [linkGoogleAction] = useState(() => Atom.fn((input) => Effect.gen(function* () {
453
+ const [linkGoogleAction] = useState(() => authClientApi(baseUrl).runtime.fn((input) => Effect.gen(function* () {
454
454
  setError(null);
455
455
  setIsLinking(true);
456
456
  const client = yield* authHttpClient(input.baseUrl);
@@ -527,6 +527,7 @@ function ChangePasswordForm({ baseUrl }) {
527
527
  const [saved, setSaved] = useState(false);
528
528
  let reset = () => { };
529
529
  const [form] = useState(() => FormReact.make(changePasswordFormBuilder, {
530
+ runtime: authClientApi(baseUrl).runtime,
530
531
  fields: { currentPassword: TextField, newPassword: TextField },
531
532
  mode: { validation: "onSubmit" },
532
533
  onSubmit: (_, { decoded }) => authHttpClient(baseUrl).pipe(Effect.tap(() => Effect.sync(() => setSaved(false))), Effect.flatMap((client) => client.auth.changePassword({
@@ -551,6 +552,7 @@ function SetPasswordForm({ baseUrl, onSaved, }) {
551
552
  const m = useUserButtonMessages();
552
553
  let reset = () => { };
553
554
  const [form] = useState(() => FormReact.make(passwordFormBuilder(true), {
555
+ runtime: authClientApi(baseUrl).runtime,
554
556
  fields: { password: TextField },
555
557
  mode: { validation: "onSubmit" },
556
558
  onSubmit: (_, { decoded }) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.authExtra.setPassword({
@@ -571,6 +573,7 @@ function SetPasswordForm({ baseUrl, onSaved, }) {
571
573
  function RevokeAccountForm({ baseUrl, account, requirePassword, onCancel, onRevoke, }) {
572
574
  const m = useUserButtonMessages();
573
575
  const [form] = useState(() => FormReact.make(passwordFormBuilder(requirePassword), {
576
+ runtime: authClientApi(baseUrl).runtime,
574
577
  fields: { password: TextField },
575
578
  mode: { validation: "onSubmit" },
576
579
  onSubmit: (_, { decoded }) => Effect.gen(function* () {
@@ -655,6 +658,7 @@ function AccountSecuritySettings({ baseUrl, accountCache, }) {
655
658
  function EnableTotpForm({ baseUrl, requirePassword, onEnabled, }) {
656
659
  const m = useUserButtonMessages();
657
660
  const [form] = useState(() => FormReact.make(passwordFormBuilder(requirePassword), {
661
+ runtime: authClientApi(baseUrl).runtime,
658
662
  fields: { password: TextField },
659
663
  mode: { validation: "onSubmit" },
660
664
  onSubmit: (_, { decoded }) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.twoFactorEnable({
@@ -677,6 +681,7 @@ function EnableTotpForm({ baseUrl, requirePassword, onEnabled, }) {
677
681
  function VerifyTotpSetup({ baseUrl, setup, onVerified, }) {
678
682
  const m = useUserButtonMessages();
679
683
  const [form] = useState(() => FormReact.make(totpCodeFormBuilder, {
684
+ runtime: authClientApi(baseUrl).runtime,
680
685
  fields: { code: TextField },
681
686
  mode: { validation: "onSubmit" },
682
687
  onSubmit: (_, { decoded }) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.twoFactorVerifyTotp({
@@ -696,6 +701,7 @@ function VerifyTotpSetup({ baseUrl, setup, onVerified, }) {
696
701
  function DisableTotpForm({ baseUrl, requirePassword, onDisabled, }) {
697
702
  const m = useUserButtonMessages();
698
703
  const [form] = useState(() => FormReact.make(passwordFormBuilder(requirePassword), {
704
+ runtime: authClientApi(baseUrl).runtime,
699
705
  fields: { password: TextField },
700
706
  mode: { validation: "onSubmit" },
701
707
  onSubmit: (_, { decoded }) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.twoFactorDisable({
@@ -743,6 +749,7 @@ function ApiKeyManager({ baseUrl, active, permissionLabels, permissions = {}, })
743
749
  permissionOptionsRef.current = permissionOptions;
744
750
  selectedPermissionsRef.current = selectedPermissions;
745
751
  const [createForm] = useState(() => FormReact.make(apiKeyFormBuilder, {
752
+ runtime: authClientApi(baseUrl).runtime,
746
753
  fields: { name: TextField, referrers: TextAreaField },
747
754
  mode: { validation: "onSubmit" },
748
755
  onSubmit: (_, { decoded }) => Effect.gen(function* () {
@@ -775,7 +782,7 @@ function ApiKeyManager({ baseUrl, active, permissionLabels, permissions = {}, })
775
782
  const togglePermission = (id, checked) => {
776
783
  setSelectedPermissions((current) => ({ ...current, [id]: checked }));
777
784
  };
778
- const [deleteKeyAction] = useState(() => Atom.fn((key) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.apiKeyDelete({
785
+ const [deleteKeyAction] = useState(() => authClientApi(baseUrl).runtime.fn((key) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.apiKeyDelete({
779
786
  payload: { configId: "user", keyId: key.id },
780
787
  })), Effect.tap(() => Effect.sync(refreshKeys)), Effect.catch((cause) => Effect.sync(() => setError(cause instanceof Error && cause.message
781
788
  ? cause.message
@@ -807,7 +814,7 @@ function ApiKeyManager({ baseUrl, active, permissionLabels, permissions = {}, })
807
814
  }, children: [_jsx(createForm.name, { label: m.user_api_key_name(), required: true }), _jsx(createForm.referrers, { label: m.user_api_key_referrers(), description: m.user_api_key_referrers_description(), placeholder: m.user_api_key_referrers_placeholder(), rows: 3 }), _jsx(ApiKeyPermissions, { description: m.user_api_key_permissions_description(), idPrefix: "user-create", permissions: permissions, labels: permissionLabels, selected: selectedPermissions, title: m.user_api_key_permissions(), onChange: togglePermission }), _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: {
808
815
  copied: m.user_api_key_copied(),
809
816
  copy: m.user_api_key_copy(),
810
- }, 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: {
817
+ }, 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, { columnDefs: apiKeyColumns({ m }), rowData: keys, features: {
811
818
  export: { baseName: m.user_api_keys_export_file_name() },
812
819
  gallery: false,
813
820
  rowActions: {
@@ -817,7 +824,7 @@ function ApiKeyManager({ baseUrl, active, permissionLabels, permissions = {}, })
817
824
  onEdit: (key) => setEditingKey(key),
818
825
  }),
819
826
  },
820
- }, searchState: "local", state: {
827
+ }, status: {
821
828
  empty: loading ? m.user_loading() : m.table_empty(),
822
829
  loading,
823
830
  } }) })) : null, editingKey ? (_jsx(ApiKeyEditForm, { baseUrl: baseUrl, configId: "user", keyData: editingKey, permissions: permissions, permissionLabels: permissionLabels, messages: {
@@ -837,28 +844,26 @@ function ApiKeyManager({ baseUrl, active, permissionLabels, permissions = {}, })
837
844
  }
838
845
  const apiKeyColumns = ({ m, }) => [
839
846
  {
840
- accessorKey: "name",
841
- header: m.user_api_key_name(),
842
- cell: ({ row }) => (_jsx("div", { className: "min-w-0", children: _jsx("p", { className: "truncate font-medium", children: row.original.name ?? m.user_api_key_hidden() }) })),
847
+ field: "name",
848
+ headerName: m.user_api_key_name(),
849
+ cellRenderer: ({ data }) => (_jsx("div", { className: "min-w-0", children: _jsx("p", { className: "truncate font-medium", children: data.name ?? m.user_api_key_hidden() }) })),
843
850
  },
844
851
  {
845
- accessorKey: "enabled",
846
- header: m.user_api_key_status(),
847
- cell: ({ row }) => (_jsx(Badge, { variant: row.original.enabled ? "default" : "secondary", children: row.original.enabled
848
- ? m.user_api_key_enabled()
849
- : m.user_api_key_disabled() })),
852
+ field: "enabled",
853
+ headerName: m.user_api_key_status(),
854
+ cellRenderer: ({ data }) => (_jsx(Badge, { variant: data.enabled ? "default" : "secondary", children: data.enabled ? m.user_api_key_enabled() : m.user_api_key_disabled() })),
850
855
  },
851
856
  {
852
- id: "referrers",
853
- accessorFn: (keyData) => keyData.metadata,
854
- header: m.user_api_key_referrers_column(),
855
- cell: ({ row }) => (_jsx(ApiKeyReferrers, { metadata: row.original.metadata, unrestrictedLabel: m.user_api_key_referrers_any() })),
857
+ colId: "referrers",
858
+ valueGetter: ({ data }) => data.metadata,
859
+ headerName: m.user_api_key_referrers_column(),
860
+ cellRenderer: ({ data }) => (_jsx(ApiKeyReferrers, { metadata: data.metadata, unrestrictedLabel: m.user_api_key_referrers_any() })),
856
861
  },
857
862
  {
858
- id: "rateLimit",
859
- accessorFn: apiKeyUsagePercent,
860
- header: m.user_api_key_rate_limit(),
861
- cell: ({ row }) => (_jsx(ApiKeyRateLimit, { keyData: row.original, messages: {
863
+ colId: "rateLimit",
864
+ valueGetter: ({ data }) => apiKeyUsagePercent(data),
865
+ headerName: m.user_api_key_rate_limit(),
866
+ cellRenderer: ({ data }) => (_jsx(ApiKeyRateLimit, { keyData: data, messages: {
862
867
  disabled: m.user_api_key_disabled(),
863
868
  none: m.user_api_key_window_none(),
864
869
  unlimited: m.user_api_key_unlimited(),
@@ -870,10 +875,10 @@ const apiKeyColumns = ({ m, }) => [
870
875
  } })),
871
876
  },
872
877
  {
873
- accessorKey: "permissions",
874
- header: m.user_api_key_permissions(),
875
- cell: ({ row }) => {
876
- const permissions = formatPermissions(row.original.permissions);
878
+ field: "permissions",
879
+ headerName: m.user_api_key_permissions(),
880
+ cellRenderer: ({ data }) => {
881
+ const permissions = formatPermissions(data.permissions);
877
882
  if (permissions.length === 0) {
878
883
  return (_jsx("span", { className: "text-muted-foreground text-sm", children: m.user_api_key_no_permissions() }));
879
884
  }