npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sherex/sbanken

v1.1.0

Published

A node module written in Typescript for interacting with SBanken's API

Downloads

5

Readme

Setup

Creating your ID and secret

If these steps are outdated you can find the updated instructions here and please create an issue or PR here :)

  1. Enable the Beta program on your account. You can do this on the Beta settings page.
  2. Then goto your API overview page to register a new application.
  3. Create a new application, an application key will be shown on the page. This is your applicationId in this module.

Note: Sometimes the API will respond with { error: "invalid_client" } with the new secret, just give it a few miutes to catch up.

  1. Generate a new password, this is your applicationSecret in this module.
  2. Your customerId is your norwegian "personnummer" (11 digits)

Usage

Install

npm i @sherex/sbanken

Typescript

import { SBanken, ClientParamOptions } from '@sherex/sbanken'

const options: ClientParamOptions = {
  applicationId: process.env.SB_APPLICATION_ID!,
  applicationSecret: process.env.SB_APPLICATION_SECRET!,
  customerId: process.env.SB_CUSTOMER_ID!
}

const client = new SBanken(options)

;(async () => {
  console.log('##### Accounts')
  const accounts = await client.getAccounts()
  console.log(accounts[0].balance)

  console.log('##### Customer')
  const customer = await client.getCustomer()
  console.log(`${customer.firstName} ${customer.lastName}`)

  console.log('##### Transactions')
  const transactionsOptions: TransactionParamOptions = {
    startDate: '2020-04-01',
    endDate: '2020-06-14',
    index: '20',
    length: '30'
  }
  const transactions = await client.getTransactions(accounts[0].accountId!, transactionsOptions)
  console.log(transactions.length)
})()

Javascript

const { SBanken } = require('@sherex/sbanken')

const options = {
  applicationId: process.env.SB_APPLICATION_ID,
  applicationSecret: process.env.SB_APPLICATION_SECRET,
  customerId: process.env.SB_CUSTOMER_ID
}

const client = new SBanken(options)

;(async () => {
  console.log('##### Accounts')
  const accounts = await client.getAccounts()
  console.log(accounts[0].balance)

  console.log('##### Customer')
  const customer = await client.getCustomer()
  console.log(`${customer.firstName} ${customer.lastName}`)

  console.log('##### Transactions')
  const transactions = await client.getTransactions(accounts[0].accountId, {
    startDate: '2020-04-01',
    endDate: '2020-06-14',
    index: '20',
    length: '30'
  })
  console.log(transactions.length)
})()

Code API

Hot tip! Use an IDE with Typescript support to get auto-complete for all parameters and data returned. I recommend VSCode.

new SBanken(options)

Create a new SBanken client. Used in the following calls.

SBanken#getToken(): TokenData

Returns the token and information about it.

SBanken#getAccounts(): Account[]

Returns all of your accounts.

SBanken#getAccount(accountId): Account

Returns specified account.

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | accountId | string | undefined | An account ID you got from .getAccounts() or your account number. |

SBanken#getTransactions(accountId, options?): Transaction

Returns transactions for specified account ID, within constraints in options.

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | accountId | string | undefined | An account ID you got from .getAccounts() or an account number (If you use an account number, it will use .getAccount() to get the accountId). | | options.startDate | string | endDate -30 days | Date part of ISO-8601 [2020-07-11]. The start of the query time span. Must be less than or equal to endDate, and less than or equal to the current date +1 day. | | options.endDate | string | current date | Date part of ISO-8601 [2020-08-10]. The end of the query time span. Must be greater than or equal to startDate, and less than or equal to the current date +1 day. | | options.index | string | '0' | The index of the first item to be retrieved, within the time span. | | options.length | string | '100' | Return a number of items items up to this value, starting from options.index. |

SBanken#getCustomer(): Customer

Get information about you as a customer.

Currently supported APIs

Bank - Swagger docs

Customers - Swagger docs

Development

git clone https://github.com/Sherex/node-sbanken
cd node-sbanken
npm i
npm run dev sandbox.ts

Updating swaggers and typings

To update the swagger schemas and typings run npm run spec:update-all. Then run npm run spec:lint:fix to fix the linting errors in those files only.

Adding a new schema

To add a new schema to the module, uncomment (or add) the entry in ./tools/update-specs.ts. Then run npm run spec:update-all and npm run spec:lint:fix.

Now add the new import and exports in ./src/types/sbanken-api.types.ts, in the same format as the others. Splitting the API response data and the actual data and other sections if needed.

Code running

For running code while developing, use npm run dev {file_name} (for example npm run dev sandbox.ts).
This uses ts-node-dev to build and run the code automatically.

Code linting

This repo is using the Standard with Typescript ESlint config.

To check linting run:
npm run lint
To fix the linting run:
npm run lint:fix

Docs

  • https://openbanking.sbanken.no/portal-sandbox/product
  • https://openbanking.sbanken.no/portal-sandbox/documentation
  • https://api.sbanken.no/exec.customers/swagger/index.html
  • https://api.sbanken.no/exec.bank/swagger/index.html

LICENSE

MIT