@crmcom/self-service-sdk 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/account.js ADDED
@@ -0,0 +1,144 @@
1
+ import { httpUtil } from './httpUtil'
2
+ import { ErrorCodes, createResult, createCommonResult } from './resultUtil'
3
+ import { logger } from './logger';
4
+
5
+ export const account = {
6
+ getPrimaryAccount,
7
+ getAccount,
8
+ getAccountJournals,
9
+ getAccountJournal,
10
+ getAccountRewards,
11
+ getAccountBalance
12
+ }
13
+
14
+ async function getPrimaryAccount() {
15
+ try {
16
+ let id = httpUtil.getSession().sub;
17
+ let response = await httpUtil.get({
18
+ resourcePath: '/v2/contacts/' + id + '/accounts',
19
+ queryParams: { is_primary: true },
20
+ withAccessToken: true
21
+ });
22
+ return createCommonResult(response);
23
+ } catch (e) {
24
+ logger.error('Exception register:', e);
25
+ return createResult(ErrorCodes.UNKNOWN, e);
26
+ }
27
+ }
28
+
29
+ async function getAccount(accountId) {
30
+ try {
31
+ let id = httpUtil.getSession().sub;
32
+ let response = await httpUtil.get({
33
+ resourcePath: '/v2/accounts/' + accountId ,
34
+ withAccessToken: true
35
+ });
36
+ return createCommonResult(response);
37
+ } catch (e) {
38
+ logger.error('Exception register:', e);
39
+ return createResult(ErrorCodes.UNKNOWN, e);
40
+ }
41
+ }
42
+
43
+ async function getAccountJournals({
44
+ include_total,
45
+ from_date,
46
+ to_date,
47
+ transaction_type,
48
+ type,
49
+ page,
50
+ size,
51
+ sort,
52
+ order
53
+ }={},accountId) {
54
+ try {
55
+ if(!accountId){
56
+ let primeAccRes = await getPrimaryAccount();
57
+ if (primeAccRes.code != ErrorCodes.OK)
58
+ return primeAccRes;
59
+ if (!primeAccRes.data.content && primeAccRes.data.content.size() == 0)
60
+ return createResult(ErrorCodes.ACCOUNT_NOT_FOUND, response.error);
61
+ accountId = primeAccRes.data.content[0].id;
62
+ }
63
+ let query = {
64
+ include_total,
65
+ transaction_type,
66
+ type,
67
+ page,
68
+ size,
69
+ sort,
70
+ order
71
+ }
72
+ if(from_date){
73
+ query['posted_on[gte]'] = from_date
74
+ }
75
+ if(to_date){
76
+ query['posted_on[lte]'] = to_date
77
+ }
78
+ let response = await httpUtil.get({
79
+ resourcePath: '/v2/accounts/' + accountId + '/journals',
80
+ queryParams: query,
81
+ withAccessToken: true
82
+ });
83
+ return createCommonResult(response);
84
+ } catch (e) {
85
+ logger.error('Exception getAccountJournals:', e);
86
+ return createResult(ErrorCodes.UNKNOWN, e);
87
+ }
88
+ }
89
+
90
+ async function getAccountJournal(id) {
91
+ try {
92
+
93
+ let response = await httpUtil.get({
94
+ resourcePath: '/v2/journals/' + id,
95
+ withAccessToken: true
96
+ });
97
+ return createCommonResult(response);
98
+ } catch (e) {
99
+ logger.error('Exception getAccountJournal:', e);
100
+ return createResult(ErrorCodes.UNKNOWN, e);
101
+ }
102
+ }
103
+
104
+ async function getAccountRewards(accountId, include_rewards) {
105
+ try {
106
+ if (!accountId) {
107
+ let primeAccRes = await getPrimaryAccount();
108
+ if (primeAccRes.code != ErrorCodes.OK)
109
+ return primeAccRes;
110
+ if (!primeAccRes.data.content && primeAccRes.data.content.size() == 0)
111
+ return createResult(ErrorCodes.ACCOUNT_NOT_FOUND, response.error);
112
+ accountId = primeAccRes.data.content[0].id;
113
+ }
114
+ let response = await httpUtil.get({
115
+ resourcePath: '/v1/accounts/' + accountId + '/rewards',
116
+ queryParams: { include_rewards },
117
+ withAccessToken: true
118
+ });
119
+ //check return code here instead of put as there would be different intepretation for different API
120
+ return createCommonResult(response);
121
+ } catch (e) {
122
+ logger.error('Exception getAccountRewards:', e);
123
+ return createResult(ErrorCodes.UNKNOWN, e);
124
+ }
125
+ }
126
+
127
+
128
+
129
+ async function getAccountBalance() {
130
+ try {
131
+ let accountsResult = await getPrimaryAccount();
132
+ if(accountsResult.code =='OK' && accountsResult.data.content && accountsResult.data.content.length > 0){
133
+ let response = await httpUtil.get({
134
+ resourcePath: '/v2/accounts/' + accountsResult.data.content[0].id,
135
+ withAccessToken: true
136
+ });
137
+ return createCommonResult(response);
138
+ }
139
+ return createCommonResult(accountsResult);
140
+ } catch (e) {
141
+ logger.error('Exception register:', e);
142
+ return createResult(ErrorCodes.UNKNOWN, e);
143
+ }
144
+ }
@@ -0,0 +1,475 @@
1
+ import { httpUtil } from "./httpUtil";
2
+ import { ErrorCodes, createResult, createCommonResult } from "./resultUtil";
3
+ import { logger } from './logger';
4
+ export const authentication = {
5
+ authenticatePhone,
6
+ authenticateEmail,
7
+ authenticateGuest,
8
+ authenticateFacebook,
9
+ authenticateFacebookOIDC,
10
+ authenticateSSOOIDC,
11
+ sendEmailVerification,
12
+ validateOTP,
13
+ registerByPhone,
14
+ registerByEmail,
15
+ registerByFacebook,
16
+ requestOTP,
17
+ addContactIdentityEmail,
18
+ addContactIdentityPhone,
19
+ forgotPassword,
20
+ contactAuthenticate
21
+ }
22
+
23
+ async function authenticatePhone({ phone_number, country_code, application_id },
24
+ startSession = false) {
25
+ let body = {
26
+ provider: "PHONE",
27
+ application_id,
28
+ phone:{
29
+ number: phone_number,
30
+ country_code: country_code
31
+ }
32
+ }
33
+ return authenticate(body,startSession);
34
+ }
35
+
36
+ async function authenticateEmail({ username, password, application_id }, startSession = true) {
37
+ let body = {
38
+ provider: "EMAIL",
39
+ username,
40
+ password,
41
+ application_id
42
+ }
43
+ return authenticate(body,startSession);
44
+ }
45
+
46
+ async function authenticateGuest({ }, startSession = true) {
47
+ let body = {
48
+ login_as_guest: true
49
+ }
50
+ return authenticate(body,startSession);
51
+ }
52
+
53
+ async function authenticateFacebook({ token, application_id }, startSession = true) {
54
+ let body = {
55
+ provider: "FACEBOOK",
56
+ token,
57
+ application_id
58
+ }
59
+ return authenticate(body,startSession);
60
+ }
61
+
62
+ async function authenticateFacebookOIDC({ state, code }, startSession = true) {
63
+ let body = {
64
+ provider: "FACEBOOK",
65
+ state : state,
66
+ code : code,
67
+ }
68
+ return authenticate(body,startSession);
69
+ }
70
+
71
+ async function authenticateSSOOIDC({ state, code }, startSession = true) {
72
+ let body = {
73
+ provider: "OIDC_OAUTH",
74
+ state : state,
75
+ code : code,
76
+ }
77
+ return authenticate(body,startSession);
78
+ }
79
+
80
+ async function authenticate(contact, startSession = true) {
81
+ try {
82
+ //console.log('API: ', contact)
83
+ let response = await httpUtil.post({
84
+ resourcePath: "/v2/contacts/authenticate",
85
+ body: contact,
86
+ logOutIfSessionInvalid: false,
87
+ });
88
+ if (startSession == true && response.code == "OK" && response.data && response.data.access_token) {
89
+ httpUtil.startSession(response.data);
90
+ }
91
+ //check return code here instead of put as there would be different intepretation for different API
92
+ if (response.code == "OK") {
93
+ if (response.data.auth_otp || response.data.access_token) {
94
+ return createResult(ErrorCodes.OK, response.data);
95
+ } else {
96
+ return createResult(ErrorCodes.INVALID_LOGIN, response.error);
97
+ }
98
+ } else {
99
+ if (
100
+ response.error &&
101
+ response.error.message == "COM.CRM.EXCEPTIONS.INVALIDLOGINEXCEPTION"
102
+ ) {
103
+ return createResult(ErrorCodes.INVALID_LOGIN, response.error);
104
+ } else if (response.error &&
105
+ response.error.error == "COM.CRM.EXCEPTIONS.EMAILNOTVERIFIEDEXCEPTION") {
106
+ return createResult(ErrorCodes.EMAIL_NOT_VERIFIED, response.error);
107
+ } else if (response.code == '429' || response.code === 429) {
108
+ return createResult(ErrorCodes.TOO_MANY_REQUESTS, response.error);
109
+ } else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION") {
110
+ return createResult(ErrorCodes.CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION, response.error);
111
+ }
112
+ else return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
113
+ }
114
+ } catch (e) {
115
+ logger.error("Exception register:", e);
116
+ return createResult(ErrorCodes.UNKNOWN, e);
117
+ }
118
+ }
119
+
120
+ async function contactAuthenticate(type, redirectUri) {
121
+ try {
122
+ let response = await httpUtil.get({
123
+ resourcePath: "/v2/contacts/oidc/" + type ,
124
+ queryParams: { redirect_url: redirectUri },
125
+ logOutIfSessionInvalid : false,
126
+ withAccessToken : false
127
+
128
+ });
129
+ return createCommonResult(response);
130
+ } catch (e) {
131
+ logger.error("Exception register:", e);
132
+ return createResult(ErrorCodes.UNKNOWN, e);
133
+ }
134
+ }
135
+
136
+ async function sendEmailVerification(email) {
137
+ try {
138
+ let response = await httpUtil.post({
139
+ resourcePath: "/v2/contacts/request_email_verification",
140
+ body: {
141
+ email_address: email
142
+ },
143
+ logOutIfSessionInvalid: false
144
+ });
145
+ //check return code here instead of put as there would be different intepretation for different API
146
+ return createCommonResult(response);
147
+ } catch (e) {
148
+ logger.error("Exception register:", e);
149
+ return createResult(ErrorCodes.UNKNOWN, e);
150
+ }
151
+ }
152
+
153
+
154
+ async function validateOTP({ auth_otp,otp }, startSession = true) {
155
+ try {
156
+ let response = await httpUtil.post({
157
+ resourcePath: "/v2/contacts/validate_otp",
158
+ body: {
159
+ auth_otp,
160
+ code: otp
161
+ },
162
+ logOutIfSessionInvalid: false
163
+ });
164
+ //check return code here instead of put as there would be different intepretation for different API
165
+ if (startSession == true && response.code == "OK") {
166
+ httpUtil.startSession(response.data);
167
+ }
168
+ if (response.code == "OK")
169
+ return createResult(ErrorCodes.OK, response.data);
170
+ else {
171
+ if (
172
+ response.error &&
173
+ response.error.message == "COM.CRM.EXCEPTIONS.INVALIDLOGINEXCEPTION"
174
+ ) {
175
+ return createResult(ErrorCodes.INVALID_LOGIN, response.error);
176
+ } else return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
177
+ }
178
+ } catch (e) {
179
+ logger.error("Exception register:", e);
180
+ return createResult(ErrorCodes.UNKNOWN, e);
181
+ }
182
+ }
183
+
184
+ async function registerByPhone(
185
+ {
186
+ first_name,
187
+ last_name,
188
+ phone,
189
+ country_code,
190
+ referral_code,
191
+ sms_opt_out,
192
+ email_opt_out,
193
+ country_agreement,
194
+ language_code,
195
+ custom_fields,
196
+ accept_term_conditions=true,
197
+ validation_required,
198
+ pass_code
199
+ },
200
+ startSession = false
201
+ ) {
202
+ let body = {
203
+ first_name,
204
+ last_name,
205
+ identification: {
206
+ provider: "PHONE",
207
+ phone: {
208
+ number: phone,
209
+ country_code: country_code,
210
+ }
211
+ },
212
+ "accept_terms_&_conditions": accept_term_conditions,
213
+ email_opt_out: !email_opt_out,
214
+ sms_opt_out: !sms_opt_out,
215
+ country_of_agreement: country_agreement,
216
+ language_code,
217
+ custom_fields,
218
+ validation_required,
219
+ pass_code
220
+ };
221
+ if (referral_code) {
222
+ body.referral_code = referral_code;
223
+ }
224
+ return await register(body,startSession);
225
+ }
226
+
227
+
228
+ async function registerByEmail(
229
+ {
230
+ first_name,
231
+ last_name,
232
+ email,
233
+ password,
234
+ referral_code,
235
+ sms_opt_out,
236
+ email_opt_out,
237
+ country_agreement,
238
+ language_code,
239
+ custom_fields,
240
+ accept_term_conditions=true,
241
+ validation_required,
242
+ pass_code
243
+ },
244
+ startSession = false
245
+ ) {
246
+ let body = {
247
+ first_name,
248
+ last_name,
249
+ identification: {
250
+ provider: "EMAIL",
251
+ email,
252
+ password
253
+ },
254
+ "accept_terms_&_conditions": accept_term_conditions,
255
+ email_opt_out: !email_opt_out,
256
+ sms_opt_out: !sms_opt_out,
257
+ country_of_agreement: country_agreement,
258
+ language_code,
259
+ custom_fields,
260
+ validation_required,
261
+ pass_code
262
+ };
263
+ if (referral_code) {
264
+ body.referral_code = referral_code;
265
+ }
266
+ return await register(body,startSession);
267
+ }
268
+
269
+ async function registerByFacebook(
270
+ {
271
+ accept_term_conditions=true,
272
+ application_id,
273
+ sms_opt_out,
274
+ email_opt_out,
275
+ token
276
+ },
277
+ startSession = false
278
+ ) {
279
+ let body = {
280
+ "accept_terms_&_conditions": accept_term_conditions,
281
+ email_opt_out: !email_opt_out,
282
+ sms_opt_out: !sms_opt_out,
283
+ identification: {
284
+ provider: "FACEBOOK",
285
+ application_id,
286
+ token
287
+ }
288
+ };
289
+ return await register(body,startSession);
290
+ }
291
+
292
+ async function register(body,startSession = true) {
293
+ try {
294
+ let response = await httpUtil.post({
295
+ resourcePath: "/v2/contacts/register",
296
+ body: body,
297
+ logOutIfSessionInvalid: false,
298
+ });
299
+ if (startSession == true && response.code == "OK") {
300
+ httpUtil.startSession(response.data);
301
+ }
302
+ //check return code here instead of put as there would be different intepretation for different API
303
+ if (response.code == "OK")
304
+ return createResult(ErrorCodes.OK, response.data);
305
+ else {
306
+ if (
307
+ response.error && (response.error.error == "COM.CRM.EXCEPTIONS.MORETHANONEENTITYEXISTSEXCEPTION" || response.error.error == 'CRM.EXCEPTIONS.MORETHANONEENTITYEXISTSEXCEPTION')
308
+ ) {
309
+ return createResult(
310
+ ErrorCodes.REGISTRATION_FAIL_CONTACT_EXISTS,
311
+ response.error
312
+ );
313
+ }else if(response.error && response.error.error == "CRM.EXCEPTIONS.INVALIDVALUEEXCEPTION"){
314
+ return createResult(
315
+ ErrorCodes.INVALIDVALUEEXCEPTION,
316
+ response.error
317
+ );
318
+ }
319
+ else if(response.error && response.error.error == "CRM.EXCEPTIONS.NOTFOUNDEXCEPTION"){
320
+ return createResult(
321
+ ErrorCodes.REDEEM_PASS_INVALID,
322
+ response.error
323
+ );
324
+ }
325
+ else if(response.error && response.error.error == "COM.CRM.EXCEPTIONS.THISPASSHASALREADYBEENREDEEMEDEXCEPTION"){
326
+ return createResult(
327
+ ErrorCodes.REDEEM_PASS_USED,
328
+ response.error
329
+ );
330
+ }
331
+ else if(response.error && response.error.error === "COM.CRM.EXCEPTIONS.ONLYACTIVEPASSESCANBEREDEEMEDEXCEPTION"){
332
+ return createResult(
333
+ ErrorCodes.REDEEM_PASS_NOT_ACTIVE,
334
+ response.error
335
+ );
336
+ }
337
+ else
338
+ return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
339
+ }
340
+ } catch (e) {
341
+ logger.error("Exception register:", e);
342
+ return createResult(ErrorCodes.UNKNOWN, e);
343
+ }
344
+ }
345
+
346
+ async function requestOTP({method,phone,email,id_number,loyalty_identifier,statutory_id}) {
347
+ try {
348
+ let credentials = [];
349
+ if(phone){
350
+ credentials.push({
351
+ name: "PHONE",
352
+ value: phone,
353
+ })
354
+ }
355
+ if(email){
356
+ credentials.push({
357
+ name: "EMAIL",
358
+ value: email,
359
+ })
360
+ }
361
+ if(id_number){
362
+ credentials.push({
363
+ name: "ID_NUMBER",
364
+ value: id_number,
365
+ })
366
+ }
367
+ if(loyalty_identifier){
368
+ credentials.push({
369
+ name: "LOYALTY_IDENTIFIER",
370
+ value: loyalty_identifier,
371
+ })
372
+ }
373
+ if(statutory_id){
374
+ credentials.push({
375
+ name: "STATUTORY_ID",
376
+ value: statutory_id,
377
+ })
378
+ }
379
+ let response = await httpUtil.post({
380
+ resourcePath: "/v2/contacts/otp",
381
+ body: {
382
+ method: method,
383
+ credentials: credentials
384
+ },
385
+ logOutIfSessionInvalid: false
386
+ });
387
+ //check return code here instead of put as there would be different intepretation for different API
388
+ return createCommonResult(response);
389
+ } catch (e) {
390
+ logger.error("Exception register:", e);
391
+ return createResult(ErrorCodes.UNKNOWN, e);
392
+ }
393
+ }
394
+
395
+ async function addContactIdentityEmail({email, password, validation_required,contact_id,access_token}) {
396
+ let body = {
397
+ provider: "EMAIL",
398
+ email: email,
399
+ password: password,
400
+ validation_required: validation_required != null || validation_required != undefined ? validation_required : true,
401
+ }
402
+ return addContactIdentity(body,contact_id,access_token)
403
+ }
404
+
405
+ async function addContactIdentityPhone({phone,country_code,contact_id,access_token}) {
406
+ let body = {
407
+ provider: "PHONE",
408
+ phone:{
409
+ number: phone,
410
+ country_code: country_code
411
+ }
412
+ }
413
+ return addContactIdentity(body,contact_id,access_token)
414
+ }
415
+ async function addContactIdentity(body,contactId,accessToken) {
416
+ try {
417
+ let response = await httpUtil.post({
418
+ resourcePath: "/v2/contacts/" + contactId + "/identities",
419
+ body: body,
420
+ withAccessToken: true,
421
+ accessToken: accessToken
422
+ });
423
+ logger.debug('Identity add response received')
424
+ if (response.code == "OK")
425
+ return createResult(ErrorCodes.OK, response.data);
426
+ else {
427
+ logger.debug("Identity add error:", response.error)
428
+ if (response.error && (response.error.error == "COM.CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION" || response.error.error == "CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION")) {
429
+ return createResult(
430
+ ErrorCodes.REGISTRATION_FAIL_CONTACT_EXISTS,
431
+ response.error
432
+ );
433
+ } else if (response.error && (response.error.error == "COM.CRM.EXCEPTIONS.INVALIDPASSWORDEXCEPTION" || response.error.error == "CRM.EXCEPTIONS.INVALIDPASSWORDEXCEPTION")) {
434
+ return createResult(
435
+ ErrorCodes.INVALID_PASSWORD_EXCEPTION,
436
+ response.error
437
+ );
438
+ } else if (response.error && (response.error.error == "COM.CRM.EXCEPTIONS.INVALIDCONTACTPASSWORDEXCEPTION" || response.error.error == "CRM.EXCEPTIONS.INVALIDCONTACTPASSWORDEXCEPTION")) {
439
+ return createResult(
440
+ "INVALID_CONTACTPASSWORD_EXCEPTION",
441
+ response.error
442
+ );
443
+ }
444
+ else return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
445
+ }
446
+ } catch (e) {
447
+ logger.error("Exception register:", e);
448
+ return createResult(ErrorCodes.UNKNOWN, e);
449
+ }
450
+ }
451
+
452
+ async function forgotPassword(email) {
453
+ try {
454
+ let response = await httpUtil.post({
455
+ resourcePath: "/v2/contacts/forgot_password",
456
+ body: {
457
+ username: email,
458
+ },
459
+ logOutIfSessionInvalid: false
460
+ });
461
+ if (response.code == "OK")
462
+ return createResult(ErrorCodes.OK, response.data);
463
+ else {
464
+ if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.INVALIDVALUEEXCEPTION") {
465
+ return createResult(ErrorCodes.FORGOT_EMAIL_NOT_FOUND_EXCEPTION, response.error);
466
+ } else if (response.code == '429') {
467
+ return createResult(ErrorCodes.TOO_MANY_REQUESTS, response.error);
468
+ } else return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
469
+ }
470
+ } catch (e) {
471
+ logger.error("Exception update phone:", e);
472
+ return createResult(ErrorCodes.UNKNOWN, e);
473
+ }
474
+ }
475
+
@@ -0,0 +1,94 @@
1
+ import { httpUtil } from './httpUtil'
2
+ import { ErrorCodes, createResult, createCommonResult } from './resultUtil'
3
+ import { logger } from './logger';
4
+
5
+ export const communications = {
6
+ getCommunications,
7
+ getCommunication,
8
+ markReadCommunication,
9
+ deleteCommunication,
10
+ }
11
+
12
+ async function getCommunications({
13
+ archived = false,
14
+ channel = 'INAPP',
15
+ page = 1,
16
+ size = 20,
17
+ sort,
18
+ order,
19
+ viewed,
20
+ created_on_gte,
21
+ created_on_lte
22
+ } = {}) {
23
+ try {
24
+ let id = httpUtil.getSession().sub;
25
+ //console.log('API: ', contact)
26
+ let response = await httpUtil.get({
27
+ resourcePath: '/v2/contacts/' + id + '/communications',
28
+ queryParams: {
29
+ archived,
30
+ channel,
31
+ page,
32
+ size,
33
+ sort,
34
+ order,
35
+ viewed,
36
+ "created_on[gte]": created_on_gte,
37
+ "created_on[lte]": created_on_lte
38
+ },
39
+ withAccessToken: true
40
+ });
41
+ return createCommonResult(response);
42
+ } catch (e) {
43
+ logger.error('Exception getCommunications:', e);
44
+ return createResult(ErrorCodes.UNKNOWN, e);
45
+ }
46
+ }
47
+
48
+ async function getCommunication(id) {
49
+ try {
50
+ let response = await httpUtil.get({
51
+ resourcePath: '/v2/communications/' + id,
52
+ withAccessToken: true
53
+ });
54
+ //check return code here instead of put as there would be different intepretation for different API
55
+ return createCommonResult(response);
56
+ } catch (e) {
57
+ logger.error('Exception getCommunication:', e);
58
+ return createResult(ErrorCodes.UNKNOWN, e);
59
+ }
60
+ }
61
+
62
+ async function markReadCommunication(id) {
63
+ try {
64
+ let response = await httpUtil.put({
65
+ resourcePath: '/v2/communications/' + id + '/actions',
66
+ body: {
67
+ viewed: true,
68
+ },
69
+ withAccessToken: true
70
+ });
71
+ return createCommonResult(response);
72
+ } catch (e) {
73
+ logger.error('Exception markReadCommunication:', e);
74
+ return createResult(ErrorCodes.UNKNOWN, e);
75
+ }
76
+ }
77
+
78
+ async function deleteCommunication(commId) {
79
+ try {
80
+ let response = await httpUtil.put({
81
+ resourcePath: '/v2/communications/' + commId + '/actions',
82
+ body: {
83
+ archived: true,
84
+ },
85
+ withAccessToken: true
86
+ });
87
+ //check return code here instead of put as there would be different intepretation for different API
88
+ return createCommonResult(response);
89
+ } catch (e) {
90
+ logger.error('Exception deleteCommunication:', e);
91
+ return createResult(ErrorCodes.UNKNOWN, e);
92
+ }
93
+ }
94
+