2023-03-18 18:27:50 +01:00
|
|
|
import type { KcContext } from "./KcContext";
|
2023-03-19 23:12:45 +01:00
|
|
|
import type { AndByDiscriminatingKey } from "keycloakify/tools/AndByDiscriminatingKey";
|
|
|
|
import { ftlValuesGlobalName } from "keycloakify/bin/keycloakify/ftlValuesGlobalName";
|
2021-11-07 20:17:14 +01:00
|
|
|
|
2023-03-19 14:48:01 +01:00
|
|
|
export type ExtendKcContext<KcContextExtension extends { pageId: string }> = [KcContextExtension] extends [never]
|
2023-03-18 18:27:50 +01:00
|
|
|
? KcContext
|
|
|
|
: AndByDiscriminatingKey<"pageId", KcContextExtension & KcContext.Common, KcContext>;
|
2021-11-07 20:17:14 +01:00
|
|
|
|
2023-03-19 14:48:01 +01:00
|
|
|
export function getKcContextFromWindow<KcContextExtension extends { pageId: string } = never>(): ExtendKcContext<KcContextExtension> | undefined {
|
2021-11-07 20:17:14 +01:00
|
|
|
return typeof window === "undefined" ? undefined : (window as any)[ftlValuesGlobalName];
|
|
|
|
}
|