See the API docs for more information about the API.
Examples can be found in the examples/
directory
To install the package, run:
npm install @cnaught/cnaught-node-sdk
We support Node 12+
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);
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.
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
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
After cloning and installing required npm modules, you should follow these practices when developing:
- Use the scripts defined in package.json in this manner
npm run [command_name]
: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.build
transpiles the Typescript into Javascript with the options specified in tsconfig.jsonunit-test
runs our unit tests which live in the unit test directory.build-examples
performs the same action asbuild
and in addition, copies thesrc
to thenode_modules
directory inexamples
such that you can test examples with local changes.
- 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.
- 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 theexamples/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/
.
- One way to use your changed local package in the examples is to copy the output of the
- Update the documentation to reflect any relevant changes and improve the development section.