import {z} from 'zod' export type GetApiDemandTargetGroupsTargetGroupIdOverviewOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const accountID = z.number().int(); export const projectID = z.string(); export const targetGroupHumanReadableID = z.string().min(7).max(7); export const userID = z.string(); export const fillingStrategy = z.enum(["automated", "prescreens", "completes"]); export const targetGroupProgress = z.object({current_completes: z.number().int().gte(0), current_prescreens: z.number().int().gte(0), filling_goal: z.number().int().gte(1), filling_strategy: fillingStrategy}); export const targetGroupPricingModel = z.enum(["rate_card", "dynamic"]); export const currencyCode = z.string(); export const monetaryAmount = z.object({value: z.string().optional(), currency_code: currencyCode.optional(), currency_scale: z.number().int().nullable().optional()}); export const targetGroupStatus = z.enum(["draft", "scheduled", "live", "paused", "completed", "archived"]); export const conversionRate = z.number().gte(0).lte(1); export const dropOffRate = z.number().gte(0).lte(1); export const incidenceRate = z.number().gte(0).lte(1); export const medianLengthOfInterviewSeconds = z.number().int().gte(0); export const studyTypeCode = z.string(); export const targetGroupOverviewByTargetGroupId = z.object({account_id: accountID, project_id: projectID, project_name: z.string(), target_group_name: z.string(), human_readable_id: targetGroupHumanReadableID.optional(), project_manager_id: userID, progress: targetGroupProgress, pricing_model: targetGroupPricingModel, is_pricing_restricted: z.boolean(), current_cost_per_interview: monetaryAmount, average_cost_per_interview: monetaryAmount.optional(), current_cost: monetaryAmount, status: targetGroupStatus, country_code: z.string(), language_code: z.string(), conversion_rate: conversionRate, drop_off_rate: dropOffRate, incidence_rate: incidenceRate, median_length_of_interview_seconds: medianLengthOfInterviewSeconds, study_type_code: studyTypeCode.optional(), target_group_customer_reference_number: z.string().min(3).max(128).nullable().optional(), created_at: z.string()}); 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 }; /** * Retrieve basic attributes and stats for a target group by ID * * GET /demand/target-groups/{target_group_id}/overview */ export const getApiDemandTargetGroupsTargetGroupIdOverview = async (options?: GetApiDemandTargetGroupsTargetGroupIdOverviewOptions) => { const {baseUrl = "https://api.cint.com/v1", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/demand/target-groups/${encodeURIComponent(String(args.target_group_id))}/overview${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(targetGroupOverviewByTargetGroupId, await res.json()) };