@crowdin/app-project-module
Version:
Module that generates for you all common endpoints for serving standalone Crowdin App
131 lines (130 loc) • 4.32 kB
TypeScript
import { ProjectsGroupsModel } from '@crowdin/crowdin-api-client';
import { IntegrationSyncSettings, TreeItem } from '../types';
import { ResponseObject } from '@crowdin/crowdin-api-client/out/core';
import { TranslationsModel } from '@crowdin/crowdin-api-client/out/translations';
import { AxiosError } from 'axios';
import { AppModuleError, AppUserModuleError } from '../../../util/logger';
export declare enum JobType {
UPDATE_TO_CROWDIN = "updateCrowdin",
UPDATE_TO_INTEGRATION = "updateIntegration",
CROWDIN_SYNC_SETTINGS_SAVE = "crowdinSyncSettingsSave",
INTEGRATION_SYNC_SETTINGS_SAVE = "integrationSyncSettingsSave"
}
export declare enum JobStatus {
CREATED = "created",
IN_PROGRESS = "inProgress",
FINISHED = "finished",
FAILED = "failed",
CANCELED = "canceled"
}
export declare enum JobClientType {
CRON = "cron",
MANUAL = "manual",
RERUN = "rerun"
}
export type JobStoreType = 'db' | 'in-memory';
export interface Job {
id: string;
integrationId: string;
crowdinId: string;
type: JobType;
title: string;
progress: number;
status: JobStatus;
payload?: any;
data?: any;
createdAt: number;
updatedAt?: number;
finishedAt?: number;
eta?: number;
info?: string;
attempt?: number;
errors?: string;
processedEntities?: string;
}
export type GetJobParams = Pick<Job, 'id'>;
export type GetActiveJobsParams = Pick<Job, 'integrationId' | 'crowdinId'>;
export type CreateJobParams = Pick<Job, 'integrationId' | 'crowdinId' | 'type' | 'payload' | 'title'>;
export type UpdateJobParams = {
id: string;
progress?: number;
status?: JobStatus;
info?: string;
data?: string;
attempt?: number;
errors?: string[];
processedEntities?: string;
};
export type JobClient = {
get: () => Promise<Job | undefined>;
update: UpdateJobProgress;
type: JobClientType;
translationUploaded: SaveUploadedFileTranslation;
fetchTranslation: FetchTranslation;
markFilesAsUnsynced: MarkUnsyncedFiles;
unmarkFilesAsUnsynced: UnmarkUnsyncedFiles;
};
export type UpdateJobProgress = ({ progress, status, info, data, attempt, errors, }: Omit<UpdateJobParams, 'id'>) => Promise<{
isCanceled: boolean;
}>;
export interface GetAllNewFilesArgs {
crowdinId: string;
integrationId: string;
projectData: ProjectsGroupsModel.ProjectSettings;
integrationSettings: any;
syncSettings: IntegrationSyncSettings;
currentFileSnapshot: TreeItem[];
}
export type SaveUploadedFileTranslation = ({ fileId, translationParams, }: {
fileId: number;
translationParams: {
languageId: string;
etag: string;
}[];
}) => Promise<void>;
export type FetchTranslation = ({ fileId, languageId, params, }: {
fileId: number;
languageId: string;
params?: Omit<TranslationsModel.BuildProjectFileTranslationRequest, 'targetLanguageId'>;
}) => Promise<ResponseObject<TranslationsModel.BuildProjectFileTranslationResponse> | null>;
export interface TranslationCache {
integrationId: string;
crowdinId: string;
fileId: number;
languageId: string;
etag?: string;
}
export type GetFileTranslationCache = Pick<TranslationCache, 'integrationId' | 'crowdinId' | 'fileId'>;
export type GetFileTranslationCacheByLanguageParams = Pick<TranslationCache, 'integrationId' | 'crowdinId' | 'fileId' | 'languageId'>;
export type UpdateTranslationCacheParams = Pick<TranslationCache, 'integrationId' | 'crowdinId' | 'fileId' | 'languageId' | 'etag'>;
export type MarkUnsyncedFiles = ({ files, }: {
files: {
fileId: number;
error: AxiosError | AppModuleError | AppUserModuleError | Error | string;
}[];
}) => Promise<void>;
export type UnmarkUnsyncedFiles = ({ files }: {
files: {
fileId: number;
}[];
}) => Promise<void>;
export interface UnsyncedFiles {
integrationId: string;
crowdinId: string;
files: string;
}
export type GetUnsyncedFiles = Pick<UnsyncedFiles, 'integrationId' | 'crowdinId'>;
export interface IntegrationSyncedData {
id: number;
integrationId: string;
crowdinId: string;
type: string;
updatedAt: string;
files?: any;
}
export type GetAllJobsParams = {
integrationId: string;
crowdinId: string;
limit: number;
offset: number;
};