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