@returningai/widget-sdk 1.8.1 → 1.8.2

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.
@@ -6,6 +6,8 @@ export declare abstract class BaseWidget extends HTMLElement {
6
6
  protected config: WidgetConfig;
7
7
  private state;
8
8
  private loaderEl;
9
+ private loaderHeightRestore;
10
+ private loaderHeightObserver;
9
11
  private errorEl;
10
12
  private msgEl;
11
13
  private cleanupListener?;
@@ -16,10 +18,10 @@ export declare abstract class BaseWidget extends HTMLElement {
16
18
  private hasAttemptedInit;
17
19
  private initGeneration;
18
20
  private lottieInstances;
19
- private renderedLoaderAnimationKey;
20
21
  private callbackRegistry;
21
22
  private bannerNode;
22
23
  private releaseAutoThemeDisableLease?;
24
+ private bundleUnmount?;
23
25
  constructor();
24
26
  registerCallback<K extends keyof ReturningAIWidgetCallbackMap>(callbackName: K, callback: ReturningAIWidgetCallbackMap[K]): void;
25
27
  registerCallback(callbackName: string, callback: ReturningAIWidgetCallback): void;
@@ -53,17 +55,14 @@ export declare abstract class BaseWidget extends HTMLElement {
53
55
  private applyFont;
54
56
  private applyPalette;
55
57
  private applyLoadingSettings;
56
- private getLoadingAnimationRenderKey;
57
58
  private renderShell;
58
59
  /**
59
60
  * Loads the community loading animation + theme palette from cache or API
60
61
  * and renders the configured animation above the loading text.
61
62
  *
62
- * Stale-while-revalidate:
63
- * - Cache hit → apply palette & render animation synchronously, fire
64
- * background refresh.
65
- * - Cache miss → retain the initial shell; await network; apply palette +
66
- * render the resolved animation or fallback.
63
+ * Cached settings are applied synchronously. On a first visit, settings load
64
+ * alongside authentication so the generic loader stays hidden until the
65
+ * configured animation is known. This request never blocks widget launch.
67
66
  */
68
67
  private fetchAndRenderLoader;
69
68
  /**
@@ -77,6 +76,14 @@ export declare abstract class BaseWidget extends HTMLElement {
77
76
  private createDefaultLoader;
78
77
  private createPresetLoader;
79
78
  private hideLoader;
79
+ /**
80
+ * Keep percentage-based iframe embeds at their resolved startup height while
81
+ * the SDK loader is visible. The child iframe may resize during auth/data
82
+ * loading; without this pin the loader's 100% centering moves with the host.
83
+ */
84
+ private freezeIframeLoaderHeight;
85
+ private deferIframeLoaderHeightFreeze;
86
+ private restoreLoaderHeight;
80
87
  /**
81
88
  * Resolve after a legacy bundle's first rendered child has reached a paint.
82
89
  * This remains the fallback for bundles that do not expose a deep-ready
@@ -2,7 +2,12 @@ export declare const BUNDLE_READY_TIMEOUT_MS = 30000;
2
2
  export interface BundleMountReadyHandle {
3
3
  ready: PromiseLike<void>;
4
4
  }
5
+ export interface BundleMountUnmountHandle {
6
+ unmount: () => void;
7
+ }
5
8
  export type BundleMountReadiness = "deep-ready" | "first-paint";
9
+ export declare function resolveBundleMountResult(mountResult: unknown, timeoutMs?: number): Promise<unknown>;
10
+ export declare function createBundleMountCleanup(mountResult: unknown): (() => void) | undefined;
6
11
  /**
7
12
  * Wait for the strongest readiness signal a bundle provides.
8
13
  *
@@ -8,9 +8,22 @@ interface BundleRuntimeLoaderOptions {
8
8
  }
9
9
  interface BundleRuntimeWarmerOptions {
10
10
  preloadScript: (url: string) => Promise<void>;
11
+ preloadBundleAssets?: (bundleUrl: string) => Promise<void>;
11
12
  baseUrl: () => string;
12
13
  }
13
- export declare function createBundleRuntimeWarmer({ preloadScript, baseUrl, }: BundleRuntimeWarmerOptions): (globalName: string, bundleUrl: string) => void;
14
+ interface BundlePreloadManifest {
15
+ version: 1;
16
+ scripts?: unknown;
17
+ styles?: unknown;
18
+ }
19
+ export interface BundlePreloadAsset {
20
+ url: string;
21
+ rel: "modulepreload" | "preload";
22
+ as: "script" | "style";
23
+ }
24
+ /** Resolve and constrain optional deep-preload assets advertised beside a bundle. */
25
+ export declare function resolveBundlePreloadAssets(bundleUrl: string, manifest: BundlePreloadManifest): BundlePreloadAsset[];
26
+ export declare function createBundleRuntimeWarmer({ preloadScript, preloadBundleAssets, baseUrl, }: BundleRuntimeWarmerOptions): (globalName: string, bundleUrl: string) => void;
14
27
  export declare function normalizeBundleUrl(url: string, baseUrl: string): string;
15
28
  /**
16
29
  * Cache widget runtimes by both their window global and normalized bundle URL.
@@ -0,0 +1,12 @@
1
+ export declare const SUPPORTED_WIDGET_LANGUAGES: readonly ["en", "de", "es", "fr", "it", "pt", "pl", "da", "nl", "ru", "chs", "el", "ko", "cht", "th", "ja", "id", "vt", "ms", "hi", "fil", "ta", "tr", "ar", "mn", "sw"];
2
+ /**
3
+ * Normalizes a BCP 47 language tag to the locale codes used by ReturningAI.
4
+ * Returns undefined when an explicit value cannot be mapped to a supported
5
+ * widget language.
6
+ */
7
+ export declare function resolveWidgetLanguage(language?: string | null): string | undefined;
8
+ /**
9
+ * Invalid language overrides are customer configuration errors, so surface
10
+ * them once per distinct value even when verbose SDK logging is disabled.
11
+ */
12
+ export declare function warnUnsupportedWidgetLanguage(language: string): void;
@@ -0,0 +1,13 @@
1
+ export declare function parsePercentageHeight(value: string): number | null;
2
+ export declare function resolvePercentageViewportHeight(value: string, viewportHeight: number): number;
3
+ /**
4
+ * Return a responsive fallback only when restoring the original height leaves
5
+ * a rendered embed collapsed. Percentage embeds use vh so viewport changes do
6
+ * not leave them permanently pinned to their startup pixel measurement.
7
+ */
8
+ export declare function resolveCollapsedRestoredHeight({ originalHeight, restoredHeight, resolvedHeight, isRendered, }: {
9
+ originalHeight: string;
10
+ restoredHeight: number;
11
+ resolvedHeight: number;
12
+ isRendered: boolean;
13
+ }): string | null;
@@ -0,0 +1,23 @@
1
+ import type { WidgetConfig } from "../types";
2
+ interface PreconnectDocument {
3
+ head: {
4
+ appendChild(link: PreconnectLink): unknown;
5
+ };
6
+ createElement(tagName: "link"): PreconnectLink;
7
+ getElementById(id: string): unknown;
8
+ }
9
+ interface PreconnectLink {
10
+ id: string;
11
+ rel: string;
12
+ href: string;
13
+ crossOrigin: string;
14
+ }
15
+ /** Let successful auth launch immediately while preserving configured auth errors. */
16
+ export declare function resolveStartupAuthentication(authentication: Promise<boolean>, loadErrorSettings: (options?: {
17
+ skipCache?: boolean;
18
+ }) => Promise<unknown>): Promise<boolean>;
19
+ /** Return the unique HTTP origins involved in widget startup. */
20
+ export declare function resolveWidgetPreconnectOrigins(config: WidgetConfig, baseUrl: string): string[];
21
+ /** Add deduplicated, anonymous preconnect hints without initiating script execution. */
22
+ export declare function ensureWidgetPreconnects(origins: string[], targetDocument?: PreconnectDocument): void;
23
+ export {};
@@ -15,6 +15,8 @@ interface RaiWidgetAttributes {
15
15
  'v2-api-url'?: string
16
16
  'embed-token'?: string
17
17
  'auth-url'?: string
18
+ language?: string
19
+ locale?: string
18
20
  'auto-refresh'?: string
19
21
  'data-container'?: string
20
22
  debug?: string
@@ -153,6 +153,12 @@ export interface WidgetConfig {
153
153
  maxRetries: number;
154
154
  retryDelay: number;
155
155
  heightDebounce: number;
156
+ /**
157
+ * Normalized, supported widget language. Explicit unsupported values are
158
+ * omitted so the widget falls back to the browser language.
159
+ */
160
+ language?: string;
161
+ /** @deprecated Use language. Kept for existing data-locale embeds. */
156
162
  locale?: string;
157
163
  customData?: Record<string, unknown>;
158
164
  authUrl?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@returningai/widget-sdk",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "description": "Shadow DOM isolated widget SDK for ReturningAI",
5
5
  "main": "dist/rai-widget.iife.js",
6
6
  "module": "dist/rai-widget.js",
@@ -25,12 +25,13 @@
25
25
  "build:all": "npm run build && npm run build:banner",
26
26
  "build:all:min": "npm run build:min && npm run build:banner:min",
27
27
  "types": "tsc --emitDeclarationOnly --outDir dist/types && cp src/jsx.d.ts dist/types/jsx.d.ts",
28
- "test": "npm run test:host-callback && npm run test:bundle-readiness && npm run test:bundle-runtime-cache && npm run test:bundle-token-sync && npm run test:auth-bootstrap && npm run test:jsx-types",
28
+ "test": "npm run test:host-callback && npm run test:bundle-readiness && npm run test:bundle-runtime-cache && npm run test:bundle-token-sync && npm run test:auth-bootstrap && npm run test:startup-performance && npm run test:jsx-types",
29
29
  "test:host-callback": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/postmessage-host-callback.test.js",
30
30
  "test:bundle-readiness": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/bundle-readiness.test.js",
31
31
  "test:bundle-runtime-cache": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/bundle-runtime-cache.test.js",
32
32
  "test:bundle-token-sync": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/bundle-token-sync.test.js",
33
33
  "test:auth-bootstrap": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/auth-bootstrap.test.js",
34
+ "test:startup-performance": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/startup-performance.test.js",
34
35
  "test:jsx-types": "tsc --noEmit --strict --lib ES2020,DOM --skipLibCheck false src/jsx.d.ts",
35
36
  "coverage:repowise": "rm -rf coverage && npm run coverage:host-callback && npm run coverage:bundle-readiness && npm run test:jsx-types",
36
37
  "coverage:host-callback": "rm -rf test/.tmp && tsc -p test/tsconfig.json && c8 --reporter=lcov --reports-dir=coverage/host-callback --exclude-after-remap --exclude='**/*.test.ts' node test/.tmp/test/postmessage-host-callback.test.js && node scripts/name-lcov-test.mjs coverage/host-callback/lcov.info test/postmessage-host-callback.test.ts",
@@ -47,4 +48,4 @@
47
48
  "dompurify": "^3.4.12",
48
49
  "lottie-web": "^5.13.0"
49
50
  }
50
- }
51
+ }