Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@highbeam/unit-node-sdk",
"version": "0.8.13",
"version": "0.8.15",
"description": "",
"main": "dist/unit.js",
"types": "dist/unit.d.ts",
Expand Down Expand Up @@ -29,6 +29,7 @@
"typescript": "^4.2.4"
},
"dependencies": {
"axios": "^0.21.2"
"axios": "^0.21.2",
"crypto": "^1.0.1"
}
}
16 changes: 10 additions & 6 deletions resources/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Include, UnitResponse, UnitConfig } from "../types/common"
import { Customer } from "../types/customer"
import { CreateAccountRequest, Account, PatchAccountRequest, AccountLimits } from "../types/account"
import { CreateAccountRequest, Account, PatchAccountRequest, AccountLimits, AccountDepositProduct, CloseAccountRequest } from "../types/account"
import { BaseResource } from "./baseResource"

export class Accounts extends BaseResource {
Expand All @@ -13,8 +13,8 @@ export class Accounts extends BaseResource {
return this.httpPost<UnitResponse<Account>>("", { data: request })
}

public async closeAccount(accountId: string): Promise<UnitResponse<Account>> {
return this.httpPost<UnitResponse<Account>>(`/${accountId}/close`)
public async closeAccount(request: CloseAccountRequest): Promise<UnitResponse<Account>> {
return this.httpPost<UnitResponse<Account>>(`/${request.accountId}/close`, request.to_json())
}

public async reopenAccount(accountId: string): Promise<UnitResponse<Account>> {
Expand Down Expand Up @@ -42,13 +42,17 @@ export class Accounts extends BaseResource {
return this.httpGet<UnitResponse<Account[]> & Include<Customer[]>>("", { params: parameters })
}

public async update(request: PatchAccountRequest) : Promise<UnitResponse<Account>> {
return this.httpPatch<UnitResponse<Account>>(`/${request.accountId}`,{data: request.data})
public async update(request: PatchAccountRequest): Promise<UnitResponse<Account>> {
return this.httpPatch<UnitResponse<Account>>(`/${request.accountId}`, { data: request.data })
}

public async limits(accountId: string) : Promise<UnitResponse<AccountLimits>> {
public async limits(accountId: string): Promise<UnitResponse<AccountLimits>> {
return this.httpGet<UnitResponse<AccountLimits>>(`/${accountId}/limits`)
}

public async getAvailableDepositProducts(accountId: string): Promise<UnitResponse<AccountDepositProduct[]>> {
return this.httpGet<UnitResponse<AccountDepositProduct[]>>(`/${accountId}/deposit-products`)
}
}

export interface AccountListParams {
Expand Down
28 changes: 28 additions & 0 deletions resources/atmLocations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AtmLocation } from "../types/atmLocation"
import { UnitResponse, UnitConfig, Coordinates, Address } from "../types/common"
import { BaseResource } from "./baseResource"

export class AtmLocations extends BaseResource {

constructor(token: string, basePath: string, config?: UnitConfig) {
super(token, basePath + "/atm-locations", config)
}

public async list(params?: AtmLocationListParams): Promise<UnitResponse<AtmLocation[]>> {
const parameters = {
...(params?.coordinates && { "filter[coordinates]": params.coordinates }),
...(params?.address && { "filter[address]": params.address }),
...(params?.postalCode && { "filter[postalCode]": params.postalCode }),
...(params?.searchRadius && { "filter[searchRadius]": params.searchRadius })
}

return this.httpGet<UnitResponse<AtmLocation[]>>("", { params: parameters })
}
}

export interface AtmLocationListParams {
coordinates?: Coordinates
address?: Address
postalCode?: string
searchRadius?: number
}
14 changes: 14 additions & 0 deletions resources/billPays.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Biller, GetBillerParams } from "../types/billPay"
import { UnitConfig, UnitResponse } from "../types/common"
import { BaseResource } from "./baseResource"

export class BillPays extends BaseResource {

constructor(token: string, basePath: string, config?: UnitConfig) {
super(token, basePath + "/payments/billpay/billers", config)
}

public async get(params: GetBillerParams): Promise<UnitResponse<Biller[]>> {
return await this.httpGet<UnitResponse<Biller[]>>("", {params: params})
}
}
29 changes: 14 additions & 15 deletions resources/cards.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Card, CardLimits, CreateDebitCardRequest, ReplaceCardRequest } from "../types/cards"
import { Card, CardLimits, CreateDebitCardRequest, PinStatus, ReplaceCardRequest } from "../types/cards"
import { Include, UnitConfig, UnitResponse } from "../types/common"
import { Customer } from "../types/customer"
import { Account } from "../types/account"
Expand All @@ -14,41 +14,36 @@ export class Cards extends BaseResource {
return await this.httpPost<UnitResponse<Card>>("", { data: request })
}

public async reportStolen(id: number): Promise<UnitResponse<Card>> {
public async reportStolen(id: string): Promise<UnitResponse<Card>> {
const path = `/${id}/report-stolen`
return await this.httpPost<UnitResponse<Card>>(path)
}

public async reportLost(id: string): Promise<UnitResponse<Card>> {
const path = `/${id}/report-lost`
return await this.httpPost<UnitResponse<Card>>(path)
return await this.httpPost<UnitResponse<Card>>(`/${id}/report-lost`)
}

public async closeCard(id: string): Promise<UnitResponse<Card>> {
const path = `/${id}/close`
return await this.httpPost<UnitResponse<Card>>(path)
return await this.httpPost<UnitResponse<Card>>(`/${id}/close`)
}

public async freeze(id: string): Promise<UnitResponse<Card>> {
const path = `/${id}/freeze`
return await this.httpPost<UnitResponse<Card>>(path)
return await this.httpPost<UnitResponse<Card>>(`/${id}/freeze`)
}

public async unfreeze(id: string): Promise<UnitResponse<Card>> {
const path = `/${id}/unfreeze`
return await this.httpPost<UnitResponse<Card>>(path)
return await this.httpPost<UnitResponse<Card>>(`/${id}/unfreeze`)
}

public async replace(request: ReplaceCardRequest): Promise<UnitResponse<Card>> {
const path = `/${request.id}/replace`
const data = {
type: "replaceCard",
attributes: {
shippingAddress: request.shippingAddress
}
}

return await this.httpPost<UnitResponse<Card>>(path, { data })
return await this.httpPost<UnitResponse<Card>>(`/${request.id}/replace`, { data })
}

/**
Expand All @@ -57,9 +52,7 @@ export class Cards extends BaseResource {
* Related resources include: customer, account. See [Getting Related Resources](https://developers.unit.co/#intro-getting-related-resources).
*/
public async get(id: string, include = ""): Promise<UnitResponse<Card>> {
const path = `/${id}?include=${include}`

return await this.httpGet<UnitResponse<Card> & Include<Account[] | Customer[]>>(path)
return await this.httpGet<UnitResponse<Card> & Include<Account[] | Customer[]>>(`/${id}?include=${include}`)
}

public async list(params?: CardListParams): Promise<UnitResponse<Card[]> & Include<Account[] | Customer[]>> {
Expand All @@ -74,6 +67,12 @@ export class Cards extends BaseResource {
return this.httpGet<UnitResponse<Card[]> & Include<Account[] | Customer[]>>("", { params: parameters })
}

public async getPinStatus(id: string): Promise<UnitResponse<PinStatus>> {
const path = `/${id}/secure-data/pin/status`

return await this.httpGet<UnitResponse<PinStatus>>(path)
}

public async limits(id: string) : Promise<UnitResponse<CardLimits>> {
return this.httpGet<UnitResponse<CardLimits>>(`/${id}/limits`)
}
Expand Down
6 changes: 5 additions & 1 deletion resources/counterparty.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UnitConfig, UnitResponse } from "../types/common"
import { AchCounterparty, CreateCounterpartyRequest, PatchCounterpartyRequest } from "../types/counterparty"
import { AchCounterparty, CounterpartyBalance, CreateCounterpartyRequest, PatchCounterpartyRequest } from "../types/counterparty"
import { BaseResource } from "./baseResource"

export class Counterparties extends BaseResource {
Expand Down Expand Up @@ -33,6 +33,10 @@ export class Counterparties extends BaseResource {
public async update(id: string, request: PatchCounterpartyRequest): Promise<UnitResponse<AchCounterparty>> {
return this.httpPatch<Promise<UnitResponse<AchCounterparty>>>(`/${id}`, { data: request })
}

public async getBalance(id: string): Promise<UnitResponse<CounterpartyBalance>> {
return this.httpGet<Promise<UnitResponse<CounterpartyBalance>>>(`/${id}/balance`)
}
}

export interface CounterpartyListParams {
Expand Down
1 change: 1 addition & 0 deletions resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export * from "./returns"
export * from "./statements"
export * from "./transactions"
export * from "./webhooks"
export * from "./billPays"

14 changes: 14 additions & 0 deletions resources/institutions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { UnitResponse, UnitConfig } from "../types/common"
import { Institution } from "../types/institution"
import { BaseResource } from "./baseResource"

export class Institutions extends BaseResource {

constructor(token: string, basePath: string, config?: UnitConfig) {
super(token, basePath + "/institutions", config)
}

public async get(routingNumber: string): Promise<UnitResponse<Institution>> {
return this.httpGet<UnitResponse<Institution>>(`/${routingNumber}`)
}
}
14 changes: 7 additions & 7 deletions resources/payments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Account } from "../types/account"
import { Include, UnitConfig, UnitResponse } from "../types/common"
import { Customer } from "../types/customer"
import { AchPayment, CreatePaymentRequest, PatchPaymentRequest, Payment } from "../types/payments"
import { CreatePaymentRequest, PatchPaymentRequest, Payment } from "../types/payments"
import { Transaction } from "../types/transactions"
import { BaseResource } from "./baseResource"

Expand All @@ -10,8 +10,8 @@ export class Payments extends BaseResource {
super(token, basePath + "/payments", config)
}

public async create(request: CreatePaymentRequest) : Promise<UnitResponse<AchPayment>> {
return this.httpPost<UnitResponse<AchPayment>>("",{data: request})
public async create(request: CreatePaymentRequest) : Promise<UnitResponse<Payment>> {
return this.httpPost<UnitResponse<Payment>>("",{data: request})
}

public async update(id: string, request: PatchPaymentRequest) : Promise<UnitResponse<Payment>> {
Expand All @@ -22,12 +22,12 @@ export class Payments extends BaseResource {
* Optional. A comma-separated list of related resources to include in the response.
* Related resources include: customer, account, transaction. See Getting Related Resources
*/
public async get(id: string, include?: string) : Promise<UnitResponse<AchPayment & Include<Account[] | Customer[] | Transaction[]>>> {
public async get(id: string, include?: string) : Promise<UnitResponse<Payment & Include<Account[] | Customer[] | Transaction[]>>> {
const params = {include : include ? `include=${include}` : ""}
return this.httpGet<UnitResponse<AchPayment & Include<Account[] | Customer[] | Transaction[]>>>(`/${id}`,{params})
return this.httpGet<UnitResponse<Payment & Include<Account[] | Customer[] | Transaction[]>>>(`/${id}`,{params})
}

public async list(params?: PaymentListParams) : Promise<UnitResponse<AchPayment[] & Include<Account[] | Customer[] | Transaction[]>>> {
public async list(params?: PaymentListParams) : Promise<UnitResponse<Payment[] & Include<Account[] | Customer[] | Transaction[]>>> {
const parameters = {
"page[limit]": (params?.limit ? params.limit : 100),
"page[offset]": (params?.offset ? params.offset : 0),
Expand All @@ -38,7 +38,7 @@ export class Payments extends BaseResource {
"include": params?.include ? params.include : ""
}

return this.httpGet<UnitResponse<AchPayment[] & Include<Account[] | Customer[] | Transaction[]>>>("", {params: parameters})
return this.httpGet<UnitResponse<Payment[] & Include<Account[] | Customer[] | Transaction[]>>>("", {params: parameters})
}
}

Expand Down
7 changes: 7 additions & 0 deletions resources/webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { UnitConfig, UnitResponse } from "../types/common"
import { CreateWebhookRequest, PatchWebhookRequest, Webhook } from "../types/webhooks"
import { BaseResource } from "./baseResource"
import crypto from "crypto"

export class Webhooks extends BaseResource {
constructor(token: string, basePath: string, config?: UnitConfig) {
Expand Down Expand Up @@ -35,6 +36,12 @@ export class Webhooks extends BaseResource {
public async disable(id: string): Promise<UnitResponse<Webhook>> {
return this.httpPost<UnitResponse<Webhook>>(`/${id}/disable`)
}

public verify(signature: string, secret: string, payload: any) {
const hmac = crypto.createHmac("sha1", secret)
hmac.update(JSON.stringify(payload))
return hmac.digest("base64") == signature
}
}

export interface WebhookListParams {
Expand Down
48 changes: 44 additions & 4 deletions types/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,16 @@ export interface CreateDepositAccountRequest {
*/
relationships: {
/**
* The customer.
* The customer the deposit account belongs to. The customer is either a business or an individual.
* You must provide exactly one of customer or customers
*/
customer: Relationship
customer?: Relationship

/**
* The list of customers the deposit account belongs to. Each of the customers is an individual customer and at least one must be over 18 years old.
* You must provide exactly one of customer or customers
*/
customers?: Relationship[]
}
}
export interface CreateBatchAccountRequest {
Expand Down Expand Up @@ -203,7 +210,8 @@ export interface PatchDepositAccountRequest {
data: {
type: "depositAccount"
attributes: {
tags: object
tags?: object
depositProduct?: string
}
}
}
Expand All @@ -222,4 +230,36 @@ export interface BatchAccount {
relationships: {
org: Relationship
}
}
}

export interface AccountDepositProduct {
type: "accountDepositProduct"
attributes: {
name: string
}
}

type CloseReason = "ByCustomer" | "Fraud"

export class CloseAccountRequest {
public accountId: string
public reason: CloseReason

constructor(accountId: string, reason: CloseReason = "ByCustomer") {
this.accountId = accountId
this.reason = reason
}

public to_json(): any {
const data: any = {
"data": {
"type": "accountClose",
"attributes": {
"reason": this.reason
}
}
}

return data
}
}
Loading