TypeScript SDK
The primary, hand-owned @magiios/sdk client for Node.
@magiios/sdk is Sello's primary SDK. Its models are generated from the OpenAPI
contract, but its runtime — auth, retries, the async waiter, typed errors,
webhook verification — is hand-owned, so the ergonomics are first-class. See
Install the SDK for registry setup.
Construct a client
import { SelloClient } from '@magiios/sdk';
const sello = new SelloClient({
apiKey: process.env.SELLO_API_KEY, // → Authorization: Bearer <key>
baseUrl: 'https://api.sello.cr',
apiVersion: '2026-06-15', // pinned, sent on every request
});SelloClientOptions also covers token (an alias for apiKey) and retry
tuning.
Issue and wait
import { isAcceptedIndEstado } from '@magiios/sdk';
const status = await sello.documents.createAndWait(
{ tipo: 'FE', /* … */ } as any,
// The Idempotency-Key is required: derive it from the order, not the content.
{ idempotencyKey: `order-${order.id}:FE`, intervalMs: 2000, timeoutMs: 120_000 },
);
// The generated model exposes the hyphenated wire field `ind-estado` as `indEstado`.
if (isAcceptedIndEstado(status.indEstado)) {
// aceptado
}Terminal-vs-pending is defined once (isTerminalIndEstado / isAcceptedIndEstado).
See Async issuance.
What the runtime layer gives you
- Auth — the key is attached as a bearer token on every request.
- Retries — exponential backoff on retryable
5xx/429, honoringRetry-After, before any error surfaces. - The waiter —
createAndWait/waitForStatus, poll-until-terminal with an injectable clock and an abortsignal. - Typed errors — every non-2xx throws a
SelloApiErrorwith the parsed RFC 9457 problem and.errorsfield list. See Error handling. - Webhook verification —
verifyWebhookdoes the constant-time HMAC compare and replay check. See Webhooks. - Idempotency —
documents.createandcreateAndWaitrequire yourIdempotency-Keyand refuse a call without one before sending anything. Derive it from the business event so your own retries dedupe too; transport retries replay it. See Idempotency. - Pagination — a generic cursor async-iterator (
paginate/collect) over{ data, nextCursor }list responses.
Errors
import { SelloApiError } from '@magiios/sdk';
try {
await sello.documents.create(invalidInvoice, `order-${order.id}:FE`);
} catch (err) {
if (err instanceof SelloApiError) {
console.error(err.status, err.problem.title);
for (const e of err.errors) console.error(`${e.path}: ${e.message}`);
}
}The generated model layer is a reproducible, non-committed artifact; the
committed value is the hand-owned ts-runtime/ layer plus the OpenAPI spec.
Publishing is tag-driven (push an sdk-v* tag) per ADR 0002.
Read an emisor's credential status
Reports whether the emisor has a complete credential set stored (the certificate, its PIN, the Hacienda user and password, the emisor's Hacienda endpoints and client id, and the certificate's expiry) and how close the certificate is to expiring. This reports what is stored, not whether Hacienda accepts the login now: the read decrypts nothing and calls no Hacienda service. `status` is `none` when any of those values is missing; otherwise `expired` when the certificate's expiry is at or before now; otherwise `expiring` when it is within 30 days of now; otherwise `valid`. `certificateExpiresAt` is the stored expiry whenever one is stored, `none` included, and null otherwise. Only a company key (`ApiKeyAuth`) pinned to this emisor and holding `credentials:read` may read. An account-wide key or a key pinned to another emisor answers `403` `https://sello.cr/problems/emisor-out-of-scope`, and a `test` key on a production emisor answers `403` `Wrong key environment`. A suspended or closed account may still read. A platform credential and an upload grant token are refused with `401`.
Other languages
Kiota-generated SDKs for Python, Go, Java, C#, and PHP.