@spacinbox/sdk 2.0.2 → 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.
@@ -1218,8 +1218,8 @@
1218
1218
  if (!tokenExpiresAt.value) return true;
1219
1219
  return tokenExpiresAt.value - Date.now() < REFRESH_THRESHOLD_MS;
1220
1220
  },
1221
- identify(user) {
1222
- ApiService.identifyVisitor({
1221
+ async identify(user) {
1222
+ return await ApiService.identifyVisitor({
1223
1223
  externalId: user.userId,
1224
1224
  name: user.name,
1225
1225
  email: user.email
@@ -1231,7 +1231,8 @@
1231
1231
  visitorId.value = visitor_id;
1232
1232
  localStorage.setItem(STORAGE_KEY, visitor_id);
1233
1233
  }
1234
- });
1234
+ return { success: true };
1235
+ }).catch(() => ({ success: false }));
1235
1236
  },
1236
1237
  clear() {
1237
1238
  localStorage.removeItem(STORAGE_KEY);
@@ -4937,7 +4938,7 @@
4937
4938
  var SocketService = {
4938
4939
  async connect() {
4939
4940
  const token = sessionToken.value;
4940
- socket.value = lookup2("https://ws.spacinbox.com", {
4941
+ socket.value = lookup2("https://ws.simple-login.com", {
4941
4942
  auth: { token },
4942
4943
  reconnection: true
4943
4944
  });
@@ -5933,10 +5934,9 @@
5933
5934
  // src/widget/mount.tsx
5934
5935
  init_service();
5935
5936
  init_state();
5936
- function mountWidget(options) {
5937
+ async function mountWidget(options) {
5937
5938
  const { appId: id, hideButton = false } = options;
5938
5939
  appId.value = id;
5939
- VisitorService.init().then(() => SocketService.connect());
5940
5940
  const host = document.createElement("div");
5941
5941
  host.id = "spacinbox-widget";
5942
5942
  document.body.appendChild(host);
@@ -5947,6 +5947,8 @@
5947
5947
  const mountPoint = document.createElement("div");
5948
5948
  shadow.appendChild(mountPoint);
5949
5949
  J(/* @__PURE__ */ u4(Widget, { hideButton }), mountPoint);
5950
+ await VisitorService.init();
5951
+ await SocketService.connect();
5950
5952
  return {
5951
5953
  open() {
5952
5954
  isOpen.value = true;
@@ -5956,7 +5958,7 @@
5956
5958
  },
5957
5959
  identify(user) {
5958
5960
  currentUser.value = user;
5959
- VisitorService.identify(user);
5961
+ return VisitorService.identify(user);
5960
5962
  },
5961
5963
  setMetadata(data) {
5962
5964
  metadata.value = { ...metadata.value, ...data };
@@ -5978,18 +5980,25 @@
5978
5980
 
5979
5981
  // src/index.ts
5980
5982
  var controller = null;
5983
+ var bootPromise = null;
5981
5984
  var Spacinbox = {
5982
5985
  boot(options) {
5983
5986
  if (typeof document === "undefined") {
5984
- return;
5987
+ return Promise.resolve();
5985
5988
  }
5986
- if (controller) {
5987
- return;
5989
+ if (bootPromise) {
5990
+ return bootPromise;
5988
5991
  }
5989
- controller = mountWidget(options);
5992
+ bootPromise = mountWidget(options).then((instance) => {
5993
+ controller = instance;
5994
+ });
5995
+ return bootPromise;
5990
5996
  },
5991
- identify(user) {
5992
- controller?.identify(user);
5997
+ async identify(user) {
5998
+ if (!controller) {
5999
+ return { success: false };
6000
+ }
6001
+ return controller.identify(user);
5993
6002
  },
5994
6003
  setMetadata(data) {
5995
6004
  controller?.setMetadata(data);
@@ -6003,6 +6012,7 @@
6003
6012
  shutdown() {
6004
6013
  controller?.shutdown();
6005
6014
  controller = null;
6015
+ bootPromise = null;
6006
6016
  }
6007
6017
  };
6008
6018
  var src_default = Spacinbox;
@@ -6013,8 +6023,8 @@
6013
6023
  var appId2 = script?.dataset?.appId;
6014
6024
  var opened = typeof script?.dataset?.opened === "string";
6015
6025
  if (appId2) {
6016
- const boot = () => {
6017
- src_default.boot({ appId: appId2 });
6026
+ const boot = async () => {
6027
+ await src_default.boot({ appId: appId2 });
6018
6028
  if (opened) {
6019
6029
  src_default.open();
6020
6030
  }