@returningai/widget-sdk 1.8.0 → 1.8.1
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 +17 -0
- package/dist/rai-banner.iife.js +1 -1
- package/dist/rai-banner.js +1 -1
- package/dist/rai-widget.iife.js +1 -1
- package/dist/rai-widget.js +18 -6
- package/dist/types/core/bundle-token-sync.d.ts +7 -0
- package/package.json +3 -2
package/dist/rai-widget.js
CHANGED
|
@@ -12812,6 +12812,20 @@ function warmBundleRuntime(globalName, bundleUrl) {
|
|
|
12812
12812
|
function getOrLoadBundleRuntime(globalName, bundleUrl) {
|
|
12813
12813
|
return loadBrowserBundleRuntime(globalName, bundleUrl);
|
|
12814
12814
|
}
|
|
12815
|
+
const BUNDLE_AUTH_TOKEN_CHANGE_EVENT = "authtoken-change";
|
|
12816
|
+
function syncBundleAccessToken(config, state, runtime = window) {
|
|
12817
|
+
if (!config.bundleUrl || !state.accessToken) return false;
|
|
12818
|
+
runtime.guest_token = state.accessToken;
|
|
12819
|
+
runtime.dispatchEvent(
|
|
12820
|
+
new CustomEvent(BUNDLE_AUTH_TOKEN_CHANGE_EVENT, {
|
|
12821
|
+
detail: {
|
|
12822
|
+
token: state.accessToken,
|
|
12823
|
+
widgetId: config.widgetId
|
|
12824
|
+
}
|
|
12825
|
+
})
|
|
12826
|
+
);
|
|
12827
|
+
return true;
|
|
12828
|
+
}
|
|
12815
12829
|
function assertCallbackName(callbackName) {
|
|
12816
12830
|
if (!callbackName || typeof callbackName !== "string") {
|
|
12817
12831
|
throw new TypeError("ReturningAI callback name must be a non-empty string");
|
|
@@ -14382,7 +14396,7 @@ class BaseWidget extends HTMLElement {
|
|
|
14382
14396
|
this.releaseAutoThemeDisableLease = acquireAutoThemeDisableLease();
|
|
14383
14397
|
}
|
|
14384
14398
|
const { bundleApiUrl, colorMode } = this.prepareBundleRuntimeEnvironment();
|
|
14385
|
-
|
|
14399
|
+
syncBundleAccessToken(this.config, this.state);
|
|
14386
14400
|
const globalName = WIDGET_GLOBALS[this.config.widgetType];
|
|
14387
14401
|
const widgetGlobal = await getOrLoadBundleRuntime(
|
|
14388
14402
|
globalName,
|
|
@@ -14486,9 +14500,7 @@ class BaseWidget extends HTMLElement {
|
|
|
14486
14500
|
const pushToken = () => {
|
|
14487
14501
|
if (this.state.iframe)
|
|
14488
14502
|
sendTokenToWidget(this.config, this.state, this.state.iframe);
|
|
14489
|
-
|
|
14490
|
-
window.guest_token = this.state.accessToken;
|
|
14491
|
-
}
|
|
14503
|
+
syncBundleAccessToken(this.config, this.state);
|
|
14492
14504
|
};
|
|
14493
14505
|
const doRefresh = async () => {
|
|
14494
14506
|
if (this.config.authUrl) {
|
|
@@ -14662,7 +14674,7 @@ class CustomWidget extends BaseWidget {
|
|
|
14662
14674
|
}
|
|
14663
14675
|
}
|
|
14664
14676
|
}
|
|
14665
|
-
console.log(`[rai-widget] v${"1.8.
|
|
14677
|
+
console.log(`[rai-widget] v${"1.8.1"}`);
|
|
14666
14678
|
class StoreWidgetCompat extends StoreWidget {
|
|
14667
14679
|
}
|
|
14668
14680
|
const WIDGET_REGISTRY = [
|
|
@@ -14726,7 +14738,7 @@ function exposePublicApi() {
|
|
|
14726
14738
|
})();
|
|
14727
14739
|
const widget = container == null ? void 0 : container.querySelector(ALL_WIDGET_SELECTOR);
|
|
14728
14740
|
window.ReturningAIWidget = {
|
|
14729
|
-
version: "1.8.
|
|
14741
|
+
version: "1.8.1",
|
|
14730
14742
|
reload: () => (widget == null ? void 0 : widget.reload()) ?? Promise.resolve(),
|
|
14731
14743
|
logout: () => (widget == null ? void 0 : widget.logoutPublic()) ?? Promise.resolve(),
|
|
14732
14744
|
isAuthenticated: () => (widget == null ? void 0 : widget.isAuthenticated()) ?? false,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { WidgetConfig, WidgetState } from "../types";
|
|
2
|
+
export declare const BUNDLE_AUTH_TOKEN_CHANGE_EVENT = "authtoken-change";
|
|
3
|
+
export type BundleTokenRuntime = EventTarget & {
|
|
4
|
+
guest_token?: string;
|
|
5
|
+
};
|
|
6
|
+
/** Publish a refreshed access token to a mounted no-iframe widget bundle. */
|
|
7
|
+
export declare function syncBundleAccessToken(config: WidgetConfig, state: WidgetState, runtime?: BundleTokenRuntime): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@returningai/widget-sdk",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.1",
|
|
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,10 +25,11 @@
|
|
|
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: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: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
|
+
"test:bundle-token-sync": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/bundle-token-sync.test.js",
|
|
32
33
|
"test:auth-bootstrap": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/auth-bootstrap.test.js",
|
|
33
34
|
"test:jsx-types": "tsc --noEmit --strict --lib ES2020,DOM --skipLibCheck false src/jsx.d.ts",
|
|
34
35
|
"coverage:repowise": "rm -rf coverage && npm run coverage:host-callback && npm run coverage:bundle-readiness && npm run test:jsx-types",
|