API

SDK

Typed functions for every API route, GraphQL clients and your organization's own typed client, over one transport you choose.

@cactive/sdk is the client the platform's own apps use: a typed function for every route of the API, a client for each GraphQL part, and a typed client for your organization's objects and actions that cactive sdk generate writes. Each call sends exactly the request the API reference shows beside its cURL. The package isn't on npm yet.

A first call

A transport sends one request and answers its JSON. In a script, fetchTransport sends your key or token as Authorization: Bearer:

import { fetchTransport } from "@cactive/sdk"
import { orgMapsLists, postOrgMapsLists } from "@cactive/sdk/platform"

const transport = fetchTransport({ baseUrl: "https://api.cactive.com.au", token: process.env.CACTIVE_TOKEN! })

const { lists } = await orgMapsLists(transport, { orgId: "org_123" })
await postOrgMapsLists(transport, { orgId: "org_123", body: { name: "Depots" } }, { idempotencyKey: "depots-1" })
  • Names: each function is named as the route's GraphQL field (orgIssuesByIssueKey, postOrgPages). The reference lists each route's function beside its cURL.
  • Input: path and query parameters side by side, the JSON body under body. A query parameter named as a path parameter is query<Name>.
  • Options: purpose, the reason a marked read asks for, and idempotencyKey, so a change sent twice runs once.
  • Bundles: each function is its own export, so a bundle keeps only the functions it imports.

Errors

A failed call throws. fetchTransport throws SdkError with the HTTP status, the API's code and its answer in body. failureOf(err) reads the status and code from any transport's error, and is undefined for a network failure.

GraphQL

import { orgClient, platformClient } from "@cactive/sdk"

const platform = platformClient(transport)
const { me } = await platform.graphql<{ me: { email: string } }>("{ me { email } }")

const org = orgClient(transport, "org_123")
const answer = await org.graphql("query { objectCount(type: \"Camera\") { total } }")

A document that answers errors throws GraphqlError, holding what did answer and each error's extensions.

Your organization's client

cactive sdk generate --out cactive-sdk

Writes your organization's schema, its OpenAPI document and client.ts, typed from the object types and actions you may see. createClient(transport, orgId) gives objects.<type>(args), objectSearch, objectCount, object and actions.<action>(args), each pinned to the version the client was built on. When a later version breaks it, a call throws OntologyChangedError naming what changed; run cactive sdk generate again. Anything carrying a marking you don't hold is in no file.

import { fetchTransport } from "@cactive/sdk"
import { createClient } from "./cactive-sdk/client"

const client = createClient(fetchTransport({ baseUrl: "https://api.cactive.com.au", token: process.env.CACTIVE_TOKEN! }), "org_123")
const page = await client.objectSearch({ type: "Camera", first: 10 })

Definitions from the command line

CommandWhat it does
cactive ontology pullWrites the definitions you may see as ontology/<kind>/<id>.json.
cactive ontology pushPublishes what the folder changed, through the same check and review as any other change.
cactive ontology push type/hydrant.json rule/pressure-low.jsonAdds a type or a rule from its file, without a pulled folder; one that exists is refused unless --force.
cactive sources add <id> --from <source>Adds a source cloned from one of your organization's, without its credential; --dry-run shows the clone.

A breaking change needs --proposal "<title>" and its review. Every command is in the command reference.