export type GetApiApiLocationsArgs = {entity_type?: string | undefined, entity_id?: number | undefined, sub_brands?: boolean | undefined, exclude_digital?: boolean | undefined, cityId?: number | undefined}; export type GetApiApiLocationsOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * List locations * * GET /api/locations */ export const getApiApiLocations = async (args: GetApiApiLocationsArgs, options: GetApiApiLocationsOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.entity_type != null) query.append("entity_type", String(args.entity_type)) if (args.entity_id != null) query.append("entity_id", String(args.entity_id)) if (args.sub_brands != null) query.append("sub_brands", String(args.sub_brands)) if (args.exclude_digital != null) query.append("exclude_digital", String(args.exclude_digital)) if (args.cityId != null) query.append("cityId", String(args.cityId)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/locations${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 };