@returningai/widget-sdk 1.8.4 → 1.8.6
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/CHANGELOG.md +29 -0
- package/dist/rai-banner.iife.js +1 -1
- package/dist/rai-banner.js +1 -1
- package/dist/rai-widget.iife.js +2 -2
- package/dist/rai-widget.js +396 -79
- package/dist/types/BaseWidget.d.ts +6 -9
- package/dist/types/core/auth-renewal-recovery.d.ts +19 -0
- package/dist/types/core/auth.d.ts +1 -0
- package/dist/types/core/bundle-readiness.d.ts +19 -2
- package/dist/types/core/widget-error-presentation.d.ts +15 -0
- package/package.json +4 -2
|
@@ -22,7 +22,9 @@ export declare abstract class BaseWidget extends HTMLElement {
|
|
|
22
22
|
private bannerNode;
|
|
23
23
|
private releaseAutoThemeDisableLease?;
|
|
24
24
|
private bundleUnmount?;
|
|
25
|
+
private cancelBundleForegroundRecovery?;
|
|
25
26
|
private authSession?;
|
|
27
|
+
private authRenewalRecovery;
|
|
26
28
|
constructor();
|
|
27
29
|
registerCallback<K extends keyof ReturningAIWidgetCallbackMap>(callbackName: K, callback: ReturningAIWidgetCallbackMap[K]): void;
|
|
28
30
|
registerCallback(callbackName: string, callback: ReturningAIWidgetCallback): void;
|
|
@@ -110,17 +112,12 @@ export declare abstract class BaseWidget extends HTMLElement {
|
|
|
110
112
|
private prepareBundleRuntimeEnvironment;
|
|
111
113
|
private mountWidget;
|
|
112
114
|
private scheduleRefresh;
|
|
115
|
+
private performScheduledRefresh;
|
|
113
116
|
private schedulePeriodicSync;
|
|
114
117
|
/**
|
|
115
|
-
* A background refresh
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* Every startup auth path already calls showError() on failure; this one is
|
|
120
|
-
* reached from a timer, so without it the widget stays mounted showing stale
|
|
121
|
-
* content while isAuthenticated() reports false to the host page — which is
|
|
122
|
-
* how a signed-in user ends up looking at content meant for signed-out users.
|
|
123
|
-
* The event gives hosts a signal to re-mint credentials instead of polling.
|
|
118
|
+
* A background refresh reached a confirmed permanent authentication failure
|
|
119
|
+
* after exhausting its safe recovery paths. Transient transport, throttling,
|
|
120
|
+
* and server failures are retained by authRenewalRecovery instead.
|
|
124
121
|
*/
|
|
125
122
|
private handleSessionExpired;
|
|
126
123
|
private logoutAndClear;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WidgetState } from "../types";
|
|
2
|
+
export interface AuthRenewalRecoveryEnvironment {
|
|
3
|
+
isHidden: () => boolean;
|
|
4
|
+
setTimeout: (callback: () => void, delayMs: number) => unknown;
|
|
5
|
+
clearTimeout: (timerId: unknown) => void;
|
|
6
|
+
addVisibilityChangeListener: (listener: () => void) => void;
|
|
7
|
+
removeVisibilityChangeListener: (listener: () => void) => void;
|
|
8
|
+
addPageShowListener: (listener: () => void) => void;
|
|
9
|
+
removePageShowListener: (listener: () => void) => void;
|
|
10
|
+
addOnlineListener: (listener: () => void) => void;
|
|
11
|
+
removeOnlineListener: (listener: () => void) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface AuthRenewalRecoveryController {
|
|
14
|
+
schedule(): void;
|
|
15
|
+
succeeded(): void;
|
|
16
|
+
cancel(): void;
|
|
17
|
+
}
|
|
18
|
+
export declare function isPermanentAuthFailure(error: WidgetState["lastAuthError"]): boolean;
|
|
19
|
+
export declare function createAuthRenewalRecoveryController(retry: () => Promise<void> | void, environment?: AuthRenewalRecoveryEnvironment): AuthRenewalRecoveryController;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { WidgetConfig, WidgetState } from '../types';
|
|
2
|
+
export declare function calculateRefreshDelay(accessTokenExpiry: number, now?: number): number;
|
|
2
3
|
export declare function authenticateServerless(config: WidgetConfig, state: WidgetState, onRefreshScheduled?: () => void): Promise<boolean>;
|
|
3
4
|
export declare function authenticateViaProxy(config: WidgetConfig, state: WidgetState, onRefreshScheduled?: () => void): Promise<boolean>;
|
|
4
5
|
export declare function refreshAccessToken(config: WidgetConfig, state: WidgetState, onRefreshScheduled?: () => void, sendToken?: () => void): Promise<boolean>;
|
|
@@ -6,7 +6,24 @@ export interface BundleMountUnmountHandle {
|
|
|
6
6
|
unmount: () => void;
|
|
7
7
|
}
|
|
8
8
|
export type BundleMountReadiness = "deep-ready" | "first-paint";
|
|
9
|
-
export
|
|
9
|
+
export type BundleReadinessPhase = "mount" | "deep-ready";
|
|
10
|
+
export interface BundleReadinessEnvironment {
|
|
11
|
+
isHidden: () => boolean;
|
|
12
|
+
now: () => number;
|
|
13
|
+
setTimeout: (callback: () => void, delayMs: number) => unknown;
|
|
14
|
+
clearTimeout: (timerId: unknown) => void;
|
|
15
|
+
addVisibilityChangeListener: (listener: () => void) => void;
|
|
16
|
+
removeVisibilityChangeListener: (listener: () => void) => void;
|
|
17
|
+
addPageShowListener: (listener: () => void) => void;
|
|
18
|
+
removePageShowListener: (listener: () => void) => void;
|
|
19
|
+
}
|
|
20
|
+
export declare class BundleReadinessTimeoutError extends Error {
|
|
21
|
+
readonly phase: BundleReadinessPhase;
|
|
22
|
+
constructor(phase: BundleReadinessPhase, message: string);
|
|
23
|
+
}
|
|
24
|
+
export declare function isBundleReadinessTimeoutError(error: unknown): error is BundleReadinessTimeoutError;
|
|
25
|
+
export declare function scheduleForegroundRecovery(recover: () => void, environment?: BundleReadinessEnvironment): () => void;
|
|
26
|
+
export declare function resolveBundleMountResult(mountResult: unknown, timeoutMs?: number, environment?: BundleReadinessEnvironment): Promise<unknown>;
|
|
10
27
|
export declare function createBundleMountCleanup(mountResult: unknown): (() => void) | undefined;
|
|
11
28
|
/**
|
|
12
29
|
* Wait for the strongest readiness signal a bundle provides.
|
|
@@ -17,4 +34,4 @@ export declare function createBundleMountCleanup(mountResult: unknown): (() => v
|
|
|
17
34
|
* to an object with a `ready` promise. Legacy bundles keep the first-paint
|
|
18
35
|
* behavior unchanged.
|
|
19
36
|
*/
|
|
20
|
-
export declare function waitForBundleMountReadiness(mountResult: unknown, firstPaint: PromiseLike<void>, timeoutMs?: number): Promise<BundleMountReadiness>;
|
|
37
|
+
export declare function waitForBundleMountReadiness(mountResult: unknown, firstPaint: PromiseLike<void>, timeoutMs?: number, environment?: BundleReadinessEnvironment): Promise<BundleMountReadiness>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { WidgetState } from "../types";
|
|
2
|
+
export type WidgetFailureKind = "authentication" | "bundle";
|
|
3
|
+
export interface WidgetErrorPresentationInput {
|
|
4
|
+
failureKind: WidgetFailureKind;
|
|
5
|
+
customMessage?: string | null;
|
|
6
|
+
lastAuthError: WidgetState["lastAuthError"];
|
|
7
|
+
}
|
|
8
|
+
export interface WidgetErrorPresentation {
|
|
9
|
+
useCustomMessage: boolean;
|
|
10
|
+
displayMessage: string;
|
|
11
|
+
emittedMessage: string;
|
|
12
|
+
hint?: string;
|
|
13
|
+
status?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare function selectWidgetErrorPresentation({ failureKind, customMessage, lastAuthError, }: WidgetErrorPresentationInput): WidgetErrorPresentation;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@returningai/widget-sdk",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.6",
|
|
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,7 +25,7 @@
|
|
|
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:auth-error-reporting && npm run test:auth-refresh-state && npm run test:auth-session-coordinator && npm run test:startup-performance && 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:auth-error-reporting && npm run test:auth-refresh-state && npm run test:auth-renewal-recovery && npm run test:auth-session-coordinator && npm run test:startup-performance && npm run test:widget-error-presentation && 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",
|
|
@@ -33,8 +33,10 @@
|
|
|
33
33
|
"test:auth-bootstrap": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/auth-bootstrap.test.js",
|
|
34
34
|
"test:auth-error-reporting": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/auth-error-reporting.test.js",
|
|
35
35
|
"test:auth-refresh-state": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/auth-refresh-state.test.js",
|
|
36
|
+
"test:auth-renewal-recovery": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/auth-renewal-recovery.test.js",
|
|
36
37
|
"test:auth-session-coordinator": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/auth-session-coordinator.test.js",
|
|
37
38
|
"test:startup-performance": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/startup-performance.test.js",
|
|
39
|
+
"test:widget-error-presentation": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/widget-error-presentation.test.js",
|
|
38
40
|
"test:jsx-types": "tsc --noEmit --strict --lib ES2020,DOM --skipLibCheck false src/jsx.d.ts",
|
|
39
41
|
"coverage:repowise": "rm -rf coverage && npm run coverage:host-callback && npm run coverage:bundle-readiness && npm run test:jsx-types",
|
|
40
42
|
"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",
|