@edgespark/web 0.0.0-beta.4ec283e

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.
Files changed (40) hide show
  1. package/README.md +310 -0
  2. package/auth/styles/styles.css +402 -0
  3. package/dist/api/fetch.d.ts +8 -0
  4. package/dist/api/types.d.ts +13 -0
  5. package/dist/auth/create-auth.d.ts +18 -0
  6. package/dist/auth/local-dev.d.ts +41 -0
  7. package/dist/auth/placeholder-email.d.ts +7 -0
  8. package/dist/auth/types.d.ts +84 -0
  9. package/dist/auth-ui/ManagedAuthUI.d.ts +114 -0
  10. package/dist/auth-ui/appearance.d.ts +64 -0
  11. package/dist/auth-ui/config.d.ts +60 -0
  12. package/dist/auth-ui/default-labels.d.ts +2 -0
  13. package/dist/auth-ui/google-one-tap.d.ts +47 -0
  14. package/dist/auth-ui/index.d.ts +4 -0
  15. package/dist/auth-ui/mount.d.ts +22 -0
  16. package/dist/auth-ui/prompt-google-one-tap.d.ts +43 -0
  17. package/dist/auth-ui/runtime.d.ts +7 -0
  18. package/dist/auth-ui/types.d.ts +202 -0
  19. package/dist/browser.d.ts +2 -0
  20. package/dist/client.d.ts +43 -0
  21. package/dist/errors.d.ts +32 -0
  22. package/dist/index.cjs +197 -0
  23. package/dist/index.d.ts +29 -0
  24. package/dist/index.es.js +2994 -0
  25. package/dist/locales/ar.d.ts +2 -0
  26. package/dist/locales/de.d.ts +2 -0
  27. package/dist/locales/en-US.d.ts +2 -0
  28. package/dist/locales/es.d.ts +2 -0
  29. package/dist/locales/fr.d.ts +2 -0
  30. package/dist/locales/hi.d.ts +2 -0
  31. package/dist/locales/index.d.ts +21 -0
  32. package/dist/locales/it.d.ts +2 -0
  33. package/dist/locales/ja.d.ts +2 -0
  34. package/dist/locales/ko.d.ts +2 -0
  35. package/dist/locales/pt-BR.d.ts +2 -0
  36. package/dist/locales/ru.d.ts +2 -0
  37. package/dist/locales/zh-CN.d.ts +2 -0
  38. package/dist/redirect.d.ts +5 -0
  39. package/dist/shared/types.d.ts +6 -0
  40. package/package.json +53 -0
@@ -0,0 +1,202 @@
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
+ import { OneTapPromptHandle, PromptGoogleOneTapOptions } from './prompt-google-one-tap';
7
+ export type { OneTapPromptHandle, PromptGoogleOneTapOptions } from './prompt-google-one-tap';
8
+ /** Sign-in or sign-up completed with an authenticated session. */
9
+ export type AuthenticatedAuthSuccessEvent = {
10
+ action: "sign-in";
11
+ user: AuthUser;
12
+ session: AuthSession;
13
+ } | {
14
+ action: "sign-up";
15
+ user: AuthUser;
16
+ session: AuthSession;
17
+ };
18
+ /** Password was reset. No session — the user must sign in again. */
19
+ export interface PasswordResetSuccessEvent {
20
+ action: "password-reset";
21
+ user: null;
22
+ session: null;
23
+ }
24
+ /**
25
+ * Payload emitted by `onSuccess` after a managed auth flow completes.
26
+ *
27
+ * Switch on `event.action` to narrow `user` and `session`:
28
+ * - `"sign-in"` / `"sign-up"` → `user: AuthUser`, `session: AuthSession`
29
+ * - `"password-reset"` → `user: null`, `session: null`
30
+ */
31
+ export type AuthSuccessEvent = AuthenticatedAuthSuccessEvent | PasswordResetSuccessEvent;
32
+ export interface AuthUILabels {
33
+ common: {
34
+ loading: string;
35
+ redirecting: string;
36
+ backToSignIn: string;
37
+ };
38
+ signIn: {
39
+ title: string;
40
+ subtitle: string;
41
+ emailLabel: string;
42
+ emailPlaceholder?: string;
43
+ codePlaceholder?: string;
44
+ sendingCode?: string;
45
+ signingIn?: string;
46
+ passwordLabel: string;
47
+ codeLabel?: string;
48
+ submitButton: string;
49
+ sendCodeButton?: string;
50
+ verifyCodeButton?: string;
51
+ resendCodeButton?: string;
52
+ resendCountdown?: string;
53
+ passwordTab?: string;
54
+ codeTab?: string;
55
+ phoneTab?: string;
56
+ phoneLabel?: string;
57
+ phonePlaceholder?: string;
58
+ phoneCodePlaceholder?: string;
59
+ forgotPassword: string;
60
+ switchToSignUp: string;
61
+ signUpPrompt: string;
62
+ };
63
+ signUp: {
64
+ title: string;
65
+ subtitle: string;
66
+ nameLabel: string;
67
+ emailLabel: string;
68
+ passwordLabel: string;
69
+ confirmPasswordLabel: string;
70
+ submitButton: string;
71
+ switchToSignIn: string;
72
+ signInPrompt: string;
73
+ };
74
+ verifyEmail: {
75
+ title: string;
76
+ subtitle: string;
77
+ sentToLabel: string;
78
+ resendButton: string;
79
+ resendCountdown: string;
80
+ changeEmailButton: string;
81
+ };
82
+ forgotPassword: {
83
+ title: string;
84
+ subtitle: string;
85
+ emailLabel: string;
86
+ submitButton: string;
87
+ };
88
+ resetPassword: {
89
+ title: string;
90
+ subtitle: string;
91
+ codeLabel: string;
92
+ newPasswordLabel: string;
93
+ confirmPasswordLabel: string;
94
+ submitButton: string;
95
+ resendCodeButton: string;
96
+ resendCountdown: string;
97
+ };
98
+ oauth: {
99
+ dividerText: string;
100
+ continueWith: string;
101
+ /** Use {provider} for the provider display name. */
102
+ redirecting?: string;
103
+ };
104
+ errors: {
105
+ invalidEmail: string;
106
+ requiredField: string;
107
+ passwordTooShort: string;
108
+ passwordMismatch: string;
109
+ invalidCode: string;
110
+ invalidPhone?: string;
111
+ smsRateLimited?: string;
112
+ smsSendFailed?: string;
113
+ generic: string;
114
+ };
115
+ }
116
+ export type AuthUILabelOverrides = DeepPartial<AuthUILabels>;
117
+ /** Sign-in form methods: email + password, email code, or SMS code. */
118
+ export type AuthUISignInMethod = "password" | "otp" | "phone";
119
+ interface BaseAuthUIOptions {
120
+ onError?: (error: EdgeSparkAuthError) => void;
121
+ labels?: AuthUILabelOverrides;
122
+ /**
123
+ * Limits which sign-in form methods are offered, e.g. to show SMS sign-in
124
+ * only to some visitors. Methods the project's auth config does not enable
125
+ * are never shown. Omit to offer every enabled method.
126
+ */
127
+ signInMethods?: readonly AuthUISignInMethod[];
128
+ /**
129
+ * Optional, constrained visual customization for the managed auth UI.
130
+ *
131
+ * This is intentionally smaller than the headless auth path. Use
132
+ * `client.auth` when the app needs full UI ownership.
133
+ */
134
+ appearance?: AuthUIAppearance;
135
+ }
136
+ /**
137
+ * Redirect mode — use when the auth UI is a full-page login gate.
138
+ *
139
+ * After successful auth the SDK navigates to `redirectTo` automatically.
140
+ * This is the common case: dedicated `/login` page → redirect to `/dashboard`.
141
+ *
142
+ * `onSuccess` is optional and fires *before* the redirect (useful for analytics).
143
+ */
144
+ export interface RedirectAuthUIOptions extends BaseAuthUIOptions {
145
+ redirectTo: RedirectTarget;
146
+ onSuccess?: (event: AuthSuccessEvent) => void;
147
+ }
148
+ /**
149
+ * Controlled mode — use when the app owns what happens after auth.
150
+ *
151
+ * The SDK will not navigate. Instead, `onSuccess` fires with the auth event
152
+ * and the app decides the next step (close a modal, update state, navigate
153
+ * programmatically via a router, etc.).
154
+ *
155
+ * Use this for: modals, embedded auth widgets, SPA routing, onboarding flows.
156
+ */
157
+ export interface ControlledAuthUIOptions extends BaseAuthUIOptions {
158
+ onSuccess: (event: AuthSuccessEvent) => void;
159
+ redirectTo?: never;
160
+ }
161
+ /**
162
+ * Two post-auth strategies — pick one:
163
+ *
164
+ * - **Redirect mode** (`{ redirectTo }`) — SDK navigates after auth.
165
+ * Best for dedicated login pages.
166
+ *
167
+ * - **Controlled mode** (`{ onSuccess }`) — app handles post-auth behavior.
168
+ * Best for modals, embedded widgets, or SPA routing.
169
+ */
170
+ export type MountAuthUIOptions = RedirectAuthUIOptions | ControlledAuthUIOptions;
171
+ export interface MountedAuthUI {
172
+ /**
173
+ * Removes the mounted UI and clears internal timers/listeners.
174
+ */
175
+ destroy(): void;
176
+ }
177
+ export interface EdgeSparkAuthUI {
178
+ /**
179
+ * Mounts the managed auth UI into a container element.
180
+ *
181
+ * Pass `redirectTo` for the common login-page case, or `onSuccess` when the
182
+ * surrounding app wants to control routing/state after auth completes.
183
+ */
184
+ mount(container: HTMLElement, options: MountAuthUIOptions): MountedAuthUI;
185
+ /**
186
+ * Triggers a Google One Tap prompt. Calling the function is the opt-in —
187
+ * there is no separate server config or option flag.
188
+ *
189
+ * The prompt shows only when Google is fully wired server-side (the
190
+ * project's `auth-config.yaml` enables Google with resolvable credentials).
191
+ * Otherwise the call logs a clear error to the console and returns an
192
+ * inert handle.
193
+ *
194
+ * @example
195
+ * useEffect(() => {
196
+ * if (session) return;
197
+ * const prompt = client.authUI.promptGoogleOneTap();
198
+ * return () => prompt.cancel();
199
+ * }, [session]);
200
+ */
201
+ promptGoogleOneTap(options?: PromptGoogleOneTapOptions): OneTapPromptHandle;
202
+ }
@@ -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;