UNPKG

@scriptables/manifest

Version:

Utilities to generate, parse, and update manifest headers in Scriptable scripts.

50 lines (41 loc) 1.63 kB
import {SCRIPTABLE_MANIFEST_KEYS, ScriptableManifest} from './types'; export function validateManifest( manifest: unknown, allowExtraKeys: boolean = false, ): asserts manifest is ScriptableManifest { if (!manifest || typeof manifest !== 'object') { throw new Error('Manifest must be an object'); } if (!allowExtraKeys) { const keys = Object.keys(manifest); for (const key of keys) { if (!SCRIPTABLE_MANIFEST_KEYS.includes(key as any)) { throw new Error(`Invalid manifest key: ${key}`); } } } const typedManifest = manifest as ScriptableManifest; if (typedManifest.alwaysRunInApp !== undefined && typeof typedManifest.alwaysRunInApp !== 'boolean') { throw new Error('alwaysRunInApp must be a boolean'); } if (typedManifest.name !== undefined && typeof typedManifest.name !== 'string') { throw new Error('name must be a string'); } if (typedManifest.iconColor !== undefined && typeof typedManifest.iconColor !== 'string') { throw new Error('iconColor must be a string'); } if (typedManifest.iconGlyph !== undefined && typeof typedManifest.iconGlyph !== 'string') { throw new Error('iconGlyph must be a string'); } if (typedManifest.shareSheetInputs !== undefined) { if (!Array.isArray(typedManifest.shareSheetInputs)) { throw new Error('shareSheetInputs must be an array'); } const validInputs = ['file-url', 'url', 'image', 'plain-text']; for (const input of typedManifest.shareSheetInputs) { if (!validInputs.includes(input)) { throw new Error(`Invalid share sheet input: ${input}`); } } } }