@digilogiclabs/platform-core 1.25.0 → 1.27.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/README.md +12 -6
- package/dist/{ConsoleEmail-iJO7Cb_v.d.ts → ConsoleEmail-BRa76Bfm.d.ts} +3 -106
- package/dist/{ConsoleEmail-CgSIvRdj.d.mts → ConsoleEmail-DSmK5jbu.d.mts} +3 -106
- package/dist/IDatabase-yOhemn5C.d.mts +49 -0
- package/dist/IDatabase-yOhemn5C.d.ts +49 -0
- package/dist/IStorage-CcFAvKDp.d.mts +58 -0
- package/dist/IStorage-CcFAvKDp.d.ts +58 -0
- package/dist/adapters/supabase-auth.d.mts +2 -0
- package/dist/adapters/supabase-auth.d.ts +2 -0
- package/dist/adapters/supabase-auth.js +714 -0
- package/dist/adapters/supabase-auth.js.map +1 -0
- package/dist/adapters/supabase-auth.mjs +687 -0
- package/dist/adapters/supabase-auth.mjs.map +1 -0
- package/dist/adapters/supabase-storage.d.mts +93 -0
- package/dist/adapters/supabase-storage.d.ts +93 -0
- package/dist/adapters/supabase-storage.js +249 -0
- package/dist/adapters/supabase-storage.js.map +1 -0
- package/dist/adapters/supabase-storage.mjs +222 -0
- package/dist/adapters/supabase-storage.mjs.map +1 -0
- package/dist/adapters/supabase.d.mts +24 -0
- package/dist/adapters/supabase.d.ts +24 -0
- package/dist/adapters/supabase.js +218 -0
- package/dist/adapters/supabase.js.map +1 -0
- package/dist/adapters/supabase.mjs +191 -0
- package/dist/adapters/supabase.mjs.map +1 -0
- package/dist/auth.d.mts +523 -512
- package/dist/auth.d.ts +523 -512
- package/dist/auth.js +7 -0
- package/dist/auth.js.map +1 -1
- package/dist/auth.mjs +7 -0
- package/dist/auth.mjs.map +1 -1
- package/dist/index-cN9dgBsn.d.mts +612 -0
- package/dist/index-cN9dgBsn.d.ts +612 -0
- package/dist/index.d.mts +10 -717
- package/dist/index.d.ts +10 -717
- package/dist/index.js +12 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -5
- package/dist/index.mjs.map +1 -1
- package/dist/testing.d.mts +5 -2
- package/dist/testing.d.ts +5 -2
- package/dist/testing.js +1 -0
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -0
- package/dist/testing.mjs.map +1 -1
- package/package.json +16 -1
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Authentication Interface
|
|
5
|
+
*
|
|
6
|
+
* Provides a vendor-agnostic abstraction for authentication.
|
|
7
|
+
* Supports various backends: Supabase, Firebase, Auth0, Clerk,
|
|
8
|
+
* AWS Cognito, Azure AD, custom JWT, etc.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Get current user
|
|
13
|
+
* const user = await auth.getCurrentUser()
|
|
14
|
+
*
|
|
15
|
+
* // Sign in with email
|
|
16
|
+
* const result = await auth.signInWithEmail({
|
|
17
|
+
* email: 'user@example.com',
|
|
18
|
+
* password: 'password',
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* // Sign in with OAuth
|
|
22
|
+
* const oauth = await auth.signInWithOAuth('google', {
|
|
23
|
+
* redirectTo: 'https://myapp.com/callback',
|
|
24
|
+
* })
|
|
25
|
+
* window.location.href = oauth.url
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Authenticated user
|
|
30
|
+
*/
|
|
31
|
+
interface AuthUser {
|
|
32
|
+
/** Unique user identifier */
|
|
33
|
+
id: string;
|
|
34
|
+
/** User email address */
|
|
35
|
+
email: string | null;
|
|
36
|
+
/** Whether email has been verified */
|
|
37
|
+
emailVerified: boolean;
|
|
38
|
+
/** User phone number */
|
|
39
|
+
phone?: string | null;
|
|
40
|
+
/** Whether phone has been verified */
|
|
41
|
+
phoneVerified?: boolean;
|
|
42
|
+
/** User display name */
|
|
43
|
+
displayName?: string | null;
|
|
44
|
+
/** User avatar URL */
|
|
45
|
+
avatarUrl?: string | null;
|
|
46
|
+
/** User metadata (provider-specific) */
|
|
47
|
+
metadata: Record<string, unknown>;
|
|
48
|
+
/** Account creation timestamp */
|
|
49
|
+
createdAt: Date;
|
|
50
|
+
/** Last sign-in timestamp */
|
|
51
|
+
lastSignInAt?: Date;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Authentication session
|
|
55
|
+
*/
|
|
56
|
+
interface AuthSession {
|
|
57
|
+
/** Access token for API calls */
|
|
58
|
+
accessToken: string;
|
|
59
|
+
/** Refresh token for renewing session */
|
|
60
|
+
refreshToken?: string;
|
|
61
|
+
/** Token type (usually 'Bearer') */
|
|
62
|
+
tokenType?: string;
|
|
63
|
+
/** Session expiration timestamp */
|
|
64
|
+
expiresAt: Date;
|
|
65
|
+
/** Authenticated user */
|
|
66
|
+
user: AuthUser;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Result of authentication operation
|
|
70
|
+
*/
|
|
71
|
+
interface AuthResult {
|
|
72
|
+
/** Whether the operation succeeded */
|
|
73
|
+
success: boolean;
|
|
74
|
+
/** Authenticated user (if successful) */
|
|
75
|
+
user?: AuthUser;
|
|
76
|
+
/** Session data (if successful) */
|
|
77
|
+
session?: AuthSession;
|
|
78
|
+
/** Error details (if failed) */
|
|
79
|
+
error?: AuthError;
|
|
80
|
+
/** Whether email verification is required */
|
|
81
|
+
needsEmailVerification?: boolean;
|
|
82
|
+
/** Whether MFA is required */
|
|
83
|
+
needsMfa?: boolean;
|
|
84
|
+
/** MFA challenge data */
|
|
85
|
+
mfaChallenge?: MfaChallenge;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Authentication error
|
|
89
|
+
*/
|
|
90
|
+
interface AuthError {
|
|
91
|
+
/** Error code */
|
|
92
|
+
code: AuthErrorCode;
|
|
93
|
+
/** Human-readable error message */
|
|
94
|
+
message: string;
|
|
95
|
+
/** Original provider error (for debugging) */
|
|
96
|
+
originalError?: unknown;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Standard authentication error codes
|
|
100
|
+
*/
|
|
101
|
+
type AuthErrorCode = "invalid_credentials" | "user_not_found" | "user_disabled" | "email_not_confirmed" | "email_already_exists" | "phone_already_exists" | "weak_password" | "expired_token" | "invalid_token" | "session_expired" | "rate_limited" | "mfa_required" | "mfa_invalid" | "oauth_error" | "network_error" | "server_error" | "unknown_error";
|
|
102
|
+
/**
|
|
103
|
+
* Options for signing in with email/password
|
|
104
|
+
*/
|
|
105
|
+
interface SignInWithEmailOptions {
|
|
106
|
+
/** User email address */
|
|
107
|
+
email: string;
|
|
108
|
+
/** User password */
|
|
109
|
+
password: string;
|
|
110
|
+
/** CAPTCHA token for bot protection */
|
|
111
|
+
captchaToken?: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Options for signing up with email/password
|
|
115
|
+
*/
|
|
116
|
+
interface SignUpWithEmailOptions {
|
|
117
|
+
/** User email address */
|
|
118
|
+
email: string;
|
|
119
|
+
/** User password */
|
|
120
|
+
password: string;
|
|
121
|
+
/** User metadata to store */
|
|
122
|
+
metadata?: Record<string, unknown>;
|
|
123
|
+
/** Redirect URL after email verification */
|
|
124
|
+
emailRedirectTo?: string;
|
|
125
|
+
/** CAPTCHA token for bot protection */
|
|
126
|
+
captchaToken?: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Options for password reset
|
|
130
|
+
*/
|
|
131
|
+
interface ResetPasswordOptions {
|
|
132
|
+
/** User email address */
|
|
133
|
+
email: string;
|
|
134
|
+
/** Redirect URL after password reset */
|
|
135
|
+
redirectTo?: string;
|
|
136
|
+
/** CAPTCHA token for bot protection */
|
|
137
|
+
captchaToken?: string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Options for updating password
|
|
141
|
+
*/
|
|
142
|
+
interface UpdatePasswordOptions {
|
|
143
|
+
/** New password */
|
|
144
|
+
password: string;
|
|
145
|
+
/** Current password (for reauthentication) */
|
|
146
|
+
currentPassword?: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Supported OAuth providers
|
|
150
|
+
*/
|
|
151
|
+
type OAuthProvider = "google" | "github" | "gitlab" | "bitbucket" | "azure" | "facebook" | "twitter" | "discord" | "linkedin" | "apple" | "spotify" | "slack" | "notion" | "figma" | "zoom" | "twitch";
|
|
152
|
+
/**
|
|
153
|
+
* Options for OAuth sign-in
|
|
154
|
+
*/
|
|
155
|
+
interface OAuthOptions {
|
|
156
|
+
/** Redirect URL after OAuth */
|
|
157
|
+
redirectTo?: string;
|
|
158
|
+
/** OAuth scopes to request */
|
|
159
|
+
scopes?: string;
|
|
160
|
+
/** Additional query parameters */
|
|
161
|
+
queryParams?: Record<string, string>;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Result of OAuth sign-in initiation
|
|
165
|
+
*/
|
|
166
|
+
interface OAuthResult {
|
|
167
|
+
/** URL to redirect user to */
|
|
168
|
+
url: string;
|
|
169
|
+
/** Provider used */
|
|
170
|
+
provider: OAuthProvider;
|
|
171
|
+
/** State parameter for CSRF protection */
|
|
172
|
+
state?: string;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Options for signing in with phone
|
|
176
|
+
*/
|
|
177
|
+
interface SignInWithPhoneOptions {
|
|
178
|
+
/** Phone number (E.164 format) */
|
|
179
|
+
phone: string;
|
|
180
|
+
/** CAPTCHA token for bot protection */
|
|
181
|
+
captchaToken?: string;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Options for verifying phone OTP
|
|
185
|
+
*/
|
|
186
|
+
interface VerifyPhoneOtpOptions {
|
|
187
|
+
/** Phone number (E.164 format) */
|
|
188
|
+
phone: string;
|
|
189
|
+
/** OTP code */
|
|
190
|
+
token: string;
|
|
191
|
+
/** Type of verification */
|
|
192
|
+
type: "sms" | "phone_change";
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Options for magic link sign-in
|
|
196
|
+
*/
|
|
197
|
+
interface SignInWithMagicLinkOptions {
|
|
198
|
+
/** User email address */
|
|
199
|
+
email: string;
|
|
200
|
+
/** Redirect URL after clicking link */
|
|
201
|
+
redirectTo?: string;
|
|
202
|
+
/** CAPTCHA token for bot protection */
|
|
203
|
+
captchaToken?: string;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* MFA factor types
|
|
207
|
+
*/
|
|
208
|
+
type MfaFactorType = "totp" | "phone" | "webauthn";
|
|
209
|
+
/**
|
|
210
|
+
* MFA factor
|
|
211
|
+
*/
|
|
212
|
+
interface MfaFactor {
|
|
213
|
+
/** Factor ID */
|
|
214
|
+
id: string;
|
|
215
|
+
/** Factor type */
|
|
216
|
+
type: MfaFactorType;
|
|
217
|
+
/** Factor name/label */
|
|
218
|
+
name?: string;
|
|
219
|
+
/** Whether factor is verified */
|
|
220
|
+
verified: boolean;
|
|
221
|
+
/** Creation timestamp */
|
|
222
|
+
createdAt: Date;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* MFA challenge
|
|
226
|
+
*/
|
|
227
|
+
interface MfaChallenge {
|
|
228
|
+
/** Challenge ID */
|
|
229
|
+
id: string;
|
|
230
|
+
/** Factor ID being verified */
|
|
231
|
+
factorId: string;
|
|
232
|
+
/** Factor type */
|
|
233
|
+
type: MfaFactorType;
|
|
234
|
+
/** Challenge expiration */
|
|
235
|
+
expiresAt: Date;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Options for enrolling MFA
|
|
239
|
+
*/
|
|
240
|
+
interface EnrollMfaOptions {
|
|
241
|
+
/** Factor type to enroll */
|
|
242
|
+
type: MfaFactorType;
|
|
243
|
+
/** Friendly name for the factor */
|
|
244
|
+
friendlyName?: string;
|
|
245
|
+
/** Phone number (for SMS MFA) */
|
|
246
|
+
phone?: string;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Result of MFA enrollment
|
|
250
|
+
*/
|
|
251
|
+
interface EnrollMfaResult {
|
|
252
|
+
/** Factor ID */
|
|
253
|
+
factorId: string;
|
|
254
|
+
/** TOTP secret (for TOTP enrollment) */
|
|
255
|
+
totpSecret?: string;
|
|
256
|
+
/** TOTP QR code URI */
|
|
257
|
+
totpQrCode?: string;
|
|
258
|
+
/** Whether verification is required */
|
|
259
|
+
needsVerification: boolean;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Options for verifying MFA
|
|
263
|
+
*/
|
|
264
|
+
interface VerifyMfaOptions {
|
|
265
|
+
/** Factor ID */
|
|
266
|
+
factorId: string;
|
|
267
|
+
/** Challenge ID (if responding to challenge) */
|
|
268
|
+
challengeId?: string;
|
|
269
|
+
/** Verification code */
|
|
270
|
+
code: string;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Options for updating user profile
|
|
274
|
+
*/
|
|
275
|
+
interface UpdateUserOptions {
|
|
276
|
+
/** New email address */
|
|
277
|
+
email?: string;
|
|
278
|
+
/** New phone number */
|
|
279
|
+
phone?: string;
|
|
280
|
+
/** New display name */
|
|
281
|
+
displayName?: string;
|
|
282
|
+
/** New avatar URL */
|
|
283
|
+
avatarUrl?: string;
|
|
284
|
+
/** Additional metadata */
|
|
285
|
+
metadata?: Record<string, unknown>;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Options for deleting account
|
|
289
|
+
*/
|
|
290
|
+
interface DeleteAccountOptions {
|
|
291
|
+
/** Current password (for reauthentication) */
|
|
292
|
+
password?: string;
|
|
293
|
+
/** Reason for deletion */
|
|
294
|
+
reason?: string;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Auth state change event types
|
|
298
|
+
*/
|
|
299
|
+
type AuthEventType = "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "USER_UPDATED" | "PASSWORD_RECOVERY" | "MFA_CHALLENGE_VERIFIED";
|
|
300
|
+
/**
|
|
301
|
+
* Auth state change callback
|
|
302
|
+
*/
|
|
303
|
+
type AuthStateChangeCallback = (event: AuthEventType, session: AuthSession | null) => void;
|
|
304
|
+
/**
|
|
305
|
+
* Unsubscribe function
|
|
306
|
+
*/
|
|
307
|
+
type Unsubscribe = () => void;
|
|
308
|
+
/**
|
|
309
|
+
* Auth configuration options
|
|
310
|
+
*/
|
|
311
|
+
interface AuthConfig {
|
|
312
|
+
/** Auto-refresh sessions before expiry */
|
|
313
|
+
autoRefreshToken?: boolean;
|
|
314
|
+
/** Persist sessions to storage */
|
|
315
|
+
persistSession?: boolean;
|
|
316
|
+
/** Storage key for session */
|
|
317
|
+
storageKey?: string;
|
|
318
|
+
/** Custom storage implementation */
|
|
319
|
+
storage?: AuthStorage;
|
|
320
|
+
/** MFA configuration */
|
|
321
|
+
mfa?: {
|
|
322
|
+
/** Enabled MFA types */
|
|
323
|
+
enabledTypes?: MfaFactorType[];
|
|
324
|
+
/** Require MFA for all users */
|
|
325
|
+
required?: boolean;
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Auth storage interface (for session persistence)
|
|
330
|
+
*/
|
|
331
|
+
interface AuthStorage {
|
|
332
|
+
getItem(key: string): Promise<string | null> | string | null;
|
|
333
|
+
setItem(key: string, value: string): Promise<void> | void;
|
|
334
|
+
removeItem(key: string): Promise<void> | void;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Authentication Provider Interface
|
|
338
|
+
*
|
|
339
|
+
* Provides a vendor-agnostic abstraction for authentication operations.
|
|
340
|
+
*/
|
|
341
|
+
interface IAuth {
|
|
342
|
+
/**
|
|
343
|
+
* Get the current authenticated user
|
|
344
|
+
* @returns The current user or null if not authenticated
|
|
345
|
+
*/
|
|
346
|
+
getCurrentUser(): Promise<AuthUser | null>;
|
|
347
|
+
/**
|
|
348
|
+
* Get the current session
|
|
349
|
+
* @returns The current session or null if not authenticated
|
|
350
|
+
*/
|
|
351
|
+
getSession(): Promise<AuthSession | null>;
|
|
352
|
+
/**
|
|
353
|
+
* Refresh the current session
|
|
354
|
+
* @returns The refreshed session or null if refresh failed
|
|
355
|
+
*/
|
|
356
|
+
refreshSession(): Promise<AuthSession | null>;
|
|
357
|
+
/**
|
|
358
|
+
* Sign out the current user
|
|
359
|
+
* @param options Scope of sign out (local or global)
|
|
360
|
+
*/
|
|
361
|
+
signOut(options?: {
|
|
362
|
+
scope?: "local" | "global";
|
|
363
|
+
}): Promise<void>;
|
|
364
|
+
/**
|
|
365
|
+
* Sign in with email and password
|
|
366
|
+
* @param options Sign-in options
|
|
367
|
+
*/
|
|
368
|
+
signInWithEmail(options: SignInWithEmailOptions): Promise<AuthResult>;
|
|
369
|
+
/**
|
|
370
|
+
* Sign up with email and password
|
|
371
|
+
* @param options Sign-up options
|
|
372
|
+
*/
|
|
373
|
+
signUpWithEmail(options: SignUpWithEmailOptions): Promise<AuthResult>;
|
|
374
|
+
/**
|
|
375
|
+
* Send a password reset email
|
|
376
|
+
* @param options Password reset options
|
|
377
|
+
*/
|
|
378
|
+
resetPassword(options: ResetPasswordOptions): Promise<AuthResult>;
|
|
379
|
+
/**
|
|
380
|
+
* Update the current user's password
|
|
381
|
+
* @param options Password update options
|
|
382
|
+
*/
|
|
383
|
+
updatePassword(options: UpdatePasswordOptions): Promise<AuthResult>;
|
|
384
|
+
/**
|
|
385
|
+
* Initiate OAuth sign-in with a provider
|
|
386
|
+
* @param provider OAuth provider
|
|
387
|
+
* @param options OAuth options
|
|
388
|
+
* @returns URL to redirect user to
|
|
389
|
+
*/
|
|
390
|
+
signInWithOAuth(provider: OAuthProvider, options?: OAuthOptions): Promise<OAuthResult>;
|
|
391
|
+
/**
|
|
392
|
+
* Handle OAuth callback (exchange code for session)
|
|
393
|
+
* @param code Authorization code from callback
|
|
394
|
+
*/
|
|
395
|
+
handleOAuthCallback(code: string): Promise<AuthResult>;
|
|
396
|
+
/**
|
|
397
|
+
* Send a magic link email
|
|
398
|
+
* @param options Magic link options
|
|
399
|
+
*/
|
|
400
|
+
signInWithMagicLink(options: SignInWithMagicLinkOptions): Promise<AuthResult>;
|
|
401
|
+
/**
|
|
402
|
+
* Verify a magic link token
|
|
403
|
+
* @param token Token from magic link
|
|
404
|
+
*/
|
|
405
|
+
verifyMagicLink(token: string): Promise<AuthResult>;
|
|
406
|
+
/**
|
|
407
|
+
* Send OTP to phone number
|
|
408
|
+
* @param options Phone sign-in options
|
|
409
|
+
*/
|
|
410
|
+
signInWithPhone(options: SignInWithPhoneOptions): Promise<AuthResult>;
|
|
411
|
+
/**
|
|
412
|
+
* Verify phone OTP
|
|
413
|
+
* @param options OTP verification options
|
|
414
|
+
*/
|
|
415
|
+
verifyPhoneOtp(options: VerifyPhoneOtpOptions): Promise<AuthResult>;
|
|
416
|
+
/**
|
|
417
|
+
* Verify email with token
|
|
418
|
+
* @param token Verification token from email
|
|
419
|
+
*/
|
|
420
|
+
verifyEmail(token: string): Promise<AuthResult>;
|
|
421
|
+
/**
|
|
422
|
+
* Resend email verification
|
|
423
|
+
* @param email Email address to send verification to
|
|
424
|
+
*/
|
|
425
|
+
resendVerification(email: string): Promise<AuthResult>;
|
|
426
|
+
/**
|
|
427
|
+
* List user's MFA factors
|
|
428
|
+
*/
|
|
429
|
+
listMfaFactors(): Promise<MfaFactor[]>;
|
|
430
|
+
/**
|
|
431
|
+
* Enroll a new MFA factor
|
|
432
|
+
* @param options Enrollment options
|
|
433
|
+
*/
|
|
434
|
+
enrollMfa(options: EnrollMfaOptions): Promise<EnrollMfaResult>;
|
|
435
|
+
/**
|
|
436
|
+
* Verify MFA factor
|
|
437
|
+
* @param options Verification options
|
|
438
|
+
*/
|
|
439
|
+
verifyMfa(options: VerifyMfaOptions): Promise<AuthResult>;
|
|
440
|
+
/**
|
|
441
|
+
* Unenroll an MFA factor
|
|
442
|
+
* @param factorId Factor to remove
|
|
443
|
+
*/
|
|
444
|
+
unenrollMfa(factorId: string): Promise<void>;
|
|
445
|
+
/**
|
|
446
|
+
* Create MFA challenge
|
|
447
|
+
* @param factorId Factor to challenge
|
|
448
|
+
*/
|
|
449
|
+
createMfaChallenge(factorId: string): Promise<MfaChallenge>;
|
|
450
|
+
/**
|
|
451
|
+
* Update user profile
|
|
452
|
+
* @param options Profile update options
|
|
453
|
+
*/
|
|
454
|
+
updateUser(options: UpdateUserOptions): Promise<AuthResult>;
|
|
455
|
+
/**
|
|
456
|
+
* Delete user account
|
|
457
|
+
* @param options Deletion options
|
|
458
|
+
*/
|
|
459
|
+
deleteAccount(options?: DeleteAccountOptions): Promise<AuthResult>;
|
|
460
|
+
/**
|
|
461
|
+
* Reauthenticate user (for sensitive operations)
|
|
462
|
+
* @param password Current password
|
|
463
|
+
*/
|
|
464
|
+
reauthenticate(password: string): Promise<AuthResult>;
|
|
465
|
+
/**
|
|
466
|
+
* Subscribe to auth state changes
|
|
467
|
+
* @param callback Callback for state changes
|
|
468
|
+
* @returns Unsubscribe function
|
|
469
|
+
*/
|
|
470
|
+
onAuthStateChange(callback: AuthStateChangeCallback): Unsubscribe;
|
|
471
|
+
/**
|
|
472
|
+
* Check auth provider health
|
|
473
|
+
*/
|
|
474
|
+
healthCheck(): Promise<boolean>;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Map a provider error to a normalized AuthError
|
|
478
|
+
*/
|
|
479
|
+
declare function createAuthError(code: AuthErrorCode, message: string, originalError?: unknown): AuthError;
|
|
480
|
+
/**
|
|
481
|
+
* Check if an error is an AuthError
|
|
482
|
+
*/
|
|
483
|
+
declare function isAuthError(error: unknown): error is AuthError;
|
|
484
|
+
/**
|
|
485
|
+
* Standard error messages
|
|
486
|
+
*/
|
|
487
|
+
declare const AuthErrorMessages: Record<AuthErrorCode, string>;
|
|
488
|
+
/**
|
|
489
|
+
* Generate a secure random string
|
|
490
|
+
*/
|
|
491
|
+
declare function generateSecureToken(length?: number): string;
|
|
492
|
+
/**
|
|
493
|
+
* Memory-based Auth Adapter
|
|
494
|
+
* For testing purposes - stores users and sessions in memory
|
|
495
|
+
*/
|
|
496
|
+
declare class MemoryAuth implements IAuth {
|
|
497
|
+
private users;
|
|
498
|
+
private sessions;
|
|
499
|
+
private currentUserId;
|
|
500
|
+
private listeners;
|
|
501
|
+
private mfaFactors;
|
|
502
|
+
/**
|
|
503
|
+
* Seed a test user
|
|
504
|
+
*/
|
|
505
|
+
seedUser(user: AuthUser, password: string): void;
|
|
506
|
+
/**
|
|
507
|
+
* Clear all data (for testing)
|
|
508
|
+
*/
|
|
509
|
+
clear(): void;
|
|
510
|
+
/**
|
|
511
|
+
* Get all users (for testing)
|
|
512
|
+
*/
|
|
513
|
+
getUsers(): AuthUser[];
|
|
514
|
+
getCurrentUser(): Promise<AuthUser | null>;
|
|
515
|
+
getSession(): Promise<AuthSession | null>;
|
|
516
|
+
refreshSession(): Promise<AuthSession | null>;
|
|
517
|
+
signOut(): Promise<void>;
|
|
518
|
+
signInWithEmail(options: SignInWithEmailOptions): Promise<AuthResult>;
|
|
519
|
+
signUpWithEmail(options: SignUpWithEmailOptions): Promise<AuthResult>;
|
|
520
|
+
resetPassword(_options: ResetPasswordOptions): Promise<AuthResult>;
|
|
521
|
+
updatePassword(options: UpdatePasswordOptions): Promise<AuthResult>;
|
|
522
|
+
signInWithOAuth(provider: OAuthProvider, options?: OAuthOptions): Promise<OAuthResult>;
|
|
523
|
+
handleOAuthCallback(_code: string): Promise<AuthResult>;
|
|
524
|
+
signInWithMagicLink(_options: SignInWithMagicLinkOptions): Promise<AuthResult>;
|
|
525
|
+
verifyMagicLink(_token: string): Promise<AuthResult>;
|
|
526
|
+
signInWithPhone(_options: SignInWithPhoneOptions): Promise<AuthResult>;
|
|
527
|
+
verifyPhoneOtp(_options: VerifyPhoneOtpOptions): Promise<AuthResult>;
|
|
528
|
+
verifyEmail(_token: string): Promise<AuthResult>;
|
|
529
|
+
resendVerification(_email: string): Promise<AuthResult>;
|
|
530
|
+
listMfaFactors(): Promise<MfaFactor[]>;
|
|
531
|
+
enrollMfa(options: EnrollMfaOptions): Promise<EnrollMfaResult>;
|
|
532
|
+
verifyMfa(options: VerifyMfaOptions): Promise<AuthResult>;
|
|
533
|
+
unenrollMfa(factorId: string): Promise<void>;
|
|
534
|
+
createMfaChallenge(factorId: string): Promise<MfaChallenge>;
|
|
535
|
+
updateUser(options: UpdateUserOptions): Promise<AuthResult>;
|
|
536
|
+
deleteAccount(_options?: DeleteAccountOptions): Promise<AuthResult>;
|
|
537
|
+
reauthenticate(password: string): Promise<AuthResult>;
|
|
538
|
+
onAuthStateChange(callback: AuthStateChangeCallback): Unsubscribe;
|
|
539
|
+
healthCheck(): Promise<boolean>;
|
|
540
|
+
private createSession;
|
|
541
|
+
private notifyListeners;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Supabase Auth Adapter
|
|
546
|
+
* Production implementation using Supabase as the authentication provider
|
|
547
|
+
*/
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Configuration for Supabase Auth
|
|
551
|
+
*/
|
|
552
|
+
interface SupabaseAuthConfig {
|
|
553
|
+
/** Supabase project URL */
|
|
554
|
+
url: string;
|
|
555
|
+
/** Supabase anon/public key */
|
|
556
|
+
anonKey: string;
|
|
557
|
+
/** Optional service role key for admin operations */
|
|
558
|
+
serviceRoleKey?: string;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Supabase Auth Adapter
|
|
562
|
+
*
|
|
563
|
+
* Provides IAuth implementation using Supabase authentication.
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
* ```typescript
|
|
567
|
+
* import { createClient } from '@supabase/supabase-js'
|
|
568
|
+
* import { SupabaseAuth } from '@digilogiclabs/platform-core/adapters/supabase-auth'
|
|
569
|
+
*
|
|
570
|
+
* const supabase = createClient(url, anonKey)
|
|
571
|
+
* const auth = new SupabaseAuth(supabase)
|
|
572
|
+
*
|
|
573
|
+
* const result = await auth.signInWithEmail({
|
|
574
|
+
* email: 'user@example.com',
|
|
575
|
+
* password: 'password',
|
|
576
|
+
* })
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
declare class SupabaseAuth implements IAuth {
|
|
580
|
+
private client;
|
|
581
|
+
constructor(client: SupabaseClient);
|
|
582
|
+
getCurrentUser(): Promise<AuthUser | null>;
|
|
583
|
+
getSession(): Promise<AuthSession | null>;
|
|
584
|
+
refreshSession(): Promise<AuthSession | null>;
|
|
585
|
+
signOut(options?: {
|
|
586
|
+
scope?: "local" | "global";
|
|
587
|
+
}): Promise<void>;
|
|
588
|
+
signInWithEmail(options: SignInWithEmailOptions): Promise<AuthResult>;
|
|
589
|
+
signUpWithEmail(options: SignUpWithEmailOptions): Promise<AuthResult>;
|
|
590
|
+
resetPassword(options: ResetPasswordOptions): Promise<AuthResult>;
|
|
591
|
+
updatePassword(options: UpdatePasswordOptions): Promise<AuthResult>;
|
|
592
|
+
signInWithOAuth(provider: OAuthProvider, options?: OAuthOptions): Promise<OAuthResult>;
|
|
593
|
+
handleOAuthCallback(code: string): Promise<AuthResult>;
|
|
594
|
+
signInWithMagicLink(options: SignInWithMagicLinkOptions): Promise<AuthResult>;
|
|
595
|
+
verifyMagicLink(token: string): Promise<AuthResult>;
|
|
596
|
+
signInWithPhone(options: SignInWithPhoneOptions): Promise<AuthResult>;
|
|
597
|
+
verifyPhoneOtp(options: VerifyPhoneOtpOptions): Promise<AuthResult>;
|
|
598
|
+
verifyEmail(token: string): Promise<AuthResult>;
|
|
599
|
+
resendVerification(email: string): Promise<AuthResult>;
|
|
600
|
+
listMfaFactors(): Promise<MfaFactor[]>;
|
|
601
|
+
enrollMfa(options: EnrollMfaOptions): Promise<EnrollMfaResult>;
|
|
602
|
+
verifyMfa(options: VerifyMfaOptions): Promise<AuthResult>;
|
|
603
|
+
unenrollMfa(factorId: string): Promise<void>;
|
|
604
|
+
createMfaChallenge(factorId: string): Promise<MfaChallenge>;
|
|
605
|
+
updateUser(options: UpdateUserOptions): Promise<AuthResult>;
|
|
606
|
+
deleteAccount(_options?: DeleteAccountOptions): Promise<AuthResult>;
|
|
607
|
+
reauthenticate(password: string): Promise<AuthResult>;
|
|
608
|
+
onAuthStateChange(callback: AuthStateChangeCallback): Unsubscribe;
|
|
609
|
+
healthCheck(): Promise<boolean>;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
export { type AuthUser as A, type DeleteAccountOptions as D, type EnrollMfaOptions as E, type IAuth as I, type MfaFactorType as M, type OAuthProvider as O, type ResetPasswordOptions as R, type SignInWithEmailOptions as S, type UpdatePasswordOptions as U, type VerifyPhoneOtpOptions as V, type AuthSession as a, type AuthError as b, type AuthResult as c, type AuthErrorCode as d, type SignUpWithEmailOptions as e, type OAuthOptions as f, type OAuthResult as g, type SignInWithPhoneOptions as h, type SignInWithMagicLinkOptions as i, type MfaFactor as j, type MfaChallenge as k, type EnrollMfaResult as l, type VerifyMfaOptions as m, type UpdateUserOptions as n, type AuthEventType as o, type AuthStateChangeCallback as p, type AuthConfig as q, type AuthStorage as r, createAuthError as s, isAuthError as t, AuthErrorMessages as u, generateSecureToken as v, MemoryAuth as w, SupabaseAuth as x, type SupabaseAuthConfig as y, type Unsubscribe as z };
|