@liuhlightning/jwt 0.1.2 → 0.2.0

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/index.d.ts CHANGED
@@ -284,18 +284,6 @@ export declare class JWT {
284
284
  * @returns The payload of the token
285
285
  */
286
286
  verify<T extends JWTPayload = JWTPayload>(input: string, options?: JWTVerifyOptions): T;
287
- /**
288
- * Parse the token
289
- * @param input The token to parse
290
- * @returns The header, payload, and signature of the token
291
- */
292
- static parse(input: string): [string, string, string];
293
- /**
294
- * Decode header or payload
295
- * @param input The input to decode
296
- * @returns The decoded input
297
- */
298
- static decode<T>(input: string): T;
299
287
  }
300
288
  export * from "./error";
301
289
  export default JWT;
package/dist/index.js CHANGED
@@ -19,6 +19,7 @@ const crypto_1 = require("crypto");
19
19
  const decode_1 = require("./decode");
20
20
  const encode_1 = require("./encode");
21
21
  const error_1 = require("./error");
22
+ const parse_1 = require("./parse");
22
23
  const time_1 = require("./time");
23
24
  /**
24
25
  * A class to create and verify JSON Web Tokens
@@ -85,15 +86,12 @@ class JWT {
85
86
  iat: this.issuedAt ?? options.issuedAt,
86
87
  jti: this.jwtID ?? options.jwtID,
87
88
  };
88
- if (rc.exp) {
89
+ if (rc.exp)
89
90
  rc.exp = (0, time_1.buildTime)(rc.exp);
90
- }
91
- if (rc.nbf) {
91
+ if (rc.nbf)
92
92
  rc.nbf = (0, time_1.buildTime)(rc.nbf);
93
- }
94
- if (rc.iat) {
93
+ if (rc.iat)
95
94
  rc.iat = (0, time_1.buildTime)(rc.iat);
96
- }
97
95
  return { ...rc, ...input };
98
96
  }
99
97
  /**
@@ -189,7 +187,7 @@ class JWT {
189
187
  * @returns The payload of the token
190
188
  */
191
189
  verify(input, options = {}) {
192
- const [header, payload, signature] = JWT.parse(input);
190
+ const [header, payload, signature] = (0, parse_1.parse)(input);
193
191
  // check header
194
192
  const h = (0, decode_1.decode)(header);
195
193
  this.checkHeader(h);
@@ -201,22 +199,6 @@ class JWT {
201
199
  this.checkSignature(signature, s1, h.alg);
202
200
  return p;
203
201
  }
204
- /**
205
- * Parse the token
206
- * @param input The token to parse
207
- * @returns The header, payload, and signature of the token
208
- */
209
- static parse(input) {
210
- return input.split(".", 3);
211
- }
212
- /**
213
- * Decode header or payload
214
- * @param input The input to decode
215
- * @returns The decoded input
216
- */
217
- static decode(input) {
218
- return (0, decode_1.decode)(input);
219
- }
220
202
  }
221
203
  exports.JWT = JWT;
222
204
  __exportStar(require("./error"), exports);
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Parse the token
3
+ * @param input The token to parse
4
+ * @returns The header, payload, and signature of the token
5
+ */
6
+ export declare function parse(input: string): [string, string, string];
7
+ //# sourceMappingURL=parse.d.ts.map
package/dist/parse.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parse = parse;
4
+ const error_1 = require("./error");
5
+ /**
6
+ * Parse the token
7
+ * @param input The token to parse
8
+ * @returns The header, payload, and signature of the token
9
+ */
10
+ function parse(input) {
11
+ const r = input.split(".", 3);
12
+ if (r.length !== 3)
13
+ throw new error_1.JWTError(`Token parts is not 3 ${input}`);
14
+ return r;
15
+ }
16
+ //# sourceMappingURL=parse.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liuhlightning/jwt",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "json web token in full typescript.",
5
5
  "keywords": [
6
6
  "jwt",
@@ -22,16 +22,16 @@
22
22
  "packageManager": "yarn@1.22.19",
23
23
  "scripts": {
24
24
  "build": "tsc -p tsconfig.build.json",
25
- "push": "yarn version --patch && git push",
25
+ "push": "yarn version --patch && git push && git push --tags",
26
26
  "test": "ts-node ./tests/index.test.ts"
27
27
  },
28
28
  "devDependencies": {
29
- "@types/node": "^20.2.3",
30
- "@typescript-eslint/eslint-plugin": "^5.59.7",
31
- "@typescript-eslint/parser": "^5.59.7",
32
- "eslint": "^8.41.0",
33
- "prettier": "^2.8.8",
34
- "ts-node": "^10.9.1",
35
- "typescript": "^5.0.4"
29
+ "@eslint/js": "^9.29.0",
30
+ "@types/node": "^22.13.14",
31
+ "eslint": "^9.29.0",
32
+ "prettier": "^3.5.3",
33
+ "ts-node": "^10.9.2",
34
+ "typescript": "^5.8.3",
35
+ "typescript-eslint": "^8.18.0"
36
36
  }
37
37
  }