helpdesk-app-framework-sdk 1.0.0

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,2107 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define([], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["BAFClient"] = factory();
8
+ else
9
+ root["BAFClient"] = factory();
10
+ })(Object(typeof self !== "undefined" ? self : this), () => {
11
+ return /******/ (() => { // webpackBootstrap
12
+ /******/ var __webpack_modules__ = ({
13
+
14
+ /***/ "./lib/apis/context.js"
15
+ /*!*****************************!*\
16
+ !*** ./lib/apis/context.js ***!
17
+ \*****************************/
18
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
19
+
20
+ "use strict";
21
+ __webpack_require__.r(__webpack_exports__);
22
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
23
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
24
+ /* harmony export */ });
25
+ /**
26
+ * BoldDesk App Framework - Context API
27
+ * Provides information about the current runtime environment
28
+ */
29
+
30
+ class ContextAPI {
31
+ constructor() {
32
+ let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
33
+ this._data = {
34
+ orgId: data.orgId || null,
35
+ orgName: data.orgName || null,
36
+ brandId: data.brandId || null,
37
+ brandName: data.brandName || null,
38
+ brandUrl: data.brandUrl || null,
39
+ defaultBrandUrl: data.defaultBrandUrl || null,
40
+ planId: data.planId || null,
41
+ planName: data.planName || null,
42
+ module: data.module || null,
43
+ objectId: data.objectId || null,
44
+ product: data.product || 'BoldDesk',
45
+ user: data.user || {
46
+ id: null,
47
+ email: null,
48
+ name: null,
49
+ displayName: null,
50
+ language: null,
51
+ timezone: null
52
+ }
53
+ };
54
+ }
55
+
56
+ /**
57
+ * Get organization ID
58
+ * @returns {string} Organization ID
59
+ */
60
+ getOrgId() {
61
+ return this._data.orgId;
62
+ }
63
+
64
+ /**
65
+ * Get organization name
66
+ * @returns {string} Organization name
67
+ */
68
+ getOrgName() {
69
+ return this._data.orgName;
70
+ }
71
+
72
+ /**
73
+ * Get brand ID
74
+ * @returns {string} Brand ID
75
+ */
76
+ getBrandId() {
77
+ return this._data.brandId;
78
+ }
79
+
80
+ /**
81
+ * Get brand name
82
+ * @returns {string} Brand name
83
+ */
84
+ getBrandName() {
85
+ return this._data.brandName;
86
+ }
87
+
88
+ /**
89
+ * Get brand URL
90
+ * @returns {string} Brand URL
91
+ */
92
+ getBrandUrl() {
93
+ return this._data.brandUrl;
94
+ }
95
+
96
+ /**
97
+ * Get current module (ticket, contact, chat, etc.)
98
+ * @returns {string} Current module
99
+ */
100
+ getModule() {
101
+ return this._data.module;
102
+ }
103
+
104
+ /**
105
+ * Get current object ID in context
106
+ * @returns {string} Object ID
107
+ */
108
+ getObjectId() {
109
+ return this._data.objectId;
110
+ }
111
+
112
+ /**
113
+ * Get current product
114
+ * @returns {string} Product name
115
+ */
116
+ getProduct() {
117
+ return this._data.product;
118
+ }
119
+
120
+ /**
121
+ * Get current user information
122
+ * @returns {Object} User object
123
+ */
124
+ getUser() {
125
+ return this._data.user;
126
+ }
127
+
128
+ /**
129
+ * Get user ID
130
+ * @returns {string} User ID
131
+ */
132
+ getUserId() {
133
+ return this._data.user?.id;
134
+ }
135
+
136
+ /**
137
+ * Get user email
138
+ * @returns {string} User email
139
+ */
140
+ getUserEmail() {
141
+ return this._data.user?.email;
142
+ }
143
+
144
+ /**
145
+ * Get user name
146
+ * @returns {string} User name
147
+ */
148
+ getUserName() {
149
+ return this._data.user?.name;
150
+ }
151
+
152
+ /**
153
+ * Get user language preference
154
+ * @returns {string} Language code (e.g., en-US)
155
+ */
156
+ getUserLanguage() {
157
+ return this._data.user?.language;
158
+ }
159
+
160
+ /**
161
+ * Get user timezone
162
+ * @returns {string} Timezone (e.g., Asia/Kolkata)
163
+ */
164
+ getUserTimezone() {
165
+ return this._data.user?.timezone;
166
+ }
167
+
168
+ /**
169
+ * Get plan information
170
+ * @returns {Object} Plan object with id and name
171
+ */
172
+ getPlan() {
173
+ return {
174
+ id: this._data.planId,
175
+ name: this._data.planName
176
+ };
177
+ }
178
+
179
+ /**
180
+ * Get all context data
181
+ * @returns {Object} Full context object
182
+ */
183
+ getAll() {
184
+ return JSON.parse(JSON.stringify(this._data));
185
+ }
186
+
187
+ /**
188
+ * Update context data (internal use)
189
+ * @param {Object} data - New data to merge
190
+ * @internal
191
+ */
192
+ _updateData(data) {
193
+ Object.assign(this._data, data);
194
+ }
195
+ }
196
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ContextAPI);
197
+
198
+ /***/ },
199
+
200
+ /***/ "./lib/apis/instance.js"
201
+ /*!******************************!*\
202
+ !*** ./lib/apis/instance.js ***!
203
+ \******************************/
204
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
205
+
206
+ "use strict";
207
+ __webpack_require__.r(__webpack_exports__);
208
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
209
+ /* harmony export */ Instance: () => (/* binding */ Instance),
210
+ /* harmony export */ InstanceAPI: () => (/* binding */ InstanceAPI)
211
+ /* harmony export */ });
212
+ /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./lib/utils.js");
213
+ /**
214
+ * BoldDesk App Framework - Instance API
215
+ * Provides access to app instances and instance-level operations
216
+ */
217
+
218
+
219
+ class Instance {
220
+ constructor(id) {
221
+ let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
222
+ this.id = id || (0,_utils__WEBPACK_IMPORTED_MODULE_0__.generateUUID)();
223
+ this.config = config;
224
+ this.widgets = config.widgets || [];
225
+ this.isActive = true;
226
+ }
227
+
228
+ /**
229
+ * Get instance ID
230
+ * @returns {string}
231
+ */
232
+ getId() {
233
+ return this.id;
234
+ }
235
+
236
+ /**
237
+ * Check if instance is active
238
+ * @returns {boolean}
239
+ */
240
+ getIsActive() {
241
+ return this.isActive;
242
+ }
243
+ }
244
+ class InstanceAPI {
245
+ constructor(client) {
246
+ this._client = client;
247
+ this._instances = {};
248
+ this._messageHandlers = {};
249
+ }
250
+
251
+ /**
252
+ * Get current active instance
253
+ * @returns {Instance}
254
+ */
255
+ current() {
256
+ const currentId = this._client._currentInstanceId;
257
+ return this._instances[currentId] || null;
258
+ }
259
+
260
+ /**
261
+ * Get instance by ID
262
+ * @param {string} id - Instance ID
263
+ * @returns {Instance}
264
+ */
265
+ get(id) {
266
+ return this._instances[id] || null;
267
+ }
268
+
269
+ /**
270
+ * Get all active instances
271
+ * @returns {Array} Array of instances
272
+ */
273
+ all() {
274
+ return Object.values(this._instances).filter(inst => inst && inst.getIsActive());
275
+ }
276
+
277
+ /**
278
+ * Create a new instance
279
+ * @param {Object} config - Instance configuration
280
+ * @returns {Promise} Resolves with instance
281
+ */
282
+ create() {
283
+ let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
284
+ return new Promise((resolve, reject) => {
285
+ try {
286
+ const instance = new Instance(null, config);
287
+ this._instances[instance.id] = instance;
288
+
289
+ // Post message to host to register instance
290
+ this._client.postMessage('instance.create', {
291
+ id: instance.id,
292
+ config
293
+ });
294
+ resolve(instance);
295
+ } catch (error) {
296
+ reject(error);
297
+ }
298
+ });
299
+ }
300
+
301
+ /**
302
+ * Send message/data to other instances
303
+ * @param {string|Array} instanceIds - Instance ID or array of IDs
304
+ * @param {string} channel - Channel name
305
+ * @param {*} payload - Data to send
306
+ * @returns {Promise}
307
+ */
308
+ send(instanceIds, channel, payload) {
309
+ return new Promise((resolve, reject) => {
310
+ try {
311
+ const ids = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.isArray)(instanceIds) ? instanceIds : [instanceIds];
312
+ this._client.postMessage('instance.send', {
313
+ instanceIds: ids,
314
+ channel,
315
+ payload
316
+ });
317
+ resolve();
318
+ } catch (error) {
319
+ reject(error);
320
+ }
321
+ });
322
+ }
323
+
324
+ /**
325
+ * Register handler to receive messages from other instances
326
+ * @param {string} channel - Channel name
327
+ * @param {Function} handler - Message handler
328
+ * @returns {void}
329
+ */
330
+ receive(channel, handler) {
331
+ if (!(0,_utils__WEBPACK_IMPORTED_MODULE_0__.isFunction)(handler)) {
332
+ throw new Error('Handler must be a function');
333
+ }
334
+ if (!this._messageHandlers[channel]) {
335
+ this._messageHandlers[channel] = [];
336
+ }
337
+ this._messageHandlers[channel].push(handler);
338
+
339
+ // Inform host about subscription
340
+ this._client.postMessage('instance.receive', {
341
+ channel
342
+ });
343
+ }
344
+
345
+ /**
346
+ * Unregister message handler
347
+ * @param {string} channel - Channel name
348
+ * @param {Function} handler - Optional specific handler to remove
349
+ * @returns {void}
350
+ */
351
+ unreceive(channel, handler) {
352
+ if (!this._messageHandlers[channel]) return;
353
+ if (handler) {
354
+ const index = this._messageHandlers[channel].indexOf(handler);
355
+ if (index > -1) {
356
+ this._messageHandlers[channel].splice(index, 1);
357
+ }
358
+ } else {
359
+ this._messageHandlers[channel] = [];
360
+ }
361
+ }
362
+
363
+ /**
364
+ * Close current instance
365
+ * @returns {Promise}
366
+ */
367
+ close() {
368
+ return new Promise((resolve, reject) => {
369
+ try {
370
+ const instance = this.current();
371
+ if (instance) {
372
+ instance.isActive = false;
373
+ delete this._instances[instance.id];
374
+ }
375
+ this._client.postMessage('instance.close', {
376
+ instanceId: instance?.id
377
+ });
378
+ resolve();
379
+ } catch (error) {
380
+ reject(error);
381
+ }
382
+ });
383
+ }
384
+
385
+ /**
386
+ * Resize widget container
387
+ * @param {number} height - Height in pixels
388
+ * @returns {Promise}
389
+ */
390
+ resize(height) {
391
+ return new Promise((resolve, reject) => {
392
+ if (typeof height !== 'number' || height < 0) {
393
+ return reject(new Error('Height must be a positive number'));
394
+ }
395
+ try {
396
+ this._client.postMessage('instance.resize', {
397
+ height
398
+ });
399
+ resolve();
400
+ } catch (error) {
401
+ reject(error);
402
+ }
403
+ });
404
+ }
405
+
406
+ /**
407
+ * Trigger instance event (for receiving messages)
408
+ * @internal
409
+ * @param {string} channel - Channel name
410
+ * @param {*} payload - Message payload
411
+ */
412
+ _triggerMessage(channel, payload) {
413
+ if (this._messageHandlers[channel]) {
414
+ this._messageHandlers[channel].forEach(handler => {
415
+ try {
416
+ handler(payload);
417
+ } catch (error) {
418
+ console.error(`Error in instance message handler for channel ${channel}:`, error);
419
+ }
420
+ });
421
+ }
422
+ }
423
+
424
+ /**
425
+ * Register instance (internal use)
426
+ * @internal
427
+ * @param {Object} data - Instance data from host
428
+ */
429
+ _registerInstance(data) {
430
+ if (data.id) {
431
+ if (!this._instances[data.id]) {
432
+ this._instances[data.id] = new Instance(data.id, data.config);
433
+ }
434
+ if (data.isCurrent) {
435
+ this._client._currentInstanceId = data.id;
436
+ }
437
+ }
438
+ }
439
+ }
440
+
441
+
442
+ /***/ },
443
+
444
+ /***/ "./lib/apis/metadata.js"
445
+ /*!******************************!*\
446
+ !*** ./lib/apis/metadata.js ***!
447
+ \******************************/
448
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
449
+
450
+ "use strict";
451
+ __webpack_require__.r(__webpack_exports__);
452
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
453
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
454
+ /* harmony export */ });
455
+ /**
456
+ * BoldDesk App Framework - Metadata API
457
+ * Provides app and installation metadata information
458
+ */
459
+
460
+ class MetadataAPI {
461
+ constructor() {
462
+ let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
463
+ this._data = {
464
+ appId: data.appId || null,
465
+ installationId: data.installationId || null,
466
+ appName: data.appName || null,
467
+ version: data.version || null,
468
+ locations: data.locations || [],
469
+ hasAllBrandAccess: data.hasAllBrandAccess || false,
470
+ hasReadAccess: data.hasReadAccess || false,
471
+ hasWriteAccess: data.hasWriteAccess || false,
472
+ isActive: data.isActive || false,
473
+ isEnabled: data.isEnabled || false,
474
+ frameworkVersion: data.frameworkVersion || null,
475
+ installDate: data.installDate || null,
476
+ developer: data.developer || null
477
+ };
478
+ }
479
+
480
+ /**
481
+ * Get app ID
482
+ * @returns {string} App ID
483
+ */
484
+ getAppId() {
485
+ return this._data.appId;
486
+ }
487
+
488
+ /**
489
+ * Get installation ID (unique per installation)
490
+ * @returns {string} Installation ID
491
+ */
492
+ getInstallationId() {
493
+ return this._data.installationId;
494
+ }
495
+
496
+ /**
497
+ * Get app name
498
+ * @returns {string} App name
499
+ */
500
+ getAppName() {
501
+ return this._data.appName;
502
+ }
503
+
504
+ /**
505
+ * Get app version
506
+ * @returns {string} Version (semantic versioning)
507
+ */
508
+ getVersion() {
509
+ return this._data.version;
510
+ }
511
+
512
+ /**
513
+ * Get widget locations where app is available
514
+ * @returns {Array} Array of location strings
515
+ */
516
+ getLocations() {
517
+ return Array.from(this._data.locations);
518
+ }
519
+
520
+ /**
521
+ * Check if app has all brand access
522
+ * @returns {boolean}
523
+ */
524
+ hasAllBrandAccess() {
525
+ return this._data.hasAllBrandAccess === true;
526
+ }
527
+
528
+ /**
529
+ * Check if app has read permissions
530
+ * @returns {boolean}
531
+ */
532
+ hasReadAccess() {
533
+ return this._data.hasReadAccess === true;
534
+ }
535
+
536
+ /**
537
+ * Check if app has write permissions
538
+ * @returns {boolean}
539
+ */
540
+ hasWriteAccess() {
541
+ return this._data.hasWriteAccess === true;
542
+ }
543
+
544
+ /**
545
+ * Check if app is active
546
+ * @returns {boolean}
547
+ */
548
+ isActive() {
549
+ return this._data.isActive === true;
550
+ }
551
+
552
+ /**
553
+ * Check if app is enabled
554
+ * @returns {boolean}
555
+ */
556
+ isEnabled() {
557
+ return this._data.isEnabled === true;
558
+ }
559
+
560
+ /**
561
+ * Get framework version
562
+ * @returns {string} Framework version
563
+ */
564
+ getFrameworkVersion() {
565
+ return this._data.frameworkVersion;
566
+ }
567
+
568
+ /**
569
+ * Get installation date
570
+ * @returns {string} ISO date string
571
+ */
572
+ getInstallDate() {
573
+ return this._data.installDate;
574
+ }
575
+
576
+ /**
577
+ * Get developer information
578
+ * @returns {Object} Developer object
579
+ */
580
+ getDeveloper() {
581
+ return this._data.developer ? JSON.parse(JSON.stringify(this._data.developer)) : null;
582
+ }
583
+
584
+ /**
585
+ * Check if location is supported
586
+ * @param {string} location - Location to check
587
+ * @returns {boolean}
588
+ */
589
+ isLocationSupported(location) {
590
+ return this._data.locations.includes(location);
591
+ }
592
+
593
+ /**
594
+ * Get all metadata
595
+ * @returns {Object} Full metadata object
596
+ */
597
+ getAll() {
598
+ return JSON.parse(JSON.stringify(this._data));
599
+ }
600
+
601
+ /**
602
+ * Update metadata (internal use)
603
+ * @param {Object} data - New data to merge
604
+ * @internal
605
+ */
606
+ _updateData(data) {
607
+ Object.assign(this._data, data);
608
+ }
609
+ }
610
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (MetadataAPI);
611
+
612
+ /***/ },
613
+
614
+ /***/ "./lib/apis/request.js"
615
+ /*!*****************************!*\
616
+ !*** ./lib/apis/request.js ***!
617
+ \*****************************/
618
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
619
+
620
+ "use strict";
621
+ __webpack_require__.r(__webpack_exports__);
622
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
623
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
624
+ /* harmony export */ });
625
+ /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./lib/utils.js");
626
+ /**
627
+ * BoldDesk App Framework - Request API (Proxy)
628
+ * Provides secure HTTP request capability through server-side proxy
629
+ */
630
+
631
+
632
+ class RequestAPI {
633
+ constructor(client) {
634
+ this._client = client;
635
+ }
636
+
637
+ /**
638
+ * Make an HTTP request through BoldDesk proxy
639
+ * Prevents exposing sensitive data and handles CORS automatically
640
+ *
641
+ * @param {Object} options - Request options
642
+ * @param {string} options.url - Full URL of the API endpoint (required)
643
+ * @param {string} options.method - HTTP method (GET, POST, PUT, DELETE, PATCH) (required)
644
+ * @param {Object} options.headers - HTTP headers (optional)
645
+ * @param {Object} options.params - Query parameters (optional)
646
+ * @param {Object|string} options.body - Request payload (optional, for POST/PUT/PATCH)
647
+ * @param {number} options.timeout - Request timeout in ms (optional, default: 15000, max: 30000)
648
+ * @param {boolean} options.autoRetry - Auto-retry on 429/5xx (optional, default: true)
649
+ * @param {number} options.maxRetry - Max retry attempts (optional, default: 3)
650
+ * @param {number} options.retryDelay - Delay between retries in ms (optional, default: 1000)
651
+ *
652
+ * @returns {Promise} Resolves with response object { status, statusText, headers, data, body }
653
+ *
654
+ * @example
655
+ * // Simple GET request
656
+ * sdk.request({
657
+ * url: 'https://api.example.com/users',
658
+ * method: 'GET'
659
+ * }).then(response => console.log(response.data))
660
+ *
661
+ * @example
662
+ * // POST with data
663
+ * sdk.request({
664
+ * url: 'https://api.example.com/tickets',
665
+ * method: 'POST',
666
+ * headers: { 'Content-Type': 'application/json' },
667
+ * body: JSON.stringify({ subject: 'Help needed', priority: 'high' })
668
+ * })
669
+ *
670
+ * @example
671
+ * // Using secure settings placeholders
672
+ * sdk.request({
673
+ * url: 'https://api.example.com/secure-endpoint',
674
+ * method: 'GET',
675
+ * headers: { 'Authorization': 'Bearer {{setting.api_key}}' }
676
+ * })
677
+ */
678
+ request() {
679
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
680
+ return new Promise((resolve, reject) => {
681
+ try {
682
+ // Validate required options
683
+ if (!options.url) {
684
+ throw new Error('Request URL is required');
685
+ }
686
+ if (!options.method) {
687
+ throw new Error('Request method is required');
688
+ }
689
+
690
+ // Validate URL format
691
+ if (!(0,_utils__WEBPACK_IMPORTED_MODULE_0__.isValidUrl)(options.url)) {
692
+ throw new Error('Invalid URL format: ' + options.url);
693
+ }
694
+
695
+ // Validate method
696
+ const validMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
697
+ const method = (options.method || 'GET').toUpperCase();
698
+ if (!validMethods.includes(method)) {
699
+ throw new Error('Invalid HTTP method: ' + method);
700
+ }
701
+
702
+ // Build request object
703
+ const requestObj = {
704
+ url: options.url,
705
+ method,
706
+ headers: options.headers || {},
707
+ timeout: Math.min(options.timeout || 15000, 30000),
708
+ autoRetry: options.autoRetry !== false,
709
+ maxRetry: options.maxRetry || 3,
710
+ retryDelay: options.retryDelay || 1000
711
+ };
712
+
713
+ // Add query parameters if provided
714
+ if (options.params && (0,_utils__WEBPACK_IMPORTED_MODULE_0__.isObject)(options.params)) {
715
+ const params = new URLSearchParams(options.params);
716
+ const separator = options.url.includes('?') ? '&' : '?';
717
+ requestObj.url += separator + params.toString();
718
+ }
719
+
720
+ // Add body for POST/PUT/PATCH
721
+ if (['POST', 'PUT', 'PATCH'].includes(method)) {
722
+ if (options.body) {
723
+ requestObj.body = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.isObject)(options.body) ? JSON.stringify(options.body) : options.body;
724
+ }
725
+ }
726
+
727
+ // Send request through BoldDesk proxy
728
+ this._client.postMessage('request.send', requestObj, response => {
729
+ if (response.error) {
730
+ reject(new Error(response.error));
731
+ } else {
732
+ resolve(response);
733
+ }
734
+ });
735
+ } catch (error) {
736
+ reject(error);
737
+ }
738
+ });
739
+ }
740
+
741
+ /**
742
+ * Make a GET request
743
+ * @param {string} url - URL endpoint
744
+ * @param {Object} options - Additional options
745
+ * @returns {Promise}
746
+ */
747
+ get(url) {
748
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
749
+ return this.request({
750
+ ...options,
751
+ url,
752
+ method: 'GET'
753
+ });
754
+ }
755
+
756
+ /**
757
+ * Make a POST request
758
+ * @param {string} url - URL endpoint
759
+ * @param {*} body - Request body
760
+ * @param {Object} options - Additional options
761
+ * @returns {Promise}
762
+ */
763
+ post(url, body) {
764
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
765
+ return this.request({
766
+ ...options,
767
+ url,
768
+ method: 'POST',
769
+ body
770
+ });
771
+ }
772
+
773
+ /**
774
+ * Make a PUT request
775
+ * @param {string} url - URL endpoint
776
+ * @param {*} body - Request body
777
+ * @param {Object} options - Additional options
778
+ * @returns {Promise}
779
+ */
780
+ put(url, body) {
781
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
782
+ return this.request({
783
+ ...options,
784
+ url,
785
+ method: 'PUT',
786
+ body
787
+ });
788
+ }
789
+
790
+ /**
791
+ * Make a PATCH request
792
+ * @param {string} url - URL endpoint
793
+ * @param {*} body - Request body
794
+ * @param {Object} options - Additional options
795
+ * @returns {Promise}
796
+ */
797
+ patch(url, body) {
798
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
799
+ return this.request({
800
+ ...options,
801
+ url,
802
+ method: 'PATCH',
803
+ body
804
+ });
805
+ }
806
+
807
+ /**
808
+ * Make a DELETE request
809
+ * @param {string} url - URL endpoint
810
+ * @param {Object} options - Additional options
811
+ * @returns {Promise}
812
+ */
813
+ delete(url) {
814
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
815
+ return this.request({
816
+ ...options,
817
+ url,
818
+ method: 'DELETE'
819
+ });
820
+ }
821
+ }
822
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (RequestAPI);
823
+
824
+ /***/ },
825
+
826
+ /***/ "./lib/client.js"
827
+ /*!***********************!*\
828
+ !*** ./lib/client.js ***!
829
+ \***********************/
830
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
831
+
832
+ "use strict";
833
+ __webpack_require__.r(__webpack_exports__);
834
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
835
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
836
+ /* harmony export */ });
837
+ /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils */ "./lib/utils.js");
838
+ /* harmony import */ var _apis_context__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./apis/context */ "./lib/apis/context.js");
839
+ /* harmony import */ var _apis_metadata__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./apis/metadata */ "./lib/apis/metadata.js");
840
+ /* harmony import */ var _apis_instance__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./apis/instance */ "./lib/apis/instance.js");
841
+ /* harmony import */ var _apis_request__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./apis/request */ "./lib/apis/request.js");
842
+ /* harmony import */ var native_promise_only__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! native-promise-only */ "./node_modules/native-promise-only/lib/npo.src.js");
843
+ /* harmony import */ var native_promise_only__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(native_promise_only__WEBPACK_IMPORTED_MODULE_5__);
844
+ /**
845
+ * BoldDesk App Framework - Client SDK
846
+ * Core client for cross-frame communication and data access
847
+ */
848
+
849
+
850
+
851
+
852
+
853
+
854
+
855
+ const Promise = window.Promise || (native_promise_only__WEBPACK_IMPORTED_MODULE_5___default());
856
+
857
+ // Constants
858
+ const IFRAME_SESSION_TIMEOUT = 5 * 60 * 1000;
859
+ const PROMISE_TIMEOUT = 10000;
860
+ const PROMISE_TIMEOUT_LONG = 5 * 60 * 1000;
861
+ class Client {
862
+ constructor() {
863
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
864
+ this.origin = options.origin;
865
+ this.appGuid = options.appGuid;
866
+
867
+ // Initialize state
868
+ this._isReady = false;
869
+ this._messageQueue = [];
870
+ this._pendingRequests = {};
871
+ this._eventListeners = {};
872
+ this._requestId = 0;
873
+ this._currentInstanceId = null;
874
+
875
+ // Initialize APIs
876
+ this.context = new _apis_context__WEBPACK_IMPORTED_MODULE_1__["default"]();
877
+ this.metadata = new _apis_metadata__WEBPACK_IMPORTED_MODULE_2__["default"]();
878
+ this.instance = new _apis_instance__WEBPACK_IMPORTED_MODULE_3__.InstanceAPI(this);
879
+ this.request = new _apis_request__WEBPACK_IMPORTED_MODULE_4__["default"](this);
880
+
881
+ // Bind message handler
882
+ this._handleMessage = this._handleMessage.bind(this);
883
+ window.addEventListener('message', this._handleMessage);
884
+
885
+ // Register with host
886
+ this._registerWithHost();
887
+ }
888
+
889
+ /**
890
+ * Register app with BoldDesk host
891
+ * @private
892
+ */
893
+ _registerWithHost() {
894
+ this.postMessage('app.register', {
895
+ appGuid: this.appGuid,
896
+ version: '1.0.0'
897
+ });
898
+ }
899
+
900
+ /**
901
+ * Post message to host frame
902
+ * @param {string} action - Action name
903
+ * @param {*} data - Data payload
904
+ * @param {Function} callback - Optional callback
905
+ * @private
906
+ */
907
+ postMessage(action, data, callback) {
908
+ const requestId = ++this._requestId;
909
+ if (callback && (0,_utils__WEBPACK_IMPORTED_MODULE_0__.isFunction)(callback)) {
910
+ this._pendingRequests[requestId] = callback;
911
+ }
912
+ const message = {
913
+ type: 'baf.request',
914
+ action,
915
+ data,
916
+ requestId,
917
+ appGuid: this.appGuid,
918
+ timestamp: Date.now()
919
+ };
920
+ if (this._isReady) {
921
+ window.parent.postMessage(message, this.origin);
922
+ } else {
923
+ this._messageQueue.push(message);
924
+ }
925
+ }
926
+
927
+ /**
928
+ * Handle incoming messages from host
929
+ * @private
930
+ */
931
+ _handleMessage(event) {
932
+ if (event.origin !== this.origin) return;
933
+ const message = event.data;
934
+ if (!message || message.type !== 'baf.response') return;
935
+
936
+ // Handle app registration
937
+ if (message.action === 'app.registered') {
938
+ this._isReady = true;
939
+ this._processMessageQueue();
940
+ this._handleAppRegistered(message.data);
941
+ return;
942
+ }
943
+
944
+ // Handle pending request responses
945
+ if (message.requestId && this._pendingRequests[message.requestId]) {
946
+ const callback = this._pendingRequests[message.requestId];
947
+ delete this._pendingRequests[message.requestId];
948
+ callback(message.data);
949
+ return;
950
+ }
951
+
952
+ // Handle events
953
+ if (message.action === 'event') {
954
+ this._handleEvent(message.eventName, message.data);
955
+ return;
956
+ }
957
+
958
+ // Handle instance messages
959
+ if (message.action === 'instance.message') {
960
+ this.instance._triggerMessage(message.channel, message.payload);
961
+ return;
962
+ }
963
+
964
+ // Handle instance registration
965
+ if (message.action === 'instance.registered') {
966
+ this.instance._registerInstance(message.data);
967
+ return;
968
+ }
969
+ }
970
+
971
+ /**
972
+ * Handle app registration from host
973
+ * @private
974
+ */
975
+ _handleAppRegistered(data) {
976
+ if (data.context) {
977
+ this.context._updateData(data.context);
978
+ }
979
+ if (data.metadata) {
980
+ this.metadata._updateData(data.metadata);
981
+ }
982
+ if (data.instanceId) {
983
+ this._currentInstanceId = data.instanceId;
984
+ }
985
+
986
+ // Emit app.registered event
987
+ this._emitEvent('app.registered', {
988
+ context: this.context.getAll(),
989
+ metadata: this.metadata.getAll()
990
+ });
991
+ }
992
+
993
+ /**
994
+ * Process queued messages
995
+ * @private
996
+ */
997
+ _processMessageQueue() {
998
+ while (this._messageQueue.length > 0) {
999
+ const message = this._messageQueue.shift();
1000
+ window.parent.postMessage(message, this.origin);
1001
+ }
1002
+ }
1003
+
1004
+ /**
1005
+ * Get data from platform context
1006
+ * Retrieves data like ticket info, user info, etc.
1007
+ *
1008
+ * @param {string|Array} path - Data path or array of paths
1009
+ * @returns {Promise} Resolves with requested data
1010
+ *
1011
+ * @example
1012
+ * // Get single value
1013
+ * sdk.get('ticket.subject').then(data => {
1014
+ * console.log(data['ticket.subject']);
1015
+ * });
1016
+ *
1017
+ * @example
1018
+ * // Get multiple values
1019
+ * sdk.get(['ticket.subject', 'ticket.requester.email']).then(data => {
1020
+ * console.log(data['ticket.subject']);
1021
+ * console.log(data['ticket.requester.email']);
1022
+ * });
1023
+ */
1024
+ get(path) {
1025
+ return new Promise((resolve, reject) => {
1026
+ if (!path) {
1027
+ return reject(new Error('Path is required for get() method'));
1028
+ }
1029
+ try {
1030
+ const paths = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.isArray)(path) ? path : [path];
1031
+ this.postMessage('data.get', {
1032
+ paths
1033
+ }, response => {
1034
+ if (response.error) {
1035
+ reject(new Error(response.error));
1036
+ } else {
1037
+ resolve(response.data || {});
1038
+ }
1039
+ });
1040
+ } catch (error) {
1041
+ reject(error);
1042
+ }
1043
+ });
1044
+ }
1045
+
1046
+ /**
1047
+ * Set data in platform context
1048
+ * Updates or stores data like ticket properties, custom fields, etc.
1049
+ *
1050
+ * @param {string} path - Data path to update
1051
+ * @param {*} value - Value to set
1052
+ * @returns {Promise} Resolves when data is set
1053
+ *
1054
+ * @example
1055
+ * sdk.set('ticket.subject', 'Issue Resolved').then(() => {
1056
+ * console.log('Subject updated');
1057
+ * });
1058
+ */
1059
+ set(path, value) {
1060
+ return new Promise((resolve, reject) => {
1061
+ if (!path) {
1062
+ return reject(new Error('Path is required for set() method'));
1063
+ }
1064
+ try {
1065
+ this.postMessage('data.set', {
1066
+ path,
1067
+ value
1068
+ }, response => {
1069
+ if (response.error) {
1070
+ reject(new Error(response.error));
1071
+ } else {
1072
+ resolve();
1073
+ }
1074
+ });
1075
+ } catch (error) {
1076
+ reject(error);
1077
+ }
1078
+ });
1079
+ }
1080
+
1081
+ /**
1082
+ * Register event listener
1083
+ * Listen for platform events like data changes, UI events, etc.
1084
+ *
1085
+ * @param {string} eventName - Event name to listen for
1086
+ * @param {Function} callback - Handler function
1087
+ * @returns {void}
1088
+ *
1089
+ * @example
1090
+ * sdk.on('ticket.updated', (ticket) => {
1091
+ * console.log('Ticket updated:', ticket);
1092
+ * });
1093
+ */
1094
+ on(eventName, callback) {
1095
+ if (!(0,_utils__WEBPACK_IMPORTED_MODULE_0__.isString)(eventName) || !(0,_utils__WEBPACK_IMPORTED_MODULE_0__.isFunction)(callback)) {
1096
+ throw new Error('on() requires eventName (string) and callback (function)');
1097
+ }
1098
+ if (!this._eventListeners[eventName]) {
1099
+ this._eventListeners[eventName] = [];
1100
+ this.postMessage('event.register', {
1101
+ eventName
1102
+ });
1103
+ }
1104
+ this._eventListeners[eventName].push(callback);
1105
+ }
1106
+
1107
+ /**
1108
+ * Unregister event listener
1109
+ * Stop listening for platform events
1110
+ *
1111
+ * @param {string} eventName - Event name
1112
+ * @param {Function} callback - Optional specific handler to remove
1113
+ * @returns {void}
1114
+ *
1115
+ * @example
1116
+ * sdk.off('ticket.updated');
1117
+ */
1118
+ off(eventName, callback) {
1119
+ if (!this._eventListeners[eventName]) return;
1120
+ if (callback && (0,_utils__WEBPACK_IMPORTED_MODULE_0__.isFunction)(callback)) {
1121
+ const index = this._eventListeners[eventName].indexOf(callback);
1122
+ if (index > -1) {
1123
+ this._eventListeners[eventName].splice(index, 1);
1124
+ }
1125
+ } else {
1126
+ this._eventListeners[eventName] = [];
1127
+ }
1128
+
1129
+ // Unregister from host if no more listeners
1130
+ if (this._eventListeners[eventName].length === 0) {
1131
+ this.postMessage('event.unregister', {
1132
+ eventName
1133
+ });
1134
+ }
1135
+ }
1136
+
1137
+ /**
1138
+ * Invoke a platform action or method
1139
+ * Execute platform-exposed methods like opening modals, etc.
1140
+ *
1141
+ * @param {string} methodName - Method name to invoke
1142
+ * @param {*} payload - Optional data for the method
1143
+ * @returns {Promise} Resolves with method result
1144
+ *
1145
+ * @example
1146
+ * sdk.invoke('modal.open', {
1147
+ * title: 'Contact Details',
1148
+ * content: 'View full contact information'
1149
+ * });
1150
+ */
1151
+ invoke(methodName, payload) {
1152
+ return new Promise((resolve, reject) => {
1153
+ if (!(0,_utils__WEBPACK_IMPORTED_MODULE_0__.isString)(methodName)) {
1154
+ return reject(new Error('Method name is required'));
1155
+ }
1156
+ try {
1157
+ this.postMessage('action.invoke', {
1158
+ methodName,
1159
+ payload
1160
+ }, response => {
1161
+ if (response.error) {
1162
+ reject(new Error(response.error));
1163
+ } else {
1164
+ resolve(response.result);
1165
+ }
1166
+ });
1167
+ } catch (error) {
1168
+ reject(error);
1169
+ }
1170
+ });
1171
+ }
1172
+
1173
+ /**
1174
+ * Trigger a custom event
1175
+ * Emit custom events to the platform or other app components
1176
+ *
1177
+ * @param {string} eventName - Event name
1178
+ * @param {*} data - Event data
1179
+ * @returns {void}
1180
+ *
1181
+ * @example
1182
+ * sdk.trigger('custom.notification', {
1183
+ * message: 'Data saved successfully'
1184
+ * });
1185
+ */
1186
+ trigger(eventName, data) {
1187
+ if (!(0,_utils__WEBPACK_IMPORTED_MODULE_0__.isString)(eventName)) {
1188
+ throw new Error('Event name must be a string');
1189
+ }
1190
+ this.postMessage('event.trigger', {
1191
+ eventName,
1192
+ data
1193
+ });
1194
+
1195
+ // Also emit locally
1196
+ this._emitEvent(eventName, data);
1197
+ }
1198
+
1199
+ /**
1200
+ * Check if capability or value exists
1201
+ * Verify availability of features or data paths
1202
+ *
1203
+ * @param {string} name - Capability or value name
1204
+ * @returns {Promise} Resolves with boolean
1205
+ *
1206
+ * @example
1207
+ * sdk.has('ticket.custom_field_123').then(exists => {
1208
+ * if (exists) {
1209
+ * console.log('Custom field is available');
1210
+ * }
1211
+ * });
1212
+ */
1213
+ has(name) {
1214
+ return new Promise((resolve, reject) => {
1215
+ if (!(0,_utils__WEBPACK_IMPORTED_MODULE_0__.isString)(name)) {
1216
+ return reject(new Error('Name must be a string'));
1217
+ }
1218
+ try {
1219
+ this.postMessage('capability.check', {
1220
+ name
1221
+ }, response => {
1222
+ resolve(response.exists === true);
1223
+ });
1224
+ } catch (error) {
1225
+ reject(error);
1226
+ }
1227
+ });
1228
+ }
1229
+
1230
+ /**
1231
+ * Internal: Emit event to local listeners
1232
+ * @private
1233
+ */
1234
+ _emitEvent(eventName, data) {
1235
+ if (this._eventListeners[eventName]) {
1236
+ this._eventListeners[eventName].forEach(callback => {
1237
+ try {
1238
+ callback(data);
1239
+ } catch (error) {
1240
+ console.error(`Error in event listener for ${eventName}:`, error);
1241
+ }
1242
+ });
1243
+ }
1244
+ }
1245
+
1246
+ /**
1247
+ * Internal: Handle incoming event from host
1248
+ * @private
1249
+ */
1250
+ _handleEvent(eventName, data) {
1251
+ this._emitEvent(eventName, data);
1252
+ }
1253
+
1254
+ /**
1255
+ * Destroy client and clean up
1256
+ * @returns {void}
1257
+ */
1258
+ destroy() {
1259
+ window.removeEventListener('message', this._handleMessage);
1260
+ this._eventListeners = {};
1261
+ this._pendingRequests = {};
1262
+ this._messageQueue = [];
1263
+ this._isReady = false;
1264
+ }
1265
+ }
1266
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Client);
1267
+
1268
+ /***/ },
1269
+
1270
+ /***/ "./lib/utils.js"
1271
+ /*!**********************!*\
1272
+ !*** ./lib/utils.js ***!
1273
+ \**********************/
1274
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1275
+
1276
+ "use strict";
1277
+ __webpack_require__.r(__webpack_exports__);
1278
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1279
+ /* harmony export */ debounce: () => (/* binding */ debounce),
1280
+ /* harmony export */ deepClone: () => (/* binding */ deepClone),
1281
+ /* harmony export */ deepMerge: () => (/* binding */ deepMerge),
1282
+ /* harmony export */ formatError: () => (/* binding */ formatError),
1283
+ /* harmony export */ generateUUID: () => (/* binding */ generateUUID),
1284
+ /* harmony export */ isArray: () => (/* binding */ isArray),
1285
+ /* harmony export */ isFunction: () => (/* binding */ isFunction),
1286
+ /* harmony export */ isNull: () => (/* binding */ isNull),
1287
+ /* harmony export */ isObject: () => (/* binding */ isObject),
1288
+ /* harmony export */ isString: () => (/* binding */ isString),
1289
+ /* harmony export */ isUndefined: () => (/* binding */ isUndefined),
1290
+ /* harmony export */ isValidUrl: () => (/* binding */ isValidUrl),
1291
+ /* harmony export */ parseWidgetLocations: () => (/* binding */ parseWidgetLocations),
1292
+ /* harmony export */ queryParameters: () => (/* binding */ queryParameters),
1293
+ /* harmony export */ throttle: () => (/* binding */ throttle),
1294
+ /* harmony export */ validateManifest: () => (/* binding */ validateManifest),
1295
+ /* harmony export */ when: () => (/* binding */ when)
1296
+ /* harmony export */ });
1297
+ /**
1298
+ * BoldDesk App Framework - Utility Functions
1299
+ * Provides helper functions for common operations
1300
+ */
1301
+
1302
+ /**
1303
+ * Query string parser
1304
+ * @param {string} queryString - Query string to parse (with or without ?)
1305
+ * @returns {Object} Parsed parameters
1306
+ */
1307
+ function queryParameters(queryString) {
1308
+ const params = {};
1309
+ if (!queryString) return params;
1310
+ const cleaned = queryString.replace(/^\?|^#/, '');
1311
+ if (!cleaned) return params;
1312
+ cleaned.split('&').forEach(pair => {
1313
+ const [key, value] = pair.split('=');
1314
+ if (key) {
1315
+ params[decodeURIComponent(key)] = value ? decodeURIComponent(value) : true;
1316
+ }
1317
+ });
1318
+ return params;
1319
+ }
1320
+
1321
+ /**
1322
+ * Promise utility - when all conditions are met
1323
+ * @param {Array} promises - Array of promises to wait for
1324
+ * @returns {Promise}
1325
+ */
1326
+ function when(promises) {
1327
+ return Promise.all(promises);
1328
+ }
1329
+
1330
+ /**
1331
+ * Type checking utilities
1332
+ */
1333
+ const isObject = obj => Object.prototype.toString.call(obj) === '[object Object]';
1334
+ const isString = str => typeof str === 'string';
1335
+ const isArray = arr => Array.isArray(arr);
1336
+ const isFunction = fn => typeof fn === 'function';
1337
+ const isUndefined = val => typeof val === 'undefined';
1338
+ const isNull = val => val === null;
1339
+
1340
+ /**
1341
+ * Debounce function - delays execution
1342
+ * @param {Function} fn - Function to debounce
1343
+ * @param {number} delay - Delay in milliseconds
1344
+ * @returns {Function} Debounced function
1345
+ */
1346
+ function debounce(fn, delay) {
1347
+ let timeoutId;
1348
+ return function () {
1349
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1350
+ args[_key] = arguments[_key];
1351
+ }
1352
+ clearTimeout(timeoutId);
1353
+ timeoutId = setTimeout(() => fn.apply(this, args), delay);
1354
+ };
1355
+ }
1356
+
1357
+ /**
1358
+ * Throttle function - rate limits execution
1359
+ * @param {Function} fn - Function to throttle
1360
+ * @param {number} limit - Time limit in milliseconds
1361
+ * @returns {Function} Throttled function
1362
+ */
1363
+ function throttle(fn, limit) {
1364
+ let inThrottle;
1365
+ return function () {
1366
+ if (!inThrottle) {
1367
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1368
+ args[_key2] = arguments[_key2];
1369
+ }
1370
+ fn.apply(this, args);
1371
+ inThrottle = true;
1372
+ setTimeout(() => inThrottle = false, limit);
1373
+ }
1374
+ };
1375
+ }
1376
+
1377
+ /**
1378
+ * Deep clone an object
1379
+ * @param {*} obj - Object to clone
1380
+ * @returns {*} Cloned object
1381
+ */
1382
+ function deepClone(obj) {
1383
+ if (obj === null || typeof obj !== 'object') return obj;
1384
+ if (obj instanceof Date) return new Date(obj.getTime());
1385
+ if (obj instanceof Array) return obj.map(item => deepClone(item));
1386
+ if (obj instanceof Object) {
1387
+ const cloned = {};
1388
+ for (const key in obj) {
1389
+ if (obj.hasOwnProperty(key)) {
1390
+ cloned[key] = deepClone(obj[key]);
1391
+ }
1392
+ }
1393
+ return cloned;
1394
+ }
1395
+ }
1396
+
1397
+ /**
1398
+ * Merge objects deeply
1399
+ * @param {Object} target - Target object
1400
+ * @param {Object} source - Source object
1401
+ * @returns {Object} Merged object
1402
+ */
1403
+ function deepMerge(target, source) {
1404
+ const result = {
1405
+ ...target
1406
+ };
1407
+ for (const key in source) {
1408
+ if (source.hasOwnProperty(key)) {
1409
+ if (isObject(source[key]) && isObject(result[key])) {
1410
+ result[key] = deepMerge(result[key], source[key]);
1411
+ } else {
1412
+ result[key] = deepClone(source[key]);
1413
+ }
1414
+ }
1415
+ }
1416
+ return result;
1417
+ }
1418
+
1419
+ /**
1420
+ * UUID v4 generator
1421
+ * @returns {string} Generated UUID
1422
+ */
1423
+ function generateUUID() {
1424
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
1425
+ const r = Math.random() * 16 | 0;
1426
+ const v = c === 'x' ? r : r & 0x3 | 0x8;
1427
+ return v.toString(16);
1428
+ });
1429
+ }
1430
+
1431
+ /**
1432
+ * Validate manifest fields
1433
+ * @param {Object} manifest - Manifest object to validate
1434
+ * @returns {Object} Validation result { valid: boolean, errors: Array }
1435
+ */
1436
+ function validateManifest(manifest) {
1437
+ const errors = [];
1438
+ if (!manifest.name) errors.push('Manifest field "name" is required');
1439
+ if (!manifest.version) errors.push('Manifest field "version" is required');
1440
+ if (!manifest.frameworkVersion) errors.push('Manifest field "frameworkVersion" is required');
1441
+ if (!manifest.product) errors.push('Manifest field "product" is required');
1442
+ if (manifest.developer) {
1443
+ const dev = manifest.developer;
1444
+ if (!dev.name) errors.push('Developer field "name" is required');
1445
+ if (!dev.contactEmail) errors.push('Developer field "contactEmail" is required');
1446
+ if (!dev.supportEmail) errors.push('Developer field "supportEmail" is required');
1447
+ } else {
1448
+ errors.push('Manifest field "developer" is required');
1449
+ }
1450
+ if (!Array.isArray(manifest.trustedDomains)) {
1451
+ errors.push('Manifest field "trustedDomains" must be an array');
1452
+ }
1453
+ return {
1454
+ valid: errors.length === 0,
1455
+ errors
1456
+ };
1457
+ }
1458
+
1459
+ /**
1460
+ * Parse widget locations to ensure valid format
1461
+ * @param {Array} locations - Widget locations from manifest
1462
+ * @returns {Array} Parsed locations
1463
+ */
1464
+ function parseWidgetLocations(locations) {
1465
+ const validLocations = ['desk.menu.left', 'desk.ticket.view.rightpanel', 'desk.contact.view.rightpanel', 'desk.contactgroup.view.rightpanel', 'desk.chat.view.rightpanel', 'desk.cti.widget'];
1466
+ return locations.filter(loc => validLocations.includes(loc));
1467
+ }
1468
+
1469
+ /**
1470
+ * Validate URL format
1471
+ * @param {string} url - URL to validate
1472
+ * @returns {boolean} Is valid URL
1473
+ */
1474
+ function isValidUrl(url) {
1475
+ try {
1476
+ new URL(url);
1477
+ return true;
1478
+ } catch (e) {
1479
+ return false;
1480
+ }
1481
+ }
1482
+
1483
+ /**
1484
+ * Format error message for logging
1485
+ * @param {string} context - Context of error
1486
+ * @param {Error} error - Error object
1487
+ * @returns {string} Formatted error message
1488
+ */
1489
+ function formatError(context, error) {
1490
+ return `[${context}] ${error.message || error}`;
1491
+ }
1492
+
1493
+ /***/ },
1494
+
1495
+ /***/ "./node_modules/native-promise-only/lib/npo.src.js"
1496
+ /*!*********************************************************!*\
1497
+ !*** ./node_modules/native-promise-only/lib/npo.src.js ***!
1498
+ \*********************************************************/
1499
+ (module, exports, __webpack_require__) {
1500
+
1501
+ var __WEBPACK_AMD_DEFINE_RESULT__;/*! Native Promise Only
1502
+ v0.8.1 (c) Kyle Simpson
1503
+ MIT License: http://getify.mit-license.org
1504
+ */
1505
+
1506
+ (function UMD(name,context,definition){
1507
+ // special form of UMD for polyfilling across evironments
1508
+ context[name] = context[name] || definition();
1509
+ if ( true && module.exports) { module.exports = context[name]; }
1510
+ else if (true) { !(__WEBPACK_AMD_DEFINE_RESULT__ = (function $AMD$(){ return context[name]; }).call(exports, __webpack_require__, exports, module),
1511
+ __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); }
1512
+ })("Promise",typeof __webpack_require__.g != "undefined" ? __webpack_require__.g : this,function DEF(){
1513
+ /*jshint validthis:true */
1514
+ "use strict";
1515
+
1516
+ var builtInProp, cycle, scheduling_queue,
1517
+ ToString = Object.prototype.toString,
1518
+ timer = (typeof setImmediate != "undefined") ?
1519
+ function timer(fn) { return setImmediate(fn); } :
1520
+ setTimeout
1521
+ ;
1522
+
1523
+ // dammit, IE8.
1524
+ try {
1525
+ Object.defineProperty({},"x",{});
1526
+ builtInProp = function builtInProp(obj,name,val,config) {
1527
+ return Object.defineProperty(obj,name,{
1528
+ value: val,
1529
+ writable: true,
1530
+ configurable: config !== false
1531
+ });
1532
+ };
1533
+ }
1534
+ catch (err) {
1535
+ builtInProp = function builtInProp(obj,name,val) {
1536
+ obj[name] = val;
1537
+ return obj;
1538
+ };
1539
+ }
1540
+
1541
+ // Note: using a queue instead of array for efficiency
1542
+ scheduling_queue = (function Queue() {
1543
+ var first, last, item;
1544
+
1545
+ function Item(fn,self) {
1546
+ this.fn = fn;
1547
+ this.self = self;
1548
+ this.next = void 0;
1549
+ }
1550
+
1551
+ return {
1552
+ add: function add(fn,self) {
1553
+ item = new Item(fn,self);
1554
+ if (last) {
1555
+ last.next = item;
1556
+ }
1557
+ else {
1558
+ first = item;
1559
+ }
1560
+ last = item;
1561
+ item = void 0;
1562
+ },
1563
+ drain: function drain() {
1564
+ var f = first;
1565
+ first = last = cycle = void 0;
1566
+
1567
+ while (f) {
1568
+ f.fn.call(f.self);
1569
+ f = f.next;
1570
+ }
1571
+ }
1572
+ };
1573
+ })();
1574
+
1575
+ function schedule(fn,self) {
1576
+ scheduling_queue.add(fn,self);
1577
+ if (!cycle) {
1578
+ cycle = timer(scheduling_queue.drain);
1579
+ }
1580
+ }
1581
+
1582
+ // promise duck typing
1583
+ function isThenable(o) {
1584
+ var _then, o_type = typeof o;
1585
+
1586
+ if (o != null &&
1587
+ (
1588
+ o_type == "object" || o_type == "function"
1589
+ )
1590
+ ) {
1591
+ _then = o.then;
1592
+ }
1593
+ return typeof _then == "function" ? _then : false;
1594
+ }
1595
+
1596
+ function notify() {
1597
+ for (var i=0; i<this.chain.length; i++) {
1598
+ notifyIsolated(
1599
+ this,
1600
+ (this.state === 1) ? this.chain[i].success : this.chain[i].failure,
1601
+ this.chain[i]
1602
+ );
1603
+ }
1604
+ this.chain.length = 0;
1605
+ }
1606
+
1607
+ // NOTE: This is a separate function to isolate
1608
+ // the `try..catch` so that other code can be
1609
+ // optimized better
1610
+ function notifyIsolated(self,cb,chain) {
1611
+ var ret, _then;
1612
+ try {
1613
+ if (cb === false) {
1614
+ chain.reject(self.msg);
1615
+ }
1616
+ else {
1617
+ if (cb === true) {
1618
+ ret = self.msg;
1619
+ }
1620
+ else {
1621
+ ret = cb.call(void 0,self.msg);
1622
+ }
1623
+
1624
+ if (ret === chain.promise) {
1625
+ chain.reject(TypeError("Promise-chain cycle"));
1626
+ }
1627
+ else if (_then = isThenable(ret)) {
1628
+ _then.call(ret,chain.resolve,chain.reject);
1629
+ }
1630
+ else {
1631
+ chain.resolve(ret);
1632
+ }
1633
+ }
1634
+ }
1635
+ catch (err) {
1636
+ chain.reject(err);
1637
+ }
1638
+ }
1639
+
1640
+ function resolve(msg) {
1641
+ var _then, self = this;
1642
+
1643
+ // already triggered?
1644
+ if (self.triggered) { return; }
1645
+
1646
+ self.triggered = true;
1647
+
1648
+ // unwrap
1649
+ if (self.def) {
1650
+ self = self.def;
1651
+ }
1652
+
1653
+ try {
1654
+ if (_then = isThenable(msg)) {
1655
+ schedule(function(){
1656
+ var def_wrapper = new MakeDefWrapper(self);
1657
+ try {
1658
+ _then.call(msg,
1659
+ function $resolve$(){ resolve.apply(def_wrapper,arguments); },
1660
+ function $reject$(){ reject.apply(def_wrapper,arguments); }
1661
+ );
1662
+ }
1663
+ catch (err) {
1664
+ reject.call(def_wrapper,err);
1665
+ }
1666
+ })
1667
+ }
1668
+ else {
1669
+ self.msg = msg;
1670
+ self.state = 1;
1671
+ if (self.chain.length > 0) {
1672
+ schedule(notify,self);
1673
+ }
1674
+ }
1675
+ }
1676
+ catch (err) {
1677
+ reject.call(new MakeDefWrapper(self),err);
1678
+ }
1679
+ }
1680
+
1681
+ function reject(msg) {
1682
+ var self = this;
1683
+
1684
+ // already triggered?
1685
+ if (self.triggered) { return; }
1686
+
1687
+ self.triggered = true;
1688
+
1689
+ // unwrap
1690
+ if (self.def) {
1691
+ self = self.def;
1692
+ }
1693
+
1694
+ self.msg = msg;
1695
+ self.state = 2;
1696
+ if (self.chain.length > 0) {
1697
+ schedule(notify,self);
1698
+ }
1699
+ }
1700
+
1701
+ function iteratePromises(Constructor,arr,resolver,rejecter) {
1702
+ for (var idx=0; idx<arr.length; idx++) {
1703
+ (function IIFE(idx){
1704
+ Constructor.resolve(arr[idx])
1705
+ .then(
1706
+ function $resolver$(msg){
1707
+ resolver(idx,msg);
1708
+ },
1709
+ rejecter
1710
+ );
1711
+ })(idx);
1712
+ }
1713
+ }
1714
+
1715
+ function MakeDefWrapper(self) {
1716
+ this.def = self;
1717
+ this.triggered = false;
1718
+ }
1719
+
1720
+ function MakeDef(self) {
1721
+ this.promise = self;
1722
+ this.state = 0;
1723
+ this.triggered = false;
1724
+ this.chain = [];
1725
+ this.msg = void 0;
1726
+ }
1727
+
1728
+ function Promise(executor) {
1729
+ if (typeof executor != "function") {
1730
+ throw TypeError("Not a function");
1731
+ }
1732
+
1733
+ if (this.__NPO__ !== 0) {
1734
+ throw TypeError("Not a promise");
1735
+ }
1736
+
1737
+ // instance shadowing the inherited "brand"
1738
+ // to signal an already "initialized" promise
1739
+ this.__NPO__ = 1;
1740
+
1741
+ var def = new MakeDef(this);
1742
+
1743
+ this["then"] = function then(success,failure) {
1744
+ var o = {
1745
+ success: typeof success == "function" ? success : true,
1746
+ failure: typeof failure == "function" ? failure : false
1747
+ };
1748
+ // Note: `then(..)` itself can be borrowed to be used against
1749
+ // a different promise constructor for making the chained promise,
1750
+ // by substituting a different `this` binding.
1751
+ o.promise = new this.constructor(function extractChain(resolve,reject) {
1752
+ if (typeof resolve != "function" || typeof reject != "function") {
1753
+ throw TypeError("Not a function");
1754
+ }
1755
+
1756
+ o.resolve = resolve;
1757
+ o.reject = reject;
1758
+ });
1759
+ def.chain.push(o);
1760
+
1761
+ if (def.state !== 0) {
1762
+ schedule(notify,def);
1763
+ }
1764
+
1765
+ return o.promise;
1766
+ };
1767
+ this["catch"] = function $catch$(failure) {
1768
+ return this.then(void 0,failure);
1769
+ };
1770
+
1771
+ try {
1772
+ executor.call(
1773
+ void 0,
1774
+ function publicResolve(msg){
1775
+ resolve.call(def,msg);
1776
+ },
1777
+ function publicReject(msg) {
1778
+ reject.call(def,msg);
1779
+ }
1780
+ );
1781
+ }
1782
+ catch (err) {
1783
+ reject.call(def,err);
1784
+ }
1785
+ }
1786
+
1787
+ var PromisePrototype = builtInProp({},"constructor",Promise,
1788
+ /*configurable=*/false
1789
+ );
1790
+
1791
+ // Note: Android 4 cannot use `Object.defineProperty(..)` here
1792
+ Promise.prototype = PromisePrototype;
1793
+
1794
+ // built-in "brand" to signal an "uninitialized" promise
1795
+ builtInProp(PromisePrototype,"__NPO__",0,
1796
+ /*configurable=*/false
1797
+ );
1798
+
1799
+ builtInProp(Promise,"resolve",function Promise$resolve(msg) {
1800
+ var Constructor = this;
1801
+
1802
+ // spec mandated checks
1803
+ // note: best "isPromise" check that's practical for now
1804
+ if (msg && typeof msg == "object" && msg.__NPO__ === 1) {
1805
+ return msg;
1806
+ }
1807
+
1808
+ return new Constructor(function executor(resolve,reject){
1809
+ if (typeof resolve != "function" || typeof reject != "function") {
1810
+ throw TypeError("Not a function");
1811
+ }
1812
+
1813
+ resolve(msg);
1814
+ });
1815
+ });
1816
+
1817
+ builtInProp(Promise,"reject",function Promise$reject(msg) {
1818
+ return new this(function executor(resolve,reject){
1819
+ if (typeof resolve != "function" || typeof reject != "function") {
1820
+ throw TypeError("Not a function");
1821
+ }
1822
+
1823
+ reject(msg);
1824
+ });
1825
+ });
1826
+
1827
+ builtInProp(Promise,"all",function Promise$all(arr) {
1828
+ var Constructor = this;
1829
+
1830
+ // spec mandated checks
1831
+ if (ToString.call(arr) != "[object Array]") {
1832
+ return Constructor.reject(TypeError("Not an array"));
1833
+ }
1834
+ if (arr.length === 0) {
1835
+ return Constructor.resolve([]);
1836
+ }
1837
+
1838
+ return new Constructor(function executor(resolve,reject){
1839
+ if (typeof resolve != "function" || typeof reject != "function") {
1840
+ throw TypeError("Not a function");
1841
+ }
1842
+
1843
+ var len = arr.length, msgs = Array(len), count = 0;
1844
+
1845
+ iteratePromises(Constructor,arr,function resolver(idx,msg) {
1846
+ msgs[idx] = msg;
1847
+ if (++count === len) {
1848
+ resolve(msgs);
1849
+ }
1850
+ },reject);
1851
+ });
1852
+ });
1853
+
1854
+ builtInProp(Promise,"race",function Promise$race(arr) {
1855
+ var Constructor = this;
1856
+
1857
+ // spec mandated checks
1858
+ if (ToString.call(arr) != "[object Array]") {
1859
+ return Constructor.reject(TypeError("Not an array"));
1860
+ }
1861
+
1862
+ return new Constructor(function executor(resolve,reject){
1863
+ if (typeof resolve != "function" || typeof reject != "function") {
1864
+ throw TypeError("Not a function");
1865
+ }
1866
+
1867
+ iteratePromises(Constructor,arr,function resolver(idx,msg){
1868
+ resolve(msg);
1869
+ },reject);
1870
+ });
1871
+ });
1872
+
1873
+ return Promise;
1874
+ });
1875
+
1876
+
1877
+ /***/ }
1878
+
1879
+ /******/ });
1880
+ /************************************************************************/
1881
+ /******/ // The module cache
1882
+ /******/ var __webpack_module_cache__ = {};
1883
+ /******/
1884
+ /******/ // The require function
1885
+ /******/ function __webpack_require__(moduleId) {
1886
+ /******/ // Check if module is in cache
1887
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
1888
+ /******/ if (cachedModule !== undefined) {
1889
+ /******/ return cachedModule.exports;
1890
+ /******/ }
1891
+ /******/ // Create a new module (and put it into the cache)
1892
+ /******/ var module = __webpack_module_cache__[moduleId] = {
1893
+ /******/ // no module.id needed
1894
+ /******/ // no module.loaded needed
1895
+ /******/ exports: {}
1896
+ /******/ };
1897
+ /******/
1898
+ /******/ // Execute the module function
1899
+ /******/ if (!(moduleId in __webpack_modules__)) {
1900
+ /******/ delete __webpack_module_cache__[moduleId];
1901
+ /******/ var e = new Error("Cannot find module '" + moduleId + "'");
1902
+ /******/ e.code = 'MODULE_NOT_FOUND';
1903
+ /******/ throw e;
1904
+ /******/ }
1905
+ /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
1906
+ /******/
1907
+ /******/ // Return the exports of the module
1908
+ /******/ return module.exports;
1909
+ /******/ }
1910
+ /******/
1911
+ /************************************************************************/
1912
+ /******/ /* webpack/runtime/compat get default export */
1913
+ /******/ (() => {
1914
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
1915
+ /******/ __webpack_require__.n = (module) => {
1916
+ /******/ var getter = module && module.__esModule ?
1917
+ /******/ () => (module['default']) :
1918
+ /******/ () => (module);
1919
+ /******/ __webpack_require__.d(getter, { a: getter });
1920
+ /******/ return getter;
1921
+ /******/ };
1922
+ /******/ })();
1923
+ /******/
1924
+ /******/ /* webpack/runtime/define property getters */
1925
+ /******/ (() => {
1926
+ /******/ // define getter functions for harmony exports
1927
+ /******/ __webpack_require__.d = (exports, definition) => {
1928
+ /******/ for(var key in definition) {
1929
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
1930
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
1931
+ /******/ }
1932
+ /******/ }
1933
+ /******/ };
1934
+ /******/ })();
1935
+ /******/
1936
+ /******/ /* webpack/runtime/global */
1937
+ /******/ (() => {
1938
+ /******/ __webpack_require__.g = (function() {
1939
+ /******/ if (typeof globalThis === 'object') return globalThis;
1940
+ /******/ try {
1941
+ /******/ return this || new Function('return this')();
1942
+ /******/ } catch (e) {
1943
+ /******/ if (typeof window === 'object') return window;
1944
+ /******/ }
1945
+ /******/ })();
1946
+ /******/ })();
1947
+ /******/
1948
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
1949
+ /******/ (() => {
1950
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
1951
+ /******/ })();
1952
+ /******/
1953
+ /******/ /* webpack/runtime/make namespace object */
1954
+ /******/ (() => {
1955
+ /******/ // define __esModule on exports
1956
+ /******/ __webpack_require__.r = (exports) => {
1957
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
1958
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1959
+ /******/ }
1960
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
1961
+ /******/ };
1962
+ /******/ })();
1963
+ /******/
1964
+ /************************************************************************/
1965
+ var __webpack_exports__ = {};
1966
+ // This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
1967
+ (() => {
1968
+ "use strict";
1969
+ /*!**********************!*\
1970
+ !*** ./lib/index.js ***!
1971
+ \**********************/
1972
+ __webpack_require__.r(__webpack_exports__);
1973
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1974
+ /* harmony export */ Client: () => (/* reexport safe */ _client__WEBPACK_IMPORTED_MODULE_0__["default"]),
1975
+ /* harmony export */ ContextAPI: () => (/* reexport safe */ _apis_context__WEBPACK_IMPORTED_MODULE_2__["default"]),
1976
+ /* harmony export */ InstanceAPI: () => (/* reexport safe */ _apis_instance__WEBPACK_IMPORTED_MODULE_4__.InstanceAPI),
1977
+ /* harmony export */ MetadataAPI: () => (/* reexport safe */ _apis_metadata__WEBPACK_IMPORTED_MODULE_3__["default"]),
1978
+ /* harmony export */ RequestAPI: () => (/* reexport safe */ _apis_request__WEBPACK_IMPORTED_MODULE_5__["default"]),
1979
+ /* harmony export */ debounce: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.debounce),
1980
+ /* harmony export */ deepClone: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.deepClone),
1981
+ /* harmony export */ deepMerge: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.deepMerge),
1982
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__),
1983
+ /* harmony export */ formatError: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.formatError),
1984
+ /* harmony export */ generateUUID: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.generateUUID),
1985
+ /* harmony export */ isArray: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.isArray),
1986
+ /* harmony export */ isFunction: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.isFunction),
1987
+ /* harmony export */ isNull: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.isNull),
1988
+ /* harmony export */ isObject: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.isObject),
1989
+ /* harmony export */ isString: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.isString),
1990
+ /* harmony export */ isUndefined: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.isUndefined),
1991
+ /* harmony export */ isValidUrl: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.isValidUrl),
1992
+ /* harmony export */ parseWidgetLocations: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.parseWidgetLocations),
1993
+ /* harmony export */ queryParameters: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.queryParameters),
1994
+ /* harmony export */ throttle: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.throttle),
1995
+ /* harmony export */ validateManifest: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.validateManifest),
1996
+ /* harmony export */ when: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_1__.when)
1997
+ /* harmony export */ });
1998
+ /* harmony import */ var _client__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./client */ "./lib/client.js");
1999
+ /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils */ "./lib/utils.js");
2000
+ /* harmony import */ var _apis_context__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./apis/context */ "./lib/apis/context.js");
2001
+ /* harmony import */ var _apis_metadata__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./apis/metadata */ "./lib/apis/metadata.js");
2002
+ /* harmony import */ var _apis_instance__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./apis/instance */ "./lib/apis/instance.js");
2003
+ /* harmony import */ var _apis_request__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./apis/request */ "./lib/apis/request.js");
2004
+ /**
2005
+ * BoldDesk App Framework SDK
2006
+ * Main entry point for the BAF SDK library
2007
+ */
2008
+
2009
+
2010
+
2011
+
2012
+ /**
2013
+ * BAFClient - BoldDesk App Framework Client
2014
+ *
2015
+ * Main API for initializing and using the BoldDesk App Framework SDK
2016
+ * in embedded app iframes.
2017
+ *
2018
+ * @example
2019
+ * // Initialize the client
2020
+ * const client = BAFClient.init((context) => {
2021
+ * console.log('App initialized');
2022
+ * console.log('Current module:', context.module);
2023
+ * console.log('User:', context.user.name);
2024
+ * });
2025
+ *
2026
+ * // Use the client APIs
2027
+ * client.get('ticket.subject').then(data => {
2028
+ * console.log(data['ticket.subject']);
2029
+ * });
2030
+ */
2031
+
2032
+ const BAFClient = {
2033
+ /**
2034
+ * Initialize BAFClient and establish connection with BoldDesk host
2035
+ *
2036
+ * Call this function in your app's HTML to initialize the SDK.
2037
+ * The client will automatically detect the app instance and establish
2038
+ * two-way communication with the BoldDesk platform.
2039
+ *
2040
+ * @param {Function} callback - Optional callback function called when app is registered
2041
+ * Receives context object with app information
2042
+ * @param {Object} loc - Optional window location object (for testing)
2043
+ * @returns {Client|boolean} Client instance or false if not in iframe
2044
+ *
2045
+ * @example
2046
+ * // Basic usage
2047
+ * const client = BAFClient.init();
2048
+ *
2049
+ * @example
2050
+ * // With callback
2051
+ * const client = BAFClient.init((context) => {
2052
+ * const currentUser = context.user;
2053
+ * console.log('Hello ' + currentUser.name);
2054
+ * });
2055
+ */
2056
+ init: function (callback, loc) {
2057
+ loc = loc || window.location;
2058
+
2059
+ // Parse query/hash parameters
2060
+ const queryParams = (0,_utils__WEBPACK_IMPORTED_MODULE_1__.queryParameters)(loc.search);
2061
+ const hashParams = (0,_utils__WEBPACK_IMPORTED_MODULE_1__.queryParameters)(loc.hash);
2062
+
2063
+ // Required parameters for iframe app
2064
+ const origin = queryParams.origin || hashParams.origin;
2065
+ const appGuid = queryParams.app_guid || hashParams.app_guid;
2066
+
2067
+ // Validate required parameters
2068
+ if (!origin || !appGuid) {
2069
+ console.error('BAFClient.init(): Missing required parameters. ' + 'App must be loaded with "origin" and "app_guid" parameters.');
2070
+ return false;
2071
+ }
2072
+
2073
+ // Create client instance
2074
+ const client = new _client__WEBPACK_IMPORTED_MODULE_0__["default"]({
2075
+ origin,
2076
+ appGuid
2077
+ });
2078
+
2079
+ // Register callback for app registration event
2080
+ if (typeof callback === 'function') {
2081
+ client.on('app.registered', function (context) {
2082
+ callback.call(client, context);
2083
+ });
2084
+ }
2085
+ return client;
2086
+ }
2087
+ };
2088
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (BAFClient);
2089
+
2090
+ // Also export Client for advanced usage
2091
+
2092
+
2093
+ // Export utility functions
2094
+
2095
+
2096
+ // Export APIs for direct access
2097
+
2098
+
2099
+
2100
+
2101
+ })();
2102
+
2103
+ /******/ return __webpack_exports__;
2104
+ /******/ })()
2105
+ ;
2106
+ });
2107
+ //# sourceMappingURL=baf_sdk.js.map