histoire
Version:
A fast story book powered by Vite
19 lines (18 loc) • 939 B
JavaScript
import { validateEmbedOrigins, validateHostChannelNames } from '@histoire/protocol';
/** Validates entire configured policy before any embed document becomes available. */
export function resolveEmbedConfig(value) {
if (value != null && (typeof value !== 'object' || Array.isArray(value)))
throw new Error('Expected embed configuration object');
const config = value ?? {};
for (const key of ['enabled', 'allowOpenInEditor', 'allowServerTests']) {
if (config[key] !== undefined && typeof config[key] !== 'boolean')
throw new Error(`Expected embed.${key} boolean`);
}
return {
enabled: config.enabled ?? false,
allowedOrigins: validateEmbedOrigins(config.allowedOrigins ?? []),
allowOpenInEditor: config.allowOpenInEditor ?? false,
allowServerTests: config.allowServerTests ?? false,
channels: validateHostChannelNames(config.channels ?? []),
};
}