From c7d2401b8be61ff795467dab75146415420cbec3 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Wed, 1 Apr 2026 15:35:06 +0100 Subject: [PATCH] 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 --- packages/cloudflare/src/cache/runtime.ts | 4 +- .../tests/db/playground-toolbar.test.ts | 2 +- packages/create-emdash/src/index.ts | 53 ++++++++++--------- packages/x402/src/enforcer.ts | 9 ++-- packages/x402/src/middleware.ts | 3 +- 5 files changed, 41 insertions(+), 30 deletions(-) diff --git a/packages/cloudflare/src/cache/runtime.ts b/packages/cloudflare/src/cache/runtime.ts index 0d3bd2c..ee2e00b 100644 --- a/packages/cloudflare/src/cache/runtime.ts +++ b/packages/cloudflare/src/cache/runtime.ts @@ -134,7 +134,9 @@ function normalizeCacheKey(url: URL): string { */ function resolveEnvValue(explicit: string | undefined, envVarName: string): string | undefined { if (explicit) return explicit; - return (env as Record)[envVarName] as string | undefined; + if (!(envVarName in env)) return undefined; + const value: unknown = Reflect.get(env, envVarName); + return typeof value === "string" ? value : undefined; } /** diff --git a/packages/cloudflare/tests/db/playground-toolbar.test.ts b/packages/cloudflare/tests/db/playground-toolbar.test.ts index 7c4d386..341b61e 100644 --- a/packages/cloudflare/tests/db/playground-toolbar.test.ts +++ b/packages/cloudflare/tests/db/playground-toolbar.test.ts @@ -25,7 +25,7 @@ describe("renderPlaygroundToolbar", () => { it("renders the deploy CTA link", () => { const html = renderPlaygroundToolbar(BASE_CONFIG); expect(html).toContain("Deploy your own"); - expect(html).toContain("docs.emdashcms.com/getting-started"); + expect(html).toContain("github.com/emdash-cms/emdash"); }); it("renders reset and dismiss buttons", () => { diff --git a/packages/create-emdash/src/index.ts b/packages/create-emdash/src/index.ts index c4a3df4..3ddb605 100644 --- a/packages/create-emdash/src/index.ts +++ b/packages/create-emdash/src/index.ts @@ -99,13 +99,39 @@ type CloudflareTemplate = keyof typeof CLOUDFLARE_TEMPLATES; function selectOptions( obj: Readonly>>, ): { value: K; label: string; hint: string }[] { - return (Object.keys(obj) as K[]).map((key) => ({ + const keys: K[] = Object.keys(obj).filter((k): k is K => k in obj); + return keys.map((key) => ({ value: key, label: obj[key].name, hint: obj[key].description, })); } +async function selectTemplate(platform: Platform): Promise { + if (platform === "node") { + const key = await p.select({ + message: "Which template?", + options: selectOptions(NODE_TEMPLATES), + initialValue: "blog", + }); + if (p.isCancel(key)) { + p.cancel("Operation cancelled."); + process.exit(0); + } + return NODE_TEMPLATES[key]; + } + const key = await p.select({ + message: "Which template?", + options: selectOptions(CLOUDFLARE_TEMPLATES), + initialValue: "blog", + }); + if (p.isCancel(key)) { + p.cancel("Operation cancelled."); + process.exit(0); + } + return CLOUDFLARE_TEMPLATES[key]; +} + async function main() { console.clear(); @@ -158,7 +184,7 @@ async function main() { hint: "SQLite + local file storage", }, ], - initialValue: "node", + initialValue: "cloudflare", }); if (p.isCancel(platform)) { @@ -167,28 +193,7 @@ async function main() { } // Step 2: pick template - const templateKey = - platform === "node" - ? await p.select({ - message: "Which template?", - options: selectOptions(NODE_TEMPLATES), - initialValue: "blog", - }) - : await p.select({ - message: "Which template?", - options: selectOptions(CLOUDFLARE_TEMPLATES), - initialValue: "blog", - }); - - if (p.isCancel(templateKey)) { - p.cancel("Operation cancelled."); - process.exit(0); - } - - const templateConfig = - platform === "node" - ? NODE_TEMPLATES[templateKey as NodeTemplate] - : CLOUDFLARE_TEMPLATES[templateKey as CloudflareTemplate]; + const templateConfig = await selectTemplate(platform); // Step 3: pick package manager const detectedPm = detectPackageManager(); diff --git a/packages/x402/src/enforcer.ts b/packages/x402/src/enforcer.ts index 950c7c2..28a8dde 100644 --- a/packages/x402/src/enforcer.ts +++ b/packages/x402/src/enforcer.ts @@ -81,9 +81,12 @@ async function getResourceServer(config: X402Config): Promise {