refactor: eliminate ~1100 lines of code duplication - #17
Open
lucas-309 wants to merge 3 commits into
Open
Conversation
- Fix test API keys to use valid sk_ prefix format (client validates prefix) - Fix subscription test mocks to match Subscription model field names - Fix cost estimation test URLs (remove incorrect /dashboard prefix) - Fix base URL test to account for auto-appended /v1 - Fix list_subscriptions test mocks to not require exact query string match - Default resilience to disabled (opt-in, not opt-out) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Three fixes for critical/high bloat: 1. core.ts → DripCore base class: index.ts Drip now extends DripCore, inheriting shared methods (ping, createCustomer, getCustomer, trackUsage, startRun, endRun, emitEvent, recordRun, checkEntitlement, etc.) instead of duplicating them. ~1140 lines removed from index.ts. 2. Shared metadata sanitization: Extracted isMetadataPrimitive, SENSITIVE_METADATA_KEY_PATTERN, and sanitizeMetadata into src/sanitize.ts. middleware/core.ts, langchain.ts, and openclaw.ts now import from the shared module instead of each defining their own copy. 3. Consolidated retry: Replaced standalone retryWithBackoff in index.ts with calculateBackoff/isRetryableError from the existing resilience module, eliminating the duplicate retry implementation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
core.tsDripCore base class —index.tsDrip now extends DripCore, inheriting 14 shared methods instead of duplicating them. Removes ~1140 lines from index.ts.isMetadataPrimitive,SENSITIVE_METADATA_KEY_PATTERN,sanitizeMetadata) intosrc/sanitize.ts.middleware/core.ts,langchain.ts, andopenclaw.tsnow import from the shared module.retryWithBackoffwithcalculateBackoff/isRetryableErrorfrom the existing resilience module.Net: -461 lines (960 added, 1421 removed). Zero public API changes — all exports and method signatures are preserved.
Test plan
tsc --noEmitpasses cleanlynpm run buildsucceeds (ESM + CJS + DTS)@drip-sdk/nodeimport path works (Drip class with resilience)@drip-sdk/node/coreimport path works (DripCore as Drip alias)🤖 Generated with Claude Code