sms-transaction-parser
Version:
Parse SMS for transactions to extract relevant information.
78 lines (77 loc) • 2.32 kB
TypeScript
export declare const TransactionType: {
readonly MPesaSentTo: "M-PESA-SENT";
readonly MPesaPaidTo: "M-PESA-PAID";
readonly MShwariDeposit: "M-SHWARI-DEPOSIT";
readonly MShwariWithdraw: "M-SHWARI-WITHDRAW";
readonly MPesaWithdraw: "M-PESA-WITHDRAW";
readonly MPesaDeposit: "M-PESA-DEPOSIT";
};
export declare const FailedParsing: {
readonly NoMatch: "NO-MATCH";
readonly NoTransactionType: "NO-TRANSACTION-TYPE";
readonly NoResult: "NO-RESULT";
};
export type TransactionTypeWithRegex = {
type: typeof TransactionType[keyof typeof TransactionType];
keyPhrase: string;
regex: RegExp;
};
export declare const transactionTypeWithPattern: TransactionTypeWithRegex[];
export type MShwariTransferredToMPesa = {
reference: string;
amount: number;
transactionType: 'transferred';
account: string;
dateTime: number;
mShwariBalance: string;
balance: number;
transactionCost: string;
type: typeof TransactionType;
};
export type MPeseSentTo = {
reference: string;
amount: number;
transactionType: 'sent';
recipient: string;
dateTime: number;
balance: number;
transactionCost: string;
type: typeof TransactionType.MPesaSentTo;
};
export type MPesaPaidTo = {
reference: string;
amount: number;
transactionType: 'paid';
recipient: string;
dateTime: number;
balance: number;
transactionCost: string;
type: typeof TransactionType.MPesaPaidTo;
};
export type MPesaWithdraw = {
reference: string;
dateTime: number;
transactionType: 'Withdraw';
amount: number;
agent: string;
balance: number;
transactionCost: string;
type: typeof TransactionType.MPesaWithdraw;
};
export type MPesaDeposit = {
reference: string;
dateTime: number;
transactionType: 'received';
amount: number;
balance: number;
sender: string;
type: typeof TransactionType.MPesaDeposit;
};
export type ParsedMessage = MShwariTransferredToMPesa | MPeseSentTo | MPesaWithdraw | MPesaPaidTo | MPesaDeposit;
export type ParsedMessageFailure = {
type: typeof FailedParsing.NoMatch;
} | {
type: typeof FailedParsing.NoResult;
} | {
type: typeof FailedParsing.NoTransactionType;
};