triggair /docs
Recipes

Copy-paste integration recipes

Each recipe is a self-contained snippet you (or your agent) can lift verbatim. They are the same building blocks that assemble llms-full.txt.

Install & initialize

npm i @triggair/sdk
import { createClient } from '@triggair/sdk';
const tg = createClient({ key: 'tg_pk_your_key' });
Only the publishable key (tg_pk_) is needed. NEVER put a secret key (tg_sk_) in client code — it belongs on a server.

Player identity (anonymous-first)

const { playerId } = await tg.login();
An anonymous player token is minted from a device id on first use and silently refreshed. Player-scoped calls attach it automatically.

Cloud saves

await tg.saves.put('slot1', { level: 4 });        // last-write-wins
await tg.saves.put('slot1', data, { ifMatch: v });  // conflict-safe (throws save_conflict)
const { data } = await tg.saves.get('slot1');
tg.saves.queue('slot1', data);                     // durable/offline (replays on reconnect)

Leaderboards

Configure a board once (triggair_configure_leaderboard), then:
await tg.leaderboards.submit('high_scores', 9000);
const { entries } = await tg.leaderboards.top('high_scores', { limit: 10 });

Achievements & daily rewards

await tg.achievements.report('first_win', 1);  // reward lands in the inbox on unlock
const status = await tg.daily.status();
if (status.claimable) await tg.daily.claim();
Rewards are claimed from tg.inbox (the one hardened grant path).

Analytics (durable & offline)

tg.track('level_complete');
Events are coalesced and queued in a durable outbox; they survive a dropped connection and flush on reconnect. Counts only — no per-player data.

CORS: works locally, 403s when deployed

Browser calls are origin-checked. If a call fails only once deployed, add your deployed origin to the game's allowed_origins (dashboard → CORS, or triggair_set_allowed_origins). An empty allowlist = open to any origin — set it before you ship.

Recovery (cross-device)

const { code } = await tg.mintRecoveryCode();  // show/share once
await tg.recover(code);                        // same player on a new device

Errors are actionable

Every failure throws a TriggairError with { code, message, agentHint, requestId }. Read agentHint — it tells you how to fix the call. rate_limited/5xx/network retry automatically. See /docs/errors/<code>.

Verify your integration

After wiring the SDK, run the MCP tool triggair_verify_integration (or the dashboard's verify runner). It live-probes player + saves + leaderboards and advises on CORS, with pass/fail per service and fix hints — closing the loop.