@opencx/widget-core 4.0.24-prerelease.0 → 4.0.25

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.js CHANGED
@@ -1,15 +1,15 @@
1
- import D from "openapi-fetch";
1
+ import j from "openapi-fetch";
2
2
  import L from "lodash.isequal";
3
- import { v4 as O } from "uuid";
4
- const j = (h) => {
3
+ import { v4 as z } from "uuid";
4
+ const F = (h) => {
5
5
  console.log(h.error);
6
6
  }, N = (h) => {
7
- const i = D({
7
+ const i = j({
8
8
  baseUrl: h.baseUrl
9
9
  }), a = {
10
10
  onRequest: h.onRequest,
11
11
  onResponse: h.onResponse,
12
- onError: h.onError || j
12
+ onError: h.onError || F
13
13
  };
14
14
  return i.use(a), i;
15
15
  };
@@ -73,9 +73,9 @@ class M {
73
73
  abortSignal: t,
74
74
  onProgress: n
75
75
  }) => new Promise((o, r) => {
76
- var w;
77
- const l = new FormData();
78
- l.append("file", e);
76
+ var C;
77
+ const c = new FormData();
78
+ c.append("file", e);
79
79
  const u = new XMLHttpRequest();
80
80
  if (t && (t.addEventListener("abort", () => {
81
81
  u.abort(), r(new DOMException("Aborted", "AbortError"));
@@ -83,18 +83,18 @@ class M {
83
83
  r(new DOMException("Aborted", "AbortError"));
84
84
  return;
85
85
  }
86
- u.upload.addEventListener("progress", (m) => {
87
- if (m.lengthComputable && n) {
88
- const C = Math.round(m.loaded / m.total * 100);
89
- n(C);
86
+ u.upload.addEventListener("progress", (_) => {
87
+ if (_.lengthComputable && n) {
88
+ const v = Math.round(_.loaded / _.total * 100);
89
+ n(v);
90
90
  }
91
91
  }), u.addEventListener("load", () => {
92
92
  if (u.status >= 200 && u.status < 300)
93
93
  try {
94
- const m = JSON.parse(u.responseText);
95
- o(m);
96
- } catch (m) {
97
- r(new Error(`Failed to parse response: ${m}`));
94
+ const _ = JSON.parse(u.responseText);
95
+ o(_);
96
+ } catch (_) {
97
+ r(new Error(`Failed to parse response: ${_}`));
98
98
  }
99
99
  else
100
100
  r(new Error(`Upload failed with status: ${u.status}`));
@@ -103,18 +103,18 @@ class M {
103
103
  }), u.addEventListener("timeout", () => {
104
104
  r(new Error("Upload timed out"));
105
105
  });
106
- const { baseUrl: _ } = this.constructClientOptions(this.userToken), f = `${_}/backend/widget/v2/upload`;
107
- u.open("POST", f), u.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((w = this.config.user) == null ? void 0 : w.token) ? u.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : console.error("User token not set"), u.send(l);
106
+ const { baseUrl: p } = this.constructClientOptions(this.userToken), f = `${p}/backend/widget/v2/upload`;
107
+ u.open("POST", f), u.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((C = this.config.user) == null ? void 0 : C.token) ? u.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : console.error("User token not set"), u.send(c);
108
108
  }), this.vote = async (e) => await this.client.POST("/backend/widget/v2/chat/vote", { body: e }), this.resolveSession = async (e, t) => await this.client.POST("/backend/widget/v2/session/resolve", {
109
109
  body: e,
110
110
  signal: t
111
111
  }), this.createStateCheckpoint = async (e) => await this.client.POST("/backend/widget/v2/checkpoint", {
112
112
  body: e
113
113
  }), this.submitCsat = async (e) => await this.client.POST("/backend/widget/v2/submit-csat", { body: e }), this.config = i, this.userToken = ((d = i.user) == null ? void 0 : d.token) || null;
114
- const { baseUrl: a, headers: c } = this.constructClientOptions(
114
+ const { baseUrl: a, headers: l } = this.constructClientOptions(
115
115
  (s = i.user) == null ? void 0 : s.token
116
116
  );
117
- this.client = this.createOpenAPIClient({ baseUrl: a, headers: c });
117
+ this.client = this.createOpenAPIClient({ baseUrl: a, headers: l });
118
118
  }
119
119
  }
120
120
  function B(h, i) {
@@ -126,8 +126,8 @@ class y {
126
126
  L(this.state, a) || (this.state = a, this.notifySubscribers(a));
127
127
  }, this.setPartial = (a) => {
128
128
  if (a == null) return;
129
- const c = { ...this.state, ...a };
130
- this.set(c);
129
+ const l = { ...this.state, ...a };
130
+ this.set(l);
131
131
  }, this.reset = () => {
132
132
  this.set(this.initialState);
133
133
  }, this.notifySubscribers = (a) => {
@@ -143,7 +143,7 @@ class y {
143
143
  }), this.state = i, this.initialState = i;
144
144
  }
145
145
  }
146
- class R {
146
+ class O {
147
147
  constructor() {
148
148
  this.state = new y({
149
149
  isPolling: !1,
@@ -153,7 +153,7 @@ class R {
153
153
  this.abortController.abort("Resetting poller"), (i = this.stopPolling) == null || i.call(this), this.stopPolling = null;
154
154
  }, this.stopPolling = null, this.startPolling = (i, a) => {
155
155
  if (this.stopPolling) return;
156
- const c = [], d = async () => {
156
+ const l = [], d = async () => {
157
157
  this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
158
158
  try {
159
159
  await i(this.abortController.signal);
@@ -164,10 +164,10 @@ class R {
164
164
  } finally {
165
165
  this.state.setPartial({ isPolling: !1 });
166
166
  }
167
- this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") : c.push(setTimeout(d, a));
167
+ this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") : l.push(setTimeout(d, a));
168
168
  };
169
169
  d(), this.stopPolling = () => {
170
- c.forEach(clearTimeout), this.state.reset();
170
+ l.forEach(clearTimeout), this.state.reset();
171
171
  };
172
172
  };
173
173
  }
@@ -184,11 +184,11 @@ class q {
184
184
  constructor({
185
185
  api: i,
186
186
  config: a,
187
- sessionCtx: c,
187
+ sessionCtx: l,
188
188
  messageCtx: d,
189
189
  sessionPollingIntervalSeconds: s
190
190
  }) {
191
- this.poller = new R(), this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.registerPolling = () => {
191
+ this.poller = new O(), this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.registerPolling = () => {
192
192
  this.sessionCtx.sessionState.subscribe(({ session: e }) => {
193
193
  e != null && e.id ? this.poller.startPolling(async (t) => {
194
194
  this.fetchSessionAndHistory({ sessionId: e.id, abortSignal: t });
@@ -214,17 +214,17 @@ class q {
214
214
  }) => {
215
215
  var u;
216
216
  this.messageCtx.state.get().messages.length === 0 && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
217
- const o = this.messageCtx.state.get().messages, r = o.length > 0 ? ((u = o[o.length - 1]) == null ? void 0 : u.timestamp) ?? void 0 : void 0, { data: l } = await this.api.pollSessionAndHistory({
217
+ const o = this.messageCtx.state.get().messages, r = o.length > 0 ? ((u = o[o.length - 1]) == null ? void 0 : u.timestamp) ?? void 0 : void 0, { data: c } = await this.api.pollSessionAndHistory({
218
218
  sessionId: e,
219
219
  abortSignal: t,
220
220
  lastMessageTimestamp: n ? void 0 : r
221
221
  });
222
- if (l != null && l.session && (this.sessionCtx.sessionState.setPartial({ session: l.session }), this.sessionCtx.setSessions([l.session])), l != null && l.history && l.history.length > 0) {
223
- const _ = this.messageCtx.state.get().messages, S = l.history.map(this.mapHistoryToMessage).filter((f) => f !== null).filter(
224
- (f) => !_.some((v) => v.id === f.id)
222
+ if (c != null && c.session && (this.sessionCtx.sessionState.setPartial({ session: c.session }), this.sessionCtx.setSessions([c.session])), c != null && c.history && c.history.length > 0) {
223
+ const p = this.messageCtx.state.get().messages, S = c.history.map(this.mapHistoryToMessage).filter((f) => f !== null).filter(
224
+ (f) => !p.some((b) => b.id === f.id)
225
225
  );
226
226
  this.messageCtx.state.setPartial({
227
- messages: [..._, ...S]
227
+ messages: [...p, ...S]
228
228
  });
229
229
  }
230
230
  this.messageCtx.state.get().isInitialFetchLoading && this.messageCtx.state.setPartial({ isInitialFetchLoading: !1 });
@@ -334,40 +334,40 @@ class q {
334
334
  if (o) return o;
335
335
  }
336
336
  return e.result;
337
- }, this.api = i, this.config = a, this.sessionCtx = c, this.messageCtx = d, this.sessionPollingIntervalSeconds = s, this.registerPolling();
337
+ }, this.api = i, this.config = a, this.sessionCtx = l, this.messageCtx = d, this.sessionPollingIntervalSeconds = s, this.registerPolling();
338
338
  }
339
339
  }
340
- class Y {
340
+ class V {
341
341
  constructor({
342
342
  config: i,
343
343
  api: a,
344
- storageCtx: c
344
+ storageCtx: l
345
345
  }) {
346
346
  var d;
347
347
  this.shouldCollectData = () => {
348
348
  var s;
349
349
  return !!(!((s = this.state.get().contact) != null && s.token) && this.config.collectUserData);
350
350
  }, this.autoCreateUnverifiedUserIfNotExists = async () => {
351
- var s, e, t, n, o, r, l, u, _, S, f, v, w, m;
351
+ var s, e, t, n, o, r, c, u, p, S, f, b, C, _;
352
352
  if (!((s = this.config.user) != null && s.token)) {
353
353
  if (this.config.collectUserData && !((t = (e = this.config.user) == null ? void 0 : e.data) != null && t.email)) {
354
354
  if ((n = this.config.extraDataCollectionFields) != null && n.length)
355
355
  return;
356
- const C = await ((o = this.storageCtx) == null ? void 0 : o.getContactToken());
357
- C && await this.setUnverifiedContact(C);
356
+ const v = await ((o = this.storageCtx) == null ? void 0 : o.getContactToken());
357
+ v && await this.setUnverifiedContact(v);
358
358
  return;
359
359
  }
360
- if (!((l = (r = this.config.user) == null ? void 0 : r.data) != null && l.email)) {
361
- const C = await ((u = this.storageCtx) == null ? void 0 : u.getContactToken());
362
- if (C) {
363
- await this.setUnverifiedContact(C);
360
+ if (!((c = (r = this.config.user) == null ? void 0 : r.data) != null && c.email)) {
361
+ const v = await ((u = this.storageCtx) == null ? void 0 : u.getContactToken());
362
+ if (v) {
363
+ await this.setUnverifiedContact(v);
364
364
  return;
365
365
  }
366
366
  }
367
367
  await this.createUnverifiedContact({
368
- email: (S = (_ = this.config.user) == null ? void 0 : _.data) == null ? void 0 : S.email,
369
- non_verified_name: (v = (f = this.config.user) == null ? void 0 : f.data) == null ? void 0 : v.name,
370
- non_verified_custom_data: (m = (w = this.config.user) == null ? void 0 : w.data) == null ? void 0 : m.customData
368
+ email: (S = (p = this.config.user) == null ? void 0 : p.data) == null ? void 0 : S.email,
369
+ non_verified_name: (b = (f = this.config.user) == null ? void 0 : f.data) == null ? void 0 : b.name,
370
+ non_verified_custom_data: (_ = (C = this.config.user) == null ? void 0 : C.data) == null ? void 0 : _.customData
371
371
  });
372
372
  }
373
373
  }, this.createUnverifiedContact = async (s, e) => {
@@ -383,10 +383,10 @@ class Y {
383
383
  this.state.setPartial({ isCreatingUnverifiedContact: !1 });
384
384
  }
385
385
  }, this.setUnverifiedContact = async (s) => {
386
- var n, o, r, l;
387
- const e = await ((n = this.storageCtx) == null ? void 0 : n.getExternalContactId()), t = ((o = this.config.user) == null ? void 0 : o.externalId) || e || O();
388
- this.api.setAuthToken(s), await ((r = this.storageCtx) == null ? void 0 : r.setContactToken(s)), await ((l = this.storageCtx) == null ? void 0 : l.setExternalContactId(t)), this.state.setPartial({ contact: { token: s, externalId: t } });
389
- }, this.config = i, this.storageCtx = c, this.api = a, this.state = new y({
386
+ var n, o, r, c;
387
+ const e = await ((n = this.storageCtx) == null ? void 0 : n.getExternalContactId()), t = ((o = this.config.user) == null ? void 0 : o.externalId) || e || z();
388
+ this.api.setAuthToken(s), await ((r = this.storageCtx) == null ? void 0 : r.setContactToken(s)), await ((c = this.storageCtx) == null ? void 0 : c.setExternalContactId(t)), this.state.setPartial({ contact: { token: s, externalId: t } });
389
+ }, this.config = i, this.storageCtx = l, this.api = a, this.state = new y({
390
390
  contact: (d = i.user) != null && d.token ? {
391
391
  token: i.user.token,
392
392
  // Set optional externalId from config... not local storage
@@ -398,14 +398,14 @@ class Y {
398
398
  }), this.autoCreateUnverifiedUserIfNotExists();
399
399
  }
400
400
  }
401
- function x() {
402
- return O();
401
+ function k() {
402
+ return z();
403
403
  }
404
- class $ {
404
+ class Y {
405
405
  constructor({
406
406
  config: i,
407
407
  api: a,
408
- sessionCtx: c,
408
+ sessionCtx: l,
409
409
  messageCtx: d
410
410
  }) {
411
411
  this.submitCsat = async (s) => {
@@ -413,7 +413,7 @@ class $ {
413
413
  const e = (r = this.sessionCtx.sessionState.get().session) == null ? void 0 : r.id;
414
414
  if (!e)
415
415
  return { data: null, error: "No session id found" };
416
- const t = x();
416
+ const t = k();
417
417
  this.messageCtx.state.setPartial({
418
418
  messages: [
419
419
  ...this.messageCtx.state.get().messages,
@@ -437,17 +437,17 @@ class $ {
437
437
  session_id: e
438
438
  });
439
439
  return { data: n, error: o };
440
- }, this.config = i, this.api = a, this.sessionCtx = c, this.messageCtx = d;
440
+ }, this.config = i, this.api = a, this.sessionCtx = l, this.messageCtx = d;
441
441
  }
442
442
  }
443
- class G {
443
+ class $ {
444
444
  constructor({
445
445
  config: i,
446
446
  api: a,
447
- contactCtx: c,
447
+ contactCtx: l,
448
448
  sessionsPollingIntervalSeconds: d
449
449
  }) {
450
- this.sessionsRefresher = new R(), this.sessionState = new y({
450
+ this.sessionsRefresher = new O(), this.sessionState = new y({
451
451
  session: null,
452
452
  isCreatingSession: !1,
453
453
  isResolvingSession: !1
@@ -489,7 +489,7 @@ class G {
489
489
  });
490
490
  if (s) {
491
491
  const t = [...this.sessionsState.get().data, ...s.items].filter(
492
- (n, o, r) => o === r.findIndex((l) => n.id === l.id)
492
+ (n, o, r) => o === r.findIndex((c) => n.id === c.id)
493
493
  );
494
494
  this.sessionsState.setPartial({
495
495
  data: t,
@@ -533,14 +533,14 @@ class G {
533
533
  payload: s
534
534
  });
535
535
  return t != null && t.success ? { success: !0 } : { success: !1 };
536
- }, this.config = i, this.api = a, this.contactCtx = c, this.sessionsPollingIntervalSeconds = d, this.registerSessionsRefresherWrapper();
536
+ }, this.config = i, this.api = a, this.contactCtx = l, this.sessionsPollingIntervalSeconds = d, this.registerSessionsRefresherWrapper();
537
537
  }
538
538
  }
539
539
  class K {
540
540
  constructor({
541
541
  config: i,
542
542
  api: a,
543
- sessionCtx: c,
543
+ sessionCtx: l,
544
544
  contactCtx: d
545
545
  }) {
546
546
  this.state = new y({
@@ -551,7 +551,7 @@ class K {
551
551
  }), this.sendMessageAbortController = new AbortController(), this.reset = () => {
552
552
  this.sendMessageAbortController.abort("Resetting chat"), this.state.reset();
553
553
  }, this.sendMessage = async (s) => {
554
- var e, t, n, o, r, l, u, _, S, f;
554
+ var e, t, n, o, r, c, u, p, S, f;
555
555
  try {
556
556
  if (!s.content.trim() && (!s.attachments || s.attachments.length === 0)) {
557
557
  console.warn(
@@ -559,16 +559,16 @@ class K {
559
559
  );
560
560
  return;
561
561
  }
562
- const v = this.state.get().isSendingMessage, w = ((e = this.sessionCtx.sessionState.get().session) == null ? void 0 : e.assignee.kind) === "ai", m = this.state.get().messages, C = m.length > 0 ? m[m.length - 1] : void 0;
563
- if (w && v || // If last message is from user, then bot response did not arrive yet
564
- w && (C == null ? void 0 : C.type) === "USER") {
562
+ const b = this.state.get().isSendingMessage, C = ((e = this.sessionCtx.sessionState.get().session) == null ? void 0 : e.assignee.kind) === "ai", _ = this.state.get().messages, v = _.length > 0 ? _[_.length - 1] : void 0;
563
+ if (C && b || // If last message is from user, then bot response did not arrive yet
564
+ C && (v == null ? void 0 : v.type) === "USER") {
565
565
  console.warn("Cannot send messages while awaiting AI response");
566
566
  return;
567
567
  }
568
568
  this.sendMessageAbortController = new AbortController(), this.state.setPartial({ lastAIResMightSolveUserIssue: !1 }), this.state.setPartial({ isSendingMessage: !0 });
569
569
  const P = this.state.get().messages, A = !((t = this.sessionCtx.sessionState.get().session) != null && t.id) && P.length === 0 && ((n = this.config.advancedInitialMessages) == null ? void 0 : n.some((g) => g.persistent)), T = A ? (this.config.advancedInitialMessages || []).filter((g) => g.persistent).map(
570
570
  (g) => ({
571
- id: x(),
571
+ id: k(),
572
572
  component: "bot_message",
573
573
  type: "AI",
574
574
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -595,7 +595,7 @@ class K {
595
595
  }
596
596
  const E = (r = this.sessionCtx.sessionState.get().session) == null ? void 0 : r.id;
597
597
  if (!E) return;
598
- const { data: p } = await this.api.sendMessage(
598
+ const { data: m } = await this.api.sendMessage(
599
599
  {
600
600
  uuid: I.id,
601
601
  bot_token: this.config.token,
@@ -619,47 +619,47 @@ class K {
619
619
  },
620
620
  this.sendMessageAbortController.signal
621
621
  );
622
- if (p != null && p.success) {
623
- const g = this.toBotMessage(p);
622
+ if (m != null && m.success) {
623
+ const g = this.toBotMessage(m);
624
624
  if (g) {
625
- const k = this.state.get().messages;
626
- if (!!k.some(
627
- (F) => F.id === g.id
625
+ const x = this.state.get().messages;
626
+ if (!!x.some(
627
+ (D) => D.id === g.id
628
628
  )) {
629
629
  this.state.setPartial({
630
- lastAIResMightSolveUserIssue: ((l = p.autopilotResponse) == null ? void 0 : l.mightSolveUserIssue) || ((u = p.uiResponse) == null ? void 0 : u.mightSolveUserIssue)
630
+ lastAIResMightSolveUserIssue: ((c = m.autopilotResponse) == null ? void 0 : c.mightSolveUserIssue) || ((u = m.uiResponse) == null ? void 0 : u.mightSolveUserIssue)
631
631
  });
632
632
  return;
633
633
  }
634
634
  this.state.setPartial({
635
- messages: [...k, g],
636
- lastAIResMightSolveUserIssue: ((_ = p.autopilotResponse) == null ? void 0 : _.mightSolveUserIssue) || ((S = p.uiResponse) == null ? void 0 : S.mightSolveUserIssue)
635
+ messages: [...x, g],
636
+ lastAIResMightSolveUserIssue: ((p = m.autopilotResponse) == null ? void 0 : p.mightSolveUserIssue) || ((S = m.uiResponse) == null ? void 0 : S.mightSolveUserIssue)
637
637
  });
638
638
  }
639
- p.session && this.sessionCtx.sessionState.setPartial({ session: p.session });
639
+ m.session && this.sessionCtx.sessionState.setPartial({ session: m.session });
640
640
  } else {
641
641
  const g = this.toBotErrorMessage(
642
- ((f = p == null ? void 0 : p.error) == null ? void 0 : f.message) || "Unknown error occurred"
643
- ), k = this.state.get().messages;
642
+ ((f = m == null ? void 0 : m.error) == null ? void 0 : f.message) || "Unknown error occurred"
643
+ ), x = this.state.get().messages;
644
644
  this.state.setPartial({
645
- messages: [...k, g]
645
+ messages: [...x, g]
646
646
  });
647
647
  }
648
- } catch (v) {
649
- this.sendMessageAbortController.signal.aborted || console.error("Failed to send message:", v);
648
+ } catch (b) {
649
+ this.sendMessageAbortController.signal.aborted || console.error("Failed to send message:", b);
650
650
  } finally {
651
651
  this.state.setPartial({ isSendingMessage: !1 });
652
652
  }
653
653
  }, this.toUserMessage = (s, e) => {
654
654
  const t = (() => {
655
655
  const n = this.contactCtx.state.get().extraCollectedData;
656
- return this.state.get().messages.length === 0 && n && Object.keys(n).length > 0 ? `${Object.entries(n).filter(([r, l]) => !!l).map(([r, l]) => `${r}: ${l}`).join(`
656
+ return this.state.get().messages.length === 0 && n && Object.keys(n).length > 0 ? `${Object.entries(n).filter(([r, c]) => !!c).map(([r, c]) => `${r}: ${c}`).join(`
657
657
  `)}
658
658
 
659
659
  ${s}` : s;
660
660
  })();
661
661
  return {
662
- id: x(),
662
+ id: k(),
663
663
  type: "USER",
664
664
  content: t,
665
665
  deliveredAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -670,7 +670,7 @@ ${s}` : s;
670
670
  var e;
671
671
  return s.success && s.autopilotResponse ? {
672
672
  type: "AI",
673
- id: s.autopilotResponse.id || x(),
673
+ id: s.autopilotResponse.id || k(),
674
674
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
675
675
  component: "bot_message",
676
676
  agent: this.config.bot ? {
@@ -689,7 +689,7 @@ ${s}` : s;
689
689
  } : null;
690
690
  }, this.toBotErrorMessage = (s) => ({
691
691
  type: "AI",
692
- id: x(),
692
+ id: k(),
693
693
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
694
694
  component: "TEXT",
695
695
  data: {
@@ -697,14 +697,14 @@ ${s}` : s;
697
697
  variant: "error",
698
698
  action: void 0
699
699
  }
700
- }), this.config = i, this.api = a, this.sessionCtx = c, this.contactCtx = d;
700
+ }), this.config = i, this.api = a, this.sessionCtx = l, this.contactCtx = d;
701
701
  }
702
702
  }
703
- class W {
703
+ class G {
704
704
  constructor({
705
705
  config: i,
706
706
  contactCtx: a,
707
- sessionCtx: c,
707
+ sessionCtx: l,
708
708
  resetChat: d
709
709
  }) {
710
710
  var s;
@@ -716,14 +716,14 @@ class W {
716
716
  });
717
717
  }), this.sessionCtx.sessionsState.subscribe(
718
718
  ({ isInitialFetchLoading: e, data: t }) => {
719
- var n, o, r, l;
719
+ var n, o, r, c;
720
720
  if ((n = this.config.router) != null && n.chatScreenOnly && // Do not route to a chat if we are currently inside one already
721
721
  // This also applies to newly created sessions; the new session will be in `sessionState` before it is refreshed and included in `sessionsState`
722
722
  !((o = this.sessionCtx.sessionState.get().session) != null && o.id)) {
723
- const u = (r = t.find((_) => _.isOpened)) == null ? void 0 : r.id;
723
+ const u = (r = t.find((p) => p.isOpened)) == null ? void 0 : r.id;
724
724
  return u ? this.toChatScreen(u) : void 0;
725
725
  }
726
- t.length || ((l = this.config.router) == null ? void 0 : l.goToChatIfNoSessions) !== !1 && !e && this.state.get().screen !== "chat" && this.toChatScreen();
726
+ t.length || ((c = this.config.router) == null ? void 0 : c.goToChatIfNoSessions) !== !1 && !e && this.state.get().screen !== "chat" && this.toChatScreen();
727
727
  }
728
728
  );
729
729
  }, this.toSessionsScreen = () => {
@@ -735,54 +735,54 @@ class W {
735
735
  this.sessionCtx.sessionState.setPartial({ session: t });
736
736
  }
737
737
  this.state.setPartial({ screen: "chat" });
738
- }, this.config = i, this.contactCtx = a, this.sessionCtx = c, this.resetChat = d, this.state = new y({
738
+ }, this.config = i, this.contactCtx = a, this.sessionCtx = l, this.resetChat = d, this.state = new y({
739
739
  screen: this.contactCtx.shouldCollectData() ? "welcome" : (s = this.config.router) != null && s.chatScreenOnly ? "chat" : "sessions"
740
740
  }), this.registerRoutingListener();
741
741
  }
742
742
  }
743
- class V {
743
+ class W {
744
744
  constructor({
745
745
  storage: i,
746
746
  config: a
747
747
  }) {
748
748
  this.KEYS = {
749
- contactToken: (c) => `opencx-widget:org-token-${c}:contact-token`,
750
- externalContactId: (c) => `opencx-widget:org-token-${c}:external-contact-id`
751
- }, this.setContactToken = async (c) => {
752
- await this.storage.set(this.KEYS.contactToken(this.config.token), c);
753
- }, this.getContactToken = async () => this.storage.get(this.KEYS.contactToken(this.config.token)), this.setExternalContactId = async (c) => {
754
- await this.storage.set(this.KEYS.externalContactId(this.config.token), c);
749
+ contactToken: (l) => `opencx-widget:org-token-${l}:contact-token`,
750
+ externalContactId: (l) => `opencx-widget:org-token-${l}:external-contact-id`
751
+ }, this.setContactToken = async (l) => {
752
+ await this.storage.set(this.KEYS.contactToken(this.config.token), l);
753
+ }, this.getContactToken = async () => this.storage.get(this.KEYS.contactToken(this.config.token)), this.setExternalContactId = async (l) => {
754
+ await this.storage.set(this.KEYS.externalContactId(this.config.token), l);
755
755
  }, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId(this.config.token)), this.storage = i, this.config = a;
756
756
  }
757
757
  }
758
- const b = class b {
758
+ const w = class w {
759
759
  constructor({
760
760
  config: i,
761
761
  storage: a,
762
- modes: c,
762
+ modes: l,
763
763
  org: d
764
764
  }) {
765
765
  if (this.modes = [], this.resetChat = () => {
766
766
  this.sessionCtx.reset(), this.messageCtx.reset();
767
- }, !b.pollingIntervalsSeconds)
767
+ }, !w.pollingIntervalsSeconds)
768
768
  throw Error(
769
769
  "Widget polling values are not defined, did you call WidgetCtx.initialize()"
770
770
  );
771
- this.config = i, this.org = d, this.api = new M({ config: i }), this.storageCtx = a ? new V({ storage: a, config: i }) : void 0, this.modes = c, this.contactCtx = new Y({
771
+ this.config = i, this.org = d, this.api = new M({ config: i }), this.storageCtx = a ? new W({ storage: a, config: i }) : void 0, this.modes = l, this.contactCtx = new V({
772
772
  api: this.api,
773
773
  config: this.config,
774
774
  storageCtx: this.storageCtx
775
- }), this.sessionCtx = new G({
775
+ }), this.sessionCtx = new $({
776
776
  config: this.config,
777
777
  api: this.api,
778
778
  contactCtx: this.contactCtx,
779
- sessionsPollingIntervalSeconds: b.pollingIntervalsSeconds.sessions
779
+ sessionsPollingIntervalSeconds: w.pollingIntervalsSeconds.sessions
780
780
  }), this.messageCtx = new K({
781
781
  config: this.config,
782
782
  api: this.api,
783
783
  sessionCtx: this.sessionCtx,
784
784
  contactCtx: this.contactCtx
785
- }), this.csatCtx = new $({
785
+ }), this.csatCtx = new Y({
786
786
  config: this.config,
787
787
  api: this.api,
788
788
  sessionCtx: this.sessionCtx,
@@ -792,8 +792,8 @@ const b = class b {
792
792
  config: this.config,
793
793
  sessionCtx: this.sessionCtx,
794
794
  messageCtx: this.messageCtx,
795
- sessionPollingIntervalSeconds: b.pollingIntervalsSeconds.session
796
- }), this.routerCtx = new W({
795
+ sessionPollingIntervalSeconds: w.pollingIntervalsSeconds.session
796
+ }), this.routerCtx = new G({
797
797
  config: this.config,
798
798
  contactCtx: this.contactCtx,
799
799
  sessionCtx: this.sessionCtx,
@@ -801,30 +801,30 @@ const b = class b {
801
801
  });
802
802
  }
803
803
  };
804
- b.pollingIntervalsSeconds = null, b.initialize = async ({
804
+ w.pollingIntervalsSeconds = null, w.initialize = async ({
805
805
  config: i,
806
806
  storage: a
807
807
  }) => {
808
808
  var d, s, e;
809
- const c = await new M({
809
+ const l = await new M({
810
810
  config: i
811
811
  }).getExternalWidgetConfig();
812
- if (!c.data)
812
+ if (!l.data)
813
813
  throw new Error("Failed to fetch widget config");
814
- return b.pollingIntervalsSeconds = {
815
- session: ((d = c.data) == null ? void 0 : d.sessionPollingIntervalSeconds) || 10,
816
- sessions: ((s = c.data) == null ? void 0 : s.sessionsPollingIntervalSeconds) || 60
817
- }, new b({
814
+ return w.pollingIntervalsSeconds = {
815
+ session: ((d = l.data) == null ? void 0 : d.sessionPollingIntervalSeconds) || 10,
816
+ sessions: ((s = l.data) == null ? void 0 : s.sessionsPollingIntervalSeconds) || 60
817
+ }, new w({
818
818
  config: i,
819
819
  storage: a,
820
- modes: ((e = c.data) == null ? void 0 : e.modes) || [],
820
+ modes: ((e = l.data) == null ? void 0 : e.modes) || [],
821
821
  org: {
822
- id: c.data.org.id,
823
- name: c.data.org.name
822
+ id: l.data.org.id,
823
+ name: l.data.org.name
824
824
  }
825
825
  });
826
826
  };
827
- let U = b;
827
+ let U = w;
828
828
  const J = {
829
829
  write_a_message_placeholder: "اكتب رسالة...",
830
830
  your_issue_has_been_resolved: "تم حل مشكلتك!",
@@ -842,6 +842,22 @@ const J = {
842
842
  back_to_conversations: "العودة إلى المحادثات",
843
843
  closed_conversations: "المحادثات المغلقة"
844
844
  }, X = {
845
+ write_a_message_placeholder: "Skriv en besked...",
846
+ your_issue_has_been_resolved: "Dit problem er løst!",
847
+ new_conversation: "Ny samtale",
848
+ welcome_screen_title: "Velkommen til vores support chat",
849
+ welcome_screen_description: "Vi er her for at hjælpe! Start en samtale, og vi vender tilbage til dig så hurtigt som muligt.",
850
+ your_name_placeholder: "Dit navn",
851
+ your_email_placeholder: "Din e-mailadresse",
852
+ start_chat_button: "Tal med support",
853
+ start_chat_button_loading: "Forbinder...",
854
+ i_need_more_help: "Jeg har brug for mere hjælp",
855
+ this_was_helpful: "Dette var nyttigt",
856
+ optional: "Valgfrit",
857
+ no_conversations_yet: "Ingen samtaler endnu",
858
+ back_to_conversations: "Tilbage til samtaler",
859
+ closed_conversations: "Lukkede samtaler"
860
+ }, Z = {
845
861
  write_a_message_placeholder: "Nachricht schreiben...",
846
862
  your_issue_has_been_resolved: "Ihr Problem wurde gelöst!",
847
863
  new_conversation: "Neue Konversation",
@@ -857,7 +873,7 @@ const J = {
857
873
  no_conversations_yet: "noch keine Gespräche",
858
874
  back_to_conversations: "Zurück zur Konversationen",
859
875
  closed_conversations: "Geschlossene Konversationen"
860
- }, Z = {
876
+ }, Q = {
861
877
  write_a_message_placeholder: "Write a message...",
862
878
  your_issue_has_been_resolved: "Your issue has been resolved!",
863
879
  new_conversation: "New conversation",
@@ -873,7 +889,7 @@ const J = {
873
889
  no_conversations_yet: "No conversations yet",
874
890
  back_to_conversations: "Back to conversations",
875
891
  closed_conversations: "Closed conversations"
876
- }, Q = {
892
+ }, ee = {
877
893
  write_a_message_placeholder: "Escribe un mensaje...",
878
894
  your_issue_has_been_resolved: "¡Tu problema fue resuelto!",
879
895
  new_conversation: "Nueva conversación",
@@ -889,7 +905,23 @@ const J = {
889
905
  no_conversations_yet: "Sin conversaciones aún",
890
906
  back_to_conversations: "Volver a conversaciones",
891
907
  closed_conversations: "Conversaciones cerradas"
892
- }, ee = {
908
+ }, te = {
909
+ write_a_message_placeholder: "Kirjoita viesti...",
910
+ your_issue_has_been_resolved: "Ongelmasi on ratkaistu!",
911
+ new_conversation: "Uusi keskustelu",
912
+ welcome_screen_title: "Tervetuloa tukichattiin",
913
+ welcome_screen_description: "Olemme täällä auttamassa! Aloita keskustelu ja palaamme sinulle mahdollisimman pian.",
914
+ your_name_placeholder: "Nimesi",
915
+ your_email_placeholder: "Sähköpostiosoitteesi",
916
+ start_chat_button: "Keskustele tuen kanssa",
917
+ start_chat_button_loading: "Yhdistetään...",
918
+ i_need_more_help: "Tarvitsen lisää apua",
919
+ this_was_helpful: "Tämä oli hyödyllistä",
920
+ optional: "Valinnainen",
921
+ no_conversations_yet: "Ei vielä keskusteluja",
922
+ back_to_conversations: "Takaisin keskusteluihin",
923
+ closed_conversations: "Suljetut keskustelut"
924
+ }, se = {
893
925
  write_a_message_placeholder: "Écrivez un message...",
894
926
  your_issue_has_been_resolved: "Votre problème a été résolu !",
895
927
  new_conversation: "Nouvelle conversation",
@@ -905,7 +937,23 @@ const J = {
905
937
  no_conversations_yet: "Aucune conversation pour le moment",
906
938
  back_to_conversations: "Retour aux conversations",
907
939
  closed_conversations: "Conversations fermées"
908
- }, te = {
940
+ }, ie = {
941
+ write_a_message_placeholder: "Scrivi un messaggio...",
942
+ your_issue_has_been_resolved: "Il tuo problema è stato risolto!",
943
+ new_conversation: "Nuova conversazione",
944
+ welcome_screen_title: "Benvenuto nella nostra chat di supporto",
945
+ welcome_screen_description: "Siamo qui per aiutarti! Inizia una conversazione e ti risponderemo il prima possibile.",
946
+ your_name_placeholder: "Il tuo nome",
947
+ your_email_placeholder: "Il tuo indirizzo email",
948
+ start_chat_button: "Parla con il supporto",
949
+ start_chat_button_loading: "Connessione in corso...",
950
+ i_need_more_help: "Ho bisogno di ulteriore aiuto",
951
+ this_was_helpful: "Questo è stato utile",
952
+ optional: "Opzionale",
953
+ no_conversations_yet: "Nessuna conversazione ancora",
954
+ back_to_conversations: "Torna alle conversazioni",
955
+ closed_conversations: "Conversazioni chiuse"
956
+ }, ne = {
909
957
  write_a_message_placeholder: "Schrijf een bericht...",
910
958
  your_issue_has_been_resolved: "Uw probleem is opgelost!",
911
959
  new_conversation: "Nieuw gesprek",
@@ -921,7 +969,23 @@ const J = {
921
969
  no_conversations_yet: "Nog geen gesprekken",
922
970
  back_to_conversations: "Terug naar gesprekken",
923
971
  closed_conversations: "Afgesloten gesprekken"
924
- }, se = {
972
+ }, ae = {
973
+ write_a_message_placeholder: "Skriv en melding...",
974
+ your_issue_has_been_resolved: "Problemet ditt er løst!",
975
+ new_conversation: "Ny samtale",
976
+ welcome_screen_title: "Velkommen til vår kundestøtte-chat",
977
+ welcome_screen_description: "Vi er her for å hjelpe! Start en samtale så kommer vi tilbake til deg så snart som mulig.",
978
+ your_name_placeholder: "Ditt navn",
979
+ your_email_placeholder: "Din e-postadresse",
980
+ start_chat_button: "Snakk med kundestøtte",
981
+ start_chat_button_loading: "Kobler til...",
982
+ i_need_more_help: "Jeg trenger mer hjelp",
983
+ this_was_helpful: "Dette var nyttig",
984
+ optional: "Valgfritt",
985
+ no_conversations_yet: "Ingen samtaler ennå",
986
+ back_to_conversations: "Tilbake til samtaler",
987
+ closed_conversations: "Lukkede samtaler"
988
+ }, oe = {
925
989
  write_a_message_placeholder: "Napisz wiadomość...",
926
990
  your_issue_has_been_resolved: "Twój problem został rozwiązany!",
927
991
  new_conversation: "Nowa rozmowa",
@@ -937,7 +1001,7 @@ const J = {
937
1001
  no_conversations_yet: "Jeszcze brak rozmów",
938
1002
  back_to_conversations: "Powrót do rozmów",
939
1003
  closed_conversations: "Zamknięte rozmowy"
940
- }, ie = {
1004
+ }, re = {
941
1005
  write_a_message_placeholder: "Escreva uma mensagem...",
942
1006
  your_issue_has_been_resolved: "Seu problema foi resolvido!",
943
1007
  new_conversation: "Nova conversa",
@@ -953,7 +1017,39 @@ const J = {
953
1017
  no_conversations_yet: "Nenhuma conversa ainda",
954
1018
  back_to_conversations: "Voltar para conversas",
955
1019
  closed_conversations: "Conversas fechadas"
956
- }, ne = {
1020
+ }, le = {
1021
+ write_a_message_placeholder: "Scrie un mesaj...",
1022
+ your_issue_has_been_resolved: "Problema ta a fost rezolvată!",
1023
+ new_conversation: "Conversație nouă",
1024
+ welcome_screen_title: "Bine ai venit la chat-ul nostru de suport",
1025
+ welcome_screen_description: "Suntem aici să te ajutăm! Începe o conversație și îți vom răspunde cât mai curând posibil.",
1026
+ your_name_placeholder: "Numele tău",
1027
+ your_email_placeholder: "Adresa ta de email",
1028
+ start_chat_button: "Vorbește cu suportul",
1029
+ start_chat_button_loading: "Se conectează...",
1030
+ i_need_more_help: "Am nevoie de mai mult ajutor",
1031
+ this_was_helpful: "Acest lucru a fost util",
1032
+ optional: "Opțional",
1033
+ no_conversations_yet: "Încă nu există conversații",
1034
+ back_to_conversations: "Înapoi la conversații",
1035
+ closed_conversations: "Conversații închise"
1036
+ }, ce = {
1037
+ write_a_message_placeholder: "Skriv ett meddelande...",
1038
+ your_issue_has_been_resolved: "Ditt problem har lösts!",
1039
+ new_conversation: "Ny konversation",
1040
+ welcome_screen_title: "Välkommen till vår supportchatt",
1041
+ welcome_screen_description: "Vi är här för att hjälpa! Starta en konversation så återkommer vi till dig så snart som möjligt.",
1042
+ your_name_placeholder: "Ditt namn",
1043
+ your_email_placeholder: "Din e-postadress",
1044
+ start_chat_button: "Prata med support",
1045
+ start_chat_button_loading: "Ansluter...",
1046
+ i_need_more_help: "Jag behöver mer hjälp",
1047
+ this_was_helpful: "Detta var användbart",
1048
+ optional: "Frivilligt",
1049
+ no_conversations_yet: "Inga konversationer ännu",
1050
+ back_to_conversations: "Tillbaka till konversationer",
1051
+ closed_conversations: "Stängda konversationer"
1052
+ }, he = {
957
1053
  write_a_message_placeholder: "Bir mesaj yazın...",
958
1054
  your_issue_has_been_resolved: "Sorununuz çözüldü!",
959
1055
  new_conversation: "Yeni konuşma",
@@ -969,29 +1065,35 @@ const J = {
969
1065
  no_conversations_yet: "Henüz konuşma yok",
970
1066
  back_to_conversations: "Konuşmalara geri dön",
971
1067
  closed_conversations: "Kapatılan konuşmalar"
972
- }, z = {
973
- en: Z,
1068
+ }, R = {
1069
+ en: Q,
974
1070
  ar: J,
975
- nl: te,
976
- fr: ee,
977
- de: X,
978
- pt: ie,
979
- es: Q,
980
- tr: ne,
981
- pl: se
982
- }, ae = Object.keys(z);
983
- function he(h) {
984
- return ae.includes(h);
1071
+ nl: ne,
1072
+ fr: se,
1073
+ de: Z,
1074
+ pt: re,
1075
+ es: ee,
1076
+ tr: he,
1077
+ pl: oe,
1078
+ fi: te,
1079
+ it: ie,
1080
+ no: ae,
1081
+ ro: le,
1082
+ da: X,
1083
+ sv: ce
1084
+ }, de = Object.keys(R);
1085
+ function pe(h) {
1086
+ return de.includes(h);
985
1087
  }
986
- function de(h, i, a) {
987
- var c;
988
- return ((c = a == null ? void 0 : a[i]) == null ? void 0 : c[h]) || z[i][h] || "";
1088
+ function fe(h, i, a) {
1089
+ var l;
1090
+ return ((l = a == null ? void 0 : a[i]) == null ? void 0 : l[h]) || R[i][h] || "";
989
1091
  }
990
1092
  export {
991
1093
  y as PrimitiveState,
992
1094
  U as WidgetCtx,
993
- de as getTranslation,
1095
+ fe as getTranslation,
994
1096
  B as isExhaustive,
995
- he as isSupportedLanguage
1097
+ pe as isSupportedLanguage
996
1098
  };
997
1099
  //# sourceMappingURL=index.js.map