import {z} from 'zod' export type GetApiV1ComponentsComponentIdTranslatableFormatArgs = {component_id: string, 'Content-Type'?: string | undefined, format: string, filename?: string | undefined, exclude_disabled_creatives?: boolean | undefined, having_any_tags?: (string | null) | undefined, having_all_tags?: (string | null) | undefined, exclude_having_any_tags?: (string | null) | undefined, exclude_having_all_tags?: (string | null) | undefined, exclude_inheriting?: boolean | undefined, enabled_variants_only?: boolean | undefined}; export type GetApiV1ComponentsComponentIdTranslatableFormatOptions = {baseUrl?: string | undefined, HEADER?: string | undefined, fetch?: typeof fetch | undefined}; export const batchComponentVariableValues = z.object({absolute_name: z.string().optional(), display_name: z.string().optional(), name: z.string().optional(), type: z.enum(["ADMIN_ICON", "AUDIENCE_ID", "AUDIENCE_ID_LIST", "BOOLEAN", "BROWSER_SIDE_JAVASCRIPT", "CLIENT_DOMAIN_ID_LIST", "CLIENT_KEY", "CLIENT_KEY_FLOW", "COLOR", "COMPONENT_ID", "COMPONENT_SETTING_LOOKUP", "CSS", "DELAY", "DELAY_LIST", "ENUM", "ENUM_LIST", "EXTOLE_CLIENT_KEY", "FONT", "GLOB_COMPONENT_PATH", "HTML", "IMAGE", "INTEGER", "INTEGER_LIST", "JSON", "MULTI_SOCKET", "PARTNER_ENUM", "PARTNER_ENUM_LIST", "PERSON_KEY_NAME", "REWARD_SUPPLIER_ID", "REWARD_SUPPLIER_ID_LIST", "SOCKET", "STRING", "STRING_LIST", "STRING_MAP", "URL", "WEBHOOK_ID"]).optional()}); export const getApiV1ComponentsComponentIdTranslatableFormatResponse = z.array(batchComponentVariableValues); 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 }; /** * Download translatable component variables * * GET /v1/components/{component_id}/translatable.{format} * * Also accepts auth: QUERY, COOKIE */ export const getApiV1ComponentsComponentIdTranslatableFormat = async (args: GetApiV1ComponentsComponentIdTranslatableFormatArgs, options?: GetApiV1ComponentsComponentIdTranslatableFormatOptions) => { const {baseUrl = "https://api.extole.io", fetch: fetchFn = fetch, HEADER} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args.filename != null) query.append("filename", String(args.filename)) if (args.exclude_disabled_creatives != null) query.append("exclude_disabled_creatives", String(args.exclude_disabled_creatives)) if (args.having_any_tags != null) query.append("having_any_tags", String(args.having_any_tags)) if (args.having_all_tags != null) query.append("having_all_tags", String(args.having_all_tags)) if (args.exclude_having_any_tags != null) query.append("exclude_having_any_tags", String(args.exclude_having_any_tags)) if (args.exclude_having_all_tags != null) query.append("exclude_having_all_tags", String(args.exclude_having_all_tags)) if (args.exclude_inheriting != null) query.append("exclude_inheriting", String(args.exclude_inheriting)) if (args.enabled_variants_only != null) query.append("enabled_variants_only", String(args.enabled_variants_only)) if (HEADER !== undefined) headers.set("Authorization", HEADER) const url = `${baseUrl.replace(/\/+$/, '')}/v1/components/${encodeURIComponent(String(args.component_id))}/translatable.${encodeURIComponent(String(args.format))}${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(getApiV1ComponentsComponentIdTranslatableFormatResponse, await res.json()) };