hono 4.5.10 → 4.5.11
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/README.md +1 -1
- package/dist/cjs/jsx/base.js +1 -1
- package/dist/cjs/jsx/components.js +10 -5
- package/dist/cjs/jsx/intrinsic-element/components.js +15 -3
- package/dist/cjs/middleware/basic-auth/index.js +2 -20
- package/dist/cjs/utils/basic-auth.js +46 -0
- package/dist/cjs/utils/body.js +1 -1
- package/dist/jsx/base.js +1 -1
- package/dist/jsx/components.js +10 -5
- package/dist/jsx/intrinsic-element/components.js +15 -3
- package/dist/middleware/basic-auth/index.js +2 -20
- package/dist/types/middleware/jsx-renderer/index.d.ts +1 -1
- package/dist/types/utils/basic-auth.d.ts +5 -0
- package/dist/utils/basic-auth.js +23 -0
- package/dist/utils/body.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,7 +71,7 @@ Contributions Welcome! You can contribute in the following ways.
|
|
|
71
71
|
- Create an Issue - Propose a new feature. Report a bug.
|
|
72
72
|
- Pull Request - Fix a bug and typo. Refactor the code.
|
|
73
73
|
- Create third-party middleware - Instruct below.
|
|
74
|
-
- Share - Share your thoughts on the Blog,
|
|
74
|
+
- Share - Share your thoughts on the Blog, X, and others.
|
|
75
75
|
- Make your application - Please try to use Hono.
|
|
76
76
|
|
|
77
77
|
For more details, see [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md).
|
package/dist/cjs/jsx/base.js
CHANGED
|
@@ -271,7 +271,7 @@ const jsxFn = (tag, props, children) => {
|
|
|
271
271
|
props,
|
|
272
272
|
children
|
|
273
273
|
);
|
|
274
|
-
} else if (tag === "svg") {
|
|
274
|
+
} else if (tag === "svg" || tag === "head") {
|
|
275
275
|
nameSpaceContext ||= (0, import_context.createContext)("");
|
|
276
276
|
return new JSXNode(tag, props, [
|
|
277
277
|
new JSXFunctionNode(
|
|
@@ -71,11 +71,11 @@ const ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) =>
|
|
|
71
71
|
const index = errorBoundaryCounter++;
|
|
72
72
|
const replaceRe = RegExp(`(<template id="E:${index}"></template>.*?)(.*?)(<!--E:${index}-->)`);
|
|
73
73
|
const caught = false;
|
|
74
|
-
const catchCallback = ({ error, buffer }) => {
|
|
74
|
+
const catchCallback = ({ error: error2, buffer }) => {
|
|
75
75
|
if (caught) {
|
|
76
76
|
return "";
|
|
77
77
|
}
|
|
78
|
-
const fallbackResString = fallbackRes(
|
|
78
|
+
const fallbackResString = fallbackRes(error2);
|
|
79
79
|
if (buffer) {
|
|
80
80
|
buffer[0] = buffer[0].replace(replaceRe, fallbackResString);
|
|
81
81
|
}
|
|
@@ -89,12 +89,17 @@ d.replaceWith(c.content)
|
|
|
89
89
|
})(document)
|
|
90
90
|
<\/script>`;
|
|
91
91
|
};
|
|
92
|
+
let error;
|
|
93
|
+
const promiseAll = Promise.all(resArray).catch((e) => error = e);
|
|
92
94
|
return (0, import_html.raw)(`<template id="E:${index}"></template><!--E:${index}-->`, [
|
|
93
95
|
({ phase, buffer, context }) => {
|
|
94
96
|
if (phase === import_html2.HtmlEscapedCallbackPhase.BeforeStream) {
|
|
95
97
|
return;
|
|
96
98
|
}
|
|
97
|
-
return
|
|
99
|
+
return promiseAll.then(async (htmlArray) => {
|
|
100
|
+
if (error) {
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
98
103
|
htmlArray = htmlArray.flat();
|
|
99
104
|
const content = htmlArray.join("");
|
|
100
105
|
let html = buffer ? "" : `<template data-hono-target="E:${index}">${content}</template><script>
|
|
@@ -150,10 +155,10 @@ d.remove()
|
|
|
150
155
|
<\/script>`),
|
|
151
156
|
content2.callbacks
|
|
152
157
|
);
|
|
153
|
-
}).catch((
|
|
158
|
+
}).catch((error2) => catchCallback({ error: error2, buffer }))
|
|
154
159
|
);
|
|
155
160
|
return (0, import_html.raw)(html, promises);
|
|
156
|
-
}).catch((
|
|
161
|
+
}).catch((error2) => catchCallback({ error: error2, buffer }));
|
|
157
162
|
}
|
|
158
163
|
]);
|
|
159
164
|
} else {
|
|
@@ -107,8 +107,15 @@ const documentMetadataTag = (tag, children, props, sort) => {
|
|
|
107
107
|
};
|
|
108
108
|
const title = ({ children, ...props }) => {
|
|
109
109
|
const nameSpaceContext = (0, import_base.getNameSpaceContext)();
|
|
110
|
-
if (nameSpaceContext
|
|
111
|
-
|
|
110
|
+
if (nameSpaceContext) {
|
|
111
|
+
const context = (0, import_context.useContext)(nameSpaceContext);
|
|
112
|
+
if (context === "svg" || context === "head") {
|
|
113
|
+
return new import_base.JSXNode(
|
|
114
|
+
"title",
|
|
115
|
+
props,
|
|
116
|
+
(0, import_children.toArray)(children ?? [])
|
|
117
|
+
);
|
|
118
|
+
}
|
|
112
119
|
}
|
|
113
120
|
return documentMetadataTag("title", children, props, false);
|
|
114
121
|
};
|
|
@@ -116,7 +123,8 @@ const script = ({
|
|
|
116
123
|
children,
|
|
117
124
|
...props
|
|
118
125
|
}) => {
|
|
119
|
-
|
|
126
|
+
const nameSpaceContext = (0, import_base.getNameSpaceContext)();
|
|
127
|
+
if (["src", "async"].some((k) => !props[k]) || nameSpaceContext && (0, import_context.useContext)(nameSpaceContext) === "head") {
|
|
120
128
|
return returnWithoutSpecialBehavior("script", children, props);
|
|
121
129
|
}
|
|
122
130
|
return documentMetadataTag("script", children, props, false);
|
|
@@ -139,6 +147,10 @@ const link = ({ children, ...props }) => {
|
|
|
139
147
|
return documentMetadataTag("link", children, props, "precedence" in props);
|
|
140
148
|
};
|
|
141
149
|
const meta = ({ children, ...props }) => {
|
|
150
|
+
const nameSpaceContext = (0, import_base.getNameSpaceContext)();
|
|
151
|
+
if (nameSpaceContext && (0, import_context.useContext)(nameSpaceContext) === "head") {
|
|
152
|
+
return returnWithoutSpecialBehavior("meta", children, props);
|
|
153
|
+
}
|
|
142
154
|
return documentMetadataTag("meta", children, props, false);
|
|
143
155
|
};
|
|
144
156
|
const newJSXNode = (tag, { children, ...props }) => new import_base.JSXNode(tag, props, (0, import_children.toArray)(children ?? []));
|
|
@@ -22,26 +22,8 @@ __export(basic_auth_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(basic_auth_exports);
|
|
24
24
|
var import_http_exception = require("../../http-exception");
|
|
25
|
+
var import_basic_auth = require("../../utils/basic-auth");
|
|
25
26
|
var import_buffer = require("../../utils/buffer");
|
|
26
|
-
var import_encode = require("../../utils/encode");
|
|
27
|
-
const CREDENTIALS_REGEXP = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/;
|
|
28
|
-
const USER_PASS_REGEXP = /^([^:]*):(.*)$/;
|
|
29
|
-
const utf8Decoder = new TextDecoder();
|
|
30
|
-
const auth = (req) => {
|
|
31
|
-
const match = CREDENTIALS_REGEXP.exec(req.header("Authorization") || "");
|
|
32
|
-
if (!match) {
|
|
33
|
-
return void 0;
|
|
34
|
-
}
|
|
35
|
-
let userPass = void 0;
|
|
36
|
-
try {
|
|
37
|
-
userPass = USER_PASS_REGEXP.exec(utf8Decoder.decode((0, import_encode.decodeBase64)(match[1])));
|
|
38
|
-
} catch {
|
|
39
|
-
}
|
|
40
|
-
if (!userPass) {
|
|
41
|
-
return void 0;
|
|
42
|
-
}
|
|
43
|
-
return { username: userPass[1], password: userPass[2] };
|
|
44
|
-
};
|
|
45
27
|
const basicAuth = (options, ...users) => {
|
|
46
28
|
const usernamePasswordInOptions = "username" in options && "password" in options;
|
|
47
29
|
const verifyUserInOptions = "verifyUser" in options;
|
|
@@ -57,7 +39,7 @@ const basicAuth = (options, ...users) => {
|
|
|
57
39
|
users.unshift({ username: options.username, password: options.password });
|
|
58
40
|
}
|
|
59
41
|
return async function basicAuth2(ctx, next) {
|
|
60
|
-
const requestUser = auth(ctx.req);
|
|
42
|
+
const requestUser = (0, import_basic_auth.auth)(ctx.req.raw);
|
|
61
43
|
if (requestUser) {
|
|
62
44
|
if (verifyUserInOptions) {
|
|
63
45
|
if (await options.verifyUser(requestUser.username, requestUser.password, ctx)) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var basic_auth_exports = {};
|
|
20
|
+
__export(basic_auth_exports, {
|
|
21
|
+
auth: () => auth
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(basic_auth_exports);
|
|
24
|
+
var import_encode = require("./encode");
|
|
25
|
+
const CREDENTIALS_REGEXP = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/;
|
|
26
|
+
const USER_PASS_REGEXP = /^([^:]*):(.*)$/;
|
|
27
|
+
const utf8Decoder = new TextDecoder();
|
|
28
|
+
const auth = (req) => {
|
|
29
|
+
const match = CREDENTIALS_REGEXP.exec(req.headers.get("Authorization") || "");
|
|
30
|
+
if (!match) {
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
let userPass = void 0;
|
|
34
|
+
try {
|
|
35
|
+
userPass = USER_PASS_REGEXP.exec(utf8Decoder.decode((0, import_encode.decodeBase64)(match[1])));
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
if (!userPass) {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
return { username: userPass[1], password: userPass[2] };
|
|
42
|
+
};
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
auth
|
|
46
|
+
});
|
package/dist/cjs/utils/body.js
CHANGED
|
@@ -26,7 +26,7 @@ const parseBody = async (request, options = /* @__PURE__ */ Object.create(null))
|
|
|
26
26
|
const { all = false, dot = false } = options;
|
|
27
27
|
const headers = request instanceof import_request.HonoRequest ? request.raw.headers : request.headers;
|
|
28
28
|
const contentType = headers.get("Content-Type");
|
|
29
|
-
if (contentType
|
|
29
|
+
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
30
30
|
return parseFormData(request, { all, dot });
|
|
31
31
|
}
|
|
32
32
|
return {};
|
package/dist/jsx/base.js
CHANGED
|
@@ -234,7 +234,7 @@ var jsxFn = (tag, props, children) => {
|
|
|
234
234
|
props,
|
|
235
235
|
children
|
|
236
236
|
);
|
|
237
|
-
} else if (tag === "svg") {
|
|
237
|
+
} else if (tag === "svg" || tag === "head") {
|
|
238
238
|
nameSpaceContext ||= createContext("");
|
|
239
239
|
return new JSXNode(tag, props, [
|
|
240
240
|
new JSXFunctionNode(
|
package/dist/jsx/components.js
CHANGED
|
@@ -48,11 +48,11 @@ var ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) => {
|
|
|
48
48
|
const index = errorBoundaryCounter++;
|
|
49
49
|
const replaceRe = RegExp(`(<template id="E:${index}"></template>.*?)(.*?)(<!--E:${index}-->)`);
|
|
50
50
|
const caught = false;
|
|
51
|
-
const catchCallback = ({ error, buffer }) => {
|
|
51
|
+
const catchCallback = ({ error: error2, buffer }) => {
|
|
52
52
|
if (caught) {
|
|
53
53
|
return "";
|
|
54
54
|
}
|
|
55
|
-
const fallbackResString = fallbackRes(
|
|
55
|
+
const fallbackResString = fallbackRes(error2);
|
|
56
56
|
if (buffer) {
|
|
57
57
|
buffer[0] = buffer[0].replace(replaceRe, fallbackResString);
|
|
58
58
|
}
|
|
@@ -66,12 +66,17 @@ d.replaceWith(c.content)
|
|
|
66
66
|
})(document)
|
|
67
67
|
<\/script>`;
|
|
68
68
|
};
|
|
69
|
+
let error;
|
|
70
|
+
const promiseAll = Promise.all(resArray).catch((e) => error = e);
|
|
69
71
|
return raw(`<template id="E:${index}"></template><!--E:${index}-->`, [
|
|
70
72
|
({ phase, buffer, context }) => {
|
|
71
73
|
if (phase === HtmlEscapedCallbackPhase.BeforeStream) {
|
|
72
74
|
return;
|
|
73
75
|
}
|
|
74
|
-
return
|
|
76
|
+
return promiseAll.then(async (htmlArray) => {
|
|
77
|
+
if (error) {
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
75
80
|
htmlArray = htmlArray.flat();
|
|
76
81
|
const content = htmlArray.join("");
|
|
77
82
|
let html = buffer ? "" : `<template data-hono-target="E:${index}">${content}</template><script>
|
|
@@ -127,10 +132,10 @@ d.remove()
|
|
|
127
132
|
<\/script>`),
|
|
128
133
|
content2.callbacks
|
|
129
134
|
);
|
|
130
|
-
}).catch((
|
|
135
|
+
}).catch((error2) => catchCallback({ error: error2, buffer }))
|
|
131
136
|
);
|
|
132
137
|
return raw(html, promises);
|
|
133
|
-
}).catch((
|
|
138
|
+
}).catch((error2) => catchCallback({ error: error2, buffer }));
|
|
134
139
|
}
|
|
135
140
|
]);
|
|
136
141
|
} else {
|
|
@@ -78,8 +78,15 @@ var documentMetadataTag = (tag, children, props, sort) => {
|
|
|
78
78
|
};
|
|
79
79
|
var title = ({ children, ...props }) => {
|
|
80
80
|
const nameSpaceContext = getNameSpaceContext();
|
|
81
|
-
if (nameSpaceContext
|
|
82
|
-
|
|
81
|
+
if (nameSpaceContext) {
|
|
82
|
+
const context = useContext(nameSpaceContext);
|
|
83
|
+
if (context === "svg" || context === "head") {
|
|
84
|
+
return new JSXNode(
|
|
85
|
+
"title",
|
|
86
|
+
props,
|
|
87
|
+
toArray(children ?? [])
|
|
88
|
+
);
|
|
89
|
+
}
|
|
83
90
|
}
|
|
84
91
|
return documentMetadataTag("title", children, props, false);
|
|
85
92
|
};
|
|
@@ -87,7 +94,8 @@ var script = ({
|
|
|
87
94
|
children,
|
|
88
95
|
...props
|
|
89
96
|
}) => {
|
|
90
|
-
|
|
97
|
+
const nameSpaceContext = getNameSpaceContext();
|
|
98
|
+
if (["src", "async"].some((k) => !props[k]) || nameSpaceContext && useContext(nameSpaceContext) === "head") {
|
|
91
99
|
return returnWithoutSpecialBehavior("script", children, props);
|
|
92
100
|
}
|
|
93
101
|
return documentMetadataTag("script", children, props, false);
|
|
@@ -110,6 +118,10 @@ var link = ({ children, ...props }) => {
|
|
|
110
118
|
return documentMetadataTag("link", children, props, "precedence" in props);
|
|
111
119
|
};
|
|
112
120
|
var meta = ({ children, ...props }) => {
|
|
121
|
+
const nameSpaceContext = getNameSpaceContext();
|
|
122
|
+
if (nameSpaceContext && useContext(nameSpaceContext) === "head") {
|
|
123
|
+
return returnWithoutSpecialBehavior("meta", children, props);
|
|
124
|
+
}
|
|
113
125
|
return documentMetadataTag("meta", children, props, false);
|
|
114
126
|
};
|
|
115
127
|
var newJSXNode = (tag, { children, ...props }) => new JSXNode(tag, props, toArray(children ?? []));
|
|
@@ -1,25 +1,7 @@
|
|
|
1
1
|
// src/middleware/basic-auth/index.ts
|
|
2
2
|
import { HTTPException } from "../../http-exception.js";
|
|
3
|
+
import { auth } from "../../utils/basic-auth.js";
|
|
3
4
|
import { timingSafeEqual } from "../../utils/buffer.js";
|
|
4
|
-
import { decodeBase64 } from "../../utils/encode.js";
|
|
5
|
-
var CREDENTIALS_REGEXP = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/;
|
|
6
|
-
var USER_PASS_REGEXP = /^([^:]*):(.*)$/;
|
|
7
|
-
var utf8Decoder = new TextDecoder();
|
|
8
|
-
var auth = (req) => {
|
|
9
|
-
const match = CREDENTIALS_REGEXP.exec(req.header("Authorization") || "");
|
|
10
|
-
if (!match) {
|
|
11
|
-
return void 0;
|
|
12
|
-
}
|
|
13
|
-
let userPass = void 0;
|
|
14
|
-
try {
|
|
15
|
-
userPass = USER_PASS_REGEXP.exec(utf8Decoder.decode(decodeBase64(match[1])));
|
|
16
|
-
} catch {
|
|
17
|
-
}
|
|
18
|
-
if (!userPass) {
|
|
19
|
-
return void 0;
|
|
20
|
-
}
|
|
21
|
-
return { username: userPass[1], password: userPass[2] };
|
|
22
|
-
};
|
|
23
5
|
var basicAuth = (options, ...users) => {
|
|
24
6
|
const usernamePasswordInOptions = "username" in options && "password" in options;
|
|
25
7
|
const verifyUserInOptions = "verifyUser" in options;
|
|
@@ -35,7 +17,7 @@ var basicAuth = (options, ...users) => {
|
|
|
35
17
|
users.unshift({ username: options.username, password: options.password });
|
|
36
18
|
}
|
|
37
19
|
return async function basicAuth2(ctx, next) {
|
|
38
|
-
const requestUser = auth(ctx.req);
|
|
20
|
+
const requestUser = auth(ctx.req.raw);
|
|
39
21
|
if (requestUser) {
|
|
40
22
|
if (verifyUserInOptions) {
|
|
41
23
|
if (await options.verifyUser(requestUser.username, requestUser.password, ctx)) {
|
|
@@ -17,7 +17,7 @@ type ComponentWithChildren = (props: PropsWithChildren<PropsForRenderer & {
|
|
|
17
17
|
/**
|
|
18
18
|
* JSX Renderer Middleware for hono.
|
|
19
19
|
*
|
|
20
|
-
* @see {@link
|
|
20
|
+
* @see {@link https://hono.dev/docs/middleware/builtin/jsx-renderer}
|
|
21
21
|
*
|
|
22
22
|
* @param {ComponentWithChildren} [component] - The component to render, which can accept children and props.
|
|
23
23
|
* @param {RendererOptions} [options] - The options for the JSX renderer middleware.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/utils/basic-auth.ts
|
|
2
|
+
import { decodeBase64 } from "./encode.js";
|
|
3
|
+
var CREDENTIALS_REGEXP = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/;
|
|
4
|
+
var USER_PASS_REGEXP = /^([^:]*):(.*)$/;
|
|
5
|
+
var utf8Decoder = new TextDecoder();
|
|
6
|
+
var auth = (req) => {
|
|
7
|
+
const match = CREDENTIALS_REGEXP.exec(req.headers.get("Authorization") || "");
|
|
8
|
+
if (!match) {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
let userPass = void 0;
|
|
12
|
+
try {
|
|
13
|
+
userPass = USER_PASS_REGEXP.exec(utf8Decoder.decode(decodeBase64(match[1])));
|
|
14
|
+
} catch {
|
|
15
|
+
}
|
|
16
|
+
if (!userPass) {
|
|
17
|
+
return void 0;
|
|
18
|
+
}
|
|
19
|
+
return { username: userPass[1], password: userPass[2] };
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
auth
|
|
23
|
+
};
|
package/dist/utils/body.js
CHANGED
|
@@ -4,7 +4,7 @@ var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) =
|
|
|
4
4
|
const { all = false, dot = false } = options;
|
|
5
5
|
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
6
6
|
const contentType = headers.get("Content-Type");
|
|
7
|
-
if (contentType
|
|
7
|
+
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
8
8
|
return parseFormData(request, { all, dot });
|
|
9
9
|
}
|
|
10
10
|
return {};
|