@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
@@ -0,0 +1,102 @@
1
+ import type { BlueprintResource } from '../index.js';
2
+ /**
3
+ * A knowledge base that a Context MCP endpoint serves.
4
+ * @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
5
+ * @hidden
6
+ * @category Resource Types
7
+ */
8
+ export interface ContextKnowledgeBaseSource {
9
+ type: 'knowledge-base';
10
+ /** A knowledge base in the blueprint as `$.resources.<name>`, or the ID (`kb…`) of a knowledge base. */
11
+ id: string;
12
+ }
13
+ /**
14
+ * A Sanity dataset that a Context MCP endpoint serves.
15
+ * @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
16
+ * @hidden
17
+ * @category Resource Types
18
+ */
19
+ export interface ContextDatasetSource {
20
+ type: 'dataset';
21
+ /** The dataset as `<projectId>.<datasetName>`, for example `abc123.production`. It can't be a `$.resources.<name>` reference. */
22
+ id: string;
23
+ /** The studio workspace whose schema agents use, by name. `null` uses the studio's first workspace. */
24
+ workspace?: string | null;
25
+ /** The perspective agents query the dataset with. `null` uses `published`. */
26
+ perspective?: 'published' | 'drafts' | 'raw' | null;
27
+ /**
28
+ * Whether agents can use semantic search on the dataset. `false` turns it off. `true` or `null` use it while the
29
+ * dataset has embeddings enabled.
30
+ */
31
+ semanticSearch?: boolean | null;
32
+ }
33
+ /**
34
+ * Content that a Context MCP endpoint serves.
35
+ * @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
36
+ * @hidden
37
+ * @category Resource Types
38
+ */
39
+ export type ContextMcpEndpointSource = ContextKnowledgeBaseSource | ContextDatasetSource;
40
+ /**
41
+ * A Context knowledge base resource.
42
+ * @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
43
+ * @hidden
44
+ * @category Resource Types
45
+ */
46
+ export interface BlueprintContextKnowledgeBaseResource extends BlueprintResource {
47
+ type: 'sanity.context.knowledge-base';
48
+ /**
49
+ * The resource name in the blueprint. The knowledge base has no name, only a `title`. With the default deletion
50
+ * policy (`retain`), a deploy fails if this name changes.
51
+ */
52
+ name: string;
53
+ /** The knowledge base title, up to 100 characters. */
54
+ title: string;
55
+ /** What the knowledge base covers, up to 2,000 characters. */
56
+ description: string;
57
+ }
58
+ /**
59
+ * Configuration for a Context knowledge base.
60
+ * @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
61
+ * @hidden
62
+ * @category Resource Types
63
+ * @interface
64
+ */
65
+ export type BlueprintContextKnowledgeBaseConfig = Omit<BlueprintContextKnowledgeBaseResource, 'type'>;
66
+ /**
67
+ * A Context MCP endpoint resource.
68
+ * @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
69
+ * @hidden
70
+ * @category Resource Types
71
+ */
72
+ export interface BlueprintContextMcpEndpointResource extends BlueprintResource {
73
+ type: 'sanity.context.mcp';
74
+ /**
75
+ * The endpoint name in the URL that agents connect to: lowercase letters, digits and single hyphens, up to 64
76
+ * characters. The names `by-name` and `mcp` followed by 8 letters or digits are reserved. With the default deletion
77
+ * policy (`allow`), a change deletes the endpoint and creates a new endpoint with a new URL.
78
+ */
79
+ name: string;
80
+ /** The endpoint title, up to 100 characters. */
81
+ title: string;
82
+ /** What the endpoint serves: any number of knowledge bases and at most one dataset. */
83
+ sources: ContextMcpEndpointSource[];
84
+ /** Instructions for agents that connect to the endpoint, up to 10,000 characters. */
85
+ instructions?: string;
86
+ /** A GROQ filter for the documents that the dataset source serves. It requires a dataset source. */
87
+ groqFilter?: string;
88
+ }
89
+ /**
90
+ * Configuration for a Context MCP endpoint.
91
+ * @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
92
+ * @hidden
93
+ * @category Resource Types
94
+ * @interface
95
+ */
96
+ export type BlueprintContextMcpEndpointConfig = Omit<BlueprintContextMcpEndpointResource, 'type' | 'sources'> & {
97
+ /**
98
+ * What the endpoint serves: any number of knowledge bases and at most one dataset. A knowledge base source can also
99
+ * be the resource that {@link defineContextKnowledgeBase} returns.
100
+ */
101
+ sources: Array<ContextMcpEndpointSource | BlueprintContextKnowledgeBaseResource>;
102
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/types/context.ts"],"names":[],"mappings":""}
@@ -180,11 +180,10 @@ export interface BlueprintPubSubFunctionResource extends BlueprintBaseFunctionRe
180
180
  }
181
181
  /**
182
182
  * A durable, step-based function.
183
- * @alpha Deploying Durable Functions via Blueprints is experimental. This feature is not available publicly yet.
184
- * @hidden
183
+ * @beta Deploying Durable Functions via Blueprints is experimental.
185
184
  * @category Functions Types
186
185
  */
187
- export interface BlueprintDurableFunctionResource extends BlueprintBaseFunctionResource, QueueConfig {
186
+ export interface BlueprintDurableFunctionResource extends BlueprintBaseFunctionResource {
188
187
  type: 'sanity.function.durable';
189
188
  event?: BlueprintFunctionResourceContentLakeEvent;
190
189
  /**
@@ -301,12 +300,11 @@ export type BlueprintPubSubFunctionConfig = Omit<BlueprintPubSubFunctionResource
301
300
  /**
302
301
  * Configuration for defining a durable function.
303
302
  * @public
304
- * @alpha Deploying Durable Functions via Blueprints is experimental. This feature is not available publicly yet.
305
- * @hidden
303
+ * @beta Deploying Durable Functions via Blueprints is experimental.
306
304
  * @category Functions Types
307
305
  * @interface
308
306
  */
309
- export type BlueprintDurableConfig = Omit<BlueprintDurableFunctionResource, 'type' | 'src' | 'event' | 'durableTimeout' | 'debounce'> & {
307
+ export type BlueprintDurableConfig = Omit<BlueprintDurableFunctionResource, 'type' | 'src' | 'event' | 'durableTimeout'> & {
310
308
  /**
311
309
  * Path to the function source code
312
310
  * @defaultValue `functions/${name}`
@@ -321,8 +319,4 @@ export type BlueprintDurableConfig = Omit<BlueprintDurableFunctionResource, 'typ
321
319
  * @defaultValue 86_400 (24 hours)
322
320
  */
323
321
  durableTimeout?: string | number;
324
- /**
325
- * Optional debounce configuration, as a duration or a full config
326
- */
327
- debounce?: DebounceInput;
328
322
  };
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../src/types/permissions.ts"],"names":[],"mappings":""}
@@ -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;
@@ -0,0 +1,19 @@
1
+ import { type BlueprintError } from '../index.js';
2
+ /**
3
+ * Validates that the given resource is a valid Context knowledge base.
4
+ * @param resource The Context knowledge base resource
5
+ * @alpha
6
+ * @hidden
7
+ * @category Validation
8
+ * @returns A list of validation errors
9
+ */
10
+ export declare function validateContextKnowledgeBase(resource: unknown): BlueprintError[];
11
+ /**
12
+ * Validates that the given resource is a valid Context MCP endpoint.
13
+ * @param resource The Context MCP endpoint resource
14
+ * @alpha
15
+ * @hidden
16
+ * @category Validation
17
+ * @returns A list of validation errors
18
+ */
19
+ export declare function validateContextMcpEndpoint(resource: unknown): BlueprintError[];
@@ -0,0 +1,136 @@
1
+ import { validateResource } from '../index.js';
2
+ import { isReference } from '../utils/validation.js';
3
+ const MCP_ENDPOINT_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
4
+ const MCP_ENDPOINT_ID_PATTERN = /^mcp[a-z0-9]{8}$/;
5
+ const DATASET_SOURCE_PATTERN = /^[a-z0-9]+\.[a-z0-9][a-z0-9_-]*$/;
6
+ const DATASET_PERSPECTIVES = ['published', 'drafts', 'raw'];
7
+ function validateText(resource, field, label, options) {
8
+ if (!(field in resource)) {
9
+ return options.required ? [{ type: 'missing_parameter', message: `${label} is required` }] : [];
10
+ }
11
+ const value = Reflect.get(resource, field);
12
+ if (typeof value !== 'string')
13
+ return [{ type: 'invalid_type', message: `${label} must be a string` }];
14
+ if (value.length === 0)
15
+ return [{ type: 'invalid_value', message: `${label} must not be empty` }];
16
+ if (value.length > options.max) {
17
+ return [{ type: 'invalid_value', message: `${label} must be ${options.max} characters or less` }];
18
+ }
19
+ return [];
20
+ }
21
+ function validateDatasetSettings(source) {
22
+ const errors = [];
23
+ const workspace = Reflect.get(source, 'workspace');
24
+ const perspective = Reflect.get(source, 'perspective');
25
+ const semanticSearch = Reflect.get(source, 'semanticSearch');
26
+ if (workspace != null && (typeof workspace !== 'string' || workspace.length === 0)) {
27
+ errors.push({ type: 'invalid_type', message: 'Dataset source `workspace` must be a non-empty string or null' });
28
+ }
29
+ if (perspective != null && !DATASET_PERSPECTIVES.includes(perspective)) {
30
+ errors.push({ type: 'invalid_value', message: 'Dataset source `perspective` must be `published`, `drafts`, `raw` or null' });
31
+ }
32
+ if (semanticSearch != null && typeof semanticSearch !== 'boolean') {
33
+ errors.push({ type: 'invalid_type', message: 'Dataset source `semanticSearch` must be a boolean or null' });
34
+ }
35
+ return errors;
36
+ }
37
+ /**
38
+ * Validates that the given resource is a valid Context knowledge base.
39
+ * @param resource The Context knowledge base resource
40
+ * @alpha
41
+ * @hidden
42
+ * @category Validation
43
+ * @returns A list of validation errors
44
+ */
45
+ export function validateContextKnowledgeBase(resource) {
46
+ if (!resource)
47
+ return [{ type: 'invalid_value', message: 'Knowledge base config must be provided' }];
48
+ if (typeof resource !== 'object')
49
+ return [{ type: 'invalid_type', message: 'Knowledge base config must be an object' }];
50
+ const errors = validateResource(resource);
51
+ if ('type' in resource && resource.type !== 'sanity.context.knowledge-base') {
52
+ errors.push({ type: 'invalid_value', message: 'Knowledge base type must be `sanity.context.knowledge-base`' });
53
+ }
54
+ errors.push(...validateText(resource, 'title', 'Knowledge base title', { required: true, max: 100 }));
55
+ errors.push(...validateText(resource, 'description', 'Knowledge base description', { required: true, max: 2000 }));
56
+ return errors;
57
+ }
58
+ /**
59
+ * Validates that the given resource is a valid Context MCP endpoint.
60
+ * @param resource The Context MCP endpoint resource
61
+ * @alpha
62
+ * @hidden
63
+ * @category Validation
64
+ * @returns A list of validation errors
65
+ */
66
+ export function validateContextMcpEndpoint(resource) {
67
+ if (!resource)
68
+ return [{ type: 'invalid_value', message: 'MCP endpoint config must be provided' }];
69
+ if (typeof resource !== 'object')
70
+ return [{ type: 'invalid_type', message: 'MCP endpoint config must be an object' }];
71
+ const errors = validateResource(resource);
72
+ if ('type' in resource && resource.type !== 'sanity.context.mcp') {
73
+ errors.push({ type: 'invalid_value', message: 'MCP endpoint type must be `sanity.context.mcp`' });
74
+ }
75
+ if ('name' in resource && typeof resource.name === 'string') {
76
+ if (resource.name.length > 64 || !MCP_ENDPOINT_NAME_PATTERN.test(resource.name)) {
77
+ errors.push({
78
+ type: 'invalid_format',
79
+ message: 'MCP endpoint name must be lowercase letters, digits and single hyphens, up to 64 characters',
80
+ });
81
+ }
82
+ else if (resource.name === 'by-name' || MCP_ENDPOINT_ID_PATTERN.test(resource.name)) {
83
+ errors.push({ type: 'invalid_value', message: `MCP endpoint name "${resource.name}" is reserved` });
84
+ }
85
+ }
86
+ errors.push(...validateText(resource, 'title', 'MCP endpoint title', { required: true, max: 100 }));
87
+ errors.push(...validateText(resource, 'instructions', 'MCP endpoint instructions', { required: false, max: 10_000 }));
88
+ errors.push(...validateText(resource, 'groqFilter', 'MCP endpoint GROQ filter', { required: false, max: 10_000 }));
89
+ if (!('sources' in resource)) {
90
+ errors.push({ type: 'missing_parameter', message: 'MCP endpoint sources are required' });
91
+ return errors;
92
+ }
93
+ if (!Array.isArray(resource.sources) || resource.sources.length === 0) {
94
+ errors.push({ type: 'invalid_value', message: 'MCP endpoint must have at least one source' });
95
+ return errors;
96
+ }
97
+ if (resource.sources.length > 100) {
98
+ errors.push({ type: 'invalid_value', message: 'MCP endpoint can have at most 100 sources' });
99
+ }
100
+ let datasets = 0;
101
+ for (const source of resource.sources) {
102
+ if (!source || typeof source !== 'object' || !('type' in source) || !('id' in source)) {
103
+ errors.push({ type: 'invalid_value', message: 'Each MCP endpoint source needs a `type` and an `id`' });
104
+ continue;
105
+ }
106
+ if (typeof source.id !== 'string' || source.id.length === 0) {
107
+ errors.push({ type: 'invalid_type', message: 'MCP endpoint source `id` must be a non-empty string' });
108
+ continue;
109
+ }
110
+ if (source.type === 'dataset') {
111
+ datasets++;
112
+ // The provider checks the format before references resolve, and no resource exposes `<projectId>.<datasetName>`
113
+ if (source.id.startsWith('$.resources.')) {
114
+ errors.push({
115
+ type: 'invalid_value',
116
+ message: `Dataset source "${source.id}" must be "<projectId>.<datasetName>", not a resource reference`,
117
+ });
118
+ }
119
+ else if (!isReference(source.id) && !DATASET_SOURCE_PATTERN.test(source.id)) {
120
+ errors.push({ type: 'invalid_format', message: `Dataset source "${source.id}" must be "<projectId>.<datasetName>"` });
121
+ }
122
+ errors.push(...validateDatasetSettings(source));
123
+ }
124
+ else if (source.type !== 'knowledge-base') {
125
+ errors.push({ type: 'invalid_value', message: 'MCP endpoint source `type` must be `knowledge-base` or `dataset`' });
126
+ }
127
+ }
128
+ if (datasets > 1) {
129
+ errors.push({ type: 'invalid_value', message: 'MCP endpoint can have at most one dataset source' });
130
+ }
131
+ if (datasets === 0 && 'groqFilter' in resource) {
132
+ errors.push({ type: 'invalid_value', message: 'MCP endpoint GROQ filter requires a dataset source' });
133
+ }
134
+ return errors;
135
+ }
136
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/validation/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,gBAAgB,EAAC,MAAM,aAAa,CAAA;AACjE,OAAO,EAAC,WAAW,EAAC,MAAM,wBAAwB,CAAA;AAElD,MAAM,yBAAyB,GAAG,4BAA4B,CAAA;AAC9D,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AC,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;gBAC9E,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,mBAAmB,MAAM,CAAC,EAAE,uCAAuC,EAAC,CAAC,CAAA;YACrH,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAA;QACjD,CAAC;aAAM,IAAI,MAAM,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YAC5C,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,kEAAkE,EAAC,CAAC,CAAA;QACnH,CAAC;IACH,CAAC;IACD,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,kDAAkD,EAAC,CAAC,CAAA;IACnG,CAAC;IACD,IAAI,QAAQ,KAAK,CAAC,IAAI,YAAY,IAAI,QAAQ,EAAE,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,oDAAoD,EAAC,CAAC,CAAA;IACrG,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -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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f,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/blueprints",
3
- "version": "0.29.0",
3
+ "version": "0.31.0",
4
4
  "description": "Helper methods and type definitions for Sanity Blueprints",
5
5
  "keywords": [
6
6
  "sanity",
@@ -0,0 +1,124 @@
1
+ import {
2
+ type BlueprintContextKnowledgeBaseConfig,
3
+ type BlueprintContextKnowledgeBaseResource,
4
+ type BlueprintContextMcpEndpointConfig,
5
+ type BlueprintContextMcpEndpointResource,
6
+ validateContextKnowledgeBase,
7
+ validateContextMcpEndpoint,
8
+ } from '../index.js'
9
+ import {runValidation} from '../utils/validation.js'
10
+
11
+ /**
12
+ * Defines a Context knowledge base.
13
+ *
14
+ * @remarks
15
+ * The blueprint must be scoped to an organization. A new knowledge base has no sources. Add sources in the Context API
16
+ * or the dashboard.
17
+ *
18
+ * The default deletion policy is `retain`. If the stack is destroyed, the knowledge base is detached and not deleted. If
19
+ * the resource is removed from the blueprint, the deploy fails. To remove the resource, first deploy it with one of these
20
+ * `lifecycle` values:
21
+ * - `{ownershipAction: {type: 'detach'}}` keeps the knowledge base.
22
+ * - `{deletionPolicy: 'allow'}` deletes the knowledge base.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * defineContextKnowledgeBase({
27
+ * name: 'product-docs',
28
+ * title: 'Product docs',
29
+ * description: 'Everything about the product',
30
+ * })
31
+ * ```
32
+ *
33
+ * @example Detach before removal
34
+ * ```ts
35
+ * defineContextKnowledgeBase({
36
+ * name: 'product-docs',
37
+ * title: 'Product docs',
38
+ * description: 'Everything about the product',
39
+ * lifecycle: {ownershipAction: {type: 'detach'}},
40
+ * })
41
+ * ```
42
+ * @param parameters The knowledge base configuration
43
+ * @public
44
+ * @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
45
+ * @hidden
46
+ * @category Definers
47
+ * @expandType BlueprintContextKnowledgeBaseConfig
48
+ * @returns The knowledge base resource
49
+ */
50
+ export function defineContextKnowledgeBase(parameters: BlueprintContextKnowledgeBaseConfig): BlueprintContextKnowledgeBaseResource {
51
+ const knowledgeBaseResource: BlueprintContextKnowledgeBaseResource = {
52
+ ...parameters,
53
+ type: 'sanity.context.knowledge-base',
54
+ }
55
+
56
+ runValidation(() => validateContextKnowledgeBase(knowledgeBaseResource))
57
+
58
+ return knowledgeBaseResource
59
+ }
60
+
61
+ /**
62
+ * Defines a Context MCP endpoint that agents connect to.
63
+ *
64
+ * @remarks
65
+ * The blueprint must be scoped to an organization.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * defineContextMcpEndpoint({
70
+ * name: 'support-agent',
71
+ * title: 'Support agent',
72
+ * sources: [{type: 'dataset', id: 'abc123.production'}],
73
+ * })
74
+ * ```
75
+ *
76
+ * @example Knowledge base and dataset sources
77
+ * ```ts
78
+ * const productDocs = defineContextKnowledgeBase({
79
+ * name: 'product-docs',
80
+ * title: 'Product docs',
81
+ * description: 'Everything about the product',
82
+ * })
83
+ *
84
+ * defineContextMcpEndpoint({
85
+ * name: 'support-agent',
86
+ * title: 'Support agent',
87
+ * sources: [productDocs, {type: 'dataset', id: 'abc123.production'}],
88
+ * instructions: 'Answer questions about the product.',
89
+ * groqFilter: '_type in ["article", "faq"]',
90
+ * })
91
+ * ```
92
+ *
93
+ * @example Dataset settings
94
+ * ```ts
95
+ * defineContextMcpEndpoint({
96
+ * name: 'editor-agent',
97
+ * title: 'Editor agent',
98
+ * sources: [{type: 'dataset', id: 'abc123.production', workspace: 'marketing', perspective: 'drafts', semanticSearch: false}],
99
+ * })
100
+ * ```
101
+ * @param parameters The MCP endpoint configuration
102
+ * @public
103
+ * @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
104
+ * @hidden
105
+ * @category Definers
106
+ * @expandType BlueprintContextMcpEndpointConfig
107
+ * @returns The MCP endpoint resource
108
+ */
109
+ export function defineContextMcpEndpoint(parameters: BlueprintContextMcpEndpointConfig): BlueprintContextMcpEndpointResource {
110
+ const mcpEndpointResource: BlueprintContextMcpEndpointResource = {
111
+ ...parameters,
112
+ type: 'sanity.context.mcp',
113
+ // Malformed sources pass through untouched, so validation reports them instead of throwing here.
114
+ sources: Array.isArray(parameters.sources)
115
+ ? parameters.sources.map((source) =>
116
+ source?.type === 'sanity.context.knowledge-base' ? {type: 'knowledge-base', id: `$.resources.${source.name}`} : source,
117
+ )
118
+ : parameters.sources,
119
+ }
120
+
121
+ runValidation(() => validateContextMcpEndpoint(mcpEndpointResource))
122
+
123
+ return mcpEndpointResource
124
+ }