keycloakify 11.3.7 → 11.3.9-rc.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/README.md +1 -0
- package/bin/526.index.js +4 -4
- package/login/lib/getUserProfileApi/getUserProfileApi.d.ts +88 -0
- package/login/lib/getUserProfileApi/getUserProfileApi.js +1076 -0
- package/login/lib/getUserProfileApi/getUserProfileApi.js.map +1 -0
- package/login/lib/getUserProfileApi/index.d.ts +1 -0
- package/login/lib/getUserProfileApi/index.js +2 -0
- package/login/lib/getUserProfileApi/index.js.map +1 -0
- package/login/lib/getUserProfileApi/kcNumberUnFormat.d.ts +1 -0
- package/login/lib/getUserProfileApi/kcNumberUnFormat.js +84 -0
- package/login/lib/getUserProfileApi/kcNumberUnFormat.js.map +1 -0
- package/login/lib/useUserProfileForm.d.ts +9 -34
- package/login/lib/useUserProfileForm.js +44 -998
- package/login/lib/useUserProfileForm.js.map +1 -1
- package/login/pages/LoginPasskeysConditionalAuthenticate.useScript.js +7 -1
- package/login/pages/LoginPasskeysConditionalAuthenticate.useScript.js.map +1 -1
- package/login/pages/LoginRecoveryAuthnCodeConfig.useScript.js +7 -1
- package/login/pages/LoginRecoveryAuthnCodeConfig.useScript.js.map +1 -1
- package/login/pages/WebauthnAuthenticate.useScript.js +7 -1
- package/login/pages/WebauthnAuthenticate.useScript.js.map +1 -1
- package/login/pages/WebauthnRegister.useScript.js +7 -1
- package/login/pages/WebauthnRegister.useScript.js.map +1 -1
- package/package.json +17 -1
- package/src/bin/start-keycloak/start-keycloak.ts +4 -4
- package/src/login/lib/getUserProfileApi/getUserProfileApi.ts +1561 -0
- package/src/login/lib/getUserProfileApi/index.ts +1 -0
- package/src/login/lib/getUserProfileApi/kcNumberUnFormat.ts +109 -0
- package/src/login/lib/useUserProfileForm.tsx +82 -1322
- package/src/login/pages/LoginPasskeysConditionalAuthenticate.useScript.tsx +8 -1
- package/src/login/pages/LoginRecoveryAuthnCodeConfig.useScript.tsx +8 -1
- package/src/login/pages/WebauthnAuthenticate.useScript.tsx +8 -1
- package/src/login/pages/WebauthnRegister.useScript.tsx +8 -1
- package/src/tools/waitForElementMountedOnDom.ts +30 -0
- package/tools/waitForElementMountedOnDom.d.ts +3 -0
- package/tools/waitForElementMountedOnDom.js +21 -0
- package/tools/waitForElementMountedOnDom.js.map +1 -0
@@ -1,1010 +1,56 @@
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
2
|
-
var t = {};
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
4
|
-
t[p] = s[p];
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
8
|
-
t[p[i]] = s[p[i]];
|
9
|
-
}
|
10
|
-
return t;
|
11
|
-
};
|
12
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
13
|
-
import "
|
14
|
-
import {
|
2
|
+
import * as reactlessApi from "./getUserProfileApi/index";
|
3
|
+
import { useEffect, useState, useMemo, Fragment } from "react";
|
15
4
|
import { assert } from "tsafe/assert";
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
5
|
+
export { getButtonToDisplayForMultivaluedAttributeField } from "./getUserProfileApi/index";
|
6
|
+
{
|
7
|
+
assert();
|
8
|
+
}
|
9
|
+
{
|
10
|
+
assert();
|
11
|
+
}
|
12
|
+
{
|
13
|
+
assert();
|
14
|
+
}
|
15
|
+
{
|
16
|
+
assert();
|
17
|
+
}
|
18
|
+
{
|
19
|
+
assert();
|
20
|
+
}
|
21
|
+
{
|
22
|
+
assert();
|
23
|
+
}
|
24
24
|
export function useUserProfileForm(params) {
|
25
|
-
|
26
|
-
const
|
27
|
-
const { insertScriptTags } = useInsertScriptTags({
|
28
|
-
componentOrHookName: "useUserProfileForm",
|
29
|
-
scriptTags: Object.keys((_b = (_a = kcContext.profile) === null || _a === void 0 ? void 0 : _a.html5DataAnnotations) !== null && _b !== void 0 ? _b : {})
|
30
|
-
.filter(key => key !== "kcMultivalued" && key !== "kcNumberFormat") // NOTE: Keycloakify handles it.
|
31
|
-
.map(key => ({
|
32
|
-
type: "module",
|
33
|
-
src: `${kcContext.url.resourcesPath}/js/${key}.js`
|
34
|
-
}))
|
35
|
-
});
|
36
|
-
useEffect(() => {
|
37
|
-
insertScriptTags();
|
38
|
-
}, []);
|
39
|
-
const { getErrors } = useGetErrors({
|
25
|
+
const { doMakeUserConfirmPassword, i18n, kcContext } = params;
|
26
|
+
const api = reactlessApi.getUserProfileApi({
|
40
27
|
kcContext,
|
41
|
-
|
28
|
+
doMakeUserConfirmPassword
|
42
29
|
});
|
43
|
-
const
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
// We also want to apply some retro-compatibility and consistency patches.
|
48
|
-
const attributes = (() => {
|
49
|
-
var _a;
|
50
|
-
mock_user_profile_attributes_for_older_keycloak_versions: {
|
51
|
-
if ("profile" in kcContext &&
|
52
|
-
"attributesByName" in kcContext.profile &&
|
53
|
-
Object.keys(kcContext.profile.attributesByName).length !== 0) {
|
54
|
-
break mock_user_profile_attributes_for_older_keycloak_versions;
|
55
|
-
}
|
56
|
-
if ("register" in kcContext && kcContext.register instanceof Object && "formData" in kcContext.register) {
|
57
|
-
//NOTE: Handle legacy register.ftl page
|
58
|
-
return ["firstName", "lastName", "email", "username"]
|
59
|
-
.filter(name => (name !== "username" ? true : !kcContext.realm.registrationEmailAsUsername))
|
60
|
-
.map(name => {
|
61
|
-
var _a;
|
62
|
-
return id({
|
63
|
-
name: name,
|
64
|
-
displayName: id(`\${${name}}`),
|
65
|
-
required: true,
|
66
|
-
value: (_a = kcContext.register.formData[name]) !== null && _a !== void 0 ? _a : "",
|
67
|
-
html5DataAnnotations: {},
|
68
|
-
readOnly: false,
|
69
|
-
validators: {},
|
70
|
-
annotations: {},
|
71
|
-
autocomplete: (() => {
|
72
|
-
switch (name) {
|
73
|
-
case "email":
|
74
|
-
return "email";
|
75
|
-
case "username":
|
76
|
-
return "username";
|
77
|
-
default:
|
78
|
-
return undefined;
|
79
|
-
}
|
80
|
-
})()
|
81
|
-
});
|
82
|
-
});
|
83
|
-
}
|
84
|
-
if ("user" in kcContext && kcContext.user instanceof Object) {
|
85
|
-
//NOTE: Handle legacy login-update-profile.ftl
|
86
|
-
return ["username", "email", "firstName", "lastName"]
|
87
|
-
.filter(name => (name !== "username" ? true : kcContext.user.editUsernameAllowed))
|
88
|
-
.map(name => {
|
89
|
-
var _a;
|
90
|
-
return id({
|
91
|
-
name: name,
|
92
|
-
displayName: id(`\${${name}}`),
|
93
|
-
required: true,
|
94
|
-
value: (_a = kcContext.user[name]) !== null && _a !== void 0 ? _a : "",
|
95
|
-
html5DataAnnotations: {},
|
96
|
-
readOnly: false,
|
97
|
-
validators: {},
|
98
|
-
annotations: {},
|
99
|
-
autocomplete: (() => {
|
100
|
-
switch (name) {
|
101
|
-
case "email":
|
102
|
-
return "email";
|
103
|
-
case "username":
|
104
|
-
return "username";
|
105
|
-
default:
|
106
|
-
return undefined;
|
107
|
-
}
|
108
|
-
})()
|
109
|
-
});
|
110
|
-
});
|
111
|
-
}
|
112
|
-
if ("email" in kcContext && kcContext.email instanceof Object) {
|
113
|
-
//NOTE: Handle legacy update-email.ftl
|
114
|
-
return [
|
115
|
-
id({
|
116
|
-
name: "email",
|
117
|
-
displayName: id(`\${email}`),
|
118
|
-
required: true,
|
119
|
-
value: (_a = kcContext.email.value) !== null && _a !== void 0 ? _a : "",
|
120
|
-
html5DataAnnotations: {},
|
121
|
-
readOnly: false,
|
122
|
-
validators: {},
|
123
|
-
annotations: {},
|
124
|
-
autocomplete: "email"
|
125
|
-
})
|
126
|
-
];
|
127
|
-
}
|
128
|
-
assert(false, "Unable to mock user profile from the current kcContext");
|
129
|
-
}
|
130
|
-
return Object.values(kcContext.profile.attributesByName).map(structuredCloneButFunctions);
|
131
|
-
})();
|
132
|
-
// Retro-compatibility and consistency patches
|
133
|
-
attributes.forEach(attribute => {
|
134
|
-
var _a, _b, _c;
|
135
|
-
patch_legacy_group: {
|
136
|
-
if (typeof attribute.group !== "string") {
|
137
|
-
break patch_legacy_group;
|
138
|
-
}
|
139
|
-
const { group, groupDisplayHeader, groupDisplayDescription, groupAnnotations } = attribute;
|
140
|
-
delete attribute.group;
|
141
|
-
// @ts-expect-error
|
142
|
-
delete attribute.groupDisplayHeader;
|
143
|
-
// @ts-expect-error
|
144
|
-
delete attribute.groupDisplayDescription;
|
145
|
-
// @ts-expect-error
|
146
|
-
delete attribute.groupAnnotations;
|
147
|
-
if (group === "") {
|
148
|
-
break patch_legacy_group;
|
149
|
-
}
|
150
|
-
attribute.group = {
|
151
|
-
name: group,
|
152
|
-
displayHeader: groupDisplayHeader,
|
153
|
-
displayDescription: groupDisplayDescription,
|
154
|
-
annotations: groupAnnotations,
|
155
|
-
html5DataAnnotations: {}
|
156
|
-
};
|
157
|
-
}
|
158
|
-
// Attributes with options rendered by default as select inputs
|
159
|
-
if (attribute.validators.options !== undefined && attribute.annotations.inputType === undefined) {
|
160
|
-
attribute.annotations.inputType = "select";
|
161
|
-
}
|
162
|
-
// Consistency patch on values/value property
|
163
|
-
{
|
164
|
-
if (getIsMultivaluedSingleField({ attribute })) {
|
165
|
-
attribute.multivalued = true;
|
166
|
-
}
|
167
|
-
if (attribute.multivalued) {
|
168
|
-
(_a = attribute.values) !== null && _a !== void 0 ? _a : (attribute.values = attribute.value !== undefined ? [attribute.value] : []);
|
169
|
-
delete attribute.value;
|
170
|
-
}
|
171
|
-
else {
|
172
|
-
(_b = attribute.value) !== null && _b !== void 0 ? _b : (attribute.value = (_c = attribute.values) === null || _c === void 0 ? void 0 : _c[0]);
|
173
|
-
delete attribute.values;
|
174
|
-
}
|
175
|
-
}
|
30
|
+
const [formState_reactless, setFormState_reactless] = useState(() => api.getFormState());
|
31
|
+
useEffect(() => {
|
32
|
+
const { unsubscribe } = api.subscribeToFormState(() => {
|
33
|
+
setFormState_reactless(api.getFormState());
|
176
34
|
});
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
}
|
181
|
-
attributes.forEach((attribute, i) => {
|
182
|
-
if (attribute.name !== (kcContext.realm.registrationEmailAsUsername ? "email" : "username")) {
|
183
|
-
// NOTE: We want to add password and password-confirm after the field that identifies the user.
|
184
|
-
// It's either email or username.
|
185
|
-
return;
|
186
|
-
}
|
187
|
-
attributes.splice(i + 1, 0, {
|
188
|
-
name: "password",
|
189
|
-
displayName: id("${password}"),
|
190
|
-
required: true,
|
191
|
-
readOnly: false,
|
192
|
-
validators: {},
|
193
|
-
annotations: {},
|
194
|
-
autocomplete: "new-password",
|
195
|
-
html5DataAnnotations: {}
|
196
|
-
}, {
|
197
|
-
name: "password-confirm",
|
198
|
-
displayName: id("${passwordConfirm}"),
|
199
|
-
required: true,
|
200
|
-
readOnly: false,
|
201
|
-
validators: {},
|
202
|
-
annotations: {},
|
203
|
-
html5DataAnnotations: {},
|
204
|
-
autocomplete: "new-password"
|
205
|
-
});
|
206
|
-
});
|
207
|
-
}
|
208
|
-
const initialFormFieldState = [];
|
209
|
-
for (const attribute of attributes) {
|
210
|
-
handle_multi_valued_attribute: {
|
211
|
-
if (!attribute.multivalued) {
|
212
|
-
break handle_multi_valued_attribute;
|
213
|
-
}
|
214
|
-
const values = ((_a = attribute.values) === null || _a === void 0 ? void 0 : _a.length) ? attribute.values : [""];
|
215
|
-
apply_validator_min_range: {
|
216
|
-
if (getIsMultivaluedSingleField({ attribute })) {
|
217
|
-
break apply_validator_min_range;
|
218
|
-
}
|
219
|
-
const validator = attribute.validators.multivalued;
|
220
|
-
if (validator === undefined) {
|
221
|
-
break apply_validator_min_range;
|
222
|
-
}
|
223
|
-
const { min: minStr } = validator;
|
224
|
-
if (!minStr) {
|
225
|
-
break apply_validator_min_range;
|
226
|
-
}
|
227
|
-
const min = parseInt(`${minStr}`);
|
228
|
-
for (let index = values.length; index < min; index++) {
|
229
|
-
values.push("");
|
230
|
-
}
|
231
|
-
}
|
232
|
-
initialFormFieldState.push({
|
233
|
-
attribute,
|
234
|
-
valueOrValues: values
|
235
|
-
});
|
236
|
-
continue;
|
237
|
-
}
|
238
|
-
initialFormFieldState.push({
|
239
|
-
attribute,
|
240
|
-
valueOrValues: (_b = attribute.value) !== null && _b !== void 0 ? _b : ""
|
241
|
-
});
|
242
|
-
}
|
243
|
-
const initialState = {
|
244
|
-
formFieldStates: initialFormFieldState.map(({ attribute, valueOrValues }) => ({
|
245
|
-
attribute,
|
246
|
-
errors: getErrors({
|
247
|
-
attributeName: attribute.name,
|
248
|
-
formFieldStates: initialFormFieldState
|
249
|
-
}),
|
250
|
-
hasLostFocusAtLeastOnce: valueOrValues instanceof Array && !getIsMultivaluedSingleField({ attribute }) ? valueOrValues.map(() => false) : false,
|
251
|
-
valueOrValues: valueOrValues
|
252
|
-
}))
|
253
|
-
};
|
254
|
-
return initialState;
|
255
|
-
}, []);
|
256
|
-
const [state, dispatchFormAction] = useReducer(function reducer(state, formAction) {
|
257
|
-
const formFieldState = state.formFieldStates.find(({ attribute }) => attribute.name === formAction.name);
|
258
|
-
assert(formFieldState !== undefined);
|
259
|
-
(() => {
|
260
|
-
var _a;
|
261
|
-
switch (formAction.action) {
|
262
|
-
case "update":
|
263
|
-
formFieldState.valueOrValues = formAction.valueOrValues;
|
264
|
-
apply_formatters: {
|
265
|
-
const { attribute } = formFieldState;
|
266
|
-
const { kcNumberFormat } = (_a = attribute.html5DataAnnotations) !== null && _a !== void 0 ? _a : {};
|
267
|
-
if (!kcNumberFormat) {
|
268
|
-
break apply_formatters;
|
269
|
-
}
|
270
|
-
if (formFieldState.valueOrValues instanceof Array) {
|
271
|
-
formFieldState.valueOrValues = formFieldState.valueOrValues.map(value => formatNumber(value, kcNumberFormat));
|
272
|
-
}
|
273
|
-
else {
|
274
|
-
formFieldState.valueOrValues = formatNumber(formFieldState.valueOrValues, kcNumberFormat);
|
275
|
-
}
|
276
|
-
}
|
277
|
-
formFieldState.errors = getErrors({
|
278
|
-
attributeName: formAction.name,
|
279
|
-
formFieldStates: state.formFieldStates
|
280
|
-
});
|
281
|
-
simulate_focus_lost: {
|
282
|
-
const { displayErrorsImmediately = false } = formAction;
|
283
|
-
if (!displayErrorsImmediately) {
|
284
|
-
break simulate_focus_lost;
|
285
|
-
}
|
286
|
-
for (const fieldIndex of formAction.valueOrValues instanceof Array
|
287
|
-
? formAction.valueOrValues.map((...[, index]) => index)
|
288
|
-
: [undefined]) {
|
289
|
-
state = reducer(state, {
|
290
|
-
action: "focus lost",
|
291
|
-
name: formAction.name,
|
292
|
-
fieldIndex
|
293
|
-
});
|
294
|
-
}
|
295
|
-
}
|
296
|
-
update_password_confirm: {
|
297
|
-
if (doMakeUserConfirmPassword) {
|
298
|
-
break update_password_confirm;
|
299
|
-
}
|
300
|
-
if (formAction.name !== "password") {
|
301
|
-
break update_password_confirm;
|
302
|
-
}
|
303
|
-
state = reducer(state, {
|
304
|
-
action: "update",
|
305
|
-
name: "password-confirm",
|
306
|
-
valueOrValues: formAction.valueOrValues,
|
307
|
-
displayErrorsImmediately: formAction.displayErrorsImmediately
|
308
|
-
});
|
309
|
-
}
|
310
|
-
trigger_password_confirm_validation_on_password_change: {
|
311
|
-
if (!doMakeUserConfirmPassword) {
|
312
|
-
break trigger_password_confirm_validation_on_password_change;
|
313
|
-
}
|
314
|
-
if (formAction.name !== "password") {
|
315
|
-
break trigger_password_confirm_validation_on_password_change;
|
316
|
-
}
|
317
|
-
state = reducer(state, {
|
318
|
-
action: "update",
|
319
|
-
name: "password-confirm",
|
320
|
-
valueOrValues: (() => {
|
321
|
-
const formFieldState = state.formFieldStates.find(({ attribute }) => attribute.name === "password-confirm");
|
322
|
-
assert(formFieldState !== undefined);
|
323
|
-
return formFieldState.valueOrValues;
|
324
|
-
})(),
|
325
|
-
displayErrorsImmediately: formAction.displayErrorsImmediately
|
326
|
-
});
|
327
|
-
}
|
328
|
-
return;
|
329
|
-
case "focus lost":
|
330
|
-
if (formFieldState.hasLostFocusAtLeastOnce instanceof Array) {
|
331
|
-
const { fieldIndex } = formAction;
|
332
|
-
assert(fieldIndex !== undefined);
|
333
|
-
formFieldState.hasLostFocusAtLeastOnce[fieldIndex] = true;
|
334
|
-
return;
|
335
|
-
}
|
336
|
-
formFieldState.hasLostFocusAtLeastOnce = true;
|
337
|
-
return;
|
338
|
-
}
|
339
|
-
assert(false);
|
340
|
-
})();
|
341
|
-
return Object.assign({}, state);
|
342
|
-
}, initialState);
|
35
|
+
return () => unsubscribe();
|
36
|
+
}, [api]);
|
37
|
+
const { advancedMsg, advancedMsgStr } = i18n;
|
343
38
|
const formState = useMemo(() => ({
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
switch (error.source.rule) {
|
357
|
-
case "requiredField":
|
358
|
-
return hasLostFocusAtLeastOnce;
|
359
|
-
case "passwordConfirmMatchesPassword":
|
360
|
-
return hasLostFocusAtLeastOnce;
|
361
|
-
}
|
362
|
-
assert(false);
|
363
|
-
case "passwordPolicy":
|
364
|
-
switch (error.source.name) {
|
365
|
-
case "length":
|
366
|
-
return hasLostFocusAtLeastOnce;
|
367
|
-
case "digits":
|
368
|
-
return hasLostFocusAtLeastOnce;
|
369
|
-
case "lowerCase":
|
370
|
-
return hasLostFocusAtLeastOnce;
|
371
|
-
case "upperCase":
|
372
|
-
return hasLostFocusAtLeastOnce;
|
373
|
-
case "specialChars":
|
374
|
-
return hasLostFocusAtLeastOnce;
|
375
|
-
case "notUsername":
|
376
|
-
return true;
|
377
|
-
case "notEmail":
|
378
|
-
return true;
|
379
|
-
}
|
380
|
-
assert(false);
|
381
|
-
case "validator":
|
382
|
-
switch (error.source.name) {
|
383
|
-
case "length":
|
384
|
-
return hasLostFocusAtLeastOnce;
|
385
|
-
case "pattern":
|
386
|
-
return hasLostFocusAtLeastOnce;
|
387
|
-
case "email":
|
388
|
-
return hasLostFocusAtLeastOnce;
|
389
|
-
case "integer":
|
390
|
-
return hasLostFocusAtLeastOnce;
|
391
|
-
case "multivalued":
|
392
|
-
return hasLostFocusAtLeastOnce;
|
393
|
-
case "options":
|
394
|
-
return hasLostFocusAtLeastOnce;
|
395
|
-
}
|
396
|
-
assert(false);
|
397
|
-
}
|
398
|
-
}), attribute }, valueOrValuesWrap));
|
399
|
-
}),
|
400
|
-
isFormSubmittable: state.formFieldStates.every(({ errors }) => errors.length === 0)
|
401
|
-
}), [state]);
|
39
|
+
isFormSubmittable: formState_reactless.isFormSubmittable,
|
40
|
+
formFieldStates: formState_reactless.formFieldStates.map(formFieldState_reactless => ({
|
41
|
+
attribute: formFieldState_reactless.attribute,
|
42
|
+
valueOrValues: formFieldState_reactless.valueOrValues,
|
43
|
+
displayableErrors: formFieldState_reactless.displayableErrors.map((formFieldError_reactless, i) => ({
|
44
|
+
errorMessage: (_jsx(Fragment, { children: advancedMsg(...formFieldError_reactless.advancedMsgArgs) }, `${formFieldState_reactless.attribute.name}-${i}`)),
|
45
|
+
errorMessageStr: advancedMsgStr(...formFieldError_reactless.advancedMsgArgs),
|
46
|
+
source: formFieldError_reactless.source,
|
47
|
+
fieldIndex: formFieldError_reactless.fieldIndex
|
48
|
+
}))
|
49
|
+
}))
|
50
|
+
}), [formState_reactless]);
|
402
51
|
return {
|
403
52
|
formState,
|
404
|
-
dispatchFormAction
|
53
|
+
dispatchFormAction: api.dispatchFormAction
|
405
54
|
};
|
406
55
|
}
|
407
|
-
assert();
|
408
|
-
function useGetErrors(params) {
|
409
|
-
const { kcContext, i18n } = params;
|
410
|
-
const { messagesPerField, passwordPolicies } = kcContext;
|
411
|
-
const { msg, msgStr, advancedMsg, advancedMsgStr } = i18n;
|
412
|
-
const getErrors = useConstCallback((params) => {
|
413
|
-
var _a, _b;
|
414
|
-
const { attributeName, formFieldStates } = params;
|
415
|
-
const formFieldState = formFieldStates.find(({ attribute }) => attribute.name === attributeName);
|
416
|
-
assert(formFieldState !== undefined);
|
417
|
-
const { attribute } = formFieldState;
|
418
|
-
const valueOrValues = (() => {
|
419
|
-
var _a;
|
420
|
-
let { valueOrValues } = formFieldState;
|
421
|
-
unFormat_number: {
|
422
|
-
const { kcNumberUnFormat } = (_a = attribute.html5DataAnnotations) !== null && _a !== void 0 ? _a : {};
|
423
|
-
if (!kcNumberUnFormat) {
|
424
|
-
break unFormat_number;
|
425
|
-
}
|
426
|
-
if (valueOrValues instanceof Array) {
|
427
|
-
valueOrValues = valueOrValues.map(value => formatNumber(value, kcNumberUnFormat));
|
428
|
-
}
|
429
|
-
else {
|
430
|
-
valueOrValues = formatNumber(valueOrValues, kcNumberUnFormat);
|
431
|
-
}
|
432
|
-
}
|
433
|
-
return valueOrValues;
|
434
|
-
})();
|
435
|
-
assert(attribute !== undefined);
|
436
|
-
server_side_error: {
|
437
|
-
if (attribute.multivalued) {
|
438
|
-
const defaultValues = ((_a = attribute.values) === null || _a === void 0 ? void 0 : _a.length) ? attribute.values : [""];
|
439
|
-
assert(valueOrValues instanceof Array);
|
440
|
-
const values = valueOrValues;
|
441
|
-
if (JSON.stringify(defaultValues) !== JSON.stringify(values.slice(0, defaultValues.length))) {
|
442
|
-
break server_side_error;
|
443
|
-
}
|
444
|
-
}
|
445
|
-
else {
|
446
|
-
const defaultValue = (_b = attribute.value) !== null && _b !== void 0 ? _b : "";
|
447
|
-
assert(typeof valueOrValues === "string");
|
448
|
-
const value = valueOrValues;
|
449
|
-
if (defaultValue !== value) {
|
450
|
-
break server_side_error;
|
451
|
-
}
|
452
|
-
}
|
453
|
-
let doesErrorExist;
|
454
|
-
try {
|
455
|
-
doesErrorExist = messagesPerField.existsError(attributeName);
|
456
|
-
}
|
457
|
-
catch (_c) {
|
458
|
-
break server_side_error;
|
459
|
-
}
|
460
|
-
if (!doesErrorExist) {
|
461
|
-
break server_side_error;
|
462
|
-
}
|
463
|
-
const errorMessageStr = messagesPerField.get(attributeName);
|
464
|
-
return [
|
465
|
-
{
|
466
|
-
errorMessageStr,
|
467
|
-
errorMessage: (_jsx("span", { dangerouslySetInnerHTML: {
|
468
|
-
__html: kcSanitize(errorMessageStr)
|
469
|
-
} }, 0)),
|
470
|
-
fieldIndex: undefined,
|
471
|
-
source: {
|
472
|
-
type: "server"
|
473
|
-
}
|
474
|
-
}
|
475
|
-
];
|
476
|
-
}
|
477
|
-
handle_multi_valued_multi_fields: {
|
478
|
-
if (!attribute.multivalued) {
|
479
|
-
break handle_multi_valued_multi_fields;
|
480
|
-
}
|
481
|
-
if (getIsMultivaluedSingleField({ attribute })) {
|
482
|
-
break handle_multi_valued_multi_fields;
|
483
|
-
}
|
484
|
-
assert(valueOrValues instanceof Array);
|
485
|
-
const values = valueOrValues;
|
486
|
-
const errors = values
|
487
|
-
.map((...[, index]) => {
|
488
|
-
const specificValueErrors = getErrors({
|
489
|
-
attributeName,
|
490
|
-
formFieldStates: formFieldStates.map(formFieldState => {
|
491
|
-
if (formFieldState.attribute.name === attributeName) {
|
492
|
-
assert(formFieldState.valueOrValues instanceof Array);
|
493
|
-
return {
|
494
|
-
attribute: Object.assign(Object.assign({}, attribute), { annotations: Object.assign(Object.assign({}, attribute.annotations), { inputType: undefined }), multivalued: false }),
|
495
|
-
valueOrValues: formFieldState.valueOrValues[index]
|
496
|
-
};
|
497
|
-
}
|
498
|
-
return formFieldState;
|
499
|
-
})
|
500
|
-
});
|
501
|
-
return specificValueErrors
|
502
|
-
.filter(error => {
|
503
|
-
if (error.source.type === "other" && error.source.rule === "requiredField") {
|
504
|
-
return false;
|
505
|
-
}
|
506
|
-
return true;
|
507
|
-
})
|
508
|
-
.map((error) => (Object.assign(Object.assign({}, error), { fieldIndex: index })));
|
509
|
-
})
|
510
|
-
.reduce((acc, errors) => [...acc, ...errors], []);
|
511
|
-
required_field: {
|
512
|
-
if (!attribute.required) {
|
513
|
-
break required_field;
|
514
|
-
}
|
515
|
-
if (values.every(value => value !== "")) {
|
516
|
-
break required_field;
|
517
|
-
}
|
518
|
-
const msgArgs = ["error-user-attribute-required"];
|
519
|
-
errors.push({
|
520
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
521
|
-
errorMessageStr: msgStr(...msgArgs),
|
522
|
-
fieldIndex: undefined,
|
523
|
-
source: {
|
524
|
-
type: "other",
|
525
|
-
rule: "requiredField"
|
526
|
-
}
|
527
|
-
});
|
528
|
-
}
|
529
|
-
return errors;
|
530
|
-
}
|
531
|
-
handle_multi_valued_single_field: {
|
532
|
-
if (!attribute.multivalued) {
|
533
|
-
break handle_multi_valued_single_field;
|
534
|
-
}
|
535
|
-
if (!getIsMultivaluedSingleField({ attribute })) {
|
536
|
-
break handle_multi_valued_single_field;
|
537
|
-
}
|
538
|
-
const validatorName = "multivalued";
|
539
|
-
const validator = attribute.validators[validatorName];
|
540
|
-
if (validator === undefined) {
|
541
|
-
return [];
|
542
|
-
}
|
543
|
-
const { min: minStr } = validator;
|
544
|
-
const min = minStr ? parseInt(`${minStr}`) : attribute.required ? 1 : 0;
|
545
|
-
assert(!isNaN(min));
|
546
|
-
const { max: maxStr } = validator;
|
547
|
-
const max = !maxStr ? Infinity : parseInt(`${maxStr}`);
|
548
|
-
assert(!isNaN(max));
|
549
|
-
assert(valueOrValues instanceof Array);
|
550
|
-
const values = valueOrValues;
|
551
|
-
if (min <= values.length && values.length <= max) {
|
552
|
-
return [];
|
553
|
-
}
|
554
|
-
const msgArgs = ["error-invalid-multivalued-size", `${min}`, `${max}`];
|
555
|
-
return [
|
556
|
-
{
|
557
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, 0),
|
558
|
-
errorMessageStr: msgStr(...msgArgs),
|
559
|
-
fieldIndex: undefined,
|
560
|
-
source: {
|
561
|
-
type: "validator",
|
562
|
-
name: validatorName
|
563
|
-
}
|
564
|
-
}
|
565
|
-
];
|
566
|
-
}
|
567
|
-
assert(typeof valueOrValues === "string");
|
568
|
-
const value = valueOrValues;
|
569
|
-
const errors = [];
|
570
|
-
check_password_policies: {
|
571
|
-
if (attributeName !== "password") {
|
572
|
-
break check_password_policies;
|
573
|
-
}
|
574
|
-
if (passwordPolicies === undefined) {
|
575
|
-
break check_password_policies;
|
576
|
-
}
|
577
|
-
check_password_policy_x: {
|
578
|
-
const policyName = "length";
|
579
|
-
const policy = passwordPolicies[policyName];
|
580
|
-
if (!policy) {
|
581
|
-
break check_password_policy_x;
|
582
|
-
}
|
583
|
-
const minLength = policy;
|
584
|
-
if (value.length >= minLength) {
|
585
|
-
break check_password_policy_x;
|
586
|
-
}
|
587
|
-
const msgArgs = ["invalidPasswordMinLengthMessage", `${minLength}`];
|
588
|
-
errors.push({
|
589
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
590
|
-
errorMessageStr: msgStr(...msgArgs),
|
591
|
-
fieldIndex: undefined,
|
592
|
-
source: {
|
593
|
-
type: "passwordPolicy",
|
594
|
-
name: policyName
|
595
|
-
}
|
596
|
-
});
|
597
|
-
}
|
598
|
-
check_password_policy_x: {
|
599
|
-
const policyName = "digits";
|
600
|
-
const policy = passwordPolicies[policyName];
|
601
|
-
if (!policy) {
|
602
|
-
break check_password_policy_x;
|
603
|
-
}
|
604
|
-
const minNumberOfDigits = policy;
|
605
|
-
if (value.split("").filter(char => !isNaN(parseInt(char))).length >= minNumberOfDigits) {
|
606
|
-
break check_password_policy_x;
|
607
|
-
}
|
608
|
-
const msgArgs = ["invalidPasswordMinDigitsMessage", `${minNumberOfDigits}`];
|
609
|
-
errors.push({
|
610
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
611
|
-
errorMessageStr: msgStr(...msgArgs),
|
612
|
-
fieldIndex: undefined,
|
613
|
-
source: {
|
614
|
-
type: "passwordPolicy",
|
615
|
-
name: policyName
|
616
|
-
}
|
617
|
-
});
|
618
|
-
}
|
619
|
-
check_password_policy_x: {
|
620
|
-
const policyName = "lowerCase";
|
621
|
-
const policy = passwordPolicies[policyName];
|
622
|
-
if (!policy) {
|
623
|
-
break check_password_policy_x;
|
624
|
-
}
|
625
|
-
const minNumberOfLowerCaseChar = policy;
|
626
|
-
if (value.split("").filter(char => char === char.toLowerCase() && char !== char.toUpperCase()).length >= minNumberOfLowerCaseChar) {
|
627
|
-
break check_password_policy_x;
|
628
|
-
}
|
629
|
-
const msgArgs = ["invalidPasswordMinLowerCaseCharsMessage", `${minNumberOfLowerCaseChar}`];
|
630
|
-
errors.push({
|
631
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
632
|
-
errorMessageStr: msgStr(...msgArgs),
|
633
|
-
fieldIndex: undefined,
|
634
|
-
source: {
|
635
|
-
type: "passwordPolicy",
|
636
|
-
name: policyName
|
637
|
-
}
|
638
|
-
});
|
639
|
-
}
|
640
|
-
check_password_policy_x: {
|
641
|
-
const policyName = "upperCase";
|
642
|
-
const policy = passwordPolicies[policyName];
|
643
|
-
if (!policy) {
|
644
|
-
break check_password_policy_x;
|
645
|
-
}
|
646
|
-
const minNumberOfUpperCaseChar = policy;
|
647
|
-
if (value.split("").filter(char => char === char.toUpperCase() && char !== char.toLowerCase()).length >= minNumberOfUpperCaseChar) {
|
648
|
-
break check_password_policy_x;
|
649
|
-
}
|
650
|
-
const msgArgs = ["invalidPasswordMinUpperCaseCharsMessage", `${minNumberOfUpperCaseChar}`];
|
651
|
-
errors.push({
|
652
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
653
|
-
errorMessageStr: msgStr(...msgArgs),
|
654
|
-
fieldIndex: undefined,
|
655
|
-
source: {
|
656
|
-
type: "passwordPolicy",
|
657
|
-
name: policyName
|
658
|
-
}
|
659
|
-
});
|
660
|
-
}
|
661
|
-
check_password_policy_x: {
|
662
|
-
const policyName = "specialChars";
|
663
|
-
const policy = passwordPolicies[policyName];
|
664
|
-
if (!policy) {
|
665
|
-
break check_password_policy_x;
|
666
|
-
}
|
667
|
-
const minNumberOfSpecialChar = policy;
|
668
|
-
if (value.split("").filter(char => !char.match(/[a-zA-Z0-9]/)).length >= minNumberOfSpecialChar) {
|
669
|
-
break check_password_policy_x;
|
670
|
-
}
|
671
|
-
const msgArgs = ["invalidPasswordMinSpecialCharsMessage", `${minNumberOfSpecialChar}`];
|
672
|
-
errors.push({
|
673
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
674
|
-
errorMessageStr: msgStr(...msgArgs),
|
675
|
-
fieldIndex: undefined,
|
676
|
-
source: {
|
677
|
-
type: "passwordPolicy",
|
678
|
-
name: policyName
|
679
|
-
}
|
680
|
-
});
|
681
|
-
}
|
682
|
-
check_password_policy_x: {
|
683
|
-
const policyName = "notUsername";
|
684
|
-
const notUsername = passwordPolicies[policyName];
|
685
|
-
if (!notUsername) {
|
686
|
-
break check_password_policy_x;
|
687
|
-
}
|
688
|
-
const usernameFormFieldState = formFieldStates.find(formFieldState => formFieldState.attribute.name === "username");
|
689
|
-
if (!usernameFormFieldState) {
|
690
|
-
break check_password_policy_x;
|
691
|
-
}
|
692
|
-
const usernameValue = (() => {
|
693
|
-
var _a;
|
694
|
-
let { valueOrValues } = usernameFormFieldState;
|
695
|
-
assert(typeof valueOrValues === "string");
|
696
|
-
unFormat_number: {
|
697
|
-
const { kcNumberUnFormat } = (_a = attribute.html5DataAnnotations) !== null && _a !== void 0 ? _a : {};
|
698
|
-
if (!kcNumberUnFormat) {
|
699
|
-
break unFormat_number;
|
700
|
-
}
|
701
|
-
valueOrValues = formatNumber(valueOrValues, kcNumberUnFormat);
|
702
|
-
}
|
703
|
-
return valueOrValues;
|
704
|
-
})();
|
705
|
-
if (usernameValue === "") {
|
706
|
-
break check_password_policy_x;
|
707
|
-
}
|
708
|
-
if (value !== usernameValue) {
|
709
|
-
break check_password_policy_x;
|
710
|
-
}
|
711
|
-
const msgArgs = ["invalidPasswordNotUsernameMessage"];
|
712
|
-
errors.push({
|
713
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
714
|
-
errorMessageStr: msgStr(...msgArgs),
|
715
|
-
fieldIndex: undefined,
|
716
|
-
source: {
|
717
|
-
type: "passwordPolicy",
|
718
|
-
name: policyName
|
719
|
-
}
|
720
|
-
});
|
721
|
-
}
|
722
|
-
check_password_policy_x: {
|
723
|
-
const policyName = "notEmail";
|
724
|
-
const notEmail = passwordPolicies[policyName];
|
725
|
-
if (!notEmail) {
|
726
|
-
break check_password_policy_x;
|
727
|
-
}
|
728
|
-
const emailFormFieldState = formFieldStates.find(formFieldState => formFieldState.attribute.name === "email");
|
729
|
-
if (!emailFormFieldState) {
|
730
|
-
break check_password_policy_x;
|
731
|
-
}
|
732
|
-
assert(typeof emailFormFieldState.valueOrValues === "string");
|
733
|
-
{
|
734
|
-
const emailValue = emailFormFieldState.valueOrValues;
|
735
|
-
if (emailValue === "") {
|
736
|
-
break check_password_policy_x;
|
737
|
-
}
|
738
|
-
if (value !== emailValue) {
|
739
|
-
break check_password_policy_x;
|
740
|
-
}
|
741
|
-
}
|
742
|
-
const msgArgs = ["invalidPasswordNotEmailMessage"];
|
743
|
-
errors.push({
|
744
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
745
|
-
errorMessageStr: msgStr(...msgArgs),
|
746
|
-
fieldIndex: undefined,
|
747
|
-
source: {
|
748
|
-
type: "passwordPolicy",
|
749
|
-
name: policyName
|
750
|
-
}
|
751
|
-
});
|
752
|
-
}
|
753
|
-
}
|
754
|
-
password_confirm_matches_password: {
|
755
|
-
if (attributeName !== "password-confirm") {
|
756
|
-
break password_confirm_matches_password;
|
757
|
-
}
|
758
|
-
const passwordFormFieldState = formFieldStates.find(formFieldState => formFieldState.attribute.name === "password");
|
759
|
-
assert(passwordFormFieldState !== undefined);
|
760
|
-
assert(typeof passwordFormFieldState.valueOrValues === "string");
|
761
|
-
{
|
762
|
-
const passwordValue = passwordFormFieldState.valueOrValues;
|
763
|
-
if (value === passwordValue) {
|
764
|
-
break password_confirm_matches_password;
|
765
|
-
}
|
766
|
-
}
|
767
|
-
const msgArgs = ["invalidPasswordConfirmMessage"];
|
768
|
-
errors.push({
|
769
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
770
|
-
errorMessageStr: msgStr(...msgArgs),
|
771
|
-
fieldIndex: undefined,
|
772
|
-
source: {
|
773
|
-
type: "other",
|
774
|
-
rule: "passwordConfirmMatchesPassword"
|
775
|
-
}
|
776
|
-
});
|
777
|
-
}
|
778
|
-
const { validators } = attribute;
|
779
|
-
required_field: {
|
780
|
-
if (!attribute.required) {
|
781
|
-
break required_field;
|
782
|
-
}
|
783
|
-
if (value !== "") {
|
784
|
-
break required_field;
|
785
|
-
}
|
786
|
-
const msgArgs = ["error-user-attribute-required"];
|
787
|
-
errors.push({
|
788
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
789
|
-
errorMessageStr: msgStr(...msgArgs),
|
790
|
-
fieldIndex: undefined,
|
791
|
-
source: {
|
792
|
-
type: "other",
|
793
|
-
rule: "requiredField"
|
794
|
-
}
|
795
|
-
});
|
796
|
-
}
|
797
|
-
validator_x: {
|
798
|
-
const validatorName = "length";
|
799
|
-
const validator = validators[validatorName];
|
800
|
-
if (!validator) {
|
801
|
-
break validator_x;
|
802
|
-
}
|
803
|
-
const { "ignore.empty.value": ignoreEmptyValue = false, max, min } = validator;
|
804
|
-
if (ignoreEmptyValue && value === "") {
|
805
|
-
break validator_x;
|
806
|
-
}
|
807
|
-
const source = {
|
808
|
-
type: "validator",
|
809
|
-
name: validatorName
|
810
|
-
};
|
811
|
-
if (max && value.length > parseInt(`${max}`)) {
|
812
|
-
const msgArgs = ["error-invalid-length-too-long", `${max}`];
|
813
|
-
errors.push({
|
814
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
815
|
-
errorMessageStr: msgStr(...msgArgs),
|
816
|
-
fieldIndex: undefined,
|
817
|
-
source
|
818
|
-
});
|
819
|
-
}
|
820
|
-
if (min && value.length < parseInt(`${min}`)) {
|
821
|
-
const msgArgs = ["error-invalid-length-too-short", `${min}`];
|
822
|
-
errors.push({
|
823
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
824
|
-
errorMessageStr: msgStr(...msgArgs),
|
825
|
-
fieldIndex: undefined,
|
826
|
-
source
|
827
|
-
});
|
828
|
-
}
|
829
|
-
}
|
830
|
-
validator_x: {
|
831
|
-
const validatorName = "pattern";
|
832
|
-
const validator = validators[validatorName];
|
833
|
-
if (validator === undefined) {
|
834
|
-
break validator_x;
|
835
|
-
}
|
836
|
-
const { "ignore.empty.value": ignoreEmptyValue = false, pattern, "error-message": errorMessageKey } = validator;
|
837
|
-
if (ignoreEmptyValue && value === "") {
|
838
|
-
break validator_x;
|
839
|
-
}
|
840
|
-
if (new RegExp(pattern).test(value)) {
|
841
|
-
break validator_x;
|
842
|
-
}
|
843
|
-
const msgArgs = [errorMessageKey !== null && errorMessageKey !== void 0 ? errorMessageKey : id("shouldMatchPattern"), pattern];
|
844
|
-
errors.push({
|
845
|
-
errorMessage: _jsx(Fragment, { children: advancedMsg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
846
|
-
errorMessageStr: advancedMsgStr(...msgArgs),
|
847
|
-
fieldIndex: undefined,
|
848
|
-
source: {
|
849
|
-
type: "validator",
|
850
|
-
name: validatorName
|
851
|
-
}
|
852
|
-
});
|
853
|
-
}
|
854
|
-
validator_x: {
|
855
|
-
{
|
856
|
-
const lastError = errors[errors.length - 1];
|
857
|
-
if (lastError !== undefined && lastError.source.type === "validator" && lastError.source.name === "pattern") {
|
858
|
-
break validator_x;
|
859
|
-
}
|
860
|
-
}
|
861
|
-
const validatorName = "email";
|
862
|
-
const validator = validators[validatorName];
|
863
|
-
if (validator === undefined) {
|
864
|
-
break validator_x;
|
865
|
-
}
|
866
|
-
const { "ignore.empty.value": ignoreEmptyValue = false } = validator;
|
867
|
-
if (ignoreEmptyValue && value === "") {
|
868
|
-
break validator_x;
|
869
|
-
}
|
870
|
-
if (emailRegexp.test(value)) {
|
871
|
-
break validator_x;
|
872
|
-
}
|
873
|
-
const msgArgs = [id("invalidEmailMessage")];
|
874
|
-
errors.push({
|
875
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
876
|
-
errorMessageStr: msgStr(...msgArgs),
|
877
|
-
fieldIndex: undefined,
|
878
|
-
source: {
|
879
|
-
type: "validator",
|
880
|
-
name: validatorName
|
881
|
-
}
|
882
|
-
});
|
883
|
-
}
|
884
|
-
validator_x: {
|
885
|
-
const validatorName = "integer";
|
886
|
-
const validator = validators[validatorName];
|
887
|
-
if (validator === undefined) {
|
888
|
-
break validator_x;
|
889
|
-
}
|
890
|
-
const { "ignore.empty.value": ignoreEmptyValue = false, max, min } = validator;
|
891
|
-
if (ignoreEmptyValue && value === "") {
|
892
|
-
break validator_x;
|
893
|
-
}
|
894
|
-
const intValue = parseInt(value);
|
895
|
-
const source = {
|
896
|
-
type: "validator",
|
897
|
-
name: validatorName
|
898
|
-
};
|
899
|
-
if (isNaN(intValue)) {
|
900
|
-
const msgArgs = ["mustBeAnInteger"];
|
901
|
-
errors.push({
|
902
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
903
|
-
errorMessageStr: msgStr(...msgArgs),
|
904
|
-
fieldIndex: undefined,
|
905
|
-
source
|
906
|
-
});
|
907
|
-
break validator_x;
|
908
|
-
}
|
909
|
-
if (max && intValue > parseInt(`${max}`)) {
|
910
|
-
const msgArgs = ["error-number-out-of-range-too-big", `${max}`];
|
911
|
-
errors.push({
|
912
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
913
|
-
errorMessageStr: msgStr(...msgArgs),
|
914
|
-
fieldIndex: undefined,
|
915
|
-
source
|
916
|
-
});
|
917
|
-
break validator_x;
|
918
|
-
}
|
919
|
-
if (min && intValue < parseInt(`${min}`)) {
|
920
|
-
const msgArgs = ["error-number-out-of-range-too-small", `${min}`];
|
921
|
-
errors.push({
|
922
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
923
|
-
errorMessageStr: msgStr(...msgArgs),
|
924
|
-
fieldIndex: undefined,
|
925
|
-
source
|
926
|
-
});
|
927
|
-
break validator_x;
|
928
|
-
}
|
929
|
-
}
|
930
|
-
validator_x: {
|
931
|
-
const validatorName = "options";
|
932
|
-
const validator = validators[validatorName];
|
933
|
-
if (validator === undefined) {
|
934
|
-
break validator_x;
|
935
|
-
}
|
936
|
-
if (value === "") {
|
937
|
-
break validator_x;
|
938
|
-
}
|
939
|
-
if (validator.options.indexOf(value) >= 0) {
|
940
|
-
break validator_x;
|
941
|
-
}
|
942
|
-
const msgArgs = [id("notAValidOption")];
|
943
|
-
errors.push({
|
944
|
-
errorMessage: _jsx(Fragment, { children: msg(...msgArgs) }, `${attributeName}-${errors.length}`),
|
945
|
-
errorMessageStr: msgStr(...msgArgs),
|
946
|
-
fieldIndex: undefined,
|
947
|
-
source: {
|
948
|
-
type: "validator",
|
949
|
-
name: validatorName
|
950
|
-
}
|
951
|
-
});
|
952
|
-
}
|
953
|
-
//TODO: Implement missing validators. See Validators type definition.
|
954
|
-
return errors;
|
955
|
-
});
|
956
|
-
return { getErrors };
|
957
|
-
}
|
958
|
-
function getIsMultivaluedSingleField(params) {
|
959
|
-
var _a, _b;
|
960
|
-
const { attribute } = params;
|
961
|
-
return (_b = (_a = attribute.annotations.inputType) === null || _a === void 0 ? void 0 : _a.startsWith("multiselect")) !== null && _b !== void 0 ? _b : false;
|
962
|
-
}
|
963
|
-
export function getButtonToDisplayForMultivaluedAttributeField(params) {
|
964
|
-
const { attribute, values, fieldIndex } = params;
|
965
|
-
const hasRemove = (() => {
|
966
|
-
if (values.length === 1) {
|
967
|
-
return false;
|
968
|
-
}
|
969
|
-
const minCount = (() => {
|
970
|
-
const { multivalued } = attribute.validators;
|
971
|
-
if (multivalued === undefined) {
|
972
|
-
return undefined;
|
973
|
-
}
|
974
|
-
const minStr = multivalued.min;
|
975
|
-
if (minStr === undefined) {
|
976
|
-
return undefined;
|
977
|
-
}
|
978
|
-
return parseInt(`${minStr}`);
|
979
|
-
})();
|
980
|
-
if (minCount === undefined) {
|
981
|
-
return true;
|
982
|
-
}
|
983
|
-
if (values.length === minCount) {
|
984
|
-
return false;
|
985
|
-
}
|
986
|
-
return true;
|
987
|
-
})();
|
988
|
-
const hasAdd = (() => {
|
989
|
-
if (fieldIndex + 1 !== values.length) {
|
990
|
-
return false;
|
991
|
-
}
|
992
|
-
const maxCount = (() => {
|
993
|
-
const { multivalued } = attribute.validators;
|
994
|
-
if (multivalued === undefined) {
|
995
|
-
return undefined;
|
996
|
-
}
|
997
|
-
const maxStr = multivalued.max;
|
998
|
-
if (maxStr === undefined) {
|
999
|
-
return undefined;
|
1000
|
-
}
|
1001
|
-
return parseInt(`${maxStr}`);
|
1002
|
-
})();
|
1003
|
-
if (maxCount === undefined) {
|
1004
|
-
return true;
|
1005
|
-
}
|
1006
|
-
return values.length !== maxCount;
|
1007
|
-
})();
|
1008
|
-
return { hasRemove, hasAdd };
|
1009
|
-
}
|
1010
56
|
//# sourceMappingURL=useUserProfileForm.js.map
|