b2b-platform-utils 1.1.23 → 1.1.24
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/errorsMap.js +87 -71
- package/package.json +1 -1
package/errorsMap.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// Purpose: Static error map with backward compatibility and dynamic shortcuts.
|
|
4
4
|
// - Old style calls like errorsMap.mailTemplateNotFound?.() continue to work.
|
|
5
|
-
// - Any property access matching an errorKey returns a function that yields
|
|
5
|
+
// - Any property access matching an errorKey returns a function that yields the error OBJECT.
|
|
6
6
|
// - New API: get(), getString(), getCode(), list(), and legacy getSingleError().
|
|
7
7
|
// - Cache-first: if localCache.errorsMap exists, it overrides static entries.
|
|
8
8
|
|
|
@@ -10,63 +10,67 @@ const { getValue } = require('./localCache');
|
|
|
10
10
|
|
|
11
11
|
// ---- Static fallback (source of truth when cache is empty) ----
|
|
12
12
|
const STATIC_ERRORS = [
|
|
13
|
-
{ errorCode: 1000, errorKey: 'userNotFound',
|
|
14
|
-
{ errorCode: 1001, errorKey: 'unauthorized',
|
|
15
|
-
{ errorCode: 1002, errorKey: 'gameCategoryNotFound',
|
|
16
|
-
{ errorCode: 1003, errorKey: 'mediaResourceNotFound',
|
|
17
|
-
{ errorCode: 1004, errorKey: 'roleNotFound',
|
|
18
|
-
{ errorCode: 1005, errorKey: 'duplicatedUniqueField',
|
|
19
|
-
{ errorCode: 1006, errorKey: 'gameCollectionNotFound',
|
|
20
|
-
{ errorCode: 1007, errorKey: 'gameTagNotFound',
|
|
21
|
-
{ errorCode: 1008, errorKey: 'invalidConstraintField',
|
|
22
|
-
{ errorCode: 1009, errorKey: 'gameProviderNotFound',
|
|
23
|
-
{ errorCode: 1010, errorKey: 'gameNotFound',
|
|
24
|
-
{ errorCode: 1011, errorKey: 'undefinedRequest',
|
|
25
|
-
{ errorCode: 1012, errorKey: 'widgetNotFound',
|
|
26
|
-
{ errorCode: 1013, errorKey: 'segmentNotFound',
|
|
27
|
-
{ errorCode: 1014, errorKey: 'bonusNotFound',
|
|
28
|
-
{ errorCode: 1015, errorKey: 'userBonusNotFound',
|
|
29
|
-
{ errorCode: 1016, errorKey: 'freeSpinsNotFound',
|
|
30
|
-
{ errorCode: 1017, errorKey: 'gameWagerListNotFound',
|
|
31
|
-
{ errorCode: 1018, errorKey: 'bonusAlreadyInUse',
|
|
32
|
-
{ errorCode: 1019, errorKey: 'bonusRestrictForClaim',
|
|
33
|
-
{ errorCode: 1020, errorKey: 'bonusRewardAttachError',
|
|
34
|
-
{ errorCode: 1021, errorKey: 'loyaltyLevelNotFound',
|
|
35
|
-
{ errorCode: 1022, errorKey: 'loyaltyPointNotFound',
|
|
36
|
-
{ errorCode: 1023, errorKey: 'notificationNotFound',
|
|
37
|
-
{ errorCode: 1024, errorKey: 'bannerNotFound',
|
|
38
|
-
{ errorCode: 1025, errorKey: 'paymentProviderNotFound',
|
|
39
|
-
{ errorCode: 1026, errorKey: 'paymentMethodNotFound',
|
|
40
|
-
{ errorCode: 1027, errorKey: 'depositNotFound',
|
|
41
|
-
{ errorCode: 1028, errorKey: 'withdrawalNotFound',
|
|
42
|
-
{ errorCode: 1029, errorKey: 'noteNotFound',
|
|
43
|
-
{ errorCode: 1030, errorKey: 'promoCodeNotFound',
|
|
44
|
-
{ errorCode: 1031, errorKey: 'cashBackNotFound',
|
|
45
|
-
{ errorCode: 1032, errorKey: 'tournamentNotFound',
|
|
46
|
-
{ errorCode: 1033, errorKey: 'pageNotFound',
|
|
47
|
-
{ errorCode: 1034, errorKey: 'gameCashBackListNotFound',
|
|
48
|
-
{ errorCode: 1035, errorKey: 'bonusDepositRequired',
|
|
49
|
-
{ errorCode: 1036, errorKey: 'taskNotFound',
|
|
13
|
+
{ errorCode: 1000, errorKey: 'userNotFound', httpCode: 404, description: 'User was not found' },
|
|
14
|
+
{ errorCode: 1001, errorKey: 'unauthorized', httpCode: 401, description: 'The server requires user authentication' },
|
|
15
|
+
{ errorCode: 1002, errorKey: 'gameCategoryNotFound', httpCode: 404, description: 'Game`s category was not found' },
|
|
16
|
+
{ errorCode: 1003, errorKey: 'mediaResourceNotFound', httpCode: 404, description: 'Media resource was not found' },
|
|
17
|
+
{ errorCode: 1004, errorKey: 'roleNotFound', httpCode: 404, description: 'Role or permission were not found' },
|
|
18
|
+
{ errorCode: 1005, errorKey: 'duplicatedUniqueField', httpCode: 422, description: 'Some of unique fields were duplicated.' },
|
|
19
|
+
{ errorCode: 1006, errorKey: 'gameCollectionNotFound', httpCode: 404, description: 'Game`s collection was not found' },
|
|
20
|
+
{ errorCode: 1007, errorKey: 'gameTagNotFound', httpCode: 404, description: 'Game`s tag was not found' },
|
|
21
|
+
{ errorCode: 1008, errorKey: 'invalidConstraintField', httpCode: 422, description: 'Some of foreign keys fields were invalid.' },
|
|
22
|
+
{ errorCode: 1009, errorKey: 'gameProviderNotFound', httpCode: 404, description: 'Game`s provider was not found' },
|
|
23
|
+
{ errorCode: 1010, errorKey: 'gameNotFound', httpCode: 404, description: 'Game was not found' },
|
|
24
|
+
{ errorCode: 1011, errorKey: 'undefinedRequest', httpCode: 422, description: 'Request data or format is undefined for handler.' },
|
|
25
|
+
{ errorCode: 1012, errorKey: 'widgetNotFound', httpCode: 404, description: 'Widget[CMS] was not found' },
|
|
26
|
+
{ errorCode: 1013, errorKey: 'segmentNotFound', httpCode: 404, description: 'User`s Segment was not found' },
|
|
27
|
+
{ errorCode: 1014, errorKey: 'bonusNotFound', httpCode: 404, description: 'Bonus was not found' },
|
|
28
|
+
{ errorCode: 1015, errorKey: 'userBonusNotFound', httpCode: 404, description: 'User`s bonus was not found' },
|
|
29
|
+
{ errorCode: 1016, errorKey: 'freeSpinsNotFound', httpCode: 404, description: 'Free spins was not found' },
|
|
30
|
+
{ errorCode: 1017, errorKey: 'gameWagerListNotFound', httpCode: 404, description: 'Game`s wager list was not found' },
|
|
31
|
+
{ errorCode: 1018, errorKey: 'bonusAlreadyInUse', httpCode: 422, description: 'Bonus is already use(d)' },
|
|
32
|
+
{ errorCode: 1019, errorKey: 'bonusRestrictForClaim', httpCode: 422, description: 'Bonus does not fit for user`s claiming' },
|
|
33
|
+
{ errorCode: 1020, errorKey: 'bonusRewardAttachError', httpCode: 422, description: 'Bonus reward can not be attached.' },
|
|
34
|
+
{ errorCode: 1021, errorKey: 'loyaltyLevelNotFound', httpCode: 404, description: 'Loyalty level was not found' },
|
|
35
|
+
{ errorCode: 1022, errorKey: 'loyaltyPointNotFound', httpCode: 404, description: 'Loyalty point was not found' },
|
|
36
|
+
{ errorCode: 1023, errorKey: 'notificationNotFound', httpCode: 404, description: 'Notification was not found' },
|
|
37
|
+
{ errorCode: 1024, errorKey: 'bannerNotFound', httpCode: 404, description: 'Banner was not found' },
|
|
38
|
+
{ errorCode: 1025, errorKey: 'paymentProviderNotFound', httpCode: 404, description: 'Payment provider was not found' },
|
|
39
|
+
{ errorCode: 1026, errorKey: 'paymentMethodNotFound', httpCode: 404, description: 'Payment method was not found' },
|
|
40
|
+
{ errorCode: 1027, errorKey: 'depositNotFound', httpCode: 404, description: 'Deposit was not found' },
|
|
41
|
+
{ errorCode: 1028, errorKey: 'withdrawalNotFound', httpCode: 404, description: 'Withdrawal was not found' },
|
|
42
|
+
{ errorCode: 1029, errorKey: 'noteNotFound', httpCode: 404, description: 'User`s Note was not found' },
|
|
43
|
+
{ errorCode: 1030, errorKey: 'promoCodeNotFound', httpCode: 404, description: 'Promo Code was not found' },
|
|
44
|
+
{ errorCode: 1031, errorKey: 'cashBackNotFound', httpCode: 404, description: 'Cash Back was not found' },
|
|
45
|
+
{ errorCode: 1032, errorKey: 'tournamentNotFound', httpCode: 404, description: 'Tournament was not found' },
|
|
46
|
+
{ errorCode: 1033, errorKey: 'pageNotFound', httpCode: 404, description: 'Page was not found' },
|
|
47
|
+
{ errorCode: 1034, errorKey: 'gameCashBackListNotFound', httpCode: 404, description: 'Game`s cash back list was not found' },
|
|
48
|
+
{ errorCode: 1035, errorKey: 'bonusDepositRequired', httpCode: 404, description: 'For bonus activation desposit requited.' },
|
|
49
|
+
{ errorCode: 1036, errorKey: 'taskNotFound', httpCode: 404, description: 'Task for schedule was not found.' },
|
|
50
50
|
{ errorCode: 1037, errorKey: 'bonusConfirmationRequired', httpCode: 404, description: 'For bonus activation confirmation of personal user data requited.' },
|
|
51
|
-
{ errorCode: 1038, errorKey: 'promoNotFound',
|
|
52
|
-
{ errorCode: 1039, errorKey: 'badSignature',
|
|
53
|
-
{ errorCode: 1040, errorKey: 'mailTemplateNotFound',
|
|
54
|
-
{ errorCode: 1041, errorKey: 'domainNotFound',
|
|
55
|
-
{ errorCode: 1042, errorKey: 'domainAlreadyExists',
|
|
56
|
-
{ errorCode: 1043, errorKey: 'domainIsNotActivated',
|
|
57
|
-
{ errorCode: 1044, errorKey: 'domainCountriesNotFound',
|
|
58
|
-
{ errorCode: 1045, errorKey: 'footerPartnersNotFound',
|
|
59
|
-
{ errorCode: 1046, errorKey: 'footerBrandCoreNotFound',
|
|
60
|
-
{ errorCode: 1047, errorKey: 'footerPaymentsNotFound',
|
|
61
|
-
{ errorCode: 1048, errorKey: 'footerMainTextNotFound',
|
|
62
|
-
{ errorCode: 1049, errorKey: 'footerApplicationsNotFound',httpCode: 404, description: 'Footer Applications block were not found.' },
|
|
63
|
-
{ errorCode: 1050, errorKey: 'footerBlockAlreadyExists',
|
|
64
|
-
{ errorCode: 1051, errorKey: 'invalidTwoFaCode',
|
|
51
|
+
{ errorCode: 1038, errorKey: 'promoNotFound', httpCode: 404, description: 'Promo was not found.' },
|
|
52
|
+
{ errorCode: 1039, errorKey: 'badSignature', httpCode: 401, description: 'Untrusted request, bad signature.' },
|
|
53
|
+
{ errorCode: 1040, errorKey: 'mailTemplateNotFound', httpCode: 404, description: 'Email template was not found.' },
|
|
54
|
+
{ errorCode: 1041, errorKey: 'domainNotFound', httpCode: 404, description: 'Domain was not found.' },
|
|
55
|
+
{ errorCode: 1042, errorKey: 'domainAlreadyExists', httpCode: 422, description: 'Domain already in use.' },
|
|
56
|
+
{ errorCode: 1043, errorKey: 'domainIsNotActivated', httpCode: 422, description: 'Current Domain is not activated yet.' },
|
|
57
|
+
{ errorCode: 1044, errorKey: 'domainCountriesNotFound', httpCode: 404, description: 'Domain`s Countries were not found for primary zone.' },
|
|
58
|
+
{ errorCode: 1045, errorKey: 'footerPartnersNotFound', httpCode: 404, description: 'Footer Partners block were not found.' },
|
|
59
|
+
{ errorCode: 1046, errorKey: 'footerBrandCoreNotFound', httpCode: 404, description: 'Footer Brand Core block were not found.' },
|
|
60
|
+
{ errorCode: 1047, errorKey: 'footerPaymentsNotFound', httpCode: 404, description: 'Footer Payments block were not found.' },
|
|
61
|
+
{ errorCode: 1048, errorKey: 'footerMainTextNotFound', httpCode: 404, description: 'Footer Main Text block were not found.' },
|
|
62
|
+
{ errorCode: 1049, errorKey: 'footerApplicationsNotFound', httpCode: 404, description: 'Footer Applications block were not found.' },
|
|
63
|
+
{ errorCode: 1050, errorKey: 'footerBlockAlreadyExists', httpCode: 422, description: 'Footer block item already exists.' },
|
|
64
|
+
{ errorCode: 1051, errorKey: 'invalidTwoFaCode', httpCode: 422, description: 'Two Factor Auth code is invalid or expired.' }
|
|
65
65
|
];
|
|
66
66
|
|
|
67
|
-
const STATIC_BY_KEY = Object.fromEntries(STATIC_ERRORS.map(e => [e.errorKey, e]));
|
|
67
|
+
const STATIC_BY_KEY = Object.fromEntries(STATIC_ERRORS.map((e) => [e.errorKey, e]));
|
|
68
68
|
|
|
69
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Resolve error by key from cache (if any) or static table.
|
|
71
|
+
* @param {string} errorKey
|
|
72
|
+
* @returns {object|undefined}
|
|
73
|
+
*/
|
|
70
74
|
function resolveErrorByKey(errorKey) {
|
|
71
75
|
const cached = getValue('errorsMap');
|
|
72
76
|
if (Array.isArray(cached) && cached.length) {
|
|
@@ -78,29 +82,48 @@ function resolveErrorByKey(errorKey) {
|
|
|
78
82
|
|
|
79
83
|
// --- Base API object (do not export directly; we wrap it in a Proxy) ---
|
|
80
84
|
const api = {
|
|
81
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Legacy accessor kept for compatibility (returns JSON string).
|
|
87
|
+
* @param {string} errorKey
|
|
88
|
+
* @returns {string|undefined}
|
|
89
|
+
*/
|
|
82
90
|
getSingleError: (errorKey) => {
|
|
83
91
|
const obj = resolveErrorByKey(errorKey);
|
|
84
92
|
return obj ? JSON.stringify(obj) : undefined;
|
|
85
93
|
},
|
|
86
94
|
|
|
87
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* New API: get full error object.
|
|
97
|
+
* @param {string} errorKey
|
|
98
|
+
* @returns {object|undefined}
|
|
99
|
+
*/
|
|
88
100
|
get: (errorKey) => resolveErrorByKey(errorKey),
|
|
89
101
|
|
|
90
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* New API: get JSON string version (same shape as legacy).
|
|
104
|
+
* @param {string} errorKey
|
|
105
|
+
* @returns {string|undefined}
|
|
106
|
+
*/
|
|
91
107
|
getString: (errorKey) => {
|
|
92
108
|
const obj = resolveErrorByKey(errorKey);
|
|
93
109
|
return obj ? JSON.stringify(obj) : undefined;
|
|
94
110
|
},
|
|
95
111
|
|
|
96
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* New API: get numeric error code.
|
|
114
|
+
* @param {string} errorKey
|
|
115
|
+
* @returns {number|undefined}
|
|
116
|
+
*/
|
|
97
117
|
getCode: (errorKey) => resolveErrorByKey(errorKey)?.errorCode,
|
|
98
118
|
|
|
99
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* New API: list all static errors (useful for diagnostics).
|
|
121
|
+
* @returns {object[]}
|
|
122
|
+
*/
|
|
100
123
|
list: () => [...STATIC_ERRORS]
|
|
101
124
|
};
|
|
102
125
|
|
|
103
|
-
// --- Dynamic shortcuts: errorsMap.<errorKey>() returns
|
|
126
|
+
// --- Dynamic shortcuts: errorsMap.<errorKey>() returns OBJECT (same as get()) ---
|
|
104
127
|
module.exports = new Proxy(api, {
|
|
105
128
|
get(target, prop, receiver) {
|
|
106
129
|
// If method exists (get, getString, etc.) → return it
|
|
@@ -108,15 +131,11 @@ module.exports = new Proxy(api, {
|
|
|
108
131
|
return Reflect.get(target, prop, receiver);
|
|
109
132
|
}
|
|
110
133
|
|
|
111
|
-
// If property is a known errorKey → return a function () =>
|
|
134
|
+
// If property is a known errorKey → return a function () => get(errorKey) (OBJECT)
|
|
112
135
|
if (typeof prop === 'string' && STATIC_BY_KEY[prop]) {
|
|
113
|
-
// Legacy behavior: errorsMap.userNotFound() -> JSON string
|
|
114
136
|
return function () {
|
|
115
|
-
|
|
116
|
-
return obj ? JSON.stringify(obj) : undefined;
|
|
137
|
+
return target.get(prop);
|
|
117
138
|
};
|
|
118
|
-
// Или короче:
|
|
119
|
-
// return () => target.getString(prop);
|
|
120
139
|
}
|
|
121
140
|
|
|
122
141
|
// Otherwise undefined
|
|
@@ -124,9 +143,6 @@ module.exports = new Proxy(api, {
|
|
|
124
143
|
},
|
|
125
144
|
|
|
126
145
|
has(target, prop) {
|
|
127
|
-
return (
|
|
128
|
-
prop in target ||
|
|
129
|
-
(typeof prop === 'string' && !!STATIC_BY_KEY[prop])
|
|
130
|
-
);
|
|
146
|
+
return prop in target || (typeof prop === 'string' && !!STATIC_BY_KEY[prop]);
|
|
131
147
|
}
|
|
132
|
-
});
|
|
148
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "b2b-platform-utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.24",
|
|
4
4
|
"description": "Shared utilities for Node.js microservices: errors map, local cache, logger, numbers, dates, filesystem, media optimization, paginator, slugger, crypto wrapper, sanitize HTML, sorting.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "KingSizer",
|