@donotdev/auth 0.0.14 → 0.0.16

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.
@@ -1,52 +0,0 @@
1
- import { type AuthResult, type AuthPartnerId } from '@donotdev/core';
2
- import { type AuthMethod } from './constants';
3
- /**
4
- * Context information for smart recovery
5
- *
6
- * @version 0.0.1
7
- * @since 0.0.1
8
- * @author AMBROISE PARK Consulting
9
- */
10
- export interface SmartRecoveryContext {
11
- email?: string;
12
- partnerId?: AuthPartnerId;
13
- method?: AuthMethod;
14
- }
15
- /**
16
- * Dependencies required for smart recovery
17
- *
18
- * @version 0.0.1
19
- * @since 0.0.1
20
- * @author AMBROISE PARK Consulting
21
- */
22
- export interface SmartRecoveryDependencies {
23
- sdk: any;
24
- handleAccountLinking: (error: any, attemptedProvider: AuthPartnerId, method: AuthMethod) => Promise<AuthResult | null>;
25
- createAuthResult: (user: any, isNewUser?: boolean) => AuthResult;
26
- }
27
- /**
28
- * Centralized smart recovery handler
29
- *
30
- * Handles all Firebase error scenarios with appropriate recovery strategies.
31
- * Wraps unrecoverable errors with handleError() before throwing.
32
- *
33
- * **Recovery Strategies:**
34
- * - Network issues: Linear backoff (1s, 2s, 3s)
35
- * - Rate limiting: Exponential backoff (2s, 4s, 8s)
36
- * - Internal errors: Simple retry with 2s delay
37
- * - Account linking: Delegate to account linking handler
38
- * - User cancellation: Return null (not an error)
39
- *
40
- * @param error - Firebase error object
41
- * @param operation - Operation to retry
42
- * @param context - Context information for recovery
43
- * @param deps - Dependencies for recovery operations
44
- * @returns Auth result or null if user cancelled
45
- * @throws DoNotDevError if recovery fails
46
- *
47
- * @version 0.0.1
48
- * @since 0.0.1
49
- * @author AMBROISE PARK Consulting
50
- */
51
- export declare function handleSmartRecovery(error: any, operation: () => Promise<any>, context: SmartRecoveryContext, deps: SmartRecoveryDependencies): Promise<AuthResult | null>;
52
- //# sourceMappingURL=FirebaseSmartRecovery.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FirebaseSmartRecovery.d.ts","sourceRoot":"","sources":["../src/FirebaseSmartRecovery.ts"],"names":[],"mappings":"AAYA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE7D;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACxC,GAAG,EAAE,GAAG,CAAC;IACT,oBAAoB,EAAE,CACpB,KAAK,EAAE,GAAG,EACV,iBAAiB,EAAE,aAAa,EAChC,MAAM,EAAE,UAAU,KACf,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAChC,gBAAgB,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,OAAO,KAAK,UAAU,CAAC;CAClE;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,GAAG,EACV,SAAS,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EAC7B,OAAO,EAAE,oBAAoB,EAC7B,IAAI,EAAE,yBAAyB,GAC9B,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAkF5B"}
@@ -1 +0,0 @@
1
- import{toast as c}from"@donotdev/components";import{handleError as s,isDev as u}from"@donotdev/core";import{getAuthMethod as d}from"./constants";async function l(e,o,r,a){if(e.code==="auth/network-request-failed"){c("info","Connection issue - retrying...");try{return await h(o,a)}catch(t){throw s(t,{userMessage:"Network connection failed. Please check your internet and try again.",context:{operation:"network-retry",originalError:e.code},showNotification:!0})}}if(e.code==="auth/too-many-requests"){c("info","Rate limited - retrying with backoff...");try{return await w(o,a)}catch(t){throw s(t,{userMessage:"Too many attempts. Please wait a moment and try again.",context:{operation:"rate-limit-retry",originalError:e.code},showNotification:!0})}}if(e.code==="auth/internal-error"){c("info","Temporary issue - retrying...");try{return await p(o,a)}catch(t){throw s(t,{userMessage:"A temporary error occurred. Please try again.",context:{operation:"internal-error-retry",originalError:e.code},showNotification:!0})}}if(e.code==="auth/account-exists-with-different-credential")try{return await a.handleAccountLinking(e,r.partnerId,r.method?d(r.method):d())}catch(t){throw s(t,{userMessage:"Failed to link accounts. Please try again.",context:{operation:"account-linking",originalError:e.code},showNotification:!0})}if(e.code==="auth/popup-closed-by-user"||e.code==="auth/cancelled-popup-request"||e.code==="auth/popup-blocked"||e.message?.includes("popup")||e.message?.includes("cancelled")||e.message?.includes("closed"))return null;throw s(e,{userMessage:f(e.code),context:{operation:"smart-recovery",errorCode:e.code},showNotification:!0})}async function h(e,o,r=3){for(let a=1;a<=r;a++)try{const t=await e();return o.createAuthResult(t.user)}catch(t){if(a===r||t.code!=="auth/network-request-failed")throw t;const i=a*1e3;u(),await new Promise(n=>setTimeout(n,i))}throw new Error("Max retries exceeded")}async function w(e,o,r=3){for(let a=1;a<=r;a++)try{const t=await e();return o.createAuthResult(t.user)}catch(t){if(a===r||t.code!=="auth/too-many-requests")throw t;const i=Math.pow(2,a)*1e3;u(),await new Promise(n=>setTimeout(n,i))}throw new Error("Max retries exceeded")}async function p(e,o,r=2){for(let a=1;a<=r;a++)try{const t=await e();return o.createAuthResult(t.user)}catch(t){if(a===r||t.code!=="auth/internal-error")throw t;const i=2e3;u(),await new Promise(n=>setTimeout(n,i))}throw new Error("Max retries exceeded")}function f(e){return{"auth/invalid-email":"Invalid email address","auth/user-disabled":"This account has been disabled","auth/user-not-found":"No account found with this email","auth/wrong-password":"Incorrect password","auth/email-already-in-use":"An account already exists with this email","auth/weak-password":"Password is too weak","auth/operation-not-allowed":"This sign-in method is not enabled","auth/invalid-credential":"Invalid credentials provided","auth/invalid-verification-code":"Invalid verification code","auth/invalid-verification-id":"Invalid verification ID","auth/expired-action-code":"This link has expired","auth/invalid-action-code":"Invalid or expired link","auth/credential-already-in-use":"This credential is already associated with another account","auth/requires-recent-login":"Please sign in again to continue","auth/popup-blocked":"Popup was blocked by your browser. Please allow popups and try again."}[e]||"An authentication error occurred"}export{l as handleSmartRecovery};