@sanity/blueprints 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -317
- package/dist/definers/blueprints.d.ts +15 -3
- package/dist/definers/blueprints.js +40 -3
- package/dist/definers/blueprints.js.map +1 -1
- package/dist/definers/cors.d.ts +5 -2
- package/dist/definers/cors.js +17 -2
- package/dist/definers/cors.js.map +1 -1
- package/dist/definers/datasets.d.ts +5 -2
- package/dist/definers/datasets.js +18 -2
- package/dist/definers/datasets.js.map +1 -1
- package/dist/definers/functions.d.ts +37 -61
- package/dist/definers/functions.js +69 -95
- package/dist/definers/functions.js.map +1 -1
- package/dist/definers/resources.d.ts +10 -0
- package/dist/definers/resources.js +21 -0
- package/dist/definers/resources.js.map +1 -1
- package/dist/definers/robotTokens.d.ts +22 -0
- package/dist/definers/robotTokens.js +53 -0
- package/dist/definers/robotTokens.js.map +1 -0
- package/dist/definers/robots.d.ts +2 -22
- package/dist/definers/robots.js +2 -33
- package/dist/definers/robots.js.map +1 -1
- package/dist/definers/roles.d.ts +16 -25
- package/dist/definers/roles.js +64 -23
- package/dist/definers/roles.js.map +1 -1
- package/dist/definers/webhooks.d.ts +5 -2
- package/dist/definers/webhooks.js +25 -2
- package/dist/definers/webhooks.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/types/cors.d.ts +2 -0
- package/dist/types/datasets.d.ts +5 -1
- package/dist/types/functions.d.ts +65 -3
- package/dist/types/functions.js.map +1 -1
- package/dist/types/resources.d.ts +25 -0
- package/dist/types/robotTokens.d.ts +45 -0
- package/dist/types/robotTokens.js +2 -0
- package/dist/types/robotTokens.js.map +1 -0
- package/dist/types/robots.d.ts +8 -39
- package/dist/types/robots.js +1 -0
- package/dist/types/robots.js.map +1 -1
- package/dist/types/roles.d.ts +1 -0
- package/dist/types/webhooks.d.ts +6 -0
- package/dist/utils/validation.d.ts +9 -0
- package/dist/utils/validation.js +12 -0
- package/dist/utils/validation.js.map +1 -1
- package/dist/validation/cors.js +7 -0
- package/dist/validation/cors.js.map +1 -1
- package/dist/validation/resources.js +8 -0
- package/dist/validation/resources.js.map +1 -1
- package/dist/validation/robotTokens.d.ts +15 -0
- package/dist/validation/robotTokens.js +104 -0
- package/dist/validation/robotTokens.js.map +1 -0
- package/dist/validation/robots.d.ts +4 -15
- package/dist/validation/robots.js +5 -103
- package/dist/validation/robots.js.map +1 -1
- package/dist/validation/webhooks.js +6 -3
- package/dist/validation/webhooks.js.map +1 -1
- package/package.json +6 -6
- package/src/definers/blueprints.ts +40 -3
- package/src/definers/cors.ts +17 -2
- package/src/definers/datasets.ts +18 -2
- package/src/definers/functions.ts +124 -132
- package/src/definers/resources.ts +21 -0
- package/src/definers/robotTokens.ts +56 -0
- package/src/definers/robots.ts +2 -37
- package/src/definers/roles.ts +64 -23
- package/src/definers/webhooks.ts +25 -2
- package/src/index.ts +3 -0
- package/src/types/cors.ts +2 -0
- package/src/types/datasets.ts +5 -1
- package/src/types/functions.ts +71 -3
- package/src/types/resources.ts +26 -1
- package/src/types/robotTokens.ts +50 -0
- package/src/types/robots.ts +10 -44
- package/src/types/roles.ts +1 -0
- package/src/types/webhooks.ts +6 -0
- package/src/utils/validation.ts +14 -0
- package/src/validation/cors.ts +6 -0
- package/src/validation/resources.ts +8 -0
- package/src/validation/robotTokens.ts +103 -0
- package/src/validation/robots.ts +5 -102
- package/src/validation/webhooks.ts +5 -3
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from './definers/datasets.js'
|
|
|
9
9
|
export * from './definers/functions.js'
|
|
10
10
|
export * from './definers/resources.js'
|
|
11
11
|
export * from './definers/robots.js'
|
|
12
|
+
export * from './definers/robotTokens.js'
|
|
12
13
|
export * from './definers/roles.js'
|
|
13
14
|
export * from './definers/webhooks.js'
|
|
14
15
|
|
|
@@ -28,6 +29,7 @@ export * from './types/errors.js'
|
|
|
28
29
|
export * from './types/functions.js'
|
|
29
30
|
export * from './types/resources.js'
|
|
30
31
|
export * from './types/robots.js'
|
|
32
|
+
export * from './types/robotTokens.js'
|
|
31
33
|
export * from './types/roles.js'
|
|
32
34
|
export * from './types/webhooks.js'
|
|
33
35
|
|
|
@@ -42,6 +44,7 @@ export * from './validation/datasets.js'
|
|
|
42
44
|
export * from './validation/functions.js'
|
|
43
45
|
export * from './validation/resources.js'
|
|
44
46
|
export * from './validation/robots.js'
|
|
47
|
+
export * from './validation/robotTokens.js'
|
|
45
48
|
export * from './validation/roles.js'
|
|
46
49
|
export * from './validation/webhooks.js'
|
|
47
50
|
|
package/src/types/cors.ts
CHANGED
|
@@ -35,6 +35,7 @@ export interface BlueprintCorsOriginResource extends BlueprintResource<Blueprint
|
|
|
35
35
|
* @see https://www.sanity.io/docs/content-lake/cors
|
|
36
36
|
* @beta This feature is subject to breaking changes.
|
|
37
37
|
* @category Resource Types
|
|
38
|
+
* @interface
|
|
38
39
|
*/
|
|
39
40
|
export type BlueprintCorsOriginConfig = Omit<BlueprintCorsOriginResource, 'type' | 'allowCredentials'> & {
|
|
40
41
|
/**
|
|
@@ -43,6 +44,7 @@ export type BlueprintCorsOriginConfig = Omit<BlueprintCorsOriginResource, 'type'
|
|
|
43
44
|
* If this origin hosts a studio, you will need to allow credentials. Otherwise, you should probably select not to allow credentials.
|
|
44
45
|
*
|
|
45
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
|
|
46
48
|
*/
|
|
47
49
|
allowCredentials?: boolean
|
|
48
50
|
}
|
package/src/types/datasets.ts
CHANGED
|
@@ -36,8 +36,12 @@ export interface BlueprintDatasetResource extends BlueprintResource<BlueprintPro
|
|
|
36
36
|
* @alpha This feature is subject to breaking changes.
|
|
37
37
|
* @hidden
|
|
38
38
|
* @category Resource Types
|
|
39
|
+
* @interface
|
|
39
40
|
*/
|
|
40
41
|
export type BlueprintDatasetConfig = Omit<BlueprintDatasetResource, 'type' | 'datasetName'> & {
|
|
41
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* The name of the dataset. Must be unique within a project.
|
|
44
|
+
* @defaultValue The `name` of the resource
|
|
45
|
+
*/
|
|
42
46
|
datasetName?: string
|
|
43
47
|
}
|
package/src/types/functions.ts
CHANGED
|
@@ -7,7 +7,10 @@ import type {BlueprintResource} from '../index.js'
|
|
|
7
7
|
* @category Functions Types
|
|
8
8
|
*/
|
|
9
9
|
export interface BlueprintFunctionBaseResourceEvent {
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Event types that trigger the function
|
|
12
|
+
* @defaultValue ['publish']
|
|
13
|
+
*/
|
|
11
14
|
on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]]
|
|
12
15
|
/** GROQ filter expression to match specific documents (e.g., "_type == 'post'") */
|
|
13
16
|
filter?: string
|
|
@@ -76,7 +79,7 @@ export type BlueprintScheduleFunctionResourceEvent =
|
|
|
76
79
|
/**
|
|
77
80
|
* Dataset resource for scoping document functions to specific datasets
|
|
78
81
|
* @example { type: 'dataset', id: 'my-project.production' }
|
|
79
|
-
* @category
|
|
82
|
+
* @category Functions Types
|
|
80
83
|
*/
|
|
81
84
|
export interface BlueprintFunctionResourceEventResourceDataset {
|
|
82
85
|
type: 'dataset'
|
|
@@ -138,7 +141,7 @@ export interface BlueprintBaseFunctionResource extends BlueprintResource {
|
|
|
138
141
|
|
|
139
142
|
/**
|
|
140
143
|
* The runtime environment for the function (currently only Node.js is supported)
|
|
141
|
-
* @
|
|
144
|
+
* @defaultValue 'nodejs24.x'
|
|
142
145
|
*/
|
|
143
146
|
runtime?: FunctionRuntimes
|
|
144
147
|
}
|
|
@@ -172,3 +175,68 @@ export interface BlueprintScheduleFunctionResource extends BlueprintBaseFunction
|
|
|
172
175
|
event: BlueprintScheduleFunctionResourceEvent
|
|
173
176
|
timezone?: string
|
|
174
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
|
+
}
|
package/src/types/resources.ts
CHANGED
|
@@ -28,6 +28,7 @@ export interface BlueprintOwnershipDetachAction {
|
|
|
28
28
|
/**
|
|
29
29
|
* A union of all possible ownership actions.
|
|
30
30
|
* @category Blueprint Internals
|
|
31
|
+
* @expand
|
|
31
32
|
*/
|
|
32
33
|
export type BlueprintOwnershipAction = BlueprintOwnershipAttachAction | BlueprintOwnershipDetachAction
|
|
33
34
|
|
|
@@ -42,6 +43,7 @@ export interface BlueprintProjectOwnershipAttachAction extends BlueprintOwnershi
|
|
|
42
43
|
/**
|
|
43
44
|
* A union of all possible ownership actions for resources belonging to projects.
|
|
44
45
|
* @category Blueprint Internals
|
|
46
|
+
* @expand
|
|
45
47
|
*/
|
|
46
48
|
export type BlueprintProjectOwnershipAction = BlueprintProjectOwnershipAttachAction
|
|
47
49
|
|
|
@@ -53,11 +55,28 @@ export interface BlueprintResourceLifecycle {
|
|
|
53
55
|
deletionPolicy?: BlueprintResourceDeletionPolicy
|
|
54
56
|
|
|
55
57
|
ownershipAction?: BlueprintOwnershipAction
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Declares a dependency on another resource in the blueprint.
|
|
61
|
+
* The referenced resource will be deployed before this one.
|
|
62
|
+
*
|
|
63
|
+
* The value must be a resource reference starting with `$.resources.` followed by the name of
|
|
64
|
+
* the resource this resource depends on.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* lifecycle: {
|
|
69
|
+
* dependsOn: '$.resources.my-dataset',
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
dependsOn?: string
|
|
56
74
|
}
|
|
57
75
|
|
|
58
76
|
/**
|
|
59
77
|
* Defines the lifcycle policy for this resource.
|
|
60
78
|
* @category Blueprint Internals
|
|
79
|
+
* @experimental
|
|
61
80
|
*/
|
|
62
81
|
export interface BlueprintProjectResourceLifecycle extends BlueprintResourceLifecycle {
|
|
63
82
|
ownershipAction?: BlueprintProjectOwnershipAction
|
|
@@ -68,8 +87,14 @@ export interface BlueprintProjectResourceLifecycle extends BlueprintResourceLife
|
|
|
68
87
|
* @category Blueprint Internals
|
|
69
88
|
*/
|
|
70
89
|
export interface BlueprintResource<Lifecycle extends BlueprintResourceLifecycle = BlueprintResourceLifecycle> {
|
|
90
|
+
/** The type of the resource. e.g. 'sanity.project.webhook' */
|
|
71
91
|
type: string
|
|
92
|
+
/** The name of the resource. Unique within the blueprint. e.g. 'sync-webhook' */
|
|
72
93
|
name: string
|
|
73
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Defines the lifcycle policy for this resource.
|
|
96
|
+
* @experimental
|
|
97
|
+
* @hidden
|
|
98
|
+
*/
|
|
74
99
|
lifecycle?: Lifecycle
|
|
75
100
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type {BlueprintProjectResourceLifecycle, BlueprintResource} from './resources'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resource types that robot tokens can be attached to.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export type RobotTokenResourceType = 'organization' | 'project'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Defines the robot token's roles within a given resource.
|
|
11
|
+
* @beta This feature is subject to breaking changes.
|
|
12
|
+
* @category Resource Types
|
|
13
|
+
* @expand
|
|
14
|
+
*/
|
|
15
|
+
export interface RobotTokenMembership {
|
|
16
|
+
resourceType: RobotTokenResourceType
|
|
17
|
+
resourceId: string
|
|
18
|
+
roleNames: string[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A robot token that provides automated access.
|
|
23
|
+
* @see https://www.sanity.io/docs/content-lake/http-auth#k4c21d7b829fe
|
|
24
|
+
* @beta This feature is subject to breaking changes.
|
|
25
|
+
* @category Resource Types
|
|
26
|
+
*/
|
|
27
|
+
export interface BlueprintRobotTokenResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
|
|
28
|
+
type: 'sanity.access.robot'
|
|
29
|
+
/** A descriptive label for the robot token and its use case */
|
|
30
|
+
label: string
|
|
31
|
+
memberships: RobotTokenMembership[]
|
|
32
|
+
|
|
33
|
+
resourceType?: RobotTokenResourceType
|
|
34
|
+
resourceId?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Configuration for a robot token that provides automated access.
|
|
39
|
+
* @see https://www.sanity.io/docs/content-lake/http-auth#k4c21d7b829fe
|
|
40
|
+
* @beta This feature is subject to breaking changes.
|
|
41
|
+
* @category Resource Types
|
|
42
|
+
* @interface
|
|
43
|
+
*/
|
|
44
|
+
export type BlueprintRobotTokenConfig = Omit<BlueprintRobotTokenResource, 'type' | 'label' | 'token'> & {
|
|
45
|
+
/**
|
|
46
|
+
* A descriptive label for the robot token and its use case
|
|
47
|
+
* @defaultValue The `name` of the resource
|
|
48
|
+
*/
|
|
49
|
+
label?: string
|
|
50
|
+
}
|
package/src/types/robots.ts
CHANGED
|
@@ -1,44 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
* @beta This feature is subject to breaking changes.
|
|
12
|
-
* @category Resource Types
|
|
13
|
-
*/
|
|
14
|
-
export interface RobotMembership {
|
|
15
|
-
resourceType: RobotResourceType
|
|
16
|
-
resourceId: string
|
|
17
|
-
roleNames: string[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* A robot that provides a token for automated access.
|
|
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
|
|
25
|
-
*/
|
|
26
|
-
export interface BlueprintRobotResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
|
|
27
|
-
type: 'sanity.access.robot'
|
|
28
|
-
/** A descriptive label for the robot and its use case */
|
|
29
|
-
label: string
|
|
30
|
-
memberships: RobotMembership[]
|
|
31
|
-
|
|
32
|
-
resourceType?: RobotResourceType
|
|
33
|
-
resourceId?: string
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Configuration for a robot that provides a token for automated access.
|
|
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
|
|
41
|
-
*/
|
|
42
|
-
export type BlueprintRobotConfig = Omit<BlueprintRobotResource, 'type' | 'label' | 'token'> & {
|
|
43
|
-
label?: string
|
|
44
|
-
}
|
|
1
|
+
// biome-ignore-all assist/source/organizeImports: sorting imports moves typedocs
|
|
2
|
+
|
|
3
|
+
/** @deprecated Use {@link BlueprintRobotTokenConfig} instead @hidden */
|
|
4
|
+
export type {BlueprintRobotTokenConfig as BlueprintRobotConfig} from './robotTokens.js'
|
|
5
|
+
/** @deprecated Use {@link BlueprintRobotTokenResource} instead @hidden */
|
|
6
|
+
export type {BlueprintRobotTokenResource as BlueprintRobotResource} from './robotTokens.js'
|
|
7
|
+
/** @deprecated Use {@link RobotTokenMembership} instead @hidden */
|
|
8
|
+
export type {RobotTokenMembership as RobotMembership} from './robotTokens.js'
|
|
9
|
+
/** @deprecated Use {@link RobotTokenResourceType} instead @hidden */
|
|
10
|
+
export type {RobotTokenResourceType as RobotResourceType} from './robotTokens.js'
|
package/src/types/roles.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {BlueprintProjectResourceLifecycle, BlueprintResource} from '../inde
|
|
|
4
4
|
* A permission definition for a role.
|
|
5
5
|
* @beta This feature is subject to breaking changes.
|
|
6
6
|
* @category Resource Types
|
|
7
|
+
* @expand
|
|
7
8
|
*/
|
|
8
9
|
export interface RolePermission {
|
|
9
10
|
/** Predefined permission name (e.g., 'sanity-all-documents') */
|
package/src/types/webhooks.ts
CHANGED
|
@@ -15,6 +15,10 @@ export type WebhookTrigger = 'create' | 'update' | 'delete'
|
|
|
15
15
|
export interface BlueprintDocumentWebhookResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
|
|
16
16
|
type: 'sanity.project.webhook'
|
|
17
17
|
project?: string
|
|
18
|
+
/**
|
|
19
|
+
* Display name shown in the Sanity dashboard
|
|
20
|
+
* @defaultValue The `name` of the resource
|
|
21
|
+
*/
|
|
18
22
|
displayName?: string
|
|
19
23
|
description?: string | null
|
|
20
24
|
url: string
|
|
@@ -28,6 +32,7 @@ export interface BlueprintDocumentWebhookResource extends BlueprintResource<Blue
|
|
|
28
32
|
includeAllVersions?: boolean
|
|
29
33
|
secret?: string
|
|
30
34
|
dataset: string
|
|
35
|
+
/** Must start with 'v' and use the format YYYY-MM-DD */
|
|
31
36
|
apiVersion: string
|
|
32
37
|
}
|
|
33
38
|
|
|
@@ -35,5 +40,6 @@ export interface BlueprintDocumentWebhookResource extends BlueprintResource<Blue
|
|
|
35
40
|
* Configuration for a webhook
|
|
36
41
|
* @beta This feature is subject to breaking changes.
|
|
37
42
|
* @category Resource Types
|
|
43
|
+
* @interface
|
|
38
44
|
*/
|
|
39
45
|
export type BlueprintDocumentWebhookConfig = Omit<BlueprintDocumentWebhookResource, 'type'>
|
package/src/utils/validation.ts
CHANGED
|
@@ -12,3 +12,17 @@ export function runValidation(validator: () => BlueprintError[]) {
|
|
|
12
12
|
throw new Error(message)
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
const REFERENCE_PREFIXES = ['$.resources.', '$.values.', '$.parameters.', '$.params.']
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Checks whether a value is a blueprint reference expression.
|
|
20
|
+
*
|
|
21
|
+
* Recognized prefixes: `$.resources.*`, `$.values.*`, `$.parameters.*`, `$.params.*`.
|
|
22
|
+
* @param value The value to check
|
|
23
|
+
* @returns `true` if the value matches a known reference prefix
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export function isReference(value: unknown): boolean {
|
|
27
|
+
return typeof value === 'string' && REFERENCE_PREFIXES.some((prefix) => value.startsWith(prefix))
|
|
28
|
+
}
|
package/src/validation/cors.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {type BlueprintError, validateResource} from '../index.js'
|
|
2
|
+
import {isReference} from '../utils/validation.js'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Validates that the given resource is a valid CORS origin.
|
|
@@ -28,6 +29,11 @@ export function validateCorsOrigin(resource: unknown): BlueprintError[] {
|
|
|
28
29
|
errors.push({type: 'missing_parameter', message: 'CORS Origin URL is required'})
|
|
29
30
|
} else if (typeof resource.origin !== 'string') {
|
|
30
31
|
errors.push({type: 'invalid_type', message: 'CORS Origin URL must be a string'})
|
|
32
|
+
} else if (!isReference(resource.origin)) {
|
|
33
|
+
const isSpecialValue = resource.origin === '*' || resource.origin === 'null' || resource.origin === 'file:///*'
|
|
34
|
+
if (!isSpecialValue && !resource.origin.includes('://')) {
|
|
35
|
+
errors.push({type: 'invalid_format', message: 'CORS Origin must include a protocol (e.g. https://)'})
|
|
36
|
+
}
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
if ('project' in resource) {
|
|
@@ -68,6 +68,14 @@ export function validateResource(resource: unknown, options?: {projectContained?
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
|
|
72
|
+
if ('dependsOn' in resource.lifecycle) {
|
|
73
|
+
if (typeof resource.lifecycle.dependsOn !== 'string') {
|
|
74
|
+
errors.push({type: 'invalid_type', message: '`lifecycle.dependsOn` must be a string'})
|
|
75
|
+
} else if (!resource.lifecycle.dependsOn.startsWith('$.resources.')) {
|
|
76
|
+
errors.push({type: 'invalid_value', message: '`lifecycle.dependsOn` must be a resource reference starting with `$.resources.`'})
|
|
77
|
+
}
|
|
78
|
+
}
|
|
71
79
|
}
|
|
72
80
|
}
|
|
73
81
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {type BlueprintError, validateResource} from '../index.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Validates that the given resource is a valid Robot Token.
|
|
5
|
+
* @param resource The Robot Token resource
|
|
6
|
+
* @category Validation
|
|
7
|
+
* @returns A list of validation errors
|
|
8
|
+
*/
|
|
9
|
+
export function validateRobotToken(resource: unknown): BlueprintError[] {
|
|
10
|
+
if (!resource) return [{type: 'invalid_value', message: 'Robot config must be provided'}]
|
|
11
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Robot config must be an object'}]
|
|
12
|
+
|
|
13
|
+
const errors: BlueprintError[] = validateResource(resource, {projectContained: true})
|
|
14
|
+
|
|
15
|
+
if (!('name' in resource) || !resource.name) {
|
|
16
|
+
errors.push({type: 'missing_parameter', message: 'Robot name is required'})
|
|
17
|
+
} else if (typeof resource.name !== 'string') {
|
|
18
|
+
errors.push({type: 'invalid_type', message: 'Robot name must be a string'})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!('type' in resource)) {
|
|
22
|
+
errors.push({type: 'missing_parameter', message: 'Robot type is required'})
|
|
23
|
+
} else if (resource.type !== 'sanity.access.robot') {
|
|
24
|
+
errors.push({type: 'invalid_value', message: 'Robot type must be `sanity.access.robot`'})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!('label' in resource) || !resource.label) {
|
|
28
|
+
errors.push({type: 'missing_parameter', message: 'Robot label is required'})
|
|
29
|
+
} else if (typeof resource.label !== 'string') {
|
|
30
|
+
errors.push({type: 'invalid_type', message: 'Robot label must be a string'})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!('memberships' in resource)) {
|
|
34
|
+
errors.push({type: 'missing_parameter', message: 'Robot memberships array is required'})
|
|
35
|
+
} else if (!Array.isArray(resource.memberships)) {
|
|
36
|
+
errors.push({type: 'invalid_type', message: 'Robot memberships must be an array'})
|
|
37
|
+
} else if (resource.memberships.length === 0) {
|
|
38
|
+
errors.push({type: 'invalid_value', message: 'Robot must have at least one membership'})
|
|
39
|
+
} else {
|
|
40
|
+
errors.push(...resource.memberships.flatMap(validateRobotTokenMembership))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if ('resourceType' in resource) {
|
|
44
|
+
if (resource.resourceType !== 'organization' && resource.resourceType !== 'project') {
|
|
45
|
+
errors.push({type: 'invalid_value', message: 'Robot resource type must be `organization` or `project`'})
|
|
46
|
+
}
|
|
47
|
+
if (!('resourceId' in resource)) {
|
|
48
|
+
errors.push({type: 'missing_parameter', message: 'Robot resource ID is required when resource type is provided'})
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if ('resourceId' in resource) {
|
|
53
|
+
if (typeof resource.resourceId !== 'string') {
|
|
54
|
+
errors.push({type: 'invalid_type', message: 'Robot resource ID must be a string'})
|
|
55
|
+
}
|
|
56
|
+
if (!('resourceType' in resource)) {
|
|
57
|
+
errors.push({type: 'missing_parameter', message: 'Robot resource type is required when resource ID is provided'})
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return errors
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Validates that the given membership is a valid Robot Token membership.
|
|
66
|
+
* @param membership The membership to validate
|
|
67
|
+
* @internal
|
|
68
|
+
* @returns A list of validation errors
|
|
69
|
+
*/
|
|
70
|
+
export function validateRobotTokenMembership(membership: unknown): BlueprintError[] {
|
|
71
|
+
if (!membership) return [{type: 'invalid_value', message: 'Membership config must be provided'}]
|
|
72
|
+
if (typeof membership !== 'object') return [{type: 'invalid_type', message: 'Membership config must be an object'}]
|
|
73
|
+
|
|
74
|
+
const errors: BlueprintError[] = []
|
|
75
|
+
|
|
76
|
+
if (!('resourceType' in membership)) {
|
|
77
|
+
errors.push({type: 'missing_parameter', message: 'Membership resource type is required'})
|
|
78
|
+
} else if (membership.resourceType !== 'organization' && membership.resourceType !== 'project') {
|
|
79
|
+
errors.push({type: 'invalid_value', message: 'Membership resource type must be `organization` or `project`'})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!('resourceId' in membership) || !membership.resourceId) {
|
|
83
|
+
errors.push({type: 'missing_parameter', message: 'Membership resource ID is required'})
|
|
84
|
+
} else if (typeof membership.resourceId !== 'string') {
|
|
85
|
+
errors.push({type: 'invalid_type', message: 'Membership resource ID must be a string'})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!('roleNames' in membership)) {
|
|
89
|
+
errors.push({type: 'missing_parameter', message: 'Membership role names array is required'})
|
|
90
|
+
} else if (!Array.isArray(membership.roleNames)) {
|
|
91
|
+
errors.push({type: 'invalid_type', message: 'Membership role names must be an array'})
|
|
92
|
+
} else if (membership.roleNames.length === 0) {
|
|
93
|
+
errors.push({type: 'invalid_value', message: 'Membership must have at least one role name'})
|
|
94
|
+
} else {
|
|
95
|
+
for (const roleName of membership.roleNames) {
|
|
96
|
+
if (!roleName || typeof roleName !== 'string') {
|
|
97
|
+
errors.push({type: 'invalid_value', message: 'Membership role name must have at least one character'})
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return errors
|
|
103
|
+
}
|
package/src/validation/robots.ts
CHANGED
|
@@ -1,103 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
// biome-ignore-all assist/source/organizeImports: sorting imports moves typedocs
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @returns A list of validation errors
|
|
8
|
-
*/
|
|
9
|
-
export function validateRobot(resource: unknown): BlueprintError[] {
|
|
10
|
-
if (!resource) return [{type: 'invalid_value', message: 'Robot config must be provided'}]
|
|
11
|
-
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Robot config must be an object'}]
|
|
12
|
-
|
|
13
|
-
const errors: BlueprintError[] = validateResource(resource, {projectContained: true})
|
|
14
|
-
|
|
15
|
-
if (!('name' in resource) || !resource.name) {
|
|
16
|
-
errors.push({type: 'missing_parameter', message: 'Robot name is required'})
|
|
17
|
-
} else if (typeof resource.name !== 'string') {
|
|
18
|
-
errors.push({type: 'invalid_type', message: 'Robot name must be a string'})
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (!('type' in resource)) {
|
|
22
|
-
errors.push({type: 'missing_parameter', message: 'Robot type is required'})
|
|
23
|
-
} else if (resource.type !== 'sanity.access.robot') {
|
|
24
|
-
errors.push({type: 'invalid_value', message: 'Robot type must be `sanity.access.robot`'})
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (!('label' in resource) || !resource.label) {
|
|
28
|
-
errors.push({type: 'missing_parameter', message: 'Robot label is required'})
|
|
29
|
-
} else if (typeof resource.label !== 'string') {
|
|
30
|
-
errors.push({type: 'invalid_type', message: 'Robot label must be a string'})
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!('memberships' in resource)) {
|
|
34
|
-
errors.push({type: 'missing_parameter', message: 'Robot memberships array is required'})
|
|
35
|
-
} else if (!Array.isArray(resource.memberships)) {
|
|
36
|
-
errors.push({type: 'invalid_type', message: 'Robot memberships must be an array'})
|
|
37
|
-
} else if (resource.memberships.length === 0) {
|
|
38
|
-
errors.push({type: 'invalid_value', message: 'Robot must have at least one membership'})
|
|
39
|
-
} else {
|
|
40
|
-
errors.push(...resource.memberships.flatMap(validateRobotMembership))
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if ('resourceType' in resource) {
|
|
44
|
-
if (resource.resourceType !== 'organization' && resource.resourceType !== 'project') {
|
|
45
|
-
errors.push({type: 'invalid_value', message: 'Robot resource type must be `organization` or `project`'})
|
|
46
|
-
}
|
|
47
|
-
if (!('resourceId' in resource)) {
|
|
48
|
-
errors.push({type: 'missing_parameter', message: 'Robot resource ID is required when resource type is provided'})
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if ('resourceId' in resource) {
|
|
53
|
-
if (typeof resource.resourceId !== 'string') {
|
|
54
|
-
errors.push({type: 'invalid_type', message: 'Robot resource ID must be a string'})
|
|
55
|
-
}
|
|
56
|
-
if (!('resourceType' in resource)) {
|
|
57
|
-
errors.push({type: 'missing_parameter', message: 'Robot resource type is required when resource ID is provided'})
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return errors
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Validates that the given membership is a valid Robot membership.
|
|
66
|
-
* @param membership The membership to validate
|
|
67
|
-
* @internal
|
|
68
|
-
* @returns A list of validation errors
|
|
69
|
-
*/
|
|
70
|
-
export function validateRobotMembership(membership: unknown): BlueprintError[] {
|
|
71
|
-
if (!membership) return [{type: 'invalid_value', message: 'Membership config must be provided'}]
|
|
72
|
-
if (typeof membership !== 'object') return [{type: 'invalid_type', message: 'Membership config must be an object'}]
|
|
73
|
-
|
|
74
|
-
const errors: BlueprintError[] = []
|
|
75
|
-
|
|
76
|
-
if (!('resourceType' in membership)) {
|
|
77
|
-
errors.push({type: 'missing_parameter', message: 'Membership resource type is required'})
|
|
78
|
-
} else if (membership.resourceType !== 'organization' && membership.resourceType !== 'project') {
|
|
79
|
-
errors.push({type: 'invalid_value', message: 'Membership resource type must be `organization` or `project`'})
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (!('resourceId' in membership) || !membership.resourceId) {
|
|
83
|
-
errors.push({type: 'missing_parameter', message: 'Membership resource ID is required'})
|
|
84
|
-
} else if (typeof membership.resourceId !== 'string') {
|
|
85
|
-
errors.push({type: 'invalid_type', message: 'Membership resource ID must be a string'})
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!('roleNames' in membership)) {
|
|
89
|
-
errors.push({type: 'missing_parameter', message: 'Membership role names array is required'})
|
|
90
|
-
} else if (!Array.isArray(membership.roleNames)) {
|
|
91
|
-
errors.push({type: 'invalid_type', message: 'Membership role names must be an array'})
|
|
92
|
-
} else if (membership.roleNames.length === 0) {
|
|
93
|
-
errors.push({type: 'invalid_value', message: 'Membership must have at least one role name'})
|
|
94
|
-
} else {
|
|
95
|
-
for (const roleName of membership.roleNames) {
|
|
96
|
-
if (!roleName || typeof roleName !== 'string') {
|
|
97
|
-
errors.push({type: 'invalid_value', message: 'Membership role name must have at least one character'})
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return errors
|
|
103
|
-
}
|
|
3
|
+
/** @deprecated Use {@link validateRobotToken} instead @hidden */
|
|
4
|
+
export {validateRobotToken as validateRobot} from './robotTokens.js'
|
|
5
|
+
/** @deprecated Use {@link validateRobotTokenMembership} instead @hidden */
|
|
6
|
+
export {validateRobotTokenMembership as validateRobotMembership} from './robotTokens.js'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {type BlueprintError, validateResource} from '../index.js'
|
|
2
|
+
import {isReference} from '../utils/validation.js'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Validates that the given resource is a valid Document Webhook.
|
|
@@ -36,8 +37,7 @@ export function validateDocumentWebhook(resource: unknown): BlueprintError[] {
|
|
|
36
37
|
errors.push({type: 'missing_parameter', message: 'Webhook URL is required'})
|
|
37
38
|
} else if (typeof resource.url !== 'string') {
|
|
38
39
|
errors.push({type: 'invalid_type', message: 'Webhook URL must be a string'})
|
|
39
|
-
} else {
|
|
40
|
-
// Validate URL format
|
|
40
|
+
} else if (!isReference(resource.url)) {
|
|
41
41
|
try {
|
|
42
42
|
new URL(resource.url)
|
|
43
43
|
} catch {
|
|
@@ -64,7 +64,9 @@ export function validateDocumentWebhook(resource: unknown): BlueprintError[] {
|
|
|
64
64
|
// Validate dataset pattern
|
|
65
65
|
if (!('dataset' in resource)) {
|
|
66
66
|
errors.push({type: 'missing_parameter', message: 'Webhook dataset is required'})
|
|
67
|
-
} else if (typeof resource.dataset !== 'string'
|
|
67
|
+
} else if (typeof resource.dataset !== 'string') {
|
|
68
|
+
errors.push({type: 'invalid_format', message: 'Dataset must be a string'})
|
|
69
|
+
} else if (!isReference(resource.dataset) && !/^[a-z0-9-_]+$/.test(resource.dataset)) {
|
|
68
70
|
errors.push({type: 'invalid_format', message: 'Dataset must match pattern: ^[a-z0-9-_]+$'})
|
|
69
71
|
}
|
|
70
72
|
|