SDK

TypeScript SDK

@malla/business is the official SDK for Node.js and every runtime with fetch: Bun, Deno, Cloudflare Workers, Vercel and Next.js. Fully typed, zero dependencies, with retries, timeouts and auto-pagination built in.

Install

npm install @malla/business

Requires Node.js 20 or newer. Ships ESM and CommonJS.

Configure

import { Malla } from '@malla/business'

const malla = new Malla({
apiKey: process.env.MALLA_API_KEY, // default: MALLA_API_KEY
timeout: 30_000, // ms per request
maxRetries: 2, // for 429s, and 5xx/network errors on GET, PUT and DELETE
})
Option Default
apiKey process.env.MALLA_API_KEY Your mk_live_... key.
baseUrl process.env.MALLA_BASE_URL or https://api.malla.business The API root.
timeout 30000 Milliseconds before a request is aborted.
maxRetries 2 Automatic retries.
fetch global fetch Bring your own fetch.
headers {} Extra headers on every request.

Making requests

Resources mirror the API. Methods take the path ids first, then the body or query, then per-call options.

const product = await malla.products.create({ title: 'Café de altura 1 lb', slug: 'cafe-altura-1lb', status: 'active' })

await malla.products.updateVariant(product.id, product.variants[0].id, { priceCents: 1250, inventoryQuantity: 40 })

const order = await malla.orders.retrieve(orderId)
await malla.orders.fulfill(order.id)

// Per-call options
await malla.customers.list({ q: 'ana' }, { timeout: 5_000, signal: controller.signal })
Client Methods
malla.products list iterate retrieve create update delete setOptions updateVariant deleteVariant inventory
malla.orders list iterate retrieve create quote cancel fulfill
malla.paymentLinks create list
malla.customers list iterate retrieve create update tags
malla.collections list iterate retrieve create update delete addProduct removeProduct
malla.categories list iterate retrieve create update delete assignProduct removeProduct
malla.discounts list iterate retrieve create update delete getBirthdaySettings updateBirthdaySettings
malla.conversations list iterate retrieve update listMessages sendMessage
malla.payouts list iterate balance
malla.webhookEndpoints list create retrieve update delete revealSecret rollSecret sendTestEvent listDeliveries retrieveDelivery resendDelivery
malla.business summary analytics

Anything not wrapped yet is one call away, with the same auth, retries and errors:

const result = await malla.request('GET', '/products/inventory', { query: { stock: 'low' } })

Pagination

list() returns one page; iterate() walks them all lazily. See Pagination.

const { data, nextCursor } = await malla.products.list({ limit: 50 })

for await (const customer of malla.customers.iterate({ tag: 'vip' }))
await sendGift(customer)

Errors

Every failure is a MallaError with status, code (the API's error) and details:

Class Status Typical codes
MallaAuthenticationError 401 invalid_api_key
MallaPermissionError 403 insufficient_scope (see .required), forbidden_for_api_keys, plan_required
MallaNotFoundError 404 not_found
MallaConflictError 409 order_not_pending, out_of_stock, phone_taken…
MallaValidationError 400, 422 validation_error (see details.issues), invalid_items…
MallaRateLimitError 429 rate_limited
MallaConnectionError — timeout, connection_error
import { MallaNotFoundError } from '@malla/business'

const order = await malla.orders.retrieve(id).catch((error) => {
if (error instanceof MallaNotFoundError)
return null
throw error
})

Retries

  • 429 is retried for every method: it's rejected before anything runs.
  • 5xx and network errors are retried only for GET, PUT and DELETE, so a POST /orders is never placed twice.
  • Backoff is exponential with jitter (from 0.5 s, up to 8 s), or Retry-After when the API sends it.

Webhooks

Verify deliveries and get typed events. Import from @malla/business/webhooks to leave the API client out of your bundle.

import { constructWebhookEvent } from '@malla/business/webhooks'

const event = await constructWebhookEvent(rawBody, request.headers.get('Malla-Signature'), process.env.MALLA_WEBHOOK_SECRET!)

switch (event.type) {
case 'order.paid':
event.data.object.total_cents // typed: OrderObject
break
case 'message.received':
event.data.object.content // typed: MessageObject
break
}

Full guide with Express, Next.js and Hono examples: Verify signatures.

TypeScript

Every request and response type is exported: Order, OrderCreateParams, Product, Customer, Page<T>, WebhookEvent, OrderObject…

import type { Order, Page, WebhookEventOf } from '@malla/business'

function onPaid(event: WebhookEventOf<'order.paid'>) { /* … */ }

REST responses use camelCase (totalCents); webhook payloads use snake_case (total_cents). The types follow each.