keycloakify 7.6.7 → 7.6.9
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/account/pages/Password.js +1 -1
- package/account/pages/Password.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/account/pages/Password.tsx +2 -2
- 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
@@ -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
|
}
|