export type AppleHealthWebhookWorkoutStreamDateIntervalDto = {startDate: string, duration: number}; export type AppleHealthWebhookWorkoutStreamItemDto = {dateInterval: AppleHealthWebhookWorkoutStreamDateIntervalDto, value: number}; export type AppleHealthWebhookWorkoutDto = {id: string, name: string, startedAt: string, timezone: string, workoutType: string, distanceMeters?: number | undefined, totalDurationSeconds: number, movingDurationSeconds?: number | undefined, averagePowerWatts?: number | undefined, averageHeartRateBpm?: number | undefined, averageSpeedMps?: number | undefined, averageCadenceRpm?: number | undefined, activeKilocalories?: number | undefined, totalKilocalories?: number | undefined, isIndoor: boolean, streamHeartRateBpm?: Array | undefined, streamPowerWatts?: Array | undefined, streamSpeedMps?: Array | undefined, streamCadenceRpm?: Array | undefined, sourceName?: string | undefined}; export type AppleHealthWebhookBodyDto = {workout: AppleHealthWebhookWorkoutDto}; export type CreateApiV1DataSourcesAppleHealthWebhookArgs = {body: AppleHealthWebhookBodyDto}; export type CreateApiV1DataSourcesAppleHealthWebhookOptions = {baseUrl: string, bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * POST /v1/data-sources/apple-health/webhook */ export const createApiV1DataSourcesAppleHealthWebhook = async (args: CreateApiV1DataSourcesAppleHealthWebhookArgs, options: CreateApiV1DataSourcesAppleHealthWebhookOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/data-sources/apple-health/webhook${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };