@krak-stack/auth 0.1.60 → 0.1.62

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.
@@ -28,6 +28,7 @@ const signupFormBuilder = FormBuilder.empty
28
28
  const verifyEmailFormBuilder = FormBuilder.empty
29
29
  .addField("email", Schema.String)
30
30
  .addField("otp", Schema.String);
31
+ const forgotPasswordFormBuilder = FormBuilder.empty.addField("email", Schema.String);
31
32
  const resetPasswordFormBuilder = FormBuilder.empty.addField("password", Schema.String);
32
33
  const twoFactorFormBuilder = FormBuilder.empty
33
34
  .addField("code", Schema.String)
@@ -42,6 +43,11 @@ const defaultMessages = {
42
43
  field_name: "Name",
43
44
  field_password: "Password",
44
45
  forgot_password_back_to_sign_in: "Back to sign in",
46
+ forgot_password_description: "Enter your email and we will send a reset link if an account exists.",
47
+ forgot_password_error: "Unable to send password reset email.",
48
+ forgot_password_submit: "Send reset link",
49
+ forgot_password_success: "If an account exists for that email, a reset link has been sent.",
50
+ forgot_password_title: "Reset password",
45
51
  oauth_client_no_auth_methods: "No authentication methods are enabled for this application.",
46
52
  reset_password_description: "Enter a new password for your account.",
47
53
  reset_password_error: "Unable to reset password.",
@@ -100,6 +106,11 @@ const defaultMessages = {
100
106
  field_name: "Nom",
101
107
  field_password: "Mot de passe",
102
108
  forgot_password_back_to_sign_in: "Retour à la connexion",
109
+ forgot_password_description: "Saisissez votre courriel et nous enverrons un lien de réinitialisation si un compte existe.",
110
+ forgot_password_error: "Impossible d'envoyer le courriel de réinitialisation.",
111
+ forgot_password_submit: "Envoyer le lien",
112
+ forgot_password_success: "Si un compte existe pour ce courriel, un lien de réinitialisation a été envoyé.",
113
+ forgot_password_title: "Réinitialiser le mot de passe",
103
114
  oauth_client_no_auth_methods: "Aucune méthode d'authentification n'est activée pour cette application.",
104
115
  reset_password_description: "Saisissez un nouveau mot de passe pour votre compte.",
105
116
  reset_password_error: "Impossible de réinitialiser le mot de passe.",
@@ -377,7 +388,7 @@ export function Signin(props) {
377
388
  method: selectedAuthMethod,
378
389
  otpSent: Boolean(otpSentTo),
379
390
  });
380
- }, children: [!emailSubmitted ? (_jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", required: true })) : null, emailSubmitted && selectedAuthMethod === "password" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.password, { label: m.field_password, type: "password", autoComplete: "current-password", required: true }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [_jsx(Link, { className: authLinkClassName, to: "/forgot-password", search: searchObject(searchString), children: m.sign_in_forgot_password }), canChangeAuthMethod ? (_jsxs(Button, { type: "button", variant: "link", className: "h-auto px-0", onClick: switchAuthMethod, children: [_jsx(Mail, {}), m.sign_in_use_email_otp] })) : null] })] })) : null, emailSubmitted && selectedAuthMethod === "emailOtp" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.otp, { label: m.sign_in_email_otp_code }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [otpSentTo ? (_jsx(Button, { type: "button", variant: "link", className: "h-auto px-0", disabled: emailOtpResendSeconds > 0, onClick: resendEmailOtp, children: emailOtpResendSeconds > 0
391
+ }, children: [!emailSubmitted ? (_jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", required: true })) : null, emailSubmitted && selectedAuthMethod === "password" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.password, { label: m.field_password, type: "password", autoComplete: "current-password", required: true }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [_jsx(Link, { className: authLinkClassName, to: "/reset-password", search: searchObject(searchString), children: m.sign_in_forgot_password }), canChangeAuthMethod ? (_jsxs(Button, { type: "button", variant: "link", className: "h-auto px-0", onClick: switchAuthMethod, children: [_jsx(Mail, {}), m.sign_in_use_email_otp] })) : null] })] })) : null, emailSubmitted && selectedAuthMethod === "emailOtp" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.otp, { label: m.sign_in_email_otp_code }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [otpSentTo ? (_jsx(Button, { type: "button", variant: "link", className: "h-auto px-0", disabled: emailOtpResendSeconds > 0, onClick: resendEmailOtp, children: emailOtpResendSeconds > 0
381
392
  ? text(m.sign_in_email_otp_resend_countdown, {
382
393
  seconds: String(emailOtpResendSeconds),
383
394
  })
@@ -508,21 +519,54 @@ export function VerifyEmail(props) {
508
519
  submit("verify");
509
520
  }, children: [_jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", required: true }), _jsx(form.otp, { label: m.verify_email_code }), _jsx(SubmitError, { result: submitResult }), resent ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.verify_email_resent })) : null, _jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [_jsxs(Button, { type: "submit", disabled: submitResult.waiting, children: [submitResult.waiting ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, effectFormMessages().submit] }), _jsx(Button, { type: "button", variant: "ghost", disabled: submitResult.waiting, onClick: resendCode, children: m.verify_email_resend })] })] }) }), _jsx("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: _jsx(Link, { className: authLinkClassName, to: "/sign-in", children: m.forgot_password_back_to_sign_in }) })] })] }));
510
521
  }
511
- export function ResetPassword(props) {
522
+ export function ForgotPassword(props) {
512
523
  const { authClient, labels: m } = useAuthFormOptions(props);
513
- const navigate = useNavigate();
514
524
  const searchString = useRouterState({
515
525
  select: (state) => state.location.searchStr,
516
526
  });
517
- const token = getSearchParam(searchString, "token") ?? "";
527
+ const [submitted, setSubmitted] = useState(false);
528
+ const [form] = useState(() => FormReact.make(forgotPasswordFormBuilder, {
529
+ fields: { email: TextField },
530
+ mode: { validation: "onSubmit" },
531
+ onSubmit: (_, { decoded: value }) => Effect.tryPromise({
532
+ try: async () => {
533
+ setSubmitted(false);
534
+ const result = await authClient.requestPasswordReset({
535
+ email: value.email.trim(),
536
+ redirectTo: `${window.location.origin}/reset-password`,
537
+ });
538
+ if (result.error) {
539
+ throw new Error(result.error.message ?? m.forgot_password_error);
540
+ }
541
+ setSubmitted(true);
542
+ },
543
+ catch: (cause) => cause instanceof Error ? cause : new Error(m.forgot_password_error),
544
+ }),
545
+ }));
546
+ const submit = useAtomSet(form.submit);
547
+ const submitResult = useAtomValue(form.submit);
548
+ return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.forgot_password_title }), _jsx(CardDescription, { children: m.forgot_password_description })] }), _jsxs(CardContent, { children: [_jsx(form.Initialize, { defaultValues: { email: "" }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
549
+ event.preventDefault();
550
+ event.stopPropagation();
551
+ submit();
552
+ }, children: [_jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", required: true }), _jsx(SubmitError, { result: submitResult }), submitted ? (_jsx("p", { className: "bg-card text-card-foreground rounded-lg border px-4 py-3 text-sm shadow-xs", children: m.forgot_password_success })) : null, _jsxs(Button, { type: "submit", disabled: submitResult.waiting, children: [submitResult.waiting ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, m.forgot_password_submit] })] }) }), _jsx("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: _jsx(Link, { className: authLinkClassName, to: "/sign-in", search: searchObject(searchString), children: m.forgot_password_back_to_sign_in }) })] })] }));
553
+ }
554
+ export function ResetPassword(props) {
555
+ const searchString = useRouterState({
556
+ select: (state) => state.location.searchStr,
557
+ });
558
+ const token = getSearchParam(searchString, "token");
559
+ return token ? (_jsx(ResetPasswordForm, { ...props, token: token })) : (_jsx(ForgotPassword, { ...props }));
560
+ }
561
+ function ResetPasswordForm({ token, ...props }) {
562
+ const { authClient, labels: m } = useAuthFormOptions(props);
563
+ const navigate = useNavigate();
518
564
  const onSuccess = () => navigate({ to: "/sign-in" });
519
565
  const [form] = useState(() => FormReact.make(resetPasswordFormBuilder, {
520
566
  fields: { password: TextField },
521
567
  mode: { validation: "onSubmit" },
522
568
  onSubmit: (_, { decoded: value }) => Effect.tryPromise({
523
569
  try: async () => {
524
- if (!token)
525
- throw new Error(m.reset_password_missing_token);
526
570
  const result = await authClient.resetPassword({
527
571
  newPassword: value.password,
528
572
  token,
@@ -1,7 +1,7 @@
1
1
  import { type ReactNode } from "react";
2
2
  import { type AuthUiClient } from "./auth-client";
3
3
  import type { ExtraProjectPublicConfig } from "../extra/schema";
4
- import type { ProjectAccessCatalog } from "../access";
4
+ import type { ProjectAccessCatalog, ProjectAccessLabelCatalog } from "../access";
5
5
  export type KrakstackAuthLocale = "en" | "fr";
6
6
  export type KrakstackAuthProviderProps = {
7
7
  children: ReactNode;
@@ -10,6 +10,7 @@ export type KrakstackAuthProviderProps = {
10
10
  projectId?: string | null | undefined;
11
11
  authClient?: AuthUiClient | undefined;
12
12
  access?: ProjectAccessCatalog | undefined;
13
+ accessLabels?: ProjectAccessLabelCatalog | undefined;
13
14
  };
14
15
  export type KrakstackAuthContextValue = {
15
16
  locale: KrakstackAuthLocale;
@@ -18,10 +19,11 @@ export type KrakstackAuthContextValue = {
18
19
  authClient: AuthUiClient;
19
20
  projectConfig: ExtraProjectPublicConfig | null;
20
21
  access: ProjectAccessCatalog | null;
22
+ accessLabels: ProjectAccessLabelCatalog | null;
21
23
  authRefreshVersion: number;
22
24
  refreshAuth: () => void;
23
25
  };
24
- export declare function KrakstackAuthProvider({ children, locale, baseUrl, projectId, authClient, access, }: KrakstackAuthProviderProps): import("react").JSX.Element;
26
+ export declare function KrakstackAuthProvider({ children, locale, baseUrl, projectId, authClient, access, accessLabels, }: KrakstackAuthProviderProps): import("react").JSX.Element;
25
27
  export declare const useKrakstackAuth: () => KrakstackAuthContextValue | null;
26
28
  export declare const useAuthClient: () => AuthUiClient;
27
29
  export declare const useKrakstackAuthProjectConfig: () => import("effect/Schema").Struct.ReadonlySide<{
@@ -68,7 +68,7 @@ const useProjectConfig = (baseUrl, providedProjectId) => {
68
68
  }), { suspendOnWaiting: true });
69
69
  return result.value;
70
70
  };
71
- export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projectId, authClient, access, }) {
71
+ export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projectId, authClient, access, accessLabels, }) {
72
72
  const searchString = useRouterState({
73
73
  select: (state) => state.location.searchStr,
74
74
  });
@@ -89,6 +89,7 @@ export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projec
89
89
  projectId: resolvedProjectId,
90
90
  projectConfig,
91
91
  access: access ?? null,
92
+ accessLabels: accessLabels ?? null,
92
93
  authRefreshVersion,
93
94
  refreshAuth,
94
95
  }), [
@@ -98,6 +99,7 @@ export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projec
98
99
  resolvedProjectId,
99
100
  projectConfig,
100
101
  access,
102
+ accessLabels,
101
103
  authRefreshVersion,
102
104
  refreshAuth,
103
105
  ]);
@@ -3,14 +3,16 @@ export { createAuthUiClient } from "./auth-client";
3
3
  export { OrganizationSwitcher } from "./organization-switcher";
4
4
  export { MemberRequired } from "./member-required";
5
5
  export { HasPermission, useHasPermission } from "./has-permission";
6
- export { ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, } from "./auth-forms";
6
+ export { ProjectAccessMatrix } from "./project-access-matrix";
7
+ export { ForgotPassword, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, } from "./auth-forms";
7
8
  export { UserButton } from "./user-button";
8
9
  export { AdminOrganizationsTable } from "./admin-organizations";
9
10
  export { AdminOrganizationForm } from "./admin-organization-form";
10
11
  export { AdminUsersTable, useAdminUsersTotal } from "./admin-users";
11
12
  export { assetUrl } from "./utils";
12
- export { ApiKeyPermissionGrant, CurrentActor, Forbidden, all, actorUserId, any, defineProjectAccess, permission, policy, withPolicy, } from "../access";
13
- export type { ApiKeyOwner, ApiKeyActor, Actor, Policy, ProjectAccessConfig, ProjectAccessCatalog, ProjectAccessDefinition, UserActor, } from "../access";
13
+ export { ApiKeyPermissionGrant, CurrentActor, Forbidden, all, actorUserId, any, defineProjectAccess, defineProjectAccessLabels, permission, policy, withPolicy, } from "../access";
14
+ export type { ApiKeyOwner, ApiKeyActor, Actor, Policy, ProjectAccessConfig, ProjectAccessCatalog, ProjectAccessLabelCatalog, ProjectAccessDefinition, ProjectAccessLabels, UserActor, } from "../access";
15
+ export type { ProjectAccessMatrixAccess, ProjectAccessMatrixMessages, } from "./project-access-matrix";
14
16
  export type { KrakstackAuthContextValue, KrakstackAuthLocale, KrakstackAuthProviderProps, } from "./auth-provider";
15
17
  export type { OrganizationSwitcherDialog, OrganizationSwitcherFeatures, OrganizationSwitcherProps, } from "./organization-switcher";
16
18
  export type { UserButtonDialog } from "./user-button";
@@ -3,10 +3,11 @@ export { createAuthUiClient } from "./auth-client";
3
3
  export { OrganizationSwitcher } from "./organization-switcher";
4
4
  export { MemberRequired } from "./member-required";
5
5
  export { HasPermission, useHasPermission } from "./has-permission";
6
- export { ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, } from "./auth-forms";
6
+ export { ProjectAccessMatrix } from "./project-access-matrix";
7
+ export { ForgotPassword, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, } from "./auth-forms";
7
8
  export { UserButton } from "./user-button";
8
9
  export { AdminOrganizationsTable } from "./admin-organizations";
9
10
  export { AdminOrganizationForm } from "./admin-organization-form";
10
11
  export { AdminUsersTable, useAdminUsersTotal } from "./admin-users";
11
12
  export { assetUrl } from "./utils";
12
- export { ApiKeyPermissionGrant, CurrentActor, Forbidden, all, actorUserId, any, defineProjectAccess, permission, policy, withPolicy, } from "../access";
13
+ export { ApiKeyPermissionGrant, CurrentActor, Forbidden, all, actorUserId, any, defineProjectAccess, defineProjectAccessLabels, permission, policy, withPolicy, } from "../access";
@@ -15,7 +15,6 @@ import { Field, FieldLabel, FieldSet } from "@/components/ui/field";
15
15
  import { Input } from "@/components/ui/input";
16
16
  import { Badge } from "@/components/ui/badge";
17
17
  import { Button } from "@/components/ui/button";
18
- import { Checkbox } from "@/components/ui/checkbox";
19
18
  import { CopyButton } from "@/components/ui/copy-button";
20
19
  import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
21
20
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
@@ -27,6 +26,7 @@ import { authClientApi } from "./auth-client-api";
27
26
  import { useKrakstackAuth } from "./auth-provider";
28
27
  import { createApiKey, parseApiKeyReferrers } from "./api-key";
29
28
  import { ApiKeyEditForm } from "./api-key-edit-form";
29
+ import { ApiKeyPermissions } from "./api-key-permissions";
30
30
  import { ApiKeyRateLimit, apiKeyUsagePercent } from "./api-key-rate-limit";
31
31
  import { ApiKeyReferrers } from "./api-key-referrers";
32
32
  import { useOpenedOnce } from "./hooks";
@@ -954,8 +954,8 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
954
954
  onChange?.(null);
955
955
  } })) : null }) }), _jsx(Dialog, { open: dialog === "apiKeys" && canManageApiKeys, onOpenChange: (open) => {
956
956
  setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
957
- }, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: activeOrganization.data ? (_jsx(OrganizationApiKeyManager, { authClient: authClient, organization: activeOrganization.data, active: dialog === "apiKeys" && canManageApiKeys, permissions: apiKeyPermissions ??
958
- auth?.access?.organizationApiKeyPermissions ??
957
+ }, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: activeOrganization.data ? (_jsx(OrganizationApiKeyManager, { authClient: authClient, organization: activeOrganization.data, active: dialog === "apiKeys" && canManageApiKeys, permissionLabels: auth?.accessLabels ?? undefined, permissions: apiKeyPermissions ??
958
+ auth?.access?.apiKeyPermissions.organization ??
959
959
  {} })) : null }) }), _jsx(Dialog, { open: dialog === "invitations" && canViewOrganizationInvitations, onOpenChange: (open) => {
960
960
  setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
961
961
  }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }), _jsx(Separator, {}), _jsx(UserInvitationsManager, { authClient: authClient, baseUrl: baseUrl, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, ...(activeOrganization.data
@@ -1490,7 +1490,7 @@ const invitationRowActions = ({ m, cancellingInvitationId, onCancel, }) => [
1490
1490
  onClick: onCancel,
1491
1491
  },
1492
1492
  ];
1493
- function OrganizationApiKeyManager({ authClient, organization, active, permissions, }) {
1493
+ function OrganizationApiKeyManager({ authClient, organization, active, permissionLabels, permissions, }) {
1494
1494
  const m = useOrganizationMessages();
1495
1495
  const hasOpened = useOpenedOnce(active);
1496
1496
  const keysAtom = hasOpened
@@ -1587,7 +1587,7 @@ function OrganizationApiKeyManager({ authClient, organization, active, permissio
1587
1587
  event.preventDefault();
1588
1588
  event.stopPropagation();
1589
1589
  submitApiKey();
1590
- }, children: [_jsx(createForm.name, { label: m.user_api_key_name(), required: true }), _jsx(createForm.referrers, { label: m.user_api_key_referrers(), description: m.user_api_key_referrers_description(), placeholder: m.user_api_key_referrers_placeholder(), rows: 3 }), permissionOptions.length > 0 ? (_jsxs(FieldSet, { children: [_jsx("p", { className: "font-medium", children: m.user_api_key_permissions() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_api_key_permissions_description() }), _jsx("div", { className: "flex flex-col gap-3", children: permissionOptions.map((permission) => (_jsxs(Field, { orientation: "horizontal", children: [_jsx(Checkbox, { id: `organization-${permission.id}`, checked: selectedPermissions[permission.id] ?? false, onCheckedChange: (checked) => togglePermission(permission.id, checked) }), _jsxs(FieldLabel, { htmlFor: `organization-${permission.id}`, children: [permission.resource, ": ", permission.action] })] }, permission.id))) })] })) : null, _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: {
1590
+ }, 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: {
1591
1591
  copied: m.user_api_key_copied(),
1592
1592
  copy: m.user_api_key_copy(),
1593
1593
  }, 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: {
@@ -1603,7 +1603,7 @@ function OrganizationApiKeyManager({ authClient, organization, active, permissio
1603
1603
  }, searchState: "local", state: {
1604
1604
  empty: loading ? m.user_loading() : m.table_empty(),
1605
1605
  loading,
1606
- } }) })) : null, editingKey ? (_jsx(ApiKeyEditForm, { configId: "organization", keyData: editingKey, permissions: permissions, messages: {
1606
+ } }) })) : null, editingKey ? (_jsx(ApiKeyEditForm, { configId: "organization", keyData: editingKey, permissions: permissions, permissionLabels: permissionLabels, messages: {
1607
1607
  enabled: m.user_api_key_enabled(),
1608
1608
  name: m.user_api_key_name(),
1609
1609
  referrers: m.user_api_key_referrers(),
@@ -0,0 +1,26 @@
1
+ import type { ProjectAccessLabels } from "../access";
2
+ export type ProjectAccessMatrixAccess<Action extends string = string> = {
3
+ readonly actions: ReadonlyArray<Action>;
4
+ readonly apiKeys: {
5
+ readonly user: ReadonlyArray<Action>;
6
+ readonly organization: ReadonlyArray<Action>;
7
+ };
8
+ readonly project: string;
9
+ readonly roles: Readonly<Record<string, ReadonlyArray<Action> | undefined>>;
10
+ };
11
+ export type ProjectAccessMatrixMessages = {
12
+ action: string;
13
+ allowed: string;
14
+ apiKeyPermissions: string;
15
+ denied: string;
16
+ organizationKey: string;
17
+ resource: string;
18
+ rolePermissions: string;
19
+ userKey: string;
20
+ };
21
+ export declare const ProjectAccessMatrix: <Action extends string, Role extends string>({ access, labels, locale, messages: messageOverrides, }: {
22
+ access: ProjectAccessMatrixAccess<Action>;
23
+ labels?: ProjectAccessLabels<Action, Role>;
24
+ locale?: string;
25
+ messages?: Partial<ProjectAccessMatrixMessages>;
26
+ }) => import("react").JSX.Element;
@@ -0,0 +1,85 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Check, Minus } from "lucide-react";
3
+ const messages = {
4
+ en: {
5
+ action: "Action",
6
+ allowed: "Allowed",
7
+ apiKeyPermissions: "API-key assignable permissions",
8
+ denied: "Not allowed",
9
+ organizationKey: "Organization key",
10
+ resource: "Resource",
11
+ rolePermissions: "Role grants",
12
+ userKey: "User key",
13
+ },
14
+ fr: {
15
+ action: "Action",
16
+ allowed: "Autorisé",
17
+ apiKeyPermissions: "Autorisations attribuables aux clés API",
18
+ denied: "Non autorisé",
19
+ organizationKey: "Clé d’organisation",
20
+ resource: "Ressource",
21
+ rolePermissions: "Droits des rôles",
22
+ userKey: "Clé utilisateur",
23
+ },
24
+ };
25
+ export const ProjectAccessMatrix = ({ access, labels, locale = "en", messages: messageOverrides, }) => {
26
+ const language = locale === "fr" ? "fr" : "en";
27
+ const text = { ...messages[language], ...messageOverrides };
28
+ const roleLabel = (id) => {
29
+ const label = Object.entries(labels?.roles ?? {}).find(([role]) => role === id)?.[1];
30
+ return typeof label === "string" ? label : capitalizeFirst(id);
31
+ };
32
+ const roleColumns = Object.entries(access.roles).map(([id, permissions]) => ({
33
+ id,
34
+ label: roleLabel(id),
35
+ permissions: permissions ?? [],
36
+ }));
37
+ const keyColumns = [
38
+ {
39
+ id: "user",
40
+ label: text.userKey,
41
+ permissions: access.apiKeys.user,
42
+ },
43
+ {
44
+ id: "organization",
45
+ label: text.organizationKey,
46
+ permissions: access.apiKeys.organization,
47
+ },
48
+ ];
49
+ return (_jsxs("div", { className: "space-y-8", children: [_jsx(PermissionTable, { access: access, columns: roleColumns, labels: labels, text: text, title: text.rolePermissions }), _jsx(PermissionTable, { access: access, columns: keyColumns, labels: labels, text: text, title: text.apiKeyPermissions })] }));
50
+ };
51
+ const PermissionTable = ({ access, columns, labels, text, title, }) => (_jsxs("section", { className: "space-y-3", children: [_jsx("h3", { className: "text-lg font-semibold", children: title }), _jsx("div", { className: "overflow-x-auto rounded-lg border", children: _jsxs("table", { className: "w-full min-w-max border-collapse text-sm", children: [_jsx("thead", { className: "bg-muted/50", children: _jsxs("tr", { children: [_jsx("th", { className: "px-4 py-3 text-left font-medium", scope: "col", children: text.resource }), _jsx("th", { className: "px-4 py-3 text-left font-medium", scope: "col", children: text.action }), columns.map((column) => (_jsx("th", { className: "px-4 py-3 text-center font-medium", scope: "col", children: column.label }, column.id)))] }) }), _jsx("tbody", { children: access.actions.map((permission) => {
52
+ const { action, resource } = splitPermission(permission);
53
+ return (_jsxs("tr", { className: "border-t", children: [_jsxs("th", { className: "px-4 py-3 text-left font-normal", scope: "row", children: [_jsx("span", { children: permissionLabels(labels, resource, action).resource }), _jsx("code", { className: "text-muted-foreground ml-2 text-xs", children: resource })] }), _jsxs("td", { className: "px-4 py-3", children: [_jsx("span", { children: permissionLabels(labels, resource, action).action }), _jsx("code", { className: "text-muted-foreground ml-2 text-xs", children: action })] }), columns.map((column) => (_jsx(PermissionCell, { allowed: column.permissions.includes(permission), messages: text }, column.id)))] }, permission));
54
+ }) })] }) })] }));
55
+ const PermissionCell = ({ allowed, messages, }) => (_jsxs("td", { className: "px-4 py-3 text-center", children: [_jsx("span", { className: "sr-only", children: allowed ? messages.allowed : messages.denied }), allowed ? (_jsx(Check, { "aria-hidden": "true", className: "mx-auto size-4 text-emerald-600 dark:text-emerald-400" })) : (_jsx(Minus, { "aria-hidden": "true", className: "text-muted-foreground/60 mx-auto size-4" }))] }));
56
+ const splitPermission = (permission) => {
57
+ const separator = permission.indexOf(":");
58
+ return separator === -1
59
+ ? { resource: permission, action: permission }
60
+ : {
61
+ resource: permission.slice(0, separator),
62
+ action: permission.slice(separator + 1),
63
+ };
64
+ };
65
+ const capitalizeFirst = (value) => value.charAt(0).toUpperCase() + value.slice(1);
66
+ const permissionLabels = (labels, resource, action) => {
67
+ const group = Reflect.get(labels?.permissions ?? {}, resource);
68
+ if (typeof group !== "object" || group === null) {
69
+ return {
70
+ resource: capitalizeFirst(resource),
71
+ action: capitalizeFirst(action),
72
+ };
73
+ }
74
+ const resourceLabel = Reflect.get(group, "label");
75
+ const actions = Reflect.get(group, "actions");
76
+ const actionLabel = typeof actions === "object" && actions !== null
77
+ ? Reflect.get(actions, action)
78
+ : undefined;
79
+ return {
80
+ resource: typeof resourceLabel === "string"
81
+ ? resourceLabel
82
+ : capitalizeFirst(resource),
83
+ action: typeof actionLabel === "string" ? actionLabel : capitalizeFirst(action),
84
+ };
85
+ };
@@ -13,16 +13,15 @@ import { AppBrand } from "@/components/ui/app-brand";
13
13
  import { effectFormMessages, ImageField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@/components/ui/effect-form";
14
14
  import { Badge } from "@/components/ui/badge";
15
15
  import { Button } from "@/components/ui/button";
16
- import { Checkbox } from "@/components/ui/checkbox";
17
16
  import { CopyButton } from "@/components/ui/copy-button";
18
17
  import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
19
- import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLegend, FieldSet, } from "@/components/ui/field";
20
18
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
21
19
  import { Separator } from "@/components/ui/separator";
22
20
  import { authClientApi } from "./auth-client-api";
23
21
  import { useKrakstackAuth } from "./auth-provider";
24
22
  import { createApiKey, parseApiKeyReferrers } from "./api-key";
25
23
  import { ApiKeyEditForm } from "./api-key-edit-form";
24
+ import { ApiKeyPermissions } from "./api-key-permissions";
26
25
  import { ApiKeyRateLimit, apiKeyUsagePercent } from "./api-key-rate-limit";
27
26
  import { ApiKeyReferrers } from "./api-key-referrers";
28
27
  import { useOpenedOnce } from "./hooks";
@@ -434,7 +433,7 @@ export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRed
434
433
  setSettingsDialog((current) => open ? "security" : current === "security" ? null : current);
435
434
  }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_security_title() }), _jsx(DialogDescription, { children: m.user_security_description() })] }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(PasswordSettings, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache }), _jsx(Separator, {}), _jsx(AccountSecuritySettings, { authClient: authClient, accountCache: accountCache })] })] }) }), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "apiKeys", onOpenChange: (open) => {
436
435
  setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
437
- }, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: _jsx(ApiKeyManager, { authClient: authClient, active: settingsDialog === "apiKeys", permissions: apiKeyPermissions ?? auth?.access?.userApiKeyPermissions ?? {} }) }) }), isAdmin ? (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: settingsDialog === "adminUsers", onOpenChange: (open) => {
436
+ }, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: _jsx(ApiKeyManager, { authClient: authClient, active: settingsDialog === "apiKeys", permissionLabels: auth?.accessLabels ?? undefined, permissions: apiKeyPermissions ?? auth?.access?.apiKeyPermissions.user ?? {} }) }) }), isAdmin ? (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: settingsDialog === "adminUsers", onOpenChange: (open) => {
438
437
  setSettingsDialog((current) => open ? "adminUsers" : current === "adminUsers" ? null : current);
439
438
  }, 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) => {
440
439
  setSettingsDialog((current) => open
@@ -753,7 +752,7 @@ function DisableTotpForm({ authClient, requirePassword, onDisabled, }) {
753
752
  submit();
754
753
  }, children: [requirePassword ? (_jsx(form.password, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) : null, _jsx(SubmitError, { result: submitResult }), requirePassword ? (_jsx(SubmitButton, { form: form })) : (_jsxs(Button, { type: "button", disabled: submitResult.waiting, onClick: () => submit(), children: [submitResult.waiting ? (_jsx(Loader2, { "data-icon": "inline-start", className: "animate-spin" })) : null, effectFormMessages().submit] }))] }) }));
755
754
  }
756
- function ApiKeyManager({ authClient, active, permissions = {}, }) {
755
+ function ApiKeyManager({ authClient, active, permissionLabels, permissions = {}, }) {
757
756
  const m = useUserButtonMessages();
758
757
  const hasOpened = useOpenedOnce(active);
759
758
  const keysAtom = hasOpened ? userApiKeysAtom(authClient) : emptyApiKeysAtom;
@@ -842,7 +841,7 @@ function ApiKeyManager({ authClient, active, permissions = {}, }) {
842
841
  event.preventDefault();
843
842
  event.stopPropagation();
844
843
  submitCreateForm();
845
- }, children: [_jsx(createForm.name, { label: m.user_api_key_name(), required: true }), _jsx(createForm.referrers, { label: m.user_api_key_referrers(), description: m.user_api_key_referrers_description(), placeholder: m.user_api_key_referrers_placeholder(), rows: 3 }), permissionOptions.length > 0 ? (_jsxs(FieldSet, { children: [_jsx(FieldLegend, { children: m.user_api_key_permissions() }), _jsx(FieldDescription, { children: m.user_api_key_permissions_description() }), _jsx(FieldGroup, { "data-slot": "checkbox-group", className: "gap-3", children: permissionOptions.map((permission) => (_jsxs(Field, { orientation: "horizontal", children: [_jsx(Checkbox, { id: permission.id, checked: selectedPermissions[permission.id] ?? false, onCheckedChange: (checked) => togglePermission(permission.id, checked) }), _jsx(FieldContent, { children: _jsx(FieldLabel, { htmlFor: permission.id, children: permission.id }) })] }, permission.id))) })] })) : null, _jsx(SubmitError, { result: createSubmitResult }), _jsx(SubmitButton, { form: createForm })] }) }) })) : null, creating && createdKey ? (_jsx("div", { className: "flex min-w-0 flex-col gap-3", children: _jsxs("div", { className: "bg-muted/50 flex min-w-0 items-center justify-between gap-3 rounded-md border px-3 py-2", children: [_jsx("code", { className: "block min-w-0 flex-1 overflow-x-auto text-sm whitespace-nowrap", children: createdKey }), _jsx(CopyButton, { className: "shrink-0", messages: {
844
+ }, 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: {
846
845
  copied: m.user_api_key_copied(),
847
846
  copy: m.user_api_key_copy(),
848
847
  }, 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: {
@@ -858,7 +857,7 @@ function ApiKeyManager({ authClient, active, permissions = {}, }) {
858
857
  }, searchState: "local", state: {
859
858
  empty: loading ? m.user_loading() : m.table_empty(),
860
859
  loading,
861
- } }) })) : null, editingKey ? (_jsx(ApiKeyEditForm, { configId: "user", keyData: editingKey, permissions: permissions, messages: {
860
+ } }) })) : null, editingKey ? (_jsx(ApiKeyEditForm, { configId: "user", keyData: editingKey, permissions: permissions, permissionLabels: permissionLabels, messages: {
862
861
  enabled: m.user_api_key_enabled(),
863
862
  name: m.user_api_key_name(),
864
863
  referrers: m.user_api_key_referrers(),
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { AuthClientApi, AuthServiceApi } from "./api";
5
5
  export { AuthService, type AuthServiceLayerOptions } from "./service";
6
6
  export { AuthClientConfig } from "./config";
7
7
  export { proxyAuthRequest } from "./server/proxy";
8
- export { OrganizationSwitcher, MemberRequired, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, type AuthUiClient, type MemberRequiredMessages, type MemberRequiredProps, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type OrganizationSwitcherFeatures, type OrganizationSwitcherProps, type UserButtonDialog, useAuthClient, useAdminUsersTotal, } from "./components";
8
+ export { OrganizationSwitcher, MemberRequired, ProjectAccessMatrix, KrakstackAuthProvider, ForgotPassword, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, type AuthUiClient, type MemberRequiredMessages, type MemberRequiredProps, type ProjectAccessMatrixAccess, type ProjectAccessMatrixMessages, type ProjectAccessLabels, type ProjectAccessLabelCatalog, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type OrganizationSwitcherFeatures, type OrganizationSwitcherProps, type UserButtonDialog, useAuthClient, useAdminUsersTotal, } from "./components";
9
9
  export * as BetterAuth from "./better-auth/api.group";
10
10
  export * as Extra from "./extra/api.group";
11
11
  export * as Server from "./server";
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ export { AuthClientApi, AuthServiceApi } from "./api";
5
5
  export { AuthService } from "./service";
6
6
  export { AuthClientConfig } from "./config";
7
7
  export { proxyAuthRequest } from "./server/proxy";
8
- export { OrganizationSwitcher, MemberRequired, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, useAuthClient, useAdminUsersTotal, } from "./components";
8
+ export { OrganizationSwitcher, MemberRequired, ProjectAccessMatrix, KrakstackAuthProvider, ForgotPassword, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, useAuthClient, useAdminUsersTotal, } from "./components";
9
9
  export * as BetterAuth from "./better-auth/api.group";
10
10
  export * as Extra from "./extra/api.group";
11
11
  export * as Server from "./server";
@@ -52,23 +52,13 @@ declare const OrganizationApiKeyActorRequired_base: HttpApiMiddleware.ServiceCla
52
52
  }, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden], AuthService>>;
53
53
  declare class OrganizationApiKeyActorRequired extends OrganizationApiKeyActorRequired_base {
54
54
  }
55
- declare const ServiceApiKeyActorRequired_base: HttpApiMiddleware.ServiceClass<ServiceApiKeyActorRequired, "@krak-stack/auth/ActorRequired/ApiKey/Service", {
56
- requires: AuthService;
57
- provides: CurrentActor;
58
- error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden];
59
- clientError: never;
60
- requiredForClient: false;
61
- security: never;
62
- }, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden], AuthService>>;
63
- declare class ServiceApiKeyActorRequired extends ServiceApiKeyActorRequired_base {
64
- }
65
55
  export type ActorConstraint = {
66
56
  readonly type: "user";
67
57
  } | {
68
58
  readonly type: "apiKey";
69
- readonly ownerType?: "user" | "organization" | "service" | undefined;
59
+ readonly ownerType?: "user" | "organization" | undefined;
70
60
  };
71
- declare const actorRequiredLayer: <Project extends string, Action extends string>(access: ProjectAccessDefinition<Project, Action>) => Layer.Layer<AnyActorRequired | ApiKeyActorRequired | OrganizationApiKeyActorRequired | ServiceApiKeyActorRequired | UserActorRequired | UserApiKeyActorRequired, never, never>;
61
+ declare const actorRequiredLayer: <Project extends string, Action extends string>(access: ProjectAccessDefinition<Project, Action>) => Layer.Layer<AnyActorRequired | ApiKeyActorRequired | OrganizationApiKeyActorRequired | UserActorRequired | UserApiKeyActorRequired, never, never>;
72
62
  type ActorRequiredFactory = {
73
63
  (): typeof AnyActorRequired;
74
64
  (constraint: {
@@ -82,10 +72,6 @@ type ActorRequiredFactory = {
82
72
  readonly type: "apiKey";
83
73
  readonly ownerType: "organization";
84
74
  }): typeof OrganizationApiKeyActorRequired;
85
- (constraint: {
86
- readonly type: "apiKey";
87
- readonly ownerType: "service";
88
- }): typeof ServiceApiKeyActorRequired;
89
75
  (constraint: {
90
76
  readonly type: "apiKey";
91
77
  }): typeof ApiKeyActorRequired;
@@ -16,13 +16,6 @@ const resolveCurrentActor = (access) => Effect.gen(function* () {
16
16
  if (session.authMethod.type === "apiKey") {
17
17
  const apiKey = session.authMethod.apiKey;
18
18
  const grant = yield* Schema.decodeUnknownEffect(ApiKeyPermissionGrant)(apiKey.permissions ?? {}).pipe(Effect.mapError(() => new HttpApiError.Unauthorized({})));
19
- if (apiKey.configId === "service") {
20
- return access.actorForApiKey({
21
- apiKeyId: apiKey.id,
22
- owner: { type: "service", serviceId: apiKey.referenceId },
23
- grant,
24
- });
25
- }
26
19
  const organizationId = session.session.activeOrganizationId;
27
20
  if (!organizationId)
28
21
  return yield* new HttpApiError.Unauthorized({});
@@ -86,10 +79,6 @@ class OrganizationApiKeyActorRequired extends HttpApiMiddleware.Service()("@krak
86
79
  error: [HttpApiError.Unauthorized, HttpApiError.Forbidden],
87
80
  }) {
88
81
  }
89
- class ServiceApiKeyActorRequired extends HttpApiMiddleware.Service()("@krak-stack/auth/ActorRequired/ApiKey/Service", {
90
- error: [HttpApiError.Unauthorized, HttpApiError.Forbidden],
91
- }) {
92
- }
93
82
  const matchesConstraint = (actor, constraint) => {
94
83
  if (!constraint)
95
84
  return true;
@@ -111,16 +100,11 @@ const actorRequired = (constraint) => {
111
100
  if (constraint.ownerType === "organization") {
112
101
  return OrganizationApiKeyActorRequired;
113
102
  }
114
- if (constraint.ownerType === "service")
115
- return ServiceApiKeyActorRequired;
116
103
  return ApiKeyActorRequired;
117
104
  };
118
105
  const actorRequiredLayer = (access) => Layer.mergeAll(Layer.succeed(AnyActorRequired, (httpEffect) => requiredActor(access).pipe(Effect.flatMap((actor) => httpEffect.pipe(Effect.provideService(CurrentActor, actor))))), Layer.succeed(UserActorRequired, (httpEffect) => requiredActor(access, { type: "user" }).pipe(Effect.flatMap((actor) => httpEffect.pipe(Effect.provideService(CurrentActor, actor))))), Layer.succeed(ApiKeyActorRequired, (httpEffect) => requiredActor(access, { type: "apiKey" }).pipe(Effect.flatMap((actor) => httpEffect.pipe(Effect.provideService(CurrentActor, actor))))), Layer.succeed(UserApiKeyActorRequired, (httpEffect) => requiredActor(access, { type: "apiKey", ownerType: "user" }).pipe(Effect.flatMap((actor) => httpEffect.pipe(Effect.provideService(CurrentActor, actor))))), Layer.succeed(OrganizationApiKeyActorRequired, (httpEffect) => requiredActor(access, {
119
106
  type: "apiKey",
120
107
  ownerType: "organization",
121
- }).pipe(Effect.flatMap((actor) => httpEffect.pipe(Effect.provideService(CurrentActor, actor))))), Layer.succeed(ServiceApiKeyActorRequired, (httpEffect) => requiredActor(access, {
122
- type: "apiKey",
123
- ownerType: "service",
124
108
  }).pipe(Effect.flatMap((actor) => httpEffect.pipe(Effect.provideService(CurrentActor, actor))))));
125
109
  export const ActorRequired = Object.assign(actorRequired, {
126
110
  layer: actorRequiredLayer,
@@ -41,11 +41,11 @@ export const makeAuthenticationLive = (options = {}) => {
41
41
  return yield* new HttpApiError.Forbidden({});
42
42
  }
43
43
  }
44
- return yield* httpEffect.pipe(Effect.provideService(AuthService, auth));
44
+ return auth;
45
45
  }).pipe(Effect.mapError((error) => error instanceof HttpApiError.Unauthorized ||
46
46
  error instanceof HttpApiError.Forbidden
47
47
  ? error
48
- : new HttpApiError.Unauthorized({}))),
48
+ : new HttpApiError.Unauthorized({})), Effect.flatMap((auth) => httpEffect.pipe(Effect.provideService(AuthService, auth)))),
49
49
  };
50
50
  }));
51
51
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.1.60",
3
+ "version": "0.1.62",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -38,6 +38,10 @@
38
38
  "types": "./dist/access.d.ts",
39
39
  "default": "./dist/access.js"
40
40
  },
41
+ "./access/matrix": {
42
+ "types": "./dist/components/project-access-matrix.d.ts",
43
+ "default": "./dist/components/project-access-matrix.js"
44
+ },
41
45
  "./components": {
42
46
  "types": "./dist/components/index.d.ts",
43
47
  "default": "./dist/components/index.js"