Skip to main content

Bookmarks Module

The bookmarks module allows users to save products for later reference, implementing wishlist functionality.

Configuration Options​

The bookmarks module has no configuration options.

Module API​

Access via modules.bookmarks in the Unchained API context.

Queries​

MethodArgumentsDescription
findBookmarkByIdbookmarkIdFind a specific bookmark
findBookmarksByUserIduserIdGet all bookmarks for a user
findBookmarksqueryFind bookmarks by custom filter

Mutations​

MethodArgumentsDescription
createdocCreate a new bookmark
updatebookmarkId, docUpdate bookmark
deletebookmarkIdDelete bookmark
deleteByUserIduserIdDelete all bookmarks for a user
deleteByProductIdproductIdDelete all bookmarks for a product
replaceUserIdfromUserId, toUserId, bookmarkIds?Migrate bookmarks between users (used during guest-to-registered conversion)

Usage​

// Create a bookmark
await modules.bookmarks.create({
userId: 'user-123',
productId: 'product-456',
});

// Get user's wishlist
const wishlist = await modules.bookmarks.findBookmarksByUserId('user-123');

// Migrate bookmarks when guest converts to registered user
await modules.bookmarks.replaceUserId('guest-id', 'registered-id');

Events​

EventPayloadDescription
BOOKMARK_CREATE{ bookmarkId }Emitted when a bookmark is created
BOOKMARK_UPDATE{ bookmarkId }Emitted when a bookmark is updated
BOOKMARK_REMOVE{ bookmarkId }Emitted when a bookmark is removed