Node.js API Client
This guide will get you all set up with our Node.js API Client, ready to integrate pricing, payments, authentication and more into your storefront.
The client is intended to be used for customer facing applications, with built-in security token handling including automatic refreshing of access tokens.
Make sure to add your local development or test environment URLs to the whitelisted URLs of your Moonbase account if you are using this package in the browser. Otherwise, you will see CORS issues when calling endpoints.
Getting started
Start by adding the package to your project
npm install @moonbase.sh/storefront-api --save
Now you're ready to instantiate the client itself:
import { MoonbaseClient } from '@moonbase.sh/storefront-api'
const client = new MoonbaseClient({
endpoint: 'https://{YOUR-ACCOUNT-ID}.moonbase.sh',
});
If you have custom domains enabled for your customer portal, use that instead of the moonbase.sh domain.
Endpoint collections
The client exposes a number of endpoint collections:
- Identity - For all authentication concerns
- Inventory - For getting customer inventory of licenses & products
- Orders - For handling order & cart contents
- Storefront - For getting storefront products and bundles
- Vouchers - For redeeming vouchers
All endpoint collections come with TypeScript types that explain the models.