|
1 | | -# ecommaps-storefront-kit |
2 | | -Framework-agnostic storefront business logic kit for Ecommaps. |
| 1 | +# @ecommaps/storefront-kit |
| 2 | + |
| 3 | +Framework-agnostic commerce logic primitives for Ecommaps storefront applications. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## 1. Positioning |
| 8 | + |
| 9 | +Use this package for reusable business logic that should not depend on: |
| 10 | +- Next.js |
| 11 | +- React |
| 12 | +- AI SDK |
| 13 | + |
| 14 | +This package is intended for server actions, API routes, workers, and backend services. |
| 15 | + |
| 16 | +## 2. Installation |
| 17 | + |
| 18 | +```bash |
| 19 | +pnpm add @ecommaps/storefront-kit |
| 20 | +``` |
| 21 | + |
| 22 | +## 3. Public API |
| 23 | + |
| 24 | +### Variant resolution |
| 25 | + |
| 26 | +- `resolveVariantSelection(product, input)` |
| 27 | +- `variantMatchesColorAndSize(product, variant, color, size)` |
| 28 | + |
| 29 | +Behavior: |
| 30 | +- supports multilingual color/size synonyms |
| 31 | +- enforces exact size semantics (prevents wrong size fallback) |
| 32 | +- returns `requires_selection` when match is ambiguous |
| 33 | + |
| 34 | +### Normalizers |
| 35 | + |
| 36 | +- `normalizeProductCard(product)` |
| 37 | +- `normalizeCartSummary(cart)` |
| 38 | + |
| 39 | +### Promotions |
| 40 | + |
| 41 | +- `classifyPromotionStatus(promotion, context)` |
| 42 | +- `promotionStatusLabel(status)` |
| 43 | + |
| 44 | +## 4. Usage example |
| 45 | + |
| 46 | +```ts |
| 47 | +import { |
| 48 | + resolveVariantSelection, |
| 49 | + normalizeProductCard, |
| 50 | + normalizeCartSummary, |
| 51 | + classifyPromotionStatus, |
| 52 | +} from "@ecommaps/storefront-kit"; |
| 53 | + |
| 54 | +const selection = resolveVariantSelection(product, { |
| 55 | + variant_id: undefined, |
| 56 | + color: "red", |
| 57 | + size: "L", |
| 58 | +}); |
| 59 | + |
| 60 | +const card = normalizeProductCard(product); |
| 61 | +const cart = normalizeCartSummary(rawCart); |
| 62 | + |
| 63 | +const promoState = classifyPromotionStatus( |
| 64 | + { code: "DISCOUNT20", min_order_amount: 5000 }, |
| 65 | + { enteredCode: "DISCOUNT20", cartTotal: 7000, explicitValidationPassed: true }, |
| 66 | +); |
| 67 | +``` |
| 68 | + |
| 69 | +## 5. Compatibility |
| 70 | + |
| 71 | +- Runtime: Node.js 20+ |
| 72 | +- No UI framework dependency |
| 73 | +- Semver-stable function contracts |
0 commit comments