@seaverse/auth-sdk 0.3.9 → 0.4.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/dist/index.d.ts CHANGED
@@ -1056,6 +1056,35 @@ declare class SeaVerseBackendAPIClient {
1056
1056
  * }
1057
1057
  */
1058
1058
  setToken(token: string): void;
1059
+ /**
1060
+ * Check if the application is running inside an iframe
1061
+ * This is a utility method to detect iframe context before calling iframe-specific methods
1062
+ *
1063
+ * @returns true if running in an iframe, false otherwise
1064
+ *
1065
+ * @example
1066
+ * // Check if in iframe before requesting token
1067
+ * if (client.isInIframe()) {
1068
+ * const token = await client.getIframeToken();
1069
+ * client.setToken(token);
1070
+ * } else {
1071
+ * console.log('Not running in an iframe');
1072
+ * }
1073
+ *
1074
+ * @example
1075
+ * // Use as a static method without client instance
1076
+ * if (SeaVerseBackendAPIClient.isInIframe()) {
1077
+ * console.log('Application is embedded in an iframe');
1078
+ * }
1079
+ */
1080
+ static isInIframe(): boolean;
1081
+ /**
1082
+ * Instance method to check if running in an iframe
1083
+ * Calls the static method for convenience
1084
+ *
1085
+ * @returns true if running in an iframe, false otherwise
1086
+ */
1087
+ isInIframe(): boolean;
1059
1088
  /**
1060
1089
  * Get token from parent window via iframe communication
1061
1090
  * This method is designed for scenarios where the application is embedded in an iframe
@@ -1552,6 +1581,7 @@ declare class Toast {
1552
1581
  private static toasts;
1553
1582
  private static nextId;
1554
1583
  private static cssInjected;
1584
+ private static timers;
1555
1585
  /**
1556
1586
  * Show a toast notification
1557
1587
  */
@@ -1579,6 +1609,14 @@ declare class Toast {
1579
1609
  * Create close button SVG
1580
1610
  */
1581
1611
  private static createCloseSVG;
1612
+ /**
1613
+ * Schedule auto-dismiss for a toast
1614
+ */
1615
+ private static scheduleAutoDismiss;
1616
+ /**
1617
+ * Clear auto-dismiss timer for a toast
1618
+ */
1619
+ private static clearAutoDismiss;
1582
1620
  /**
1583
1621
  * Dismiss a toast
1584
1622
  */
package/dist/index.js CHANGED
@@ -1262,6 +1262,51 @@ class SeaVerseBackendAPIClient {
1262
1262
  // Update the httpClient's auth
1263
1263
  this.httpClient.auth = auth;
1264
1264
  }
1265
+ /**
1266
+ * Check if the application is running inside an iframe
1267
+ * This is a utility method to detect iframe context before calling iframe-specific methods
1268
+ *
1269
+ * @returns true if running in an iframe, false otherwise
1270
+ *
1271
+ * @example
1272
+ * // Check if in iframe before requesting token
1273
+ * if (client.isInIframe()) {
1274
+ * const token = await client.getIframeToken();
1275
+ * client.setToken(token);
1276
+ * } else {
1277
+ * console.log('Not running in an iframe');
1278
+ * }
1279
+ *
1280
+ * @example
1281
+ * // Use as a static method without client instance
1282
+ * if (SeaVerseBackendAPIClient.isInIframe()) {
1283
+ * console.log('Application is embedded in an iframe');
1284
+ * }
1285
+ */
1286
+ static isInIframe() {
1287
+ // Only works in browser environment
1288
+ if (typeof window === 'undefined') {
1289
+ return false;
1290
+ }
1291
+ // Check if window.self is not equal to window.top
1292
+ // This is the standard way to detect if running in an iframe
1293
+ try {
1294
+ return window.self !== window.top;
1295
+ }
1296
+ catch (e) {
1297
+ // If we get a SecurityError (cross-origin iframe), we're definitely in an iframe
1298
+ return true;
1299
+ }
1300
+ }
1301
+ /**
1302
+ * Instance method to check if running in an iframe
1303
+ * Calls the static method for convenience
1304
+ *
1305
+ * @returns true if running in an iframe, false otherwise
1306
+ */
1307
+ isInIframe() {
1308
+ return SeaVerseBackendAPIClient.isInIframe();
1309
+ }
1265
1310
  /**
1266
1311
  * Get token from parent window via iframe communication
1267
1312
  * This method is designed for scenarios where the application is embedded in an iframe
@@ -1307,7 +1352,7 @@ class SeaVerseBackendAPIClient {
1307
1352
  return Promise.reject(new Error('getIframeToken() can only be used in browser environment'));
1308
1353
  }
1309
1354
  // Check if we're in an iframe
1310
- if (window.self === window.top) {
1355
+ if (!this.isInIframe()) {
1311
1356
  return Promise.reject(new Error('getIframeToken() can only be used inside an iframe'));
1312
1357
  }
1313
1358
  const timeout = options?.timeout || 30000; // Default 30 seconds
@@ -2179,6 +2224,7 @@ class Toast {
2179
2224
  }
2180
2225
  // Create toast element
2181
2226
  const toast = this.createToast(type, title, message, onClose);
2227
+ const toastId = toast.id;
2182
2228
  // Add to container
2183
2229
  this.container.appendChild(toast);
2184
2230
  this.toasts.push(toast);
@@ -2186,11 +2232,17 @@ class Toast {
2186
2232
  requestAnimationFrame(() => {
2187
2233
  toast.classList.add('toast-show');
2188
2234
  });
2189
- // Auto-dismiss
2235
+ // Auto-dismiss with hover support
2190
2236
  if (duration > 0) {
2191
- setTimeout(() => {
2192
- this.dismiss(toast, onClose);
2193
- }, duration);
2237
+ this.scheduleAutoDismiss(toast, duration, onClose);
2238
+ // Pause auto-dismiss on hover
2239
+ toast.addEventListener('mouseenter', () => {
2240
+ this.clearAutoDismiss(toastId);
2241
+ });
2242
+ // Resume auto-dismiss on leave
2243
+ toast.addEventListener('mouseleave', () => {
2244
+ this.scheduleAutoDismiss(toast, duration, onClose);
2245
+ });
2194
2246
  }
2195
2247
  }
2196
2248
  /**
@@ -2404,6 +2456,30 @@ class Toast {
2404
2456
  svg.appendChild(path);
2405
2457
  return svg;
2406
2458
  }
2459
+ /**
2460
+ * Schedule auto-dismiss for a toast
2461
+ */
2462
+ static scheduleAutoDismiss(toast, duration, onClose) {
2463
+ const toastId = toast.id;
2464
+ // Clear existing timer if any
2465
+ this.clearAutoDismiss(toastId);
2466
+ // Schedule new timer
2467
+ const timer = setTimeout(() => {
2468
+ this.dismiss(toast, onClose);
2469
+ this.timers.delete(toastId);
2470
+ }, duration);
2471
+ this.timers.set(toastId, timer);
2472
+ }
2473
+ /**
2474
+ * Clear auto-dismiss timer for a toast
2475
+ */
2476
+ static clearAutoDismiss(toastId) {
2477
+ const timer = this.timers.get(toastId);
2478
+ if (timer) {
2479
+ clearTimeout(timer);
2480
+ this.timers.delete(toastId);
2481
+ }
2482
+ }
2407
2483
  /**
2408
2484
  * Dismiss a toast
2409
2485
  */
@@ -2696,6 +2772,7 @@ Toast.container = null;
2696
2772
  Toast.toasts = [];
2697
2773
  Toast.nextId = 0;
2698
2774
  Toast.cssInjected = false;
2775
+ Toast.timers = new Map();
2699
2776
 
2700
2777
  class AuthModal {
2701
2778
  constructor(options) {