@themodcraft/cms
v1.2.0
Published
Auth-agnostic CMS runtime for React projects. It provides page models, a transport-driven client, a React provider, hooks, and a registry renderer.
Readme
@themodcraft/cms
Auth-agnostic CMS runtime for React projects. It provides page models, a transport-driven client, a React provider, hooks, and a registry renderer.
The package contains no authentication implementation. The host application owns authentication and injects a CmsTransport.
import { CmsClient, CmsPageRenderer, CmsProvider, useCmsPage } from "@themodcraft/cms";
import { TmcLicenseProvider } from "@themodcraft/license-client";
const client = new CmsClient({
locale: "en",
siteId: "example",
transport: (path, init) => authenticatedFetch(`https://api.example.com${path}`, init),
});
function Page() {
const { page } = useCmsPage("/home");
return page ? <CmsPageRenderer content={page.content} registry={registry} /> : null;
}
export function App() {
return (
<TmcLicenseProvider
apiEndpoint="https://licenses.themodcraft.net/v1/license/resolve"
licenseKey={process.env.NEXT_PUBLIC_TMC_LICENSE_KEY}
packageName="@themodcraft/cms"
projectId="example"
>
<CmsProvider client={client}>
<Page />
</CmsProvider>
</TmcLicenseProvider>
);
}The active license must include the cms entitlement. Non-React and server-side consumers must resolve a license and call configureTmcLicense(snapshot) before invoking the client.
