diff --git a/package.json b/package.json index 396cd04a..8a53a2ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@unit-finance/unit-node-sdk", - "version": "0.1.2", + "version": "0.2.0", "description": "", "main": "index.js", "scripts": { diff --git a/resources/customerToken.ts b/resources/customerToken.ts new file mode 100644 index 00000000..3d65a3f9 --- /dev/null +++ b/resources/customerToken.ts @@ -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 | UnitError> { + return this.httpPost>(`/${customerId}/token`, { data: request }) + } + + public async createTokenVerification(customerId: string, request: CreateTokenVerificationRequest) : Promise | UnitError> { + return this.httpPost>(`/${customerId}/token/verification`,{ data: request}) + } +} + diff --git a/types/customerToken.ts b/types/customerToken.ts new file mode 100644 index 00000000..4d379983 --- /dev/null +++ b/types/customerToken.ts @@ -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 + } +} diff --git a/unit.ts b/unit.ts index ca642cd5..967e2993 100644 --- a/unit.ts +++ b/unit.ts @@ -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 { @@ -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(response: T | UnitError): response is UnitError {