@contfu/sanity
v0.2.2
Published
Post your Sanity Studio schema to Contfu so Contfu can use the Studio schema as the authoritative collection schema instead of sampling Content Lake documents. Collections without a pushed Studio schema use item-derived sampling until a push arrives.
Downloads
504
Readme
@contfu/sanity
Post your Sanity Studio schema to Contfu so Contfu can use the Studio schema as the authoritative collection schema instead of sampling Content Lake documents. Collections without a pushed Studio schema use item-derived sampling until a push arrives.
Install
bun add @contfu/sanity@contfu/sanity consumes your Studio schemaTypes array without importing Sanity at runtime.
Usage
Given a Sanity Studio schema setup like this:
// schemaTypes/postType.ts
import { defineField, defineType } from "sanity";
export const postType = defineType({
name: "post",
title: "Post",
type: "document",
fields: [
defineField({ name: "title", type: "string" }),
defineField({ name: "slug", type: "slug", options: { source: "title" } }),
defineField({ name: "publishedAt", type: "datetime" }),
defineField({ name: "image", type: "image" }),
defineField({ name: "body", type: "array", of: [{ type: "block" }] }),
],
});// schemaTypes/index.ts
import { postType } from "./postType";
export const schemaTypes = [postType];Call updateContfuSchema from sanity.cli.ts so the schema sync runs server-side when the Sanity CLI starts:
import { updateContfuSchema } from "@contfu/sanity";
import { defineCliConfig } from "sanity/cli";
import { schemaTypes } from "./schemaTypes";
await updateContfuSchema({
webhookSecret: process.env.CONTFU_SANITY_WEBHOOK_SECRET!,
dataset: process.env.SANITY_STUDIO_DATASET ?? "production",
schemaTypes,
});
export default defineCliConfig({
api: {
projectId: process.env.SANITY_STUDIO_PROJECT_ID!,
dataset: process.env.SANITY_STUDIO_DATASET ?? "production",
},
});