export type GetApiRestApiV1IntegrationsProviderCallbackArgs = {provider: string, code?: string | undefined, state?: string | undefined, error?: string | undefined}; export type GetApiRestApiV1IntegrationsProviderCallbackOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * OAuth redirect target (public) * * GET /rest/api/v1/integrations/{provider}/callback */ export const getApiRestApiV1IntegrationsProviderCallback = async (args: GetApiRestApiV1IntegrationsProviderCallbackArgs, options?: GetApiRestApiV1IntegrationsProviderCallbackOptions) => { const {baseUrl = "https://api.metacopier.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.code != null) query.append("code", String(args.code)) if (args.state != null) query.append("state", String(args.state)) if (args.error != null) query.append("error", String(args.error)) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/rest/api/v1/integrations/${encodeURIComponent(String(args.provider))}/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 };