@sanity/blueprints 0.11.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 (71) hide show
  1. package/README.md +40 -317
  2. package/dist/definers/blueprints.d.ts +15 -3
  3. package/dist/definers/blueprints.js +40 -3
  4. package/dist/definers/blueprints.js.map +1 -1
  5. package/dist/definers/cors.d.ts +5 -2
  6. package/dist/definers/cors.js +17 -2
  7. package/dist/definers/cors.js.map +1 -1
  8. package/dist/definers/datasets.d.ts +5 -2
  9. package/dist/definers/datasets.js +18 -2
  10. package/dist/definers/datasets.js.map +1 -1
  11. package/dist/definers/functions.d.ts +37 -61
  12. package/dist/definers/functions.js +69 -95
  13. package/dist/definers/functions.js.map +1 -1
  14. package/dist/definers/resources.d.ts +10 -0
  15. package/dist/definers/resources.js +21 -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 -22
  21. package/dist/definers/robots.js +2 -33
  22. package/dist/definers/robots.js.map +1 -1
  23. package/dist/definers/roles.d.ts +16 -25
  24. package/dist/definers/roles.js +64 -23
  25. package/dist/definers/roles.js.map +1 -1
  26. package/dist/definers/webhooks.d.ts +5 -2
  27. package/dist/definers/webhooks.js +25 -2
  28. package/dist/definers/webhooks.js.map +1 -1
  29. package/dist/index.d.ts +3 -0
  30. package/dist/index.js +3 -0
  31. package/dist/index.js.map +1 -1
  32. package/dist/types/cors.d.ts +2 -0
  33. package/dist/types/datasets.d.ts +5 -1
  34. package/dist/types/functions.d.ts +65 -3
  35. package/dist/types/functions.js.map +1 -1
  36. package/dist/types/resources.d.ts +8 -0
  37. package/dist/types/robotTokens.d.ts +45 -0
  38. package/dist/types/robotTokens.js +2 -0
  39. package/dist/types/robotTokens.js.map +1 -0
  40. package/dist/types/robots.d.ts +8 -39
  41. package/dist/types/robots.js +1 -0
  42. package/dist/types/robots.js.map +1 -1
  43. package/dist/types/roles.d.ts +1 -0
  44. package/dist/types/webhooks.d.ts +6 -0
  45. package/dist/validation/robotTokens.d.ts +15 -0
  46. package/dist/validation/robotTokens.js +104 -0
  47. package/dist/validation/robotTokens.js.map +1 -0
  48. package/dist/validation/robots.d.ts +4 -15
  49. package/dist/validation/robots.js +5 -103
  50. package/dist/validation/robots.js.map +1 -1
  51. package/package.json +6 -6
  52. package/src/definers/blueprints.ts +40 -3
  53. package/src/definers/cors.ts +17 -2
  54. package/src/definers/datasets.ts +18 -2
  55. package/src/definers/functions.ts +124 -132
  56. package/src/definers/resources.ts +21 -0
  57. package/src/definers/robotTokens.ts +56 -0
  58. package/src/definers/robots.ts +2 -37
  59. package/src/definers/roles.ts +64 -23
  60. package/src/definers/webhooks.ts +25 -2
  61. package/src/index.ts +3 -0
  62. package/src/types/cors.ts +2 -0
  63. package/src/types/datasets.ts +5 -1
  64. package/src/types/functions.ts +71 -3
  65. package/src/types/resources.ts +8 -1
  66. package/src/types/robotTokens.ts +50 -0
  67. package/src/types/robots.ts +10 -44
  68. package/src/types/roles.ts +1 -0
  69. package/src/types/webhooks.ts +6 -0
  70. package/src/validation/robotTokens.ts +103 -0
  71. package/src/validation/robots.ts +5 -102
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
  }
@@ -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
- /** 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
+ */
42
46
  datasetName?: string
43
47
  }
@@ -7,7 +7,10 @@ import type {BlueprintResource} from '../index.js'
7
7
  * @category Functions Types
8
8
  */
9
9
  export interface BlueprintFunctionBaseResourceEvent {
10
- /** Event types that trigger the function. Defaults to ['publish'] */
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 Resource Types
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
- * @default 'nodejs24.x'
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
+ }
@@ -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
 
@@ -58,6 +60,7 @@ export interface BlueprintResourceLifecycle {
58
60
  /**
59
61
  * Defines the lifcycle policy for this resource.
60
62
  * @category Blueprint Internals
63
+ * @experimental
61
64
  */
62
65
  export interface BlueprintProjectResourceLifecycle extends BlueprintResourceLifecycle {
63
66
  ownershipAction?: BlueprintProjectOwnershipAction
@@ -70,6 +73,10 @@ export interface BlueprintProjectResourceLifecycle extends BlueprintResourceLife
70
73
  export interface BlueprintResource<Lifecycle extends BlueprintResourceLifecycle = BlueprintResourceLifecycle> {
71
74
  type: string
72
75
  name: string
73
-
76
+ /**
77
+ * Defines the lifcycle policy for this resource.
78
+ * @experimental
79
+ * @hidden
80
+ */
74
81
  lifecycle?: Lifecycle
75
82
  }
@@ -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
+ }
@@ -1,44 +1,10 @@
1
- import type {BlueprintProjectResourceLifecycle, BlueprintResource} from './resources'
2
-
3
- /**
4
- * Resource types that robots can be attached to.
5
- * @internal
6
- */
7
- export type RobotResourceType = 'organization' | 'project'
8
-
9
- /**
10
- * Defines the robot's roles within a given resource.
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'
@@ -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') */
@@ -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'>
@@ -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
+ }
@@ -1,103 +1,6 @@
1
- import {type BlueprintError, validateResource} from '../index.js'
1
+ // biome-ignore-all assist/source/organizeImports: sorting imports moves typedocs
2
2
 
3
- /**
4
- * Validates that the given resource is a valid Robot.
5
- * @param resource The Robot resource
6
- * @category Validation
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'