@ujet/websdk-headless 3.6.3 → 3.6.4

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.mjs CHANGED
@@ -18,7 +18,7 @@ function SI(e, r) {
18
18
  return Object.freeze(Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }));
19
19
  }
20
20
  var au = /* @__PURE__ */ ((e) => (e.WAITING = "waiting", e.READY = "ready", e.IN_PROGRESS = "in_progress", e.FINISHED = "finished", e))(au || {});
21
- const $ee = "prod", J0 = "3.6.3", jg = "https://main.api.ujet.co", Kr = {
21
+ const $ee = "prod", J0 = "3.6.4", jg = "https://main.api.ujet.co", Kr = {
22
22
  companyId: "",
23
23
  tenant: "",
24
24
  trackerId: "",
@@ -845,7 +845,7 @@ function sO(e) {
845
845
  cobrowse: n,
846
846
  companyId: e.companyId,
847
847
  location: location.href,
848
- version: e.version || "3.6.3",
848
+ version: e.version || "3.6.4",
849
849
  bridge: i
850
850
  };
851
851
  }
@@ -1065,86 +1065,100 @@ class bO {
1065
1065
  });
1066
1066
  }
1067
1067
  get id() {
1068
- return this.state.id;
1068
+ var r;
1069
+ return ((r = this.state) == null ? void 0 : r.id) || -1;
1069
1070
  }
1070
1071
  get menuId() {
1071
- return this.state.menus[this.state.menus.length - 1].id;
1072
+ return this.state ? this.state.menus[this.state.menus.length - 1].id : -1;
1072
1073
  }
1073
1074
  get channelId() {
1074
- return this.state.provider_channel_id;
1075
+ var r;
1076
+ return ((r = this.state) == null ? void 0 : r.provider_channel_id) || "";
1075
1077
  }
1076
1078
  get lang() {
1077
- return this.state.lang;
1079
+ var r;
1080
+ return ((r = this.state) == null ? void 0 : r.lang) || "";
1078
1081
  }
1079
1082
  get virtual() {
1080
- return mO.indexOf(this.state.status) !== -1;
1083
+ return mO.indexOf(this.status) !== -1;
1081
1084
  }
1082
1085
  get muted() {
1083
- return this.provider.muted;
1086
+ var r;
1087
+ return ((r = this.provider) == null ? void 0 : r.muted) || !1;
1084
1088
  }
1085
1089
  set muted(r) {
1086
- this.provider.muted = r;
1090
+ this.provider && (this.provider.muted = r);
1087
1091
  }
1088
1092
  get agent() {
1089
- return this.virtual ? this.state.external_agent ? this.state.external_agent : this.state.virtual_agent : this.state.agent || this.state.virtual_agent;
1093
+ return this.state ? this.virtual ? this.state.external_agent || this.state.virtual_agent : this.state.agent || this.state.virtual_agent : null;
1090
1094
  }
1091
1095
  get allAgents() {
1096
+ var r, t;
1092
1097
  return {
1093
- virtual: this.state.all_virtual_agents,
1094
- human: this.state.all_agents
1098
+ virtual: ((r = this.state) == null ? void 0 : r.all_virtual_agents) || [],
1099
+ human: ((t = this.state) == null ? void 0 : t.all_agents) || []
1095
1100
  };
1096
1101
  }
1097
1102
  get userIdentity() {
1098
- return this.provider.identity;
1103
+ var r;
1104
+ return ((r = this.provider) == null ? void 0 : r.identity) || "";
1099
1105
  }
1100
1106
  get status() {
1101
- return this.state.status;
1107
+ var r;
1108
+ return ((r = this.state) == null ? void 0 : r.status) || "";
1102
1109
  }
1103
1110
  get postSessionStatus() {
1104
- return this.state.post_session_transfer_status;
1111
+ var r;
1112
+ return ((r = this.state) == null ? void 0 : r.post_session_transfer_status) || "";
1105
1113
  }
1106
1114
  get statusText() {
1107
- return this.state.status_text;
1115
+ var r;
1116
+ return ((r = this.state) == null ? void 0 : r.status_text) || "";
1108
1117
  }
1109
1118
  get cobrowsable() {
1110
- return this.state.features.indexOf("cobrowse") !== -1;
1119
+ return this.state ? this.state.features.indexOf("cobrowse") !== -1 : !1;
1111
1120
  }
1112
1121
  get ongoing() {
1113
- return gO.indexOf(this.state.status) != -1;
1122
+ return gO.indexOf(this.status) != -1;
1114
1123
  }
1115
1124
  get assigned() {
1116
- return oT.indexOf(this.state.status) != -1;
1125
+ return oT.indexOf(this.status) != -1;
1117
1126
  }
1118
1127
  get dismissed() {
1119
- return uT.indexOf(this.state.status) != -1;
1128
+ return uT.indexOf(this.status) != -1;
1120
1129
  }
1121
1130
  get ended() {
1122
- return yO.indexOf(this.state.status) != -1;
1131
+ return yO.indexOf(this.status) != -1;
1123
1132
  }
1124
1133
  get transcriptCount() {
1125
- return this.state.transcript_requested_count;
1134
+ var r;
1135
+ return ((r = this.state) == null ? void 0 : r.transcript_requested_count) || 0;
1126
1136
  }
1127
1137
  get createdAt() {
1128
- return this.state.created_at;
1138
+ var r;
1139
+ return ((r = this.state) == null ? void 0 : r.created_at) || "";
1129
1140
  }
1130
1141
  get inTask() {
1131
- return this.provider.inTask;
1142
+ var r;
1143
+ return ((r = this.provider) == null ? void 0 : r.inTask) || !1;
1132
1144
  }
1133
1145
  get feedbackType() {
1134
1146
  var r;
1135
- return this.state.survey_enabled ? "survey" : (r = this.state.csat_settings) != null && r.enabled ? "rate" : "none";
1147
+ return this.state ? this.state.survey_enabled ? "survey" : (r = this.state.csat_settings) != null && r.enabled ? "rate" : "none" : "none";
1136
1148
  }
1137
1149
  get optInRequired() {
1138
- return this.state.post_session_opt_in_required;
1150
+ var r;
1151
+ return ((r = this.state) == null ? void 0 : r.post_session_opt_in_required) || !1;
1139
1152
  }
1140
1153
  get postSessionRequired() {
1141
- return this.state.post_session_required;
1154
+ var r;
1155
+ return ((r = this.state) == null ? void 0 : r.post_session_required) || !1;
1142
1156
  }
1143
1157
  get postSessionInProgress() {
1144
- return this.state.post_session_transfer_status === au.IN_PROGRESS;
1158
+ return this.state ? this.state.post_session_transfer_status === au.IN_PROGRESS : !1;
1145
1159
  }
1146
1160
  update(r) {
1147
- r.id == this.state.id && (this.state = r, r.status === "canceled" ? this.triggerEvent("ended", this) : this.triggerEvent("updated", this));
1161
+ !this.state || this.state.id !== r.id || (this.state = r, r.status === "canceled" ? this.triggerEvent("ended", this) : this.triggerEvent("updated", this));
1148
1162
  }
1149
1163
  on(r, t) {
1150
1164
  this.events.addEventListener(r, t);
@@ -1154,13 +1168,20 @@ class bO {
1154
1168
  }
1155
1169
  async connect() {
1156
1170
  try {
1157
- return await Kg(() => {
1158
- var r;
1159
- return (r = this.provider) == null ? void 0 : r.create();
1171
+ if (await Kg(() => {
1172
+ var n;
1173
+ return (n = this.provider) == null ? void 0 : n.create();
1160
1174
  }, 3), await Kg(() => {
1161
- var r;
1162
- return (r = this.provider) == null ? void 0 : r.join(this.state.provider_channel_id);
1163
- }, 3), this.provider ? (this.connected = !0, this.triggerEvent("connected", this), Zf.info("connected with provider", this.state.provider_type), !0) : (Zf.info("connecting interrupted"), !1);
1175
+ var n;
1176
+ return (n = this.provider) == null ? void 0 : n.join(this.state.provider_channel_id);
1177
+ }, 3), !this.provider)
1178
+ return Zf.info("connecting interrupted"), !1;
1179
+ this.connected = !0;
1180
+ const r = await this.fetchMessages(), t = {
1181
+ chat: this,
1182
+ messages: r
1183
+ };
1184
+ return this.triggerEvent("connectedMessages", t), this.triggerEvent("connected", this), this.registerProviderEvents(), Zf.info("connected with provider", this.state.provider_type), !0;
1164
1185
  } catch {
1165
1186
  return !1;
1166
1187
  }
@@ -1199,13 +1220,16 @@ class bO {
1199
1220
  await this.store.clear();
1200
1221
  }
1201
1222
  _handleChatEndedEvent(r) {
1202
- this.disconnect(), r.timeout ? (this.state.status = "timeout", this.triggerEvent("timeout", this)) : (this.state.status = "finished", this.triggerEvent("ended", this));
1223
+ this.disconnect(), this.state && (r.timeout ? (this.state.status = "timeout", this.triggerEvent("timeout", this)) : (this.state.status = "finished", this.triggerEvent("ended", this)));
1203
1224
  }
1204
1225
  triggerEvent(r, t) {
1205
1226
  this.events.triggerEvent(r, t), this.globalEvents && this.globalEvents.triggerEvent("chat." + r, t);
1206
1227
  }
1228
+ registerProviderEvents() {
1229
+ this.provider && this.provider.registerConversationEvents();
1230
+ }
1207
1231
  registerMessageEvents(r) {
1208
- r.event === "cobrowseRequestedFromAgent" ? this.events.triggerEvent("_requestCobrowse", "agent") : r.event === "cobrowseRequestedFromEndUser" ? this.events.triggerEvent("_requestCobrowse", "end_user") : r.event === "chatDismissed" ? (this.state.status = "dismissed", this.triggerEvent("dismissed", this)) : r.event === "chatEnded" ? this.events.triggerEvent("_chatEnded", r) : r.event === "escalationStarted" ? this.inEscalation = !0 : (r.event === "escalationFailed" || r.event === "escalationAccepted") && (this.inEscalation = !1);
1232
+ r.event === "cobrowseRequestedFromAgent" ? this.events.triggerEvent("_requestCobrowse", "agent") : r.event === "cobrowseRequestedFromEndUser" ? this.events.triggerEvent("_requestCobrowse", "end_user") : r.event === "chatDismissed" && this.state ? (this.state.status = "dismissed", this.triggerEvent("dismissed", this)) : r.event === "chatEnded" ? this.events.triggerEvent("_chatEnded", r) : r.event === "escalationStarted" ? this.inEscalation = !0 : (r.event === "escalationFailed" || r.event === "escalationAccepted") && (this.inEscalation = !1);
1209
1233
  }
1210
1234
  }
1211
1235
  function cT(e) {
@@ -1552,7 +1576,7 @@ class kO {
1552
1576
  i.update(s);
1553
1577
  }), i.on("_chatEnded", async (s) => {
1554
1578
  const o = await this.getChat(i.id);
1555
- i.update(o), i.ended && i._handleChatEndedEvent(s);
1579
+ i.update(o), (!i.state || i.ended) && i._handleChatEndedEvent(s);
1556
1580
  }), i;
1557
1581
  }
1558
1582
  async createCall(r, t, n) {
@@ -29514,7 +29538,7 @@ class e$ extends Uv {
29514
29538
  }
29515
29539
  async join(t) {
29516
29540
  const n = await this.client.getConversationBySid(t);
29517
- n.status === "joined" ? xn.info("already joined conversation:", t) : (await n.join(), xn.info("success joined conversation:", t)), this.registerEvents(n), this.conversation = n;
29541
+ n.status === "joined" ? xn.info("already joined conversation:", t) : (await n.join(), xn.info("success joined conversation:", t)), this.conversation = n;
29518
29542
  }
29519
29543
  async preview(t) {
29520
29544
  await (await this.conversation.getParticipantByIdentity(this.identity)).updateAttributes({
@@ -29545,6 +29569,9 @@ class e$ extends Uv {
29545
29569
  // no function for twilio
29546
29570
  stopTyping() {
29547
29571
  }
29572
+ registerConversationEvents() {
29573
+ this.registerEvents(this.conversation);
29574
+ }
29548
29575
  registerEvents(t) {
29549
29576
  t.on("messageAdded", (n) => {
29550
29577
  const i = s0(n);
@@ -41861,6 +41888,9 @@ class bI extends Uv {
41861
41888
  stopTyping() {
41862
41889
  this.conversation && this.conversation.stopTyping();
41863
41890
  }
41891
+ registerConversationEvents() {
41892
+ this.registerEvents(this.conversation);
41893
+ }
41864
41894
  registerEvents(t) {
41865
41895
  t.on("message", (n, i) => {
41866
41896
  const a = K0(i, n.userName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ujet/websdk-headless",
3
- "version": "3.6.3",
3
+ "version": "3.6.4",
4
4
  "types": "dist/index.d.ts",
5
5
  "files": [
6
6
  "dist/index.mjs",