@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.
Files changed (21) hide show
  1. package/build/backend/constants/index.d.ts +1 -0
  2. package/build/backend/constants/index.d.ts.map +1 -1
  3. package/build/backend/constants/index.js +1 -0
  4. package/build/backend/constants/language-codes.constant.d.ts +770 -0
  5. package/build/backend/constants/language-codes.constant.d.ts.map +1 -0
  6. package/build/backend/constants/language-codes.constant.js +242 -0
  7. package/build/backend/constants/subscription-page-config/subscription-page-config.contants.d.ts +2 -2
  8. package/build/backend/constants/subscription-page-config/subscription-page-config.contants.d.ts.map +1 -1
  9. package/build/backend/constants/subscription-page-config/subscription-page-config.contants.js +3 -2
  10. package/build/backend/models/subscription-page-config/subscription-page-config.schema.d.ts +363 -1166
  11. package/build/backend/models/subscription-page-config/subscription-page-config.schema.d.ts.map +1 -1
  12. package/build/backend/models/subscription-page-config/subscription-page-config.schema.js +27 -8
  13. package/build/backend/models/subscription-page-config/subscription-page-config.validator.d.ts +19 -3
  14. package/build/backend/models/subscription-page-config/subscription-page-config.validator.d.ts.map +1 -1
  15. package/build/backend/models/subscription-page-config/subscription-page-config.validator.js +64 -25
  16. package/build/frontend/constants/index.js +1 -0
  17. package/build/frontend/constants/language-codes.constant.js +239 -0
  18. package/build/frontend/constants/subscription-page-config/subscription-page-config.contants.js +3 -2
  19. package/build/frontend/models/subscription-page-config/subscription-page-config.schema.js +27 -8
  20. package/build/frontend/models/subscription-page-config/subscription-page-config.validator.js +64 -25
  21. package/package.json +1 -1
@@ -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 validateLocalizedTexts = (obj, requiredLocales, path, ctx) => {
6
- if (obj === null || typeof obj !== 'object')
7
- return;
8
- if ('en' in obj && typeof obj.en === 'string') {
9
- for (const locale of requiredLocales) {
10
- const value = obj[locale];
11
- if (!value || value.trim() === '') {
12
- ctx.addIssue({
13
- code: zod_1.z.ZodIssueCode.custom,
14
- message: `Missing required locale '${locale}' at ${path}`,
15
- path: [path, locale],
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
- return;
20
- }
21
- for (const [key, value] of Object.entries(obj)) {
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
- else if (typeof value === 'object' && value !== null) {
28
- (0, exports.validateLocalizedTexts)(value, requiredLocales, `${path}.${key}`, ctx);
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 ('en' in obj && typeof obj.en === 'string') {
63
- const allowedKeys = new Set(['en', ...activeLocales]);
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 || key === 'en') {
107
+ if (trimmed) {
69
108
  cleaned[key] = trimmed;
70
109
  }
71
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnawave/subscription-page-types",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "public": true,
5
5
  "license": "AGPL-3.0-only",
6
6
  "description": "A types library for Remnawave Subscription Page.",