@crmcom/self-service-sdk 3.0.0-build.4 → 3.0.0-build.6
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/authentication.js +25 -87
- package/contacts.js +13 -25
- package/eventListener.js +20 -20
- package/index.js +0 -1
- package/orders.js +4 -56
- package/package.json +2 -2
- package/resultUtil.js +72 -30
- package/rewards.js +6 -23
- package/subscriptions.js +5 -17
- package/dataUtil.js +0 -2186
package/authentication.js
CHANGED
|
@@ -88,7 +88,6 @@ async function authenticate(contact, startSession = true) {
|
|
|
88
88
|
if (startSession == true && response.code == "OK" && response.data && response.data.access_token) {
|
|
89
89
|
httpUtil.startSession(response.data);
|
|
90
90
|
}
|
|
91
|
-
//check return code here instead of put as there would be different intepretation for different API
|
|
92
91
|
if (response.code == "OK") {
|
|
93
92
|
if (response.data.auth_otp || response.data.access_token) {
|
|
94
93
|
return createResult(ErrorCodes.OK, response.data);
|
|
@@ -96,20 +95,7 @@ async function authenticate(contact, startSession = true) {
|
|
|
96
95
|
return createResult(ErrorCodes.INVALID_LOGIN, response.error);
|
|
97
96
|
}
|
|
98
97
|
} else {
|
|
99
|
-
|
|
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);
|
|
98
|
+
return createCommonResult(response);
|
|
113
99
|
}
|
|
114
100
|
} catch (e) {
|
|
115
101
|
logger.error("Exception register:", e);
|
|
@@ -165,16 +151,7 @@ async function validateOTP({ auth_otp,otp }, startSession = true) {
|
|
|
165
151
|
if (startSession == true && response.code == "OK") {
|
|
166
152
|
httpUtil.startSession(response.data);
|
|
167
153
|
}
|
|
168
|
-
|
|
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
|
-
}
|
|
154
|
+
return createCommonResult(response);
|
|
178
155
|
} catch (e) {
|
|
179
156
|
logger.error("Exception register:", e);
|
|
180
157
|
return createResult(ErrorCodes.UNKNOWN, e);
|
|
@@ -300,43 +277,18 @@ async function register(body,startSession = true) {
|
|
|
300
277
|
httpUtil.startSession(response.data);
|
|
301
278
|
}
|
|
302
279
|
//check return code here instead of put as there would be different intepretation for different API
|
|
303
|
-
if (response.code == "OK")
|
|
280
|
+
if (response.code == "OK") {
|
|
304
281
|
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
282
|
}
|
|
283
|
+
// Registration-specific: MORETHANONEENTITYEXISTSEXCEPTION means contact already exists
|
|
284
|
+
if (response.error && (response.error.error == "COM.CRM.EXCEPTIONS.MORETHANONEENTITYEXISTSEXCEPTION" || response.error.error == 'CRM.EXCEPTIONS.MORETHANONEENTITYEXISTSEXCEPTION')) {
|
|
285
|
+
return createResult(ErrorCodes.REGISTRATION_FAIL_CONTACT_EXISTS, response.error);
|
|
286
|
+
}
|
|
287
|
+
// Pass-specific: NOTFOUNDEXCEPTION means invalid pass in this context
|
|
288
|
+
if (response.error && response.error.error == "CRM.EXCEPTIONS.NOTFOUNDEXCEPTION") {
|
|
289
|
+
return createResult(ErrorCodes.REDEEM_PASS_INVALID, response.error);
|
|
290
|
+
}
|
|
291
|
+
return createCommonResult(response);
|
|
340
292
|
} catch (e) {
|
|
341
293
|
logger.error("Exception register:", e);
|
|
342
294
|
return createResult(ErrorCodes.UNKNOWN, e);
|
|
@@ -421,28 +373,15 @@ async function addContactIdentity(body,contactId,accessToken) {
|
|
|
421
373
|
accessToken: accessToken
|
|
422
374
|
});
|
|
423
375
|
logger.debug('Identity add response received')
|
|
424
|
-
if (response.code == "OK")
|
|
376
|
+
if (response.code == "OK") {
|
|
425
377
|
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
378
|
}
|
|
379
|
+
logger.debug("Identity add error:", response.error)
|
|
380
|
+
// Identity-specific: ALREADYEXISTSEXCEPTION means contact already exists
|
|
381
|
+
if (response.error && (response.error.error == "COM.CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION" || response.error.error == "CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION")) {
|
|
382
|
+
return createResult(ErrorCodes.REGISTRATION_FAIL_CONTACT_EXISTS, response.error);
|
|
383
|
+
}
|
|
384
|
+
return createCommonResult(response);
|
|
446
385
|
} catch (e) {
|
|
447
386
|
logger.error("Exception register:", e);
|
|
448
387
|
return createResult(ErrorCodes.UNKNOWN, e);
|
|
@@ -458,15 +397,14 @@ async function forgotPassword(email) {
|
|
|
458
397
|
},
|
|
459
398
|
logOutIfSessionInvalid: false
|
|
460
399
|
});
|
|
461
|
-
if (response.code == "OK")
|
|
400
|
+
if (response.code == "OK") {
|
|
462
401
|
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
402
|
}
|
|
403
|
+
// Forgot password specific: INVALIDVALUEEXCEPTION means email not found
|
|
404
|
+
if (response.error && (response.error.error == "COM.CRM.EXCEPTIONS.INVALIDVALUEEXCEPTION" || response.error.error == "CRM.EXCEPTIONS.INVALIDVALUEEXCEPTION")) {
|
|
405
|
+
return createResult(ErrorCodes.FORGOT_EMAIL_NOT_FOUND_EXCEPTION, response.error);
|
|
406
|
+
}
|
|
407
|
+
return createCommonResult(response);
|
|
470
408
|
} catch (e) {
|
|
471
409
|
logger.error("Exception update phone:", e);
|
|
472
410
|
return createResult(ErrorCodes.UNKNOWN, e);
|
package/contacts.js
CHANGED
|
@@ -123,19 +123,14 @@ async function addContactAddress({
|
|
|
123
123
|
},
|
|
124
124
|
withAccessToken: true,
|
|
125
125
|
});
|
|
126
|
-
if (response.code == "OK")
|
|
126
|
+
if (response.code == "OK") {
|
|
127
127
|
return createResult(ErrorCodes.OK, response.data);
|
|
128
|
-
else {
|
|
129
|
-
if (
|
|
130
|
-
response.error && (
|
|
131
|
-
response.error.error == "COM.CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION" || response.error.error == "CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION")
|
|
132
|
-
) {
|
|
133
|
-
return createResult(
|
|
134
|
-
ErrorCodes.ADD_ADDRESS_ALREADY_TYPE,
|
|
135
|
-
response.error
|
|
136
|
-
);
|
|
137
|
-
} else return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
|
|
138
128
|
}
|
|
129
|
+
// Address-specific: ALREADYEXISTSEXCEPTION means address type already exists
|
|
130
|
+
if (response.error && (response.error.error == "COM.CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION" || response.error.error == "CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION")) {
|
|
131
|
+
return createResult(ErrorCodes.ADD_ADDRESS_ALREADY_TYPE, response.error);
|
|
132
|
+
}
|
|
133
|
+
return createCommonResult(response);
|
|
139
134
|
} catch (e) {
|
|
140
135
|
logger.error("Exception addContactAddress:", e);
|
|
141
136
|
return createResult(ErrorCodes.UNKNOWN, e);
|
|
@@ -176,19 +171,14 @@ async function updateContactAddress({
|
|
|
176
171
|
},
|
|
177
172
|
withAccessToken: true,
|
|
178
173
|
});
|
|
179
|
-
if (response.code == "OK")
|
|
174
|
+
if (response.code == "OK") {
|
|
180
175
|
return createResult(ErrorCodes.OK, response.data);
|
|
181
|
-
else {
|
|
182
|
-
if (
|
|
183
|
-
response.error && (
|
|
184
|
-
response.error.error == "COM.CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION" || response.error.error == "CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION")
|
|
185
|
-
) {
|
|
186
|
-
return createResult(
|
|
187
|
-
ErrorCodes.ADD_ADDRESS_ALREADY_TYPE,
|
|
188
|
-
response.error
|
|
189
|
-
);
|
|
190
|
-
} else return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
|
|
191
176
|
}
|
|
177
|
+
// Address-specific: ALREADYEXISTSEXCEPTION means address type already exists
|
|
178
|
+
if (response.error && (response.error.error == "COM.CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION" || response.error.error == "CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION")) {
|
|
179
|
+
return createResult(ErrorCodes.ADD_ADDRESS_ALREADY_TYPE, response.error);
|
|
180
|
+
}
|
|
181
|
+
return createCommonResult(response);
|
|
192
182
|
} catch (e) {
|
|
193
183
|
logger.error("Exception updateContactAddress:", e);
|
|
194
184
|
return createResult(ErrorCodes.UNKNOWN, e);
|
|
@@ -207,9 +197,7 @@ async function updateContactOnboardingCards({
|
|
|
207
197
|
},
|
|
208
198
|
withAccessToken: true,
|
|
209
199
|
});
|
|
210
|
-
|
|
211
|
-
return createResult(ErrorCodes.OK, response.data);
|
|
212
|
-
else return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
|
|
200
|
+
return createCommonResult(response);
|
|
213
201
|
} catch (e) {
|
|
214
202
|
logger.error("Exception updateContactOnboardingCards:", e);
|
|
215
203
|
return createResult(ErrorCodes.UNKNOWN, e);
|
package/eventListener.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { logger } from './logger';
|
|
2
2
|
let events = {};
|
|
3
3
|
|
|
4
|
-
try {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} catch (error) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
4
|
+
// try {
|
|
5
|
+
// // Dynamic import for Vite / ES modules
|
|
6
|
+
// const customConfigModule = import("../../../custom.config");
|
|
7
|
+
// events = customConfigModule.events || {};
|
|
8
|
+
// } catch (error) {
|
|
9
|
+
// if (error.code === 'MODULE_NOT_FOUND') {
|
|
10
|
+
// events = {};
|
|
11
|
+
// } else {
|
|
12
|
+
// throw error;
|
|
13
|
+
// }
|
|
14
|
+
// }
|
|
15
15
|
|
|
16
16
|
export const eventListener = {
|
|
17
17
|
handleEvent,
|
|
@@ -28,14 +28,14 @@ export async function handleEvent({
|
|
|
28
28
|
object_type // object type, e.g., string or object
|
|
29
29
|
}) {
|
|
30
30
|
logger.debug("handleEvent type:", type);
|
|
31
|
-
logger.debug("handleEvent code:", code);
|
|
32
|
-
logger.debug("handleEvent object_type:", object_type);
|
|
33
|
-
logger.debug("handleEvent data:", data);
|
|
31
|
+
// logger.debug("handleEvent code:", code);
|
|
32
|
+
// logger.debug("handleEvent object_type:", object_type);
|
|
33
|
+
// logger.debug("handleEvent data:", data);
|
|
34
34
|
|
|
35
|
-
if (type === eventTypes.kochava) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
35
|
+
// if (type === eventTypes.kochava) {
|
|
36
|
+
// const kochava = events?.kochava ?? null;
|
|
37
|
+
// if (kochava?.sendEvent) {
|
|
38
|
+
// await kochava.sendEvent(object_type, code, data);
|
|
39
|
+
// }
|
|
40
|
+
// }
|
|
41
41
|
}
|
package/index.js
CHANGED
|
@@ -18,7 +18,6 @@ export { jcccards } from './jcccards.js';
|
|
|
18
18
|
export { mobilepass } from './mobilepass.js';
|
|
19
19
|
export { paymentgateway } from './paymentgateway.js';
|
|
20
20
|
export { payouts } from './payouts.js';
|
|
21
|
-
export { dataUtil } from './dataUtil.js';
|
|
22
21
|
export { ErrorCodes, createResult, createCommonResult } from './resultUtil.js';
|
|
23
22
|
export { eventListener, eventTypes } from './eventListener.js';
|
|
24
23
|
export { logger } from './logger.js';
|
package/orders.js
CHANGED
|
@@ -69,14 +69,7 @@ async function getOrder(id) {
|
|
|
69
69
|
resourcePath: '/v2/orders/' + id,
|
|
70
70
|
withAccessToken: true
|
|
71
71
|
});
|
|
72
|
-
|
|
73
|
-
return createResult(ErrorCodes.OK, response.data);
|
|
74
|
-
else {
|
|
75
|
-
if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.ORDERS.CANNOTFULFILLORDEREXCEPTION" || response.error && response.error.error == "COM.CRM.EXCEPTIONS.CANNOTFULFILLORDEREXCEPTION") {
|
|
76
|
-
return createResult(ErrorCodes.CAN_NOT_FULFILL_ORDER_EXCEPTION, response.error);
|
|
77
|
-
}
|
|
78
|
-
return createCommonResult(response);
|
|
79
|
-
}
|
|
72
|
+
return createCommonResult(response);
|
|
80
73
|
} catch (e) {
|
|
81
74
|
logger.error('Exception getOrder:', e);
|
|
82
75
|
return createResult(ErrorCodes.UNKNOWN, e);
|
|
@@ -444,16 +437,7 @@ async function estimateOrderFulfillment({
|
|
|
444
437
|
},
|
|
445
438
|
withAccessToken: true
|
|
446
439
|
});
|
|
447
|
-
|
|
448
|
-
if (response.code == 'OK') {
|
|
449
|
-
return createCommonResult(response);
|
|
450
|
-
} else {
|
|
451
|
-
if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.ORDERS.CANNOTFULFILLORDEREXCEPTION"
|
|
452
|
-
|| response.error && response.error.error == "COM.CRM.EXCEPTIONS.CANNOTFULFILLORDEREXCEPTION" || response.error && response.error.error == "CRM.EXCEPTIONS.CANNOTFULFILLORDEREXCEPTION") {
|
|
453
|
-
return createResult(ErrorCodes.CAN_NOT_FULFILL_ORDER_EXCEPTION, response.error);
|
|
454
|
-
}
|
|
455
|
-
return createCommonResult(response);
|
|
456
|
-
}
|
|
440
|
+
return createCommonResult(response);
|
|
457
441
|
} catch (e) {
|
|
458
442
|
logger.error('Exception orderFulfillment:', e);
|
|
459
443
|
return createResult(ErrorCodes.UNKNOWN, e);
|
|
@@ -509,30 +493,7 @@ async function estimateOrder({
|
|
|
509
493
|
},
|
|
510
494
|
withAccessToken: true
|
|
511
495
|
});
|
|
512
|
-
|
|
513
|
-
//console.log('response=1=====',response)
|
|
514
|
-
if (response.code == 'OK') {
|
|
515
|
-
return createCommonResult(response);
|
|
516
|
-
} else {
|
|
517
|
-
if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.ORDERS.CANNOTFULFILLORDEREXCEPTION"
|
|
518
|
-
|| response.error && response.error.error == "COM.CRM.EXCEPTIONS.CANNOTFULFILLORDEREXCEPTION" || response.error && response.error.error == "CRM.EXCEPTIONS.CANNOTFULFILLORDEREXCEPTION") {
|
|
519
|
-
return createResult(ErrorCodes.CAN_NOT_FULFILL_ORDER_EXCEPTION, response.error);
|
|
520
|
-
} else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.ORDERS.MINIMUMORDERAMOUNTNOTREACHEDEXCEPTION" || response.error && response.error.error == "COM.CRM.EXCEPTIONS.MINIMUMORDERAMOUNTNOTREACHEDEXCEPTION") {
|
|
521
|
-
return createResult(ErrorCodes.MINIMUM_ORDER_AMOUNT_NOT_REACHED, response.error);
|
|
522
|
-
}
|
|
523
|
-
else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.SERVICEALREADYEXISTSONSUBSCRIPTIONEXCEPTION") {
|
|
524
|
-
return createResult(ErrorCodes.SERVICE_ALREADY_EXIST, response.error);
|
|
525
|
-
}
|
|
526
|
-
else if (response.error && response.error.error == "FINANCE.EXCEPTIONS.CANNOTEXECUTEACTIONCREDITLIMITEXCEPTION") {
|
|
527
|
-
return createResult(ErrorCodes.CANNOTEXECUTEACTIONCREDITLIMITEXCEPTION, response.error);
|
|
528
|
-
}
|
|
529
|
-
else if (response.error && response.error.error == "CRM.EXCEPTIONS.CANNOTSPENDAMOUNTWALLETBALANCENOTENOUGHEXCEPTION") {
|
|
530
|
-
return createResult(ErrorCodes.CANNOTSPENDAMOUNTWALLETBALANCENOTENOUGHEXCEPTION, response.error);
|
|
531
|
-
} else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.CANNOTEXECUTESUBSCRIPTIONACTIONEXCEPTION") {
|
|
532
|
-
return createResult(ErrorCodes.CANNOTEXECUTESUBSCRIPTIONACTIONEXCEPTION, response.error);
|
|
533
|
-
}
|
|
534
|
-
return createCommonResult(response);
|
|
535
|
-
}
|
|
496
|
+
return createCommonResult(response);
|
|
536
497
|
} catch (e) {
|
|
537
498
|
logger.error('Exception estimateOrder:', e);
|
|
538
499
|
return createResult(ErrorCodes.UNKNOWN, e);
|
|
@@ -570,20 +531,7 @@ async function makeOrder({
|
|
|
570
531
|
},
|
|
571
532
|
withAccessToken: true
|
|
572
533
|
});
|
|
573
|
-
|
|
574
|
-
return createCommonResult(response);
|
|
575
|
-
} else {
|
|
576
|
-
if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.ORDERS.CANNOTFULFILLORDEREXCEPTION"
|
|
577
|
-
|| response.error && response.error.error == "COM.CRM.EXCEPTIONS.CANNOTFULFILLORDEREXCEPTION" || response.error && response.error.error == "CRM.EXCEPTIONS.CANNOTFULFILLORDEREXCEPTION") {
|
|
578
|
-
return createResult(ErrorCodes.CAN_NOT_FULFILL_ORDER_EXCEPTION, response.error);
|
|
579
|
-
} else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.ORDERS.MINIMUMORDERAMOUNTNOTREACHEDEXCEPTION" || response.error && response.error.error == "COM.CRM.EXCEPTIONS.MINIMUMORDERAMOUNTNOTREACHEDEXCEPTION") {
|
|
580
|
-
return createResult(ErrorCodes.MINIMUM_ORDER_AMOUNT_NOT_REACHED, response.error);
|
|
581
|
-
}
|
|
582
|
-
else if (response.error && response.error.error == "FINANCE.EXCEPTIONS.CANNOTEXECUTEACTIONCREDITLIMITEXCEPTION") {
|
|
583
|
-
return createResult(ErrorCodes.CANNOTEXECUTEACTIONCREDITLIMITEXCEPTION, response.error);
|
|
584
|
-
}
|
|
585
|
-
return createCommonResult(response);
|
|
586
|
-
}
|
|
534
|
+
return createCommonResult(response);
|
|
587
535
|
} catch (e) {
|
|
588
536
|
logger.error('Exception addDevice:', e);
|
|
589
537
|
return createResult(ErrorCodes.UNKNOWN, e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crmcom/self-service-sdk",
|
|
3
|
-
"version": "3.0.0-build.
|
|
3
|
+
"version": "3.0.0-build.6",
|
|
4
4
|
"description": "Official CRM.COM Self-Service JavaScript SDK for consumer-facing API integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"./mobilepass": "./mobilepass.js",
|
|
28
28
|
"./paymentgateway": "./paymentgateway.js",
|
|
29
29
|
"./payouts": "./payouts.js",
|
|
30
|
-
"./dataUtil": "./dataUtil.js",
|
|
31
30
|
"./resultUtil": "./resultUtil.js",
|
|
32
31
|
"./eventListener": "./eventListener.js",
|
|
33
32
|
"./logger": "./logger.js"
|
|
@@ -35,6 +34,7 @@
|
|
|
35
34
|
"files": [
|
|
36
35
|
"*.js",
|
|
37
36
|
"*.d.ts",
|
|
37
|
+
"!dataUtil.js",
|
|
38
38
|
"!add_imports.ps1"
|
|
39
39
|
],
|
|
40
40
|
"keywords": [
|
package/resultUtil.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { logger } from './logger';
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
export const ErrorCodes = {
|
|
5
4
|
OK: 'OK',
|
|
6
5
|
UNKNOWN: 'UNKNOWN',
|
|
@@ -42,6 +41,60 @@ export const ErrorCodes = {
|
|
|
42
41
|
INVALIDENTITYLIFECYCLESTATEEXCEPTION: "INVALIDENTITYLIFECYCLESTATEEXCEPTION"
|
|
43
42
|
}
|
|
44
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Centralized mapping from API exception strings to SDK ErrorCodes.
|
|
46
|
+
* Multiple API exception variants can map to the same ErrorCode.
|
|
47
|
+
* Both `response.error.error` and `response.error.message` fields are checked.
|
|
48
|
+
*/
|
|
49
|
+
const EXCEPTION_MAP = {
|
|
50
|
+
// Authentication
|
|
51
|
+
'COM.CRM.EXCEPTIONS.INVALIDLOGINEXCEPTION': ErrorCodes.INVALID_LOGIN,
|
|
52
|
+
'COM.CRM.EXCEPTIONS.EMAILNOTVERIFIEDEXCEPTION': ErrorCodes.EMAIL_NOT_VERIFIED,
|
|
53
|
+
'COM.CRM.EXCEPTIONS.INVALIDPASSWORDEXCEPTION': ErrorCodes.INVALID_PASSWORD_EXCEPTION,
|
|
54
|
+
'CRM.EXCEPTIONS.INVALIDPASSWORDEXCEPTION': ErrorCodes.INVALID_PASSWORD_EXCEPTION,
|
|
55
|
+
'COM.CRM.EXCEPTIONS.INVALIDCONTACTPASSWORDEXCEPTION': ErrorCodes.PASSWORD_LENGTH_EXCEPTION,
|
|
56
|
+
'CRM.EXCEPTIONS.INVALIDCONTACTPASSWORDEXCEPTION': ErrorCodes.PASSWORD_LENGTH_EXCEPTION,
|
|
57
|
+
'COM.CRM.EXCEPTIONS.INVALIDVALUEEXCEPTION': ErrorCodes.INVALIDVALUEEXCEPTION,
|
|
58
|
+
'CRM.EXCEPTIONS.INVALIDVALUEEXCEPTION': ErrorCodes.INVALIDVALUEEXCEPTION,
|
|
59
|
+
|
|
60
|
+
// Contact / Registration
|
|
61
|
+
'COM.CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION': ErrorCodes.CUSTOMER_EMAIL_ALREADY_EXIST,
|
|
62
|
+
'CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION': ErrorCodes.CUSTOMER_EMAIL_ALREADY_EXIST,
|
|
63
|
+
'COM.CRM.EXCEPTIONS.CONTACTUNIQUELYIDENTIFYEXCEPTION': ErrorCodes.CONTACTUNIQUELYIDENTIFYEXCEPTION,
|
|
64
|
+
'COM.CRM.EXCEPTIONS.CANNOTUNREGISTERCONTACTEXCEPTION': ErrorCodes.CANNOTUNREGISTERCONTACTEXCEPTION,
|
|
65
|
+
'COM.CRM.EXCEPTIONS.CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION': ErrorCodes.CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION,
|
|
66
|
+
'COM.CRM.EXCEPTIONS.MULTIPLECONTACTSSAMEPHONEEXCEPTION': ErrorCodes.MULTIPLECONTACTSSAMEPHONEEXCEPTION,
|
|
67
|
+
'COM.CRM.EXCEPTIONS.MORETHANONEENTITYEXISTSEXCEPTION': ErrorCodes.MULTIPLECONTACTSSAMEPHONEEXCEPTION,
|
|
68
|
+
'CRM.EXCEPTIONS.MORETHANONEENTITYEXISTSEXCEPTION': ErrorCodes.MULTIPLECONTACTSSAMEPHONEEXCEPTION,
|
|
69
|
+
|
|
70
|
+
// Orders
|
|
71
|
+
'COM.CRM.EXCEPTIONS.ORDERS.CANNOTFULFILLORDEREXCEPTION': ErrorCodes.CAN_NOT_FULFILL_ORDER_EXCEPTION,
|
|
72
|
+
'COM.CRM.EXCEPTIONS.CANNOTFULFILLORDEREXCEPTION': ErrorCodes.CAN_NOT_FULFILL_ORDER_EXCEPTION,
|
|
73
|
+
'CRM.EXCEPTIONS.CANNOTFULFILLORDEREXCEPTION': ErrorCodes.CAN_NOT_FULFILL_ORDER_EXCEPTION,
|
|
74
|
+
'COM.CRM.EXCEPTIONS.ORDERS.MINIMUMORDERAMOUNTNOTREACHEDEXCEPTION': ErrorCodes.MINIMUM_ORDER_AMOUNT_NOT_REACHED,
|
|
75
|
+
'COM.CRM.EXCEPTIONS.MINIMUMORDERAMOUNTNOTREACHEDEXCEPTION': ErrorCodes.MINIMUM_ORDER_AMOUNT_NOT_REACHED,
|
|
76
|
+
|
|
77
|
+
// Subscriptions / Services
|
|
78
|
+
'COM.CRM.EXCEPTIONS.SERVICEALREADYEXISTSONSUBSCRIPTIONEXCEPTION': ErrorCodes.SERVICE_ALREADY_EXIST,
|
|
79
|
+
'COM.CRM.EXCEPTIONS.CANNOTEXECUTESUBSCRIPTIONACTIONEXCEPTION': ErrorCodes.CANNOTEXECUTESUBSCRIPTIONACTIONEXCEPTION,
|
|
80
|
+
|
|
81
|
+
// Finance / Wallet
|
|
82
|
+
'COM.CRM.EXCEPTIONS.SPENDAMOUNTNOTFULLYCOVEREDEXCEPTION': ErrorCodes.SPEND_AMOUNT_NOT_FULLY_COVERED_EXCEPTION,
|
|
83
|
+
'FINANCE.EXCEPTIONS.CANNOTEXECUTEACTIONCREDITLIMITEXCEPTION': ErrorCodes.CANNOTEXECUTEACTIONCREDITLIMITEXCEPTION,
|
|
84
|
+
'CRM.EXCEPTIONS.CANNOTSPENDAMOUNTWALLETBALANCENOTENOUGHEXCEPTION': ErrorCodes.CANNOTSPENDAMOUNTWALLETBALANCENOTENOUGHEXCEPTION,
|
|
85
|
+
|
|
86
|
+
// Rewards / Passes
|
|
87
|
+
'COM.CRM.EXCEPTIONS.THISPASSHASALREADYBEENREDEEMEDEXCEPTION': ErrorCodes.REDEEM_PASS_USED,
|
|
88
|
+
'COM.CRM.EXCEPTIONS.ONLYACTIVEPASSESCANBEREDEEMEDEXCEPTION': ErrorCodes.REDEEM_PASS_NOT_ACTIVE,
|
|
89
|
+
'CRM.EXCEPTIONS.NOTFOUNDEXCEPTION': ErrorCodes.NOTFOUNDEXCEPTION,
|
|
90
|
+
|
|
91
|
+
// Community
|
|
92
|
+
'COM.CRM.EXCEPTIONS.COMMUNITYPARENTCHILDEXCEPTION': ErrorCodes.COMMUNITYPARENTCHILDEXCEPTION,
|
|
93
|
+
|
|
94
|
+
// Lifecycle
|
|
95
|
+
'CRM.EXCEPTIONS.INVALIDENTITYLIFECYCLESTATEEXCEPTION': ErrorCodes.INVALIDENTITYLIFECYCLESTATEEXCEPTION,
|
|
96
|
+
};
|
|
97
|
+
|
|
45
98
|
export function createResult(errorCode, data) {
|
|
46
99
|
return {
|
|
47
100
|
code: errorCode,
|
|
@@ -51,36 +104,25 @@ export function createResult(errorCode, data) {
|
|
|
51
104
|
|
|
52
105
|
export function createCommonResult(response, requestType) {
|
|
53
106
|
logger.debug("createCommonResult response:", response);
|
|
54
|
-
|
|
107
|
+
|
|
108
|
+
// Success responses
|
|
109
|
+
if (response.code == 'OK' || response.code == '204') {
|
|
55
110
|
return createResult(ErrorCodes.OK, response.data);
|
|
56
|
-
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// HTTP status code mappings
|
|
114
|
+
if (response.code == '429') {
|
|
57
115
|
return createResult(ErrorCodes.TOO_MANY_REQUESTS, response.error);
|
|
58
|
-
} else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.SPENDAMOUNTNOTFULLYCOVEREDEXCEPTION") {
|
|
59
|
-
return createResult(ErrorCodes.SPEND_AMOUNT_NOT_FULLY_COVERED_EXCEPTION, response.error);
|
|
60
|
-
} else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.CANNOTUNREGISTERCONTACTEXCEPTION") {
|
|
61
|
-
return createResult(ErrorCodes.CANNOTUNREGISTERCONTACTEXCEPTION, response.error)
|
|
62
|
-
} else if (response.error && response.error.error == "CRM.EXCEPTIONS.INVALIDVALUEEXCEPTION") {
|
|
63
|
-
return createResult(ErrorCodes.INVALIDVALUEEXCEPTION, response.error)
|
|
64
|
-
} else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.CONTACTUNIQUELYIDENTIFYEXCEPTION") {
|
|
65
|
-
return createResult(ErrorCodes.CONTACTUNIQUELYIDENTIFYEXCEPTION, response.error)
|
|
66
|
-
} else if (response.error && response.error.error == "CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION") {
|
|
67
|
-
return createResult(ErrorCodes.CUSTOMER_EMAIL_ALREADY_EXIST, response.error)
|
|
68
|
-
} else if (response.error && response.error.error == "CRM.EXCEPTIONS.CANNOTSPENDAMOUNTWALLETBALANCENOTENOUGHEXCEPTION") {
|
|
69
|
-
return createResult(ErrorCodes.CANNOTSPENDAMOUNTWALLETBALANCENOTENOUGHEXCEPTION, response.error)
|
|
70
|
-
}else if (response.error && response.error.error == "CRM.EXCEPTIONS.NOTFOUNDEXCEPTION") {
|
|
71
|
-
return createResult(ErrorCodes.NOTFOUNDEXCEPTION, response.error)
|
|
72
|
-
}else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.MULTIPLECONTACTSSAMEPHONEEXCEPTION") {
|
|
73
|
-
return createResult(ErrorCodes.MULTIPLECONTACTSSAMEPHONEEXCEPTION, response.error)
|
|
74
|
-
}else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.COMMUNITYPARENTCHILDEXCEPTION") {
|
|
75
|
-
return createResult(ErrorCodes.COMMUNITYPARENTCHILDEXCEPTION, response.error)
|
|
76
|
-
}else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION") {
|
|
77
|
-
return createResult(ErrorCodes.CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION, response.error)
|
|
78
|
-
}else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION") {
|
|
79
|
-
return createResult(ErrorCodes.CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION, response.error)
|
|
80
|
-
}else if (response.error && response.error.error == "CRM.EXCEPTIONS.INVALIDENTITYLIFECYCLESTATEEXCEPTION") {
|
|
81
|
-
return createResult(ErrorCodes.INVALIDENTITYLIFECYCLESTATEEXCEPTION, response.error)
|
|
82
116
|
}
|
|
83
|
-
|
|
84
|
-
|
|
117
|
+
|
|
118
|
+
// Exception mapping — check both error.error and error.message fields
|
|
119
|
+
if (response.error) {
|
|
120
|
+
const exceptionKey = response.error.error || response.error.message;
|
|
121
|
+
if (exceptionKey && EXCEPTION_MAP[exceptionKey]) {
|
|
122
|
+
return createResult(EXCEPTION_MAP[exceptionKey], response.error);
|
|
123
|
+
}
|
|
85
124
|
}
|
|
86
|
-
|
|
125
|
+
|
|
126
|
+
// Fallback
|
|
127
|
+
return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
|
|
128
|
+
}
|
package/rewards.js
CHANGED
|
@@ -233,31 +233,14 @@ async function redeemPass({
|
|
|
233
233
|
wallet_id: wallet_id,
|
|
234
234
|
}
|
|
235
235
|
});
|
|
236
|
-
|
|
237
|
-
if (response.code == "OK")
|
|
236
|
+
if (response.code == "OK") {
|
|
238
237
|
return createResult(ErrorCodes.OK, response.data);
|
|
239
|
-
else {
|
|
240
|
-
if(response.error && response.error.error == "CRM.EXCEPTIONS.NOTFOUNDEXCEPTION"){
|
|
241
|
-
return createResult(
|
|
242
|
-
ErrorCodes.REDEEM_PASS_INVALID,
|
|
243
|
-
response.error
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
else if(response.error && response.error.error == "COM.CRM.EXCEPTIONS.THISPASSHASALREADYBEENREDEEMEDEXCEPTION"){
|
|
247
|
-
return createResult(
|
|
248
|
-
ErrorCodes.REDEEM_PASS_USED,
|
|
249
|
-
response.error
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
else if(response.error && response.error.error == "COM.CRM.EXCEPTIONS.ONLYACTIVEPASSESCANBEREDEEMEDEXCEPTION"){
|
|
253
|
-
return createResult(
|
|
254
|
-
ErrorCodes.REDEEM_PASS_NOT_ACTIVE,
|
|
255
|
-
response.error
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
else
|
|
259
|
-
return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
|
|
260
238
|
}
|
|
239
|
+
// Pass-specific: NOTFOUNDEXCEPTION means invalid pass in this context
|
|
240
|
+
if (response.error && response.error.error == "CRM.EXCEPTIONS.NOTFOUNDEXCEPTION") {
|
|
241
|
+
return createResult(ErrorCodes.REDEEM_PASS_INVALID, response.error);
|
|
242
|
+
}
|
|
243
|
+
return createCommonResult(response);
|
|
261
244
|
} catch (e) {
|
|
262
245
|
logger.error('Exception redeemPass:', e);
|
|
263
246
|
return createResult(ErrorCodes.UNKNOWN, e);
|
package/subscriptions.js
CHANGED
|
@@ -262,11 +262,7 @@ async function onServiceDelivery({
|
|
|
262
262
|
},
|
|
263
263
|
withAccessToken: true,
|
|
264
264
|
});
|
|
265
|
-
|
|
266
|
-
return createResult(ErrorCodes.OK, response.data);
|
|
267
|
-
else {
|
|
268
|
-
return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
|
|
269
|
-
}
|
|
265
|
+
return createCommonResult(response);
|
|
270
266
|
} catch (e) {
|
|
271
267
|
logger.error("Exception onServiceDelivery:", e);
|
|
272
268
|
return createResult(ErrorCodes.UNKNOWN, e);
|
|
@@ -286,17 +282,13 @@ async function onEstimateBilling({
|
|
|
286
282
|
contact_id: id,
|
|
287
283
|
account_id: account_id,
|
|
288
284
|
subscription_id: subscription_id,
|
|
289
|
-
upcoming_billing_cycles : upcoming_billing_cycles
|
|
285
|
+
upcoming_billing_cycles : upcoming_billing_cycles
|
|
290
286
|
},
|
|
291
287
|
withAccessToken: true,
|
|
292
288
|
});
|
|
293
|
-
|
|
294
|
-
return createResult(ErrorCodes.OK, response.data);
|
|
295
|
-
else {
|
|
296
|
-
return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
|
|
297
|
-
}
|
|
289
|
+
return createCommonResult(response);
|
|
298
290
|
} catch (e) {
|
|
299
|
-
logger.error("Exception
|
|
291
|
+
logger.error("Exception onEstimateBilling:", e);
|
|
300
292
|
return createResult(ErrorCodes.UNKNOWN, e);
|
|
301
293
|
}
|
|
302
294
|
}
|
|
@@ -309,11 +301,7 @@ async function onUpdateServiceWithBody(service_id, body) {
|
|
|
309
301
|
body: body,
|
|
310
302
|
withAccessToken: false,
|
|
311
303
|
});
|
|
312
|
-
|
|
313
|
-
return createResult(ErrorCodes.OK, response.data);
|
|
314
|
-
else {
|
|
315
|
-
return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
|
|
316
|
-
}
|
|
304
|
+
return createCommonResult(response);
|
|
317
305
|
} catch (e) {
|
|
318
306
|
logger.error("Exception onUpdateServiceWithBody:", e);
|
|
319
307
|
return createResult(ErrorCodes.UNKNOWN, e);
|