Skip to content

Commit

Permalink
Merge branch 'feature/auth-js' of github.com:ivoilic/middleware into …
Browse files Browse the repository at this point in the history
…feature/auth-js
  • Loading branch information
ivoilic committed Mar 11, 2023
2 parents 953cc94 + eb79217 commit 0b30e08
Show file tree
Hide file tree
Showing 27 changed files with 424 additions and 52 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci-typebox-validator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: ci-typebox-validator
on:
push:
branches: [main]
paths:
- 'packages/typebox-validator/**'
pull_request:
branches: ['*']
paths:
- 'packages/typebox-validator/**'

jobs:
ci:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./packages/typebox-validator
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18.x
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn test
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build:firebase-auth": "yarn workspace @hono/firebase-auth build",
"build:trpc-server": "yarn workspace @hono/trpc-server build",
"build:authjs-server": "yarn workspace @hono/authjs-server build",
"build:typebox-validator": "yarn workspace @hono/typebox-validator build",
"build": "run-p build:*"
},
"license": "MIT",
Expand Down
6 changes: 6 additions & 0 deletions packages/firebase-auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @hono/firebase-auth

## 1.2.0

### Minor Changes

- [#60](https://github.com/honojs/middleware/pull/60) [`a798c30`](https://github.com/honojs/middleware/commit/a798c307e11cd8d414ee23259fe0c5730dfb8841) Thanks [@yusukebe](https://github.com/yusukebe)! - feat: support Hono v3

## 1.1.0

### Minor Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/firebase-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hono/firebase-auth",
"version": "1.1.0",
"version": "1.2.0",
"description": "A third-party firebase auth middleware for Hono",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -31,13 +31,13 @@
"firebase-auth-cloudflare-workers": "^1.0.0"
},
"peerDependencies": {
"hono": "^2.7.2"
"hono": "3.*"
},
"devDependencies": {
"@cloudflare/workers-types": "^3.14.1",
"@types/jest": "^28.1.4",
"firebase-tools": "^11.4.0",
"hono": "^2.7.2",
"hono": "^3.0.3",
"jest": "^28.1.2",
"jest-environment-miniflare": "^2.6.0",
"prettier": "^2.7.1",
Expand Down
11 changes: 3 additions & 8 deletions packages/firebase-auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { EmulatorEnv, KeyStorer, FirebaseIdToken } from 'firebase-auth-cloudflare-workers'
import type { KeyStorer, FirebaseIdToken } from 'firebase-auth-cloudflare-workers'
import { Auth, WorkersKVStoreSingle } from 'firebase-auth-cloudflare-workers'
import type { Context, MiddlewareHandler } from 'hono'

export interface VerifyFirebaseAuthEnv extends EmulatorEnv {
export type VerifyFirebaseAuthEnv = {
PUBLIC_JWK_CACHE_KEY?: string | undefined
PUBLIC_JWK_CACHE_KV?: KVNamespace | undefined
FIREBASE_AUTH_EMULATOR_HOST: string | undefined
}

export interface VerifyFirebaseAuthConfig {
Expand All @@ -24,12 +25,6 @@ const defaultKeyStoreInitializer = (c: Context): KeyStorer => {
)
}

type Env = {
Bindings: {
FIREBASE_AUTH_EMULATOR_HOST: string
}
}

export const verifyFirebaseAuth = (userConfig: VerifyFirebaseAuthConfig): MiddlewareHandler => {
const config = {
projectId: userConfig.projectId,
Expand Down
6 changes: 6 additions & 0 deletions packages/graphql-server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @hono/graphql-server

## 0.4.0

### Minor Changes

- [#53](https://github.com/honojs/middleware/pull/53) [`ca1a210`](https://github.com/honojs/middleware/commit/ca1a2103a7b2692d05e29c67f891a9a147240efb) Thanks [@lrazovic](https://github.com/lrazovic)! - feat: bump up Hono to version 3.0.0

## 0.2.0

### Minor Changes
Expand Down
4 changes: 4 additions & 0 deletions packages/graphql-server/deno_dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ app.use(

app.fire()
```

## Author

Minghe Huang <h.minghe@gmail.com>
4 changes: 2 additions & 2 deletions packages/graphql-server/deno_dist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
GraphQLFormattedError,
} from 'https://cdn.skypack.dev/graphql@16.6.0?dts'

import type { Context } from 'https://deno.land/x/hono@v2.7.5/mod.ts'
import type { Context } from 'https://deno.land/x/hono@v3.0.0/mod.ts'
import { parseBody } from './parse-body.ts'

export type RootResolver = (ctx?: Context) => Promise<unknown> | unknown
Expand Down Expand Up @@ -46,7 +46,7 @@ export const graphqlServer = (options: Options) => {

let params: GraphQLParams
try {
params = await getGraphQLParams(c.req)
params = await getGraphQLParams(c.req.raw)
} catch (e) {
if (e instanceof Error) {
console.error(`${e.stack || e.message}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql-server/deno_test/hono.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { buildSchema } from 'https://cdn.skypack.dev/graphql@16.6.0?dts'
import { assertEquals } from 'https://deno.land/std@0.149.0/testing/asserts.ts'
import { Hono } from 'https://deno.land/x/hono@v2.7.5/mod.ts'
import { assertEquals } from 'https://deno.land/std@0.177.0/testing/asserts.ts'
import { Hono } from 'https://deno.land/x/hono@v3.0.0/mod.ts'
import { graphqlServer } from '../deno_dist/index.ts'

Deno.test('graphql-server', async (t) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hono/graphql-server",
"version": "0.2.0",
"version": "0.4.0",
"repository": "git@github.com:honojs/middleware.git",
"author": "Minghe Huang <h.minghe@gmail.com>",
"main": "dist/index.js",
Expand All @@ -27,7 +27,7 @@
"release": "np"
},
"peerDependencies": {
"hono": "^2.6.1"
"hono": "^3.0.0"
},
"dependencies": {
"graphql": "^16.5.0"
Expand All @@ -46,7 +46,7 @@
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"hono": "^2.6.1",
"hono": "^3.0.0",
"jest": "^28.1.2",
"jest-environment-miniflare": "^2.6.0",
"np": "^7.6.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const graphqlServer = (options: Options) => {

let params: GraphQLParams
try {
params = await getGraphQLParams(c.req)
params = await getGraphQLParams(c.req.raw)
} catch (e) {
if (e instanceof Error) {
console.error(`${e.stack || e.message}`)
Expand Down
6 changes: 6 additions & 0 deletions packages/sentry/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @hono/sentry

## 0.2.0

### Minor Changes

- [#57](https://github.com/honojs/middleware/pull/57) [`8d57df8`](https://github.com/honojs/middleware/commit/8d57df889d472fe9c40f468ce2103fe9880ff91b) Thanks [@yusukebe](https://github.com/yusukebe)! - feat: support latest Hono version

## 0.1.0

### Minor Changes
Expand Down
10 changes: 1 addition & 9 deletions packages/sentry/deno_dist/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
# Sentry middleware for Hono

## Information

Sentry Middleware `@honojs/sentry` is renamed to `@hono/sentry`.
`@honojs/sentry` is not maintained, please use `@hono/sentry`.
Also, for Deno, you can use import with `npm:` prefix like `npm:@hono/sentry`.

---

Sentry middleware for [Hono](https://github.com/honojs/hono).
This middleware sends captured exceptions to the specified Sentry data source name via [toucan-js](https://github.com/robertcepa/toucan-js).

## Usage

```ts
import { sentry } from '@hono/sentry'
import { Hono } from 'hono'
import { sentry } from '@hono/sentry'

const app = new Hono()

Expand Down
9 changes: 2 additions & 7 deletions packages/sentry/deno_dist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ declare module 'https://deno.land/x/hono/mod.ts' {
}
}

interface Bindings {
SENTRY_DSN?: string
NEXT_PUBLIC_SENTRY_DSN?: string
}

class MockContext implements ExecutionContext {
passThroughOnException(): void {
throw new Error('Method not implemented.')
Expand All @@ -37,7 +32,7 @@ export type Options = {
export const sentry = (
options?: Options,
callback?: (sentry: Toucan) => void
): MiddlewareHandler<string, { Bindings: Bindings }> => {
): MiddlewareHandler => {
return async (c, next) => {
let hasExecutionContext = true
try {
Expand All @@ -49,7 +44,7 @@ export const sentry = (
dsn: c.env.SENTRY_DSN ?? c.env.NEXT_PUBLIC_SENTRY_DSN,
allowedHeaders: ['user-agent'],
allowedSearchParams: /(.*)/,
request: c.req,
request: c.req.raw,
context: hasExecutionContext ? c.executionCtx : new MockContext(),
...options,
})
Expand Down
6 changes: 3 additions & 3 deletions packages/sentry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hono/sentry",
"version": "0.1.0",
"version": "0.2.0",
"description": "Sentry Middleware for Hono",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -33,7 +33,7 @@
"access": "public"
},
"peerDependencies": {
"hono": "^2.6.1"
"hono": "^3.0.2"
},
"dependencies": {
"toucan-js": "^2.6.1"
Expand All @@ -52,7 +52,7 @@
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"hono": "^2.6.1",
"hono": "^3.0.2",
"jest": "^28.1.2",
"jest-environment-miniflare": "^2.6.0",
"np": "^7.6.2",
Expand Down
9 changes: 2 additions & 7 deletions packages/sentry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ declare module 'hono' {
}
}

interface Bindings {
SENTRY_DSN?: string
NEXT_PUBLIC_SENTRY_DSN?: string
}

class MockContext implements ExecutionContext {
passThroughOnException(): void {
throw new Error('Method not implemented.')
Expand All @@ -37,7 +32,7 @@ export type Options = {
export const sentry = (
options?: Options,
callback?: (sentry: Toucan) => void
): MiddlewareHandler<string, { Bindings: Bindings }> => {
): MiddlewareHandler => {
return async (c, next) => {
let hasExecutionContext = true
try {
Expand All @@ -49,7 +44,7 @@ export const sentry = (
dsn: c.env.SENTRY_DSN ?? c.env.NEXT_PUBLIC_SENTRY_DSN,
allowedHeaders: ['user-agent'],
allowedSearchParams: /(.*)/,
request: c.req,
request: c.req.raw,
context: hasExecutionContext ? c.executionCtx : new MockContext(),
...options,
})
Expand Down
7 changes: 7 additions & 0 deletions packages/typebox-validator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @hono/typebox-validator

## 0.0.1

### Patch Changes

- [#55](https://github.com/honojs/middleware/pull/55) [`2a3245a`](https://github.com/honojs/middleware/commit/2a3245ad060590fee85b4c7b4188196817b41945) Thanks [@curtislarson](https://github.com/curtislarson)! - Add TypeBox validator middleware
53 changes: 53 additions & 0 deletions packages/typebox-validator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# TypeBox validator middleware for Hono

Validator middleware using [TypeBox](https://github.com/sinclairzx81/typebox) for [Hono](https://honojs.dev) applications.
Define your schema with TypeBox and validate incoming requests.

## Usage

No Hook:

```ts
import { tbValidator } from '@hono/typebox-validator'
import { Type as T } from '@sinclair/typebox'

const schema = T.Object({
name: T.String(),
age: T.Number(),
})

const route = app.post('/user', tbValidator('json', schema), (c) => {
const user = c.req.valid('json')
return c.json({ success: true, message: `${user.name} is ${user.age}` })
})
```

Hook:

```ts
import { tbValidator } from '@hono/typebox-validator'
import { Type as T } from '@sinclair/typebox'

const schema = T.Object({
name: T.String(),
age: T.Number(),
})

app.post(
'/user',
tbValidator('json', schema, (result, c) => {
if (!result.success) {
return c.text('Invalid!', 400)
}
})
//...
)
```

## Author

Curtis Larson <https://github.com/curtislarson>

## License

MIT
1 change: 1 addition & 0 deletions packages/typebox-validator/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../jest.config.js')

0 comments on commit 0b30e08

Please sign in to comment.