@kaappu/react 0.2.0
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/LICENSE +21 -0
- package/README.md +134 -0
- package/dist/index.d.mts +354 -0
- package/dist/index.d.ts +354 -0
- package/dist/index.js +2201 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2183 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React$1 from 'react';
|
|
3
|
+
export { AuthResponse, KaappuApiClient, KaappuSession, KaappuTenantConfig, KaappuUser, checkAllPermissions, checkAnyPermission, checkPermission, isPermission } from '@kaappu/core';
|
|
4
|
+
|
|
5
|
+
/** Tenant config returned by GET /api/v1/accounts/config?pk=... */
|
|
6
|
+
interface KaappuTenantConfig {
|
|
7
|
+
accountId: string;
|
|
8
|
+
authMethods: {
|
|
9
|
+
password: boolean;
|
|
10
|
+
magicLink: boolean;
|
|
11
|
+
emailOtp: boolean;
|
|
12
|
+
phoneOtp: boolean;
|
|
13
|
+
passkeys: boolean;
|
|
14
|
+
google: boolean;
|
|
15
|
+
github: boolean;
|
|
16
|
+
microsoft: boolean;
|
|
17
|
+
};
|
|
18
|
+
customProviders: Array<{
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
discoveryUrl: string;
|
|
22
|
+
}>;
|
|
23
|
+
branding: {
|
|
24
|
+
logoUrl: string;
|
|
25
|
+
primaryColor: string;
|
|
26
|
+
name: string;
|
|
27
|
+
};
|
|
28
|
+
botProtection: {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
siteKey: string;
|
|
31
|
+
};
|
|
32
|
+
policy: {
|
|
33
|
+
mfaRequired: boolean;
|
|
34
|
+
requireEmailVerification: boolean;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Authenticated user shape */
|
|
38
|
+
interface KaappuUser {
|
|
39
|
+
id: string;
|
|
40
|
+
email: string;
|
|
41
|
+
firstName?: string;
|
|
42
|
+
lastName?: string;
|
|
43
|
+
avatarUrl?: string;
|
|
44
|
+
emailVerified?: boolean;
|
|
45
|
+
mfaEnabled?: boolean;
|
|
46
|
+
accountId: string;
|
|
47
|
+
sessionId: string;
|
|
48
|
+
roles?: string[];
|
|
49
|
+
permissions?: string[];
|
|
50
|
+
}
|
|
51
|
+
/** Auth state exposed via useKaappu() */
|
|
52
|
+
interface KaappuContextValue {
|
|
53
|
+
/** Whether the provider has finished loading (config + session check) */
|
|
54
|
+
isLoaded: boolean;
|
|
55
|
+
/** Whether a user is signed in */
|
|
56
|
+
isSignedIn: boolean;
|
|
57
|
+
/** The signed-in user, or null */
|
|
58
|
+
user: KaappuUser | null;
|
|
59
|
+
/** Current access token (may be refreshed transparently) */
|
|
60
|
+
accessToken: string | null;
|
|
61
|
+
/** Tenant configuration fetched at init */
|
|
62
|
+
tenantConfig: KaappuTenantConfig | null;
|
|
63
|
+
/** Sign out — clears session + tokens */
|
|
64
|
+
signOut: () => Promise<void>;
|
|
65
|
+
/** Get the current access token (refreshes if needed) */
|
|
66
|
+
getToken: () => Promise<string | null>;
|
|
67
|
+
/** Check if user has a permission (client-side, from token claims) */
|
|
68
|
+
hasPermission: (permission: string) => boolean;
|
|
69
|
+
}
|
|
70
|
+
/** KaappuProvider props */
|
|
71
|
+
interface KaappuProviderProps {
|
|
72
|
+
/** The publishable key for your Kaappu account (pk_live_xxx) */
|
|
73
|
+
publishableKey: string;
|
|
74
|
+
/** Base URL of the Kaappu API (e.g. https://api.kaappu.com or http://localhost:9091) */
|
|
75
|
+
baseUrl?: string;
|
|
76
|
+
/** Default: '/sign-in' */
|
|
77
|
+
signInUrl?: string;
|
|
78
|
+
/** Default: '/sign-up' */
|
|
79
|
+
signUpUrl?: string;
|
|
80
|
+
children: React.ReactNode;
|
|
81
|
+
}
|
|
82
|
+
/** Appearance customization — passed to any SDK component */
|
|
83
|
+
interface KaappuAppearance {
|
|
84
|
+
/**
|
|
85
|
+
* Color scheme. 'auto' follows the OS prefers-color-scheme setting.
|
|
86
|
+
* Default: 'dark'
|
|
87
|
+
*/
|
|
88
|
+
colorScheme?: 'dark' | 'light' | 'auto';
|
|
89
|
+
/** Override CSS custom properties */
|
|
90
|
+
variables?: {
|
|
91
|
+
primaryColor?: string;
|
|
92
|
+
primaryForeground?: string;
|
|
93
|
+
backgroundColor?: string;
|
|
94
|
+
cardBackground?: string;
|
|
95
|
+
textColor?: string;
|
|
96
|
+
mutedColor?: string;
|
|
97
|
+
borderColor?: string;
|
|
98
|
+
borderRadius?: string;
|
|
99
|
+
fontFamily?: string;
|
|
100
|
+
};
|
|
101
|
+
/** Class names for individual elements (slots) */
|
|
102
|
+
elements?: {
|
|
103
|
+
card?: string;
|
|
104
|
+
title?: string;
|
|
105
|
+
subtitle?: string;
|
|
106
|
+
input?: string;
|
|
107
|
+
button?: string;
|
|
108
|
+
divider?: string;
|
|
109
|
+
oauthButton?: string;
|
|
110
|
+
footer?: string;
|
|
111
|
+
badge?: string;
|
|
112
|
+
dropdown?: string;
|
|
113
|
+
dropdownItem?: string;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** ProfileBadge props */
|
|
117
|
+
interface ProfileBadgeProps$1 {
|
|
118
|
+
afterSignOutUrl?: string;
|
|
119
|
+
userProfileUrl?: string;
|
|
120
|
+
appearance?: KaappuAppearance;
|
|
121
|
+
className?: string;
|
|
122
|
+
}
|
|
123
|
+
/** AccountView props */
|
|
124
|
+
interface AccountViewProps$1 {
|
|
125
|
+
appearance?: KaappuAppearance;
|
|
126
|
+
className?: string;
|
|
127
|
+
}
|
|
128
|
+
/** LoginPanel props */
|
|
129
|
+
interface LoginPanelProps {
|
|
130
|
+
/** Called with accessToken on successful sign-in */
|
|
131
|
+
onSuccess?: (token: string, user: KaappuUser) => void;
|
|
132
|
+
/** Redirect URL after sign-in (used by kaappuPipeline integration) */
|
|
133
|
+
redirectUrl?: string;
|
|
134
|
+
/** Override the logo displayed inside the card (URL or React node) */
|
|
135
|
+
logoUrl?: string;
|
|
136
|
+
/** Appearance overrides */
|
|
137
|
+
appearance?: KaappuAppearance;
|
|
138
|
+
/** Custom CSS class for the card wrapper */
|
|
139
|
+
className?: string;
|
|
140
|
+
/** Override OAuth redirect base URL (e.g., for WordPress proxy). If set, OAuth goes to {oauthProxyUrl}/{provider} instead of {baseUrl}/oauth/{provider} */
|
|
141
|
+
oauthProxyUrl?: string;
|
|
142
|
+
/** List of OAuth providers to show (e.g., ['google']). If set, only these are shown. */
|
|
143
|
+
allowedProviders?: string[];
|
|
144
|
+
}
|
|
145
|
+
/** RegisterPanel props */
|
|
146
|
+
interface RegisterPanelProps {
|
|
147
|
+
/** Called with accessToken on successful registration */
|
|
148
|
+
onSuccess?: (token: string, user: KaappuUser) => void;
|
|
149
|
+
/** Redirect URL after registration */
|
|
150
|
+
redirectUrl?: string;
|
|
151
|
+
/** Override the logo displayed inside the card (URL or data URI) */
|
|
152
|
+
logoUrl?: string;
|
|
153
|
+
/** Appearance overrides */
|
|
154
|
+
appearance?: KaappuAppearance;
|
|
155
|
+
className?: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
declare function KaappuProvider({ publishableKey, baseUrl, signInUrl, signUpUrl, children, }: KaappuProviderProps): react_jsx_runtime.JSX.Element;
|
|
159
|
+
|
|
160
|
+
declare function useKaappu(): KaappuContextValue;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* <LoginPanel /> — Drop-in sign-in component.
|
|
164
|
+
*
|
|
165
|
+
* Renders the full Kaappu authentication UI: OAuth providers, passkey,
|
|
166
|
+
* email/password, magic link, OTP, and phone tabs.
|
|
167
|
+
*
|
|
168
|
+
* All auth calls go through the configured middleware (Next.js API routes
|
|
169
|
+
* at /api/auth/*) — never directly to igai-connector.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* // Inside <KaappuProvider baseUrl="/api/auth">
|
|
173
|
+
* <LoginPanel onSuccess={(token, user) => router.push('/')} />
|
|
174
|
+
*
|
|
175
|
+
* // Or standalone without KaappuProvider:
|
|
176
|
+
* <LoginPanel
|
|
177
|
+
* authUrl="https://myapp.com/api/auth"
|
|
178
|
+
* accountId="kaappu_org"
|
|
179
|
+
* onSuccess={(token, user) => { ... }}
|
|
180
|
+
* />
|
|
181
|
+
*/
|
|
182
|
+
declare function LoginPanel({ onSuccess, redirectUrl, logoUrl, appearance, className, oauthProxyUrl, allowedProviders, authUrl: authUrlProp, accountId: accountIdProp, signUpPath, signUpLabel, signUpPrompt, }: LoginPanelProps & {
|
|
183
|
+
authUrl?: string;
|
|
184
|
+
accountId?: string;
|
|
185
|
+
signUpPath?: string;
|
|
186
|
+
signUpLabel?: string;
|
|
187
|
+
signUpPrompt?: string;
|
|
188
|
+
}): react_jsx_runtime.JSX.Element;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* <RegisterPanel /> — Drop-in sign-up component.
|
|
192
|
+
*
|
|
193
|
+
* Renders the full Kaappu registration UI: OAuth providers, name/email/
|
|
194
|
+
* password form with confirm-password and live password rule indicators,
|
|
195
|
+
* friendly error messages, and an optional email-verification step.
|
|
196
|
+
*
|
|
197
|
+
* Designed for visual parity with <LoginPanel /> so apps can wire both
|
|
198
|
+
* components into a single onboarding flow.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* // Inside <KaappuProvider baseUrl="/api/auth">
|
|
202
|
+
* <RegisterPanel onSuccess={(token, user) => router.push('/')} />
|
|
203
|
+
*
|
|
204
|
+
* // Standalone (no provider needed):
|
|
205
|
+
* <RegisterPanel
|
|
206
|
+
* authUrl="https://myapp.com/api/auth"
|
|
207
|
+
* accountId="acme"
|
|
208
|
+
* onSuccess={(token, user) => { ... }}
|
|
209
|
+
* />
|
|
210
|
+
*/
|
|
211
|
+
declare function RegisterPanel({ onSuccess, redirectUrl, logoUrl, appearance, className, authUrl: authUrlProp, accountId: accountIdProp, signInPath, signInLabel, signInPrompt, allowedProviders, oauthProxyUrl, }: RegisterPanelProps & {
|
|
212
|
+
authUrl?: string;
|
|
213
|
+
accountId?: string;
|
|
214
|
+
signInPath?: string;
|
|
215
|
+
signInLabel?: string;
|
|
216
|
+
signInPrompt?: string;
|
|
217
|
+
allowedProviders?: string[];
|
|
218
|
+
oauthProxyUrl?: string;
|
|
219
|
+
}): react_jsx_runtime.JSX.Element;
|
|
220
|
+
|
|
221
|
+
interface ProfileBadgeProps {
|
|
222
|
+
/** URL to redirect after sign-out (default: '/sign-in') */
|
|
223
|
+
afterSignOutUrl?: string;
|
|
224
|
+
/** URL for "Manage account" link (default: '/account') */
|
|
225
|
+
userProfileUrl?: string;
|
|
226
|
+
/** Appearance overrides */
|
|
227
|
+
appearance?: KaappuAppearance;
|
|
228
|
+
/** Custom CSS class for the trigger button */
|
|
229
|
+
className?: string;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* <ProfileBadge /> — compact avatar + dropdown menu.
|
|
233
|
+
* Shows user's initials (or avatar image) and name.
|
|
234
|
+
* Click opens a dropdown: Manage account, Sign out.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* <ProfileBadge afterSignOutUrl="/sign-in" userProfileUrl="/dashboard/profile" />
|
|
238
|
+
*/
|
|
239
|
+
declare function ProfileBadge({ afterSignOutUrl, userProfileUrl, appearance, className, }: ProfileBadgeProps): react_jsx_runtime.JSX.Element | null;
|
|
240
|
+
|
|
241
|
+
interface AccountViewProps {
|
|
242
|
+
/** Appearance overrides */
|
|
243
|
+
appearance?: KaappuAppearance;
|
|
244
|
+
/** Custom CSS class for the wrapper */
|
|
245
|
+
className?: string;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* <AccountView /> — full embeddable profile + security management component.
|
|
249
|
+
*
|
|
250
|
+
* Tabs:
|
|
251
|
+
* - Profile — display name editing
|
|
252
|
+
* - Security — TOTP MFA enrollment/status, password change
|
|
253
|
+
* - Sessions — active session list with individual revoke
|
|
254
|
+
* - Passkeys — registered passkey list with delete
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* // app/account/page.tsx
|
|
258
|
+
* import { AccountView } from '@kaappu/react'
|
|
259
|
+
* export default function AccountPage() {
|
|
260
|
+
* return <AccountView />
|
|
261
|
+
* }
|
|
262
|
+
*/
|
|
263
|
+
declare function AccountView({ appearance, className }: AccountViewProps): react_jsx_runtime.JSX.Element | null;
|
|
264
|
+
|
|
265
|
+
interface LoggedInProps {
|
|
266
|
+
children: React$1.ReactNode;
|
|
267
|
+
/** Rendered while auth state is loading */
|
|
268
|
+
fallback?: React$1.ReactNode;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Renders children only when the user is signed in.
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* <LoggedIn fallback={<Spinner />}>
|
|
275
|
+
* <UserMenu />
|
|
276
|
+
* </LoggedIn>
|
|
277
|
+
*/
|
|
278
|
+
declare function LoggedIn({ children, fallback }: LoggedInProps): react_jsx_runtime.JSX.Element | null;
|
|
279
|
+
interface LoggedOutProps {
|
|
280
|
+
children: React$1.ReactNode;
|
|
281
|
+
/** Rendered while auth state is loading */
|
|
282
|
+
fallback?: React$1.ReactNode;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Renders children only when the user is NOT signed in.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* <LoggedOut>
|
|
289
|
+
* <a href="/sign-in">Sign in</a>
|
|
290
|
+
* </LoggedOut>
|
|
291
|
+
*/
|
|
292
|
+
declare function LoggedOut({ children, fallback }: LoggedOutProps): react_jsx_runtime.JSX.Element | null;
|
|
293
|
+
interface AuthorizeProps {
|
|
294
|
+
children: React$1.ReactNode;
|
|
295
|
+
/**
|
|
296
|
+
* Required permission string (e.g. "billing:manage", "users:read").
|
|
297
|
+
* Uses client-side permission list from the user's session.
|
|
298
|
+
* The wildcard permission "*" grants access to everything.
|
|
299
|
+
*/
|
|
300
|
+
permission?: string;
|
|
301
|
+
/**
|
|
302
|
+
* Required role name (e.g. "admin", "owner").
|
|
303
|
+
* Checked against user.roles[].
|
|
304
|
+
*/
|
|
305
|
+
role?: string;
|
|
306
|
+
/** Rendered when the user lacks the required permission/role */
|
|
307
|
+
fallback?: React$1.ReactNode;
|
|
308
|
+
/** Rendered while auth state is loading */
|
|
309
|
+
loading?: React$1.ReactNode;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Conditionally renders children based on the user's permissions or role.
|
|
313
|
+
* Combines with <LoggedIn> semantics — unauthenticated users see fallback.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* // Permission-gated
|
|
317
|
+
* <Authorize permission="billing:manage" fallback={<p>Upgrade to access billing.</p>}>
|
|
318
|
+
* <BillingPanel />
|
|
319
|
+
* </Authorize>
|
|
320
|
+
*
|
|
321
|
+
* // Role-gated
|
|
322
|
+
* <Authorize role="admin">
|
|
323
|
+
* <AdminTools />
|
|
324
|
+
* </Authorize>
|
|
325
|
+
*
|
|
326
|
+
* // Combine both (user must have BOTH)
|
|
327
|
+
* <Authorize role="admin" permission="users:delete">
|
|
328
|
+
* <DangerZone />
|
|
329
|
+
* </Authorize>
|
|
330
|
+
*/
|
|
331
|
+
declare function Authorize({ children, permission, role, fallback, loading, }: AuthorizeProps): react_jsx_runtime.JSX.Element;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Resolves the active color scheme.
|
|
335
|
+
* 'auto' reads prefers-color-scheme at call time (SSR-safe — defaults to dark).
|
|
336
|
+
*/
|
|
337
|
+
declare function resolveColorScheme(scheme?: 'dark' | 'light' | 'auto'): 'dark' | 'light';
|
|
338
|
+
/**
|
|
339
|
+
* Build the CSS variables object to apply as `style` on the root element.
|
|
340
|
+
* Merges theme defaults → branding primaryColor → appearance overrides.
|
|
341
|
+
*/
|
|
342
|
+
declare function buildThemeVars(appearance?: KaappuAppearance, brandingColor?: string): React.CSSProperties;
|
|
343
|
+
/**
|
|
344
|
+
* createTheme() — convenience helper for customers who want to define a
|
|
345
|
+
* theme object once and reuse it across multiple components.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* const theme = createTheme({ colorScheme: 'light', variables: { primaryColor: '#0ea5e9' } })
|
|
349
|
+
* <LoginPanel appearance={theme} />
|
|
350
|
+
* <ProfileBadge appearance={theme} />
|
|
351
|
+
*/
|
|
352
|
+
declare function createTheme(appearance: KaappuAppearance): KaappuAppearance;
|
|
353
|
+
|
|
354
|
+
export { AccountView, type AccountViewProps$1 as AccountViewProps, Authorize, type KaappuAppearance, type KaappuContextValue, KaappuProvider, type KaappuProviderProps, LoggedIn, LoggedOut, LoginPanel, type LoginPanelProps, ProfileBadge, type ProfileBadgeProps$1 as ProfileBadgeProps, RegisterPanel, type RegisterPanelProps, buildThemeVars, createTheme, resolveColorScheme, useKaappu };
|