Skip to content

JavaScript SDK — @glowar-ltd/sdk-js

The JavaScript SDK is the main way to build on AIR. It is TypeScript, ships as ES modules, has no runtime dependencies, and runs on Node 18+ and in the browser.

  • Repo: https://github.com/Glowar-Ltd/air-sdk-js (private)
  • Current version: 0.35.1
  • Runnable example: examples/webhook-server in that repo.

Install

The package is published privately to GitHub Packages under the @glowar-ltd scope. You need a GitHub token with read:packages and access to the package. Add an .npmrc to the consuming project:

@glowar-ltd:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}

Then:

NODE_AUTH_TOKEN=<your token> npm install @glowar-ltd/sdk-js

In GitHub Actions, set NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} with permissions: packages: read.

Pin your range deliberately

The SDK is pre-1.0. In 0.x a minor version may change shape — 0.35.0 did, when peer messaging moved under the Care practice's routes. A caret range like ^0.35.0 only accepts 0.35.x patches, which is what you want: read the changelog and bump the range yourself.

What is in it

Import only what you need; each entry point is independent.

Import Runs on What it gives you
@glowar-ltd/sdk-js or …/webhooks Server handleWebhook, verifyWebhook, parseEvent, a typed Event union, and a mountable receiver (createWebhookReceiver, createWebhookRoute, createWebhookMiddleware)
@glowar-ltd/sdk-js/management Server only PartnerClient — typed wrappers for the partner API: groups, contacts, care profiles, the cast, allowances, sessions, threads, oversight, files, messages, peer relationships and the door read
@glowar-ltd/sdk-js/thread Browser Colleague / Thread — a participant's chat with their colleague over the live WebSocket, with history, a resuming fallback, resend-until-acknowledged, multi-device echo, pictures and taking a message back
@glowar-ltd/sdk-js/peer Browser Peer / PeerChannel — moderated messaging between two participants (needs the Care practice)

A typical integration uses three of them: your server provisions people and mints a session token with PartnerClient, the browser spends that token on a chat with Thread, and webhooks bring what happens out of band back to your server.

The partner key never reaches a browser

PartnerClient holds your partner key, which is root over your team's slice of AIR. Never import …/management into browser code or put the key in a public environment variable. A browser only ever gets a short-lived session token, minted for one person.

The partner client

import { PartnerClient } from "@glowar-ltd/sdk-js/management";

const air = new PartnerClient({
  baseUrl: process.env.AIR_PARTNER_BASE_URL!,
  key: process.env.AIR_PARTNER_KEY!,
});

const group = await air.groups.create({ kind: "family", label: "The Prices" });
const child = await air.contacts.create({
  group_id: group.id,
  kind: "external_participant",
  first_name: "Owain",
});

Every failure — an HTTP error, a timeout, AIR unreachable — arrives as a PartnerError with a stable code. Switch on code, never on message.

The full surface, with its object model, is docs/partner-client.md in the SDK repo. The routes underneath are described on the partner API page.

Webhooks

The quickest correct receiver is the mountable one. It answers with the status codes AIR expects (a bad signature is 401; a handler that throws is 500, so AIR retries), tries every secret during a rotation, and lets you skip events you have already processed.

import { createWebhookRoute } from "@glowar-ltd/sdk-js";

export const POST = createWebhookRoute({
  signingSecrets: currentSecrets(),      // webhook.signing_secrets from GET /v1/partner/door
  refreshSecrets: () => readDoorSecrets(), // optional: re-read once after a signature failure
  seen: (eventId) => alreadyProcessed(eventId),
  onEvent: async (event) => {
    switch (event.event) {
      case "overseer.alert":
        await notifyParent(event.data);
        break;
      // …
    }
  },
});

createWebhookMiddleware does the same for Express-style servers, and createWebhookReceiver gives you the decision without any framework.

If you would rather do it yourself, handleWebhook verifies and parses in one call:

import { handleWebhook } from "@glowar-ltd/sdk-js";

const result = handleWebhook({
  rawBody,                         // the raw request body string, before any JSON parsing
  signingSecret,                   // your door's signing secret
  signatureHeader,                 // value of the X-AIR-Signature header
});
if (!result.ok) return res.writeHead(result.status).end(result.reason);
const event = result.envelope;     // typed: event.event + event.data

The typed event list lags the platform

alert.peer.participant_pattern and quiz.assignment.completed are delivered today but are not yet in the SDK's typed union — they arrive as an UnknownEvent, with the signature verified as usual. The union also still lists a few kinds AIR does not send to partners (conversation.opened, conversation.ended, file.scanned, alert.media.blocked); you will never receive them. The webhooks page has the list of what is actually delivered.