export type GetApiAppwiseV2SearchArgs = {q: string, number?: number | undefined, size?: number | undefined, sort?: string | undefined}; export type GetApiAppwiseV2SearchOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Search content * * GET /appwise/v2/search */ export const getApiAppwiseV2Search = async (args: GetApiAppwiseV2SearchArgs, options?: GetApiAppwiseV2SearchOptions) => { const {baseUrl = "https://marketplace.appdirect.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.q != null) query.append("q", String(args.q)) if (args.number != null) query.append("number", String(args.number)) if (args.size != null) query.append("size", String(args.size)) if (args.sort != null) query.append("sort", String(args.sort)) const url = `${baseUrl.replace(/\/+$/, '')}/appwise/v2/search${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 (await res.json()) as unknown };