@newskit-render/validation 1.5.12 → 1.6.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/dist/cjs/__tests__/mocks.d.ts +132 -0
- package/dist/cjs/__tests__/mocks.js +350 -0
- package/dist/cjs/__tests__/mocks.js.map +1 -0
- package/dist/cjs/index.d.ts +2 -163
- package/dist/cjs/index.js +5 -204
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types.d.ts +16 -2
- package/dist/cjs/types.js +18 -18
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils.d.ts +180 -0
- package/dist/cjs/utils.js +115 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/cjs/validation.d.ts +5 -0
- package/dist/cjs/validation.js +25 -0
- package/dist/cjs/validation.js.map +1 -0
- package/dist/cjs/validations/accountInfo.d.ts +77 -0
- package/dist/cjs/validations/accountInfo.js +90 -0
- package/dist/cjs/validations/accountInfo.js.map +1 -0
- package/dist/cjs/validations/address.d.ts +49 -0
- package/dist/cjs/validations/address.js +108 -0
- package/dist/cjs/validations/address.js.map +1 -0
- package/dist/cjs/validations/cancellation.d.ts +15 -0
- package/dist/cjs/validations/cancellation.js +51 -0
- package/dist/cjs/validations/cancellation.js.map +1 -0
- package/dist/cjs/validations/holidayStop.d.ts +17 -0
- package/dist/cjs/validations/holidayStop.js +41 -0
- package/dist/cjs/validations/holidayStop.js.map +1 -0
- package/dist/cjs/validations/index.d.ts +6 -0
- package/dist/cjs/validations/index.js +23 -0
- package/dist/cjs/validations/index.js.map +1 -0
- package/dist/cjs/validations/payment.d.ts +20 -0
- package/dist/cjs/validations/payment.js +40 -0
- package/dist/cjs/validations/payment.js.map +1 -0
- package/dist/cjs/validations/phoneNumber.d.ts +22 -0
- package/dist/cjs/validations/phoneNumber.js +57 -0
- package/dist/cjs/validations/phoneNumber.js.map +1 -0
- package/dist/esm/__tests__/mocks.d.ts +132 -0
- package/dist/esm/__tests__/mocks.js +347 -0
- package/dist/esm/__tests__/mocks.js.map +1 -0
- package/dist/esm/index.d.ts +2 -163
- package/dist/esm/index.js +2 -190
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.d.ts +16 -2
- package/dist/esm/types.js +17 -17
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.d.ts +180 -0
- package/dist/esm/utils.js +87 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/validation.d.ts +5 -0
- package/dist/esm/validation.js +21 -0
- package/dist/esm/validation.js.map +1 -0
- package/dist/esm/validations/accountInfo.d.ts +77 -0
- package/dist/esm/validations/accountInfo.js +60 -0
- package/dist/esm/validations/accountInfo.js.map +1 -0
- package/dist/esm/validations/address.d.ts +49 -0
- package/dist/esm/validations/address.js +80 -0
- package/dist/esm/validations/address.js.map +1 -0
- package/dist/esm/validations/cancellation.d.ts +15 -0
- package/dist/esm/validations/cancellation.js +24 -0
- package/dist/esm/validations/cancellation.js.map +1 -0
- package/dist/esm/validations/holidayStop.d.ts +17 -0
- package/dist/esm/validations/holidayStop.js +15 -0
- package/dist/esm/validations/holidayStop.js.map +1 -0
- package/dist/esm/validations/index.d.ts +6 -0
- package/dist/esm/validations/index.js +7 -0
- package/dist/esm/validations/index.js.map +1 -0
- package/dist/esm/validations/payment.d.ts +20 -0
- package/dist/esm/validations/payment.js +14 -0
- package/dist/esm/validations/payment.js.map +1 -0
- package/dist/esm/validations/phoneNumber.d.ts +22 -0
- package/dist/esm/validations/phoneNumber.js +29 -0
- package/dist/esm/validations/phoneNumber.js.map +1 -0
- package/package.json +1 -1
- package/dist/cjs/__tests__/index.tests.d.ts +0 -1
- package/dist/cjs/__tests__/index.tests.js +0 -666
- package/dist/cjs/__tests__/index.tests.js.map +0 -1
- package/dist/esm/__tests__/index.tests.d.ts +0 -1
- package/dist/esm/__tests__/index.tests.js +0 -638
- package/dist/esm/__tests__/index.tests.js.map +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -21,199 +10,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
21
10
|
if (k2 === undefined) k2 = k;
|
|
22
11
|
o[k2] = m[k];
|
|
23
12
|
}));
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
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);
|
|
35
15
|
};
|
|
36
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
require("yup-phone");
|
|
41
|
-
var getValidation = function (validationField, requiredFields, requiredMessage, formatMesage, regex, isPhone, excludeEmptyString) {
|
|
42
|
-
var validation = yup.string();
|
|
43
|
-
if (requiredFields.includes(validationField)) {
|
|
44
|
-
validation = validation.required(requiredMessage);
|
|
45
|
-
}
|
|
46
|
-
if (isPhone) {
|
|
47
|
-
validation = validation.phone(undefined, true, formatMesage);
|
|
48
|
-
}
|
|
49
|
-
else if (regex) {
|
|
50
|
-
validation = validation.matches(regex, {
|
|
51
|
-
message: formatMesage,
|
|
52
|
-
excludeEmptyString: excludeEmptyString,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
return validation;
|
|
56
|
-
};
|
|
57
|
-
exports.defaultRequiredFields = [
|
|
58
|
-
types_1.ValidationFields.firstName,
|
|
59
|
-
types_1.ValidationFields.lastname,
|
|
60
|
-
types_1.ValidationFields.mobile,
|
|
61
|
-
types_1.ValidationFields.phoneNumber,
|
|
62
|
-
types_1.ValidationFields.country,
|
|
63
|
-
types_1.ValidationFields.line1,
|
|
64
|
-
types_1.ValidationFields.city,
|
|
65
|
-
types_1.ValidationFields.postcode,
|
|
66
|
-
types_1.ValidationFields.other,
|
|
67
|
-
types_1.ValidationFields.cancellationReason,
|
|
68
|
-
];
|
|
69
|
-
var generateDefaultSchema = function (options) {
|
|
70
|
-
var _a, _b;
|
|
71
|
-
var requiredFields = (options === null || options === void 0 ? void 0 : options.overrideRequiredFields) || exports.defaultRequiredFields;
|
|
72
|
-
var DEFAULT_REQUIRED_MESSAGE = 'Please enter your ${field}';
|
|
73
|
-
var DEFAULT_WRONG_FORMAT_MESSAGE = 'Your ${field} can’t contain special characters. Please try again.';
|
|
74
|
-
var includesReuiredTemplate = (_a = options === null || options === void 0 ? void 0 : options.requiredMessage) === null || _a === void 0 ? void 0 : _a.includes('${field}');
|
|
75
|
-
var includesWrongFormatTemplate = (_b = options === null || options === void 0 ? void 0 : options.wrongFormatMessage) === null || _b === void 0 ? void 0 : _b.includes('${field}');
|
|
76
|
-
var requiredMessage = includesReuiredTemplate
|
|
77
|
-
? options === null || options === void 0 ? void 0 : options.requiredMessage
|
|
78
|
-
: DEFAULT_REQUIRED_MESSAGE;
|
|
79
|
-
var wrongFormatMessage = includesWrongFormatTemplate
|
|
80
|
-
? options === null || options === void 0 ? void 0 : options.wrongFormatMessage
|
|
81
|
-
: DEFAULT_WRONG_FORMAT_MESSAGE;
|
|
82
|
-
var nameValidation = yup.object().shape({
|
|
83
|
-
firstName: getValidation(types_1.ValidationFields.firstName, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'First Name'), wrongFormatMessage === null || wrongFormatMessage === void 0 ? void 0 : wrongFormatMessage.replace('${field}', 'first name'), /^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z])*$/),
|
|
84
|
-
lastName: getValidation(types_1.ValidationFields.lastname, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'Last Name'), wrongFormatMessage === null || wrongFormatMessage === void 0 ? void 0 : wrongFormatMessage.replace('${field}', 'last name'), /^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z])*$/),
|
|
85
|
-
});
|
|
86
|
-
var displayNameValidation = yup.object().shape({
|
|
87
|
-
displayName: yup
|
|
88
|
-
.string() //Please enter your Display name'
|
|
89
|
-
.required(requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'Display Name')),
|
|
90
|
-
});
|
|
91
|
-
var passwordValidation = yup.object({
|
|
92
|
-
password: yup.string(),
|
|
93
|
-
});
|
|
94
|
-
var phoneMessage = 'That doesn’t look like a valid phone number. Please try again.';
|
|
95
|
-
var mobileValidation = yup.object({
|
|
96
|
-
mobile: getValidation(types_1.ValidationFields.mobile, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'mobile telephone number'), phoneMessage, undefined, true),
|
|
97
|
-
});
|
|
98
|
-
var phoneNumberValidation = yup.object({
|
|
99
|
-
phoneNumber: getValidation(types_1.ValidationFields.phoneNumber, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'landline telephone number'), phoneMessage, undefined, true),
|
|
100
|
-
});
|
|
101
|
-
//Payment cannot be not required
|
|
102
|
-
var paymentMethodIdValidation = yup.object({
|
|
103
|
-
paymentMethodId: yup.string().required(),
|
|
104
|
-
});
|
|
105
|
-
var zuoraPaymentMethodValidation = yup.object({
|
|
106
|
-
refId: yup.string().required(),
|
|
107
|
-
responseSignature: yup.string().required(),
|
|
108
|
-
token: yup.string().required(),
|
|
109
|
-
id: yup.string().required(),
|
|
110
|
-
timestamp: yup.number().required(),
|
|
111
|
-
tenantId: yup.number().required(),
|
|
112
|
-
});
|
|
113
|
-
//Email cannot be not required
|
|
114
|
-
var emailValidation = yup.object({
|
|
115
|
-
email: yup
|
|
116
|
-
.string()
|
|
117
|
-
.required(requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'Email address'))
|
|
118
|
-
.email('That doesn’t look like a valid email address. Please try again.'),
|
|
119
|
-
});
|
|
120
|
-
var commentingNotifications = yup.object({
|
|
121
|
-
likedYourMessage: yup.boolean(),
|
|
122
|
-
userMentioned: yup.boolean(),
|
|
123
|
-
repliedToMessage: yup.boolean(),
|
|
124
|
-
});
|
|
125
|
-
var addressRegex = /^['&#.0-9a-zA-Z\s,-]+$/;
|
|
126
|
-
var addressValidation = yup.object({
|
|
127
|
-
country: getValidation(types_1.ValidationFields.country, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'Country'), 'This is not a valid Country code', /^[A-Z]{2,3}$/),
|
|
128
|
-
line1: getValidation(types_1.ValidationFields.line1, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'first line of your address'), wrongFormatMessage === null || wrongFormatMessage === void 0 ? void 0 : wrongFormatMessage.replace('${field}', 'address'), addressRegex),
|
|
129
|
-
line2: getValidation(types_1.ValidationFields.line2, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'second line of your address'), wrongFormatMessage === null || wrongFormatMessage === void 0 ? void 0 : wrongFormatMessage.replace('${field}', 'address'), addressRegex, false, true),
|
|
130
|
-
line3: getValidation(types_1.ValidationFields.line2, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'third line of your address'), wrongFormatMessage === null || wrongFormatMessage === void 0 ? void 0 : wrongFormatMessage.replace('${field}', 'address'), addressRegex, false, true),
|
|
131
|
-
city: getValidation(types_1.ValidationFields.city, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'Town/City'), wrongFormatMessage === null || wrongFormatMessage === void 0 ? void 0 : wrongFormatMessage.replace('${field}', 'town/city'), addressRegex),
|
|
132
|
-
county: getValidation(types_1.ValidationFields.county, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'County'), wrongFormatMessage === null || wrongFormatMessage === void 0 ? void 0 : wrongFormatMessage.replace('${field}', 'county'), addressRegex, false, true),
|
|
133
|
-
postcode: getValidation(types_1.ValidationFields.postcode, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'Postcode'), wrongFormatMessage === null || wrongFormatMessage === void 0 ? void 0 : wrongFormatMessage.replace('${field}', 'postcode'), addressRegex),
|
|
134
|
-
});
|
|
135
|
-
var postcodeValidation = yup.object({
|
|
136
|
-
postcode: getValidation(types_1.ValidationFields.postcode, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'Postcode'), wrongFormatMessage === null || wrongFormatMessage === void 0 ? void 0 : wrongFormatMessage.replace('${field}', 'postcode'), addressRegex),
|
|
137
|
-
});
|
|
138
|
-
var extraInfoRegex = /^[&!?#'.:0-9a-zA-Z\s]+$/;
|
|
139
|
-
var extraInfoMessage = "Sorry there are some charaters we don't allow in this field";
|
|
140
|
-
var cancellationReason = yup.object({
|
|
141
|
-
radioInput: yup.string().required('Please, select one option').nullable(),
|
|
142
|
-
other: yup.string().when('radioInput', {
|
|
143
|
-
is: function (val) { return val === 'Other'; },
|
|
144
|
-
then: yup.string().required('This field cannot be empty.'),
|
|
145
|
-
otherwise: yup.string().notRequired(),
|
|
146
|
-
}),
|
|
147
|
-
});
|
|
148
|
-
var confirmCancellation = yup.object({
|
|
149
|
-
cancellationReason: getValidation(types_1.ValidationFields.cancellationReason, requiredFields, 'This field cannot be empty.', extraInfoMessage, extraInfoRegex),
|
|
150
|
-
});
|
|
151
|
-
var deliveryInstructions = yup.object({
|
|
152
|
-
deliveryInformation: yup
|
|
153
|
-
.string()
|
|
154
|
-
.required('Please, select one option')
|
|
155
|
-
.nullable(),
|
|
156
|
-
other: yup
|
|
157
|
-
.string()
|
|
158
|
-
.when('deliveryInformation', {
|
|
159
|
-
is: function (val) { return val === 'Other (Please state)'; },
|
|
160
|
-
then: yup.string().required('Please enter your delivery instructions.'),
|
|
161
|
-
otherwise: yup.string().notRequired(),
|
|
162
|
-
})
|
|
163
|
-
.max(70, 'You cannot exceed 70 characters'),
|
|
164
|
-
});
|
|
165
|
-
var holidayStopValidation = yup.object({
|
|
166
|
-
startDate: yup.date().required('StartDate is required'),
|
|
167
|
-
endDate: yup
|
|
168
|
-
.date()
|
|
169
|
-
.required('EndDate is required')
|
|
170
|
-
.min(yup.ref('startDate'), "End date can't be before start date"),
|
|
171
|
-
});
|
|
172
|
-
var vouchersValidation = yup.object({
|
|
173
|
-
code: yup.string().required('need a subscription id'),
|
|
174
|
-
});
|
|
175
|
-
var accountCreationPage = yup.object({
|
|
176
|
-
title: yup.string().required('Title is required'),
|
|
177
|
-
firstName: getValidation(types_1.ValidationFields.firstName, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'First Name'), wrongFormatMessage === null || wrongFormatMessage === void 0 ? void 0 : wrongFormatMessage.replace('${field}', 'first name'), /^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z])*$/),
|
|
178
|
-
lastName: getValidation(types_1.ValidationFields.lastname, requiredFields, requiredMessage === null || requiredMessage === void 0 ? void 0 : requiredMessage.replace('${field}', 'Last Name'), wrongFormatMessage === null || wrongFormatMessage === void 0 ? void 0 : wrongFormatMessage.replace('${field}', 'last name'), /^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z])*$/),
|
|
179
|
-
yyyy: yup.string().required('Year is required').min(4).max(4),
|
|
180
|
-
mm: yup.string().required('Month is required').min(2).max(2),
|
|
181
|
-
dd: yup.string().required('Day is required').min(2).max(2),
|
|
182
|
-
tc: yup.string().required().oneOf(['true'], 'Required field'),
|
|
183
|
-
});
|
|
184
|
-
var deleteUserHolidayStopValidation = yup.object({
|
|
185
|
-
id: yup.string().required('Holiday stop Id is required'),
|
|
186
|
-
});
|
|
187
|
-
return {
|
|
188
|
-
name: nameValidation,
|
|
189
|
-
password: passwordValidation,
|
|
190
|
-
mobile: mobileValidation,
|
|
191
|
-
phoneNumber: phoneNumberValidation,
|
|
192
|
-
paymentMethodId: paymentMethodIdValidation,
|
|
193
|
-
zuoraPaymentMethod: zuoraPaymentMethodValidation,
|
|
194
|
-
email: emailValidation,
|
|
195
|
-
address: addressValidation,
|
|
196
|
-
displayName: displayNameValidation,
|
|
197
|
-
confirmCancellation: confirmCancellation,
|
|
198
|
-
'commenting-notifications': commentingNotifications,
|
|
199
|
-
cancellationReason: cancellationReason,
|
|
200
|
-
postcode: postcodeValidation,
|
|
201
|
-
accountCreationPage: accountCreationPage,
|
|
202
|
-
'delivery-instructions': deliveryInstructions,
|
|
203
|
-
'create-holiday-stop': holidayStopValidation,
|
|
204
|
-
'update-holiday-stop': holidayStopValidation,
|
|
205
|
-
deleteUserHolidayStop: deleteUserHolidayStopValidation,
|
|
206
|
-
vouchers: vouchersValidation,
|
|
207
|
-
};
|
|
208
|
-
};
|
|
209
|
-
exports.generateDefaultSchema = generateDefaultSchema;
|
|
210
|
-
var initializeYupSchema = function (_a) {
|
|
211
|
-
var overrideYupSchema = _a.overrideYupSchema, options = _a.options;
|
|
212
|
-
var defaultSchema = (0, exports.generateDefaultSchema)(options);
|
|
213
|
-
if (!overrideYupSchema || Object.keys(overrideYupSchema).length === 0) {
|
|
214
|
-
return defaultSchema;
|
|
215
|
-
}
|
|
216
|
-
return __assign(__assign({}, defaultSchema), overrideYupSchema);
|
|
217
|
-
};
|
|
218
|
-
exports.default = initializeYupSchema;
|
|
17
|
+
var validation_1 = require("./validation");
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
exports.default = validation_1.initializeYupSchema;
|
|
219
20
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAkD;AAClD,0CAAuB;AAEvB,kBAAe,gCAAmB,CAAA"}
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { generateDefaultSchema } from './utils';
|
|
2
|
+
export declare enum ValidationFieldNames {
|
|
2
3
|
'firstName' = 1,
|
|
3
4
|
'lastname' = 2,
|
|
4
5
|
'mobile' = 3,
|
|
@@ -17,5 +18,18 @@ export declare enum ValidationFields {
|
|
|
17
18
|
export interface InitializeYupOptions {
|
|
18
19
|
requiredMessage?: string;
|
|
19
20
|
wrongFormatMessage?: string;
|
|
20
|
-
overrideRequiredFields?:
|
|
21
|
+
overrideRequiredFields?: ValidationFieldNames[];
|
|
21
22
|
}
|
|
23
|
+
export type GetValidation = {
|
|
24
|
+
validationFieldName: ValidationFieldNames;
|
|
25
|
+
requiredMessage: string | undefined;
|
|
26
|
+
formatMessage: string | undefined;
|
|
27
|
+
regex?: RegExp;
|
|
28
|
+
isPhone?: boolean;
|
|
29
|
+
excludeEmptyString?: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type DefaultSchemaType = ReturnType<typeof generateDefaultSchema>;
|
|
32
|
+
export type DefaultSchemaKeysType = keyof DefaultSchemaType;
|
|
33
|
+
export type OverrideYupSchemaType = {
|
|
34
|
+
[key in DefaultSchemaKeysType]?: Record<string, any>;
|
|
35
|
+
};
|
package/dist/cjs/types.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
(function (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
})(
|
|
3
|
+
exports.ValidationFieldNames = void 0;
|
|
4
|
+
var ValidationFieldNames;
|
|
5
|
+
(function (ValidationFieldNames) {
|
|
6
|
+
ValidationFieldNames[ValidationFieldNames["firstName"] = 1] = "firstName";
|
|
7
|
+
ValidationFieldNames[ValidationFieldNames["lastname"] = 2] = "lastname";
|
|
8
|
+
ValidationFieldNames[ValidationFieldNames["mobile"] = 3] = "mobile";
|
|
9
|
+
ValidationFieldNames[ValidationFieldNames["phoneNumber"] = 4] = "phoneNumber";
|
|
10
|
+
ValidationFieldNames[ValidationFieldNames["country"] = 5] = "country";
|
|
11
|
+
ValidationFieldNames[ValidationFieldNames["line1"] = 6] = "line1";
|
|
12
|
+
ValidationFieldNames[ValidationFieldNames["line2"] = 7] = "line2";
|
|
13
|
+
ValidationFieldNames[ValidationFieldNames["city"] = 8] = "city";
|
|
14
|
+
ValidationFieldNames[ValidationFieldNames["county"] = 9] = "county";
|
|
15
|
+
ValidationFieldNames[ValidationFieldNames["postcode"] = 10] = "postcode";
|
|
16
|
+
ValidationFieldNames[ValidationFieldNames["other"] = 11] = "other";
|
|
17
|
+
ValidationFieldNames[ValidationFieldNames["radioInput"] = 12] = "radioInput";
|
|
18
|
+
ValidationFieldNames[ValidationFieldNames["cancellationReason"] = 13] = "cancellationReason";
|
|
19
|
+
ValidationFieldNames[ValidationFieldNames["accountCreationPage"] = 14] = "accountCreationPage";
|
|
20
|
+
})(ValidationFieldNames = exports.ValidationFieldNames || (exports.ValidationFieldNames = {}));
|
|
21
21
|
//# sourceMappingURL=types.js.map
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AACA,IAAY,oBAeX;AAfD,WAAY,oBAAoB;IAC9B,yEAAe,CAAA;IACf,uEAAU,CAAA;IACV,mEAAQ,CAAA;IACR,6EAAa,CAAA;IACb,qEAAS,CAAA;IACT,iEAAO,CAAA;IACP,iEAAO,CAAA;IACP,+DAAM,CAAA;IACN,mEAAQ,CAAA;IACR,wEAAU,CAAA;IACV,kEAAO,CAAA;IACP,4EAAY,CAAA;IACZ,4FAAoB,CAAA;IACpB,8FAAqB,CAAA;AACvB,CAAC,EAfW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAe/B"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
import { InitializeYupOptions, ValidationFieldNames, GetValidation } from './types';
|
|
3
|
+
export declare const defaultRequiredFields: ValidationFieldNames[];
|
|
4
|
+
export declare const getValidation: (requiredFields: ValidationFieldNames[]) => ({ validationFieldName, requiredMessage, formatMessage, regex, isPhone, excludeEmptyString, }: GetValidation) => yup.default<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
|
|
5
|
+
export declare const generateDefaultSchema: (options?: InitializeYupOptions) => {
|
|
6
|
+
name: yup.ObjectSchema<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
7
|
+
firstName: any;
|
|
8
|
+
lastName: any;
|
|
9
|
+
}>, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
10
|
+
firstName: any;
|
|
11
|
+
lastName: any;
|
|
12
|
+
}>>, import("yup/lib/object").AssertsShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
13
|
+
firstName: any;
|
|
14
|
+
lastName: any;
|
|
15
|
+
}>>>;
|
|
16
|
+
password: import("yup/lib/object").OptionalObjectSchema<{
|
|
17
|
+
password: yup.default<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
|
|
18
|
+
}, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
|
|
19
|
+
password: yup.default<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
|
|
20
|
+
}>>;
|
|
21
|
+
mobile: yup.ObjectSchema<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
22
|
+
mobile: any;
|
|
23
|
+
}>, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
24
|
+
mobile: any;
|
|
25
|
+
}>>, import("yup/lib/object").AssertsShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
26
|
+
mobile: any;
|
|
27
|
+
}>>>;
|
|
28
|
+
phoneNumber: yup.ObjectSchema<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
29
|
+
phoneNumber: any;
|
|
30
|
+
}>, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
31
|
+
phoneNumber: any;
|
|
32
|
+
}>>, import("yup/lib/object").AssertsShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
33
|
+
phoneNumber: any;
|
|
34
|
+
}>>>;
|
|
35
|
+
paymentMethodId: import("yup/lib/object").OptionalObjectSchema<{
|
|
36
|
+
paymentMethodId: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
37
|
+
}, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
|
|
38
|
+
paymentMethodId: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
39
|
+
}>>;
|
|
40
|
+
zuoraPaymentMethod: import("yup/lib/object").OptionalObjectSchema<{
|
|
41
|
+
refId: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
42
|
+
responseSignature: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
43
|
+
token: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
44
|
+
id: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
45
|
+
timestamp: import("yup/lib/number").RequiredNumberSchema<number | undefined, import("yup/lib/types").AnyObject>;
|
|
46
|
+
tenantId: import("yup/lib/number").RequiredNumberSchema<number | undefined, import("yup/lib/types").AnyObject>;
|
|
47
|
+
}, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
|
|
48
|
+
refId: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
49
|
+
responseSignature: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
50
|
+
token: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
51
|
+
id: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
52
|
+
timestamp: import("yup/lib/number").RequiredNumberSchema<number | undefined, import("yup/lib/types").AnyObject>;
|
|
53
|
+
tenantId: import("yup/lib/number").RequiredNumberSchema<number | undefined, import("yup/lib/types").AnyObject>;
|
|
54
|
+
}>>;
|
|
55
|
+
email: import("yup/lib/object").OptionalObjectSchema<{
|
|
56
|
+
email: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
57
|
+
}, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
|
|
58
|
+
email: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
59
|
+
}>>;
|
|
60
|
+
address: yup.ObjectSchema<import("yup/lib/object").Assign<{
|
|
61
|
+
postcode: any;
|
|
62
|
+
}, {
|
|
63
|
+
country: any;
|
|
64
|
+
line1: any;
|
|
65
|
+
line2: any;
|
|
66
|
+
line3: any;
|
|
67
|
+
city: any;
|
|
68
|
+
county: any;
|
|
69
|
+
}>, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<import("yup/lib/object").Assign<{
|
|
70
|
+
postcode: any;
|
|
71
|
+
}, {
|
|
72
|
+
country: any;
|
|
73
|
+
line1: any;
|
|
74
|
+
line2: any;
|
|
75
|
+
line3: any;
|
|
76
|
+
city: any;
|
|
77
|
+
county: any;
|
|
78
|
+
}>>, import("yup/lib/object").AssertsShape<import("yup/lib/object").Assign<{
|
|
79
|
+
postcode: any;
|
|
80
|
+
}, {
|
|
81
|
+
country: any;
|
|
82
|
+
line1: any;
|
|
83
|
+
line2: any;
|
|
84
|
+
line3: any;
|
|
85
|
+
city: any;
|
|
86
|
+
county: any;
|
|
87
|
+
}>>>;
|
|
88
|
+
displayName: yup.ObjectSchema<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
89
|
+
displayName: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
90
|
+
}>, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
91
|
+
displayName: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
92
|
+
}>>, import("yup/lib/object").AssertsShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
93
|
+
displayName: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
94
|
+
}>>>;
|
|
95
|
+
confirmCancellation: import("yup/lib/object").OptionalObjectSchema<{
|
|
96
|
+
cancellationReason: any;
|
|
97
|
+
}, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
|
|
98
|
+
cancellationReason: any;
|
|
99
|
+
}>>;
|
|
100
|
+
'commenting-notifications': import("yup/lib/object").OptionalObjectSchema<{
|
|
101
|
+
likedYourMessage: yup.BooleanSchema<boolean | undefined, import("yup/lib/types").AnyObject, boolean | undefined>;
|
|
102
|
+
userMentioned: yup.BooleanSchema<boolean | undefined, import("yup/lib/types").AnyObject, boolean | undefined>;
|
|
103
|
+
repliedToMessage: yup.BooleanSchema<boolean | undefined, import("yup/lib/types").AnyObject, boolean | undefined>;
|
|
104
|
+
}, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
|
|
105
|
+
likedYourMessage: yup.BooleanSchema<boolean | undefined, import("yup/lib/types").AnyObject, boolean | undefined>;
|
|
106
|
+
userMentioned: yup.BooleanSchema<boolean | undefined, import("yup/lib/types").AnyObject, boolean | undefined>;
|
|
107
|
+
repliedToMessage: yup.BooleanSchema<boolean | undefined, import("yup/lib/types").AnyObject, boolean | undefined>;
|
|
108
|
+
}>>;
|
|
109
|
+
cancellationReason: import("yup/lib/object").OptionalObjectSchema<{
|
|
110
|
+
radioInput: import("yup/lib/string").RequiredStringSchema<string | null | undefined, import("yup/lib/types").AnyObject>;
|
|
111
|
+
other: yup.default<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
|
|
112
|
+
}, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
|
|
113
|
+
radioInput: import("yup/lib/string").RequiredStringSchema<string | null | undefined, import("yup/lib/types").AnyObject>;
|
|
114
|
+
other: yup.default<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
|
|
115
|
+
}>>;
|
|
116
|
+
postcode: import("yup/lib/object").OptionalObjectSchema<{
|
|
117
|
+
postcode: any;
|
|
118
|
+
}, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
|
|
119
|
+
postcode: any;
|
|
120
|
+
}>>;
|
|
121
|
+
accountCreationPage: yup.ObjectSchema<import("yup/lib/object").Assign<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
122
|
+
firstName: any;
|
|
123
|
+
lastName: any;
|
|
124
|
+
}>, {
|
|
125
|
+
title: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
126
|
+
yyyy: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
127
|
+
mm: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
128
|
+
dd: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
129
|
+
tc: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
130
|
+
}>, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<import("yup/lib/object").Assign<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
131
|
+
firstName: any;
|
|
132
|
+
lastName: any;
|
|
133
|
+
}>, {
|
|
134
|
+
title: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
135
|
+
yyyy: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
136
|
+
mm: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
137
|
+
dd: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
138
|
+
tc: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
139
|
+
}>>, import("yup/lib/object").AssertsShape<import("yup/lib/object").Assign<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
|
|
140
|
+
firstName: any;
|
|
141
|
+
lastName: any;
|
|
142
|
+
}>, {
|
|
143
|
+
title: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
144
|
+
yyyy: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
145
|
+
mm: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
146
|
+
dd: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
147
|
+
tc: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
148
|
+
}>>>;
|
|
149
|
+
'delivery-instructions': import("yup/lib/object").OptionalObjectSchema<{
|
|
150
|
+
deliveryInformation: import("yup/lib/string").RequiredStringSchema<string | null | undefined, import("yup/lib/types").AnyObject>;
|
|
151
|
+
other: yup.default<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
|
|
152
|
+
}, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
|
|
153
|
+
deliveryInformation: import("yup/lib/string").RequiredStringSchema<string | null | undefined, import("yup/lib/types").AnyObject>;
|
|
154
|
+
other: yup.default<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
|
|
155
|
+
}>>;
|
|
156
|
+
'create-holiday-stop': import("yup/lib/object").OptionalObjectSchema<{
|
|
157
|
+
startDate: import("yup/lib/date").RequiredDateSchema<Date | undefined, import("yup/lib/types").AnyObject>;
|
|
158
|
+
endDate: import("yup/lib/date").RequiredDateSchema<Date | undefined, import("yup/lib/types").AnyObject>;
|
|
159
|
+
}, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
|
|
160
|
+
startDate: import("yup/lib/date").RequiredDateSchema<Date | undefined, import("yup/lib/types").AnyObject>;
|
|
161
|
+
endDate: import("yup/lib/date").RequiredDateSchema<Date | undefined, import("yup/lib/types").AnyObject>;
|
|
162
|
+
}>>;
|
|
163
|
+
'update-holiday-stop': import("yup/lib/object").OptionalObjectSchema<{
|
|
164
|
+
startDate: import("yup/lib/date").RequiredDateSchema<Date | undefined, import("yup/lib/types").AnyObject>;
|
|
165
|
+
endDate: import("yup/lib/date").RequiredDateSchema<Date | undefined, import("yup/lib/types").AnyObject>;
|
|
166
|
+
}, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
|
|
167
|
+
startDate: import("yup/lib/date").RequiredDateSchema<Date | undefined, import("yup/lib/types").AnyObject>;
|
|
168
|
+
endDate: import("yup/lib/date").RequiredDateSchema<Date | undefined, import("yup/lib/types").AnyObject>;
|
|
169
|
+
}>>;
|
|
170
|
+
deleteUserHolidayStop: import("yup/lib/object").OptionalObjectSchema<{
|
|
171
|
+
id: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
172
|
+
}, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
|
|
173
|
+
id: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
174
|
+
}>>;
|
|
175
|
+
vouchers: import("yup/lib/object").OptionalObjectSchema<{
|
|
176
|
+
code: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
177
|
+
}, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
|
|
178
|
+
code: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
|
|
179
|
+
}>>;
|
|
180
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.generateDefaultSchema = exports.getValidation = exports.defaultRequiredFields = void 0;
|
|
27
|
+
var yup = __importStar(require("yup"));
|
|
28
|
+
var types_1 = require("./types");
|
|
29
|
+
var validations_1 = require("./validations");
|
|
30
|
+
exports.defaultRequiredFields = [
|
|
31
|
+
types_1.ValidationFieldNames.firstName,
|
|
32
|
+
types_1.ValidationFieldNames.lastname,
|
|
33
|
+
types_1.ValidationFieldNames.mobile,
|
|
34
|
+
types_1.ValidationFieldNames.phoneNumber,
|
|
35
|
+
types_1.ValidationFieldNames.country,
|
|
36
|
+
types_1.ValidationFieldNames.line1,
|
|
37
|
+
types_1.ValidationFieldNames.city,
|
|
38
|
+
types_1.ValidationFieldNames.postcode,
|
|
39
|
+
types_1.ValidationFieldNames.other,
|
|
40
|
+
types_1.ValidationFieldNames.cancellationReason,
|
|
41
|
+
];
|
|
42
|
+
var getValidation = function (requiredFields) {
|
|
43
|
+
return function (_a) {
|
|
44
|
+
var validationFieldName = _a.validationFieldName, requiredMessage = _a.requiredMessage, formatMessage = _a.formatMessage, regex = _a.regex, isPhone = _a.isPhone, excludeEmptyString = _a.excludeEmptyString;
|
|
45
|
+
var validation = yup.string();
|
|
46
|
+
if (requiredFields.includes(validationFieldName)) {
|
|
47
|
+
validation = validation.required(requiredMessage);
|
|
48
|
+
}
|
|
49
|
+
if (isPhone) {
|
|
50
|
+
validation = validation.phone(undefined, true, formatMessage);
|
|
51
|
+
}
|
|
52
|
+
else if (regex) {
|
|
53
|
+
validation = validation.matches(regex, {
|
|
54
|
+
message: formatMessage,
|
|
55
|
+
excludeEmptyString: excludeEmptyString,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return validation;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
exports.getValidation = getValidation;
|
|
62
|
+
var generateDefaultSchema = function (options) {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
var requiredFields = (options === null || options === void 0 ? void 0 : options.overrideRequiredFields) || exports.defaultRequiredFields;
|
|
65
|
+
var getFieldValidation = (0, exports.getValidation)(requiredFields);
|
|
66
|
+
var DEFAULT_REQUIRED_MESSAGE = 'Please enter your ${field}';
|
|
67
|
+
var DEFAULT_WRONG_FORMAT_MESSAGE = 'Your ${field} can’t contain special characters. Please try again.';
|
|
68
|
+
var includesReuiredTemplate = (_a = options === null || options === void 0 ? void 0 : options.requiredMessage) === null || _a === void 0 ? void 0 : _a.includes('${field}');
|
|
69
|
+
var includesWrongFormatTemplate = (_b = options === null || options === void 0 ? void 0 : options.wrongFormatMessage) === null || _b === void 0 ? void 0 : _b.includes('${field}');
|
|
70
|
+
var requiredMessage = includesReuiredTemplate
|
|
71
|
+
? options === null || options === void 0 ? void 0 : options.requiredMessage
|
|
72
|
+
: DEFAULT_REQUIRED_MESSAGE;
|
|
73
|
+
var wrongFormatMessage = includesWrongFormatTemplate
|
|
74
|
+
? options === null || options === void 0 ? void 0 : options.wrongFormatMessage
|
|
75
|
+
: DEFAULT_WRONG_FORMAT_MESSAGE;
|
|
76
|
+
return {
|
|
77
|
+
name: (0, validations_1.nameValidation)({
|
|
78
|
+
getFieldValidation: getFieldValidation,
|
|
79
|
+
requiredMessage: requiredMessage,
|
|
80
|
+
wrongFormatMessage: wrongFormatMessage,
|
|
81
|
+
}),
|
|
82
|
+
password: validations_1.passwordValidation,
|
|
83
|
+
mobile: (0, validations_1.mobileValidation)({ getFieldValidation: getFieldValidation, requiredMessage: requiredMessage }),
|
|
84
|
+
phoneNumber: (0, validations_1.phoneNumberValidation)({ getFieldValidation: getFieldValidation, requiredMessage: requiredMessage }),
|
|
85
|
+
paymentMethodId: validations_1.paymentMethodIdValidation,
|
|
86
|
+
zuoraPaymentMethod: validations_1.zuoraPaymentMethodValidation,
|
|
87
|
+
email: (0, validations_1.emailValidation)({ requiredMessage: requiredMessage }),
|
|
88
|
+
address: (0, validations_1.addressValidation)({
|
|
89
|
+
getFieldValidation: getFieldValidation,
|
|
90
|
+
requiredMessage: requiredMessage,
|
|
91
|
+
wrongFormatMessage: wrongFormatMessage,
|
|
92
|
+
}),
|
|
93
|
+
displayName: (0, validations_1.displayNameValidation)({ requiredMessage: requiredMessage }),
|
|
94
|
+
confirmCancellation: (0, validations_1.confirmCancellation)({ getFieldValidation: getFieldValidation }),
|
|
95
|
+
'commenting-notifications': validations_1.commentingNotifications,
|
|
96
|
+
cancellationReason: validations_1.cancellationReason,
|
|
97
|
+
postcode: (0, validations_1.postcodeValidation)({
|
|
98
|
+
getFieldValidation: getFieldValidation,
|
|
99
|
+
requiredMessage: requiredMessage,
|
|
100
|
+
wrongFormatMessage: wrongFormatMessage,
|
|
101
|
+
}),
|
|
102
|
+
accountCreationPage: (0, validations_1.accountCreationPage)({
|
|
103
|
+
getFieldValidation: getFieldValidation,
|
|
104
|
+
requiredMessage: requiredMessage,
|
|
105
|
+
wrongFormatMessage: wrongFormatMessage,
|
|
106
|
+
}),
|
|
107
|
+
'delivery-instructions': validations_1.deliveryInstructions,
|
|
108
|
+
'create-holiday-stop': validations_1.holidayStopValidation,
|
|
109
|
+
'update-holiday-stop': validations_1.holidayStopValidation,
|
|
110
|
+
deleteUserHolidayStop: validations_1.deleteUserHolidayStopValidation,
|
|
111
|
+
vouchers: validations_1.vouchersValidation,
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
exports.generateDefaultSchema = generateDefaultSchema;
|
|
115
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"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"}
|