feat: Rewrite SDK in TypeScript with full type definitions#11
Open
emilio-kariuki wants to merge 6 commits intoIntaSend:masterfrom
Open
feat: Rewrite SDK in TypeScript with full type definitions#11emilio-kariuki wants to merge 6 commits intoIntaSend:masterfrom
emilio-kariuki wants to merge 6 commits intoIntaSend:masterfrom
Conversation
- Convert all 6 source modules (requests, intasend, collection, payouts, wallets, refunds) from JS to fully typed TypeScript - Add src/types.ts with shared interfaces for all API payloads (ChargePayload, MpesaStkPushPayload, PayoutPayload, etc.) - Enable strict mode in tsconfig with ES2018 target - Split tsconfig: root for IDE support, tsconfig.build.json for compilation (src only) - Use ES module imports internally, compile to CommonJS - Re-export all types and service classes from main entry point - Add generic send<T>() method on RequestClient for typed responses
- Add Jest + ts-jest for TypeScript test execution
- Add test helper (tests/helpers.ts) with https mock utilities:
mockHttpsRequest, mockHttpsError, mockHttpsNetworkError
- Add 74 unit tests across 6 test files:
- intasend.test.ts: client init, service factories, credential propagation
- requests.test.ts: auth headers, routing, request body, response handling
- collection.test.ts: charge, mpesaStkPush, status (with/without signature)
- payouts.test.ts: initiate, mpesa, mpesaB2B, bank, intasend, airtime,
approve, status
- wallets.test.ts: list, create, get, transactions, intraTransfer,
fundMPesa, fundCheckout
- refunds.test.ts: list, create, get
- All tests mock https.request — no network calls required
- Remove src/example.js from compiled source - Add examples/example.ts with typed usage of the SDK - Keeps example out of the published dist/ package
- Add requires_approval ('YES' | 'NO') option to PayoutPayload type,
aligning with the latest API on the dev branch
- Update example to demonstrate conditional approval flow
- Add module.exports assignment so `require('intasend-node')` returns
the IntaSend class directly (matching the old JS behavior)
- Both `require()` and `import` patterns now work
- Fix PULL_REQUEST.md: correct type names, remove references to
nonexistent features (error classes, JSDoc, ESM), update code
examples to match actual interfaces
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.
feat: Rewrite SDK in TypeScript with full type definitions
Summary
Complete rewrite of the IntaSend Node.js SDK from JavaScript to TypeScript, providing full type safety, improved developer experience, and IDE autocompletion.
Changes
New Features
ChargePayload,PayoutPayload, etc.).d.ts) generated and published automaticallyImprovements
send<T>()method on the HTTP client for typed responsesAPI Coverage
Testing
httpsmodule mocking — no network calls requiredMigration
This is a non-breaking change. Existing JavaScript users can continue using
const IntaSend = require('intasend-node')without modifications, while TypeScript users gain full type safety.Usage Examples
Initialize Client
Collection - M-Pesa STK Push
Collection - Checkout
Payouts - M-Pesa
Wallets
Refunds
Type Definitions
All interfaces are exported for use in your TypeScript projects:
Breaking Changes
None. This is a backward-compatible rewrite. Both
require()andimportpatterns work.