fix: resolve all lint warnings and fix failing playground toolbar test
- Fix playground-toolbar test: URL changed to github.com but test still expected docs.emdashcms.com - create-emdash: extract selectTemplate() to eliminate unsafe/unnecessary type assertions - create-emdash: use type-safe Object.keys filter instead of bare cast - cloudflare/cache: use Reflect.get with typeof guard instead of double type assertion - x402/enforcer: replace unsafe request cast with Reflect.get type guards for CF bot management - x402/middleware: suppress unavoidable virtual module any-cast with eslint comment
This commit is contained in:
@@ -81,9 +81,12 @@ async function getResourceServer(config: X402Config): Promise<x402ResourceServer
|
||||
*/
|
||||
function isBot(request: Request, threshold: number): boolean {
|
||||
// Cloudflare Workers expose cf properties on the request
|
||||
const cf = (request as unknown as { cf?: { botManagement?: { score?: number } } }).cf;
|
||||
const score = cf?.botManagement?.score;
|
||||
if (score == null) return false;
|
||||
const cf: unknown = Reflect.get(request, "cf");
|
||||
if (cf == null || typeof cf !== "object") return false;
|
||||
const bm: unknown = Reflect.get(cf, "botManagement");
|
||||
if (bm == null || typeof bm !== "object") return false;
|
||||
const score: unknown = Reflect.get(bm, "score");
|
||||
if (typeof score !== "number") return false;
|
||||
return score < threshold;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ import x402Config from "virtual:x402/config";
|
||||
import { createEnforcer } from "./enforcer.js";
|
||||
import type { X402Config } from "./types.js";
|
||||
|
||||
const config = x402Config as X402Config;
|
||||
// eslint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- virtual module import has no type info
|
||||
const config: X402Config = x402Config as X402Config;
|
||||
const enforcer = createEnforcer(config);
|
||||
|
||||
export const onRequest = defineMiddleware(async (context, next) => {
|
||||
|
||||
Reference in New Issue
Block a user