@cufea/sdk is a thin TypeScript client for the Cufea API: typed requests and answers,
automatic idempotency keys, typed errors, timeouts, safe retries and webhook signature
verification. ESM, zero runtime dependencies, global fetch and Web Crypto: Node 20+,
browsers and edge runtimes. Its types are generated from the same OpenAPI document as the
API reference, so they follow the server.
The package is not published to npm yet. Until it is, call the API directly as in the
quickstart.
Quickstart
The same flow as the quickstart, against the sandbox:method_code takes a code of the DIAN list MediosPago-2.1; any other code is a 422 (see
Payments). The SDK exports the list, generated from the contract, as
PAYMENT_MEANS_CODES (type PaymentMeansCode), e.g. to validate input or fill a picker.
Resources
Every method takes a last
options argument with signal (an AbortSignal) and timeoutMs;
the routes that honour Idempotency-Key also take idempotencyKey. Request and answer types
are exported by schema name (InvoiceCreate, InvoiceRecord, WebhookEvent…).
Tenant setup for the test and production stages (issuer, numbering ranges, certificates, API
keys) is not wrapped yet: the sandbox needs none of it.
Idempotency
invoices.create, invoices.send, notes.create, notes.send, events.create and
webhookEndpoints.create always send an Idempotency-Key: a random UUID per call unless you
pass idempotencyKey. Pass your own (an order id, say) to make a retry from your side safe
too. See Idempotency.
Errors
Every error answer becomes aCufeaError with the fields of its problem document (see
Errors):
problem+json (a proxy’s HTML page, say) still gives a CufeaError,
with code: "http_error". No HTTP answer at all is a CufeaConnectionError, and no answer
within timeoutMs is a CufeaTimeoutError.
Timeouts and retries
timeoutMs bounds each attempt. A network error, a timeout, a 429 or a 5xx is retried up
to maxRetries times with exponential backoff and jitter (honouring a Retry-After of up to
30 s), but only when retrying cannot apply a request twice: GET, PUT and DELETE, and the
POSTs that carry an Idempotency-Key. Any other 4xx is never retried.
Webhooks
verify follows the server’s rules exactly (see Webhooks): it refuses a t
more than 300 s from your clock either way, accepts the request when any v1 entry matches,
ignores unknown keys and compares in constant time. A malformed or missing header is false,
never an exception. webhooks.sign(secret, body, t) makes a header for your receiver’s tests.