pluggy-js
Version:
Client-side JavaScript toolkit for Pluggy's API.
284 lines (283 loc) • 12.2 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const baseApi_1 = require("./baseApi");
/**
* 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
*/
class Pluggy extends baseApi_1.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 = {}, includeHealth = false) {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest('connectors', Object.assign(Object.assign({}, connectorSearchFilters), { includeHealth }));
});
}
/**
* 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, includeHealth = false) {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest(`connectors/${id}`, { includeHealth });
});
}
/**
* 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() {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest(`items`);
});
}
/**
* 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) {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest(`items/${id}`);
});
}
/**
* 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, parameters, webhookUrl, products) {
return __awaiter(this, void 0, void 0, function* () {
return this.createPostRequest(`items`, null, {
connectorId,
parameters,
webhookUrl,
products,
});
});
}
/**
* 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, parameters, webhookUrl) {
return __awaiter(this, void 0, void 0, function* () {
return this.createPatchRequest(`items/${id}`, null, {
id,
parameters,
webhookUrl,
});
});
}
/**
* 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, parameters) {
return __awaiter(this, void 0, void 0, function* () {
return this.createPostRequest(`items/${id}/mfa`, null, parameters);
});
}
/**
* 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) {
return __awaiter(this, void 0, void 0, function* () {
return this.createDeleteRequest(`items/${id}`);
});
}
/**
* 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, type) {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest('accounts', { itemId, type });
});
}
/**
* 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) {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest(`accounts/${id}`);
});
}
/**
* 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, options = {}) {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest('transactions', Object.assign(Object.assign({}, options), { accountId }));
});
}
/**
* 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) {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest(`transactions/${id}`);
});
}
/**
* 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, type) {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest('investments', { itemId, type });
});
}
/**
* 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) {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest(`investments/${id}`);
});
}
/**
* 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) {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest(`identity/${id}`);
});
}
/**
* 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) {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest(`identity?itemId=${itemId}`);
});
}
/**
* 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() {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest('categories');
});
}
/**
* 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) {
return __awaiter(this, void 0, void 0, function* () {
return this.createGetRequest(`categories/${id}`);
});
}
/**
* 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, options) {
return __awaiter(this, void 0, void 0, function* () {
return this.createPostRequest(`connect_token`, null, { itemId, options });
});
}
}
exports.default = Pluggy;