Tiun sdk
Use when integrating or debugging the tiun SDK (@tiun/sdk), tiun's JavaScript library for authentication, subscription billing, one-time purchases, and time-based paywalls. Triggers on imports of `@tiun/sdk`, calls like `tiun.init`, `tiun.checkout`, `tiun.login`, `tiun.start`, or questions about tiun products, entitlements, one-time purchases, lifetime access, fixed fees, time-based sessions, or server-side verification.From its SKILL.md
npx -y skills add tiun-app/skills --skill tiun-sdkAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
13.1 KB, as published. Nobody here has run it
tiun SDK skill
Use this skill whenever the user is integrating, extending, or debugging code that uses @tiun/sdk. Authoritative upstream docs: https://docs.tiun.io/llms-full.txt.
What tiun is
A commercial backend platform providing authentication, payments, and entitlements through a single JS SDK. The tiun singleton supports three flows; you pick based on the integrator's intent (see "Step 0 — Discovery before code"):
- Subscriptions — persistent user accounts (OTP login), recurring billing, per-product entitlements in
user.productAccess[]. Entry point:tiun.checkout({ productId }). See references/subscriptions.md. - One-time purchases — same accounts and same entry point as subscriptions, but a single fixed fee and permanent entitlement: no interval, no trial, no renewal, no expiry. Entry point:
tiun.checkout({ productId }). See references/one-time.md. - Time-based — per-session anonymous access (no account required), metered by time spent on paid content. Entry point:
tiun.start()+paywallShow/paywallHideevents. See references/time-based.md.
Install: npm install @tiun/sdk. Init: tiun.init({ snippetId, language: 'en' }) on app start (idempotent).
tiun runs live and sandbox as two independent parallel environments. The SDK's sandbox flag selects which one — see references/installation.md.
Step 0 — Discovery before code
Before writing any integration code, establish four things. Ask only for items the user has not already stated. If their prompt is fully specified ("wire up subscription with product p-test-pro in sandbox to gate /watch/*"), skip discovery.
Use a structured question primitive (e.g. AskQuestion) if your client supports one; otherwise ask inline in chat.
0a. Detect the MCP and offer to install if missing. See references/mcp.md for per-client install instructions and detection. Three states:
- MCP present and authed → use it to enumerate providers/products in 0c.
- MCP present, not authed → prompt auth once; if declined, proceed in manual mode.
- MCP absent → offer to install (single-sentence value proposition: "fetch your snippetId and productIds directly so we avoid copy-paste errors"). If declined, proceed in manual mode.
0b. Establish integration mode. Subscription, one-time purchase, time-based, or a combination? See references/discovery.md for cues that map user language to each mode. Do not infer mode from the account's inventory. A provider with only one product type today may be planning another tomorrow.
0c. Gather identifiers. Questions depend on mode and MCP availability:
- Subscription, MCP present → list providers, ask user to pick; list products, ask user to pick one or multiple tiers; confirm environment from the provider's sandbox/live tag.
- Subscription, no MCP → ask for
snippetId; ask one product or multiple tiers; for each, askproductIdand label; confirm sandbox or live (thep-test-.../p-live-...prefix is a strong hint). - One-time, MCP present → list providers, ask user to pick; list products, ask user to pick the product(s) to unlock; confirm environment from the provider's sandbox/live tag. Do not ask about tiers — one-time products are not tiered.
- One-time, no MCP → ask for
snippetId; for each product, askproductIdand label; confirm sandbox or live (prefix is a strong hint). - Time-based, MCP present → list providers, ask user to pick; confirm environment from provider tag.
- Time-based, no MCP → ask for
snippetId; confirm sandbox or live.
When the MCP is present, ground questions in inventory ("you have a sandbox time-based product p-test-xxx — wire that up, or set up subscription products first?") rather than asking blind.
0d. Identify what to gate. Without this step the agent is generating boilerplate with no target. Ask:
- Which routes/components/features require access?
- What should non-authenticated users see? (inline login + checkout buttons / redirect to pricing page / full-screen paywall / teaser + subscribe)
- What should authenticated-but-no-access users see? (typically the same UX with "upgrade" copy)
- Is there a free preview? (If yes, this is often a cue the user actually wants time-based, not subscription — feed back into 0b.)
- For multi-tier: which routes/features map to which tier?
When to do what
| Task | Route to |
|---|---|
| Discovery, scoping, MCP detection, mode selection | references/discovery.md |
| MCP installation per client, detection, auth | references/mcp.md |
| What tiun is, supported platforms, product model | references/overview.md |
| Install / init / config / per-host env injection | references/installation.md |
| Method or property lookup | references/api-reference.md |
| Event names and payloads | references/events.md |
| Subscription gating (accounts + recurring billing) | references/subscriptions.md |
| One-time purchase gating (fixed fee, permanent access) | references/one-time.md |
| Time-based paywall (per-session, anonymous, metered) | references/time-based.md |
| Trusted backend authorization | references/server-verification.md |
| Framework wiring (any stack) + lifecycle matrix | references/frameworks.md |
| "Overlay not appearing", SSR errors, sandbox mismatch | references/troubleshooting.md |
Load-bearing rules
tiun.init({ snippetId, language })runs on the client, early in startup. In Next.js/Nuxt, wrap in a client-only component/plugin. Never call it on the server.initis idempotent — calling it again merges config rather than re-initializing, so noisInitializedguard is needed.snippetIdis not a secret. It identifies the environment. UseNEXT_PUBLIC_*/publicruntime config.userChangeis the source of truth for checkout-based gating (subscriptions and one-time purchases), not a one-shottiun.userread. Entitlements change mid-session. The payload includesevent: 'init' | 'login' | 'checkout' | 'logout' | 'update'for cases where you need to know what triggered the change.- Never trust the client for authorization. For protected server resources:
tiun.getUserVerificationToken()returns a JWT (5-minute lifetime), send it to your backend, the backend validates it viaPOST /live_api/s2s/v1/users/verificationwithX-TIUN-API-KEY. For time-based, use thesessionIdfrompaywallHideagainstPATCH /live_api/s2s/v1/sessions/{sessionId}/status. Seereferences/server-verification.md. - Do not reimplement checkout/login UIs. tiun hosts them. Call
tiun.checkout({ productId }),tiun.login(), ortiun.start()to open them. - Methods before
readymay queue or no-op. Methods likecheckout/login/start/setContent/logoutalready callensureInitialized()andawait this.waitForReady()internally — no need to wrap them. - Unsubscribe handlers returned from
tiun.on(...)on component unmount to avoid stale listeners. Or calltiun.destroy()if the whole subtree is going away. - Live and sandbox are independent parallel environments. Each has its own snippet ID, products, product-ID prefix (
p-live-...vsp-test-...), API keys, and API base URL (https://api.tiun.livevshttps://api-sandbox.tiun.live). The SDK'ssandboxflag must match the dashboard view and the product-ID prefix, or checkout silently fails.localhostis blocked in live and enabled by default in sandbox. - No runtime product-list API. Products are configured in the tiun dashboard (
my.tiun.business) and referenced by hardcodedproductIdstrings. Do not invent methods liketiun.getProducts()or REST endpoints; direct users to the dashboard. - No webhooks. tiun does not emit webhooks. For backend integration, drive state from the JWT returned by
getUserVerificationToken()or thesessionIdfrompaywallHide. Do not invent webhook endpoints or event payloads. - Stay upstream-faithful. All code examples must match https://docs.tiun.io. If a pattern isn't documented upstream (custom SSR wiring, multi-env setups, backend SDKs in other languages, etc.), point the user at the upstream docs rather than inventing a snippet.
- Do not infer integration mode from the account's product inventory. Always confirm with the user (see "Step 0"). What the MCP reports is what exists; it does not report what the integrator wants to build.
- A one-time product ID in
productAccessis permanent. It enters at checkout and never leaves —event: 'update'never removes it. Do not generate expiry, renewal, cancellation, trial, or revocation handling for a one-time product; that is dead code for state that cannot occur. Renewal and cancellation belong to subscriptions only. Seereferences/one-time.md. - Do not wrap SDK methods to add
isInitialized/waitForReadyguards.tiun.checkout,tiun.login,tiun.start,tiun.setContent, andtiun.logoutalready do both internally. Wrapper helpers around these methods are noise. - Do not pass
baseUrltoinit(). It is an internal-only field reserved for tiun's own infrastructure. Usesandbox: truefor non-production environments; that is the only public environment switch. The SDK routes to the matching API host automatically. languageis a closed enum:'en' | 'de' | 'fr', case-insensitive. Unsupported values trigger a one-time console warning and fall back to'en'. Do not generate other values.- Do not branch app logic on
error.code. It's a string but there's no published enum; codes can change between SDK versions. Displayerr.messageto users and logerr.codefor support. - Write runtime config to files the bundler actually loads.
.env.exampleis documentation and is never evaluated. Vite loads.env/.env.local; Next.js loads.env.localand requires theNEXT_PUBLIC_*prefix for client-exposed values; Nuxt loads viaruntimeConfig.publicinnuxt.config.ts. Seereferences/installation.mdfor the per-host table.
Minimal working example
Three primitives — works in every supported environment. Adapt the reactive primitive (state hook, ref, signal, store, DOM update) to your stack.
import { tiun } from '@tiun/sdk';
tiun.init({ snippetId: 'YOUR_SNIPPET_ID', language: 'en' });
const off = tiun.on('userChange', ({ event, isAuthenticated, user }) => {
// push into your framework's reactive primitive
});
document.querySelector('#buy').onclick =
() => tiun.checkout({ productId: 'p-live-pro' });
// off(); tiun.destroy();
Full per-mode walkthroughs in references/subscriptions.md, references/one-time.md, and references/time-based.md. Per-framework adaptations in references/frameworks.md.
Decision cues
- User says "subscription", "recurring", "members", "paid account", "products and tiers" → subscription flow. Route to subscriptions.md.
- User says "buy once", "pay once", "one-time", "lifetime", "lifetime deal", "single payment", "unlock forever", "fixed fee", "perpetual license", "no subscription" → one-time flow. Route to one-time.md.
- User says "article paywall", "watch a video then pay", "session", "no account needed", "donation prompt", "first N seconds free" → time-based flow. Route to time-based.md.
- User says "videos behind a paywall", "premium content" (ambiguous) → ask which mode. Don't guess.
- User says "how do I get my agent to integrate tiun?" / "set this up with an AI coding agent" → point at the upstream Agent integration guide on docs.tiun.io and the
npx skills add tiun-app/skillsquickstart inreferences/mcp.md. - User asks "how do I list products?" / "get all products?" → products are configured in the dashboard at
my.tiun.business; there is no runtime product-list API. (The MCP exposes inventory to the agent for setup; this is not a runtime SDK feature.) - User mentions "verify on the backend", "protect API", "trust the client" → server verification (
X-TIUN-API-KEYheader; per-environment base URLs). - User mentions sandbox /
localhost/ "why won't it work locally" → confirmsandbox: true+ sandbox snippet ID +p-test-...product IDs (live is hard-blocked onlocalhost). - Errors like "overlay doesn't appear", "methods called before ready" → troubleshooting.