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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unit-finance/unit-node-sdk",
"version": "0.1.2",
"version": "0.2.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
18 changes: 18 additions & 0 deletions resources/customerToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { UnitError, UnitResponse } from "../types/common"
import { CreateTokenRequest, CustomerToken, CreateTokenVerificationRequest, VerificationToken } from "../types/customerToken"
import { BaseResource } from "./baseResource"

export class CustomerTokens extends BaseResource {
constructor(token: string, basePath: string){
super(token,basePath + "/customers")
}

public async createToken(customerId: string, request: CreateTokenRequest) : Promise<UnitResponse<CustomerToken> | UnitError> {
return this.httpPost<UnitResponse<CustomerToken>>(`/${customerId}/token`, { data: request })
}

public async createTokenVerification(customerId: string, request: CreateTokenVerificationRequest) : Promise<UnitResponse<VerificationToken> | UnitError> {
return this.httpPost<UnitResponse<VerificationToken>>(`/${customerId}/token/verification`,{ data: request})
}
}

58 changes: 58 additions & 0 deletions types/customerToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Phone } from "./common"

export interface CreateTokenRequest {
type: "customerToken"
attributes: {
/**
* list of Scopes separated by spaces.
*/
scope: string

/**
* Received as a response from Create Customer Token Verification.
* Required if scope includes a scope which require two-factor authentication.
*/
verificationToken?: string

/**
* 6 digits code sent to the customer through the desired channel.
* Required if the scope attribute includes a scope which requires two-factor authentication.
*/
verificationCode?: string
}
}

export interface CreateTokenVerificationRequest {
type: "customerTokenVerification"
attributes: {
/**
* send a verification code to the customer through one of the following channels sms or call.
*/
channel: "sms" | "call"

/**
* Optional. For [BusinessCustomer](https://developers.unit.co/#businesscustomer) only, this allows providing the phone number of one of the customer's authorized users.
* The provided phone must match an authorized user phone and will be used in the One Time Password (OTP) authentication process instead of the business customer contact's phone.
*/
phone?: Phone
}
}

export interface CustomerToken {
type: "customerBearerToken"
attributes: {
token: string
expiresIn: number
}
}

export interface VerificationToken {
type: "customerTokenVerification"
attributes: {
/**
* The generated verification token.
* It should be passed back to [Create Customer Bearer Token](https://developers.unit.co/#customers-create-customer-bearer-token) along with the verification code the customer received on the specified channel
*/
verificationToken: string
}
}
5 changes: 4 additions & 1 deletion unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Cards } from "./resources/cards"
import { Customers } from "./resources/customer"
import { Transactions } from "./resources/transactions"
import { Accounts } from "./resources/account"
import { CustomerTokens } from "./resources/customerToken"
import { UnitError } from "./types/common"

export class Unit {
Expand All @@ -11,13 +12,15 @@ export class Unit {
public accounts: Accounts
public transactions: Transactions
public cards: Cards

public customerToken: CustomerTokens

constructor(token: string, basePath: string) {
this.applications = new Applications(token, basePath)
this.customers = new Customers(token, basePath)
this.accounts = new Accounts(token, basePath)
this.transactions = new Transactions(token,basePath)
this.cards = new Cards(token, basePath)
this.customerToken = new CustomerTokens(token, basePath)
}

isError<T>(response: T | UnitError): response is UnitError {
Expand Down