import {z} from 'zod' export type GetApiVendorCostsLanguagePairsArgs = {Authorization: string, $filter?: string | undefined, $top?: number | undefined, $skip?: number | undefined, $count?: boolean | undefined, 'X-LC-Tenant': string}; export type GetApiVendorCostsLanguagePairsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const dimLanguagePair = z.object({internalId: z.number().int().optional(), sourceLanguageCode: z.string().optional(), sourceEnglishName: z.string().optional(), sourceParentLanguageCode: z.string().optional(), targetLanguageCode: z.string().optional(), targetEnglishName: z.string().optional(), targetParentLanguageCode: z.string().optional()}); export const getApiVendorCostsLanguagePairsResponse = z.object({itemCount: z.number().int().optional(), items: z.array(dimLanguagePair).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 Vendor Costs Language Pair Dimension * * GET /vendor-costs/language-pairs */ export const getApiVendorCostsLanguagePairs = async (args: GetApiVendorCostsLanguagePairsArgs, options?: GetApiVendorCostsLanguagePairsOptions) => { const {baseUrl = "https://api.eu.cloud.trados.com/data-api/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.$filter != null) query.append("$filter", String(args.$filter)) if (args.$top != null) query.append("$top", String(args.$top)) if (args.$skip != null) query.append("$skip", String(args.$skip)) if (args.$count != null) query.append("$count", String(args.$count)) if (args['X-LC-Tenant'] != null) headers.set("X-LC-Tenant", String(args['X-LC-Tenant'])) const url = `${baseUrl.replace(/\/+$/, '')}/vendor-costs/language-pairs${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(getApiVendorCostsLanguagePairsResponse, await res.json()) };