import {z} from 'zod' export type GroupTranslationCostsPeReportBaseRates = {fullTranslation: number, proofread?: number | undefined}; export type GroupTranslationCostsPeReportIndividualRate = {languageIds: Array, userIds: Array, fullTranslation: number, proofread?: number | undefined}; export type GroupTranslationCostsPeReportNetRateSchemesTmMatchNetRate = {matchType: string, price: number}; export type GroupTranslationCostsPeReportNetRateSchemesMtMatchNetRate = {matchType: string, price: number}; export type GroupTranslationCostsPeReportNetRateSchemesAiMatchNetRate = {matchType: string, price: number}; export type GroupTranslationCostsPeReportNetRateSchemesSuggestionMatchNetRate = {matchType: string, price: number}; export type GroupTranslationCostsPeReportNetRateSchemes = {tmMatch: Array, mtMatch: Array, aiMatch?: Array | undefined, suggestionMatch: Array}; 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 GroupTranslationCostsPostEditing = {name: 'group-translation-costs-pe', schema: {projectIds?: Array | 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: GroupTranslationCostsPeReportBaseRates, individualRates: Array, netRateSchemes: GroupTranslationCostsPeReportNetRateSchemes, useCategoryBasedProofreadRates?: boolean | undefined, useTmEditDistance?: boolean | undefined, excludeApprovalsForEditedTranslations?: boolean | undefined, preTranslatedStringsCategorizationAdjustment?: boolean | undefined, groupBy?: ('user' | 'language' | 'project') | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, userIds?: Array | 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, taskIds?: Array | undefined, useCategoryBasedProofreadRates?: boolean | undefined, useTmEditDistance?: boolean | undefined, excludeApprovalsForEditedTranslations?: boolean | undefined, preTranslatedStringsCategorizationAdjustment?: boolean | undefined, skipArchiving?: boolean | undefined}}; export type GroupTopMembers = {name: 'group-top-members', schema: {projectIds?: Array | undefined, 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 GroupTaskUsageReport = {format: 'xlsx' | 'csv' | 'json', type: 'workload', projectIds?: Array | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, groupBy?: ('user' | 'language' | 'type' | 'project') | undefined, typeTasks?: (0 | 1 | 2 | 3) | undefined, languageId?: string | undefined, creatorId?: number | undefined, assigneeId?: number | undefined} | {format: 'xlsx' | 'csv' | 'json', type: 'created-vs-resolved', projectIds?: Array | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, groupBy?: ('language' | 'type' | 'project') | undefined, typeTasks?: (0 | 1 | 2 | 3) | undefined, languageId?: string | undefined, creatorId?: number | undefined} | {format: 'xlsx' | 'csv' | 'json', type: 'performance', projectIds?: Array | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, groupBy?: ('language' | 'type' | 'project') | undefined, typeTasks?: (0 | 1 | 2 | 3) | undefined, languageId?: string | undefined, creatorId?: number | undefined, assigneeId?: number | undefined} | {format: 'xlsx' | 'csv' | 'json', type: 'time', projectIds?: Array | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, groupBy?: ('language' | 'type' | 'project') | undefined, typeTasks?: (0 | 1 | 2 | 3) | undefined, languageId?: string | undefined, creatorId?: number | undefined, assigneeId?: number | undefined, wordsCountFrom?: number | undefined, wordsCountTo?: number | undefined} | {format: 'xlsx' | 'csv' | 'json', type: 'cost', projectIds?: Array | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, groupBy?: ('language' | 'type' | 'project') | undefined, typeTasks?: (0 | 1 | 2 | 3) | undefined, languageId?: string | undefined, creatorId?: number | undefined, assigneeId?: number | undefined, statuses?: (Array<'todo' | 'in_progress' | 'done' | 'closed' | 'review'>) | undefined}; export type GroupTaskUsage = {name: 'group-task-usage', schema: GroupTaskUsageReport}; export type GroupQaCheckIssuesReport = {projectIds?: Array | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, dateFrom?: string | undefined, dateTo?: string | undefined}; export type GroupQaCheckIssues = {name: 'group-qa-check-issues', schema: GroupQaCheckIssuesReport}; export type GroupTranslationActivityReport = {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, projectIds?: Array | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, userIds?: Array | undefined}; export type GroupTranslationActivity = {name: 'group-translation-activity', schema: GroupTranslationActivityReport}; export type GroupSourceContentUpdatesReport = {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, projectIds?: Array | undefined, dateFrom?: string | undefined, dateTo?: string | undefined}; export type GroupSourceContentUpdates = {name: 'group-source-content-updates', schema: GroupSourceContentUpdatesReport}; export type TimeSpentReportBaseRates = {hourly: number}; export type TimeSpentReportIndividualRate = {languageIds: Array, userIds: Array, hourly: number}; export type GroupTimeSpentReport = {format?: ('xlsx' | 'csv' | 'json') | undefined, groupBy?: ('user' | 'language' | 'task' | 'project') | 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, projectIds?: Array | undefined, taskIds?: Array | undefined, skipArchiving?: boolean | undefined}; export type GroupTimeSpent = {name: 'group-time-spent', schema: GroupTimeSpentReport}; export type GroupPreTranslateAccuracy = {name: 'group-pre-translate-accuracy', schema: {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, languageId?: string | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, postEditingCategories?: Array | undefined, matchScoreCategories?: Array | undefined, projectIds?: Array | undefined, skipArchiving?: boolean | undefined} | {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, matchScoreCategories?: Array | undefined, taskIds?: Array | undefined, skipArchiving?: boolean | undefined}}; export type GroupTranslatorAccuracyReportGeneral = {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, languageId?: string | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, postEditingCategories?: Array | undefined, matchScoreCategories?: Array | undefined, userIds?: Array | undefined, projectIds?: Array | undefined, skipArchiving?: boolean | undefined}; export type GroupTranslatorAccuracy = {name: 'group-translator-accuracy', schema: GroupTranslatorAccuracyReportGeneral}; export type GroupSavingActivityReport = {unit?: ('strings' | 'words' | 'chars' | 'chars_with_spaces') | undefined, projectIds?: Array | undefined, format?: ('xlsx' | 'csv' | 'json') | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, languageId?: string | undefined, mode?: ('relative' | 'currency') | undefined}; export type GroupSavingActivity = {name: 'group-saving-activity', schema: GroupSavingActivityReport}; export type CreateApiReportsArgs = {body: GroupTranslationCostsPostEditing | GroupTopMembers | GroupTaskUsage | GroupQaCheckIssues | GroupTranslationActivity | GroupSourceContentUpdates | GroupTimeSpent | GroupPreTranslateAccuracy | GroupTranslatorAccuracy | GroupSavingActivity}; export type CreateApiReportsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const groupReportGenerate = 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(), projectIds: z.array(z.number().int()).optional(), schema: z.object({}).optional()}).optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), startedAt: z.string().optional(), finishedAt: z.string().optional()}); export const groupReportResource = z.object({data: groupReportGenerate}); 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 Organization Report * * POST /reports */ export const createApiReports = async (args: CreateApiReportsArgs, options?: CreateApiReportsOptions) => { 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(/\/+$/, '')}/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(groupReportResource, await res.json()) };