import {z} from 'zod' export type BusinessUnitID = string; export type CountryCode = string; export type GetApiDemandAccountsAccountIdCountryAllocationTemplatesArgs = {search?: string | undefined, page_size?: number | undefined, start_after?: string | undefined, end_before?: string | undefined, sort_ascending?: ('asc' | 'desc') | undefined, business_unit_id?: BusinessUnitID | undefined, country_code?: CountryCode | undefined, is_default?: boolean | undefined, sort_by?: string | undefined}; export type GetApiDemandAccountsAccountIdCountryAllocationTemplatesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const templateID = z.string(); export const countryCode = z.string().min(2).max(2); export const lastModifiedAt = z.string(); export const userID = z.string(); export const countryAllocationTemplateListItem = z.object({template_id: templateID, name: z.string(), country_code: countryCode, business_unit_id: z.string(), is_default: z.boolean(), version: z.number().int(), last_modified_at: lastModifiedAt, last_modified_by: userID}); export const listCountryAllocationTemplatesResponse = z.object({templates: z.array(countryAllocationTemplateListItem), has_more: z.boolean(), next_cursor: 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 }; /** * List country allocation templates * * GET /demand/accounts/{account_id}/country-allocation-templates */ export const getApiDemandAccountsAccountIdCountryAllocationTemplates = async (args: GetApiDemandAccountsAccountIdCountryAllocationTemplatesArgs, options?: GetApiDemandAccountsAccountIdCountryAllocationTemplatesOptions) => { 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.search != null) query.append("search", String(args.search)) 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 (args.sort_ascending != null) query.append("sort_ascending", String(args.sort_ascending)) if (args.business_unit_id != null) query.append("business_unit_id", String(args.business_unit_id)) if (args.country_code != null) query.append("country_code", String(args.country_code)) if (args.is_default != null) query.append("is_default", String(args.is_default)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/demand/accounts/${encodeURIComponent(String(args.account_id))}/country-allocation-templates${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(listCountryAllocationTemplatesResponse, await res.json()) };