import {z} from 'zod' export type PreTranslateAccuracy = {name: 'pre-translate-efficiency' | 'pre-translate-accuracy', schema: {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, postEditingCategories?: Array | undefined, matchScoreCategories?: Array | undefined, languageId?: string | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, branchIds?: Array | undefined, labelIds?: Array | undefined, labelIncludeType?: ('strings_with_label' | 'strings_without_label') | undefined, skipArchiving?: boolean | undefined} | {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, postEditingCategories?: Array | undefined, matchScoreCategories?: Array | undefined, taskId?: number | undefined, skipArchiving?: boolean | undefined}}; export type TranslatorAccuracyReportGeneral = {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, postEditingCategories?: Array | undefined, matchScoreCategories?: Array | undefined, languageId?: string | undefined, userIds?: Array | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, branchIds?: Array | undefined, labelIds?: Array | undefined, labelIncludeType?: ('strings_with_label' | 'strings_without_label') | undefined, skipArchiving?: boolean | undefined}; export type TranslatorAccuracy = {name: 'translator-accuracy', schema: TranslatorAccuracyReportGeneral}; export type CostsEstimationPeReportBaseRates = {fullTranslation: number, proofread: number}; export type CostsEstimationPeReportIndividualRate = {languageIds: Array, fullTranslation: number, proofread: number}; export type CostsEstimationPeReportNetRateSchemesTmMatchNetRate = {matchType: string, price: number}; export type CostsEstimationPeReportNetRateSchemes = {tmMatch: Array}; export type CostsEstimationPostEditing = {name: 'costs-estimation-pe', schema: {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, currency?: ('USD' | 'EUR' | 'JPY' | 'GBP' | 'AUD' | 'CAD' | 'CHF' | 'CNY' | 'SEK' | 'NZD' | 'MXN' | 'SGD' | 'HKD' | 'NOK' | 'KRW' | 'TRY' | 'RUB' | 'INR' | 'BRL' | 'ZAR' | 'GEL' | 'UAH' | 'DDK' | 'PLN') | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, baseRates: CostsEstimationPeReportBaseRates, individualRates: Array, netRateSchemes: CostsEstimationPeReportNetRateSchemes, calculateInternalMatches?: boolean | undefined, includePreTranslatedStrings?: boolean | undefined, languageId?: string | undefined, branchIds?: Array | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, labelIds?: Array | undefined, labelIncludeType?: ('strings_with_label' | 'strings_without_label') | undefined, skipArchiving?: boolean | undefined} | {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, currency?: ('USD' | 'EUR' | 'JPY' | 'GBP' | 'AUD' | 'CAD' | 'CHF' | 'CNY' | 'SEK' | 'NZD' | 'MXN' | 'SGD' | 'HKD' | 'NOK' | 'KRW' | 'TRY' | 'RUB' | 'INR' | 'BRL' | 'ZAR' | 'GEL' | 'UAH' | 'DDK' | 'PLN') | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, baseRates?: CostsEstimationPeReportBaseRates | undefined, individualRates?: Array | undefined, netRateSchemes?: CostsEstimationPeReportNetRateSchemes | undefined, calculateInternalMatches?: boolean | undefined, includePreTranslatedStrings?: boolean | undefined, taskId?: number | undefined, taskIds?: Array | undefined, skipArchiving?: boolean | undefined}}; export type TranslationCostsPeReportBaseRates = {fullTranslation: number, proofread?: number | undefined}; export type TranslationCostsPeReportIndividualRate = {languageIds: Array, userIds: Array, fullTranslation: number, proofread?: number | undefined}; export type TranslationCostsPeReportNetRateSchemesTmMatchNetRate = {matchType: string, price: number}; export type TranslationCostsPeReportNetRateSchemesMtMatchNetRate = {matchType: string, price: number}; export type TranslationCostsPeReportNetRateSchemesAiMatchNetRate = {matchType: string, price: number}; export type TranslationCostsPeReportNetRateSchemesSuggestionMatchNetRate = {matchType: string, price: number}; export type TranslationCostsPeReportNetRateSchemes = {tmMatch: Array, mtMatch: Array, aiMatch?: Array | undefined, suggestionMatch: Array}; export type TranslationCostsPostEditing = {name: 'translation-costs-pe', schema: {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, currency?: ('USD' | 'EUR' | 'JPY' | 'GBP' | 'AUD' | 'CAD' | 'CHF' | 'CNY' | 'SEK' | 'NZD' | 'MXN' | 'SGD' | 'HKD' | 'NOK' | 'KRW' | 'TRY' | 'RUB' | 'INR' | 'BRL' | 'ZAR' | 'GEL' | 'UAH' | 'DDK' | 'PLN') | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, baseRates: TranslationCostsPeReportBaseRates, individualRates: Array, netRateSchemes: TranslationCostsPeReportNetRateSchemes, useCategoryBasedProofreadRates?: boolean | undefined, useTmEditDistance?: boolean | undefined, excludeApprovalsForEditedTranslations?: boolean | undefined, preTranslatedStringsCategorizationAdjustment?: boolean | undefined, groupBy?: ('user' | 'language') | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, languageId?: string | undefined, userIds?: Array | undefined, branchIds?: Array | undefined, labelIds?: Array | undefined, labelIncludeType?: ('strings_with_label' | 'strings_without_label') | undefined, skipArchiving?: boolean | undefined} | {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, currency?: ('USD' | 'EUR' | 'JPY' | 'GBP' | 'AUD' | 'CAD' | 'CHF' | 'CNY' | 'SEK' | 'NZD' | 'MXN' | 'SGD' | 'HKD' | 'NOK' | 'KRW' | 'TRY' | 'RUB' | 'INR' | 'BRL' | 'ZAR' | 'GEL' | 'UAH' | 'DDK' | 'PLN') | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, baseRates: TranslationCostsPeReportBaseRates, individualRates: Array, netRateSchemes: TranslationCostsPeReportNetRateSchemes, taskId?: number | undefined, taskIds?: Array | undefined, useCategoryBasedProofreadRates?: boolean | undefined, useTmEditDistance?: boolean | undefined, excludeApprovalsForEditedTranslations?: boolean | undefined, preTranslatedStringsCategorizationAdjustment?: boolean | undefined, skipArchiving?: boolean | undefined}}; export type TopMembers = {name: 'top-members', schema: {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, languageId?: string | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, userIds?: Array | undefined}}; export type ContributionReportModeTranslationItems = 'userId' | 'languageId' | 'stringId' | 'translationId' | 'brancId' | 'branchName' | 'pluralForm' | 'sourceStringTextHash' | 'mtEngine' | 'mtId' | 'tmName' | 'tmId' | 'aiPromptName' | 'aiPromptId' | 'preTranslated' | 'tmMatch' | 'mtMatch' | 'aiMatch' | 'suggestionMatch' | 'sourceUnits' | 'targetUnits' | 'createdAt' | 'updatedAt'; export type ContributionReportModeTranslation = Array; export type ContributionReportModeApprovalItems = 'userId' | 'languageId' | 'stringId' | 'translationId' | 'brancId' | 'branchName' | 'pluralForm' | 'sourceStringTextHash' | 'mtEngine' | 'mtId' | 'tmName' | 'tmId' | 'aiPromptName' | 'aiPromptId' | 'preTranslated' | 'wasEdited' | 'tmMatch' | 'mtMatch' | 'aiMatch' | 'suggestionMatch' | 'sourceUnits' | 'targetUnits' | 'createdAt' | 'updatedAt'; export type ContributionReportModeApproval = Array; export type ContributionReportModeVotesItems = 'userId' | 'languageId' | 'stringId' | 'translationId' | 'brancId' | 'branchName' | 'pluralForm' | 'sourceStringTextHash' | 'mtEngine' | 'mtId' | 'tmName' | 'tmId' | 'aiPromptName' | 'aiPromptId' | 'preTranslated' | 'mark' | 'sourceUnits' | 'targetUnits' | 'createdAt' | 'updatedAt'; export type ContributionReportModeVotes = Array; export type ContributionRawData = {name: 'contribution-raw-data', schema: {mode: 'translations' | 'approvals' | 'votes', unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, languageId?: string | undefined, userId?: number | undefined, columns?: (ContributionReportModeTranslation | ContributionReportModeApproval | ContributionReportModeVotes) | undefined, tmIds?: Array | undefined, mtIds?: Array | undefined, aiPromptIds?: Array | undefined, branchIds?: Array | undefined, dateFrom?: string | undefined, dateTo?: string | undefined} | {mode: 'translations' | 'approvals' | 'votes', unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, taskId: number, columns?: (ContributionReportModeTranslation | ContributionReportModeApproval | ContributionReportModeVotes) | undefined, tmIds?: Array | undefined, mtIds?: Array | undefined, aiPromptIds?: Array | undefined, dateFrom?: string | undefined, dateTo?: string | undefined}}; export type SourceContentUpdatesReport = {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, dateFrom?: string | undefined, dateTo?: string | undefined}; export type SourceContentUpdates = {name: 'source-content-updates', schema: SourceContentUpdatesReport}; export type ProjectMembersReport = {format?: ('xlsx' | 'csv' | 'json') | undefined, dateFrom?: string | undefined, dateTo?: string | undefined}; export type ProjectMembersStatistics = {name: 'project-members', schema: ProjectMembersReport}; export type EditorIssuesReport = {dateFrom?: string | undefined, dateTo?: string | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, issueType?: ('general_question' | 'translation_mistake' | 'context_request' | 'source_mistake' | null) | undefined}; export type EditorIssues = {name: 'editor-issues', schema: EditorIssuesReport}; export type ProjectQaCheckIssuesReport = {format?: ('xlsx' | 'csv' | 'json') | undefined, languageId?: string | undefined, dateFrom?: string | undefined, dateTo?: string | undefined}; export type ProjectQaCheckIssues = {name: 'qa-check-issues', schema: ProjectQaCheckIssuesReport}; export type SavingActivityReport = {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, languageId?: string | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, mode?: ('currency' | 'relative') | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, branchIds?: Array | undefined, userIds?: Array | undefined}; export type ProjectSavingActivity = {name: 'saving-activity', schema: SavingActivityReport}; export type ProjectConsumptionReport = {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, languageId?: string | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, userIds?: Array | undefined}; export type ProjectTranslationActivity = {name: 'translation-activity', schema: ProjectConsumptionReport}; export type TimeSpentReportBaseRates = {hourly: number}; export type TimeSpentReportIndividualRate = {languageIds: Array, userIds: Array, hourly: number}; export type ProjectTimeSpentReport = {format?: ('xlsx' | 'csv' | 'json') | undefined, groupBy?: ('user' | 'language' | 'task') | undefined, baseRates?: TimeSpentReportBaseRates | undefined, individualRates?: Array | undefined, languageId?: string | undefined, userIds?: Array | undefined, typeTasks?: (0 | 1 | 2 | 3) | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, taskIds?: Array | undefined, skipArchiving?: boolean | undefined}; export type TimeSpent = {name: 'time-spent', schema: ProjectTimeSpentReport}; export type CreateApiProjectsProjectIdReportsArgs = {projectId: number, body: PreTranslateAccuracy | TranslatorAccuracy | CostsEstimationPostEditing | TranslationCostsPostEditing | TopMembers | ContributionRawData | SourceContentUpdates | ProjectMembersStatistics | EditorIssues | ProjectQaCheckIssues | ProjectSavingActivity | ProjectTranslationActivity | TimeSpent}; export type CreateApiProjectsProjectIdReportsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const reportGenerate = z.object({identifier: z.string().optional(), status: z.string().optional(), progress: z.number().int().optional(), attributes: z.object({format: z.string().optional(), reportName: z.string().optional(), schema: z.object({}).optional()}).optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), startedAt: z.string().optional(), finishedAt: z.string().optional()}); export const reportResource = z.object({data: reportGenerate}); 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 }; /** * Generate Report * * POST /projects/{projectId}/reports */ export const createApiProjectsProjectIdReports = async (args: CreateApiProjectsProjectIdReportsArgs, options?: CreateApiProjectsProjectIdReportsOptions) => { 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))}/reports${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(reportResource, await res.json()) };