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 🙏

© 2026 – Pkg Stats / Ryan Hefner

merchi_sdk_ts

v1.2.19

Published

A TypeScript SDK for interacting with the Merchi API.

Readme

Merchi TypeScript SDK

A TypeScript SDK for interacting with the Merchi API.

npm version License: GPL-3.0

Table of Contents

Installation

# Using npm
npm install merchi_sdk_ts

# Using yarn
yarn add merchi_sdk_ts

Quick Start

import { Merchi, Product } from 'merchi_sdk_ts';

// Initialize the SDK
const merchi = new Merchi();

// Fetch a product by ID
Product.get(123).then(product => {
  console.log(product.name);
});

Configuration

The SDK by default is set up to make requests to the Merchi production server at https://api.merchi.co/v6/.

You can customize the API endpoint by:

  1. Setting process.env.MERCHI_BACKEND_URI in your Node.js environment.
  2. Setting window.merchiBackendUri in the browser.
  3. Passing the backendUri directly to the Merchi constructor (highest precedence).

The SDK will look for these in the order of 3, 2, 1, and finally use the default production URL if none are found. The API version (e.g., /v6/) will be appended automatically if not included in your custom URI, assuming the URI ends with the base domain (e.g. https://custom.merchi.co). If your custom URI already includes a path (e.g., https://custom.merchi.co/api/), ensure it ends with a trailing slash for the version to be appended correctly (e.g., https://custom.merchi.co/api/v6/).

Example: Passing backendUri to the constructor

import { Merchi } from 'merchi_sdk_ts';

// Initialize the SDK with a custom backend URI
// This URI should be the base path to your Merchi backend instance.
// The API version (e.g., /v6/) will be appended.
const customBackend = 'https://my-custom-merchi-instance.com/';
const merchi = new Merchi(undefined, undefined, undefined, undefined, customBackend);

// If your custom URI already includes a specific path and you want to control the full endpoint:
const specificCustomBackend = 'https://my-custom-merchi-instance.com/api/custom_version/';
const merchiSpecific = new Merchi(undefined, undefined, undefined, undefined, specificCustomBackend);

// Now, all API calls made using this 'merchi' or 'merchiSpecific' instance
// will be directed to your specified backend.
// For example:
// merchi.Product.get(1) will call https://my-custom-merchi-instance.com/v6/products/1/
// merchiSpecific.Product.get(1) will call https://my-custom-merchi-instance.com/api/custom_version/products/1/

Authentication

The SDK supports several authentication methods:

// Session token authentication (most common)
const merchi = new Merchi('your-session-token');

// Alternative methods
const merchi = new Merchi(
  'your-session-token',     // Session token
  'your-client-token',      // Client token
  'your-invoice-token',     // Invoice token
  'your-cart-token'         // Cart token
);

// The SDK will also attempt to read session_token from cookies
// if no token is provided

Basic Usage

Entity Operations

Each entity supports standard CRUD operations:

// Fetch a single entity
Product.get(123).then(product => {
  console.log(product);
});

// List entities with filtering
Product.list({
  limit: 10,
  offset: 0,
  q: 'search-term'
}).then(response => {
  console.log(response.items);        // Array of products
  console.log(response.metadata);     // Metadata including count, limit, offset
});

// Create a new entity
const product = new Product();
product.name = 'New Product';
product.description = 'Product description';
product.create().then(newProduct => {
  console.log(newProduct.id);
});

// Update an entity
product.name = 'Updated Product Name';
product.save().then(updatedProduct => {
  console.log(updatedProduct);
});

// Delete an entity
product.delete().then(() => {
  console.log('Product deleted');
});

Embedding Related Entities

You can request related entities be included in responses:

Product.get(123, {
  embed: {
    domain: {},
    variations: {
      variationFields: {}
    }
  }
}).then(product => {
  console.log(product.domain);            // Domain entity is included
  console.log(product.variations);        // Variations are included
  console.log(product.variations[0].variationFields);  // Fields are included
});

Available Entities

The SDK provides access to all Merchi entities, including but not limited to:

  • User, Company, Domain
  • Product, Category, Variation
  • Cart, CartItem
  • Job, Assignment, Invoice
  • File, Draft, DraftTemplate
  • Payment, Shipment
  • And many more...

Each entity maps directly to the corresponding API endpoint and data structure.

Examples

Working with Products

import { Merchi, Product } from 'merchi_sdk_ts';

// Initialize Merchi
const merchi = new Merchi('your-session-token');

// Create a new product
const product = new Product();
product.name = 'Custom T-Shirt';
product.description = 'High-quality custom printed t-shirt';
product.public = true;

product.create().then(newProduct => {
  console.log(`Created product with ID: ${newProduct.id}`);
});

Managing a Cart

import { Merchi, Cart, CartItem } from 'merchi_sdk_ts';

// Initialize Merchi
const merchi = new Merchi('your-session-token');

// Create a new cart
const cart = new Cart();
cart.create().then(newCart => {
  // Add an item to the cart
  const cartItem = new CartItem();
  cartItem.productId = 123;
  cartItem.quantity = 2;
  cartItem.cartId = newCart.id;
  
  return cartItem.create();
}).then(newCartItem => {
  console.log('Item added to cart!');
});

TypeScript Support

This SDK is built with TypeScript and provides full type definitions for all entities and operations.

import { Product, EmbedDescriptor } from 'merchi_sdk_ts';

// TypeScript will provide intellisense for all properties
const product = new Product();
product.name = 'New Product';

// Type checking for embed options
const embedOptions: EmbedDescriptor = {
  domain: {},
  variations: {
    variationFields: {}
  }
};

Product.get(123, { embed: embedOptions });

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.