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

@webeetle/core-sdk

v1.2.1

Published

Core SDK

Downloads

28

Readme

Core SDK

js-standard-style Build Status Greenkeeper badge

Core SDK is a small library that help you to build your own SDK in your Javascript Application.

Create your own SDK

Start to create your SDK is really simple.

import SDK from '@webeetle/core-sdk'

const sdk = new SDK()

Now you have an instance of your sdk. Basicly you now have a sdk.req. This property defined is an instance of axios library. Check out how to use it here.

In addition to having the property, you will have a set of functionality such as:

  • decorate: you can decorate your sdk instance with your functionalities.

  • log: you have a predefined logger.

  • addClient: allow you to add axios based client configuration.

  • addService: allow you to add plugin to your instance.

Options

You can pass to the core-sdk constructor a set of options:

  • name: the name of your sdk.

  • clients: a key value object where the key represent the name and the value is an object that represent an axios client configuration.

  • logLevel: one of info, warn, error (predefined), trace.

Example

import SDK from '@webeetle/core-sdk'

const mySdk = new SDK({
  name: 'WeBeetle SDK',
  clients: {
    v1: {
      baseUrl: 'http://api.webeetle.com/v1',
      headers: {'Authorization': 'Bearer 12333321122222'}
    },
    v2: {
      baseUrl: 'http://api.webeetle.com/v2',
      headers: {'Authorization': 'Bearer 44443322222222'}
    }
  },
  logLevel: 'info'
})

Perfect now yoou have your configured sdk instance. If you have the necessity to invoke an endpoint on the v1 api version you can simply:

mySdk.v1.post('/your/endpoint')
  .then(response => {
    // Do something useful here
  })
  .catch(e => {
    // Manage the error
  })

or if you want to use v2 api in an async function:

async function myUtilityFunction () {
  try {
    const response = await mySdk.v2.post('/your/endpoint')
    // Do something userful here
  } catch (e) {
    // Manage your error here
  }
}

Decorate

The API of your sdk instance allows you to add new properties that you can use everywhere in your application. Here an example:

import SDK from '@webeetle/core-sdk'

const mySdk = new SDK()
mySdk.decorate('sum', (a, b) => a + b)

and somewhere else in your application you can use it as follow:

const total = mySdk.sum(5, 30)

With the decorate API you can store everything you want. For example a configuration object.

Add service

The core-sdk api expose another method that allow you to expose a service. For example, if you need to expose a set of functionality to manage users (create, update, delete) you can create a service, and decorate the main sdk instance. Below an example:

// file users.js

import { plugin } from '@webeetle/core-sdk'

export default plugin((instance, name) => {
  instance.decorate(name, {
    create: async userData => {
      // create you user
    },
    getUserByUsername: async username => {
      // get user by username
    },
    update: async userData => {
      // update your user
    },
    delete: async username => {
      // delete your user
    }
  })
})
// file mySdk.js

import SDK from '@webeetle/core-sdk'
import users from '/path/to/users'

const mySdk = new SDK()
mySdk,addService('users', users)

// now we can use it
mySdk.users.create({
    name: 'Davide',
    username: 'davide'
  })
  .then(response => {
    // do something 
  })
  .catch(e => {
    // do something 
  })

Contributing

If you feel you can help in any way, be it with examples, extra testing, or new features please open a pull request or open an issue.

The code follows the Standard code style.

js-standard-style

Running Tests

Simply run npm run test from command line.

Acknowledgements

This project is kindly sponsored by Webeetle s.r.l.

License

Licensed under MIT.