@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
|
@@ -1,125 +1,101 @@
|
|
|
1
|
-
import { type BlueprintBaseFunctionResource, type BlueprintDocumentFunctionResource, type BlueprintDocumentFunctionResourceEvent, type
|
|
2
|
-
/** @internal */
|
|
3
|
-
export interface RequiredFunctionProperties {
|
|
4
|
-
name: string;
|
|
5
|
-
}
|
|
1
|
+
import { type BlueprintBaseFunctionConfig, type BlueprintBaseFunctionResource, type BlueprintDocumentFunctionConfig, type BlueprintDocumentFunctionResource, type BlueprintDocumentFunctionResourceEvent, type BlueprintMediaLibraryAssetFunctionConfig, type BlueprintMediaLibraryAssetFunctionResource, type BlueprintScheduleFunctionConfig, type BlueprintScheduleFunctionResource } from '../index.js';
|
|
6
2
|
/**
|
|
7
3
|
* Defines a function that is triggered by document events in Sanity datasets.
|
|
8
|
-
*
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
9
6
|
* defineDocumentFunction({
|
|
10
7
|
* name: 'my-document-function',
|
|
11
|
-
* src: 'functions/my-function',
|
|
12
|
-
* memory: 3,
|
|
13
|
-
* timeout: 300,
|
|
14
8
|
* event: {
|
|
15
9
|
* on: ['create', 'update'],
|
|
16
|
-
* filter: "_type == '
|
|
17
|
-
* projection: "{
|
|
18
|
-
* includeDrafts: false,
|
|
19
|
-
* },
|
|
20
|
-
* env: {
|
|
21
|
-
* MY_ENV_VAR: 'custom-value',
|
|
10
|
+
* filter: "_type == 'post'",
|
|
11
|
+
* projection: "{_id, title, slug}",
|
|
22
12
|
* },
|
|
23
13
|
* })
|
|
24
14
|
* ```
|
|
25
15
|
* @param functionConfig The configuration for the document function
|
|
26
16
|
* @public
|
|
27
17
|
* @category Definers
|
|
18
|
+
* @expandType BlueprintDocumentFunctionConfig
|
|
28
19
|
* @returns The validated document function resource
|
|
29
20
|
*/
|
|
30
|
-
export declare function defineDocumentFunction(functionConfig:
|
|
31
|
-
/**
|
|
32
|
-
|
|
21
|
+
export declare function defineDocumentFunction(functionConfig: BlueprintDocumentFunctionConfig): BlueprintDocumentFunctionResource;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Define event properties under the 'event' key instead of specifying them at the top level
|
|
24
|
+
* @hidden
|
|
25
|
+
*/
|
|
26
|
+
export declare function defineDocumentFunction(functionConfig: BlueprintDocumentFunctionConfig & Partial<BlueprintDocumentFunctionResourceEvent>): BlueprintDocumentFunctionResource;
|
|
33
27
|
/**
|
|
34
28
|
* Defines a function that is triggered by media library events.
|
|
35
|
-
*
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
36
31
|
* defineMediaLibraryAssetFunction({
|
|
37
32
|
* name: 'my-media-library-function',
|
|
38
|
-
* src: 'functions/media-library-function',
|
|
39
33
|
* event: {
|
|
40
|
-
* on: ['create'
|
|
34
|
+
* on: ['create'],
|
|
41
35
|
* resource: {
|
|
42
36
|
* type: 'media-library',
|
|
43
37
|
* id: 'my-media-library-id',
|
|
44
38
|
* },
|
|
45
|
-
* filter: "type == 'my-type'",
|
|
46
|
-
* projection: "{_id}",
|
|
47
|
-
* },
|
|
48
|
-
* env: {
|
|
49
|
-
* MY_ENV_VAR: 'custom-value',
|
|
50
39
|
* },
|
|
51
40
|
* })
|
|
52
41
|
* ```
|
|
53
42
|
* @param functionConfig The configuration for the media library asset function
|
|
54
43
|
* @public
|
|
55
44
|
* @category Definers
|
|
45
|
+
* @expandType BlueprintMediaLibraryAssetFunctionConfig
|
|
56
46
|
* @returns The validated media library asset function resource
|
|
57
47
|
*/
|
|
58
|
-
export declare function defineMediaLibraryAssetFunction(functionConfig:
|
|
48
|
+
export declare function defineMediaLibraryAssetFunction(functionConfig: BlueprintMediaLibraryAssetFunctionConfig): BlueprintMediaLibraryAssetFunctionResource;
|
|
59
49
|
/**
|
|
60
50
|
* Defines a function that is triggered on a schedule.
|
|
61
51
|
* Supports cron expressions or natural language schedules.
|
|
62
52
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* Using a cron expression:
|
|
55
|
+
* ```ts
|
|
65
56
|
* defineScheduleFunction({
|
|
66
57
|
* name: 'daily-cleanup',
|
|
67
58
|
* event: {expression: '0 9 * * *'},
|
|
68
59
|
* })
|
|
60
|
+
* ```
|
|
69
61
|
*
|
|
70
|
-
*
|
|
62
|
+
* Using explicit cron fields:
|
|
63
|
+
* ```ts
|
|
71
64
|
* defineScheduleFunction({
|
|
72
|
-
* name: 'daily-
|
|
73
|
-
* event: {
|
|
65
|
+
* name: 'daily-cleanup',
|
|
66
|
+
* event: {minute: '0', hour: '9', dayOfMonth: '*', month: '*', dayOfWeek: '*'},
|
|
74
67
|
* })
|
|
68
|
+
* ```
|
|
75
69
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* // 'fridays in the evening'
|
|
80
|
-
* // 'mon, wed, fri at 9am'
|
|
81
|
-
* // 'first of the month at noon'
|
|
70
|
+
* The `event.expression` field accepts standard cron expressions or natural language:
|
|
71
|
+
* `'every 15 minutes'`, `'weekdays at 8am'`, `'fridays in the evening'`,
|
|
72
|
+
* `'mon, wed, fri at 9am'`, `'first of the month at noon'`
|
|
82
73
|
*
|
|
83
|
-
*
|
|
74
|
+
* ```ts
|
|
84
75
|
* defineScheduleFunction({
|
|
85
|
-
* name: '
|
|
86
|
-
* event: {
|
|
87
|
-
* minute: '0',
|
|
88
|
-
* hour: '9',
|
|
89
|
-
* dayOfMonth: '*',
|
|
90
|
-
* month: '*',
|
|
91
|
-
* dayOfWeek: '*',
|
|
92
|
-
* },
|
|
76
|
+
* name: 'daily-cleanup',
|
|
77
|
+
* event: {expression: 'every day at 9am'},
|
|
93
78
|
* })
|
|
94
79
|
* ```
|
|
95
80
|
* @public
|
|
96
81
|
* @alpha Deploying Schedule Functions via Blueprints is experimental. This feature is not available publicly yet.
|
|
97
82
|
* @hidden
|
|
98
83
|
* @category Definers
|
|
84
|
+
* @expandType BlueprintScheduleFunctionConfig
|
|
99
85
|
* @param functionConfig The configuration for the schedule function
|
|
100
86
|
* @returns The validated schedule function resource
|
|
101
87
|
*/
|
|
102
|
-
export declare function defineScheduleFunction(functionConfig:
|
|
88
|
+
export declare function defineScheduleFunction(functionConfig: BlueprintScheduleFunctionConfig): BlueprintScheduleFunctionResource;
|
|
103
89
|
/**
|
|
104
90
|
* Defines a base function resource with common properties.
|
|
105
|
-
*
|
|
106
|
-
* defineFunction({
|
|
107
|
-
* name: 'my-function',
|
|
108
|
-
* src: 'functions/my-function',
|
|
109
|
-
* timeout: 300,
|
|
110
|
-
* memory: 1,
|
|
111
|
-
* runtime: 'nodejs24.x',
|
|
112
|
-
* env: {
|
|
113
|
-
* MY_ENV_VAR: 'my-custom-value'
|
|
114
|
-
* },
|
|
115
|
-
* })
|
|
116
|
-
* ```
|
|
91
|
+
*
|
|
117
92
|
* @param functionConfig The configuration for the function
|
|
118
93
|
* @param options Optional configuration including validation options
|
|
119
94
|
* @category Definers
|
|
120
95
|
* @internal
|
|
96
|
+
* @expandType BlueprintBaseFunctionConfig
|
|
121
97
|
* @returns The validated function resource
|
|
122
98
|
*/
|
|
123
|
-
export declare function defineFunction(functionConfig:
|
|
99
|
+
export declare function defineFunction(functionConfig: BlueprintBaseFunctionConfig, options?: {
|
|
124
100
|
skipValidation?: boolean;
|
|
125
101
|
}): BlueprintBaseFunctionResource;
|
|
@@ -6,9 +6,7 @@ const DOCUMENT_EVENT_KEYS = new Set(['includeAllVersions', 'resource', ...BASE_E
|
|
|
6
6
|
const MEDIA_LIBRARY_EVENT_KEYS = new Set(['resource', ...BASE_EVENT_KEYS.values()]);
|
|
7
7
|
const SCHEDULE_EVENT_KEYS = new Set(['minute', 'hour', 'dayOfWeek', 'month', 'dayOfMonth', 'expression']);
|
|
8
8
|
export function defineDocumentFunction(functionConfig) {
|
|
9
|
-
let { name, src, event, timeout, memory, env,
|
|
10
|
-
if (!type)
|
|
11
|
-
type = 'sanity.function.document';
|
|
9
|
+
let { name, src, event, timeout, memory, env, robotToken, project, runtime, ...maybeEvent } = functionConfig;
|
|
12
10
|
// event validation and normalization
|
|
13
11
|
if (event) {
|
|
14
12
|
// `event` was specified, but event keys (aggregated in `maybeEvent`) were also specified at the top level. ambiguous and deprecated usage.
|
|
@@ -24,67 +22,71 @@ export function defineDocumentFunction(functionConfig) {
|
|
|
24
22
|
console.warn('⚠️ Deprecated usage of `defineDocumentFunction`: prefer to put `event` properties under the `event` key rather than at the top level.');
|
|
25
23
|
}
|
|
26
24
|
const functionResource = {
|
|
27
|
-
...defineFunction({
|
|
28
|
-
|
|
29
|
-
src,
|
|
30
|
-
timeout,
|
|
31
|
-
memory,
|
|
32
|
-
env,
|
|
33
|
-
robotToken,
|
|
34
|
-
project,
|
|
35
|
-
runtime,
|
|
36
|
-
}, {
|
|
37
|
-
skipValidation: true, // already done below
|
|
38
|
-
}),
|
|
39
|
-
type,
|
|
25
|
+
...defineFunction(functionConfig, { skipValidation: true }),
|
|
26
|
+
type: 'sanity.function.document',
|
|
40
27
|
event,
|
|
41
28
|
};
|
|
42
29
|
runValidation(() => validateDocumentFunction(functionResource));
|
|
43
30
|
return functionResource;
|
|
44
31
|
}
|
|
45
|
-
|
|
46
|
-
*
|
|
47
|
-
*
|
|
32
|
+
/*
|
|
33
|
+
* FUTURE example (move below @example when ready)
|
|
34
|
+
* @example With robot token reference
|
|
35
|
+
* ```ts
|
|
36
|
+
* defineRobotToken({
|
|
37
|
+
* name: 'media-robot',
|
|
38
|
+
* memberships: [{
|
|
39
|
+
* resourceType: 'project',
|
|
40
|
+
* resourceId: projectId,
|
|
41
|
+
* roleNames: ['editor'],
|
|
42
|
+
* }],
|
|
43
|
+
* })
|
|
44
|
+
*
|
|
48
45
|
* defineMediaLibraryAssetFunction({
|
|
49
|
-
* name: '
|
|
50
|
-
* src: 'functions/
|
|
46
|
+
* name: 'process-uploads',
|
|
47
|
+
* src: 'functions/process-uploads-v2',
|
|
48
|
+
* robotToken: '$.resources.media-robot',
|
|
51
49
|
* event: {
|
|
52
50
|
* on: ['create', 'update'],
|
|
53
51
|
* resource: {
|
|
54
52
|
* type: 'media-library',
|
|
55
53
|
* id: 'my-media-library-id',
|
|
56
54
|
* },
|
|
57
|
-
* filter: "type == '
|
|
55
|
+
* filter: "type == 'image'",
|
|
58
56
|
* projection: "{_id}",
|
|
59
57
|
* },
|
|
60
58
|
* env: {
|
|
61
|
-
*
|
|
59
|
+
* CDN_BUCKET: 'my-cdn-bucket',
|
|
60
|
+
* },
|
|
61
|
+
* })
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* Defines a function that is triggered by media library events.
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* defineMediaLibraryAssetFunction({
|
|
69
|
+
* name: 'my-media-library-function',
|
|
70
|
+
* event: {
|
|
71
|
+
* on: ['create'],
|
|
72
|
+
* resource: {
|
|
73
|
+
* type: 'media-library',
|
|
74
|
+
* id: 'my-media-library-id',
|
|
75
|
+
* },
|
|
62
76
|
* },
|
|
63
77
|
* })
|
|
64
78
|
* ```
|
|
65
79
|
* @param functionConfig The configuration for the media library asset function
|
|
66
80
|
* @public
|
|
67
81
|
* @category Definers
|
|
82
|
+
* @expandType BlueprintMediaLibraryAssetFunctionConfig
|
|
68
83
|
* @returns The validated media library asset function resource
|
|
69
84
|
*/
|
|
70
85
|
export function defineMediaLibraryAssetFunction(functionConfig) {
|
|
71
|
-
|
|
72
|
-
if (!type)
|
|
73
|
-
type = 'sanity.function.media-library.asset';
|
|
86
|
+
const { event } = functionConfig;
|
|
74
87
|
const functionResource = {
|
|
75
|
-
...defineFunction({
|
|
76
|
-
|
|
77
|
-
src,
|
|
78
|
-
timeout,
|
|
79
|
-
memory,
|
|
80
|
-
env,
|
|
81
|
-
robotToken,
|
|
82
|
-
project,
|
|
83
|
-
runtime,
|
|
84
|
-
}, {
|
|
85
|
-
skipValidation: true, // already done below
|
|
86
|
-
}),
|
|
87
|
-
type,
|
|
88
|
+
...defineFunction(functionConfig, { skipValidation: true }),
|
|
89
|
+
type: 'sanity.function.media-library.asset',
|
|
88
90
|
event: buildMediaLibraryFunctionEvent(event),
|
|
89
91
|
};
|
|
90
92
|
runValidation(() => validateMediaLibraryAssetFunction(functionResource));
|
|
@@ -94,66 +96,50 @@ export function defineMediaLibraryAssetFunction(functionConfig) {
|
|
|
94
96
|
* Defines a function that is triggered on a schedule.
|
|
95
97
|
* Supports cron expressions or natural language schedules.
|
|
96
98
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* Using a cron expression:
|
|
101
|
+
* ```ts
|
|
99
102
|
* defineScheduleFunction({
|
|
100
103
|
* name: 'daily-cleanup',
|
|
101
104
|
* event: {expression: '0 9 * * *'},
|
|
102
105
|
* })
|
|
106
|
+
* ```
|
|
103
107
|
*
|
|
104
|
-
*
|
|
108
|
+
* Using explicit cron fields:
|
|
109
|
+
* ```ts
|
|
105
110
|
* defineScheduleFunction({
|
|
106
|
-
* name: 'daily-
|
|
107
|
-
* event: {
|
|
111
|
+
* name: 'daily-cleanup',
|
|
112
|
+
* event: {minute: '0', hour: '9', dayOfMonth: '*', month: '*', dayOfWeek: '*'},
|
|
108
113
|
* })
|
|
114
|
+
* ```
|
|
109
115
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* // 'fridays in the evening'
|
|
114
|
-
* // 'mon, wed, fri at 9am'
|
|
115
|
-
* // 'first of the month at noon'
|
|
116
|
+
* The `event.expression` field accepts standard cron expressions or natural language:
|
|
117
|
+
* `'every 15 minutes'`, `'weekdays at 8am'`, `'fridays in the evening'`,
|
|
118
|
+
* `'mon, wed, fri at 9am'`, `'first of the month at noon'`
|
|
116
119
|
*
|
|
117
|
-
*
|
|
120
|
+
* ```ts
|
|
118
121
|
* defineScheduleFunction({
|
|
119
|
-
* name: '
|
|
120
|
-
* event: {
|
|
121
|
-
* minute: '0',
|
|
122
|
-
* hour: '9',
|
|
123
|
-
* dayOfMonth: '*',
|
|
124
|
-
* month: '*',
|
|
125
|
-
* dayOfWeek: '*',
|
|
126
|
-
* },
|
|
122
|
+
* name: 'daily-cleanup',
|
|
123
|
+
* event: {expression: 'every day at 9am'},
|
|
127
124
|
* })
|
|
128
125
|
* ```
|
|
129
126
|
* @public
|
|
130
127
|
* @alpha Deploying Schedule Functions via Blueprints is experimental. This feature is not available publicly yet.
|
|
131
128
|
* @hidden
|
|
132
129
|
* @category Definers
|
|
130
|
+
* @expandType BlueprintScheduleFunctionConfig
|
|
133
131
|
* @param functionConfig The configuration for the schedule function
|
|
134
132
|
* @returns The validated schedule function resource
|
|
135
133
|
*/
|
|
136
134
|
export function defineScheduleFunction(functionConfig) {
|
|
137
|
-
|
|
138
|
-
if (!type)
|
|
139
|
-
type = 'sanity.function.cron';
|
|
135
|
+
const { event, timezone } = functionConfig;
|
|
140
136
|
const functionResource = {
|
|
141
|
-
...defineFunction({
|
|
142
|
-
|
|
143
|
-
src,
|
|
144
|
-
timeout,
|
|
145
|
-
memory,
|
|
146
|
-
env,
|
|
147
|
-
runtime,
|
|
148
|
-
}, {
|
|
149
|
-
skipValidation: true, // already done below
|
|
150
|
-
}),
|
|
151
|
-
type,
|
|
137
|
+
...defineFunction(functionConfig, { skipValidation: true }),
|
|
138
|
+
type: 'sanity.function.cron',
|
|
152
139
|
event: buildScheduleFunctionEvent(event),
|
|
153
140
|
};
|
|
154
|
-
if (timezone)
|
|
141
|
+
if (timezone)
|
|
155
142
|
functionResource.timezone = timezone;
|
|
156
|
-
}
|
|
157
143
|
runValidation(() => validateScheduleFunction(functionResource));
|
|
158
144
|
// Parse expression after validation (validation ensures it's valid)
|
|
159
145
|
if ('expression' in functionResource.event && functionResource.event.expression) {
|
|
@@ -163,35 +149,21 @@ export function defineScheduleFunction(functionConfig) {
|
|
|
163
149
|
}
|
|
164
150
|
/**
|
|
165
151
|
* Defines a base function resource with common properties.
|
|
166
|
-
*
|
|
167
|
-
* defineFunction({
|
|
168
|
-
* name: 'my-function',
|
|
169
|
-
* src: 'functions/my-function',
|
|
170
|
-
* timeout: 300,
|
|
171
|
-
* memory: 1,
|
|
172
|
-
* runtime: 'nodejs24.x',
|
|
173
|
-
* env: {
|
|
174
|
-
* MY_ENV_VAR: 'my-custom-value'
|
|
175
|
-
* },
|
|
176
|
-
* })
|
|
177
|
-
* ```
|
|
152
|
+
*
|
|
178
153
|
* @param functionConfig The configuration for the function
|
|
179
154
|
* @param options Optional configuration including validation options
|
|
180
155
|
* @category Definers
|
|
181
156
|
* @internal
|
|
157
|
+
* @expandType BlueprintBaseFunctionConfig
|
|
182
158
|
* @returns The validated function resource
|
|
183
159
|
*/
|
|
184
160
|
export function defineFunction(functionConfig, options) {
|
|
185
|
-
|
|
186
|
-
// defaults
|
|
187
|
-
if (!src)
|
|
188
|
-
src = `functions/${name}`;
|
|
189
|
-
if (!type)
|
|
190
|
-
type = 'sanity.function.document';
|
|
161
|
+
const { name, displayName, src, timeout, memory, env, robotToken, project, runtime, lifecycle } = functionConfig;
|
|
191
162
|
const functionResource = {
|
|
192
|
-
type,
|
|
163
|
+
type: 'sanity.function.document',
|
|
193
164
|
name,
|
|
194
|
-
src
|
|
165
|
+
src: src ?? `functions/${name}`,
|
|
166
|
+
displayName,
|
|
195
167
|
timeout,
|
|
196
168
|
memory,
|
|
197
169
|
env,
|
|
@@ -199,6 +171,8 @@ export function defineFunction(functionConfig, options) {
|
|
|
199
171
|
project,
|
|
200
172
|
runtime,
|
|
201
173
|
};
|
|
174
|
+
if (lifecycle)
|
|
175
|
+
functionResource.lifecycle = lifecycle;
|
|
202
176
|
if (options?.skipValidation !== true)
|
|
203
177
|
runValidation(() => validateFunction(functionResource));
|
|
204
178
|
return functionResource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/definers/functions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/definers/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAeL,wBAAwB,EACxB,gBAAgB,EAChB,iCAAiC,EACjC,wBAAwB,GACzB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAC,uBAAuB,EAAC,MAAM,6BAA6B,CAAA;AACnE,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAGpD,MAAM,eAAe,GAAG,IAAI,GAAG,CAAuB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC,CAAA;AAEtG,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAA2B,CAAC,oBAAoB,EAAE,UAAU,EAAE,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;AAE9H,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAA+B,CAAC,UAAU,EAAE,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;AAIjH,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAA2B,CAAC,QAAQ,EAAE,MAAM,EAAE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AU,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC;QAChC,GAAG,UAAU;KACd,CAAA;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;;;GAKG;AACH,SAAS,0BAA0B,CAAC,KAA6C;IAC/E,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAA+B,CAAC,CAAC,CACxD,CAAA;AAC7C,CAAC"}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { type BlueprintResource } from '../index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Defines a generic resource to be managed in Blueprints.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
4
6
|
* This is useful if the resource type does not yet have a `define*` function.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* defineResource({
|
|
10
|
+
* name: 'my-resource',
|
|
11
|
+
* type: 'sanity.new.resource',
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
5
14
|
* @param resourceConfig The resource configuration
|
|
6
15
|
* @category Definers
|
|
16
|
+
* @expandType BlueprintResource
|
|
7
17
|
* @internal
|
|
8
18
|
*/
|
|
9
19
|
export declare function defineResource(resourceConfig: Partial<BlueprintResource>): BlueprintResource;
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { assertResource } from '../index.js';
|
|
2
|
+
/*
|
|
3
|
+
* FUTURE example (move below @example when ready)
|
|
4
|
+
* @example With lifecycle
|
|
5
|
+
* ```ts
|
|
6
|
+
* defineResource({
|
|
7
|
+
* name: 'my-resource',
|
|
8
|
+
* type: 'sanity.new.resource',
|
|
9
|
+
* lifecycle: {deletionPolicy: 'retain'},
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
2
13
|
/**
|
|
3
14
|
* Defines a generic resource to be managed in Blueprints.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
4
17
|
* This is useful if the resource type does not yet have a `define*` function.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* defineResource({
|
|
21
|
+
* name: 'my-resource',
|
|
22
|
+
* type: 'sanity.new.resource',
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
5
25
|
* @param resourceConfig The resource configuration
|
|
6
26
|
* @category Definers
|
|
27
|
+
* @expandType BlueprintResource
|
|
7
28
|
* @internal
|
|
8
29
|
*/
|
|
9
30
|
export function defineResource(resourceConfig) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/definers/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAyB,MAAM,aAAa,CAAA;AAElE
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/definers/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAyB,MAAM,aAAa,CAAA;AAElE;;;;;;;;;;GAUG;AACH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,cAAc,CAAC,cAA0C;IACvE,MAAM,QAAQ,GAAG;QACf,GAAG,cAAc;KAClB,CAAA;IAED,cAAc,CAAC,QAAQ,CAAC,CAAA;IAExB,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type BlueprintRobotTokenConfig, type BlueprintRobotTokenResource } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Defines a Robot Token for automated access. Has a token property provided during deployment that can be referenced by other resources.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* defineRobotToken({
|
|
7
|
+
* name: 'my-robot',
|
|
8
|
+
* memberships: [{
|
|
9
|
+
* resourceType: 'project',
|
|
10
|
+
* resourceId: projectId,
|
|
11
|
+
* roleNames: ['editor'],
|
|
12
|
+
* }],
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
* @param parameters The robot token configuration
|
|
16
|
+
* @public
|
|
17
|
+
* @beta Deploying Robot Tokens via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
18
|
+
* @category Definers
|
|
19
|
+
* @expandType BlueprintRobotTokenConfig
|
|
20
|
+
* @returns The robot token resource
|
|
21
|
+
*/
|
|
22
|
+
export declare function defineRobotToken(parameters: BlueprintRobotTokenConfig): BlueprintRobotTokenResource;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { validateRobotToken } from '../index.js';
|
|
2
|
+
import { runValidation } from '../utils/validation.js';
|
|
3
|
+
/*
|
|
4
|
+
* FUTURE example (move below @example when ready)
|
|
5
|
+
* @example Cross-resource references
|
|
6
|
+
* ```ts
|
|
7
|
+
* defineRole({
|
|
8
|
+
* name: 'ci-deploy-role',
|
|
9
|
+
* title: 'CI Deploy Role',
|
|
10
|
+
* appliesToRobots: true,
|
|
11
|
+
* permissions: [{name: 'sanity-project-cors', action: 'create'}],
|
|
12
|
+
* })
|
|
13
|
+
*
|
|
14
|
+
* defineRobotToken({
|
|
15
|
+
* name: 'ci-robot',
|
|
16
|
+
* label: 'CI Deploy Robot',
|
|
17
|
+
* memberships: [{
|
|
18
|
+
* roleNames: ['$.resources.ci-deploy-role'],
|
|
19
|
+
* }],
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Defines a Robot Token for automated access. Has a token property provided during deployment that can be referenced by other resources.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* defineRobotToken({
|
|
28
|
+
* name: 'my-robot',
|
|
29
|
+
* memberships: [{
|
|
30
|
+
* resourceType: 'project',
|
|
31
|
+
* resourceId: projectId,
|
|
32
|
+
* roleNames: ['editor'],
|
|
33
|
+
* }],
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
* @param parameters The robot token configuration
|
|
37
|
+
* @public
|
|
38
|
+
* @beta Deploying Robot Tokens via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
39
|
+
* @category Definers
|
|
40
|
+
* @expandType BlueprintRobotTokenConfig
|
|
41
|
+
* @returns The robot token resource
|
|
42
|
+
*/
|
|
43
|
+
export function defineRobotToken(parameters) {
|
|
44
|
+
const label = parameters.label || parameters.name;
|
|
45
|
+
const robotResource = {
|
|
46
|
+
...parameters,
|
|
47
|
+
label,
|
|
48
|
+
type: 'sanity.access.robot',
|
|
49
|
+
};
|
|
50
|
+
runValidation(() => validateRobotToken(robotResource));
|
|
51
|
+
return robotResource;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=robotTokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"robotTokens.js","sourceRoot":"","sources":["../../src/definers/robotTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmE,kBAAkB,EAAC,MAAM,aAAa,CAAA;AAChH,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;GAmBG;AACH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAqC;IACpE,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,IAAI,CAAA;IAEjD,MAAM,aAAa,GAAgC;QACjD,GAAG,UAAU;QACb,KAAK;QACL,IAAI,EAAE,qBAAqB;KAC5B,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC,CAAA;IAEtD,OAAO,aAAa,CAAA;AACtB,CAAC"}
|
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Defines a Robot token for automated access. Has a token property provided during deployment that can be referenced by other resources.
|
|
4
|
-
* ```
|
|
5
|
-
* defineRobot({
|
|
6
|
-
* name: 'my-robot',
|
|
7
|
-
* label: 'My Robot',
|
|
8
|
-
* memberships: [{
|
|
9
|
-
* resourceType: 'project',
|
|
10
|
-
* resourceId: projectId,
|
|
11
|
-
* roleNames: ['custom-robot-role'],
|
|
12
|
-
* }],
|
|
13
|
-
* })
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @param parameters The robot configuration
|
|
17
|
-
* @public
|
|
18
|
-
* @beta Deploying Robots via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
19
|
-
* @category Definers
|
|
20
|
-
* @returns The robot resource
|
|
21
|
-
*/
|
|
22
|
-
export declare function defineRobot(parameters: BlueprintRobotConfig): BlueprintRobotResource;
|
|
1
|
+
/** @deprecated Use {@link defineRobotToken} instead @hidden */
|
|
2
|
+
export { defineRobotToken as defineRobot } from './robotTokens.js';
|
package/dist/definers/robots.js
CHANGED
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Defines a Robot token for automated access. Has a token property provided during deployment that can be referenced by other resources.
|
|
5
|
-
* ```
|
|
6
|
-
* defineRobot({
|
|
7
|
-
* name: 'my-robot',
|
|
8
|
-
* label: 'My Robot',
|
|
9
|
-
* memberships: [{
|
|
10
|
-
* resourceType: 'project',
|
|
11
|
-
* resourceId: projectId,
|
|
12
|
-
* roleNames: ['custom-robot-role'],
|
|
13
|
-
* }],
|
|
14
|
-
* })
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @param parameters The robot configuration
|
|
18
|
-
* @public
|
|
19
|
-
* @beta Deploying Robots via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
20
|
-
* @category Definers
|
|
21
|
-
* @returns The robot resource
|
|
22
|
-
*/
|
|
23
|
-
export function defineRobot(parameters) {
|
|
24
|
-
// default robot label
|
|
25
|
-
const label = parameters.label || parameters.name;
|
|
26
|
-
const robotResource = {
|
|
27
|
-
...parameters,
|
|
28
|
-
label,
|
|
29
|
-
type: 'sanity.access.robot',
|
|
30
|
-
};
|
|
31
|
-
runValidation(() => validateRobot(robotResource));
|
|
32
|
-
return robotResource;
|
|
33
|
-
}
|
|
1
|
+
/** @deprecated Use {@link defineRobotToken} instead @hidden */
|
|
2
|
+
export { defineRobotToken as defineRobot } from './robotTokens.js';
|
|
34
3
|
//# sourceMappingURL=robots.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"robots.js","sourceRoot":"","sources":["../../src/definers/robots.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"robots.js","sourceRoot":"","sources":["../../src/definers/robots.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,OAAO,EAAC,gBAAgB,IAAI,WAAW,EAAC,MAAM,kBAAkB,CAAA"}
|