import {z} from 'zod' export type ProjectUid = string; export type TranslationJobUid = string; export type LocaleId = string; export type GetApiJobsApiV3ProjectsProjectIdJobsTranslationJobUidStringsArgs = {projectId: ProjectUid, translationJobUid: TranslationJobUid, targetLocaleId?: LocaleId | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiJobsApiV3ProjectsProjectIdJobsTranslationJobUidStringsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const localeId = z.string(); export const hashcode = z.string(); export const localeHashcodeResponse = z.object({response: z.object({code: z.literal("SUCCESS"), data: z.object({totalCount: z.number().int().optional(), items: z.array(z.object({targetLocaleId: localeId.optional(), hashcode: hashcode.optional()})).optional()}).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 }; /** * Get translation job strings. * * GET /jobs-api/v3/projects/{projectId}/jobs/{translationJobUid}/strings */ export const getApiJobsApiV3ProjectsProjectIdJobsTranslationJobUidStrings = async (args: GetApiJobsApiV3ProjectsProjectIdJobsTranslationJobUidStringsArgs, options?: GetApiJobsApiV3ProjectsProjectIdJobsTranslationJobUidStringsOptions) => { 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.targetLocaleId != null) query.append("targetLocaleId", String(args.targetLocaleId)) 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(/\/+$/, '')}/jobs-api/v3/projects/${encodeURIComponent(String(args.projectId))}/jobs/${encodeURIComponent(String(args.translationJobUid))}/strings${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(localeHashcodeResponse, await res.json()) };