Blueprint configuration reference
Reference documentation for the Blueprint configuration files.
The Blueprints configuration file defines resources, like Functions, for deployment to Sanity's infrastructure.
Interact with Blueprints by using the npx sanity blueprints CLI command.
The top-level of the blueprint configuration file contains the following properties:
RequiredblueprintVersionstring
Defines the version of the Blueprints specification to use when parsing the configuration. Uses the
YYYY-MM-DDformat.Requiredresourcesarray
An array of Sanity resources. Right now this is limited to Function resources, but will expand in the future.
Resources
The following properties are shared across all resources. Additional resource-specific properties follow in the sections below.
Requirednamestring
A unique function name. Must be an alphanumeric string that can contain dashes or underscores.
Requiredtypestring
A resource type. For Sanity resources, this is made up of the
sanitynamespace, category, subcategory, and resource types separated by single periods. For example:sanity.function.documentorsanity.function.media-library.asset.
Functions
In addition to the required common resource properties above, functions also contain the following properties.
srcstring
The path, relative to the blueprint configuration file, of the individual function directory. Will be inferred from the name if omitted. For example,
functions/myFunction.typestring
Specifies the Function type. Supported Function types are:
sanity.function.document: this Function will react to changes in your dataset documents, like when a document is created, updated or deleted.sanity.function.media-library.asset: this Function will react to changes in your Media Library, like when an asset is uploaded, updated or deleted. Note that your plan must have access to the Media Library to use this Function type.
eventobject
Configuration options for the triggering event. See the
eventproperties section below for details.timeoutinteger
The max invocation time, in seconds, of the function.
- Default: 10
- Minimum: 1
- Maximum: 900
memoryinteger
Sets the max memory allocation, in GBs.
- Default: 1
- Min: 1
- Max: 10
envobject
Set environment variables for the function. The
envobject accepts custom keys with string values. This is an alternative approach to using thesanity functions envCLI command. Note: Setting environment variables in this manner is only additive. It can create/update variables, but in order to remove an environment variable you must use thesanity functions env removecommand.transpileboolean
If false, you will need to transpile any TypeScript code yourself and output the results to the individual function's
.builddirectory. Defaults totrue.autoResolveDepsboolean
If
false, disables the automatic dependency resolution. Defaults totrue.
event properties
onstring
Defines the types of events that trigger your Function. You can include more than one, but you cannot combine
publishwith other events. The options are:create: Activates when a document is created. Defaults toincludeDrafts: falseandincludeAllVersions: false.delete: Activates when a document is deleted. Defaults toincludeDrafts: falseandincludeAllVersions: false.update: Activates when a document is updated. Defaults toincludeDrafts: falseandincludeAllVersions: false.publish: Activates when a document is published. Essentially a shorthand for:create+update. Defaults toincludeDrafts: falseandincludeAllVersions: true.
These actions trigger on individual documents with unique
_idvalues.filterstring
A valid GROQ filter. Learn more about GROQ Filters.
Only include the contents of the filter, not any other surrounding syntax.
✅ Do this:
_type == "article"❌ Not this:
[_type == "article"]projectionstring
A valid GROQ projection. Example:
{title, _id, slug}includeDraftsboolean
Determines whether the event trigger should take into account events happening on draft documents. Defaults to
false. Please note that turning this on by setting it totruecan quickly have your Function hit rate limits.Only applies to the following Function types:
sanity.function.documentsanity.function.media-library.asset
includeAllVersionsboolean
Determines whether the event trigger should take into account events happening on version documents (documents that are part of Content Releases). Defaults to
false. Please note that turning this on by setting it totruecan quickly have your Function hit rate limits.Only applies to the following Function types:
sanity.function.document
resourceobject
Defines the resource from which changes will trigger your function. If defined, you must specify a
typeandid. If not set, the resource will default to all datasets for the Blueprint's linked project.Accepted values depend on what
typeof Function you are defining:- Optional if your Function
typeissanity.function.document.- If defined, the
resource.typemust bedatasetandresource.idis specified in the form<projectId>.<datasetName>. - You can set
<datasetName>to*to signify "all datasets in the project with ID<projectId>."
- If defined, the
- Required if your Function
typeissanity.function.media-library.*. Theresource.typemust bemedia-libraryandresource.idshould equal your Media Library ID.
- Optional if your Function
Example
import {defineBlueprint, defineDocumentFunction, defineMediaLibraryAssetFunction} from '@sanity/blueprints'
export default defineBlueprint({
resources: [
defineDocumentFunction({
name: "log-event",
event: {
on: ["update"],
filter: "_type == 'post'",
projection: "{title, _id, _type}",
resource: {
type: 'dataset',
id: 'myProject.myDataset'
}
},
env: {
example: 'value'
}
}),
// Helper introduced in @sanity/blueprints v0.4.0
defineMediaLibraryAssetFunction({
name: "image-title-updated",
event: {
on: ["update"],
filter: "delta::changedAny(title)",
projection: "{title, _id, versions}",
resource: {
type: 'media-library',
id: 'mlAbcd1234'
}
}
})
]
}){
"blueprintVersion": "2024-10-01",
"resources": [
{
"name": "log-event",
"src": "functions/log-event",
"type": "sanity.function.document",
"event": {
"on": [
"update"
],
"filter": "_type == 'post'",
"projection": "{title, _id, _type}",
"resource": {
"type": "dataset",
"id": "myProject.myDataset"
}
},
"env": {
"example": "value"
}
},
{
"name": "image-created",
"src": "functions/image-created",
"type": "sanity.function.media-library.asset",
"event": {
"on": [
"create"
],
"filter": "assetType == 'sanity.imageAsset'",
"projection": "{title, _id, versions}",
"resource": {
"type": "media-library",
"id": "mlAbcd1234"
}
}
}
]
}TypeScript / JavaScript helpers
You can configure Blueprints with TypeScript and JavaScript. If you select either during sanity blueprints init, the CLI prompts you to install the @sanity/blueprints package. You can also add it to an existing project by adding it to your Blueprints-level project directory.
npm i @sanity/blueprintspnpm add @sanity/blueprintsThe helpers provide defaults and allow you to omit some configuration options. You can always override these defaults by explicitly setting the values as you would with the JSON format.
Was this page helpful?