โ๏ธ Alphabite Medusa SDK
The Alphabite Medusa SDK is a drop-in replacement for the official @medusajs/js-sdk
with built-in support for Alphabite plugins like Wishlists, Reviews, and PayPal.
This SDK simplifies client-side integration with your Medusa backend, and provides a unified interface for accessing plugin functionality alongside core Medusa features.
๐ง Why Use It?โ
- โ Plug-and-play Medusa SDK replacement
- ๐ Seamless plugin injection and namespaced usage
- ๐ Flexible auth handling with global or per-request headers
- ๐งฉ Tight TypeScript support across all plugins
- โ๏ธ Customizable and easy to extend
๐ฆ Installationโ
npm install @alphabite/medusa-sdk
๐ Basic Usageโ
import { AlphabiteMedusaSdk, wishlistPlugin, paypalPlugin, reviewsPlugin } from "@alphabite/medusa-sdk";
const sdk = new AlphabiteMedusaSdk(
{
baseUrl: "https://your-medusa-api.com/api",
publishableKey: "pk_...",
},
[wishlistPlugin, paypalPlugin, reviewsPlugin],
{
getAuthHeader: async () => {
const token = await getTokenFromStorage();
return { authorization: `Bearer ${token}` };
},
}
);
๐งฉ Plugin Architectureโ
All Alphabite plugins are injected via the second parameter when creating the SDK instance. They register under a namespaced sdk.alphabite
object. For example:
sdk.alphabite.wishlist.create({ name: "My Wishlist" });
sdk.alphabite.reviews.list({ product_id: "prod_123" });
๐ Auth Handlingโ
You can pass an optional getAuthHeader
function to automatically attach authorization headers to every request.
const sdk = new AlphabiteMedusaSdk({ baseUrl }, [wishlistPlugin], {
getAuthHeader: async () => {
const token = await getAccessToken();
return { authorization: `Bearer ${token}` };
},
});
You can also pass headers per request:
await sdk.alphabite.wishlist.create({ name: "Private Wishlist" }, { "x-request-id": "my-id" });
โ Example: Wishlist Flowโ
await sdk.alphabite.wishlist.create({ name: "My Gear" });
await sdk.alphabite.wishlist.addItem({
id: "wishlist_id",
product_id: "variant_id",
});
const { data: items } = await sdk.alphabite.wishlist.listItems({
id: "wishlist_id",
});
๐ Recommended Structureโ
Centralize your SDK instance:
// lib/sdk.ts
import { AlphabiteMedusaSdk, wishlistPlugin } from "@alphabite/medusa-sdk";
export const sdk = new AlphabiteMedusaSdk(
{ baseUrl: process.env.NEXT_PUBLIC_API_URL! },
[wishlistPlugin],
{
getAuthHeader: async () => {
const token = await getToken();
return { authorization: `Bearer ${token}` };
},
});
Then import sdk
anywhere in your app:
import { sdk } from "@/lib/sdk";
const { data: lists } = await sdk.alphabite.wishlist.list();
๐ Supported Pluginsโ
Plugin | Namespace | Description |
---|---|---|
Wishlist | sdk.alphabite.wishlist | Create and manage wishlists |
Reviews | sdk.alphabite.reviews | Customer product reviews |
PayPal | sdk.alphabite.paypal | Payment integration |
More plugins are coming soon.
๐งช TypeScript Supportโ
This SDK ships with full TypeScript types for all plugin methods and payloads. You get full autocomplete, request typing, and strict response validation out of the box.
๐ค Contributingโ
We're building this SDK to be extensible. If you want to create your own plugin or improve the SDK core, contributions are welcome.
๐ Licenseโ
MIT ยฉ Alphabite