@mptransformation/omisdk 0.1.1

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.
@@ -0,0 +1,786 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ var AppEventType = /* @__PURE__ */ ((AppEventType2) => {
5
+ AppEventType2["READY"] = "ready";
6
+ AppEventType2["DISPLAY_CHANGED"] = "display_changed";
7
+ AppEventType2["BUBBLE_HIDDEN"] = "bubble_hidden";
8
+ AppEventType2["BUBBLE_SHOWN"] = "bubble_shown";
9
+ AppEventType2["LOGGED_IN"] = "logged_in";
10
+ AppEventType2["LOGGED_OUT"] = "logged_out";
11
+ AppEventType2["TOKEN_EXPIRED"] = "token_expired";
12
+ AppEventType2["ERROR"] = "error";
13
+ return AppEventType2;
14
+ })(AppEventType || {});
15
+ function createElement(tag, attributes = {}, children = []) {
16
+ const element = document.createElement(tag);
17
+ Object.entries(attributes).forEach(([key, value]) => {
18
+ element.setAttribute(key, value);
19
+ });
20
+ children.forEach((child) => {
21
+ if (typeof child === "string") {
22
+ element.appendChild(document.createTextNode(child));
23
+ } else {
24
+ element.appendChild(child);
25
+ }
26
+ });
27
+ return element;
28
+ }
29
+ function getElementById(id) {
30
+ return document.getElementById(id);
31
+ }
32
+ function createStyleElement(css, id) {
33
+ const style = document.createElement("style");
34
+ style.textContent = css;
35
+ if (id) {
36
+ style.id = id;
37
+ }
38
+ return style;
39
+ }
40
+ function addStyleToDocument(css, id) {
41
+ const style = createStyleElement(css, id);
42
+ document.head.appendChild(style);
43
+ return style;
44
+ }
45
+ function removeElement(element) {
46
+ if (element && element.parentNode) {
47
+ element.parentNode.removeChild(element);
48
+ }
49
+ }
50
+ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
51
+ LogLevel2["DEBUG"] = "debug";
52
+ LogLevel2["INFO"] = "info";
53
+ LogLevel2["WARN"] = "warn";
54
+ LogLevel2["ERROR"] = "error";
55
+ return LogLevel2;
56
+ })(LogLevel || {});
57
+ const DEFAULT_CONFIG = {
58
+ enabled: false,
59
+ level: "info",
60
+ prefix: "[OmiSDK]"
61
+ };
62
+ class Logger {
63
+ /**
64
+ * Creates a new Logger instance
65
+ * @param config Logger configuration
66
+ */
67
+ constructor(config = {}) {
68
+ __publicField(this, "config");
69
+ this.config = { ...DEFAULT_CONFIG, ...config };
70
+ }
71
+ /**
72
+ * Updates the logger configuration
73
+ * @param config New configuration
74
+ */
75
+ updateConfig(config) {
76
+ this.config = { ...this.config, ...config };
77
+ }
78
+ /**
79
+ * Logs a debug message
80
+ * @param message Message to log
81
+ * @param args Additional arguments
82
+ */
83
+ debug(message, ...args) {
84
+ this.log("debug", message, ...args);
85
+ }
86
+ /**
87
+ * Logs an info message
88
+ * @param message Message to log
89
+ * @param args Additional arguments
90
+ */
91
+ info(message, ...args) {
92
+ this.log("info", message, ...args);
93
+ }
94
+ /**
95
+ * Logs a warning message
96
+ * @param message Message to log
97
+ * @param args Additional arguments
98
+ */
99
+ warn(message, ...args) {
100
+ this.log("warn", message, ...args);
101
+ }
102
+ /**
103
+ * Logs an error message
104
+ * @param message Message to log
105
+ * @param args Additional arguments
106
+ */
107
+ error(message, ...args) {
108
+ this.log("error", message, ...args);
109
+ }
110
+ /**
111
+ * Internal log method
112
+ * @param level Log level
113
+ * @param message Message to log
114
+ * @param args Additional arguments
115
+ */
116
+ log(level, message, ...args) {
117
+ if (!this.config.enabled) return;
118
+ const logLevels = Object.values(LogLevel);
119
+ const configLevelIndex = logLevels.indexOf(this.config.level);
120
+ const messageLevelIndex = logLevels.indexOf(level);
121
+ if (messageLevelIndex < configLevelIndex) return;
122
+ const formattedMessage = `${this.config.prefix} ${message}`;
123
+ switch (level) {
124
+ case "debug":
125
+ console.debug(formattedMessage, ...args);
126
+ break;
127
+ case "info":
128
+ console.info(formattedMessage, ...args);
129
+ break;
130
+ case "warn":
131
+ console.warn(formattedMessage, ...args);
132
+ break;
133
+ case "error":
134
+ console.error(formattedMessage, ...args);
135
+ break;
136
+ }
137
+ }
138
+ }
139
+ const DEFAULT_THEME = {
140
+ primaryColor: "#3498db",
141
+ secondaryColor: "#2ecc71",
142
+ textColor: "#333333",
143
+ backgroundColor: "#ffffff",
144
+ fontFamily: "Arial, sans-serif",
145
+ borderRadius: "4px",
146
+ customClasses: {}
147
+ };
148
+ function generateThemeCSS(theme, namespace) {
149
+ const mergedTheme = { ...DEFAULT_THEME, ...theme };
150
+ return `
151
+ .${namespace} {
152
+ --primary-color: ${mergedTheme.primaryColor};
153
+ --secondary-color: ${mergedTheme.secondaryColor};
154
+ --text-color: ${mergedTheme.textColor};
155
+ --background-color: ${mergedTheme.backgroundColor};
156
+ --font-family: ${mergedTheme.fontFamily};
157
+ --border-radius: ${mergedTheme.borderRadius};
158
+
159
+ font-family: var(--font-family);
160
+ color: var(--text-color);
161
+ background-color: var(--background-color);
162
+ }
163
+
164
+ .${namespace} .btn {
165
+ background-color: var(--primary-color);
166
+ color: white;
167
+ border: none;
168
+ border-radius: var(--border-radius);
169
+ padding: 8px 16px;
170
+ cursor: pointer;
171
+ transition: background-color 0.3s ease;
172
+ }
173
+
174
+ .${namespace} .btn:hover {
175
+ background-color: var(--secondary-color);
176
+ }
177
+
178
+ .${namespace} .container {
179
+ border-radius: var(--border-radius);
180
+ border: 1px solid #e0e0e0;
181
+ padding: 16px;
182
+ margin: 8px 0;
183
+ }
184
+
185
+ .${namespace} .header {
186
+ font-weight: bold;
187
+ margin-bottom: 8px;
188
+ }
189
+
190
+ ${Object.entries(mergedTheme.customClasses || {}).map(([className, css]) => `.${namespace} .${className} { ${css} }`).join("\n")}
191
+ `;
192
+ }
193
+ function applyTheme(theme, namespace) {
194
+ const css = generateThemeCSS(theme, namespace);
195
+ const styleId = `${namespace}-theme`;
196
+ const existingStyle = document.getElementById(styleId);
197
+ if (existingStyle) {
198
+ existingStyle.remove();
199
+ }
200
+ return addStyleToDocument(css, styleId);
201
+ }
202
+ class SimpleEventEmitter {
203
+ constructor() {
204
+ __publicField(this, "events", /* @__PURE__ */ new Map());
205
+ }
206
+ /**
207
+ * Subscribe to an event
208
+ * @param eventName Event name
209
+ * @param callback Callback function
210
+ */
211
+ on(eventName, callback) {
212
+ if (!this.events.has(eventName)) {
213
+ this.events.set(eventName, []);
214
+ }
215
+ this.events.get(eventName).push(callback);
216
+ }
217
+ /**
218
+ * Unsubscribe from an event
219
+ * @param eventName Event name
220
+ * @param callback Callback function
221
+ */
222
+ off(eventName, callback) {
223
+ if (!this.events.has(eventName)) {
224
+ return;
225
+ }
226
+ const callbacks = this.events.get(eventName);
227
+ const index = callbacks.indexOf(callback);
228
+ if (index !== -1) {
229
+ callbacks.splice(index, 1);
230
+ }
231
+ if (callbacks.length === 0) {
232
+ this.events.delete(eventName);
233
+ }
234
+ }
235
+ /**
236
+ * Emit an event
237
+ * @param eventName Event name
238
+ * @param data Event data
239
+ */
240
+ emit(eventName, data) {
241
+ if (!this.events.has(eventName)) {
242
+ return;
243
+ }
244
+ const callbacks = this.events.get(eventName);
245
+ for (const callback of callbacks) {
246
+ try {
247
+ callback(data);
248
+ } catch (error) {
249
+ console.error(`Error in event listener for "${eventName}":`, error);
250
+ }
251
+ }
252
+ }
253
+ }
254
+ const BUBBLE_CSS = `
255
+ .sdk-bubble {
256
+ position: fixed;
257
+ width: 60px;
258
+ height: 60px;
259
+ border-radius: 50%;
260
+ background-color: var(--primary-color);
261
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
262
+ display: flex;
263
+ align-items: center;
264
+ justify-content: center;
265
+ cursor: pointer;
266
+ transition: all 0.3s ease;
267
+ z-index: 9999;
268
+ }
269
+
270
+ .sdk-bubble:hover {
271
+ transform: scale(1.1);
272
+ background-color: var(--secondary-color);
273
+ }
274
+
275
+ .sdk-bubble-icon {
276
+ width: 30px;
277
+ height: 30px;
278
+ fill: white;
279
+ }
280
+
281
+ .sdk-bubble-content {
282
+ position: fixed;
283
+ width: 300px;
284
+ max-height: 400px;
285
+ background-color: var(--background-color);
286
+ border-radius: var(--border-radius);
287
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
288
+ overflow: hidden;
289
+ display: none;
290
+ flex-direction: column;
291
+ z-index: 9998;
292
+ }
293
+
294
+ .sdk-bubble-content.active {
295
+ display: flex;
296
+ }
297
+
298
+ .sdk-bubble-header {
299
+ padding: 12px 16px;
300
+ background-color: var(--primary-color);
301
+ color: white;
302
+ font-weight: bold;
303
+ display: flex;
304
+ justify-content: space-between;
305
+ align-items: center;
306
+ }
307
+
308
+ .sdk-bubble-close {
309
+ cursor: pointer;
310
+ font-size: 18px;
311
+ }
312
+
313
+ .sdk-bubble-body {
314
+ padding: 16px;
315
+ overflow-y: auto;
316
+ flex-grow: 1;
317
+ }
318
+
319
+ .sdk-bubble-footer {
320
+ padding: 12px 16px;
321
+ border-top: 1px solid #eee;
322
+ display: flex;
323
+ justify-content: flex-end;
324
+ }
325
+ `;
326
+ const BUBBLE_POSITIONS = {
327
+ "top-left": { top: "20px", left: "20px" },
328
+ "top-right": { top: "20px", right: "20px" },
329
+ "bottom-left": { bottom: "20px", left: "20px" },
330
+ "bottom-right": { bottom: "20px", right: "20px" }
331
+ };
332
+ const CONTENT_POSITIONS = {
333
+ "top-left": { top: "90px", left: "20px" },
334
+ "top-right": { top: "90px", right: "20px" },
335
+ "bottom-left": { bottom: "90px", left: "20px" },
336
+ "bottom-right": { bottom: "90px", right: "20px" }
337
+ };
338
+ class BubbleUI {
339
+ /**
340
+ * Creates a new BubbleUI instance
341
+ * @param container Container element
342
+ * @param theme Theme options
343
+ */
344
+ constructor(container, theme = {}) {
345
+ __publicField(this, "container");
346
+ __publicField(this, "bubble", null);
347
+ __publicField(this, "content", null);
348
+ __publicField(this, "isOpen", false);
349
+ __publicField(this, "theme");
350
+ __publicField(this, "position");
351
+ this.container = container;
352
+ this.theme = theme;
353
+ this.position = theme.bubblePosition || "bottom-right";
354
+ }
355
+ /**
356
+ * Creates and renders the bubble UI
357
+ */
358
+ render() {
359
+ this.bubble = createElement("div", { class: "sdk-bubble" });
360
+ const bubblePosition = BUBBLE_POSITIONS[this.position];
361
+ Object.entries(bubblePosition).forEach(([key, value]) => {
362
+ this.bubble.style[key] = value;
363
+ });
364
+ if (this.theme.primaryColor) {
365
+ this.bubble.style.setProperty("--primary-color", this.theme.primaryColor);
366
+ }
367
+ if (this.theme.secondaryColor) {
368
+ this.bubble.style.setProperty(
369
+ "--secondary-color",
370
+ this.theme.secondaryColor
371
+ );
372
+ }
373
+ const icon = this.createBubbleIcon();
374
+ this.bubble.appendChild(icon);
375
+ this.content = this.createContentContainer();
376
+ this.bubble.addEventListener("click", () => this.toggleContent());
377
+ this.container.appendChild(this.bubble);
378
+ this.container.appendChild(this.content);
379
+ }
380
+ /**
381
+ * Updates the bubble UI with new content
382
+ * @param title Content title
383
+ * @param body Content body
384
+ */
385
+ updateContent(title, body) {
386
+ if (!this.content) return;
387
+ const headerText = this.content.querySelector(".sdk-bubble-header-text");
388
+ if (headerText) {
389
+ headerText.textContent = title;
390
+ }
391
+ const bodyElement = this.content.querySelector(".sdk-bubble-body");
392
+ if (bodyElement) {
393
+ bodyElement.innerHTML = body;
394
+ }
395
+ }
396
+ /**
397
+ * Shows the bubble UI
398
+ */
399
+ show() {
400
+ if (this.bubble) {
401
+ this.bubble.style.display = "flex";
402
+ }
403
+ }
404
+ /**
405
+ * Hides the bubble UI
406
+ */
407
+ hide() {
408
+ if (this.bubble) {
409
+ this.bubble.style.display = "none";
410
+ }
411
+ this.closeContent();
412
+ }
413
+ /**
414
+ * Destroys the bubble UI
415
+ */
416
+ destroy() {
417
+ if (this.bubble && this.bubble.parentNode) {
418
+ this.bubble.parentNode.removeChild(this.bubble);
419
+ }
420
+ if (this.content && this.content.parentNode) {
421
+ this.content.parentNode.removeChild(this.content);
422
+ }
423
+ this.bubble = null;
424
+ this.content = null;
425
+ }
426
+ /**
427
+ * Creates the bubble icon
428
+ * @returns The bubble icon element
429
+ */
430
+ createBubbleIcon() {
431
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
432
+ svg.setAttribute("class", "sdk-bubble-icon");
433
+ svg.setAttribute("viewBox", "0 0 24 24");
434
+ const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
435
+ path.setAttribute(
436
+ "d",
437
+ "M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H5.17L4 17.17V4h16v12z"
438
+ );
439
+ svg.appendChild(path);
440
+ return svg;
441
+ }
442
+ /**
443
+ * Creates the content container
444
+ * @returns The content container element
445
+ */
446
+ createContentContainer() {
447
+ const content = createElement("div", {
448
+ class: "sdk-bubble-content"
449
+ });
450
+ const contentPosition = CONTENT_POSITIONS[this.position];
451
+ Object.entries(contentPosition).forEach(([key, value]) => {
452
+ content.style[key] = value;
453
+ });
454
+ const header = createElement("div", {
455
+ class: "sdk-bubble-header"
456
+ });
457
+ const headerText = createElement(
458
+ "div",
459
+ { class: "sdk-bubble-header-text" },
460
+ ["SDK"]
461
+ );
462
+ const closeButton = createElement(
463
+ "div",
464
+ { class: "sdk-bubble-close" },
465
+ ["×"]
466
+ );
467
+ closeButton.addEventListener("click", (e) => {
468
+ e.stopPropagation();
469
+ this.closeContent();
470
+ });
471
+ header.appendChild(headerText);
472
+ header.appendChild(closeButton);
473
+ const body = createElement(
474
+ "div",
475
+ { class: "sdk-bubble-body" },
476
+ ["SDK content goes here."]
477
+ );
478
+ const footer = createElement("div", {
479
+ class: "sdk-bubble-footer"
480
+ });
481
+ content.appendChild(header);
482
+ content.appendChild(body);
483
+ content.appendChild(footer);
484
+ return content;
485
+ }
486
+ /**
487
+ * Toggles the content visibility
488
+ */
489
+ toggleContent() {
490
+ if (this.isOpen) {
491
+ this.closeContent();
492
+ } else {
493
+ this.openContent();
494
+ }
495
+ }
496
+ /**
497
+ * Opens the content
498
+ */
499
+ openContent() {
500
+ if (!this.content) return;
501
+ this.content.classList.add("active");
502
+ this.isOpen = true;
503
+ }
504
+ /**
505
+ * Closes the content
506
+ */
507
+ closeContent() {
508
+ if (!this.content) return;
509
+ this.content.classList.remove("active");
510
+ this.isOpen = false;
511
+ }
512
+ /**
513
+ * Gets the bubble CSS
514
+ * @returns The bubble CSS
515
+ */
516
+ static getCSS() {
517
+ return BUBBLE_CSS;
518
+ }
519
+ }
520
+ const DEFAULT_OPTIONS = {
521
+ targetElementId: "omi-sdk-container",
522
+ mode: "bubble",
523
+ debug: false
524
+ };
525
+ const SDK_NAMESPACE = "OmiSDK";
526
+ const SDK_VERSION = "0.1.0";
527
+ class OmiSDK {
528
+ /**
529
+ * Creates a new SDK instance
530
+ * @param options SDK options
531
+ */
532
+ constructor(options = {}) {
533
+ __publicField(this, "options");
534
+ __publicField(this, "container", null);
535
+ __publicField(this, "logger");
536
+ __publicField(this, "initialized", false);
537
+ __publicField(this, "styleElement", null);
538
+ __publicField(this, "eventEmitter");
539
+ __publicField(this, "bubbleUI", null);
540
+ this.options = { ...DEFAULT_OPTIONS, ...options };
541
+ this.logger = new Logger({
542
+ enabled: !!this.options.debug,
543
+ prefix: "[OmiSDK]",
544
+ level: LogLevel.DEBUG
545
+ });
546
+ this.eventEmitter = new SimpleEventEmitter();
547
+ }
548
+ login(_) {
549
+ return Promise.resolve({ success: true, message: "Logged in" });
550
+ }
551
+ loginSSO(_) {
552
+ return Promise.resolve({ success: true, message: "Logged in" });
553
+ }
554
+ logout() {
555
+ return Promise.resolve({ success: true, message: "Logged out" });
556
+ }
557
+ makeCall(_) {
558
+ return Promise.resolve({ success: true, message: "Call made" });
559
+ }
560
+ hangup() {
561
+ return Promise.resolve({ success: true, message: "Call hung up" });
562
+ }
563
+ answerCall(_) {
564
+ return Promise.resolve({ success: true, message: "Call answered" });
565
+ }
566
+ rejectCall() {
567
+ return Promise.resolve({ success: true, message: "Call rejected" });
568
+ }
569
+ hold() {
570
+ return Promise.resolve({ success: true, message: "Held" });
571
+ }
572
+ unhold() {
573
+ return Promise.resolve({ success: true, message: "Unheld" });
574
+ }
575
+ mute() {
576
+ return Promise.resolve({ success: true, message: "Muted" });
577
+ }
578
+ unmute() {
579
+ return Promise.resolve({ success: true, message: "Unmuted" });
580
+ }
581
+ cameraOn() {
582
+ return Promise.resolve({ success: true, message: "Camera on" });
583
+ }
584
+ cameraOff() {
585
+ return Promise.resolve({ success: true, message: "Camera off" });
586
+ }
587
+ transfer(_) {
588
+ return Promise.resolve({ success: true, message: "Call transferred" });
589
+ }
590
+ changeAgentStatus(_) {
591
+ return Promise.resolve({ success: true, message: "Agent status changed" });
592
+ }
593
+ getAgentStatus() {
594
+ return Promise.resolve({ success: true, message: "Agent status" });
595
+ }
596
+ hideBubble() {
597
+ var _a;
598
+ (_a = this.bubbleUI) == null ? void 0 : _a.hide();
599
+ return Promise.resolve({ success: true, message: "Bubble hidden" });
600
+ }
601
+ showBubble() {
602
+ var _a;
603
+ (_a = this.bubbleUI) == null ? void 0 : _a.show();
604
+ return Promise.resolve({ success: true, message: "Bubble shown" });
605
+ }
606
+ on(eventName, callback) {
607
+ this.eventEmitter.on(eventName, callback);
608
+ }
609
+ off(eventName, callback) {
610
+ this.eventEmitter.off(eventName, callback);
611
+ }
612
+ /**
613
+ * Initializes the SDK
614
+ * @param options SDK options
615
+ */
616
+ init(options = {}) {
617
+ if (this.initialized) {
618
+ this.logger.warn("SDK is already initialized");
619
+ return;
620
+ }
621
+ this.updateOptions(options);
622
+ this.logger.debug("Initializing SDK with options:", this.options);
623
+ try {
624
+ const targetId = this.options.targetElementId || DEFAULT_OPTIONS.targetElementId;
625
+ let targetElement = getElementById(targetId);
626
+ if (!targetElement) {
627
+ this.logger.debug(
628
+ `Target element with ID "${targetId}" not found, creating it`
629
+ );
630
+ targetElement = createElement("div", { id: targetId });
631
+ document.body.appendChild(targetElement);
632
+ }
633
+ this.container = createElement("div", {
634
+ class: SDK_NAMESPACE,
635
+ "data-version": SDK_VERSION,
636
+ "data-mode": this.options.mode || DEFAULT_OPTIONS.mode
637
+ });
638
+ targetElement.appendChild(this.container);
639
+ if (this.options.theme) {
640
+ this.styleElement = applyTheme(this.options.theme, SDK_NAMESPACE);
641
+ }
642
+ this.initializeUI();
643
+ this.initialized = true;
644
+ this.logger.info("SDK initialized successfully");
645
+ setTimeout(() => {
646
+ this.eventEmitter.emit("AppEvent", {
647
+ name: "ready",
648
+ type: AppEventType.READY,
649
+ message: "SDK initialized successfully",
650
+ timestamp: Date.now()
651
+ });
652
+ }, 0);
653
+ } catch (error) {
654
+ this.logger.error("Failed to initialize SDK:", error);
655
+ this.eventEmitter.emit("AppEvent", {
656
+ name: "error",
657
+ type: AppEventType.ERROR,
658
+ message: "Failed to initialize SDK",
659
+ error,
660
+ timestamp: Date.now()
661
+ });
662
+ }
663
+ }
664
+ /**
665
+ * Destroys the SDK instance
666
+ */
667
+ destroy() {
668
+ if (!this.initialized) {
669
+ this.logger.warn("SDK is not initialized");
670
+ return;
671
+ }
672
+ this.logger.debug("Destroying SDK");
673
+ try {
674
+ if (this.bubbleUI) {
675
+ this.bubbleUI.destroy();
676
+ this.bubbleUI = null;
677
+ }
678
+ if (this.container) {
679
+ removeElement(this.container);
680
+ this.container = null;
681
+ }
682
+ if (this.styleElement) {
683
+ removeElement(this.styleElement);
684
+ this.styleElement = null;
685
+ }
686
+ this.initialized = false;
687
+ this.logger.info("SDK destroyed successfully");
688
+ } catch (error) {
689
+ this.logger.error("Failed to destroy SDK:", error);
690
+ this.eventEmitter.emit("AppEvent", {
691
+ name: "error",
692
+ type: AppEventType.ERROR,
693
+ message: "Failed to destroy SDK",
694
+ error,
695
+ timestamp: Date.now()
696
+ });
697
+ }
698
+ }
699
+ /**
700
+ * Updates SDK options
701
+ * @param options New options
702
+ */
703
+ updateOptions(options) {
704
+ const previousMode = this.options.mode;
705
+ this.options = { ...this.options, ...options };
706
+ this.logger.updateConfig({
707
+ enabled: !!this.options.debug
708
+ });
709
+ this.logger.debug("Options updated:", this.options);
710
+ if (this.initialized && this.options.theme) {
711
+ this.styleElement = applyTheme(this.options.theme, SDK_NAMESPACE);
712
+ }
713
+ if (this.initialized && previousMode !== this.options.mode) {
714
+ this.initializeUI();
715
+ }
716
+ }
717
+ /**
718
+ * Gets the SDK version
719
+ * @returns SDK version
720
+ */
721
+ getVersion() {
722
+ return SDK_VERSION;
723
+ }
724
+ /**
725
+ * Gets the current SDK options
726
+ * @returns SDK options
727
+ */
728
+ getOptions() {
729
+ return { ...this.options };
730
+ }
731
+ /**
732
+ * Initializes the UI based on the mode
733
+ */
734
+ initializeUI() {
735
+ if (!this.container) return;
736
+ this.container.innerHTML = "";
737
+ if (this.bubbleUI) {
738
+ this.bubbleUI.destroy();
739
+ this.bubbleUI = null;
740
+ }
741
+ if (this.options.mode === "bubble") {
742
+ const bubbleCSS = BubbleUI.getCSS();
743
+ addStyleToDocument(bubbleCSS, `${SDK_NAMESPACE}-bubble-style`);
744
+ this.bubbleUI = new BubbleUI(this.container, this.options.theme);
745
+ this.bubbleUI.render();
746
+ this.bubbleUI.updateContent("SDK", "Connected and ready to use.");
747
+ } else {
748
+ this.logger.debug("SDK initialized in headless mode");
749
+ const existingStyle = document.getElementById(
750
+ `${SDK_NAMESPACE}-bubble-style`
751
+ );
752
+ if (existingStyle && existingStyle.parentNode) {
753
+ existingStyle.parentNode.removeChild(existingStyle);
754
+ }
755
+ }
756
+ }
757
+ }
758
+ const sdkInstance = new OmiSDK();
759
+ document.addEventListener("DOMContentLoaded", () => {
760
+ const scriptTag = document.querySelector("script[data-auto-init]");
761
+ if (scriptTag) {
762
+ const options = {};
763
+ const targetElementId = scriptTag.getAttribute("data-target-element-id");
764
+ if (targetElementId) {
765
+ options.targetElementId = targetElementId;
766
+ }
767
+ const mode = scriptTag.getAttribute("data-mode");
768
+ if (mode && (mode === "none" || mode === "bubble")) {
769
+ options.mode = mode;
770
+ }
771
+ const baseUrl = scriptTag.getAttribute("data-base-url");
772
+ if (baseUrl) {
773
+ options.baseUrl = baseUrl;
774
+ }
775
+ const debug = scriptTag.getAttribute("data-debug") === "true";
776
+ if (debug) {
777
+ options.debug = debug;
778
+ }
779
+ sdkInstance.init(options);
780
+ }
781
+ });
782
+ export {
783
+ OmiSDK,
784
+ sdkInstance as default
785
+ };
786
+ //# sourceMappingURL=omisdk.es.js.map