levrops-contracts
v1.3.1
Published
LevrOps API contracts, schemas, code generators, and Sanity content contracts
Downloads
24
Readme
LevrOps Contracts
Source of truth for LevrOps API and event contracts, JSON schemas, and generated SDKs.
Contents
openapi/– OpenAPI specifications for the HTTP API (levrops.v1.yaml)asyncapi/– AsyncAPI contracts for event/webhook payloads (events.yaml)schemas/– Shared JSON Schemas for core LevrOps domain objectscontracts/content/– Content contracts for Sanity schema generationclients/ts/– TypeScript SDK generated from the OpenAPI specificationsanity/generated/– Generated Sanity schema from content contractsCOMPAT.json– Compatibility matrix between API, events, and SDK releasesVERSION– Repository release version (mirrors the latest API contract)
Workflow
- Update JSON schemas and specs
- Edit
openapi/levrops.v1.yamlfor HTTP endpoints - Edit
asyncapi/events.yamlfor event stream/webhook contracts - Keep shared domain objects in
schemas/aligned with the operational data model
- Edit
- Validate contracts
- Run Spectral or Redocly CLI locally:
npx @redocly/cli lint openapi/levrops.v1.yaml - Validate AsyncAPI:
npx @asyncapi/cli validate asyncapi/events.yaml
- Run Spectral or Redocly CLI locally:
- Generate SDKs
- From
clients/ts:npm installthennpm run build - Publish to npm:
npm publish --access public
- From
- Bump versions & regenerate artifacts
- Run
python3 scripts/bump_version.py <new-version>(ormake release VERSION=<new-version>) to updateopenapi/levrops.v1.yaml,VERSION,COMPAT.json, and the TypeScript SDK (includes rebuilding docs). - Use
--events YYYY-MM-DD(ormake release VERSION=<new-version> EVENTS=YYYY-MM-DD) to override the events date recorded inCOMPAT.json.
- Run
TypeScript SDK
The TypeScript SDK lives in clients/ts and is generated via
openapi-typescript-codegen. Use the provided scripts:
cd clients/ts
npm install
npm run build # runs generate + compile
npm publish # publishes @hewnventures/levrops-sdkConsumers can instantiate the SDK with:
import { createLevropsClient } from '@hewnventures/levrops-sdk';
const client = createLevropsClient({
baseUrl: 'https://api.levrops.com',
accessToken: process.env.LEVROPS_ACCESS_TOKEN,
tenant: 'heirloom'
});
const contacts = await client.listContacts();CLI Tool
A command-line tool is available for managing contracts:
# Install the CLI
make install-cli
# or: cd cli && pip install -e .
# Use it
levrops-contracts bump 1.3.0 # Bump version and regenerate
levrops-contracts sync # Sync contracts across all projects
levrops-contracts validate # Validate OpenAPI/AsyncAPI specs
levrops-contracts status # Check versions across projects
levrops-contracts generate-docs # Regenerate API documentation
levrops-contracts submit-proposal --all # Submit contract proposalsSee cli/README.md for full CLI documentation.
Sanity Integration
Content contracts in contracts/content/ automatically generate Sanity schema definitions with multi-tenant/property support.
For Contract Maintainers
- Add or modify content contracts in
contracts/content/- Use
shared/for contracts available to all tenants - Use
heirloom/,studioops/for tenant-specific contracts - Add
scopemetadata to filter by tenant/property
- Use
- Generate schemas:
npm run sanity:codegen # All contracts npm run sanity:codegen -- --tenant=heirloom # Tenant-specific npm run sanity:codegen -- --tenant=heirloom --property=store1 # Property-specific - Commit the generated schema files
For Sanity Studio Repositories
Install the package:
npm install levrops-contractsImport and use schemas:
Option 1: Import all schemas (use runtime filtering):
import { allSchemas } from "levrops-contracts/sanity/generated/schema";
import { filterSchemas } from "levrops-contracts/sanity/utils";
import { contentContracts } from "levrops-contracts/contracts/content";
const tenant = process.env.SANITY_TENANT || "heirloom";
const tenantSchemas = filterSchemas(allSchemas, tenant, contentContracts);
export default {
name: "default",
types: tenantSchemas,
};Option 2: Import tenant-specific schema:
import { allSchemas } from "levrops-contracts/sanity/generated/schema-heirloom";
export default {
name: "default",
types: allSchemas,
};CI/CD:
- Run
npm run sanity:checkin CI to prevent schema drift - Regenerate schemas when contracts update
See docs/sanity-integration.md for detailed integration instructions.
Versioning
- Use semantic versioning for the repo (
VERSION) and the TypeScript SDK. - Use
levrops-contracts bump <new-version>(orpython3 scripts/bump_version.py <new-version>, ormake release VERSION=<new-version>) to keepVERSION,COMPAT.json, and the OpenAPI spec aligned (the script also bumpsclients/tsversions and rebuilds). - When events change, bump the AsyncAPI
info.versionand note the new target inCOMPAT.json(override via--eventsif needed).
Roadmap
- Add Python SDK generation (e.g., via
openapi-python-client) - Expand coverage to additional endpoints and webhook streams
- Automate validation and SDK publication in CI
