diff --git a/package-lock.json b/package-lock.json index 521a37f..5d21283 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "fintecture-client", - "version": "1.0.10", + "version": "2.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 09c7eab..26347a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fintecture-client", - "version": "2.0.2", + "version": "2.1.0", "description": "Fintecture Open Banking API Gateway enabling secure bank connections and payments", "main": "lib/fintecture-client.js", "types": "lib/fintecture-client.d.ts", diff --git a/src/Ais.ts b/src/Ais.ts index 728cdfc..d71f30e 100644 --- a/src/Ais.ts +++ b/src/Ais.ts @@ -43,22 +43,29 @@ export class AIS { state?: string, model?: string, psuId?: string, - psuIpAddress?: string + psuIpAddress?: string, ): Promise { if (accessToken) { - return await this._authorizeWithAccessToken(accessToken, providerId, redirectUri, state, model, psuId, psuIpAddress); + return await this._authorizeWithAccessToken( + accessToken, + providerId, + redirectUri, + state, + model, + psuId, + psuIpAddress, + ); } else { return await this._authorizeWithAppId(providerId, redirectUri, state, model, psuId, psuIpAddress); } } - /** - * This API is used to poll the authentication status within + * This API is used to poll the authentication status within * the decoupled model. Once the decoupled authentication flow - * as initiated, the status is "PENDING". Once the PSU has - * successfully authenticated, the status becomes "COMPLETED". - * If the authentication times out, is cancelled or failed, + * as initiated, the status is "PENDING". Once the PSU has + * successfully authenticated, the status becomes "COMPLETED". + * If the authentication times out, is cancelled or failed, * the status becomes "FAILED". * * @param {string} accessToken @@ -66,11 +73,7 @@ export class AIS { * @param {string} pollingId * @returns {Promise} */ - public async decoupled( - accessToken: string, - providerId: string, - pollingId: string - ): Promise { + public async decoupled(accessToken: string, providerId: string, pollingId: string): Promise { if (accessToken) { return await this._decoupledWithAccesToken(accessToken, providerId, pollingId); } else { @@ -86,16 +89,21 @@ export class AIS { * @param {object} queryParameters (optional) * @returns {Promise} */ - public async getAccounts(accessToken: string, customerId: string, queryParameters?: object, headerParameters?: object): Promise { - const url = `${Endpoints.AISCUSTOMER}/${customerId}/accounts${queryParameters ? '?' + qs.stringify(queryParameters) : ''}`; + public async getAccounts( + accessToken: string, + customerId: string, + queryParameters?: object, + headerParameters?: object, + ): Promise { + const url = `${Endpoints.AISCUSTOMER}/${customerId}/accounts${ + queryParameters ? '?' + qs.stringify(queryParameters) : '' + }`; const headers = apiService.getHeaders('get', url, accessToken, this.config, null, headerParameters); - return await this.axiosInstance - .get(url, { headers }) - .then(response => { - return response.data; - }); + return await this.axiosInstance.get(url, { headers }).then(response => { + return response.data; + }); } /** @@ -109,21 +117,27 @@ export class AIS { * @param {string} paginationUrl (optional) * @returns {Promise} */ - public async getTransactions(accessToken: string, customerId: string, accountId: string, queryParameters?: object, headerParameters?: object, paginationUrl?: string): Promise { - + public async getTransactions( + accessToken: string, + customerId: string, + accountId: string, + queryParameters?: object, + headerParameters?: object, + paginationUrl?: string, + ): Promise { let url = paginationUrl; if (!url) { - url = `${Endpoints.AISCUSTOMER}/${customerId}/accounts/${accountId}/transactions${queryParameters ? '?' + qs.stringify(queryParameters) : ''}` ; + url = `${Endpoints.AISCUSTOMER}/${customerId}/accounts/${accountId}/transactions${ + queryParameters ? '?' + qs.stringify(queryParameters) : '' + }`; } const headers = apiService.getHeaders('get', url, accessToken, this.config, null, headerParameters); - return await this.axiosInstance - .get(url, { headers }) - .then(response => { - return response.data; - }); + return await this.axiosInstance.get(url, { headers }).then(response => { + return response.data; + }); } /** @@ -135,16 +149,21 @@ export class AIS { * @param {object} queryParameters (optional) * @returns {Promise} */ - public async getAccountHolders(accessToken: string, customerId: string, queryParameters: object, headerParameters?: object): Promise { - const url = `${Endpoints.AISCUSTOMER}/${customerId}/accountholders${queryParameters ? '?' + qs.stringify(queryParameters) : ''}`; + public async getAccountHolders( + accessToken: string, + customerId: string, + queryParameters: object, + headerParameters?: object, + ): Promise { + const url = `${Endpoints.AISCUSTOMER}/${customerId}/accountholders${ + queryParameters ? '?' + qs.stringify(queryParameters) : '' + }`; const headers = apiService.getHeaders('get', url, accessToken, this.config, null, headerParameters); - return await this.axiosInstance - .get(url, { headers },) - .then(response => { - return response.data; - }); + return await this.axiosInstance.get(url, { headers }).then(response => { + return response.data; + }); } /** @@ -159,9 +178,7 @@ export class AIS { const headers = apiService.getHeaders('delete', url, accessToken, this.config); - return await this.axiosInstance - .delete(url, { headers }) - .then(response => response.data); + return await this.axiosInstance.delete(url, { headers }).then(response => response.data); } /** @@ -181,11 +198,10 @@ export class AIS { providerId: string, redirectUri: string, state?: string, - model?: string, - psuId?: string, - psuIpAddress?: string + model?: string, + psuId?: string, + psuIpAddress?: string, ): Promise { - const queryParameters = { redirect_uri: redirectUri, }; @@ -203,12 +219,10 @@ export class AIS { const headers = apiService.getHeaders('get', url, accessToken, this.config); if (model === Constants.DECOUPLEDMODEL) { - headers["x-psu-id"] = psuId; - headers["x-psu-ip-address"] = psuIpAddress + headers['x-psu-id'] = psuId; + headers['x-psu-ip-address'] = psuIpAddress; } - - const response = await this.axiosInstance.get(url, { headers }); return response.data; } @@ -218,10 +232,9 @@ export class AIS { redirectUri: string, state?: string, model?: string, - psuId?: string, - psuIpAddress?: string + psuId?: string, + psuIpAddress?: string, ): Promise { - const queryParameters = { response_type: 'code', redirect_uri: redirectUri, @@ -240,19 +253,15 @@ export class AIS { const headers = apiService.getHeaders('get', url, null, this.config); if (model === Constants.DECOUPLEDMODEL) { - headers["x-psu-id"] = psuId; - headers["x-psu-ip-address"] = psuIpAddress + headers['x-psu-id'] = psuId; + headers['x-psu-ip-address'] = psuIpAddress; } const response = await this.axiosInstance.get(url, { headers }); return response.data; } - private async _decoupledWithAccesToken( - accessToken: string, - providerId: string, - pollingId: string - ): Promise { + private async _decoupledWithAccesToken(accessToken: string, providerId: string, pollingId: string): Promise { const url = `${Endpoints.AISPROVIDER}/${providerId}/authorize/decoupled/${pollingId}`; const headers = apiService.getHeaders('get', url, accessToken, this.config); @@ -261,10 +270,7 @@ export class AIS { return response.data; } - private async _decoupledWithAppId( - providerId: string, - pollingId: string - ): Promise { + private async _decoupledWithAppId(providerId: string, pollingId: string): Promise { const url = `${Endpoints.AISPROVIDER}/${providerId}/authorize/decoupled/${pollingId}`; const headers = apiService.getHeaders('get', url, null, this.config); diff --git a/src/Authentication.ts b/src/Authentication.ts index d25e479..7b3cfdf 100644 --- a/src/Authentication.ts +++ b/src/Authentication.ts @@ -74,8 +74,7 @@ export class Authentication { code: authCode, grant_type: 'authorization_code', }; - } - else { + } else { data = { scope: 'PIS', app_id: this.appId, @@ -84,9 +83,9 @@ export class Authentication { } if (scopes) { - data["scope"] = scopes; + data['scope'] = scopes; } - + return qs.stringify(data); } diff --git a/src/Connect.ts b/src/Connect.ts index 4af7c04..273013f 100644 --- a/src/Connect.ts +++ b/src/Connect.ts @@ -30,7 +30,7 @@ export class Connect { const queryParameters = qs.stringify({ redirect_uri: connectConfig.redirect_uri, - state: connectConfig.state + state: connectConfig.state, }); const url = `${Endpoints.AISCONNECT}?${queryParameters}`; @@ -47,7 +47,7 @@ export class Connect { const { data } = await this.axiosInstance.get(url, { headers }); return { - url: data.meta.url + url: data.meta.url, }; } @@ -66,7 +66,7 @@ export class Connect { const queryParameters = qs.stringify({ origin_uri: connectConfig.origin_uri, redirect_uri: connectConfig.redirect_uri, - state: connectConfig.state + state: connectConfig.state, }); const url = `${Endpoints.PISCONNECT}?${queryParameters}`; @@ -137,7 +137,7 @@ export class Connect { psu_email: payment.customer_email, psu_ip: payment.customer_ip, psu_phone: payment.customer_phone, - psu_address: payment.customer_address + psu_address: payment.customer_address, }; const data: IData = { diff --git a/src/Pis.ts b/src/Pis.ts index 913a9de..044508f 100644 --- a/src/Pis.ts +++ b/src/Pis.ts @@ -32,10 +32,7 @@ export class PIS { * @param {object} payload * @returns {Promise} */ - public async prepare( - accessToken: string, - payload: object, - ): Promise { + public async prepare(accessToken: string, payload: object): Promise { const url = `${Endpoints.PIS}/prepare`; const headers = apiService.getHeaders('post', url, accessToken, this.config, payload); @@ -61,7 +58,9 @@ export class PIS { redirectUri: string, state?: string, ): Promise { - const url = `${Endpoints.PISPROVIDER}/${providerId}/initiate?redirect_uri=${redirectUri}${state ? '&state=' + state : ''}`; + const url = `${Endpoints.PISPROVIDER}/${providerId}/initiate?redirect_uri=${redirectUri}${ + state ? '&state=' + state : '' + }`; const headers = apiService.getHeaders('post', url, accessToken, this.config, payload); @@ -105,8 +104,8 @@ export class PIS { if (amount) { payload.data = { attributes: { - amount - } + amount, + }, }; } @@ -126,12 +125,14 @@ export class PIS { * @returns {Promise} */ public async getPayments(accessToken: string, sessionId: string, queryParameters?: object): Promise { - - const url = `${Endpoints.PIS}/payments` + (sessionId?('/'+sessionId):'') + (queryParameters ? ('?' + qs.stringify(queryParameters)) : '') + const url = + `${Endpoints.PIS}/payments` + + (sessionId ? '/' + sessionId : '') + + (queryParameters ? '?' + qs.stringify(queryParameters) : ''); const headers = apiService.getHeaders('get', url, accessToken, this.config); - const response = await this.axiosInstance.get(url, {headers}); + const response = await this.axiosInstance.get(url, { headers }); return response.data; } diff --git a/src/interfaces/ConfigInterface.ts b/src/interfaces/ConfigInterface.ts index 9b2483e..de5fba8 100644 --- a/src/interfaces/ConfigInterface.ts +++ b/src/interfaces/ConfigInterface.ts @@ -4,8 +4,7 @@ * @interface IFintectureConfig */ -import { environment } from "../utils/Constants"; - +import { environment } from '../utils/Constants'; export interface IFintectureConfig { app_id: string; diff --git a/src/interfaces/connect/ConnectInterface.ts b/src/interfaces/connect/ConnectInterface.ts index 69e3a93..c0686e4 100644 --- a/src/interfaces/connect/ConnectInterface.ts +++ b/src/interfaces/connect/ConnectInterface.ts @@ -46,7 +46,6 @@ export interface IPisConnectConfig { provider?: string; } - export interface IAisConnectConfig { app_id: string; access_token?: string; @@ -96,35 +95,33 @@ export interface IMeta { } export interface IAddress { - name : string, - street : string, - number : string, - city : string, - zip : string, - country : string + name: string; + street: string; + number: string; + city: string; + zip: string; + country: string; } export interface IBeneficiary { - name : string, - form?: string, - incorporation?: string, - street : string, - number? : string, - city : string, - zip : string, - country : string, - iban : string, - swift_bic: string, - bank_name: string + name: string; + form?: string; + incorporation?: string; + street: string; + number?: string; + city: string; + zip: string; + country: string; + iban: string; + swift_bic: string; + bank_name: string; } - export interface IPisConnect { - url: string, - session_id: string + url: string; + session_id: string; } - export interface IAisConnect { - url: string + url: string; } diff --git a/src/interfaces/pis/PisInterface.ts b/src/interfaces/pis/PisInterface.ts index 32b41eb..c8a608d 100644 --- a/src/interfaces/pis/PisInterface.ts +++ b/src/interfaces/pis/PisInterface.ts @@ -6,6 +6,6 @@ export interface ISessionPayload { meta: { session_id: string; - }, + }; data?: any; -} \ No newline at end of file +} diff --git a/src/services/ApiService.ts b/src/services/ApiService.ts index a0d471c..eb540f0 100644 --- a/src/services/ApiService.ts +++ b/src/services/ApiService.ts @@ -15,7 +15,14 @@ export const getInstance = (env: string) => { }); }; -export const getHeaders = (method: string, url: string, accessToken: string, config: IFintectureConfig, body?: any, extraHeaders?: any) => { +export const getHeaders = ( + method: string, + url: string, + accessToken: string, + config: IFintectureConfig, + body?: any, + extraHeaders?: any, +) => { const headers = { Accept: 'application/json', 'User-Agent': 'Fintecture NodeJS SDK v' + Constants.FINTECTURESDKVERSION, @@ -36,9 +43,9 @@ export const getHeaders = (method: string, url: string, accessToken: string, con const search = URL.parse(url).search; if (body) { - headers['Digest'] = "SHA-256=" + Crypto.hashBase64(payload); + headers['Digest'] = 'SHA-256=' + Crypto.hashBase64(payload); } - + headers['Date'] = new Date().toUTCString(); headers['X-Date'] = headers['Date']; headers['X-Request-ID'] = Crypto.generateUUIDv4(); @@ -53,7 +60,7 @@ export const getHeaders = (method: string, url: string, accessToken: string, con if (headerValue !== undefined) { headers[headerName] = headerValue; } - }) + }); } return headers; diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 59fc6c7..5504a8c 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -5,11 +5,10 @@ import * as pjson from '../../package.json'; */ export enum environment { - sandbox = "sandbox", - production = "production" + sandbox = 'sandbox', + production = 'production', } - /** * Project wide constants * diff --git a/src/utils/Crypto.ts b/src/utils/Crypto.ts index 975b4e8..a496494 100644 --- a/src/utils/Crypto.ts +++ b/src/utils/Crypto.ts @@ -14,7 +14,7 @@ export function generateUUIDv4() { export function createSignatureHeader(headers: any, config: IFintectureConfig, signedHeaders: any) { const signingString = buildSigningString(headers, signedHeaders); const headerString = buildHeaderString(headers, signedHeaders); - + const signature = signPayload(signingString, config.private_key); return ( 'keyId="' + config.app_id + '",algorithm="rsa-sha256",headers="' + headerString + '",signature="' + signature + '"' @@ -68,5 +68,7 @@ export function signPayload(payload: any, privateKey: string, algorithm?: string } export function hashBase64(plainText: string): string { - return createHash('sha256').update(plainText).digest('base64'); + return createHash('sha256') + .update(plainText) + .digest('base64'); }