@shware/http 1.1.10 → 1.1.12
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/hono/__tests__/authorizer.test.cjs +483 -0
- package/dist/hono/__tests__/authorizer.test.cjs.map +1 -0
- package/dist/hono/__tests__/authorizer.test.mjs +481 -0
- package/dist/hono/__tests__/authorizer.test.mjs.map +1 -0
- package/dist/hono/__tests__/csrf.test.cjs +152 -154
- package/dist/hono/__tests__/csrf.test.cjs.map +1 -1
- package/dist/hono/__tests__/csrf.test.mjs +152 -154
- package/dist/hono/__tests__/csrf.test.mjs.map +1 -1
- package/dist/hono/authorizer.cjs +30 -2
- package/dist/hono/authorizer.cjs.map +1 -1
- package/dist/hono/authorizer.d.cts +10 -1
- package/dist/hono/authorizer.d.ts +10 -1
- package/dist/hono/authorizer.mjs +28 -1
- package/dist/hono/authorizer.mjs.map +1 -1
- package/dist/hono/index.cjs +2 -0
- package/dist/hono/index.cjs.map +1 -1
- package/dist/hono/index.d.cts +1 -1
- package/dist/hono/index.d.ts +1 -1
- package/dist/hono/index.mjs +2 -1
- package/dist/hono/index.mjs.map +1 -1
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/{__tests__ → utils/__tests__}/ip.test.cjs +2 -2
- package/dist/utils/__tests__/ip.test.cjs.map +1 -0
- package/dist/utils/__tests__/ip.test.d.cts +2 -0
- package/dist/utils/__tests__/ip.test.d.ts +2 -0
- package/dist/{__tests__ → utils/__tests__}/ip.test.mjs +2 -2
- package/dist/utils/__tests__/ip.test.mjs.map +1 -0
- package/dist/utils/promise.cjs +47 -0
- package/dist/utils/promise.cjs.map +1 -0
- package/dist/utils/promise.d.cts +3 -0
- package/dist/utils/promise.d.ts +3 -0
- package/dist/utils/promise.mjs +22 -0
- package/dist/utils/promise.mjs.map +1 -0
- package/package.json +3 -3
- package/dist/__tests__/ip.test.cjs.map +0 -1
- package/dist/__tests__/ip.test.mjs.map +0 -1
- /package/dist/{__tests__/ip.test.d.cts → hono/__tests__/authorizer.test.d.cts} +0 -0
- /package/dist/{__tests__/ip.test.d.ts → hono/__tests__/authorizer.test.d.ts} +0 -0
|
@@ -3,160 +3,158 @@ import { Hono } from "hono";
|
|
|
3
3
|
import { csrf } from "../csrf.mjs";
|
|
4
4
|
import { errorHandler } from "../handler.mjs";
|
|
5
5
|
describe("CSRF Protection", () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
expect(res.status).toBe(200);
|
|
159
|
-
});
|
|
6
|
+
let app;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
app = new Hono();
|
|
9
|
+
app.onError(errorHandler);
|
|
10
|
+
});
|
|
11
|
+
it("should allow GET requests without CSRF token", async () => {
|
|
12
|
+
app.use(csrf());
|
|
13
|
+
app.get("/test", (c) => c.text("OK"));
|
|
14
|
+
const res = await app.request("/test");
|
|
15
|
+
expect(res.status).toBe(200);
|
|
16
|
+
expect(await res.text()).toBe("OK");
|
|
17
|
+
});
|
|
18
|
+
it("should allow HEAD requests without CSRF token", async () => {
|
|
19
|
+
app.use(csrf());
|
|
20
|
+
app.all("/test", (c) => c.text("OK"));
|
|
21
|
+
const res = await app.request("/test", { method: "HEAD" });
|
|
22
|
+
expect(res.status).toBe(200);
|
|
23
|
+
});
|
|
24
|
+
it("should allow OPTIONS requests without CSRF token", async () => {
|
|
25
|
+
app.use(csrf());
|
|
26
|
+
app.options("/test", (c) => c.text("OK"));
|
|
27
|
+
const res = await app.request("/test", { method: "OPTIONS" });
|
|
28
|
+
expect(res.status).toBe(200);
|
|
29
|
+
});
|
|
30
|
+
it("should reject POST requests without CSRF token", async () => {
|
|
31
|
+
app.use(csrf());
|
|
32
|
+
app.post("/test", (c) => c.text("OK"));
|
|
33
|
+
const res = await app.request("/test", { method: "POST" });
|
|
34
|
+
expect(res.status).toBe(403);
|
|
35
|
+
});
|
|
36
|
+
it("should reject POST requests with mismatched tokens", async () => {
|
|
37
|
+
app.use(csrf());
|
|
38
|
+
app.post("/test", (c) => c.text("OK"));
|
|
39
|
+
const res = await app.request("/test", {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: { "X-XSRF-TOKEN": "header-token", Cookie: "XSRF-TOKEN=cookie-token" }
|
|
42
|
+
});
|
|
43
|
+
expect(res.status).toBe(403);
|
|
44
|
+
});
|
|
45
|
+
it("should allow POST requests with matching tokens", async () => {
|
|
46
|
+
app.use(csrf());
|
|
47
|
+
app.post("/test", (c) => c.text("OK"));
|
|
48
|
+
const res = await app.request("/test", {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: {
|
|
51
|
+
"X-XSRF-TOKEN": "matching-token",
|
|
52
|
+
Cookie: "XSRF-TOKEN=matching-token"
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
expect(res.status).toBe(200);
|
|
56
|
+
expect(await res.text()).toBe("OK");
|
|
57
|
+
});
|
|
58
|
+
it("should use custom cookie and header names", async () => {
|
|
59
|
+
app.use(csrf({ cookieName: "csrf-token", headerName: "X-CSRF-Token" }));
|
|
60
|
+
app.post("/test", (c) => c.text("OK"));
|
|
61
|
+
const res = await app.request("/test", {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: {
|
|
64
|
+
"X-CSRF-Token": "test-token",
|
|
65
|
+
Cookie: "csrf-token=test-token"
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
expect(res.status).toBe(200);
|
|
69
|
+
});
|
|
70
|
+
it("should ignore specified paths", async () => {
|
|
71
|
+
app.use(csrf({ ignores: [{ path: "/webhook/*", methods: ["POST"] }] }));
|
|
72
|
+
app.post("/webhook/stripe", (c) => c.text("OK"));
|
|
73
|
+
app.post("/api/data", (c) => c.text("OK"));
|
|
74
|
+
const webhookRes = await app.request("/webhook/stripe", { method: "POST" });
|
|
75
|
+
expect(webhookRes.status).toBe(200);
|
|
76
|
+
const apiRes = await app.request("/api/data", { method: "POST" });
|
|
77
|
+
expect(apiRes.status).toBe(403);
|
|
78
|
+
});
|
|
79
|
+
it("should ignore all methods for a path when methods not specified", async () => {
|
|
80
|
+
app.use(csrf({ ignores: [{ path: "/auth/apple/callback" }] }));
|
|
81
|
+
app.post("/auth/apple/callback", (c) => c.text("OK"));
|
|
82
|
+
app.put("/auth/apple/callback", (c) => c.text("OK"));
|
|
83
|
+
const postRes = await app.request("/auth/apple/callback", { method: "POST" });
|
|
84
|
+
expect(postRes.status).toBe(200);
|
|
85
|
+
const putRes = await app.request("/auth/apple/callback", { method: "PUT" });
|
|
86
|
+
expect(putRes.status).toBe(200);
|
|
87
|
+
});
|
|
88
|
+
it("should handle empty tokens safely", async () => {
|
|
89
|
+
app.use(csrf());
|
|
90
|
+
app.post("/test", (c) => c.text("OK"));
|
|
91
|
+
const res = await app.request("/test", {
|
|
92
|
+
method: "POST",
|
|
93
|
+
headers: { "X-XSRF-TOKEN": "", Cookie: "XSRF-TOKEN=" }
|
|
94
|
+
});
|
|
95
|
+
expect(res.status).toBe(403);
|
|
96
|
+
});
|
|
97
|
+
it("should handle missing cookie", async () => {
|
|
98
|
+
app.use(csrf());
|
|
99
|
+
app.post("/test", (c) => c.text("OK"));
|
|
100
|
+
const res = await app.request("/test", {
|
|
101
|
+
method: "POST",
|
|
102
|
+
headers: { "X-XSRF-TOKEN": "token" }
|
|
103
|
+
});
|
|
104
|
+
expect(res.status).toBe(403);
|
|
105
|
+
});
|
|
106
|
+
it("should handle missing header", async () => {
|
|
107
|
+
app.use(csrf());
|
|
108
|
+
app.post("/test", (c) => c.text("OK"));
|
|
109
|
+
const res = await app.request("/test", {
|
|
110
|
+
method: "POST",
|
|
111
|
+
headers: { Cookie: "XSRF-TOKEN=token" }
|
|
112
|
+
});
|
|
113
|
+
expect(res.status).toBe(403);
|
|
114
|
+
});
|
|
115
|
+
it("should use custom error message", async () => {
|
|
116
|
+
app.use(csrf({ errorMessage: "Custom CSRF error" }));
|
|
117
|
+
app.post("/test", (c) => c.text("OK"));
|
|
118
|
+
const res = await app.request("/test", { method: "POST" });
|
|
119
|
+
expect(res.status).toBe(403);
|
|
120
|
+
const body = await res.json();
|
|
121
|
+
expect(body.error.message).toBe("Custom CSRF error");
|
|
122
|
+
});
|
|
123
|
+
it("should work with custom safe methods", async () => {
|
|
124
|
+
app.use(csrf({ safeMethods: ["GET"] }));
|
|
125
|
+
app.all("/test", (c) => c.text("OK"));
|
|
126
|
+
const res = await app.request("/test", { method: "HEAD" });
|
|
127
|
+
expect(res.status).toBe(403);
|
|
128
|
+
});
|
|
129
|
+
it("should handle complex ignore patterns", async () => {
|
|
130
|
+
app.use(
|
|
131
|
+
csrf({
|
|
132
|
+
ignores: [
|
|
133
|
+
{ path: "/api/v1/*", methods: ["GET", "POST"] },
|
|
134
|
+
{ path: "/api/v2/*", methods: ["POST"] },
|
|
135
|
+
{ path: "/public/*" }
|
|
136
|
+
// All methods
|
|
137
|
+
]
|
|
138
|
+
})
|
|
139
|
+
);
|
|
140
|
+
app.get("/api/v1/users", (c) => c.text("OK"));
|
|
141
|
+
app.post("/api/v1/users", (c) => c.text("OK"));
|
|
142
|
+
app.put("/api/v1/users", (c) => c.text("OK"));
|
|
143
|
+
app.post("/api/v2/users", (c) => c.text("OK"));
|
|
144
|
+
app.get("/api/v2/users", (c) => c.text("OK"));
|
|
145
|
+
app.post("/public/data", (c) => c.text("OK"));
|
|
146
|
+
let res = await app.request("/api/v1/users", { method: "GET" });
|
|
147
|
+
expect(res.status).toBe(200);
|
|
148
|
+
res = await app.request("/api/v1/users", { method: "POST" });
|
|
149
|
+
expect(res.status).toBe(200);
|
|
150
|
+
res = await app.request("/api/v1/users", { method: "PUT" });
|
|
151
|
+
expect(res.status).toBe(403);
|
|
152
|
+
res = await app.request("/api/v2/users", { method: "POST" });
|
|
153
|
+
expect(res.status).toBe(200);
|
|
154
|
+
res = await app.request("/api/v2/users", { method: "GET" });
|
|
155
|
+
expect(res.status).toBe(200);
|
|
156
|
+
res = await app.request("/public/data", { method: "POST" });
|
|
157
|
+
expect(res.status).toBe(200);
|
|
160
158
|
});
|
|
161
159
|
});
|
|
162
160
|
//# sourceMappingURL=csrf.test.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hono/__tests__/csrf.test.ts"],"sourcesContent":["import { Hono } from 'hono';\nimport { csrf } from '../csrf';\nimport { errorHandler, type Env } from '../handler';\n\ndescribe('CSRF Protection', () => {\n describe('csrfProtection middleware', () => {\n let app: Hono<Env>;\n\n beforeEach(() => {\n app = new Hono();\n app.onError(errorHandler);\n });\n\n it('should allow GET requests without CSRF token', async () => {\n app.use(csrf());\n app.get('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test');\n expect(res.status).toBe(200);\n expect(await res.text()).toBe('OK');\n });\n\n it('should allow HEAD requests without CSRF token', async () => {\n app.use(csrf());\n app.all('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', { method: 'HEAD' });\n expect(res.status).toBe(200);\n });\n\n it('should allow OPTIONS requests without CSRF token', async () => {\n app.use(csrf());\n app.options('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', { method: 'OPTIONS' });\n expect(res.status).toBe(200);\n });\n\n it('should reject POST requests without CSRF token', async () => {\n app.use(csrf());\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', { method: 'POST' });\n expect(res.status).toBe(403);\n });\n\n it('should reject POST requests with mismatched tokens', async () => {\n app.use(csrf());\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', {\n method: 'POST',\n headers: { 'X-XSRF-TOKEN': 'header-token', Cookie: 'XSRF-TOKEN=cookie-token' },\n });\n expect(res.status).toBe(403);\n });\n\n it('should allow POST requests with matching tokens', async () => {\n app.use(csrf());\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', {\n method: 'POST',\n headers: {\n 'X-XSRF-TOKEN': 'matching-token',\n Cookie: 'XSRF-TOKEN=matching-token',\n },\n });\n expect(res.status).toBe(200);\n expect(await res.text()).toBe('OK');\n });\n\n it('should use custom cookie and header names', async () => {\n app.use(csrf({ cookieName: 'csrf-token', headerName: 'X-CSRF-Token' }));\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', {\n method: 'POST',\n headers: {\n 'X-CSRF-Token': 'test-token',\n Cookie: 'csrf-token=test-token',\n },\n });\n expect(res.status).toBe(200);\n });\n\n it('should ignore specified paths', async () => {\n app.use(csrf({ ignores: [{ path: '/webhook/*', methods: ['POST'] }] }));\n app.post('/webhook/stripe', (c) => c.text('OK'));\n app.post('/api/data', (c) => c.text('OK'));\n\n // Ignored path should work without CSRF token\n const webhookRes = await app.request('/webhook/stripe', { method: 'POST' });\n expect(webhookRes.status).toBe(200);\n\n // Non-ignored path should require CSRF token\n const apiRes = await app.request('/api/data', { method: 'POST' });\n expect(apiRes.status).toBe(403);\n });\n\n it('should ignore all methods for a path when methods not specified', async () => {\n app.use(csrf({ ignores: [{ path: '/auth/apple/callback' }] }));\n app.post('/auth/apple/callback', (c) => c.text('OK'));\n app.put('/auth/apple/callback', (c) => c.text('OK'));\n\n const postRes = await app.request('/auth/apple/callback', { method: 'POST' });\n expect(postRes.status).toBe(200);\n\n const putRes = await app.request('/auth/apple/callback', { method: 'PUT' });\n expect(putRes.status).toBe(200);\n });\n\n it('should handle empty tokens safely', async () => {\n app.use(csrf());\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', {\n method: 'POST',\n headers: { 'X-XSRF-TOKEN': '', Cookie: 'XSRF-TOKEN=' },\n });\n expect(res.status).toBe(403);\n });\n\n it('should handle missing cookie', async () => {\n app.use(csrf());\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', {\n method: 'POST',\n headers: { 'X-XSRF-TOKEN': 'token' },\n });\n expect(res.status).toBe(403);\n });\n\n it('should handle missing header', async () => {\n app.use(csrf());\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', {\n method: 'POST',\n headers: { Cookie: 'XSRF-TOKEN=token' },\n });\n expect(res.status).toBe(403);\n });\n\n it('should use custom error message', async () => {\n app.use(csrf({ errorMessage: 'Custom CSRF error' }));\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', { method: 'POST' });\n expect(res.status).toBe(403);\n const body = await res.json();\n expect(body.error.message).toBe('Custom CSRF error');\n });\n\n it('should work with custom safe methods', async () => {\n app.use(csrf({ safeMethods: ['GET'] }));\n app.all('/test', (c) => c.text('OK'));\n\n // HEAD is no longer safe, should require CSRF token\n const res = await app.request('/test', { method: 'HEAD' });\n expect(res.status).toBe(403);\n });\n\n it('should handle complex ignore patterns', async () => {\n app.use(\n csrf({\n ignores: [\n { path: '/api/v1/*', methods: ['GET', 'POST'] },\n { path: '/api/v2/*', methods: ['POST'] },\n { path: '/public/*' }, // All methods\n ],\n })\n );\n\n app.get('/api/v1/users', (c) => c.text('OK'));\n app.post('/api/v1/users', (c) => c.text('OK'));\n app.put('/api/v1/users', (c) => c.text('OK'));\n app.post('/api/v2/users', (c) => c.text('OK'));\n app.get('/api/v2/users', (c) => c.text('OK'));\n app.post('/public/data', (c) => c.text('OK'));\n\n // Ignored GET and POST for /api/v1/*\n let res = await app.request('/api/v1/users', { method: 'GET' });\n expect(res.status).toBe(200);\n\n res = await app.request('/api/v1/users', { method: 'POST' });\n expect(res.status).toBe(200);\n\n // PUT not ignored for /api/v1/*\n res = await app.request('/api/v1/users', { method: 'PUT' });\n expect(res.status).toBe(403);\n\n // Only POST ignored for /api/v2/*\n res = await app.request('/api/v2/users', { method: 'POST' });\n expect(res.status).toBe(200);\n\n // GET not ignored for /api/v2/* (but GET is safe by default)\n res = await app.request('/api/v2/users', { method: 'GET' });\n expect(res.status).toBe(200);\n\n // All methods ignored for /public/*\n res = await app.request('/public/data', { method: 'POST' });\n expect(res.status).toBe(200);\n });\n });\n});\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,oBAA8B;AAEvC,SAAS,mBAAmB,MAAM;AAChC,WAAS,6BAA6B,MAAM;AAC1C,QAAI;AAEJ,eAAW,MAAM;AACf,YAAM,IAAI,KAAK;AACf,UAAI,QAAQ,YAAY;AAAA,IAC1B,CAAC;AAED,OAAG,gDAAgD,YAAY;AAC7D,UAAI,IAAI,KAAK,CAAC;AACd,UAAI,IAAI,SAAS,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC;AAEpC,YAAM,MAAM,MAAM,IAAI,QAAQ,OAAO;AACrC,aAAO,IAAI,MAAM,EAAE,KAAK,GAAG;AAC3B,aAAO,MAAM,IAAI,KAAK,CAAC,EAAE,KAAK,IAAI;AAAA,IACpC,CAAC;AAED,OAAG,iDAAiD,YAAY;AAC9D,UAAI,IAAI,KAAK,CAAC;AACd,UAAI,IAAI,SAAS,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC;AAEpC,YAAM,MAAM,MAAM,IAAI,QAAQ,SAAS,EAAE,QAAQ,OAAO,CAAC;AACzD,aAAO,IAAI,MAAM,EAAE,KAAK,GAA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AI,MAAM,EAAE,KAAK,GAAG;AAG3B,YAAM,MAAM,IAAI,QAAQ,iBAAiB,EAAE,QAAQ,MAAM,CAAC;AAC1D,aAAO,IAAI,MAAM,EAAE,KAAK,GAAG;AAG3B,YAAM,MAAM,IAAI,QAAQ,iBAAiB,EAAE,QAAQ,OAAO,CAAC;AAC3D,aAAO,IAAI,MAAM,EAAE,KAAK,GAAG;AAG3B,YAAM,MAAM,IAAI,QAAQ,iBAAiB,EAAE,QAAQ,MAAM,CAAC;AAC1D,aAAO,IAAI,MAAM,EAAE,KAAK,GAAG;AAG3B,YAAM,MAAM,IAAI,QAAQ,gBAAgB,EAAE,QAAQ,OAAO,CAAC;AAC1D,aAAO,IAAI,MAAM,EAAE,KAAK,GAAG;AAAA,IAC7B,CAAC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/hono/__tests__/csrf.test.ts"],"sourcesContent":["import { Hono } from 'hono';\nimport { csrf } from '../csrf';\nimport { errorHandler, type Env } from '../handler';\n\ndescribe('CSRF Protection', () => {\n let app: Hono<Env>;\n\n beforeEach(() => {\n app = new Hono();\n app.onError(errorHandler);\n });\n\n it('should allow GET requests without CSRF token', async () => {\n app.use(csrf());\n app.get('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test');\n expect(res.status).toBe(200);\n expect(await res.text()).toBe('OK');\n });\n\n it('should allow HEAD requests without CSRF token', async () => {\n app.use(csrf());\n app.all('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', { method: 'HEAD' });\n expect(res.status).toBe(200);\n });\n\n it('should allow OPTIONS requests without CSRF token', async () => {\n app.use(csrf());\n app.options('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', { method: 'OPTIONS' });\n expect(res.status).toBe(200);\n });\n\n it('should reject POST requests without CSRF token', async () => {\n app.use(csrf());\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', { method: 'POST' });\n expect(res.status).toBe(403);\n });\n\n it('should reject POST requests with mismatched tokens', async () => {\n app.use(csrf());\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', {\n method: 'POST',\n headers: { 'X-XSRF-TOKEN': 'header-token', Cookie: 'XSRF-TOKEN=cookie-token' },\n });\n expect(res.status).toBe(403);\n });\n\n it('should allow POST requests with matching tokens', async () => {\n app.use(csrf());\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', {\n method: 'POST',\n headers: {\n 'X-XSRF-TOKEN': 'matching-token',\n Cookie: 'XSRF-TOKEN=matching-token',\n },\n });\n expect(res.status).toBe(200);\n expect(await res.text()).toBe('OK');\n });\n\n it('should use custom cookie and header names', async () => {\n app.use(csrf({ cookieName: 'csrf-token', headerName: 'X-CSRF-Token' }));\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', {\n method: 'POST',\n headers: {\n 'X-CSRF-Token': 'test-token',\n Cookie: 'csrf-token=test-token',\n },\n });\n expect(res.status).toBe(200);\n });\n\n it('should ignore specified paths', async () => {\n app.use(csrf({ ignores: [{ path: '/webhook/*', methods: ['POST'] }] }));\n app.post('/webhook/stripe', (c) => c.text('OK'));\n app.post('/api/data', (c) => c.text('OK'));\n\n // Ignored path should work without CSRF token\n const webhookRes = await app.request('/webhook/stripe', { method: 'POST' });\n expect(webhookRes.status).toBe(200);\n\n // Non-ignored path should require CSRF token\n const apiRes = await app.request('/api/data', { method: 'POST' });\n expect(apiRes.status).toBe(403);\n });\n\n it('should ignore all methods for a path when methods not specified', async () => {\n app.use(csrf({ ignores: [{ path: '/auth/apple/callback' }] }));\n app.post('/auth/apple/callback', (c) => c.text('OK'));\n app.put('/auth/apple/callback', (c) => c.text('OK'));\n\n const postRes = await app.request('/auth/apple/callback', { method: 'POST' });\n expect(postRes.status).toBe(200);\n\n const putRes = await app.request('/auth/apple/callback', { method: 'PUT' });\n expect(putRes.status).toBe(200);\n });\n\n it('should handle empty tokens safely', async () => {\n app.use(csrf());\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', {\n method: 'POST',\n headers: { 'X-XSRF-TOKEN': '', Cookie: 'XSRF-TOKEN=' },\n });\n expect(res.status).toBe(403);\n });\n\n it('should handle missing cookie', async () => {\n app.use(csrf());\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', {\n method: 'POST',\n headers: { 'X-XSRF-TOKEN': 'token' },\n });\n expect(res.status).toBe(403);\n });\n\n it('should handle missing header', async () => {\n app.use(csrf());\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', {\n method: 'POST',\n headers: { Cookie: 'XSRF-TOKEN=token' },\n });\n expect(res.status).toBe(403);\n });\n\n it('should use custom error message', async () => {\n app.use(csrf({ errorMessage: 'Custom CSRF error' }));\n app.post('/test', (c) => c.text('OK'));\n\n const res = await app.request('/test', { method: 'POST' });\n expect(res.status).toBe(403);\n const body = await res.json();\n expect(body.error.message).toBe('Custom CSRF error');\n });\n\n it('should work with custom safe methods', async () => {\n app.use(csrf({ safeMethods: ['GET'] }));\n app.all('/test', (c) => c.text('OK'));\n\n // HEAD is no longer safe, should require CSRF token\n const res = await app.request('/test', { method: 'HEAD' });\n expect(res.status).toBe(403);\n });\n\n it('should handle complex ignore patterns', async () => {\n app.use(\n csrf({\n ignores: [\n { path: '/api/v1/*', methods: ['GET', 'POST'] },\n { path: '/api/v2/*', methods: ['POST'] },\n { path: '/public/*' }, // All methods\n ],\n })\n );\n\n app.get('/api/v1/users', (c) => c.text('OK'));\n app.post('/api/v1/users', (c) => c.text('OK'));\n app.put('/api/v1/users', (c) => c.text('OK'));\n app.post('/api/v2/users', (c) => c.text('OK'));\n app.get('/api/v2/users', (c) => c.text('OK'));\n app.post('/public/data', (c) => c.text('OK'));\n\n // Ignored GET and POST for /api/v1/*\n let res = await app.request('/api/v1/users', { method: 'GET' });\n expect(res.status).toBe(200);\n\n res = await app.request('/api/v1/users', { method: 'POST' });\n expect(res.status).toBe(200);\n\n // PUT not ignored for /api/v1/*\n res = await app.request('/api/v1/users', { method: 'PUT' });\n expect(res.status).toBe(403);\n\n // Only POST ignored for /api/v2/*\n res = await app.request('/api/v2/users', { method: 'POST' });\n expect(res.status).toBe(200);\n\n // GET not ignored for /api/v2/* (but GET is safe by default)\n res = await app.request('/api/v2/users', { method: 'GET' });\n expect(res.status).toBe(200);\n\n // All methods ignored for /public/*\n res = await app.request('/public/data', { method: 'POST' });\n expect(res.status).toBe(200);\n });\n});\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,oBAA8B;AAEvC,SAAS,mBAAmB,MAAM;AAChC,MAAI;AAEJ,aAAW,MAAM;AACf,UAAM,IAAI,KAAK;AACf,QAAI,QAAQ,YAAY;AAAA,EAC1B,CAAC;AAED,KAAG,gDAAgD,YAAY;AAC7D,QAAI,IAAI,KAAK,CAAC;AACd,QAAI,IAAI,SAAS,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC;AAEpC,UAAM,MAAM,MAAM,IAAI,QAAQ,OAAO;AACrC,WAAO,IAAI,MAAM,EAAE,KAAK,GAAG;AAC3B,WAAO,MAAM,IAAI,KAAK,CAAC,EAAE,KAAK,IAAI;AAAA,EACpC,CAAC;AAED,KAAG,iDAAiD,YAAY;AAC9D,QAAI,IAAI,KAAK,CAAC;AACd,QAAI,IAAI,SAAS,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC;AAEpC,UAAM,MAAM,MAAM,IAAI,QAAQ,SAAS,EAAE,QAAQ,OAAO,CAAC;AACzD,WAAO,IAAI,MAAM,EAAE,KAAK,GAAG;AAAA,EAC7B,CAAC;AAED,KAAG,oDAAoD,YAAY;AACjE,QAAI,IAAI,KAAK,CAAC;AACd,QAAI,QAAQ,SAAS,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC;AAExC,UAAM,MAAM,MAAM,IAAI,QAAQ,SAAS,EAAE,QAAQ,UAAU,CAAC;AAC5D,WAAO,IAAI,MAAM,EAAE,KAAK,GAAG;AAAA,EAC7B,CAAC;AAED,KAAG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,iBAAiB,EAAE,QAAQ,MAAM,CAAC;AAC1D,WAAO,IAAI,MAAM,EAAE,KAAK,GAAG;AAG3B,UAAM,MAAM,IAAI,QAAQ,gBAAgB,EAAE,QAAQ,OAAO,CAAC;AAC1D,WAAO,IAAI,MAAM,EAAE,KAAK,GAAG;AAAA,EAC7B,CAAC;AACH,CAAC;","names":[]}
|
package/dist/hono/authorizer.cjs
CHANGED
|
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/hono/authorizer.ts
|
|
21
21
|
var authorizer_exports = {};
|
|
22
22
|
__export(authorizer_exports, {
|
|
23
|
-
Authorizer: () => Authorizer
|
|
23
|
+
Authorizer: () => Authorizer,
|
|
24
|
+
authorizer: () => authorizer
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(authorizer_exports);
|
|
26
27
|
var import_router = require("hono/router");
|
|
@@ -64,8 +65,35 @@ var Authorizer = class _Authorizer {
|
|
|
64
65
|
};
|
|
65
66
|
};
|
|
66
67
|
};
|
|
68
|
+
function authorizer({
|
|
69
|
+
auth,
|
|
70
|
+
errorMessage = "Unauthorized, please login to continue.",
|
|
71
|
+
rules = []
|
|
72
|
+
}) {
|
|
73
|
+
const router = new import_smart_router.SmartRouter({ routers: [new import_reg_exp_router.RegExpRouter(), new import_trie_router.TrieRouter()] });
|
|
74
|
+
for (const { path, methods = [import_router.METHOD_NAME_ALL] } of rules) {
|
|
75
|
+
for (const method of methods) {
|
|
76
|
+
router.add(method, path, null);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return async (c, next) => {
|
|
80
|
+
if (c.req.method === "OPTIONS") {
|
|
81
|
+
await next();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const [matched] = router.match(c.req.method, c.req.path);
|
|
85
|
+
if (matched.length === 0) {
|
|
86
|
+
await next();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const authenticated = await auth.isAuthenticated(c.req.raw);
|
|
90
|
+
if (!authenticated) throw import_status.Status.unauthorized(errorMessage).error();
|
|
91
|
+
await next();
|
|
92
|
+
};
|
|
93
|
+
}
|
|
67
94
|
// Annotate the CommonJS export names for ESM import in node:
|
|
68
95
|
0 && (module.exports = {
|
|
69
|
-
Authorizer
|
|
96
|
+
Authorizer,
|
|
97
|
+
authorizer
|
|
70
98
|
});
|
|
71
99
|
//# sourceMappingURL=authorizer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hono/authorizer.ts"],"sourcesContent":["import { METHOD_NAME_ALL } from 'hono/router';\nimport { RegExpRouter } from 'hono/router/reg-exp-router';\nimport { SmartRouter } from 'hono/router/smart-router';\nimport { TrieRouter } from 'hono/router/trie-router';\nimport { Status } from '../error/status';\nimport type { MiddlewareHandler } from 'hono';\n\ntype Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\ntype Auth = {
|
|
1
|
+
{"version":3,"sources":["../../src/hono/authorizer.ts"],"sourcesContent":["import { METHOD_NAME_ALL } from 'hono/router';\nimport { RegExpRouter } from 'hono/router/reg-exp-router';\nimport { SmartRouter } from 'hono/router/smart-router';\nimport { TrieRouter } from 'hono/router/trie-router';\nimport { Status } from '../error/status';\nimport type { MiddlewareHandler } from 'hono';\n\ntype Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\ntype Auth = { isAuthenticated: (request: Request) => Promise<boolean> };\n\nexport class Authorizer {\n private readonly router = new SmartRouter<null>({\n routers: [new RegExpRouter(), new TrieRouter()],\n });\n\n private readonly auth: Auth;\n\n private constructor(auth: Auth) {\n this.auth = auth;\n }\n\n static create = (auth: Auth) => new Authorizer(auth);\n\n match(path: string, methods?: [Methods, ...Methods[]]) {\n if (methods) {\n for (const method of methods) {\n this.router.add(method, path, null);\n }\n } else {\n this.router.add(METHOD_NAME_ALL, path, null);\n }\n return this;\n }\n\n build = (): MiddlewareHandler => {\n return async (c, next) => {\n if (c.req.method === 'OPTIONS') {\n await next();\n return;\n }\n\n const [matched] = this.router.match(c.req.method, c.req.path);\n if (matched.length === 0) {\n await next();\n return;\n }\n\n const authenticated = await this.auth.isAuthenticated(c.req.raw);\n if (!authenticated) throw Status.unauthorized().error();\n await next();\n };\n };\n}\n\nexport interface AuthorizerConfig {\n auth: Auth;\n errorMessage?: string;\n rules?: { path: string; methods?: [Methods, ...Methods[]] }[];\n}\n\nexport function authorizer({\n auth,\n errorMessage = 'Unauthorized, please login to continue.',\n rules = [],\n}: AuthorizerConfig): MiddlewareHandler {\n const router = new SmartRouter<null>({ routers: [new RegExpRouter(), new TrieRouter()] });\n\n for (const { path, methods = [METHOD_NAME_ALL] } of rules) {\n for (const method of methods) {\n router.add(method, path, null);\n }\n }\n\n return async (c, next) => {\n if (c.req.method === 'OPTIONS') {\n await next();\n return;\n }\n\n const [matched] = router.match(c.req.method, c.req.path);\n if (matched.length === 0) {\n await next();\n return;\n }\n\n const authenticated = await auth.isAuthenticated(c.req.raw);\n if (!authenticated) throw Status.unauthorized(errorMessage).error();\n await next();\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAgC;AAChC,4BAA6B;AAC7B,0BAA4B;AAC5B,yBAA2B;AAC3B,oBAAuB;AAOhB,IAAM,aAAN,MAAM,YAAW;AAAA,EACL,SAAS,IAAI,gCAAkB;AAAA,IAC9C,SAAS,CAAC,IAAI,mCAAa,GAAG,IAAI,8BAAW,CAAC;AAAA,EAChD,CAAC;AAAA,EAEgB;AAAA,EAET,YAAY,MAAY;AAC9B,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,OAAO,SAAS,CAAC,SAAe,IAAI,YAAW,IAAI;AAAA,EAEnD,MAAM,MAAc,SAAmC;AACrD,QAAI,SAAS;AACX,iBAAW,UAAU,SAAS;AAC5B,aAAK,OAAO,IAAI,QAAQ,MAAM,IAAI;AAAA,MACpC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AE,MAAM;AAClE,UAAM,KAAK;AAAA,EACb;AACF;","names":[]}
|
|
@@ -12,5 +12,14 @@ declare class Authorizer {
|
|
|
12
12
|
match(path: string, methods?: [Methods, ...Methods[]]): this;
|
|
13
13
|
build: () => MiddlewareHandler;
|
|
14
14
|
}
|
|
15
|
+
interface AuthorizerConfig {
|
|
16
|
+
auth: Auth;
|
|
17
|
+
errorMessage?: string;
|
|
18
|
+
rules?: {
|
|
19
|
+
path: string;
|
|
20
|
+
methods?: [Methods, ...Methods[]];
|
|
21
|
+
}[];
|
|
22
|
+
}
|
|
23
|
+
declare function authorizer({ auth, errorMessage, rules, }: AuthorizerConfig): MiddlewareHandler;
|
|
15
24
|
|
|
16
|
-
export { Authorizer };
|
|
25
|
+
export { Authorizer, type AuthorizerConfig, authorizer };
|
|
@@ -12,5 +12,14 @@ declare class Authorizer {
|
|
|
12
12
|
match(path: string, methods?: [Methods, ...Methods[]]): this;
|
|
13
13
|
build: () => MiddlewareHandler;
|
|
14
14
|
}
|
|
15
|
+
interface AuthorizerConfig {
|
|
16
|
+
auth: Auth;
|
|
17
|
+
errorMessage?: string;
|
|
18
|
+
rules?: {
|
|
19
|
+
path: string;
|
|
20
|
+
methods?: [Methods, ...Methods[]];
|
|
21
|
+
}[];
|
|
22
|
+
}
|
|
23
|
+
declare function authorizer({ auth, errorMessage, rules, }: AuthorizerConfig): MiddlewareHandler;
|
|
15
24
|
|
|
16
|
-
export { Authorizer };
|
|
25
|
+
export { Authorizer, type AuthorizerConfig, authorizer };
|
package/dist/hono/authorizer.mjs
CHANGED
|
@@ -40,7 +40,34 @@ var Authorizer = class _Authorizer {
|
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
|
+
function authorizer({
|
|
44
|
+
auth,
|
|
45
|
+
errorMessage = "Unauthorized, please login to continue.",
|
|
46
|
+
rules = []
|
|
47
|
+
}) {
|
|
48
|
+
const router = new SmartRouter({ routers: [new RegExpRouter(), new TrieRouter()] });
|
|
49
|
+
for (const { path, methods = [METHOD_NAME_ALL] } of rules) {
|
|
50
|
+
for (const method of methods) {
|
|
51
|
+
router.add(method, path, null);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return async (c, next) => {
|
|
55
|
+
if (c.req.method === "OPTIONS") {
|
|
56
|
+
await next();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const [matched] = router.match(c.req.method, c.req.path);
|
|
60
|
+
if (matched.length === 0) {
|
|
61
|
+
await next();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const authenticated = await auth.isAuthenticated(c.req.raw);
|
|
65
|
+
if (!authenticated) throw Status.unauthorized(errorMessage).error();
|
|
66
|
+
await next();
|
|
67
|
+
};
|
|
68
|
+
}
|
|
43
69
|
export {
|
|
44
|
-
Authorizer
|
|
70
|
+
Authorizer,
|
|
71
|
+
authorizer
|
|
45
72
|
};
|
|
46
73
|
//# sourceMappingURL=authorizer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hono/authorizer.ts"],"sourcesContent":["import { METHOD_NAME_ALL } from 'hono/router';\nimport { RegExpRouter } from 'hono/router/reg-exp-router';\nimport { SmartRouter } from 'hono/router/smart-router';\nimport { TrieRouter } from 'hono/router/trie-router';\nimport { Status } from '../error/status';\nimport type { MiddlewareHandler } from 'hono';\n\ntype Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\ntype Auth = {
|
|
1
|
+
{"version":3,"sources":["../../src/hono/authorizer.ts"],"sourcesContent":["import { METHOD_NAME_ALL } from 'hono/router';\nimport { RegExpRouter } from 'hono/router/reg-exp-router';\nimport { SmartRouter } from 'hono/router/smart-router';\nimport { TrieRouter } from 'hono/router/trie-router';\nimport { Status } from '../error/status';\nimport type { MiddlewareHandler } from 'hono';\n\ntype Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\ntype Auth = { isAuthenticated: (request: Request) => Promise<boolean> };\n\nexport class Authorizer {\n private readonly router = new SmartRouter<null>({\n routers: [new RegExpRouter(), new TrieRouter()],\n });\n\n private readonly auth: Auth;\n\n private constructor(auth: Auth) {\n this.auth = auth;\n }\n\n static create = (auth: Auth) => new Authorizer(auth);\n\n match(path: string, methods?: [Methods, ...Methods[]]) {\n if (methods) {\n for (const method of methods) {\n this.router.add(method, path, null);\n }\n } else {\n this.router.add(METHOD_NAME_ALL, path, null);\n }\n return this;\n }\n\n build = (): MiddlewareHandler => {\n return async (c, next) => {\n if (c.req.method === 'OPTIONS') {\n await next();\n return;\n }\n\n const [matched] = this.router.match(c.req.method, c.req.path);\n if (matched.length === 0) {\n await next();\n return;\n }\n\n const authenticated = await this.auth.isAuthenticated(c.req.raw);\n if (!authenticated) throw Status.unauthorized().error();\n await next();\n };\n };\n}\n\nexport interface AuthorizerConfig {\n auth: Auth;\n errorMessage?: string;\n rules?: { path: string; methods?: [Methods, ...Methods[]] }[];\n}\n\nexport function authorizer({\n auth,\n errorMessage = 'Unauthorized, please login to continue.',\n rules = [],\n}: AuthorizerConfig): MiddlewareHandler {\n const router = new SmartRouter<null>({ routers: [new RegExpRouter(), new TrieRouter()] });\n\n for (const { path, methods = [METHOD_NAME_ALL] } of rules) {\n for (const method of methods) {\n router.add(method, path, null);\n }\n }\n\n return async (c, next) => {\n if (c.req.method === 'OPTIONS') {\n await next();\n return;\n }\n\n const [matched] = router.match(c.req.method, c.req.path);\n if (matched.length === 0) {\n await next();\n return;\n }\n\n const authenticated = await auth.isAuthenticated(c.req.raw);\n if (!authenticated) throw Status.unauthorized(errorMessage).error();\n await next();\n };\n}\n"],"mappings":";AAAA,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AAOhB,IAAM,aAAN,MAAM,YAAW;AAAA,EACL,SAAS,IAAI,YAAkB;AAAA,IAC9C,SAAS,CAAC,IAAI,aAAa,GAAG,IAAI,WAAW,CA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AAA,IACF;AAEA,UAAM,CAAC,OAAO,IAAI,OAAO,MAAM,EAAE,IAAI,QAAQ,EAAE,IAAI,IAAI;AACvD,QAAI,QAAQ,WAAW,GAAG;AACxB,YAAM,KAAK;AACX;AAAA,IACF;AAEA,UAAM,gBAAgB,MAAM,KAAK,gBAAgB,EAAE,IAAI,GAAG;AAC1D,QAAI,CAAC,cAAe,OAAM,OAAO,aAAa,YAAY,EAAE,MAAM;AAClE,UAAM,KAAK;AAAA,EACb;AACF;","names":[]}
|
package/dist/hono/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var hono_exports = {};
|
|
22
22
|
__export(hono_exports, {
|
|
23
23
|
Authorizer: () => import_authorizer.Authorizer,
|
|
24
|
+
authorizer: () => import_authorizer.authorizer,
|
|
24
25
|
bigintId: () => import_validator.bigintId,
|
|
25
26
|
csrf: () => import_csrf.csrf,
|
|
26
27
|
errorHandler: () => import_handler.errorHandler,
|
|
@@ -36,6 +37,7 @@ var import_csrf = require("./csrf.cjs");
|
|
|
36
37
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
38
|
0 && (module.exports = {
|
|
38
39
|
Authorizer,
|
|
40
|
+
authorizer,
|
|
39
41
|
bigintId,
|
|
40
42
|
csrf,
|
|
41
43
|
errorHandler,
|
package/dist/hono/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hono/index.ts"],"sourcesContent":["export { zValidator, bigintId } from './validator';\nexport { errorHandler } from './handler';\nexport { geolocation } from './geolocation';\nexport { Authorizer } from './authorizer';\nexport { csrf, type CSRFConfig, type CSRFIgnoreRule } from './csrf';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAqC;AACrC,qBAA6B;AAC7B,yBAA4B;AAC5B,
|
|
1
|
+
{"version":3,"sources":["../../src/hono/index.ts"],"sourcesContent":["export { zValidator, bigintId } from './validator';\nexport { errorHandler } from './handler';\nexport { geolocation } from './geolocation';\nexport { Authorizer, authorizer, type AuthorizerConfig } from './authorizer';\nexport { csrf, type CSRFConfig, type CSRFIgnoreRule } from './csrf';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAqC;AACrC,qBAA6B;AAC7B,yBAA4B;AAC5B,wBAA8D;AAC9D,kBAA2D;","names":[]}
|
package/dist/hono/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { bigintId, zValidator } from './validator.cjs';
|
|
2
2
|
export { errorHandler } from './handler.cjs';
|
|
3
3
|
export { geolocation } from './geolocation.cjs';
|
|
4
|
-
export { Authorizer } from './authorizer.cjs';
|
|
4
|
+
export { Authorizer, AuthorizerConfig, authorizer } from './authorizer.cjs';
|
|
5
5
|
export { CSRFConfig, CSRFIgnoreRule, csrf } from './csrf.cjs';
|
|
6
6
|
import 'zod/mini';
|
|
7
7
|
import 'hono';
|
package/dist/hono/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { bigintId, zValidator } from './validator.js';
|
|
2
2
|
export { errorHandler } from './handler.js';
|
|
3
3
|
export { geolocation } from './geolocation.js';
|
|
4
|
-
export { Authorizer } from './authorizer.js';
|
|
4
|
+
export { Authorizer, AuthorizerConfig, authorizer } from './authorizer.js';
|
|
5
5
|
export { CSRFConfig, CSRFIgnoreRule, csrf } from './csrf.js';
|
|
6
6
|
import 'zod/mini';
|
|
7
7
|
import 'hono';
|
package/dist/hono/index.mjs
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
import { zValidator, bigintId } from "./validator.mjs";
|
|
3
3
|
import { errorHandler } from "./handler.mjs";
|
|
4
4
|
import { geolocation } from "./geolocation.mjs";
|
|
5
|
-
import { Authorizer } from "./authorizer.mjs";
|
|
5
|
+
import { Authorizer, authorizer } from "./authorizer.mjs";
|
|
6
6
|
import { csrf } from "./csrf.mjs";
|
|
7
7
|
export {
|
|
8
8
|
Authorizer,
|
|
9
|
+
authorizer,
|
|
9
10
|
bigintId,
|
|
10
11
|
csrf,
|
|
11
12
|
errorHandler,
|
package/dist/hono/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hono/index.ts"],"sourcesContent":["export { zValidator, bigintId } from './validator';\nexport { errorHandler } from './handler';\nexport { geolocation } from './geolocation';\nexport { Authorizer } from './authorizer';\nexport { csrf, type CSRFConfig, type CSRFIgnoreRule } from './csrf';\n"],"mappings":";AAAA,SAAS,YAAY,gBAAgB;AACrC,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,
|
|
1
|
+
{"version":3,"sources":["../../src/hono/index.ts"],"sourcesContent":["export { zValidator, bigintId } from './validator';\nexport { errorHandler } from './handler';\nexport { geolocation } from './geolocation';\nexport { Authorizer, authorizer, type AuthorizerConfig } from './authorizer';\nexport { csrf, type CSRFConfig, type CSRFIgnoreRule } from './csrf';\n"],"mappings":";AAAA,SAAS,YAAY,gBAAgB;AACrC,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,YAAY,kBAAyC;AAC9D,SAAS,YAAkD;","names":[]}
|