@gram-ai/elements 1.27.1 → 1.27.3
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/elements.cjs +1 -1
- package/dist/elements.js +1 -1
- package/dist/hooks/useAuth.d.ts +3 -1
- package/dist/hooks/useSession.d.ts +1 -0
- package/dist/{index-oO5BAmPI.js → index-DBrhzauj.js} +6051 -5999
- package/dist/index-DBrhzauj.js.map +1 -0
- package/dist/{index-CP-wWZCV.cjs → index-DxfW52oA.cjs} +49 -49
- package/dist/index-DxfW52oA.cjs.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/lib/token.d.ts +12 -0
- package/dist/lib/token.test.d.ts +1 -0
- package/dist/{profiler-ECh1zoXF.js → profiler-D6ndqfsd.js} +2 -2
- package/dist/{profiler-ECh1zoXF.js.map → profiler-D6ndqfsd.js.map} +1 -1
- package/dist/{profiler-CEpc7O5Q.cjs → profiler-DhnzZ34c.cjs} +2 -2
- package/dist/{profiler-CEpc7O5Q.cjs.map → profiler-DhnzZ34c.cjs.map} +1 -1
- package/dist/{startRecording-CmZjjJoz.js → startRecording-B_9CRZ_P.js} +2 -2
- package/dist/{startRecording-CmZjjJoz.js.map → startRecording-B_9CRZ_P.js.map} +1 -1
- package/dist/{startRecording-qDCAu4Q0.cjs → startRecording-BwXmdmy1.cjs} +2 -2
- package/dist/{startRecording-qDCAu4Q0.cjs.map → startRecording-BwXmdmy1.cjs.map} +1 -1
- package/package.json +1 -1
- package/src/contexts/ElementsProvider.tsx +26 -7
- package/src/hooks/useAuth.ts +51 -3
- package/src/hooks/useMCPTools.ts +25 -14
- package/src/hooks/useSession.ts +7 -10
- package/src/index.ts +1 -0
- package/src/lib/token.test.ts +79 -0
- package/src/lib/token.ts +39 -0
- package/dist/index-CP-wWZCV.cjs.map +0 -1
- package/dist/index-oO5BAmPI.js.map +0 -1
package/src/lib/token.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the `exp` claim from a JWT token without verifying the signature.
|
|
3
|
+
* Returns the expiry as a Unix timestamp (seconds), or null if the token
|
|
4
|
+
* is not a valid JWT or has no `exp` claim.
|
|
5
|
+
*/
|
|
6
|
+
export function getTokenExpiry(token: string): number | null {
|
|
7
|
+
try {
|
|
8
|
+
const parts = token.split('.')
|
|
9
|
+
if (parts.length !== 3) return null
|
|
10
|
+
|
|
11
|
+
// base64url → base64 → decode
|
|
12
|
+
let payload = parts[1].replace(/-/g, '+').replace(/_/g, '/')
|
|
13
|
+
while (payload.length % 4) payload += '='
|
|
14
|
+
|
|
15
|
+
const json = atob(payload)
|
|
16
|
+
const parsed = JSON.parse(json)
|
|
17
|
+
|
|
18
|
+
if (typeof parsed.exp === 'number') {
|
|
19
|
+
return parsed.exp
|
|
20
|
+
}
|
|
21
|
+
return null
|
|
22
|
+
} catch {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns true when the token is expired or within `bufferMs` milliseconds
|
|
29
|
+
* of expiry. Fails open (returns false) for non-JWT tokens or tokens
|
|
30
|
+
* without an `exp` claim so they pass through unchanged.
|
|
31
|
+
*/
|
|
32
|
+
export function isTokenExpired(
|
|
33
|
+
token: string,
|
|
34
|
+
bufferMs: number = 30_000
|
|
35
|
+
): boolean {
|
|
36
|
+
const exp = getTokenExpiry(token)
|
|
37
|
+
if (exp === null) return false // fail-open for non-JWT tokens
|
|
38
|
+
return Date.now() >= exp * 1000 - bufferMs
|
|
39
|
+
}
|