@reblu/site-next 1.1.0 → 1.2.1

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auth/login-form.tsx","../src/auth/safe-redirect.ts","../src/auth/auth-callback.tsx","../src/auth/login-errors.ts","../src/auth/auth-logo.tsx","../src/auth/reset-password-request.tsx","../src/auth/reset-password-confirm.tsx","../src/auth/set-password.tsx","../src/auth/auth-confirm.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { Button, Input, cn } from '@reblu/site-ui'\nimport { Label } from '@reblu/site-ui/label'\nimport { Tabs, TabsList, TabsTrigger, TabsContent } from '@reblu/site-ui/tabs'\nimport { isSafeRedirectUrl } from './safe-redirect'\n\nexport interface LoginFormCopy {\n // Tab labels\n magicLinkTabLabel: string\n passwordTabLabel: string\n\n // Shared\n emailLabel: string\n emailPlaceholder: string\n\n // Password tab\n passwordLabel: string\n passwordPlaceholder: string\n passwordSubmitCta: string\n forgotPasswordCta: string\n\n // Magic-link tab\n magicLinkSubmitCta: string\n\n // Magic-link success\n magicLinkSuccessTitle: string\n magicLinkSuccessMessage: string\n\n // MFA prompt\n mfaTitle: string\n mfaMessage: string\n mfaCodeLabel: string\n mfaCodePlaceholder: string\n mfaSubmitCta: string\n\n // Errors\n invalidEmailError: string\n networkError: string\n invalidCredentialsError: string\n mfaInvalidCodeError: string\n}\n\nexport interface LoginFormProps {\n // Endpoint URLs (all required)\n passwordLoginUrl: string\n mfaVerifyUrl: string\n magicLinkRequestUrl: string\n resetPasswordUrl: string\n\n // UX\n copy?: Partial<LoginFormCopy>\n className?: string\n defaultMethod?: 'magic-link' | 'password'\n\n // Hooks\n onPasswordSubmitted?: (email: string) => void\n onMagicLinkSubmitted?: (email: string) => void\n onMfaSubmitted?: () => void\n}\n\nconst DEFAULT_COPY: LoginFormCopy = {\n magicLinkTabLabel: 'Enlace mágico',\n passwordTabLabel: 'Contraseña',\n emailLabel: 'Correo electrónico',\n emailPlaceholder: 'tu@email.com',\n passwordLabel: 'Contraseña',\n passwordPlaceholder: '••••••••',\n passwordSubmitCta: 'Iniciar sesión',\n forgotPasswordCta: '¿Olvidaste tu contraseña?',\n magicLinkSubmitCta: 'Enviar enlace de acceso',\n magicLinkSuccessTitle: '¡Enlace enviado!',\n magicLinkSuccessMessage: 'Revisa tu correo para acceder.',\n mfaTitle: 'Verificación en dos pasos',\n mfaMessage: 'Introduce el código de 6 dígitos de tu aplicación autenticadora.',\n mfaCodeLabel: 'Código de verificación',\n mfaCodePlaceholder: '123456',\n mfaSubmitCta: 'Verificar código',\n invalidEmailError: 'Introduce un correo electrónico válido.',\n networkError: 'No se pudo enviar el enlace. Inténtalo de nuevo.',\n invalidCredentialsError: 'Email o contraseña incorrectos',\n mfaInvalidCodeError: 'Código incorrecto. Por favor, inténtalo de nuevo.',\n}\n\nconst EMAIL_REGEX = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n\nfunction isValidEmail(value: string): boolean {\n return EMAIL_REGEX.test(value)\n}\n\ntype FormState = 'idle' | 'submitting' | 'magic-link-success' | 'mfa-required' | 'error'\n\ninterface MfaState {\n factorId: string\n accessToken: string\n refreshToken: string\n}\n\ninterface PasswordLoginResponse {\n data?: {\n mfaRequired: boolean\n sessionExchangeUrl?: string\n factorId?: string\n accessToken?: string\n refreshToken?: string\n }\n error?: string\n}\n\ninterface MfaVerifyResponse {\n data?: { sessionExchangeUrl: string }\n error?: string\n}\n\nexport function LoginForm(props: LoginFormProps) {\n const {\n passwordLoginUrl,\n mfaVerifyUrl,\n magicLinkRequestUrl,\n resetPasswordUrl,\n copy,\n className,\n defaultMethod = 'password',\n onPasswordSubmitted,\n onMagicLinkSubmitted,\n onMfaSubmitted,\n } = props\n\n const c = { ...DEFAULT_COPY, ...copy }\n\n const [method, setMethod] = React.useState<'magic-link' | 'password'>(defaultMethod)\n const [state, setState] = React.useState<FormState>('idle')\n const [error, setError] = React.useState<string | null>(null)\n\n // Password & magic-link inputs\n const [email, setEmail] = React.useState('')\n const [password, setPassword] = React.useState('')\n\n // MFA state\n const [mfa, setMfa] = React.useState<MfaState | null>(null)\n const [mfaCode, setMfaCode] = React.useState('')\n\n const resetTransientState = React.useCallback(() => {\n setState('idle')\n setError(null)\n setMfa(null)\n setMfaCode('')\n }, [])\n\n const handleTabChange = (next: string) => {\n if (next !== 'magic-link' && next !== 'password') return\n setMethod(next)\n resetTransientState()\n }\n\n const handleMagicLinkSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n setError(null)\n\n const trimmed = email.trim().toLowerCase()\n if (!isValidEmail(trimmed)) {\n setError(c.invalidEmailError)\n setState('error')\n return\n }\n\n setState('submitting')\n try {\n const res = await fetch(magicLinkRequestUrl, {\n method: 'POST',\n credentials: 'same-origin',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ email: trimmed }),\n })\n\n if (res.ok) {\n setState('magic-link-success')\n onMagicLinkSubmitted?.(trimmed)\n return\n }\n\n setState('error')\n setError(c.networkError)\n } catch {\n setState('error')\n setError(c.networkError)\n }\n }\n\n const handlePasswordSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n setError(null)\n\n const trimmed = email.trim().toLowerCase()\n if (!isValidEmail(trimmed)) {\n setError(c.invalidEmailError)\n setState('error')\n return\n }\n if (!password) {\n setError(c.invalidCredentialsError)\n setState('error')\n return\n }\n\n setState('submitting')\n try {\n const res = await fetch(passwordLoginUrl, {\n method: 'POST',\n credentials: 'same-origin',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ email: trimmed, password }),\n })\n\n const json = (await res.json().catch(() => ({}))) as PasswordLoginResponse\n\n if (!res.ok || !json.data) {\n setState('error')\n setError(json.error ?? c.invalidCredentialsError)\n return\n }\n\n onPasswordSubmitted?.(trimmed)\n\n if (json.data.mfaRequired) {\n setMfa({\n factorId: json.data.factorId ?? '',\n accessToken: json.data.accessToken ?? '',\n refreshToken: json.data.refreshToken ?? '',\n })\n setState('mfa-required')\n return\n }\n\n const exchangeUrl = json.data.sessionExchangeUrl\n if (!exchangeUrl || !isSafeRedirectUrl(exchangeUrl)) {\n setState('error')\n setError(c.networkError)\n return\n }\n window.location.assign(exchangeUrl)\n } catch {\n setState('error')\n setError(c.networkError)\n }\n }\n\n const handleMfaSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n if (!mfa) return\n setError(null)\n setState('submitting')\n\n try {\n const res = await fetch(mfaVerifyUrl, {\n method: 'POST',\n credentials: 'same-origin',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n factorId: mfa.factorId,\n code: mfaCode,\n accessToken: mfa.accessToken,\n refreshToken: mfa.refreshToken,\n }),\n })\n\n const json = (await res.json().catch(() => ({}))) as MfaVerifyResponse\n\n if (\n !res.ok ||\n !json.data?.sessionExchangeUrl ||\n !isSafeRedirectUrl(json.data.sessionExchangeUrl)\n ) {\n // Stay in mfa-required state so user can retry the code\n setState('mfa-required')\n setError(json.error ?? c.mfaInvalidCodeError)\n setMfaCode('')\n return\n }\n\n onMfaSubmitted?.()\n window.location.assign(json.data.sessionExchangeUrl)\n } catch {\n setState('mfa-required')\n setError(c.networkError)\n }\n }\n\n // MFA prompt replaces the form entirely\n if (state === 'mfa-required' || (mfa && state === 'submitting')) {\n return (\n <div className={cn('space-y-6', className)}>\n <div className='space-y-1'>\n <h2 className='text-xl font-semibold'>{c.mfaTitle}</h2>\n <p className='text-muted-foreground text-sm'>{c.mfaMessage}</p>\n </div>\n <form onSubmit={(e) => void handleMfaSubmit(e)} className='space-y-4' noValidate>\n <div className='space-y-2'>\n <Label htmlFor='login-mfa-code'>{c.mfaCodeLabel}</Label>\n <Input\n id='login-mfa-code'\n type='text'\n inputMode='numeric'\n pattern='\\d{6}'\n maxLength={6}\n autoComplete='one-time-code'\n placeholder={c.mfaCodePlaceholder}\n value={mfaCode}\n onChange={(ev) => setMfaCode(ev.target.value.replace(/\\D/g, '').slice(0, 6))}\n disabled={state === 'submitting'}\n aria-describedby={error ? 'login-mfa-error' : undefined}\n autoFocus\n />\n {error && (\n <p id='login-mfa-error' role='alert' className='text-destructive text-sm'>\n {error}\n </p>\n )}\n </div>\n <Button\n type='submit'\n className='w-full'\n disabled={state === 'submitting' || mfaCode.length !== 6}\n >\n {c.mfaSubmitCta}\n </Button>\n <button\n type='button'\n onClick={resetTransientState}\n className='text-muted-foreground hover:text-foreground w-full text-sm transition-colors'\n disabled={state === 'submitting'}\n >\n ← Volver\n </button>\n </form>\n </div>\n )\n }\n\n // Magic-link success replaces the form\n if (state === 'magic-link-success') {\n return (\n <div className={cn('space-y-2 text-center', className)}>\n <h2 className='text-xl font-semibold'>{c.magicLinkSuccessTitle}</h2>\n <p className='text-muted-foreground'>{c.magicLinkSuccessMessage}</p>\n </div>\n )\n }\n\n return (\n <div className={cn('space-y-6', className)}>\n <Tabs value={method} onValueChange={handleTabChange}>\n <TabsList className='grid w-full grid-cols-2'>\n <TabsTrigger value='password'>{c.passwordTabLabel}</TabsTrigger>\n <TabsTrigger value='magic-link'>{c.magicLinkTabLabel}</TabsTrigger>\n </TabsList>\n\n <TabsContent value='password' className='pt-4'>\n <form onSubmit={(e) => void handlePasswordSubmit(e)} className='space-y-4' noValidate>\n <div className='space-y-2'>\n <Label htmlFor='login-email-pwd'>{c.emailLabel}</Label>\n <Input\n id='login-email-pwd'\n type='email'\n autoComplete='email'\n placeholder={c.emailPlaceholder}\n value={email}\n onChange={(ev) => setEmail(ev.target.value)}\n disabled={state === 'submitting'}\n />\n </div>\n <div className='space-y-2'>\n <div className='flex items-center justify-between'>\n <Label htmlFor='login-password'>{c.passwordLabel}</Label>\n <a\n href={resetPasswordUrl}\n className='text-muted-foreground hover:text-foreground text-xs transition-colors'\n >\n {c.forgotPasswordCta}\n </a>\n </div>\n <Input\n id='login-password'\n type='password'\n autoComplete='current-password'\n placeholder={c.passwordPlaceholder}\n value={password}\n onChange={(ev) => setPassword(ev.target.value)}\n disabled={state === 'submitting'}\n aria-describedby={error ? 'login-pwd-error' : undefined}\n />\n {error && (\n <p id='login-pwd-error' role='alert' className='text-destructive text-sm'>\n {error}\n </p>\n )}\n </div>\n <Button type='submit' className='w-full' disabled={state === 'submitting'}>\n {c.passwordSubmitCta}\n </Button>\n </form>\n </TabsContent>\n\n <TabsContent value='magic-link' className='pt-4'>\n <form onSubmit={(e) => void handleMagicLinkSubmit(e)} className='space-y-4' noValidate>\n <div className='space-y-2'>\n <Label htmlFor='login-email-magic'>{c.emailLabel}</Label>\n <Input\n id='login-email-magic'\n type='email'\n autoComplete='email'\n placeholder={c.emailPlaceholder}\n value={email}\n onChange={(ev) => setEmail(ev.target.value)}\n disabled={state === 'submitting'}\n aria-describedby={error ? 'login-magic-error' : undefined}\n />\n {error && (\n <p id='login-magic-error' role='alert' className='text-destructive text-sm'>\n {error}\n </p>\n )}\n </div>\n <Button type='submit' className='w-full' disabled={state === 'submitting'}>\n {c.magicLinkSubmitCta}\n </Button>\n </form>\n </TabsContent>\n </Tabs>\n </div>\n )\n}\n","/**\n * Scheme + URL-trick allowlist for a server-returned redirect target\n * (`sessionExchangeUrl`, `redirectTo`, etc.). Shared by `AuthCallback`,\n * `AuthConfirm`, and `SetPassword` — see `CLAUDE.md` Regla A: a predicate\n * applied more than 3 times gets one home, not N inline copies that drift.\n *\n * IMPORTANT — this is NOT full open-redirect confinement: it does NOT\n * restrict absolute `http`/`https` URLs to a specific origin.\n * `isSafeRedirectUrl('https://evil.com')` returns `true`. What it DOES\n * reject:\n * - dangerous schemes (`javascript:`, `data:`, `vbscript:`, ...) — the\n * classic XSS-via-redirect vector\n * - protocol-relative URLs (`//evil.com`) — these start with `/` but\n * browsers resolve them as an absolute, CROSS-ORIGIN URL (the scheme is\n * inherited from the current page), so a naive \"starts with /\" check\n * would wrongly treat them as same-origin\n * - backslash-authority URLs (`/\\evil.com`, `\\\\evil.com`) — browsers\n * normalize `\\` to `/` for special schemes, so these resolve the same way\n * - the same tricks with an ASCII tab/LF/CR spliced between the slashes\n * (`/\\t/evil.com`) — the WHATWG URL parser strips ALL tab/LF/CR from the\n * input BEFORE parsing (anywhere in the string, not just leading/trailing),\n * so `/\\t/evil.com` is indistinguishable from `//evil.com` to the browser\n * even though a naive regex over the raw string wouldn't see two adjacent\n * slashes\n *\n * Full origin-pinning (rejecting any absolute URL whose origin isn't the\n * actual expected one) is a SEPARATE, not-yet-implemented layer. It can't\n * simply pin to `REBLU_API_BASE_URL`: that's a server-only env var\n * unavailable in these `'use client'` components, and per REB-218's\n * subdomain redirect architecture it would be the WRONG origin anyway\n * (production session-exchange lives at `nexus.<tenantDomain>`, not the\n * SITE's own `REBLU_API_BASE_URL`). It would need a dedicated prop\n * conveying the actual expected origin per deploy/routing mode.\n */\nexport function isSafeRedirectUrl(url: string): boolean {\n if (!url) return false\n\n // Match the WHATWG URL parser's own first step: strip ALL ASCII\n // tab/LF/CR from the input, anywhere in the string — not just\n // leading/trailing — before evaluating what the browser will actually\n // resolve. Without this, '/\\t/evil.com' looks like a single-'/' relative\n // path to a naive check but the browser sees '//evil.com'.\n const clean = url.replace(/[\\t\\n\\r]/g, '')\n if (!clean) return false\n\n // A relative path must start with a SINGLE '/' — '//' or '/\\' resolve as\n // an absolute, cross-origin URL in the browser despite \"starting with /\".\n if (/^[/\\\\]{2}/.test(clean)) return false\n\n const scheme = clean.split(':')[0].toLowerCase()\n return ['http', 'https'].includes(scheme) || clean.startsWith('/')\n}\n","'use client'\n\nimport * as React from 'react'\nimport { Button, cn } from '@reblu/site-ui'\nimport { isSafeRedirectUrl } from './safe-redirect'\n\nexport interface AuthCallbackCopy {\n loadingTitle: string\n loadingMessage: string\n successMessage: string\n expiredTitle: string\n expiredMessage: string\n expiredCta: string\n networkErrorTitle: string\n networkErrorMessage: string\n networkErrorRetryCta: string\n networkErrorBackCta: string\n malformedTitle: string\n malformedMessage: string\n malformedCta: string\n}\n\nexport interface AuthCallbackProps {\n exchangeUrl: string\n loginUrl: string\n copy?: Partial<AuthCallbackCopy>\n onSuccess?: (redirectTo: string) => void\n onError?: (state: 'expired' | 'network' | 'malformed', error?: Error) => void\n className?: string\n}\n\ntype State = 'mounting' | 'parsing' | 'exchanging' | 'success' | 'expired' | 'network' | 'malformed'\n\nconst DEFAULT_COPY: AuthCallbackCopy = {\n loadingTitle: 'Autenticando...',\n loadingMessage: 'Estamos verificando tu identidad.',\n successMessage: 'Iniciando sesión...',\n expiredTitle: 'Enlace caducado',\n expiredMessage: 'El enlace ha expirado o ya fue utilizado. Solicita uno nuevo.',\n expiredCta: 'Volver al login',\n networkErrorTitle: 'Error de conexión',\n networkErrorMessage: 'No pudimos completar el inicio de sesión. Inténtalo de nuevo.',\n networkErrorRetryCta: 'Reintentar',\n networkErrorBackCta: 'Volver al login',\n malformedTitle: 'Enlace inválido',\n malformedMessage: 'Enlace inválido. Solicita uno nuevo.',\n malformedCta: 'Volver al login',\n}\n\nfunction parseHash(hash: string): { access_token: string; refresh_token: string } | null {\n const raw = hash.startsWith('#') ? hash.slice(1) : hash\n if (!raw) return null\n const params = new URLSearchParams(raw)\n const access_token = params.get('access_token') ?? ''\n const refresh_token = params.get('refresh_token') ?? ''\n const type = params.get('type') ?? ''\n if (!access_token || !refresh_token || type !== 'magiclink') return null\n return { access_token, refresh_token }\n}\n\n/**\n * On failure Supabase redirects to the callback with the reason in the hash\n * fragment (e.g. `#error=access_denied&error_code=otp_expired`), never in the\n * query — the server cannot see it (REB-177). Detect it client-side and tell an\n * expired/used link (recoverable → 'expired') apart from any other failure\n * (→ 'malformed').\n */\nfunction parseHashError(hash: string): 'expired' | 'malformed' | null {\n const raw = hash.startsWith('#') ? hash.slice(1) : hash\n if (!raw) return null\n const params = new URLSearchParams(raw)\n const error = params.get('error')\n const errorCode = params.get('error_code')\n if (!error && !errorCode) return null\n // Expired or already-used magic links come back as access_denied / otp_expired.\n return errorCode === 'otp_expired' || error === 'access_denied' ? 'expired' : 'malformed'\n}\n\nexport function AuthCallback({\n exchangeUrl,\n loginUrl,\n copy,\n onSuccess,\n onError,\n className,\n}: AuthCallbackProps) {\n const [state, setState] = React.useState<State>('mounting')\n const [tokens, setTokens] = React.useState<{\n access_token: string\n refresh_token: string\n } | null>(null)\n const retryRef = React.useRef<HTMLButtonElement>(null)\n const linkRef = React.useRef<HTMLAnchorElement>(null)\n const c = { ...DEFAULT_COPY, ...copy }\n\n const exchange = React.useCallback(\n async (t: { access_token: string; refresh_token: string }) => {\n setState('exchanging')\n try {\n const res = await fetch(exchangeUrl, {\n method: 'POST',\n credentials: 'same-origin',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(t),\n })\n\n if (res.ok) {\n const raw = (await res.json()) as unknown\n const redirectTo =\n raw !== null &&\n typeof raw === 'object' &&\n 'redirectTo' in raw &&\n typeof (raw as { redirectTo: unknown }).redirectTo === 'string'\n ? (raw as { redirectTo: string }).redirectTo\n : null\n\n if (!redirectTo) {\n setState('network')\n onError?.('network', undefined)\n return\n }\n\n // Guard against dangerous schemes (javascript:, data:, etc.) AND\n // protocol-relative/backslash-authority URLs (//evil.com, /\\evil.com)\n // — see safe-redirect.ts.\n if (!isSafeRedirectUrl(redirectTo)) {\n setState('network')\n onError?.('network', undefined)\n return\n }\n\n history.replaceState({}, '', window.location.pathname)\n window.location.replace(redirectTo)\n setState('success')\n onSuccess?.(redirectTo)\n return\n }\n\n if (res.status === 401) {\n setState('expired')\n onError?.('expired')\n return\n }\n\n setState('network')\n onError?.('network', undefined)\n } catch (err) {\n setState('network')\n onError?.('network', err instanceof Error ? err : undefined)\n }\n },\n [exchangeUrl, onError, onSuccess],\n )\n\n React.useEffect(() => {\n setState('parsing')\n // A failure reported in the hash (expired/used/invalid link) is not a token\n // to exchange — surface it directly without hitting the network (REB-177).\n const hashError = parseHashError(window.location.hash)\n if (hashError) {\n setState(hashError)\n onError?.(hashError)\n return\n }\n const parsed = parseHash(window.location.hash)\n if (!parsed) {\n setState('malformed')\n onError?.('malformed')\n return\n }\n setTokens(parsed)\n void exchange(parsed)\n // `exchange`/`onError` are intentionally excluded: this effect must run\n // EXACTLY ONCE on mount to parse `window.location.hash` — re-running it\n // on every `exchange` identity change (which itself changes whenever\n // `onSuccess`/`onError` props change identity) would re-parse an\n // already-cleared hash and misfire.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n React.useEffect(() => {\n if (state === 'network') retryRef.current?.focus()\n if (state === 'expired' || state === 'malformed') linkRef.current?.focus()\n }, [state])\n\n const isLoading = state === 'mounting' || state === 'parsing' || state === 'exchanging'\n\n return (\n <main className={cn('flex min-h-screen items-center justify-center', className)}>\n <div aria-live='polite' className='w-full max-w-md space-y-4 p-6 text-center'>\n {isLoading && (\n <section>\n <h2 className='text-xl font-semibold'>{c.loadingTitle}</h2>\n <p className='text-muted-foreground mt-2'>{c.loadingMessage}</p>\n </section>\n )}\n\n {state === 'success' && (\n <section>\n <p>{c.successMessage}</p>\n </section>\n )}\n\n {state === 'expired' && (\n <section className='space-y-4'>\n <h2 className='text-xl font-semibold'>{c.expiredTitle}</h2>\n <p className='text-muted-foreground'>{c.expiredMessage}</p>\n <Button asChild variant='outline'>\n <a href={loginUrl} ref={linkRef}>\n {c.expiredCta}\n </a>\n </Button>\n </section>\n )}\n\n {state === 'network' && (\n <section className='space-y-4'>\n <h2 className='text-xl font-semibold'>{c.networkErrorTitle}</h2>\n <p className='text-muted-foreground'>{c.networkErrorMessage}</p>\n <div className='flex flex-col gap-2'>\n <Button type='button' ref={retryRef} onClick={() => tokens && void exchange(tokens)}>\n {c.networkErrorRetryCta}\n </Button>\n <Button asChild variant='outline'>\n <a href={loginUrl}>{c.networkErrorBackCta}</a>\n </Button>\n </div>\n </section>\n )}\n\n {state === 'malformed' && (\n <section className='space-y-4'>\n <h2 className='text-xl font-semibold'>{c.malformedTitle}</h2>\n <p className='text-muted-foreground'>{c.malformedMessage}</p>\n <Button asChild variant='outline'>\n <a href={loginUrl} ref={linkRef}>\n {c.malformedCta}\n </a>\n </Button>\n </section>\n )}\n </div>\n </main>\n )\n}\n","/**\n * Maps the raw `?error=` query param that Supabase appends when a magic link is\n * already consumed or expired to a user-facing Spanish message.\n *\n * Supabase redirects to /login?error=... with a raw English message (e.g.\n * \"Email link is invalid or has expired\"). Showing that verbatim is confusing,\n * so we translate the common cases and signal whether the \"Solicitar otro\n * enlace\" CTA should be offered.\n *\n * Matching is case-insensitive and whitespace-tolerant so it survives small\n * variations in how the error text arrives.\n *\n * Relocated from apps/demo-site/src/lib/utils/login-errors.ts (REB-510 slice\n * 2a) as a copy-injectable helper — Spanish defaults are unchanged, and a SITE\n * MAY override individual messages via `Partial<LoginErrorCopy>`.\n */\n\nexport interface LoginErrorInfo {\n /** Message shown in the error card. */\n message: string\n /** Whether to show the \"Solicitar otro enlace\" CTA. */\n showRequestLink: boolean\n}\n\nexport interface LoginErrorCopy {\n expiredMessage: string\n missingTokenMessage: string\n genericMessage: string\n}\n\nconst DEFAULT_COPY: LoginErrorCopy = {\n expiredMessage: 'El enlace ha expirado o ya fue utilizado.',\n missingTokenMessage: 'El enlace no es válido. Solicita uno nuevo.',\n genericMessage: 'No se pudo completar el inicio de sesión. Intenta de nuevo.',\n}\n\nexport function mapLoginError(\n error: string | null | undefined,\n copy?: Partial<LoginErrorCopy>,\n): LoginErrorInfo | null {\n if (!error) return null\n\n const normalized = error.trim().toLowerCase()\n if (normalized === '') return null\n\n const c = { ...DEFAULT_COPY, ...copy }\n\n if (\n normalized.includes('email link is invalid or has expired') ||\n normalized.includes('token has expired or is invalid')\n ) {\n return { message: c.expiredMessage, showRequestLink: true }\n }\n\n if (normalized.includes('missing_token')) {\n return { message: c.missingTokenMessage, showRequestLink: true }\n }\n\n return { message: c.genericMessage, showRequestLink: true }\n}\n","'use client'\n\nimport * as React from 'react'\nimport { useTheme } from 'next-themes'\nimport { cn } from '@reblu/site-ui'\n\nexport interface AuthLogoCopy {\n /**\n * Overrides the rendered `<img>` alt text. Pass `''` explicitly to mark the\n * logo as decorative (e.g. when an adjacent heading already announces\n * `siteName`, so screen readers shouldn't read it twice) — `undefined`\n * (the key simply omitted from `copy`) is what falls back to `siteName`.\n */\n altText?: string\n /** Shown when neither a logo URL nor `siteName` is available. */\n fallbackLabel: string\n}\n\nexport interface AuthLogoProps {\n logoLightExpandedUrl: string | null\n logoDarkExpandedUrl: string | null\n logoLightSmallUrl: string | null\n logoDarkSmallUrl: string | null\n siteName: string\n /** @default 'expanded' */\n variant?: 'expanded' | 'compact'\n className?: string\n copy?: Partial<AuthLogoCopy>\n /**\n * When `true`, renders `null` instead of the `siteName`/fallback-label text\n * span whenever no logo URL resolves for the active variant+theme, rather\n * than showing the text. Use this when the consumer already renders\n * `siteName` as a heading elsewhere on the page — without it, a visitor\n * with no logo configured (or only a light-mode logo, viewed in dark mode)\n * would see/hear `siteName` twice: once from this fallback, once from the\n * consumer's own heading.\n * @default false\n */\n hideTextFallback?: boolean\n}\n\nconst DEFAULT_COPY: Required<Pick<AuthLogoCopy, 'fallbackLabel'>> = {\n fallbackLabel: 'Inicio de sesión',\n}\n\nconst VARIANT_CLASS: Record<'expanded' | 'compact', string> = {\n expanded: 'h-8 w-auto',\n compact: 'h-8 w-8',\n}\n\n// Intrinsic `width`/`height` attributes so the browser reserves layout space\n// via its built-in aspect-ratio-from-attributes heuristic before the real\n// image loads (avoids vertical CLS at minimum; horizontal width still\n// depends on the tenant's actual logo aspect ratio, which `/api/site/config`\n// doesn't expose — an arbitrary-but-reasonable box, not a promise of zero\n// shift). `VARIANT_CLASS`'s `h-8` always wins for height regardless.\nconst VARIANT_INTRINSIC_SIZE: Record<'expanded' | 'compact', { width: number; height: number }> = {\n expanded: { width: 160, height: 32 },\n compact: { width: 32, height: 32 },\n}\n\n/**\n * Dynamic tenant logo for auth pages (REB-510 R1). Resolves expanded/compact ×\n * light/dark from the 4 `/api/site/config` logo URLs, switching light/dark\n * CLIENT-SIDE via `next-themes`. Falls back to `siteName` text, then a generic\n * `copy.fallbackLabel`, whenever the resolved URL for the active\n * variant+theme combination is `null` — it never silently swaps in the OTHER\n * theme's logo.\n *\n * Hydration-safe: `next-themes`' `resolvedTheme` is `undefined` until it\n * mounts client-side, so pre-mount `isDark` is always `false` — the same\n * light-first markup the server rendered, avoiding a hydration mismatch.\n *\n * Renders a plain `<img>`, not `next/image`: this is a distributable SDK\n * consumed by external SITE repos, so it cannot assume the consuming app's\n * `next.config` `images.remotePatterns` allowlists the tenant's logo CDN.\n */\nexport function AuthLogo(props: AuthLogoProps) {\n const {\n logoLightExpandedUrl,\n logoDarkExpandedUrl,\n logoLightSmallUrl,\n logoDarkSmallUrl,\n siteName,\n variant = 'expanded',\n className,\n copy,\n hideTextFallback = false,\n } = props\n const fallbackLabel = copy?.fallbackLabel ?? DEFAULT_COPY.fallbackLabel\n const { resolvedTheme } = useTheme()\n const isDark = resolvedTheme === 'dark'\n\n const lightUrl = variant === 'compact' ? logoLightSmallUrl : logoLightExpandedUrl\n const darkUrl = variant === 'compact' ? logoDarkSmallUrl : logoDarkExpandedUrl\n const logoUrl = isDark ? darkUrl : lightUrl\n\n // Tracks a broken/stale logo URL (404, CDN outage, etc.) — degrades to the\n // text fallback instead of a broken-image glyph. Reset whenever `logoUrl`\n // itself changes (e.g. a theme toggle resolves a DIFFERENT URL) so a past\n // failure doesn't permanently block a future, valid attempt.\n const [imgError, setImgError] = React.useState(false)\n React.useEffect(() => {\n setImgError(false)\n }, [logoUrl])\n\n const fallbackText = siteName || fallbackLabel\n // `copy.altText` — a VALUE-defined key (including `''`) wins outright,\n // that's how a consumer marks the logo decorative. A value-undefined key\n // (whether omitted from `copy` entirely, or present with an explicit\n // `undefined` value) falls back to siteName/fallbackLabel — checking value\n // definedness, not `'altText' in copy` key presence, is what makes\n // `copy={{ altText: undefined }}` behave the same as omitting the key.\n const altText = copy?.altText !== undefined ? copy.altText : siteName || fallbackLabel\n\n if (logoUrl && !imgError) {\n const { width, height } = VARIANT_INTRINSIC_SIZE[variant]\n return (\n <img\n src={logoUrl}\n alt={altText}\n width={width}\n height={height}\n className={cn(VARIANT_CLASS[variant], className)}\n onError={() => setImgError(true)}\n />\n )\n }\n\n if (hideTextFallback) return null\n\n return (\n <span className={cn('text-lg font-semibold text-foreground', className)}>{fallbackText}</span>\n )\n}\n","'use client'\n\nimport * as React from 'react'\nimport { Button, Input, cn } from '@reblu/site-ui'\nimport { Label } from '@reblu/site-ui/label'\n\nexport interface ResetPasswordRequestCopy {\n emailLabel: string\n emailPlaceholder: string\n submitCta: string\n submittingCta: string\n successTitle: string\n successMessage: string\n backToLoginCta: string\n invalidEmailError: string\n networkError: string\n}\n\nexport interface ResetPasswordRequestProps {\n requestUrl: string\n loginUrl: string\n copy?: Partial<ResetPasswordRequestCopy>\n className?: string\n onSubmitted?: (email: string) => void\n}\n\nconst DEFAULT_COPY: ResetPasswordRequestCopy = {\n emailLabel: 'Correo electrónico',\n emailPlaceholder: 'tu@email.com',\n submitCta: 'Enviar enlace de recuperación',\n submittingCta: 'Enviando...',\n successTitle: 'Revisa tu email',\n successMessage:\n 'Si el email existe en nuestra plataforma, recibirás un enlace para restablecer tu contraseña en los próximos minutos.',\n backToLoginCta: '← Volver al inicio de sesión',\n invalidEmailError: 'Introduce un correo electrónico válido.',\n networkError: 'Error de conexión. Por favor, inténtalo de nuevo.',\n}\n\nconst EMAIL_REGEX = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n\n/**\n * Step 1 of the password-reset flow — anti-enumeration: always shows the same\n * generic success message on a 2xx response, regardless of whether the email\n * exists (the backend never leaks that).\n */\nexport function ResetPasswordRequest(props: ResetPasswordRequestProps) {\n const { requestUrl, loginUrl, copy, className, onSubmitted } = props\n const c = { ...DEFAULT_COPY, ...copy }\n\n const [email, setEmail] = React.useState('')\n const [loading, setLoading] = React.useState(false)\n const [submitted, setSubmitted] = React.useState(false)\n const [error, setError] = React.useState<string | null>(null)\n\n const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n setError(null)\n\n const trimmed = email.trim().toLowerCase()\n if (!EMAIL_REGEX.test(trimmed)) {\n setError(c.invalidEmailError)\n return\n }\n\n setLoading(true)\n // `succeeded` isolates the consumer's `onSubmitted` callback from this\n // try/catch: if we called it INSIDE the try and it threw, that throw\n // would land in the network `catch` below and misreport a successful\n // request as a connection error.\n let succeeded = false\n try {\n const res = await fetch(requestUrl, {\n method: 'POST',\n credentials: 'same-origin',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ email: trimmed }),\n })\n\n if (!res.ok) {\n const json = (await res.json().catch(() => ({}))) as { error?: string }\n setError(json.error ?? c.networkError)\n setLoading(false)\n return\n }\n\n succeeded = true\n setSubmitted(true)\n setLoading(false)\n } catch {\n setError(c.networkError)\n setLoading(false)\n return\n }\n\n if (succeeded) {\n try {\n onSubmitted?.(trimmed)\n } catch (err) {\n console.error('[ResetPasswordRequest] onSubmitted callback threw:', err)\n }\n }\n }\n\n if (submitted) {\n return (\n <div className={cn('space-y-4 text-center', className)}>\n <h2 className='text-lg font-semibold'>{c.successTitle}</h2>\n <p className='text-muted-foreground text-sm'>{c.successMessage}</p>\n <a href={loginUrl} className='text-primary inline-block text-sm hover:underline'>\n {c.backToLoginCta}\n </a>\n </div>\n )\n }\n\n return (\n <form\n onSubmit={(e) => void handleSubmit(e)}\n className={cn('space-y-5', className)}\n noValidate\n >\n <div className='space-y-1.5'>\n <Label htmlFor='reset-request-email'>{c.emailLabel}</Label>\n <Input\n id='reset-request-email'\n type='email'\n autoComplete='email'\n placeholder={c.emailPlaceholder}\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n disabled={loading}\n aria-describedby={error ? 'reset-request-error' : undefined}\n autoFocus\n />\n {error && (\n <p id='reset-request-error' role='alert' className='text-destructive text-sm'>\n {error}\n </p>\n )}\n </div>\n <Button type='submit' className='w-full' disabled={loading}>\n {loading ? c.submittingCta : c.submitCta}\n </Button>\n <div className='text-center'>\n <a\n href={loginUrl}\n className='text-muted-foreground hover:text-foreground text-sm transition-colors'\n >\n {c.backToLoginCta}\n </a>\n </div>\n </form>\n )\n}\n","'use client'\n\nimport * as React from 'react'\nimport { useRouter, useSearchParams } from 'next/navigation'\nimport { Button, Input, cn } from '@reblu/site-ui'\nimport { Label } from '@reblu/site-ui/label'\n\n/**\n * Appends `key=value` to `url` without producing a malformed double `?` when\n * `url` (consumer-supplied `loginUrl`, e.g. `/login?tenant=acme`) already\n * carries a query string. Deliberately NOT `new URL(url)` — `loginUrl` is\n * typically a relative path and the WHATWG `URL` constructor requires a base\n * for those.\n */\nfunction withQueryParam(url: string, key: string, value: string): string {\n const separator = url.includes('?') ? '&' : '?'\n return `${url}${separator}${key}=${encodeURIComponent(value)}`\n}\n\nexport interface ResetPasswordConfirmCopy {\n passwordLabel: string\n passwordPlaceholder: string\n confirmPasswordLabel: string\n confirmPasswordPlaceholder: string\n mfaCodeLabel: string\n mfaCodePlaceholder: string\n mfaHelpMessage: string\n submitCta: string\n submittingCta: string\n passwordTooShortError: string\n passwordMismatchError: string\n mfaInvalidCodeError: string\n genericError: string\n missingTokensTitle: string\n missingTokensMessage: string\n requestNewLinkCta: string\n}\n\nexport interface ResetPasswordConfirmProps {\n confirmUrl: string\n loginUrl: string\n resetRequestUrl: string\n copy?: Partial<ResetPasswordConfirmCopy>\n className?: string\n onSuccess?: () => void\n}\n\nconst DEFAULT_COPY: ResetPasswordConfirmCopy = {\n passwordLabel: 'Nueva contraseña',\n passwordPlaceholder: 'Mínimo 8 caracteres',\n confirmPasswordLabel: 'Confirmar contraseña',\n confirmPasswordPlaceholder: 'Repite la contraseña',\n mfaCodeLabel: 'Código de verificación (2FA)',\n mfaCodePlaceholder: '6 dígitos',\n mfaHelpMessage:\n 'Tu cuenta tiene verificación en dos pasos. Introduce el código de tu app de autenticación para completar el cambio.',\n submitCta: 'Establecer nueva contraseña',\n submittingCta: 'Actualizando contraseña...',\n passwordTooShortError: 'La contraseña debe tener al menos 8 caracteres',\n passwordMismatchError: 'Las contraseñas no coinciden',\n mfaInvalidCodeError: 'Introduce el código de 6 dígitos de tu app de autenticación',\n genericError: 'Error al restablecer la contraseña',\n missingTokensTitle: 'Enlace inválido',\n missingTokensMessage: 'El enlace ha expirado o no es válido. Solicita uno nuevo.',\n requestNewLinkCta: 'Solicitar nuevo enlace',\n}\n\n/**\n * Step 2 of the password-reset flow. Reads `access_token`/`refresh_token`\n * straight off `useSearchParams` — no `window.location.search` + effect-timing\n * workaround needed here because, unlike a page-level default export, this is\n * a component the SITE mounts inside its own `<Suspense>` boundary.\n *\n * REB-378: when the account has a verified MFA factor, the recovery session\n * (AAL1) cannot change the password on its own. The backend responds\n * `{ data: { mfaRequired: true } }` and this reveals a 6-digit TOTP field so\n * the user can resubmit with the code (the recovery tokens stay valid).\n */\nexport function ResetPasswordConfirm(props: ResetPasswordConfirmProps) {\n const { confirmUrl, loginUrl, resetRequestUrl, copy, className, onSuccess } = props\n const c = { ...DEFAULT_COPY, ...copy }\n const router = useRouter()\n const searchParams = useSearchParams()\n\n const accessToken = searchParams.get('access_token')\n const refreshToken = searchParams.get('refresh_token')\n const hasTokens = Boolean(accessToken && refreshToken)\n\n const [password, setPassword] = React.useState('')\n const [confirmPassword, setConfirmPassword] = React.useState('')\n const [loading, setLoading] = React.useState(false)\n const [error, setError] = React.useState<string | null>(null)\n const [mfaRequired, setMfaRequired] = React.useState(false)\n const [mfaCode, setMfaCode] = React.useState('')\n\n const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n setError(null)\n if (!hasTokens) return\n\n if (password.length < 8) {\n setError(c.passwordTooShortError)\n return\n }\n if (password !== confirmPassword) {\n setError(c.passwordMismatchError)\n return\n }\n if (mfaRequired && !/^\\d{6}$/.test(mfaCode)) {\n setError(c.mfaInvalidCodeError)\n return\n }\n\n setLoading(true)\n // `succeeded` isolates the consumer's `onSuccess` callback (and the\n // navigation) from this try/catch: calling either INSIDE the try means a\n // throwing callback lands in the network `catch` below and misreports an\n // already-successful password change as a failure — the user retries\n // with recovery tokens the backend has already consumed.\n let succeeded = false\n try {\n const res = await fetch(confirmUrl, {\n method: 'POST',\n credentials: 'same-origin',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n access_token: accessToken,\n refresh_token: refreshToken,\n new_password: password,\n ...(mfaRequired ? { mfa_code: mfaCode } : {}),\n }),\n })\n\n const json = (await res.json().catch(() => ({}))) as {\n error?: string\n data?: { success?: boolean; mfaRequired?: boolean }\n }\n\n if (!res.ok) {\n setError(json.error ?? c.genericError)\n setLoading(false)\n return\n }\n\n if (json.data?.mfaRequired) {\n setMfaRequired(true)\n setLoading(false)\n return\n }\n\n succeeded = true\n setLoading(false)\n } catch {\n setError(c.genericError)\n setLoading(false)\n return\n }\n\n if (succeeded) {\n // Navigate FIRST, consumer callback SECOND (isolated in its own\n // try/catch) — same reasoning as set-password.tsx: a throwing\n // `onSuccess` can no longer block the redirect or escape as an\n // unhandled rejection out of this fire-and-forget async handler.\n router.replace(withQueryParam(loginUrl, 'reset', 'success'))\n try {\n onSuccess?.()\n } catch (err) {\n console.error('[ResetPasswordConfirm] onSuccess callback threw:', err)\n }\n }\n }\n\n if (!hasTokens) {\n return (\n <div className={cn('space-y-4 text-center', className)}>\n <h2 className='text-lg font-semibold'>{c.missingTokensTitle}</h2>\n <p className='text-muted-foreground text-sm'>{c.missingTokensMessage}</p>\n <a href={resetRequestUrl} className='text-primary inline-block text-sm hover:underline'>\n {c.requestNewLinkCta}\n </a>\n </div>\n )\n }\n\n return (\n <form\n onSubmit={(e) => void handleSubmit(e)}\n className={cn('space-y-5', className)}\n noValidate\n >\n <div className='space-y-1.5'>\n <Label htmlFor='reset-confirm-password'>{c.passwordLabel}</Label>\n <Input\n id='reset-confirm-password'\n type='password'\n autoComplete='new-password'\n placeholder={c.passwordPlaceholder}\n value={password}\n onChange={(e) => setPassword(e.target.value)}\n disabled={loading}\n minLength={8}\n aria-describedby={error ? 'reset-confirm-error' : undefined}\n autoFocus\n />\n </div>\n <div className='space-y-1.5'>\n <Label htmlFor='reset-confirm-password-2'>{c.confirmPasswordLabel}</Label>\n <Input\n id='reset-confirm-password-2'\n type='password'\n autoComplete='new-password'\n placeholder={c.confirmPasswordPlaceholder}\n value={confirmPassword}\n onChange={(e) => setConfirmPassword(e.target.value)}\n disabled={loading}\n minLength={8}\n aria-describedby={error ? 'reset-confirm-error' : undefined}\n />\n </div>\n {mfaRequired && (\n <div className='space-y-1.5'>\n <Label htmlFor='reset-confirm-mfa'>{c.mfaCodeLabel}</Label>\n <Input\n id='reset-confirm-mfa'\n type='text'\n inputMode='numeric'\n autoComplete='one-time-code'\n placeholder={c.mfaCodePlaceholder}\n value={mfaCode}\n onChange={(e) => setMfaCode(e.target.value.replace(/\\D/g, '').slice(0, 6))}\n disabled={loading}\n maxLength={6}\n aria-describedby={error ? 'reset-confirm-error' : undefined}\n autoFocus\n />\n <p className='text-muted-foreground text-xs'>{c.mfaHelpMessage}</p>\n </div>\n )}\n {error && (\n <p id='reset-confirm-error' role='alert' className='text-destructive text-sm'>\n {error}\n </p>\n )}\n <Button\n type='submit'\n className='w-full'\n disabled={\n loading || !password || !confirmPassword || (mfaRequired && mfaCode.length !== 6)\n }\n >\n {loading ? c.submittingCta : c.submitCta}\n </Button>\n </form>\n )\n}\n","'use client'\n\nimport * as React from 'react'\nimport { useSearchParams } from 'next/navigation'\nimport { Button, Input, cn } from '@reblu/site-ui'\nimport { Label } from '@reblu/site-ui/label'\nimport { isSafeRedirectUrl } from './safe-redirect'\n\nexport interface SetPasswordCopy {\n passwordLabel: string\n passwordPlaceholder: string\n confirmPasswordLabel: string\n confirmPasswordPlaceholder: string\n submitCta: string\n submittingCta: string\n passwordTooShortError: string\n passwordMismatchError: string\n genericError: string\n missingTokenTitle: string\n missingTokenMessage: string\n backToLoginCta: string\n}\n\nexport interface SetPasswordProps {\n submitUrl: string\n loginUrl: string\n copy?: Partial<SetPasswordCopy>\n className?: string\n onSuccess?: (sessionExchangeUrl: string) => void\n}\n\nconst DEFAULT_COPY: SetPasswordCopy = {\n passwordLabel: 'Contraseña',\n passwordPlaceholder: 'Mínimo 8 caracteres',\n confirmPasswordLabel: 'Confirmar contraseña',\n confirmPasswordPlaceholder: 'Repite la contraseña',\n submitCta: 'Activar cuenta',\n submittingCta: 'Activando cuenta...',\n passwordTooShortError: 'La contraseña debe tener al menos 8 caracteres',\n passwordMismatchError: 'Las contraseñas no coinciden',\n genericError: 'Error al establecer la contraseña',\n missingTokenTitle: 'Enlace inválido',\n missingTokenMessage: 'El enlace de invitación ha expirado o no es válido.',\n backToLoginCta: '← Volver al inicio de sesión',\n}\n\n/**\n * Invite flow — for a user setting their initial password. Reads\n * `session_exchange_token` off `useSearchParams`; on success, redirects via\n * `window.location.assign` (NOT the Next router) because the returned\n * `sessionExchangeUrl` points at base-api's own domain to set cookies, not a\n * same-origin SITE route.\n */\nexport function SetPassword(props: SetPasswordProps) {\n const { submitUrl, loginUrl, copy, className, onSuccess } = props\n const c = { ...DEFAULT_COPY, ...copy }\n const searchParams = useSearchParams()\n const sessionExchangeToken = searchParams.get('session_exchange_token')\n\n const [password, setPassword] = React.useState('')\n const [confirmPassword, setConfirmPassword] = React.useState('')\n const [loading, setLoading] = React.useState(false)\n const [error, setError] = React.useState<string | null>(null)\n\n const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n setError(null)\n if (!sessionExchangeToken) return\n\n if (password.length < 8) {\n setError(c.passwordTooShortError)\n return\n }\n if (password !== confirmPassword) {\n setError(c.passwordMismatchError)\n return\n }\n\n setLoading(true)\n // `sessionExchangeUrl` isolates the consumer's `onSuccess` callback (and\n // the actual navigation) from this try/catch: calling either INSIDE the\n // try means a throwing callback lands in the network `catch` below and\n // misreports an already-successful password-set as a connection error —\n // stranding an activated user on a form that tells them it failed.\n let sessionExchangeUrl: string | null = null\n try {\n const res = await fetch(submitUrl, {\n method: 'POST',\n credentials: 'same-origin',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n session_exchange_token: sessionExchangeToken,\n new_password: password,\n }),\n })\n\n const json = (await res.json().catch(() => ({}))) as {\n data?: { sessionExchangeUrl?: string }\n error?: string\n }\n\n if (!res.ok || !json.data?.sessionExchangeUrl) {\n setError(json.error ?? c.genericError)\n setLoading(false)\n return\n }\n\n if (!isSafeRedirectUrl(json.data.sessionExchangeUrl)) {\n setError(c.genericError)\n setLoading(false)\n return\n }\n\n sessionExchangeUrl = json.data.sessionExchangeUrl\n } catch {\n setError(c.genericError)\n setLoading(false)\n return\n }\n\n // Navigate FIRST, consumer callback SECOND (isolated in its own\n // try/catch): if `onSuccess` throws (ad blocker on an analytics call,\n // etc.) the navigation has already been triggered and is unaffected, and\n // the throw doesn't escape as an unhandled rejection out of this\n // fire-and-forget async handler — the user is never stranded on this\n // form by code that isn't even this component's own.\n window.location.assign(sessionExchangeUrl)\n try {\n onSuccess?.(sessionExchangeUrl)\n } catch (err) {\n console.error('[SetPassword] onSuccess callback threw:', err)\n }\n }\n\n if (!sessionExchangeToken) {\n return (\n <div className={cn('space-y-4 text-center', className)}>\n <h2 className='text-lg font-semibold'>{c.missingTokenTitle}</h2>\n <p className='text-muted-foreground text-sm'>{c.missingTokenMessage}</p>\n <a href={loginUrl} className='text-primary inline-block text-sm hover:underline'>\n {c.backToLoginCta}\n </a>\n </div>\n )\n }\n\n return (\n <form\n onSubmit={(e) => void handleSubmit(e)}\n className={cn('space-y-5', className)}\n noValidate\n >\n <div className='space-y-1.5'>\n <Label htmlFor='set-password-password'>{c.passwordLabel}</Label>\n <Input\n id='set-password-password'\n type='password'\n autoComplete='new-password'\n placeholder={c.passwordPlaceholder}\n value={password}\n onChange={(e) => setPassword(e.target.value)}\n disabled={loading}\n minLength={8}\n aria-describedby={error ? 'set-password-error' : undefined}\n // Single-purpose activation page (this IS the whole page's task,\n // there's no earlier content competing for attention) — same\n // pattern as reset-password-confirm.tsx/reset-password-request.tsx.\n autoFocus\n />\n </div>\n <div className='space-y-1.5'>\n <Label htmlFor='set-password-confirm'>{c.confirmPasswordLabel}</Label>\n <Input\n id='set-password-confirm'\n type='password'\n autoComplete='new-password'\n placeholder={c.confirmPasswordPlaceholder}\n value={confirmPassword}\n onChange={(e) => setConfirmPassword(e.target.value)}\n disabled={loading}\n minLength={8}\n aria-describedby={error ? 'set-password-error' : undefined}\n />\n </div>\n {error && (\n <p id='set-password-error' role='alert' className='text-destructive text-sm'>\n {error}\n </p>\n )}\n <Button type='submit' className='w-full' disabled={loading || !password || !confirmPassword}>\n {loading ? c.submittingCta : c.submitCta}\n </Button>\n </form>\n )\n}\n","'use client'\n\nimport * as React from 'react'\nimport { useSearchParams } from 'next/navigation'\nimport { cn } from '@reblu/site-ui'\nimport { isSafeRedirectUrl } from './safe-redirect'\n\nexport interface AuthConfirmCopy {\n loadingMessage: string\n successTitle: string\n successMessage: string\n successCta: string\n errorTitle: string\n errorMessage: string\n errorCta: string\n}\n\nexport interface AuthConfirmProps {\n confirmUrl: string\n loginUrl: string\n copy?: Partial<AuthConfirmCopy>\n className?: string\n}\n\nconst DEFAULT_COPY: AuthConfirmCopy = {\n loadingMessage: 'Confirmando tu email...',\n successTitle: 'Email confirmado',\n successMessage: 'Tu dirección de email ha sido verificada correctamente.',\n successCta: 'Iniciar sesión',\n errorTitle: 'Error al confirmar',\n errorMessage: 'El enlace de confirmación no es válido o ha expirado.',\n errorCta: 'Volver al inicio de sesión',\n}\n\ntype Status = 'loading' | 'success' | 'error'\n\n/**\n * Dual-mode email confirmation (signup / email-change):\n *\n * 1. `?success=true` — base-api already ran `verifyOtp` server-side and\n * redirected here. Shows the confirmed message with no API call.\n * 2. `?token_hash=&type=` — client-initiated verify: POSTs to `confirmUrl`\n * and follows the returned `sessionExchangeUrl`, or shows success/error\n * copy based on the response.\n *\n * Neither param present → shown as an error state with a link back to login,\n * rather than a silent client-side redirect.\n */\nexport function AuthConfirm(props: AuthConfirmProps) {\n const { confirmUrl, loginUrl, copy, className } = props\n const c = { ...DEFAULT_COPY, ...copy }\n const searchParams = useSearchParams()\n\n const success = searchParams.get('success')\n const tokenHash = searchParams.get('token_hash')\n const type = searchParams.get('type')\n\n const [status, setStatus] = React.useState<Status>(success === 'true' ? 'success' : 'loading')\n const [errorMessage, setErrorMessage] = React.useState<string | null>(null)\n\n React.useEffect(() => {\n if (success === 'true') {\n setStatus('success')\n return\n }\n\n if (tokenHash && type) {\n // `token_hash` is single-use server-side — verifying it twice makes\n // the SECOND call fail even though the first already succeeded. React\n // Strict Mode's dev-only mount→cleanup→mount double-invoke would\n // otherwise fire this fetch twice for the same token. Aborting the\n // in-flight request on cleanup stops the CLIENT from processing that\n // first response and swallows its `AbortError` below instead of\n // surfacing a false \"confirmation failed\" — but `abort()` cannot\n // retroactively un-send a request that already reached base-api\n // before cleanup ran, so this reduces rather than deterministically\n // eliminates the double-POST race (in practice React's dev\n // double-invoke runs both phases synchronously in the same commit, so\n // the abort typically wins, but that is not a spec guarantee). A\n // fully deterministic fix needs server-side idempotency on\n // `verify-otp`, which is out of this package's control. The same\n // abort also guards a genuine unmount mid-request.\n const controller = new AbortController()\n setStatus('loading')\n fetch(confirmUrl, {\n method: 'POST',\n credentials: 'same-origin',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ token_hash: tokenHash, type }),\n signal: controller.signal,\n })\n .then(async (res) => {\n const json = (await res.json().catch(() => ({}))) as {\n data?: { sessionExchangeUrl?: string; success?: boolean }\n error?: string\n }\n\n if (!res.ok) {\n setStatus('error')\n setErrorMessage(json.error ?? c.errorMessage)\n return\n }\n\n if (json.data?.sessionExchangeUrl) {\n if (!isSafeRedirectUrl(json.data.sessionExchangeUrl)) {\n setStatus('error')\n setErrorMessage(c.errorMessage)\n return\n }\n window.location.assign(json.data.sessionExchangeUrl)\n return\n }\n\n setStatus('success')\n })\n .catch((err: unknown) => {\n if (err instanceof Error && err.name === 'AbortError') return\n setStatus('error')\n setErrorMessage(c.errorMessage)\n })\n\n return () => controller.abort()\n }\n\n // Neither success=true nor token_hash+type — nothing to confirm.\n setStatus('error')\n // `c.errorMessage` (derived from the `copy` prop) is intentionally\n // excluded: re-running this effect on every `copy` object identity\n // change would re-fire the fetch. The URL params are the only real\n // trigger for this effect.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [success, tokenHash, type, confirmUrl])\n\n if (status === 'loading') {\n return (\n <div className={cn('space-y-4 text-center', className)}>\n <p className='text-muted-foreground text-sm'>{c.loadingMessage}</p>\n </div>\n )\n }\n\n if (status === 'error') {\n return (\n <div className={cn('space-y-4 text-center', className)}>\n <h2 className='text-lg font-semibold'>{c.errorTitle}</h2>\n <p className='text-muted-foreground text-sm'>{errorMessage ?? c.errorMessage}</p>\n <a href={loginUrl} className='text-primary inline-block text-sm hover:underline'>\n {c.errorCta}\n </a>\n </div>\n )\n }\n\n return (\n <div className={cn('space-y-4 text-center', className)}>\n <h2 className='text-lg font-semibold'>{c.successTitle}</h2>\n <p className='text-muted-foreground text-sm'>{c.successMessage}</p>\n <a href={loginUrl} className='text-primary inline-block text-sm hover:underline'>\n {c.successCta}\n </a>\n </div>\n )\n}\n"],"mappings":";;;AAEA,YAAY,WAAW;AACvB,SAAS,QAAQ,OAAO,UAAU;AAClC,SAAS,aAAa;AACtB,SAAS,MAAM,UAAU,aAAa,mBAAmB;;;AC6BlD,SAAS,kBAAkB,KAAsB;AACtD,MAAI,CAAC,IAAK,QAAO;AAOjB,QAAM,QAAQ,IAAI,QAAQ,aAAa,EAAE;AACzC,MAAI,CAAC,MAAO,QAAO;AAInB,MAAI,YAAY,KAAK,KAAK,EAAG,QAAO;AAEpC,QAAM,SAAS,MAAM,MAAM,GAAG,EAAE,CAAC,EAAE,YAAY;AAC/C,SAAO,CAAC,QAAQ,OAAO,EAAE,SAAS,MAAM,KAAK,MAAM,WAAW,GAAG;AACnE;;;ADkPQ,SACE,KADF;AAvOR,IAAM,eAA8B;AAAA,EAClC,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,qB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AY;AAAA,MAChC,CAAC;AAEH,aAAO,MAAM,WAAW,MAAM;AAAA,IAChC;AAGA,cAAU,OAAO;AAAA,EAMnB,GAAG,CAAC,SAAS,WAAW,MAAM,UAAU,CAAC;AAEzC,MAAI,WAAW,WAAW;AACxB,WACE,gBAAAH,KAAC,SAAI,WAAWI,IAAG,yBAAyB,SAAS,GACnD,0BAAAJ,KAAC,OAAE,WAAU,iCAAiC,YAAE,gBAAe,GACjE;AAAA,EAEJ;AAEA,MAAI,WAAW,SAAS;AACtB,WACE,gBAAAC,MAAC,SAAI,WAAWG,IAAG,yBAAyB,SAAS,GACnD;AAAA,sBAAAJ,KAAC,QAAG,WAAU,yBAAyB,YAAE,YAAW;AAAA,MACpD,gBAAAA,KAAC,OAAE,WAAU,iCAAiC,0BAAgB,EAAE,cAAa;AAAA,MAC7E,gBAAAA,KAAC,OAAE,MAAM,UAAU,WAAU,qDAC1B,YAAE,UACL;AAAA,OACF;AAAA,EAEJ;AAEA,SACE,gBAAAC,MAAC,SAAI,WAAWG,IAAG,yBAAyB,SAAS,GACnD;AAAA,oBAAAJ,KAAC,QAAG,WAAU,yBAAyB,YAAE,cAAa;AAAA,IACtD,gBAAAA,KAAC,OAAE,WAAU,iCAAiC,YAAE,gBAAe;AAAA,IAC/D,gBAAAA,KAAC,OAAE,MAAM,UAAU,WAAU,qDAC1B,YAAE,YACL;AAAA,KACF;AAEJ;","names":["React","Button","cn","jsx","jsxs","DEFAULT_COPY","cn","Button","DEFAULT_COPY","React","cn","jsx","DEFAULT_COPY","React","Button","Input","cn","Label","jsx","jsxs","DEFAULT_COPY","EMAIL_REGEX","React","Button","Input","cn","Label","jsx","jsxs","DEFAULT_COPY","React","useSearchParams","Button","Input","cn","Label","jsx","jsxs","DEFAULT_COPY","useSearchParams","cn","Label","Input","Button","React","useSearchParams","cn","jsx","jsxs","DEFAULT_COPY","useSearchParams","cn"]}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/route-handlers.ts
21
+ var route_handlers_exports = {};
22
+ __export(route_handlers_exports, {
23
+ createProxyRoute: () => createProxyRoute
24
+ });
25
+ module.exports = __toCommonJS(route_handlers_exports);
26
+ function jsonErrorResponse(status, error, message) {
27
+ return new Response(
28
+ JSON.stringify({ error, message, correlation_id: crypto.randomUUID() }),
29
+ { status, headers: { "Content-Type": "application/json; charset=utf-8" } }
30
+ );
31
+ }
32
+ function createProxyRoute(targetPath, opts = {}) {
33
+ const {
34
+ method = "POST",
35
+ forwardSetCookie = false,
36
+ requireJson = false,
37
+ invalidRequestMessage = "Solicitud no v\xE1lida",
38
+ timeoutMs = 8e3,
39
+ configurationErrorMessage = "Error de configuraci\xF3n del servidor.",
40
+ timeoutMessage = "La solicitud ha superado el tiempo de espera.",
41
+ proxyErrorMessage = "Error de conexi\xF3n con el servidor."
42
+ } = opts;
43
+ return async function handler(request) {
44
+ if (requireJson) {
45
+ const contentType = request.headers.get("content-type") ?? "";
46
+ if (!contentType.includes("application/json")) {
47
+ return jsonErrorResponse(400, "invalid_request", invalidRequestMessage);
48
+ }
49
+ }
50
+ const baseUrl = opts.baseUrl ?? process.env.REBLU_API_BASE_URL ?? "";
51
+ const apiKey = opts.apiKey ?? process.env.REBLU_API_KEY ?? "";
52
+ if (!baseUrl || !apiKey) {
53
+ console.error(
54
+ `[createProxyRoute] Missing configuration for ${targetPath}: ` + `${!baseUrl ? "baseUrl/REBLU_API_BASE_URL " : ""}${!apiKey ? "apiKey/REBLU_API_KEY" : ""}`.trim()
55
+ );
56
+ return jsonErrorResponse(500, "missing_configuration", configurationErrorMessage);
57
+ }
58
+ const forwardedHeaders = {};
59
+ const ua = request.headers.get("user-agent");
60
+ if (ua) forwardedHeaders["user-agent"] = ua;
61
+ const xff = request.headers.get("x-forwarded-for");
62
+ if (xff) forwardedHeaders["x-forwarded-for"] = xff;
63
+ const xri = request.headers.get("x-real-ip");
64
+ if (xri) forwardedHeaders["x-real-ip"] = xri;
65
+ const upperMethod = method.toUpperCase();
66
+ const body = upperMethod === "GET" || upperMethod === "HEAD" ? void 0 : await request.text();
67
+ const search = request.nextUrl?.search ?? "";
68
+ const controller = new AbortController();
69
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
70
+ try {
71
+ const res = await fetch(`${baseUrl}${targetPath}${search}`, {
72
+ method,
73
+ headers: {
74
+ "Content-Type": "application/json",
75
+ "X-Reblu-Api-Key": apiKey,
76
+ ...forwardedHeaders
77
+ },
78
+ ...body ? { body } : {},
79
+ cache: "no-store",
80
+ signal: controller.signal
81
+ });
82
+ const data = await res.text();
83
+ const responseHeaders = new Headers({
84
+ "Content-Type": res.headers.get("Content-Type") ?? "application/json"
85
+ });
86
+ if (forwardSetCookie) {
87
+ for (const cookie of res.headers.getSetCookie()) {
88
+ responseHeaders.append("set-cookie", cookie);
89
+ }
90
+ }
91
+ return new Response(data, { status: res.status, headers: responseHeaders });
92
+ } catch (err) {
93
+ if (err instanceof Error && err.name === "AbortError") {
94
+ console.error(`[createProxyRoute] Timed out forwarding to ${targetPath} after ${timeoutMs}ms`);
95
+ return jsonErrorResponse(502, "upstream_timeout", timeoutMessage);
96
+ }
97
+ console.error(`[createProxyRoute] Error forwarding to ${targetPath}:`, err);
98
+ return jsonErrorResponse(502, "proxy_error", proxyErrorMessage);
99
+ } finally {
100
+ clearTimeout(timer);
101
+ }
102
+ };
103
+ }
104
+ // Annotate the CommonJS export names for ESM import in node:
105
+ 0 && (module.exports = {
106
+ createProxyRoute
107
+ });
108
+ //# sourceMappingURL=route-handlers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/route-handlers.ts"],"sourcesContent":["/**\n * `@reblu/site-next/route-handlers` — server-only, dependency-free Route\n * Handler factory (REB-510 / design doc \"site-auth-package\").\n *\n * This module MUST stay dependency-free (no `@reblu/site-ui`, no React): it is\n * imported directly by `app/api/*` Route Handler files, and its own tsup entry\n * carries NO `'use client'` directive (mirrors the `cache` subpath's R4\n * precedent for the opposite direction — see `tsup.config.ts`).\n *\n * Scope: this factory covers the `/api/site/auth/*` proxy shape specifically\n * (fixed target path, JSON body passthrough, optional `Set-Cookie` forward) —\n * the same shape as every one of demo-site's 8 auth Route Handlers. It is\n * modeled on `apps/demo-site/src/lib/api/proxy.ts` (`proxyToBaseApi`) but is\n * NOT a drop-in replacement for every one of that helper's call sites: it\n * does not support a per-request DYNAMIC `targetPath` (e.g.\n * `api/shop/order/[sessionId]/route.ts`'s `` `/api/site/shop/order/${id}` ``)\n * or an arbitrary extra-`headers` passthrough — both are genuinely out of\n * scope for REB-510 (auth only). demo-site's non-auth proxy routes keep using\n * `proxyToBaseApi` directly; only the 8 auth routes are candidates to adopt\n * this factory.\n *\n * export const POST = createProxyRoute('/api/site/auth/login')\n *\n * Deliberate behavior change vs the original (R6): `proxy.ts` reads\n * `REBLU_API_BASE_URL`/`REBLU_API_KEY` at MODULE LOAD. This factory reads them\n * LAZILY, inside the returned handler, on every request — `opts.baseUrl` /\n * `opts.apiKey` still take priority when provided.\n *\n * Why this factory reads `process.env` at all, unlike `@reblu/site-client`\n * (whose own docblock states \"the SDK never reads `process.env` itself\"):\n * `site-client` is instantiated ONCE by the consuming SITE, which already\n * owns and injects its env at that single call site. `createProxyRoute` is\n * the opposite shape on purpose — a ZERO-CONFIG one-liner meant to be called\n * once per Route Handler FILE (8+ files in a typical SITE), so requiring\n * every file to re-thread `baseUrl`/`apiKey` would defeat the \"one line\"\n * value proposition documented in the README. The env fallback is this\n * factory's deliberate ergonomic default; `opts.baseUrl`/`opts.apiKey` remain\n * available for a SITE that wants explicit, non-`process.env` control.\n *\n * Trust note on header forwarding: `X-Forwarded-For`/`X-Real-IP` are copied\n * from the incoming request VERBATIM (same as the original `proxy.ts`). On\n * Vercel the platform itself sets/overwrites these ahead of the Route\n * Handler, so they're trustworthy there — but this is a distributable SDK a\n * SITE can deploy anywhere. On a host where nothing strips inbound spoofed\n * values, a client can forge the IP base-api rate-limits on. Deploy this\n * factory only behind a platform that normalizes/overwrites these headers,\n * or in front of infra that strips client-supplied ones.\n */\nimport type { NextRequest } from 'next/server'\n\nexport interface CreateProxyRouteOptions {\n /** Overrides `REBLU_API_BASE_URL`. Read lazily per-request when omitted. */\n baseUrl?: string\n /** Overrides `REBLU_API_KEY`. Read lazily per-request when omitted. */\n apiKey?: string\n /** @default 'POST' */\n method?: string\n /** Forward upstream `Set-Cookie` headers to the browser. @default false */\n forwardSetCookie?: boolean\n /**\n * Reject non-`application/json` requests with a Spanish 400 before ever\n * reaching the network — mirrors `magic-link-exchange/route.ts`'s guard.\n * @default false\n */\n requireJson?: boolean\n /**\n * Overrides the Spanish `message` field of the `requireJson` 400 body, for\n * a non-Spanish-default SITE. The `error` code (`invalid_request`) and\n * shape stay fixed — only the human-facing text is overridable.\n * @default 'Solicitud no válida'\n */\n invalidRequestMessage?: string\n /**\n * Hard timeout (ms) for the upstream fetch, enforced via `AbortController`\n * — mirrors `@reblu/site-client`'s own `timeoutMs` (default `8000`, same\n * value). Without this, a hung base-api response would hang the SITE's\n * Route Handler indefinitely instead of degrading.\n * @default 8000\n */\n timeoutMs?: number\n /**\n * Overrides the `message` field of the 500 body returned when neither\n * `opts.baseUrl`/`opts.apiKey` nor `REBLU_API_BASE_URL`/`REBLU_API_KEY`\n * resolve to a non-empty value.\n * @default 'Error de configuración del servidor.'\n */\n configurationErrorMessage?: string\n /**\n * Overrides the `message` field of the 502 body returned when the\n * upstream fetch times out.\n * @default 'La solicitud ha superado el tiempo de espera.'\n */\n timeoutMessage?: string\n /**\n * Overrides the `message` field of the 502 body returned when the\n * upstream fetch fails for any other reason (DNS, connection refused,\n * etc.).\n * @default 'Error de conexión con el servidor.'\n */\n proxyErrorMessage?: string\n}\n\nfunction jsonErrorResponse(status: number, error: string, message: string): Response {\n return new Response(\n JSON.stringify({ error, message, correlation_id: crypto.randomUUID() }),\n { status, headers: { 'Content-Type': 'application/json; charset=utf-8' } },\n )\n}\n\n/**\n * Creates a Next.js Route Handler that proxies `request` to\n * `${baseUrl}${targetPath}` at base-api, injecting the `X-Reblu-Api-Key`\n * server-side so it never reaches the browser.\n */\nexport function createProxyRoute(targetPath: string, opts: CreateProxyRouteOptions = {}) {\n const {\n method = 'POST',\n forwardSetCookie = false,\n requireJson = false,\n invalidRequestMessage = 'Solicitud no válida',\n timeoutMs = 8000,\n configurationErrorMessage = 'Error de configuración del servidor.',\n timeoutMessage = 'La solicitud ha superado el tiempo de espera.',\n proxyErrorMessage = 'Error de conexión con el servidor.',\n } = opts\n\n return async function handler(request: NextRequest): Promise<Response> {\n if (requireJson) {\n const contentType = request.headers.get('content-type') ?? ''\n if (!contentType.includes('application/json')) {\n return jsonErrorResponse(400, 'invalid_request', invalidRequestMessage)\n }\n }\n\n // Lazy, per-request env read (R6) — opts win when provided.\n const baseUrl = opts.baseUrl ?? process.env.REBLU_API_BASE_URL ?? ''\n const apiKey = opts.apiKey ?? process.env.REBLU_API_KEY ?? ''\n\n if (!baseUrl || !apiKey) {\n console.error(\n `[createProxyRoute] Missing configuration for ${targetPath}: ` +\n `${!baseUrl ? 'baseUrl/REBLU_API_BASE_URL ' : ''}${!apiKey ? 'apiKey/REBLU_API_KEY' : ''}`.trim(),\n )\n return jsonErrorResponse(500, 'missing_configuration', configurationErrorMessage)\n }\n\n const forwardedHeaders: Record<string, string> = {}\n const ua = request.headers.get('user-agent')\n if (ua) forwardedHeaders['user-agent'] = ua\n const xff = request.headers.get('x-forwarded-for')\n if (xff) forwardedHeaders['x-forwarded-for'] = xff\n const xri = request.headers.get('x-real-ip')\n if (xri) forwardedHeaders['x-real-ip'] = xri\n\n const upperMethod = method.toUpperCase()\n const body =\n upperMethod === 'GET' || upperMethod === 'HEAD' ? undefined : await request.text()\n // Forward the original query string (e.g. `?slug=x`) regardless of\n // method — `targetPath` is fixed at factory-call time, so without this a\n // GET route configured via `{ method: 'GET' }` would silently drop it.\n const search = request.nextUrl?.search ?? ''\n\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), timeoutMs)\n\n try {\n const res = await fetch(`${baseUrl}${targetPath}${search}`, {\n method,\n headers: {\n 'Content-Type': 'application/json',\n 'X-Reblu-Api-Key': apiKey,\n ...forwardedHeaders,\n },\n ...(body ? { body } : {}),\n cache: 'no-store',\n signal: controller.signal,\n })\n\n const data = await res.text()\n const responseHeaders = new Headers({\n 'Content-Type': res.headers.get('Content-Type') ?? 'application/json',\n })\n\n if (forwardSetCookie) {\n for (const cookie of res.headers.getSetCookie()) {\n responseHeaders.append('set-cookie', cookie)\n }\n }\n\n return new Response(data, { status: res.status, headers: responseHeaders })\n } catch (err) {\n if (err instanceof Error && err.name === 'AbortError') {\n console.error(`[createProxyRoute] Timed out forwarding to ${targetPath} after ${timeoutMs}ms`)\n return jsonErrorResponse(502, 'upstream_timeout', timeoutMessage)\n }\n console.error(`[createProxyRoute] Error forwarding to ${targetPath}:`, err)\n return jsonErrorResponse(502, 'proxy_error', proxyErrorMessage)\n } finally {\n clearTimeout(timer)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsGA,SAAS,kBAAkB,QAAgB,OAAe,SAA2B;AACnF,SAAO,IAAI;AAAA,IACT,KAAK,UAAU,EAAE,OAAO,SAAS,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* Handler factory (REB-510 / design doc "site-auth-package").
6
+ *
7
+ * This module MUST stay dependency-free (no `@reblu/site-ui`, no React): it is
8
+ * imported directly by `app/api/*` Route Handler files, and its own tsup entry
9
+ * carries NO `'use client'` directive (mirrors the `cache` subpath's R4
10
+ * precedent for the opposite direction — see `tsup.config.ts`).
11
+ *
12
+ * Scope: this factory covers the `/api/site/auth/*` proxy shape specifically
13
+ * (fixed target path, JSON body passthrough, optional `Set-Cookie` forward) —
14
+ * the same shape as every one of demo-site's 8 auth Route Handlers. It is
15
+ * modeled on `apps/demo-site/src/lib/api/proxy.ts` (`proxyToBaseApi`) but is
16
+ * NOT a drop-in replacement for every one of that helper's call sites: it
17
+ * does not support a per-request DYNAMIC `targetPath` (e.g.
18
+ * `api/shop/order/[sessionId]/route.ts`'s `` `/api/site/shop/order/${id}` ``)
19
+ * or an arbitrary extra-`headers` passthrough — both are genuinely out of
20
+ * scope for REB-510 (auth only). demo-site's non-auth proxy routes keep using
21
+ * `proxyToBaseApi` directly; only the 8 auth routes are candidates to adopt
22
+ * this factory.
23
+ *
24
+ * export const POST = createProxyRoute('/api/site/auth/login')
25
+ *
26
+ * Deliberate behavior change vs the original (R6): `proxy.ts` reads
27
+ * `REBLU_API_BASE_URL`/`REBLU_API_KEY` at MODULE LOAD. This factory reads them
28
+ * LAZILY, inside the returned handler, on every request — `opts.baseUrl` /
29
+ * `opts.apiKey` still take priority when provided.
30
+ *
31
+ * Why this factory reads `process.env` at all, unlike `@reblu/site-client`
32
+ * (whose own docblock states "the SDK never reads `process.env` itself"):
33
+ * `site-client` is instantiated ONCE by the consuming SITE, which already
34
+ * owns and injects its env at that single call site. `createProxyRoute` is
35
+ * the opposite shape on purpose — a ZERO-CONFIG one-liner meant to be called
36
+ * once per Route Handler FILE (8+ files in a typical SITE), so requiring
37
+ * every file to re-thread `baseUrl`/`apiKey` would defeat the "one line"
38
+ * value proposition documented in the README. The env fallback is this
39
+ * factory's deliberate ergonomic default; `opts.baseUrl`/`opts.apiKey` remain
40
+ * available for a SITE that wants explicit, non-`process.env` control.
41
+ *
42
+ * Trust note on header forwarding: `X-Forwarded-For`/`X-Real-IP` are copied
43
+ * from the incoming request VERBATIM (same as the original `proxy.ts`). On
44
+ * Vercel the platform itself sets/overwrites these ahead of the Route
45
+ * Handler, so they're trustworthy there — but this is a distributable SDK a
46
+ * SITE can deploy anywhere. On a host where nothing strips inbound spoofed
47
+ * values, a client can forge the IP base-api rate-limits on. Deploy this
48
+ * factory only behind a platform that normalizes/overwrites these headers,
49
+ * or in front of infra that strips client-supplied ones.
50
+ */
51
+
52
+ interface CreateProxyRouteOptions {
53
+ /** Overrides `REBLU_API_BASE_URL`. Read lazily per-request when omitted. */
54
+ baseUrl?: string;
55
+ /** Overrides `REBLU_API_KEY`. Read lazily per-request when omitted. */
56
+ apiKey?: string;
57
+ /** @default 'POST' */
58
+ method?: string;
59
+ /** Forward upstream `Set-Cookie` headers to the browser. @default false */
60
+ forwardSetCookie?: boolean;
61
+ /**
62
+ * Reject non-`application/json` requests with a Spanish 400 before ever
63
+ * reaching the network — mirrors `magic-link-exchange/route.ts`'s guard.
64
+ * @default false
65
+ */
66
+ requireJson?: boolean;
67
+ /**
68
+ * Overrides the Spanish `message` field of the `requireJson` 400 body, for
69
+ * a non-Spanish-default SITE. The `error` code (`invalid_request`) and
70
+ * shape stay fixed — only the human-facing text is overridable.
71
+ * @default 'Solicitud no válida'
72
+ */
73
+ invalidRequestMessage?: string;
74
+ /**
75
+ * Hard timeout (ms) for the upstream fetch, enforced via `AbortController`
76
+ * — mirrors `@reblu/site-client`'s own `timeoutMs` (default `8000`, same
77
+ * value). Without this, a hung base-api response would hang the SITE's
78
+ * Route Handler indefinitely instead of degrading.
79
+ * @default 8000
80
+ */
81
+ timeoutMs?: number;
82
+ /**
83
+ * Overrides the `message` field of the 500 body returned when neither
84
+ * `opts.baseUrl`/`opts.apiKey` nor `REBLU_API_BASE_URL`/`REBLU_API_KEY`
85
+ * resolve to a non-empty value.
86
+ * @default 'Error de configuración del servidor.'
87
+ */
88
+ configurationErrorMessage?: string;
89
+ /**
90
+ * Overrides the `message` field of the 502 body returned when the
91
+ * upstream fetch times out.
92
+ * @default 'La solicitud ha superado el tiempo de espera.'
93
+ */
94
+ timeoutMessage?: string;
95
+ /**
96
+ * Overrides the `message` field of the 502 body returned when the
97
+ * upstream fetch fails for any other reason (DNS, connection refused,
98
+ * etc.).
99
+ * @default 'Error de conexión con el servidor.'
100
+ */
101
+ proxyErrorMessage?: string;
102
+ }
103
+ /**
104
+ * Creates a Next.js Route Handler that proxies `request` to
105
+ * `${baseUrl}${targetPath}` at base-api, injecting the `X-Reblu-Api-Key`
106
+ * server-side so it never reaches the browser.
107
+ */
108
+ declare function createProxyRoute(targetPath: string, opts?: CreateProxyRouteOptions): (request: NextRequest) => Promise<Response>;
109
+
110
+ export { type CreateProxyRouteOptions, createProxyRoute };
@@ -0,0 +1,110 @@
1
+ import { NextRequest } from 'next/server';
2
+
3
+ /**
4
+ * `@reblu/site-next/route-handlers` — server-only, dependency-free Route
5
+ * Handler factory (REB-510 / design doc "site-auth-package").
6
+ *
7
+ * This module MUST stay dependency-free (no `@reblu/site-ui`, no React): it is
8
+ * imported directly by `app/api/*` Route Handler files, and its own tsup entry
9
+ * carries NO `'use client'` directive (mirrors the `cache` subpath's R4
10
+ * precedent for the opposite direction — see `tsup.config.ts`).
11
+ *
12
+ * Scope: this factory covers the `/api/site/auth/*` proxy shape specifically
13
+ * (fixed target path, JSON body passthrough, optional `Set-Cookie` forward) —
14
+ * the same shape as every one of demo-site's 8 auth Route Handlers. It is
15
+ * modeled on `apps/demo-site/src/lib/api/proxy.ts` (`proxyToBaseApi`) but is
16
+ * NOT a drop-in replacement for every one of that helper's call sites: it
17
+ * does not support a per-request DYNAMIC `targetPath` (e.g.
18
+ * `api/shop/order/[sessionId]/route.ts`'s `` `/api/site/shop/order/${id}` ``)
19
+ * or an arbitrary extra-`headers` passthrough — both are genuinely out of
20
+ * scope for REB-510 (auth only). demo-site's non-auth proxy routes keep using
21
+ * `proxyToBaseApi` directly; only the 8 auth routes are candidates to adopt
22
+ * this factory.
23
+ *
24
+ * export const POST = createProxyRoute('/api/site/auth/login')
25
+ *
26
+ * Deliberate behavior change vs the original (R6): `proxy.ts` reads
27
+ * `REBLU_API_BASE_URL`/`REBLU_API_KEY` at MODULE LOAD. This factory reads them
28
+ * LAZILY, inside the returned handler, on every request — `opts.baseUrl` /
29
+ * `opts.apiKey` still take priority when provided.
30
+ *
31
+ * Why this factory reads `process.env` at all, unlike `@reblu/site-client`
32
+ * (whose own docblock states "the SDK never reads `process.env` itself"):
33
+ * `site-client` is instantiated ONCE by the consuming SITE, which already
34
+ * owns and injects its env at that single call site. `createProxyRoute` is
35
+ * the opposite shape on purpose — a ZERO-CONFIG one-liner meant to be called
36
+ * once per Route Handler FILE (8+ files in a typical SITE), so requiring
37
+ * every file to re-thread `baseUrl`/`apiKey` would defeat the "one line"
38
+ * value proposition documented in the README. The env fallback is this
39
+ * factory's deliberate ergonomic default; `opts.baseUrl`/`opts.apiKey` remain
40
+ * available for a SITE that wants explicit, non-`process.env` control.
41
+ *
42
+ * Trust note on header forwarding: `X-Forwarded-For`/`X-Real-IP` are copied
43
+ * from the incoming request VERBATIM (same as the original `proxy.ts`). On
44
+ * Vercel the platform itself sets/overwrites these ahead of the Route
45
+ * Handler, so they're trustworthy there — but this is a distributable SDK a
46
+ * SITE can deploy anywhere. On a host where nothing strips inbound spoofed
47
+ * values, a client can forge the IP base-api rate-limits on. Deploy this
48
+ * factory only behind a platform that normalizes/overwrites these headers,
49
+ * or in front of infra that strips client-supplied ones.
50
+ */
51
+
52
+ interface CreateProxyRouteOptions {
53
+ /** Overrides `REBLU_API_BASE_URL`. Read lazily per-request when omitted. */
54
+ baseUrl?: string;
55
+ /** Overrides `REBLU_API_KEY`. Read lazily per-request when omitted. */
56
+ apiKey?: string;
57
+ /** @default 'POST' */
58
+ method?: string;
59
+ /** Forward upstream `Set-Cookie` headers to the browser. @default false */
60
+ forwardSetCookie?: boolean;
61
+ /**
62
+ * Reject non-`application/json` requests with a Spanish 400 before ever
63
+ * reaching the network — mirrors `magic-link-exchange/route.ts`'s guard.
64
+ * @default false
65
+ */
66
+ requireJson?: boolean;
67
+ /**
68
+ * Overrides the Spanish `message` field of the `requireJson` 400 body, for
69
+ * a non-Spanish-default SITE. The `error` code (`invalid_request`) and
70
+ * shape stay fixed — only the human-facing text is overridable.
71
+ * @default 'Solicitud no válida'
72
+ */
73
+ invalidRequestMessage?: string;
74
+ /**
75
+ * Hard timeout (ms) for the upstream fetch, enforced via `AbortController`
76
+ * — mirrors `@reblu/site-client`'s own `timeoutMs` (default `8000`, same
77
+ * value). Without this, a hung base-api response would hang the SITE's
78
+ * Route Handler indefinitely instead of degrading.
79
+ * @default 8000
80
+ */
81
+ timeoutMs?: number;
82
+ /**
83
+ * Overrides the `message` field of the 500 body returned when neither
84
+ * `opts.baseUrl`/`opts.apiKey` nor `REBLU_API_BASE_URL`/`REBLU_API_KEY`
85
+ * resolve to a non-empty value.
86
+ * @default 'Error de configuración del servidor.'
87
+ */
88
+ configurationErrorMessage?: string;
89
+ /**
90
+ * Overrides the `message` field of the 502 body returned when the
91
+ * upstream fetch times out.
92
+ * @default 'La solicitud ha superado el tiempo de espera.'
93
+ */
94
+ timeoutMessage?: string;
95
+ /**
96
+ * Overrides the `message` field of the 502 body returned when the
97
+ * upstream fetch fails for any other reason (DNS, connection refused,
98
+ * etc.).
99
+ * @default 'Error de conexión con el servidor.'
100
+ */
101
+ proxyErrorMessage?: string;
102
+ }
103
+ /**
104
+ * Creates a Next.js Route Handler that proxies `request` to
105
+ * `${baseUrl}${targetPath}` at base-api, injecting the `X-Reblu-Api-Key`
106
+ * server-side so it never reaches the browser.
107
+ */
108
+ declare function createProxyRoute(targetPath: string, opts?: CreateProxyRouteOptions): (request: NextRequest) => Promise<Response>;
109
+
110
+ export { type CreateProxyRouteOptions, createProxyRoute };