export type GetApiCatalogServicesArgs = {q?: string | undefined, barcode?: string | undefined, category_ids?: Array | undefined, sort?: ('title' | '-title') | undefined}; export type GetApiCatalogServicesOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get Services * * GET /catalog/services */ export const getApiCatalogServices = async (args: GetApiCatalogServicesArgs, options?: GetApiCatalogServicesOptions) => { const {baseUrl = "https://api.roapp.io/v2", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.q != null) query.append("q", String(args.q)) if (args.barcode != null) query.append("barcode", String(args.barcode)) for (const item of args.category_ids ?? []) query.append("category_ids", String(item)) if (args.sort != null) query.append("sort", String(args.sort)) if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/catalog/services${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };