keycloakify 6.1.0 → 6.3.2

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.
Files changed (48) hide show
  1. package/bin/keycloakify/generateFtl/generateFtl.d.ts +1 -1
  2. package/bin/keycloakify/generateFtl/generateFtl.js +3 -1
  3. package/bin/keycloakify/generateFtl/generateFtl.js.map +1 -1
  4. package/bin/tsconfig.tsbuildinfo +1 -1
  5. package/lib/components/IdpReviewUserProfile.d.ts +9 -0
  6. package/lib/components/IdpReviewUserProfile.js +31 -0
  7. package/lib/components/IdpReviewUserProfile.js.map +1 -0
  8. package/lib/components/KcApp.js +6 -0
  9. package/lib/components/KcApp.js.map +1 -1
  10. package/lib/components/RegisterUserProfile.js +2 -61
  11. package/lib/components/RegisterUserProfile.js.map +1 -1
  12. package/lib/components/Terms.js +2 -1
  13. package/lib/components/Terms.js.map +1 -1
  14. package/lib/components/UpdateUserProfile.d.ts +9 -0
  15. package/lib/components/UpdateUserProfile.js +32 -0
  16. package/lib/components/UpdateUserProfile.js.map +1 -0
  17. package/lib/components/shared/UserProfileCommons.d.ts +16 -0
  18. package/lib/components/shared/UserProfileCommons.js +76 -0
  19. package/lib/components/shared/UserProfileCommons.js.map +1 -0
  20. package/lib/getKcContext/KcContextBase.d.ts +16 -1
  21. package/lib/getKcContext/KcContextBase.js.map +1 -1
  22. package/lib/getKcContext/getKcContext.js +6 -3
  23. package/lib/getKcContext/getKcContext.js.map +1 -1
  24. package/lib/getKcContext/kcContextMocks/kcContextMocks.js +107 -98
  25. package/lib/getKcContext/kcContextMocks/kcContextMocks.js.map +1 -1
  26. package/lib/i18n/index.js +2 -2
  27. package/lib/i18n/index.js.map +1 -1
  28. package/lib/tools/Markdown.d.ts +2 -0
  29. package/lib/tools/Markdown.js +3 -0
  30. package/lib/tools/Markdown.js.map +1 -0
  31. package/lib/tsconfig.tsbuildinfo +1 -1
  32. package/lib/useFormValidationSlice.d.ts +5 -1
  33. package/lib/useFormValidationSlice.js +4 -0
  34. package/lib/useFormValidationSlice.js.map +1 -1
  35. package/package.json +17 -1
  36. package/src/bin/keycloakify/generateFtl/generateFtl.ts +3 -1
  37. package/src/lib/components/IdpReviewUserProfile.tsx +46 -0
  38. package/src/lib/components/KcApp.tsx +6 -0
  39. package/src/lib/components/RegisterUserProfile.tsx +3 -156
  40. package/src/lib/components/Terms.tsx +2 -1
  41. package/src/lib/components/UpdateUserProfile.tsx +71 -0
  42. package/src/lib/components/shared/UserProfileCommons.tsx +170 -0
  43. package/src/lib/getKcContext/KcContextBase.ts +20 -1
  44. package/src/lib/getKcContext/getKcContext.ts +10 -4
  45. package/src/lib/getKcContext/kcContextMocks/kcContextMocks.ts +113 -98
  46. package/src/lib/i18n/index.tsx +3 -3
  47. package/src/lib/tools/Markdown.ts +3 -0
  48. package/src/lib/useFormValidationSlice.tsx +5 -1
@@ -25,7 +25,9 @@ export type KcContextBase =
25
25
  | KcContextBase.LoginIdpLinkEmail
26
26
  | KcContextBase.LoginPageExpired
27
27
  | KcContextBase.LoginConfigTotp
28
- | KcContextBase.LogoutConfirm;
28
+ | KcContextBase.LogoutConfirm
29
+ | KcContextBase.UpdateUserProfile
30
+ | KcContextBase.IdpReviewUserProfile;
29
31
 
30
32
  export declare namespace KcContextBase {
31
33
  export type Common = {
@@ -270,6 +272,23 @@ export declare namespace KcContextBase {
270
272
  skipLink?: boolean;
271
273
  };
272
274
  };
275
+
276
+ export type UpdateUserProfile = Common & {
277
+ pageId: "update-user-profile.ftl";
278
+ profile: {
279
+ attributes: Attribute[];
280
+ attributesByName: Record<string, Attribute>;
281
+ };
282
+ };
283
+
284
+ export type IdpReviewUserProfile = Common & {
285
+ pageId: "idp-review-user-profile.ftl";
286
+ profile: {
287
+ context: "IDP_REVIEW";
288
+ attributes: Attribute[];
289
+ attributesByName: Record<string, Attribute>;
290
+ };
291
+ };
273
292
  }
274
293
 
275
294
  export type Attribute = {
@@ -47,8 +47,16 @@ export function getKcContext<KcContextExtended extends { pageId: string } = neve
47
47
  "source": partialKcContextCustomMock
48
48
  });
49
49
 
50
- if (partialKcContextCustomMock.pageId === "register-user-profile.ftl") {
51
- assert(kcContextDefaultMock?.pageId === "register-user-profile.ftl");
50
+ if (
51
+ partialKcContextCustomMock.pageId === "register-user-profile.ftl" ||
52
+ partialKcContextCustomMock.pageId === "update-user-profile.ftl" ||
53
+ partialKcContextCustomMock.pageId === "idp-review-user-profile.ftl"
54
+ ) {
55
+ assert(
56
+ kcContextDefaultMock?.pageId === "register-user-profile.ftl" ||
57
+ kcContextDefaultMock?.pageId === "update-user-profile.ftl" ||
58
+ kcContextDefaultMock?.pageId === "idp-review-user-profile.ftl"
59
+ );
52
60
 
53
61
  const { attributes } = kcContextDefaultMock.profile;
54
62
 
@@ -60,8 +68,6 @@ export function getKcContext<KcContextExtended extends { pageId: string } = neve
60
68
  ].filter(exclude(undefined));
61
69
 
62
70
  attributes.forEach(attribute => {
63
- console.log("====>", attribute);
64
-
65
71
  const partialAttribute = partialAttributes.find(({ name }) => name === attribute.name);
66
72
 
67
73
  const augmentedAttribute: Attribute = {} as any;
@@ -7,6 +7,100 @@ import { pathJoin } from "../../../bin/tools/pathJoin";
7
7
 
8
8
  const PUBLIC_URL = process.env["PUBLIC_URL"] ?? "/";
9
9
 
10
+ const attributes: Attribute[] = [
11
+ {
12
+ "validators": {
13
+ "username-prohibited-characters": {
14
+ "ignore.empty.value": true
15
+ },
16
+ "up-username-has-value": {},
17
+ "length": {
18
+ "ignore.empty.value": true,
19
+ "min": "3",
20
+ "max": "255"
21
+ },
22
+ "up-duplicate-username": {},
23
+ "up-username-mutation": {}
24
+ },
25
+ "displayName": "${username}",
26
+ "annotations": {},
27
+ "required": true,
28
+ "groupAnnotations": {},
29
+ "autocomplete": "username",
30
+ "readOnly": false,
31
+ "name": "username",
32
+ "value": "xxxx"
33
+ },
34
+ {
35
+ "validators": {
36
+ "up-email-exists-as-username": {},
37
+ "length": {
38
+ "max": "255",
39
+ "ignore.empty.value": true
40
+ },
41
+ "up-blank-attribute-value": {
42
+ "error-message": "missingEmailMessage",
43
+ "fail-on-null": false
44
+ },
45
+ "up-duplicate-email": {},
46
+ "email": {
47
+ "ignore.empty.value": true
48
+ },
49
+ "pattern": {
50
+ "ignore.empty.value": true,
51
+ "pattern": "gmail\\.com$"
52
+ }
53
+ },
54
+ "displayName": "${email}",
55
+ "annotations": {},
56
+ "required": true,
57
+ "groupAnnotations": {},
58
+ "autocomplete": "email",
59
+ "readOnly": false,
60
+ "name": "email"
61
+ },
62
+ {
63
+ "validators": {
64
+ "length": {
65
+ "max": "255",
66
+ "ignore.empty.value": true
67
+ },
68
+ "person-name-prohibited-characters": {
69
+ "ignore.empty.value": true
70
+ },
71
+ "up-immutable-attribute": {},
72
+ "up-attribute-required-by-metadata-value": {}
73
+ },
74
+ "displayName": "${firstName}",
75
+ "annotations": {},
76
+ "required": true,
77
+ "groupAnnotations": {},
78
+ "readOnly": false,
79
+ "name": "firstName"
80
+ },
81
+ {
82
+ "validators": {
83
+ "length": {
84
+ "max": "255",
85
+ "ignore.empty.value": true
86
+ },
87
+ "person-name-prohibited-characters": {
88
+ "ignore.empty.value": true
89
+ },
90
+ "up-immutable-attribute": {},
91
+ "up-attribute-required-by-metadata-value": {}
92
+ },
93
+ "displayName": "${lastName}",
94
+ "annotations": {},
95
+ "required": true,
96
+ "groupAnnotations": {},
97
+ "readOnly": false,
98
+ "name": "lastName"
99
+ }
100
+ ];
101
+
102
+ const attributesByName = Object.fromEntries(attributes.map(attribute => [attribute.name, attribute])) as any;
103
+
10
104
  export const kcContextCommonMock: KcContextBase.Common = {
11
105
  "url": {
12
106
  "loginAction": "#",
@@ -200,104 +294,8 @@ export const kcContextMocks: KcContextBase[] = [
200
294
  ...registerCommon,
201
295
  "profile": {
202
296
  "context": "REGISTRATION_PROFILE" as const,
203
- ...(() => {
204
- const attributes: Attribute[] = [
205
- {
206
- "validators": {
207
- "username-prohibited-characters": {
208
- "ignore.empty.value": true
209
- },
210
- "up-username-has-value": {},
211
- "length": {
212
- "ignore.empty.value": true,
213
- "min": "3",
214
- "max": "255"
215
- },
216
- "up-duplicate-username": {},
217
- "up-username-mutation": {}
218
- },
219
- "displayName": "${username}",
220
- "annotations": {},
221
- "required": true,
222
- "groupAnnotations": {},
223
- "autocomplete": "username",
224
- "readOnly": false,
225
- "name": "username",
226
- "value": "xxxx"
227
- },
228
- {
229
- "validators": {
230
- "up-email-exists-as-username": {},
231
- "length": {
232
- "max": "255",
233
- "ignore.empty.value": true
234
- },
235
- "up-blank-attribute-value": {
236
- "error-message": "missingEmailMessage",
237
- "fail-on-null": false
238
- },
239
- "up-duplicate-email": {},
240
- "email": {
241
- "ignore.empty.value": true
242
- },
243
- "pattern": {
244
- "ignore.empty.value": true,
245
- "pattern": "gmail\\.com$"
246
- }
247
- },
248
- "displayName": "${email}",
249
- "annotations": {},
250
- "required": true,
251
- "groupAnnotations": {},
252
- "autocomplete": "email",
253
- "readOnly": false,
254
- "name": "email"
255
- },
256
- {
257
- "validators": {
258
- "length": {
259
- "max": "255",
260
- "ignore.empty.value": true
261
- },
262
- "person-name-prohibited-characters": {
263
- "ignore.empty.value": true
264
- },
265
- "up-immutable-attribute": {},
266
- "up-attribute-required-by-metadata-value": {}
267
- },
268
- "displayName": "${firstName}",
269
- "annotations": {},
270
- "required": true,
271
- "groupAnnotations": {},
272
- "readOnly": false,
273
- "name": "firstName"
274
- },
275
- {
276
- "validators": {
277
- "length": {
278
- "max": "255",
279
- "ignore.empty.value": true
280
- },
281
- "person-name-prohibited-characters": {
282
- "ignore.empty.value": true
283
- },
284
- "up-immutable-attribute": {},
285
- "up-attribute-required-by-metadata-value": {}
286
- },
287
- "displayName": "${lastName}",
288
- "annotations": {},
289
- "required": true,
290
- "groupAnnotations": {},
291
- "readOnly": false,
292
- "name": "lastName"
293
- }
294
- ];
295
-
296
- return {
297
- attributes,
298
- "attributesByName": Object.fromEntries(attributes.map(attribute => [attribute.name, attribute])) as any
299
- } as any;
300
- })()
297
+ attributes,
298
+ attributesByName
301
299
  }
302
300
  })
303
301
  ];
@@ -423,5 +421,22 @@ export const kcContextMocks: KcContextBase[] = [
423
421
  "baseUrl": "#"
424
422
  },
425
423
  "logoutConfirm": { "code": "123", skipLink: false }
424
+ }),
425
+ id<KcContextBase.UpdateUserProfile>({
426
+ ...kcContextCommonMock,
427
+ "pageId": "update-user-profile.ftl",
428
+ "profile": {
429
+ attributes,
430
+ attributesByName
431
+ }
432
+ }),
433
+ id<KcContextBase.IdpReviewUserProfile>({
434
+ ...kcContextCommonMock,
435
+ "pageId": "idp-review-user-profile.ftl",
436
+ "profile": {
437
+ context: "IDP_REVIEW",
438
+ attributes,
439
+ attributesByName
440
+ }
426
441
  })
427
442
  ];
@@ -1,10 +1,10 @@
1
1
  import "minimal-polyfills/Object.fromEntries";
2
2
  //NOTE for later: https://github.com/remarkjs/react-markdown/blob/236182ecf30bd89c1e5a7652acaf8d0bf81e6170/src/renderers.js#L7-L35
3
3
  import React, { useEffect, useState, useRef } from "react";
4
- import ReactMarkdown from "react-markdown";
5
4
  import type baseMessages from "./generated_messages/18.0.1/login/en";
6
5
  import { assert } from "tsafe/assert";
7
6
  import type { KcContextBase } from "../getKcContext/KcContextBase";
7
+ import { Markdown } from "../tools/Markdown";
8
8
 
9
9
  export const fallbackLanguageTag = "en";
10
10
 
@@ -234,9 +234,9 @@ function createI18nTranslationFunctions<MessageKey extends string>(params: {
234
234
  })();
235
235
 
236
236
  return doRenderMarkdown ? (
237
- <ReactMarkdown allowDangerousHtml renderers={key === "termsText" ? undefined : { "paragraph": "span" }}>
237
+ <Markdown allowDangerousHtml renderers={{ "paragraph": "span" }}>
238
238
  {messageWithArgsInjectedIfAny}
239
- </ReactMarkdown>
239
+ </Markdown>
240
240
  ) : (
241
241
  messageWithArgsInjectedIfAny
242
242
  );
@@ -0,0 +1,3 @@
1
+ import Markdown from "react-markdown";
2
+
3
+ export { Markdown };
@@ -304,13 +304,17 @@ export function useGetErrors(params: {
304
304
  return { getErrors };
305
305
  }
306
306
 
307
+ /**
308
+ * NOTE: The attributesWithPassword returned is actually augmented with
309
+ * artificial password related attributes only if kcContext.passwordRequired === true
310
+ */
307
311
  export function useFormValidationSlice(params: {
308
312
  kcContext: {
309
313
  messagesPerField: Pick<KcContextBase.Common["messagesPerField"], "existsError" | "get">;
310
314
  profile: {
311
315
  attributes: Attribute[];
312
316
  };
313
- passwordRequired: boolean;
317
+ passwordRequired?: boolean;
314
318
  realm: { registrationEmailAsUsername: boolean };
315
319
  };
316
320
  /** NOTE: Try to avoid passing a new ref every render for better performances. */