@devvit/web-view-scripts 0.12.10-next-2026-01-22-22-08-59-4328e6a29.0 → 0.12.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/devvit-global.d.ts +2 -0
- package/devvit-global.d.ts.map +1 -1
- package/devvit-global.js +3 -0
- package/devvit.v1.js +2 -0
- package/meta.json +1 -1
- package/package.json +7 -7
- package/scripts/devvit.v1.min.js +1 -1
- package/scripts/devvit.v1.min.js.map +3 -3
- package/token.d.ts +1 -3
- package/token.d.ts.map +1 -1
- package/token.js +24 -0
package/token.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { RequestContext } from '@devvit/protos/json/devvit/platform/v1/request_context.js';
|
|
2
|
-
export type ContextClaims = {
|
|
3
|
-
devvit: RequestContext;
|
|
4
|
-
};
|
|
5
2
|
export declare function decodeToken(token: string | undefined): RequestContext | undefined;
|
|
3
|
+
export declare function initToken(): void;
|
|
6
4
|
//# sourceMappingURL=token.d.ts.map
|
package/token.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2DAA2D,CAAC;
|
|
1
|
+
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2DAA2D,CAAC;AAchG,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,CAQjF;AAED,wBAAgB,SAAS,IAAI,IAAI,CAEhC"}
|
package/token.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { EffectType } from '@devvit/protos/json/devvit/ui/effects/v1alpha/effect.js';
|
|
2
|
+
import { emitEffect } from '@devvit/shared-types/client/emit-effect.js';
|
|
1
3
|
import { jwtDecode } from 'jwt-decode';
|
|
4
|
+
import { updateToken } from './devvit-global.js';
|
|
2
5
|
export function decodeToken(token) {
|
|
3
6
|
if (!token)
|
|
4
7
|
return;
|
|
@@ -9,3 +12,24 @@ export function decodeToken(token) {
|
|
|
9
12
|
throw Error('token decode failure', { cause: err });
|
|
10
13
|
}
|
|
11
14
|
}
|
|
15
|
+
export function initToken() {
|
|
16
|
+
setInterval(refreshToken, 60000);
|
|
17
|
+
}
|
|
18
|
+
/** @internal */
|
|
19
|
+
export async function refreshToken() {
|
|
20
|
+
// Check if the token is about to expire in the next 5 minutes
|
|
21
|
+
const { exp: expiresAt } = jwtDecode(globalThis.devvit.token);
|
|
22
|
+
if (expiresAt && expiresAt - Date.now() / 1000 > 300) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Refresh the token
|
|
26
|
+
const response = await emitEffect({
|
|
27
|
+
type: EffectType.EFFECT_UPDATE_REQUEST_CONTEXT,
|
|
28
|
+
updateRequestContext: {},
|
|
29
|
+
});
|
|
30
|
+
if (!response?.updateRequestContext) {
|
|
31
|
+
console.error('Failed to refresh token');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
updateToken(response.updateRequestContext.signedRequestContext);
|
|
35
|
+
}
|