@spacinbox/sdk 2.1.0 → 2.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/dist/index.d.cts CHANGED
@@ -17,15 +17,19 @@ declare function mountWidget(options: BootOptions): Promise<{
17
17
  success: boolean;
18
18
  }>;
19
19
  setMetadata(data: Record<string, unknown>): void;
20
+ logout(): Promise<void>;
20
21
  shutdown(): void;
21
22
  }>;
22
23
 
23
24
  type Controller = Awaited<ReturnType<typeof mountWidget>>;
24
25
  declare const Spacinbox: {
25
- boot(options: BootOptions): Promise<void>;
26
+ boot(options: BootOptions): Promise<{
27
+ success: boolean;
28
+ }>;
26
29
  identify(user: Parameters<Controller["identify"]>[0]): Promise<{
27
30
  success: boolean;
28
31
  }>;
32
+ logout(): Promise<void | undefined>;
29
33
  setMetadata(data: Record<string, unknown>): void;
30
34
  open(): void;
31
35
  close(): void;
package/dist/index.d.ts CHANGED
@@ -17,15 +17,19 @@ declare function mountWidget(options: BootOptions): Promise<{
17
17
  success: boolean;
18
18
  }>;
19
19
  setMetadata(data: Record<string, unknown>): void;
20
+ logout(): Promise<void>;
20
21
  shutdown(): void;
21
22
  }>;
22
23
 
23
24
  type Controller = Awaited<ReturnType<typeof mountWidget>>;
24
25
  declare const Spacinbox: {
25
- boot(options: BootOptions): Promise<void>;
26
+ boot(options: BootOptions): Promise<{
27
+ success: boolean;
28
+ }>;
26
29
  identify(user: Parameters<Controller["identify"]>[0]): Promise<{
27
30
  success: boolean;
28
31
  }>;
32
+ logout(): Promise<void | undefined>;
29
33
  setMetadata(data: Record<string, unknown>): void;
30
34
  open(): void;
31
35
  close(): void;
package/dist/index.js CHANGED
@@ -1429,6 +1429,16 @@ async function mountWidget(options) {
1429
1429
  setMetadata(data) {
1430
1430
  metadata.value = { ...metadata.value, ...data };
1431
1431
  },
1432
+ async logout() {
1433
+ isOpen.value = false;
1434
+ currentUser.value = null;
1435
+ metadata.value = {};
1436
+ resetRouter();
1437
+ SocketService.disconnect();
1438
+ VisitorService.clear();
1439
+ await VisitorService.init();
1440
+ await SocketService.connect();
1441
+ },
1432
1442
  shutdown() {
1433
1443
  render(null, mountPoint);
1434
1444
  host.remove();
@@ -1448,16 +1458,17 @@ async function mountWidget(options) {
1448
1458
  var controller = null;
1449
1459
  var bootPromise = null;
1450
1460
  var Spacinbox = {
1451
- boot(options) {
1461
+ async boot(options) {
1452
1462
  if (typeof document === "undefined") {
1453
- return Promise.resolve();
1463
+ return Promise.resolve({ success: false });
1454
1464
  }
1455
1465
  if (bootPromise) {
1456
1466
  return bootPromise;
1457
1467
  }
1458
1468
  bootPromise = mountWidget(options).then((instance) => {
1459
1469
  controller = instance;
1460
- });
1470
+ return { success: true };
1471
+ }).catch(() => ({ success: false }));
1461
1472
  return bootPromise;
1462
1473
  },
1463
1474
  async identify(user) {
@@ -1466,6 +1477,9 @@ var Spacinbox = {
1466
1477
  }
1467
1478
  return controller.identify(user);
1468
1479
  },
1480
+ async logout() {
1481
+ return controller?.logout();
1482
+ },
1469
1483
  setMetadata(data) {
1470
1484
  controller?.setMetadata(data);
1471
1485
  },