@yuno-payments/dashboard-embed-sdk 1.4.0-BETA.8 → 1.4.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 +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +31 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ destroyDashboard();
|
|
|
70
70
|
| `token` | `string` | No | JWT auth token — sent via PostMessage after the iframe is ready |
|
|
71
71
|
| `theme` | `DashboardTheme` | No | Initial theme configuration |
|
|
72
72
|
| `lang` | `string` | No | Language code (default: `"en"`) |
|
|
73
|
-
| `path` | `string` | No | Initial navigation path (default: `"/"`).
|
|
73
|
+
| `path` | `string` | No | Initial navigation path (default: `"/"`). Any query string you pass is stripped — only the SDK sets the iframe query params (embed/theme/lang/test) |
|
|
74
74
|
| `testMode` | `boolean` | No | When set, the dashboard mounts in test/sandbox mode (`true`) or live mode (`false`). Omit to inherit the dashboard's own default. See [Test mode](#test-mode) |
|
|
75
75
|
| `onReady` | `() => void` | No | Callback invoked when the dashboard is fully loaded and authenticated |
|
|
76
76
|
| `onSessionExpired` | `() => void` | No | Callback invoked when the embedded session has expired. The host should re-authenticate and call `setToken(newToken)` to resume. |
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
// src/dashboard.ts
|
|
2
2
|
var EMBED_EVENT_MESSAGE_TYPE = "yuno-dashboard:embed-event";
|
|
3
3
|
var HOST_CAPABILITIES_MESSAGE_TYPE = "yuno-dashboard:host-capabilities";
|
|
4
|
+
var OVERLAY_FADE = "opacity 0.15s ease";
|
|
5
|
+
var OVERLAY_REVEAL_DELAY_MS = 100;
|
|
6
|
+
function stripQueryParams(path) {
|
|
7
|
+
const queryIndex = path.indexOf("?");
|
|
8
|
+
if (queryIndex < 0) return path;
|
|
9
|
+
const hashIndex = path.indexOf("#", queryIndex);
|
|
10
|
+
const hash = hashIndex >= 0 ? path.slice(hashIndex) : "";
|
|
11
|
+
return path.slice(0, queryIndex) + hash;
|
|
12
|
+
}
|
|
4
13
|
function buildCapabilities(events) {
|
|
5
14
|
const capabilities = {};
|
|
6
15
|
if (!events) return capabilities;
|
|
@@ -56,7 +65,10 @@ var Dashboard = class {
|
|
|
56
65
|
this.wrapper.appendChild(this.overlay);
|
|
57
66
|
this.messageHandler = (e) => {
|
|
58
67
|
if (e.origin !== this.baseUrl) return;
|
|
59
|
-
if (this.autoHeight &&
|
|
68
|
+
if (this.autoHeight && // Ignore content-height resizes while an overlay is open — the iframe is
|
|
69
|
+
// pinned full-viewport, and applying a height would break the overlay
|
|
70
|
+
// and leave a stale wrapper height after it closes.
|
|
71
|
+
this.overlayCount === 0 && e.data?.action === "resize" && typeof e.data?.height === "number") {
|
|
60
72
|
this.iframe.style.height = `${e.data.height}px`;
|
|
61
73
|
this.wrapper.style.height = `${e.data.height}px`;
|
|
62
74
|
return;
|
|
@@ -104,7 +116,7 @@ var Dashboard = class {
|
|
|
104
116
|
this.post({ action: "setToken", token });
|
|
105
117
|
}
|
|
106
118
|
navigate(path) {
|
|
107
|
-
this.post({ action: "navigate", path });
|
|
119
|
+
this.post({ action: "navigate", path: stripQueryParams(path) });
|
|
108
120
|
}
|
|
109
121
|
setTestMode(enabled) {
|
|
110
122
|
this.post({ action: "setTestMode", testMode: enabled });
|
|
@@ -185,30 +197,30 @@ var Dashboard = class {
|
|
|
185
197
|
// Transparent so the host page shows through wherever the dashboard
|
|
186
198
|
// doesn't paint (the offset regions).
|
|
187
199
|
background: "transparent",
|
|
188
|
-
//
|
|
189
|
-
//
|
|
190
|
-
//
|
|
191
|
-
// animate the hide and leave the reflow visible mid-fade) and fade it
|
|
192
|
-
// back in once the inset has settled.
|
|
200
|
+
// Hide instantly (no transition — a transition would animate the hide and
|
|
201
|
+
// leave the reflow visible mid-fade), then fade back in once the inset has
|
|
202
|
+
// settled, masking the cross-document expand→inset reflow.
|
|
193
203
|
transition: "none",
|
|
194
204
|
opacity: "0"
|
|
195
205
|
});
|
|
196
206
|
this.post({ action: "overlay-mode", active: true, offset });
|
|
197
|
-
|
|
198
|
-
this.overlayRevealTimer = setTimeout(() => {
|
|
199
|
-
this.iframe.style.transition = "opacity 0.15s ease";
|
|
200
|
-
this.iframe.style.opacity = "1";
|
|
201
|
-
this.overlayRevealTimer = null;
|
|
202
|
-
}, 100);
|
|
207
|
+
this.scheduleReveal();
|
|
203
208
|
}
|
|
204
209
|
restoreIframe() {
|
|
205
|
-
if (this.overlayRevealTimer) {
|
|
206
|
-
clearTimeout(this.overlayRevealTimer);
|
|
207
|
-
this.overlayRevealTimer = null;
|
|
208
|
-
}
|
|
209
210
|
this.iframe.style.cssText = this.savedIframeCss ?? "";
|
|
210
211
|
this.savedIframeCss = null;
|
|
212
|
+
this.iframe.style.transition = "none";
|
|
213
|
+
this.iframe.style.opacity = "0";
|
|
211
214
|
this.post({ action: "overlay-mode", active: false });
|
|
215
|
+
this.scheduleReveal();
|
|
216
|
+
}
|
|
217
|
+
scheduleReveal() {
|
|
218
|
+
if (this.overlayRevealTimer) clearTimeout(this.overlayRevealTimer);
|
|
219
|
+
this.overlayRevealTimer = setTimeout(() => {
|
|
220
|
+
this.iframe.style.transition = OVERLAY_FADE;
|
|
221
|
+
this.iframe.style.opacity = "1";
|
|
222
|
+
this.overlayRevealTimer = null;
|
|
223
|
+
}, OVERLAY_REVEAL_DELAY_MS);
|
|
212
224
|
}
|
|
213
225
|
post(message) {
|
|
214
226
|
if (this.ready && this.iframe.contentWindow) {
|
|
@@ -282,7 +294,8 @@ var Dashboard = class {
|
|
|
282
294
|
if (this.initialTestMode !== void 0) {
|
|
283
295
|
params.set("test", String(this.initialTestMode));
|
|
284
296
|
}
|
|
285
|
-
const
|
|
297
|
+
const rawPath = !this.initialPath || this.initialPath === "/" ? "/" : this.initialPath;
|
|
298
|
+
const path = stripQueryParams(rawPath);
|
|
286
299
|
return `${this.baseUrl}${path}?${params.toString()}`;
|
|
287
300
|
}
|
|
288
301
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dashboard.ts","../src/singleton.ts"],"sourcesContent":["import type { DashboardTheme, DashboardConfig, DashboardEvents } from \"./types\";\n\nconst EMBED_EVENT_MESSAGE_TYPE = \"yuno-dashboard:embed-event\";\nconst HOST_CAPABILITIES_MESSAGE_TYPE = \"yuno-dashboard:host-capabilities\";\n\ntype EmbedEventHandler = (event: {\n status?: unknown;\n payload?: unknown;\n}) => void | Promise<void>;\n\n// Build the capability map the dashboard reads to decide which actions the\n// host owns: { connections: { created: true }, ... } for every provided handler.\nfunction buildCapabilities(\n events?: DashboardEvents,\n): Record<string, Record<string, boolean>> {\n const capabilities: Record<string, Record<string, boolean>> = {};\n if (!events) return capabilities;\n const groups = events as Record<string, Record<string, unknown> | undefined>;\n for (const domain of Object.keys(groups)) {\n const group = groups[domain];\n if (!group) continue;\n for (const action of Object.keys(group)) {\n if (typeof group[action] === \"function\") {\n capabilities[domain] = capabilities[domain] ?? {};\n capabilities[domain][action] = true;\n }\n }\n }\n return capabilities;\n}\n\nexport class Dashboard {\n private iframe: HTMLIFrameElement;\n private wrapper: HTMLDivElement;\n private overlay: HTMLElement | null = null;\n private baseUrl: string;\n private ready = false;\n private queue: Record<string, unknown>[] = [];\n private messageHandler: (e: MessageEvent) => void;\n private initialTheme?: DashboardTheme;\n private initialLang?: string;\n private initialPath: string;\n private initialTestMode?: boolean;\n private token?: string;\n private onReadyCallback?: () => void;\n private onSessionExpiredCallback?: () => void | Promise<void>;\n private events?: DashboardEvents;\n private autoHeight: boolean;\n // Overlay (modal/drawer) mode: while >0 the iframe is expanded to the full\n // viewport so the dashboard's overlay centers to the host page, not the\n // iframe. Ref-counted to survive stacked overlays.\n private overlayCount = 0;\n private savedIframeCss: string | null = null;\n private overlayRevealTimer: ReturnType<typeof setTimeout> | null = null;\n\n constructor(config: DashboardConfig) {\n this.baseUrl = config.baseUrl;\n this.initialTheme = config.theme;\n this.initialLang = config.lang;\n this.initialPath = config.path ?? \"/\";\n this.initialTestMode = config.testMode;\n this.token = config.token;\n this.onReadyCallback = config.onReady;\n this.onSessionExpiredCallback = config.onSessionExpired;\n this.events = config.events;\n this.autoHeight = config.autoHeight ?? false;\n\n this.wrapper = document.createElement(\"div\");\n this.wrapper.style.position = \"relative\";\n this.wrapper.style.width = \"100%\";\n this.wrapper.style.height = \"100%\";\n\n this.iframe = document.createElement(\"iframe\");\n this.iframe.style.width = \"100%\";\n this.iframe.style.height = \"100%\";\n this.iframe.style.border = \"none\";\n this.iframe.title = \"Yuno Dashboard\";\n this.iframe.src = this.buildSrc();\n\n this.wrapper.appendChild(this.iframe);\n\n this.overlay = config.loading instanceof HTMLElement\n ? config.loading\n : this.createDefaultOverlay();\n this.overlay.style.position = \"absolute\";\n this.overlay.style.inset = \"0\";\n this.overlay.style.zIndex = \"1\";\n this.wrapper.appendChild(this.overlay);\n\n this.messageHandler = (e: MessageEvent) => {\n if (e.origin !== this.baseUrl) return;\n if (\n this.autoHeight &&\n e.data?.action === \"resize\" &&\n typeof e.data?.height === \"number\"\n ) {\n this.iframe.style.height = `${e.data.height}px`;\n this.wrapper.style.height = `${e.data.height}px`;\n return;\n }\n if (e.data?.type === \"yuno-dashboard:session-expired\") {\n this.invokeCallback(\"onSessionExpired\", () =>\n this.onSessionExpiredCallback?.(),\n );\n return;\n }\n if (e.data?.type === EMBED_EVENT_MESSAGE_TYPE) {\n this.dispatchEmbedEvent(e.data);\n return;\n }\n if (e.data?.action === \"ready\") {\n this.onReady();\n }\n if (e.data?.action === \"tokenApplied\") {\n this.onTokenApplied();\n }\n };\n window.addEventListener(\"message\", this.messageHandler);\n\n config.container.appendChild(this.wrapper);\n }\n\n setTheme(theme: DashboardTheme): void {\n if (theme.tokens || theme.typography) {\n const themePayload: Record<string, unknown> = {};\n if (theme.tokens) themePayload.colors = theme.tokens;\n if (theme.typography) themePayload.typography = theme.typography;\n this.post({ action: \"setTheme\", theme: themePayload });\n }\n if (theme.mode) {\n this.post({ action: \"setMode\", mode: theme.mode });\n }\n if (theme.styles !== undefined) {\n this.post({ action: \"setExternalStyles\", css: theme.styles });\n }\n }\n\n setLang(lang: string): void {\n this.post({ action: \"setLang\", lang });\n }\n\n setToken(token: string): void {\n this.token = token;\n this.post({ action: \"setToken\", token });\n }\n\n navigate(path: string): void {\n this.post({ action: \"navigate\", path });\n }\n\n setTestMode(enabled: boolean): void {\n this.post({ action: \"setTestMode\", testMode: enabled });\n }\n\n destroy(): void {\n window.removeEventListener(\"message\", this.messageHandler);\n this.wrapper.remove();\n this.queue = [];\n this.ready = false;\n this.overlayCount = 0;\n this.savedIframeCss = null;\n if (this.overlayRevealTimer) {\n clearTimeout(this.overlayRevealTimer);\n this.overlayRevealTimer = null;\n }\n }\n\n // Runs a host callback, swallowing sync throws and async rejections so a\n // misbehaving host handler can never break the SDK's message loop.\n private invokeCallback(\n name: string,\n run: () => void | Promise<void> | undefined,\n ): void {\n try {\n const result = run();\n if (result && typeof (result as Promise<unknown>).catch === \"function\") {\n (result as Promise<unknown>).catch((err) =>\n // eslint-disable-next-line no-console\n console.warn(`[yuno-dashboard-sdk] ${name} async callback rejected`, err),\n );\n }\n } catch (err) {\n // eslint-disable-next-line no-console\n console.warn(`[yuno-dashboard-sdk] ${name} callback threw`, err);\n }\n }\n\n // Routes an embed-event envelope to the host's events[domain][action] handler.\n private dispatchEmbedEvent(data: Record<string, unknown>): void {\n const domain = data?.domain;\n const action = data?.action;\n if (typeof domain !== \"string\" || typeof action !== \"string\") return;\n\n // UI signals are handled by the SDK itself (iframe sizing), not routed to\n // a host callback.\n if (domain === \"ui\") {\n this.handleOverlaySignal(action);\n return;\n }\n\n const groups = this.events as\n | Record<string, Record<string, EmbedEventHandler | undefined> | undefined>\n | undefined;\n const handler = groups?.[domain]?.[action];\n if (!handler) return;\n\n this.invokeCallback(`events.${domain}.${action}`, () =>\n handler({ status: data?.status, payload: data?.payload }),\n );\n }\n\n // Expands the iframe to the full viewport on the first open and restores it\n // once the last overlay closes (ref-counted for stacked overlays).\n private handleOverlaySignal(action: string): void {\n if (action === \"overlay-open\") {\n if (this.overlayCount === 0) this.expandToViewport();\n this.overlayCount += 1;\n } else if (action === \"overlay-close\") {\n if (this.overlayCount === 0) return;\n this.overlayCount -= 1;\n if (this.overlayCount === 0) this.restoreIframe();\n }\n }\n\n private expandToViewport(): void {\n // Capture where the iframe sits (its panel position) BEFORE expanding —\n // that's the offset of the host's chrome around it. The dashboard uses it\n // to leave those regions transparent so the host chrome shows through.\n const rect = this.iframe.getBoundingClientRect();\n const offset = {\n top: Math.max(0, Math.round(rect.top)),\n left: Math.max(0, Math.round(rect.left)),\n right: Math.max(0, Math.round(window.innerWidth - rect.right)),\n bottom: Math.max(0, Math.round(window.innerHeight - rect.bottom)),\n };\n\n this.savedIframeCss = this.iframe.style.cssText;\n Object.assign(this.iframe.style, {\n position: \"fixed\",\n inset: \"0\",\n width: \"100%\",\n height: \"100%\",\n zIndex: \"2147483647\",\n // Transparent so the host page shows through wherever the dashboard\n // doesn't paint (the offset regions).\n background: \"transparent\",\n // Mask the cross-document reflow: expanding the iframe and the\n // dashboard insetting its content happen a frame apart, which flickers.\n // Hide the iframe INSTANTLY (no transition here — a transition would\n // animate the hide and leave the reflow visible mid-fade) and fade it\n // back in once the inset has settled.\n transition: \"none\",\n opacity: \"0\",\n });\n this.post({ action: \"overlay-mode\", active: true, offset });\n if (this.overlayRevealTimer) clearTimeout(this.overlayRevealTimer);\n this.overlayRevealTimer = setTimeout(() => {\n this.iframe.style.transition = \"opacity 0.15s ease\";\n this.iframe.style.opacity = \"1\";\n this.overlayRevealTimer = null;\n }, 100);\n }\n\n private restoreIframe(): void {\n if (this.overlayRevealTimer) {\n clearTimeout(this.overlayRevealTimer);\n this.overlayRevealTimer = null;\n }\n this.iframe.style.cssText = this.savedIframeCss ?? \"\";\n this.savedIframeCss = null;\n this.post({ action: \"overlay-mode\", active: false });\n }\n\n private post(message: Record<string, unknown>): void {\n if (this.ready && this.iframe.contentWindow) {\n this.iframe.contentWindow.postMessage(message, this.baseUrl);\n } else {\n this.queue.push(message);\n }\n }\n\n private flush(): void {\n const pending = this.queue.splice(0);\n for (const message of pending) {\n if (this.iframe.contentWindow) {\n this.iframe.contentWindow.postMessage(message, this.baseUrl);\n }\n }\n }\n\n private onReady(): void {\n this.ready = true;\n const capabilities = buildCapabilities(this.events);\n if (Object.keys(capabilities).length > 0) {\n this.post({ type: HOST_CAPABILITIES_MESSAGE_TYPE, capabilities });\n }\n if (this.token) {\n this.post({ action: \"setToken\", token: this.token });\n }\n if (this.initialTheme) {\n this.setTheme(this.initialTheme);\n }\n if (this.initialLang) {\n this.setLang(this.initialLang);\n }\n this.flush();\n }\n\n private onTokenApplied(): void {\n setTimeout(() => {\n this.hideOverlay();\n this.onReadyCallback?.();\n }, 1000);\n }\n\n private hideOverlay(): void {\n if (!this.overlay) return;\n this.overlay.style.transition = \"opacity 0.3s\";\n this.overlay.style.opacity = \"0\";\n setTimeout(() => this.overlay?.remove(), 300);\n }\n\n private createDefaultOverlay(): HTMLElement {\n const overlay = document.createElement(\"div\");\n overlay.style.background = \"#ffffff\";\n overlay.style.display = \"flex\";\n overlay.style.alignItems = \"center\";\n overlay.style.justifyContent = \"center\";\n\n const spinner = document.createElement(\"div\");\n spinner.style.width = \"32px\";\n spinner.style.height = \"32px\";\n spinner.style.border = \"3px solid #e0e0e0\";\n spinner.style.borderTopColor = \"#666\";\n spinner.style.borderRadius = \"50%\";\n spinner.style.animation = \"yuno-spin 0.8s linear infinite\";\n\n const style = document.createElement(\"style\");\n style.textContent = \"@keyframes yuno-spin { to { transform: rotate(360deg); } }\";\n\n overlay.appendChild(style);\n overlay.appendChild(spinner);\n return overlay;\n }\n\n private buildSrc(): string {\n const params = new URLSearchParams({\n embed: \"true\",\n theme: this.initialTheme?.mode ?? \"light\",\n lang: this.initialLang ?? \"en\",\n });\n if (this.initialTestMode !== undefined) {\n params.set(\"test\", String(this.initialTestMode));\n }\n const path = !this.initialPath || this.initialPath === \"/\" ? \"/\" : this.initialPath;\n return `${this.baseUrl}${path}?${params.toString()}`;\n }\n}\n","import { Dashboard } from \"./dashboard\";\nimport type { DashboardConfig } from \"./types\";\n\nlet instance: Dashboard | null = null;\n\nexport function initDashboard(config: DashboardConfig): Dashboard {\n if (instance) {\n instance.destroy();\n }\n instance = new Dashboard(config);\n return instance;\n}\n\nexport function getDashboard(): Dashboard | null {\n return instance;\n}\n\nexport function destroyDashboard(): void {\n if (instance) {\n instance.destroy();\n instance = null;\n }\n}\n"],"mappings":";AAEA,IAAM,2BAA2B;AACjC,IAAM,iCAAiC;AASvC,SAAS,kBACP,QACyC;AACzC,QAAM,eAAwD,CAAC;AAC/D,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,SAAS;AACf,aAAW,UAAU,OAAO,KAAK,MAAM,GAAG;AACxC,UAAM,QAAQ,OAAO,MAAM;AAC3B,QAAI,CAAC,MAAO;AACZ,eAAW,UAAU,OAAO,KAAK,KAAK,GAAG;AACvC,UAAI,OAAO,MAAM,MAAM,MAAM,YAAY;AACvC,qBAAa,MAAM,IAAI,aAAa,MAAM,KAAK,CAAC;AAChD,qBAAa,MAAM,EAAE,MAAM,IAAI;AAAA,MACjC;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,IAAM,YAAN,MAAgB;AAAA,EAwBrB,YAAY,QAAyB;AArBrC,SAAQ,UAA8B;AAEtC,SAAQ,QAAQ;AAChB,SAAQ,QAAmC,CAAC;AAc5C;AAAA;AAAA;AAAA,SAAQ,eAAe;AACvB,SAAQ,iBAAgC;AACxC,SAAQ,qBAA2D;AAGjE,SAAK,UAAU,OAAO;AACtB,SAAK,eAAe,OAAO;AAC3B,SAAK,cAAc,OAAO;AAC1B,SAAK,cAAc,OAAO,QAAQ;AAClC,SAAK,kBAAkB,OAAO;AAC9B,SAAK,QAAQ,OAAO;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,iBAAiB;AAC/B,YAAQ,MAAM,eAAe;AAC7B,YAAQ,MAAM,YAAY;AAE1B,UAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,UAAM,cAAc;AAEpB,YAAQ,YAAY,KAAK;AACzB,YAAQ,YAAY,OAAO;AAC3B,WAAO;AAAA,EACT;AAAA,EAEQ,WAAmB;AACzB,UAAM,SAAS,IAAI,gBAAgB;AAAA,MACjC,OAAO;AAAA,MACP,OAAO,KAAK,cAAc,QAAQ;AAAA,MAClC,MAAM,KAAK,eAAe;AAAA,IAC5B,CAAC;AACD,QAAI,KAAK,oBAAoB,QAAW;AACtC,aAAO,IAAI,QAAQ,OAAO,KAAK,eAAe,CAAC;AAAA,IACjD;AACA,UAAM,OAAO,CAAC,KAAK,eAAe,KAAK,gBAAgB,MAAM,MAAM,KAAK;AACxE,WAAO,GAAG,KAAK,OAAO,GAAG,IAAI,IAAI,OAAO,SAAS,CAAC;AAAA,EACpD;AACF;;;AClWA,IAAI,WAA6B;AAE1B,SAAS,cAAc,QAAoC;AAChE,MAAI,UAAU;AACZ,aAAS,QAAQ;AAAA,EACnB;AACA,aAAW,IAAI,UAAU,MAAM;AAC/B,SAAO;AACT;AAEO,SAAS,eAAiC;AAC/C,SAAO;AACT;AAEO,SAAS,mBAAyB;AACvC,MAAI,UAAU;AACZ,aAAS,QAAQ;AACjB,eAAW;AAAA,EACb;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/dashboard.ts","../src/singleton.ts"],"sourcesContent":["import type { DashboardTheme, DashboardConfig, DashboardEvents } from \"./types\";\n\nconst EMBED_EVENT_MESSAGE_TYPE = \"yuno-dashboard:embed-event\";\nconst HOST_CAPABILITIES_MESSAGE_TYPE = \"yuno-dashboard:host-capabilities\";\n\nconst OVERLAY_FADE = \"opacity 0.15s ease\";\nconst OVERLAY_REVEAL_DELAY_MS = 100;\n\n// Strips the query string from a host-provided path so only the SDK controls\n// the iframe URL's query params (embed/theme/lang/test). Any host query params\n// are dropped before processing; the pathname (and a trailing hash, if any) is\n// kept. Returns the path unchanged when it has no query string.\nfunction stripQueryParams(path: string): string {\n const queryIndex = path.indexOf(\"?\");\n if (queryIndex < 0) return path;\n\n const hashIndex = path.indexOf(\"#\", queryIndex);\n const hash = hashIndex >= 0 ? path.slice(hashIndex) : \"\";\n return path.slice(0, queryIndex) + hash;\n}\n\ntype EmbedEventHandler = (event: {\n status?: unknown;\n payload?: unknown;\n}) => void | Promise<void>;\n\n// Build the capability map the dashboard reads to decide which actions the\n// host owns: { connections: { created: true }, ... } for every provided handler.\nfunction buildCapabilities(\n events?: DashboardEvents,\n): Record<string, Record<string, boolean>> {\n const capabilities: Record<string, Record<string, boolean>> = {};\n if (!events) return capabilities;\n const groups = events as Record<string, Record<string, unknown> | undefined>;\n for (const domain of Object.keys(groups)) {\n const group = groups[domain];\n if (!group) continue;\n for (const action of Object.keys(group)) {\n if (typeof group[action] === \"function\") {\n capabilities[domain] = capabilities[domain] ?? {};\n capabilities[domain][action] = true;\n }\n }\n }\n return capabilities;\n}\n\nexport class Dashboard {\n private iframe: HTMLIFrameElement;\n private wrapper: HTMLDivElement;\n private overlay: HTMLElement | null = null;\n private baseUrl: string;\n private ready = false;\n private queue: Record<string, unknown>[] = [];\n private messageHandler: (e: MessageEvent) => void;\n private initialTheme?: DashboardTheme;\n private initialLang?: string;\n private initialPath: string;\n private initialTestMode?: boolean;\n private token?: string;\n private onReadyCallback?: () => void;\n private onSessionExpiredCallback?: () => void | Promise<void>;\n private events?: DashboardEvents;\n private autoHeight: boolean;\n // Overlay (modal/drawer) mode: while >0 the iframe is expanded to the full\n // viewport so the dashboard's overlay centers to the host page, not the\n // iframe. Ref-counted to survive stacked overlays.\n private overlayCount = 0;\n private savedIframeCss: string | null = null;\n private overlayRevealTimer: ReturnType<typeof setTimeout> | null = null;\n\n constructor(config: DashboardConfig) {\n this.baseUrl = config.baseUrl;\n this.initialTheme = config.theme;\n this.initialLang = config.lang;\n this.initialPath = config.path ?? \"/\";\n this.initialTestMode = config.testMode;\n this.token = config.token;\n this.onReadyCallback = config.onReady;\n this.onSessionExpiredCallback = config.onSessionExpired;\n this.events = config.events;\n this.autoHeight = config.autoHeight ?? false;\n\n this.wrapper = document.createElement(\"div\");\n this.wrapper.style.position = \"relative\";\n this.wrapper.style.width = \"100%\";\n this.wrapper.style.height = \"100%\";\n\n this.iframe = document.createElement(\"iframe\");\n this.iframe.style.width = \"100%\";\n this.iframe.style.height = \"100%\";\n this.iframe.style.border = \"none\";\n this.iframe.title = \"Yuno Dashboard\";\n this.iframe.src = this.buildSrc();\n\n this.wrapper.appendChild(this.iframe);\n\n this.overlay = config.loading instanceof HTMLElement\n ? config.loading\n : this.createDefaultOverlay();\n this.overlay.style.position = \"absolute\";\n this.overlay.style.inset = \"0\";\n this.overlay.style.zIndex = \"1\";\n this.wrapper.appendChild(this.overlay);\n\n this.messageHandler = (e: MessageEvent) => {\n if (e.origin !== this.baseUrl) return;\n if (\n this.autoHeight &&\n // Ignore content-height resizes while an overlay is open — the iframe is\n // pinned full-viewport, and applying a height would break the overlay\n // and leave a stale wrapper height after it closes.\n this.overlayCount === 0 &&\n e.data?.action === \"resize\" &&\n typeof e.data?.height === \"number\"\n ) {\n this.iframe.style.height = `${e.data.height}px`;\n this.wrapper.style.height = `${e.data.height}px`;\n return;\n }\n if (e.data?.type === \"yuno-dashboard:session-expired\") {\n this.invokeCallback(\"onSessionExpired\", () =>\n this.onSessionExpiredCallback?.(),\n );\n return;\n }\n if (e.data?.type === EMBED_EVENT_MESSAGE_TYPE) {\n this.dispatchEmbedEvent(e.data);\n return;\n }\n if (e.data?.action === \"ready\") {\n this.onReady();\n }\n if (e.data?.action === \"tokenApplied\") {\n this.onTokenApplied();\n }\n };\n window.addEventListener(\"message\", this.messageHandler);\n\n config.container.appendChild(this.wrapper);\n }\n\n setTheme(theme: DashboardTheme): void {\n if (theme.tokens || theme.typography) {\n const themePayload: Record<string, unknown> = {};\n if (theme.tokens) themePayload.colors = theme.tokens;\n if (theme.typography) themePayload.typography = theme.typography;\n this.post({ action: \"setTheme\", theme: themePayload });\n }\n if (theme.mode) {\n this.post({ action: \"setMode\", mode: theme.mode });\n }\n if (theme.styles !== undefined) {\n this.post({ action: \"setExternalStyles\", css: theme.styles });\n }\n }\n\n setLang(lang: string): void {\n this.post({ action: \"setLang\", lang });\n }\n\n setToken(token: string): void {\n this.token = token;\n this.post({ action: \"setToken\", token });\n }\n\n navigate(path: string): void {\n this.post({ action: \"navigate\", path: stripQueryParams(path) });\n }\n\n setTestMode(enabled: boolean): void {\n this.post({ action: \"setTestMode\", testMode: enabled });\n }\n\n destroy(): void {\n window.removeEventListener(\"message\", this.messageHandler);\n this.wrapper.remove();\n this.queue = [];\n this.ready = false;\n this.overlayCount = 0;\n this.savedIframeCss = null;\n if (this.overlayRevealTimer) {\n clearTimeout(this.overlayRevealTimer);\n this.overlayRevealTimer = null;\n }\n }\n\n // Runs a host callback, swallowing sync throws and async rejections so a\n // misbehaving host handler can never break the SDK's message loop.\n private invokeCallback(\n name: string,\n run: () => void | Promise<void> | undefined,\n ): void {\n try {\n const result = run();\n if (result && typeof (result as Promise<unknown>).catch === \"function\") {\n (result as Promise<unknown>).catch((err) =>\n // eslint-disable-next-line no-console\n console.warn(`[yuno-dashboard-sdk] ${name} async callback rejected`, err),\n );\n }\n } catch (err) {\n // eslint-disable-next-line no-console\n console.warn(`[yuno-dashboard-sdk] ${name} callback threw`, err);\n }\n }\n\n // Routes an embed-event envelope to the host's events[domain][action] handler.\n private dispatchEmbedEvent(data: Record<string, unknown>): void {\n const domain = data?.domain;\n const action = data?.action;\n if (typeof domain !== \"string\" || typeof action !== \"string\") return;\n\n // UI signals are handled by the SDK itself (iframe sizing), not routed to\n // a host callback.\n if (domain === \"ui\") {\n this.handleOverlaySignal(action);\n return;\n }\n\n const groups = this.events as\n | Record<string, Record<string, EmbedEventHandler | undefined> | undefined>\n | undefined;\n const handler = groups?.[domain]?.[action];\n if (!handler) return;\n\n this.invokeCallback(`events.${domain}.${action}`, () =>\n handler({ status: data?.status, payload: data?.payload }),\n );\n }\n\n // Expands the iframe to the full viewport on the first open and restores it\n // once the last overlay closes (ref-counted for stacked overlays).\n private handleOverlaySignal(action: string): void {\n if (action === \"overlay-open\") {\n if (this.overlayCount === 0) this.expandToViewport();\n this.overlayCount += 1;\n } else if (action === \"overlay-close\") {\n if (this.overlayCount === 0) return;\n this.overlayCount -= 1;\n if (this.overlayCount === 0) this.restoreIframe();\n }\n }\n\n private expandToViewport(): void {\n // Capture where the iframe sits (its panel position) BEFORE expanding —\n // that's the offset of the host's chrome around it. The dashboard uses it\n // to leave those regions transparent so the host chrome shows through.\n const rect = this.iframe.getBoundingClientRect();\n const offset = {\n top: Math.max(0, Math.round(rect.top)),\n left: Math.max(0, Math.round(rect.left)),\n right: Math.max(0, Math.round(window.innerWidth - rect.right)),\n bottom: Math.max(0, Math.round(window.innerHeight - rect.bottom)),\n };\n\n this.savedIframeCss = this.iframe.style.cssText;\n Object.assign(this.iframe.style, {\n position: \"fixed\",\n inset: \"0\",\n width: \"100%\",\n height: \"100%\",\n zIndex: \"2147483647\",\n // Transparent so the host page shows through wherever the dashboard\n // doesn't paint (the offset regions).\n background: \"transparent\",\n // Hide instantly (no transition — a transition would animate the hide and\n // leave the reflow visible mid-fade), then fade back in once the inset has\n // settled, masking the cross-document expand→inset reflow.\n transition: \"none\",\n opacity: \"0\",\n });\n this.post({ action: \"overlay-mode\", active: true, offset });\n this.scheduleReveal();\n }\n\n private restoreIframe(): void {\n // Restore the geometry while hidden, let the dashboard remove its inset,\n // then fade back in — same masking as the open, so nothing shifts.\n this.iframe.style.cssText = this.savedIframeCss ?? \"\";\n this.savedIframeCss = null;\n this.iframe.style.transition = \"none\";\n this.iframe.style.opacity = \"0\";\n this.post({ action: \"overlay-mode\", active: false });\n this.scheduleReveal();\n }\n\n private scheduleReveal(): void {\n if (this.overlayRevealTimer) clearTimeout(this.overlayRevealTimer);\n this.overlayRevealTimer = setTimeout(() => {\n this.iframe.style.transition = OVERLAY_FADE;\n this.iframe.style.opacity = \"1\";\n this.overlayRevealTimer = null;\n }, OVERLAY_REVEAL_DELAY_MS);\n }\n\n private post(message: Record<string, unknown>): void {\n if (this.ready && this.iframe.contentWindow) {\n this.iframe.contentWindow.postMessage(message, this.baseUrl);\n } else {\n this.queue.push(message);\n }\n }\n\n private flush(): void {\n const pending = this.queue.splice(0);\n for (const message of pending) {\n if (this.iframe.contentWindow) {\n this.iframe.contentWindow.postMessage(message, this.baseUrl);\n }\n }\n }\n\n private onReady(): void {\n this.ready = true;\n const capabilities = buildCapabilities(this.events);\n if (Object.keys(capabilities).length > 0) {\n this.post({ type: HOST_CAPABILITIES_MESSAGE_TYPE, capabilities });\n }\n if (this.token) {\n this.post({ action: \"setToken\", token: this.token });\n }\n if (this.initialTheme) {\n this.setTheme(this.initialTheme);\n }\n if (this.initialLang) {\n this.setLang(this.initialLang);\n }\n this.flush();\n }\n\n private onTokenApplied(): void {\n setTimeout(() => {\n this.hideOverlay();\n this.onReadyCallback?.();\n }, 1000);\n }\n\n private hideOverlay(): void {\n if (!this.overlay) return;\n this.overlay.style.transition = \"opacity 0.3s\";\n this.overlay.style.opacity = \"0\";\n setTimeout(() => this.overlay?.remove(), 300);\n }\n\n private createDefaultOverlay(): HTMLElement {\n const overlay = document.createElement(\"div\");\n overlay.style.background = \"#ffffff\";\n overlay.style.display = \"flex\";\n overlay.style.alignItems = \"center\";\n overlay.style.justifyContent = \"center\";\n\n const spinner = document.createElement(\"div\");\n spinner.style.width = \"32px\";\n spinner.style.height = \"32px\";\n spinner.style.border = \"3px solid #e0e0e0\";\n spinner.style.borderTopColor = \"#666\";\n spinner.style.borderRadius = \"50%\";\n spinner.style.animation = \"yuno-spin 0.8s linear infinite\";\n\n const style = document.createElement(\"style\");\n style.textContent = \"@keyframes yuno-spin { to { transform: rotate(360deg); } }\";\n\n overlay.appendChild(style);\n overlay.appendChild(spinner);\n return overlay;\n }\n\n private buildSrc(): string {\n const params = new URLSearchParams({\n embed: \"true\",\n theme: this.initialTheme?.mode ?? \"light\",\n lang: this.initialLang ?? \"en\",\n });\n if (this.initialTestMode !== undefined) {\n params.set(\"test\", String(this.initialTestMode));\n }\n // Drop any host-provided query params so only the SDK controls the query\n // string (avoids conflicts and a double \"?\").\n const rawPath =\n !this.initialPath || this.initialPath === \"/\" ? \"/\" : this.initialPath;\n const path = stripQueryParams(rawPath);\n return `${this.baseUrl}${path}?${params.toString()}`;\n }\n}\n","import { Dashboard } from \"./dashboard\";\nimport type { DashboardConfig } from \"./types\";\n\nlet instance: Dashboard | null = null;\n\nexport function initDashboard(config: DashboardConfig): Dashboard {\n if (instance) {\n instance.destroy();\n }\n instance = new Dashboard(config);\n return instance;\n}\n\nexport function getDashboard(): Dashboard | null {\n return instance;\n}\n\nexport function destroyDashboard(): void {\n if (instance) {\n instance.destroy();\n instance = null;\n }\n}\n"],"mappings":";AAEA,IAAM,2BAA2B;AACjC,IAAM,iCAAiC;AAEvC,IAAM,eAAe;AACrB,IAAM,0BAA0B;AAMhC,SAAS,iBAAiB,MAAsB;AAC9C,QAAM,aAAa,KAAK,QAAQ,GAAG;AACnC,MAAI,aAAa,EAAG,QAAO;AAE3B,QAAM,YAAY,KAAK,QAAQ,KAAK,UAAU;AAC9C,QAAM,OAAO,aAAa,IAAI,KAAK,MAAM,SAAS,IAAI;AACtD,SAAO,KAAK,MAAM,GAAG,UAAU,IAAI;AACrC;AASA,SAAS,kBACP,QACyC;AACzC,QAAM,eAAwD,CAAC;AAC/D,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,SAAS;AACf,aAAW,UAAU,OAAO,KAAK,MAAM,GAAG;AACxC,UAAM,QAAQ,OAAO,MAAM;AAC3B,QAAI,CAAC,MAAO;AACZ,eAAW,UAAU,OAAO,KAAK,KAAK,GAAG;AACvC,UAAI,OAAO,MAAM,MAAM,MAAM,YAAY;AACvC,qBAAa,MAAM,IAAI,aAAa,MAAM,KAAK,CAAC;AAChD,qBA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