binoauth 0.0.10 → 0.0.12

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.
Files changed (111) hide show
  1. package/README.md +359 -165
  2. package/dist/core/src/admin/client.d.ts +203 -0
  3. package/dist/core/src/admin/client.d.ts.map +1 -0
  4. package/dist/core/src/admin/client.js +391 -0
  5. package/dist/core/src/admin/client.js.map +1 -0
  6. package/dist/core/src/admin/index.d.ts +6 -0
  7. package/dist/core/src/admin/index.d.ts.map +1 -0
  8. package/dist/core/src/admin/index.js +5 -0
  9. package/dist/core/src/admin/index.js.map +1 -0
  10. package/dist/core/src/admin/types.d.ts +412 -0
  11. package/dist/core/src/admin/types.d.ts.map +1 -0
  12. package/dist/core/src/admin/types.js +5 -0
  13. package/dist/core/src/admin/types.js.map +1 -0
  14. package/dist/core/src/auth/client.d.ts +330 -0
  15. package/dist/core/src/auth/client.d.ts.map +1 -0
  16. package/dist/core/src/auth/client.js +408 -0
  17. package/dist/core/src/auth/client.js.map +1 -0
  18. package/dist/core/src/auth/error.d.ts +113 -0
  19. package/dist/core/src/auth/error.d.ts.map +1 -0
  20. package/dist/core/src/auth/error.js +257 -0
  21. package/dist/core/src/auth/error.js.map +1 -0
  22. package/dist/core/src/auth/flows/base-flow.d.ts +98 -0
  23. package/dist/core/src/auth/flows/base-flow.d.ts.map +1 -0
  24. package/dist/core/src/auth/flows/base-flow.js +182 -0
  25. package/dist/core/src/auth/flows/base-flow.js.map +1 -0
  26. package/dist/core/src/auth/flows/magic-link.d.ts +175 -0
  27. package/dist/core/src/auth/flows/magic-link.d.ts.map +1 -0
  28. package/dist/core/src/auth/flows/magic-link.js +228 -0
  29. package/dist/core/src/auth/flows/magic-link.js.map +1 -0
  30. package/dist/core/src/auth/flows/mfa.d.ts +81 -0
  31. package/dist/core/src/auth/flows/mfa.d.ts.map +1 -0
  32. package/dist/core/src/auth/flows/mfa.js +103 -0
  33. package/dist/core/src/auth/flows/mfa.js.map +1 -0
  34. package/dist/core/src/auth/flows/otp.d.ts +172 -0
  35. package/dist/core/src/auth/flows/otp.d.ts.map +1 -0
  36. package/dist/core/src/auth/flows/otp.js +222 -0
  37. package/dist/core/src/auth/flows/otp.js.map +1 -0
  38. package/dist/core/src/auth/flows/password.d.ts +242 -0
  39. package/dist/core/src/auth/flows/password.d.ts.map +1 -0
  40. package/dist/core/src/auth/flows/password.js +344 -0
  41. package/dist/core/src/auth/flows/password.js.map +1 -0
  42. package/dist/core/src/auth/flows/social.d.ts +209 -0
  43. package/dist/core/src/auth/flows/social.d.ts.map +1 -0
  44. package/dist/core/src/auth/flows/social.js +284 -0
  45. package/dist/core/src/auth/flows/social.js.map +1 -0
  46. package/dist/core/src/auth/index.d.ts +19 -0
  47. package/dist/core/src/auth/index.d.ts.map +1 -0
  48. package/dist/core/src/auth/index.js +32 -0
  49. package/dist/core/src/auth/index.js.map +1 -0
  50. package/dist/core/src/auth/types.d.ts +151 -0
  51. package/dist/core/src/auth/types.d.ts.map +1 -0
  52. package/dist/core/src/auth/types.js +7 -0
  53. package/dist/core/src/auth/types.js.map +1 -0
  54. package/dist/core/src/index.d.ts +53 -49
  55. package/dist/core/src/index.d.ts.map +1 -1
  56. package/dist/core/src/index.js +61 -343
  57. package/dist/core/src/index.js.map +1 -1
  58. package/dist/core/src/oauth/client.d.ts +322 -0
  59. package/dist/core/src/oauth/client.d.ts.map +1 -0
  60. package/dist/core/src/oauth/client.js +491 -0
  61. package/dist/core/src/oauth/client.js.map +1 -0
  62. package/dist/core/src/oauth/error.d.ts +18 -0
  63. package/dist/core/src/oauth/error.d.ts.map +1 -0
  64. package/dist/core/src/oauth/error.js +24 -0
  65. package/dist/core/src/oauth/error.js.map +1 -0
  66. package/dist/core/src/oauth/flows/authorization-code.d.ts +122 -0
  67. package/dist/core/src/oauth/flows/authorization-code.d.ts.map +1 -0
  68. package/dist/core/src/oauth/flows/authorization-code.js +278 -0
  69. package/dist/core/src/oauth/flows/authorization-code.js.map +1 -0
  70. package/dist/core/src/oauth/flows/base-flow.d.ts +17 -0
  71. package/dist/core/src/oauth/flows/base-flow.d.ts.map +1 -0
  72. package/dist/core/src/oauth/flows/base-flow.js +107 -0
  73. package/dist/core/src/oauth/flows/base-flow.js.map +1 -0
  74. package/dist/core/src/oauth/flows/client-credentials.d.ts +72 -0
  75. package/dist/core/src/oauth/flows/client-credentials.d.ts.map +1 -0
  76. package/dist/core/src/oauth/flows/client-credentials.js +100 -0
  77. package/dist/core/src/oauth/flows/client-credentials.js.map +1 -0
  78. package/dist/core/src/oauth/flows/device-code.d.ts +108 -0
  79. package/dist/core/src/oauth/flows/device-code.d.ts.map +1 -0
  80. package/dist/core/src/oauth/flows/device-code.js +193 -0
  81. package/dist/core/src/oauth/flows/device-code.js.map +1 -0
  82. package/dist/core/src/oauth/flows/refresh-token.d.ts +59 -0
  83. package/dist/core/src/oauth/flows/refresh-token.d.ts.map +1 -0
  84. package/dist/core/src/oauth/flows/refresh-token.js +105 -0
  85. package/dist/core/src/oauth/flows/refresh-token.js.map +1 -0
  86. package/dist/core/src/oauth/index.d.ts +12 -0
  87. package/dist/core/src/oauth/index.d.ts.map +1 -0
  88. package/dist/core/src/oauth/index.js +11 -0
  89. package/dist/core/src/oauth/index.js.map +1 -0
  90. package/dist/core/src/oauth/storage/encryption.d.ts +12 -0
  91. package/dist/core/src/oauth/storage/encryption.d.ts.map +1 -0
  92. package/dist/core/src/oauth/storage/encryption.js +76 -0
  93. package/dist/core/src/oauth/storage/encryption.js.map +1 -0
  94. package/dist/core/src/oauth/storage/index.d.ts +201 -0
  95. package/dist/core/src/oauth/storage/index.d.ts.map +1 -0
  96. package/dist/core/src/oauth/storage/index.js +322 -0
  97. package/dist/core/src/oauth/storage/index.js.map +1 -0
  98. package/dist/core/src/oauth/storage/strategies.d.ts +34 -0
  99. package/dist/core/src/oauth/storage/strategies.d.ts.map +1 -0
  100. package/dist/core/src/oauth/storage/strategies.js +100 -0
  101. package/dist/core/src/oauth/storage/strategies.js.map +1 -0
  102. package/dist/core/src/oauth/types.d.ts +261 -0
  103. package/dist/core/src/oauth/types.d.ts.map +1 -0
  104. package/dist/core/src/oauth/types.js +39 -0
  105. package/dist/core/src/oauth/types.js.map +1 -0
  106. package/dist/core/src/oauth/utils.d.ts +56 -0
  107. package/dist/core/src/oauth/utils.d.ts.map +1 -0
  108. package/dist/core/src/oauth/utils.js +140 -0
  109. package/dist/core/src/oauth/utils.js.map +1 -0
  110. package/dist/tsconfig.tsbuildinfo +1 -1
  111. package/package.json +1 -1
@@ -0,0 +1,408 @@
1
+ /**
2
+ * Unified BinoAuth authentication client
3
+ *
4
+ * Provides a single interface for all authentication methods including
5
+ * OAuth, password, magic link, OTP, MFA, and social authentication.
6
+ */
7
+ import { AuthError, AuthErrorCode } from "./error";
8
+ import { BinoAuthOAuth } from "../oauth/client";
9
+ import { PasswordFlow } from "./flows/password";
10
+ import { MagicLinkFlow } from "./flows/magic-link";
11
+ import { OTPFlow } from "./flows/otp";
12
+ import { MFAFlow } from "./flows/mfa";
13
+ import { SocialFlow } from "./flows/social";
14
+ /**
15
+ * Unified BinoAuth authentication client
16
+ *
17
+ * Provides a comprehensive authentication solution with multiple flows
18
+ * and methods. This is the main entry point for most authentication needs.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * import { BinoAuthClient } from 'binoauth';
23
+ *
24
+ * const auth = new BinoAuthClient({
25
+ * issuer: 'https://auth.binoauth.com',
26
+ * clientId: 'your_client_id',
27
+ * redirectUri: 'https://yourapp.com/callback',
28
+ * apiKey: 'your_api_key'
29
+ * });
30
+ *
31
+ * // Password authentication
32
+ * const result = await auth.loginWithPassword('user@example.com', 'password123');
33
+ *
34
+ * // Magic link authentication
35
+ * await auth.sendMagicLink('user@example.com', 'https://yourapp.com/dashboard');
36
+ *
37
+ * // OAuth authentication
38
+ * const oauthUrl = await auth.getOAuthLoginUrl();
39
+ * window.location.href = oauthUrl;
40
+ *
41
+ * // Social authentication
42
+ * const googleUrl = await auth.getSocialLoginUrl('google');
43
+ * window.location.href = googleUrl;
44
+ * ```
45
+ */
46
+ export class BinoAuthClient {
47
+ config;
48
+ // Individual flow instances
49
+ oauth;
50
+ password;
51
+ magicLink;
52
+ otp;
53
+ mfa;
54
+ social;
55
+ /**
56
+ * Creates a new BinoAuth client instance
57
+ *
58
+ * @param config - BinoAuth configuration
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * // Minimal configuration
63
+ * const auth = new BinoAuthClient({
64
+ * issuer: 'https://auth.binoauth.com',
65
+ * clientId: 'your_client_id'
66
+ * });
67
+ *
68
+ * // Full configuration
69
+ * const auth = new BinoAuthClient({
70
+ * issuer: 'https://auth.binoauth.com',
71
+ * clientId: 'your_client_id',
72
+ * redirectUri: 'https://yourapp.com/callback',
73
+ * scope: 'openid profile email',
74
+ * apiKey: 'your_api_key',
75
+ * tenant: 'your_tenant_id',
76
+ * enableMFA: true
77
+ * });
78
+ * ```
79
+ */
80
+ constructor(config) {
81
+ this.config = config;
82
+ this.validateConfig();
83
+ // Initialize OAuth client
84
+ this.oauth = new BinoAuthOAuth({
85
+ issuer: config.issuer || config.baseUrl || 'https://auth.binoauth.com',
86
+ clientId: config.clientId,
87
+ redirectUri: config.redirectUri || 'http://localhost:3000/callback',
88
+ scope: config.scope,
89
+ clientSecret: config.clientSecret,
90
+ }, {
91
+ storage: 'localStorage',
92
+ encryptionKey: this.generateEncryptionKey(),
93
+ clientId: config.clientId,
94
+ });
95
+ // Initialize authentication flows
96
+ this.password = new PasswordFlow(config);
97
+ this.magicLink = new MagicLinkFlow(config);
98
+ this.otp = new OTPFlow(config);
99
+ this.mfa = new MFAFlow(config);
100
+ this.social = new SocialFlow(config);
101
+ }
102
+ /**
103
+ * Validates the client configuration
104
+ *
105
+ * @throws {AuthError} When configuration is invalid
106
+ */
107
+ validateConfig() {
108
+ if (!this.config.issuer && !this.config.baseUrl) {
109
+ throw new AuthError(AuthErrorCode.INVALID_CONFIG, 'Either issuer or baseUrl must be provided');
110
+ }
111
+ if (!this.config.clientId) {
112
+ throw new AuthError(AuthErrorCode.INVALID_CONFIG, 'clientId is required');
113
+ }
114
+ }
115
+ /**
116
+ * Generates a default encryption key for token storage
117
+ *
118
+ * @returns Encryption key
119
+ */
120
+ generateEncryptionKey() {
121
+ // In production, this should be provided by the user or generated securely
122
+ return `binoauth_${this.config.clientId}_${this.config.issuer || this.config.baseUrl}`.substring(0, 32).padEnd(32, '0');
123
+ }
124
+ // Convenience methods for common authentication patterns
125
+ /**
126
+ * Authenticates a user with email and password
127
+ *
128
+ * @param email - User's email address
129
+ * @param password - User's password
130
+ * @param rememberMe - Whether to remember the user
131
+ * @returns Promise resolving to authentication result
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * try {
136
+ * const result = await auth.loginWithPassword(
137
+ * 'user@example.com',
138
+ * 'password123',
139
+ * true // remember me
140
+ * );
141
+ *
142
+ * if (result.success) {
143
+ * console.log('Login successful:', result.user);
144
+ * }
145
+ * } catch (error) {
146
+ * if (error.code === AuthErrorCode.MFA_REQUIRED) {
147
+ * // Handle MFA challenge
148
+ * const challenge = error.details.mfaChallenge;
149
+ * await auth.sendMFAChallenge(challenge.challengeId, 'sms');
150
+ * }
151
+ * }
152
+ * ```
153
+ */
154
+ async loginWithPassword(email, password, rememberMe) {
155
+ return this.password.login(email, password, rememberMe);
156
+ }
157
+ /**
158
+ * Authenticates a user with credentials object
159
+ *
160
+ * @param credentials - Login credentials
161
+ * @returns Promise resolving to authentication result
162
+ */
163
+ async loginWithCredentials(credentials) {
164
+ return this.password.loginWithCredentials(credentials);
165
+ }
166
+ /**
167
+ * Registers a new user account
168
+ *
169
+ * @param userData - User registration data
170
+ * @returns Promise resolving to authentication result
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * const result = await auth.register({
175
+ * email: 'newuser@example.com',
176
+ * password: 'securepassword123',
177
+ * name: 'John Doe',
178
+ * acceptTerms: true
179
+ * });
180
+ * ```
181
+ */
182
+ async register(userData) {
183
+ return this.password.register(userData);
184
+ }
185
+ /**
186
+ * Sends a magic link to the user's email
187
+ *
188
+ * @param email - User's email address
189
+ * @param returnTo - URL to redirect to after authentication
190
+ * @returns Promise resolving when magic link is sent
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * await auth.sendMagicLink('user@example.com', 'https://myapp.com/dashboard');
195
+ * console.log('Magic link sent! Check your email.');
196
+ * ```
197
+ */
198
+ async sendMagicLink(email, returnTo) {
199
+ return this.magicLink.sendMagicLinkToEmail(email, returnTo || 'http://localhost:3000/callback');
200
+ }
201
+ /**
202
+ * Verifies a magic link token
203
+ *
204
+ * @param token - Magic link token
205
+ * @returns Promise resolving to authentication result
206
+ */
207
+ async verifyMagicLink(token) {
208
+ return this.magicLink.verifyMagicLink(token);
209
+ }
210
+ /**
211
+ * Sends an OTP to the user's email
212
+ *
213
+ * @param email - User's email address
214
+ * @returns Promise resolving when OTP is sent
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * await auth.sendEmailOTP('user@example.com');
219
+ * console.log('Verification code sent to your email');
220
+ * ```
221
+ */
222
+ /**
223
+ * Note: Email OTP is not supported. Use sendPhoneOTP instead.
224
+ * @deprecated Use sendPhoneOTP for SMS OTP
225
+ */
226
+ async sendEmailOTP(email) {
227
+ throw new AuthError(AuthErrorCode.INVALID_CONFIG, 'Email OTP is not supported. Use sendPhoneOTP for SMS OTP instead.');
228
+ }
229
+ /**
230
+ * Sends an OTP to the user's phone
231
+ *
232
+ * @param phone - User's phone number
233
+ * @returns Promise resolving when OTP is sent
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * await auth.sendPhoneOTP('+1234567890');
238
+ * console.log('Verification code sent to your phone');
239
+ * ```
240
+ */
241
+ async sendPhoneOTP(phone) {
242
+ return this.otp.sendPhoneOTP(phone);
243
+ }
244
+ /**
245
+ * Verifies an OTP code
246
+ *
247
+ * @param code - OTP code
248
+ * @param method - OTP method ('email' or 'sms')
249
+ * @returns Promise resolving to authentication result
250
+ *
251
+ * @example
252
+ * ```typescript
253
+ * const result = await auth.verifyOTP('123456', 'email');
254
+ * if (result.success) {
255
+ * console.log('OTP verification successful');
256
+ * }
257
+ * ```
258
+ */
259
+ async verifyOTP(code) {
260
+ return this.otp.verifyPhoneOTP(code);
261
+ }
262
+ /**
263
+ * Gets the OAuth authorization URL
264
+ *
265
+ * @returns Promise resolving to authorization URL
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * const oauthUrl = await auth.getOAuthLoginUrl();
270
+ * window.location.href = oauthUrl;
271
+ * ```
272
+ */
273
+ async getOAuthLoginUrl() {
274
+ return this.oauth.getLoginUrl();
275
+ }
276
+ /**
277
+ * Handles OAuth callback
278
+ *
279
+ * @param code - Authorization code
280
+ * @param state - State parameter
281
+ * @returns Promise resolving when callback is handled
282
+ */
283
+ async handleOAuthCallback(code, state) {
284
+ return this.oauth.handleCallback(code, state);
285
+ }
286
+ /**
287
+ * Gets social login URL for a provider
288
+ *
289
+ * @param provider - Social provider
290
+ * @param request - Optional social auth request
291
+ * @returns Promise resolving to authorization URL
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * const googleUrl = await auth.getSocialLoginUrl('google', {
296
+ * returnTo: 'https://myapp.com/dashboard'
297
+ * });
298
+ * window.location.href = googleUrl;
299
+ * ```
300
+ */
301
+ async getSocialLoginUrl(provider, returnTo, redirectUri) {
302
+ return this.social.getAuthUrl(provider, returnTo, redirectUri);
303
+ }
304
+ /**
305
+ * Handles social authentication callback
306
+ *
307
+ * @param provider - Social provider
308
+ * @param code - Authorization code
309
+ * @param state - State parameter
310
+ * @returns Promise resolving to authentication result
311
+ */
312
+ async handleSocialCallback(provider, code, state, link) {
313
+ return this.social.handleCallback(provider, code, state, link);
314
+ }
315
+ /**
316
+ * Sends an MFA challenge
317
+ *
318
+ * @param challengeId - MFA challenge ID
319
+ * @param method - MFA method
320
+ * @returns Promise resolving when challenge is sent
321
+ */
322
+ /**
323
+ * Note: MFA challenge sending is not available in current tenant-sdk.
324
+ * @deprecated Use verifyMFA instead
325
+ */
326
+ async sendMFAChallenge(challengeId, method) {
327
+ throw new AuthError(AuthErrorCode.INVALID_CONFIG, 'MFA challenge sending is not supported. Use verifyMFA for verification.');
328
+ }
329
+ /**
330
+ * Verifies an MFA challenge
331
+ *
332
+ * @param challengeId - MFA challenge ID
333
+ * @param code - Verification code
334
+ * @param method - MFA method
335
+ * @returns Promise resolving to authentication result
336
+ */
337
+ async verifyMFA(code, sessionId) {
338
+ return this.mfa.verifyMFA(code, sessionId);
339
+ }
340
+ /**
341
+ * Requests password reset
342
+ *
343
+ * @param request - Password reset request
344
+ * @returns Promise resolving when reset request is sent
345
+ */
346
+ async requestPasswordReset(request) {
347
+ return this.password.requestPasswordReset(request);
348
+ }
349
+ /**
350
+ * Resets password with token
351
+ *
352
+ * @param resetData - Password reset data
353
+ * @returns Promise resolving to authentication result
354
+ */
355
+ async resetPassword(resetData) {
356
+ return this.password.resetPassword(resetData);
357
+ }
358
+ /**
359
+ * Gets current access token
360
+ *
361
+ * @returns Promise resolving to access token or null
362
+ */
363
+ async getAccessToken() {
364
+ return this.oauth.getAccessToken();
365
+ }
366
+ /**
367
+ * Checks if user is authenticated
368
+ *
369
+ * @returns Promise resolving to authentication status
370
+ */
371
+ async isAuthenticated() {
372
+ return this.oauth.isAuthenticated();
373
+ }
374
+ /**
375
+ * Gets current user information
376
+ *
377
+ * @returns Promise resolving to user info or null
378
+ */
379
+ async getUserInfo() {
380
+ const userInfo = await this.oauth.getUserInfo();
381
+ return userInfo;
382
+ }
383
+ /**
384
+ * Refreshes access tokens
385
+ *
386
+ * @returns Promise resolving when tokens are refreshed
387
+ */
388
+ async refreshTokens() {
389
+ return this.oauth.refreshTokens();
390
+ }
391
+ /**
392
+ * Logs out the user
393
+ *
394
+ * @returns Promise resolving when logout is complete
395
+ */
396
+ async logout() {
397
+ return this.oauth.logout();
398
+ }
399
+ /**
400
+ * Gets logout URL
401
+ *
402
+ * @returns Promise resolving to logout URL
403
+ */
404
+ async getLogoutUrl() {
405
+ return this.oauth.getLogoutUrl();
406
+ }
407
+ }
408
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../src/auth/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiBH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,OAAO,cAAc;IAkCL;IAjCpB,4BAA4B;IACZ,KAAK,CAAgB;IACrB,QAAQ,CAAe;IACvB,SAAS,CAAgB;IACzB,GAAG,CAAU;IACb,GAAG,CAAU;IACb,MAAM,CAAa;IAEnC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,YAAoB,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;QACxC,IAAI,CAAC,cAAc,EAAE,CAAC;QAEtB,0BAA0B;QAC1B,IAAI,CAAC,KAAK,GAAG,IAAI,aAAa,CAAC;YAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,OAAO,IAAI,2BAA2B;YACtE,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,gCAAgC;YACnE,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,YAAY,EAAE,MAAM,CAAC,YAAY;SAClC,EAAE;YACD,OAAO,EAAE,cAAc;YACvB,aAAa,EAAE,IAAI,CAAC,qBAAqB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,EAAE,CAAC;IACrC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW;QACf,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QAChD,OAAO,QAAuB,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,aAAa;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;IACnC,CAAC;CACF"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Authentication error codes and error handling
3
+ */
4
+ /**
5
+ * Authentication error codes
6
+ *
7
+ * Standardized error codes for different authentication scenarios.
8
+ */
9
+ export declare enum AuthErrorCode {
10
+ INVALID_CREDENTIALS = "INVALID_CREDENTIALS",
11
+ INVALID_EMAIL = "INVALID_EMAIL",
12
+ INVALID_PASSWORD = "INVALID_PASSWORD",
13
+ INVALID_OTP = "INVALID_OTP",
14
+ EXPIRED_OTP = "EXPIRED_OTP",
15
+ INVALID_TOKEN = "INVALID_TOKEN",
16
+ EXPIRED_TOKEN = "EXPIRED_TOKEN",
17
+ ACCOUNT_NOT_FOUND = "ACCOUNT_NOT_FOUND",
18
+ ACCOUNT_LOCKED = "ACCOUNT_LOCKED",
19
+ ACCOUNT_DISABLED = "ACCOUNT_DISABLED",
20
+ EMAIL_NOT_VERIFIED = "EMAIL_NOT_VERIFIED",
21
+ PHONE_NOT_VERIFIED = "PHONE_NOT_VERIFIED",
22
+ MFA_REQUIRED = "MFA_REQUIRED",
23
+ MFA_INVALID_METHOD = "MFA_INVALID_METHOD",
24
+ MFA_CHALLENGE_EXPIRED = "MFA_CHALLENGE_EXPIRED",
25
+ TOO_MANY_ATTEMPTS = "TOO_MANY_ATTEMPTS",
26
+ RATE_LIMITED = "RATE_LIMITED",
27
+ EMAIL_ALREADY_EXISTS = "EMAIL_ALREADY_EXISTS",
28
+ PHONE_ALREADY_EXISTS = "PHONE_ALREADY_EXISTS",
29
+ WEAK_PASSWORD = "WEAK_PASSWORD",
30
+ TERMS_NOT_ACCEPTED = "TERMS_NOT_ACCEPTED",
31
+ NETWORK_ERROR = "NETWORK_ERROR",
32
+ SERVER_ERROR = "SERVER_ERROR",
33
+ INVALID_CONFIG = "INVALID_CONFIG",
34
+ MISSING_REQUIRED_FIELD = "MISSING_REQUIRED_FIELD",
35
+ OAUTH_ERROR = "OAUTH_ERROR",
36
+ INVALID_GRANT = "INVALID_GRANT",
37
+ INVALID_CLIENT = "INVALID_CLIENT",
38
+ INVALID_SCOPE = "INVALID_SCOPE",
39
+ UNKNOWN_ERROR = "UNKNOWN_ERROR"
40
+ }
41
+ /**
42
+ * Authentication error class
43
+ *
44
+ * Provides structured error information for authentication failures.
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * try {
49
+ * await authClient.login(email, password);
50
+ * } catch (error) {
51
+ * if (error instanceof AuthError) {
52
+ * switch (error.code) {
53
+ * case AuthErrorCode.INVALID_CREDENTIALS:
54
+ * console.log('Invalid email or password');
55
+ * break;
56
+ * case AuthErrorCode.MFA_REQUIRED:
57
+ * console.log('MFA required:', error.details);
58
+ * break;
59
+ * default:
60
+ * console.log('Auth error:', error.message);
61
+ * }
62
+ * }
63
+ * }
64
+ * ```
65
+ */
66
+ export declare class AuthError extends Error {
67
+ readonly code: AuthErrorCode;
68
+ readonly details?: any | undefined;
69
+ readonly originalError?: Error | undefined;
70
+ /**
71
+ * Creates a new authentication error
72
+ *
73
+ * @param code - Standardized error code
74
+ * @param message - Human-readable error message
75
+ * @param details - Additional error details
76
+ * @param originalError - Original error that caused this error
77
+ */
78
+ constructor(code: AuthErrorCode, message: string, details?: any | undefined, originalError?: Error | undefined);
79
+ /**
80
+ * Creates an AuthError from an unknown error
81
+ *
82
+ * @param error - Unknown error object
83
+ * @param defaultCode - Default error code if none can be determined
84
+ * @returns AuthError instance
85
+ */
86
+ static fromError(error: any, defaultCode?: AuthErrorCode): AuthError;
87
+ /**
88
+ * Converts the error to a JSON-serializable object
89
+ *
90
+ * @returns Plain object representation of the error
91
+ */
92
+ toJSON(): {
93
+ name: string;
94
+ code: AuthErrorCode;
95
+ message: string;
96
+ details: any;
97
+ stack: string | undefined;
98
+ };
99
+ }
100
+ /**
101
+ * Creates user-friendly error messages for error codes
102
+ *
103
+ * @param code - Error code
104
+ * @returns User-friendly error message
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const message = getErrorMessage(AuthErrorCode.INVALID_CREDENTIALS);
109
+ * console.log(message); // "Invalid email or password"
110
+ * ```
111
+ */
112
+ export declare function getErrorMessage(code: AuthErrorCode): string;
113
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../../src/auth/error.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,oBAAY,aAAa;IAEvB,mBAAmB,wBAAwB;IAC3C,aAAa,kBAAkB;IAC/B,gBAAgB,qBAAqB;IACrC,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;IAC3B,aAAa,kBAAkB;IAC/B,aAAa,kBAAkB;IAG/B,iBAAiB,sBAAsB;IACvC,cAAc,mBAAmB;IACjC,gBAAgB,qBAAqB;IACrC,kBAAkB,uBAAuB;IACzC,kBAAkB,uBAAuB;IAGzC,YAAY,iBAAiB;IAC7B,kBAAkB,uBAAuB;IACzC,qBAAqB,0BAA0B;IAG/C,iBAAiB,sBAAsB;IACvC,YAAY,iBAAiB;IAG7B,oBAAoB,yBAAyB;IAC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