import {z} from 'zod' export type GetApiProfileProfilePublicIdTrackSampleArgs = {cursor?: string | undefined, page_size?: number | undefined, date_start?: string | undefined, date_end?: string | undefined}; export type GetApiProfileProfilePublicIdTrackSampleOptions = {baseUrl?: string | undefined, BearerProfile?: string | undefined, fetch?: typeof fetch | undefined}; export const trackSample = z.object({timestamp: z.string(), duration: z.string().nullable().optional(), source: z.enum(["AGGREGATED", "ANDROID", "APPLE", "FITBIT", "GARMIN", "GOOGLE_HEALTH", "GOOGLEFIT", "HEALTHCONNECT", "HUAWEI", "MYZONE", "OMH", "OMRON", "OURA", "POLAR", "SAMSUNG", "STRAVA", "SUUNTO", "WF", "WHOOP", "WITHINGS"]), activity_type: z.string().nullable().optional(), activity_id: z.string().nullable().optional(), distance: z.number().nullable().optional(), calories: z.number().nullable().optional()}); export const getApiProfileProfilePublicIdTrackSampleResponse = z.array(trackSample); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Track Sample * * GET /profile/{profile_public_id}/track_sample/ */ export const getApiProfileProfilePublicIdTrackSample = async (args: GetApiProfileProfilePublicIdTrackSampleArgs, options?: GetApiProfileProfilePublicIdTrackSampleOptions) => { const {baseUrl = "https://api.wefitter.com/api/v1", fetch: fetchFn = fetch, BearerProfile} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.date_start != null) query.append("date_start", String(args.date_start)) if (args.date_end != null) query.append("date_end", String(args.date_end)) if (BearerProfile !== undefined) headers.set("Authorization", BearerProfile) const url = `${baseUrl.replace(/\/+$/, '')}/profile/${encodeURIComponent(String(args.profile_public_id))}/track_sample/${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 validateResponse(getApiProfileProfilePublicIdTrackSampleResponse, await res.json()) };