@ada-cx/messaging-bridge 1.3.0 → 1.3.3

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.
@@ -1,482 +1,511 @@
1
- var L = 400, x = 5e3, B = class extends Error {
2
- constructor(a = "The bridge client was destroyed.") {
3
- super(a), this.name = "BridgeClientDestroyedError";
4
- }
5
- static is(a) {
6
- return a instanceof Error && a.name === "BridgeClientDestroyedError";
7
- }
1
+ //#region ../../shared/utils/src/browser-polyfills.ts
2
+ var e = Object.prototype.hasOwnProperty;
3
+ function t(e, t, n) {
4
+ Object.defineProperty(e, t, {
5
+ value: n,
6
+ configurable: !0,
7
+ writable: !0
8
+ });
9
+ }
10
+ Object.hasOwn || t(Object, "hasOwn", (t, n) => {
11
+ if (t == null) throw TypeError("ada browser-polyfills: Cannot convert undefined or null to object");
12
+ return e.call(Object(t), n);
13
+ });
14
+ function n(e) {
15
+ let t = Math.trunc(Number(this.length)) || 0, n = Math.trunc(Number(e)) || 0;
16
+ return n < 0 && (n += t), n < 0 || n >= t ? void 0 : this[n];
17
+ }
18
+ function r(e) {
19
+ let t = String(this), n = t.length, r = Math.trunc(Number(e)) || 0;
20
+ return r < 0 && (r += n), r < 0 || r >= n ? void 0 : t.charAt(r);
21
+ }
22
+ var i = [
23
+ globalThis.Int8Array,
24
+ globalThis.Uint8Array,
25
+ globalThis.Uint8ClampedArray,
26
+ globalThis.Int16Array,
27
+ globalThis.Uint16Array,
28
+ globalThis.Int32Array,
29
+ globalThis.Uint32Array,
30
+ globalThis.Float32Array,
31
+ globalThis.Float64Array,
32
+ globalThis.BigInt64Array,
33
+ globalThis.BigUint64Array
34
+ ].filter(Boolean);
35
+ Array.prototype.at || t(Array.prototype, "at", n), String.prototype.at || t(String.prototype, "at", r);
36
+ for (let e of i) {
37
+ let r = e.prototype;
38
+ r.at || t(r, "at", n);
39
+ }
40
+ //#endregion
41
+ //#region src/contract/operations.ts
42
+ var a = 400, o = 5e3, s = class extends Error {
43
+ constructor(e = "The bridge client was destroyed.") {
44
+ super(e), this.name = "BridgeClientDestroyedError";
45
+ }
46
+ static is(e) {
47
+ return e instanceof Error && e.name === "BridgeClientDestroyedError";
48
+ }
8
49
  };
9
- function R() {
10
- const a = typeof crypto > "u" ? void 0 : crypto;
11
- if (typeof a?.randomUUID == "function") return a.randomUUID();
12
- const s = new Uint8Array(16);
13
- if (typeof a?.getRandomValues == "function") a.getRandomValues(s);
14
- else for (let i = 0; i < s.length; i += 1) s[i] = Math.floor(Math.random() * 256);
15
- s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128;
16
- const t = Array.from(s, (i) => i.toString(16).padStart(2, "0"));
17
- return `${t.slice(0, 4).join("")}-${t.slice(4, 6).join("")}-${t.slice(6, 8).join("")}-${t.slice(8, 10).join("")}-${t.slice(10).join("")}`;
50
+ function c() {
51
+ let e = typeof crypto > "u" ? void 0 : crypto;
52
+ if (typeof e?.randomUUID == "function") return e.randomUUID();
53
+ let t = new Uint8Array(16);
54
+ if (typeof e?.getRandomValues == "function") e.getRandomValues(t);
55
+ else for (let e = 0; e < t.length; e += 1) t[e] = Math.floor(Math.random() * 256);
56
+ t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
57
+ let n = Array.from(t, (e) => e.toString(16).padStart(2, "0"));
58
+ return `${n.slice(0, 4).join("")}-${n.slice(4, 6).join("")}-${n.slice(6, 8).join("")}-${n.slice(8, 10).join("")}-${n.slice(10).join("")}`;
18
59
  }
19
- function T(a, s, t, i) {
20
- return new Promise((d, f) => {
21
- if (s.isDisposed()) {
22
- f(new B());
23
- return;
24
- }
25
- let m = !1, g = null, p = null;
26
- const S = (o) => {
27
- C({ error: o });
28
- }, C = (o) => {
29
- m || (m = !0, s.unregister(S), g?.(), p !== null && clearTimeout(p), "value" in o ? d(o.value) : f(o.error));
30
- }, q = () => {
31
- const o = t(a.getState());
32
- o && C(o);
33
- };
34
- q(), !m && (s.register(S), g = a.subscribe(q), i?.timeoutMs !== void 0 && (p = setTimeout(() => {
35
- C({ error: /* @__PURE__ */ new Error(`Bridge operation timed out after ${i.timeoutMs}ms.`) });
36
- }, i.timeoutMs)));
37
- });
60
+ function l(e, t, n, r) {
61
+ return new Promise((i, a) => {
62
+ if (t.isDisposed()) {
63
+ a(new s());
64
+ return;
65
+ }
66
+ let o = !1, c = null, l = null, u = (e) => {
67
+ d({ error: e });
68
+ }, d = (e) => {
69
+ o || (o = !0, t.unregister(u), c?.(), l !== null && clearTimeout(l), "value" in e ? i(e.value) : a(e.error));
70
+ }, f = () => {
71
+ let t = n(e.getState());
72
+ t && d(t);
73
+ };
74
+ f(), !o && (t.register(u), c = e.subscribe(f), r?.timeoutMs !== void 0 && (l = setTimeout(() => {
75
+ d({ error: /* @__PURE__ */ Error(`Bridge operation timed out after ${r.timeoutMs}ms.`) });
76
+ }, r.timeoutMs)));
77
+ });
38
78
  }
39
- function O(a) {
40
- function s(i, d, f) {
41
- const m = f?.equals ?? Object.is;
42
- let g = i(a.getState());
43
- return f?.emitInitial === !0 && d(g, void 0), a.subscribe(() => {
44
- const p = i(a.getState());
45
- if (m(p, g)) return;
46
- const S = g;
47
- g = p, d(p, S);
48
- });
49
- }
50
- function t(i, d, f) {
51
- return s((m) => m?.[i], d, f);
52
- }
53
- return {
54
- subscribeKey: t,
55
- select: s
56
- };
79
+ function u(e) {
80
+ function t(t, n, r) {
81
+ let i = r?.equals ?? Object.is, a = t(e.getState());
82
+ return r?.emitInitial === !0 && n(a, void 0), e.subscribe(() => {
83
+ let r = t(e.getState());
84
+ if (i(r, a)) return;
85
+ let o = a;
86
+ a = r, n(r, o);
87
+ });
88
+ }
89
+ function n(e, n, r) {
90
+ return t((t) => t?.[e], n, r);
91
+ }
92
+ return {
93
+ subscribeKey: n,
94
+ select: t
95
+ };
57
96
  }
58
- function A(a) {
59
- let s = !1;
60
- const t = {
61
- getState: () => a.getState(),
62
- subscribe: (e) => s ? () => {
63
- } : a.subscribe(e),
64
- sendEvent: (e, ...r) => {
65
- s || a.sendEvent(e, ...r);
66
- }
67
- }, i = /* @__PURE__ */ new Set(), d = {
68
- isDisposed: () => s,
69
- register: (e) => {
70
- i.add(e);
71
- },
72
- unregister: (e) => {
73
- i.delete(e);
74
- }
75
- };
76
- let f = "", m = "", g = null, p = null, S = null;
77
- function C() {
78
- f = "", m = "", g !== null && (clearTimeout(g), g = null);
79
- }
80
- function q() {
81
- if (S) return;
82
- let e = t.getState()?.["chat.conversationId"] ?? null;
83
- S = t.subscribe(() => {
84
- const r = t.getState()?.["chat.conversationId"] ?? null;
85
- r !== e && (e = r, C(), p = r);
86
- });
87
- }
88
- function o() {
89
- g === null && (g = setTimeout(() => {
90
- g = null, f > m && (m = f, t.sendEvent("chat.messages.read", {
91
- cursor: f,
92
- ...p ? { conversationId: p } : {}
93
- }));
94
- }, L));
95
- }
96
- let w = 0;
97
- const D = {
98
- sendMessage(e, r) {
99
- const n = typeof e == "string" ? e.trim() : "", h = r?.secret === !0, v = R();
100
- let y = null, b = null;
101
- if (n) {
102
- const l = t.getState();
103
- y = l?.["chat.error"] ?? null, b = l?.["chat.error.seq"] ?? null, t.sendEvent("chat.message.send", {
104
- body: n,
105
- messageType: h ? "secret" : "text",
106
- tempMessageUuid: v
107
- });
108
- }
109
- return {
110
- tempMessageUuid: v,
111
- settled(l) {
112
- return n ? h ? T(t, d, () => {
113
- }, l) : T(t, d, (u) => {
114
- const I = (u?.["chat.messages"] ?? []).find((M) => M.clientKey === v);
115
- if (I) return { value: I };
116
- const c = u?.["chat.error"] ?? null;
117
- if (u !== null && "chat.error.clientKey" in u)
118
- return c !== null && u["chat.error.clientKey"] === v ? { error: new Error(c) } : void 0;
119
- const E = u?.["chat.error.seq"];
120
- if (typeof E == "number") {
121
- if (b === null) {
122
- b = E;
123
- return;
124
- }
125
- return c !== null && E !== b ? { error: new Error(c) } : void 0;
126
- }
127
- if (c === null) {
128
- y = null;
129
- return;
130
- }
131
- if (c !== y) return { error: new Error(c) };
132
- }, l) : Promise.reject(/* @__PURE__ */ new Error("sendMessage requires a non-empty body."));
133
- }
134
- };
135
- },
136
- retryMessage(e) {
137
- t.sendEvent("chat.message.retry", { message: {
138
- id: e,
139
- type: "text"
140
- } });
141
- },
142
- canRetryMessage(e) {
143
- const r = t.getState();
144
- return e.type === "text" && e.isRetryable === !0 && r?.["zendesk.sdk.disconnected"] !== !0 && (e.conversationId == null || e.conversationId === (r?.["chat.conversationId"] ?? null));
145
- },
146
- selectQuickReply(e, r) {
147
- t.sendEvent("chat.quickReply.select", {
148
- label: e.label,
149
- target: e.target,
150
- buttonType: e.buttonType,
151
- ...e.value !== void 0 ? { value: e.value } : {},
152
- messageId: r
153
- });
154
- },
155
- selectOption(e, r) {
156
- t.sendEvent("chat.option.select", {
157
- optionId: e.id,
158
- optionLabel: e.label || e.id,
159
- messageId: r
160
- });
161
- },
162
- submitListSelection(e) {
163
- const r = t.getState()?.["conversation.stateData.listSelection"];
164
- r && t.sendEvent("chat.selectableList.submit", {
165
- selectedIds: e,
166
- dataId: r.dataId
167
- });
168
- },
169
- cancelListSelection(e) {
170
- const r = t.getState()?.["conversation.stateData.listSelection"];
171
- r?.cancelCaptureResponseId && t.sendEvent("listSelection.cancel", {
172
- cancelResponseId: r.cancelCaptureResponseId,
173
- cancelLabel: e ?? r.cancelCaptureLabel,
174
- dataId: r.dataId
175
- });
176
- },
177
- submitCapture(e) {
178
- const r = t.getState()?.["conversation.stateData.capture"];
179
- if (!r) return { settled: () => Promise.reject(/* @__PURE__ */ new Error("No capture field is active.")) };
180
- const n = r.dataId, h = R();
181
- t.sendEvent("capture.submit", {
182
- value: e,
183
- dataId: n,
184
- submitId: h
185
- });
186
- let v = !1;
187
- return { settled: (y) => T(t, d, (b) => {
188
- const l = b?.["conversation.stateData.capture"] ?? null;
189
- if (!l || l.dataId !== n) return { value: { ok: !0 } };
190
- const u = l.lastSubmitFailure;
191
- if (u && u.submitId === h) return { value: {
192
- ok: !1,
193
- message: u.message
194
- } };
195
- if (l.isSubmitting === !0) {
196
- v = !0;
197
- return;
198
- }
199
- if (v) return l.validationErrorMessage ? { value: {
200
- ok: !1,
201
- message: l.validationErrorMessage
202
- } } : { value: { ok: !0 } };
203
- }, y) };
204
- },
205
- cancelCapture(e) {
206
- const r = t.getState()?.["conversation.stateData.capture"];
207
- r?.cancelCaptureResponseId && t.sendEvent("capture.cancel", {
208
- cancelResponseId: r.cancelCaptureResponseId,
209
- cancelLabel: e ?? r.cancelCaptureLabel,
210
- dataId: r.dataId
211
- });
212
- },
213
- addReaction(e, r) {
214
- t.sendEvent("chat.message.reaction.add", {
215
- messageId: e,
216
- reaction: r
217
- });
218
- },
219
- reportLinkClick(e, r) {
220
- t.sendEvent("chat.link.click", {
221
- messageId: e,
222
- ...r?.navigateInHost !== void 0 ? { navigateInHost: r.navigateInHost } : {}
223
- });
224
- },
225
- markRead(e, r) {
226
- if (typeof e != "string" || e === "") return;
227
- q();
228
- const n = r?.conversationId ?? t.getState()?.["chat.conversationId"] ?? null;
229
- n !== p && (C(), p = n), e > f && (f = e, o());
230
- },
231
- loadOlderMessages() {
232
- const e = t.getState();
233
- e?.["chat.canLoadMore"] !== !0 || e["chat.loadingPreviousMessages"] === !0 || t.sendEvent("chat.logs.loadMore");
234
- },
235
- onHistoryLoaded(e) {
236
- let r = t.getState()?.["chat.recentMessagesLoadSeq"] ?? 0;
237
- return t.subscribe(() => {
238
- const n = t.getState()?.["chat.recentMessagesLoadSeq"] ?? 0;
239
- n > r ? (r = n, e(n)) : n < r && (r = n);
240
- });
241
- },
242
- submitCsat(e, r) {
243
- const { surveyType: n, partial: h, conversationId: v } = r, y = t.getState()?.["csat.submitSuccess.seq"] ?? 0;
244
- let b = t.getState()?.["csat.submitError"] ?? null, l = t.getState()?.["csat.submitError.seq"] ?? null;
245
- t.sendEvent("csat.submit", {
246
- data: e,
247
- surveyType: n,
248
- ...h !== void 0 ? { partial: h } : {},
249
- ...v != null ? { conversationId: v } : {}
250
- });
251
- const u = (I) => v == null || (I ?? null) === v;
252
- return { settled: (I) => T(t, d, (c) => {
253
- if ((c?.["csat.submitSuccess.seq"] ?? 0) > y && c?.["csat.submitSuccess.surveyType"] === n && u(c?.["csat.submitSuccess.conversationId"])) return { value: { ok: !0 } };
254
- const E = c?.["csat.submitError"] ?? null, M = c?.["csat.submitError.seq"];
255
- if (typeof M == "number") {
256
- if (l === null) {
257
- l = M;
258
- return;
259
- }
260
- return E !== null && M !== l && c?.["csat.submitErrorSurveyType"] === n && u(c?.["csat.submitErrorConversationId"]) ? { value: {
261
- ok: !1,
262
- message: E
263
- } } : void 0;
264
- }
265
- if (E === null) {
266
- b = null;
267
- return;
268
- }
269
- if (E !== b && c?.["csat.submitErrorSurveyType"] === n && u(c?.["csat.submitErrorConversationId"])) return { value: {
270
- ok: !1,
271
- message: E
272
- } };
273
- }, I) };
274
- },
275
- trackCsatShown(e, r) {
276
- t.sendEvent("csat.shown", {
277
- surveyType: e,
278
- ...r != null ? { conversationId: r } : {}
279
- });
280
- },
281
- checkEndChatEligibility(e) {
282
- const r = t.getState()?.["csat.endChatEligibility.seq"] ?? 0;
283
- return t.sendEvent("csat.checkEndChatEligibility"), T(t, d, (n) => {
284
- if (!((n?.["csat.endChatEligibility.seq"] ?? 0) <= r))
285
- return { value: {
286
- eligible: n?.["csat.endChatEligible"] ?? null,
287
- surveyTarget: n?.["csat.endChatSurveyTarget"] ?? null
288
- } };
289
- }, e);
290
- },
291
- skipCsatAndEndChat() {
292
- t.sendEvent("endChat.skipCsat");
293
- },
294
- endLiveChat() {
295
- t.sendEvent("endChat.endLiveChat");
296
- },
297
- startNewConversation(e) {
298
- if (t.getState()?.["app.conversationStartPending"] === !0) return !1;
299
- const r = Date.now();
300
- return r < w ? !1 : (w = r + (e?.cooldownMs ?? x), t.sendEvent("app.startNewConversation"), !0);
301
- },
302
- resetApp() {
303
- t.sendEvent("app.reset");
304
- },
305
- notifyComposerChanged(e) {
306
- e?.secret === !0 || t.getState()?.["ui.secretMessage.isOpen"] === !0 || t.sendEvent("ui.composer.textChanged");
307
- },
308
- toggleSecretMessage(e) {
309
- t.sendEvent("ui.secretMessage.toggle", { open: e });
310
- },
311
- startFileUpload(e) {
312
- const r = R();
313
- return t.sendEvent("file.upload.start", {
314
- file: e,
315
- uploadId: r
316
- }), {
317
- uploadId: r,
318
- retry() {
319
- t.sendEvent("file.upload.retry", {
320
- file: e,
321
- uploadId: r
322
- });
323
- },
324
- dismissError() {
325
- t.sendEvent("file.upload.errorDismiss");
326
- }
327
- };
328
- },
329
- setLanguage(e) {
330
- t.sendEvent("settings.language.change", { language: e });
331
- },
332
- emailTranscript(e, r) {
333
- const n = typeof e == "string" ? e.trim() : "";
334
- return n ? (t.sendEvent("settings.transcript.email.send", { email: n }), k("transcript.email.status", r, n)) : Promise.reject(/* @__PURE__ */ new Error("emailTranscript requires a non-empty email."));
335
- },
336
- downloadTranscript(e) {
337
- return t.sendEvent("settings.transcript.download.request"), k("transcript.download.status", e);
338
- },
339
- setAlertSound(e) {
340
- t.sendEvent("settings.alertSound.toggle", { enabled: e });
341
- },
342
- requestNotificationPermission() {
343
- t.sendEvent("settings.notifications.requestPermission");
344
- },
345
- setTheme(e) {
346
- t.sendEvent("appearance.setTheme", { theme: e });
347
- },
348
- setTextSize(e) {
349
- t.sendEvent("appearance.setTextSize", { textSize: e });
350
- },
351
- close() {
352
- t.sendEvent("ui.closeButton.click");
353
- },
354
- minimize() {
355
- t.sendEvent("ui.minimizeButton.click");
356
- },
357
- dismissToast() {
358
- t.sendEvent("ui.toast.dismiss");
359
- },
360
- dismissError() {
361
- t.sendEvent("chat.error.dismiss");
362
- },
363
- setHostViewportExpanded(e) {
364
- t.sendEvent("ui.hostViewport.set", { expanded: e });
365
- },
366
- retryAfterOutage() {
367
- t.sendEvent("outage.retry");
368
- },
369
- reportAppError(e, r) {
370
- const n = e instanceof Error ? e : null;
371
- t.sendEvent("app.error.report", {
372
- message: n?.message ?? String(e),
373
- stack: n?.stack ?? "",
374
- componentStack: r ?? ""
375
- });
376
- }
377
- };
378
- function k(e, r, n) {
379
- const h = `${e}.seq`;
380
- let v = t.getState()?.[e] ?? "idle", y = t.getState()?.[h] ?? null, b = t.getState()?.["transcript.email.conflict.seq"] ?? null;
381
- return T(t, d, (l) => {
382
- if (n !== void 0) {
383
- const E = l?.["transcript.email.conflict.seq"];
384
- if (typeof E == "number") {
385
- if (b === null) b = E;
386
- else if (E !== b && l?.["transcript.email.conflict.email"] === n) return { error: /* @__PURE__ */ new Error("emailTranscript was rejected: a request for a different address is already in flight. The in-flight email still completes with its own outcome.") };
387
- }
388
- }
389
- const u = l?.[e] ?? "idle", I = l?.[h];
390
- if (typeof I == "number") {
391
- if (y === null) {
392
- y = I;
393
- return;
394
- }
395
- return I === y ? void 0 : u === "success" ? { value: void 0 } : u === "error" ? { error: /* @__PURE__ */ new Error(`${e} reported an error.`) } : void 0;
396
- }
397
- const c = v;
398
- if (v = u, c === "pending") {
399
- if (u === "success") return { value: void 0 };
400
- if (u === "error") return { error: /* @__PURE__ */ new Error(`${e} reported an error.`) };
401
- }
402
- }, r);
403
- }
404
- return {
405
- operations: D,
406
- dispose() {
407
- if (!s) {
408
- s = !0, C(), S?.(), S = null;
409
- for (const e of [...i]) e(new B());
410
- i.clear();
411
- }
412
- }
413
- };
97
+ function d(e) {
98
+ let t = !1, n = {
99
+ getState: () => e.getState(),
100
+ subscribe: (n) => t ? () => {} : e.subscribe(n),
101
+ sendEvent: (n, ...r) => {
102
+ t || e.sendEvent(n, ...r);
103
+ }
104
+ }, r = /* @__PURE__ */ new Set(), i = {
105
+ isDisposed: () => t,
106
+ register: (e) => {
107
+ r.add(e);
108
+ },
109
+ unregister: (e) => {
110
+ r.delete(e);
111
+ }
112
+ }, u = "", d = "", f = null, p = null, m = null;
113
+ function h() {
114
+ u = "", d = "", f !== null && (clearTimeout(f), f = null);
115
+ }
116
+ function g() {
117
+ if (m) return;
118
+ let e = n.getState()?.["chat.conversationId"] ?? null;
119
+ m = n.subscribe(() => {
120
+ let t = n.getState()?.["chat.conversationId"] ?? null;
121
+ t !== e && (e = t, h(), p = t);
122
+ });
123
+ }
124
+ function _() {
125
+ f === null && (f = setTimeout(() => {
126
+ f = null, u > d && (d = u, n.sendEvent("chat.messages.read", {
127
+ cursor: u,
128
+ ...p ? { conversationId: p } : {}
129
+ }));
130
+ }, a));
131
+ }
132
+ let v = 0, y = {
133
+ sendMessage(e, t) {
134
+ let r = typeof e == "string" ? e.trim() : "", a = t?.secret === !0, o = c(), s = null, u = null;
135
+ if (r) {
136
+ let e = n.getState();
137
+ s = e?.["chat.error"] ?? null, u = e?.["chat.error.seq"] ?? null, n.sendEvent("chat.message.send", {
138
+ body: r,
139
+ messageType: a ? "secret" : "text",
140
+ tempMessageUuid: o
141
+ });
142
+ }
143
+ return {
144
+ tempMessageUuid: o,
145
+ settled(e) {
146
+ return r ? a ? l(n, i, () => void 0, e) : l(n, i, (e) => {
147
+ let t = (e?.["chat.messages"] ?? []).find((e) => e.clientKey === o);
148
+ if (t) return { value: t };
149
+ let n = e?.["chat.error"] ?? null;
150
+ if (e !== null && "chat.error.clientKey" in e) return n !== null && e["chat.error.clientKey"] === o ? { error: Error(n) } : void 0;
151
+ let r = e?.["chat.error.seq"];
152
+ if (typeof r == "number") {
153
+ if (u === null) {
154
+ u = r;
155
+ return;
156
+ }
157
+ return n !== null && r !== u ? { error: Error(n) } : void 0;
158
+ }
159
+ if (n === null) {
160
+ s = null;
161
+ return;
162
+ }
163
+ if (n !== s) return { error: Error(n) };
164
+ }, e) : Promise.reject(/* @__PURE__ */ Error("sendMessage requires a non-empty body."));
165
+ }
166
+ };
167
+ },
168
+ retryMessage(e) {
169
+ n.sendEvent("chat.message.retry", { message: {
170
+ id: e,
171
+ type: "text"
172
+ } });
173
+ },
174
+ canRetryMessage(e) {
175
+ let t = n.getState();
176
+ return e.type === "text" && e.isRetryable === !0 && t?.["zendesk.sdk.disconnected"] !== !0 && (e.conversationId == null || e.conversationId === (t?.["chat.conversationId"] ?? null));
177
+ },
178
+ selectQuickReply(e, t) {
179
+ n.sendEvent("chat.quickReply.select", {
180
+ label: e.label,
181
+ target: e.target,
182
+ buttonType: e.buttonType,
183
+ ...e.value === void 0 ? {} : { value: e.value },
184
+ messageId: t
185
+ });
186
+ },
187
+ selectOption(e, t) {
188
+ n.sendEvent("chat.option.select", {
189
+ optionId: e.id,
190
+ optionLabel: e.label || e.id,
191
+ messageId: t
192
+ });
193
+ },
194
+ submitListSelection(e) {
195
+ let t = n.getState()?.["conversation.stateData.listSelection"];
196
+ t && n.sendEvent("chat.selectableList.submit", {
197
+ selectedIds: e,
198
+ dataId: t.dataId
199
+ });
200
+ },
201
+ cancelListSelection(e) {
202
+ let t = n.getState()?.["conversation.stateData.listSelection"];
203
+ t?.cancelCaptureResponseId && n.sendEvent("listSelection.cancel", {
204
+ cancelResponseId: t.cancelCaptureResponseId,
205
+ cancelLabel: e ?? t.cancelCaptureLabel,
206
+ dataId: t.dataId
207
+ });
208
+ },
209
+ submitCapture(e) {
210
+ let t = n.getState()?.["conversation.stateData.capture"];
211
+ if (!t) return { settled: () => Promise.reject(/* @__PURE__ */ Error("No capture field is active.")) };
212
+ let r = t.dataId, a = c();
213
+ n.sendEvent("capture.submit", {
214
+ value: e,
215
+ dataId: r,
216
+ submitId: a
217
+ });
218
+ let o = !1;
219
+ return { settled: (e) => l(n, i, (e) => {
220
+ let t = e?.["conversation.stateData.capture"] ?? null;
221
+ if (!t || t.dataId !== r) return { value: { ok: !0 } };
222
+ let n = t.lastSubmitFailure;
223
+ if (n && n.submitId === a) return { value: {
224
+ ok: !1,
225
+ message: n.message
226
+ } };
227
+ if (t.isSubmitting === !0) {
228
+ o = !0;
229
+ return;
230
+ }
231
+ if (o) return t.validationErrorMessage ? { value: {
232
+ ok: !1,
233
+ message: t.validationErrorMessage
234
+ } } : { value: { ok: !0 } };
235
+ }, e) };
236
+ },
237
+ cancelCapture(e) {
238
+ let t = n.getState()?.["conversation.stateData.capture"];
239
+ t?.cancelCaptureResponseId && n.sendEvent("capture.cancel", {
240
+ cancelResponseId: t.cancelCaptureResponseId,
241
+ cancelLabel: e ?? t.cancelCaptureLabel,
242
+ dataId: t.dataId
243
+ });
244
+ },
245
+ addReaction(e, t) {
246
+ n.sendEvent("chat.message.reaction.add", {
247
+ messageId: e,
248
+ reaction: t
249
+ });
250
+ },
251
+ reportLinkClick(e, t) {
252
+ n.sendEvent("chat.link.click", {
253
+ messageId: e,
254
+ ...t?.navigateInHost === void 0 ? {} : { navigateInHost: t.navigateInHost }
255
+ });
256
+ },
257
+ markRead(e, t) {
258
+ if (typeof e != "string" || e === "") return;
259
+ g();
260
+ let r = t?.conversationId ?? n.getState()?.["chat.conversationId"] ?? null;
261
+ r !== p && (h(), p = r), e > u && (u = e, _());
262
+ },
263
+ loadOlderMessages() {
264
+ let e = n.getState();
265
+ e?.["chat.canLoadMore"] !== !0 || e["chat.loadingPreviousMessages"] === !0 || n.sendEvent("chat.logs.loadMore");
266
+ },
267
+ onHistoryLoaded(e) {
268
+ let t = n.getState()?.["chat.recentMessagesLoadSeq"] ?? 0;
269
+ return n.subscribe(() => {
270
+ let r = n.getState()?.["chat.recentMessagesLoadSeq"] ?? 0;
271
+ r > t ? (t = r, e(r)) : r < t && (t = r);
272
+ });
273
+ },
274
+ submitCsat(e, t) {
275
+ let { surveyType: r, partial: a, conversationId: o } = t, s = n.getState()?.["csat.submitSuccess.seq"] ?? 0, c = n.getState()?.["csat.submitError"] ?? null, u = n.getState()?.["csat.submitError.seq"] ?? null;
276
+ n.sendEvent("csat.submit", {
277
+ data: e,
278
+ surveyType: r,
279
+ ...a === void 0 ? {} : { partial: a },
280
+ ...o == null ? {} : { conversationId: o }
281
+ });
282
+ let d = (e) => o == null || (e ?? null) === o;
283
+ return { settled: (e) => l(n, i, (e) => {
284
+ if ((e?.["csat.submitSuccess.seq"] ?? 0) > s && e?.["csat.submitSuccess.surveyType"] === r && d(e?.["csat.submitSuccess.conversationId"])) return { value: { ok: !0 } };
285
+ let t = e?.["csat.submitError"] ?? null, n = e?.["csat.submitError.seq"];
286
+ if (typeof n == "number") {
287
+ if (u === null) {
288
+ u = n;
289
+ return;
290
+ }
291
+ return t !== null && n !== u && e?.["csat.submitErrorSurveyType"] === r && d(e?.["csat.submitErrorConversationId"]) ? { value: {
292
+ ok: !1,
293
+ message: t
294
+ } } : void 0;
295
+ }
296
+ if (t === null) {
297
+ c = null;
298
+ return;
299
+ }
300
+ if (t !== c && e?.["csat.submitErrorSurveyType"] === r && d(e?.["csat.submitErrorConversationId"])) return { value: {
301
+ ok: !1,
302
+ message: t
303
+ } };
304
+ }, e) };
305
+ },
306
+ trackCsatShown(e, t) {
307
+ n.sendEvent("csat.shown", {
308
+ surveyType: e,
309
+ ...t == null ? {} : { conversationId: t }
310
+ });
311
+ },
312
+ checkEndChatEligibility(e) {
313
+ let t = n.getState()?.["csat.endChatEligibility.seq"] ?? 0;
314
+ return n.sendEvent("csat.checkEndChatEligibility"), l(n, i, (e) => {
315
+ if (!((e?.["csat.endChatEligibility.seq"] ?? 0) <= t)) return { value: {
316
+ eligible: e?.["csat.endChatEligible"] ?? null,
317
+ surveyTarget: e?.["csat.endChatSurveyTarget"] ?? null
318
+ } };
319
+ }, e);
320
+ },
321
+ skipCsatAndEndChat() {
322
+ n.sendEvent("endChat.skipCsat");
323
+ },
324
+ endLiveChat() {
325
+ n.sendEvent("endChat.endLiveChat");
326
+ },
327
+ startNewConversation(e) {
328
+ if (n.getState()?.["app.conversationStartPending"] === !0) return !1;
329
+ let t = Date.now();
330
+ return t < v ? !1 : (v = t + (e?.cooldownMs ?? o), n.sendEvent("app.startNewConversation"), !0);
331
+ },
332
+ resetApp() {
333
+ n.sendEvent("app.reset");
334
+ },
335
+ notifyComposerChanged(e) {
336
+ e?.secret === !0 || n.getState()?.["ui.secretMessage.isOpen"] === !0 || n.sendEvent("ui.composer.textChanged");
337
+ },
338
+ toggleSecretMessage(e) {
339
+ n.sendEvent("ui.secretMessage.toggle", { open: e });
340
+ },
341
+ startFileUpload(e) {
342
+ let t = c();
343
+ return n.sendEvent("file.upload.start", {
344
+ file: e,
345
+ uploadId: t
346
+ }), {
347
+ uploadId: t,
348
+ retry() {
349
+ n.sendEvent("file.upload.retry", {
350
+ file: e,
351
+ uploadId: t
352
+ });
353
+ },
354
+ dismissError() {
355
+ n.sendEvent("file.upload.errorDismiss");
356
+ }
357
+ };
358
+ },
359
+ setLanguage(e) {
360
+ n.sendEvent("settings.language.change", { language: e });
361
+ },
362
+ emailTranscript(e, t) {
363
+ let r = typeof e == "string" ? e.trim() : "";
364
+ return r ? (n.sendEvent("settings.transcript.email.send", { email: r }), b("transcript.email.status", t, r)) : Promise.reject(/* @__PURE__ */ Error("emailTranscript requires a non-empty email."));
365
+ },
366
+ downloadTranscript(e) {
367
+ return n.sendEvent("settings.transcript.download.request"), b("transcript.download.status", e);
368
+ },
369
+ setAlertSound(e) {
370
+ n.sendEvent("settings.alertSound.toggle", { enabled: e });
371
+ },
372
+ requestNotificationPermission() {
373
+ n.sendEvent("settings.notifications.requestPermission");
374
+ },
375
+ setTheme(e) {
376
+ n.sendEvent("appearance.setTheme", { theme: e });
377
+ },
378
+ setTextSize(e) {
379
+ n.sendEvent("appearance.setTextSize", { textSize: e });
380
+ },
381
+ close() {
382
+ n.sendEvent("ui.closeButton.click");
383
+ },
384
+ minimize() {
385
+ n.sendEvent("ui.minimizeButton.click");
386
+ },
387
+ dismissToast() {
388
+ n.sendEvent("ui.toast.dismiss");
389
+ },
390
+ dismissError() {
391
+ n.sendEvent("chat.error.dismiss");
392
+ },
393
+ setHostViewportExpanded(e) {
394
+ n.sendEvent("ui.hostViewport.set", { expanded: e });
395
+ },
396
+ retryAfterOutage() {
397
+ n.sendEvent("outage.retry");
398
+ },
399
+ reportAppError(e, t) {
400
+ let r = e instanceof Error ? e : null;
401
+ n.sendEvent("app.error.report", {
402
+ message: r?.message ?? String(e),
403
+ stack: r?.stack ?? "",
404
+ componentStack: t ?? ""
405
+ });
406
+ }
407
+ };
408
+ function b(e, t, r) {
409
+ let a = `${e}.seq`, o = n.getState()?.[e] ?? "idle", s = n.getState()?.[a] ?? null, c = n.getState()?.["transcript.email.conflict.seq"] ?? null;
410
+ return l(n, i, (t) => {
411
+ if (r !== void 0) {
412
+ let e = t?.["transcript.email.conflict.seq"];
413
+ if (typeof e == "number") {
414
+ if (c === null) c = e;
415
+ else if (e !== c && t?.["transcript.email.conflict.email"] === r) return { error: /* @__PURE__ */ Error("emailTranscript was rejected: a request for a different address is already in flight. The in-flight email still completes with its own outcome.") };
416
+ }
417
+ }
418
+ let n = t?.[e] ?? "idle", i = t?.[a];
419
+ if (typeof i == "number") {
420
+ if (s === null) {
421
+ s = i;
422
+ return;
423
+ }
424
+ return i === s ? void 0 : n === "success" ? { value: void 0 } : n === "error" ? { error: /* @__PURE__ */ Error(`${e} reported an error.`) } : void 0;
425
+ }
426
+ let l = o;
427
+ if (o = n, l === "pending") {
428
+ if (n === "success") return { value: void 0 };
429
+ if (n === "error") return { error: /* @__PURE__ */ Error(`${e} reported an error.`) };
430
+ }
431
+ }, t);
432
+ }
433
+ return {
434
+ operations: y,
435
+ dispose() {
436
+ if (!t) {
437
+ t = !0, h(), m?.(), m = null;
438
+ for (let e of [...r]) e(new s());
439
+ r.clear();
440
+ }
441
+ }
442
+ };
414
443
  }
415
- function U(a = null) {
416
- let s = a, t = !1;
417
- const i = /* @__PURE__ */ new Set(), d = [];
418
- function f() {
419
- for (const o of [...i]) try {
420
- o();
421
- } catch (w) {
422
- console.error("[AdaMessaging] Bridge subscriber threw:", w);
423
- }
424
- }
425
- function m() {
426
- return s;
427
- }
428
- function g(o) {
429
- return i.add(o), () => {
430
- i.delete(o);
431
- };
432
- }
433
- function p(o, ...w) {
434
- t || d.push({
435
- event: o,
436
- payload: w[0]
437
- });
438
- }
439
- const S = {
440
- getState: m,
441
- subscribe: g,
442
- sendEvent: p
443
- }, C = O(S), q = A(S);
444
- return {
445
- getState: m,
446
- subscribe: g,
447
- sendEvent: p,
448
- subscribeKey: C.subscribeKey,
449
- select: C.select,
450
- operations: q.operations,
451
- destroy() {
452
- t = !0, q.dispose(), s = null, i.clear();
453
- },
454
- setState(o) {
455
- s = o, f();
456
- },
457
- updateState(o) {
458
- s = {
459
- "chat.error.clientKey": null,
460
- ...s ?? {},
461
- ...o
462
- }, f();
463
- },
464
- get sentEvents() {
465
- return [...d];
466
- },
467
- clearSentEvents() {
468
- d.length = 0;
469
- },
470
- get subscriberCount() {
471
- return i.size;
472
- },
473
- get destroyed() {
474
- return t;
475
- }
476
- };
444
+ //#endregion
445
+ //#region src/npm/testing.ts
446
+ function f(e = null) {
447
+ let t = e, n = !1, r = /* @__PURE__ */ new Set(), i = [];
448
+ function a() {
449
+ for (let e of [...r]) try {
450
+ e();
451
+ } catch (e) {
452
+ console.error("[AdaMessaging] Bridge subscriber threw:", e);
453
+ }
454
+ }
455
+ function o() {
456
+ return t;
457
+ }
458
+ function s(e) {
459
+ return r.add(e), () => {
460
+ r.delete(e);
461
+ };
462
+ }
463
+ function c(e, ...t) {
464
+ n || i.push({
465
+ event: e,
466
+ payload: t[0]
467
+ });
468
+ }
469
+ let l = {
470
+ getState: o,
471
+ subscribe: s,
472
+ sendEvent: c
473
+ }, f = u(l), p = d(l);
474
+ return {
475
+ getState: o,
476
+ subscribe: s,
477
+ sendEvent: c,
478
+ subscribeKey: f.subscribeKey,
479
+ select: f.select,
480
+ operations: p.operations,
481
+ destroy() {
482
+ n = !0, p.dispose(), t = null, r.clear();
483
+ },
484
+ setState(e) {
485
+ t = e, a();
486
+ },
487
+ updateState(e) {
488
+ t = {
489
+ "chat.error.clientKey": null,
490
+ ...t ?? {},
491
+ ...e
492
+ }, a();
493
+ },
494
+ get sentEvents() {
495
+ return [...i];
496
+ },
497
+ clearSentEvents() {
498
+ i.length = 0;
499
+ },
500
+ get subscriberCount() {
501
+ return r.size;
502
+ },
503
+ get destroyed() {
504
+ return n;
505
+ }
506
+ };
477
507
  }
478
- export {
479
- U as createMockBridgeClient
480
- };
508
+ //#endregion
509
+ export { f as createMockBridgeClient };
481
510
 
482
511
  //# sourceMappingURL=testing.js.map