@ateam-ai-mobile/core 0.1.8 → 0.1.10
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/index.d.mts +14 -5
- package/dist/index.d.ts +14 -5
- package/dist/index.js +23 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/authSession.ts +1 -20
- package/src/config.ts +14 -4
- package/src/index.ts +1 -0
- package/src/jwt.ts +29 -0
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
// src/jwt.ts
|
|
2
|
+
function decodeJwtPayload(token) {
|
|
3
|
+
try {
|
|
4
|
+
const segs = token.split(".");
|
|
5
|
+
if (segs.length !== 3) return null;
|
|
6
|
+
const b64 = segs[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
7
|
+
const padded = b64 + "=".repeat((4 - b64.length % 4) % 4);
|
|
8
|
+
const json = typeof atob === "function" ? atob(padded) : Buffer.from(padded, "base64").toString("utf8");
|
|
9
|
+
return JSON.parse(json);
|
|
10
|
+
} catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function tenantFromToken(token) {
|
|
15
|
+
if (!token) return null;
|
|
16
|
+
const t = decodeJwtPayload(token)?.tenant;
|
|
17
|
+
return typeof t === "string" && t ? t : null;
|
|
18
|
+
}
|
|
19
|
+
|
|
1
20
|
// src/config.ts
|
|
2
21
|
var _config = null;
|
|
3
22
|
function initAdas(config) {
|
|
@@ -32,6 +51,8 @@ function getConsumerAuthApiUrl() {
|
|
|
32
51
|
return resolveUrl(url);
|
|
33
52
|
}
|
|
34
53
|
function getTenant() {
|
|
54
|
+
const token = getConfig().tokenProvider.getToken();
|
|
55
|
+
if (token) return tenantFromToken(token) || "";
|
|
35
56
|
const t = getConfig().tenant;
|
|
36
57
|
return (typeof t === "function" ? t() : t) || "";
|
|
37
58
|
}
|
|
@@ -207,18 +228,6 @@ function getSession() {
|
|
|
207
228
|
}
|
|
208
229
|
|
|
209
230
|
// src/authSession.ts
|
|
210
|
-
function decodeJwtPayload(token) {
|
|
211
|
-
try {
|
|
212
|
-
const segs = token.split(".");
|
|
213
|
-
if (segs.length !== 3) return null;
|
|
214
|
-
const b64 = segs[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
215
|
-
const padded = b64 + "=".repeat((4 - b64.length % 4) % 4);
|
|
216
|
-
const json = typeof atob === "function" ? atob(padded) : Buffer.from(padded, "base64").toString("utf8");
|
|
217
|
-
return JSON.parse(json);
|
|
218
|
-
} catch {
|
|
219
|
-
return null;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
231
|
function userFromJwt(token) {
|
|
223
232
|
const claims = decodeJwtPayload(token);
|
|
224
233
|
if (!claims?.sub) return null;
|
|
@@ -2142,6 +2151,7 @@ export {
|
|
|
2142
2151
|
signInWithGoogle,
|
|
2143
2152
|
spacing,
|
|
2144
2153
|
switchTenant,
|
|
2154
|
+
tenantFromToken,
|
|
2145
2155
|
unwrapMcpResult,
|
|
2146
2156
|
useCapability,
|
|
2147
2157
|
useChatStore,
|