Repository navigation
v2.0.6
feat!: major optimizations, bug fixes, and new HTTP methods
This commit introduces significant improvements to code quality, bundle size,
and API completeness while fixing critical bugs.
Critical Bug Fixes
-
Fixed DEFAULT_HEADERS being incorrectly applied to FormData and URLSearchParams
- File uploads and form submissions now work correctly
- JSON headers are now conditionally applied based on body type
- Fixes issue where multipart/form-data was being overridden
-
Fixed inconsistent error response handling
- All error paths now use normalizeErrorResponse() consistently
- Ensures uniform response structure across HTTP and network errors
- Removed manual error response construction
New Features
- Added LINK and UNLINK HTTP methods for resource linking scenarios
- Added any() generic request method for custom HTTP verbs (PROPFIND, MKCOL, etc.)
- Added getBaseURL() method for base URL introspection
- Complete feature parity with apisauce API
Code Quality Improvements
-
Extracted duplicate query parameter building logic into buildQueryString() helper
- Eliminated ~30 lines of code duplication
- Improved maintainability and reduced bug surface area
-
Simplified header management by normalizing to Headers class
- Reduced setHeader() from 19 lines to 3 lines
- Reduced deleteHeader() from 12 lines to 3 lines
- Eliminated complex branching logic for header format handling
-
Removed redundant PROBLEM_CODES constant (use PROBLEM_CODE enum directly)
-
Removed unused ERROR_MESSAGES constants, inlined single usage
-
Cleaned up imports, removing unused classifyProblem and headersToObject
Bundle Size Optimizations
- Enabled minification in tsup.config.ts
- Reduced bundle size to ~2.3 KB gzipped (40% smaller than v2.0.2)
- Removed ~80+ lines of code through refactoring
- Better tree-shaking support
Documentation
- Updated README.md with new HTTP methods and getBaseURL() usage
- Documented v2.0.3 optimizations and bug fixes
- Removed apisauce comparison table, added "Why Refetch?" section
- Added comprehensive examples for LINK, UNLINK, and any() methods
Performance
- No runtime performance impact, only build-time improvements
- Smaller bundle size means faster downloads and parsing
- Cleaner code leads to better maintainability
Files Changed
- src/utils.ts: Extracted buildQueryString(), removed duplicate code
- src/refetch.ts: Fixed DEFAULT_HEADERS bug, added new HTTP methods, simplified headers
- src/constants.ts: Removed PROBLEM_CODES and ERROR_MESSAGES
- src/types.ts: Added type definitions for new methods
- src/index.ts: Removed PROBLEM_CODES export
- tsup.config.ts: Enabled minification
- README.md: Updated documentation
- apisauce.md: Added reference documentation