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

xero-node-bankfeeds

v0.9.1

Published

NodeJS client for Xero bank feeds API with OAuth 2.0 support

Downloads

7

Readme

xero-node-bankfeeds

npm

Release of SDK with oAuth 2 support

Beta version 0.9.x of xero-node-bankfeeds SDK supports oAuth2 authentication with bank feeds API.

Usage

Installation This SDK is published as an npm package called xero-node-bankfeeds.

npm install --save xero-node-bankfeeds

Getting Started

Create a Xero App

Follow these steps to create your Xero app

  • Create a free Xero user account (if you don't have one)
  • Login to Xero developer center
  • Click "Try oAuth2" link
  • Enter your App name, company url, privacy policy url.
  • Enter the redirect URI (this is your callback url - localhost, etc)
  • Agree to terms and condition and click "Create App".
  • Click "Generate a secret" button.
  • Copy your client id and client secret and save for use later.
  • Click the "Save" button. You secret is now hidden.

Typescript example

A "kitchen sync" app is available that demonstrates interacting with "feedconnections" endpoint. Just download the code and configure.

Javascript Example

This is a barebones example showing how to authenticate and display the name of the Xero organisation you've connected to.

Start with an empty folder

Initialze your app

npm init

Install dependencies

npm install --save xero-node-bankfeeds
npm install express --save
npm install express-session --save

Create your index.js using the code below - don't forget to add your client id and secret

'use strict';

const express = require('express');
const session = require('express-session');
const  xero_node_bankfeeds = require('xero-node-bankfeeds');

const client_id = 'YOUR-CLIENT_ID'
const client_secret = 'YOUR-CLIENT_SECRET'
const redirectUri = 'http://localhost:5000/callback'
const scopes = 'openid profile email bankfeeds offline_access'

const xeroClient = new xero_node_bankfeeds.XeroBankFeedClient({
        clientId: client_id,
        clientSecret: client_secret,
        redirectUris: [redirectUri],
        scopes: scopes.split(" "),
      });

let app = express()

app.set('port', (process.env.PORT || 3000))
app.use(express.static(__dirname + '/public'))
app.use(session({
    secret: 'something crazy',
    resave: false,
    saveUninitialized: true,
    cookie: { secure: false }
}));

app.get('/', function(req, res) {
  res.send('<a href="/connect">Connect to Xero</a>');
})

app.get('/connect', async function(req, res) {
  try {
    let consentUrl = await xeroClient.buildConsentUrl();	  
    res.redirect(consentUrl);
  } catch (err) {
    res.send("Sorry, something went wrong");
  }
})

app.get('/callback', async function(req, res) {
    const url = "http://localhost:5000/" + req.originalUrl;
    await xeroClient.setAccessTokenFromRedirectUri(url);

    // Optional: read user info from the id token
    let tokenClaims = await xeroClient.readIdTokenClaims();
    const accessToken = await xeroClient.readTokenSet();
    
    req.session.tokenClaims = tokenClaims;
    req.session.accessToken = accessToken;
    res.redirect('/feedconnections');
})

app.get('/feedconnections', async function(req, res) {  

  try {
    const accessToken =  req.session.accessToken;
    await  xeroClient.setTokenSet(accessToken);
  
    // CREATE
    var feedConnection = new xero_node_bankfeeds.FeedConnection();
    feedConnection.accountName = "SDK Test Account";
    feedConnection.accountNumber = "123321";
    feedConnection.accountToken = "foobar321";
    feedConnection.accountType = xero_node_bankfeeds.FeedConnection.AccountTypeEnum.BANK;
    feedConnection.currency = xero_node_bankfeeds.CurrencyCode.GBP;
  
    const feedConnections = new xero_node_bankfeeds.FeedConnections();
    feedConnections.items = [feedConnection];

    const response = await xeroClient.bankFeedsApi.createFeedConnections(xeroClient.tenantIds[0], feedConnections);
    res.send("Bank account create with ID: " + response.body.items[0].id );    
} catch (err) {
    console.log(err.body);
    res.send("Sorry, something went wrong");
  }
})

const PORT = process.env.PORT || 5000;
app.listen(PORT, function() {
  console.log("Your Xero basic public app is running at localhost:" + PORT)
})

Project Structure

src/
  |-  gen/        autogenerated TypeScript
  `-  *.ts        handwritten TypeScript
dist/             compiled JavaScript
package.json