import { NetworkCollectionModuleDefinitionResponse } from '../../domain/collection-modules/collection-module-definition'; import { HttpMethod, RootAPIHelper } from '../root-api'; /** * Fetch the draft code_id for a collection module * This is used to construct the S3 key path for Lambda package uploads */ export const fetchCollectionModuleCodeId = async (params: { collectionModuleKey: string; apiKey: string; host: string; }): Promise => { const { apiKey, host, collectionModuleKey } = params; const rootApi = new RootAPIHelper({ host, apiKey, throwResponseErrors: true }); const path = `/cli/collection-modules/${collectionModuleKey}`; const searchParams = { live_version: 'false' }; // Always fetch draft version const response: any = await rootApi.send({ method: HttpMethod.Get, path, searchParams, }); // Backend returns code_id field in the response if (!response.code_id) { console.error('Response:', JSON.stringify(response, null, 2)); throw new Error(`Failed to fetch code_id for collection module '${collectionModuleKey}'`); } return response.code_id; };