@webex/calling 0.0.1-next.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.
- package/README.md +67 -0
- package/dist/module/CallHistory/CallHistory.js +84 -0
- package/dist/module/CallHistory/callHistoryFixtures.js +307 -0
- package/dist/module/CallHistory/constants.js +9 -0
- package/dist/module/CallHistory/types.js +1 -0
- package/dist/module/CallSettings/CallSettings.js +65 -0
- package/dist/module/CallSettings/UcmBackendConnector.js +100 -0
- package/dist/module/CallSettings/WxCallBackendConnector.js +287 -0
- package/dist/module/CallSettings/constants.js +11 -0
- package/dist/module/CallSettings/testFixtures.js +62 -0
- package/dist/module/CallSettings/types.js +1 -0
- package/dist/module/CallingClient/CallingClient.js +268 -0
- package/dist/module/CallingClient/callRecordFixtures.js +93 -0
- package/dist/module/CallingClient/calling/CallerId/index.js +169 -0
- package/dist/module/CallingClient/calling/CallerId/types.js +1 -0
- package/dist/module/CallingClient/calling/call.js +1649 -0
- package/dist/module/CallingClient/calling/callManager.js +274 -0
- package/dist/module/CallingClient/calling/index.js +2 -0
- package/dist/module/CallingClient/calling/types.js +53 -0
- package/dist/module/CallingClient/callingClientFixtures.js +38 -0
- package/dist/module/CallingClient/constants.js +122 -0
- package/dist/module/CallingClient/line/index.js +110 -0
- package/dist/module/CallingClient/line/types.js +14 -0
- package/dist/module/CallingClient/registration/index.js +1 -0
- package/dist/module/CallingClient/registration/register.js +507 -0
- package/dist/module/CallingClient/registration/registerFixtures.js +28 -0
- package/dist/module/CallingClient/registration/types.js +1 -0
- package/dist/module/CallingClient/types.js +1 -0
- package/dist/module/Contacts/ContactsClient.js +487 -0
- package/dist/module/Contacts/constants.js +20 -0
- package/dist/module/Contacts/contactFixtures.js +284 -0
- package/dist/module/Contacts/types.js +10 -0
- package/dist/module/Errors/catalog/CallError.js +26 -0
- package/dist/module/Errors/catalog/CallingDeviceError.js +18 -0
- package/dist/module/Errors/catalog/ExtendedError.js +10 -0
- package/dist/module/Errors/catalog/LineError.js +24 -0
- package/dist/module/Errors/index.js +2 -0
- package/dist/module/Errors/types.js +48 -0
- package/dist/module/Events/impl/index.js +19 -0
- package/dist/module/Events/types.js +74 -0
- package/dist/module/Logger/index.js +114 -0
- package/dist/module/Logger/types.js +25 -0
- package/dist/module/Metrics/index.js +232 -0
- package/dist/module/Metrics/types.js +37 -0
- package/dist/module/SDKConnector/index.js +39 -0
- package/dist/module/SDKConnector/types.js +1 -0
- package/dist/module/SDKConnector/utils.js +12 -0
- package/dist/module/Voicemail/BroadworksBackendConnector.js +289 -0
- package/dist/module/Voicemail/UcmBackendConnector.js +275 -0
- package/dist/module/Voicemail/Voicemail.js +110 -0
- package/dist/module/Voicemail/WxCallBackendConnector.js +279 -0
- package/dist/module/Voicemail/constants.js +29 -0
- package/dist/module/Voicemail/types.js +1 -0
- package/dist/module/Voicemail/voicemailFixture.js +449 -0
- package/dist/module/common/Utils.js +802 -0
- package/dist/module/common/constants.js +40 -0
- package/dist/module/common/index.js +1 -0
- package/dist/module/common/testUtil.js +938 -0
- package/dist/module/common/types.js +57 -0
- package/dist/module/index.js +8 -0
- package/dist/types/CallHistory/CallHistory.d.ts +19 -0
- package/dist/types/CallHistory/CallHistory.d.ts.map +1 -0
- package/dist/types/CallHistory/callHistoryFixtures.d.ts +95 -0
- package/dist/types/CallHistory/callHistoryFixtures.d.ts.map +1 -0
- package/dist/types/CallHistory/constants.d.ts +10 -0
- package/dist/types/CallHistory/constants.d.ts.map +1 -0
- package/dist/types/CallHistory/types.d.ts +21 -0
- package/dist/types/CallHistory/types.d.ts.map +1 -0
- package/dist/types/CallSettings/CallSettings.d.ts +20 -0
- package/dist/types/CallSettings/CallSettings.d.ts.map +1 -0
- package/dist/types/CallSettings/UcmBackendConnector.d.ts +20 -0
- package/dist/types/CallSettings/UcmBackendConnector.d.ts.map +1 -0
- package/dist/types/CallSettings/WxCallBackendConnector.d.ts +22 -0
- package/dist/types/CallSettings/WxCallBackendConnector.d.ts.map +1 -0
- package/dist/types/CallSettings/constants.d.ts +12 -0
- package/dist/types/CallSettings/constants.d.ts.map +1 -0
- package/dist/types/CallSettings/testFixtures.d.ts +16 -0
- package/dist/types/CallSettings/testFixtures.d.ts.map +1 -0
- package/dist/types/CallSettings/types.d.ts +108 -0
- package/dist/types/CallSettings/types.d.ts.map +1 -0
- package/dist/types/CallingClient/CallingClient.d.ts +38 -0
- package/dist/types/CallingClient/CallingClient.d.ts.map +1 -0
- package/dist/types/CallingClient/callRecordFixtures.d.ts +4 -0
- package/dist/types/CallingClient/callRecordFixtures.d.ts.map +1 -0
- package/dist/types/CallingClient/calling/CallerId/index.d.ts +18 -0
- package/dist/types/CallingClient/calling/CallerId/index.d.ts.map +1 -0
- package/dist/types/CallingClient/calling/CallerId/types.d.ts +42 -0
- package/dist/types/CallingClient/calling/CallerId/types.d.ts.map +1 -0
- package/dist/types/CallingClient/calling/call.d.ts +95 -0
- package/dist/types/CallingClient/calling/call.d.ts.map +1 -0
- package/dist/types/CallingClient/calling/callManager.d.ts +22 -0
- package/dist/types/CallingClient/calling/callManager.d.ts.map +1 -0
- package/dist/types/CallingClient/calling/index.d.ts +3 -0
- package/dist/types/CallingClient/calling/index.d.ts.map +1 -0
- package/dist/types/CallingClient/calling/types.d.ts +204 -0
- package/dist/types/CallingClient/calling/types.d.ts.map +1 -0
- package/dist/types/CallingClient/callingClientFixtures.d.ts +19 -0
- package/dist/types/CallingClient/callingClientFixtures.d.ts.map +1 -0
- package/dist/types/CallingClient/constants.d.ts +123 -0
- package/dist/types/CallingClient/constants.d.ts.map +1 -0
- package/dist/types/CallingClient/line/index.d.ts +39 -0
- package/dist/types/CallingClient/line/index.d.ts.map +1 -0
- package/dist/types/CallingClient/line/types.d.ts +51 -0
- package/dist/types/CallingClient/line/types.d.ts.map +1 -0
- package/dist/types/CallingClient/registration/index.d.ts +2 -0
- package/dist/types/CallingClient/registration/index.d.ts.map +1 -0
- package/dist/types/CallingClient/registration/register.d.ts +65 -0
- package/dist/types/CallingClient/registration/register.d.ts.map +1 -0
- package/dist/types/CallingClient/registration/registerFixtures.d.ts +29 -0
- package/dist/types/CallingClient/registration/registerFixtures.d.ts.map +1 -0
- package/dist/types/CallingClient/registration/types.d.ts +21 -0
- package/dist/types/CallingClient/registration/types.d.ts.map +1 -0
- package/dist/types/CallingClient/types.d.ts +30 -0
- package/dist/types/CallingClient/types.d.ts.map +1 -0
- package/dist/types/Contacts/ContactsClient.d.ts +28 -0
- package/dist/types/Contacts/ContactsClient.d.ts.map +1 -0
- package/dist/types/Contacts/constants.d.ts +20 -0
- package/dist/types/Contacts/constants.d.ts.map +1 -0
- package/dist/types/Contacts/contactFixtures.d.ts +281 -0
- package/dist/types/Contacts/contactFixtures.d.ts.map +1 -0
- package/dist/types/Contacts/types.d.ts +75 -0
- package/dist/types/Contacts/types.d.ts.map +1 -0
- package/dist/types/Errors/catalog/CallError.d.ts +12 -0
- package/dist/types/Errors/catalog/CallError.d.ts.map +1 -0
- package/dist/types/Errors/catalog/CallingDeviceError.d.ts +11 -0
- package/dist/types/Errors/catalog/CallingDeviceError.d.ts.map +1 -0
- package/dist/types/Errors/catalog/ExtendedError.d.ts +7 -0
- package/dist/types/Errors/catalog/ExtendedError.d.ts.map +1 -0
- package/dist/types/Errors/catalog/LineError.d.ts +11 -0
- package/dist/types/Errors/catalog/LineError.d.ts.map +1 -0
- package/dist/types/Errors/index.d.ts +3 -0
- package/dist/types/Errors/index.d.ts.map +1 -0
- package/dist/types/Errors/types.d.ts +61 -0
- package/dist/types/Errors/types.d.ts.map +1 -0
- package/dist/types/Events/impl/index.d.ts +9 -0
- package/dist/types/Events/impl/index.d.ts.map +1 -0
- package/dist/types/Events/types.d.ts +284 -0
- package/dist/types/Events/types.d.ts.map +1 -0
- package/dist/types/Logger/index.d.ts +13 -0
- package/dist/types/Logger/index.d.ts.map +1 -0
- package/dist/types/Logger/types.d.ts +26 -0
- package/dist/types/Logger/types.d.ts.map +1 -0
- package/dist/types/Metrics/index.d.ts +6 -0
- package/dist/types/Metrics/index.d.ts.map +1 -0
- package/dist/types/Metrics/types.d.ts +43 -0
- package/dist/types/Metrics/types.d.ts.map +1 -0
- package/dist/types/SDKConnector/index.d.ts +13 -0
- package/dist/types/SDKConnector/index.d.ts.map +1 -0
- package/dist/types/SDKConnector/types.d.ts +129 -0
- package/dist/types/SDKConnector/types.d.ts.map +1 -0
- package/dist/types/SDKConnector/utils.d.ts +6 -0
- package/dist/types/SDKConnector/utils.d.ts.map +1 -0
- package/dist/types/Voicemail/BroadworksBackendConnector.d.ts +28 -0
- package/dist/types/Voicemail/BroadworksBackendConnector.d.ts.map +1 -0
- package/dist/types/Voicemail/UcmBackendConnector.d.ts +35 -0
- package/dist/types/Voicemail/UcmBackendConnector.d.ts.map +1 -0
- package/dist/types/Voicemail/Voicemail.d.ts +28 -0
- package/dist/types/Voicemail/Voicemail.d.ts.map +1 -0
- package/dist/types/Voicemail/WxCallBackendConnector.d.ts +24 -0
- package/dist/types/Voicemail/WxCallBackendConnector.d.ts.map +1 -0
- package/dist/types/Voicemail/constants.d.ts +30 -0
- package/dist/types/Voicemail/constants.d.ts.map +1 -0
- package/dist/types/Voicemail/types.d.ts +134 -0
- package/dist/types/Voicemail/types.d.ts.map +1 -0
- package/dist/types/Voicemail/voicemailFixture.d.ts +350 -0
- package/dist/types/Voicemail/voicemailFixture.d.ts.map +1 -0
- package/dist/types/common/Utils.d.ts +35 -0
- package/dist/types/common/Utils.d.ts.map +1 -0
- package/dist/types/common/constants.d.ts +41 -0
- package/dist/types/common/constants.d.ts.map +1 -0
- package/dist/types/common/index.d.ts +2 -0
- package/dist/types/common/index.d.ts.map +1 -0
- package/dist/types/common/testUtil.d.ts +3612 -0
- package/dist/types/common/testUtil.d.ts.map +1 -0
- package/dist/types/common/types.d.ts +192 -0
- package/dist/types/common/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +161 -0
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
import { FAILURE_MESSAGE, STATUS_CODE, SUCCESS_MESSAGE } from '../common/constants';
|
|
2
|
+
import { HTTP_METHODS } from '../common/types';
|
|
3
|
+
import SDKConnector from '../SDKConnector';
|
|
4
|
+
import log from '../Logger';
|
|
5
|
+
import { CONTACTS_FILE, CONTACTS_SCHEMA, CONTACT_FILTER, DEFAULT_GROUP_NAME, ENCRYPT_FILTER, GROUP_FILTER, USERS, encryptedFields, } from './constants';
|
|
6
|
+
import { ContactType, GroupType, } from './types';
|
|
7
|
+
import { serviceErrorCodeHandler } from '../common/Utils';
|
|
8
|
+
export class ContactsClient {
|
|
9
|
+
sdkConnector;
|
|
10
|
+
encryptionKeyUrl;
|
|
11
|
+
webex;
|
|
12
|
+
groups;
|
|
13
|
+
contacts;
|
|
14
|
+
defaultGroupId;
|
|
15
|
+
constructor(webex, logger) {
|
|
16
|
+
this.sdkConnector = SDKConnector;
|
|
17
|
+
if (!this.sdkConnector.getWebex()) {
|
|
18
|
+
SDKConnector.setWebex(webex);
|
|
19
|
+
}
|
|
20
|
+
this.webex = this.sdkConnector.getWebex();
|
|
21
|
+
this.encryptionKeyUrl = '';
|
|
22
|
+
this.groups = undefined;
|
|
23
|
+
this.contacts = undefined;
|
|
24
|
+
this.defaultGroupId = '';
|
|
25
|
+
log.setLogger(logger.level, CONTACTS_FILE);
|
|
26
|
+
}
|
|
27
|
+
getSDKConnector() {
|
|
28
|
+
return this.sdkConnector;
|
|
29
|
+
}
|
|
30
|
+
async decryptContactDetail(encryptionKeyUrl, contactDetails) {
|
|
31
|
+
const decryptedContactDetail = [...contactDetails];
|
|
32
|
+
const decryptedValues = await Promise.all(decryptedContactDetail.map((detail) => this.webex.internal.encryption.decryptText(encryptionKeyUrl, detail.value)));
|
|
33
|
+
decryptedValues.forEach((decryptedValue, index) => {
|
|
34
|
+
decryptedContactDetail[index].value = decryptedValue;
|
|
35
|
+
});
|
|
36
|
+
return decryptedContactDetail;
|
|
37
|
+
}
|
|
38
|
+
async encryptContactDetail(encryptionKeyUrl, contactDetails) {
|
|
39
|
+
const encryptedContactDetail = [...contactDetails];
|
|
40
|
+
const encryptedValues = await Promise.all(encryptedContactDetail.map((detail) => this.webex.internal.encryption.encryptText(encryptionKeyUrl, detail.value)));
|
|
41
|
+
encryptedValues.forEach((encryptedValue, index) => {
|
|
42
|
+
encryptedContactDetail[index].value = encryptedValue;
|
|
43
|
+
});
|
|
44
|
+
return encryptedContactDetail;
|
|
45
|
+
}
|
|
46
|
+
async encryptContact(contact) {
|
|
47
|
+
const { encryptionKeyUrl } = contact;
|
|
48
|
+
const encryptedContact = { ...contact };
|
|
49
|
+
const encryptionPromises = Object.values(encryptedFields).map(async (field) => {
|
|
50
|
+
switch (field) {
|
|
51
|
+
case encryptedFields.ADDRESS_INFO: {
|
|
52
|
+
const plaintextAddressInfo = encryptedContact.addressInfo;
|
|
53
|
+
let encryptedAddressInfo;
|
|
54
|
+
if (plaintextAddressInfo) {
|
|
55
|
+
const encryptedAddressInfoPromises = Object.entries(plaintextAddressInfo).map(async ([key, value]) => [
|
|
56
|
+
key,
|
|
57
|
+
await this.webex.internal.encryption.encryptText(encryptionKeyUrl, value),
|
|
58
|
+
]);
|
|
59
|
+
encryptedAddressInfo = Object.fromEntries(await Promise.all(encryptedAddressInfoPromises));
|
|
60
|
+
}
|
|
61
|
+
return [field, encryptedAddressInfo];
|
|
62
|
+
}
|
|
63
|
+
case encryptedFields.EMAILS:
|
|
64
|
+
case encryptedFields.PHONE_NUMBERS:
|
|
65
|
+
case encryptedFields.SIP_ADDRESSES: {
|
|
66
|
+
const plainTextDetails = encryptedContact[field];
|
|
67
|
+
let encryptedDetails;
|
|
68
|
+
if (plainTextDetails) {
|
|
69
|
+
encryptedDetails = await this.encryptContactDetail(encryptionKeyUrl, plainTextDetails);
|
|
70
|
+
}
|
|
71
|
+
return [field, encryptedDetails];
|
|
72
|
+
}
|
|
73
|
+
default: {
|
|
74
|
+
let encryptedValue;
|
|
75
|
+
if (Object.values(encryptedFields).includes(field) && encryptedContact[field]) {
|
|
76
|
+
encryptedValue = await this.webex.internal.encryption.encryptText(encryptionKeyUrl, encryptedContact[field]);
|
|
77
|
+
}
|
|
78
|
+
return [field, encryptedValue];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
const encryptedFieldsList = await Promise.all(encryptionPromises);
|
|
83
|
+
encryptedFieldsList.forEach(([field, value]) => {
|
|
84
|
+
if (value !== undefined) {
|
|
85
|
+
encryptedContact[field] = value;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return encryptedContact;
|
|
89
|
+
}
|
|
90
|
+
async decryptContact(contact) {
|
|
91
|
+
const { encryptionKeyUrl } = contact;
|
|
92
|
+
const decryptedContact = { ...contact };
|
|
93
|
+
const decryptionPromises = Object.values(encryptedFields).map(async (field) => {
|
|
94
|
+
switch (field) {
|
|
95
|
+
case encryptedFields.ADDRESS_INFO: {
|
|
96
|
+
const plaintextAddressInfo = decryptedContact.addressInfo;
|
|
97
|
+
let decryptedAddressInfo;
|
|
98
|
+
if (plaintextAddressInfo) {
|
|
99
|
+
const decryptedAddressInfoPromises = Object.entries(plaintextAddressInfo).map(async ([key, value]) => [
|
|
100
|
+
key,
|
|
101
|
+
await this.webex.internal.encryption.decryptText(encryptionKeyUrl, value),
|
|
102
|
+
]);
|
|
103
|
+
decryptedAddressInfo = Object.fromEntries(await Promise.all(decryptedAddressInfoPromises));
|
|
104
|
+
}
|
|
105
|
+
return [field, decryptedAddressInfo];
|
|
106
|
+
}
|
|
107
|
+
case encryptedFields.EMAILS:
|
|
108
|
+
case encryptedFields.PHONE_NUMBERS:
|
|
109
|
+
case encryptedFields.SIP_ADDRESSES: {
|
|
110
|
+
const plainTextDetails = decryptedContact[field];
|
|
111
|
+
let decryptedDetails;
|
|
112
|
+
if (plainTextDetails) {
|
|
113
|
+
decryptedDetails = await this.decryptContactDetail(encryptionKeyUrl, plainTextDetails);
|
|
114
|
+
}
|
|
115
|
+
return [field, decryptedDetails];
|
|
116
|
+
}
|
|
117
|
+
default: {
|
|
118
|
+
let decryptedValue;
|
|
119
|
+
if (Object.values(encryptedFields).includes(field) && decryptedContact[field]) {
|
|
120
|
+
decryptedValue = await this.webex.internal.encryption.decryptText(encryptionKeyUrl, decryptedContact[field]);
|
|
121
|
+
}
|
|
122
|
+
return [field, decryptedValue];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
const decryptedFieldsList = await Promise.all(decryptionPromises);
|
|
127
|
+
decryptedFieldsList.forEach(([field, value]) => {
|
|
128
|
+
if (value !== undefined) {
|
|
129
|
+
decryptedContact[field] = value;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return decryptedContact;
|
|
133
|
+
}
|
|
134
|
+
async fetchContactFromDSS(contactsDataMap) {
|
|
135
|
+
const contactList = [];
|
|
136
|
+
const dssResult = await this.webex.internal.dss.lookup({ ids: Object.keys(contactsDataMap) });
|
|
137
|
+
for (let i = 0; i < dssResult.length; i += 1) {
|
|
138
|
+
const contact = dssResult[i];
|
|
139
|
+
const contactId = contact.identity;
|
|
140
|
+
const { displayName, emails, phoneNumbers, sipAddresses, photos } = contact;
|
|
141
|
+
const { department, firstName, identityManager, jobTitle, lastName } = contact.additionalInfo;
|
|
142
|
+
const manager = identityManager && identityManager.displayName ? identityManager.displayName : undefined;
|
|
143
|
+
const { contactType, avatarUrlDomain, encryptionKeyUrl, ownerId, groups } = contactsDataMap[contactId];
|
|
144
|
+
let avatarURL = '';
|
|
145
|
+
if (photos.length) {
|
|
146
|
+
avatarURL = photos[0].value;
|
|
147
|
+
}
|
|
148
|
+
const addedPhoneNumbers = contactsDataMap[contactId].phoneNumbers;
|
|
149
|
+
if (addedPhoneNumbers) {
|
|
150
|
+
const decryptedPhoneNumbers = await this.decryptContactDetail(encryptionKeyUrl, addedPhoneNumbers);
|
|
151
|
+
decryptedPhoneNumbers.forEach((number) => phoneNumbers.push(number));
|
|
152
|
+
}
|
|
153
|
+
const addedSipAddresses = contactsDataMap[contactId].sipAddresses;
|
|
154
|
+
if (addedSipAddresses) {
|
|
155
|
+
const decryptedSipAddresses = await this.decryptContactDetail(encryptionKeyUrl, addedSipAddresses);
|
|
156
|
+
decryptedSipAddresses.forEach((address) => sipAddresses.push(address));
|
|
157
|
+
}
|
|
158
|
+
const cloudContact = {
|
|
159
|
+
avatarUrlDomain,
|
|
160
|
+
avatarURL,
|
|
161
|
+
contactId,
|
|
162
|
+
contactType,
|
|
163
|
+
department,
|
|
164
|
+
displayName,
|
|
165
|
+
emails,
|
|
166
|
+
encryptionKeyUrl,
|
|
167
|
+
firstName,
|
|
168
|
+
groups,
|
|
169
|
+
lastName,
|
|
170
|
+
manager,
|
|
171
|
+
ownerId,
|
|
172
|
+
phoneNumbers,
|
|
173
|
+
sipAddresses,
|
|
174
|
+
title: jobTitle,
|
|
175
|
+
};
|
|
176
|
+
contactList.push(cloudContact);
|
|
177
|
+
}
|
|
178
|
+
return contactList;
|
|
179
|
+
}
|
|
180
|
+
async getContacts() {
|
|
181
|
+
const loggerContext = {
|
|
182
|
+
file: CONTACTS_FILE,
|
|
183
|
+
method: 'getContacts',
|
|
184
|
+
};
|
|
185
|
+
const contactList = [];
|
|
186
|
+
const contactsDataMap = {};
|
|
187
|
+
try {
|
|
188
|
+
const response = await this.webex.request({
|
|
189
|
+
uri: `${this.webex.internal.services._serviceUrls.contactsService}/${ENCRYPT_FILTER}/${USERS}/${CONTACT_FILTER}`,
|
|
190
|
+
method: HTTP_METHODS.GET,
|
|
191
|
+
});
|
|
192
|
+
const responseBody = response.body;
|
|
193
|
+
if (!responseBody) {
|
|
194
|
+
throw new Error(`${response}`);
|
|
195
|
+
}
|
|
196
|
+
const { contacts, groups } = responseBody;
|
|
197
|
+
for (let i = 0; i < contacts.length; i += 1) {
|
|
198
|
+
const contact = contacts[i];
|
|
199
|
+
if (contact.contactType === ContactType.CUSTOM) {
|
|
200
|
+
const decryptedContact = await this.decryptContact(contact);
|
|
201
|
+
contactList.push(decryptedContact);
|
|
202
|
+
}
|
|
203
|
+
else if (contact.contactType === ContactType.CLOUD && contact.contactId) {
|
|
204
|
+
contactsDataMap[contact.contactId] = contact;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (Object.keys(contactsDataMap).length) {
|
|
208
|
+
const cloudContacts = await this.fetchContactFromDSS(contactsDataMap);
|
|
209
|
+
contactList.push(...cloudContacts);
|
|
210
|
+
}
|
|
211
|
+
await Promise.all(groups.map(async (group, idx) => {
|
|
212
|
+
groups[idx].displayName = await this.webex.internal.encryption.decryptText(group.encryptionKeyUrl, group.displayName);
|
|
213
|
+
}));
|
|
214
|
+
this.groups = groups;
|
|
215
|
+
this.contacts = contactList;
|
|
216
|
+
const contactResponse = {
|
|
217
|
+
statusCode: Number(response[STATUS_CODE]),
|
|
218
|
+
data: {
|
|
219
|
+
contacts: contactList,
|
|
220
|
+
groups,
|
|
221
|
+
},
|
|
222
|
+
message: SUCCESS_MESSAGE,
|
|
223
|
+
};
|
|
224
|
+
return contactResponse;
|
|
225
|
+
}
|
|
226
|
+
catch (err) {
|
|
227
|
+
const errorInfo = err;
|
|
228
|
+
const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
|
|
229
|
+
return errorStatus;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
async createNewEncryptionKeyUrl() {
|
|
233
|
+
const loggerContext = {
|
|
234
|
+
file: CONTACTS_FILE,
|
|
235
|
+
method: this.createNewEncryptionKeyUrl.name,
|
|
236
|
+
};
|
|
237
|
+
let unboundedKeyUri = '';
|
|
238
|
+
log.info('Requesting kms for a new KRO and key', loggerContext);
|
|
239
|
+
const unboundedKeys = await this.webex.internal.encryption.kms.createUnboundKeys({ count: 1 });
|
|
240
|
+
unboundedKeyUri = unboundedKeys[0].uri;
|
|
241
|
+
this.webex.internal.encryption.kms.createResource({ keyUris: [unboundedKeyUri] });
|
|
242
|
+
return unboundedKeyUri;
|
|
243
|
+
}
|
|
244
|
+
async fetchEncryptionKeyUrl() {
|
|
245
|
+
if (this.encryptionKeyUrl) {
|
|
246
|
+
return this.encryptionKeyUrl;
|
|
247
|
+
}
|
|
248
|
+
if (this.groups === undefined) {
|
|
249
|
+
this.getContacts();
|
|
250
|
+
}
|
|
251
|
+
if (this.groups && this.groups.length) {
|
|
252
|
+
return this.groups[0].encryptionKeyUrl;
|
|
253
|
+
}
|
|
254
|
+
this.encryptionKeyUrl = await this.createNewEncryptionKeyUrl();
|
|
255
|
+
log.info(`Creating a default group: ${DEFAULT_GROUP_NAME}`, {
|
|
256
|
+
file: CONTACTS_FILE,
|
|
257
|
+
method: this.fetchEncryptionKeyUrl.name,
|
|
258
|
+
});
|
|
259
|
+
const response = await this.createContactGroup(DEFAULT_GROUP_NAME, this.encryptionKeyUrl);
|
|
260
|
+
if (response.data.group?.groupId) {
|
|
261
|
+
this.defaultGroupId = response.data.group?.groupId;
|
|
262
|
+
}
|
|
263
|
+
return this.encryptionKeyUrl;
|
|
264
|
+
}
|
|
265
|
+
async fetchDefaultGroup() {
|
|
266
|
+
if (this.defaultGroupId) {
|
|
267
|
+
return this.defaultGroupId;
|
|
268
|
+
}
|
|
269
|
+
if (this.groups && this.groups.length) {
|
|
270
|
+
for (let i = 0; i < this.groups.length; i += 1) {
|
|
271
|
+
if (this.groups[i].displayName === DEFAULT_GROUP_NAME) {
|
|
272
|
+
this.defaultGroupId = this.groups[i].groupId;
|
|
273
|
+
return this.defaultGroupId;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
log.info('No default group found.', {
|
|
278
|
+
file: CONTACTS_FILE,
|
|
279
|
+
method: this.fetchDefaultGroup.name,
|
|
280
|
+
});
|
|
281
|
+
const response = await this.createContactGroup(DEFAULT_GROUP_NAME);
|
|
282
|
+
const { group } = response.data;
|
|
283
|
+
if (group) {
|
|
284
|
+
return group.groupId;
|
|
285
|
+
}
|
|
286
|
+
return '';
|
|
287
|
+
}
|
|
288
|
+
async createContactGroup(displayName, encryptionKeyUrl, groupType) {
|
|
289
|
+
const loggerContext = {
|
|
290
|
+
file: CONTACTS_FILE,
|
|
291
|
+
method: this.createContactGroup.name,
|
|
292
|
+
};
|
|
293
|
+
log.info(`Creating contact group ${displayName}`, loggerContext);
|
|
294
|
+
const encryptionKeyUrlFinal = encryptionKeyUrl || (await this.fetchEncryptionKeyUrl());
|
|
295
|
+
if (this.groups === undefined) {
|
|
296
|
+
await this.getContacts();
|
|
297
|
+
}
|
|
298
|
+
if (this.groups && this.groups.length) {
|
|
299
|
+
const isExistingGroup = this.groups.find((group) => {
|
|
300
|
+
return group.displayName === displayName;
|
|
301
|
+
});
|
|
302
|
+
if (isExistingGroup) {
|
|
303
|
+
log.warn(`Group name ${displayName} already exists.`, loggerContext);
|
|
304
|
+
return {
|
|
305
|
+
statusCode: 400,
|
|
306
|
+
data: { error: 'Group displayName already exists' },
|
|
307
|
+
message: FAILURE_MESSAGE,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const encryptedDisplayName = await this.webex.internal.encryption.encryptText(encryptionKeyUrlFinal, displayName);
|
|
312
|
+
const groupInfo = {
|
|
313
|
+
schemas: CONTACTS_SCHEMA,
|
|
314
|
+
displayName: encryptedDisplayName,
|
|
315
|
+
groupType: groupType || GroupType.NORMAL,
|
|
316
|
+
encryptionKeyUrl: encryptionKeyUrlFinal,
|
|
317
|
+
};
|
|
318
|
+
try {
|
|
319
|
+
const response = await this.webex.request({
|
|
320
|
+
uri: `${this.webex.internal.services._serviceUrls.contactsService}/${ENCRYPT_FILTER}/${USERS}/${GROUP_FILTER}`,
|
|
321
|
+
method: HTTP_METHODS.POST,
|
|
322
|
+
body: groupInfo,
|
|
323
|
+
});
|
|
324
|
+
const group = response.body;
|
|
325
|
+
group.displayName = displayName;
|
|
326
|
+
const contactResponse = {
|
|
327
|
+
statusCode: Number(response[STATUS_CODE]),
|
|
328
|
+
data: {
|
|
329
|
+
group,
|
|
330
|
+
},
|
|
331
|
+
message: SUCCESS_MESSAGE,
|
|
332
|
+
};
|
|
333
|
+
this.groups?.push(group);
|
|
334
|
+
return contactResponse;
|
|
335
|
+
}
|
|
336
|
+
catch (err) {
|
|
337
|
+
log.warn('Unable to create contact group.', loggerContext);
|
|
338
|
+
const errorInfo = err;
|
|
339
|
+
const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
|
|
340
|
+
return errorStatus;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
async deleteContactGroup(groupId) {
|
|
344
|
+
const loggerContext = {
|
|
345
|
+
file: CONTACTS_FILE,
|
|
346
|
+
method: this.deleteContactGroup.name,
|
|
347
|
+
};
|
|
348
|
+
try {
|
|
349
|
+
log.info(`Deleting contact group: ${groupId}`, loggerContext);
|
|
350
|
+
const response = await this.webex.request({
|
|
351
|
+
uri: `${this.webex.internal.services._serviceUrls.contactsService}/${ENCRYPT_FILTER}/${USERS}/${GROUP_FILTER}/${groupId}`,
|
|
352
|
+
method: HTTP_METHODS.DELETE,
|
|
353
|
+
});
|
|
354
|
+
const contactResponse = {
|
|
355
|
+
statusCode: Number(response[STATUS_CODE]),
|
|
356
|
+
data: {},
|
|
357
|
+
message: SUCCESS_MESSAGE,
|
|
358
|
+
};
|
|
359
|
+
const groupToDelete = this.groups?.findIndex((group) => group.groupId === groupId);
|
|
360
|
+
if (groupToDelete !== undefined && groupToDelete !== -1) {
|
|
361
|
+
this.groups?.splice(groupToDelete, 1);
|
|
362
|
+
}
|
|
363
|
+
if (!this.groups?.length) {
|
|
364
|
+
this.defaultGroupId = '';
|
|
365
|
+
}
|
|
366
|
+
return contactResponse;
|
|
367
|
+
}
|
|
368
|
+
catch (err) {
|
|
369
|
+
log.warn(`Unable to delete contact group ${groupId}`, loggerContext);
|
|
370
|
+
const errorInfo = err;
|
|
371
|
+
const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
|
|
372
|
+
return errorStatus;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
async createContact(contactInfo) {
|
|
376
|
+
const loggerContext = {
|
|
377
|
+
file: CONTACTS_FILE,
|
|
378
|
+
method: this.createContact.name,
|
|
379
|
+
};
|
|
380
|
+
log.info(`Request to create contact: contactType: ${contactInfo.contactType}`, loggerContext);
|
|
381
|
+
try {
|
|
382
|
+
const contact = { ...contactInfo };
|
|
383
|
+
if (!contact.encryptionKeyUrl) {
|
|
384
|
+
contact.encryptionKeyUrl = await this.fetchEncryptionKeyUrl();
|
|
385
|
+
}
|
|
386
|
+
if (!contact.groups || contact.groups.length === 0) {
|
|
387
|
+
const defaultGroupId = await this.fetchDefaultGroup();
|
|
388
|
+
contact.groups = [defaultGroupId];
|
|
389
|
+
}
|
|
390
|
+
contact.schemas = CONTACTS_SCHEMA;
|
|
391
|
+
let requestBody = {};
|
|
392
|
+
switch (contact.contactType) {
|
|
393
|
+
case ContactType.CUSTOM: {
|
|
394
|
+
const encryptedContact = await this.encryptContact(contact);
|
|
395
|
+
requestBody = encryptedContact;
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
case ContactType.CLOUD: {
|
|
399
|
+
if (!contact.contactId) {
|
|
400
|
+
return {
|
|
401
|
+
statusCode: 400,
|
|
402
|
+
data: {
|
|
403
|
+
error: 'contactId is required for contactType:CLOUD.',
|
|
404
|
+
},
|
|
405
|
+
message: FAILURE_MESSAGE,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
const encryptedContact = await this.encryptContact(contact);
|
|
409
|
+
requestBody = encryptedContact;
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
default: {
|
|
413
|
+
return {
|
|
414
|
+
statusCode: 400,
|
|
415
|
+
data: {
|
|
416
|
+
error: 'Unknown contactType received.',
|
|
417
|
+
},
|
|
418
|
+
message: FAILURE_MESSAGE,
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const response = await this.webex.request({
|
|
423
|
+
uri: `${this.webex.internal.services._serviceUrls.contactsService}/${ENCRYPT_FILTER}/${USERS}/${CONTACT_FILTER}`,
|
|
424
|
+
method: HTTP_METHODS.POST,
|
|
425
|
+
body: requestBody,
|
|
426
|
+
});
|
|
427
|
+
const newContact = response.body;
|
|
428
|
+
contact.contactId = newContact.contactId;
|
|
429
|
+
const contactResponse = {
|
|
430
|
+
statusCode: Number(response[STATUS_CODE]),
|
|
431
|
+
data: {
|
|
432
|
+
contact,
|
|
433
|
+
},
|
|
434
|
+
message: SUCCESS_MESSAGE,
|
|
435
|
+
};
|
|
436
|
+
if (contact.contactType === ContactType.CLOUD) {
|
|
437
|
+
const decryptedContacts = await this.fetchContactFromDSS(Object.fromEntries([[newContact.contactId, newContact]]));
|
|
438
|
+
if (decryptedContacts.length && decryptedContacts[0]) {
|
|
439
|
+
this.contacts?.push(decryptedContacts[0]);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
this.contacts?.push(contact);
|
|
444
|
+
}
|
|
445
|
+
return contactResponse;
|
|
446
|
+
}
|
|
447
|
+
catch (err) {
|
|
448
|
+
log.warn('Failed to create contact.', {
|
|
449
|
+
file: CONTACTS_FILE,
|
|
450
|
+
method: this.createContact.name,
|
|
451
|
+
});
|
|
452
|
+
const errorInfo = err;
|
|
453
|
+
const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
|
|
454
|
+
return errorStatus;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
async deleteContact(contactId) {
|
|
458
|
+
const loggerContext = {
|
|
459
|
+
file: CONTACTS_FILE,
|
|
460
|
+
method: this.deleteContact.name,
|
|
461
|
+
};
|
|
462
|
+
try {
|
|
463
|
+
log.info(`Deleting contact : ${contactId}`, loggerContext);
|
|
464
|
+
const response = await this.webex.request({
|
|
465
|
+
uri: `${this.webex.internal.services._serviceUrls.contactsService}/${ENCRYPT_FILTER}/${USERS}/${CONTACT_FILTER}/${contactId}`,
|
|
466
|
+
method: HTTP_METHODS.DELETE,
|
|
467
|
+
});
|
|
468
|
+
const contactResponse = {
|
|
469
|
+
statusCode: Number(response[STATUS_CODE]),
|
|
470
|
+
data: {},
|
|
471
|
+
message: SUCCESS_MESSAGE,
|
|
472
|
+
};
|
|
473
|
+
const contactToDelete = this.contacts?.findIndex((contact) => contact.contactId === contactId);
|
|
474
|
+
if (contactToDelete !== undefined && contactToDelete !== -1) {
|
|
475
|
+
this.contacts?.splice(contactToDelete, 1);
|
|
476
|
+
}
|
|
477
|
+
return contactResponse;
|
|
478
|
+
}
|
|
479
|
+
catch (err) {
|
|
480
|
+
log.warn(`Unable to delete contact ${contactId}`, loggerContext);
|
|
481
|
+
const errorInfo = err;
|
|
482
|
+
const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
|
|
483
|
+
return errorStatus;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
export const createContactsClient = (webex, logger) => new ContactsClient(webex, logger);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const CONTACTS_FILE = 'Contacts';
|
|
2
|
+
export const CONTACT_FILTER = 'contacts';
|
|
3
|
+
export const GROUP_FILTER = 'groups';
|
|
4
|
+
export const ENCRYPT_FILTER = 'encrypt';
|
|
5
|
+
export const USERS = 'Users';
|
|
6
|
+
export const DEFAULT_GROUP_NAME = 'Other contacts';
|
|
7
|
+
export const CONTACTS_SCHEMA = 'urn:cisco:codev:identity:contact:core:1.0';
|
|
8
|
+
export var encryptedFields;
|
|
9
|
+
(function (encryptedFields) {
|
|
10
|
+
encryptedFields["ADDRESS_INFO"] = "addressInfo";
|
|
11
|
+
encryptedFields["AVATAR_URL"] = "avatarURL";
|
|
12
|
+
encryptedFields["COMPANY"] = "companyName";
|
|
13
|
+
encryptedFields["DISPLAY_NAME"] = "displayName";
|
|
14
|
+
encryptedFields["EMAILS"] = "emails";
|
|
15
|
+
encryptedFields["FIRST_NAME"] = "firstName";
|
|
16
|
+
encryptedFields["LAST_NAME"] = "lastName";
|
|
17
|
+
encryptedFields["PHONE_NUMBERS"] = "phoneNumbers";
|
|
18
|
+
encryptedFields["SIP_ADDRESSES"] = "sipAddresses";
|
|
19
|
+
encryptedFields["TITLE"] = "title";
|
|
20
|
+
})(encryptedFields || (encryptedFields = {}));
|