import {z} from 'zod' export type GetApiDemandAccountsAccountIdQuestionsTranslationOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const questionID = z.number().int(); export const questionsTranslationSelectionCondition = z.object({object: z.literal("selection"), question_id: questionID, option: z.string()}); export const questionsTranslationRangeCondition = z.object({object: z.literal("range"), question_id: questionID, option: z.string().nullable()}); export const questionsTranslationOpenEndedCondition = z.object({object: z.literal("open_ended"), question_id: questionID, option: z.string().nullable(), allow_all_values: z.boolean()}); export const questionsTranslationConditions = z.union([questionsTranslationSelectionCondition, questionsTranslationRangeCondition, questionsTranslationOpenEndedCondition]); export const questionQuotaDetailsV3 = z.object({name: z.string().optional(), text: z.string(), text_translated: z.string().optional(), conditions: z.array(questionsTranslationConditions)}); export const questionQuotaV3 = z.array(questionQuotaDetailsV3); export const questionConstraints = z.object({type: z.string().optional(), minimum: z.number().optional(), maximum: z.number().optional()}); export const questionResponseProfileFormat = z.object({object: z.literal("regular"), name: z.string(), description: z.string(), description_translated: z.string().optional(), quotas_enabled: z.boolean(), targets: questionQuotaV3, option_mask: z.string().optional(), constraints: questionConstraints.optional(), standard: z.boolean(), profile_condition_type: z.enum(["Single Punch", "Multi Punch", "Dummy", "Text - Open-end", "Numeric - Open-end"]), classification_id: z.number().int().optional(), classification_code: z.string().optional()}); export const nextCursor = z.string().nullable(); export const questionsTranslationResponse = z.object({total: z.number().int(), profiles: z.array(questionResponseProfileFormat).nullable(), has_more: z.boolean(), 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 }; /** * Lists all available questions, answers, and conditions. * * GET /demand/accounts/{account_id}/questions-translation */ export const getApiDemandAccountsAccountIdQuestionsTranslation = async (options?: GetApiDemandAccountsAccountIdQuestionsTranslationOptions) => { 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 (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/demand/accounts/${encodeURIComponent(String(args.account_id))}/questions-translation${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(questionsTranslationResponse, await res.json()) };