Promo codes for 86d with percentage, fixed-amount, and free-shipping types, product and category scoping, usage limits, and date ranges.
Experimental. This Module has no test or production evidence recorded yet. Read it, run it locally, and hold off on real Orders. See maturity levels.
The Discounts Module creates, validates, and applies promo codes. It has no Module dependencies and no init-time options. You manage discount rules and codes at runtime through the admin endpoints or the controller API. The Checkout Module picks up discounts through structural typing, so promo codes entered in CheckoutSummary flow through without extra wiring.Source:modules/discounts · npm:@86d-store/discounts
Installation
npm install @86d-store/discounts
Configuration
The Discounts Module takes no configuration options. Initialize it with no arguments:
import discounts from "@86d-store/discounts";import { createModuleClient } from "@86d-store/core";const client = createModuleClient([discounts()]);
Discount types
type
value field
Calculation
percentage
0 to 100
subtotal * value / 100
fixed_amount
cents
min(value, subtotal). Never exceeds cart total.
free_shipping
0
Sets freeShipping: true in the result; no amount deducted
Store endpoints
POST /discounts/validate
This endpoint checks a promo code and calculates the discount amount without applying it or incrementing any usage counters. That makes it safe to call on every cart update or preview.Request body:
{ code: string; subtotal: number; // cart subtotal in cents productIds?: string[]; // for product-scoped discounts categoryIds?: string[]; // for category-scoped discounts}
Response:
{ valid: boolean; discountAmount: number; // in cents; 0 for free_shipping type freeShipping: boolean; error?: string; // present when valid is false}
Admin endpoints
Method
Path
Description
GET
/admin/discounts
List all discounts (paginated)
POST
/admin/discounts/create
Create a new discount rule
GET
/admin/discounts/:id
Get a discount with all its codes
PUT
/admin/discounts/:id/update
Update a discount rule
DELETE
/admin/discounts/:id/delete
Delete a discount and all its codes
POST
/admin/discounts/:id/codes
Add a promo code to a discount
DELETE
/admin/discounts/codes/:id/delete
Delete a single promo code
Deleting a discount cascades: all promo codes attached to that discount are removed first, then the discount record is deleted.
Components
DiscountCodeInput
DiscountCodeInput is a promo code entry field with live validation. When a valid code is entered it shows an applied state with the discount amount, and the Shopper can remove the code.
Case-insensitive codes. Promo codes are stored and matched as uppercase. SAVE10, save10, and Save10 all resolve to the same code.validateCode vs. applyCode. Use validateCode for previews and cart-page feedback; it never mutates state. Call applyCode exactly once per order at confirmation time; it increments both the code’s usedCount and the parent discount’s usedCount.Checkout integration. The Checkout Module accesses DiscountController through the runtime context via structural typing; no direct import is needed. The CheckoutSummary component handles the promo code form automatically, so you do not need to wire up DiscountCodeInput separately on the Checkout page.