LearnUse it in your language
Load a bundle
Load a compiled bundle, or compile YAML where your language can, in every runtime.
A bundle is the compiled, checksummed form of a ruleset. CI compiles it once; every runtime loads the same file and gives the same answer. Load it once, when your program starts. A bundle that cannot be read is a load error: stop, do not serve without rules.
What to do. Give the browser the client manifest, never the bundle: the bundle holds server-only rules. Import it at build time, or fetch it from the rule server with createManifestClient.
The code.
import type { Manifest } from '@rules-cascade/core';
import { TransferForm } from './TransferForm';
import clientManifest from './manifest.client.json';
/**
* The manifest is the client-safe view of examples/contracts/payments-transfer.ruleset.yaml.
* It is committed here so the example runs without a backend (regenerate it with `make sync`).
*
* Against a real service, fetch it instead - the ETag is the ruleset checksum, so it caches well:
*
* const client = createManifestClient({ baseUrl: '/api/rules', onStale: ({ error }) => console.warn(error) });
* const manifest = await client.get('acme.payments.transfer');
*
* While the rule server cannot be reached, `get` answers with the manifest it fetched last and calls
* `onStale`, so the form keeps working; the API still evaluates the contract when the form is submitted.
*/
const manifest = clientManifest as unknown as Manifest;Run it.
npm ci && npm run build # at the repository root, once
npm run dev -w rule-cascade-example-frontend-reactThe output.
The form loads the manifest and evaluates it on every change. Try the same engine here:
Try it YourselfRuns in your browser with the TypeScript engine. Nothing to install.