@sanity/blueprints 0.28.0 → 0.30.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 +18 -14
- package/dist/definers/functions/scheduled.d.ts +1 -3
- package/dist/definers/functions/scheduled.js +1 -3
- package/dist/definers/functions/scheduled.js.map +1 -1
- package/dist/definers/permissions.d.ts +71 -0
- package/dist/definers/permissions.js +95 -0
- package/dist/definers/permissions.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/types/applications.d.ts +3 -1
- package/dist/types/applications.js +1 -1
- package/dist/types/applications.js.map +1 -1
- package/dist/types/installation-config.d.ts +2 -0
- package/dist/types/permissions.d.ts +63 -0
- package/dist/types/permissions.js +2 -0
- package/dist/types/permissions.js.map +1 -0
- package/dist/types/roles.d.ts +1 -1
- package/dist/types/studios.d.ts +9 -1
- package/dist/types/studios.js.map +1 -1
- package/dist/validation/permissions.d.ts +15 -0
- package/dist/validation/permissions.js +95 -0
- package/dist/validation/permissions.js.map +1 -0
- package/dist/validation/resources.js +14 -4
- package/dist/validation/resources.js.map +1 -1
- package/package.json +10 -4
- package/src/definers/functions/scheduled.ts +1 -3
- package/src/definers/permissions.ts +107 -0
- package/src/index.ts +3 -0
- package/src/types/applications.ts +4 -1
- package/src/types/installation-config.ts +3 -0
- package/src/types/permissions.ts +67 -0
- package/src/types/roles.ts +1 -1
- package/src/types/studios.ts +11 -1
- package/src/validation/permissions.ts +100 -0
- package/src/validation/resources.ts +13 -4
package/README.md
CHANGED
|
@@ -53,11 +53,13 @@ export default defineBlueprint({
|
|
|
53
53
|
|
|
54
54
|
defineRobotToken({
|
|
55
55
|
name: 'ci-robot',
|
|
56
|
-
memberships: [
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
memberships: [
|
|
57
|
+
{
|
|
58
|
+
resourceType: 'project',
|
|
59
|
+
resourceId: 'your-project-id',
|
|
60
|
+
roleNames: ['developer'],
|
|
61
|
+
},
|
|
62
|
+
],
|
|
61
63
|
}),
|
|
62
64
|
],
|
|
63
65
|
})
|
|
@@ -65,15 +67,17 @@ export default defineBlueprint({
|
|
|
65
67
|
|
|
66
68
|
## Available resources
|
|
67
69
|
|
|
68
|
-
| Definer
|
|
69
|
-
|
|
70
|
-
| `defineBlueprint`
|
|
71
|
-
| `defineDocumentFunction`
|
|
72
|
-
| `defineMediaLibraryAssetFunction` | Function triggered by media library events
|
|
73
|
-
| `
|
|
74
|
-
| `
|
|
75
|
-
| `
|
|
76
|
-
| `
|
|
70
|
+
| Definer | Description |
|
|
71
|
+
| --------------------------------- | --------------------------------------------------------------------------- |
|
|
72
|
+
| `defineBlueprint` | Top-level blueprint module containing resources |
|
|
73
|
+
| `defineDocumentFunction` | Function triggered by document events |
|
|
74
|
+
| `defineMediaLibraryAssetFunction` | Function triggered by media library events |
|
|
75
|
+
| `defineContentResource` β | Content resource as in the Manage UI, made from document types and a filter |
|
|
76
|
+
| `defineCorsOrigin` β | CORS origin allowing browser requests to your project |
|
|
77
|
+
| `defineDocumentWebhook` β | Webhook triggered by document changes |
|
|
78
|
+
| `definePermission` β | Custom permission that roles can grant, in the Access API shape |
|
|
79
|
+
| `defineRole` β | Custom role with permissions |
|
|
80
|
+
| `defineRobotToken` β | Robot token for automated access |
|
|
77
81
|
|
|
78
82
|
Each definer validates its input at call time and returns a typed resource object. See the [reference docs](https://reference.sanity.io/_sanity/blueprints) for full configuration details and additional resource types.
|
|
79
83
|
|
|
@@ -30,12 +30,10 @@ import { type BlueprintScheduledFunctionConfig, type BlueprintScheduledFunctionR
|
|
|
30
30
|
* event: {expression: 'every day at 9am'},
|
|
31
31
|
* })
|
|
32
32
|
* ```
|
|
33
|
+
* @param functionConfig The configuration for the scheduled function
|
|
33
34
|
* @public
|
|
34
|
-
* @alpha Deploying Scheduled Functions via Blueprints is experimental. This feature is not available publicly yet.
|
|
35
|
-
* @hidden
|
|
36
35
|
* @category Definers
|
|
37
36
|
* @expandType BlueprintScheduledFunctionConfig
|
|
38
|
-
* @param functionConfig The configuration for the scheduled function
|
|
39
37
|
* @returns The validated scheduled function resource
|
|
40
38
|
*/
|
|
41
39
|
export declare function defineScheduledFunction(functionConfig: BlueprintScheduledFunctionConfig): BlueprintScheduledFunctionResource;
|
|
@@ -34,12 +34,10 @@ const SCHEDULED_EVENT_KEYS = new Set(['minute', 'hour', 'dayOfWeek', 'month', 'd
|
|
|
34
34
|
* event: {expression: 'every day at 9am'},
|
|
35
35
|
* })
|
|
36
36
|
* ```
|
|
37
|
+
* @param functionConfig The configuration for the scheduled function
|
|
37
38
|
* @public
|
|
38
|
-
* @alpha Deploying Scheduled Functions via Blueprints is experimental. This feature is not available publicly yet.
|
|
39
|
-
* @hidden
|
|
40
39
|
* @category Definers
|
|
41
40
|
* @expandType BlueprintScheduledFunctionConfig
|
|
42
|
-
* @param functionConfig The configuration for the scheduled function
|
|
43
41
|
* @returns The validated scheduled function resource
|
|
44
42
|
*/
|
|
45
43
|
export function defineScheduledFunction(functionConfig) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduled.js","sourceRoot":"","sources":["../../../src/definers/functions/scheduled.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,yBAAyB,GAC1B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,wBAAwB,EAAC,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AAKzC,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAA4B,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAA;AAErI
|
|
1
|
+
{"version":3,"file":"scheduled.js","sourceRoot":"","sources":["../../../src/definers/functions/scheduled.ts"],"names":[],"mappings":"AAAA,O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AAO,uBAAuB,CAAC,cAAc,CAAC,CAAA;AAChD,CAAC;AAED;;;;;GAKG;AACH,SAAS,2BAA2B,CAAC,KAA4C;IAC/E,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,oBAAoB,CAAC,GAAG,CAAC,GAAgC,CAAC,CAAC,CACzD,CAAA;AAC9C,CAAC;AAED;;;;GAIG;AACH,SAAS,yBAAyB,CAAC,IAAY;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACtC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,+CAA+C,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;IAChF,CAAC;IACD,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,GAAG,KAAK,CAAA;IAC1D,OAAO,EAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAC,CAAA;AACrD,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type BlueprintContentResourceConfig, type BlueprintPermissionConfig, type BlueprintPermissionResource } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Defines a custom permission that roles can grant, in the shape of the Access API.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* definePermission({
|
|
7
|
+
* name: 'articles-only',
|
|
8
|
+
* permissionType: 'sanity.document.filter.mode',
|
|
9
|
+
* config: {filter: '_type == "article"'},
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @example Grant the permission with a role
|
|
14
|
+
* ```ts
|
|
15
|
+
* definePermission({
|
|
16
|
+
* name: 'articles-only',
|
|
17
|
+
* title: 'Articles only',
|
|
18
|
+
* description: 'Access to article documents',
|
|
19
|
+
* permissionType: 'sanity.document.filter',
|
|
20
|
+
* config: {filter: '_type == "article"'},
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* defineRole({
|
|
24
|
+
* name: 'article-editor',
|
|
25
|
+
* title: 'Article editor',
|
|
26
|
+
* appliesToUsers: true,
|
|
27
|
+
* appliesToRobots: false,
|
|
28
|
+
* permissions: [
|
|
29
|
+
* {name: 'sanity-project', action: 'read'},
|
|
30
|
+
* {name: '$.resources.articles-only', action: 'read'},
|
|
31
|
+
* {name: '$.resources.articles-only', action: 'update'},
|
|
32
|
+
* ],
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
* @param parameters The configuration of the permission
|
|
36
|
+
* @public
|
|
37
|
+
* @beta Deploying Permissions via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
38
|
+
* @category Definers
|
|
39
|
+
* @expandType BlueprintPermissionConfig
|
|
40
|
+
* @returns The permission resource
|
|
41
|
+
*/
|
|
42
|
+
export declare function definePermission(parameters: BlueprintPermissionConfig): BlueprintPermissionResource;
|
|
43
|
+
/**
|
|
44
|
+
* Defines a content resource as the Manage UI makes it: a custom permission of type `sanity.document.filter.mode`.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* defineContentResource({
|
|
48
|
+
* name: 'movies',
|
|
49
|
+
* documentTypes: ['movie'],
|
|
50
|
+
* })
|
|
51
|
+
* // config.filter: '_type == "movie"'
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example Document types and a filter
|
|
55
|
+
* ```ts
|
|
56
|
+
* defineContentResource({
|
|
57
|
+
* name: 'london-posts',
|
|
58
|
+
* title: 'London posts',
|
|
59
|
+
* documentTypes: ['post', 'event'],
|
|
60
|
+
* filter: 'branch == "london"',
|
|
61
|
+
* })
|
|
62
|
+
* // config.filter: '_type in ["post", "event"] && (branch == "london")'
|
|
63
|
+
* ```
|
|
64
|
+
* @param parameters The configuration of the content resource
|
|
65
|
+
* @public
|
|
66
|
+
* @beta Deploying Permissions via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
67
|
+
* @category Definers
|
|
68
|
+
* @expandType BlueprintContentResourceConfig
|
|
69
|
+
* @returns The permission resource
|
|
70
|
+
*/
|
|
71
|
+
export declare function defineContentResource(parameters: BlueprintContentResourceConfig): BlueprintPermissionResource;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { validateContentResource, validatePermission, } from '../index.js';
|
|
2
|
+
import { runValidation } from '../utils/validation.js';
|
|
3
|
+
/**
|
|
4
|
+
* Defines a custom permission that roles can grant, in the shape of the Access API.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* definePermission({
|
|
8
|
+
* name: 'articles-only',
|
|
9
|
+
* permissionType: 'sanity.document.filter.mode',
|
|
10
|
+
* config: {filter: '_type == "article"'},
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @example Grant the permission with a role
|
|
15
|
+
* ```ts
|
|
16
|
+
* definePermission({
|
|
17
|
+
* name: 'articles-only',
|
|
18
|
+
* title: 'Articles only',
|
|
19
|
+
* description: 'Access to article documents',
|
|
20
|
+
* permissionType: 'sanity.document.filter',
|
|
21
|
+
* config: {filter: '_type == "article"'},
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* defineRole({
|
|
25
|
+
* name: 'article-editor',
|
|
26
|
+
* title: 'Article editor',
|
|
27
|
+
* appliesToUsers: true,
|
|
28
|
+
* appliesToRobots: false,
|
|
29
|
+
* permissions: [
|
|
30
|
+
* {name: 'sanity-project', action: 'read'},
|
|
31
|
+
* {name: '$.resources.articles-only', action: 'read'},
|
|
32
|
+
* {name: '$.resources.articles-only', action: 'update'},
|
|
33
|
+
* ],
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
* @param parameters The configuration of the permission
|
|
37
|
+
* @public
|
|
38
|
+
* @beta Deploying Permissions via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
39
|
+
* @category Definers
|
|
40
|
+
* @expandType BlueprintPermissionConfig
|
|
41
|
+
* @returns The permission resource
|
|
42
|
+
*/
|
|
43
|
+
export function definePermission(parameters) {
|
|
44
|
+
const permissionResource = {
|
|
45
|
+
...parameters,
|
|
46
|
+
type: 'sanity.access.permission',
|
|
47
|
+
};
|
|
48
|
+
runValidation(() => validatePermission(permissionResource));
|
|
49
|
+
return permissionResource;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Defines a content resource as the Manage UI makes it: a custom permission of type `sanity.document.filter.mode`.
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* defineContentResource({
|
|
56
|
+
* name: 'movies',
|
|
57
|
+
* documentTypes: ['movie'],
|
|
58
|
+
* })
|
|
59
|
+
* // config.filter: '_type == "movie"'
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example Document types and a filter
|
|
63
|
+
* ```ts
|
|
64
|
+
* defineContentResource({
|
|
65
|
+
* name: 'london-posts',
|
|
66
|
+
* title: 'London posts',
|
|
67
|
+
* documentTypes: ['post', 'event'],
|
|
68
|
+
* filter: 'branch == "london"',
|
|
69
|
+
* })
|
|
70
|
+
* // config.filter: '_type in ["post", "event"] && (branch == "london")'
|
|
71
|
+
* ```
|
|
72
|
+
* @param parameters The configuration of the content resource
|
|
73
|
+
* @public
|
|
74
|
+
* @beta Deploying Permissions via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
75
|
+
* @category Definers
|
|
76
|
+
* @expandType BlueprintContentResourceConfig
|
|
77
|
+
* @returns The permission resource
|
|
78
|
+
*/
|
|
79
|
+
export function defineContentResource(parameters) {
|
|
80
|
+
const { documentTypes, filter, ...permission } = parameters;
|
|
81
|
+
runValidation(() => validateContentResource(parameters));
|
|
82
|
+
return definePermission({
|
|
83
|
+
...permission,
|
|
84
|
+
permissionType: 'sanity.document.filter.mode',
|
|
85
|
+
config: { filter: contentResourceFilter(documentTypes, filter) },
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function contentResourceFilter(documentTypes, filter) {
|
|
89
|
+
const types = Array.isArray(documentTypes) ? documentTypes.map((type) => JSON.stringify(type)) : [];
|
|
90
|
+
const typeClause = types.length > 1 ? `_type in [${types.join(', ')}]` : types.length === 1 ? `_type == ${types[0]}` : '';
|
|
91
|
+
if (!typeClause)
|
|
92
|
+
return filter ?? '';
|
|
93
|
+
return filter ? `${typeClause} && (${filter})` : typeClause;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../src/definers/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAqC;IACpE,MAAM,kBAAkB,GAAgC;QACtD,GAAG,UAAU;QACb,IAAI,EAAE,0BAA0B;KACjC,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CAAC,CAAA;IAE3D,OAAO,kBAAkB,CAAA;AAC3B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,qBAAqB,CAAC,UAA0C;IAC9E,MAAM,EAAC,aAAa,EAAE,MAAM,EAAE,GAAG,UAAU,EAAC,GAAG,UAAU,CAAA;IAEzD,aAAa,CAAC,GAAG,EAAE,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC,CAAA;IAExD,OAAO,gBAAgB,CAAC;QACtB,GAAG,UAAU;QACb,cAAc,EAAE,6BAA6B;QAC7C,MAAM,EAAE,EAAC,MAAM,EAAE,qBAAqB,CAAC,aAAa,EAAE,MAAM,CAAC,EAAC;KAC/D,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,aAAsB,EAAE,MAAe;IACpE,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACnG,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAEzH,IAAI,CAAC,UAAU;QAAE,OAAO,MAAM,IAAI,EAAE,CAAA;IACpC,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,UAAU,QAAQ,MAAM,GAAG,CAAC,CAAC,CAAC,UAAU,CAAA;AAC7D,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export * from './definers/functions/queue.js';
|
|
|
19
19
|
export * from './definers/functions/scheduled.js';
|
|
20
20
|
export * from './definers/functions/sync-tag-invalidate.js';
|
|
21
21
|
export * from './definers/installation-config.js';
|
|
22
|
+
export * from './definers/permissions.js';
|
|
22
23
|
export * from './definers/projects.js';
|
|
23
24
|
export * from './definers/resources.js';
|
|
24
25
|
export * from './definers/robots.js';
|
|
@@ -41,6 +42,7 @@ export * from './types/datasets.js';
|
|
|
41
42
|
export * from './types/errors.js';
|
|
42
43
|
export * from './types/functions/index.js';
|
|
43
44
|
export * from './types/installation-config.js';
|
|
45
|
+
export * from './types/permissions.js';
|
|
44
46
|
export * from './types/projects.js';
|
|
45
47
|
export * from './types/resources.js';
|
|
46
48
|
export * from './types/robots.js';
|
|
@@ -58,6 +60,7 @@ export * from './validation/cors.js';
|
|
|
58
60
|
export * from './validation/datasets.js';
|
|
59
61
|
export * from './validation/functions.js';
|
|
60
62
|
export * from './validation/installation-config.js';
|
|
63
|
+
export * from './validation/permissions.js';
|
|
61
64
|
export * from './validation/projects.js';
|
|
62
65
|
export * from './validation/resources.js';
|
|
63
66
|
export * from './validation/robots.js';
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ export * from './definers/functions/queue.js';
|
|
|
20
20
|
export * from './definers/functions/scheduled.js';
|
|
21
21
|
export * from './definers/functions/sync-tag-invalidate.js';
|
|
22
22
|
export * from './definers/installation-config.js';
|
|
23
|
+
export * from './definers/permissions.js';
|
|
23
24
|
export * from './definers/projects.js';
|
|
24
25
|
export * from './definers/resources.js';
|
|
25
26
|
export * from './definers/robots.js';
|
|
@@ -43,6 +44,7 @@ export * from './types/datasets.js';
|
|
|
43
44
|
export * from './types/errors.js';
|
|
44
45
|
export * from './types/functions/index.js';
|
|
45
46
|
export * from './types/installation-config.js';
|
|
47
|
+
export * from './types/permissions.js';
|
|
46
48
|
export * from './types/projects.js';
|
|
47
49
|
export * from './types/resources.js';
|
|
48
50
|
export * from './types/robots.js';
|
|
@@ -61,6 +63,7 @@ export * from './validation/cors.js';
|
|
|
61
63
|
export * from './validation/datasets.js';
|
|
62
64
|
export * from './validation/functions.js';
|
|
63
65
|
export * from './validation/installation-config.js';
|
|
66
|
+
export * from './validation/permissions.js';
|
|
64
67
|
export * from './validation/projects.js';
|
|
65
68
|
export * from './validation/resources.js';
|
|
66
69
|
export * from './validation/robots.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD;;;GAGG;AACH;;;GAGG;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AAqB,CAAA;AAEnC,4CAA4C;AAC5C;;;GAGG;AACH,cAAc,8BAA8B,CAAA;AAC5C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,sBAAsB,CAAA;AACpC,cAAc,0BAA0B,CAAA;AACxC,cAAc,2BAA2B,CAAA;AACzC,cAAc,qCAAqC,CAAA;AACnD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,0BAA0B,CAAA;AACxC,cAAc,2BAA2B,CAAA;AACzC,cAAc,wBAAwB,CAAA;AACtC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,uBAAuB,CAAA;AACrC,cAAc,yBAAyB,CAAA;AACvC,cAAc,0BAA0B,CAAA;AAExC,yEAAyE;AACzE;;;GAGG"}
|
|
@@ -37,7 +37,7 @@ export type ApplicationViewSurface = (typeof APPLICATION_VIEW_SURFACES)[number];
|
|
|
37
37
|
* @category Resource Types
|
|
38
38
|
* @hidden
|
|
39
39
|
*/
|
|
40
|
-
export declare const APPLICATION_DOCK_GROUPS: readonly ['system', 'applications'
|
|
40
|
+
export declare const APPLICATION_DOCK_GROUPS: readonly ['system', 'applications'];
|
|
41
41
|
/**
|
|
42
42
|
* The dock group a window or panel view is placed into.
|
|
43
43
|
* @beta This feature is subject to breaking changes.
|
|
@@ -186,6 +186,8 @@ export interface BlueprintApplicationResource extends BlueprintResource {
|
|
|
186
186
|
views?: BlueprintApplicationView[];
|
|
187
187
|
/** The background web workers the application runs. */
|
|
188
188
|
webWorkers?: BlueprintWebWorker[];
|
|
189
|
+
/** Module federation manifest */
|
|
190
|
+
mfManifest?: Record<string, unknown>;
|
|
189
191
|
}
|
|
190
192
|
export interface BlueprintViewConfigBase {
|
|
191
193
|
type: 'view';
|
|
@@ -21,5 +21,5 @@ export const APPLICATION_VIEW_SURFACES = ['window', 'panel', 'asset-source', 'ti
|
|
|
21
21
|
* @category Resource Types
|
|
22
22
|
* @hidden
|
|
23
23
|
*/
|
|
24
|
-
export const APPLICATION_DOCK_GROUPS = ['system', 'applications'
|
|
24
|
+
export const APPLICATION_DOCK_GROUPS = ['system', 'applications'];
|
|
25
25
|
//# sourceMappingURL=applications.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applications.js","sourceRoot":"","sources":["../../src/types/applications.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAA;AAU3E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,CAAU,CAAA;AAW7F;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,QAAQ,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"applications.js","sourceRoot":"","sources":["../../src/types/applications.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAA;AAU3E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,CAAU,CAAA;AAW7F;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAU,CAAA"}
|
|
@@ -55,6 +55,8 @@ export interface BlueprintMediaLibraryConfigResource extends BlueprintInstallati
|
|
|
55
55
|
fields: BlueprintMediaLibraryField[];
|
|
56
56
|
/** The local version of `sanity` at deployment. Populated during deployment. */
|
|
57
57
|
version?: string;
|
|
58
|
+
/** Module federation manifest */
|
|
59
|
+
mfManifest?: Record<string, unknown>;
|
|
58
60
|
}
|
|
59
61
|
/**
|
|
60
62
|
* A union of every singleton installation config resource, discriminated by `appType`.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { BlueprintProjectResourceLifecycle, BlueprintResource } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The type of a custom permission.
|
|
4
|
+
*
|
|
5
|
+
* - **sanity.document.filter** A role grants document actions, such as `read` and `update`, on the documents that match the filter.
|
|
6
|
+
* - **sanity.document.filter.mode** A role grants the `mode` action, with a `mode` param such as `read` or `publish`, on the documents that match the filter.
|
|
7
|
+
* @beta This feature is subject to breaking changes.
|
|
8
|
+
* @category Resource Types
|
|
9
|
+
*/
|
|
10
|
+
export type BlueprintPermissionType = 'sanity.document.filter' | 'sanity.document.filter.mode';
|
|
11
|
+
/**
|
|
12
|
+
* A custom permission resource that roles can grant.
|
|
13
|
+
* @beta This feature is subject to breaking changes.
|
|
14
|
+
* @category Resource Types
|
|
15
|
+
*/
|
|
16
|
+
export interface BlueprintPermissionResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
|
|
17
|
+
type: 'sanity.access.permission';
|
|
18
|
+
/**
|
|
19
|
+
* The name of the permission.
|
|
20
|
+
*
|
|
21
|
+
* Lowercase letters, numbers, hyphens, and underscores only. Must not start with `sanity` or `res-`.
|
|
22
|
+
*/
|
|
23
|
+
name: string;
|
|
24
|
+
/** A human-readable title. Defaults to `name`. */
|
|
25
|
+
title?: string;
|
|
26
|
+
/** A description of the permission. Defaults to an empty string. */
|
|
27
|
+
description?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The type of the permission. It cannot change after the permission is created.
|
|
30
|
+
*
|
|
31
|
+
* Manage creates content resources as `sanity.document.filter.mode`, and lists only custom permissions of that type.
|
|
32
|
+
*/
|
|
33
|
+
permissionType: BlueprintPermissionType;
|
|
34
|
+
/** The configuration of the permission. */
|
|
35
|
+
config: {
|
|
36
|
+
/** A GROQ filter that selects the documents that the permission applies to, e.g. `_type == "article"`. */
|
|
37
|
+
filter: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The project ID of the project that contains the permission.
|
|
41
|
+
*
|
|
42
|
+
* The `project` attribute must be defined if your blueprint is scoped to an organization and the stack has no default project.
|
|
43
|
+
*/
|
|
44
|
+
project?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Configuration for a custom permission resource.
|
|
48
|
+
* @beta This feature is subject to breaking changes.
|
|
49
|
+
* @category Resource Types
|
|
50
|
+
* @interface
|
|
51
|
+
*/
|
|
52
|
+
export type BlueprintPermissionConfig = Omit<BlueprintPermissionResource, 'type'>;
|
|
53
|
+
/**
|
|
54
|
+
* Configuration for a content resource: a custom permission of type `sanity.document.filter.mode`, as the Manage UI makes it.
|
|
55
|
+
* @beta This feature is subject to breaking changes.
|
|
56
|
+
* @category Resource Types
|
|
57
|
+
*/
|
|
58
|
+
export interface BlueprintContentResourceConfig extends Omit<BlueprintPermissionConfig, 'permissionType' | 'config'> {
|
|
59
|
+
/** The document types that the content resource applies to. Omit to apply to documents of any type. */
|
|
60
|
+
documentTypes?: string[];
|
|
61
|
+
/** A GROQ filter that selects documents, e.g. `branch == "london"`. It is joined to `documentTypes` with `&&`. */
|
|
62
|
+
filter?: string;
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../src/types/permissions.ts"],"names":[],"mappings":""}
|
package/dist/types/roles.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { BlueprintProjectResourceLifecycle, BlueprintResource } from '../in
|
|
|
6
6
|
* @expand
|
|
7
7
|
*/
|
|
8
8
|
export interface RolePermission {
|
|
9
|
-
/** Predefined permission name (e.g., 'sanity-all-documents') */
|
|
9
|
+
/** Predefined permission name (e.g., 'sanity-all-documents'), or a reference to a permission in the blueprint (e.g., '$.resources.articles-only') */
|
|
10
10
|
name: string;
|
|
11
11
|
/** Permission action (e.g., 'read', 'mode') */
|
|
12
12
|
action: string;
|
package/dist/types/studios.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WorkspaceSchemaInput } from '@sanity/cli-build/_internal/manifest';
|
|
1
2
|
import type { ConfigEnv, InlineConfig } from 'vite';
|
|
2
3
|
import type { BlueprintProjectResourceLifecycle, BlueprintResource } from '../index.js';
|
|
3
4
|
/**
|
|
@@ -64,8 +65,15 @@ export interface BlueprintStudioResource extends BlueprintResource<BlueprintProj
|
|
|
64
65
|
reactCompiler?: boolean;
|
|
65
66
|
/** Whether or not to generate source maps. Defaults to false. */
|
|
66
67
|
sourceMap?: boolean;
|
|
67
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Custom Vite configuration for the Studio so it can be changed and extended.
|
|
70
|
+
* Install vite to dev dependencies to get detailed type information.
|
|
71
|
+
*/
|
|
68
72
|
vite?: UserViteConfig;
|
|
73
|
+
/** Schema inputs extracted from the studio's schema definition. */
|
|
74
|
+
schemaInputs?: WorkspaceSchemaInput[];
|
|
75
|
+
/** Module federation manifest */
|
|
76
|
+
mfManifest?: Record<string, unknown>;
|
|
69
77
|
}
|
|
70
78
|
/**
|
|
71
79
|
* Configuration for a Studio resource.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studios.js","sourceRoot":"","sources":["../../src/types/studios.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"studios.js","sourceRoot":"","sources":["../../src/types/studios.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,CAAU,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type BlueprintError } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates that the given resource is a valid Permission.
|
|
4
|
+
* @param resource The Permission resource
|
|
5
|
+
* @category Validation
|
|
6
|
+
* @returns A list of validation errors
|
|
7
|
+
*/
|
|
8
|
+
export declare function validatePermission(resource: unknown): BlueprintError[];
|
|
9
|
+
/**
|
|
10
|
+
* Validates the fields of a content resource that make its filter.
|
|
11
|
+
* @param resource The content resource configuration
|
|
12
|
+
* @category Validation
|
|
13
|
+
* @returns A list of validation errors
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateContentResource(resource: unknown): BlueprintError[];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { validateResource } from '../index.js';
|
|
2
|
+
const PERMISSION_TYPES = ['sanity.document.filter', 'sanity.document.filter.mode'];
|
|
3
|
+
const PERMISSION_NAME = /^(?!res-)(?!sanity)[a-z0-9-_]+$/;
|
|
4
|
+
/**
|
|
5
|
+
* Validates that the given resource is a valid Permission.
|
|
6
|
+
* @param resource The Permission resource
|
|
7
|
+
* @category Validation
|
|
8
|
+
* @returns A list of validation errors
|
|
9
|
+
*/
|
|
10
|
+
export function validatePermission(resource) {
|
|
11
|
+
if (!resource)
|
|
12
|
+
return [{ type: 'invalid_value', message: 'Permission config must be provided' }];
|
|
13
|
+
if (typeof resource !== 'object')
|
|
14
|
+
return [{ type: 'invalid_type', message: 'Permission config must be an object' }];
|
|
15
|
+
const errors = validateResource(resource, { projectContained: true });
|
|
16
|
+
if (!('name' in resource) || !resource.name) {
|
|
17
|
+
errors.push({ type: 'missing_parameter', message: 'Permission name is required' });
|
|
18
|
+
}
|
|
19
|
+
else if (typeof resource.name !== 'string') {
|
|
20
|
+
errors.push({ type: 'invalid_type', message: 'Permission name must be a string' });
|
|
21
|
+
}
|
|
22
|
+
else if (!PERMISSION_NAME.test(resource.name)) {
|
|
23
|
+
errors.push({
|
|
24
|
+
type: 'invalid_format',
|
|
25
|
+
message: 'Permission name must only contain lowercase letters, numbers, hyphens, and underscores, and must not start with "sanity" or "res-"',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (!('type' in resource)) {
|
|
29
|
+
errors.push({ type: 'missing_parameter', message: 'Permission type is required' });
|
|
30
|
+
}
|
|
31
|
+
else if (resource.type !== 'sanity.access.permission') {
|
|
32
|
+
errors.push({ type: 'invalid_value', message: 'Permission type must be `sanity.access.permission`' });
|
|
33
|
+
}
|
|
34
|
+
if ('title' in resource && resource.title !== undefined) {
|
|
35
|
+
if (typeof resource.title !== 'string') {
|
|
36
|
+
errors.push({ type: 'invalid_type', message: 'Permission title must be a string' });
|
|
37
|
+
}
|
|
38
|
+
else if (resource.title.length === 0) {
|
|
39
|
+
errors.push({ type: 'invalid_value', message: 'Permission title must not be empty' });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if ('description' in resource && resource.description !== undefined && typeof resource.description !== 'string') {
|
|
43
|
+
errors.push({ type: 'invalid_type', message: 'Permission description must be a string' });
|
|
44
|
+
}
|
|
45
|
+
if (!('permissionType' in resource) || !resource.permissionType) {
|
|
46
|
+
errors.push({ type: 'missing_parameter', message: 'Permission permissionType is required' });
|
|
47
|
+
}
|
|
48
|
+
else if (typeof resource.permissionType !== 'string' || !PERMISSION_TYPES.includes(resource.permissionType)) {
|
|
49
|
+
errors.push({ type: 'invalid_value', message: `Permission permissionType must be one of ${PERMISSION_TYPES.join(', ')}` });
|
|
50
|
+
}
|
|
51
|
+
if (!('config' in resource) || !resource.config) {
|
|
52
|
+
errors.push({ type: 'missing_parameter', message: 'Permission `config` is required' });
|
|
53
|
+
}
|
|
54
|
+
else if (typeof resource.config !== 'object') {
|
|
55
|
+
errors.push({ type: 'invalid_type', message: 'Permission `config` must be an object' });
|
|
56
|
+
}
|
|
57
|
+
else if (!('filter' in resource.config) || !resource.config.filter) {
|
|
58
|
+
errors.push({ type: 'missing_parameter', message: 'Permission filter is required' });
|
|
59
|
+
}
|
|
60
|
+
else if (typeof resource.config.filter !== 'string') {
|
|
61
|
+
errors.push({ type: 'invalid_type', message: 'Permission filter must be a string' });
|
|
62
|
+
}
|
|
63
|
+
if ('project' in resource && resource.project !== undefined) {
|
|
64
|
+
if (typeof resource.project !== 'string') {
|
|
65
|
+
errors.push({ type: 'invalid_type', message: 'Permission project must be a string' });
|
|
66
|
+
}
|
|
67
|
+
else if (resource.project.length === 0) {
|
|
68
|
+
errors.push({ type: 'invalid_value', message: 'Permission project must not be empty' });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return errors;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Validates the fields of a content resource that make its filter.
|
|
75
|
+
* @param resource The content resource configuration
|
|
76
|
+
* @category Validation
|
|
77
|
+
* @returns A list of validation errors
|
|
78
|
+
*/
|
|
79
|
+
export function validateContentResource(resource) {
|
|
80
|
+
if (!resource)
|
|
81
|
+
return [{ type: 'invalid_value', message: 'Content resource config must be provided' }];
|
|
82
|
+
if (typeof resource !== 'object')
|
|
83
|
+
return [{ type: 'invalid_type', message: 'Content resource config must be an object' }];
|
|
84
|
+
const errors = [];
|
|
85
|
+
if ('documentTypes' in resource &&
|
|
86
|
+
resource.documentTypes !== undefined &&
|
|
87
|
+
(!Array.isArray(resource.documentTypes) || !resource.documentTypes.every((type) => typeof type === 'string' && type.length > 0))) {
|
|
88
|
+
errors.push({ type: 'invalid_type', message: 'Content resource documentTypes must be an array of non-empty strings' });
|
|
89
|
+
}
|
|
90
|
+
if ('filter' in resource && resource.filter !== undefined && typeof resource.filter !== 'string') {
|
|
91
|
+
errors.push({ type: 'invalid_type', message: 'Content resource filter must be a string' });
|
|
92
|
+
}
|
|
93
|
+
return errors;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../src/validation/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,gBAAgB,EAAC,MAAM,aAAa,CAAA;AAEjE,MAAM,gBAAgB,GAAG,CAAC,wBAAwB,EAAE,6BAA6B,CAAC,CAAA;AAClF,MAAM,eAAe,GAAG,iCAAiC,CAAA;AAEzD;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAiB;IAClD,IAAI,CAAC,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,oCAAoC,EAAC,CAAC,CAAA;IAC9F,IAAI,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OAAO,EAAE,0CAA0C,EAAC,CAAC,CAAA;IACpG,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,2CAA2C,EAAC,CAAC,CAAA;IAEvH,MAAM,MAAM,GAAqB,EAAE,CAAA;IAEnC,IACE,eAAe,IAAI,QAAQ;QAC3B,QAAQ,CAAC,aAAa,KAAK,SAAS;QACpC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAChI,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,sEAAsE,EAAC,CAAC,CAAA;IACtH,CAAC;IAED,IAAI,QAAQ,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,IAAI,OAAO,QAAQ,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACjG,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,0CAA0C,EAAC,CAAC,CAAA;IAC1F,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -86,11 +86,21 @@ export function validateResource(resource, options) {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
if ('dependsOn' in resource.lifecycle) {
|
|
89
|
-
if (
|
|
90
|
-
|
|
89
|
+
if (Array.isArray(resource.lifecycle.dependsOn)) {
|
|
90
|
+
if (!resource.lifecycle.dependsOn.every((dep) => dep.startsWith('$.resources.'))) {
|
|
91
|
+
errors.push({
|
|
92
|
+
type: 'invalid_value',
|
|
93
|
+
message: '`lifecycle.dependsOn` elements must be resource references starting with `$.resources.`',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (typeof resource.lifecycle.dependsOn === 'string') {
|
|
98
|
+
if (!resource.lifecycle.dependsOn.startsWith('$.resources.')) {
|
|
99
|
+
errors.push({ type: 'invalid_value', message: '`lifecycle.dependsOn` must be a resource reference starting with `$.resources.`' });
|
|
100
|
+
}
|
|
91
101
|
}
|
|
92
|
-
else
|
|
93
|
-
errors.push({ type: '
|
|
102
|
+
else {
|
|
103
|
+
errors.push({ type: 'invalid_type', message: '`lifecycle.dependsOn` must be a string or an array' });
|
|
94
104
|
}
|
|
95
105
|
}
|
|
96
106
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/validation/resources.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAEpD;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAiB,EAAE,OAAsC;IACxF,IAAI,CAAC,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,kCAAkC,EAAC,CAAC,CAAA;IAC5F,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,mCAAmC,EAAC,CAAC,CAAA;IAE/G,MAAM,MAAM,GAAqB,EAAE,CAAA;IAEnC,IAAI,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,EAAE,CAAC;QAC1B,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,oBAAoB,EAAC,CAAC,CAAA;IACzE,CAAC;SAAM,IAAI,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7C,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,yBAAyB,EAAC,CAAC,CAAA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AAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC;wBACjF,MAAM,CAAC,IAAI,CAAC;4BACV,IAAI,EAAE,eAAe;4BACrB,OAAO,EAAE,yFAAyF;yBACnG,CAAC,CAAA;oBACJ,CAAC;gBACH,CAAC;qBAAM,IAAI,OAAO,QAAQ,CAAC,SAAS,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;oBAC5D,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;wBAC7D,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,iFAAiF,EAAC,CAAC,CAAA;oBAClI,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,oDAAoD,EAAC,CAAC,CAAA;gBACpG,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,QAAiB;IAC9C,aAAa,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAA;AACjD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/blueprints",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "Helper methods and type definitions for Sanity Blueprints",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -55,17 +55,23 @@
|
|
|
55
55
|
"typecheck": "tsc --noEmit --project tsconfig.test.json"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@biomejs/biome": "2.
|
|
58
|
+
"@biomejs/biome": "2.6.2",
|
|
59
|
+
"@sanity/cli-build": "^7.0.0",
|
|
59
60
|
"@types/node": "^22",
|
|
60
|
-
"@vitest/coverage-v8": "^5.0.
|
|
61
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
61
62
|
"typescript": "^7.0.2",
|
|
62
|
-
"
|
|
63
|
+
"vite": "^8.3.5",
|
|
64
|
+
"vitest": "^5.0.5"
|
|
63
65
|
},
|
|
64
66
|
"peerDependencies": {
|
|
67
|
+
"@sanity/cli-build": ">= 6",
|
|
65
68
|
"vite": ">= 8",
|
|
66
69
|
"jiti": "^2"
|
|
67
70
|
},
|
|
68
71
|
"peerDependenciesMeta": {
|
|
72
|
+
"@sanity/cli-build": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
69
75
|
"vite": {
|
|
70
76
|
"optional": true
|
|
71
77
|
},
|
|
@@ -47,12 +47,10 @@ const SCHEDULED_EVENT_KEYS = new Set<ScheduledFunctionEventKey>(['minute', 'hour
|
|
|
47
47
|
* event: {expression: 'every day at 9am'},
|
|
48
48
|
* })
|
|
49
49
|
* ```
|
|
50
|
+
* @param functionConfig The configuration for the scheduled function
|
|
50
51
|
* @public
|
|
51
|
-
* @alpha Deploying Scheduled Functions via Blueprints is experimental. This feature is not available publicly yet.
|
|
52
|
-
* @hidden
|
|
53
52
|
* @category Definers
|
|
54
53
|
* @expandType BlueprintScheduledFunctionConfig
|
|
55
|
-
* @param functionConfig The configuration for the scheduled function
|
|
56
54
|
* @returns The validated scheduled function resource
|
|
57
55
|
*/
|
|
58
56
|
export function defineScheduledFunction(functionConfig: BlueprintScheduledFunctionConfig): BlueprintScheduledFunctionResource {
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BlueprintContentResourceConfig,
|
|
3
|
+
type BlueprintPermissionConfig,
|
|
4
|
+
type BlueprintPermissionResource,
|
|
5
|
+
validateContentResource,
|
|
6
|
+
validatePermission,
|
|
7
|
+
} from '../index.js'
|
|
8
|
+
import {runValidation} from '../utils/validation.js'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Defines a custom permission that roles can grant, in the shape of the Access API.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* definePermission({
|
|
15
|
+
* name: 'articles-only',
|
|
16
|
+
* permissionType: 'sanity.document.filter.mode',
|
|
17
|
+
* config: {filter: '_type == "article"'},
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @example Grant the permission with a role
|
|
22
|
+
* ```ts
|
|
23
|
+
* definePermission({
|
|
24
|
+
* name: 'articles-only',
|
|
25
|
+
* title: 'Articles only',
|
|
26
|
+
* description: 'Access to article documents',
|
|
27
|
+
* permissionType: 'sanity.document.filter',
|
|
28
|
+
* config: {filter: '_type == "article"'},
|
|
29
|
+
* })
|
|
30
|
+
*
|
|
31
|
+
* defineRole({
|
|
32
|
+
* name: 'article-editor',
|
|
33
|
+
* title: 'Article editor',
|
|
34
|
+
* appliesToUsers: true,
|
|
35
|
+
* appliesToRobots: false,
|
|
36
|
+
* permissions: [
|
|
37
|
+
* {name: 'sanity-project', action: 'read'},
|
|
38
|
+
* {name: '$.resources.articles-only', action: 'read'},
|
|
39
|
+
* {name: '$.resources.articles-only', action: 'update'},
|
|
40
|
+
* ],
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
* @param parameters The configuration of the permission
|
|
44
|
+
* @public
|
|
45
|
+
* @beta Deploying Permissions via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
46
|
+
* @category Definers
|
|
47
|
+
* @expandType BlueprintPermissionConfig
|
|
48
|
+
* @returns The permission resource
|
|
49
|
+
*/
|
|
50
|
+
export function definePermission(parameters: BlueprintPermissionConfig): BlueprintPermissionResource {
|
|
51
|
+
const permissionResource: BlueprintPermissionResource = {
|
|
52
|
+
...parameters,
|
|
53
|
+
type: 'sanity.access.permission',
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
runValidation(() => validatePermission(permissionResource))
|
|
57
|
+
|
|
58
|
+
return permissionResource
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Defines a content resource as the Manage UI makes it: a custom permission of type `sanity.document.filter.mode`.
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* defineContentResource({
|
|
66
|
+
* name: 'movies',
|
|
67
|
+
* documentTypes: ['movie'],
|
|
68
|
+
* })
|
|
69
|
+
* // config.filter: '_type == "movie"'
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example Document types and a filter
|
|
73
|
+
* ```ts
|
|
74
|
+
* defineContentResource({
|
|
75
|
+
* name: 'london-posts',
|
|
76
|
+
* title: 'London posts',
|
|
77
|
+
* documentTypes: ['post', 'event'],
|
|
78
|
+
* filter: 'branch == "london"',
|
|
79
|
+
* })
|
|
80
|
+
* // config.filter: '_type in ["post", "event"] && (branch == "london")'
|
|
81
|
+
* ```
|
|
82
|
+
* @param parameters The configuration of the content resource
|
|
83
|
+
* @public
|
|
84
|
+
* @beta Deploying Permissions via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
85
|
+
* @category Definers
|
|
86
|
+
* @expandType BlueprintContentResourceConfig
|
|
87
|
+
* @returns The permission resource
|
|
88
|
+
*/
|
|
89
|
+
export function defineContentResource(parameters: BlueprintContentResourceConfig): BlueprintPermissionResource {
|
|
90
|
+
const {documentTypes, filter, ...permission} = parameters
|
|
91
|
+
|
|
92
|
+
runValidation(() => validateContentResource(parameters))
|
|
93
|
+
|
|
94
|
+
return definePermission({
|
|
95
|
+
...permission,
|
|
96
|
+
permissionType: 'sanity.document.filter.mode',
|
|
97
|
+
config: {filter: contentResourceFilter(documentTypes, filter)},
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function contentResourceFilter(documentTypes: unknown, filter?: string): string {
|
|
102
|
+
const types = Array.isArray(documentTypes) ? documentTypes.map((type) => JSON.stringify(type)) : []
|
|
103
|
+
const typeClause = types.length > 1 ? `_type in [${types.join(', ')}]` : types.length === 1 ? `_type == ${types[0]}` : ''
|
|
104
|
+
|
|
105
|
+
if (!typeClause) return filter ?? ''
|
|
106
|
+
return filter ? `${typeClause} && (${filter})` : typeClause
|
|
107
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ export * from './definers/functions/queue.js'
|
|
|
20
20
|
export * from './definers/functions/scheduled.js'
|
|
21
21
|
export * from './definers/functions/sync-tag-invalidate.js'
|
|
22
22
|
export * from './definers/installation-config.js'
|
|
23
|
+
export * from './definers/permissions.js'
|
|
23
24
|
export * from './definers/projects.js'
|
|
24
25
|
export * from './definers/resources.js'
|
|
25
26
|
export * from './definers/robots.js'
|
|
@@ -44,6 +45,7 @@ export * from './types/datasets.js'
|
|
|
44
45
|
export * from './types/errors.js'
|
|
45
46
|
export * from './types/functions/index.js'
|
|
46
47
|
export * from './types/installation-config.js'
|
|
48
|
+
export * from './types/permissions.js'
|
|
47
49
|
export * from './types/projects.js'
|
|
48
50
|
export * from './types/resources.js'
|
|
49
51
|
export * from './types/robots.js'
|
|
@@ -63,6 +65,7 @@ export * from './validation/cors.js'
|
|
|
63
65
|
export * from './validation/datasets.js'
|
|
64
66
|
export * from './validation/functions.js'
|
|
65
67
|
export * from './validation/installation-config.js'
|
|
68
|
+
export * from './validation/permissions.js'
|
|
66
69
|
export * from './validation/projects.js'
|
|
67
70
|
export * from './validation/resources.js'
|
|
68
71
|
export * from './validation/robots.js'
|
|
@@ -42,7 +42,7 @@ export type ApplicationViewSurface = (typeof APPLICATION_VIEW_SURFACES)[number]
|
|
|
42
42
|
* @category Resource Types
|
|
43
43
|
* @hidden
|
|
44
44
|
*/
|
|
45
|
-
export const APPLICATION_DOCK_GROUPS = ['system', 'applications'
|
|
45
|
+
export const APPLICATION_DOCK_GROUPS = ['system', 'applications'] as const
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* The dock group a window or panel view is placed into.
|
|
@@ -216,6 +216,9 @@ export interface BlueprintApplicationResource extends BlueprintResource {
|
|
|
216
216
|
|
|
217
217
|
/** The background web workers the application runs. */
|
|
218
218
|
webWorkers?: BlueprintWebWorker[]
|
|
219
|
+
|
|
220
|
+
/** Module federation manifest */
|
|
221
|
+
mfManifest?: Record<string, unknown>
|
|
219
222
|
}
|
|
220
223
|
|
|
221
224
|
export interface BlueprintViewConfigBase {
|
|
@@ -65,6 +65,9 @@ export interface BlueprintMediaLibraryConfigResource extends BlueprintInstallati
|
|
|
65
65
|
|
|
66
66
|
/** The local version of `sanity` at deployment. Populated during deployment. */
|
|
67
67
|
version?: string
|
|
68
|
+
|
|
69
|
+
/** Module federation manifest */
|
|
70
|
+
mfManifest?: Record<string, unknown>
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
/**
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type {BlueprintProjectResourceLifecycle, BlueprintResource} from '../index.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The type of a custom permission.
|
|
5
|
+
*
|
|
6
|
+
* - **sanity.document.filter** A role grants document actions, such as `read` and `update`, on the documents that match the filter.
|
|
7
|
+
* - **sanity.document.filter.mode** A role grants the `mode` action, with a `mode` param such as `read` or `publish`, on the documents that match the filter.
|
|
8
|
+
* @beta This feature is subject to breaking changes.
|
|
9
|
+
* @category Resource Types
|
|
10
|
+
*/
|
|
11
|
+
export type BlueprintPermissionType = 'sanity.document.filter' | 'sanity.document.filter.mode'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A custom permission resource that roles can grant.
|
|
15
|
+
* @beta This feature is subject to breaking changes.
|
|
16
|
+
* @category Resource Types
|
|
17
|
+
*/
|
|
18
|
+
export interface BlueprintPermissionResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
|
|
19
|
+
type: 'sanity.access.permission'
|
|
20
|
+
/**
|
|
21
|
+
* The name of the permission.
|
|
22
|
+
*
|
|
23
|
+
* Lowercase letters, numbers, hyphens, and underscores only. Must not start with `sanity` or `res-`.
|
|
24
|
+
*/
|
|
25
|
+
name: string
|
|
26
|
+
/** A human-readable title. Defaults to `name`. */
|
|
27
|
+
title?: string
|
|
28
|
+
/** A description of the permission. Defaults to an empty string. */
|
|
29
|
+
description?: string
|
|
30
|
+
/**
|
|
31
|
+
* The type of the permission. It cannot change after the permission is created.
|
|
32
|
+
*
|
|
33
|
+
* Manage creates content resources as `sanity.document.filter.mode`, and lists only custom permissions of that type.
|
|
34
|
+
*/
|
|
35
|
+
permissionType: BlueprintPermissionType
|
|
36
|
+
/** The configuration of the permission. */
|
|
37
|
+
config: {
|
|
38
|
+
/** A GROQ filter that selects the documents that the permission applies to, e.g. `_type == "article"`. */
|
|
39
|
+
filter: string
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The project ID of the project that contains the permission.
|
|
43
|
+
*
|
|
44
|
+
* The `project` attribute must be defined if your blueprint is scoped to an organization and the stack has no default project.
|
|
45
|
+
*/
|
|
46
|
+
project?: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Configuration for a custom permission resource.
|
|
51
|
+
* @beta This feature is subject to breaking changes.
|
|
52
|
+
* @category Resource Types
|
|
53
|
+
* @interface
|
|
54
|
+
*/
|
|
55
|
+
export type BlueprintPermissionConfig = Omit<BlueprintPermissionResource, 'type'>
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Configuration for a content resource: a custom permission of type `sanity.document.filter.mode`, as the Manage UI makes it.
|
|
59
|
+
* @beta This feature is subject to breaking changes.
|
|
60
|
+
* @category Resource Types
|
|
61
|
+
*/
|
|
62
|
+
export interface BlueprintContentResourceConfig extends Omit<BlueprintPermissionConfig, 'permissionType' | 'config'> {
|
|
63
|
+
/** The document types that the content resource applies to. Omit to apply to documents of any type. */
|
|
64
|
+
documentTypes?: string[]
|
|
65
|
+
/** A GROQ filter that selects documents, e.g. `branch == "london"`. It is joined to `documentTypes` with `&&`. */
|
|
66
|
+
filter?: string
|
|
67
|
+
}
|
package/src/types/roles.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type {BlueprintProjectResourceLifecycle, BlueprintResource} from '../inde
|
|
|
7
7
|
* @expand
|
|
8
8
|
*/
|
|
9
9
|
export interface RolePermission {
|
|
10
|
-
/** Predefined permission name (e.g., 'sanity-all-documents') */
|
|
10
|
+
/** Predefined permission name (e.g., 'sanity-all-documents'), or a reference to a permission in the blueprint (e.g., '$.resources.articles-only') */
|
|
11
11
|
name: string
|
|
12
12
|
/** Permission action (e.g., 'read', 'mode') */
|
|
13
13
|
action: string
|
package/src/types/studios.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type {WorkspaceSchemaInput} from '@sanity/cli-build/_internal/manifest'
|
|
1
2
|
import type {ConfigEnv, InlineConfig} from 'vite'
|
|
2
3
|
import type {BlueprintProjectResourceLifecycle, BlueprintResource} from '../index.js'
|
|
3
4
|
|
|
@@ -81,8 +82,17 @@ export interface BlueprintStudioResource extends BlueprintResource<BlueprintProj
|
|
|
81
82
|
/** Whether or not to generate source maps. Defaults to false. */
|
|
82
83
|
sourceMap?: boolean
|
|
83
84
|
|
|
84
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Custom Vite configuration for the Studio so it can be changed and extended.
|
|
87
|
+
* Install vite to dev dependencies to get detailed type information.
|
|
88
|
+
*/
|
|
85
89
|
vite?: UserViteConfig
|
|
90
|
+
|
|
91
|
+
/** Schema inputs extracted from the studio's schema definition. */
|
|
92
|
+
schemaInputs?: WorkspaceSchemaInput[]
|
|
93
|
+
|
|
94
|
+
/** Module federation manifest */
|
|
95
|
+
mfManifest?: Record<string, unknown>
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
/**
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {type BlueprintError, validateResource} from '../index.js'
|
|
2
|
+
|
|
3
|
+
const PERMISSION_TYPES = ['sanity.document.filter', 'sanity.document.filter.mode']
|
|
4
|
+
const PERMISSION_NAME = /^(?!res-)(?!sanity)[a-z0-9-_]+$/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Validates that the given resource is a valid Permission.
|
|
8
|
+
* @param resource The Permission resource
|
|
9
|
+
* @category Validation
|
|
10
|
+
* @returns A list of validation errors
|
|
11
|
+
*/
|
|
12
|
+
export function validatePermission(resource: unknown): BlueprintError[] {
|
|
13
|
+
if (!resource) return [{type: 'invalid_value', message: 'Permission config must be provided'}]
|
|
14
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Permission config must be an object'}]
|
|
15
|
+
|
|
16
|
+
const errors: BlueprintError[] = validateResource(resource, {projectContained: true})
|
|
17
|
+
|
|
18
|
+
if (!('name' in resource) || !resource.name) {
|
|
19
|
+
errors.push({type: 'missing_parameter', message: 'Permission name is required'})
|
|
20
|
+
} else if (typeof resource.name !== 'string') {
|
|
21
|
+
errors.push({type: 'invalid_type', message: 'Permission name must be a string'})
|
|
22
|
+
} else if (!PERMISSION_NAME.test(resource.name)) {
|
|
23
|
+
errors.push({
|
|
24
|
+
type: 'invalid_format',
|
|
25
|
+
message:
|
|
26
|
+
'Permission name must only contain lowercase letters, numbers, hyphens, and underscores, and must not start with "sanity" or "res-"',
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!('type' in resource)) {
|
|
31
|
+
errors.push({type: 'missing_parameter', message: 'Permission type is required'})
|
|
32
|
+
} else if (resource.type !== 'sanity.access.permission') {
|
|
33
|
+
errors.push({type: 'invalid_value', message: 'Permission type must be `sanity.access.permission`'})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if ('title' in resource && resource.title !== undefined) {
|
|
37
|
+
if (typeof resource.title !== 'string') {
|
|
38
|
+
errors.push({type: 'invalid_type', message: 'Permission title must be a string'})
|
|
39
|
+
} else if (resource.title.length === 0) {
|
|
40
|
+
errors.push({type: 'invalid_value', message: 'Permission title must not be empty'})
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if ('description' in resource && resource.description !== undefined && typeof resource.description !== 'string') {
|
|
45
|
+
errors.push({type: 'invalid_type', message: 'Permission description must be a string'})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!('permissionType' in resource) || !resource.permissionType) {
|
|
49
|
+
errors.push({type: 'missing_parameter', message: 'Permission permissionType is required'})
|
|
50
|
+
} else if (typeof resource.permissionType !== 'string' || !PERMISSION_TYPES.includes(resource.permissionType)) {
|
|
51
|
+
errors.push({type: 'invalid_value', message: `Permission permissionType must be one of ${PERMISSION_TYPES.join(', ')}`})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!('config' in resource) || !resource.config) {
|
|
55
|
+
errors.push({type: 'missing_parameter', message: 'Permission `config` is required'})
|
|
56
|
+
} else if (typeof resource.config !== 'object') {
|
|
57
|
+
errors.push({type: 'invalid_type', message: 'Permission `config` must be an object'})
|
|
58
|
+
} else if (!('filter' in resource.config) || !resource.config.filter) {
|
|
59
|
+
errors.push({type: 'missing_parameter', message: 'Permission filter is required'})
|
|
60
|
+
} else if (typeof resource.config.filter !== 'string') {
|
|
61
|
+
errors.push({type: 'invalid_type', message: 'Permission filter must be a string'})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if ('project' in resource && resource.project !== undefined) {
|
|
65
|
+
if (typeof resource.project !== 'string') {
|
|
66
|
+
errors.push({type: 'invalid_type', message: 'Permission project must be a string'})
|
|
67
|
+
} else if (resource.project.length === 0) {
|
|
68
|
+
errors.push({type: 'invalid_value', message: 'Permission project must not be empty'})
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return errors
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Validates the fields of a content resource that make its filter.
|
|
77
|
+
* @param resource The content resource configuration
|
|
78
|
+
* @category Validation
|
|
79
|
+
* @returns A list of validation errors
|
|
80
|
+
*/
|
|
81
|
+
export function validateContentResource(resource: unknown): BlueprintError[] {
|
|
82
|
+
if (!resource) return [{type: 'invalid_value', message: 'Content resource config must be provided'}]
|
|
83
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Content resource config must be an object'}]
|
|
84
|
+
|
|
85
|
+
const errors: BlueprintError[] = []
|
|
86
|
+
|
|
87
|
+
if (
|
|
88
|
+
'documentTypes' in resource &&
|
|
89
|
+
resource.documentTypes !== undefined &&
|
|
90
|
+
(!Array.isArray(resource.documentTypes) || !resource.documentTypes.every((type) => typeof type === 'string' && type.length > 0))
|
|
91
|
+
) {
|
|
92
|
+
errors.push({type: 'invalid_type', message: 'Content resource documentTypes must be an array of non-empty strings'})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if ('filter' in resource && resource.filter !== undefined && typeof resource.filter !== 'string') {
|
|
96
|
+
errors.push({type: 'invalid_type', message: 'Content resource filter must be a string'})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return errors
|
|
100
|
+
}
|
|
@@ -82,10 +82,19 @@ export function validateResource(resource: unknown, options?: {projectContained?
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
if ('dependsOn' in resource.lifecycle) {
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
if (Array.isArray(resource.lifecycle.dependsOn)) {
|
|
86
|
+
if (!resource.lifecycle.dependsOn.every((dep) => dep.startsWith('$.resources.'))) {
|
|
87
|
+
errors.push({
|
|
88
|
+
type: 'invalid_value',
|
|
89
|
+
message: '`lifecycle.dependsOn` elements must be resource references starting with `$.resources.`',
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
} else if (typeof resource.lifecycle.dependsOn === 'string') {
|
|
93
|
+
if (!resource.lifecycle.dependsOn.startsWith('$.resources.')) {
|
|
94
|
+
errors.push({type: 'invalid_value', message: '`lifecycle.dependsOn` must be a resource reference starting with `$.resources.`'})
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
errors.push({type: 'invalid_type', message: '`lifecycle.dependsOn` must be a string or an array'})
|
|
89
98
|
}
|
|
90
99
|
}
|
|
91
100
|
}
|