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

backlog-js

v0.13.3

Published

Backlog API v2 client for browser and node

Downloads

1,666

Readme

backlog-js CI npm version

Backlog API version 2 client for browser and node.

Required reading

Please check out the Nulab Backlog API page.

Installation

npm:

$ npm install --save backlog-js

Getting started

Append your "API Key" or "OAuth2 Access Token" to requests to the API to return data.

import 'isomorphic-form-data';
import 'isomorphic-fetch';
import * as backlogjs from 'backlog-js';

// 'xxx.backlog.jp' or 'xxx.backlogtool.com' or 'your package host'
const host = 'yourSpaceHost';
const apiKey = 'yourApiKey';
const accessToken = 'yourAccessToken';

// Use API Key
const backlog = new backlogjs.Backlog({ host, apiKey });

// Use OAuth2 Access Token
const backlog = new backlogjs.Backlog({ host, accessToken });

// Returns information about your space.
backlog.getSpace().then(data => {
  console.log('space:', data);
}).catch(err => {
  console.log('error:', err.message);
});

Other Example

Download File

// node
backlog.getSpaceIcon().then(data => {
  data.body.pipe(fs.createWriteStream(`./${data.filename}`));
}).catch(err => {
  console.log('error:', err.message);
});

// browser
backlog.getSpaceIcon().then(data => {  
  data.blob().then((blob) => {
    const objectURL = URL.createObjectURL(blob);
    const element = window.document.querySelector('#image');
    element.src = objectURL;
  });
}).catch(err => {
  console.log('error:', err.message);
});

Upload File

// node
const formData = new FormData();
formData.append("filename", "sample.png");
formData.append("file", fs.createReadStream("./sample.png"));

// browser
// <form id="upload_form" method="post" enctype="multipart/form-data" >
//   <input type="file" name="file" >
// </form>
const $form = window.document.querySelector('#upload_form');
const formData = new FormData($form);

backlog.postSpaceAttachment(formData).then(data => {
  console.log('success:', data);
}).catch(err => {
  console.log('error:', err.message);
});

Use OAuth2 for authentication

Details on the OAuth2 process are available here.

Here are the basic steps for OAuth2 using the Express:

import * as express from 'express';
import * as backlogjs from 'backlog-js';

const app = express();

const host = 'xxx.backlog.jp'; // or 'xxx.backlogtool.com' or 'your package host'
const clientId = 'yourClientId';
const clientSecret = 'yourClientSecret';
const redirectUri = 'https://localhost:3000/callback';
const state = 'yourState';

const credentials = { clientId, clientSecret }
const oauth2 = new backlogjs.OAuth2(credentials);

const authorizationURL = oauth2.getAuthorizationURL({ host, redirectUri, state });

app.get('/auth', (req, res) => {
  res.redirect(authorizationURL);
});

app.get('/callback', async (req, res) => {
  const code = req.query.code;
  try {
    const accessToken = await oauth2.getAccessToken({ host, code, redirectUri });
    console.log('Access Token:', accessToken);

    // save access token.

    const myself = await new backlogjs.Backlog({
      host, accessToken: accessToken.access_token
    }).getMyself();
    console.log('Myself:', myself);

    res.redirect('/');
  } catch (e) {
    console.log('Access Token Error', e.message);
    res.redirect('/login');
  }
});

app.get('/', (req, res) => {
  res.send('Hello');
});

app.get('/login', (req, res) => {
  res.send('<a href="/auth">Login with Backlog</a>');
});

app.listen(3000);

console.log('Express server started on port 3000');

License

MIT License

  • http://www.opensource.org/licenses/mit-license.php