import {z} from 'zod' export type CeleryTaskInExecute = {name: 'upload_userlog_to_logs_api' | 'engagement_rate_tracking' | 'classify_new_reviews' | 'features_usage_tracking' | 'challenges_leaderboard_update' | 'get_amazon_ratings' | 'habits_streak_volts_reward' | 'features_usage_tracking_bulk_sync' | 'upload_diaglog_to_logs_api' | 'firmwares_adoption_tracking' | 'habit_goals_achievements_sync', params: Record}; export type BodyCeleryTasksAdminAdminReviewsSyncApiV5AdminCeleryTasksPost = {celery_task: CeleryTaskInExecute}; export type CreateApiApiV5AdminCeleryTasksArgs = {body: BodyCeleryTasksAdminAdminReviewsSyncApiV5AdminCeleryTasksPost}; export type CreateApiApiV5AdminCeleryTasksOptions = {baseUrl?: string | undefined, RWAPIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV5AdminCeleryTasksResponse = z.unknown(); 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 }; /** * Launches the specified celery task * * POST /api/v5/admin/celery-tasks/ */ export const createApiApiV5AdminCeleryTasks = async (args: CreateApiApiV5AdminCeleryTasksArgs, options?: CreateApiApiV5AdminCeleryTasksOptions) => { const {baseUrl = "https://api.pavlok.com", fetch: fetchFn = fetch, RWAPIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (RWAPIKeyHeader !== undefined) headers.set("Authorization", RWAPIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/api/v5/admin/celery-tasks/${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 validateResponse(createApiApiV5AdminCeleryTasksResponse, await res.json()) };