diff --git a/src/api/methods/api-import.ts b/src/api/methods/api-import.ts index 837f8bd..3ee134e 100644 --- a/src/api/methods/api-import.ts +++ b/src/api/methods/api-import.ts @@ -9,6 +9,8 @@ import { ImportJsonRequest } from '@/types/import-json-request'; import { Project } from '@/types/project'; import { delay } from '@/utils/delay'; import { JsonUtils } from '@/utils/json-utils'; +import { ImportProgressRequest } from '@/types/import-progress-request'; +import { UploadSessionStatus } from '@/types/upload-session-status'; export class ApiImport extends ApiBase { /** @@ -39,6 +41,21 @@ export class ApiImport extends ApiBase { return this.getImportedFile(project, data, result); } + /** + * Get progress of the import session. + * + * @param request Import session progress request. + * @param config Request config. + * + * Not available in the Localazy API Docs yet. + */ + public async getProgress(request: ImportProgressRequest, config?: RequestConfig): Promise { + const { project, importBatch }: ImportProgressRequest = request; + const projectId: string = ApiBase.getId(project, 'project'); + + return (await this.api.client.get(`/projects/${projectId}/import/${importBatch}`, config)) as UploadSessionStatus; + } + protected async getImportedFile( project: string | Project, data: ImportData, diff --git a/src/api/methods/api-keys.ts b/src/api/methods/api-keys.ts index 882c672..64431f5 100644 --- a/src/api/methods/api-keys.ts +++ b/src/api/methods/api-keys.ts @@ -1,5 +1,6 @@ import { ApiBase } from '@/api/methods/api-base'; import { KeyDeleteRequest } from '@/types/key-delete-request'; +import { KeyDeprecateRequest } from '@/types/key-deprecate-request'; import { KeyUpdateRequest } from '@/types/key-update-request'; import { RequestConfig } from '@/types/request-config'; @@ -35,4 +36,29 @@ export class ApiKeys extends ApiBase { await this.api.client.delete(`/projects/${projectId}/keys/${keyId}`, config); } + + /** + * Deprecate keys. + * + * @param request Key deprecate request config. + * @param config Request config. + */ + public async deprecate(request: KeyDeprecateRequest, config?: RequestConfig): Promise { + const { project, phrases }: KeyDeprecateRequest = request; + + const localPhrases: string[] = phrases.map((phrase) => { + if (typeof phrase === 'object' && 'id' in phrase) { + return phrase.id; + } + + if (typeof phrase === 'string') { + return phrase; + } + + return phrase; + }); + const projectId: string = ApiBase.getId(project, 'project'); + + await this.api.client.post(`/projects/${projectId}/keys/deprecate`, { phrases: localPhrases }, config); + } } diff --git a/src/enums/upload-status.ts b/src/enums/upload-status.ts new file mode 100644 index 0000000..b63e043 --- /dev/null +++ b/src/enums/upload-status.ts @@ -0,0 +1,8 @@ +export enum UploadStatus { + NOT_FOUND = 'not_found', + SCHEDULED = 'scheduled', + IN_PROGRESS = 'in_progress', + DONE = 'done', + INVALID_ID = 'invalid_id', + ERROR = 'error', +} diff --git a/src/main.ts b/src/main.ts index e8157c3..35f32be 100644 --- a/src/main.ts +++ b/src/main.ts @@ -27,6 +27,7 @@ export * from '@/api/methods/api-webhooks'; export * from '@/enums/i18n-deprecate'; export * from '@/enums/project-tone'; export * from '@/enums/project-type'; +export * from '@/enums/upload-status'; export * from '@/enums/user-role'; export * from '@/enums/webhook-event'; export * from '@/http/fetch-http-adapter'; @@ -57,8 +58,10 @@ export * from '@/types/import-data'; export * from '@/types/import-file-options'; export * from '@/types/import-i18n-options'; export * from '@/types/import-json-request'; +export * from '@/types/import-progress-request'; export * from '@/types/json'; export * from '@/types/key-delete-request'; +export * from '@/types/key-deprecate-request'; export * from '@/types/key-update-request'; export * from '@/types/key-value'; export * from '@/types/key'; @@ -79,6 +82,7 @@ export * from '@/types/screenshot-update-request'; export * from '@/types/screenshot'; export * from '@/types/screenshots-list-request'; export * from '@/types/screenshots-list-tags-request'; +export * from '@/types/upload-session-status'; export * from '@/types/webhook'; export * from '@/types/webhooks-get-secret-request'; export * from '@/types/webhooks-list-request'; diff --git a/src/types/file-list-keys-request.ts b/src/types/file-list-keys-request.ts index 850c77f..306a965 100644 --- a/src/types/file-list-keys-request.ts +++ b/src/types/file-list-keys-request.ts @@ -37,4 +37,9 @@ export type FileListKeysRequest = { * Receive additional info such as translation note, whether it's hidden etc. */ extra_info?: boolean; + + /** + * Receive also metadata for the key. + */ + metadata?: boolean; }; diff --git a/src/types/import-progress-request.ts b/src/types/import-progress-request.ts new file mode 100644 index 0000000..f0162e7 --- /dev/null +++ b/src/types/import-progress-request.ts @@ -0,0 +1,13 @@ +import { Project } from '@/types/project'; + +export type ImportProgressRequest = { + /** + * Project object or Project ID. + */ + project: Project | string; + + /** + * Import session identifier. + */ + importBatch: string; +}; diff --git a/src/types/key-deprecate-request.ts b/src/types/key-deprecate-request.ts new file mode 100644 index 0000000..ad35bf7 --- /dev/null +++ b/src/types/key-deprecate-request.ts @@ -0,0 +1,14 @@ +import { Project } from '@/types/project'; +import { Key } from '@/types/key'; + +export type KeyDeprecateRequest = { + /** + * Project object or Project ID. + */ + project: Project | string; + + /** + * List of keys identifiers to deprecate. + */ + phrases: Key[] | Pick[] | string[]; +}; diff --git a/src/types/screenshot-update-request.ts b/src/types/screenshot-update-request.ts index 583fa9c..847a171 100644 --- a/src/types/screenshot-update-request.ts +++ b/src/types/screenshot-update-request.ts @@ -45,8 +45,8 @@ export type ScreenshotUpdateRequest = { /** * Add or remove metadata. Adding has priority over removing. Cannot be used together with metadata. */ - addMetaData?: ScreenshotMetadata; - removeMetaData?: ScreenshotMetadata; + addMetadata?: ScreenshotMetadata; + removeMetadata?: string[]; /** * Replace metadata with the current value. Cannot be used together with addMetadata and/or removeMetadata. diff --git a/src/types/upload-session-status.ts b/src/types/upload-session-status.ts new file mode 100644 index 0000000..cb6f970 --- /dev/null +++ b/src/types/upload-session-status.ts @@ -0,0 +1,23 @@ +import { UploadStatus } from '@/enums/upload-status'; + +export type UploadSessionStatus = { + /** + * Possible status of the upload session. + */ + status: UploadStatus; + + /** + * Number of keys added in the upload session. + */ + added?: number; + + /** + * Number of keys updated in the upload session. + */ + updated?: number; + + /** + * Number of keys deprecated in the upload session. + */ + deprecated?: number; +};