Fix build for real

This commit is contained in:
garronej
2023-03-18 16:17:33 +01:00
parent 4f0b1688db
commit 43e4dd6bb6
10 changed files with 154 additions and 102 deletions

View File

@ -3,7 +3,7 @@ import { clsx } from "keycloakify/tools/clsx";
import { usePrepareTemplate } from "keycloakify/lib/usePrepareTemplate";
import { type TemplateProps, defaultTemplateClasses } from "keycloakify/TemplateProps";
import { useGetClassName } from "keycloakify/lib/useGetClassName";
type KcContext = import("./kcContext/KcContextBase").KcContextBase.Common.Login;
type KcContext = import("./kcContext/KcContextBase").KcContextBase.Common;
import type { I18nBase as I18n } from "./i18n";
export default function Template(props: TemplateProps<KcContext, I18n>) {

View File

@ -2,7 +2,7 @@ import type { ReactNode } from "react";
import type { KcContextBase } from "keycloakify/kcContext";
import type { I18nBase } from "keycloakify/i18n";
export type TemplateProps<KcContext extends KcContextBase.Common.Login, I18n extends I18nBase> = {
export type TemplateProps<KcContext extends KcContextBase.Common, I18n extends I18nBase> = {
kcContext: KcContext;
i18n: I18n;
doUseDefaultCss: boolean;

View File

@ -40,7 +40,7 @@ export const loginThemePageIds = [
export const accountThemePageIds = ["password.ftl"] as const;
export type LoginThemePageId = (typeof loginThemePageIds)[number];
export type PageId = (typeof loginThemePageIds)[number];
export type AccountThemePageId = (typeof accountThemePageIds)[number];
export type BuildOptionsLike = BuildOptionsLike.Standalone | BuildOptionsLike.ExternalAssets;

View File

@ -72,6 +72,10 @@ export async function generateKeycloakThemeResources(params: {
let generateFtlFilesCode_glob: ReturnType<typeof generateFtlFilesCodeFactory>["generateFtlFilesCode"] | undefined = undefined;
for (const themeType of themeTypes) {
if (themeType === "account") {
continue;
}
const themeDirPath = getThemeDirPath(themeType);
copy_app_resources_to_theme_path: {

View File

@ -1,4 +1,4 @@
import type { LoginThemePageId, AccountThemePageId } from "../bin/keycloakify/generateFtl";
import type { PageId } from "../bin/keycloakify/generateFtl";
import { assert } from "tsafe/assert";
import type { Equals } from "tsafe";
import type { MessageKeyBase } from "../i18n";
@ -30,73 +30,59 @@ export type KcContextBase =
| KcContextBase.LoginConfigTotp
| KcContextBase.LogoutConfirm
| KcContextBase.UpdateUserProfile
| KcContextBase.IdpReviewUserProfile
| KcContextBase.Password;
| KcContextBase.IdpReviewUserProfile;
export declare namespace KcContextBase {
export namespace Common {
export type Login = {
url: {
loginAction: string;
resourcesPath: string;
resourcesCommonPath: string;
loginRestartFlowUrl: string;
loginUrl: string;
};
realm: {
name: string;
displayName?: string;
displayNameHtml?: string;
internationalizationEnabled: boolean;
registrationEmailAsUsername: boolean;
};
/** Undefined if !realm.internationalizationEnabled */
locale?: {
supported: {
url: string;
label: string;
languageTag: string;
}[];
currentLanguageTag: string;
};
auth?: {
showUsername?: boolean;
showResetCredentials?: boolean;
showTryAnotherWayLink?: boolean;
attemptedUsername?: string;
};
scripts: string[];
message?: {
type: "success" | "warning" | "error" | "info";
summary: string;
};
client: {
clientId: string;
name?: string;
description?: string;
};
isAppInitiatedAction: boolean;
messagesPerField: {
printIfExists: <T>(fieldName: string, x: T) => T | undefined;
existsError: (fieldName: string) => boolean;
get: (fieldName: string) => string;
exists: (fieldName: string) => boolean;
};
export type Common = {
url: {
loginAction: string;
resourcesPath: string;
resourcesCommonPath: string;
loginRestartFlowUrl: string;
loginUrl: string;
};
export type Account = {
locale?: {
currentLanguageTag: string;
supported: { languageTag: string; url: string; label: string }[];
};
url: {
resourcesPath: string;
resourcesCommonPath: string;
};
realm: {
name: string;
displayName?: string;
displayNameHtml?: string;
internationalizationEnabled: boolean;
registrationEmailAsUsername: boolean;
};
}
/** Undefined if !realm.internationalizationEnabled */
locale?: {
supported: {
url: string;
label: string;
languageTag: string;
}[];
currentLanguageTag: string;
};
auth?: {
showUsername?: boolean;
showResetCredentials?: boolean;
showTryAnotherWayLink?: boolean;
attemptedUsername?: string;
};
scripts: string[];
message?: {
type: "success" | "warning" | "error" | "info";
summary: string;
};
client: {
clientId: string;
name?: string;
description?: string;
};
isAppInitiatedAction: boolean;
messagesPerField: {
printIfExists: <T>(fieldName: string, x: T) => T | undefined;
existsError: (fieldName: string) => boolean;
get: (fieldName: string) => string;
exists: (fieldName: string) => boolean;
};
};
export type Login = Common.Login & {
export type Login = Common & {
pageId: "login.ftl";
url: {
loginResetCredentialsUrl: string;
@ -152,7 +138,7 @@ export declare namespace KcContextBase {
};
export namespace RegisterUserProfile {
export type CommonWithLegacy = Common.Login & {
export type CommonWithLegacy = Common & {
url: {
registrationAction: string;
};
@ -171,7 +157,7 @@ export declare namespace KcContextBase {
};
}
export type Info = Common.Login & {
export type Info = Common & {
pageId: "info.ftl";
messageHeader?: string;
requiredActions?: ExtractAfterStartingWith<"requiredAction.", MessageKeyBase>[];
@ -183,22 +169,22 @@ export declare namespace KcContextBase {
};
};
export type Error = Common.Login & {
export type Error = Common & {
pageId: "error.ftl";
client?: {
baseUrl?: string;
};
message: NonNullable<Common.Login["message"]>;
message: NonNullable<Common["message"]>;
};
export type LoginResetPassword = Common.Login & {
export type LoginResetPassword = Common & {
pageId: "login-reset-password.ftl";
realm: {
loginWithEmailAllowed: boolean;
};
};
export type LoginVerifyEmail = Common.Login & {
export type LoginVerifyEmail = Common & {
pageId: "login-verify-email.ftl";
//NOTE: Optional because maybe it wasn't defined in older keycloak versions.
user?: {
@ -206,18 +192,18 @@ export declare namespace KcContextBase {
};
};
export type Terms = Common.Login & {
export type Terms = Common & {
pageId: "terms.ftl";
};
export type LoginOtp = Common.Login & {
export type LoginOtp = Common & {
pageId: "login-otp.ftl";
otpLogin: {
userOtpCredentials: { id: string; userLabel: string }[];
};
};
export type LoginUsername = Common.Login & {
export type LoginUsername = Common & {
pageId: "login-username.ftl";
url: {
loginResetCredentialsUrl: string;
@ -247,7 +233,7 @@ export declare namespace KcContextBase {
};
};
export type LoginPassword = Common.Login & {
export type LoginPassword = Common & {
pageId: "login-password.ftl";
url: {
loginResetCredentialsUrl: string;
@ -270,7 +256,7 @@ export declare namespace KcContextBase {
};
};
export type WebauthnAuthenticate = Common.Login & {
export type WebauthnAuthenticate = Common & {
pageId: "webauthn-authenticate.ftl";
authenticators: {
authenticators: WebauthnAuthenticate.WebauthnAuthenticator[];
@ -300,12 +286,12 @@ export declare namespace KcContextBase {
};
}
export type LoginUpdatePassword = Common.Login & {
export type LoginUpdatePassword = Common & {
pageId: "login-update-password.ftl";
username: string;
};
export type LoginUpdateProfile = Common.Login & {
export type LoginUpdateProfile = Common & {
pageId: "login-update-profile.ftl";
user: {
editUsernameAllowed: boolean;
@ -316,12 +302,12 @@ export declare namespace KcContextBase {
};
};
export type LoginIdpLinkConfirm = Common.Login & {
export type LoginIdpLinkConfirm = Common & {
pageId: "login-idp-link-confirm.ftl";
idpAlias: string;
};
export type LoginIdpLinkEmail = Common.Login & {
export type LoginIdpLinkEmail = Common & {
pageId: "login-idp-link-email.ftl";
brokerContext: {
username: string;
@ -329,11 +315,11 @@ export declare namespace KcContextBase {
idpAlias: string;
};
export type LoginPageExpired = Common.Login & {
export type LoginPageExpired = Common & {
pageId: "login-page-expired.ftl";
};
export type LoginConfigTotp = Common.Login & {
export type LoginConfigTotp = Common & {
pageId: "login-config-totp.ftl";
mode?: "qr" | "manual" | undefined | null;
totp: {
@ -361,7 +347,7 @@ export declare namespace KcContextBase {
};
};
export type LogoutConfirm = Common.Login & {
export type LogoutConfirm = Common & {
pageId: "logout-confirm.ftl";
url: {
logoutConfirmAction: string;
@ -375,7 +361,7 @@ export declare namespace KcContextBase {
};
};
export type UpdateUserProfile = Common.Login & {
export type UpdateUserProfile = Common & {
pageId: "update-user-profile.ftl";
profile: {
attributes: Attribute[];
@ -383,7 +369,7 @@ export declare namespace KcContextBase {
};
};
export type IdpReviewUserProfile = Common.Login & {
export type IdpReviewUserProfile = Common & {
pageId: "idp-review-user-profile.ftl";
profile: {
context: "IDP_REVIEW";
@ -391,13 +377,6 @@ export declare namespace KcContextBase {
attributesByName: Record<string, Attribute>;
};
};
export type Password = Common.Account & {
pageId: "password.ftl";
url: {
passwordUrl: string;
};
};
}
export type Attribute = {
@ -517,4 +496,4 @@ export declare namespace Validators {
};
}
assert<Equals<KcContextBase["pageId"], LoginThemePageId | AccountThemePageId>>();
assert<Equals<KcContextBase["pageId"], PageId>>();

View File

@ -4,7 +4,7 @@ import { ftlValuesGlobalName } from "../bin/keycloakify/ftlValuesGlobalName";
export type ExtendsKcContextBase<KcContextExtended extends { pageId: string }> = [KcContextExtended] extends [never]
? KcContextBase
: AndByDiscriminatingKey<"pageId", KcContextExtended & KcContextBase.Common.Login, KcContextBase>;
: AndByDiscriminatingKey<"pageId", KcContextExtended & KcContextBase.Common, KcContextBase>;
export function getKcContextFromWindow<KcContextExtended extends { pageId: string } = never>(): ExtendsKcContextBase<KcContextExtended> | undefined {
return typeof window === "undefined" ? undefined : (window as any)[ftlValuesGlobalName];

View File

@ -101,7 +101,7 @@ const attributes: Attribute[] = [
const attributesByName = Object.fromEntries(attributes.map(attribute => [attribute.name, attribute])) as any;
export const kcContextCommonMock: KcContextBase.Common.Login = {
export const kcContextCommonMock: KcContextBase.Common = {
"url": {
"loginAction": "#",
"resourcesPath": pathJoin(PUBLIC_URL, mockTestingResourcesPath),

View File

@ -14,7 +14,7 @@ import type { I18nBase as I18n } from "../i18n";
*/
export function useFormValidation(params: {
kcContext: {
messagesPerField: Pick<KcContext.Common.Login["messagesPerField"], "existsError" | "get">;
messagesPerField: Pick<KcContext.Common["messagesPerField"], "existsError" | "get">;
profile: {
attributes: Attribute[];
};
@ -187,7 +187,7 @@ export function useFormValidation(params: {
/** Expect to be used in a component wrapped within a <I18nProvider> */
function useGetErrors(params: {
kcContext: {
messagesPerField: Pick<KcContext.Common.Login["messagesPerField"], "existsError" | "get">;
messagesPerField: Pick<KcContext.Common["messagesPerField"], "existsError" | "get">;
profile: {
attributes: { name: string; value?: string; validators: Validators }[];
};