@edgespark/web 0.0.0-beta.920378e

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,85 @@
1
+ import { BetterAuthClientInstance } from '../auth/types';
2
+ import { NormalizedAuthUIConfig } from './config';
3
+ import { MountAuthUIOptions, MountedAuthUI } from './types';
4
+ export interface ManagedAuthUIRuntimeOptions {
5
+ syncPublicSession?: () => Promise<void> | void;
6
+ }
7
+ /**
8
+ * Internal managed auth UI implementation.
9
+ *
10
+ * The public API only exposes `authUI.mount(...)`; this class owns the DOM,
11
+ * form flows, and lifecycle.
12
+ */
13
+ export declare class ManagedAuthUI implements MountedAuthUI {
14
+ private readonly container;
15
+ private readonly auth;
16
+ private readonly options;
17
+ private readonly loadConfig;
18
+ private readonly runtimeOptions?;
19
+ private readonly labels;
20
+ private readonly root;
21
+ private readonly state;
22
+ private destroyed;
23
+ private terminalActionInProgress;
24
+ private config;
25
+ private countdownUntil;
26
+ private countdownTimer;
27
+ private pendingFocusSnapshot;
28
+ private focusRestoreTimer;
29
+ private verificationCompletionAction;
30
+ constructor(container: HTMLElement, auth: BetterAuthClientInstance, options: MountAuthUIOptions, loadConfig: () => Promise<NormalizedAuthUIConfig>, runtimeOptions?: ManagedAuthUIRuntimeOptions | undefined);
31
+ destroy(): void;
32
+ private initialize;
33
+ private redirectAfterManagedReturnLookupFailure;
34
+ private navigateToRedirect;
35
+ private readMountSession;
36
+ private render;
37
+ private renderLoading;
38
+ private renderStatus;
39
+ private renderCurrentView;
40
+ private renderSignInView;
41
+ private renderSignUpView;
42
+ private renderVerifyEmailView;
43
+ private renderForgotPasswordView;
44
+ private renderResetPasswordView;
45
+ private renderOAuthProviders;
46
+ private renderInput;
47
+ private bindDOM;
48
+ private switchView;
49
+ private handleSignIn;
50
+ private handleSignUp;
51
+ private handleOAuthSignIn;
52
+ private handleForgotPassword;
53
+ private resendResetCode;
54
+ private handleResetPassword;
55
+ private resendVerificationEmail;
56
+ private sendVerificationEmail;
57
+ private completeAuth;
58
+ private retryAuthCompletionDataIfNeeded;
59
+ private syncPublicSessionBestEffort;
60
+ private resolveAuthCompletionData;
61
+ private completePasswordReset;
62
+ private handleExistingSessionOnMount;
63
+ private runAction;
64
+ private maybeHandleVerificationRequired;
65
+ private handleVerificationEmailSent;
66
+ private invokeRedirectModeSuccessHook;
67
+ private handleError;
68
+ private failValidation;
69
+ private getManagedReturnURL;
70
+ private consumeManagedReturnContext;
71
+ private startCountdown;
72
+ private clearCountdown;
73
+ private captureFocusSnapshot;
74
+ private scheduleFocusRestore;
75
+ private clearFocusRestoreTimer;
76
+ private passwordResetEndpoints;
77
+ private extractRedirectURL;
78
+ private extractUser;
79
+ private canUsePasswordResetEmailOtp;
80
+ private handleSessionlessManagedReturn;
81
+ private isCountdownActive;
82
+ private getCountdownSecondsRemaining;
83
+ private countdownText;
84
+ private escape;
85
+ }
@@ -0,0 +1,64 @@
1
+ export declare const AUTH_UI_THEME: {
2
+ readonly LIGHT: "light";
3
+ readonly DARK: "dark";
4
+ };
5
+ export declare const AUTH_UI_THEME_LIGHT: "light";
6
+ export declare const AUTH_UI_THEME_DARK: "dark";
7
+ export declare const AUTH_UI_THEMES: readonly ["light", "dark"];
8
+ export declare const AUTH_UI_DEFAULT_THEME: "light";
9
+ export type AuthUITheme = (typeof AUTH_UI_THEME)[keyof typeof AUTH_UI_THEME];
10
+ export declare const AUTH_UI_APPEARANCE_VARIABLE: {
11
+ readonly BACKGROUND: "--edgespark-auth-bg";
12
+ readonly BACKGROUND_MUTED: "--edgespark-auth-bg-muted";
13
+ readonly CARD_BACKGROUND: "--edgespark-auth-card-bg";
14
+ readonly BORDER: "--edgespark-auth-border";
15
+ readonly TEXT: "--edgespark-auth-text";
16
+ readonly TEXT_MUTED: "--edgespark-auth-text-muted";
17
+ readonly DIVIDER_BACKGROUND: "--edgespark-auth-divider-bg";
18
+ readonly PRIMARY: "--edgespark-auth-primary";
19
+ readonly PRIMARY_HOVER: "--edgespark-auth-primary-hover";
20
+ readonly PRIMARY_CONTRAST: "--edgespark-auth-primary-contrast";
21
+ readonly ERROR: "--edgespark-auth-error";
22
+ readonly INFO: "--edgespark-auth-info";
23
+ readonly CARD_RADIUS: "--edgespark-auth-radius-card";
24
+ readonly CONTROL_RADIUS: "--edgespark-auth-radius-control";
25
+ readonly SHADOW: "--edgespark-auth-shadow";
26
+ readonly FONT: "--edgespark-auth-font";
27
+ readonly MODAL_BACKDROP: "--edgespark-auth-modal-backdrop";
28
+ readonly MODAL_CARD_BACKGROUND: "--edgespark-auth-modal-card-bg";
29
+ readonly MODAL_SHADOW: "--edgespark-auth-modal-shadow";
30
+ };
31
+ export type AuthUIAppearanceVariableName = (typeof AUTH_UI_APPEARANCE_VARIABLE)[keyof typeof AUTH_UI_APPEARANCE_VARIABLE];
32
+ export declare const AUTH_UI_APPEARANCE_VARIABLE_NAMES: readonly AuthUIAppearanceVariableName[];
33
+ export type AuthUIAppearanceVariables = Partial<Record<AuthUIAppearanceVariableName, string>>;
34
+ export interface AuthUIAppearance {
35
+ /**
36
+ * Built-in visual preset for the managed auth UI root.
37
+ *
38
+ * Defaults to `"light"` when omitted. Variable overrides apply on top of the
39
+ * selected preset instead of replacing the entire theme contract.
40
+ */
41
+ theme?: AuthUITheme;
42
+ /**
43
+ * Optional class applied to the managed auth UI root container.
44
+ *
45
+ * Use this to scope additional app-level CSS around the stable root element.
46
+ */
47
+ className?: string;
48
+ /**
49
+ * Stable CSS custom properties supported by the managed auth UI.
50
+ *
51
+ * This is the supported appearance contract for light-touch theming. When a
52
+ * variable is omitted, the current theme preset keeps its default value.
53
+ */
54
+ variables?: AuthUIAppearanceVariables;
55
+ }
56
+ interface NormalizedAuthUIAppearance {
57
+ theme: AuthUITheme;
58
+ className: string;
59
+ variables: AuthUIAppearanceVariables;
60
+ }
61
+ export declare function isAuthUITheme(value: unknown): value is AuthUITheme;
62
+ export declare function isAuthUIAppearanceVariableName(value: string): value is AuthUIAppearanceVariableName;
63
+ export declare function normalizeAuthUIAppearance(appearance?: AuthUIAppearance): NormalizedAuthUIAppearance;
64
+ export {};
@@ -0,0 +1,33 @@
1
+ export type OAuthProviderId = "google" | "apple" | "microsoft" | "github" | "gitlab" | "discord";
2
+ interface OAuthProviderBlock {
3
+ enabled?: boolean;
4
+ }
5
+ interface ProviderEmailPassword {
6
+ enabled?: boolean;
7
+ config?: {
8
+ minPasswordLength?: number;
9
+ requireEmailVerification?: boolean;
10
+ requirePasswordResetEmailVerification?: boolean;
11
+ };
12
+ }
13
+ interface AuthConfigResponse {
14
+ disableSignUp?: boolean;
15
+ providerEmailPassword?: ProviderEmailPassword;
16
+ providerGoogle?: OAuthProviderBlock;
17
+ providerApple?: OAuthProviderBlock;
18
+ providerMicrosoft?: OAuthProviderBlock;
19
+ providerGithub?: OAuthProviderBlock;
20
+ providerGitlab?: OAuthProviderBlock;
21
+ providerDiscord?: OAuthProviderBlock;
22
+ }
23
+ export interface NormalizedAuthUIConfig {
24
+ disableSignUp: boolean;
25
+ emailPasswordEnabled: boolean;
26
+ minPasswordLength: number;
27
+ requireEmailVerification: boolean;
28
+ passwordResetEmailOtpEnabled: boolean;
29
+ oauthProviders: OAuthProviderId[];
30
+ }
31
+ export declare function loadNormalizedAuthUIConfig(): Promise<NormalizedAuthUIConfig>;
32
+ export declare function normalizeAuthUIConfig(config: AuthConfigResponse): NormalizedAuthUIConfig;
33
+ export {};
@@ -0,0 +1,2 @@
1
+ import { AuthUILabelOverrides, AuthUILabels } from './types';
2
+ export declare function mergeAuthUILabels(base: AuthUILabels, overrides?: AuthUILabelOverrides): AuthUILabels;
@@ -0,0 +1,4 @@
1
+ export { createAuthUIModule } from './mount';
2
+ export { AUTH_UI_APPEARANCE_VARIABLE, AUTH_UI_APPEARANCE_VARIABLE_NAMES, AUTH_UI_THEME, AUTH_UI_DEFAULT_THEME, AUTH_UI_THEME_DARK, AUTH_UI_THEME_LIGHT, AUTH_UI_THEMES, } from './appearance';
3
+ export type { AuthUIAppearance, AuthUIAppearanceVariableName, AuthUIAppearanceVariables, AuthUITheme, } from './appearance';
4
+ export type { AuthSuccessEvent, AuthUILabelOverrides, AuthUILabels, ControlledAuthUIOptions, EdgeSparkAuthUI, MountAuthUIOptions, MountedAuthUI, RedirectAuthUIOptions, } from './types';
@@ -0,0 +1,4 @@
1
+ import { BetterAuthClientInstance } from '../auth/types';
2
+ import { ManagedAuthUIRuntimeOptions } from './ManagedAuthUI';
3
+ import { EdgeSparkAuthUI } from './types';
4
+ export declare function createAuthUIModule(auth: BetterAuthClientInstance, runtimeOptions?: ManagedAuthUIRuntimeOptions): EdgeSparkAuthUI;
@@ -0,0 +1,7 @@
1
+ import { AuthSession, AuthUser, BetterAuthClientInstance } from '../auth/types';
2
+ import { EdgeSparkAuthError } from '../errors';
3
+ export declare function normalizeAuthError(error: unknown, fallbackMessage?: string): EdgeSparkAuthError;
4
+ export declare function readCurrentSession(auth: BetterAuthClientInstance): Promise<{
5
+ user: AuthUser | null;
6
+ session: AuthSession | null;
7
+ }>;
@@ -0,0 +1,156 @@
1
+ import { AuthSession, AuthUser } from '../auth/types';
2
+ import { EdgeSparkAuthError } from '../errors';
3
+ import { RedirectTarget } from '../redirect';
4
+ import { DeepPartial } from '../shared/types';
5
+ import { AuthUIAppearance } from './appearance';
6
+ /** Sign-in or sign-up completed with an authenticated session. */
7
+ export type AuthenticatedAuthSuccessEvent = {
8
+ action: "sign-in";
9
+ user: AuthUser;
10
+ session: AuthSession;
11
+ } | {
12
+ action: "sign-up";
13
+ user: AuthUser;
14
+ session: AuthSession;
15
+ };
16
+ /** Password was reset. No session — the user must sign in again. */
17
+ export interface PasswordResetSuccessEvent {
18
+ action: "password-reset";
19
+ user: null;
20
+ session: null;
21
+ }
22
+ /**
23
+ * Payload emitted by `onSuccess` after a managed auth flow completes.
24
+ *
25
+ * Switch on `event.action` to narrow `user` and `session`:
26
+ * - `"sign-in"` / `"sign-up"` → `user: AuthUser`, `session: AuthSession`
27
+ * - `"password-reset"` → `user: null`, `session: null`
28
+ */
29
+ export type AuthSuccessEvent = AuthenticatedAuthSuccessEvent | PasswordResetSuccessEvent;
30
+ export interface AuthUILabels {
31
+ common: {
32
+ loading: string;
33
+ redirecting: string;
34
+ backToSignIn: string;
35
+ };
36
+ signIn: {
37
+ title: string;
38
+ subtitle: string;
39
+ emailLabel: string;
40
+ passwordLabel: string;
41
+ submitButton: string;
42
+ forgotPassword: string;
43
+ switchToSignUp: string;
44
+ signUpPrompt: string;
45
+ };
46
+ signUp: {
47
+ title: string;
48
+ subtitle: string;
49
+ nameLabel: string;
50
+ emailLabel: string;
51
+ passwordLabel: string;
52
+ confirmPasswordLabel: string;
53
+ submitButton: string;
54
+ switchToSignIn: string;
55
+ signInPrompt: string;
56
+ };
57
+ verifyEmail: {
58
+ title: string;
59
+ subtitle: string;
60
+ sentToLabel: string;
61
+ resendButton: string;
62
+ resendCountdown: string;
63
+ changeEmailButton: string;
64
+ };
65
+ forgotPassword: {
66
+ title: string;
67
+ subtitle: string;
68
+ emailLabel: string;
69
+ submitButton: string;
70
+ };
71
+ resetPassword: {
72
+ title: string;
73
+ subtitle: string;
74
+ codeLabel: string;
75
+ newPasswordLabel: string;
76
+ confirmPasswordLabel: string;
77
+ submitButton: string;
78
+ resendCodeButton: string;
79
+ resendCountdown: string;
80
+ };
81
+ oauth: {
82
+ dividerText: string;
83
+ continueWith: string;
84
+ };
85
+ errors: {
86
+ invalidEmail: string;
87
+ requiredField: string;
88
+ passwordTooShort: string;
89
+ passwordMismatch: string;
90
+ invalidCode: string;
91
+ generic: string;
92
+ };
93
+ }
94
+ export type AuthUILabelOverrides = DeepPartial<AuthUILabels>;
95
+ interface BaseAuthUIOptions {
96
+ onError?: (error: EdgeSparkAuthError) => void;
97
+ labels?: AuthUILabelOverrides;
98
+ /**
99
+ * Optional, constrained visual customization for the managed auth UI.
100
+ *
101
+ * This is intentionally smaller than the headless auth path. Use
102
+ * `client.auth` when the app needs full UI ownership.
103
+ */
104
+ appearance?: AuthUIAppearance;
105
+ }
106
+ /**
107
+ * Redirect mode — use when the auth UI is a full-page login gate.
108
+ *
109
+ * After successful auth the SDK navigates to `redirectTo` automatically.
110
+ * This is the common case: dedicated `/login` page → redirect to `/dashboard`.
111
+ *
112
+ * `onSuccess` is optional and fires *before* the redirect (useful for analytics).
113
+ */
114
+ export interface RedirectAuthUIOptions extends BaseAuthUIOptions {
115
+ redirectTo: RedirectTarget;
116
+ onSuccess?: (event: AuthSuccessEvent) => void;
117
+ }
118
+ /**
119
+ * Controlled mode — use when the app owns what happens after auth.
120
+ *
121
+ * The SDK will not navigate. Instead, `onSuccess` fires with the auth event
122
+ * and the app decides the next step (close a modal, update state, navigate
123
+ * programmatically via a router, etc.).
124
+ *
125
+ * Use this for: modals, embedded auth widgets, SPA routing, onboarding flows.
126
+ */
127
+ export interface ControlledAuthUIOptions extends BaseAuthUIOptions {
128
+ onSuccess: (event: AuthSuccessEvent) => void;
129
+ redirectTo?: never;
130
+ }
131
+ /**
132
+ * Two post-auth strategies — pick one:
133
+ *
134
+ * - **Redirect mode** (`{ redirectTo }`) — SDK navigates after auth.
135
+ * Best for dedicated login pages.
136
+ *
137
+ * - **Controlled mode** (`{ onSuccess }`) — app handles post-auth behavior.
138
+ * Best for modals, embedded widgets, or SPA routing.
139
+ */
140
+ export type MountAuthUIOptions = RedirectAuthUIOptions | ControlledAuthUIOptions;
141
+ export interface MountedAuthUI {
142
+ /**
143
+ * Removes the mounted UI and clears internal timers/listeners.
144
+ */
145
+ destroy(): void;
146
+ }
147
+ export interface EdgeSparkAuthUI {
148
+ /**
149
+ * Mounts the managed auth UI into a container element.
150
+ *
151
+ * Pass `redirectTo` for the common login-page case, or `onSuccess` when the
152
+ * surrounding app wants to control routing/state after auth completes.
153
+ */
154
+ mount(container: HTMLElement, options: MountAuthUIOptions): MountedAuthUI;
155
+ }
156
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare function assertBrowserRuntime(): void;
2
+ export declare function getBrowserOrigin(): string;
@@ -0,0 +1,43 @@
1
+ import { EdgeSparkApi } from './api/types';
2
+ import { EdgeSparkAuth } from './auth/types';
3
+ import { EdgeSparkAuthUI } from './auth-ui';
4
+ export interface EdgeSparkClient {
5
+ /**
6
+ * Headless auth client with a better-auth-aligned API shape, plus a small
7
+ * set of EdgeSpark session helpers:
8
+ *
9
+ * - `requireSession()` — resolves or throws, for route guards
10
+ * - `onSessionChange()` — hydration-safe session observer
11
+ *
12
+ * Standard auth methods such as `signIn.email`, `signIn.social`,
13
+ * `signUp.email`, `signOut`, and `getSession` remain available on the same
14
+ * familiar shape.
15
+ *
16
+ * Some upstream better-auth methods may still be intentionally unsupported
17
+ * by the current EdgeSpark platform capability set. Those methods fail fast
18
+ * with `UNSUPPORTED_AUTH_METHOD` instead of deferring to a platform 400/404.
19
+ */
20
+ auth: EdgeSparkAuth;
21
+ /**
22
+ * Same-origin fetch wrapper for app APIs.
23
+ *
24
+ * Always sends cookie credentials. Rejects cross-origin URLs.
25
+ */
26
+ api: EdgeSparkApi;
27
+ /**
28
+ * Managed auth UI for login, sign-up, verification, and password reset flows.
29
+ *
30
+ * Mount with `{ redirectTo }` for login pages, or `{ onSuccess }` for
31
+ * modals and SPA routing.
32
+ */
33
+ authUI: EdgeSparkAuthUI;
34
+ }
35
+ /**
36
+ * Creates the EdgeSpark browser client.
37
+ *
38
+ * The v2 SDK is intentionally zero-config:
39
+ * - current page origin is always used
40
+ * - cookie credentials are always enabled
41
+ * - auth routes stay internal
42
+ */
43
+ export declare function createEdgeSpark(): EdgeSparkClient;
@@ -0,0 +1,32 @@
1
+ /** Base error class for all EdgeSpark SDK errors. Use `instanceof` to catch. */
2
+ export declare class EdgeSparkError extends Error {
3
+ readonly code: string;
4
+ constructor(code: string, message: string);
5
+ }
6
+ /** Programmer mistake: bad options, invalid container, cross-origin fetch, etc. */
7
+ export declare class EdgeSparkConfigError extends EdgeSparkError {
8
+ constructor(message: string);
9
+ }
10
+ /** Called outside a browser (SSR, Node, tests without DOM). */
11
+ export declare class EdgeSparkRuntimeError extends EdgeSparkError {
12
+ constructor(message: string);
13
+ }
14
+ /** Auth operation failed (sign-in rejected, session missing, etc.). */
15
+ export declare class EdgeSparkAuthError extends EdgeSparkError {
16
+ readonly cause?: unknown;
17
+ readonly status?: number;
18
+ constructor(message: string, options?: {
19
+ code?: string;
20
+ cause?: unknown;
21
+ status?: number;
22
+ });
23
+ }
24
+ /**
25
+ * Normalize an unknown thrown value into an {@link EdgeSparkAuthError}.
26
+ *
27
+ * Already-normalized instances pass through unchanged. Objects with
28
+ * `message`/`code`/`status` fields are preserved. Plain strings become
29
+ * the error message. Everything else falls back to the caller-supplied
30
+ * defaults.
31
+ */
32
+ export declare function normalizeToAuthError(error: unknown, fallbackMessage?: string, fallbackCode?: string): EdgeSparkAuthError;