@webex/contact-center 3.8.1 → 3.9.0-next.10

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.
Files changed (89) hide show
  1. package/dist/cc.js +105 -63
  2. package/dist/cc.js.map +1 -1
  3. package/dist/index.js +13 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/logger-proxy.js +24 -1
  6. package/dist/logger-proxy.js.map +1 -1
  7. package/dist/metrics/MetricsManager.js +1 -1
  8. package/dist/metrics/MetricsManager.js.map +1 -1
  9. package/dist/metrics/behavioral-events.js +51 -0
  10. package/dist/metrics/behavioral-events.js.map +1 -1
  11. package/dist/metrics/constants.js +12 -1
  12. package/dist/metrics/constants.js.map +1 -1
  13. package/dist/services/AddressBook.js +271 -0
  14. package/dist/services/AddressBook.js.map +1 -0
  15. package/dist/services/EntryPoint.js +227 -0
  16. package/dist/services/EntryPoint.js.map +1 -0
  17. package/dist/services/Queue.js +261 -0
  18. package/dist/services/Queue.js.map +1 -0
  19. package/dist/services/config/constants.js +24 -2
  20. package/dist/services/config/constants.js.map +1 -1
  21. package/dist/services/config/index.js +1 -43
  22. package/dist/services/config/index.js.map +1 -1
  23. package/dist/services/config/types.js +0 -5
  24. package/dist/services/config/types.js.map +1 -1
  25. package/dist/services/core/GlobalTypes.js.map +1 -1
  26. package/dist/services/core/Utils.js +121 -2
  27. package/dist/services/core/Utils.js.map +1 -1
  28. package/dist/services/core/aqm-reqs.js +0 -4
  29. package/dist/services/core/aqm-reqs.js.map +1 -1
  30. package/dist/services/core/websocket/WebSocketManager.js +0 -4
  31. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  32. package/dist/services/task/TaskManager.js +1 -0
  33. package/dist/services/task/TaskManager.js.map +1 -1
  34. package/dist/services/task/index.js +145 -71
  35. package/dist/services/task/index.js.map +1 -1
  36. package/dist/types/cc.d.ts +77 -43
  37. package/dist/types/index.d.ts +8 -3
  38. package/dist/types/metrics/constants.d.ts +7 -0
  39. package/dist/types/services/AddressBook.d.ts +74 -0
  40. package/dist/types/services/EntryPoint.d.ts +67 -0
  41. package/dist/types/services/Queue.d.ts +76 -0
  42. package/dist/types/services/config/constants.d.ts +23 -1
  43. package/dist/types/services/config/index.d.ts +1 -14
  44. package/dist/types/services/config/types.d.ts +0 -64
  45. package/dist/types/services/core/GlobalTypes.d.ts +25 -0
  46. package/dist/types/services/core/Utils.d.ts +27 -1
  47. package/dist/types/services/task/index.d.ts +1 -1
  48. package/dist/types/types.d.ts +162 -0
  49. package/dist/types/utils/PageCache.d.ts +173 -0
  50. package/dist/types.js +17 -0
  51. package/dist/types.js.map +1 -1
  52. package/dist/utils/PageCache.js +192 -0
  53. package/dist/utils/PageCache.js.map +1 -0
  54. package/dist/webex.js +1 -1
  55. package/package.json +10 -10
  56. package/src/cc.ts +121 -81
  57. package/src/index.ts +19 -3
  58. package/src/logger-proxy.ts +24 -1
  59. package/src/metrics/MetricsManager.ts +1 -1
  60. package/src/metrics/behavioral-events.ts +54 -0
  61. package/src/metrics/constants.ts +15 -0
  62. package/src/services/AddressBook.ts +291 -0
  63. package/src/services/EntryPoint.ts +241 -0
  64. package/src/services/Queue.ts +277 -0
  65. package/src/services/config/constants.ts +26 -2
  66. package/src/services/config/index.ts +1 -55
  67. package/src/services/config/types.ts +0 -65
  68. package/src/services/core/GlobalTypes.ts +27 -0
  69. package/src/services/core/Utils.ts +155 -1
  70. package/src/services/core/aqm-reqs.ts +0 -5
  71. package/src/services/core/websocket/WebSocketManager.ts +0 -4
  72. package/src/services/task/TaskManager.ts +1 -0
  73. package/src/services/task/index.ts +172 -56
  74. package/src/types.ts +180 -0
  75. package/src/utils/PageCache.ts +252 -0
  76. package/test/unit/spec/cc.ts +30 -82
  77. package/test/unit/spec/metrics/MetricsManager.ts +0 -1
  78. package/test/unit/spec/metrics/behavioral-events.ts +14 -0
  79. package/test/unit/spec/services/AddressBook.ts +332 -0
  80. package/test/unit/spec/services/EntryPoint.ts +259 -0
  81. package/test/unit/spec/services/Queue.ts +323 -0
  82. package/test/unit/spec/services/config/index.ts +0 -71
  83. package/test/unit/spec/services/core/Utils.ts +50 -0
  84. package/test/unit/spec/services/core/aqm-reqs.ts +1 -3
  85. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +0 -4
  86. package/test/unit/spec/services/task/TaskManager.ts +8 -1
  87. package/test/unit/spec/services/task/index.ts +226 -122
  88. package/umd/contact-center.min.js +2 -2
  89. package/umd/contact-center.min.js.map +1 -1
@@ -0,0 +1,252 @@
1
+ import LoggerProxy from '../logger-proxy';
2
+
3
+ /**
4
+ * Common pagination metadata interface used across all APIs.
5
+ * @public
6
+ * @template T - Additional metadata properties specific to the API
7
+ */
8
+ export interface PaginationMeta {
9
+ /** Organization ID */
10
+ orgid?: string;
11
+ /** Current page number */
12
+ page?: number;
13
+ /** Page size for current data set */
14
+ pageSize?: number;
15
+ /** Number of pages */
16
+ totalPages?: number;
17
+ /** Total number of items */
18
+ totalRecords?: number;
19
+ /** Total number of items (alias for compatibility) */
20
+ totalItems?: number;
21
+ /** Current page number (alias for compatibility) */
22
+ currentPage?: number;
23
+ /** Map of pagination links */
24
+ links?: Record<string, string>;
25
+ }
26
+
27
+ /**
28
+ * Common paginated response interface used across all APIs.
29
+ * @public
30
+ * @template T - The type of data items in the response
31
+ */
32
+ export interface PaginatedResponse<T> {
33
+ /** Array of data items */
34
+ data: T[];
35
+ /** Pagination metadata */
36
+ meta: PaginationMeta;
37
+ }
38
+
39
+ /**
40
+ * Common search and pagination parameters interface.
41
+ * @public
42
+ */
43
+ export interface BaseSearchParams {
44
+ /** Search keyword */
45
+ search?: string;
46
+ /** Filter criteria using RSQL syntax */
47
+ filter?: string;
48
+ /** Attributes to be returned */
49
+ attributes?: string;
50
+ /** Page number (starts from 0) */
51
+ page?: number;
52
+ /** Number of items per page */
53
+ pageSize?: number;
54
+ /** Sort field */
55
+ sortBy?: string;
56
+ /** Sort direction */
57
+ sortOrder?: 'asc' | 'desc';
58
+ }
59
+
60
+ /**
61
+ * Default pagination constants used across all APIs.
62
+ * @public
63
+ */
64
+ export const PAGINATION_DEFAULTS = {
65
+ /** Default page number */
66
+ PAGE: 0,
67
+ /** Default page size */
68
+ PAGE_SIZE: 100,
69
+ } as const;
70
+
71
+ /**
72
+ * Interface for cached page entry with metadata
73
+ * @public
74
+ */
75
+ export interface PageCacheEntry<T> {
76
+ /** Cached data items for this page */
77
+ data: T[];
78
+ /** Timestamp when this page was cached */
79
+ timestamp: number;
80
+ /** Total metadata if available */
81
+ totalMeta?: {
82
+ totalPages?: number;
83
+ totalRecords?: number;
84
+ };
85
+ }
86
+
87
+ /**
88
+ * Interface for cache validation parameters
89
+ * @public
90
+ */
91
+ export interface CacheValidationParams {
92
+ /** Search query parameter */
93
+ search?: string;
94
+ /** Filter parameter */
95
+ filter?: string;
96
+ /** Attributes parameter */
97
+ attributes?: string;
98
+ /** Sort by parameter */
99
+ sortBy?: string;
100
+ }
101
+
102
+ /**
103
+ * Default cache TTL in minutes
104
+ */
105
+ const DEFAULT_CACHE_TTL_MINUTES = 5;
106
+
107
+ /**
108
+ * Page cache utility class for managing paginated API response caching.
109
+ * Provides consistent caching behavior across all Contact Center APIs.
110
+ *
111
+ * @class PageCache
112
+ * @public
113
+ * @template T - The type of data items being cached
114
+ * @example
115
+ * ```typescript
116
+ * // Create a cache instance for a specific data type
117
+ * const cache = new PageCache<AddressBookEntry>('AddressBook');
118
+ *
119
+ * // Check if we can use cache (no search/filter parameters)
120
+ * if (cache.canUseCache({ search, filter })) {
121
+ * const cacheKey = cache.buildCacheKey(orgId, page, pageSize);
122
+ * const cachedPage = cache.getCachedPage(cacheKey);
123
+ *
124
+ * if (cachedPage) {
125
+ * return cachedPage.data;
126
+ * }
127
+ * }
128
+ *
129
+ * // Cache API response
130
+ * cache.cachePage(cacheKey, responseData, responseMeta);
131
+ * ```
132
+ */
133
+ export class PageCache<T> {
134
+ private cache: Map<string, PageCacheEntry<T>> = new Map();
135
+ private apiName: string;
136
+
137
+ /**
138
+ * Creates an instance of PageCache
139
+ * @param {string} apiName - Name of the API using this cache (for logging)
140
+ * @public
141
+ */
142
+ constructor(apiName: string) {
143
+ this.apiName = apiName;
144
+ }
145
+
146
+ /**
147
+ * Checks if cache can be used for the given parameters.
148
+ * Cache is only used for simple pagination without search/filter/attributes/sort.
149
+ * @param {CacheValidationParams} params - Parameters to validate
150
+ * @returns {boolean} True if cache can be used
151
+ * @public
152
+ */
153
+ public canUseCache(params: CacheValidationParams): boolean {
154
+ const {search, filter, attributes, sortBy} = params;
155
+
156
+ return !search && !filter && !attributes && !sortBy;
157
+ }
158
+
159
+ /**
160
+ * Builds a cache key for the given parameters
161
+ * @param {string} orgId - Organization ID
162
+ * @param {number} page - Page number
163
+ * @param {number} pageSize - Page size
164
+ * @returns {string} Cache key
165
+ * @public
166
+ */
167
+ public buildCacheKey(orgId: string, page: number, pageSize: number): string {
168
+ return `${orgId}:${page}:${pageSize}`;
169
+ }
170
+
171
+ /**
172
+ * Gets a cached page if it exists and is valid
173
+ * @param {string} cacheKey - Cache key to look up
174
+ * @returns {PageCacheEntry<T> | null} Cached page entry or null if not found/expired
175
+ * @public
176
+ */
177
+ public getCachedPage(cacheKey: string): PageCacheEntry<T> | null {
178
+ const cachedEntry = this.cache.get(cacheKey);
179
+
180
+ if (!cachedEntry) {
181
+ return null;
182
+ }
183
+
184
+ // Check if cache entry is expired
185
+ const now = Date.now();
186
+ const cacheAge = (now - cachedEntry.timestamp) / (1000 * 60); // in minutes
187
+
188
+ if (cacheAge >= DEFAULT_CACHE_TTL_MINUTES) {
189
+ LoggerProxy.log(`Cache entry expired for key: ${cacheKey}`, {
190
+ module: this.apiName,
191
+ method: 'getCachedPage',
192
+ });
193
+ this.cache.delete(cacheKey);
194
+
195
+ return null;
196
+ }
197
+
198
+ return cachedEntry;
199
+ }
200
+
201
+ /**
202
+ * Caches a page of data with metadata
203
+ * @param {string} cacheKey - Cache key
204
+ * @param {T[]} data - Data items to cache
205
+ * @param {any} meta - Metadata from API response
206
+ * @public
207
+ */
208
+ public cachePage(cacheKey: string, data: T[], meta?: any): void {
209
+ const cacheEntry: PageCacheEntry<T> = {
210
+ data,
211
+ timestamp: Date.now(),
212
+ totalMeta: meta
213
+ ? {
214
+ totalPages: meta.totalPages,
215
+ totalRecords: meta.totalRecords || meta.totalItems,
216
+ }
217
+ : undefined,
218
+ };
219
+
220
+ this.cache.set(cacheKey, cacheEntry);
221
+
222
+ LoggerProxy.log(`Cached page with ${data.length} items for key: ${cacheKey}`, {
223
+ module: this.apiName,
224
+ method: 'cachePage',
225
+ });
226
+ }
227
+
228
+ /**
229
+ * Clears all cached entries
230
+ * @public
231
+ */
232
+ public clearCache(): void {
233
+ const cacheSize = this.cache.size;
234
+ this.cache.clear();
235
+
236
+ LoggerProxy.log(`Cleared ${cacheSize} cache entries`, {
237
+ module: this.apiName,
238
+ method: 'clearCache',
239
+ });
240
+ }
241
+
242
+ /**
243
+ * Gets the current number of cached entries
244
+ * @returns {number} Number of cached entries
245
+ * @public
246
+ */
247
+ public getCacheSize(): number {
248
+ return this.cache.size;
249
+ }
250
+ }
251
+
252
+ export default PageCache;
@@ -7,6 +7,11 @@ import {
7
7
  WebexSDK,
8
8
  } from '../../../src/types';
9
9
  import ContactCenter from '../../../src/cc';
10
+ import EntryPoint from '../../../src/services/EntryPoint';
11
+ import type {EntryPointListResponse} from '../../../src/types';
12
+ import AddressBook from '../../../src/services/AddressBook';
13
+ import Queue from '../../../src/services/Queue';
14
+ import type {ContactServiceQueuesResponse} from '../../../src/types';
10
15
  import MockWebex from '@webex/test-helper-mock-webex';
11
16
  import {StationLoginSuccess, AGENT_EVENTS} from '../../../src/services/agent/types';
12
17
  import {SetStateResponse} from '../../../src/types';
@@ -1387,88 +1392,6 @@ describe('webex.cc', () => {
1387
1392
  });
1388
1393
  });
1389
1394
 
1390
- describe('getQueues', () => {
1391
- it('should return queues response when successful', async () => {
1392
- const mockQueuesResponse = [
1393
- {
1394
- queueId: 'queue1',
1395
- queueName: 'Queue 1',
1396
- },
1397
- {
1398
- queueId: 'queue2',
1399
- queueName: 'Queue 2',
1400
- },
1401
- ];
1402
-
1403
- webex.cc.services.config.getQueues = jest.fn().mockResolvedValue(mockQueuesResponse);
1404
-
1405
- const result = await webex.cc.getQueues();
1406
-
1407
- // Verify logging calls
1408
- expect(LoggerProxy.info).toHaveBeenCalledWith('Fetching queues', {
1409
- module: CC_FILE,
1410
- method: 'getQueues',
1411
- });
1412
- expect(LoggerProxy.log).toHaveBeenCalledWith(
1413
- `Successfully retrieved ${result.length} queues`,
1414
- {
1415
- module: CC_FILE,
1416
- method: 'getQueues',
1417
- }
1418
- );
1419
-
1420
- expect(webex.cc.services.config.getQueues).toHaveBeenCalledWith(
1421
- 'mockOrgId',
1422
- 0,
1423
- 100,
1424
- undefined,
1425
- undefined
1426
- );
1427
- expect(result).toEqual(mockQueuesResponse);
1428
- });
1429
-
1430
- it('should throw an error if orgId is not present', async () => {
1431
- jest.spyOn(webex.credentials, 'getOrgId').mockResolvedValue(undefined);
1432
- webex.cc.services.config.getQueues = jest.fn();
1433
-
1434
- try {
1435
- await webex.cc.getQueues();
1436
- } catch (error) {
1437
- expect(error).toEqual(new Error('Org ID not found.'));
1438
- expect(LoggerProxy.info).toHaveBeenCalledWith('Fetching queues', {
1439
- module: CC_FILE,
1440
- method: 'getQueues',
1441
- });
1442
- expect(LoggerProxy.error).toHaveBeenCalledWith('Org ID not found.', {
1443
- module: CC_FILE,
1444
- method: 'getQueues',
1445
- });
1446
- expect(webex.cc.services.config.getQueues).not.toHaveBeenCalled();
1447
- }
1448
- });
1449
-
1450
- it('should throw an error if config getQueues throws an error', async () => {
1451
- webex.cc.services.config.getQueues = jest.fn().mockRejectedValue(new Error('Test error.'));
1452
-
1453
- try {
1454
- await webex.cc.getQueues();
1455
- } catch (error) {
1456
- expect(error).toEqual(new Error('Test error.'));
1457
- expect(LoggerProxy.info).toHaveBeenCalledWith('Fetching queues', {
1458
- module: CC_FILE,
1459
- method: 'getQueues',
1460
- });
1461
- expect(webex.cc.services.config.getQueues).toHaveBeenCalledWith(
1462
- 'mockOrgId',
1463
- 0,
1464
- 100,
1465
- undefined,
1466
- undefined
1467
- );
1468
- }
1469
- });
1470
- });
1471
-
1472
1395
  describe('uploadLogs', () => {
1473
1396
  it('should upload logs successfully', async () => {
1474
1397
  const uploadLogsMock = jest.spyOn(webex.cc.webexRequest, 'uploadLogs').mockResolvedValue({
@@ -1796,6 +1719,31 @@ describe('webex.cc', () => {
1796
1719
  });
1797
1720
  });
1798
1721
 
1722
+ describe('API property exposure', () => {
1723
+ it('should provide getEntryPoints wrapper that delegates to EntryPoint', async () => {
1724
+ const spy = jest
1725
+ .spyOn(EntryPoint.prototype, 'getEntryPoints')
1726
+ .mockResolvedValue({} as EntryPointListResponse);
1727
+ await webex.cc.getEntryPoints();
1728
+ expect(spy).toHaveBeenCalled();
1729
+ spy.mockRestore();
1730
+ });
1731
+
1732
+ it('should expose addressBook API', () => {
1733
+ expect(webex.cc.addressBook).toBeDefined();
1734
+ expect(webex.cc.addressBook).toBeInstanceOf(AddressBook);
1735
+ });
1736
+
1737
+ it('should provide getQueues wrapper that delegates to Queue', async () => {
1738
+ const spy = jest
1739
+ .spyOn(Queue.prototype, 'getQueues')
1740
+ .mockResolvedValue({} as ContactServiceQueuesResponse);
1741
+ await webex.cc.getQueues();
1742
+ expect(spy).toHaveBeenCalled();
1743
+ spy.mockRestore();
1744
+ });
1745
+ });
1746
+
1799
1747
  describe('updateAgentProfile', () => {
1800
1748
  beforeEach(() => {
1801
1749
  webex.cc.agentConfig = {
@@ -3,7 +3,6 @@ import MetricsManager from '../../../../src/metrics/MetricsManager';
3
3
  import {METRIC_EVENT_NAMES} from '../../../../src/metrics/constants';
4
4
  import {WebexSDK} from '../../../../src/types';
5
5
  import {EventPayload} from '@webex/internal-plugin-metrics/src/metrics.types';
6
- import LoggerProxy from '../../../../src/logger-proxy';
7
6
 
8
7
  describe('MetricsManagerImplementation', () => {
9
8
  let webex: WebexSDK;
@@ -12,6 +12,20 @@ describe('metrics/behavioral-events', () => {
12
12
  verb: 'set',
13
13
  });
14
14
 
15
+ expect(getEventTaxonomy(METRIC_EVENT_NAMES.AGENT_CONTACT_ASSIGN_FAILED)).toEqual({
16
+ product,
17
+ agent: 'service',
18
+ target: 'agent_contact_assign',
19
+ verb: 'fail',
20
+ });
21
+
22
+ expect(getEventTaxonomy(METRIC_EVENT_NAMES.AGENT_INVITE_FAILED)).toEqual({
23
+ product,
24
+ agent: 'service',
25
+ target: 'agent_invite',
26
+ verb: 'fail',
27
+ });
28
+
15
29
  expect(getEventTaxonomy(METRIC_EVENT_NAMES.STATION_LOGIN_SUCCESS)).toEqual({
16
30
  product,
17
31
  agent: 'user',