Skip to content

The SDK

The four parts of @sypnia/cases, and how to parse, validate and change maps from code.

Applies to EngineCloud
View as Markdown
On this page
  1. @sypnia/cases/spec: the format, offline
  2. @sypnia/cases/client: the Cases API
Terminal
npm install @sypnia/cases
ImportFor
@sypnia/cases/sypnormSypnorm, the use-case ORM, and the runtime inside each area’s service (Sypnorm, Running cases)
@sypnia/cases/mapderive and upload the map from code (The map from your code)
@sypnia/cases/specthe format, offline (below)
@sypnia/cases/clientthe Cases API (below)

@sypnia/cases/spec: the format, offline

TypeScript
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 graph

parsePlan(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

TypeScript
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. baseUrl points the client at your own Cases server (by default https://cases.api.sypnia.com/v1, or SYPNIA_CASES_API plus /v1).
  • A session bound to a key. Pass headers: (method, url) => … instead of token, to send Authorization: DPoP … and its DPoP proof on every request.
  • Errors throw a CasesApiError with the status, the code of the API errors, the errors[] of an invalid_map, and retryAfter for a 429.
  1. @sypnia/cases/spec: the format, offline
  2. @sypnia/cases/client: the Cases API

    Search pages, sections and terms