@earntori/sdk
v0.2.1
Published
Tori rewards SDK — issue AI credits to your users and read their balances.
Readme
@earntori/sdk
Give your users AI credits when something happens in your app.
import { Tori } from "@earntori/sdk";
const tori = new Tori({ apiKey: process.env.TORI_API_KEY! });
// 1. Define "first_project" on your developer page (name + amount).
// 2. When it happens, tell Tori:
await tori.rewards.trigger({ reward: "first_project", user: { id: user.id, email: user.email }, eventId: project.id });Tori handles the amount, duplicate protection, limits, the claim email, the wallet, and redemption. Every response carries a reward_id, the amount_cents Tori decided, and duplicate. Preview first: tori.rewards.preview({ reward, user }) → { eligible, reason, amount_cents, remaining } — nothing moves.
Also: tori.users.balance(id), tori.users.ledger(id), tori.rewards.confirm(reward_id, …) for EXTERNAL rewards you deliver yourself, tori.webhooks.parse(…) (verifies and returns the event). Errors are ToriError with a code (DUPLICATE_EVENT, LIMIT_EXCEEDED, REWARD_NOT_FOUND, …).
Advanced: tori.rewards.issue({ externalUserId, amountCents, reason }) for dynamic amounts — prefer trigger().
Docs: https://www.earntori.com/developers · Get a key: https://www.earntori.com/developer
