UNPKG

@lilianaa/nordigen-node

Version:

Nordigen official API client for Node.js

531 lines (530 loc) 14.6 kB
var d = Object.defineProperty; var I = (e, i, t) => i in e ? d(e, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[i] = t; var r = (e, i, t) => (I(e, typeof i != "symbol" ? i + "" : i, t), t); import R from "axios"; const l = { GET: "GET", POST: "POST", PUT: "PUT", DELETE: "DELETE" }, S = (e) => Object.keys(e ?? {}).reduce((i, t) => (e[t] && (i[t] = e[t]), i), {}); class g { /** * Agreements api class * @param {WithClient} params */ constructor({ client: i }) { r(this, "endpoint", "institutions"); r(this, "client"); this.client = i; } /** * Get list of institutions * @param {RetrieveAllSupportedInstitutionsInAGivenCountryParams} params * @returns {Promise<RetrieveAllSupportedInstitutionsInAGivenCountryData>} institution data array */ getInstitutions({ country: i }) { return this.client.request({ endpoint: this.endpoint, parameters: { country: i } }); } /*** * Get single institution by id * @param {string} id * @returns {Promise<RetrieveInstitutionData>} single institution data */ getInstitutionById(i) { return this.client.request({ endpoint: `${this.endpoint}/${i}/` }); } } class L { /** * Agreements api class * @param {WithClient} params */ constructor({ client: i }) { r(this, "endpoint", "agreements/enduser"); r(this, "client"); this.client = i; } /** * Create enduser agreement * @param {AgreementCreateParams} params * @returns {Promise<CreateEuaData>} Agreement object */ createAgreement({ institutionId: i, maxHistoricalDays: t = 90, accessValidForDays: s = 90, accessScope: n = ["balances", "details", "transactions"] }) { const c = { institution_id: i, max_historical_days: t, access_valid_for_days: s, access_scope: n }; return this.client.request({ endpoint: `${this.endpoint}/`, parameters: c, method: l.POST }); } /** * Get list of agreements * @param {RetrieveAllEuAsForAnEndUserParams} params * @returns {Promise<RetrieveAllEuAsForAnEndUserData>} End user agreements */ getAgreements({ limit: i = 100, offset: t = 0 } = {}) { const s = { limit: i, offset: t }; return this.client.request({ endpoint: `${this.endpoint}/`, parameters: s }); } /** * Get agreement by agreement id * @param {string} agreementId * @returns {Promise<RetrieveEuaByIdData>} object with specific enduser agreement */ getAgreementById(i) { return this.client.request({ endpoint: `${this.endpoint}/${i}/` }); } /** * Delete enduser agreement * @param {string} agreementId * @returns {Promise<HasDetail>} Deleted agreement object */ deleteAgreement(i) { return this.client.request({ endpoint: `${this.endpoint}/${i}/`, method: l.DELETE }); } /** * Accept End user agreement * @param {AgreementAcceptParams} params * @returns {Promise<AcceptEuaData>} Information on accepted agreement */ acceptAgreement({ agreementId: i, ip: t, userAgent: s }) { const n = { user_agent: s, ip_address: t }; return this.client.request({ endpoint: `${this.endpoint}/${i}/accept/`, parameters: n, method: l.PUT }); } } class D { /** * Agreements api class * @param {WithClient} params */ constructor({ client: i }) { r(this, "endpoint", "requisitions"); r(this, "client"); this.client = i; } /** * Create requisition. For creating links and retrieving accounts. * @param {RequisitionCreateOptions} params * @returns {Promise<SpectacularRequisition>} Requisition object */ createRequisition({ redirectUrl: i, institutionId: t, agreement: s, userLanguage: n, redirectImmediate: c = !1, accountSelection: h = !1, reference: o = null, ssn: p = null }) { const T = { redirect: i, institution_id: t, redirect_immediate: c, account_selection: h, ...n && { user_language: n }, ...s && { agreement: typeof s == "string" ? s : s.id }, ...p && { ssn: p }, ...o && { reference: o } }; return this.client.request({ endpoint: `${this.endpoint}/`, parameters: T, method: l.POST }); } /** * Get all requisitions * @param {RetrieveAllRequisitionsParams} params * @returns {Promise<PaginatedRequisitionList>} Requisitions object */ getRequisitions({ limit: i = 100, offset: t = 0 } = {}) { const s = { limit: i, offset: t }; return this.client.request({ endpoint: this.endpoint, method: l.GET, parameters: s }); } /** * Get requisition by id * @param {string} requisitionId * @returns {Promise<RequisitionByIdData>} Returns specific requisition */ getRequisitionById(i) { return this.client.request({ endpoint: `${this.endpoint}/${i}/` }); } /** * Delete requisition by id * @param {string} requisitionId * @returns {HasDetail} Object that consist confirmation message that requisition has been deleted */ deleteRequisition(i) { return this.client.request({ endpoint: `${this.endpoint}/${i}/`, method: l.DELETE }); } } class B { /** * Account api class * @param {Object} params */ constructor({ client: i, accountId: t }) { r(this, "endpoint", "accounts"); r(this, "client"); r(this, "accountId"); this.client = i, this.accountId = t; } /** * Construct reusable get request * * @template {AccountGetPath} P * @param {P} path api endpoint * @param {AccountGetPathToParams[P]} [parameters] parameters * @returns {Promise<AccountGetPathToResponse[P]>} Account data object */ get(i, t) { const s = `${this.endpoint}/${this.accountId}/${i}/`; return this.client.request({ endpoint: s, parameters: t || {} }); } /** * Access account metadata * @returns {Promise<RetrieveAccountMetadataData>} Account metadata object */ getMetadata() { return this.client.request({ endpoint: `${this.endpoint}/${this.accountId}/` }); } /** * Access account details * @returns {Promise<RetrieveAccountDetailsData>} Object with account details */ getDetails() { return this.get("details", {}); } /** * Access account balances * @returns {Promise<RetrieveAccountBalancesData>} Object with account balances */ getBalances() { return this.get("balances", {}); } /** * Access account transactions * @param {AccountGetTransactionsParams} params * @returns {Promise<RetrieveAccountTransactionsResponse>} Object with account transactions */ getTransactions({ dateFrom: i, dateTo: t } = {}) { const s = { date_from: i, date_to: t }; return this.get("transactions", s); } } class M { constructor({ secretId: i, secretKey: t, baseUrl: s = "https://bankaccountdata.gocardless.com/api/v2" }) { r(this, "endpoint", "token"); r(this, "_token", null); r(this, "baseUrl"); r(this, "secretId"); r(this, "secretKey"); r(this, "headers", {}); r(this, "institution"); r(this, "agreement"); r(this, "requisition"); this.baseUrl = s, this.secretKey = t, this.secretId = i, this.headers = { accept: "application/json", "Content-Type": "application/json", "User-Agent": "Nordigen-Node-v2" }, this.institution = new g({ client: this }), this.agreement = new L({ client: this }), this.requisition = new D({ client: this }); } /** * Token setter * @param {string|null} token */ set token(i) { if (this._token = i, !i) { delete this.headers.Authorization; return; } this.headers.Authorization = `Bearer ${i}`; } /** * Token getter * @returns {string|null} token */ get token() { return this._token; } /** * Construct Account object * @param {string} accountId * @returns {AccountApi} */ account(i) { return new B({ client: this, accountId: i }); } /** * Request wrapper * @template T * @template P * @param {RequestWrapperOptions<P>} params * @returns {Promise<T>} Request object */ async request({ endpoint: i, parameters: t, method: s = l.GET }) { const n = new URL(`${this.baseUrl}/${i}`), c = S(t); return s === l.GET && Object.keys(c).length > 0 && (n.search = new URLSearchParams(c).toString()), (await R({ method: s, url: n.toString(), headers: this.headers, ...s !== l.GET ? { data: JSON.stringify(t) } : {} })).data; } /** * Generate new access token * @returns {Promise<SpectacularJWTObtain>} Object with token details */ async generateToken() { const i = { secret_key: this.secretKey, secret_id: this.secretId }, t = await this.request({ endpoint: `${this.endpoint}/new/`, parameters: i, method: l.POST }); return this.token = (t == null ? void 0 : t.access) ?? null, t; } /** * Exchange refresh token for access token * @param {ExchangeTokenOptions} params * @returns {Promise<SpectacularJWTRefresh>} Object with new access token */ async exchangeToken({ refreshToken: i }) { const t = { refresh: i }; return await this.request({ endpoint: `${this.endpoint}/refresh/`, parameters: t, method: l.POST }); } /** * Factory method that creates authorization in a specific institution * - and are responsible for the following steps: * * Gets institution id; * * Creates agreement * * Creates requisiton * * @param {InitSessionOptions} params * @returns {Promise<SpectacularRequisition>} Requisitions object */ async initSession({ redirectUrl: i, institutionId: t, maxHistoricalDays: s = 90, // accessValidForDays = 90, userLanguage: n = "en", referenceId: c, ssn: h = null, redirectImmediate: o = !1, accountSelection: p = !1 }) { const T = await this.agreement.createAgreement({ maxHistoricalDays: s, institutionId: t }); return await this.requisition.createRequisition({ redirectUrl: i, institutionId: t, reference: c, agreement: T, userLanguage: n, redirectImmediate: o, accountSelection: p, ssn: h }); } } var N = /* @__PURE__ */ ((e) => (e.DISCOVERED = "DISCOVERED", e.PROCESSING = "PROCESSING", e.READY = "READY", e.ERROR = "ERROR", e.SUSPENDED = "SUSPENDED", e))(N || {}), G = /* @__PURE__ */ ((e) => (e.AT = "AT", e.BE = "BE", e.BG = "BG", e.HR = "HR", e.CY = "CY", e.CZ = "CZ", e.DK = "DK", e.EE = "EE", e.FI = "FI", e.FR = "FR", e.DE = "DE", e.GR = "GR", e.HU = "HU", e.IS = "IS", e.IE = "IE", e.IT = "IT", e.LV = "LV", e.LI = "LI", e.LT = "LT", e.LU = "LU", e.MT = "MT", e.NL = "NL", e.NO = "NO", e.PL = "PL", e.PT = "PT", e.RO = "RO", e.SK = "SK", e.SI = "SI", e.ES = "ES", e.SE = "SE", e.GB = "GB", e.US = "US", e))(G || {}), a = /* @__PURE__ */ ((e) => (e.AT = "AT", e.BE = "BE", e.BG = "BG", e.HR = "HR", e.CY = "CY", e.CZ = "CZ", e.DK = "DK", e.EE = "EE", e.FI = "FI", e.FR = "FR", e.DE = "DE", e.GR = "GR", e.HU = "HU", e.IS = "IS", e.IE = "IE", e.IT = "IT", e.LV = "LV", e.LI = "LI", e.LT = "LT", e.LU = "LU", e.MT = "MT", e.NL = "NL", e.NO = "NO", e.PL = "PL", e.PT = "PT", e.RO = "RO", e.SK = "SK", e.SI = "SI", e.ES = "ES", e.SE = "SE", e.GB = "GB", e.US = "US", e))(a || {}), A = /* @__PURE__ */ ((e) => (e.Following = "following", e.Preceding = "preceding", e))(A || {}), U = /* @__PURE__ */ ((e) => (e.Daily = "Daily", e.Weekly = "Weekly", e.EveryTwoWeeks = "EveryTwoWeeks", e.Monthly = "Monthly", e.EveryTwoMonths = "EveryTwoMonths", e.Quarterly = "Quarterly", e.SemiAnnual = "SemiAnnual", e.Annual = "Annual", e.MonthlyVariable = "MonthlyVariable", e))(U || {}), O = /* @__PURE__ */ ((e) => (e.T2P = "T2P", e.SCT = "SCT", e.ISCT = "ISCT", e.CBCT = "CBCT", e.BACS = "BACS", e.CHAPS = "CHAPS", e.FPS = "FPS", e.SWIFT = "SWIFT", e.BT = "BT", e.MT = "MT", e.DCT = "DCT", e.IDCT = "IDCT", e))(O || {}), $ = /* @__PURE__ */ ((e) => (e.INIT = "INIT", e.ERRE = "ERRE", e.ERRS = "ERRS", e.ACCC = "ACCC", e.ACCP = "ACCP", e.ACSC = "ACSC", e.ACSP = "ACSP", e.ACTC = "ACTC", e.ACWC = "ACWC", e.ACWP = "ACWP", e.RCVD = "RCVD", e.PDNG = "PDNG", e.RJCT = "RJCT", e.CANC = "CANC", e.ACFC = "ACFC", e.PATC = "PATC", e.PART = "PART", e))($ || {}), v = /* @__PURE__ */ ((e) => (e.SinglePayment = "single-payment", e.BulkPayment = "bulk-payment", e.PeriodicPayment = "periodic-payment", e))(v || {}), q = /* @__PURE__ */ ((e) => (e.CR = "CR", e.ID = "ID", e.LN = "LN", e.RJ = "RJ", e.ER = "ER", e.SU = "SU", e.EX = "EX", e.GC = "GC", e.UA = "UA", e.GA = "GA", e.SA = "SA", e))(q || {}), w = /* @__PURE__ */ ((e) => (e.IBAN = "IBAN", e.SCAN = "SCAN", e.BBAN = "BBAN", e))(w || {}); const H = [ { id: a.AT, name: "Austria" }, { id: a.BE, name: "Belgium" }, { id: a.BG, name: "Bulgaria" }, { id: a.HR, name: "Croatia" }, { id: a.CY, name: "Cyprus" }, { id: a.CZ, name: "Czechia" }, { id: a.DK, name: "Denmark" }, { id: a.EE, name: "Estonia" }, { id: a.FI, name: "Finland" }, { id: a.FR, name: "France" }, { id: a.DE, name: "Germany" }, { id: a.GR, name: "Greece" }, { id: a.HU, name: "Hungary" }, { id: a.IS, name: "Iceland" }, { id: a.IE, name: "Ireland" }, { id: a.IT, name: "Italy" }, { id: a.LV, name: "Latvia" }, { id: a.LI, name: "Liechtenstein" }, { id: a.LT, name: "Lithuania" }, { id: a.LU, name: "Luxembourg" }, { id: a.MT, name: "Malta" }, { id: a.NL, name: "Netherlands" }, { id: a.NO, name: "Norway" }, { id: a.PL, name: "Poland" }, { id: a.PT, name: "Portugal" }, { id: a.RO, name: "Romania" }, { id: a.SK, name: "Slovakia" }, { id: a.SI, name: "Slovenia" }, { id: a.ES, name: "Spain" }, { id: a.SE, name: "Sweden" }, { id: a.GB, name: "United Kingdom" } ]; export { N as AccountStatusEnum, G as AddressCountryEnum, a as CountryEnum, A as ExecutionRuleEnum, U as FrequencyEnum, l as HttpMethod, M as NordigenClient, O as PaymentProductEnum, $ as PaymentStatusEnum, v as PaymentTypeEnum, q as Status1C5Enum, w as TypeEnum, H as countries, M as default }; //# sourceMappingURL=index.esm.js.map