Add type definitions for mpesa-node (#46003)

This commit is contained in:
Peter Munyao 2020-07-12 11:03:42 +03:00 committed by GitHub
parent 607b638249
commit 8f4efcd2ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 102 additions and 0 deletions

49
types/mpesa-node/index.d.ts vendored Normal file
View File

@ -0,0 +1,49 @@
// Type definitions for mpesa-node 0.1
// Project: https://github.com/safaricom/mpesa-node-library#readme
// Definitions by: Peter Munyao <https://github.com/petekmunz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { AxiosPromise } from 'axios';
declare class Mpesa {
constructor(config: ConfigOptions);
accountBalance(shortCode: string, idType: string, queueUrl: string, resultUrl: string, remarks?: string, initiator?: string, commandId?: string): AxiosPromise;
b2b(senderParty: string, receiverParty: string, amount: number, queueUrl: string, resultUrl: string, senderType?: number, receiverType?: number, initiator?: string,
commandId?: string, accountRef?: string, remarks?: string): AxiosPromise;
b2c(senderParty: string, receiverParty: string, amount: number, queueUrl: string, resultUrl: string, commandId?: string, initiatorName?: string,
remarks?: string, occasion?: string): AxiosPromise;
c2bRegister(confirmationUrl: string, validationUrl: string, shortCode?: string, responseType?: string): AxiosPromise;
c2bSimulate(msisdn: string, amount: number, billRefNumber: string, commandId?: string, shortCode?: string): AxiosPromise;
lipaNaMpesaOnline(senderMsisdn: string, amount: number, callbackUrl: string, accountRef: string, transactionDesc?: string,
transactionType?: string, shortCode?: string, passKey?: string): AxiosPromise;
lipaNaMpesaQuery(checkoutRequestId: string, shortCode?: string, passKey?: string): AxiosPromise;
oAuth(consumerKey: string, consumerSecret: string, baseURL?: string): AxiosPromise;
reversal(transactionId: string, amount: number, queueUrl: string, resultUrl: string,
shortCode?: string, remarks?: string, occasion?: string, initiator?: string, receiverIdType?: string, commandId?: string): AxiosPromise;
transactionStatus(transactionId: string, amount: number, queueUrl: string, resultUrl: string, shortCode?: string, remarks?: string,
occasion?: string, initiator?: string, receiverIdType?: string, commandId?: string): AxiosPromise;
}
interface ConfigOptions {
consumerKey: string;
consumerSecret: string;
enviroment?: string;
shortCode?: string;
initiatorName?: string;
lipaNaMpesaShortCode?: string;
lipaNaMpesaShortPass?: string;
securityCredential?: string;
certPath?: string;
}
export = Mpesa;

View File

@ -0,0 +1,23 @@
import Mpesa = require('mpesa-node');
const mpesaClient = new Mpesa({ consumerKey: 'test', consumerSecret: 'test' });
mpesaClient.accountBalance('600111', '4', 'someurl/queue', 'someurl/result'); // $ExpectType AxiosPromise<any>
mpesaClient.b2b('600100', '600000', 500, 'someurl/queue', 'someurl/result'); // $ExpectType AxiosPromise<any>
mpesaClient.b2c('600100', '254722123456', 56, 'someurl/queue', 'someurl/result'); // $ExpectType AxiosPromise<any>
mpesaClient.c2bRegister('someurl/confirmation', 'someurl/validation'); // $ExpectType AxiosPromise<any>
mpesaClient.c2bSimulate('254722123456', 98, '123456'); // $ExpectType AxiosPromise<any>
mpesaClient.lipaNaMpesaOnline('254722123456', 45, 'someurl/callback', 'accountref'); // $ExpectType AxiosPromise<any>
mpesaClient.lipaNaMpesaQuery('wsyhjk6455opp'); // $ExpectType AxiosPromise<any>
mpesaClient.oAuth('consumerkey', 'consumersecret'); // $ExpectType AxiosPromise<any>
mpesaClient.reversal('WSDFR578', 456, 'someurl/queue', 'someurl/result'); // $ExpectType AxiosPromise<any>
mpesaClient.transactionStatus('WSDFR578', 578, 'someurl/queue', 'someurl/result'); // $ExpectType AxiosPromise<any>

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"axios": "^0.19.2"
}
}

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"mpesa-node-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }