b2b-platform-utils 1.1.22 → 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 -70
- 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,62 +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',
|
|
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.' }
|
|
64
65
|
];
|
|
65
66
|
|
|
66
|
-
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]));
|
|
67
68
|
|
|
68
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Resolve error by key from cache (if any) or static table.
|
|
71
|
+
* @param {string} errorKey
|
|
72
|
+
* @returns {object|undefined}
|
|
73
|
+
*/
|
|
69
74
|
function resolveErrorByKey(errorKey) {
|
|
70
75
|
const cached = getValue('errorsMap');
|
|
71
76
|
if (Array.isArray(cached) && cached.length) {
|
|
@@ -77,29 +82,48 @@ function resolveErrorByKey(errorKey) {
|
|
|
77
82
|
|
|
78
83
|
// --- Base API object (do not export directly; we wrap it in a Proxy) ---
|
|
79
84
|
const api = {
|
|
80
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Legacy accessor kept for compatibility (returns JSON string).
|
|
87
|
+
* @param {string} errorKey
|
|
88
|
+
* @returns {string|undefined}
|
|
89
|
+
*/
|
|
81
90
|
getSingleError: (errorKey) => {
|
|
82
91
|
const obj = resolveErrorByKey(errorKey);
|
|
83
92
|
return obj ? JSON.stringify(obj) : undefined;
|
|
84
93
|
},
|
|
85
94
|
|
|
86
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* New API: get full error object.
|
|
97
|
+
* @param {string} errorKey
|
|
98
|
+
* @returns {object|undefined}
|
|
99
|
+
*/
|
|
87
100
|
get: (errorKey) => resolveErrorByKey(errorKey),
|
|
88
101
|
|
|
89
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* New API: get JSON string version (same shape as legacy).
|
|
104
|
+
* @param {string} errorKey
|
|
105
|
+
* @returns {string|undefined}
|
|
106
|
+
*/
|
|
90
107
|
getString: (errorKey) => {
|
|
91
108
|
const obj = resolveErrorByKey(errorKey);
|
|
92
109
|
return obj ? JSON.stringify(obj) : undefined;
|
|
93
110
|
},
|
|
94
111
|
|
|
95
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* New API: get numeric error code.
|
|
114
|
+
* @param {string} errorKey
|
|
115
|
+
* @returns {number|undefined}
|
|
116
|
+
*/
|
|
96
117
|
getCode: (errorKey) => resolveErrorByKey(errorKey)?.errorCode,
|
|
97
118
|
|
|
98
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* New API: list all static errors (useful for diagnostics).
|
|
121
|
+
* @returns {object[]}
|
|
122
|
+
*/
|
|
99
123
|
list: () => [...STATIC_ERRORS]
|
|
100
124
|
};
|
|
101
125
|
|
|
102
|
-
// --- Dynamic shortcuts: errorsMap.<errorKey>() returns
|
|
126
|
+
// --- Dynamic shortcuts: errorsMap.<errorKey>() returns OBJECT (same as get()) ---
|
|
103
127
|
module.exports = new Proxy(api, {
|
|
104
128
|
get(target, prop, receiver) {
|
|
105
129
|
// If method exists (get, getString, etc.) → return it
|
|
@@ -107,15 +131,11 @@ module.exports = new Proxy(api, {
|
|
|
107
131
|
return Reflect.get(target, prop, receiver);
|
|
108
132
|
}
|
|
109
133
|
|
|
110
|
-
// If property is a known errorKey → return a function () =>
|
|
134
|
+
// If property is a known errorKey → return a function () => get(errorKey) (OBJECT)
|
|
111
135
|
if (typeof prop === 'string' && STATIC_BY_KEY[prop]) {
|
|
112
|
-
// Legacy behavior: errorsMap.userNotFound() -> JSON string
|
|
113
136
|
return function () {
|
|
114
|
-
|
|
115
|
-
return obj ? JSON.stringify(obj) : undefined;
|
|
137
|
+
return target.get(prop);
|
|
116
138
|
};
|
|
117
|
-
// Или короче:
|
|
118
|
-
// return () => target.getString(prop);
|
|
119
139
|
}
|
|
120
140
|
|
|
121
141
|
// Otherwise undefined
|
|
@@ -123,9 +143,6 @@ module.exports = new Proxy(api, {
|
|
|
123
143
|
},
|
|
124
144
|
|
|
125
145
|
has(target, prop) {
|
|
126
|
-
return (
|
|
127
|
-
prop in target ||
|
|
128
|
-
(typeof prop === 'string' && !!STATIC_BY_KEY[prop])
|
|
129
|
-
);
|
|
146
|
+
return prop in target || (typeof prop === 'string' && !!STATIC_BY_KEY[prop]);
|
|
130
147
|
}
|
|
131
|
-
});
|
|
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",
|