UNPKG

pluggy-js

Version:

Client-side JavaScript toolkit for Pluggy's API.

191 lines (190 loc) 9.34 kB
import { BaseApi } from './baseApi'; import { Account, AccountType, Category, Connector, ConnectorFilters, IdentityResponse, Investment, InvestmentType, Item, PageResponse, Transaction, TransactionFilters, Parameters, ListResponse, ConnectTokenOptions, ProductType } from './types'; /** * Creates a new client instance for interacting with Pluggy API * @constructor * @param API_KEY for authenticating to the API * @returns {Pluggy} a client for making requests */ declare class Pluggy extends BaseApi { /** * Fetch all available connectors * @param connectorSearchFilters {ConnectorFilters} - GET /connectors search filtering options * @param includeHealth {boolean} - if 'true', connectors response will include 'health' field. * * @returns {ListResponse<Connector>} a list response of connectors * * @throws {AxiosError<ErrorResponse>} status 403 if user is unauthorized */ fetchConnectors(connectorSearchFilters?: ConnectorFilters, includeHealth?: boolean): Promise<ListResponse<Connector>>; /** * Fetch a single Connector * @param id The Connector ID * @param includeHealth {boolean} - if 'true', connectors response will include 'health' field. * * @returns {Connector} a connector object * * @throws {AxiosError<ErrorResponse>} status 404 If specified Connector by 'id' does not exist or is not accessible by the user, * status 403 if user is unauthorized */ fetchConnector(id: number, includeHealth?: boolean): Promise<Connector>; /** * Fetch all items from the client * @returns {ListResponse<Item>} a list response of connected items * * @throws {AxiosError<ErrorResponse>} status 403 if user is unauthorized */ fetchItems(): Promise<ListResponse<Item>>; /** * Fetch a single item * @param id The Item ID * @returns {Item} a item object * * @throws {AxiosError<ErrorResponse>} status 404 If specified Item by 'id' does not exist or is not accessible by the user, * status 403 if user is unauthorized */ fetchItem(id: string): Promise<Item>; /** * Creates an item * @param connectorId The Connector's id * @param parameters A map of name and value for the needed credentials * @param webhookUrl - The webhookUrl to send item notifications to (optional) * @param products - Products to include in item execution and collection steps. * Optional. If not specified, all products available to your subscription level will be collected. * * @returns {Item} the created Item object * * @throws {AxiosError<ErrorResponse>} status 404 If connector is not found or accessible, status 403 if user is unauthorized * @throws {AxiosError<ValidationErrorResponse>} if 'connectorId' or 'webhookUrl' are invalid * @throws {AxiosError<ConnectorValidationErrorResponse>} if provided 'parameters' fail for some connector validation rules */ createItem(connectorId: number, parameters: Parameters, webhookUrl?: string, products?: ProductType[]): Promise<Item>; /** * Updates an item * @param id The Item ID * @param parameters A map of name and value for the credentials to be updated * @param webhookUrl - The new webhookUrl to send item notifications to (optional) * @returns {Item} the updated Item object * * @throws {AxiosError<ValidationErrorResponse>} if 'connectorId' or 'webhookUrl' are invalid * @throws {AxiosError<ConnectorValidationErrorResponse>} if provided 'parameters' fail for some connector validation rules * @throws {AxiosError<ErrorResponse>} status 404 If connector is not found or accessible, * status 403 if user is unauthorized */ updateItem(id: string, parameters?: Parameters, webhookUrl?: string): Promise<Item>; /** * Send MFA for item execution * @param id The Item ID * @param parameters A map of name and value for the mfa requested * @returns {Item} a item object * * @throws {AxiosError<ValidationErrorResponse>} if item 'id' is invalid * @throws {AxiosError<ConnectorValidationErrorResponse>} if provided 'parameters' with the MFA value fail connector validation rules * @throws {AxiosError<ErrorResponse>} status 404 If item is not waiting an MFA request (or has already been fulfilled), * status 403 if user is unauthorized */ updateItemMFA(id: string, parameters?: Parameters): Promise<Item>; /** * Deletes an item * * @throws {AxiosError<ValidationErrorResponse>} if item 'id' is invalid * @throws {AxiosError<ErrorResponse>} status 404 If item does not exist or is not accessible by the user, * status 403 if user is unauthorized */ deleteItem(id: string): Promise<void>; /** * Fetch accounts from an Item * @param itemId The Item id * @param type - AccountType filter (optional) * @returns {ListResponse<Account>} a list response of accounts * * @throws {AxiosError<ErrorResponse>} status 403 if user is unauthorized */ fetchAccounts(itemId: string, type?: AccountType): Promise<ListResponse<Account>>; /** * Fetch a single account * @returns {Account} an account object * * @throws {AxiosError<ErrorResponse>} status 404 If account does not exist or is not accessible by the user, * status 403 if user is unauthorized */ fetchAccount(id: string): Promise<Account>; /** * Fetch transactions from an account * @param accountId The account id * @param {TransactionFilters} options Transaction options to filter * @returns {PageResponse<Transaction>} object which contains the transactions list and related paging data * * @throws {AxiosError<ErrorResponse>} status 403 if user is unauthorized */ fetchTransactions(accountId: string, options?: TransactionFilters): Promise<PageResponse<Transaction>>; /** * Fetch a single transaction * @returns {Transaction} an transaction object * * @throws {AxiosError<ErrorResponse>} status 404 If transaction does not exist or is not accessible by the user, * status 403 if user is unauthorized */ fetchTransaction(id: string): Promise<Transaction>; /** * Fetch investments from an Item * @param itemId The Item id * @param type - InvestmentType filter (optional) * @returns {ListResponse<Investment>} a list response of investments * * @throws {AxiosError<ErrorResponse>} status 403 if user is unauthorized */ fetchInvestments(itemId: string, type?: InvestmentType): Promise<ListResponse<Investment>>; /** * Fetch a single investment * @returns {Investment} an investment object * * @throws {AxiosError<ErrorResponse>} status 404 If transaction does not exist or is not accessible by the user, * status 403 if user is unauthorized */ fetchInvestment(id: string): Promise<Investment>; /** * Fetch the identity resource * @returns {IdentityResponse} an identity object * * @throws {AxiosError<ErrorResponse>} status 404 If identity does not exist or is not accessible by the user, * status 403 if user is unauthorized */ fetchIdentity(id: string): Promise<IdentityResponse>; /** * Fetch the identity resource by it's Item ID * @returns {IdentityResponse} an identity object * * @throws {AxiosError<ErrorResponse>} status 403 if user is unauthorized */ fetchIdentityByItemId(itemId: string): Promise<IdentityResponse>; /** * Fetch all available categories * @returns {ListResponse<Category>[]} an list response of categories * * @throws {AxiosError<ErrorResponse>} status 404 If identity does not exist or is not accessible by the user, * status 403 if user is unauthorized */ fetchCategories(): Promise<ListResponse<Category>>; /** * Fetch a single category * @returns {Category} a category object * * @throws {AxiosError<ErrorResponse>} status 404 If category does not exist * status 403 if user is unauthorized */ fetchCategory(id: string): Promise<Category>; /** * Creates a connect token that can be used as API KEY to connect items from the Frontend * @param {string} itemId - primary identifier of the Item * @param {ConnectTokenOptions} options - options object to create a connect token * @returns {string} Access token to connect items with restrict access * * @throws {AxiosError<ErrorResponse>} status 404 If specified Item by 'id' does not exist or is not accessible by the user, * status 403 if user is unauthorized */ createConnectToken(itemId?: string, options?: ConnectTokenOptions): Promise<{ accessToken: string; }>; } export default Pluggy;