diff --git a/example/package-lock.json b/example/package-lock.json index e06a30f..ef0eafd 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -1102,11 +1102,11 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" }, "pluggy-sdk": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/pluggy-sdk/-/pluggy-sdk-0.3.0.tgz", - "integrity": "sha512-RXSgiatpmjz7L/5QAFWS0zmlkoK6mWGdxu4t8J+jopY3l2n03h55QYcjyOv4+t8J9JkJeXyDtkmfxiAkmj7s/w==", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/pluggy-sdk/-/pluggy-sdk-0.4.0.tgz", + "integrity": "sha512-F7YPw5lICWDfOx2I+pgir1VzoebgxQvxHxjMn4L1mceyKYY9LMnq6bDtaBOzQcnN9IyvKOpeGX32o4gURTHxkw==", "requires": { - "node-fetch": "^2.6.0", + "node-fetch": "^2.6.1", "request": "^2.88.0" } }, diff --git a/example/package.json b/example/package.json index 85dd40f..76e7087 100644 --- a/example/package.json +++ b/example/package.json @@ -21,7 +21,7 @@ "repository": "https://github.com/pluggyai/pluggy-sdk-node", "dependencies": { "dotenv": "^8.2.0", - "pluggy-sdk": "^0.3.0", + "pluggy-sdk": "^0.4.0", "ts-node": "^8.10.2", "typescript": "^3.9.7" }, diff --git a/example/src/index.ts b/example/src/index.ts index 557fe0a..647a713 100644 --- a/example/src/index.ts +++ b/example/src/index.ts @@ -58,6 +58,10 @@ void (async function(): Promise { }) } + console.log(`Retrieving identity for item # ${item.id}`) + const identity = await client.fetchIdentityByItemId(item.id) + console.log(`Identity of the account name is ${identity.fullName}`) + console.log(`Deleting retrieved data for item #${item.id}`) await client.deleteItem(item.id) console.log(`Item deleted succesfully`) diff --git a/lib/package-lock.json b/lib/package-lock.json index c4d655a..fca3c7c 100644 --- a/lib/package-lock.json +++ b/lib/package-lock.json @@ -1,6 +1,6 @@ { "name": "pluggy-sdk", - "version": "0.3.0", + "version": "0.4.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/lib/package.json b/lib/package.json index 81f4457..9cc7bfa 100644 --- a/lib/package.json +++ b/lib/package.json @@ -1,6 +1,6 @@ { "name": "pluggy-sdk", - "version": "0.3.0", + "version": "0.4.0", "main": "dist/index.js", "typings": "dist/index.d.ts", "files": [ diff --git a/lib/src/baseApi.ts b/lib/src/baseApi.ts index 1692223..4e01942 100644 --- a/lib/src/baseApi.ts +++ b/lib/src/baseApi.ts @@ -3,10 +3,10 @@ import fetch from 'node-fetch' type QueryParameters = { [key: string]: number | number[] | string | string[] | boolean } export type ClientParams = { - clientId: string; - clientSecret: string; - baseUrl?: string; - showUrls?: boolean; + clientId: string + clientSecret: string + baseUrl?: string + showUrls?: boolean } export class BaseApi { diff --git a/lib/src/index.ts b/lib/src/index.ts index 6fbf633..466942a 100644 --- a/lib/src/index.ts +++ b/lib/src/index.ts @@ -13,6 +13,7 @@ import { PageResponse, Webhook, WebhookEvent, + IdentityResponse, } from './types' /** @@ -88,7 +89,10 @@ export class PluggyClient extends BaseApi { * @param parameters A map of name and value for the mfa requested * @returns {Item} a item object */ - async updateItemMFA(id: string, parameters: { [key: string]: string } = undefined): Promise { + async updateItemMFA( + id: string, + parameters: { [key: string]: string } = undefined + ): Promise { return this.createPostRequest(`items/${id}/mfa`, null, parameters) } @@ -154,6 +158,22 @@ export class PluggyClient extends BaseApi { return this.createGetRequest(`investments/${id}`) } + /** + * Fetch the identity resource + * @returns {IdentityResponse} an identity object + */ + async fetchIdentity(id: string): Promise { + return this.createGetRequest(`identity/${id}`) + } + + /** + * Fetch the identity resource by it's Item ID + * @returns {IdentityResponse} an identity object + */ + async fetchIdentityByItemId(itemId: string): Promise { + return this.createGetRequest(`identity?itemId=${itemId}`) + } + /** * Fetch all available categories * @returns {Categories[]} an paging response of categories diff --git a/lib/src/types.ts b/lib/src/types.ts index fcb7965..8ca5620 100644 --- a/lib/src/types.ts +++ b/lib/src/types.ts @@ -7,10 +7,10 @@ * @property {number} page - Page of transactions to retrieve, this calculates the offset. */ export type TransactionFilters = { - to?: string; - from?: string; - pageSize?: number; - page?: number; + to?: string + from?: string + pageSize?: number + page?: number } /* @@ -22,10 +22,10 @@ export type TransactionFilters = { * @property {boolean} sandbox - recovers sandbox connectors. Default: false */ export type ConnectorFilters = { - name?: string; - countries?: string[]; - types?: string[]; - sandbox?: boolean; + name?: string + countries?: string[] + types?: string[] + sandbox?: boolean } export type CurrencyCode = 'USD' | 'ARS' | 'BRL' @@ -41,10 +41,10 @@ export type InvestmentType = 'MUTUAL_FUND' | 'SECURITY' | 'EQUITY' * @property {string} parentDescription - Parent category hierachy name or description */ export type Category = { - id: string; - description: string; - parentId?: string; - parentDescription?: string; + id: string + description: string + parentId?: string + parentDescription?: string } /* @@ -67,21 +67,21 @@ export type Category = { * @property {InvestmentType} type - Type of the investment */ export type Investment = { - id: string; - itemId: string; - type: InvestmentType; - number: string; - balance: number; - name: string; - annualRate?: number; - currencyCode: CurrencyCode; - date?: Date; - value?: number; - quantity?: number; - taxes?: number; - taxes2?: number; - amountWithdrawal?: number; - amountProfit?: number; + id: string + itemId: string + type: InvestmentType + number: string + balance: number + name: string + annualRate?: number + currencyCode: CurrencyCode + date?: Date + value?: number + quantity?: number + taxes?: number + taxes2?: number + amountWithdrawal?: number + amountProfit?: number } /* @@ -100,19 +100,19 @@ export type Investment = { * @property {AccountSubType} subtype - Sub type of the account */ export type Account = { - id: string; - itemId: string; - type: AccountType; - subtype: AccountSubType; - number: string; - balance: number; - name: string; - marketingName?: string; - owner?: string; - taxNumber?: string; - currencyCode: CurrencyCode; - bankData?: BankData; - creditData?: CreditData; + id: string + itemId: string + type: AccountType + subtype: AccountSubType + number: string + balance: number + name: string + marketingName?: string + owner?: string + taxNumber?: string + currencyCode: CurrencyCode + bankData?: BankData + creditData?: CreditData } /* @@ -122,8 +122,8 @@ export type Account = { * @property {string} closingBalance - available balance of the account */ export type BankData = { - transferNumber?: string; - closingBalance?: number; + transferNumber?: string + closingBalance?: number } /* @@ -138,13 +138,13 @@ export type BankData = { * @property {number} availableCreditLimit - Available credit limit to use. */ export type CreditData = { - level?: string; - brand?: string; - balanceCloseDate?: Date; - balanceDueDate?: Date; - availableCreditLimit?: number; - balanceForeignCurrency?: number; - minimumPayment?: number; + level?: string + brand?: string + balanceCloseDate?: Date + balanceDueDate?: Date + availableCreditLimit?: number + balanceForeignCurrency?: number + minimumPayment?: number } /* @@ -159,14 +159,14 @@ export type CreditData = { * @property {CurrencyCode} currencyCode - ISO Currency code of the Transaction */ export type Transaction = { - id: string; - accountId: string; - date: Date; - description: string; - amount: number; - balance: number; - currencyCode: CurrencyCode; - providerCode?: string; + id: string + accountId: string + date: Date + description: string + amount: number + balance: number + currencyCode: CurrencyCode + providerCode?: string } /* @@ -178,10 +178,10 @@ export type Transaction = { * @property {boolean} mfa - If parameter is used for MFA. */ export type ConnectorCredential = { - label: string; - name: string; - type?: 'text' | 'password' | 'number'; - mfa?: boolean; + label: string + name: string + type?: 'text' | 'password' | 'number' + mfa?: boolean } /* @@ -197,14 +197,14 @@ export type ConnectorCredential = { * @property {any} credentials - List of parameters needed to execute the connector */ export type Connector = { - id: string; - name: string; - institutionUrl: string; - imageUrl: string; - primaryColor: string; - type: ConnectorType; - country: string; - credentials: ConnectorCredential[]; + id: string + name: string + institutionUrl: string + imageUrl: string + primaryColor: string + type: ConnectorType + country: string + credentials: ConnectorCredential[] } /* @@ -218,23 +218,23 @@ export type Connector = { * @property {Date} lastUpdatedAt - Last connection sync date with the institution. */ export type Item = { - id: string; - connector: Connector; - status: ItemStatus; - executionStatus: string; - createdAt: Date; - lastUpdatedAt?: Date; + id: string + connector: Connector + status: ItemStatus + executionStatus: string + createdAt: Date + lastUpdatedAt?: Date parameter?: ConnectorCredential } export type PageResponse = { - results: T[]; + results: T[] } export type Webhook = { - id: string; - event: string; - url: string; + id: string + event: string + url: string } export type WebhookEvent = 'item/created' | 'item/updated' | 'item/error' | 'all' @@ -244,7 +244,47 @@ export enum ItemStatus { OUTDATED = 'OUTDATED', UPDATED = 'UPDATED', UPDATING = 'UPDATING', - WAITING_USER_INPUT = 'WAITING_USER_INPUT' + WAITING_USER_INPUT = 'WAITING_USER_INPUT', } export type ConnectorType = 'PERSONAL_BANK' | 'BUSINESS_BANK' | 'INVOICE' | 'INVESTMENT' + +export type IdentityResponse = { + id: string + birthDate?: Date + taxNumber?: string + document?: string + documentType?: string + jobTitle?: string + fullName?: string + phoneNumbers?: PhoneNumber[] + emails?: Email[] + addresses?: Address[] + relations?: IdentityRelation[] +} + +export type PhoneNumber = { + type?: 'Personal' | 'Work' | 'Residencial' + value: string +} + +export type Email = { + type?: 'Personal' | 'Work' + value: string +} + +export type IdentityRelation = { + type?: 'Mother' | 'Father' | 'Spouse' + name?: string + document?: string +} + +export type Address = { + fullAddress?: string + primaryAddress?: string + city?: string + postalCode?: string + state?: string + country?: string + type?: 'Personal' | 'Work' +}