-
Notifications
You must be signed in to change notification settings - Fork 5
Add Sanity Plugin #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrewmumblebee
wants to merge
26
commits into
main
Choose a base branch
from
work/ah/sanity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
a114afb
Add a Sanity.io plugin
andrewmumblebee 604a72c
index sanity datasets using dependent imports
andrewmumblebee 3dd494a
Use scoped dataset datastreams
andrewmumblebee 1a2cbea
Add dataset stats dataStream
andrewmumblebee 6b65bc8
Update Sanity data stream tags
andrewmumblebee b255f92
Sanity plugin cleanup
andrewmumblebee b91fd2f
Reduce dataStreams down to useful ones
andrewmumblebee b1535bd
Show recently updated documents in the GROQ tile
andrewmumblebee 328dcfd
Show dataset limit usage on the Dataset dashboard
andrewmumblebee bb5984e
Add an Overview dashboard summarising the org
andrewmumblebee edcbddc
Explain the missing token when content tiles fail
andrewmumblebee 76ca3db
Index only projects with a configured token
andrewmumblebee 90c2cb9
Show every project's token status on the Overview
andrewmumblebee 860eb18
Keep description to one sentence
andrewmumblebee 8cabb6e
update readme
andrewmumblebee 86a8c84
Escape project names in token error messages
andrewmumblebee 951cd19
Derive dataset uid and displayName in the script
andrewmumblebee 6fccd09
Parse project createdAt as a date
andrewmumblebee ce72435
Describe the document type counts query
andrewmumblebee 54125d7
Match dashboard timeframes to their tiles
andrewmumblebee e7ab531
Give overview project tiles distinct titles
andrewmumblebee 9610e46
Give each dashboard tile a unique GUID
andrewmumblebee d3b5ed5
Document correct admin token creation steps
andrewmumblebee 705796a
Index members per project membership
andrewmumblebee d4e1471
Scope member roles to the imported project
andrewmumblebee 02103b7
Load error handling scripts from script files
andrewmumblebee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "steps": [ | ||
| { | ||
| "displayName": "Authenticate", | ||
| "dataStream": { | ||
| "name": "listProjects" | ||
| }, | ||
| "required": true, | ||
| "success": "Connected to the Sanity management API.", | ||
| "error": "Could not list projects. Check your Admin API token is valid and has access to your projects." | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| [ | ||
| { | ||
| "name": "Project", | ||
| "sourceType": "Project", | ||
| "icon": "layer-group", | ||
| "singular": "Project", | ||
| "plural": "Projects" | ||
| }, | ||
| { | ||
| "name": "Dataset", | ||
| "sourceType": "Dataset", | ||
| "icon": "layer-group", | ||
| "singular": "Dataset", | ||
| "plural": "Datasets" | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| "name": "allProjects", | ||
| "displayName": "All Projects", | ||
| "description": "Every project the admin token can see, flagging which have a content API token configured", | ||
| "tags": ["Project"], | ||
| "baseDataSourceName": "httpRequestUnscoped", | ||
| "config": { | ||
| "httpMethod": "get", | ||
| "paging": { | ||
| "mode": "none" | ||
| }, | ||
| "expandInnerObjects": false, | ||
| "endpointPath": "projects", | ||
| "getArgs": [], | ||
| "headers": [], | ||
| "postRequestScript": "allProjects.js" | ||
| }, | ||
| "metadata": [ | ||
| { | ||
| "name": "displayName", | ||
| "shape": "string", | ||
| "displayName": "Name", | ||
| "role": "label" | ||
| }, | ||
| { | ||
| "name": "tokenStatus", | ||
| "displayName": "Token Status", | ||
| "shape": [ | ||
| "state", | ||
| { | ||
| "map": { | ||
| "success": ["configured"], | ||
| "error": ["missing"] | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "name": "id", | ||
| "shape": "string", | ||
| "displayName": "Project ID" | ||
| } | ||
| ], | ||
| "timeframes": false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| { | ||
| "name": "customQuery", | ||
| "displayName": "Custom GROQ Query", | ||
| "description": "Run an arbitrary GROQ query against a dataset", | ||
| "tags": ["Documents"], | ||
| "baseDataSourceName": "httpRequestScopedSingle", | ||
| "matches": { | ||
| "sourceType": { | ||
| "type": "equals", | ||
| "value": "Dataset" | ||
| } | ||
| }, | ||
| "providesPluginDiagnostics": true, | ||
| "config": { | ||
| "baseUrl": "https://{{object.projectId}}.api.sanity.io/{{dataSource.apiVersion}}/", | ||
| "httpMethod": "get", | ||
| "errorHandling": { | ||
| "type": "script", | ||
| "script": "const hasToken = {{ !!((dataSource.projects || []).find(p => p.key === object.projectId) || {}).value }}; const apiMsg = data && (data.message || (typeof data.error === 'string' ? data.error : (data.error || {}).description)); result = hasToken ? (apiMsg || ('Request failed with HTTP ' + response.status)) : 'No API token is configured for project {{object.projectId}} (which this dataset belongs to). Add its Project ID and API token under Project API tokens in the Sanity data source settings to query it.';" | ||
| }, | ||
| "paging": { | ||
| "mode": "none" | ||
| }, | ||
| "expandInnerObjects": true, | ||
| "endpointPath": "data/query/{{object.datasetId}}", | ||
| "pathToData": "result", | ||
| "getArgs": [ | ||
| { | ||
| "key": "query", | ||
| "value": "{{query}}" | ||
| }, | ||
| { | ||
| "key": "perspective", | ||
| "value": "{{perspective}}" | ||
| } | ||
| ], | ||
| "headers": [ | ||
| { | ||
| "key": "Authorization", | ||
| "value": "Bearer {{ ((dataSource.projects || []).find(p => p.key === object.projectId) || {}).value }}" | ||
| } | ||
| ] | ||
| }, | ||
| "ui": [ | ||
| { | ||
| "type": "code", | ||
| "name": "query", | ||
| "language": "groq", | ||
| "label": "GROQ query", | ||
| "defaultValue": "*[ !(_id in path(\"_.**\")) ] | order(_updatedAt desc) [0...20] {_id, _type, _updatedAt}", | ||
| "validation": { "required": true }, | ||
| "help": "See [GROQ query cheat sheet](https://www.sanity.io/docs/content-lake/query-cheat-sheet) for patterns" | ||
| }, | ||
| { | ||
| "type": "switch", | ||
| "name": "perspective", | ||
| "label": "Perspective", | ||
| "defaultValue": "published", | ||
| "options": [ | ||
| { "value": "published", "label": "Published" }, | ||
| { "value": "drafts", "label": "Drafts" }, | ||
| { "value": "raw", "label": "Raw" } | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": [{ "pattern": ".*" }], | ||
| "timeframes": false, | ||
| "manualConfigApply": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| { | ||
| "name": "datasetStats", | ||
| "displayName": "Dataset Stats", | ||
| "description": "Get stats on how close to usage limits this dataset is", | ||
| "tags": ["Analytics"], | ||
| "baseDataSourceName": "httpRequestScopedSingle", | ||
| "matches": { | ||
| "sourceType": { | ||
| "type": "equals", | ||
| "value": "Dataset" | ||
| } | ||
| }, | ||
| "config": { | ||
| "baseUrl": "https://{{object.projectId}}.api.sanity.io/v1/", | ||
| "httpMethod": "get", | ||
| "errorHandling": { | ||
| "type": "script", | ||
| "script": "const hasToken = {{ !!((dataSource.projects || []).find(p => p.key === object.projectId) || {}).value }}; const apiMsg = data && (data.message || (typeof data.error === 'string' ? data.error : (data.error || {}).description)); result = hasToken ? (apiMsg || ('Request failed with HTTP ' + response.status)) : 'No API token is configured for project {{object.projectId}} (which this dataset belongs to). Add its Project ID and API token under Project API tokens in the Sanity data source settings to see its usage stats.';" | ||
| }, | ||
| "paging": { | ||
| "mode": "none" | ||
| }, | ||
| "endpointPath": "data/stats/{{object.datasetId}}", | ||
| "getArgs": [], | ||
| "headers": [ | ||
| { | ||
| "key": "Authorization", | ||
| "value": "Bearer {{ ((dataSource.projects || []).find(p => p.key === object.projectId) || {}).value }}" | ||
| } | ||
| ], | ||
| "expandInnerObjects": true, | ||
| "postRequestScript": "datasetStats.js" | ||
| }, | ||
| "metadata": [ | ||
| { | ||
| "name": "dataset", | ||
| "displayName": "Dataset", | ||
| "shape": "string", | ||
| "role": "label" | ||
| }, | ||
| { | ||
| "name": "documentsPctOfLimit", | ||
| "displayName": "Documents (% of limit)", | ||
| "shape": "percent", | ||
| "role": "value" | ||
| }, | ||
| { | ||
| "name": "fieldsPctOfLimit", | ||
| "displayName": "Fields (% of limit)", | ||
| "shape": "percent" | ||
| }, | ||
| { | ||
| "name": "jsonSizePctOfLimit", | ||
| "displayName": "JSON Size (% of limit)", | ||
| "shape": "percent" | ||
| }, | ||
| { | ||
| "name": "releasesPctOfLimit", | ||
| "displayName": "Releases (% of limit)", | ||
| "shape": "percent" | ||
| }, | ||
| { | ||
| "name": "documents.count.value", | ||
| "displayName": "Documents", | ||
| "shape": "number" | ||
| }, | ||
| { | ||
| "name": "documents.count.limit", | ||
| "displayName": "Document Limit", | ||
| "shape": "number" | ||
| }, | ||
| { | ||
| "name": "fields.count.value", | ||
| "displayName": "Fields", | ||
| "shape": "number" | ||
| }, | ||
| { | ||
| "name": "fields.count.limit", | ||
| "displayName": "Field Limit", | ||
| "shape": "number" | ||
| }, | ||
| { | ||
| "name": "documents.jsonSizeSum.value", | ||
| "displayName": "JSON Size", | ||
| "shape": "bytes" | ||
| }, | ||
| { | ||
| "name": "documents.jsonSizeSum.limit", | ||
| "displayName": "JSON Size Limit", | ||
| "shape": "bytes" | ||
| }, | ||
| { | ||
| "pattern": ".*" | ||
| } | ||
| ], | ||
| "timeframes": false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| { | ||
| "name": "datasets", | ||
| "displayName": "Datasets", | ||
| "description": "Lists the datasets in a project, with their access-control mode", | ||
| "tags": ["Datasets"], | ||
| "baseDataSourceName": "httpRequestScopedSingle", | ||
| "matches": { | ||
| "sourceType": { | ||
| "type": "equals", | ||
| "value": "Project" | ||
| } | ||
| }, | ||
| "config": { | ||
| "httpMethod": "get", | ||
| "errorHandling": { | ||
| "type": "script", | ||
| "script": "errorHandling/datasets.js" | ||
| }, | ||
| "paging": { | ||
| "mode": "none" | ||
| }, | ||
| "expandInnerObjects": true, | ||
| "endpointPath": "projects/{{object.rawId}}/datasets", | ||
| "getArgs": [], | ||
| "postRequestScript": "datasets.js", | ||
| "headers": [ | ||
| { | ||
| "key": "Authorization", | ||
| "value": "Bearer {{ ((dataSource.projects || []).find(p => p.key === object.rawId) || {}).value }}" | ||
| } | ||
| ] | ||
| }, | ||
| "metadata": [ | ||
| { | ||
| "name": "projectId", | ||
| "displayName": "Project ID", | ||
| "shape": "string", | ||
| "visible": false | ||
| }, | ||
| { | ||
| "name": "datasetId", | ||
| "shape": "string", | ||
| "displayName": "Dataset", | ||
| "role": "label" | ||
| }, | ||
| { | ||
| "name": "aclMode", | ||
| "shape": "string", | ||
| "displayName": "Access mode" | ||
| }, | ||
| { | ||
| "name": "createdAt", | ||
| "shape": "date", | ||
| "displayName": "Created At" | ||
| }, | ||
| { | ||
| "name": "createdByUserId", | ||
| "shape": "string", | ||
| "displayName": "Created By User Id" | ||
| }, | ||
| { | ||
| "name": "projectName", | ||
| "displayName": "Project Name", | ||
| "shape": "string" | ||
| }, | ||
| { | ||
| "name": "uid", | ||
| "displayName": "uid", | ||
| "shape": "string", | ||
| "visible": false | ||
| }, | ||
| { | ||
| "name": "displayName", | ||
| "displayName": "Display Name", | ||
| "shape": "string", | ||
| "visible": false | ||
|
andrewmumblebee marked this conversation as resolved.
|
||
| } | ||
| ], | ||
| "timeframes": false | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| { | ||
| "name": "listProjects", | ||
| "displayName": "Projects", | ||
| "description": "Lists the projects that have a content API token configured", | ||
| "tags": ["Project"], | ||
| "baseDataSourceName": "httpRequestUnscoped", | ||
| "config": { | ||
| "httpMethod": "get", | ||
| "paging": { | ||
| "mode": "none" | ||
| }, | ||
| "expandInnerObjects": false, | ||
| "endpointPath": "projects", | ||
| "getArgs": [], | ||
| "headers": [], | ||
| "postRequestScript": "listProjects.js" | ||
| }, | ||
| "metadata": [ | ||
| { | ||
| "name": "id", | ||
| "shape": "string", | ||
| "displayName": "Project ID" | ||
| }, | ||
| { | ||
| "name": "displayName", | ||
| "shape": "string", | ||
| "displayName": "Name" | ||
| }, | ||
| { | ||
| "name": "organizationId", | ||
| "shape": "string", | ||
| "displayName": "Organization ID" | ||
| }, | ||
| { | ||
| "name": "studioHost", | ||
| "shape": "string", | ||
| "displayName": "Studio host" | ||
| }, | ||
| { | ||
| "name": "createdAt", | ||
| "shape": "date", | ||
| "displayName": "Created" | ||
|
andrewmumblebee marked this conversation as resolved.
|
||
| }, | ||
| { | ||
| "pattern": ".*" | ||
| } | ||
| ], | ||
| "timeframes": false, | ||
| "visibility": { | ||
| "type": "hidden" | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.