@yuno-payments/dashboard-embed-sdk 1.0.0 → 1.1.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/README.md CHANGED
@@ -73,7 +73,9 @@ destroyDashboard();
73
73
  | `path` | `string` | No | Initial navigation path (default: `"/"`) |
74
74
  | `onReady` | `() => void` | No | Callback invoked when the dashboard is fully loaded and authenticated |
75
75
  | `onSessionExpired` | `() => void` | No | Callback invoked when the embedded session has expired. The host should re-authenticate and call `setToken(newToken)` to resume. |
76
+ | `onCheckoutPublished` | `(event: CheckoutPublishedEvent) => void \| Promise<void>` | No | Callback invoked when the user publishes the checkout configuration or styling. `event.source` is `"checkout"` or `"styling"`, `event.status` reports the publish call state (`"loading"` → `"success"` or `"error"`), and `event.payload` contains the configuration object that was published. |
76
77
  | `loading` | `HTMLElement` | No | Custom loading overlay element. If omitted, a default spinner is shown |
78
+ | `autoHeight` | `boolean` | No | When `true`, the iframe is resized to match the dashboard content height (no inner scroll). Default `false` (iframe fills its container at `100%`). See [Auto height](#auto-height) |
77
79
 
78
80
  ### Methods
79
81
 
@@ -128,6 +130,16 @@ interface DashboardTheme {
128
130
  mode?: "light" | "dark";
129
131
  styles?: string; // Custom CSS injected into the dashboard
130
132
  }
133
+
134
+ type CheckoutPublishedSource = "checkout" | "styling";
135
+
136
+ type CheckoutPublishedStatus = "loading" | "success" | "error";
137
+
138
+ interface CheckoutPublishedEvent {
139
+ source: CheckoutPublishedSource;
140
+ status: CheckoutPublishedStatus;
141
+ payload?: unknown; // The configuration object that was published
142
+ }
131
143
  ```
132
144
 
133
145
  ## Session timeouts
@@ -157,10 +169,66 @@ const sdk = initDashboard({
157
169
  })
158
170
  ```
159
171
 
172
+ ## Checkout published events
173
+
174
+ Whenever the user publishes from the embedded Checkout Builder (payment method
175
+ configuration) or the Styling editor, the iframe emits a message to the host.
176
+ Subscribe via `onCheckoutPublished`:
177
+
178
+ ```ts
179
+ const sdk = initDashboard({
180
+ baseUrl: "https://dashboard.y.uno",
181
+ container: document.getElementById("dashboard")!,
182
+ token: initialToken,
183
+ onCheckoutPublished: (event) => {
184
+ // event.source is "checkout" | "styling"
185
+ // event.status is "loading" | "success" | "error"
186
+ // event.payload is the configuration object that was published
187
+ switch (event.status) {
188
+ case "loading":
189
+ console.log(`Publish loading from ${event.source}`)
190
+ break
191
+ case "success":
192
+ console.log(`Checkout published from ${event.source}`, event.payload)
193
+ break
194
+ case "error":
195
+ console.log("Publish failed — please try again")
196
+ break
197
+ }
198
+ },
199
+ })
200
+ ```
201
+
202
+ The callback fires once per state transition of the publish call: first with
203
+ `status: "loading"` when the user triggers the publish, then a second time with
204
+ either `"success"` or `"error"` once the dashboard's publish endpoint responds.
205
+ `event.payload` is only meaningful on the `"success"` event.
206
+
160
207
  ## Loading overlay
161
208
 
162
209
  A loading overlay covers the iframe while initialization completes. You can provide a custom element via the `loading` config option, or the SDK renders a default spinner. The overlay fades out automatically (300ms transition) once the dashboard is authenticated and ready.
163
210
 
211
+ ## Auto height
212
+
213
+ By default the iframe fills its container (`height: 100%`) and the dashboard content
214
+ scrolls inside it. Pass `autoHeight: true` to size the iframe to the dashboard's content
215
+ height instead, so the whole host page scrolls naturally with no inner scrollbar:
216
+
217
+ ```ts
218
+ initDashboard({
219
+ baseUrl: "https://dashboard.y.uno",
220
+ container: document.getElementById("dashboard")!,
221
+ token,
222
+ autoHeight: true,
223
+ });
224
+ ```
225
+
226
+ **Host/iframe contract:** when `autoHeight` is enabled, the embedded dashboard reports its
227
+ content height to the host via `postMessage({ action: "resize", height })` whenever the
228
+ content resizes; the SDK applies that height to the iframe and its wrapper. Messages are
229
+ accepted only from the configured `baseUrl` origin. Your container must allow vertical growth
230
+ (avoid a fixed `height` / `overflow: hidden`) for the effect to be visible.
231
+
164
232
  ## Migrating from 0.x to 1.0
165
233
 
166
234
  `1.0.0` drops the `Yuno` brand prefix from the public API so the SDK reads cleanly
package/dist/index.d.ts CHANGED
@@ -37,6 +37,13 @@ interface DashboardTheme {
37
37
  mode?: "light" | "dark";
38
38
  styles?: string;
39
39
  }
40
+ type CheckoutPublishedSource = "checkout" | "styling";
41
+ type CheckoutPublishedStatus = "loading" | "success" | "error";
42
+ interface CheckoutPublishedEvent {
43
+ source: CheckoutPublishedSource;
44
+ status: CheckoutPublishedStatus;
45
+ payload?: unknown;
46
+ }
40
47
  interface DashboardConfig {
41
48
  baseUrl: string;
42
49
  container: HTMLElement;
@@ -46,7 +53,9 @@ interface DashboardConfig {
46
53
  path?: string;
47
54
  onReady?: () => void;
48
55
  onSessionExpired?: () => void | Promise<void>;
56
+ onCheckoutPublished?: (event: CheckoutPublishedEvent) => void | Promise<void>;
49
57
  loading?: HTMLElement;
58
+ autoHeight?: boolean;
50
59
  }
51
60
 
52
61
  declare class Dashboard {
@@ -63,6 +72,8 @@ declare class Dashboard {
63
72
  private token?;
64
73
  private onReadyCallback?;
65
74
  private onSessionExpiredCallback?;
75
+ private onCheckoutPublishedCallback?;
76
+ private autoHeight;
66
77
  constructor(config: DashboardConfig);
67
78
  setTheme(theme: DashboardTheme): void;
68
79
  setLang(lang: string): void;
@@ -82,4 +93,4 @@ declare function initDashboard(config: DashboardConfig): Dashboard;
82
93
  declare function getDashboard(): Dashboard | null;
83
94
  declare function destroyDashboard(): void;
84
95
 
85
- export { Dashboard, type DashboardConfig, type DashboardTheme, type ModeTokens, type ThemeColors, type ThemeTypography, destroyDashboard, getDashboard, initDashboard };
96
+ export { type CheckoutPublishedEvent, type CheckoutPublishedSource, type CheckoutPublishedStatus, Dashboard, type DashboardConfig, type DashboardTheme, type ModeTokens, type ThemeColors, type ThemeTypography, destroyDashboard, getDashboard, initDashboard };
package/dist/index.js CHANGED
@@ -11,6 +11,8 @@ var Dashboard = class {
11
11
  this.token = config.token;
12
12
  this.onReadyCallback = config.onReady;
13
13
  this.onSessionExpiredCallback = config.onSessionExpired;
14
+ this.onCheckoutPublishedCallback = config.onCheckoutPublished;
15
+ this.autoHeight = config.autoHeight ?? false;
14
16
  this.wrapper = document.createElement("div");
15
17
  this.wrapper.style.position = "relative";
16
18
  this.wrapper.style.width = "100%";
@@ -29,6 +31,11 @@ var Dashboard = class {
29
31
  this.wrapper.appendChild(this.overlay);
30
32
  this.messageHandler = (e) => {
31
33
  if (e.origin !== this.baseUrl) return;
34
+ if (this.autoHeight && e.data?.action === "resize" && typeof e.data?.height === "number") {
35
+ this.iframe.style.height = `${e.data.height}px`;
36
+ this.wrapper.style.height = `${e.data.height}px`;
37
+ return;
38
+ }
32
39
  if (e.data?.type === "yuno-dashboard:session-expired") {
33
40
  try {
34
41
  const result = this.onSessionExpiredCallback?.();
@@ -45,6 +52,26 @@ var Dashboard = class {
45
52
  }
46
53
  return;
47
54
  }
55
+ if (e.data?.type === "yuno-dashboard:checkout-published") {
56
+ try {
57
+ const result = this.onCheckoutPublishedCallback?.({
58
+ source: e.data?.source,
59
+ status: e.data?.status,
60
+ payload: e.data?.payload
61
+ });
62
+ if (result && typeof result.catch === "function") {
63
+ result.catch(
64
+ (err) => (
65
+ // eslint-disable-next-line no-console
66
+ console.warn("[yuno-dashboard-sdk] onCheckoutPublished async callback rejected", err)
67
+ )
68
+ );
69
+ }
70
+ } catch (err) {
71
+ console.warn("[yuno-dashboard-sdk] onCheckoutPublished callback threw", err);
72
+ }
73
+ return;
74
+ }
48
75
  if (e.data?.action === "ready") {
49
76
  this.onReady();
50
77
  }
@@ -115,9 +142,6 @@ var Dashboard = class {
115
142
  }
116
143
  onTokenApplied() {
117
144
  setTimeout(() => {
118
- if (this.initialPath !== "/") {
119
- this.post({ action: "navigate", path: this.initialPath });
120
- }
121
145
  this.hideOverlay();
122
146
  this.onReadyCallback?.();
123
147
  }, 1e3);
@@ -153,7 +177,8 @@ var Dashboard = class {
153
177
  theme: this.initialTheme?.mode ?? "light",
154
178
  lang: this.initialLang ?? "en"
155
179
  });
156
- return `${this.baseUrl}/?${params.toString()}`;
180
+ const path = !this.initialPath || this.initialPath === "/" ? "/" : this.initialPath;
181
+ return `${this.baseUrl}${path}?${params.toString()}`;
157
182
  }
158
183
  };
159
184
 
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dashboard.ts","../src/singleton.ts"],"sourcesContent":["import type { DashboardTheme, DashboardConfig } from \"./types\";\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 token?: string;\n private onReadyCallback?: () => void;\n private onSessionExpiredCallback?: () => void | Promise<void>;\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.token = config.token;\n this.onReadyCallback = config.onReady;\n this.onSessionExpiredCallback = config.onSessionExpired;\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 (e.data?.type === \"yuno-dashboard:session-expired\") {\n try {\n const result = this.onSessionExpiredCallback?.();\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] onSessionExpired async callback rejected\", err),\n );\n }\n } catch (err) {\n // eslint-disable-next-line no-console\n console.warn(\"[yuno-dashboard-sdk] onSessionExpired callback threw\", err);\n }\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 destroy(): void {\n window.removeEventListener(\"message\", this.messageHandler);\n this.wrapper.remove();\n this.queue = [];\n this.ready = 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 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 if (this.initialPath !== \"/\") {\n this.post({ action: \"navigate\", path: this.initialPath });\n }\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 return `${this.baseUrl}/?${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":";AAEO,IAAM,YAAN,MAAgB;AAAA,EAerB,YAAY,QAAyB;AAZrC,SAAQ,UAA8B;AAEtC,SAAQ,QAAQ;AAChB,SAAQ,QAAmC,CAAC;AAU1C,SAAK,UAAU,OAAO;AACtB,SAAK,eAAe,OAAO;AAC3B,SAAK,cAAc,OAAO;AAC1B,SAAK,cAAc,OAAO,QAAQ;AAClC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AAY,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,WAAO,GAAG,KAAK,OAAO,KAAK,OAAO,SAAS,CAAC;AAAA,EAC9C;AACF;;;AC5LA,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, CheckoutPublishedEvent } from \"./types\";\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 token?: string;\n private onReadyCallback?: () => void;\n private onSessionExpiredCallback?: () => void | Promise<void>;\n private onCheckoutPublishedCallback?: (event: CheckoutPublishedEvent) => void | Promise<void>;\n private autoHeight: boolean;\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.token = config.token;\n this.onReadyCallback = config.onReady;\n this.onSessionExpiredCallback = config.onSessionExpired;\n this.onCheckoutPublishedCallback = config.onCheckoutPublished;\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 try {\n const result = this.onSessionExpiredCallback?.();\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] onSessionExpired async callback rejected\", err),\n );\n }\n } catch (err) {\n // eslint-disable-next-line no-console\n console.warn(\"[yuno-dashboard-sdk] onSessionExpired callback threw\", err);\n }\n return;\n }\n if (e.data?.type === \"yuno-dashboard:checkout-published\") {\n try {\n const result = this.onCheckoutPublishedCallback?.({\n source: e.data?.source,\n status: e.data?.status,\n payload: e.data?.payload,\n });\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] onCheckoutPublished async callback rejected\", err),\n );\n }\n } catch (err) {\n // eslint-disable-next-line no-console\n console.warn(\"[yuno-dashboard-sdk] onCheckoutPublished callback threw\", err);\n }\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 destroy(): void {\n window.removeEventListener(\"message\", this.messageHandler);\n this.wrapper.remove();\n this.queue = [];\n this.ready = 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 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 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":";AAEO,IAAM,YAAN,MAAgB;AAAA,EAiBrB,YAAY,QAAyB;AAdrC,SAAQ,UAA8B;AAEtC,SAAQ,QAAQ;AAChB,SAAQ,QAAmC,CAAC;AAY1C,SAAK,UAAU,OAAO;AACtB,SAAK,eAAe,OAAO;AAC3B,SAAK,cAAc,OAAO;AAC1B,SAAK,cAAc,OAAO,QAAQ;AAClC,SAAK,QAAQ,OAAO;AACpB,SAAK,kBAAkB,OAAO;AAC9B,SAAK,2BAA2B,OAAO;AACvC,SAAK,8BAA8B,OAAO;AAC1C,SAAK,aAAa,OAAO,cAAc;AAEvC,SAAK,UAAU,SAAS,cAAc,KAAK;AAC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AS,cAAc,KAAK;AAC5C,YAAQ,MAAM,aAAa;AAC3B,YAAQ,MAAM,UAAU;AACxB,YAAQ,MAAM,aAAa;AAC3B,YAAQ,MAAM,iBAAiB;AAE/B,UAAM,UAAU,SAAS,cAAc,KAAK;AAC5C,YAAQ,MAAM,QAAQ;AACtB,YAAQ,MAAM,SAAS;AACvB,YAAQ,MAAM,SAAS;AACvB,YAAQ,MAAM,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,UAAM,OAAO,CAAC,KAAK,eAAe,KAAK,gBAAgB,MAAM,MAAM,KAAK;AACxE,WAAO,GAAG,KAAK,OAAO,GAAG,IAAI,IAAI,OAAO,SAAS,CAAC;AAAA,EACpD;AACF;;;AC1NA,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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuno-payments/dashboard-embed-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Lightweight SDK for embedding the Yuno Dashboard via iframe",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",