import {z} from 'zod' export type ProjectUid = string; export type TranslationJobUid = string; export type UserUid = string; export type GetApiEstimatesApiV2ProjectsProjectIdJobsTranslationJobUidReportsCostArgs = {projectId: ProjectUid, translationJobUid: TranslationJobUid, reportStatus?: ('NOT_FOUND' | 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED' | 'TIMEOUT') | undefined, contentCoverage?: ('FULL' | 'PARTIAL') | undefined, creatorUserUids?: Array | undefined, translationJobSchemaContents?: (Array<'TRANSLATION' | 'ALL_CONTENT' | 'CLAIMING' | 'UNAUTHORIZED'>) | undefined, tags?: Array | undefined, createdFrom?: string | undefined, createdTo?: string | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiEstimatesApiV2ProjectsProjectIdJobsTranslationJobUidReportsCostOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const projectUid = z.string(); export const userUid = z.string(); export const agencyUid = z.string(); export const dateTime = z.string(); export const estimateJobReport = z.object({reportUid: z.string().optional(), schemaType: z.string().optional(), reportType: z.string().optional(), schema: z.string().optional(), reportStatus: z.string().optional(), totalStrings: z.number().int().optional(), projectId: projectUid.optional(), creatorUserUid: userUid.optional(), creatorUserRole: z.string().optional(), contentCoverage: z.string().optional(), creatorAgencyUid: agencyUid.optional(), createdDate: dateTime.optional(), totalWordCount: z.string().optional(), totalWeightedWordCount: z.number().int().optional(), priceInformation: z.string().optional(), localeEstimates: z.string().optional(), tags: z.array(z.string()).optional(), warnings: z.array(z.string()).optional(), errors: z.array(z.string()).optional()}); export const estimateJobReportResponse = z.object({response: z.object({code: z.enum(["SUCCESS", "GENERAL_ERROR", "MAINTENANCE_MODE_ERROR"]), data: z.array(estimateJobReport)})}); 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 }; /** * Get List of Job Cost Estimate Reports * * GET /estimates-api/v2/projects/{projectId}/jobs/{translationJobUid}/reports/cost */ export const getApiEstimatesApiV2ProjectsProjectIdJobsTranslationJobUidReportsCost = async (args: GetApiEstimatesApiV2ProjectsProjectIdJobsTranslationJobUidReportsCostArgs, options?: GetApiEstimatesApiV2ProjectsProjectIdJobsTranslationJobUidReportsCostOptions) => { const {baseUrl = "https://api.smartling.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.reportStatus != null) query.append("reportStatus", String(args.reportStatus)) if (args.contentCoverage != null) query.append("contentCoverage", String(args.contentCoverage)) for (const item of args.creatorUserUids ?? []) query.append("creatorUserUids", String(item)) for (const item of args.translationJobSchemaContents ?? []) query.append("translationJobSchemaContents", String(item)) for (const item of args.tags ?? []) query.append("tags", String(item)) if (args.createdFrom != null) query.append("createdFrom", String(args.createdFrom)) if (args.createdTo != null) query.append("createdTo", String(args.createdTo)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/estimates-api/v2/projects/${encodeURIComponent(String(args.projectId))}/jobs/${encodeURIComponent(String(args.translationJobUid))}/reports/cost${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(estimateJobReportResponse, await res.json()) };