Docs · nexoflow-sdk Configuration
nexoflow-sdk
Configuration
Construct a client with your site key, then tune timeouts, caching, retries and logging if you need to.
Full example
client.ts
const nf = new NexoFlow({
// Required
apiKey: process.env.NEXOFLOW_API_KEY!,
// Optional
baseUrl: "https://nexoflow.net", // default
timeout: 15_000, // 15 seconds for the whole call (default)
revalidate: 60, // Next.js ISR hint in seconds (default)
// Custom fetch (polyfills, edge, tests)
fetch: customFetchFn,
// Retry network errors, 5xx and 429 answers
retry: {
attempts: 3, // default, including the first request
delay: 500, // base delay in ms, doubled each retry, plus jitter (default)
},
// Debug logging (request/response details, keys masked)
debug: true,
// Lifecycle hooks
hooks: {
beforeRequest: ({ url, init }) => {
console.log("Requesting:", url)
},
afterResponse: (res) => {
console.log("Status:", res.status)
},
},
})Options
Reference for each constructor option:
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | Your site key. Must start with pk_live_ |
baseUrl | string | https://nexoflow.net | NexoFlow's address; paths are added after it |
revalidate | number | false | 60 | Default Next.js ISR hint (seconds), sent as next.revalidate; other runtimes ignore it |
timeout | number | 15000 | Time limit for a call in ms, retries included |
fetch | typeof fetch | globalThis.fetch | Custom fetch (edge, tests, polyfills) |
retry | object | { attempts: 3, delay: 500 } | Retries for network errors, 5xx and 429 |
debug | boolean | false | Log each request and response to console.debug, with the key masked |
hooks | object | – | beforeRequest (may change the request) / afterResponse (every response, errors included) |
The constructor checks its input and throws a plain Error when the key is missing or doesn't start with pk_live_, when timeout isn't a positive number, when retry.attempts isn't a positive whole number, or when retry.delay is negative.
Retries & timeouts
- A network error, a timeout, a
5xxor a429is retried, up toretry.attemptstries in all. - The wait before each retry is
retry.delaydoubled each time, plus up to half again at random. On a429, the API'sRetry-Afterwins. - Other
4xxanswers (400,401,402,404) are thrown at once. timeoutcovers the whole call, retries and waits included. When it runs out, the error's code isTIMEOUT.
Per-request options
Every method takes an optional last argument with a signal to cancel the call (combined with the client's timeout) and a revalidate that overrides the client's ISR hint for that call only.
per-request.ts
const controller = new AbortController()
const { data } = await nf.posts.list(
{ limit: 12 },
{ revalidate: 300, signal: controller.signal }, // this call only
)What each request sends
Every call is a GET with these headers. The X-Request-Id is the traceId you get back, so you can find the call in your own logs.
request
GET https://nexoflow.net/api/v1/content/posts?limit=12
Authorization: Bearer pk_live_…
Accept: application/json
User-Agent: nexoflow-sdk/0.3.8
X-Request-Id: nf_… // the traceId on the response or the error