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

boundless-api-client

v1.0.3

Published

The official JavaScript + TypeScript client library for Boundless Commerce

Downloads

395

Readme

Boundless API client

JavaScript client for Boundless Commerce API.

About Boundless Commerce

API’s First Headless E-commerce CMS: We Provide An Admin-Side For Store Management, Powerful API, And Ready-To-Use Checkout Area.

Self-Hosted solution:

There is an option for Running Boundless-Commerce on your own server. Read more at Open-Source Headless eCommerce Platform

Ready to use online-shops (NextJS examples):

Just clone and go!

Ready to use checkout area:

WIX version:

API

API Specification

Installation

yarn add boundless-api-client or npm install boundless-api-client --save

Getting Started

Generate access token in the control panel.

Setting up with a permanent token

import {BoundlessClient} from 'boundless-api-client';
const apiClient = new BoundlessClient('<YOUR PERMANENT TOKEN>');
apiClient.setInstanceId('<YOUR INSTANCE ID>');

//fetch products:
apiClient.catalog.getProducts().then(data => console.log(data));

Generate token and make a request

Generate a token yourself is more secure way. Use the following approach to issue an access-token:

import {BoundlessClient} from 'boundless-api-client';
import {generateBoundlessToken} from 'boundless-api-client/token';

const token = generateBoundlessToken('<YOUR CLIENT ID>', '<YOUR SECRET>', '<YOUR INSTANCE ID>');
const apiClient = new BoundlessClient(token);
apiClient.setInstanceId('<YOUR INSTANCE ID>');

//fetch products:
apiClient.catalog.getProducts().then(data => console.log(data));

Library structure

API client

import {BoundlessClient} from 'boundless-api-client';
const apiClient = new BoundlessClient('<TOKEN>');
apiClient.setInstanceId('<INSTANCE ID>');

The client splits into these parts:

Catalog

Consists methods for working with the catalog (products, categories, etc.):

const {products, pagiantion} = await apiClient.catalog.getProducts();
const categories = await apiClient.catalog.getCategoryTree();
//...

For a full list of methods please visit the official documentation.

Cart

Consists methods for working with the cart.

//creates a cart:
const cart = await apiClient.cart.retrieveCart();

//fetch cart info (e.g. cartId is stored in cookie):
const cart = await apiClient.cart.getCartInfo('<CART ID>');

//fetch cart items
const data = await apiClient.cart.getCartItems('<CART ID>');

//add to cart
const data = await apiClient.cart.addItemToCart('<CART ID>', '<ITEM ID>', '<QTY>');
//...

For a full list of methods please visit the official documentation.

Checkout

Consists methods for working with the checkout.

const checkoutData = await apiClient.checkout.init('<CART ID>');
const {customer} = await apiClient.checkout.saveContactsData({order_id: '<ORDER ID>', email: '<CUSTOMER EMAIL>'});
//...

For a full list of methods please visit the official documentation.

Customer

Consists methods for working with the customer.

const {customer, authToken} = await apiClient.customer.login('<EMAIL>', '<PASS>');
const {customer, authToken} = await apiClient.customer.register({...customerData});

If there is a customer auth token, you need to specify it in the client:

apiClient.setCustomerAuthToken(authToken);

//reset token:
apiClient.setCustomerAuthToken(null);

//get token:
apiClient.getCustomerAuthToken();

For a full list of methods please visit the official documentation.

Public order's methods

Consists methods for working with customer's orders:

const order = await apiClient.customerOrder.getOrder('<ID>');
await apiClient.customerOrder.setCustomAttrs({order_id, attrs});
//...

For a full list of methods please visit the official documentation.

Private order's methods

Access is available only for tokens with the management rights.

const {orders, pagination} = await apiClient.adminOrder.getOrders();

For a full list of methods please visit the official documentation.

Thumbnail generation

To generate a thumbnail by a local path:

const thumb = apiClient.makeThumb({imgLocalPath, maxSize});
thumb.getSrc(); //returns URL to the media server

To get thumbnail attributes (width and height) pass original width/height:

const thumb = apiClient.makeThumb({imgLocalPath, maxSize, originalWidth, originalHeight});
thumb.getAttrs(); //returns {src, width, height}

Thumbnail transformations:

const thumb = apiClient.makeThumb({imgLocalPath, maxSize});

//Set quality:
thumb.setQuality('<low | normal | hight>');

//set ratio:
thumb.setRatio('<1-1 | 2-3 | 3-2 | 4-5 | 5-4 | 3-4 | 4-3 | 16-9 | 9-16>');

//set pad: boolean
thumb.setPad(value);

//blur image, blur - number: 0-15
thumb.setBlur(blur);

//background: hex, e.g. 'ffffff'
thumb.setBackground(hex);

//grayscale: boolean
thumb.setGrayscale(value);

//get resulting SRC:
thumb.getSrc();

Arbitrary requests

There are methods in the API which aren't covered by the interface access, so you need to execute requests manually:

//setup the client in the same way:
import {BoundlessClient} from 'boundless-api-client';
const apiClient = new BoundlessClient('<YOUR TOKEN>');

//executing GET request
const {data, headers} = await apiClient.createRequest().get('/catalog/attributes');

//POST
await apiClient.createRequest().post('/catalog/products', {
	title: 'My new product',
	slug: '...'
});

//PUT
await apiClient.createRequest().put('/catalog/products/1', {title: 'my new title'});

apiClient.createRequest() returns instance of Axios Fetch Adapter (Axios was replaced to fetch) - pre-configured instance for API requests.

Example of files uploader (where file is instance of File):

const formData = new FormData();
formData.append('file_name', file.name);
formData.append('file', file);
formData.append('for_product_id', 1);

const {data} = await apiClient.createRequest().post('/files/images/upload', formData);

How to build library?

yarn build

NextJS eCommerce templates - Free. Ready to use. Just clone & deploy!