Skip to content

Merion-Dynamics/cnaught-node-sdk

 
 

Repository files navigation

Build Status npm version Software License

Documentation

See the API docs for more information about the API.

Examples

Examples can be found in the examples/ directory

Installation

To install the package, run:

npm install @cnaught/cnaught-node-sdk

Support

We support Node 12+

Usage

All you need to get started is your API Key, which can be generated on your API Keys Page. Create a client with the given API Key:

import { CNaughtApiClient } from "@cnaught/cnaught-node-sdk";

// Initialize your client with your CNaught API key
const apiKey = "Your API Key";
const client = new CNaughtApiClient(apiKey);

Placing an order

Once you've set up your client with your API Key, placing an Offsets Order is easy

// ride order
const order = await client.placeRideOrder({ distance_km: 10 });

// or a generic order
const order = await client.placeGenericOrder({ amount_kg: 20 });

order will contain all the information normally found in a successful response from our Place Order endpoint.

Checking your order status

You can check the status of your order using its id

const orderDetails = await client.getOrderDetails(order.id);

orderDetails will contain all information normally found in a successful response from our Get Order By Id endpoint

Getting order history

You can retrieve a list of orders with optional parameters

const orders = await client.getListOfOrders();

// limit amount of retrieved orders
const orders = await client.getListOfOrders(3);

// get orders starting after a certain orders id
const orders = await client.getListOfOrders(undefined, "Umx5c6F7pH7r");

orders will contain a list of orders details having all information normally found in a successful response from our Get List of Orders endpoint

For CNaught Node SDK Developers

After cloning and installing required npm modules, you should follow these practices when developing:

  1. Use the scripts defined in package.json in this manner npm run [command_name]:
    1. lint checks that you are not violating any code style standards. This ensures our code's style quality stays high improving readability and reducing room for errors.
    2. build transpiles the Typescript into Javascript with the options specified in tsconfig.json
    3. unit-test runs our unit tests which live in the unit test directory.
    4. build-examples performs the same action as build and in addition, copies the src to the node_modules directory in examples such that you can test examples with local changes.
  2. Add any relevant test logic if you add or modify any features in the source code and check that the tests pass using the scripts mentioned above.
  3. Update the examples provided to illustrate any relevant changes you made, and check that they work properly with your changed local cnaught-node-sdk.
    • One way to use your changed local package in the examples is to copy the output of the build script into the examples/node_modules/cnaught-node-sdk. On Unix, this can be simply done with the following command when in the root directory: $ cp -r dist/src examples/node_modules/cnaught-node-sdk/.
  4. Update the documentation to reflect any relevant changes and improve the development section.

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 65.5%
  • JavaScript 34.5%