import {z} from 'zod' export type AccountID = number; export type ProjectID = string; export type TargetGroupSearchString = string; export type TargetGroupStatus = 'draft' | 'scheduled' | 'live' | 'paused' | 'completed' | 'archived'; export type SchemasTargetGroupStatus = Array; export type TargetGroupCountry = Array; export type TargetGroupLanguage = Array; export type ComputeTargetGroupTransitionsFilters = {status?: SchemasTargetGroupStatus | undefined, country?: TargetGroupCountry | undefined, language?: TargetGroupLanguage | undefined}; export type TargetGroupID = string; export type TargetGroupIds = Array; export type ComputeTargetGroupTransitionsRequest = {search_string?: TargetGroupSearchString | undefined, filters?: ComputeTargetGroupTransitionsFilters | undefined, included_target_group_ids?: TargetGroupIds | undefined, excluded_target_group_ids?: TargetGroupIds | undefined}; export type CreateApiDemandAccountsAccountIdProjectsProjectIdComputeTargetGroupTransitionsArgs = {account_id: AccountID, project_id: ProjectID, body: ComputeTargetGroupTransitionsRequest}; export type CreateApiDemandAccountsAccountIdProjectsProjectIdComputeTargetGroupTransitionsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const targetGroupID = z.string(); export const targetGroupIds = z.array(targetGroupID); export const computeTargetGroupTransitionsResponse = z.object({target_groups: targetGroupIds.optional(), is_launch_allowed: z.boolean().optional(), is_pause_allowed: z.boolean().optional(), is_resume_allowed: z.boolean().optional(), is_relaunch_allowed: z.boolean().optional(), is_finish_allowed: z.boolean().optional()}); 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 }; /** * Compute available target group transitions * * POST /demand/accounts/{account_id}/projects/{project_id}/compute-target-group-transitions */ export const createApiDemandAccountsAccountIdProjectsProjectIdComputeTargetGroupTransitions = async (args: CreateApiDemandAccountsAccountIdProjectsProjectIdComputeTargetGroupTransitionsArgs, options?: CreateApiDemandAccountsAccountIdProjectsProjectIdComputeTargetGroupTransitionsOptions) => { 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))}/compute-target-group-transitions${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(computeTargetGroupTransitionsResponse, await res.json()) };