export type GetApiV1ConnectMetaAdsCallbackArgs = {state: string, code?: string | undefined, error?: string | undefined}; export type GetApiV1ConnectMetaAdsCallbackOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Complete Meta business login * * GET /v1/connect/meta-ads/callback */ export const getApiV1ConnectMetaAdsCallback = async (args: GetApiV1ConnectMetaAdsCallbackArgs, options?: GetApiV1ConnectMetaAdsCallbackOptions) => { const {baseUrl = "https://zernio.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.state != null) query.append("state", String(args.state)) if (args.code != null) query.append("code", String(args.code)) if (args.error != null) query.append("error", String(args.error)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/connect/meta-ads/callback${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 };