JezK
Edit File: verification-00df9439.js.map
{"file":"verification-00df9439.js","mappings":"AAAA;;;AAaA;MACa,uBAAuB,GAAG,GAAG;AAE1C;MACa,YAAY,GAAG,CAAC,WAA2B;IACtD,IAAI,CAAC,WAAW;QAAE,OAAO,CAAC,CAAC;IAC3B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC;AACnE,EAAE;AAEF;;;;MAIa,0BAA0B,GAAG,CAAC,KAAU;;IACnD,MAAM,OAAO,GAAG,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,iBAAiB,KAAI,EAAE,EAAE,IAAI,CAAC,CAAC,CAAM,KAAK,CAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,IAAI,MAAK,2CAA2C,CAAC,CAAC;IAC3H,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,OAAO,0CAAE,OAAO,EAAE,EAAE,CAAC,CAAC;IAC9D,OAAO,OAAO,GAAG,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC;AACtC,EAAE;AAEF;;;;;;;;;;MAUa,gBAAgB,GAAG,CAAC,OAAuB;IACtD,MAAM,MAAM,GAAG,OAAO,IAAI,IAAI,GAAG,uBAAuB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAChF,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,GAAG,IAAI,CAAC;AACpC;;;;","names":[],"sources":["src/functions/verification.ts"],"sourcesContent":["/**\n * Verification code utility functions.\n */\n\n/** Response shape from POST surecart/v1/verification_codes. */\nexport interface VerificationCodeResponse {\n email?: string;\n /** False when an in-window request resumed an existing code instead of sending a new email. */\n email_sent?: boolean;\n resend_available_at?: number;\n resend_available_in?: number;\n}\n\n/** Fallback resend window (seconds) used when the platform doesn't provide one. */\nexport const RESEND_COOLDOWN_SECONDS = 60;\n\n/** Whole seconds from now until an absolute timestamp (ms); 0 if unset or already past. */\nexport const secondsUntil = (timestampMs?: number | null): number => {\n if (!timestampMs) return 0;\n return Math.max(0, Math.ceil((timestampMs - Date.now()) / 1000));\n};\n\n/**\n * The platform's resend backoff (in seconds) carried in a verification-code error.\n * Present on `blocked_duplicate` responses; returns null when absent or non-positive.\n */\nexport const getBlockedDuplicateSeconds = (error: any): number | null => {\n const blocked = (error?.additional_errors || []).find((e: any) => e?.code === 'verification_code.email.blocked_duplicate');\n const seconds = parseInt(blocked?.data?.options?.seconds, 10);\n return seconds > 0 ? seconds : null;\n};\n\n/**\n * Absolute ms timestamp when a resend becomes available, from a platform-provided\n * seconds value.\n *\n * - `null`/`undefined` means the window is unknown → fall back to the default so\n * callers always get a concrete anchor (never an unset cooldown).\n * - A numeric `0` (or negative) is a real \"available now\" signal (e.g. the window\n * lapsed by the time the request resolved) → anchor at now so the resend link\n * shows immediately instead of imposing another full cooldown.\n */\nexport const resendAnchorFrom = (seconds?: number | null): number => {\n const window = seconds == null ? RESEND_COOLDOWN_SECONDS : Math.max(0, seconds);\n return Date.now() + window * 1000;\n};\n"],"version":3}