@krak-stack/auth 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,7 @@ const errors = [
15
15
  const docs = (title, description) => OpenApi.annotations({ title, summary: title, description });
16
16
  export const AuthApiGroup = HttpApiGroup.make("auth")
17
17
  .add(HttpApiEndpoint.get("getSession", "/get-session", {
18
- query: GetSessionQuery,
18
+ query: GetSessionQuery.fields,
19
19
  success: GetSessionResponse,
20
20
  error: errors,
21
21
  }).annotateMerge(docs("Get session", "Returns the current browser session.")))
@@ -117,7 +117,7 @@ export const AuthApiGroup = HttpApiGroup.make("auth")
117
117
  error: errors,
118
118
  }).annotateMerge(docs("List organizations", "Lists the user's organizations.")))
119
119
  .add(HttpApiEndpoint.get("organizationGetFull", "/organization/get-full-organization", {
120
- query: GetFullOrganizationQuery,
120
+ query: GetFullOrganizationQuery.fields,
121
121
  success: Schema.NullOr(FullAuthOrganization),
122
122
  error: errors,
123
123
  }).annotateMerge(docs("Get full organization", "Returns an organization with membership data.")))
@@ -137,12 +137,12 @@ export const AuthApiGroup = HttpApiGroup.make("auth")
137
137
  error: errors,
138
138
  }).annotateMerge(docs("Update organization", "Updates an organization.")))
139
139
  .add(HttpApiEndpoint.get("organizationListUserInvitations", "/organization/list-user-invitations", {
140
- query: UserInvitationsQuery,
140
+ query: UserInvitationsQuery.fields,
141
141
  success: Schema.Array(AuthInvitation),
142
142
  error: errors,
143
143
  }).annotateMerge(docs("List user invitations", "Lists organization invitations for the user.")))
144
144
  .add(HttpApiEndpoint.get("organizationListMembers", "/organization/list-members", {
145
- query: OrganizationListMembersQuery,
145
+ query: OrganizationListMembersQuery.fields,
146
146
  success: OrganizationListMembersResponse,
147
147
  error: errors,
148
148
  }).annotateMerge(docs("List organization members", "Lists members of an organization.")))
@@ -167,12 +167,12 @@ export const AuthApiGroup = HttpApiGroup.make("auth")
167
167
  error: errors,
168
168
  }).annotateMerge(docs("Leave organization", "Removes the current user's membership.")))
169
169
  .add(HttpApiEndpoint.get("organizationListInvitations", "/organization/list-invitations", {
170
- query: OrganizationInvitationsQuery,
170
+ query: OrganizationInvitationsQuery.fields,
171
171
  success: Schema.Array(AuthInvitation),
172
172
  error: errors,
173
173
  }).annotateMerge(docs("List organization invitations", "Lists invitations for an organization.")))
174
174
  .add(HttpApiEndpoint.get("organizationGetInvitation", "/organization/get-invitation", {
175
- query: GetInvitationQuery,
175
+ query: GetInvitationQuery.fields,
176
176
  success: GetInvitationResponse,
177
177
  error: errors,
178
178
  }).annotateMerge(docs("Get invitation", "Returns an organization invitation.")))
@@ -192,7 +192,7 @@ export const AuthApiGroup = HttpApiGroup.make("auth")
192
192
  error: errors,
193
193
  }).annotateMerge(docs("Cancel invitation", "Cancels an organization invitation.")))
194
194
  .add(HttpApiEndpoint.get("apiKeyList", "/api-key/list", {
195
- query: ListApiKeysQuery,
195
+ query: ListApiKeysQuery.fields,
196
196
  success: ListApiKeysResponse,
197
197
  error: errors,
198
198
  }).annotateMerge(docs("List API keys", "Lists user or organization API keys.")))
@@ -231,7 +231,7 @@ export const AuthApiGroup = HttpApiGroup.make("auth")
231
231
  error: errors,
232
232
  }).annotateMerge(docs("OAuth consent", "Accepts or denies an OAuth authorization request.")))
233
233
  .add(HttpApiEndpoint.get("oauthPublicClient", "/oauth2/public-client", {
234
- query: OAuthPublicClientQuery,
234
+ query: OAuthPublicClientQuery.fields,
235
235
  success: OAuthPublicClient,
236
236
  error: errors,
237
237
  }).annotateMerge(docs("Get OAuth public client", "Returns public OAuth client details.")))
@@ -103,67 +103,75 @@ export declare const AuthErrorBody: Schema.Struct<{
103
103
  readonly error: Schema.optional<Schema.String>;
104
104
  readonly error_description: Schema.optional<Schema.String>;
105
105
  }>;
106
- declare const AuthBadRequest_base: Schema.Class<AuthBadRequest, Schema.Struct<{
107
- readonly code: Schema.optional<Schema.String>;
108
- readonly message: Schema.optional<Schema.String>;
109
- readonly error: Schema.optional<Schema.String>;
110
- readonly error_description: Schema.optional<Schema.String>;
106
+ declare const AuthBadRequest_base: Schema.Class<AuthBadRequest, Schema.TaggedStruct<"AuthBadRequest", {
107
+ code: Schema.optional<Schema.String>;
108
+ message: Schema.optional<Schema.String>;
109
+ error: Schema.optional<Schema.String>;
110
+ error_description: Schema.optional<Schema.String>;
111
+ _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthBadRequest">, never>;
111
112
  }>, import("effect/Cause").YieldableError>;
112
113
  export declare class AuthBadRequest extends AuthBadRequest_base {
113
114
  }
114
- declare const AuthUnauthorized_base: Schema.Class<AuthUnauthorized, Schema.Struct<{
115
- readonly code: Schema.optional<Schema.String>;
116
- readonly message: Schema.optional<Schema.String>;
117
- readonly error: Schema.optional<Schema.String>;
118
- readonly error_description: Schema.optional<Schema.String>;
115
+ declare const AuthUnauthorized_base: Schema.Class<AuthUnauthorized, Schema.TaggedStruct<"AuthUnauthorized", {
116
+ code: Schema.optional<Schema.String>;
117
+ message: Schema.optional<Schema.String>;
118
+ error: Schema.optional<Schema.String>;
119
+ error_description: Schema.optional<Schema.String>;
120
+ _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthUnauthorized">, never>;
119
121
  }>, import("effect/Cause").YieldableError>;
120
122
  export declare class AuthUnauthorized extends AuthUnauthorized_base {
121
123
  }
122
- declare const AuthForbidden_base: Schema.Class<AuthForbidden, Schema.Struct<{
123
- readonly code: Schema.optional<Schema.String>;
124
- readonly message: Schema.optional<Schema.String>;
125
- readonly error: Schema.optional<Schema.String>;
126
- readonly error_description: Schema.optional<Schema.String>;
124
+ declare const AuthForbidden_base: Schema.Class<AuthForbidden, Schema.TaggedStruct<"AuthForbidden", {
125
+ code: Schema.optional<Schema.String>;
126
+ message: Schema.optional<Schema.String>;
127
+ error: Schema.optional<Schema.String>;
128
+ error_description: Schema.optional<Schema.String>;
129
+ _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthForbidden">, never>;
127
130
  }>, import("effect/Cause").YieldableError>;
128
131
  export declare class AuthForbidden extends AuthForbidden_base {
129
132
  }
130
- declare const AuthNotFound_base: Schema.Class<AuthNotFound, Schema.Struct<{
131
- readonly code: Schema.optional<Schema.String>;
132
- readonly message: Schema.optional<Schema.String>;
133
- readonly error: Schema.optional<Schema.String>;
134
- readonly error_description: Schema.optional<Schema.String>;
133
+ declare const AuthNotFound_base: Schema.Class<AuthNotFound, Schema.TaggedStruct<"AuthNotFound", {
134
+ code: Schema.optional<Schema.String>;
135
+ message: Schema.optional<Schema.String>;
136
+ error: Schema.optional<Schema.String>;
137
+ error_description: Schema.optional<Schema.String>;
138
+ _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthNotFound">, never>;
135
139
  }>, import("effect/Cause").YieldableError>;
136
140
  export declare class AuthNotFound extends AuthNotFound_base {
137
141
  }
138
- declare const AuthConflict_base: Schema.Class<AuthConflict, Schema.Struct<{
139
- readonly code: Schema.optional<Schema.String>;
140
- readonly message: Schema.optional<Schema.String>;
141
- readonly error: Schema.optional<Schema.String>;
142
- readonly error_description: Schema.optional<Schema.String>;
142
+ declare const AuthConflict_base: Schema.Class<AuthConflict, Schema.TaggedStruct<"AuthConflict", {
143
+ code: Schema.optional<Schema.String>;
144
+ message: Schema.optional<Schema.String>;
145
+ error: Schema.optional<Schema.String>;
146
+ error_description: Schema.optional<Schema.String>;
147
+ _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthConflict">, never>;
143
148
  }>, import("effect/Cause").YieldableError>;
144
149
  export declare class AuthConflict extends AuthConflict_base {
145
150
  }
146
- declare const AuthExpectationFailed_base: Schema.Class<AuthExpectationFailed, Schema.Struct<{
147
- readonly code: Schema.optional<Schema.String>;
148
- readonly message: Schema.optional<Schema.String>;
149
- readonly error: Schema.optional<Schema.String>;
150
- readonly error_description: Schema.optional<Schema.String>;
151
+ declare const AuthExpectationFailed_base: Schema.Class<AuthExpectationFailed, Schema.TaggedStruct<"AuthExpectationFailed", {
152
+ code: Schema.optional<Schema.String>;
153
+ message: Schema.optional<Schema.String>;
154
+ error: Schema.optional<Schema.String>;
155
+ error_description: Schema.optional<Schema.String>;
156
+ _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthExpectationFailed">, never>;
151
157
  }>, import("effect/Cause").YieldableError>;
152
158
  export declare class AuthExpectationFailed extends AuthExpectationFailed_base {
153
159
  }
154
- declare const AuthTooManyRequests_base: Schema.Class<AuthTooManyRequests, Schema.Struct<{
155
- readonly code: Schema.optional<Schema.String>;
156
- readonly message: Schema.optional<Schema.String>;
157
- readonly error: Schema.optional<Schema.String>;
158
- readonly error_description: Schema.optional<Schema.String>;
160
+ declare const AuthTooManyRequests_base: Schema.Class<AuthTooManyRequests, Schema.TaggedStruct<"AuthTooManyRequests", {
161
+ code: Schema.optional<Schema.String>;
162
+ message: Schema.optional<Schema.String>;
163
+ error: Schema.optional<Schema.String>;
164
+ error_description: Schema.optional<Schema.String>;
165
+ _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthTooManyRequests">, never>;
159
166
  }>, import("effect/Cause").YieldableError>;
160
167
  export declare class AuthTooManyRequests extends AuthTooManyRequests_base {
161
168
  }
162
- declare const AuthInternalServerError_base: Schema.Class<AuthInternalServerError, Schema.Struct<{
163
- readonly code: Schema.optional<Schema.String>;
164
- readonly message: Schema.optional<Schema.String>;
165
- readonly error: Schema.optional<Schema.String>;
166
- readonly error_description: Schema.optional<Schema.String>;
169
+ declare const AuthInternalServerError_base: Schema.Class<AuthInternalServerError, Schema.TaggedStruct<"AuthInternalServerError", {
170
+ code: Schema.optional<Schema.String>;
171
+ message: Schema.optional<Schema.String>;
172
+ error: Schema.optional<Schema.String>;
173
+ error_description: Schema.optional<Schema.String>;
174
+ _tag: Schema.withDecodingDefaultKey<Schema.tag<"AuthInternalServerError">, never>;
167
175
  }>, import("effect/Cause").YieldableError>;
168
176
  export declare class AuthInternalServerError extends AuthInternalServerError_base {
169
177
  }
@@ -72,50 +72,53 @@ export const AuthErrorBody = Schema.Struct({
72
72
  title: "Auth error",
73
73
  description: "Wire error returned by an authentication endpoint.",
74
74
  });
75
- const authErrorFields = AuthErrorBody.fields;
76
- export class AuthBadRequest extends Schema.ErrorClass("AuthBadRequest")(authErrorFields, {
75
+ const authErrorFields = (tag) => ({
76
+ _tag: Schema.tagDefaultOmit(tag),
77
+ ...AuthErrorBody.fields,
78
+ });
79
+ export class AuthBadRequest extends Schema.TaggedError()("AuthBadRequest", authErrorFields("AuthBadRequest"), {
77
80
  identifier: "AuthBadRequest",
78
81
  title: "Bad request",
79
82
  httpApiStatus: 400,
80
83
  }) {
81
84
  }
82
- export class AuthUnauthorized extends Schema.ErrorClass("AuthUnauthorized")(authErrorFields, {
85
+ export class AuthUnauthorized extends Schema.TaggedError()("AuthUnauthorized", authErrorFields("AuthUnauthorized"), {
83
86
  identifier: "AuthUnauthorized",
84
87
  title: "Unauthorized",
85
88
  httpApiStatus: 401,
86
89
  }) {
87
90
  }
88
- export class AuthForbidden extends Schema.ErrorClass("AuthForbidden")(authErrorFields, {
91
+ export class AuthForbidden extends Schema.TaggedError()("AuthForbidden", authErrorFields("AuthForbidden"), {
89
92
  identifier: "AuthForbidden",
90
93
  title: "Forbidden",
91
94
  httpApiStatus: 403,
92
95
  }) {
93
96
  }
94
- export class AuthNotFound extends Schema.ErrorClass("AuthNotFound")(authErrorFields, {
97
+ export class AuthNotFound extends Schema.TaggedError()("AuthNotFound", authErrorFields("AuthNotFound"), {
95
98
  identifier: "AuthNotFound",
96
99
  title: "Not found",
97
100
  httpApiStatus: 404,
98
101
  }) {
99
102
  }
100
- export class AuthConflict extends Schema.ErrorClass("AuthConflict")(authErrorFields, {
103
+ export class AuthConflict extends Schema.TaggedError()("AuthConflict", authErrorFields("AuthConflict"), {
101
104
  identifier: "AuthConflict",
102
105
  title: "Conflict",
103
106
  httpApiStatus: 409,
104
107
  }) {
105
108
  }
106
- export class AuthExpectationFailed extends Schema.ErrorClass("AuthExpectationFailed")(authErrorFields, {
109
+ export class AuthExpectationFailed extends Schema.TaggedError()("AuthExpectationFailed", authErrorFields("AuthExpectationFailed"), {
107
110
  identifier: "AuthExpectationFailed",
108
111
  title: "Expectation failed",
109
112
  httpApiStatus: 417,
110
113
  }) {
111
114
  }
112
- export class AuthTooManyRequests extends Schema.ErrorClass("AuthTooManyRequests")(authErrorFields, {
115
+ export class AuthTooManyRequests extends Schema.TaggedError()("AuthTooManyRequests", authErrorFields("AuthTooManyRequests"), {
113
116
  identifier: "AuthTooManyRequests",
114
117
  title: "Too many requests",
115
118
  httpApiStatus: 429,
116
119
  }) {
117
120
  }
118
- export class AuthInternalServerError extends Schema.ErrorClass("AuthInternalServerError")(authErrorFields, {
121
+ export class AuthInternalServerError extends Schema.TaggedError()("AuthInternalServerError", authErrorFields("AuthInternalServerError"), {
119
122
  identifier: "AuthInternalServerError",
120
123
  title: "Internal server error",
121
124
  httpApiStatus: 500,
@@ -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 { ValidateFromPath } from "@tanstack/react-router";
2
- import { type TableParams } from "@krak-stack/registry/data-table";
3
- export declare function AdminOrganizationsTable({ from, reloadKey, search, }: {
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?: TableParams;
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 = { ...query, sort: search.sort };
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({ from, reloadKey = 0, search, }) {
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
- globalFilter: "",
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, { columns: organizationColumns(m, locale, baseUrl), data: organizations, features: {
134
- columnVisibility: { default: { id: false } },
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
- }, ...(from ? { routeFrom: from } : {}), ...(!search
155
- ? {
156
- search: tableSearch,
157
- onSearchChange: setLocalSearch,
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
- : {}), onRefresh: () => setRefreshKey((current) => current + 1), state: { 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: () => {
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
- accessorKey: "id",
169
- header: m.admin_column_id,
170
- cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground font-mono text-xs", children: row.original.id })),
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
- accessorKey: "memberCount",
182
- header: m.admin_column_members,
183
- cell: ({ row }) => (_jsx(OrganizationMembers, { baseUrl: baseUrl, members: row.original.memberPreviews ?? [], total: row.original.memberCount ?? 0 })),
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
- accessorKey: "projects",
187
- header: m.admin_column_projects,
188
- cell: ({ row }) => (_jsx(DataTableListSummary, { emptyLabel: "-", items: (row.original.projects ?? []).map((project) => {
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
- accessorKey: "createdAt",
199
- header: m.admin_column_created,
200
- cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: new Date(row.original.createdAt).toLocaleDateString() })),
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(() => Atom.fn((id) => Effect.flatMap(authHttpClient(baseUrl), (http) => http.admin.deleteOrganization({ params: { id } }))));
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 ValidateFromPath } from "@tanstack/react-router";
2
- import { type TableParams } from "@krak-stack/registry/data-table";
3
- export declare function AdminUsersTable({ from, reloadKey, search, }: {
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?: TableParams;
5
+ search?: QueryType;
7
6
  }): import("react").JSX.Element;
8
- export declare function useAdminUsersTotal(search: TableParams): number;
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, } from "@tanstack/react-router";
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 = { ...query, sort: search.sort };
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({ from, reloadKey = 0, search, }) {
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
- globalFilter: "",
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(() => Atom.fn((userId) => Effect.gen(function* () {
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(() => Atom.fn(({ actorUserId, organizationId, targetUserId, }) => Effect.gen(function* () {
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, { columns: userColumns(m, baseUrl), data: users, features: {
217
- columnVisibility: { default: { id: false } },
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
- }, ...(from ? { routeFrom: from } : {}), ...(!search
270
- ? {
271
- search: tableSearch,
272
- onSearchChange: setLocalSearch,
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
- : {}), onRefresh: () => setRefreshKey((current) => current + 1), state: { 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] }));
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
- accessorKey: "id",
289
- header: m.admin_column_id,
290
- cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground font-mono text-xs", children: row.original.id })),
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
- accessorKey: "organizations",
302
- header: m.admin_column_organizations,
303
- cell: ({ row }) => (_jsx(DataTableListSummary, { emptyLabel: "-", items: row.original.organizations.map((organization) => {
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
- accessorKey: "projects",
314
- header: m.admin_column_projects,
315
- cell: ({ row }) => (_jsx(DataTableListSummary, { emptyLabel: "-", items: row.original.projects.map((project) => {
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
- accessorKey: "emailVerified",
326
- header: m.admin_column_verified,
327
- cell: ({ row }) => row.original.emailVerified ? (_jsx(Badge, { variant: "outline", children: m.admin_column_verified })) : (_jsx(Badge, { variant: "secondary", children: m.admin_column_unverified })),
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
- accessorKey: "role",
331
- header: m.admin_column_role,
332
- cell: ({ row }) => {
333
- const role = row.original.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
- accessorKey: "banned",
341
- header: m.admin_column_status,
342
- cell: ({ row }) => row.original.banned ? (_jsx(Badge, { variant: "destructive", children: m.admin_status_banned })) : (_jsx(Badge, { variant: "outline", children: m.admin_status_active })),
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
- accessorKey: "lastSignedIn",
346
- header: m.admin_column_last_signed_in,
347
- cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: row.original.lastSignedIn
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
- accessorKey: "createdAt",
353
- header: m.admin_column_created,
354
- cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: new Date(row.original.createdAt).toLocaleDateString() })),
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(() => Atom.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
+ 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(() => Atom.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
+ 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;