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

@spurtcommerce/product

v1.3.0

Published

Spurtcommerce Product

Downloads

194

Readme

Spurtcommerce Product

The @spurtcommerce/product package provides a versatile set of functions for handling various operations in a Node.js application. It streamlines product-related tasks, simplifies category management, and offers robust functionalities for tax management. Developers can leverage this toolkit to create products, retrieve product lists, manage categories with advanced filtering, create new categories, handle taxes seamlessly, and more.

Key Features:

  1. Product Operations • Easily create new products with the provided payload • Retrieve a list of products with flexible filtering options
  2. Category Management • Streamline the process of creating new categories • Retrieve a list of categories with advanced filtering options
  3. Tax Management • Effortlessly create new taxes with specified details • Retrieve a list of taxes, update tax information, and delete taxes as needed

Package Installation

With npm:

npm install @spurtcommerce/product

Implementation logic:

1. productCreate()

This function creates a new product based on the provided payload. Parameters:payload: An object containing product creation information such as productName, productDescription, productSlug, sku, upc, hsn, quantity, categoryId, tax, price,Image • TypeORM connection to the database Returns a new product is created when a promise with a status, message, and optional data object.

Usage Example:

const { productCreate } = require('@spurtcommerce/product');
// ... initialize TypeORM connection

const payload = {
  // ... product creation payload
};

const result = await productCreate(payload, _connection);
console.log(result);

2. productList()

This function retrieves a list of products based on the provided criteria. Parameters:_connection: TypeORM connection to the database • select: An array of selected fields • limit: Number of items to retrieve • offset: Number of items to skip • keyword: Search keyword • sku: Product SKU • status: Product status (e.g., 'active', 'inactive') • price: Sorting option for the price (1 for ascending, 2 for descending) • count: Boolean indicating whether to retrieve the count only Returns a promise with a status, message, and data object containing the product list.

Usage Example:

const { productList } = require('@spurtcommerce/product');
// ... initialize TypeORM connection

const select = ['productName', 'productPrice', 'quantity', 'isActive'];
const limit = 10;
const offset = 0;
const keyword = 'search-keyword';
const sku = 'product-sku';
const status = 'active';
const price = 1; // 1 for ascending, 2 for descending
const count = false;

const result = await productList(_connection, select, limit, offset, keyword, sku, status, price, count);
console.log(result);

3. categoryCreate()

This function creates a new category based on the provided payload. Parameters:payload: An object containing category creation information such as name, containerName, containerPath, parentInt, sortOrder, categorySlug, categoryDescription, status • _connection: TypeORM connection to the database Returns a promise with a status, message, and optional data object.

Usage Examaple:

const { categoryCreate } = require('@spurtcommerce/product');
// ... initialize TypeORM connection

const payload = {
  name: 'New Category',
  containerName: 'category-image.jpg',
  containerPath: '/images/categories/',
  parentInt: 0, // Parent category ID, use 0 for top-level
  sortOrder: 1,
  categorySlug: 'new-category',
  categoryDescription: 'Description for the new category',
  status: 1, // 1 for active, 0 for inactive
};

const result = await categoryCreate(_connection, payload);
console.log(result);

4. categoryList()

This function retrieves a list of categories based on the provided criteria. Parameters:_connection: TypeORM connection to the database • limit: Number of items to retrieve • offset: Number of items to skip • keyword: Search keyword • status: Category status ('1' for active, '0' for inactive) • sortOrder: Sorting option for the list (1 for ascending, 2 for descending) Returns a promise with a status, message, and data object containing the category list.

Usage Example:

const { categoryList } = require('@spurtcommerce/product');
// ... initialize TypeORM connection

const limit = 10;
const offset = 0;
const keyword = 'search-keyword';
const status = '1'; // '1' for active, '0' for inactive
const sortOrder = 1; // 1 for ascending, 2 for descending

const result = await categoryList(_connection, limit, offset, keyword, status, sortOrder);
console.log(result);

5. taxCreate()

This function creates a new tax based on the provided payload. Parameters:payload: An object containing tax creation information such as taxName, taxPercentage, taxStatus • _connection: TypeORM connection to the database Returns a promise with a status, message, and optional data object.

Usage Example:

const { taxCreate } = require('@spurtcommerce/product');
// ... initialize TypeORM connection

const payload = {
  taxName: 'VAT',
  taxPercentage: 10,
  taxStatus: 1, // 1 for active, 0 for inactive
};
const result = await taxCreate(_connection, payload);
console.log(result);

6. taxList()

This function retrieves a list of Taxes on the provided criteria. Parameters:_connection: TypeORM connection to the database • limit: Number of items to retrieve • offset: Number of items to skip • keyword: Search keyword • status: Tax status ('1' for active, '0' for inactive) • count: If true, returns the count of taxes without the actual list Returns a promise with a status, message, and data object containing the tax list.

Usage Example:

const { taxList } = require('@spurtcommerce/product');
// ... initialize TypeORM connection

const limit = 10;
const offset = 0;
const keyword = 'search-keyword';
const status = '1'; // '1' for active, '0' for inactive
const count = false; // true if you want to get the count only

const result = await taxList(_connection, limit, offset, keyword, status, count);
console.log(result);

7. taxDelete()

This function deletes a tax based on the provided tax ID. Parameters:_connection: TypeORM connection to the database • taxId: ID of the tax to delete Returns a promise with a status and message.

Usage Example:

const { taxDelete } = require('@spurtcommerce/product');
// ... initialize TypeORM connection

const taxIdToDelete = 1; // replace with the actual tax ID

const result = await taxDelete(_connection, taxIdToDelete);
console.log(result);

8. taxUpdate()

This function upadates a tax based on the provided tax ID.

Parameters:payload: An object containing tax update information • _connection: TypeORM connection to the database Returns a promise with a status, message, and optional data object.

Usage Example:

const { taxUpdate } = require('@spurtcommerce/product');
// ... initialize TypeORM connection

const payload = {
  taxId: 1, // replace with the actual tax ID
  taxName: 'Updated VAT',
  taxPercentage: 12,
  taxStatus: 1, // 1 for active, 0 for inactive
};

const result = await taxUpdate(_connection, payload);
console.log(result);

Development

Fork/clone this repository and install dependencies normally:

git clone https://github.com/spurtcommerce/product
cd product
npm i

Then you can edit source files and test locally with npm start serve.

Notes:

Ensure that you have valid TypeORM connections and proper configuration. The actual usage of this function would depend on how it's integrated into your application and how routes and permissions are defined in your system.