feat(export): add buffer download methods to ExportBuilder
- Added download() method to get statements as Buffer without saving to disk - Added downloadAsArrayBuffer() method for web API compatibility - Enhanced documentation for getAccountStatement() method - Updated README with comprehensive examples - No breaking changes, backward compatible
This commit is contained in:
@@ -1,71 +1,48 @@
|
||||
# bunq API Client Implementation Plan
|
||||
# Migration Plan: @push.rocks/smartrequest
|
||||
|
||||
cat /home/philkunz/.claude/CLAUDE.md
|
||||
To re-read CLAUDE.md: `cat ~/.claude/CLAUDE.md`
|
||||
|
||||
## Phase 1: Remove External Dependencies & Setup Core Infrastructure
|
||||
## Objective
|
||||
Migrate the Bunq HTTP client from native `fetch` to `@push.rocks/smartrequest` to leverage built-in rate limiting, better error handling, and improved maintainability.
|
||||
|
||||
- [x] Remove @bunq-community/bunq-js-client dependency from package.json
|
||||
- [x] Remove JSONFileStore and bunqCommunityClient from bunq.plugins.ts
|
||||
- [x] Create bunq.classes.apicontext.ts for API context management
|
||||
- [x] Create bunq.classes.httpclient.ts for HTTP request handling
|
||||
- [x] Create bunq.classes.crypto.ts for cryptographic operations
|
||||
- [x] Create bunq.classes.session.ts for session management
|
||||
- [x] Create bunq.interfaces.ts for shared interfaces and types
|
||||
## Tasks
|
||||
|
||||
## Phase 2: Implement Core Authentication Flow
|
||||
### 1. Setup
|
||||
- [x] Install @push.rocks/smartrequest dependency using pnpm
|
||||
- [x] Update ts/bunq.plugins.ts to import smartrequest
|
||||
|
||||
- [x] Implement RSA key pair generation in crypto class
|
||||
- [x] Implement installation endpoint (`POST /v1/installation`)
|
||||
- [x] Implement device registration (`POST /v1/device-server`)
|
||||
- [x] Implement session creation (`POST /v1/session-server`)
|
||||
- [x] Implement request signing mechanism
|
||||
- [x] Implement response verification
|
||||
- [x] Add session token refresh logic
|
||||
### 2. Refactor BunqHttpClient
|
||||
- [x] Replace fetch-based makeRequest method with SmartRequest implementation
|
||||
- [x] Preserve all custom headers (X-Bunq-*)
|
||||
- [x] Maintain request signing functionality
|
||||
- [x] Keep response signature verification
|
||||
- [x] Map LIST method to GET (SmartRequest doesn't have LIST)
|
||||
- [x] Replace manual retry logic with built-in handle429Backoff()
|
||||
|
||||
## Phase 3: Update Existing Classes
|
||||
### 3. Error Handling
|
||||
- [x] Ensure BunqApiError is still thrown for API errors
|
||||
- [x] Map SmartRequest errors to appropriate error messages
|
||||
- [x] Preserve error message format for backward compatibility
|
||||
|
||||
- [x] Refactor BunqAccount class to use new HTTP client
|
||||
- [x] Update BunqMonetaryAccount to work with new infrastructure
|
||||
- [x] Update BunqTransaction to work with new infrastructure
|
||||
- [x] Add proper TypeScript interfaces for all API responses
|
||||
- [x] Implement error handling with bunq-specific error types
|
||||
### 4. Testing
|
||||
- [x] Run existing tests to ensure no regression (tests passing)
|
||||
- [x] Verify rate limiting behavior works correctly
|
||||
- [x] Test signature creation and verification
|
||||
- [x] Ensure all HTTP methods (GET, POST, PUT, DELETE, LIST) work
|
||||
|
||||
## Phase 4: Implement Additional API Resources
|
||||
### 5. Cleanup
|
||||
- [x] Remove unused code from the old implementation (manual retry logic removed)
|
||||
- [x] Update any relevant documentation or comments
|
||||
|
||||
- [x] Create bunq.classes.user.ts for user management
|
||||
- [x] Create bunq.classes.payment.ts for payment operations
|
||||
- [x] Create bunq.classes.card.ts for card management
|
||||
- [x] Create bunq.classes.request.ts for payment requests
|
||||
- [x] Create bunq.classes.schedule.ts for scheduled payments
|
||||
- [x] Create bunq.classes.draft.ts for draft payments
|
||||
- [x] Create bunq.classes.attachment.ts for file handling
|
||||
- [x] Create bunq.classes.export.ts for statement exports
|
||||
- [x] Create bunq.classes.notification.ts for notifications
|
||||
- [x] Create bunq.classes.webhook.ts for webhook management
|
||||
## Implementation Notes
|
||||
|
||||
## Phase 5: Enhanced Features
|
||||
### Key Changes
|
||||
1. Replace native fetch with SmartRequest fluent API
|
||||
2. Use built-in handle429Backoff() instead of manual retry logic
|
||||
3. Leverage SmartRequest's response methods (.json(), .text())
|
||||
4. Maintain all Bunq-specific behavior (signatures, custom headers)
|
||||
|
||||
- [x] Implement pagination support for all list endpoints
|
||||
- [x] Add rate limiting compliance
|
||||
- [x] Implement retry logic with exponential backoff
|
||||
- [x] Add request/response logging capabilities
|
||||
- [x] Implement webhook signature verification
|
||||
- [x] Add OAuth flow support for third-party apps
|
||||
|
||||
## Phase 6: Testing & Documentation
|
||||
|
||||
- [ ] Write unit tests for crypto operations
|
||||
- [ ] Write unit tests for HTTP client
|
||||
- [ ] Write unit tests for all API classes
|
||||
- [ ] Create integration tests using sandbox environment
|
||||
- [x] Update main README.md with usage examples
|
||||
- [x] Add JSDoc comments to all public methods
|
||||
- [x] Create example scripts for common use cases
|
||||
|
||||
## Phase 7: Cleanup & Optimization
|
||||
|
||||
- [x] Remove all references to old bunq-community client
|
||||
- [x] Optimize bundle size
|
||||
- [x] Ensure all TypeScript types are properly exported
|
||||
- [x] Run build and verify all tests pass
|
||||
- [x] Update package version
|
||||
### Risk Mitigation
|
||||
- All Bunq-specific logic remains unchanged
|
||||
- Public API of BunqHttpClient stays the same
|
||||
- Error handling maintains same format
|
Reference in New Issue
Block a user