@multiplatform.one/keycloak 6.4.2 → 6.6.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.
- package/dist/cjs/index.cjs +14 -0
- package/dist/esm/index.js +14 -0
- package/package.json +9 -9
- package/types/frappeToken.d.ts +10 -2
- package/types/frappeToken.d.ts.map +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -897,9 +897,20 @@ function KeycloakProvider({
|
|
|
897
897
|
|
|
898
898
|
// src/frappeToken.ts
|
|
899
899
|
var cached;
|
|
900
|
+
var pending;
|
|
901
|
+
var signedOutUntil = 0;
|
|
902
|
+
var SIGNED_OUT_COOLDOWN_MS = 15e3;
|
|
900
903
|
async function getKeycloakBearerToken() {
|
|
901
904
|
if (typeof window === "undefined") return void 0;
|
|
902
905
|
if (cached && cached.expiresAt - 6e4 > Date.now()) return cached.token;
|
|
906
|
+
if (Date.now() < signedOutUntil) return void 0;
|
|
907
|
+
if (pending) return pending;
|
|
908
|
+
pending = fetchToken().finally(() => {
|
|
909
|
+
pending = void 0;
|
|
910
|
+
});
|
|
911
|
+
return pending;
|
|
912
|
+
}
|
|
913
|
+
async function fetchToken() {
|
|
903
914
|
try {
|
|
904
915
|
const res = await fetch(`${window.location.origin}/api/auth/get-access-token`, {
|
|
905
916
|
method: "POST",
|
|
@@ -909,11 +920,13 @@ async function getKeycloakBearerToken() {
|
|
|
909
920
|
});
|
|
910
921
|
if (!res.ok) {
|
|
911
922
|
cached = void 0;
|
|
923
|
+
signedOutUntil = Date.now() + SIGNED_OUT_COOLDOWN_MS;
|
|
912
924
|
return void 0;
|
|
913
925
|
}
|
|
914
926
|
const data = await res.json().catch(() => null);
|
|
915
927
|
if (!data?.accessToken) {
|
|
916
928
|
cached = void 0;
|
|
929
|
+
signedOutUntil = Date.now() + SIGNED_OUT_COOLDOWN_MS;
|
|
917
930
|
return void 0;
|
|
918
931
|
}
|
|
919
932
|
cached = {
|
|
@@ -923,6 +936,7 @@ async function getKeycloakBearerToken() {
|
|
|
923
936
|
return cached.token;
|
|
924
937
|
} catch {
|
|
925
938
|
cached = void 0;
|
|
939
|
+
signedOutUntil = Date.now() + SIGNED_OUT_COOLDOWN_MS;
|
|
926
940
|
return void 0;
|
|
927
941
|
}
|
|
928
942
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -840,9 +840,20 @@ function KeycloakProvider({
|
|
|
840
840
|
|
|
841
841
|
// src/frappeToken.ts
|
|
842
842
|
var cached;
|
|
843
|
+
var pending;
|
|
844
|
+
var signedOutUntil = 0;
|
|
845
|
+
var SIGNED_OUT_COOLDOWN_MS = 15e3;
|
|
843
846
|
async function getKeycloakBearerToken() {
|
|
844
847
|
if (typeof window === "undefined") return void 0;
|
|
845
848
|
if (cached && cached.expiresAt - 6e4 > Date.now()) return cached.token;
|
|
849
|
+
if (Date.now() < signedOutUntil) return void 0;
|
|
850
|
+
if (pending) return pending;
|
|
851
|
+
pending = fetchToken().finally(() => {
|
|
852
|
+
pending = void 0;
|
|
853
|
+
});
|
|
854
|
+
return pending;
|
|
855
|
+
}
|
|
856
|
+
async function fetchToken() {
|
|
846
857
|
try {
|
|
847
858
|
const res = await fetch(`${window.location.origin}/api/auth/get-access-token`, {
|
|
848
859
|
method: "POST",
|
|
@@ -852,11 +863,13 @@ async function getKeycloakBearerToken() {
|
|
|
852
863
|
});
|
|
853
864
|
if (!res.ok) {
|
|
854
865
|
cached = void 0;
|
|
866
|
+
signedOutUntil = Date.now() + SIGNED_OUT_COOLDOWN_MS;
|
|
855
867
|
return void 0;
|
|
856
868
|
}
|
|
857
869
|
const data = await res.json().catch(() => null);
|
|
858
870
|
if (!data?.accessToken) {
|
|
859
871
|
cached = void 0;
|
|
872
|
+
signedOutUntil = Date.now() + SIGNED_OUT_COOLDOWN_MS;
|
|
860
873
|
return void 0;
|
|
861
874
|
}
|
|
862
875
|
cached = {
|
|
@@ -866,6 +879,7 @@ async function getKeycloakBearerToken() {
|
|
|
866
879
|
return cached.token;
|
|
867
880
|
} catch {
|
|
868
881
|
cached = void 0;
|
|
882
|
+
signedOutUntil = Date.now() + SIGNED_OUT_COOLDOWN_MS;
|
|
869
883
|
return void 0;
|
|
870
884
|
}
|
|
871
885
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/keycloak",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.0",
|
|
4
4
|
"description": "keycloak client for multiplatform.one ecosystem",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auth",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"@better-auth/expo": "^1.6.9",
|
|
55
55
|
"better-auth": "^1.6.9",
|
|
56
56
|
"jwt-decode": "^4.0.0",
|
|
57
|
-
"@multiplatform.one/store": "6.
|
|
58
|
-
"@multiplatform.one/keycloak-js": "6.
|
|
57
|
+
"@multiplatform.one/store": "6.6.0",
|
|
58
|
+
"@multiplatform.one/keycloak-js": "6.6.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@tamagui/build": "2.0.0-rc.41",
|
|
@@ -70,15 +70,15 @@
|
|
|
70
70
|
"react": "19.2.5",
|
|
71
71
|
"typescript": "~5.9.3",
|
|
72
72
|
"vitest": "^4.1.5",
|
|
73
|
-
"@multiplatform.one/config": "6.
|
|
74
|
-
"@multiplatform.one/logger": "6.
|
|
75
|
-
"@multiplatform.one/platform": "6.
|
|
76
|
-
"@multiplatform.one/test-utils": "6.
|
|
73
|
+
"@multiplatform.one/config": "6.6.0",
|
|
74
|
+
"@multiplatform.one/logger": "6.6.0",
|
|
75
|
+
"@multiplatform.one/platform": "6.6.0",
|
|
76
|
+
"@multiplatform.one/test-utils": "6.6.0"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"react": "^19.1.0",
|
|
80
|
-
"@multiplatform.one/logger": "^6.
|
|
81
|
-
"@multiplatform.one/platform": "^6.
|
|
80
|
+
"@multiplatform.one/logger": "^6.6.0",
|
|
81
|
+
"@multiplatform.one/platform": "^6.6.0"
|
|
82
82
|
},
|
|
83
83
|
"optionalDependencies": {
|
|
84
84
|
"expo-linking": "^55.0.15",
|
package/types/frappeToken.d.ts
CHANGED
|
@@ -12,8 +12,16 @@
|
|
|
12
12
|
* and socket handshake — the same transport native uses. The bench's
|
|
13
13
|
* frappe_keycloak auth hook validates the JWT against the realm public key.
|
|
14
14
|
*/
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Returns a valid Keycloak access token, or undefined when signed out.
|
|
17
|
+
*
|
|
18
|
+
* Anonymous visitors get a single 401 per cooldown window instead of one per
|
|
19
|
+
* concurrent data request: parallel callers share the in-flight fetch, and a
|
|
20
|
+
* signed-out answer short-circuits further attempts for a few seconds. A real
|
|
21
|
+
* sign-in arrives via the OAuth redirect (full navigation), which resets this
|
|
22
|
+
* module state anyway.
|
|
23
|
+
*/
|
|
16
24
|
export declare function getKeycloakBearerToken(): Promise<string | undefined>;
|
|
17
|
-
/** Drop the cached token (sign-out). */
|
|
25
|
+
/** Drop the cached token (sign-out / fresh sign-in). */
|
|
18
26
|
export declare function clearKeycloakBearerToken(): void;
|
|
19
27
|
//# sourceMappingURL=frappeToken.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frappeToken.d.ts","sourceRoot":"","sources":["../src/frappeToken.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"frappeToken.d.ts","sourceRoot":"","sources":["../src/frappeToken.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAUH;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAU1E;AAuCD,wDAAwD;AACxD,wBAAgB,wBAAwB,SAIvC"}
|