Skip to content

Commit d450360

Browse files
Sanity plugin cleanup
1 parent aa9ab20 commit d450360

16 files changed

Lines changed: 125 additions & 77 deletions
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
[
22
{
3-
"name": "Sanity Project",
4-
"sourceType": "Sanity Project",
3+
"name": "Project",
4+
"sourceType": "Project",
55
"icon": "layer-group",
6-
"singular": "Sanity Project",
7-
"plural": "Sanity Projects"
6+
"singular": "Project",
7+
"plural": "Projects"
8+
},
9+
{
10+
"name": "Dataset",
11+
"sourceType": "Dataset",
12+
"icon": "layer-group",
13+
"singular": "Dataset",
14+
"plural": "Datasets"
815
}
916
]

plugins/Sanity/v1/dataStreams/changeHistory.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "changeHistory",
33
"displayName": "Change History",
4-
"description": "Transaction history for a Sanity dataset — every content change with timestamp, author, and affected document count",
4+
"description": "Transaction history for a dataset — every content change with timestamp, author, and affected document count",
55
"tags": ["Documents"],
66
"baseDataSourceName": "httpRequestScopedSingle",
77
"matches": {
88
"sourceType": {
99
"type": "equals",
10-
"value": "Sanity Dataset"
10+
"value": "Dataset"
1111
}
1212
},
1313
"config": {
@@ -57,6 +57,9 @@
5757
"displayName": "Documents Changed",
5858
"shape": "number",
5959
"role": "value"
60+
},
61+
{
62+
"pattern": ".*"
6063
}
6164
],
6265
"timeframes": [

plugins/Sanity/v1/dataStreams/customQuery.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "customQuery",
33
"displayName": "Custom GROQ Query",
4-
"description": "Run an arbitrary GROQ query against a Sanity dataset",
4+
"description": "Run an arbitrary GROQ query against a dataset",
55
"tags": ["Documents"],
66
"baseDataSourceName": "httpRequestScopedSingle",
77
"matches": {
88
"sourceType": {
99
"type": "equals",
10-
"value": "Sanity Dataset"
10+
"value": "Dataset"
1111
}
1212
},
1313
"providesPluginDiagnostics": true,

plugins/Sanity/v1/dataStreams/datasetStats.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"matches": {
88
"sourceType": {
99
"type": "equals",
10-
"value": "Sanity Dataset"
10+
"value": "Dataset"
1111
}
1212
},
1313
"providesPluginDiagnostics": true,

plugins/Sanity/v1/dataStreams/datasets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "datasets",
33
"displayName": "Datasets",
4-
"description": "Lists the datasets in a Sanity project, with their access-control mode.",
4+
"description": "Lists the datasets in a project, with their access-control mode.",
55
"tags": ["Datasets"],
66
"baseDataSourceName": "httpRequestScopedSingle",
77
"matches": {
88
"sourceType": {
99
"type": "equals",
10-
"value": "Sanity Project"
10+
"value": "Project"
1111
}
1212
},
1313
"config": {

plugins/Sanity/v1/dataStreams/documentTypeCounts.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "documentTypeCounts",
33
"displayName": "Document Type Counts",
4-
"description": "Count of published documents per type in a Sanity dataset",
4+
"description": "Count of published documents per type in a dataset",
55
"tags": ["Documents"],
66
"baseDataSourceName": "httpRequestScopedSingle",
77
"matches": {
88
"sourceType": {
99
"type": "equals",
10-
"value": "Sanity Dataset"
10+
"value": "Dataset"
1111
}
1212
},
1313
"config": {

plugins/Sanity/v1/dataStreams/listProjects.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "listProjects",
33
"displayName": "Projects",
4-
"description": "Lists all Sanity projects the admin token can access. Backs config validation and the project import.",
4+
"description": "Lists all projects the admin token can access. Backs config validation and the project import.",
55
"tags": ["Project"],
66
"baseDataSourceName": "httpRequestUnscoped",
77
"config": {

plugins/Sanity/v1/dataStreams/members.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "members",
33
"displayName": "Members",
4-
"description": "People with access to a Sanity project, with their roles",
4+
"description": "People with access to a project, with their roles",
55
"tags": ["Members"],
66
"baseDataSourceName": "httpRequestScopedSingle",
77
"matches": {
88
"sourceType": {
99
"type": "equals",
10-
"value": "Sanity Project"
10+
"value": "Project"
1111
}
1212
},
1313
"config": {
@@ -56,6 +56,19 @@
5656
"displayName": "Roles",
5757
"shape": "string"
5858
},
59+
{
60+
"name": "memberships.0.resourceId",
61+
"displayName": "projectId",
62+
"shape": "string",
63+
"sourceType": "Project",
64+
"visible": false
65+
},
66+
{
67+
"name": "project",
68+
"displayName": "Project",
69+
"sourceId": "memberships.0.resourceId",
70+
"objectPropertyPath": "name"
71+
},
5972
{
6073
"pattern": ".*"
6174
}

plugins/Sanity/v1/dataStreams/scripts/changeHistory.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,26 @@
22
// The endpoint returns one JSON object per line (not a JSON array).
33
// data will be null/undefined; raw text is in response.body.
44

5-
const body = response.body;
6-
7-
// Defensive: if the handler somehow parsed it already, handle that case
8-
if (Array.isArray(body)) {
9-
result = body.map(function(tx) {
5+
result = response.body
6+
.split("\n")
7+
.map(function (line) {
8+
return line.trim();
9+
})
10+
.filter(function (line) {
11+
return line.length > 0;
12+
})
13+
.map(function (line) {
14+
return JSON.parse(line);
15+
})
16+
.map(function (tx) {
1017
return {
18+
...tx,
1119
timestamp: tx.timestamp,
1220
transactionId: tx.id,
1321
author: tx.author,
14-
documentCount: Array.isArray(tx.documentIDs) ? tx.documentIDs.length : 0
22+
documentCount: Array.isArray(tx.documentIDs)
23+
? tx.documentIDs.length
24+
: 0,
1525
};
1626
});
17-
} else if (typeof body === 'string') {
18-
result = body
19-
.split('\n')
20-
.map(function(line) { return line.trim(); })
21-
.filter(function(line) { return line.length > 0; })
22-
.map(function(line) { return JSON.parse(line); })
23-
.map(function(tx) {
24-
return {
25-
timestamp: tx.timestamp,
26-
transactionId: tx.id,
27-
author: tx.author,
28-
documentCount: Array.isArray(tx.documentIDs) ? tx.documentIDs.length : 0
29-
};
30-
});
31-
} else {
32-
result = [];
33-
}
27+

plugins/Sanity/v1/dataStreams/scripts/members.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const members = (data && data.data) || [];
66

77
result = members.map((user) => ({
8+
...user,
89
name: user.profile && user.profile.displayName,
910
email: user.profile && user.profile.email,
1011
roles: (user.memberships || [])
@@ -13,3 +14,4 @@ result = members.map((user) => ({
1314
sanityUserId: user.sanityUserId,
1415
imageUrl: user.profile && user.profile.imageUrl,
1516
}));
17+

0 commit comments

Comments
 (0)