@tyashin/suite-client
v0.0.1
Published
Shared client for Tyashin suite SSO + billing: auth introspection, entitlements, pricing, checkout. Browser, Worker, and React.
Readme
@tyashin/suite-client
Shared client for the Tyashin suite. One dependency gives any Tyashin app (invoice, linkedin, platform, future tools) single sign-on and centralized billing against accounts.tyashin.com — no per-app auth or billing code.
Install
npm install @tyashin/suite-clientBrowser
import { SuiteClient } from "@tyashin/suite-client";
const client = new SuiteClient({ product: "invoice-tyashin" });
const session = await client.introspect(); // null when signed out
if (!session) location.href = client.loginUrl(location.href);React
import { SuiteClient } from "@tyashin/suite-client";
import { TyashinSuiteProvider, useTyashinUser, useEntitlement } from "@tyashin/suite-client/react";
const client = new SuiteClient({ product: "invoice-tyashin" });
function App() {
return (
<TyashinSuiteProvider client={client}>
<Dashboard />
</TyashinSuiteProvider>
);
}
function Dashboard() {
const { loading, isAuthenticated } = useTyashinUser();
const { needsOnboarding, plan } = useEntitlement();
if (loading) return null;
if (!isAuthenticated) { /* redirect to client.loginUrl(...) */ }
if (needsOnboarding) return <StartSubscription />; // post-signup journey
return <TheApp plan={plan} />;
}Server / Cloudflare Worker
import { requireEntitlement } from "@tyashin/suite-client/server";
const session = await requireEntitlement(request, {
product: "invoice-tyashin",
allowFree: true, // free-tier users pass; app enforces its own free limits
});
// session.account, session.entitlements["invoice-tyashin"]SSO model
- Sign-in at
accounts.tyashin.comsets atyashin_sessioncookie scoped toDomain=.tyashin.com, so it is sent to every*.tyashin.comsubdomain. introspect()validates that cookie and returns the account + per-product entitlements. A product missing fromentitlementsmeans the user has not started there yet → render that product's onboarding.- Currency is detected from the visitor's country and locked at first
payment (
account.currencyLocked).
