keycloakify 10.0.0-rc.17 → 10.0.0-rc.19
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.js.map +1 -1
- package/account/Template.js +5 -5
- package/account/Template.js.map +1 -1
- package/account/i18n/i18n.js +37 -29
- package/account/i18n/i18n.js.map +1 -1
- package/account/kcContext/KcContext.js.map +1 -1
- package/account/kcContext/createGetKcContext.js +20 -15
- package/account/kcContext/createGetKcContext.js.map +1 -1
- package/account/kcContext/getKcContext.js.map +1 -1
- package/account/kcContext/getKcContextFromWindow.d.ts +3 -1
- package/account/kcContext/getKcContextFromWindow.js.map +1 -1
- package/account/kcContext/kcContextMocks.js +148 -144
- package/account/kcContext/kcContextMocks.js.map +1 -1
- package/account/lib/useGetClassName.js +14 -14
- package/account/lib/useGetClassName.js.map +1 -1
- package/account/pages/Account.js +1 -1
- package/account/pages/Account.js.map +1 -1
- package/account/pages/Password.js +7 -7
- package/account/pages/Password.js.map +1 -1
- package/account/pages/Totp.js +4 -4
- package/account/pages/Totp.js.map +1 -1
- package/bin/main.js +2265 -2028
- package/bin/shared/constants.d.ts +1 -0
- package/bin/shared/constants.js +4 -3
- package/bin/shared/constants.js.map +1 -1
- package/lib/isStorybook.js +2 -1
- package/lib/isStorybook.js.map +1 -1
- package/lib/useGetClassName.js.map +1 -1
- package/login/Template.js +13 -13
- package/login/Template.js.map +1 -1
- package/login/UserProfileFormFields.js +43 -41
- package/login/UserProfileFormFields.js.map +1 -1
- package/login/i18n/baseMessages/ca.d.ts +1 -1
- package/login/i18n/baseMessages/ca.js +1 -1
- package/login/i18n/baseMessages/el.d.ts +0 -1
- package/login/i18n/baseMessages/el.js +0 -1
- package/login/i18n/baseMessages/el.js.map +1 -1
- package/login/i18n/baseMessages/en.d.ts +1 -1
- package/login/i18n/baseMessages/en.js +1 -1
- package/login/i18n/baseMessages/es.d.ts +1 -1
- package/login/i18n/baseMessages/es.js +1 -1
- package/login/i18n/baseMessages/fa.d.ts +0 -1
- package/login/i18n/baseMessages/fa.js +0 -1
- package/login/i18n/baseMessages/fa.js.map +1 -1
- package/login/i18n/baseMessages/hu.d.ts +1 -1
- package/login/i18n/baseMessages/hu.js +1 -1
- package/login/i18n/baseMessages/index.d.ts +1 -2
- package/login/i18n/baseMessages/zh-CN.d.ts +1 -1
- package/login/i18n/baseMessages/zh-CN.js +1 -1
- package/login/i18n/i18n.js +39 -31
- package/login/i18n/i18n.js.map +1 -1
- package/login/kcContext/KcContext.js.map +1 -1
- package/login/kcContext/createGetKcContext.js +30 -22
- package/login/kcContext/createGetKcContext.js.map +1 -1
- package/login/kcContext/getKcContext.js.map +1 -1
- package/login/kcContext/getKcContextFromWindow.d.ts +3 -1
- package/login/kcContext/getKcContextFromWindow.js.map +1 -1
- package/login/kcContext/kcContextMocks.js +233 -231
- package/login/kcContext/kcContextMocks.js.map +1 -1
- package/login/lib/useDownloadTerms.js.map +1 -1
- package/login/lib/useGetClassName.js +112 -112
- package/login/lib/useGetClassName.js.map +1 -1
- package/login/lib/useUserProfileForm.js +181 -181
- package/login/lib/useUserProfileForm.js.map +1 -1
- package/login/pages/DeleteAccountConfirm.js +5 -1
- package/login/pages/DeleteAccountConfirm.js.map +1 -1
- package/login/pages/FrontchannelLogout.js +1 -1
- package/login/pages/FrontchannelLogout.js.map +1 -1
- package/login/pages/Login.js.map +1 -1
- package/login/pages/LoginRecoveryAuthnCodeConfig.js +3 -3
- package/login/pages/LoginRecoveryAuthnCodeConfig.js.map +1 -1
- package/login/pages/LoginResetPassword.js.map +1 -1
- package/login/pages/LoginUsername.js.map +1 -1
- package/login/pages/WebauthnAuthenticate.js +11 -8
- package/login/pages/WebauthnAuthenticate.js.map +1 -1
- package/login/pages/WebauthnRegister.js +7 -7
- package/login/pages/WebauthnRegister.js.map +1 -1
- package/package.json +232 -226
- package/src/PUBLIC_URL.ts +4 -1
- package/src/account/Template.tsx +5 -5
- package/src/account/TemplateProps.ts +4 -1
- package/src/account/i18n/i18n.tsx +40 -30
- package/src/account/kcContext/KcContext.ts +4 -1
- package/src/account/kcContext/createGetKcContext.ts +48 -22
- package/src/account/kcContext/getKcContext.ts +3 -1
- package/src/account/kcContext/getKcContextFromWindow.ts +6 -2
- package/src/account/kcContext/kcContextMocks.ts +164 -160
- package/src/account/lib/useGetClassName.ts +15 -14
- package/src/account/pages/Account.tsx +2 -2
- package/src/account/pages/Password.tsx +8 -8
- package/src/account/pages/Totp.tsx +4 -6
- package/src/bin/copy-keycloak-resources-to-public.ts +2 -2
- package/src/bin/download-keycloak-default-theme.ts +30 -8
- package/src/bin/eject-page.ts +48 -11
- package/src/bin/initialize-email-theme.ts +25 -17
- package/src/bin/keycloakify/buildJars/buildJar.ts +179 -104
- package/src/bin/keycloakify/buildJars/buildJars.ts +35 -16
- package/src/bin/keycloakify/buildJars/extensionVersions.ts +2 -1
- package/src/bin/keycloakify/buildJars/generatePom.ts +11 -3
- package/src/bin/keycloakify/buildJars/getKeycloakVersionRangeForJar.ts +33 -8
- package/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl +20 -2
- package/src/bin/keycloakify/generateFtl/generateFtl.ts +49 -12
- package/src/bin/keycloakify/generateSrcMainResources/bringInAccountV1.ts +29 -18
- package/src/bin/keycloakify/generateSrcMainResources/generateMessageProperties.ts +35 -12
- package/src/bin/keycloakify/generateSrcMainResources/generateSrcMainResources.ts +3 -1
- package/src/bin/keycloakify/generateSrcMainResources/generateSrcMainResourcesForMainTheme.ts +86 -41
- package/src/bin/keycloakify/generateSrcMainResources/generateSrcMainResourcesForThemeVariant.ts +39 -15
- package/src/bin/keycloakify/generateSrcMainResources/readExtraPageNames.ts +21 -7
- package/src/bin/keycloakify/generateSrcMainResources/readFieldNameUsage.ts +34 -7
- package/src/bin/keycloakify/generateStartKeycloakTestingContainer.ts +19 -5
- package/src/bin/keycloakify/keycloakify.ts +28 -9
- package/src/bin/keycloakify/replacers/replaceImportsInCssCode.ts +24 -5
- package/src/bin/keycloakify/replacers/replaceImportsInInlineCssCode.ts +6 -2
- package/src/bin/keycloakify/replacers/replaceImportsInJsCode/replaceImportsInJsCode.ts +6 -3
- package/src/bin/keycloakify/replacers/replaceImportsInJsCode/vite.ts +24 -6
- package/src/bin/keycloakify/replacers/replaceImportsInJsCode/webpack.ts +49 -11
- package/src/bin/main.ts +78 -41
- package/src/bin/shared/KeycloakVersionRange.ts +3 -1
- package/src/bin/shared/buildOptions.ts +70 -43
- package/src/bin/shared/constants.ts +4 -2
- package/src/bin/shared/copyKeycloakResourcesToPublic.ts +27 -13
- package/src/bin/shared/downloadKeycloakDefaultTheme.ts +161 -218
- package/src/bin/shared/downloadKeycloakStaticResources.ts +25 -21
- package/src/bin/shared/getJarFileBasename.ts +3 -1
- package/src/bin/shared/getThemeSrcDirPath.ts +5 -2
- package/src/bin/shared/metaInfKeycloakThemes.ts +35 -8
- package/src/bin/shared/promptKeycloakVersion.ts +33 -14
- package/src/bin/start-keycloak/appBuild.ts +128 -0
- package/src/bin/start-keycloak/index.ts +1 -0
- package/src/bin/start-keycloak/keycloakifyBuild.ts +41 -0
- package/src/bin/start-keycloak/myrealm-realm-23.json +2142 -0
- package/src/bin/start-keycloak/myrealm-realm-24.json +2318 -0
- package/src/bin/start-keycloak/start-keycloak.ts +469 -0
- package/src/bin/tools/SemVer.ts +32 -13
- package/src/bin/tools/String.prototype.replaceAll.ts +9 -2
- package/src/bin/tools/crawl.ts +4 -1
- package/src/bin/tools/crc32.ts +42 -24
- package/src/bin/tools/downloadAndExtractArchive/downloadAndExtractArchive.ts +262 -0
- package/src/bin/tools/downloadAndExtractArchive/fetchProxyOptions.ts +96 -0
- package/src/bin/tools/downloadAndExtractArchive/index.ts +1 -0
- package/src/bin/tools/extractArchive.ts +132 -0
- package/src/bin/tools/fetchProxyOptions.ts +31 -8
- package/src/bin/tools/getAbsoluteAndInOsFormatPath.ts +10 -2
- package/src/bin/tools/getNpmWorkspaceRootDirPath.ts +18 -5
- package/src/bin/tools/octokit-addons/getLatestsSemVersionedTag.ts +8 -2
- package/src/bin/tools/octokit-addons/listTags.ts +15 -4
- package/src/bin/tools/partitionPromiseSettledResults.ts +12 -3
- package/src/bin/tools/readThisNpmPackageVersion.ts +5 -1
- package/src/bin/tools/transformCodebase.ts +29 -10
- package/src/bin/tools/trimIndent.ts +4 -1
- package/src/lib/isStorybook.ts +3 -1
- package/src/lib/useGetClassName.ts +12 -3
- package/src/login/Template.tsx +14 -14
- package/src/login/TemplateProps.ts +4 -1
- package/src/login/UserProfileFormFields.tsx +44 -42
- package/src/login/i18n/baseMessages/ca.ts +1 -1
- package/src/login/i18n/baseMessages/el.ts +0 -1
- package/src/login/i18n/baseMessages/en.ts +1 -1
- package/src/login/i18n/baseMessages/es.ts +1 -1
- package/src/login/i18n/baseMessages/fa.ts +0 -1
- package/src/login/i18n/baseMessages/hu.ts +1 -1
- package/src/login/i18n/baseMessages/zh-CN.ts +1 -1
- package/src/login/i18n/i18n.tsx +42 -32
- package/src/login/kcContext/KcContext.ts +8 -2
- package/src/login/kcContext/createGetKcContext.ts +84 -37
- package/src/login/kcContext/getKcContext.ts +3 -1
- package/src/login/kcContext/getKcContextFromWindow.ts +6 -2
- package/src/login/kcContext/kcContextMocks.ts +339 -325
- package/src/login/lib/useDownloadTerms.ts +6 -4
- package/src/login/lib/useGetClassName.ts +119 -112
- package/src/login/lib/useUserProfileForm.tsx +219 -205
- package/src/login/pages/DeleteAccountConfirm.tsx +9 -3
- package/src/login/pages/FrontchannelLogout.tsx +1 -1
- package/src/login/pages/Login.tsx +2 -2
- package/src/login/pages/LoginRecoveryAuthnCodeConfig.tsx +3 -3
- package/src/login/pages/LoginResetPassword.tsx +2 -2
- package/src/login/pages/LoginUsername.tsx +2 -2
- package/src/login/pages/WebauthnAuthenticate.tsx +11 -8
- package/src/login/pages/WebauthnRegister.tsx +7 -7
- package/src/tools/AndByDiscriminatingKey.ts +12 -6
- package/src/tools/Array.prototype.every.ts +4 -1
- package/src/tools/LazyOrNot.ts +3 -1
- package/src/tools/clsx.ts +7 -1
- package/src/tools/deepAssign.ts +15 -8
- package/src/tools/deepClone.ts +3 -1
- package/src/tools/formatNumber.ts +4 -1
- package/src/tools/useConstCallback.ts +3 -1
- package/src/tools/useInsertLinkTags.ts +20 -7
- package/src/tools/useInsertScriptTags.ts +7 -2
- package/src/tools/useSetClassName.ts +4 -1
- package/src/vite-plugin/vite-plugin.ts +45 -21
- package/tools/Array.prototype.every.js +2 -1
- package/tools/Array.prototype.every.js.map +1 -1
- package/tools/clsx.js.map +1 -1
- package/tools/deepAssign.js +9 -7
- package/tools/deepAssign.js.map +1 -1
- package/tools/deepClone.js.map +1 -1
- package/tools/formatNumber.js.map +1 -1
- package/tools/useConstCallback.js.map +1 -1
- package/tools/useInsertLinkTags.js +5 -4
- package/tools/useInsertLinkTags.js.map +1 -1
- package/tools/useInsertScriptTags.js +5 -2
- package/tools/useInsertScriptTags.js.map +1 -1
- package/tools/useSetClassName.js.map +1 -1
- package/vite-plugin/index.js +985 -1651
- package/src/bin/shared/downloadAndUnzip.ts +0 -203
- package/src/bin/start-keycloak.ts +0 -309
- package/src/bin/tools/unzip.ts +0 -141
package/src/login/i18n/i18n.tsx
CHANGED
@@ -91,19 +91,19 @@ export function createUseI18n<ExtraMessageKey extends string = never>(extraMessa
|
|
91
91
|
|
92
92
|
setI18n({
|
93
93
|
...createI18nTranslationFunctions({
|
94
|
-
|
94
|
+
fallbackMessages: {
|
95
95
|
...fallbackMessages,
|
96
96
|
...(keycloakifyExtraMessages[fallbackLanguageTag] ?? {}),
|
97
97
|
...(extraMessages[fallbackLanguageTag] ?? {})
|
98
98
|
} as any,
|
99
|
-
|
99
|
+
messages: {
|
100
100
|
...(await getMessages(currentLanguageTag)),
|
101
101
|
...((keycloakifyExtraMessages as any)[currentLanguageTag] ?? {}),
|
102
102
|
...(extraMessages[currentLanguageTag] ?? {})
|
103
103
|
} as any
|
104
104
|
}),
|
105
105
|
currentLanguageTag,
|
106
|
-
|
106
|
+
getChangeLocalUrl: newLanguageTag => {
|
107
107
|
const { locale } = kcContext;
|
108
108
|
|
109
109
|
assert(locale !== undefined, "Internationalization not enabled");
|
@@ -114,7 +114,7 @@ export function createUseI18n<ExtraMessageKey extends string = never>(extraMessa
|
|
114
114
|
|
115
115
|
return targetSupportedLocale.url;
|
116
116
|
},
|
117
|
-
|
117
|
+
labelBySupportedLanguageTag: Object.fromEntries(
|
118
118
|
(kcContext.locale?.supported ?? []).map(({ languageTag, label }) => [languageTag, label])
|
119
119
|
)
|
120
120
|
});
|
@@ -170,7 +170,7 @@ function createI18nTranslationFunctions<MessageKey extends string>(params: {
|
|
170
170
|
})();
|
171
171
|
|
172
172
|
return doRenderMarkdown ? (
|
173
|
-
<Markdown allowDangerousHtml renderers={{
|
173
|
+
<Markdown allowDangerousHtml renderers={{ paragraph: "span" }}>
|
174
174
|
{messageWithArgsInjectedIfAny}
|
175
175
|
</Markdown>
|
176
176
|
) : (
|
@@ -186,7 +186,7 @@ function createI18nTranslationFunctions<MessageKey extends string>(params: {
|
|
186
186
|
const keyUnwrappedFromCurlyBraces = match === null ? key : match[1];
|
187
187
|
|
188
188
|
const out = resolveMsg({
|
189
|
-
|
189
|
+
key: keyUnwrappedFromCurlyBraces,
|
190
190
|
args,
|
191
191
|
doRenderMarkdown
|
192
192
|
});
|
@@ -195,38 +195,48 @@ function createI18nTranslationFunctions<MessageKey extends string>(params: {
|
|
195
195
|
}
|
196
196
|
|
197
197
|
return {
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
198
|
+
msgStr: (key, ...args) => resolveMsg({ key, args, doRenderMarkdown: false }) as string,
|
199
|
+
msg: (key, ...args) => resolveMsg({ key, args, doRenderMarkdown: true }) as JSX.Element,
|
200
|
+
advancedMsg: (key, ...args) =>
|
201
|
+
resolveMsgAdvanced({
|
202
|
+
key,
|
203
|
+
args,
|
204
|
+
doRenderMarkdown: true
|
205
|
+
}) as JSX.Element,
|
206
|
+
advancedMsgStr: (key, ...args) =>
|
207
|
+
resolveMsgAdvanced({
|
208
|
+
key,
|
209
|
+
args,
|
210
|
+
doRenderMarkdown: false
|
211
|
+
}) as string
|
202
212
|
};
|
203
213
|
}
|
204
214
|
|
205
215
|
const keycloakifyExtraMessages = {
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
216
|
+
en: {
|
217
|
+
shouldBeEqual: "{0} should be equal to {1}",
|
218
|
+
shouldBeDifferent: "{0} should be different to {1}",
|
219
|
+
shouldMatchPattern: "Pattern should match: `/{0}/`",
|
220
|
+
mustBeAnInteger: "Must be an integer",
|
221
|
+
notAValidOption: "Not a valid option",
|
222
|
+
selectAnOption: "Select an option",
|
223
|
+
remove: "Remove",
|
224
|
+
addValue: "Add value"
|
215
225
|
},
|
216
|
-
|
226
|
+
fr: {
|
217
227
|
/* spell-checker: disable */
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
228
|
+
shouldBeEqual: "{0} doit être égal à {1}",
|
229
|
+
shouldBeDifferent: "{0} doit être différent de {1}",
|
230
|
+
shouldMatchPattern: "Dois respecter le schéma: `/{0}/`",
|
231
|
+
mustBeAnInteger: "Doit être un nombre entier",
|
232
|
+
notAValidOption: "N'est pas une option valide",
|
233
|
+
|
234
|
+
logoutConfirmTitle: "Déconnexion",
|
235
|
+
logoutConfirmHeader: "Êtes-vous sûr(e) de vouloir vous déconnecter ?",
|
236
|
+
doLogout: "Se déconnecter",
|
237
|
+
selectAnOption: "Sélectionner une option",
|
238
|
+
remove: "Supprimer",
|
239
|
+
addValue: "Ajouter une valeur"
|
230
240
|
/* spell-checker: enable */
|
231
241
|
}
|
232
242
|
};
|
@@ -3,7 +3,10 @@ import { assert } from "tsafe/assert";
|
|
3
3
|
import type { Equals } from "tsafe";
|
4
4
|
import type { MessageKey } from "../i18n/i18n";
|
5
5
|
|
6
|
-
type ExtractAfterStartingWith<
|
6
|
+
type ExtractAfterStartingWith<
|
7
|
+
Prefix extends string,
|
8
|
+
StrEnum
|
9
|
+
> = StrEnum extends `${Prefix}${infer U}` ? U : never;
|
7
10
|
|
8
11
|
/** Take theses type definition with a grain of salt.
|
9
12
|
* Some values might be undefined on some pages.
|
@@ -103,7 +106,10 @@ export declare namespace KcContext {
|
|
103
106
|
* @param text to return
|
104
107
|
* @return text if message exists for given field, else undefined
|
105
108
|
*/
|
106
|
-
printIfExists: <T extends string>(
|
109
|
+
printIfExists: <T extends string>(
|
110
|
+
fieldName: string,
|
111
|
+
text: T
|
112
|
+
) => T | undefined;
|
107
113
|
/**
|
108
114
|
* Check if exists error message for given fields
|
109
115
|
*
|
@@ -10,15 +10,23 @@ import type { ExtendKcContext } from "./getKcContextFromWindow";
|
|
10
10
|
import { getKcContextFromWindow } from "./getKcContextFromWindow";
|
11
11
|
import { symToStr } from "tsafe/symToStr";
|
12
12
|
|
13
|
-
export function createGetKcContext<
|
13
|
+
export function createGetKcContext<
|
14
|
+
KcContextExtension extends { pageId: string } = never
|
15
|
+
>(params?: {
|
14
16
|
mockData?: readonly DeepPartial<ExtendKcContext<KcContextExtension>>[];
|
15
17
|
mockProperties?: Record<string, string>;
|
16
18
|
}) {
|
17
19
|
const { mockData, mockProperties } = params ?? {};
|
18
20
|
|
19
|
-
function getKcContext<
|
21
|
+
function getKcContext<
|
22
|
+
PageId extends
|
23
|
+
| ExtendKcContext<KcContextExtension>["pageId"]
|
24
|
+
| undefined = undefined
|
25
|
+
>(params?: {
|
20
26
|
mockPageId?: PageId;
|
21
|
-
storyPartialKcContext?: DeepPartial<
|
27
|
+
storyPartialKcContext?: DeepPartial<
|
28
|
+
Extract<ExtendKcContext<KcContextExtension>, { pageId: PageId }>
|
29
|
+
>;
|
22
30
|
}): {
|
23
31
|
kcContext: PageId extends undefined
|
24
32
|
? ExtendKcContext<KcContextExtension> | undefined
|
@@ -36,34 +44,46 @@ export function createGetKcContext<KcContextExtension extends { pageId: string }
|
|
36
44
|
break warn_that_mock_is_enbaled;
|
37
45
|
}
|
38
46
|
|
39
|
-
console.log(
|
47
|
+
console.log(
|
48
|
+
`%cKeycloakify: ${symToStr({
|
49
|
+
mockPageId
|
50
|
+
})} set to ${mockPageId}.`,
|
51
|
+
"background: red; color: yellow; font-size: medium"
|
52
|
+
);
|
40
53
|
}
|
41
54
|
|
42
|
-
const kcContextDefaultMock = kcContextMocks.find(
|
55
|
+
const kcContextDefaultMock = kcContextMocks.find(
|
56
|
+
({ pageId }) => pageId === mockPageId
|
57
|
+
);
|
43
58
|
|
44
59
|
const partialKcContextCustomMock = (() => {
|
45
60
|
const out: DeepPartial<ExtendKcContext<KcContextExtension>> = {};
|
46
61
|
|
47
|
-
const mockDataPick = mockData?.find(
|
62
|
+
const mockDataPick = mockData?.find(
|
63
|
+
({ pageId }) => pageId === mockPageId
|
64
|
+
);
|
48
65
|
|
49
66
|
if (mockDataPick !== undefined) {
|
50
67
|
deepAssign({
|
51
|
-
|
52
|
-
|
68
|
+
target: out,
|
69
|
+
source: mockDataPick
|
53
70
|
});
|
54
71
|
}
|
55
72
|
|
56
73
|
if (storyPartialKcContext !== undefined) {
|
57
74
|
deepAssign({
|
58
|
-
|
59
|
-
|
75
|
+
target: out,
|
76
|
+
source: storyPartialKcContext
|
60
77
|
});
|
61
78
|
}
|
62
79
|
|
63
80
|
return Object.keys(out).length === 0 ? undefined : out;
|
64
81
|
})();
|
65
82
|
|
66
|
-
if (
|
83
|
+
if (
|
84
|
+
kcContextDefaultMock === undefined &&
|
85
|
+
partialKcContextCustomMock === undefined
|
86
|
+
) {
|
67
87
|
console.warn(
|
68
88
|
[
|
69
89
|
`WARNING: You declared the non build in page ${mockPageId} but you didn't `,
|
@@ -76,68 +96,95 @@ export function createGetKcContext<KcContextExtension extends { pageId: string }
|
|
76
96
|
const kcContext: any = {};
|
77
97
|
|
78
98
|
deepAssign({
|
79
|
-
|
80
|
-
|
99
|
+
target: kcContext,
|
100
|
+
source:
|
101
|
+
kcContextDefaultMock !== undefined
|
102
|
+
? kcContextDefaultMock
|
103
|
+
: { pageId: mockPageId, ...kcContextCommonMock }
|
81
104
|
});
|
82
105
|
|
83
106
|
if (partialKcContextCustomMock !== undefined) {
|
84
107
|
deepAssign({
|
85
|
-
|
86
|
-
|
108
|
+
target: kcContext,
|
109
|
+
source: partialKcContextCustomMock
|
87
110
|
});
|
88
111
|
|
89
112
|
if ("profile" in partialKcContextCustomMock) {
|
90
|
-
assert(
|
113
|
+
assert(
|
114
|
+
kcContextDefaultMock !== undefined &&
|
115
|
+
"profile" in kcContextDefaultMock
|
116
|
+
);
|
91
117
|
|
92
118
|
const { attributes } = kcContextDefaultMock.profile;
|
93
119
|
|
94
120
|
id<KcContext.Register>(kcContext).profile.attributes = [];
|
95
121
|
id<KcContext.Register>(kcContext).profile.attributesByName = {};
|
96
122
|
|
97
|
-
const partialAttributes = [
|
98
|
-
|
99
|
-
|
123
|
+
const partialAttributes = [
|
124
|
+
...((
|
125
|
+
partialKcContextCustomMock as DeepPartial<KcContext.Register>
|
126
|
+
).profile?.attributes ?? [])
|
127
|
+
].filter(exclude(undefined));
|
100
128
|
|
101
129
|
attributes.forEach(attribute => {
|
102
|
-
const partialAttribute = partialAttributes.find(
|
130
|
+
const partialAttribute = partialAttributes.find(
|
131
|
+
({ name }) => name === attribute.name
|
132
|
+
);
|
103
133
|
|
104
134
|
const augmentedAttribute: Attribute = {} as any;
|
105
135
|
|
106
136
|
deepAssign({
|
107
|
-
|
108
|
-
|
137
|
+
target: augmentedAttribute,
|
138
|
+
source: attribute
|
109
139
|
});
|
110
140
|
|
111
141
|
if (partialAttribute !== undefined) {
|
112
|
-
partialAttributes.splice(
|
142
|
+
partialAttributes.splice(
|
143
|
+
partialAttributes.indexOf(partialAttribute),
|
144
|
+
1
|
145
|
+
);
|
113
146
|
|
114
147
|
deepAssign({
|
115
|
-
|
116
|
-
|
148
|
+
target: augmentedAttribute,
|
149
|
+
source: partialAttribute
|
117
150
|
});
|
118
151
|
}
|
119
152
|
|
120
|
-
id<KcContext.Register>(kcContext).profile.attributes.push(
|
121
|
-
|
153
|
+
id<KcContext.Register>(kcContext).profile.attributes.push(
|
154
|
+
augmentedAttribute
|
155
|
+
);
|
156
|
+
id<KcContext.Register>(kcContext).profile.attributesByName[
|
157
|
+
augmentedAttribute.name
|
158
|
+
] = augmentedAttribute;
|
122
159
|
});
|
123
160
|
|
124
161
|
partialAttributes
|
125
|
-
.map(partialAttribute => ({
|
162
|
+
.map(partialAttribute => ({
|
163
|
+
validators: {},
|
164
|
+
...partialAttribute
|
165
|
+
}))
|
126
166
|
.forEach(partialAttribute => {
|
127
167
|
const { name } = partialAttribute;
|
128
168
|
|
129
|
-
assert(
|
130
|
-
|
131
|
-
|
132
|
-
|
169
|
+
assert(
|
170
|
+
name !== undefined,
|
171
|
+
"If you define a mock attribute it must have at least a name"
|
172
|
+
);
|
173
|
+
|
174
|
+
id<KcContext.Register>(kcContext).profile.attributes.push(
|
175
|
+
partialAttribute as any
|
176
|
+
);
|
177
|
+
id<KcContext.Register>(kcContext).profile.attributesByName[
|
178
|
+
name
|
179
|
+
] = partialAttribute as any;
|
133
180
|
});
|
134
181
|
}
|
135
182
|
}
|
136
183
|
|
137
184
|
if (mockProperties !== undefined) {
|
138
185
|
deepAssign({
|
139
|
-
|
140
|
-
|
186
|
+
target: kcContext.properties,
|
187
|
+
source: mockProperties
|
141
188
|
});
|
142
189
|
}
|
143
190
|
|
@@ -145,14 +192,14 @@ export function createGetKcContext<KcContextExtension extends { pageId: string }
|
|
145
192
|
}
|
146
193
|
|
147
194
|
if (realKcContext === undefined) {
|
148
|
-
return {
|
195
|
+
return { kcContext: undefined as any };
|
149
196
|
}
|
150
197
|
|
151
198
|
if (realKcContext.themeType !== "login") {
|
152
|
-
return {
|
199
|
+
return { kcContext: undefined as any };
|
153
200
|
}
|
154
201
|
|
155
|
-
return {
|
202
|
+
return { kcContext: realKcContext as any };
|
156
203
|
}
|
157
204
|
|
158
205
|
return { getKcContext };
|
@@ -5,7 +5,9 @@ import { createGetKcContext } from "./createGetKcContext";
|
|
5
5
|
/** NOTE: We now recommend using createGetKcContext instead of this function to make storybook integration easier
|
6
6
|
* See: https://github.com/keycloakify/keycloakify-starter/blob/main/src/keycloak-theme/account/kcContext.ts
|
7
7
|
*/
|
8
|
-
export function getKcContext<
|
8
|
+
export function getKcContext<
|
9
|
+
KcContextExtension extends { pageId: string } = never
|
10
|
+
>(params?: {
|
9
11
|
mockPageId?: ExtendKcContext<KcContextExtension>["pageId"];
|
10
12
|
mockData?: readonly DeepPartial<ExtendKcContext<KcContextExtension>>[];
|
11
13
|
}): { kcContext: ExtendKcContext<KcContextExtension> | undefined } {
|
@@ -2,10 +2,14 @@ import type { KcContext } from "./KcContext";
|
|
2
2
|
import type { AndByDiscriminatingKey } from "keycloakify/tools/AndByDiscriminatingKey";
|
3
3
|
import { nameOfTheGlobal } from "keycloakify/bin/shared/constants";
|
4
4
|
|
5
|
-
export type ExtendKcContext<KcContextExtension extends { pageId: string }> = [
|
5
|
+
export type ExtendKcContext<KcContextExtension extends { pageId: string }> = [
|
6
|
+
KcContextExtension
|
7
|
+
] extends [never]
|
6
8
|
? KcContext
|
7
9
|
: AndByDiscriminatingKey<"pageId", KcContextExtension & KcContext.Common, KcContext>;
|
8
10
|
|
9
|
-
export function getKcContextFromWindow<
|
11
|
+
export function getKcContextFromWindow<
|
12
|
+
KcContextExtension extends { pageId: string } = never
|
13
|
+
>(): ExtendKcContext<KcContextExtension> | undefined {
|
10
14
|
return typeof window === "undefined" ? undefined : (window as any)[nameOfTheGlobal];
|
11
15
|
}
|