@sanity/blueprints 0.34.1 → 0.36.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.
- package/README.md +1 -2
- package/dist/definers/agents.d.ts +3 -1
- package/dist/definers/agents.js +4 -2
- package/dist/definers/agents.js.map +1 -1
- package/dist/definers/applications.d.ts +30 -18
- package/dist/definers/applications.js +36 -24
- package/dist/definers/applications.js.map +1 -1
- package/dist/definers/blueprints.d.ts +1 -0
- package/dist/definers/blueprints.js +5 -27
- package/dist/definers/blueprints.js.map +1 -1
- package/dist/definers/context.d.ts +6 -2
- package/dist/definers/context.js +8 -4
- package/dist/definers/context.js.map +1 -1
- package/dist/definers/cors.d.ts +11 -1
- package/dist/definers/cors.js +11 -13
- package/dist/definers/cors.js.map +1 -1
- package/dist/definers/datasets.d.ts +30 -3
- package/dist/definers/datasets.js +32 -16
- package/dist/definers/datasets.js.map +1 -1
- package/dist/definers/functions/document.d.ts +29 -0
- package/dist/definers/functions/document.js +1 -1
- package/dist/definers/functions/document.js.map +1 -1
- package/dist/definers/functions/durable.d.ts +4 -3
- package/dist/definers/functions/durable.js +5 -4
- package/dist/definers/functions/durable.js.map +1 -1
- package/dist/definers/functions/index.js +1 -1
- package/dist/definers/functions/index.js.map +1 -1
- package/dist/definers/functions/media-library.d.ts +30 -0
- package/dist/definers/functions/media-library.js +19 -21
- package/dist/definers/functions/media-library.js.map +1 -1
- package/dist/definers/functions/pubsub.d.ts +2 -3
- package/dist/definers/functions/pubsub.js +3 -4
- package/dist/definers/functions/pubsub.js.map +1 -1
- package/dist/definers/functions/queue.d.ts +26 -6
- package/dist/definers/functions/queue.js +31 -10
- package/dist/definers/functions/queue.js.map +1 -1
- package/dist/definers/functions/scheduled.d.ts +7 -6
- package/dist/definers/functions/scheduled.js +8 -7
- package/dist/definers/functions/scheduled.js.map +1 -1
- package/dist/definers/functions/sync-tag-invalidate.d.ts +5 -2
- package/dist/definers/functions/sync-tag-invalidate.js +6 -3
- package/dist/definers/functions/sync-tag-invalidate.js.map +1 -1
- package/dist/definers/installation-config.d.ts +4 -2
- package/dist/definers/installation-config.js +5 -3
- package/dist/definers/installation-config.js.map +1 -1
- package/dist/definers/permissions.d.ts +8 -2
- package/dist/definers/permissions.js +12 -5
- package/dist/definers/permissions.js.map +1 -1
- package/dist/definers/projects.d.ts +3 -4
- package/dist/definers/projects.js +4 -5
- package/dist/definers/projects.js.map +1 -1
- package/dist/definers/resources.d.ts +1 -0
- package/dist/definers/resources.js +1 -11
- package/dist/definers/resources.js.map +1 -1
- package/dist/definers/robotTokens.d.ts +22 -4
- package/dist/definers/robotTokens.js +53 -20
- package/dist/definers/robotTokens.js.map +1 -1
- package/dist/definers/roles.d.ts +49 -9
- package/dist/definers/roles.js +54 -55
- package/dist/definers/roles.js.map +1 -1
- package/dist/definers/studios.d.ts +5 -3
- package/dist/definers/studios.js +6 -4
- package/dist/definers/studios.js.map +1 -1
- package/dist/definers/webhooks.d.ts +19 -1
- package/dist/definers/webhooks.js +18 -22
- package/dist/definers/webhooks.js.map +1 -1
- package/dist/index.d.ts +18 -18
- package/dist/index.js +19 -20
- package/dist/index.js.map +1 -1
- package/dist/resolve/index.d.ts +2 -3
- package/dist/resolve/index.js +2 -3
- package/dist/resolve/index.js.map +1 -1
- package/dist/types/agents.d.ts +7 -3
- package/dist/types/applications.d.ts +68 -50
- package/dist/types/applications.js +9 -6
- package/dist/types/applications.js.map +1 -1
- package/dist/types/context.d.ts +17 -7
- package/dist/types/cors.d.ts +0 -2
- package/dist/types/datasets.d.ts +0 -6
- package/dist/types/functions/index.d.ts +96 -21
- package/dist/types/functions/index.js +2 -1
- package/dist/types/functions/index.js.map +1 -1
- package/dist/types/installation-config.d.ts +14 -11
- package/dist/types/permissions.d.ts +8 -4
- package/dist/types/projects.d.ts +5 -4
- package/dist/types/robotTokens.d.ts +14 -4
- package/dist/types/roles.d.ts +10 -9
- package/dist/types/studios.d.ts +29 -14
- package/dist/types/studios.js +3 -2
- package/dist/types/studios.js.map +1 -1
- package/dist/types/webhooks.d.ts +0 -3
- package/dist/utils/debounce.d.ts +0 -11
- package/dist/utils/debounce.js +0 -22
- package/dist/utils/debounce.js.map +1 -1
- package/dist/utils/parse-duration.d.ts +13 -0
- package/dist/utils/parse-duration.js +24 -0
- package/dist/utils/parse-duration.js.map +1 -1
- package/dist/utils/throttle.d.ts +9 -0
- package/dist/utils/throttle.js +22 -0
- package/dist/utils/throttle.js.map +1 -0
- package/dist/utils/validation.d.ts +14 -11
- package/dist/utils/validation.js +25 -17
- package/dist/utils/validation.js.map +1 -1
- package/dist/validation/applications.js +7 -2
- package/dist/validation/applications.js.map +1 -1
- package/dist/validation/blueprints.js +120 -4
- package/dist/validation/blueprints.js.map +1 -1
- package/dist/validation/functions.d.ts +19 -0
- package/dist/validation/functions.js +169 -36
- package/dist/validation/functions.js.map +1 -1
- package/dist/validation/projects.js +3 -0
- package/dist/validation/projects.js.map +1 -1
- package/dist/validation/resources.js +1 -1
- package/dist/validation/resources.js.map +1 -1
- package/dist/validation/studios.js +4 -0
- package/dist/validation/studios.js.map +1 -1
- package/package.json +1 -1
- package/src/definers/agents.ts +4 -2
- package/src/definers/applications.ts +36 -24
- package/src/definers/blueprints.ts +4 -27
- package/src/definers/context.ts +8 -4
- package/src/definers/cors.ts +11 -13
- package/src/definers/datasets.ts +40 -16
- package/src/definers/functions/document.ts +17 -25
- package/src/definers/functions/durable.ts +5 -4
- package/src/definers/functions/index.ts +1 -1
- package/src/definers/functions/media-library.ts +19 -21
- package/src/definers/functions/pubsub.ts +3 -4
- package/src/definers/functions/queue.ts +31 -10
- package/src/definers/functions/scheduled.ts +8 -7
- package/src/definers/functions/sync-tag-invalidate.ts +6 -3
- package/src/definers/installation-config.ts +5 -3
- package/src/definers/permissions.ts +14 -6
- package/src/definers/projects.ts +4 -5
- package/src/definers/resources.ts +1 -11
- package/src/definers/robotTokens.ts +55 -20
- package/src/definers/roles.ts +60 -58
- package/src/definers/studios.ts +6 -4
- package/src/definers/webhooks.ts +18 -23
- package/src/index.ts +20 -21
- package/src/resolve/index.ts +2 -4
- package/src/types/agents.ts +7 -3
- package/src/types/applications.ts +68 -50
- package/src/types/context.ts +17 -7
- package/src/types/cors.ts +0 -2
- package/src/types/datasets.ts +0 -6
- package/src/types/functions/index.ts +100 -21
- package/src/types/installation-config.ts +14 -11
- package/src/types/permissions.ts +8 -4
- package/src/types/projects.ts +6 -4
- package/src/types/robotTokens.ts +15 -4
- package/src/types/roles.ts +10 -9
- package/src/types/studios.ts +33 -14
- package/src/types/webhooks.ts +0 -3
- package/src/utils/debounce.ts +0 -25
- package/src/utils/parse-duration.ts +27 -0
- package/src/utils/throttle.ts +25 -0
- package/src/utils/validation.ts +24 -17
- package/src/validation/applications.ts +6 -2
- package/src/validation/blueprints.ts +132 -5
- package/src/validation/functions.ts +183 -37
- package/src/validation/projects.ts +4 -0
- package/src/validation/resources.ts +1 -1
- package/src/validation/studios.ts +3 -0
|
@@ -1,29 +1,50 @@
|
|
|
1
1
|
import {type BlueprintQueueFunctionConfig, type BlueprintQueueFunctionResource, validateQueueFunction} from '../../index.js'
|
|
2
2
|
import {createDebounceObject} from '../../utils/debounce.js'
|
|
3
|
+
import {createThrottleObject} from '../../utils/throttle.js'
|
|
3
4
|
import {runValidation} from '../../utils/validation.js'
|
|
4
5
|
import {defineFunction} from './index.js'
|
|
5
6
|
/**
|
|
6
7
|
* Defines a function that provide queueing behaviour.
|
|
7
8
|
*
|
|
9
|
+
* Deploying Queue Functions via Blueprints is experimental. This feature is not available publicly yet.
|
|
10
|
+
*
|
|
8
11
|
* @remarks
|
|
9
|
-
*
|
|
12
|
+
* Fields left out use the functions service defaults: `concurrency: {limit: 2, fifo: false}` and `maxAttempts: 3`.
|
|
13
|
+
* Changing `concurrency.fifo` on a deployed function replaces its queue, and messages still waiting in the old queue are lost.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
10
16
|
* ```ts
|
|
11
17
|
* defineQueueFunction({
|
|
12
18
|
* name: 'send-email',
|
|
13
19
|
* })
|
|
14
20
|
* ```
|
|
15
21
|
*
|
|
16
|
-
*
|
|
22
|
+
* @example Processing messages one at a time, in order
|
|
23
|
+
* ```ts
|
|
24
|
+
* defineQueueFunction({
|
|
25
|
+
* name: 'sync-inventory',
|
|
26
|
+
* concurrency: {limit: 1, fifo: true},
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example Keeping each document's messages in order, with up to 5 documents at once
|
|
17
31
|
* ```ts
|
|
18
32
|
* defineQueueFunction({
|
|
19
33
|
* name: 'bustin-caches',
|
|
20
|
-
* concurrency: 5,
|
|
21
|
-
*
|
|
22
|
-
*
|
|
34
|
+
* concurrency: {limit: 5, fifo: true, key: 'event.data.documentId'},
|
|
35
|
+
* maxAttempts: 5,
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example Starting at most 100 messages per minute, paced per tenant, with bursts of up to 10
|
|
40
|
+
* ```ts
|
|
41
|
+
* defineQueueFunction({
|
|
42
|
+
* name: 'call-rate-limited-api',
|
|
43
|
+
* throttle: {limit: 100, period: '1 minute', burst: 10, key: 'event.data.tenantId'},
|
|
23
44
|
* })
|
|
24
45
|
* ```
|
|
25
46
|
* @public
|
|
26
|
-
* @alpha
|
|
47
|
+
* @alpha
|
|
27
48
|
* @hidden
|
|
28
49
|
* @category Definers
|
|
29
50
|
* @expandType BlueprintQueueFunctionConfig
|
|
@@ -31,19 +52,19 @@ import {defineFunction} from './index.js'
|
|
|
31
52
|
* @returns The validated queue function resource
|
|
32
53
|
*/
|
|
33
54
|
export function defineQueueFunction(functionConfig: BlueprintQueueFunctionConfig): BlueprintQueueFunctionResource {
|
|
34
|
-
const {concurrency
|
|
55
|
+
const {concurrency, debounce, event, maxAttempts, throttle} = functionConfig
|
|
35
56
|
|
|
36
57
|
const functionResource: BlueprintQueueFunctionResource = {
|
|
37
58
|
...defineFunction(functionConfig, {skipValidation: true}),
|
|
38
59
|
type: 'sanity.function.queue',
|
|
39
60
|
...(concurrency !== undefined && {concurrency}),
|
|
40
61
|
...(debounce !== undefined && {debounce: createDebounceObject(debounce)}),
|
|
41
|
-
...(dlq !== undefined && {dlq}),
|
|
42
62
|
...(event !== undefined && {event}),
|
|
43
|
-
...(
|
|
63
|
+
...(maxAttempts !== undefined && {maxAttempts}),
|
|
64
|
+
...(throttle !== undefined && {throttle: createThrottleObject(throttle)}),
|
|
44
65
|
}
|
|
45
66
|
|
|
46
|
-
runValidation(() => validateQueueFunction(functionResource))
|
|
67
|
+
runValidation(functionResource, () => validateQueueFunction(functionResource))
|
|
47
68
|
|
|
48
69
|
return functionResource
|
|
49
70
|
}
|
|
@@ -21,7 +21,11 @@ const SCHEDULED_EVENT_KEYS = new Set<ScheduledFunctionEventKey>(['minute', 'hour
|
|
|
21
21
|
* Supports cron expressions or natural language schedules.
|
|
22
22
|
*
|
|
23
23
|
* @remarks
|
|
24
|
-
*
|
|
24
|
+
* The `event.expression` field accepts standard cron expressions or natural language:
|
|
25
|
+
* `'every 15 minutes'`, `'weekdays at 8am'`, `'fridays in the evening'`,
|
|
26
|
+
* `'mon, wed, fri at 9am'`, `'first of the month at noon'`
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
25
29
|
* ```ts
|
|
26
30
|
* defineScheduledFunction({
|
|
27
31
|
* name: 'daily-cleanup',
|
|
@@ -29,7 +33,7 @@ const SCHEDULED_EVENT_KEYS = new Set<ScheduledFunctionEventKey>(['minute', 'hour
|
|
|
29
33
|
* })
|
|
30
34
|
* ```
|
|
31
35
|
*
|
|
32
|
-
*
|
|
36
|
+
* @example Explicit cron fields
|
|
33
37
|
* ```ts
|
|
34
38
|
* defineScheduledFunction({
|
|
35
39
|
* name: 'daily-cleanup',
|
|
@@ -37,10 +41,7 @@ const SCHEDULED_EVENT_KEYS = new Set<ScheduledFunctionEventKey>(['minute', 'hour
|
|
|
37
41
|
* })
|
|
38
42
|
* ```
|
|
39
43
|
*
|
|
40
|
-
*
|
|
41
|
-
* `'every 15 minutes'`, `'weekdays at 8am'`, `'fridays in the evening'`,
|
|
42
|
-
* `'mon, wed, fri at 9am'`, `'first of the month at noon'`
|
|
43
|
-
*
|
|
44
|
+
* @example Natural language schedule
|
|
44
45
|
* ```ts
|
|
45
46
|
* defineScheduledFunction({
|
|
46
47
|
* name: 'daily-cleanup',
|
|
@@ -70,7 +71,7 @@ export function defineScheduledFunction(functionConfig: BlueprintScheduledFuncti
|
|
|
70
71
|
functionResource.event = cronStringToExplicitEvent(cron)
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
runValidation(() => validateScheduledFunction(functionResource))
|
|
74
|
+
runValidation(functionResource, () => validateScheduledFunction(functionResource))
|
|
74
75
|
|
|
75
76
|
return functionResource
|
|
76
77
|
}
|
|
@@ -9,14 +9,17 @@ import {defineFunction} from './index.js'
|
|
|
9
9
|
* Defines a function that is triggered on a sync tag invalidate event.
|
|
10
10
|
*
|
|
11
11
|
* @remarks
|
|
12
|
-
*
|
|
12
|
+
* By default, the event covers all datasets in the function project.
|
|
13
|
+
* Set `event.resource` to scope the event to one dataset.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
13
16
|
* ```ts
|
|
14
17
|
* defineSyncTagInvalidateFunction({
|
|
15
18
|
* name: 'bustin-caches',
|
|
16
19
|
* })
|
|
17
20
|
* ```
|
|
18
21
|
*
|
|
19
|
-
*
|
|
22
|
+
* @example Scoped to one dataset
|
|
20
23
|
* ```ts
|
|
21
24
|
* defineSyncTagInvalidateFunction({
|
|
22
25
|
* name: 'bustin-caches',
|
|
@@ -45,7 +48,7 @@ export function defineSyncTagInvalidateFunction(
|
|
|
45
48
|
...(event?.resource ? {event} : {}),
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
runValidation(() => validateSyncTagInvalidateFunction(functionResource))
|
|
51
|
+
runValidation(functionResource, () => validateSyncTagInvalidateFunction(functionResource))
|
|
49
52
|
|
|
50
53
|
return functionResource
|
|
51
54
|
}
|
|
@@ -4,12 +4,15 @@ import {runValidation} from '../utils/validation.js'
|
|
|
4
4
|
/**
|
|
5
5
|
* Defines a singleton Media Library configuration.
|
|
6
6
|
*
|
|
7
|
+
* Configuring the Media Library via Blueprints is experimental. This may be subject to breaking changes.
|
|
8
|
+
*
|
|
7
9
|
* @remarks
|
|
8
10
|
* The Media Library is a Sanity-owned singleton, so this resource carries no
|
|
9
11
|
* application identity of its own — only the config `root` and its `fields`.
|
|
10
12
|
* The provider resolves the organization's media library installation id at
|
|
11
13
|
* deploy time.
|
|
12
14
|
*
|
|
15
|
+
* @example
|
|
13
16
|
* ```ts
|
|
14
17
|
* defineMediaLibraryConfig({
|
|
15
18
|
* name: 'media-library',
|
|
@@ -19,11 +22,10 @@ import {runValidation} from '../utils/validation.js'
|
|
|
19
22
|
* ```
|
|
20
23
|
* @param config The Media Library configuration
|
|
21
24
|
* @public
|
|
22
|
-
* @beta
|
|
25
|
+
* @beta
|
|
23
26
|
* @category Definers
|
|
24
27
|
* @expandType BlueprintMediaLibraryConfigConfig
|
|
25
28
|
* @returns The Media Library configuration resource
|
|
26
|
-
* @hidden
|
|
27
29
|
*/
|
|
28
30
|
export function defineMediaLibraryConfig(config: BlueprintMediaLibraryConfigConfig): BlueprintMediaLibraryConfigResource {
|
|
29
31
|
const resource = {
|
|
@@ -32,7 +34,7 @@ export function defineMediaLibraryConfig(config: BlueprintMediaLibraryConfigConf
|
|
|
32
34
|
appType: 'media-library',
|
|
33
35
|
} satisfies BlueprintMediaLibraryConfigResource
|
|
34
36
|
|
|
35
|
-
runValidation(() => validateMediaLibraryConfig(resource))
|
|
37
|
+
runValidation(resource, () => validateMediaLibraryConfig(resource))
|
|
36
38
|
|
|
37
39
|
return resource
|
|
38
40
|
}
|
|
@@ -10,6 +10,9 @@ import {runValidation} from '../utils/validation.js'
|
|
|
10
10
|
/**
|
|
11
11
|
* Defines a custom permission that roles can grant, in the shape of the Access API.
|
|
12
12
|
*
|
|
13
|
+
* Deploying Permissions via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
13
16
|
* ```ts
|
|
14
17
|
* definePermission({
|
|
15
18
|
* name: 'articles-only',
|
|
@@ -42,7 +45,7 @@ import {runValidation} from '../utils/validation.js'
|
|
|
42
45
|
* ```
|
|
43
46
|
* @param parameters The configuration of the permission
|
|
44
47
|
* @public
|
|
45
|
-
* @beta
|
|
48
|
+
* @beta
|
|
46
49
|
* @category Definers
|
|
47
50
|
* @expandType BlueprintPermissionConfig
|
|
48
51
|
* @returns The permission resource
|
|
@@ -53,7 +56,7 @@ export function definePermission(parameters: BlueprintPermissionConfig): Bluepri
|
|
|
53
56
|
type: 'sanity.access.permission',
|
|
54
57
|
}
|
|
55
58
|
|
|
56
|
-
runValidation(() => validatePermission(permissionResource))
|
|
59
|
+
runValidation(permissionResource, () => validatePermission(permissionResource))
|
|
57
60
|
|
|
58
61
|
return permissionResource
|
|
59
62
|
}
|
|
@@ -61,6 +64,9 @@ export function definePermission(parameters: BlueprintPermissionConfig): Bluepri
|
|
|
61
64
|
/**
|
|
62
65
|
* Defines a content resource as the Manage UI makes it: a custom permission of type `sanity.document.filter.mode`.
|
|
63
66
|
*
|
|
67
|
+
* Deploying Permissions via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
64
70
|
* ```ts
|
|
65
71
|
* defineContentResource({
|
|
66
72
|
* name: 'movies',
|
|
@@ -81,7 +87,7 @@ export function definePermission(parameters: BlueprintPermissionConfig): Bluepri
|
|
|
81
87
|
* ```
|
|
82
88
|
* @param parameters The configuration of the content resource
|
|
83
89
|
* @public
|
|
84
|
-
* @beta
|
|
90
|
+
* @beta
|
|
85
91
|
* @category Definers
|
|
86
92
|
* @expandType BlueprintContentResourceConfig
|
|
87
93
|
* @returns The permission resource
|
|
@@ -89,13 +95,15 @@ export function definePermission(parameters: BlueprintPermissionConfig): Bluepri
|
|
|
89
95
|
export function defineContentResource(parameters: BlueprintContentResourceConfig): BlueprintPermissionResource {
|
|
90
96
|
const {documentTypes, filter, ...permission} = parameters
|
|
91
97
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return definePermission({
|
|
98
|
+
const permissionResource = definePermission({
|
|
95
99
|
...permission,
|
|
96
100
|
permissionType: 'sanity.document.filter.mode',
|
|
97
101
|
config: {filter: contentResourceFilter(documentTypes, filter)},
|
|
98
102
|
})
|
|
103
|
+
|
|
104
|
+
runValidation(permissionResource, () => validateContentResource(parameters))
|
|
105
|
+
|
|
106
|
+
return permissionResource
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
function contentResourceFilter(documentTypes: unknown, filter?: string): string {
|
package/src/definers/projects.ts
CHANGED
|
@@ -11,19 +11,19 @@ import {runValidation} from '../utils/validation.js'
|
|
|
11
11
|
/**
|
|
12
12
|
* Defines a project.
|
|
13
13
|
*
|
|
14
|
+
* @example
|
|
14
15
|
* ```ts
|
|
15
16
|
* defineProject({
|
|
16
17
|
* name: 'my-project',
|
|
17
18
|
* displayName: 'My Project',
|
|
19
|
+
* logo: './logo.png',
|
|
18
20
|
* })
|
|
19
21
|
* ```
|
|
20
22
|
* @param parameters The project configuration
|
|
21
23
|
* @public
|
|
22
|
-
* @beta Deploying Projects via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
23
24
|
* @category Definers
|
|
24
25
|
* @expandType BlueprintProjectConfig
|
|
25
26
|
* @returns The project resource
|
|
26
|
-
* @hidden
|
|
27
27
|
*/
|
|
28
28
|
export function defineProject(parameters: BlueprintProjectConfig): BlueprintProjectResource {
|
|
29
29
|
// default project name
|
|
@@ -35,7 +35,7 @@ export function defineProject(parameters: BlueprintProjectConfig): BlueprintProj
|
|
|
35
35
|
type: 'sanity.project',
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
runValidation(() => validateProject(projectResource))
|
|
38
|
+
runValidation(projectResource, () => validateProject(projectResource))
|
|
39
39
|
|
|
40
40
|
return projectResource
|
|
41
41
|
}
|
|
@@ -43,6 +43,7 @@ export function defineProject(parameters: BlueprintProjectConfig): BlueprintProj
|
|
|
43
43
|
/**
|
|
44
44
|
* Creates a reference to a project in another stack.
|
|
45
45
|
*
|
|
46
|
+
* @example
|
|
46
47
|
* ```ts
|
|
47
48
|
* referenceProject({
|
|
48
49
|
* name: 'editorial-project',
|
|
@@ -52,10 +53,8 @@ export function defineProject(parameters: BlueprintProjectConfig): BlueprintProj
|
|
|
52
53
|
*
|
|
53
54
|
* @param params The parameters for referencing the project
|
|
54
55
|
* @public
|
|
55
|
-
* @beta Referencing Projects via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
56
56
|
* @category Referencers
|
|
57
57
|
* @returns The project reference
|
|
58
|
-
* @hidden
|
|
59
58
|
*/
|
|
60
59
|
export function referenceProject({name, stack, localName}: BlueprintCrossStackReferenceConfig): BlueprintResource {
|
|
61
60
|
return referenceResource({name, stack, localName, type: 'sanity.project'})
|
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
import {assertResource, type BlueprintCrossStackReferenceResourceConfig, type BlueprintResource} from '../index.js'
|
|
2
2
|
|
|
3
|
-
/*
|
|
4
|
-
* FUTURE example (move below @example when ready)
|
|
5
|
-
* @example With lifecycle
|
|
6
|
-
* ```ts
|
|
7
|
-
* defineResource({
|
|
8
|
-
* name: 'my-resource',
|
|
9
|
-
* type: 'sanity.new.resource',
|
|
10
|
-
* lifecycle: {deletionPolicy: 'retain'},
|
|
11
|
-
* })
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
3
|
/**
|
|
15
4
|
* Defines a generic resource to be managed in Blueprints.
|
|
16
5
|
*
|
|
17
6
|
* @remarks
|
|
18
7
|
* This is useful if the resource type does not yet have a `define*` function.
|
|
19
8
|
*
|
|
9
|
+
* @example
|
|
20
10
|
* ```ts
|
|
21
11
|
* defineResource({
|
|
22
12
|
* name: 'my-resource',
|
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type BlueprintCrossStackReferenceConfig,
|
|
3
|
+
type BlueprintError,
|
|
3
4
|
type BlueprintResource,
|
|
4
5
|
type BlueprintRobotTokenConfig,
|
|
5
6
|
type BlueprintRobotTokenResource,
|
|
7
|
+
type RobotTokenMembership,
|
|
8
|
+
type RobotTokenMembershipConfig,
|
|
6
9
|
referenceResource,
|
|
7
10
|
validateRobotToken,
|
|
8
11
|
} from '../index.js'
|
|
9
12
|
import {runValidation} from '../utils/validation.js'
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
*
|
|
14
|
+
/**
|
|
15
|
+
* Defines a Robot Token for automated access. Has a token property provided during deployment that can be referenced by other resources.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* defineRobotToken({
|
|
20
|
+
* name: 'my-robot',
|
|
21
|
+
* memberships: [{
|
|
22
|
+
* project: 'my-project-id',
|
|
23
|
+
* roleNames: ['editor'],
|
|
24
|
+
* }],
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
13
28
|
* @example Cross-resource references
|
|
14
29
|
* ```ts
|
|
15
30
|
* defineRole({
|
|
16
31
|
* name: 'ci-deploy-role',
|
|
17
32
|
* title: 'CI Deploy Role',
|
|
18
33
|
* appliesToRobots: true,
|
|
34
|
+
* appliesToUsers: false,
|
|
19
35
|
* permissions: [{name: 'sanity-project-cors', action: 'create'}],
|
|
20
36
|
* })
|
|
21
37
|
*
|
|
@@ -27,44 +43,64 @@ import {runValidation} from '../utils/validation.js'
|
|
|
27
43
|
* }],
|
|
28
44
|
* })
|
|
29
45
|
* ```
|
|
30
|
-
*/
|
|
31
|
-
/**
|
|
32
|
-
* Defines a Robot Token for automated access. Has a token property provided during deployment that can be referenced by other resources.
|
|
33
|
-
*
|
|
34
|
-
* ```ts
|
|
35
|
-
* defineRobotToken({
|
|
36
|
-
* name: 'my-robot',
|
|
37
|
-
* memberships: [{
|
|
38
|
-
* resourceType: 'project',
|
|
39
|
-
* resourceId: projectId,
|
|
40
|
-
* roleNames: ['editor'],
|
|
41
|
-
* }],
|
|
42
|
-
* })
|
|
43
|
-
* ```
|
|
44
46
|
* @param parameters The robot token configuration
|
|
45
47
|
* @public
|
|
46
|
-
* @beta Deploying Robot Tokens via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
47
48
|
* @category Definers
|
|
48
49
|
* @expandType BlueprintRobotTokenConfig
|
|
49
50
|
* @returns The robot token resource
|
|
50
51
|
*/
|
|
51
52
|
export function defineRobotToken(parameters: BlueprintRobotTokenConfig): BlueprintRobotTokenResource {
|
|
53
|
+
const {project, memberships, ...rest} = parameters
|
|
52
54
|
const label = parameters.label || parameters.name
|
|
53
55
|
|
|
54
56
|
const robotResource: BlueprintRobotTokenResource = {
|
|
55
|
-
...
|
|
57
|
+
...rest,
|
|
56
58
|
label,
|
|
57
59
|
type: 'sanity.access.robot',
|
|
60
|
+
// malformed memberships pass through untouched, so validation reports them instead of throwing here
|
|
61
|
+
memberships: Array.isArray(memberships) ? memberships.map(toMembership) : memberships,
|
|
62
|
+
}
|
|
63
|
+
if (project !== undefined) {
|
|
64
|
+
robotResource.resourceType = 'project'
|
|
65
|
+
robotResource.resourceId = project
|
|
58
66
|
}
|
|
59
67
|
|
|
60
|
-
runValidation(() =>
|
|
68
|
+
runValidation(robotResource, () => [
|
|
69
|
+
...validateProjectScope(parameters, 'Robot token'),
|
|
70
|
+
...(Array.isArray(memberships) ? memberships.flatMap((membership) => validateProjectScope(membership, 'Membership')) : []),
|
|
71
|
+
...validateRobotToken(robotResource),
|
|
72
|
+
])
|
|
61
73
|
|
|
62
74
|
return robotResource
|
|
63
75
|
}
|
|
64
76
|
|
|
77
|
+
function toMembership(membership: RobotTokenMembershipConfig): RobotTokenMembership {
|
|
78
|
+
if (typeof membership !== 'object' || membership === null) return membership
|
|
79
|
+
const {project, ...rest} = membership
|
|
80
|
+
const result: RobotTokenMembership = rest
|
|
81
|
+
if (project !== undefined) {
|
|
82
|
+
result.resourceType = 'project'
|
|
83
|
+
result.resourceId = project
|
|
84
|
+
}
|
|
85
|
+
return result
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* `project` sets `resourceType` and `resourceId`, so it can't be combined with them.
|
|
90
|
+
* @param scope The robot token or membership options that were passed to the definer
|
|
91
|
+
* @param label The label used as the prefix of error messages
|
|
92
|
+
* @returns A list of validation errors
|
|
93
|
+
*/
|
|
94
|
+
function validateProjectScope(scope: unknown, label: string): BlueprintError[] {
|
|
95
|
+
if (typeof scope !== 'object' || scope === null || !('project' in scope) || scope.project === undefined) return []
|
|
96
|
+
if (!('resourceType' in scope) && !('resourceId' in scope)) return []
|
|
97
|
+
return [{type: 'invalid_value', message: `${label} \`project\` can't be combined with \`resourceType\` or \`resourceId\``}]
|
|
98
|
+
}
|
|
99
|
+
|
|
65
100
|
/**
|
|
66
101
|
* Creates a reference to a robot token in another stack.
|
|
67
102
|
*
|
|
103
|
+
* @example
|
|
68
104
|
* ```ts
|
|
69
105
|
* referenceRobotToken({
|
|
70
106
|
* name: 'editor-token',
|
|
@@ -73,7 +109,6 @@ export function defineRobotToken(parameters: BlueprintRobotTokenConfig): Bluepri
|
|
|
73
109
|
* ```
|
|
74
110
|
*
|
|
75
111
|
* @public
|
|
76
|
-
* @beta Referencing Robot Tokens via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
77
112
|
* @category Referencers
|
|
78
113
|
* @expandType BlueprintCrossStackReferenceConfig
|
|
79
114
|
* @param params The parameters for referencing the robot token
|
package/src/definers/roles.ts
CHANGED
|
@@ -10,14 +10,30 @@ import {
|
|
|
10
10
|
} from '../index.js'
|
|
11
11
|
import {runValidation} from '../utils/validation.js'
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
*
|
|
13
|
+
/**
|
|
14
|
+
* Defines a custom role. Set `project` to scope the role to a project. Without it, the role is scoped to the same resource
|
|
15
|
+
* as the blueprint.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* defineRole({
|
|
20
|
+
* name: 'custom-robot-role',
|
|
21
|
+
* title: 'Custom Robot Role',
|
|
22
|
+
* appliesToRobots: true,
|
|
23
|
+
* appliesToUsers: false,
|
|
24
|
+
* permissions: [{
|
|
25
|
+
* name: 'sanity-project-cors',
|
|
26
|
+
* action: 'create',
|
|
27
|
+
* }],
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
15
31
|
* @example All options
|
|
16
32
|
* ```ts
|
|
17
33
|
* defineRole({
|
|
18
34
|
* name: 'ci-deploy-role',
|
|
19
35
|
* title: 'CI Deploy Role',
|
|
20
|
-
* description: 'Permissions for CI/CD pipelines to manage CORS
|
|
36
|
+
* description: 'Permissions for CI/CD pipelines to manage CORS origins',
|
|
21
37
|
* appliesToRobots: true,
|
|
22
38
|
* appliesToUsers: false,
|
|
23
39
|
* permissions: [{
|
|
@@ -32,29 +48,40 @@ import {runValidation} from '../utils/validation.js'
|
|
|
32
48
|
* }],
|
|
33
49
|
* })
|
|
34
50
|
* ```
|
|
35
|
-
*/
|
|
36
|
-
/**
|
|
37
|
-
* Defines a role that is scoped to the same resource as the blueprint.
|
|
38
51
|
*
|
|
52
|
+
* @example In a project, for a robot token
|
|
39
53
|
* ```ts
|
|
40
54
|
* defineRole({
|
|
41
|
-
* name: '
|
|
42
|
-
* title: '
|
|
55
|
+
* name: 'ci-deploy-role',
|
|
56
|
+
* title: 'CI Deploy Role',
|
|
57
|
+
* project: 'my-project-id',
|
|
43
58
|
* appliesToRobots: true,
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
59
|
+
* appliesToUsers: false,
|
|
60
|
+
* permissions: [{name: 'sanity-project-cors', action: 'create'}],
|
|
61
|
+
* })
|
|
62
|
+
*
|
|
63
|
+
* defineRobotToken({
|
|
64
|
+
* name: 'ci-robot',
|
|
65
|
+
* memberships: [{project: 'my-project-id', roleNames: ['$.resources.ci-deploy-role']}],
|
|
48
66
|
* })
|
|
49
67
|
* ```
|
|
50
68
|
* @param parameters The configuration of the role
|
|
51
69
|
* @public
|
|
52
|
-
* @beta Deploying Roles via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
53
70
|
* @category Definers
|
|
54
71
|
* @expandType BlueprintRoleConfig
|
|
55
72
|
* @returns The role resource
|
|
56
73
|
*/
|
|
57
|
-
export function defineRole(parameters: BlueprintRoleConfig
|
|
74
|
+
export function defineRole(parameters: BlueprintRoleConfig): BlueprintRoleResource {
|
|
75
|
+
if (parameters.project !== undefined) return defineRoleInProject(parameters.project, parameters)
|
|
76
|
+
|
|
77
|
+
const roleResource = buildRoleResource(parameters)
|
|
78
|
+
|
|
79
|
+
runValidation(roleResource, () => validateRole(roleResource))
|
|
80
|
+
|
|
81
|
+
return roleResource
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function buildRoleResource(parameters: BlueprintRoleConfig): BlueprintRoleResource {
|
|
58
85
|
const roleResource: BlueprintRoleResource = {
|
|
59
86
|
name: parameters.name,
|
|
60
87
|
type: 'sanity.access.role',
|
|
@@ -69,46 +96,33 @@ export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValid
|
|
|
69
96
|
roleResource.lifecycle = parameters.lifecycle
|
|
70
97
|
}
|
|
71
98
|
|
|
72
|
-
if (options?.skipValidation !== true) runValidation(() => validateRole(roleResource))
|
|
73
|
-
|
|
74
99
|
return roleResource
|
|
75
100
|
}
|
|
76
101
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
* name: 'sanity-project-cors',
|
|
90
|
-
* action: 'delete',
|
|
91
|
-
* }],
|
|
92
|
-
* })
|
|
93
|
-
*
|
|
94
|
-
* defineRobotToken({
|
|
95
|
-
* name: 'ci-robot',
|
|
96
|
-
* memberships: [{
|
|
97
|
-
* resourceType: 'project',
|
|
98
|
-
* resourceId: projectId,
|
|
99
|
-
* roleNames: ['$.resources.ci-deploy-role'],
|
|
100
|
-
* }],
|
|
101
|
-
* })
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
102
|
+
function defineRoleInProject(project: string, parameters: BlueprintRoleConfig): BlueprintProjectRoleResource {
|
|
103
|
+
const projectRoleResource: BlueprintProjectRoleResource = {
|
|
104
|
+
...buildRoleResource(parameters),
|
|
105
|
+
resourceType: 'project',
|
|
106
|
+
resourceId: project,
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
runValidation(projectRoleResource, () => validateProjectRole(projectRoleResource))
|
|
110
|
+
|
|
111
|
+
return projectRoleResource
|
|
112
|
+
}
|
|
113
|
+
|
|
104
114
|
/**
|
|
105
115
|
* Defines a role that is scoped to the specified project.
|
|
106
116
|
*
|
|
117
|
+
* @deprecated Use {@link defineRole} with `project` instead.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
107
120
|
* ```ts
|
|
108
|
-
* defineProjectRole(
|
|
121
|
+
* defineProjectRole('my-project-id', {
|
|
109
122
|
* name: 'viewer-role',
|
|
110
123
|
* title: 'Viewer',
|
|
111
124
|
* appliesToUsers: true,
|
|
125
|
+
* appliesToRobots: false,
|
|
112
126
|
* permissions: [{
|
|
113
127
|
* name: 'sanity-project-cors',
|
|
114
128
|
* action: 'read',
|
|
@@ -116,8 +130,6 @@ export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValid
|
|
|
116
130
|
* })
|
|
117
131
|
* ```
|
|
118
132
|
* @public
|
|
119
|
-
* @beta Deploying Roles via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
120
|
-
* @hidden
|
|
121
133
|
* @category Definers
|
|
122
134
|
* @expandType BlueprintRoleConfig
|
|
123
135
|
* @param projectId The ID of the project to which the role will be scoped
|
|
@@ -125,22 +137,13 @@ export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValid
|
|
|
125
137
|
* @returns The role resource
|
|
126
138
|
*/
|
|
127
139
|
export function defineProjectRole(projectId: string, parameters: BlueprintRoleConfig): BlueprintProjectRoleResource {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const projectRoleResource: BlueprintProjectRoleResource = {
|
|
131
|
-
...roleResource,
|
|
132
|
-
resourceType: 'project',
|
|
133
|
-
resourceId: projectId,
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
runValidation(() => validateProjectRole(projectRoleResource))
|
|
137
|
-
|
|
138
|
-
return projectRoleResource
|
|
140
|
+
return defineRoleInProject(projectId, parameters)
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
/**
|
|
142
144
|
* Creates a reference to a role in another stack.
|
|
143
145
|
*
|
|
146
|
+
* @example
|
|
144
147
|
* ```ts
|
|
145
148
|
* referenceRole({
|
|
146
149
|
* name: 'editor-role',
|
|
@@ -149,7 +152,6 @@ export function defineProjectRole(projectId: string, parameters: BlueprintRoleCo
|
|
|
149
152
|
* ```
|
|
150
153
|
*
|
|
151
154
|
* @public
|
|
152
|
-
* @beta Referencing Roles via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
153
155
|
* @category Referencers
|
|
154
156
|
* @expandType BlueprintCrossStackReferenceConfig
|
|
155
157
|
* @param params The parameters for referencing the role
|
package/src/definers/studios.ts
CHANGED
|
@@ -5,6 +5,9 @@ import {runValidation} from '../utils/validation.js'
|
|
|
5
5
|
/**
|
|
6
6
|
* Defines a studio.
|
|
7
7
|
*
|
|
8
|
+
* Deploying Studios via Blueprints is experimental. This may be subject to breaking changes.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
8
11
|
* ```ts
|
|
9
12
|
* defineStudio({
|
|
10
13
|
* name: 'my-studio',
|
|
@@ -15,13 +18,12 @@ import {runValidation} from '../utils/validation.js'
|
|
|
15
18
|
* }
|
|
16
19
|
* })
|
|
17
20
|
* ```
|
|
18
|
-
* @param
|
|
21
|
+
* @param config The studio configuration
|
|
19
22
|
* @public
|
|
20
|
-
* @beta
|
|
23
|
+
* @beta
|
|
21
24
|
* @category Definers
|
|
22
25
|
* @expandType BlueprintStudioConfig
|
|
23
26
|
* @returns The studio resource
|
|
24
|
-
* @hidden
|
|
25
27
|
*/
|
|
26
28
|
export function defineStudio(config: BlueprintStudioConfig): BlueprintStudioResource {
|
|
27
29
|
const autoUpdates: BlueprintStudioResource['autoUpdates'] = {enabled: config.autoUpdates?.enabled ?? true}
|
|
@@ -37,7 +39,7 @@ export function defineStudio(config: BlueprintStudioConfig): BlueprintStudioReso
|
|
|
37
39
|
type: 'sanity.studio',
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
runValidation(() => validateStudio(studioResource))
|
|
42
|
+
runValidation(studioResource, () => validateStudio(studioResource))
|
|
41
43
|
|
|
42
44
|
return studioResource
|
|
43
45
|
}
|