Socket
Socket
Sign inDemoInstall

ordercloud-js-sdk

Package Overview
Dependencies
1
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ordercloud-js-sdk

ordercloud-js-sdk


Version published
Maintainers
2
Install size
560 kB
Created

Readme

Source

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.

    MethodParamsAction
    GetcredentialsAuthenticates user and returns an access-token (and refresh-token if applicable)
    DeleteRemoves 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

    MethodParamsAction
    GetTokenGets the stored access-token in cookies
    SetTokentokenSets access token, typically used after with OrderCloud.Credentials.Get

Keywords

FAQs

Last updated on 22 Dec 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc