@returningai/widget-sdk 1.2.15 → 1.3.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.
- package/README.md +505 -527
- package/dist/rai-widget.iife.js +1 -1
- package/dist/rai-widget.js +401 -120
- package/dist/types/BaseWidget.d.ts +50 -9
- package/dist/types/core/auth.d.ts +10 -2
- package/dist/types/types.d.ts +19 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WidgetConfig } from
|
|
1
|
+
import type { WidgetConfig } from "./types";
|
|
2
2
|
export declare function readConfig(el: Element, existingId?: string): WidgetConfig;
|
|
3
3
|
export declare abstract class BaseWidget extends HTMLElement {
|
|
4
4
|
protected shadow: ShadowRoot;
|
|
@@ -15,22 +15,63 @@ export declare abstract class BaseWidget extends HTMLElement {
|
|
|
15
15
|
connectedCallback(): void;
|
|
16
16
|
disconnectedCallback(): void;
|
|
17
17
|
private emit;
|
|
18
|
+
/**
|
|
19
|
+
* Apply widget-defined CSS colors before first paint so the loader uses
|
|
20
|
+
* the community's actual theme — not generic light/dark — from frame 1.
|
|
21
|
+
*
|
|
22
|
+
* Priority:
|
|
23
|
+
* 1. Cached themePalette (synchronous localStorage read)
|
|
24
|
+
* 2. HTML attribute hints (`bg`, `text`, `accent`)
|
|
25
|
+
* 3. Generic light/dark fallback (--rai-* vars set in connectedCallback)
|
|
26
|
+
*
|
|
27
|
+
* After the API response arrives, fetchAndRenderLoader() re-applies the
|
|
28
|
+
* fresh palette via applyPaletteFromState(). On every load except the
|
|
29
|
+
* absolute first-ever, the cached palette is already correct.
|
|
30
|
+
*/
|
|
31
|
+
private applyFirstPaintColors;
|
|
32
|
+
private applyFont;
|
|
33
|
+
private applyPalette;
|
|
18
34
|
private renderShell;
|
|
19
35
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
36
|
+
* Loads the community loading animation + theme palette from cache or API
|
|
37
|
+
* and renders the animation above the "Loading ..." text. The text is
|
|
38
|
+
* already painted by renderShell so this method only ADDS the animation;
|
|
39
|
+
* users see two states at most: text-only → text + animation.
|
|
24
40
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
41
|
+
* Stale-while-revalidate:
|
|
42
|
+
* - Cache hit → apply palette & render animation synchronously, fire
|
|
43
|
+
* background refresh.
|
|
44
|
+
* - Cache miss → text remains visible; await network; apply palette
|
|
45
|
+
* + render animation when response arrives.
|
|
28
46
|
*/
|
|
29
47
|
private fetchAndRenderLoader;
|
|
30
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Append the loading animation above the text. Removes any previous
|
|
50
|
+
* animation first so this is safe to call repeatedly (e.g. after a
|
|
51
|
+
* background refresh changes the configured loader).
|
|
52
|
+
*/
|
|
53
|
+
private renderLoaderAnimation;
|
|
54
|
+
private renderLottieInto;
|
|
31
55
|
private createDefaultLoader;
|
|
32
56
|
private createPresetLoader;
|
|
33
57
|
private hideLoader;
|
|
58
|
+
/**
|
|
59
|
+
* Bundle mode: keep the SDK loader visible until React has actually
|
|
60
|
+
* painted into `container`, eliminating the brief bg-color gap that
|
|
61
|
+
* happens when the loader is removed before the React app's first frame.
|
|
62
|
+
*
|
|
63
|
+
* Strategy:
|
|
64
|
+
* 1. MutationObserver fires when React commits any DOM mutation into
|
|
65
|
+
* the container — synchronous inside mount(), but the callback runs
|
|
66
|
+
* as a microtask, so it observes the first child addition.
|
|
67
|
+
* 2. requestAnimationFrame waits one paint cycle so the React content
|
|
68
|
+
* is actually visible before the SDK loader fades out.
|
|
69
|
+
* 3. 2s fallback covers silent React mount errors so the loader doesn't
|
|
70
|
+
* hang forever.
|
|
71
|
+
*
|
|
72
|
+
* Calls hideLoader() (with its 300ms fade-out) so the transition is smooth.
|
|
73
|
+
*/
|
|
74
|
+
private deferLoaderRemovalUntilReactPaints;
|
|
34
75
|
private showError;
|
|
35
76
|
private renderCustomError;
|
|
36
77
|
private init;
|
|
@@ -4,7 +4,15 @@ export declare function authenticateViaProxy(config: WidgetConfig, state: Widget
|
|
|
4
4
|
export declare function refreshAccessToken(config: WidgetConfig, state: WidgetState, onRefreshScheduled?: () => void, sendToken?: () => void): Promise<boolean>;
|
|
5
5
|
export declare function getValidToken(config: WidgetConfig, state: WidgetState, onRefreshScheduled?: () => void): Promise<string>;
|
|
6
6
|
export declare function logout(config: WidgetConfig, state: WidgetState): Promise<void>;
|
|
7
|
-
export declare function
|
|
8
|
-
|
|
7
|
+
export declare function applyErrorSettingsToState(state: WidgetState, data: Record<string, unknown>): void;
|
|
8
|
+
/**
|
|
9
|
+
* Fetches widget error settings + community loading animation.
|
|
10
|
+
*
|
|
11
|
+
* Stale-while-revalidate: serves from cache instantly when present (no TTL).
|
|
12
|
+
* Pass { skipCache: true } to force a network fetch (used for background refresh).
|
|
13
|
+
*/
|
|
14
|
+
export declare function fetchErrorSettings(config: WidgetConfig, state: WidgetState, opts?: {
|
|
15
|
+
skipCache?: boolean;
|
|
16
|
+
}): Promise<typeof state.errorSettings>;
|
|
9
17
|
declare function clearState(state: WidgetState): void;
|
|
10
18
|
export { clearState };
|
package/dist/types/types.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface WidgetConfig {
|
|
|
11
11
|
widgetId: string;
|
|
12
12
|
widgetType: 'store' | 'channel' | 'milestone' | 'social' | 'currency-view' | 'referral-conditions' | 'custom';
|
|
13
13
|
theme: 'light' | 'dark';
|
|
14
|
+
themeExplicit: boolean;
|
|
14
15
|
container: string;
|
|
15
16
|
width: string;
|
|
16
17
|
height: string;
|
|
@@ -31,6 +32,13 @@ export interface WidgetConfig {
|
|
|
31
32
|
embedToken?: string;
|
|
32
33
|
v2ApiUrl?: string;
|
|
33
34
|
domainKey?: string;
|
|
35
|
+
loadingText: string;
|
|
36
|
+
firstPaintColors?: {
|
|
37
|
+
bg?: string;
|
|
38
|
+
text?: string;
|
|
39
|
+
accent?: string;
|
|
40
|
+
};
|
|
41
|
+
firstPaintFont?: string;
|
|
34
42
|
}
|
|
35
43
|
export interface WidgetState {
|
|
36
44
|
accessToken: string | null;
|
|
@@ -49,6 +57,11 @@ export interface WidgetState {
|
|
|
49
57
|
modalColor?: string;
|
|
50
58
|
backgroundImage?: string;
|
|
51
59
|
} | null;
|
|
60
|
+
lastAuthError: {
|
|
61
|
+
status: number;
|
|
62
|
+
error?: string;
|
|
63
|
+
hint?: string;
|
|
64
|
+
} | null;
|
|
52
65
|
loadingAnimation: {
|
|
53
66
|
type?: string;
|
|
54
67
|
preset?: string;
|
|
@@ -68,6 +81,12 @@ export interface WidgetState {
|
|
|
68
81
|
};
|
|
69
82
|
};
|
|
70
83
|
} | null;
|
|
84
|
+
themePalette: {
|
|
85
|
+
light?: Record<string, string>;
|
|
86
|
+
dark?: Record<string, string>;
|
|
87
|
+
} | null;
|
|
88
|
+
font: string | null;
|
|
89
|
+
defaultColorSchema: 'light' | 'dark' | null;
|
|
71
90
|
}
|
|
72
91
|
export interface TokenData {
|
|
73
92
|
accessToken: string;
|