UNPKG

flexbase-client

Version:
880 lines (879 loc) 34.8 kB
var j = Object.defineProperty; var x = (s, e, r) => e in s ? j(s, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : s[e] = r; var d = (s, e, r) => (x(s, typeof e != "symbol" ? e + "" : e, r), r); import { ConsoleLogger as v } from "@flexbase/logger"; import { DateTime as k } from "luxon"; import { AuthenticationTokenAccessorBase as P, PasswordCredentials as $ } from "@flexbase/http-client-middleware"; import C from "jwt-decode"; function T(s, e) { e.forEach((r) => { Object.getOwnPropertyNames(r.prototype).forEach((t) => { t !== "constructor" && Object.defineProperty(s.prototype, t, Object.getOwnPropertyDescriptor(r.prototype, t) || /* @__PURE__ */ Object.create(null)); }); }); } class i { // eslint-disable-next-line @typescript-eslint/no-explicit-any constructor(e, r, t) { d(this, "_client"); d(this, "_logger"); // eslint-disable-next-line @typescript-eslint/no-explicit-any d(this, "_tokenAccessor"); d(this, "_token"); this._client = e, this._tokenAccessor = r, this._token = null, this._logger = t || new v(); } get client() { return this._client; } get token() { return this._token; } get logger() { return this._logger; } setAuthenticationToken(e) { this._token = e, this.client._options = { ...this.client._options, authContext: { token: this._token } }; } // eslint-disable-next-line @typescript-eslint/no-explicit-any get tokenAccessor() { return this._tokenAccessor; } } class B extends i { /** * Get address suggestions based on the specified street * @param street A partial street address * @returns An array of matched addresses, otherwise an empty array */ async getAddressPreview(e) { try { return e ? (await this.client.url("/address/preview").post({ address: e }).json()).previews.map((t) => ({ street1: t.address, street2: null, city: t.city, state: t.state || "", postalCode: t.postalCode || "", country: t.country || "" })) : []; } catch { return this.logger.error("Unable to get address previews"), []; } } } class D extends i { buildParams(e) { const r = {}; return e != null && e.before && (r.before = e.before.toISO()), e != null && e.after && (r.after = e.after.toISO()), (e == null ? void 0 : e.includeCardholder) === !0 && (r.inclCardholder = !0), (e == null ? void 0 : e.includeMerchantName) === !0 && (r.inclStore = !0), (e == null ? void 0 : e.includeReversed) === !0 && (r.inclReversed = !0), (e == null ? void 0 : e.includeExpired) === !0 && (r.inclExpired = !0), r; } async getInvoicesByCompany(e, r) { try { const t = this.buildParams(r), n = await this.client.url(`/invoice/company/${e}`).query(t).get().json(); return n.success ? n.invoices : null; } catch (t) { return this.logger.error("Unable to get company transactions", t), null; } } async getInvoicesByUser(e, r) { try { const t = this.buildParams(r), n = await this.client.url(`/invoice/user/${e}`).query(t).get().json(); return n.success ? n.invoices : null; } catch (t) { return this.logger.error("Unable to get company transactions", t), null; } } // eslint-disable-next-line @typescript-eslint/no-explicit-any async uploadInvoiceFile(e, r) { try { const t = await this.client.url(`/invoice/${e}/invoicePic`).formData({ file: r }).post().json(); return t.success ? t.invoice : null; } catch (t) { return this.logger.error("Unable to upload invoice file", t), null; } } async unlinkInvoiceFile(e) { try { const r = await this.client.url(`/invoice/${e}/invoicePic`).delete().json(); return r.success ? r.invoice : null; } catch (r) { return this.logger.error("Unable to unlink invoice file", r), null; } } async updateInvoice(e, r) { try { const t = await this.client.url(`/invoice/${e}/summary`).put(r).json(); return t.success ? t.invoice : null; } catch (t) { return console.error("Unable to update the invoice", t), null; } } } class N extends i { /** * Request a Plaid `link_token` used to initialize [Plaid Link](https://plaid.com/docs/link/) * @returns A link token if successful, null otherwise */ async getPlaidLinkToken() { try { const e = await this.client.url("/plaid/linktoken").get().json(); return e.success ? e.response.link_token : null; } catch { return this.logger.error("Unable to get plaid link token"), null; } } /** * Exchange a Plaid `public_token` * @param public_token The public token issued by [Plaid Link](https://plaid.com/docs/link/) * @param metadata * @returns `success: true` and response data to be used on web if successful, otherwise `success: false` */ async exchangePlaidPublicToken(e, r) { try { return await this.client.url("/plaid/publicToken").post({ public_token: e, metadata: r }).json(); } catch { return this.logger.error("Unable to exchange plaid public token"), { success: !1 }; } } /** * Update a Plaid `link_token` used by [Plaid Link](https://plaid.com/docs/link/). Used when re-authentication is required. * @returns A link token if successful, null otherwise */ async updatePlaidLinkToken() { try { const e = await this.client.url("/plaid/linktoken/update").get().json(); return e.success ? e.response.link_token : null; } catch { return this.logger.error("Unable to get plaid link token"), null; } } async getPlaidAcctLocation() { try { const e = await this.client.url("/plaid/acctLocation").get().json(); return e.success ? e : null; } catch { return this.logger.error("Unable to get plaid link token"), null; } } } class A extends i { async getEmployees() { try { return await this.client.url("/user").get().json(); } catch (e) { return this.logger.error("ALL USERS ERROR", e), []; } } async getPerson(e) { if (!e) throw new Error("userId is required"); try { const r = await this.client.url(`/user/${e}`).get().json(); return r.success || this.logger.error(`Unable to get person ${e}`, r.error), r; } catch (r) { return this.logger.error(`Unable to get person ${e}`, r), { success: !1, error: `Unable to get person ${e}` }; } } async addPerson(e) { try { return (await this.client.url("/onboarding/user").post(e).json()).newUser; } catch (r) { return this.logger.error("SAVE USER ERROR", r), null; } } async updatePerson(e, r) { var t, n, o, c, g, h; if (!e) throw new Error("userId is required"); try { const l = { firstName: r.firstName, lastName: r.lastName, taxId: r.taxId, birthDate: r.birthDate, jobTitle: r.jobTitle, email: r.email, address: (t = r.address) == null ? void 0 : t.street1, addressLine2: (n = r.address) == null ? void 0 : n.street2, city: (o = r.address) == null ? void 0 : o.city, country: (c = r.address) == null ? void 0 : c.country, postalCode: (g = r.address) == null ? void 0 : g.postalCode, cellPhone: (h = r.phone) == null ? void 0 : h.number, roles: r.roles, authorizedSignatory: r.authorizedSignatory, preferences: r.preferences }, u = await this.client.url(`/user/${e}`).put(l).json(); return u || this.logger.error(`Unable to update person ${e}`, u), u; } catch (l) { return this.logger.error(`Unable to update person ${e}`, l), null; } } // eslint-disable-next-line @typescript-eslint/no-explicit-any async updatePersonPicture(e, r) { if (!e) throw new Error("userId is required"); try { const t = await this.client.url(`/user/${e}/profilePic`).formData({ file: r }).post().json(); return t.error && this.logger.error(`Unable to update person picture ${e}`, t), t.success; } catch (t) { return this.logger.error(`Unable to update person picture ${e}`, t), !1; } } async getPersonPicture(e) { if (!e) throw new Error("userId is required"); try { return await this.client.url(`/user/${e}/profilePic`).get().arrayBuffer(); } catch (r) { return this.logger.error(`Unable to get person picture ${e}`, r), null; } } async getAuthenticatedUserData() { try { const e = await this.client.url("/user/self").get().json(); return e || this.logger.error("Unable to get user data", e), { usr: { id: e.id, firstName: e.firstName, lastName: e.lastName, email: e.email, roles: e.roles, cellPhone: e.cellPhone, preferences: e.preferences }, success: !0 }; } catch (e) { return this.logger.error("Unable to get user data", e), { success: !1, error: "Unable to get authenticated user data" }; } } } class F extends i { async getMerchant(e) { if (!e) throw new Error("apiKey is required"); try { const r = await this.client.url(`/credit/merchant/${e}`).options({ authContext: { isAnonymousRoute: !0 } }, !0).get().json(); return r.success ? r.merchant : (this.logger.error(`Unable to get merchant ${e}`, r.error), null); } catch (r) { return this.logger.error(`Unable to get merchant ${e}`, r), null; } } } class O extends i { async getCompanyCredit(e) { try { let r = "/servicing/minimumDue"; e && (r = r + `?id=${e}`); const t = await this.client.url(r).get().json(); return t.success ? { available: t.availableLimit, total: t.creditLimit } : (this.logger.error(`Unable to get credit for company ${e}`), null); } catch (r) { return this.logger.error(`Unable to get credit for company ${e}`, r), null; } } async payDebt(e, r) { try { const t = await this.client.url("/servicing/payments/stripe").post({ companyId: e, amount: r }).json(); return t.success || this.logger.error("Unable to make the pay debt"), t; } catch (t) { return this.logger.error("Unable to make the pay debt", t), { success: !1, error: "Unable to make the pay debt", cardPayment: null }; } } async requestPayWithFlexbase(e) { if (!e.apiKey || e.amount <= 0) throw new Error("apiKey is required and amount must be greater than 0"); try { const r = await this.client.url("/credit/buyNow").post(e).json(); return r.success ? r : (this.logger.error("Unable to pay with flexbase", e), { approved: !1 }); } catch (r) { return this.logger.error("Unable to pay with flexbase", e, r), { approved: !1 }; } } } class W extends i { async requestLevel(e, r) { try { let t = `/underwriting/updateLevel?level=${e}`; r && (t = t + `&id=${r}`); const n = await this.client.url(t).put().json(); return n.success ? { ...n } : (this.logger.error(`Unable to underwrite company ${r}`), null); } catch (t) { return this.logger.error(`Unable to underwrite company ${r}`, t), null; } } } class q extends i { async getPatrons(e) { try { let r = "/clients"; return e && (r = r + `/${e}`), await this.client.url(r).get().json(); } catch (r) { return this.logger.error("Unable to get patrons", r), []; } } async addOrUpdatePatron(e) { try { return await this.client.url("/clients").post(e).json(); } catch (r) { return this.logger.error("Unable to add or update patron", r), null; } } } const S = (s) => { var e, r, t, n, o, c; return { id: s.id, businessName: s.companyName || "", doingBusinessAs: s.doingBusinessAs, taxId: s.taxId || "", formationDate: s.formationDate || "", legalStructure: s.legalStructure || "", category: s.category || "", monthlyExpenditure: s.monthlyExpenditure || "", website: s.website, owners: [...s.owners || []], address: { street1: ((e = s.address) == null ? void 0 : e.line1) || "", street2: ((r = s.address) == null ? void 0 : r.line2) || null, city: ((t = s.address) == null ? void 0 : t.city) || "", state: ((n = s.address) == null ? void 0 : n.state) || "", postalCode: ((o = s.address) == null ? void 0 : o.postalCode) || "", country: ((c = s.address) == null ? void 0 : c.country) || "" }, phone: { number: s.phone || "" } }; }, I = (s) => { var e, r, t, n, o, c; return { id: s.id, firstName: s.firstName || "", lastName: s.lastName || "", taxId: s.taxId || "", birthDate: s.birthDate || "", jobTitle: s.jobTitle || "", email: s.email, authorizedSignatory: s.authorizedSignatory || !1, businessId: s.companyId, address: { street1: ((e = s.address) == null ? void 0 : e.line1) || "", street2: ((r = s.address) == null ? void 0 : r.line2) || null, city: ((t = s.address) == null ? void 0 : t.city) || "", state: ((n = s.address) == null ? void 0 : n.state) || "", postalCode: ((o = s.address) == null ? void 0 : o.postalCode) || "", country: ((c = s.address) == null ? void 0 : c.country) || "" }, phone: { number: s.cellPhone || s.phone || "" }, roles: s.roles || [] }; }; class _ extends i { async getOnboardingStatus(e) { try { let r = "/onboarding"; e && (r = r + `?full=${e}`); const t = await this.client.url(r).get().json(); return t.success ? { completedTimestamp: k.fromISO(t.completedOnboarding), required: t.required, business: S(t.company), person: I(t.user) } : (this.logger.error("Unable to get onboarding status", t.error), null); } catch (r) { return this.logger.error("Unable to get onboarding status", r), null; } } } class E extends i { async getCompanyProjects() { try { return await this.client.url("/project/all?full=true").get().json(); } catch (e) { return this.logger.error("Unable to get company projects", e), null; } } async createOrUpdateProject(e) { try { return await this.client.url("/project").post(e).json(); } catch (r) { return this.logger.error("Unable to create a project", r), null; } } } class z extends i { async getDocumentImage(e) { try { return await this.client.url(`/doc/${e}`).get().arrayBuffer(); } catch (r) { return this.logger.error("Unable to get the image", r), null; } } } class L extends i { params({ searchTerm: e, status: r, full: t } = {}) { const n = {}; return e && (n.searchTerm = e), r && (n.status = r), t && (n.full = !0), n; } async getCardsByCompany({ searchTerm: e, status: r, full: t } = {}) { try { const n = this.params({ searchTerm: e, status: r, full: t }), o = await this.client.url("/card/company").query(n).get().json(); return o.success || this.logger.error("Unable to get company cards", o.error), o; } catch (n) { return this.logger.error("Unable to get company cards", n), { success: !1, error: "Unable to get company cards", cards: [] }; } } async getCard(e, r) { try { const t = this.params({ full: r }), n = await this.client.url(`/card/${e}`).query(t).get().json(); return n.success || this.logger.error(`Unable to get the card info for ${e}`), n; } catch (t) { return this.logger.error("Unable to get user card", t), { success: !1, error: "Unable to get the card info", card: null }; } } async issueCard(e, r) { try { const t = await this.client.url(`/card/${e}/issue`).post(r).json(); return t.success || this.logger.error("Unable to issue the card", t.error), t; } catch (t) { return this.logger.error("Unable to issue card", t), { success: !1, error: "Unable to issue the card", card: null }; } } async updateCard(e, r) { try { const t = await this.client.url(`/card/${e}`).put(r).json(); return t.success || this.logger.error(`Unable to update the card info for ${e}`), t; } catch (t) { return this.logger.error("Unable to update the card info", t), { success: !1, error: "Unable to update the card info", card: null }; } } async updateCardStatus(e, r, t) { try { const n = await this.client.url("/card/status").put({ cardId: e, status: r, last4: t }).json(); return n.success || this.logger.error("Unable to update the card status", n.error), n; } catch (n) { return this.logger.error("Unable to update the card status", n), { success: !1, error: "Unable to update the card status", card: null }; } } async getCardHiddenInfo(e) { try { const r = await this.client.url(`/card/${e}/hiddenInfo`).get().json(); return r.success || this.logger.error(`Unable to obtain hidden card information for ${e}`), r; } catch (r) { return this.logger.error("Unable to get user card", r), { cardNumber: null, cvc: null, embedUrl: null, expirationDate: null, last4: null, success: !1, error: "Unable to obtain hidden card information" }; } } } class R extends i { async getCompanyBalance(e) { try { return this.client.url(`/servicing/minimumDue/${e}`).get().json(); } catch (r) { return this.logger.error("Unable to get company balance data", r), null; } } async getCompanyPayments() { try { const e = await this.client.url("/servicing/payments").get().json(); return e.success || this.logger.error("Unable to get company payments", e.error), e; } catch (e) { return this.logger.error("Unable to get company payments", e), { success: !1, error: "Unable to get company payments", payments: [] }; } } async getCompanyData() { try { const e = await this.client.url("/tenant").get().json(); return e || this.logger.error("Unable to get company data", e), { company: { id: e == null ? void 0 : e.id, companyName: e == null ? void 0 : e.companyName, phone: e == null ? void 0 : e.phone, doingBusinessAs: e == null ? void 0 : e.dba, createdAt: e == null ? void 0 : e.createdAt, address: { line1: e == null ? void 0 : e.address, line2: e == null ? void 0 : e.addressLine2, city: e == null ? void 0 : e.city, state: e == null ? void 0 : e.state, postalCode: e == null ? void 0 : e.postalCode, country: e == null ? void 0 : e.country } }, success: !0 }; } catch (e) { return this.logger.error("Unable to get company data", e), { success: !1, error: "Unable to get company data", company: null }; } } } class M extends i { async changePassword(e) { try { const r = await this.client.url("/auth/setPass").post({ password: e }).json(); return r.success || this.logger.error("Unable to change the password", r.error), r; } catch (r) { return this.logger.error("Unable to change the password", r), { success: !1, error: "Unable to change the password" }; } } async validatePassword(e, r) { try { const t = await this.client.url("/auth/token").post({ email: e, password: r }).json(); return t.success || this.logger.error("failed to validate password", t.error), t; } catch (t) { return this.logger.error("failed to validate password", t), { success: !1, error: "failed to validate password", token: null }; } } } class V extends i { bankingParams(e) { const r = {}; let t; for (t in e) if (e && Object.hasOwn(e, t)) if (typeof e[t] == "object") { const n = e[t]; r[t] = n.toISO(); } else typeof e[t] == "boolean" ? r[t] = !0 : r[t] = e[t]; return r; } // APPLICATION async createBankingApplication(e) { try { const r = await this.client.url(`/banking/${e}/application`).post().json(); return r.success || this.logger.error(`Unable to create the application for the companyId ${e}`, r.error), r; } catch (r) { return this.logger.error(`Unable to create the application for the companyId ${e}`, r), { success: !1, error: r }; } } async getBankingApplicationStatus(e) { try { const r = await this.client.url(`/banking/${e}/application`).get().json(); return r.success || this.logger.error("Unable to get the application status", r.error), r; } catch (r) { return this.logger.error("Unable to get the application status", r), { success: !1, error: r }; } } // STATEMENTS async getBankingStatements(e, r, t) { try { const n = this.bankingParams(t), o = await this.client.url(`/banking/${e}/statements`).query(n).get().json(); return o.success || this.logger.error("Unable to get the list of statements", o.error), o; } catch (n) { return this.logger.error("Unable to get the list of statements", n), { success: !1, error: n }; } } // async getBankingStatementPdf(companyId: string, statementId: string, options?: BankingParameters): Promise<SingleStatementResponse> { // try { // const params = this.bankingParams(options); // let response; // if (options?.isPdf) { // response = await this.client.url(`/banking/${companyId}/statements/${statementId}`).query(params).get().arrayBuffer(); // } else { // response = await this.client.url(`/banking/${companyId}/statements/${statementId}`).query(params).get().json(); // if (!response.success) { // this.logger.error(`Unable to get the statement details for statementId ${statementId}`, response.error); // } // } // return response; // } catch (error) { // this.logger.error(`Unable to get the statement details for statementId ${statementId}`, error); // return { success: false, error: `Unable to get the statement details for statementId ${statementId}` }; // } // } // PAYMENTS async createBankingPayment(e, r) { try { const t = await this.client.url(`/banking/${e}/moneymovement`).post(r).json(); return t.success || this.logger.error("Unable to create a Unit Co. Payment", t.error), t; } catch (t) { return this.logger.error("Unable to create a Unit Co. Payment", t), { success: !1, error: t }; } } async getBankingPayments(e) { try { const r = await this.client.url(`/banking/${e}/moneymovement/list`).get().json(); return r.success || this.logger.error("Unable to get the list of payments", r.error), r; } catch (r) { return this.logger.error("Unable to get the list of payments", r), { success: !1, error: r }; } } // COUNTERPARTIES async createBankingCounterparty(e, r) { var t, n, o, c, g, h, l, u, y, p, b, f, m, w, U; try { const a = await this.client.url(`/banking/${e}/moneymovement/counterparty`).post(r).json(); return a.success && a.counterparty ? { id: ((t = a == null ? void 0 : a.counterparty) == null ? void 0 : t.id) || "", companyId: ((n = a == null ? void 0 : a.counterparty) == null ? void 0 : n.companyId) || "", accountNumber: ((o = a == null ? void 0 : a.counterparty) == null ? void 0 : o.accountNumber) || "", routingNumber: ((c = a == null ? void 0 : a.counterparty) == null ? void 0 : c.response.data.attributes.routingNumber) || "", accountType: ((g = a == null ? void 0 : a.counterparty) == null ? void 0 : g.response.data.attributes.accountType) || "", accountName: ((h = a == null ? void 0 : a.counterparty) == null ? void 0 : h.accountName) || "", accessToken: ((l = a == null ? void 0 : a.counterparty) == null ? void 0 : l.accessToken) || "", asOf: ((u = a == null ? void 0 : a.counterparty) == null ? void 0 : u.asOf) || "", byUser: ((y = a == null ? void 0 : a.counterparty) == null ? void 0 : y.byUser) || "", createdAt: ((p = a == null ? void 0 : a.counterparty) == null ? void 0 : p.createdAt) || "", type: ((b = a == null ? void 0 : a.counterparty) == null ? void 0 : b.response.data.attributes.type) || "", ucCounterpartyId: ((f = a == null ? void 0 : a.counterparty) == null ? void 0 : f.ucCounterpartyId) || "", ucCustomerId: ((m = a == null ? void 0 : a.counterparty) == null ? void 0 : m.ucCustomerId) || "", version: ((w = a == null ? void 0 : a.counterparty) == null ? void 0 : w.version) || -1, name: ((U = a == null ? void 0 : a.counterparty) == null ? void 0 : U.accountName) || "" } : null; } catch (a) { return this.logger.error("Unable to create a Unit Co. Counter Party. Please verify that all the Counterparty banking data required exists", a), null; } } async getBankingCounterparties(e, r) { try { const t = this.bankingParams(r), n = await this.client.url(`/banking/${e}/moneymovement/counterparty/list`).query(t).get().json(); return n.success && n.counterparties ? n.counterparties.map((o) => { var c, g, h, l, u, y; return { id: o.id || "", companyId: o.companyId || "", accountNumber: o.accountNumber || "", routingNumber: ((h = (g = (c = o.response) == null ? void 0 : c.data) == null ? void 0 : g.attributes) == null ? void 0 : h.routingNumber) || "", accountType: ((y = (u = (l = o.response) == null ? void 0 : l.data) == null ? void 0 : u.attributes) == null ? void 0 : y.accountType) || "", accountName: o.accountName || "", accessToken: o.accessToken || "", asOf: o.asOf || "", byUser: o.byUser || "", createdAt: o.createdAt || "", type: o.type || "", ucCounterpartyId: o.ucCounterpartyId || "", ucCustomerId: o.ucCustomerId || "", version: o.version || -1, name: o.accountName || "" }; }) : null; } catch (t) { return this.logger.error("Error calling Unit Co. Banking Counterparties", t), null; } } // DEPOSIT async getBankingAccounts(e, r) { try { const t = this.bankingParams(r), n = await this.client.url(`/banking/${e}/deposits/list`).query(t).get().json(); return n.success || this.logger.error("While trying to get a banking deposit account, an unhandled exception was thrown", n.error), n; } catch (t) { return this.logger.error("While trying to get a banking deposit account, an unhandled exception was thrown", t), { success: !1, error: t }; } } async getBankingAccountBalance(e, r) { try { const t = this.bankingParams(r), n = await this.client.url(`/banking/${e}/deposits/history`).query(t).get().json(); return n.success || this.logger.error("While trying to get banking deposit balance history, an unhandled exception was thrown", n.error), n; } catch (t) { return this.logger.error("While trying to get banking deposit balance history, an unhandled exception was thrown", t), { success: !1, error: t }; } } async getBankingAccountLimits(e) { try { const r = await this.client.url(`/banking/${e}/deposits/limits`).get().json(); return r.success || this.logger.error("While trying to get banking deposit limits, an unhandled exception was thrown", r.error), r; } catch (r) { return this.logger.error("While trying to get banking deposit limits, an unhandled exception was thrown", r), { success: !1, error: r }; } } // TRANSACTIONS async getBankingTransactions(e, r) { try { const t = this.bankingParams(r), n = await this.client.url(`/banking/${e}/transactions`).query(t).get().json(); return n.success || this.logger.error("Unable to get the list of transactions", n.error), n; } catch (t) { return this.logger.error("Unable to get the list of transactions", t), { success: !1, error: t }; } } // DEBIT CARDS async getBankingDebitCards(e, r) { try { const t = this.bankingParams(r), n = await this.client.url(`/banking/${e}/cards`).query(t).get().json(); return n.success || this.logger.error("While trying to get banking Cards by Company, an unhandled exception occurred", n.error), n; } catch (t) { return this.logger.error("While trying to get banking Cards by Company, an unhandled exception was thrown", t), { success: !1, error: t }; } } async createBankingDebitCard(e, r) { try { const t = await this.client.url(`/banking/${e}/cards`).post(r).json(); return t.success || this.logger.error("While trying to create a Unit Co. Debit Card, an unhandled exception was thrown", t.error), t; } catch (t) { return this.logger.error("While trying to create a Unit Co. Debit Card, an unhandled exception was thrown", t), { success: !1, error: t }; } } async updateBankingDebitCard(e, r) { try { const t = await this.client.url(`/banking/${e}/cards`).put(r).json(); return t.success || this.logger.error("While trying to update the Unit Co. Debit Card, an unhandled exception was thrown", t.error), t; } catch (t) { return this.logger.error("While trying to update the Unit Co. Debit Card, an unhandled exception was thrown", t), { success: !1, error: t }; } } async getPinStatus(e, r) { try { const t = await this.client.url(`/banking/${e}/cards/${r}/pin`).get().json(); return t.success || this.logger.error("Unable to get the Banking Card PIN status. Please verify that the Card is active", t.error), t; } catch (t) { return this.logger.error("While trying to get a Banking Card PIN status, an unhandled exception was thrown", t), { success: !1, error: t }; } } async reportBankingDebitCard(e, r) { try { const t = await this.client.url(`/banking/${e}/cards/reportCard`).post(r).json(); return t.success || this.logger.error("While trying to report a lost or stolen UnitCo Debit Card, an unhandled exception was thrown", t.error), t; } catch (t) { return this.logger.error("While trying to report a lost or stolen UnitCo Debit Card, an unhandled exception was thrown", t), { success: !1, error: t }; } } async freezeBankingDebitCard(e, r) { try { const t = await this.client.url(`/banking/${e}/cards/${r}/freeze`).post({ status: "freeze" }).json(); return t.success || this.logger.error("While trying to update a Frozen UnitCo Banking Debit Card in the database, an error was encountered", t.error), t; } catch (t) { return this.logger.error("While trying to Freeze a UnitCo Debit Card, an unhandled exception was thrown", t), { success: !1, error: t }; } } async unfreezeBankingDebitCard(e, r) { try { const t = await this.client.url(`/banking/${e}/cards/${r}/unfreeze`).post({ status: "unfreeze" }).json(); return t.success || this.logger.error("While trying to update a Unfrozen UnitCo Banking Debit Card in the database, an error was encountered", t.error), t; } catch (t) { return this.logger.error("While trying to Unfreeze a UnitCo Debit Card, an unhandled exception was thrown", t), { success: !1, error: t }; } } // UNITCO TOKEN async getUnitcoToken() { try { const e = await this.client.url("/unitco/verifToken").get().json(); return e.success || this.logger.error("While trying to create a new Customer Token Verification, an error occurred!", e.error), e; } catch (e) { return this.logger.error("While trying to create a new Customer Token Verification, an error occurred!", e), { success: !1, error: e }; } } async createUnitCoToken(e) { try { const r = await this.client.url("/unitco/custToken").post(e).json(); return r.success || this.logger.error("While trying to create a new Customer Token, an error occurred!", r.error), r; } catch (r) { return this.logger.error("While trying to create a new Customer Token, an error occurred!", r), { success: !1, error: r }; } } } class G extends i { servicingParams(e) { const r = {}; let t; for (t in e) e && Object.hasOwn(e, t) && (typeof e[t] == "boolean" ? r[t] = !0 : r[t] = e[t]); return r; } async getCreditStatement(e, r) { try { const t = this.servicingParams(r), n = await this.client.url(`/servicing/statement/${e}`).query(t).get().json(); return n.success || this.logger.error("Unable to get credit statement data", n), n; } catch (t) { return this.logger.error("Unable to get credit statement data", t), { success: !1, error: "Unable to get credit statement data" }; } } async getCompanyTransactions(e, r) { try { const t = this.servicingParams(r), n = await this.client.url(`/servicing/transactions/${e}`).query(t).get().json(); return n.success || this.logger.error("Unable to get company transactions data", n), n; } catch (t) { return this.logger.error("Unable to get company transactions data", t), null; } } } class H extends i { } T(H, [ B, N, D, A, F, O, W, E, z, L, q, _, R, M, V, G ]); const J = (s) => { var n; if (!s.success) return null; if (!!((n = s.message) != null && n.startsWith("Sent code"))) return { tokenType: "Challenge", token: "", expiration: 0, refreshToken: "", scope: "" }; const r = C.default(s.token), t = k.utc().plus(r.exp || 0); return { token: s.token, tokenType: "Bearer", expiration: t.toUnixInteger(), refreshToken: s.token, scope: r.roles ? r.roles.join(" ") : "" }; }; class ee extends P { // eslint-disable-next-line @typescript-eslint/no-explicit-any generateBody(e, r) { let t = ""; const n = {}; return r && r.trim().length !== 0 ? (n.grant_type = e.refreshGrantType, n.refresh_token = r, t = e.refreshTokenUrl || e.tokenUrl) : (n.grant_type = e.grantType, n.password = e.password, t = e.tokenUrl), n.email = e.username, n.scope = e.scope, n.code = e.code, { url: t, body: n }; } // eslint-disable-next-line @typescript-eslint/no-explicit-any coerceResponse(e) { return J(e); } } class re extends $ { constructor() { super(...arguments); d(this, "code", ""); } } const te = (s) => { const e = C.default(s); return { email: e.email, companyId: e.companyId, id: e.id }; }; export { ee as FlexbaseAuthenticationTokenAccessor, H as FlexbaseClient, re as FlexbasePasswordCredentials, J as convertFlexbaseToken, te as decodeFlexbaseToken };