@sanity/blueprints 0.7.0 → 0.8.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 -0
- package/dist/definers/blueprints.d.ts +12 -0
- package/dist/definers/blueprints.js +12 -0
- package/dist/definers/blueprints.js.map +1 -1
- package/dist/definers/cors.d.ts +10 -0
- package/dist/definers/cors.js +10 -0
- package/dist/definers/cors.js.map +1 -1
- package/dist/definers/datasets.d.ts +9 -0
- package/dist/definers/datasets.js +9 -0
- package/dist/definers/datasets.js.map +1 -1
- package/dist/definers/functions.d.ts +62 -0
- package/dist/definers/functions.js +58 -3
- package/dist/definers/functions.js.map +1 -1
- package/dist/definers/resources.d.ts +5 -0
- package/dist/definers/resources.js +5 -0
- package/dist/definers/resources.js.map +1 -1
- package/dist/definers/robots.d.ts +18 -0
- package/dist/definers/robots.js +30 -0
- package/dist/definers/robots.js.map +1 -0
- package/dist/definers/roles.d.ts +36 -0
- package/dist/definers/roles.js +39 -0
- package/dist/definers/roles.js.map +1 -1
- package/dist/definers/webhooks.d.ts +13 -0
- package/dist/definers/webhooks.js +13 -0
- package/dist/definers/webhooks.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/types/blueprints.d.ts +5 -5
- package/dist/types/cors.d.ts +30 -4
- package/dist/types/datasets.d.ts +16 -4
- package/dist/types/functions.d.ts +29 -0
- package/dist/types/resources.d.ts +47 -1
- package/dist/types/robots.d.ts +30 -0
- package/dist/types/robots.js +2 -0
- package/dist/types/robots.js.map +1 -0
- package/dist/types/roles.d.ts +16 -2
- package/dist/types/webhooks.d.ts +4 -1
- package/dist/utils/validation.d.ts +4 -0
- package/dist/utils/validation.js +4 -0
- package/dist/utils/validation.js.map +1 -1
- package/dist/validation/blueprints.d.ts +5 -0
- package/dist/validation/blueprints.js +5 -0
- package/dist/validation/blueprints.js.map +1 -1
- package/dist/validation/cors.d.ts +6 -1
- package/dist/validation/cors.js +7 -1
- package/dist/validation/cors.js.map +1 -1
- package/dist/validation/datasets.d.ts +6 -1
- package/dist/validation/datasets.js +7 -1
- package/dist/validation/datasets.js.map +1 -1
- package/dist/validation/functions.d.ts +19 -1
- package/dist/validation/functions.js +39 -5
- package/dist/validation/functions.js.map +1 -1
- package/dist/validation/resources.d.ts +9 -1
- package/dist/validation/resources.js +55 -1
- package/dist/validation/resources.js.map +1 -1
- package/dist/validation/robots.d.ts +8 -0
- package/dist/validation/robots.js +97 -0
- package/dist/validation/robots.js.map +1 -0
- package/dist/validation/roles.d.ts +11 -6
- package/dist/validation/roles.js +30 -23
- package/dist/validation/roles.js.map +1 -1
- package/dist/validation/webhooks.d.ts +7 -2
- package/dist/validation/webhooks.js +35 -29
- package/dist/validation/webhooks.js.map +1 -1
- package/package.json +1 -1
- package/src/definers/blueprints.ts +12 -0
- package/src/definers/cors.ts +10 -0
- package/src/definers/datasets.ts +9 -0
- package/src/definers/functions.ts +80 -3
- package/src/definers/resources.ts +5 -0
- package/src/definers/robots.ts +33 -0
- package/src/definers/roles.ts +40 -0
- package/src/definers/webhooks.ts +13 -0
- package/src/index.ts +3 -0
- package/src/types/blueprints.ts +5 -5
- package/src/types/cors.ts +30 -4
- package/src/types/datasets.ts +16 -4
- package/src/types/functions.ts +29 -0
- package/src/types/resources.ts +54 -1
- package/src/types/robots.ts +35 -0
- package/src/types/roles.ts +19 -5
- package/src/types/webhooks.ts +6 -1
- package/src/utils/validation.ts +4 -0
- package/src/validation/blueprints.ts +5 -0
- package/src/validation/cors.ts +7 -2
- package/src/validation/datasets.ts +7 -2
- package/src/validation/functions.ts +45 -12
- package/src/validation/resources.ts +50 -1
- package/src/validation/robots.ts +96 -0
- package/src/validation/roles.ts +30 -24
- package/src/validation/webhooks.ts +35 -30
|
@@ -22,6 +22,28 @@ interface RequiredFunctionProperties {
|
|
|
22
22
|
name: string
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Defines a function that is triggered by document events in Sanity datasets.
|
|
27
|
+
* ```
|
|
28
|
+
* defineDocumentFunction({
|
|
29
|
+
* name: 'my-document-function',
|
|
30
|
+
* src: 'functions/my-function',
|
|
31
|
+
* memory: 3,
|
|
32
|
+
* timeout: 300,
|
|
33
|
+
* event: {
|
|
34
|
+
* on: ['create', 'update'],
|
|
35
|
+
* filter: "_type == 'some-type'",
|
|
36
|
+
* projection: "{title, _id, _type}",
|
|
37
|
+
* includeDrafts: false,
|
|
38
|
+
* },
|
|
39
|
+
* env: {
|
|
40
|
+
* MY_ENV_VAR: 'custom-value',
|
|
41
|
+
* },
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
* @param functionConfig The configuration for the document function
|
|
45
|
+
* @returns The validated document function resource
|
|
46
|
+
*/
|
|
25
47
|
export function defineDocumentFunction(
|
|
26
48
|
functionConfig: Partial<BlueprintDocumentFunctionResource> & RequiredFunctionProperties,
|
|
27
49
|
): BlueprintDocumentFunctionResource
|
|
@@ -34,7 +56,7 @@ export function defineDocumentFunction(
|
|
|
34
56
|
export function defineDocumentFunction(
|
|
35
57
|
functionConfig: Partial<BlueprintDocumentFunctionResource> & RequiredFunctionProperties & Partial<BlueprintDocumentFunctionResourceEvent>,
|
|
36
58
|
): BlueprintDocumentFunctionResource {
|
|
37
|
-
let {name, src, event, timeout, memory, env, type, ...maybeEvent} = functionConfig
|
|
59
|
+
let {name, src, event, timeout, memory, env, type, robotToken, ...maybeEvent} = functionConfig
|
|
38
60
|
if (!type) type = 'sanity.function.document'
|
|
39
61
|
|
|
40
62
|
// event validation and normalization
|
|
@@ -64,6 +86,7 @@ export function defineDocumentFunction(
|
|
|
64
86
|
timeout,
|
|
65
87
|
memory,
|
|
66
88
|
env,
|
|
89
|
+
robotToken,
|
|
67
90
|
},
|
|
68
91
|
{
|
|
69
92
|
skipValidation: true, // already done below
|
|
@@ -78,13 +101,36 @@ export function defineDocumentFunction(
|
|
|
78
101
|
return functionResource
|
|
79
102
|
}
|
|
80
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Defines a function that is triggered by media library events.
|
|
106
|
+
* ```
|
|
107
|
+
* defineMediaLibraryAssetFunction({
|
|
108
|
+
* name: 'my-media-library-function',
|
|
109
|
+
* src: 'functions/media-library-function',
|
|
110
|
+
* event: {
|
|
111
|
+
* on: ['create', 'update'],
|
|
112
|
+
* resource: {
|
|
113
|
+
* type: 'media-library',
|
|
114
|
+
* id: 'my-media-library-id',
|
|
115
|
+
* },
|
|
116
|
+
* filter: "type == 'my-type'",
|
|
117
|
+
* projection: "{_id}",
|
|
118
|
+
* },
|
|
119
|
+
* env: {
|
|
120
|
+
* MY_ENV_VAR: 'custom-value',
|
|
121
|
+
* },
|
|
122
|
+
* })
|
|
123
|
+
* ```
|
|
124
|
+
* @param functionConfig The configuration for the media library asset function
|
|
125
|
+
* @returns The validated media library asset function resource
|
|
126
|
+
*/
|
|
81
127
|
export function defineMediaLibraryAssetFunction(
|
|
82
128
|
functionConfig: Partial<BlueprintMediaLibraryAssetFunctionResource> &
|
|
83
129
|
RequiredFunctionProperties &
|
|
84
130
|
Pick<BlueprintMediaLibraryAssetFunctionResource, 'event'> &
|
|
85
131
|
Partial<BlueprintMediaLibraryFunctionResourceEvent>,
|
|
86
132
|
): BlueprintMediaLibraryAssetFunctionResource {
|
|
87
|
-
let {name, src, event, timeout, memory, env, type} = functionConfig
|
|
133
|
+
let {name, src, event, timeout, memory, env, type, robotToken} = functionConfig
|
|
88
134
|
if (!type) type = 'sanity.function.media-library.asset'
|
|
89
135
|
|
|
90
136
|
const functionResource: BlueprintMediaLibraryAssetFunctionResource = {
|
|
@@ -95,6 +141,7 @@ export function defineMediaLibraryAssetFunction(
|
|
|
95
141
|
timeout,
|
|
96
142
|
memory,
|
|
97
143
|
env,
|
|
144
|
+
robotToken,
|
|
98
145
|
},
|
|
99
146
|
{
|
|
100
147
|
skipValidation: true, // already done below
|
|
@@ -109,11 +156,28 @@ export function defineMediaLibraryAssetFunction(
|
|
|
109
156
|
return functionResource
|
|
110
157
|
}
|
|
111
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Defines a base function resource with common properties.
|
|
161
|
+
* ```
|
|
162
|
+
* defineFunction({
|
|
163
|
+
* name: 'my-function',
|
|
164
|
+
* src: 'functions/my-function',
|
|
165
|
+
* timeout: 300,
|
|
166
|
+
* memory: 1,
|
|
167
|
+
* env: {
|
|
168
|
+
* MY_ENV_VAR: 'my-custom-value'
|
|
169
|
+
* },
|
|
170
|
+
* })
|
|
171
|
+
* ```
|
|
172
|
+
* @param functionConfig The configuration for the function
|
|
173
|
+
* @param options Optional configuration including validation options
|
|
174
|
+
* @returns The validated function resource
|
|
175
|
+
*/
|
|
112
176
|
export function defineFunction(
|
|
113
177
|
functionConfig: Partial<BlueprintBaseFunctionResource> & RequiredFunctionProperties,
|
|
114
178
|
options?: {skipValidation?: boolean},
|
|
115
179
|
): BlueprintBaseFunctionResource {
|
|
116
|
-
let {name, src, timeout, memory, env, type} = functionConfig
|
|
180
|
+
let {name, src, timeout, memory, env, type, robotToken} = functionConfig
|
|
117
181
|
|
|
118
182
|
// defaults
|
|
119
183
|
if (!src) src = `functions/${name}`
|
|
@@ -126,6 +190,7 @@ export function defineFunction(
|
|
|
126
190
|
timeout,
|
|
127
191
|
memory,
|
|
128
192
|
env,
|
|
193
|
+
robotToken,
|
|
129
194
|
}
|
|
130
195
|
|
|
131
196
|
if (options?.skipValidation !== true) runValidation(() => validateFunction(functionResource))
|
|
@@ -133,6 +198,12 @@ export function defineFunction(
|
|
|
133
198
|
return functionResource
|
|
134
199
|
}
|
|
135
200
|
|
|
201
|
+
/**
|
|
202
|
+
* Builds a document function event configuration from partial event properties.
|
|
203
|
+
* Filters out non-event properties and applies defaults.
|
|
204
|
+
* @param event Partial document function event configuration
|
|
205
|
+
* @returns Complete document function event configuration
|
|
206
|
+
*/
|
|
136
207
|
function buildDocumentFunctionEvent(event: Partial<BlueprintDocumentFunctionResourceEvent>): BlueprintDocumentFunctionResourceEvent {
|
|
137
208
|
const cleanEvent = Object.fromEntries(
|
|
138
209
|
Object.entries(event).filter(([key]) => DOCUMENT_EVENT_KEYS.has(key as DocumentFunctionEventKey)),
|
|
@@ -144,6 +215,12 @@ function buildDocumentFunctionEvent(event: Partial<BlueprintDocumentFunctionReso
|
|
|
144
215
|
}
|
|
145
216
|
}
|
|
146
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Builds a media library function event configuration.
|
|
220
|
+
* Filters out non-event properties and applies defaults.
|
|
221
|
+
* @param event Media library function event configuration
|
|
222
|
+
* @returns Complete media library function event configuration
|
|
223
|
+
*/
|
|
147
224
|
function buildMediaLibraryFunctionEvent(event: BlueprintMediaLibraryFunctionResourceEvent): BlueprintMediaLibraryFunctionResourceEvent {
|
|
148
225
|
const cleanEvent = Object.fromEntries(
|
|
149
226
|
Object.entries(event).filter(([key]) => MEDIA_LIBRARY_EVENT_KEYS.has(key as MediaLibraryFunctionEventKey)),
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import {type BlueprintResource, assertResource} from '../index.js'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Defines a generic resource to be managed in Blueprints.
|
|
5
|
+
* This is useful if the resource type does not yet have a `define*` function.
|
|
6
|
+
* @param resourceConfig The resource configuration
|
|
7
|
+
*/
|
|
3
8
|
export function defineResource(resourceConfig: Partial<BlueprintResource>): BlueprintResource {
|
|
4
9
|
const resource = {
|
|
5
10
|
...resourceConfig,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {type BlueprintRobotConfig, type BlueprintRobotResource, validateRobot} from '../index.js'
|
|
2
|
+
import {runValidation} from '../utils/validation.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Defines a Robot token for automated access. Has a token property provided during deployment that can be referenced by other resources.
|
|
6
|
+
* ```
|
|
7
|
+
* defineRobot({
|
|
8
|
+
* name: 'my-robot',
|
|
9
|
+
* label: 'My Robot',
|
|
10
|
+
* memberships: [{
|
|
11
|
+
* resourceType: 'project',
|
|
12
|
+
* resourceId: projectId,
|
|
13
|
+
* roleNames: ['custom-robot-role'],
|
|
14
|
+
* }],
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param parameters The robot configuration
|
|
19
|
+
*/
|
|
20
|
+
export function defineRobot(parameters: BlueprintRobotConfig): BlueprintRobotResource {
|
|
21
|
+
// default robot label
|
|
22
|
+
const label = parameters.label || parameters.name
|
|
23
|
+
|
|
24
|
+
const robotResource: BlueprintRobotResource = {
|
|
25
|
+
...parameters,
|
|
26
|
+
label,
|
|
27
|
+
type: 'sanity.access.robot',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
runValidation(() => validateRobot(robotResource))
|
|
31
|
+
|
|
32
|
+
return robotResource
|
|
33
|
+
}
|
package/src/definers/roles.ts
CHANGED
|
@@ -9,6 +9,24 @@ import {runValidation} from '../utils/validation.js'
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Defines a role that is scoped to the same resource as the blueprint.
|
|
12
|
+
* ```
|
|
13
|
+
* defineRole({
|
|
14
|
+
* name: 'custom-robot-role',
|
|
15
|
+
* title: 'Custom Robot Role',
|
|
16
|
+
* appliesToRobots: true,
|
|
17
|
+
* appliesToUsers: false,
|
|
18
|
+
* permissions: [{
|
|
19
|
+
* name: 'sanity-project-cors',
|
|
20
|
+
* action: 'create'
|
|
21
|
+
* }, {
|
|
22
|
+
* name: 'sanity-project-cors',
|
|
23
|
+
* action: 'read'
|
|
24
|
+
* }, {
|
|
25
|
+
* name: 'sanity-project-cors',
|
|
26
|
+
* action: 'delete'
|
|
27
|
+
* }]
|
|
28
|
+
* }),
|
|
29
|
+
* ```
|
|
12
30
|
* @param parameters The configuration of the role
|
|
13
31
|
* @returns The role resource
|
|
14
32
|
*/
|
|
@@ -23,6 +41,10 @@ export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValid
|
|
|
23
41
|
permissions: parameters.permissions,
|
|
24
42
|
}
|
|
25
43
|
|
|
44
|
+
if (parameters.lifecycle) {
|
|
45
|
+
roleResource.lifecycle = parameters.lifecycle
|
|
46
|
+
}
|
|
47
|
+
|
|
26
48
|
if (options?.skipValidation !== true) runValidation(() => validateRole(roleResource))
|
|
27
49
|
|
|
28
50
|
return roleResource
|
|
@@ -30,6 +52,24 @@ export function defineRole(parameters: BlueprintRoleConfig, options?: {skipValid
|
|
|
30
52
|
|
|
31
53
|
/**
|
|
32
54
|
* Defines a role that is scoped to the specified project.
|
|
55
|
+
* ```
|
|
56
|
+
* defineProjectRole(projectId, {
|
|
57
|
+
* name: 'custom-robot-role',
|
|
58
|
+
* title: 'Custom Robot Role',
|
|
59
|
+
* appliesToRobots: true,
|
|
60
|
+
* appliesToUsers: false,
|
|
61
|
+
* permissions: [{
|
|
62
|
+
* name: 'sanity-project-cors',
|
|
63
|
+
* action: 'create'
|
|
64
|
+
* }, {
|
|
65
|
+
* name: 'sanity-project-cors',
|
|
66
|
+
* action: 'read'
|
|
67
|
+
* }, {
|
|
68
|
+
* name: 'sanity-project-cors',
|
|
69
|
+
* action: 'delete'
|
|
70
|
+
* }]
|
|
71
|
+
* }),
|
|
72
|
+
* ```
|
|
33
73
|
* @param projectId The ID of the project to which the role will be scoped
|
|
34
74
|
* @param parameters The configuration of the role
|
|
35
75
|
* @returns The role resource
|
package/src/definers/webhooks.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import {type BlueprintDocumentWebhookConfig, type BlueprintDocumentWebhookResource, validateDocumentWebhook} from '../index.js'
|
|
2
2
|
import {runValidation} from '../utils/validation.js'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Defines a webhook that is called when document changes occur.
|
|
6
|
+
* ```
|
|
7
|
+
* defineDocumentWebhook({
|
|
8
|
+
* name: 'my-webhook',
|
|
9
|
+
* on: ['create'],
|
|
10
|
+
* url: 'https://example.com/webhook',
|
|
11
|
+
* projection: '{_id}',
|
|
12
|
+
* dataset: 'staging'
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
* @param parameters The webhook configuration
|
|
16
|
+
*/
|
|
4
17
|
export function defineDocumentWebhook(parameters: BlueprintDocumentWebhookConfig): BlueprintDocumentWebhookResource {
|
|
5
18
|
// default the display name
|
|
6
19
|
if (!parameters.displayName) {
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './definers/cors.js'
|
|
|
4
4
|
export * from './definers/datasets.js'
|
|
5
5
|
export * from './definers/functions.js'
|
|
6
6
|
export * from './definers/resources.js'
|
|
7
|
+
export * from './definers/robots.js'
|
|
7
8
|
export * from './definers/roles.js'
|
|
8
9
|
export * from './definers/webhooks.js'
|
|
9
10
|
|
|
@@ -14,6 +15,7 @@ export * from './types/datasets.js'
|
|
|
14
15
|
export * from './types/errors.js'
|
|
15
16
|
export * from './types/functions.js'
|
|
16
17
|
export * from './types/resources.js'
|
|
18
|
+
export * from './types/robots.js'
|
|
17
19
|
export * from './types/roles.js'
|
|
18
20
|
export * from './types/webhooks.js'
|
|
19
21
|
|
|
@@ -23,5 +25,6 @@ export * from './validation/cors.js'
|
|
|
23
25
|
export * from './validation/datasets.js'
|
|
24
26
|
export * from './validation/functions.js'
|
|
25
27
|
export * from './validation/resources.js'
|
|
28
|
+
export * from './validation/robots.js'
|
|
26
29
|
export * from './validation/roles.js'
|
|
27
30
|
export * from './validation/webhooks.js'
|
package/src/types/blueprints.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import type {BlueprintResource} from '../index.js'
|
|
2
2
|
|
|
3
|
+
/** Additional configuration on a Blueprint that overrides the normal configuration */
|
|
3
4
|
export interface BlueprintsApiConfig {
|
|
4
5
|
organizationId: string
|
|
5
6
|
projectId: string
|
|
6
7
|
stackId: string
|
|
7
8
|
}
|
|
8
9
|
|
|
10
|
+
/** A key-value pair that will be output from a Blueprint */
|
|
9
11
|
export interface BlueprintOutput {
|
|
10
12
|
name: string
|
|
11
13
|
value: string
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
/** A representation of a Blueprint document */
|
|
14
17
|
export interface Blueprint {
|
|
15
18
|
$schema: string
|
|
16
19
|
blueprintVersion: string
|
|
@@ -19,8 +22,5 @@ export interface Blueprint {
|
|
|
19
22
|
outputs?: BlueprintOutput[]
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
projectId?: string
|
|
25
|
-
stackId?: string
|
|
26
|
-
}
|
|
25
|
+
/** The result of defining a blueprint with `defineBlueprint` */
|
|
26
|
+
export type BlueprintModule = ((args?: unknown) => Blueprint) & Partial<BlueprintsApiConfig>
|
package/src/types/cors.ts
CHANGED
|
@@ -1,18 +1,44 @@
|
|
|
1
|
-
import type {BlueprintResource} from '../index.js'
|
|
1
|
+
import type {BlueprintProjectResourceLifecycle, BlueprintResource} from '../index.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents a CORS Origin resource.
|
|
5
|
+
* @see https://www.sanity.io/docs/content-lake/cors
|
|
5
6
|
*/
|
|
6
|
-
export interface BlueprintCorsOriginResource extends BlueprintResource {
|
|
7
|
+
export interface BlueprintCorsOriginResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
|
|
7
8
|
type: 'sanity.project.cors'
|
|
9
|
+
/**
|
|
10
|
+
* A CORS origin will be defined using the following format: `protocol://hostname[:port]`
|
|
11
|
+
*
|
|
12
|
+
* The protocol and host name are required while the port is optional. Wildcards (*) are allowed.
|
|
13
|
+
*/
|
|
8
14
|
origin: string
|
|
15
|
+
/**
|
|
16
|
+
* When adding a CORS origin, you will also need to decide whether or not to allow credentials. If you allow credentials, the origin will be allowed to send authenticated requests using the token or session of a logged in user.
|
|
17
|
+
*
|
|
18
|
+
* If this origin hosts a studio, you will need to allow credentials. Otherwise, you should probably select not to allow credentials.
|
|
19
|
+
*
|
|
20
|
+
* 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.
|
|
21
|
+
*/
|
|
9
22
|
allowCredentials?: boolean
|
|
10
23
|
|
|
11
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* The project ID of the project that contains your CORS Origin.
|
|
26
|
+
*
|
|
27
|
+
* The `project` attribute must be defined if your blueprint is scoped to an organization. */
|
|
12
28
|
project?: string
|
|
13
29
|
}
|
|
14
30
|
|
|
15
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Configuration for a CORS Origin resource.
|
|
33
|
+
* @see https://www.sanity.io/docs/content-lake/cors
|
|
34
|
+
*/
|
|
16
35
|
export type BlueprintCorsOriginConfig = Omit<BlueprintCorsOriginResource, 'type' | 'allowCredentials'> & {
|
|
36
|
+
/**
|
|
37
|
+
* When adding a CORS origin, you will also need to decide whether or not to allow credentials. If you allow credentials, the origin will be allowed to send authenticated requests using the token or session of a logged in user.
|
|
38
|
+
*
|
|
39
|
+
* If this origin hosts a studio, you will need to allow credentials. Otherwise, you should probably select not to allow credentials.
|
|
40
|
+
*
|
|
41
|
+
* 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.
|
|
42
|
+
*/
|
|
17
43
|
allowCredentials?: boolean
|
|
18
44
|
}
|
package/src/types/datasets.ts
CHANGED
|
@@ -2,18 +2,30 @@ import type {BlueprintResource} from '../index.js'
|
|
|
2
2
|
|
|
3
3
|
export type AclMode = 'public' | 'private' | 'custom'
|
|
4
4
|
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Represents a Dataset resource.
|
|
7
|
+
* @see https://www.sanity.io/docs/content-lake/datasets
|
|
8
|
+
*/
|
|
6
9
|
export interface BlueprintDatasetResource extends BlueprintResource {
|
|
7
10
|
type: 'sanity.project.dataset'
|
|
11
|
+
/** The name of the dataset. Must be unique within a project. */
|
|
8
12
|
datasetName: string
|
|
13
|
+
/** The ACL mode to set for the new dataset. Defaults to public. */
|
|
9
14
|
aclMode?: AclMode
|
|
10
15
|
|
|
11
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The project ID of the project that contains your Dataset.
|
|
18
|
+
*
|
|
19
|
+
* The `project` attribute must be defined if your blueprint is scoped to an organization.
|
|
20
|
+
*/
|
|
12
21
|
project?: string
|
|
13
22
|
}
|
|
14
23
|
|
|
15
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for a Dataset resource.
|
|
26
|
+
* @see https://www.sanity.io/docs/content-lake/datasets
|
|
27
|
+
*/
|
|
16
28
|
export type BlueprintDatasetConfig = Omit<BlueprintDatasetResource, 'type' | 'datasetName'> & {
|
|
17
|
-
/** The name of the dataset
|
|
29
|
+
/** The name of the dataset. Must be unique within a project. Defaults to the name of the resource. */
|
|
18
30
|
datasetName?: string
|
|
19
31
|
}
|
package/src/types/functions.ts
CHANGED
|
@@ -2,47 +2,76 @@ import type {BlueprintResource} from '../index.js'
|
|
|
2
2
|
|
|
3
3
|
// --- Function Event Types ---
|
|
4
4
|
|
|
5
|
+
/** Base event configuration shared by document and media library function types */
|
|
5
6
|
export interface BlueprintFunctionBaseResourceEvent {
|
|
7
|
+
/** Event types that trigger the function. Defaults to ['publish'] */
|
|
6
8
|
on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]]
|
|
9
|
+
/** GROQ filter expression to match specific documents (e.g., "_type == 'post'") */
|
|
7
10
|
filter?: string
|
|
11
|
+
/** GROQ projection to specify which fields to include (e.g., "{_id, title, slug}") */
|
|
8
12
|
projection?: `{${string}}`
|
|
13
|
+
/** Include draft documents in addition to published documents */
|
|
9
14
|
includeDrafts?: boolean
|
|
10
15
|
}
|
|
16
|
+
/** Event configuration for document functions */
|
|
11
17
|
export interface BlueprintDocumentFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
|
|
18
|
+
/** Include all versions of documents, not just the current version */
|
|
12
19
|
includeAllVersions?: boolean
|
|
20
|
+
/** Optional dataset resource scoping for the function */
|
|
13
21
|
resource?: BlueprintFunctionResourceEventResourceDataset
|
|
14
22
|
}
|
|
23
|
+
/** Event configuration for media library asset functions */
|
|
15
24
|
export interface BlueprintMediaLibraryFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
|
|
25
|
+
/** Media library resource scoping (required for media library functions) */
|
|
16
26
|
resource: BlueprintFunctionResourceEventResourceMediaLibrary
|
|
17
27
|
}
|
|
28
|
+
/** Union type of all function resource event configurations */
|
|
18
29
|
export type BlueprintFunctionResourceEvent = BlueprintDocumentFunctionResourceEvent | BlueprintMediaLibraryFunctionResourceEvent
|
|
19
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Dataset resource for scoping document functions to specific datasets
|
|
33
|
+
* @example { type: 'dataset', id: 'my-project.production' }
|
|
34
|
+
*/
|
|
20
35
|
interface BlueprintFunctionResourceEventResourceDataset {
|
|
21
36
|
type: 'dataset'
|
|
22
37
|
/** @description A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
|
|
23
38
|
id: string
|
|
24
39
|
}
|
|
40
|
+
/** Media library resource for scoping media library functions */
|
|
25
41
|
interface BlueprintFunctionResourceEventResourceMediaLibrary {
|
|
26
42
|
type: 'media-library'
|
|
27
43
|
id: string
|
|
28
44
|
}
|
|
29
45
|
|
|
46
|
+
/** Events that can trigger a function */
|
|
30
47
|
type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update'
|
|
31
48
|
|
|
32
49
|
// --- Main Function Types ---
|
|
33
50
|
|
|
51
|
+
/** Base function resource with common properties for all function types */
|
|
34
52
|
export interface BlueprintBaseFunctionResource extends BlueprintResource {
|
|
53
|
+
/** Human-readable display name for the function */
|
|
35
54
|
displayName?: string
|
|
55
|
+
/** Path to the function source code */
|
|
36
56
|
src: string
|
|
57
|
+
/** Execution timeout in seconds */
|
|
37
58
|
timeout?: number
|
|
59
|
+
/** Memory allocation in gigabytes */
|
|
38
60
|
memory?: number
|
|
61
|
+
/** Environment variables provided to the function */
|
|
39
62
|
env?: Record<string, string>
|
|
63
|
+
/** Token provided during function invocation */
|
|
64
|
+
robotToken?: string
|
|
40
65
|
}
|
|
66
|
+
/** A function resource triggered by document events in Sanity datasets */
|
|
41
67
|
export interface BlueprintDocumentFunctionResource extends BlueprintBaseFunctionResource {
|
|
42
68
|
type: 'sanity.function.document'
|
|
69
|
+
/** Event configuration specifying when and how the function is triggered */
|
|
43
70
|
event: BlueprintDocumentFunctionResourceEvent
|
|
44
71
|
}
|
|
72
|
+
/** A function resource triggered by media library asset events */
|
|
45
73
|
export interface BlueprintMediaLibraryAssetFunctionResource extends BlueprintBaseFunctionResource {
|
|
46
74
|
type: 'sanity.function.media-library.asset'
|
|
75
|
+
/** Event configuration specifying when and how the function is triggered */
|
|
47
76
|
event: BlueprintMediaLibraryFunctionResourceEvent
|
|
48
77
|
}
|
package/src/types/resources.ts
CHANGED
|
@@ -1,7 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define deployment behaviour once the policy has been deployed. The following behaviours are allowed:
|
|
3
|
+
*
|
|
4
|
+
* - **retain** If a stack is destroyed, the resource is detached from the stack and will not be destroyed. If the resource is removed from the blueprint, deployment will fail.
|
|
5
|
+
* - **replace** if a stack is deployed, the resource will be destroyed and created instead of performing an update. If the resource is removed from the blueprint, it will be destroyed. If the stack is destroyed, the resource will be destroyed.
|
|
6
|
+
* - **allow** if a stack is destroyed, the resource will be destroyed along with it. If the resource is removed it will be destroyed
|
|
7
|
+
* - **protect** if a stack is deployed the resource will not be updated. If the resource is removed from the blueprint or the stack is destroyed, deployment will fail.
|
|
8
|
+
*/
|
|
9
|
+
export type BlueprintResourceDeletionPolicy = 'allow' | 'retain' | 'replace' | 'protect'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* An ownership action that will cause the referenced resource to be attached to the current stack.
|
|
13
|
+
*/
|
|
14
|
+
export interface BlueprintOwnershipAttachAction {
|
|
15
|
+
type: 'attach'
|
|
16
|
+
/** The identifier of the resource to be attached to the current stack */
|
|
17
|
+
id: string
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A union of all possible ownership actions.
|
|
21
|
+
*/
|
|
22
|
+
export type BlueprintOwnershipAction = BlueprintOwnershipAttachAction
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* An ownership action that will cause the referenced project-contained resource to be attached to the current stack.
|
|
26
|
+
*/
|
|
27
|
+
export interface BlueprintProjectOwnershipAttachAction extends BlueprintOwnershipAttachAction {
|
|
28
|
+
/** The identifier of the project for resources contained in a project */
|
|
29
|
+
projectId: string
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A union of all possible ownership actions for resources belonging to projects.
|
|
33
|
+
*/
|
|
34
|
+
export type BlueprintProjectOwnershipAction = BlueprintProjectOwnershipAttachAction
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Defines the lifcycle policy for this resource.
|
|
38
|
+
*/
|
|
39
|
+
export interface BlueprintResourceLifecycle {
|
|
40
|
+
deletionPolicy?: BlueprintResourceDeletionPolicy
|
|
41
|
+
|
|
42
|
+
ownershipAction?: BlueprintOwnershipAction
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Defines the lifcycle policy for this resource.
|
|
47
|
+
*/
|
|
48
|
+
export interface BlueprintProjectResourceLifecycle extends BlueprintResourceLifecycle {
|
|
49
|
+
ownershipAction?: BlueprintProjectOwnershipAction
|
|
50
|
+
}
|
|
51
|
+
|
|
1
52
|
/**
|
|
2
53
|
* The base type for all resources.
|
|
3
54
|
*/
|
|
4
|
-
export interface BlueprintResource {
|
|
55
|
+
export interface BlueprintResource<Lifecycle extends BlueprintResourceLifecycle = BlueprintResourceLifecycle> {
|
|
5
56
|
type: string
|
|
6
57
|
name: string
|
|
58
|
+
|
|
59
|
+
lifecycle?: Lifecycle
|
|
7
60
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type {BlueprintResource} from './resources'
|
|
2
|
+
|
|
3
|
+
/** Resource types that robots can be attached to. */
|
|
4
|
+
export type RobotResourceType = 'organization' | 'project'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Defines the robot's roles within a given resource.
|
|
8
|
+
*/
|
|
9
|
+
export interface RobotMembership {
|
|
10
|
+
resourceType: RobotResourceType
|
|
11
|
+
resourceId: string
|
|
12
|
+
roleNames: string[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A robot that provides a token for automated access.
|
|
17
|
+
* @see https://www.sanity.io/docs/content-lake/http-auth#k4c21d7b829fe
|
|
18
|
+
*/
|
|
19
|
+
export interface BlueprintRobotResource extends BlueprintResource {
|
|
20
|
+
type: 'sanity.access.robot'
|
|
21
|
+
/** A descriptive label for the robot and its use case */
|
|
22
|
+
label: string
|
|
23
|
+
memberships: RobotMembership[]
|
|
24
|
+
|
|
25
|
+
resourceType?: RobotResourceType
|
|
26
|
+
resourceId?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Configuration for a robot that provides a token for automated access.
|
|
31
|
+
* @see https://www.sanity.io/docs/content-lake/http-auth#k4c21d7b829fe
|
|
32
|
+
*/
|
|
33
|
+
export type BlueprintRobotConfig = Omit<BlueprintRobotResource, 'type' | 'label' | 'token'> & {
|
|
34
|
+
label?: string
|
|
35
|
+
}
|
package/src/types/roles.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import type {BlueprintResource} from '../index.js'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* A permission definition for a role.
|
|
5
|
+
*/
|
|
3
6
|
export interface RolePermission {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
/** Predefined permission name (e.g., 'sanity-all-documents') */
|
|
8
|
+
name: string
|
|
9
|
+
/** Permission action (e.g., 'read', 'mode') */
|
|
10
|
+
action: string
|
|
11
|
+
/** Additional parameters for the permission */
|
|
12
|
+
params?: Record<string, unknown>
|
|
7
13
|
}
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for a custom role.
|
|
17
|
+
*/
|
|
18
|
+
export interface BlueprintRoleConfig extends Omit<BlueprintResource, 'type'> {
|
|
11
19
|
title: string
|
|
12
20
|
description?: string
|
|
13
21
|
appliesToUsers: boolean
|
|
@@ -15,10 +23,16 @@ export interface BlueprintRoleConfig {
|
|
|
15
23
|
permissions: RolePermission[]
|
|
16
24
|
}
|
|
17
25
|
|
|
26
|
+
/**
|
|
27
|
+
* A custom role resource
|
|
28
|
+
*/
|
|
18
29
|
export interface BlueprintRoleResource extends BlueprintRoleConfig, BlueprintResource {
|
|
19
30
|
type: 'sanity.access.role'
|
|
20
31
|
}
|
|
21
32
|
|
|
33
|
+
/**
|
|
34
|
+
* A custom role resource that is tied to a specific project
|
|
35
|
+
*/
|
|
22
36
|
export interface BlueprintProjectRoleResource extends BlueprintRoleResource {
|
|
23
37
|
resourceType: 'project'
|
|
24
38
|
resourceId: string
|
package/src/types/webhooks.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type {BlueprintResource} from '../index.js'
|
|
2
2
|
|
|
3
|
+
/** Types of events that can trigger a webhook */
|
|
3
4
|
export type WebhookTrigger = 'create' | 'update' | 'delete'
|
|
5
|
+
|
|
6
|
+
/** A webhook resource definition */
|
|
4
7
|
export interface BlueprintDocumentWebhookResource extends BlueprintResource {
|
|
5
8
|
type: 'sanity.project.webhook'
|
|
6
9
|
project?: string
|
|
@@ -17,6 +20,8 @@ export interface BlueprintDocumentWebhookResource extends BlueprintResource {
|
|
|
17
20
|
includeAllVersions?: boolean
|
|
18
21
|
secret?: string
|
|
19
22
|
dataset?: string
|
|
20
|
-
apiVersion
|
|
23
|
+
apiVersion: string
|
|
21
24
|
}
|
|
25
|
+
|
|
26
|
+
/** Configuration for a webhook */
|
|
22
27
|
export type BlueprintDocumentWebhookConfig = Omit<BlueprintDocumentWebhookResource, 'type'>
|
package/src/utils/validation.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type {BlueprintError} from '../types/errors'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Executes the given validator function and throws a formatted error if any are returned.
|
|
5
|
+
* @param validator A function that returns a list of validation errors.
|
|
6
|
+
*/
|
|
3
7
|
export function runValidation(validator: () => BlueprintError[]) {
|
|
4
8
|
const errors = validator()
|
|
5
9
|
if (errors.length > 0) {
|