@widgetic/embed-sdk 0.0.0-stage → 2.0.7

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 (89) hide show
  1. package/README.md +567 -2
  2. package/dist/browser/chunks/ABTestManager.js +1 -0
  3. package/dist/browser/chunks/advanced.js +1 -0
  4. package/dist/browser/chunks/api.js +1 -0
  5. package/dist/browser/chunks/core.js +1 -0
  6. package/dist/browser/chunks/display.js +1 -0
  7. package/dist/browser/chunks/media.js +1 -0
  8. package/dist/browser/chunks/messaging.js +1 -0
  9. package/dist/browser/chunks/performance.js +1 -0
  10. package/dist/browser/chunks/renderers.js +1 -0
  11. package/dist/browser/chunks/scanner.js +1 -0
  12. package/dist/browser/chunks/security.js +1 -0
  13. package/dist/browser/chunks/vendor.js +1 -0
  14. package/dist/browser/embed-bootstrap.js +1 -0
  15. package/dist/browser/embed-sdk.js +1 -0
  16. package/dist/esm/chunks/ABTestManager.js +1 -0
  17. package/dist/esm/chunks/advanced.js +1 -0
  18. package/dist/esm/chunks/api.js +1 -0
  19. package/dist/esm/chunks/core.js +1 -0
  20. package/dist/esm/chunks/display.js +1 -0
  21. package/dist/esm/chunks/media.js +1 -0
  22. package/dist/esm/chunks/messaging.js +1 -0
  23. package/dist/esm/chunks/performance.js +1 -0
  24. package/dist/esm/chunks/renderers.js +1 -0
  25. package/dist/esm/chunks/scanner.js +1 -0
  26. package/dist/esm/chunks/security.js +1 -0
  27. package/dist/esm/chunks/vendor.js +1 -0
  28. package/dist/esm/embed-bootstrap.js +1 -0
  29. package/dist/esm/embed-sdk.js +1 -0
  30. package/dist/esm/types/abTesting/ABTestElement.d.ts +120 -0
  31. package/dist/esm/types/abTesting/ABTestManager.d.ts +177 -0
  32. package/dist/esm/types/api/batch-client.d.ts +163 -0
  33. package/dist/esm/types/api/layers.d.ts +119 -0
  34. package/dist/esm/types/core/advanced-security-manager.d.ts +330 -0
  35. package/dist/esm/types/core/analytics-tracker.d.ts +224 -0
  36. package/dist/esm/types/core/auth-detector.d.ts +65 -0
  37. package/dist/esm/types/core/auth-manager.d.ts +90 -0
  38. package/dist/esm/types/core/autoscale-manager.d.ts +91 -0
  39. package/dist/esm/types/core/breakpoints.d.ts +48 -0
  40. package/dist/esm/types/core/config.d.ts +152 -0
  41. package/dist/esm/types/core/constants.d.ts +75 -0
  42. package/dist/esm/types/core/content-position-manager.d.ts +228 -0
  43. package/dist/esm/types/core/custom-element.d.ts +152 -0
  44. package/dist/esm/types/core/display-manager.d.ts +109 -0
  45. package/dist/esm/types/core/editor-overlay.d.ts +113 -0
  46. package/dist/esm/types/core/embed-sdk.d.ts +310 -0
  47. package/dist/esm/types/core/exit-intent-trigger.d.ts +114 -0
  48. package/dist/esm/types/core/lazy-loader.d.ts +111 -0
  49. package/dist/esm/types/core/media-manager.d.ts +364 -0
  50. package/dist/esm/types/core/messaging.d.ts +251 -0
  51. package/dist/esm/types/core/overlay-manager.d.ts +119 -0
  52. package/dist/esm/types/core/performance-monitor.d.ts +152 -0
  53. package/dist/esm/types/core/privacy-compliance.d.ts +236 -0
  54. package/dist/esm/types/core/realtime-manager.d.ts +279 -0
  55. package/dist/esm/types/core/resize-handler.d.ts +81 -0
  56. package/dist/esm/types/core/resource-optimizer.d.ts +133 -0
  57. package/dist/esm/types/core/responsive-manager.d.ts +49 -0
  58. package/dist/esm/types/core/scroll-trigger.d.ts +105 -0
  59. package/dist/esm/types/core/security-manager.d.ts +150 -0
  60. package/dist/esm/types/core/text-field-manager.d.ts +204 -0
  61. package/dist/esm/types/core/token-provider.d.ts +75 -0
  62. package/dist/esm/types/core/trigger-defaults.d.ts +36 -0
  63. package/dist/esm/types/core/trigger-manager.d.ts +248 -0
  64. package/dist/esm/types/core/types.d.ts +473 -0
  65. package/dist/esm/types/core/ui-sdk-loader.d.ts +90 -0
  66. package/dist/esm/types/core/widget-manager.d.ts +285 -0
  67. package/dist/esm/types/core/widget-metadata.d.ts +107 -0
  68. package/dist/esm/types/embed-sdk.d.ts +31 -0
  69. package/dist/esm/types/loaders/module-loader.d.ts +147 -0
  70. package/dist/esm/types/renderers/custom-element-renderer.d.ts +78 -0
  71. package/dist/esm/types/renderers/iframe-renderer.d.ts +185 -0
  72. package/dist/esm/types/renderers/widget-renderer.d.ts +173 -0
  73. package/dist/esm/types/sdk/embed-bootstrap.d.ts +84 -0
  74. package/dist/esm/types/sdk/embed-sdk.d.ts +31 -0
  75. package/dist/esm/types/translations/TranslationElement.d.ts +93 -0
  76. package/dist/esm/types/utils/browser.d.ts +29 -0
  77. package/dist/esm/types/utils/caseConversion.d.ts +2 -0
  78. package/dist/esm/types/utils/css-debug.d.ts +105 -0
  79. package/dist/esm/types/utils/device-detector.d.ts +100 -0
  80. package/dist/esm/types/utils/event-emitter.d.ts +14 -0
  81. package/dist/esm/types/utils/hydrate-published-host.d.ts +17 -0
  82. package/dist/esm/types/utils/logger.d.ts +31 -0
  83. package/dist/esm/types/utils/parser.d.ts +39 -0
  84. package/dist/esm/types/utils/portal.d.ts +74 -0
  85. package/dist/esm/types/utils/public-embed-lookup.d.ts +68 -0
  86. package/dist/esm/types/utils/published-host-display.d.ts +61 -0
  87. package/dist/umd/embed-bootstrap.js +1 -0
  88. package/dist/umd/embed-sdk.js +1 -0
  89. package/package.json +154 -4
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Token Provider System
3
+ *
4
+ * Provides secure token management for the SDK by allowing runtime token retrieval
5
+ * instead of embedding API keys directly in client-side code.
6
+ */
7
+ export interface TokenProvider {
8
+ /**
9
+ * Retrieves a valid token for API requests
10
+ * @returns Promise<string> - A Bearer token or API key
11
+ */
12
+ getToken(): Promise<string>;
13
+ /**
14
+ * Optional: Refresh token if it's expired
15
+ * @returns Promise<string> - A new Bearer token
16
+ */
17
+ refreshToken?(): Promise<string>;
18
+ /**
19
+ * Optional: Check if token is valid/not expired
20
+ * @returns Promise<boolean>
21
+ */
22
+ isTokenValid?(): Promise<boolean>;
23
+ }
24
+ /**
25
+ * Static API Key Provider - for development/testing only
26
+ * NOT recommended for production use
27
+ */
28
+ export declare class StaticApiKeyProvider implements TokenProvider {
29
+ private apiKey;
30
+ constructor(apiKey: string);
31
+ getToken(): Promise<string>;
32
+ isTokenValid(): Promise<boolean>;
33
+ }
34
+ /**
35
+ * Endpoint Token Provider - fetches tokens from your backend
36
+ * Recommended for production use
37
+ */
38
+ export declare class EndpointTokenProvider implements TokenProvider {
39
+ private tokenEndpoint;
40
+ private refreshEndpoint?;
41
+ private cachedToken?;
42
+ private tokenExpiry?;
43
+ private headers;
44
+ constructor(options: {
45
+ tokenEndpoint?: string;
46
+ endpoint?: string;
47
+ refreshEndpoint?: string;
48
+ headers?: Record<string, string>;
49
+ apiKey?: string;
50
+ });
51
+ getToken(): Promise<string>;
52
+ refreshToken(): Promise<string>;
53
+ isTokenValid(): Promise<boolean>;
54
+ }
55
+ /**
56
+ * Function Token Provider - uses a custom function to get tokens
57
+ * Flexible option for custom token retrieval logic
58
+ */
59
+ export declare class FunctionTokenProvider implements TokenProvider {
60
+ private tokenFunction;
61
+ private validationFunction?;
62
+ constructor(tokenFunction: () => Promise<string>, validationFunction?: () => Promise<boolean>);
63
+ getToken(): Promise<string>;
64
+ isTokenValid(): Promise<boolean>;
65
+ }
66
+ /**
67
+ * Default token provider that falls back to environment variables
68
+ * Used when no custom token provider is configured
69
+ */
70
+ export declare class DefaultTokenProvider implements TokenProvider {
71
+ private apiKey?;
72
+ constructor(apiKey?: string);
73
+ getToken(): Promise<string>;
74
+ isTokenValid(): Promise<boolean>;
75
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Trigger defaults shared by the attribute parser and the TriggerManager.
3
+ *
4
+ * Kept in a module of their own, with no imports, so `core/trigger-manager`
5
+ * does not have to depend on `utils/parser` (or the other way round) just to
6
+ * agree on a number.
7
+ */
8
+ /**
9
+ * How long the `delay` event trigger waits when the embed does not say
10
+ * (`trigger-delay`, milliseconds). Three seconds is long enough to be read as
11
+ * "after a moment" rather than as part of the page load.
12
+ */
13
+ export declare const DEFAULT_TRIGGER_DELAY_MS = 3000;
14
+ /**
15
+ * Ceiling for `trigger-delay`. `setTimeout` stores its delay in 32 bits and
16
+ * fires immediately for anything larger, so an absurd value would turn "wait
17
+ * very long" into "show now". A day is already far beyond a useful delay.
18
+ */
19
+ export declare const MAX_TRIGGER_DELAY_MS: number;
20
+ /**
21
+ * How far the visitor scrolls before the `scroll` event trigger fires when the
22
+ * embed does not say (`trigger-scroll-distance`, pixels). Matches the distance
23
+ * `ScrollTrigger` has always used as its own default.
24
+ */
25
+ export declare const DEFAULT_TRIGGER_SCROLL_DISTANCE_PX = 100;
26
+ /**
27
+ * Stacking order of the overlay layer when the embed does not state one
28
+ * (`overlay-z-index`). The same value the design system's Portal uses, so an
29
+ * embed that says nothing keeps sitting above everything else on the page.
30
+ */
31
+ export declare const DEFAULT_OVERLAY_Z_INDEX = 99999999;
32
+ /**
33
+ * Largest `z-index` a browser honours (a signed 32-bit integer). A bigger
34
+ * number is not "even higher": it is invalid, and the declaration is dropped.
35
+ */
36
+ export declare const MAX_OVERLAY_Z_INDEX = 2147483647;
@@ -0,0 +1,248 @@
1
+ /**
2
+ * Trigger Manager
3
+ * Manages widget display triggers and modes (site, mixed, overlay)
4
+ * Handles seamless transitions between inline and overlay display using Portal
5
+ */
6
+ import type { TriggerConfig } from "./types.js";
7
+ export type DisplayMode = 'site' | 'mixed' | 'overlay';
8
+ export interface TriggerManagerOptions {
9
+ widgetId: string;
10
+ element: HTMLElement;
11
+ config: TriggerConfig;
12
+ /**
13
+ * The `display` the widget element gets when the overlay reveals it. The
14
+ * default, an empty string, hands the choice back to the stylesheet, which is
15
+ * right for an element that already has a display of its own. A `<widgetic>`
16
+ * host has none: an unknown element is inline, and an inline box ignores the
17
+ * width and height of what it wraps. The code that hosts one passes `block`.
18
+ */
19
+ displayWhenShown?: string;
20
+ }
21
+ /**
22
+ * Manages widget display triggers and mode transitions
23
+ */
24
+ export declare class TriggerManager {
25
+ private widgetId;
26
+ private element;
27
+ private config;
28
+ private mode;
29
+ private scrollTrigger;
30
+ private exitIntentTrigger;
31
+ private portal;
32
+ private overlayContainer;
33
+ private originalParent;
34
+ private originalNextSibling;
35
+ private placeholder;
36
+ private isInOverlay;
37
+ private isDestroyed;
38
+ private triggerInstances;
39
+ private keydownListener;
40
+ private recurrenceManager;
41
+ private displayWhenShown;
42
+ private delayTimer;
43
+ private domReadyListener;
44
+ private fullWidthRestore;
45
+ private readonly onTriggerActivated;
46
+ private readonly onTriggerDeactivated;
47
+ private readonly onOverlayClose;
48
+ constructor(options: TriggerManagerOptions);
49
+ /**
50
+ * Get default trigger configuration
51
+ */
52
+ private getDefaultConfig;
53
+ /**
54
+ * Initialize trigger system based on mode
55
+ */
56
+ private initialize;
57
+ /**
58
+ * Arm whatever the embed chose to bring the overlay in.
59
+ *
60
+ * `exitIntent` and an unset trigger keep the behaviour the trigger system has
61
+ * always had: distance scrolling and exit intent are both armed, and either
62
+ * one shows the overlay. The newer values arm only what they name, because an
63
+ * embed that asked for a scroll trigger must not also pop up when the pointer
64
+ * leaves the window.
65
+ */
66
+ private armOverlayEventTrigger;
67
+ /**
68
+ * Run `callback` once the DOM has finished parsing, or right away if it
69
+ * already has. The pending listener is kept so destroy() can take it back.
70
+ */
71
+ private whenDomReady;
72
+ /**
73
+ * Show the overlay once the page is ready.
74
+ *
75
+ * This is the Embed Editor's `pageLoad` event trigger. It deliberately goes
76
+ * through `showOverlay()` rather than revealing the element directly, so both
77
+ * choices in that dropdown pass the same recurrence gate: an overlay that has
78
+ * already used up its views must not reappear on the next page load.
79
+ */
80
+ private showOnLoad;
81
+ /**
82
+ * Show the overlay a fixed time after the page is ready (`event-trigger="delay"`).
83
+ *
84
+ * Like `showOnLoad`, it goes through `showOverlay()` so the recurrence gate
85
+ * applies. The wait starts once the DOM is ready rather than when this manager
86
+ * was built, so a slow parse does not eat into the delay. It fires once:
87
+ * closing the overlay does not bring it back on the timer.
88
+ */
89
+ private showAfterDelay;
90
+ /**
91
+ * Initialize scroll trigger
92
+ */
93
+ private initializeScrollTrigger;
94
+ /**
95
+ * Initialize exit intent trigger
96
+ */
97
+ private initializeExitIntentTrigger;
98
+ /**
99
+ * Bind trigger events
100
+ */
101
+ private bindEvents;
102
+ /**
103
+ * Handle trigger activation
104
+ */
105
+ private handleTriggerActivated;
106
+ /**
107
+ * Handle trigger deactivation
108
+ */
109
+ private handleTriggerDeactivated;
110
+ /**
111
+ * Handle overlay close request
112
+ */
113
+ private handleOverlayClose;
114
+ /**
115
+ * Handle escape key press
116
+ */
117
+ private handleEscapeKey;
118
+ /**
119
+ * Show widget in overlay mode
120
+ */
121
+ private showOverlay;
122
+ /**
123
+ * Mixed mode: leave a same-sized, invisible stand-in where the widget is about
124
+ * to leave from, and watch that instead of the widget.
125
+ *
126
+ * The widget in the overlay is on screen, so a viewport watch that stayed on
127
+ * it would report "back in view" the moment it arrived, send it home (out of
128
+ * view again), and repeat on every scroll. The stand-in stays in the page, so
129
+ * it is in view exactly when the widget's own place is. It also keeps the page
130
+ * from jumping, because the widget's height would otherwise leave the flow.
131
+ */
132
+ private leavePlaceholder;
133
+ /**
134
+ * Mixed mode: put the widget back exactly where its stand-in is.
135
+ *
136
+ * Returns false when there is nothing to return to (not mixed mode, or the
137
+ * page removed the stand-in), and the caller falls back to the position the
138
+ * manager remembered.
139
+ */
140
+ private returnToPlaceholder;
141
+ /**
142
+ * Hide overlay and return widget to original position
143
+ */
144
+ private hideOverlay;
145
+ /**
146
+ * Hide widget completely (for overlay mode initial state)
147
+ */
148
+ private hideWidget;
149
+ /**
150
+ * Create overlay container with positioning and styling
151
+ */
152
+ private createOverlayContainer;
153
+ /**
154
+ * Apply background styling to overlay container
155
+ */
156
+ private applyBackgroundStyling;
157
+ /**
158
+ * Does the overlay carry a full-viewport background layer (a backdrop)?
159
+ */
160
+ private hasOverlayBackground;
161
+ /**
162
+ * The stacking order of the overlay layer: the embed's `overlay-z-index` when
163
+ * it states a usable one, the design system's Portal value otherwise.
164
+ */
165
+ private getOverlayZIndex;
166
+ /**
167
+ * Get overlay positioning styles
168
+ *
169
+ * Centering uses auto margins between opposite edges rather than
170
+ * `left: 50%` plus a `transform`. A transformed element becomes the
171
+ * containing block of its `position: fixed` descendants, so with a transform
172
+ * the backdrop inside a centered overlay was measured from the overlay's own
173
+ * corner instead of the viewport's, and no longer covered the screen.
174
+ *
175
+ * With `fullWidth` the overlay is a bar: the horizontal axis is stretched
176
+ * edge to edge, and the vertical edge is flush (the offset is ignored).
177
+ */
178
+ private getOverlayStyles;
179
+ /**
180
+ * Make the widget fill a full-width bar.
181
+ *
182
+ * A published iframe carries a fixed `width` attribute, which the bar's own
183
+ * width cannot override, so the widget and its iframe are told to fill their
184
+ * container. What was changed is remembered, so hiding the overlay can give
185
+ * the inline layout back untouched.
186
+ */
187
+ private applyFullWidthSizing;
188
+ /**
189
+ * Undo applyFullWidthSizing
190
+ */
191
+ private restoreFullWidthSizing;
192
+ /**
193
+ * Create close button for overlay with SVG X icon
194
+ */
195
+ private createCloseButton;
196
+ /**
197
+ * Create SVG X icon for close button
198
+ */
199
+ private createCloseSVG;
200
+ /**
201
+ * Dispatch trigger event
202
+ */
203
+ private dispatchTriggerEvent;
204
+ /**
205
+ * Dispatch custom event
206
+ */
207
+ private dispatchEvent;
208
+ /**
209
+ * Update trigger configuration
210
+ */
211
+ updateConfig(newConfig: Partial<TriggerConfig>): void;
212
+ /**
213
+ * Get current trigger stats
214
+ */
215
+ getStats(): any;
216
+ /**
217
+ * Force show overlay (for testing/manual trigger)
218
+ */
219
+ forceShowOverlay(): void;
220
+ /**
221
+ * Force hide overlay (for testing/manual trigger)
222
+ */
223
+ forceHideOverlay(): void;
224
+ /**
225
+ * Get recurrence statistics
226
+ */
227
+ getRecurrenceStats(): any;
228
+ /**
229
+ * Clear recurrence history for this widget
230
+ */
231
+ clearRecurrenceHistory(): void;
232
+ /**
233
+ * Check if overlay can be shown based on recurrence limits
234
+ */
235
+ canShowOverlay(): boolean;
236
+ /**
237
+ * Destroy trigger manager and clean up
238
+ */
239
+ destroy(): void;
240
+ /**
241
+ * Apply overlay-specific styling for mixed mode widgets
242
+ */
243
+ private applyOverlayWidgetStyling;
244
+ /**
245
+ * Apply overlay-specific resize mode to container
246
+ */
247
+ private applyOverlayResizeMode;
248
+ }