hono 4.3.11 → 4.4.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.
Files changed (188) hide show
  1. package/README.md +2 -3
  2. package/dist/adapter/aws-lambda/handler.js +12 -9
  3. package/dist/adapter/bun/conninfo.js +21 -0
  4. package/dist/adapter/bun/index.js +2 -0
  5. package/dist/adapter/bun/websocket.js +1 -3
  6. package/dist/adapter/cloudflare-workers/conninfo.js +10 -0
  7. package/dist/adapter/cloudflare-workers/websocket.js +2 -6
  8. package/dist/adapter/deno/conninfo.js +15 -0
  9. package/dist/adapter/deno/index.js +2 -0
  10. package/dist/adapter/lambda-edge/handler.js +3 -3
  11. package/dist/cjs/adapter/aws-lambda/handler.js +12 -9
  12. package/dist/cjs/adapter/bun/conninfo.js +44 -0
  13. package/dist/cjs/adapter/bun/index.js +3 -0
  14. package/dist/cjs/adapter/cloudflare-workers/conninfo.js +33 -0
  15. package/dist/cjs/adapter/cloudflare-workers/websocket.js +2 -6
  16. package/dist/cjs/adapter/deno/conninfo.js +38 -0
  17. package/dist/cjs/adapter/deno/index.js +3 -0
  18. package/dist/cjs/adapter/lambda-edge/handler.js +3 -3
  19. package/dist/cjs/helper/conninfo/index.js +16 -0
  20. package/dist/cjs/helper/ssg/ssg.js +64 -3
  21. package/dist/cjs/helper/streaming/text.js +1 -1
  22. package/dist/cjs/hono-base.js +10 -6
  23. package/dist/cjs/jsx/base.js +5 -2
  24. package/dist/cjs/jsx/dom/client.js +68 -0
  25. package/dist/cjs/jsx/dom/index.js +8 -4
  26. package/dist/cjs/jsx/dom/jsx-dev-runtime.js +6 -20
  27. package/dist/cjs/jsx/dom/render.js +41 -25
  28. package/dist/cjs/jsx/dom/utils.js +15 -0
  29. package/dist/cjs/jsx/hooks/index.js +4 -1
  30. package/dist/cjs/jsx/index.js +8 -4
  31. package/dist/cjs/middleware/jwt/index.js +5 -82
  32. package/dist/cjs/middleware/jwt/jwt.js +111 -0
  33. package/dist/cjs/middleware/secure-headers/index.js +3 -123
  34. package/dist/cjs/middleware/secure-headers/secure-headers.js +150 -0
  35. package/dist/cjs/middleware/timeout/index.js +48 -0
  36. package/dist/cjs/middleware/timing/index.js +5 -89
  37. package/dist/cjs/middleware/timing/timing.js +118 -0
  38. package/dist/cjs/utils/body.js +34 -9
  39. package/dist/cjs/utils/jwt/jws.js +4 -5
  40. package/dist/cjs/utils/jwt/jwt.js +6 -7
  41. package/dist/cjs/utils/url.js +26 -2
  42. package/dist/helper/css/index.js +4 -4
  43. package/dist/helper/html/index.js +1 -1
  44. package/dist/helper/ssg/ssg.js +63 -5
  45. package/dist/helper/streaming/text.js +1 -1
  46. package/dist/hono-base.js +11 -7
  47. package/dist/jsx/base.js +3 -1
  48. package/dist/jsx/dom/client.js +44 -0
  49. package/dist/jsx/dom/css.js +4 -4
  50. package/dist/jsx/dom/index.js +25 -21
  51. package/dist/jsx/dom/jsx-dev-runtime.js +6 -20
  52. package/dist/jsx/dom/render.js +40 -26
  53. package/dist/jsx/dom/utils.js +14 -0
  54. package/dist/jsx/hooks/index.js +4 -2
  55. package/dist/jsx/index.js +22 -18
  56. package/dist/jsx/jsx-runtime.js +1 -1
  57. package/dist/middleware/jsx-renderer/index.js +1 -1
  58. package/dist/middleware/jwt/index.js +1 -78
  59. package/dist/middleware/jwt/jwt.js +85 -0
  60. package/dist/middleware/secure-headers/index.js +1 -121
  61. package/dist/middleware/secure-headers/secure-headers.js +126 -0
  62. package/dist/middleware/timeout/index.js +25 -0
  63. package/dist/middleware/timing/index.js +1 -85
  64. package/dist/middleware/timing/timing.js +92 -0
  65. package/dist/request.js +1 -1
  66. package/dist/router/reg-exp-router/router.js +2 -2
  67. package/dist/router/smart-router/router.js +1 -1
  68. package/dist/router/trie-router/node.js +1 -1
  69. package/dist/types/adapter/aws-lambda/handler.d.ts +3 -3
  70. package/dist/types/adapter/aws-lambda/index.d.ts +4 -0
  71. package/dist/types/adapter/bun/conninfo.d.ts +7 -0
  72. package/dist/types/adapter/bun/index.d.ts +5 -0
  73. package/dist/types/adapter/bun/websocket.d.ts +2 -3
  74. package/dist/types/adapter/cloudflare-pages/index.d.ts +4 -0
  75. package/dist/types/adapter/cloudflare-workers/conninfo.d.ts +2 -0
  76. package/dist/types/adapter/cloudflare-workers/index.d.ts +4 -0
  77. package/dist/types/adapter/cloudflare-workers/serve-static-module.d.ts +2 -2
  78. package/dist/types/adapter/cloudflare-workers/serve-static.d.ts +1 -2
  79. package/dist/types/adapter/cloudflare-workers/utils.d.ts +1 -2
  80. package/dist/types/adapter/deno/conninfo.d.ts +7 -0
  81. package/dist/types/adapter/deno/index.d.ts +5 -0
  82. package/dist/types/adapter/lambda-edge/handler.d.ts +1 -2
  83. package/dist/types/adapter/lambda-edge/index.d.ts +4 -0
  84. package/dist/types/adapter/netlify/handler.d.ts +1 -7
  85. package/dist/types/adapter/netlify/index.d.ts +4 -0
  86. package/dist/types/adapter/netlify/mod.d.ts +0 -1
  87. package/dist/types/adapter/vercel/index.d.ts +4 -0
  88. package/dist/types/client/index.d.ts +4 -0
  89. package/dist/types/compose.d.ts +1 -1
  90. package/dist/types/helper/accepts/index.d.ts +4 -0
  91. package/dist/types/helper/adapter/index.d.ts +4 -0
  92. package/dist/types/helper/conninfo/index.d.ts +40 -0
  93. package/dist/types/helper/cookie/index.d.ts +5 -1
  94. package/dist/types/helper/css/index.d.ts +4 -0
  95. package/dist/types/helper/dev/index.d.ts +4 -0
  96. package/dist/types/helper/factory/index.d.ts +4 -0
  97. package/dist/types/helper/html/index.d.ts +4 -0
  98. package/dist/types/helper/ssg/index.d.ts +4 -0
  99. package/dist/types/helper/ssg/ssg.d.ts +6 -3
  100. package/dist/types/helper/streaming/index.d.ts +4 -0
  101. package/dist/types/helper/testing/index.d.ts +4 -0
  102. package/dist/types/helper/websocket/index.d.ts +4 -0
  103. package/dist/types/hono-base.d.ts +15 -15
  104. package/dist/types/http-exception.d.ts +4 -0
  105. package/dist/types/index.d.ts +15 -0
  106. package/dist/types/jsx/base.d.ts +10 -11
  107. package/dist/types/jsx/components.d.ts +1 -1
  108. package/dist/types/jsx/context.d.ts +1 -1
  109. package/dist/types/jsx/dom/client.d.ts +26 -0
  110. package/dist/types/jsx/dom/components.d.ts +2 -2
  111. package/dist/types/jsx/dom/css.d.ts +31 -20
  112. package/dist/types/jsx/dom/index.d.ts +13 -7
  113. package/dist/types/jsx/dom/jsx-dev-runtime.d.ts +5 -1
  114. package/dist/types/jsx/dom/jsx-runtime.d.ts +4 -0
  115. package/dist/types/jsx/dom/render.d.ts +4 -3
  116. package/dist/types/jsx/dom/utils.d.ts +6 -0
  117. package/dist/types/jsx/hooks/index.d.ts +4 -0
  118. package/dist/types/jsx/index.d.ts +13 -7
  119. package/dist/types/jsx/intrinsic-elements.d.ts +629 -630
  120. package/dist/types/jsx/jsx-dev-runtime.d.ts +5 -0
  121. package/dist/types/jsx/jsx-runtime.d.ts +5 -0
  122. package/dist/types/jsx/streaming.d.ts +5 -1
  123. package/dist/types/jsx/types.d.ts +1 -0
  124. package/dist/types/middleware/basic-auth/index.d.ts +35 -0
  125. package/dist/types/middleware/bearer-auth/index.d.ts +33 -0
  126. package/dist/types/middleware/body-limit/index.d.ts +28 -11
  127. package/dist/types/middleware/cache/index.d.ts +29 -0
  128. package/dist/types/middleware/compress/index.d.ts +20 -0
  129. package/dist/types/middleware/cors/index.d.ts +43 -0
  130. package/dist/types/middleware/csrf/index.d.ts +41 -0
  131. package/dist/types/middleware/etag/index.d.ts +24 -0
  132. package/dist/types/middleware/jsx-renderer/index.d.ts +63 -2
  133. package/dist/types/middleware/jwt/index.d.ts +5 -17
  134. package/dist/types/middleware/jwt/jwt.d.ts +48 -0
  135. package/dist/types/middleware/logger/index.d.ts +20 -0
  136. package/dist/types/middleware/method-override/index.d.ts +22 -10
  137. package/dist/types/middleware/powered-by/index.d.ts +4 -0
  138. package/dist/types/middleware/pretty-json/index.d.ts +23 -0
  139. package/dist/types/middleware/secure-headers/index.d.ts +6 -64
  140. package/dist/types/middleware/secure-headers/secure-headers.d.ts +97 -0
  141. package/dist/types/middleware/serve-static/index.d.ts +4 -0
  142. package/dist/types/middleware/timeout/index.d.ts +31 -0
  143. package/dist/types/middleware/timing/index.d.ts +5 -29
  144. package/dist/types/middleware/timing/timing.d.ts +111 -0
  145. package/dist/types/middleware/trailing-slash/index.d.ts +29 -5
  146. package/dist/types/preset/quick.d.ts +4 -0
  147. package/dist/types/preset/tiny.d.ts +4 -0
  148. package/dist/types/request.d.ts +5 -4
  149. package/dist/types/router/linear-router/index.d.ts +4 -0
  150. package/dist/types/router/linear-router/router.d.ts +1 -1
  151. package/dist/types/router/pattern-router/index.d.ts +4 -0
  152. package/dist/types/router/reg-exp-router/index.d.ts +4 -0
  153. package/dist/types/router/reg-exp-router/router.d.ts +1 -1
  154. package/dist/types/router/reg-exp-router/trie.d.ts +1 -1
  155. package/dist/types/router/smart-router/index.d.ts +4 -0
  156. package/dist/types/router/smart-router/router.d.ts +1 -1
  157. package/dist/types/router/trie-router/index.d.ts +4 -0
  158. package/dist/types/router.d.ts +4 -0
  159. package/dist/types/types.d.ts +4 -0
  160. package/dist/types/utils/body.d.ts +61 -3
  161. package/dist/types/utils/buffer.d.ts +4 -0
  162. package/dist/types/utils/color.d.ts +4 -0
  163. package/dist/types/utils/concurrent.d.ts +4 -0
  164. package/dist/types/utils/cookie.d.ts +4 -0
  165. package/dist/types/utils/crypto.d.ts +4 -0
  166. package/dist/types/utils/encode.d.ts +4 -0
  167. package/dist/types/utils/filepath.d.ts +4 -0
  168. package/dist/types/utils/handler.d.ts +4 -0
  169. package/dist/types/utils/html.d.ts +4 -0
  170. package/dist/types/utils/http-status.d.ts +4 -0
  171. package/dist/types/utils/jwt/index.d.ts +4 -0
  172. package/dist/types/utils/jwt/jwt.d.ts +3 -3
  173. package/dist/types/utils/mime.d.ts +4 -0
  174. package/dist/types/utils/stream.d.ts +4 -0
  175. package/dist/types/utils/types.d.ts +4 -0
  176. package/dist/types/utils/url.d.ts +4 -0
  177. package/dist/types/validator/index.d.ts +4 -0
  178. package/dist/types/validator/validator.d.ts +1 -1
  179. package/dist/utils/body.js +34 -9
  180. package/dist/utils/jwt/index.js +1 -1
  181. package/dist/utils/jwt/jws.js +1 -2
  182. package/dist/utils/jwt/jwt.js +5 -5
  183. package/dist/utils/url.js +26 -2
  184. package/package.json +27 -6
  185. package/dist/cjs/adapter/aws-lambda/awslambda.d.js +0 -1
  186. package/dist/cjs/helper.js +0 -44
  187. package/dist/helper.js +0 -18
  188. /package/dist/{adapter/aws-lambda/awslambda.d.js → helper/conninfo/index.js} +0 -0
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @module
3
+ * This module provides Hono's JSX dev runtime.
4
+ */
1
5
  import type { JSXNode } from './base';
2
6
  export { Fragment } from './base';
7
+ export type { JSX } from './base';
3
8
  export declare function jsxDEV(tag: string | Function, props: Record<string, unknown>, key?: string): JSXNode;
@@ -1,5 +1,10 @@
1
+ /**
2
+ * @module
3
+ * This module provides Hono's JSX runtime.
4
+ */
1
5
  export { jsxDEV as jsx, Fragment } from './jsx-dev-runtime';
2
6
  export { jsxDEV as jsxs } from './jsx-dev-runtime';
7
+ export type { JSX } from './jsx-dev-runtime';
3
8
  import { html } from '../helper/html';
4
9
  import type { HtmlEscapedString } from '../utils/html';
5
10
  export { html as jsxTemplate };
@@ -1,5 +1,9 @@
1
+ /**
2
+ * @module
3
+ * This module enables JSX to supports streaming Response.
4
+ */
1
5
  import type { HtmlEscapedString } from '../utils/html';
2
- import type { FC, PropsWithChildren } from '.';
6
+ import type { FC, PropsWithChildren } from './';
3
7
  /**
4
8
  * @experimental
5
9
  * `Suspense` is an experimental feature.
@@ -2,6 +2,7 @@
2
2
  * All types exported from "hono/jsx" are in this file.
3
3
  */
4
4
  import type { Child, JSXNode } from './base';
5
+ import type { Hono } from './intrinsic-elements';
5
6
  export type { Child, JSXNode, FC } from './base';
6
7
  export type { RefObject } from './hooks';
7
8
  export type { Context } from './context';
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module
3
+ * Basic Auth Middleware for Hono.
4
+ */
1
5
  import type { Context } from '../../context';
2
6
  import type { MiddlewareHandler } from '../../types';
3
7
  type BasicAuthOptions = {
@@ -10,6 +14,37 @@ type BasicAuthOptions = {
10
14
  realm?: string;
11
15
  hashFunction?: Function;
12
16
  };
17
+ /**
18
+ * Basic Auth Middleware for Hono.
19
+ *
20
+ * @see {@link https://hono.dev/middleware/builtin/basic-auth}
21
+ *
22
+ * @param {BasicAuthOptions} options - The options for the basic authentication middleware.
23
+ * @param {string} options.username - The username for authentication.
24
+ * @param {string} options.password - The password for authentication.
25
+ * @param {string} [options.realm="Secure Area"] - The realm attribute for the WWW-Authenticate header.
26
+ * @param {Function} [options.hashFunction] - The hash function used for secure comparison.
27
+ * @param {Function} [options.verifyUser] - The function to verify user credentials.
28
+ * @returns {MiddlewareHandler} The middleware handler function.
29
+ * @throws {HTTPException} If neither "username and password" nor "verifyUser" options are provided.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const app = new Hono()
34
+ *
35
+ * app.use(
36
+ * '/auth/*',
37
+ * basicAuth({
38
+ * username: 'hono',
39
+ * password: 'acoolproject',
40
+ * })
41
+ * )
42
+ *
43
+ * app.get('/auth/page', (c) => {
44
+ * return c.text('You are authorized')
45
+ * })
46
+ * ```
47
+ */
13
48
  export declare const basicAuth: (options: BasicAuthOptions, ...users: {
14
49
  username: string;
15
50
  password: string;
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module
3
+ * Bearer Auth Middleware for Hono.
4
+ */
1
5
  import type { Context } from '../../context';
2
6
  import type { MiddlewareHandler } from '../../types';
3
7
  type BearerAuthOptions = {
@@ -13,5 +17,34 @@ type BearerAuthOptions = {
13
17
  verifyToken: (token: string, c: Context) => boolean | Promise<boolean>;
14
18
  hashFunction?: Function;
15
19
  };
20
+ /**
21
+ * Bearer Auth Middleware for Hono.
22
+ *
23
+ * @see {@link https://hono.dev/middleware/builtin/bearer-auth}
24
+ *
25
+ * @param {BearerAuthOptions} options - The options for the bearer authentication middleware.
26
+ * @param {string | string[]} [options.token] - The string or array of strings to validate the incoming bearer token against.
27
+ * @param {Function} [options.verifyToken] - The function to verify the token.
28
+ * @param {string} [options.realm=""] - The domain name of the realm, as part of the returned WWW-Authenticate challenge header.
29
+ * @param {string} [options.prefix="Bearer"] - The prefix (or known as `schema`) for the Authorization header value.
30
+ * @param {string} [options.headerName=Authorization] - The header name.
31
+ * @param {Function} [options.hashFunction] - A function to handle hashing for safe comparison of authentication tokens.
32
+ * @returns {MiddlewareHandler} The middleware handler function.
33
+ * @throws {Error} If neither "token" nor "verifyToken" options are provided.
34
+ * @throws {HTTPException} If authentication fails, with 401 status code for missing or invalid token, or 400 status code for invalid request.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const app = new Hono()
39
+ *
40
+ * const token = 'honoiscool'
41
+ *
42
+ * app.use('/api/*', bearerAuth({ token }))
43
+ *
44
+ * app.get('/api/page', (c) => {
45
+ * return c.json({ message: 'You are authorized' })
46
+ * })
47
+ * ```
48
+ */
16
49
  export declare const bearerAuth: (options: BearerAuthOptions) => MiddlewareHandler;
17
50
  export {};
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module
3
+ * Body Limit Middleware for Hono.
4
+ */
1
5
  import type { Context } from '../../context';
2
6
  import type { MiddlewareHandler } from '../../types';
3
7
  type OnError = (c: Context) => Response | Promise<Response>;
@@ -6,21 +10,34 @@ type BodyLimitOptions = {
6
10
  onError?: OnError;
7
11
  };
8
12
  /**
9
- * Body Limit Middleware
13
+ * Body Limit Middleware for Hono.
14
+ *
15
+ * @see {@link https://hono.dev/middleware/builtin/body-limit}
16
+ *
17
+ * @param {BodyLimitOptions} options - The options for the body limit middleware.
18
+ * @param {number} options.maxSize - The maximum body size allowed.
19
+ * @param {OnError} [options.onError] - The error handler to be invoked if the specified body size is exceeded.
20
+ * @returns {MiddlewareHandler} The middleware handler function.
10
21
  *
11
22
  * @example
12
23
  * ```ts
24
+ * const app = new Hono()
25
+ *
13
26
  * app.post(
14
- * '/hello',
15
- * bodyLimit({
16
- * maxSize: 100 * 1024, // 100kb
17
- * onError: (c) => {
18
- * return c.text('overflow :(', 413)
19
- * }
20
- * }),
21
- * (c) => {
22
- * return c.text('pass :)')
23
- * }
27
+ * '/upload',
28
+ * bodyLimit({
29
+ * maxSize: 50 * 1024, // 50kb
30
+ * onError: (c) => {
31
+ * return c.text('overflow :(', 413)
32
+ * },
33
+ * }),
34
+ * async (c) => {
35
+ * const body = await c.req.parseBody()
36
+ * if (body['file'] instanceof File) {
37
+ * console.log(`Got file sized: ${body['file'].size}`)
38
+ * }
39
+ * return c.text('pass :)')
40
+ * }
24
41
  * )
25
42
  * ```
26
43
  */
@@ -1,5 +1,34 @@
1
+ /**
2
+ * @module
3
+ * Cache Middleware for Hono.
4
+ */
1
5
  import type { Context } from '../../context';
2
6
  import type { MiddlewareHandler } from '../../types';
7
+ /**
8
+ * Cache Middleware for Hono.
9
+ *
10
+ * @see {@link https://hono.dev/middleware/builtin/cache}
11
+ *
12
+ * @param {Object} options - The options for the cache middleware.
13
+ * @param {string | Function} options.cacheName - The name of the cache. Can be used to store multiple caches with different identifiers.
14
+ * @param {boolean} [options.wait=false] - A boolean indicating if Hono should wait for the Promise of the `cache.put` function to resolve before continuing with the request. Required to be true for the Deno environment.
15
+ * @param {string} [options.cacheControl] - A string of directives for the `Cache-Control` header.
16
+ * @param {string | string[]} [options.vary] - Sets the `Vary` header in the response. If the original response header already contains a `Vary` header, the values are merged, removing any duplicates.
17
+ * @param {Function} [options.keyGenerator] - Generates keys for every request in the `cacheName` store. This can be used to cache data based on request parameters or context parameters.
18
+ * @returns {MiddlewareHandler} The middleware handler function.
19
+ * @throws {Error} If the `vary` option includes "*".
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * app.get(
24
+ * '*',
25
+ * cache({
26
+ * cacheName: 'my-app',
27
+ * cacheControl: 'max-age=3600',
28
+ * })
29
+ * )
30
+ * ```
31
+ */
3
32
  export declare const cache: (options: {
4
33
  cacheName: string | ((c: Context) => Promise<string> | string);
5
34
  wait?: boolean | undefined;
@@ -1,7 +1,27 @@
1
+ /**
2
+ * @module
3
+ * Compress Middleware for Hono.
4
+ */
1
5
  import type { MiddlewareHandler } from '../../types';
2
6
  declare const ENCODING_TYPES: readonly ["gzip", "deflate"];
3
7
  interface CompressionOptions {
4
8
  encoding?: (typeof ENCODING_TYPES)[number];
5
9
  }
10
+ /**
11
+ * Compress Middleware for Hono.
12
+ *
13
+ * @see {@link https://hono.dev/middleware/builtin/compress}
14
+ *
15
+ * @param {CompressionOptions} [options] - The options for the compress middleware.
16
+ * @param {'gzip' | 'deflate'} [options.encoding] - The compression scheme to allow for response compression. Either 'gzip' or 'deflate'. If not defined, both are allowed and will be used based on the Accept-Encoding header. 'gzip' is prioritized if this option is not provided and the client provides both in the Accept-Encoding header.
17
+ * @returns {MiddlewareHandler} The middleware handler function.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const app = new Hono()
22
+ *
23
+ * app.use(compress())
24
+ * ```
25
+ */
6
26
  export declare const compress: (options?: CompressionOptions) => MiddlewareHandler;
7
27
  export {};
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module
3
+ * CORS Middleware for Hono.
4
+ */
1
5
  import type { Context } from '../../context';
2
6
  import type { MiddlewareHandler } from '../../types';
3
7
  type CORSOptions = {
@@ -8,5 +12,44 @@ type CORSOptions = {
8
12
  credentials?: boolean;
9
13
  exposeHeaders?: string[];
10
14
  };
15
+ /**
16
+ * CORS Middleware for Hono.
17
+ *
18
+ * @see {@link https://hono.dev/middleware/builtin/cors}
19
+ *
20
+ * @param {CORSOptions} [options] - The options for the CORS middleware.
21
+ * @param {string | string[] | ((origin: string, c: Context) => string | undefined | null)} [options.origin='*'] - The value of "Access-Control-Allow-Origin" CORS header.
22
+ * @param {string[]} [options.allowMethods=['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH']] - The value of "Access-Control-Allow-Methods" CORS header.
23
+ * @param {string[]} [options.allowHeaders=[]] - The value of "Access-Control-Allow-Headers" CORS header.
24
+ * @param {number} [options.maxAge] - The value of "Access-Control-Max-Age" CORS header.
25
+ * @param {boolean} [options.credentials] - The value of "Access-Control-Allow-Credentials" CORS header.
26
+ * @param {string[]} [options.exposeHeaders=[]] - The value of "Access-Control-Expose-Headers" CORS header.
27
+ * @returns {MiddlewareHandler} The middleware handler function.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const app = new Hono()
32
+ *
33
+ * app.use('/api/*', cors())
34
+ * app.use(
35
+ * '/api2/*',
36
+ * cors({
37
+ * origin: 'http://example.com',
38
+ * allowHeaders: ['X-Custom-Header', 'Upgrade-Insecure-Requests'],
39
+ * allowMethods: ['POST', 'GET', 'OPTIONS'],
40
+ * exposeHeaders: ['Content-Length', 'X-Kuma-Revision'],
41
+ * maxAge: 600,
42
+ * credentials: true,
43
+ * })
44
+ * )
45
+ *
46
+ * app.all('/api/abc', (c) => {
47
+ * return c.json({ success: true })
48
+ * })
49
+ * app.all('/api2/abc', (c) => {
50
+ * return c.json({ success: true })
51
+ * })
52
+ * ```
53
+ */
11
54
  export declare const cors: (options?: CORSOptions) => MiddlewareHandler;
12
55
  export {};
@@ -1,8 +1,49 @@
1
+ /**
2
+ * @module
3
+ * CSRF Protection Middleware for Hono.
4
+ */
1
5
  import type { Context } from '../../context';
2
6
  import type { MiddlewareHandler } from '../../types';
3
7
  type IsAllowedOriginHandler = (origin: string, context: Context) => boolean;
4
8
  interface CSRFOptions {
5
9
  origin?: string | string[] | IsAllowedOriginHandler;
6
10
  }
11
+ /**
12
+ * CSRF Protection Middleware for Hono.
13
+ *
14
+ * @see {@link https://hono.dev/middleware/builtin/csrf}
15
+ *
16
+ * @param {CSRFOptions} [options] - The options for the CSRF protection middleware.
17
+ * @param {string|string[]|(origin: string, context: Context) => boolean} [options.origin] - Specify origins.
18
+ * @returns {MiddlewareHandler} The middleware handler function.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const app = new Hono()
23
+ *
24
+ * app.use(csrf())
25
+ *
26
+ * // Specifying origins with using `origin` option
27
+ * // string
28
+ * app.use(csrf({ origin: 'myapp.example.com' }))
29
+ *
30
+ * // string[]
31
+ * app.use(
32
+ * csrf({
33
+ * origin: ['myapp.example.com', 'development.myapp.example.com'],
34
+ * })
35
+ * )
36
+ *
37
+ * // Function
38
+ * // It is strongly recommended that the protocol be verified to ensure a match to `$`.
39
+ * // You should *never* do a forward match.
40
+ * app.use(
41
+ * '*',
42
+ * csrf({
43
+ * origin: (origin) => /https:\/\/(\w+\.)?myapp\.example\.com$/.test(origin),
44
+ * })
45
+ * )
46
+ * ```
47
+ */
7
48
  export declare const csrf: (options?: CSRFOptions) => MiddlewareHandler;
8
49
  export {};
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module
3
+ * ETag Middleware for Hono.
4
+ */
1
5
  import type { MiddlewareHandler } from '../../types';
2
6
  type ETagOptions = {
3
7
  retainedHeaders?: string[];
@@ -10,5 +14,25 @@ type ETagOptions = {
10
14
  * > Content-Location, Date, ETag, Expires, and Vary.
11
15
  */
12
16
  export declare const RETAINED_304_HEADERS: string[];
17
+ /**
18
+ * ETag Middleware for Hono.
19
+ *
20
+ * @see {@link https://hono.dev/middleware/builtin/etag}
21
+ *
22
+ * @param {ETagOptions} [options] - The options for the ETag middleware.
23
+ * @param {boolean} [options.weak=false] - Define using or not using a weak validation. If true is set, then `W/` is added to the prefix of the value.
24
+ * @param {string[]} [options.retainedHeaders=RETAINED_304_HEADERS] - The headers that you want to retain in the 304 Response.
25
+ * @returns {MiddlewareHandler} The middleware handler function.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const app = new Hono()
30
+ *
31
+ * app.use('/etag/*', etag())
32
+ * app.get('/etag/abc', (c) => {
33
+ * return c.text('Hono is cool')
34
+ * })
35
+ * ```
36
+ */
13
37
  export declare const etag: (options?: ETagOptions) => MiddlewareHandler;
14
38
  export {};
@@ -1,6 +1,9 @@
1
+ /**
2
+ * @module
3
+ * JSR Renderer Middleware for Hono.
4
+ */
1
5
  import type { Context, PropsForRenderer } from '../../context';
2
- import type { FC, PropsWithChildren } from '../../jsx';
3
- import type { Context as JSXContext } from '../../jsx';
6
+ import type { FC, Context as JSXContext, PropsWithChildren } from '../../jsx';
4
7
  import type { Env, Input, MiddlewareHandler } from '../../types';
5
8
  import type { HtmlEscapedString } from '../../utils/html';
6
9
  export declare const RequestContext: JSXContext<Context<any, any, {}> | null>;
@@ -11,6 +14,64 @@ type RendererOptions = {
11
14
  type ComponentWithChildren = (props: PropsWithChildren<PropsForRenderer & {
12
15
  Layout: FC;
13
16
  }>, c: Context) => HtmlEscapedString | Promise<HtmlEscapedString>;
17
+ /**
18
+ * JSX Renderer Middleware for hono.
19
+ *
20
+ * @see {@link{https://hono.dev/middleware/builtin/jsx-renderer}}
21
+ *
22
+ * @param {ComponentWithChildren} [component] - The component to render, which can accept children and props.
23
+ * @param {RendererOptions} [options] - The options for the JSX renderer middleware.
24
+ * @param {boolean | string} [options.docType=true] - The DOCTYPE to be added at the beginning of the HTML. If set to false, no DOCTYPE will be added.
25
+ * @param {boolean | Record<string, string>} [options.stream=false] - If set to true, enables streaming response with default headers. If a record is provided, custom headers will be used.
26
+ * @returns {MiddlewareHandler} The middleware handler function.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const app = new Hono()
31
+ *
32
+ * app.get(
33
+ * '/page/*',
34
+ * jsxRenderer(({ children }) => {
35
+ * return (
36
+ * <html>
37
+ * <body>
38
+ * <header>Menu</header>
39
+ * <div>{children}</div>
40
+ * </body>
41
+ * </html>
42
+ * )
43
+ * })
44
+ * )
45
+ *
46
+ * app.get('/page/about', (c) => {
47
+ * return c.render(<h1>About me!</h1>)
48
+ * })
49
+ * ```
50
+ */
14
51
  export declare const jsxRenderer: (component?: ComponentWithChildren, options?: RendererOptions) => MiddlewareHandler;
52
+ /**
53
+ * useRequestContext for Hono.
54
+ *
55
+ * @template E - The environment type.
56
+ * @template P - The parameter type.
57
+ * @template I - The input type.
58
+ * @returns {Context<E, P, I>} An instance of Context.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const RequestUrlBadge: FC = () => {
63
+ * const c = useRequestContext()
64
+ * return <b>{c.req.url}</b>
65
+ * }
66
+ *
67
+ * app.get('/page/info', (c) => {
68
+ * return c.render(
69
+ * <div>
70
+ * You are accessing: <RequestUrlBadge />
71
+ * </div>
72
+ * )
73
+ * })
74
+ * ```
75
+ */
15
76
  export declare const useRequestContext: <E extends Env = any, P extends string = any, I extends Input = {}>() => Context<E, P, I>;
16
77
  export {};
@@ -1,19 +1,7 @@
1
- import type { MiddlewareHandler } from '../../types';
2
- import '../../context';
3
- import type { SignatureAlgorithm } from '../../utils/jwt/jwa';
4
- declare module '../../context' {
5
- interface ContextVariableMap {
6
- jwtPayload: any;
1
+ import type { JwtVariables } from './jwt';
2
+ export type { JwtVariables };
3
+ export { jwt, verify, decode, sign } from './jwt';
4
+ declare module '../..' {
5
+ interface ContextVariableMap extends JwtVariables {
7
6
  }
8
7
  }
9
- export declare const jwt: (options: {
10
- secret: string;
11
- cookie?: string;
12
- alg?: SignatureAlgorithm;
13
- }) => MiddlewareHandler;
14
- export declare const verify: (token: string, publicKey: import("../../utils/jwt/jws").SignatureKey, alg?: "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "PS256" | "PS384" | "PS512" | "ES256" | "ES384" | "ES512" | "EdDSA") => Promise<import("../../utils/jwt/types").JWTPayload>;
15
- export declare const decode: (token: string) => {
16
- header: import("../../utils/jwt/jwt").TokenHeader;
17
- payload: import("../../utils/jwt/types").JWTPayload;
18
- };
19
- export declare const sign: (payload: import("../../utils/jwt/types").JWTPayload, privateKey: import("../../utils/jwt/jws").SignatureKey, alg?: "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "PS256" | "PS384" | "PS512" | "ES256" | "ES384" | "ES512" | "EdDSA") => Promise<string>;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @module
3
+ * JWT Auth Middleware for Hono.
4
+ */
5
+ import type { MiddlewareHandler } from '../../types';
6
+ import '../../context';
7
+ import type { SignatureAlgorithm } from '../../utils/jwt/jwa';
8
+ export type JwtVariables = {
9
+ jwtPayload: any;
10
+ };
11
+ /**
12
+ * JWT Auth Middleware for Hono.
13
+ *
14
+ * @see {@link https://hono.dev/middleware/builtin/jwt}
15
+ *
16
+ * @param {object} options - The options for the JWT middleware.
17
+ * @param {string} [options.secret] - A value of your secret key.
18
+ * @param {string} [options.cookie] - If this value is set, then the value is retrieved from the cookie header using that value as a key, which is then validated as a token.
19
+ * @param {SignatureAlgorithm} [options.alg=HS256] - An algorithm type that is used for verifying. Available types are `HS256` | `HS384` | `HS512` | `RS256` | `RS384` | `RS512` | `PS256` | `PS384` | `PS512` | `ES256` | `ES384` | `ES512` | `EdDSA`.
20
+ * @returns {MiddlewareHandler} The middleware handler function.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const app = new Hono()
25
+ *
26
+ * app.use(
27
+ * '/auth/*',
28
+ * jwt({
29
+ * secret: 'it-is-very-secret',
30
+ * })
31
+ * )
32
+ *
33
+ * app.get('/auth/page', (c) => {
34
+ * return c.text('You are authorized')
35
+ * })
36
+ * ```
37
+ */
38
+ export declare const jwt: (options: {
39
+ secret: string;
40
+ cookie?: string;
41
+ alg?: SignatureAlgorithm;
42
+ }) => MiddlewareHandler;
43
+ export declare const verify: (token: string, publicKey: import("../../utils/jwt/jws").SignatureKey, alg?: "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "PS256" | "PS384" | "PS512" | "ES256" | "ES384" | "ES512" | "EdDSA") => Promise<import("../../utils/jwt/types").JWTPayload>;
44
+ export declare const decode: (token: string) => {
45
+ header: import("../../utils/jwt/jwt").TokenHeader;
46
+ payload: import("../../utils/jwt/types").JWTPayload;
47
+ };
48
+ export declare const sign: (payload: import("../../utils/jwt/types").JWTPayload, privateKey: import("../../utils/jwt/jws").SignatureKey, alg?: "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "PS256" | "PS384" | "PS512" | "ES256" | "ES384" | "ES512" | "EdDSA") => Promise<string>;
@@ -1,4 +1,24 @@
1
+ /**
2
+ * @module
3
+ * Logger Middleware for Hono.
4
+ */
1
5
  import type { MiddlewareHandler } from '../../types';
2
6
  type PrintFunc = (str: string, ...rest: string[]) => void;
7
+ /**
8
+ * Logger Middleware for Hono.
9
+ *
10
+ * @see {@link https://hono.dev/middleware/builtin/logger}
11
+ *
12
+ * @param {PrintFunc} [fn=console.log] - Optional function for customized logging behavior.
13
+ * @returns {MiddlewareHandler} The middleware handler function.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const app = new Hono()
18
+ *
19
+ * app.use(logger())
20
+ * app.get('/', (c) => c.text('Hello Hono!'))
21
+ * ```
22
+ */
3
23
  export declare const logger: (fn?: PrintFunc) => MiddlewareHandler;
4
24
  export {};
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module
3
+ * Method Override Middleware for Hono.
4
+ */
1
5
  import type { Hono } from '../../hono';
2
6
  import type { MiddlewareHandler } from '../../types';
3
7
  type MethodOverrideOptions = {
@@ -16,21 +20,29 @@ type MethodOverrideOptions = {
16
20
  query: string;
17
21
  });
18
22
  /**
19
- * Method Override Middleware
23
+ * Method Override Middleware for Hono.
24
+ *
25
+ * @see {@link https://hono.dev/middleware/builtin/method-override}
26
+ *
27
+ * @param {MethodOverrideOptions} options - The options for the method override middleware.
28
+ * @param {Hono} options.app - The instance of Hono is used in your application.
29
+ * @param {string} [options.form=_method] - Form key with a value containing the method name.
30
+ * @param {string} [options.header] - Header name with a value containing the method name.
31
+ * @param {string} [options.query] - Query parameter key with a value containing the method name.
32
+ * @returns {MiddlewareHandler} The middleware handler function.
20
33
  *
21
34
  * @example
22
- * // with form input method
35
+ * ```ts
23
36
  * const app = new Hono()
24
- * app.use('/books/*', methodOverride({ app })) // the default `form` value is `_method`
25
- * app.use('/authors/*', methodOverride({ app, form: 'method' }))
26
37
  *
27
- * @example
28
- * // with custom header
29
- * app.use('/books/*', methodOverride({ app, header: 'X-HTTP-METHOD-OVERRIDE' }))
38
+ * // If no options are specified, the value of `_method` in the form,
39
+ * // e.g. DELETE, is used as the method.
40
+ * app.use('/posts', methodOverride({ app }))
30
41
  *
31
- * @example
32
- * // with query parameter
33
- * app.use('/books/*', methodOverride({ app, query: '_method' }))
42
+ * app.delete('/posts', (c) => {
43
+ * // ....
44
+ * })
45
+ * ```
34
46
  */
35
47
  export declare const methodOverride: (options: MethodOverrideOptions) => MiddlewareHandler;
36
48
  export {};
@@ -1,2 +1,6 @@
1
+ /**
2
+ * @module
3
+ * Powered By Middleware for Hono.
4
+ */
1
5
  import type { MiddlewareHandler } from '../../types';
2
6
  export declare const poweredBy: () => MiddlewareHandler;
@@ -1,6 +1,29 @@
1
+ /**
2
+ * @module
3
+ * Pretty JSON Middleware for Hono.
4
+ */
1
5
  import type { MiddlewareHandler } from '../../types';
2
6
  type prettyOptions = {
3
7
  space: number;
4
8
  };
9
+ /**
10
+ * Pretty JSON Middleware for Hono.
11
+ *
12
+ * @see {@link https://hono.dev/middleware/builtin/pretty-json}
13
+ *
14
+ * @param {prettyOptions} [options] - The options for the pretty JSON middleware.
15
+ * @param {number} [options.space=2] - Number of spaces for indentation.
16
+ * @returns {MiddlewareHandler} The middleware handler function.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const app = new Hono()
21
+ *
22
+ * app.use(prettyJSON()) // With options: prettyJSON({ space: 4 })
23
+ * app.get('/', (c) => {
24
+ * return c.json({ message: 'Hono!' })
25
+ * })
26
+ * ```
27
+ */
5
28
  export declare const prettyJSON: (options?: prettyOptions) => MiddlewareHandler;
6
29
  export {};