import {z} from 'zod' export type AccountID = number; export type TargetGroupID = string; export type GetApiDemandAccountsAccountIdTargetGroupsTargetGroupIdExclusionGroupsArgs = {account_id: AccountID, target_group_id: TargetGroupID, page_size?: number | undefined, start_after?: string | undefined, end_before?: string | undefined}; export type GetApiDemandAccountsAccountIdTargetGroupsTargetGroupIdExclusionGroupsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const exclusionGroupID = z.string(); export const exclusionGroupTag = z.string().max(128); export const exclusionGroupDescription = z.string().max(500); export const exclusionGroupInfo = z.object({exclusion_group_id: exclusionGroupID, tag: exclusionGroupTag, description: exclusionGroupDescription, create_date: z.string(), update_date: z.string().optional()}); export const getExclusionGroupsByTargetGroupResponse = z.object({data: z.array(exclusionGroupInfo), next_cursor: z.string().optional(), url: 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 }; /** * Lists the exclusion groups of a specific target group * * GET /demand/accounts/{account_id}/target-groups/{target_group_id}/exclusion-groups */ export const getApiDemandAccountsAccountIdTargetGroupsTargetGroupIdExclusionGroups = async (args: GetApiDemandAccountsAccountIdTargetGroupsTargetGroupIdExclusionGroupsArgs, options?: GetApiDemandAccountsAccountIdTargetGroupsTargetGroupIdExclusionGroupsOptions) => { 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 (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.start_after != null) query.append("start_after", String(args.start_after)) if (args.end_before != null) query.append("end_before", String(args.end_before)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/demand/accounts/${encodeURIComponent(String(args.account_id))}/target-groups/${encodeURIComponent(String(args.target_group_id))}/exclusion-groups${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(getExclusionGroupsByTargetGroupResponse, await res.json()) };