The SDK
The four parts of @sypnia/cases, and how to parse, validate and change maps from code.
npm install @sypnia/cases| Import | For |
|---|---|
@sypnia/cases/sypnorm | Sypnorm, the use-case ORM, and the runtime inside each area’s service (Sypnorm, Running cases) |
@sypnia/cases/map | derive and upload the map from code (The map from your code) |
@sypnia/cases/spec | the format, offline (below) |
@sypnia/cases/client | the Cases API (below) |
@sypnia/cases/spec: the format, offline
import { parseMap, validateMap, diffMaps } from '@sypnia/cases/spec';
const map = await parseMap('./cases'); // reads map.yaml, navigation.yaml and every case file
const { ok, errors } = validateMap(map); // [{ file, path, line, message, kind }]
const changes = diffMaps(previous, map); // added, removed and changed cases, field by field
const path = map.navigation.pathOf('shop.order-for-tomorrow'); // ['Shop', 'Order for tomorrow']
const graph = map.events(); // { nodes, edges, cycles }, the event graphparsePlan(file, text) reads cases/plan.md into its milestones (title, cases, delivered, line), and checkMap(map, { code, plan, caseIds, production, contract }) runs the whole check on what you give it. sameTable(a, b) compares table names by singular and plural, as the check does, and repairOneOf joins a one_of(a, b) that a YAML flow mapping split at the comma.
The JSON Schemas of the format ship in the package too: mapSchema, navigationSchema, caseSchema and eventSchema from @sypnia/cases/spec, and the files in @sypnia/cases/schema/ (JSON Schema).
@sypnia/cases/client: the Cases API
import { createClient } from '@sypnia/cases/client';
const cases = createClient({ token: process.env.SYPNIA_TOKEN }); // a Sypnia token (session, PAT) or a Cases project token
const map = await cases.maps.get('la-espiga');
const proposal = await cases.proposals.create(map.id, {
title: 'Gift cards',
changes: [{ op: 'add', case: { id: 'redeem-gift-card', title: 'Pay with a gift card', actor: 'customer', goal: 'Use a gift card at checkout' } }],
});
await cases.proposals.requestReview(proposal.id, { reviewers: ['ana@laespiga.co'] });Every method maps to one endpoint of the API: me, workspaces, maps (with navigation, places, find, events, links to Data and Telemetry, uploads and the audit), versions, proposals, checks, cases, deliveries, deadLetters and tokens.
- One map.
createClient({ token, map: 'la-espiga' })lets the methods about one map leave it out:cases.cases.links('place-order'). - Another server.
baseUrlpoints the client at your own Cases server (by defaulthttps://cases.api.sypnia.com/v1, orSYPNIA_CASES_APIplus/v1). - A session bound to a key. Pass
headers: (method, url) => …instead oftoken, to sendAuthorization: DPoP …and itsDPoPproof on every request. - Errors throw a
CasesApiErrorwith thestatus, thecodeof the API errors, theerrors[]of aninvalid_map, andretryAfterfor a429.