cilantro-react 0.1.6 → 0.1.7
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/README.md +147 -7
- package/dist/AuthGuard-siMJeYPD.d.mts +42 -0
- package/dist/AuthGuard-siMJeYPD.d.ts +42 -0
- package/dist/index.d.mts +134 -23
- package/dist/index.d.ts +134 -23
- package/dist/index.js +633 -272
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +610 -254
- package/dist/index.mjs.map +1 -1
- package/dist/next.d.mts +19 -0
- package/dist/next.d.ts +19 -0
- package/dist/next.js +494 -0
- package/dist/next.js.map +1 -0
- package/dist/next.mjs +465 -0
- package/dist/next.mjs.map +1 -0
- package/package.json +10 -3
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { WalletControllerFindAllResult, WalletControllerCreateResult, WalletCont
|
|
|
5
5
|
export { WalletControllerFindAllResult, WalletControllerFindOneResult, WalletControllerListSignersResult, WalletControllerSubmitTransactionResult } from 'cilantro-sdk/wallet';
|
|
6
6
|
import { createIndexedDBAdapter, SignerInfo } from 'cilantro-sdk/helpers';
|
|
7
7
|
export { createIndexedDBAdapter, createLocalStorageAdapter, createMemoryAdapter } from 'cilantro-sdk/helpers';
|
|
8
|
+
export { A as AuthGuard, a as AuthGuardClassNames, b as AuthGuardLayout, c as AuthGuardProps } from './AuthGuard-siMJeYPD.js';
|
|
8
9
|
import { PublicKey, Transaction, Connection } from '@solana/web3.js';
|
|
9
10
|
export { AuthControllerLogin200Data } from 'cilantro-sdk/auth';
|
|
10
11
|
export { TransactionControllerSendRawPasskeyTransactionResult } from 'cilantro-sdk/transactions';
|
|
@@ -62,12 +63,16 @@ interface CilantroContextProviderProps {
|
|
|
62
63
|
storageAdapter?: DeviceKeyStorage | null;
|
|
63
64
|
jwtStorageKey?: string;
|
|
64
65
|
walletStorageKey?: string;
|
|
66
|
+
/** When true, sync JWT to a cookie (same name as jwtStorageKey) for Next.js/middleware. Default: false. */
|
|
67
|
+
syncJwtToCookie?: boolean;
|
|
68
|
+
/** Cookie name for JWT when syncJwtToCookie is true. Default: cilantro_jwt. */
|
|
69
|
+
jwtCookieName?: string;
|
|
65
70
|
onLoginSuccess?: () => void;
|
|
66
71
|
onLogout?: () => void;
|
|
67
72
|
onRegisterSuccess?: () => void;
|
|
68
73
|
onSessionExpired?: () => void;
|
|
69
74
|
}
|
|
70
|
-
declare function CilantroContextProvider({ children, apiKey, baseURL, storageAdapter, jwtStorageKey, walletStorageKey, onLoginSuccess, onLogout, onRegisterSuccess, onSessionExpired, }: CilantroContextProviderProps): react_jsx_runtime.JSX.Element;
|
|
75
|
+
declare function CilantroContextProvider({ children, apiKey, baseURL, storageAdapter, jwtStorageKey, walletStorageKey, syncJwtToCookie, jwtCookieName, onLoginSuccess, onLogout, onRegisterSuccess, onSessionExpired, }: CilantroContextProviderProps): react_jsx_runtime.JSX.Element;
|
|
71
76
|
declare function useCilantroContext(): CilantroContextValue;
|
|
72
77
|
|
|
73
78
|
interface CilantroProviderProps {
|
|
@@ -86,15 +91,21 @@ interface CilantroProviderProps {
|
|
|
86
91
|
jwtStorageKey?: string;
|
|
87
92
|
/** localStorage key for selected wallet id (default: cilantro_selected_wallet_id) */
|
|
88
93
|
walletStorageKey?: string;
|
|
94
|
+
/** When true, sync JWT to a cookie for Next.js/middleware. Default: false. */
|
|
95
|
+
syncJwtToCookie?: boolean;
|
|
96
|
+
/** Cookie name for JWT when syncJwtToCookie is true. Default: cilantro_jwt. */
|
|
97
|
+
jwtCookieName?: string;
|
|
89
98
|
onLoginSuccess?: () => void;
|
|
90
99
|
onLogout?: () => void;
|
|
91
100
|
onRegisterSuccess?: () => void;
|
|
92
101
|
onSessionExpired?: () => void;
|
|
93
102
|
}
|
|
94
|
-
declare function CilantroProvider({ children, apiKey: apiKeyProp, baseURL, storageAdapter, platformApiKey, apiUrl, jwtStorageKey, walletStorageKey, onLoginSuccess, onLogout, onRegisterSuccess, onSessionExpired, }: CilantroProviderProps): react_jsx_runtime.JSX.Element;
|
|
103
|
+
declare function CilantroProvider({ children, apiKey: apiKeyProp, baseURL, storageAdapter, platformApiKey, apiUrl, jwtStorageKey, walletStorageKey, syncJwtToCookie, jwtCookieName, onLoginSuccess, onLogout, onRegisterSuccess, onSessionExpired, }: CilantroProviderProps): react_jsx_runtime.JSX.Element;
|
|
95
104
|
|
|
96
105
|
interface CilantroAuthContextType {
|
|
97
106
|
user: User | null;
|
|
107
|
+
/** JWT token. Alias for token. */
|
|
108
|
+
jwt: string | null;
|
|
98
109
|
token: string | null;
|
|
99
110
|
isAuthenticated: boolean;
|
|
100
111
|
login: (usernameOrEmail: string, password: string) => Promise<void>;
|
|
@@ -106,6 +117,9 @@ interface CilantroAuthContextType {
|
|
|
106
117
|
declare function useCilantroAuth(): CilantroAuthContextType;
|
|
107
118
|
|
|
108
119
|
interface WalletContextType {
|
|
120
|
+
/** Selected wallet. Primary name. */
|
|
121
|
+
wallet: WalletData | null;
|
|
122
|
+
/** @deprecated Use wallet instead. Alias for backward compat. */
|
|
109
123
|
selectedWallet: WalletData | null;
|
|
110
124
|
wallets: WalletData[];
|
|
111
125
|
selectWallet: (walletId: string) => void;
|
|
@@ -124,19 +138,54 @@ interface UseCilantroConfigResult {
|
|
|
124
138
|
declare function useCilantroConfig(): UseCilantroConfigResult;
|
|
125
139
|
|
|
126
140
|
interface UseAuthResult {
|
|
141
|
+
/** Current user (from JWT payload or login response). */
|
|
127
142
|
user: User | null;
|
|
143
|
+
/** JWT token. Prefer this name. */
|
|
128
144
|
jwt: string | null;
|
|
145
|
+
/** Alias for jwt. Same value. */
|
|
146
|
+
token: string | null;
|
|
129
147
|
isLoading: boolean;
|
|
130
148
|
isAuthenticated: boolean;
|
|
131
149
|
login: (params: {
|
|
132
150
|
usernameOrEmail: string;
|
|
133
151
|
password: string;
|
|
134
152
|
}) => Promise<void>;
|
|
153
|
+
/** Register a new user and auto-login. */
|
|
154
|
+
register: (username: string, email: string, password: string, isActive?: boolean) => Promise<void>;
|
|
135
155
|
logout: () => void;
|
|
156
|
+
/** Clear session when API returns 401/403. Call onSessionExpired. */
|
|
157
|
+
clearSessionDueToAuthError: () => void;
|
|
136
158
|
}
|
|
137
159
|
declare function useAuth(): UseAuthResult;
|
|
138
160
|
|
|
161
|
+
interface UseReturnUrlOptions {
|
|
162
|
+
/** Query param name for return URL. Default: "returnUrl" */
|
|
163
|
+
param?: string;
|
|
164
|
+
/** Default path when no returnUrl in URL. Default: "/" */
|
|
165
|
+
defaultPath?: string;
|
|
166
|
+
/** Only allow relative paths (no protocol). Default: true */
|
|
167
|
+
allowRelativeOnly?: boolean;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Read returnUrl from URL search params and provide a safe redirect path.
|
|
171
|
+
* Use with LoginForm/RegisterForm to redirect users back after auth.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* // In LoginForm wrapper - redirect to returnUrl after login
|
|
175
|
+
* const { returnPath, redirect } = useReturnUrl();
|
|
176
|
+
* <LoginForm onSuccess={() => redirect()} redirectAfterSuccess={returnPath} onRedirect={router.replace} />
|
|
177
|
+
*/
|
|
178
|
+
declare function useReturnUrl(options?: UseReturnUrlOptions): {
|
|
179
|
+
/** Safe path to redirect to (from URL or defaultPath) */
|
|
180
|
+
returnPath: string;
|
|
181
|
+
/** Redirect to returnPath using window.location (or pass custom fn) */
|
|
182
|
+
redirect: (customRedirect?: (path: string) => void) => void;
|
|
183
|
+
/** Raw value from URL (may be empty) */
|
|
184
|
+
rawReturnUrl: string | null;
|
|
185
|
+
};
|
|
186
|
+
|
|
139
187
|
interface UseWalletResult {
|
|
188
|
+
/** Selected wallet. Use this as primary. */
|
|
140
189
|
wallet: WalletData | null;
|
|
141
190
|
wallets: WalletData[];
|
|
142
191
|
createWallet: (params: {
|
|
@@ -144,7 +193,11 @@ interface UseWalletResult {
|
|
|
144
193
|
userId?: string;
|
|
145
194
|
}) => Promise<WalletControllerCreateResult>;
|
|
146
195
|
selectWallet: (walletId: string) => void;
|
|
196
|
+
/** Refresh wallet list from API. */
|
|
197
|
+
refreshWallets: () => Promise<void>;
|
|
147
198
|
isLoading: boolean;
|
|
199
|
+
/** Error from wallet operations (e.g. fetch failed). */
|
|
200
|
+
error: string | null;
|
|
148
201
|
}
|
|
149
202
|
declare function useWallet(_walletId?: string): UseWalletResult;
|
|
150
203
|
|
|
@@ -277,6 +330,12 @@ interface LoginFormProps {
|
|
|
277
330
|
style?: React.CSSProperties;
|
|
278
331
|
onSuccess?: () => void;
|
|
279
332
|
onError?: (error: Error) => void;
|
|
333
|
+
/** Redirect to this path after successful login. If not set, reads from URL ?returnUrl= (when returnUrlParam provided). */
|
|
334
|
+
redirectAfterSuccess?: string;
|
|
335
|
+
/** Custom redirect function for SPA routers. e.g. (path) => router.replace(path) */
|
|
336
|
+
onRedirect?: (path: string) => void;
|
|
337
|
+
/** Query param to read returnUrl from URL. Default: "returnUrl". Used when redirectAfterSuccess not set. */
|
|
338
|
+
returnUrlParam?: string;
|
|
280
339
|
rememberMe?: boolean;
|
|
281
340
|
/** Override submit button label */
|
|
282
341
|
submitLabel?: string;
|
|
@@ -287,41 +346,78 @@ interface LoginFormProps {
|
|
|
287
346
|
/** Render "Create account" link (e.g. to switch to register). Shown below submit. */
|
|
288
347
|
renderSwitchToRegister?: () => React.ReactNode;
|
|
289
348
|
}
|
|
290
|
-
declare function LoginForm({ className, classNames, style, onSuccess, onError, submitLabel, title, description, renderSwitchToRegister, }: LoginFormProps): react_jsx_runtime.JSX.Element;
|
|
349
|
+
declare function LoginForm({ className, classNames, style, onSuccess, onError, redirectAfterSuccess, onRedirect, returnUrlParam, submitLabel, title, description, renderSwitchToRegister, }: LoginFormProps): react_jsx_runtime.JSX.Element;
|
|
350
|
+
|
|
351
|
+
interface RegisterFormClassNames {
|
|
352
|
+
root?: string;
|
|
353
|
+
header?: string;
|
|
354
|
+
title?: string;
|
|
355
|
+
description?: string;
|
|
356
|
+
form?: string;
|
|
357
|
+
label?: string;
|
|
358
|
+
input?: string;
|
|
359
|
+
submitButton?: string;
|
|
360
|
+
error?: string;
|
|
361
|
+
}
|
|
362
|
+
interface RegisterFormProps {
|
|
363
|
+
className?: string;
|
|
364
|
+
classNames?: RegisterFormClassNames;
|
|
365
|
+
style?: React.CSSProperties;
|
|
366
|
+
onSuccess?: () => void;
|
|
367
|
+
onError?: (error: Error) => void;
|
|
368
|
+
/** Redirect to this path after successful registration. If not set, reads from URL ?returnUrl= */
|
|
369
|
+
redirectAfterSuccess?: string;
|
|
370
|
+
/** Custom redirect function for SPA routers */
|
|
371
|
+
onRedirect?: (path: string) => void;
|
|
372
|
+
/** Query param to read returnUrl from URL. Default: "returnUrl" */
|
|
373
|
+
returnUrlParam?: string;
|
|
374
|
+
/** Override submit button label */
|
|
375
|
+
submitLabel?: string;
|
|
376
|
+
/** Override title */
|
|
377
|
+
title?: string;
|
|
378
|
+
/** Override description */
|
|
379
|
+
description?: string;
|
|
380
|
+
/** Render "Already have an account?" link to switch to login */
|
|
381
|
+
renderSwitchToLogin?: () => React.ReactNode;
|
|
382
|
+
}
|
|
383
|
+
declare function RegisterForm({ className, classNames, style, onSuccess, onError, redirectAfterSuccess, onRedirect, returnUrlParam, submitLabel, title, description, renderSwitchToLogin, }: RegisterFormProps): react_jsx_runtime.JSX.Element;
|
|
291
384
|
|
|
292
385
|
interface LogoutButtonProps {
|
|
293
386
|
onLogout?: () => void;
|
|
387
|
+
/** Redirect to this path after logout (e.g. "/login") */
|
|
388
|
+
redirectAfterLogout?: string;
|
|
389
|
+
/** Custom redirect for SPA routers. e.g. (path) => router.replace(path) */
|
|
390
|
+
onRedirect?: (path: string) => void;
|
|
294
391
|
confirmBeforeLogout?: boolean;
|
|
295
392
|
className?: string;
|
|
296
393
|
children?: ReactNode;
|
|
297
394
|
}
|
|
298
|
-
declare function LogoutButton({ onLogout, confirmBeforeLogout, className, children, }: LogoutButtonProps): react_jsx_runtime.JSX.Element;
|
|
395
|
+
declare function LogoutButton({ onLogout, redirectAfterLogout, onRedirect, confirmBeforeLogout, className, children, }: LogoutButtonProps): react_jsx_runtime.JSX.Element;
|
|
299
396
|
|
|
300
|
-
interface
|
|
397
|
+
interface AuthShellClassNames {
|
|
301
398
|
root?: string;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
loading?: string;
|
|
399
|
+
inner?: string;
|
|
400
|
+
logo?: string;
|
|
305
401
|
}
|
|
306
|
-
interface
|
|
402
|
+
interface AuthShellProps {
|
|
307
403
|
children: ReactNode;
|
|
308
|
-
/**
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
|
|
312
|
-
/** Root class when showing fallback */
|
|
404
|
+
/** Optional logo/brand (e.g. <img> or <Logo />) */
|
|
405
|
+
logo?: ReactNode;
|
|
406
|
+
/** Max width of the auth card area. Default: "sm" (24rem) */
|
|
407
|
+
maxWidth?: "sm" | "md" | "lg";
|
|
313
408
|
className?: string;
|
|
314
|
-
classNames?:
|
|
315
|
-
/** When true, show fallback (login) instead of children when unauthenticated. When false, render null when unauthenticated. */
|
|
316
|
-
showFallback?: boolean;
|
|
317
|
-
/** When true, show a small skeleton card while loading; when false (default), show "Loading..." text. */
|
|
318
|
-
useSkeleton?: boolean;
|
|
409
|
+
classNames?: AuthShellClassNames;
|
|
319
410
|
}
|
|
320
411
|
/**
|
|
321
|
-
*
|
|
322
|
-
*
|
|
412
|
+
* Full-page centered layout for auth screens (login, register).
|
|
413
|
+
* Provides a polished, accessible UX with consistent spacing and optional logo.
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* <AuthShell logo={<img src="/logo.svg" alt="App" />}>
|
|
417
|
+
* <LoginForm />
|
|
418
|
+
* </AuthShell>
|
|
323
419
|
*/
|
|
324
|
-
declare function
|
|
420
|
+
declare function AuthShell({ children, logo, maxWidth, className, classNames, }: AuthShellProps): react_jsx_runtime.JSX.Element;
|
|
325
421
|
|
|
326
422
|
interface CreateEmailSignerFormProps {
|
|
327
423
|
walletId: string;
|
|
@@ -673,6 +769,21 @@ interface NormalizedWallet {
|
|
|
673
769
|
* Accepts any object with optional walletId/id, walletAddress/address, isActive.
|
|
674
770
|
*/
|
|
675
771
|
declare function normalizeWallet(dto: Record<string, unknown>): NormalizedWallet;
|
|
772
|
+
/** Wallet-like object with optional id/walletId and address/walletAddress. */
|
|
773
|
+
type WalletLike = {
|
|
774
|
+
id?: string;
|
|
775
|
+
walletId?: string;
|
|
776
|
+
address?: string;
|
|
777
|
+
walletAddress?: string;
|
|
778
|
+
} & Record<string, unknown>;
|
|
779
|
+
/**
|
|
780
|
+
* Get wallet ID from a wallet-like object. Prefer id; fallback to walletId.
|
|
781
|
+
*/
|
|
782
|
+
declare function getWalletId(wallet: WalletLike | null | undefined): string;
|
|
783
|
+
/**
|
|
784
|
+
* Get wallet address from a wallet-like object. Prefer address; fallback to walletAddress.
|
|
785
|
+
*/
|
|
786
|
+
declare function getWalletAddress(wallet: WalletLike | null | undefined): string;
|
|
676
787
|
|
|
677
788
|
declare function extractErrorMessage(error: unknown): string;
|
|
678
789
|
declare function isAuthError(error: unknown): boolean;
|
|
@@ -716,4 +827,4 @@ interface SignAndSendConnectionAdapter {
|
|
|
716
827
|
*/
|
|
717
828
|
declare function adaptSolanaConnection(connection: Connection): SignAndSendConnectionAdapter;
|
|
718
829
|
|
|
719
|
-
export { type ActionState, AddPasskeyButton, type AddPasskeyButtonProps, type ApiResponse,
|
|
830
|
+
export { type ActionState, AddPasskeyButton, type AddPasskeyButtonProps, type ApiResponse, AuthShell, type AuthShellClassNames, type AuthShellProps, type CilantroAuthContextType, type CilantroConfig, CilantroConnect, type CilantroConnectProps, CilantroContextProvider, type CilantroContextValue, CilantroProvider, type CilantroProviderProps, ConnectWalletButton, type ConnectWalletButtonProps, CreateEmailSignerForm, type CreateEmailSignerFormProps, CreatePhoneSignerForm, type CreatePhoneSignerFormProps, CreateWalletForm, type CreateWalletFormProps, type DeviceKeyStorage, ErrorBoundary, type ErrorBoundaryProps, type ErrorResponse, LoadingOverlay, type LoadingOverlayProps, LoginForm, type LoginFormClassNames, type LoginFormProps, LogoutButton, type LogoutButtonProps, type NormalizedWallet, RegisterForm, type RegisterFormClassNames, type RegisterFormProps, type ResolvedTheme, SIGNER_TYPES, SendSOLForm, type SendSOLFormProps, type SignerType as SendSOLSignerType, SendSPLForm, type SendSPLFormProps, type SignerType$2 as SendTransactionSignerType, type SignAndSendConnection, type SignAndSendConnectionAdapter, type SignAndSendResult, type SignMessageResult, type SignerData, SignerList, type SignerListClassNames, type SignerListProps, SignerSelector, type SignerSelectorClassNames, type SignerSelectorProps, type SignerType$1 as SignerType, Skeleton, type SolanaWallet, type SubmitTransactionDataDto, type SubmitTransactionResult, type Theme, ThemeProvider, type ThemeProviderProps, TransactionHistory, type TransactionHistoryProps, TransactionStatus, type TransactionStatusProps, type UseAuthResult, type UseCilantroConfigResult, type UseExternalWalletResult, type UsePasskeyResult, type UseReturnUrlOptions, type UseSendTransactionResult, type UseSignersOptions, type UseSignersResult, type UseWalletResult, type User, WalletAddress, type WalletAddressProps, WalletBalance, type WalletBalanceProps, type WalletContextType, type WalletData, type WalletDataDto$1 as WalletDataDto, type WalletDataDto as WalletDataDtoFromHook, type WalletData as WalletDataFromHook, type WalletInfo, type WalletLike, WalletSelector, type WalletSelectorClassNames, type WalletSelectorProps, adaptSolanaConnection, extractErrorMessage, extractResponseData, getSignerPublicKey, getWalletAddress, getWalletData, getWalletId, isAuthError, isJwtExpired, normalizeSigner, normalizeWallet, signAndSendTransactionWithSigner, signMessageWithSigner, signTransactionWithSigner, useAuth, useCilantroAuth, useCilantroConfig, useCilantroContext, useExternalWallet, usePasskey, useReturnUrl, useSendTransaction, useSigners, useWallet, useWallets };
|