multivendor-sale
v0.0.1
Published
Install-and-use platform sale plugin with TypeORM store, pricing hooks, and HTTP routes for multi-vendor marketplaces
Maintainers
Readme
multivendor-sale
Install-and-use platform sale plugin for multi-vendor marketplaces.
Features
- Admin CRUD for sale campaigns (
PERCENT/FIXED_AMOUNT/FIXED_PRICE) - Target ALL / CATEGORY / PRODUCT / BRAND
- Active-sale resolution with priority tie-breakers
- Optional Redis/cache adapter + in-memory TTL cache
- TypeORM entities + migrations
- routing-controllers HTTP (or express router)
Host integration
import { registerSalePlugin, getSaleOrmMetadata, SALE_PLUGIN_TOKEN } from 'multivendor-sale';
import { Container } from 'typedi';
import { getConnection } from 'typeorm';
const salePlugin = registerSalePlugin({
dataSource: getConnection(),
flags: { enabled: true },
http: { mode: 'routing-controllers' },
expandCategoryIds: async (categoryId) => {
// return [categoryId, ...descendantIds]
return [categoryId];
},
// optional: cache: { get, set, delPattern }
});
Container.set(SALE_PLUGIN_TOKEN, salePlugin);
// ORM
const saleOrm = getSaleOrmMetadata();
// entities: [...hostEntities, ...saleOrm.entities]
// migrations: [...hostMigrations, ...saleOrm.migrations]
// Controllers
// controllers: [...host, ...(salePlugin.http.controllers ?? [])]Pricing hook
const sale = await salePlugin.client.findActiveSaleForProduct({
productId,
categoryId,
brandId,
});
const platformPrice = applyPlatformSale(catalogBase, sale);Publish
pnpm run build && pnpm run test
# tag: sale-v0.0.1