@valbuild/server 0.16.2 → 0.16.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.
@@ -1,3 +1,9 @@
1
- export declare function decodeJwt(token: string, secretKey?: string): unknown | null;
1
+ export type JwtPayload = {
2
+ sub: string;
3
+ exp: number;
4
+ org: string;
5
+ project: string;
6
+ };
7
+ export declare function decodeJwt(token: string, secretKey?: string): JwtPayload | null;
2
8
  export declare function getExpire(): number;
3
9
  export declare function encodeJwt(payload: object, sessionKey: string): string;
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "./package.json": "./package.json"
13
13
  },
14
14
  "types": "dist/valbuild-server.cjs.d.ts",
15
- "version": "0.16.2",
15
+ "version": "0.16.3",
16
16
  "scripts": {
17
17
  "typecheck": "tsc --noEmit",
18
18
  "test": "jest",
package/src/jwt.ts CHANGED
@@ -1,7 +1,17 @@
1
1
  import crypto from "crypto";
2
2
  import { z } from "zod";
3
3
 
4
- export function decodeJwt(token: string, secretKey?: string): unknown | null {
4
+ export type JwtPayload = {
5
+ sub: string;
6
+ exp: number;
7
+ org: string;
8
+ project: string;
9
+ };
10
+
11
+ export function decodeJwt(
12
+ token: string,
13
+ secretKey?: string
14
+ ): JwtPayload | null {
5
15
  const [headerBase64, payloadBase64, signatureBase64, ...rest] =
6
16
  token.split(".");
7
17
  if (!headerBase64 || !payloadBase64 || !signatureBase64 || rest.length > 0) {
@@ -47,7 +57,7 @@ export function decodeJwt(token: string, secretKey?: string): unknown | null {
47
57
  try {
48
58
  const parsedPayload = JSON.parse(
49
59
  Buffer.from(payloadBase64, "base64").toString("utf8")
50
- ) as unknown;
60
+ ) as JwtPayload;
51
61
  return parsedPayload;
52
62
  } catch (err) {
53
63
  console.debug("Invalid JWT: could not parse payload", err);