@krak-stack/auth 0.2.31 → 0.3.0
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 +19 -0
- package/README.md +175 -1
- 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 +141 -81
- package/dist/auth/api.group.d.ts +37 -19
- package/dist/auth/api.group.js +17 -1
- package/dist/auth/schema.d.ts +61 -33
- package/dist/auth/schema.js +30 -18
- package/dist/components/account-deletion-request.d.ts +5 -0
- package/dist/components/account-deletion-request.js +7 -0
- package/dist/components/account-deletion.d.ts +8 -0
- package/dist/components/account-deletion.js +59 -0
- package/dist/components/admin-organization-form.js +2 -2
- package/dist/components/admin-organizations.js +9 -7
- 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 +7 -3
- package/dist/components/auth-atoms.js +1 -2
- package/dist/components/auth-client-api.d.ts +94 -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/deletion-visibility.d.ts +1 -0
- package/dist/components/deletion-visibility.js +3 -0
- 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-deletion-request.d.ts +17 -0
- package/dist/components/organization-deletion-request.js +9 -0
- package/dist/components/organization-switcher.d.ts +1 -1
- package/dist/components/organization-switcher.js +113 -55
- package/dist/components/project-card-list.d.ts +6 -0
- package/dist/components/project-card-list.js +4 -0
- package/dist/components/user-button.d.ts +29 -1
- package/dist/components/user-button.js +145 -47
- package/dist/extra/api.group.d.ts +13 -1
- package/dist/extra/api.group.js +5 -1
- package/dist/extra/schema.d.ts +16 -1
- package/dist/extra/schema.js +13 -0
- 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.d.ts +35 -0
- package/dist/schema.js +26 -1
- package/dist/server/actor.js +2 -4
- package/dist/server/index.d.ts +4 -1
- package/dist/server/index.js +2 -0
- package/dist/server/mcp.d.ts +20 -0
- package/dist/server/mcp.js +66 -0
- package/dist/server/middleware.d.ts +15 -7
- package/dist/server/middleware.js +19 -6
- package/dist/server/webhook-layer.d.ts +6 -0
- package/dist/server/webhook-layer.js +41 -0
- package/dist/server/webhooks.d.ts +44 -0
- package/dist/server/webhooks.js +39 -0
- package/dist/service.d.ts +118 -46
- package/dist/service.js +56 -9
- package/package.json +8 -3
|
@@ -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";
|
|
@@ -12,6 +13,7 @@ import { AppBrand } from "@krak-stack/registry/app-brand";
|
|
|
12
13
|
import { FieldSet } from "@/components/ui/field";
|
|
13
14
|
import { Badge } from "@/components/ui/badge";
|
|
14
15
|
import { Button } from "@/components/ui/button";
|
|
16
|
+
import { AlertDialog, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
|
|
15
17
|
import { CopyButton } from "@krak-stack/registry/copy-button";
|
|
16
18
|
import { Dialog, DialogFooter, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
|
17
19
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
@@ -19,6 +21,9 @@ import { Separator } from "@/components/ui/separator";
|
|
|
19
21
|
import { OrganizationEmail, OrganizationAddress, OrganizationMetadata, OrganizationPhone, OrganizationSocial, OrganizationTranslation, OrganizationWebsite, decodeOrganizationMetadata, } from "@krak-stack/auth/schema";
|
|
20
22
|
import { isOrganizationRole, normalizeOrganizationRole, normalizeOrganizationRoles, organizationRoles, parseRoleList, } from "../roles.js";
|
|
21
23
|
import { authClientApi, authHttpClient } from "./auth-client-api.js";
|
|
24
|
+
import { adminOrganizationsMessages } from "./admin-organizations.js";
|
|
25
|
+
import { deletionControlsEnabled } from "./deletion-visibility.js";
|
|
26
|
+
import { canDeleteOrganization, requestOrganizationDeletion, } from "./organization-deletion-request.js";
|
|
22
27
|
import { activeAuthOrganizationAtom, authOrganizationsAtom, authSessionAtom, notifyAuthChange, refreshOnAuthChange, } from "./auth-atoms.js";
|
|
23
28
|
import { useKrakstackAuth } from "./auth-provider.js";
|
|
24
29
|
import { parseApiKeyReferrers } from "./api-key.js";
|
|
@@ -26,13 +31,15 @@ import { ApiKeyPermissions } from "./api-key-permissions.js";
|
|
|
26
31
|
import { ApiKeyRateLimit, apiKeyUsagePercent } from "./api-key-rate-limit.js";
|
|
27
32
|
import { ApiKeyReferrers, apiKeyReferrers } from "./api-key-referrers.js";
|
|
28
33
|
import { ContactAddressesField, ContactEmailsField, ContactPhonesField, ContactSocialsField, ContactWebsitesField, } from "./contact-fields.js";
|
|
29
|
-
import { useOpenedOnce } from "./hooks.js";
|
|
34
|
+
import { useLatestAtom, useOpenedOnce } from "./hooks.js";
|
|
30
35
|
import { ScrollableDialogBody, ScrollableDialogContent, ScrollableDialogHeader, } from "./scrollable-dialog.js";
|
|
31
36
|
import { invitationDisplayStatus, isInvitationExpired, useInvitationExpirationClock, } from "./invitation-expiration.js";
|
|
32
37
|
import { ExtraUploadedAsset } from "../extra/schema.js";
|
|
33
38
|
import { assetPath, assetUrl, cn } from "./utils.js";
|
|
34
39
|
import { AssociatedProjectsNotice } from "./associated-projects-notice.js";
|
|
35
40
|
import { ExtraApiKeyPermissions } from "../extra/schema.js";
|
|
41
|
+
class OrganizationActionError extends Data.TaggedError("OrganizationActionError") {
|
|
42
|
+
}
|
|
36
43
|
const messages = {
|
|
37
44
|
en: {
|
|
38
45
|
organization_back: "Back",
|
|
@@ -480,11 +487,13 @@ const organizationFailureMessage = (cause, fallback) => {
|
|
|
480
487
|
};
|
|
481
488
|
const decodeUploadedAsset = Schema.decodeUnknownEffect(ExtraUploadedAsset);
|
|
482
489
|
const OrganizationMetadataRecord = Schema.Record(Schema.String, Schema.Json);
|
|
483
|
-
const normalizeOrganizationMetadata = (metadata) => Schema.
|
|
490
|
+
const normalizeOrganizationMetadata = (metadata) => Schema.decodeEffect(OrganizationMetadataRecord)(metadata);
|
|
484
491
|
const uploadImageAsset = (file, m, uploadImage) => {
|
|
485
492
|
const payload = new FormData();
|
|
486
493
|
payload.append("file", file);
|
|
487
|
-
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
|
+
})));
|
|
488
497
|
};
|
|
489
498
|
const currentOrganizationLocale = () => getLocale() === "fr" ? "fr" : "en";
|
|
490
499
|
const parseOrganizationMetadata = decodeOrganizationMetadata;
|
|
@@ -749,6 +758,8 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
749
758
|
payload: { organizationId },
|
|
750
759
|
})));
|
|
751
760
|
const [uncontrolledDialog, setUncontrolledDialog] = useState(defaultDialog);
|
|
761
|
+
const [deletingOrganization, setDeletingOrganization] = useState(null);
|
|
762
|
+
const deletionLabels = adminOrganizationsMessages(auth?.locale ?? "en");
|
|
752
763
|
const [editingOrganizationLocale, setEditingOrganizationLocale] = useState(currentOrganizationLocale);
|
|
753
764
|
const dialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
|
|
754
765
|
const invitationsAtom = userInvitationsAtom(baseUrl);
|
|
@@ -765,8 +776,8 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
765
776
|
});
|
|
766
777
|
const loadingUserInvitations = invitationsResult._tag === "Initial";
|
|
767
778
|
const activeMemberRoles = parseRoleList(activeOrganization?.members.find((member) => member.userId === session?.user.id)?.role);
|
|
768
|
-
const canManageApiKeys = activeMemberRoles.
|
|
769
|
-
const canUpdateOrganization =
|
|
779
|
+
const canManageApiKeys = activeMemberRoles.includes("owner");
|
|
780
|
+
const canUpdateOrganization = activeMemberRoles.some((role) => role === "owner" || role === "admin");
|
|
770
781
|
const canSwitchOrganizations = features?.organizationSwitching ?? true;
|
|
771
782
|
const canCreateOrganization = features?.organizationCreation ?? true;
|
|
772
783
|
const canViewOrganizationInvitations = features?.userInvitations ?? true;
|
|
@@ -818,7 +829,7 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
818
829
|
? { imageSrc: activeDisplay.image }
|
|
819
830
|
: {}) }), _jsx(ChevronsUpDown, { className: "text-muted-foreground size-4 shrink-0 group-data-[collapsible=icon]:hidden" })] }) }), _jsx(DropdownMenuContent, { className: "max-w-[calc(100vw-1rem)] min-w-64 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: activeDisplay.name, subtitle: activeSubtitle, icon: Building2, variant: "sidebar", className: "px-1 py-1.5 text-left text-sm", ...(activeDisplay.image
|
|
820
831
|
? { imageSrc: activeDisplay.image }
|
|
821
|
-
: {}) }) }), active ? (_jsx(
|
|
832
|
+
: {}) }) }), active ? (_jsx(AssociatedProjectsNotice, { baseUrl: baseUrl, getSummary: (count) => m.organization_projects_summary({ count }), organizationId: active.id, viewLabel: m.organization_projects_view() })) : null, menuActions ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), menuActions] })) : null, hasOrganizationListItems ? _jsx(DropdownMenuSeparator, {}) : null, organizationsResult._tag === "Initial" ? (_jsx(DropdownMenuItem, { disabled: true, children: m.organization_loading() })) : null, organizationsError ? (_jsx(DropdownMenuItem, { disabled: true, children: organizationsError })) : null, canSwitchOrganizations && selectableOrganizations.length ? (_jsx("div", { className: cn(scrollOrganizationList &&
|
|
822
833
|
"max-h-64 overflow-y-auto overscroll-contain"), children: selectableOrganizations.map((organization) => {
|
|
823
834
|
const display = organizationDisplay(organization, m, baseUrl);
|
|
824
835
|
return (_jsx(DropdownMenuItem, { onClick: async () => {
|
|
@@ -845,7 +856,15 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
845
856
|
return (_jsxs(DropdownMenuItem, { onClick: () => {
|
|
846
857
|
void navigator.clipboard.writeText(organizationId);
|
|
847
858
|
}, children: [_jsx(Copy, {}), m.organization_copy_id()] }));
|
|
848
|
-
})(), canUpdateOrganization ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), canManageApiKeys ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })) : null
|
|
859
|
+
})(), canUpdateOrganization ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), canManageApiKeys ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })) : null, deletionControlsEnabled &&
|
|
860
|
+
canDeleteOrganization(activeOrganization, session.user.id) ? (_jsxs(DropdownMenuItem, { variant: "destructive", onClick: () => setDeletingOrganization({
|
|
861
|
+
id: activeOrganization.id,
|
|
862
|
+
name: activeOrganization.name,
|
|
863
|
+
}), children: [_jsx(Trash2, {}), deletionLabels.organization_action_delete] })) : null] })) : null] }) })] })), deletionControlsEnabled && deletingOrganization ? (_jsx(OrganizationDeletionDialog, { baseUrl: baseUrl, organization: deletingOrganization, onClose: () => setDeletingOrganization(null), onDeleted: () => {
|
|
864
|
+
setDeletingOrganization(null);
|
|
865
|
+
setDialog(null);
|
|
866
|
+
onChange?.(null);
|
|
867
|
+
} }, deletingOrganization.id)) : null, _jsx(Dialog, { open: dialog === "create" && canCreateOrganization, onOpenChange: (open) => {
|
|
849
868
|
setDialog((current) => open ? "create" : current === "create" ? null : current);
|
|
850
869
|
}, children: _jsx(CreateOrganizationSection, { 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_create_title() }), _jsx(DialogDescription, { children: m.organization_create_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, onCreated: async (organization) => {
|
|
851
870
|
setDialog(null);
|
|
@@ -866,7 +885,7 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
866
885
|
setDialog((current) => open ? "manage" : current === "manage" ? null : current);
|
|
867
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) => {
|
|
868
887
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
869
|
-
}, 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: () => {
|
|
870
889
|
setDialog(null);
|
|
871
890
|
onChange?.(null);
|
|
872
891
|
} })) : null }) }), _jsx(Dialog, { open: dialog === "apiKeys" && canManageApiKeys, onOpenChange: (open) => {
|
|
@@ -879,6 +898,22 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
879
898
|
? { activeOrganizationId: activeOrganization.id }
|
|
880
899
|
: {}), onActionComplete: refreshAfterInvitationAction }) })] }) })] }));
|
|
881
900
|
}
|
|
901
|
+
const OrganizationDeletionDialog = ({ baseUrl, organization, onClose, onDeleted, }) => {
|
|
902
|
+
const auth = useKrakstackAuth();
|
|
903
|
+
const labels = adminOrganizationsMessages(auth?.locale ?? "en");
|
|
904
|
+
const m = useOrganizationMessages();
|
|
905
|
+
// Cross-project deletion cannot be predicted or rolled back on the client.
|
|
906
|
+
const [mutation] = useState(() => authClientApi(baseUrl).runtime.fn(() => requestOrganizationDeletion(organization.id, baseUrl).pipe(Effect.tap(() => Effect.sync(() => {
|
|
907
|
+
notifyAuthChange();
|
|
908
|
+
onDeleted();
|
|
909
|
+
})))));
|
|
910
|
+
const remove = useAtomSet(mutation);
|
|
911
|
+
const result = useAtomValue(mutation);
|
|
912
|
+
return (_jsx(AlertDialog, { open: true, onOpenChange: (open) => {
|
|
913
|
+
if (!open && !result.waiting)
|
|
914
|
+
onClose();
|
|
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 })] })] }) }));
|
|
916
|
+
};
|
|
882
917
|
function UserInvitationsManager({ baseUrl, invitations, loading, error, activeOrganizationId, onActionComplete, }) {
|
|
883
918
|
const m = useOrganizationMessages();
|
|
884
919
|
const [actingInvitationId, setActingInvitationId] = useState(null);
|
|
@@ -1002,7 +1037,9 @@ function EditOrganizationSection({ header, baseUrl, editingLocale, organization,
|
|
|
1002
1037
|
onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
|
|
1003
1038
|
const name = organizationNameFromForm(value, defaultLocale);
|
|
1004
1039
|
if (!name)
|
|
1005
|
-
return yield*
|
|
1040
|
+
return yield* new OrganizationActionError({
|
|
1041
|
+
message: m.organization_name_required(),
|
|
1042
|
+
});
|
|
1006
1043
|
const slug = value.slug.trim().toLowerCase();
|
|
1007
1044
|
const client = yield* authHttpClient(baseUrl);
|
|
1008
1045
|
const metadata = yield* organizationMetadataFromForm(value, m, (input) => client.authExtra.uploadUserImage(input), organization.metadata);
|
|
@@ -1019,9 +1056,12 @@ function EditOrganizationSection({ header, baseUrl, editingLocale, organization,
|
|
|
1019
1056
|
});
|
|
1020
1057
|
yield* Effect.sync(notifyAuthChange);
|
|
1021
1058
|
return updated;
|
|
1022
|
-
}).pipe(Effect.mapError((cause) =>
|
|
1023
|
-
|
|
1024
|
-
|
|
1059
|
+
}).pipe(Effect.mapError((cause) => new OrganizationActionError({
|
|
1060
|
+
message: cause instanceof Error
|
|
1061
|
+
? cause.message
|
|
1062
|
+
: m.organization_update_error(),
|
|
1063
|
+
cause: cause,
|
|
1064
|
+
}))),
|
|
1025
1065
|
}));
|
|
1026
1066
|
const submit = useAtomSet(form.submit);
|
|
1027
1067
|
const submitResult = useAtomValue(form.submit);
|
|
@@ -1061,7 +1101,9 @@ function CreateOrganizationSection({ header, baseUrl, editingLocale, onCreated,
|
|
|
1061
1101
|
onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
|
|
1062
1102
|
const name = organizationNameFromForm(value, defaultLocale);
|
|
1063
1103
|
if (!name)
|
|
1064
|
-
return yield*
|
|
1104
|
+
return yield* new OrganizationActionError({
|
|
1105
|
+
message: m.organization_name_required(),
|
|
1106
|
+
});
|
|
1065
1107
|
const slug = (value.slug.trim() || slugify(name)).toLowerCase();
|
|
1066
1108
|
const client = yield* authHttpClient(baseUrl);
|
|
1067
1109
|
const metadata = yield* organizationMetadataFromForm({ ...value, slug }, m, (input) => client.authExtra.uploadUserImage(input));
|
|
@@ -1069,18 +1111,28 @@ function CreateOrganizationSection({ header, baseUrl, editingLocale, onCreated,
|
|
|
1069
1111
|
const createPayload = { name, slug, metadata: normalizedMetadata };
|
|
1070
1112
|
const created = yield* client.auth
|
|
1071
1113
|
.organizationCreate({ payload: createPayload })
|
|
1072
|
-
.pipe(Effect.mapError((cause) => new
|
|
1073
|
-
|
|
1074
|
-
|
|
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
|
+
})));
|
|
1075
1119
|
yield* Effect.sync(notifyAuthChange);
|
|
1076
1120
|
yield* Effect.tryPromise({
|
|
1077
1121
|
try: () => onCreated(created),
|
|
1078
|
-
catch: (cause) =>
|
|
1122
|
+
catch: (cause) => new OrganizationActionError({
|
|
1123
|
+
message: cause instanceof Error
|
|
1124
|
+
? cause.message
|
|
1125
|
+
: m.organization_create_error(),
|
|
1126
|
+
cause,
|
|
1127
|
+
}),
|
|
1079
1128
|
});
|
|
1080
1129
|
return created;
|
|
1081
|
-
}).pipe(Effect.mapError((cause) =>
|
|
1082
|
-
|
|
1083
|
-
|
|
1130
|
+
}).pipe(Effect.mapError((cause) => new OrganizationActionError({
|
|
1131
|
+
message: cause instanceof Error
|
|
1132
|
+
? cause.message
|
|
1133
|
+
: m.organization_create_error(),
|
|
1134
|
+
cause: cause,
|
|
1135
|
+
}))),
|
|
1084
1136
|
}));
|
|
1085
1137
|
const submit = useAtomSet(form.submit);
|
|
1086
1138
|
const submitResult = useAtomValue(form.submit);
|
|
@@ -1150,7 +1202,6 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
|
|
|
1150
1202
|
const [error, setError] = useState(null);
|
|
1151
1203
|
const [cancellingInvitationId, setCancellingInvitationId] = useState(null);
|
|
1152
1204
|
const [leavingOrganization, setLeavingOrganization] = useState(false);
|
|
1153
|
-
const [lastMembersData, setLastMembersData] = useState(null);
|
|
1154
1205
|
const currentMembers = AsyncResult.match(membersResult, {
|
|
1155
1206
|
onInitial: () => null,
|
|
1156
1207
|
onFailure: () => null,
|
|
@@ -1161,6 +1212,7 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
|
|
|
1161
1212
|
onFailure: () => null,
|
|
1162
1213
|
onSuccess: ({ value }) => value,
|
|
1163
1214
|
});
|
|
1215
|
+
const [lastMembersData, setLastMembersData] = useState(null);
|
|
1164
1216
|
const currentMembersData = currentMembers && currentInvitations
|
|
1165
1217
|
? {
|
|
1166
1218
|
members: Array.from(currentMembers),
|
|
@@ -1168,7 +1220,7 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
|
|
|
1168
1220
|
}
|
|
1169
1221
|
: null;
|
|
1170
1222
|
const membersData = currentMembersData ??
|
|
1171
|
-
lastMembersData ?? {
|
|
1223
|
+
lastMembersData?.data ?? {
|
|
1172
1224
|
members: [],
|
|
1173
1225
|
invitations: [],
|
|
1174
1226
|
};
|
|
@@ -1195,14 +1247,15 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
|
|
|
1195
1247
|
(membersResult._tag === "Initial" || invitationsResult._tag === "Initial");
|
|
1196
1248
|
const canInviteMembers = canManageMembers;
|
|
1197
1249
|
const canRemoveMembers = canManageMembers;
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1250
|
+
if (currentMembersData &&
|
|
1251
|
+
(lastMembersData?.members !== currentMembers ||
|
|
1252
|
+
lastMembersData?.invitations !== currentInvitations)) {
|
|
1201
1253
|
setLastMembersData({
|
|
1202
|
-
members:
|
|
1203
|
-
invitations:
|
|
1254
|
+
members: currentMembers,
|
|
1255
|
+
invitations: currentInvitations,
|
|
1256
|
+
data: currentMembersData,
|
|
1204
1257
|
});
|
|
1205
|
-
}
|
|
1258
|
+
}
|
|
1206
1259
|
const [inviteForm] = useState(() => FormReact.make(inviteMemberFormBuilder, {
|
|
1207
1260
|
runtime: authClientApi(baseUrl).runtime,
|
|
1208
1261
|
fields: {
|
|
@@ -1215,19 +1268,22 @@ function OrganizationMembersManager({ baseUrl, canManageMembers, organization, c
|
|
|
1215
1268
|
role: normalizeInvitationRole(value.role),
|
|
1216
1269
|
organizationId: organization.id,
|
|
1217
1270
|
},
|
|
1218
|
-
})), Effect.tap(() => Effect.sync(refreshInvitations)), Effect.mapError((cause) =>
|
|
1219
|
-
|
|
1220
|
-
|
|
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
|
+
}))),
|
|
1221
1277
|
}));
|
|
1222
1278
|
const submitInvitation = useAtomSet(inviteForm.submit);
|
|
1223
1279
|
const resetInvitation = useAtomSet(inviteForm.reset);
|
|
1224
1280
|
const inviteResult = useAtomValue(inviteForm.submit);
|
|
1225
|
-
|
|
1226
|
-
if (!AsyncResult.isSuccess(
|
|
1281
|
+
useAtomSubscribe(inviteForm.submit, (result) => {
|
|
1282
|
+
if (!AsyncResult.isSuccess(result))
|
|
1227
1283
|
return;
|
|
1228
1284
|
resetInvitation();
|
|
1229
1285
|
setInviting(false);
|
|
1230
|
-
}
|
|
1286
|
+
});
|
|
1231
1287
|
const updateRole = async (member, role) => {
|
|
1232
1288
|
setError(null);
|
|
1233
1289
|
const nextRole = Array.isArray(role)
|
|
@@ -1457,10 +1513,8 @@ function OrganizationApiKeyManager({ baseUrl, locale, organization, active, perm
|
|
|
1457
1513
|
const [error, setError] = useState(null);
|
|
1458
1514
|
const permissionOptions = organizationApiKeyPermissionOptions(permissions);
|
|
1459
1515
|
const [selectedPermissions, setSelectedPermissions] = useState({});
|
|
1460
|
-
const
|
|
1461
|
-
const
|
|
1462
|
-
permissionOptionsRef.current = permissionOptions;
|
|
1463
|
-
selectedPermissionsRef.current = selectedPermissions;
|
|
1516
|
+
const permissionOptionsAtom = useLatestAtom(permissionOptions);
|
|
1517
|
+
const selectedPermissionsAtom = useLatestAtom(selectedPermissions);
|
|
1464
1518
|
const keys = AsyncResult.match(keysResult, {
|
|
1465
1519
|
onInitial: () => [],
|
|
1466
1520
|
onFailure: () => [],
|
|
@@ -1475,7 +1529,7 @@ function OrganizationApiKeyManager({ baseUrl, locale, organization, active, perm
|
|
|
1475
1529
|
const [createForm] = useState(() => FormReact.make(apiKeyFormBuilder, {
|
|
1476
1530
|
runtime: authClientApi(baseUrl).runtime,
|
|
1477
1531
|
fields: { name: TextField, referrers: TextAreaField },
|
|
1478
|
-
onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
|
|
1532
|
+
onSubmit: (_, { decoded: value, get }) => Effect.gen(function* () {
|
|
1479
1533
|
yield* Effect.sync(() => setCreatedKey(null));
|
|
1480
1534
|
const client = yield* authHttpClient(baseUrl);
|
|
1481
1535
|
const created = yield* client.authExtra.createApiKey({
|
|
@@ -1483,7 +1537,7 @@ function OrganizationApiKeyManager({ baseUrl, locale, organization, active, perm
|
|
|
1483
1537
|
configId: "organization",
|
|
1484
1538
|
organizationId: organization.id,
|
|
1485
1539
|
name: value.name.trim(),
|
|
1486
|
-
permissions: organizationApiKeySelectedPermissions(
|
|
1540
|
+
permissions: organizationApiKeySelectedPermissions(get(permissionOptionsAtom), get(selectedPermissionsAtom)),
|
|
1487
1541
|
referrers: parseApiKeyReferrers(value.referrers, m.user_api_key_referrers_error()),
|
|
1488
1542
|
},
|
|
1489
1543
|
});
|
|
@@ -1493,9 +1547,12 @@ function OrganizationApiKeyManager({ baseUrl, locale, organization, active, perm
|
|
|
1493
1547
|
refreshKeys();
|
|
1494
1548
|
});
|
|
1495
1549
|
return created;
|
|
1496
|
-
}).pipe(Effect.mapError((cause) =>
|
|
1497
|
-
|
|
1498
|
-
|
|
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
|
+
}))),
|
|
1499
1556
|
}));
|
|
1500
1557
|
const submitApiKey = useAtomSet(createForm.submit);
|
|
1501
1558
|
const resetApiKey = useAtomSet(createForm.reset);
|
|
@@ -1583,7 +1640,7 @@ function OrganizationApiKeyEditForm({ baseUrl, keyData, messages, permissions, p
|
|
|
1583
1640
|
project,
|
|
1584
1641
|
action,
|
|
1585
1642
|
})));
|
|
1586
|
-
const currentPermissions = Schema.
|
|
1643
|
+
const currentPermissions = Schema.decodeOption(ExtraApiKeyPermissions)(keyData.permissions ?? {});
|
|
1587
1644
|
const currentGrant = Option.isSome(currentPermissions)
|
|
1588
1645
|
? currentPermissions.value
|
|
1589
1646
|
: {};
|
|
@@ -1591,10 +1648,8 @@ function OrganizationApiKeyEditForm({ baseUrl, keyData, messages, permissions, p
|
|
|
1591
1648
|
option.id,
|
|
1592
1649
|
currentGrant[option.project]?.includes(option.action) ?? false,
|
|
1593
1650
|
]));
|
|
1594
|
-
const
|
|
1595
|
-
const
|
|
1596
|
-
permissionOptionsRef.current = permissionOptions;
|
|
1597
|
-
permissionsRef.current = permissions;
|
|
1651
|
+
const permissionOptionsAtom = useLatestAtom(permissionOptions);
|
|
1652
|
+
const permissionsAtom = useLatestAtom(permissions);
|
|
1598
1653
|
const [form] = useState(() => FormReact.make(editApiKeyFormBuilder, {
|
|
1599
1654
|
runtime: authClientApi(baseUrl).runtime,
|
|
1600
1655
|
fields: {
|
|
@@ -1604,13 +1659,13 @@ function OrganizationApiKeyEditForm({ baseUrl, keyData, messages, permissions, p
|
|
|
1604
1659
|
permissions: ApiKeyPermissionsField,
|
|
1605
1660
|
},
|
|
1606
1661
|
mode: { validation: "onSubmit" },
|
|
1607
|
-
onSubmit: (_, { decoded }) => Effect.gen(function* () {
|
|
1662
|
+
onSubmit: (_, { decoded, get }) => Effect.gen(function* () {
|
|
1608
1663
|
const referrers = parseApiKeyReferrers(decoded.referrers, messages.referrersError);
|
|
1609
1664
|
const selectedGrant = {};
|
|
1610
|
-
for (const project of Object.keys(
|
|
1665
|
+
for (const project of Object.keys(get(permissionsAtom))) {
|
|
1611
1666
|
selectedGrant[project] = [];
|
|
1612
1667
|
}
|
|
1613
|
-
for (const option of
|
|
1668
|
+
for (const option of get(permissionOptionsAtom)) {
|
|
1614
1669
|
if (!decoded.permissions[option.id])
|
|
1615
1670
|
continue;
|
|
1616
1671
|
selectedGrant[option.project] = [
|
|
@@ -1631,9 +1686,12 @@ function OrganizationApiKeyEditForm({ baseUrl, keyData, messages, permissions, p
|
|
|
1631
1686
|
});
|
|
1632
1687
|
yield* Effect.sync(onSaved);
|
|
1633
1688
|
return updated;
|
|
1634
|
-
}).pipe(Effect.mapError((cause) =>
|
|
1635
|
-
|
|
1636
|
-
|
|
1689
|
+
}).pipe(Effect.mapError((cause) => new OrganizationActionError({
|
|
1690
|
+
message: cause instanceof Error
|
|
1691
|
+
? cause.message
|
|
1692
|
+
: organizationFailureMessage(cause, messages.updateError),
|
|
1693
|
+
cause: cause,
|
|
1694
|
+
}))),
|
|
1637
1695
|
}));
|
|
1638
1696
|
const submit = useAtomSet(form.submit);
|
|
1639
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))) }));
|
|
@@ -4,6 +4,20 @@ import { DropdownMenuContent } from "@/components/ui/dropdown-menu";
|
|
|
4
4
|
import { type ContactEmail as ContactEmailValue, type ContactPhone as ContactPhoneValue, type ContactSocial as ContactSocialValue, type ContactWebsite as ContactWebsiteValue, UserMetadata } from "../schema.js";
|
|
5
5
|
declare const messages: {
|
|
6
6
|
readonly en: {
|
|
7
|
+
readonly user_delete_title: "Delete account";
|
|
8
|
+
readonly user_delete_description: "Permanently delete your account and unshared personal organizations. This cannot be undone.";
|
|
9
|
+
readonly user_delete_projects: "Connected projects";
|
|
10
|
+
readonly user_delete_organizations: "Organizations to resolve";
|
|
11
|
+
readonly user_delete_retention: "Project cleanup is requested separately. Legal retention may apply.";
|
|
12
|
+
readonly user_delete_missing: "Some projects need support to complete cleanup.";
|
|
13
|
+
readonly user_delete_owner: "Transfer ownership or delete these in the organization switcher. Shared personal organizations need support.";
|
|
14
|
+
readonly user_delete_admin: "Remove your platform admin role before continuing.";
|
|
15
|
+
readonly user_delete_confirm: "Type DELETE to confirm";
|
|
16
|
+
readonly user_delete_password: "Current password (if required)";
|
|
17
|
+
readonly user_delete_error: "Unable to delete your account. Check your password, or sign in again and retry.";
|
|
18
|
+
readonly user_delete_load_error: "Loading requirements… Close and retry if this takes too long.";
|
|
19
|
+
readonly user_delete_complete: "Your account is deleted. Project cleanup may still be pending; retained records are not necessarily erased.";
|
|
20
|
+
readonly user_delete_done: "Done";
|
|
7
21
|
readonly table_empty: "No results.";
|
|
8
22
|
readonly user_account_cancel: "Cancel";
|
|
9
23
|
readonly user_account_back: "Back";
|
|
@@ -149,6 +163,20 @@ declare const messages: {
|
|
|
149
163
|
readonly user_two_factor_verify_error: "Could not verify the code.";
|
|
150
164
|
};
|
|
151
165
|
readonly fr: {
|
|
166
|
+
readonly user_delete_title: "Supprimer le compte";
|
|
167
|
+
readonly user_delete_description: "Supprimez définitivement votre compte et vos organisations personnelles non partagées. Cette action est irréversible.";
|
|
168
|
+
readonly user_delete_projects: "Projets liés";
|
|
169
|
+
readonly user_delete_organizations: "Organisations à régler";
|
|
170
|
+
readonly user_delete_retention: "Le nettoyage des projets est demandé séparément. Une conservation légale peut s’appliquer.";
|
|
171
|
+
readonly user_delete_missing: "Certains projets nécessitent l’assistance pour terminer le nettoyage.";
|
|
172
|
+
readonly user_delete_owner: "Transférez la propriété ou supprimez ces organisations dans le sélecteur. Les organisations personnelles partagées nécessitent l’assistance.";
|
|
173
|
+
readonly user_delete_admin: "Retirez votre rôle administrateur de plateforme avant de continuer.";
|
|
174
|
+
readonly user_delete_confirm: "Saisissez DELETE pour confirmer";
|
|
175
|
+
readonly user_delete_password: "Mot de passe actuel (si nécessaire)";
|
|
176
|
+
readonly user_delete_error: "Impossible de supprimer le compte. Vérifiez votre mot de passe ou reconnectez-vous, puis réessayez.";
|
|
177
|
+
readonly user_delete_load_error: "Chargement des conditions… Fermez et réessayez si l’attente se prolonge.";
|
|
178
|
+
readonly user_delete_complete: "Votre compte est supprimé. Le nettoyage des projets peut être en attente ; les données conservées ne sont pas nécessairement effacées.";
|
|
179
|
+
readonly user_delete_done: "Terminé";
|
|
152
180
|
readonly table_empty: "Aucun résultat.";
|
|
153
181
|
readonly user_account_cancel: "Annuler";
|
|
154
182
|
readonly user_account_back: "Retour";
|
|
@@ -350,6 +378,6 @@ export type UserButtonProps = {
|
|
|
350
378
|
dialog?: UserButtonDialog | null;
|
|
351
379
|
onDialogChange?: (dialog: UserButtonDialog | null) => void;
|
|
352
380
|
};
|
|
353
|
-
export type UserButtonDialog = "account" | "security" | "apiKeys" | "adminUsers" | "adminOrganizations";
|
|
381
|
+
export type UserButtonDialog = "deleteAccount" | "account" | "security" | "apiKeys" | "adminUsers" | "adminOrganizations";
|
|
354
382
|
export declare const UserButton: ({ baseUrl, signOutRedirect, side, defaultDialog, hideTrigger, renderUnauthenticated, menuActions, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }: UserButtonProps) => import("react").JSX.Element;
|
|
355
383
|
export {};
|