export type GetApiV1ActivitiesArgs = {fromDate?: string | undefined, toDate?: string | undefined, orderBy?: ('startedAt' | '-startedAt') | undefined, page: number, limit: number}; export type GetApiV1ActivitiesOptions = {baseUrl: string, bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * GET /v1/activities */ export const getApiV1Activities = async (args: GetApiV1ActivitiesArgs, options: GetApiV1ActivitiesOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.fromDate != null) query.append("fromDate", String(args.fromDate)) if (args.toDate != null) query.append("toDate", String(args.toDate)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/activities${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 };