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

ordercloud-js-sdk

v0.0.5

Published

ordercloud-js-sdk

Downloads

2

Readme

OrderCloud Javascript SDK

This is the OrderCloud Javascript (browser-side) and Node (server-side) SDK. The same distributed JS file can be used for both cases. If you are using angular, we have an SDK specifically for that framework. The npm library is called ordercoud-angular-sdk. If you are using any other SPA framework or web app configuration (such as Backbone, Ember, Jquery, Coffeescript, or just plain-old vanilla javascript), this is the SDK for you!

Install

This library is supported for both npm and bower. For browser-side, we recommend bower. For server-side, we recommend npm.

bower install ordercloud-js-sdk --save

npm install ordercloud-js-sdk --save

Using The OrderCloud Javascript SDK in the Browser

After you succesfully install the SDK, you will need to include the library in your index.html file. We have created two files, one minified and one standard.

<script src=path/to/ordercloud-js-sdk.min.js></script>

or

<script src=path/to/ordercloud-js-sdk.js></script>

We recommend that you use either gulp or grunt to create a build that puts all of your third-party app dependencies in one location. This will make it much easier to inject each of the bower or npm main scripts into your index.html file.

After you have successfully injected the ordercloud-js-sdk, it will be available in the global namespace of your application under OrderCloud. Ensure that any reference you make to OrderCloud come after your inject the script (from above). An example will look like this,

<script src=path/to/ordercloud-js-sdk.min.js></script>
<script>
OrderCloud.Buyers.Create({
  "ID": "buyer_1",
  "Name": "My First Buyer",
  "Active": true
}
</script>

The OrderCloud Javascript SDK uses the q promise library to handle all asynchronous tasks. And since OrderCloud is an API and every method call you make to the server is asynchronous, you will be using this promise library A LOT. The good news, however, is that q is an extremely useful and easy to use library that will simplify your codebase and make it much more readable. An example of how q is used within this SDK is below,

OrderCloud.Categories.Get('category_id_1')
  .then(function(data) {
      //successful
      console.log(data);
    },
    function(ex) {
      //failure
      console.log(ex);
    });

Instead of using a callback function as you may have used previously with asynchronous functions, q has a .then method that you call on the same asynchronous method you wish to handle. Inside of the .then method, you provide it with two functions, the first being the function that handles a success, and the second being the function that handles an exception. Additionally, you can chain the .then methods together, making it quite easy to handle a flow of function handlers.

This is just a basic introduction to how the q promise library works. If you would like to learn more about how you can use q, head over to the documentation here

Beyond the standard OrderCloud API resources and methods available to you in this SDK, there are also a few configuration settings and helper functions that are meant to help you develop without any need to configure how the SDK is being used yourself. Below is a list of these configurations that you will use time and time again,

  1. OrderCloud.Credentials
  • Has two methods to handle logging in and logging out.

    Method | Params | Action
    :---------: | -------- | --------------------
    Get | credentials | Authenticates user and returns an access-token (and refresh-token if applicable)
    Delete | | Removes access-token from cookies

  • Note that the Get method does not save the access-token for you. You must handle the response appropriately using OrderCloud.Auth.SetToken method (down below)

  1. OrderCloud.Auth
  • Provides all necessary methods to work with authentication in OrderCloud (excluding authenticating itself, as shown above using OrderCloud.Credentials)

  • Utilizes cookies to store tokens in the browser upon user-reentry into the application

    Method | Params | Action
    :---------: | -------- | --------------------
    GetToken | | Gets the stored access-token in cookies
    SetToken | token | Sets access token, typically used after with OrderCloud.Credentials.Get