@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.d.cts
CHANGED
|
@@ -10,18 +10,22 @@ type BootOptions = {
|
|
|
10
10
|
hideButton?: boolean;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
declare function mountWidget(options: BootOptions): {
|
|
13
|
+
declare function mountWidget(options: BootOptions): Promise<{
|
|
14
14
|
open(): void;
|
|
15
15
|
close(): void;
|
|
16
|
-
identify(user: WidgetUser):
|
|
16
|
+
identify(user: WidgetUser): Promise<{
|
|
17
|
+
success: boolean;
|
|
18
|
+
}>;
|
|
17
19
|
setMetadata(data: Record<string, unknown>): void;
|
|
18
20
|
shutdown(): void;
|
|
19
|
-
}
|
|
21
|
+
}>;
|
|
20
22
|
|
|
21
|
-
type Controller = ReturnType<typeof mountWidget
|
|
23
|
+
type Controller = Awaited<ReturnType<typeof mountWidget>>;
|
|
22
24
|
declare const Spacinbox: {
|
|
23
|
-
boot(options: BootOptions): void
|
|
24
|
-
identify(user: Parameters<Controller["identify"]>[0]):
|
|
25
|
+
boot(options: BootOptions): Promise<void>;
|
|
26
|
+
identify(user: Parameters<Controller["identify"]>[0]): Promise<{
|
|
27
|
+
success: boolean;
|
|
28
|
+
}>;
|
|
25
29
|
setMetadata(data: Record<string, unknown>): void;
|
|
26
30
|
open(): void;
|
|
27
31
|
close(): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,18 +10,22 @@ type BootOptions = {
|
|
|
10
10
|
hideButton?: boolean;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
declare function mountWidget(options: BootOptions): {
|
|
13
|
+
declare function mountWidget(options: BootOptions): Promise<{
|
|
14
14
|
open(): void;
|
|
15
15
|
close(): void;
|
|
16
|
-
identify(user: WidgetUser):
|
|
16
|
+
identify(user: WidgetUser): Promise<{
|
|
17
|
+
success: boolean;
|
|
18
|
+
}>;
|
|
17
19
|
setMetadata(data: Record<string, unknown>): void;
|
|
18
20
|
shutdown(): void;
|
|
19
|
-
}
|
|
21
|
+
}>;
|
|
20
22
|
|
|
21
|
-
type Controller = ReturnType<typeof mountWidget
|
|
23
|
+
type Controller = Awaited<ReturnType<typeof mountWidget>>;
|
|
22
24
|
declare const Spacinbox: {
|
|
23
|
-
boot(options: BootOptions): void
|
|
24
|
-
identify(user: Parameters<Controller["identify"]>[0]):
|
|
25
|
+
boot(options: BootOptions): Promise<void>;
|
|
26
|
+
identify(user: Parameters<Controller["identify"]>[0]): Promise<{
|
|
27
|
+
success: boolean;
|
|
28
|
+
}>;
|
|
25
29
|
setMetadata(data: Record<string, unknown>): void;
|
|
26
30
|
open(): void;
|
|
27
31
|
close(): void;
|
package/dist/index.js
CHANGED
|
@@ -221,8 +221,8 @@ var init_service = __esm({
|
|
|
221
221
|
if (!tokenExpiresAt.value) return true;
|
|
222
222
|
return tokenExpiresAt.value - Date.now() < REFRESH_THRESHOLD_MS;
|
|
223
223
|
},
|
|
224
|
-
identify(user) {
|
|
225
|
-
ApiService.identifyVisitor({
|
|
224
|
+
async identify(user) {
|
|
225
|
+
return await ApiService.identifyVisitor({
|
|
226
226
|
externalId: user.userId,
|
|
227
227
|
name: user.name,
|
|
228
228
|
email: user.email
|
|
@@ -234,7 +234,8 @@ var init_service = __esm({
|
|
|
234
234
|
visitorId.value = visitor_id;
|
|
235
235
|
localStorage.setItem(STORAGE_KEY, visitor_id);
|
|
236
236
|
}
|
|
237
|
-
|
|
237
|
+
return { success: true };
|
|
238
|
+
}).catch(() => ({ success: false }));
|
|
238
239
|
},
|
|
239
240
|
clear() {
|
|
240
241
|
localStorage.removeItem(STORAGE_KEY);
|
|
@@ -1399,10 +1400,9 @@ var compiled_css_default = '/*! tailwindcss v4.2.1 | MIT License | https://tailw
|
|
|
1399
1400
|
init_service();
|
|
1400
1401
|
init_state();
|
|
1401
1402
|
import { jsx as jsx20 } from "preact/jsx-runtime";
|
|
1402
|
-
function mountWidget(options) {
|
|
1403
|
+
async function mountWidget(options) {
|
|
1403
1404
|
const { appId: id, hideButton = false } = options;
|
|
1404
1405
|
appId.value = id;
|
|
1405
|
-
VisitorService.init().then(() => SocketService.connect());
|
|
1406
1406
|
const host = document.createElement("div");
|
|
1407
1407
|
host.id = "spacinbox-widget";
|
|
1408
1408
|
document.body.appendChild(host);
|
|
@@ -1413,6 +1413,8 @@ function mountWidget(options) {
|
|
|
1413
1413
|
const mountPoint = document.createElement("div");
|
|
1414
1414
|
shadow.appendChild(mountPoint);
|
|
1415
1415
|
render(/* @__PURE__ */ jsx20(Widget, { hideButton }), mountPoint);
|
|
1416
|
+
await VisitorService.init();
|
|
1417
|
+
await SocketService.connect();
|
|
1416
1418
|
return {
|
|
1417
1419
|
open() {
|
|
1418
1420
|
isOpen.value = true;
|
|
@@ -1422,7 +1424,7 @@ function mountWidget(options) {
|
|
|
1422
1424
|
},
|
|
1423
1425
|
identify(user) {
|
|
1424
1426
|
currentUser.value = user;
|
|
1425
|
-
VisitorService.identify(user);
|
|
1427
|
+
return VisitorService.identify(user);
|
|
1426
1428
|
},
|
|
1427
1429
|
setMetadata(data) {
|
|
1428
1430
|
metadata.value = { ...metadata.value, ...data };
|
|
@@ -1444,18 +1446,25 @@ function mountWidget(options) {
|
|
|
1444
1446
|
|
|
1445
1447
|
// src/index.ts
|
|
1446
1448
|
var controller = null;
|
|
1449
|
+
var bootPromise = null;
|
|
1447
1450
|
var Spacinbox = {
|
|
1448
1451
|
boot(options) {
|
|
1449
1452
|
if (typeof document === "undefined") {
|
|
1450
|
-
return;
|
|
1453
|
+
return Promise.resolve();
|
|
1451
1454
|
}
|
|
1452
|
-
if (
|
|
1453
|
-
return;
|
|
1455
|
+
if (bootPromise) {
|
|
1456
|
+
return bootPromise;
|
|
1454
1457
|
}
|
|
1455
|
-
|
|
1458
|
+
bootPromise = mountWidget(options).then((instance) => {
|
|
1459
|
+
controller = instance;
|
|
1460
|
+
});
|
|
1461
|
+
return bootPromise;
|
|
1456
1462
|
},
|
|
1457
|
-
identify(user) {
|
|
1458
|
-
controller
|
|
1463
|
+
async identify(user) {
|
|
1464
|
+
if (!controller) {
|
|
1465
|
+
return { success: false };
|
|
1466
|
+
}
|
|
1467
|
+
return controller.identify(user);
|
|
1459
1468
|
},
|
|
1460
1469
|
setMetadata(data) {
|
|
1461
1470
|
controller?.setMetadata(data);
|
|
@@ -1469,6 +1478,7 @@ var Spacinbox = {
|
|
|
1469
1478
|
shutdown() {
|
|
1470
1479
|
controller?.shutdown();
|
|
1471
1480
|
controller = null;
|
|
1481
|
+
bootPromise = null;
|
|
1472
1482
|
}
|
|
1473
1483
|
};
|
|
1474
1484
|
var index_default = Spacinbox;
|