
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@sanity/template-validator
Advanced tools
A validation utility for Sanity.io template repositories. Use it as a dependency in your projects or as a GitHub Action to ensure your Sanity templates meet the required standards.
npm install @sanity/template-validator
# or
yarn add @sanity/template-validator
# or
pnpm add @sanity/template-validator
The package includes a CLI tool that can validate local directories:
# Install globally
npm install -g @sanity/template-validator
# Validate current directory
sanity-template-validate
# Validate specific directory
sanity-template-validate path/to/template
# Using Npx
npx @sanity/template-validator
The recommended way to use the validator in your template project is to add it as a dev dependency and create a validation script:
npm install --save-dev @sanity/template-validator
package.json:{
"scripts": {
"validate": "sanity-template-validate"
}
}
npm run validate
import {validateLocalTemplate, validateRemoteTemplate} from '@sanity/template-validator'
// Validate a local directory
async function validateLocal() {
const result = await validateLocalTemplate('/path/to/template')
if (result.isValid) {
console.log('Template is valid!')
} else {
console.error('Validation failed:', result.errors)
}
}
// Validate a remote repository
async function validateRemote() {
const baseUrl = 'https://raw.githubusercontent.com/owner/repo/branch'
const result = await validateRemoteTemplate(baseUrl)
if (result.isValid) {
console.log('Template is valid!')
} else {
console.error('Validation failed:', result.errors)
}
}
// Advanced usage with FileReader
import {LocalFileReader, getMonoRepo} from '@sanity/template-validator'
async function advancedValidation() {
const fileReader = new LocalFileReader('/path/to/template')
const packages = await getMonoRepo(fileReader)
// Use packages for further processing
}
name: Validate Template
on: push
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate Sanity Template
uses: sanity-io/template-validator@v2
validateLocalTemplateValidates a local Sanity template directory.
async function validateLocalTemplate(directory: string): Promise<ValidationResult>
Parameters:
directory: Path to the template directoryvalidateRemoteTemplateValidates a remote Sanity template repository.
async function validateRemoteTemplate(
baseUrl: string,
headers?: Record<string, string>,
): Promise<ValidationResult>
Parameters:
baseUrl: The base URL to the raw repository contentheaders: Custom headers for API requests (optional)Returns:
type ValidationResult = {
isValid: boolean
errors: string[]
}
The package provides two file reader classes for advanced usage:
class LocalFileReader implements FileReader {
constructor(basePath: string)
readFile(filePath: string): Promise<{exists: boolean; content: string}>
}
class GitHubFileReader implements FileReader {
constructor(baseUrl: string, headers?: Record<string, string>)
readFile(filePath: string): Promise<{exists: boolean; content: string}>
}
getMonoRepoHelper function to detect monorepo configuration.
async function getMonoRepo(fileReader: FileReader): Promise<string[] | undefined>
A valid Sanity template must meet the following criteria:
package.json with 'sanity' dependencysanity.config.js/ts/tsx and sanity.cli.js/ts.env.template, .env.example, .env.local.template, or .env.local.examplepackage.jsonSANITY_PROJECT_ID or SANITY_STUDIO_PROJECT_IDSANITY_DATASET or SANITY_STUDIO_DATASET| Input | Description | Required |
|---|---|---|
directory | The directory to validate. Use this if you have multiple templates in a repository. | No |
token | GitHub token for accessing and validating private repositories. | No |
Contributions are welcome! Please feel free to submit a Pull Request.
MIT © Sanity.io
FAQs
Sanity template validator for remote templates
We found that @sanity/template-validator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 112 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.