FOMDocs

TypeScript SDK

Retry၊ စာမျက်နှာ ဖတ်ခြင်းနဲ့ webhook စစ်ခြင်း ပါဝင်ပြီး Node.js၊ Bun၊ Deno နဲ့ edge runtime တွေအတွက် type ပါ client။

SDK က request နဲ့ response တိုင်းကို type နဲ့ API ကို ထုပ်ပိုးပေးပါတယ်။ Dependency မရှိဘဲ Node.js 20 ဒါမှမဟုတ် နောက်ပိုင်း (သို့ Bun၊ Deno ဒါမှမဟုတ် edge runtime) လိုပါတယ်။

npm install @getfom/sdk

Key ကို server ပေါ်မှာပဲ ထားပါ။ Browser ဒါမှမဟုတ် app ထဲက key နဲ့ SDK ကို ဘယ်တော့မှ မသုံးပါနဲ့။

Request ပို့ခြင်း

import { FomClient } from "@getfom/sdk"

const fom = new FomClient({ apiKey: process.env.FOM_API_KEY! })

const { shop, api_key } = await fom.shop.get()
console.log(`${shop.name}, as ${api_key.acts_for}`)

const order = await fom.orders.create({
  customer: { name: "Ko Ko", phone: "09123456789" },
  items: [{ variant_id: "var_123", qty: 2 }],
})

await fom.orders.changeStatus(order.id, {
  status: "confirmed",
  expected_revision: order.revision,
})

await fom.products.adjustStock("var_123", { delta: -2, reason: "manual_adjust" })
အပိုင်းMethod များ
Shopshop.get()
Ordersorders.list, listAll, get, create, changeStatus
Customerscustomers.list, listAll, get, create, update
Productsproducts.list, listAll, get, create, update, adjustStock
Deliveriesdeliveries.list, listAll, get, update

စာရင်းနဲ့ sync

list() က data၊ nextCursor နဲ့ hasMore ပါတဲ့ စာမျက်နှာ တစ်ခု ပြန်ပေးပါတယ်။ listAll() က စာမျက်နှာတိုင်းကို သင့်အတွက် ဖတ်ပေးပါတယ် -

let since = await loadCheckpoint() // e.g. "2026-11-01T00:00:00.000Z"
for await (const product of fom.products.listAll({ updated_since: since })) {
  await save(product)
  since = product.updated_at
}
await saveCheckpoint(since)

ပြန်ကြိုးစားခြင်းနဲ့ error များ

SDK က 429၊ 5xx အဖြေနဲ့ ကွန်ရက် ပြတ်တာတွေကို နှစ်ကြိမ် ပြန်ကြိုးစားပြီး FOM က Retry-After ပို့ရင် အဲဒီအတိုင်း စောင့်ပါတယ်။ ပြင်ဆင်မှုတိုင်းမှာ ပြန်ကြိုးစားတိုင်း မပြောင်းတဲ့ Idempotency-Key ပါပါတယ်။ ကိုယ်ပိုင် key ကို { idempotencyKey: "sale-42" } နဲ့ ပေးနိုင်ပါတယ်။

Error တွေက စစ်လို့ရတဲ့ class တွေပါ -

import { FomConflictError, FomValidationError } from "@getfom/sdk"

try {
  await fom.orders.changeStatus(order.id, { status: "delivered", expected_revision: 3 })
} catch (error) {
  if (error instanceof FomConflictError) {
    // Someone changed the order; read it again.
  } else if (error instanceof FomValidationError) {
    console.log(error.details)
  } else {
    throw error
  }
}
ClassStatus
FomAuthenticationError401
FomPermissionError403
FomNotFoundError404
FomConflictError409
FomValidationError422
FomRateLimitError429
FomConnectionErrorအဖြေ မရ - ကွန်ရက် ပြတ်တာ ဒါမှမဟုတ် အချိန်ကုန်တာ

အားလုံးမှာ status၊ code၊ message နဲ့ requestId ပါပါတယ်။

Webhook များ

constructWebhookEvent က FOM-Signature header ကို စစ်ပြီး type ပါ event ကို ပြန်ပေးပါတယ်၊ မကိုက်ရင် error ပစ်ပါတယ် -

import express from "express"
import { constructWebhookEvent } from "@getfom/sdk"

app.post("/fom-webhooks", express.raw({ type: "application/json" }), async (req, res) => {
  let event
  try {
    event = await constructWebhookEvent(req.body, req.get("FOM-Signature"), process.env.FOM_WEBHOOK_SECRET!)
  } catch {
    return res.sendStatus(400)
  }
  if (event.type === "order.created") {
    console.log("New order", event.data.order.order_no)
  }
  res.sendStatus(200)
})

Option များ

new FomClient({
  apiKey: "fom_live_…",
  maxRetries: 2, // retries for 429, 5xx and network failures
  timeoutMs: 30_000, // per try
  maxRetryDelayMs: 60_000, // a longer Retry-After throws instead of waiting
  fetch: myFetch, // e.g. through a proxy
})

ဤစာမျက်နှာတွင်