@krak-stack/auth 0.2.31 → 0.2.32
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 +11 -0
- package/README.md +79 -1
- package/dist/api.d.ts +1453 -1393
- package/dist/auth/api.group.d.ts +19 -1
- package/dist/auth/api.group.js +17 -1
- package/dist/auth/schema.d.ts +12 -0
- package/dist/auth/schema.js +12 -0
- 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-organizations.js +3 -2
- package/dist/components/associated-projects-notice.js +1 -1
- package/dist/components/auth-client-api.d.ts +33 -0
- package/dist/components/deletion-visibility.d.ts +1 -0
- package/dist/components/deletion-visibility.js +3 -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.js +31 -2
- package/dist/components/user-button.d.ts +29 -1
- package/dist/components/user-button.js +39 -2
- package/dist/extra/api.group.d.ts +13 -1
- package/dist/extra/api.group.js +5 -1
- package/dist/extra/schema.d.ts +13 -0
- package/dist/extra/schema.js +13 -0
- package/dist/schema.d.ts +35 -0
- package/dist/schema.js +25 -0
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +1 -0
- package/dist/server/middleware.d.ts +10 -2
- package/dist/server/middleware.js +4 -1
- package/dist/server/webhook-layer.d.ts +6 -0
- package/dist/server/webhook-layer.js +37 -0
- package/dist/server/webhooks.d.ts +38 -0
- package/dist/server/webhooks.js +39 -0
- package/dist/service.d.ts +66 -0
- package/package.json +7 -3
package/dist/auth/api.group.d.ts
CHANGED
|
@@ -327,7 +327,14 @@ export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndp
|
|
|
327
327
|
readonly createdAt: Schema.DateFromString;
|
|
328
328
|
readonly updatedAt: Schema.DateFromString;
|
|
329
329
|
}>;
|
|
330
|
-
}>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthConflict | typeof AuthExpectationFailed | typeof AuthTooManyRequests | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"
|
|
330
|
+
}>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthConflict | typeof AuthExpectationFailed | typeof AuthTooManyRequests | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"deleteUser", "POST", "/delete-user", never, never, Schema.toCodecJson<Schema.Struct<{
|
|
331
|
+
readonly password: Schema.optional<Schema.String>;
|
|
332
|
+
readonly token: Schema.optional<Schema.String>;
|
|
333
|
+
readonly callbackURL: Schema.optional<Schema.String>;
|
|
334
|
+
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
335
|
+
readonly success: Schema.Boolean;
|
|
336
|
+
readonly message: Schema.String;
|
|
337
|
+
}>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getSession", "GET", "/get-session", never, Schema.toCodecStringTree<Schema.Struct<{
|
|
331
338
|
readonly disableCookieCache: Schema.optional<Schema.String>;
|
|
332
339
|
readonly disableRefresh: Schema.optional<Schema.String>;
|
|
333
340
|
}>>, never, never, Schema.toCodecJson<Schema.NullOr<Schema.Struct<{
|
|
@@ -537,6 +544,17 @@ export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndp
|
|
|
537
544
|
readonly userId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
538
545
|
readonly parentId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
539
546
|
readonly createdAt: Schema.DateFromString;
|
|
547
|
+
}>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthConflict | typeof AuthExpectationFailed | typeof AuthTooManyRequests | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"organizationDelete", "POST", "/organization/delete", never, never, Schema.toCodecJson<Schema.Struct<{
|
|
548
|
+
readonly organizationId: Schema.NonEmptyString;
|
|
549
|
+
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
550
|
+
readonly id: Schema.String;
|
|
551
|
+
readonly name: Schema.String;
|
|
552
|
+
readonly slug: Schema.String;
|
|
553
|
+
readonly logo: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
554
|
+
readonly metadata: Schema.optional<Schema.NullOr<Schema.Union<readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.String]>>>;
|
|
555
|
+
readonly userId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
556
|
+
readonly parentId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
557
|
+
readonly createdAt: Schema.DateFromString;
|
|
540
558
|
}>>, Schema.toCodecJson<typeof AuthBadRequest | typeof AuthUnauthorized | typeof AuthForbidden | typeof AuthNotFound | typeof AuthConflict | typeof AuthExpectationFailed | typeof AuthTooManyRequests | typeof AuthInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"organizationGetFull", "GET", "/organization/get-full-organization", never, Schema.toCodecStringTree<Schema.Struct<{
|
|
541
559
|
readonly organizationId: Schema.optional<Schema.String>;
|
|
542
560
|
readonly organizationSlug: Schema.optional<Schema.String>;
|
package/dist/auth/api.group.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api";
|
|
3
|
-
import { AdminBanUserPayload, AdminStopImpersonatingPayload, AdminUserIdPayload, AdminUserResponse, AuthBadRequest, AuthConflict, AuthExpectationFailed, AuthForbidden, AuthInternalServerError, AuthInvitation, AuthNotFound, AuthOrganization, AuthSessionResponse, AuthStatusResponse, AuthSuccessResponse, AuthTooManyRequests, AuthUnauthorized, ChangePasswordPayload, ChangePasswordResponse, CreateOrganizationPayload, DeleteApiKeyPayload, FullAuthOrganization, GetFullOrganizationQuery, GetInvitationQuery, GetInvitationResponse, GetSessionQuery, GetSessionResponse, InvitationActionResponse, InvitationIdPayload, InviteMemberPayload, LeaveOrganizationPayload, LinkedAccount, LinkSocialPayload, ListApiKeysQuery, ListApiKeysResponse, MemberResponse, OAuthConsentPayload, OAuthPublicClient, OAuthPublicClientQuery, OAuthRedirectResponse, OrganizationImpersonateUserPayload, OrganizationImpersonateUserResponse, OrganizationInvitationsQuery, OrganizationListMembersQuery, OrganizationListMembersResponse, RemoveMemberPayload, RequestPasswordResetPayload, RequestPasswordResetResponse, ResetPasswordPayload, SendVerificationOtpPayload, SetActiveOrganizationPayload, SignInEmailOtpPayload, SignInEmailPayload, SignInEmailResponse, SignInResponse, SignInSocialPayload, SignOutPayload, SocialRedirectResponse, TwoFactorBackupVerifyPayload, TwoFactorDisablePayload, TwoFactorEnablePayload, TwoFactorEnableResponse, TwoFactorSendPayload, TwoFactorVerifyPayload, UnlinkAccountPayload, UpdateMemberRolePayload, UpdateOrganizationPayload, UpdateUserPayload, UserInvitationsQuery, VerifyEmailOtpPayload, VerifyEmailOtpResponse, } from "./schema.js";
|
|
3
|
+
import { DeleteUserPayload, DeleteOrganizationPayload, DeleteUserResponse, AdminBanUserPayload, AdminStopImpersonatingPayload, AdminUserIdPayload, AdminUserResponse, AuthBadRequest, AuthConflict, AuthExpectationFailed, AuthForbidden, AuthInternalServerError, AuthInvitation, AuthNotFound, AuthOrganization, AuthSessionResponse, AuthStatusResponse, AuthSuccessResponse, AuthTooManyRequests, AuthUnauthorized, ChangePasswordPayload, ChangePasswordResponse, CreateOrganizationPayload, DeleteApiKeyPayload, FullAuthOrganization, GetFullOrganizationQuery, GetInvitationQuery, GetInvitationResponse, GetSessionQuery, GetSessionResponse, InvitationActionResponse, InvitationIdPayload, InviteMemberPayload, LeaveOrganizationPayload, LinkedAccount, LinkSocialPayload, ListApiKeysQuery, ListApiKeysResponse, MemberResponse, OAuthConsentPayload, OAuthPublicClient, OAuthPublicClientQuery, OAuthRedirectResponse, OrganizationImpersonateUserPayload, OrganizationImpersonateUserResponse, OrganizationInvitationsQuery, OrganizationListMembersQuery, OrganizationListMembersResponse, RemoveMemberPayload, RequestPasswordResetPayload, RequestPasswordResetResponse, ResetPasswordPayload, SendVerificationOtpPayload, SetActiveOrganizationPayload, SignInEmailOtpPayload, SignInEmailPayload, SignInEmailResponse, SignInResponse, SignInSocialPayload, SignOutPayload, SocialRedirectResponse, TwoFactorBackupVerifyPayload, TwoFactorDisablePayload, TwoFactorEnablePayload, TwoFactorEnableResponse, TwoFactorSendPayload, TwoFactorVerifyPayload, UnlinkAccountPayload, UpdateMemberRolePayload, UpdateOrganizationPayload, UpdateUserPayload, UserInvitationsQuery, VerifyEmailOtpPayload, VerifyEmailOtpResponse, } from "./schema.js";
|
|
4
4
|
export * from "./schema.js";
|
|
5
5
|
const errors = [
|
|
6
6
|
AuthBadRequest,
|
|
@@ -14,6 +14,17 @@ const errors = [
|
|
|
14
14
|
];
|
|
15
15
|
const docs = (title, description) => OpenApi.annotations({ title, summary: title, description });
|
|
16
16
|
export const AuthApiGroup = HttpApiGroup.make("auth")
|
|
17
|
+
.add(HttpApiEndpoint.post("deleteUser", "/delete-user", {
|
|
18
|
+
payload: DeleteUserPayload,
|
|
19
|
+
success: DeleteUserResponse,
|
|
20
|
+
error: [
|
|
21
|
+
AuthBadRequest,
|
|
22
|
+
AuthUnauthorized,
|
|
23
|
+
AuthForbidden,
|
|
24
|
+
AuthNotFound,
|
|
25
|
+
AuthInternalServerError,
|
|
26
|
+
],
|
|
27
|
+
}))
|
|
17
28
|
.add(HttpApiEndpoint.get("getSession", "/get-session", {
|
|
18
29
|
query: GetSessionQuery.fields,
|
|
19
30
|
success: GetSessionResponse,
|
|
@@ -132,6 +143,11 @@ export const AuthApiGroup = HttpApiGroup.make("auth")
|
|
|
132
143
|
success: AuthOrganization,
|
|
133
144
|
error: errors,
|
|
134
145
|
}).annotateMerge(docs("Create organization", "Creates an organization.")))
|
|
146
|
+
.add(HttpApiEndpoint.post("organizationDelete", "/organization/delete", {
|
|
147
|
+
payload: DeleteOrganizationPayload,
|
|
148
|
+
success: AuthOrganization,
|
|
149
|
+
error: errors,
|
|
150
|
+
}).annotateMerge(docs("Delete organization", "Permanently deletes an organization owned by the current user. Personal organizations are protected.")))
|
|
135
151
|
.add(HttpApiEndpoint.post("organizationUpdate", "/organization/update", {
|
|
136
152
|
payload: UpdateOrganizationPayload,
|
|
137
153
|
success: AuthOrganization,
|
package/dist/auth/schema.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
+
export declare const DeleteUserPayload: Schema.Struct<{
|
|
3
|
+
readonly password: Schema.optional<Schema.String>;
|
|
4
|
+
readonly token: Schema.optional<Schema.String>;
|
|
5
|
+
readonly callbackURL: Schema.optional<Schema.String>;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const DeleteUserResponse: Schema.Struct<{
|
|
8
|
+
readonly success: Schema.Boolean;
|
|
9
|
+
readonly message: Schema.String;
|
|
10
|
+
}>;
|
|
2
11
|
export declare const AuthRedirectURLFromString: (origin?: string) => Schema.decodeTo<Schema.URL, Schema.String, never, never>;
|
|
3
12
|
export declare const AuthUser: Schema.Struct<{
|
|
4
13
|
readonly id: Schema.String;
|
|
@@ -991,6 +1000,9 @@ export declare const RemoveMemberPayload: Schema.Struct<{
|
|
|
991
1000
|
readonly memberIdOrEmail: Schema.String;
|
|
992
1001
|
readonly organizationId: Schema.optional<Schema.String>;
|
|
993
1002
|
}>;
|
|
1003
|
+
export declare const DeleteOrganizationPayload: Schema.Struct<{
|
|
1004
|
+
readonly organizationId: Schema.NonEmptyString;
|
|
1005
|
+
}>;
|
|
994
1006
|
export declare const LeaveOrganizationPayload: Schema.Struct<{
|
|
995
1007
|
readonly organizationId: Schema.String;
|
|
996
1008
|
}>;
|
package/dist/auth/schema.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { Effect, Schema, SchemaIssue, SchemaTransformation } from "effect";
|
|
2
|
+
export const DeleteUserPayload = Schema.Struct({
|
|
3
|
+
password: Schema.optional(Schema.String),
|
|
4
|
+
token: Schema.optional(Schema.String),
|
|
5
|
+
callbackURL: Schema.optional(Schema.String),
|
|
6
|
+
}).annotate({ identifier: "DeleteUserPayload" });
|
|
7
|
+
export const DeleteUserResponse = Schema.Struct({
|
|
8
|
+
success: Schema.Boolean,
|
|
9
|
+
message: Schema.String,
|
|
10
|
+
}).annotate({ identifier: "DeleteUserResponse" });
|
|
2
11
|
import { User, UserLocale, UserMetadata } from "../schema.js";
|
|
3
12
|
const JsonRecord = Schema.Record(Schema.String, Schema.Json);
|
|
4
13
|
const StringArrayRecord = Schema.Record(Schema.String, Schema.Array(Schema.String));
|
|
@@ -501,6 +510,9 @@ export const RemoveMemberPayload = Schema.Struct({
|
|
|
501
510
|
identifier: "RemoveMemberPayload",
|
|
502
511
|
title: "Remove member payload",
|
|
503
512
|
});
|
|
513
|
+
export const DeleteOrganizationPayload = Schema.Struct({
|
|
514
|
+
organizationId: Schema.NonEmptyString,
|
|
515
|
+
}).annotate({ identifier: "DeleteOrganizationPayload" });
|
|
504
516
|
export const LeaveOrganizationPayload = Schema.Struct({
|
|
505
517
|
organizationId: Schema.String,
|
|
506
518
|
}).annotate({
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
export declare const requestAccountDeletion: (password: string, baseUrl?: string) => Effect.Effect<{
|
|
3
|
+
readonly success: boolean;
|
|
4
|
+
readonly message: string;
|
|
5
|
+
}, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthUnauthorized | import("effect/http/HttpClientError").HttpClientError | import("effect/Schema").SchemaError, never>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { authHttpClient } from "./auth-client-api.js";
|
|
3
|
+
export const requestAccountDeletion = (password, baseUrl) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.deleteUser({
|
|
4
|
+
// Better Auth accepts an absent password, not null. Explicit undefined
|
|
5
|
+
// values are encoded as null by the HTTP API's JSON codec.
|
|
6
|
+
payload: password ? { password } : {},
|
|
7
|
+
})));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type AccountDeletionLabels = Record<"title" | "description" | "projects" | "organizations" | "retention" | "missing" | "owner" | "admin" | "confirm" | "password" | "error" | "loadError" | "cancel" | "submit" | "done" | "complete", string>;
|
|
2
|
+
export declare const AccountDeletionDialog: (props: {
|
|
3
|
+
baseUrl?: string | undefined;
|
|
4
|
+
userId: string;
|
|
5
|
+
labels: AccountDeletionLabels;
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
onDeleted: () => void;
|
|
8
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
3
|
+
import { AsyncResult, Atom } from "effect/reactivity";
|
|
4
|
+
import { Schema } from "effect";
|
|
5
|
+
import { useId, useState } from "react";
|
|
6
|
+
import { AppWindow, Building2, TriangleAlert, UserRound } from "lucide-react";
|
|
7
|
+
import { Button } from "@/components/ui/button";
|
|
8
|
+
import { Card, CardContent } from "@/components/ui/card";
|
|
9
|
+
import { Input } from "@/components/ui/input";
|
|
10
|
+
import { FieldLabel } from "@/components/ui/field";
|
|
11
|
+
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, } from "@/components/ui/dialog";
|
|
12
|
+
import { authClientApi } from "./auth-client-api.js";
|
|
13
|
+
import { requestAccountDeletion } from "./account-deletion-request.js";
|
|
14
|
+
import { refreshOnAuthChange } from "./auth-atoms.js";
|
|
15
|
+
const planQueries = Atom.family((baseUrl) => Atom.family((userId) => authClientApi(baseUrl)
|
|
16
|
+
.query("authExtra", "getAccountDeletionPlan", {
|
|
17
|
+
timeToLive: "0 seconds",
|
|
18
|
+
serializationKey: `account-deletion:${userId}`,
|
|
19
|
+
})
|
|
20
|
+
.pipe(refreshOnAuthChange)));
|
|
21
|
+
const plans = Atom.family((baseUrl) => Atom.family((userId) => Atom.optimistic(planQueries(baseUrl)(userId))));
|
|
22
|
+
export const AccountDeletionDialog = (props) => {
|
|
23
|
+
const [confirmation, setConfirmation] = useState("");
|
|
24
|
+
const passwordId = useId();
|
|
25
|
+
const confirmationId = useId();
|
|
26
|
+
const projectsId = useId();
|
|
27
|
+
const organizationsId = useId();
|
|
28
|
+
const [password, setPassword] = useState("");
|
|
29
|
+
const planResult = useAtomValue(plans(props.baseUrl)(props.userId));
|
|
30
|
+
const [mutation] = useState(() => authClientApi(props.baseUrl).runtime.fn((password) => requestAccountDeletion(password, props.baseUrl)));
|
|
31
|
+
const remove = useAtomSet(mutation);
|
|
32
|
+
const result = useAtomValue(mutation);
|
|
33
|
+
const plan = AsyncResult.match(planResult, {
|
|
34
|
+
onInitial: () => null,
|
|
35
|
+
onFailure: () => null,
|
|
36
|
+
onSuccess: ({ value }) => value,
|
|
37
|
+
});
|
|
38
|
+
const completed = AsyncResult.isSuccess(result) && result.value.success;
|
|
39
|
+
const blockedByOrganizations = (plan?.organizations.length ?? 0) > 0;
|
|
40
|
+
const busy = result.waiting;
|
|
41
|
+
const disabled = !plan ||
|
|
42
|
+
plan.organizations.length > 0 ||
|
|
43
|
+
plan.adminAccount ||
|
|
44
|
+
!Schema.is(Schema.Literal("DELETE"))(confirmation) ||
|
|
45
|
+
busy;
|
|
46
|
+
const labels = props.labels;
|
|
47
|
+
return (_jsx(Dialog, { open: true, onOpenChange: (open) => {
|
|
48
|
+
if (!open && !busy) {
|
|
49
|
+
if (completed)
|
|
50
|
+
props.onDeleted();
|
|
51
|
+
else
|
|
52
|
+
props.onClose();
|
|
53
|
+
}
|
|
54
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: labels.title }), _jsx(DialogDescription, { children: completed ? labels.complete : labels.description })] }), completed ? (_jsx(Button, { onClick: props.onDeleted, children: labels.done })) : (_jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
if (!disabled)
|
|
57
|
+
remove(password);
|
|
58
|
+
}, children: [plan ? (_jsxs(_Fragment, { children: [plan.projects.length ? (_jsxs("section", { "aria-labelledby": projectsId, className: "space-y-2", children: [_jsxs("h3", { id: projectsId, className: "text-muted-foreground text-xs font-medium", children: [labels.projects, " ", _jsx("span", { className: "ml-1 tabular-nums", children: plan.projects.length })] }), _jsx("ul", { className: "grid gap-2 sm:grid-cols-2", children: plan.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.ready ? (_jsxs("span", { title: labels.missing, className: "text-muted-foreground shrink-0", children: [_jsx(TriangleAlert, { "aria-hidden": "true", className: "size-4" }), _jsx("span", { className: "sr-only", children: labels.missing })] })) : null] }) }) }, project.id))) }), plan.projects.some((project) => !project.ready) ? (_jsx("p", { role: "status", className: "text-muted-foreground text-xs", children: labels.missing })) : null] })) : null, plan.organizations.length ? (_jsxs("section", { "aria-labelledby": organizationsId, className: "space-y-2", children: [_jsxs("h3", { id: organizationsId, className: "text-destructive text-xs font-medium", children: [labels.organizations, " ", _jsx("span", { className: "ml-1 tabular-nums", children: plan.organizations.length })] }), _jsx("ul", { className: "grid gap-2 sm:grid-cols-2", children: plan.organizations.map((organization) => (_jsx("li", { children: _jsx(Card, { size: "sm", className: "bg-destructive/5 ring-destructive/20 h-full py-3 shadow-none", children: _jsxs(CardContent, { className: "flex items-center gap-3 px-3", children: [_jsx("span", { className: "bg-destructive/10 text-destructive flex size-9 shrink-0 items-center justify-center rounded-lg", children: organization.personal ? (_jsx(UserRound, { "aria-hidden": "true", className: "size-4" })) : (_jsx(Building2, { "aria-hidden": "true", className: "size-4" })) }), _jsx("span", { className: "min-w-0 text-sm font-medium break-words", children: organization.name })] }) }) }, organization.id))) }), _jsx("p", { role: "alert", className: "text-destructive text-xs", children: labels.owner })] })) : null, plan.adminAccount ? (_jsx("p", { role: "alert", className: "text-destructive text-sm", children: labels.admin })) : null] })) : (_jsx("p", { role: "status", className: "text-muted-foreground text-sm", children: labels.loadError })), !blockedByOrganizations ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(FieldLabel, { htmlFor: passwordId, children: labels.password }), _jsx(Input, { id: passwordId, type: "password", autoComplete: "current-password", value: password, onChange: (event) => setPassword(event.target.value) })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(FieldLabel, { htmlFor: confirmationId, children: labels.confirm }), _jsx(Input, { id: confirmationId, value: confirmation, autoComplete: "off", onChange: (event) => setConfirmation(event.target.value) })] }), AsyncResult.isFailure(result) ? (_jsx("p", { role: "alert", className: "text-destructive text-sm", children: labels.error })) : null] })) : null, _jsx("p", { className: "text-muted-foreground text-xs", children: labels.retention }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: "button", variant: "outline", disabled: busy, onClick: props.onClose, children: labels.cancel }), !blockedByOrganizations ? (_jsx(Button, { type: "submit", variant: "destructive", disabled: disabled, children: labels.submit })) : null] })] }))] }) }));
|
|
59
|
+
};
|
|
@@ -13,6 +13,7 @@ import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent,
|
|
|
13
13
|
import { AdminListQuery } from "../admin/schema.js";
|
|
14
14
|
import { normalizeOrganizationRoles } from "../roles.js";
|
|
15
15
|
import { AdminOrganizationForm } from "./admin-organization-form.js";
|
|
16
|
+
import { deletionControlsEnabled } from "./deletion-visibility.js";
|
|
16
17
|
import { authClientApi, authHttpClient } from "./auth-client-api.js";
|
|
17
18
|
import { useKrakstackAuth } from "./auth-provider.js";
|
|
18
19
|
import { assetUrl, organizationBranding } from "./utils.js";
|
|
@@ -220,7 +221,7 @@ export function AdminOrganizationsTable({ messages: messageOverrides, onSearchCh
|
|
|
220
221
|
icon: _jsx(Trash2, { className: "size-4" }),
|
|
221
222
|
variant: "destructive",
|
|
222
223
|
onClick: setDeletingOrganization,
|
|
223
|
-
visible: (organization) => !organization.userId,
|
|
224
|
+
visible: (organization) => deletionControlsEnabled && !organization.userId,
|
|
224
225
|
},
|
|
225
226
|
],
|
|
226
227
|
},
|
|
@@ -242,7 +243,7 @@ export function AdminOrganizationsTable({ messages: messageOverrides, onSearchCh
|
|
|
242
243
|
}, status: { loading: isLoading } }), editingOrganization ? (_jsx(AdminOrganizationForm, { organization: editingOrganization, onClose: () => setEditingOrganization(null), onSaved: () => setTableRequest((current) => ({
|
|
243
244
|
...current,
|
|
244
245
|
refreshKey: current.refreshKey + 1,
|
|
245
|
-
})) })) : null, deletingOrganization ? (_jsx(DeleteOrganizationDialog, { labels: m, organization: deletingOrganization, baseUrl: baseUrl, onClose: () => setDeletingOrganization(null), onDeleted: () => {
|
|
246
|
+
})) })) : null, deletionControlsEnabled && deletingOrganization ? (_jsx(DeleteOrganizationDialog, { labels: m, organization: deletingOrganization, baseUrl: baseUrl, onClose: () => setDeletingOrganization(null), onDeleted: () => {
|
|
246
247
|
setDeletingOrganization(null);
|
|
247
248
|
setTableRequest((current) => ({
|
|
248
249
|
...current,
|
|
@@ -20,5 +20,5 @@ export const AssociatedProjectsNotice = ({ baseUrl, getSummary, organizationId =
|
|
|
20
20
|
});
|
|
21
21
|
if (projects.length <= 1)
|
|
22
22
|
return null;
|
|
23
|
-
return (_jsxs("details", { className: "border-primary/60 text-muted-foreground border-l-2 pl-3 text-sm", children: [_jsxs("summary", { className: "cursor-pointer list-none [&::-webkit-details-marker]:hidden", children: [getSummary(projects.length), " ", _jsx("span", { className: "text-foreground underline underline-offset-4", children: viewLabel })] }), _jsx("div", { className: "mt-2 flex flex-wrap gap-2", children: projects.map((project) => (_jsx(Badge, { variant: "secondary", children: project.name }, project.id))) })] }));
|
|
23
|
+
return (_jsx("div", { className: "px-1 py-2", children: _jsxs("details", { className: "border-primary/60 text-muted-foreground border-l-2 pl-3 text-sm", children: [_jsxs("summary", { className: "cursor-pointer list-none [&::-webkit-details-marker]:hidden", children: [getSummary(projects.length), " ", _jsx("span", { className: "text-foreground underline underline-offset-4", children: viewLabel })] }), _jsx("div", { className: "mt-2 flex flex-wrap gap-2", children: projects.map((project) => (_jsx(Badge, { variant: "secondary", children: project.name }, project.id))) })] }) }));
|
|
24
24
|
};
|
|
@@ -848,6 +848,14 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
848
848
|
readonly updatedAt: import("effect/Schema").DateFromString;
|
|
849
849
|
}>;
|
|
850
850
|
}>>, import("effect/Schema").toCodecJson<typeof import("../auth/schema.js").AuthBadRequest | typeof import("../auth/schema.js").AuthUnauthorized | typeof import("../auth/schema.js").AuthForbidden | typeof import("../auth/schema.js").AuthNotFound | typeof import("../auth/schema.js").AuthConflict | typeof import("../auth/schema.js").AuthExpectationFailed | typeof import("../auth/schema.js").AuthTooManyRequests | typeof import("../auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
|
|
851
|
+
readonly deleteUser: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"deleteUser", "POST", "/api/auth/delete-user", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
852
|
+
readonly password: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
853
|
+
readonly token: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
854
|
+
readonly callbackURL: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
855
|
+
}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
856
|
+
readonly success: import("effect/Schema").Boolean;
|
|
857
|
+
readonly message: import("effect/Schema").String;
|
|
858
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("../auth/schema.js").AuthBadRequest | typeof import("../auth/schema.js").AuthUnauthorized | typeof import("../auth/schema.js").AuthForbidden | typeof import("../auth/schema.js").AuthNotFound | typeof import("../auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
|
|
851
859
|
readonly getSession: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getSession", "GET", "/api/auth/get-session", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
852
860
|
readonly disableCookieCache: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
853
861
|
readonly disableRefresh: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
@@ -1066,6 +1074,18 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
1066
1074
|
readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
1067
1075
|
readonly createdAt: import("effect/Schema").DateFromString;
|
|
1068
1076
|
}>>, import("effect/Schema").toCodecJson<typeof import("../auth/schema.js").AuthBadRequest | typeof import("../auth/schema.js").AuthUnauthorized | typeof import("../auth/schema.js").AuthForbidden | typeof import("../auth/schema.js").AuthNotFound | typeof import("../auth/schema.js").AuthConflict | typeof import("../auth/schema.js").AuthExpectationFailed | typeof import("../auth/schema.js").AuthTooManyRequests | typeof import("../auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
|
|
1077
|
+
readonly organizationDelete: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationDelete", "POST", "/api/auth/organization/delete", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
1078
|
+
readonly organizationId: import("effect/Schema").NonEmptyString;
|
|
1079
|
+
}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
1080
|
+
readonly id: import("effect/Schema").String;
|
|
1081
|
+
readonly name: import("effect/Schema").String;
|
|
1082
|
+
readonly slug: import("effect/Schema").String;
|
|
1083
|
+
readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
1084
|
+
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Union<readonly [import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").Codec<import("effect/Schema").Json, import("effect/Schema").Json, never, never>>, import("effect/Schema").String]>>>;
|
|
1085
|
+
readonly userId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
1086
|
+
readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
1087
|
+
readonly createdAt: import("effect/Schema").DateFromString;
|
|
1088
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("../auth/schema.js").AuthBadRequest | typeof import("../auth/schema.js").AuthUnauthorized | typeof import("../auth/schema.js").AuthForbidden | typeof import("../auth/schema.js").AuthNotFound | typeof import("../auth/schema.js").AuthConflict | typeof import("../auth/schema.js").AuthExpectationFailed | typeof import("../auth/schema.js").AuthTooManyRequests | typeof import("../auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
|
|
1069
1089
|
readonly organizationGetFull: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"organizationGetFull", "GET", "/api/auth/organization/get-full-organization", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
1070
1090
|
readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
1071
1091
|
readonly organizationSlug: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
@@ -1935,6 +1955,19 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
1935
1955
|
readonly id: import("effect/Schema").String;
|
|
1936
1956
|
readonly key: import("effect/Schema").String;
|
|
1937
1957
|
}>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError | typeof import("../extra/schema.js").ExtraBadRequest>, never, never>, never, never>;
|
|
1958
|
+
readonly getAccountDeletionPlan: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getAccountDeletionPlan", "GET", "/api/auth/account-deletion", never, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
1959
|
+
readonly projects: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
1960
|
+
readonly id: import("effect/Schema").String;
|
|
1961
|
+
readonly name: import("effect/Schema").String;
|
|
1962
|
+
readonly ready: import("effect/Schema").Boolean;
|
|
1963
|
+
}>>;
|
|
1964
|
+
readonly organizations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
1965
|
+
readonly id: import("effect/Schema").String;
|
|
1966
|
+
readonly name: import("effect/Schema").String;
|
|
1967
|
+
readonly personal: import("effect/Schema").Boolean;
|
|
1968
|
+
}>>;
|
|
1969
|
+
readonly adminAccount: import("effect/Schema").Boolean;
|
|
1970
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError>, never, never>, never, never>;
|
|
1938
1971
|
readonly getOrganizationPublicProfile: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"getOrganizationPublicProfile", "GET", "/api/auth/organization-profile", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
1939
1972
|
readonly organizationId: import("effect/Schema").String;
|
|
1940
1973
|
readonly locale: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"en">, import("effect/Schema").Literal<"fr">]>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const deletionControlsEnabled: boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { AuthMember, FullAuthOrganization } from "../auth/schema.js";
|
|
3
|
+
export declare const canDeleteOrganization: (organization: (Pick<FullAuthOrganization, "userId"> & {
|
|
4
|
+
readonly members: ReadonlyArray<Pick<AuthMember, "userId" | "role">>;
|
|
5
|
+
}) | null, userId: string | undefined) => boolean;
|
|
6
|
+
export declare const requestOrganizationDeletion: (organizationId: string, baseUrl?: string) => Effect.Effect<{
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly slug: string;
|
|
10
|
+
readonly logo?: string | null | undefined;
|
|
11
|
+
readonly metadata?: string | {
|
|
12
|
+
readonly [x: string]: import("effect/Schema").Json;
|
|
13
|
+
} | null | undefined;
|
|
14
|
+
readonly userId?: string | null | undefined;
|
|
15
|
+
readonly parentId?: string | null | undefined;
|
|
16
|
+
readonly createdAt: Date;
|
|
17
|
+
}, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthConflict | import("../auth/schema.js").AuthExpectationFailed | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthTooManyRequests | import("../auth/schema.js").AuthUnauthorized | import("effect/http/HttpClientError").HttpClientError | import("effect/Schema").SchemaError, never>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { parseRoleList } from "../roles.js";
|
|
3
|
+
import { authHttpClient } from "./auth-client-api.js";
|
|
4
|
+
export const canDeleteOrganization = (organization, userId) => Boolean(organization &&
|
|
5
|
+
!organization.userId &&
|
|
6
|
+
userId &&
|
|
7
|
+
organization.members.some((member) => member.userId === userId &&
|
|
8
|
+
parseRoleList(member.role).includes("owner")));
|
|
9
|
+
export const requestOrganizationDeletion = (organizationId, baseUrl) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.organizationDelete({ payload: { organizationId } })));
|
|
@@ -12,6 +12,7 @@ import { AppBrand } from "@krak-stack/registry/app-brand";
|
|
|
12
12
|
import { FieldSet } from "@/components/ui/field";
|
|
13
13
|
import { Badge } from "@/components/ui/badge";
|
|
14
14
|
import { Button } from "@/components/ui/button";
|
|
15
|
+
import { AlertDialog, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
|
|
15
16
|
import { CopyButton } from "@krak-stack/registry/copy-button";
|
|
16
17
|
import { Dialog, DialogFooter, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
|
17
18
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
@@ -19,6 +20,9 @@ import { Separator } from "@/components/ui/separator";
|
|
|
19
20
|
import { OrganizationEmail, OrganizationAddress, OrganizationMetadata, OrganizationPhone, OrganizationSocial, OrganizationTranslation, OrganizationWebsite, decodeOrganizationMetadata, } from "@krak-stack/auth/schema";
|
|
20
21
|
import { isOrganizationRole, normalizeOrganizationRole, normalizeOrganizationRoles, organizationRoles, parseRoleList, } from "../roles.js";
|
|
21
22
|
import { authClientApi, authHttpClient } from "./auth-client-api.js";
|
|
23
|
+
import { adminOrganizationsMessages } from "./admin-organizations.js";
|
|
24
|
+
import { deletionControlsEnabled } from "./deletion-visibility.js";
|
|
25
|
+
import { canDeleteOrganization, requestOrganizationDeletion, } from "./organization-deletion-request.js";
|
|
22
26
|
import { activeAuthOrganizationAtom, authOrganizationsAtom, authSessionAtom, notifyAuthChange, refreshOnAuthChange, } from "./auth-atoms.js";
|
|
23
27
|
import { useKrakstackAuth } from "./auth-provider.js";
|
|
24
28
|
import { parseApiKeyReferrers } from "./api-key.js";
|
|
@@ -749,6 +753,8 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
749
753
|
payload: { organizationId },
|
|
750
754
|
})));
|
|
751
755
|
const [uncontrolledDialog, setUncontrolledDialog] = useState(defaultDialog);
|
|
756
|
+
const [deletingOrganization, setDeletingOrganization] = useState(null);
|
|
757
|
+
const deletionLabels = adminOrganizationsMessages(auth?.locale ?? "en");
|
|
752
758
|
const [editingOrganizationLocale, setEditingOrganizationLocale] = useState(currentOrganizationLocale);
|
|
753
759
|
const dialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
|
|
754
760
|
const invitationsAtom = userInvitationsAtom(baseUrl);
|
|
@@ -818,7 +824,7 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
818
824
|
? { imageSrc: activeDisplay.image }
|
|
819
825
|
: {}) }), _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
826
|
? { imageSrc: activeDisplay.image }
|
|
821
|
-
: {}) }) }), active ? (_jsx(
|
|
827
|
+
: {}) }) }), 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
828
|
"max-h-64 overflow-y-auto overscroll-contain"), children: selectableOrganizations.map((organization) => {
|
|
823
829
|
const display = organizationDisplay(organization, m, baseUrl);
|
|
824
830
|
return (_jsx(DropdownMenuItem, { onClick: async () => {
|
|
@@ -845,7 +851,15 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
845
851
|
return (_jsxs(DropdownMenuItem, { onClick: () => {
|
|
846
852
|
void navigator.clipboard.writeText(organizationId);
|
|
847
853
|
}, 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
|
|
854
|
+
})(), 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 &&
|
|
855
|
+
canDeleteOrganization(activeOrganization, session.user.id) ? (_jsxs(DropdownMenuItem, { variant: "destructive", onClick: () => setDeletingOrganization({
|
|
856
|
+
id: activeOrganization.id,
|
|
857
|
+
name: activeOrganization.name,
|
|
858
|
+
}), children: [_jsx(Trash2, {}), deletionLabels.organization_action_delete] })) : null] })) : null] }) })] })), deletionControlsEnabled && deletingOrganization ? (_jsx(OrganizationDeletionDialog, { baseUrl: baseUrl, organization: deletingOrganization, onClose: () => setDeletingOrganization(null), onDeleted: () => {
|
|
859
|
+
setDeletingOrganization(null);
|
|
860
|
+
setDialog(null);
|
|
861
|
+
onChange?.(null);
|
|
862
|
+
} }, deletingOrganization.id)) : null, _jsx(Dialog, { open: dialog === "create" && canCreateOrganization, onOpenChange: (open) => {
|
|
849
863
|
setDialog((current) => open ? "create" : current === "create" ? null : current);
|
|
850
864
|
}, 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
865
|
setDialog(null);
|
|
@@ -879,6 +893,21 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
879
893
|
? { activeOrganizationId: activeOrganization.id }
|
|
880
894
|
: {}), onActionComplete: refreshAfterInvitationAction }) })] }) })] }));
|
|
881
895
|
}
|
|
896
|
+
const OrganizationDeletionDialog = ({ baseUrl, organization, onClose, onDeleted, }) => {
|
|
897
|
+
const auth = useKrakstackAuth();
|
|
898
|
+
const labels = adminOrganizationsMessages(auth?.locale ?? "en");
|
|
899
|
+
// Cross-project deletion cannot be predicted or rolled back on the client.
|
|
900
|
+
const [mutation] = useState(() => authClientApi(baseUrl).runtime.fn(() => requestOrganizationDeletion(organization.id, baseUrl).pipe(Effect.tap(() => Effect.sync(() => {
|
|
901
|
+
notifyAuthChange();
|
|
902
|
+
onDeleted();
|
|
903
|
+
})))));
|
|
904
|
+
const remove = useAtomSet(mutation);
|
|
905
|
+
const result = useAtomValue(mutation);
|
|
906
|
+
return (_jsx(AlertDialog, { open: true, onOpenChange: (open) => {
|
|
907
|
+
if (!open && !result.waiting)
|
|
908
|
+
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 })] })] }) }));
|
|
910
|
+
};
|
|
882
911
|
function UserInvitationsManager({ baseUrl, invitations, loading, error, activeOrganizationId, onActionComplete, }) {
|
|
883
912
|
const m = useOrganizationMessages();
|
|
884
913
|
const [actingInvitationId, setActingInvitationId] = useState(null);
|
|
@@ -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 {};
|
|
@@ -36,10 +36,26 @@ import { AdminOrganizationsTable } from "./admin-organizations.js";
|
|
|
36
36
|
import { AdminUsersTable } from "./admin-users.js";
|
|
37
37
|
import { ScrollableDialogBody, ScrollableDialogContent, ScrollableDialogHeader, } from "./scrollable-dialog.js";
|
|
38
38
|
import { AssociatedProjectsNotice } from "./associated-projects-notice.js";
|
|
39
|
+
import { AccountDeletionDialog } from "./account-deletion.js";
|
|
40
|
+
import { deletionControlsEnabled } from "./deletion-visibility.js";
|
|
39
41
|
import { ContactEmailsField, ContactPhonesField, ContactSocialsField, ContactWebsitesField, } from "./contact-fields.js";
|
|
40
42
|
import { decodeUserMetadata, ContactLocale, SocialPlatform, USER_CONTACT_LIMIT, UserMetadata, } from "../schema.js";
|
|
41
43
|
const messages = {
|
|
42
44
|
en: {
|
|
45
|
+
user_delete_title: "Delete account",
|
|
46
|
+
user_delete_description: "Permanently delete your account and unshared personal organizations. This cannot be undone.",
|
|
47
|
+
user_delete_projects: "Connected projects",
|
|
48
|
+
user_delete_organizations: "Organizations to resolve",
|
|
49
|
+
user_delete_retention: "Project cleanup is requested separately. Legal retention may apply.",
|
|
50
|
+
user_delete_missing: "Some projects need support to complete cleanup.",
|
|
51
|
+
user_delete_owner: "Transfer ownership or delete these in the organization switcher. Shared personal organizations need support.",
|
|
52
|
+
user_delete_admin: "Remove your platform admin role before continuing.",
|
|
53
|
+
user_delete_confirm: "Type DELETE to confirm",
|
|
54
|
+
user_delete_password: "Current password (if required)",
|
|
55
|
+
user_delete_error: "Unable to delete your account. Check your password, or sign in again and retry.",
|
|
56
|
+
user_delete_load_error: "Loading requirements… Close and retry if this takes too long.",
|
|
57
|
+
user_delete_complete: "Your account is deleted. Project cleanup may still be pending; retained records are not necessarily erased.",
|
|
58
|
+
user_delete_done: "Done",
|
|
43
59
|
table_empty: "No results.",
|
|
44
60
|
user_account_cancel: "Cancel",
|
|
45
61
|
user_account_back: "Back",
|
|
@@ -185,6 +201,20 @@ const messages = {
|
|
|
185
201
|
user_two_factor_verify_error: "Could not verify the code.",
|
|
186
202
|
},
|
|
187
203
|
fr: {
|
|
204
|
+
user_delete_title: "Supprimer le compte",
|
|
205
|
+
user_delete_description: "Supprimez définitivement votre compte et vos organisations personnelles non partagées. Cette action est irréversible.",
|
|
206
|
+
user_delete_projects: "Projets liés",
|
|
207
|
+
user_delete_organizations: "Organisations à régler",
|
|
208
|
+
user_delete_retention: "Le nettoyage des projets est demandé séparément. Une conservation légale peut s’appliquer.",
|
|
209
|
+
user_delete_missing: "Certains projets nécessitent l’assistance pour terminer le nettoyage.",
|
|
210
|
+
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.",
|
|
211
|
+
user_delete_admin: "Retirez votre rôle administrateur de plateforme avant de continuer.",
|
|
212
|
+
user_delete_confirm: "Saisissez DELETE pour confirmer",
|
|
213
|
+
user_delete_password: "Mot de passe actuel (si nécessaire)",
|
|
214
|
+
user_delete_error: "Impossible de supprimer le compte. Vérifiez votre mot de passe ou reconnectez-vous, puis réessayez.",
|
|
215
|
+
user_delete_load_error: "Chargement des conditions… Fermez et réessayez si l’attente se prolonge.",
|
|
216
|
+
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.",
|
|
217
|
+
user_delete_done: "Terminé",
|
|
188
218
|
table_empty: "Aucun résultat.",
|
|
189
219
|
user_account_cancel: "Annuler",
|
|
190
220
|
user_account_back: "Retour",
|
|
@@ -603,11 +633,18 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
|
|
|
603
633
|
: `${import.meta.env.VITE_SITE_URL}${signOutRedirect.startsWith("/") ? signOutRedirect : `/${signOutRedirect}`}`;
|
|
604
634
|
signOut({ baseUrl: resolvedBaseUrl, redirectUrl });
|
|
605
635
|
};
|
|
606
|
-
return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", className: "overflow-hidden", children: [displayImage ? (_jsx("img", { src: displayImage, alt: displayName || displayEmail, className: "size-full object-cover" })) : (_jsx(UserIcon, { className: "size-4.5" })), _jsx("span", { className: "sr-only", children: m.user_button_aria_label() })] }) }), _jsx(DropdownMenuContent, { className: "w-56 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [isImpersonating ? (_jsx("div", { className: "px-1 py-0.5", children: _jsx(Badge, { variant: "secondary", className: "text-xs font-normal", children: m.user_button_impersonating() }) })) : null, _jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: displayName || displayEmail, subtitle: displayName ? displayEmail : m.user_button_account(), icon: UserIcon, className: "px-1 py-1.5 text-left text-sm", ...(displayImage ? { imageSrc: displayImage } : {}) }) }), _jsx(
|
|
636
|
+
return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", className: "overflow-hidden", children: [displayImage ? (_jsx("img", { src: displayImage, alt: displayName || displayEmail, className: "size-full object-cover" })) : (_jsx(UserIcon, { className: "size-4.5" })), _jsx("span", { className: "sr-only", children: m.user_button_aria_label() })] }) }), _jsx(DropdownMenuContent, { className: "w-56 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [isImpersonating ? (_jsx("div", { className: "px-1 py-0.5", children: _jsx(Badge, { variant: "secondary", className: "text-xs font-normal", children: m.user_button_impersonating() }) })) : null, _jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: displayName || displayEmail, subtitle: displayName ? displayEmail : m.user_button_account(), icon: UserIcon, className: "px-1 py-1.5 text-left text-sm", ...(displayImage ? { imageSrc: displayImage } : {}) }) }), _jsx(AssociatedProjectsNotice, { baseUrl: resolvedBaseUrl, getSummary: (count) => m.user_form_projects_summary({ count }), viewLabel: m.user_form_projects_view() }), menuActions ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), menuActions] })) : null, _jsx(DropdownMenuSeparator, {}), canManageUserSettings ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { disabled: isPending, onClick: () => setSettingsDialog("account"), children: [_jsx(UserCircleIcon, {}), m.user_button_account()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("security"), children: [_jsx(ShieldCheck, {}), m.user_button_security()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] }), _jsx(DropdownMenuSeparator, {})] })) : null, deletionControlsEnabled && !isImpersonating && !isOrganizationImpersonating ? _jsxs(DropdownMenuItem, { variant: "destructive", onClick: () => setSettingsDialog("deleteAccount"), children: [_jsx(Trash2, {}), m.user_delete_title()] }) : null, (isAdmin && canUseAdminSettings) || isImpersonating ? (_jsxs(_Fragment, { children: [isAdmin && canUseAdminSettings ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminUsers"), children: [_jsx(Users, {}), m.user_button_admin_users()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminOrganizations"), children: [_jsx(Building2, {}), m.user_button_admin_organizations()] })] })) : null, isImpersonating ? (_jsxs(DropdownMenuItem, { disabled: isStoppingImpersonation, onClick: () => stopImpersonating({
|
|
607
637
|
baseUrl: resolvedBaseUrl,
|
|
608
638
|
currentSiteHref,
|
|
609
639
|
refreshSession,
|
|
610
|
-
}), children: [_jsx(StopCircle, {}), m.user_button_stop_impersonating()] })) : null, _jsx(DropdownMenuSeparator, {})] })) : null, _jsxs(DropdownMenuItem, { disabled: signOutResult.waiting, onClick: startSignOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] }), authActionError ? (_jsx(DropdownMenuLabel, { className: "text-destructive text-xs font-normal", children: authActionError })) : null] }) })] })), _jsx(
|
|
640
|
+
}), children: [_jsx(StopCircle, {}), m.user_button_stop_impersonating()] })) : null, _jsx(DropdownMenuSeparator, {})] })) : null, _jsxs(DropdownMenuItem, { disabled: signOutResult.waiting, onClick: startSignOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] }), authActionError ? (_jsx(DropdownMenuLabel, { className: "text-destructive text-xs font-normal", children: authActionError })) : null] }) })] })), deletionControlsEnabled && settingsDialog === "deleteAccount" && !isImpersonating && !isOrganizationImpersonating ? _jsx(AccountDeletionDialog, { baseUrl: resolvedBaseUrl, userId: session.user.id, onClose: () => setSettingsDialog(null), onDeleted: () => { notifyAuthChange(); void navigate({ href: signOutRedirect }); }, labels: {
|
|
641
|
+
title: m.user_delete_title(), description: m.user_delete_description(), projects: m.user_delete_projects(),
|
|
642
|
+
organizations: m.user_delete_organizations(), retention: m.user_delete_retention(),
|
|
643
|
+
missing: m.user_delete_missing(), owner: m.user_delete_owner(), admin: m.user_delete_admin(),
|
|
644
|
+
confirm: m.user_delete_confirm(), password: m.user_delete_password(), error: m.user_delete_error(),
|
|
645
|
+
loadError: m.user_delete_load_error(), cancel: m.user_account_cancel(), submit: m.user_delete_title(),
|
|
646
|
+
done: m.user_delete_done(), complete: m.user_delete_complete(),
|
|
647
|
+
} }) : null, _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "account", onOpenChange: (open) => {
|
|
611
648
|
setSettingsDialog((current) => open ? "account" : current === "account" ? null : current);
|
|
612
649
|
}, children: _jsx(UserForm, { primaryEmail: displayEmail, defaultValues: {
|
|
613
650
|
name: displayName ?? "",
|
|
@@ -12,7 +12,19 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
|
|
|
12
12
|
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
13
13
|
readonly id: Schema.String;
|
|
14
14
|
readonly key: Schema.String;
|
|
15
|
-
}>>, Schema.toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"
|
|
15
|
+
}>>, Schema.toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getAccountDeletionPlan", "GET", "/auth/account-deletion", never, never, never, never, Schema.toCodecJson<Schema.Struct<{
|
|
16
|
+
readonly projects: Schema.$Array<Schema.Struct<{
|
|
17
|
+
readonly id: Schema.String;
|
|
18
|
+
readonly name: Schema.String;
|
|
19
|
+
readonly ready: Schema.Boolean;
|
|
20
|
+
}>>;
|
|
21
|
+
readonly organizations: Schema.$Array<Schema.Struct<{
|
|
22
|
+
readonly id: Schema.String;
|
|
23
|
+
readonly name: Schema.String;
|
|
24
|
+
readonly personal: Schema.Boolean;
|
|
25
|
+
}>>;
|
|
26
|
+
readonly adminAccount: Schema.Boolean;
|
|
27
|
+
}>>, Schema.toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getOrganizationPublicProfile", "GET", "/auth/organization-profile", never, Schema.toCodecStringTree<Schema.Struct<{
|
|
16
28
|
readonly organizationId: Schema.String;
|
|
17
29
|
readonly locale: Schema.optional<Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>>;
|
|
18
30
|
}>>, never, never, Schema.toCodecJson<Schema.Struct<{
|