@hosterai/types 0.0.21 → 0.0.22

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/README.md CHANGED
@@ -27,6 +27,24 @@ or
27
27
  yarn add @hosterai/types
28
28
  ```
29
29
 
30
+ ## Peer Dependencies
31
+
32
+ This package relies on the following peer dependencies. Install them in your project:
33
+
34
+ ```bash
35
+ npm install class-validator class-transformer class-validator-jsonschema reflect-metadata
36
+ # If your project already uses Express, ensure a compatible version is installed
37
+ npm install express
38
+ ```
39
+
40
+ Note:
41
+
42
+ - Import `reflect-metadata` once at the entry point of your application (e.g., `main.ts` or `index.ts`).
43
+
44
+ ```ts
45
+ import 'reflect-metadata';
46
+ ```
47
+
30
48
  ## Core Concepts
31
49
 
32
50
  ### DTOs (Data Transfer Objects)
@@ -167,6 +185,15 @@ Transformer functions for converting plain objects to typed DTOs:
167
185
  - `transformMenu`: Converts plain objects to `MenuDtoWithUrl` or `MenuDtoWithSubmenu` based on the type property.
168
186
  - `transformSettings`: Converts plain objects to `SettingsWithUrlDto` or `SettingsWithTabsDto` based on the presence of url or tabs properties.
169
187
 
188
+ ## Generating JSON Schemas
189
+
190
+ This package can generate JSON Schemas for all DTOs using the `class-validator-jsonschema` integration. The generated schemas are used in OpenAPI and other tooling.
191
+
192
+ - Script: `npm run build:schemas`
193
+ - Output: `openapi/schemas/components.schemas.ts`
194
+
195
+ During packaging, schemas are built automatically via the `prepack` script. Run the command locally whenever you change DTOs or validators and want to refresh the schemas.
196
+
170
197
  ## Usage Example
171
198
 
172
199
  Here is an example of how to use a DTO and its validator.
@@ -28,8 +28,8 @@ export declare class FieldDto {
28
28
  * Type of the field
29
29
  */
30
30
  type: FieldTypeEnum;
31
- reapetableMin?: number;
32
- reapetableMax?: number;
31
+ repeatableMin?: number;
32
+ repeatableMax?: number;
33
33
  /**
34
34
  * Indicates if the field is required
35
35
  */
@@ -39,9 +39,13 @@ export declare class FieldDto {
39
39
  */
40
40
  disabled: boolean;
41
41
  /**
42
- * Indicates if the field is hidden
42
+ * Indicates if the field is hidden in order
43
43
  */
44
- hidden: boolean;
44
+ visibleInOrder: boolean;
45
+ /**
46
+ * Indicates if the field is visible in client panel
47
+ */
48
+ visibleInClientPanel: boolean;
45
49
  /**
46
50
  * Regex validation pattern for the field
47
51
  */
@@ -103,12 +103,12 @@ __decorate([
103
103
  (0, class_validator_1.IsOptional)(),
104
104
  (0, class_validator_1.IsNumber)(),
105
105
  __metadata("design:type", Number)
106
- ], FieldDto.prototype, "reapetableMin", void 0);
106
+ ], FieldDto.prototype, "repeatableMin", void 0);
107
107
  __decorate([
108
108
  (0, class_validator_1.IsOptional)(),
109
109
  (0, class_validator_1.IsNumber)(),
110
110
  __metadata("design:type", Number)
111
- ], FieldDto.prototype, "reapetableMax", void 0);
111
+ ], FieldDto.prototype, "repeatableMax", void 0);
112
112
  __decorate([
113
113
  (0, class_validator_1.IsBoolean)(),
114
114
  (0, class_validator_1.IsDefined)(),
@@ -133,12 +133,22 @@ __decorate([
133
133
  (0, class_validator_1.IsBoolean)(),
134
134
  (0, class_validator_1.IsDefined)(),
135
135
  (0, class_validator_jsonschema_1.JSONSchema)({
136
- title: 'Hidden',
137
- description: 'Whether the field is hidden.',
136
+ title: 'Visible In Order',
137
+ description: 'Whether the field is visible in order.',
138
138
  type: 'boolean',
139
139
  }),
140
140
  __metadata("design:type", Boolean)
141
- ], FieldDto.prototype, "hidden", void 0);
141
+ ], FieldDto.prototype, "visibleInOrder", void 0);
142
+ __decorate([
143
+ (0, class_validator_1.IsBoolean)(),
144
+ (0, class_validator_1.IsDefined)(),
145
+ (0, class_validator_jsonschema_1.JSONSchema)({
146
+ title: 'Visible In Client Panel',
147
+ description: 'Whether the field is visible in client panel.',
148
+ type: 'boolean',
149
+ }),
150
+ __metadata("design:type", Boolean)
151
+ ], FieldDto.prototype, "visibleInClientPanel", void 0);
142
152
  __decorate([
143
153
  (0, class_validator_1.IsString)(),
144
154
  (0, is_regex_validator_1.IsRegex)(),
@@ -198,6 +208,6 @@ __decorate([
198
208
  __metadata("design:type", Boolean)
199
209
  ], FieldDto.prototype, "upgradable", void 0);
200
210
  exports.FieldDto = FieldDto = __decorate([
201
- (0, all_or_none_validator_1.AllOrNoneProperty)(['reapetableMin', 'reapetableMax']),
202
- (0, min_less_or_equal_validator_1.MinLessOrEqualMaxProperty)(['reapetableMin', 'reapetableMax'])
211
+ (0, all_or_none_validator_1.AllOrNoneProperty)(['repeatableMin', 'repeatableMax']),
212
+ (0, min_less_or_equal_validator_1.MinLessOrEqualMaxProperty)(['repeatableMin', 'repeatableMax'])
203
213
  ], FieldDto);
@@ -31,7 +31,7 @@ __decorate([
31
31
  description: 'Notification channel type.',
32
32
  type: 'string',
33
33
  enum: Object.values(notification_message_type_enum_1.NotificationMessageTypeEnum),
34
- example: Object.values(notification_message_type_enum_1.NotificationMessageTypeEnum)[0]
34
+ example: Object.values(notification_message_type_enum_1.NotificationMessageTypeEnum)[0],
35
35
  }),
36
36
  __metadata("design:type", String)
37
37
  ], NotificationInfoDto.prototype, "type", void 0);
@@ -46,8 +46,12 @@ __decorate([
46
46
  type: 'array',
47
47
  items: { $ref: '#/components/schemas/UnitDto' },
48
48
  example: [
49
- { id: 'messages', unitDescription: 'Message sent', intervalDescription: 'Per month' }
50
- ]
49
+ {
50
+ id: 'messages',
51
+ unitDescription: 'Message sent',
52
+ intervalDescription: 'Per month',
53
+ },
54
+ ],
51
55
  }),
52
56
  __metadata("design:type", Array)
53
57
  ], NotificationInfoDto.prototype, "payPerUseUnits", void 0);
@@ -4,6 +4,7 @@ export declare enum ActionsEnum {
4
4
  UPGRADE = "upgrade",
5
5
  DOWNGRADE = "downgrade",
6
6
  TRANSFER = "transfer",
7
+ TRADE = "trade",
7
8
  SUSPEND = "suspend",
8
9
  UNSUSPEND = "unsuspend",
9
10
  DELETE = "delete"
@@ -8,6 +8,7 @@ var ActionsEnum;
8
8
  ActionsEnum["UPGRADE"] = "upgrade";
9
9
  ActionsEnum["DOWNGRADE"] = "downgrade";
10
10
  ActionsEnum["TRANSFER"] = "transfer";
11
+ ActionsEnum["TRADE"] = "trade";
11
12
  ActionsEnum["SUSPEND"] = "suspend";
12
13
  ActionsEnum["UNSUSPEND"] = "unsuspend";
13
14
  ActionsEnum["DELETE"] = "delete";
@@ -495,7 +495,7 @@ export declare const ComponentsSchemas: {
495
495
  };
496
496
  readonly supportedActions: {
497
497
  readonly items: {
498
- readonly enum: readonly ["create", "renew", "upgrade", "downgrade", "transfer", "suspend", "unsuspend", "delete"];
498
+ readonly enum: readonly ["create", "renew", "upgrade", "downgrade", "transfer", "trade", "suspend", "unsuspend", "delete"];
499
499
  readonly type: "string";
500
500
  };
501
501
  readonly type: "array";
@@ -642,7 +642,7 @@ export declare const ComponentsSchemas: {
642
642
  };
643
643
  readonly supportedActions: {
644
644
  readonly items: {
645
- readonly enum: readonly ["create", "renew", "upgrade", "downgrade", "transfer", "suspend", "unsuspend", "delete"];
645
+ readonly enum: readonly ["create", "renew", "upgrade", "downgrade", "transfer", "trade", "suspend", "unsuspend", "delete"];
646
646
  readonly type: "string";
647
647
  };
648
648
  readonly type: "array";
@@ -787,10 +787,10 @@ export declare const ComponentsSchemas: {
787
787
  readonly title: "Field Type";
788
788
  readonly description: "Type of the field.";
789
789
  };
790
- readonly reapetableMin: {
790
+ readonly repeatableMin: {
791
791
  readonly type: "number";
792
792
  };
793
- readonly reapetableMax: {
793
+ readonly repeatableMax: {
794
794
  readonly type: "number";
795
795
  };
796
796
  readonly required: {
@@ -809,13 +809,21 @@ export declare const ComponentsSchemas: {
809
809
  readonly title: "Disabled";
810
810
  readonly description: "Whether the field is disabled.";
811
811
  };
812
- readonly hidden: {
812
+ readonly visibleInOrder: {
813
813
  readonly not: {
814
814
  readonly type: "null";
815
815
  };
816
816
  readonly type: "boolean";
817
- readonly title: "Hidden";
818
- readonly description: "Whether the field is hidden.";
817
+ readonly title: "Visible In Order";
818
+ readonly description: "Whether the field is visible in order.";
819
+ };
820
+ readonly visibleInClientPanel: {
821
+ readonly not: {
822
+ readonly type: "null";
823
+ };
824
+ readonly type: "boolean";
825
+ readonly title: "Visible In Client Panel";
826
+ readonly description: "Whether the field is visible in client panel.";
819
827
  };
820
828
  readonly regexValidation: {
821
829
  readonly type: "string";
@@ -854,7 +862,7 @@ export declare const ComponentsSchemas: {
854
862
  };
855
863
  };
856
864
  readonly type: "object";
857
- readonly required: readonly ["id", "label", "value", "type", "required", "disabled", "hidden", "upgradable"];
865
+ readonly required: readonly ["id", "label", "value", "type", "required", "disabled", "visibleInOrder", "visibleInClientPanel", "upgradable"];
858
866
  };
859
867
  readonly ProductInfoDto: {
860
868
  readonly properties: {
@@ -938,7 +946,7 @@ export declare const ComponentsSchemas: {
938
946
  };
939
947
  readonly supportedActions: {
940
948
  readonly items: {
941
- readonly enum: readonly ["create", "renew", "upgrade", "downgrade", "transfer", "suspend", "unsuspend", "delete"];
949
+ readonly enum: readonly ["create", "renew", "upgrade", "downgrade", "transfer", "trade", "suspend", "unsuspend", "delete"];
942
950
  readonly type: "string";
943
951
  };
944
952
  readonly type: "array";
@@ -747,6 +747,7 @@ exports.ComponentsSchemas = {
747
747
  "upgrade",
748
748
  "downgrade",
749
749
  "transfer",
750
+ "trade",
750
751
  "suspend",
751
752
  "unsuspend",
752
753
  "delete"
@@ -1332,6 +1333,7 @@ exports.ComponentsSchemas = {
1332
1333
  "upgrade",
1333
1334
  "downgrade",
1334
1335
  "transfer",
1336
+ "trade",
1335
1337
  "suspend",
1336
1338
  "unsuspend",
1337
1339
  "delete"
@@ -1918,10 +1920,10 @@ exports.ComponentsSchemas = {
1918
1920
  "title": "Field Type",
1919
1921
  "description": "Type of the field."
1920
1922
  },
1921
- "reapetableMin": {
1923
+ "repeatableMin": {
1922
1924
  "type": "number"
1923
1925
  },
1924
- "reapetableMax": {
1926
+ "repeatableMax": {
1925
1927
  "type": "number"
1926
1928
  },
1927
1929
  "required": {
@@ -1940,13 +1942,21 @@ exports.ComponentsSchemas = {
1940
1942
  "title": "Disabled",
1941
1943
  "description": "Whether the field is disabled."
1942
1944
  },
1943
- "hidden": {
1945
+ "visibleInOrder": {
1944
1946
  "not": {
1945
1947
  "type": "null"
1946
1948
  },
1947
1949
  "type": "boolean",
1948
- "title": "Hidden",
1949
- "description": "Whether the field is hidden."
1950
+ "title": "Visible In Order",
1951
+ "description": "Whether the field is visible in order."
1952
+ },
1953
+ "visibleInClientPanel": {
1954
+ "not": {
1955
+ "type": "null"
1956
+ },
1957
+ "type": "boolean",
1958
+ "title": "Visible In Client Panel",
1959
+ "description": "Whether the field is visible in client panel."
1950
1960
  },
1951
1961
  "regexValidation": {
1952
1962
  "type": "string",
@@ -1992,7 +2002,8 @@ exports.ComponentsSchemas = {
1992
2002
  "type",
1993
2003
  "required",
1994
2004
  "disabled",
1995
- "hidden",
2005
+ "visibleInOrder",
2006
+ "visibleInClientPanel",
1996
2007
  "upgradable"
1997
2008
  ]
1998
2009
  },
@@ -2273,6 +2284,7 @@ exports.ComponentsSchemas = {
2273
2284
  "upgrade",
2274
2285
  "downgrade",
2275
2286
  "transfer",
2287
+ "trade",
2276
2288
  "suspend",
2277
2289
  "unsuspend",
2278
2290
  "delete"
@@ -11,7 +11,8 @@ const baseValidDto = {
11
11
  type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
12
12
  required: true,
13
13
  disabled: false,
14
- hidden: false,
14
+ visibleInOrder: false,
15
+ visibleInClientPanel: false,
15
16
  upgradable: false,
16
17
  };
17
18
  describe('FieldDto Validator', () => {
@@ -31,7 +32,7 @@ describe('FieldDto Validator', () => {
31
32
  describe('Missing required fields', () => {
32
33
  it('should return errors for all missing required fields (except upgradable)', () => {
33
34
  const errors = (0, field_validator_1.validateFieldDto)({});
34
- const requiredProps = ['id', 'label', 'value', 'type', 'required', 'disabled', 'hidden'];
35
+ const requiredProps = ['id', 'label', 'value', 'type', 'required', 'disabled', 'visibleInOrder', 'visibleInClientPanel'];
35
36
  for (const prop of requiredProps) {
36
37
  expect(errors.some(e => e.property === prop)).toBe(true);
37
38
  }
@@ -74,26 +75,26 @@ describe('FieldDto Validator', () => {
74
75
  });
75
76
  });
76
77
  describe('Repeatable constraints (AllOrNone and Min<=Max)', () => {
77
- it('should fail when only reapetableMin is present', () => {
78
- const dto = { ...baseValidDto, reapetableMin: 1 };
78
+ it('should fail when only repeatableMin is present', () => {
79
+ const dto = { ...baseValidDto, repeatableMin: 1 };
79
80
  const errors = (0, field_validator_1.validateFieldDto)(dto);
80
81
  expect(errors.length).toBeGreaterThan(0);
81
82
  // Class-level error; ensure at least one constraint exists
82
83
  expect(errors.some(e => e.constraints && (e.constraints['AllOrNone'] || Object.values(e.constraints).some(msg => msg.includes('All of'))))).toBe(true);
83
84
  });
84
- it('should fail when only reapetableMax is present', () => {
85
- const dto = { ...baseValidDto, reapetableMax: 2 };
85
+ it('should fail when only repeatableMax is present', () => {
86
+ const dto = { ...baseValidDto, repeatableMax: 2 };
86
87
  const errors = (0, field_validator_1.validateFieldDto)(dto);
87
88
  expect(errors.length).toBeGreaterThan(0);
88
89
  expect(errors.some(e => e.constraints && (e.constraints['AllOrNone'] || Object.values(e.constraints).some(msg => msg.includes('All of'))))).toBe(true);
89
90
  });
90
- it('should pass when both present and reapetableMin <= reapetableMax', () => {
91
- const dto = { ...baseValidDto, reapetableMin: 1, reapetableMax: 2 };
91
+ it('should pass when both present and repeatableMin <= repeatableMax', () => {
92
+ const dto = { ...baseValidDto, repeatableMin: 1, repeatableMax: 2 };
92
93
  const errors = (0, field_validator_1.validateFieldDto)(dto);
93
94
  expect(errors).toHaveLength(0);
94
95
  });
95
- it('should fail when both present and reapetableMin > reapetableMax', () => {
96
- const dto = { ...baseValidDto, reapetableMin: 3, reapetableMax: 2 };
96
+ it('should fail when both present and repeatableMin > repeatableMax', () => {
97
+ const dto = { ...baseValidDto, repeatableMin: 3, repeatableMax: 2 };
97
98
  const errors = (0, field_validator_1.validateFieldDto)(dto);
98
99
  expect(errors.length).toBeGreaterThan(0);
99
100
  expect(errors.some(e => e.constraints && (e.constraints['MinLessOrEqualMax'] || Object.values(e.constraints).some(msg => msg.includes('must be less than or equal'))))).toBe(true);
@@ -14,7 +14,8 @@ describe('ProductInfoDto Validator', () => {
14
14
  type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
15
15
  required: false,
16
16
  disabled: false,
17
- hidden: false,
17
+ visibleInOrder: false,
18
+ visibleInClientPanel: true,
18
19
  upgradable: false
19
20
  };
20
21
  const invalidField = {
@@ -170,7 +171,7 @@ describe('ProductInfoDto Validator', () => {
170
171
  });
171
172
  });
172
173
  describe('FieldDto class-level constraints inside ProductInfoDto', () => {
173
- it('fails when a FieldDto has only reapetableMin (AllOrNone)', () => {
174
+ it('fails when a FieldDto has only repeatableMin (AllOrNone)', () => {
174
175
  const fieldWithOnlyMin = {
175
176
  id: 'f1',
176
177
  label: [{ language: language_enum_1.LanguageEnum.EN, text: 'label' }],
@@ -178,9 +179,10 @@ describe('ProductInfoDto Validator', () => {
178
179
  type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
179
180
  required: false,
180
181
  disabled: false,
181
- hidden: false,
182
+ visibleInOrder: false,
183
+ visibleInClientPanel: true,
182
184
  upgradable: false,
183
- reapetableMin: 1,
185
+ repeatableMin: 1,
184
186
  };
185
187
  const dto = {
186
188
  title: 'Test',
@@ -191,7 +193,7 @@ describe('ProductInfoDto Validator', () => {
191
193
  const errors = (0, product_info_validator_1.validateProductInfoDto)(dto);
192
194
  expect(errors.length).toBeGreaterThan(0);
193
195
  });
194
- it('fails when a FieldDto has only reapetableMax (AllOrNone)', () => {
196
+ it('fails when a FieldDto has only repeatableMax (AllOrNone)', () => {
195
197
  const fieldWithOnlyMax = {
196
198
  id: 'f2',
197
199
  label: [{ language: language_enum_1.LanguageEnum.EN, text: 'label' }],
@@ -199,9 +201,10 @@ describe('ProductInfoDto Validator', () => {
199
201
  type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
200
202
  required: false,
201
203
  disabled: false,
202
- hidden: false,
204
+ visibleInOrder: false,
205
+ visibleInClientPanel: true,
203
206
  upgradable: false,
204
- reapetableMax: 2,
207
+ repeatableMax: 2,
205
208
  };
206
209
  const dto = {
207
210
  title: 'Test',
@@ -220,10 +223,11 @@ describe('ProductInfoDto Validator', () => {
220
223
  type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
221
224
  required: false,
222
225
  disabled: false,
223
- hidden: false,
226
+ visibleInOrder: false,
227
+ visibleInClientPanel: true,
224
228
  upgradable: false,
225
- reapetableMin: 1,
226
- reapetableMax: 2,
229
+ repeatableMin: 1,
230
+ repeatableMax: 2,
227
231
  };
228
232
  const dto = {
229
233
  title: 'Test',
@@ -241,10 +245,11 @@ describe('ProductInfoDto Validator', () => {
241
245
  type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
242
246
  required: false,
243
247
  disabled: false,
244
- hidden: false,
248
+ visibleInOrder: false,
249
+ visibleInClientPanel: true,
245
250
  upgradable: false,
246
- reapetableMin: 5,
247
- reapetableMax: 2,
251
+ repeatableMin: 5,
252
+ repeatableMax: 2,
248
253
  };
249
254
  const dto = {
250
255
  title: 'Test',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hosterai/types",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {