@sanity/blueprints 0.11.0 → 0.12.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 +40 -317
- package/dist/definers/blueprints.d.ts +15 -3
- package/dist/definers/blueprints.js +40 -3
- package/dist/definers/blueprints.js.map +1 -1
- package/dist/definers/cors.d.ts +5 -2
- package/dist/definers/cors.js +17 -2
- package/dist/definers/cors.js.map +1 -1
- package/dist/definers/datasets.d.ts +5 -2
- package/dist/definers/datasets.js +18 -2
- package/dist/definers/datasets.js.map +1 -1
- package/dist/definers/functions.d.ts +37 -61
- package/dist/definers/functions.js +69 -95
- package/dist/definers/functions.js.map +1 -1
- package/dist/definers/resources.d.ts +10 -0
- package/dist/definers/resources.js +21 -0
- package/dist/definers/resources.js.map +1 -1
- package/dist/definers/robotTokens.d.ts +22 -0
- package/dist/definers/robotTokens.js +53 -0
- package/dist/definers/robotTokens.js.map +1 -0
- package/dist/definers/robots.d.ts +2 -22
- package/dist/definers/robots.js +2 -33
- package/dist/definers/robots.js.map +1 -1
- package/dist/definers/roles.d.ts +16 -25
- package/dist/definers/roles.js +64 -23
- package/dist/definers/roles.js.map +1 -1
- package/dist/definers/webhooks.d.ts +5 -2
- package/dist/definers/webhooks.js +25 -2
- package/dist/definers/webhooks.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/types/cors.d.ts +2 -0
- package/dist/types/datasets.d.ts +5 -1
- package/dist/types/functions.d.ts +65 -3
- package/dist/types/functions.js.map +1 -1
- package/dist/types/resources.d.ts +8 -0
- package/dist/types/robotTokens.d.ts +45 -0
- package/dist/types/robotTokens.js +2 -0
- package/dist/types/robotTokens.js.map +1 -0
- package/dist/types/robots.d.ts +8 -39
- package/dist/types/robots.js +1 -0
- package/dist/types/robots.js.map +1 -1
- package/dist/types/roles.d.ts +1 -0
- package/dist/types/webhooks.d.ts +6 -0
- package/dist/validation/robotTokens.d.ts +15 -0
- package/dist/validation/robotTokens.js +104 -0
- package/dist/validation/robotTokens.js.map +1 -0
- package/dist/validation/robots.d.ts +4 -15
- package/dist/validation/robots.js +5 -103
- package/dist/validation/robots.js.map +1 -1
- package/package.json +6 -6
- package/src/definers/blueprints.ts +40 -3
- package/src/definers/cors.ts +17 -2
- package/src/definers/datasets.ts +18 -2
- package/src/definers/functions.ts +124 -132
- package/src/definers/resources.ts +21 -0
- package/src/definers/robotTokens.ts +56 -0
- package/src/definers/robots.ts +2 -37
- package/src/definers/roles.ts +64 -23
- package/src/definers/webhooks.ts +25 -2
- package/src/index.ts +3 -0
- package/src/types/cors.ts +2 -0
- package/src/types/datasets.ts +5 -1
- package/src/types/functions.ts +71 -3
- package/src/types/resources.ts +8 -1
- package/src/types/robotTokens.ts +50 -0
- package/src/types/robots.ts +10 -44
- package/src/types/roles.ts +1 -0
- package/src/types/webhooks.ts +6 -0
- package/src/validation/robotTokens.ts +103 -0
- package/src/validation/robots.ts +5 -102
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type BlueprintError } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates that the given resource is a valid Robot Token.
|
|
4
|
+
* @param resource The Robot Token resource
|
|
5
|
+
* @category Validation
|
|
6
|
+
* @returns A list of validation errors
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateRobotToken(resource: unknown): BlueprintError[];
|
|
9
|
+
/**
|
|
10
|
+
* Validates that the given membership is a valid Robot Token membership.
|
|
11
|
+
* @param membership The membership to validate
|
|
12
|
+
* @internal
|
|
13
|
+
* @returns A list of validation errors
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateRobotTokenMembership(membership: unknown): BlueprintError[];
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { validateResource } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates that the given resource is a valid Robot Token.
|
|
4
|
+
* @param resource The Robot Token resource
|
|
5
|
+
* @category Validation
|
|
6
|
+
* @returns A list of validation errors
|
|
7
|
+
*/
|
|
8
|
+
export function validateRobotToken(resource) {
|
|
9
|
+
if (!resource)
|
|
10
|
+
return [{ type: 'invalid_value', message: 'Robot config must be provided' }];
|
|
11
|
+
if (typeof resource !== 'object')
|
|
12
|
+
return [{ type: 'invalid_type', message: 'Robot config must be an object' }];
|
|
13
|
+
const errors = validateResource(resource, { projectContained: true });
|
|
14
|
+
if (!('name' in resource) || !resource.name) {
|
|
15
|
+
errors.push({ type: 'missing_parameter', message: 'Robot name is required' });
|
|
16
|
+
}
|
|
17
|
+
else if (typeof resource.name !== 'string') {
|
|
18
|
+
errors.push({ type: 'invalid_type', message: 'Robot name must be a string' });
|
|
19
|
+
}
|
|
20
|
+
if (!('type' in resource)) {
|
|
21
|
+
errors.push({ type: 'missing_parameter', message: 'Robot type is required' });
|
|
22
|
+
}
|
|
23
|
+
else if (resource.type !== 'sanity.access.robot') {
|
|
24
|
+
errors.push({ type: 'invalid_value', message: 'Robot type must be `sanity.access.robot`' });
|
|
25
|
+
}
|
|
26
|
+
if (!('label' in resource) || !resource.label) {
|
|
27
|
+
errors.push({ type: 'missing_parameter', message: 'Robot label is required' });
|
|
28
|
+
}
|
|
29
|
+
else if (typeof resource.label !== 'string') {
|
|
30
|
+
errors.push({ type: 'invalid_type', message: 'Robot label must be a string' });
|
|
31
|
+
}
|
|
32
|
+
if (!('memberships' in resource)) {
|
|
33
|
+
errors.push({ type: 'missing_parameter', message: 'Robot memberships array is required' });
|
|
34
|
+
}
|
|
35
|
+
else if (!Array.isArray(resource.memberships)) {
|
|
36
|
+
errors.push({ type: 'invalid_type', message: 'Robot memberships must be an array' });
|
|
37
|
+
}
|
|
38
|
+
else if (resource.memberships.length === 0) {
|
|
39
|
+
errors.push({ type: 'invalid_value', message: 'Robot must have at least one membership' });
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
errors.push(...resource.memberships.flatMap(validateRobotTokenMembership));
|
|
43
|
+
}
|
|
44
|
+
if ('resourceType' in resource) {
|
|
45
|
+
if (resource.resourceType !== 'organization' && resource.resourceType !== 'project') {
|
|
46
|
+
errors.push({ type: 'invalid_value', message: 'Robot resource type must be `organization` or `project`' });
|
|
47
|
+
}
|
|
48
|
+
if (!('resourceId' in resource)) {
|
|
49
|
+
errors.push({ type: 'missing_parameter', message: 'Robot resource ID is required when resource type is provided' });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if ('resourceId' in resource) {
|
|
53
|
+
if (typeof resource.resourceId !== 'string') {
|
|
54
|
+
errors.push({ type: 'invalid_type', message: 'Robot resource ID must be a string' });
|
|
55
|
+
}
|
|
56
|
+
if (!('resourceType' in resource)) {
|
|
57
|
+
errors.push({ type: 'missing_parameter', message: 'Robot resource type is required when resource ID is provided' });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return errors;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Validates that the given membership is a valid Robot Token membership.
|
|
64
|
+
* @param membership The membership to validate
|
|
65
|
+
* @internal
|
|
66
|
+
* @returns A list of validation errors
|
|
67
|
+
*/
|
|
68
|
+
export function validateRobotTokenMembership(membership) {
|
|
69
|
+
if (!membership)
|
|
70
|
+
return [{ type: 'invalid_value', message: 'Membership config must be provided' }];
|
|
71
|
+
if (typeof membership !== 'object')
|
|
72
|
+
return [{ type: 'invalid_type', message: 'Membership config must be an object' }];
|
|
73
|
+
const errors = [];
|
|
74
|
+
if (!('resourceType' in membership)) {
|
|
75
|
+
errors.push({ type: 'missing_parameter', message: 'Membership resource type is required' });
|
|
76
|
+
}
|
|
77
|
+
else if (membership.resourceType !== 'organization' && membership.resourceType !== 'project') {
|
|
78
|
+
errors.push({ type: 'invalid_value', message: 'Membership resource type must be `organization` or `project`' });
|
|
79
|
+
}
|
|
80
|
+
if (!('resourceId' in membership) || !membership.resourceId) {
|
|
81
|
+
errors.push({ type: 'missing_parameter', message: 'Membership resource ID is required' });
|
|
82
|
+
}
|
|
83
|
+
else if (typeof membership.resourceId !== 'string') {
|
|
84
|
+
errors.push({ type: 'invalid_type', message: 'Membership resource ID must be a string' });
|
|
85
|
+
}
|
|
86
|
+
if (!('roleNames' in membership)) {
|
|
87
|
+
errors.push({ type: 'missing_parameter', message: 'Membership role names array is required' });
|
|
88
|
+
}
|
|
89
|
+
else if (!Array.isArray(membership.roleNames)) {
|
|
90
|
+
errors.push({ type: 'invalid_type', message: 'Membership role names must be an array' });
|
|
91
|
+
}
|
|
92
|
+
else if (membership.roleNames.length === 0) {
|
|
93
|
+
errors.push({ type: 'invalid_value', message: 'Membership must have at least one role name' });
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
for (const roleName of membership.roleNames) {
|
|
97
|
+
if (!roleName || typeof roleName !== 'string') {
|
|
98
|
+
errors.push({ type: 'invalid_value', message: 'Membership role name must have at least one character' });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return errors;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=robotTokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"robotTokens.js","sourceRoot":"","sources":["../../src/validation/robotTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,gBAAgB,EAAC,MAAM,aAAa,CAAA;AAEjE;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAiB;IAClD,IAAI,CAAC,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,+BAA+B,EAAC,CAAC,CAAA;IACzF,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,gCAAgC,EAAC,CAAC,CAAA;IAE5G,MAAM,MAAM,GAAqB,gBAAgB,CAAC,QAAQ,EAAE,EAAC,gBAAgB,EAAE,IAAI,EAAC,CAAC,CAAA;IAErF,IAAI,CAAC,CAAC,MAAM,IAAI,QAAQ,CAA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AAC,CAAC,WAAW,IAAI,UAAU,CAAC,EAAE,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,yCAAyC,EAAC,CAAC,CAAA;IAC9F,CAAC;SAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAChD,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,wCAAwC,EAAC,CAAC,CAAA;IACxF,CAAC;SAAM,IAAI,UAAU,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7C,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,6CAA6C,EAAC,CAAC,CAAA;IAC9F,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,QAAQ,IAAI,UAAU,CAAC,SAAS,EAAE,CAAC;YAC5C,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBAC9C,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,uDAAuD,EAAC,CAAC,CAAA;YACxG,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @category Validation
|
|
6
|
-
* @returns A list of validation errors
|
|
7
|
-
*/
|
|
8
|
-
export declare function validateRobot(resource: unknown): BlueprintError[];
|
|
9
|
-
/**
|
|
10
|
-
* Validates that the given membership is a valid Robot membership.
|
|
11
|
-
* @param membership The membership to validate
|
|
12
|
-
* @internal
|
|
13
|
-
* @returns A list of validation errors
|
|
14
|
-
*/
|
|
15
|
-
export declare function validateRobotMembership(membership: unknown): BlueprintError[];
|
|
1
|
+
/** @deprecated Use {@link validateRobotToken} instead @hidden */
|
|
2
|
+
export { validateRobotToken as validateRobot } from './robotTokens.js';
|
|
3
|
+
/** @deprecated Use {@link validateRobotTokenMembership} instead @hidden */
|
|
4
|
+
export { validateRobotTokenMembership as validateRobotMembership } from './robotTokens.js';
|
|
@@ -1,104 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @returns A list of validation errors
|
|
7
|
-
*/
|
|
8
|
-
export function validateRobot(resource) {
|
|
9
|
-
if (!resource)
|
|
10
|
-
return [{ type: 'invalid_value', message: 'Robot config must be provided' }];
|
|
11
|
-
if (typeof resource !== 'object')
|
|
12
|
-
return [{ type: 'invalid_type', message: 'Robot config must be an object' }];
|
|
13
|
-
const errors = validateResource(resource, { projectContained: true });
|
|
14
|
-
if (!('name' in resource) || !resource.name) {
|
|
15
|
-
errors.push({ type: 'missing_parameter', message: 'Robot name is required' });
|
|
16
|
-
}
|
|
17
|
-
else if (typeof resource.name !== 'string') {
|
|
18
|
-
errors.push({ type: 'invalid_type', message: 'Robot name must be a string' });
|
|
19
|
-
}
|
|
20
|
-
if (!('type' in resource)) {
|
|
21
|
-
errors.push({ type: 'missing_parameter', message: 'Robot type is required' });
|
|
22
|
-
}
|
|
23
|
-
else if (resource.type !== 'sanity.access.robot') {
|
|
24
|
-
errors.push({ type: 'invalid_value', message: 'Robot type must be `sanity.access.robot`' });
|
|
25
|
-
}
|
|
26
|
-
if (!('label' in resource) || !resource.label) {
|
|
27
|
-
errors.push({ type: 'missing_parameter', message: 'Robot label is required' });
|
|
28
|
-
}
|
|
29
|
-
else if (typeof resource.label !== 'string') {
|
|
30
|
-
errors.push({ type: 'invalid_type', message: 'Robot label must be a string' });
|
|
31
|
-
}
|
|
32
|
-
if (!('memberships' in resource)) {
|
|
33
|
-
errors.push({ type: 'missing_parameter', message: 'Robot memberships array is required' });
|
|
34
|
-
}
|
|
35
|
-
else if (!Array.isArray(resource.memberships)) {
|
|
36
|
-
errors.push({ type: 'invalid_type', message: 'Robot memberships must be an array' });
|
|
37
|
-
}
|
|
38
|
-
else if (resource.memberships.length === 0) {
|
|
39
|
-
errors.push({ type: 'invalid_value', message: 'Robot must have at least one membership' });
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
errors.push(...resource.memberships.flatMap(validateRobotMembership));
|
|
43
|
-
}
|
|
44
|
-
if ('resourceType' in resource) {
|
|
45
|
-
if (resource.resourceType !== 'organization' && resource.resourceType !== 'project') {
|
|
46
|
-
errors.push({ type: 'invalid_value', message: 'Robot resource type must be `organization` or `project`' });
|
|
47
|
-
}
|
|
48
|
-
if (!('resourceId' in resource)) {
|
|
49
|
-
errors.push({ type: 'missing_parameter', message: 'Robot resource ID is required when resource type is provided' });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if ('resourceId' in resource) {
|
|
53
|
-
if (typeof resource.resourceId !== 'string') {
|
|
54
|
-
errors.push({ type: 'invalid_type', message: 'Robot resource ID must be a string' });
|
|
55
|
-
}
|
|
56
|
-
if (!('resourceType' in resource)) {
|
|
57
|
-
errors.push({ type: 'missing_parameter', message: 'Robot resource type is required when resource ID is provided' });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return errors;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Validates that the given membership is a valid Robot membership.
|
|
64
|
-
* @param membership The membership to validate
|
|
65
|
-
* @internal
|
|
66
|
-
* @returns A list of validation errors
|
|
67
|
-
*/
|
|
68
|
-
export function validateRobotMembership(membership) {
|
|
69
|
-
if (!membership)
|
|
70
|
-
return [{ type: 'invalid_value', message: 'Membership config must be provided' }];
|
|
71
|
-
if (typeof membership !== 'object')
|
|
72
|
-
return [{ type: 'invalid_type', message: 'Membership config must be an object' }];
|
|
73
|
-
const errors = [];
|
|
74
|
-
if (!('resourceType' in membership)) {
|
|
75
|
-
errors.push({ type: 'missing_parameter', message: 'Membership resource type is required' });
|
|
76
|
-
}
|
|
77
|
-
else if (membership.resourceType !== 'organization' && membership.resourceType !== 'project') {
|
|
78
|
-
errors.push({ type: 'invalid_value', message: 'Membership resource type must be `organization` or `project`' });
|
|
79
|
-
}
|
|
80
|
-
if (!('resourceId' in membership) || !membership.resourceId) {
|
|
81
|
-
errors.push({ type: 'missing_parameter', message: 'Membership resource ID is required' });
|
|
82
|
-
}
|
|
83
|
-
else if (typeof membership.resourceId !== 'string') {
|
|
84
|
-
errors.push({ type: 'invalid_type', message: 'Membership resource ID must be a string' });
|
|
85
|
-
}
|
|
86
|
-
if (!('roleNames' in membership)) {
|
|
87
|
-
errors.push({ type: 'missing_parameter', message: 'Membership role names array is required' });
|
|
88
|
-
}
|
|
89
|
-
else if (!Array.isArray(membership.roleNames)) {
|
|
90
|
-
errors.push({ type: 'invalid_type', message: 'Membership role names must be an array' });
|
|
91
|
-
}
|
|
92
|
-
else if (membership.roleNames.length === 0) {
|
|
93
|
-
errors.push({ type: 'invalid_value', message: 'Membership must have at least one role name' });
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
for (const roleName of membership.roleNames) {
|
|
97
|
-
if (!roleName || typeof roleName !== 'string') {
|
|
98
|
-
errors.push({ type: 'invalid_value', message: 'Membership role name must have at least one character' });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return errors;
|
|
103
|
-
}
|
|
1
|
+
// biome-ignore-all assist/source/organizeImports: sorting imports moves typedocs
|
|
2
|
+
/** @deprecated Use {@link validateRobotToken} instead @hidden */
|
|
3
|
+
export { validateRobotToken as validateRobot } from './robotTokens.js';
|
|
4
|
+
/** @deprecated Use {@link validateRobotTokenMembership} instead @hidden */
|
|
5
|
+
export { validateRobotTokenMembership as validateRobotMembership } from './robotTokens.js';
|
|
104
6
|
//# sourceMappingURL=robots.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"robots.js","sourceRoot":"","sources":["../../src/validation/robots.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"robots.js","sourceRoot":"","sources":["../../src/validation/robots.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAEjF,iEAAiE;AACjE,OAAO,EAAC,kBAAkB,IAAI,aAAa,EAAC,MAAM,kBAAkB,CAAA;AACpE,2EAA2E;AAC3E,OAAO,EAAC,4BAA4B,IAAI,uBAAuB,EAAC,MAAM,kBAAkB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/blueprints",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Helper methods and type definitions for Sanity Blueprints",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "rimraf dist && tsc",
|
|
38
38
|
"coverage": "vitest --coverage",
|
|
39
|
-
"docs:
|
|
40
|
-
"docs:watch": "npm run docs:
|
|
39
|
+
"docs:typedoc": "typedoc --options typedoc.json",
|
|
40
|
+
"docs:watch": "npm run docs:typedoc && open ./docs/html/index.html && npm run docs:typedoc -- --watch",
|
|
41
41
|
"lint": "biome check .",
|
|
42
42
|
"lint:write": "biome check --write .",
|
|
43
43
|
"posttest": "npm run lint",
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"typecheck": "tsc --noEmit --project tsconfig.test.json"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@biomejs/biome": "2.3.
|
|
52
|
+
"@biomejs/biome": "2.3.14",
|
|
53
53
|
"@types/node": "^20",
|
|
54
|
-
"@vitest/coverage-v8": "^4.0.
|
|
54
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
55
55
|
"rimraf": "^6.1.2",
|
|
56
56
|
"typedoc": "^0.28.16",
|
|
57
57
|
"typescript": "^5.9.3",
|
|
58
|
-
"vitest": "4.0.
|
|
58
|
+
"vitest": "4.0.18"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=20"
|
|
@@ -1,13 +1,50 @@
|
|
|
1
1
|
import {type Blueprint, type BlueprintModule, type BlueprintsApiConfig, validateBlueprint} from '../index.js'
|
|
2
2
|
import {runValidation} from '../utils/validation.js'
|
|
3
3
|
|
|
4
|
+
/*
|
|
5
|
+
* FUTURE example (move below @example when ready)
|
|
6
|
+
* @example With deployment API config
|
|
7
|
+
* ```ts
|
|
8
|
+
* defineBlueprint({
|
|
9
|
+
* resources: [
|
|
10
|
+
* defineCorsOrigin({
|
|
11
|
+
* name: 'cors-localhost',
|
|
12
|
+
* origin: 'http://localhost:3333'
|
|
13
|
+
* }),
|
|
14
|
+
* defineRole({
|
|
15
|
+
* name: 'role-ci',
|
|
16
|
+
* title: 'CI Role',
|
|
17
|
+
* appliesToRobots: true,
|
|
18
|
+
* permissions: []
|
|
19
|
+
* }),
|
|
20
|
+
* defineRobotToken({
|
|
21
|
+
* name: 'ci-robot',
|
|
22
|
+
* memberships: [{
|
|
23
|
+
* roleNames: ['$.resources.ci-role']}],
|
|
24
|
+
* }),
|
|
25
|
+
* ],
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
4
29
|
/**
|
|
5
30
|
* Define a Blueprint to manage Sanity resources
|
|
6
|
-
*
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
7
33
|
* defineBlueprint({
|
|
8
34
|
* resources: [
|
|
9
|
-
*
|
|
10
|
-
*
|
|
35
|
+
* defineCorsOrigin({
|
|
36
|
+
* name: 'localhost-origin',
|
|
37
|
+
* origin: 'http://localhost:3333',
|
|
38
|
+
* }),
|
|
39
|
+
* defineDocumentFunction({
|
|
40
|
+
* name: 'update-search-index',
|
|
41
|
+
* event: {
|
|
42
|
+
* on: ['create', 'update'],
|
|
43
|
+
* filter: "_type == 'post'",
|
|
44
|
+
* projection: "{_id, title, slug}",
|
|
45
|
+
* },
|
|
46
|
+
* }),
|
|
47
|
+
* ],
|
|
11
48
|
* })
|
|
12
49
|
* ```
|
|
13
50
|
* @param blueprintConfig The blueprint configuration
|
package/src/definers/cors.ts
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
import {type BlueprintCorsOriginConfig, type BlueprintCorsOriginResource, validateCorsOrigin} from '../index.js'
|
|
2
2
|
import {runValidation} from '../utils/validation.js'
|
|
3
3
|
|
|
4
|
+
/*
|
|
5
|
+
* FUTURE example (move below @example when ready)
|
|
6
|
+
* @example All options
|
|
7
|
+
* ```ts
|
|
8
|
+
* defineCorsOrigin({
|
|
9
|
+
* name: 'studio-cors',
|
|
10
|
+
* origin: 'https://my-studio.sanity.studio',
|
|
11
|
+
* allowCredentials: true,
|
|
12
|
+
* project: 'my-project-id',
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
4
16
|
/**
|
|
5
17
|
* Defines a CORS Origin to be managed in a Blueprint.
|
|
6
|
-
*
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
7
20
|
* defineCorsOrigin({
|
|
21
|
+
* name: 'my-cors-origin',
|
|
8
22
|
* origin: 'https://mydomain.com',
|
|
9
|
-
* allowCredentials: true
|
|
23
|
+
* allowCredentials: true,
|
|
10
24
|
* })
|
|
11
25
|
* ```
|
|
12
26
|
* @param parameters The CORS Origin configuration
|
|
13
27
|
* @public
|
|
14
28
|
* @beta Deploying CORS Origins via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
15
29
|
* @category Definers
|
|
30
|
+
* @expandType BlueprintCorsOriginConfig
|
|
16
31
|
* @returns The CORS Origin resource
|
|
17
32
|
*/
|
|
18
33
|
export function defineCorsOrigin(parameters: BlueprintCorsOriginConfig): BlueprintCorsOriginResource {
|
package/src/definers/datasets.ts
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import {type BlueprintDatasetConfig, type BlueprintDatasetResource, validateDataset} from '../index.js'
|
|
2
2
|
import {runValidation} from '../utils/validation.js'
|
|
3
3
|
|
|
4
|
+
/*
|
|
5
|
+
* FUTURE example (move below @example when ready)
|
|
6
|
+
* @example All options
|
|
7
|
+
* ```ts
|
|
8
|
+
* defineDataset({
|
|
9
|
+
* name: 'staging',
|
|
10
|
+
* datasetName: 'staging-v2',
|
|
11
|
+
* aclMode: 'private',
|
|
12
|
+
* project: 'my-project-id',
|
|
13
|
+
* lifecycle: {deletionPolicy: 'protect'},
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
4
17
|
/**
|
|
5
18
|
* Defines a Dataset to be managed in a Blueprint.
|
|
6
|
-
*
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
7
21
|
* defineDataset({
|
|
8
|
-
* name: '
|
|
22
|
+
* name: 'staging-dataset',
|
|
23
|
+
* datasetName: 'staging',
|
|
9
24
|
* })
|
|
10
25
|
* ```
|
|
11
26
|
* @param parameters The dataset configuration
|
|
@@ -13,6 +28,7 @@ import {runValidation} from '../utils/validation.js'
|
|
|
13
28
|
* @alpha Deploying Datasets via Blueprints is experimental. This feature is subject to breaking changes.
|
|
14
29
|
* @hidden
|
|
15
30
|
* @category Definers
|
|
31
|
+
* @expandType BlueprintDatasetConfig
|
|
16
32
|
* @returns The dataset resource
|
|
17
33
|
*/
|
|
18
34
|
export function defineDataset(parameters: BlueprintDatasetConfig): BlueprintDatasetResource {
|