Conversation
- Extract encoding utilities to src/utils/encoding.ts - Consolidate X402PaymentRequired type to src/types.ts - Consolidate StorageDO ID generation into single helper - Extract JSON parsing helper in StorageDO - Update CLAUDE.md to reflect actual 3-tier pricing model - Clarify base endpoint aliases are semantic, not pricing tiers Net reduction: 176 lines (138 added, 314 removed) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create createHashingEndpoint() factory in base.ts - Extract keccak256 implementation to keccak256-impl.ts - Refactor all 6 hashing endpoints to use factory pattern - Each endpoint now ~15 lines of config vs ~100+ lines of duplicated code Net reduction: 411 lines (from 742 to 331 across hashing endpoints) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Centralize duplicate validation helpers to _shared_utils.ts: - hasTokenType, hasField, hasFields, isOk functions - validators object with additional helpers (resultEquals, resultIsString, etc.) - Remove duplicates from endpoint-registry.ts and _test_generator.ts Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Create shared schema helpers to reduce duplication: - tokenTypeParam, response constants (402, 400, 404, 500) - Property type helpers (okProp, stringProp, boolProp, etc.) - Parameter builders (pathParam, queryParamString, queryParamInt) Update KV and Paste storage endpoints to use shared schemas. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove types that were defined but never used: - PricingConfig - HealthResponse - ErrorResponse Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
x402-api-production | 82337f7 | Jan 20 2026, 07:43 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
x402-api-production | 0dba0e6 | Jan 20 2026, 07:08 PM |
There was a problem hiding this comment.
Pull request overview
This PR consolidates duplicated code patterns across the codebase, reducing net lines by 580 while improving maintainability. The refactoring focuses on creating shared utilities, consolidating type definitions, and implementing factory patterns to eliminate repetitive code.
Changes:
- Consolidated
X402PaymentRequiredandTokenContracttypes tosrc/types.tsand removed 7 duplicate definitions across test files - Created shared encoding utilities (
src/utils/encoding.ts) for hex/base64 conversions used by hashing endpoints - Created hashing endpoint factory pattern that reduced 6 endpoints from ~120 lines each to ~15 lines
- Consolidated test validation helpers to
_shared_utils.tsand created OpenAPI schema helpers insrc/endpoints/schema.ts - Simplified StorageDO ID generation with shared helper functions
- Removed 3 unused type definitions (
PricingConfig,HealthResponse,ErrorResponse)
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/types.ts | Added consolidated X402PaymentRequired and TokenContract types, removed unused type definitions |
| src/utils/encoding.ts | New shared encoding utilities for hex/bytes/base64 conversions |
| src/endpoints/schema.ts | New shared OpenAPI schema definitions for common parameters and responses |
| src/endpoints/hashing/base.ts | New factory function for creating hashing endpoints with shared logic |
| src/endpoints/hashing/*.ts | Refactored 6 hashing endpoints to use factory pattern (SHA256, SHA512, SHA512-256, Keccak256, RIPEMD160, Hash160) |
| src/endpoints/hashing/keccak256-impl.ts | Extracted Keccak-256 implementation to separate file |
| src/endpoints/storage//.ts | Updated storage endpoints to use shared schema definitions |
| src/middleware/x402.ts | Updated to import X402PaymentRequired and TokenContract from types.ts |
| src/durable-objects/StorageDO.ts | Consolidated ID generation with generateRandomString helper and parseJsonField helper |
| tests/_shared_utils.ts | Added consolidated validation helpers (hasTokenType, hasField, hasFields, isOk, validators) |
| tests/_test_generator.ts | Removed duplicate validators and X402PaymentRequired, now imports from shared locations |
| tests/endpoint-registry.ts | Updated to import validation helpers from _shared_utils.ts |
| tests/*-lifecycle.test.ts | Updated 7 test files to import X402PaymentRequired from _test_generator |
| tests/_run_all_tests.ts | Updated imports for X402PaymentRequired |
| src/endpoints/base.ts | Added clarifying documentation for endpoint class aliases |
| CLAUDE.md | Updated pricing documentation for clarity |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address PR feedback: use tokenTypeParam, response400, response402 from schema.ts instead of inline definitions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Addressed Copilot's feedback in 82337f7 - now using |
Summary
First pass of code simplification across the codebase, reducing duplication and consolidating common patterns.
X402PaymentRequiredtype, simplified StorageDO ID generation_shared_utils.tsTotal: 33 files changed, -580 net lines
Test plan
npm run check- type check passesnpm test- existing tests should pass/docsendpoint still renders OpenAPI spec correctly🤖 Generated with Claude Code