npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@finsys/borrower-client

v3.5.0

Published

Client library for the FinSys Borrower API — authentication, file uploads, and two-step loan application submission

Readme

@finsys/borrower-client

Client library for the FinSys Borrower API — handles authentication, file uploads, and two-step loan application submission.

Install

npm install @finsys/borrower-client @finsys/core

@finsys/core is a peer dependency that provides shared form configuration types.

Quick Start

import {
  BorrowerApiClient,
  BorrowerEnvironment,
  buildSubmissionPayloads,
} from '@finsys/borrower-client'

// 1. Create a client
const client = new BorrowerApiClient({
  environment: BorrowerEnvironment.STAGING,
  credentials: {
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret',
    gatewayKey: 'optional-gateway-key', // Azure APIM subscription key
  },
})

// 2. Test the connection
const { success, message } = await client.testConnection()

// 3. Upload a file
const result = await client.uploadFile(fileBuffer, 'document.pdf')
console.log(result.url) // blob storage URL

// 4. Build submission payloads from form data
const formData = {
  totalFinancing: 329000,
  fullName: 'John Doe',
  email: '[email protected]',
  bank_statement_t1: [{ url: result.url, name: 'document.pdf' }],
}

const { createPayload, finalizePayload } = buildSubmissionPayloads(
  formData,
  formConfig.fields // Record<string, FieldData> from @finsys/core
)

// 5. Two-step submission
const created = await client.submitApplication({
  ...createPayload,
  status: 'CREATING_APPLICATION',
})

await client.updateApplication(created.ihsId, {
  ...finalizePayload,
  status: 'APPLICATION_FINALIZED',
})

API

BorrowerApiClient

constructor(config: BorrowerClientConfig)

Creates a client instance. Environment determines the base URL:

| Environment | Base URL | |-------------|----------| | staging | https://api.finhero.asia/stage/buyerfuel/v1 | | production | https://api.finhero.asia/buyerfuel/v1 |

Use endpointOverrides to override individual endpoint URLs when needed.

login(): Promise<string>

Authenticates and returns a bearer token. Tokens are cached and auto-refreshed.

uploadFile(fileBuffer: Buffer, fileName: string): Promise<UploadResult>

Uploads a file and returns the blob storage URL.

submitApplication(payload): Promise<SubmissionResult>

Creates a new loan application (POST). Returns ihsId on success.

updateApplication(ihsId: string, payload): Promise<UpdateResult>

Updates an existing application (PATCH). Used to finalize with document URLs.

testConnection(): Promise<ConnectionTestResult>

Tests connectivity by attempting to authenticate.

invalidateToken(): void

Clears the cached auth token, forcing re-authentication on the next call.

buildSubmissionPayloads(formData, fields, now?)

Transforms form data into the two payloads needed for the two-step submission flow.

Parameters:

  • formData — Form values (Record<string, unknown>). File fields should contain UploadedFileRef[] or plain URL strings.
  • fields — Form config fields (Record<string, FieldData> from @finsys/core). File fields are identified by type: 'file'.
  • now — Optional Date for bank statement year computation (defaults to current date).

Returns: { createPayload, finalizePayload }

  • createPayload — Metadata only (no file references). Used for the initial POST.
  • finalizePayload — Updatable metadata + transformed document references. Used for the PATCH.

Field name conventions:

File fields are mapped to the API format based on their names:

| Field pattern | API field | Format | |---------------|-----------|--------| | bank_statement_tN | bankStatements | [{ path, month: N, year }] | | financials* | financialStatements | [{ path, year: ordinal }] | | ssm | form9 | "url" |

Contact/consent fields (email, fullName, mobilePhoneNo, formOfDisclosure) are automatically excluded from the finalize payload, as the API rejects these on update.

Types

interface UploadedFileRef {
  url: string
  name: string
}

/**
 * Typed upstream error detail surfaced on failed result objects (3.5.0+).
 * Populated when the underlying axios call receives a response from finsys-api.
 * All fields optional: WAF blocks at App Gateway arrive with no body, so only
 * `status` is set. Some legacy paths return only a `message` string, so
 * `code`/`desc` may be undefined.
 */
interface UpstreamErrorDetail {
  code?: string    // e.g. "APPLICATION_IS_FINALIZED"
  desc?: string    // human-readable description from finsys-api err.desc
  status?: number  // HTTP status from the upstream response
}

interface UploadResult {
  success: boolean
  url?: string
  data?: unknown
  message?: string
  upstream?: UpstreamErrorDetail  // 3.5.0+, on failure only
}

interface SubmissionResult {
  success: boolean
  applicationId?: string
  ihsId?: string
  message?: string
  errors?: Record<string, string[]>
  data?: unknown
  upstream?: UpstreamErrorDetail  // 3.5.0+, on failure only
}

interface UpdateResult {
  success: boolean
  message?: string
  data?: unknown
  upstream?: UpstreamErrorDetail  // 3.5.0+, on failure only
}

interface StatusResult {
  success: boolean
  ihsId?: string
  status?: string
  message?: string
  data?: unknown
  upstream?: UpstreamErrorDetail  // 3.5.0+, on failure only
}

interface ConnectionTestResult {
  success: boolean
  message: string
}

interface SubmissionPayloads {
  createPayload: Record<string, unknown>
  finalizePayload: Record<string, unknown>
}

Reading upstream errors (3.5.0+)

When a request fails, the result includes a typed upstream field with the upstream HTTP status and (when available) the finsys-api error code and description:

const result = await client.updateApplication(ihsId, payload)

if (!result.success) {
  console.error('Update failed:', {
    status: result.upstream?.status,
    code: result.upstream?.code,
    desc: result.upstream?.desc,
  })
}

code and desc are populated when the upstream returns the { err: { code, desc } } shape (the common case from finsys-api). For WAF blocks at the App Gateway, the response body is empty and only status is set.

License

Apache-2.0