/*! * @license * Copyright Squiz Australia Pty Ltd. All Rights Reserved. */ import { RECOMMENDED_RUNTIME_IMAGE, SUPPORTED_RUNTIME_IMAGES, isDeprecatedRuntimeImage, isSupportedRuntimeImage, } from '../../job/constants/RuntimeImage.constants'; import { ManifestValidationError } from '../errors/ManifestValidationError'; export const validateAndDefaultRuntimeImage = (image: string | null | undefined): string => { if (image === null || image === undefined) { return RECOMMENDED_RUNTIME_IMAGE; } if (!isSupportedRuntimeImage(image)) { throw new ManifestValidationError( `Unsupported runtime image "${image}". Supported images are: ${SUPPORTED_RUNTIME_IMAGES.join(', ')}`, ); } if (isDeprecatedRuntimeImage(image)) { throw new ManifestValidationError( `Runtime image "${image}" is deprecated and can no longer be used for new uploads. ` + `Please use the recommended runtime image "${RECOMMENDED_RUNTIME_IMAGE}".`, ); } return image; };