@sanity/blueprints 0.10.0 → 0.11.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 +326 -14
- package/dist/definers/blueprints.d.ts +2 -0
- package/dist/definers/blueprints.js +2 -0
- package/dist/definers/blueprints.js.map +1 -1
- package/dist/definers/cors.d.ts +4 -0
- package/dist/definers/cors.js +4 -0
- package/dist/definers/cors.js.map +1 -1
- package/dist/definers/datasets.d.ts +5 -0
- package/dist/definers/datasets.js +5 -0
- package/dist/definers/datasets.js.map +1 -1
- package/dist/definers/functions.d.ts +41 -12
- package/dist/definers/functions.js +57 -16
- package/dist/definers/functions.js.map +1 -1
- package/dist/definers/resources.d.ts +2 -0
- package/dist/definers/resources.js +2 -0
- package/dist/definers/resources.js.map +1 -1
- package/dist/definers/robots.d.ts +4 -0
- package/dist/definers/robots.js +4 -0
- package/dist/definers/robots.js.map +1 -1
- package/dist/definers/roles.d.ts +6 -0
- package/dist/definers/roles.js +6 -0
- package/dist/definers/roles.js.map +1 -1
- package/dist/definers/webhooks.d.ts +4 -0
- package/dist/definers/webhooks.js +4 -0
- package/dist/definers/webhooks.js.map +1 -1
- package/dist/index.d.ts +20 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -1
- package/dist/types/blueprints.d.ts +16 -4
- package/dist/types/cors.d.ts +4 -0
- package/dist/types/datasets.d.ts +14 -2
- package/dist/types/errors.d.ts +4 -1
- package/dist/types/functions.d.ts +76 -16
- package/dist/types/functions.js +5 -1
- package/dist/types/functions.js.map +1 -1
- package/dist/types/resources.d.ts +9 -0
- package/dist/types/robots.d.ts +12 -3
- package/dist/types/roles.d.ts +11 -3
- package/dist/types/webhooks.d.ts +17 -5
- package/dist/utils/schedule-parser.d.ts +42 -0
- package/dist/utils/schedule-parser.js +450 -0
- package/dist/utils/schedule-parser.js.map +1 -0
- package/dist/utils/validation.d.ts +1 -0
- package/dist/utils/validation.js +1 -0
- package/dist/utils/validation.js.map +1 -1
- package/dist/validation/blueprints.d.ts +1 -0
- package/dist/validation/blueprints.js +1 -0
- package/dist/validation/blueprints.js.map +1 -1
- package/dist/validation/cors.d.ts +1 -0
- package/dist/validation/cors.js +1 -0
- package/dist/validation/cors.js.map +1 -1
- package/dist/validation/datasets.d.ts +2 -0
- package/dist/validation/datasets.js +2 -0
- package/dist/validation/datasets.js.map +1 -1
- package/dist/validation/functions.d.ts +11 -0
- package/dist/validation/functions.js +37 -1
- package/dist/validation/functions.js.map +1 -1
- package/dist/validation/resources.d.ts +7 -1
- package/dist/validation/resources.js +20 -14
- package/dist/validation/resources.js.map +1 -1
- package/dist/validation/robots.d.ts +7 -0
- package/dist/validation/robots.js +7 -0
- package/dist/validation/robots.js.map +1 -1
- package/dist/validation/roles.d.ts +3 -1
- package/dist/validation/roles.js +3 -1
- package/dist/validation/roles.js.map +1 -1
- package/dist/validation/webhooks.d.ts +1 -0
- package/dist/validation/webhooks.js +1 -0
- package/dist/validation/webhooks.js.map +1 -1
- package/package.json +4 -1
- package/src/definers/blueprints.ts +2 -0
- package/src/definers/cors.ts +4 -0
- package/src/definers/datasets.ts +5 -0
- package/src/definers/functions.ts +62 -18
- package/src/definers/resources.ts +2 -0
- package/src/definers/robots.ts +4 -0
- package/src/definers/roles.ts +6 -0
- package/src/definers/webhooks.ts +4 -0
- package/src/index.ts +22 -0
- package/src/types/blueprints.ts +16 -4
- package/src/types/cors.ts +4 -0
- package/src/types/datasets.ts +14 -2
- package/src/types/errors.ts +4 -1
- package/src/types/functions.ts +87 -15
- package/src/types/resources.ts +9 -0
- package/src/types/robots.ts +12 -3
- package/src/types/roles.ts +11 -3
- package/src/types/webhooks.ts +17 -5
- package/src/utils/schedule-parser.ts +502 -0
- package/src/utils/validation.ts +1 -0
- package/src/validation/blueprints.ts +1 -0
- package/src/validation/cors.ts +1 -0
- package/src/validation/datasets.ts +2 -0
- package/src/validation/functions.ts +37 -0
- package/src/validation/resources.ts +20 -14
- package/src/validation/robots.ts +7 -0
- package/src/validation/roles.ts +3 -1
- package/src/validation/webhooks.ts +1 -0
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
validateMediaLibraryAssetFunction,
|
|
15
15
|
validateScheduleFunction,
|
|
16
16
|
} from '../index.js'
|
|
17
|
+
import {parseScheduleExpression} from '../utils/schedule-parser.js'
|
|
17
18
|
import {runValidation} from '../utils/validation.js'
|
|
18
19
|
|
|
19
20
|
type BaseFunctionEventKey = keyof BlueprintFunctionBaseResourceEvent
|
|
@@ -27,7 +28,8 @@ type ScheduleFunctionEventKey =
|
|
|
27
28
|
| keyof BlueprintScheduleFunctionExpressionResourceEvent
|
|
28
29
|
const SCHEDULE_EVENT_KEYS = new Set<ScheduleFunctionEventKey>(['minute', 'hour', 'dayOfWeek', 'month', 'dayOfMonth', 'expression'])
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
/** @internal */
|
|
32
|
+
export interface RequiredFunctionProperties {
|
|
31
33
|
name: string
|
|
32
34
|
}
|
|
33
35
|
|
|
@@ -51,6 +53,8 @@ interface RequiredFunctionProperties {
|
|
|
51
53
|
* })
|
|
52
54
|
* ```
|
|
53
55
|
* @param functionConfig The configuration for the document function
|
|
56
|
+
* @public
|
|
57
|
+
* @category Definers
|
|
54
58
|
* @returns The validated document function resource
|
|
55
59
|
*/
|
|
56
60
|
export function defineDocumentFunction(
|
|
@@ -65,7 +69,7 @@ export function defineDocumentFunction(
|
|
|
65
69
|
export function defineDocumentFunction(
|
|
66
70
|
functionConfig: Partial<BlueprintDocumentFunctionResource> & RequiredFunctionProperties & Partial<BlueprintDocumentFunctionResourceEvent>,
|
|
67
71
|
): BlueprintDocumentFunctionResource {
|
|
68
|
-
let {name, src, event, timeout, memory, env, type, robotToken, project, ...maybeEvent} = functionConfig
|
|
72
|
+
let {name, src, event, timeout, memory, env, type, robotToken, project, runtime, ...maybeEvent} = functionConfig
|
|
69
73
|
if (!type) type = 'sanity.function.document'
|
|
70
74
|
|
|
71
75
|
// event validation and normalization
|
|
@@ -97,6 +101,7 @@ export function defineDocumentFunction(
|
|
|
97
101
|
env,
|
|
98
102
|
robotToken,
|
|
99
103
|
project,
|
|
104
|
+
runtime,
|
|
100
105
|
},
|
|
101
106
|
{
|
|
102
107
|
skipValidation: true, // already done below
|
|
@@ -132,6 +137,8 @@ export function defineDocumentFunction(
|
|
|
132
137
|
* })
|
|
133
138
|
* ```
|
|
134
139
|
* @param functionConfig The configuration for the media library asset function
|
|
140
|
+
* @public
|
|
141
|
+
* @category Definers
|
|
135
142
|
* @returns The validated media library asset function resource
|
|
136
143
|
*/
|
|
137
144
|
export function defineMediaLibraryAssetFunction(
|
|
@@ -140,7 +147,7 @@ export function defineMediaLibraryAssetFunction(
|
|
|
140
147
|
Pick<BlueprintMediaLibraryAssetFunctionResource, 'event'> &
|
|
141
148
|
Partial<BlueprintMediaLibraryFunctionResourceEvent>,
|
|
142
149
|
): BlueprintMediaLibraryAssetFunctionResource {
|
|
143
|
-
let {name, src, event, timeout, memory, env, type, robotToken, project} = functionConfig
|
|
150
|
+
let {name, src, event, timeout, memory, env, type, robotToken, project, runtime} = functionConfig
|
|
144
151
|
if (!type) type = 'sanity.function.media-library.asset'
|
|
145
152
|
|
|
146
153
|
const functionResource: BlueprintMediaLibraryAssetFunctionResource = {
|
|
@@ -153,6 +160,7 @@ export function defineMediaLibraryAssetFunction(
|
|
|
153
160
|
env,
|
|
154
161
|
robotToken,
|
|
155
162
|
project,
|
|
163
|
+
runtime,
|
|
156
164
|
},
|
|
157
165
|
{
|
|
158
166
|
skipValidation: true, // already done below
|
|
@@ -169,23 +177,45 @@ export function defineMediaLibraryAssetFunction(
|
|
|
169
177
|
|
|
170
178
|
/**
|
|
171
179
|
* Defines a function that is triggered on a schedule.
|
|
180
|
+
* Supports cron expressions or natural language schedules.
|
|
181
|
+
*
|
|
172
182
|
* ```
|
|
183
|
+
* // Using cron expression
|
|
184
|
+
* defineScheduleFunction({
|
|
185
|
+
* name: 'daily-cleanup',
|
|
186
|
+
* event: {expression: '0 9 * * *'},
|
|
187
|
+
* })
|
|
188
|
+
*
|
|
189
|
+
* // Using natural language
|
|
190
|
+
* defineScheduleFunction({
|
|
191
|
+
* name: 'daily-report',
|
|
192
|
+
* event: {expression: 'every day at 9am'},
|
|
193
|
+
* })
|
|
194
|
+
*
|
|
195
|
+
* // More natural language examples:
|
|
196
|
+
* // 'every 15 minutes'
|
|
197
|
+
* // 'weekdays at 8am'
|
|
198
|
+
* // 'fridays in the evening'
|
|
199
|
+
* // 'mon, wed, fri at 9am'
|
|
200
|
+
* // 'first of the month at noon'
|
|
201
|
+
*
|
|
202
|
+
* // Using explicit cron fields
|
|
173
203
|
* defineScheduleFunction({
|
|
174
204
|
* name: 'my-schedule-function',
|
|
175
|
-
* src: 'functions/schedule-function',
|
|
176
|
-
* memory: 3,
|
|
177
|
-
* timeout: 300,
|
|
178
205
|
* event: {
|
|
179
|
-
* minute:
|
|
180
|
-
* hour:
|
|
181
|
-
* dayOfMonth:
|
|
182
|
-
* month:
|
|
183
|
-
* dayOfWeek:
|
|
206
|
+
* minute: '0',
|
|
207
|
+
* hour: '9',
|
|
208
|
+
* dayOfMonth: '*',
|
|
209
|
+
* month: '*',
|
|
210
|
+
* dayOfWeek: '*',
|
|
184
211
|
* },
|
|
185
212
|
* })
|
|
186
213
|
* ```
|
|
187
|
-
* @
|
|
188
|
-
* @
|
|
214
|
+
* @public
|
|
215
|
+
* @alpha Deploying Schedule Functions via Blueprints is experimental. This feature is not available publicly yet.
|
|
216
|
+
* @hidden
|
|
217
|
+
* @category Definers
|
|
218
|
+
* @param functionConfig The configuration for the schedule function
|
|
189
219
|
* @returns The validated schedule function resource
|
|
190
220
|
*/
|
|
191
221
|
export function defineScheduleFunction(
|
|
@@ -194,7 +224,7 @@ export function defineScheduleFunction(
|
|
|
194
224
|
Pick<BlueprintScheduleFunctionResource, 'event'> &
|
|
195
225
|
Partial<BlueprintScheduleFunctionResourceEvent>,
|
|
196
226
|
): BlueprintScheduleFunctionResource {
|
|
197
|
-
let {name, src, event, timeout, memory, env, type, timezone} = functionConfig
|
|
227
|
+
let {name, src, event, timeout, memory, env, type, timezone, runtime} = functionConfig
|
|
198
228
|
if (!type) type = 'sanity.function.cron'
|
|
199
229
|
|
|
200
230
|
const functionResource: BlueprintScheduleFunctionResource = {
|
|
@@ -205,6 +235,7 @@ export function defineScheduleFunction(
|
|
|
205
235
|
timeout,
|
|
206
236
|
memory,
|
|
207
237
|
env,
|
|
238
|
+
runtime,
|
|
208
239
|
},
|
|
209
240
|
{
|
|
210
241
|
skipValidation: true, // already done below
|
|
@@ -219,6 +250,11 @@ export function defineScheduleFunction(
|
|
|
219
250
|
|
|
220
251
|
runValidation(() => validateScheduleFunction(functionResource))
|
|
221
252
|
|
|
253
|
+
// Parse expression after validation (validation ensures it's valid)
|
|
254
|
+
if ('expression' in functionResource.event && functionResource.event.expression) {
|
|
255
|
+
functionResource.event.expression = parseScheduleExpression(functionResource.event.expression)
|
|
256
|
+
}
|
|
257
|
+
|
|
222
258
|
return functionResource
|
|
223
259
|
}
|
|
224
260
|
|
|
@@ -230,6 +266,7 @@ export function defineScheduleFunction(
|
|
|
230
266
|
* src: 'functions/my-function',
|
|
231
267
|
* timeout: 300,
|
|
232
268
|
* memory: 1,
|
|
269
|
+
* runtime: 'nodejs24.x',
|
|
233
270
|
* env: {
|
|
234
271
|
* MY_ENV_VAR: 'my-custom-value'
|
|
235
272
|
* },
|
|
@@ -237,13 +274,15 @@ export function defineScheduleFunction(
|
|
|
237
274
|
* ```
|
|
238
275
|
* @param functionConfig The configuration for the function
|
|
239
276
|
* @param options Optional configuration including validation options
|
|
277
|
+
* @category Definers
|
|
278
|
+
* @internal
|
|
240
279
|
* @returns The validated function resource
|
|
241
280
|
*/
|
|
242
281
|
export function defineFunction(
|
|
243
282
|
functionConfig: Partial<BlueprintBaseFunctionResource> & RequiredFunctionProperties,
|
|
244
283
|
options?: {skipValidation?: boolean},
|
|
245
284
|
): BlueprintBaseFunctionResource {
|
|
246
|
-
let {name, src, timeout, memory, env, type, robotToken, project} = functionConfig
|
|
285
|
+
let {name, src, timeout, memory, env, type, robotToken, project, runtime} = functionConfig
|
|
247
286
|
|
|
248
287
|
// defaults
|
|
249
288
|
if (!src) src = `functions/${name}`
|
|
@@ -258,6 +297,7 @@ export function defineFunction(
|
|
|
258
297
|
env,
|
|
259
298
|
robotToken,
|
|
260
299
|
project,
|
|
300
|
+
runtime,
|
|
261
301
|
}
|
|
262
302
|
|
|
263
303
|
if (options?.skipValidation !== true) runValidation(() => validateFunction(functionResource))
|
|
@@ -300,10 +340,14 @@ function buildMediaLibraryFunctionEvent(event: BlueprintMediaLibraryFunctionReso
|
|
|
300
340
|
return fullEvent
|
|
301
341
|
}
|
|
302
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Builds a schedule function event configuration.
|
|
345
|
+
* Filters out non-event properties. Does not parse expressions.
|
|
346
|
+
* @param event Schedule function event configuration
|
|
347
|
+
* @returns Cleaned schedule function event configuration
|
|
348
|
+
*/
|
|
303
349
|
function buildScheduleFunctionEvent(event: BlueprintScheduleFunctionResourceEvent): BlueprintScheduleFunctionResourceEvent {
|
|
304
|
-
|
|
350
|
+
return Object.fromEntries(
|
|
305
351
|
Object.entries(event).filter(([key]) => SCHEDULE_EVENT_KEYS.has(key as ScheduleFunctionEventKey)),
|
|
306
352
|
) as BlueprintScheduleFunctionResourceEvent
|
|
307
|
-
|
|
308
|
-
return cleanEvent
|
|
309
353
|
}
|
|
@@ -4,6 +4,8 @@ import {assertResource, type BlueprintResource} from '../index.js'
|
|
|
4
4
|
* Defines a generic resource to be managed in Blueprints.
|
|
5
5
|
* This is useful if the resource type does not yet have a `define*` function.
|
|
6
6
|
* @param resourceConfig The resource configuration
|
|
7
|
+
* @category Definers
|
|
8
|
+
* @internal
|
|
7
9
|
*/
|
|
8
10
|
export function defineResource(resourceConfig: Partial<BlueprintResource>): BlueprintResource {
|
|
9
11
|
const resource = {
|
package/src/definers/robots.ts
CHANGED
|
@@ -16,6 +16,10 @@ import {runValidation} from '../utils/validation.js'
|
|
|
16
16
|
* ```
|
|
17
17
|
*
|
|
18
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
|
|
19
23
|
*/
|
|
20
24
|
export function defineRobot(parameters: BlueprintRobotConfig): BlueprintRobotResource {
|
|
21
25
|
// default robot label
|
package/src/definers/roles.ts
CHANGED
|
@@ -28,6 +28,9 @@ import {runValidation} from '../utils/validation.js'
|
|
|
28
28
|
* }),
|
|
29
29
|
* ```
|
|
30
30
|
* @param parameters The configuration of the role
|
|
31
|
+
* @public
|
|
32
|
+
* @beta Deploying Roles via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
33
|
+
* @category Definers
|
|
31
34
|
* @returns The role resource
|
|
32
35
|
*/
|
|
33
36
|
export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValidation?: boolean}): BlueprintRoleResource {
|
|
@@ -70,6 +73,9 @@ export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValid
|
|
|
70
73
|
* }]
|
|
71
74
|
* }),
|
|
72
75
|
* ```
|
|
76
|
+
* @public
|
|
77
|
+
* @beta Deploying Roles via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
78
|
+
* @category Definers
|
|
73
79
|
* @param projectId The ID of the project to which the role will be scoped
|
|
74
80
|
* @param parameters The configuration of the role
|
|
75
81
|
* @returns The role resource
|
package/src/definers/webhooks.ts
CHANGED
|
@@ -13,6 +13,10 @@ import {runValidation} from '../utils/validation.js'
|
|
|
13
13
|
* })
|
|
14
14
|
* ```
|
|
15
15
|
* @param parameters The webhook configuration
|
|
16
|
+
* @public
|
|
17
|
+
* @beta Deploying Webhooks via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
18
|
+
* @category Definers
|
|
19
|
+
* @returns The webhook resource
|
|
16
20
|
*/
|
|
17
21
|
export function defineDocumentWebhook(parameters: BlueprintDocumentWebhookConfig): BlueprintDocumentWebhookResource {
|
|
18
22
|
// default the display name
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
// DEFINERS - helper functions to create resources
|
|
2
|
+
/**
|
|
3
|
+
* @categoryDescription Definers
|
|
4
|
+
* These functions are used to define resources in a Blueprint.
|
|
5
|
+
*/
|
|
2
6
|
export * from './definers/blueprints.js'
|
|
3
7
|
export * from './definers/cors.js'
|
|
4
8
|
export * from './definers/datasets.js'
|
|
@@ -9,6 +13,14 @@ export * from './definers/roles.js'
|
|
|
9
13
|
export * from './definers/webhooks.js'
|
|
10
14
|
|
|
11
15
|
// TYPES - base types for all resources
|
|
16
|
+
/**
|
|
17
|
+
* @categoryDescription Resource Types
|
|
18
|
+
* These types are used to define the shape of resources in a Blueprint.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @categoryDescription Functions Types
|
|
22
|
+
* Resource types for functions in a Blueprint.
|
|
23
|
+
*/
|
|
12
24
|
export * from './types/blueprints.js'
|
|
13
25
|
export * from './types/cors.js'
|
|
14
26
|
export * from './types/datasets.js'
|
|
@@ -20,6 +32,10 @@ export * from './types/roles.js'
|
|
|
20
32
|
export * from './types/webhooks.js'
|
|
21
33
|
|
|
22
34
|
// VALIDATION - validation for all resources
|
|
35
|
+
/**
|
|
36
|
+
* @categoryDescription Validation
|
|
37
|
+
* These functions are used to validate resources in a Blueprint.
|
|
38
|
+
*/
|
|
23
39
|
export * from './validation/blueprints.js'
|
|
24
40
|
export * from './validation/cors.js'
|
|
25
41
|
export * from './validation/datasets.js'
|
|
@@ -28,3 +44,9 @@ export * from './validation/resources.js'
|
|
|
28
44
|
export * from './validation/robots.js'
|
|
29
45
|
export * from './validation/roles.js'
|
|
30
46
|
export * from './validation/webhooks.js'
|
|
47
|
+
|
|
48
|
+
// Public BLUEPRINTS INTERNALS - published bucket of misc Blueprint types
|
|
49
|
+
/**
|
|
50
|
+
* @categoryDescription Blueprint Internals
|
|
51
|
+
* Miscellaneous Blueprint types that make up the public API but are not exported directly.
|
|
52
|
+
*/
|
package/src/types/blueprints.ts
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import type {BlueprintResource} from '../index.js'
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Additional configuration on a Blueprint that overrides the normal configuration
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
4
7
|
export interface BlueprintsApiConfig {
|
|
5
8
|
organizationId: string
|
|
6
9
|
projectId: string
|
|
7
10
|
stackId: string
|
|
8
11
|
}
|
|
9
12
|
|
|
10
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* A key-value pair that will be output from a Blueprint
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
11
17
|
export interface BlueprintOutput {
|
|
12
18
|
name: string
|
|
13
19
|
value: string
|
|
14
20
|
}
|
|
15
21
|
|
|
16
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* A representation of a Blueprint document
|
|
24
|
+
* @category Blueprint Internals
|
|
25
|
+
*/
|
|
17
26
|
export interface Blueprint {
|
|
18
27
|
$schema: string
|
|
19
28
|
blueprintVersion: string
|
|
@@ -22,5 +31,8 @@ export interface Blueprint {
|
|
|
22
31
|
outputs?: BlueprintOutput[]
|
|
23
32
|
}
|
|
24
33
|
|
|
25
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* The result of defining a blueprint with `defineBlueprint`
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
26
38
|
export type BlueprintModule = ((args?: unknown) => Blueprint) & Partial<BlueprintsApiConfig>
|
package/src/types/cors.ts
CHANGED
|
@@ -3,6 +3,8 @@ import type {BlueprintProjectResourceLifecycle, BlueprintResource} from '../inde
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents a CORS Origin resource.
|
|
5
5
|
* @see https://www.sanity.io/docs/content-lake/cors
|
|
6
|
+
* @beta This feature is subject to breaking changes.
|
|
7
|
+
* @category Resource Types
|
|
6
8
|
*/
|
|
7
9
|
export interface BlueprintCorsOriginResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
|
|
8
10
|
type: 'sanity.project.cors'
|
|
@@ -31,6 +33,8 @@ export interface BlueprintCorsOriginResource extends BlueprintResource<Blueprint
|
|
|
31
33
|
/**
|
|
32
34
|
* Configuration for a CORS Origin resource.
|
|
33
35
|
* @see https://www.sanity.io/docs/content-lake/cors
|
|
36
|
+
* @beta This feature is subject to breaking changes.
|
|
37
|
+
* @category Resource Types
|
|
34
38
|
*/
|
|
35
39
|
export type BlueprintCorsOriginConfig = Omit<BlueprintCorsOriginResource, 'type' | 'allowCredentials'> & {
|
|
36
40
|
/**
|
package/src/types/datasets.ts
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import type {BlueprintResource} from '../index.js'
|
|
1
|
+
import type {BlueprintProjectResourceLifecycle, BlueprintResource} from '../index.js'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* The ACL mode for a dataset.
|
|
5
|
+
* @alpha
|
|
6
|
+
* @hidden
|
|
7
|
+
* @category Resource Types
|
|
8
|
+
*/
|
|
3
9
|
export type AclMode = 'public' | 'private' | 'custom'
|
|
4
10
|
|
|
5
11
|
/**
|
|
6
12
|
* Represents a Dataset resource.
|
|
7
13
|
* @see https://www.sanity.io/docs/content-lake/datasets
|
|
14
|
+
* @alpha This feature is subject to breaking changes.
|
|
15
|
+
* @hidden
|
|
16
|
+
* @category Resource Types
|
|
8
17
|
*/
|
|
9
|
-
export interface BlueprintDatasetResource extends BlueprintResource {
|
|
18
|
+
export interface BlueprintDatasetResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
|
|
10
19
|
type: 'sanity.project.dataset'
|
|
11
20
|
/** The name of the dataset. Must be unique within a project. */
|
|
12
21
|
datasetName: string
|
|
@@ -24,6 +33,9 @@ export interface BlueprintDatasetResource extends BlueprintResource {
|
|
|
24
33
|
/**
|
|
25
34
|
* Configuration for a Dataset resource.
|
|
26
35
|
* @see https://www.sanity.io/docs/content-lake/datasets
|
|
36
|
+
* @alpha This feature is subject to breaking changes.
|
|
37
|
+
* @hidden
|
|
38
|
+
* @category Resource Types
|
|
27
39
|
*/
|
|
28
40
|
export type BlueprintDatasetConfig = Omit<BlueprintDatasetResource, 'type' | 'datasetName'> & {
|
|
29
41
|
/** The name of the dataset. Must be unique within a project. Defaults to the name of the resource. */
|
package/src/types/errors.ts
CHANGED
package/src/types/functions.ts
CHANGED
|
@@ -2,7 +2,10 @@ import type {BlueprintResource} from '../index.js'
|
|
|
2
2
|
|
|
3
3
|
// --- Function Event Types ---
|
|
4
4
|
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Base event configuration shared by document and media library function types
|
|
7
|
+
* @category Functions Types
|
|
8
|
+
*/
|
|
6
9
|
export interface BlueprintFunctionBaseResourceEvent {
|
|
7
10
|
/** Event types that trigger the function. Defaults to ['publish'] */
|
|
8
11
|
on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]]
|
|
@@ -13,24 +16,37 @@ export interface BlueprintFunctionBaseResourceEvent {
|
|
|
13
16
|
/** Include draft documents in addition to published documents */
|
|
14
17
|
includeDrafts?: boolean
|
|
15
18
|
}
|
|
16
|
-
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Event configuration for document functions
|
|
22
|
+
* @category Functions Types
|
|
23
|
+
*/
|
|
17
24
|
export interface BlueprintDocumentFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
|
|
18
25
|
/** Include all versions of documents, not just the current version */
|
|
19
26
|
includeAllVersions?: boolean
|
|
20
27
|
/** Optional dataset resource scoping for the function */
|
|
21
28
|
resource?: BlueprintFunctionResourceEventResourceDataset
|
|
22
29
|
}
|
|
23
|
-
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Event configuration for media library asset functions
|
|
33
|
+
* @category Functions Types
|
|
34
|
+
*/
|
|
24
35
|
export interface BlueprintMediaLibraryFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
|
|
25
36
|
/** Media library resource scoping (required for media library functions) */
|
|
26
37
|
resource: BlueprintFunctionResourceEventResourceMediaLibrary
|
|
27
38
|
}
|
|
28
|
-
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Union type of all function resource event configurations
|
|
42
|
+
* @category Functions Types
|
|
43
|
+
*/
|
|
29
44
|
export type BlueprintFunctionResourceEvent = BlueprintDocumentFunctionResourceEvent | BlueprintMediaLibraryFunctionResourceEvent
|
|
30
45
|
|
|
31
46
|
/**
|
|
32
|
-
*
|
|
33
|
-
* @example {
|
|
47
|
+
* Explicit resource event for schedule functions to specific minutes, hours, days of month, months, and days of week
|
|
48
|
+
* @example { minute: '0', hour: '9', dayOfMonth: '1', month: '1', dayOfWeek: '1' }
|
|
49
|
+
* @category Functions Types
|
|
34
50
|
*/
|
|
35
51
|
export interface BlueprintScheduleFunctionExplicitResourceEvent {
|
|
36
52
|
minute: string
|
|
@@ -39,30 +55,67 @@ export interface BlueprintScheduleFunctionExplicitResourceEvent {
|
|
|
39
55
|
month: string
|
|
40
56
|
dayOfWeek: string
|
|
41
57
|
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Expression resource for schedule functions to specific expressions
|
|
61
|
+
* @example { expression: '0 9 * * *' }
|
|
62
|
+
* @category Functions Types
|
|
63
|
+
*/
|
|
42
64
|
export interface BlueprintScheduleFunctionExpressionResourceEvent {
|
|
43
65
|
expression: string
|
|
44
66
|
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Union type of all schedule function resource event configurations
|
|
70
|
+
* @category Functions Types
|
|
71
|
+
*/
|
|
45
72
|
export type BlueprintScheduleFunctionResourceEvent =
|
|
46
73
|
| BlueprintScheduleFunctionExplicitResourceEvent
|
|
47
74
|
| BlueprintScheduleFunctionExpressionResourceEvent
|
|
48
75
|
|
|
49
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Dataset resource for scoping document functions to specific datasets
|
|
78
|
+
* @example { type: 'dataset', id: 'my-project.production' }
|
|
79
|
+
* @category Resource Types
|
|
80
|
+
*/
|
|
81
|
+
export interface BlueprintFunctionResourceEventResourceDataset {
|
|
50
82
|
type: 'dataset'
|
|
51
|
-
/**
|
|
83
|
+
/** A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
|
|
52
84
|
id: string
|
|
53
85
|
}
|
|
54
|
-
|
|
55
|
-
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Media library resource for scoping media library functions
|
|
89
|
+
* @category Functions Types
|
|
90
|
+
*/
|
|
91
|
+
export interface BlueprintFunctionResourceEventResourceMediaLibrary {
|
|
56
92
|
type: 'media-library'
|
|
57
93
|
id: string
|
|
58
94
|
}
|
|
59
95
|
|
|
60
|
-
/**
|
|
61
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Events that can trigger a function
|
|
98
|
+
* @category Functions Types
|
|
99
|
+
*/
|
|
100
|
+
export type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update'
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Current support Function runtimes
|
|
104
|
+
* @category Functions Types
|
|
105
|
+
*/
|
|
106
|
+
export const VALID_RUNTIMES = ['node', 'nodejs22.x', 'nodejs24.x'] as const
|
|
107
|
+
/**
|
|
108
|
+
* Supported function runtimes
|
|
109
|
+
* @category Functions Types
|
|
110
|
+
*/
|
|
111
|
+
export type FunctionRuntimes = (typeof VALID_RUNTIMES)[number]
|
|
62
112
|
|
|
63
113
|
// --- Main Function Types ---
|
|
64
114
|
|
|
65
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* Base function resource with common properties for all function types
|
|
117
|
+
* @category Functions Types
|
|
118
|
+
*/
|
|
66
119
|
export interface BlueprintBaseFunctionResource extends BlueprintResource {
|
|
67
120
|
/** Human-readable display name for the function */
|
|
68
121
|
displayName?: string
|
|
@@ -82,19 +135,38 @@ export interface BlueprintBaseFunctionResource extends BlueprintResource {
|
|
|
82
135
|
*
|
|
83
136
|
* The `project` attribute must be defined if your blueprint is scoped to an organization. */
|
|
84
137
|
project?: string
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The runtime environment for the function (currently only Node.js is supported)
|
|
141
|
+
* @default 'nodejs24.x'
|
|
142
|
+
*/
|
|
143
|
+
runtime?: FunctionRuntimes
|
|
85
144
|
}
|
|
86
|
-
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A function resource triggered by document events in Sanity datasets
|
|
148
|
+
* @category Functions Types
|
|
149
|
+
*/
|
|
87
150
|
export interface BlueprintDocumentFunctionResource extends BlueprintBaseFunctionResource {
|
|
88
151
|
type: 'sanity.function.document'
|
|
89
152
|
/** Event configuration specifying when and how the function is triggered */
|
|
90
153
|
event: BlueprintDocumentFunctionResourceEvent
|
|
91
154
|
}
|
|
92
|
-
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A function resource triggered by media library asset events
|
|
158
|
+
* @category Functions Types
|
|
159
|
+
*/
|
|
93
160
|
export interface BlueprintMediaLibraryAssetFunctionResource extends BlueprintBaseFunctionResource {
|
|
94
161
|
type: 'sanity.function.media-library.asset'
|
|
95
162
|
/** Event configuration specifying when and how the function is triggered */
|
|
96
163
|
event: BlueprintMediaLibraryFunctionResourceEvent
|
|
97
164
|
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* A function resource triggered by schedule events
|
|
168
|
+
* @category Functions Types
|
|
169
|
+
*/
|
|
98
170
|
export interface BlueprintScheduleFunctionResource extends BlueprintBaseFunctionResource {
|
|
99
171
|
type: 'sanity.function.cron'
|
|
100
172
|
event: BlueprintScheduleFunctionResourceEvent
|
package/src/types/resources.ts
CHANGED
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
* - **replace** if a stack is deployed, the resource will be destroyed and created instead of performing an update. If the resource is removed from the blueprint, it will be destroyed. If the stack is destroyed, the resource will be destroyed.
|
|
6
6
|
* - **allow** if a stack is destroyed, the resource will be destroyed along with it. If the resource is removed it will be destroyed
|
|
7
7
|
* - **protect** if a stack is deployed the resource will not be updated. If the resource is removed from the blueprint or the stack is destroyed, deployment will fail.
|
|
8
|
+
* @category Blueprint Internals
|
|
8
9
|
*/
|
|
9
10
|
export type BlueprintResourceDeletionPolicy = 'allow' | 'retain' | 'replace' | 'protect'
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* An ownership action that will cause the referenced resource to be attached to the current stack.
|
|
14
|
+
* @category Blueprint Internals
|
|
13
15
|
*/
|
|
14
16
|
export interface BlueprintOwnershipAttachAction {
|
|
15
17
|
type: 'attach'
|
|
@@ -18,17 +20,20 @@ export interface BlueprintOwnershipAttachAction {
|
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* An ownership action that will cause the referenced resource to be detached from the current stack.
|
|
23
|
+
* @category Blueprint Internals
|
|
21
24
|
*/
|
|
22
25
|
export interface BlueprintOwnershipDetachAction {
|
|
23
26
|
type: 'detach'
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
26
29
|
* A union of all possible ownership actions.
|
|
30
|
+
* @category Blueprint Internals
|
|
27
31
|
*/
|
|
28
32
|
export type BlueprintOwnershipAction = BlueprintOwnershipAttachAction | BlueprintOwnershipDetachAction
|
|
29
33
|
|
|
30
34
|
/**
|
|
31
35
|
* An ownership action that will cause the referenced project-contained resource to be attached to the current stack.
|
|
36
|
+
* @category Blueprint Internals
|
|
32
37
|
*/
|
|
33
38
|
export interface BlueprintProjectOwnershipAttachAction extends BlueprintOwnershipAttachAction {
|
|
34
39
|
/** The identifier of the project for resources contained in a project */
|
|
@@ -36,11 +41,13 @@ export interface BlueprintProjectOwnershipAttachAction extends BlueprintOwnershi
|
|
|
36
41
|
}
|
|
37
42
|
/**
|
|
38
43
|
* A union of all possible ownership actions for resources belonging to projects.
|
|
44
|
+
* @category Blueprint Internals
|
|
39
45
|
*/
|
|
40
46
|
export type BlueprintProjectOwnershipAction = BlueprintProjectOwnershipAttachAction
|
|
41
47
|
|
|
42
48
|
/**
|
|
43
49
|
* Defines the lifcycle policy for this resource.
|
|
50
|
+
* @category Blueprint Internals
|
|
44
51
|
*/
|
|
45
52
|
export interface BlueprintResourceLifecycle {
|
|
46
53
|
deletionPolicy?: BlueprintResourceDeletionPolicy
|
|
@@ -50,6 +57,7 @@ export interface BlueprintResourceLifecycle {
|
|
|
50
57
|
|
|
51
58
|
/**
|
|
52
59
|
* Defines the lifcycle policy for this resource.
|
|
60
|
+
* @category Blueprint Internals
|
|
53
61
|
*/
|
|
54
62
|
export interface BlueprintProjectResourceLifecycle extends BlueprintResourceLifecycle {
|
|
55
63
|
ownershipAction?: BlueprintProjectOwnershipAction
|
|
@@ -57,6 +65,7 @@ export interface BlueprintProjectResourceLifecycle extends BlueprintResourceLife
|
|
|
57
65
|
|
|
58
66
|
/**
|
|
59
67
|
* The base type for all resources.
|
|
68
|
+
* @category Blueprint Internals
|
|
60
69
|
*/
|
|
61
70
|
export interface BlueprintResource<Lifecycle extends BlueprintResourceLifecycle = BlueprintResourceLifecycle> {
|
|
62
71
|
type: string
|
package/src/types/robots.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import type {BlueprintResource} from './resources'
|
|
1
|
+
import type {BlueprintProjectResourceLifecycle, BlueprintResource} from './resources'
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Resource types that robots can be attached to.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
4
7
|
export type RobotResourceType = 'organization' | 'project'
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Defines the robot's roles within a given resource.
|
|
11
|
+
* @beta This feature is subject to breaking changes.
|
|
12
|
+
* @category Resource Types
|
|
8
13
|
*/
|
|
9
14
|
export interface RobotMembership {
|
|
10
15
|
resourceType: RobotResourceType
|
|
@@ -15,8 +20,10 @@ export interface RobotMembership {
|
|
|
15
20
|
/**
|
|
16
21
|
* A robot that provides a token for automated access.
|
|
17
22
|
* @see https://www.sanity.io/docs/content-lake/http-auth#k4c21d7b829fe
|
|
23
|
+
* @beta This feature is subject to breaking changes.
|
|
24
|
+
* @category Resource Types
|
|
18
25
|
*/
|
|
19
|
-
export interface BlueprintRobotResource extends BlueprintResource {
|
|
26
|
+
export interface BlueprintRobotResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
|
|
20
27
|
type: 'sanity.access.robot'
|
|
21
28
|
/** A descriptive label for the robot and its use case */
|
|
22
29
|
label: string
|
|
@@ -29,6 +36,8 @@ export interface BlueprintRobotResource extends BlueprintResource {
|
|
|
29
36
|
/**
|
|
30
37
|
* Configuration for a robot that provides a token for automated access.
|
|
31
38
|
* @see https://www.sanity.io/docs/content-lake/http-auth#k4c21d7b829fe
|
|
39
|
+
* @beta This feature is subject to breaking changes.
|
|
40
|
+
* @category Resource Types
|
|
32
41
|
*/
|
|
33
42
|
export type BlueprintRobotConfig = Omit<BlueprintRobotResource, 'type' | 'label' | 'token'> & {
|
|
34
43
|
label?: string
|