doc-manager

API Reference

Everything exported by sanity-plugin-document-manager.

documentManager(config?)

The main export. Call it with an optional config object and pass the result to your Sanity plugins array. It returns a fully resolved Sanity plugin.

Exports
import { documentManager } from 'sanity-plugin-document-manager'
import type { DocumentManagerPluginConfig, DocEntry } from 'sanity-plugin-document-manager'

// Main export — returns a Sanity plugin instance
const plugin = documentManager(config?: DocumentManagerPluginConfig)

DocumentManagerPluginConfig

The configuration interface accepted by documentManager(). All fields are optional.

Type
interface DocumentManagerPluginConfig {
  /** Tool title in the Studio navbar. @default 'Document Manager' */
  title?: string

  /** Tool icon component. @default DatabaseIcon */
  icon?: React.ComponentType

  /** Documents per page. @default 50 */
  pageSize?: number

  /** Sanity API version. @default '2024-06-01' */
  apiVersion?: string

  /** Document types to exclude from the filter. @default [] */
  excludeTypes?: string[]

  /** Pre-select a dataset on load. */
  defaultDataset?: string
}

DocEntry

The shape of a single document entry as returned by the GROQ query inside the tool. Exported for convenience if you want to extend or wrap the plugin.

Type
interface DocEntry {
  _id: string
  _type: string
  _createdAt: string   // ISO 8601 date string
  _updatedAt: string   // ISO 8601 date string
  title?: string       // Document title field (if present)
  name?: string        // Document name field (if present)
}

GROQ Query

The plugin fetches documents using this GROQ query internally:

GROQ
*[!(_id in path("_.**"))] | order(_updatedAt desc) {
  _id, _type, _createdAt, _updatedAt, title, name
}

This excludes all internal Sanity system documents (those with IDs starting with _.) and orders results by last update time.

Sanity API Endpoints

The plugin makes two types of API calls:

Both require a Bearer token with read+write access, provided via the SANITY_STUDIO_WRITE_TOKEN environment variable.