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

ec.sdk

v0.30.4

Published

SDK for ec.api

Downloads

777

Readme

ec.sdk

This is the SDK for all ec.APIs by entrecode. By entrecode.

npm version Build Status Coverage Status Inline docs

Documentation can be found here. If you like to see some code look here.

Getting Started

In order to use this SDK you should be familiar with ec.APIs and the concepts behind those. Please refer to the official documentation to get a basic understanding. The documentation you are reading now will first introduce the basic concept when using the SDK. Secondly it is the complete API documentation for ec.sdk.

For every ec.API you will find an API connector. Use one of those to connect to a certain ec.API. Login and logout for ec.users are special cases and are done in Session API connector. All API connectors of a certain environment share some information. The most important one is any access token either received with Session#login or by calling Core#setToken. This means you can specifiy the token on any API connector and it will be automatically used by all other API connectors. Also it will be saved in a cookie with the name <environment>Token. If any API connector receives a token related Error (Problem) it will be automatically removed from all API connectors and a logout event is triggered. A special case is PublicAPI since this will store the token in a cookie containing the environment and Data Manager shortID of the PublicAPI (for example: stagebeefbeefToken).

Since version 0.13.0 you can create a stand-alone API Connector. By calling the constructor with new Session({ noCookie: true }); the API Connector won't share its token with other API Connectors.

Every action you take in the ec.sdk will be validated before it will be sent as a request to ec.APIs. This means that the provided json schemas are used.

Installation
npm i --save ec.sdk
ES6 / Webpack

Add the following in your webpack.config.js.


const config = {
  // …
  node: {
    fs: 'empty',
    Buffer: false,
    net: 'empty',
    tls: 'empty',
  },
};

Then you can start coding:

import { Session, Accounts, DataManager } from 'ec.sdk';
import AccountResource from 'ec.sdk/src/resources/accounts/AccountResource';
import DataManagerResource from 'ec.sdk/src/resources/datamanager/DataManagerResource';

class MyExample {
  session: Session;
  accounts: Accounts;
  dataManager: DataManager;

  me: AccountResource;
  dm: DataManagerResource;

  constructor() {
    session = new Session();
    accounts = new Accounts();

    session.setClientID('rest');
    // this will also receive events from Accounts and DataManager
    session.on('error', console.error);
  }

  login(email, password) {
    session.login(email, password)
    .then((token) => {
      // if you use stand-alone API Connectors (`noCookie` set to true)
      accounts.setToken(token);

      // or anywhere in the code
      dataManager.setToken(session.getToken());
    });
  }

  setAccountLanguage(lang) {
    Promise.resolve()
    .then(() => {
      if (this.me){
        return this.me;
      }
      return this.accounts.me();
    })
    .then((me) => {
      me.language = lang;
      return me.save();
    })
    .then((meSaved: AccountResource) => this.me = meSaved);
  }

  loadDataManager(id) {
    if (!this.dataManager){
      this.dataManager = new DataManager();
    }

    this.dataManager.dataManager(id)
    .then((dm) =>{
      this.dm = dm;
    });
  }
}
Node

Require statements are different on node. Also, you probably don't want to share tokens in a node.js environment. You'll need to use noCookie or namespacing via cookieModifier.

const ec = require('ec.sdk');
const dataManager = new ec.DataManager({ environment: 'live', cookieModifier: 'myScriptName' });
dataManager.setToken(accessToken);

dataManager.dataManagerList()
.then(list => doSomthingWith(list))
.catch(console.log);
Browsers

This is not officially supported. Mainly exists for usage in jsfiddles or similar.

<script src="https://unpkg.com/ec.sdk/dist/ec.sdk.min.js"></script>
<script>
    console.log('My development stack is old and I should feel old');

    var dataManager = new ec.DataManager('live');
    dataManager.setToken(accessToken);
    dataManager.list()
    .then(list => doSomthingWith(list))
    .catch(console.log);
</script>

Development

Here are two notes on developing ec.sdk:

  • Please use Conventional Commits
  • When releasing a new version use npm run release <semver-version> – This will build docs and changelog etc, npm publish is handled by travis.