Skip to Content
SelloDeveloper docs
SDKs

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, honoring Retry-After, before any error surfaces.
  • The waiter — createAndWait / waitForStatus, poll-until-terminal with an injectable clock and an abort signal.
  • Typed errors — every non-2xx throws a SelloApiError with the parsed RFC 9457 problem and .errors field list. See Error handling.
  • Webhook verification — verifyWebhook does the constant-time HMAC compare and replay check. See Webhooks.
  • Idempotency — documents.create and createAndWait require your Idempotency-Key and 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.

On this page