@temboplus/frontend-core
Version:
A JavaScript/TypeScript package providing common utilities and logic shared across front-end TemboPlus projects.
162 lines (161 loc) • 6.08 kB
TypeScript
import { ISO2CountryCode } from "../country/country.types.js";
import type { BankSwiftCode, KEBankSwiftCode, TZBankSwiftCode } from "./bank.types.js";
import { z } from "zod";
import { BankJSONSchema } from "./bank.schema.js";
/**
* Infer the BankJSON type from the schema
*/
export type BankJSON = z.infer<typeof BankJSONSchema>;
export declare class Bank {
/**
* The full registered name of the bank.
*/
readonly fullName: string;
/**
* The commonly used short name or abbreviation for the bank.
*/
readonly shortName: string;
/**
* The SWIFT/BIC code for the bank's head office.
*/
readonly swiftCode: TZBankSwiftCode | KEBankSwiftCode;
/**
* The ISO 3166-1 alpha-2 country code (e.g., 'TZ', 'KE').
*/
readonly countryCode: ISO2CountryCode;
/**
* Creates a new Bank instance.
*
* @param fullName The full registered name of the bank
* @param shortName The commonly used short name or abbreviation for the bank
* @param swiftCode The SWIFT/BIC code for the bank's head office
* @param countryCode The ISO 3166-1 alpha-2 country code
*/
constructor(fullName: string, shortName: string, swiftCode: TZBankSwiftCode | KEBankSwiftCode, countryCode: ISO2CountryCode);
/**
* Returns a string representation of the bank.
* @returns A formatted string, e.g., "CRDB BANK PLC (CRDB) - SWIFT: CORUTZTZ [TZ]"
*/
toString(): string;
static from(swiftCode: BankSwiftCode, countryCode: ISO2CountryCode): Bank;
/**
* Converts the Bank instance to a plain JavaScript object.
* Suitable for serialization or data transfer.
*
* @returns {Object} Plain object representation of the bank
* @returns {string} returns.fullName - The full registered name of the bank
* @returns {string} returns.shortName - The commonly used short name
* @returns {string} returns.swiftCode - The SWIFT/BIC code
* @returns {ISO2CountryCode} returns.countryCode - The ISO 3166-1 alpha-2 country code
*
* @example
* ```typescript
* const bank = Bank.from("CORUTZTZ", "TZ");
* const obj = bank.toObject();
* console.log(obj);
* // {
* // fullName: "CRDB BANK PLC",
* // shortName: "CRDB",
* // swiftCode: "CORUTZTZ",
* // countryCode: "TZ"
* // }
* ```
*/
toObject(): {
fullName: string;
shortName: string;
swiftCode: TZBankSwiftCode | KEBankSwiftCode;
countryCode: ISO2CountryCode;
};
/**
* Static method to determine if an unknown object is a valid Bank object.
*
* This method performs a series of checks to validate if the provided object conforms
* to the Bank interface and contains valid data.
*
* @param {unknown} obj - The object to validate.
* @returns {obj is Bank} - Returns true if the object is a valid Bank, false otherwise.
*/
static is(obj: unknown): obj is Bank;
/**
* Serializes the Bank instance to a JSON-compatible object
*/
toJSON(): BankJSON;
/**
* Serializes the Bank instance to a JSON string
*/
toJSONString(): string;
/**
* Creates a Bank instance from a JSON-compatible object or string
*/
static fromJSON(json: BankJSON | string): Bank | undefined;
/**
* Creates a Bank instance from a JSON string
*/
static fromJSONString(jsonString: string): Bank | undefined;
/**
* Type guard to check if an object is a valid BankJSON using Zod validation
*/
static isBankJSON(obj: unknown): obj is BankJSON;
}
/**
* Service for managing bank data, validation, and instance creation
* across multiple countries. Acts as the central Facade and Factory.
* @class BankService
*/
export declare class BankService {
private static instance;
private loadedData;
private constructor();
/**
* Gets the singleton instance of BankService.
* Initializes known countries synchronously on first call.
* Consider async initialization if data loading becomes async.
*/
static getInstance(): BankService;
/**
* Initializes bank data for a specific country synchronously.
* @param countryCode The ISO country code (e.g., 'TZ', 'KE').
* @returns True if successful or already loaded, false on failure.
*/
initializeCountry(countryCode: ISO2CountryCode): boolean;
/**
* Retrieves the loaded data structure for a given country.
* Ensures country is initialized.
* @param countryCode The ISO country code.
* @returns The CountryBankData structure or undefined.
*/
private getCountryData;
/**
* Retrieves a Bank instance by its SWIFT code for a specific country.
* Performs validation before returning.
* @param countryCode The ISO country code.
* @param swiftCode The SWIFT code.
* @returns The Bank instance or undefined if SWIFT is invalid or not found.
*/
getBankBySwiftCode(countryCode: ISO2CountryCode, swiftCode: BankSwiftCode): Bank | undefined;
/**
* Retrieves all banks for a specific country.
* @param countryCode The ISO country code.
* @returns An array of Bank instances, or empty array.
*/
getAllBanks(countryCode: ISO2CountryCode): Bank[];
/**
* Retrieves all banks for all supported countries.
* @param countryCode The ISO country code.
* @returns An array of Bank instances, or empty array.
*/
getAllSupportedBanks(): Bank[];
/**
* Searches all supported banks for a bank with the provided swift code
*/
detectBank(swiftCode: string): Bank | undefined;
/**
* Searches for banks within a specific country by name or SWIFT code.
* @param countryCode The ISO country code.
* @param searchTerm The term to search for (case-insensitive).
* @param limit Max number of results.
* @returns An array of matching Bank instances.
*/
searchBanks(countryCode: ISO2CountryCode, searchTerm: string, limit?: number): Bank[];
}