@yuno-payments/dashboard-embed-sdk 0.3.0 → 1.0.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 CHANGED
@@ -11,19 +11,19 @@ npm install @yuno-payments/dashboard-embed-sdk
11
11
  ## Quick Start
12
12
 
13
13
  ```ts
14
- import { initYunoDashboard } from "@yuno-payments/dashboard-embed-sdk";
14
+ import { initDashboard } from "@yuno-payments/dashboard-embed-sdk";
15
15
 
16
- const sdk = initYunoDashboard({
16
+ const sdk = initDashboard({
17
17
  baseUrl: "https://dashboard.y.uno",
18
18
  container: document.getElementById("dashboard")!,
19
19
  token: "your-jwt-token",
20
20
  theme: {
21
21
  // Simple: flat tokens apply to both light mode and dark mode;
22
- tokens: { primary: "#134AC3" },
22
+ tokens: { primary: "#134AC3", surface: "#FFFFFF" },
23
23
  // Per-mode: full control over both light and dark colors
24
24
  // tokens: {
25
- // light: { primary: "#134AC3", background: "#FFFFFF" },
26
- // dark: { primary: "#5B7BFF", background: "#0A0A0A" },
25
+ // light: { primary: "#134AC3", surface: "#FFFFFF" },
26
+ // dark: { primary: "#5B7BFF", surface: "#0A0A0A" },
27
27
  // },
28
28
  typography: {
29
29
  fontFamily: "'Inter', sans-serif",
@@ -46,22 +46,22 @@ The recommended way to manage the SDK instance:
46
46
 
47
47
  ```ts
48
48
  import {
49
- initYunoDashboard,
50
- getYunoDashboard,
51
- destroyYunoDashboard,
49
+ initDashboard,
50
+ getDashboard,
51
+ destroyDashboard,
52
52
  } from "@yuno-payments/dashboard-embed-sdk";
53
53
 
54
54
  // Create (destroys any previous instance automatically)
55
- const sdk = initYunoDashboard(config);
55
+ const sdk = initDashboard(config);
56
56
 
57
57
  // Retrieve the current instance from anywhere
58
- const sdk = getYunoDashboard();
58
+ const sdk = getDashboard();
59
59
 
60
60
  // Destroy the instance and clean up
61
- destroyYunoDashboard();
61
+ destroyDashboard();
62
62
  ```
63
63
 
64
- ### `new YunoDashboard(config)` / `initYunoDashboard(config)`
64
+ ### `initDashboard(config)`
65
65
 
66
66
  | Option | Type | Required | Description |
67
67
  |---|---|---|---|
@@ -72,6 +72,7 @@ destroyYunoDashboard();
72
72
  | `lang` | `string` | No | Language code (default: `"en"`) |
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
+ | `onSessionExpired` | `() => void` | No | Callback invoked when the embedded session has expired. The host should re-authenticate and call `setToken(newToken)` to resume. |
75
76
  | `loading` | `HTMLElement` | No | Custom loading overlay element. If omitted, a default spinner is shown |
76
77
 
77
78
  ### Methods
@@ -129,10 +130,64 @@ interface DashboardTheme {
129
130
  }
130
131
  ```
131
132
 
133
+ ## Session timeouts
134
+
135
+ By default, sessions issued by `POST /v1/external/authenticate` are valid for 24 hours.
136
+ You can issue a shorter session by passing `timeout_seconds` (between 60 and 86400):
137
+
138
+ ```bash
139
+ curl -X POST https://api.y.uno/v1/external/authenticate \
140
+ -H "x-organization-code: <your-org-uuid>" \
141
+ -H "Content-Type: application/json" \
142
+ -d '{"user_id":"<user-uuid>", "timeout_seconds": 1800}'
143
+ ```
144
+
145
+ When the embedded session expires, the iframe paints a "Session expired" overlay
146
+ and emits a message to the host. Subscribe via `onSessionExpired`:
147
+
148
+ ```ts
149
+ const sdk = initDashboard({
150
+ baseUrl: "https://dashboard.y.uno",
151
+ container: document.getElementById("dashboard")!,
152
+ token: initialToken,
153
+ onSessionExpired: async () => {
154
+ const newToken = await myBackend.requestEmbedToken({ timeout_seconds: 1800 })
155
+ sdk.setToken(newToken)
156
+ },
157
+ })
158
+ ```
159
+
132
160
  ## Loading overlay
133
161
 
134
162
  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.
135
163
 
164
+ ## Migrating from 0.x to 1.0
165
+
166
+ `1.0.0` drops the `Yuno` brand prefix from the public API so the SDK reads cleanly
167
+ in white-labelled integrations. The old names were **removed** — there is no
168
+ compatibility shim, so update every import and call site:
169
+
170
+ | 0.x (removed) | 1.0 (new) |
171
+ |---|---|
172
+ | `initYunoDashboard(config)` | `initDashboard(config)` |
173
+ | `getYunoDashboard()` | `getDashboard()` |
174
+ | `destroyYunoDashboard()` | `destroyDashboard()` |
175
+ | `YunoDashboard` (class) | `Dashboard` |
176
+ | `YunoDashboardConfig` (type) | `DashboardConfig` |
177
+
178
+ ```diff
179
+ - import { initYunoDashboard, getYunoDashboard, destroyYunoDashboard } from "@yuno-payments/dashboard-embed-sdk";
180
+ - import type { YunoDashboardConfig } from "@yuno-payments/dashboard-embed-sdk";
181
+ + import { initDashboard, getDashboard, destroyDashboard } from "@yuno-payments/dashboard-embed-sdk";
182
+ + import type { DashboardConfig } from "@yuno-payments/dashboard-embed-sdk";
183
+
184
+ - const sdk = initYunoDashboard(config);
185
+ + const sdk = initDashboard(config);
186
+ ```
187
+
188
+ Behavior, config options, methods, callbacks, and the PostMessage host/iframe
189
+ contract are unchanged — this release renames the API surface only.
190
+
136
191
  ## Development
137
192
 
138
193
  ```bash
package/dist/index.d.ts CHANGED
@@ -37,7 +37,7 @@ interface DashboardTheme {
37
37
  mode?: "light" | "dark";
38
38
  styles?: string;
39
39
  }
40
- interface YunoDashboardConfig {
40
+ interface DashboardConfig {
41
41
  baseUrl: string;
42
42
  container: HTMLElement;
43
43
  token?: string;
@@ -45,10 +45,11 @@ interface YunoDashboardConfig {
45
45
  lang?: string;
46
46
  path?: string;
47
47
  onReady?: () => void;
48
+ onSessionExpired?: () => void | Promise<void>;
48
49
  loading?: HTMLElement;
49
50
  }
50
51
 
51
- declare class YunoDashboard {
52
+ declare class Dashboard {
52
53
  private iframe;
53
54
  private wrapper;
54
55
  private overlay;
@@ -61,7 +62,8 @@ declare class YunoDashboard {
61
62
  private initialPath;
62
63
  private token?;
63
64
  private onReadyCallback?;
64
- constructor(config: YunoDashboardConfig);
65
+ private onSessionExpiredCallback?;
66
+ constructor(config: DashboardConfig);
65
67
  setTheme(theme: DashboardTheme): void;
66
68
  setLang(lang: string): void;
67
69
  setToken(token: string): void;
@@ -76,8 +78,8 @@ declare class YunoDashboard {
76
78
  private buildSrc;
77
79
  }
78
80
 
79
- declare function initYunoDashboard(config: YunoDashboardConfig): YunoDashboard;
80
- declare function getYunoDashboard(): YunoDashboard | null;
81
- declare function destroyYunoDashboard(): void;
81
+ declare function initDashboard(config: DashboardConfig): Dashboard;
82
+ declare function getDashboard(): Dashboard | null;
83
+ declare function destroyDashboard(): void;
82
84
 
83
- export { type DashboardTheme, type ModeTokens, type ThemeColors, type ThemeTypography, YunoDashboard, type YunoDashboardConfig, destroyYunoDashboard, getYunoDashboard, initYunoDashboard };
85
+ export { Dashboard, type DashboardConfig, type DashboardTheme, type ModeTokens, type ThemeColors, type ThemeTypography, destroyDashboard, getDashboard, initDashboard };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- // src/yuno-dashboard.ts
2
- var YunoDashboard = class {
1
+ // src/dashboard.ts
2
+ var Dashboard = class {
3
3
  constructor(config) {
4
4
  this.overlay = null;
5
5
  this.ready = false;
@@ -10,6 +10,7 @@ var YunoDashboard = class {
10
10
  this.initialPath = config.path ?? "/";
11
11
  this.token = config.token;
12
12
  this.onReadyCallback = config.onReady;
13
+ this.onSessionExpiredCallback = config.onSessionExpired;
13
14
  this.wrapper = document.createElement("div");
14
15
  this.wrapper.style.position = "relative";
15
16
  this.wrapper.style.width = "100%";
@@ -28,6 +29,22 @@ var YunoDashboard = class {
28
29
  this.wrapper.appendChild(this.overlay);
29
30
  this.messageHandler = (e) => {
30
31
  if (e.origin !== this.baseUrl) return;
32
+ if (e.data?.type === "yuno-dashboard:session-expired") {
33
+ try {
34
+ const result = this.onSessionExpiredCallback?.();
35
+ if (result && typeof result.catch === "function") {
36
+ result.catch(
37
+ (err) => (
38
+ // eslint-disable-next-line no-console
39
+ console.warn("[yuno-dashboard-sdk] onSessionExpired async callback rejected", err)
40
+ )
41
+ );
42
+ }
43
+ } catch (err) {
44
+ console.warn("[yuno-dashboard-sdk] onSessionExpired callback threw", err);
45
+ }
46
+ return;
47
+ }
31
48
  if (e.data?.action === "ready") {
32
49
  this.onReady();
33
50
  }
@@ -142,26 +159,26 @@ var YunoDashboard = class {
142
159
 
143
160
  // src/singleton.ts
144
161
  var instance = null;
145
- function initYunoDashboard(config) {
162
+ function initDashboard(config) {
146
163
  if (instance) {
147
164
  instance.destroy();
148
165
  }
149
- instance = new YunoDashboard(config);
166
+ instance = new Dashboard(config);
150
167
  return instance;
151
168
  }
152
- function getYunoDashboard() {
169
+ function getDashboard() {
153
170
  return instance;
154
171
  }
155
- function destroyYunoDashboard() {
172
+ function destroyDashboard() {
156
173
  if (instance) {
157
174
  instance.destroy();
158
175
  instance = null;
159
176
  }
160
177
  }
161
178
  export {
162
- YunoDashboard,
163
- destroyYunoDashboard,
164
- getYunoDashboard,
165
- initYunoDashboard
179
+ Dashboard,
180
+ destroyDashboard,
181
+ getDashboard,
182
+ initDashboard
166
183
  };
167
184
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/yuno-dashboard.ts","../src/singleton.ts"],"sourcesContent":["import type { DashboardTheme, YunoDashboardConfig } from \"./types\";\n\nexport class YunoDashboard {\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\n constructor(config: YunoDashboardConfig) {\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\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?.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 { YunoDashboard } from \"./yuno-dashboard\";\nimport type { YunoDashboardConfig } from \"./types\";\n\nlet instance: YunoDashboard | null = null;\n\nexport function initYunoDashboard(config: YunoDashboardConfig): YunoDashboard {\n if (instance) {\n instance.destroy();\n }\n instance = new YunoDashboard(config);\n return instance;\n}\n\nexport function getYunoDashboard(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AAA,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;;;AC3KA,IAAI,WAAiC;AAE9B,SAAS,kBAAkB,QAA4C;AAC5E,MAAI,UAAU;AACZ,aAAS,QAAQ;AAAA,EACnB;AACA,aAAW,IAAI,cAAc,MAAM;AACnC,SAAO;AACT;AAEO,SAAS,mBAAyC;AACvD,SAAO;AACT;AAEO,SAAS,uBAA6B;AAC3C,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 } 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,SAAK,QAAQ,OAAO;AACpB,SAAK,kBAAkB,OAAO;AAC9B,SAAK,2BAA2B,OAAO;AAEvC,SAAK,UAAU,SAAS,cAAc,KAAK;AAC3C,SAAK,QAAQ,MAAM,WAAW;AAC9B,SAAK,QAAQ,MAAM,QAAQ;AAC3B,SAAK,QAAQ,MAAM,SAAS;AAE5B,SAAK,SAAS,SAAS,cAAc,QAAQ;AAC7C,SAAK,OAAO,MAAM,QAAQ;AAC1B,SAAK,OAAO,MAAM,SAAS;AAC3B,SAAK,OAAO,MAAM,SAAS;AAC3B,SAAK,OAAO,QAAQ;AACpB,SAAK,OAAO,MAAM,KAAK,SAAS;AAEhC,SAAK,QAAQ,YAAY,KAAK,MAAM;AAEpC,SAAK,UAAU,OAAO,mBAAmB,cACrC,OAAO,UACP,KAAK,qBAAqB;AAC9B,SAAK,QAAQ,MAAM,WAAW;AAC9B,SAAK,QAAQ,MAAM,QAAQ;AAC3B,SAAK,QAAQ,MAAM,SAAS;AAC5B,SAAK,QAAQ,YAAY,KAAK,OAAO;AAErC,SAAK,iBAAiB,CAAC,MAAoB;AACzC,UAAI,EAAE,WAAW,KAAK,QAAS;AAC/B,UAAI,EAAE,MAAM,SAAS,kCAAkC;AACrD,YAAI;AACF,gBAAM,SAAS,KAAK,2BAA2B;AAC/C,cAA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SAAS,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,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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuno-payments/dashboard-embed-sdk",
3
- "version": "0.3.0",
3
+ "version": "1.0.0",
4
4
  "description": "Lightweight SDK for embedding the Yuno Dashboard via iframe",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,11 +21,16 @@
21
21
  "dev": "tsup --watch",
22
22
  "build": "tsup",
23
23
  "type-check": "tsc --noEmit",
24
+ "test": "vitest",
25
+ "test:run": "vitest run",
24
26
  "prepublishOnly": "npm run build"
25
27
  },
26
28
  "devDependencies": {
29
+ "@vitest/ui": "^4.1.5",
30
+ "jsdom": "^29.1.1",
27
31
  "tsup": "^8.0.1",
28
- "typescript": "~5.8.3"
32
+ "typescript": "~5.8.3",
33
+ "vitest": "^4.1.5"
29
34
  },
30
35
  "repository": {
31
36
  "type": "git",