@sanity/blueprints 0.35.0 → 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.js +1 -1
- package/dist/definers/agents.js.map +1 -1
- package/dist/definers/applications.js +6 -6
- package/dist/definers/applications.js.map +1 -1
- package/dist/definers/blueprints.js +4 -2
- package/dist/definers/blueprints.js.map +1 -1
- package/dist/definers/context.js +2 -2
- package/dist/definers/context.js.map +1 -1
- package/dist/definers/cors.js +1 -1
- package/dist/definers/cors.js.map +1 -1
- package/dist/definers/datasets.d.ts +18 -1
- package/dist/definers/datasets.js +21 -2
- package/dist/definers/datasets.js.map +1 -1
- package/dist/definers/functions/document.d.ts +1 -2
- package/dist/definers/functions/document.js +1 -1
- package/dist/definers/functions/document.js.map +1 -1
- package/dist/definers/functions/durable.js +1 -1
- 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 +1 -2
- package/dist/definers/functions/media-library.js +2 -3
- package/dist/definers/functions/media-library.js.map +1 -1
- package/dist/definers/functions/pubsub.js +1 -1
- package/dist/definers/functions/pubsub.js.map +1 -1
- package/dist/definers/functions/queue.d.ts +16 -7
- package/dist/definers/functions/queue.js +18 -10
- package/dist/definers/functions/queue.js.map +1 -1
- package/dist/definers/functions/scheduled.js +1 -1
- package/dist/definers/functions/scheduled.js.map +1 -1
- package/dist/definers/functions/sync-tag-invalidate.js +1 -1
- package/dist/definers/functions/sync-tag-invalidate.js.map +1 -1
- package/dist/definers/installation-config.js +1 -1
- package/dist/definers/installation-config.js.map +1 -1
- package/dist/definers/permissions.js +4 -3
- package/dist/definers/permissions.js.map +1 -1
- package/dist/definers/projects.js +1 -1
- package/dist/definers/projects.js.map +1 -1
- package/dist/definers/robotTokens.d.ts +1 -2
- package/dist/definers/robotTokens.js +38 -4
- package/dist/definers/robotTokens.js.map +1 -1
- package/dist/definers/roles.d.ts +22 -30
- package/dist/definers/roles.js +39 -38
- package/dist/definers/roles.js.map +1 -1
- package/dist/definers/studios.js +1 -1
- package/dist/definers/studios.js.map +1 -1
- package/dist/definers/webhooks.js +3 -5
- package/dist/definers/webhooks.js.map +1 -1
- package/dist/types/applications.d.ts +1 -1
- package/dist/types/functions/index.d.ts +36 -11
- package/dist/types/installation-config.d.ts +1 -1
- package/dist/types/robotTokens.d.ts +14 -1
- package/dist/types/roles.d.ts +10 -5
- package/dist/types/studios.d.ts +1 -1
- 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/blueprints.js +120 -4
- package/dist/validation/blueprints.js.map +1 -1
- package/dist/validation/functions.d.ts +9 -0
- package/dist/validation/functions.js +65 -32
- package/dist/validation/functions.js.map +1 -1
- package/dist/validation/resources.js +1 -1
- package/dist/validation/resources.js.map +1 -1
- package/package.json +1 -1
- package/src/definers/agents.ts +1 -1
- package/src/definers/applications.ts +6 -6
- package/src/definers/blueprints.ts +3 -2
- package/src/definers/context.ts +2 -2
- package/src/definers/cors.ts +1 -1
- package/src/definers/datasets.ts +29 -2
- package/src/definers/functions/document.ts +2 -3
- package/src/definers/functions/durable.ts +1 -1
- package/src/definers/functions/index.ts +1 -1
- package/src/definers/functions/media-library.ts +2 -3
- package/src/definers/functions/pubsub.ts +1 -1
- package/src/definers/functions/queue.ts +18 -10
- package/src/definers/functions/scheduled.ts +1 -1
- package/src/definers/functions/sync-tag-invalidate.ts +1 -1
- package/src/definers/installation-config.ts +1 -1
- package/src/definers/permissions.ts +6 -4
- package/src/definers/projects.ts +1 -1
- package/src/definers/robotTokens.ts +40 -4
- package/src/definers/roles.ts +45 -41
- package/src/definers/studios.ts +1 -1
- package/src/definers/webhooks.ts +3 -6
- package/src/types/applications.ts +1 -1
- package/src/types/functions/index.ts +37 -11
- package/src/types/installation-config.ts +1 -1
- package/src/types/robotTokens.ts +15 -1
- package/src/types/roles.ts +10 -5
- package/src/types/studios.ts +5 -1
- package/src/utils/validation.ts +24 -17
- package/src/validation/blueprints.ts +132 -5
- package/src/validation/functions.ts +68 -33
- package/src/validation/resources.ts +1 -1
|
@@ -33,7 +33,7 @@ export function defineFunction(
|
|
|
33
33
|
|
|
34
34
|
if (lifecycle) functionResource.lifecycle = lifecycle
|
|
35
35
|
|
|
36
|
-
if (options?.skipValidation !== true) runValidation(() => validateFunction(functionResource))
|
|
36
|
+
if (options?.skipValidation !== true) runValidation(functionResource, () => validateFunction(functionResource))
|
|
37
37
|
|
|
38
38
|
return functionResource
|
|
39
39
|
}
|
|
@@ -32,8 +32,7 @@ const MEDIA_LIBRARY_EVENT_KEYS = new Set<MediaLibraryFunctionEventKey>(['resourc
|
|
|
32
32
|
* defineRobotToken({
|
|
33
33
|
* name: 'media-robot',
|
|
34
34
|
* memberships: [{
|
|
35
|
-
*
|
|
36
|
-
* resourceId: 'my-project-id',
|
|
35
|
+
* project: 'my-project-id',
|
|
37
36
|
* roleNames: ['editor'],
|
|
38
37
|
* }],
|
|
39
38
|
* })
|
|
@@ -73,7 +72,7 @@ export function defineMediaLibraryAssetFunction(
|
|
|
73
72
|
event: buildMediaLibraryFunctionEvent(event),
|
|
74
73
|
}
|
|
75
74
|
|
|
76
|
-
runValidation(() => validateMediaLibraryAssetFunction(functionResource))
|
|
75
|
+
runValidation(functionResource, () => validateMediaLibraryAssetFunction(functionResource))
|
|
77
76
|
|
|
78
77
|
return functionResource
|
|
79
78
|
}
|
|
@@ -23,7 +23,7 @@ export function definePubSubFunction(functionConfig: BlueprintPubSubFunctionConf
|
|
|
23
23
|
type: 'sanity.function.pubsub',
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
runValidation(() => validatePubSubFunction(functionResource))
|
|
26
|
+
runValidation(functionResource, () => validatePubSubFunction(functionResource))
|
|
27
27
|
|
|
28
28
|
return functionResource
|
|
29
29
|
}
|
|
@@ -9,25 +9,34 @@ import {defineFunction} from './index.js'
|
|
|
9
9
|
* Deploying Queue Functions via Blueprints is experimental. This feature is not available publicly yet.
|
|
10
10
|
*
|
|
11
11
|
* @remarks
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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
|
|
14
16
|
* ```ts
|
|
15
17
|
* defineQueueFunction({
|
|
16
18
|
* name: 'send-email',
|
|
17
19
|
* })
|
|
18
20
|
* ```
|
|
19
21
|
*
|
|
20
|
-
*
|
|
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
|
|
21
31
|
* ```ts
|
|
22
32
|
* defineQueueFunction({
|
|
23
33
|
* name: 'bustin-caches',
|
|
24
|
-
* concurrency: 5,
|
|
25
|
-
*
|
|
26
|
-
* maxAttempts: 3,
|
|
34
|
+
* concurrency: {limit: 5, fifo: true, key: 'event.data.documentId'},
|
|
35
|
+
* maxAttempts: 5,
|
|
27
36
|
* })
|
|
28
37
|
* ```
|
|
29
38
|
*
|
|
30
|
-
* Starting at most 100 messages per minute, paced per tenant, with bursts of up to 10
|
|
39
|
+
* @example Starting at most 100 messages per minute, paced per tenant, with bursts of up to 10
|
|
31
40
|
* ```ts
|
|
32
41
|
* defineQueueFunction({
|
|
33
42
|
* name: 'call-rate-limited-api',
|
|
@@ -43,7 +52,7 @@ import {defineFunction} from './index.js'
|
|
|
43
52
|
* @returns The validated queue function resource
|
|
44
53
|
*/
|
|
45
54
|
export function defineQueueFunction(functionConfig: BlueprintQueueFunctionConfig): BlueprintQueueFunctionResource {
|
|
46
|
-
const {concurrency
|
|
55
|
+
const {concurrency, debounce, event, maxAttempts, throttle} = functionConfig
|
|
47
56
|
|
|
48
57
|
const functionResource: BlueprintQueueFunctionResource = {
|
|
49
58
|
...defineFunction(functionConfig, {skipValidation: true}),
|
|
@@ -51,12 +60,11 @@ export function defineQueueFunction(functionConfig: BlueprintQueueFunctionConfig
|
|
|
51
60
|
...(concurrency !== undefined && {concurrency}),
|
|
52
61
|
...(debounce !== undefined && {debounce: createDebounceObject(debounce)}),
|
|
53
62
|
...(event !== undefined && {event}),
|
|
54
|
-
...(fifo !== undefined && {fifo}),
|
|
55
63
|
...(maxAttempts !== undefined && {maxAttempts}),
|
|
56
64
|
...(throttle !== undefined && {throttle: createThrottleObject(throttle)}),
|
|
57
65
|
}
|
|
58
66
|
|
|
59
|
-
runValidation(() => validateQueueFunction(functionResource))
|
|
67
|
+
runValidation(functionResource, () => validateQueueFunction(functionResource))
|
|
60
68
|
|
|
61
69
|
return functionResource
|
|
62
70
|
}
|
|
@@ -71,7 +71,7 @@ export function defineScheduledFunction(functionConfig: BlueprintScheduledFuncti
|
|
|
71
71
|
functionResource.event = cronStringToExplicitEvent(cron)
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
runValidation(() => validateScheduledFunction(functionResource))
|
|
74
|
+
runValidation(functionResource, () => validateScheduledFunction(functionResource))
|
|
75
75
|
|
|
76
76
|
return functionResource
|
|
77
77
|
}
|
|
@@ -48,7 +48,7 @@ export function defineSyncTagInvalidateFunction(
|
|
|
48
48
|
...(event?.resource ? {event} : {}),
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
runValidation(() => validateSyncTagInvalidateFunction(functionResource))
|
|
51
|
+
runValidation(functionResource, () => validateSyncTagInvalidateFunction(functionResource))
|
|
52
52
|
|
|
53
53
|
return functionResource
|
|
54
54
|
}
|
|
@@ -34,7 +34,7 @@ export function defineMediaLibraryConfig(config: BlueprintMediaLibraryConfigConf
|
|
|
34
34
|
appType: 'media-library',
|
|
35
35
|
} satisfies BlueprintMediaLibraryConfigResource
|
|
36
36
|
|
|
37
|
-
runValidation(() => validateMediaLibraryConfig(resource))
|
|
37
|
+
runValidation(resource, () => validateMediaLibraryConfig(resource))
|
|
38
38
|
|
|
39
39
|
return resource
|
|
40
40
|
}
|
|
@@ -56,7 +56,7 @@ export function definePermission(parameters: BlueprintPermissionConfig): Bluepri
|
|
|
56
56
|
type: 'sanity.access.permission',
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
runValidation(() => validatePermission(permissionResource))
|
|
59
|
+
runValidation(permissionResource, () => validatePermission(permissionResource))
|
|
60
60
|
|
|
61
61
|
return permissionResource
|
|
62
62
|
}
|
|
@@ -95,13 +95,15 @@ export function definePermission(parameters: BlueprintPermissionConfig): Bluepri
|
|
|
95
95
|
export function defineContentResource(parameters: BlueprintContentResourceConfig): BlueprintPermissionResource {
|
|
96
96
|
const {documentTypes, filter, ...permission} = parameters
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return definePermission({
|
|
98
|
+
const permissionResource = definePermission({
|
|
101
99
|
...permission,
|
|
102
100
|
permissionType: 'sanity.document.filter.mode',
|
|
103
101
|
config: {filter: contentResourceFilter(documentTypes, filter)},
|
|
104
102
|
})
|
|
103
|
+
|
|
104
|
+
runValidation(permissionResource, () => validateContentResource(parameters))
|
|
105
|
+
|
|
106
|
+
return permissionResource
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
function contentResourceFilter(documentTypes: unknown, filter?: string): string {
|
package/src/definers/projects.ts
CHANGED
|
@@ -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
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
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'
|
|
@@ -16,8 +19,7 @@ import {runValidation} from '../utils/validation.js'
|
|
|
16
19
|
* defineRobotToken({
|
|
17
20
|
* name: 'my-robot',
|
|
18
21
|
* memberships: [{
|
|
19
|
-
*
|
|
20
|
-
* resourceId: 'my-project-id',
|
|
22
|
+
* project: 'my-project-id',
|
|
21
23
|
* roleNames: ['editor'],
|
|
22
24
|
* }],
|
|
23
25
|
* })
|
|
@@ -48,19 +50,53 @@ import {runValidation} from '../utils/validation.js'
|
|
|
48
50
|
* @returns The robot token resource
|
|
49
51
|
*/
|
|
50
52
|
export function defineRobotToken(parameters: BlueprintRobotTokenConfig): BlueprintRobotTokenResource {
|
|
53
|
+
const {project, memberships, ...rest} = parameters
|
|
51
54
|
const label = parameters.label || parameters.name
|
|
52
55
|
|
|
53
56
|
const robotResource: BlueprintRobotTokenResource = {
|
|
54
|
-
...
|
|
57
|
+
...rest,
|
|
55
58
|
label,
|
|
56
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
|
|
57
66
|
}
|
|
58
67
|
|
|
59
|
-
runValidation(() =>
|
|
68
|
+
runValidation(robotResource, () => [
|
|
69
|
+
...validateProjectScope(parameters, 'Robot token'),
|
|
70
|
+
...(Array.isArray(memberships) ? memberships.flatMap((membership) => validateProjectScope(membership, 'Membership')) : []),
|
|
71
|
+
...validateRobotToken(robotResource),
|
|
72
|
+
])
|
|
60
73
|
|
|
61
74
|
return robotResource
|
|
62
75
|
}
|
|
63
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
|
+
|
|
64
100
|
/**
|
|
65
101
|
* Creates a reference to a robot token in another stack.
|
|
66
102
|
*
|
package/src/definers/roles.ts
CHANGED
|
@@ -11,7 +11,8 @@ import {
|
|
|
11
11
|
import {runValidation} from '../utils/validation.js'
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Defines a role
|
|
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.
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* ```ts
|
|
@@ -47,13 +48,40 @@ import {runValidation} from '../utils/validation.js'
|
|
|
47
48
|
* }],
|
|
48
49
|
* })
|
|
49
50
|
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example In a project, for a robot token
|
|
53
|
+
* ```ts
|
|
54
|
+
* defineRole({
|
|
55
|
+
* name: 'ci-deploy-role',
|
|
56
|
+
* title: 'CI Deploy Role',
|
|
57
|
+
* project: 'my-project-id',
|
|
58
|
+
* appliesToRobots: true,
|
|
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']}],
|
|
66
|
+
* })
|
|
67
|
+
* ```
|
|
50
68
|
* @param parameters The configuration of the role
|
|
51
69
|
* @public
|
|
52
70
|
* @category Definers
|
|
53
71
|
* @expandType BlueprintRoleConfig
|
|
54
72
|
* @returns The role resource
|
|
55
73
|
*/
|
|
56
|
-
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 {
|
|
57
85
|
const roleResource: BlueprintRoleResource = {
|
|
58
86
|
name: parameters.name,
|
|
59
87
|
type: 'sanity.access.role',
|
|
@@ -68,14 +96,26 @@ export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValid
|
|
|
68
96
|
roleResource.lifecycle = parameters.lifecycle
|
|
69
97
|
}
|
|
70
98
|
|
|
71
|
-
if (options?.skipValidation !== true) runValidation(() => validateRole(roleResource))
|
|
72
|
-
|
|
73
99
|
return roleResource
|
|
74
100
|
}
|
|
75
101
|
|
|
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
|
+
|
|
76
114
|
/**
|
|
77
115
|
* Defines a role that is scoped to the specified project.
|
|
78
116
|
*
|
|
117
|
+
* @deprecated Use {@link defineRole} with `project` instead.
|
|
118
|
+
*
|
|
79
119
|
* @example
|
|
80
120
|
* ```ts
|
|
81
121
|
* defineProjectRole('my-project-id', {
|
|
@@ -89,32 +129,6 @@ export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValid
|
|
|
89
129
|
* }],
|
|
90
130
|
* })
|
|
91
131
|
* ```
|
|
92
|
-
*
|
|
93
|
-
* @example Cross-resource references
|
|
94
|
-
* ```ts
|
|
95
|
-
* defineProjectRole('my-project-id', {
|
|
96
|
-
* name: 'ci-deploy-role',
|
|
97
|
-
* title: 'CI Deploy Role',
|
|
98
|
-
* appliesToRobots: true,
|
|
99
|
-
* appliesToUsers: false,
|
|
100
|
-
* permissions: [{
|
|
101
|
-
* name: 'sanity-project-cors',
|
|
102
|
-
* action: 'create',
|
|
103
|
-
* }, {
|
|
104
|
-
* name: 'sanity-project-cors',
|
|
105
|
-
* action: 'delete',
|
|
106
|
-
* }],
|
|
107
|
-
* })
|
|
108
|
-
*
|
|
109
|
-
* defineRobotToken({
|
|
110
|
-
* name: 'ci-robot',
|
|
111
|
-
* memberships: [{
|
|
112
|
-
* resourceType: 'project',
|
|
113
|
-
* resourceId: 'my-project-id',
|
|
114
|
-
* roleNames: ['$.resources.ci-deploy-role'],
|
|
115
|
-
* }],
|
|
116
|
-
* })
|
|
117
|
-
* ```
|
|
118
132
|
* @public
|
|
119
133
|
* @category Definers
|
|
120
134
|
* @expandType BlueprintRoleConfig
|
|
@@ -123,17 +137,7 @@ export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValid
|
|
|
123
137
|
* @returns The role resource
|
|
124
138
|
*/
|
|
125
139
|
export function defineProjectRole(projectId: string, parameters: BlueprintRoleConfig): BlueprintProjectRoleResource {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const projectRoleResource: BlueprintProjectRoleResource = {
|
|
129
|
-
...roleResource,
|
|
130
|
-
resourceType: 'project',
|
|
131
|
-
resourceId: projectId,
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
runValidation(() => validateProjectRole(projectRoleResource))
|
|
135
|
-
|
|
136
|
-
return projectRoleResource
|
|
140
|
+
return defineRoleInProject(projectId, parameters)
|
|
137
141
|
}
|
|
138
142
|
|
|
139
143
|
/**
|
package/src/definers/studios.ts
CHANGED
|
@@ -39,7 +39,7 @@ export function defineStudio(config: BlueprintStudioConfig): BlueprintStudioReso
|
|
|
39
39
|
type: 'sanity.studio',
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
runValidation(() => validateStudio(studioResource))
|
|
42
|
+
runValidation(studioResource, () => validateStudio(studioResource))
|
|
43
43
|
|
|
44
44
|
return studioResource
|
|
45
45
|
}
|
package/src/definers/webhooks.ts
CHANGED
|
@@ -40,17 +40,14 @@ import {runValidation} from '../utils/validation.js'
|
|
|
40
40
|
* @returns The webhook resource
|
|
41
41
|
*/
|
|
42
42
|
export function defineDocumentWebhook(parameters: BlueprintDocumentWebhookConfig): BlueprintDocumentWebhookResource {
|
|
43
|
-
// default the display name
|
|
44
|
-
if (!parameters.displayName) {
|
|
45
|
-
parameters.displayName = parameters.name.substring(0, 100)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
43
|
const webhookResource: BlueprintDocumentWebhookResource = {
|
|
49
44
|
...parameters,
|
|
45
|
+
// default the display name
|
|
46
|
+
displayName: parameters.displayName || parameters.name.substring(0, 100),
|
|
50
47
|
type: 'sanity.project.webhook',
|
|
51
48
|
}
|
|
52
49
|
|
|
53
|
-
runValidation(() => validateDocumentWebhook(webhookResource))
|
|
50
|
+
runValidation(webhookResource, () => validateDocumentWebhook(webhookResource))
|
|
54
51
|
|
|
55
52
|
return webhookResource
|
|
56
53
|
}
|
|
@@ -346,7 +346,7 @@ export type BlueprintApplicationViewConfig =
|
|
|
346
346
|
* @category Resource Types
|
|
347
347
|
* @interface
|
|
348
348
|
*/
|
|
349
|
-
export type BlueprintApplicationConfig = Omit<BlueprintApplicationResource, 'type' | 'slug' | 'views'> & {
|
|
349
|
+
export type BlueprintApplicationConfig = Omit<BlueprintApplicationResource, 'type' | 'slug' | 'views' | 'mfManifest'> & {
|
|
350
350
|
/**
|
|
351
351
|
* The slug to be used in the application hostname. Must match `^[a-z0-9]([a-z0-9-]*[a-z0-9])?$`.
|
|
352
352
|
*
|
|
@@ -51,30 +51,56 @@ interface BlueprintCommonFunctionResource extends BlueprintResource {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* Configuration used for Queue
|
|
55
|
-
* @todo: not implemented
|
|
54
|
+
* Configuration used for Queue function types.
|
|
56
55
|
* @category Functions Types
|
|
57
56
|
* @alpha
|
|
58
57
|
* @hidden
|
|
59
58
|
*/
|
|
60
59
|
interface QueueConfig {
|
|
61
60
|
/**
|
|
62
|
-
*
|
|
63
|
-
* @
|
|
61
|
+
* How many messages run at once, and whether they run in order.
|
|
62
|
+
* @defaultValue `{limit: 2, fifo: false}`
|
|
64
63
|
*/
|
|
65
|
-
concurrency?:
|
|
64
|
+
concurrency?: ConcurrencyConfig
|
|
66
65
|
/**
|
|
67
66
|
* Debounce configuration, with any durations already resolved to seconds.
|
|
68
67
|
* Definers accept the wider {@link DebounceInput} and parse it into this shape.
|
|
69
68
|
*/
|
|
70
69
|
debounce?: DebounceConfig
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* How many messages a Queue function runs at once, and if they are processed in order.
|
|
74
|
+
*
|
|
75
|
+
* - `{limit: 1, fifo: true}` processes messages one at a time, in order.
|
|
76
|
+
* - `{limit: 5, fifo: true, key: 'event.data.documentId'}` keeps messages with the same key in order,
|
|
77
|
+
* while up to 5 keys run at once, so one busy key doesn't delay the others.
|
|
78
|
+
* - `{limit: 5}` processes up to 5 messages at once, with no order guarantees.
|
|
79
|
+
*
|
|
80
|
+
* A `limit` of 1 needs `fifo: true`, and `fifo` with a `limit` above 1 needs a `key`.
|
|
81
|
+
*
|
|
82
|
+
* Changing `fifo` on a deployed function replaces its queue, and messages still waiting in the old queue are lost.
|
|
83
|
+
* @category Functions Types
|
|
84
|
+
* @alpha
|
|
85
|
+
* @hidden
|
|
86
|
+
*/
|
|
87
|
+
export interface ConcurrencyConfig {
|
|
88
|
+
/**
|
|
89
|
+
* Maximum number of messages processed at once, from 1 to 1000.
|
|
90
|
+
* A limit of 1 needs `fifo: true`.
|
|
91
|
+
*/
|
|
92
|
+
limit: number
|
|
71
93
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* @
|
|
75
|
-
* @default `false`
|
|
94
|
+
* Process messages in order: one at a time with a `limit` of 1, or in order per `key` with a higher limit.
|
|
95
|
+
* Changing this on a deployed function replaces its queue, and messages still waiting in the old queue are lost.
|
|
96
|
+
* @defaultValue `false`
|
|
76
97
|
*/
|
|
77
98
|
fifo?: boolean
|
|
99
|
+
/**
|
|
100
|
+
* Dotted path into `{event, context}`, e.g. `event.data.documentId`; messages with the same value are processed in order.
|
|
101
|
+
* Required when `fifo` is `true` and `limit` is above 1.
|
|
102
|
+
*/
|
|
103
|
+
key?: string
|
|
78
104
|
}
|
|
79
105
|
|
|
80
106
|
/**
|
|
@@ -231,9 +257,9 @@ export interface BlueprintQueueFunctionResource extends BlueprintBaseFunctionRes
|
|
|
231
257
|
/** Optional Content Lake event source that triggers the function */
|
|
232
258
|
event?: BlueprintFunctionResourceContentLakeEvent
|
|
233
259
|
/**
|
|
234
|
-
* Total delivery attempts per message, at most
|
|
260
|
+
* Total delivery attempts per message, at most 100: `1` delivers once and never retries, `3` delivers once and retries twice.
|
|
235
261
|
* Messages that use up their attempts are moved to a Dead Letter Queue.
|
|
236
|
-
*
|
|
262
|
+
* @defaultValue `3`, applied by the functions service when omitted
|
|
237
263
|
*/
|
|
238
264
|
maxAttempts?: number
|
|
239
265
|
/**
|
|
@@ -92,4 +92,4 @@ export type BlueprintInstallationConfigResource = BlueprintMediaLibraryConfigRes
|
|
|
92
92
|
* @category Resource Types
|
|
93
93
|
* @interface
|
|
94
94
|
*/
|
|
95
|
-
export type BlueprintMediaLibraryConfigConfig = Omit<BlueprintMediaLibraryConfigResource, 'type' | 'appType'>
|
|
95
|
+
export type BlueprintMediaLibraryConfigConfig = Omit<BlueprintMediaLibraryConfigResource, 'type' | 'appType' | 'version' | 'mfManifest'>
|
package/src/types/robotTokens.ts
CHANGED
|
@@ -17,6 +17,17 @@ export interface RobotTokenMembership {
|
|
|
17
17
|
roleNames: string[]
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* A membership of a robot token, as passed to {@link defineRobotToken}.
|
|
22
|
+
* @category Resource Types
|
|
23
|
+
* @expand
|
|
24
|
+
* @interface
|
|
25
|
+
*/
|
|
26
|
+
export type RobotTokenMembershipConfig = RobotTokenMembership & {
|
|
27
|
+
/** The ID of the project that the membership belongs to. Sets `resourceType` to `project` and `resourceId` to the project. */
|
|
28
|
+
project?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
20
31
|
/**
|
|
21
32
|
* A robot token that provides automated access.
|
|
22
33
|
* @see https://www.sanity.io/docs/content-lake/http-auth#k4c21d7b829fe
|
|
@@ -38,10 +49,13 @@ export interface BlueprintRobotTokenResource extends BlueprintResource<Blueprint
|
|
|
38
49
|
* @category Resource Types
|
|
39
50
|
* @interface
|
|
40
51
|
*/
|
|
41
|
-
export type BlueprintRobotTokenConfig = Omit<BlueprintRobotTokenResource, 'type' | 'label' | '
|
|
52
|
+
export type BlueprintRobotTokenConfig = Omit<BlueprintRobotTokenResource, 'type' | 'label' | 'memberships'> & {
|
|
42
53
|
/**
|
|
43
54
|
* A descriptive label for the robot token and its use case
|
|
44
55
|
* @defaultValue The `name` of the resource
|
|
45
56
|
*/
|
|
46
57
|
label?: string
|
|
58
|
+
/** The ID of the project that the robot token belongs to. Sets `resourceType` to `project` and `resourceId` to the project. */
|
|
59
|
+
project?: string
|
|
60
|
+
memberships: RobotTokenMembershipConfig[]
|
|
47
61
|
}
|
package/src/types/roles.ts
CHANGED
|
@@ -15,10 +15,11 @@ export interface RolePermission {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* A custom role resource
|
|
19
19
|
* @category Resource Types
|
|
20
20
|
*/
|
|
21
|
-
export interface
|
|
21
|
+
export interface BlueprintRoleResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
|
|
22
|
+
type: 'sanity.access.role'
|
|
22
23
|
title: string
|
|
23
24
|
description?: string
|
|
24
25
|
appliesToUsers: boolean
|
|
@@ -27,11 +28,15 @@ export interface BlueprintRoleConfig extends Omit<BlueprintResource<BlueprintPro
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
|
-
*
|
|
31
|
+
* Configuration for a custom role.
|
|
31
32
|
* @category Resource Types
|
|
32
33
|
*/
|
|
33
|
-
export interface
|
|
34
|
-
|
|
34
|
+
export interface BlueprintRoleConfig extends Omit<BlueprintRoleResource, 'type'> {
|
|
35
|
+
/**
|
|
36
|
+
* The ID of the project that the role belongs to. Without it, the role is scoped to the stack.
|
|
37
|
+
* Sets `resourceType` to `project` and `resourceId` to the project.
|
|
38
|
+
*/
|
|
39
|
+
project?: string
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
/**
|
package/src/types/studios.ts
CHANGED
|
@@ -138,7 +138,11 @@ export interface BlueprintStudioResource extends BlueprintResource<BlueprintProj
|
|
|
138
138
|
* @category Resource Types
|
|
139
139
|
* @interface
|
|
140
140
|
*/
|
|
141
|
-
export interface BlueprintStudioConfig
|
|
141
|
+
export interface BlueprintStudioConfig
|
|
142
|
+
extends Omit<
|
|
143
|
+
BlueprintStudioResource,
|
|
144
|
+
'type' | 'slug' | 'title' | 'autoUpdates' | 'schemaInputs' | 'workspaces' | 'mfManifest' | 'version'
|
|
145
|
+
> {
|
|
142
146
|
/**
|
|
143
147
|
* The slug to be used in the studio hostname. Must match `^[a-z0-9]([a-z0-9-]*[a-z0-9])?$`.
|
|
144
148
|
*
|
package/src/utils/validation.ts
CHANGED
|
@@ -1,37 +1,44 @@
|
|
|
1
1
|
import type {BlueprintError} from '../types/errors.js'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const errorsByTarget = new WeakMap<object, BlueprintError[]>()
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Runs a validator and records its errors against `target`, which is the object a definer returns.
|
|
7
|
+
* `defineBlueprint` reports the errors of the resources in its `resources` list, so errors for a resource that never makes
|
|
8
|
+
* it into a blueprint are not reported, and errors don't carry over from one blueprint to the next.
|
|
9
|
+
* @param target The object the errors belong to, usually the resource a definer returns
|
|
10
|
+
* @param validator A function that returns a list of validation errors
|
|
9
11
|
* @internal
|
|
10
12
|
*/
|
|
11
|
-
export function runValidation(validator: () => BlueprintError[]
|
|
13
|
+
export function runValidation(target: unknown, validator: () => BlueprintError[]): void {
|
|
12
14
|
const errors = validator()
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (errors.length === 0) return
|
|
16
|
+
|
|
17
|
+
// there is nothing to attach the errors to, so report them right away
|
|
18
|
+
if (typeof target !== 'object' || target === null) throw new Error(formatErrors(errors))
|
|
19
|
+
|
|
20
|
+
errorsByTarget.set(target, [...(errorsByTarget.get(target) ?? []), ...errors])
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
/**
|
|
21
|
-
* Gets the
|
|
22
|
-
* @
|
|
24
|
+
* Gets the validation errors that were recorded against an object when a definer created it.
|
|
25
|
+
* @param target The object the errors belong to, usually a resource
|
|
26
|
+
* @returns The recorded errors, or an empty list
|
|
23
27
|
* @internal
|
|
24
28
|
*/
|
|
25
|
-
export function
|
|
26
|
-
return
|
|
29
|
+
export function getValidationErrors(target: unknown): BlueprintError[] {
|
|
30
|
+
if (typeof target !== 'object' || target === null) return []
|
|
31
|
+
return errorsByTarget.get(target) ?? []
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
/**
|
|
30
|
-
*
|
|
35
|
+
* Formats a list of validation errors as an error message, one error per line.
|
|
36
|
+
* @param errors The errors to format
|
|
37
|
+
* @returns The error message
|
|
31
38
|
* @internal
|
|
32
39
|
*/
|
|
33
|
-
export function
|
|
34
|
-
|
|
40
|
+
export function formatErrors(errors: BlueprintError[]): string {
|
|
41
|
+
return errors.map((err) => err.message).join('\n')
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
const REFERENCE_PREFIXES = ['$.resources.', '$.values.', '$.parameters.', '$.params.']
|