@sanity/blueprints 0.29.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +11 -9
  2. package/dist/definers/context.d.ts +90 -0
  3. package/dist/definers/context.js +110 -0
  4. package/dist/definers/context.js.map +1 -0
  5. package/dist/definers/functions/durable.d.ts +1 -5
  6. package/dist/definers/functions/durable.js +5 -9
  7. package/dist/definers/functions/durable.js.map +1 -1
  8. package/dist/definers/permissions.d.ts +71 -0
  9. package/dist/definers/permissions.js +95 -0
  10. package/dist/definers/permissions.js.map +1 -0
  11. package/dist/index.d.ts +6 -0
  12. package/dist/index.js +6 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/types/context.d.ts +102 -0
  15. package/dist/types/context.js +2 -0
  16. package/dist/types/context.js.map +1 -0
  17. package/dist/types/functions/index.d.ts +4 -10
  18. package/dist/types/permissions.d.ts +63 -0
  19. package/dist/types/permissions.js +2 -0
  20. package/dist/types/permissions.js.map +1 -0
  21. package/dist/types/roles.d.ts +1 -1
  22. package/dist/validation/context.d.ts +19 -0
  23. package/dist/validation/context.js +136 -0
  24. package/dist/validation/context.js.map +1 -0
  25. package/dist/validation/permissions.d.ts +15 -0
  26. package/dist/validation/permissions.js +95 -0
  27. package/dist/validation/permissions.js.map +1 -0
  28. package/package.json +1 -1
  29. package/src/definers/context.ts +124 -0
  30. package/src/definers/functions/durable.ts +5 -9
  31. package/src/definers/permissions.ts +107 -0
  32. package/src/index.ts +6 -0
  33. package/src/types/context.ts +109 -0
  34. package/src/types/functions/index.ts +4 -10
  35. package/src/types/permissions.ts +67 -0
  36. package/src/types/roles.ts +1 -1
  37. package/src/validation/context.ts +142 -0
  38. package/src/validation/permissions.ts +100 -0
package/README.md CHANGED
@@ -67,15 +67,17 @@ export default defineBlueprint({
67
67
 
68
68
  ## Available resources
69
69
 
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
- | `defineCorsOrigin` β | CORS origin allowing browser requests to your project |
76
- | `defineDocumentWebhook` β | Webhook triggered by document changes |
77
- | `defineRole` β | Custom role with permissions |
78
- | `defineRobotToken` β | Robot token for automated access |
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 |
79
81
 
80
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.
81
83
 
@@ -0,0 +1,90 @@
1
+ import { type BlueprintContextKnowledgeBaseConfig, type BlueprintContextKnowledgeBaseResource, type BlueprintContextMcpEndpointConfig, type BlueprintContextMcpEndpointResource } from '../index.js';
2
+ /**
3
+ * Defines a Context knowledge base.
4
+ *
5
+ * @remarks
6
+ * The blueprint must be scoped to an organization. A new knowledge base has no sources. Add sources in the Context API
7
+ * or the dashboard.
8
+ *
9
+ * The default deletion policy is `retain`. If the stack is destroyed, the knowledge base is detached and not deleted. If
10
+ * the resource is removed from the blueprint, the deploy fails. To remove the resource, first deploy it with one of these
11
+ * `lifecycle` values:
12
+ * - `{ownershipAction: {type: 'detach'}}` keeps the knowledge base.
13
+ * - `{deletionPolicy: 'allow'}` deletes the knowledge base.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * defineContextKnowledgeBase({
18
+ * name: 'product-docs',
19
+ * title: 'Product docs',
20
+ * description: 'Everything about the product',
21
+ * })
22
+ * ```
23
+ *
24
+ * @example Detach before removal
25
+ * ```ts
26
+ * defineContextKnowledgeBase({
27
+ * name: 'product-docs',
28
+ * title: 'Product docs',
29
+ * description: 'Everything about the product',
30
+ * lifecycle: {ownershipAction: {type: 'detach'}},
31
+ * })
32
+ * ```
33
+ * @param parameters The knowledge base configuration
34
+ * @public
35
+ * @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
36
+ * @hidden
37
+ * @category Definers
38
+ * @expandType BlueprintContextKnowledgeBaseConfig
39
+ * @returns The knowledge base resource
40
+ */
41
+ export declare function defineContextKnowledgeBase(parameters: BlueprintContextKnowledgeBaseConfig): BlueprintContextKnowledgeBaseResource;
42
+ /**
43
+ * Defines a Context MCP endpoint that agents connect to.
44
+ *
45
+ * @remarks
46
+ * The blueprint must be scoped to an organization.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * defineContextMcpEndpoint({
51
+ * name: 'support-agent',
52
+ * title: 'Support agent',
53
+ * sources: [{type: 'dataset', id: 'abc123.production'}],
54
+ * })
55
+ * ```
56
+ *
57
+ * @example Knowledge base and dataset sources
58
+ * ```ts
59
+ * const productDocs = defineContextKnowledgeBase({
60
+ * name: 'product-docs',
61
+ * title: 'Product docs',
62
+ * description: 'Everything about the product',
63
+ * })
64
+ *
65
+ * defineContextMcpEndpoint({
66
+ * name: 'support-agent',
67
+ * title: 'Support agent',
68
+ * sources: [productDocs, {type: 'dataset', id: 'abc123.production'}],
69
+ * instructions: 'Answer questions about the product.',
70
+ * groqFilter: '_type in ["article", "faq"]',
71
+ * })
72
+ * ```
73
+ *
74
+ * @example Dataset settings
75
+ * ```ts
76
+ * defineContextMcpEndpoint({
77
+ * name: 'editor-agent',
78
+ * title: 'Editor agent',
79
+ * sources: [{type: 'dataset', id: 'abc123.production', workspace: 'marketing', perspective: 'drafts', semanticSearch: false}],
80
+ * })
81
+ * ```
82
+ * @param parameters The MCP endpoint configuration
83
+ * @public
84
+ * @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
85
+ * @hidden
86
+ * @category Definers
87
+ * @expandType BlueprintContextMcpEndpointConfig
88
+ * @returns The MCP endpoint resource
89
+ */
90
+ export declare function defineContextMcpEndpoint(parameters: BlueprintContextMcpEndpointConfig): BlueprintContextMcpEndpointResource;
@@ -0,0 +1,110 @@
1
+ import { validateContextKnowledgeBase, validateContextMcpEndpoint, } from '../index.js';
2
+ import { runValidation } from '../utils/validation.js';
3
+ /**
4
+ * Defines a Context knowledge base.
5
+ *
6
+ * @remarks
7
+ * The blueprint must be scoped to an organization. A new knowledge base has no sources. Add sources in the Context API
8
+ * or the dashboard.
9
+ *
10
+ * The default deletion policy is `retain`. If the stack is destroyed, the knowledge base is detached and not deleted. If
11
+ * the resource is removed from the blueprint, the deploy fails. To remove the resource, first deploy it with one of these
12
+ * `lifecycle` values:
13
+ * - `{ownershipAction: {type: 'detach'}}` keeps the knowledge base.
14
+ * - `{deletionPolicy: 'allow'}` deletes the knowledge base.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * defineContextKnowledgeBase({
19
+ * name: 'product-docs',
20
+ * title: 'Product docs',
21
+ * description: 'Everything about the product',
22
+ * })
23
+ * ```
24
+ *
25
+ * @example Detach before removal
26
+ * ```ts
27
+ * defineContextKnowledgeBase({
28
+ * name: 'product-docs',
29
+ * title: 'Product docs',
30
+ * description: 'Everything about the product',
31
+ * lifecycle: {ownershipAction: {type: 'detach'}},
32
+ * })
33
+ * ```
34
+ * @param parameters The knowledge base configuration
35
+ * @public
36
+ * @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
37
+ * @hidden
38
+ * @category Definers
39
+ * @expandType BlueprintContextKnowledgeBaseConfig
40
+ * @returns The knowledge base resource
41
+ */
42
+ export function defineContextKnowledgeBase(parameters) {
43
+ const knowledgeBaseResource = {
44
+ ...parameters,
45
+ type: 'sanity.context.knowledge-base',
46
+ };
47
+ runValidation(() => validateContextKnowledgeBase(knowledgeBaseResource));
48
+ return knowledgeBaseResource;
49
+ }
50
+ /**
51
+ * Defines a Context MCP endpoint that agents connect to.
52
+ *
53
+ * @remarks
54
+ * The blueprint must be scoped to an organization.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * defineContextMcpEndpoint({
59
+ * name: 'support-agent',
60
+ * title: 'Support agent',
61
+ * sources: [{type: 'dataset', id: 'abc123.production'}],
62
+ * })
63
+ * ```
64
+ *
65
+ * @example Knowledge base and dataset sources
66
+ * ```ts
67
+ * const productDocs = defineContextKnowledgeBase({
68
+ * name: 'product-docs',
69
+ * title: 'Product docs',
70
+ * description: 'Everything about the product',
71
+ * })
72
+ *
73
+ * defineContextMcpEndpoint({
74
+ * name: 'support-agent',
75
+ * title: 'Support agent',
76
+ * sources: [productDocs, {type: 'dataset', id: 'abc123.production'}],
77
+ * instructions: 'Answer questions about the product.',
78
+ * groqFilter: '_type in ["article", "faq"]',
79
+ * })
80
+ * ```
81
+ *
82
+ * @example Dataset settings
83
+ * ```ts
84
+ * defineContextMcpEndpoint({
85
+ * name: 'editor-agent',
86
+ * title: 'Editor agent',
87
+ * sources: [{type: 'dataset', id: 'abc123.production', workspace: 'marketing', perspective: 'drafts', semanticSearch: false}],
88
+ * })
89
+ * ```
90
+ * @param parameters The MCP endpoint configuration
91
+ * @public
92
+ * @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
93
+ * @hidden
94
+ * @category Definers
95
+ * @expandType BlueprintContextMcpEndpointConfig
96
+ * @returns The MCP endpoint resource
97
+ */
98
+ export function defineContextMcpEndpoint(parameters) {
99
+ const mcpEndpointResource = {
100
+ ...parameters,
101
+ type: 'sanity.context.mcp',
102
+ // Malformed sources pass through untouched, so validation reports them instead of throwing here.
103
+ sources: Array.isArray(parameters.sources)
104
+ ? parameters.sources.map((source) => source?.type === 'sanity.context.knowledge-base' ? { type: 'knowledge-base', id: `$.resources.${source.name}` } : source)
105
+ : parameters.sources,
106
+ };
107
+ runValidation(() => validateContextMcpEndpoint(mcpEndpointResource));
108
+ return mcpEndpointResource;
109
+ }
110
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/definers/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,aAAa,CAAA;AACpB,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,UAAU,0BAA0B,CAAC,UAA+C;IACxF,MAAM,qBAAqB,GAA0C;QACnE,GAAG,UAAU;QACb,IAAI,EAAE,+BAA+B;KACtC,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,4BAA4B,CAAC,qBAAqB,CAAC,CAAC,CAAA;IAExE,OAAO,qBAAqB,CAAA;AAC9B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,wBAAwB,CAAC,UAA6C;IACpF,MAAM,mBAAmB,GAAwC;QAC/D,GAAG,UAAU;QACb,IAAI,EAAE,oBAAoB;QAC1B,iGAAiG;QACjG,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;YACxC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAChC,MAAM,EAAE,IAAI,KAAK,+BAA+B,CAAC,CAAC,CAAC,EAAC,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,eAAe,MAAM,CAAC,IAAI,EAAE,EAAC,CAAC,CAAC,CAAC,MAAM,CACvH;YACH,CAAC,CAAC,UAAU,CAAC,OAAO;KACvB,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,0BAA0B,CAAC,mBAAmB,CAAC,CAAC,CAAA;IAEpE,OAAO,mBAAmB,CAAA;AAC5B,CAAC"}
@@ -8,17 +8,13 @@ import { type BlueprintDurableConfig, type BlueprintDurableFunctionResource } fr
8
8
  * defineDurableFunction({
9
9
  * name: 'daily-cleanup',
10
10
  * event: {type: 'document', on: ['create'], filter: "_type == 'post'"},
11
- * concurrency: 5,
12
- * debounce: 10,
13
11
  * })
14
12
  * ```
15
13
  *
16
- *
17
14
  * @param functionConfig The configuration for the function
18
15
  * @category Definers
19
- * @alpha Deploying Durable Functions via Blueprints is experimental. This feature is not available publicly yet.
16
+ * @beta Deploying Durable Functions via Blueprints is experimental.
20
17
  * @public
21
- * @hidden
22
18
  * @expandType BlueprintDurableConfig
23
19
  * @returns The validated durable function resource
24
20
  */
@@ -1,5 +1,4 @@
1
1
  import { validateDurableFunction } from '../../index.js';
2
- import { createDebounceObject } from '../../utils/debounce.js';
3
2
  import { parseDuration } from '../../utils/parse-duration.js';
4
3
  import { runValidation } from '../../utils/validation.js';
5
4
  import { defineFunction } from './index.js';
@@ -12,29 +11,26 @@ import { defineFunction } from './index.js';
12
11
  * defineDurableFunction({
13
12
  * name: 'daily-cleanup',
14
13
  * event: {type: 'document', on: ['create'], filter: "_type == 'post'"},
15
- * concurrency: 5,
16
- * debounce: 10,
17
14
  * })
18
15
  * ```
19
16
  *
20
- *
21
17
  * @param functionConfig The configuration for the function
22
18
  * @category Definers
23
- * @alpha Deploying Durable Functions via Blueprints is experimental. This feature is not available publicly yet.
19
+ * @beta Deploying Durable Functions via Blueprints is experimental.
24
20
  * @public
25
- * @hidden
26
21
  * @expandType BlueprintDurableConfig
27
22
  * @returns The validated durable function resource
28
23
  */
29
24
  export function defineDurableFunction(functionConfig) {
30
- const { name, event, concurrency, debounce, src, durableTimeout } = functionConfig;
25
+ const { name, event, src, durableTimeout } = functionConfig;
31
26
  const functionResource = {
32
27
  ...defineFunction({ ...functionConfig, src: src ?? `functions/${name}` }, { skipValidation: true }),
33
28
  type: 'sanity.function.durable',
34
29
  ...(event !== undefined && { event }),
35
30
  ...(durableTimeout !== undefined && { durableTimeout: parseDuration(durableTimeout, 's') }),
36
- ...(concurrency !== undefined && { concurrency }),
37
- ...(debounce !== undefined && { debounce: createDebounceObject(debounce) }),
31
+ // TODO: eventually support queue fields once backend supports it
32
+ // ...(concurrency !== undefined && {concurrency}),
33
+ // ...(debounce !== undefined && {debounce: createDebounceObject(debounce)}),
38
34
  };
39
35
  runValidation(() => validateDurableFunction(functionResource));
40
36
  return functionResource;
@@ -1 +1 @@
1
- {"version":3,"file":"durable.js","sourceRoot":"","sources":["../../../src/definers/functions/durable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqE,uBAAuB,EAAC,MAAM,gBAAgB,CAAA;AAC1H,OAAO,EAAC,oBAAoB,EAAC,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAC,aAAa,EAAC,MAAM,+BAA+B,CAAA;AAC3D,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AAEzC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,qBAAqB,CAAC,cAAsC;IAC1E,MAAM,EAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAC,GAAG,cAAc,CAAA;IAChF,MAAM,gBAAgB,GAAqC;QACzD,GAAG,cAAc,CAAC,EAAC,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,aAAa,IAAI,EAAE,EAAC,EAAE,EAAC,cAAc,EAAE,IAAI,EAAC,CAAC;QAC/F,IAAI,EAAE,yBAAyB;QAC/B,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAC,KAAK,EAAC,CAAC;QACnC,GAAG,CAAC,cAAc,KAAK,SAAS,IAAI,EAAC,cAAc,EAAE,aAAa,CAAC,cAAc,EAAE,GAAG,CAAC,EAAC,CAAC;QACzF,GAAG,CAAC,WAAW,KAAK,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CAAA;AACzB,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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,GAAG,CAAC,CAAC,CAAC,UAAU,CAAA;AAC7D,CAAC"}
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  */
9
9
  export * from './definers/applications.js';
10
10
  export * from './definers/blueprints.js';
11
+ export * from './definers/context.js';
11
12
  export * from './definers/cors.js';
12
13
  export * from './definers/datasets.js';
13
14
  export * from './definers/functions/document.js';
@@ -19,6 +20,7 @@ export * from './definers/functions/queue.js';
19
20
  export * from './definers/functions/scheduled.js';
20
21
  export * from './definers/functions/sync-tag-invalidate.js';
21
22
  export * from './definers/installation-config.js';
23
+ export * from './definers/permissions.js';
22
24
  export * from './definers/projects.js';
23
25
  export * from './definers/resources.js';
24
26
  export * from './definers/robots.js';
@@ -36,11 +38,13 @@ export * from './definers/webhooks.js';
36
38
  */
37
39
  export * from './types/applications.js';
38
40
  export * from './types/blueprints.js';
41
+ export * from './types/context.js';
39
42
  export * from './types/cors.js';
40
43
  export * from './types/datasets.js';
41
44
  export * from './types/errors.js';
42
45
  export * from './types/functions/index.js';
43
46
  export * from './types/installation-config.js';
47
+ export * from './types/permissions.js';
44
48
  export * from './types/projects.js';
45
49
  export * from './types/resources.js';
46
50
  export * from './types/robots.js';
@@ -54,10 +58,12 @@ export * from './types/webhooks.js';
54
58
  */
55
59
  export * from './validation/applications.js';
56
60
  export * from './validation/blueprints.js';
61
+ export * from './validation/context.js';
57
62
  export * from './validation/cors.js';
58
63
  export * from './validation/datasets.js';
59
64
  export * from './validation/functions.js';
60
65
  export * from './validation/installation-config.js';
66
+ export * from './validation/permissions.js';
61
67
  export * from './validation/projects.js';
62
68
  export * from './validation/resources.js';
63
69
  export * from './validation/robots.js';
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@
9
9
  */
10
10
  export * from './definers/applications.js';
11
11
  export * from './definers/blueprints.js';
12
+ export * from './definers/context.js';
12
13
  export * from './definers/cors.js';
13
14
  export * from './definers/datasets.js';
14
15
  export * from './definers/functions/document.js';
@@ -20,6 +21,7 @@ export * from './definers/functions/queue.js';
20
21
  export * from './definers/functions/scheduled.js';
21
22
  export * from './definers/functions/sync-tag-invalidate.js';
22
23
  export * from './definers/installation-config.js';
24
+ export * from './definers/permissions.js';
23
25
  export * from './definers/projects.js';
24
26
  export * from './definers/resources.js';
25
27
  export * from './definers/robots.js';
@@ -38,11 +40,13 @@ export * from './definers/webhooks.js';
38
40
  */
39
41
  export * from './types/applications.js';
40
42
  export * from './types/blueprints.js';
43
+ export * from './types/context.js';
41
44
  export * from './types/cors.js';
42
45
  export * from './types/datasets.js';
43
46
  export * from './types/errors.js';
44
47
  export * from './types/functions/index.js';
45
48
  export * from './types/installation-config.js';
49
+ export * from './types/permissions.js';
46
50
  export * from './types/projects.js';
47
51
  export * from './types/resources.js';
48
52
  export * from './types/robots.js';
@@ -57,10 +61,12 @@ export * from './types/webhooks.js';
57
61
  */
58
62
  export * from './validation/applications.js';
59
63
  export * from './validation/blueprints.js';
64
+ export * from './validation/context.js';
60
65
  export * from './validation/cors.js';
61
66
  export * from './validation/datasets.js';
62
67
  export * from './validation/functions.js';
63
68
  export * from './validation/installation-config.js';
69
+ export * from './validation/permissions.js';
64
70
  export * from './validation/projects.js';
65
71
  export * from './validation/resources.js';
66
72
  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;AACH,cAAc,4BAA4B,CAAA;AAC1C,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,kCAAkC,CAAA;AAChD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,uCAAuC,CAAA;AACrD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,mCAAmC,CAAA;AACjD,cAAc,6CAA6C,CAAA;AA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