@webex/contact-center 3.13.0-next.12 → 3.13.0-next.13

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 (37) hide show
  1. package/ai-docs/contact-center-spec.md +387 -0
  2. package/dist/cc.js +7 -7
  3. package/dist/cc.js.map +1 -1
  4. package/dist/services/core/Utils.js +21 -2
  5. package/dist/services/core/Utils.js.map +1 -1
  6. package/dist/services/core/aqm-reqs.js +1 -1
  7. package/dist/services/core/aqm-reqs.js.map +1 -1
  8. package/dist/services/core/websocket/connection-service.js +18 -1
  9. package/dist/services/core/websocket/connection-service.js.map +1 -1
  10. package/dist/services/core/websocket/keepalive.worker.js +0 -9
  11. package/dist/services/core/websocket/keepalive.worker.js.map +1 -1
  12. package/dist/services/task/TaskManager.js +9 -1
  13. package/dist/services/task/TaskManager.js.map +1 -1
  14. package/dist/services/task/TaskUtils.js +7 -4
  15. package/dist/services/task/TaskUtils.js.map +1 -1
  16. package/dist/types/services/core/Utils.d.ts +9 -0
  17. package/dist/types/services/core/websocket/keepalive.worker.d.ts +1 -1
  18. package/dist/webex.js +1 -1
  19. package/package.json +1 -1
  20. package/src/cc.ts +19 -11
  21. package/src/services/core/Utils.ts +19 -0
  22. package/src/services/core/ai-docs/core-spec.md +808 -0
  23. package/src/services/core/aqm-reqs.ts +1 -1
  24. package/src/services/core/websocket/connection-service.ts +21 -2
  25. package/src/services/core/websocket/keepalive.worker.js +0 -9
  26. package/src/services/task/TaskManager.ts +12 -1
  27. package/src/services/task/TaskUtils.ts +10 -9
  28. package/src/services/task/ai-docs/task-spec.md +1511 -0
  29. package/test/unit/spec/cc.ts +124 -0
  30. package/test/unit/spec/services/core/Utils.ts +27 -0
  31. package/test/unit/spec/services/core/aqm-reqs.ts +18 -0
  32. package/test/unit/spec/services/core/websocket/connection-service.ts +29 -0
  33. package/test/unit/spec/services/core/websocket/keepalive.worker.ts +18 -0
  34. package/test/unit/spec/services/task/TaskManager.ts +52 -0
  35. package/test/unit/spec/services/task/TaskUtils.ts +51 -0
  36. package/umd/contact-center.min.js +2 -2
  37. package/umd/contact-center.min.js.map +1 -1
@@ -3144,6 +3144,20 @@ describe('webex.cc', () => {
3144
3144
  ]);
3145
3145
  });
3146
3146
 
3147
+ it('logout reason is sanitized before metrics', async () => {
3148
+ const data = {logoutReason: 'Logout\r\ninjected: evil'};
3149
+
3150
+ jest.spyOn(webex.cc.services.agent, 'logout').mockResolvedValue({} as StationLogoutResponse);
3151
+
3152
+ await webex.cc.stationLogout(data);
3153
+
3154
+ expect(mockMetricsManager.trackEvent).toHaveBeenCalledWith(
3155
+ METRIC_EVENT_NAMES.STATION_LOGOUT_SUCCESS,
3156
+ expect.objectContaining({logoutReason: 'Logoutinjected: evil'}),
3157
+ ['behavioral', 'business', 'operational']
3158
+ );
3159
+ });
3160
+
3147
3161
  it('should not publish usersub false on logout when wxApp was never enabled', async () => {
3148
3162
  webex.internal.device = {userId: 'user-123'};
3149
3163
  const publishSpy = jest
@@ -3378,6 +3392,26 @@ describe('webex.cc', () => {
3378
3392
  {module: CC_FILE, method: 'stationLogout', trackingId: error.details.trackingId}
3379
3393
  );
3380
3394
  });
3395
+
3396
+ it('logout reason is sanitized before metrics in error path', async () => {
3397
+ const data = {logoutReason: 'Logout\r\ninjected: evil'};
3398
+ const error = {
3399
+ details: {
3400
+ trackingId: '1234',
3401
+ data: {reason: 'station logout failed'},
3402
+ },
3403
+ };
3404
+
3405
+ jest.spyOn(webex.cc.services.agent, 'logout').mockRejectedValue(error);
3406
+
3407
+ await expect(webex.cc.stationLogout(data)).rejects.toThrow();
3408
+
3409
+ expect(mockMetricsManager.trackEvent).toHaveBeenCalledWith(
3410
+ METRIC_EVENT_NAMES.STATION_LOGOUT_FAILED,
3411
+ expect.objectContaining({logoutReason: 'Logoutinjected: evil'}),
3412
+ ['behavioral', 'business', 'operational']
3413
+ );
3414
+ });
3381
3415
  });
3382
3416
 
3383
3417
  describe('setAgentStatus', () => {
@@ -3561,6 +3595,53 @@ describe('webex.cc', () => {
3561
3595
  {module: CC_FILE, method: 'setAgentState', trackingId: error.details.trackingId}
3562
3596
  );
3563
3597
  });
3598
+
3599
+ it('state change reason is sanitized before metrics on success', async () => {
3600
+ const expectedPayload = {
3601
+ state: 'Available',
3602
+ auxCodeId: '0',
3603
+ agentId: '123',
3604
+ lastStateChangeReason: 'Available\r\ninjected: evil',
3605
+ };
3606
+
3607
+ jest
3608
+ .spyOn(webex.cc.services.agent, 'stateChange')
3609
+ .mockResolvedValue({data: expectedPayload});
3610
+
3611
+ await webex.cc.setAgentState(expectedPayload);
3612
+
3613
+ expect(mockMetricsManager.trackEvent).toHaveBeenCalledWith(
3614
+ METRIC_EVENT_NAMES.AGENT_STATE_CHANGE_SUCCESS,
3615
+ expect.objectContaining({lastStateChangeReason: 'Availableinjected: evil'}),
3616
+ ['behavioral', 'business', 'operational']
3617
+ );
3618
+ });
3619
+
3620
+ it('state change reason is sanitized before metrics on failure', async () => {
3621
+ const expectedPayload = {
3622
+ state: 'Meeting',
3623
+ auxCodeId: '12345',
3624
+ agentId: '123',
3625
+ lastStateChangeReason: 'Meeting\r\ninjected: evil',
3626
+ };
3627
+ const error = {
3628
+ details: {
3629
+ trackingId: '1234',
3630
+ data: {reason: 'missing status'},
3631
+ },
3632
+ };
3633
+ jest.spyOn(webex.cc.services.agent, 'stateChange').mockRejectedValue(error);
3634
+
3635
+ await expect(webex.cc.setAgentState(expectedPayload)).rejects.toThrow(
3636
+ error.details.data.reason
3637
+ );
3638
+
3639
+ expect(mockMetricsManager.trackEvent).toHaveBeenCalledWith(
3640
+ METRIC_EVENT_NAMES.AGENT_STATE_CHANGE_FAILED,
3641
+ expect.objectContaining({lastStateChangeReason: 'Meetinginjected: evil'}),
3642
+ ['behavioral', 'business', 'operational']
3643
+ );
3644
+ });
3564
3645
  });
3565
3646
 
3566
3647
  describe('Agent Wellness Break SDK contracts', () => {
@@ -3912,6 +3993,26 @@ describe('webex.cc', () => {
3912
3993
  });
3913
3994
  });
3914
3995
 
3996
+ it('uses config agentProfileId and ignores override', async () => {
3997
+ webex.cc.agentConfig = {agentProfileID: 'test-agent-profile-id'};
3998
+ const buddyAgentsResponse = {data: {agentList: []}};
3999
+ const buddyAgentsSpy = jest
4000
+ .spyOn(webex.cc.services.agent, 'buddyAgents')
4001
+ .mockResolvedValue(buddyAgentsResponse);
4002
+
4003
+ await webex.cc.getBuddyAgents({
4004
+ mediaType: 'telephony',
4005
+ agentProfileId: 'malicious-override-id',
4006
+ } as BuddyAgents);
4007
+
4008
+ expect(buddyAgentsSpy).toHaveBeenCalledWith({
4009
+ data: {
4010
+ agentProfileId: 'test-agent-profile-id',
4011
+ mediaType: 'telephony',
4012
+ },
4013
+ });
4014
+ });
4015
+
3915
4016
  it('should handle error', async () => {
3916
4017
  const data: BuddyAgents = {state: 'Available', mediaType: 'telephony'};
3917
4018
  webex.cc.agentConfig = {
@@ -5020,6 +5121,29 @@ describe('webex.cc', () => {
5020
5121
  expect(emitSpy).toHaveBeenCalledWith(CC_EVENTS.AGENT_STATE_CHANGE_SUCCESS, sample);
5021
5122
  });
5022
5123
 
5124
+ it('websocket event type is sanitized before logging and metrics', () => {
5125
+ const maliciousType = 'ContactUpdated\r\ninjected: evil';
5126
+ const payload = {
5127
+ type: maliciousType,
5128
+ data: {foo: 'bar'},
5129
+ };
5130
+
5131
+ messageCallback(JSON.stringify(payload));
5132
+
5133
+ expect(LoggerProxy.log).toHaveBeenCalledWith(
5134
+ 'Received event: ContactUpdatedinjected: evil',
5135
+ {module: CC_FILE, method: 'handleWebsocketMessage'}
5136
+ );
5137
+ expect(mockMetricsManager.trackEvent).toHaveBeenCalledWith(
5138
+ METRIC_EVENT_NAMES.WEBSOCKET_EVENT_RECEIVED,
5139
+ expect.objectContaining({
5140
+ ws_event_type: 'ContactUpdatedinjected: evil',
5141
+ top_level_type: 'ContactUpdatedinjected: evil',
5142
+ }),
5143
+ ['operational']
5144
+ );
5145
+ });
5146
+
5023
5147
  it('should call webCallingService.setLoginOption with correct deviceType on AGENT_STATION_LOGIN_SUCCESS', () => {
5024
5148
  const setLoginOptionSpy = jest.spyOn(webex.cc.webCallingService, 'setLoginOption');
5025
5149
  const deviceType = LoginOption.BROWSER;
@@ -1058,4 +1058,31 @@ describe('Utils', () => {
1058
1058
  expect(Utils.isAllowedUrlHost(undefined as any, ['cisco.com'])).toBe(false);
1059
1059
  });
1060
1060
  });
1061
+
1062
+ describe('sanitizeForObservability', () => {
1063
+ it('returns an empty string for non-string input', () => {
1064
+ expect(Utils.sanitizeForObservability(undefined)).toBe('');
1065
+ expect(Utils.sanitizeForObservability(null)).toBe('');
1066
+ expect(Utils.sanitizeForObservability(42)).toBe('');
1067
+ expect(Utils.sanitizeForObservability({})).toBe('');
1068
+ });
1069
+
1070
+ it('leaves a legitimate value effectively unchanged', () => {
1071
+ expect(Utils.sanitizeForObservability('AGENT_LOGOUT')).toBe('AGENT_LOGOUT');
1072
+ });
1073
+
1074
+ it('strips CR/LF to block log-line injection', () => {
1075
+ expect(Utils.sanitizeForObservability('ok\r\nINJECTED fake log line')).toBe(
1076
+ 'okINJECTED fake log line'
1077
+ );
1078
+ });
1079
+
1080
+ it('strips other control characters', () => {
1081
+ expect(Utils.sanitizeForObservability('a\x00b\x1f\x7fc')).toBe('abc');
1082
+ });
1083
+
1084
+ it('caps the length at 200 characters', () => {
1085
+ expect(Utils.sanitizeForObservability('x'.repeat(500))).toHaveLength(200);
1086
+ });
1087
+ });
1061
1088
  });
@@ -706,4 +706,22 @@ describe('AqmReqs', () => {
706
706
  }
707
707
  });
708
708
  });
709
+
710
+ describe('typeMapCheck', () => {
711
+ const typeMapCheck = (AqmReqs as any).typeMapCheck.bind(AqmReqs);
712
+
713
+ it('rejects inherited prototype key', () => {
714
+ const typeMap = {typeField: 'type', conditions: {}};
715
+ const msg = {type: 'constructor'};
716
+
717
+ expect(typeMapCheck(typeMap, msg)).toBe(false);
718
+ });
719
+
720
+ it('still matches valid own-key condition', () => {
721
+ const typeMap = {typeField: 'type', conditions: {EventA: {field: 'value'}}};
722
+ const msg = {type: 'EventA', field: 'value'};
723
+
724
+ expect(typeMapCheck(typeMap, msg)).toBe(true);
725
+ });
726
+ });
709
727
  });
@@ -138,6 +138,35 @@ describe('ConnectionService', () => {
138
138
  expect(clearTimeoutSpy).toHaveBeenCalledWith(reconnectingTimer);
139
139
  expect(clearTimeoutSpy).toHaveBeenCalledWith(restoreTimer);
140
140
  });
141
+
142
+ it.each(['not-json', 'null', '42', '"text"', undefined])(
143
+ 'onPing ignores malformed or non-object payload %p',
144
+ (payload) => {
145
+ connectionService['reconnectingTimer'] = undefined;
146
+ connectionService['restoreTimer'] = undefined;
147
+
148
+ expect(() => connectionService['onPing'](payload)).not.toThrow();
149
+
150
+ expect(connectionService['reconnectingTimer']).toBeUndefined();
151
+ expect(connectionService['restoreTimer']).toBeUndefined();
152
+ expect(LoggerProxy.error).toHaveBeenCalledWith(expect.stringContaining('onPing'), {
153
+ module: CONNECTION_SERVICE_FILE,
154
+ method: 'onPing',
155
+ });
156
+ }
157
+ );
158
+
159
+ it('onPing still processes valid keepalive ping', () => {
160
+ const emitSpy = jest.spyOn(connectionService, 'emit');
161
+ const pingMessage = JSON.stringify({keepalive: 'true'});
162
+
163
+ connectionService['onPing'](pingMessage);
164
+
165
+ expect(connectionService['isKeepAlive']).toBe(true);
166
+ expect(emitSpy).toHaveBeenCalledWith('connectionLost', expect.anything());
167
+ expect(connectionService['reconnectingTimer']).toBeDefined();
168
+ expect(connectionService['restoreTimer']).toBeDefined();
169
+ });
141
170
  });
142
171
 
143
172
  describe('ConnectionService Reconnect', () => {
@@ -0,0 +1,18 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import workerScript from '../../../../../../src/services/core/websocket/keepalive.worker';
3
+
4
+ describe('keepalive worker script', () => {
5
+ it('omits console logging', () => {
6
+ expect(workerScript).not.toMatch(/console\./);
7
+ });
8
+
9
+ it('still defines the keepalive control flow', () => {
10
+ expect(workerScript).toMatch(/checkOnlineStatus/);
11
+ expect(workerScript).toMatch(/checkNetworkStatus/);
12
+ expect(workerScript).toMatch(/addEventListener\("message"/);
13
+ expect(workerScript).toMatch(/self\.addEventListener\('online'/);
14
+ expect(workerScript).toMatch(/self\.addEventListener\('offline'/);
15
+ expect(workerScript).toMatch(/postMessage\(\{ type: "keepalive", onlineStatus \}\)/);
16
+ expect(workerScript).toMatch(/postMessage\(\{ type: "closeSocket" \}\)/);
17
+ });
18
+ });
@@ -625,6 +625,58 @@ describe('TaskManager', () => {
625
625
  );
626
626
  });
627
627
 
628
+ it('requestRealTimeTranscripts rejects invalid interactionId', () => {
629
+ taskManager.setConfigFlags({
630
+ isEndTaskEnabled: true,
631
+ isEndConsultEnabled: true,
632
+ webRtcEnabled: true,
633
+ autoWrapup: false,
634
+ aiFeature: {
635
+ id: 'ai-feature-1',
636
+ realtimeTranscripts: {
637
+ enable: true,
638
+ },
639
+ },
640
+ });
641
+
642
+ (taskManager as any)['requestRealTimeTranscripts'](
643
+ CC_EVENTS.AGENT_CONTACT_ASSIGNED,
644
+ ' '
645
+ );
646
+
647
+ expect(mockApiAIAssistant.sendEvent).not.toHaveBeenCalled();
648
+ });
649
+
650
+ it('requestRealTimeTranscripts trims whitespace from interactionId before sending', () => {
651
+ taskManager.setConfigFlags({
652
+ isEndTaskEnabled: true,
653
+ isEndConsultEnabled: true,
654
+ webRtcEnabled: true,
655
+ autoWrapup: false,
656
+ aiFeature: {
657
+ id: 'ai-feature-1',
658
+ realtimeTranscripts: {
659
+ enable: true,
660
+ },
661
+ },
662
+ });
663
+
664
+ const paddedId = ` ${taskId} `;
665
+
666
+ (taskManager as any)['requestRealTimeTranscripts'](
667
+ CC_EVENTS.AGENT_CONTACT_ASSIGNED,
668
+ paddedId
669
+ );
670
+
671
+ expect(mockApiAIAssistant.sendEvent).toHaveBeenCalledWith(
672
+ expect.any(String),
673
+ taskId,
674
+ expect.any(String),
675
+ expect.any(String),
676
+ expect.any(Object)
677
+ );
678
+ });
679
+
628
680
  it('should not invoke sendEvent when realtime transcripts are disabled in aiFeature', () => {
629
681
  taskManager.setConfigFlags({
630
682
  isEndTaskEnabled: true,
@@ -18,6 +18,7 @@ import {
18
18
  getServerHoldStateForControls,
19
19
  isCampaignPreviewTask,
20
20
  isCampaignPreviewReservation,
21
+ isEpDnConsultPendingConferenceMerge,
21
22
  } from '../../../../../src/services/task/TaskUtils';
22
23
  import {ITask, Interaction, TaskData} from '../../../../../src/services/task/types';
23
24
  import {LoginOption} from '../../../../../src/types';
@@ -737,4 +738,54 @@ describe('TaskUtils', () => {
737
738
  ).toBe(true);
738
739
  });
739
740
  });
741
+
742
+ describe('isEpDnConsultPendingConferenceMerge', () => {
743
+ const buildTaskData = (overrides: {
744
+ state?: unknown;
745
+ hasCustomerLeft?: unknown;
746
+ selfConsultState?: unknown;
747
+ }) =>
748
+ ({
749
+ type: 'ParticipantPostCallActivity',
750
+ consultingAgentId: 'agent-1',
751
+ isConsulted: false,
752
+ interactionId: 'interaction-1',
753
+ interaction: {
754
+ state: overrides.state ?? 'post_call',
755
+ mainInteractionId: 'interaction-1',
756
+ owner: 'agent-1',
757
+ callProcessingDetails: {hasCustomerLeft: overrides.hasCustomerLeft ?? 'true'},
758
+ participants: {
759
+ 'agent-1': {
760
+ id: 'agent-1',
761
+ pType: 'Agent',
762
+ hasLeft: false,
763
+ consultState: overrides.selfConsultState ?? 'conferencing',
764
+ },
765
+ '+13159998059': {id: '+13159998059', pType: 'EP-DN', hasLeft: false, hasJoined: false},
766
+ 'customer-1': {id: 'customer-1', pType: 'Customer', hasJoined: true, hasLeft: true},
767
+ },
768
+ media: {
769
+ 'interaction-1': {mType: 'mainCall', participants: ['agent-1']},
770
+ 'consult-media-1': {mType: 'consult', participants: ['+13159998059', 'agent-1']},
771
+ },
772
+ },
773
+ }) as any;
774
+
775
+ it('merge decision preserved for valid values', () => {
776
+ const taskData = buildTaskData({});
777
+
778
+ expect(isEpDnConsultPendingConferenceMerge(taskData, 'agent-1')).toBe(true);
779
+ });
780
+
781
+ it('merge decision ignores unexpected server field values', () => {
782
+ const taskData = buildTaskData({
783
+ state: 'bogus-state',
784
+ hasCustomerLeft: 'maybe',
785
+ selfConsultState: 'bogus-consult-state',
786
+ });
787
+
788
+ expect(isEpDnConsultPendingConferenceMerge(taskData, 'agent-1')).toBe(false);
789
+ });
790
+ });
740
791
  });