Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
341d985610 | |||
76b9a78182 | |||
021c0a9429 | |||
7b3462d158 | |||
c180dee414 | |||
769da5c5ca | |||
1a4dd79240 | |||
5cf290b033 | |||
aec3da25b3 | |||
66d7cb563d | |||
551e9c041e | |||
fffb6d5b5e | |||
ac0bfeb360 | |||
7c30059ca3 | |||
fdb9ae6c40 | |||
3c82ffc0ab | |||
5dd3103aba | |||
84fc81f531 | |||
a20cbc62a5 | |||
e6a93e2838 | |||
3cff54561f | |||
e50a6a7876 | |||
b887ec839b |
4
.gitattributes
vendored
4
.gitattributes
vendored
@ -1,3 +1,3 @@
|
||||
src/lib/i18n/generated_messages/* linguist-documentation
|
||||
src/lib/i18n/generated_kcMessages/* linguist-documentation
|
||||
src/bin/build-keycloak-theme/index.ts -linguist-detectable
|
||||
src/bin/install-builtin-keycloak-themes.ts -linguist-detectable
|
||||
src/bin/build-keycloak-theme/index.ts -linguist-detectable
|
29
CHANGELOG.md
29
CHANGELOG.md
@ -1,3 +1,32 @@
|
||||
### **2.0.8** (2021-07-12)
|
||||
|
||||
- Fix previous release
|
||||
- #20: Add def for clientId and name on kcContext.client
|
||||
|
||||
### **2.0.6** (2021-07-08)
|
||||
|
||||
- Merge pull request #18 from asashay/add-custom-props-to-theme-properties
|
||||
|
||||
Add possibility to add custom properties to theme.properties file
|
||||
- add possibility to add custom properties to theme.properties file
|
||||
|
||||
### **2.0.5** (2021-07-05)
|
||||
|
||||
- Fix broken url for big stylesheet #16
|
||||
|
||||
### **2.0.4** (2021-07-03)
|
||||
|
||||
- Fix: #7
|
||||
|
||||
### **2.0.3** (2021-06-30)
|
||||
|
||||
- Escape double quote in ftl to js conversion #15
|
||||
- Update readme
|
||||
|
||||
### **2.0.2** (2021-06-28)
|
||||
|
||||
- Updagte README for implementing non incuded pages
|
||||
|
||||
### **2.0.1** (2021-06-28)
|
||||
|
||||
- Update documentation for v2
|
||||
|
14
README.md
14
README.md
@ -208,7 +208,9 @@ and the result you can expect:
|
||||
If you want to go beyond only customizing the CSS you can re-implement some of the
|
||||
pages or event add new ones.
|
||||
|
||||
If you want to go this way checkout the demo setup provided [here](https://github.com/garronej/keycloakify-demo-app/tree/look_and_feel)
|
||||
If you want to go this way checkout the demo setup provided [here](https://github.com/garronej/keycloakify-demo-app/tree/look_and_feel).
|
||||
If you prefer a real life example you can checkout [onyxia-web's source](https://github.com/InseeFrLab/onyxia-web/tree/main/src/app/components/KcApp).
|
||||
The web app is in production [here](https://datalab.sspcloud.fr).
|
||||
|
||||
Main takeaways are:
|
||||
- You must declare your custom pages in the package.json. [example](https://github.com/garronej/keycloakify-demo-app/blob/4eb2a9f63e9823e653b2d439495bda55e5ecc134/package.json#L17-L22)
|
||||
@ -286,16 +288,10 @@ Then to load your own therms of services using [like this](https://github.com/ga
|
||||
|
||||
# Some pages still have the default theme. Why?
|
||||
|
||||
**NEW in v1.2 it is now much more easy to add support for custom pages since the
|
||||
Keycloak context is now automatically converted into a JavaScript object (kcContext).
|
||||
In v2 (coming soon) it won't be required to fork for adding support for custom pages.**
|
||||
|
||||
This project only support the most common user facing pages of Keycloak login.
|
||||
This project only support out of the box the most common user facing pages of Keycloak login.
|
||||
[Here](https://user-images.githubusercontent.com/6702424/116787906-227fe700-aaa7-11eb-92ee-22e7673717c2.png) is the complete list of pages (you get them after running `yarn test`)
|
||||
and [here](https://github.com/InseeFrLab/keycloakify/tree/main/src/lib/components) are the pages currently implemented by this module.
|
||||
If you need to customize pages that are not supported yet you can submit an issue about it and wait for me get it implemented.
|
||||
If you can't wait, PR are welcome! [Here](https://github.com/InseeFrLab/keycloakify/commit/0163459ad6b1ad0afcc34fae5f3cc28dbcf8b4a7) is the commit that adds support
|
||||
for the `login-otp.ftl` page. You can use it as a model for implementing other pages.
|
||||
If you need to customize pages that are not supported yet or if you need to implement some non standard `.ftl` pages please refer to [Advanced pages configuration](#advanced-pages-configuration).
|
||||
|
||||
# GitHub Actions
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "keycloakify",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.8",
|
||||
"description": "Keycloak theme generator for Reacts app",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -19,6 +19,7 @@ export function main() {
|
||||
console.log("🔏 Building the keycloak theme...⌚");
|
||||
|
||||
const extraPagesId: string[] = (parsedPackageJson as any)["keycloakify"]?.["extraPages"] ?? [];
|
||||
const extraThemeProperties: string[] = (parsedPackageJson as any)["keycloakify"]?.["extraThemeProperties"] ?? [];
|
||||
|
||||
generateKeycloakThemeResources({
|
||||
keycloakThemeBuildingDirPath,
|
||||
@ -55,7 +56,8 @@ export function main() {
|
||||
};
|
||||
|
||||
})(),
|
||||
extraPagesId
|
||||
extraPagesId,
|
||||
extraThemeProperties
|
||||
});
|
||||
|
||||
const { jarFilePath } = generateJavaStackFiles({
|
||||
|
@ -113,7 +113,7 @@
|
||||
|
||||
|
||||
<#attempt>
|
||||
"${object?no_esc}"
|
||||
"${object?replace('"', '\\"')?no_esc}"
|
||||
<#recover>
|
||||
/* couldn't convert into string non hash, non method, non boolean, non enumerable object */
|
||||
undefined;
|
||||
|
@ -23,12 +23,13 @@ export function generateKeycloakThemeResources(
|
||||
//If urlOrigin is not undefined then it means --externals-assets
|
||||
urlOrigin: undefined | string;
|
||||
extraPagesId: string[];
|
||||
extraThemeProperties: string[];
|
||||
}
|
||||
) {
|
||||
|
||||
const {
|
||||
themeName, reactAppBuildDirPath, keycloakThemeBuildingDirPath,
|
||||
urlPathname, urlOrigin, extraPagesId
|
||||
urlPathname, urlOrigin, extraPagesId, extraThemeProperties
|
||||
} = params;
|
||||
|
||||
const themeDirPath = pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", themeName, "login");
|
||||
@ -166,7 +167,10 @@ export function generateKeycloakThemeResources(
|
||||
|
||||
fs.writeFileSync(
|
||||
pathJoin(themeDirPath, "theme.properties"),
|
||||
Buffer.from("parent=keycloak", "utf8")
|
||||
Buffer.from(
|
||||
"parent=keycloak".concat("\n\n", extraThemeProperties.join("\n\n")),
|
||||
"utf8"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
@ -5,19 +5,40 @@ import { ftlValuesGlobalName } from "./ftlValuesGlobalName";
|
||||
export function replaceImportsFromStaticInJsCode(
|
||||
params: {
|
||||
jsCode: string;
|
||||
urlOrigin: undefined | string;
|
||||
urlOrigin: undefined | string;
|
||||
}
|
||||
): { fixedJsCode: string; } {
|
||||
|
||||
/*
|
||||
NOTE:
|
||||
|
||||
When we have urlOrigin defined it means that
|
||||
we are building with --external-assets
|
||||
so we have to make sur that the fixed js code will run
|
||||
inside and outside keycloak.
|
||||
|
||||
When urlOrigin isn't defined we can assume the fixedJsCode
|
||||
will always run in keycloak context.
|
||||
*/
|
||||
|
||||
const { jsCode, urlOrigin } = params;
|
||||
|
||||
const fixedJsCode = jsCode.replace(
|
||||
/([a-z]+\.[a-z]+)\+"static\//g,
|
||||
(...[, group]) =>
|
||||
urlOrigin === undefined ?
|
||||
`window.${ftlValuesGlobalName}.url.resourcesPath + "/build/static/` :
|
||||
`("${ftlValuesGlobalName}" in window ? "${urlOrigin}" : "") + ${group} + "static/`
|
||||
);
|
||||
const fixedJsCode =
|
||||
jsCode
|
||||
.replace(
|
||||
/([a-z]+\.[a-z]+)\+"static\//g,
|
||||
(...[, group]) =>
|
||||
urlOrigin === undefined ?
|
||||
`window.${ftlValuesGlobalName}.url.resourcesPath + "/build/static/` :
|
||||
`("${ftlValuesGlobalName}" in window ? "${urlOrigin}" : "") + ${group} + "static/`
|
||||
)
|
||||
.replace(
|
||||
/".chunk.css",([a-z])+=([a-z]+\.[a-z]+)\+([a-z]+),/,
|
||||
(...[, group1, group2, group3]) =>
|
||||
urlOrigin === undefined ?
|
||||
`".chunk.css",${group1} = window.${ftlValuesGlobalName}.url.resourcesPath + "/build/" + ${group3},` :
|
||||
`".chunk.css",${group1} = ("${ftlValuesGlobalName}" in window ? "${urlOrigin}" : "") + ${group2} + ${group3},`
|
||||
);
|
||||
|
||||
return { fixedJsCode };
|
||||
|
||||
|
@ -57,6 +57,10 @@ export declare namespace KcContextBase {
|
||||
type: "success" | "warning" | "error" | "info";
|
||||
summary: string;
|
||||
};
|
||||
client: {
|
||||
clientId: string;
|
||||
name?: string;
|
||||
}
|
||||
isAppInitiatedAction: boolean;
|
||||
};
|
||||
|
||||
|
@ -8,9 +8,9 @@ import { deepAssign } from "../tools/deepAssign";
|
||||
|
||||
|
||||
export type ExtendsKcContextBase<
|
||||
KcContextExtended extends ({ pageId: string; } | undefined)
|
||||
KcContextExtended extends { pageId: string; }
|
||||
> =
|
||||
KcContextExtended extends undefined ?
|
||||
[KcContextExtended] extends [never] ?
|
||||
KcContextBase :
|
||||
AndByDiscriminatingKey<
|
||||
"pageId",
|
||||
@ -18,7 +18,7 @@ export type ExtendsKcContextBase<
|
||||
KcContextBase
|
||||
>;
|
||||
|
||||
export function getKcContext<KcContextExtended extends ({ pageId: string; } | undefined) = undefined>(
|
||||
export function getKcContext<KcContextExtended extends { pageId: string; } = never>(
|
||||
params?: {
|
||||
mockPageId?: ExtendsKcContextBase<KcContextExtended>["pageId"];
|
||||
mockData?: readonly DeepPartial<ExtendsKcContextBase<KcContextExtended>>[];
|
||||
@ -51,22 +51,15 @@ export function getKcContext<KcContextExtended extends ({ pageId: string; } | un
|
||||
|
||||
}
|
||||
|
||||
const kcContext: any = { "pageId": mockPageId };
|
||||
const kcContext: any = {};
|
||||
|
||||
deepAssign({
|
||||
"target": kcContext,
|
||||
"source": kcContextCommonMock
|
||||
"source": kcContextDefaultMock !== undefined ?
|
||||
kcContextDefaultMock :
|
||||
{ "pageId": mockPageId, ...kcContextCommonMock, }
|
||||
});
|
||||
|
||||
if (kcContextDefaultMock !== undefined) {
|
||||
|
||||
deepAssign({
|
||||
"target": kcContext,
|
||||
"source": kcContextDefaultMock
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (partialKcContextCustomMock !== undefined) {
|
||||
|
||||
deepAssign({
|
||||
|
@ -106,6 +106,9 @@ export const kcContextCommonMock: KcContextBase.Common = {
|
||||
"showResetCredentials": false,
|
||||
"showTryAnotherWayLink": false
|
||||
},
|
||||
"client": {
|
||||
"clientId": "myApp"
|
||||
},
|
||||
"scripts": [],
|
||||
"message": {
|
||||
"type": "success",
|
||||
@ -184,6 +187,7 @@ export const kcContextMocks: KcContextBase[] = [
|
||||
"skipLink": false,
|
||||
"actionUri": "#",
|
||||
"client": {
|
||||
"clientId": "myApp",
|
||||
"baseUrl": "#"
|
||||
}
|
||||
|
||||
@ -192,6 +196,7 @@ export const kcContextMocks: KcContextBase[] = [
|
||||
...kcContextCommonMock,
|
||||
"pageId": "error.ftl",
|
||||
"client": {
|
||||
"clientId": "myApp",
|
||||
"baseUrl": "#"
|
||||
},
|
||||
"message": {
|
||||
|
@ -2,6 +2,7 @@
|
||||
import { assert } from "tsafe/assert";
|
||||
import { is } from "tsafe/is";
|
||||
|
||||
//Warning: Be mindful that because of array this is not idempotent.
|
||||
export function deepAssign(
|
||||
params: {
|
||||
target: Record<string, unknown>;
|
||||
|
@ -14,6 +14,7 @@ generateKeycloakThemeResources({
|
||||
"keycloakThemeBuildingDirPath": pathJoin(sampleReactProjectDirPath, "build_keycloak_theme"),
|
||||
"urlPathname": "/keycloakify-demo-app/",
|
||||
"urlOrigin": undefined,
|
||||
"extraPagesId": ["my-custom-page.ftl"]
|
||||
"extraPagesId": ["my-custom-page.ftl"],
|
||||
"extraThemeProperties": ["env=test"]
|
||||
});
|
||||
|
||||
|
@ -6,202 +6,245 @@ import { same } from "evt/tools/inDepth";
|
||||
import { doExtends } from "tsafe/doExtends";
|
||||
import { assert } from "tsafe/assert";
|
||||
import { kcContextMocks, kcContextCommonMock } from "../../lib/getKcContext/kcContextMocks";
|
||||
import { deepClone } from "../../lib/tools/deepClone";
|
||||
import { deepClone } from "../../lib/tools/deepClone";
|
||||
import type { Any } from "ts-toolbelt";
|
||||
|
||||
{
|
||||
|
||||
const authorizedMailDomains = [
|
||||
"example.com",
|
||||
"another-example.com",
|
||||
"*.yet-another-example.com",
|
||||
"*.example.com",
|
||||
"hello-world.com"
|
||||
];
|
||||
const authorizedMailDomains = [
|
||||
"example.com",
|
||||
"another-example.com",
|
||||
"*.yet-another-example.com",
|
||||
"*.example.com",
|
||||
"hello-world.com"
|
||||
];
|
||||
|
||||
const displayName = "this is an overwritten common value";
|
||||
const displayName = "this is an overwritten common value";
|
||||
|
||||
const aNonStandardValue = "a non standard value";
|
||||
const aNonStandardValue1 = "a non standard value 1";
|
||||
const aNonStandardValue2 = "a non standard value 2";
|
||||
|
||||
type KcContextExtended = {
|
||||
pageId: "register.ftl";
|
||||
authorizedMailDomains: string[];
|
||||
} | {
|
||||
pageId: "my-extra-page-1.ftl";
|
||||
} | {
|
||||
pageId: "my-extra-page-2.ftl";
|
||||
aNonStandardValue: string;
|
||||
};
|
||||
type KcContextExtended = {
|
||||
pageId: "register.ftl";
|
||||
authorizedMailDomains: string[];
|
||||
} | {
|
||||
pageId: "info.ftl";
|
||||
aNonStandardValue1: string;
|
||||
} | {
|
||||
pageId: "my-extra-page-1.ftl";
|
||||
} | {
|
||||
pageId: "my-extra-page-2.ftl";
|
||||
aNonStandardValue2: string;
|
||||
};
|
||||
|
||||
const getKcContextProxy = (
|
||||
params: {
|
||||
mockPageId: ExtendsKcContextBase<KcContextExtended>["pageId"];
|
||||
}
|
||||
) => {
|
||||
|
||||
const { mockPageId } = params;
|
||||
|
||||
const { kcContext } = getKcContext<KcContextExtended>({
|
||||
mockPageId,
|
||||
"mockData": [
|
||||
{
|
||||
"pageId": "login.ftl",
|
||||
"realm": { displayName }
|
||||
},
|
||||
{
|
||||
"pageId": "info.ftl",
|
||||
aNonStandardValue1
|
||||
},
|
||||
{
|
||||
"pageId": "register.ftl",
|
||||
authorizedMailDomains
|
||||
},
|
||||
{
|
||||
"pageId": "my-extra-page-2.ftl",
|
||||
aNonStandardValue2
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
return { kcContext };
|
||||
|
||||
};
|
||||
|
||||
{
|
||||
|
||||
const pageId = "login.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase.Login>, 1>();
|
||||
|
||||
assert(same(
|
||||
//NOTE: deepClone for printIfExists or other functions...
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
|
||||
mock.realm.displayName = displayName;
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
function getKcContextProxy(
|
||||
params: {
|
||||
mockPageId: ExtendsKcContextBase<KcContextExtended>["pageId"];
|
||||
}
|
||||
) {
|
||||
|
||||
const { mockPageId } = params;
|
||||
{
|
||||
const pageId = "info.ftl";
|
||||
|
||||
const { kcContext } = getKcContext<KcContextExtended>({
|
||||
mockPageId,
|
||||
"mockData": [
|
||||
{
|
||||
"pageId": "login.ftl",
|
||||
"realm": { displayName }
|
||||
},
|
||||
{
|
||||
"pageId": "register.ftl",
|
||||
authorizedMailDomains
|
||||
},
|
||||
{
|
||||
"pageId": "my-extra-page-2.ftl",
|
||||
aNonStandardValue
|
||||
}
|
||||
]
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
//NOTE: I don't understand the need to add: pageId: typeof pageId; ...
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase.Info & { pageId: typeof pageId; aNonStandardValue1: string; }>, 1>();
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
|
||||
Object.assign(mock, { aNonStandardValue1 });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
const pageId = "register.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
//NOTE: I don't understand the need to add: pageId: typeof pageId; ...
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase.Register & { pageId: typeof pageId; authorizedMailDomains: string[]; }>, 1>();
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
|
||||
Object.assign(mock, { authorizedMailDomains });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const pageId = "my-extra-page-2.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase.Common & { pageId: typeof pageId; aNonStandardValue2: string; }>, 1>();
|
||||
|
||||
kcContext.aNonStandardValue2;
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextCommonMock);
|
||||
|
||||
Object.assign(mock, { pageId, aNonStandardValue2 });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const pageId = "my-extra-page-1.ftl";
|
||||
|
||||
console.log("We expect a warning here =>");
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase.Common & { pageId: typeof pageId; }>, 1>();
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextCommonMock);
|
||||
|
||||
Object.assign(mock, { pageId });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const pageId = "login.ftl";
|
||||
|
||||
const { kcContext } = getKcContext({
|
||||
"mockPageId": pageId
|
||||
});
|
||||
|
||||
return { kcContext };
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const pageId= "login.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<Any.Equals<typeof kcContext, any>, 1>();
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
doExtends<typeof kcContext, KcContextBase.Login>();
|
||||
|
||||
assert(same(
|
||||
//NOTE: deepClone for printIfExists or other functions...
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
|
||||
mock.realm.displayName = displayName;
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
const pageId = "register.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<Any.Equals<typeof kcContext, any>, 1>();
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
doExtends<typeof kcContext, KcContextBase.Register>();
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase | undefined>, 1>();
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
|
||||
Object.assign(mock, { authorizedMailDomains });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!)
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const pageId = "my-extra-page-2.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<Any.Equals<typeof kcContext, any>, 1>();
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<typeof kcContext, KcContextBase>();
|
||||
|
||||
doExtends<typeof kcContext, KcContextBase.Common>();
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextCommonMock);
|
||||
|
||||
Object.assign(mock, { pageId, aNonStandardValue });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
console.log("PASS no extension");
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const pageId = "my-extra-page-1.ftl";
|
||||
|
||||
console.log("We expect a warning here =>");
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<Any.Equals<typeof kcContext, any>, 1>();
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<typeof kcContext, KcContextBase>();
|
||||
|
||||
doExtends<typeof kcContext, KcContextBase.Common>();
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextCommonMock);
|
||||
|
||||
Object.assign(mock, { pageId });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const { kcContext } = getKcContext();
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<Any.Equals<typeof kcContext, any>, 1>();
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase | undefined>, 1>();
|
||||
|
||||
doExtends<typeof kcContext, KcContextBase | undefined>();
|
||||
assert(kcContext === undefined);
|
||||
|
||||
console.log("PASS no extension, no mock");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
42
yarn.lock
42
yarn.lock
@ -139,9 +139,9 @@
|
||||
integrity sha512-6U71C2Wp7r5XtFtQzYrW5iKFT67OixrSxjI4MptCHzdSVlgabczzqLe0ZSgnub/5Kp4hSbpDB1tMytZY9pwxxA==
|
||||
|
||||
"@types/mdast@^3.0.0", "@types/mdast@^3.0.3":
|
||||
version "3.0.3"
|
||||
resolved "https://registry.yarnpkg.com/@types/mdast/-/mdast-3.0.3.tgz#2d7d671b1cd1ea3deb306ea75036c2a0407d2deb"
|
||||
integrity sha512-SXPBMnFVQg1s00dlMCc/jCdvPqdE4mXaMMCeRlxLDmTAEoegHT53xKtkDnzDTOcmMHUfcjyf36/YYZ6SxRdnsw==
|
||||
version "3.0.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/mdast/-/mdast-3.0.4.tgz#8ee6b5200751b6cadb9a043ca39612693ad6cb9e"
|
||||
integrity sha512-gIdhbLDFlspL53xzol2hVzrXAbzt71erJHoOwQZWssjaiouOotf03lNtMmFm9VfFkvnLWccSVjUAZGQ5Kqw+jA==
|
||||
dependencies:
|
||||
"@types/unist" "*"
|
||||
|
||||
@ -156,28 +156,28 @@
|
||||
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==
|
||||
|
||||
"@types/prop-types@*":
|
||||
version "15.7.3"
|
||||
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
|
||||
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==
|
||||
version "15.7.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11"
|
||||
integrity sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ==
|
||||
|
||||
"@types/react@^17.0.0":
|
||||
version "17.0.11"
|
||||
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.11.tgz#67fcd0ddbf5a0b083a0f94e926c7d63f3b836451"
|
||||
integrity sha512-yFRQbD+whVonItSk7ZzP/L+gPTJVBkL/7shLEF+i9GC/1cV3JmUxEQz6+9ylhUpWSDuqo1N9qEvqS6vTj4USUA==
|
||||
version "17.0.14"
|
||||
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.14.tgz#f0629761ca02945c4e8fea99b8177f4c5c61fb0f"
|
||||
integrity sha512-0WwKHUbWuQWOce61UexYuWTGuGY/8JvtUe/dtQ6lR4sZ3UiylHotJeWpf3ArP9+DSGUoLY3wbU59VyMrJps5VQ==
|
||||
dependencies:
|
||||
"@types/prop-types" "*"
|
||||
"@types/scheduler" "*"
|
||||
csstype "^3.0.2"
|
||||
|
||||
"@types/scheduler@*":
|
||||
version "0.16.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.1.tgz#18845205e86ff0038517aab7a18a62a6b9f71275"
|
||||
integrity sha512-EaCxbanVeyxDRTQBkdLb3Bvl/HK7PBK6UJjsSixB0iHKoWxE5uu2Q/DgtpOhPIojN0Zl1whvOd7PoHs2P0s5eA==
|
||||
version "0.16.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39"
|
||||
integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==
|
||||
|
||||
"@types/unist@*", "@types/unist@^2.0.0", "@types/unist@^2.0.2", "@types/unist@^2.0.3":
|
||||
version "2.0.3"
|
||||
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
|
||||
integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==
|
||||
version "2.0.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.5.tgz#fdd299f23205c3455af88ce618dd65c14cb73e22"
|
||||
integrity sha512-wnra4Vw9dopnuybR6HBywJ/URYpYrKLoepBTEtgfJup8Ahoi2zJECPP2cwiXp7btTvOT2CULv87aQRA4eZSP6g==
|
||||
|
||||
ansi-regex@^5.0.0:
|
||||
version "5.0.0"
|
||||
@ -387,9 +387,9 @@ d@1, d@^1.0.1:
|
||||
type "^1.0.1"
|
||||
|
||||
debug@^4.0.0:
|
||||
version "4.3.1"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee"
|
||||
integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==
|
||||
version "4.3.2"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.2.tgz#f0a49c18ac8779e31d4a0c6029dfb76873c7428b"
|
||||
integrity sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==
|
||||
dependencies:
|
||||
ms "2.1.2"
|
||||
|
||||
@ -1173,9 +1173,9 @@ type@^2.0.0:
|
||||
integrity sha512-180WMDQaIMm3+7hGXWf12GtdniDEy7nYcyFMKJn/eZz/6tSLXrUN9V0wKSbMjej0I1WHWbpREDEKHtqPQa9NNw==
|
||||
|
||||
typescript@^4.2.3:
|
||||
version "4.3.4"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.4.tgz#3f85b986945bcf31071decdd96cf8bfa65f9dcbc"
|
||||
integrity sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==
|
||||
version "4.3.5"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"
|
||||
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==
|
||||
|
||||
unified@^9.0.0:
|
||||
version "9.2.1"
|
||||
|
Reference in New Issue
Block a user