@crmcom/self-service-sdk 3.0.0-build.4 → 3.0.0-build.5
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/dataUtil.js +97 -14
- package/eventListener.js +20 -20
- package/orders.js +4 -56
- package/package.json +1 -1
- package/resultUtil.js +72 -30
- package/rewards.js +6 -23
- package/subscriptions.js +5 -17
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/dataUtil.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import contacts from "./contacts";
|
|
2
|
+
import community from "./community";
|
|
3
|
+
import payment from "./payment";
|
|
4
|
+
import orders from "./orders";
|
|
5
|
+
import config from "./config";
|
|
3
6
|
import { httpUtil } from "./httpUtil";
|
|
4
7
|
import { logger } from './logger';
|
|
5
8
|
import { cache, order_key } from "../../utils/cache";
|
|
@@ -546,7 +549,7 @@ async function checkAllowOrderByContact(agreement_countries,contact) {
|
|
|
546
549
|
|
|
547
550
|
if(!contact)
|
|
548
551
|
{
|
|
549
|
-
let result = await
|
|
552
|
+
let result = await contacts.getContact();
|
|
550
553
|
if (result.code == 'OK') {
|
|
551
554
|
contact = result.data;
|
|
552
555
|
}
|
|
@@ -1125,7 +1128,7 @@ async function checkContactWallet(contact) {
|
|
|
1125
1128
|
if(!contact)
|
|
1126
1129
|
{
|
|
1127
1130
|
|
|
1128
|
-
const result = await
|
|
1131
|
+
const result = await contacts.getContact();
|
|
1129
1132
|
if (result.code == 'OK') {
|
|
1130
1133
|
isAlreadyWallet = result.data.wallet && result.data.wallet.id ? true : false;
|
|
1131
1134
|
}
|
|
@@ -1181,7 +1184,7 @@ async function getJoinedCommunities(joinedCommunityIds) {
|
|
|
1181
1184
|
for (let i = 0; i < joinedCommunityIds.length; i++) {
|
|
1182
1185
|
let joinedCommunity = joinedCommunityIds[i];
|
|
1183
1186
|
joinedCommunity.name = joinedCommunityIds[i].community_owner ? joinedCommunityIds[i].community_owner.first_name : ""
|
|
1184
|
-
var result = await
|
|
1187
|
+
var result = await community.getListCommunityPeople({}, joinedCommunity.community_owner.id);
|
|
1185
1188
|
if (result.code == 'OK') {
|
|
1186
1189
|
let content = result.data.content ? result.data.content : [];
|
|
1187
1190
|
content.forEach(c => {
|
|
@@ -1308,7 +1311,7 @@ async function onLoadAllCardsInfo(payment_method_types, gateway) {
|
|
|
1308
1311
|
payment_method_types = []
|
|
1309
1312
|
}
|
|
1310
1313
|
try {
|
|
1311
|
-
var result = await
|
|
1314
|
+
var result = await payment.getListPaymentMethods();
|
|
1312
1315
|
if (result.code == 'OK') {
|
|
1313
1316
|
cards = result.data && result.data.content ? result.data.content : [];
|
|
1314
1317
|
if (cards.length > 0) {
|
|
@@ -1382,7 +1385,7 @@ async function onLoadCards(payment_method_types, gateway) {
|
|
|
1382
1385
|
payment_method_types = []
|
|
1383
1386
|
}
|
|
1384
1387
|
try {
|
|
1385
|
-
var result = await
|
|
1388
|
+
var result = await payment.getListPaymentMethods();
|
|
1386
1389
|
if (result.code == 'OK') {
|
|
1387
1390
|
cards = result.data && result.data.content ? result.data.content : [];
|
|
1388
1391
|
if (cards.length > 0) {
|
|
@@ -1428,7 +1431,7 @@ async function onLoadA2A(payment_method_types, gateway) {
|
|
|
1428
1431
|
payment_method_types = []
|
|
1429
1432
|
}
|
|
1430
1433
|
try {
|
|
1431
|
-
var result = await
|
|
1434
|
+
var result = await payment.getListPaymentMethods();
|
|
1432
1435
|
if (result.code == 'OK') {
|
|
1433
1436
|
a2a = result.data && result.data.content ? result.data.content : [];
|
|
1434
1437
|
if (a2a.length > 0) {
|
|
@@ -1838,7 +1841,7 @@ const onLoadMyOrder = async () => {
|
|
|
1838
1841
|
let _lastOrder = null;
|
|
1839
1842
|
if(!cache.getLastOrder()){
|
|
1840
1843
|
try {
|
|
1841
|
-
var result = await
|
|
1844
|
+
var result = await orders.getMyOrders({ size: 1, page: 1 });
|
|
1842
1845
|
if (result.code === 'OK') {
|
|
1843
1846
|
_lastOrder = result.data.content && result.data.content.length > 0 ? result.data.content[0] : null;
|
|
1844
1847
|
cache.setLastOrder(_lastOrder);
|
|
@@ -1873,7 +1876,7 @@ async function getFulfillmentStoreDetail({
|
|
|
1873
1876
|
body.lat_lot = customer_address.lat + ":" + customer_address.lon;
|
|
1874
1877
|
body.postal_code = customer_address.postal_code;
|
|
1875
1878
|
}
|
|
1876
|
-
var result = await
|
|
1879
|
+
var result = await orders.estimateOrderFulfillment(body);
|
|
1877
1880
|
if (result.code == 'OK') {
|
|
1878
1881
|
_stores = result.data.fulfilled_by ? result.data.fulfilled_by : [];
|
|
1879
1882
|
}
|
|
@@ -1986,7 +1989,7 @@ async function onInitOrder({ location, appConfig, skipLastOrder = false, supplyM
|
|
|
1986
1989
|
} else {
|
|
1987
1990
|
let customer_address = null;
|
|
1988
1991
|
if (lastOrder.supply_method == 'DELIVERY' && supportDelivery) {
|
|
1989
|
-
const orderDetailResult = await
|
|
1992
|
+
const orderDetailResult = await orders.getOrder(lastOrder.id);
|
|
1990
1993
|
if (orderDetailResult.code == 'OK') {
|
|
1991
1994
|
customer_address = orderDetailResult.data.address
|
|
1992
1995
|
}
|
|
@@ -2066,7 +2069,7 @@ async function onLoadAddress() {
|
|
|
2066
2069
|
var customerAddress = null;
|
|
2067
2070
|
var _addresses = []
|
|
2068
2071
|
try {
|
|
2069
|
-
var result = await
|
|
2072
|
+
var result = await contacts.getContactAddresses();
|
|
2070
2073
|
if (result.code === 'OK') {
|
|
2071
2074
|
_addresses = result.data && result.data.content ? result.data.content : [];
|
|
2072
2075
|
cache.setContactAddresses(_addresses);
|
|
@@ -2100,7 +2103,7 @@ async function onGetCurrentAdress({ lat, lon, location } = {}) {
|
|
|
2100
2103
|
{
|
|
2101
2104
|
if (latlng) {
|
|
2102
2105
|
try {
|
|
2103
|
-
var result = await
|
|
2106
|
+
var result = await config.getAddress({ latlng: latlng });
|
|
2104
2107
|
if (result.code == 'OK') {
|
|
2105
2108
|
if (result.data) {
|
|
2106
2109
|
_currentAddress = result.data;
|
|
@@ -2183,4 +2186,84 @@ function getEstimationIds(estimate_order_result) {
|
|
|
2183
2186
|
}
|
|
2184
2187
|
|
|
2185
2188
|
return estimate_ids;
|
|
2186
|
-
}
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
|
|
2192
|
+
export function formatDateToMonthNameAndDayOfWeek(date) {
|
|
2193
|
+
var date = new Date(date);
|
|
2194
|
+
var dayOfWeeks = createShortDayOfWeek();
|
|
2195
|
+
var dayOfWeek = dayOfWeeks[date.getDay()];
|
|
2196
|
+
|
|
2197
|
+
return dayOfWeek + '. ' + formatDateToShortMonthName(date);
|
|
2198
|
+
}
|
|
2199
|
+
export function createShortDayOfWeek() {
|
|
2200
|
+
var day = i18next.t('SHORTDAYS', { returnObjects: true });
|
|
2201
|
+
let days = [
|
|
2202
|
+
day.SUNDAY,
|
|
2203
|
+
day.MONDAY,
|
|
2204
|
+
day.TUESDAY,
|
|
2205
|
+
day.WEDNESDAY,
|
|
2206
|
+
day.THURSDAY,
|
|
2207
|
+
day.FRIDAY,
|
|
2208
|
+
day.SATURDAY,
|
|
2209
|
+
];
|
|
2210
|
+
return days;
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
export function createShortMonth() {
|
|
2214
|
+
var month = i18next.t('SHORTMONTH', { returnObjects: true });
|
|
2215
|
+
let months = [
|
|
2216
|
+
month.JAN,
|
|
2217
|
+
month.FEB,
|
|
2218
|
+
month.MAR,
|
|
2219
|
+
month.APR,
|
|
2220
|
+
month.MAY,
|
|
2221
|
+
month.JUN,
|
|
2222
|
+
month.JUL,
|
|
2223
|
+
month.AUG,
|
|
2224
|
+
month.SEP,
|
|
2225
|
+
month.OCT,
|
|
2226
|
+
month.NOV,
|
|
2227
|
+
month.DEC,
|
|
2228
|
+
];
|
|
2229
|
+
|
|
2230
|
+
return months;
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2233
|
+
export function formatDateToShortMonthName(date) {
|
|
2234
|
+
var date = new Date(date);
|
|
2235
|
+
var day = date.getDate();
|
|
2236
|
+
var month = date.getMonth();
|
|
2237
|
+
if (day < 10) day = '0' + day;
|
|
2238
|
+
var months = createShortMonth();
|
|
2239
|
+
month = months[month];
|
|
2240
|
+
var dateFormatted = day + ' ' + month + ' ' + date.getFullYear();
|
|
2241
|
+
return dateFormatted;
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
export function formatDateToDDMMYYYY(date) {
|
|
2245
|
+
var date = new Date(date);
|
|
2246
|
+
var day = date.getDate();
|
|
2247
|
+
var month = date.getMonth() + 1;
|
|
2248
|
+
if (day < 10) day = '0' + day;
|
|
2249
|
+
if (month < 10) month = '0' + month;
|
|
2250
|
+
var dateFormatted = day + '/' + month + '/' + date.getFullYear();
|
|
2251
|
+
return dateFormatted;
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
export function formatDateToDDMMYYYYFrEpoch(epochTime, normal) {
|
|
2255
|
+
var d = new Date(epochTime * 1000); // The 0 there is the key, which sets the date to the epoch
|
|
2256
|
+
return normal ? formatDateToDDMMYYYY(d) : formatDateToMonthNameAndDayOfWeek(d);
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2259
|
+
export function newGUID() {
|
|
2260
|
+
function s4() {
|
|
2261
|
+
return Math.floor((1 + Math.random()) * 0x10000)
|
|
2262
|
+
.toString(16)
|
|
2263
|
+
.substring(1);
|
|
2264
|
+
}
|
|
2265
|
+
//return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
|
|
2266
|
+
// s4() + '-' + s4() + s4() + s4();
|
|
2267
|
+
return s4() + s4() + s4() + s4() +
|
|
2268
|
+
s4() + s4() + s4() + s4();
|
|
2269
|
+
}
|
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/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
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);
|