@diia-inhouse/validators 1.17.0
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/LICENCE.md +287 -0
- package/README.md +93 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.js +20 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/rule.js +3 -0
- package/dist/interfaces/rule.js.map +1 -0
- package/dist/interfaces/schema.js +3 -0
- package/dist/interfaces/schema.js.map +1 -0
- package/dist/interfaces/validationSchema.js +3 -0
- package/dist/interfaces/validationSchema.js.map +1 -0
- package/dist/rules/buffer.js +31 -0
- package/dist/rules/buffer.js.map +1 -0
- package/dist/rules/date.js +50 -0
- package/dist/rules/date.js.map +1 -0
- package/dist/rules/index.js +23 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/internationalPhoneNumber.js +31 -0
- package/dist/rules/internationalPhoneNumber.js.map +1 -0
- package/dist/rules/objectId.js +31 -0
- package/dist/rules/objectId.js.map +1 -0
- package/dist/rules/phoneNumber.js +35 -0
- package/dist/rules/phoneNumber.js.map +1 -0
- package/dist/rules/version.js +50 -0
- package/dist/rules/version.js.map +1 -0
- package/dist/schemas/index.js +88 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/interfaces/index.d.ts +3 -0
- package/dist/types/interfaces/rule.d.ts +13 -0
- package/dist/types/interfaces/schema.d.ts +5 -0
- package/dist/types/interfaces/validationSchema.d.ts +86 -0
- package/dist/types/rules/buffer.d.ts +7 -0
- package/dist/types/rules/date.d.ts +9 -0
- package/dist/types/rules/index.d.ts +6 -0
- package/dist/types/rules/internationalPhoneNumber.d.ts +8 -0
- package/dist/types/rules/objectId.d.ts +7 -0
- package/dist/types/rules/phoneNumber.d.ts +9 -0
- package/dist/types/rules/version.d.ts +10 -0
- package/dist/types/schemas/index.d.ts +13 -0
- package/dist/types/validator.d.ts +10 -0
- package/dist/validator.js +50 -0
- package/dist/validator.js.map +1 -0
- package/package.json +87 -0
package/LICENCE.md
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
EUROPEAN UNION PUBLIC LICENCE v. 1.2
|
|
2
|
+
EUPL © the European Union 2007, 2016
|
|
3
|
+
|
|
4
|
+
This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined
|
|
5
|
+
below) which is provided under the terms of this Licence. Any use of the Work,
|
|
6
|
+
other than as authorised under this Licence is prohibited (to the extent such
|
|
7
|
+
use is covered by a right of the copyright holder of the Work).
|
|
8
|
+
|
|
9
|
+
The Work is provided under the terms of this Licence when the Licensor (as
|
|
10
|
+
defined below) has placed the following notice immediately following the
|
|
11
|
+
copyright notice for the Work:
|
|
12
|
+
|
|
13
|
+
Licensed under the EUPL
|
|
14
|
+
|
|
15
|
+
or has expressed by any other means his willingness to license under the EUPL.
|
|
16
|
+
|
|
17
|
+
1. Definitions
|
|
18
|
+
|
|
19
|
+
In this Licence, the following terms have the following meaning:
|
|
20
|
+
|
|
21
|
+
- ‘The Licence’: this Licence.
|
|
22
|
+
|
|
23
|
+
- ‘The Original Work’: the work or software distributed or communicated by the
|
|
24
|
+
Licensor under this Licence, available as Source Code and also as Executable
|
|
25
|
+
Code as the case may be.
|
|
26
|
+
|
|
27
|
+
- ‘Derivative Works’: the works or software that could be created by the
|
|
28
|
+
Licensee, based upon the Original Work or modifications thereof. This Licence
|
|
29
|
+
does not define the extent of modification or dependence on the Original Work
|
|
30
|
+
required in order to classify a work as a Derivative Work; this extent is
|
|
31
|
+
determined by copyright law applicable in the country mentioned in Article 15.
|
|
32
|
+
|
|
33
|
+
- ‘The Work’: the Original Work or its Derivative Works.
|
|
34
|
+
|
|
35
|
+
- ‘The Source Code’: the human-readable form of the Work which is the most
|
|
36
|
+
convenient for people to study and modify.
|
|
37
|
+
|
|
38
|
+
- ‘The Executable Code’: any code which has generally been compiled and which is
|
|
39
|
+
meant to be interpreted by a computer as a program.
|
|
40
|
+
|
|
41
|
+
- ‘The Licensor’: the natural or legal person that distributes or communicates
|
|
42
|
+
the Work under the Licence.
|
|
43
|
+
|
|
44
|
+
- ‘Contributor(s)’: any natural or legal person who modifies the Work under the
|
|
45
|
+
Licence, or otherwise contributes to the creation of a Derivative Work.
|
|
46
|
+
|
|
47
|
+
- ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of
|
|
48
|
+
the Work under the terms of the Licence.
|
|
49
|
+
|
|
50
|
+
- ‘Distribution’ or ‘Communication’: any act of selling, giving, lending,
|
|
51
|
+
renting, distributing, communicating, transmitting, or otherwise making
|
|
52
|
+
available, online or offline, copies of the Work or providing access to its
|
|
53
|
+
essential functionalities at the disposal of any other natural or legal
|
|
54
|
+
person.
|
|
55
|
+
|
|
56
|
+
2. Scope of the rights granted by the Licence
|
|
57
|
+
|
|
58
|
+
The Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
|
|
59
|
+
sublicensable licence to do the following, for the duration of copyright vested
|
|
60
|
+
in the Original Work:
|
|
61
|
+
|
|
62
|
+
- use the Work in any circumstance and for all usage,
|
|
63
|
+
- reproduce the Work,
|
|
64
|
+
- modify the Work, and make Derivative Works based upon the Work,
|
|
65
|
+
- communicate to the public, including the right to make available or display
|
|
66
|
+
the Work or copies thereof to the public and perform publicly, as the case may
|
|
67
|
+
be, the Work,
|
|
68
|
+
- distribute the Work or copies thereof,
|
|
69
|
+
- lend and rent the Work or copies thereof,
|
|
70
|
+
- sublicense rights in the Work or copies thereof.
|
|
71
|
+
|
|
72
|
+
Those rights can be exercised on any media, supports and formats, whether now
|
|
73
|
+
known or later invented, as far as the applicable law permits so.
|
|
74
|
+
|
|
75
|
+
In the countries where moral rights apply, the Licensor waives his right to
|
|
76
|
+
exercise his moral right to the extent allowed by law in order to make effective
|
|
77
|
+
the licence of the economic rights here above listed.
|
|
78
|
+
|
|
79
|
+
The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to
|
|
80
|
+
any patents held by the Licensor, to the extent necessary to make use of the
|
|
81
|
+
rights granted on the Work under this Licence.
|
|
82
|
+
|
|
83
|
+
3. Communication of the Source Code
|
|
84
|
+
|
|
85
|
+
The Licensor may provide the Work either in its Source Code form, or as
|
|
86
|
+
Executable Code. If the Work is provided as Executable Code, the Licensor
|
|
87
|
+
provides in addition a machine-readable copy of the Source Code of the Work
|
|
88
|
+
along with each copy of the Work that the Licensor distributes or indicates, in
|
|
89
|
+
a notice following the copyright notice attached to the Work, a repository where
|
|
90
|
+
the Source Code is easily and freely accessible for as long as the Licensor
|
|
91
|
+
continues to distribute or communicate the Work.
|
|
92
|
+
|
|
93
|
+
4. Limitations on copyright
|
|
94
|
+
|
|
95
|
+
Nothing in this Licence is intended to deprive the Licensee of the benefits from
|
|
96
|
+
any exception or limitation to the exclusive rights of the rights owners in the
|
|
97
|
+
Work, of the exhaustion of those rights or of other applicable limitations
|
|
98
|
+
thereto.
|
|
99
|
+
|
|
100
|
+
5. Obligations of the Licensee
|
|
101
|
+
|
|
102
|
+
The grant of the rights mentioned above is subject to some restrictions and
|
|
103
|
+
obligations imposed on the Licensee. Those obligations are the following:
|
|
104
|
+
|
|
105
|
+
Attribution right: The Licensee shall keep intact all copyright, patent or
|
|
106
|
+
trademarks notices and all notices that refer to the Licence and to the
|
|
107
|
+
disclaimer of warranties. The Licensee must include a copy of such notices and a
|
|
108
|
+
copy of the Licence with every copy of the Work he/she distributes or
|
|
109
|
+
communicates. The Licensee must cause any Derivative Work to carry prominent
|
|
110
|
+
notices stating that the Work has been modified and the date of modification.
|
|
111
|
+
|
|
112
|
+
Copyleft clause: If the Licensee distributes or communicates copies of the
|
|
113
|
+
Original Works or Derivative Works, this Distribution or Communication will be
|
|
114
|
+
done under the terms of this Licence or of a later version of this Licence
|
|
115
|
+
unless the Original Work is expressly distributed only under this version of the
|
|
116
|
+
Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee
|
|
117
|
+
(becoming Licensor) cannot offer or impose any additional terms or conditions on
|
|
118
|
+
the Work or Derivative Work that alter or restrict the terms of the Licence.
|
|
119
|
+
|
|
120
|
+
Compatibility clause: If the Licensee Distributes or Communicates Derivative
|
|
121
|
+
Works or copies thereof based upon both the Work and another work licensed under
|
|
122
|
+
a Compatible Licence, this Distribution or Communication can be done under the
|
|
123
|
+
terms of this Compatible Licence. For the sake of this clause, ‘Compatible
|
|
124
|
+
Licence’ refers to the licences listed in the appendix attached to this Licence.
|
|
125
|
+
Should the Licensee's obligations under the Compatible Licence conflict with
|
|
126
|
+
his/her obligations under this Licence, the obligations of the Compatible
|
|
127
|
+
Licence shall prevail.
|
|
128
|
+
|
|
129
|
+
Provision of Source Code: When distributing or communicating copies of the Work,
|
|
130
|
+
the Licensee will provide a machine-readable copy of the Source Code or indicate
|
|
131
|
+
a repository where this Source will be easily and freely available for as long
|
|
132
|
+
as the Licensee continues to distribute or communicate the Work.
|
|
133
|
+
|
|
134
|
+
Legal Protection: This Licence does not grant permission to use the trade names,
|
|
135
|
+
trademarks, service marks, or names of the Licensor, except as required for
|
|
136
|
+
reasonable and customary use in describing the origin of the Work and
|
|
137
|
+
reproducing the content of the copyright notice.
|
|
138
|
+
|
|
139
|
+
6. Chain of Authorship
|
|
140
|
+
|
|
141
|
+
The original Licensor warrants that the copyright in the Original Work granted
|
|
142
|
+
hereunder is owned by him/her or licensed to him/her and that he/she has the
|
|
143
|
+
power and authority to grant the Licence.
|
|
144
|
+
|
|
145
|
+
Each Contributor warrants that the copyright in the modifications he/she brings
|
|
146
|
+
to the Work are owned by him/her or licensed to him/her and that he/she has the
|
|
147
|
+
power and authority to grant the Licence.
|
|
148
|
+
|
|
149
|
+
Each time You accept the Licence, the original Licensor and subsequent
|
|
150
|
+
Contributors grant You a licence to their contributions to the Work, under the
|
|
151
|
+
terms of this Licence.
|
|
152
|
+
|
|
153
|
+
7. Disclaimer of Warranty
|
|
154
|
+
|
|
155
|
+
The Work is a work in progress, which is continuously improved by numerous
|
|
156
|
+
Contributors. It is not a finished work and may therefore contain defects or
|
|
157
|
+
‘bugs’ inherent to this type of development.
|
|
158
|
+
|
|
159
|
+
For the above reason, the Work is provided under the Licence on an ‘as is’ basis
|
|
160
|
+
and without warranties of any kind concerning the Work, including without
|
|
161
|
+
limitation merchantability, fitness for a particular purpose, absence of defects
|
|
162
|
+
or errors, accuracy, non-infringement of intellectual property rights other than
|
|
163
|
+
copyright as stated in Article 6 of this Licence.
|
|
164
|
+
|
|
165
|
+
This disclaimer of warranty is an essential part of the Licence and a condition
|
|
166
|
+
for the grant of any rights to the Work.
|
|
167
|
+
|
|
168
|
+
8. Disclaimer of Liability
|
|
169
|
+
|
|
170
|
+
Except in the cases of wilful misconduct or damages directly caused to natural
|
|
171
|
+
persons, the Licensor will in no event be liable for any direct or indirect,
|
|
172
|
+
material or moral, damages of any kind, arising out of the Licence or of the use
|
|
173
|
+
of the Work, including without limitation, damages for loss of goodwill, work
|
|
174
|
+
stoppage, computer failure or malfunction, loss of data or any commercial
|
|
175
|
+
damage, even if the Licensor has been advised of the possibility of such damage.
|
|
176
|
+
However, the Licensor will be liable under statutory product liability laws as
|
|
177
|
+
far such laws apply to the Work.
|
|
178
|
+
|
|
179
|
+
9. Additional agreements
|
|
180
|
+
|
|
181
|
+
While distributing the Work, You may choose to conclude an additional agreement,
|
|
182
|
+
defining obligations or services consistent with this Licence. However, if
|
|
183
|
+
accepting obligations, You may act only on your own behalf and on your sole
|
|
184
|
+
responsibility, not on behalf of the original Licensor or any other Contributor,
|
|
185
|
+
and only if You agree to indemnify, defend, and hold each Contributor harmless
|
|
186
|
+
for any liability incurred by, or claims asserted against such Contributor by
|
|
187
|
+
the fact You have accepted any warranty or additional liability.
|
|
188
|
+
|
|
189
|
+
10. Acceptance of the Licence
|
|
190
|
+
|
|
191
|
+
The provisions of this Licence can be accepted by clicking on an icon ‘I agree’
|
|
192
|
+
placed under the bottom of a window displaying the text of this Licence or by
|
|
193
|
+
affirming consent in any other similar way, in accordance with the rules of
|
|
194
|
+
applicable law. Clicking on that icon indicates your clear and irrevocable
|
|
195
|
+
acceptance of this Licence and all of its terms and conditions.
|
|
196
|
+
|
|
197
|
+
Similarly, you irrevocably accept this Licence and all of its terms and
|
|
198
|
+
conditions by exercising any rights granted to You by Article 2 of this Licence,
|
|
199
|
+
such as the use of the Work, the creation by You of a Derivative Work or the
|
|
200
|
+
Distribution or Communication by You of the Work or copies thereof.
|
|
201
|
+
|
|
202
|
+
11. Information to the public
|
|
203
|
+
|
|
204
|
+
In case of any Distribution or Communication of the Work by means of electronic
|
|
205
|
+
communication by You (for example, by offering to download the Work from a
|
|
206
|
+
remote location) the distribution channel or media (for example, a website) must
|
|
207
|
+
at least provide to the public the information requested by the applicable law
|
|
208
|
+
regarding the Licensor, the Licence and the way it may be accessible, concluded,
|
|
209
|
+
stored and reproduced by the Licensee.
|
|
210
|
+
|
|
211
|
+
12. Termination of the Licence
|
|
212
|
+
|
|
213
|
+
The Licence and the rights granted hereunder will terminate automatically upon
|
|
214
|
+
any breach by the Licensee of the terms of the Licence.
|
|
215
|
+
|
|
216
|
+
Such a termination will not terminate the licences of any person who has
|
|
217
|
+
received the Work from the Licensee under the Licence, provided such persons
|
|
218
|
+
remain in full compliance with the Licence.
|
|
219
|
+
|
|
220
|
+
13. Miscellaneous
|
|
221
|
+
|
|
222
|
+
Without prejudice of Article 9 above, the Licence represents the complete
|
|
223
|
+
agreement between the Parties as to the Work.
|
|
224
|
+
|
|
225
|
+
If any provision of the Licence is invalid or unenforceable under applicable
|
|
226
|
+
law, this will not affect the validity or enforceability of the Licence as a
|
|
227
|
+
whole. Such provision will be construed or reformed so as necessary to make it
|
|
228
|
+
valid and enforceable.
|
|
229
|
+
|
|
230
|
+
The European Commission may publish other linguistic versions or new versions of
|
|
231
|
+
this Licence or updated versions of the Appendix, so far this is required and
|
|
232
|
+
reasonable, without reducing the scope of the rights granted by the Licence. New
|
|
233
|
+
versions of the Licence will be published with a unique version number.
|
|
234
|
+
|
|
235
|
+
All linguistic versions of this Licence, approved by the European Commission,
|
|
236
|
+
have identical value. Parties can take advantage of the linguistic version of
|
|
237
|
+
their choice.
|
|
238
|
+
|
|
239
|
+
14. Jurisdiction
|
|
240
|
+
|
|
241
|
+
Without prejudice to specific agreement between parties,
|
|
242
|
+
|
|
243
|
+
- any litigation resulting from the interpretation of this License, arising
|
|
244
|
+
between the European Union institutions, bodies, offices or agencies, as a
|
|
245
|
+
Licensor, and any Licensee, will be subject to the jurisdiction of the Court
|
|
246
|
+
of Justice of the European Union, as laid down in article 272 of the Treaty on
|
|
247
|
+
the Functioning of the European Union,
|
|
248
|
+
|
|
249
|
+
- any litigation arising between other parties and resulting from the
|
|
250
|
+
interpretation of this License, will be subject to the exclusive jurisdiction
|
|
251
|
+
of the competent court where the Licensor resides or conducts its primary
|
|
252
|
+
business.
|
|
253
|
+
|
|
254
|
+
15. Applicable Law
|
|
255
|
+
|
|
256
|
+
Without prejudice to specific agreement between parties,
|
|
257
|
+
|
|
258
|
+
- this Licence shall be governed by the law of the European Union Member State
|
|
259
|
+
where the Licensor has his seat, resides or has his registered office,
|
|
260
|
+
|
|
261
|
+
- this licence shall be governed by Belgian law if the Licensor has no seat,
|
|
262
|
+
residence or registered office inside a European Union Member State.
|
|
263
|
+
|
|
264
|
+
Appendix
|
|
265
|
+
|
|
266
|
+
‘Compatible Licences’ according to Article 5 EUPL are:
|
|
267
|
+
|
|
268
|
+
- GNU General Public License (GPL) v. 2, v. 3
|
|
269
|
+
- GNU Affero General Public License (AGPL) v. 3
|
|
270
|
+
- Open Software License (OSL) v. 2.1, v. 3.0
|
|
271
|
+
- Eclipse Public License (EPL) v. 1.0
|
|
272
|
+
- CeCILL v. 2.0, v. 2.1
|
|
273
|
+
- Mozilla Public Licence (MPL) v. 2
|
|
274
|
+
- GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
|
|
275
|
+
- Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for
|
|
276
|
+
works other than software
|
|
277
|
+
- European Union Public Licence (EUPL) v. 1.1, v. 1.2
|
|
278
|
+
- Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong
|
|
279
|
+
Reciprocity (LiLiQ-R+).
|
|
280
|
+
|
|
281
|
+
The European Commission may update this Appendix to later versions of the above
|
|
282
|
+
licences without producing a new version of the EUPL, as long as they provide
|
|
283
|
+
the rights granted in Article 2 of this Licence and protect the covered Source
|
|
284
|
+
Code from exclusive appropriation.
|
|
285
|
+
|
|
286
|
+
All other changes or additions to this Appendix require the production of a new
|
|
287
|
+
EUPL version.
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Diia
|
|
2
|
+
|
|
3
|
+
This repository provides an overview over the flagship product [**Diia**](https://diia.gov.ua/) developed by the [**Ministry of Digital Transformation of Ukraine**](https://thedigital.gov.ua/).
|
|
4
|
+
|
|
5
|
+
**Diia** is an app with access to citizen’s digital documents and government services.
|
|
6
|
+
|
|
7
|
+
The application was created so that Ukrainians could interact with the state in a few clicks, without spending their time on queues and paperwork - **Diia** open source application will help countries, companies and communities build a foundation for long-term relationships. At the heart of these relations are openness, efficiency and humanity.
|
|
8
|
+
|
|
9
|
+
We're pleased to share the **Diia** project with you.
|
|
10
|
+
|
|
11
|
+
## Useful Links
|
|
12
|
+
|
|
13
|
+
| Topic | Link | Description |
|
|
14
|
+
| --------------------------------------------- | -------------------------- | -------------------------------------------------------------------------- |
|
|
15
|
+
| Ministry of Digital Transformation of Ukraine | https://thedigital.gov.ua/ | The Official homepage of the Ministry of Digital Transformation of Ukraine |
|
|
16
|
+
| Diia App | https://diia.gov.ua/ | The Official website for the Diia application |
|
|
17
|
+
|
|
18
|
+
## Getting Started
|
|
19
|
+
|
|
20
|
+
This repository contains the package with data validation functionality.
|
|
21
|
+
|
|
22
|
+
## Build Process
|
|
23
|
+
|
|
24
|
+
### **1. Clone codebase via `git clone` command**
|
|
25
|
+
|
|
26
|
+
Example:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
git clone https://github.com/diia-open-source/be-pkg-validators.git pkg-validators
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
### **2. Go to code base root directory**
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
cd ./pkg-validators
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
### **3. Install npm dependencies**
|
|
43
|
+
|
|
44
|
+
The installation of dependencies consists of the following 2 steps:
|
|
45
|
+
|
|
46
|
+
#### **1. Manually clone, build and link dependencies from `@diia-inhouse` scope**
|
|
47
|
+
|
|
48
|
+
Each Diia service depends on dependencies from `@diia-inhouse/<package>` scope which are distributed across different repositories, are built separately, and aren't published into public npm registry.
|
|
49
|
+
|
|
50
|
+
The full list of such dependencies can be found in the target service `package.json` file in `dependencies` and `devDependencies` sections respectively.
|
|
51
|
+
|
|
52
|
+
Detailed instructions on how to link dependencies from `@diia-inhouse/<package>` scope are described in `LINKDEPS.md` which can be found here
|
|
53
|
+
https://github.com/diia-open-source/diia-setup-howto/tree/main/backend
|
|
54
|
+
|
|
55
|
+
#### **2. Install public npm dependencies and use those linked from `@diia-inhouse` scope**
|
|
56
|
+
|
|
57
|
+
In order to install and use the linked dependencies for `pkg-validators` the following command can be used:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
$ cd ./pkg-validators
|
|
61
|
+
$ npm link @diia-inhouse/db @diia-inhouse/redis ... @diia-inhouse/<package-name>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
In case all dependencies from `@diia-inhouse` scope are linked, and can be resolved, you will then have a complete list of dependencies installed for the service code base.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
### **4. Build package**
|
|
69
|
+
|
|
70
|
+
In order to build the service you have to run the command `npm run build` inside the root directory of service code base as per:
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
$ cd ./pkg-validators
|
|
74
|
+
$ npm run build
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## How to contribute
|
|
80
|
+
|
|
81
|
+
The Diia project welcomes contributions into this solution; please refer to the CONTRIBUTING.md file for details
|
|
82
|
+
|
|
83
|
+
## Licensing
|
|
84
|
+
|
|
85
|
+
Copyright (C) Diia and all other contributors.
|
|
86
|
+
|
|
87
|
+
Licensed under the **EUPL** (the "License"); you may not use this file except in compliance with the License. Re-use is permitted, although not encouraged, under the EUPL, with the exception of source files that contain a different license.
|
|
88
|
+
|
|
89
|
+
You may obtain a copy of the License at [https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12](https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12).
|
|
90
|
+
|
|
91
|
+
Questions regarding the Diia project, the License and any re-use should be directed to [modt.opensource@thedigital.gov.ua](mailto:modt.opensource@thedigital.gov.ua).
|
|
92
|
+
|
|
93
|
+
This project incorporates third party material. In all cases the original copyright notices and the license under which these third party dependencies were provided remains as so. In relation to the Typescript dependency you should also review the [Typescript Third Party Notices](https://github.com/microsoft/TypeScript/blob/9684ba6b0d73c37546ada901e5d0a5324de7fc1d/ThirdPartyNoticeText.txt).
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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("./interfaces"), exports);
|
|
18
|
+
__exportStar(require("./validator"), exports);
|
|
19
|
+
__exportStar(require("./schemas"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAE5B,8CAA2B;AAE3B,4CAAyB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./rule"), exports);
|
|
18
|
+
__exportStar(require("./schema"), exports);
|
|
19
|
+
__exportStar(require("./validationSchema"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAsB;AAEtB,2CAAwB;AAExB,qDAAkC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule.js","sourceRoot":"","sources":["../../src/interfaces/rule.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/interfaces/schema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validationSchema.js","sourceRoot":"","sources":["../../src/interfaces/validationSchema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BufferValidationRule = void 0;
|
|
4
|
+
class BufferValidationRule {
|
|
5
|
+
getName() {
|
|
6
|
+
return 'buffer';
|
|
7
|
+
}
|
|
8
|
+
getMessage() {
|
|
9
|
+
return "The '{field}' field must be an Buffer object!";
|
|
10
|
+
}
|
|
11
|
+
getRule(validator) {
|
|
12
|
+
/**
|
|
13
|
+
* Signature: function(value, field, parent, errors, context)
|
|
14
|
+
*/
|
|
15
|
+
return ({ messages }) => {
|
|
16
|
+
const source = `
|
|
17
|
+
if (!value || !(Buffer.isBuffer(value) || value.type === 'Buffer')) {
|
|
18
|
+
${validator.makeError({ type: 'buffer', actual: 'value', messages })}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return value;
|
|
23
|
+
`;
|
|
24
|
+
return {
|
|
25
|
+
source,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.BufferValidationRule = BufferValidationRule;
|
|
31
|
+
//# sourceMappingURL=buffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../../src/rules/buffer.ts"],"names":[],"mappings":";;;AAIA,MAAa,oBAAoB;IAC7B,OAAO;QACH,OAAO,QAAQ,CAAA;IACnB,CAAC;IAED,UAAU;QACN,OAAO,+CAA+C,CAAA;IAC1D,CAAC;IAED,OAAO,CAAC,SAAkB;QACtB;;WAEG;QACH,OAAO,CAAC,EAAE,QAAQ,EAA8B,EAAsB,EAAE;YACpE,MAAM,MAAM,GAAG;;sBAEL,SAAS,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;;;;;aAK3E,CAAA;YAED,OAAO;gBACH,MAAM;aACT,CAAA;QACL,CAAC,CAAA;IACL,CAAC;CACJ;AA5BD,oDA4BC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateValidationRule = void 0;
|
|
4
|
+
class DateValidationRule {
|
|
5
|
+
checkPattern;
|
|
6
|
+
constructor(checkPattern = /(?:\d{2}\.){2}\d{4}/) {
|
|
7
|
+
this.checkPattern = checkPattern;
|
|
8
|
+
}
|
|
9
|
+
getName() {
|
|
10
|
+
return 'customDate';
|
|
11
|
+
}
|
|
12
|
+
getMessage() {
|
|
13
|
+
return "The '{field}' field must be a valid date string format (DD.MM.YYYY)!";
|
|
14
|
+
}
|
|
15
|
+
getRule(validator) {
|
|
16
|
+
/**
|
|
17
|
+
* Signature: function(value, field, parent, errors, context)
|
|
18
|
+
*/
|
|
19
|
+
return ({ schema, messages }) => {
|
|
20
|
+
let sanitized = false;
|
|
21
|
+
const src = [
|
|
22
|
+
`
|
|
23
|
+
if (typeof value !== 'string' || !${this.checkPattern.toString()}.test(value)) {
|
|
24
|
+
${validator.makeError({ type: 'customDate', actual: 'value', messages })}
|
|
25
|
+
}
|
|
26
|
+
`,
|
|
27
|
+
];
|
|
28
|
+
if (schema.convert === true) {
|
|
29
|
+
sanitized = true;
|
|
30
|
+
src.push(`
|
|
31
|
+
var origValue = value;
|
|
32
|
+
if (!(value instanceof Date)) {
|
|
33
|
+
var parts = origValue.split('.');
|
|
34
|
+
value = new Date(Date.UTC(parts[2], parts[1] - 1, parts[0]));
|
|
35
|
+
if (isNaN(value)) {
|
|
36
|
+
${validator.makeError({ type: 'customDate', actual: 'origValue', messages })}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
`);
|
|
40
|
+
}
|
|
41
|
+
src.push('return value;');
|
|
42
|
+
return {
|
|
43
|
+
sanitized,
|
|
44
|
+
source: src.join('\n'),
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.DateValidationRule = DateValidationRule;
|
|
50
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/rules/date.ts"],"names":[],"mappings":";;;AAIA,MAAa,kBAAkB;IACE;IAA7B,YAA6B,eAAe,qBAAqB;QAApC,iBAAY,GAAZ,YAAY,CAAwB;IAAG,CAAC;IAErE,OAAO;QACH,OAAO,YAAY,CAAA;IACvB,CAAC;IAED,UAAU;QACN,OAAO,sEAAsE,CAAA;IACjF,CAAC;IAED,OAAO,CAAC,SAAkB;QACtB;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAA0C,EAAE;YACpE,IAAI,SAAS,GAAG,KAAK,CAAA;YACrB,MAAM,GAAG,GAAa;gBAClB;oDACoC,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE;sBAC1D,SAAS,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;;aAE/E;aACA,CAAA;YAED,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;gBAC1B,SAAS,GAAG,IAAI,CAAA;gBAChB,GAAG,CAAC,IAAI,CAAC;;;;;;8BAMK,SAAS,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;;;iBAGvF,CAAC,CAAA;YACN,CAAC;YAED,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;YAEzB,OAAO;gBACH,SAAS;gBACT,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;aACzB,CAAA;QACL,CAAC,CAAA;IACL,CAAC;CACJ;AA/CD,gDA+CC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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("./buffer"), exports);
|
|
18
|
+
__exportStar(require("./date"), exports);
|
|
19
|
+
__exportStar(require("./objectId"), exports);
|
|
20
|
+
__exportStar(require("./phoneNumber"), exports);
|
|
21
|
+
__exportStar(require("./version"), exports);
|
|
22
|
+
__exportStar(require("./internationalPhoneNumber"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AAExB,yCAAsB;AAEtB,6CAA0B;AAE1B,gDAA6B;AAE7B,4CAAyB;AAEzB,6DAA0C"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InternationalPhoneNumberValidationRule = void 0;
|
|
4
|
+
class InternationalPhoneNumberValidationRule {
|
|
5
|
+
checkPattern = /^\+?\d{1,4}?[\s.-]?\(?\d{1,3}?\)?(?:[\s.-]?\d{1,4}){2}[\s.-]?\d{1,9}$/g;
|
|
6
|
+
getName() {
|
|
7
|
+
return 'internationalPhoneNumber';
|
|
8
|
+
}
|
|
9
|
+
getMessage() {
|
|
10
|
+
return "The '{field}' field must be a string and valid international phone number!";
|
|
11
|
+
}
|
|
12
|
+
getRule(validator) {
|
|
13
|
+
/**
|
|
14
|
+
* Signature: function(value, field, parent, errors, context)
|
|
15
|
+
*/
|
|
16
|
+
return ({ messages }) => {
|
|
17
|
+
const source = `
|
|
18
|
+
if (typeof value !== 'string' || !${this.checkPattern.toString()}.test(value)) {
|
|
19
|
+
${validator.makeError({ type: 'internationalPhoneNumber', actual: 'value', messages })}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return value;
|
|
23
|
+
`;
|
|
24
|
+
return {
|
|
25
|
+
source,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.InternationalPhoneNumberValidationRule = InternationalPhoneNumberValidationRule;
|
|
31
|
+
//# sourceMappingURL=internationalPhoneNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internationalPhoneNumber.js","sourceRoot":"","sources":["../../src/rules/internationalPhoneNumber.ts"],"names":[],"mappings":";;;AAIA,MAAa,sCAAsC;IACvC,YAAY,GAAG,wEAAwE,CAAA;IAE/F,OAAO;QACH,OAAO,0BAA0B,CAAA;IACrC,CAAC;IAED,UAAU;QACN,OAAO,4EAA4E,CAAA;IACvF,CAAC;IAED,OAAO,CAAC,SAAkB;QACtB;;WAEG;QACH,OAAO,CAAC,EAAE,QAAQ,EAAE,EAAsB,EAAE;YACxC,MAAM,MAAM,GAAG;oDACyB,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE;sBAC1D,SAAS,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,0BAA0B,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;;;;aAI7F,CAAA;YAED,OAAO;gBACH,MAAM;aACT,CAAA;QACL,CAAC,CAAA;IACL,CAAC;CACJ;AA7BD,wFA6BC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObjectIdValidationRule = void 0;
|
|
4
|
+
const PATTERN = /^[\da-f]{24}$/i;
|
|
5
|
+
class ObjectIdValidationRule {
|
|
6
|
+
getName() {
|
|
7
|
+
return 'objectId';
|
|
8
|
+
}
|
|
9
|
+
getMessage() {
|
|
10
|
+
return "The '{field}' field must be an objectId string!";
|
|
11
|
+
}
|
|
12
|
+
getRule(validator) {
|
|
13
|
+
/**
|
|
14
|
+
* Signature: function(value, field, parent, errors, context)
|
|
15
|
+
*/
|
|
16
|
+
return ({ messages }) => {
|
|
17
|
+
const source = `
|
|
18
|
+
if (typeof value !== 'string' || !${PATTERN.toString()}.test(value)) {
|
|
19
|
+
${validator.makeError({ type: 'objectId', actual: 'value', messages })}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return value;
|
|
23
|
+
`;
|
|
24
|
+
return {
|
|
25
|
+
source,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ObjectIdValidationRule = ObjectIdValidationRule;
|
|
31
|
+
//# sourceMappingURL=objectId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectId.js","sourceRoot":"","sources":["../../src/rules/objectId.ts"],"names":[],"mappings":";;;AAIA,MAAM,OAAO,GAAG,gBAAgB,CAAA;AAEhC,MAAa,sBAAsB;IAC/B,OAAO;QACH,OAAO,UAAU,CAAA;IACrB,CAAC;IAED,UAAU;QACN,OAAO,iDAAiD,CAAA;IAC5D,CAAC;IAED,OAAO,CAAC,SAAkB;QACtB;;WAEG;QACH,OAAO,CAAC,EAAE,QAAQ,EAA8B,EAAsB,EAAE;YACpE,MAAM,MAAM,GAAG;oDACyB,OAAO,CAAC,QAAQ,EAAE;sBAChD,SAAS,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;;;;aAI7E,CAAA;YAED,OAAO;gBACH,MAAM;aACT,CAAA;QACL,CAAC,CAAA;IACL,CAAC;CACJ;AA3BD,wDA2BC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PhoneNumberValidationRule = void 0;
|
|
4
|
+
const schemas_1 = require("../schemas");
|
|
5
|
+
class PhoneNumberValidationRule {
|
|
6
|
+
checkPattern;
|
|
7
|
+
constructor() {
|
|
8
|
+
this.checkPattern = new RegExp(`^38(${schemas_1.availableMobileCodes.map((code) => `0${code}`).join('|')})\\d{7}$`);
|
|
9
|
+
}
|
|
10
|
+
getName() {
|
|
11
|
+
return 'phoneNumber';
|
|
12
|
+
}
|
|
13
|
+
getMessage() {
|
|
14
|
+
return "The '{field}' field must be a string and valid phone number. E.g. 380xxxxxxx!";
|
|
15
|
+
}
|
|
16
|
+
getRule(validator) {
|
|
17
|
+
/**
|
|
18
|
+
* Signature: function(value, field, parent, errors, context)
|
|
19
|
+
*/
|
|
20
|
+
return ({ messages }) => {
|
|
21
|
+
const source = `
|
|
22
|
+
if (typeof value !== 'string' || !${this.checkPattern.toString()}.test(value)) {
|
|
23
|
+
${validator.makeError({ type: 'phoneNumber', actual: 'value', messages })}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return value;
|
|
27
|
+
`;
|
|
28
|
+
return {
|
|
29
|
+
source,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.PhoneNumberValidationRule = PhoneNumberValidationRule;
|
|
35
|
+
//# sourceMappingURL=phoneNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phoneNumber.js","sourceRoot":"","sources":["../../src/rules/phoneNumber.ts"],"names":[],"mappings":";;;AAGA,wCAAiD;AAEjD,MAAa,yBAAyB;IAC1B,YAAY,CAAQ;IAE5B;QACI,IAAI,CAAC,YAAY,GAAG,IAAI,MAAM,CAAC,OAAO,8BAAoB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IAC7G,CAAC;IAED,OAAO;QACH,OAAO,aAAa,CAAA;IACxB,CAAC;IAED,UAAU;QACN,OAAO,+EAA+E,CAAA;IAC1F,CAAC;IAED,OAAO,CAAC,SAAkB;QACtB;;WAEG;QACH,OAAO,CAAC,EAAE,QAAQ,EAAE,EAAsB,EAAE;YACxC,MAAM,MAAM,GAAG;oDACyB,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE;sBAC1D,SAAS,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;;;;aAIhF,CAAA;YAED,OAAO;gBACH,MAAM;aACT,CAAA;QACL,CAAC,CAAA;IACL,CAAC;CACJ;AAjCD,8DAiCC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VersionValidationRule = void 0;
|
|
4
|
+
const PATTERN = /^v\d+$/;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated
|
|
7
|
+
*/
|
|
8
|
+
class VersionValidationRule {
|
|
9
|
+
getName() {
|
|
10
|
+
return 'version';
|
|
11
|
+
}
|
|
12
|
+
getMessage() {
|
|
13
|
+
return "The '{field}' field must be a valid version provided. E.g. v1";
|
|
14
|
+
}
|
|
15
|
+
getRule(validator) {
|
|
16
|
+
/**
|
|
17
|
+
* Signature: function(value, field, parent, errors, context)
|
|
18
|
+
*/
|
|
19
|
+
return ({ schema, messages }) => {
|
|
20
|
+
const src = [];
|
|
21
|
+
src.push(`
|
|
22
|
+
if (typeof value !== 'string') {
|
|
23
|
+
${validator.makeError({ type: 'string', actual: 'value', messages })}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
`);
|
|
27
|
+
if (Array.isArray(schema.versions) && schema.versions.length > 0) {
|
|
28
|
+
const { versions } = schema;
|
|
29
|
+
src.push(`
|
|
30
|
+
if (!${JSON.stringify(versions)}.includes(value)) {
|
|
31
|
+
${validator.makeError({ type: 'version', expected: `'${versions.join(', ')}'`, actual: 'value', messages })}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
`);
|
|
35
|
+
}
|
|
36
|
+
src.push(`
|
|
37
|
+
if (!${PATTERN.toString()}.test(value)) {
|
|
38
|
+
${validator.makeError({ type: 'version', actual: 'value', messages })}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return value;
|
|
42
|
+
`);
|
|
43
|
+
return {
|
|
44
|
+
source: src.join('\n'),
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.VersionValidationRule = VersionValidationRule;
|
|
50
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/rules/version.ts"],"names":[],"mappings":";;;AAIA,MAAM,OAAO,GAAG,QAAQ,CAAA;AAExB;;GAEG;AACH,MAAa,qBAAqB;IAC9B,OAAO;QACH,OAAO,SAAS,CAAA;IACpB,CAAC;IAED,UAAU;QACN,OAAO,+DAA+D,CAAA;IAC1E,CAAC;IAED,OAAO,CAAC,SAAkB;QACtB;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAwD,EAAsB,EAAE;YACtG,MAAM,GAAG,GAAa,EAAE,CAAA;YAExB,GAAG,CAAC,IAAI,CAAC;;sBAEC,SAAS,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;;;aAG3E,CAAC,CAAA;YAEF,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC/D,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;gBAE3B,GAAG,CAAC,IAAI,CAAC;2BACE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;0BACzB,SAAS,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;;;iBAGlH,CAAC,CAAA;YACN,CAAC;YAED,GAAG,CAAC,IAAI,CAAC;uBACE,OAAO,CAAC,QAAQ,EAAE;sBACnB,SAAS,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;;;;aAI5E,CAAC,CAAA;YAEF,OAAO;gBACH,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;aACzB,CAAA;QACL,CAAC,CAAA;IACL,CAAC;CACJ;AA/CD,sDA+CC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.appVersionsValidationSchema = exports.getListValidationSchema = exports.listValidationSchema = exports.zipValidation = exports.shortTextValidation = exports.emailRuValidation = exports.emailValidation = exports.phoneNumberValidation = exports.availableMobileCodes = void 0;
|
|
7
|
+
const lodash_frompairs_1 = __importDefault(require("lodash.frompairs"));
|
|
8
|
+
const types_1 = require("@diia-inhouse/types");
|
|
9
|
+
exports.availableMobileCodes = [
|
|
10
|
+
'39',
|
|
11
|
+
'50',
|
|
12
|
+
'63',
|
|
13
|
+
'66',
|
|
14
|
+
'67',
|
|
15
|
+
'68',
|
|
16
|
+
'73',
|
|
17
|
+
'91',
|
|
18
|
+
'92',
|
|
19
|
+
'93',
|
|
20
|
+
'94',
|
|
21
|
+
'95',
|
|
22
|
+
'96',
|
|
23
|
+
'97',
|
|
24
|
+
'98',
|
|
25
|
+
'99',
|
|
26
|
+
];
|
|
27
|
+
exports.phoneNumberValidation = {
|
|
28
|
+
regexp: `^\\+380(${exports.availableMobileCodes.join('|')})\\d{7}$`,
|
|
29
|
+
flags: ['i', 'g'],
|
|
30
|
+
errorMessage: 'Упс, ви ввели неправильний номер телефону. Використовуйте формат + 38 (0ХХ) ХХХ ХХ ХХ.',
|
|
31
|
+
};
|
|
32
|
+
exports.emailValidation = {
|
|
33
|
+
regexp: '^([a-zA-Z0-9_%+-]{1,}.{0,1}){0,}[a-zA-Z0-9_%+-]{1,}@([a-zA-Z0-9_%+-]{1,}.{0,1}){1,}[A-Za-z]{2,64}$',
|
|
34
|
+
flags: ['i'],
|
|
35
|
+
errorMessage: 'Упс, ви ввели неправильний email. Виправте дані або спробуйте іншу пошту.',
|
|
36
|
+
};
|
|
37
|
+
exports.emailRuValidation = {
|
|
38
|
+
regexp: '^([a-zA-Z0-9_%+-]{1,}.{0,1}){0,}[a-zA-Z0-9_%+-]{1,}@([a-zA-Z0-9_%+-]{1,}.{0,1}){1,}(?!ru|su)[A-Za-z]{2,64}$',
|
|
39
|
+
flags: ['i'],
|
|
40
|
+
errorMessage: 'Йой, це ж електронна адреса з російським доменом. Ми не можемо її прийняти. Спробуйте іншу скриньку, будь ласка.',
|
|
41
|
+
};
|
|
42
|
+
exports.shortTextValidation = {
|
|
43
|
+
regexp: String.raw `^([a-z]|[а-яґєії]|\d|-|—|/|\s){1,10}$`,
|
|
44
|
+
flags: ['i'],
|
|
45
|
+
errorMessage: 'Введіть номер до 10 знаків, не використовуйте спецсимволи, окрім «-, /»',
|
|
46
|
+
};
|
|
47
|
+
exports.zipValidation = {
|
|
48
|
+
regexp: String.raw `^\d{5}$`,
|
|
49
|
+
flags: [],
|
|
50
|
+
errorMessage: 'Введіть індекс з 5 цифр',
|
|
51
|
+
};
|
|
52
|
+
/** @deprecated use getListValidationSchema function instead */
|
|
53
|
+
exports.listValidationSchema = {
|
|
54
|
+
skip: { type: 'number', convert: true, min: 0, optional: true },
|
|
55
|
+
limit: { type: 'number', convert: true, min: 0, max: 100, optional: true },
|
|
56
|
+
};
|
|
57
|
+
function getListValidationSchema(min = 0, max = 100) {
|
|
58
|
+
return {
|
|
59
|
+
skip: { type: 'number', convert: true, min, optional: true },
|
|
60
|
+
limit: { type: 'number', convert: true, min, max, optional: true },
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.getListValidationSchema = getListValidationSchema;
|
|
64
|
+
exports.appVersionsValidationSchema = {
|
|
65
|
+
type: 'object',
|
|
66
|
+
props: {
|
|
67
|
+
versions: {
|
|
68
|
+
type: 'object',
|
|
69
|
+
optional: true,
|
|
70
|
+
props: (0, lodash_frompairs_1.default)(Object.values(types_1.PlatformType).map((platformType) => [
|
|
71
|
+
platformType,
|
|
72
|
+
{ type: 'array', items: { type: 'string' }, optional: true },
|
|
73
|
+
])),
|
|
74
|
+
},
|
|
75
|
+
minVersion: {
|
|
76
|
+
type: 'object',
|
|
77
|
+
optional: true,
|
|
78
|
+
props: (0, lodash_frompairs_1.default)(Object.values(types_1.PlatformType).map((platformType) => [platformType, { type: 'string', optional: true }])),
|
|
79
|
+
},
|
|
80
|
+
maxVersion: {
|
|
81
|
+
type: 'object',
|
|
82
|
+
optional: true,
|
|
83
|
+
props: (0, lodash_frompairs_1.default)(Object.values(types_1.PlatformType).map((platformType) => [platformType, { type: 'string', optional: true }])),
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
optional: true,
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":";;;;;;AAAA,wEAAwC;AAExC,+CAA+D;AAKlD,QAAA,oBAAoB,GAAa;IAC1C,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;CACP,CAAA;AAEY,QAAA,qBAAqB,GAAwB;IACtD,MAAM,EAAE,WAAW,4BAAoB,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU;IAC3D,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IACjB,YAAY,EAAE,wFAAwF;CACzG,CAAA;AAEY,QAAA,eAAe,GAAwB;IAChD,MAAM,EAAE,oGAAoG;IAC5G,KAAK,EAAE,CAAC,GAAG,CAAC;IACZ,YAAY,EAAE,2EAA2E;CAC5F,CAAA;AAEY,QAAA,iBAAiB,GAAwB;IAClD,MAAM,EAAE,6GAA6G;IACrH,KAAK,EAAE,CAAC,GAAG,CAAC;IACZ,YAAY,EAAE,kHAAkH;CACnI,CAAA;AAEY,QAAA,mBAAmB,GAAwB;IACpD,MAAM,EAAE,MAAM,CAAC,GAAG,CAAA,uCAAuC;IACzD,KAAK,EAAE,CAAC,GAAG,CAAC;IACZ,YAAY,EAAE,yEAAyE;CAC1F,CAAA;AAEY,QAAA,aAAa,GAAwB;IAC9C,MAAM,EAAE,MAAM,CAAC,GAAG,CAAA,SAAS;IAC3B,KAAK,EAAE,EAAE;IACT,YAAY,EAAE,yBAAyB;CAC1C,CAAA;AAED,+DAA+D;AAClD,QAAA,oBAAoB,GAAyB;IACtD,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC/D,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE;CAC7E,CAAA;AAED,SAAgB,uBAAuB,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG;IACtD,OAAO;QACH,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC5D,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE;KACrE,CAAA;AACL,CAAC;AALD,0DAKC;AAEY,QAAA,2BAA2B,GAA4B;IAChE,IAAI,EAAE,QAAQ;IACd,KAAK,EAAE;QACH,QAAQ,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,KAAK,EAAE,IAAA,0BAAS,EACZ,MAAM,CAAC,MAAM,CAAC,oBAAY,CAAC,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC;gBAC9C,YAAY;gBACZ,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;aAC/D,CAAC,CACL;SACJ;QACD,UAAU,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,KAAK,EAAE,IAAA,0BAAS,EAAC,MAAM,CAAC,MAAM,CAAC,oBAAY,CAAC,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;SAC1H;QACD,UAAU,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,KAAK,EAAE,IAAA,0BAAS,EAAC,MAAM,CAAC,MAAM,CAAC,oBAAY,CAAC,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;SAC1H;KACJ;IACD,QAAQ,EAAE,IAAI;CACjB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Fastest, { MessagesType, ValidationSchema } from 'fastest-validator';
|
|
2
|
+
export type RuleValidator = (param: {
|
|
3
|
+
messages: MessagesType;
|
|
4
|
+
schema: ValidationSchema;
|
|
5
|
+
}) => {
|
|
6
|
+
source: string;
|
|
7
|
+
sanitized?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export interface Rule {
|
|
10
|
+
getName(): string;
|
|
11
|
+
getMessage(): string;
|
|
12
|
+
getRule(validator: Fastest): RuleValidator;
|
|
13
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ObjectId } from 'bson';
|
|
3
|
+
export type RuleType = 'any' | 'boolean' | 'number' | 'email' | 'object' | 'string' | 'enum' | 'uuid' | 'array' | 'forbidden' | 'function' | 'date' | 'customDate' | 'objectId' | 'version' | 'phoneNumber' | 'internationalPhoneNumber' | 'buffer' | 'record';
|
|
4
|
+
interface BasicRule<T extends RuleType> {
|
|
5
|
+
type: T;
|
|
6
|
+
optional?: boolean;
|
|
7
|
+
default?: unknown;
|
|
8
|
+
null?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface Sanitazible {
|
|
11
|
+
convert?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface NumberRule extends BasicRule<'number'>, Sanitazible {
|
|
14
|
+
min?: number;
|
|
15
|
+
max?: number;
|
|
16
|
+
equal?: number;
|
|
17
|
+
notEqual?: number;
|
|
18
|
+
integer?: boolean;
|
|
19
|
+
positive?: boolean;
|
|
20
|
+
negative?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface ArrayRule<T = null> extends BasicRule<'array'> {
|
|
23
|
+
items?: ValidationProperty<T>;
|
|
24
|
+
empty?: boolean;
|
|
25
|
+
min?: number;
|
|
26
|
+
max?: number;
|
|
27
|
+
length?: number;
|
|
28
|
+
contains?: any;
|
|
29
|
+
enum?: any[];
|
|
30
|
+
unique?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface ObjectRule<T = null> extends BasicRule<'object'> {
|
|
33
|
+
props?: ValidationSchema<T>;
|
|
34
|
+
strict?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface RecordRule<K, V> extends BasicRule<'record'> {
|
|
37
|
+
key: EnumRule<K>;
|
|
38
|
+
value: ValidationProperty<V> | ValidationProperty<V>[];
|
|
39
|
+
}
|
|
40
|
+
export interface StringRule extends BasicRule<'string'> {
|
|
41
|
+
empty?: boolean;
|
|
42
|
+
min?: number;
|
|
43
|
+
max?: number;
|
|
44
|
+
length?: number;
|
|
45
|
+
pattern?: any;
|
|
46
|
+
contains?: any;
|
|
47
|
+
enum?: string[];
|
|
48
|
+
alpha?: boolean;
|
|
49
|
+
numeric?: boolean;
|
|
50
|
+
alphanum?: boolean;
|
|
51
|
+
alphadash?: boolean;
|
|
52
|
+
uppercase?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface EmailRule extends BasicRule<'email'> {
|
|
55
|
+
mode?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface VersionRule extends BasicRule<'version'>, Sanitazible {
|
|
58
|
+
versions?: string[];
|
|
59
|
+
}
|
|
60
|
+
export interface EnumRule<T = any> extends BasicRule<'enum'> {
|
|
61
|
+
values: T[];
|
|
62
|
+
}
|
|
63
|
+
export interface DateRule extends BasicRule<'date'>, Sanitazible {
|
|
64
|
+
format?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface ListValidationSchema {
|
|
67
|
+
skip: NumberRule;
|
|
68
|
+
limit: NumberRule;
|
|
69
|
+
}
|
|
70
|
+
export interface CustomDateRule extends BasicRule<'customDate'>, Sanitazible {
|
|
71
|
+
}
|
|
72
|
+
export interface ObjectIdRule extends BasicRule<'objectId'>, Sanitazible {
|
|
73
|
+
}
|
|
74
|
+
export interface BooleanRule extends BasicRule<'boolean'>, Sanitazible {
|
|
75
|
+
}
|
|
76
|
+
type CommonRule = BasicRule<'any' | 'forbidden'> | EnumRule;
|
|
77
|
+
type ComplexRule = StringRule | NumberRule | BooleanRule | ArrayRule | ObjectRule | DateRule | CustomDateRule | EmailRule | EnumRule | ObjectIdRule | RecordRule<string, unknown> | VersionRule;
|
|
78
|
+
type ValidationProperty<T = null> = T extends null ? ValidationRule : T extends string ? StringRule | EmailRule | VersionRule | BasicRule<'uuid' | 'phoneNumber' | 'internationalPhoneNumber'> : T extends number ? NumberRule : T extends boolean ? BooleanRule : T extends Date ? DateRule | CustomDateRule | StringRule : T extends Buffer ? BasicRule<'buffer'> : T extends ObjectId ? ObjectIdRule | StringRule : T extends ArrayLike<infer U> ? ArrayRule<U> : T extends object ? ObjectRule<T> | RecordRule<keyof T, Required<T>[keyof T]> : ValidationRule;
|
|
79
|
+
type Rule = string | boolean | ComplexRule | CommonRule | BasicRule<Exclude<RuleType, CommonRule['type'] | ComplexRule['type']>>;
|
|
80
|
+
export type ValidationRule<T = null> = T extends null ? Rule : T extends object ? ObjectRule<T> : T extends ArrayLike<infer U> ? ArrayRule<U> : Rule;
|
|
81
|
+
export type ValidationSchema<T = null> = T extends null ? {
|
|
82
|
+
[path: string]: ValidationRule | ValidationRule[];
|
|
83
|
+
} : {
|
|
84
|
+
[path in keyof Required<T>]: ValidationProperty<T[path]> | ValidationProperty<T[path]>[] | CommonRule;
|
|
85
|
+
};
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Fastest from 'fastest-validator';
|
|
2
|
+
import { Rule, RuleValidator } from '../interfaces/rule';
|
|
3
|
+
export declare class DateValidationRule implements Rule {
|
|
4
|
+
private readonly checkPattern;
|
|
5
|
+
constructor(checkPattern?: RegExp);
|
|
6
|
+
getName(): string;
|
|
7
|
+
getMessage(): string;
|
|
8
|
+
getRule(validator: Fastest): RuleValidator;
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import Fastest from 'fastest-validator';
|
|
2
|
+
import { Rule, RuleValidator } from '../interfaces/rule';
|
|
3
|
+
export declare class InternationalPhoneNumberValidationRule implements Rule {
|
|
4
|
+
private checkPattern;
|
|
5
|
+
getName(): string;
|
|
6
|
+
getMessage(): string;
|
|
7
|
+
getRule(validator: Fastest): RuleValidator;
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Fastest from 'fastest-validator';
|
|
2
|
+
import { Rule, RuleValidator } from '../interfaces/rule';
|
|
3
|
+
export declare class PhoneNumberValidationRule implements Rule {
|
|
4
|
+
private checkPattern;
|
|
5
|
+
constructor();
|
|
6
|
+
getName(): string;
|
|
7
|
+
getMessage(): string;
|
|
8
|
+
getRule(validator: Fastest): RuleValidator;
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Fastest from 'fastest-validator';
|
|
2
|
+
import { Rule, RuleValidator } from '../interfaces/rule';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated
|
|
5
|
+
*/
|
|
6
|
+
export declare class VersionValidationRule implements Rule {
|
|
7
|
+
getName(): string;
|
|
8
|
+
getMessage(): string;
|
|
9
|
+
getRule(validator: Fastest): RuleValidator;
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AppVersions } from '@diia-inhouse/types';
|
|
2
|
+
import { ListValidationSchema, ObjectRule } from '../interfaces';
|
|
3
|
+
import { ParameterValidation } from '../interfaces/schema';
|
|
4
|
+
export declare const availableMobileCodes: string[];
|
|
5
|
+
export declare const phoneNumberValidation: ParameterValidation;
|
|
6
|
+
export declare const emailValidation: ParameterValidation;
|
|
7
|
+
export declare const emailRuValidation: ParameterValidation;
|
|
8
|
+
export declare const shortTextValidation: ParameterValidation;
|
|
9
|
+
export declare const zipValidation: ParameterValidation;
|
|
10
|
+
/** @deprecated use getListValidationSchema function instead */
|
|
11
|
+
export declare const listValidationSchema: ListValidationSchema;
|
|
12
|
+
export declare function getListValidationSchema(min?: number, max?: number): ListValidationSchema;
|
|
13
|
+
export declare const appVersionsValidationSchema: ObjectRule<AppVersions>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ValidationSchema } from 'fastest-validator';
|
|
2
|
+
export declare class AppValidator {
|
|
3
|
+
private readonly validator;
|
|
4
|
+
private customRules;
|
|
5
|
+
constructor();
|
|
6
|
+
compile(schema: ValidationSchema): (params: unknown) => boolean;
|
|
7
|
+
validate(params: unknown, schema: ValidationSchema): boolean;
|
|
8
|
+
private getCustomValidatorsMessages;
|
|
9
|
+
private addCustomValidationRules;
|
|
10
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AppValidator = void 0;
|
|
7
|
+
const fastest_validator_1 = __importDefault(require("fastest-validator"));
|
|
8
|
+
const errors_1 = require("@diia-inhouse/errors");
|
|
9
|
+
const rules_1 = require("./rules");
|
|
10
|
+
const internationalPhoneNumber_1 = require("./rules/internationalPhoneNumber");
|
|
11
|
+
class AppValidator {
|
|
12
|
+
validator;
|
|
13
|
+
customRules;
|
|
14
|
+
constructor() {
|
|
15
|
+
this.customRules = [
|
|
16
|
+
new rules_1.BufferValidationRule(),
|
|
17
|
+
new rules_1.DateValidationRule(),
|
|
18
|
+
new rules_1.ObjectIdValidationRule(),
|
|
19
|
+
new rules_1.PhoneNumberValidationRule(),
|
|
20
|
+
new internationalPhoneNumber_1.InternationalPhoneNumberValidationRule(),
|
|
21
|
+
new rules_1.VersionValidationRule(),
|
|
22
|
+
];
|
|
23
|
+
this.validator = new fastest_validator_1.default({ messages: this.getCustomValidatorsMessages() });
|
|
24
|
+
this.addCustomValidationRules();
|
|
25
|
+
}
|
|
26
|
+
compile(schema) {
|
|
27
|
+
return (params) => this.validate(params, schema);
|
|
28
|
+
}
|
|
29
|
+
validate(params, schema) {
|
|
30
|
+
const res = this.validator.validate(params, schema);
|
|
31
|
+
if (res !== true) {
|
|
32
|
+
throw new errors_1.ValidationError(res, errors_1.ErrorCode.ValidationError);
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
getCustomValidatorsMessages() {
|
|
37
|
+
const res = {};
|
|
38
|
+
for (const rule of this.customRules) {
|
|
39
|
+
res[rule.getName()] = rule.getMessage();
|
|
40
|
+
}
|
|
41
|
+
return res;
|
|
42
|
+
}
|
|
43
|
+
addCustomValidationRules() {
|
|
44
|
+
for (const rule of this.customRules) {
|
|
45
|
+
this.validator.add(rule.getName(), rule.getRule(this.validator));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.AppValidator = AppValidator;
|
|
50
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":";;;;;;AAAA,0EAAsE;AAEtE,iDAAuF;AAGvF,mCAA4I;AAC5I,+EAAyF;AAEzF,MAAa,YAAY;IACJ,SAAS,CAAkB;IAEpC,WAAW,CAAQ;IAE3B;QACI,IAAI,CAAC,WAAW,GAAG;YACf,IAAI,4BAAoB,EAAE;YAC1B,IAAI,0BAAkB,EAAE;YACxB,IAAI,8BAAsB,EAAE;YAC5B,IAAI,iCAAyB,EAAE;YAC/B,IAAI,iEAAsC,EAAE;YAC5C,IAAI,6BAAqB,EAAE;SAC9B,CAAA;QAED,IAAI,CAAC,SAAS,GAAG,IAAI,2BAAgB,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAA;QAEvF,IAAI,CAAC,wBAAwB,EAAE,CAAA;IACnC,CAAC;IAED,OAAO,CAAC,MAAwB;QAC5B,OAAO,CAAC,MAAe,EAAW,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACtE,CAAC;IAED,QAAQ,CAAC,MAAe,EAAE,MAAwB;QAC9C,MAAM,GAAG,GAAkC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAA0B,MAAM,EAAE,MAAM,CAAC,CAAA;QAE3G,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACf,MAAM,IAAI,wBAAe,CAAC,GAAG,EAAE,kBAAS,CAAC,eAAe,CAAC,CAAA;QAC7D,CAAC;QAED,OAAO,IAAI,CAAA;IACf,CAAC;IAEO,2BAA2B;QAC/B,MAAM,GAAG,GAA2B,EAAE,CAAA;QAEtC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAClC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,CAAA;QAC3C,CAAC;QAED,OAAO,GAAG,CAAA;IACd,CAAC;IAEO,wBAAwB;QAC5B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAClC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAA;QACpE,CAAC;IACL,CAAC;CACJ;AAjDD,oCAiDC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@diia-inhouse/validators",
|
|
3
|
+
"version": "1.17.0",
|
|
4
|
+
"description": "Data validators package",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"repository": "https://github.com/diia-open-source/be-pkg-validators.git",
|
|
8
|
+
"author": "Diia",
|
|
9
|
+
"license": "SEE LICENCE IN LICENCE.md",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"prebuild": "rimraf dist",
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"semantic-release": "semantic-release",
|
|
20
|
+
"start": "npm run build && node dist/index.js",
|
|
21
|
+
"lint": "eslint --ext .ts . && prettier --check .",
|
|
22
|
+
"lint-fix": "eslint '*/**/*.{js,ts}' --fix && prettier --write .",
|
|
23
|
+
"lint:lockfile": "lockfile-lint --path package-lock.json --allowed-hosts registry.npmjs.org --validate-https",
|
|
24
|
+
"prepare": "npm run build",
|
|
25
|
+
"test": "jest",
|
|
26
|
+
"test:unit": "npm run test --selectProjects unit --",
|
|
27
|
+
"test:coverage": "npm run test --selectProjects unit --coverage",
|
|
28
|
+
"find-circulars": "madge --circular ./"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"bson": "6.2.0",
|
|
32
|
+
"fastest-validator": "1.16.0",
|
|
33
|
+
"lodash.frompairs": "4.0.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@diia-inhouse/errors": ">=1.0.0",
|
|
37
|
+
"@diia-inhouse/types": ">=2.5.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@commitlint/cli": "17.5.0",
|
|
41
|
+
"@diia-inhouse/configs": "1.31.1",
|
|
42
|
+
"@diia-inhouse/errors": "1.9.0",
|
|
43
|
+
"@diia-inhouse/eslint-config": "5.1.0",
|
|
44
|
+
"@diia-inhouse/types": "6.24.0",
|
|
45
|
+
"@types/lodash.frompairs": "4.0.9",
|
|
46
|
+
"@types/node": "20.3.1",
|
|
47
|
+
"jest": "29.7.0",
|
|
48
|
+
"jest-junit": "16.0.0",
|
|
49
|
+
"lockfile-lint": "4.10.1",
|
|
50
|
+
"madge": "7.0.0",
|
|
51
|
+
"protobufjs": "7.2.5",
|
|
52
|
+
"rimraf": "5.0.7",
|
|
53
|
+
"semantic-release": "21.1.2"
|
|
54
|
+
},
|
|
55
|
+
"release": {
|
|
56
|
+
"extends": "@diia-inhouse/configs/dist/semantic-release/package",
|
|
57
|
+
"branches": [
|
|
58
|
+
"main"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
"commitlint": {
|
|
62
|
+
"extends": "@diia-inhouse/configs/dist/commitlint"
|
|
63
|
+
},
|
|
64
|
+
"eslintConfig": {
|
|
65
|
+
"extends": "@diia-inhouse/eslint-config",
|
|
66
|
+
"overrides": [
|
|
67
|
+
{
|
|
68
|
+
"files": [
|
|
69
|
+
"*.ts"
|
|
70
|
+
],
|
|
71
|
+
"parserOptions": {
|
|
72
|
+
"project": [
|
|
73
|
+
"./tsconfig.json",
|
|
74
|
+
"./tests/tsconfig.json"
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
"jest": {
|
|
81
|
+
"preset": "@diia-inhouse/configs/dist/jest"
|
|
82
|
+
},
|
|
83
|
+
"prettier": "@diia-inhouse/eslint-config/prettier",
|
|
84
|
+
"madge": {
|
|
85
|
+
"tsConfig": "./tsconfig.json"
|
|
86
|
+
}
|
|
87
|
+
}
|