export type GetApiIntegrationsCalendarCallbackProviderArgs = {provider: string, state: string, code: string}; export type GetApiIntegrationsCalendarCallbackProviderOptions = {baseUrl: string, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Callback for provider OAuth setup. * * GET /integrations/calendar/callback/{provider} */ export const getApiIntegrationsCalendarCallbackProvider = async (args: GetApiIntegrationsCalendarCallbackProviderArgs, options: GetApiIntegrationsCalendarCallbackProviderOptions) => { const {baseUrl, fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.provider != null) query.append("provider", String(args.provider)) if (args.state != null) query.append("state", String(args.state)) if (args.code != null) query.append("code", String(args.code)) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/integrations/calendar/callback/${encodeURIComponent(String(args.provider))}${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 };