Class default

Main client class for MB Bank API integration. Provides functionality for authentication, account balance queries, and transaction history.

Example

// Initialize the MB client
const mb = new MB({
username: '0123456789', // Your MB Bank phone number
password: 'your_password' // Your MB Bank password
});

// Login and get account balance
async function checkBalance() {
await mb.login();
const balance = await mb.getBalance();
console.log('Total balance:', balance.totalBalance);
console.log('Accounts:', balance.balances);
}

checkBalance().catch(console.error);

Hierarchy

  • default

Constructors

  • Creates a new MB client instance.

    Parameters

    • data: {
          username: string;
          password: string;
          preferredOCRMethod?: "default" | "tesseract" | "custom";
          customOCRFunction?: ((image) => Promise<string>);
          saveWasm?: boolean;
      }

      Configuration options

      • username: string

        MB Bank login username (usually your registered phone number)

      • password: string

        MB Bank login password

      • Optional preferredOCRMethod?: "default" | "tesseract" | "custom"

        OCR method for captcha recognition

      • Optional customOCRFunction?: ((image) => Promise<string>)
          • (image): Promise<string>
          • Custom OCR function (required if preferredOCRMethod is "custom")

            Parameters

            • image: Buffer

            Returns Promise<string>

      • Optional saveWasm?: boolean

        Whether to save the WASM file to disk

    Returns default

    Throws

    If username or password is not provided

    Example

    // Basic usage with default OCR
    const mbClient = new MB({
    username: '0123456789',
    password: 'your_password'
    });

    // Using Tesseract OCR
    const mbWithTesseract = new MB({
    username: '0123456789',
    password: 'your_password',
    preferredOCRMethod: 'tesseract'
    });

    // Using custom OCR function
    const mbWithCustomOCR = new MB({
    username: '0123456789',
    password: 'your_password',
    preferredOCRMethod: 'custom',
    customOCRFunction: async (image) => {
    // Your custom captcha recognition logic
    return recognizedText;
    }
    });

Properties

username: string

MB Bank account username (usually phone number).

password: string

MB Bank account password.

sessionId: undefined | null | string

Session identifier returned by MB Bank's API after successful authentication. Used to validate subsequent requests.

deviceId: string = ...

Device identifier used for authentication with MB Bank API. This is automatically generated for each session.

client: Client = ...

HTTP client for making requests to MB Bank's API.

wasmData: Buffer

WASM binary data downloaded from MB Bank. Used for request encryption.

customOCRFunction?: ((image) => Promise<string>)

Type declaration

    • (image): Promise<string>
    • Custom OCR function for captcha recognition. Allows implementing your own captcha recognition logic.

      Parameters

      • image: Buffer

        The captcha image buffer to be recognized

      Returns Promise<string>

      Recognized text from the captcha

      Example

      const mb = new MB({
      username: '0123456789',
      password: 'your_password',
      preferredOCRMethod: 'custom',
      customOCRFunction: async (imageBuffer) => {
      // Your custom OCR logic here
      // For example, using a third-party OCR service:
      const result = await someOCRService.recognize(imageBuffer);
      return result.text;
      }
      });
preferredOCRMethod: "default" | "tesseract" | "custom" = "default"

The OCR method to use for captcha recognition.

  • "default": Uses the pre-trained OCR model (recommended)
  • "tesseract": Uses Tesseract OCR engine
  • "custom": Uses the custom OCR function provided

Default

"default"
saveWasm: boolean = false

Whether to save the WASM file to disk. Useful for debugging or caching purposes.

Default

false

Methods

  • Private

    Processes captcha image according to the configured OCR method.

    Parameters

    • image: Buffer

      Captcha image buffer

    Returns Promise<null | string>

    Recognized captcha text or null if recognition failed

  • Private

    Since version 1.8.7, MB Bank requires biometric verification for transactions. This function will checks for biometric verification requirement and return if you need to complete biometric verification. This function should be called before performing any transaction-related operations.

    Returns Promise<any>

  • Authenticates with MB Bank API by solving captcha and sending login credentials. Sets the session ID upon successful login.

    Returns Promise<LoginResponseData>

    Login response from the API

    Throws

    If login fails with specific error code and message

    Example

    const mb = new MB({
    username: '0123456789',
    password: 'your_password'
    });

    try {
    const loginResponse = await mb.login();
    console.log('Login successful!');
    console.log('Session ID:', mb.sessionId);
    } catch (error) {
    console.error('Login failed:', error.message);
    }
  • Private

    Generates a reference ID required by MB Bank API. The format is "{username}-{timestamp}".

    Returns string

    Reference ID for API requests

  • Private

    Makes an authenticated request to MB Bank API. Handles session expiration by automatically re-logging in.

    Parameters

    • data: {
          path: string;
          json?: object;
          headers?: object;
      }

      Request parameters

      • path: string

        API endpoint path

      • Optional json?: object

        Request body data

      • Optional headers?: object

        Additional request headers

    Returns Promise<any>

    API response

    Throws

    If the request fails with error code and message

  • Retrieves account balance information for all accounts.

    Returns Promise<undefined | BalanceList>

    Account balance data or undefined if request fails

    Example

    const mb = new MB({
    username: '0123456789',
    password: 'your_password'
    });

    async function getAccountInfo() {
    await mb.login();
    const balanceInfo = await mb.getBalance();

    if (balanceInfo) {
    console.log(`Total balance: ${balanceInfo.totalBalance} ${balanceInfo.currencyEquivalent}`);

    // Display each account's details
    balanceInfo.balances.forEach(account => {
    console.log(`Account: ${account.name} (${account.number})`);
    console.log(`Balance: ${account.balance} ${account.currency}`);
    console.log('---');
    });
    }
    }

    getAccountInfo().catch(console.error);
  • Retrieves transaction history for a specific account within a date range.

    Parameters

    • data: {
          accountNumber: string;
          fromDate: string;
          toDate: string;
      }

      Request parameters

      • accountNumber: string

        MB Bank account number to query

      • fromDate: string

        Start date in format "DD/MM/YYYY" or "D/M/YYYY"

      • toDate: string

        End date in format "DD/MM/YYYY" or "D/M/YYYY"

    Returns Promise<undefined | TransactionInfo[]>

    Array of transaction details or undefined if request fails

    Throws

    If date range exceeds 90 days or date format is invalid

    Example

    const mb = new MB({
    username: '0123456789',
    password: 'your_password'
    });

    async function getLastMonthTransactions() {
    await mb.login();

    // Get account first
    const balanceInfo = await mb.getBalance();
    if (!balanceInfo?.balances?.length) {
    console.log('No accounts found');
    return;
    }

    const accountNumber = balanceInfo.balances[0].number;

    // Get transactions for the last 30 days
    const today = new Date();
    const lastMonth = new Date();
    lastMonth.setDate(today.getDate() - 30);

    const fromDate = `${lastMonth.getDate()}/${lastMonth.getMonth() + 1}/${lastMonth.getFullYear()}`;
    const toDate = `${today.getDate()}/${today.getMonth() + 1}/${today.getFullYear()}`;

    const transactions = await mb.getTransactionsHistory({
    accountNumber,
    fromDate,
    toDate
    });

    if (transactions) {
    console.log(`Found ${transactions.length} transactions`);

    transactions.forEach(tx => {
    const amount = tx.creditAmount || tx.debitAmount;
    const type = tx.creditAmount ? 'CREDIT' : 'DEBIT';

    console.log(`${tx.transactionDate} | ${type} | ${amount} ${tx.transactionCurrency}`);
    console.log(`Description: ${tx.transactionDesc}`);
    if (tx.toAccountName) {
    console.log(`To: ${tx.toAccountName} (${tx.toAccountNumber}) at ${tx.toBank}`);
    }
    console.log('---');
    });
    }
    }

    getLastMonthTransactions().catch(console.error);

Generated using TypeDoc