@sanity/blueprints 0.9.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.
Files changed (98) hide show
  1. package/README.md +326 -14
  2. package/dist/definers/blueprints.d.ts +2 -0
  3. package/dist/definers/blueprints.js +2 -0
  4. package/dist/definers/blueprints.js.map +1 -1
  5. package/dist/definers/cors.d.ts +4 -0
  6. package/dist/definers/cors.js +4 -0
  7. package/dist/definers/cors.js.map +1 -1
  8. package/dist/definers/datasets.d.ts +5 -0
  9. package/dist/definers/datasets.js +5 -0
  10. package/dist/definers/datasets.js.map +1 -1
  11. package/dist/definers/functions.d.ts +41 -12
  12. package/dist/definers/functions.js +60 -16
  13. package/dist/definers/functions.js.map +1 -1
  14. package/dist/definers/resources.d.ts +2 -0
  15. package/dist/definers/resources.js +2 -0
  16. package/dist/definers/resources.js.map +1 -1
  17. package/dist/definers/robots.d.ts +4 -0
  18. package/dist/definers/robots.js +4 -0
  19. package/dist/definers/robots.js.map +1 -1
  20. package/dist/definers/roles.d.ts +6 -0
  21. package/dist/definers/roles.js +6 -0
  22. package/dist/definers/roles.js.map +1 -1
  23. package/dist/definers/webhooks.d.ts +4 -0
  24. package/dist/definers/webhooks.js +4 -0
  25. package/dist/definers/webhooks.js.map +1 -1
  26. package/dist/index.d.ts +20 -0
  27. package/dist/index.js +21 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/types/blueprints.d.ts +16 -4
  30. package/dist/types/cors.d.ts +4 -0
  31. package/dist/types/datasets.d.ts +14 -2
  32. package/dist/types/errors.d.ts +4 -1
  33. package/dist/types/functions.d.ts +81 -16
  34. package/dist/types/functions.js +5 -1
  35. package/dist/types/functions.js.map +1 -1
  36. package/dist/types/resources.d.ts +16 -1
  37. package/dist/types/robots.d.ts +12 -3
  38. package/dist/types/roles.d.ts +11 -3
  39. package/dist/types/webhooks.d.ts +18 -6
  40. package/dist/utils/schedule-parser.d.ts +42 -0
  41. package/dist/utils/schedule-parser.js +450 -0
  42. package/dist/utils/schedule-parser.js.map +1 -0
  43. package/dist/utils/validation.d.ts +1 -0
  44. package/dist/utils/validation.js +1 -0
  45. package/dist/utils/validation.js.map +1 -1
  46. package/dist/validation/blueprints.d.ts +1 -0
  47. package/dist/validation/blueprints.js +1 -0
  48. package/dist/validation/blueprints.js.map +1 -1
  49. package/dist/validation/cors.d.ts +1 -0
  50. package/dist/validation/cors.js +1 -0
  51. package/dist/validation/cors.js.map +1 -1
  52. package/dist/validation/datasets.d.ts +2 -0
  53. package/dist/validation/datasets.js +2 -0
  54. package/dist/validation/datasets.js.map +1 -1
  55. package/dist/validation/functions.d.ts +11 -0
  56. package/dist/validation/functions.js +37 -1
  57. package/dist/validation/functions.js.map +1 -1
  58. package/dist/validation/resources.d.ts +7 -1
  59. package/dist/validation/resources.js +23 -16
  60. package/dist/validation/resources.js.map +1 -1
  61. package/dist/validation/robots.d.ts +7 -0
  62. package/dist/validation/robots.js +7 -0
  63. package/dist/validation/robots.js.map +1 -1
  64. package/dist/validation/roles.d.ts +3 -1
  65. package/dist/validation/roles.js +3 -1
  66. package/dist/validation/roles.js.map +1 -1
  67. package/dist/validation/webhooks.d.ts +1 -0
  68. package/dist/validation/webhooks.js +1 -0
  69. package/dist/validation/webhooks.js.map +1 -1
  70. package/package.json +4 -1
  71. package/src/definers/blueprints.ts +2 -0
  72. package/src/definers/cors.ts +4 -0
  73. package/src/definers/datasets.ts +5 -0
  74. package/src/definers/functions.ts +65 -18
  75. package/src/definers/resources.ts +2 -0
  76. package/src/definers/robots.ts +4 -0
  77. package/src/definers/roles.ts +6 -0
  78. package/src/definers/webhooks.ts +4 -0
  79. package/src/index.ts +22 -0
  80. package/src/types/blueprints.ts +16 -4
  81. package/src/types/cors.ts +4 -0
  82. package/src/types/datasets.ts +14 -2
  83. package/src/types/errors.ts +4 -1
  84. package/src/types/functions.ts +93 -15
  85. package/src/types/resources.ts +16 -1
  86. package/src/types/robots.ts +12 -3
  87. package/src/types/roles.ts +11 -3
  88. package/src/types/webhooks.ts +18 -6
  89. package/src/utils/schedule-parser.ts +502 -0
  90. package/src/utils/validation.ts +1 -0
  91. package/src/validation/blueprints.ts +1 -0
  92. package/src/validation/cors.ts +1 -0
  93. package/src/validation/datasets.ts +2 -0
  94. package/src/validation/functions.ts +37 -0
  95. package/src/validation/resources.ts +24 -16
  96. package/src/validation/robots.ts +7 -0
  97. package/src/validation/roles.ts +3 -1
  98. 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
- interface RequiredFunctionProperties {
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, ...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
@@ -96,6 +100,8 @@ export function defineDocumentFunction(
96
100
  memory,
97
101
  env,
98
102
  robotToken,
103
+ project,
104
+ runtime,
99
105
  },
100
106
  {
101
107
  skipValidation: true, // already done below
@@ -131,6 +137,8 @@ export function defineDocumentFunction(
131
137
  * })
132
138
  * ```
133
139
  * @param functionConfig The configuration for the media library asset function
140
+ * @public
141
+ * @category Definers
134
142
  * @returns The validated media library asset function resource
135
143
  */
136
144
  export function defineMediaLibraryAssetFunction(
@@ -139,7 +147,7 @@ export function defineMediaLibraryAssetFunction(
139
147
  Pick<BlueprintMediaLibraryAssetFunctionResource, 'event'> &
140
148
  Partial<BlueprintMediaLibraryFunctionResourceEvent>,
141
149
  ): BlueprintMediaLibraryAssetFunctionResource {
142
- let {name, src, event, timeout, memory, env, type, robotToken} = functionConfig
150
+ let {name, src, event, timeout, memory, env, type, robotToken, project, runtime} = functionConfig
143
151
  if (!type) type = 'sanity.function.media-library.asset'
144
152
 
145
153
  const functionResource: BlueprintMediaLibraryAssetFunctionResource = {
@@ -151,6 +159,8 @@ export function defineMediaLibraryAssetFunction(
151
159
  memory,
152
160
  env,
153
161
  robotToken,
162
+ project,
163
+ runtime,
154
164
  },
155
165
  {
156
166
  skipValidation: true, // already done below
@@ -167,23 +177,45 @@ export function defineMediaLibraryAssetFunction(
167
177
 
168
178
  /**
169
179
  * Defines a function that is triggered on a schedule.
180
+ * Supports cron expressions or natural language schedules.
181
+ *
170
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
171
203
  * defineScheduleFunction({
172
204
  * name: 'my-schedule-function',
173
- * src: 'functions/schedule-function',
174
- * memory: 3,
175
- * timeout: 300,
176
205
  * event: {
177
- * minute: "0",
178
- * hour: "0",
179
- * dayOfMonth: "*",
180
- * month: "*",
181
- * dayOfWeek: "*",
206
+ * minute: '0',
207
+ * hour: '9',
208
+ * dayOfMonth: '*',
209
+ * month: '*',
210
+ * dayOfWeek: '*',
182
211
  * },
183
212
  * })
184
213
  * ```
185
- * @beta
186
- * @param functionConfig The configuration for the document function
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
187
219
  * @returns The validated schedule function resource
188
220
  */
189
221
  export function defineScheduleFunction(
@@ -192,7 +224,7 @@ export function defineScheduleFunction(
192
224
  Pick<BlueprintScheduleFunctionResource, 'event'> &
193
225
  Partial<BlueprintScheduleFunctionResourceEvent>,
194
226
  ): BlueprintScheduleFunctionResource {
195
- let {name, src, event, timeout, memory, env, type, timezone} = functionConfig
227
+ let {name, src, event, timeout, memory, env, type, timezone, runtime} = functionConfig
196
228
  if (!type) type = 'sanity.function.cron'
197
229
 
198
230
  const functionResource: BlueprintScheduleFunctionResource = {
@@ -203,6 +235,7 @@ export function defineScheduleFunction(
203
235
  timeout,
204
236
  memory,
205
237
  env,
238
+ runtime,
206
239
  },
207
240
  {
208
241
  skipValidation: true, // already done below
@@ -217,6 +250,11 @@ export function defineScheduleFunction(
217
250
 
218
251
  runValidation(() => validateScheduleFunction(functionResource))
219
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
+
220
258
  return functionResource
221
259
  }
222
260
 
@@ -228,6 +266,7 @@ export function defineScheduleFunction(
228
266
  * src: 'functions/my-function',
229
267
  * timeout: 300,
230
268
  * memory: 1,
269
+ * runtime: 'nodejs24.x',
231
270
  * env: {
232
271
  * MY_ENV_VAR: 'my-custom-value'
233
272
  * },
@@ -235,13 +274,15 @@ export function defineScheduleFunction(
235
274
  * ```
236
275
  * @param functionConfig The configuration for the function
237
276
  * @param options Optional configuration including validation options
277
+ * @category Definers
278
+ * @internal
238
279
  * @returns The validated function resource
239
280
  */
240
281
  export function defineFunction(
241
282
  functionConfig: Partial<BlueprintBaseFunctionResource> & RequiredFunctionProperties,
242
283
  options?: {skipValidation?: boolean},
243
284
  ): BlueprintBaseFunctionResource {
244
- let {name, src, timeout, memory, env, type, robotToken} = functionConfig
285
+ let {name, src, timeout, memory, env, type, robotToken, project, runtime} = functionConfig
245
286
 
246
287
  // defaults
247
288
  if (!src) src = `functions/${name}`
@@ -255,6 +296,8 @@ export function defineFunction(
255
296
  memory,
256
297
  env,
257
298
  robotToken,
299
+ project,
300
+ runtime,
258
301
  }
259
302
 
260
303
  if (options?.skipValidation !== true) runValidation(() => validateFunction(functionResource))
@@ -297,10 +340,14 @@ function buildMediaLibraryFunctionEvent(event: BlueprintMediaLibraryFunctionReso
297
340
  return fullEvent
298
341
  }
299
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
+ */
300
349
  function buildScheduleFunctionEvent(event: BlueprintScheduleFunctionResourceEvent): BlueprintScheduleFunctionResourceEvent {
301
- const cleanEvent = Object.fromEntries(
350
+ return Object.fromEntries(
302
351
  Object.entries(event).filter(([key]) => SCHEDULE_EVENT_KEYS.has(key as ScheduleFunctionEventKey)),
303
352
  ) as BlueprintScheduleFunctionResourceEvent
304
-
305
- return cleanEvent
306
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 = {
@@ -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
@@ -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
@@ -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
+ */
@@ -1,19 +1,28 @@
1
1
  import type {BlueprintResource} from '../index.js'
2
2
 
3
- /** Additional configuration on a Blueprint that overrides the normal configuration */
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
- /** A key-value pair that will be output from a Blueprint */
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
- /** A representation of a Blueprint document */
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
- /** The result of defining a blueprint with `defineBlueprint` */
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
  /**
@@ -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. */
@@ -1,4 +1,7 @@
1
- /** Standard error shape returned by validation functions */
1
+ /**
2
+ * Standard error shape returned by validation functions
3
+ * @internal
4
+ */
2
5
  export interface BlueprintError {
3
6
  message: string
4
7
  type: string
@@ -2,7 +2,10 @@ import type {BlueprintResource} from '../index.js'
2
2
 
3
3
  // --- Function Event Types ---
4
4
 
5
- /** Base event configuration shared by document and media library function types */
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
- /** Event configuration for document functions */
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
- /** Event configuration for media library asset functions */
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
- /** Union type of all function resource event configurations */
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
- * Dataset resource for scoping document functions to specific datasets
33
- * @example { type: 'dataset', id: 'my-project.production' }
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
- interface BlueprintFunctionResourceEventResourceDataset {
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
- /** @description A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
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
- /** Media library resource for scoping media library functions */
55
- interface BlueprintFunctionResourceEventResourceMediaLibrary {
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
- /** Events that can trigger a function */
61
- type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update'
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
- /** Base function resource with common properties for all function types */
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
@@ -76,19 +129,44 @@ export interface BlueprintBaseFunctionResource extends BlueprintResource {
76
129
  env?: Record<string, string>
77
130
  /** Token provided during function invocation */
78
131
  robotToken?: string
132
+
133
+ /**
134
+ * The project ID of the project that contains your function.
135
+ *
136
+ * The `project` attribute must be defined if your blueprint is scoped to an organization. */
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
79
144
  }
80
- /** A function resource triggered by document events in Sanity datasets */
145
+
146
+ /**
147
+ * A function resource triggered by document events in Sanity datasets
148
+ * @category Functions Types
149
+ */
81
150
  export interface BlueprintDocumentFunctionResource extends BlueprintBaseFunctionResource {
82
151
  type: 'sanity.function.document'
83
152
  /** Event configuration specifying when and how the function is triggered */
84
153
  event: BlueprintDocumentFunctionResourceEvent
85
154
  }
86
- /** A function resource triggered by media library asset events */
155
+
156
+ /**
157
+ * A function resource triggered by media library asset events
158
+ * @category Functions Types
159
+ */
87
160
  export interface BlueprintMediaLibraryAssetFunctionResource extends BlueprintBaseFunctionResource {
88
161
  type: 'sanity.function.media-library.asset'
89
162
  /** Event configuration specifying when and how the function is triggered */
90
163
  event: BlueprintMediaLibraryFunctionResourceEvent
91
164
  }
165
+
166
+ /**
167
+ * A function resource triggered by schedule events
168
+ * @category Functions Types
169
+ */
92
170
  export interface BlueprintScheduleFunctionResource extends BlueprintBaseFunctionResource {
93
171
  type: 'sanity.function.cron'
94
172
  event: BlueprintScheduleFunctionResourceEvent
@@ -5,24 +5,35 @@
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'
16
18
  /** The identifier of the resource to be attached to the current stack */
17
19
  id: string
18
20
  }
21
+ /**
22
+ * An ownership action that will cause the referenced resource to be detached from the current stack.
23
+ * @category Blueprint Internals
24
+ */
25
+ export interface BlueprintOwnershipDetachAction {
26
+ type: 'detach'
27
+ }
19
28
  /**
20
29
  * A union of all possible ownership actions.
30
+ * @category Blueprint Internals
21
31
  */
22
- export type BlueprintOwnershipAction = BlueprintOwnershipAttachAction
32
+ export type BlueprintOwnershipAction = BlueprintOwnershipAttachAction | BlueprintOwnershipDetachAction
23
33
 
24
34
  /**
25
35
  * An ownership action that will cause the referenced project-contained resource to be attached to the current stack.
36
+ * @category Blueprint Internals
26
37
  */
27
38
  export interface BlueprintProjectOwnershipAttachAction extends BlueprintOwnershipAttachAction {
28
39
  /** The identifier of the project for resources contained in a project */
@@ -30,11 +41,13 @@ export interface BlueprintProjectOwnershipAttachAction extends BlueprintOwnershi
30
41
  }
31
42
  /**
32
43
  * A union of all possible ownership actions for resources belonging to projects.
44
+ * @category Blueprint Internals
33
45
  */
34
46
  export type BlueprintProjectOwnershipAction = BlueprintProjectOwnershipAttachAction
35
47
 
36
48
  /**
37
49
  * Defines the lifcycle policy for this resource.
50
+ * @category Blueprint Internals
38
51
  */
39
52
  export interface BlueprintResourceLifecycle {
40
53
  deletionPolicy?: BlueprintResourceDeletionPolicy
@@ -44,6 +57,7 @@ export interface BlueprintResourceLifecycle {
44
57
 
45
58
  /**
46
59
  * Defines the lifcycle policy for this resource.
60
+ * @category Blueprint Internals
47
61
  */
48
62
  export interface BlueprintProjectResourceLifecycle extends BlueprintResourceLifecycle {
49
63
  ownershipAction?: BlueprintProjectOwnershipAction
@@ -51,6 +65,7 @@ export interface BlueprintProjectResourceLifecycle extends BlueprintResourceLife
51
65
 
52
66
  /**
53
67
  * The base type for all resources.
68
+ * @category Blueprint Internals
54
69
  */
55
70
  export interface BlueprintResource<Lifecycle extends BlueprintResourceLifecycle = BlueprintResourceLifecycle> {
56
71
  type: string