keycloakify 7.6.7 → 7.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -5
- package/account/index.d.ts +1 -0
- package/account/index.js +1 -0
- package/account/index.js.map +1 -1
- package/account/kcContext/createGetKcContext.d.ts +18 -0
- package/account/kcContext/createGetKcContext.js +73 -0
- package/account/kcContext/createGetKcContext.js.map +1 -0
- package/account/kcContext/getKcContext.d.ts +1 -0
- package/account/kcContext/getKcContext.js +7 -49
- package/account/kcContext/getKcContext.js.map +1 -1
- package/bin/keycloakify/generateKeycloakThemeResources.js +1 -1
- package/bin/keycloakify/generateKeycloakThemeResources.js.map +1 -1
- package/login/index.d.ts +1 -0
- package/login/index.js +1 -0
- package/login/index.js.map +1 -1
- package/login/kcContext/createGetKcContext.d.ts +18 -0
- package/login/kcContext/createGetKcContext.js +114 -0
- package/login/kcContext/createGetKcContext.js.map +1 -0
- package/login/kcContext/getKcContext.d.ts +1 -0
- package/login/kcContext/getKcContext.js +7 -90
- package/login/kcContext/getKcContext.js.map +1 -1
- package/package.json +25 -4
- package/src/account/index.ts +1 -0
- package/src/account/kcContext/createGetKcContext.ts +110 -0
- package/src/account/kcContext/getKcContext.ts +7 -66
- package/src/bin/keycloakify/generateKeycloakThemeResources.ts +1 -1
- package/src/login/index.ts +1 -0
- package/src/login/kcContext/createGetKcContext.ts +168 -0
- package/src/login/kcContext/getKcContext.ts +7 -124
package/README.md
CHANGED
@@ -36,13 +36,64 @@
|
|
36
36
|
<img src="https://user-images.githubusercontent.com/6702424/110260457-a1c3d380-7fac-11eb-853a-80459b65626b.png">
|
37
37
|
</p>
|
38
38
|
|
39
|
-
|
39
|
+
## Sponsor 👼
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
> Checkout [the migration guide](https://docs.keycloakify.dev/migration-guides/v6-greater-than-v7).
|
41
|
+
We are exclusively sponsored by [Cloud IAM](https://www.cloud-iam.com), a French company offering Keycloak as a service.
|
42
|
+
Their dedicated support helps us continue the development and maintenance of this project.
|
44
43
|
|
45
|
-
|
44
|
+
[Cloud IAM](https://www.cloud-iam.com/) provides the following services:
|
45
|
+
|
46
|
+
- Perfectly configured and optimized Keycloak IAM, ready in seconds.
|
47
|
+
- Custom theme building for your brand using Keycloakify.
|
48
|
+
|
49
|
+
<p align="center">
|
50
|
+
<a href="https://www.cloud-iam.com/">
|
51
|
+
<img src="https://user-images.githubusercontent.com/6702424/232165752-17134e68-4a55-4d6e-8672-e9132ecac5d5.svg" alt="Cloud IAM Logo" width="200"/>
|
52
|
+
</a>
|
53
|
+
<br/>
|
54
|
+
<i>Use promo code <code>keycloakify</code> </i>
|
55
|
+
<br/>
|
56
|
+
<i>5% of your annual subscription will be donated to us, and you'll get 5% off too.</i>
|
57
|
+
</p>
|
58
|
+
|
59
|
+
Thank you, [Cloud IAM](https://www.cloud-iam.com/), for your support!
|
60
|
+
|
61
|
+
## Contributors ✨
|
62
|
+
|
63
|
+
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
64
|
+
|
65
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
66
|
+
<!-- prettier-ignore-start -->
|
67
|
+
<!-- markdownlint-disable -->
|
68
|
+
<table>
|
69
|
+
<tbody>
|
70
|
+
<tr>
|
71
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/lordvlad"><img src="https://avatars.githubusercontent.com/u/1217769?v=4?s=100" width="100px;" alt="Waldemar Reusch"/><br /><sub><b>Waldemar Reusch</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=lordvlad" title="Code">💻</a></td>
|
72
|
+
<td align="center" valign="top" width="14.28%"><a href="https://willwill96.github.io/the-ui-dawg-static-site/en/introduction/"><img src="https://avatars.githubusercontent.com/u/10997562?v=4?s=100" width="100px;" alt="William Will"/><br /><sub><b>William Will</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=willwill96" title="Code">💻</a></td>
|
73
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Ann2827"><img src="https://avatars.githubusercontent.com/u/32645809?v=4?s=100" width="100px;" alt="Bystrova Ann"/><br /><sub><b>Bystrova Ann</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=Ann2827" title="Code">💻</a></td>
|
74
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mkreuzmayr"><img src="https://avatars.githubusercontent.com/u/20108212?v=4?s=100" width="100px;" alt="Michael Kreuzmayr"/><br /><sub><b>Michael Kreuzmayr</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=mkreuzmayr" title="Code">💻</a></td>
|
75
|
+
<td align="center" valign="top" width="14.28%"><a href="https://coolmathgames.tech"><img src="https://avatars.githubusercontent.com/u/6877780?v=4?s=100" width="100px;" alt="Mary "/><br /><sub><b>Mary </b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=Mstrodl" title="Code">💻</a></td>
|
76
|
+
<td align="center" valign="top" width="14.28%"><a href="https://tasyp.xyz/"><img src="https://avatars.githubusercontent.com/u/6623212?v=4?s=100" width="100px;" alt="German Öö"/><br /><sub><b>German Öö</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=Tasyp" title="Code">💻</a></td>
|
77
|
+
<td align="center" valign="top" width="14.28%"><a href="https://revolunet.com"><img src="https://avatars.githubusercontent.com/u/124937?v=4?s=100" width="100px;" alt="Julien Bouquillon"/><br /><sub><b>Julien Bouquillon</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=revolunet" title="Code">💻</a></td>
|
78
|
+
</tr>
|
79
|
+
<tr>
|
80
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/aidangilmore"><img src="https://avatars.githubusercontent.com/u/32880357?v=4?s=100" width="100px;" alt="Aidan Gilmore"/><br /><sub><b>Aidan Gilmore</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=aidangilmore" title="Code">💻</a></td>
|
81
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/0x-Void"><img src="https://avatars.githubusercontent.com/u/32745739?v=4?s=100" width="100px;" alt="Void"/><br /><sub><b>Void</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=0x-Void" title="Code">💻</a></td>
|
82
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/juffe"><img src="https://avatars.githubusercontent.com/u/5393231?v=4?s=100" width="100px;" alt="juffe"/><br /><sub><b>juffe</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=juffe" title="Code">💻</a></td>
|
83
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/lazToum"><img src="https://avatars.githubusercontent.com/u/4764837?v=4?s=100" width="100px;" alt="Lazaros Toumanidis"/><br /><sub><b>Lazaros Toumanidis</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=lazToum" title="Code">💻</a></td>
|
84
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/marcmrf"><img src="https://avatars.githubusercontent.com/u/9928519?v=4?s=100" width="100px;" alt="Marc"/><br /><sub><b>Marc</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=marcmrf" title="Code">💻</a></td>
|
85
|
+
<td align="center" valign="top" width="14.28%"><a href="http://kasir-barati.github.io"><img src="https://avatars.githubusercontent.com/u/73785723?v=4?s=100" width="100px;" alt="Kasir Barati"/><br /><sub><b>Kasir Barati</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=kasir-barati" title="Documentation">📖</a></td>
|
86
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/asashay"><img src="https://avatars.githubusercontent.com/u/10714670?v=4?s=100" width="100px;" alt="Alex Oliynyk"/><br /><sub><b>Alex Oliynyk</b></sub></a><br /> <a href="https://github.com/keycloakify/keycloakify/commits?author=asashay" title="Code">💻</a></td>
|
87
|
+
</tr>
|
88
|
+
</tbody>
|
89
|
+
</table>
|
90
|
+
|
91
|
+
<!-- markdownlint-restore -->
|
92
|
+
<!-- prettier-ignore-end -->
|
93
|
+
|
94
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
95
|
+
|
96
|
+
## Changelog highlights
|
46
97
|
|
47
98
|
## 7.0 🍾
|
48
99
|
|
package/account/index.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import Fallback from "../account/Fallback";
|
2
2
|
export default Fallback;
|
3
3
|
export { getKcContext } from "../account/kcContext/getKcContext";
|
4
|
+
export { createGetKcContext } from "../account/kcContext/createGetKcContext";
|
4
5
|
export { createUseI18n } from "../account/i18n/i18n";
|
5
6
|
export type { PageProps } from "../account/pages/PageProps";
|
package/account/index.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import Fallback from "../account/Fallback";
|
2
2
|
export default Fallback;
|
3
3
|
export { getKcContext } from "../account/kcContext/getKcContext";
|
4
|
+
export { createGetKcContext } from "../account/kcContext/createGetKcContext";
|
4
5
|
export { createUseI18n } from "../account/i18n/i18n";
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/account/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/account/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,8BAA8B,CAAC;AAEpD,eAAe,QAAQ,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/account/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,8BAA8B,CAAC;AAEpD,eAAe,QAAQ,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kDAAkD,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { DeepPartial } from "../../tools/DeepPartial";
|
2
|
+
import type { ExtendKcContext } from "./getKcContextFromWindow";
|
3
|
+
export declare function createGetKcContext<KcContextExtension extends {
|
4
|
+
pageId: string;
|
5
|
+
} = never>(params?: {
|
6
|
+
mockData?: readonly DeepPartial<ExtendKcContext<KcContextExtension>>[];
|
7
|
+
}): {
|
8
|
+
getKcContext: <PageId extends ExtendKcContext<KcContextExtension>["pageId"] | undefined = undefined>(params?: {
|
9
|
+
mockPageId?: PageId | undefined;
|
10
|
+
storyParams?: DeepPartial<Extract<ExtendKcContext<KcContextExtension>, {
|
11
|
+
pageId: PageId;
|
12
|
+
}>> | undefined;
|
13
|
+
} | undefined) => {
|
14
|
+
kcContext: PageId extends undefined ? ExtendKcContext<KcContextExtension> | undefined : Extract<ExtendKcContext<KcContextExtension>, {
|
15
|
+
pageId: PageId;
|
16
|
+
}>;
|
17
|
+
};
|
18
|
+
};
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import { deepAssign } from "../../tools/deepAssign";
|
2
|
+
import { getKcContextFromWindow } from "./getKcContextFromWindow";
|
3
|
+
import { pathJoin } from "../../bin/tools/pathJoin";
|
4
|
+
import { pathBasename } from "../../tools/pathBasename";
|
5
|
+
import { mockTestingResourcesCommonPath } from "../../bin/mockTestingResourcesPath";
|
6
|
+
import { symToStr } from "tsafe/symToStr";
|
7
|
+
import { kcContextMocks, kcContextCommonMock } from "../../account/kcContext/kcContextMocks";
|
8
|
+
import { id } from "tsafe/id";
|
9
|
+
import { accountThemePageIds } from "../../bin/keycloakify/generateFtl/pageId";
|
10
|
+
export function createGetKcContext(params) {
|
11
|
+
const { mockData } = params !== null && params !== void 0 ? params : {};
|
12
|
+
function getKcContext(params) {
|
13
|
+
const { mockPageId, storyParams } = params !== null && params !== void 0 ? params : {};
|
14
|
+
const realKcContext = getKcContextFromWindow();
|
15
|
+
if (mockPageId !== undefined && realKcContext === undefined) {
|
16
|
+
//TODO maybe trow if no mock fo custom page
|
17
|
+
console.log([
|
18
|
+
`%cKeycloakify: ${symToStr({ mockPageId })} set to ${mockPageId}.`,
|
19
|
+
`If assets are missing make sure you have built your Keycloak theme at least once.`
|
20
|
+
].join(" "), "background: red; color: yellow; font-size: medium");
|
21
|
+
const kcContextDefaultMock = kcContextMocks.find(({ pageId }) => pageId === mockPageId);
|
22
|
+
const partialKcContextCustomMock = (() => {
|
23
|
+
const out = {};
|
24
|
+
const mockDataPick = mockData === null || mockData === void 0 ? void 0 : mockData.find(({ pageId }) => pageId === mockPageId);
|
25
|
+
if (mockDataPick !== undefined) {
|
26
|
+
deepAssign({
|
27
|
+
"target": out,
|
28
|
+
"source": mockDataPick
|
29
|
+
});
|
30
|
+
}
|
31
|
+
if (storyParams !== undefined) {
|
32
|
+
deepAssign({
|
33
|
+
"target": out,
|
34
|
+
"source": storyParams
|
35
|
+
});
|
36
|
+
}
|
37
|
+
return Object.keys(out).length === 0 ? undefined : out;
|
38
|
+
})();
|
39
|
+
if (kcContextDefaultMock === undefined && partialKcContextCustomMock === undefined) {
|
40
|
+
console.warn([
|
41
|
+
`WARNING: You declared the non build in page ${mockPageId} but you didn't `,
|
42
|
+
`provide mock data needed to debug the page outside of Keycloak as you are trying to do now.`,
|
43
|
+
`Please check the documentation of the getKcContext function`
|
44
|
+
].join("\n"));
|
45
|
+
}
|
46
|
+
const kcContext = {};
|
47
|
+
deepAssign({
|
48
|
+
"target": kcContext,
|
49
|
+
"source": kcContextDefaultMock !== undefined ? kcContextDefaultMock : Object.assign({ "pageId": mockPageId }, kcContextCommonMock)
|
50
|
+
});
|
51
|
+
if (partialKcContextCustomMock !== undefined) {
|
52
|
+
deepAssign({
|
53
|
+
"target": kcContext,
|
54
|
+
"source": partialKcContextCustomMock
|
55
|
+
});
|
56
|
+
}
|
57
|
+
return { kcContext };
|
58
|
+
}
|
59
|
+
if (realKcContext === undefined) {
|
60
|
+
return { "kcContext": undefined };
|
61
|
+
}
|
62
|
+
if (id(accountThemePageIds).indexOf(realKcContext.pageId) < 0 && !("account" in realKcContext)) {
|
63
|
+
return { "kcContext": undefined };
|
64
|
+
}
|
65
|
+
{
|
66
|
+
const { url } = realKcContext;
|
67
|
+
url.resourcesCommonPath = pathJoin(url.resourcesPath, pathBasename(mockTestingResourcesCommonPath));
|
68
|
+
}
|
69
|
+
return { "kcContext": realKcContext };
|
70
|
+
}
|
71
|
+
return { getKcContext };
|
72
|
+
}
|
73
|
+
//# sourceMappingURL=createGetKcContext.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"createGetKcContext.js","sourceRoot":"","sources":["../../src/account/kcContext/createGetKcContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,8BAA8B,EAAE,MAAM,0CAA0C,CAAC;AAC1F,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnG,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAErF,MAAM,UAAU,kBAAkB,CAAwD,MAEzF;IACG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;IAElC,SAAS,YAAY,CAAuF,MAG3G;QAKG,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;QAEjD,MAAM,aAAa,GAAG,sBAAsB,EAAsB,CA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,CACf,CAAC;aACL;YAED,MAAM,SAAS,GAAQ,EAAE,CAAC;YAE1B,UAAU,CAAC;gBACP,QAAQ,EAAE,SAAS;gBACnB,QAAQ,EAAE,oBAAoB,KAAK,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,iBAAG,QAAQ,EAAE,UAAU,IAAK,mBAAmB,CAAE;aACzH,CAAC,CAAC;YAEH,IAAI,0BAA0B,KAAK,SAAS,EAAE;gBAC1C,UAAU,CAAC;oBACP,QAAQ,EAAE,SAAS;oBACnB,QAAQ,EAAE,0BAA0B;iBACvC,CAAC,CAAC;aACN;YAED,OAAO,EAAE,SAAS,EAAE,CAAC;SACxB;QAED,IAAI,aAAa,KAAK,SAAS,EAAE;YAC7B,OAAO,EAAE,WAAW,EAAE,SAAgB,EAAE,CAAC;SAC5C;QAED,IAAI,EAAE,CAAoB,mBAAmB,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,SAAS,IAAI,aAAa,CAAC,EAAE;YAC/G,OAAO,EAAE,WAAW,EAAE,SAAgB,EAAE,CAAC;SAC5C;QAED;YACI,MAAM,EAAE,GAAG,EAAE,GAAG,aAAa,CAAC;YAE9B,GAAG,CAAC,mBAAmB,GAAG,QAAQ,CAAC,GAAG,CAAC,aAAa,EAAE,YAAY,CAAC,8BAA8B,CAAC,CAAC,CAAC;SACvG;QAED,OAAO,EAAE,WAAW,EAAE,aAAoB,EAAE,CAAC;IACjD,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,CAAC;AAC5B,CAAC"}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { DeepPartial } from "../../tools/DeepPartial";
|
2
2
|
import type { ExtendKcContext } from "./getKcContextFromWindow";
|
3
|
+
/** @deprecated: Use createGetKcContext instead */
|
3
4
|
export declare function getKcContext<KcContextExtension extends {
|
4
5
|
pageId: string;
|
5
6
|
} = never>(params?: {
|
@@ -1,53 +1,11 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
import { pathJoin } from "../../bin/tools/pathJoin";
|
4
|
-
import { pathBasename } from "../../tools/pathBasename";
|
5
|
-
import { mockTestingResourcesCommonPath } from "../../bin/mockTestingResourcesPath";
|
6
|
-
import { symToStr } from "tsafe/symToStr";
|
7
|
-
import { kcContextMocks, kcContextCommonMock } from "../../account/kcContext/kcContextMocks";
|
8
|
-
import { id } from "tsafe/id";
|
9
|
-
import { accountThemePageIds } from "../../bin/keycloakify/generateFtl/pageId";
|
1
|
+
import { createGetKcContext } from "./createGetKcContext";
|
2
|
+
/** @deprecated: Use createGetKcContext instead */
|
10
3
|
export function getKcContext(params) {
|
11
4
|
const { mockPageId, mockData } = params !== null && params !== void 0 ? params : {};
|
12
|
-
const
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
`If assets are missing make sure you have built your Keycloak theme at least once.`
|
18
|
-
].join(" "), "background: red; color: yellow; font-size: medium");
|
19
|
-
const kcContextDefaultMock = kcContextMocks.find(({ pageId }) => pageId === mockPageId);
|
20
|
-
const partialKcContextCustomMock = mockData === null || mockData === void 0 ? void 0 : mockData.find(({ pageId }) => pageId === mockPageId);
|
21
|
-
if (kcContextDefaultMock === undefined && partialKcContextCustomMock === undefined) {
|
22
|
-
console.warn([
|
23
|
-
`WARNING: You declared the non build in page ${mockPageId} but you didn't `,
|
24
|
-
`provide mock data needed to debug the page outside of Keycloak as you are trying to do now.`,
|
25
|
-
`Please check the documentation of the getKcContext function`
|
26
|
-
].join("\n"));
|
27
|
-
}
|
28
|
-
const kcContext = {};
|
29
|
-
deepAssign({
|
30
|
-
"target": kcContext,
|
31
|
-
"source": kcContextDefaultMock !== undefined ? kcContextDefaultMock : Object.assign({ "pageId": mockPageId }, kcContextCommonMock)
|
32
|
-
});
|
33
|
-
if (partialKcContextCustomMock !== undefined) {
|
34
|
-
deepAssign({
|
35
|
-
"target": kcContext,
|
36
|
-
"source": partialKcContextCustomMock
|
37
|
-
});
|
38
|
-
}
|
39
|
-
return { kcContext };
|
40
|
-
}
|
41
|
-
if (realKcContext === undefined) {
|
42
|
-
return { "kcContext": undefined };
|
43
|
-
}
|
44
|
-
if (id(accountThemePageIds).indexOf(realKcContext.pageId) < 0 && !("account" in realKcContext)) {
|
45
|
-
return { "kcContext": undefined };
|
46
|
-
}
|
47
|
-
{
|
48
|
-
const { url } = realKcContext;
|
49
|
-
url.resourcesCommonPath = pathJoin(url.resourcesPath, pathBasename(mockTestingResourcesCommonPath));
|
50
|
-
}
|
51
|
-
return { "kcContext": realKcContext };
|
5
|
+
const { getKcContext } = createGetKcContext({
|
6
|
+
mockData
|
7
|
+
});
|
8
|
+
const { kcContext } = getKcContext({ mockPageId });
|
9
|
+
return { kcContext };
|
52
10
|
}
|
53
11
|
//# sourceMappingURL=getKcContext.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getKcContext.js","sourceRoot":"","sources":["../../src/account/kcContext/getKcContext.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"getKcContext.js","sourceRoot":"","sources":["../../src/account/kcContext/getKcContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,kDAAkD;AAClD,MAAM,UAAU,YAAY,CAAwD,MAGnF;IACG,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;IAE9C,MAAM,EAAE,YAAY,EAAE,GAAG,kBAAkB,CAAC;QACxC,QAAQ;KACX,CAAC,CAAC;IAEH,MAAM,EAAE,SAAS,EAAE,GAAG,YAAY,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;IAEnD,OAAO,EAAE,SAAS,EAAE,CAAC;AACzB,CAAC"}
|
@@ -226,7 +226,7 @@ function generateKeycloakThemeResources(params) {
|
|
226
226
|
_e.sent();
|
227
227
|
themeResourcesDirPath = (0, path_1.join)(themeDirPath, "resources");
|
228
228
|
(0, transformCodebase_1.transformCodebase)({
|
229
|
-
"srcDirPath": (0, path_1.join)(tmpDirPath, "keycloak",
|
229
|
+
"srcDirPath": (0, path_1.join)(tmpDirPath, "keycloak", themeType, "resources"),
|
230
230
|
"destDirPath": themeResourcesDirPath
|
231
231
|
});
|
232
232
|
reactAppPublicDirPath = (0, path_1.join)(reactAppBuildDirPath, "..", "public");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generateKeycloakThemeResources.js","sourceRoot":"","sources":["../../src/bin/keycloakify/generateKeycloakThemeResources.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAA+D;AAC/D,qCAAyB;AACzB,6BAAkE;AAClE,iGAAgG;AAChG,+EAA8E;AAC9E,6CAAgI;AAChI,sFAAkF;AAClF,wEAA6I;AAC7I,8CAA6C;AAE7C,uCAAsC;AAuCtC,IAAA,eAAM,GAAwD,CAAC;AAE/D,SAAsB,8BAA8B,CAAC,MAOpD;;;;;;;;oBACW,oBAAoB,GAA4G,MAAM,qBAAlH,EAAE,4BAA4B,GAA8E,MAAM,6BAApF,EAAE,oBAAoB,GAAwD,MAAM,qBAA9D,EAAE,eAAe,GAAuC,MAAM,gBAA7C,EAAE,YAAY,GAAyB,MAAM,aAA/B,EAAE,kBAAkB,GAAK,MAAM,mBAAX,CAAY;oBAEzI,eAAe,GAAG,UAAC,SAA8B;wBACnD,OAAA,IAAA,WAAQ,EAAC,4BAA4B,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,CAAC,SAAS,EAAE,SAAS,CAAC;oBAA9G,CAA8G,CAAC;oBAE/G,qBAAqB,GAA2B,EAAE,CAAC;oBAEnD,yBAAyB,GAAuF,SAAS,CAAC;wCAEnH,SAAS;;;;;oCACV,YAAY,GAA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AE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;oCACzG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;oCAG5D,EAAE,CAAC,aAAa,CACZ,IAAA,WAAQ,EAAC,YAAY,EAAE,kBAAkB,CAAC,EAC1C,MAAM,CAAC,IAAI,CAAC,eAAC,iBAAiB,UAAK,CAAC,MAAA,YAAY,CAAC,oBAAoB,mCAAI,EAAE,CAAC,UAAE,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CACtG,CAAC;;;;;;;;oBAxJkB,eAAA,SAAA,wBAAU,CAAA;;;;oBAAvB,SAAS;kDAAT,SAAS;;;;;;;;;;;;;;;;;;;oBA6JpB,KAAK,EAAE;wBACH,IAAI,oBAAoB,KAAK,SAAS,EAAE;4BACpC,sBAAsB,GAAG,KAAK,CAAC;4BAC/B,MAAM,KAAK,CAAC;yBACf;wBAED,sBAAsB,GAAG,IAAI,CAAC;wBAE9B,IAAA,qCAAiB,EAAC;4BACd,YAAY,EAAE,oBAAoB;4BAClC,aAAa,EAAE,eAAe,CAAC,OAAO,CAAC;yBAC1C,CAAC,CAAC;qBACN;oBAED,sBAAO,EAAE,sBAAsB,wBAAA,EAAE,EAAC;;;;CACrC;AA7LD,wEA6LC"}
|
package/login/index.d.ts
CHANGED
@@ -2,5 +2,6 @@ import Fallback from "../login/Fallback";
|
|
2
2
|
export default Fallback;
|
3
3
|
export { useDownloadTerms } from "../login/lib/useDownloadTerms";
|
4
4
|
export { getKcContext } from "../login/kcContext/getKcContext";
|
5
|
+
export { createGetKcContext } from "../login/kcContext/createGetKcContext";
|
5
6
|
export { createUseI18n } from "../login/i18n/i18n";
|
6
7
|
export type { PageProps } from "../login/pages/PageProps";
|
package/login/index.js
CHANGED
@@ -2,5 +2,6 @@ import Fallback from "../login/Fallback";
|
|
2
2
|
export default Fallback;
|
3
3
|
export { useDownloadTerms } from "../login/lib/useDownloadTerms";
|
4
4
|
export { getKcContext } from "../login/kcContext/getKcContext";
|
5
|
+
export { createGetKcContext } from "../login/kcContext/createGetKcContext";
|
5
6
|
export { createUseI18n } from "../login/i18n/i18n";
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/login/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/login/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,4BAA4B,CAAC;AAElD,eAAe,QAAQ,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/login/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,4BAA4B,CAAC;AAElD,eAAe,QAAQ,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { DeepPartial } from "../../tools/DeepPartial";
|
2
|
+
import type { ExtendKcContext } from "./getKcContextFromWindow";
|
3
|
+
export declare function createGetKcContext<KcContextExtension extends {
|
4
|
+
pageId: string;
|
5
|
+
} = never>(params?: {
|
6
|
+
mockData?: readonly DeepPartial<ExtendKcContext<KcContextExtension>>[];
|
7
|
+
}): {
|
8
|
+
getKcContext: <PageId extends ExtendKcContext<KcContextExtension>["pageId"] | undefined = undefined>(params?: {
|
9
|
+
mockPageId?: PageId | undefined;
|
10
|
+
storyParams?: DeepPartial<Extract<ExtendKcContext<KcContextExtension>, {
|
11
|
+
pageId: PageId;
|
12
|
+
}>> | undefined;
|
13
|
+
} | undefined) => {
|
14
|
+
kcContext: PageId extends undefined ? ExtendKcContext<KcContextExtension> | undefined : Extract<ExtendKcContext<KcContextExtension>, {
|
15
|
+
pageId: PageId;
|
16
|
+
}>;
|
17
|
+
};
|
18
|
+
};
|
@@ -0,0 +1,114 @@
|
|
1
|
+
import { kcContextMocks, kcContextCommonMock } from "./kcContextMocks";
|
2
|
+
import { deepAssign } from "../../tools/deepAssign";
|
3
|
+
import { id } from "tsafe/id";
|
4
|
+
import { exclude } from "tsafe/exclude";
|
5
|
+
import { assert } from "tsafe/assert";
|
6
|
+
import { getKcContextFromWindow } from "./getKcContextFromWindow";
|
7
|
+
import { pathJoin } from "../../bin/tools/pathJoin";
|
8
|
+
import { pathBasename } from "../../tools/pathBasename";
|
9
|
+
import { mockTestingResourcesCommonPath } from "../../bin/mockTestingResourcesPath";
|
10
|
+
import { symToStr } from "tsafe/symToStr";
|
11
|
+
import { loginThemePageIds } from "../../bin/keycloakify/generateFtl/pageId";
|
12
|
+
export function createGetKcContext(params) {
|
13
|
+
const { mockData } = params !== null && params !== void 0 ? params : {};
|
14
|
+
function getKcContext(params) {
|
15
|
+
var _a, _b;
|
16
|
+
const { mockPageId, storyParams } = params !== null && params !== void 0 ? params : {};
|
17
|
+
const realKcContext = getKcContextFromWindow();
|
18
|
+
if (mockPageId !== undefined && realKcContext === undefined) {
|
19
|
+
//TODO maybe trow if no mock fo custom page
|
20
|
+
console.log([
|
21
|
+
`%cKeycloakify: ${symToStr({ mockPageId })} set to ${mockPageId}.`,
|
22
|
+
`If assets are missing make sure you have built your Keycloak theme at least once.`
|
23
|
+
].join(" "), "background: red; color: yellow; font-size: medium");
|
24
|
+
const kcContextDefaultMock = kcContextMocks.find(({ pageId }) => pageId === mockPageId);
|
25
|
+
const partialKcContextCustomMock = (() => {
|
26
|
+
const out = {};
|
27
|
+
const mockDataPick = mockData === null || mockData === void 0 ? void 0 : mockData.find(({ pageId }) => pageId === mockPageId);
|
28
|
+
if (mockDataPick !== undefined) {
|
29
|
+
deepAssign({
|
30
|
+
"target": out,
|
31
|
+
"source": mockDataPick
|
32
|
+
});
|
33
|
+
}
|
34
|
+
if (storyParams !== undefined) {
|
35
|
+
deepAssign({
|
36
|
+
"target": out,
|
37
|
+
"source": storyParams
|
38
|
+
});
|
39
|
+
}
|
40
|
+
return Object.keys(out).length === 0 ? undefined : out;
|
41
|
+
})();
|
42
|
+
if (kcContextDefaultMock === undefined && partialKcContextCustomMock === undefined) {
|
43
|
+
console.warn([
|
44
|
+
`WARNING: You declared the non build in page ${mockPageId} but you didn't `,
|
45
|
+
`provide mock data needed to debug the page outside of Keycloak as you are trying to do now.`,
|
46
|
+
`Please check the documentation of the getKcContext function`
|
47
|
+
].join("\n"));
|
48
|
+
}
|
49
|
+
const kcContext = {};
|
50
|
+
deepAssign({
|
51
|
+
"target": kcContext,
|
52
|
+
"source": kcContextDefaultMock !== undefined ? kcContextDefaultMock : Object.assign({ "pageId": mockPageId }, kcContextCommonMock)
|
53
|
+
});
|
54
|
+
if (partialKcContextCustomMock !== undefined) {
|
55
|
+
deepAssign({
|
56
|
+
"target": kcContext,
|
57
|
+
"source": partialKcContextCustomMock
|
58
|
+
});
|
59
|
+
if (partialKcContextCustomMock.pageId === "register-user-profile.ftl" ||
|
60
|
+
partialKcContextCustomMock.pageId === "update-user-profile.ftl" ||
|
61
|
+
partialKcContextCustomMock.pageId === "idp-review-user-profile.ftl") {
|
62
|
+
assert((kcContextDefaultMock === null || kcContextDefaultMock === void 0 ? void 0 : kcContextDefaultMock.pageId) === "register-user-profile.ftl" ||
|
63
|
+
(kcContextDefaultMock === null || kcContextDefaultMock === void 0 ? void 0 : kcContextDefaultMock.pageId) === "update-user-profile.ftl" ||
|
64
|
+
(kcContextDefaultMock === null || kcContextDefaultMock === void 0 ? void 0 : kcContextDefaultMock.pageId) === "idp-review-user-profile.ftl");
|
65
|
+
const { attributes } = kcContextDefaultMock.profile;
|
66
|
+
id(kcContext).profile.attributes = [];
|
67
|
+
id(kcContext).profile.attributesByName = {};
|
68
|
+
const partialAttributes = [
|
69
|
+
...((_b = (_a = partialKcContextCustomMock.profile) === null || _a === void 0 ? void 0 : _a.attributes) !== null && _b !== void 0 ? _b : [])
|
70
|
+
].filter(exclude(undefined));
|
71
|
+
attributes.forEach(attribute => {
|
72
|
+
const partialAttribute = partialAttributes.find(({ name }) => name === attribute.name);
|
73
|
+
const augmentedAttribute = {};
|
74
|
+
deepAssign({
|
75
|
+
"target": augmentedAttribute,
|
76
|
+
"source": attribute
|
77
|
+
});
|
78
|
+
if (partialAttribute !== undefined) {
|
79
|
+
partialAttributes.splice(partialAttributes.indexOf(partialAttribute), 1);
|
80
|
+
deepAssign({
|
81
|
+
"target": augmentedAttribute,
|
82
|
+
"source": partialAttribute
|
83
|
+
});
|
84
|
+
}
|
85
|
+
id(kcContext).profile.attributes.push(augmentedAttribute);
|
86
|
+
id(kcContext).profile.attributesByName[augmentedAttribute.name] = augmentedAttribute;
|
87
|
+
});
|
88
|
+
partialAttributes
|
89
|
+
.map(partialAttribute => (Object.assign({ "validators": {} }, partialAttribute)))
|
90
|
+
.forEach(partialAttribute => {
|
91
|
+
const { name } = partialAttribute;
|
92
|
+
assert(name !== undefined, "If you define a mock attribute it must have at least a name");
|
93
|
+
id(kcContext).profile.attributes.push(partialAttribute);
|
94
|
+
id(kcContext).profile.attributesByName[name] = partialAttribute;
|
95
|
+
});
|
96
|
+
}
|
97
|
+
}
|
98
|
+
return { kcContext };
|
99
|
+
}
|
100
|
+
if (realKcContext === undefined) {
|
101
|
+
return { "kcContext": undefined };
|
102
|
+
}
|
103
|
+
if (id(loginThemePageIds).indexOf(realKcContext.pageId) < 0 && !("login" in realKcContext)) {
|
104
|
+
return { "kcContext": undefined };
|
105
|
+
}
|
106
|
+
{
|
107
|
+
const { url } = realKcContext;
|
108
|
+
url.resourcesCommonPath = pathJoin(url.resourcesPath, pathBasename(mockTestingResourcesCommonPath));
|
109
|
+
}
|
110
|
+
return { "kcContext": realKcContext };
|
111
|
+
}
|
112
|
+
return { getKcContext };
|
113
|
+
}
|
114
|
+
//# sourceMappingURL=createGetKcContext.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"createGetKcContext.js","sourceRoot":"","sources":["../../src/login/kcContext/createGetKcContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,8BAA8B,EAAE,MAAM,0CAA0C,CAAC;AAC1F,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AAEnF,MAAM,UAAU,kBAAkB,CAAwD,MAEzF;IACG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;IAElC,SAAS,YAAY,CAAuF,MAG3G;;QAKG,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;QAEjD,MAAM,aAAa,GAAG,sBAAsB,EAAsB,CAAC;QAEnE,IAAI,UAAU,KAAK,SAAS,IAAI,aAAa,KAAK,SAAS,EAAE;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AAS,EAAE;YAC7B,OAAO,EAAE,WAAW,EAAE,SAAgB,EAAE,CAAC;SAC5C;QAED,IAAI,EAAE,CAAoB,iBAAiB,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,IAAI,aAAa,CAAC,EAAE;YAC3G,OAAO,EAAE,WAAW,EAAE,SAAgB,EAAE,CAAC;SAC5C;QAED;YACI,MAAM,EAAE,GAAG,EAAE,GAAG,aAAa,CAAC;YAE9B,GAAG,CAAC,mBAAmB,GAAG,QAAQ,CAAC,GAAG,CAAC,aAAa,EAAE,YAAY,CAAC,8BAA8B,CAAC,CAAC,CAAC;SACvG;QAED,OAAO,EAAE,WAAW,EAAE,aAAoB,EAAE,CAAC;IACjD,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,CAAC;AAC5B,CAAC"}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { DeepPartial } from "../../tools/DeepPartial";
|
2
2
|
import type { ExtendKcContext } from "./getKcContextFromWindow";
|
3
|
+
/** @deprecated: Use createGetKcContext instead */
|
3
4
|
export declare function getKcContext<KcContextExtension extends {
|
4
5
|
pageId: string;
|
5
6
|
} = never>(params?: {
|
@@ -1,94 +1,11 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
import { id } from "tsafe/id";
|
4
|
-
import { exclude } from "tsafe/exclude";
|
5
|
-
import { assert } from "tsafe/assert";
|
6
|
-
import { getKcContextFromWindow } from "./getKcContextFromWindow";
|
7
|
-
import { pathJoin } from "../../bin/tools/pathJoin";
|
8
|
-
import { pathBasename } from "../../tools/pathBasename";
|
9
|
-
import { mockTestingResourcesCommonPath } from "../../bin/mockTestingResourcesPath";
|
10
|
-
import { symToStr } from "tsafe/symToStr";
|
11
|
-
import { loginThemePageIds } from "../../bin/keycloakify/generateFtl/pageId";
|
1
|
+
import { createGetKcContext } from "./createGetKcContext";
|
2
|
+
/** @deprecated: Use createGetKcContext instead */
|
12
3
|
export function getKcContext(params) {
|
13
|
-
var _a, _b;
|
14
4
|
const { mockPageId, mockData } = params !== null && params !== void 0 ? params : {};
|
15
|
-
const
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
`If assets are missing make sure you have built your Keycloak theme at least once.`
|
21
|
-
].join(" "), "background: red; color: yellow; font-size: medium");
|
22
|
-
const kcContextDefaultMock = kcContextMocks.find(({ pageId }) => pageId === mockPageId);
|
23
|
-
const partialKcContextCustomMock = mockData === null || mockData === void 0 ? void 0 : mockData.find(({ pageId }) => pageId === mockPageId);
|
24
|
-
if (kcContextDefaultMock === undefined && partialKcContextCustomMock === undefined) {
|
25
|
-
console.warn([
|
26
|
-
`WARNING: You declared the non build in page ${mockPageId} but you didn't `,
|
27
|
-
`provide mock data needed to debug the page outside of Keycloak as you are trying to do now.`,
|
28
|
-
`Please check the documentation of the getKcContext function`
|
29
|
-
].join("\n"));
|
30
|
-
}
|
31
|
-
const kcContext = {};
|
32
|
-
deepAssign({
|
33
|
-
"target": kcContext,
|
34
|
-
"source": kcContextDefaultMock !== undefined ? kcContextDefaultMock : Object.assign({ "pageId": mockPageId }, kcContextCommonMock)
|
35
|
-
});
|
36
|
-
if (partialKcContextCustomMock !== undefined) {
|
37
|
-
deepAssign({
|
38
|
-
"target": kcContext,
|
39
|
-
"source": partialKcContextCustomMock
|
40
|
-
});
|
41
|
-
if (partialKcContextCustomMock.pageId === "register-user-profile.ftl" ||
|
42
|
-
partialKcContextCustomMock.pageId === "update-user-profile.ftl" ||
|
43
|
-
partialKcContextCustomMock.pageId === "idp-review-user-profile.ftl") {
|
44
|
-
assert((kcContextDefaultMock === null || kcContextDefaultMock === void 0 ? void 0 : kcContextDefaultMock.pageId) === "register-user-profile.ftl" ||
|
45
|
-
(kcContextDefaultMock === null || kcContextDefaultMock === void 0 ? void 0 : kcContextDefaultMock.pageId) === "update-user-profile.ftl" ||
|
46
|
-
(kcContextDefaultMock === null || kcContextDefaultMock === void 0 ? void 0 : kcContextDefaultMock.pageId) === "idp-review-user-profile.ftl");
|
47
|
-
const { attributes } = kcContextDefaultMock.profile;
|
48
|
-
id(kcContext).profile.attributes = [];
|
49
|
-
id(kcContext).profile.attributesByName = {};
|
50
|
-
const partialAttributes = [
|
51
|
-
...((_b = (_a = partialKcContextCustomMock.profile) === null || _a === void 0 ? void 0 : _a.attributes) !== null && _b !== void 0 ? _b : [])
|
52
|
-
].filter(exclude(undefined));
|
53
|
-
attributes.forEach(attribute => {
|
54
|
-
const partialAttribute = partialAttributes.find(({ name }) => name === attribute.name);
|
55
|
-
const augmentedAttribute = {};
|
56
|
-
deepAssign({
|
57
|
-
"target": augmentedAttribute,
|
58
|
-
"source": attribute
|
59
|
-
});
|
60
|
-
if (partialAttribute !== undefined) {
|
61
|
-
partialAttributes.splice(partialAttributes.indexOf(partialAttribute), 1);
|
62
|
-
deepAssign({
|
63
|
-
"target": augmentedAttribute,
|
64
|
-
"source": partialAttribute
|
65
|
-
});
|
66
|
-
}
|
67
|
-
id(kcContext).profile.attributes.push(augmentedAttribute);
|
68
|
-
id(kcContext).profile.attributesByName[augmentedAttribute.name] = augmentedAttribute;
|
69
|
-
});
|
70
|
-
partialAttributes
|
71
|
-
.map(partialAttribute => (Object.assign({ "validators": {} }, partialAttribute)))
|
72
|
-
.forEach(partialAttribute => {
|
73
|
-
const { name } = partialAttribute;
|
74
|
-
assert(name !== undefined, "If you define a mock attribute it must have at least a name");
|
75
|
-
id(kcContext).profile.attributes.push(partialAttribute);
|
76
|
-
id(kcContext).profile.attributesByName[name] = partialAttribute;
|
77
|
-
});
|
78
|
-
}
|
79
|
-
}
|
80
|
-
return { kcContext };
|
81
|
-
}
|
82
|
-
if (realKcContext === undefined) {
|
83
|
-
return { "kcContext": undefined };
|
84
|
-
}
|
85
|
-
if (id(loginThemePageIds).indexOf(realKcContext.pageId) < 0 && !("login" in realKcContext)) {
|
86
|
-
return { "kcContext": undefined };
|
87
|
-
}
|
88
|
-
{
|
89
|
-
const { url } = realKcContext;
|
90
|
-
url.resourcesCommonPath = pathJoin(url.resourcesPath, pathBasename(mockTestingResourcesCommonPath));
|
91
|
-
}
|
92
|
-
return { "kcContext": realKcContext };
|
5
|
+
const { getKcContext } = createGetKcContext({
|
6
|
+
mockData
|
7
|
+
});
|
8
|
+
const { kcContext } = getKcContext({ mockPageId });
|
9
|
+
return { kcContext };
|
93
10
|
}
|
94
11
|
//# sourceMappingURL=getKcContext.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getKcContext.js","sourceRoot":"","sources":["../../src/login/kcContext/getKcContext.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"getKcContext.js","sourceRoot":"","sources":["../../src/login/kcContext/getKcContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,kDAAkD;AAClD,MAAM,UAAU,YAAY,CAAwD,MAGnF;IACG,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;IAE9C,MAAM,EAAE,YAAY,EAAE,GAAG,kBAAkB,CAAqB;QAC5D,QAAQ;KACX,CAAC,CAAC;IAEH,MAAM,EAAE,SAAS,EAAE,GAAG,YAAY,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;IAEnD,OAAO,EAAE,SAAS,EAAE,CAAC;AACzB,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "keycloakify",
|
3
|
-
"version": "7.6.
|
3
|
+
"version": "7.6.8",
|
4
4
|
"description": "Create Keycloak themes using React",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -58,6 +58,7 @@
|
|
58
58
|
"src/account/i18n/index.ts",
|
59
59
|
"src/account/index.ts",
|
60
60
|
"src/account/kcContext/KcContext.ts",
|
61
|
+
"src/account/kcContext/createGetKcContext.ts",
|
61
62
|
"src/account/kcContext/getKcContext.ts",
|
62
63
|
"src/account/kcContext/getKcContextFromWindow.ts",
|
63
64
|
"src/account/kcContext/index.ts",
|
@@ -144,6 +145,7 @@
|
|
144
145
|
"src/login/i18n/index.ts",
|
145
146
|
"src/login/index.ts",
|
146
147
|
"src/login/kcContext/KcContext.ts",
|
148
|
+
"src/login/kcContext/createGetKcContext.ts",
|
147
149
|
"src/login/kcContext/getKcContext.ts",
|
148
150
|
"src/login/kcContext/getKcContextFromWindow.ts",
|
149
151
|
"src/login/kcContext/index.ts",
|
@@ -285,6 +287,9 @@
|
|
285
287
|
"account/kcContext/KcContext.d.ts",
|
286
288
|
"account/kcContext/KcContext.js",
|
287
289
|
"account/kcContext/KcContext.js.map",
|
290
|
+
"account/kcContext/createGetKcContext.d.ts",
|
291
|
+
"account/kcContext/createGetKcContext.js",
|
292
|
+
"account/kcContext/createGetKcContext.js.map",
|
288
293
|
"account/kcContext/getKcContext.d.ts",
|
289
294
|
"account/kcContext/getKcContext.js",
|
290
295
|
"account/kcContext/getKcContext.js.map",
|
@@ -538,6 +543,9 @@
|
|
538
543
|
"login/kcContext/KcContext.d.ts",
|
539
544
|
"login/kcContext/KcContext.js",
|
540
545
|
"login/kcContext/KcContext.js.map",
|
546
|
+
"login/kcContext/createGetKcContext.d.ts",
|
547
|
+
"login/kcContext/createGetKcContext.js",
|
548
|
+
"login/kcContext/createGetKcContext.js.map",
|
541
549
|
"login/kcContext/getKcContext.d.ts",
|
542
550
|
"login/kcContext/getKcContext.js",
|
543
551
|
"login/kcContext/getKcContext.js.map",
|
@@ -696,23 +704,36 @@
|
|
696
704
|
},
|
697
705
|
"devDependencies": {
|
698
706
|
"@babel/core": "^7.0.0",
|
707
|
+
"@storybook/addon-a11y": "^6.5.16",
|
708
|
+
"@storybook/addon-actions": "^6.5.13",
|
709
|
+
"@storybook/addon-essentials": "^6.5.13",
|
710
|
+
"@storybook/addon-interactions": "^6.5.13",
|
711
|
+
"@storybook/addon-links": "^6.5.13",
|
712
|
+
"@storybook/builder-webpack5": "^6.5.13",
|
713
|
+
"@storybook/manager-webpack5": "^6.5.13",
|
714
|
+
"@storybook/react": "^6.5.13",
|
715
|
+
"@storybook/testing-library": "^0.0.13",
|
699
716
|
"@types/make-fetch-happen": "^10.0.1",
|
700
717
|
"@types/minimist": "^1.2.2",
|
701
718
|
"@types/node": "^18.15.3",
|
702
|
-
"@types/react": "18.0.
|
719
|
+
"@types/react": "^18.0.35",
|
720
|
+
"@types/react-dom": "^18.0.11",
|
703
721
|
"@types/yauzl": "^2.10.0",
|
704
722
|
"concurrently": "^7.6.0",
|
705
723
|
"copyfiles": "^2.4.1",
|
724
|
+
"eslint-plugin-storybook": "^0.6.7",
|
706
725
|
"husky": "^4.3.8",
|
707
726
|
"lint-staged": "^11.0.0",
|
708
727
|
"prettier": "^2.3.0",
|
709
728
|
"properties-parser": "^0.3.1",
|
710
|
-
"react": "18.
|
729
|
+
"react": "^18.2.0",
|
730
|
+
"react-dom": "^18.2.0",
|
711
731
|
"rimraf": "^3.0.2",
|
712
732
|
"scripting-tools": "^0.19.13",
|
733
|
+
"storybook-dark-mode": "^1.1.2",
|
713
734
|
"ts-node": "^10.9.1",
|
714
735
|
"tsc-alias": "^1.8.3",
|
715
|
-
"typescript": "^5.0.
|
736
|
+
"typescript": "^5.0.4",
|
716
737
|
"vitest": "^0.29.8",
|
717
738
|
"zod-to-json-schema": "^3.20.4"
|
718
739
|
},
|
package/src/account/index.ts
CHANGED
@@ -3,6 +3,7 @@ import Fallback from "keycloakify/account/Fallback";
|
|
3
3
|
export default Fallback;
|
4
4
|
|
5
5
|
export { getKcContext } from "keycloakify/account/kcContext/getKcContext";
|
6
|
+
export { createGetKcContext } from "keycloakify/account/kcContext/createGetKcContext";
|
6
7
|
export { createUseI18n } from "keycloakify/account/i18n/i18n";
|
7
8
|
|
8
9
|
export type { PageProps } from "keycloakify/account/pages/PageProps";
|
@@ -0,0 +1,110 @@
|
|
1
|
+
import type { DeepPartial } from "keycloakify/tools/DeepPartial";
|
2
|
+
import { deepAssign } from "keycloakify/tools/deepAssign";
|
3
|
+
import type { ExtendKcContext } from "./getKcContextFromWindow";
|
4
|
+
import { getKcContextFromWindow } from "./getKcContextFromWindow";
|
5
|
+
import { pathJoin } from "keycloakify/bin/tools/pathJoin";
|
6
|
+
import { pathBasename } from "keycloakify/tools/pathBasename";
|
7
|
+
import { mockTestingResourcesCommonPath } from "keycloakify/bin/mockTestingResourcesPath";
|
8
|
+
import { symToStr } from "tsafe/symToStr";
|
9
|
+
import { kcContextMocks, kcContextCommonMock } from "keycloakify/account/kcContext/kcContextMocks";
|
10
|
+
import { id } from "tsafe/id";
|
11
|
+
import { accountThemePageIds } from "keycloakify/bin/keycloakify/generateFtl/pageId";
|
12
|
+
|
13
|
+
export function createGetKcContext<KcContextExtension extends { pageId: string } = never>(params?: {
|
14
|
+
mockData?: readonly DeepPartial<ExtendKcContext<KcContextExtension>>[];
|
15
|
+
}) {
|
16
|
+
const { mockData } = params ?? {};
|
17
|
+
|
18
|
+
function getKcContext<PageId extends ExtendKcContext<KcContextExtension>["pageId"] | undefined = undefined>(params?: {
|
19
|
+
mockPageId?: PageId;
|
20
|
+
storyParams?: DeepPartial<Extract<ExtendKcContext<KcContextExtension>, { pageId: PageId }>>;
|
21
|
+
}): {
|
22
|
+
kcContext: PageId extends undefined
|
23
|
+
? ExtendKcContext<KcContextExtension> | undefined
|
24
|
+
: Extract<ExtendKcContext<KcContextExtension>, { pageId: PageId }>;
|
25
|
+
} {
|
26
|
+
const { mockPageId, storyParams } = params ?? {};
|
27
|
+
|
28
|
+
const realKcContext = getKcContextFromWindow<KcContextExtension>();
|
29
|
+
|
30
|
+
if (mockPageId !== undefined && realKcContext === undefined) {
|
31
|
+
//TODO maybe trow if no mock fo custom page
|
32
|
+
|
33
|
+
console.log(
|
34
|
+
[
|
35
|
+
`%cKeycloakify: ${symToStr({ mockPageId })} set to ${mockPageId}.`,
|
36
|
+
`If assets are missing make sure you have built your Keycloak theme at least once.`
|
37
|
+
].join(" "),
|
38
|
+
"background: red; color: yellow; font-size: medium"
|
39
|
+
);
|
40
|
+
|
41
|
+
const kcContextDefaultMock = kcContextMocks.find(({ pageId }) => pageId === mockPageId);
|
42
|
+
|
43
|
+
const partialKcContextCustomMock = (() => {
|
44
|
+
const out: DeepPartial<ExtendKcContext<KcContextExtension>> = {};
|
45
|
+
|
46
|
+
const mockDataPick = mockData?.find(({ pageId }) => pageId === mockPageId);
|
47
|
+
|
48
|
+
if (mockDataPick !== undefined) {
|
49
|
+
deepAssign({
|
50
|
+
"target": out,
|
51
|
+
"source": mockDataPick
|
52
|
+
});
|
53
|
+
}
|
54
|
+
|
55
|
+
if (storyParams !== undefined) {
|
56
|
+
deepAssign({
|
57
|
+
"target": out,
|
58
|
+
"source": storyParams
|
59
|
+
});
|
60
|
+
}
|
61
|
+
|
62
|
+
return Object.keys(out).length === 0 ? undefined : out;
|
63
|
+
})();
|
64
|
+
|
65
|
+
if (kcContextDefaultMock === undefined && partialKcContextCustomMock === undefined) {
|
66
|
+
console.warn(
|
67
|
+
[
|
68
|
+
`WARNING: You declared the non build in page ${mockPageId} but you didn't `,
|
69
|
+
`provide mock data needed to debug the page outside of Keycloak as you are trying to do now.`,
|
70
|
+
`Please check the documentation of the getKcContext function`
|
71
|
+
].join("\n")
|
72
|
+
);
|
73
|
+
}
|
74
|
+
|
75
|
+
const kcContext: any = {};
|
76
|
+
|
77
|
+
deepAssign({
|
78
|
+
"target": kcContext,
|
79
|
+
"source": kcContextDefaultMock !== undefined ? kcContextDefaultMock : { "pageId": mockPageId, ...kcContextCommonMock }
|
80
|
+
});
|
81
|
+
|
82
|
+
if (partialKcContextCustomMock !== undefined) {
|
83
|
+
deepAssign({
|
84
|
+
"target": kcContext,
|
85
|
+
"source": partialKcContextCustomMock
|
86
|
+
});
|
87
|
+
}
|
88
|
+
|
89
|
+
return { kcContext };
|
90
|
+
}
|
91
|
+
|
92
|
+
if (realKcContext === undefined) {
|
93
|
+
return { "kcContext": undefined as any };
|
94
|
+
}
|
95
|
+
|
96
|
+
if (id<readonly string[]>(accountThemePageIds).indexOf(realKcContext.pageId) < 0 && !("account" in realKcContext)) {
|
97
|
+
return { "kcContext": undefined as any };
|
98
|
+
}
|
99
|
+
|
100
|
+
{
|
101
|
+
const { url } = realKcContext;
|
102
|
+
|
103
|
+
url.resourcesCommonPath = pathJoin(url.resourcesPath, pathBasename(mockTestingResourcesCommonPath));
|
104
|
+
}
|
105
|
+
|
106
|
+
return { "kcContext": realKcContext as any };
|
107
|
+
}
|
108
|
+
|
109
|
+
return { getKcContext };
|
110
|
+
}
|
@@ -1,78 +1,19 @@
|
|
1
1
|
import type { DeepPartial } from "keycloakify/tools/DeepPartial";
|
2
|
-
import { deepAssign } from "keycloakify/tools/deepAssign";
|
3
2
|
import type { ExtendKcContext } from "./getKcContextFromWindow";
|
4
|
-
import {
|
5
|
-
import { pathJoin } from "keycloakify/bin/tools/pathJoin";
|
6
|
-
import { pathBasename } from "keycloakify/tools/pathBasename";
|
7
|
-
import { mockTestingResourcesCommonPath } from "keycloakify/bin/mockTestingResourcesPath";
|
8
|
-
import { symToStr } from "tsafe/symToStr";
|
9
|
-
import { kcContextMocks, kcContextCommonMock } from "keycloakify/account/kcContext/kcContextMocks";
|
10
|
-
import { id } from "tsafe/id";
|
11
|
-
import { accountThemePageIds } from "keycloakify/bin/keycloakify/generateFtl/pageId";
|
3
|
+
import { createGetKcContext } from "./createGetKcContext";
|
12
4
|
|
5
|
+
/** @deprecated: Use createGetKcContext instead */
|
13
6
|
export function getKcContext<KcContextExtension extends { pageId: string } = never>(params?: {
|
14
7
|
mockPageId?: ExtendKcContext<KcContextExtension>["pageId"];
|
15
8
|
mockData?: readonly DeepPartial<ExtendKcContext<KcContextExtension>>[];
|
16
9
|
}): { kcContext: ExtendKcContext<KcContextExtension> | undefined } {
|
17
10
|
const { mockPageId, mockData } = params ?? {};
|
18
11
|
|
19
|
-
const
|
12
|
+
const { getKcContext } = createGetKcContext({
|
13
|
+
mockData
|
14
|
+
});
|
20
15
|
|
21
|
-
|
22
|
-
//TODO maybe trow if no mock fo custom page
|
16
|
+
const { kcContext } = getKcContext({ mockPageId });
|
23
17
|
|
24
|
-
|
25
|
-
[
|
26
|
-
`%cKeycloakify: ${symToStr({ mockPageId })} set to ${mockPageId}.`,
|
27
|
-
`If assets are missing make sure you have built your Keycloak theme at least once.`
|
28
|
-
].join(" "),
|
29
|
-
"background: red; color: yellow; font-size: medium"
|
30
|
-
);
|
31
|
-
|
32
|
-
const kcContextDefaultMock = kcContextMocks.find(({ pageId }) => pageId === mockPageId);
|
33
|
-
|
34
|
-
const partialKcContextCustomMock = mockData?.find(({ pageId }) => pageId === mockPageId);
|
35
|
-
|
36
|
-
if (kcContextDefaultMock === undefined && partialKcContextCustomMock === undefined) {
|
37
|
-
console.warn(
|
38
|
-
[
|
39
|
-
`WARNING: You declared the non build in page ${mockPageId} but you didn't `,
|
40
|
-
`provide mock data needed to debug the page outside of Keycloak as you are trying to do now.`,
|
41
|
-
`Please check the documentation of the getKcContext function`
|
42
|
-
].join("\n")
|
43
|
-
);
|
44
|
-
}
|
45
|
-
|
46
|
-
const kcContext: any = {};
|
47
|
-
|
48
|
-
deepAssign({
|
49
|
-
"target": kcContext,
|
50
|
-
"source": kcContextDefaultMock !== undefined ? kcContextDefaultMock : { "pageId": mockPageId, ...kcContextCommonMock }
|
51
|
-
});
|
52
|
-
|
53
|
-
if (partialKcContextCustomMock !== undefined) {
|
54
|
-
deepAssign({
|
55
|
-
"target": kcContext,
|
56
|
-
"source": partialKcContextCustomMock
|
57
|
-
});
|
58
|
-
}
|
59
|
-
|
60
|
-
return { kcContext };
|
61
|
-
}
|
62
|
-
|
63
|
-
if (realKcContext === undefined) {
|
64
|
-
return { "kcContext": undefined };
|
65
|
-
}
|
66
|
-
|
67
|
-
if (id<readonly string[]>(accountThemePageIds).indexOf(realKcContext.pageId) < 0 && !("account" in realKcContext)) {
|
68
|
-
return { "kcContext": undefined };
|
69
|
-
}
|
70
|
-
|
71
|
-
{
|
72
|
-
const { url } = realKcContext;
|
73
|
-
|
74
|
-
url.resourcesCommonPath = pathJoin(url.resourcesPath, pathBasename(mockTestingResourcesCommonPath));
|
75
|
-
}
|
76
|
-
|
77
|
-
return { "kcContext": realKcContext };
|
18
|
+
return { kcContext };
|
78
19
|
}
|
@@ -184,7 +184,7 @@ export async function generateKeycloakThemeResources(params: {
|
|
184
184
|
const themeResourcesDirPath = pathJoin(themeDirPath, "resources");
|
185
185
|
|
186
186
|
transformCodebase({
|
187
|
-
"srcDirPath": pathJoin(tmpDirPath, "keycloak",
|
187
|
+
"srcDirPath": pathJoin(tmpDirPath, "keycloak", themeType, "resources"),
|
188
188
|
"destDirPath": themeResourcesDirPath
|
189
189
|
});
|
190
190
|
|
package/src/login/index.ts
CHANGED
@@ -4,6 +4,7 @@ export default Fallback;
|
|
4
4
|
|
5
5
|
export { useDownloadTerms } from "keycloakify/login/lib/useDownloadTerms";
|
6
6
|
export { getKcContext } from "keycloakify/login/kcContext/getKcContext";
|
7
|
+
export { createGetKcContext } from "keycloakify/login/kcContext/createGetKcContext";
|
7
8
|
export { createUseI18n } from "keycloakify/login/i18n/i18n";
|
8
9
|
|
9
10
|
export type { PageProps } from "keycloakify/login/pages/PageProps";
|
@@ -0,0 +1,168 @@
|
|
1
|
+
import type { KcContext, Attribute } from "./KcContext";
|
2
|
+
import { kcContextMocks, kcContextCommonMock } from "./kcContextMocks";
|
3
|
+
import type { DeepPartial } from "keycloakify/tools/DeepPartial";
|
4
|
+
import { deepAssign } from "keycloakify/tools/deepAssign";
|
5
|
+
import { id } from "tsafe/id";
|
6
|
+
import { exclude } from "tsafe/exclude";
|
7
|
+
import { assert } from "tsafe/assert";
|
8
|
+
import type { ExtendKcContext } from "./getKcContextFromWindow";
|
9
|
+
import { getKcContextFromWindow } from "./getKcContextFromWindow";
|
10
|
+
import { pathJoin } from "keycloakify/bin/tools/pathJoin";
|
11
|
+
import { pathBasename } from "keycloakify/tools/pathBasename";
|
12
|
+
import { mockTestingResourcesCommonPath } from "keycloakify/bin/mockTestingResourcesPath";
|
13
|
+
import { symToStr } from "tsafe/symToStr";
|
14
|
+
import { loginThemePageIds } from "keycloakify/bin/keycloakify/generateFtl/pageId";
|
15
|
+
|
16
|
+
export function createGetKcContext<KcContextExtension extends { pageId: string } = never>(params?: {
|
17
|
+
mockData?: readonly DeepPartial<ExtendKcContext<KcContextExtension>>[];
|
18
|
+
}) {
|
19
|
+
const { mockData } = params ?? {};
|
20
|
+
|
21
|
+
function getKcContext<PageId extends ExtendKcContext<KcContextExtension>["pageId"] | undefined = undefined>(params?: {
|
22
|
+
mockPageId?: PageId;
|
23
|
+
storyParams?: DeepPartial<Extract<ExtendKcContext<KcContextExtension>, { pageId: PageId }>>;
|
24
|
+
}): {
|
25
|
+
kcContext: PageId extends undefined
|
26
|
+
? ExtendKcContext<KcContextExtension> | undefined
|
27
|
+
: Extract<ExtendKcContext<KcContextExtension>, { pageId: PageId }>;
|
28
|
+
} {
|
29
|
+
const { mockPageId, storyParams } = params ?? {};
|
30
|
+
|
31
|
+
const realKcContext = getKcContextFromWindow<KcContextExtension>();
|
32
|
+
|
33
|
+
if (mockPageId !== undefined && realKcContext === undefined) {
|
34
|
+
//TODO maybe trow if no mock fo custom page
|
35
|
+
|
36
|
+
console.log(
|
37
|
+
[
|
38
|
+
`%cKeycloakify: ${symToStr({ mockPageId })} set to ${mockPageId}.`,
|
39
|
+
`If assets are missing make sure you have built your Keycloak theme at least once.`
|
40
|
+
].join(" "),
|
41
|
+
"background: red; color: yellow; font-size: medium"
|
42
|
+
);
|
43
|
+
|
44
|
+
const kcContextDefaultMock = kcContextMocks.find(({ pageId }) => pageId === mockPageId);
|
45
|
+
|
46
|
+
const partialKcContextCustomMock = (() => {
|
47
|
+
const out: DeepPartial<ExtendKcContext<KcContextExtension>> = {};
|
48
|
+
|
49
|
+
const mockDataPick = mockData?.find(({ pageId }) => pageId === mockPageId);
|
50
|
+
|
51
|
+
if (mockDataPick !== undefined) {
|
52
|
+
deepAssign({
|
53
|
+
"target": out,
|
54
|
+
"source": mockDataPick
|
55
|
+
});
|
56
|
+
}
|
57
|
+
|
58
|
+
if (storyParams !== undefined) {
|
59
|
+
deepAssign({
|
60
|
+
"target": out,
|
61
|
+
"source": storyParams
|
62
|
+
});
|
63
|
+
}
|
64
|
+
|
65
|
+
return Object.keys(out).length === 0 ? undefined : out;
|
66
|
+
})();
|
67
|
+
|
68
|
+
if (kcContextDefaultMock === undefined && partialKcContextCustomMock === undefined) {
|
69
|
+
console.warn(
|
70
|
+
[
|
71
|
+
`WARNING: You declared the non build in page ${mockPageId} but you didn't `,
|
72
|
+
`provide mock data needed to debug the page outside of Keycloak as you are trying to do now.`,
|
73
|
+
`Please check the documentation of the getKcContext function`
|
74
|
+
].join("\n")
|
75
|
+
);
|
76
|
+
}
|
77
|
+
|
78
|
+
const kcContext: any = {};
|
79
|
+
|
80
|
+
deepAssign({
|
81
|
+
"target": kcContext,
|
82
|
+
"source": kcContextDefaultMock !== undefined ? kcContextDefaultMock : { "pageId": mockPageId, ...kcContextCommonMock }
|
83
|
+
});
|
84
|
+
|
85
|
+
if (partialKcContextCustomMock !== undefined) {
|
86
|
+
deepAssign({
|
87
|
+
"target": kcContext,
|
88
|
+
"source": partialKcContextCustomMock
|
89
|
+
});
|
90
|
+
|
91
|
+
if (
|
92
|
+
partialKcContextCustomMock.pageId === "register-user-profile.ftl" ||
|
93
|
+
partialKcContextCustomMock.pageId === "update-user-profile.ftl" ||
|
94
|
+
partialKcContextCustomMock.pageId === "idp-review-user-profile.ftl"
|
95
|
+
) {
|
96
|
+
assert(
|
97
|
+
kcContextDefaultMock?.pageId === "register-user-profile.ftl" ||
|
98
|
+
kcContextDefaultMock?.pageId === "update-user-profile.ftl" ||
|
99
|
+
kcContextDefaultMock?.pageId === "idp-review-user-profile.ftl"
|
100
|
+
);
|
101
|
+
|
102
|
+
const { attributes } = kcContextDefaultMock.profile;
|
103
|
+
|
104
|
+
id<KcContext.RegisterUserProfile>(kcContext).profile.attributes = [];
|
105
|
+
id<KcContext.RegisterUserProfile>(kcContext).profile.attributesByName = {};
|
106
|
+
|
107
|
+
const partialAttributes = [
|
108
|
+
...((partialKcContextCustomMock as DeepPartial<KcContext.RegisterUserProfile>).profile?.attributes ?? [])
|
109
|
+
].filter(exclude(undefined));
|
110
|
+
|
111
|
+
attributes.forEach(attribute => {
|
112
|
+
const partialAttribute = partialAttributes.find(({ name }) => name === attribute.name);
|
113
|
+
|
114
|
+
const augmentedAttribute: Attribute = {} as any;
|
115
|
+
|
116
|
+
deepAssign({
|
117
|
+
"target": augmentedAttribute,
|
118
|
+
"source": attribute
|
119
|
+
});
|
120
|
+
|
121
|
+
if (partialAttribute !== undefined) {
|
122
|
+
partialAttributes.splice(partialAttributes.indexOf(partialAttribute), 1);
|
123
|
+
|
124
|
+
deepAssign({
|
125
|
+
"target": augmentedAttribute,
|
126
|
+
"source": partialAttribute
|
127
|
+
});
|
128
|
+
}
|
129
|
+
|
130
|
+
id<KcContext.RegisterUserProfile>(kcContext).profile.attributes.push(augmentedAttribute);
|
131
|
+
id<KcContext.RegisterUserProfile>(kcContext).profile.attributesByName[augmentedAttribute.name] = augmentedAttribute;
|
132
|
+
});
|
133
|
+
|
134
|
+
partialAttributes
|
135
|
+
.map(partialAttribute => ({ "validators": {}, ...partialAttribute }))
|
136
|
+
.forEach(partialAttribute => {
|
137
|
+
const { name } = partialAttribute;
|
138
|
+
|
139
|
+
assert(name !== undefined, "If you define a mock attribute it must have at least a name");
|
140
|
+
|
141
|
+
id<KcContext.RegisterUserProfile>(kcContext).profile.attributes.push(partialAttribute as any);
|
142
|
+
id<KcContext.RegisterUserProfile>(kcContext).profile.attributesByName[name] = partialAttribute as any;
|
143
|
+
});
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
return { kcContext };
|
148
|
+
}
|
149
|
+
|
150
|
+
if (realKcContext === undefined) {
|
151
|
+
return { "kcContext": undefined as any };
|
152
|
+
}
|
153
|
+
|
154
|
+
if (id<readonly string[]>(loginThemePageIds).indexOf(realKcContext.pageId) < 0 && !("login" in realKcContext)) {
|
155
|
+
return { "kcContext": undefined as any };
|
156
|
+
}
|
157
|
+
|
158
|
+
{
|
159
|
+
const { url } = realKcContext;
|
160
|
+
|
161
|
+
url.resourcesCommonPath = pathJoin(url.resourcesPath, pathBasename(mockTestingResourcesCommonPath));
|
162
|
+
}
|
163
|
+
|
164
|
+
return { "kcContext": realKcContext as any };
|
165
|
+
}
|
166
|
+
|
167
|
+
return { getKcContext };
|
168
|
+
}
|
@@ -1,136 +1,19 @@
|
|
1
|
-
import type { KcContext, Attribute } from "./KcContext";
|
2
|
-
import { kcContextMocks, kcContextCommonMock } from "./kcContextMocks";
|
3
1
|
import type { DeepPartial } from "keycloakify/tools/DeepPartial";
|
4
|
-
import { deepAssign } from "keycloakify/tools/deepAssign";
|
5
|
-
import { id } from "tsafe/id";
|
6
|
-
import { exclude } from "tsafe/exclude";
|
7
|
-
import { assert } from "tsafe/assert";
|
8
2
|
import type { ExtendKcContext } from "./getKcContextFromWindow";
|
9
|
-
import {
|
10
|
-
import { pathJoin } from "keycloakify/bin/tools/pathJoin";
|
11
|
-
import { pathBasename } from "keycloakify/tools/pathBasename";
|
12
|
-
import { mockTestingResourcesCommonPath } from "keycloakify/bin/mockTestingResourcesPath";
|
13
|
-
import { symToStr } from "tsafe/symToStr";
|
14
|
-
import { loginThemePageIds } from "keycloakify/bin/keycloakify/generateFtl/pageId";
|
3
|
+
import { createGetKcContext } from "./createGetKcContext";
|
15
4
|
|
5
|
+
/** @deprecated: Use createGetKcContext instead */
|
16
6
|
export function getKcContext<KcContextExtension extends { pageId: string } = never>(params?: {
|
17
7
|
mockPageId?: ExtendKcContext<KcContextExtension>["pageId"];
|
18
8
|
mockData?: readonly DeepPartial<ExtendKcContext<KcContextExtension>>[];
|
19
9
|
}): { kcContext: ExtendKcContext<KcContextExtension> | undefined } {
|
20
10
|
const { mockPageId, mockData } = params ?? {};
|
21
11
|
|
22
|
-
const
|
12
|
+
const { getKcContext } = createGetKcContext<KcContextExtension>({
|
13
|
+
mockData
|
14
|
+
});
|
23
15
|
|
24
|
-
|
25
|
-
//TODO maybe trow if no mock fo custom page
|
16
|
+
const { kcContext } = getKcContext({ mockPageId });
|
26
17
|
|
27
|
-
|
28
|
-
[
|
29
|
-
`%cKeycloakify: ${symToStr({ mockPageId })} set to ${mockPageId}.`,
|
30
|
-
`If assets are missing make sure you have built your Keycloak theme at least once.`
|
31
|
-
].join(" "),
|
32
|
-
"background: red; color: yellow; font-size: medium"
|
33
|
-
);
|
34
|
-
|
35
|
-
const kcContextDefaultMock = kcContextMocks.find(({ pageId }) => pageId === mockPageId);
|
36
|
-
|
37
|
-
const partialKcContextCustomMock = mockData?.find(({ pageId }) => pageId === mockPageId);
|
38
|
-
|
39
|
-
if (kcContextDefaultMock === undefined && partialKcContextCustomMock === undefined) {
|
40
|
-
console.warn(
|
41
|
-
[
|
42
|
-
`WARNING: You declared the non build in page ${mockPageId} but you didn't `,
|
43
|
-
`provide mock data needed to debug the page outside of Keycloak as you are trying to do now.`,
|
44
|
-
`Please check the documentation of the getKcContext function`
|
45
|
-
].join("\n")
|
46
|
-
);
|
47
|
-
}
|
48
|
-
|
49
|
-
const kcContext: any = {};
|
50
|
-
|
51
|
-
deepAssign({
|
52
|
-
"target": kcContext,
|
53
|
-
"source": kcContextDefaultMock !== undefined ? kcContextDefaultMock : { "pageId": mockPageId, ...kcContextCommonMock }
|
54
|
-
});
|
55
|
-
|
56
|
-
if (partialKcContextCustomMock !== undefined) {
|
57
|
-
deepAssign({
|
58
|
-
"target": kcContext,
|
59
|
-
"source": partialKcContextCustomMock
|
60
|
-
});
|
61
|
-
|
62
|
-
if (
|
63
|
-
partialKcContextCustomMock.pageId === "register-user-profile.ftl" ||
|
64
|
-
partialKcContextCustomMock.pageId === "update-user-profile.ftl" ||
|
65
|
-
partialKcContextCustomMock.pageId === "idp-review-user-profile.ftl"
|
66
|
-
) {
|
67
|
-
assert(
|
68
|
-
kcContextDefaultMock?.pageId === "register-user-profile.ftl" ||
|
69
|
-
kcContextDefaultMock?.pageId === "update-user-profile.ftl" ||
|
70
|
-
kcContextDefaultMock?.pageId === "idp-review-user-profile.ftl"
|
71
|
-
);
|
72
|
-
|
73
|
-
const { attributes } = kcContextDefaultMock.profile;
|
74
|
-
|
75
|
-
id<KcContext.RegisterUserProfile>(kcContext).profile.attributes = [];
|
76
|
-
id<KcContext.RegisterUserProfile>(kcContext).profile.attributesByName = {};
|
77
|
-
|
78
|
-
const partialAttributes = [
|
79
|
-
...((partialKcContextCustomMock as DeepPartial<KcContext.RegisterUserProfile>).profile?.attributes ?? [])
|
80
|
-
].filter(exclude(undefined));
|
81
|
-
|
82
|
-
attributes.forEach(attribute => {
|
83
|
-
const partialAttribute = partialAttributes.find(({ name }) => name === attribute.name);
|
84
|
-
|
85
|
-
const augmentedAttribute: Attribute = {} as any;
|
86
|
-
|
87
|
-
deepAssign({
|
88
|
-
"target": augmentedAttribute,
|
89
|
-
"source": attribute
|
90
|
-
});
|
91
|
-
|
92
|
-
if (partialAttribute !== undefined) {
|
93
|
-
partialAttributes.splice(partialAttributes.indexOf(partialAttribute), 1);
|
94
|
-
|
95
|
-
deepAssign({
|
96
|
-
"target": augmentedAttribute,
|
97
|
-
"source": partialAttribute
|
98
|
-
});
|
99
|
-
}
|
100
|
-
|
101
|
-
id<KcContext.RegisterUserProfile>(kcContext).profile.attributes.push(augmentedAttribute);
|
102
|
-
id<KcContext.RegisterUserProfile>(kcContext).profile.attributesByName[augmentedAttribute.name] = augmentedAttribute;
|
103
|
-
});
|
104
|
-
|
105
|
-
partialAttributes
|
106
|
-
.map(partialAttribute => ({ "validators": {}, ...partialAttribute }))
|
107
|
-
.forEach(partialAttribute => {
|
108
|
-
const { name } = partialAttribute;
|
109
|
-
|
110
|
-
assert(name !== undefined, "If you define a mock attribute it must have at least a name");
|
111
|
-
|
112
|
-
id<KcContext.RegisterUserProfile>(kcContext).profile.attributes.push(partialAttribute as any);
|
113
|
-
id<KcContext.RegisterUserProfile>(kcContext).profile.attributesByName[name] = partialAttribute as any;
|
114
|
-
});
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
return { kcContext };
|
119
|
-
}
|
120
|
-
|
121
|
-
if (realKcContext === undefined) {
|
122
|
-
return { "kcContext": undefined };
|
123
|
-
}
|
124
|
-
|
125
|
-
if (id<readonly string[]>(loginThemePageIds).indexOf(realKcContext.pageId) < 0 && !("login" in realKcContext)) {
|
126
|
-
return { "kcContext": undefined };
|
127
|
-
}
|
128
|
-
|
129
|
-
{
|
130
|
-
const { url } = realKcContext;
|
131
|
-
|
132
|
-
url.resourcesCommonPath = pathJoin(url.resourcesPath, pathBasename(mockTestingResourcesCommonPath));
|
133
|
-
}
|
134
|
-
|
135
|
-
return { "kcContext": realKcContext };
|
18
|
+
return { kcContext };
|
136
19
|
}
|