keycloakify 11.3.7 → 11.3.9-rc.0

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 (36) hide show
  1. package/README.md +1 -0
  2. package/bin/526.index.js +4 -4
  3. package/login/lib/getUserProfileApi/getUserProfileApi.d.ts +88 -0
  4. package/login/lib/getUserProfileApi/getUserProfileApi.js +1076 -0
  5. package/login/lib/getUserProfileApi/getUserProfileApi.js.map +1 -0
  6. package/login/lib/getUserProfileApi/index.d.ts +1 -0
  7. package/login/lib/getUserProfileApi/index.js +2 -0
  8. package/login/lib/getUserProfileApi/index.js.map +1 -0
  9. package/login/lib/getUserProfileApi/kcNumberUnFormat.d.ts +1 -0
  10. package/login/lib/getUserProfileApi/kcNumberUnFormat.js +84 -0
  11. package/login/lib/getUserProfileApi/kcNumberUnFormat.js.map +1 -0
  12. package/login/lib/useUserProfileForm.d.ts +9 -34
  13. package/login/lib/useUserProfileForm.js +44 -998
  14. package/login/lib/useUserProfileForm.js.map +1 -1
  15. package/login/pages/LoginPasskeysConditionalAuthenticate.useScript.js +7 -1
  16. package/login/pages/LoginPasskeysConditionalAuthenticate.useScript.js.map +1 -1
  17. package/login/pages/LoginRecoveryAuthnCodeConfig.useScript.js +7 -1
  18. package/login/pages/LoginRecoveryAuthnCodeConfig.useScript.js.map +1 -1
  19. package/login/pages/WebauthnAuthenticate.useScript.js +7 -1
  20. package/login/pages/WebauthnAuthenticate.useScript.js.map +1 -1
  21. package/login/pages/WebauthnRegister.useScript.js +7 -1
  22. package/login/pages/WebauthnRegister.useScript.js.map +1 -1
  23. package/package.json +17 -1
  24. package/src/bin/start-keycloak/start-keycloak.ts +4 -4
  25. package/src/login/lib/getUserProfileApi/getUserProfileApi.ts +1561 -0
  26. package/src/login/lib/getUserProfileApi/index.ts +1 -0
  27. package/src/login/lib/getUserProfileApi/kcNumberUnFormat.ts +109 -0
  28. package/src/login/lib/useUserProfileForm.tsx +82 -1322
  29. package/src/login/pages/LoginPasskeysConditionalAuthenticate.useScript.tsx +8 -1
  30. package/src/login/pages/LoginRecoveryAuthnCodeConfig.useScript.tsx +8 -1
  31. package/src/login/pages/WebauthnAuthenticate.useScript.tsx +8 -1
  32. package/src/login/pages/WebauthnRegister.useScript.tsx +8 -1
  33. package/src/tools/waitForElementMountedOnDom.ts +30 -0
  34. package/tools/waitForElementMountedOnDom.d.ts +3 -0
  35. package/tools/waitForElementMountedOnDom.js +21 -0
  36. package/tools/waitForElementMountedOnDom.js.map +1 -0
@@ -0,0 +1 @@
1
+ export * from "./getUserProfileApi";
@@ -0,0 +1,109 @@
1
+ import { assert } from "keycloakify/tools/assert";
2
+ let cleanup: (() => void) | undefined;
3
+ const handledElements = new WeakSet<HTMLElement>();
4
+ const KC_NUMBER_UNFORMAT = "kcNumberUnFormat";
5
+ const SELECTOR = `input[data-${KC_NUMBER_UNFORMAT}]`;
6
+
7
+ export function unFormatNumberOnSubmit() {
8
+ cleanup?.();
9
+
10
+ const handleElement = (element: HTMLInputElement) => {
11
+ if (handledElements.has(element)) {
12
+ return;
13
+ }
14
+
15
+ const form = element.closest("form");
16
+
17
+ if (form === null) {
18
+ return;
19
+ }
20
+
21
+ form.addEventListener("submit", () => {
22
+ const rawFormat = element.getAttribute(`data-${KC_NUMBER_UNFORMAT}`);
23
+ if (rawFormat) {
24
+ element.value = formatNumber(element.value, rawFormat);
25
+ }
26
+ });
27
+
28
+ handledElements.add(element);
29
+ };
30
+
31
+ document.querySelectorAll(SELECTOR).forEach(element => {
32
+ assert(element instanceof HTMLInputElement);
33
+ handleElement(element);
34
+ });
35
+
36
+ const observer = new MutationObserver(mutationsList => {
37
+ for (const mutation of mutationsList) {
38
+ if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
39
+ mutation.addedNodes.forEach(node => {
40
+ if (node.nodeType === Node.ELEMENT_NODE) {
41
+ const element = (node as HTMLElement).querySelector(SELECTOR);
42
+ if (element !== null) {
43
+ assert(element instanceof HTMLInputElement);
44
+ handleElement(element);
45
+ }
46
+ }
47
+ });
48
+ }
49
+ }
50
+ });
51
+
52
+ observer.observe(document.body, { childList: true, subtree: true });
53
+
54
+ cleanup = () => observer.disconnect();
55
+ }
56
+
57
+ // NOTE: Keycloak code
58
+ const formatNumber = (input: string, format: string) => {
59
+ if (!input) {
60
+ return "";
61
+ }
62
+
63
+ // array holding the patterns for the number of expected digits in each part
64
+ const digitPattern = format.match(/{\d+}/g);
65
+
66
+ if (!digitPattern) {
67
+ return "";
68
+ }
69
+
70
+ // calculate the maximum size of the given pattern based on the sum of the expected digits
71
+ const maxSize = digitPattern.reduce(
72
+ (total, p) => total + parseInt(p.replace("{", "").replace("}", "")),
73
+ 0
74
+ );
75
+
76
+ // keep only digits
77
+ let rawValue = input.replace(/\D+/g, "");
78
+
79
+ // make sure the value is a number
80
+ //@ts-expect-error
81
+ if (parseInt(rawValue) != rawValue) {
82
+ return "";
83
+ }
84
+
85
+ // make sure the number of digits does not exceed the maximum size
86
+ if (rawValue.length > maxSize) {
87
+ rawValue = rawValue.substring(0, maxSize);
88
+ }
89
+
90
+ // build the regex based based on the expected digits in each part
91
+ const formatter = digitPattern.reduce((result, p) => result + `(\\d${p})`, "^");
92
+
93
+ // if the current digits match the pattern we have each group of digits in an array
94
+ let digits = new RegExp(formatter).exec(rawValue);
95
+
96
+ // no match, return the raw value without any format
97
+ if (!digits) {
98
+ return input;
99
+ }
100
+
101
+ let result = format;
102
+
103
+ // finally format the current digits accordingly to the given format
104
+ for (let i = 0; i < digitPattern.length; i++) {
105
+ result = result.replace(digitPattern[i], digits[i + 1]);
106
+ }
107
+
108
+ return result;
109
+ };