malonlin-sdk
v0.1.1
Published
Framework-agnostic TypeScript SDK for the Malonlin storefront API
Readme
Malonlin SDK
The Malonlin SDK gives TypeScript and JavaScript applications a clear, framework-agnostic way to work with the Malonlin storefront API. It includes a cart and checkout client, typed request and event APIs, and the same named GraphQL operations used by the Malonlin web app.
The package is published on npm as malonlin-sdk.
Install
npm install malonlin-sdkA gentle start
import { CartSDK } from "malonlin-sdk";
const sdk = new CartSDK({
endpoint: "https://your-api.example/graphql",
apiKey: process.env.MALONLIN_API_KEY,
});
sdk.on("cart:synced", (cart) => {
console.log("Cart synced:", cart.items);
});
const cart = await sdk.getCart({ userId: "user-id", currencyCode: "ZAR" });CartSDK also exposes cart synchronization, item updates, coupon helpers, checkout readiness, and checkout. Domain clients cover sdk.auth, sdk.account, sdk.settings, sdk.stores, sdk.members, sdk.products, sdk.wanted, sdk.coupons, sdk.orders, sdk.analytics, sdk.scheduledOrders, sdk.serviceBookings, sdk.wallet, sdk.contacts, sdk.ratings, sdk.communications, sdk.subscriptions, sdk.apiSubscriptions, sdk.digitalPurchases, sdk.webhooks, and sdk.uploads.
const members = await sdk.members.listMembers(storeId, memberId);
const wallet = await sdk.wallet.getUserWallet(userId, "ZAR");
const products = await sdk.products.publicStoreProducts(storeId, "ZAR");
const requests = await sdk.wanted.list({
type: "SERVICE",
search: "Honda Civic",
});
const request = await sdk.wanted.create({
type: "SERVICE",
title: "Engine swap for a Honda Civic",
description: "Looking for an experienced local mechanic for an engine swap.",
location: "Cape Town",
budgetMax: 25000,
currencyCode: "ZAR",
});
const result = await sdk.communications.subscribeNewsletter(
"[email protected]",
);
const webhook = await sdk.webhooks.create({
storeId,
name: "Order notifications",
endpointUrl: "https://merchant.example/webhooks/malonlin",
eventTypes: ["payment.completed"],
});
// Save webhook.secret when returned; the backend only shows it once.Ready-to-use clients cover the website's common product, order, analytics, settings, store, scheduled-order, service-booking, wallet, and membership flows, including buyer receipt confirmation and seller digital-sales history. For any additional named GraphQL operation, call sdk.execute(...) or use sdk.request(...) with an exported query. See the SDK docs site for feature and security guides.
Website media uploads use the same-origin multipart route:
const uploaded = await sdk.uploads.upload(file, {
folder: "products",
fileName: file.name,
});See the feature-client reference for method coverage and the events/webhooks guide for all local SDK events, backend webhook types, and website-only React hooks.
Framework-agnostic API operations
Every named GraphQL operation from the web app is available from the package. This keeps additional web features accessible without a React, Redux, or browser-storage dependency:
import { CartSDK, USER_PROFILE_GET_USER_ORDERS } from "malonlin-sdk";
const sdk = new CartSDK({ endpoint: "https://your-api.example/graphql" });
const result = await sdk.request({
query: USER_PROFILE_GET_USER_ORDERS,
variables: { userId: "user-id", page: 1, limit: 20 },
});You can also import operations from malonlin-sdk/operations.
Security in one sentence
The SDK helps callers follow the right flow; the backend remains the authority for identity, ownership, prices, inventory, payment, and idempotency. Never put a private API key in a browser bundle.
