@johntad/m-pesa
Version:
A TypeScript SDK for integrating M-Pesa mobile payment services into applications, enabling seamless money transfers and transactions.
82 lines (81 loc) • 2.7 kB
TypeScript
/**
* Utilities for SDK Development
* This file contains common utilities for input validation,
* date/time formatting, string manipulation and more
*/
/**
* Input Validation Utility
*/
export declare class Validator {
/**
* Validates that a required field is present and non-empty.
* @param value - The value to validate.
* @param fieldName - The name of the field for error messages.
*/
static validateRequired(value: unknown, fieldName: string): void;
/**
* Validates that a value is a positive number.
* @param value - The value to validate.
* @param fieldName - The name of the field for error messages.
*/
static validatePositiveNumber(value: unknown, fieldName: string): void;
/**
* Validates that a URL is properly formatted.
* @param url - The URL to validate.
* @param fieldName - The name of the field for error messages.
*/
static validateURL(url: string, fieldName: string): void;
}
/**
* Date/Time Utility
*/
export declare class DateTimeUtil {
/**
* Formats a Date object into the required API format (YYYYMMDDHHmmss).
* @param date - The date to format.
* @returns The formatted date string.
*/
static formatToApiTimestamp(date: Date): string;
/**
* Calculates the expiration time given a number of seconds.
* @param expiresInSeconds - The expiration duration in seconds.
* @returns The expiration timestamp as a Date object.
*/
static calculateExpiryTime(expiresInSeconds: number): Date;
}
/**
* String Utility
*/
export declare class StringUtil {
/**
* Encodes a string to Base64.
* @param value - The string to encode.
* @returns The Base64-encoded string.
*/
static toBase64(value: string): string;
/**
* Truncates a string to the specified length, adding "..." if truncated.
* @param value - The string to truncate.
* @param maxLength - The maximum allowed length.
* @returns The truncated string.
*/
static truncate(value: string, maxLength: number): string;
}
/**
* Exponential Backoff Utility
*/
export declare class RetryUtil {
/**
* Calculates the delay for a retry attempt using exponential backoff.
* @param attempt - The current retry attempt (0-indexed).
* @param baseDelay - The base delay in milliseconds (default: 100ms).
* @returns The calculated delay in milliseconds.
*/
static calculateBackoffDelay(attempt: number, baseDelay?: number): number;
}
export declare const Utils: {
Validator: typeof Validator;
DateTimeUtil: typeof DateTimeUtil;
StringUtil: typeof StringUtil;
RetryUtil: typeof RetryUtil;
};