@krak-stack/auth 0.2.0 → 0.2.2
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/access.d.ts +1 -3
- package/dist/access.js +1 -3
- package/dist/admin/api.group.d.ts +36 -36
- package/dist/admin/api.group.js +13 -13
- package/dist/api.d.ts +2109 -865
- package/dist/auth/api.group.d.ts +664 -106
- package/dist/auth/api.group.js +8 -8
- package/dist/auth/schema.d.ts +537 -70
- package/dist/auth/schema.js +26 -10
- package/dist/components/admin-organization-form.js +1 -0
- package/dist/components/admin-organizations.d.ts +4 -5
- package/dist/components/admin-organizations.js +34 -31
- package/dist/components/admin-users.d.ts +5 -6
- package/dist/components/admin-users.js +51 -50
- package/dist/components/api-key-edit-form.js +2 -1
- package/dist/components/auth-atoms.d.ts +213 -103
- package/dist/components/auth-client-api.d.ts +1412 -2371
- package/dist/components/auth-client-api.js +11 -7
- package/dist/components/auth-forms.js +6 -1
- package/dist/components/auth-provider.d.ts +13 -13
- package/dist/components/contact-fields.d.ts +40 -0
- package/dist/components/contact-fields.js +86 -0
- package/dist/components/member-required.js +2 -2
- package/dist/components/organization-switcher.js +101 -193
- package/dist/components/user-button.d.ts +73 -0
- package/dist/components/user-button.js +179 -29
- package/dist/extra/api.group.d.ts +19 -19
- package/dist/extra/api.group.js +3 -3
- package/dist/extra/schema.d.ts +1 -2
- package/dist/extra/schema.js +1 -2
- package/dist/query.js +5 -5
- package/dist/schema.d.ts +279 -12
- package/dist/schema.js +162 -42
- package/dist/server/api.group.d.ts +157 -29
- package/dist/server/api.group.js +12 -12
- package/dist/server/schema.d.ts +64 -0
- package/dist/service.d.ts +3380 -2446
- package/package.json +4 -4
package/dist/auth/schema.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
+
import { User, UserMetadata } from "../schema.js";
|
|
2
3
|
const JsonRecord = Schema.Record(Schema.String, Schema.Json);
|
|
3
4
|
const StringArrayRecord = Schema.Record(Schema.String, Schema.Array(Schema.String));
|
|
4
5
|
export const AuthUser = Schema.Struct({
|
|
@@ -7,6 +8,7 @@ export const AuthUser = Schema.Struct({
|
|
|
7
8
|
email: Schema.String,
|
|
8
9
|
emailVerified: Schema.Boolean,
|
|
9
10
|
image: Schema.NullOr(Schema.String),
|
|
11
|
+
metadata: User.fields.metadata,
|
|
10
12
|
role: Schema.NullOr(Schema.String),
|
|
11
13
|
banned: Schema.NullOr(Schema.Boolean),
|
|
12
14
|
banReason: Schema.optional(Schema.NullOr(Schema.String)),
|
|
@@ -72,50 +74,53 @@ export const AuthErrorBody = Schema.Struct({
|
|
|
72
74
|
title: "Auth error",
|
|
73
75
|
description: "Wire error returned by an authentication endpoint.",
|
|
74
76
|
});
|
|
75
|
-
const authErrorFields =
|
|
76
|
-
|
|
77
|
+
const authErrorFields = (tag) => ({
|
|
78
|
+
_tag: Schema.tagDefaultOmit(tag),
|
|
79
|
+
...AuthErrorBody.fields,
|
|
80
|
+
});
|
|
81
|
+
export class AuthBadRequest extends Schema.TaggedError()("AuthBadRequest", authErrorFields("AuthBadRequest"), {
|
|
77
82
|
identifier: "AuthBadRequest",
|
|
78
83
|
title: "Bad request",
|
|
79
84
|
httpApiStatus: 400,
|
|
80
85
|
}) {
|
|
81
86
|
}
|
|
82
|
-
export class AuthUnauthorized extends Schema.
|
|
87
|
+
export class AuthUnauthorized extends Schema.TaggedError()("AuthUnauthorized", authErrorFields("AuthUnauthorized"), {
|
|
83
88
|
identifier: "AuthUnauthorized",
|
|
84
89
|
title: "Unauthorized",
|
|
85
90
|
httpApiStatus: 401,
|
|
86
91
|
}) {
|
|
87
92
|
}
|
|
88
|
-
export class AuthForbidden extends Schema.
|
|
93
|
+
export class AuthForbidden extends Schema.TaggedError()("AuthForbidden", authErrorFields("AuthForbidden"), {
|
|
89
94
|
identifier: "AuthForbidden",
|
|
90
95
|
title: "Forbidden",
|
|
91
96
|
httpApiStatus: 403,
|
|
92
97
|
}) {
|
|
93
98
|
}
|
|
94
|
-
export class AuthNotFound extends Schema.
|
|
99
|
+
export class AuthNotFound extends Schema.TaggedError()("AuthNotFound", authErrorFields("AuthNotFound"), {
|
|
95
100
|
identifier: "AuthNotFound",
|
|
96
101
|
title: "Not found",
|
|
97
102
|
httpApiStatus: 404,
|
|
98
103
|
}) {
|
|
99
104
|
}
|
|
100
|
-
export class AuthConflict extends Schema.
|
|
105
|
+
export class AuthConflict extends Schema.TaggedError()("AuthConflict", authErrorFields("AuthConflict"), {
|
|
101
106
|
identifier: "AuthConflict",
|
|
102
107
|
title: "Conflict",
|
|
103
108
|
httpApiStatus: 409,
|
|
104
109
|
}) {
|
|
105
110
|
}
|
|
106
|
-
export class AuthExpectationFailed extends Schema.
|
|
111
|
+
export class AuthExpectationFailed extends Schema.TaggedError()("AuthExpectationFailed", authErrorFields("AuthExpectationFailed"), {
|
|
107
112
|
identifier: "AuthExpectationFailed",
|
|
108
113
|
title: "Expectation failed",
|
|
109
114
|
httpApiStatus: 417,
|
|
110
115
|
}) {
|
|
111
116
|
}
|
|
112
|
-
export class AuthTooManyRequests extends Schema.
|
|
117
|
+
export class AuthTooManyRequests extends Schema.TaggedError()("AuthTooManyRequests", authErrorFields("AuthTooManyRequests"), {
|
|
113
118
|
identifier: "AuthTooManyRequests",
|
|
114
119
|
title: "Too many requests",
|
|
115
120
|
httpApiStatus: 429,
|
|
116
121
|
}) {
|
|
117
122
|
}
|
|
118
|
-
export class AuthInternalServerError extends Schema.
|
|
123
|
+
export class AuthInternalServerError extends Schema.TaggedError()("AuthInternalServerError", authErrorFields("AuthInternalServerError"), {
|
|
119
124
|
identifier: "AuthInternalServerError",
|
|
120
125
|
title: "Internal server error",
|
|
121
126
|
httpApiStatus: 500,
|
|
@@ -124,6 +129,7 @@ export class AuthInternalServerError extends Schema.ErrorClass("AuthInternalServ
|
|
|
124
129
|
export const UpdateUserPayload = Schema.Struct({
|
|
125
130
|
name: Schema.optional(Schema.String),
|
|
126
131
|
image: Schema.optional(Schema.NullOr(Schema.String)),
|
|
132
|
+
metadata: Schema.optional(Schema.NullOr(UserMetadata)),
|
|
127
133
|
}).annotate({ identifier: "UpdateUserPayload", title: "Update user payload" });
|
|
128
134
|
export const SignInEmailPayload = Schema.Struct({
|
|
129
135
|
email: Schema.String,
|
|
@@ -360,9 +366,19 @@ export const AuthMemberRecord = Schema.Struct({
|
|
|
360
366
|
identifier: "AuthMemberRecord",
|
|
361
367
|
title: "Organization member record",
|
|
362
368
|
});
|
|
369
|
+
export const AuthMemberUser = Schema.Struct({
|
|
370
|
+
id: Schema.String,
|
|
371
|
+
name: Schema.String,
|
|
372
|
+
email: Schema.String,
|
|
373
|
+
image: Schema.optional(Schema.NullOr(Schema.String)),
|
|
374
|
+
metadata: User.fields.metadata,
|
|
375
|
+
}).annotate({
|
|
376
|
+
identifier: "AuthMemberUser",
|
|
377
|
+
title: "Organization member user",
|
|
378
|
+
});
|
|
363
379
|
export const AuthMember = Schema.Struct({
|
|
364
380
|
...AuthMemberRecord.fields,
|
|
365
|
-
user:
|
|
381
|
+
user: AuthMemberUser,
|
|
366
382
|
}).annotate({ identifier: "AuthMember", title: "Organization member" });
|
|
367
383
|
export const AuthInvitation = Schema.Struct({
|
|
368
384
|
id: Schema.String,
|
|
@@ -72,6 +72,7 @@ const organizationFormBuilder = FormBuilder.empty
|
|
|
72
72
|
.addField("logo", Schema.UndefinedOr(Schema.NullOr(Schema.Union([Schema.String, Schema.instanceOf(File)]))))
|
|
73
73
|
.addField("parentId", Schema.String);
|
|
74
74
|
const makeOrganizationForm = ({ baseUrl, organization, }) => FormReact.make(organizationFormBuilder, {
|
|
75
|
+
runtime: authClientApi(baseUrl).runtime,
|
|
75
76
|
fields: {
|
|
76
77
|
name: TextField,
|
|
77
78
|
slug: TextField,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
from?: ValidateFromPath;
|
|
1
|
+
import { type QueryType } from "@krak-stack/registry/query";
|
|
2
|
+
export declare function AdminOrganizationsTable({ onSearchChange, reloadKey, search, }: {
|
|
3
|
+
onSearchChange?: (search: QueryType) => void;
|
|
5
4
|
reloadKey?: number;
|
|
6
|
-
search?:
|
|
5
|
+
search?: QueryType;
|
|
7
6
|
}): import("react").JSX.Element;
|
|
@@ -6,6 +6,7 @@ import { Building2, Pencil, Trash2 } from "lucide-react";
|
|
|
6
6
|
import { useState } from "react";
|
|
7
7
|
import { toast } from "sonner";
|
|
8
8
|
import { DataTable, DataTableListSummary, } from "@krak-stack/registry/data-table";
|
|
9
|
+
import { SortParamsFromString, } from "@krak-stack/registry/query";
|
|
9
10
|
import { ErrorMessage } from "@krak-stack/registry/effect-form";
|
|
10
11
|
import { AppBrand } from "@krak-stack/registry/app-brand";
|
|
11
12
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
|
|
@@ -75,7 +76,10 @@ const organizationsQuery = (search, projectId) => {
|
|
|
75
76
|
if (search.globalFilter)
|
|
76
77
|
query = { ...query, globalFilter: search.globalFilter };
|
|
77
78
|
if (search.sort)
|
|
78
|
-
query = {
|
|
79
|
+
query = {
|
|
80
|
+
...query,
|
|
81
|
+
sort: Schema.encodeSync(SortParamsFromString)(search.sort),
|
|
82
|
+
};
|
|
79
83
|
if (projectId)
|
|
80
84
|
query = { ...query, projectId };
|
|
81
85
|
return query;
|
|
@@ -96,7 +100,7 @@ const organizationsAtom = Atom.family((baseUrl) => Atom.family((key) => {
|
|
|
96
100
|
serializationKey: `organizations:${reloadKey}:${JSON.stringify(query)}`,
|
|
97
101
|
});
|
|
98
102
|
}));
|
|
99
|
-
export function AdminOrganizationsTable({
|
|
103
|
+
export function AdminOrganizationsTable({ onSearchChange, reloadKey = 0, search, }) {
|
|
100
104
|
const auth = useKrakstackAuth();
|
|
101
105
|
const locale = auth?.locale ?? "en";
|
|
102
106
|
const m = labels(locale);
|
|
@@ -106,7 +110,8 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
|
106
110
|
const [editingOrganization, setEditingOrganization] = useState(null);
|
|
107
111
|
const [deletingOrganization, setDeletingOrganization] = useState(null);
|
|
108
112
|
const [localSearch, setLocalSearch] = useState({
|
|
109
|
-
|
|
113
|
+
page: 0,
|
|
114
|
+
pageSize: 10,
|
|
110
115
|
});
|
|
111
116
|
const tableSearch = search ?? localSearch;
|
|
112
117
|
const result = useAtomValue(organizationsAtom(baseUrl)(adminOrganizationsFamilyKey(tableSearch, projectId, reloadKey + refreshKey)));
|
|
@@ -130,11 +135,12 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
|
130
135
|
onFailure: () => false,
|
|
131
136
|
onSuccess: () => false,
|
|
132
137
|
});
|
|
133
|
-
return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(DataTable, {
|
|
134
|
-
columnVisibility:
|
|
138
|
+
return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(DataTable, { columnDefs: organizationColumns(m, locale, baseUrl), rowData: organizations, features: {
|
|
139
|
+
columnVisibility: true,
|
|
135
140
|
export: { baseName: "organizations" },
|
|
136
141
|
gallery: false,
|
|
137
142
|
pagination: { mode: "server", rowCount: total },
|
|
143
|
+
refresh: () => setRefreshKey((current) => current + 1),
|
|
138
144
|
rowActions: {
|
|
139
145
|
items: [
|
|
140
146
|
{
|
|
@@ -151,13 +157,15 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
|
151
157
|
},
|
|
152
158
|
],
|
|
153
159
|
},
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
onSearchChange
|
|
158
|
-
searchState: "local",
|
|
160
|
+
}, initialState: tableSearch, onStateChange: ({ page, pageSize, globalFilter, sort }) => {
|
|
161
|
+
const nextSearch = { page, pageSize, globalFilter, sort };
|
|
162
|
+
if (onSearchChange) {
|
|
163
|
+
onSearchChange(nextSearch);
|
|
159
164
|
}
|
|
160
|
-
|
|
165
|
+
else {
|
|
166
|
+
setLocalSearch(nextSearch);
|
|
167
|
+
}
|
|
168
|
+
}, status: { loading: isLoading } }), editingOrganization ? (_jsx(AdminOrganizationForm, { organization: editingOrganization, onClose: () => setEditingOrganization(null), onSaved: () => setRefreshKey((current) => current + 1) })) : null, deletingOrganization ? (_jsx(DeleteOrganizationDialog, { labels: m, organization: deletingOrganization, baseUrl: baseUrl, onClose: () => setDeletingOrganization(null), onDeleted: () => {
|
|
161
169
|
toast.success(m.organization_deleted_toast);
|
|
162
170
|
setDeletingOrganization(null);
|
|
163
171
|
setRefreshKey((current) => current + 1);
|
|
@@ -165,27 +173,22 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
|
165
173
|
}
|
|
166
174
|
const organizationColumns = (m, locale, baseUrl) => [
|
|
167
175
|
{
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
accessorKey: "name",
|
|
174
|
-
header: m.admin_column_organization,
|
|
175
|
-
cell: ({ row }) => {
|
|
176
|
-
const display = organizationDisplay(row.original, locale, baseUrl);
|
|
177
|
-
return (_jsx(AppBrand, { to: null, label: display.name, subtitle: row.original.slug, icon: Building2, className: "min-w-56", ...(display.image ? { imageSrc: display.image } : {}) }));
|
|
176
|
+
field: "name",
|
|
177
|
+
headerName: m.admin_column_organization,
|
|
178
|
+
cellRenderer: ({ data }) => {
|
|
179
|
+
const display = organizationDisplay(data, locale, baseUrl);
|
|
180
|
+
return (_jsx(AppBrand, { to: null, label: display.name, subtitle: data.slug, icon: Building2, className: "min-w-56", ...(display.image ? { imageSrc: display.image } : {}) }));
|
|
178
181
|
},
|
|
179
182
|
},
|
|
180
183
|
{
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
field: "memberCount",
|
|
185
|
+
headerName: m.admin_column_members,
|
|
186
|
+
cellRenderer: ({ data }) => (_jsx(OrganizationMembers, { baseUrl: baseUrl, members: data.memberPreviews ?? [], total: data.memberCount ?? 0 })),
|
|
184
187
|
},
|
|
185
188
|
{
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
+
field: "projects",
|
|
190
|
+
headerName: m.admin_column_projects,
|
|
191
|
+
cellRenderer: ({ data }) => (_jsx(DataTableListSummary, { emptyLabel: "-", items: (data.projects ?? []).map((project) => {
|
|
189
192
|
const logo = assetUrl(project.logo, baseUrl);
|
|
190
193
|
return {
|
|
191
194
|
label: project.name,
|
|
@@ -195,9 +198,9 @@ const organizationColumns = (m, locale, baseUrl) => [
|
|
|
195
198
|
}), variant: "icon" })),
|
|
196
199
|
},
|
|
197
200
|
{
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
+
field: "createdAt",
|
|
202
|
+
headerName: m.admin_column_created,
|
|
203
|
+
cellRenderer: ({ data }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: new Date(data.createdAt).toLocaleDateString() })),
|
|
201
204
|
},
|
|
202
205
|
];
|
|
203
206
|
const initials = (name) => name
|
|
@@ -217,7 +220,7 @@ function OrganizationMembers({ baseUrl, members, total, }) {
|
|
|
217
220
|
}), totalCount: total, variant: "icon" }));
|
|
218
221
|
}
|
|
219
222
|
function DeleteOrganizationDialog({ baseUrl, labels: m, organization, onClose, onDeleted, }) {
|
|
220
|
-
const [deleteOrganizationAtom] = useState(() =>
|
|
223
|
+
const [deleteOrganizationAtom] = useState(() => authClientApi(baseUrl).runtime.fn((id) => Effect.flatMap(authHttpClient(baseUrl), (http) => http.admin.deleteOrganization({ params: { id } }))));
|
|
221
224
|
const deleteOrganization = useAtomSet(deleteOrganizationAtom);
|
|
222
225
|
const result = useAtomValue(deleteOrganizationAtom);
|
|
223
226
|
useAtomSubscribe(deleteOrganizationAtom, (current) => {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
from?: ValidateFromPath;
|
|
1
|
+
import { type QueryType } from "@krak-stack/registry/query";
|
|
2
|
+
export declare function AdminUsersTable({ onSearchChange, reloadKey, search, }: {
|
|
3
|
+
onSearchChange?: (search: QueryType) => void;
|
|
5
4
|
reloadKey?: number;
|
|
6
|
-
search?:
|
|
5
|
+
search?: QueryType;
|
|
7
6
|
}): import("react").JSX.Element;
|
|
8
|
-
export declare function useAdminUsersTotal(search:
|
|
7
|
+
export declare function useAdminUsersTotal(search: QueryType): number;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useAtomRefresh, useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
3
|
-
import { useNavigate, useRouter
|
|
3
|
+
import { useNavigate, useRouter } from "@tanstack/react-router";
|
|
4
4
|
import { Atom, AsyncResult } from "effect/unstable/reactivity";
|
|
5
5
|
import { Effect, Option, Schema } from "effect";
|
|
6
6
|
import { Ban, Building2, Loader2, ShieldOff, UserCog, UserIcon, } from "lucide-react";
|
|
7
7
|
import { useState } from "react";
|
|
8
8
|
import { DataTable, DataTableListSummary, } from "@krak-stack/registry/data-table";
|
|
9
|
+
import { SortParamsFromString, } from "@krak-stack/registry/query";
|
|
9
10
|
import { ErrorMessage } from "@krak-stack/registry/effect-form";
|
|
10
11
|
import { AppBrand } from "@krak-stack/registry/app-brand";
|
|
11
12
|
import { Badge } from "@/components/ui/badge";
|
|
@@ -104,7 +105,10 @@ const adminUsersQuery = (search, projectId) => {
|
|
|
104
105
|
if (search.globalFilter)
|
|
105
106
|
query = { ...query, globalFilter: search.globalFilter };
|
|
106
107
|
if (search.sort)
|
|
107
|
-
query = {
|
|
108
|
+
query = {
|
|
109
|
+
...query,
|
|
110
|
+
sort: Schema.encodeSync(SortParamsFromString)(search.sort),
|
|
111
|
+
};
|
|
108
112
|
if (projectId)
|
|
109
113
|
query = { ...query, projectId };
|
|
110
114
|
return query;
|
|
@@ -126,7 +130,7 @@ const activeOrganizationId = (session) => {
|
|
|
126
130
|
const value = session?.session?.activeOrganizationId;
|
|
127
131
|
return Option.getOrNull(Schema.decodeUnknownOption(Schema.NonEmptyString)(value));
|
|
128
132
|
};
|
|
129
|
-
export function AdminUsersTable({
|
|
133
|
+
export function AdminUsersTable({ onSearchChange, reloadKey = 0, search, }) {
|
|
130
134
|
const navigate = useNavigate();
|
|
131
135
|
const router = useRouter();
|
|
132
136
|
const auth = useKrakstackAuth();
|
|
@@ -144,13 +148,14 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
|
|
|
144
148
|
const [impersonateError, setImpersonateError] = useState("");
|
|
145
149
|
const [refreshKey, setRefreshKey] = useState(0);
|
|
146
150
|
const [localSearch, setLocalSearch] = useState({
|
|
147
|
-
|
|
151
|
+
page: 0,
|
|
152
|
+
pageSize: 10,
|
|
148
153
|
});
|
|
149
154
|
const tableSearch = search ?? localSearch;
|
|
150
155
|
const result = useAtomValue(usersAtom(baseUrl)(adminUsersFamilyKey(tableSearch, projectId, reloadKey + refreshKey)));
|
|
151
156
|
const [banningUser, setBanningUser] = useState(null);
|
|
152
157
|
const [unbanningUser, setUnbanningUser] = useState(null);
|
|
153
|
-
const [impersonateUserAtom] = useState(() =>
|
|
158
|
+
const [impersonateUserAtom] = useState(() => authClientApi(baseUrl).runtime.fn((userId) => Effect.gen(function* () {
|
|
154
159
|
const client = yield* authHttpClient(baseUrl);
|
|
155
160
|
yield* client.auth.adminImpersonateUser({ payload: { userId } });
|
|
156
161
|
notifyAuthChange();
|
|
@@ -168,7 +173,7 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
|
|
|
168
173
|
}).pipe(Effect.catch((cause) => Effect.sync(() => setImpersonateError(cause instanceof Error
|
|
169
174
|
? cause.message
|
|
170
175
|
: m.admin_error_impersonate))))));
|
|
171
|
-
const [impersonateOrganizationUserAtom] = useState(() =>
|
|
176
|
+
const [impersonateOrganizationUserAtom] = useState(() => authClientApi(baseUrl).runtime.fn(({ actorUserId, organizationId, targetUserId, }) => Effect.gen(function* () {
|
|
172
177
|
const client = yield* authHttpClient(baseUrl);
|
|
173
178
|
yield* client.auth.organizationImpersonateUser({
|
|
174
179
|
payload: { organizationId, actorUserId, targetUserId },
|
|
@@ -213,11 +218,12 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
|
|
|
213
218
|
onFailure: () => false,
|
|
214
219
|
onSuccess: () => false,
|
|
215
220
|
});
|
|
216
|
-
return (_jsxs(_Fragment, { children: [error ? _jsx(ErrorMessage, { text: error }) : null, impersonateError ? _jsx(ErrorMessage, { text: impersonateError }) : null, _jsx(DataTable, {
|
|
217
|
-
columnVisibility:
|
|
221
|
+
return (_jsxs(_Fragment, { children: [error ? _jsx(ErrorMessage, { text: error }) : null, impersonateError ? _jsx(ErrorMessage, { text: impersonateError }) : null, _jsx(DataTable, { columnDefs: userColumns(m, baseUrl), rowData: users, features: {
|
|
222
|
+
columnVisibility: true,
|
|
218
223
|
export: { baseName: "users" },
|
|
219
224
|
gallery: false,
|
|
220
225
|
pagination: { mode: "server", rowCount: total },
|
|
226
|
+
refresh: () => setRefreshKey((current) => current + 1),
|
|
221
227
|
rowActions: {
|
|
222
228
|
items: [
|
|
223
229
|
{
|
|
@@ -266,13 +272,15 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
|
|
|
266
272
|
},
|
|
267
273
|
],
|
|
268
274
|
},
|
|
269
|
-
},
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
onSearchChange
|
|
273
|
-
searchState: "local",
|
|
275
|
+
}, initialState: tableSearch, onStateChange: ({ page, pageSize, globalFilter, sort }) => {
|
|
276
|
+
const nextSearch = { page, pageSize, globalFilter, sort };
|
|
277
|
+
if (onSearchChange) {
|
|
278
|
+
onSearchChange(nextSearch);
|
|
274
279
|
}
|
|
275
|
-
|
|
280
|
+
else {
|
|
281
|
+
setLocalSearch(nextSearch);
|
|
282
|
+
}
|
|
283
|
+
}, status: { loading: isLoading } }), banningUser ? (_jsx(BanUserDialog, { labels: m, baseUrl: baseUrl, user: banningUser, onBanned: () => setRefreshKey((current) => current + 1), onClose: () => setBanningUser(null) })) : null, unbanningUser ? (_jsx(UnbanUserDialog, { labels: m, baseUrl: baseUrl, user: unbanningUser, onUnbanned: () => setRefreshKey((current) => current + 1), onClose: () => setUnbanningUser(null) })) : null] }));
|
|
276
284
|
}
|
|
277
285
|
export function useAdminUsersTotal(search) {
|
|
278
286
|
const auth = useKrakstackAuth();
|
|
@@ -285,22 +293,17 @@ export function useAdminUsersTotal(search) {
|
|
|
285
293
|
}
|
|
286
294
|
const userColumns = (m, baseUrl) => [
|
|
287
295
|
{
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
accessorKey: "email",
|
|
294
|
-
header: m.admin_column_user,
|
|
295
|
-
cell: ({ row }) => {
|
|
296
|
-
const image = assetUrl(row.original.image);
|
|
297
|
-
return (_jsx(AppBrand, { to: null, label: row.original.email, subtitle: row.original.name, icon: UserIcon, className: "min-w-48", ...(image ? { imageSrc: image } : {}) }));
|
|
296
|
+
field: "email",
|
|
297
|
+
headerName: m.admin_column_user,
|
|
298
|
+
cellRenderer: ({ data }) => {
|
|
299
|
+
const image = assetUrl(data.image);
|
|
300
|
+
return (_jsx(AppBrand, { to: null, label: data.email, subtitle: data.name, icon: UserIcon, className: "min-w-48", ...(image ? { imageSrc: image } : {}) }));
|
|
298
301
|
},
|
|
299
302
|
},
|
|
300
303
|
{
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
+
field: "organizations",
|
|
305
|
+
headerName: m.admin_column_organizations,
|
|
306
|
+
cellRenderer: ({ data }) => (_jsx(DataTableListSummary, { emptyLabel: "-", items: data.organizations.map((organization) => {
|
|
304
307
|
const logo = assetUrl(organization.logo, baseUrl);
|
|
305
308
|
return {
|
|
306
309
|
label: organization.name,
|
|
@@ -310,9 +313,9 @@ const userColumns = (m, baseUrl) => [
|
|
|
310
313
|
}), variant: "icon" })),
|
|
311
314
|
},
|
|
312
315
|
{
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
+
field: "projects",
|
|
317
|
+
headerName: m.admin_column_projects,
|
|
318
|
+
cellRenderer: ({ data }) => (_jsx(DataTableListSummary, { emptyLabel: "-", items: data.projects.map((project) => {
|
|
316
319
|
const logo = assetUrl(project.logo, baseUrl);
|
|
317
320
|
return {
|
|
318
321
|
label: project.name,
|
|
@@ -322,40 +325,38 @@ const userColumns = (m, baseUrl) => [
|
|
|
322
325
|
}), variant: "icon" })),
|
|
323
326
|
},
|
|
324
327
|
{
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
+
field: "emailVerified",
|
|
329
|
+
headerName: m.admin_column_verified,
|
|
330
|
+
cellRenderer: ({ data }) => data.emailVerified ? (_jsx(Badge, { variant: "outline", children: m.admin_column_verified })) : (_jsx(Badge, { variant: "secondary", children: m.admin_column_unverified })),
|
|
328
331
|
},
|
|
329
332
|
{
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const role =
|
|
333
|
+
field: "role",
|
|
334
|
+
headerName: m.admin_column_role,
|
|
335
|
+
cellRenderer: ({ data }) => {
|
|
336
|
+
const role = data.role;
|
|
334
337
|
if (!role)
|
|
335
338
|
return _jsx(Badge, { variant: "outline", children: m.user_role_default });
|
|
336
339
|
return (_jsx("div", { className: "flex flex-wrap gap-1.5", children: role.split(",").map((r) => (_jsx(Badge, { variant: r.trim() === "admin" ? "default" : "outline", children: r.trim() }, r.trim()))) }));
|
|
337
340
|
},
|
|
338
341
|
},
|
|
339
342
|
{
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
+
field: "banned",
|
|
344
|
+
headerName: m.admin_column_status,
|
|
345
|
+
cellRenderer: ({ data }) => data.banned ? (_jsx(Badge, { variant: "destructive", children: m.admin_status_banned })) : (_jsx(Badge, { variant: "outline", children: m.admin_status_active })),
|
|
343
346
|
},
|
|
344
347
|
{
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
? new Date(row.original.lastSignedIn).toLocaleString()
|
|
349
|
-
: "-" })),
|
|
348
|
+
field: "lastSignedIn",
|
|
349
|
+
headerName: m.admin_column_last_signed_in,
|
|
350
|
+
cellRenderer: ({ data }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: data.lastSignedIn ? new Date(data.lastSignedIn).toLocaleString() : "-" })),
|
|
350
351
|
},
|
|
351
352
|
{
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
353
|
+
field: "createdAt",
|
|
354
|
+
headerName: m.admin_column_created,
|
|
355
|
+
cellRenderer: ({ data }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: new Date(data.createdAt).toLocaleDateString() })),
|
|
355
356
|
},
|
|
356
357
|
];
|
|
357
358
|
function BanUserDialog({ labels: m, baseUrl, user, onBanned, onClose, }) {
|
|
358
|
-
const [banUserAtom] = useState(() =>
|
|
359
|
+
const [banUserAtom] = useState(() => authClientApi(baseUrl).runtime.fn((userId) => Effect.flatMap(authHttpClient(baseUrl), (client) => client.auth.adminBanUser({ payload: { userId } })).pipe(Effect.tap(() => Effect.sync(onBanned)), Effect.tap(() => Effect.sync(onClose)), Effect.catch((cause) => Effect.sync(() => setError(cause instanceof Error ? cause.message : m.admin_error_ban))))));
|
|
359
360
|
const [error, setError] = useState("");
|
|
360
361
|
const banUser = useAtomSet(banUserAtom);
|
|
361
362
|
const isPending = useAtomValue(banUserAtom).waiting;
|
|
@@ -368,7 +369,7 @@ function BanUserDialog({ labels: m, baseUrl, user, onBanned, onClose, }) {
|
|
|
368
369
|
}, disabled: isPending, children: [isPending ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, m.admin_action_ban] })] })] }) }));
|
|
369
370
|
}
|
|
370
371
|
function UnbanUserDialog({ labels: m, baseUrl, user, onUnbanned, onClose, }) {
|
|
371
|
-
const [unbanUserAtom] = useState(() =>
|
|
372
|
+
const [unbanUserAtom] = useState(() => authClientApi(baseUrl).runtime.fn((userId) => Effect.flatMap(authHttpClient(baseUrl), (client) => client.auth.adminUnbanUser({ payload: { userId } })).pipe(Effect.tap(() => Effect.sync(onUnbanned)), Effect.tap(() => Effect.sync(onClose)), Effect.catch((cause) => Effect.sync(() => setError(cause instanceof Error ? cause.message : m.admin_error_unban))))));
|
|
372
373
|
const [error, setError] = useState("");
|
|
373
374
|
const unbanUser = useAtomSet(unbanUserAtom);
|
|
374
375
|
const isPending = useAtomValue(unbanUserAtom).waiting;
|
|
@@ -5,7 +5,7 @@ import { Effect, Schema } from "effect";
|
|
|
5
5
|
import { useRef, useState } from "react";
|
|
6
6
|
import { CheckboxField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
|
|
7
7
|
import { parseApiKeyReferrers } from "./api-key.js";
|
|
8
|
-
import { authHttpClient } from "./auth-client-api.js";
|
|
8
|
+
import { authClientApi, authHttpClient } from "./auth-client-api.js";
|
|
9
9
|
import { ApiKeyPermissions } from "./api-key-permissions.js";
|
|
10
10
|
import { apiKeyReferrers } from "./api-key-referrers.js";
|
|
11
11
|
import { ExtraApiKeyPermissions } from "../extra/schema.js";
|
|
@@ -32,6 +32,7 @@ export const ApiKeyEditForm = ({ baseUrl, configId, keyData, messages, permissio
|
|
|
32
32
|
permissionOptionsRef.current = permissionOptions;
|
|
33
33
|
permissionsRef.current = permissions;
|
|
34
34
|
const [form] = useState(() => FormReact.make(editApiKeyFormBuilder, {
|
|
35
|
+
runtime: authClientApi(baseUrl).runtime,
|
|
35
36
|
fields: {
|
|
36
37
|
name: TextField,
|
|
37
38
|
enabled: CheckboxField,
|