Skip to content

Techsolace-Products/storentiajs

Repository files navigation

Storentia Node.js SDK

Official SDK for Storentia API. Type-safe, GraphQL-powered, fully documented.

Install

npm install @storentia/sdk

Setup

import { Storentia } from '@storentia/sdk';

const storentia = new Storentia({
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret'
});

Credentials from Storentia dashboard. Auto-authenticates on first request.

Usage

Products

// Get single product
const product = await storentia.products.get('product-id');

// List products
const { data, pageInfo } = await storentia.products.list({
  status: 'ACTIVE',
  pagination: { page: 1, limit: 20 }
});

// Create product
const newProduct = await storentia.products.create({
  title: 'T-Shirt',
  sellingPrice: 29.99,
  originalPrice: 39.99,
  sku: 'TSHIRT-001'
});

// Update product
await storentia.products.update('product-id', {
  sellingPrice: 34.99,
  originalPrice: 44.99
});

// Delete product
await storentia.products.delete('product-id');

Variants

// Generate variants from options
const variants = await storentia.products.generateVariants('product-id');

// Create variant
const variant = await storentia.products.createVariant({
  productId: 'product-id',
  title: 'Red / Large',
  sku: 'TSHIRT-001-RED-L'
});

// Update variant
await storentia.products.updateVariant('variant-id', { stock: 50 });

// Delete variant
await storentia.products.deleteVariant('variant-id');

Options & Values

// Add option (e.g., "Color")
const option = await storentia.products.addOption({
  productId: 'product-id',
  name: 'Color'
});

// Add option value (e.g., "Red")
const value = await storentia.products.addOptionValue({
  optionId: 'option-id',
  value: 'Red'
});

// Update/delete
await storentia.products.updateOption('option-id', { name: 'Colour' });
await storentia.products.deleteOptionValue('value-id');

Collections

// Add products to collection
await storentia.products.addToCollection('collection-id', ['product-1', 'product-2']);

// Remove from collection
await storentia.products.removeFromCollection('collection-id', ['product-1']);

Inventory

// List inventory across all products/variants
const { data, pageInfo } = await storentia.products.listInventory({
  pagination: { page: 1, limit: 50 }
});

Cart

Requires customer JWT authentication.

// Get cart
const cart = await storentia.carts.get();

// Add item to cart
const item = await storentia.carts.addItem({
  productId: 'product-id',
  quantity: 1
});

// Update cart item quantity
await storentia.carts.updateItem({
  cartItemId: 'cart-item-id',
  quantity: 5
});

// Remove item from cart
await storentia.carts.removeItem('cart-item-id');

// Clear entire cart
await storentia.carts.clear();

Blog Posts

// Get/list/create/update/delete
const post = await storentia.blogs.get('post-id');
const { data, pageInfo } = await storentia.blogs.list({ pagination: { limit: 10 } });
const newPost = await storentia.blogs.create({ title: 'Hello', content: '...' });
await storentia.blogs.update('post-id', { title: 'Updated' });
await storentia.blogs.delete('post-id');

Pages

// Get/list/create/update/delete
const page = await storentia.pages.get('page-id');
const { data, pageInfo } = await storentia.pages.list();
const newPage = await storentia.pages.create({ pageTitle: 'About', content: '...' });
await storentia.pages.update('page-id', { pageTitle: 'Updated' });
await storentia.pages.delete('page-id');

Error Handling

import { ApiError } from '@storentia/sdk';

try {
  const product = await storentia.products.get('invalid-id');
} catch (err) {
  if (err instanceof ApiError) {
    console.error(`${err.statusCode}: ${err.message}`);
  }
}

Authentication

SDK uses OAuth2 client credentials. Get credentials from dashboard. Auto-refreshes tokens before expiry.

Override token:

storentia.setAccessToken('pre-obtained-token');

Config

const storentia = new Storentia({
  clientId: string,      // Required
  clientSecret: string,  // Required
  timeout: 30000         // Optional, milliseconds
});

IDE Help

Hover on any method/type for docs. Full JSDoc coverage.

Build & Test

npm run build
npm test

License

MIT

About

Storentia Software Development Kit for NodeJs based applications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors