Skip to content

feat: comprehensive SDK improvements - error handling, build system, testing, and documentation#17

Merged
fireayehu merged 53 commits into
fireayehu:mainfrom
haxurn:chore/improvements
Feb 14, 2026
Merged

feat: comprehensive SDK improvements - error handling, build system, testing, and documentation#17
fireayehu merged 53 commits into
fireayehu:mainfrom
haxurn:chore/improvements

Conversation

@haxurn
Copy link
Copy Markdown
Contributor

@haxurn haxurn commented Feb 13, 2026

Overview

Major improvements to the chapa-nodejs SDK including modernized build system, enhanced error handling, comprehensive testing, and complete documentation.

Breaking Changes

  • Migrated from Yup to Zod for validation (synchronous API)
  • Updated minimum Node.js version from 10 to 18
  • Migrated from tsdx to Rollup build system

Core Improvements

Error Handling

  • Centralized error handler with TypeScript type guards
  • Created withErrorHandling() wrapper to eliminate duplicate try-catch blocks
  • Proper AxiosError and Zod error handling

Build System

  • Migrated from deprecated tsdx to modern Rollup
  • Generates both CJS (dist/index.js) and ESM (dist/index.esm.js) bundles
  • Proper TypeScript declaration files

Validation

  • Migrated from Yup to Zod
  • Synchronous validation (removed unnecessary await calls)
  • Better type inference and error messages

HTTP Client

  • Created configured axios instance with base URL and timeout
  • Added retry logic for failed requests (configurable)
  • Request/response logging and debug mode
  • Proper authorization headers

Testing

  • Added 55 tests across 7 test suites
  • Achieved 85%+ test coverage
  • Configured Jest with ts-jest
  • Coverage reporting to Codecov

CI/CD

  • GitHub Actions workflow for testing on Node 18/20/22
  • Automated publish workflow with pre-publish checks
  • Codecov integration

Documentation

  • Created CONTRIBUTING.md with development guidelines
  • Created SECURITY.md with vulnerability reporting process
  • Created CODE_OF_CONDUCT.md
  • Added GitHub issue templates (bug, feature, question)
  • Added pull request template
  • Updated README with badges, collapsible sections, and project stats

Developer Experience

  • Added .nvmrc for Node version management
  • Added .editorconfig for consistent coding style
  • Updated .gitignore and .npmignore
  • Updated husky pre-commit hook (lint + format check + tests)
  • Added Prettier for code formatting

Files Changed

  • Core: src/chapa.ts, src/error-handler.ts, src/utils.ts, src/axios-instance.ts, src/webhook.ts
  • Validation: All files in src/validations/ migrated to Zod
  • Tests: test/*.test.ts (7 test files)
  • Config: package.json, tsconfig.json, rollup.config.mjs, jest.config.js
  • CI/CD: .github/workflows/ci.yml, .github/workflows/publish.yml
  • Templates: .github/ISSUE_TEMPLATE/*, .github/PULL_REQUEST_TEMPLATE.md
  • Docs: README.md, CONTRIBUTING.md, SECURITY.md, CODE_OF_CONDUCT.md
  • Tooling: .nvmrc, .editorconfig, .gitignore, .npmignore, .husky/pre-commit

Testing

  • All tests pass (54 tests)
  • Coverage meets threshold (85%+)
  • Linting passes
  • Build succeeds
  • Types are correct

Checklist

  • Code follows project style guidelines
  • Tests added/updated
  • Documentation updated
  • No breaking changes to public API (except validation library)
  • Commit messages follow conventional commits

- Replace yup validation library with zod for schema validation
- Convert validateRefundOptions from async to synchronous function
- Update schema definition to use zod syntax with z.object() and z.string()
- Simplify validation call from schema.validate() to schema.parse()
- Maintain same validation rules for tx_ref, reason, amount, and meta fields
- Add .changeset/config.json with schema reference and default settings
- Configure changelog generation using @changesets/cli
- Set access level to restricted for package publishing
- Set base branch to main for version tracking
- Configure internal dependency updates to patch level
- Disable automatic commit creation on version bumps
- Add bug report template with reproduction steps and environment details
- Add feature request template with problem statement and proposed solution
- Add question template for user inquiries
- Add issue template config to disable blank issues and link to documentation
- Standardize issue creation workflow with structured forms
- Add CI workflow that runs on push to main and develop branches
- Add pull request trigger for main and develop branches
- Configure matrix testing across Node.js versions 18.x, 20.x, and 22.x
- Add steps for dependency installation with pnpm frozen lockfile
- Add format check, linting, and test execution steps
- Add build step to verify compilation
- Add codecov integration for coverage reporting on Node.js 20.x
- Automate quality checks and test execution on code changes
- Add GitHub pull request template to standardize PR submissions
- Include sections for description, change type, and related issues
- Add checklist for code quality, testing, and documentation requirements
- Provide structure for contributors to follow when creating pull requests
- Add pre-commit hook configuration to run linting checks
- Add pre-commit hook configuration to run format validation
- Add pre-commit hook configuration to run test suite
- Ensures code quality and consistency before commits are made
- Add ChapaErrorResponse interface for standardized error responses
- Add isAxiosError type guard function to safely check Axios errors
- Create types/index.ts barrel export for centralized type exports
- Establish foundation for consistent error handling across the SDK
- Replace yup validation library with zod in transaction.validation.ts
- Replace yup validation library with zod in transfer.validation.ts
- Convert validateGetTransactionLogsOptions to synchronous function using zod.parse()
- Convert validateTransferOptions to synchronous function using zod.parse()
- Convert validateBulkTransferOptions to synchronous function using zod.parse()
- Convert validateVerifyTransferOptions to synchronous function using zod.parse()
- Extract schema definitions to module level for better reusability
- Remove async/await patterns in favor of synchronous zod validation
- Simplify schema definitions by removing explicit .required() calls (zod fields are required by default)
- Create axios instance factory with configurable base URL and timeout
- Add request/response logging with sensitive data redaction
- Implement automatic retry logic for failed requests with exponential backoff
- Add debug mode for detailed request/response inspection
- Sanitize headers and request/response data to prevent credential leakage
- Support Bearer token authentication via secret key parameter
…idation errors

- Add error handler utility to normalize axios and zod validation errors
- Implement axios status code resolution for network errors (timeouts, connection refused, host unreachable)
- Map axios errors to appropriate HTTP status codes (408 for timeouts, 503 for connection errors, 500 default)
- Handle zod validation errors with 400 status code and first issue message
- Provide consistent error response format through HttpException wrapper
- Enables standardized error handling across the application for external API calls and input validation
- Add withErrorHandling generic function to wrap async operations
- Integrate centralized error handling via handleChapaError
- Provide reusable pattern for consistent error management across async calls
- Add WebhookPayload interface for type-safe webhook data handling
- Implement verifyWebhookSignature function to validate webhook authenticity
- Add constantTimeEquals helper for secure signature comparison to prevent timing attacks
- Support both string and object payload formats with automatic JSON serialization
- Use HMAC-SHA256 for cryptographic signature generation and validation
- Add comprehensive tests for verifyWebhookSignature utility function
- Test valid signature verification with object payload
- Test valid signature verification with string payload
- Test detection of tampered payload signatures
- Test rejection of signatures with incorrect secret
- Ensure webhook signature validation works correctly before deployment
- Add payment validation tests for initialize and verify options
- Add subaccount creation validation tests with split type validation
- Add direct charge validation tests for mobile payment options
- Add transfer validation tests for bank account transfers
- Add refund validation tests for transaction refunds
- Test both valid inputs and error cases for all validation schemas
- Ensure zod schema validation errors are properly thrown on invalid data
- Remove verbose inline comments for cleaner configuration
- Update target to ES2017 for better compatibility
- Simplify lib configuration to ES2017 only
- Add explicit output directory configuration (dist)
- Add declaration directory mapping for type definitions
- Remove JSX transpilation (react) as not needed for this project
- Add Node and Jest type definitions
- Consolidate and remove redundant compiler options
- Improve maintainability by reducing comment clutter
- Add supported versions table with version support status
- Document vulnerability reporting process and contact information
- Include response time expectations for security issues
- Add disclosure policy for coordinated vulnerability announcements
- List security best practices for library users
- Document available security features including webhook verification and type-safe validation
- Establish clear guidelines for responsible disclosure
- Add Rollup configuration with CommonJS and ESM output formats
- Configure TypeScript plugin to compile source files with sourcemap support
- Set up node-resolve and commonjs plugins for dependency resolution
- Mark axios, nanoid, nanoid-dictionary, and zod as external dependencies
- Add rollup-plugin-dts for bundled type definitions generation
- Enable sourcemaps for both output formats to aid debugging
- Add Chapa class integration tests covering transaction initialization, verification, and mobile payments
- Add error handler utility tests for axios and validation error handling
- Add HTTP exception tests for error response handling
- Add utility function tests for common helper functions
- Add refund endpoint tests with improved coverage
- Ensure all core SDK functionality is properly tested with mocked axios instances
- Add comprehensive Code of Conduct document outlining community standards
- Define positive behavior expectations including inclusivity and respect
- Document unacceptable behaviors and enforcement procedures
- Establish clear reporting mechanism for violations
- Adapt from Contributor Covenant v2.0 for consistency with industry standards
- Add root EditorConfig configuration file for project-wide editor settings
- Configure UTF-8 charset and LF line endings for all files
- Set 2-space indentation for consistent code style across the project
- Enable automatic final newline insertion and trailing whitespace trimming
- Preserve trailing whitespace in Markdown files for proper formatting
- Ensure consistent YAML indentation settings
- Standardize development environment configuration across team members
- Add .npmignore to exclude source files, configs, and dev dependencies from npm package
- Add .nvmrc to specify Node.js version 20.10.0 for consistent development environment
- Add .prettierrc with code formatting rules (80 char width, semicolons, single quotes, trailing commas)
- Add eslint.config.js with TypeScript and Jest support for comprehensive linting coverage
- Ensures consistent code quality and formatting across the project and for contributors
- Add comprehensive CHANGELOG.md documenting v2.3.0 features and improvements
- Add CONTRIBUTING.md with guidelines for bug reports, feature requests, and pull requests
- Add bump.config.json for version management configuration
- Include development setup instructions and coding standards
- Document project structure and testing guidelines
- Establish contribution workflow and commit message conventions
@haxurn
Copy link
Copy Markdown
Contributor Author

haxurn commented Feb 13, 2026

@fireayehu what do you think about this changes?

- Remove codecov badge link from README shields section
- Simplify badge display by removing coverage tracking reference
Comment thread .github/workflows/publish.yml
Comment thread .github/workflows/publish.yml
Comment thread .github/workflows/publish.yml
Comment thread .github/workflows/publish.yml Outdated
Copy link
Copy Markdown
Contributor Author

@haxurn haxurn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback earlier. I’ve addressed all the requested changes and updated the implementation accordingly. Everything should now align with the project’s expectations. Looks good from my side ready to merge to main when you are.

@haxurn haxurn requested a review from fireayehu February 13, 2026 15:42
@fireayehu fireayehu merged commit 396d49a into fireayehu:main Feb 14, 2026
3 checks passed
@haxurn haxurn deleted the chore/improvements branch February 14, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants