SDKs
Server (TypeScript)
A typed client for the native API, for your backend.
The typed TypeScript client is generated from the same openapi.json as the API reference. Every route is typed, errors are typed classes, and a function can supply the token so a rotating token needs no new client.
Create a client#
import { createKentonganClient } from "@kentongan/sdk";
const sapagan = createKentonganClient({
baseUrl: process.env.SAPAGAN_URL!,
token: process.env.SAPAGAN_KEY!, // or () => string | Promise<string>
});baseUrl is the API origin. Routes are /v1/... below it. token is a server key, a store key, or a function that returns one (for a store token that rotates). Other options: fetch, headers, and workspace for console sessions.
Helpers#
| Helper | Route |
|---|---|
sapagan.customers | GET /v1/customers/{id} and its relationships |
sapagan.scopes | GET /v1/scopes/{id} |
sapagan.scope | The store-facing routes: policy, usage, block and appeals, plan, ledger, health, flows, reports, products |
sapagan.templates | Push templates: list, create, update, preview |
sapagan.broadcasts | List, read, create, update, submit, schedule, cancel, stats |
Any route#
sapagan.http is a typed openapi-fetch client over the whole generated contract, including routes without a helper:
const { data, error } = await sapagan.http.POST("/v1/batch", {
body: {
items: [{ type: "profile", id: "user-42", attributes: { name: "Budi Santoso" } }],
},
});Errors#
A non-2xx answer becomes a typed error with status, code, details and the requestId to quote to support.
| Class | Status |
|---|---|
InvalidRequestError | 400 |
UnauthorizedError | 401 |
ForbiddenError | 403 |
NotFoundError | 404 |
ConflictError | 409 |
UnprocessableError | 422 |
RateLimitedError | 429 |
ServerError | 5xx |
All extend ApiError.
import { NotFoundError } from "@kentongan/sdk";
try {
await sapagan.customers.get("user-42");
} catch (e) {
if (e instanceof NotFoundError) {
// the key cannot see this person
} else throw e;
}See Errors and limits for the codes.