investec-pb-api
Version:
A simple package for interacting with Investec's private banking API
226 lines (223 loc) • 6.38 kB
TypeScript
/**
* OAuth authentication response from Investec API.
*/
interface AuthResponse {
access_token: string;
token_type: string;
expires_in: number;
scope: string;
}
/**
* Represents a single Investec account.
*/
interface Account {
accountId: string;
accountNumber: string;
accountName: string;
referenceName: string;
productName: string;
kycCompliant: boolean;
profileId: string;
profileName: string;
}
/**
* Balance details for a specific account.
*/
interface AccountBalance {
accountId: string;
currentBalance: number;
availableBalance: number;
budgetBalance: number;
straightBalance: number;
cashBalance: number;
currency: string;
}
/**
* API response for a single account's balance.
*/
interface AccountBalanceResponse {
data: AccountBalance;
}
/**
* API response for a list of accounts.
*/
interface AccountResponse {
data: {
accounts: Account[];
};
}
/**
* Represents a single transaction on an account.
*/
interface AccountTransaction {
accountId: string;
type: string;
transactionType: string;
status: string;
description: string;
cardNumber: string | null;
postedOrder: number;
postingDate: string;
valueDate: string;
actionDate: string;
transactionDate: string;
amount: number;
runningBalance: number;
uuid: string;
}
/**
* Represents a single beneficiary for payments.
*/
interface Beneficiary {
beneficiaryId: string;
accountNumber: string;
code: string;
bank: string;
beneficiaryName: string;
lastPaymentAmount: string;
lastPaymentDate: string;
cellNo: string;
emailAddress: string;
name: string;
referenceAccountNumber: string;
referenceName: string;
categoryId: string;
profileId: string;
fasterPaymentAllowed: boolean;
}
/**
* API response for a list of beneficiaries.
*/
interface BeneficiaryResponse {
data: Beneficiary[];
links: {
self: string;
};
meta: {
totalPages: number;
};
}
/**
* API response for a list of transactions on an account.
*/
interface AccountTransactionResponse {
data: {
transactions: AccountTransaction[];
};
}
/**
* Transfer instruction for multiple transfers.
*/
interface TransferMultiple {
beneficiaryAccountId: string;
amount: string;
myReference: string;
theirReference: string;
}
/**
* Payment instruction for multiple payments.
*/
interface PayMultiple {
beneficiaryId: string;
amount: string;
myReference: string;
theirReference: string;
}
/**
* Details of a single transfer result.
*/
interface Transfer {
PaymentReferenceNumber: string;
PaymentDate: string;
Status: string;
BeneficiaryName: string;
BeneficiaryAccountId: string;
AuthorisationRequired: boolean;
}
/**
* API response for multiple transfer results.
*/
interface TransferResponse {
data: {
TransferResponses: Transfer[];
};
}
/**
* Main API client for Investec Private Banking programmable banking API.
* Handles authentication and provides methods for account, transaction, and payment operations.
*
* @example
* const api = new InvestecPbApi(clientId, clientSecret, apiKey);
* const accounts = await api.getAccounts();
*/
declare class InvestecPbApi {
host: string;
clientId: string;
clientSecret: string;
apiKey: string;
token: string;
expiresIn: Date;
/**
* Create a new InvestecPbApi instance.
* @param clientId OAuth client ID
* @param clientSecret OAuth client secret
* @param apiKey API key from Investec
* @param host Optional API host (defaults to Investec production)
*/
constructor(clientId: string, clientSecret: string, apiKey: string, host?: string);
/**
* Get a valid OAuth token, refreshing if necessary.
* @returns Access token string
*/
getToken(): Promise<string>;
/**
* Request a new OAuth access token from Investec.
* @returns AuthResponse object
* @throws Error if authentication fails
*/
getAccessToken(): Promise<AuthResponse>;
/**
* Make multiple transfers from an account.
* @param accountId The account ID to transfer from
* @param transfers One or more transfer instructions
* @returns TransferResponse
* @throws Error if parameters are missing or API call fails
*/
transferMultiple(accountId: string, transfers: TransferMultiple[] | TransferMultiple): Promise<TransferResponse>;
/**
* Make multiple payments from an account.
* @param accountId The account ID to pay from
* @param payments One or more payment instructions
* @returns TransferResponse
* @throws Error if parameters are missing or API call fails
*/
payMultiple(accountId: string, payments: PayMultiple[] | PayMultiple): Promise<TransferResponse>;
/**
* Retrieve all beneficiaries for the authenticated user.
* @returns BeneficiaryResponse
*/
getBeneficiaries(): Promise<BeneficiaryResponse>;
/**
* Retrieve all accounts for the authenticated user.
* @returns AccountResponse
*/
getAccounts(): Promise<AccountResponse>;
/**
* Get the balance for a specific account.
* @param accountId The account ID
* @returns AccountBalanceResponse
* @throws Error if accountId is missing or API call fails
*/
getAccountBalances(accountId: string): Promise<AccountBalanceResponse>;
/**
* Get transactions for a specific account, optionally filtered by date and type.
* @param accountId The account ID
* @param fromDate Optional start date (YYYY-MM-DD)
* @param toDate Optional end date (YYYY-MM-DD)
* @param transactionType Optional transaction type filter
* @returns AccountTransactionResponse
* @throws Error if accountId is missing or API call fails
*/
getAccountTransactions(accountId: string, fromDate?: string | null, toDate?: string | null, transactionType?: string | null): Promise<AccountTransactionResponse>;
}
export { type AccountBalance, type AccountBalanceResponse, type AccountResponse, type AccountTransaction, type AccountTransactionResponse, type AuthResponse, type Beneficiary, type BeneficiaryResponse, InvestecPbApi, type Transfer, type TransferMultiple, type TransferResponse };