mercurjs/mercur

repository·main·Indexed 23 days ago

https://github.com/mercurjs/mercur

An open-source, headless marketplace platform built on top of Medusa. It provides primitives for multi-vendor commerce, including vendor onboarding, commissions, and automated payouts, to support the development of B2B or B2C marketplaces.

Tokens
361.3K
Snippets
867
Records
2.2K
Agent score
79%

What's inside mercur

  1. What is Medusa

    main
    Medusa is a collection of open-source commerce modules and tools designed to provide foundational commerce primitives. It allows developers to build advanced ecommerce stores, marketplaces, and other commerce-driven applications without having to implement core commerce logic from scratch. All modules are available via npm.
  2. What is the Split Order Payment Module?

    main

    The Split Order Payment Module is a standalone package in Mercur designed for multi-vendor marketplaces. It enables tracking of payment amounts (authorized, captured, refunded) separately for each seller's portion of a multi-vendor order.

    Key features include:

    • Payment Tracking per Seller: Separate tracking for each seller's portion of a single cart.
    • Payment Collection Association: Linking split payments to the main payment collection.
    • Automatic Status Updates: Syncing split payment status with the main payment.
    • Refund Management: Handling partial refunds specific to individual sellers.
    • Financial Reconciliation: Accurate records for commission and payout processing.
  3. What is Mercur

    main

    Mercur is an open-core marketplace platform built on top of the Medusa Framework. While Medusa provides the core commerce engine (products, pricing, carts, orders, fulfillment, and events), Mercur adds a marketplace domain layer including:

    • Marketplace Entities & Workflows: Sellers, onboarding, product requests, commissions, reviews, return escalations, order splitting, and vendor payouts.
    • Dedicated APIs: Separate APIs for Admin, Vendor, and Storefront.
    • Optional Interfaces:
      • Admin Panel: For marketplace operators.
      • Vendor Portal: For seller teams.
      • Storefront: For marketplace consumers.
  4. Overview of the Payout Module

    main

    The Payout Module is a standalone package in Mercur that provides out-of-the-box seller payout features. It is designed to handle the lifecycle of marketplace funds moving from the platform to sellers.

    Key Features:

    • Payout Account Management: Create and manage seller accounts integrated with providers like Stripe Connect.
    • Seller Onboarding: Manage the process for sellers to connect bank accounts.
    • Automated Payouts: Automatically process payouts based on completed orders.
    • Payout Reversals: Handle refunds and chargebacks.
    • Webhook Integration: Process asynchronous events from payment providers to update account statuses.
  5. Overview of the Vendor Panel features

    main

    The Vendor Panel is a platform for vendors to manage their online store operations. Key functional areas include:

    • Dashboard: Monitor store performance and key metrics.
    • Company Profile: Manage business and company details.
    • Orders Management: Track order status, fulfillment, and process order updates.
    • Product Management: Create listings, organize collections/categories, and manage pricing and descriptions.
    • Inventory Control: Track stock levels and manage inventory reservations.
    • Customer Management: View customer history, manage groups, and monitor reviews.
    • Promotions and Marketing: Create campaigns, special offers, discounts, and segment-specific price lists.
    • Messaging: A TalkJS-based system for communicating with customers and tracking conversation history.
  6. Compare Mercur vs Mirakl

    main

    Mercur is an open-source (MIT licensed) marketplace platform designed as an alternative to closed-source SaaS providers like Mirakl.

    Key differentiators include:

    • Ownership: Mercur provides full source code access and data ownership, whereas Mirakl is proprietary and vendor-controlled.
    • Pricing: Mercur has no GMV (Gross Merchandise Volume) fees or per-transaction cuts. Mirakl typically charges a percentage of GMV plus platform fees.
    • Hosting: Mercur can be self-hosted on any infrastructure (including on-prem or air-gapped networks) or used via fully managed services (Medusa Cloud or Rigby-hosted). Mirakl is vendor-hosted SaaS only.
    • Extensibility: Mercur is built on a composable architecture (TypeScript, Node.js, React, PostgreSQL) allowing for deep customization of workflows, APIs, and UI. Mirakl is limited to configuration within platform constraints.
    • Speed to Market: Mercur can be initialized in minutes using bun create mercur-app.
  7. Identify the correct Mercur API surface

    main

    Mercur exposes three distinct HTTP surfaces on the Medusa server. Choose the surface based on your target audience and required permissions:

    • Admin API (/admin/*): For marketplace operators. Requires Medusa admin authentication (session or bearer token).
    • Vendor API (/vendor/*): For sellers. Requires member authentication and is scoped to a specific seller via the x-seller-id header or a session-selected seller. This surface automatically filters all queries and mutations to the selected seller.
    • Store API (/store/*): For storefronts. Mostly public. Customer authentication is required for /store/order-groups and optional for routes like /store/offers, /store/products, and /store/search to enrich pricing context.

    All requests and responses use JSON. It is highly recommended to use the typed @mercurjs/client for all calls.

  8. Use the Marketplace Module for multi-vendor order management

    main

    The Marketplace Module provides out-of-the-box features for managing multi-vendor commerce. Key features include:

    • Order Set Management: Grouping multiple vendor orders from a single customer checkout into an OrderSet for unified tracking.
    • Multi-Vendor Order Tracking: Associating multiple orders with a single cart and payment collection.
    • Order Aggregation: Calculating aggregated totals, status, and fulfillment information across all orders in a set.
    • Unified Customer View: Providing customers with a single view of multi-vendor orders while maintaining individual records per seller.

    In Mercur, you interact with these features by building Workflows using pre-built workflows provided in the @mercurjs/b2c-core package.

  9. Project Structure of the Mercur Basic Template

    main

    The Mercur Basic Template is a monorepo managed by Turborepo. The core structure is as follows:

    • apps/admin/: Admin dashboard extensions.
    • apps/vendor/: Vendor portal extensions.
    • packages/api/: The core backend (based on Medusa) containing:
      • src/api/: Custom API routes.
      • src/jobs/: Background jobs.
      • src/links/: Module links.
      • src/modules/: Custom modules.
      • src/scripts/: CLI scripts.
      • src/subscribers/: Event subscribers.
      • src/workflows/: Business workflows.
      • medusa-config.ts: Backend configuration.
    • blocks.json: Configuration for Mercur blocks.
    • turbo.json: Turborepo configuration.
    ├── apps/
    │   ├── admin/          # Admin dashboard extensions
    │   └── vendor/         # Vendor portal extensions
    ├── packages/
    │   └── api/            # Medusa backend
    │       ├── src/
    │       │   ├── api/         # Custom API routes
    │       │   ├── jobs/        # Background jobs
    │       │   ├── links/       # Module links
    │       │   ├── modules/     # Custom modules
    │       │   ├── scripts/     # CLI scripts
    │       │   ├── subscribers/ # Event subscribers
    │       │   └── workflows/   # Business workflows
    │       └── medusa-config.ts
    ├── blocks.json         # Mercur blocks configuration
    ├── package.json
    └── turbo.json
  10. Understand Medusa commerce modules

    main
    Medusa is a collection of open-source commerce modules and tools designed to provide foundational commerce primitives. It allows developers to build advanced ecommerce stores, marketplaces, or other commerce-driven applications without having to reimplement core commerce logic. All modules are available via npm and can be customized to fit specific business needs.
  11. Use ICommissionModuleService for complex customizations

    main

    The ICommissionModuleService interface provides low-level access to the Commission Module's functionalities. It is intended for developers implementing complex customizations. For standard use cases, you should use the available built-in workflows instead.

    The interface is organized into several method groups:

    Commission Rule Methods

    Methods for managing rules: createCommissionRules, updateCommissionRules, deleteCommissionRules, retrieveCommissionRule, listCommissionRules, listAndCountCommissionRules, softDeleteCommissionRules, and restoreCommissionRules.

    Commission Rate Methods

    Methods for managing rates: createCommissionRates, updateCommissionRates, deleteCommissionRates, retrieveCommissionRate, listCommissionRates, listAndCountCommissionRates, softDeleteCommissionRates, and restoreCommissionRates.

    Commission Line Methods

    Methods for managing lines: createCommissionLines, updateCommissionLines, deleteCommissionLines, retrieveCommissionLine, listCommissionLines, listAndCountCommissionLines, softDeleteCommissionLines, and restoreCommissionLines.

    Custom Methods

    Includes specialized logic like selectCommissionForProductLine.

  12. Summary of Seller Module links

    main

    The Seller Module maintains several stored links to other Commerce Modules to associate sellers with their respective data models. These include:

    Second Data ModelTypeDescription
    ProductStored - one-to-manyAssociates a seller with their products
    OrderStored - one-to-manyAssociates a seller with their orders
    ReturnStored - one-to-manyAssociates a seller with order returns
    PayoutAccountStored - one-to-oneAssociates a seller with their payout account
    StockLocationStored - one-to-manyAssociates a seller with their stock locations
    FulfillmentSetStored - one-to-manyAssociates a seller with their fulfillment sets
    ServiceZoneStored - one-to-manyAssociates a seller with their service zones
    ShippingOptionStored - one-to-manyAssociates a seller with their shipping options
    ShippingProfileStored - one-to-manyAssociates a seller with their shipping profiles
    InventoryItemStored - one-to-manyAssociates a seller with their inventory items
    CustomerGroupStored - one-to-manyAssociates a seller with their customer groups
    PriceListStored - one-to-manyAssociates a seller with their price lists
    PromotionStored - one-to-manyAssociates a seller with their promotions
    CampaignStored - one-to-manyAssociates a seller with their campaigns