@edgespark/web 0.0.0-beta.807cd96
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.
- package/README.md +301 -0
- package/auth/styles/styles.css +402 -0
- package/dist/api/fetch.d.ts +8 -0
- package/dist/api/types.d.ts +13 -0
- package/dist/auth/create-auth.d.ts +18 -0
- package/dist/auth/local-dev.d.ts +41 -0
- package/dist/auth/placeholder-email.d.ts +7 -0
- package/dist/auth/types.d.ts +84 -0
- package/dist/auth-ui/ManagedAuthUI.d.ts +114 -0
- package/dist/auth-ui/appearance.d.ts +64 -0
- package/dist/auth-ui/config.d.ts +60 -0
- package/dist/auth-ui/default-labels.d.ts +2 -0
- package/dist/auth-ui/google-one-tap.d.ts +47 -0
- package/dist/auth-ui/index.d.ts +4 -0
- package/dist/auth-ui/mount.d.ts +22 -0
- package/dist/auth-ui/prompt-google-one-tap.d.ts +43 -0
- package/dist/auth-ui/runtime.d.ts +7 -0
- package/dist/auth-ui/types.d.ts +194 -0
- package/dist/browser.d.ts +2 -0
- package/dist/client.d.ts +43 -0
- package/dist/errors.d.ts +32 -0
- package/dist/index.cjs +197 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.es.js +2994 -0
- package/dist/locales/ar.d.ts +2 -0
- package/dist/locales/de.d.ts +2 -0
- package/dist/locales/en-US.d.ts +2 -0
- package/dist/locales/es.d.ts +2 -0
- package/dist/locales/fr.d.ts +2 -0
- package/dist/locales/hi.d.ts +2 -0
- package/dist/locales/index.d.ts +21 -0
- package/dist/locales/it.d.ts +2 -0
- package/dist/locales/ja.d.ts +2 -0
- package/dist/locales/ko.d.ts +2 -0
- package/dist/locales/pt-BR.d.ts +2 -0
- package/dist/locales/ru.d.ts +2 -0
- package/dist/locales/zh-CN.d.ts +2 -0
- package/dist/redirect.d.ts +5 -0
- package/dist/shared/types.d.ts +6 -0
- package/package.json +53 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type EdgeSparkRequestInit = Omit<RequestInit, "credentials">;
|
|
2
|
+
/**
|
|
3
|
+
* Same-origin fetch wrapper for authenticated app requests.
|
|
4
|
+
*/
|
|
5
|
+
export interface EdgeSparkApi {
|
|
6
|
+
/**
|
|
7
|
+
* Same-origin `fetch` with cookie credentials always enabled.
|
|
8
|
+
*
|
|
9
|
+
* `credentials` is intentionally omitted from the accepted init shape because
|
|
10
|
+
* the SDK never allows callers to disable cookie auth.
|
|
11
|
+
*/
|
|
12
|
+
fetch(input: RequestInfo | URL, init?: EdgeSparkRequestInit): Promise<Response>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BetterAuthClientInstance, EdgeSparkAuth } from './types';
|
|
2
|
+
export declare const AUTH_BASE_PATH: "/api/_es/auth";
|
|
3
|
+
export declare function syncEdgeSparkAuthSession(authClient: BetterAuthClientInstance): Promise<void>;
|
|
4
|
+
/**
|
|
5
|
+
* Creates the headless auth module.
|
|
6
|
+
*
|
|
7
|
+
* The exposed API intentionally keeps better-auth's shape so existing upstream
|
|
8
|
+
* knowledge transfers directly. EdgeSpark adds session helpers and sync
|
|
9
|
+
* semantics on top of that familiar surface.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createEdgeSparkAuth(): EdgeSparkAuth;
|
|
12
|
+
/**
|
|
13
|
+
* Creates the internal auth client used by the managed UI.
|
|
14
|
+
*
|
|
15
|
+
* Redirect handling is intentionally disabled here so `authUI` can own
|
|
16
|
+
* callback timing, loading state, and post-auth navigation semantics.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createManagedAuthUIClient(): BetterAuthClientInstance;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Is the web app running in local-dev mode?
|
|
3
|
+
*
|
|
4
|
+
* Reads a `<meta name="edgespark-local-dev" content="true">` tag that
|
|
5
|
+
* the `edgespark dev` reverse proxy splices into every HTML response.
|
|
6
|
+
* The dev proxy only runs under `edgespark dev`; the meta tag is absent
|
|
7
|
+
* on deployed apps (served through the CF dispatcher, which doesn't
|
|
8
|
+
* inject).
|
|
9
|
+
*
|
|
10
|
+
* Uses a <meta> tag rather than an inline <script> so the signal works
|
|
11
|
+
* under strict CSP — `script-src 'self'` without `'unsafe-inline'`
|
|
12
|
+
* would silently drop a script-based marker. Meta tags carry no
|
|
13
|
+
* script-src constraint.
|
|
14
|
+
*
|
|
15
|
+
* No server round-trip, no build-time macro, no hostname heuristic, no
|
|
16
|
+
* framework assumptions. Survives SDK pre-bundling — the SDK reads the
|
|
17
|
+
* DOM at call time, not a value captured at build time.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isLocalDev(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Auto-verify email in local dev. The server reads the pending verification
|
|
22
|
+
* token from D1, drives Better Auth's verify-email handler, and returns with
|
|
23
|
+
* the session cookie already set. Single round-trip — no token round-trip on
|
|
24
|
+
* the client.
|
|
25
|
+
*/
|
|
26
|
+
export declare function autoVerifyLocalDev(email: string): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Fetch the pending OTP for password reset in local dev.
|
|
29
|
+
* Returns the OTP string or null if not available.
|
|
30
|
+
*/
|
|
31
|
+
export declare function fetchOtpLocalDev(email: string): Promise<string | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Fetch the pending OTP for email sign-in in local dev.
|
|
34
|
+
* Returns the OTP string or null if not available.
|
|
35
|
+
*/
|
|
36
|
+
export declare function fetchSignInOtpLocalDev(email: string): Promise<string | null>;
|
|
37
|
+
/**
|
|
38
|
+
* Fetch the pending SMS sign-in code in local dev.
|
|
39
|
+
* Returns the code string or null if not available.
|
|
40
|
+
*/
|
|
41
|
+
export declare function fetchPhoneOtpLocalDev(phoneNumber: string): Promise<string | null>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const PLACEHOLDER_EMAIL_DOMAIN = "phone.invalid";
|
|
2
|
+
/**
|
|
3
|
+
* Users who signed in without an email (e.g. SMS sign-in) get a generated
|
|
4
|
+
* `@phone.invalid` address. It cannot receive mail — don't display it or
|
|
5
|
+
* pass it to payment, analytics, or email providers.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isPlaceholderEmail(email: string | null | undefined): boolean;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createAuthClient } from 'better-auth/client';
|
|
2
|
+
/**
|
|
3
|
+
* Direct better-auth client instance returned by createAuthClient().
|
|
4
|
+
*/
|
|
5
|
+
export type BetterAuthClientInstance = ReturnType<typeof createAuthClient>;
|
|
6
|
+
export type SessionResult = Awaited<ReturnType<BetterAuthClientInstance["getSession"]>>;
|
|
7
|
+
export type AuthSession = NonNullable<SessionResult["data"]>;
|
|
8
|
+
export type AuthUser = AuthSession["user"];
|
|
9
|
+
export type SessionChangeCallback = (session: AuthSession | null) => void;
|
|
10
|
+
export interface AuthEndpointError {
|
|
11
|
+
code?: string;
|
|
12
|
+
message?: string;
|
|
13
|
+
status?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface AuthEndpointResult<TData = unknown> {
|
|
16
|
+
data?: TData | null;
|
|
17
|
+
error?: AuthEndpointError | null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* EdgeSpark keeps the auth API shape aligned with better-auth while adding a
|
|
21
|
+
* small set of session helpers on top.
|
|
22
|
+
*
|
|
23
|
+
* Most upstream auth methods remain available on the familiar better-auth
|
|
24
|
+
* shape. Some upstream methods may still be intentionally unsupported by the
|
|
25
|
+
* current EdgeSpark platform capability set even though they exist on the
|
|
26
|
+
* underlying better-auth client surface. In those cases, the facade throws an
|
|
27
|
+
* `EdgeSparkAuthError` with code `UNSUPPORTED_AUTH_METHOD` instead of deferring
|
|
28
|
+
* to a platform-specific 400/404 response.
|
|
29
|
+
*/
|
|
30
|
+
export type EdgeSparkAuth = BetterAuthClientInstance & {
|
|
31
|
+
/**
|
|
32
|
+
* Resolves with the current session, or throws when the browser is not authenticated.
|
|
33
|
+
*
|
|
34
|
+
* Use this for route guards and other flows where nullable session checks add noise.
|
|
35
|
+
*
|
|
36
|
+
* If the session lookup itself fails (offline, 5xx, etc.), this throws an
|
|
37
|
+
* `EdgeSparkAuthError` that preserves the upstream error code/status instead
|
|
38
|
+
* of collapsing the failure into `UNAUTHENTICATED`.
|
|
39
|
+
*/
|
|
40
|
+
requireSession(): Promise<AuthSession>;
|
|
41
|
+
/**
|
|
42
|
+
* Subscribes to session changes for the current browser context.
|
|
43
|
+
*
|
|
44
|
+
* The first emission is hydration-safe: it waits for the initial server
|
|
45
|
+
* session lookup to complete before firing, so subscribers never receive a
|
|
46
|
+
* premature `null` while a cookie session is still settling.
|
|
47
|
+
*
|
|
48
|
+
* After hydration, successful session atom updates are forwarded immediately.
|
|
49
|
+
* Successful auth mutations that create or clear a session in the current
|
|
50
|
+
* tab also prompt other tabs to refetch their session state, so logout and
|
|
51
|
+
* same-tab sign-in/sign-up converge quickly across tabs.
|
|
52
|
+
*
|
|
53
|
+
* Transient lookup failures that temporarily clear the atom to `null` are
|
|
54
|
+
* ignored so subscribers do not mistake a backend error for a real sign-out.
|
|
55
|
+
*
|
|
56
|
+
* Returns an unsubscribe function.
|
|
57
|
+
*/
|
|
58
|
+
onSessionChange(callback: SessionChangeCallback): () => void;
|
|
59
|
+
/**
|
|
60
|
+
* Signs out and then best-effort synchronizes session state for the current
|
|
61
|
+
* tab and other open tabs.
|
|
62
|
+
*
|
|
63
|
+
* The underlying better-auth result is returned unchanged.
|
|
64
|
+
*/
|
|
65
|
+
signOut(...args: Parameters<BetterAuthClientInstance["signOut"]>): ReturnType<BetterAuthClientInstance["signOut"]>;
|
|
66
|
+
/**
|
|
67
|
+
* Currently unsupported by EdgeSpark platform auth.
|
|
68
|
+
*
|
|
69
|
+
* The method remains present to preserve the familiar better-auth API shape,
|
|
70
|
+
* but the facade throws `UNSUPPORTED_AUTH_METHOD` until the platform enables
|
|
71
|
+
* this capability. For browser auth, prefer supported `client.auth` methods
|
|
72
|
+
* or `authUI.mount()` instead of dropping to raw `/api/_es/auth/*` routes.
|
|
73
|
+
*/
|
|
74
|
+
changeEmail(...args: Parameters<BetterAuthClientInstance["changeEmail"]>): ReturnType<BetterAuthClientInstance["changeEmail"]>;
|
|
75
|
+
/**
|
|
76
|
+
* Currently unsupported by EdgeSpark platform auth.
|
|
77
|
+
*
|
|
78
|
+
* The method remains present to preserve the familiar better-auth API shape,
|
|
79
|
+
* but the facade throws `UNSUPPORTED_AUTH_METHOD` until the platform enables
|
|
80
|
+
* this capability. Handle account removal through your own app flow until the
|
|
81
|
+
* platform adds first-class support.
|
|
82
|
+
*/
|
|
83
|
+
deleteUser(...args: Parameters<BetterAuthClientInstance["deleteUser"]>): ReturnType<BetterAuthClientInstance["deleteUser"]>;
|
|
84
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { BetterAuthClientInstance } from '../auth/types';
|
|
2
|
+
import { NormalizedAuthUIConfig } from './config';
|
|
3
|
+
import { AuthUIModuleRuntimeOptions } from './mount';
|
|
4
|
+
import { MountAuthUIOptions, MountedAuthUI } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Internal managed auth UI implementation.
|
|
7
|
+
*
|
|
8
|
+
* The public API only exposes `authUI.mount(...)`; this class owns the DOM,
|
|
9
|
+
* form flows, and lifecycle.
|
|
10
|
+
*
|
|
11
|
+
* DOM ownership: the instance owns a single root element it appends to the
|
|
12
|
+
* mount container. It never writes to `container.innerHTML`. This keeps
|
|
13
|
+
* tear-down safe when the container is a DOM node a reconciling framework
|
|
14
|
+
* (React/Vue/Solid) reuses across conditional branches — wiping the
|
|
15
|
+
* container would erase sibling content the framework just rendered.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ManagedAuthUI implements MountedAuthUI {
|
|
18
|
+
private readonly container;
|
|
19
|
+
private readonly auth;
|
|
20
|
+
private readonly options;
|
|
21
|
+
private readonly loadConfig;
|
|
22
|
+
private readonly runtimeOptions?;
|
|
23
|
+
private readonly fieldIdPrefix;
|
|
24
|
+
private readonly labels;
|
|
25
|
+
private readonly root;
|
|
26
|
+
private readonly state;
|
|
27
|
+
private destroyed;
|
|
28
|
+
private terminalActionInProgress;
|
|
29
|
+
private config;
|
|
30
|
+
private countdownUntil;
|
|
31
|
+
private countdownTimer;
|
|
32
|
+
private pendingFocusSnapshot;
|
|
33
|
+
private focusRestoreTimer;
|
|
34
|
+
private verificationCompletionAction;
|
|
35
|
+
constructor(container: HTMLElement, auth: BetterAuthClientInstance, options: MountAuthUIOptions, loadConfig: () => Promise<NormalizedAuthUIConfig>, runtimeOptions?: AuthUIModuleRuntimeOptions | undefined);
|
|
36
|
+
destroy(): void;
|
|
37
|
+
private initialize;
|
|
38
|
+
private redirectAfterManagedReturnLookupFailure;
|
|
39
|
+
private navigateToRedirect;
|
|
40
|
+
private readMountSession;
|
|
41
|
+
private render;
|
|
42
|
+
private renderLoading;
|
|
43
|
+
private renderDevModeBanner;
|
|
44
|
+
private renderStatus;
|
|
45
|
+
private renderCurrentView;
|
|
46
|
+
private renderSignInView;
|
|
47
|
+
private renderSignInMethodTab;
|
|
48
|
+
private renderPhoneInput;
|
|
49
|
+
private renderSignUpView;
|
|
50
|
+
private renderVerifyEmailView;
|
|
51
|
+
private renderForgotPasswordView;
|
|
52
|
+
private renderResetPasswordView;
|
|
53
|
+
private renderOAuthProviders;
|
|
54
|
+
private renderInput;
|
|
55
|
+
private bindDOM;
|
|
56
|
+
private switchView;
|
|
57
|
+
private handleSignIn;
|
|
58
|
+
private handleEmailOtpSignIn;
|
|
59
|
+
private sendSignInOtp;
|
|
60
|
+
private resendSignInCode;
|
|
61
|
+
private handlePhoneOtpSignIn;
|
|
62
|
+
private sendPhoneOtp;
|
|
63
|
+
private fullPhoneNumber;
|
|
64
|
+
private toPhoneAuthError;
|
|
65
|
+
private handleSignUp;
|
|
66
|
+
private handleOAuthSignIn;
|
|
67
|
+
private handleForgotPassword;
|
|
68
|
+
private resendResetCode;
|
|
69
|
+
private handleResetPassword;
|
|
70
|
+
private resendVerificationEmail;
|
|
71
|
+
/**
|
|
72
|
+
* Drive the local-dev auto-verify endpoint and, on success, complete the
|
|
73
|
+
* auth flow. Returns whether auto-verify completed — callers decide what
|
|
74
|
+
* to do on `false` (sign-up falls through to a retry UI; resend throws).
|
|
75
|
+
*/
|
|
76
|
+
private tryDevAutoVerify;
|
|
77
|
+
private sendVerificationEmail;
|
|
78
|
+
private completeAuth;
|
|
79
|
+
private retryAuthCompletionDataIfNeeded;
|
|
80
|
+
private syncPublicSessionBestEffort;
|
|
81
|
+
private resolveAuthCompletionData;
|
|
82
|
+
private completePasswordReset;
|
|
83
|
+
private handleExistingSessionOnMount;
|
|
84
|
+
private runAction;
|
|
85
|
+
private maybeHandleVerificationRequired;
|
|
86
|
+
private handleVerificationEmailSent;
|
|
87
|
+
private invokeRedirectModeSuccessHook;
|
|
88
|
+
private handleError;
|
|
89
|
+
private failValidation;
|
|
90
|
+
private getManagedReturnURL;
|
|
91
|
+
private consumeManagedReturnContext;
|
|
92
|
+
private startCountdown;
|
|
93
|
+
private updateCountdownControls;
|
|
94
|
+
private clearCountdown;
|
|
95
|
+
private captureFocusSnapshot;
|
|
96
|
+
private scheduleFocusRestore;
|
|
97
|
+
private clearFocusRestoreTimer;
|
|
98
|
+
private passwordResetEndpoints;
|
|
99
|
+
private emailOtpSignInEndpoints;
|
|
100
|
+
private phoneOtpSignInEndpoints;
|
|
101
|
+
private availableSignInMethods;
|
|
102
|
+
private activeSignInMethod;
|
|
103
|
+
private resolveInitialSignInMethod;
|
|
104
|
+
private setSignInMethod;
|
|
105
|
+
private canUseEmailOtpSignIn;
|
|
106
|
+
private extractRedirectURL;
|
|
107
|
+
private extractUser;
|
|
108
|
+
private canUsePasswordResetEmailOtp;
|
|
109
|
+
private handleSessionlessManagedReturn;
|
|
110
|
+
private isCountdownActive;
|
|
111
|
+
private getCountdownSecondsRemaining;
|
|
112
|
+
private countdownText;
|
|
113
|
+
private escape;
|
|
114
|
+
}
|
|
@@ -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,60 @@
|
|
|
1
|
+
export type OAuthProviderId = "google" | "apple" | "microsoft" | "github" | "gitlab" | "discord";
|
|
2
|
+
interface OAuthProviderConfig {
|
|
3
|
+
/**
|
|
4
|
+
* OAuth Client ID resolved server-side. Present only when both the Client
|
|
5
|
+
* ID var and the corresponding secret resolve, so a non-empty value is
|
|
6
|
+
* the "this provider is fully wired browser-side" signal.
|
|
7
|
+
*/
|
|
8
|
+
clientId?: string;
|
|
9
|
+
}
|
|
10
|
+
interface OAuthProviderBlock {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
config?: OAuthProviderConfig;
|
|
13
|
+
}
|
|
14
|
+
interface ProviderEmailPassword {
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
config?: {
|
|
17
|
+
minPasswordLength?: number;
|
|
18
|
+
requireEmailVerification?: boolean;
|
|
19
|
+
requirePasswordResetEmailVerification?: boolean;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
interface ProviderEmailOtp {
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface ProviderPhoneOtp {
|
|
26
|
+
enabled?: boolean;
|
|
27
|
+
}
|
|
28
|
+
interface AuthConfigResponse {
|
|
29
|
+
disableSignUp?: boolean;
|
|
30
|
+
providerEmailPassword?: ProviderEmailPassword;
|
|
31
|
+
providerEmailOtp?: ProviderEmailOtp;
|
|
32
|
+
providerPhoneOtp?: ProviderPhoneOtp;
|
|
33
|
+
providerGoogle?: OAuthProviderBlock;
|
|
34
|
+
providerApple?: OAuthProviderBlock;
|
|
35
|
+
providerMicrosoft?: OAuthProviderBlock;
|
|
36
|
+
providerGithub?: OAuthProviderBlock;
|
|
37
|
+
providerGitlab?: OAuthProviderBlock;
|
|
38
|
+
providerDiscord?: OAuthProviderBlock;
|
|
39
|
+
}
|
|
40
|
+
export interface NormalizedAuthUIConfig {
|
|
41
|
+
disableSignUp: boolean;
|
|
42
|
+
emailPasswordEnabled: boolean;
|
|
43
|
+
emailOtpSignInEnabled: boolean;
|
|
44
|
+
/** SMS sign-in for +86 mobile numbers; only present for projects the platform enabled. */
|
|
45
|
+
phoneOtpSignInEnabled?: boolean;
|
|
46
|
+
minPasswordLength: number;
|
|
47
|
+
requireEmailVerification: boolean;
|
|
48
|
+
passwordResetEmailOtpEnabled: boolean;
|
|
49
|
+
oauthProviders: OAuthProviderId[];
|
|
50
|
+
/**
|
|
51
|
+
* Resolved Google OAuth Client ID when Google is enabled and both
|
|
52
|
+
* credentials resolved server-side; `null` otherwise. Signals that
|
|
53
|
+
* Google client-side wiring is ready.
|
|
54
|
+
*/
|
|
55
|
+
googleClientId: string | null;
|
|
56
|
+
isLocalDev: boolean;
|
|
57
|
+
}
|
|
58
|
+
export declare function loadNormalizedAuthUIConfig(): Promise<NormalizedAuthUIConfig>;
|
|
59
|
+
export declare function normalizeAuthUIConfig(config: AuthConfigResponse, isLocalDev?: boolean): NormalizedAuthUIConfig;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal helpers for driving Google Identity Services (One Tap) from the
|
|
3
|
+
* managed auth UI. Loads the GIS client script on demand and exposes a tiny
|
|
4
|
+
* typed surface around the global `google.accounts.id` namespace.
|
|
5
|
+
*
|
|
6
|
+
* GIS is treated as a UX enhancement: any load failure falls back silently
|
|
7
|
+
* to the regular "Continue with Google" OAuth button.
|
|
8
|
+
*/
|
|
9
|
+
interface GsiCredentialResponse {
|
|
10
|
+
credential: string;
|
|
11
|
+
select_by?: string;
|
|
12
|
+
}
|
|
13
|
+
interface GsiInitializeOptions {
|
|
14
|
+
client_id: string;
|
|
15
|
+
callback: (response: GsiCredentialResponse) => void;
|
|
16
|
+
auto_select?: boolean;
|
|
17
|
+
cancel_on_tap_outside?: boolean;
|
|
18
|
+
use_fedcm_for_prompt?: boolean;
|
|
19
|
+
context?: "signin" | "signup" | "use";
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Subset of Google's `PromptMomentNotification`. Methods are optional because
|
|
23
|
+
* GIS's FedCM-era roadmap retires some of them, and EdgeSpark does not depend
|
|
24
|
+
* on `@types/google.accounts` for the full type surface.
|
|
25
|
+
*/
|
|
26
|
+
interface GsiPromptNotification {
|
|
27
|
+
isNotDisplayed?: () => boolean;
|
|
28
|
+
isSkippedMoment?: () => boolean;
|
|
29
|
+
isDismissedMoment?: () => boolean;
|
|
30
|
+
getDismissedReason?: () => string | undefined;
|
|
31
|
+
}
|
|
32
|
+
interface GsiIdAccounts {
|
|
33
|
+
initialize(options: GsiInitializeOptions): void;
|
|
34
|
+
prompt(notificationCallback?: (notification: GsiPromptNotification) => void): void;
|
|
35
|
+
cancel(): void;
|
|
36
|
+
disableAutoSelect(): void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Loads `accounts.google.com/gsi/client` once per page and resolves with
|
|
40
|
+
* the `google.accounts.id` namespace. Subsequent calls return the same
|
|
41
|
+
* promise; load failures reject and reset so a caller can retry next mount.
|
|
42
|
+
*/
|
|
43
|
+
export declare function loadGoogleIdentityServices(): Promise<GsiIdAccounts>;
|
|
44
|
+
export type GoogleIdentityServices = GsiIdAccounts;
|
|
45
|
+
export type GoogleCredentialResponse = GsiCredentialResponse;
|
|
46
|
+
export type GooglePromptNotification = GsiPromptNotification;
|
|
47
|
+
export {};
|
|
@@ -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 { AuthenticatedAuthSuccessEvent, AuthSuccessEvent, AuthUILabelOverrides, AuthUILabels, ControlledAuthUIOptions, EdgeSparkAuthUI, MountAuthUIOptions, MountedAuthUI, OneTapPromptHandle, PromptGoogleOneTapOptions, RedirectAuthUIOptions, } from './types';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BetterAuthClientInstance } from '../auth/types';
|
|
2
|
+
import { EdgeSparkAuthUI } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Internal runtime config for the auth-UI module factory. Threads cross-cutting
|
|
5
|
+
* auth wiring into `ManagedAuthUI` (modal/redirect flows) and
|
|
6
|
+
* `promptGoogleOneTap` (page-load One Tap prompt).
|
|
7
|
+
*/
|
|
8
|
+
export interface AuthUIModuleRuntimeOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Best-effort hook to nudge the public auth session after the managed UI
|
|
11
|
+
* completes a sign-in. Used by `ManagedAuthUI`'s email and OAuth flows.
|
|
12
|
+
*/
|
|
13
|
+
syncPublicSession?: () => Promise<void> | void;
|
|
14
|
+
/**
|
|
15
|
+
* The public auth client used by `promptGoogleOneTap` for credential
|
|
16
|
+
* exchange. Routing One Tap through the same client as `signIn`/`signUp`
|
|
17
|
+
* keeps session updates and `onSessionChange` consistent across all
|
|
18
|
+
* sign-in methods.
|
|
19
|
+
*/
|
|
20
|
+
publicAuthClient: BetterAuthClientInstance;
|
|
21
|
+
}
|
|
22
|
+
export declare function createAuthUIModule(auth: BetterAuthClientInstance, runtimeOptions: AuthUIModuleRuntimeOptions): EdgeSparkAuthUI;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BetterAuthClientInstance } from '../auth/types';
|
|
2
|
+
import { EdgeSparkAuthError } from '../errors';
|
|
3
|
+
import { NormalizedAuthUIConfig } from './config';
|
|
4
|
+
import { AuthenticatedAuthSuccessEvent } from './types';
|
|
5
|
+
export interface PromptGoogleOneTapOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Fires when Google One Tap sign-in completes.
|
|
8
|
+
*
|
|
9
|
+
* **Most apps should prefer `client.auth.onSessionChange`** as the single
|
|
10
|
+
* source of truth — it fires for One Tap, modal sign-in, sign-out, and
|
|
11
|
+
* cross-tab session changes. Use `onSuccess` only for flow-local concerns
|
|
12
|
+
* scoped to this specific prompt (e.g., per-flow analytics).
|
|
13
|
+
*/
|
|
14
|
+
onSuccess?: (event: AuthenticatedAuthSuccessEvent) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Fires on credential-exchange or post-sign-in errors.
|
|
17
|
+
*/
|
|
18
|
+
onError?: (error: EdgeSparkAuthError) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Fires when Google declines to display the prompt — e.g., FedCM cooldown,
|
|
21
|
+
* no eligible accounts, or browser permission denied. Use this to render a
|
|
22
|
+
* fallback "Sign in with Google" button.
|
|
23
|
+
*/
|
|
24
|
+
onUnavailable?: () => void;
|
|
25
|
+
}
|
|
26
|
+
export interface OneTapPromptHandle {
|
|
27
|
+
/**
|
|
28
|
+
* Dismiss the prompt and suppress any pending callbacks. Idempotent and
|
|
29
|
+
* safe to call after the prompt has already closed.
|
|
30
|
+
*/
|
|
31
|
+
cancel(): void;
|
|
32
|
+
}
|
|
33
|
+
interface PromptRuntime {
|
|
34
|
+
/**
|
|
35
|
+
* The wrapped public auth client. Calls flow through its path-proxy so
|
|
36
|
+
* `oneTap.callback` triggers the same session-atom refresh and
|
|
37
|
+
* `onSessionChange` emit as `signIn`/`signUp`.
|
|
38
|
+
*/
|
|
39
|
+
authClient: BetterAuthClientInstance;
|
|
40
|
+
loadConfig: () => Promise<NormalizedAuthUIConfig>;
|
|
41
|
+
}
|
|
42
|
+
export declare function createPromptGoogleOneTap(runtime: PromptRuntime): (options?: PromptGoogleOneTapOptions) => OneTapPromptHandle;
|
|
43
|
+
export {};
|
|
@@ -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
|
+
}>;
|