import {z} from 'zod' export type TargetGroupName = string; export type BusinessUnitIDAsInteger = number; export type LocaleCodeWithReference = string; export type TargetGroupCollectsPII = boolean; export type StudyTypeCodeWithReference = string; export type IndustryCodeWithReference = string; export type CurrencyCode = string; export type TargetGroupClientCpiMonetaryAmountRequestModel = {value?: string | undefined, currency_code?: CurrencyCode | undefined}; export type UserID = string; export type TargetGroupClientID = number | null; export type TargetGroupFieldingSpecification = {start_at: string, end_at: string}; export type CompletesGoal = number; export type TargetGroupExpectedLengthOfInterview = number; export type TargetGroupExpectedIncidenceRate = number; export type ExclusionEntityType = 'RID' | 'CID'; export type ExclusionEntityID = string; export type ExclusionEntityList = {entity_type?: ExclusionEntityType | undefined, entity_ids?: Array | undefined}; export type TargetGroupExclusionObject = {enabled?: boolean | undefined, list?: Array | undefined}; export type RespondentActivityExclusionsIDsListRequest = {type: 'target-group' | 'project', id: unknown, duration?: unknown | undefined, respondent_statuses?: (Array<'Complete' | 'Terminate' | 'SecurityFailure' | 'OverQuota' | 'FinancialTerm' | 'PreClientSurveyProcess'>) | undefined}; export type TargetGroupRespondentActivityExclusionsRequest = Array; export type TargetGroupIndustryLockoutCodeWithReference = string; export type TargetGroupLiveUrl = string; export type TargetGroupTestUrl = string; export type MonetaryAmount = {value?: string | undefined, currency_code?: CurrencyCode | undefined, currency_scale?: (number | null) | undefined}; export type ModuleDynamicPricing = {type: 'dynamic', total_budget?: MonetaryAmount | undefined, maximum_cpi?: MonetaryAmount | undefined, minimum_cpi?: MonetaryAmount | undefined}; export type ModuleRateCardPricing = {type: 'rate_card', maximum_cpi?: MonetaryAmount | undefined, boost_cpi?: MonetaryAmount | undefined}; export type ModuleQuotaOverlay = {prevent_overfill: boolean, balance_fill: boolean}; export type IncrementInterval = unknown; export type ModuleLinearPacing = {type: 'linear', increment_interval: IncrementInterval}; export type ModuleAdaptivePacing = {type: 'adaptive', increment_interval: IncrementInterval}; export type ModuleGeminiPacing = {type: 'gemini', exposed_target_group_id: unknown}; export type ModuleSoftLaunch = {end_at: string, filling_goal_percentage: number, demographics_strictness_percentage: number}; export type FieldingAssistantModulesAssignmentRequestModel = {pricing?: (ModuleDynamicPricing | ModuleRateCardPricing | null) | undefined, quota_overlay?: ModuleQuotaOverlay | undefined, pacing?: (ModuleLinearPacing | ModuleAdaptivePacing | ModuleGeminiPacing | null) | undefined, soft_launch?: ModuleSoftLaunch | undefined}; export type FillingStrategy = 'automated' | 'prescreens' | 'completes'; export type QuestionID = number; export type ProfileTargetsSelectionConditionsV3 = {object: 'selection', question_id: QuestionID, option: string}; export type ProfileTargetsRangeConditionsV3 = {object: 'range', question_id: QuestionID, min: number, max: number}; export type ProfileTargetsOpenEndedConditionsV3 = {object: 'open_ended', question_id: QuestionID, allow_all_values: true, open_ended_values: Array | null} | {object: 'open_ended', question_id: QuestionID, allow_all_values: false, open_ended_values: Array}; export type InterlockProfileConditionsV3 = ProfileTargetsSelectionConditionsV3 | ProfileTargetsRangeConditionsV3 | ProfileTargetsOpenEndedConditionsV3; export type RequestDraftQuotaNominalV3 = {conditions: Array, quota: {name?: string | undefined, completes_goal: number}}; export type RequestDraftQuotaPercentageV3 = {conditions: Array, quota: {name?: string | undefined, completes_goal_percentage: number}}; export type RequestDraftNoQuotaV3 = {object?: 'nominal' | undefined, conditions: Array, quota?: (Record | null) | undefined}; export type RequestDraftQuotaV3 = Array | Array | Array; export type RequestDraftRegularProfileV3 = {object: 'regular', name?: string | undefined, quotas_enabled: boolean, targets: RequestDraftQuotaV3} | {object: 'blended', blended_type?: ('interlock' | 'control') | undefined, name: string, quotas_enabled: boolean, targets: RequestDraftQuotaV3}; export type ProfilingRequest = {template_id: string, profile_adjustment_type: 'percentage', profiles: Array} | Record | null; export type SupplierIds = Array; export type CreateDraftAllocationSpecificationGroupRequest = {open_exchange_allocations: {blocked_supplier_ids: SupplierIds, exchange_min_percentage: number, exchange_max_percentage: number, groups: Array<{group_name: string, min_percentage: number, max_percentage: number, suppliers: SupplierIds}>}, private_exchange_allocations?: {blocked_supplier_ids: SupplierIds, groups: Array<{group_name: string, min_percentage: number, max_percentage: number, supplier_id: string}>} | undefined}; export type TemplateID = unknown; export type AllocationTemplateReference = {id: TemplateID, type: 'global' | 'account' | 'country'}; export type TargetGroupReEntryAttributeConfig = {allow_for_current_target_group: boolean, allow_for_other_target_groups: boolean}; export type ReEntryConfiguration = {completes: {client_side: TargetGroupReEntryAttributeConfig}, pre_client_survey_processes: {screener_side: TargetGroupReEntryAttributeConfig}, financial_terms: {screener_side: TargetGroupReEntryAttributeConfig}, terminates: {client_side: TargetGroupReEntryAttributeConfig, screener_side: TargetGroupReEntryAttributeConfig}, security_failures: {client_side: TargetGroupReEntryAttributeConfig, screener_side: TargetGroupReEntryAttributeConfig}, overquota: {client_side: TargetGroupReEntryAttributeConfig, screener_side: TargetGroupReEntryAttributeConfig}, in_screener: {client_side: TargetGroupReEntryAttributeConfig, screener_side: TargetGroupReEntryAttributeConfig}}; export type CreateDraftTargetGroupRequest = {name: TargetGroupName, business_unit_id: BusinessUnitIDAsInteger, locale: LocaleCodeWithReference, collects_pii: TargetGroupCollectsPII, study_type_code?: StudyTypeCodeWithReference | undefined, industry_code?: IndustryCodeWithReference | undefined, cost_per_interview?: TargetGroupClientCpiMonetaryAmountRequestModel | undefined, client_cost_per_interview_note?: TargetGroupClientCpiMonetaryAmountRequestModel | undefined, project_manager_id: UserID, client_id?: TargetGroupClientID | undefined, fielding_specification: TargetGroupFieldingSpecification, completes_goal: CompletesGoal, expected_length_of_interview_minutes: TargetGroupExpectedLengthOfInterview, expected_incidence_rate: TargetGroupExpectedIncidenceRate, exclusion?: TargetGroupExclusionObject | undefined, respondent_activity_exclusions?: TargetGroupRespondentActivityExclusionsRequest | undefined, industry_lockout_code?: TargetGroupIndustryLockoutCodeWithReference | undefined, live_url?: (TargetGroupLiveUrl | null) | undefined, test_url?: (TargetGroupTestUrl | null) | undefined, fielding_assistant_assignment: FieldingAssistantModulesAssignmentRequestModel, filling_strategy?: (FillingStrategy | null) | undefined, profiling?: ProfilingRequest | undefined, allocations: CreateDraftAllocationSpecificationGroupRequest, allocation_template?: AllocationTemplateReference | undefined, re_entry_configuration?: ReEntryConfiguration | undefined, target_group_customer_reference_number?: (string | null) | undefined} | {name: TargetGroupName, business_unit_id: BusinessUnitIDAsInteger, locale: LocaleCodeWithReference, collects_pii: TargetGroupCollectsPII, study_type_code?: StudyTypeCodeWithReference | undefined, industry_code?: IndustryCodeWithReference | undefined, cost_per_interview?: TargetGroupClientCpiMonetaryAmountRequestModel | undefined, client_cost_per_interview_note?: TargetGroupClientCpiMonetaryAmountRequestModel | undefined, project_manager_id: UserID, client_id?: TargetGroupClientID | undefined, fielding_specification: TargetGroupFieldingSpecification, completes_goal: CompletesGoal, expected_length_of_interview_minutes: TargetGroupExpectedLengthOfInterview, expected_incidence_rate: TargetGroupExpectedIncidenceRate, exclusion?: TargetGroupExclusionObject | undefined, respondent_activity_exclusions?: TargetGroupRespondentActivityExclusionsRequest | undefined, industry_lockout_code?: TargetGroupIndustryLockoutCodeWithReference | undefined, live_url?: (TargetGroupLiveUrl | null) | undefined, test_url?: (TargetGroupTestUrl | null) | undefined, fielding_assistant_assignment: FieldingAssistantModulesAssignmentRequestModel, filling_strategy?: (FillingStrategy | null) | undefined, profiling?: ProfilingRequest | undefined, allocations?: CreateDraftAllocationSpecificationGroupRequest | undefined, allocation_template: AllocationTemplateReference, re_entry_configuration?: ReEntryConfiguration | undefined, target_group_customer_reference_number?: (string | null) | undefined}; export type CreateApiDemandAccountsAccountIdProjectsProjectIdTargetGroupsArgs = {body: CreateDraftTargetGroupRequest}; export type CreateApiDemandAccountsAccountIdProjectsProjectIdTargetGroupsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const targetGroupID = z.string(); export const createdDraftTargetGroupResponse = z.object({id: targetGroupID}); 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 }; /** * Create a target group in draft status * * POST /demand/accounts/{account_id}/projects/{project_id}/target-groups */ export const createApiDemandAccountsAccountIdProjectsProjectIdTargetGroups = async (args: CreateApiDemandAccountsAccountIdProjectsProjectIdTargetGroupsArgs, options?: CreateApiDemandAccountsAccountIdProjectsProjectIdTargetGroupsOptions) => { const {baseUrl = "https://api.cint.com/v1", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/demand/accounts/${encodeURIComponent(String(args.account_id))}/projects/${encodeURIComponent(String(args.project_id))}/target-groups${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(createdDraftTargetGroupResponse, await res.json()) };