export type GetApiProductsArgs = {search?: string | undefined, isFastTrack?: boolean | undefined, isPaperCopy?: boolean | undefined, page: number, size: number}; export type GetApiProductsOptions = {baseUrl?: string | undefined, accessToken?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get products with filters * * GET /products */ export const getApiProducts = async (args: GetApiProductsArgs, options?: GetApiProductsOptions) => { const {baseUrl = "https://api.findmydocument.net", fetch: fetchFn = fetch, accessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.search != null) query.append("search", String(args.search)) if (args.isFastTrack != null) query.append("isFastTrack", String(args.isFastTrack)) if (args.isPaperCopy != null) query.append("isPaperCopy", String(args.isPaperCopy)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (accessToken !== undefined) headers.set('authorization', `Bearer ${accessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/products${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 };