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

onep

v0.4.1

Published

Node bindings for the Exosite One Platform APIs

Downloads

5

Readme

This is a node.js library that provides access to the One Platform RPC API.

NPM

Usage

var rpc = require('onep/rpc');
rpc.call(cik, 'info', [{alias: ''}, {}],
  function(err, rpcresponse, httpresponse) {
  if (err) {
    console.log('error: ' + err);  
  } else {
    if (rpcresponse[0].status === 'ok') {
      console.log(JSON.stringify(rpcresponse[0].result));
    } else {
      console.log('Bad status: ' + rpcresponse[0].status);
    }
  }
});

API

rpc.call

Make a single call to the RPC API.

rpc.call(auth, procedure, arguments, callback)
  • auth may be a 40 character client key (e.g. '0808160000000000000000000000000000000000'), or an auth object (e.g. {cik: '0808160000000000000000000000000000000000', client_key: 'e208160000000000000000000000000000000000'}). See the RPC documentation for details.
  • procedure is the procedure name, e.g. 'read' or 'info'.
  • arguments is a list of arguments to pass the call. These are specific to <procedure>. See the RPC documentation for a list of procedures and arguments.
  • callback is a function that takes three parameters: err is null if the call was made successfully (no HTTP or RPC general error). If the call failed, err contains the error message. rpcresponse contains a list containing a single RPC response. httpresponse is the response object.

Example

var rpc = require('onep/rpc');
rpc.call(
    cik,
    'listing',
    [['client', 'dataport'], {}],
    function(err, rpcresponse, httpresponse) {
      if (err) {
        console.log('error: ' + err);
      } else {
        console.log('response: ' + util.inspect(rpcresponse, false, null));
      }
  });

// output: 
response: [ { status: 'ok',
    result: 
     { client: [ '0808160000000000000000000000000000000000',
         'c138cc0000000000000000000000000000000000',
         'fdc8160000000000000000000000000000000000' ],
       dataport: [ '7e5c6f0000000000000000000000000000000000' ] } } ]

rpc.callMulti

Make multiple calls to the RPC API.

rpc.callMulti(auth, calls, callback)
  • auth may be a 40 character client key (e.g. '0808160000000000000000000000000000000000'), or an auth object (e.g. {cik: '0808160000000000000000000000000000000000', client_key: 'e208160000000000000000000000000000000000'}). See the RPC documentation for details.
  • calls is a list of calls like this: {procedure: <procedure>, arguments: <arguments>}. See the RPC documentation for a list of procedures and arguments.
  • callback is a function is called when the call completes. It takes three parameters: err is null if the call was made successfully (no HTTP or RPC general error). If the call failed, err contains the error message. rpcresponse contains a list of RPC responses. httpresponse is the response object.

Example

// get listing and info in one request
rpc.callMulti(
  cik,
  [
    {procedure: 'info', arguments: [{alias: ""}, {basic: true}]}
    {procedure: 'listing', arguments: [['client', 'dataport']]},
  ],
  function(err, rpcresponse, httpresponse) {
    if (err) {
      console.log('error: ' + err);
    } else {
      console.log('response: ' + util.inspect(rpcresponse, false, null));
    }
});

// output:
response: [ { id: 0,
    status: 'ok',
    result: 
     { client: [ '0808160000000000000000000000000000000000',
         'c138cc0000000000000000000000000000000000',
         'fdc8160000000000000000000000000000000000' ],
       dataport: [ '7e5c6f0000000000000000000000000000000000' ] } },
  { id: 1,
    status: 'ok',
    result: 
     { basic: 
        { modified: 1374553089,
          subscribers: 0,
          type: 'client',
          status: 'activated' } } } ]

rpc.tree

Return the RIDs of all descendants of a client.

rpc.tree(auth, options, callback)
  • auth may be a 40 character client key (e.g. '0808160000000000000000000000000000000000'), or an auth object (e.g. {cik: '0808160000000000000000000000000000000000', client_key: 'e208160000000000000000000000000000000000'}). See the RPC documentation for details.

  • options is an object with the following keys, all optional:

    • depth stop at a given depth from the root client (if omitted, depth is not limited)

    • visit function to call for each resource visited. It is called with rid, type, and depth parameters.

    • types list of type strings. Options are 'dataport', 'datarule', 'dispatch'. If omitted, visits only clients.

    • info if non-null, calls info on each resource with the specified options, e.g., {basic: true}. May also be a function called with rid, type, and depth parameters for each resource. If a function, it should return null or info options for that resource.

  • callback is a function is called when the call completes. It takes the following parameters:

    • err is null if the call succeeded. If the call failed, err contains the error message.

    • tree is the tree. If the call failed, it is undefined.

Example

rpc.tree(
  '76343a56f23d9ee80f2569c8209f4e9b11a5752e',
  {
    depth: 1,
    visit: function (rid, type, depth) {
      console.log(rid + ' (' + type + ') depth:' + depth);
    },
    types: ['dataport', 'datarule', 'dispatch'],
    info: function(rid, type, depth) {
      return type === 'client' ? {basic: true} : null;
    }
  },
  function(err, tree) { 
    console.log(err ? 'Error ' + err : JSON.stringify(tree, null, 2));
  });

// output
datarule
30e8a54ef29e55415b444ed72a961be4ea0ec270 (client) depth:0
0affc14ebdf520587b6957170ec6af06b7b6ca2a (dataport) depth:1
cbf6f7731ed8ae0285b2e8f9b437356544332679 (dataport) depth:1
a0ebc3d703c94e9b37bb4a2796e447334d7ffea2 (datarule) depth:1
{
  "rid": "30e8a54ef29e55415b444ed72a961be4ea0ec270",
  "type": "client",
  "children": [
    {
      "rid": "0affc14ebdf520587b6957170ec6af06b7b6ca2a",
      "type": "dataport"
    },
    {
      "rid": "cbf6f7731ed8ae0285b2e8f9b437356544332679",
      "type": "dataport"
    },
    {
      "rid": "a0ebc3d703c94e9b37bb4a2796e447334d7ffea2",
      "type": "datarule"
    }
  ],
  "info": {
    "basic": {
      "modified": 1422061952,
      "subscribers": 0,
      "type": "client",
      "status": "activated"
    }
  }
}

rpc.batch

Make a lot of RPC calls, splitting the calls into evenly sized chunks to avoid timeouts and calling in parallel to go fast.

rpc.batch(auth, calls, options, callback)
  • auth is an RPC auth object or CIK string

  • calls is an array of call objects like this: {procedure: <procedure>, arguments: <args>}

  • options are:

    • chunkSize is the number of calls per request

    • parallelLimit is the maximum number of concurrent requests to run in parallel

rpc.walk

Walk the object returned by tree().

rpc.walk(tree, visit);
  • tree is the object returned by calling tree()

  • calls visit(resource, depth, parentRID) on each resource. For the root resource, parentRID is undefined.

rpc.setOptions

Set options for connecting to the One Platform.

rpc.setOptions(\<options\>)
  • <options> contains one or more options to update. Default options are as follows:
{
  host: 'm2.exosite.com',
  path: '/api:v1/rpc/process',
  agent: 'node-onep',
  https: true,
  port: 443,
  strictSSL: true
}

You may also specify timeout in milliseconds, which defaults to the default for the request module.

Tests

$ cp test/config-template.js test/config.js
$ mocha

By default the tests run against the mock 1P server. To make them run against production 1P, modify test/config.js with a production CIK and turn off using the mock server.