2021-02-23 15:32:37 +01:00
|
|
|
|
2021-03-02 12:17:24 +01:00
|
|
|
import { ftlValuesGlobalName } from "../bin/build-keycloak-theme/ftlValuesGlobalName";
|
2021-03-06 22:41:36 +01:00
|
|
|
import type { PageId } from "../bin/build-keycloak-theme/generateFtl";
|
2021-02-24 00:27:16 +01:00
|
|
|
import { id } from "evt/tools/typeSafety/id";
|
2021-03-04 18:15:48 +01:00
|
|
|
import type { KcLanguageTag } from "./i18n/KcLanguageTag";
|
2021-03-04 21:14:54 +01:00
|
|
|
import { doExtends } from "evt/tools/typeSafety/doExtends";
|
2021-03-07 15:37:37 +01:00
|
|
|
import type { MessageKey } from "./i18n/useKcMessage";
|
|
|
|
import type { LanguageLabel } from "./i18n/KcLanguageTag";
|
2021-02-23 15:32:37 +01:00
|
|
|
|
2021-03-07 15:37:37 +01:00
|
|
|
type ExtractAfterStartingWith<Prefix extends string, StrEnum> =
|
2021-03-06 14:42:56 +01:00
|
|
|
StrEnum extends `${Prefix}${infer U}` ? U : never;
|
2021-02-23 15:32:37 +01:00
|
|
|
|
2021-03-07 15:37:37 +01:00
|
|
|
export type KcContext =
|
|
|
|
KcContext.Login | KcContext.Register | KcContext.Info |
|
|
|
|
KcContext.Error | KcContext.LoginResetPassword | KcContext.LoginVerifyEmail;
|
2021-03-04 21:14:54 +01:00
|
|
|
export declare namespace KcContext {
|
|
|
|
|
|
|
|
export type Template = {
|
|
|
|
url: {
|
|
|
|
loginAction: string;
|
|
|
|
resourcesPath: string;
|
|
|
|
resourcesCommonPath: string;
|
|
|
|
loginRestartFlowUrl: string;
|
2021-03-02 22:48:36 +01:00
|
|
|
loginUrl: string;
|
2021-03-04 21:14:54 +01:00
|
|
|
};
|
|
|
|
realm: {
|
2021-03-04 18:15:48 +01:00
|
|
|
displayName?: string;
|
2021-03-04 21:14:54 +01:00
|
|
|
displayNameHtml?: string;
|
|
|
|
internationalizationEnabled: boolean;
|
2021-03-06 23:03:03 +01:00
|
|
|
registrationEmailAsUsername: boolean; //<---
|
2021-03-04 21:14:54 +01:00
|
|
|
};
|
|
|
|
/** Undefined if !realm.internationalizationEnabled */
|
|
|
|
locale?: {
|
|
|
|
supported: {
|
2021-03-05 19:50:08 +01:00
|
|
|
url: string;
|
2021-03-04 21:14:54 +01:00
|
|
|
languageTag: KcLanguageTag;
|
|
|
|
/** Is determined by languageTag. Ex: languageTag === "en" => label === "English"
|
|
|
|
* or getLanguageLabel(languageTag) === label
|
|
|
|
*/
|
|
|
|
//label: LanguageLabel;
|
|
|
|
}[];
|
2021-03-06 15:16:21 +01:00
|
|
|
current: LanguageLabel;
|
2021-03-04 21:14:54 +01:00
|
|
|
},
|
|
|
|
auth?: {
|
|
|
|
showUsername: boolean;
|
|
|
|
showResetCredentials: boolean;
|
|
|
|
showTryAnotherWayLink: boolean;
|
2021-03-07 14:57:53 +01:00
|
|
|
attemptedUsername?: string;
|
2021-03-04 21:14:54 +01:00
|
|
|
};
|
|
|
|
scripts: string[];
|
|
|
|
message?: {
|
|
|
|
type: "success" | "warning" | "error" | "info";
|
|
|
|
summary: string;
|
|
|
|
};
|
|
|
|
isAppInitiatedAction: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type Login = Template & {
|
2021-03-06 22:41:36 +01:00
|
|
|
pageId: "login.ftl";
|
2021-03-04 21:14:54 +01:00
|
|
|
url: {
|
|
|
|
loginResetCredentialsUrl: string;
|
|
|
|
registrationUrl: string;
|
|
|
|
};
|
|
|
|
realm: {
|
|
|
|
loginWithEmailAllowed: boolean;
|
|
|
|
rememberMe: boolean;
|
2021-03-06 23:03:03 +01:00
|
|
|
password: boolean;
|
2021-03-04 21:14:54 +01:00
|
|
|
resetPasswordAllowed: boolean;
|
2021-03-04 23:24:43 +01:00
|
|
|
registrationAllowed: boolean;
|
2021-03-04 21:14:54 +01:00
|
|
|
};
|
|
|
|
auth: {
|
|
|
|
selectedCredential?: string;
|
|
|
|
};
|
|
|
|
registrationDisabled: boolean;
|
|
|
|
login: {
|
2021-03-04 18:15:48 +01:00
|
|
|
username?: string;
|
2021-03-04 21:14:54 +01:00
|
|
|
rememberMe: boolean;
|
|
|
|
};
|
|
|
|
usernameEditDisabled: boolean;
|
|
|
|
social: {
|
|
|
|
displayInfo: boolean;
|
|
|
|
providers?: {
|
|
|
|
loginUrl: string;
|
|
|
|
alias: string;
|
|
|
|
providerId: string;
|
|
|
|
displayName: string;
|
|
|
|
}[]
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export type Register = Template & {
|
2021-03-06 22:41:36 +01:00
|
|
|
pageId: "register.ftl";
|
2021-03-04 21:14:54 +01:00
|
|
|
url: {
|
|
|
|
registrationAction: string;
|
|
|
|
};
|
|
|
|
messagesPerField: {
|
|
|
|
printIfExists<T>(
|
|
|
|
key:
|
|
|
|
"userLabel" |
|
|
|
|
"username" |
|
|
|
|
"email" |
|
|
|
|
"firstName" |
|
|
|
|
"lastName" |
|
|
|
|
"password" |
|
|
|
|
"password-confirm",
|
|
|
|
x: T
|
|
|
|
): T | undefined;
|
|
|
|
};
|
|
|
|
register: {
|
|
|
|
formData: {
|
|
|
|
firstName?: string;
|
|
|
|
displayName?: string;
|
|
|
|
lastName?: string;
|
|
|
|
email?: string;
|
|
|
|
username?: string;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
passwordRequired: boolean;
|
|
|
|
recaptchaRequired: boolean;
|
2021-03-05 14:50:46 +01:00
|
|
|
/** undefined if !recaptchaRequired */
|
|
|
|
recaptchaSiteKey?: string;
|
2021-03-04 18:15:48 +01:00
|
|
|
};
|
2021-03-04 21:14:54 +01:00
|
|
|
|
2021-03-06 14:42:56 +01:00
|
|
|
export type Info = Template & {
|
2021-03-06 22:41:36 +01:00
|
|
|
pageId: "info.ftl";
|
2021-03-06 14:42:56 +01:00
|
|
|
messageHeader?: string;
|
2021-03-07 15:37:37 +01:00
|
|
|
requiredActions?: ExtractAfterStartingWith<"requiredAction.", MessageKey>[];
|
2021-03-06 14:42:56 +01:00
|
|
|
skipLink: boolean;
|
|
|
|
pageRedirectUri?: string;
|
|
|
|
actionUri?: string;
|
|
|
|
client: {
|
|
|
|
baseUrl?: string;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-06 22:41:36 +01:00
|
|
|
export type Error = Template & {
|
2021-03-06 23:03:03 +01:00
|
|
|
pageId: "error.ftl";
|
|
|
|
client?: {
|
|
|
|
baseUrl?: string;
|
|
|
|
}
|
2021-03-06 22:41:36 +01:00
|
|
|
};
|
2021-03-04 21:14:54 +01:00
|
|
|
|
2021-03-07 14:57:53 +01:00
|
|
|
export type LoginResetPassword = Template & {
|
|
|
|
pageId: "login-reset-password.ftl";
|
|
|
|
realm: {
|
|
|
|
loginWithEmailAllowed: boolean;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-07 15:37:37 +01:00
|
|
|
export type LoginVerifyEmail = Template & {
|
|
|
|
pageId: "login-verify-email.ftl";
|
|
|
|
};
|
|
|
|
|
2021-03-04 21:14:54 +01:00
|
|
|
}
|
2021-02-23 15:32:37 +01:00
|
|
|
|
2021-03-06 22:41:36 +01:00
|
|
|
doExtends<KcContext["pageId"], PageId>();
|
|
|
|
doExtends<PageId, KcContext["pageId"]>();
|
|
|
|
|
2021-03-02 23:48:31 +01:00
|
|
|
export const kcContext = id<KcContext | undefined>((window as any)[ftlValuesGlobalName]);
|