@spacinbox/sdk 2.0.3 → 2.2.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 +24 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -6
- package/dist/index.d.ts +12 -6
- package/dist/index.js +24 -13
- package/dist/index.js.map +1 -1
- package/dist/widget.global.js +26 -15
- package/dist/widget.global.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -10,18 +10,24 @@ 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):
|
|
24
|
-
|
|
25
|
+
boot(options: BootOptions): Promise<{
|
|
26
|
+
success: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
identify(user: Parameters<Controller["identify"]>[0]): Promise<{
|
|
29
|
+
success: boolean;
|
|
30
|
+
}>;
|
|
25
31
|
setMetadata(data: Record<string, unknown>): void;
|
|
26
32
|
open(): void;
|
|
27
33
|
close(): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,18 +10,24 @@ 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):
|
|
24
|
-
|
|
25
|
+
boot(options: BootOptions): Promise<{
|
|
26
|
+
success: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
identify(user: Parameters<Controller["identify"]>[0]): Promise<{
|
|
29
|
+
success: boolean;
|
|
30
|
+
}>;
|
|
25
31
|
setMetadata(data: Record<string, unknown>): void;
|
|
26
32
|
open(): void;
|
|
27
33
|
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,26 @@ function mountWidget(options) {
|
|
|
1444
1446
|
|
|
1445
1447
|
// src/index.ts
|
|
1446
1448
|
var controller = null;
|
|
1449
|
+
var bootPromise = null;
|
|
1447
1450
|
var Spacinbox = {
|
|
1448
|
-
boot(options) {
|
|
1451
|
+
async boot(options) {
|
|
1449
1452
|
if (typeof document === "undefined") {
|
|
1450
|
-
return;
|
|
1453
|
+
return Promise.resolve({ success: false });
|
|
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
|
+
return { success: true };
|
|
1461
|
+
}).catch(() => ({ success: false }));
|
|
1462
|
+
return bootPromise;
|
|
1456
1463
|
},
|
|
1457
|
-
identify(user) {
|
|
1458
|
-
controller
|
|
1464
|
+
async identify(user) {
|
|
1465
|
+
if (!controller) {
|
|
1466
|
+
return { success: false };
|
|
1467
|
+
}
|
|
1468
|
+
return controller.identify(user);
|
|
1459
1469
|
},
|
|
1460
1470
|
setMetadata(data) {
|
|
1461
1471
|
controller?.setMetadata(data);
|
|
@@ -1469,6 +1479,7 @@ var Spacinbox = {
|
|
|
1469
1479
|
shutdown() {
|
|
1470
1480
|
controller?.shutdown();
|
|
1471
1481
|
controller = null;
|
|
1482
|
+
bootPromise = null;
|
|
1472
1483
|
}
|
|
1473
1484
|
};
|
|
1474
1485
|
var index_default = Spacinbox;
|