@sanity/blueprints 0.13.1 → 0.15.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 (48) hide show
  1. package/dist/definers/functions.d.ts +33 -1
  2. package/dist/definers/functions.js +42 -1
  3. package/dist/definers/functions.js.map +1 -1
  4. package/dist/definers/projects.d.ts +20 -2
  5. package/dist/definers/projects.js +22 -2
  6. package/dist/definers/projects.js.map +1 -1
  7. package/dist/definers/resources.d.ts +9 -1
  8. package/dist/definers/resources.js +22 -0
  9. package/dist/definers/resources.js.map +1 -1
  10. package/dist/definers/robotTokens.d.ts +19 -1
  11. package/dist/definers/robotTokens.js +21 -1
  12. package/dist/definers/robotTokens.js.map +1 -1
  13. package/dist/definers/roles.d.ts +19 -1
  14. package/dist/definers/roles.js +21 -1
  15. package/dist/definers/roles.js.map +1 -1
  16. package/dist/index.d.ts +5 -1
  17. package/dist/index.js +5 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/types/datasets.d.ts +2 -0
  20. package/dist/types/functions/event.d.ts +96 -0
  21. package/dist/types/functions/event.js +3 -0
  22. package/dist/types/functions/event.js.map +1 -0
  23. package/dist/types/{functions.d.ts → functions/index.d.ts} +27 -90
  24. package/dist/types/{functions.js → functions/index.js} +3 -2
  25. package/dist/types/functions/index.js.map +1 -0
  26. package/dist/types/resources.d.ts +35 -2
  27. package/dist/validation/datasets.js +6 -0
  28. package/dist/validation/datasets.js.map +1 -1
  29. package/dist/validation/functions.d.ts +9 -0
  30. package/dist/validation/functions.js +39 -4
  31. package/dist/validation/functions.js.map +1 -1
  32. package/dist/validation/resources.js +15 -1
  33. package/dist/validation/resources.js.map +1 -1
  34. package/package.json +1 -1
  35. package/src/definers/functions.ts +50 -0
  36. package/src/definers/projects.ts +30 -2
  37. package/src/definers/resources.ts +26 -1
  38. package/src/definers/robotTokens.ts +29 -1
  39. package/src/definers/roles.ts +24 -0
  40. package/src/index.ts +5 -1
  41. package/src/types/datasets.ts +2 -0
  42. package/src/types/functions/event.ts +114 -0
  43. package/src/types/{functions.ts → functions/index.ts} +34 -103
  44. package/src/types/resources.ts +40 -2
  45. package/src/validation/datasets.ts +7 -0
  46. package/src/validation/functions.ts +40 -4
  47. package/src/validation/resources.ts +13 -1
  48. package/dist/types/functions.js.map +0 -1
package/src/index.ts CHANGED
@@ -3,6 +3,10 @@
3
3
  * @categoryDescription Definers
4
4
  * These functions are used to define resources in a Blueprint.
5
5
  */
6
+ /**
7
+ * @categoryDescription Referencers
8
+ * These functions are used to reference resources in another Blueprint.
9
+ */
6
10
  export * from './definers/blueprints.js'
7
11
  export * from './definers/cors.js'
8
12
  export * from './definers/datasets.js'
@@ -27,7 +31,7 @@ export * from './types/blueprints.js'
27
31
  export * from './types/cors.js'
28
32
  export * from './types/datasets.js'
29
33
  export * from './types/errors.js'
30
- export * from './types/functions.js'
34
+ export * from './types/functions/index.js'
31
35
  export * from './types/projects.js'
32
36
  export * from './types/resources.js'
33
37
  export * from './types/robots.js'
@@ -19,6 +19,8 @@ export interface BlueprintDatasetResource extends BlueprintResource<BlueprintPro
19
19
  type: 'sanity.project.dataset'
20
20
  /** The name of the dataset. Must be unique within a project. */
21
21
  datasetName: string
22
+ /** The dataset description */
23
+ description?: string
22
24
  /** The ACL mode to set for the new dataset. Defaults to public. */
23
25
  aclMode?: AclMode
24
26
 
@@ -0,0 +1,114 @@
1
+ // --- Function Event Types ---
2
+
3
+ /**
4
+ * Base event configuration shared by document and media library function types
5
+ * @category Functions Types
6
+ */
7
+ export interface BlueprintFunctionBaseResourceEvent {
8
+ /**
9
+ * Event types that trigger the function
10
+ * @defaultValue ['publish']
11
+ */
12
+ on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]]
13
+ /** GROQ filter expression to match specific documents (e.g., "_type == 'post'") */
14
+ filter?: string
15
+ /** GROQ projection to specify which fields to include (e.g., "{_id, title, slug}") */
16
+ projection?: `{${string}}`
17
+ /** Include draft documents in addition to published documents */
18
+ includeDrafts?: boolean
19
+ }
20
+
21
+ /**
22
+ * Event configuration for document functions
23
+ * @category Functions Types
24
+ */
25
+ export interface BlueprintDocumentFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
26
+ /** Include all versions of documents, not just the current version */
27
+ includeAllVersions?: boolean
28
+ /** Optional dataset resource scoping for the function */
29
+ resource?: BlueprintFunctionResourceEventResourceDataset
30
+ }
31
+
32
+ /**
33
+ * Event configuration for media library asset functions
34
+ * @category Functions Types
35
+ */
36
+ export interface BlueprintMediaLibraryFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
37
+ /** Media library resource scoping (required for media library functions) */
38
+ resource: BlueprintFunctionResourceEventResourceMediaLibrary
39
+ }
40
+
41
+ /**
42
+ * Event configuration for sync tag invalidate functions
43
+ * @category Functions Types
44
+ */
45
+ export interface BlueprintSyncTagInvalidateFunctionResourceEvent {
46
+ /** Optional dataset resource scoping for the function */
47
+ resource?: BlueprintFunctionResourceEventResourceDataset
48
+ }
49
+
50
+ /**
51
+ * Explicit resource event for scheduled functions to specific minutes, hours, days of month, months, and days of week
52
+ * @example { minute: '0', hour: '9', dayOfMonth: '1', month: '1', dayOfWeek: '1' }
53
+ * @category Functions Types
54
+ */
55
+ export interface BlueprintScheduledFunctionExplicitResourceEvent {
56
+ minute: string
57
+ hour: string
58
+ dayOfMonth: string
59
+ month: string
60
+ dayOfWeek: string
61
+ }
62
+
63
+ /**
64
+ * Expression resource for scheduled functions to specific expressions
65
+ * @example { expression: '0 9 * * *' }
66
+ * @category Functions Types
67
+ */
68
+ export interface BlueprintScheduledFunctionExpressionResourceEvent {
69
+ expression: string
70
+ }
71
+
72
+ /**
73
+ * Union type of all scheduled function resource event configurations
74
+ * @category Functions Types
75
+ */
76
+ export type BlueprintScheduledFunctionResourceEvent =
77
+ | BlueprintScheduledFunctionExplicitResourceEvent
78
+ | BlueprintScheduledFunctionExpressionResourceEvent
79
+
80
+ /**
81
+ * Union type of all function resource event configurations
82
+ * @category Functions Types
83
+ */
84
+ export type BlueprintFunctionResourceEvent =
85
+ | BlueprintDocumentFunctionResourceEvent
86
+ | BlueprintMediaLibraryFunctionResourceEvent
87
+ | BlueprintScheduledFunctionResourceEvent
88
+ | BlueprintSyncTagInvalidateFunctionResourceEvent
89
+
90
+ /**
91
+ * Dataset resource for scoping document functions to specific datasets
92
+ * @example { type: 'dataset', id: 'my-project.production' }
93
+ * @category Functions Types
94
+ */
95
+ export interface BlueprintFunctionResourceEventResourceDataset {
96
+ type: 'dataset'
97
+ /** A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
98
+ id: string
99
+ }
100
+
101
+ /**
102
+ * Media library resource for scoping media library functions
103
+ * @category Functions Types
104
+ */
105
+ export interface BlueprintFunctionResourceEventResourceMediaLibrary {
106
+ type: 'media-library'
107
+ id: string
108
+ }
109
+
110
+ /**
111
+ * Events that can trigger a function
112
+ * @category Functions Types
113
+ */
114
+ export type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update'
@@ -1,109 +1,15 @@
1
- import type {BlueprintResource} from '../index.js'
1
+ import type {BlueprintResource} from '../../index.js'
2
+ import type {
3
+ BlueprintDocumentFunctionResourceEvent,
4
+ BlueprintMediaLibraryFunctionResourceEvent,
5
+ BlueprintScheduledFunctionResourceEvent,
6
+ BlueprintSyncTagInvalidateFunctionResourceEvent,
7
+ } from './event.js'
2
8
 
3
- // --- Function Event Types ---
9
+ export * from './event.js'
4
10
 
5
11
  /**
6
- * Base event configuration shared by document and media library function types
7
- * @category Functions Types
8
- */
9
- export interface BlueprintFunctionBaseResourceEvent {
10
- /**
11
- * Event types that trigger the function
12
- * @defaultValue ['publish']
13
- */
14
- on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]]
15
- /** GROQ filter expression to match specific documents (e.g., "_type == 'post'") */
16
- filter?: string
17
- /** GROQ projection to specify which fields to include (e.g., "{_id, title, slug}") */
18
- projection?: `{${string}}`
19
- /** Include draft documents in addition to published documents */
20
- includeDrafts?: boolean
21
- }
22
-
23
- /**
24
- * Event configuration for document functions
25
- * @category Functions Types
26
- */
27
- export interface BlueprintDocumentFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
28
- /** Include all versions of documents, not just the current version */
29
- includeAllVersions?: boolean
30
- /** Optional dataset resource scoping for the function */
31
- resource?: BlueprintFunctionResourceEventResourceDataset
32
- }
33
-
34
- /**
35
- * Event configuration for media library asset functions
36
- * @category Functions Types
37
- */
38
- export interface BlueprintMediaLibraryFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
39
- /** Media library resource scoping (required for media library functions) */
40
- resource: BlueprintFunctionResourceEventResourceMediaLibrary
41
- }
42
-
43
- /**
44
- * Union type of all function resource event configurations
45
- * @category Functions Types
46
- */
47
- export type BlueprintFunctionResourceEvent = BlueprintDocumentFunctionResourceEvent | BlueprintMediaLibraryFunctionResourceEvent
48
-
49
- /**
50
- * Explicit resource event for scheduled 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
53
- */
54
- export interface BlueprintScheduledFunctionExplicitResourceEvent {
55
- minute: string
56
- hour: string
57
- dayOfMonth: string
58
- month: string
59
- dayOfWeek: string
60
- }
61
-
62
- /**
63
- * Expression resource for scheduled functions to specific expressions
64
- * @example { expression: '0 9 * * *' }
65
- * @category Functions Types
66
- */
67
- export interface BlueprintScheduledFunctionExpressionResourceEvent {
68
- expression: string
69
- }
70
-
71
- /**
72
- * Union type of all scheduled function resource event configurations
73
- * @category Functions Types
74
- */
75
- export type BlueprintScheduledFunctionResourceEvent =
76
- | BlueprintScheduledFunctionExplicitResourceEvent
77
- | BlueprintScheduledFunctionExpressionResourceEvent
78
-
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 {
85
- type: 'dataset'
86
- /** A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
87
- id: string
88
- }
89
-
90
- /**
91
- * Media library resource for scoping media library functions
92
- * @category Functions Types
93
- */
94
- export interface BlueprintFunctionResourceEventResourceMediaLibrary {
95
- type: 'media-library'
96
- id: string
97
- }
98
-
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
12
+ * Supported Function runtimes
107
13
  * @category Functions Types
108
14
  */
109
15
  export const VALID_RUNTIMES = ['node', 'nodejs22.x', 'nodejs24.x'] as const
@@ -176,6 +82,15 @@ export interface BlueprintScheduledFunctionResource extends BlueprintBaseFunctio
176
82
  timezone?: string
177
83
  }
178
84
 
85
+ /**
86
+ * A function resource triggered by sync tag invalidate events
87
+ * @category Functions Types
88
+ */
89
+ export interface BlueprintSyncTagInvalidateFunctionResource extends BlueprintBaseFunctionResource {
90
+ type: 'sanity.function.sync-tag-invalidate'
91
+ event?: BlueprintSyncTagInvalidateFunctionResourceEvent
92
+ }
93
+
179
94
  // --- Function Config Types ---
180
95
 
181
96
  /**
@@ -240,3 +155,19 @@ export type BlueprintScheduledFunctionConfig = Omit<BlueprintScheduledFunctionRe
240
155
  */
241
156
  src?: string
242
157
  }
158
+
159
+ /**
160
+ * Configuration for defining a sync tag invalidate function.
161
+ * @public
162
+ * @alpha Deploying Sync Tag Invalidate Functions via Blueprints is experimental. This feature is not available publicly yet.
163
+ * @hidden
164
+ * @category Functions Types
165
+ * @interface
166
+ */
167
+ export type BlueprintSyncTagInvalidateFunctionConfig = Omit<BlueprintSyncTagInvalidateFunctionResource, 'type' | 'src'> & {
168
+ /**
169
+ * Path to the function source code
170
+ * @defaultValue `functions/${name}`
171
+ */
172
+ src?: string
173
+ }
@@ -25,12 +25,25 @@ export interface BlueprintOwnershipAttachAction {
25
25
  export interface BlueprintOwnershipDetachAction {
26
26
  type: 'detach'
27
27
  }
28
+ /**
29
+ * An ownership action that will cause the resource to be read during deployment so it can be referenced
30
+ * by other resources. Note that referenced resources must be in the same project or organization as the
31
+ * current stack.
32
+ * @category Blueprint Internals
33
+ */
34
+ export interface BlueprintOwnershipReferenceAction {
35
+ type: 'reference'
36
+ /** The name or id of the stack where the resource is attached */
37
+ stack: string
38
+ /** The name of the resource to be referenced */
39
+ name: string
40
+ }
28
41
  /**
29
42
  * A union of all possible ownership actions.
30
43
  * @category Blueprint Internals
31
44
  * @expand
32
45
  */
33
- export type BlueprintOwnershipAction = BlueprintOwnershipAttachAction | BlueprintOwnershipDetachAction
46
+ export type BlueprintOwnershipAction = BlueprintOwnershipAttachAction | BlueprintOwnershipDetachAction | BlueprintOwnershipReferenceAction
34
47
 
35
48
  /**
36
49
  * An ownership action that will cause the referenced project-contained resource to be attached to the current stack.
@@ -45,7 +58,10 @@ export interface BlueprintProjectOwnershipAttachAction extends BlueprintOwnershi
45
58
  * @category Blueprint Internals
46
59
  * @expand
47
60
  */
48
- export type BlueprintProjectOwnershipAction = BlueprintProjectOwnershipAttachAction | BlueprintOwnershipDetachAction
61
+ export type BlueprintProjectOwnershipAction =
62
+ | BlueprintProjectOwnershipAttachAction
63
+ | BlueprintOwnershipDetachAction
64
+ | BlueprintOwnershipReferenceAction
49
65
 
50
66
  /**
51
67
  * Defines the lifcycle policy for this resource.
@@ -98,3 +114,25 @@ export interface BlueprintResource<Lifecycle extends BlueprintResourceLifecycle
98
114
  */
99
115
  lifecycle?: Lifecycle
100
116
  }
117
+
118
+ /**
119
+ * The configuration for referencing a resource in another stack.
120
+ * @category Blueprint Internals
121
+ */
122
+ export interface BlueprintCrossStackReferenceConfig {
123
+ /** The name of the resource in the other stack */
124
+ name: string
125
+ /** The name or id of the stack being referenced */
126
+ stack: string
127
+ /** The local name of the resource, defaults to the name of the other resource */
128
+ localName?: string
129
+ }
130
+
131
+ /**
132
+ * The configuration for referencing a resource in another stack including the type of resource.
133
+ * @category Blueprint Internals
134
+ */
135
+ export interface BlueprintCrossStackReferenceResourceConfig extends BlueprintCrossStackReferenceConfig {
136
+ /** The type of resource being referenced (e.g. `sanity.project`) */
137
+ type: string
138
+ }
@@ -17,6 +17,13 @@ export function validateDataset(resource: unknown): BlueprintError[] {
17
17
  errors.push({type: 'invalid_value', message: 'Dataset type must be `sanity.project.dataset`'})
18
18
  }
19
19
 
20
+ // validate description if provided
21
+ if ('description' in resource) {
22
+ if (typeof resource.description !== 'string') {
23
+ errors.push({type: 'invalid_type', message: 'Dataset description must be a string'})
24
+ }
25
+ }
26
+
20
27
  // validate ACL mode if provided
21
28
  if ('aclMode' in resource) {
22
29
  if (typeof resource.aclMode !== 'string') {
@@ -151,14 +151,23 @@ function validateDocumentFunctionEvent(event: unknown): BlueprintError[] {
151
151
  }
152
152
  if (!Array.isArray(fullEvent.on)) errors.push({type: 'invalid_type', message: '`event.on` must be an array'})
153
153
  if (fullEvent.resource) {
154
- if (!fullEvent.resource.type || fullEvent.resource.type !== 'dataset')
155
- errors.push({type: 'invalid_value', message: '`event.resource.type` must be "dataset"'})
156
- if (!fullEvent.resource.id || fullEvent.resource.id.split('.').length !== 2)
157
- errors.push({type: 'invalid_format', message: '`event.resource.id` must be in the format <projectId>.<datasetName>'})
154
+ errors.push(...validateFunctionEventResourceDataset(fullEvent))
158
155
  }
159
156
  return errors
160
157
  }
161
158
 
159
+ function validateFunctionEventResourceDataset(event: unknown): BlueprintError[] {
160
+ const errors: BlueprintError[] = []
161
+ if (!event || typeof event !== 'object') return [{type: 'invalid_value', message: '`event` must be an object'}]
162
+ if (!('resource' in event)) return [{type: 'invalid_value', message: '`event.resource` must exist'}]
163
+ const resource = event.resource
164
+ if (!resource || typeof resource !== 'object') return [{type: 'invalid_value', message: '`event.resource` must be an object'}]
165
+ if (!('type' in resource) || !resource.type || resource.type !== 'dataset')
166
+ errors.push({type: 'invalid_value', message: '`event.resource.type` must be "dataset"'})
167
+ if (!('id' in resource) || !resource.id || typeof resource.id !== 'string' || resource.id.split('.').length !== 2)
168
+ errors.push({type: 'invalid_format', message: '`event.resource.id` must be in the format <projectId>.<datasetName>'})
169
+ return errors
170
+ }
162
171
  /**
163
172
  * Validates a media library function event configuration.
164
173
  * Checks event trigger types and ensures required media library resource is present.
@@ -319,3 +328,30 @@ function validateScheduledFunctionTimezone(timezone: unknown): BlueprintError[]
319
328
 
320
329
  return errors
321
330
  }
331
+
332
+ /**
333
+ * Validates a sync tag invalidate function resource configuration.
334
+ * @param functionResource The function resource to validate
335
+ * @alpha
336
+ * @hidden
337
+ * @category Functions Types
338
+ * @returns Array of validation errors, empty if valid
339
+ */
340
+ export function validateSyncTagInvalidateFunction(functionResource: unknown): BlueprintError[] {
341
+ if (!functionResource) return [{type: 'invalid_value', message: 'Function config must be provided'}]
342
+ if (typeof functionResource !== 'object') return [{type: 'invalid_type', message: 'Function config must be an object'}]
343
+
344
+ const errors: BlueprintError[] = []
345
+
346
+ if ('type' in functionResource && functionResource.type !== 'sanity.function.sync-tag-invalidate') {
347
+ errors.push({type: 'invalid_value', message: '`type` must be `sanity.function.sync-tag-invalidate`'})
348
+ }
349
+
350
+ if ('event' in functionResource) {
351
+ errors.push(...validateFunctionEventResourceDataset(functionResource.event))
352
+ }
353
+
354
+ errors.push(...validateFunction(functionResource))
355
+
356
+ return errors
357
+ }
@@ -39,7 +39,7 @@ export function validateResource(resource: unknown, options?: {projectContained?
39
39
  }
40
40
 
41
41
  if ('ownershipAction' in resource.lifecycle) {
42
- const ownershipActionTypes = ['attach', 'detach']
42
+ const ownershipActionTypes = ['attach', 'detach', 'reference']
43
43
  const ownershipAction = resource.lifecycle.ownershipAction
44
44
 
45
45
  if (typeof ownershipAction !== 'object' || ownershipAction === null) {
@@ -65,6 +65,18 @@ export function validateResource(resource: unknown, options?: {projectContained?
65
65
  errors.push({type: 'invalid_type', message: '`ownershipAction.projectId` must be a string'})
66
66
  }
67
67
  }
68
+ } else if (ownershipAction.type === 'reference') {
69
+ if (!('name' in ownershipAction)) {
70
+ errors.push({type: 'missing_parameter', message: '`ownershipAction.name` is required for reference'})
71
+ } else if (typeof ownershipAction.name !== 'string') {
72
+ errors.push({type: 'invalid_type', message: '`ownershipAction.name` must be a string'})
73
+ }
74
+
75
+ if (!('stack' in ownershipAction)) {
76
+ errors.push({type: 'missing_parameter', message: '`ownershipAction.stack` is required for reference'})
77
+ } else if (typeof ownershipAction.stack !== 'string') {
78
+ errors.push({type: 'invalid_type', message: '`ownershipAction.stack` must be a string'})
79
+ }
68
80
  }
69
81
  }
70
82
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/types/functions.ts"],"names":[],"mappings":"AAwGA;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,CAAU,CAAA"}