@sanity/blueprints 0.8.0 → 0.10.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/dist/definers/functions.d.ts +23 -1
- package/dist/definers/functions.js +56 -4
- package/dist/definers/functions.js.map +1 -1
- package/dist/definers/resources.js.map +1 -1
- package/dist/types/functions.d.ts +21 -0
- package/dist/types/resources.d.ts +7 -1
- package/dist/types/webhooks.d.ts +1 -1
- package/dist/validation/functions.d.ts +1 -0
- package/dist/validation/functions.js +105 -0
- package/dist/validation/functions.js.map +1 -1
- package/dist/validation/resources.js +3 -2
- package/dist/validation/resources.js.map +1 -1
- package/package.json +6 -6
- package/src/definers/functions.ts +78 -3
- package/src/definers/resources.ts +1 -1
- package/src/types/functions.ts +25 -0
- package/src/types/resources.ts +7 -1
- package/src/types/webhooks.ts +1 -1
- package/src/validation/functions.ts +107 -0
- package/src/validation/resources.ts +4 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type BlueprintBaseFunctionResource, type BlueprintDocumentFunctionResource, type BlueprintDocumentFunctionResourceEvent, type BlueprintMediaLibraryAssetFunctionResource, type BlueprintMediaLibraryFunctionResourceEvent } from '../index.js';
|
|
1
|
+
import { type BlueprintBaseFunctionResource, type BlueprintDocumentFunctionResource, type BlueprintDocumentFunctionResourceEvent, type BlueprintMediaLibraryAssetFunctionResource, type BlueprintMediaLibraryFunctionResourceEvent, type BlueprintScheduleFunctionResource, type BlueprintScheduleFunctionResourceEvent } from '../index.js';
|
|
2
2
|
interface RequiredFunctionProperties {
|
|
3
3
|
name: string;
|
|
4
4
|
}
|
|
@@ -51,6 +51,28 @@ export declare function defineDocumentFunction(functionConfig: Partial<Blueprint
|
|
|
51
51
|
* @returns The validated media library asset function resource
|
|
52
52
|
*/
|
|
53
53
|
export declare function defineMediaLibraryAssetFunction(functionConfig: Partial<BlueprintMediaLibraryAssetFunctionResource> & RequiredFunctionProperties & Pick<BlueprintMediaLibraryAssetFunctionResource, 'event'> & Partial<BlueprintMediaLibraryFunctionResourceEvent>): BlueprintMediaLibraryAssetFunctionResource;
|
|
54
|
+
/**
|
|
55
|
+
* Defines a function that is triggered on a schedule.
|
|
56
|
+
* ```
|
|
57
|
+
* defineScheduleFunction({
|
|
58
|
+
* name: 'my-schedule-function',
|
|
59
|
+
* src: 'functions/schedule-function',
|
|
60
|
+
* memory: 3,
|
|
61
|
+
* timeout: 300,
|
|
62
|
+
* event: {
|
|
63
|
+
* minute: "0",
|
|
64
|
+
* hour: "0",
|
|
65
|
+
* dayOfMonth: "*",
|
|
66
|
+
* month: "*",
|
|
67
|
+
* dayOfWeek: "*",
|
|
68
|
+
* },
|
|
69
|
+
* })
|
|
70
|
+
* ```
|
|
71
|
+
* @beta
|
|
72
|
+
* @param functionConfig The configuration for the document function
|
|
73
|
+
* @returns The validated schedule function resource
|
|
74
|
+
*/
|
|
75
|
+
export declare function defineScheduleFunction(functionConfig: Partial<BlueprintScheduleFunctionResource> & RequiredFunctionProperties & Pick<BlueprintScheduleFunctionResource, 'event'> & Partial<BlueprintScheduleFunctionResourceEvent>): BlueprintScheduleFunctionResource;
|
|
54
76
|
/**
|
|
55
77
|
* Defines a base function resource with common properties.
|
|
56
78
|
* ```
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { validateDocumentFunction, validateFunction, validateMediaLibraryAssetFunction, } from '../index.js';
|
|
1
|
+
import { validateDocumentFunction, validateFunction, validateMediaLibraryAssetFunction, validateScheduleFunction, } from '../index.js';
|
|
2
2
|
import { runValidation } from '../utils/validation.js';
|
|
3
3
|
const BASE_EVENT_KEYS = new Set(['on', 'filter', 'projection', 'includeDrafts']);
|
|
4
4
|
const DOCUMENT_EVENT_KEYS = new Set(['includeAllVersions', 'resource', ...BASE_EVENT_KEYS.values()]);
|
|
5
5
|
const MEDIA_LIBRARY_EVENT_KEYS = new Set(['resource', ...BASE_EVENT_KEYS.values()]);
|
|
6
|
+
const SCHEDULE_EVENT_KEYS = new Set(['minute', 'hour', 'dayOfWeek', 'month', 'dayOfMonth', 'expression']);
|
|
6
7
|
export function defineDocumentFunction(functionConfig) {
|
|
7
|
-
let { name, src, event, timeout, memory, env, type, robotToken, ...maybeEvent } = functionConfig;
|
|
8
|
+
let { name, src, event, timeout, memory, env, type, robotToken, project, ...maybeEvent } = functionConfig;
|
|
8
9
|
if (!type)
|
|
9
10
|
type = 'sanity.function.document';
|
|
10
11
|
// event validation and normalization
|
|
@@ -29,6 +30,7 @@ export function defineDocumentFunction(functionConfig) {
|
|
|
29
30
|
memory,
|
|
30
31
|
env,
|
|
31
32
|
robotToken,
|
|
33
|
+
project,
|
|
32
34
|
}, {
|
|
33
35
|
skipValidation: true, // already done below
|
|
34
36
|
}),
|
|
@@ -62,7 +64,7 @@ export function defineDocumentFunction(functionConfig) {
|
|
|
62
64
|
* @returns The validated media library asset function resource
|
|
63
65
|
*/
|
|
64
66
|
export function defineMediaLibraryAssetFunction(functionConfig) {
|
|
65
|
-
let { name, src, event, timeout, memory, env, type, robotToken } = functionConfig;
|
|
67
|
+
let { name, src, event, timeout, memory, env, type, robotToken, project } = functionConfig;
|
|
66
68
|
if (!type)
|
|
67
69
|
type = 'sanity.function.media-library.asset';
|
|
68
70
|
const functionResource = {
|
|
@@ -73,6 +75,7 @@ export function defineMediaLibraryAssetFunction(functionConfig) {
|
|
|
73
75
|
memory,
|
|
74
76
|
env,
|
|
75
77
|
robotToken,
|
|
78
|
+
project,
|
|
76
79
|
}, {
|
|
77
80
|
skipValidation: true, // already done below
|
|
78
81
|
}),
|
|
@@ -82,6 +85,50 @@ export function defineMediaLibraryAssetFunction(functionConfig) {
|
|
|
82
85
|
runValidation(() => validateMediaLibraryAssetFunction(functionResource));
|
|
83
86
|
return functionResource;
|
|
84
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Defines a function that is triggered on a schedule.
|
|
90
|
+
* ```
|
|
91
|
+
* defineScheduleFunction({
|
|
92
|
+
* name: 'my-schedule-function',
|
|
93
|
+
* src: 'functions/schedule-function',
|
|
94
|
+
* memory: 3,
|
|
95
|
+
* timeout: 300,
|
|
96
|
+
* event: {
|
|
97
|
+
* minute: "0",
|
|
98
|
+
* hour: "0",
|
|
99
|
+
* dayOfMonth: "*",
|
|
100
|
+
* month: "*",
|
|
101
|
+
* dayOfWeek: "*",
|
|
102
|
+
* },
|
|
103
|
+
* })
|
|
104
|
+
* ```
|
|
105
|
+
* @beta
|
|
106
|
+
* @param functionConfig The configuration for the document function
|
|
107
|
+
* @returns The validated schedule function resource
|
|
108
|
+
*/
|
|
109
|
+
export function defineScheduleFunction(functionConfig) {
|
|
110
|
+
let { name, src, event, timeout, memory, env, type, timezone } = functionConfig;
|
|
111
|
+
if (!type)
|
|
112
|
+
type = 'sanity.function.cron';
|
|
113
|
+
const functionResource = {
|
|
114
|
+
...defineFunction({
|
|
115
|
+
name,
|
|
116
|
+
src,
|
|
117
|
+
timeout,
|
|
118
|
+
memory,
|
|
119
|
+
env,
|
|
120
|
+
}, {
|
|
121
|
+
skipValidation: true, // already done below
|
|
122
|
+
}),
|
|
123
|
+
type,
|
|
124
|
+
event: buildScheduleFunctionEvent(event),
|
|
125
|
+
};
|
|
126
|
+
if (timezone) {
|
|
127
|
+
functionResource.timezone = timezone;
|
|
128
|
+
}
|
|
129
|
+
runValidation(() => validateScheduleFunction(functionResource));
|
|
130
|
+
return functionResource;
|
|
131
|
+
}
|
|
85
132
|
/**
|
|
86
133
|
* Defines a base function resource with common properties.
|
|
87
134
|
* ```
|
|
@@ -100,7 +147,7 @@ export function defineMediaLibraryAssetFunction(functionConfig) {
|
|
|
100
147
|
* @returns The validated function resource
|
|
101
148
|
*/
|
|
102
149
|
export function defineFunction(functionConfig, options) {
|
|
103
|
-
let { name, src, timeout, memory, env, type, robotToken } = functionConfig;
|
|
150
|
+
let { name, src, timeout, memory, env, type, robotToken, project } = functionConfig;
|
|
104
151
|
// defaults
|
|
105
152
|
if (!src)
|
|
106
153
|
src = `functions/${name}`;
|
|
@@ -114,6 +161,7 @@ export function defineFunction(functionConfig, options) {
|
|
|
114
161
|
memory,
|
|
115
162
|
env,
|
|
116
163
|
robotToken,
|
|
164
|
+
project,
|
|
117
165
|
};
|
|
118
166
|
if (options?.skipValidation !== true)
|
|
119
167
|
runValidation(() => validateFunction(functionResource));
|
|
@@ -146,4 +194,8 @@ function buildMediaLibraryFunctionEvent(event) {
|
|
|
146
194
|
};
|
|
147
195
|
return fullEvent;
|
|
148
196
|
}
|
|
197
|
+
function buildScheduleFunctionEvent(event) {
|
|
198
|
+
const cleanEvent = Object.fromEntries(Object.entries(event).filter(([key]) => SCHEDULE_EVENT_KEYS.has(key)));
|
|
199
|
+
return cleanEvent;
|
|
200
|
+
}
|
|
149
201
|
//# sourceMappingURL=functions.js.map
|
|
@@ -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,EAWL,wBAAwB,EACxB,gBAAgB,EAChB,iCAAiC,EACjC,wBAAwB,GACzB,MAAM,aAAa,CAAA;AACpB,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,MA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iD;IACvF,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CACnC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,wBAAwB,CAAC,GAAG,CAAC,GAAmC,CAAC,CAAC,CAC7D,CAAA;IAE/C,MAAM,SAAS,GAAG;QAChB,EAAE,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC;QAChC,GAAG,UAAU;KACd,CAAA;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,SAAS,0BAA0B,CAAC,KAA6C;IAC/E,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CACnC,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;IAE3C,OAAO,UAAU,CAAA;AACnB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/definers/resources.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/definers/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAyB,MAAM,aAAa,CAAA;AAElE;;;;GAIG;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"}
|
|
@@ -28,6 +28,17 @@ export type BlueprintFunctionResourceEvent = BlueprintDocumentFunctionResourceEv
|
|
|
28
28
|
* Dataset resource for scoping document functions to specific datasets
|
|
29
29
|
* @example { type: 'dataset', id: 'my-project.production' }
|
|
30
30
|
*/
|
|
31
|
+
export interface BlueprintScheduleFunctionExplicitResourceEvent {
|
|
32
|
+
minute: string;
|
|
33
|
+
hour: string;
|
|
34
|
+
dayOfMonth: string;
|
|
35
|
+
month: string;
|
|
36
|
+
dayOfWeek: string;
|
|
37
|
+
}
|
|
38
|
+
export interface BlueprintScheduleFunctionExpressionResourceEvent {
|
|
39
|
+
expression: string;
|
|
40
|
+
}
|
|
41
|
+
export type BlueprintScheduleFunctionResourceEvent = BlueprintScheduleFunctionExplicitResourceEvent | BlueprintScheduleFunctionExpressionResourceEvent;
|
|
31
42
|
interface BlueprintFunctionResourceEventResourceDataset {
|
|
32
43
|
type: 'dataset';
|
|
33
44
|
/** @description A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
|
|
@@ -54,6 +65,11 @@ export interface BlueprintBaseFunctionResource extends BlueprintResource {
|
|
|
54
65
|
env?: Record<string, string>;
|
|
55
66
|
/** Token provided during function invocation */
|
|
56
67
|
robotToken?: string;
|
|
68
|
+
/**
|
|
69
|
+
* The project ID of the project that contains your function.
|
|
70
|
+
*
|
|
71
|
+
* The `project` attribute must be defined if your blueprint is scoped to an organization. */
|
|
72
|
+
project?: string;
|
|
57
73
|
}
|
|
58
74
|
/** A function resource triggered by document events in Sanity datasets */
|
|
59
75
|
export interface BlueprintDocumentFunctionResource extends BlueprintBaseFunctionResource {
|
|
@@ -67,4 +83,9 @@ export interface BlueprintMediaLibraryAssetFunctionResource extends BlueprintBas
|
|
|
67
83
|
/** Event configuration specifying when and how the function is triggered */
|
|
68
84
|
event: BlueprintMediaLibraryFunctionResourceEvent;
|
|
69
85
|
}
|
|
86
|
+
export interface BlueprintScheduleFunctionResource extends BlueprintBaseFunctionResource {
|
|
87
|
+
type: 'sanity.function.cron';
|
|
88
|
+
event: BlueprintScheduleFunctionResourceEvent;
|
|
89
|
+
timezone?: string;
|
|
90
|
+
}
|
|
70
91
|
export {};
|
|
@@ -15,10 +15,16 @@ export interface BlueprintOwnershipAttachAction {
|
|
|
15
15
|
/** The identifier of the resource to be attached to the current stack */
|
|
16
16
|
id: string;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* An ownership action that will cause the referenced resource to be detached from the current stack.
|
|
20
|
+
*/
|
|
21
|
+
export interface BlueprintOwnershipDetachAction {
|
|
22
|
+
type: 'detach';
|
|
23
|
+
}
|
|
18
24
|
/**
|
|
19
25
|
* A union of all possible ownership actions.
|
|
20
26
|
*/
|
|
21
|
-
export type BlueprintOwnershipAction = BlueprintOwnershipAttachAction;
|
|
27
|
+
export type BlueprintOwnershipAction = BlueprintOwnershipAttachAction | BlueprintOwnershipDetachAction;
|
|
22
28
|
/**
|
|
23
29
|
* An ownership action that will cause the referenced project-contained resource to be attached to the current stack.
|
|
24
30
|
*/
|
package/dist/types/webhooks.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface BlueprintDocumentWebhookResource extends BlueprintResource {
|
|
|
17
17
|
includeDrafts?: boolean;
|
|
18
18
|
includeAllVersions?: boolean;
|
|
19
19
|
secret?: string;
|
|
20
|
-
dataset
|
|
20
|
+
dataset: string;
|
|
21
21
|
apiVersion: string;
|
|
22
22
|
}
|
|
23
23
|
/** Configuration for a webhook */
|
|
@@ -20,3 +20,4 @@ export declare function validateMediaLibraryAssetFunction(functionResource: unkn
|
|
|
20
20
|
* @returns Array of validation errors, empty if valid
|
|
21
21
|
*/
|
|
22
22
|
export declare function validateFunction(functionResource: unknown): BlueprintError[];
|
|
23
|
+
export declare function validateScheduleFunction(functionResource: unknown): BlueprintError[];
|
|
@@ -156,4 +156,109 @@ function validateMediaLibraryFunctionEvent(event) {
|
|
|
156
156
|
}
|
|
157
157
|
return errors;
|
|
158
158
|
}
|
|
159
|
+
export function validateScheduleFunction(functionResource) {
|
|
160
|
+
if (!functionResource)
|
|
161
|
+
return [{ type: 'invalid_value', message: 'Function config must be provided' }];
|
|
162
|
+
if (typeof functionResource !== 'object')
|
|
163
|
+
return [{ type: 'invalid_type', message: 'Function config must be an object' }];
|
|
164
|
+
const errors = [];
|
|
165
|
+
if ('event' in functionResource) {
|
|
166
|
+
errors.push(...validateScheduleFunctionEvent(functionResource.event));
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
errors.push({ type: 'missing_parameter', message: '`event` is required for a schedule function' });
|
|
170
|
+
}
|
|
171
|
+
if ('type' in functionResource && functionResource.type !== 'sanity.function.cron') {
|
|
172
|
+
errors.push({ type: 'invalid_value', message: '`type` must be `sanity.function.cron`' });
|
|
173
|
+
}
|
|
174
|
+
if ('timezone' in functionResource) {
|
|
175
|
+
errors.push(...validateScheduleFunctionTimezone(functionResource.timezone));
|
|
176
|
+
}
|
|
177
|
+
errors.push(...validateFunction(functionResource));
|
|
178
|
+
return errors;
|
|
179
|
+
}
|
|
180
|
+
function validateScheduleFunctionEvent(event) {
|
|
181
|
+
if (!event)
|
|
182
|
+
return [{ type: 'invalid_value', message: 'Function event must be provided' }];
|
|
183
|
+
if (typeof event !== 'object')
|
|
184
|
+
return [{ type: 'invalid_type', message: 'Function event must be an object' }];
|
|
185
|
+
const errors = [];
|
|
186
|
+
const hasExpression = 'expression' in event;
|
|
187
|
+
const hasExplicitFields = 'minute' in event || 'hour' in event || 'dayOfMonth' in event || 'month' in event || 'dayOfWeek' in event;
|
|
188
|
+
if (hasExpression && hasExplicitFields) {
|
|
189
|
+
errors.push({
|
|
190
|
+
type: 'invalid_property',
|
|
191
|
+
message: 'Cannot specify both `expression` and explicit cron fields (`minute`, `hour`, `dayOfMonth`, `month`, `dayOfWeek`)',
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
else if (!hasExpression && !hasExplicitFields) {
|
|
195
|
+
errors.push({
|
|
196
|
+
type: 'missing_parameter',
|
|
197
|
+
message: 'Either `expression` or explicit cron fields (`minute`, `hour`, `dayOfMonth`, `month`, `dayOfWeek`) must be provided',
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
else if (hasExplicitFields) {
|
|
201
|
+
if (!('minute' in event)) {
|
|
202
|
+
errors.push({
|
|
203
|
+
type: 'missing_parameter',
|
|
204
|
+
message: '`minute` must be provided',
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
else if (typeof event.minute !== 'string') {
|
|
208
|
+
errors.push({ type: 'invalid_type', message: '`minute` must be a string' });
|
|
209
|
+
}
|
|
210
|
+
if (!('hour' in event)) {
|
|
211
|
+
errors.push({
|
|
212
|
+
type: 'missing_parameter',
|
|
213
|
+
message: '`hour` must be provided',
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
else if (typeof event.hour !== 'string') {
|
|
217
|
+
errors.push({ type: 'invalid_type', message: '`hour` must be a string' });
|
|
218
|
+
}
|
|
219
|
+
if (!('dayOfWeek' in event)) {
|
|
220
|
+
errors.push({
|
|
221
|
+
type: 'missing_parameter',
|
|
222
|
+
message: '`dayOfWeek` must be provided',
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
else if (typeof event.dayOfWeek !== 'string') {
|
|
226
|
+
errors.push({ type: 'invalid_type', message: '`dayOfWeek` must be a string' });
|
|
227
|
+
}
|
|
228
|
+
if (!('month' in event)) {
|
|
229
|
+
errors.push({
|
|
230
|
+
type: 'missing_parameter',
|
|
231
|
+
message: '`month` must be provided',
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
else if (typeof event.month !== 'string') {
|
|
235
|
+
errors.push({ type: 'invalid_type', message: '`month` must be a string' });
|
|
236
|
+
}
|
|
237
|
+
if (!('dayOfMonth' in event)) {
|
|
238
|
+
errors.push({
|
|
239
|
+
type: 'missing_parameter',
|
|
240
|
+
message: '`dayOfMonth` must be provided',
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
else if (typeof event.dayOfMonth !== 'string') {
|
|
244
|
+
errors.push({ type: 'invalid_type', message: '`dayOfMonth` must be a string' });
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return errors;
|
|
248
|
+
}
|
|
249
|
+
function validateScheduleFunctionTimezone(timezone) {
|
|
250
|
+
if (typeof timezone !== 'string')
|
|
251
|
+
return [{ type: 'invalid_type', message: 'Function timezone must be a string' }];
|
|
252
|
+
const errors = [];
|
|
253
|
+
try {
|
|
254
|
+
Intl.DateTimeFormat(undefined, { timeZone: timezone });
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
errors.push({
|
|
258
|
+
type: 'invalid_value',
|
|
259
|
+
message: '`timezone` must be a valid IANA timezone',
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
return errors;
|
|
263
|
+
}
|
|
159
264
|
//# sourceMappingURL=functions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/validation/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,gBAAgB,GACjB,MAAM,aAAa,CAAA;AAGpB,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;AAEjH;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,gBAAyB;IAChE,IAAI,CAAC,gBAAgB;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,kCAAkC,EAAC,CAAC,CAAA;IACpG,IAAI,OAAO,gBAAgB,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,mCAAmC,EAAC,CAAC,CAAA;IAEvH,MAAM,MAAM,GAAqB,gBAAgB,CAAC,gBAAgB,CAAC,CAAA;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C,EAAC,CAAC,CAAA;IAEhH,MAAM,MAAM,GAAqB,EAAE,CAAA;IAEnC,IAAI,CAAC;QACH,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,EAAC,QAAQ,EAAE,QAAQ,EAAC,CAAC,CAAA;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE,0CAA0C;SACpD,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -37,6 +37,7 @@ export function validateResource(resourceConfig, options) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
if ('ownershipAction' in resourceConfig.lifecycle) {
|
|
40
|
+
const ownershipActionTypes = ['attach', 'detach'];
|
|
40
41
|
const ownershipAction = resourceConfig.lifecycle.ownershipAction;
|
|
41
42
|
if (typeof ownershipAction !== 'object' || ownershipAction === null) {
|
|
42
43
|
errors.push({ type: 'invalid_type', message: '`ownershipAction` must be an object' });
|
|
@@ -47,8 +48,8 @@ export function validateResource(resourceConfig, options) {
|
|
|
47
48
|
else if (typeof ownershipAction.type !== 'string') {
|
|
48
49
|
errors.push({ type: 'invalid_type', message: '`ownershipAction.type` must be a string' });
|
|
49
50
|
}
|
|
50
|
-
else if (!
|
|
51
|
-
errors.push({ type: 'invalid_value', message:
|
|
51
|
+
else if (!ownershipActionTypes.includes(ownershipAction.type)) {
|
|
52
|
+
errors.push({ type: 'invalid_value', message: `\`ownershipAction.type\` must be one of ${ownershipActionTypes.join(', ')}` });
|
|
52
53
|
}
|
|
53
54
|
else {
|
|
54
55
|
if (ownershipAction.type === 'attach') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/validation/resources.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAEpD;;;;;GAKG;AACH,MAAM,UAAU,gBAAg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IAAI,CAAC,EAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,6CAA6C,EAAC,CAAC,CAAA;wBAClG,CAAC;6BAAM,IAAI,OAAO,eAAe,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;4BAClD,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,uCAAuC,EAAC,CAAC,CAAA;wBACvF,CAAC;wBAED,IAAI,OAAO,EAAE,gBAAgB,EAAE,CAAC;4BAC9B,IAAI,CAAC,CAAC,WAAW,IAAI,eAAe,CAAC,EAAE,CAAC;gCACtC,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,oDAAoD,EAAC,CAAC,CAAA;4BACzG,CAAC;iCAAM,IAAI,OAAO,eAAe,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;gCACzD,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,8CAA8C,EAAC,CAAC,CAAA;4BAC9F,CAAC;wBACH,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,QAAiB;IAC9C,aAAa,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAA;AACjD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/blueprints",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Helper methods and type definitions for Sanity Blueprints",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"typecheck": "tsc --noEmit --project tsconfig.test.json"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@biomejs/biome": "
|
|
50
|
+
"@biomejs/biome": "2.3.11",
|
|
51
51
|
"@types/node": "^20",
|
|
52
|
-
"@vitest/coverage-v8": "^
|
|
53
|
-
"rimraf": "^6.
|
|
54
|
-
"typescript": "^5.
|
|
55
|
-
"vitest": "
|
|
52
|
+
"@vitest/coverage-v8": "^4.0.17",
|
|
53
|
+
"rimraf": "^6.1.2",
|
|
54
|
+
"typescript": "^5.9.3",
|
|
55
|
+
"vitest": "4.0.17"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|
|
58
58
|
"node": ">=20"
|
|
@@ -5,9 +5,14 @@ import {
|
|
|
5
5
|
type BlueprintFunctionBaseResourceEvent,
|
|
6
6
|
type BlueprintMediaLibraryAssetFunctionResource,
|
|
7
7
|
type BlueprintMediaLibraryFunctionResourceEvent,
|
|
8
|
+
type BlueprintScheduleFunctionExplicitResourceEvent,
|
|
9
|
+
type BlueprintScheduleFunctionExpressionResourceEvent,
|
|
10
|
+
type BlueprintScheduleFunctionResource,
|
|
11
|
+
type BlueprintScheduleFunctionResourceEvent,
|
|
8
12
|
validateDocumentFunction,
|
|
9
13
|
validateFunction,
|
|
10
14
|
validateMediaLibraryAssetFunction,
|
|
15
|
+
validateScheduleFunction,
|
|
11
16
|
} from '../index.js'
|
|
12
17
|
import {runValidation} from '../utils/validation.js'
|
|
13
18
|
|
|
@@ -17,6 +22,10 @@ type DocumentFunctionEventKey = keyof BlueprintDocumentFunctionResourceEvent
|
|
|
17
22
|
const DOCUMENT_EVENT_KEYS = new Set<DocumentFunctionEventKey>(['includeAllVersions', 'resource', ...BASE_EVENT_KEYS.values()])
|
|
18
23
|
type MediaLibraryFunctionEventKey = keyof BlueprintMediaLibraryFunctionResourceEvent
|
|
19
24
|
const MEDIA_LIBRARY_EVENT_KEYS = new Set<MediaLibraryFunctionEventKey>(['resource', ...BASE_EVENT_KEYS.values()])
|
|
25
|
+
type ScheduleFunctionEventKey =
|
|
26
|
+
| keyof BlueprintScheduleFunctionExplicitResourceEvent
|
|
27
|
+
| keyof BlueprintScheduleFunctionExpressionResourceEvent
|
|
28
|
+
const SCHEDULE_EVENT_KEYS = new Set<ScheduleFunctionEventKey>(['minute', 'hour', 'dayOfWeek', 'month', 'dayOfMonth', 'expression'])
|
|
20
29
|
|
|
21
30
|
interface RequiredFunctionProperties {
|
|
22
31
|
name: string
|
|
@@ -56,7 +65,7 @@ export function defineDocumentFunction(
|
|
|
56
65
|
export function defineDocumentFunction(
|
|
57
66
|
functionConfig: Partial<BlueprintDocumentFunctionResource> & RequiredFunctionProperties & Partial<BlueprintDocumentFunctionResourceEvent>,
|
|
58
67
|
): BlueprintDocumentFunctionResource {
|
|
59
|
-
let {name, src, event, timeout, memory, env, type, robotToken, ...maybeEvent} = functionConfig
|
|
68
|
+
let {name, src, event, timeout, memory, env, type, robotToken, project, ...maybeEvent} = functionConfig
|
|
60
69
|
if (!type) type = 'sanity.function.document'
|
|
61
70
|
|
|
62
71
|
// event validation and normalization
|
|
@@ -87,6 +96,7 @@ export function defineDocumentFunction(
|
|
|
87
96
|
memory,
|
|
88
97
|
env,
|
|
89
98
|
robotToken,
|
|
99
|
+
project,
|
|
90
100
|
},
|
|
91
101
|
{
|
|
92
102
|
skipValidation: true, // already done below
|
|
@@ -130,7 +140,7 @@ export function defineMediaLibraryAssetFunction(
|
|
|
130
140
|
Pick<BlueprintMediaLibraryAssetFunctionResource, 'event'> &
|
|
131
141
|
Partial<BlueprintMediaLibraryFunctionResourceEvent>,
|
|
132
142
|
): BlueprintMediaLibraryAssetFunctionResource {
|
|
133
|
-
let {name, src, event, timeout, memory, env, type, robotToken} = functionConfig
|
|
143
|
+
let {name, src, event, timeout, memory, env, type, robotToken, project} = functionConfig
|
|
134
144
|
if (!type) type = 'sanity.function.media-library.asset'
|
|
135
145
|
|
|
136
146
|
const functionResource: BlueprintMediaLibraryAssetFunctionResource = {
|
|
@@ -142,6 +152,7 @@ export function defineMediaLibraryAssetFunction(
|
|
|
142
152
|
memory,
|
|
143
153
|
env,
|
|
144
154
|
robotToken,
|
|
155
|
+
project,
|
|
145
156
|
},
|
|
146
157
|
{
|
|
147
158
|
skipValidation: true, // already done below
|
|
@@ -156,6 +167,61 @@ export function defineMediaLibraryAssetFunction(
|
|
|
156
167
|
return functionResource
|
|
157
168
|
}
|
|
158
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Defines a function that is triggered on a schedule.
|
|
172
|
+
* ```
|
|
173
|
+
* defineScheduleFunction({
|
|
174
|
+
* name: 'my-schedule-function',
|
|
175
|
+
* src: 'functions/schedule-function',
|
|
176
|
+
* memory: 3,
|
|
177
|
+
* timeout: 300,
|
|
178
|
+
* event: {
|
|
179
|
+
* minute: "0",
|
|
180
|
+
* hour: "0",
|
|
181
|
+
* dayOfMonth: "*",
|
|
182
|
+
* month: "*",
|
|
183
|
+
* dayOfWeek: "*",
|
|
184
|
+
* },
|
|
185
|
+
* })
|
|
186
|
+
* ```
|
|
187
|
+
* @beta
|
|
188
|
+
* @param functionConfig The configuration for the document function
|
|
189
|
+
* @returns The validated schedule function resource
|
|
190
|
+
*/
|
|
191
|
+
export function defineScheduleFunction(
|
|
192
|
+
functionConfig: Partial<BlueprintScheduleFunctionResource> &
|
|
193
|
+
RequiredFunctionProperties &
|
|
194
|
+
Pick<BlueprintScheduleFunctionResource, 'event'> &
|
|
195
|
+
Partial<BlueprintScheduleFunctionResourceEvent>,
|
|
196
|
+
): BlueprintScheduleFunctionResource {
|
|
197
|
+
let {name, src, event, timeout, memory, env, type, timezone} = functionConfig
|
|
198
|
+
if (!type) type = 'sanity.function.cron'
|
|
199
|
+
|
|
200
|
+
const functionResource: BlueprintScheduleFunctionResource = {
|
|
201
|
+
...defineFunction(
|
|
202
|
+
{
|
|
203
|
+
name,
|
|
204
|
+
src,
|
|
205
|
+
timeout,
|
|
206
|
+
memory,
|
|
207
|
+
env,
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
skipValidation: true, // already done below
|
|
211
|
+
},
|
|
212
|
+
),
|
|
213
|
+
type,
|
|
214
|
+
event: buildScheduleFunctionEvent(event),
|
|
215
|
+
}
|
|
216
|
+
if (timezone) {
|
|
217
|
+
functionResource.timezone = timezone
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
runValidation(() => validateScheduleFunction(functionResource))
|
|
221
|
+
|
|
222
|
+
return functionResource
|
|
223
|
+
}
|
|
224
|
+
|
|
159
225
|
/**
|
|
160
226
|
* Defines a base function resource with common properties.
|
|
161
227
|
* ```
|
|
@@ -177,7 +243,7 @@ export function defineFunction(
|
|
|
177
243
|
functionConfig: Partial<BlueprintBaseFunctionResource> & RequiredFunctionProperties,
|
|
178
244
|
options?: {skipValidation?: boolean},
|
|
179
245
|
): BlueprintBaseFunctionResource {
|
|
180
|
-
let {name, src, timeout, memory, env, type, robotToken} = functionConfig
|
|
246
|
+
let {name, src, timeout, memory, env, type, robotToken, project} = functionConfig
|
|
181
247
|
|
|
182
248
|
// defaults
|
|
183
249
|
if (!src) src = `functions/${name}`
|
|
@@ -191,6 +257,7 @@ export function defineFunction(
|
|
|
191
257
|
memory,
|
|
192
258
|
env,
|
|
193
259
|
robotToken,
|
|
260
|
+
project,
|
|
194
261
|
}
|
|
195
262
|
|
|
196
263
|
if (options?.skipValidation !== true) runValidation(() => validateFunction(functionResource))
|
|
@@ -232,3 +299,11 @@ function buildMediaLibraryFunctionEvent(event: BlueprintMediaLibraryFunctionReso
|
|
|
232
299
|
}
|
|
233
300
|
return fullEvent
|
|
234
301
|
}
|
|
302
|
+
|
|
303
|
+
function buildScheduleFunctionEvent(event: BlueprintScheduleFunctionResourceEvent): BlueprintScheduleFunctionResourceEvent {
|
|
304
|
+
const cleanEvent = Object.fromEntries(
|
|
305
|
+
Object.entries(event).filter(([key]) => SCHEDULE_EVENT_KEYS.has(key as ScheduleFunctionEventKey)),
|
|
306
|
+
) as BlueprintScheduleFunctionResourceEvent
|
|
307
|
+
|
|
308
|
+
return cleanEvent
|
|
309
|
+
}
|
package/src/types/functions.ts
CHANGED
|
@@ -32,6 +32,20 @@ export type BlueprintFunctionResourceEvent = BlueprintDocumentFunctionResourceEv
|
|
|
32
32
|
* Dataset resource for scoping document functions to specific datasets
|
|
33
33
|
* @example { type: 'dataset', id: 'my-project.production' }
|
|
34
34
|
*/
|
|
35
|
+
export interface BlueprintScheduleFunctionExplicitResourceEvent {
|
|
36
|
+
minute: string
|
|
37
|
+
hour: string
|
|
38
|
+
dayOfMonth: string
|
|
39
|
+
month: string
|
|
40
|
+
dayOfWeek: string
|
|
41
|
+
}
|
|
42
|
+
export interface BlueprintScheduleFunctionExpressionResourceEvent {
|
|
43
|
+
expression: string
|
|
44
|
+
}
|
|
45
|
+
export type BlueprintScheduleFunctionResourceEvent =
|
|
46
|
+
| BlueprintScheduleFunctionExplicitResourceEvent
|
|
47
|
+
| BlueprintScheduleFunctionExpressionResourceEvent
|
|
48
|
+
|
|
35
49
|
interface BlueprintFunctionResourceEventResourceDataset {
|
|
36
50
|
type: 'dataset'
|
|
37
51
|
/** @description A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
|
|
@@ -62,6 +76,12 @@ export interface BlueprintBaseFunctionResource extends BlueprintResource {
|
|
|
62
76
|
env?: Record<string, string>
|
|
63
77
|
/** Token provided during function invocation */
|
|
64
78
|
robotToken?: string
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The project ID of the project that contains your function.
|
|
82
|
+
*
|
|
83
|
+
* The `project` attribute must be defined if your blueprint is scoped to an organization. */
|
|
84
|
+
project?: string
|
|
65
85
|
}
|
|
66
86
|
/** A function resource triggered by document events in Sanity datasets */
|
|
67
87
|
export interface BlueprintDocumentFunctionResource extends BlueprintBaseFunctionResource {
|
|
@@ -75,3 +95,8 @@ export interface BlueprintMediaLibraryAssetFunctionResource extends BlueprintBas
|
|
|
75
95
|
/** Event configuration specifying when and how the function is triggered */
|
|
76
96
|
event: BlueprintMediaLibraryFunctionResourceEvent
|
|
77
97
|
}
|
|
98
|
+
export interface BlueprintScheduleFunctionResource extends BlueprintBaseFunctionResource {
|
|
99
|
+
type: 'sanity.function.cron'
|
|
100
|
+
event: BlueprintScheduleFunctionResourceEvent
|
|
101
|
+
timezone?: string
|
|
102
|
+
}
|
package/src/types/resources.ts
CHANGED
|
@@ -16,10 +16,16 @@ export interface BlueprintOwnershipAttachAction {
|
|
|
16
16
|
/** The identifier of the resource to be attached to the current stack */
|
|
17
17
|
id: string
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* An ownership action that will cause the referenced resource to be detached from the current stack.
|
|
21
|
+
*/
|
|
22
|
+
export interface BlueprintOwnershipDetachAction {
|
|
23
|
+
type: 'detach'
|
|
24
|
+
}
|
|
19
25
|
/**
|
|
20
26
|
* A union of all possible ownership actions.
|
|
21
27
|
*/
|
|
22
|
-
export type BlueprintOwnershipAction = BlueprintOwnershipAttachAction
|
|
28
|
+
export type BlueprintOwnershipAction = BlueprintOwnershipAttachAction | BlueprintOwnershipDetachAction
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
31
|
* An ownership action that will cause the referenced project-contained resource to be attached to the current stack.
|
package/src/types/webhooks.ts
CHANGED
|
@@ -175,3 +175,110 @@ function validateMediaLibraryFunctionEvent(event: unknown): BlueprintError[] {
|
|
|
175
175
|
}
|
|
176
176
|
return errors
|
|
177
177
|
}
|
|
178
|
+
|
|
179
|
+
export function validateScheduleFunction(functionResource: unknown): BlueprintError[] {
|
|
180
|
+
if (!functionResource) return [{type: 'invalid_value', message: 'Function config must be provided'}]
|
|
181
|
+
if (typeof functionResource !== 'object') return [{type: 'invalid_type', message: 'Function config must be an object'}]
|
|
182
|
+
|
|
183
|
+
const errors: BlueprintError[] = []
|
|
184
|
+
|
|
185
|
+
if ('event' in functionResource) {
|
|
186
|
+
errors.push(...validateScheduleFunctionEvent(functionResource.event))
|
|
187
|
+
} else {
|
|
188
|
+
errors.push({type: 'missing_parameter', message: '`event` is required for a schedule function'})
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if ('type' in functionResource && functionResource.type !== 'sanity.function.cron') {
|
|
192
|
+
errors.push({type: 'invalid_value', message: '`type` must be `sanity.function.cron`'})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if ('timezone' in functionResource) {
|
|
196
|
+
errors.push(...validateScheduleFunctionTimezone(functionResource.timezone))
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
errors.push(...validateFunction(functionResource))
|
|
200
|
+
|
|
201
|
+
return errors
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function validateScheduleFunctionEvent(event: unknown): BlueprintError[] {
|
|
205
|
+
if (!event) return [{type: 'invalid_value', message: 'Function event must be provided'}]
|
|
206
|
+
if (typeof event !== 'object') return [{type: 'invalid_type', message: 'Function event must be an object'}]
|
|
207
|
+
|
|
208
|
+
const errors: BlueprintError[] = []
|
|
209
|
+
|
|
210
|
+
const hasExpression = 'expression' in event
|
|
211
|
+
const hasExplicitFields = 'minute' in event || 'hour' in event || 'dayOfMonth' in event || 'month' in event || 'dayOfWeek' in event
|
|
212
|
+
|
|
213
|
+
if (hasExpression && hasExplicitFields) {
|
|
214
|
+
errors.push({
|
|
215
|
+
type: 'invalid_property',
|
|
216
|
+
message: 'Cannot specify both `expression` and explicit cron fields (`minute`, `hour`, `dayOfMonth`, `month`, `dayOfWeek`)',
|
|
217
|
+
})
|
|
218
|
+
} else if (!hasExpression && !hasExplicitFields) {
|
|
219
|
+
errors.push({
|
|
220
|
+
type: 'missing_parameter',
|
|
221
|
+
message: 'Either `expression` or explicit cron fields (`minute`, `hour`, `dayOfMonth`, `month`, `dayOfWeek`) must be provided',
|
|
222
|
+
})
|
|
223
|
+
} else if (hasExplicitFields) {
|
|
224
|
+
if (!('minute' in event)) {
|
|
225
|
+
errors.push({
|
|
226
|
+
type: 'missing_parameter',
|
|
227
|
+
message: '`minute` must be provided',
|
|
228
|
+
})
|
|
229
|
+
} else if (typeof event.minute !== 'string') {
|
|
230
|
+
errors.push({type: 'invalid_type', message: '`minute` must be a string'})
|
|
231
|
+
}
|
|
232
|
+
if (!('hour' in event)) {
|
|
233
|
+
errors.push({
|
|
234
|
+
type: 'missing_parameter',
|
|
235
|
+
message: '`hour` must be provided',
|
|
236
|
+
})
|
|
237
|
+
} else if (typeof event.hour !== 'string') {
|
|
238
|
+
errors.push({type: 'invalid_type', message: '`hour` must be a string'})
|
|
239
|
+
}
|
|
240
|
+
if (!('dayOfWeek' in event)) {
|
|
241
|
+
errors.push({
|
|
242
|
+
type: 'missing_parameter',
|
|
243
|
+
message: '`dayOfWeek` must be provided',
|
|
244
|
+
})
|
|
245
|
+
} else if (typeof event.dayOfWeek !== 'string') {
|
|
246
|
+
errors.push({type: 'invalid_type', message: '`dayOfWeek` must be a string'})
|
|
247
|
+
}
|
|
248
|
+
if (!('month' in event)) {
|
|
249
|
+
errors.push({
|
|
250
|
+
type: 'missing_parameter',
|
|
251
|
+
message: '`month` must be provided',
|
|
252
|
+
})
|
|
253
|
+
} else if (typeof event.month !== 'string') {
|
|
254
|
+
errors.push({type: 'invalid_type', message: '`month` must be a string'})
|
|
255
|
+
}
|
|
256
|
+
if (!('dayOfMonth' in event)) {
|
|
257
|
+
errors.push({
|
|
258
|
+
type: 'missing_parameter',
|
|
259
|
+
message: '`dayOfMonth` must be provided',
|
|
260
|
+
})
|
|
261
|
+
} else if (typeof event.dayOfMonth !== 'string') {
|
|
262
|
+
errors.push({type: 'invalid_type', message: '`dayOfMonth` must be a string'})
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return errors
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function validateScheduleFunctionTimezone(timezone: unknown): BlueprintError[] {
|
|
270
|
+
if (typeof timezone !== 'string') return [{type: 'invalid_type', message: 'Function timezone must be a string'}]
|
|
271
|
+
|
|
272
|
+
const errors: BlueprintError[] = []
|
|
273
|
+
|
|
274
|
+
try {
|
|
275
|
+
Intl.DateTimeFormat(undefined, {timeZone: timezone})
|
|
276
|
+
} catch {
|
|
277
|
+
errors.push({
|
|
278
|
+
type: 'invalid_value',
|
|
279
|
+
message: '`timezone` must be a valid IANA timezone',
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return errors
|
|
284
|
+
}
|
|
@@ -38,15 +38,17 @@ export function validateResource(resourceConfig: unknown, options?: {projectCont
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if ('ownershipAction' in resourceConfig.lifecycle) {
|
|
41
|
+
const ownershipActionTypes = ['attach', 'detach']
|
|
41
42
|
const ownershipAction = resourceConfig.lifecycle.ownershipAction
|
|
43
|
+
|
|
42
44
|
if (typeof ownershipAction !== 'object' || ownershipAction === null) {
|
|
43
45
|
errors.push({type: 'invalid_type', message: '`ownershipAction` must be an object'})
|
|
44
46
|
} else if (!('type' in ownershipAction)) {
|
|
45
47
|
errors.push({type: 'missing_parameter', message: '`ownershipAction.type` is required'})
|
|
46
48
|
} else if (typeof ownershipAction.type !== 'string') {
|
|
47
49
|
errors.push({type: 'invalid_type', message: '`ownershipAction.type` must be a string'})
|
|
48
|
-
} else if (!
|
|
49
|
-
errors.push({type: 'invalid_value', message:
|
|
50
|
+
} else if (!ownershipActionTypes.includes(ownershipAction.type)) {
|
|
51
|
+
errors.push({type: 'invalid_value', message: `\`ownershipAction.type\` must be one of ${ownershipActionTypes.join(', ')}`})
|
|
50
52
|
} else {
|
|
51
53
|
if (ownershipAction.type === 'attach') {
|
|
52
54
|
if (!('id' in ownershipAction)) {
|