hh-contracts 0.0.78 → 0.0.79

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ROLE_TYPE_VALUES = exports.ROLE_TYPES = void 0;
4
4
  exports.ROLE_TYPES = {
5
+ superAdmin: 'superAdmin',
5
6
  system: 'system',
6
7
  hotel: 'hotel',
7
8
  guest: 'guest',
@@ -33,36 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.TranslationsSchema = exports.TranslationsArraySchema = exports.TranslationItemSchema = exports.TranslationPersistedSchema = void 0;
36
+ exports.StringTranslationsByLangSchema = exports.makeTranslationsByLang = void 0;
37
37
  const z = __importStar(require("zod"));
38
38
  const language_keys_schema_1 = require("./language-keys.schema");
39
- const translatable_field_constant_1 = require("../constants/translatable-field.constant");
40
- const constants_1 = require("../constants");
41
- exports.TranslationPersistedSchema = z.object({
42
- entityName: z.enum(constants_1.ENTITY_VALUES),
43
- entityId: z.string(),
44
- lang: language_keys_schema_1.LanguageKeysSchema,
45
- field: z.enum(translatable_field_constant_1.TRANSLATABLE_FIELD_VALUES),
46
- text: z.string().min(1),
47
- });
48
- exports.TranslationItemSchema = exports.TranslationPersistedSchema.omit({
49
- entityId: true,
50
- entityName: true,
51
- field: true,
52
- });
53
- exports.TranslationsArraySchema = z
54
- .array(exports.TranslationItemSchema)
55
- .refine(items => items.length > 0, {
56
- params: { translationKey: 'errors.validation.atLeastOneTranslationRequired' },
57
- })
58
- .refine(items => {
59
- const langs = items.map(item => item.lang);
60
- const uniqueLangs = new Set(langs);
61
- return langs.length === uniqueLangs.size;
62
- }, {
63
- params: { translationKey: 'errors.validation.duplicateLanguagesNotAllowed' },
64
- });
65
- exports.TranslationsSchema = z.object({
66
- name: exports.TranslationsArraySchema,
67
- description: exports.TranslationsArraySchema,
68
- });
39
+ const makeTranslationsByLang = (schema) => z.record(language_keys_schema_1.LanguageKeysSchema, schema);
40
+ exports.makeTranslationsByLang = makeTranslationsByLang;
41
+ exports.StringTranslationsByLangSchema = (0, exports.makeTranslationsByLang)(z.string().min(1));
@@ -39,8 +39,6 @@ const common_1 = require("../common");
39
39
  exports.HotelPersistedSchema = z
40
40
  .object({
41
41
  id: z.uuid(),
42
- //убрать из модели так как у одного отеля может быть несколько юр лиц
43
- companyId: z.uuid(),
44
42
  slug: common_1.SlugSchema,
45
43
  status: z.enum(common_1.AppStatuses.HOTEL_VALUES),
46
44
  hasServices: z.boolean(),
package/build/index.js CHANGED
@@ -23,3 +23,4 @@ __exportStar(require("./permissions"), exports);
23
23
  __exportStar(require("./roles"), exports);
24
24
  __exportStar(require("./tenants"), exports);
25
25
  __exportStar(require("./translate"), exports);
26
+ __exportStar(require("./translations"), exports);
@@ -52,7 +52,7 @@ exports.PageLangTranslationSchema = z.object({
52
52
  .default({}),
53
53
  blocks: blocks_1.BlocksTranslationSchema.default({}),
54
54
  });
55
- const TranslationsSchema = z.record(common_1.LanguageKeysSchema, exports.PageLangTranslationSchema);
55
+ const TranslationsSchema = (0, common_1.makeTranslationsByLang)(exports.PageLangTranslationSchema);
56
56
  exports.PageSchema = z.object({
57
57
  meta: MetaSchema,
58
58
  blocks: z.array(blocks_1.BlockSchema),
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.PermissionListItemSchema = exports.PermissionWithTranslationsSchema = exports.PermissionPersistedSchema = exports.JsonConditionsSchema = void 0;
36
+ exports.PermissionListItemSchema = exports.PermissionWithTranslationsSchema = exports.PermissionLangTranslationSchema = exports.PermissionPersistedSchema = exports.JsonConditionsSchema = void 0;
37
37
  const z = __importStar(require("zod"));
38
38
  const common_1 = require("../common");
39
39
  exports.JsonConditionsSchema = z
@@ -51,7 +51,7 @@ exports.JsonConditionsSchema = z
51
51
  catch {
52
52
  return false;
53
53
  }
54
- }, { params: { translationKey: 'errors.validation.invalidJson' } });
54
+ }, { params: { messageKey: 'errors.validation.invalidJson' } });
55
55
  exports.PermissionPersistedSchema = z
56
56
  .object({
57
57
  id: z.uuid(),
@@ -60,10 +60,13 @@ exports.PermissionPersistedSchema = z
60
60
  conditions: exports.JsonConditionsSchema,
61
61
  })
62
62
  .extend(common_1.TimestampSchema.shape);
63
+ // V2 translations: all translatable fields are inside per-language translation object
64
+ exports.PermissionLangTranslationSchema = z.object({
65
+ name: z.string().min(3),
66
+ description: z.string().optional(),
67
+ });
63
68
  exports.PermissionWithTranslationsSchema = exports.PermissionPersistedSchema.extend({
64
- translations: common_1.TranslationsSchema.pick({ name: true, description: true }).partial({
65
- description: true,
66
- }),
69
+ translations: (0, common_1.makeTranslationsByLang)(exports.PermissionLangTranslationSchema),
67
70
  });
68
71
  exports.PermissionListItemSchema = exports.PermissionPersistedSchema.extend({
69
72
  name: z.string().nullable(),
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.RoleListItemSchema = exports.RoleWithTranslationsSchema = exports.RoleWithPermissionsSchema = exports.RolePersistedSchema = void 0;
36
+ exports.RoleListItemSchema = exports.RoleWithTranslationsSchema = exports.RoleLangTranslationSchema = exports.RoleWithPermissionsSchema = exports.RolePersistedSchema = void 0;
37
37
  const z = __importStar(require("zod"));
38
38
  const common_1 = require("../common");
39
39
  const permissions_1 = require("../permissions");
@@ -48,11 +48,12 @@ exports.RolePersistedSchema = z
48
48
  exports.RoleWithPermissionsSchema = exports.RolePersistedSchema.extend({
49
49
  permissionIds: common_1.UuidArraySchema.optional(),
50
50
  });
51
+ exports.RoleLangTranslationSchema = z.object({
52
+ name: z.string().min(3),
53
+ description: z.string().optional(),
54
+ });
51
55
  exports.RoleWithTranslationsSchema = exports.RoleWithPermissionsSchema.extend({
52
- translations: common_1.TranslationsSchema.pick({
53
- name: true,
54
- description: true,
55
- }).partial({ description: true }),
56
+ translations: (0, common_1.makeTranslationsByLang)(exports.RoleLangTranslationSchema),
56
57
  });
57
58
  exports.RoleListItemSchema = exports.RolePersistedSchema.extend({
58
59
  name: z.string().nullable(),
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./translation.models"), exports);
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.TranslationItemSchema = exports.TranslationPersistedSchema = void 0;
37
+ const z = __importStar(require("zod"));
38
+ const common_1 = require("../common");
39
+ exports.TranslationPersistedSchema = z.object({
40
+ entityName: z.enum(common_1.ENTITY_VALUES),
41
+ entityId: z.string(),
42
+ lang: common_1.LanguageKeysSchema,
43
+ field: z.string().min(1).max(255),
44
+ text: z.string().min(1),
45
+ });
46
+ exports.TranslationItemSchema = exports.TranslationPersistedSchema.omit({
47
+ entityId: true,
48
+ entityName: true,
49
+ field: true,
50
+ });
@@ -217,21 +217,10 @@ export type TAppError = TMappedErrors<typeof APP_ERRORS>;
217
217
  export type TAppErrorCode = TAppError['code'];
218
218
  export type TAppErrorMessageKey = TAppError['messageKey'];
219
219
 
220
- // type StringLeafPaths<T, K extends keyof T = keyof T> = K extends string
221
- // ? T[K] extends string
222
- // ? K
223
- // : T[K] extends Record<string, any>
224
- // ? `${K}.${StringLeafPaths<T[K]>}`
225
- // : never
226
- // : never;
227
-
228
- // export type I18nStringPath = StringLeafPaths<I18nTranslations>;
229
-
230
220
  export interface IBaseErrorDetails {
231
221
  type?: string;
232
222
  message?: string;
233
- messageKey?: TAppErrorMessageKey; // Вместо I18nPath
234
- directMessage?: string;
223
+ messageKey?: string;
235
224
  params?: Record<string, unknown>;
236
225
  }
237
226
 
@@ -1,4 +1,5 @@
1
1
  export const ROLE_TYPES = {
2
+ superAdmin: 'superAdmin',
2
3
  system: 'system',
3
4
  hotel: 'hotel',
4
5
  guest: 'guest',
@@ -1,43 +1,8 @@
1
1
  import * as z from 'zod';
2
2
  import { LanguageKeysSchema } from './language-keys.schema';
3
- import { TRANSLATABLE_FIELD_VALUES } from '../constants/translatable-field.constant';
4
- import { ENTITY_VALUES } from '../constants';
5
3
 
6
- export const TranslationPersistedSchema = z.object({
7
- entityName: z.enum(ENTITY_VALUES),
8
- entityId: z.string(),
9
- lang: LanguageKeysSchema,
10
- field: z.enum(TRANSLATABLE_FIELD_VALUES),
11
- text: z.string().min(1),
12
- });
13
- export type TTranslationPersisted = z.infer<typeof TranslationPersistedSchema>;
4
+ export const makeTranslationsByLang = <T extends z.ZodTypeAny>(schema: T) =>
5
+ z.record(LanguageKeysSchema, schema);
6
+ export type TranslationsByLang<T> = Partial<Record<z.infer<typeof LanguageKeysSchema>, T>>;
14
7
 
15
- export const TranslationItemSchema = TranslationPersistedSchema.omit({
16
- entityId: true,
17
- entityName: true,
18
- field: true,
19
- });
20
- export type TTranslationItem = z.infer<typeof TranslationItemSchema>;
21
-
22
- export const TranslationsArraySchema = z
23
- .array(TranslationItemSchema)
24
- .refine(items => items.length > 0, {
25
- params: { translationKey: 'errors.validation.atLeastOneTranslationRequired' },
26
- })
27
- .refine(
28
- items => {
29
- const langs = items.map(item => item.lang);
30
- const uniqueLangs = new Set(langs);
31
- return langs.length === uniqueLangs.size;
32
- },
33
- {
34
- params: { translationKey: 'errors.validation.duplicateLanguagesNotAllowed' },
35
- },
36
- );
37
- export type TTranslationsArray = z.infer<typeof TranslationsArraySchema>;
38
-
39
- export const TranslationsSchema = z.object({
40
- name: TranslationsArraySchema,
41
- description: TranslationsArraySchema,
42
- });
43
- export type TTranslations = z.infer<typeof TranslationsSchema>;
8
+ export const StringTranslationsByLangSchema = makeTranslationsByLang(z.string().min(1));
@@ -4,8 +4,6 @@ import { LANGUAGE_KEYS, TimestampSchema, AppStatuses, SlugSchema } from '../comm
4
4
  export const HotelPersistedSchema = z
5
5
  .object({
6
6
  id: z.uuid(),
7
- //убрать из модели так как у одного отеля может быть несколько юр лиц
8
- companyId: z.uuid(),
9
7
  slug: SlugSchema,
10
8
  status: z.enum(AppStatuses.HOTEL_VALUES),
11
9
  hasServices: z.boolean(),
package/index.ts CHANGED
@@ -7,3 +7,4 @@ export * from './permissions';
7
7
  export * from './roles';
8
8
  export * from './tenants';
9
9
  export * from './translate';
10
+ export * from './translations';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hh-contracts",
3
- "version": "0.0.78",
3
+ "version": "0.0.79",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {
@@ -10,6 +10,6 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "zod": "^4.0.17"
13
+ "zod": "^4.1.9"
14
14
  }
15
15
  }
@@ -1,5 +1,5 @@
1
1
  import * as z from 'zod';
2
- import { AppStatuses, LanguageKeysSchema, SlugSchema } from '../../common';
2
+ import { AppStatuses, LanguageKeysSchema, makeTranslationsByLang, SlugSchema } from '../../common';
3
3
  import { BlocksTranslationSchema, BlockSchema } from './blocks';
4
4
 
5
5
  const MetaSchema = z.object({
@@ -18,7 +18,7 @@ export const PageLangTranslationSchema = z.object({
18
18
  .default({}),
19
19
  blocks: BlocksTranslationSchema.default({}),
20
20
  });
21
- const TranslationsSchema = z.record(LanguageKeysSchema, PageLangTranslationSchema);
21
+ const TranslationsSchema = makeTranslationsByLang(PageLangTranslationSchema);
22
22
 
23
23
  export const PageSchema = z.object({
24
24
  meta: MetaSchema,
@@ -1,5 +1,5 @@
1
1
  import * as z from 'zod';
2
- import { AppAbility, TimestampSchema, TranslationsSchema } from '../common';
2
+ import { AppAbility, TimestampSchema, makeTranslationsByLang } from '../common';
3
3
 
4
4
  export const JsonConditionsSchema = z
5
5
  .string()
@@ -16,7 +16,7 @@ export const JsonConditionsSchema = z
16
16
  return false;
17
17
  }
18
18
  },
19
- { params: { translationKey: 'errors.validation.invalidJson' } },
19
+ { params: { messageKey: 'errors.validation.invalidJson' } },
20
20
  );
21
21
 
22
22
  export const PermissionPersistedSchema = z
@@ -31,10 +31,14 @@ export const PermissionPersistedSchema = z
31
31
 
32
32
  export type TPermissionPersisted = z.infer<typeof PermissionPersistedSchema>;
33
33
 
34
+ // V2 translations: all translatable fields are inside per-language translation object
35
+ export const PermissionLangTranslationSchema = z.object({
36
+ name: z.string().min(3),
37
+ description: z.string().optional(),
38
+ });
39
+
34
40
  export const PermissionWithTranslationsSchema = PermissionPersistedSchema.extend({
35
- translations: TranslationsSchema.pick({ name: true, description: true }).partial({
36
- description: true,
37
- }),
41
+ translations: makeTranslationsByLang(PermissionLangTranslationSchema),
38
42
  });
39
43
  export type TPermissionWithTranslations = z.infer<typeof PermissionWithTranslationsSchema>;
40
44
 
@@ -1,5 +1,10 @@
1
1
  import * as z from 'zod';
2
- import { ROLE_TYPE_VALUES, TimestampSchema, TranslationsSchema, UuidArraySchema } from '../common';
2
+ import {
3
+ ROLE_TYPE_VALUES,
4
+ TimestampSchema,
5
+ UuidArraySchema,
6
+ makeTranslationsByLang,
7
+ } from '../common';
3
8
  import { PermissionListItemSchema } from '../permissions';
4
9
 
5
10
  export const RolePersistedSchema = z
@@ -17,11 +22,13 @@ export const RoleWithPermissionsSchema = RolePersistedSchema.extend({
17
22
  });
18
23
  export type TRoleWithPermissions = z.infer<typeof RoleWithPermissionsSchema>;
19
24
 
25
+ export const RoleLangTranslationSchema = z.object({
26
+ name: z.string().min(3),
27
+ description: z.string().optional(),
28
+ });
29
+
20
30
  export const RoleWithTranslationsSchema = RoleWithPermissionsSchema.extend({
21
- translations: TranslationsSchema.pick({
22
- name: true,
23
- description: true,
24
- }).partial({ description: true }),
31
+ translations: makeTranslationsByLang(RoleLangTranslationSchema),
25
32
  });
26
33
  export type TRoleWithTranslations = z.infer<typeof RoleWithTranslationsSchema>;
27
34
 
@@ -0,0 +1 @@
1
+ export * from './translation.models';
@@ -0,0 +1,18 @@
1
+ import * as z from 'zod';
2
+ import { ENTITY_VALUES, LanguageKeysSchema } from '../common';
3
+
4
+ export const TranslationPersistedSchema = z.object({
5
+ entityName: z.enum(ENTITY_VALUES),
6
+ entityId: z.string(),
7
+ lang: LanguageKeysSchema,
8
+ field: z.string().min(1).max(255),
9
+ text: z.string().min(1),
10
+ });
11
+ export type TTranslationPersisted = z.infer<typeof TranslationPersistedSchema>;
12
+
13
+ export const TranslationItemSchema = TranslationPersistedSchema.omit({
14
+ entityId: true,
15
+ entityName: true,
16
+ field: true,
17
+ });
18
+ export type TTranslationItem = z.infer<typeof TranslationItemSchema>;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //export * from './navigation-item.transform';
@@ -1,27 +0,0 @@
1
- "use strict";
2
- // import * as z from 'zod';
3
- // import { NavigationItemEntityBaseSchema, NavigationItemEntitySchema } from '../models';
4
- // import { TDeepOptionalize } from '../types';
5
- // const NavigationItemBase = NavigationItemEntityBaseSchema.transform(
6
- // ({ parentId, description, iconKey, link, routeComponentKey, disabled, order, ...rest }) => ({
7
- // ...rest,
8
- // description: description || undefined,
9
- // iconKey: iconKey || undefined,
10
- // link: link || undefined,
11
- // routeComponentKey: routeComponentKey || undefined,
12
- // disabled: disabled === null ? undefined : disabled,
13
- // }),
14
- // );
15
- // type TInput = z.input<typeof NavigationItemEntityBaseSchema> & {
16
- // children?: TInput[];
17
- // };
18
- // type TOutput = z.output<typeof NavigationItemBase> & {
19
- // children?: TOutput[];
20
- // };
21
- // export const NavigationItem = z.lazy(() =>
22
- // NavigationItemEntitySchema.transform(({ children, ...rest }) => ({
23
- // ...NavigationItemBase.parse(rest),
24
- // children: children?.length ? children.map(child => NavigationItem.parse(child)) : undefined,
25
- // })),
26
- // );
27
- // export type TNavigationItem = TDeepOptionalize<z.infer<typeof NavigationItem>>;
@@ -1 +0,0 @@
1
- //export * from './navigation-item.transform';
@@ -1,29 +0,0 @@
1
- // import * as z from 'zod';
2
- // import { NavigationItemEntityBaseSchema, NavigationItemEntitySchema } from '../models';
3
- // import { TDeepOptionalize } from '../types';
4
-
5
- // const NavigationItemBase = NavigationItemEntityBaseSchema.transform(
6
- // ({ parentId, description, iconKey, link, routeComponentKey, disabled, order, ...rest }) => ({
7
- // ...rest,
8
- // description: description || undefined,
9
- // iconKey: iconKey || undefined,
10
- // link: link || undefined,
11
- // routeComponentKey: routeComponentKey || undefined,
12
- // disabled: disabled === null ? undefined : disabled,
13
- // }),
14
- // );
15
-
16
- // type TInput = z.input<typeof NavigationItemEntityBaseSchema> & {
17
- // children?: TInput[];
18
- // };
19
- // type TOutput = z.output<typeof NavigationItemBase> & {
20
- // children?: TOutput[];
21
- // };
22
-
23
- // export const NavigationItem = z.lazy(() =>
24
- // NavigationItemEntitySchema.transform(({ children, ...rest }) => ({
25
- // ...NavigationItemBase.parse(rest),
26
- // children: children?.length ? children.map(child => NavigationItem.parse(child)) : undefined,
27
- // })),
28
- // );
29
- // export type TNavigationItem = TDeepOptionalize<z.infer<typeof NavigationItem>>;