@sanity/blueprints 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -317
- package/dist/definers/blueprints.d.ts +15 -3
- package/dist/definers/blueprints.js +40 -3
- package/dist/definers/blueprints.js.map +1 -1
- package/dist/definers/cors.d.ts +5 -2
- package/dist/definers/cors.js +17 -2
- package/dist/definers/cors.js.map +1 -1
- package/dist/definers/datasets.d.ts +5 -2
- package/dist/definers/datasets.js +18 -2
- package/dist/definers/datasets.js.map +1 -1
- package/dist/definers/functions.d.ts +37 -61
- package/dist/definers/functions.js +69 -95
- package/dist/definers/functions.js.map +1 -1
- package/dist/definers/resources.d.ts +10 -0
- package/dist/definers/resources.js +21 -0
- package/dist/definers/resources.js.map +1 -1
- package/dist/definers/robotTokens.d.ts +22 -0
- package/dist/definers/robotTokens.js +53 -0
- package/dist/definers/robotTokens.js.map +1 -0
- package/dist/definers/robots.d.ts +2 -22
- package/dist/definers/robots.js +2 -33
- package/dist/definers/robots.js.map +1 -1
- package/dist/definers/roles.d.ts +16 -25
- package/dist/definers/roles.js +64 -23
- package/dist/definers/roles.js.map +1 -1
- package/dist/definers/webhooks.d.ts +5 -2
- package/dist/definers/webhooks.js +25 -2
- package/dist/definers/webhooks.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/types/cors.d.ts +2 -0
- package/dist/types/datasets.d.ts +5 -1
- package/dist/types/functions.d.ts +65 -3
- package/dist/types/functions.js.map +1 -1
- package/dist/types/resources.d.ts +8 -0
- package/dist/types/robotTokens.d.ts +45 -0
- package/dist/types/robotTokens.js +2 -0
- package/dist/types/robotTokens.js.map +1 -0
- package/dist/types/robots.d.ts +8 -39
- package/dist/types/robots.js +1 -0
- package/dist/types/robots.js.map +1 -1
- package/dist/types/roles.d.ts +1 -0
- package/dist/types/webhooks.d.ts +6 -0
- package/dist/validation/robotTokens.d.ts +15 -0
- package/dist/validation/robotTokens.js +104 -0
- package/dist/validation/robotTokens.js.map +1 -0
- package/dist/validation/robots.d.ts +4 -15
- package/dist/validation/robots.js +5 -103
- package/dist/validation/robots.js.map +1 -1
- package/package.json +6 -6
- package/src/definers/blueprints.ts +40 -3
- package/src/definers/cors.ts +17 -2
- package/src/definers/datasets.ts +18 -2
- package/src/definers/functions.ts +124 -132
- package/src/definers/resources.ts +21 -0
- package/src/definers/robotTokens.ts +56 -0
- package/src/definers/robots.ts +2 -37
- package/src/definers/roles.ts +64 -23
- package/src/definers/webhooks.ts +25 -2
- package/src/index.ts +3 -0
- package/src/types/cors.ts +2 -0
- package/src/types/datasets.ts +5 -1
- package/src/types/functions.ts +71 -3
- package/src/types/resources.ts +8 -1
- package/src/types/robotTokens.ts +50 -0
- package/src/types/robots.ts +10 -44
- package/src/types/roles.ts +1 -0
- package/src/types/webhooks.ts +6 -0
- package/src/validation/robotTokens.ts +103 -0
- package/src/validation/robots.ts +5 -102
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type BlueprintBaseFunctionConfig,
|
|
2
3
|
type BlueprintBaseFunctionResource,
|
|
4
|
+
type BlueprintDocumentFunctionConfig,
|
|
3
5
|
type BlueprintDocumentFunctionResource,
|
|
4
6
|
type BlueprintDocumentFunctionResourceEvent,
|
|
5
7
|
type BlueprintFunctionBaseResourceEvent,
|
|
8
|
+
type BlueprintMediaLibraryAssetFunctionConfig,
|
|
6
9
|
type BlueprintMediaLibraryAssetFunctionResource,
|
|
7
10
|
type BlueprintMediaLibraryFunctionResourceEvent,
|
|
11
|
+
type BlueprintScheduleFunctionConfig,
|
|
8
12
|
type BlueprintScheduleFunctionExplicitResourceEvent,
|
|
9
13
|
type BlueprintScheduleFunctionExpressionResourceEvent,
|
|
10
14
|
type BlueprintScheduleFunctionResource,
|
|
@@ -28,49 +32,75 @@ type ScheduleFunctionEventKey =
|
|
|
28
32
|
| keyof BlueprintScheduleFunctionExpressionResourceEvent
|
|
29
33
|
const SCHEDULE_EVENT_KEYS = new Set<ScheduleFunctionEventKey>(['minute', 'hour', 'dayOfWeek', 'month', 'dayOfMonth', 'expression'])
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*
|
|
38
|
-
*
|
|
35
|
+
/*
|
|
36
|
+
* FUTURE example (move below @example when ready)
|
|
37
|
+
* @example With robot token reference
|
|
38
|
+
* ```ts
|
|
39
|
+
* defineRole({
|
|
40
|
+
* name: 'fn-role',
|
|
41
|
+
* title: 'Function Role',
|
|
42
|
+
* appliesToRobots: true,
|
|
43
|
+
* permissions: [{name: 'sanity-project-dataset', action: 'read'}],
|
|
44
|
+
* })
|
|
45
|
+
*
|
|
46
|
+
* defineRobotToken({
|
|
47
|
+
* name: 'fn-robot',
|
|
48
|
+
* memberships: [{
|
|
49
|
+
* roleNames: ['$.resources.fn-role'],
|
|
50
|
+
* }],
|
|
51
|
+
* })
|
|
52
|
+
*
|
|
39
53
|
* defineDocumentFunction({
|
|
40
|
-
* name: '
|
|
41
|
-
* src: 'functions/
|
|
54
|
+
* name: 'sync-to-external',
|
|
55
|
+
* src: 'functions/sync',
|
|
42
56
|
* memory: 3,
|
|
43
57
|
* timeout: 300,
|
|
58
|
+
* robotToken: '$.resources.fn-robot',
|
|
44
59
|
* event: {
|
|
45
60
|
* on: ['create', 'update'],
|
|
46
|
-
* filter: "_type == '
|
|
47
|
-
* projection: "{
|
|
61
|
+
* filter: "_type == 'product'",
|
|
62
|
+
* projection: "{_id, title, slug}",
|
|
48
63
|
* includeDrafts: false,
|
|
49
64
|
* },
|
|
50
65
|
* env: {
|
|
51
|
-
*
|
|
66
|
+
* EXTERNAL_API_URL: 'https://api.example.com',
|
|
67
|
+
* SUPER_SECRET: process.env.SUPER_SECRET,
|
|
68
|
+
* },
|
|
69
|
+
* })
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* Defines a function that is triggered by document events in Sanity datasets.
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* defineDocumentFunction({
|
|
77
|
+
* name: 'my-document-function',
|
|
78
|
+
* event: {
|
|
79
|
+
* on: ['create', 'update'],
|
|
80
|
+
* filter: "_type == 'post'",
|
|
81
|
+
* projection: "{_id, title, slug}",
|
|
52
82
|
* },
|
|
53
83
|
* })
|
|
54
84
|
* ```
|
|
55
85
|
* @param functionConfig The configuration for the document function
|
|
56
86
|
* @public
|
|
57
87
|
* @category Definers
|
|
88
|
+
* @expandType BlueprintDocumentFunctionConfig
|
|
58
89
|
* @returns The validated document function resource
|
|
59
90
|
*/
|
|
91
|
+
export function defineDocumentFunction(functionConfig: BlueprintDocumentFunctionConfig): BlueprintDocumentFunctionResource
|
|
92
|
+
/**
|
|
93
|
+
* @deprecated Define event properties under the 'event' key instead of specifying them at the top level
|
|
94
|
+
* @hidden
|
|
95
|
+
*/
|
|
60
96
|
export function defineDocumentFunction(
|
|
61
|
-
functionConfig:
|
|
62
|
-
): BlueprintDocumentFunctionResource
|
|
63
|
-
|
|
64
|
-
/** @deprecated Define event properties under the 'event' key instead of specifying them at the top level */
|
|
65
|
-
export function defineDocumentFunction(
|
|
66
|
-
functionConfig: Partial<BlueprintDocumentFunctionResource> & RequiredFunctionProperties & Partial<BlueprintDocumentFunctionResourceEvent>,
|
|
97
|
+
functionConfig: BlueprintDocumentFunctionConfig & Partial<BlueprintDocumentFunctionResourceEvent>,
|
|
67
98
|
): BlueprintDocumentFunctionResource
|
|
68
99
|
|
|
69
100
|
export function defineDocumentFunction(
|
|
70
|
-
functionConfig:
|
|
101
|
+
functionConfig: BlueprintDocumentFunctionConfig & Partial<BlueprintDocumentFunctionResourceEvent>,
|
|
71
102
|
): BlueprintDocumentFunctionResource {
|
|
72
|
-
let {name, src, event, timeout, memory, env,
|
|
73
|
-
if (!type) type = 'sanity.function.document'
|
|
103
|
+
let {name, src, event, timeout, memory, env, robotToken, project, runtime, ...maybeEvent} = functionConfig
|
|
74
104
|
|
|
75
105
|
// event validation and normalization
|
|
76
106
|
if (event) {
|
|
@@ -92,22 +122,8 @@ export function defineDocumentFunction(
|
|
|
92
122
|
}
|
|
93
123
|
|
|
94
124
|
const functionResource: BlueprintDocumentFunctionResource = {
|
|
95
|
-
...defineFunction(
|
|
96
|
-
|
|
97
|
-
name,
|
|
98
|
-
src,
|
|
99
|
-
timeout,
|
|
100
|
-
memory,
|
|
101
|
-
env,
|
|
102
|
-
robotToken,
|
|
103
|
-
project,
|
|
104
|
-
runtime,
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
skipValidation: true, // already done below
|
|
108
|
-
},
|
|
109
|
-
),
|
|
110
|
-
type,
|
|
125
|
+
...defineFunction(functionConfig, {skipValidation: true}),
|
|
126
|
+
type: 'sanity.function.document',
|
|
111
127
|
event,
|
|
112
128
|
}
|
|
113
129
|
|
|
@@ -116,57 +132,67 @@ export function defineDocumentFunction(
|
|
|
116
132
|
return functionResource
|
|
117
133
|
}
|
|
118
134
|
|
|
119
|
-
|
|
120
|
-
*
|
|
121
|
-
*
|
|
135
|
+
/*
|
|
136
|
+
* FUTURE example (move below @example when ready)
|
|
137
|
+
* @example With robot token reference
|
|
138
|
+
* ```ts
|
|
139
|
+
* defineRobotToken({
|
|
140
|
+
* name: 'media-robot',
|
|
141
|
+
* memberships: [{
|
|
142
|
+
* resourceType: 'project',
|
|
143
|
+
* resourceId: projectId,
|
|
144
|
+
* roleNames: ['editor'],
|
|
145
|
+
* }],
|
|
146
|
+
* })
|
|
147
|
+
*
|
|
122
148
|
* defineMediaLibraryAssetFunction({
|
|
123
|
-
* name: '
|
|
124
|
-
* src: 'functions/
|
|
149
|
+
* name: 'process-uploads',
|
|
150
|
+
* src: 'functions/process-uploads-v2',
|
|
151
|
+
* robotToken: '$.resources.media-robot',
|
|
125
152
|
* event: {
|
|
126
153
|
* on: ['create', 'update'],
|
|
127
154
|
* resource: {
|
|
128
155
|
* type: 'media-library',
|
|
129
156
|
* id: 'my-media-library-id',
|
|
130
157
|
* },
|
|
131
|
-
* filter: "type == '
|
|
158
|
+
* filter: "type == 'image'",
|
|
132
159
|
* projection: "{_id}",
|
|
133
160
|
* },
|
|
134
161
|
* env: {
|
|
135
|
-
*
|
|
162
|
+
* CDN_BUCKET: 'my-cdn-bucket',
|
|
163
|
+
* },
|
|
164
|
+
* })
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
/**
|
|
168
|
+
* Defines a function that is triggered by media library events.
|
|
169
|
+
*
|
|
170
|
+
* ```ts
|
|
171
|
+
* defineMediaLibraryAssetFunction({
|
|
172
|
+
* name: 'my-media-library-function',
|
|
173
|
+
* event: {
|
|
174
|
+
* on: ['create'],
|
|
175
|
+
* resource: {
|
|
176
|
+
* type: 'media-library',
|
|
177
|
+
* id: 'my-media-library-id',
|
|
178
|
+
* },
|
|
136
179
|
* },
|
|
137
180
|
* })
|
|
138
181
|
* ```
|
|
139
182
|
* @param functionConfig The configuration for the media library asset function
|
|
140
183
|
* @public
|
|
141
184
|
* @category Definers
|
|
185
|
+
* @expandType BlueprintMediaLibraryAssetFunctionConfig
|
|
142
186
|
* @returns The validated media library asset function resource
|
|
143
187
|
*/
|
|
144
188
|
export function defineMediaLibraryAssetFunction(
|
|
145
|
-
functionConfig:
|
|
146
|
-
RequiredFunctionProperties &
|
|
147
|
-
Pick<BlueprintMediaLibraryAssetFunctionResource, 'event'> &
|
|
148
|
-
Partial<BlueprintMediaLibraryFunctionResourceEvent>,
|
|
189
|
+
functionConfig: BlueprintMediaLibraryAssetFunctionConfig,
|
|
149
190
|
): BlueprintMediaLibraryAssetFunctionResource {
|
|
150
|
-
|
|
151
|
-
if (!type) type = 'sanity.function.media-library.asset'
|
|
191
|
+
const {event} = functionConfig
|
|
152
192
|
|
|
153
193
|
const functionResource: BlueprintMediaLibraryAssetFunctionResource = {
|
|
154
|
-
...defineFunction(
|
|
155
|
-
|
|
156
|
-
name,
|
|
157
|
-
src,
|
|
158
|
-
timeout,
|
|
159
|
-
memory,
|
|
160
|
-
env,
|
|
161
|
-
robotToken,
|
|
162
|
-
project,
|
|
163
|
-
runtime,
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
skipValidation: true, // already done below
|
|
167
|
-
},
|
|
168
|
-
),
|
|
169
|
-
type,
|
|
194
|
+
...defineFunction(functionConfig, {skipValidation: true}),
|
|
195
|
+
type: 'sanity.function.media-library.asset',
|
|
170
196
|
event: buildMediaLibraryFunctionEvent(event),
|
|
171
197
|
}
|
|
172
198
|
|
|
@@ -179,74 +205,51 @@ export function defineMediaLibraryAssetFunction(
|
|
|
179
205
|
* Defines a function that is triggered on a schedule.
|
|
180
206
|
* Supports cron expressions or natural language schedules.
|
|
181
207
|
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
208
|
+
* @remarks
|
|
209
|
+
* Using a cron expression:
|
|
210
|
+
* ```ts
|
|
184
211
|
* defineScheduleFunction({
|
|
185
212
|
* name: 'daily-cleanup',
|
|
186
213
|
* event: {expression: '0 9 * * *'},
|
|
187
214
|
* })
|
|
215
|
+
* ```
|
|
188
216
|
*
|
|
189
|
-
*
|
|
217
|
+
* Using explicit cron fields:
|
|
218
|
+
* ```ts
|
|
190
219
|
* defineScheduleFunction({
|
|
191
|
-
* name: 'daily-
|
|
192
|
-
* event: {
|
|
220
|
+
* name: 'daily-cleanup',
|
|
221
|
+
* event: {minute: '0', hour: '9', dayOfMonth: '*', month: '*', dayOfWeek: '*'},
|
|
193
222
|
* })
|
|
223
|
+
* ```
|
|
194
224
|
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
* // 'fridays in the evening'
|
|
199
|
-
* // 'mon, wed, fri at 9am'
|
|
200
|
-
* // 'first of the month at noon'
|
|
225
|
+
* The `event.expression` field accepts standard cron expressions or natural language:
|
|
226
|
+
* `'every 15 minutes'`, `'weekdays at 8am'`, `'fridays in the evening'`,
|
|
227
|
+
* `'mon, wed, fri at 9am'`, `'first of the month at noon'`
|
|
201
228
|
*
|
|
202
|
-
*
|
|
229
|
+
* ```ts
|
|
203
230
|
* defineScheduleFunction({
|
|
204
|
-
* name: '
|
|
205
|
-
* event: {
|
|
206
|
-
* minute: '0',
|
|
207
|
-
* hour: '9',
|
|
208
|
-
* dayOfMonth: '*',
|
|
209
|
-
* month: '*',
|
|
210
|
-
* dayOfWeek: '*',
|
|
211
|
-
* },
|
|
231
|
+
* name: 'daily-cleanup',
|
|
232
|
+
* event: {expression: 'every day at 9am'},
|
|
212
233
|
* })
|
|
213
234
|
* ```
|
|
214
235
|
* @public
|
|
215
236
|
* @alpha Deploying Schedule Functions via Blueprints is experimental. This feature is not available publicly yet.
|
|
216
237
|
* @hidden
|
|
217
238
|
* @category Definers
|
|
239
|
+
* @expandType BlueprintScheduleFunctionConfig
|
|
218
240
|
* @param functionConfig The configuration for the schedule function
|
|
219
241
|
* @returns The validated schedule function resource
|
|
220
242
|
*/
|
|
221
|
-
export function defineScheduleFunction(
|
|
222
|
-
|
|
223
|
-
RequiredFunctionProperties &
|
|
224
|
-
Pick<BlueprintScheduleFunctionResource, 'event'> &
|
|
225
|
-
Partial<BlueprintScheduleFunctionResourceEvent>,
|
|
226
|
-
): BlueprintScheduleFunctionResource {
|
|
227
|
-
let {name, src, event, timeout, memory, env, type, timezone, runtime} = functionConfig
|
|
228
|
-
if (!type) type = 'sanity.function.cron'
|
|
243
|
+
export function defineScheduleFunction(functionConfig: BlueprintScheduleFunctionConfig): BlueprintScheduleFunctionResource {
|
|
244
|
+
const {event, timezone} = functionConfig
|
|
229
245
|
|
|
230
246
|
const functionResource: BlueprintScheduleFunctionResource = {
|
|
231
|
-
...defineFunction(
|
|
232
|
-
|
|
233
|
-
name,
|
|
234
|
-
src,
|
|
235
|
-
timeout,
|
|
236
|
-
memory,
|
|
237
|
-
env,
|
|
238
|
-
runtime,
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
skipValidation: true, // already done below
|
|
242
|
-
},
|
|
243
|
-
),
|
|
244
|
-
type,
|
|
247
|
+
...defineFunction(functionConfig, {skipValidation: true}),
|
|
248
|
+
type: 'sanity.function.cron',
|
|
245
249
|
event: buildScheduleFunctionEvent(event),
|
|
246
250
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
251
|
+
|
|
252
|
+
if (timezone) functionResource.timezone = timezone
|
|
250
253
|
|
|
251
254
|
runValidation(() => validateScheduleFunction(functionResource))
|
|
252
255
|
|
|
@@ -260,38 +263,25 @@ export function defineScheduleFunction(
|
|
|
260
263
|
|
|
261
264
|
/**
|
|
262
265
|
* Defines a base function resource with common properties.
|
|
263
|
-
*
|
|
264
|
-
* defineFunction({
|
|
265
|
-
* name: 'my-function',
|
|
266
|
-
* src: 'functions/my-function',
|
|
267
|
-
* timeout: 300,
|
|
268
|
-
* memory: 1,
|
|
269
|
-
* runtime: 'nodejs24.x',
|
|
270
|
-
* env: {
|
|
271
|
-
* MY_ENV_VAR: 'my-custom-value'
|
|
272
|
-
* },
|
|
273
|
-
* })
|
|
274
|
-
* ```
|
|
266
|
+
*
|
|
275
267
|
* @param functionConfig The configuration for the function
|
|
276
268
|
* @param options Optional configuration including validation options
|
|
277
269
|
* @category Definers
|
|
278
270
|
* @internal
|
|
271
|
+
* @expandType BlueprintBaseFunctionConfig
|
|
279
272
|
* @returns The validated function resource
|
|
280
273
|
*/
|
|
281
274
|
export function defineFunction(
|
|
282
|
-
functionConfig:
|
|
275
|
+
functionConfig: BlueprintBaseFunctionConfig,
|
|
283
276
|
options?: {skipValidation?: boolean},
|
|
284
277
|
): BlueprintBaseFunctionResource {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
// defaults
|
|
288
|
-
if (!src) src = `functions/${name}`
|
|
289
|
-
if (!type) type = 'sanity.function.document'
|
|
278
|
+
const {name, displayName, src, timeout, memory, env, robotToken, project, runtime, lifecycle} = functionConfig
|
|
290
279
|
|
|
291
280
|
const functionResource: BlueprintBaseFunctionResource = {
|
|
292
|
-
type,
|
|
281
|
+
type: 'sanity.function.document',
|
|
293
282
|
name,
|
|
294
|
-
src
|
|
283
|
+
src: src ?? `functions/${name}`,
|
|
284
|
+
displayName,
|
|
295
285
|
timeout,
|
|
296
286
|
memory,
|
|
297
287
|
env,
|
|
@@ -300,6 +290,8 @@ export function defineFunction(
|
|
|
300
290
|
runtime,
|
|
301
291
|
}
|
|
302
292
|
|
|
293
|
+
if (lifecycle) functionResource.lifecycle = lifecycle
|
|
294
|
+
|
|
303
295
|
if (options?.skipValidation !== true) runValidation(() => validateFunction(functionResource))
|
|
304
296
|
|
|
305
297
|
return functionResource
|
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
import {assertResource, type BlueprintResource} from '../index.js'
|
|
2
2
|
|
|
3
|
+
/*
|
|
4
|
+
* FUTURE example (move below @example when ready)
|
|
5
|
+
* @example With lifecycle
|
|
6
|
+
* ```ts
|
|
7
|
+
* defineResource({
|
|
8
|
+
* name: 'my-resource',
|
|
9
|
+
* type: 'sanity.new.resource',
|
|
10
|
+
* lifecycle: {deletionPolicy: 'retain'},
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
3
14
|
/**
|
|
4
15
|
* Defines a generic resource to be managed in Blueprints.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
5
18
|
* This is useful if the resource type does not yet have a `define*` function.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* defineResource({
|
|
22
|
+
* name: 'my-resource',
|
|
23
|
+
* type: 'sanity.new.resource',
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
6
26
|
* @param resourceConfig The resource configuration
|
|
7
27
|
* @category Definers
|
|
28
|
+
* @expandType BlueprintResource
|
|
8
29
|
* @internal
|
|
9
30
|
*/
|
|
10
31
|
export function defineResource(resourceConfig: Partial<BlueprintResource>): BlueprintResource {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {type BlueprintRobotTokenConfig, type BlueprintRobotTokenResource, validateRobotToken} from '../index.js'
|
|
2
|
+
import {runValidation} from '../utils/validation.js'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* FUTURE example (move below @example when ready)
|
|
6
|
+
* @example Cross-resource references
|
|
7
|
+
* ```ts
|
|
8
|
+
* defineRole({
|
|
9
|
+
* name: 'ci-deploy-role',
|
|
10
|
+
* title: 'CI Deploy Role',
|
|
11
|
+
* appliesToRobots: true,
|
|
12
|
+
* permissions: [{name: 'sanity-project-cors', action: 'create'}],
|
|
13
|
+
* })
|
|
14
|
+
*
|
|
15
|
+
* defineRobotToken({
|
|
16
|
+
* name: 'ci-robot',
|
|
17
|
+
* label: 'CI Deploy Robot',
|
|
18
|
+
* memberships: [{
|
|
19
|
+
* roleNames: ['$.resources.ci-deploy-role'],
|
|
20
|
+
* }],
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Defines a Robot Token for automated access. Has a token property provided during deployment that can be referenced by other resources.
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* defineRobotToken({
|
|
29
|
+
* name: 'my-robot',
|
|
30
|
+
* memberships: [{
|
|
31
|
+
* resourceType: 'project',
|
|
32
|
+
* resourceId: projectId,
|
|
33
|
+
* roleNames: ['editor'],
|
|
34
|
+
* }],
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
* @param parameters The robot token configuration
|
|
38
|
+
* @public
|
|
39
|
+
* @beta Deploying Robot Tokens via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
40
|
+
* @category Definers
|
|
41
|
+
* @expandType BlueprintRobotTokenConfig
|
|
42
|
+
* @returns The robot token resource
|
|
43
|
+
*/
|
|
44
|
+
export function defineRobotToken(parameters: BlueprintRobotTokenConfig): BlueprintRobotTokenResource {
|
|
45
|
+
const label = parameters.label || parameters.name
|
|
46
|
+
|
|
47
|
+
const robotResource: BlueprintRobotTokenResource = {
|
|
48
|
+
...parameters,
|
|
49
|
+
label,
|
|
50
|
+
type: 'sanity.access.robot',
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
runValidation(() => validateRobotToken(robotResource))
|
|
54
|
+
|
|
55
|
+
return robotResource
|
|
56
|
+
}
|
package/src/definers/robots.ts
CHANGED
|
@@ -1,37 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Defines a Robot token for automated access. Has a token property provided during deployment that can be referenced by other resources.
|
|
6
|
-
* ```
|
|
7
|
-
* defineRobot({
|
|
8
|
-
* name: 'my-robot',
|
|
9
|
-
* label: 'My Robot',
|
|
10
|
-
* memberships: [{
|
|
11
|
-
* resourceType: 'project',
|
|
12
|
-
* resourceId: projectId,
|
|
13
|
-
* roleNames: ['custom-robot-role'],
|
|
14
|
-
* }],
|
|
15
|
-
* })
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* @param parameters The robot configuration
|
|
19
|
-
* @public
|
|
20
|
-
* @beta Deploying Robots via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
21
|
-
* @category Definers
|
|
22
|
-
* @returns The robot resource
|
|
23
|
-
*/
|
|
24
|
-
export function defineRobot(parameters: BlueprintRobotConfig): BlueprintRobotResource {
|
|
25
|
-
// default robot label
|
|
26
|
-
const label = parameters.label || parameters.name
|
|
27
|
-
|
|
28
|
-
const robotResource: BlueprintRobotResource = {
|
|
29
|
-
...parameters,
|
|
30
|
-
label,
|
|
31
|
-
type: 'sanity.access.robot',
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
runValidation(() => validateRobot(robotResource))
|
|
35
|
-
|
|
36
|
-
return robotResource
|
|
37
|
-
}
|
|
1
|
+
/** @deprecated Use {@link defineRobotToken} instead @hidden */
|
|
2
|
+
export {defineRobotToken as defineRobot} from './robotTokens.js'
|
package/src/definers/roles.ts
CHANGED
|
@@ -7,30 +7,48 @@ import {
|
|
|
7
7
|
} from '../index.js'
|
|
8
8
|
import {runValidation} from '../utils/validation.js'
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
/*
|
|
11
|
+
* FUTURE example (move below @example when ready)
|
|
12
|
+
* @example All options
|
|
13
|
+
* ```ts
|
|
13
14
|
* defineRole({
|
|
14
|
-
* name: '
|
|
15
|
-
* title: '
|
|
15
|
+
* name: 'ci-deploy-role',
|
|
16
|
+
* title: 'CI Deploy Role',
|
|
17
|
+
* description: 'Permissions for CI/CD pipelines to manage CORS and datasets',
|
|
16
18
|
* appliesToRobots: true,
|
|
17
19
|
* appliesToUsers: false,
|
|
18
20
|
* permissions: [{
|
|
19
21
|
* name: 'sanity-project-cors',
|
|
20
|
-
* action: 'create'
|
|
22
|
+
* action: 'create',
|
|
21
23
|
* }, {
|
|
22
24
|
* name: 'sanity-project-cors',
|
|
23
|
-
* action: 'read'
|
|
25
|
+
* action: 'read',
|
|
24
26
|
* }, {
|
|
25
27
|
* name: 'sanity-project-cors',
|
|
26
|
-
* action: 'delete'
|
|
27
|
-
* }]
|
|
28
|
-
* })
|
|
28
|
+
* action: 'delete',
|
|
29
|
+
* }],
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Defines a role that is scoped to the same resource as the blueprint.
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* defineRole({
|
|
38
|
+
* name: 'custom-robot-role',
|
|
39
|
+
* title: 'Custom Robot Role',
|
|
40
|
+
* appliesToRobots: true,
|
|
41
|
+
* permissions: [{
|
|
42
|
+
* name: 'sanity-project-cors',
|
|
43
|
+
* action: 'create',
|
|
44
|
+
* }],
|
|
45
|
+
* })
|
|
29
46
|
* ```
|
|
30
47
|
* @param parameters The configuration of the role
|
|
31
48
|
* @public
|
|
32
49
|
* @beta Deploying Roles via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
33
50
|
* @category Definers
|
|
51
|
+
* @expandType BlueprintRoleConfig
|
|
34
52
|
* @returns The role resource
|
|
35
53
|
*/
|
|
36
54
|
export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValidation?: boolean}): BlueprintRoleResource {
|
|
@@ -53,29 +71,52 @@ export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValid
|
|
|
53
71
|
return roleResource
|
|
54
72
|
}
|
|
55
73
|
|
|
56
|
-
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
74
|
+
/*
|
|
75
|
+
* FUTURE example (move below @example when ready)
|
|
76
|
+
* @example Cross-resource references
|
|
77
|
+
* ```ts
|
|
78
|
+
* const role = defineProjectRole(projectId, {
|
|
79
|
+
* name: 'ci-deploy-role',
|
|
80
|
+
* title: 'CI Deploy Role',
|
|
62
81
|
* appliesToRobots: true,
|
|
63
|
-
* appliesToUsers: false,
|
|
64
82
|
* permissions: [{
|
|
65
83
|
* name: 'sanity-project-cors',
|
|
66
|
-
* action: 'create'
|
|
84
|
+
* action: 'create',
|
|
67
85
|
* }, {
|
|
68
86
|
* name: 'sanity-project-cors',
|
|
69
|
-
* action: '
|
|
70
|
-
* },
|
|
87
|
+
* action: 'delete',
|
|
88
|
+
* }],
|
|
89
|
+
* })
|
|
90
|
+
*
|
|
91
|
+
* defineRobotToken({
|
|
92
|
+
* name: 'ci-robot',
|
|
93
|
+
* memberships: [{
|
|
94
|
+
* resourceType: 'project',
|
|
95
|
+
* resourceId: projectId,
|
|
96
|
+
* roleNames: ['$.resources.ci-deploy-role'],
|
|
97
|
+
* }],
|
|
98
|
+
* })
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
/**
|
|
102
|
+
* Defines a role that is scoped to the specified project.
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* defineProjectRole(projectId, {
|
|
106
|
+
* name: 'viewer-role',
|
|
107
|
+
* title: 'Viewer',
|
|
108
|
+
* appliesToUsers: true,
|
|
109
|
+
* permissions: [{
|
|
71
110
|
* name: 'sanity-project-cors',
|
|
72
|
-
* action: '
|
|
73
|
-
* }]
|
|
74
|
-
* })
|
|
111
|
+
* action: 'read',
|
|
112
|
+
* }],
|
|
113
|
+
* })
|
|
75
114
|
* ```
|
|
76
115
|
* @public
|
|
77
116
|
* @beta Deploying Roles via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
117
|
+
* @hidden
|
|
78
118
|
* @category Definers
|
|
119
|
+
* @expandType BlueprintRoleConfig
|
|
79
120
|
* @param projectId The ID of the project to which the role will be scoped
|
|
80
121
|
* @param parameters The configuration of the role
|
|
81
122
|
* @returns The role resource
|
package/src/definers/webhooks.ts
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
1
|
import {type BlueprintDocumentWebhookConfig, type BlueprintDocumentWebhookResource, validateDocumentWebhook} from '../index.js'
|
|
2
2
|
import {runValidation} from '../utils/validation.js'
|
|
3
3
|
|
|
4
|
+
/*
|
|
5
|
+
* FUTURE example (move below @example when ready)
|
|
6
|
+
* @example All options
|
|
7
|
+
* ```ts
|
|
8
|
+
* defineDocumentWebhook({
|
|
9
|
+
* name: 'sync-webhook',
|
|
10
|
+
* url: 'https://example.com/sync',
|
|
11
|
+
* on: ['create', 'update', 'delete'],
|
|
12
|
+
* dataset: 'production',
|
|
13
|
+
* apiVersion: 'v2026-01-01',
|
|
14
|
+
* filter: "_type == 'product'",
|
|
15
|
+
* projection: '{_id, title, slug}',
|
|
16
|
+
* httpMethod: 'POST',
|
|
17
|
+
* headers: {'X-Custom-Header': 'value'},
|
|
18
|
+
* secret: 'my-webhook-secret',
|
|
19
|
+
* includeDrafts: false,
|
|
20
|
+
* status: 'enabled',
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
4
24
|
/**
|
|
5
25
|
* Defines a webhook that is called when document changes occur.
|
|
6
|
-
*
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
7
28
|
* defineDocumentWebhook({
|
|
8
29
|
* name: 'my-webhook',
|
|
9
30
|
* on: ['create'],
|
|
10
31
|
* url: 'https://example.com/webhook',
|
|
11
32
|
* projection: '{_id}',
|
|
12
|
-
* dataset: '
|
|
33
|
+
* dataset: 'production',
|
|
34
|
+
* apiVersion: 'v2026-01-01',
|
|
13
35
|
* })
|
|
14
36
|
* ```
|
|
15
37
|
* @param parameters The webhook configuration
|
|
16
38
|
* @public
|
|
17
39
|
* @beta Deploying Webhooks via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
18
40
|
* @category Definers
|
|
41
|
+
* @expandType BlueprintDocumentWebhookConfig
|
|
19
42
|
* @returns The webhook resource
|
|
20
43
|
*/
|
|
21
44
|
export function defineDocumentWebhook(parameters: BlueprintDocumentWebhookConfig): BlueprintDocumentWebhookResource {
|