# Changelog

All notable changes to this project will be doc# Changelog

All notable changes to this project will be documented in this file.

## [0.2.16] - 2025-01-02

### Fixed
- Replaced invalid wildcard parameter access (`getNodeParameter('*')`) with per-field parameter retrieval
- Prevents "Could not get parameter '*'" runtime error

### Improved
- Support both `routing.send` and `routing.request` mappings to build qs/body/headers
- More resilient handling when optional params are hidden or unset

## [0.2.17] - 2025-10-02

### Added
- Optional "Additional Headers" parameter (key/value) merged into request headers

### Improved
- Enriched error reporting: includes status, response body, and request context (sans Authorization) when continueOnFail is enabled
- Keeps detailed request logging for server-side debugging

## [0.2.15] - 2025-01-02

### Added
- Proper handling of query parameters, request body, and headers from generated properties
- Detailed request logging for debugging (check n8n server logs)
- Logs show: method, URL, headers (Authorization redacted), query string, and body

### Fixed
- Query parameters now properly sent to Schwab API
- Request body properly serialized for POST/PUT requests
- Custom headers from OpenAPI spec now included in requests

### Technical Details
- Parses routing.send configuration from generated properties
- Dynamically builds `qs`, `body`, and `headers` based on user input
- Only includes non-empty parameters in requests

## [0.2.14] - 2025-01-02

### Fixed
- **CRITICAL**: Fixed "Invalid URL" error by properly constructing absolute URLs
- URLs from generated properties are relative (e.g. `=/accounts/accountNumbers`)
- Now strips n8n expression prefix (`=/`) and combines with base URL
- Properly builds full URL: `https://api.schwabapi.com/trader/v1/accounts/accountNumbers`

## [0.2.13] - 2025-01-02

### Fixed
- **CRITICAL**: Implemented custom `execute()` method to properly inject OAuth2 Bearer token
- Previous versions were using declarative `requestDefaults` which bypasses n8n's OAuth2 authentication layer
- Now explicitly calls `this.helpers.requestOAuth2()` to ensure Bearer token is properly injected into API requests
- This should resolve the persistent 500 Internal Server Error from Schwab API

### Technical Details
- `@devlikeapro/n8n-openapi-node` generates declarative routing but doesn't handle OAuth2 authentication
- Added custom execute method that:
  - Reads routing information from generated properties
  - Builds request options with proper headers
  - Uses `this.helpers.requestOAuth2.call()` with `tokenType: 'Bearer'`
  - Properly handles URL parameter substitution

## [0.2.12] - 2025-01-02mented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.7] - 2025-01-02

### Fixed
- **CRITICAL**: Removed ThirdPartyId header (not required by actual Schwab API)
- Removed unnecessary `appKey` credential field
- Simplified headers to match working implementation: Bearer token + Accept + Content-Type only
- Changed default scope from 'readonly' to 'api' per Schwab documentation

### Changed
- Headers now match official Schwab OAuth implementation
- Credentials simplified to only use OAuth2 base fields (clientId, clientSecret)

## [0.2.6] - 2025-01-02

### Added
- **App Key field** in credentials for explicit ThirdPartyId header configuration
- Comprehensive OAuth 2.0 compliance documentation (SCHWAB_OAUTH_COMPLIANCE.md)
- Full Schwab API security requirements documentation

### Fixed
- Improved ThirdPartyId header implementation using dedicated `appKey` credential field
- More reliable credential field access for API headers

### Changed
- ThirdPartyId now uses `appKey` field instead of attempting to access `clientId`
- Enhanced credential setup with clear field naming ("App Key (Client ID)")

## [0.2.5] - 2025-01-02

### Fixed
- **CRITICAL**: Added required `ThirdPartyId` header to all API requests
  - Schwab API requires this header with the application's Client ID
  - Fixes "500 Internal Server Error" when making API calls
  - Header is automatically populated from OAuth2 credentials

## [0.2.4] - 2025-01-02

### Changed
- Updated node icon to official Charles Schwab Corporation logo
- Improved visual branding consistency

## [0.2.3] - 2025-01-02

### Fixed
- **CRITICAL**: Eliminated runtime dependency on `@devlikeapro/n8n-openapi-node`
  - Node properties are now pre-generated at build time
  - Generated static `generated-properties.json` file from OpenAPI spec
  - `@devlikeapro/n8n-openapi-node` moved back to devDependencies (build-time only)
  - This completely eliminates the "Cannot find module" error in n8n

### Changed
- Added `generate-properties` script to build process
- Node now loads pre-generated properties instead of building them at runtime
- Significantly reduced runtime overhead (no OpenAPI parsing needed)

## [0.2.2] - 2025-01-02

### Fixed
- **CRITICAL**: Moved `@devlikeapro/n8n-openapi-node` from devDependencies to dependencies
  - This package is required at runtime by the compiled node code
  - Fixes "Cannot find module '@devlikeapro/n8n-openapi-node'" error when loading in n8n

## [0.2.1] - 2025-01-02

### Fixed
- **CRITICAL**: Fixed package.json n8n section to point to compiled .js files instead of .ts source files
  - Changed credentials path: `credentials/SchwabOAuth2Api.credentials.ts` → `dist/credentials/SchwabOAuth2Api.credentials.js`
  - Changed node path: `nodes/Schwab/Schwab.node.ts` → `dist/nodes/Schwab/Schwab.node.js`
  - This fixes the "Cannot find module" error when loading the package in n8n

## [0.2.0] - 2025-01-02

### Changed
- **BREAKING**: Migrated from manual OAuth credentials to n8n's native OAuth2 API
  - Credentials now extend `oAuth2Api` base class
  - Renamed credential from `schwabApi` to `schwabOAuth2Api`
  - Automatic token refresh now handled by n8n
  - No more manual authorization code exchange required

### Added
- Native OAuth2 support with automatic token management
- Automatic access token refresh
- OAuth2 connection button in n8n UI
- Hidden OAuth configuration fields (authUrl, accessTokenUrl, scope, etc.)
- Improved OAuth setup documentation

### Improved
- Simplified credential setup process - just click "Connect" and authorize
- Better error handling for OAuth flows
- More secure token storage and refresh
- Updated OAUTH_SETUP.md with detailed OAuth2 instructions
- Enhanced README with v0.2.0 features

### Migration Notes
If upgrading from v0.1.0:
1. You'll need to create new credentials (old manual credentials won't work)
2. Delete old `Schwab API` credentials
3. Create new `Schwab OAuth2 API` credentials
4. Click "Connect" and authorize with Schwab
5. Update workflows to use new credentials

## [0.1.0] - 2025-01-XX

### Added
- Initial release
- Support for Schwab Trader API
- Account operations (get accounts, get balances, get positions)
- Order operations (place, cancel, replace, get orders)
- Transaction operations (get transactions, get by ID)
- User preference operations
- Manual OAuth2 implementation with authorization code flow
- OpenAPI 3.0.1 specification parsing
- Auto-generated node properties from OpenAPI spec

### Features
- Account Management
  - Get Account Numbers
  - Get All Accounts
  - Get Specific Account
- Order Management
  - Get Orders (by account or all accounts)
  - Place Order
  - Cancel Order
  - Replace Order
  - Get Order by ID
- Transactions
  - Get Transactions
  - Get Transaction by ID
- User Preferences
  - Get User Preference

### Documentation
- README with installation and usage instructions
- OAUTH_SETUP guide for credential setup
- OpenAPI specification included

---

[0.2.7]: https://github.com/your-repo/n8n-nodes-schwab/compare/v0.2.6...v0.2.7
[0.2.6]: https://github.com/your-repo/n8n-nodes-schwab/compare/v0.2.5...v0.2.6
[0.2.5]: https://github.com/your-repo/n8n-nodes-schwab/compare/v0.2.4...v0.2.5
[0.2.4]: https://github.com/your-repo/n8n-nodes-schwab/compare/v0.2.3...v0.2.4
[0.2.3]: https://github.com/your-repo/n8n-nodes-schwab/compare/v0.2.2...v0.2.3
[0.2.2]: https://github.com/your-repo/n8n-nodes-schwab/compare/v0.2.1...v0.2.2
[0.2.1]: https://github.com/your-repo/n8n-nodes-schwab/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/your-repo/n8n-nodes-schwab/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/your-repo/n8n-nodes-schwab/releases/tag/v0.1.0

## [0.2.18] - 2025-10-02

### Fixed
- Avoid sending `Content-Type` on GET requests and when there is no request body
- Never send a body with GET requests
- Add standard `User-Agent` header (n8n-nodes-schwab)

## [0.2.19] - 2025-10-02

### Added
- Credentials: Client Authentication option (Header Basic vs Body) for token and refresh exchanges. This can resolve `refresh_token_authentication_error` on some Schwab environments that expect credentials in the body.

## [0.2.20] - 2025-10-02

### Fixed
- Normalize responses that arrive as JSON strings by parsing them to objects
- If the API returns an array, flatten it into one n8n item per element
