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

@atlasconsulting/bedita-sdk

v3.1.2

Published

A simple BEdita SDK based on axios

Downloads

166

Readme

BEdita API SDK

Github Actions Codecov Scrutinizer Code Quality Build Status

A simple JavaScript SDK for BEdita API based on axios. It is fully written in Typescript and then compiled to JavaScript. Use it as you prefer.

Install

yarn add @atlasconsulting/bedita-sdk

Getting started

The following code uses Promise but you can take advantage of async functions and await operator.

import { ApiProvider } from '@atlasconsulting/bedita-sdk';

// The first argument is the name of the client
// used to register that specific client
const client = ApiProvider.get('bedita', {
    baseUrl: 'https://api-bedita.example.com',
    clientId: '123456',
    clientSecret: 'abcdefg',
    // apiKey: '123456', // as alternative you can use apiKey removing clientId and clientSecret (discouraged)
});

client.get('/documents')
    .then(response => {
        console.log(res.data);
    });

// Authenticate user.
// After authentication the Authorization header will be added to every request.
// The client takes care of JWT token renew too.
client.authenticate('username', 'password')
    .then(response => {
        // Use save() to create or update an object.
        // To update the object add object id to data
        client.save('documents', {
            title: 'My document',
            description: 'The description is here',
        });
    })

After having configured a client you can get that instance everywhere

import { ApiProvider } from '@atlasconsulting/bedita-sdk';

// get the previous registered client
const client = ApiProvider.get('bedita');

// get user data previously authenticated
client.getUserAuth()
    .then(response => {
        // the formattedData property contains a modified response data
        console.log(response.data.formattedData);
    });

In this way it is possible to instantiate different BEdita API clients distinguished by name.

Interceptors

The client takes advantage of Axios Interceptors to intercept request and response before they are handled by then or catch.

A set of default interceptor are always used:

  • AuthInterceptor is responsible for adding Authorization header if needed
  • ContentTypeInterceptor set default content type if no one is passed
  • RefreshAuthInterceptor is responsible for refreshing the access token when expired

An interceptor can be added to the client or to a request. When added to the client it will be used unless it was removed.

import { ApiProvider, MapIncludedInterceptor } from '@atlasconsulting/bedita-sdk';

const client = ApiProvider.get('bedita');
// Map included data inside the relationships
client.addInterceptor(new MapIncludedInterceptor());

A request interceptor must implements RequestInterceptorInterface. A response interceptor must implements ResponseInterceptorInterface.

Storage Adapters

By default the JWT tokens are saved in localStorage but it is possibile to use a different adapter to store that data. There are two different adapters:

  • LocalStorageAdaper
  • MemoryStorageAdapter (to save only in memory)

If you want to store data in a different storage you can implement a new adapter that must implement StorageAdapterInterface.

const client = ApiProvider.get('bedita', {
    baseUrl: 'https://api-bedita.example.com',
    clientId: '123456',
    clientSecret: 'abcdefg',
    storageAdapter: new InnoDbAdapter(), // where class InnoDbAdapter implements StorageAdapterInterface
});

Develop

@todo

Testing

  • run docker image of BEdita API as

    docker run -p 8090:80 --env BEDITA_ADMIN_USR=admin --env BEDITA_ADMIN_PWD=admin --env BEDITA_API_KEY=1234567890 bedita/bedita:latest

    Set the values you want for BEDITA_ADMIN_USR, BEDITA_ADMIN_PWD and BEDITA_API_KEY and the version of docker image, for example bedita/bedita:4.7.0.

  • run test with yarn test

  • launch yarn coverage if you want a coverage report

Linter

  • run eslint as follows:

    yarn lint