@robinpath/sanity
0.1.1Node.jsPublicSanity module for RobinPath.
Sanity
Sanity module for RobinPath.
Package: @robinpath/sanity | Category: Cms | Type: Integration
Authentication
sanity.setCredentials "your-credentials"
Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.
Use Cases
Use the sanity module when you need to:
- query -- Use
sanity.queryto perform this operation - getDocument -- Use
sanity.getDocumentto perform this operation - createDocument -- Use
sanity.createDocumentto perform this operation - createOrReplace -- Use
sanity.createOrReplaceto perform this operation - patch -- Use
sanity.patchto perform this operation
Quick Reference
| Function | Description | Returns |
|---|---|---|
setCredentials | Configure sanity credentials. | object |
query | query | object |
getDocument | getDocument | object |
createDocument | createDocument | object |
createOrReplace | createOrReplace | object |
patch | patch | object |
deleteDocument | deleteDocument | object |
uploadAsset | uploadAsset | object |
getAsset | getAsset | object |
listDatasets | listDatasets | object |
createDataset | createDataset | object |
deleteDataset | deleteDataset | object |
mutate | mutate | object |
listDocumentsByType | listDocumentsByType | object |
getProject | getProject | object |
exportDataset | exportDataset | object |
importDataset | importDataset | object |
Functions
setCredentials
Configure sanity credentials.
Module: sanity | Returns: object -- API response.
sanity.setCredentials
| Parameter | Type | Required | Description |
|---|---|---|---|
projectId | string | Yes | projectId |
dataset | string | Yes | dataset |
token | string | Yes | token |
query
query
Module: sanity | Returns: object -- API response.
sanity.query
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
getDocument
getDocument
Module: sanity | Returns: object -- API response.
sanity.getDocument
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
createDocument
createDocument
Module: sanity | Returns: object -- API response.
sanity.createDocument
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
createOrReplace
createOrReplace
Module: sanity | Returns: object -- API response.
sanity.createOrReplace
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
patch
patch
Module: sanity | Returns: object -- API response.
sanity.patch
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
deleteDocument
deleteDocument
Module: sanity | Returns: object -- API response.
sanity.deleteDocument
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
uploadAsset
uploadAsset
Module: sanity | Returns: object -- API response.
sanity.uploadAsset
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
getAsset
getAsset
Module: sanity | Returns: object -- API response.
sanity.getAsset
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
listDatasets
listDatasets
Module: sanity | Returns: object -- API response.
sanity.listDatasets
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
createDataset
createDataset
Module: sanity | Returns: object -- API response.
sanity.createDataset
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
deleteDataset
deleteDataset
Module: sanity | Returns: object -- API response.
sanity.deleteDataset
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
mutate
mutate
Module: sanity | Returns: object -- API response.
sanity.mutate
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
listDocumentsByType
listDocumentsByType
Module: sanity | Returns: object -- API response.
sanity.listDocumentsByType
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
getProject
getProject
Module: sanity | Returns: object -- API response.
sanity.getProject
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
exportDataset
exportDataset
Module: sanity | Returns: object -- API response.
sanity.exportDataset
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
importDataset
importDataset
Module: sanity | Returns: object -- API response.
sanity.importDataset
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | No | Input parameter |
Error Handling
All functions throw on failure. Common errors:
| Error | Cause |
|---|---|
Sanity API error (${res.status}): ${t} | Check the error message for details |
sanity.setCredentials requires projectId, dataset, token. | Check the error message for details |
sanity.patch requires an ID. | Check the error message for details |
sanity.deleteDocument requires an ID. | Check the error message for details |
sanity.deleteDataset requires an ID. | Check the error message for details |
Sanity: "..." not configured. Call sanity.setCredentials first. | Check the error message for details |
@desc "Query and validate result"
do
set $result as sanity.query
if $result != null
print "Success"
else
print "No result"
end
enddo
Recipes
1. List and iterate Document
Retrieve all items and loop through them.
@desc "Setup authentication"
do
sanity.setCredentials $token
enddo
@desc "Get document and iterate results"
do
set $result as sanity.getDocument
each $item in $result
print $item
end
enddo
2. Create a new item with createDocument
Create a new resource and capture the result.
@desc "Setup authentication"
do
sanity.setCredentials $token
enddo
@desc "Create document"
do
set $result as sanity.createDocument
print "Created: " + $result
enddo
3. Check before creating
List existing items and only create if needed.
@desc "Setup authentication"
do
sanity.setCredentials $token
enddo
@desc "Get document and create document"
do
set $existing as sanity.getDocument
if $existing == null
sanity.createDocument
print "Item created"
else
print "Item already exists"
end
enddo
4. Multi-step Sanity workflow
Chain multiple sanity operations together.
@desc "Setup authentication"
do
sanity.setCredentials $token
enddo
@desc "Query, get document, and more"
do
set $r_query as sanity.query
set $r_getDocument as sanity.getDocument
set $r_createDocument as sanity.createDocument
print "All operations complete"
enddo
5. Safe query with validation
Check results before proceeding.
@desc "Setup authentication"
do
sanity.setCredentials $token
enddo
@desc "Query and validate result"
do
set $result as sanity.query
if $result != null
print "Success: " + $result
else
print "Operation returned no data"
end
enddo
Related Modules
- json -- JSON module for complementary functionality
Versions (1)
| Version | Tag | Published |
|---|---|---|
| 0.1.1 | latest | 1 months ago |
Related Modules
ftp
JS@robinpathv0.1.3
FTP and SFTP file transfer operations
http
JS@robinpathv0.1.3
HTTP server for RobinPath scripts. Register routes with static responses (JSON, HTML, files), enable CORS, serve static directories. No callbacks needed.
form
JS@robinpathv0.2.1
Declarative form builder for RobinPath scripts � define fields inline, generate schemas, validate submissions
api
JS@robinpathv0.1.2
HTTP client for making requests to external APIs with profiles, auth, download/upload, and auto-JSON parsing
$ robinpath add @robinpath/sanity
