@krak-stack/auth 0.2.32 → 0.3.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.
- package/CHANGELOG.md +14 -0
- package/README.md +101 -5
- package/dist/access.d.ts +3 -1
- package/dist/admin/api.group.d.ts +41 -41
- package/dist/admin/schema.d.ts +23 -23
- package/dist/admin/schema.js +21 -19
- package/dist/api.d.ts +126 -77
- package/dist/auth/api.group.d.ts +18 -18
- package/dist/auth/schema.d.ts +49 -33
- package/dist/auth/schema.js +18 -18
- package/dist/components/admin-organization-form.js +2 -2
- package/dist/components/admin-organizations.js +6 -5
- package/dist/components/admin-users.js +6 -6
- package/dist/components/api-key-edit-form.js +19 -11
- package/dist/components/associated-projects-notice.d.ts +2 -1
- package/dist/components/associated-projects-notice.js +6 -2
- package/dist/components/auth-atoms.js +1 -2
- package/dist/components/auth-client-api.d.ts +61 -61
- package/dist/components/auth-forms.d.ts +1 -0
- package/dist/components/auth-forms.js +41 -56
- package/dist/components/auth-provider.d.ts +3 -1
- package/dist/components/hooks.d.ts +2 -0
- package/dist/components/hooks.js +13 -6
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +2 -0
- package/dist/components/member-required.js +3 -5
- package/dist/components/oauth-consent.d.ts +22 -0
- package/dist/components/oauth-consent.js +79 -0
- package/dist/components/organization-switcher.d.ts +1 -1
- package/dist/components/organization-switcher.js +83 -54
- package/dist/components/project-card-list.d.ts +6 -0
- package/dist/components/project-card-list.js +4 -0
- package/dist/components/user-button.js +115 -54
- package/dist/extra/schema.d.ts +3 -1
- package/dist/oauth/authorization.d.ts +3 -0
- package/dist/oauth/authorization.js +39 -0
- package/dist/oauth/schema.d.ts +24 -0
- package/dist/oauth/schema.js +12 -0
- package/dist/oauth/verify.d.ts +13 -0
- package/dist/oauth/verify.js +67 -0
- package/dist/schema.js +1 -1
- package/dist/server/actor.js +2 -4
- package/dist/server/api.group.d.ts +49 -0
- package/dist/server/api.group.js +10 -1
- package/dist/server/index.d.ts +3 -1
- package/dist/server/index.js +2 -1
- package/dist/server/mcp.d.ts +20 -0
- package/dist/server/mcp.js +66 -0
- package/dist/server/middleware.d.ts +5 -5
- package/dist/server/middleware.js +15 -5
- package/dist/server/schema.d.ts +51 -0
- package/dist/server/schema.js +7 -0
- package/dist/server/webhook-layer.js +8 -4
- package/dist/server/webhooks.d.ts +9 -3
- package/dist/service.d.ts +152 -46
- package/dist/service.js +56 -9
- package/package.json +2 -1
package/dist/components/hooks.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useLayoutEffect, useState } from "react";
|
|
2
|
+
import { useAtomSet } from "@effect/atom-react";
|
|
3
|
+
import { Atom } from "effect/reactivity";
|
|
4
|
+
// Stable submission-time input for form instances retained across renders.
|
|
5
|
+
export const useLatestAtom = (value) => {
|
|
6
|
+
const [atom] = useState(() => Atom.make(value));
|
|
7
|
+
const set = useAtomSet(atom);
|
|
8
|
+
useLayoutEffect(() => set(value), [set, value]);
|
|
9
|
+
return atom;
|
|
10
|
+
};
|
|
2
11
|
export const useOpenedOnce = (open) => {
|
|
3
12
|
const [opened, setOpened] = useState(open);
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}, [open]);
|
|
8
|
-
return opened;
|
|
13
|
+
if (open && !opened)
|
|
14
|
+
setOpened(true);
|
|
15
|
+
return opened || open;
|
|
9
16
|
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { KrakstackAuthProvider, KrakstackAuthRequired, KrakstackAuthUnavailableError, useKrakstackAuth, useKrakstackAuthProjectConfig, usePermissions, } from "./auth-provider.js";
|
|
2
2
|
export { activeAuthOrganizationAtom, authOrganizationsAtom, authSessionAtom, } from "./auth-atoms.js";
|
|
3
3
|
export { OrganizationSwitcher } from "./organization-switcher.js";
|
|
4
|
+
export { OAuthConsent } from "./oauth-consent.js";
|
|
5
|
+
export { getOAuthAuthorizationQuery } from "../oauth/authorization.js";
|
|
6
|
+
export type { OAuthConsentMessages } from "./oauth-consent.js";
|
|
4
7
|
export { MemberRequired } from "./member-required.js";
|
|
5
8
|
export { HasPermission, useHasPermission } from "./has-permission.js";
|
|
6
9
|
export { ProjectAccessMatrix } from "./project-access-matrix.js";
|
package/dist/components/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { KrakstackAuthProvider, KrakstackAuthRequired, KrakstackAuthUnavailableError, useKrakstackAuth, useKrakstackAuthProjectConfig, usePermissions, } from "./auth-provider.js";
|
|
2
2
|
export { activeAuthOrganizationAtom, authOrganizationsAtom, authSessionAtom, } from "./auth-atoms.js";
|
|
3
3
|
export { OrganizationSwitcher } from "./organization-switcher.js";
|
|
4
|
+
export { OAuthConsent } from "./oauth-consent.js";
|
|
5
|
+
export { getOAuthAuthorizationQuery } from "../oauth/authorization.js";
|
|
4
6
|
export { MemberRequired } from "./member-required.js";
|
|
5
7
|
export { HasPermission, useHasPermission } from "./has-permission.js";
|
|
6
8
|
export { ProjectAccessMatrix } from "./project-access-matrix.js";
|
|
@@ -82,7 +82,7 @@ const organizationProfileAtom = Atom.family((baseUrl) => Atom.family((key) => {
|
|
|
82
82
|
locale: Schema.optional(Schema.Literals(["en", "fr"])),
|
|
83
83
|
organizationId: Schema.String,
|
|
84
84
|
}));
|
|
85
|
-
const { locale, organizationId } = Schema.
|
|
85
|
+
const { locale, organizationId } = Schema.decodeSync(ProfileKey)(key);
|
|
86
86
|
const query = locale ? { organizationId, locale } : { organizationId };
|
|
87
87
|
return authClientApi(baseUrl).query("authExtra", "getOrganizationPublicProfile", {
|
|
88
88
|
query,
|
|
@@ -103,14 +103,12 @@ const accessAtom = Atom.family((baseUrl) => Atom.family((key) => {
|
|
|
103
103
|
organizationId: Schema.String,
|
|
104
104
|
userId: Schema.optional(Schema.String),
|
|
105
105
|
}));
|
|
106
|
-
const { locale, organizationId } = Schema.
|
|
106
|
+
const { locale, organizationId } = Schema.decodeSync(AccessKey)(key);
|
|
107
107
|
return Atom.optimistic(Atom.keepAlive(authClientApi(baseUrl).runtime.atom((get) => Effect.gen(function* () {
|
|
108
108
|
const client = yield* authHttpClient(baseUrl);
|
|
109
109
|
const allowed = yield* client.auth
|
|
110
110
|
.organizationSetActive({ payload: { organizationId } })
|
|
111
|
-
.pipe(Effect.as(true), Effect.
|
|
112
|
-
? Effect.succeed(false)
|
|
113
|
-
: Effect.fail(error)));
|
|
111
|
+
.pipe(Effect.as(true), Effect.catchIf((error) => error instanceof AuthForbidden, () => Effect.succeed(false)));
|
|
114
112
|
if (allowed) {
|
|
115
113
|
get.refresh(authSessionAtom(baseUrl));
|
|
116
114
|
return { allowed: true };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type OAuthConsentMessages = {
|
|
2
|
+
readonly title: string;
|
|
3
|
+
readonly description: (input: {
|
|
4
|
+
clientName: string;
|
|
5
|
+
}) => string;
|
|
6
|
+
readonly requestedScopes: string;
|
|
7
|
+
readonly allow: string;
|
|
8
|
+
readonly deny: string;
|
|
9
|
+
readonly error: string;
|
|
10
|
+
readonly invalidRequest: string;
|
|
11
|
+
readonly notice?: string;
|
|
12
|
+
readonly permissions?: Readonly<Record<string, {
|
|
13
|
+
readonly title: string;
|
|
14
|
+
readonly description?: string;
|
|
15
|
+
}>>;
|
|
16
|
+
};
|
|
17
|
+
/** Shared login-provider-aware consent. The signed OAuth query is sent intact;
|
|
18
|
+
* the provider, not the component, validates scopes, grants and callbacks. */
|
|
19
|
+
export declare const OAuthConsent: ({ messages, baseUrl: providedBaseUrl, }: {
|
|
20
|
+
readonly messages: OAuthConsentMessages;
|
|
21
|
+
readonly baseUrl?: string;
|
|
22
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useAtomSet, useAtomSubscribe, useAtomValue } from "@effect/atom-react";
|
|
3
|
+
import { useRouterState } from "@tanstack/react-router";
|
|
4
|
+
import { Effect, Option, Schema } from "effect";
|
|
5
|
+
import { AsyncResult, Atom } from "effect/reactivity";
|
|
6
|
+
import { useMemo } from "react";
|
|
7
|
+
import { Bot, BookOpen, KeyRound, Mail, Pencil, RefreshCw, UserRound, } from "lucide-react";
|
|
8
|
+
import { Button } from "@/components/ui/button";
|
|
9
|
+
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card";
|
|
10
|
+
import { authClientApi, authHttpClient } from "./auth-client-api.js";
|
|
11
|
+
import { useKrakstackAuth } from "./auth-provider.js";
|
|
12
|
+
import { getOAuthAuthorizationQuery } from "../oauth/authorization.js";
|
|
13
|
+
const ConsentSearch = Schema.Struct({
|
|
14
|
+
client_id: Schema.NonEmptyString,
|
|
15
|
+
sig: Schema.NonEmptyString,
|
|
16
|
+
scope: Schema.optional(Schema.String),
|
|
17
|
+
}).annotate({ identifier: "OAuthConsentSearch" });
|
|
18
|
+
const scopeIcon = (scope) => {
|
|
19
|
+
switch (scope) {
|
|
20
|
+
case "mcp:read":
|
|
21
|
+
return BookOpen;
|
|
22
|
+
case "mcp:write":
|
|
23
|
+
return Pencil;
|
|
24
|
+
case "offline_access":
|
|
25
|
+
return RefreshCw;
|
|
26
|
+
case "openid":
|
|
27
|
+
case "profile":
|
|
28
|
+
return UserRound;
|
|
29
|
+
case "email":
|
|
30
|
+
return Mail;
|
|
31
|
+
default:
|
|
32
|
+
return KeyRound;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const clientAtom = Atom.family((baseUrl) => Atom.family((clientId) => authClientApi(baseUrl).query("auth", "oauthPublicClient", {
|
|
36
|
+
query: { client_id: clientId },
|
|
37
|
+
timeToLive: "5 minutes",
|
|
38
|
+
})));
|
|
39
|
+
const makeConsentAtom = (baseUrl, search) => {
|
|
40
|
+
const oauthQuery = getOAuthAuthorizationQuery(search) ?? "";
|
|
41
|
+
const scope = new URLSearchParams(oauthQuery).get("scope") ?? "";
|
|
42
|
+
return Atom.fn((accept) => authHttpClient(baseUrl).pipe(Effect.flatMap((api) => api.auth.oauthConsent({
|
|
43
|
+
payload: { accept, scope, oauth_query: oauthQuery },
|
|
44
|
+
}))));
|
|
45
|
+
};
|
|
46
|
+
/** Shared login-provider-aware consent. The signed OAuth query is sent intact;
|
|
47
|
+
* the provider, not the component, validates scopes, grants and callbacks. */
|
|
48
|
+
export const OAuthConsent = ({ messages, baseUrl: providedBaseUrl, }) => {
|
|
49
|
+
const auth = useKrakstackAuth();
|
|
50
|
+
const baseUrl = providedBaseUrl ?? auth?.baseUrl;
|
|
51
|
+
const search = useRouterState({
|
|
52
|
+
select: (state) => state.location.searchStr,
|
|
53
|
+
});
|
|
54
|
+
const oauthQuery = getOAuthAuthorizationQuery(search);
|
|
55
|
+
const decoded = Schema.decodeUnknownOption(ConsentSearch)(Object.fromEntries(new URLSearchParams(oauthQuery ?? "")));
|
|
56
|
+
const clientId = Option.isSome(decoded) ? decoded.value.client_id : "";
|
|
57
|
+
const scope = Option.isSome(decoded) ? (decoded.value.scope ?? "") : "";
|
|
58
|
+
const client = useAtomValue(clientAtom(baseUrl)(clientId));
|
|
59
|
+
const clientName = AsyncResult.isSuccess(client)
|
|
60
|
+
? client.value.client_name || client.value.client_id
|
|
61
|
+
: clientId;
|
|
62
|
+
// A fresh atom per signed request prevents decisions/results leaking between
|
|
63
|
+
// successive consent screens for different agents or grants.
|
|
64
|
+
const submitAtom = useMemo(() => makeConsentAtom(baseUrl, search), [baseUrl, search]);
|
|
65
|
+
const submit = useAtomSet(submitAtom);
|
|
66
|
+
const result = useAtomValue(submitAtom);
|
|
67
|
+
useAtomSubscribe(submitAtom, (result) => {
|
|
68
|
+
if (AsyncResult.isSuccess(result))
|
|
69
|
+
window.location.assign(result.value.url);
|
|
70
|
+
});
|
|
71
|
+
const invalid = Option.isNone(decoded) || oauthQuery === null;
|
|
72
|
+
return (_jsxs(Card, { className: "w-full max-w-md rounded-2xl shadow-sm", children: [_jsxs(CardHeader, { className: "items-center gap-3 text-center", children: [_jsx("div", { className: "bg-primary/10 text-primary mx-auto flex size-12 items-center justify-center rounded-2xl", children: _jsx(Bot, { className: "size-6", "aria-hidden": "true" }) }), _jsx(CardTitle, { className: "text-xl", children: messages.title }), _jsx(CardDescription, { className: "text-pretty", children: invalid
|
|
73
|
+
? messages.invalidRequest
|
|
74
|
+
: messages.description({ clientName }) })] }), _jsxs(CardContent, { className: "space-y-4", children: [_jsx("p", { className: "text-muted-foreground text-sm", children: messages.requestedScopes }), _jsx("ul", { className: "space-y-2", children: Array.from(new Set(scope.split(/\s+/).filter(Boolean))).map((scope) => {
|
|
75
|
+
const permission = messages.permissions?.[scope];
|
|
76
|
+
const Icon = scopeIcon(scope);
|
|
77
|
+
return (_jsxs("li", { className: "bg-muted/50 flex items-start gap-3 rounded-xl p-3", children: [_jsx(Icon, { className: "text-muted-foreground mt-0.5 size-4 shrink-0", "aria-hidden": "true" }), _jsxs("div", { className: "space-y-0.5", children: [_jsx("p", { className: "text-sm font-medium", children: permission?.title ?? scope }), permission?.description && (_jsx("p", { className: "text-muted-foreground text-xs leading-relaxed", children: permission.description }))] })] }, scope));
|
|
78
|
+
}) }), AsyncResult.isFailure(result) && _jsx("p", { role: "alert", children: messages.error })] }), _jsxs(CardFooter, { className: "flex-col gap-2", children: [messages.notice && (_jsx("p", { className: "text-muted-foreground mb-2 text-center text-xs", children: messages.notice })), _jsx(Button, { disabled: invalid || result.waiting, onClick: () => submit(true), className: "w-full", children: messages.allow }), _jsx(Button, { disabled: invalid || result.waiting, variant: "ghost", onClick: () => submit(false), className: "w-full", children: messages.deny })] })] }));
|
|
79
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import * as Data from "effect/Data";
|
|
3
|
+
import { useAtomRefresh, useAtomSet, useAtomSubscribe, useAtomValue, } from "@effect/atom-react";
|
|
3
4
|
import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
|
|
4
5
|
import { Effect, Option, Predicate, Schema } from "effect";
|
|
5
6
|
import { AsyncResult, Atom } from "effect/reactivity";
|
|
@@ -30,13 +31,15 @@ import { ApiKeyPermissions } from "./api-key-permissions.js";
|
|
|
30
31
|
import { ApiKeyRateLimit, apiKeyUsagePercent } from "./api-key-rate-limit.js";
|
|
31
32
|
import { ApiKeyReferrers, apiKeyReferrers } from "./api-key-referrers.js";
|
|
32
33
|
import { ContactAddressesField, ContactEmailsField, ContactPhonesField, ContactSocialsField, ContactWebsitesField, } from "./contact-fields.js";
|
|
33
|
-
import { useOpenedOnce } from "./hooks.js";
|
|
34
|
+
import { useLatestAtom, useOpenedOnce } from "./hooks.js";
|
|
34
35
|
import { ScrollableDialogBody, ScrollableDialogContent, ScrollableDialogHeader, } from "./scrollable-dialog.js";
|
|
35
36
|
import { invitationDisplayStatus, isInvitationExpired, useInvitationExpirationClock, } from "./invitation-expiration.js";
|
|
36
37
|
import { ExtraUploadedAsset } from "../extra/schema.js";
|
|
37
38
|
import { assetPath, assetUrl, cn } from "./utils.js";
|
|
38
39
|
import { AssociatedProjectsNotice } from "./associated-projects-notice.js";
|
|
39
40
|
import { ExtraApiKeyPermissions } from "../extra/schema.js";
|
|
41
|
+
class OrganizationActionError extends Data.TaggedError("OrganizationActionError") {
|
|
42
|
+
}
|
|
40
43
|
const messages = {
|
|
41
44
|
en: {
|
|
42
45
|
organization_back: "Back",
|
|
@@ -484,11 +487,13 @@ const organizationFailureMessage = (cause, fallback) => {
|
|
|
484
487
|
};
|
|
485
488
|
const decodeUploadedAsset = Schema.decodeUnknownEffect(ExtraUploadedAsset);
|
|
486
489
|
const OrganizationMetadataRecord = Schema.Record(Schema.String, Schema.Json);
|
|
487
|
-
const normalizeOrganizationMetadata = (metadata) => Schema.
|
|
490
|
+
const normalizeOrganizationMetadata = (metadata) => Schema.decodeEffect(OrganizationMetadataRecord)(metadata);
|
|
488
491
|
const uploadImageAsset = (file, m, uploadImage) => {
|
|
489
492
|
const payload = new FormData();
|
|
490
493
|
payload.append("file", file);
|
|
491
|
-
return uploadImage({ payload }).pipe(Effect.flatMap(decodeUploadedAsset), Effect.map((uploaded) => assetPath(uploaded.url)), Effect.mapError(() => new
|
|
494
|
+
return uploadImage({ payload }).pipe(Effect.flatMap(decodeUploadedAsset), Effect.map((uploaded) => assetPath(uploaded.url)), Effect.mapError(() => new OrganizationActionError({
|
|
495
|
+
message: m.organization_logo_upload_error(),
|
|
496
|
+
})));
|
|
492
497
|
};
|
|
493
498
|
const currentOrganizationLocale = () => getLocale() === "fr" ? "fr" : "en";
|
|
494
499
|
const parseOrganizationMetadata = decodeOrganizationMetadata;
|
|
@@ -771,8 +776,8 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
771
776
|
});
|
|
772
777
|
const loadingUserInvitations = invitationsResult._tag === "Initial";
|
|
773
778
|
const activeMemberRoles = parseRoleList(activeOrganization?.members.find((member) => member.userId === session?.user.id)?.role);
|
|
774
|
-
const canManageApiKeys = activeMemberRoles.
|
|
775
|
-
const canUpdateOrganization =
|
|
779
|
+
const canManageApiKeys = activeMemberRoles.includes("owner");
|
|
780
|
+
const canUpdateOrganization = activeMemberRoles.some((role) => role === "owner" || role === "admin");
|
|
776
781
|
const canSwitchOrganizations = features?.organizationSwitching ?? true;
|
|
777
782
|
const canCreateOrganization = features?.organizationCreation ?? true;
|
|
778
783
|
const canViewOrganizationInvitations = features?.userInvitations ?? true;
|
|
@@ -880,7 +885,7 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
880
885
|
setDialog((current) => open ? "manage" : current === "manage" ? null : current);
|
|
881
886
|
}, children: activeOrganization && canUpdateOrganization ? (_jsx(EditOrganizationSection, { header: _jsxs(DialogHeader, { className: "sm:flex-row sm:items-end sm:justify-between sm:gap-4", children: [_jsxs("div", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() })] }), _jsx("div", { className: "mt-2 w-fit sm:mt-0", children: _jsx(EditingLocaleSwitcher, { locale: auth?.locale, value: editingOrganizationLocale, onValueChange: (value) => setEditingOrganizationLocale(value === "fr" ? "fr" : "en") }) })] }), baseUrl: baseUrl, editingLocale: editingOrganizationLocale, organization: activeOrganization })) : null }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
|
|
882
887
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
883
|
-
}, children: _jsx(ScrollableDialogContent, { size: "4xl", children: activeOrganization ? (_jsx(OrganizationMembersManager, { baseUrl: baseUrl, canManageMembers:
|
|
888
|
+
}, children: _jsx(ScrollableDialogContent, { size: "4xl", children: activeOrganization ? (_jsx(OrganizationMembersManager, { baseUrl: baseUrl, canManageMembers: canUpdateOrganization, organization: activeOrganization, currentUserId: session.user.id, active: dialog === "members", onLeft: () => {
|
|
884
889
|
setDialog(null);
|
|
885
890
|
onChange?.(null);
|
|
886
891
|
} })) : null }) }), _jsx(Dialog, { open: dialog === "apiKeys" && canManageApiKeys, onOpenChange: (open) => {
|
|
@@ -896,6 +901,7 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
896
901
|
const OrganizationDeletionDialog = ({ baseUrl, organization, onClose, onDeleted, }) => {
|
|
897
902
|
const auth = useKrakstackAuth();
|
|
898
903
|
const labels = adminOrganizationsMessages(auth?.locale ?? "en");
|
|
904
|
+
const m = useOrganizationMessages();
|
|
899
905
|
// Cross-project deletion cannot be predicted or rolled back on the client.
|
|
900
906
|
const [mutation] = useState(() => authClientApi(baseUrl).runtime.fn(() => requestOrganizationDeletion(organization.id, baseUrl).pipe(Effect.tap(() => Effect.sync(() => {
|
|
901
907
|
notifyAuthChange();
|
|
@@ -906,7 +912,7 @@ const OrganizationDeletionDialog = ({ baseUrl, organization, onClose, onDeleted,
|
|
|
906
912
|
return (_jsx(AlertDialog, { open: true, onOpenChange: (open) => {
|
|
907
913
|
if (!open && !result.waiting)
|
|
908
914
|
onClose();
|
|
909
|
-
}, children: _jsxs(AlertDialogContent, { children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: labels.organization_delete_title }), _jsx(AlertDialogDescription, { children: labels.organization_delete_description.replace("{name}", organization.name) })] }), AsyncResult.isFailure(result) ? (_jsx("p", { role: "alert", children: labels.organization_delete_error })) : null, _jsxs(AlertDialogFooter, { children: [_jsx(Button, { type: "button", variant: "outline", disabled: result.waiting, onClick: onClose, children: labels.organization_delete_cancel }), _jsx(Button, { type: "button", variant: "destructive", disabled: result.waiting, onClick: () => remove(), children: labels.organization_delete_confirm })] })] }) }));
|
|
915
|
+
}, children: _jsxs(AlertDialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: labels.organization_delete_title }), _jsx(AlertDialogDescription, { children: labels.organization_delete_description.replace("{name}", organization.name) })] }), _jsx(AssociatedProjectsNotice, { baseUrl: baseUrl, organizationId: organization.id, expanded: true, getSummary: (count) => m.organization_projects_summary({ count }), viewLabel: m.organization_projects_view() }), AsyncResult.isFailure(result) ? (_jsx("p", { role: "alert", children: labels.organization_delete_error })) : null, _jsxs(AlertDialogFooter, { children: [_jsx(Button, { type: "button", variant: "outline", disabled: result.waiting, onClick: onClose, children: labels.organization_delete_cancel }), _jsx(Button, { type: "button", variant: "destructive", disabled: result.waiting, onClick: () => remove(), children: labels.organization_delete_confirm })] })] }) }));
|
|
910
916
|
};
|
|
911
917
|
function UserInvitationsManager({ baseUrl, invitations, loading, error, activeOrganizationId, onActionComplete, }) {
|
|
912
918
|
const m = useOrganizationMessages();
|
|
@@ -1031,7 +1037,9 @@ function EditOrganizationSection({ header, baseUrl, editingLocale, organization,
|
|
|
1031
1037
|
onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
|
|
1032
1038
|
const name = organizationNameFromForm(value, defaultLocale);
|
|
1033
1039
|
if (!name)
|
|
1034
|
-
return yield*
|
|
1040
|
+
return yield* new OrganizationActionError({
|
|
1041
|
+
message: m.organization_name_required(),
|
|
1042
|
+
});
|
|
1035
1043
|
const slug = value.slug.trim().toLowerCase();
|
|
1036
1044
|
const client = yield* authHttpClient(baseUrl);
|
|
1037
1045
|
const metadata = yield* organizationMetadataFromForm(value, m, (input) => client.authExtra.uploadUserImage(input), organization.metadata);
|
|
@@ -1048,9 +1056,12 @@ function EditOrganizationSection({ header, baseUrl, editingLocale, organization,
|
|
|
1048
1056
|
});
|
|
1049
1057
|
yield* Effect.sync(notifyAuthChange);
|
|
1050
1058
|
return updated;
|
|
1051
|
-
}).pipe(Effect.mapError((cause) =>
|
|
1052
|
-
|
|
1053
|
-
|
|
1059
|
+
}).pipe(Effect.mapError((cause) => new OrganizationActionError({
|
|
1060
|
+
message: cause instanceof Error
|
|
1061
|
+
? cause.message
|
|
1062
|
+
: m.organization_update_error(),
|
|
1063
|
+
cause: cause,
|
|
1064
|
+
}))),
|
|
1054
1065
|
}));
|
|
1055
1066
|
const submit = useAtomSet(form.submit);
|
|
1056
1067
|
const submitResult = useAtomValue(form.submit);
|
|
@@ -1090,7 +1101,9 @@ function CreateOrganizationSection({ header, baseUrl, editingLocale, onCreated,
|
|
|
1090
1101
|
onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
|
|
1091
1102
|
const name = organizationNameFromForm(value, defaultLocale);
|
|
1092
1103
|
if (!name)
|
|
1093
|
-
return yield*
|
|
1104
|
+
return yield* new OrganizationActionError({
|
|
1105
|
+
message: m.organization_name_required(),
|
|
1106
|
+
});
|
|
1094
1107
|
const slug = (value.slug.trim() || slugify(name)).toLowerCase();
|
|
1095
1108
|
const client = yield* authHttpClient(baseUrl);
|
|
1096
1109
|
const metadata = yield* organizationMetadataFromForm({ ...value, slug }, m, (input) => client.authExtra.uploadUserImage(input));
|
|
@@ -1098,18 +1111,28 @@ function CreateOrganizationSection({ header, baseUrl, editingLocale, onCreated,
|
|
|
1098
1111
|
const createPayload = { name, slug, metadata: normalizedMetadata };
|
|
1099
1112
|
const created = yield* client.auth
|
|
1100
1113
|
.organizationCreate({ payload: createPayload })
|
|
1101
|
-
.pipe(Effect.mapError((cause) => new
|
|
1102
|
-
|
|
1103
|
-
|
|
1114
|
+
.pipe(Effect.mapError((cause) => new OrganizationActionError({
|
|
1115
|
+
message: isOrganizationSlugConflict(cause)
|
|
1116
|
+
? m.organization_create_slug_conflict()
|
|
1117
|
+
: organizationFailureMessage(cause, m.organization_create_error()),
|
|
1118
|
+
})));
|
|
1104
1119
|
yield* Effect.sync(notifyAuthChange);
|
|
1105
1120
|
yield* Effect.tryPromise({
|
|
1106
1121
|
try: () => onCreated(created),
|
|
1107
|
-
catch: (cause) =>
|
|
1122
|
+
catch: (cause) => new OrganizationActionError({
|
|
1123
|
+
message: cause instanceof Error
|
|
1124
|
+
? cause.message
|
|
1125
|
+
: m.organization_create_error(),
|
|
1126
|
+
cause,
|
|
1127
|
+
}),
|
|
1108
1128
|
});
|
|
1109
1129
|
return created;
|
|
1110
|
-
}).pipe(Effect.mapError((cause) =>
|
|
1111
|
-
|
|
1112
|
-
|
|
1130
|
+
}).pipe(Effect.mapError((cause) => new OrganizationActionError({
|
|
1131
|
+
message: cause instanceof Error
|
|
1132
|
+
? cause.message
|
|
1133
|
+
: m.organization_create_error(),
|
|
1134
|
+
cause: cause,
|
|
1135
|
+
}))),
|
|
1113
1136
|
}));
|
|
1114
1137
|
const submit = useAtomSet(form.submit);
|
|
1115
1138
|
const submitResult = useAtomValue(form.submit);
|
|
@@ -1179,7 +1202,6 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
|
|
|
1179
1202
|
const [error, setError] = useState(null);
|
|
1180
1203
|
const [cancellingInvitationId, setCancellingInvitationId] = useState(null);
|
|
1181
1204
|
const [leavingOrganization, setLeavingOrganization] = useState(false);
|
|
1182
|
-
const [lastMembersData, setLastMembersData] = useState(null);
|
|
1183
1205
|
const currentMembers = AsyncResult.match(membersResult, {
|
|
1184
1206
|
onInitial: () => null,
|
|
1185
1207
|
onFailure: () => null,
|
|
@@ -1190,6 +1212,7 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
|
|
|
1190
1212
|
onFailure: () => null,
|
|
1191
1213
|
onSuccess: ({ value }) => value,
|
|
1192
1214
|
});
|
|
1215
|
+
const [lastMembersData, setLastMembersData] = useState(null);
|
|
1193
1216
|
const currentMembersData = currentMembers && currentInvitations
|
|
1194
1217
|
? {
|
|
1195
1218
|
members: Array.from(currentMembers),
|
|
@@ -1197,7 +1220,7 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
|
|
|
1197
1220
|
}
|
|
1198
1221
|
: null;
|
|
1199
1222
|
const membersData = currentMembersData ??
|
|
1200
|
-
lastMembersData ?? {
|
|
1223
|
+
lastMembersData?.data ?? {
|
|
1201
1224
|
members: [],
|
|
1202
1225
|
invitations: [],
|
|
1203
1226
|
};
|
|
@@ -1224,14 +1247,15 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
|
|
|
1224
1247
|
(membersResult._tag === "Initial" || invitationsResult._tag === "Initial");
|
|
1225
1248
|
const canInviteMembers = canManageMembers;
|
|
1226
1249
|
const canRemoveMembers = canManageMembers;
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1250
|
+
if (currentMembersData &&
|
|
1251
|
+
(lastMembersData?.members !== currentMembers ||
|
|
1252
|
+
lastMembersData?.invitations !== currentInvitations)) {
|
|
1230
1253
|
setLastMembersData({
|
|
1231
|
-
members:
|
|
1232
|
-
invitations:
|
|
1254
|
+
members: currentMembers,
|
|
1255
|
+
invitations: currentInvitations,
|
|
1256
|
+
data: currentMembersData,
|
|
1233
1257
|
});
|
|
1234
|
-
}
|
|
1258
|
+
}
|
|
1235
1259
|
const [inviteForm] = useState(() => FormReact.make(inviteMemberFormBuilder, {
|
|
1236
1260
|
runtime: authClientApi(baseUrl).runtime,
|
|
1237
1261
|
fields: {
|
|
@@ -1244,19 +1268,22 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
|
|
|
1244
1268
|
role: normalizeInvitationRole(value.role),
|
|
1245
1269
|
organizationId: organization.id,
|
|
1246
1270
|
},
|
|
1247
|
-
})), Effect.tap(() => Effect.sync(refreshInvitations)), Effect.mapError((cause) =>
|
|
1248
|
-
|
|
1249
|
-
|
|
1271
|
+
})), Effect.tap(() => Effect.sync(refreshInvitations)), Effect.mapError((cause) => new OrganizationActionError({
|
|
1272
|
+
message: cause instanceof Error
|
|
1273
|
+
? cause.message
|
|
1274
|
+
: m.organization_invite_error(),
|
|
1275
|
+
cause: cause,
|
|
1276
|
+
}))),
|
|
1250
1277
|
}));
|
|
1251
1278
|
const submitInvitation = useAtomSet(inviteForm.submit);
|
|
1252
1279
|
const resetInvitation = useAtomSet(inviteForm.reset);
|
|
1253
1280
|
const inviteResult = useAtomValue(inviteForm.submit);
|
|
1254
|
-
|
|
1255
|
-
if (!AsyncResult.isSuccess(
|
|
1281
|
+
useAtomSubscribe(inviteForm.submit, (result) => {
|
|
1282
|
+
if (!AsyncResult.isSuccess(result))
|
|
1256
1283
|
return;
|
|
1257
1284
|
resetInvitation();
|
|
1258
1285
|
setInviting(false);
|
|
1259
|
-
}
|
|
1286
|
+
});
|
|
1260
1287
|
const updateRole = async (member, role) => {
|
|
1261
1288
|
setError(null);
|
|
1262
1289
|
const nextRole = Array.isArray(role)
|
|
@@ -1486,10 +1513,8 @@ function OrganizationApiKeyManager({ baseUrl, locale, organization, active, perm
|
|
|
1486
1513
|
const [error, setError] = useState(null);
|
|
1487
1514
|
const permissionOptions = organizationApiKeyPermissionOptions(permissions);
|
|
1488
1515
|
const [selectedPermissions, setSelectedPermissions] = useState({});
|
|
1489
|
-
const
|
|
1490
|
-
const
|
|
1491
|
-
permissionOptionsRef.current = permissionOptions;
|
|
1492
|
-
selectedPermissionsRef.current = selectedPermissions;
|
|
1516
|
+
const permissionOptionsAtom = useLatestAtom(permissionOptions);
|
|
1517
|
+
const selectedPermissionsAtom = useLatestAtom(selectedPermissions);
|
|
1493
1518
|
const keys = AsyncResult.match(keysResult, {
|
|
1494
1519
|
onInitial: () => [],
|
|
1495
1520
|
onFailure: () => [],
|
|
@@ -1504,7 +1529,7 @@ function OrganizationApiKeyManager({ baseUrl, locale, organization, active, perm
|
|
|
1504
1529
|
const [createForm] = useState(() => FormReact.make(apiKeyFormBuilder, {
|
|
1505
1530
|
runtime: authClientApi(baseUrl).runtime,
|
|
1506
1531
|
fields: { name: TextField, referrers: TextAreaField },
|
|
1507
|
-
onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
|
|
1532
|
+
onSubmit: (_, { decoded: value, get }) => Effect.gen(function* () {
|
|
1508
1533
|
yield* Effect.sync(() => setCreatedKey(null));
|
|
1509
1534
|
const client = yield* authHttpClient(baseUrl);
|
|
1510
1535
|
const created = yield* client.authExtra.createApiKey({
|
|
@@ -1512,7 +1537,7 @@ function OrganizationApiKeyManager({ baseUrl, locale, organization, active, perm
|
|
|
1512
1537
|
configId: "organization",
|
|
1513
1538
|
organizationId: organization.id,
|
|
1514
1539
|
name: value.name.trim(),
|
|
1515
|
-
permissions: organizationApiKeySelectedPermissions(
|
|
1540
|
+
permissions: organizationApiKeySelectedPermissions(get(permissionOptionsAtom), get(selectedPermissionsAtom)),
|
|
1516
1541
|
referrers: parseApiKeyReferrers(value.referrers, m.user_api_key_referrers_error()),
|
|
1517
1542
|
},
|
|
1518
1543
|
});
|
|
@@ -1522,9 +1547,12 @@ function OrganizationApiKeyManager({ baseUrl, locale, organization, active, perm
|
|
|
1522
1547
|
refreshKeys();
|
|
1523
1548
|
});
|
|
1524
1549
|
return created;
|
|
1525
|
-
}).pipe(Effect.mapError((cause) =>
|
|
1526
|
-
|
|
1527
|
-
|
|
1550
|
+
}).pipe(Effect.mapError((cause) => new OrganizationActionError({
|
|
1551
|
+
message: cause instanceof Error
|
|
1552
|
+
? cause.message
|
|
1553
|
+
: m.user_api_key_create_error(),
|
|
1554
|
+
cause: cause,
|
|
1555
|
+
}))),
|
|
1528
1556
|
}));
|
|
1529
1557
|
const submitApiKey = useAtomSet(createForm.submit);
|
|
1530
1558
|
const resetApiKey = useAtomSet(createForm.reset);
|
|
@@ -1612,7 +1640,7 @@ function OrganizationApiKeyEditForm({ baseUrl, keyData, messages, permissions, p
|
|
|
1612
1640
|
project,
|
|
1613
1641
|
action,
|
|
1614
1642
|
})));
|
|
1615
|
-
const currentPermissions = Schema.
|
|
1643
|
+
const currentPermissions = Schema.decodeOption(ExtraApiKeyPermissions)(keyData.permissions ?? {});
|
|
1616
1644
|
const currentGrant = Option.isSome(currentPermissions)
|
|
1617
1645
|
? currentPermissions.value
|
|
1618
1646
|
: {};
|
|
@@ -1620,10 +1648,8 @@ function OrganizationApiKeyEditForm({ baseUrl, keyData, messages, permissions, p
|
|
|
1620
1648
|
option.id,
|
|
1621
1649
|
currentGrant[option.project]?.includes(option.action) ?? false,
|
|
1622
1650
|
]));
|
|
1623
|
-
const
|
|
1624
|
-
const
|
|
1625
|
-
permissionOptionsRef.current = permissionOptions;
|
|
1626
|
-
permissionsRef.current = permissions;
|
|
1651
|
+
const permissionOptionsAtom = useLatestAtom(permissionOptions);
|
|
1652
|
+
const permissionsAtom = useLatestAtom(permissions);
|
|
1627
1653
|
const [form] = useState(() => FormReact.make(editApiKeyFormBuilder, {
|
|
1628
1654
|
runtime: authClientApi(baseUrl).runtime,
|
|
1629
1655
|
fields: {
|
|
@@ -1633,13 +1659,13 @@ function OrganizationApiKeyEditForm({ baseUrl, keyData, messages, permissions, p
|
|
|
1633
1659
|
permissions: ApiKeyPermissionsField,
|
|
1634
1660
|
},
|
|
1635
1661
|
mode: { validation: "onSubmit" },
|
|
1636
|
-
onSubmit: (_, { decoded }) => Effect.gen(function* () {
|
|
1662
|
+
onSubmit: (_, { decoded, get }) => Effect.gen(function* () {
|
|
1637
1663
|
const referrers = parseApiKeyReferrers(decoded.referrers, messages.referrersError);
|
|
1638
1664
|
const selectedGrant = {};
|
|
1639
|
-
for (const project of Object.keys(
|
|
1665
|
+
for (const project of Object.keys(get(permissionsAtom))) {
|
|
1640
1666
|
selectedGrant[project] = [];
|
|
1641
1667
|
}
|
|
1642
|
-
for (const option of
|
|
1668
|
+
for (const option of get(permissionOptionsAtom)) {
|
|
1643
1669
|
if (!decoded.permissions[option.id])
|
|
1644
1670
|
continue;
|
|
1645
1671
|
selectedGrant[option.project] = [
|
|
@@ -1660,9 +1686,12 @@ function OrganizationApiKeyEditForm({ baseUrl, keyData, messages, permissions, p
|
|
|
1660
1686
|
});
|
|
1661
1687
|
yield* Effect.sync(onSaved);
|
|
1662
1688
|
return updated;
|
|
1663
|
-
}).pipe(Effect.mapError((cause) =>
|
|
1664
|
-
|
|
1665
|
-
|
|
1689
|
+
}).pipe(Effect.mapError((cause) => new OrganizationActionError({
|
|
1690
|
+
message: cause instanceof Error
|
|
1691
|
+
? cause.message
|
|
1692
|
+
: organizationFailureMessage(cause, messages.updateError),
|
|
1693
|
+
cause: cause,
|
|
1694
|
+
}))),
|
|
1666
1695
|
}));
|
|
1667
1696
|
const submit = useAtomSet(form.submit);
|
|
1668
1697
|
const submitResult = useAtomValue(form.submit);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AppWindow } from "lucide-react";
|
|
3
|
+
import { Card, CardContent } from "@/components/ui/card";
|
|
4
|
+
export const ProjectCardList = ({ projects, }) => (_jsx("ul", { className: "grid gap-2 sm:grid-cols-2", children: projects.map((project) => (_jsx("li", { children: _jsx(Card, { size: "sm", className: "h-full py-3 shadow-none", children: _jsxs(CardContent, { className: "flex items-center gap-3 px-3", children: [_jsx("span", { className: "bg-muted text-muted-foreground flex size-9 shrink-0 items-center justify-center rounded-lg", children: _jsx(AppWindow, { "aria-hidden": "true", className: "size-4" }) }), _jsx("span", { className: "min-w-0 flex-1 text-sm font-medium break-words", children: project.name })] }) }) }, project.id))) }));
|