@sanity/blueprints 0.10.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.
Files changed (112) hide show
  1. package/README.md +55 -20
  2. package/dist/definers/blueprints.d.ts +17 -3
  3. package/dist/definers/blueprints.js +42 -3
  4. package/dist/definers/blueprints.js.map +1 -1
  5. package/dist/definers/cors.d.ts +9 -2
  6. package/dist/definers/cors.js +21 -2
  7. package/dist/definers/cors.js.map +1 -1
  8. package/dist/definers/datasets.d.ts +10 -2
  9. package/dist/definers/datasets.js +23 -2
  10. package/dist/definers/datasets.js.map +1 -1
  11. package/dist/definers/functions.d.ts +58 -53
  12. package/dist/definers/functions.js +101 -86
  13. package/dist/definers/functions.js.map +1 -1
  14. package/dist/definers/resources.d.ts +12 -0
  15. package/dist/definers/resources.js +23 -0
  16. package/dist/definers/resources.js.map +1 -1
  17. package/dist/definers/robotTokens.d.ts +22 -0
  18. package/dist/definers/robotTokens.js +53 -0
  19. package/dist/definers/robotTokens.js.map +1 -0
  20. package/dist/definers/robots.d.ts +2 -18
  21. package/dist/definers/robots.js +2 -29
  22. package/dist/definers/robots.js.map +1 -1
  23. package/dist/definers/roles.d.ts +22 -25
  24. package/dist/definers/roles.js +70 -23
  25. package/dist/definers/roles.js.map +1 -1
  26. package/dist/definers/webhooks.d.ts +9 -2
  27. package/dist/definers/webhooks.js +29 -2
  28. package/dist/definers/webhooks.js.map +1 -1
  29. package/dist/index.d.ts +23 -0
  30. package/dist/index.js +24 -0
  31. package/dist/index.js.map +1 -1
  32. package/dist/types/blueprints.d.ts +16 -4
  33. package/dist/types/cors.d.ts +6 -0
  34. package/dist/types/datasets.d.ts +19 -3
  35. package/dist/types/errors.d.ts +4 -1
  36. package/dist/types/functions.d.ts +139 -17
  37. package/dist/types/functions.js +5 -1
  38. package/dist/types/functions.js.map +1 -1
  39. package/dist/types/resources.d.ts +17 -0
  40. package/dist/types/robotTokens.d.ts +45 -0
  41. package/dist/types/robotTokens.js +2 -0
  42. package/dist/types/robotTokens.js.map +1 -0
  43. package/dist/types/robots.d.ts +8 -30
  44. package/dist/types/robots.js +1 -0
  45. package/dist/types/robots.js.map +1 -1
  46. package/dist/types/roles.d.ts +12 -3
  47. package/dist/types/webhooks.d.ts +23 -5
  48. package/dist/utils/schedule-parser.d.ts +42 -0
  49. package/dist/utils/schedule-parser.js +450 -0
  50. package/dist/utils/schedule-parser.js.map +1 -0
  51. package/dist/utils/validation.d.ts +1 -0
  52. package/dist/utils/validation.js +1 -0
  53. package/dist/utils/validation.js.map +1 -1
  54. package/dist/validation/blueprints.d.ts +1 -0
  55. package/dist/validation/blueprints.js +1 -0
  56. package/dist/validation/blueprints.js.map +1 -1
  57. package/dist/validation/cors.d.ts +1 -0
  58. package/dist/validation/cors.js +1 -0
  59. package/dist/validation/cors.js.map +1 -1
  60. package/dist/validation/datasets.d.ts +2 -0
  61. package/dist/validation/datasets.js +2 -0
  62. package/dist/validation/datasets.js.map +1 -1
  63. package/dist/validation/functions.d.ts +11 -0
  64. package/dist/validation/functions.js +37 -1
  65. package/dist/validation/functions.js.map +1 -1
  66. package/dist/validation/resources.d.ts +7 -1
  67. package/dist/validation/resources.js +20 -14
  68. package/dist/validation/resources.js.map +1 -1
  69. package/dist/validation/robotTokens.d.ts +15 -0
  70. package/dist/validation/robotTokens.js +104 -0
  71. package/dist/validation/robotTokens.js.map +1 -0
  72. package/dist/validation/robots.d.ts +4 -8
  73. package/dist/validation/robots.js +5 -96
  74. package/dist/validation/robots.js.map +1 -1
  75. package/dist/validation/roles.d.ts +3 -1
  76. package/dist/validation/roles.js +3 -1
  77. package/dist/validation/roles.js.map +1 -1
  78. package/dist/validation/webhooks.d.ts +1 -0
  79. package/dist/validation/webhooks.js +1 -0
  80. package/dist/validation/webhooks.js.map +1 -1
  81. package/package.json +7 -4
  82. package/src/definers/blueprints.ts +42 -3
  83. package/src/definers/cors.ts +21 -2
  84. package/src/definers/datasets.ts +23 -2
  85. package/src/definers/functions.ts +159 -123
  86. package/src/definers/resources.ts +23 -0
  87. package/src/definers/robotTokens.ts +56 -0
  88. package/src/definers/robots.ts +2 -33
  89. package/src/definers/roles.ts +70 -23
  90. package/src/definers/webhooks.ts +29 -2
  91. package/src/index.ts +25 -0
  92. package/src/types/blueprints.ts +16 -4
  93. package/src/types/cors.ts +6 -0
  94. package/src/types/datasets.ts +19 -3
  95. package/src/types/errors.ts +4 -1
  96. package/src/types/functions.ts +156 -16
  97. package/src/types/resources.ts +17 -1
  98. package/src/types/robotTokens.ts +50 -0
  99. package/src/types/robots.ts +10 -35
  100. package/src/types/roles.ts +12 -3
  101. package/src/types/webhooks.ts +23 -5
  102. package/src/utils/schedule-parser.ts +502 -0
  103. package/src/utils/validation.ts +1 -0
  104. package/src/validation/blueprints.ts +1 -0
  105. package/src/validation/cors.ts +1 -0
  106. package/src/validation/datasets.ts +2 -0
  107. package/src/validation/functions.ts +37 -0
  108. package/src/validation/resources.ts +20 -14
  109. package/src/validation/robotTokens.ts +103 -0
  110. package/src/validation/robots.ts +5 -95
  111. package/src/validation/roles.ts +3 -1
  112. package/src/validation/webhooks.ts +1 -0
@@ -1,33 +1,2 @@
1
- import {type BlueprintRobotConfig, type BlueprintRobotResource, validateRobot} from '../index.js'
2
- import {runValidation} from '../utils/validation.js'
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
- */
20
- export function defineRobot(parameters: BlueprintRobotConfig): BlueprintRobotResource {
21
- // default robot label
22
- const label = parameters.label || parameters.name
23
-
24
- const robotResource: BlueprintRobotResource = {
25
- ...parameters,
26
- label,
27
- type: 'sanity.access.robot',
28
- }
29
-
30
- runValidation(() => validateRobot(robotResource))
31
-
32
- return robotResource
33
- }
1
+ /** @deprecated Use {@link defineRobotToken} instead @hidden */
2
+ export {defineRobotToken as defineRobot} from './robotTokens.js'
@@ -7,27 +7,48 @@ import {
7
7
  } from '../index.js'
8
8
  import {runValidation} from '../utils/validation.js'
9
9
 
10
- /**
11
- * Defines a role that is scoped to the same resource as the blueprint.
12
- * ```
10
+ /*
11
+ * FUTURE example (move below @example when ready)
12
+ * @example All options
13
+ * ```ts
13
14
  * defineRole({
14
- * name: 'custom-robot-role',
15
- * title: 'Custom Robot Role',
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
48
+ * @public
49
+ * @beta Deploying Roles via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
50
+ * @category Definers
51
+ * @expandType BlueprintRoleConfig
31
52
  * @returns The role resource
32
53
  */
33
54
  export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValidation?: boolean}): BlueprintRoleResource {
@@ -50,26 +71,52 @@ export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValid
50
71
  return roleResource
51
72
  }
52
73
 
53
- /**
54
- * Defines a role that is scoped to the specified project.
55
- * ```
56
- * defineProjectRole(projectId, {
57
- * name: 'custom-robot-role',
58
- * title: 'Custom Robot Role',
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',
59
81
  * appliesToRobots: true,
60
- * appliesToUsers: false,
61
82
  * permissions: [{
62
83
  * name: 'sanity-project-cors',
63
- * action: 'create'
84
+ * action: 'create',
64
85
  * }, {
65
86
  * name: 'sanity-project-cors',
66
- * action: 'read'
67
- * }, {
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: [{
68
110
  * name: 'sanity-project-cors',
69
- * action: 'delete'
70
- * }]
71
- * }),
111
+ * action: 'read',
112
+ * }],
113
+ * })
72
114
  * ```
115
+ * @public
116
+ * @beta Deploying Roles via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
117
+ * @hidden
118
+ * @category Definers
119
+ * @expandType BlueprintRoleConfig
73
120
  * @param projectId The ID of the project to which the role will be scoped
74
121
  * @param parameters The configuration of the role
75
122
  * @returns The role resource
@@ -1,18 +1,45 @@
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: 'staging'
33
+ * dataset: 'production',
34
+ * apiVersion: 'v2026-01-01',
13
35
  * })
14
36
  * ```
15
37
  * @param parameters The webhook configuration
38
+ * @public
39
+ * @beta Deploying Webhooks via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
40
+ * @category Definers
41
+ * @expandType BlueprintDocumentWebhookConfig
42
+ * @returns The webhook resource
16
43
  */
17
44
  export function defineDocumentWebhook(parameters: BlueprintDocumentWebhookConfig): BlueprintDocumentWebhookResource {
18
45
  // default the display name
package/src/index.ts CHANGED
@@ -1,14 +1,27 @@
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'
5
9
  export * from './definers/functions.js'
6
10
  export * from './definers/resources.js'
7
11
  export * from './definers/robots.js'
12
+ export * from './definers/robotTokens.js'
8
13
  export * from './definers/roles.js'
9
14
  export * from './definers/webhooks.js'
10
15
 
11
16
  // TYPES - base types for all resources
17
+ /**
18
+ * @categoryDescription Resource Types
19
+ * These types are used to define the shape of resources in a Blueprint.
20
+ */
21
+ /**
22
+ * @categoryDescription Functions Types
23
+ * Resource types for functions in a Blueprint.
24
+ */
12
25
  export * from './types/blueprints.js'
13
26
  export * from './types/cors.js'
14
27
  export * from './types/datasets.js'
@@ -16,15 +29,27 @@ export * from './types/errors.js'
16
29
  export * from './types/functions.js'
17
30
  export * from './types/resources.js'
18
31
  export * from './types/robots.js'
32
+ export * from './types/robotTokens.js'
19
33
  export * from './types/roles.js'
20
34
  export * from './types/webhooks.js'
21
35
 
22
36
  // VALIDATION - validation for all resources
37
+ /**
38
+ * @categoryDescription Validation
39
+ * These functions are used to validate resources in a Blueprint.
40
+ */
23
41
  export * from './validation/blueprints.js'
24
42
  export * from './validation/cors.js'
25
43
  export * from './validation/datasets.js'
26
44
  export * from './validation/functions.js'
27
45
  export * from './validation/resources.js'
28
46
  export * from './validation/robots.js'
47
+ export * from './validation/robotTokens.js'
29
48
  export * from './validation/roles.js'
30
49
  export * from './validation/webhooks.js'
50
+
51
+ // Public BLUEPRINTS INTERNALS - published bucket of misc Blueprint types
52
+ /**
53
+ * @categoryDescription Blueprint Internals
54
+ * Miscellaneous Blueprint types that make up the public API but are not exported directly.
55
+ */
@@ -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,9 @@ 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
38
+ * @interface
34
39
  */
35
40
  export type BlueprintCorsOriginConfig = Omit<BlueprintCorsOriginResource, 'type' | 'allowCredentials'> & {
36
41
  /**
@@ -39,6 +44,7 @@ export type BlueprintCorsOriginConfig = Omit<BlueprintCorsOriginResource, 'type'
39
44
  * If this origin hosts a studio, you will need to allow credentials. Otherwise, you should probably select not to allow credentials.
40
45
  *
41
46
  * Allowing credentials from wildcard origins is dangerous. Any domain that matches the given pattern will be able to send requests on the user's behalf if they are logged in to your studio.
47
+ * @defaultValue false
42
48
  */
43
49
  allowCredentials?: boolean
44
50
  }
@@ -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,8 +33,15 @@ 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
39
+ * @interface
27
40
  */
28
41
  export type BlueprintDatasetConfig = Omit<BlueprintDatasetResource, 'type' | 'datasetName'> & {
29
- /** The name of the dataset. Must be unique within a project. Defaults to the name of the resource. */
42
+ /**
43
+ * The name of the dataset. Must be unique within a project.
44
+ * @defaultValue The `name` of the resource
45
+ */
30
46
  datasetName?: string
31
47
  }
@@ -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,9 +2,15 @@ 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
- /** Event types that trigger the function. Defaults to ['publish'] */
10
+ /**
11
+ * Event types that trigger the function
12
+ * @defaultValue ['publish']
13
+ */
8
14
  on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]]
9
15
  /** GROQ filter expression to match specific documents (e.g., "_type == 'post'") */
10
16
  filter?: string
@@ -13,24 +19,37 @@ export interface BlueprintFunctionBaseResourceEvent {
13
19
  /** Include draft documents in addition to published documents */
14
20
  includeDrafts?: boolean
15
21
  }
16
- /** Event configuration for document functions */
22
+
23
+ /**
24
+ * Event configuration for document functions
25
+ * @category Functions Types
26
+ */
17
27
  export interface BlueprintDocumentFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
18
28
  /** Include all versions of documents, not just the current version */
19
29
  includeAllVersions?: boolean
20
30
  /** Optional dataset resource scoping for the function */
21
31
  resource?: BlueprintFunctionResourceEventResourceDataset
22
32
  }
23
- /** Event configuration for media library asset functions */
33
+
34
+ /**
35
+ * Event configuration for media library asset functions
36
+ * @category Functions Types
37
+ */
24
38
  export interface BlueprintMediaLibraryFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
25
39
  /** Media library resource scoping (required for media library functions) */
26
40
  resource: BlueprintFunctionResourceEventResourceMediaLibrary
27
41
  }
28
- /** Union type of all function resource event configurations */
42
+
43
+ /**
44
+ * Union type of all function resource event configurations
45
+ * @category Functions Types
46
+ */
29
47
  export type BlueprintFunctionResourceEvent = BlueprintDocumentFunctionResourceEvent | BlueprintMediaLibraryFunctionResourceEvent
30
48
 
31
49
  /**
32
- * Dataset resource for scoping document functions to specific datasets
33
- * @example { type: 'dataset', id: 'my-project.production' }
50
+ * Explicit resource event for schedule functions to specific minutes, hours, days of month, months, and days of week
51
+ * @example { minute: '0', hour: '9', dayOfMonth: '1', month: '1', dayOfWeek: '1' }
52
+ * @category Functions Types
34
53
  */
35
54
  export interface BlueprintScheduleFunctionExplicitResourceEvent {
36
55
  minute: string
@@ -39,30 +58,67 @@ export interface BlueprintScheduleFunctionExplicitResourceEvent {
39
58
  month: string
40
59
  dayOfWeek: string
41
60
  }
61
+
62
+ /**
63
+ * Expression resource for schedule functions to specific expressions
64
+ * @example { expression: '0 9 * * *' }
65
+ * @category Functions Types
66
+ */
42
67
  export interface BlueprintScheduleFunctionExpressionResourceEvent {
43
68
  expression: string
44
69
  }
70
+
71
+ /**
72
+ * Union type of all schedule function resource event configurations
73
+ * @category Functions Types
74
+ */
45
75
  export type BlueprintScheduleFunctionResourceEvent =
46
76
  | BlueprintScheduleFunctionExplicitResourceEvent
47
77
  | BlueprintScheduleFunctionExpressionResourceEvent
48
78
 
49
- interface BlueprintFunctionResourceEventResourceDataset {
79
+ /**
80
+ * Dataset resource for scoping document functions to specific datasets
81
+ * @example { type: 'dataset', id: 'my-project.production' }
82
+ * @category Functions Types
83
+ */
84
+ export interface BlueprintFunctionResourceEventResourceDataset {
50
85
  type: 'dataset'
51
- /** @description A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
86
+ /** A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
52
87
  id: string
53
88
  }
54
- /** Media library resource for scoping media library functions */
55
- interface BlueprintFunctionResourceEventResourceMediaLibrary {
89
+
90
+ /**
91
+ * Media library resource for scoping media library functions
92
+ * @category Functions Types
93
+ */
94
+ export interface BlueprintFunctionResourceEventResourceMediaLibrary {
56
95
  type: 'media-library'
57
96
  id: string
58
97
  }
59
98
 
60
- /** Events that can trigger a function */
61
- type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update'
99
+ /**
100
+ * Events that can trigger a function
101
+ * @category Functions Types
102
+ */
103
+ export type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update'
104
+
105
+ /**
106
+ * Current support Function runtimes
107
+ * @category Functions Types
108
+ */
109
+ export const VALID_RUNTIMES = ['node', 'nodejs22.x', 'nodejs24.x'] as const
110
+ /**
111
+ * Supported function runtimes
112
+ * @category Functions Types
113
+ */
114
+ export type FunctionRuntimes = (typeof VALID_RUNTIMES)[number]
62
115
 
63
116
  // --- Main Function Types ---
64
117
 
65
- /** Base function resource with common properties for all function types */
118
+ /**
119
+ * Base function resource with common properties for all function types
120
+ * @category Functions Types
121
+ */
66
122
  export interface BlueprintBaseFunctionResource extends BlueprintResource {
67
123
  /** Human-readable display name for the function */
68
124
  displayName?: string
@@ -82,21 +138,105 @@ export interface BlueprintBaseFunctionResource extends BlueprintResource {
82
138
  *
83
139
  * The `project` attribute must be defined if your blueprint is scoped to an organization. */
84
140
  project?: string
141
+
142
+ /**
143
+ * The runtime environment for the function (currently only Node.js is supported)
144
+ * @defaultValue 'nodejs24.x'
145
+ */
146
+ runtime?: FunctionRuntimes
85
147
  }
86
- /** A function resource triggered by document events in Sanity datasets */
148
+
149
+ /**
150
+ * A function resource triggered by document events in Sanity datasets
151
+ * @category Functions Types
152
+ */
87
153
  export interface BlueprintDocumentFunctionResource extends BlueprintBaseFunctionResource {
88
154
  type: 'sanity.function.document'
89
155
  /** Event configuration specifying when and how the function is triggered */
90
156
  event: BlueprintDocumentFunctionResourceEvent
91
157
  }
92
- /** A function resource triggered by media library asset events */
158
+
159
+ /**
160
+ * A function resource triggered by media library asset events
161
+ * @category Functions Types
162
+ */
93
163
  export interface BlueprintMediaLibraryAssetFunctionResource extends BlueprintBaseFunctionResource {
94
164
  type: 'sanity.function.media-library.asset'
95
165
  /** Event configuration specifying when and how the function is triggered */
96
166
  event: BlueprintMediaLibraryFunctionResourceEvent
97
167
  }
168
+
169
+ /**
170
+ * A function resource triggered by schedule events
171
+ * @category Functions Types
172
+ */
98
173
  export interface BlueprintScheduleFunctionResource extends BlueprintBaseFunctionResource {
99
174
  type: 'sanity.function.cron'
100
175
  event: BlueprintScheduleFunctionResourceEvent
101
176
  timezone?: string
102
177
  }
178
+
179
+ // --- Function Config Types ---
180
+
181
+ /**
182
+ * Configuration for defining a base function.
183
+ * @internal
184
+ * @category Functions Types
185
+ * @interface
186
+ */
187
+ export type BlueprintBaseFunctionConfig = Omit<BlueprintBaseFunctionResource, 'type' | 'src'> & {
188
+ /**
189
+ * Path to the function source code
190
+ * @defaultValue `functions/${name}`
191
+ */
192
+ src?: string
193
+ }
194
+
195
+ /**
196
+ * Configuration for defining a document function.
197
+ * @public
198
+ * @category Functions Types
199
+ * @interface
200
+ */
201
+ export type BlueprintDocumentFunctionConfig = Omit<BlueprintDocumentFunctionResource, 'type' | 'src' | 'event'> & {
202
+ /**
203
+ * Path to the function source code
204
+ * @defaultValue `functions/${name}`
205
+ */
206
+ src?: string
207
+ /**
208
+ * Event configuration specifying when and how the function is triggered
209
+ * @defaultValue `{on: ['publish']}`
210
+ */
211
+ event?: BlueprintDocumentFunctionResourceEvent
212
+ }
213
+
214
+ /**
215
+ * Configuration for defining a media library asset function.
216
+ * @public
217
+ * @category Functions Types
218
+ * @interface
219
+ */
220
+ export type BlueprintMediaLibraryAssetFunctionConfig = Omit<BlueprintMediaLibraryAssetFunctionResource, 'type' | 'src'> & {
221
+ /**
222
+ * Path to the function source code
223
+ * @defaultValue `functions/${name}`
224
+ */
225
+ src?: string
226
+ }
227
+
228
+ /**
229
+ * Configuration for defining a schedule function.
230
+ * @public
231
+ * @alpha Deploying Schedule Functions via Blueprints is experimental. This feature is not available publicly yet.
232
+ * @hidden
233
+ * @category Functions Types
234
+ * @interface
235
+ */
236
+ export type BlueprintScheduleFunctionConfig = Omit<BlueprintScheduleFunctionResource, 'type' | 'src'> & {
237
+ /**
238
+ * Path to the function source code
239
+ * @defaultValue `functions/${name}`
240
+ */
241
+ src?: string
242
+ }