@fytkit/sdk
v0.4.0
Published
Vanilla TypeScript SDK for fytkit's public API
Downloads
879
Readme
@fytkit/sdk
Vanilla TypeScript SDK for the fytkit public API. Build a custom trainee-facing app on top of your fytkit programs, workouts, recipes, and Mux-protected video.
v0.1.x is a pre-1.0 release line. The shape of every exported type is documented in
etc/sdk.api.md; breaking changes are recorded inCHANGELOG.md.
Install
pnpm add @fytkit/sdk @orpc/client
# or
npm install @fytkit/sdk @orpc/clientPin to an exact version while the SDK is pre-1.0:
pnpm add @fytkit/[email protected] @orpc/clientFull install + version-pinning guidance: docs/developer/installation.md. Semver policy: docs/developer/concepts/versioning.md.
30-second quickstart
import { createFytkitClient } from "@fytkit/sdk";
const fytkit = createFytkitClient({
clientId: "fk_app_xxxxxxxxxxxxxxxxx", // from /dashboard/developer
});
// Sign a trainee in (your own auth UI calls this)
const session = await fytkit.auth.signIn({
email: "[email protected]",
password: "their-password",
});
// Fetch their workouts
const { items } = await fytkit.workouts.list({ limit: 20 });
// Subscribe to auth state (e.g. to redirect on sign-out)
const off = fytkit.auth.onAuthStateChange((state) => {
if (state.type === "signed_out") window.location.assign("/sign-in");
});
// Sign out — revokes the server-side session and clears local storage
await fytkit.auth.signOut();
off();What's included in this preview
auth.signUp/signIn/signOut/getSession/onAuthStateChangeauth.requestPasswordReset/confirmPasswordReset/confirmEmail- Data namespaces:
workouts,programs,recipes,nutrition,articles,enrollments,sessionLogs,progression,media,appConfig,subscription - Automatic header injection (
X-Fytkit-Client-Id,Authorization: Bearer …) - Proactive refresh ~60 s before token expiry + reactive 401 retry
- Pluggable token storage (
localStoragedefault, in-memory + cookie for SSR)
Storage trade-off
Access tokens land in localStorage by default, namespaced by clientId. Any script running on your origin can read them — ship a strict CSP and treat the SDK like any other auth-bearing dependency. Token TTL is ~15 minutes and refresh requires the server, so a leaked token has a short blast radius.
Use createMemoryStorageAdapter() for SSR + tests.
Coming next
@fytkit/react— hooks +<FytkitVideo>examples/sdk-react— runnable sample appdocs/sdk/quickstart.md— full guide
