@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
@@ -5,41 +5,42 @@ import {runValidation} from '../utils/validation.js'
5
5
  * Validates that the given resource is a valid resource.
6
6
  * @param resource The resource
7
7
  * @param options Validation options
8
+ * @internal
8
9
  * @returns A list of validation errors
9
10
  */
10
- export function validateResource(resourceConfig: unknown, options?: {projectContained?: boolean}): BlueprintError[] {
11
- if (!resourceConfig) return [{type: 'invalid_value', message: 'Resource config must be provided'}]
12
- if (typeof resourceConfig !== 'object') return [{type: 'invalid_type', message: 'Resource config must be an object'}]
11
+ export function validateResource(resource: unknown, options?: {projectContained?: boolean}): BlueprintError[] {
12
+ if (!resource) return [{type: 'invalid_value', message: 'Resource config must be provided'}]
13
+ if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Resource config must be an object'}]
13
14
 
14
15
  const errors: BlueprintError[] = []
15
16
 
16
- if (!('name' in resourceConfig)) {
17
+ if (!('name' in resource)) {
17
18
  errors.push({type: 'missing_parameter', message: '`name` is required'})
18
- } else if (typeof resourceConfig.name !== 'string') {
19
+ } else if (typeof resource.name !== 'string') {
19
20
  errors.push({type: 'invalid_type', message: '`name` must be a string'})
20
21
  }
21
22
 
22
- if (!('type' in resourceConfig)) {
23
+ if (!('type' in resource)) {
23
24
  errors.push({type: 'missing_parameter', message: '`type` is required'})
24
- } else if (typeof resourceConfig.type !== 'string') {
25
+ } else if (typeof resource.type !== 'string') {
25
26
  errors.push({type: 'invalid_type', message: '`type` must be a string'})
26
27
  }
27
28
 
28
- if ('lifecycle' in resourceConfig) {
29
- if (typeof resourceConfig.lifecycle !== 'object' || resourceConfig.lifecycle === null) {
29
+ if ('lifecycle' in resource) {
30
+ if (typeof resource.lifecycle !== 'object' || resource.lifecycle === null) {
30
31
  errors.push({type: 'invalid_type', message: '`lifecycle` must be an object'})
31
32
  } else {
32
- if ('deletionPolicy' in resourceConfig.lifecycle) {
33
- if (typeof resourceConfig.lifecycle.deletionPolicy !== 'string') {
33
+ if ('deletionPolicy' in resource.lifecycle) {
34
+ if (typeof resource.lifecycle.deletionPolicy !== 'string') {
34
35
  errors.push({type: 'invalid_type', message: '`deletionPolicy` must be a string'})
35
- } else if (!['allow', 'retain', 'replace', 'protect'].includes(resourceConfig.lifecycle.deletionPolicy)) {
36
+ } else if (!['allow', 'retain', 'replace', 'protect'].includes(resource.lifecycle.deletionPolicy)) {
36
37
  errors.push({type: 'invalid_value', message: '`deletionPolicy` must be one of allow, retain, replace, protect'})
37
38
  }
38
39
  }
39
40
 
40
- if ('ownershipAction' in resourceConfig.lifecycle) {
41
+ if ('ownershipAction' in resource.lifecycle) {
41
42
  const ownershipActionTypes = ['attach', 'detach']
42
- const ownershipAction = resourceConfig.lifecycle.ownershipAction
43
+ const ownershipAction = resource.lifecycle.ownershipAction
43
44
 
44
45
  if (typeof ownershipAction !== 'object' || ownershipAction === null) {
45
46
  errors.push({type: 'invalid_type', message: '`ownershipAction` must be an object'})
@@ -73,6 +74,11 @@ export function validateResource(resourceConfig: unknown, options?: {projectCont
73
74
  return errors
74
75
  }
75
76
 
77
+ /**
78
+ * @param resource The resource
79
+ * @internal
80
+ * @returns The resource
81
+ */
76
82
  export function assertResource(resource: unknown): asserts resource is BlueprintResource {
77
83
  runValidation(() => validateResource(resource))
78
84
  }
@@ -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,96 +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
- * @returns A list of validation errors
7
- */
8
- export function validateRobot(resource: unknown): BlueprintError[] {
9
- if (!resource) return [{type: 'invalid_value', message: 'Robot config must be provided'}]
10
- if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Robot config must be an object'}]
11
-
12
- const errors: BlueprintError[] = validateResource(resource, {projectContained: true})
13
-
14
- if (!('name' in resource) || !resource.name) {
15
- errors.push({type: 'missing_parameter', message: 'Robot name is required'})
16
- } else if (typeof resource.name !== 'string') {
17
- errors.push({type: 'invalid_type', message: 'Robot name must be a string'})
18
- }
19
-
20
- if (!('type' in resource)) {
21
- errors.push({type: 'missing_parameter', message: 'Robot type is required'})
22
- } else if (resource.type !== 'sanity.access.robot') {
23
- errors.push({type: 'invalid_value', message: 'Robot type must be `sanity.access.robot`'})
24
- }
25
-
26
- if (!('label' in resource) || !resource.label) {
27
- errors.push({type: 'missing_parameter', message: 'Robot label is required'})
28
- } else if (typeof resource.label !== 'string') {
29
- errors.push({type: 'invalid_type', message: 'Robot label must be a string'})
30
- }
31
-
32
- if (!('memberships' in resource)) {
33
- errors.push({type: 'missing_parameter', message: 'Robot memberships array is required'})
34
- } else if (!Array.isArray(resource.memberships)) {
35
- errors.push({type: 'invalid_type', message: 'Robot memberships must be an array'})
36
- } else if (resource.memberships.length === 0) {
37
- errors.push({type: 'invalid_value', message: 'Robot must have at least one membership'})
38
- } else {
39
- errors.push(...resource.memberships.flatMap(validateRobotMembership))
40
- }
41
-
42
- if ('resourceType' in resource) {
43
- if (resource.resourceType !== 'organization' && resource.resourceType !== 'project') {
44
- errors.push({type: 'invalid_value', message: 'Robot resource type must be `organization` or `project`'})
45
- }
46
- if (!('resourceId' in resource)) {
47
- errors.push({type: 'missing_parameter', message: 'Robot resource ID is required when resource type is provided'})
48
- }
49
- }
50
-
51
- if ('resourceId' in resource) {
52
- if (typeof resource.resourceId !== 'string') {
53
- errors.push({type: 'invalid_type', message: 'Robot resource ID must be a string'})
54
- }
55
- if (!('resourceType' in resource)) {
56
- errors.push({type: 'missing_parameter', message: 'Robot resource type is required when resource ID is provided'})
57
- }
58
- }
59
-
60
- return errors
61
- }
62
-
63
- export function validateRobotMembership(membership: unknown): BlueprintError[] {
64
- if (!membership) return [{type: 'invalid_value', message: 'Membership config must be provided'}]
65
- if (typeof membership !== 'object') return [{type: 'invalid_type', message: 'Membership config must be an object'}]
66
-
67
- const errors: BlueprintError[] = []
68
-
69
- if (!('resourceType' in membership)) {
70
- errors.push({type: 'missing_parameter', message: 'Membership resource type is required'})
71
- } else if (membership.resourceType !== 'organization' && membership.resourceType !== 'project') {
72
- errors.push({type: 'invalid_value', message: 'Membership resource type must be `organization` or `project`'})
73
- }
74
-
75
- if (!('resourceId' in membership) || !membership.resourceId) {
76
- errors.push({type: 'missing_parameter', message: 'Membership resource ID is required'})
77
- } else if (typeof membership.resourceId !== 'string') {
78
- errors.push({type: 'invalid_type', message: 'Membership resource ID must be a string'})
79
- }
80
-
81
- if (!('roleNames' in membership)) {
82
- errors.push({type: 'missing_parameter', message: 'Membership role names array is required'})
83
- } else if (!Array.isArray(membership.roleNames)) {
84
- errors.push({type: 'invalid_type', message: 'Membership role names must be an array'})
85
- } else if (membership.roleNames.length === 0) {
86
- errors.push({type: 'invalid_value', message: 'Membership must have at least one role name'})
87
- } else {
88
- for (const roleName of membership.roleNames) {
89
- if (!roleName || typeof roleName !== 'string') {
90
- errors.push({type: 'invalid_value', message: 'Membership role name must have at least one character'})
91
- }
92
- }
93
- }
94
-
95
- return errors
96
- }
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'
@@ -3,6 +3,7 @@ import {type BlueprintError, validateResource} from '../index.js'
3
3
  /**
4
4
  * Validates that the given resource is a valid Role.
5
5
  * @param resource The Role resource
6
+ * @category Validation
6
7
  * @returns A list of validation errors
7
8
  */
8
9
  export function validateRole(resource: unknown): BlueprintError[] {
@@ -39,8 +40,9 @@ export function validateRole(resource: unknown): BlueprintError[] {
39
40
  }
40
41
 
41
42
  /**
42
- * Validates that the given resource is a valid Role.
43
+ * Validates that the given resource is a valid Project Role.
43
44
  * @param resource The Role resource
45
+ * @category Validation
44
46
  * @returns A list of validation errors
45
47
  */
46
48
  export function validateProjectRole(resource: unknown): BlueprintError[] {
@@ -3,6 +3,7 @@ import {type BlueprintError, validateResource} from '../index.js'
3
3
  /**
4
4
  * Validates that the given resource is a valid Document Webhook.
5
5
  * @param resource The Document Webhook resource
6
+ * @category Validation
6
7
  * @returns A list of validation errors
7
8
  */
8
9
  export function validateDocumentWebhook(resource: unknown): BlueprintError[] {