import {z} from 'zod' export type SpreadsheetLanguageCodeColumnNumber = number; export type SpreadsheetFileImportSchema = {none?: number | undefined, identifier?: number | undefined, sourcePhrase?: number | undefined, sourceOrTranslation?: number | undefined, translation?: number | undefined, context?: number | undefined, maxLength?: number | undefined, translatable?: number | undefined, labels?: number | undefined} | {[key: string]: SpreadsheetLanguageCodeColumnNumber}; export type FileUpdateImportOptions = {firstLineContainsHeader?: boolean | undefined, importHiddenSheets?: boolean | undefined, importHiddenRows?: boolean | undefined, importEqSuggestions?: boolean | undefined, autoApproveImported?: boolean | undefined, translateHidden?: boolean | undefined, addToTm?: boolean | undefined, contentSegmentation?: boolean | undefined, srxStorageId?: number | undefined, importTranslations?: boolean | undefined, scheme?: SpreadsheetFileImportSchema | undefined} | {translateContent?: boolean | undefined, translateAttributes?: boolean | undefined, inlineTags?: Array | undefined, contentSegmentation?: boolean | undefined, srxStorageId?: number | undefined} | {inlineTags?: Array | undefined, hideAttributeValues?: boolean | undefined, contentSegmentation?: boolean | undefined, srxStorageId?: number | undefined} | {cleanTagsAggressively?: boolean | undefined, translateHiddenText?: boolean | undefined, translateHyperlinkUrls?: boolean | undefined, translateHiddenRowsAndColumns?: boolean | undefined, importNotes?: boolean | undefined, importHiddenSlides?: boolean | undefined, contentSegmentation?: boolean | undefined, srxStorageId?: number | undefined, translateDocProperties?: boolean | undefined, translateComments?: boolean | undefined, ignoreWhitespaceStyles?: boolean | undefined, addTabAsCharacter?: boolean | undefined, addLineSeparatorAsCharacter?: boolean | undefined, lineSeparatorReplacement?: string | undefined, replaceNoBreakHyphenTag?: boolean | undefined, ignoreSoftHyphenTag?: boolean | undefined, complexFieldDefinitionsToExtract?: Array | undefined, translateWordHeadersFooters?: boolean | undefined, translateWordGraphicName?: boolean | undefined, translateWordGraphicDescription?: boolean | undefined, ignoreWordFontColors?: boolean | undefined, wordFontColorsMinIgnoranceThreshold?: string | undefined, wordFontColorsMaxIgnoranceThreshold?: string | undefined, excludeWordStyles?: Array | undefined, translateWordInExcludeStyleMode?: boolean | undefined, wordHighlightColors?: Array | undefined, translateWordInExcludeHighlightMode?: boolean | undefined, translateWordExcludeColors?: boolean | undefined, wordExcludedColors?: Array | undefined, translateExcelCellsCopied?: boolean | undefined, translateExcelSheetNames?: boolean | undefined, excelExcludedColors?: Array | undefined, translateExcelDiagramData?: boolean | undefined, translateExcelDrawings?: boolean | undefined} | {cleanTagsAggressively?: boolean | undefined, translateHyperlinkUrls?: boolean | undefined, contentSegmentation?: boolean | undefined, srxStorageId?: number | undefined} | {inlineHyperlinkText?: boolean | undefined, contentSegmentation?: boolean | undefined, srxStorageId?: number | undefined} | {excludedElements?: Array | undefined, contentSegmentation?: boolean | undefined, inlineTags?: Array | undefined, srxStorageId?: number | undefined} | {excludedElements?: Array | undefined, excludedFrontMatterElements?: Array | undefined, contentSegmentation?: boolean | undefined, inlineTags?: Array | undefined, srxStorageId?: number | undefined} | {excludedFrontMatterElements?: Array | undefined, excludeCodeBlocks?: boolean | undefined, inlineTags?: Array | undefined, contentSegmentation?: boolean | undefined, srxStorageId?: number | undefined} | {excludedFrontMatterElements?: Array | undefined, excludeCodeBlocks?: boolean | undefined, contentSegmentation?: boolean | undefined, srxStorageId?: number | undefined} | {excludedFrontMatterElements?: Array | undefined, excludeCodeBlocks?: boolean | undefined, contentSegmentation?: boolean | undefined, srxStorageId?: number | undefined} | {convertIcu?: boolean | undefined, addGenderArgument?: boolean | undefined} | {contentSegmentation?: boolean | undefined, srxStorageId?: number | undefined}; export type FileExportOptions = {exportPattern?: string | undefined} | {exportPattern?: string | undefined, escapeQuotes?: (0 | 1 | 2 | 3) | undefined, escapeSpecialCharacters?: (0 | 1) | undefined} | {exportPattern?: string | undefined, exportQuotes?: ('single' | 'double') | undefined} | {exportPattern?: string | undefined, strongMarker?: ('asterisk' | 'underscore') | undefined, emphasisMarker?: ('asterisk' | 'underscore') | undefined, unorderedListBullet?: ('asterisks' | 'plus' | 'dash') | undefined, tableColumnWidth?: ('consolidate' | 'evenly_distribute_cells') | undefined, frontMatterQuotes?: ('auto' | 'single' | 'double') | undefined} | {exportPattern?: string | undefined, strongMarker?: ('asterisk' | 'underscore') | undefined, emphasisMarker?: ('asterisk' | 'underscore') | undefined, unorderedListBullet?: ('asterisks' | 'plus' | 'dash') | undefined, tableColumnWidth?: ('consolidate' | 'evenly_distribute_cells') | undefined} | {exportPattern?: string | undefined, strongMarker?: ('asterisk' | 'underscore') | undefined, emphasisMarker?: ('asterisk' | 'underscore') | undefined, unorderedListBullet?: ('asterisks' | 'plus' | 'dash') | undefined, tableColumnWidth?: ('consolidate' | 'evenly_distribute_cells') | undefined} | {exportPattern?: string | undefined, allowWordStyleOptimization?: boolean | undefined, translateExcelExcludeColors?: boolean | undefined}; export type FileReplaceFromStorageForm = {storageId: number, name?: string | undefined, updateOption?: ('clear_translations_and_approvals' | 'keep_translations' | 'keep_translations_and_approvals') | undefined, importOptions?: FileUpdateImportOptions | undefined, exportOptions?: FileExportOptions | undefined, attachLabelIds?: Array | undefined, detachLabelIds?: Array | undefined, replaceModifiedContext?: boolean | undefined}; export type FileRestoreForm = {revisionId: number}; export type UpdateApiProjectsProjectIdFilesFileIdArgs = {projectId: number, fileId: number, body: FileReplaceFromStorageForm | FileRestoreForm}; export type UpdateApiProjectsProjectIdFilesFileIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const spreadsheetLanguageCodeColumnNumber = z.number().int(); export const enterpriseAdditionalFields = z.record(z.string(), z.union([z.string(), z.number().int(), z.boolean(), z.object({})])); export const enterpriseFile = z.object({id: z.number().int().optional(), projectId: z.number().int().optional(), branchId: z.number().int().nullable().optional(), directoryId: z.number().int().nullable().optional(), name: z.string().optional(), title: z.string().nullable().optional(), context: z.string().nullable().optional(), type: z.string().optional(), path: z.string().optional(), status: z.string().optional(), revisionId: z.number().int().optional(), priority: z.string().optional(), importOptions: z.union([z.object({importTranslations: z.boolean().optional(), firstLineContainsHeader: z.boolean().optional(), contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional(), scheme: z.object({identifier: z.number().int().optional(), sourcePhrase: z.number().int().optional()}).and(z.record(z.string(), spreadsheetLanguageCodeColumnNumber)).optional()}), z.object({contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional(), inlineTags: z.array(z.string()).optional(), hideAttributeValues: z.boolean().optional()}), z.object({importTranslations: z.boolean().optional(), firstLineContainsHeader: z.boolean().optional(), importHiddenSheets: z.boolean().optional(), importHiddenRows: z.boolean().optional(), contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional(), scheme: z.object({identifier: z.number().int().optional(), sourcePhrase: z.number().int().optional()}).and(z.record(z.string(), spreadsheetLanguageCodeColumnNumber)).optional()}), z.object({contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional(), excludedElements: z.array(z.string()).optional(), inlineTags: z.array(z.string()).optional(), hideAttributeValues: z.boolean().optional()}), z.object({contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional(), excludedElements: z.array(z.string()).optional(), inlineTags: z.array(z.string()).optional(), excludedFrontMatterElements: z.array(z.string()).optional(), hideAttributeValues: z.boolean().optional()}), z.object({contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional(), excludeCodeBlocks: z.boolean().optional(), excludedFrontMatterElements: z.array(z.string()).optional()}), z.object({contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional(), excludeCodeBlocks: z.boolean().optional(), excludedFrontMatterElements: z.array(z.string()).optional()}), z.object({contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional(), excludeCodeBlocks: z.boolean().optional(), excludedFrontMatterElements: z.array(z.string()).optional(), inlineTags: z.array(z.string()).optional()}), z.object({translateContent: z.boolean().optional(), translateAttributes: z.boolean().optional(), contentSegmentation: z.boolean().optional(), translatableElements: z.array(z.string()).optional(), customSegmentation: z.boolean().optional(), inlineTags: z.array(z.string()).optional()}), z.object({cleanTagsAggressively: z.boolean().optional(), translateHiddenText: z.boolean().optional(), translateHyperlinkUrls: z.boolean().optional(), translateHiddenRowsAndColumns: z.boolean().optional(), importNotes: z.boolean().optional(), importHiddenSlides: z.boolean().optional(), contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional(), translateDocProperties: z.boolean().optional(), translateComments: z.boolean().optional(), ignoreWhitespaceStyles: z.boolean().optional(), addTabAsCharacter: z.boolean().optional(), addLineSeparatorAsCharacter: z.boolean().optional(), lineSeparatorReplacement: z.string().optional(), replaceNoBreakHyphenTag: z.boolean().optional(), ignoreSoftHyphenTag: z.boolean().optional(), complexFieldDefinitionsToExtract: z.array(z.string()).optional(), translateWordHeadersFooters: z.boolean().optional(), translateWordGraphicName: z.boolean().optional(), translateWordGraphicDescription: z.boolean().optional(), ignoreWordFontColors: z.boolean().optional(), wordFontColorsMinIgnoranceThreshold: z.string().optional(), wordFontColorsMaxIgnoranceThreshold: z.string().optional(), excludeWordStyles: z.array(z.string()).optional(), translateWordInExcludeStyleMode: z.boolean().optional(), wordHighlightColors: z.array(z.string()).optional(), translateWordInExcludeHighlightMode: z.boolean().optional(), translateWordExcludeColors: z.boolean().optional(), wordExcludedColors: z.array(z.string()).optional(), translateExcelCellsCopied: z.boolean().optional(), translateExcelSheetNames: z.boolean().optional(), excelExcludedColors: z.array(z.string()).optional(), translateExcelDiagramData: z.boolean().optional(), translateExcelDrawings: z.boolean().optional()}), z.object({cleanTagsAggressively: z.boolean().optional(), translateHiddenText: z.boolean().optional(), translateHyperlinkUrls: z.boolean().optional(), translateHiddenRowsAndColumns: z.boolean().optional(), importNotes: z.boolean().optional(), importHiddenSlides: z.boolean().optional(), contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional()}), z.object({cleanTagsAggressively: z.boolean().optional(), translateHyperlinkUrls: z.boolean().optional(), contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional()}), z.object({inlineHyperlinkText: z.boolean().optional(), contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional()}), z.object({convertIcu: z.boolean().optional(), addGenderArgument: z.boolean().optional()}), z.object({contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional()}), z.object({customSegmentation: z.boolean().optional()}), z.object({importKeyAsSource: z.boolean().optional(), importTranslations: z.boolean().optional()}), z.object({contentSegmentation: z.boolean().optional(), customSegmentation: z.boolean().optional(), excludeIncludeDirectives: z.boolean().optional()})]).nullable().optional(), exportOptions: z.union([z.object({exportPattern: z.string().nullable().optional()}), z.object({exportPattern: z.string().nullable().optional(), allowWordStyleOptimization: z.boolean().optional(), translateExcelExcludeColors: z.boolean().optional()}), z.object({escapeQuotes: z.number().int().nullable().optional(), escapeSpecialCharacters: z.number().int().nullable().optional(), exportPattern: z.string().nullable().optional()}), z.object({exportQuotes: z.string().optional(), exportPattern: z.string().nullable().optional()}), z.object({exportPattern: z.string().nullable().optional(), strongMarker: z.string().optional(), emphasisMarker: z.string().optional(), unorderedListBullet: z.string().optional(), tableColumnWidth: z.string().optional(), frontMatterQuotes: z.string().optional()}), z.object({exportPattern: z.string().nullable().optional(), strongMarker: z.string().optional(), emphasisMarker: z.string().optional(), unorderedListBullet: z.string().optional(), tableColumnWidth: z.string().optional()}), z.object({exportPattern: z.string().nullable().optional(), strongMarker: z.string().optional(), emphasisMarker: z.string().optional(), unorderedListBullet: z.string().optional(), tableColumnWidth: z.string().optional()})]).nullable().optional(), excludedTargetLanguages: z.array(z.string()).nullable().optional(), parserVersion: z.number().int().nullable().optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), fields: enterpriseAdditionalFields.nullable().optional()}); export const enterpriseFileResource = z.object({data: enterpriseFile}); 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 }; /** * Update or Restore File * * PUT /projects/{projectId}/files/{fileId} */ export const updateApiProjectsProjectIdFilesFileId = async (args: UpdateApiProjectsProjectIdFilesFileIdArgs, options?: UpdateApiProjectsProjectIdFilesFileIdOptions) => { const {baseUrl = "https://api.crowdin.com/api/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.projectId))}/files/${encodeURIComponent(String(args.fileId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(enterpriseFileResource, await res.json()) };