hono 3.1.4 → 3.1.6
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 +2 -2
- package/dist/cjs/middleware/jwt/index.js +5 -3
- package/dist/cjs/utils/jwt/jwt.js +1 -1
- package/dist/cjs/utils/url.js +15 -7
- package/dist/middleware/jwt/index.js +5 -3
- package/dist/types/adapter/cloudflare-pages/handler.d.ts +1 -1
- package/dist/types/adapter.d.ts +1 -1
- package/dist/types/context.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/middleware/jwt/index.d.ts +6 -0
- package/dist/types/utils/jwt/jwt.d.ts +1 -1
- package/dist/utils/jwt/jwt.js +1 -1
- package/dist/utils/url.js +15 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
[](https://doc.deno.land/https/deno.land/x/hono/mod.ts)
|
|
26
26
|
[](https://discord.gg/KMh2eNSdxV)
|
|
27
27
|
|
|
28
|
-
Hono - _**\[炎\] means flame🔥 in Japanese**_ - is a small, simple, and ultrafast web framework for the
|
|
28
|
+
Hono - _**\[炎\] means flame🔥 in Japanese**_ - is a small, simple, and ultrafast web framework for the Edges.
|
|
29
29
|
It works on Cloudflare Workers, Fastly Compute@Edge, Deno, Bun, Vercel, Lagon, Node.js, and others.
|
|
30
30
|
Fast, but not only fast.
|
|
31
31
|
|
|
@@ -93,7 +93,7 @@ For more details, see [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md).
|
|
|
93
93
|
|
|
94
94
|
Thanks to [all contributors](https://github.com/honojs/hono/graphs/contributors)! Especially, [@metrue](https://github.com/metrue) and [@usualoma](https://github.com/usualoma)!
|
|
95
95
|
|
|
96
|
-
##
|
|
96
|
+
## Authors
|
|
97
97
|
|
|
98
98
|
Yusuke Wada <https://github.com/yusukebe>
|
|
99
99
|
|
|
@@ -23,6 +23,7 @@ __export(jwt_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(jwt_exports);
|
|
24
24
|
var import_http_exception = require("../../http-exception");
|
|
25
25
|
var import_jwt = require("../../utils/jwt");
|
|
26
|
+
var import_context = require("../../context");
|
|
26
27
|
const jwt = (options) => {
|
|
27
28
|
if (!options) {
|
|
28
29
|
throw new Error('JWT auth middleware requires options for "secret');
|
|
@@ -58,14 +59,14 @@ const jwt = (options) => {
|
|
|
58
59
|
});
|
|
59
60
|
throw new import_http_exception.HTTPException(401, { res });
|
|
60
61
|
}
|
|
61
|
-
let
|
|
62
|
+
let payload;
|
|
62
63
|
let msg = "";
|
|
63
64
|
try {
|
|
64
|
-
|
|
65
|
+
payload = await import_jwt.Jwt.verify(token, options.secret, options.alg);
|
|
65
66
|
} catch (e) {
|
|
66
67
|
msg = `${e}`;
|
|
67
68
|
}
|
|
68
|
-
if (!
|
|
69
|
+
if (!payload) {
|
|
69
70
|
const res = new Response("Unauthorized", {
|
|
70
71
|
status: 401,
|
|
71
72
|
statusText: msg,
|
|
@@ -75,6 +76,7 @@ const jwt = (options) => {
|
|
|
75
76
|
});
|
|
76
77
|
throw new import_http_exception.HTTPException(401, { res });
|
|
77
78
|
}
|
|
79
|
+
ctx.set("jwtPayload", payload);
|
|
78
80
|
await next();
|
|
79
81
|
};
|
|
80
82
|
};
|
|
@@ -120,7 +120,7 @@ const verify = async (token, secret, alg = import_types.AlgorithmTypes.HS256) =>
|
|
|
120
120
|
if (encodedSignature !== tokenParts[2]) {
|
|
121
121
|
throw new import_types2.JwtTokenSignatureMismatched(token);
|
|
122
122
|
}
|
|
123
|
-
return
|
|
123
|
+
return payload;
|
|
124
124
|
};
|
|
125
125
|
const decode = (token) => {
|
|
126
126
|
try {
|
package/dist/cjs/utils/url.js
CHANGED
|
@@ -142,8 +142,7 @@ const _getQueryParam = (url, key, multiple) => {
|
|
|
142
142
|
if (trailingKeyCode === 61) {
|
|
143
143
|
const valueIndex = keyIndex2 + key.length + 2;
|
|
144
144
|
const endIndex = url.indexOf("&", valueIndex);
|
|
145
|
-
|
|
146
|
-
return _decodeURI(value);
|
|
145
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
147
146
|
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
|
148
147
|
return "";
|
|
149
148
|
}
|
|
@@ -158,18 +157,27 @@ const _getQueryParam = (url, key, multiple) => {
|
|
|
158
157
|
encoded ?? (encoded = /[%+]/.test(url));
|
|
159
158
|
let keyIndex = url.indexOf("?", 8);
|
|
160
159
|
while (keyIndex !== -1) {
|
|
161
|
-
const
|
|
162
|
-
let
|
|
160
|
+
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
161
|
+
let valueIndex = url.indexOf("=", keyIndex);
|
|
162
|
+
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
|
|
163
|
+
valueIndex = -1;
|
|
164
|
+
}
|
|
165
|
+
let name = url.slice(
|
|
166
|
+
keyIndex + 1,
|
|
167
|
+
valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
|
|
168
|
+
);
|
|
163
169
|
if (encoded) {
|
|
164
170
|
name = _decodeURI(name);
|
|
165
171
|
}
|
|
172
|
+
keyIndex = nextKeyIndex;
|
|
173
|
+
if (name === "") {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
166
176
|
let value;
|
|
167
177
|
if (valueIndex === -1) {
|
|
168
|
-
keyIndex = -1;
|
|
169
178
|
value = "";
|
|
170
179
|
} else {
|
|
171
|
-
|
|
172
|
-
value = url.slice(valueIndex + 1, keyIndex === -1 ? void 0 : keyIndex);
|
|
180
|
+
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
|
|
173
181
|
if (encoded) {
|
|
174
182
|
value = _decodeURI(value);
|
|
175
183
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/middleware/jwt/index.ts
|
|
2
2
|
import { HTTPException } from "../../http-exception.js";
|
|
3
3
|
import { Jwt } from "../../utils/jwt/index.js";
|
|
4
|
+
import "../../context.js";
|
|
4
5
|
var jwt = (options) => {
|
|
5
6
|
if (!options) {
|
|
6
7
|
throw new Error('JWT auth middleware requires options for "secret');
|
|
@@ -36,14 +37,14 @@ var jwt = (options) => {
|
|
|
36
37
|
});
|
|
37
38
|
throw new HTTPException(401, { res });
|
|
38
39
|
}
|
|
39
|
-
let
|
|
40
|
+
let payload;
|
|
40
41
|
let msg = "";
|
|
41
42
|
try {
|
|
42
|
-
|
|
43
|
+
payload = await Jwt.verify(token, options.secret, options.alg);
|
|
43
44
|
} catch (e) {
|
|
44
45
|
msg = `${e}`;
|
|
45
46
|
}
|
|
46
|
-
if (!
|
|
47
|
+
if (!payload) {
|
|
47
48
|
const res = new Response("Unauthorized", {
|
|
48
49
|
status: 401,
|
|
49
50
|
statusText: msg,
|
|
@@ -53,6 +54,7 @@ var jwt = (options) => {
|
|
|
53
54
|
});
|
|
54
55
|
throw new HTTPException(401, { res });
|
|
55
56
|
}
|
|
57
|
+
ctx.set("jwtPayload", payload);
|
|
56
58
|
await next();
|
|
57
59
|
};
|
|
58
60
|
};
|
|
@@ -6,7 +6,7 @@ export declare type EventContext<Env = {}, P extends string = any, Data = {}> =
|
|
|
6
6
|
functionPath: string;
|
|
7
7
|
waitUntil: (promise: Promise<unknown>) => void;
|
|
8
8
|
passThroughOnException: () => void;
|
|
9
|
-
next: (input?: Request | string, init?: RequestInit) => Response
|
|
9
|
+
next: (input?: Request | string, init?: RequestInit) => Promise<Response>;
|
|
10
10
|
env: Env & {
|
|
11
11
|
ASSETS: {
|
|
12
12
|
fetch: typeof fetch;
|
package/dist/types/adapter.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Context } from './context';
|
|
2
|
-
export declare const env: <T
|
|
2
|
+
export declare const env: <T extends Record<string, string>, C extends Context<any, any, {}> = Context<{}, any, {}>>(c: C) => T & C["env"];
|
package/dist/types/context.d.ts
CHANGED
|
@@ -70,8 +70,8 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
70
70
|
append?: boolean;
|
|
71
71
|
}) => void;
|
|
72
72
|
status: (status: StatusCode) => void;
|
|
73
|
-
set: <Key extends keyof E["Variables"]>(key: Key, value: GetVariable<Key, E>) => void;
|
|
74
|
-
get: <Key extends keyof E["Variables"]>(key: Key) => GetVariable<Key, E>;
|
|
73
|
+
set: <Key extends keyof E["Variables"] | "jwtPayload">(key: Key, value: GetVariable<Key, E>) => void;
|
|
74
|
+
get: <Key extends keyof E["Variables"] | "jwtPayload">(key: Key) => GetVariable<Key, E>;
|
|
75
75
|
pretty: (prettyJSON: boolean, space?: number) => void;
|
|
76
76
|
newResponse: NewResponse;
|
|
77
77
|
body: BodyRespond;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hono } from './hono';
|
|
2
|
-
export type { Env, ErrorHandler, Handler, MiddlewareHandler, Next, NotFoundHandler, ValidationTargets, } from './types';
|
|
2
|
+
export type { Env, ErrorHandler, Handler, MiddlewareHandler, Next, NotFoundHandler, ValidationTargets, Input, } from './types';
|
|
3
3
|
export type { Context, ContextVariableMap } from './context';
|
|
4
4
|
export type { HonoRequest } from './request';
|
|
5
5
|
declare module './hono' {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AlgorithmTypes } from './types';
|
|
2
2
|
export declare const sign: (payload: unknown, secret: string, alg?: AlgorithmTypes) => Promise<string>;
|
|
3
|
-
export declare const verify: (token: string, secret: string, alg?: AlgorithmTypes) => Promise<
|
|
3
|
+
export declare const verify: (token: string, secret: string, alg?: AlgorithmTypes) => Promise<any>;
|
|
4
4
|
export declare const decode: (token: string) => {
|
|
5
5
|
header: any;
|
|
6
6
|
payload: any;
|
package/dist/utils/jwt/jwt.js
CHANGED
package/dist/utils/url.js
CHANGED
|
@@ -113,8 +113,7 @@ var _getQueryParam = (url, key, multiple) => {
|
|
|
113
113
|
if (trailingKeyCode === 61) {
|
|
114
114
|
const valueIndex = keyIndex2 + key.length + 2;
|
|
115
115
|
const endIndex = url.indexOf("&", valueIndex);
|
|
116
|
-
|
|
117
|
-
return _decodeURI(value);
|
|
116
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
118
117
|
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
|
119
118
|
return "";
|
|
120
119
|
}
|
|
@@ -129,18 +128,27 @@ var _getQueryParam = (url, key, multiple) => {
|
|
|
129
128
|
encoded ?? (encoded = /[%+]/.test(url));
|
|
130
129
|
let keyIndex = url.indexOf("?", 8);
|
|
131
130
|
while (keyIndex !== -1) {
|
|
132
|
-
const
|
|
133
|
-
let
|
|
131
|
+
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
132
|
+
let valueIndex = url.indexOf("=", keyIndex);
|
|
133
|
+
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
|
|
134
|
+
valueIndex = -1;
|
|
135
|
+
}
|
|
136
|
+
let name = url.slice(
|
|
137
|
+
keyIndex + 1,
|
|
138
|
+
valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
|
|
139
|
+
);
|
|
134
140
|
if (encoded) {
|
|
135
141
|
name = _decodeURI(name);
|
|
136
142
|
}
|
|
143
|
+
keyIndex = nextKeyIndex;
|
|
144
|
+
if (name === "") {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
137
147
|
let value;
|
|
138
148
|
if (valueIndex === -1) {
|
|
139
|
-
keyIndex = -1;
|
|
140
149
|
value = "";
|
|
141
150
|
} else {
|
|
142
|
-
|
|
143
|
-
value = url.slice(valueIndex + 1, keyIndex === -1 ? void 0 : keyIndex);
|
|
151
|
+
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
|
|
144
152
|
if (encoded) {
|
|
145
153
|
value = _decodeURI(value);
|
|
146
154
|
}
|