@krak-stack/auth 0.1.39 → 0.1.41
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/admin/api.d.ts +196 -0
- package/dist/admin/api.js +158 -0
- package/dist/admin/index.d.ts +2 -0
- package/dist/admin/index.js +2 -0
- package/dist/admin/schema.d.ts +128 -0
- package/dist/admin/schema.js +190 -0
- package/dist/api.d.ts +278 -1
- package/dist/api.js +11 -2
- package/dist/components/admin-organization-form.d.ts +6 -0
- package/dist/components/admin-organization-form.js +126 -0
- package/dist/components/admin-organizations.d.ts +7 -0
- package/dist/components/admin-organizations.js +122 -0
- package/dist/components/admin-users.d.ts +8 -0
- package/dist/components/admin-users.js +282 -0
- package/dist/components/{auth-api-client.d.ts → auth-client-api.d.ts} +186 -196
- package/dist/components/auth-client-api.js +29 -0
- package/dist/components/auth-client.d.ts +2 -1
- package/dist/components/auth-forms.js +3 -3
- package/dist/components/auth-provider.d.ts +16 -15
- package/dist/components/auth-provider.js +30 -5
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +3 -0
- package/dist/components/organization-switcher.js +4 -5
- package/dist/components/user-button.d.ts +11 -1
- package/dist/components/user-button.js +57 -6
- package/dist/components/utils.d.ts +11 -0
- package/dist/components/utils.js +24 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/query.d.ts +49 -0
- package/dist/query.js +114 -0
- package/dist/server/api.d.ts +32 -0
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +2 -1
- package/dist/server/schema.d.ts +4 -0
- package/dist/server/schema.js +8 -0
- package/dist/service.d.ts +462 -434
- package/dist/service.js +2 -2
- package/package.json +9 -1
- package/dist/components/auth-api-client.js +0 -29
|
@@ -2,14 +2,26 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { apiKeyClient } from "@better-auth/api-key/client";
|
|
3
3
|
import { useAtomSuspense } from "@effect/atom-react";
|
|
4
4
|
import { useRouterState } from "@tanstack/react-router";
|
|
5
|
-
import { emailOTPClient, genericOAuthClient, lastLoginMethodClient, organizationClient, twoFactorClient, } from "better-auth/client/plugins";
|
|
5
|
+
import { adminClient, emailOTPClient, genericOAuthClient, lastLoginMethodClient, organizationClient, twoFactorClient, } from "better-auth/client/plugins";
|
|
6
6
|
import { createAuthClient } from "better-auth/react";
|
|
7
|
-
import { createContext, useContext, useMemo } from "react";
|
|
8
|
-
import {
|
|
7
|
+
import { createContext, useContext, useEffect, useMemo, } from "react";
|
|
8
|
+
import { authClientApi } from "./auth-client-api";
|
|
9
9
|
const KrakstackAuthContext = createContext(null);
|
|
10
|
+
const PROJECT_CONTEXT_COOKIE = "krakstack-auth.project_context";
|
|
11
|
+
const setProjectContextCookie = (projectId) => {
|
|
12
|
+
if (typeof document === "undefined")
|
|
13
|
+
return;
|
|
14
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
15
|
+
if (!projectId) {
|
|
16
|
+
document.cookie = `${PROJECT_CONTEXT_COOKIE}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
document.cookie = `${PROJECT_CONTEXT_COOKIE}=${encodeURIComponent(projectId)}; Path=/; Max-Age=600; SameSite=Lax${secure}`;
|
|
20
|
+
};
|
|
10
21
|
const createAuthUiClient = (baseUrl) => createAuthClient({
|
|
11
22
|
...(baseUrl ? { baseURL: baseUrl } : {}),
|
|
12
23
|
plugins: [
|
|
24
|
+
adminClient(),
|
|
13
25
|
emailOTPClient(),
|
|
14
26
|
lastLoginMethodClient(),
|
|
15
27
|
organizationClient(),
|
|
@@ -50,7 +62,7 @@ const useProjectConfig = (baseUrl, providedProjectId) => {
|
|
|
50
62
|
const clientId = getSearchParam(searchString, "client_id");
|
|
51
63
|
const host = getBrowserAuthHost();
|
|
52
64
|
const rootHost = getRedirectHost(searchString);
|
|
53
|
-
const result = useAtomSuspense(
|
|
65
|
+
const result = useAtomSuspense(authClientApi(baseUrl).query("authExtra", "getProjectPublicConfig", {
|
|
54
66
|
query: {
|
|
55
67
|
...(projectId ? { projectId } : {}),
|
|
56
68
|
...(clientId ? { clientId } : {}),
|
|
@@ -70,9 +82,22 @@ const useProjectConfig = (baseUrl, providedProjectId) => {
|
|
|
70
82
|
return result.value;
|
|
71
83
|
};
|
|
72
84
|
export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projectId, authClient, }) {
|
|
85
|
+
const searchString = useRouterState({
|
|
86
|
+
select: (state) => state.location.searchStr,
|
|
87
|
+
});
|
|
88
|
+
const resolvedProjectId = projectId ?? getSearchParam(searchString, "projectId");
|
|
73
89
|
const resolvedAuthClient = useMemo(() => authClient ?? createAuthUiClient(baseUrl), [authClient, baseUrl]);
|
|
74
90
|
const projectConfig = useProjectConfig(baseUrl, projectId);
|
|
75
|
-
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
setProjectContextCookie(resolvedProjectId);
|
|
93
|
+
}, [resolvedProjectId]);
|
|
94
|
+
const value = useMemo(() => ({
|
|
95
|
+
authClient: resolvedAuthClient,
|
|
96
|
+
baseUrl,
|
|
97
|
+
locale,
|
|
98
|
+
projectId: resolvedProjectId,
|
|
99
|
+
projectConfig,
|
|
100
|
+
}), [resolvedAuthClient, baseUrl, locale, resolvedProjectId, projectConfig]);
|
|
76
101
|
return (_jsx(KrakstackAuthContext.Provider, { value: value, children: children }));
|
|
77
102
|
}
|
|
78
103
|
export const useKrakstackAuth = () => useContext(KrakstackAuthContext);
|
|
@@ -2,6 +2,9 @@ export { KrakstackAuthProvider, useKrakstackAuth, useKrakstackAuthProjectConfig,
|
|
|
2
2
|
export { OrganizationSwitcher } from "./organization-switcher";
|
|
3
3
|
export { ResetPassword, Signin, Signup, TwoFactor } from "./auth-forms";
|
|
4
4
|
export { UserButton } from "./user-button";
|
|
5
|
+
export { AdminOrganizationsTable } from "./admin-organizations";
|
|
6
|
+
export { AdminOrganizationForm } from "./admin-organization-form";
|
|
7
|
+
export { AdminUsersTable, useAdminUsersTotal } from "./admin-users";
|
|
5
8
|
export type { KrakstackAuthContextValue, KrakstackAuthLocale, KrakstackAuthProviderProps, } from "./auth-provider";
|
|
6
9
|
export type { OrganizationSwitcherDialog } from "./organization-switcher";
|
|
7
10
|
export type { UserButtonDialog } from "./user-button";
|
package/dist/components/index.js
CHANGED
|
@@ -2,3 +2,6 @@ export { KrakstackAuthProvider, useKrakstackAuth, useKrakstackAuthProjectConfig,
|
|
|
2
2
|
export { OrganizationSwitcher } from "./organization-switcher";
|
|
3
3
|
export { ResetPassword, Signin, Signup, TwoFactor } from "./auth-forms";
|
|
4
4
|
export { UserButton } from "./user-button";
|
|
5
|
+
export { AdminOrganizationsTable } from "./admin-organizations";
|
|
6
|
+
export { AdminOrganizationForm } from "./admin-organization-form";
|
|
7
|
+
export { AdminUsersTable, useAdminUsersTotal } from "./admin-users";
|
|
@@ -16,13 +16,12 @@ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, }
|
|
|
16
16
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
17
17
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
|
|
18
18
|
import { Separator } from "@/components/ui/separator";
|
|
19
|
-
import { cn } from "@/lib/utils";
|
|
20
19
|
import { OrganizationMetadata, } from "@krak-stack/auth/schema";
|
|
21
|
-
import {
|
|
20
|
+
import { authClientApi } from "./auth-client-api";
|
|
22
21
|
import { createApiKey } from "./api-key";
|
|
23
22
|
import { useOpenedOnce } from "./hooks";
|
|
24
23
|
import { ExtraUploadedAsset } from "../extra/schema";
|
|
25
|
-
import { assetPath, assetUrl } from "./utils";
|
|
24
|
+
import { assetPath, assetUrl, cn } from "./utils";
|
|
26
25
|
const messages = {
|
|
27
26
|
en: {
|
|
28
27
|
api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
|
|
@@ -563,7 +562,7 @@ const userInvitationRowActions = ({ m, actingInvitationId, onAccept, onReject, }
|
|
|
563
562
|
];
|
|
564
563
|
function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated, }) {
|
|
565
564
|
const m = useOrganizationMessages();
|
|
566
|
-
const uploadOrganizationLogo = useAtomSet(
|
|
565
|
+
const uploadOrganizationLogo = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadOrganizationLogo"), { mode: "promise" });
|
|
567
566
|
const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
|
|
568
567
|
const defaultValues = organizationFormDefaults(organization, baseUrl);
|
|
569
568
|
const form = useAppForm({
|
|
@@ -639,7 +638,7 @@ function CreateOrganizationSlugAutoFill({ form, }) {
|
|
|
639
638
|
}
|
|
640
639
|
function CreateOrganizationSection({ authClient, baseUrl, onCreated, }) {
|
|
641
640
|
const m = useOrganizationMessages();
|
|
642
|
-
const uploadOrganizationLogo = useAtomSet(
|
|
641
|
+
const uploadOrganizationLogo = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadOrganizationLogo"), { mode: "promise" });
|
|
643
642
|
const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
|
|
644
643
|
const defaultValues = organizationFormDefaults(undefined, baseUrl);
|
|
645
644
|
const form = useAppForm({
|
|
@@ -52,10 +52,15 @@ declare const messages: {
|
|
|
52
52
|
readonly user_api_keys_load_error: "Could not load API keys.";
|
|
53
53
|
readonly user_api_keys_title: "API keys";
|
|
54
54
|
readonly user_button_account: "Account";
|
|
55
|
+
readonly user_button_admin_organizations: "Organizations";
|
|
56
|
+
readonly user_button_admin_organizations_description: "Review and manage organizations.";
|
|
57
|
+
readonly user_button_admin_users: "Users";
|
|
58
|
+
readonly user_button_admin_users_description: "Review and manage users.";
|
|
55
59
|
readonly user_button_api_keys: "API keys";
|
|
56
60
|
readonly user_button_aria_label: "Open user menu";
|
|
57
61
|
readonly user_button_logout: "Log out";
|
|
58
62
|
readonly user_button_security: "Security";
|
|
63
|
+
readonly user_button_stop_impersonating: "Stop impersonating";
|
|
59
64
|
readonly user_delete: "Delete";
|
|
60
65
|
readonly user_field_password: "Password";
|
|
61
66
|
readonly user_form_description: "Update the profile details associated with your account.";
|
|
@@ -134,10 +139,15 @@ declare const messages: {
|
|
|
134
139
|
readonly user_api_keys_load_error: "Impossible de charger les clés API.";
|
|
135
140
|
readonly user_api_keys_title: "Clés API";
|
|
136
141
|
readonly user_button_account: "Compte";
|
|
142
|
+
readonly user_button_admin_organizations: "Organisations";
|
|
143
|
+
readonly user_button_admin_organizations_description: "Consultez et gérez les organisations.";
|
|
144
|
+
readonly user_button_admin_users: "Utilisateurs";
|
|
145
|
+
readonly user_button_admin_users_description: "Consultez et gérez les utilisateurs.";
|
|
137
146
|
readonly user_button_api_keys: "Clés API";
|
|
138
147
|
readonly user_button_aria_label: "Ouvrir le menu utilisateur";
|
|
139
148
|
readonly user_button_logout: "Se déconnecter";
|
|
140
149
|
readonly user_button_security: "Sécurité";
|
|
150
|
+
readonly user_button_stop_impersonating: "Arrêter l'imitation";
|
|
141
151
|
readonly user_delete: "Supprimer";
|
|
142
152
|
readonly user_field_password: "Mot de passe";
|
|
143
153
|
readonly user_form_description: "Mettez à jour les informations de profil associées à votre compte.";
|
|
@@ -182,6 +192,6 @@ type UserDropdownProps = {
|
|
|
182
192
|
dialog?: UserButtonDialog | null;
|
|
183
193
|
onDialogChange?: (dialog: UserButtonDialog | null) => void;
|
|
184
194
|
};
|
|
185
|
-
export type UserButtonDialog = "account" | "security" | "apiKeys";
|
|
195
|
+
export type UserButtonDialog = "account" | "security" | "apiKeys" | "adminUsers" | "adminOrganizations";
|
|
186
196
|
export declare const UserButton: ({ authClient, baseUrl, signOutRedirect, side, defaultDialog, hideTrigger, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }: UserDropdownProps) => import("react").JSX.Element;
|
|
187
197
|
export {};
|
|
@@ -4,7 +4,7 @@ import {} from "@tanstack/react-table";
|
|
|
4
4
|
import { useNavigate, useRouterState, } from "@tanstack/react-router";
|
|
5
5
|
import { Effect, Schema } from "effect";
|
|
6
6
|
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
7
|
-
import { Check, Copy, KeyRound, LogOutIcon, ShieldCheck, Trash2, UserCircleIcon, UserIcon, } from "lucide-react";
|
|
7
|
+
import { Check, Copy, Building2, KeyRound, LogOutIcon, ShieldCheck, StopCircle, Trash2, UserCircleIcon, Users, UserIcon, } from "lucide-react";
|
|
8
8
|
import { QRCode } from "react-qr-code";
|
|
9
9
|
import { createContext, useContext, useState, } from "react";
|
|
10
10
|
import { DataTable } from "@/components/ui/data-table";
|
|
@@ -17,12 +17,19 @@ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, }
|
|
|
17
17
|
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLegend, FieldSet, } from "@/components/ui/field";
|
|
18
18
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
19
19
|
import { Separator } from "@/components/ui/separator";
|
|
20
|
-
import {
|
|
20
|
+
import { authClientApi } from "./auth-client-api";
|
|
21
21
|
import { useKrakstackAuthProjectConfig } from "./auth-provider";
|
|
22
22
|
import { createApiKey } from "./api-key";
|
|
23
23
|
import { useOpenedOnce } from "./hooks";
|
|
24
24
|
import { ExtraUploadedAsset } from "../extra/schema";
|
|
25
25
|
import { assetPath, assetUrl } from "./utils";
|
|
26
|
+
import { AdminOrganizationsTable } from "./admin-organizations";
|
|
27
|
+
import { AdminUsersTable } from "./admin-users";
|
|
28
|
+
const defaultAdminTableSearch = {
|
|
29
|
+
page: 0,
|
|
30
|
+
pageSize: 10,
|
|
31
|
+
globalFilter: "",
|
|
32
|
+
};
|
|
26
33
|
const messages = {
|
|
27
34
|
en: {
|
|
28
35
|
api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
|
|
@@ -74,10 +81,15 @@ const messages = {
|
|
|
74
81
|
user_api_keys_load_error: "Could not load API keys.",
|
|
75
82
|
user_api_keys_title: "API keys",
|
|
76
83
|
user_button_account: "Account",
|
|
84
|
+
user_button_admin_organizations: "Organizations",
|
|
85
|
+
user_button_admin_organizations_description: "Review and manage organizations.",
|
|
86
|
+
user_button_admin_users: "Users",
|
|
87
|
+
user_button_admin_users_description: "Review and manage users.",
|
|
77
88
|
user_button_api_keys: "API keys",
|
|
78
89
|
user_button_aria_label: "Open user menu",
|
|
79
90
|
user_button_logout: "Log out",
|
|
80
91
|
user_button_security: "Security",
|
|
92
|
+
user_button_stop_impersonating: "Stop impersonating",
|
|
81
93
|
user_delete: "Delete",
|
|
82
94
|
user_field_password: "Password",
|
|
83
95
|
user_form_description: "Update the profile details associated with your account.",
|
|
@@ -156,10 +168,15 @@ const messages = {
|
|
|
156
168
|
user_api_keys_load_error: "Impossible de charger les clés API.",
|
|
157
169
|
user_api_keys_title: "Clés API",
|
|
158
170
|
user_button_account: "Compte",
|
|
171
|
+
user_button_admin_organizations: "Organisations",
|
|
172
|
+
user_button_admin_organizations_description: "Consultez et gérez les organisations.",
|
|
173
|
+
user_button_admin_users: "Utilisateurs",
|
|
174
|
+
user_button_admin_users_description: "Consultez et gérez les utilisateurs.",
|
|
159
175
|
user_button_api_keys: "Clés API",
|
|
160
176
|
user_button_aria_label: "Ouvrir le menu utilisateur",
|
|
161
177
|
user_button_logout: "Se déconnecter",
|
|
162
178
|
user_button_security: "Sécurité",
|
|
179
|
+
user_button_stop_impersonating: "Arrêter l'imitation",
|
|
163
180
|
user_delete: "Supprimer",
|
|
164
181
|
user_field_password: "Mot de passe",
|
|
165
182
|
user_form_description: "Mettez à jour les informations de profil associées à votre compte.",
|
|
@@ -208,6 +225,12 @@ const userButtonMessageFns = (labels) => new Proxy({}, {
|
|
|
208
225
|
});
|
|
209
226
|
const UserButtonMessagesContext = createContext(userButtonMessageFns(userButtonMessages()));
|
|
210
227
|
const useUserButtonMessages = () => useContext(UserButtonMessagesContext);
|
|
228
|
+
const hasRole = (role, roles) => typeof role === "string" &&
|
|
229
|
+
role.split(",").some((item) => roles.includes(item.trim().toLowerCase()));
|
|
230
|
+
const hasAdminRole = (user) => typeof user === "object" &&
|
|
231
|
+
user !== null &&
|
|
232
|
+
"role" in user &&
|
|
233
|
+
hasRole(user.role, ["admin"]);
|
|
211
234
|
const isFile = (value) => value instanceof File;
|
|
212
235
|
const decodeUploadedAsset = Schema.decodeUnknownPromise(ExtraUploadedAsset);
|
|
213
236
|
const uploadUserImageAsset = async (file, m, uploadUserImage) => {
|
|
@@ -253,8 +276,15 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
|
|
|
253
276
|
const currentSiteHref = useRouterState({
|
|
254
277
|
select: (state) => `${import.meta.env.VITE_SITE_URL}${state.location.href}`,
|
|
255
278
|
});
|
|
279
|
+
const adminTableSearch = useRouterState({
|
|
280
|
+
select: (state) => ({
|
|
281
|
+
...defaultAdminTableSearch,
|
|
282
|
+
...state.location.search,
|
|
283
|
+
}),
|
|
284
|
+
});
|
|
256
285
|
const { data: session, isPending, refetch } = authClient.useSession();
|
|
257
286
|
const [uncontrolledDialog, setUncontrolledDialog] = useState(defaultDialog);
|
|
287
|
+
const [isStoppingImpersonation, setIsStoppingImpersonation] = useState(false);
|
|
258
288
|
const settingsDialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
|
|
259
289
|
const [formError, setFormError] = useState(null);
|
|
260
290
|
const shouldLoadAccounts = Boolean(session) &&
|
|
@@ -264,7 +294,7 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
|
|
|
264
294
|
: emptyAccountsAtom;
|
|
265
295
|
const accountsResult = useAtomValue(accountsAtom);
|
|
266
296
|
const refreshAccounts = useAtomRefresh(accountsAtom);
|
|
267
|
-
const uploadUserImage = useAtomSet(
|
|
297
|
+
const uploadUserImage = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
|
|
268
298
|
const accountCache = {
|
|
269
299
|
accounts: AsyncResult.match(accountsResult, {
|
|
270
300
|
onInitial: () => null,
|
|
@@ -292,6 +322,8 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
|
|
|
292
322
|
const displayName = session.user.name.trim();
|
|
293
323
|
const displayEmail = session.user.email.trim();
|
|
294
324
|
const displayImage = assetUrl(session.user.image, baseUrl);
|
|
325
|
+
const isImpersonating = Boolean(session.session.impersonatedBy);
|
|
326
|
+
const isAdmin = hasAdminRole(session.user);
|
|
295
327
|
const signOut = async () => {
|
|
296
328
|
const redirectUrl = signOutRedirect.startsWith("http")
|
|
297
329
|
? signOutRedirect
|
|
@@ -299,6 +331,17 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
|
|
|
299
331
|
await authClient.signOut();
|
|
300
332
|
await navigate({ href: redirectUrl });
|
|
301
333
|
};
|
|
334
|
+
const stopImpersonating = async () => {
|
|
335
|
+
setIsStoppingImpersonation(true);
|
|
336
|
+
try {
|
|
337
|
+
await authClient.admin.stopImpersonating();
|
|
338
|
+
await refetch();
|
|
339
|
+
await navigate({ href: currentSiteHref });
|
|
340
|
+
}
|
|
341
|
+
finally {
|
|
342
|
+
setIsStoppingImpersonation(false);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
302
345
|
const updateUser = async (values) => {
|
|
303
346
|
setFormError(null);
|
|
304
347
|
const imageFile = isFile(values.image) ? values.image : null;
|
|
@@ -320,7 +363,7 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
|
|
|
320
363
|
await refetch();
|
|
321
364
|
setSettingsDialog(null);
|
|
322
365
|
};
|
|
323
|
-
return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", children: [displayImage ? (_jsx("img", { src: displayImage, alt: displayName || displayEmail, className: "size-full rounded-md object-cover" })) : (_jsx(UserIcon, { className: "size-4.5" })), _jsx("span", { className: "sr-only", children: m.user_button_aria_label() })] }) }), _jsx(DropdownMenuContent, { className: "w-56 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: displayName || displayEmail, subtitle: displayName ? displayEmail : m.user_button_account(), icon: UserIcon, className: "px-1 py-1.5 text-left text-sm", ...(displayImage ? { imageSrc: displayImage } : {}) }) }), _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { disabled: isPending, onClick: () => setSettingsDialog("account"), children: [_jsx(UserCircleIcon, {}), m.user_button_account()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("security"), children: [_jsx(ShieldCheck, {}), m.user_button_security()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] }), _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onClick: signOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] })] }) })] })), _jsx(Dialog, { open: settingsDialog === "account", onOpenChange: (open) => {
|
|
366
|
+
return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", children: [displayImage ? (_jsx("img", { src: displayImage, alt: displayName || displayEmail, className: "size-full rounded-md object-cover" })) : (_jsx(UserIcon, { className: "size-4.5" })), _jsx("span", { className: "sr-only", children: m.user_button_aria_label() })] }) }), _jsx(DropdownMenuContent, { className: "w-56 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: displayName || displayEmail, subtitle: displayName ? displayEmail : m.user_button_account(), icon: UserIcon, className: "px-1 py-1.5 text-left text-sm", ...(displayImage ? { imageSrc: displayImage } : {}) }) }), _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { disabled: isPending, onClick: () => setSettingsDialog("account"), children: [_jsx(UserCircleIcon, {}), m.user_button_account()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("security"), children: [_jsx(ShieldCheck, {}), m.user_button_security()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] }), _jsx(DropdownMenuSeparator, {}), isAdmin || isImpersonating ? (_jsxs(_Fragment, { children: [isAdmin ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminUsers"), children: [_jsx(Users, {}), m.user_button_admin_users()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminOrganizations"), children: [_jsx(Building2, {}), m.user_button_admin_organizations()] })] })) : null, isImpersonating ? (_jsxs(DropdownMenuItem, { disabled: isStoppingImpersonation, onClick: stopImpersonating, children: [_jsx(StopCircle, {}), m.user_button_stop_impersonating()] })) : null, _jsx(DropdownMenuSeparator, {})] })) : null, _jsxs(DropdownMenuItem, { onClick: signOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] })] }) })] })), _jsx(Dialog, { open: settingsDialog === "account", onOpenChange: (open) => {
|
|
324
367
|
setSettingsDialog((current) => open ? "account" : current === "account" ? null : current);
|
|
325
368
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_form_title() }), _jsx(DialogDescription, { children: m.user_form_description() })] }), _jsx(Separator, {}), isPending ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : (_jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(UserForm, { defaultValues: {
|
|
326
369
|
name: displayName ?? "",
|
|
@@ -338,7 +381,15 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
|
|
|
338
381
|
setSettingsDialog((current) => open ? "security" : current === "security" ? null : current);
|
|
339
382
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_security_title() }), _jsx(DialogDescription, { children: m.user_security_description() })] }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(PasswordSettings, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache }), _jsx(Separator, {}), _jsx(AccountSecuritySettings, { authClient: authClient, accountCache: accountCache })] })] }) }), _jsx(Dialog, { open: settingsDialog === "apiKeys", onOpenChange: (open) => {
|
|
340
383
|
setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
341
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_api_keys_title() }), _jsx(DialogDescription, { children: m.user_api_keys_description() })] }), _jsx(Separator, {}), _jsx(ApiKeyManager, { authClient: authClient, active: settingsDialog === "apiKeys", permissions: apiKeyPermissions ?? {} })] }) })
|
|
384
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_api_keys_title() }), _jsx(DialogDescription, { children: m.user_api_keys_description() })] }), _jsx(Separator, {}), _jsx(ApiKeyManager, { authClient: authClient, active: settingsDialog === "apiKeys", permissions: apiKeyPermissions ?? {} })] }) }), isAdmin ? (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: settingsDialog === "adminUsers", onOpenChange: (open) => {
|
|
385
|
+
setSettingsDialog((current) => open ? "adminUsers" : current === "adminUsers" ? null : current);
|
|
386
|
+
}, children: _jsxs(DialogContent, { className: "flex h-[85vh] flex-col overflow-y-auto sm:max-w-6xl", 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(Separator, {}), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(AdminUsersTable, { search: adminTableSearch }) })] }) }), _jsx(Dialog, { open: settingsDialog === "adminOrganizations", onOpenChange: (open) => {
|
|
387
|
+
setSettingsDialog((current) => open
|
|
388
|
+
? "adminOrganizations"
|
|
389
|
+
: current === "adminOrganizations"
|
|
390
|
+
? null
|
|
391
|
+
: current);
|
|
392
|
+
}, children: _jsxs(DialogContent, { className: "flex h-[85vh] flex-col overflow-y-auto sm:max-w-6xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_button_admin_organizations() }), _jsx(DialogDescription, { children: m.user_button_admin_organizations_description() })] }), _jsx(Separator, {}), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(AdminOrganizationsTable, { search: adminTableSearch }) })] }) })] })) : null] }));
|
|
342
393
|
};
|
|
343
394
|
function ConnectedAccounts({ authClient, baseUrl, accountCache, googleEnabled, currentSiteHref, navigate, }) {
|
|
344
395
|
const m = useUserButtonMessages();
|
|
@@ -481,7 +532,7 @@ function SetPasswordForm({ authClient, onSaved, }) {
|
|
|
481
532
|
}
|
|
482
533
|
function RevokeAccountForm({ baseUrl, account, requirePassword, onCancel, onRevoke, }) {
|
|
483
534
|
const m = useUserButtonMessages();
|
|
484
|
-
const verifyPassword = useAtomSet(
|
|
535
|
+
const verifyPassword = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "verifyPassword"), { mode: "promise" });
|
|
485
536
|
const form = useAppForm({
|
|
486
537
|
defaultValues: { password: "" },
|
|
487
538
|
onSubmit: async ({ value, formApi }) => {
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
|
2
|
+
export declare const cn: (...inputs: ReadonlyArray<string | false | null | undefined>) => string;
|
|
3
|
+
export type OrganizationBrandingLocale = "en" | "fr";
|
|
4
|
+
export interface OrganizationBrandingSource {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly logo?: string | null | undefined;
|
|
7
|
+
readonly metadata?: unknown;
|
|
8
|
+
}
|
|
9
|
+
export declare const organizationBranding: (organization: OrganizationBrandingSource | null | undefined, locale?: OrganizationBrandingLocale) => {
|
|
10
|
+
name: string;
|
|
11
|
+
logo: string | null | undefined;
|
|
12
|
+
} | null;
|
|
2
13
|
export declare const assetPath: (value: string | null | undefined) => string | null;
|
|
3
14
|
export declare const assetUrl: (value: string | null | undefined, baseUrl?: string) => string;
|
package/dist/components/utils.js
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { OrganizationMetadata } from "../schema";
|
|
1
3
|
export const isRecord = (value) => typeof value === "object" && value !== null;
|
|
4
|
+
export const cn = (...inputs) => inputs.filter(Boolean).join(" ");
|
|
5
|
+
const parseOrganizationMetadata = (metadata) => {
|
|
6
|
+
try {
|
|
7
|
+
const value = typeof metadata === "string" ? JSON.parse(metadata) : metadata;
|
|
8
|
+
return Schema.decodeUnknownSync(OrganizationMetadata)(value);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return { translations: [] };
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export const organizationBranding = (organization, locale = "en") => {
|
|
15
|
+
if (!organization)
|
|
16
|
+
return null;
|
|
17
|
+
const translations = parseOrganizationMetadata(organization.metadata).translations;
|
|
18
|
+
const translation = translations.find((item) => item.locale === locale) ??
|
|
19
|
+
translations.find((item) => item.locale === "en") ??
|
|
20
|
+
translations[0];
|
|
21
|
+
return {
|
|
22
|
+
name: translation?.name || organization.name,
|
|
23
|
+
logo: translation?.icon || translation?.logo || organization.logo,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
2
26
|
const assetRoutePrefix = "/api/auth/assets/";
|
|
3
27
|
const legacyAssetRoutePrefix = "/api/assets/";
|
|
4
28
|
const assetKey = (value) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export * from "./schema";
|
|
2
|
-
export
|
|
2
|
+
export * as Query from "./query";
|
|
3
|
+
export { AuthClientApi, AuthServiceApi } from "./api";
|
|
3
4
|
export { AuthService, type AuthServiceLayerOptions } from "./service";
|
|
4
5
|
export { AuthClientConfig } from "./config";
|
|
5
6
|
export { proxyAuthRequest } from "./server/proxy";
|
|
6
|
-
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, UserButton, type AuthUiClient, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type UserButtonDialog, } from "./components";
|
|
7
|
+
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, type AuthUiClient, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type UserButtonDialog, useAdminUsersTotal, } from "./components";
|
|
7
8
|
export * as BetterAuth from "./better-auth";
|
|
8
9
|
export * as Extra from "./extra";
|
|
9
10
|
export * as Server from "./server";
|
|
11
|
+
export * as Admin from "./admin";
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export * from "./schema";
|
|
2
|
-
export
|
|
2
|
+
export * as Query from "./query";
|
|
3
|
+
export { AuthClientApi, AuthServiceApi } from "./api";
|
|
3
4
|
export { AuthService } from "./service";
|
|
4
5
|
export { AuthClientConfig } from "./config";
|
|
5
6
|
export { proxyAuthRequest } from "./server/proxy";
|
|
6
|
-
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, UserButton, } from "./components";
|
|
7
|
+
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, useAdminUsersTotal, } from "./components";
|
|
7
8
|
export * as BetterAuth from "./better-auth";
|
|
8
9
|
export * as Extra from "./extra";
|
|
9
10
|
export * as Server from "./server";
|
|
11
|
+
export * as Admin from "./admin";
|
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export type SortDirection = "asc" | "desc";
|
|
3
|
+
export interface SortState {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly desc: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface SortParam {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly direction: SortDirection;
|
|
10
|
+
}
|
|
11
|
+
export declare const SortDirection: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
|
|
12
|
+
export declare const SortParam: Schema.Struct<{
|
|
13
|
+
readonly id: Schema.NonEmptyString;
|
|
14
|
+
readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const SortParamFromString: Schema.decodeTo<Schema.Struct<{
|
|
17
|
+
readonly id: Schema.NonEmptyString;
|
|
18
|
+
readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
|
|
19
|
+
}>, Schema.String, never, never>;
|
|
20
|
+
export declare const SortParamsFromString: Schema.decodeTo<Schema.$Array<Schema.Struct<{
|
|
21
|
+
readonly id: Schema.NonEmptyString;
|
|
22
|
+
readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
|
|
23
|
+
}>>, Schema.String, never, never>;
|
|
24
|
+
export declare const Query: Schema.Struct<{
|
|
25
|
+
readonly page: Schema.Int;
|
|
26
|
+
readonly pageSize: Schema.Int;
|
|
27
|
+
readonly globalFilter: Schema.optional<Schema.String>;
|
|
28
|
+
readonly sort: Schema.optional<Schema.decodeTo<Schema.String, Schema.decodeTo<Schema.$Array<Schema.Struct<{
|
|
29
|
+
readonly id: Schema.NonEmptyString;
|
|
30
|
+
readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
|
|
31
|
+
}>>, Schema.String, never, never>, never, never>>;
|
|
32
|
+
}>;
|
|
33
|
+
export type QueryType = typeof Query.Type;
|
|
34
|
+
export declare const PaginationMeta: Schema.Struct<{
|
|
35
|
+
readonly page: Schema.Int;
|
|
36
|
+
readonly pageSize: Schema.Int;
|
|
37
|
+
readonly total: Schema.Int;
|
|
38
|
+
readonly pageCount: Schema.Int;
|
|
39
|
+
}>;
|
|
40
|
+
export type PaginationMetaType = typeof PaginationMeta.Type;
|
|
41
|
+
export declare const PaginatedResponse: <A>(items: Schema.Schema<A>) => Schema.Struct<{
|
|
42
|
+
readonly data: Schema.$Array<Schema.Schema<A>>;
|
|
43
|
+
readonly meta: Schema.Struct<{
|
|
44
|
+
readonly page: Schema.Int;
|
|
45
|
+
readonly pageSize: Schema.Int;
|
|
46
|
+
readonly total: Schema.Int;
|
|
47
|
+
readonly pageCount: Schema.Int;
|
|
48
|
+
}>;
|
|
49
|
+
}>;
|
package/dist/query.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Effect, Option, Schema, SchemaIssue, SchemaTransformation, } from "effect";
|
|
2
|
+
const parseSortParam = (sort) => {
|
|
3
|
+
const id = sort.startsWith("-") ? sort.slice(1) : sort;
|
|
4
|
+
if (!id || id.includes(",") || id.includes(":")) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
return { id, direction: sort.startsWith("-") ? "desc" : "asc" };
|
|
8
|
+
};
|
|
9
|
+
export const SortDirection = Schema.Union([
|
|
10
|
+
Schema.Literal("asc"),
|
|
11
|
+
Schema.Literal("desc"),
|
|
12
|
+
]).annotate({
|
|
13
|
+
identifier: "SortDirection",
|
|
14
|
+
title: "Sort Direction",
|
|
15
|
+
description: "Sort direction for list query results.",
|
|
16
|
+
examples: ["asc", "desc"],
|
|
17
|
+
});
|
|
18
|
+
export const SortParam = Schema.Struct({
|
|
19
|
+
id: Schema.NonEmptyString,
|
|
20
|
+
direction: SortDirection,
|
|
21
|
+
}).annotate({
|
|
22
|
+
identifier: "SortParam",
|
|
23
|
+
title: "Sort Parameter",
|
|
24
|
+
description: "Decoded sort parameter with a field id and direction.",
|
|
25
|
+
examples: [{ id: "name", direction: "asc" }],
|
|
26
|
+
});
|
|
27
|
+
export const SortParamFromString = Schema.String.pipe(Schema.decodeTo(SortParam, SchemaTransformation.transformOrFail({
|
|
28
|
+
decode: (sort) => {
|
|
29
|
+
const sortParam = parseSortParam(sort);
|
|
30
|
+
if (!sortParam) {
|
|
31
|
+
return Effect.fail(new SchemaIssue.InvalidValue(Option.some(sort), {
|
|
32
|
+
message: 'Expected sort in the format "field" or "-field"',
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
return Effect.succeed(sortParam);
|
|
36
|
+
},
|
|
37
|
+
encode: (sort) => Effect.succeed(sort.direction === "desc" ? `-${sort.id}` : sort.id),
|
|
38
|
+
})), Schema.annotate({
|
|
39
|
+
identifier: "SortParamFromString",
|
|
40
|
+
title: "Sort Parameter From String",
|
|
41
|
+
description: 'URL encoded single sort parameter where descending fields are prefixed with "-".',
|
|
42
|
+
examples: [{ id: "name", direction: "asc" }],
|
|
43
|
+
}));
|
|
44
|
+
export const SortParamsFromString = Schema.String.pipe(Schema.decodeTo(Schema.Array(SortParam), SchemaTransformation.transformOrFail({
|
|
45
|
+
decode: (sort) => {
|
|
46
|
+
const parts = sort.split(",");
|
|
47
|
+
const sortParams = [];
|
|
48
|
+
for (const part of parts) {
|
|
49
|
+
const sortParam = parseSortParam(part);
|
|
50
|
+
if (!sortParam) {
|
|
51
|
+
return Effect.fail(new SchemaIssue.InvalidValue(Option.some(sort), {
|
|
52
|
+
message: 'Expected sort in the format "field,-otherField"',
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
sortParams.push(sortParam);
|
|
56
|
+
}
|
|
57
|
+
return Effect.succeed(sortParams);
|
|
58
|
+
},
|
|
59
|
+
encode: (sort) => Effect.succeed(sort
|
|
60
|
+
.map((part) => Schema.encodeSync(SortParamFromString)(part))
|
|
61
|
+
.join(",")),
|
|
62
|
+
})), Schema.annotate({
|
|
63
|
+
identifier: "SortParamsFromString",
|
|
64
|
+
title: "Sort Parameters From String",
|
|
65
|
+
description: 'URL encoded sort parameters where descending fields are prefixed with "-" and multiple fields are comma-separated.',
|
|
66
|
+
examples: [
|
|
67
|
+
[
|
|
68
|
+
{ id: "name", direction: "desc" },
|
|
69
|
+
{ id: "createdAt", direction: "asc" },
|
|
70
|
+
],
|
|
71
|
+
],
|
|
72
|
+
}));
|
|
73
|
+
const SortParamSearch = SortParamsFromString.pipe(Schema.decodeTo(Schema.String, SchemaTransformation.transform({
|
|
74
|
+
decode: (sort) => Schema.encodeSync(SortParamsFromString)(sort),
|
|
75
|
+
encode: (sort) => Schema.decodeUnknownSync(SortParamsFromString)(sort),
|
|
76
|
+
})), Schema.annotate({
|
|
77
|
+
identifier: "SortParamSearch",
|
|
78
|
+
title: "Sort Search Parameter",
|
|
79
|
+
description: 'Search parameter sort value normalized to the compact "-field,otherField" URL format.',
|
|
80
|
+
examples: ["-name,createdAt"],
|
|
81
|
+
}));
|
|
82
|
+
export const Query = Schema.Struct({
|
|
83
|
+
page: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
84
|
+
pageSize: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })),
|
|
85
|
+
globalFilter: Schema.optional(Schema.String),
|
|
86
|
+
sort: Schema.optional(SortParamSearch),
|
|
87
|
+
}).annotate({
|
|
88
|
+
identifier: "Query",
|
|
89
|
+
title: "Query",
|
|
90
|
+
description: "Zero-based page request parameters with optional filtering and sorting for list endpoints.",
|
|
91
|
+
examples: [
|
|
92
|
+
{
|
|
93
|
+
page: 0,
|
|
94
|
+
pageSize: 10,
|
|
95
|
+
globalFilter: "housing",
|
|
96
|
+
sort: "-name,createdAt",
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
});
|
|
100
|
+
export const PaginationMeta = Schema.Struct({
|
|
101
|
+
page: Schema.Int,
|
|
102
|
+
pageSize: Schema.Int,
|
|
103
|
+
total: Schema.Int,
|
|
104
|
+
pageCount: Schema.Int,
|
|
105
|
+
}).annotate({
|
|
106
|
+
identifier: "PaginationMeta",
|
|
107
|
+
title: "Pagination Metadata",
|
|
108
|
+
description: "Pagination metadata returned with a paginated list response.",
|
|
109
|
+
examples: [{ page: 0, pageSize: 10, total: 125, pageCount: 13 }],
|
|
110
|
+
});
|
|
111
|
+
export const PaginatedResponse = (items) => Schema.Struct({
|
|
112
|
+
data: Schema.Array(items),
|
|
113
|
+
meta: PaginationMeta,
|
|
114
|
+
});
|