@remnawave/subscription-page-types 0.1.2 → 0.1.4
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/build/backend/constants/index.d.ts +1 -0
- package/build/backend/constants/index.d.ts.map +1 -1
- package/build/backend/constants/index.js +1 -0
- package/build/backend/constants/language-codes.constant.d.ts +770 -0
- package/build/backend/constants/language-codes.constant.d.ts.map +1 -0
- package/build/backend/constants/language-codes.constant.js +242 -0
- package/build/backend/constants/subscription-page-config/subscription-page-config.contants.d.ts +2 -2
- package/build/backend/constants/subscription-page-config/subscription-page-config.contants.d.ts.map +1 -1
- package/build/backend/constants/subscription-page-config/subscription-page-config.contants.js +3 -2
- package/build/backend/models/subscription-page-config/subscription-page-config.schema.d.ts +363 -1166
- package/build/backend/models/subscription-page-config/subscription-page-config.schema.d.ts.map +1 -1
- package/build/backend/models/subscription-page-config/subscription-page-config.schema.js +27 -8
- package/build/backend/models/subscription-page-config/subscription-page-config.validator.d.ts +19 -3
- package/build/backend/models/subscription-page-config/subscription-page-config.validator.d.ts.map +1 -1
- package/build/backend/models/subscription-page-config/subscription-page-config.validator.js +64 -25
- package/build/frontend/constants/index.js +1 -0
- package/build/frontend/constants/language-codes.constant.js +239 -0
- package/build/frontend/constants/subscription-page-config/subscription-page-config.contants.js +3 -2
- package/build/frontend/models/subscription-page-config/subscription-page-config.schema.js +27 -8
- package/build/frontend/models/subscription-page-config/subscription-page-config.validator.js +64 -25
- package/package.json +1 -1
package/build/frontend/models/subscription-page-config/subscription-page-config.validator.js
CHANGED
|
@@ -2,34 +2,64 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cleanLocalizedTexts = exports.validateSvgReferences = exports.validateLocalizedTexts = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
/**
|
|
7
|
+
* Проверяет что LocalizedText объект является таковым
|
|
8
|
+
* LocalizedText - это объект где ключи это языковые коды, а значения - строки
|
|
9
|
+
*/
|
|
10
|
+
const isLocalizedText = (obj) => {
|
|
11
|
+
if (obj === null || typeof obj !== 'object' || Array.isArray(obj))
|
|
12
|
+
return false;
|
|
13
|
+
const entries = Object.entries(obj);
|
|
14
|
+
if (entries.length === 0)
|
|
15
|
+
return false;
|
|
16
|
+
// Проверяем что все значения - строки (характерно для LocalizedText)
|
|
17
|
+
// и что хотя бы один ключ выглядит как языковой код (2 символа)
|
|
18
|
+
const hasStringValues = entries.every(([, value]) => typeof value === 'string');
|
|
19
|
+
const hasLanguageCodeKey = entries.some(([key]) => key.length === 2);
|
|
20
|
+
return hasStringValues && hasLanguageCodeKey;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Валидирует что все обязательные локали присутствуют в LocalizedText полях
|
|
24
|
+
*/
|
|
25
|
+
const validateLocalizedTexts = (data, requiredLocales, ctx) => {
|
|
26
|
+
const checkLocalizedText = (obj, path) => {
|
|
27
|
+
if (obj === null || typeof obj !== 'object')
|
|
28
|
+
return;
|
|
29
|
+
if (isLocalizedText(obj)) {
|
|
30
|
+
for (const locale of requiredLocales) {
|
|
31
|
+
const value = obj[locale];
|
|
32
|
+
if (!value || value.trim() === '') {
|
|
33
|
+
ctx.addIssue({
|
|
34
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
35
|
+
message: `Missing required locale '${locale}' at ${path}`,
|
|
36
|
+
path: [path, locale],
|
|
37
|
+
});
|
|
38
|
+
}
|
|
17
39
|
}
|
|
40
|
+
return;
|
|
18
41
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (Array.isArray(value)) {
|
|
23
|
-
value.forEach((item, index) => {
|
|
24
|
-
(0, exports.validateLocalizedTexts)(item, requiredLocales, `${path}.${key}[${index}]`, ctx);
|
|
42
|
+
if (Array.isArray(obj)) {
|
|
43
|
+
obj.forEach((item, index) => {
|
|
44
|
+
checkLocalizedText(item, `${path}[${index}]`);
|
|
25
45
|
});
|
|
46
|
+
return;
|
|
26
47
|
}
|
|
27
|
-
|
|
28
|
-
(
|
|
48
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
49
|
+
if (typeof value === 'object' && value !== null) {
|
|
50
|
+
checkLocalizedText(value, `${path}.${key}`);
|
|
51
|
+
}
|
|
29
52
|
}
|
|
30
|
-
}
|
|
53
|
+
};
|
|
54
|
+
// Проверяем platforms
|
|
55
|
+
checkLocalizedText(data.platforms, 'platforms');
|
|
56
|
+
// Проверяем uiConfig
|
|
57
|
+
checkLocalizedText(data.uiConfig, 'uiConfig');
|
|
31
58
|
};
|
|
32
59
|
exports.validateLocalizedTexts = validateLocalizedTexts;
|
|
60
|
+
/**
|
|
61
|
+
* Валидирует что все svgIconKey ссылаются на существующие ключи в svgLibrary
|
|
62
|
+
*/
|
|
33
63
|
const validateSvgReferences = (data, ctx) => {
|
|
34
64
|
const validKeys = new Set(Object.keys(data.svgLibrary));
|
|
35
65
|
const checkSvgRef = (obj, path) => {
|
|
@@ -37,6 +67,9 @@ const validateSvgReferences = (data, ctx) => {
|
|
|
37
67
|
return;
|
|
38
68
|
for (const [key, value] of Object.entries(obj)) {
|
|
39
69
|
if (key === 'svgIconKey' && typeof value === 'string') {
|
|
70
|
+
// Пустая строка = нет иконки (для опциональных полей)
|
|
71
|
+
if (value === '')
|
|
72
|
+
continue;
|
|
40
73
|
if (!validKeys.has(value)) {
|
|
41
74
|
ctx.addIssue({
|
|
42
75
|
code: zod_1.z.ZodIssueCode.custom,
|
|
@@ -56,16 +89,22 @@ const validateSvgReferences = (data, ctx) => {
|
|
|
56
89
|
checkSvgRef(data.platforms, 'platforms');
|
|
57
90
|
};
|
|
58
91
|
exports.validateSvgReferences = validateSvgReferences;
|
|
92
|
+
/**
|
|
93
|
+
* Очищает LocalizedText поля:
|
|
94
|
+
* - Оставляет только указанные локали
|
|
95
|
+
* - Делает trim() всем строкам
|
|
96
|
+
* - Удаляет пустые значения
|
|
97
|
+
*/
|
|
59
98
|
const cleanLocalizedTexts = (obj, activeLocales) => {
|
|
60
99
|
if (obj === null || typeof obj !== 'object')
|
|
61
100
|
return obj;
|
|
62
|
-
if (
|
|
63
|
-
const allowedKeys = new Set(
|
|
101
|
+
if (isLocalizedText(obj)) {
|
|
102
|
+
const allowedKeys = new Set(activeLocales);
|
|
64
103
|
const cleaned = {};
|
|
65
104
|
for (const [key, value] of Object.entries(obj)) {
|
|
66
|
-
if (typeof value === 'string' && allowedKeys.has(key)) {
|
|
105
|
+
if (typeof value === 'string' && (0, constants_1.isLanguageCode)(key) && allowedKeys.has(key)) {
|
|
67
106
|
const trimmed = value.trim();
|
|
68
|
-
if (trimmed
|
|
107
|
+
if (trimmed) {
|
|
69
108
|
cleaned[key] = trimmed;
|
|
70
109
|
}
|
|
71
110
|
}
|