@valbuild/server 0.16.1 → 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.
@@ -13,3 +13,4 @@ export { formatSyntaxErrorTree } from "./patch/ts/syntax.js";
13
13
  export { LocalValServer } from "./LocalValServer.js";
14
14
  export { createFixPatch } from "./createFixPatch.js";
15
15
  export { PatchJSON } from "./patch/validation.js";
16
+ export * from "./jwt.js";
@@ -0,0 +1,9 @@
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;
8
+ export declare function getExpire(): number;
9
+ export declare function encodeJwt(payload: object, sessionKey: string): string;
@@ -1674,6 +1674,9 @@ exports.createFixPatch = createFixPatch;
1674
1674
  exports.createRequestHandler = createRequestHandler;
1675
1675
  exports.createRequestListener = createRequestListener;
1676
1676
  exports.createService = createService;
1677
+ exports.decodeJwt = decodeJwt;
1678
+ exports.encodeJwt = encodeJwt;
1677
1679
  exports.formatSyntaxErrorTree = formatSyntaxErrorTree;
1678
1680
  exports.getCompilerOptions = getCompilerOptions;
1681
+ exports.getExpire = getExpire;
1679
1682
  exports.patchSourceFile = patchSourceFile;
@@ -1674,6 +1674,9 @@ exports.createFixPatch = createFixPatch;
1674
1674
  exports.createRequestHandler = createRequestHandler;
1675
1675
  exports.createRequestListener = createRequestListener;
1676
1676
  exports.createService = createService;
1677
+ exports.decodeJwt = decodeJwt;
1678
+ exports.encodeJwt = encodeJwt;
1677
1679
  exports.formatSyntaxErrorTree = formatSyntaxErrorTree;
1678
1680
  exports.getCompilerOptions = getCompilerOptions;
1681
+ exports.getExpire = getExpire;
1679
1682
  exports.patchSourceFile = patchSourceFile;
@@ -1650,4 +1650,4 @@ const getSHA256Hash = async bits => {
1650
1650
  return hash;
1651
1651
  };
1652
1652
 
1653
- export { LocalValServer, PatchJSON, Service, ValFSHost, ValModuleLoader, ValSourceFileHandler, createFixPatch, createRequestHandler, createRequestListener, createService, formatSyntaxErrorTree, getCompilerOptions, patchSourceFile };
1653
+ export { LocalValServer, PatchJSON, Service, ValFSHost, ValModuleLoader, ValSourceFileHandler, createFixPatch, createRequestHandler, createRequestListener, createService, decodeJwt, encodeJwt, formatSyntaxErrorTree, getCompilerOptions, getExpire, patchSourceFile };
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.1",
15
+ "version": "0.16.3",
16
16
  "scripts": {
17
17
  "typecheck": "tsc --noEmit",
18
18
  "test": "jest",
package/src/index.ts CHANGED
@@ -13,3 +13,4 @@ export { formatSyntaxErrorTree } from "./patch/ts/syntax";
13
13
  export { LocalValServer } from "./LocalValServer";
14
14
  export { createFixPatch } from "./createFixPatch";
15
15
  export { PatchJSON } from "./patch/validation";
16
+ export * from "./jwt";
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);