@krak-stack/auth 0.2.13 → 0.2.15
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/dist/components/admin-organization-form.js +1 -1
- package/dist/components/auth-provider.d.ts +23 -0
- package/dist/components/auth-provider.js +68 -19
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +1 -1
- package/dist/components/member-required.js +1 -4
- package/dist/components/organization-switcher.js +5 -8
- package/dist/components/user-button.js +5 -7
- package/package.json +2 -2
|
@@ -153,5 +153,5 @@ export function AdminOrganizationForm({ organization, onClose, onSaved, }) {
|
|
|
153
153
|
height: 96,
|
|
154
154
|
suggestedWidth: 512,
|
|
155
155
|
suggestedHeight: 512,
|
|
156
|
-
} }), _jsx(form.parentId, { description: m.organization_parent_description, emptyLabel: m.organization_parent_empty, items: parentOptions, label: m.organization_parent,
|
|
156
|
+
} }), _jsx(form.parentId, { description: m.organization_parent_description, emptyLabel: m.organization_parent_empty, items: parentOptions, label: m.organization_parent, placeholder: m.organization_parent_none }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form, children: m.form_submit })] }) })] }) }));
|
|
157
157
|
}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import { Cause, Schema } from "effect";
|
|
2
|
+
import { AsyncResult } from "effect/unstable/reactivity";
|
|
1
3
|
import { type ReactNode } from "react";
|
|
2
4
|
import type { ExtraProjectPublicConfig } from "../extra/schema.js";
|
|
3
5
|
import type { ProjectAccessCatalog, ProjectAccessLabelCatalog } from "../access.js";
|
|
4
6
|
export type KrakstackAuthLocale = "en" | "fr";
|
|
7
|
+
export type KrakstackAuthStatus = "loading" | "ready" | "degraded" | "error";
|
|
8
|
+
declare const KrakstackAuthUnavailableError_base: Schema.Class<KrakstackAuthUnavailableError, Schema.TaggedStruct<"KrakstackAuthUnavailableError", {
|
|
9
|
+
readonly cause: Schema.Defect;
|
|
10
|
+
}>, Cause.YieldableError>;
|
|
11
|
+
export declare class KrakstackAuthUnavailableError extends KrakstackAuthUnavailableError_base {
|
|
12
|
+
readonly status = 503;
|
|
13
|
+
}
|
|
5
14
|
export type KrakstackAuthProviderProps = {
|
|
6
15
|
children: ReactNode;
|
|
7
16
|
locale?: KrakstackAuthLocale | undefined;
|
|
@@ -14,10 +23,18 @@ export type KrakstackAuthContextValue = {
|
|
|
14
23
|
locale: KrakstackAuthLocale;
|
|
15
24
|
baseUrl?: string | undefined;
|
|
16
25
|
projectId?: string | null | undefined;
|
|
26
|
+
status: KrakstackAuthStatus;
|
|
27
|
+
error: KrakstackAuthUnavailableError | null;
|
|
17
28
|
projectConfig: ExtraProjectPublicConfig | null;
|
|
18
29
|
access: ProjectAccessCatalog | null;
|
|
19
30
|
accessLabels: ProjectAccessLabelCatalog | null;
|
|
20
31
|
};
|
|
32
|
+
type ProjectConfigState = {
|
|
33
|
+
status: KrakstackAuthStatus;
|
|
34
|
+
error: KrakstackAuthUnavailableError | null;
|
|
35
|
+
projectConfig: ExtraProjectPublicConfig | null;
|
|
36
|
+
};
|
|
37
|
+
export declare const resolveProjectConfigState: (result: AsyncResult.AsyncResult<ExtraProjectPublicConfig | null, unknown>) => ProjectConfigState;
|
|
21
38
|
export declare function KrakstackAuthProvider({ children, locale, baseUrl, projectId, access, accessLabels, }: KrakstackAuthProviderProps): import("react").JSX.Element;
|
|
22
39
|
export declare const useKrakstackAuth: () => KrakstackAuthContextValue | null;
|
|
23
40
|
export declare const useKrakstackAuthProjectConfig: () => {
|
|
@@ -33,6 +50,11 @@ export declare const useKrakstackAuthProjectConfig: () => {
|
|
|
33
50
|
readonly google: boolean;
|
|
34
51
|
};
|
|
35
52
|
} | null;
|
|
53
|
+
export type KrakstackAuthRequiredProps = {
|
|
54
|
+
children: ReactNode;
|
|
55
|
+
fallback?: ReactNode | undefined;
|
|
56
|
+
};
|
|
57
|
+
export declare const KrakstackAuthRequired: ({ children, fallback, }: KrakstackAuthRequiredProps) => ReactNode;
|
|
36
58
|
export declare const usePermissions: () => {
|
|
37
59
|
loading: boolean;
|
|
38
60
|
permissions: Set<string>;
|
|
@@ -40,3 +62,4 @@ export declare const usePermissions: () => {
|
|
|
40
62
|
canAll: (required: ReadonlyArray<string>) => boolean;
|
|
41
63
|
canAny: (required: ReadonlyArray<string>) => boolean;
|
|
42
64
|
};
|
|
65
|
+
export {};
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useAtomValue } from "@effect/atom-react";
|
|
3
3
|
import { useRouterState } from "@tanstack/react-router";
|
|
4
|
-
import {
|
|
4
|
+
import { Cause, Option, Schema } from "effect";
|
|
5
|
+
import { HttpApiError } from "effect/unstable/httpapi";
|
|
6
|
+
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
5
7
|
import { createContext, useContext, useEffect, useMemo, useRef, } from "react";
|
|
6
8
|
import { activeAuthOrganizationAtom, authSessionAtom } from "./auth-atoms.js";
|
|
7
9
|
import { authClientApi } from "./auth-client-api.js";
|
|
8
10
|
import { parseRoleList } from "../roles.js";
|
|
11
|
+
export class KrakstackAuthUnavailableError extends Schema.TaggedError()("KrakstackAuthUnavailableError", {
|
|
12
|
+
cause: Schema.Defect(),
|
|
13
|
+
}) {
|
|
14
|
+
status = 503;
|
|
15
|
+
}
|
|
9
16
|
const KrakstackAuthContext = createContext(null);
|
|
10
17
|
const PROJECT_CONTEXT_COOKIE = "krakstack-auth.project_context";
|
|
11
18
|
const setProjectContextCookie = (projectId) => {
|
|
@@ -42,7 +49,28 @@ const getRedirectHost = (searchString) => {
|
|
|
42
49
|
return null;
|
|
43
50
|
}
|
|
44
51
|
};
|
|
45
|
-
const
|
|
52
|
+
const serverProjectConfigAtom = Atom.make(AsyncResult.initial());
|
|
53
|
+
export const resolveProjectConfigState = (result) => {
|
|
54
|
+
if (AsyncResult.isFailure(result)) {
|
|
55
|
+
const projectConfig = AsyncResult.getOrElse(result, () => null);
|
|
56
|
+
return {
|
|
57
|
+
status: Option.isSome(result.previousSuccess) ? "degraded" : "error",
|
|
58
|
+
error: new KrakstackAuthUnavailableError({
|
|
59
|
+
cause: Cause.squash(result.cause),
|
|
60
|
+
}),
|
|
61
|
+
projectConfig,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (AsyncResult.isSuccess(result)) {
|
|
65
|
+
return {
|
|
66
|
+
status: "ready",
|
|
67
|
+
error: null,
|
|
68
|
+
projectConfig: result.value,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return { status: "loading", error: null, projectConfig: null };
|
|
72
|
+
};
|
|
73
|
+
const useProjectConfigState = (baseUrl, providedProjectId) => {
|
|
46
74
|
const searchString = useRouterState({
|
|
47
75
|
select: (state) => state.location.searchStr,
|
|
48
76
|
});
|
|
@@ -59,26 +87,29 @@ const useProjectConfig = (baseUrl, providedProjectId) => {
|
|
|
59
87
|
query.host = host;
|
|
60
88
|
if (rootHost)
|
|
61
89
|
query.rootHost = rootHost;
|
|
62
|
-
const
|
|
63
|
-
query,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
90
|
+
const projectConfigAtom = globalThis.window
|
|
91
|
+
? authClientApi(baseUrl).query("authExtra", "getProjectPublicConfig", {
|
|
92
|
+
query,
|
|
93
|
+
timeToLive: "5 minutes",
|
|
94
|
+
reactivityKeys: [
|
|
95
|
+
"project-public-config",
|
|
96
|
+
...(projectId ? [`project:${projectId}`] : []),
|
|
97
|
+
...(clientId ? [`client:${clientId}`] : []),
|
|
98
|
+
...(host ? [`host:${host}`] : []),
|
|
99
|
+
...(rootHost ? [`root-host:${rootHost}`] : []),
|
|
100
|
+
],
|
|
101
|
+
serializationKey: `project-public-config:${projectId ?? ""}:${clientId ?? ""}:${host ?? ""}:${rootHost ?? ""}`,
|
|
102
|
+
})
|
|
103
|
+
: serverProjectConfigAtom;
|
|
104
|
+
const result = useAtomValue(projectConfigAtom);
|
|
105
|
+
return useMemo(() => resolveProjectConfigState(result), [result]);
|
|
75
106
|
};
|
|
76
107
|
export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projectId, access, accessLabels, }) {
|
|
77
108
|
const searchString = useRouterState({
|
|
78
109
|
select: (state) => state.location.searchStr,
|
|
79
110
|
});
|
|
80
111
|
const resolvedProjectId = projectId ?? getSearchParam(searchString, "projectId");
|
|
81
|
-
const
|
|
112
|
+
const projectConfigState = useProjectConfigState(baseUrl, projectId);
|
|
82
113
|
const sessionAtom = authSessionAtom(baseUrl);
|
|
83
114
|
const sessionResult = useAtomValue(sessionAtom);
|
|
84
115
|
const wasAuthenticated = useRef(false);
|
|
@@ -101,14 +132,32 @@ export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projec
|
|
|
101
132
|
baseUrl,
|
|
102
133
|
locale,
|
|
103
134
|
projectId: resolvedProjectId,
|
|
104
|
-
|
|
135
|
+
...projectConfigState,
|
|
105
136
|
access: access ?? null,
|
|
106
137
|
accessLabels: accessLabels ?? null,
|
|
107
|
-
}), [
|
|
138
|
+
}), [
|
|
139
|
+
baseUrl,
|
|
140
|
+
locale,
|
|
141
|
+
resolvedProjectId,
|
|
142
|
+
projectConfigState,
|
|
143
|
+
access,
|
|
144
|
+
accessLabels,
|
|
145
|
+
]);
|
|
108
146
|
return (_jsx(KrakstackAuthContext.Provider, { value: value, children: children }));
|
|
109
147
|
}
|
|
110
148
|
export const useKrakstackAuth = () => useContext(KrakstackAuthContext);
|
|
111
149
|
export const useKrakstackAuthProjectConfig = () => useKrakstackAuth()?.projectConfig ?? null;
|
|
150
|
+
export const KrakstackAuthRequired = ({ children, fallback = null, }) => {
|
|
151
|
+
const auth = useKrakstackAuth();
|
|
152
|
+
if (!auth) {
|
|
153
|
+
throw new Error("KrakstackAuthProvider is required to use KrakstackAuthRequired.");
|
|
154
|
+
}
|
|
155
|
+
if (auth.status === "loading")
|
|
156
|
+
return fallback;
|
|
157
|
+
if (auth.status === "error")
|
|
158
|
+
throw auth.error;
|
|
159
|
+
return children;
|
|
160
|
+
};
|
|
112
161
|
export const usePermissions = () => {
|
|
113
162
|
const auth = useKrakstackAuth();
|
|
114
163
|
if (!auth) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { KrakstackAuthProvider, useKrakstackAuth, useKrakstackAuthProjectConfig, usePermissions, } from "./auth-provider.js";
|
|
1
|
+
export { KrakstackAuthProvider, KrakstackAuthRequired, KrakstackAuthUnavailableError, useKrakstackAuth, useKrakstackAuthProjectConfig, usePermissions, } from "./auth-provider.js";
|
|
2
2
|
export { activeAuthOrganizationAtom, authOrganizationsAtom, authSessionAtom, } from "./auth-atoms.js";
|
|
3
3
|
export { OrganizationSwitcher } from "./organization-switcher.js";
|
|
4
4
|
export { MemberRequired } from "./member-required.js";
|
|
@@ -14,7 +14,7 @@ export { ApiKeyPermissionGrant, CurrentActor, Forbidden, all, actorUserId, any,
|
|
|
14
14
|
export type { ApiKeyOwner, ApiKeyActor, Actor, Policy, ProjectAccessConfig, ProjectAccessCatalog, ProjectAccessLabelCatalog, ProjectAccessDefinition, ProjectAccessLabels, UserActor, } from "../access.js";
|
|
15
15
|
export type { ProjectAccessMatrixAccess, ProjectAccessMatrixMessages, } from "./project-access-matrix.js";
|
|
16
16
|
export type { AdminOrganizationsMessages } from "./admin-organizations.js";
|
|
17
|
-
export type { KrakstackAuthContextValue, KrakstackAuthLocale, KrakstackAuthProviderProps, } from "./auth-provider.js";
|
|
17
|
+
export type { KrakstackAuthContextValue, KrakstackAuthLocale, KrakstackAuthProviderProps, KrakstackAuthRequiredProps, KrakstackAuthStatus, } from "./auth-provider.js";
|
|
18
18
|
export type { OrganizationSwitcherDialog, OrganizationSwitcherFeatures, OrganizationSwitcherProps, } from "./organization-switcher.js";
|
|
19
19
|
export type { UserButtonDialog, UserButtonProps } from "./user-button.js";
|
|
20
20
|
export type { MemberRequiredMessages, MemberRequiredProps, } from "./member-required.js";
|
package/dist/components/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { KrakstackAuthProvider, useKrakstackAuth, useKrakstackAuthProjectConfig, usePermissions, } from "./auth-provider.js";
|
|
1
|
+
export { KrakstackAuthProvider, KrakstackAuthRequired, KrakstackAuthUnavailableError, useKrakstackAuth, useKrakstackAuthProjectConfig, usePermissions, } from "./auth-provider.js";
|
|
2
2
|
export { activeAuthOrganizationAtom, authOrganizationsAtom, authSessionAtom, } from "./auth-atoms.js";
|
|
3
3
|
export { OrganizationSwitcher } from "./organization-switcher.js";
|
|
4
4
|
export { MemberRequired } from "./member-required.js";
|
|
@@ -200,10 +200,7 @@ function MemberRequiredGate({ accessKey, baseUrl, contactEmail, children, locale
|
|
|
200
200
|
organization: displayName,
|
|
201
201
|
}) })] }), _jsxs(CardContent, { className: "space-y-3", children: [invitation ? (_jsx("p", { className: "text-muted-foreground text-sm", children: interpolate(invitationExpired
|
|
202
202
|
? m.member_required_invite_expired
|
|
203
|
-
: m.member_required_invite_found, { organization: displayName }) })) : (_jsx("p", { className: "text-muted-foreground text-sm", children: m.member_required_contact_description })), resolvedContactEmail ? (_jsxs("div", { className: "bg-muted/50 flex items-center justify-between gap-3 rounded-md border px-3 py-2 text-sm", children: [_jsxs("span", { className: "flex min-w-0 items-center gap-2 font-medium", children: [_jsx(Mail, { className: "text-muted-foreground size-4 shrink-0" }), _jsx("span", { className: "truncate", children: resolvedContactEmail })] }), _jsx(CopyButton, { value: resolvedContactEmail, valueDescription: resolvedContactEmail, variant: "ghost", className: "shrink-0",
|
|
204
|
-
copy: m.member_required_copy_email,
|
|
205
|
-
copied: m.member_required_copied_email,
|
|
206
|
-
} })] })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }), _jsx(CardFooter, { className: "flex flex-wrap gap-2", children: invitation && !invitationExpired ? (_jsxs(Button, { onClick: acceptInvitation, disabled: accepting, children: [accepting ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : (_jsx(Check, { className: "size-4" })), accepting
|
|
203
|
+
: m.member_required_invite_found, { organization: displayName }) })) : (_jsx("p", { className: "text-muted-foreground text-sm", children: m.member_required_contact_description })), resolvedContactEmail ? (_jsxs("div", { className: "bg-muted/50 flex items-center justify-between gap-3 rounded-md border px-3 py-2 text-sm", children: [_jsxs("span", { className: "flex min-w-0 items-center gap-2 font-medium", children: [_jsx(Mail, { className: "text-muted-foreground size-4 shrink-0" }), _jsx("span", { className: "truncate", children: resolvedContactEmail })] }), _jsx(CopyButton, { value: resolvedContactEmail, valueDescription: resolvedContactEmail, variant: "ghost", className: "shrink-0", locale: locale })] })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }), _jsx(CardFooter, { className: "flex flex-wrap gap-2", children: invitation && !invitationExpired ? (_jsxs(Button, { onClick: acceptInvitation, disabled: accepting, children: [accepting ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : (_jsx(Check, { className: "size-4" })), accepting
|
|
207
204
|
? m.member_required_accepting_invite
|
|
208
205
|
: m.member_required_accept_invite] })) : null })] }) }));
|
|
209
206
|
}
|
|
@@ -847,7 +847,7 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
847
847
|
}, children: [_jsx(Copy, {}), m.organization_copy_id()] }));
|
|
848
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] })) : null] }) })] })), _jsx(Dialog, { open: dialog === "create" && canCreateOrganization, onOpenChange: (open) => {
|
|
849
849
|
setDialog((current) => open ? "create" : current === "create" ? null : current);
|
|
850
|
-
}, 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, { value: editingOrganizationLocale, onValueChange: setEditingOrganizationLocale }) })] }), baseUrl: baseUrl, editingLocale: editingOrganizationLocale, onCreated: async (organization) => {
|
|
850
|
+
}, 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
851
|
setDialog(null);
|
|
852
852
|
let activated = false;
|
|
853
853
|
try {
|
|
@@ -864,14 +864,14 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
|
|
|
864
864
|
}
|
|
865
865
|
} }) }), _jsx(Dialog, { open: dialog === "manage" && canUpdateOrganization, onOpenChange: (open) => {
|
|
866
866
|
setDialog((current) => open ? "manage" : current === "manage" ? null : current);
|
|
867
|
-
}, 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, { value: editingOrganizationLocale, onValueChange: setEditingOrganizationLocale }) })] }), baseUrl: baseUrl, editingLocale: editingOrganizationLocale, organization: activeOrganization })) : null }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
|
|
867
|
+
}, 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
868
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
869
869
|
}, children: _jsx(ScrollableDialogContent, { size: "4xl", children: activeOrganization ? (_jsx(OrganizationMembersManager, { baseUrl: baseUrl, canManageMembers: canManageApiKeys, organization: activeOrganization, currentUserId: session.user.id, active: dialog === "members", onLeft: () => {
|
|
870
870
|
setDialog(null);
|
|
871
871
|
onChange?.(null);
|
|
872
872
|
} })) : null }) }), _jsx(Dialog, { open: dialog === "apiKeys" && canManageApiKeys, onOpenChange: (open) => {
|
|
873
873
|
setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
874
|
-
}, children: _jsx(ScrollableDialogContent, { size: "4xl", children: activeOrganization ? (_jsx(OrganizationApiKeyManager, { baseUrl: baseUrl, organization: activeOrganization, active: dialog === "apiKeys" && canManageApiKeys, permissionLabels: auth?.accessLabels ?? undefined, permissions: apiKeyPermissions ??
|
|
874
|
+
}, children: _jsx(ScrollableDialogContent, { size: "4xl", children: activeOrganization ? (_jsx(OrganizationApiKeyManager, { baseUrl: baseUrl, locale: auth?.locale ?? "en", organization: activeOrganization, active: dialog === "apiKeys" && canManageApiKeys, permissionLabels: auth?.accessLabels ?? undefined, permissions: apiKeyPermissions ??
|
|
875
875
|
auth?.access?.apiKeyPermissions.organization ??
|
|
876
876
|
{} })) : null }) }), _jsx(Dialog, { open: dialog === "invitations" && canViewOrganizationInvitations, onOpenChange: (open) => {
|
|
877
877
|
setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
|
|
@@ -1443,7 +1443,7 @@ const invitationRowActions = ({ m, cancellingInvitationId, onCancel, }) => [
|
|
|
1443
1443
|
onClick: onCancel,
|
|
1444
1444
|
},
|
|
1445
1445
|
];
|
|
1446
|
-
function OrganizationApiKeyManager({ baseUrl, organization, active, permissionLabels, permissions, }) {
|
|
1446
|
+
function OrganizationApiKeyManager({ baseUrl, locale, organization, active, permissionLabels, permissions, }) {
|
|
1447
1447
|
const m = useOrganizationMessages();
|
|
1448
1448
|
const hasOpened = useOpenedOnce(active);
|
|
1449
1449
|
const keysAtom = hasOpened
|
|
@@ -1547,10 +1547,7 @@ function OrganizationApiKeyManager({ baseUrl, organization, active, permissionLa
|
|
|
1547
1547
|
}, children: [_jsx(createForm.name, { label: m.user_api_key_name(), required: true }), _jsx(createForm.referrers, { label: m.user_api_key_referrers(), description: m.user_api_key_referrers_description(), placeholder: m.user_api_key_referrers_placeholder(), rows: 3 }), _jsx(ApiKeyPermissions, { clearAllLabel: m.user_api_key_permissions_clear_all(), description: m.user_api_key_permissions_description(), idPrefix: "organization-create", permissions: permissions, labels: permissionLabels, selectAllLabel: m.user_api_key_permissions_select_all(), selected: selectedPermissions, title: m.user_api_key_permissions(), onChange: togglePermission, onChangeAll: (ids, checked) => setSelectedPermissions((current) => ({
|
|
1548
1548
|
...current,
|
|
1549
1549
|
...Object.fromEntries(ids.map((id) => [id, checked])),
|
|
1550
|
-
})) }), _jsx(SubmitError, { result: createResult }), _jsx(SubmitButton, { form: createForm })] }) }) })) : null, creating && createdKey ? (_jsx("div", { className: "flex min-w-0 flex-col gap-3", children: _jsxs("div", { className: "bg-muted/50 flex min-w-0 items-center justify-between gap-3 rounded-md border px-3 py-2", children: [_jsx("code", { className: "block min-w-0 flex-1 overflow-x-auto text-sm whitespace-nowrap", children: createdKey }), _jsx(CopyButton, { className: "shrink-0",
|
|
1551
|
-
copied: m.user_api_key_copied(),
|
|
1552
|
-
copy: m.user_api_key_copy(),
|
|
1553
|
-
}, value: createdKey, variant: "ghost" })] }) })) : null, !creating && !editingKey && keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, !creating && !editingKey && error ? (_jsx("p", { className: "text-destructive text-sm", children: error })) : null, !creating && !editingKey ? (_jsx("div", { className: "max-w-full min-w-0", children: _jsx(DataTable, { columnDefs: apiKeyColumns({ m }), rowData: keys, features: {
|
|
1550
|
+
})) }), _jsx(SubmitError, { result: createResult }), _jsx(SubmitButton, { form: createForm })] }) }) })) : null, creating && createdKey ? (_jsx("div", { className: "flex min-w-0 flex-col gap-3", children: _jsxs("div", { className: "bg-muted/50 flex min-w-0 items-center justify-between gap-3 rounded-md border px-3 py-2", children: [_jsx("code", { className: "block min-w-0 flex-1 overflow-x-auto text-sm whitespace-nowrap", children: createdKey }), _jsx(CopyButton, { className: "shrink-0", locale: locale, value: createdKey, variant: "ghost" })] }) })) : null, !creating && !editingKey && keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, !creating && !editingKey && error ? (_jsx("p", { className: "text-destructive text-sm", children: error })) : null, !creating && !editingKey ? (_jsx("div", { className: "max-w-full min-w-0", children: _jsx(DataTable, { columnDefs: apiKeyColumns({ m }), rowData: keys, features: {
|
|
1554
1551
|
export: { baseName: `${organization.slug}-api-keys` },
|
|
1555
1552
|
gallery: false,
|
|
1556
1553
|
rowActions: {
|
|
@@ -648,7 +648,7 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
|
|
|
648
648
|
? m.user_two_factor_enabled()
|
|
649
649
|
: m.user_two_factor_disabled() })] }), hasTwoFactorEnabled(session?.user) ? (_jsx(AccountSecuritySettings, { baseUrl: resolvedBaseUrl, accountCache: accountCache, onSetup: setTotpSetup })) : (_jsx(Button, { type: "button", className: "self-start", onClick: () => setManagingTwoFactor(true), children: m.user_two_factor_enable_submit() }))] })] })) })] }) }), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "apiKeys", onOpenChange: (open) => {
|
|
650
650
|
setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
651
|
-
}, children: _jsx(ScrollableDialogContent, { size: "4xl", children: _jsx(ApiKeyManager, { baseUrl: resolvedBaseUrl, active: settingsDialog === "apiKeys", permissionLabels: auth?.accessLabels ?? undefined, permissions: apiKeyPermissions ?? auth?.access?.apiKeyPermissions.user ?? {} }) }) }), isAdmin ? (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: settingsDialog === "adminUsers", onOpenChange: (open) => {
|
|
651
|
+
}, children: _jsx(ScrollableDialogContent, { size: "4xl", children: _jsx(ApiKeyManager, { baseUrl: resolvedBaseUrl, active: settingsDialog === "apiKeys", locale: auth?.locale ?? "en", permissionLabels: auth?.accessLabels ?? undefined, permissions: apiKeyPermissions ?? auth?.access?.apiKeyPermissions.user ?? {} }) }) }), isAdmin ? (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: settingsDialog === "adminUsers", onOpenChange: (open) => {
|
|
652
652
|
setSettingsDialog((current) => open ? "adminUsers" : current === "adminUsers" ? null : current);
|
|
653
653
|
}, children: _jsxs(ScrollableDialogContent, { size: "6xl", children: [_jsx(ScrollableDialogHeader, { children: _jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_button_admin_users() }), _jsx(DialogDescription, { children: m.user_button_admin_users_description() })] }) }), _jsx(ScrollableDialogBody, { children: _jsx(AdminUsersTable, {}) })] }) }), _jsx(Dialog, { open: settingsDialog === "adminOrganizations", onOpenChange: (open) => {
|
|
654
654
|
setSettingsDialog((current) => open
|
|
@@ -803,6 +803,7 @@ const providerName = (providerId, m) => {
|
|
|
803
803
|
return providerId;
|
|
804
804
|
};
|
|
805
805
|
const UserForm = ({ defaultValues, error, onSubmit, }) => {
|
|
806
|
+
const auth = useKrakstackAuth();
|
|
806
807
|
const m = useUserButtonMessages();
|
|
807
808
|
const [editingLocale, setEditingLocale] = useState(getLocale());
|
|
808
809
|
const [form] = useState(() => FormReact.make(userFormBuilder, {
|
|
@@ -829,7 +830,7 @@ const UserForm = ({ defaultValues, error, onSubmit, }) => {
|
|
|
829
830
|
height: 96,
|
|
830
831
|
suggestedWidth: 512,
|
|
831
832
|
suggestedHeight: 512,
|
|
832
|
-
} }), _jsx(form.name, { label: m.user_form_name_label(), autoComplete: "name", required: true }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h3", { className: "text-sm leading-none font-medium", children: m.user_contact_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_contact_description() })] }), _jsx(EditingLocaleSwitcher, { value: editingLocale, onValueChange: setEditingLocale })] }), _jsx(UserContactGroup, { title: m.user_contact_email_type(), children: _jsx(form.emails, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_phone_type(), children: _jsx(form.phones, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_website_type(), children: _jsx(form.websites, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_social_type(), children: _jsx(form.socials, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) })] })] }), _jsx(DialogFooter, { className: "-mx-6 -mb-6 border-t px-6 py-4", children: _jsxs("div", { className: "flex flex-col gap-3", children: [error && (_jsx("p", { role: "alert", className: "text-destructive text-sm", children: error })), _jsx(SubmitButton, { form: form })] }) })] }) }) }));
|
|
833
|
+
} }), _jsx(form.name, { label: m.user_form_name_label(), autoComplete: "name", required: true }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h3", { className: "text-sm leading-none font-medium", children: m.user_contact_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_contact_description() })] }), _jsx(EditingLocaleSwitcher, { locale: auth?.locale, value: editingLocale, onValueChange: (value) => setEditingLocale(value === "fr" ? "fr" : "en") })] }), _jsx(UserContactGroup, { title: m.user_contact_email_type(), children: _jsx(form.emails, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_phone_type(), children: _jsx(form.phones, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_website_type(), children: _jsx(form.websites, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_social_type(), children: _jsx(form.socials, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) })] })] }), _jsx(DialogFooter, { className: "-mx-6 -mb-6 border-t px-6 py-4", children: _jsxs("div", { className: "flex flex-col gap-3", children: [error && (_jsx("p", { role: "alert", className: "text-destructive text-sm", children: error })), _jsx(SubmitButton, { form: form })] }) })] }) }) }));
|
|
833
834
|
};
|
|
834
835
|
const UserContactGroup = ({ children, title, }) => (_jsxs("div", { className: "flex flex-col gap-3", children: [_jsx("h4", { className: "text-sm font-medium", children: title }), children] }));
|
|
835
836
|
function AccountSecuritySettings({ baseUrl, accountCache, onSetup, }) {
|
|
@@ -924,7 +925,7 @@ function DisableTotpForm({ baseUrl, requirePassword, onDisabled, }) {
|
|
|
924
925
|
submit();
|
|
925
926
|
}, children: [requirePassword ? (_jsx(form.password, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) : null, _jsx(SubmitError, { result: submitResult }), requirePassword ? (_jsx(SubmitButton, { form: form, children: m.user_confirm_password() })) : (_jsxs(Button, { type: "button", disabled: submitResult.waiting, onClick: () => submit(), children: [submitResult.waiting ? (_jsx(Loader2, { "data-icon": "inline-start", className: "animate-spin" })) : null, effectFormMessages().submit] }))] }) }));
|
|
926
927
|
}
|
|
927
|
-
function ApiKeyManager({ baseUrl, active, permissionLabels, permissions = {}, }) {
|
|
928
|
+
function ApiKeyManager({ baseUrl, active, locale, permissionLabels, permissions = {}, }) {
|
|
928
929
|
const m = useUserButtonMessages();
|
|
929
930
|
const hasOpened = useOpenedOnce(active);
|
|
930
931
|
const loadedKeysAtom = userApiKeysAtom(baseUrl);
|
|
@@ -1020,10 +1021,7 @@ function ApiKeyManager({ baseUrl, active, permissionLabels, permissions = {}, })
|
|
|
1020
1021
|
}, children: [_jsx(createForm.name, { label: m.user_api_key_name(), required: true }), _jsx(createForm.referrers, { label: m.user_api_key_referrers(), description: m.user_api_key_referrers_description(), placeholder: m.user_api_key_referrers_placeholder(), rows: 3 }), _jsx(ApiKeyPermissions, { clearAllLabel: m.user_api_key_permissions_clear_all(), description: m.user_api_key_permissions_description(), idPrefix: "user-create", permissions: permissions, labels: permissionLabels, selectAllLabel: m.user_api_key_permissions_select_all(), selected: selectedPermissions, title: m.user_api_key_permissions(), onChange: togglePermission, onChangeAll: (ids, checked) => setSelectedPermissions((current) => ({
|
|
1021
1022
|
...current,
|
|
1022
1023
|
...Object.fromEntries(ids.map((id) => [id, checked])),
|
|
1023
|
-
})) }), _jsx(SubmitError, { result: createSubmitResult }), _jsx(SubmitButton, { form: createForm })] }) }) })) : null, creating && createdKey ? (_jsx("div", { className: "flex min-w-0 flex-col gap-3", children: _jsxs("div", { className: "bg-muted/50 flex min-w-0 items-center justify-between gap-3 rounded-md border px-3 py-2", children: [_jsx("code", { className: "block min-w-0 flex-1 overflow-x-auto text-sm whitespace-nowrap", children: createdKey }), _jsx(CopyButton, { className: "shrink-0",
|
|
1024
|
-
copied: m.user_api_key_copied(),
|
|
1025
|
-
copy: m.user_api_key_copy(),
|
|
1026
|
-
}, value: createdKey, variant: "ghost" })] }) })) : null, !creating && !editingKey && keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, !creating && !editingKey && error ? (_jsx("p", { className: "text-destructive text-sm", children: error })) : null, !creating && !editingKey ? (_jsx("div", { className: "max-w-full min-w-0", children: _jsx(DataTable, { columnDefs: apiKeyColumns({ m }), rowData: keys, features: {
|
|
1024
|
+
})) }), _jsx(SubmitError, { result: createSubmitResult }), _jsx(SubmitButton, { form: createForm })] }) }) })) : null, creating && createdKey ? (_jsx("div", { className: "flex min-w-0 flex-col gap-3", children: _jsxs("div", { className: "bg-muted/50 flex min-w-0 items-center justify-between gap-3 rounded-md border px-3 py-2", children: [_jsx("code", { className: "block min-w-0 flex-1 overflow-x-auto text-sm whitespace-nowrap", children: createdKey }), _jsx(CopyButton, { className: "shrink-0", locale: locale, value: createdKey, variant: "ghost" })] }) })) : null, !creating && !editingKey && keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, !creating && !editingKey && error ? (_jsx("p", { className: "text-destructive text-sm", children: error })) : null, !creating && !editingKey ? (_jsx("div", { className: "max-w-full min-w-0", children: _jsx(DataTable, { columnDefs: apiKeyColumns({ m }), rowData: keys, features: {
|
|
1027
1025
|
export: { baseName: m.user_api_keys_export_file_name() },
|
|
1028
1026
|
gallery: false,
|
|
1029
1027
|
rowActions: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/auth",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"description": "Effect HttpApi clients and schemas for KrakStack Auth.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"@effect/atom-react": "4.0.0-rc.112",
|
|
79
|
-
"@krak-stack/registry": "^0.1.
|
|
79
|
+
"@krak-stack/registry": "^0.1.33",
|
|
80
80
|
"@lucas-barake/effect-form-react": "0.26.0-beta.5",
|
|
81
81
|
"react-qr-code": "^2.2.0"
|
|
82
82
|
},
|