GithubHelp home page GithubHelp logo

nordigen-node's Introduction

Nordigen Node.js Library

This is official Node client library for GoCardless Bank Account Data.

For a full list of endpoints and arguments, see the docs.

Before starting to use API you will need to create a new secret and get your SECRET_ID and SECRET_KEY from the GoCardless Bank Account Data Portal.

Requirements

  • Node >= 12.0

Installation

Install library via npm:

npm install nordigen-node --save
# or
yarn add nordigen-node

Example application

Express example application can be found in example directory

Quickstart

// Get secretId and secretKey from bankaccountdata.gocardless.com portal and pass to NordigenClient or load from .env file
const client = new NordigenClient({
    secretId: process.env.SECRET_ID,
    secretKey: process.env.SECRET_KEY
});

// Generate new access token. Token is valid for 24 hours
const tokenData = await client.generateToken();

// Get access and refresh token
// Note: access_token is automatically injected to other requests after you successfully obtain it
const token = tokenData.access;
const refreshToken = tokenData.refresh;

// Exchange refresh token. Refresh token is valid for 30 days
const newToken = await client.exchangeToken({refreshToken: refreshToken});

// Use existing token
client.token = process.env.TOKEN;

// Get list of institutions
const institutions = await client.institution.getInstitutions({country: "LV"});

// Institution id can be gathered from getInstitutions response.
// Example Revolut ID
const institutionId = "REVOLUT_REVOGB21";

// Initialize new bank session
const init = await client.initSession({
    redirectUrl: "https://gocardless.com",
    institutionId: institutionId,
    referenceId: randomUUID()
})

// Get link to authorize in the bank
// Authorize with your bank via this link, to gain access to account data
const link = init.link;
// requisition id is needed to get accountId in the next step
const requisitionId = init.id;

After successful authorization with a bank you can fetch your data (details, balances, transactions)

Fetching account metadata, balances, details and transactions

// Get account id after completed authorization with a bank
const requisitionData = await client.requisition.getRequisitionById(requisitionId);
// Get account id from the list
const accountId = requisitionData.accounts[0];

// Instantiate account object
const account = client.account(accountId);

// Fetch account metadata
const metadata = await account.getMetadata();
// Fetch account balances
const balances = await account.getBalances();
// Fetch account details
const details = await account.getDetails();
// Fetch account transactions
const transactions = await account.getTransactions();
// Optional. You can filter transactions by specific date range
await account.getTransactions({dateFrom: "2021-12-01", dateTo: "2022-01-30"});

Build and publish

  1. Run npm run build
  2. Publish library npm publish

Support

For any inquiries please contact support at [email protected] or create an issue in repository.

nordigen-node's People

Contributors

antoineandrieu avatar asamsig avatar daniellinna avatar dependabot[bot] avatar desclapez avatar dipo avatar ekatvars-gc avatar epicivo avatar janisskuja avatar mattickx avatar safriks avatar victory-sokolov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nordigen-node's Issues

Support maxHistoricalDays parameter on initSession function

Is your feature request related to a problem? Please describe.

I see from the source code that it is possible to provide a maxHistoricalDays parameter to the nordigenClient.initSession() function, but it has no effect on the requisition. The returned value is always 90 days.

Describe the solution you'd like

It would be great to support that parameter in the node library. I believe that it is already supported in your API endpoints.

Describe alternatives you've considered

Additional context

TypeScript

Is your feature request related to a problem? Please describe.
Migrate the repo to TypeScript and benefits of all its advantages (I noticed the types are currently wrong)

Describe the solution you'd like
Migrate the repo to TypeScript

Describe alternatives you've considered
None

Additional context
I'm opened to do that migration

Error while Nordigen node client library on node version > 12.x : Must use import to load ES Module: /../node_modules/nordigen-node/lib/index.js require() of ES modules is not supported.

I am using latest stable node version i.e 16.14.2, I get below mentioned error on compiling the code.

const nordigen_node_1 = require("nordigen-node");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/polyscripts/polyscripts/payments-backend/node_modules/nordigen-node/lib/index.js from /home/../dist/nordigen/nordigen.controller.js not supported.
Instead change the require of index.js in /home/../dist/nordigen/nordigen.controller.js to a dynamic import() which is available in all CommonJS modules.

Date filtering for getTransactions does not work

The optional parameters dateFrom and dateTo have no effect in account.getTransactions function.

Steps to reproduce the behavior:

  1. Use getTransaction feature from AccountAPI
  2. Specify dateFrom and dateTo parameters as intended
  3. Note that they have no effect in the request

The response should return only the transactions which match the defined date range.

I will open a pull request, it was due to a misspelled variable.

Account balance for specific day

Right now, you can get account balance only for the current day AFAIK.

Ok solution would be to add date parameter to API call.
The best solution would be to add date-range like dateFrom and dateTo for which the API would return balances for each day.

The only workaround I can think of is to get todays balance + transactions from today to that specific day and add/subtract each transaction from the current balance however that's not really a great solution, especially if the specific day is far from today.

setToken function is not working

Describe the bug
The setToken function doesn't seems to work for me. I'm running into the following error:

TypeError: client.setToken is not a function.

To Reproduce
Steps to reproduce the behavior:

  1. I just copied the Quickstart code.

Expected behavior
I expect the function to work.

Screenshots
-

Additional context
No fancy things, just a clean Node.js project. The other functions do work for me.

Incorrect order of transactions

Describe the bug
Transactions are not ordered in the correct order on the same day when compared to the bank statement list.

To Reproduce
Steps to reproduce the behavior:

  1. Use getTransactions call from AccountAPI.
  2. Specify dateFrom and dateTo parameters as intended.
  3. Transactions on the same date are not in the correct order compared to the order in the bank statement list. The current behavior is nondeterministic and might or might not be in the correct order for a single request.

Expected behavior
Transactions should always be ordered in the exact same order as in the bank statement list.

Create requisition fails when `accountSelection` is specified

Describe the bug
When calling the createRequisition() method, the server returns status 400 with the following error: Unknown fields {'accountSelection'} in payload

To Reproduce
Steps to reproduce the behavior:

  1. Call createRequisition() and specify accountSelection: true in the input
  2. Server returns:
{
      summary: 'Unknown fields',
      detail: "Unknown fields {'accountSelection'} in payload",
      status_code: 400
}

Expected behavior
Server returns status code 200 and creates a new requisition

Additional context
This might be a typo in the client source code as it sends the parameter as accountSelection but according to the API documentation, the parameter is defined as account_selection.

redirectImmediate might be susceptible to the same error (untested).

Inconsistencies between `createRequisition` input type and API definition

Describe the bug
In the type declaration for createRequisition() method input, the reference, ssn, redirectImmediate and accountSelection parameters are all required although the API does not enforce them.

To Reproduce
Steps to reproduce the behavior:

  • (v 1.2.1) When constructing the input to createRequisition() method call, type checker will emit a warning
  • When calling POST ​/api​/v2​/agreements​/enduser​/ directly via curl without these parameters, the API returns a successful response

Expected behavior
reference, ssn, redirectImmediate, accountSelection should either be marked optional in the type declaration or the API should enforce these parameters.

Issue building typescript

Describe the bug
While trying around with the module, I found out that compiling from typescript is throwing an error with the code from the examples.
Errors:

$ npx tsc
node_modules/nordigen-node/dist/types/api/account.d.ts:53:48 - error TS2339: Property 'country' does not exist on type '{ dateFrom: string; dateTo: string; }'.

53     getPremiumTransactions({ dateFrom, dateTo, country }?: {
                                                  ~~~~~~~

node_modules/nordigen-node/dist/types/index.d.ts:8:40 - error TS2339: Property 'baseUrl' does not exist on type '{ secretId: string; secretKey: string; }'.

8     constructor({ secretId, secretKey, baseUrl, }: {
                                         ~~~~~~~


Found 2 errors in 2 files.

Errors  Files
     1  node_modules/nordigen-node/dist/types/api/account.d.ts:53
     1  node_modules/nordigen-node/dist/types/index.d.ts:8

To Reproduce
Implement that code in your app:

let client = new NordigenClient({
    secretId: 'censored',
    secretKey: 'censored'
});
await client.generateToken();

let inst = await client.institution.getInstitutions({ country: 'LV' });
console.log(inst);

Then let typescript compile.

tsconfig.json:

{
    "compilerOptions": {
      "module": "ES6",
      "esModuleInterop": true,
      "target": "ES6",
      "moduleResolution": "node",
      "sourceMap": true,
      "outDir": "dist",
      "strict": true,
      "typeRoots": [
        "node_modules/@types"
      ],
      "forceConsistentCasingInFileNames": true
    },
    "lib": [ "esnext", "dom", "dom.iterable" ]
}

Expected behavior
Building should be successful.

Additional context
Running with nodemon and ts-node is working as expected.

Expose accesstoken to single page client?

In a SPA that ideally would run without api backend for interacting with Nordigen, would it be ok to expose the access token to the client?

I'm thinking that a standalone script that periodically fetches the access token from Nordigen could be saved in a database where the client could retrieve it (using Pocketbase for database and auth to the app itself) and use it to directly fetch data from Nordigen.

client.initSession has now more required params

Describe the bug
A clear and concise description of what the bug is.

In v1.1.1 -->

 const init = await client.initSession({
        redirectUrl: REDIRECT_URI,
        institutionId: institutionId,
        referenceId: randomUUID()
    })

this would work

but not in v.1.2.4

because we do have not the following required params:

 initSession({ redirectUrl, institutionId, maxHistoricalDays, accessValidForDays, userLanguage, referenceId, ssn, redirectImmediate, accountSelection, }: {
        redirectUrl: string;
        institutionId: string;
        referenceId: string;
        maxHistoricalDays: number;
        accessValidForDays: number;
        userLanguage: string;
        ssn: string;
        redirectImmediate: boolean;
        accountSelection: boolean;
    }): Promise<any>;

so please either update the docs or tell us how to integrate that with the new nordigen version... <3

To Reproduce
Steps to reproduce the behavior:

  1. Specify API endpoint
  2. Specify response & error message

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.
Bildschirm­foto 2023-05-04 um 16 41 42

Additional context
Add any other context about the problem here.

If you're having general trouble with your Nordigen integration or bank related issue, please reach out to our support via email [email protected]

Bank account/transactions subscription

Is it possible to subscribe to new bank accounts and transactions as they are created? I'm making a budgeting app and I think it would be nice if my budget could update in realtime according to transactions/accounts as they happen.

Incorrect JSDoc and Typescript definitions

Describe the bug
JSDoc and Typescript types are incorrect, which provoques compilation issues when is used in a Typescript project.

To Reproduce
As example, lets take a look to this fragment in JS:

/**
* Account api class
* @param {NordigenClient} client
* @param {str} accountId
*/
constructor({client, accountId}) {
this.#client = client;
this.#accountId = accountId
}

...and its generated Typescript:

/**
* Account api class
* @param {NordigenClient} client
* @param {str} accountId
*/
constructor({ client, accountId }: NordigenClient);

As you can see, those types are incorrect. Also there are a lot more definitions in JS that does not produce the correct Typescript types.

Expected behavior
As an example of the correct type for JSDoc:

    /**
     * Account api class
     * @param {Object} params
     * @param {NordigenClient} params.client
     * @param {string} params.accountId
    */
    constructor({client, accountId}) {
        this.#client = client;
        this.#accountId = accountId
    }

...will generate the proper Typescript types:

    /**
     * Account api class
     * @param {Object} params
     * @param {NordigenClient} params.client
     * @param {string} params.accountId
    */
    constructor({ client, accountId }: {
        client: NordigenClient;
        accountId: string;
    });

I forked the repository and made a fix, I will link it to this issue.

Types exported wrong

Describe the bug
I've tried using the package in my Remix Run project and the typings are not working correctly. https://publint.dev/[email protected] says that there's a problem with exporting types.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new Remix Run project
  2. install nordigen-node
  3. import it into a file and you get the error

Expected behavior
Importing the library should work as usual and it should be typed.

Screenshots
image

change the require of /node_modules/nordigen-node/lib/index.js to a dynamic import() which is available in all CommonJS modules

Describe the bug
A clear and concise description of what the bug is.

I am trying to integration nordigen-node v1.1.1 into my firebase cloud function

my package is using

  "compilerOptions": {
    "module": "commonjs",

To Reproduce
Steps to reproduce the behavior:

  1. Specify API endpoint
  2. Specify response & error message

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.
Bildschirmfoto 2022-10-26 um 21 00 20

Additional context
Add any other context about the problem here.

Whenever I try to upload my functions, the deploy will exit with the code shown in the above screeshot

Will you publish the addition of Typescript types to npm?

Is your feature request related to a problem? Please describe.
-

Describe the solution you'd like
I saw that you merged my addition of Typescript types 😄. I was wandering when you would publish these to npm so that I can start using them in my project.

Describe alternatives you've considered
-

Additional context
Btw I've also added the command: npm run gen:types to generate the types from the source code. So whenever you make a change to the project in the future, please make sure to run this command before you commit the changes 🙂.

Migration to GoCardLess

👋

Hi! Not exactly sure if this is a feature request or bug report.

Given that Nordigen was acquired by GoCardLess and is now fully moving under their umbrella - is there a migration path/guide for existing nordigen-node customers?

Thanks

Can't solve "Cannot use import statement outside a module"

Describe the bug
When testing with jest it displays "Cannot use import statement outside a module"

To Reproduce
Steps to reproduce the behavior:
I added the library with npm install nordigen-node --save, wrote code to substitute direct API calls with the methods in the library as the quickstart guide showed, called them in my code and then proceeded in testing the files.

Expected behavior
I expected to solve this error by either adding type:module to package.json, installing babel/nodemon, or in general by specifying that the library must not be executed as a commonjs, but nothing solves the error

Screenshots
immagine

Date filter to getTransactions request

Is your feature request related to a problem? Please describe.

I am storing the end-user's transactions to a database. When I get new transactions, it would be convenient to filter them so that those transactions that I already have, would not be retrieved from Nordigen. At this time, I have to retrieve all the transactions, and do the filtering myself, which means that there is unnecessary network traffic and filtering processes done in our server.

Describe the solution you'd like

It would be great to be able to provide a date range for the getTransactions request, so that only the transactions matching the filter would be fetched. I believe that these filters exist in the API endpoints already, as date_from and date_to parameters.

Describe alternatives you've considered

Other possible filter could be from_transaction_id filter, which would return all transactions after the id provided as parameter. This would be very easy to use in our application, since we would be able to provide the id of the latest transaction that we have fetched, and it would return all the ones we are missing.

Additional context

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.