@elysiajs/jwt 0.5.2 → 0.6.0-rc.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.
@@ -1,4 +1,4 @@
1
- import { type Elysia } from 'elysia';
1
+ import { Elysia } from 'elysia';
2
2
  import { type JWTPayload, type JWSHeaderParameters } from 'jose';
3
3
  import type { Static, TSchema } from '@sinclair/typebox';
4
4
  type UnwrapSchema<Schema extends TSchema | undefined, Fallback = unknown> = Schema extends TSchema ? Static<NonNullable<Schema>> : Fallback;
@@ -18,13 +18,22 @@ export interface JWTOption<Name extends string | undefined = 'jwt', Schema exten
18
18
  nbf?: string | number;
19
19
  exp?: string | number;
20
20
  }
21
- export declare const jwt: <Name extends string = "jwt", Schema extends TSchema | undefined = undefined>({ name, secret, alg, crit, schema, nbf, exp, ...payload }: JWTOption<Name, Schema>) => (app: Elysia) => Elysia<{
21
+ export declare const jwt: <Name extends string = "jwt", Schema extends TSchema | undefined = undefined>({ name, secret, alg, crit, schema, nbf, exp, ...payload }: JWTOption<Name, Schema>) => Elysia<{
22
+ path: "";
22
23
  store: {};
23
- request: { [key in Name extends string ? Name : "jwt"]: {
24
+ error: {};
25
+ request: Record<Name extends string ? Name : "jwt", {
24
26
  readonly sign: (morePayload: UnwrapSchema<Schema, Record<string, string>> & JWTPayloadSpec) => Promise<string>;
25
27
  readonly verify: (jwt?: string) => Promise<false | (UnwrapSchema<Schema, Record<string, string>> & JWTPayloadSpec)>;
26
- }; };
28
+ }> extends infer T extends Object ? { [key in keyof T]: Record<Name extends string ? Name : "jwt", {
29
+ readonly sign: (morePayload: UnwrapSchema<Schema, Record<string, string>> & JWTPayloadSpec) => Promise<string>;
30
+ readonly verify: (jwt?: string) => Promise<false | (UnwrapSchema<Schema, Record<string, string>> & JWTPayloadSpec)>;
31
+ }>[key]; } : never;
27
32
  schema: {};
28
- meta: Record<typeof import("elysia").SCHEMA, {}> & Record<typeof import("elysia").DEFS, {}> & Record<typeof import("elysia").EXPOSED, {}>;
33
+ meta: {
34
+ schema: {};
35
+ defs: {};
36
+ exposed: {};
37
+ };
29
38
  }>;
30
39
  export default jwt;
package/dist/cjs/index.js CHANGED
@@ -4,7 +4,7 @@ exports.jwt = void 0;
4
4
  const elysia_1 = require("elysia");
5
5
  const jose_1 = require("jose");
6
6
  const typebox_1 = require("@sinclair/typebox");
7
- const jwt = ({ name = 'jwt', secret, alg = 'HS256', crit, schema, nbf, exp, ...payload }) => (app) => {
7
+ const jwt = ({ name = 'jwt', secret, alg = 'HS256', crit, schema, nbf, exp, ...payload }) => {
8
8
  if (!secret)
9
9
  throw new Error("Secret can't be empty");
10
10
  const key = new TextEncoder().encode(secret);
@@ -22,7 +22,19 @@ const jwt = ({ name = 'jwt', secret, alg = 'HS256', crit, schema, nbf, exp, ...p
22
22
  })
23
23
  ]), {})
24
24
  : undefined;
25
- return app.decorate(name, {
25
+ return new elysia_1.Elysia({
26
+ name: '@elysiajs/jwt',
27
+ seed: {
28
+ name,
29
+ secret,
30
+ alg,
31
+ crit,
32
+ schema,
33
+ nbf,
34
+ exp,
35
+ ...payload
36
+ }
37
+ }).decorate(name, {
26
38
  sign: (morePayload) => {
27
39
  let jwt = new jose_1.SignJWT({
28
40
  ...payload,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Elysia } from 'elysia';
1
+ import { Elysia } from 'elysia';
2
2
  import { type JWTPayload, type JWSHeaderParameters } from 'jose';
3
3
  import type { Static, TSchema } from '@sinclair/typebox';
4
4
  type UnwrapSchema<Schema extends TSchema | undefined, Fallback = unknown> = Schema extends TSchema ? Static<NonNullable<Schema>> : Fallback;
@@ -18,13 +18,22 @@ export interface JWTOption<Name extends string | undefined = 'jwt', Schema exten
18
18
  nbf?: string | number;
19
19
  exp?: string | number;
20
20
  }
21
- export declare const jwt: <Name extends string = "jwt", Schema extends TSchema | undefined = undefined>({ name, secret, alg, crit, schema, nbf, exp, ...payload }: JWTOption<Name, Schema>) => (app: Elysia) => Elysia<{
21
+ export declare const jwt: <Name extends string = "jwt", Schema extends TSchema | undefined = undefined>({ name, secret, alg, crit, schema, nbf, exp, ...payload }: JWTOption<Name, Schema>) => Elysia<{
22
+ path: "";
22
23
  store: {};
23
- request: { [key in Name extends string ? Name : "jwt"]: {
24
+ error: {};
25
+ request: Record<Name extends string ? Name : "jwt", {
24
26
  readonly sign: (morePayload: UnwrapSchema<Schema, Record<string, string>> & JWTPayloadSpec) => Promise<string>;
25
27
  readonly verify: (jwt?: string) => Promise<false | (UnwrapSchema<Schema, Record<string, string>> & JWTPayloadSpec)>;
26
- }; };
28
+ }> extends infer T extends Object ? { [key in keyof T]: Record<Name extends string ? Name : "jwt", {
29
+ readonly sign: (morePayload: UnwrapSchema<Schema, Record<string, string>> & JWTPayloadSpec) => Promise<string>;
30
+ readonly verify: (jwt?: string) => Promise<false | (UnwrapSchema<Schema, Record<string, string>> & JWTPayloadSpec)>;
31
+ }>[key]; } : never;
27
32
  schema: {};
28
- meta: Record<typeof import("elysia").SCHEMA, {}> & Record<typeof import("elysia").DEFS, {}> & Record<typeof import("elysia").EXPOSED, {}>;
33
+ meta: {
34
+ schema: {};
35
+ defs: {};
36
+ exposed: {};
37
+ };
29
38
  }>;
30
39
  export default jwt;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { ValidationError, getSchemaValidator } from 'elysia';
1
+ import { ValidationError, getSchemaValidator, Elysia } from 'elysia';
2
2
  import { SignJWT, jwtVerify } from 'jose';
3
3
  import { Type as t } from '@sinclair/typebox';
4
- export const jwt = ({ name = 'jwt', secret, alg = 'HS256', crit, schema, nbf, exp, ...payload }) => (app) => {
4
+ export const jwt = ({ name = 'jwt', secret, alg = 'HS256', crit, schema, nbf, exp, ...payload }) => {
5
5
  if (!secret)
6
6
  throw new Error("Secret can't be empty");
7
7
  const key = new TextEncoder().encode(secret);
@@ -19,7 +19,19 @@ export const jwt = ({ name = 'jwt', secret, alg = 'HS256', crit, schema, nbf, ex
19
19
  })
20
20
  ]), {})
21
21
  : undefined;
22
- return app.decorate(name, {
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, {
23
35
  sign: (morePayload) => {
24
36
  let jwt = new SignJWT({
25
37
  ...payload,
package/package.json CHANGED
@@ -1,55 +1,55 @@
1
1
  {
2
- "name": "@elysiajs/jwt",
3
- "description": "Plugin for Elysia for using JWT Authentication",
4
- "version": "0.5.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 wiptest && 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
- "@sinclair/typebox": "^0.28.10",
45
- "@types/node": "^20.1.4",
46
- "bun-types": "^0.5.8",
47
- "elysia": "0.5.12",
48
- "eslint": "^8.40.0",
49
- "rimraf": "4.3",
50
- "typescript": "^5.0.4"
51
- },
52
- "peerDependencies": {
53
- "elysia": ">= 0.5.12"
54
- }
55
- }
2
+ "name": "@elysiajs/jwt",
3
+ "description": "Plugin for Elysia for using JWT Authentication",
4
+ "version": "0.6.0-rc.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/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 wiptest && 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
+ "@sinclair/typebox": "^0.28.10",
45
+ "@types/node": "^20.1.4",
46
+ "bun-types": "^0.5.8",
47
+ "elysia": "0.6.0-alpha.4",
48
+ "eslint": "^8.40.0",
49
+ "rimraf": "4.3",
50
+ "typescript": "^5.0.4"
51
+ },
52
+ "peerDependencies": {
53
+ "elysia": ">= 0.5.12"
54
+ }
55
+ }