Refactor of the FreeMarker template

This commit is contained in:
Joseph Garrone 2024-07-13 18:17:21 +02:00
parent 54f43d3331
commit 2754900f7a
10 changed files with 487 additions and 482 deletions

View File

@ -24,6 +24,7 @@ export type BuildContextLike = BuildContextLike_generatePom & {
artifactId: string; artifactId: string;
themeVersion: string; themeVersion: string;
cacheDirPath: string; cacheDirPath: string;
recordIsImplementedByThemeType: BuildContext["recordIsImplementedByThemeType"];
}; };
assert<BuildContext extends BuildContextLike ? true : false>(); assert<BuildContext extends BuildContextLike ? true : false>();
@ -134,6 +135,10 @@ export async function buildJar(params: {
} }
route_legacy_pages: { route_legacy_pages: {
if (!buildContext.recordIsImplementedByThemeType.login) {
break route_legacy_pages;
}
// NOTE: If there's no account theme there is no special target for keycloak 24 and up so we create // NOTE: If there's no account theme there is no special target for keycloak 24 and up so we create
// the pages anyway. If there is an account pages, since we know that account-v1 is only support keycloak // the pages anyway. If there is an account pages, since we know that account-v1 is only support keycloak
// 24 in version 0.4 and up, we can safely break the route for legacy pages. // 24 in version 0.4 and up, we can safely break the route for legacy pages.
@ -165,7 +170,7 @@ export async function buildJar(params: {
const ftlFileContent = readFileSync(ftlFilePath).toString("utf8"); const ftlFileContent = readFileSync(ftlFilePath).toString("utf8");
const realPageId = (() => { const ftlFileBasename = (() => {
switch (pageId) { switch (pageId) {
case "register.ftl": case "register.ftl":
return "register-user-profile.ftl"; return "register-user-profile.ftl";
@ -176,14 +181,14 @@ export async function buildJar(params: {
})(); })();
const modifiedFtlFileContent = ftlFileContent.replace( const modifiedFtlFileContent = ftlFileContent.replace(
`kcContext.pageId = "\${pageId}";`, `"ftlTemplateFileName": "${pageId}"`,
`kcContext.pageId = "${pageId}"; kcContext.realPageId = "${realPageId}";` `"ftlTemplateFileName": "${ftlFileBasename}"`
); );
assert(modifiedFtlFileContent !== ftlFileContent); assert(modifiedFtlFileContent !== ftlFileContent);
fs.writeFile( fs.writeFile(
pathJoin(pathDirname(ftlFilePath), realPageId), pathJoin(pathDirname(ftlFilePath), ftlFileBasename),
Buffer.from(modifiedFtlFileContent, "utf8") Buffer.from(modifiedFtlFileContent, "utf8")
); );
}) })

View File

@ -34,7 +34,6 @@ export function generateFtlFilesCodeFactory(params: {
keycloakifyVersion: string; keycloakifyVersion: string;
themeType: ThemeType; themeType: ThemeType;
fieldNames: string[]; fieldNames: string[];
isAccountV3: boolean;
}) { }) {
const { const {
themeName, themeName,
@ -42,8 +41,7 @@ export function generateFtlFilesCodeFactory(params: {
buildContext, buildContext,
keycloakifyVersion, keycloakifyVersion,
themeType, themeType,
fieldNames, fieldNames
isAccountV3
} = params; } = params;
const $ = cheerio.load(indexHtmlCode); const $ = cheerio.load(indexHtmlCode);
@ -70,8 +68,7 @@ export function generateFtlFilesCodeFactory(params: {
const { fixedCssCode } = replaceImportsInCssCode({ const { fixedCssCode } = replaceImportsInCssCode({
cssCode, cssCode,
cssFileRelativeDirPath: undefined, cssFileRelativeDirPath: undefined,
buildContext, buildContext
isAccountV3
}); });
$(element).text(fixedCssCode); $(element).text(fixedCssCode);
@ -96,7 +93,7 @@ export function generateFtlFilesCodeFactory(params: {
new RegExp( new RegExp(
`^${(buildContext.urlPathname ?? "/").replace(/\//g, "\\/")}` `^${(buildContext.urlPathname ?? "/").replace(/\//g, "\\/")}`
), ),
`\${${!isAccountV3 ? "url.resourcesPath" : "resourceUrl"}}/${basenameOfTheKeycloakifyResourcesDir}/` `\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/`
) )
); );
}) })
@ -116,19 +113,17 @@ export function generateFtlFilesCodeFactory(params: {
) )
) )
.toString("utf8") .toString("utf8")
.replace("{{themeType}}", themeType)
.replace("{{themeName}}", themeName)
.replace("{{keycloakifyVersion}}", keycloakifyVersion)
.replace("{{themeVersion}}", buildContext.themeVersion)
.replace("{{fieldNames}}", fieldNames.map(name => `"${name}"`).join(", "))
.replace("{{RESOURCES_COMMON}}", resources_common)
.replace( .replace(
"FIELD_NAMES_eKsIY4ZsZ4xeM", "{{userDefinedExclusions}}",
fieldNames.map(name => `"${name}"`).join(", ")
)
.replace("KEYCLOAKIFY_VERSION_xEdKd3xEdr", keycloakifyVersion)
.replace("KEYCLOAKIFY_THEME_VERSION_sIgKd3xEdr3dx", buildContext.themeVersion)
.replace("KEYCLOAKIFY_THEME_TYPE_dExKd3xEdr", themeType)
.replace("KEYCLOAKIFY_THEME_NAME_cXxKd3xEer", themeName)
.replace("RESOURCES_COMMON_cLsLsMrtDkpVv", resources_common)
.replace(
"USER_DEFINED_EXCLUSIONS_eKsaY4ZsZ4eMr2",
buildContext.kcContextExclusionsFtlCode ?? "" buildContext.kcContextExclusionsFtlCode ?? ""
); );
const ftlObjectToJsCodeDeclaringAnObjectPlaceholder = const ftlObjectToJsCodeDeclaringAnObjectPlaceholder =
'{ "x": "vIdLqMeOed9sdLdIdOxdK0d" }'; '{ "x": "vIdLqMeOed9sdLdIdOxdK0d" }';
@ -173,7 +168,8 @@ export function generateFtlFilesCodeFactory(params: {
Object.entries({ Object.entries({
[ftlObjectToJsCodeDeclaringAnObjectPlaceholder]: [ftlObjectToJsCodeDeclaringAnObjectPlaceholder]:
kcContextDeclarationTemplateFtl, kcContextDeclarationTemplateFtl,
PAGE_ID_xIgLsPgGId9D8e: pageId "{{pageId}}": pageId,
"{{ftlTemplateFileName}}": pageId
}).map( }).map(
([searchValue, replaceValue]) => ([searchValue, replaceValue]) =>
(ftlCode = ftlCode.replace(searchValue, replaceValue)) (ftlCode = ftlCode.replace(searchValue, replaceValue))

View File

@ -1,21 +1,50 @@
<#assign pageId="PAGE_ID_xIgLsPgGId9D8e"> <#assign xKeycloakify={
<#assign themeType="KEYCLOAKIFY_THEME_TYPE_dExKd3xEdr"> "messages": {},
<#assign xKeycloakifyMessages = {}> "pageId": "{{pageId}}",
"ftlTemplateFileName": "{{ftlTemplateFileName}}",
"themeType": "{{themeType}}",
"themeName": "{{themeName}}",
"keycloakifyVersion": "{{keycloakifyVersion}}",
"themeVersion": "{{themeVersion}}",
"resourcesPath": ""
}>
const kcContext = ${ftl_object_to_js_code_declaring_an_object(.data_model, [])?no_esc}; <#if url?? && url?is_hash && url.resourcesPath?? && url.resourcesPath?is_string>
<#assign xKeycloakify = xKeycloakify + { "resourcesPath": url.resourcesPath }>
</#if>
<#if resourceUrl?? && resourceUrl?is_string>
<#assign xKeycloakify = xKeycloakify + { "resourcesPath": resourceUrl }>
</#if>
const kcContext = ${toJsDeclarationString(.data_model, [])?no_esc};
kcContext.keycloakifyVersion = "${xKeycloakify.keycloakifyVersion}";
kcContext.themeVersion = "${xKeycloakify.themeVersion}";
kcContext.themeType = "${xKeycloakify.themeType}";
kcContext.themeName = "${xKeycloakify.themeName}";
kcContext.pageId = "${xKeycloakify.pageId}";
kcContext.ftlTemplateFileName = "${xKeycloakify.ftlTemplateFileName}";
<@addNonAutomaticallyGatherableMessagesToXKeycloakifyMessages /> <@addNonAutomaticallyGatherableMessagesToXKeycloakifyMessages />
kcContext["x-keycloakify"] = {}; kcContext["x-keycloakify"] = {};
kcContext["x-keycloakify"].resourcesPath = "${xKeycloakify.resourcesPath}";
{ {
var messages = {}; var messages = {};
<#list xKeycloakifyMessages as key, resolvedMsg> <#list xKeycloakify.messages as key, resolvedMsg>
messages["${key}"] = decodeHtmlEntities("${resolvedMsg?js_string}"); messages["${key}"] = decodeHtmlEntities("${resolvedMsg?js_string}");
</#list> </#list>
kcContext["x-keycloakify"].messages = messages; kcContext["x-keycloakify"].messages = messages;
} }
if(
kcContext.url instanceof Object &&
typeof kcContext.url.resourcesPath === "string"
){
kcContext.url.resourcesCommonPath = kcContext.url.resourcesPath + "/{{RESOURCES_COMMON}}";
}
if( kcContext.messagesPerField ){ if( kcContext.messagesPerField ){
var existsError_singleFieldName = kcContext.messagesPerField.existsError; var existsError_singleFieldName = kcContext.messagesPerField.existsError;
kcContext.messagesPerField.existsError = function (){ kcContext.messagesPerField.existsError = function (){
@ -41,23 +70,6 @@ if( kcContext.messagesPerField ){
} }
}; };
} }
kcContext.keycloakifyVersion = "KEYCLOAKIFY_VERSION_xEdKd3xEdr";
kcContext.themeVersion = "KEYCLOAKIFY_THEME_VERSION_sIgKd3xEdr3dx";
kcContext.themeType = "${themeType}";
kcContext.themeName = "KEYCLOAKIFY_THEME_NAME_cXxKd3xEer";
kcContext.pageId = "${pageId}";
if( kcContext.url && kcContext.url.resourcesPath ){
kcContext.url.resourcesCommonPath = kcContext.url.resourcesPath + "/" + "RESOURCES_COMMON_cLsLsMrtDkpVv";
}
if( kcContext.resourceUrl && !kcContext.url ){
Object.defineProperty(kcContext, "url", {
value: {
resourcesPath: kcContext.resourceUrl
},
enumerable: false
});
}
attributes_to_attributesByName: { attributes_to_attributesByName: {
if( !kcContext.profile ){ if( !kcContext.profile ){
break attributes_to_attributesByName; break attributes_to_attributesByName;
@ -83,44 +95,39 @@ function decodeHtmlEntities(htmlStr){
return element.value; return element.value;
} }
<#function ftl_object_to_js_code_declaring_an_object object path> <#function toJsDeclarationString object path>
<#local isHash = -1>
<#local isHash = "">
<#attempt> <#attempt>
<#local isHash = object?is_hash || object?is_hash_ex> <#local isHash = object?is_hash || object?is_hash_ex>
<#recover> <#recover>
<#return "ABORT: Can't evaluate if " + path?join(".") + " is hash"> <#return "ABORT: Can't evaluate if " + path?join(".") + " is a hash">
</#attempt> </#attempt>
<#if isHash> <#if isHash>
<#if path?size gt 10> <#if path?size gt 10>
<#return "ABORT: Too many recursive calls, path: " + path?join(".")> <#return "ABORT: Too many recursive calls, path: " + path?join(".")>
</#if> </#if>
<#local keys = -1>
<#local keys = "">
<#attempt> <#attempt>
<#local keys = object?keys> <#local keys = object?keys>
<#recover> <#recover>
<#return "ABORT: We can't list keys on this object"> <#return "ABORT: We can't list keys on object">
</#attempt> </#attempt>
<#local out_seq = []> <#local outSeq = []>
<#list keys as key> <#list keys as key>
<#if ["class","declaredConstructors","superclass","declaringClass" ]?seq_contains(key) > <#if ["class","declaredConstructors","superclass","declaringClass" ]?seq_contains(key) >
<#continue> <#continue>
</#if> </#if>
<#if <#if (
( areSamePath(path, ["url"]) &&
["loginUpdatePasswordUrl", "loginUpdateProfileUrl", "loginUsernameReminderUrl", "loginUpdateTotpUrl"]?seq_contains(key) && ["loginUpdatePasswordUrl", "loginUpdateProfileUrl", "loginUsernameReminderUrl", "loginUpdateTotpUrl"]?seq_contains(key)
are_same_path(path, ["url"])
) || ( ) || (
key == "updateProfileCtx" && key == "updateProfileCtx" &&
are_same_path(path, []) areSamePath(path, [])
) || ( ) || (
<#-- https://github.com/keycloakify/keycloakify/pull/65#issuecomment-991896344 (reports with saml-post-form.ftl) --> <#-- https://github.com/keycloakify/keycloakify/pull/65#issuecomment-991896344 (reports with saml-post-form.ftl) -->
<#-- https://github.com/keycloakify/keycloakify/issues/91#issue-1212319466 (reports with error.ftl and Kc18) --> <#-- https://github.com/keycloakify/keycloakify/issues/91#issue-1212319466 (reports with error.ftl and Kc18) -->
@ -128,60 +135,60 @@ function decodeHtmlEntities(htmlStr){
<#-- https://github.com/keycloakify/keycloakify/issues/357 --> <#-- https://github.com/keycloakify/keycloakify/issues/357 -->
<#-- https://github.com/keycloakify/keycloakify/discussions/406#discussioncomment-7514787 --> <#-- https://github.com/keycloakify/keycloakify/discussions/406#discussioncomment-7514787 -->
key == "loginAction" && key == "loginAction" &&
are_same_path(path, ["url"]) && areSamePath(path, ["url"]) &&
["saml-post-form.ftl", "error.ftl", "info.ftl", "login-oauth-grant.ftl", "logout-confirm.ftl", "login-oauth2-device-verify-user-code.ftl"]?seq_contains(pageId) && ["saml-post-form.ftl", "error.ftl", "info.ftl", "login-oauth-grant.ftl", "logout-confirm.ftl", "login-oauth2-device-verify-user-code.ftl"]?seq_contains(xKeycloakify.pageId) &&
!(auth?has_content && auth.showTryAnotherWayLink()) !(auth?has_content && auth.showTryAnotherWayLink())
) || ( ) || (
<#-- https://github.com/keycloakify/keycloakify/issues/362 --> <#-- https://github.com/keycloakify/keycloakify/issues/362 -->
["secretData", "value"]?seq_contains(key) && ["secretData", "value"]?seq_contains(key) &&
are_same_path(path, [ "totp", "otpCredentials", "*" ]) areSamePath(path, [ "totp", "otpCredentials", "*" ])
) || ( ) || (
["contextData", "idpConfig", "idp", "authenticationSession"]?seq_contains(key) && ["contextData", "idpConfig", "idp", "authenticationSession"]?seq_contains(key) &&
are_same_path(path, ["brokerContext"]) && areSamePath(path, ["brokerContext"]) &&
["login-idp-link-confirm.ftl", "login-idp-link-email.ftl" ]?seq_contains(pageId) ["login-idp-link-confirm.ftl", "login-idp-link-email.ftl" ]?seq_contains(xKeycloakify.pageId)
) || ( ) || (
key == "identityProviderBrokerCtx" && key == "identityProviderBrokerCtx" &&
are_same_path(path, []) && areSamePath(path, []) &&
["login-idp-link-confirm.ftl", "login-idp-link-email.ftl" ]?seq_contains(pageId) ["login-idp-link-confirm.ftl", "login-idp-link-email.ftl" ]?seq_contains(xKeycloakify.pageId)
) || ( ) || (
["masterAdminClient", "delegateForUpdate", "defaultRole"]?seq_contains(key) && ["masterAdminClient", "delegateForUpdate", "defaultRole"]?seq_contains(key) &&
are_same_path(path, ["realm"]) areSamePath(path, ["realm"])
) || ( ) || (
"error.ftl" == pageId && xKeycloakify.pageId == "error.ftl" &&
are_same_path(path, ["realm"]) && areSamePath(path, ["realm"]) &&
!["name", "displayName", "displayNameHtml", "internationalizationEnabled", "registrationEmailAsUsername" ]?seq_contains(key) !["name", "displayName", "displayNameHtml", "internationalizationEnabled", "registrationEmailAsUsername" ]?seq_contains(key)
) || ( ) || (
"applications.ftl" == pageId && xKeycloakify.pageId == "applications.ftl" &&
( (
key == "realm" || key == "realm" ||
key == "container" key == "container"
) && ) &&
is_subpath(path, ["applications", "applications"]) isSubpath(path, ["applications", "applications"])
) || ( ) || (
key == "delegateForUpdate" && key == "delegateForUpdate" &&
are_same_path(path, ["user"]) areSamePath(path, ["user"])
) || ( ) || (
<#-- Security audit forwarded by Garth (Gmail) --> <#-- Security audit forwarded by Garth (Gmail) -->
key == "saml.signing.private.key" && key == "saml.signing.private.key" &&
are_same_path(path, ["client", "attributes"]) areSamePath(path, ["client", "attributes"])
) || ( ) || (
<#-- See: https://github.com/keycloakify/keycloakify/issues/534 --> <#-- See: https://github.com/keycloakify/keycloakify/issues/534 -->
key == "password" && key == "password" &&
are_same_path(path, ["login"]) areSamePath(path, ["login"])
) || ( ) || (
<#-- Remove realmAttributes added by https://github.com/jcputney/keycloak-theme-additional-info-extension for peace of mind. --> <#-- Remove realmAttributes added by https://github.com/jcputney/keycloak-theme-additional-info-extension for peace of mind. -->
key == "realmAttributes" && key == "realmAttributes" &&
are_same_path(path, []) areSamePath(path, [])
) || ( ) || (
<#-- attributesByName adds a lot of noise to the output and is not needed, we already have profile.attributes --> <#-- attributesByName adds a lot of noise to the output and is not needed, we already have profile.attributes -->
key == "attributesByName" && key == "attributesByName" &&
are_same_path(path, ["profile"]) areSamePath(path, ["profile"])
) || ( ) || (
<#-- We already have the attributes in profile speedup the rendering by filtering it out from the register object --> <#-- We already have the attributes in profile speedup the rendering by filtering it out from the register object -->
(key == "attributes" || key == "attributesByName") && (key == "attributes" || key == "attributesByName") &&
are_same_path(path, ["register"]) areSamePath(path, ["register"])
) || ( ) || (
are_same_path(path, ["properties"]) && areSamePath(path, ["properties"]) &&
( (
key?starts_with("kc") || key?starts_with("kc") ||
key == "locales" || key == "locales" ||
@ -194,74 +201,78 @@ function decodeHtmlEntities(htmlStr){
) )
) || ( ) || (
key == "execution" && key == "execution" &&
are_same_path(path, []) areSamePath(path, [])
) || ( ) || (
key == "entity" && key == "entity" &&
are_same_path(path, ["user"]) areSamePath(path, ["user"])
) )
> >
<#-- <#local out_seq += ["/*" + path?join(".") + "." + key + " excluded*/"]> --> <#-- <#local outSeq += ["/*" + path?join(".") + "." + key + " excluded*/"]> -->
<#continue> <#continue>
</#if> </#if>
<#-- https://github.com/keycloakify/keycloakify/discussions/406 --> <#-- https://github.com/keycloakify/keycloakify/discussions/406 -->
<#if ( <#if (
["register.ftl", "register-user-profile.ftl", "terms.ftl", "info.ftl", "login.ftl", "login-update-password.ftl", "login-oauth2-device-verify-user-code.ftl"]?seq_contains(pageId) && key == "attemptedUsername" &&
key == "attemptedUsername" && are_same_path(path, ["auth"]) areSamePath(path, ["auth"]) &&
[
"register.ftl", "terms.ftl", "info.ftl", "login.ftl",
"login-update-password.ftl", "login-oauth2-device-verify-user-code.ftl"
]?seq_contains(xKeycloakify.pageId)
)> )>
<#attempt> <#attempt>
<#-- https://github.com/keycloak/keycloak/blob/3a2bf0c04bcde185e497aaa32d0bb7ab7520cf4a/themes/src/main/resources/theme/base/login/template.ftl#L63 --> <#-- https://github.com/keycloak/keycloak/blob/3a2bf0c04bcde185e497aaa32d0bb7ab7520cf4a/themes/src/main/resources/theme/base/login/template.ftl#L63 -->
<#if !(auth?has_content && auth.showUsername() && !auth.showResetCredentials())> <#if !(auth?has_content && auth.showUsername() && !auth.showResetCredentials())>
<#local out_seq += ["/*" + path?join(".") + "." + key + " excluded*/"]> <#local outSeq += ["/*" + path?join(".") + "." + key + " excluded*/"]>
<#continue> <#continue>
</#if> </#if>
<#recover> <#recover>
<#local out_seq += ["/*Accessing attemptedUsername throwed an exception */"]> <#local outSeq += ["/*Accessing attemptedUsername throwed an exception */"]>
</#attempt> </#attempt>
</#if> </#if>
USER_DEFINED_EXCLUSIONS_eKsaY4ZsZ4eMr2 {{userDefinedExclusions}}
<#attempt> <#attempt>
<#if !object[key]??> <#if !object[key]??>
<#continue> <#continue>
</#if> </#if>
<#recover> <#recover>
<#local out_seq += ["/*Couldn't test if '" + key + "' is available on this object*/"]> <#local outSeq += ["/*Couldn't test if '" + key + "' is available on this object*/"]>
<#continue> <#continue>
</#attempt> </#attempt>
<#local propertyValue = ""> <#local propertyValue = -1>
<#attempt> <#attempt>
<#local propertyValue = object[key]> <#local propertyValue = object[key]>
<#recover> <#recover>
<#local out_seq += ["/*Couldn't dereference '" + key + "' on this object*/"]> <#local outSeq += ["/*Couldn't dereference '" + key + "' on this object*/"]>
<#continue> <#continue>
</#attempt> </#attempt>
<#local rec_out = ftl_object_to_js_code_declaring_an_object(propertyValue, path + [ key ])> <#local recOut = toJsDeclarationString(propertyValue, path + [ key ])>
<#if rec_out?starts_with("ABORT:")> <#if recOut?starts_with("ABORT:")>
<#local errorMessage = rec_out?remove_beginning("ABORT:")> <#local errorMessage = recOut?remove_beginning("ABORT:")>
<#if errorMessage != " It's a method" > <#if errorMessage != " It's a method" >
<#local out_seq += ["/*" + key + ": " + errorMessage + "*/"]> <#local outSeq += ["/*" + key + ": " + errorMessage + "*/"]>
</#if> </#if>
<#continue> <#continue>
</#if> </#if>
<#local out_seq += ['"' + key + '": ' + rec_out + ","]> <#local outSeq += ['"' + key + '": ' + recOut + ","]>
</#list> </#list>
<#return (["{"] + out_seq?map(str -> ""?right_pad(4 * (path?size + 1)) + str) + [ ""?right_pad(4 * path?size) + "}"])?join("\n")> <#return (["{"] + outSeq?map(str -> ""?right_pad(4 * (path?size + 1)) + str) + [ ""?right_pad(4 * path?size) + "}"])?join("\n")>
</#if> </#if>
<#local isMethod = ""> <#local isMethod = -1>
<#attempt> <#attempt>
<#local isMethod = object?is_method> <#local isMethod = object?is_method>
<#recover> <#recover>
@ -270,7 +281,7 @@ function decodeHtmlEntities(htmlStr){
<#if isMethod> <#if isMethod>
<#if are_same_path(path, ["auth", "showUsername"])> <#if areSamePath(path, ["auth", "showUsername"])>
<#attempt> <#attempt>
<#return auth.showUsername()?c> <#return auth.showUsername()?c>
<#recover> <#recover>
@ -278,7 +289,7 @@ function decodeHtmlEntities(htmlStr){
</#attempt> </#attempt>
</#if> </#if>
<#if are_same_path(path, ["auth", "showResetCredentials"])> <#if areSamePath(path, ["auth", "showResetCredentials"])>
<#attempt> <#attempt>
<#return auth.showResetCredentials()?c> <#return auth.showResetCredentials()?c>
<#recover> <#recover>
@ -286,7 +297,7 @@ function decodeHtmlEntities(htmlStr){
</#attempt> </#attempt>
</#if> </#if>
<#if are_same_path(path, ["auth", "showTryAnotherWayLink"])> <#if areSamePath(path, ["auth", "showTryAnotherWayLink"])>
<#attempt> <#attempt>
<#return auth.showTryAnotherWayLink()?c> <#return auth.showTryAnotherWayLink()?c>
<#recover> <#recover>
@ -294,8 +305,8 @@ function decodeHtmlEntities(htmlStr){
</#attempt> </#attempt>
</#if> </#if>
<#if are_same_path(path, ["url", "getLogoutUrl"])> <#if areSamePath(path, ["url", "getLogoutUrl"])>
<#local returnValue = ""> <#local returnValue = -1>
<#attempt> <#attempt>
<#local returnValue = url.getLogoutUrl()> <#local returnValue = url.getLogoutUrl()>
<#recover> <#recover>
@ -304,7 +315,7 @@ function decodeHtmlEntities(htmlStr){
<#return 'function(){ return "' + returnValue + '"; }'> <#return 'function(){ return "' + returnValue + '"; }'>
</#if> </#if>
<#if are_same_path(path, ["totp", "policy", "getAlgorithmKey"])> <#if areSamePath(path, ["totp", "policy", "getAlgorithmKey"])>
<#local returnValue = "error"> <#local returnValue = "error">
<#if mode?? && mode = "manual"> <#if mode?? && mode = "manual">
<#attempt> <#attempt>
@ -316,7 +327,7 @@ function decodeHtmlEntities(htmlStr){
<#return 'function(){ return "' + returnValue + '"; }'> <#return 'function(){ return "' + returnValue + '"; }'>
</#if> </#if>
<#assign fieldNames = [ FIELD_NAMES_eKsIY4ZsZ4xeM ]> <#assign fieldNames = [{{fieldNames}}]>
<#if profile?? && profile.attributes??> <#if profile?? && profile.attributes??>
<#list profile.attributes as attribute> <#list profile.attributes as attribute>
<#if fieldNames?seq_contains(attribute.name)> <#if fieldNames?seq_contains(attribute.name)>
@ -326,14 +337,14 @@ function decodeHtmlEntities(htmlStr){
</#list> </#list>
</#if> </#if>
<#if are_same_path(path, ["messagesPerField", "get"])> <#if areSamePath(path, ["messagesPerField", "get"])>
<#local jsFunctionCode = "function (fieldName) { "> <#local jsFunctionCode = "function (fieldName) { ">
<#list fieldNames as fieldName> <#list fieldNames as fieldName>
<#-- See: https://github.com/keycloakify/keycloakify/issues/217 --> <#-- See: https://github.com/keycloakify/keycloakify/issues/217 -->
<#if pageId == "login.ftl" > <#if xKeycloakify.pageId == "login.ftl" >
<#if fieldName == "username"> <#if fieldName == "username">
@ -374,14 +385,14 @@ function decodeHtmlEntities(htmlStr){
</#if> </#if>
<#if are_same_path(path, ["messagesPerField", "existsError"])> <#if areSamePath(path, ["messagesPerField", "existsError"])>
<#local jsFunctionCode = "function (fieldName) { "> <#local jsFunctionCode = "function (fieldName) { ">
<#list fieldNames as fieldName> <#list fieldNames as fieldName>
<#-- See: https://github.com/keycloakify/keycloakify/issues/217 --> <#-- See: https://github.com/keycloakify/keycloakify/issues/217 -->
<#if pageId == "login.ftl" > <#if xKeycloakify.pageId == "login.ftl" >
<#if fieldName == "username"> <#if fieldName == "username">
<#local jsFunctionCode += "if(fieldName === 'username' || fieldName === 'password' ){ "> <#local jsFunctionCode += "if(fieldName === 'username' || fieldName === 'password' ){ ">
@ -420,7 +431,7 @@ function decodeHtmlEntities(htmlStr){
</#if> </#if>
<#if themeType == "account" && are_same_path(path, ["realm", "isInternationalizationEnabled"])> <#if xKeycloakify.themeType == "account" && areSamePath(path, ["realm", "isInternationalizationEnabled"])>
<#attempt> <#attempt>
<#return realm.isInternationalizationEnabled()?c> <#return realm.isInternationalizationEnabled()?c>
<#recover> <#recover>
@ -431,7 +442,7 @@ function decodeHtmlEntities(htmlStr){
<#return "ABORT: It's a method"> <#return "ABORT: It's a method">
</#if> </#if>
<#local isBoolean = ""> <#local isBoolean = -1>
<#attempt> <#attempt>
<#local isBoolean = object?is_boolean> <#local isBoolean = object?is_boolean>
<#recover> <#recover>
@ -442,7 +453,7 @@ function decodeHtmlEntities(htmlStr){
<#return object?c> <#return object?c>
</#if> </#if>
<#local isEnumerable = ""> <#local isEnumerable = -1>
<#attempt> <#attempt>
<#local isEnumerable = object?is_enumerable> <#local isEnumerable = object?is_enumerable>
<#recover> <#recover>
@ -452,41 +463,41 @@ function decodeHtmlEntities(htmlStr){
<#if isEnumerable> <#if isEnumerable>
<#local out_seq = []> <#local outSeq = []>
<#local i = 0> <#local i = 0>
<#list object as array_item> <#list object as array_item>
<#if !array_item??> <#if !array_item??>
<#local out_seq += ["null,"]> <#local outSeq += ["null,"]>
<#continue> <#continue>
</#if> </#if>
<#local rec_out = ftl_object_to_js_code_declaring_an_object(array_item, path + [ i ])> <#local recOut = toJsDeclarationString(array_item, path + [ i ])>
<#local i = i + 1> <#local i = i + 1>
<#if rec_out?starts_with("ABORT:")> <#if recOut?starts_with("ABORT:")>
<#local errorMessage = rec_out?remove_beginning("ABORT:")> <#local errorMessage = recOut?remove_beginning("ABORT:")>
<#if errorMessage != " It's a method" > <#if errorMessage != " It's a method" >
<#local out_seq += ["/*" + i?string + ": " + errorMessage + "*/"]> <#local outSeq += ["/*" + i?string + ": " + errorMessage + "*/"]>
</#if> </#if>
<#continue> <#continue>
</#if> </#if>
<#local out_seq += [rec_out + ","]> <#local outSeq += [recOut + ","]>
</#list> </#list>
<#return (["["] + out_seq?map(str -> ""?right_pad(4 * (path?size + 1)) + str) + [ ""?right_pad(4 * path?size) + "]"])?join("\n")> <#return (["["] + outSeq?map(str -> ""?right_pad(4 * (path?size + 1)) + str) + [ ""?right_pad(4 * path?size) + "]"])?join("\n")>
</#if> </#if>
<#local isDate = ""> <#local isDate = -1>
<#attempt> <#attempt>
<#local isDate = object?is_date_like> <#local isDate = object?is_date_like>
<#recover> <#recover>
@ -497,7 +508,7 @@ function decodeHtmlEntities(htmlStr){
<#return '"' + object?datetime?iso_utc + '"'> <#return '"' + object?datetime?iso_utc + '"'>
</#if> </#if>
<#local isNumber = ""> <#local isNumber = -1>
<#attempt> <#attempt>
<#local isNumber = object?is_number> <#local isNumber = object?is_number>
<#recover> <#recover>
@ -508,7 +519,7 @@ function decodeHtmlEntities(htmlStr){
<#return object?c> <#return object?c>
</#if> </#if>
<#local isString = ""> <#local isString = -1>
<#attempt> <#attempt>
<#local isString = object?is_string> <#local isString = object?is_string>
<#recover> <#recover>
@ -520,14 +531,14 @@ function decodeHtmlEntities(htmlStr){
</#if> </#if>
<#attempt> <#attempt>
<#return '"' + object?js_string + '"'>; <#return 'decodeHtmlEntities("' + object?js_string + '")'>;
<#recover> <#recover>
</#attempt> </#attempt>
<#return "ABORT: Couldn't convert into string non hash, non method, non boolean, non number, non enumerable object"> <#return "ABORT: Couldn't convert into string non hash, non method, non boolean, non number, non enumerable object">
</#function> </#function>
<#function is_subpath path searchedPath> <#function isSubpath path searchedPath>
<#if path?size < searchedPath?size> <#if path?size < searchedPath?size>
<#return false> <#return false>
@ -567,8 +578,8 @@ function decodeHtmlEntities(htmlStr){
</#function> </#function>
<#function are_same_path path searchedPath> <#function areSamePath path searchedPath>
<#return path?size == searchedPath?size && is_subpath(path, searchedPath)> <#return path?size == searchedPath?size && isSubpath(path, searchedPath)>
</#function> </#function>
<#macro addToXKeycloakifyMessagesIfMessageKey str> <#macro addToXKeycloakifyMessagesIfMessageKey str>
@ -589,7 +600,9 @@ function decodeHtmlEntities(htmlStr){
<#if resolvedMsg==key> <#if resolvedMsg==key>
<#return> <#return>
</#if> </#if>
<#assign xKeycloakifyMessages = xKeycloakifyMessages + { "${key}": resolvedMsg }> <#local messages=xKeycloakify.messages>
<#local messages = messages + { key: resolvedMsg }>
<#assign xKeycloakify = xKeycloakify + { "messages": messages }>
</#macro> </#macro>
<#function removeBrackets str> <#function removeBrackets str>
@ -625,7 +638,7 @@ function decodeHtmlEntities(htmlStr){
</#list> </#list>
</#list> </#list>
</#if> </#if>
<#if pageId == "terms.ftl" || termsAcceptanceRequired?? && termsAcceptanceRequired> <#if xKeycloakify.pageId == "terms.ftl" || termsAcceptanceRequired?? && termsAcceptanceRequired>
<@addToXKeycloakifyMessagesIfMessageKey str="termsText" /> <@addToXKeycloakifyMessagesIfMessageKey str="termsText" />
</#if> </#if>
<#if requiredActions?? && requiredActions?is_enumerable> <#if requiredActions?? && requiredActions?is_enumerable>
@ -637,5 +650,3 @@ function decodeHtmlEntities(htmlStr){
</#list> </#list>
</#if> </#if>
</#macro> </#macro>

View File

@ -140,8 +140,7 @@ export async function generateResourcesForMainTheme(params: {
const { fixedCssCode } = replaceImportsInCssCode({ const { fixedCssCode } = replaceImportsInCssCode({
cssCode: sourceCode.toString("utf8"), cssCode: sourceCode.toString("utf8"),
cssFileRelativeDirPath: pathDirname(fileRelativePath), cssFileRelativeDirPath: pathDirname(fileRelativePath),
buildContext, buildContext
isAccountV3
}); });
return { return {
@ -176,8 +175,7 @@ export async function generateResourcesForMainTheme(params: {
fieldNames: readFieldNameUsage({ fieldNames: readFieldNameUsage({
themeSrcDirPath: buildContext.themeSrcDirPath, themeSrcDirPath: buildContext.themeSrcDirPath,
themeType themeType
}), })
isAccountV3
}); });
[ [

View File

@ -31,8 +31,8 @@ export function generateResourcesForThemeVariant(params: {
Buffer.from(sourceCode) Buffer.from(sourceCode)
.toString("utf-8") .toString("utf-8")
.replace( .replace(
`kcContext.themeName = "${themeName}";`, `"themeName": "${themeName}"`,
`kcContext.themeName = "${themeVariantName}";` `"themeName": "${themeVariantName}"`
), ),
"utf8" "utf8"
); );

View File

@ -12,12 +12,11 @@ assert<BuildContext extends BuildContextLike ? true : false>();
export function replaceImportsInCssCode(params: { export function replaceImportsInCssCode(params: {
cssCode: string; cssCode: string;
cssFileRelativeDirPath: string | undefined; cssFileRelativeDirPath: string | undefined;
isAccountV3: boolean;
buildContext: BuildContextLike; buildContext: BuildContextLike;
}): { }): {
fixedCssCode: string; fixedCssCode: string;
} { } {
const { cssCode, cssFileRelativeDirPath, buildContext, isAccountV3 } = params; const { cssCode, cssFileRelativeDirPath, buildContext } = params;
const fixedCssCode = cssCode.replace( const fixedCssCode = cssCode.replace(
/url\(["']?(\/[^/][^)"']+)["']?\)/g, /url\(["']?(\/[^/][^)"']+)["']?\)/g,
@ -38,7 +37,7 @@ export function replaceImportsInCssCode(params: {
break inline_style_in_html; break inline_style_in_html;
} }
return `url(\${${!isAccountV3 ? "url.resourcesPath" : "resourceUrl"}}/${basenameOfTheKeycloakifyResourcesDir}${assetFileAbsoluteUrlPathname})`; return `url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}${assetFileAbsoluteUrlPathname})`;
} }
const assetFileRelativeUrlPathname = posix.relative( const assetFileRelativeUrlPathname = posix.relative(

View File

@ -31,13 +31,13 @@ export function replaceImportsInJsCode_vite(params: {
let fixedJsCode = jsCode; let fixedJsCode = jsCode;
replace_base_javacript_import: { replace_base_js_import: {
if (buildContext.urlPathname === undefined) { if (buildContext.urlPathname === undefined) {
break replace_base_javacript_import; break replace_base_js_import;
} }
// Optimization // Optimization
if (!jsCode.includes(buildContext.urlPathname)) { if (!jsCode.includes(buildContext.urlPathname)) {
break replace_base_javacript_import; break replace_base_js_import;
} }
// Replace `Hv=function(e){return"/abcde12345/"+e}` by `Hv=function(e){return"/"+e}` // Replace `Hv=function(e){return"/abcde12345/"+e}` by `Hv=function(e){return"/"+e}`
@ -85,13 +85,13 @@ export function replaceImportsInJsCode_vite(params: {
fixedJsCode = replaceAll( fixedJsCode = replaceAll(
fixedJsCode, fixedJsCode,
`"${relativePathOfAssetFile}"`, `"${relativePathOfAssetFile}"`,
`(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/${relativePathOfAssetFile}")` `(window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/${relativePathOfAssetFile}")`
); );
fixedJsCode = replaceAll( fixedJsCode = replaceAll(
fixedJsCode, fixedJsCode,
`"${buildContext.urlPathname ?? "/"}${relativePathOfAssetFile}"`, `"${buildContext.urlPathname ?? "/"}${relativePathOfAssetFile}"`,
`(window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/${relativePathOfAssetFile}")` `(window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/${relativePathOfAssetFile}")`
); );
}); });
} }

View File

@ -83,7 +83,7 @@ export function replaceImportsInJsCode_webpack(params: {
var pd = Object.getOwnPropertyDescriptor(${n}, "p"); var pd = Object.getOwnPropertyDescriptor(${n}, "p");
if( pd === undefined || pd.configurable ){ if( pd === undefined || pd.configurable ){
Object.defineProperty(${n}, "p", { Object.defineProperty(${n}, "p", {
get: function() { return window.kcContext.url.resourcesPath; }, get: function() { return window.kcContext["x-keycloakify"].resourcesPath; },
set: function() {} set: function() {}
}); });
} }
@ -104,7 +104,7 @@ export function replaceImportsInJsCode_webpack(params: {
`[a-zA-Z]+\\.[a-zA-Z]+\\+"${staticDir.replace(/\//g, "\\/")}`, `[a-zA-Z]+\\.[a-zA-Z]+\\+"${staticDir.replace(/\//g, "\\/")}`,
"g" "g"
), ),
`window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/${staticDir}` `window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/${staticDir}`
); );
return { fixedJsCode }; return { fixedJsCode };

View File

@ -172,7 +172,7 @@ export function keycloakify(params?: Params) {
`(`, `(`,
`(window.kcContext === undefined || import.meta.env.MODE === "development")?`, `(window.kcContext === undefined || import.meta.env.MODE === "development")?`,
`"${urlPathname ?? "/"}":`, `"${urlPathname ?? "/"}":`,
`(window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/")`, `(window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/")`,
`)` `)`
].join("") ].join("")
); );

View File

@ -87,13 +87,13 @@ describe("js replacer - vite", () => {
}); });
const fixedJsCodeExpected = ` const fixedJsCodeExpected = `
S=(window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{ S=(window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
function __vite__mapDeps(indexes) { function __vite__mapDeps(indexes) {
if (!__vite__mapDeps.viteFileDeps) { if (!__vite__mapDeps.viteFileDeps) {
__vite__mapDeps.viteFileDeps = [ __vite__mapDeps.viteFileDeps = [
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"), (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"),
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js") (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js")
] ]
} }
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i]) return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
@ -146,13 +146,13 @@ describe("js replacer - vite", () => {
}); });
const fixedJsCodeExpected = ` const fixedJsCodeExpected = `
S=(window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/keycloakify-logo-mqjydaoZ.png"),H=(()=>{ S=(window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
function __vite__mapDeps(indexes) { function __vite__mapDeps(indexes) {
if (!__vite__mapDeps.viteFileDeps) { if (!__vite__mapDeps.viteFileDeps) {
__vite__mapDeps.viteFileDeps = [ __vite__mapDeps.viteFileDeps = [
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/Login-dJpPRzM4.js"), (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/Login-dJpPRzM4.js"),
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/index-XwzrZ5Gu.js") (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/index-XwzrZ5Gu.js")
] ]
} }
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i]) return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
@ -205,13 +205,13 @@ describe("js replacer - vite", () => {
}); });
const fixedJsCodeExpected = ` const fixedJsCodeExpected = `
S=(window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{ S=(window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
function __vite__mapDeps(indexes) { function __vite__mapDeps(indexes) {
if (!__vite__mapDeps.viteFileDeps) { if (!__vite__mapDeps.viteFileDeps) {
__vite__mapDeps.viteFileDeps = [ __vite__mapDeps.viteFileDeps = [
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"), (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"),
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js") (window.kcContext["x-keycloakify"].resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js")
] ]
} }
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i]) return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
@ -267,13 +267,13 @@ describe("js replacer - webpack", () => {
const fixedJsCodeExpected = ` const fixedJsCodeExpected = `
function f() { function f() {
return window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/static/js/" + ({}[e] || e) + "." + { return window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/static/js/" + ({}[e] || e) + "." + {
3: "0664cdc0" 3: "0664cdc0"
}[e] + ".chunk.js" }[e] + ".chunk.js"
} }
function sameAsF() { function sameAsF() {
return window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/static/js/" + ({}[e] || e) + "." + { return window.kcContext["x-keycloakify"].resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/static/js/" + ({}[e] || e) + "." + {
3: "0664cdc0" 3: "0664cdc0"
}[e] + ".chunk.js" }[e] + ".chunk.js"
} }
@ -282,7 +282,7 @@ describe("js replacer - webpack", () => {
var pd = Object.getOwnPropertyDescriptor(__webpack_require__, "p"); var pd = Object.getOwnPropertyDescriptor(__webpack_require__, "p");
if( pd === undefined || pd.configurable ){ if( pd === undefined || pd.configurable ){
Object.defineProperty(__webpack_require__, "p", { Object.defineProperty(__webpack_require__, "p", {
get: function() { return window.kcContext.url.resourcesPath; }, get: function() { return window.kcContext["x-keycloakify"].resourcesPath; },
set: function() {} set: function() {}
}); });
} }
@ -299,7 +299,7 @@ describe("js replacer - webpack", () => {
var pd = Object.getOwnPropertyDescriptor(t, "p"); var pd = Object.getOwnPropertyDescriptor(t, "p");
if( pd === undefined || pd.configurable ){ if( pd === undefined || pd.configurable ){
Object.defineProperty(t, "p", { Object.defineProperty(t, "p", {
get: function() { return window.kcContext.url.resourcesPath; }, get: function() { return window.kcContext["x-keycloakify"].resourcesPath; },
set: function() {} set: function() {}
}); });
} }
@ -315,7 +315,7 @@ describe("js replacer - webpack", () => {
var pd = Object.getOwnPropertyDescriptor(n, "p"); var pd = Object.getOwnPropertyDescriptor(n, "p");
if( pd === undefined || pd.configurable ){ if( pd === undefined || pd.configurable ){
Object.defineProperty(n, "p", { Object.defineProperty(n, "p", {
get: function() { return window.kcContext.url.resourcesPath; }, get: function() { return window.kcContext["x-keycloakify"].resourcesPath; },
set: function() {} set: function() {}
}); });
} }
@ -326,7 +326,7 @@ describe("js replacer - webpack", () => {
var pd = Object.getOwnPropertyDescriptor(t, "p"); var pd = Object.getOwnPropertyDescriptor(t, "p");
if( pd === undefined || pd.configurable ){ if( pd === undefined || pd.configurable ){
Object.defineProperty(t, "p", { Object.defineProperty(t, "p", {
get: function() { return window.kcContext.url.resourcesPath; }, get: function() { return window.kcContext["x-keycloakify"].resourcesPath; },
set: function() {} set: function() {}
}); });
} }
@ -396,7 +396,6 @@ describe("css replacer", () => {
} }
`, `,
cssFileRelativeDirPath: "assets/", cssFileRelativeDirPath: "assets/",
isAccountV3: false,
buildContext: { buildContext: {
urlPathname: undefined urlPathname: undefined
} }
@ -435,7 +434,6 @@ describe("css replacer", () => {
} }
`, `,
cssFileRelativeDirPath: "assets/", cssFileRelativeDirPath: "assets/",
isAccountV3: false,
buildContext: { buildContext: {
urlPathname: "/a/b/" urlPathname: "/a/b/"
} }
@ -474,7 +472,6 @@ describe("css replacer", () => {
} }
`, `,
cssFileRelativeDirPath: undefined, cssFileRelativeDirPath: undefined,
isAccountV3: false,
buildContext: { buildContext: {
urlPathname: "/a/b/" urlPathname: "/a/b/"
} }
@ -482,15 +479,15 @@ describe("css replacer", () => {
const fixedCssCodeExpected = ` const fixedCssCodeExpected = `
.my-div { .my-div {
background: url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/background.png) no-repeat center center; background: url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/background.png) no-repeat center center;
} }
.my-div2 { .my-div2 {
background: url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/background.png) repeat center center; background: url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/background.png) repeat center center;
} }
.my-div3 { .my-div3 {
background-image: url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/media/something.svg); background-image: url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/media/something.svg);
} }
`; `;
@ -513,7 +510,6 @@ describe("css replacer", () => {
} }
`, `,
cssFileRelativeDirPath: undefined, cssFileRelativeDirPath: undefined,
isAccountV3: false,
buildContext: { buildContext: {
urlPathname: undefined urlPathname: undefined
} }
@ -521,15 +517,15 @@ describe("css replacer", () => {
const fixedCssCodeExpected = ` const fixedCssCodeExpected = `
.my-div { .my-div {
background: url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/background.png) no-repeat center center; background: url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/background.png) no-repeat center center;
} }
.my-div2 { .my-div2 {
background: url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/background.png) repeat center center; background: url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/background.png) repeat center center;
} }
.my-div3 { .my-div3 {
background-image: url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/media/something.svg); background-image: url(\${xKeycloakify.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/media/something.svg);
} }
`; `;