@innocells/unnax-client
v1.0.60
Published
Unnax client for node
Downloads
53
Keywords
Readme
unnax-client
Unnax SDK for JavaScript
Installation
You can install it directly from npm:
npm install @innocells/unnax-client --save
Initialization
init(request)
To initialize the unnax-client use the init()
method passing the options object:
{
apiCode: Unnax client ApiCode (string)
apiId: Unnax client ApiId (string)
unnaxBaseUrl: Unnax api endpoint (Unnax Environment) (string)
}
Initialization example:
const UnnaxClient = require('@innocells/unnax-client').init({
apiCode: "unnaxApiCode",
apiId: "unnaxApiId",
unnaxBaseUrl: "unnax api url base (integration environment unnax sample: https://integration.unnax.com)"
});
Response:
Returns an instance of the unnax-client.
Methods
getWidgetHtml(request)
Returns the html code (so intended for web browsers) of the widget used to connect bank accounts.
Request object definition:
{
requestCode: Unique request code (string)
baseColor: Base color for the widget (?string) (Default #0098C3)
logoUrl: Url for the application logo (?string)
urlOk: Redirect url for success bank login (?string)
urlKo: Redirect url for fails bank login (?string)
}
Request example:
const widgetRequest = {
baseColor: '#09D3C7',
requestCode: '123456',
logoUrl: 'https://www.jido.io/wp-content/uploads/2018/01/Jido-logo.png'
urlOk: 'http://localhost:4000/loginOk',
urlKo: 'http://localhost:4000/loginOk'
};
const widget = UnnaxClient.getWidgetHtml(widgetRequest);
Response:
HTML content for the widget. When the user finish the login process the unnax widget redirects to urlOk
or urlKo
.
getAvailableWebhooks()
Returns the list of available webhooks in Unnax.
Request example:
const response = await UnnaxClient.getAvailableWebhooks();
The returned object is an array of events:
[
{
"name": "Aml Check",
"id": "aml_check",
"description": "Triggered when an AML check completes"
},
{
"name": "Fitnance Read",
"id": "fitnance_read",
"description": "Triggered when a fitnance read operation completes"
}
...
]
getSubscribedWebhooks()
Returns an object with the currently subscribed events.
Request example:
const response = await UnnaxClient.getSubscribedWebhooks();
Response:
{
count: Number of subscribed webhooks.
next: Url to get the next page.
previous: Url to get the previous page.
results: Array of subscribed events. Each event has an id, client ("email" or "callback") and target (email or callback url from site)
}
Response sample:
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 235,
"client": "callback",
"event": "event_credential_token_creation",
"target": "https://mySite.com/response",
"created_at": "2018-01-17T12:24:53Z",
"updated_at": "2018-01-17T12:24:53Z"
},
{
"id": 240,
"client": "email",
"event": "event_reader_lockstep_complete",
"target": "[email protected]",
"created_at": "2018-01-17T14:57:55Z",
"updated_at": "2018-01-17T15:07:56Z"
},
...
]
}
subscribeWebHook(options)
This method is used to register a webhook event.
Request object definition:
{
client: Client type, either `email` or `callback`) (string)
event: Event id (returned from `getAvailableWebhooks()`) (string)
target: An email or callback url.
}
Request example:
const request = { client: 'email', event: 'aml_check', target: '[email protected]' };
const response = await UnnaxClient.SubscribeWebHook(request);
The response represents a new webhook subscription:
{
id: Webhook subscription id (number)
client: 'email' or 'callback' (same as request.client) (string)
event: Event id (eventId returned in the getAvailableWebhooks() method) (string)
target: Target of webhook response. (url if the client is 'callback' or email if the client is 'email')
}
decryptData(data)
This method is used to decrypt the data received from the webhook (fitnance_read
) callback.
Request object definition:
data: string
Callback webhook definition object
Sample fitnance_reader
callback:
{
service: Service (example: 'reader') (string)
triggered_event: Event id (to receive the callback, you must to subscribe to an event) (string)
environment: Unnax environment (example: "unnax_integration")
data: Encrypted data received (i.e. all movements from a client bank account) (string)
date: Date time executed (string)
response_id: Response id (string),
trace_identifier: trace identifier (string)
}
Sample request:
const result = UnnaxClient.decryptData(request.body.data.data);
launchTokenizedReader(request)
Launchs a request for tokenized readings (once the read finish unnax will launch a fitnance_read
event and post the data to the target webhook subscription).
Request object definition:
{
tokenKey: Token_key created previously (callback of Credentials Tokenized Widget) (string),
tokenId: Token_id created previously (callback of Credentials Tokenized Widget) (string),
requestCode: RequestCode for reader (string),
startDate: Movements since YYYY-MM-DD (string)
}
Request example:
const request = {
tokenKey: "lsFt7skxMaVfX4itYFB5sP8XVZLXoCVn",
tokenId: "92",
requestCode: "2AAsdfrA65_1",
startDate : "2017-01-01"
}
const result = await UnnaxClient.launchTokenizedReader(request);
The response contains a job_id
:
{
"job_id": "rt_f586421f5e9c4f61b0f8882a220ddd77"
}
apiInit(requestCode)
Launchs a request for Login Bank by API
Request object definition:
requestCode: identifier for bank login (string)
Request example:
const request = 'requesBankLoginIdentifier'
const result = await UnnaxClient.apiInit(request);
The response contains a session ID sid
and array of banks
. Each bank
contains login methods:
{
"sid": "s_asdassdacegrthaf86a90aa6437da4f3",
"banks": [
{
"id": 3,
"name": "Banc Sabadell",
"parameters": [
{
"name": "document_type",
"label": "Tipo de documento",
"type": "option",
"optional": false,
"fields": [
{
"name": "bso_id_number",
"label": "Usuario (DNI)",
"type": "text",
"minLength": 0,
"maxLength": 30
},
{
"name": "bso_sec_card",
"label": "Tarjeta secundaria",
"type": "text",
"minLength": 0,
"maxLength": 30
},
{
"name": "bso_nie",
"label": "NIE",
"type": "text",
"minLength": 0,
"maxLength": 30
}
]
},
{
"name": "username",
"label": "Usuario",
"type": "text",
"optional": false,
"fields": [
{
"name": "username",
"label": "Usuario",
"type": "text",
"minLength": 0,
"maxLength": 20
}
]
},
{
"name": "password",
"label": "Contraseña",
"type": "password",
"optional": false,
"fields": [
{
"name": "password",
"label": "Contraseña",
"type": "text",
"minLength": 0,
"maxLength": 20
}
]
}
]
}]
}