@weldsuite/helpdesk-widget-sdk 1.0.2

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,1428 @@
1
+ /**
2
+ * Weld SDK - Configuration Types
3
+ * Type definitions for SDK initialization and configuration
4
+ */
5
+ /**
6
+ * Event types for widget events
7
+ */
8
+ type WidgetEventType = 'ready' | 'open' | 'close' | 'error' | 'message' | 'minimize' | 'maximize' | 'destroy';
9
+ /**
10
+ * Widget event structure
11
+ */
12
+ interface WidgetEvent {
13
+ type: WidgetEventType;
14
+ data?: any;
15
+ timestamp: number;
16
+ }
17
+ /**
18
+ * Event handler function type
19
+ */
20
+ type WidgetEventHandler = (event?: WidgetEvent | any) => void;
21
+ /**
22
+ * Position configuration
23
+ */
24
+ interface PositionConfig {
25
+ bottom?: string;
26
+ right?: string;
27
+ left?: string;
28
+ top?: string;
29
+ }
30
+ /**
31
+ * Customization configuration
32
+ */
33
+ interface CustomizationConfig {
34
+ primaryColor?: string;
35
+ accentColor?: string;
36
+ backgroundColor?: string;
37
+ textColor?: string;
38
+ fontFamily?: string;
39
+ fontSize?: string;
40
+ borderRadius?: string;
41
+ }
42
+ /**
43
+ * Feature flags
44
+ */
45
+ interface FeatureConfig {
46
+ attachments?: boolean;
47
+ reactions?: boolean;
48
+ typing?: boolean;
49
+ readReceipts?: boolean;
50
+ offlineMode?: boolean;
51
+ fileUpload?: boolean;
52
+ imageUpload?: boolean;
53
+ voiceMessages?: boolean;
54
+ videoMessages?: boolean;
55
+ }
56
+ /**
57
+ * Mobile configuration
58
+ */
59
+ interface MobileConfig {
60
+ fullScreen?: boolean;
61
+ scrollLock?: boolean;
62
+ keyboardHandling?: 'auto' | 'manual';
63
+ safeAreaInsets?: boolean;
64
+ }
65
+ /**
66
+ * Iframe configuration
67
+ */
68
+ interface IframeConfig {
69
+ launcher: {
70
+ url: string;
71
+ name: string;
72
+ position: PositionConfig;
73
+ size: string;
74
+ };
75
+ widget: {
76
+ url: string;
77
+ name: string;
78
+ position: PositionConfig;
79
+ width: string;
80
+ height: string;
81
+ };
82
+ backdrop?: {
83
+ enabled: boolean;
84
+ closeOnClick: boolean;
85
+ };
86
+ }
87
+ /**
88
+ * API configuration
89
+ */
90
+ interface ApiConfig {
91
+ baseUrl: string;
92
+ widgetId: string;
93
+ endpoints?: {
94
+ messages?: string;
95
+ users?: string;
96
+ conversations?: string;
97
+ upload?: string;
98
+ };
99
+ timeout?: number;
100
+ retries?: number;
101
+ }
102
+ /**
103
+ * Authentication configuration
104
+ */
105
+ interface AuthConfig {
106
+ enabled?: boolean;
107
+ mode?: 'anonymous' | 'identified';
108
+ userId?: string;
109
+ email?: string;
110
+ name?: string;
111
+ avatar?: string;
112
+ metadata?: Record<string, any>;
113
+ token?: string;
114
+ }
115
+ /**
116
+ * Locale configuration
117
+ */
118
+ interface LocaleConfig {
119
+ locale?: string;
120
+ translations?: Record<string, Record<string, string>>;
121
+ dateFormat?: string;
122
+ timeFormat?: string;
123
+ timezone?: string;
124
+ }
125
+ /**
126
+ * Logging configuration
127
+ */
128
+ interface LogConfig {
129
+ enabled?: boolean;
130
+ level?: 'debug' | 'info' | 'warn' | 'error';
131
+ prefix?: string;
132
+ includeTimestamp?: boolean;
133
+ }
134
+ /**
135
+ * Performance configuration
136
+ */
137
+ interface PerformanceConfig {
138
+ lazyLoad?: boolean;
139
+ preload?: boolean;
140
+ caching?: boolean;
141
+ prefetch?: boolean;
142
+ }
143
+ /**
144
+ * Security configuration
145
+ */
146
+ interface SecurityConfig {
147
+ allowedOrigins?: string[];
148
+ validateMessages?: boolean;
149
+ sanitizeInput?: boolean;
150
+ contentSecurityPolicy?: string;
151
+ }
152
+ /**
153
+ * Main SDK configuration
154
+ */
155
+ interface WeldConfig {
156
+ widgetId: string;
157
+ api?: Partial<ApiConfig>;
158
+ iframes?: Partial<IframeConfig>;
159
+ position?: {
160
+ launcher?: PositionConfig;
161
+ widget?: PositionConfig;
162
+ };
163
+ customization?: CustomizationConfig;
164
+ features?: FeatureConfig;
165
+ mobile?: MobileConfig;
166
+ auth?: AuthConfig;
167
+ locale?: LocaleConfig;
168
+ logging?: LogConfig;
169
+ performance?: PerformanceConfig;
170
+ security?: SecurityConfig;
171
+ onReady?: () => void;
172
+ onError?: (error: Error) => void;
173
+ onOpen?: () => void;
174
+ onClose?: () => void;
175
+ onMessage?: (message: any) => void;
176
+ onMinimize?: () => void;
177
+ onMaximize?: () => void;
178
+ onDestroy?: () => void;
179
+ }
180
+ /**
181
+ * Runtime configuration (resolved from WeldConfig)
182
+ */
183
+ interface ResolvedConfig {
184
+ widgetId: string;
185
+ api: ApiConfig;
186
+ iframes: IframeConfig;
187
+ customization: CustomizationConfig;
188
+ features: FeatureConfig;
189
+ mobile: MobileConfig;
190
+ auth: AuthConfig;
191
+ locale: LocaleConfig;
192
+ logging: LogConfig;
193
+ performance: PerformanceConfig;
194
+ security: SecurityConfig;
195
+ onReady?: () => void;
196
+ onError?: (error: Error) => void;
197
+ onOpen?: () => void;
198
+ onClose?: () => void;
199
+ onMessage?: (message: any) => void;
200
+ onMinimize?: () => void;
201
+ onMaximize?: () => void;
202
+ onDestroy?: () => void;
203
+ }
204
+ /**
205
+ * Device detection
206
+ */
207
+ type DeviceType = 'mobile' | 'tablet' | 'desktop';
208
+ interface DeviceInfo {
209
+ type: DeviceType;
210
+ isMobile: boolean;
211
+ isTablet: boolean;
212
+ isDesktop: boolean;
213
+ isTouchDevice: boolean;
214
+ screenWidth: number;
215
+ screenHeight: number;
216
+ orientation: 'portrait' | 'landscape';
217
+ userAgent: string;
218
+ }
219
+ /**
220
+ * Default configuration values
221
+ */
222
+ declare const DEFAULT_CONFIG: Omit<ResolvedConfig, 'widgetId'>;
223
+ /**
224
+ * Configuration validation
225
+ */
226
+ declare function validateConfig(config: Partial<WeldConfig>): boolean;
227
+ /**
228
+ * Merge configuration with defaults
229
+ */
230
+ declare function resolveConfig(config: WeldConfig): ResolvedConfig;
231
+
232
+ /**
233
+ * Weld SDK - State Types
234
+ * Type definitions for state management across iframes
235
+ */
236
+ /**
237
+ * Widget visibility state
238
+ */
239
+ declare enum WidgetVisibility {
240
+ HIDDEN = "hidden",
241
+ VISIBLE = "visible",
242
+ MINIMIZED = "minimized"
243
+ }
244
+ /**
245
+ * Widget view types
246
+ */
247
+ declare enum WidgetView {
248
+ HOME = "home",
249
+ CONVERSATION = "conversation",
250
+ CONVERSATIONS = "conversations",
251
+ HELP = "help",
252
+ SETTINGS = "settings",
253
+ SEARCH = "search"
254
+ }
255
+ /**
256
+ * Connection status
257
+ */
258
+ declare enum ConnectionStatus {
259
+ DISCONNECTED = "disconnected",
260
+ CONNECTING = "connecting",
261
+ CONNECTED = "connected",
262
+ RECONNECTING = "reconnecting",
263
+ ERROR = "error"
264
+ }
265
+ /**
266
+ * Message status
267
+ */
268
+ declare enum MessageStatus {
269
+ SENDING = "sending",
270
+ SENT = "sent",
271
+ DELIVERED = "delivered",
272
+ READ = "read",
273
+ FAILED = "failed"
274
+ }
275
+ /**
276
+ * User state
277
+ */
278
+ interface UserState {
279
+ id?: string;
280
+ email?: string;
281
+ name?: string;
282
+ avatar?: string;
283
+ metadata?: Record<string, any>;
284
+ isAuthenticated: boolean;
285
+ isAnonymous: boolean;
286
+ }
287
+ /**
288
+ * Conversation state
289
+ */
290
+ interface ConversationState {
291
+ id?: string;
292
+ messages: Message[];
293
+ participants: Participant[];
294
+ unreadCount: number;
295
+ lastMessageAt?: number;
296
+ isTyping: boolean;
297
+ typingUsers: string[];
298
+ }
299
+ /**
300
+ * Message interface
301
+ */
302
+ interface Message {
303
+ id: string;
304
+ conversationId: string;
305
+ text: string;
306
+ sender: {
307
+ id: string;
308
+ name: string;
309
+ avatar?: string;
310
+ type: 'user' | 'agent' | 'bot';
311
+ };
312
+ status: MessageStatus;
313
+ timestamp: number;
314
+ createdAt: number;
315
+ updatedAt?: number;
316
+ attachments?: Attachment[];
317
+ reactions?: Reaction[];
318
+ metadata?: Record<string, any>;
319
+ }
320
+ /**
321
+ * Attachment interface
322
+ */
323
+ interface Attachment {
324
+ id: string;
325
+ type: 'image' | 'file' | 'video' | 'audio';
326
+ url: string;
327
+ name: string;
328
+ size: number;
329
+ mimeType: string;
330
+ thumbnail?: string;
331
+ }
332
+ /**
333
+ * Reaction interface
334
+ */
335
+ interface Reaction {
336
+ emoji: string;
337
+ count: number;
338
+ users: string[];
339
+ }
340
+ /**
341
+ * Participant interface
342
+ */
343
+ interface Participant {
344
+ id: string;
345
+ name: string;
346
+ avatar?: string;
347
+ type: 'user' | 'agent' | 'bot';
348
+ isOnline: boolean;
349
+ lastSeenAt?: number;
350
+ }
351
+ /**
352
+ * Widget state
353
+ */
354
+ interface WidgetState {
355
+ visibility: WidgetVisibility;
356
+ view: WidgetView;
357
+ isOpen: boolean;
358
+ isMinimized: boolean;
359
+ dimensions: {
360
+ width: string;
361
+ height: string;
362
+ };
363
+ position: {
364
+ bottom: string;
365
+ right: string;
366
+ };
367
+ }
368
+ /**
369
+ * Launcher state
370
+ */
371
+ interface LauncherState {
372
+ isVisible: boolean;
373
+ badge: {
374
+ count: number;
375
+ text?: string;
376
+ show: boolean;
377
+ };
378
+ customColor?: string;
379
+ tooltip?: string;
380
+ }
381
+ /**
382
+ * Backdrop state
383
+ */
384
+ interface BackdropState {
385
+ isVisible: boolean;
386
+ closeOnClick: boolean;
387
+ opacity: number;
388
+ }
389
+ /**
390
+ * Mobile state
391
+ */
392
+ interface MobileState {
393
+ isFullScreen: boolean;
394
+ isScrollLocked: boolean;
395
+ keyboardHeight: number;
396
+ orientation: 'portrait' | 'landscape';
397
+ safeAreaInsets: {
398
+ top: number;
399
+ right: number;
400
+ bottom: number;
401
+ left: number;
402
+ };
403
+ }
404
+ /**
405
+ * Network state
406
+ */
407
+ interface NetworkState {
408
+ status: ConnectionStatus;
409
+ lastConnected?: number;
410
+ retryCount: number;
411
+ latency?: number;
412
+ }
413
+ /**
414
+ * UI state
415
+ */
416
+ interface UIState {
417
+ theme: 'light' | 'dark' | 'auto';
418
+ locale: string;
419
+ isLoading: boolean;
420
+ error?: {
421
+ code: string;
422
+ message: string;
423
+ recoverable: boolean;
424
+ };
425
+ }
426
+ /**
427
+ * Main application state
428
+ */
429
+ interface WeldState {
430
+ user: UserState;
431
+ conversation: ConversationState;
432
+ widget: WidgetState;
433
+ launcher: LauncherState;
434
+ backdrop: BackdropState;
435
+ mobile: MobileState;
436
+ network: NetworkState;
437
+ ui: UIState;
438
+ initialized: boolean;
439
+ lastUpdated: number;
440
+ }
441
+ /**
442
+ * State update action
443
+ */
444
+ interface StateAction<T = any> {
445
+ type: string;
446
+ path: keyof WeldState | string;
447
+ payload: T;
448
+ merge?: boolean;
449
+ timestamp: number;
450
+ }
451
+ /**
452
+ * State listener callback
453
+ */
454
+ type StateListener<T = any> = (newState: T, oldState: T) => void;
455
+ /**
456
+ * State subscription
457
+ */
458
+ interface StateSubscription {
459
+ id: string;
460
+ path: string;
461
+ listener: StateListener;
462
+ immediate?: boolean;
463
+ }
464
+ /**
465
+ * Initial state factory
466
+ */
467
+ declare function createInitialState(): WeldState;
468
+ /**
469
+ * State path utility
470
+ */
471
+ declare function getStateValue<T = any>(state: WeldState, path: string): T;
472
+ /**
473
+ * State update utility
474
+ */
475
+ declare function setStateValue(state: WeldState, path: string, value: any, merge?: boolean): WeldState;
476
+
477
+ /**
478
+ * User identification data
479
+ */
480
+ interface UserIdentity {
481
+ userId: string;
482
+ email?: string;
483
+ name?: string;
484
+ avatar?: string;
485
+ metadata?: Record<string, any>;
486
+ }
487
+ /**
488
+ * WeldSDK class
489
+ * Main SDK interface for embedding the widget
490
+ */
491
+ declare class WeldSDK {
492
+ private config;
493
+ private logger;
494
+ private iframeManager;
495
+ private messageBroker;
496
+ private stateCoordinator;
497
+ private status;
498
+ private readyPromise;
499
+ private readyResolve;
500
+ constructor(config: WeldConfig);
501
+ /**
502
+ * Initialize the SDK and render widget
503
+ */
504
+ init(): Promise<void>;
505
+ /**
506
+ * Setup ready message handlers
507
+ */
508
+ private setupReadyHandlers;
509
+ /**
510
+ * Map iframe name to type
511
+ */
512
+ private mapIframeNameToType;
513
+ /**
514
+ * Wait for all iframes to be ready
515
+ */
516
+ private waitForIframesReady;
517
+ /**
518
+ * Wait for SDK to be ready
519
+ */
520
+ ready(): Promise<void>;
521
+ /**
522
+ * Check if SDK is ready
523
+ */
524
+ isReady(): boolean;
525
+ /**
526
+ * Open the widget
527
+ */
528
+ open(): void;
529
+ /**
530
+ * Close the widget
531
+ */
532
+ close(): void;
533
+ /**
534
+ * Toggle widget open/close
535
+ */
536
+ toggle(): void;
537
+ /**
538
+ * Minimize the widget
539
+ */
540
+ minimize(): void;
541
+ /**
542
+ * Maximize the widget
543
+ */
544
+ maximize(): void;
545
+ /**
546
+ * Show the launcher
547
+ */
548
+ showLauncher(): void;
549
+ /**
550
+ * Hide the launcher
551
+ */
552
+ hideLauncher(): void;
553
+ /**
554
+ * Set badge count
555
+ */
556
+ setBadgeCount(count: number): void;
557
+ /**
558
+ * Clear badge
559
+ */
560
+ clearBadge(): void;
561
+ /**
562
+ * Send a message
563
+ */
564
+ sendMessage(text: string, metadata?: Record<string, any>): void;
565
+ /**
566
+ * Identify user
567
+ */
568
+ identify(identity: UserIdentity): void;
569
+ /**
570
+ * Logout user
571
+ */
572
+ logout(): void;
573
+ /**
574
+ * Update configuration
575
+ */
576
+ updateConfig(updates: Partial<WeldConfig>): void;
577
+ /**
578
+ * Update theme
579
+ */
580
+ setTheme(theme: 'light' | 'dark' | 'auto'): void;
581
+ /**
582
+ * Update locale
583
+ */
584
+ setLocale(locale: string): void;
585
+ /**
586
+ * Track custom event
587
+ */
588
+ track(eventName: string, properties?: Record<string, any>): void;
589
+ /**
590
+ * Get current state
591
+ */
592
+ getState(): WeldState;
593
+ /**
594
+ * Subscribe to state changes
595
+ */
596
+ onStateChange<T = any>(path: string, listener: (newValue: T, oldValue: T) => void): () => void;
597
+ /**
598
+ * Get device info
599
+ */
600
+ getDeviceInfo(): DeviceInfo;
601
+ /**
602
+ * Get SDK status
603
+ */
604
+ getStatus(): string;
605
+ /**
606
+ * Get SDK version
607
+ */
608
+ getVersion(): string;
609
+ /**
610
+ * Enable debug mode
611
+ */
612
+ enableDebug(): void;
613
+ /**
614
+ * Disable debug mode
615
+ */
616
+ disableDebug(): void;
617
+ /**
618
+ * Ensure SDK is ready before operation
619
+ */
620
+ private ensureReady;
621
+ /**
622
+ * Destroy SDK and cleanup
623
+ */
624
+ destroy(): void;
625
+ }
626
+ /**
627
+ * Create and initialize WeldSDK instance
628
+ */
629
+ declare function createWeldSDK(config: WeldConfig): Promise<WeldSDK>;
630
+
631
+ /**
632
+ * Weld SDK - Iframe Manager
633
+ * Manages creation, lifecycle, and communication with multiple iframes
634
+ */
635
+
636
+ /**
637
+ * Iframe types
638
+ */
639
+ declare enum IframeType {
640
+ LAUNCHER = "launcher",
641
+ WIDGET = "widget",
642
+ BACKDROP = "backdrop"
643
+ }
644
+ /**
645
+ * Iframe metadata
646
+ */
647
+ interface IframeMetadata {
648
+ type: IframeType;
649
+ element: HTMLIFrameElement;
650
+ container: HTMLDivElement;
651
+ ready: boolean;
652
+ visible: boolean;
653
+ createdAt: number;
654
+ }
655
+ /**
656
+ * IframeManager class
657
+ * Orchestrates multiple iframes for the widget system
658
+ */
659
+ declare class IframeManager {
660
+ private config;
661
+ private logger;
662
+ private iframes;
663
+ private rootContainer;
664
+ private appContainer;
665
+ private modalContainer;
666
+ private deviceInfo;
667
+ private styleElement;
668
+ constructor(config: ResolvedConfig);
669
+ /**
670
+ * Initialize all containers and iframes
671
+ */
672
+ init(): Promise<void>;
673
+ /**
674
+ * Create root container structure
675
+ */
676
+ private createRootContainer;
677
+ /**
678
+ * Inject CSS into the page
679
+ */
680
+ private injectCSS;
681
+ /**
682
+ * Generate CSS for containers
683
+ */
684
+ private generateCSS;
685
+ /**
686
+ * Create launcher iframe
687
+ */
688
+ private createLauncherIframe;
689
+ /**
690
+ * Create widget iframe
691
+ */
692
+ private createWidgetIframe;
693
+ /**
694
+ * Create backdrop iframe
695
+ */
696
+ private createBackdropIframe;
697
+ /**
698
+ * Build iframe URL with parameters
699
+ */
700
+ private buildIframeUrl;
701
+ /**
702
+ * Setup event listeners
703
+ */
704
+ private setupEventListeners;
705
+ /**
706
+ * Handle window resize
707
+ */
708
+ private handleResize;
709
+ /**
710
+ * Handle orientation change
711
+ */
712
+ private handleOrientationChange;
713
+ /**
714
+ * Get iframe by type
715
+ */
716
+ getIframe(type: IframeType): IframeMetadata | undefined;
717
+ /**
718
+ * Get iframe element
719
+ */
720
+ getIframeElement(type: IframeType): HTMLIFrameElement | undefined;
721
+ /**
722
+ * Get iframe container
723
+ */
724
+ getIframeContainer(type: IframeType): HTMLDivElement | undefined;
725
+ /**
726
+ * Mark iframe as ready
727
+ */
728
+ setIframeReady(type: IframeType): void;
729
+ /**
730
+ * Check if all iframes are ready
731
+ */
732
+ areAllIframesReady(): boolean;
733
+ /**
734
+ * Show iframe
735
+ */
736
+ showIframe(type: IframeType): void;
737
+ /**
738
+ * Hide iframe
739
+ */
740
+ hideIframe(type: IframeType): void;
741
+ /**
742
+ * Get device info
743
+ */
744
+ getDeviceInfo(): DeviceInfo;
745
+ /**
746
+ * Get modal container
747
+ */
748
+ getModalContainer(): HTMLDivElement | null;
749
+ /**
750
+ * Destroy all iframes and cleanup
751
+ */
752
+ destroy(): void;
753
+ }
754
+
755
+ /**
756
+ * Weld SDK - Message Types
757
+ * Type definitions for postMessage communication between parent and iframes
758
+ */
759
+ /**
760
+ * Message origins for validation
761
+ */
762
+ declare enum MessageOrigin {
763
+ LAUNCHER = "launcher",
764
+ WIDGET = "widget",
765
+ PARENT = "parent",
766
+ BACKDROP = "backdrop"
767
+ }
768
+ /**
769
+ * Message types for different communication patterns
770
+ */
771
+ declare enum MessageType {
772
+ READY = "weld:ready",
773
+ INIT = "weld:init",
774
+ DESTROY = "weld:destroy",
775
+ STATE_UPDATE = "weld:state:update",
776
+ STATE_REQUEST = "weld:state:request",
777
+ STATE_RESPONSE = "weld:state:response",
778
+ WIDGET_OPEN = "weld:widget:open",
779
+ WIDGET_CLOSE = "weld:widget:close",
780
+ WIDGET_TOGGLE = "weld:widget:toggle",
781
+ WIDGET_MINIMIZE = "weld:widget:minimize",
782
+ WIDGET_MAXIMIZE = "weld:widget:maximize",
783
+ LAUNCHER_SHOW = "weld:launcher:show",
784
+ LAUNCHER_HIDE = "weld:launcher:hide",
785
+ LAUNCHER_UPDATE = "weld:launcher:update",
786
+ BACKDROP_SHOW = "weld:backdrop:show",
787
+ BACKDROP_HIDE = "weld:backdrop:hide",
788
+ BACKDROP_CLICK = "weld:backdrop:click",
789
+ MESSAGE_SEND = "weld:message:send",
790
+ MESSAGE_RECEIVE = "weld:message:receive",
791
+ TYPING_START = "weld:typing:start",
792
+ TYPING_STOP = "weld:typing:stop",
793
+ BADGE_UPDATE = "weld:badge:update",
794
+ BADGE_CLEAR = "weld:badge:clear",
795
+ MOBILE_SCROLL_LOCK = "weld:mobile:scroll:lock",
796
+ MOBILE_SCROLL_UNLOCK = "weld:mobile:scroll:unlock",
797
+ CONFIG_UPDATE = "weld:config:update",
798
+ THEME_UPDATE = "weld:theme:update",
799
+ LOCALE_UPDATE = "weld:locale:update",
800
+ AUTH_LOGIN = "weld:auth:login",
801
+ AUTH_LOGOUT = "weld:auth:logout",
802
+ AUTH_TOKEN_UPDATE = "weld:auth:token:update",
803
+ EVENT_TRACK = "weld:event:track",
804
+ ERROR_REPORT = "weld:error:report",
805
+ API_SUCCESS = "weld:api:success",
806
+ API_ERROR = "weld:api:error"
807
+ }
808
+ /**
809
+ * Base message structure
810
+ */
811
+ interface BaseMessage {
812
+ type: MessageType;
813
+ origin: MessageOrigin;
814
+ timestamp: number;
815
+ id: string;
816
+ }
817
+ /**
818
+ * Message with payload
819
+ */
820
+ interface PayloadMessage<T = any> extends BaseMessage {
821
+ payload: T;
822
+ }
823
+ /**
824
+ * State update payload
825
+ */
826
+ interface StateUpdatePayload {
827
+ path: string;
828
+ value: any;
829
+ merge?: boolean;
830
+ }
831
+ /**
832
+ * Widget state payload
833
+ */
834
+ interface WidgetStatePayload {
835
+ isOpen: boolean;
836
+ isMinimized: boolean;
837
+ view?: string;
838
+ data?: any;
839
+ }
840
+ /**
841
+ * Launcher state payload
842
+ */
843
+ interface LauncherStatePayload {
844
+ isVisible: boolean;
845
+ badgeCount?: number;
846
+ badgeText?: string;
847
+ customColor?: string;
848
+ }
849
+ /**
850
+ * Backdrop state payload
851
+ */
852
+ interface BackdropStatePayload {
853
+ isVisible: boolean;
854
+ onClick?: 'close' | 'ignore';
855
+ }
856
+ /**
857
+ * Message data payload
858
+ */
859
+ interface MessageDataPayload {
860
+ id: string;
861
+ text: string;
862
+ sender: 'user' | 'agent' | 'bot';
863
+ timestamp: number;
864
+ attachments?: Array<{
865
+ type: string;
866
+ url: string;
867
+ name?: string;
868
+ }>;
869
+ }
870
+ /**
871
+ * Configuration update payload
872
+ */
873
+ interface ConfigUpdatePayload {
874
+ apiKey?: string;
875
+ workspaceId?: string;
876
+ position?: {
877
+ launcher?: {
878
+ bottom: string;
879
+ right: string;
880
+ };
881
+ widget?: {
882
+ bottom: string;
883
+ right: string;
884
+ };
885
+ };
886
+ customization?: {
887
+ primaryColor?: string;
888
+ accentColor?: string;
889
+ fontFamily?: string;
890
+ };
891
+ features?: {
892
+ attachments?: boolean;
893
+ reactions?: boolean;
894
+ typing?: boolean;
895
+ };
896
+ }
897
+ /**
898
+ * Theme update payload
899
+ */
900
+ interface ThemeUpdatePayload {
901
+ mode: 'light' | 'dark' | 'auto';
902
+ primaryColor?: string;
903
+ accentColor?: string;
904
+ customCSS?: string;
905
+ }
906
+ /**
907
+ * Authentication payload
908
+ */
909
+ interface AuthPayload {
910
+ userId?: string;
911
+ email?: string;
912
+ name?: string;
913
+ avatar?: string;
914
+ metadata?: Record<string, any>;
915
+ token?: string;
916
+ }
917
+ /**
918
+ * Error payload
919
+ */
920
+ interface ErrorPayload {
921
+ code: string;
922
+ message: string;
923
+ stack?: string;
924
+ context?: Record<string, any>;
925
+ }
926
+ /**
927
+ * Event tracking payload
928
+ */
929
+ interface EventPayload {
930
+ name: string;
931
+ properties?: Record<string, any>;
932
+ timestamp: number;
933
+ }
934
+ /**
935
+ * Type guards
936
+ */
937
+ declare function isBaseMessage(message: any): message is BaseMessage;
938
+ declare function isPayloadMessage<T = any>(message: any): message is PayloadMessage<T>;
939
+ /**
940
+ * Message creator utilities
941
+ */
942
+ declare function createMessage(type: MessageType, origin: MessageOrigin, payload?: any): PayloadMessage;
943
+ /**
944
+ * Specific message type definitions
945
+ */
946
+ type ReadyMessage = PayloadMessage<{
947
+ iframe: string;
948
+ ready: true;
949
+ }>;
950
+ type StateUpdateMessage = PayloadMessage<StateUpdatePayload>;
951
+ type WidgetStateMessage = PayloadMessage<WidgetStatePayload>;
952
+ type LauncherStateMessage = PayloadMessage<LauncherStatePayload>;
953
+ type BackdropStateMessage = PayloadMessage<BackdropStatePayload>;
954
+ type MessageDataMessage = PayloadMessage<MessageDataPayload>;
955
+ type ConfigUpdateMessage = PayloadMessage<ConfigUpdatePayload>;
956
+ type ThemeUpdateMessage = PayloadMessage<ThemeUpdatePayload>;
957
+ type AuthMessage = PayloadMessage<AuthPayload>;
958
+ type ErrorMessage = PayloadMessage<ErrorPayload>;
959
+ type EventMessage = PayloadMessage<EventPayload>;
960
+ /**
961
+ * Union type for all messages
962
+ */
963
+ type WeldMessage = BaseMessage | ReadyMessage | StateUpdateMessage | WidgetStateMessage | LauncherStateMessage | BackdropStateMessage | MessageDataMessage | ConfigUpdateMessage | ThemeUpdateMessage | AuthMessage | ErrorMessage | EventMessage;
964
+
965
+ /**
966
+ * Weld SDK - Logger Utility
967
+ * Centralized logging with configurable levels and formatting
968
+ */
969
+
970
+ /**
971
+ * Log levels
972
+ */
973
+ declare enum LogLevel {
974
+ DEBUG = 0,
975
+ INFO = 1,
976
+ WARN = 2,
977
+ ERROR = 3,
978
+ SILENT = 4
979
+ }
980
+ /**
981
+ * Logger class
982
+ */
983
+ declare class Logger {
984
+ private config;
985
+ private level;
986
+ constructor(config: LogConfig);
987
+ /**
988
+ * Convert string level to LogLevel enum
989
+ */
990
+ private getLevelFromString;
991
+ /**
992
+ * Check if logging is enabled for level
993
+ */
994
+ private shouldLog;
995
+ /**
996
+ * Format log message
997
+ */
998
+ private format;
999
+ /**
1000
+ * Log debug message
1001
+ */
1002
+ debug(message: string, data?: any): void;
1003
+ /**
1004
+ * Log info message
1005
+ */
1006
+ info(message: string, data?: any): void;
1007
+ /**
1008
+ * Log warning message
1009
+ */
1010
+ warn(message: string, data?: any): void;
1011
+ /**
1012
+ * Log error message
1013
+ */
1014
+ error(message: string, error?: Error | any): void;
1015
+ /**
1016
+ * Create child logger with prefix
1017
+ */
1018
+ child(prefix: string): Logger;
1019
+ /**
1020
+ * Update log level at runtime
1021
+ */
1022
+ setLevel(level: 'debug' | 'info' | 'warn' | 'error'): void;
1023
+ /**
1024
+ * Enable/disable logging
1025
+ */
1026
+ setEnabled(enabled: boolean): void;
1027
+ }
1028
+ /**
1029
+ * Default logger instance
1030
+ */
1031
+ declare const defaultLogger: Logger;
1032
+
1033
+ /**
1034
+ * Weld SDK - Message Broker
1035
+ * Handles secure postMessage communication between parent and iframes
1036
+ */
1037
+
1038
+ /**
1039
+ * Message handler callback
1040
+ */
1041
+ type MessageHandler<T = any> = (payload: T, message: PayloadMessage<T>) => void;
1042
+ /**
1043
+ * MessageBroker class
1044
+ * Central hub for all postMessage communication
1045
+ */
1046
+ declare class MessageBroker {
1047
+ private config;
1048
+ private logger;
1049
+ private security;
1050
+ private iframeManager;
1051
+ private subscriptions;
1052
+ private messageQueue;
1053
+ private isReady;
1054
+ private rateLimiter;
1055
+ private responseHandlers;
1056
+ constructor(config: ResolvedConfig, iframeManager: IframeManager, logger: Logger);
1057
+ /**
1058
+ * Setup global message listener
1059
+ */
1060
+ private setupMessageListener;
1061
+ /**
1062
+ * Handle incoming postMessage
1063
+ */
1064
+ private handleMessage;
1065
+ /**
1066
+ * Dispatch message to subscribers
1067
+ */
1068
+ private dispatchMessage;
1069
+ /**
1070
+ * Subscribe to messages
1071
+ */
1072
+ subscribe<T = any>(type: MessageType | '*', handler: MessageHandler<T>, origin?: MessageOrigin): string;
1073
+ /**
1074
+ * Unsubscribe from messages
1075
+ */
1076
+ unsubscribe(subscriptionId: string): void;
1077
+ /**
1078
+ * Send message to iframe
1079
+ */
1080
+ sendToIframe(iframeType: IframeType, type: MessageType, payload?: any): void;
1081
+ /**
1082
+ * Send message to all iframes
1083
+ */
1084
+ broadcast(type: MessageType, payload?: any): void;
1085
+ /**
1086
+ * Send message and wait for response
1087
+ */
1088
+ sendAndWaitForResponse<T = any>(iframeType: IframeType, type: MessageType, payload?: any, timeout?: number): Promise<T>;
1089
+ /**
1090
+ * Post message to iframe
1091
+ */
1092
+ private postMessage;
1093
+ /**
1094
+ * Mark iframe as ready and flush queued messages
1095
+ */
1096
+ setIframeReady(iframeType: IframeType): void;
1097
+ /**
1098
+ * Flush queued messages to iframe
1099
+ */
1100
+ private flushMessageQueue;
1101
+ /**
1102
+ * Check if broker is ready
1103
+ */
1104
+ isMessageBrokerReady(): boolean;
1105
+ /**
1106
+ * Get queued message count
1107
+ */
1108
+ getQueuedMessageCount(): number;
1109
+ /**
1110
+ * Clear message queue
1111
+ */
1112
+ clearMessageQueue(): void;
1113
+ /**
1114
+ * Get active subscription count
1115
+ */
1116
+ getSubscriptionCount(): number;
1117
+ /**
1118
+ * Destroy broker and cleanup
1119
+ */
1120
+ destroy(): void;
1121
+ }
1122
+
1123
+ /**
1124
+ * Weld SDK - State Coordinator
1125
+ * Manages and synchronizes state across iframes
1126
+ */
1127
+
1128
+ /**
1129
+ * StateCoordinator class
1130
+ * Central state management for multi-iframe architecture
1131
+ */
1132
+ declare class StateCoordinator {
1133
+ private state;
1134
+ private logger;
1135
+ private messageBroker;
1136
+ private subscriptions;
1137
+ private stateHistory;
1138
+ private maxHistorySize;
1139
+ constructor(messageBroker: MessageBroker, logger: Logger);
1140
+ /**
1141
+ * Setup message handlers for state updates
1142
+ */
1143
+ private setupMessageHandlers;
1144
+ /**
1145
+ * Handle state update from iframe
1146
+ */
1147
+ private handleStateUpdate;
1148
+ /**
1149
+ * Handle state request from iframe
1150
+ */
1151
+ private handleStateRequest;
1152
+ /**
1153
+ * Get current state
1154
+ */
1155
+ getState(): WeldState;
1156
+ /**
1157
+ * Get state value by path
1158
+ */
1159
+ getValue<T = any>(path: string): T;
1160
+ /**
1161
+ * Update state
1162
+ */
1163
+ updateState(path: string, value: any, merge?: boolean): void;
1164
+ /**
1165
+ * Batch update multiple state paths
1166
+ */
1167
+ batchUpdate(updates: Array<{
1168
+ path: string;
1169
+ value: any;
1170
+ merge?: boolean;
1171
+ }>): void;
1172
+ /**
1173
+ * Reset state to initial
1174
+ */
1175
+ resetState(): void;
1176
+ /**
1177
+ * Subscribe to state changes
1178
+ */
1179
+ subscribe<T = any>(path: string, listener: StateListener<T>, immediate?: boolean): string;
1180
+ /**
1181
+ * Unsubscribe from state changes
1182
+ */
1183
+ unsubscribe(subscriptionId: string): void;
1184
+ /**
1185
+ * Notify subscribers of state change
1186
+ */
1187
+ private notifySubscribers;
1188
+ /**
1189
+ * Add action to history
1190
+ */
1191
+ private addToHistory;
1192
+ /**
1193
+ * Get state history
1194
+ */
1195
+ getHistory(): StateAction[];
1196
+ /**
1197
+ * Clear state history
1198
+ */
1199
+ clearHistory(): void;
1200
+ /**
1201
+ * Get snapshot of state at specific time
1202
+ */
1203
+ getSnapshot(timestamp: number): WeldState | null;
1204
+ /**
1205
+ * Widget-specific state helpers
1206
+ */
1207
+ openWidget(): void;
1208
+ closeWidget(): void;
1209
+ minimizeWidget(): void;
1210
+ maximizeWidget(): void;
1211
+ setBadgeCount(count: number): void;
1212
+ setUserAuth(userId: string, email?: string, name?: string): void;
1213
+ setConnectionStatus(status: string): void;
1214
+ setLoading(isLoading: boolean): void;
1215
+ setError(code: string, message: string, recoverable?: boolean): void;
1216
+ clearError(): void;
1217
+ /**
1218
+ * Get active subscription count
1219
+ */
1220
+ getSubscriptionCount(): number;
1221
+ /**
1222
+ * Validate state integrity
1223
+ */
1224
+ validateState(): boolean;
1225
+ /**
1226
+ * Export state as JSON
1227
+ */
1228
+ exportState(): string;
1229
+ /**
1230
+ * Import state from JSON
1231
+ */
1232
+ importState(json: string): boolean;
1233
+ /**
1234
+ * Destroy coordinator and cleanup
1235
+ */
1236
+ destroy(): void;
1237
+ }
1238
+
1239
+ /**
1240
+ * Weld SDK - Security Utilities
1241
+ * Security validation and origin checking for postMessage communication
1242
+ */
1243
+
1244
+ /**
1245
+ * SecurityManager class
1246
+ */
1247
+ declare class SecurityManager {
1248
+ private config;
1249
+ private logger;
1250
+ private allowedOrigins;
1251
+ constructor(config: SecurityConfig, logger: Logger);
1252
+ /**
1253
+ * Validate message origin
1254
+ */
1255
+ isOriginAllowed(origin: string): boolean;
1256
+ /**
1257
+ * Match origin against pattern (supports wildcards)
1258
+ */
1259
+ private matchesPattern;
1260
+ /**
1261
+ * Validate postMessage event
1262
+ */
1263
+ validateMessageEvent(event: MessageEvent): boolean;
1264
+ /**
1265
+ * Sanitize message data
1266
+ */
1267
+ sanitizeMessageData(data: any): any;
1268
+ /**
1269
+ * Recursively sanitize object properties
1270
+ */
1271
+ private sanitizeObject;
1272
+ /**
1273
+ * Sanitize string to prevent XSS
1274
+ */
1275
+ private sanitizeString;
1276
+ /**
1277
+ * Generate secure random ID
1278
+ */
1279
+ generateSecureId(): string;
1280
+ /**
1281
+ * Validate iframe source
1282
+ */
1283
+ isValidIframeSource(src: string): boolean;
1284
+ /**
1285
+ * Create Content Security Policy
1286
+ */
1287
+ createCSP(): string;
1288
+ /**
1289
+ * Add allowed origin
1290
+ */
1291
+ addAllowedOrigin(origin: string): void;
1292
+ /**
1293
+ * Remove allowed origin
1294
+ */
1295
+ removeAllowedOrigin(origin: string): void;
1296
+ /**
1297
+ * Get all allowed origins
1298
+ */
1299
+ getAllowedOrigins(): string[];
1300
+ }
1301
+ /**
1302
+ * Rate limiting utility
1303
+ */
1304
+ declare class RateLimiter {
1305
+ private requests;
1306
+ private maxRequests;
1307
+ private windowMs;
1308
+ constructor(maxRequests?: number, windowMs?: number);
1309
+ /**
1310
+ * Check if request is allowed
1311
+ */
1312
+ isAllowed(key: string): boolean;
1313
+ /**
1314
+ * Reset rate limit for key
1315
+ */
1316
+ reset(key: string): void;
1317
+ /**
1318
+ * Clear all rate limits
1319
+ */
1320
+ clearAll(): void;
1321
+ }
1322
+ /**
1323
+ * Token validation utilities
1324
+ */
1325
+ declare class TokenValidator {
1326
+ private static readonly TOKEN_PATTERN;
1327
+ /**
1328
+ * Check if string looks like a JWT token
1329
+ */
1330
+ static isJWT(token: string): boolean;
1331
+ /**
1332
+ * Decode JWT payload (without verification)
1333
+ */
1334
+ static decodeJWT(token: string): any | null;
1335
+ /**
1336
+ * Check if JWT is expired
1337
+ */
1338
+ static isExpired(token: string): boolean;
1339
+ }
1340
+
1341
+ /**
1342
+ * Weld SDK - Validation Utilities
1343
+ * Input validation and sanitization functions
1344
+ */
1345
+ /**
1346
+ * Validate email format
1347
+ */
1348
+ declare function isValidEmail(email: string): boolean;
1349
+ /**
1350
+ * Validate URL format
1351
+ */
1352
+ declare function isValidUrl(url: string): boolean;
1353
+ /**
1354
+ * Validate API key format
1355
+ */
1356
+ declare function isValidApiKey(apiKey: string): boolean;
1357
+ /**
1358
+ * Validate workspace ID format
1359
+ */
1360
+ declare function isValidWorkspaceId(workspaceId: string): boolean;
1361
+ /**
1362
+ * Validate color format (hex, rgb, rgba)
1363
+ */
1364
+ declare function isValidColor(color: string): boolean;
1365
+ /**
1366
+ * Validate message text
1367
+ */
1368
+ declare function isValidMessageText(text: string): boolean;
1369
+ /**
1370
+ * Sanitize HTML to prevent XSS
1371
+ */
1372
+ declare function sanitizeHtml(html: string): string;
1373
+ /**
1374
+ * Sanitize user input
1375
+ */
1376
+ declare function sanitizeInput(input: string): string;
1377
+ /**
1378
+ * Validate object has required properties
1379
+ */
1380
+ declare function hasRequiredProperties<T extends Record<string, any>>(obj: any, properties: (keyof T)[]): obj is T;
1381
+ /**
1382
+ * Validate string length
1383
+ */
1384
+ declare function isValidLength(str: string, options: {
1385
+ min?: number;
1386
+ max?: number;
1387
+ }): boolean;
1388
+ /**
1389
+ * Validate number range
1390
+ */
1391
+ declare function isInRange(num: number, options: {
1392
+ min?: number;
1393
+ max?: number;
1394
+ }): boolean;
1395
+ /**
1396
+ * Validate array length
1397
+ */
1398
+ declare function isValidArrayLength<T>(arr: T[], options: {
1399
+ min?: number;
1400
+ max?: number;
1401
+ }): boolean;
1402
+ /**
1403
+ * Deep clone object (safe for JSON-serializable objects)
1404
+ */
1405
+ declare function deepClone<T>(obj: T): T;
1406
+ /**
1407
+ * Check if value is a plain object
1408
+ */
1409
+ declare function isPlainObject(value: any): value is Record<string, any>;
1410
+ /**
1411
+ * Merge objects deeply
1412
+ */
1413
+ declare function deepMerge<T extends Record<string, any>>(target: T, ...sources: Partial<T>[]): T;
1414
+ /**
1415
+ * Validate file type
1416
+ */
1417
+ declare function isValidFileType(file: File, allowedTypes: string[]): boolean;
1418
+ /**
1419
+ * Validate file size
1420
+ */
1421
+ declare function isValidFileSize(file: File, maxSizeBytes: number): boolean;
1422
+ /**
1423
+ * Format file size for display
1424
+ */
1425
+ declare function formatFileSize(bytes: number): string;
1426
+
1427
+ export { ConnectionStatus, DEFAULT_CONFIG, WeldSDK as HelpdeskWidget, IframeManager, IframeType, LogLevel, Logger, MessageBroker, MessageOrigin, MessageStatus, MessageType, RateLimiter, SecurityManager, StateCoordinator, TokenValidator, WeldSDK, WidgetView, WidgetVisibility, createInitialState, createMessage, createWeldSDK, deepClone, deepMerge, WeldSDK as default, defaultLogger, formatFileSize, getStateValue, hasRequiredProperties, createWeldSDK as initHelpdeskWidget, isBaseMessage, isInRange, isPayloadMessage, isPlainObject, isValidApiKey, isValidArrayLength, isValidColor, isValidEmail, isValidFileSize, isValidFileType, isValidLength, isValidMessageText, isValidUrl, isValidWorkspaceId, resolveConfig, sanitizeHtml, sanitizeInput, setStateValue, validateConfig };
1428
+ export type { ApiConfig, Attachment, AuthConfig, AuthPayload, BackdropState, BackdropStatePayload, BaseMessage, ConfigUpdatePayload, ConversationState, CustomizationConfig, DeviceInfo, DeviceType, ErrorPayload, EventPayload, FeatureConfig, WeldConfig as HelpdeskWidgetConfig, IframeConfig, LauncherState, LauncherStatePayload, LocaleConfig, LogConfig, Message, MessageDataPayload, MobileConfig, MobileState, NetworkState, Participant, PayloadMessage, PerformanceConfig, PositionConfig, Reaction, ResolvedConfig, SecurityConfig, StateAction, StateListener, StateSubscription, StateUpdatePayload, ThemeUpdatePayload, UIState, UserState, WeldConfig, WeldMessage, WeldState, WidgetEvent, WidgetEventHandler, WidgetEventType, WidgetState, WidgetStatePayload };