@sanity/blueprints 0.24.0 → 0.26.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/applications.d.ts +164 -0
- package/dist/definers/applications.js +211 -0
- package/dist/definers/applications.js.map +1 -0
- package/dist/definers/installation-config.d.ts +26 -0
- package/dist/definers/installation-config.js +36 -0
- package/dist/definers/installation-config.js.map +1 -0
- package/dist/definers/studios.d.ts +1 -1
- package/dist/definers/studios.js +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/types/applications.d.ts +290 -0
- package/dist/types/applications.js +25 -0
- package/dist/types/applications.js.map +1 -0
- package/dist/types/installation-config.d.ts +75 -0
- package/dist/types/installation-config.js +2 -0
- package/dist/types/installation-config.js.map +1 -0
- package/dist/types/projects.d.ts +1 -1
- package/dist/types/robotTokens.d.ts +1 -1
- package/dist/types/studios.d.ts +2 -2
- package/dist/utils/validation.d.ts +1 -1
- package/dist/validation/applications.d.ts +58 -0
- package/dist/validation/applications.js +308 -0
- package/dist/validation/applications.js.map +1 -0
- package/dist/validation/installation-config.d.ts +18 -0
- package/dist/validation/installation-config.js +110 -0
- package/dist/validation/installation-config.js.map +1 -0
- package/dist/validation/studios.js +4 -4
- package/dist/validation/studios.js.map +1 -1
- package/package.json +4 -4
- package/src/definers/applications.ts +237 -0
- package/src/definers/installation-config.ts +38 -0
- package/src/definers/studios.ts +1 -1
- package/src/index.ts +6 -0
- package/src/types/applications.ts +337 -0
- package/src/types/installation-config.ts +86 -0
- package/src/types/projects.ts +1 -1
- package/src/types/robotTokens.ts +1 -1
- package/src/types/studios.ts +2 -2
- package/src/utils/validation.ts +1 -1
- package/src/validation/applications.ts +330 -0
- package/src/validation/installation-config.ts +115 -0
- package/src/validation/studios.ts +4 -4
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type {BlueprintResource} from '../index.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fields shared by every singleton installation config resource.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The backend selects a provider from the resource `type`
|
|
8
|
+
* (`sanity.installation.config`), so every installation config shares that one
|
|
9
|
+
* type and is discriminated by `appType`.
|
|
10
|
+
* @beta This feature is subject to breaking changes.
|
|
11
|
+
* @category Resource Types
|
|
12
|
+
* @hidden
|
|
13
|
+
*/
|
|
14
|
+
export interface BlueprintInstallationConfigResourceBase extends BlueprintResource {
|
|
15
|
+
type: 'sanity.installation.config'
|
|
16
|
+
|
|
17
|
+
/** The installation this config targets. Discriminates the config shape. */
|
|
18
|
+
appType: string
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The config build directory, relative to the blueprint file. Contains the
|
|
22
|
+
* config's `package.json`; every field `src` is resolved relative to it.
|
|
23
|
+
*/
|
|
24
|
+
root: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* One custom field a Media Library configuration exposes.
|
|
29
|
+
* @beta This feature is subject to breaking changes.
|
|
30
|
+
* @category Resource Types
|
|
31
|
+
* @hidden
|
|
32
|
+
*/
|
|
33
|
+
export interface BlueprintMediaLibraryField {
|
|
34
|
+
/** Unique within the Media Library config. */
|
|
35
|
+
name: string
|
|
36
|
+
|
|
37
|
+
/** Human-readable title for the field. */
|
|
38
|
+
title: string
|
|
39
|
+
|
|
40
|
+
/** The location of the field source code, relative to `root`. */
|
|
41
|
+
src: string
|
|
42
|
+
|
|
43
|
+
/** Readable outside the owning organization. */
|
|
44
|
+
public?: boolean
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Represents a singleton Media Library configuration resource.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* The Media Library is a Sanity-owned singleton, so this resource carries no
|
|
52
|
+
* application identity of its own — it only names the target `appType`, the
|
|
53
|
+
* config `root`, and its `fields`. The provider resolves the organization's
|
|
54
|
+
* media library installation id at deploy time.
|
|
55
|
+
* @beta This feature is subject to breaking changes.
|
|
56
|
+
* @category Resource Types
|
|
57
|
+
* @hidden
|
|
58
|
+
*/
|
|
59
|
+
export interface BlueprintMediaLibraryConfigResource extends BlueprintInstallationConfigResourceBase {
|
|
60
|
+
/** The target installation this config applies to. Set by the definer. */
|
|
61
|
+
appType: 'media-library'
|
|
62
|
+
|
|
63
|
+
/** The custom fields the Media Library config exposes. */
|
|
64
|
+
fields: BlueprintMediaLibraryField[]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A union of every singleton installation config resource, discriminated by `appType`.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* Media Library is the only member today; additional installation configs are
|
|
72
|
+
* added to this union.
|
|
73
|
+
* @beta This feature is subject to breaking changes.
|
|
74
|
+
* @category Resource Types
|
|
75
|
+
* @hidden
|
|
76
|
+
*/
|
|
77
|
+
export type BlueprintInstallationConfigResource = BlueprintMediaLibraryConfigResource
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Configuration for a singleton Media Library configuration resource.
|
|
81
|
+
* @beta This feature is subject to breaking changes.
|
|
82
|
+
* @category Resource Types
|
|
83
|
+
* @interface
|
|
84
|
+
* @hidden
|
|
85
|
+
*/
|
|
86
|
+
export type BlueprintMediaLibraryConfigConfig = Omit<BlueprintMediaLibraryConfigResource, 'type' | 'appType'>
|
package/src/types/projects.ts
CHANGED
package/src/types/robotTokens.ts
CHANGED
package/src/types/studios.ts
CHANGED
|
@@ -36,8 +36,8 @@ export type ApplicationVisibility = (typeof APPLICATION_VISIBILITIES)[number]
|
|
|
36
36
|
export interface BlueprintStudioResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
|
|
37
37
|
type: 'sanity.studio'
|
|
38
38
|
|
|
39
|
-
/** The relative location of the studio
|
|
40
|
-
|
|
39
|
+
/** The relative location of the studio directory. */
|
|
40
|
+
root: string
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* The project ID of the project that contains your Studio.
|
package/src/utils/validation.ts
CHANGED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import {APPLICATION_DOCK_GROUPS, APPLICATION_TILE_SIZES} from '../types/applications.js'
|
|
2
|
+
import type {BlueprintError} from '../types/errors.js'
|
|
3
|
+
import {APPLICATION_VISIBILITIES} from '../types/studios.js'
|
|
4
|
+
import {isReference} from '../utils/validation.js'
|
|
5
|
+
import {validateResource} from './resources.js'
|
|
6
|
+
|
|
7
|
+
/** hostname validity pattern */
|
|
8
|
+
const APPLICATION_SLUG_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/
|
|
9
|
+
|
|
10
|
+
/** view/worker name pattern */
|
|
11
|
+
const VIEW_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/
|
|
12
|
+
|
|
13
|
+
/** absolute path: POSIX `/…`, Windows `C:\…`/`C:/…`, or UNC `\\…` */
|
|
14
|
+
const ABSOLUTE_PATH_PATTERN = /^(?:[/\\]|[a-zA-Z]:[/\\])/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether a path stays within the directory it is resolved against, i.e. it is
|
|
18
|
+
* relative and never climbs above its starting point.
|
|
19
|
+
* @param path The path to check
|
|
20
|
+
* @hidden
|
|
21
|
+
* @category Validation
|
|
22
|
+
* @returns true when the path is relative and does not escape its root
|
|
23
|
+
*/
|
|
24
|
+
export function isContainedRelativePath(path: string): boolean {
|
|
25
|
+
if (ABSOLUTE_PATH_PATTERN.test(path)) return false
|
|
26
|
+
|
|
27
|
+
let depth = 0
|
|
28
|
+
for (const segment of path.split(/[/\\]/)) {
|
|
29
|
+
if (segment === '..') depth--
|
|
30
|
+
else if (segment !== '' && segment !== '.') depth++
|
|
31
|
+
if (depth < 0) return false
|
|
32
|
+
}
|
|
33
|
+
return true
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Validates the fields shared by every application view and web worker.
|
|
38
|
+
* @param view The view or web worker
|
|
39
|
+
* @param label The human-readable label used in error messages (e.g. `Window view`)
|
|
40
|
+
* @returns A list of validation errors
|
|
41
|
+
*/
|
|
42
|
+
function validateViewBase(view: object, label: string): BlueprintError[] {
|
|
43
|
+
const errors: BlueprintError[] = []
|
|
44
|
+
|
|
45
|
+
if (!('name' in view) || !view.name) {
|
|
46
|
+
errors.push({type: 'missing_parameter', message: `${label} name is required`})
|
|
47
|
+
} else if (typeof view.name !== 'string') {
|
|
48
|
+
errors.push({type: 'invalid_type', message: `${label} name must be a string`})
|
|
49
|
+
} else if (!isReference(view.name) && !VIEW_NAME_PATTERN.test(view.name)) {
|
|
50
|
+
errors.push({type: 'invalid_format', message: `${label} name must match pattern: ${VIEW_NAME_PATTERN.source}`})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!('title' in view) || !view.title) {
|
|
54
|
+
errors.push({type: 'missing_parameter', message: `${label} title is required`})
|
|
55
|
+
} else if (typeof view.title !== 'string') {
|
|
56
|
+
errors.push({type: 'invalid_type', message: `${label} title must be a string`})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!('src' in view) || !view.src) {
|
|
60
|
+
errors.push({type: 'missing_parameter', message: `${label} src is required`})
|
|
61
|
+
} else if (typeof view.src !== 'string') {
|
|
62
|
+
errors.push({type: 'invalid_type', message: `${label} src must be a string`})
|
|
63
|
+
} else if (!isReference(view.src) && !isContainedRelativePath(view.src)) {
|
|
64
|
+
errors.push({type: 'invalid_value', message: `${label} src must be a relative path within the application root`})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return errors
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Validates the optional `dock` placement of a window view.
|
|
72
|
+
* @param view The window view
|
|
73
|
+
* @param label The human-readable label used in error messages
|
|
74
|
+
* @returns A list of validation errors
|
|
75
|
+
*/
|
|
76
|
+
function validateDockField(view: object, label: string): BlueprintError[] {
|
|
77
|
+
if (!('dock' in view) || typeof view.dock === 'undefined') return []
|
|
78
|
+
|
|
79
|
+
if (typeof view.dock !== 'object' || view.dock === null) {
|
|
80
|
+
return [{type: 'invalid_type', message: `${label} dock must be an object`}]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const errors: BlueprintError[] = []
|
|
84
|
+
if ('group' in view.dock) {
|
|
85
|
+
const group = view.dock.group
|
|
86
|
+
if (typeof group !== 'string') {
|
|
87
|
+
errors.push({type: 'invalid_type', message: `${label} dock.group must be a string`})
|
|
88
|
+
} else if (!APPLICATION_DOCK_GROUPS.some((g) => g === group)) {
|
|
89
|
+
errors.push({type: 'invalid_value', message: `${label} dock.group must be one of ${APPLICATION_DOCK_GROUPS.join(', ')}`})
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if ('order' in view.dock && typeof view.dock.order !== 'number') {
|
|
93
|
+
errors.push({type: 'invalid_type', message: `${label} dock.order must be a number`})
|
|
94
|
+
}
|
|
95
|
+
return errors
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Validates the `size` and optional `order` of a tile view.
|
|
100
|
+
* @param view The tile view
|
|
101
|
+
* @param label The human-readable label used in error messages
|
|
102
|
+
* @returns A list of validation errors
|
|
103
|
+
*/
|
|
104
|
+
function validateTileFields(view: object, label: string): BlueprintError[] {
|
|
105
|
+
const errors: BlueprintError[] = []
|
|
106
|
+
|
|
107
|
+
if (!('size' in view) || !view.size) {
|
|
108
|
+
errors.push({type: 'missing_parameter', message: `${label} size is required`})
|
|
109
|
+
} else if (!APPLICATION_TILE_SIZES.some((size) => size === view.size)) {
|
|
110
|
+
errors.push({type: 'invalid_value', message: `${label} size must be one of ${APPLICATION_TILE_SIZES.join(', ')}`})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if ('order' in view && typeof view.order !== 'number') {
|
|
114
|
+
errors.push({type: 'invalid_type', message: `${label} order must be a number`})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return errors
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Validates that the given resource is a valid window view.
|
|
122
|
+
* @param resource The window view
|
|
123
|
+
* @hidden
|
|
124
|
+
* @category Validation
|
|
125
|
+
* @returns A list of validation errors
|
|
126
|
+
*/
|
|
127
|
+
export function validateWindowView(resource: unknown): BlueprintError[] {
|
|
128
|
+
if (!resource) return [{type: 'invalid_value', message: 'Window view config must be provided'}]
|
|
129
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Window view config must be an object'}]
|
|
130
|
+
|
|
131
|
+
const errors: BlueprintError[] = validateViewBase(resource, 'Window view')
|
|
132
|
+
|
|
133
|
+
if ('type' in resource && resource.type !== 'app') {
|
|
134
|
+
errors.push({type: 'invalid_value', message: 'Window view type must be `app`'})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
errors.push(...validateDockField(resource, 'Window view'))
|
|
138
|
+
|
|
139
|
+
return errors
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Validates that the given resource is a valid panel view.
|
|
144
|
+
* @param resource The panel view
|
|
145
|
+
* @hidden
|
|
146
|
+
* @category Validation
|
|
147
|
+
* @returns A list of validation errors
|
|
148
|
+
*/
|
|
149
|
+
export function validatePanelView(resource: unknown): BlueprintError[] {
|
|
150
|
+
if (!resource) return [{type: 'invalid_value', message: 'Panel view config must be provided'}]
|
|
151
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Panel view config must be an object'}]
|
|
152
|
+
|
|
153
|
+
const errors: BlueprintError[] = validateViewBase(resource, 'Panel view')
|
|
154
|
+
|
|
155
|
+
if ('type' in resource && resource.type !== 'panel') {
|
|
156
|
+
errors.push({type: 'invalid_value', message: 'Panel view type must be `panel`'})
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return errors
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Validates that the given resource is a valid asset source view.
|
|
164
|
+
* @param resource The asset source view
|
|
165
|
+
* @hidden
|
|
166
|
+
* @category Validation
|
|
167
|
+
* @returns A list of validation errors
|
|
168
|
+
*/
|
|
169
|
+
export function validateAssetSourceView(resource: unknown): BlueprintError[] {
|
|
170
|
+
if (!resource) return [{type: 'invalid_value', message: 'Asset source view config must be provided'}]
|
|
171
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Asset source view config must be an object'}]
|
|
172
|
+
|
|
173
|
+
const errors: BlueprintError[] = validateViewBase(resource, 'Asset source view')
|
|
174
|
+
|
|
175
|
+
if ('type' in resource && resource.type !== 'asset_source') {
|
|
176
|
+
errors.push({type: 'invalid_value', message: 'Asset source view type must be `asset_source`'})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return errors
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Validates that the given resource is a valid tile view.
|
|
184
|
+
* @param resource The tile view
|
|
185
|
+
* @hidden
|
|
186
|
+
* @category Validation
|
|
187
|
+
* @returns A list of validation errors
|
|
188
|
+
*/
|
|
189
|
+
export function validateTileView(resource: unknown): BlueprintError[] {
|
|
190
|
+
if (!resource) return [{type: 'invalid_value', message: 'Tile view config must be provided'}]
|
|
191
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Tile view config must be an object'}]
|
|
192
|
+
|
|
193
|
+
const errors: BlueprintError[] = validateViewBase(resource, 'Tile view')
|
|
194
|
+
|
|
195
|
+
if ('type' in resource && resource.type !== 'tile') {
|
|
196
|
+
errors.push({type: 'invalid_value', message: 'Tile view type must be `tile`'})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
errors.push(...validateTileFields(resource, 'Tile view'))
|
|
200
|
+
|
|
201
|
+
return errors
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Validates that the given resource is a valid web worker.
|
|
206
|
+
* @param resource The web worker
|
|
207
|
+
* @hidden
|
|
208
|
+
* @category Validation
|
|
209
|
+
* @returns A list of validation errors
|
|
210
|
+
*/
|
|
211
|
+
export function validateWebWorker(resource: unknown): BlueprintError[] {
|
|
212
|
+
if (!resource) return [{type: 'invalid_value', message: 'Web worker config must be provided'}]
|
|
213
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Web worker config must be an object'}]
|
|
214
|
+
|
|
215
|
+
const errors: BlueprintError[] = validateViewBase(resource, 'Web worker')
|
|
216
|
+
|
|
217
|
+
if ('type' in resource && resource.type !== 'worker') {
|
|
218
|
+
errors.push({type: 'invalid_value', message: 'Web worker type must be `worker`'})
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return errors
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Validates a single emitted application view by its `type` discriminator.
|
|
226
|
+
* @param view The emitted view
|
|
227
|
+
* @returns A list of validation errors
|
|
228
|
+
*/
|
|
229
|
+
function validateApplicationView(view: unknown): BlueprintError[] {
|
|
230
|
+
if (!view || typeof view !== 'object' || !('type' in view)) {
|
|
231
|
+
return [{type: 'invalid_value', message: 'Application view must be an object with a `type`'}]
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
switch (view.type) {
|
|
235
|
+
case 'app':
|
|
236
|
+
return validateWindowView(view)
|
|
237
|
+
case 'panel':
|
|
238
|
+
return validatePanelView(view)
|
|
239
|
+
case 'asset_source':
|
|
240
|
+
return validateAssetSourceView(view)
|
|
241
|
+
case 'tile':
|
|
242
|
+
return validateTileView(view)
|
|
243
|
+
default:
|
|
244
|
+
return [{type: 'invalid_value', message: 'Application view type must be one of app, panel, asset_source, tile'}]
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Validates that the given resource is a valid Application.
|
|
250
|
+
* @param resource The Application resource
|
|
251
|
+
* @hidden
|
|
252
|
+
* @category Validation
|
|
253
|
+
* @returns A list of validation errors
|
|
254
|
+
*/
|
|
255
|
+
export function validateApplication(resource: unknown): BlueprintError[] {
|
|
256
|
+
if (!resource) return [{type: 'invalid_value', message: 'Application config must be provided'}]
|
|
257
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Application config must be an object'}]
|
|
258
|
+
|
|
259
|
+
const errors: BlueprintError[] = validateResource(resource)
|
|
260
|
+
|
|
261
|
+
if ('type' in resource && resource.type !== 'sanity.application') {
|
|
262
|
+
errors.push({type: 'invalid_value', message: 'Application type must be `sanity.application`'})
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (!('slug' in resource) || !resource.slug) {
|
|
266
|
+
errors.push({type: 'missing_parameter', message: 'Application slug is required'})
|
|
267
|
+
} else if (typeof resource.slug !== 'string') {
|
|
268
|
+
errors.push({type: 'invalid_type', message: 'Application slug must be a string'})
|
|
269
|
+
} else if (!isReference(resource.slug) && !APPLICATION_SLUG_PATTERN.test(resource.slug)) {
|
|
270
|
+
errors.push({type: 'invalid_format', message: `Application slug must match pattern: ${APPLICATION_SLUG_PATTERN.source}`})
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (!('title' in resource) || !resource.title) {
|
|
274
|
+
errors.push({type: 'missing_parameter', message: 'Application title is required'})
|
|
275
|
+
} else if (typeof resource.title !== 'string') {
|
|
276
|
+
errors.push({type: 'invalid_type', message: 'Application title must be a string'})
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (!('root' in resource) || !resource.root) {
|
|
280
|
+
errors.push({type: 'missing_parameter', message: 'Application root is required'})
|
|
281
|
+
} else if (typeof resource.root !== 'string') {
|
|
282
|
+
errors.push({type: 'invalid_type', message: 'Application root must be a string'})
|
|
283
|
+
} else if (!isReference(resource.root) && !isContainedRelativePath(resource.root)) {
|
|
284
|
+
errors.push({type: 'invalid_value', message: 'Application root must be a relative path within the blueprint directory'})
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if ('icon' in resource && typeof resource.icon !== 'string') {
|
|
288
|
+
errors.push({type: 'invalid_type', message: 'Application icon must be a string'})
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (
|
|
292
|
+
'visibility' in resource &&
|
|
293
|
+
typeof resource.visibility !== 'undefined' &&
|
|
294
|
+
!APPLICATION_VISIBILITIES.some((av) => av === resource.visibility)
|
|
295
|
+
) {
|
|
296
|
+
errors.push({type: 'invalid_value', message: 'visibility must be one of `default`, `unlisted`, or `disabled`'})
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (!('views' in resource) || typeof resource.views === 'undefined') {
|
|
300
|
+
errors.push({type: 'missing_parameter', message: 'Application must declare at least one view'})
|
|
301
|
+
} else if (!Array.isArray(resource.views)) {
|
|
302
|
+
errors.push({type: 'invalid_type', message: 'Application views must be an array'})
|
|
303
|
+
} else if (resource.views.length === 0) {
|
|
304
|
+
errors.push({type: 'invalid_value', message: 'Application must declare at least one view'})
|
|
305
|
+
} else {
|
|
306
|
+
for (const view of resource.views) {
|
|
307
|
+
errors.push(...validateApplicationView(view))
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// The surface does not matter, but the dashboard resolves a single
|
|
311
|
+
// navigable window (federated as `App`) per application, so a second
|
|
312
|
+
// window view would collide.
|
|
313
|
+
const windowCount = resource.views.filter((view) => view && typeof view === 'object' && view.type === 'app').length
|
|
314
|
+
if (windowCount > 1) {
|
|
315
|
+
errors.push({type: 'invalid_value', message: 'Application views may include at most one window view'})
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if ('webWorkers' in resource && typeof resource.webWorkers !== 'undefined') {
|
|
320
|
+
if (!Array.isArray(resource.webWorkers)) {
|
|
321
|
+
errors.push({type: 'invalid_type', message: 'Application webWorkers must be an array'})
|
|
322
|
+
} else {
|
|
323
|
+
for (const worker of resource.webWorkers) {
|
|
324
|
+
errors.push(...validateWebWorker(worker))
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return errors
|
|
330
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type {BlueprintError} from '../types/errors.js'
|
|
2
|
+
import {isReference} from '../utils/validation.js'
|
|
3
|
+
import {isContainedRelativePath} from './applications.js'
|
|
4
|
+
import {validateResource} from './resources.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Validates the fields shared by every singleton installation config resource.
|
|
8
|
+
* @param resource The installation config resource
|
|
9
|
+
* @param label The human-readable label used in error messages (e.g. `Media Library config`)
|
|
10
|
+
* @hidden
|
|
11
|
+
* @category Validation
|
|
12
|
+
* @returns A list of validation errors
|
|
13
|
+
*/
|
|
14
|
+
export function validateInstallationConfig(resource: unknown, label = 'Installation config'): BlueprintError[] {
|
|
15
|
+
if (!resource) return [{type: 'invalid_value', message: `${label} must be provided`}]
|
|
16
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: `${label} must be an object`}]
|
|
17
|
+
|
|
18
|
+
const errors: BlueprintError[] = validateResource(resource)
|
|
19
|
+
|
|
20
|
+
if ('type' in resource && resource.type !== 'sanity.installation.config') {
|
|
21
|
+
errors.push({type: 'invalid_value', message: `${label} type must be \`sanity.installation.config\``})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!('appType' in resource) || !resource.appType) {
|
|
25
|
+
errors.push({type: 'missing_parameter', message: `${label} appType is required`})
|
|
26
|
+
} else if (typeof resource.appType !== 'string') {
|
|
27
|
+
errors.push({type: 'invalid_type', message: `${label} appType must be a string`})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!('root' in resource) || !resource.root) {
|
|
31
|
+
errors.push({type: 'missing_parameter', message: `${label} root is required`})
|
|
32
|
+
} else if (typeof resource.root !== 'string') {
|
|
33
|
+
errors.push({type: 'invalid_type', message: `${label} root must be a string`})
|
|
34
|
+
} else if (!isReference(resource.root) && !isContainedRelativePath(resource.root)) {
|
|
35
|
+
errors.push({type: 'invalid_value', message: `${label} root must be a relative path within the blueprint directory`})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return errors
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Validates a single Media Library field.
|
|
43
|
+
* @param field The field
|
|
44
|
+
* @param label The human-readable label used in error messages (e.g. `Media Library config field`)
|
|
45
|
+
* @returns A list of validation errors
|
|
46
|
+
*/
|
|
47
|
+
function validateMediaLibraryField(field: unknown, label: string): BlueprintError[] {
|
|
48
|
+
if (!field || typeof field !== 'object') return [{type: 'invalid_type', message: `${label} must be an object`}]
|
|
49
|
+
|
|
50
|
+
const errors: BlueprintError[] = []
|
|
51
|
+
|
|
52
|
+
if (!('name' in field) || !field.name) {
|
|
53
|
+
errors.push({type: 'missing_parameter', message: `${label} name is required`})
|
|
54
|
+
} else if (typeof field.name !== 'string') {
|
|
55
|
+
errors.push({type: 'invalid_type', message: `${label} name must be a string`})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!('title' in field) || !field.title) {
|
|
59
|
+
errors.push({type: 'missing_parameter', message: `${label} title is required`})
|
|
60
|
+
} else if (typeof field.title !== 'string') {
|
|
61
|
+
errors.push({type: 'invalid_type', message: `${label} title must be a string`})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!('src' in field) || !field.src) {
|
|
65
|
+
errors.push({type: 'missing_parameter', message: `${label} src is required`})
|
|
66
|
+
} else if (typeof field.src !== 'string') {
|
|
67
|
+
errors.push({type: 'invalid_type', message: `${label} src must be a string`})
|
|
68
|
+
} else if (!isReference(field.src) && !isContainedRelativePath(field.src)) {
|
|
69
|
+
errors.push({type: 'invalid_value', message: `${label} src must be a relative path within the config root`})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if ('public' in field && typeof field.public !== 'undefined' && typeof field.public !== 'boolean') {
|
|
73
|
+
errors.push({type: 'invalid_type', message: `${label} public must be a boolean`})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return errors
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Validates that the given resource is a valid Media Library configuration.
|
|
81
|
+
* @param resource The Media Library configuration resource
|
|
82
|
+
* @hidden
|
|
83
|
+
* @category Validation
|
|
84
|
+
* @returns A list of validation errors
|
|
85
|
+
*/
|
|
86
|
+
export function validateMediaLibraryConfig(resource: unknown): BlueprintError[] {
|
|
87
|
+
const errors: BlueprintError[] = validateInstallationConfig(resource, 'Media Library config')
|
|
88
|
+
|
|
89
|
+
if (!resource || typeof resource !== 'object') return errors
|
|
90
|
+
|
|
91
|
+
if ('appType' in resource && resource.appType !== 'media-library') {
|
|
92
|
+
errors.push({type: 'invalid_value', message: 'Media Library config appType must be `media-library`'})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!('fields' in resource) || typeof resource.fields === 'undefined') {
|
|
96
|
+
errors.push({type: 'missing_parameter', message: 'Media Library config fields is required'})
|
|
97
|
+
} else if (!Array.isArray(resource.fields)) {
|
|
98
|
+
errors.push({type: 'invalid_type', message: 'Media Library config fields must be an array'})
|
|
99
|
+
} else if (resource.fields.length === 0) {
|
|
100
|
+
errors.push({type: 'invalid_value', message: 'Media Library config must declare at least one field'})
|
|
101
|
+
} else {
|
|
102
|
+
for (const field of resource.fields) {
|
|
103
|
+
errors.push(...validateMediaLibraryField(field, 'Media Library config field'))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const names = resource.fields
|
|
107
|
+
.filter((field): field is {name: string} => Boolean(field) && typeof field === 'object' && typeof field.name === 'string')
|
|
108
|
+
.map((field) => field.name)
|
|
109
|
+
if (new Set(names).size !== names.length) {
|
|
110
|
+
errors.push({type: 'invalid_value', message: 'Media Library config field names must be unique'})
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return errors
|
|
115
|
+
}
|
|
@@ -23,10 +23,10 @@ export function validateStudio(resource: unknown): BlueprintError[] {
|
|
|
23
23
|
errors.push({type: 'invalid_value', message: 'Studio type must be `sanity.studio`'})
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
if (!('
|
|
27
|
-
errors.push({type: 'missing_parameter', message: 'Studio
|
|
28
|
-
} else if (typeof resource.
|
|
29
|
-
errors.push({type: 'invalid_type', message: 'Studio
|
|
26
|
+
if (!('root' in resource) || !resource.root) {
|
|
27
|
+
errors.push({type: 'missing_parameter', message: 'Studio root is required'})
|
|
28
|
+
} else if (typeof resource.root !== 'string') {
|
|
29
|
+
errors.push({type: 'invalid_type', message: 'Studio root must be a string'})
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
if ('project' in resource) {
|