hono 4.6.20 → 4.7.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.
- package/dist/cjs/helper/accepts/accepts.js +4 -26
- package/dist/cjs/helper/factory/index.js +6 -2
- package/dist/cjs/helper/proxy/index.js +75 -0
- package/dist/cjs/middleware/etag/digest.js +2 -7
- package/dist/cjs/middleware/etag/index.js +7 -2
- package/dist/cjs/middleware/jwk/index.js +28 -0
- package/dist/cjs/middleware/jwk/jwk.js +124 -0
- package/dist/cjs/middleware/language/index.js +36 -0
- package/dist/cjs/middleware/language/language.js +210 -0
- package/dist/cjs/middleware/logger/index.js +2 -3
- package/dist/cjs/request.js +1 -1
- package/dist/cjs/router/linear-router/router.js +3 -1
- package/dist/cjs/router/trie-router/node.js +24 -11
- package/dist/cjs/utils/accept.js +86 -0
- package/dist/cjs/utils/jwt/index.js +1 -1
- package/dist/cjs/utils/jwt/jwt.js +56 -3
- package/dist/cjs/utils/jwt/types.js +8 -0
- package/dist/cjs/utils/url.js +6 -5
- package/dist/helper/accepts/accepts.js +2 -23
- package/dist/helper/factory/index.js +6 -2
- package/dist/helper/proxy/index.js +52 -0
- package/dist/middleware/etag/digest.js +2 -7
- package/dist/middleware/etag/index.js +7 -2
- package/dist/middleware/jwk/index.js +5 -0
- package/dist/middleware/jwk/jwk.js +101 -0
- package/dist/middleware/language/index.js +15 -0
- package/dist/middleware/language/language.js +178 -0
- package/dist/middleware/logger/index.js +2 -3
- package/dist/request.js +1 -1
- package/dist/router/linear-router/router.js +3 -1
- package/dist/router/trie-router/node.js +24 -11
- package/dist/types/adapter/cloudflare-pages/handler.d.ts +1 -1
- package/dist/types/adapter/cloudflare-workers/websocket.d.ts +1 -1
- package/dist/types/adapter/lambda-edge/handler.d.ts +2 -2
- package/dist/types/client/types.d.ts +7 -8
- package/dist/types/compose.d.ts +11 -1
- package/dist/types/context.d.ts +31 -21
- package/dist/types/helper/accepts/accepts.d.ts +0 -1
- package/dist/types/helper/adapter/index.d.ts +2 -2
- package/dist/types/helper/conninfo/types.d.ts +2 -2
- package/dist/types/helper/css/common.d.ts +6 -1
- package/dist/types/helper/factory/index.d.ts +289 -12
- package/dist/types/helper/proxy/index.d.ts +54 -0
- package/dist/types/helper/ssg/ssg.d.ts +1 -1
- package/dist/types/helper/websocket/index.d.ts +1 -2
- package/dist/types/hono-base.d.ts +18 -15
- package/dist/types/hono.d.ts +1 -1
- package/dist/types/jsx/base.d.ts +4 -1
- package/dist/types/jsx/dom/hooks/index.d.ts +9 -3
- package/dist/types/jsx/dom/index.d.ts +28 -7
- package/dist/types/jsx/dom/intrinsic-element/components.d.ts +6 -6
- package/dist/types/jsx/dom/render.d.ts +28 -4
- package/dist/types/jsx/dom/server.d.ts +28 -7
- package/dist/types/jsx/hooks/index.d.ts +20 -5
- package/dist/types/jsx/index.d.ts +28 -7
- package/dist/types/jsx/intrinsic-element/components.d.ts +4 -4
- package/dist/types/jsx/intrinsic-elements.d.ts +46 -46
- package/dist/types/middleware/compress/index.d.ts +4 -1
- package/dist/types/middleware/etag/digest.d.ts +1 -1
- package/dist/types/middleware/etag/index.d.ts +4 -0
- package/dist/types/middleware/jwk/index.d.ts +1 -0
- package/dist/types/middleware/jwk/jwk.d.ts +40 -0
- package/dist/types/middleware/language/index.d.ts +7 -0
- package/dist/types/middleware/language/language.d.ts +102 -0
- package/dist/types/middleware/secure-headers/permissions-policy.d.ts +3 -3
- package/dist/types/middleware/secure-headers/secure-headers.d.ts +1 -1
- package/dist/types/preset/quick.d.ts +1 -1
- package/dist/types/preset/tiny.d.ts +1 -1
- package/dist/types/request.d.ts +5 -3
- package/dist/types/router/linear-router/router.d.ts +0 -1
- package/dist/types/router/pattern-router/router.d.ts +0 -1
- package/dist/types/router/reg-exp-router/node.d.ts +4 -2
- package/dist/types/router/reg-exp-router/router.d.ts +0 -1
- package/dist/types/router/reg-exp-router/trie.d.ts +5 -2
- package/dist/types/router/smart-router/router.d.ts +0 -1
- package/dist/types/router/trie-router/node.d.ts +6 -2
- package/dist/types/router/trie-router/router.d.ts +0 -1
- package/dist/types/router.d.ts +20 -2
- package/dist/types/types.d.ts +2002 -111
- package/dist/types/utils/accept.d.ts +11 -0
- package/dist/types/utils/cookie.d.ts +4 -4
- package/dist/types/utils/headers.d.ts +3 -3
- package/dist/types/utils/html.d.ts +6 -2
- package/dist/types/utils/jwt/index.d.ts +4 -0
- package/dist/types/utils/jwt/jws.d.ts +4 -1
- package/dist/types/utils/jwt/jwt.d.ts +8 -2
- package/dist/types/utils/jwt/types.d.ts +4 -0
- package/dist/types/utils/mime.d.ts +2 -2
- package/dist/types/utils/stream.d.ts +0 -4
- package/dist/types/utils/url.d.ts +6 -2
- package/dist/types/validator/validator.d.ts +18 -6
- package/dist/utils/accept.js +63 -0
- package/dist/utils/jwt/index.js +2 -2
- package/dist/utils/jwt/jwt.js +54 -2
- package/dist/utils/jwt/types.js +7 -0
- package/dist/utils/url.js +6 -5
- package/package.json +24 -3
|
@@ -19,31 +19,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var accepts_exports = {};
|
|
20
20
|
__export(accepts_exports, {
|
|
21
21
|
accepts: () => accepts,
|
|
22
|
-
defaultMatch: () => defaultMatch
|
|
23
|
-
parseAccept: () => parseAccept
|
|
22
|
+
defaultMatch: () => defaultMatch
|
|
24
23
|
});
|
|
25
24
|
module.exports = __toCommonJS(accepts_exports);
|
|
26
|
-
|
|
27
|
-
const accepts2 = acceptHeader.split(",");
|
|
28
|
-
return accepts2.map((accept) => {
|
|
29
|
-
const parts = accept.trim().split(";");
|
|
30
|
-
const type = parts[0];
|
|
31
|
-
const params = parts.slice(1);
|
|
32
|
-
const q = params.find((param) => param.startsWith("q="));
|
|
33
|
-
const paramsObject = params.reduce((acc, param) => {
|
|
34
|
-
const keyValue = param.split("=");
|
|
35
|
-
const key = keyValue[0].trim();
|
|
36
|
-
const value = keyValue[1].trim();
|
|
37
|
-
acc[key] = value;
|
|
38
|
-
return acc;
|
|
39
|
-
}, {});
|
|
40
|
-
return {
|
|
41
|
-
type,
|
|
42
|
-
params: paramsObject,
|
|
43
|
-
q: q ? parseFloat(q.split("=")[1]) : 1
|
|
44
|
-
};
|
|
45
|
-
});
|
|
46
|
-
};
|
|
25
|
+
var import_accept = require("../../utils/accept");
|
|
47
26
|
const defaultMatch = (accepts2, config) => {
|
|
48
27
|
const { supports, default: defaultSupport } = config;
|
|
49
28
|
const accept = accepts2.sort((a, b) => b.q - a.q).find((accept2) => supports.includes(accept2.type));
|
|
@@ -54,13 +33,12 @@ const accepts = (c, options) => {
|
|
|
54
33
|
if (!acceptHeader) {
|
|
55
34
|
return options.default;
|
|
56
35
|
}
|
|
57
|
-
const accepts2 = parseAccept(acceptHeader);
|
|
36
|
+
const accepts2 = (0, import_accept.parseAccept)(acceptHeader);
|
|
58
37
|
const match = options.match || defaultMatch;
|
|
59
38
|
return match(accepts2, options);
|
|
60
39
|
};
|
|
61
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
62
41
|
0 && (module.exports = {
|
|
63
42
|
accepts,
|
|
64
|
-
defaultMatch
|
|
65
|
-
parseAccept
|
|
43
|
+
defaultMatch
|
|
66
44
|
});
|
|
@@ -26,11 +26,15 @@ module.exports = __toCommonJS(factory_exports);
|
|
|
26
26
|
var import_hono = require("../../hono");
|
|
27
27
|
class Factory {
|
|
28
28
|
initApp;
|
|
29
|
+
#defaultAppOptions;
|
|
29
30
|
constructor(init) {
|
|
30
31
|
this.initApp = init?.initApp;
|
|
32
|
+
this.#defaultAppOptions = init?.defaultAppOptions;
|
|
31
33
|
}
|
|
32
|
-
createApp = () => {
|
|
33
|
-
const app = new import_hono.Hono(
|
|
34
|
+
createApp = (options) => {
|
|
35
|
+
const app = new import_hono.Hono(
|
|
36
|
+
options && this.#defaultAppOptions ? { ...this.#defaultAppOptions, ...options } : options ?? this.#defaultAppOptions
|
|
37
|
+
);
|
|
34
38
|
if (this.initApp) {
|
|
35
39
|
this.initApp(app);
|
|
36
40
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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 proxy_exports = {};
|
|
20
|
+
__export(proxy_exports, {
|
|
21
|
+
proxy: () => proxy
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(proxy_exports);
|
|
24
|
+
const hopByHopHeaders = [
|
|
25
|
+
"connection",
|
|
26
|
+
"keep-alive",
|
|
27
|
+
"proxy-authenticate",
|
|
28
|
+
"proxy-authorization",
|
|
29
|
+
"te",
|
|
30
|
+
"trailers",
|
|
31
|
+
"transfer-encoding"
|
|
32
|
+
];
|
|
33
|
+
const buildRequestInitFromRequest = (request) => {
|
|
34
|
+
if (!request) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
const headers = new Headers(request.headers);
|
|
38
|
+
hopByHopHeaders.forEach((header) => {
|
|
39
|
+
headers.delete(header);
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
method: request.method,
|
|
43
|
+
body: request.body,
|
|
44
|
+
duplex: request.body ? "half" : void 0,
|
|
45
|
+
headers
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const proxy = async (input, proxyInit) => {
|
|
49
|
+
const { raw, ...requestInit } = proxyInit ?? {};
|
|
50
|
+
const req = new Request(
|
|
51
|
+
input,
|
|
52
|
+
{
|
|
53
|
+
...buildRequestInitFromRequest(raw),
|
|
54
|
+
...requestInit
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
req.headers.delete("accept-encoding");
|
|
58
|
+
const res = await fetch(req);
|
|
59
|
+
const resHeaders = new Headers(res.headers);
|
|
60
|
+
hopByHopHeaders.forEach((header) => {
|
|
61
|
+
resHeaders.delete(header);
|
|
62
|
+
});
|
|
63
|
+
if (resHeaders.has("content-encoding")) {
|
|
64
|
+
resHeaders.delete("content-encoding");
|
|
65
|
+
resHeaders.delete("content-length");
|
|
66
|
+
}
|
|
67
|
+
return new Response(res.body, {
|
|
68
|
+
...res,
|
|
69
|
+
headers: resHeaders
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
proxy
|
|
75
|
+
});
|
|
@@ -30,7 +30,7 @@ const mergeBuffers = (buffer1, buffer2) => {
|
|
|
30
30
|
merged.set(buffer2, buffer1.byteLength);
|
|
31
31
|
return merged;
|
|
32
32
|
};
|
|
33
|
-
const generateDigest = async (stream) => {
|
|
33
|
+
const generateDigest = async (stream, generator) => {
|
|
34
34
|
if (!stream || !crypto || !crypto.subtle) {
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
@@ -41,12 +41,7 @@ const generateDigest = async (stream) => {
|
|
|
41
41
|
if (done) {
|
|
42
42
|
break;
|
|
43
43
|
}
|
|
44
|
-
result = await
|
|
45
|
-
{
|
|
46
|
-
name: "SHA-1"
|
|
47
|
-
},
|
|
48
|
-
mergeBuffers(result, value)
|
|
49
|
-
);
|
|
44
|
+
result = await generator(mergeBuffers(result, value));
|
|
50
45
|
}
|
|
51
46
|
if (!result) {
|
|
52
47
|
return null;
|
|
@@ -37,20 +37,25 @@ function etagMatches(etag2, ifNoneMatch) {
|
|
|
37
37
|
const etag = (options) => {
|
|
38
38
|
const retainedHeaders = options?.retainedHeaders ?? RETAINED_304_HEADERS;
|
|
39
39
|
const weak = options?.weak ?? false;
|
|
40
|
+
const generator = options?.generateDigest ?? ((body) => crypto.subtle.digest(
|
|
41
|
+
{
|
|
42
|
+
name: "SHA-1"
|
|
43
|
+
},
|
|
44
|
+
body
|
|
45
|
+
));
|
|
40
46
|
return async function etag2(c, next) {
|
|
41
47
|
const ifNoneMatch = c.req.header("If-None-Match") ?? null;
|
|
42
48
|
await next();
|
|
43
49
|
const res = c.res;
|
|
44
50
|
let etag3 = res.headers.get("ETag");
|
|
45
51
|
if (!etag3) {
|
|
46
|
-
const hash = await (0, import_digest.generateDigest)(res.clone().body);
|
|
52
|
+
const hash = await (0, import_digest.generateDigest)(res.clone().body, generator);
|
|
47
53
|
if (hash === null) {
|
|
48
54
|
return;
|
|
49
55
|
}
|
|
50
56
|
etag3 = weak ? `W/"${hash}"` : `"${hash}"`;
|
|
51
57
|
}
|
|
52
58
|
if (etagMatches(etag3, ifNoneMatch)) {
|
|
53
|
-
await c.res.blob();
|
|
54
59
|
c.res = new Response(null, {
|
|
55
60
|
status: 304,
|
|
56
61
|
statusText: "Not Modified",
|
|
@@ -0,0 +1,28 @@
|
|
|
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 jwk_exports = {};
|
|
20
|
+
__export(jwk_exports, {
|
|
21
|
+
jwk: () => import_jwk.jwk
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(jwk_exports);
|
|
24
|
+
var import_jwk = require("./jwk");
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
jwk
|
|
28
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
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 jwk_exports = {};
|
|
20
|
+
__export(jwk_exports, {
|
|
21
|
+
jwk: () => jwk
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(jwk_exports);
|
|
24
|
+
var import_cookie = require("../../helper/cookie");
|
|
25
|
+
var import_http_exception = require("../../http-exception");
|
|
26
|
+
var import_jwt = require("../../utils/jwt");
|
|
27
|
+
var import_context = require("../../context");
|
|
28
|
+
const jwk = (options, init) => {
|
|
29
|
+
if (!options || !(options.keys || options.jwks_uri)) {
|
|
30
|
+
throw new Error('JWK auth middleware requires options for either "keys" or "jwks_uri" or both');
|
|
31
|
+
}
|
|
32
|
+
if (!crypto.subtle || !crypto.subtle.importKey) {
|
|
33
|
+
throw new Error("`crypto.subtle.importKey` is undefined. JWK auth middleware requires it.");
|
|
34
|
+
}
|
|
35
|
+
return async function jwk2(ctx, next) {
|
|
36
|
+
const credentials = ctx.req.raw.headers.get("Authorization");
|
|
37
|
+
let token;
|
|
38
|
+
if (credentials) {
|
|
39
|
+
const parts = credentials.split(/\s+/);
|
|
40
|
+
if (parts.length !== 2) {
|
|
41
|
+
const errDescription = "invalid credentials structure";
|
|
42
|
+
throw new import_http_exception.HTTPException(401, {
|
|
43
|
+
message: errDescription,
|
|
44
|
+
res: unauthorizedResponse({
|
|
45
|
+
ctx,
|
|
46
|
+
error: "invalid_request",
|
|
47
|
+
errDescription
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
token = parts[1];
|
|
52
|
+
}
|
|
53
|
+
} else if (options.cookie) {
|
|
54
|
+
if (typeof options.cookie == "string") {
|
|
55
|
+
token = (0, import_cookie.getCookie)(ctx, options.cookie);
|
|
56
|
+
} else if (options.cookie.secret) {
|
|
57
|
+
if (options.cookie.prefixOptions) {
|
|
58
|
+
token = await (0, import_cookie.getSignedCookie)(
|
|
59
|
+
ctx,
|
|
60
|
+
options.cookie.secret,
|
|
61
|
+
options.cookie.key,
|
|
62
|
+
options.cookie.prefixOptions
|
|
63
|
+
);
|
|
64
|
+
} else {
|
|
65
|
+
token = await (0, import_cookie.getSignedCookie)(ctx, options.cookie.secret, options.cookie.key);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
if (options.cookie.prefixOptions) {
|
|
69
|
+
token = (0, import_cookie.getCookie)(ctx, options.cookie.key, options.cookie.prefixOptions);
|
|
70
|
+
} else {
|
|
71
|
+
token = (0, import_cookie.getCookie)(ctx, options.cookie.key);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!token) {
|
|
76
|
+
const errDescription = "no authorization included in request";
|
|
77
|
+
throw new import_http_exception.HTTPException(401, {
|
|
78
|
+
message: errDescription,
|
|
79
|
+
res: unauthorizedResponse({
|
|
80
|
+
ctx,
|
|
81
|
+
error: "invalid_request",
|
|
82
|
+
errDescription
|
|
83
|
+
})
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
let payload;
|
|
87
|
+
let cause;
|
|
88
|
+
try {
|
|
89
|
+
payload = await import_jwt.Jwt.verifyFromJwks(token, options, init);
|
|
90
|
+
} catch (e) {
|
|
91
|
+
cause = e;
|
|
92
|
+
}
|
|
93
|
+
if (!payload) {
|
|
94
|
+
if (cause instanceof Error && cause.constructor === Error) {
|
|
95
|
+
throw cause;
|
|
96
|
+
}
|
|
97
|
+
throw new import_http_exception.HTTPException(401, {
|
|
98
|
+
message: "Unauthorized",
|
|
99
|
+
res: unauthorizedResponse({
|
|
100
|
+
ctx,
|
|
101
|
+
error: "invalid_token",
|
|
102
|
+
statusText: "Unauthorized",
|
|
103
|
+
errDescription: "token verification failure"
|
|
104
|
+
}),
|
|
105
|
+
cause
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
ctx.set("jwtPayload", payload);
|
|
109
|
+
await next();
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
function unauthorizedResponse(opts) {
|
|
113
|
+
return new Response("Unauthorized", {
|
|
114
|
+
status: 401,
|
|
115
|
+
statusText: opts.statusText,
|
|
116
|
+
headers: {
|
|
117
|
+
"WWW-Authenticate": `Bearer realm="${opts.ctx.req.url}",error="${opts.error}",error_description="${opts.errDescription}"`
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
jwk
|
|
124
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
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 language_exports = {};
|
|
20
|
+
__export(language_exports, {
|
|
21
|
+
detectFromCookie: () => import_language.detectFromCookie,
|
|
22
|
+
detectFromHeader: () => import_language.detectFromHeader,
|
|
23
|
+
detectFromPath: () => import_language.detectFromPath,
|
|
24
|
+
detectFromQuery: () => import_language.detectFromQuery,
|
|
25
|
+
languageDetector: () => import_language.languageDetector
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(language_exports);
|
|
28
|
+
var import_language = require("./language");
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
detectFromCookie,
|
|
32
|
+
detectFromHeader,
|
|
33
|
+
detectFromPath,
|
|
34
|
+
detectFromQuery,
|
|
35
|
+
languageDetector
|
|
36
|
+
});
|
|
@@ -0,0 +1,210 @@
|
|
|
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 language_exports = {};
|
|
20
|
+
__export(language_exports, {
|
|
21
|
+
DEFAULT_OPTIONS: () => DEFAULT_OPTIONS,
|
|
22
|
+
detectFromCookie: () => detectFromCookie,
|
|
23
|
+
detectFromHeader: () => detectFromHeader,
|
|
24
|
+
detectFromPath: () => detectFromPath,
|
|
25
|
+
detectFromQuery: () => detectFromQuery,
|
|
26
|
+
detectors: () => detectors,
|
|
27
|
+
languageDetector: () => languageDetector,
|
|
28
|
+
normalizeLanguage: () => normalizeLanguage,
|
|
29
|
+
parseAcceptLanguage: () => parseAcceptLanguage,
|
|
30
|
+
validateOptions: () => validateOptions
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(language_exports);
|
|
33
|
+
var import_cookie = require("../../helper/cookie");
|
|
34
|
+
var import_accept = require("../../utils/accept");
|
|
35
|
+
const DEFAULT_OPTIONS = {
|
|
36
|
+
order: ["querystring", "cookie", "header"],
|
|
37
|
+
lookupQueryString: "lang",
|
|
38
|
+
lookupCookie: "language",
|
|
39
|
+
lookupFromHeaderKey: "accept-language",
|
|
40
|
+
lookupFromPathIndex: 0,
|
|
41
|
+
caches: ["cookie"],
|
|
42
|
+
ignoreCase: true,
|
|
43
|
+
fallbackLanguage: "en",
|
|
44
|
+
supportedLanguages: ["en"],
|
|
45
|
+
cookieOptions: {
|
|
46
|
+
sameSite: "Strict",
|
|
47
|
+
secure: true,
|
|
48
|
+
maxAge: 365 * 24 * 60 * 60,
|
|
49
|
+
httpOnly: true
|
|
50
|
+
},
|
|
51
|
+
debug: false
|
|
52
|
+
};
|
|
53
|
+
function parseAcceptLanguage(header) {
|
|
54
|
+
return (0, import_accept.parseAccept)(header).map(({ type, q }) => ({ lang: type, q }));
|
|
55
|
+
}
|
|
56
|
+
const normalizeLanguage = (lang, options) => {
|
|
57
|
+
if (!lang) {
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
let normalizedLang = lang.trim();
|
|
62
|
+
if (options.convertDetectedLanguage) {
|
|
63
|
+
normalizedLang = options.convertDetectedLanguage(normalizedLang);
|
|
64
|
+
}
|
|
65
|
+
const compLang = options.ignoreCase ? normalizedLang.toLowerCase() : normalizedLang;
|
|
66
|
+
const compSupported = options.supportedLanguages.map(
|
|
67
|
+
(l) => options.ignoreCase ? l.toLowerCase() : l
|
|
68
|
+
);
|
|
69
|
+
const matchedLang = compSupported.find((l) => l === compLang);
|
|
70
|
+
return matchedLang ? options.supportedLanguages[compSupported.indexOf(matchedLang)] : void 0;
|
|
71
|
+
} catch {
|
|
72
|
+
return void 0;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const detectFromQuery = (c, options) => {
|
|
76
|
+
try {
|
|
77
|
+
const query = c.req.query(options.lookupQueryString);
|
|
78
|
+
return normalizeLanguage(query, options);
|
|
79
|
+
} catch {
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const detectFromCookie = (c, options) => {
|
|
84
|
+
try {
|
|
85
|
+
const cookie = (0, import_cookie.getCookie)(c, options.lookupCookie);
|
|
86
|
+
return normalizeLanguage(cookie, options);
|
|
87
|
+
} catch {
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
function detectFromHeader(c, options) {
|
|
92
|
+
try {
|
|
93
|
+
const acceptLanguage = c.req.header(options.lookupFromHeaderKey);
|
|
94
|
+
if (!acceptLanguage) {
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
const languages = parseAcceptLanguage(acceptLanguage);
|
|
98
|
+
for (const { lang } of languages) {
|
|
99
|
+
const normalizedLang = normalizeLanguage(lang, options);
|
|
100
|
+
if (normalizedLang) {
|
|
101
|
+
return normalizedLang;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return void 0;
|
|
105
|
+
} catch {
|
|
106
|
+
return void 0;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function detectFromPath(c, options) {
|
|
110
|
+
try {
|
|
111
|
+
const pathSegments = c.req.path.split("/").filter(Boolean);
|
|
112
|
+
const langSegment = pathSegments[options.lookupFromPathIndex];
|
|
113
|
+
return normalizeLanguage(langSegment, options);
|
|
114
|
+
} catch {
|
|
115
|
+
return void 0;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const detectors = {
|
|
119
|
+
querystring: detectFromQuery,
|
|
120
|
+
cookie: detectFromCookie,
|
|
121
|
+
header: detectFromHeader,
|
|
122
|
+
path: detectFromPath
|
|
123
|
+
};
|
|
124
|
+
function validateOptions(options) {
|
|
125
|
+
if (!options.supportedLanguages.includes(options.fallbackLanguage)) {
|
|
126
|
+
throw new Error("Fallback language must be included in supported languages");
|
|
127
|
+
}
|
|
128
|
+
if (options.lookupFromPathIndex < 0) {
|
|
129
|
+
throw new Error("Path index must be non-negative");
|
|
130
|
+
}
|
|
131
|
+
if (!options.order.every((detector) => Object.keys(detectors).includes(detector))) {
|
|
132
|
+
throw new Error("Invalid detector type in order array");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function cacheLanguage(c, language, options) {
|
|
136
|
+
if (!Array.isArray(options.caches) || !options.caches.includes("cookie")) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
(0, import_cookie.setCookie)(c, options.lookupCookie, language, options.cookieOptions);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (options.debug) {
|
|
143
|
+
console.error("Failed to cache language:", error);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const detectLanguage = (c, options) => {
|
|
148
|
+
let detectedLang;
|
|
149
|
+
for (const detectorName of options.order) {
|
|
150
|
+
const detector = detectors[detectorName];
|
|
151
|
+
if (!detector) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
detectedLang = detector(c, options);
|
|
156
|
+
if (detectedLang) {
|
|
157
|
+
if (options.debug) {
|
|
158
|
+
console.log(`Language detected from ${detectorName}: ${detectedLang}`);
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (options.debug) {
|
|
164
|
+
console.error(`Error in ${detectorName} detector:`, error);
|
|
165
|
+
}
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const finalLang = detectedLang || options.fallbackLanguage;
|
|
170
|
+
if (detectedLang && options.caches) {
|
|
171
|
+
cacheLanguage(c, finalLang, options);
|
|
172
|
+
}
|
|
173
|
+
return finalLang;
|
|
174
|
+
};
|
|
175
|
+
const languageDetector = (userOptions) => {
|
|
176
|
+
const options = {
|
|
177
|
+
...DEFAULT_OPTIONS,
|
|
178
|
+
...userOptions,
|
|
179
|
+
cookieOptions: {
|
|
180
|
+
...DEFAULT_OPTIONS.cookieOptions,
|
|
181
|
+
...userOptions.cookieOptions
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
validateOptions(options);
|
|
185
|
+
return async function languageDetector2(ctx, next) {
|
|
186
|
+
try {
|
|
187
|
+
const lang = detectLanguage(ctx, options);
|
|
188
|
+
ctx.set("language", lang);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (options.debug) {
|
|
191
|
+
console.error("Language detection failed:", error);
|
|
192
|
+
}
|
|
193
|
+
ctx.set("language", options.fallbackLanguage);
|
|
194
|
+
}
|
|
195
|
+
await next();
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
199
|
+
0 && (module.exports = {
|
|
200
|
+
DEFAULT_OPTIONS,
|
|
201
|
+
detectFromCookie,
|
|
202
|
+
detectFromHeader,
|
|
203
|
+
detectFromPath,
|
|
204
|
+
detectFromQuery,
|
|
205
|
+
detectors,
|
|
206
|
+
languageDetector,
|
|
207
|
+
normalizeLanguage,
|
|
208
|
+
parseAcceptLanguage,
|
|
209
|
+
validateOptions
|
|
210
|
+
});
|
|
@@ -22,7 +22,6 @@ __export(logger_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(logger_exports);
|
|
24
24
|
var import_color = require("../../utils/color");
|
|
25
|
-
var import_url = require("../../utils/url");
|
|
26
25
|
var LogPrefix = /* @__PURE__ */ ((LogPrefix2) => {
|
|
27
26
|
LogPrefix2["Outgoing"] = "-->";
|
|
28
27
|
LogPrefix2["Incoming"] = "<--";
|
|
@@ -60,8 +59,8 @@ function log(fn, prefix, method, path, status = 0, elapsed) {
|
|
|
60
59
|
}
|
|
61
60
|
const logger = (fn = console.log) => {
|
|
62
61
|
return async function logger2(c, next) {
|
|
63
|
-
const { method } = c.req;
|
|
64
|
-
const path = (
|
|
62
|
+
const { method, url } = c.req;
|
|
63
|
+
const path = url.slice(url.indexOf("/", 8));
|
|
65
64
|
log(fn, "<--" /* Incoming */, method, path);
|
|
66
65
|
const start = Date.now();
|
|
67
66
|
await next();
|
package/dist/cjs/request.js
CHANGED
|
@@ -88,7 +88,9 @@ class LinearRouter {
|
|
|
88
88
|
let value;
|
|
89
89
|
if (name.charCodeAt(name.length - 1) === 125) {
|
|
90
90
|
const openBracePos = name.indexOf("{");
|
|
91
|
-
const
|
|
91
|
+
const next = parts[j + 1];
|
|
92
|
+
const lookahead = next && next[1] !== ":" && next[1] !== "*" ? `(?=${next})` : "";
|
|
93
|
+
const pattern = name.slice(openBracePos + 1, -1) + lookahead;
|
|
92
94
|
const restPath = path.slice(pos + 1);
|
|
93
95
|
const match = new RegExp(pattern, "d").exec(restPath);
|
|
94
96
|
if (!match || match.indices[0][0] !== 0 || match.indices[0][1] === 0) {
|