fetch (browser, Node, edge, workers).
Install
Usage
getAd resolves to RevinelAd | null; getAds to RevinelAd[] (empty when nothing is
eligible; the SDK never throws on “no ads”).
Typed creative (meta)
ad.meta is keyed by each custom field’s stable machine slug (set when the publisher
creates the field, e.g. bannerImage for a “Banner image” field). Pass your own interface
for typesafe access:
Next.js / caching
Ad fetches default tonext: { revalidate: 60 }, so App Router pages that call
getAd/getAds stay statically renderable while the ad still refreshes every minute.
(Revinel’s API edge-caches responses for ~5s anyway, so per-request rotation was always
approximate.) Non-Next runtimes ignore the next key: server fetches (Node/edge) stay
uncached, while browsers honor the response Cache-Control (max-age=5) and may reuse
an identical request for up to ~5s, the same window the API’s edge cache already
imposes.
Opt out for true per-request rotation (on an already-dynamic Next page, or anywhere
else):
cache or next.revalidate you pass replaces the default entirely.
Checkout
Start a Stripe Checkout session for a tier price and send the visitor to itsurl:
metadata is written to both the Stripe Checkout session and the subscription on your
connected Stripe account. The subscription keeps it, so every renewal invoice carries it
too. Values must be strings. You can send up to 47 keys (Stripe allows 50 and Revinel uses
3), each key up to 40 characters and each value up to 500 characters. Keys cannot contain
square brackets. The keys workspaceId, tierId and tierPriceId are reserved for
Revinel. A request that uses one of them or breaks a limit answers 422 and creates no
session. Revinel does not store your metadata.
Local development
On a page served from a local or private host,recordImpression and recordClick send no
request and resolve to { success: false }. The Revinel API ignores those events, so your own
testing stays out of the stats advertisers see. A client pointed at a local Revinel API still
sends them.
isLocalHostname(hostname) is the check the SDK and the API both use. It is exported if you
want to apply the same rule elsewhere:
Errors
Non-2xx responses throwRevinelApiError ({ status, body }). The body is the Revinel
API error envelope:
code: "INPUT_VALIDATION_FAILED" and a
data.fieldErrors / data.formErrors map.
For React bindings see revinel/react.