npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cbe-utils

v1.0.0

Published

A TypeScript utility library for CBE (Commercial Bank of Ethiopia) payment verification and transaction processing

Readme

CBE Utils

A TypeScript utility library for CBE (Commercial Bank of Ethiopia) payment verification, built with Vite and Vitest for modern development.

Overview

CBE Utils provides tools to verify direct deposit transactions by extracting and parsing transaction details from CBE-generated PDF receipts. It supports both transaction reference numbers and direct PDF URLs.

Features

  • PDF Text Extraction - Download and extract text from CBE transaction PDFs
  • Transaction Parsing - Extract structured data from unformatted PDF text
  • Payment Verification - Verify transaction authenticity and timing
  • TypeScript - Full type safety with comprehensive interfaces
  • Modular Architecture - Well-organized, testable code structure
  • Comprehensive Testing - 35+ unit tests with 100% coverage
  • Multiple Input Formats - Support for reference numbers and URLs
  • Age Validation - Configurable transaction age limits

Setup

This project uses pnpm for package management. Make sure you have pnpm installed:

npm install -g pnpm

Install dependencies:

pnpm install

Quick Start

import { verifyPayment } from 'cbe-utils';

// Verify using transaction reference number
const result = await verifyPayment(
  'TXN123456789',  // Transaction reference number
  '12345678'       // Your CBE account number
);

console.log(result);
// {
//   transactionRefNumber: 'TXN123456789',
//   paymentDateTime: Date,
//   totalAmountDebited: '1,500.00 ETB',
//   receiver: 'ACME Corporation',
//   payer: 'John Doe'
// }

API Reference

Main Functions

verifyPayment(transactionRefOrUrl, cbeAccountNumber, options?)

Convenience function for payment verification with minimal configuration.

Parameters:

  • transactionRefOrUrl (string): Transaction reference number or PDF URL
  • cbeAccountNumber (string): Your CBE account number for verification
  • options (object, optional): Configuration overrides

Returns: Promise<TransactionDetails>

// Basic usage
const result = await verifyPayment('TXN123456789', '12345678');

// With custom options
const result = await verifyPayment('TXN123456789', '12345678', {
  maxTransactionAgeHours: 48,
  rejectUnauthorized: true
});

verifyDirectDeposit(transactionRefOrUrl, config)

Advanced verification function with full configuration control.

Parameters:

  • transactionRefOrUrl (string): Transaction reference number or PDF URL
  • config (PaymentVerificationConfig): Complete configuration object

Returns: Promise<TransactionDetails>

import { verifyDirectDeposit } from 'cbe-utils';

const config = {
  cbeAccountNumber: '12345678',
  maxTransactionAgeHours: 24,
  rejectUnauthorized: false
};

const result = await verifyDirectDeposit('TXN123456789', config);

isValidCbeAccountNumber(accountNumber)

Validates CBE account number format.

Parameters:

  • accountNumber (string): Account number to validate

Returns: boolean

import { isValidCbeAccountNumber } from 'cbe-utils';

console.log(isValidCbeAccountNumber('12345678')); // true
console.log(isValidCbeAccountNumber('123abc')); // false

Types

TransactionDetails

interface TransactionDetails {
  transactionRefNumber: string | null;
  paymentDateTime: Date | null;
  totalAmountDebited: string | null;
  receiver: string | null;
  payer: string | null;
}

PaymentVerificationConfig

interface PaymentVerificationConfig {
  cbeAccountNumber: string;
  maxTransactionAgeHours?: number; // Default: 24
  rejectUnauthorized?: boolean;    // Default: false
}

Advanced Usage

Custom PDF Processing

import { 
  extractTextFromPdfUrl, 
  extractTransactionDetails 
} from 'cbe-utils';

// Extract text from PDF
const pdfText = await extractTextFromPdfUrl(pdfUrl, config);

// Parse transaction details
const details = extractTransactionDetails(pdfText, config);

Environment Configuration

Set up environment variables for production use:

# Required
PAYMENT_CBE_ACCOUNT_NUMBER=your_cbe_account_number

# Optional
MAX_TRANSACTION_AGE_HOURS=24
REJECT_UNAUTHORIZED_SSL=false

Error Handling

The library throws descriptive errors for various failure scenarios:

try {
  const result = await verifyPayment('INVALID', '12345678');
} catch (error) {
  console.error(error.message);
  // Possible errors:
  // - "Invalid transaction reference number or URL format"
  // - "Transaction reference number not found in the PDF"
  // - "Transaction is older than 24 hours, cannot verify"
  // - "Failed to download PDF: Network error"
}

Input Formats

Transaction Reference Numbers

  • Alphanumeric characters only: TXN123456789
  • Bank reference codes: REF789ABC123

PDF URLs

  • Direct CBE PDF links: https://apps.cbe.com.et:100/?id=TXN123...
  • Any valid HTTP/HTTPS URL pointing to a CBE transaction PDF

Development Scripts

Testing

# Run tests in watch mode
pnpm test

# Run tests once
pnpm test:run

# Run tests with UI
pnpm test:ui

# Run tests with coverage
pnpm coverage

Building

# Build for production
pnpm build

# Run the built version
pnpm start

Development

# Start development server
pnpm dev

Project Structure

cbe-utils/
├── src/
│   ├── types.ts                  # TypeScript interfaces
│   ├── constants.ts              # Regex patterns and constants
│   ├── pdf-extractor.ts          # PDF download and text extraction
│   ├── transaction-parser.ts     # Transaction detail parsing
│   ├── payment-verifier.ts       # Main verification logic
│   └── index.ts                  # Public API exports
├── test/
│   ├── constants.test.ts         # Constants validation tests
│   ├── transaction-parser.test.ts # Transaction parsing tests
│   ├── payment-verifier.test.ts  # Payment verification tests
│   └── index.test.ts             # Public API integration tests
├── dist/                         # Compiled output
│   ├── index.js                  # ES module build
│   ├── index.cjs                 # CommonJS build
│   └── index.d.ts               # TypeScript declarations
├── coverage/                     # Test coverage reports
└── package.json                  # Dependencies and scripts

Module Usage

The built library supports both ES modules and CommonJS:

// ES modules
import { verifyPayment } from 'cbe-utils';

// CommonJS
const { verifyPayment } = require('cbe-utils');

// Default import
import CBEUtils from 'cbe-utils';
await CBEUtils.verifyPayment('TXN123', '12345678');

Security Considerations

  • SSL Certificates: By default, SSL certificate validation is disabled for CBE services due to their invalid intermediate certificates. Enable rejectUnauthorized: true if you have proper certificate setup.
  • Account Number: Never expose your CBE account number in client-side code.
  • Rate Limiting: Implement appropriate rate limiting when making multiple verification requests.

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-feature
  3. Make your changes and add tests
  4. Run the test suite: pnpm test:run
  5. Commit your changes: git commit -m 'Add new feature'
  6. Push to the branch: git push origin feature/new-feature
  7. Submit a pull request

License

ISC

Support

For issues related to CBE's PDF format changes or API updates, please open an issue with:

  • Sample transaction reference number (if possible)
  • Error message
  • Expected vs actual behavior