import {z} from 'zod' export type GetApiDemandAccountsAccountIdProfilingTemplatesArgs = {page_size?: number | undefined, start_after?: string | undefined, end_before?: string | undefined, order?: ('desc' | 'asc') | undefined, scope?: ('global' | 'account') | undefined, locales?: string | undefined}; export type GetApiDemandAccountsAccountIdProfilingTemplatesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const profileTemplateID = z.string(); export const localeCode = z.string(); export const profileTemplateListItem = z.object({id: profileTemplateID.optional(), name: z.string().optional(), description: z.string().optional(), label: z.string().optional(), locales: z.array(localeCode).optional(), scope: z.enum(["global", "account"]).optional()}); export const nextCursor = z.string().nullable(); export const profileTemplatesList = z.object({templates: z.array(profileTemplateListItem).optional(), next_cursor: nextCursor.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 }; /** * List profile templates * * GET /demand/accounts/{account_id}/profiling-templates */ export const getApiDemandAccountsAccountIdProfilingTemplates = async (args: GetApiDemandAccountsAccountIdProfilingTemplatesArgs, options?: GetApiDemandAccountsAccountIdProfilingTemplatesOptions) => { 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 (args.order != null) query.append("order", String(args.order)) if (args.scope != null) query.append("scope", String(args.scope)) if (args.locales != null) query.append("locales", String(args.locales)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/demand/accounts/${encodeURIComponent(String(args.account_id))}/profiling-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(profileTemplatesList, await res.json()) };