@remnawave/subscription-page-types 0.1.3 → 0.1.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.
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 +346 -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 +29 -8
  13. package/build/backend/models/subscription-page-config/subscription-page-config.validator.d.ts +22 -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 +80 -26
  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 +29 -8
  20. package/build/frontend/models/subscription-page-config/subscription-page-config.validator.js +80 -26
  21. package/package.json +1 -1
@@ -1,35 +1,80 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cleanLocalizedTexts = exports.validateSvgReferences = exports.validateLocalizedTexts = void 0;
3
+ exports.cleanLocalizedTexts = exports.validateSvgReferences = exports.validateLocalizedTexts = exports.validateLocales = 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
- });
17
- }
5
+ const constants_1 = require("../../constants");
6
+ /**
7
+ * Валидирует что все локали являются валидными языковыми кодами
8
+ */
9
+ const validateLocales = (locales, ctx) => {
10
+ for (let i = 0; i < locales.length; i++) {
11
+ if (!(0, constants_1.isLanguageCode)(locales[i])) {
12
+ ctx.addIssue({
13
+ code: zod_1.z.ZodIssueCode.custom,
14
+ message: `Invalid language code '${locales[i]}' at locales[${i}]`,
15
+ path: ['locales', i],
16
+ });
18
17
  }
19
- return;
20
18
  }
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);
19
+ };
20
+ exports.validateLocales = validateLocales;
21
+ /**
22
+ * Проверяет что LocalizedText объект является таковым
23
+ * LocalizedText - это объект где ключи это языковые коды, а значения - строки
24
+ */
25
+ const isLocalizedText = (obj) => {
26
+ if (obj === null || typeof obj !== 'object' || Array.isArray(obj))
27
+ return false;
28
+ const entries = Object.entries(obj);
29
+ if (entries.length === 0)
30
+ return false;
31
+ // Проверяем что все значения - строки (характерно для LocalizedText)
32
+ // и что хотя бы один ключ выглядит как языковой код (2 символа)
33
+ const hasStringValues = entries.every(([, value]) => typeof value === 'string');
34
+ const hasLanguageCodeKey = entries.some(([key]) => key.length === 2);
35
+ return hasStringValues && hasLanguageCodeKey;
36
+ };
37
+ /**
38
+ * Валидирует что все обязательные локали присутствуют в LocalizedText полях
39
+ */
40
+ const validateLocalizedTexts = (data, requiredLocales, ctx) => {
41
+ const checkLocalizedText = (obj, path) => {
42
+ if (obj === null || typeof obj !== 'object')
43
+ return;
44
+ if (isLocalizedText(obj)) {
45
+ for (const locale of requiredLocales) {
46
+ const value = obj[locale];
47
+ if (!value || value.trim() === '') {
48
+ ctx.addIssue({
49
+ code: zod_1.z.ZodIssueCode.custom,
50
+ message: `Missing required locale '${locale}' at ${path}`,
51
+ path: [path, locale],
52
+ });
53
+ }
54
+ }
55
+ return;
56
+ }
57
+ if (Array.isArray(obj)) {
58
+ obj.forEach((item, index) => {
59
+ checkLocalizedText(item, `${path}[${index}]`);
25
60
  });
61
+ return;
26
62
  }
27
- else if (typeof value === 'object' && value !== null) {
28
- (0, exports.validateLocalizedTexts)(value, requiredLocales, `${path}.${key}`, ctx);
63
+ for (const [key, value] of Object.entries(obj)) {
64
+ if (typeof value === 'object' && value !== null) {
65
+ checkLocalizedText(value, `${path}.${key}`);
66
+ }
29
67
  }
30
- }
68
+ };
69
+ // Проверяем platforms
70
+ checkLocalizedText(data.platforms, 'platforms');
71
+ // Проверяем uiConfig
72
+ checkLocalizedText(data.uiConfig, 'uiConfig');
31
73
  };
32
74
  exports.validateLocalizedTexts = validateLocalizedTexts;
75
+ /**
76
+ * Валидирует что все svgIconKey ссылаются на существующие ключи в svgLibrary
77
+ */
33
78
  const validateSvgReferences = (data, ctx) => {
34
79
  const validKeys = new Set(Object.keys(data.svgLibrary));
35
80
  const checkSvgRef = (obj, path) => {
@@ -37,6 +82,9 @@ const validateSvgReferences = (data, ctx) => {
37
82
  return;
38
83
  for (const [key, value] of Object.entries(obj)) {
39
84
  if (key === 'svgIconKey' && typeof value === 'string') {
85
+ // Пустая строка = нет иконки (для опциональных полей)
86
+ if (value === '')
87
+ continue;
40
88
  if (!validKeys.has(value)) {
41
89
  ctx.addIssue({
42
90
  code: zod_1.z.ZodIssueCode.custom,
@@ -56,16 +104,22 @@ const validateSvgReferences = (data, ctx) => {
56
104
  checkSvgRef(data.platforms, 'platforms');
57
105
  };
58
106
  exports.validateSvgReferences = validateSvgReferences;
107
+ /**
108
+ * Очищает LocalizedText поля:
109
+ * - Оставляет только указанные локали
110
+ * - Делает trim() всем строкам
111
+ * - Удаляет пустые значения
112
+ */
59
113
  const cleanLocalizedTexts = (obj, activeLocales) => {
60
114
  if (obj === null || typeof obj !== 'object')
61
115
  return obj;
62
- if ('en' in obj && typeof obj.en === 'string') {
63
- const allowedKeys = new Set(['en', ...activeLocales]);
116
+ if (isLocalizedText(obj)) {
117
+ const allowedKeys = new Set(activeLocales);
64
118
  const cleaned = {};
65
119
  for (const [key, value] of Object.entries(obj)) {
66
- if (typeof value === 'string' && allowedKeys.has(key)) {
120
+ if (typeof value === 'string' && (0, constants_1.isLanguageCode)(key) && allowedKeys.has(key)) {
67
121
  const trimmed = value.trim();
68
- if (trimmed || key === 'en') {
122
+ if (trimmed) {
69
123
  cleaned[key] = trimmed;
70
124
  }
71
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnawave/subscription-page-types",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "public": true,
5
5
  "license": "AGPL-3.0-only",
6
6
  "description": "A types library for Remnawave Subscription Page.",