---
title: "site-kit: the Astro client for the Rivil site API | Rivil Solutions"
description: "The npm client for the Rivil site API. Content, modules, shop and customer accounts on Astro or any Node server. The site key stays on the server."
url: https://rivil.app/en/developers
language: en
publisher: Rivil Solutions
---

# site-kit: the Astro client for the Rivil site API

Build the site. The data comes from the ERP.

@rivil-solutions/site-kit talks to the Rivil site API (/api/site/v1) from your server. Use it on an Astro site, or on any Node server, built on top of Rivil ERP. The site key never reaches the browser.

npm i @rivil-solutions/site-kit

Also: npx degit iorpaul3/rivil-site-template my-site

[Start from the starter](https://github.com/iorpaul3/rivil-site-template) [Read the docs](https://docs.rivil.app/en/start/starter/) [Package on npm](https://www.npmjs.com/package/@rivil-solutions/site-kit) [GitHub](https://github.com/iorpaul3/rivil-site-kit)

What’s inside

## What’s inside the package

The package is the client for the Site API, plus the pieces a site needs around it: cache, webhooks, modules, shop, languages and SEO. It updates with npm update, so a fix reaches every site that uses it.

### createSiteClient

Requests with the site key. Reads are cached in memory (fresh for 60 seconds, then served stale and refreshed in the background), identical requests are merged, and purge() refreshes everything after a webhook. Errors come as RivilApiError (status, code, message).

### createContentApi

The Site module: settings, menus, redirects, terms, entries, search, forms.

### createModulesApi

Public reads of booking, careers, reviews and events, for server-rendered pages.

### siteProxy

The browser calls /api/rivil/... on the site; the site calls the ERP with the key. Only visitor actions get through (MODULE_ROUTES).

### @rivil-solutions/site-kit/web

What also runs in the browser: rivilFetch, SiteError, money, days, consents, bookingPlan.

### @rivil-solutions/site-kit/react

Form logic for the modules, with no styling: useBooking, useStay, useApplication, useReview, useEventCheckout. Peer dependency: React 18 or newer.

### Webhooks

rivilWebhookHandler and verifyRivilSignature for signed webhooks (X-Rivil-Signature).

### Visitor IP

visitorIp plus the X-Rivil-Client-IP header, so ERP rate limits apply per visitor, not per site.

### createI18n

Language from the URL prefix (/en/...), t(), lp(), translated segments, prefixed internal links.

### Images

imageAt, imageWidths and @rivil-solutions/site-kit/astro-image: Gallery images at the right width, with no processing on the server.

### SEO helpers

sitemapXml, robotsTxt, matchRedirect: sitemap, robots and the redirects set in the ERP.

### Consent

consentScriptUrl for the Rivil Consent banner.

### createShopApi

Catalog, cart, shipping, checkout, customer account, gift cards and returns, with the language in the URL. warmProducts() loads the catalog into memory at startup; purgeChanged handles the shop.changed webhook.

### accountProxy

The customer account (portal) through the site, session in an httpOnly cookie, only the allowed routes (AUTH_ROUTES).

### rivil CLI

Copies module pages and starting themes into a site.

Start with an AI assistant

## Paste one prompt and run the site locally

After the trial is ready, the handover page gives you a prompt for Claude or Cursor. It installs the starter, writes .env with your keys and runs npm run dev.

1

### Install Node.js 20+

If it is missing, the prompt tells you what to install.

2

### Copy the handover prompt

One text block with keys and commands, not in email.

3

### Change a title in the ERP

See it on localhost in a few minutes.

How it works

## The browser talks to the site, the site talks to the ERP

Visitor actions never go to the ERP with the site key in the browser. Pages are rendered on the server. When something must be submitted from the browser (a booking, a form, an account request), the request hits a route on the site; the site adds the key and calls the ERP. Only the visitor actions allowed by the package get through.

### Visitor browser

Pages arrive already rendered

- /api/rivil/... (siteProxy, visitor actions only)
- /api/account/... (accountProxy, httpOnly session cookie)

### Your Astro or Node site

The keys stay here

- ERP_SITE_KEY, SHOP_CHANNEL_KEY, ERP_PORTAL_KEY
- createContentApi, createModulesApi, createShopApi

### Rivil ERP

Content, modules and shop

- /api/site/v1 and the shop API
- Signed webhook: X-Rivil-Signature

**/api/hooks/rivil on the site** rivil.purge() or shop.purgeChanged(...)

The site key never leaves the server. Rate limits use the visitor’s IP (X-Rivil-Client-IP), not the site’s.

### What not to touch

- The site key is server only: never in the browser or in PUBLIC_*.
- Do not rewrite the webhook route or the /api/rivil route.
- Do not put texts, prices, opening hours or phone numbers in code when they already live in the ERP.// src/pages/api/rivil/[...path].ts import { siteProxy } from '@rivil-solutions/site-kit' import { client, siteUrl } from '../../../lib/rivil' // origins: behind a reverse proxy, Astro sees the request on localhost const proxy = siteProxy({ client, origins: [siteUrl()] }) export const ALL = (c) => proxy({ request: c.request, path: c.params.path, clientAddress: c.clientAddress })

Modules and themes

## Add booking, jobs, events and more with one command

rivil add copies the module’s pages and styled components into the site. From then on they belong to the site and can be changed freely. The logic (free slots, holds, validation, submitting) stays in this package and is updated with it.

The command also prints the scopes the site key needs and the English URL segments to add to site.config.ts.

### booking

Online booking: services, specialist, time, confirmation

### stay

Stays: free rooms by night, reservation

### careers

Open jobs, job page, application with CV

### reviews

Published reviews and the review form

### events

Events, paid tickets, the order

### newsletter

Newsletter signup, with email confirmation

### Starting themes

The starting themes come from the demo sites and only change colors and fonts.

aercabanacurtelumenmiezsolvar

### The shop is not a module to copy

Start from Casa Lumen, which uses the same package, and use createShopApi with a shop channel key.

[See the demo store](https://demo-ecommerce.rivil.app/en)

Shop and account

## Shop and customer account

The shop uses the same package, with a channel key. createShopApi covers the catalog, cart, shipping, checkout, customer account, gift cards and returns. At startup, call warmProducts() once per language. When the ERP sends shop.changed, call shop.purgeChanged(event.data.object) so only what changed is refreshed.

The customer account (portal) goes through the site: accountProxy plus AUTH_ROUTES, a session in an httpOnly cookie, and only the allowed routes. Use a portal key (ERP_PORTAL_KEY in the README sample), separate from the site key.

[Headless ecommerce](https://rivil.app/en/headless/ecommerce) [Client portals](https://rivil.app/en/client-portals)

Webhooks and cache

## A webhook clears the cache when something changes

Reads through createSiteClient stay fresh for 60 seconds, then can be served stale while they refresh in the background. Identical in-flight requests are merged. After a signed webhook, purge() refreshes everything. For the shop, purgeChanged can limit the refresh to what the shop.changed event names.

Set the webhook in the ERP, on the site, to /api/hooks/rivil, with the content.* events (and shop.changed when you run a store). The handler verifies X-Rivil-Signature with ERP_WEBHOOK_SECRET.

Languages, images, SEO

## Languages, images and SEO, from the ERP

createI18n reads the language from the URL prefix (/en/...), and gives you t(), lp(), translated segments and prefixed internal links. In the starter, the first locale has no prefix and the others do. Menus, redirects, titles and the sitemap come from the ERP; the package helps you emit sitemapXml, robotsTxt and apply matchRedirect.

Gallery images are resized by width with imageAt and imageWidths, and in Astro you can set the image service to @rivil-solutions/site-kit/astro-image, with no image processing on your server. consentScriptUrl loads the Rivil Consent banner.

[Headless website](https://rivil.app/en/headless/website) [Cookie banner](https://rivil.app/en/cookie-banner)

Starter template

## Start from the Astro starter

rivil-site-template is an Astro site that takes its content from the Rivil Site module: home page, pages and posts following the URL pattern set in Site, menus, contact form, 404, sitemap, robots, and a second language on /en. It also includes rules for Claude Code and Cursor (AGENTS.md). To let the assistant see types, fields and entries in the ERP, set RIVIL_API_KEY (an API key with access to Site only) and use the included .mcp.json and .cursor/mcp.json.

- 1

### Get the code

Use the template on GitHub, or npx degit iorpaul3/rivil-site-template my-site.

- 2

### Set up the site in the ERP

Under Site: create the site, then on its page a site key and, so it updates by itself, a webhook to /api/hooks/rivil with the content.* events.

- 3

### Fill in .env

Copy .env.example to .env and fill in ERP_URL and ERP_SITE_KEY (and ERP_WEBHOOK_SECRET for the webhook).

- 4

### Run it

npm install, then npm run dev: the site shows the company’s real data on http://localhost:4321.

- 5

### Deploy once

Work locally until it looks right, then deploy once (Dockerfile included). On the server, set the same variables, plus SITE_INDEX=true on the final domain only.

The package and the starter are MIT licensed.

[Starter on GitHub](https://github.com/iorpaul3/rivil-site-template) [Full starter guide](https://docs.rivil.app/en/start/starter/) [Docs for AI assistants](https://docs.rivil.app/en/start/for-ai/) [Demo sites](https://demo-websites.rivil.app/en)

Around the package

## Where it fits

### [Rivil Headless](https://rivil.app/en/headless)
The model: ERP as backend, API, channels.

Read more

### [Headless website](https://rivil.app/en/headless/website)
Content in the ERP, on any site.

Read more

### [Headless ecommerce](https://rivil.app/en/headless/ecommerce)
Catalog, cart and checkout on your frontend.

Read more

### [Build it yourself](https://rivil.app/en/build-it-yourself)
Access, test environment and optional hosting.

Read more

Questions

## What people ask us

### Do I have to use Astro?

The package is written for Astro sites, or any Node server, on top of Rivil ERP. The public starter and the rivil add and rivil theme commands copy Astro pages and components. There are also React hooks (@rivil-solutions/site-kit/react) and a browser module (@rivil-solutions/site-kit/web). If you are not on Astro, you can still use the client on a Node server; you will wire the routes yourself.

### Does the site key reach the browser?

No. The client runs on the server. The site key must never go into the browser or into a PUBLIC_* variable. The browser calls /api/rivil/... (and /api/account/... for the customer account) on your site; your site calls the ERP with the key.

### What does npx rivil add change in my project?

It copies the module’s pages and styled components into the site. Those files are yours to change. The logic (free slots, holds, validation, submitting) stays in @rivil-solutions/site-kit and is updated with the package. The command also prints the scopes the site key needs and the English URL segments to add to site.config.ts.

### Can I add the shop the same way?

No. The shop is not a module to copy with rivil add. You start from Casa Lumen, which uses the same package, and you use createShopApi with a shop channel key. There is a live demo store at demo-ecommerce.rivil.app.

### How does the site stay in sync with the ERP?

Reads are cached in memory: fresh for 60 seconds, then served stale and refreshed in the background. You set a signed webhook on the site to /api/hooks/rivil (for example content.*, and shop.changed for the store). The handler calls purge() or shop.purgeChanged(...).

### Can I build this with Cursor or Claude?

Yes. The starter ships AGENTS.md and MCP config for Cursor and Claude. Set RIVIL_API_KEY to a key with access to Site only, so the assistant can see types, fields and entries. The docs also have a page for AI assistants, plus prompts. You still need a Rivil site and a site key; request access if you do not have them yet.
