Skip to content

Commit 236c2a6

Browse files
committed
Merge branch 'main' of github.com:honojs/middleware
2 parents 753700b + 0ebcc6f commit 236c2a6

28 files changed

+2077
-10
lines changed

Diff for: .github/workflows/ci-class-validator.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: ci-class-validator
2+
on:
3+
push:
4+
branches: [main]
5+
paths:
6+
- 'packages/class-validator/**'
7+
pull_request:
8+
branches: ['*']
9+
paths:
10+
- 'packages/class-validator/**'
11+
12+
jobs:
13+
ci:
14+
runs-on: ubuntu-latest
15+
defaults:
16+
run:
17+
working-directory: ./packages/class-validator
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-node@v4
21+
with:
22+
node-version: 20.x
23+
- run: yarn install --frozen-lockfile
24+
- run: yarn build
25+
- run: yarn test

Diff for: .github/workflows/ci-swagger-editor.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: ci-swagger-editor
2+
on:
3+
push:
4+
branches: [main]
5+
paths:
6+
- 'packages/swagger-editor/**'
7+
pull_request:
8+
branches: ['*']
9+
paths:
10+
- 'packages/swagger-editor/**'
11+
12+
jobs:
13+
ci:
14+
runs-on: ubuntu-latest
15+
defaults:
16+
run:
17+
working-directory: ./packages/swagger-editor
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-node@v4
21+
with:
22+
node-version: 20.x
23+
- run: yarn install --frozen-lockfile
24+
- run: yarn build
25+
- run: yarn test

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"scripts": {
1111
"build:hello": "yarn workspace @hono/hello build",
1212
"build:zod-validator": "yarn workspace @hono/zod-validator build",
13+
"build:class-validator": "yarn workspace @hono/class-validator build",
1314
"build:arktype-validator": "yarn workspace @hono/arktype-validator build",
1415
"build:qwik-city": "yarn workspace @hono/qwik-city build",
1516
"build:graphql-server": "yarn workspace @hono/graphql-server build",
@@ -24,6 +25,7 @@
2425
"build:typebox-openapi": "yarn workspace @hono/typebox-openapi install && yarn workspace @hono/typebox-openapi build",
2526
"build:typia-validator": "yarn workspace @hono/typia-validator build",
2627
"build:swagger-ui": "yarn workspace @hono/swagger-ui build",
28+
"build:swagger-editor": "yarn workspace @hono/swagger-editor build",
2729
"build:esbuild-transpiler": "yarn workspace @hono/esbuild-transpiler build",
2830
"build:event-emitter": "yarn workspace @hono/event-emitter build",
2931
"build:oauth-providers": "yarn workspace @hono/oauth-providers build",

Diff for: packages/auth-js/CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# @hono/auth-js
22

3+
## 1.0.15
4+
5+
### Patch Changes
6+
7+
- [#813](https://github.com/honojs/middleware/pull/813) [`b1c812e50c9388cf7cda893e7c554cedeb24d803`](https://github.com/honojs/middleware/commit/b1c812e50c9388cf7cda893e7c554cedeb24d803) Thanks [@divyam234](https://github.com/divyam234)! - add react 19 in peer dependencies
8+
9+
## 1.0.14
10+
11+
### Patch Changes
12+
13+
- [#806](https://github.com/honojs/middleware/pull/806) [`9a2cf452c7000aee4193502da755b2c4352b077d`](https://github.com/honojs/middleware/commit/9a2cf452c7000aee4193502da755b2c4352b077d) Thanks [@985563349](https://github.com/985563349)! - fix cloned request causing request body to be unavailable in middleware
14+
315
## 1.0.13
416

517
### Patch Changes

Diff for: packages/auth-js/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hono/auth-js",
3-
"version": "1.0.13",
3+
"version": "1.0.15",
44
"description": "A third-party Auth js middleware for Hono",
55
"main": "dist/index.js",
66
"exports": {
@@ -54,7 +54,7 @@
5454
"peerDependencies": {
5555
"@auth/core": "0.*",
5656
"hono": ">=3.*",
57-
"react": ">=18"
57+
"react": "^18 || ^19 || ^19.0.0-rc"
5858
},
5959
"devDependencies": {
6060
"@auth/core": "^0.35.3",

Diff for: packages/auth-js/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export function reqWithEnvUrl(req: Request, authUrl?: string) {
4747
}
4848
return new Request(reqUrlObj.href, req)
4949
}
50-
const newReq = new Request(req)
51-
const url = new URL(newReq.url)
50+
const url = new URL(req.url)
51+
const newReq = new Request(url.href, req)
5252
const proto = newReq.headers.get('x-forwarded-proto')
5353
const host = newReq.headers.get('x-forwarded-host') ?? newReq.headers.get('host')
5454
if (proto != null) url.protocol = proto.endsWith(':') ? proto : `${proto}:`
@@ -128,7 +128,7 @@ export function authHandler(): MiddlewareHandler {
128128
if (!config.secret || config.secret.length === 0) {
129129
throw new HTTPException(500, { message: 'Missing AUTH_SECRET' })
130130
}
131-
131+
132132
const res = await Auth(reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL), config)
133133
return new Response(res.body, res)
134134
}

Diff for: packages/auth-js/test/index.test.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ describe('Credentials Provider', () => {
122122
return c.json(auth)
123123
})
124124

125+
app.post('/api/create', async (c) => {
126+
const data = await c.req.json()
127+
return c.json({ data })
128+
})
129+
125130
const credentials = Credentials({
126131
credentials: {
127132
password: {},
@@ -186,7 +191,7 @@ describe('Credentials Provider', () => {
186191
headers,
187192
})
188193
expect(res.status).toBe(200)
189-
const obj = await res.json() as {
194+
const obj = (await res.json()) as {
190195
token: {
191196
name: string
192197
email: string
@@ -196,6 +201,26 @@ describe('Credentials Provider', () => {
196201
expect(obj.token.email).toBe(user.email)
197202
})
198203

204+
it('Should authorize and return 200 - /api/create', async () => {
205+
const data = { name: 'Hono' }
206+
207+
const headers = new Headers()
208+
headers.append('cookie', cookie[1])
209+
headers.append('Content-Type', 'application/json')
210+
const res = await app.request('http://localhost/api/create', {
211+
method: 'POST',
212+
headers,
213+
body: JSON.stringify(data),
214+
})
215+
expect(res.status).toBe(200)
216+
const obj = (await res.json()) as {
217+
data: {
218+
name: string
219+
}
220+
}
221+
expect(obj.data.name).toBe(data.name)
222+
})
223+
199224
it('Should respect x-forwarded-proto and x-forwarded-host', async () => {
200225
const headers = new Headers()
201226
headers.append('x-forwarded-proto', 'https')

Diff for: packages/class-validator/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# @hono/class-validator
2+
3+
## 1.0.0
4+
5+
### Major Changes
6+
7+
- [#788](https://github.com/honojs/middleware/pull/788) [`a5c20b34285991c75871f67398e56e2b112c4dc9`](https://github.com/honojs/middleware/commit/a5c20b34285991c75871f67398e56e2b112c4dc9) Thanks [@pr0m3th3usEx](https://github.com/pr0m3th3usEx)! - First release

Diff for: packages/class-validator/README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Class-validator middleware for Hono
2+
3+
The validator middleware using [class-validator](https://github.com/typestack/class-validator) for [Hono](https://github.com/honojs/hono) applications.
4+
5+
## Usage
6+
7+
```ts
8+
import { classValidator } from '@hono/class-validator'
9+
import { IsInt, IsString } from 'class-validator'
10+
11+
class CreateUserDto {
12+
@IsString()
13+
name!: string;
14+
15+
@IsInt()
16+
age!: number;
17+
}
18+
19+
20+
const route = app.post('/user', classValidator('json', CreateUserDto), (c) => {
21+
const user = c.req.valid('json')
22+
return c.json({ success: true, message: `${user.name} is ${user.age}` })
23+
})
24+
```
25+
26+
With hook:
27+
28+
```ts
29+
import { classValidator } from '@hono/class-validator'
30+
import { IsInt, IsString } from 'class-validator'
31+
32+
class CreateUserDto {
33+
@IsString()
34+
name!: string;
35+
36+
@IsInt()
37+
age!: number;
38+
}
39+
40+
app.post(
41+
'/user', classValidator('json', CreateUserDto, (result, c) => {
42+
if (!result.success) {
43+
return c.text('Invalid!', 400)
44+
}
45+
})
46+
//...
47+
)
48+
```
49+
50+
## Author
51+
52+
**Pr0m3ht3us** - https://github.com/pr0m3th3usex
53+
54+
## License
55+
56+
MIT

Diff for: packages/class-validator/package.json

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "@hono/class-validator",
3+
"packageManager": "[email protected]",
4+
"description": "Validator middleware using class-validator",
5+
"version": "1.0.0",
6+
"type": "module",
7+
"main": "dist/index.js",
8+
"module": "dist/index.js",
9+
"types": "dist/index.d.ts",
10+
"exports": {
11+
".": {
12+
"import": "./dist/index.js",
13+
"types": "./dist/index.d.ts"
14+
}
15+
},
16+
"scripts": {
17+
"test": "vitest --run",
18+
"build": "rimraf dist && tsup ./src/index.ts --format esm,cjs --dts",
19+
"prerelease": "yarn build && yarn test",
20+
"release": "yarn publish"
21+
},
22+
"license": "MIT",
23+
"publishConfig": {
24+
"registry": "https://registry.npmjs.org",
25+
"access": "public"
26+
},
27+
"repository": {
28+
"type": "git",
29+
"url": "https://github.com/honojs/middleware.git"
30+
},
31+
"homepage": "https://github.com/honojs/middleware",
32+
"peerDependencies": {
33+
"hono": ">=3.9.0"
34+
},
35+
"devDependencies": {
36+
"hono": "^4.0.10",
37+
"rimraf": "^5.0.5",
38+
"tsup": "^8.3.5",
39+
"typescript": "^5.3.3",
40+
"vitest": "^1.4.0"
41+
},
42+
"dependencies": {
43+
"class-transformer": "^0.5.1",
44+
"class-validator": "^0.14.1",
45+
"reflect-metadata": "^0.2.2"
46+
}
47+
}

0 commit comments

Comments
 (0)