@authhero/widget 0.7.2 → 0.8.0

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.
@@ -1,6 +1,6 @@
1
- import { EventEmitter } from '../../stencil-public-runtime';
2
- import type { UiScreen } from '../../types/components';
3
- import type { WidgetBranding, WidgetTheme } from '../../utils/branding';
1
+ import { EventEmitter } from "../../stencil-public-runtime";
2
+ import type { UiScreen } from "../../types/components";
3
+ import type { WidgetBranding, WidgetTheme } from "../../utils/branding";
4
4
  /**
5
5
  * Submit event detail - emitted when a form is submitted
6
6
  */
@@ -57,6 +57,22 @@ export interface ErrorEventDetail {
57
57
  /** Error code */
58
58
  code?: string;
59
59
  }
60
+ /**
61
+ * Auth params needed for social login and OAuth flows
62
+ */
63
+ export interface AuthParams {
64
+ client_id: string;
65
+ redirect_uri?: string;
66
+ scope?: string;
67
+ audience?: string;
68
+ nonce?: string;
69
+ response_type?: string;
70
+ state?: string;
71
+ }
72
+ /**
73
+ * State persistence mode - where to track state and screen
74
+ */
75
+ export type StatePersistence = "url" | "session" | "memory";
60
76
  export declare class AuthheroWidget {
61
77
  el: HTMLElement;
62
78
  /**
@@ -68,8 +84,43 @@ export declare class AuthheroWidget {
68
84
  /**
69
85
  * API endpoint to fetch the initial screen from.
70
86
  * If provided, the widget will fetch the screen on load.
87
+ * Can include {screenId} placeholder which will be replaced with the current screen.
88
+ * Example: "/u2/screen/{screenId}" or "https://auth.example.com/u2/screen/{screenId}"
71
89
  */
72
90
  apiUrl?: string;
91
+ /**
92
+ * Base URL for all API calls. Used when widget is embedded on a different domain.
93
+ * If not provided, relative URLs are used.
94
+ * Example: "https://auth.example.com"
95
+ */
96
+ baseUrl?: string;
97
+ /**
98
+ * Login session state token. Required for social login and maintaining session.
99
+ */
100
+ state?: string;
101
+ /**
102
+ * Current screen ID. Used with apiUrl to fetch screen configuration.
103
+ * When statePersistence is 'url', this is synced with the URL.
104
+ */
105
+ screenId?: string;
106
+ /**
107
+ * OAuth/OIDC parameters for social login redirects.
108
+ * Can be passed as a JSON string or object.
109
+ */
110
+ authParams?: AuthParams | string;
111
+ /**
112
+ * Where to persist state and screen ID.
113
+ * - 'url': Updates URL path/query (default for standalone pages)
114
+ * - 'session': Uses sessionStorage (for embedded widgets)
115
+ * - 'memory': No persistence, state only in memory
116
+ * @default 'memory'
117
+ */
118
+ statePersistence: StatePersistence;
119
+ /**
120
+ * Storage key prefix for session/local storage persistence.
121
+ * @default 'authhero_widget'
122
+ */
123
+ storageKey: string;
73
124
  /**
74
125
  * Branding configuration from AuthHero API.
75
126
  * Controls logo, primary color, and page background.
@@ -94,10 +145,21 @@ export declare class AuthheroWidget {
94
145
  * @default false
95
146
  */
96
147
  autoSubmit: boolean;
148
+ /**
149
+ * Whether the widget should handle navigation automatically.
150
+ * When true, social login buttons redirect, links navigate, etc.
151
+ * When false, only events are emitted.
152
+ * @default false (same as autoSubmit when not specified)
153
+ */
154
+ autoNavigate?: boolean;
97
155
  /**
98
156
  * Internal parsed screen state.
99
157
  */
100
158
  _screen?: UiScreen;
159
+ /**
160
+ * Internal parsed auth params state.
161
+ */
162
+ _authParams?: AuthParams;
101
163
  /**
102
164
  * Internal parsed branding state.
103
165
  */
@@ -146,15 +208,45 @@ export declare class AuthheroWidget {
146
208
  watchScreen(newValue: UiScreen | string | undefined): void;
147
209
  watchBranding(newValue: WidgetBranding | string | undefined): void;
148
210
  watchTheme(newValue: WidgetTheme | string | undefined): void;
211
+ watchAuthParams(newValue: AuthParams | string | undefined): void;
149
212
  /**
150
213
  * Apply branding and theme as CSS custom properties
151
214
  */
152
215
  private applyThemeStyles;
216
+ /**
217
+ * Get the effective autoNavigate value (defaults to autoSubmit if not set)
218
+ */
219
+ private get shouldAutoNavigate();
220
+ /**
221
+ * Build the full URL for API calls
222
+ */
223
+ private buildUrl;
224
+ /**
225
+ * Load state from URL or storage based on statePersistence setting
226
+ */
227
+ private loadPersistedState;
228
+ /**
229
+ * Save state to URL or storage based on statePersistence setting
230
+ */
231
+ private persistState;
153
232
  componentWillLoad(): Promise<void>;
154
- private fetchScreen;
233
+ /**
234
+ * Fetch screen configuration from the API
235
+ * @param screenIdOverride Optional screen ID to fetch (overrides this.screenId)
236
+ * @param nodeId Optional node ID for flow navigation
237
+ */
238
+ fetchScreen(screenIdOverride?: string, nodeId?: string): Promise<void>;
155
239
  private handleInputChange;
156
240
  private handleSubmit;
157
241
  private handleButtonClick;
242
+ /**
243
+ * Handle social login redirect
244
+ */
245
+ private handleSocialLogin;
246
+ /**
247
+ * Handle resend button click (e.g., resend OTP code)
248
+ */
249
+ private handleResend;
158
250
  private handleLinkClick;
159
251
  /**
160
252
  * Get error messages from the screen-level messages array.
@@ -6,11 +6,11 @@
6
6
  */
7
7
  import { HTMLStencilElement, JSXBase } from "./stencil-public-runtime";
8
8
  import { FormComponent, RuntimeComponent, UiScreen } from "./types/components";
9
+ import { AuthParams, ButtonClickEventDetail, CompleteEventDetail, ErrorEventDetail, LinkClickEventDetail, NavigateEventDetail, StatePersistence, SubmitEventDetail } from "./components/authhero-widget/authhero-widget";
9
10
  import { WidgetBranding, WidgetTheme } from "./utils/branding";
10
- import { ButtonClickEventDetail, CompleteEventDetail, ErrorEventDetail, LinkClickEventDetail, NavigateEventDetail, SubmitEventDetail } from "./components/authhero-widget/authhero-widget";
11
11
  export { FormComponent, RuntimeComponent, UiScreen } from "./types/components";
12
+ export { AuthParams, ButtonClickEventDetail, CompleteEventDetail, ErrorEventDetail, LinkClickEventDetail, NavigateEventDetail, StatePersistence, SubmitEventDetail } from "./components/authhero-widget/authhero-widget";
12
13
  export { WidgetBranding, WidgetTheme } from "./utils/branding";
13
- export { ButtonClickEventDetail, CompleteEventDetail, ErrorEventDetail, LinkClickEventDetail, NavigateEventDetail, SubmitEventDetail } from "./components/authhero-widget/authhero-widget";
14
14
  export namespace Components {
15
15
  interface AuthheroNode {
16
16
  /**
@@ -29,14 +29,27 @@ export namespace Components {
29
29
  }
30
30
  interface AuthheroWidget {
31
31
  /**
32
- * API endpoint to fetch the initial screen from. If provided, the widget will fetch the screen on load.
32
+ * API endpoint to fetch the initial screen from. If provided, the widget will fetch the screen on load. Can include {screenId} placeholder which will be replaced with the current screen. Example: "/u2/screen/{screenId}" or "https://auth.example.com/u2/screen/{screenId}"
33
33
  */
34
34
  "apiUrl"?: string;
35
+ /**
36
+ * OAuth/OIDC parameters for social login redirects. Can be passed as a JSON string or object.
37
+ */
38
+ "authParams"?: AuthParams | string;
39
+ /**
40
+ * Whether the widget should handle navigation automatically. When true, social login buttons redirect, links navigate, etc. When false, only events are emitted.
41
+ * @default false (same as autoSubmit when not specified)
42
+ */
43
+ "autoNavigate"?: boolean;
35
44
  /**
36
45
  * Whether the widget should automatically submit forms to the action URL. When false (default), the widget only emits events and the consuming application handles all HTTP requests. When true, the widget handles form submission and screen updates.
37
46
  * @default false
38
47
  */
39
48
  "autoSubmit": boolean;
49
+ /**
50
+ * Base URL for all API calls. Used when widget is embedded on a different domain. If not provided, relative URLs are used. Example: "https://auth.example.com"
51
+ */
52
+ "baseUrl"?: string;
40
53
  /**
41
54
  * Branding configuration from AuthHero API. Controls logo, primary color, and page background. Can be passed as a JSON string or object.
42
55
  */
@@ -50,6 +63,24 @@ export namespace Components {
50
63
  * The UI screen configuration from the server. Can be passed as a JSON string or object. Follows Auth0 Forms component schema.
51
64
  */
52
65
  "screen"?: UiScreen | string;
66
+ /**
67
+ * Current screen ID. Used with apiUrl to fetch screen configuration. When statePersistence is 'url', this is synced with the URL.
68
+ */
69
+ "screenId"?: string;
70
+ /**
71
+ * Login session state token. Required for social login and maintaining session.
72
+ */
73
+ "state"?: string;
74
+ /**
75
+ * Where to persist state and screen ID. - 'url': Updates URL path/query (default for standalone pages) - 'session': Uses sessionStorage (for embedded widgets) - 'memory': No persistence, state only in memory
76
+ * @default 'memory'
77
+ */
78
+ "statePersistence": StatePersistence;
79
+ /**
80
+ * Storage key prefix for session/local storage persistence.
81
+ * @default 'authhero_widget'
82
+ */
83
+ "storageKey": string;
53
84
  /**
54
85
  * Theme configuration from AuthHero API. Controls colors, borders, fonts, and layout. Can be passed as a JSON string or object.
55
86
  */
@@ -145,14 +176,27 @@ declare namespace LocalJSX {
145
176
  }
146
177
  interface AuthheroWidget {
147
178
  /**
148
- * API endpoint to fetch the initial screen from. If provided, the widget will fetch the screen on load.
179
+ * API endpoint to fetch the initial screen from. If provided, the widget will fetch the screen on load. Can include {screenId} placeholder which will be replaced with the current screen. Example: "/u2/screen/{screenId}" or "https://auth.example.com/u2/screen/{screenId}"
149
180
  */
150
181
  "apiUrl"?: string;
182
+ /**
183
+ * OAuth/OIDC parameters for social login redirects. Can be passed as a JSON string or object.
184
+ */
185
+ "authParams"?: AuthParams | string;
186
+ /**
187
+ * Whether the widget should handle navigation automatically. When true, social login buttons redirect, links navigate, etc. When false, only events are emitted.
188
+ * @default false (same as autoSubmit when not specified)
189
+ */
190
+ "autoNavigate"?: boolean;
151
191
  /**
152
192
  * Whether the widget should automatically submit forms to the action URL. When false (default), the widget only emits events and the consuming application handles all HTTP requests. When true, the widget handles form submission and screen updates.
153
193
  * @default false
154
194
  */
155
195
  "autoSubmit"?: boolean;
196
+ /**
197
+ * Base URL for all API calls. Used when widget is embedded on a different domain. If not provided, relative URLs are used. Example: "https://auth.example.com"
198
+ */
199
+ "baseUrl"?: string;
156
200
  /**
157
201
  * Branding configuration from AuthHero API. Controls logo, primary color, and page background. Can be passed as a JSON string or object.
158
202
  */
@@ -194,6 +238,24 @@ declare namespace LocalJSX {
194
238
  * The UI screen configuration from the server. Can be passed as a JSON string or object. Follows Auth0 Forms component schema.
195
239
  */
196
240
  "screen"?: UiScreen | string;
241
+ /**
242
+ * Current screen ID. Used with apiUrl to fetch screen configuration. When statePersistence is 'url', this is synced with the URL.
243
+ */
244
+ "screenId"?: string;
245
+ /**
246
+ * Login session state token. Required for social login and maintaining session.
247
+ */
248
+ "state"?: string;
249
+ /**
250
+ * Where to persist state and screen ID. - 'url': Updates URL path/query (default for standalone pages) - 'session': Uses sessionStorage (for embedded widgets) - 'memory': No persistence, state only in memory
251
+ * @default 'memory'
252
+ */
253
+ "statePersistence"?: StatePersistence;
254
+ /**
255
+ * Storage key prefix for session/local storage persistence.
256
+ * @default 'authhero_widget'
257
+ */
258
+ "storageKey"?: string;
197
259
  /**
198
260
  * Theme configuration from AuthHero API. Controls colors, borders, fonts, and layout. Can be passed as a JSON string or object.
199
261
  */