keycloak_theme/src/lib/kcContext.ts

102 lines
3.0 KiB
TypeScript
Raw Normal View History

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-02-23 15:32:37 +01:00
import type { generateFtlFilesCodeFactory } from "../bin/build-keycloak-theme/generateFtl";
import { id } from "evt/tools/typeSafety/id";
2021-03-04 18:15:48 +01:00
import type { KcLanguageTag } from "./i18n/KcLanguageTag";
2021-02-23 15:32:37 +01:00
2021-03-02 23:48:31 +01:00
export type KcContext = {
2021-02-23 15:32:37 +01:00
pageBasename: Parameters<ReturnType<typeof generateFtlFilesCodeFactory>["generateFtlFilesCode"]>[0]["pageBasename"];
url: {
loginAction: string;
resourcesPath: string;
resourcesCommonPath: string;
loginRestartFlowUrl: string;
2021-03-02 22:48:36 +01:00
loginResetCredentialsUrl: string;
registrationUrl: string;
2021-03-04 18:15:48 +01:00
//Specific to register
registrationAction: string;
loginUrl: string;
2021-03-02 22:48:36 +01:00
};
realm: {
displayName?: string;
displayNameHtml?: string;
internationalizationEnabled: boolean;
2021-03-02 22:48:36 +01:00
password: boolean;
loginWithEmailAllowed: boolean;
registrationEmailAsUsername: boolean;
rememberMe: boolean;
resetPasswordAllowed: boolean;
};
2021-03-01 20:45:37 +01:00
/** Undefined if !realm.internationalizationEnabled */
locale?: {
supported: {
2021-03-01 20:45:37 +01:00
//url: string;
2021-03-02 23:48:31 +01:00
languageTag: KcLanguageTag;
2021-03-01 20:45:37 +01:00
/** Is determined by languageTag. Ex: languageTag === "en" => label === "English"
* or getLanguageLabel(languageTag) === label
*/
//label: LanguageLabel;
}[];
//NOTE: We do not expose this because the language is managed
//client side. We use this value however to set the default.
//current: LanguageLabel;
},
auth?: {
showUsername: boolean;
showResetCredentials: boolean;
showTryAnotherWayLink: boolean;
attemptedUsername?: boolean;
2021-03-02 22:48:36 +01:00
selectedCredential?: string;
};
scripts: string[];
message?: {
type: "success" | "warning" | "error" | "info";
summary: string;
2021-03-02 22:48:36 +01:00
};
isAppInitiatedAction: boolean;
2021-03-02 22:48:36 +01:00
social: {
displayInfo: boolean;
providers?: {
loginUrl: string;
alias: string;
providerId: string;
displayName: string;
}[]
};
usernameEditDisabled: boolean;
login: {
username?: string;
rememberMe: boolean;
};
registrationDisabled: boolean;
2021-03-04 18:15:48 +01:00
//Specific to register
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;
recaptchaSiteKey: string;
2021-02-23 15:32:37 +01:00
};
2021-03-02 23:48:31 +01:00
export const kcContext = id<KcContext | undefined>((window as any)[ftlValuesGlobalName]);