@spacinbox/sdk 2.0.3 → 2.1.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.cjs +22 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -6
- package/dist/index.d.ts +10 -6
- package/dist/index.js +22 -12
- package/dist/index.js.map +1 -1
- package/dist/widget.global.js +24 -14
- package/dist/widget.global.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -233,8 +233,8 @@ var init_service = __esm({
|
|
|
233
233
|
if (!tokenExpiresAt.value) return true;
|
|
234
234
|
return tokenExpiresAt.value - Date.now() < REFRESH_THRESHOLD_MS;
|
|
235
235
|
},
|
|
236
|
-
identify(user) {
|
|
237
|
-
ApiService.identifyVisitor({
|
|
236
|
+
async identify(user) {
|
|
237
|
+
return await ApiService.identifyVisitor({
|
|
238
238
|
externalId: user.userId,
|
|
239
239
|
name: user.name,
|
|
240
240
|
email: user.email
|
|
@@ -246,7 +246,8 @@ var init_service = __esm({
|
|
|
246
246
|
visitorId.value = visitor_id;
|
|
247
247
|
localStorage.setItem(STORAGE_KEY, visitor_id);
|
|
248
248
|
}
|
|
249
|
-
|
|
249
|
+
return { success: true };
|
|
250
|
+
}).catch(() => ({ success: false }));
|
|
250
251
|
},
|
|
251
252
|
clear() {
|
|
252
253
|
localStorage.removeItem(STORAGE_KEY);
|
|
@@ -1418,10 +1419,9 @@ var compiled_css_default = '/*! tailwindcss v4.2.1 | MIT License | https://tailw
|
|
|
1418
1419
|
init_service();
|
|
1419
1420
|
init_state();
|
|
1420
1421
|
var import_jsx_runtime20 = require("preact/jsx-runtime");
|
|
1421
|
-
function mountWidget(options) {
|
|
1422
|
+
async function mountWidget(options) {
|
|
1422
1423
|
const { appId: id, hideButton = false } = options;
|
|
1423
1424
|
appId.value = id;
|
|
1424
|
-
VisitorService.init().then(() => SocketService.connect());
|
|
1425
1425
|
const host = document.createElement("div");
|
|
1426
1426
|
host.id = "spacinbox-widget";
|
|
1427
1427
|
document.body.appendChild(host);
|
|
@@ -1432,6 +1432,8 @@ function mountWidget(options) {
|
|
|
1432
1432
|
const mountPoint = document.createElement("div");
|
|
1433
1433
|
shadow.appendChild(mountPoint);
|
|
1434
1434
|
(0, import_preact2.render)(/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Widget, { hideButton }), mountPoint);
|
|
1435
|
+
await VisitorService.init();
|
|
1436
|
+
await SocketService.connect();
|
|
1435
1437
|
return {
|
|
1436
1438
|
open() {
|
|
1437
1439
|
isOpen.value = true;
|
|
@@ -1441,7 +1443,7 @@ function mountWidget(options) {
|
|
|
1441
1443
|
},
|
|
1442
1444
|
identify(user) {
|
|
1443
1445
|
currentUser.value = user;
|
|
1444
|
-
VisitorService.identify(user);
|
|
1446
|
+
return VisitorService.identify(user);
|
|
1445
1447
|
},
|
|
1446
1448
|
setMetadata(data) {
|
|
1447
1449
|
metadata.value = { ...metadata.value, ...data };
|
|
@@ -1463,18 +1465,25 @@ function mountWidget(options) {
|
|
|
1463
1465
|
|
|
1464
1466
|
// src/index.ts
|
|
1465
1467
|
var controller = null;
|
|
1468
|
+
var bootPromise = null;
|
|
1466
1469
|
var Spacinbox = {
|
|
1467
1470
|
boot(options) {
|
|
1468
1471
|
if (typeof document === "undefined") {
|
|
1469
|
-
return;
|
|
1472
|
+
return Promise.resolve();
|
|
1470
1473
|
}
|
|
1471
|
-
if (
|
|
1472
|
-
return;
|
|
1474
|
+
if (bootPromise) {
|
|
1475
|
+
return bootPromise;
|
|
1473
1476
|
}
|
|
1474
|
-
|
|
1477
|
+
bootPromise = mountWidget(options).then((instance) => {
|
|
1478
|
+
controller = instance;
|
|
1479
|
+
});
|
|
1480
|
+
return bootPromise;
|
|
1475
1481
|
},
|
|
1476
|
-
identify(user) {
|
|
1477
|
-
controller
|
|
1482
|
+
async identify(user) {
|
|
1483
|
+
if (!controller) {
|
|
1484
|
+
return { success: false };
|
|
1485
|
+
}
|
|
1486
|
+
return controller.identify(user);
|
|
1478
1487
|
},
|
|
1479
1488
|
setMetadata(data) {
|
|
1480
1489
|
controller?.setMetadata(data);
|
|
@@ -1488,6 +1497,7 @@ var Spacinbox = {
|
|
|
1488
1497
|
shutdown() {
|
|
1489
1498
|
controller?.shutdown();
|
|
1490
1499
|
controller = null;
|
|
1500
|
+
bootPromise = null;
|
|
1491
1501
|
}
|
|
1492
1502
|
};
|
|
1493
1503
|
var index_default = Spacinbox;
|