@forge-connect/react 0.1.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/dist/index.cjs +1179 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +310 -0
- package/dist/index.d.ts +310 -0
- package/dist/index.js +1149 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +443 -0
- package/package.json +46 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
type OAuthProvider = 'google' | 'discord' | 'twitter' | 'apple';
|
|
6
|
+
type Chain = 'solana' | 'ethereum';
|
|
7
|
+
interface ForgeConnectConfig {
|
|
8
|
+
/** Base URL of the ForgeConnect API */
|
|
9
|
+
apiUrl: string;
|
|
10
|
+
/** OAuth providers to enable */
|
|
11
|
+
oauthProviders?: OAuthProvider[];
|
|
12
|
+
/** Enable wallet login */
|
|
13
|
+
walletLogin?: boolean;
|
|
14
|
+
/** Enable passwordless (OTP) login */
|
|
15
|
+
passwordlessLogin?: boolean;
|
|
16
|
+
/** Appearance customization */
|
|
17
|
+
appearance?: AppearanceConfig;
|
|
18
|
+
}
|
|
19
|
+
interface AppearanceConfig {
|
|
20
|
+
theme?: 'light' | 'dark';
|
|
21
|
+
accentColor?: string;
|
|
22
|
+
logo?: string;
|
|
23
|
+
title?: string;
|
|
24
|
+
}
|
|
25
|
+
interface User {
|
|
26
|
+
id: string;
|
|
27
|
+
displayName: string | null;
|
|
28
|
+
avatarUrl: string | null;
|
|
29
|
+
primaryEmail: string | null;
|
|
30
|
+
status: string;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
updatedAt: string;
|
|
33
|
+
}
|
|
34
|
+
type AuthProvider = 'email' | 'google' | 'twitter' | 'discord' | 'apple' | 'solana_wallet' | 'ethereum_wallet';
|
|
35
|
+
interface AuthMethod {
|
|
36
|
+
id: string;
|
|
37
|
+
provider: AuthProvider;
|
|
38
|
+
providerId: string;
|
|
39
|
+
isVerified: boolean;
|
|
40
|
+
verifiedAt: string | null;
|
|
41
|
+
createdAt: string;
|
|
42
|
+
}
|
|
43
|
+
interface Wallet {
|
|
44
|
+
id: string;
|
|
45
|
+
userId: string;
|
|
46
|
+
chain: Chain;
|
|
47
|
+
address: string;
|
|
48
|
+
label: string | null;
|
|
49
|
+
isPrimary: boolean;
|
|
50
|
+
verifiedAt: string | null;
|
|
51
|
+
lastUsedAt: string | null;
|
|
52
|
+
}
|
|
53
|
+
interface Session {
|
|
54
|
+
id: string;
|
|
55
|
+
createdAt: string;
|
|
56
|
+
expiresAt: string;
|
|
57
|
+
lastActiveAt: string;
|
|
58
|
+
deviceInfo: Record<string, unknown> | null;
|
|
59
|
+
ipAddress: string;
|
|
60
|
+
}
|
|
61
|
+
type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated';
|
|
62
|
+
interface AuthState {
|
|
63
|
+
status: AuthStatus;
|
|
64
|
+
user: User | null;
|
|
65
|
+
accessToken: string | null;
|
|
66
|
+
}
|
|
67
|
+
type ModalStep = 'method-select' | 'email-login' | 'email-register' | 'email-otp' | 'wallet-connect' | 'oauth';
|
|
68
|
+
interface ModalState {
|
|
69
|
+
isOpen: boolean;
|
|
70
|
+
step: ModalStep;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface ForgeConnectProviderProps {
|
|
74
|
+
config: ForgeConnectConfig;
|
|
75
|
+
children: ReactNode;
|
|
76
|
+
/** Called when user successfully authenticates */
|
|
77
|
+
onLogin?: (user: User) => void;
|
|
78
|
+
/** Called when user logs out */
|
|
79
|
+
onLogout?: () => void;
|
|
80
|
+
}
|
|
81
|
+
declare function ForgeConnectProvider({ config, children, onLogin, onLogout }: ForgeConnectProviderProps): react_jsx_runtime.JSX.Element;
|
|
82
|
+
|
|
83
|
+
interface LoginButtonProps {
|
|
84
|
+
className?: string;
|
|
85
|
+
label?: string;
|
|
86
|
+
}
|
|
87
|
+
declare function LoginButton({ className, label }: LoginButtonProps): react_jsx_runtime.JSX.Element;
|
|
88
|
+
|
|
89
|
+
declare function LoginModal(): react_jsx_runtime.JSX.Element;
|
|
90
|
+
|
|
91
|
+
interface ModalOverlayProps {
|
|
92
|
+
isOpen: boolean;
|
|
93
|
+
onClose: () => void;
|
|
94
|
+
children: ReactNode;
|
|
95
|
+
}
|
|
96
|
+
declare function ModalOverlay({ isOpen, onClose, children }: ModalOverlayProps): react.ReactPortal | null;
|
|
97
|
+
|
|
98
|
+
declare class ForgeConnectApiError extends Error {
|
|
99
|
+
readonly status: number;
|
|
100
|
+
readonly code: string;
|
|
101
|
+
constructor(status: number, code: string, message: string);
|
|
102
|
+
}
|
|
103
|
+
declare function createApiClient(apiUrl: string): {
|
|
104
|
+
register(email: string, password: string, displayName?: string): Promise<{
|
|
105
|
+
success: true;
|
|
106
|
+
}>;
|
|
107
|
+
login(email: string, password: string): Promise<{
|
|
108
|
+
accessToken: string;
|
|
109
|
+
user: {
|
|
110
|
+
id: string;
|
|
111
|
+
displayName: string | null;
|
|
112
|
+
email: string;
|
|
113
|
+
};
|
|
114
|
+
}>;
|
|
115
|
+
sendOtp(email: string): Promise<{
|
|
116
|
+
success: true;
|
|
117
|
+
}>;
|
|
118
|
+
verifyOtp(email: string, code: string): Promise<{
|
|
119
|
+
accessToken: string;
|
|
120
|
+
user: {
|
|
121
|
+
id: string;
|
|
122
|
+
email: string;
|
|
123
|
+
};
|
|
124
|
+
}>;
|
|
125
|
+
walletChallenge(walletAddress: string, chain?: string): Promise<{
|
|
126
|
+
challengeId: string;
|
|
127
|
+
nonce: string;
|
|
128
|
+
}>;
|
|
129
|
+
walletVerify(challengeId: string, signature: string, walletAddress: string): Promise<{
|
|
130
|
+
accessToken: string;
|
|
131
|
+
}>;
|
|
132
|
+
refresh(): Promise<{
|
|
133
|
+
accessToken: string;
|
|
134
|
+
}>;
|
|
135
|
+
logout(token: string): Promise<{
|
|
136
|
+
success: true;
|
|
137
|
+
}>;
|
|
138
|
+
logoutAll(token: string): Promise<{
|
|
139
|
+
success: true;
|
|
140
|
+
}>;
|
|
141
|
+
getMe(token: string): Promise<{
|
|
142
|
+
id: string;
|
|
143
|
+
displayName: string | null;
|
|
144
|
+
avatarUrl: string | null;
|
|
145
|
+
primaryEmail: string | null;
|
|
146
|
+
status: string;
|
|
147
|
+
createdAt: string;
|
|
148
|
+
updatedAt: string;
|
|
149
|
+
}>;
|
|
150
|
+
updateMe(token: string, data: {
|
|
151
|
+
displayName?: string;
|
|
152
|
+
avatarUrl?: string;
|
|
153
|
+
}): Promise<{
|
|
154
|
+
id: string;
|
|
155
|
+
displayName: string | null;
|
|
156
|
+
avatarUrl: string | null;
|
|
157
|
+
primaryEmail: string | null;
|
|
158
|
+
status: string;
|
|
159
|
+
createdAt: string;
|
|
160
|
+
updatedAt: string;
|
|
161
|
+
}>;
|
|
162
|
+
getAuthMethods(token: string): Promise<{
|
|
163
|
+
id: string;
|
|
164
|
+
provider: string;
|
|
165
|
+
providerId: string;
|
|
166
|
+
isVerified: boolean;
|
|
167
|
+
verifiedAt: string | null;
|
|
168
|
+
createdAt: string;
|
|
169
|
+
}[]>;
|
|
170
|
+
linkAuthMethod(token: string, data: {
|
|
171
|
+
provider: string;
|
|
172
|
+
email?: string;
|
|
173
|
+
password?: string;
|
|
174
|
+
challengeId?: string;
|
|
175
|
+
signature?: string;
|
|
176
|
+
walletAddress?: string;
|
|
177
|
+
}): Promise<{
|
|
178
|
+
success: true;
|
|
179
|
+
}>;
|
|
180
|
+
unlinkAuthMethod(token: string, id: string): Promise<{
|
|
181
|
+
success: true;
|
|
182
|
+
}>;
|
|
183
|
+
getWallets(token: string): Promise<{
|
|
184
|
+
id: string;
|
|
185
|
+
userId: string;
|
|
186
|
+
chain: string;
|
|
187
|
+
address: string;
|
|
188
|
+
label: string | null;
|
|
189
|
+
isPrimary: boolean;
|
|
190
|
+
verifiedAt: string | null;
|
|
191
|
+
lastUsedAt: string | null;
|
|
192
|
+
}[]>;
|
|
193
|
+
updateWallet(token: string, id: string, data: {
|
|
194
|
+
label?: string;
|
|
195
|
+
isPrimary?: boolean;
|
|
196
|
+
}): Promise<{
|
|
197
|
+
id: string;
|
|
198
|
+
userId: string;
|
|
199
|
+
chain: string;
|
|
200
|
+
address: string;
|
|
201
|
+
label: string | null;
|
|
202
|
+
isPrimary: boolean;
|
|
203
|
+
verifiedAt: string | null;
|
|
204
|
+
lastUsedAt: string | null;
|
|
205
|
+
}>;
|
|
206
|
+
getSessions(token: string): Promise<{
|
|
207
|
+
id: string;
|
|
208
|
+
createdAt: string;
|
|
209
|
+
expiresAt: string;
|
|
210
|
+
lastActiveAt: string;
|
|
211
|
+
deviceInfo: Record<string, unknown> | null;
|
|
212
|
+
ipAddress: string;
|
|
213
|
+
}[]>;
|
|
214
|
+
revokeSession(token: string, id: string): Promise<{
|
|
215
|
+
success: true;
|
|
216
|
+
}>;
|
|
217
|
+
};
|
|
218
|
+
type ApiClient = ReturnType<typeof createApiClient>;
|
|
219
|
+
|
|
220
|
+
interface ForgeConnectContextValue {
|
|
221
|
+
auth: AuthState;
|
|
222
|
+
modal: ModalState;
|
|
223
|
+
config: ForgeConnectConfig;
|
|
224
|
+
api: ApiClient;
|
|
225
|
+
loginWithEmail: (email: string, password: string) => Promise<void>;
|
|
226
|
+
register: (email: string, password: string, displayName?: string) => Promise<void>;
|
|
227
|
+
sendOtp: (email: string) => Promise<void>;
|
|
228
|
+
verifyOtp: (email: string, code: string) => Promise<void>;
|
|
229
|
+
loginWithWallet: (walletAddress: string, signMessage: (message: Uint8Array) => Promise<Uint8Array>, chain?: string) => Promise<void>;
|
|
230
|
+
loginWithOAuth: (provider: string) => void;
|
|
231
|
+
logout: () => Promise<void>;
|
|
232
|
+
logoutAll: () => Promise<void>;
|
|
233
|
+
openModal: () => void;
|
|
234
|
+
closeModal: () => void;
|
|
235
|
+
setModalStep: (step: ModalState['step']) => void;
|
|
236
|
+
getAccessToken: () => string | null;
|
|
237
|
+
}
|
|
238
|
+
declare const ForgeConnectContext: react.Context<ForgeConnectContextValue | null>;
|
|
239
|
+
|
|
240
|
+
declare function useForgeConnect(): ForgeConnectContextValue;
|
|
241
|
+
|
|
242
|
+
declare function useUser(): {
|
|
243
|
+
user: User | null;
|
|
244
|
+
authMethods: AuthMethod[] | null;
|
|
245
|
+
loading: boolean;
|
|
246
|
+
updateProfile: (data: {
|
|
247
|
+
displayName?: string;
|
|
248
|
+
avatarUrl?: string;
|
|
249
|
+
}) => Promise<{
|
|
250
|
+
id: string;
|
|
251
|
+
displayName: string | null;
|
|
252
|
+
avatarUrl: string | null;
|
|
253
|
+
primaryEmail: string | null;
|
|
254
|
+
status: string;
|
|
255
|
+
createdAt: string;
|
|
256
|
+
updatedAt: string;
|
|
257
|
+
}>;
|
|
258
|
+
fetchAuthMethods: () => Promise<{
|
|
259
|
+
id: string;
|
|
260
|
+
provider: string;
|
|
261
|
+
providerId: string;
|
|
262
|
+
isVerified: boolean;
|
|
263
|
+
verifiedAt: string | null;
|
|
264
|
+
createdAt: string;
|
|
265
|
+
}[]>;
|
|
266
|
+
linkAuthMethod: (data: {
|
|
267
|
+
provider: string;
|
|
268
|
+
email?: string;
|
|
269
|
+
password?: string;
|
|
270
|
+
challengeId?: string;
|
|
271
|
+
signature?: string;
|
|
272
|
+
walletAddress?: string;
|
|
273
|
+
}) => Promise<void>;
|
|
274
|
+
unlinkAuthMethod: (id: string) => Promise<void>;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
declare function useWallets(): {
|
|
278
|
+
wallets: Wallet[] | null;
|
|
279
|
+
loading: boolean;
|
|
280
|
+
fetchWallets: () => Promise<{
|
|
281
|
+
id: string;
|
|
282
|
+
userId: string;
|
|
283
|
+
chain: string;
|
|
284
|
+
address: string;
|
|
285
|
+
label: string | null;
|
|
286
|
+
isPrimary: boolean;
|
|
287
|
+
verifiedAt: string | null;
|
|
288
|
+
lastUsedAt: string | null;
|
|
289
|
+
}[]>;
|
|
290
|
+
updateWallet: (id: string, data: {
|
|
291
|
+
label?: string;
|
|
292
|
+
isPrimary?: boolean;
|
|
293
|
+
}) => Promise<void>;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
declare function useSessions(): {
|
|
297
|
+
sessions: Session[] | null;
|
|
298
|
+
loading: boolean;
|
|
299
|
+
fetchSessions: () => Promise<{
|
|
300
|
+
id: string;
|
|
301
|
+
createdAt: string;
|
|
302
|
+
expiresAt: string;
|
|
303
|
+
lastActiveAt: string;
|
|
304
|
+
deviceInfo: Record<string, unknown> | null;
|
|
305
|
+
ipAddress: string;
|
|
306
|
+
}[]>;
|
|
307
|
+
revokeSession: (id: string) => Promise<void>;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export { type ApiClient, type AppearanceConfig, type AuthMethod, type AuthProvider, type AuthState, type AuthStatus, type Chain, ForgeConnectApiError, type ForgeConnectConfig, ForgeConnectContext, type ForgeConnectContextValue, ForgeConnectProvider, LoginButton, LoginModal, ModalOverlay, type ModalState, type ModalStep, type OAuthProvider, type Session, type User, type Wallet, createApiClient, useForgeConnect, useSessions, useUser, useWallets };
|