JavaScript SDK
Built-in Modules
Posts, pages, media, products, cart, orders, payment, wallets, SSE events, and health check.
The SDK provides dedicated modules for built-in features. Access them directly on the client instance.
Posts
client.posts.list(query?)
client.posts.get(slug)
client.posts.create(body)
client.posts.update(slug, body)
client.posts.delete(slug)// List published posts
const result = await client.posts.list({
page: 1,
page_size: 20,
status: "published",
category_id: "cat_id",
tag_id: "tag_id",
});
// Get by slug
const post = await client.posts.get("hello-world");
// Create
const post = await client.posts.create({
title: "Hello World",
content: "<p>First post</p>",
excerpt: "My first post",
status: "draft",
category_id: "cat_id",
tag_ids: ["tag1", "tag2"],
});Pages
client.pages.list(page?, pageSize?)
client.pages.get(slug)
client.pages.sitemap()const pages = await client.pages.list(1, 20);
const page = await client.pages.get("about");
const sitemap = await client.pages.sitemap();Comments
client.comments.list(postSlug, page?, pageSize?)
client.comments.create(postSlug, body)
client.comments.listAll(page?, pageSize?)
client.comments.updateStatus(id, status)
client.comments.delete(id)// Comments for a specific post
const comments = await client.comments.list("hello-world", 1, 20);
// Add a comment
await client.comments.create("hello-world", {
content: "Great post!",
nickname: "Visitor",
email: "visitor@example.com",
parent_id: null,
});Categories
client.categories.list(page?, pageSize?)
client.categories.get(id)
client.categories.create(body)
client.categories.update(id, body)
client.categories.delete(id)Tags
client.tags.list(page?, pageSize?)
client.tags.get(id)
client.tags.create(body)
client.tags.update(id, body)
client.tags.delete(id)Media
client.media.upload(file, options?)
client.media.list(page?, pageSize?)
client.media.stats()
client.media.delete(id)
client.media.getFileURL(record, field, options?)// Upload a file
const fileInput = document.querySelector<HTMLInputElement>("#file")!;
const media = await client.media.upload(fileInput.files![0]);
// Get file URL
const url = client.media.getFileURL(record, "cover");
// With thumbnail
const thumbUrl = client.media.getFileURL(record, "cover", {
thumb: "300x200",
});
// Storage stats
const stats = await client.media.stats();
// { total_files: 42, total_size: 10485760 }Products
client.products.list(page?, pageSize?)
client.products.get(id)const products = await client.products.list(1, 20);
const product = await client.products.get("product_id");Cart
client.cart.list()
client.cart.add(body)
client.cart.updateItem(id, body)
client.cart.removeItem(id)
client.cart.clear()
client.cart.checkout()// View cart
const cart = await client.cart.list();
// Add to cart
await client.cart.add({
product_id: "product_id",
quantity: 2,
});
// Update quantity
await client.cart.updateItem("item_id", { quantity: 3 });
// Remove item
await client.cart.removeItem("item_id");
// Checkout (creates an order)
const result = await client.cart.checkout();Orders
client.orders.list(page?, pageSize?)
client.orders.get(id)
client.orders.create(body)
client.orders.cancel(id)
client.orders.confirmReceipt(id)// Create order directly
const order = await client.orders.create({
items: [
{ product_id: "product_id", quantity: 1 },
],
currency: "USD",
buyer_name: "Alice",
buyer_email: "alice@example.com",
shipping_address: "123 Main St",
remark: "Please gift-wrap",
});
// List my orders
const orders = await client.orders.list(1, 20);
// Cancel
await client.orders.cancel("order_id");
// Confirm receipt
await client.orders.confirmReceipt("order_id");Payment
client.payment.listAvailableChannels(query)
client.payment.createOrder(body)
client.payment.getOrder(id)
client.payment.cancelOrder(id)
client.payment.listTransactions(id)
client.payment.listRefunds(id)
client.payment.listOrders(page?, pageSize?)// Get available payment channels
const channels = await client.payment.listAvailableChannels({
order_id: "order_id",
country: "US",
});
// Create payment order
const paymentOrder = await client.payment.createOrder({
order_id: "order_id",
channel: "stripe",
});Wallets
client.wallets.list()
client.wallets.get(currency)
client.wallets.listTransactions(currency, query?)
client.wallets.listAllTransactions(query?)// My wallets
const wallets = await client.wallets.list();
// Transactions for a currency
const txs = await client.wallets.listTransactions("USD", {
page: 1,
page_size: 20,
});Events (SSE)
Real-time server-sent events:
const es = client.events.subscribe();
// Listen for specific events
es.addEventListener("post.created", (event) => {
console.log("New post:", JSON.parse(event.data));
});
es.addEventListener("order.paid", (event) => {
console.log("Order paid:", JSON.parse(event.data));
});
// Filter events
const es = client.events.subscribe("order.*");
// Cleanup
es.close();Returns a native browser EventSource. No WebSocket support — real-time is SSE only.
Health Check
client.health.check()
client.health.liveness()
client.health.readiness()const status = await client.health.check();
// { status: "ok", version: "0.1.0" }