/*! * @license * Copyright Squiz Australia Pty Ltd. All Rights Reserved. */ import { AxiosInstance } from 'axios'; import path from 'path'; import { JobManifestV1, ManifestServiceForDev } from '../../../../manifest'; import { checkIfVersionExists } from './versionChecker'; /** * Get and validate a job manifest * @param apiClient - Axios client for API calls * @param folderPath - Path to the job folder * @param logger - Logger instance * @returns The validated manifest */ export async function getAndValidateManifest(apiClient: AxiosInstance, folderPath: string): Promise { const manifestService = new ManifestServiceForDev(); const manifestPath = path.join(folderPath, 'manifest.json'); const manifest = await manifestService.readJobManifest(manifestPath); if (await checkIfVersionExists(apiClient, `/job/${manifest.getName()}/${manifest.getVersion()}`)) { throw new Error(`Cannot upload job version, ${manifest.getName()} ${manifest.getVersion()} already exists`); } return manifest; }