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

optimizely-x-node-client

v0.1.1

Published

Optimizely X Client for Node.js

Downloads

7

Readme

Optimizely X Node Client

A JavaScript/Node wrapper library for the Optimizely REST API v2.0 (https://developers.optimizely.com/rest/v2/), proudly created and open sourced by Optimizely Solutions Partner, Web Marketing ROI.

Installation

$ npm install optimizely-x-node-client

Usage

// Require the optimizely-x-node-client package
var OptimizelyClient = require('optimizely-x-node-client');

// Define OAuth 2 credentials in the form of an object.
// If you use the "OAuth 2.0 authorization code" grant, use the following object.
var authCredentials = {
    "clientId" : "YOUR_CLIENT_ID",
    "clientSecret" : "YOUR_CLIENT_SECRET",
    "accessToken" : "YOUR_ACCESS_TOKEN",
    "refreshToken" : "YOUR_REFRESH_TOKEN"
};

// Or, if you use the "OAuth 2.0 implicit grant" or "Optimizely personal 
// token", use the following object. Please note that personal tokens are not
// recommended to use in production environments.
var authCredentials = {
    "accessToken" : "YOUR_ACCESS_TOKEN",
};

// Create an instance of the OptimizelyClient. You can do that using the following lines of code:
var oc = new OptimizelyClient(authCredentials);

// Do something with the client. The client uses Bluebird Promises as return values of its methods. 

// For example, get the first page of projects, 25 projects per page
oc.getProjects({page: 1, per_page:25}).then(function(data){
    // Extract projects from the result. 
    // The result (the data variable) is an object containing the following fields:
    // - `url` - the URL of the request
    // - `statusCode` - the response status code (e.g. 200)
    // - `headers` - the response headers
    // - `meta` - parsed headers (used for pagination and rate limiting)
    // - `payload` - the array of projects

    // Dump the list of projects to the console
    console.log("%o", data.payload);
    
    // When the client makes a request, it may get the new access token by the refresh token 
    // (if the existing access token already expired). When you are done with the client, 
    // you may save the (updated) oc.authCredentials to a file or database for later consuming by the client.
    // If you don't save the new credentials/consume them to the client, the client will retrieve the new 
    // access token with each request (unneeded work). 
    var fs = require('fs');
    fs.writeFile("auth_credentials.json", JSON.stringify(oc.authCredentials), function(err) {
        if(err) {
            return console.log(err);
        }
    });
    
    return oc;
}.bind(oc));

More Examples

Creating a Project

var newProject = {
    "name" : "Some Project",
    "account_id" : 12345,
    "confidence_threshold" : 0.9,
    "platform" : "web",
    "status" : "active",
    "web_snippet" : {
      "enable_force_variation" : false,
      "exclude_disabled_experiments" : false,
      "exclude_names" : true,
      "include_jquery" : true,
      "ip_anonymization" : false,
      "ip_filter" : "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
      "library" : "jquery-1.11.3-trim",
      "project_javascript" : "alert(\"Active Experiment\")"
    }
};

oc.createProject(newProject)
  .then(function(data) {
      // The following will dump the data of the newly created project
      console.log("%o", data.payload);
  });

Reading a Project

oc.getProject({id: 123456})
  .then(function(data) {
      // The following will output the data of the project with ID 123456
      console.log("%o", data.payload);
  });

Running Unit Tests

This library uses Mocha for testing. To run unit tests, use the following command:

npm test

If you want to run integration tests against a real Optimizely account, rename test/auth_credentials.json.dist to test/auth_credentials.json and type your credentials in that file. Then, create the OPTIMIZELY_X_NODE_TEST_INTEGRATION environment variable as follows

export OPTIMIZELY_X_NODE_TEST_INTEGRATION=1

and then run unit tests.

Copyright and license

Code copyright 2017 Web Marketing ROI. Released under the Apache 2.0 License.