UNPKG

eregistrations-js

Version:

A JavaScript library that simplifies usage of eRegistrations APIs.

41 lines (40 loc) 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getServiceNames = getServiceNames; /** * Fetches all service names available * @param config Configuration object with API and auth details * @returns Array of services with id and name */ async function getServiceNames(config) { try { if (!config || !config.baseApiUrl) { throw new Error('Invalid configuration: baseApiUrl is required'); } console.log('Fetching all service names...'); const url = `${config.baseApiUrl}/bparest/bpa/v2016/06/service/service-list-ai`; const response = await fetch(url, { method: 'GET', headers: { 'Authorization': `Bearer ${config.token}`, 'Content-Type': 'application/json' } }); if (!response.ok) { const errorBody = await response.text(); console.error(`Failed to fetch service names: ${response.status} ${response.statusText}`); console.error(`Error details: ${errorBody}`); throw new Error(`Failed to fetch service names: ${response.status} ${response.statusText}`); } const data = await response.json(); console.log(`Successfully fetched service data:`, typeof data); // Ensure we have an array of services const services = Array.isArray(data) ? data : (data.services || []); console.log(`Successfully processed ${services.length || 0} services`); return services; } catch (error) { console.error('Error fetching service names:', error); throw error; } }