2021-06-23 08:16:51 +02:00
|
|
|
|
|
|
|
|
|
import type { KcContextBase } from "./KcContextBase";
|
|
|
|
|
import { kcContextMocks, kcContextCommonMock } from "./kcContextMocks";
|
|
|
|
|
import { ftlValuesGlobalName } from "../../bin/build-keycloak-theme/ftlValuesGlobalName";
|
|
|
|
|
|
|
|
|
|
export function getKcContext<KcContextExtended extends { pageId: string; } = never>(
|
|
|
|
|
params?: {
|
2021-06-23 18:03:49 +02:00
|
|
|
|
mockPageId?: KcContextBase["pageId"] | KcContextExtended["pageId"];
|
2021-06-23 08:16:51 +02:00
|
|
|
|
kcContextExtendedMock?: KcContextExtended[];
|
|
|
|
|
}
|
2021-06-23 18:03:49 +02:00
|
|
|
|
): { kcContext: (KcContextBase | KcContextExtended & KcContextBase.Common) | undefined; } {
|
2021-06-23 08:16:51 +02:00
|
|
|
|
|
|
|
|
|
const { mockPageId, kcContextExtendedMock } = params ?? { "mockPageId": false };
|
|
|
|
|
|
2021-06-23 18:03:49 +02:00
|
|
|
|
if (mockPageId !== undefined) {
|
2021-06-23 08:16:51 +02:00
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"pageId": mockPageId,
|
|
|
|
|
...(kcContextMocks.find(({ pageId }) => pageId === mockPageId) ?? kcContextCommonMock),
|
|
|
|
|
...(kcContextExtendedMock?.find(({ pageId }) => pageId === mockPageId) ?? {})
|
|
|
|
|
} as any;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (window as any)[ftlValuesGlobalName];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|