@elysiajs/jwt 1.0.2 → 1.1.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/package.json CHANGED
@@ -1,56 +1,56 @@
1
1
  {
2
- "name": "@elysiajs/jwt",
3
- "description": "Plugin for Elysia for using JWT Authentication",
4
- "version": "1.0.2",
5
- "author": {
6
- "name": "saltyAom",
7
- "url": "https://github.com/SaltyAom",
8
- "email": "saltyaom@gmail.com"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "https://github.com/elysiajs/elysia-jwt"
13
- },
14
- "main": "./dist/index.js",
15
- "exports": {
16
- "bun": "./dist/index.js",
17
- "node": "./dist/cjs/index.js",
18
- "require": "./dist/cjs/index.js",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
21
- },
22
- "types": "./dist/index.d.ts",
23
- "bugs": "https://github.com/elysiajs/elysia-jwt/issues",
24
- "homepage": "https://github.com/elysiajs/elysia-jwt",
25
- "keywords": [
26
- "elysia",
27
- "jwt",
28
- "auth",
29
- "authentication"
30
- ],
31
- "license": "MIT",
32
- "scripts": {
33
- "dev": "bun run --hot example/index.ts",
34
- "test": "bun test && npm run test:node",
35
- "test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js",
36
- "build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
37
- "release": "npm run build && npm run test && npm publish --access public"
38
- },
39
- "dependencies": {
40
- "jose": "^4.14.4"
41
- },
42
- "devDependencies": {
43
- "@elysiajs/cookie": "^0.3.0",
44
- "@types/bun": "^1.0.4",
45
- "@types/node": "^20.1.4",
46
- "@typescript-eslint/eslint-plugin": "^6.6.0",
47
- "@typescript-eslint/parser": "^6.6.0",
48
- "elysia": "1.0.2",
49
- "eslint": "^8.40.0",
50
- "rimraf": "4.3",
51
- "typescript": "^5.1.6"
52
- },
53
- "peerDependencies": {
54
- "elysia": ">= 1.0.2"
55
- }
2
+ "name": "@elysiajs/jwt",
3
+ "description": "Plugin for Elysia for using JWT Authentication",
4
+ "version": "1.1.0",
5
+ "author": {
6
+ "name": "saltyAom",
7
+ "url": "https://github.com/SaltyAom",
8
+ "email": "saltyaom@gmail.com"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/elysiajs/elysia-jwt"
13
+ },
14
+ "main": "./dist/cjs/index.js",
15
+ "module": "./dist/index.mjs",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ "./package.json": "./package.json",
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.mjs",
22
+ "require": "./dist/cjs/index.js"
23
+ }
24
+ },
25
+ "bugs": "https://github.com/elysiajs/elysia-jwt/issues",
26
+ "homepage": "https://github.com/elysiajs/elysia-jwt",
27
+ "keywords": [
28
+ "elysia",
29
+ "jwt",
30
+ "auth",
31
+ "authentication"
32
+ ],
33
+ "license": "MIT",
34
+ "scripts": {
35
+ "dev": "bun run --hot example/index.ts",
36
+ "test": "bun test && npm run test:node",
37
+ "test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js",
38
+ "build": "bun build.ts",
39
+ "release": "npm run build && npm run test && npm publish --access public"
40
+ },
41
+ "dependencies": {
42
+ "jose": "^4.14.4"
43
+ },
44
+ "devDependencies": {
45
+ "@types/bun": "1.1.6",
46
+ "@typescript-eslint/eslint-plugin": "^6.6.0",
47
+ "@typescript-eslint/parser": "^6.6.0",
48
+ "elysia": ">= 1.1.0-rc.2",
49
+ "eslint": "9.6.0",
50
+ "tsup": "^8.1.0",
51
+ "typescript": "^5.5.3"
52
+ },
53
+ "peerDependencies": {
54
+ "elysia": ">= 1.1.0"
55
+ }
56
56
  }
package/dist/index.js DELETED
@@ -1,66 +0,0 @@
1
- import { Elysia, ValidationError, getSchemaValidator } from 'elysia';
2
- import { SignJWT, jwtVerify } from 'jose';
3
- import { Type as t } from '@sinclair/typebox';
4
- export const jwt = ({ name = 'jwt', secret, alg = 'HS256', crit, schema, nbf, exp, ...payload }) => {
5
- if (!secret)
6
- throw new Error("Secret can't be empty");
7
- const key = typeof secret === 'string' ? new TextEncoder().encode(secret) : secret;
8
- const validator = schema
9
- ? getSchemaValidator(t.Intersect([
10
- schema,
11
- t.Object({
12
- iss: t.Optional(t.String()),
13
- sub: t.Optional(t.String()),
14
- aud: t.Optional(t.Union([t.String(), t.Array(t.String())])),
15
- jti: t.Optional(t.String()),
16
- nbf: t.Optional(t.Union([t.String(), t.Number()])),
17
- exp: t.Optional(t.Union([t.String(), t.Number()])),
18
- iat: t.Optional(t.String())
19
- })
20
- ]), {})
21
- : undefined;
22
- return new Elysia({
23
- name: '@elysiajs/jwt',
24
- seed: {
25
- name,
26
- secret,
27
- alg,
28
- crit,
29
- schema,
30
- nbf,
31
- exp,
32
- ...payload
33
- }
34
- }).decorate(name, {
35
- sign: (morePayload) => {
36
- let jwt = new SignJWT({
37
- ...payload,
38
- ...morePayload,
39
- nbf: undefined,
40
- exp: undefined
41
- }).setProtectedHeader({
42
- alg,
43
- crit
44
- });
45
- if (nbf)
46
- jwt = jwt.setNotBefore(nbf);
47
- if (exp)
48
- jwt = jwt.setExpirationTime(exp);
49
- return jwt.sign(key);
50
- },
51
- verify: async (jwt) => {
52
- if (!jwt)
53
- return false;
54
- try {
55
- const data = (await jwtVerify(jwt, key)).payload;
56
- if (validator && !validator.Check(data))
57
- throw new ValidationError('JWT', validator, data);
58
- return data;
59
- }
60
- catch (_) {
61
- return false;
62
- }
63
- }
64
- });
65
- };
66
- export default jwt;