export type GetApiLinkArgs = {client_id: string, user_id: string, language?: ('ar' | 'de' | 'en' | 'es' | 'fr') | undefined, reporting_period?: number | undefined, market?: ('at' | 'be' | 'de' | 'demo' | 'dk' | 'es' | 'fi' | 'fr' | 'it' | 'nl' | 'no' | 'pt' | 'se') | undefined}; export type GetApiLinkOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Initiate Qwist Link flow * * GET /link */ export const getApiLink = async (args: GetApiLinkArgs, options?: GetApiLinkOptions) => { const {baseUrl = "https://api.nrich.qwist.cloud", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.client_id != null) query.append("client_id", String(args.client_id)) if (args.user_id != null) query.append("user_id", String(args.user_id)) if (args.language != null) query.append("language", String(args.language)) if (args.reporting_period != null) query.append("reporting_period", String(args.reporting_period)) if (args.market != null) query.append("market", String(args.market)) const url = `${baseUrl.replace(/\/+$/, '')}/link${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 };