keycloakify 10.0.0-rc.22 → 10.0.0-rc.24
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/PUBLIC_URL.d.ts +1 -1
- package/PUBLIC_URL.js +1 -1
- package/PUBLIC_URL.js.map +1 -1
- package/account/Fallback.js.map +1 -1
- package/account/Template.js +3 -3
- package/account/Template.js.map +1 -1
- package/account/i18n/baseMessages/index.js.map +1 -1
- package/account/i18n/i18n.js.map +1 -1
- package/account/index.d.ts +2 -2
- package/account/index.js +1 -2
- package/account/index.js.map +1 -1
- package/account/kcContext/KcContext.d.ts +12 -0
- package/account/kcContext/KcContext.js.map +1 -1
- package/account/kcContext/getKcContextMock.d.ts +24 -0
- package/account/kcContext/getKcContextMock.js +28 -0
- package/account/kcContext/getKcContextMock.js.map +1 -0
- package/account/kcContext/index.d.ts +2 -1
- package/account/kcContext/index.js +1 -1
- package/account/kcContext/index.js.map +1 -1
- package/account/kcContext/kcContextMocks.js +23 -91
- package/account/kcContext/kcContextMocks.js.map +1 -1
- package/account/pages/Account.js +1 -1
- package/account/pages/Account.js.map +1 -1
- package/account/pages/Applications.js +2 -2
- package/account/pages/Applications.js.map +1 -1
- package/account/pages/FederatedIdentity.js +1 -1
- package/account/pages/FederatedIdentity.js.map +1 -1
- package/account/pages/Log.js +1 -1
- package/account/pages/Log.js.map +1 -1
- package/account/pages/Password.js +6 -4
- package/account/pages/Password.js.map +1 -1
- package/account/pages/Sessions.js +1 -1
- package/account/pages/Sessions.js.map +1 -1
- package/account/pages/Totp.js +1 -1
- package/account/pages/Totp.js.map +1 -1
- package/bin/main.js +174 -162
- package/lib/BASE_URL.js.map +1 -1
- package/login/Fallback.js.map +1 -1
- package/login/Template.js +7 -7
- package/login/Template.js.map +1 -1
- package/login/UserProfileFormFields.js +24 -68
- package/login/UserProfileFormFields.js.map +1 -1
- package/login/i18n/baseMessages/index.js.map +1 -1
- package/login/i18n/i18n.d.ts +1 -1
- package/login/i18n/i18n.js +1 -1
- package/login/i18n/i18n.js.map +1 -1
- package/login/index.d.ts +2 -3
- package/login/index.js +1 -2
- package/login/index.js.map +1 -1
- package/login/kcContext/KcContext.d.ts +23 -13
- package/login/kcContext/KcContext.js.map +1 -1
- package/login/kcContext/getKcContextMock.d.ts +24 -0
- package/login/kcContext/getKcContextMock.js +28 -0
- package/login/kcContext/getKcContextMock.js.map +1 -0
- package/login/kcContext/index.d.ts +2 -1
- package/login/kcContext/index.js +1 -1
- package/login/kcContext/index.js.map +1 -1
- package/login/kcContext/kcContextMocks.js +29 -103
- package/login/kcContext/kcContextMocks.js.map +1 -1
- package/login/lib/useDownloadTerms.js +8 -14
- package/login/lib/useDownloadTerms.js.map +1 -1
- package/login/lib/useGetClassName.js +1 -1
- package/login/lib/useGetClassName.js.map +1 -1
- package/login/lib/useUserProfileForm.d.ts +9 -1
- package/login/lib/useUserProfileForm.js +94 -15
- package/login/lib/useUserProfileForm.js.map +1 -1
- package/login/pages/Code.js +1 -1
- package/login/pages/Code.js.map +1 -1
- package/login/pages/DeleteAccountConfirm.js +2 -2
- package/login/pages/DeleteAccountConfirm.js.map +1 -1
- package/login/pages/DeleteCredential.js +1 -1
- package/login/pages/DeleteCredential.js.map +1 -1
- package/login/pages/Error.js +1 -1
- package/login/pages/Error.js.map +1 -1
- package/login/pages/FrontchannelLogout.js +1 -1
- package/login/pages/FrontchannelLogout.js.map +1 -1
- package/login/pages/IdpReviewUserProfile.js +1 -1
- package/login/pages/IdpReviewUserProfile.js.map +1 -1
- package/login/pages/Info.js +5 -5
- package/login/pages/Info.js.map +1 -1
- package/login/pages/Login.js +4 -4
- package/login/pages/Login.js.map +1 -1
- package/login/pages/LoginConfigTotp.js +2 -2
- package/login/pages/LoginConfigTotp.js.map +1 -1
- package/login/pages/LoginIdpLinkConfirm.js +1 -1
- package/login/pages/LoginIdpLinkConfirm.js.map +1 -1
- package/login/pages/LoginIdpLinkEmail.js +1 -1
- package/login/pages/LoginIdpLinkEmail.js.map +1 -1
- package/login/pages/LoginOauth2DeviceVerifyUserCode.js +1 -1
- package/login/pages/LoginOauth2DeviceVerifyUserCode.js.map +1 -1
- package/login/pages/LoginOauthGrant.js +2 -2
- package/login/pages/LoginOauthGrant.js.map +1 -1
- package/login/pages/LoginOtp.js +1 -1
- package/login/pages/LoginOtp.js.map +1 -1
- package/login/pages/LoginPageExpired.js +1 -1
- package/login/pages/LoginPageExpired.js.map +1 -1
- package/login/pages/LoginPassword.js +3 -3
- package/login/pages/LoginPassword.js.map +1 -1
- package/login/pages/LoginRecoveryAuthnCodeConfig.js +10 -10
- package/login/pages/LoginRecoveryAuthnCodeConfig.js.map +1 -1
- package/login/pages/LoginRecoveryAuthnCodeInput.js +1 -1
- package/login/pages/LoginRecoveryAuthnCodeInput.js.map +1 -1
- package/login/pages/LoginResetOtp.js +1 -1
- package/login/pages/LoginResetOtp.js.map +1 -1
- package/login/pages/LoginResetPassword.js +2 -2
- package/login/pages/LoginResetPassword.js.map +1 -1
- package/login/pages/LoginUpdatePassword.js +3 -3
- package/login/pages/LoginUpdatePassword.js.map +1 -1
- package/login/pages/LoginUpdateProfile.js +4 -2
- package/login/pages/LoginUpdateProfile.js.map +1 -1
- package/login/pages/LoginUsername.js +3 -3
- package/login/pages/LoginUsername.js.map +1 -1
- package/login/pages/LoginVerifyEmail.js +1 -1
- package/login/pages/LoginVerifyEmail.js.map +1 -1
- package/login/pages/LoginX509Info.js +1 -1
- package/login/pages/LoginX509Info.js.map +1 -1
- package/login/pages/LogoutConfirm.js +1 -1
- package/login/pages/LogoutConfirm.js.map +1 -1
- package/login/pages/Register.js +8 -4
- package/login/pages/Register.js.map +1 -1
- package/login/pages/SamlPostForm.js +1 -1
- package/login/pages/SamlPostForm.js.map +1 -1
- package/login/pages/SelectAuthenticator.js +2 -2
- package/login/pages/SelectAuthenticator.js.map +1 -1
- package/login/pages/Terms.js +1 -1
- package/login/pages/Terms.js.map +1 -1
- package/login/pages/UpdateEmail.js +5 -3
- package/login/pages/UpdateEmail.js.map +1 -1
- package/login/pages/WebauthnAuthenticate.js +8 -8
- package/login/pages/WebauthnAuthenticate.js.map +1 -1
- package/login/pages/WebauthnError.js +2 -2
- package/login/pages/WebauthnError.js.map +1 -1
- package/login/pages/WebauthnRegister.js +5 -5
- package/login/pages/WebauthnRegister.js.map +1 -1
- package/package.json +26 -38
- package/src/PUBLIC_URL.ts +1 -1
- package/src/account/Template.tsx +2 -3
- package/src/account/index.ts +2 -2
- package/src/account/kcContext/KcContext.ts +19 -1
- package/src/account/kcContext/getKcContextMock.ts +80 -0
- package/src/account/kcContext/index.ts +2 -1
- package/src/account/kcContext/kcContextMocks.ts +26 -91
- package/src/bin/copy-keycloak-resources-to-public.ts +1 -4
- package/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl +19 -11
- package/src/bin/start-keycloak/start-keycloak.ts +18 -5
- package/src/bin/tools/getNpmWorkspaceRootDirPath.ts +25 -25
- package/src/login/Template.tsx +4 -5
- package/src/login/UserProfileFormFields.tsx +28 -80
- package/src/login/i18n/i18n.tsx +3 -3
- package/src/login/index.ts +6 -3
- package/src/login/kcContext/KcContext.ts +43 -31
- package/src/login/kcContext/getKcContextMock.ts +80 -0
- package/src/login/kcContext/index.ts +7 -1
- package/src/login/kcContext/kcContextMocks.ts +92 -165
- package/src/login/lib/useDownloadTerms.ts +10 -24
- package/src/login/lib/useGetClassName.ts +1 -1
- package/src/login/lib/useUserProfileForm.tsx +117 -13
- package/src/login/pages/LoginConfigTotp.tsx +1 -1
- package/src/login/pages/LoginRecoveryAuthnCodeConfig.tsx +7 -8
- package/src/login/pages/WebauthnAuthenticate.tsx +2 -3
- package/src/login/pages/WebauthnRegister.tsx +2 -3
- package/src/tools/ExtractAfterStartingWith.ts +4 -0
- package/src/tools/StatefulObservable/hooks/useRerenderOnChange.ts +4 -4
- package/src/tools/ValueOf.ts +2 -0
- package/src/tools/deepAssign.ts +51 -20
- package/src/tools/structuredCloneButFunctions.ts +24 -0
- package/src/tools/useInsertLinkTags.ts +78 -87
- package/src/tools/useInsertScriptTags.ts +69 -78
- package/src/tools/useOnFirstMount.ts +18 -0
- package/tools/Array.prototype.every.js.map +1 -1
- package/tools/ExtractAfterStartingWith.d.ts +1 -0
- package/tools/ExtractAfterStartingWith.js +2 -0
- package/tools/ExtractAfterStartingWith.js.map +1 -0
- package/tools/HTMLElement.prototype.prepend.js.map +1 -1
- package/tools/StatefulObservable/StatefulObservable.js.map +1 -1
- package/tools/StatefulObservable/hooks/useRerenderOnChange.d.ts +1 -1
- package/tools/StatefulObservable/hooks/useRerenderOnChange.js +4 -4
- package/tools/StatefulObservable/hooks/useRerenderOnChange.js.map +1 -1
- package/tools/ValueOf.d.ts +2 -0
- package/tools/ValueOf.js +2 -0
- package/tools/ValueOf.js.map +1 -0
- package/tools/clsx.js.map +1 -1
- package/tools/deepAssign.d.ts +1 -0
- package/tools/deepAssign.js +39 -16
- package/tools/deepAssign.js.map +1 -1
- package/tools/formatNumber.js.map +1 -1
- package/tools/structuredCloneButFunctions.d.ts +7 -0
- package/tools/structuredCloneButFunctions.js +19 -0
- package/tools/structuredCloneButFunctions.js.map +1 -0
- package/tools/useInsertLinkTags.d.ts +11 -6
- package/tools/useInsertLinkTags.js +53 -53
- package/tools/useInsertLinkTags.js.map +1 -1
- package/tools/useInsertScriptTags.d.ts +15 -6
- package/tools/useInsertScriptTags.js +56 -64
- package/tools/useInsertScriptTags.js.map +1 -1
- package/tools/useOnFirstMount.d.ts +2 -0
- package/tools/useOnFirstMount.js +15 -0
- package/tools/useOnFirstMount.js.map +1 -0
- package/tools/useSetClassName.js.map +1 -1
- package/vite-plugin/index.js +66 -64
- package/account/kcContext/createGetKcContext.d.ts +0 -19
- package/account/kcContext/createGetKcContext.js +0 -78
- package/account/kcContext/createGetKcContext.js.map +0 -1
- package/account/kcContext/getKcContext.d.ts +0 -13
- package/account/kcContext/getKcContext.js +0 -13
- package/account/kcContext/getKcContext.js.map +0 -1
- package/account/kcContext/getKcContextFromWindow.d.ts +0 -10
- package/account/kcContext/getKcContextFromWindow.js +0 -5
- package/account/kcContext/getKcContextFromWindow.js.map +0 -1
- package/login/kcContext/createGetKcContext.d.ts +0 -19
- package/login/kcContext/createGetKcContext.js +0 -117
- package/login/kcContext/createGetKcContext.js.map +0 -1
- package/login/kcContext/getKcContext.d.ts +0 -13
- package/login/kcContext/getKcContext.js +0 -13
- package/login/kcContext/getKcContext.js.map +0 -1
- package/login/kcContext/getKcContextFromWindow.d.ts +0 -10
- package/login/kcContext/getKcContextFromWindow.js +0 -5
- package/login/kcContext/getKcContextFromWindow.js.map +0 -1
- package/src/account/kcContext/createGetKcContext.ts +0 -134
- package/src/account/kcContext/getKcContext.ts +0 -23
- package/src/account/kcContext/getKcContextFromWindow.ts +0 -15
- package/src/login/kcContext/createGetKcContext.ts +0 -206
- package/src/login/kcContext/getKcContext.ts +0 -23
- package/src/login/kcContext/getKcContextFromWindow.ts +0 -15
- package/src/tools/AndByDiscriminatingKey.ts +0 -31
- package/src/tools/deepClone.ts +0 -19
- package/src/tools/memoize.ts +0 -55
- package/tools/AndByDiscriminatingKey.d.ts +0 -5
- package/tools/AndByDiscriminatingKey.js +0 -2
- package/tools/AndByDiscriminatingKey.js.map +0 -1
- package/tools/deepClone.d.ts +0 -2
- package/tools/deepClone.js +0 -14
- package/tools/deepClone.js.map +0 -1
- package/tools/memoize.d.ts +0 -7
- package/tools/memoize.js +0 -38
- package/tools/memoize.js.map +0 -1
package/src/login/Template.tsx
CHANGED
@@ -3,15 +3,12 @@ import { assert } from "keycloakify/tools/assert";
|
|
3
3
|
import { clsx } from "keycloakify/tools/clsx";
|
4
4
|
import { type TemplateProps } from "keycloakify/login/TemplateProps";
|
5
5
|
import { useGetClassName } from "keycloakify/login/lib/useGetClassName";
|
6
|
-
import {
|
7
|
-
import {
|
6
|
+
import { useInsertScriptTags } from "keycloakify/tools/useInsertScriptTags";
|
7
|
+
import { useInsertLinkTags } from "keycloakify/tools/useInsertLinkTags";
|
8
8
|
import { useSetClassName } from "keycloakify/tools/useSetClassName";
|
9
9
|
import type { KcContext } from "./kcContext";
|
10
10
|
import type { I18n } from "./i18n";
|
11
11
|
|
12
|
-
const { useInsertLinkTags } = createUseInsertLinkTags();
|
13
|
-
const { useInsertScriptTags } = createUseInsertScriptTags();
|
14
|
-
|
15
12
|
export default function Template(props: TemplateProps<KcContext, I18n>) {
|
16
13
|
const {
|
17
14
|
displayInfo = false,
|
@@ -63,6 +60,7 @@ export default function Template(props: TemplateProps<KcContext, I18n>) {
|
|
63
60
|
}, []);
|
64
61
|
|
65
62
|
const { areAllStyleSheetsLoaded } = useInsertLinkTags({
|
63
|
+
componentOrHookName: "Template",
|
66
64
|
hrefs: !doUseDefaultCss
|
67
65
|
? []
|
68
66
|
: [
|
@@ -75,6 +73,7 @@ export default function Template(props: TemplateProps<KcContext, I18n>) {
|
|
75
73
|
});
|
76
74
|
|
77
75
|
const { insertScriptTags } = useInsertScriptTags({
|
76
|
+
componentOrHookName: "Template",
|
78
77
|
scriptTags: [
|
79
78
|
{
|
80
79
|
type: "module",
|
@@ -1,6 +1,12 @@
|
|
1
1
|
import { useEffect, useReducer, Fragment } from "react";
|
2
2
|
import type { ClassKey } from "keycloakify/login/TemplateProps";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
useUserProfileForm,
|
5
|
+
getButtonToDisplayForMultivaluedAttributeField,
|
6
|
+
type KcContextLike,
|
7
|
+
type FormAction,
|
8
|
+
type FormFieldError
|
9
|
+
} from "keycloakify/login/lib/useUserProfileForm";
|
4
10
|
import type { Attribute } from "keycloakify/login/kcContext/KcContext";
|
5
11
|
import { assert } from "tsafe/assert";
|
6
12
|
import type { I18n } from "./i18n";
|
@@ -413,92 +419,34 @@ function AddRemoveButtonsMultiValuedAttribute(props: {
|
|
413
419
|
|
414
420
|
const { msg } = i18n;
|
415
421
|
|
416
|
-
const hasRemove = (
|
417
|
-
if (values.length === 1) {
|
418
|
-
return false;
|
419
|
-
}
|
420
|
-
|
421
|
-
const minCount = (() => {
|
422
|
-
const { multivalued } = attribute.validators;
|
423
|
-
|
424
|
-
if (multivalued === undefined) {
|
425
|
-
return undefined;
|
426
|
-
}
|
427
|
-
|
428
|
-
const minStr = multivalued.min;
|
429
|
-
|
430
|
-
if (minStr === undefined) {
|
431
|
-
return undefined;
|
432
|
-
}
|
433
|
-
|
434
|
-
return parseInt(`${minStr}`);
|
435
|
-
})();
|
436
|
-
|
437
|
-
if (minCount === undefined) {
|
438
|
-
return true;
|
439
|
-
}
|
440
|
-
|
441
|
-
if (values.length === minCount) {
|
442
|
-
return false;
|
443
|
-
}
|
444
|
-
|
445
|
-
return true;
|
446
|
-
})();
|
447
|
-
|
448
|
-
const hasAdd = (() => {
|
449
|
-
if (fieldIndex + 1 !== values.length) {
|
450
|
-
return false;
|
451
|
-
}
|
452
|
-
|
453
|
-
const maxCount = (() => {
|
454
|
-
const { multivalued } = attribute.validators;
|
455
|
-
|
456
|
-
if (multivalued === undefined) {
|
457
|
-
return undefined;
|
458
|
-
}
|
459
|
-
|
460
|
-
const maxStr = multivalued.max;
|
461
|
-
|
462
|
-
if (maxStr === undefined) {
|
463
|
-
return undefined;
|
464
|
-
}
|
422
|
+
const { hasAdd, hasRemove } = getButtonToDisplayForMultivaluedAttributeField({ attribute, values, fieldIndex });
|
465
423
|
|
466
|
-
|
467
|
-
})();
|
468
|
-
|
469
|
-
if (maxCount === undefined) {
|
470
|
-
return false;
|
471
|
-
}
|
472
|
-
|
473
|
-
if (values.length === maxCount) {
|
474
|
-
return false;
|
475
|
-
}
|
476
|
-
|
477
|
-
return true;
|
478
|
-
})();
|
424
|
+
const idPostfix = `-${attribute.name}-${fieldIndex + 1}`;
|
479
425
|
|
480
426
|
return (
|
481
427
|
<>
|
482
428
|
{hasRemove && (
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
429
|
+
<>
|
430
|
+
<button
|
431
|
+
id={`kc-remove${idPostfix}`}
|
432
|
+
type="button"
|
433
|
+
className="pf-c-button pf-m-inline pf-m-link"
|
434
|
+
onClick={() =>
|
435
|
+
dispatchFormAction({
|
436
|
+
action: "update",
|
437
|
+
name: attribute.name,
|
438
|
+
valueOrValues: values.filter((_, i) => i !== fieldIndex)
|
439
|
+
})
|
440
|
+
}
|
441
|
+
>
|
442
|
+
{msg("remove")}
|
443
|
+
</button>
|
444
|
+
{hasAdd ? <> | </> : null}
|
445
|
+
</>
|
498
446
|
)}
|
499
447
|
{hasAdd && (
|
500
448
|
<button
|
501
|
-
id=
|
449
|
+
id={`kc-add${idPostfix}`}
|
502
450
|
type="button"
|
503
451
|
className="pf-c-button pf-m-inline pf-m-link"
|
504
452
|
onClick={() =>
|
@@ -580,7 +528,7 @@ function InputTagSelects(props: InputFiledByTypeProps) {
|
|
580
528
|
className={classInput}
|
581
529
|
aria-invalid={props.displayableErrors.length !== 0}
|
582
530
|
disabled={attribute.readOnly}
|
583
|
-
checked={valueOrValues.includes(option)}
|
531
|
+
checked={valueOrValues instanceof Array ? valueOrValues.includes(option) : valueOrValues === option}
|
584
532
|
onChange={event =>
|
585
533
|
formValidationDispatch({
|
586
534
|
action: "update",
|
package/src/login/i18n/i18n.tsx
CHANGED
@@ -12,7 +12,7 @@ export type KcContextLike = {
|
|
12
12
|
currentLanguageTag: string;
|
13
13
|
supported: { languageTag: string; url: string; label: string }[];
|
14
14
|
};
|
15
|
-
__localizationRealmOverridesUserProfile
|
15
|
+
__localizationRealmOverridesUserProfile?: Record<string, string>;
|
16
16
|
};
|
17
17
|
|
18
18
|
assert<KcContext extends KcContextLike ? true : false>();
|
@@ -145,7 +145,7 @@ export function createUseI18n<ExtraMessageKey extends string = never>(extraMessa
|
|
145
145
|
function createI18nTranslationFunctions<MessageKey extends string>(params: {
|
146
146
|
fallbackMessages: Record<MessageKey, string>;
|
147
147
|
messages: Record<MessageKey, string>;
|
148
|
-
__localizationRealmOverridesUserProfile: Record<string, string
|
148
|
+
__localizationRealmOverridesUserProfile: Record<string, string> | undefined;
|
149
149
|
}): Pick<GenericI18n<MessageKey>, "msg" | "msgStr" | "advancedMsg" | "advancedMsgStr"> {
|
150
150
|
const { fallbackMessages, messages, __localizationRealmOverridesUserProfile } = params;
|
151
151
|
|
@@ -203,7 +203,7 @@ function createI18nTranslationFunctions<MessageKey extends string>(params: {
|
|
203
203
|
function resolveMsgAdvanced(props: { key: string; args: (string | undefined)[]; doRenderAsHtml: boolean }): JSX.Element | string {
|
204
204
|
const { key, args, doRenderAsHtml } = props;
|
205
205
|
|
206
|
-
if (key in __localizationRealmOverridesUserProfile) {
|
206
|
+
if (__localizationRealmOverridesUserProfile !== undefined && key in __localizationRealmOverridesUserProfile) {
|
207
207
|
const resolvedMessage = __localizationRealmOverridesUserProfile[key];
|
208
208
|
|
209
209
|
return doRenderAsHtml ? (
|
package/src/login/index.ts
CHANGED
@@ -3,9 +3,12 @@ import Fallback from "keycloakify/login/Fallback";
|
|
3
3
|
export default Fallback;
|
4
4
|
|
5
5
|
export { useDownloadTerms } from "keycloakify/login/lib/useDownloadTerms";
|
6
|
-
export { getKcContext } from "keycloakify/login/kcContext/getKcContext";
|
7
|
-
export { createGetKcContext } from "keycloakify/login/kcContext/createGetKcContext";
|
8
|
-
export type { LoginThemePageId as PageId } from "keycloakify/bin/shared/constants";
|
9
6
|
export { createUseI18n } from "keycloakify/login/i18n/i18n";
|
7
|
+
export type {
|
8
|
+
ExtendKcContext,
|
9
|
+
Attribute,
|
10
|
+
PasswordPolicies
|
11
|
+
} from "keycloakify/login/kcContext";
|
12
|
+
export { createGetKcContextMock } from "keycloakify/login/kcContext";
|
10
13
|
|
11
14
|
export type { PageProps } from "keycloakify/login/pages/PageProps";
|
@@ -3,14 +3,28 @@ import type {
|
|
3
3
|
LoginThemePageId,
|
4
4
|
nameOfTheLocalizationRealmOverridesUserProfileProperty
|
5
5
|
} from "keycloakify/bin/shared/constants";
|
6
|
+
import type { ExtractAfterStartingWith } from "keycloakify/tools/ExtractAfterStartingWith";
|
7
|
+
import type { ValueOf } from "keycloakify/tools/ValueOf";
|
6
8
|
import { assert } from "tsafe/assert";
|
7
9
|
import type { Equals } from "tsafe";
|
8
10
|
import type { MessageKey } from "../i18n/i18n";
|
9
11
|
|
10
|
-
type
|
11
|
-
|
12
|
-
|
13
|
-
> =
|
12
|
+
export type ExtendKcContext<
|
13
|
+
KcContextExtraProperties extends { properties?: Record<string, string | undefined> },
|
14
|
+
KcContextExtraPropertiesPerPage extends Record<string, Record<string, unknown>>
|
15
|
+
> = ValueOf<{
|
16
|
+
[PageId in keyof KcContextExtraPropertiesPerPage | KcContext["pageId"]]: Extract<
|
17
|
+
KcContext,
|
18
|
+
{ pageId: PageId }
|
19
|
+
> extends never
|
20
|
+
? KcContext.Common &
|
21
|
+
KcContextExtraProperties & {
|
22
|
+
pageId: PageId;
|
23
|
+
} & KcContextExtraPropertiesPerPage[PageId]
|
24
|
+
: Extract<KcContext, { pageId: PageId }> &
|
25
|
+
KcContextExtraProperties &
|
26
|
+
KcContextExtraPropertiesPerPage[PageId];
|
27
|
+
}>;
|
14
28
|
|
15
29
|
/** Take theses type definition with a grain of salt.
|
16
30
|
* Some values might be undefined on some pages.
|
@@ -138,13 +152,13 @@ export declare namespace KcContext {
|
|
138
152
|
|
139
153
|
getFirstError: (...fieldNames: string[]) => string;
|
140
154
|
};
|
141
|
-
properties: Record<string, string | undefined>;
|
142
155
|
authenticationSession?: {
|
143
156
|
authSessionId: string;
|
144
157
|
tabId: string;
|
145
158
|
ssoLoginInOtherTabsUrl: string;
|
146
159
|
};
|
147
|
-
|
160
|
+
properties: {};
|
161
|
+
__localizationRealmOverridesUserProfile?: Record<string, string>;
|
148
162
|
};
|
149
163
|
|
150
164
|
export type SamlPostForm = Common & {
|
@@ -585,7 +599,6 @@ export declare namespace KcContext {
|
|
585
599
|
}
|
586
600
|
|
587
601
|
export type UserProfile = {
|
588
|
-
attributes: Attribute[];
|
589
602
|
attributesByName: Record<string, Attribute>;
|
590
603
|
html5DataAnnotations?: Record<string, string>;
|
591
604
|
};
|
@@ -684,31 +697,31 @@ export type Attribute = {
|
|
684
697
|
| "photo";
|
685
698
|
};
|
686
699
|
|
687
|
-
export type Validators =
|
688
|
-
length
|
689
|
-
integer
|
690
|
-
email
|
691
|
-
pattern
|
692
|
-
options
|
693
|
-
multivalued
|
700
|
+
export type Validators = {
|
701
|
+
length?: Validators.DoIgnoreEmpty & Validators.Range;
|
702
|
+
integer?: Validators.DoIgnoreEmpty & Validators.Range;
|
703
|
+
email?: Validators.DoIgnoreEmpty;
|
704
|
+
pattern?: Validators.DoIgnoreEmpty & Validators.ErrorMessage & { pattern: string };
|
705
|
+
options?: Validators.Options;
|
706
|
+
multivalued?: Validators.DoIgnoreEmpty & Validators.Range;
|
694
707
|
// NOTE: Following are the validators for which we don't implement client side validation yet
|
695
708
|
// or for which the validation can't be performed on the client side.
|
696
709
|
/*
|
697
|
-
double
|
698
|
-
"up-immutable-attribute"
|
699
|
-
"up-attribute-required-by-metadata-value"
|
700
|
-
"up-username-has-value"
|
701
|
-
"up-duplicate-username"
|
702
|
-
"up-username-mutation"
|
703
|
-
"up-email-exists-as-username"
|
704
|
-
"up-blank-attribute-value"
|
705
|
-
"up-duplicate-email"
|
706
|
-
"local-date"
|
707
|
-
"person-name-prohibited-characters"
|
708
|
-
uri
|
709
|
-
"username-prohibited-characters"
|
710
|
+
double?: Validators.DoIgnoreEmpty & Validators.Range;
|
711
|
+
"up-immutable-attribute"?: {};
|
712
|
+
"up-attribute-required-by-metadata-value"?: {};
|
713
|
+
"up-username-has-value"?: {};
|
714
|
+
"up-duplicate-username"?: {};
|
715
|
+
"up-username-mutation"?: {};
|
716
|
+
"up-email-exists-as-username"?: {};
|
717
|
+
"up-blank-attribute-value"?: Validators.ErrorMessage & { "fail-on-null": boolean; };
|
718
|
+
"up-duplicate-email"?: {};
|
719
|
+
"local-date"?: Validators.DoIgnoreEmpty;
|
720
|
+
"person-name-prohibited-characters"?: Validators.DoIgnoreEmpty & Validators.ErrorMessage;
|
721
|
+
uri?: Validators.DoIgnoreEmpty;
|
722
|
+
"username-prohibited-characters"?: Validators.DoIgnoreEmpty & Validators.ErrorMessage;
|
710
723
|
*/
|
711
|
-
}
|
724
|
+
};
|
712
725
|
|
713
726
|
export declare namespace Validators {
|
714
727
|
export type DoIgnoreEmpty = {
|
@@ -757,9 +770,8 @@ export type PasswordPolicies = {
|
|
757
770
|
};
|
758
771
|
|
759
772
|
assert<
|
760
|
-
KcContext.Common extends
|
761
|
-
typeof nameOfTheLocalizationRealmOverridesUserProfileProperty,
|
762
|
-
unknown
|
773
|
+
KcContext.Common extends Partial<
|
774
|
+
Record<typeof nameOfTheLocalizationRealmOverridesUserProfileProperty, unknown>
|
763
775
|
>
|
764
776
|
? true
|
765
777
|
: false
|
@@ -0,0 +1,80 @@
|
|
1
|
+
import type { ExtendKcContext, KcContext as KcContextBase } from "./KcContext";
|
2
|
+
import type { LoginThemePageId } from "keycloakify/bin/shared/constants";
|
3
|
+
import type { DeepPartial } from "keycloakify/tools/DeepPartial";
|
4
|
+
import { deepAssign } from "keycloakify/tools/deepAssign";
|
5
|
+
import { structuredCloneButFunctions } from "keycloakify/tools/structuredCloneButFunctions";
|
6
|
+
import { kcContextMocks, kcContextCommonMock } from "./kcContextMocks";
|
7
|
+
import { exclude } from "tsafe/exclude";
|
8
|
+
|
9
|
+
export function createGetKcContextMock<
|
10
|
+
KcContextExtraProperties extends { properties?: Record<string, string | undefined> },
|
11
|
+
KcContextExtraPropertiesPerPage extends Record<
|
12
|
+
`${string}.ftl`,
|
13
|
+
Record<string, unknown>
|
14
|
+
>
|
15
|
+
>(params: {
|
16
|
+
kcContextExtraProperties: KcContextExtraProperties;
|
17
|
+
kcContextExtraPropertiesPerPage: KcContextExtraPropertiesPerPage;
|
18
|
+
overrides?: DeepPartial<KcContextExtraProperties & KcContextBase.Common>;
|
19
|
+
overridesPerPage?: {
|
20
|
+
[PageId in
|
21
|
+
| LoginThemePageId
|
22
|
+
| keyof KcContextExtraPropertiesPerPage]?: DeepPartial<
|
23
|
+
Extract<
|
24
|
+
ExtendKcContext<
|
25
|
+
KcContextExtraProperties,
|
26
|
+
KcContextExtraPropertiesPerPage
|
27
|
+
>,
|
28
|
+
{ pageId: PageId }
|
29
|
+
>
|
30
|
+
>;
|
31
|
+
};
|
32
|
+
}) {
|
33
|
+
const {
|
34
|
+
kcContextExtraProperties,
|
35
|
+
kcContextExtraPropertiesPerPage,
|
36
|
+
overrides: overrides_global,
|
37
|
+
overridesPerPage: overridesPerPage_global
|
38
|
+
} = params;
|
39
|
+
|
40
|
+
type KcContext = ExtendKcContext<
|
41
|
+
KcContextExtraProperties,
|
42
|
+
KcContextExtraPropertiesPerPage
|
43
|
+
>;
|
44
|
+
|
45
|
+
function getKcContextMock<
|
46
|
+
PageId extends LoginThemePageId | keyof KcContextExtraPropertiesPerPage
|
47
|
+
>(params: {
|
48
|
+
pageId: PageId;
|
49
|
+
overrides?: DeepPartial<Extract<KcContext, { pageId: PageId }>>;
|
50
|
+
}): Extract<KcContext, { pageId: PageId }> {
|
51
|
+
const { pageId, overrides } = params;
|
52
|
+
|
53
|
+
const kcContextMock = structuredCloneButFunctions(
|
54
|
+
kcContextMocks.find(kcContextMock => kcContextMock.pageId === pageId) ?? {
|
55
|
+
...kcContextCommonMock,
|
56
|
+
pageId
|
57
|
+
}
|
58
|
+
);
|
59
|
+
|
60
|
+
[
|
61
|
+
kcContextExtraProperties,
|
62
|
+
kcContextExtraPropertiesPerPage[pageId],
|
63
|
+
overrides_global,
|
64
|
+
overridesPerPage_global?.[pageId],
|
65
|
+
overrides
|
66
|
+
]
|
67
|
+
.filter(exclude(undefined))
|
68
|
+
.forEach(overrides =>
|
69
|
+
deepAssign({
|
70
|
+
target: kcContextMock,
|
71
|
+
source: overrides
|
72
|
+
})
|
73
|
+
);
|
74
|
+
|
75
|
+
// @ts-expect-error
|
76
|
+
return kcContextMock;
|
77
|
+
}
|
78
|
+
|
79
|
+
return { getKcContextMock };
|
80
|
+
}
|