@webdecoy/hono 0.13.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/index.d.mts +51 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +53 -0
- package/dist/index.mjs +27 -0
- package/package.json +64 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Context, MiddlewareHandler } from 'hono';
|
|
2
|
+
import { Decision, FetchGuardOptions } from '@webdecoy/node';
|
|
3
|
+
export { Decision, FetchGuardOptions, ProtectResult, RequestMetadata, WebDecoyConfig } from '@webdecoy/node';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Web Decoy middleware for Hono.
|
|
7
|
+
*
|
|
8
|
+
* Hono is the default on Cloudflare Workers, Bun and Deno — the runtimes where
|
|
9
|
+
* the rest of our stack already sits. The Cloudflare edge sensor fronts these
|
|
10
|
+
* deployments and tags every request it forwards, and `readEdgeVerdict()` exists
|
|
11
|
+
* so the origin can act on that tag. Until now there was no origin middleware
|
|
12
|
+
* there to do it.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { Hono } from 'hono';
|
|
17
|
+
* import { webdecoy } from '@webdecoy/hono';
|
|
18
|
+
* import { tripwire, rateLimit } from '@webdecoy/node';
|
|
19
|
+
*
|
|
20
|
+
* const app = new Hono();
|
|
21
|
+
*
|
|
22
|
+
* app.use('*', webdecoy({
|
|
23
|
+
* rules: [tripwire(), rateLimit({ max: 100, window: 60 })],
|
|
24
|
+
* skipPaths: ['/health'],
|
|
25
|
+
* }));
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
interface WebDecoyHonoOptions extends Omit<FetchGuardOptions, 'onBlocked'> {
|
|
30
|
+
/**
|
|
31
|
+
* Build the blocking response. Defaults to 403, or 429 with a `Retry-After`
|
|
32
|
+
* for a throttle.
|
|
33
|
+
*/
|
|
34
|
+
onBlocked?: (c: Context, decision: Decision) => Response | Promise<Response>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Where the decision is stashed on the Hono context.
|
|
38
|
+
*
|
|
39
|
+
* Read it with `c.get('webdecoy')` — in monitor mode this is the only place the
|
|
40
|
+
* verdict surfaces, and monitor is the default.
|
|
41
|
+
*/
|
|
42
|
+
declare const WEBDECOY_CONTEXT_KEY = "webdecoy";
|
|
43
|
+
declare module 'hono' {
|
|
44
|
+
interface ContextVariableMap {
|
|
45
|
+
webdecoy?: Decision;
|
|
46
|
+
webdecoyDecision?: Decision;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
declare function webdecoy(options?: WebDecoyHonoOptions): MiddlewareHandler;
|
|
50
|
+
|
|
51
|
+
export { WEBDECOY_CONTEXT_KEY, type WebDecoyHonoOptions, webdecoy };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Context, MiddlewareHandler } from 'hono';
|
|
2
|
+
import { Decision, FetchGuardOptions } from '@webdecoy/node';
|
|
3
|
+
export { Decision, FetchGuardOptions, ProtectResult, RequestMetadata, WebDecoyConfig } from '@webdecoy/node';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Web Decoy middleware for Hono.
|
|
7
|
+
*
|
|
8
|
+
* Hono is the default on Cloudflare Workers, Bun and Deno — the runtimes where
|
|
9
|
+
* the rest of our stack already sits. The Cloudflare edge sensor fronts these
|
|
10
|
+
* deployments and tags every request it forwards, and `readEdgeVerdict()` exists
|
|
11
|
+
* so the origin can act on that tag. Until now there was no origin middleware
|
|
12
|
+
* there to do it.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { Hono } from 'hono';
|
|
17
|
+
* import { webdecoy } from '@webdecoy/hono';
|
|
18
|
+
* import { tripwire, rateLimit } from '@webdecoy/node';
|
|
19
|
+
*
|
|
20
|
+
* const app = new Hono();
|
|
21
|
+
*
|
|
22
|
+
* app.use('*', webdecoy({
|
|
23
|
+
* rules: [tripwire(), rateLimit({ max: 100, window: 60 })],
|
|
24
|
+
* skipPaths: ['/health'],
|
|
25
|
+
* }));
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
interface WebDecoyHonoOptions extends Omit<FetchGuardOptions, 'onBlocked'> {
|
|
30
|
+
/**
|
|
31
|
+
* Build the blocking response. Defaults to 403, or 429 with a `Retry-After`
|
|
32
|
+
* for a throttle.
|
|
33
|
+
*/
|
|
34
|
+
onBlocked?: (c: Context, decision: Decision) => Response | Promise<Response>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Where the decision is stashed on the Hono context.
|
|
38
|
+
*
|
|
39
|
+
* Read it with `c.get('webdecoy')` — in monitor mode this is the only place the
|
|
40
|
+
* verdict surfaces, and monitor is the default.
|
|
41
|
+
*/
|
|
42
|
+
declare const WEBDECOY_CONTEXT_KEY = "webdecoy";
|
|
43
|
+
declare module 'hono' {
|
|
44
|
+
interface ContextVariableMap {
|
|
45
|
+
webdecoy?: Decision;
|
|
46
|
+
webdecoyDecision?: Decision;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
declare function webdecoy(options?: WebDecoyHonoOptions): MiddlewareHandler;
|
|
50
|
+
|
|
51
|
+
export { WEBDECOY_CONTEXT_KEY, type WebDecoyHonoOptions, webdecoy };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
WEBDECOY_CONTEXT_KEY: () => WEBDECOY_CONTEXT_KEY,
|
|
24
|
+
webdecoy: () => webdecoy
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_node = require("@webdecoy/node");
|
|
28
|
+
var WEBDECOY_CONTEXT_KEY = "webdecoy";
|
|
29
|
+
function webdecoy(options = {}) {
|
|
30
|
+
const { onBlocked, ...guardOptions } = options;
|
|
31
|
+
const guard = (0, import_node.createFetchGuard)(guardOptions);
|
|
32
|
+
return async (c, next) => {
|
|
33
|
+
if (guard.skips(new URL(c.req.url).pathname)) {
|
|
34
|
+
await next();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const { decision, response } = await guard.check(c.req.raw);
|
|
38
|
+
c.set(WEBDECOY_CONTEXT_KEY, decision);
|
|
39
|
+
c.set("webdecoyDecision", decision);
|
|
40
|
+
if (response) {
|
|
41
|
+
return onBlocked ? await onBlocked(c, decision) : response;
|
|
42
|
+
}
|
|
43
|
+
await next();
|
|
44
|
+
if (c.res) {
|
|
45
|
+
c.res = await guard.decorate(c.res);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
WEBDECOY_CONTEXT_KEY,
|
|
52
|
+
webdecoy
|
|
53
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createFetchGuard } from "@webdecoy/node";
|
|
3
|
+
var WEBDECOY_CONTEXT_KEY = "webdecoy";
|
|
4
|
+
function webdecoy(options = {}) {
|
|
5
|
+
const { onBlocked, ...guardOptions } = options;
|
|
6
|
+
const guard = createFetchGuard(guardOptions);
|
|
7
|
+
return async (c, next) => {
|
|
8
|
+
if (guard.skips(new URL(c.req.url).pathname)) {
|
|
9
|
+
await next();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const { decision, response } = await guard.check(c.req.raw);
|
|
13
|
+
c.set(WEBDECOY_CONTEXT_KEY, decision);
|
|
14
|
+
c.set("webdecoyDecision", decision);
|
|
15
|
+
if (response) {
|
|
16
|
+
return onBlocked ? await onBlocked(c, decision) : response;
|
|
17
|
+
}
|
|
18
|
+
await next();
|
|
19
|
+
if (c.res) {
|
|
20
|
+
c.res = await guard.decorate(c.res);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
WEBDECOY_CONTEXT_KEY,
|
|
26
|
+
webdecoy
|
|
27
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webdecoy/hono",
|
|
3
|
+
"version": "0.13.0",
|
|
4
|
+
"description": "Web Decoy middleware for Hono — Cloudflare Workers, Bun, Deno, Node",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"require": "./dist/index.js",
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
19
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
20
|
+
"test": "jest",
|
|
21
|
+
"lint": "eslint src --max-warnings 0",
|
|
22
|
+
"clean": "rm -rf dist",
|
|
23
|
+
"check:edge": "node ../../scripts/check-edge.mjs src/index.ts"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"web-decoy",
|
|
27
|
+
"hono",
|
|
28
|
+
"middleware",
|
|
29
|
+
"bot-detection",
|
|
30
|
+
"cloudflare-workers",
|
|
31
|
+
"bun",
|
|
32
|
+
"deno",
|
|
33
|
+
"security"
|
|
34
|
+
],
|
|
35
|
+
"author": "Web Decoy",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"homepage": "https://github.com/WebDecoy/node#readme",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/WebDecoy/node.git",
|
|
41
|
+
"directory": "packages/hono"
|
|
42
|
+
},
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/WebDecoy/node/issues"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@webdecoy/node": "^0.13.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"hono": "^4.0.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/jest": "^29.5.11",
|
|
54
|
+
"@types/node": "^20.11.0",
|
|
55
|
+
"jest": "^29.7.0",
|
|
56
|
+
"ts-jest": "^29.1.1",
|
|
57
|
+
"tsup": "^8.0.1",
|
|
58
|
+
"typescript": "^5.3.3",
|
|
59
|
+
"hono": "^4.6.0"
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=18.0.0"
|
|
63
|
+
}
|
|
64
|
+
}
|