Wishlist
Let customers save and share wishlist items
Medusa Wishlist
A wishlist plugin for Medusa v2 that allows customers to save products for later and share their wishlists with others.
Features
- ποΈ Customer Wishlists - Each customer gets their own wishlist, automatically created when they add their first item
- β Add/Update Items - Customers can add products to their wishlist and update quantities
- ποΈ Remove Items - Easy removal of items from the wishlist
- π Share Wishlists - Generate shareable links using JWT tokens
- π Public Access - Shared wishlists can be viewed without authentication
- π Secure - JWT-based token system for sharing
Installation
Option 1: Install as NPM Package
- Install the plugin:
123npm install @rsc-labs/medusa-wishlist# oryarn add @rsc-labs/medusa-wishlist
- Add the plugin to your Copy to clipboard
medusa-config.js
:
123456789const plugins = [// ... other plugins{resolve: "@rsc-labs/medusa-wishlist",options: {jwtSecret: process.env.JWT_SECRET || "supersecret"}}]
Or simply:
1234const plugins = [// ... other plugins"@rsc-labs/medusa-wishlist"]
- Run database migrations:
1npx medusa db:migrate
Option 2: Copy Source Code
You can also copy the source code directly into your Medusa project:
- Copy the Copy to clipboard
/src
directory contents into your project - Add the module to your Copy to clipboard
medusa-config.js
:
123456789const modules = [// ... other modules{resolve: "./src/modules/wishlist",options: {jwtSecret: process.env.JWT_SECRET || "supersecret"}}]
- Install required dependencies:
123npm install jsonwebtoken# oryarn add jsonwebtoken
- Run database migrations:
1npx medusa db:migrate
Configuration
JWT Secret
The wishlist sharing feature uses JWT tokens. It's recommended to set a strong secret in your environment variables:
12# .envJWT_SECRET=your-super-secret-key-here
Then configure it in Copy to clipboardmedusa-config.js
:
123456{resolve: "@rsc-labs/medusa-wishlist",options: {jwtSecret: process.env.JWT_SECRET}}
API Endpoints
Authenticated Endpoints (Require Customer Token)
Get Customer's Wishlist
12GET /store/customers/me/wishlistAuthorization: Bearer {customer-token}
Add or Update Item
123456789POST /store/customers/me/wishlist/itemsAuthorization: Bearer {customer-token}Content-Type: application/json{"productId": "prod_01XXXXX","productVariantId": "variant_01XXXXX","quantity": 1}
Remove Item
12DELETE /store/customers/me/wishlist/items?productId={productId}&productVariantId={productVariantId}Authorization: Bearer {customer-token}
Generate Share Token
1234567POST /store/customers/me/wishlist/share-tokenAuthorization: Bearer {customer-token}Response:{"shared_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."}
Public Endpoints (No Authentication Required)
View Shared Wishlist
1GET /store/wishlists?token={shared-token}
Usage Example
1. Customer Login
123456curl -X POST http://localhost:9000/store/auth/customer/emailpass \-H "Content-Type: application/json" \-d '{"email": "customer@example.com","password": "password123"}'
2. Add Item to Wishlist
12345678curl -X POST http://localhost:9000/store/customers/me/wishlist/items \-H "Authorization: Bearer {token}" \-H "Content-Type: application/json" \-d '{"productId": "prod_01XXXXX","productVariantId": "variant_01XXXXX","quantity": 1}'
3. Get Wishlist
12curl -X GET http://localhost:9000/store/customers/me/wishlist \-H "Authorization: Bearer {token}"
4. Generate Share Token
12curl -X POST http://localhost:9000/store/customers/me/wishlist/share-token \-H "Authorization: Bearer {token}"
5. View Shared Wishlist (Public)
1curl -X GET "http://localhost:9000/store/wishlists?token={shared-token}"
Database Schema
The plugin creates the following tables:
Copy to clipboardwishlist
- Copy to clipboard
id
- Primary key - Copy to clipboard
created_at
- Timestamp - Copy to clipboard
updated_at
- Timestamp
Copy to clipboardwishlist_item
- Copy to clipboard
id
- Primary key - Copy to clipboard
wishlist_id
- Foreign key to wishlist - Copy to clipboard
product_id
- Product identifier - Copy to clipboard
product_variant_id
- Product variant identifier - Copy to clipboard
quantity
- Item quantity - Copy to clipboard
created_at
- Timestamp - Copy to clipboard
updated_at
- Timestamp
Copy to clipboardlink_customer_wishlist
- Links customers to their wishlists (1:1 relationship)
How It Works
- Automatic Creation: When a customer adds their first item, a wishlist is automatically created and linked to their account
- Item Management: Customers can add, update quantities, or remove items from their wishlist
- Sharing: Customers can generate a JWT token to share their wishlist with others
- Public Access: Anyone with the share token can view the wishlist without authentication
API Documentation
For detailed API specifications, see the OpenAPI documentation.
Development
Prerequisites
- Node.js 20+
- Medusa v2
- PostgreSQL
Local Setup
12345678# Install dependenciesnpm install# Run migrationsnpx medusa db:migrate# Start development servernpm run dev
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details.
Credits
Created by RSC Labs
Support
For issues and questions:
- GitHub Issues: medusa-wishlist/issues
- Documentation: docs.medusajs.com
Built for Medusa v2 π