@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.
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/jwt.d.ts +9 -0
- package/dist/valbuild-server.cjs.dev.js +3 -0
- package/dist/valbuild-server.cjs.prod.js +3 -0
- package/dist/valbuild-server.esm.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/jwt.ts +12 -2
|
@@ -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
package/src/index.ts
CHANGED
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
|
|
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
|
|
60
|
+
) as JwtPayload;
|
|
51
61
|
return parsedPayload;
|
|
52
62
|
} catch (err) {
|
|
53
63
|
console.debug("Invalid JWT: could not parse payload", err);
|