Merge branch 'doge_ftl_errors' of https://github.com/garronej/keycloakify into doge_ftl_errors

This commit is contained in:
garronej 2021-12-09 02:01:01 +01:00
commit e12f01181d
3 changed files with 35 additions and 58 deletions

2
.gitignore vendored
View File

@ -44,3 +44,5 @@ jspm_packages
/sample_react_project/ /sample_react_project/
/.yarn_home/ /.yarn_home/
.idea

View File

@ -1,7 +1,6 @@
<script>const _= <script>const _=
<#macro objectToJson_please_ignore_errors object depth> <#macro objectToJson_please_ignore_errors object depth arr ftl>
<@compress> <@compress>
<#local isHash = false> <#local isHash = false>
<#attempt> <#attempt>
<#local isHash = object?is_hash || object?is_hash_ex> <#local isHash = object?is_hash || object?is_hash_ex>
@ -11,9 +10,7 @@
<#return> <#return>
</#attempt> </#attempt>
<#if isHash> <#if isHash>
<#local keys = ""> <#local keys = "">
<#attempt> <#attempt>
<#local keys = object?keys> <#local keys = object?keys>
<#recover> <#recover>
@ -21,41 +18,42 @@
undefined undefined
<#return> <#return>
</#attempt> </#attempt>
<#if arr?sequence?size gte 1>
<#local keys = arr>
</#if>
{${'\n'} {${'\n'}
<#list keys as key> <#list keys as key>
<#if key == "class"> <#if key == "class">
/* skipping "class" property of object */ /* skipping "class" property of object */
<#continue> <#continue>
</#if> </#if>
<#local value = "">
<#attempt> <#attempt>
<#local value = object[key]> <#local value = object[key]!"error_data_is_undefined">
<#recover> <#recover>
/* couldn't dereference ${key} of object */ /* couldn't dereference ${key} of object */
<#continue> <#continue>
</#attempt> </#attempt>
<#if depth gt 7> <#if depth gt 7>
/* Avoid calling recustively too many times depth: ${depth}, key: ${key} */ /* Avoid calling recustively too many times depth: ${depth}, key: ${key} */
<#continue> <#continue>
</#if> </#if>
<#local arr_keys = []>
"${key}": <@objectToJson_please_ignore_errors object=value depth=depth+1/>, <#if depth==0 && key=="url" && ftl=="saml-post-form.ftl" >
<#local arr_keys = ["resourcesPath", "resourcesCommonPath", "loginRestartFlowUrl", "loginUrl", "loginResetCredentialsUrl", "registrationUrl", "registrationAction", "oauth2DeviceVerificationAction", "oauthAction", "loginResetCredentialsUrl"]>
<#elseif depth==0 && key=="url">
<#local arr_keys = ["loginAction", "resourcesPath", "resourcesCommonPath", "loginRestartFlowUrl", "loginUrl", "loginResetCredentialsUrl", "registrationUrl", "registrationAction", "oauth2DeviceVerificationAction", "oauthAction", "loginResetCredentialsUrl"]>
</#if>
<#if depth==0 && key=="auth" && ftl=="login-reset-password.ftl" >
<#local arr_keys = ["showUsername", "showResetCredentials", "showTryAnotherWayLink", "attemptedUsername"]>
<#elseif depth==0 && key=="auth">
<#local arr_keys = ["showUsername", "showResetCredentials", "showTryAnotherWayLink"]>
</#if>
<#if depth==0 && key=="updateProfileCtx" ><#continue></#if>
"${key}": <@objectToJson_please_ignore_errors object=value depth=depth+1 arr=arr_keys ftl=ftl />,
</#list> </#list>
}${'\n'} }${'\n'}
<#return> <#return>
</#if> </#if>
<#local isMethod = ""> <#local isMethod = "">
<#attempt> <#attempt>
<#local isMethod = object?is_method> <#local isMethod = object?is_method>
@ -64,14 +62,10 @@
undefined undefined
<#return> <#return>
</#attempt> </#attempt>
<#if isMethod> <#if isMethod>
undefined undefined
<#return> <#return>
</#if> </#if>
<#local isBoolean = ""> <#local isBoolean = "">
<#attempt> <#attempt>
<#local isBoolean = object?is_boolean> <#local isBoolean = object?is_boolean>
@ -80,13 +74,10 @@
undefined undefined
<#return> <#return>
</#attempt> </#attempt>
<#if isBoolean> <#if isBoolean>
${object?c} ${object?c}
<#return> <#return>
</#if> </#if>
<#local isEnumerable = ""> <#local isEnumerable = "">
<#attempt> <#attempt>
<#local isEnumerable = object?is_enumerable> <#local isEnumerable = object?is_enumerable>
@ -95,23 +86,14 @@
undefined undefined
<#return> <#return>
</#attempt> </#attempt>
<#if isEnumerable> <#if isEnumerable>
[${'\n'} [${'\n'}
<#list object as item> <#list object as item>
<@objectToJson_please_ignore_errors object=item depth=depth+1 arr=[] ftl=ftl/>,
<@objectToJson_please_ignore_errors object=item depth=depth+1/>,
</#list> </#list>
]${'\n'} ]${'\n'}
<#return> <#return>
</#if> </#if>
<#attempt> <#attempt>
"${object?replace('"', '\\"')?no_esc}" "${object?replace('"', '\\"')?no_esc}"
<#recover> <#recover>
@ -119,25 +101,21 @@
undefined; undefined;
<#return> <#return>
</#attempt> </#attempt>
</@compress> </@compress>
</#macro> </#macro>
(()=>{ (()=>{
const nonAutomaticallyConvertible = {
const nonAutomaticallyConvertible = {
"messagesPerField": { "messagesPerField": {
<#assign fieldNames = ["global", "userLabel", "username", "email", "firstName", "lastName", "password", "password-confirm", "totp", "totpSecret", "SAMLRequest", "SAMLResponse", "relayState", "device_user_code", "code", "password-new", "rememberMe", "login", "authenticationExecution", "cancel-aia", "clientDataJSON", "authenticatorData", "signature", "credentialId", "userHandle", "error", "authn_use_chk", "authenticationExecution", "isSetRetry", "try-again", "attestationObject", "publicKeyCredentialId", "authenticatorLabel"]>
<#assign fieldNames = ["global", "userLabel", "username", "email", "firstName", "lastName", "password", "password-confirm"]> <#assign attributes = (profile.attributes)![]>
<#attempt> <#attempt>
<#list profile.attributes as attribute> <#list attributes as attribute>
<#assign fieldNames += [attribute.name]> <#if (attribute.name)??>
<#assign fieldNames += [attribute.name]>
</#if>
</#list> </#list>
<#recover> <#recover>
</#attempt> </#attempt>
"printIfExists": function (fieldName, x) { "printIfExists": function (fieldName, x) {
<#list fieldNames as fieldName> <#list fieldNames as fieldName>
if(fieldName === "${fieldName}" ){ if(fieldName === "${fieldName}" ){
@ -185,24 +163,19 @@
throw new Error("There is no " + fieldName + " field"); throw new Error("There is no " + fieldName + " field");
} }
}, },
"msg": function(){ throw new Error("use import { useKcMessage } from 'keycloakify'"); }, "msg": function(){ throw new Error("use import { useKcMessage } from 'keycloakify'"); },
"advancedMsg": function(){ throw new Error("use import { useKcMessage } from 'keycloakify'"); } "advancedMsg": function(){ throw new Error("use import { useKcMessage } from 'keycloakify'"); }
}; };
const out = {}; const out = {};
Object.deepAssign( Object.deepAssign(
out, out,
//Removing all the undefined //Removing all the undefined
JSON.parse(JSON.stringify(<@objectToJson_please_ignore_errors object=.data_model depth=0 />)) JSON.parse(JSON.stringify(<@objectToJson_please_ignore_errors object=.data_model depth=0 arr=[] ftl="ftl_template_for_replacement" />), (key, value) => value === "error_data_is_undefined" ? undefined : value)
); );
Object.deepAssign( Object.deepAssign(
out, out,
nonAutomaticallyConvertible nonAutomaticallyConvertible
); );
return out; return out;
})() })()
</script> </script>

View File

@ -141,7 +141,9 @@ export function generateFtlFilesCodeFactory(params: {
].join("\n"), ].join("\n"),
); );
objectKeys(ftlPlaceholders).forEach(id => (ftlCode = ftlCode.replace(id, ftlPlaceholders[id]))); objectKeys(ftlPlaceholders).forEach(
id => (ftlCode = ftlCode.replace(id, ftlPlaceholders[id]).replace("ftl_template_for_replacement", pageId)),
);
return { ftlCode }; return { ftlCode };
} }