From 1477d0a73c6053ee5643cb64b6e8fac858f8fa27 Mon Sep 17 00:00:00 2001 From: david-vaclavek Date: Mon, 13 May 2024 15:32:26 +0200 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9C=A8=20feat(Import):=20add=20upload=20?= =?UTF-8?q?status=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/methods/api-import.ts | 23 +++++++++++++++++++++++ src/enums/upload-status.ts | 8 ++++++++ src/types/import-progress-request.ts | 13 +++++++++++++ src/types/upload-session-status.ts | 23 +++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 src/enums/upload-status.ts create mode 100644 src/types/import-progress-request.ts create mode 100644 src/types/upload-session-status.ts diff --git a/src/api/methods/api-import.ts b/src/api/methods/api-import.ts index 837f8bd..6e431ad 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,27 @@ 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/enums/upload-status.ts b/src/enums/upload-status.ts new file mode 100644 index 0000000..4861dbc --- /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/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/upload-session-status.ts b/src/types/upload-session-status.ts new file mode 100644 index 0000000..62dd391 --- /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; +} From 117b3a553bba8dc2f1231d18743dbb63e27cd5cb Mon Sep 17 00:00:00 2001 From: david-vaclavek Date: Mon, 13 May 2024 15:32:39 +0200 Subject: [PATCH 2/6] =?UTF-8?q?=E2=9C=A8=20feat(Key):=20add=20deprecate=20?= =?UTF-8?q?endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/methods/api-keys.ts | 26 ++++++++++++++++++++++++++ src/main.ts | 4 ++++ src/types/key-deprecate-request.ts | 14 ++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 src/types/key-deprecate-request.ts 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/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/key-deprecate-request.ts b/src/types/key-deprecate-request.ts new file mode 100644 index 0000000..5a8055c --- /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[]; +} From e045dad7aabcae908acadd4960971a84c50ce1c4 Mon Sep 17 00:00:00 2001 From: david-vaclavek Date: Tue, 4 Jun 2024 14:10:05 +0200 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=90=9B=20fix:(screenshots):=20fix=20`?= =?UTF-8?q?removeMetadata`=20data=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/types/screenshot-update-request.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/screenshot-update-request.ts b/src/types/screenshot-update-request.ts index 583fa9c..387b33f 100644 --- a/src/types/screenshot-update-request.ts +++ b/src/types/screenshot-update-request.ts @@ -46,7 +46,7 @@ export type ScreenshotUpdateRequest = { * Add or remove metadata. Adding has priority over removing. Cannot be used together with metadata. */ addMetaData?: ScreenshotMetadata; - removeMetaData?: ScreenshotMetadata; + removeMetaData?: string[]; /** * Replace metadata with the current value. Cannot be used together with addMetadata and/or removeMetadata. From d5ecfacb7cf8668f6089cc97a00b5c9d3b8a4242 Mon Sep 17 00:00:00 2001 From: david-vaclavek Date: Tue, 4 Jun 2024 14:25:19 +0200 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=90=9B=20fix(screenshots):=20fix=20`a?= =?UTF-8?q?ddMetadata`=20and=20`removeMetadata`=20params=20casing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/types/screenshot-update-request.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/screenshot-update-request.ts b/src/types/screenshot-update-request.ts index 387b33f..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?: string[]; + addMetadata?: ScreenshotMetadata; + removeMetadata?: string[]; /** * Replace metadata with the current value. Cannot be used together with addMetadata and/or removeMetadata. From 6bd51dc581dc5d3bfe33c4a0f18093131f395dc1 Mon Sep 17 00:00:00 2001 From: david-vaclavek Date: Tue, 16 Jul 2024 17:00:53 +0200 Subject: [PATCH 5/6] =?UTF-8?q?=E2=9C=A8=20feat(`listKeys`):=20add=20suppo?= =?UTF-8?q?rt=20for=20`metadata`=20parameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/types/file-list-keys-request.ts | 5 +++++ 1 file changed, 5 insertions(+) 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; }; From aa710d1074b8f85ca8945e038699cd406d1f9f09 Mon Sep 17 00:00:00 2001 From: david-vaclavek Date: Tue, 16 Jul 2024 17:46:51 +0200 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=9A=A8=20lint:=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/methods/api-import.ts | 10 ++-------- src/enums/upload-status.ts | 12 ++++++------ src/types/key-deprecate-request.ts | 8 ++++---- src/types/upload-session-status.ts | 4 ++-- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/api/methods/api-import.ts b/src/api/methods/api-import.ts index 6e431ad..3ee134e 100644 --- a/src/api/methods/api-import.ts +++ b/src/api/methods/api-import.ts @@ -49,17 +49,11 @@ export class ApiImport extends ApiBase { * * Not available in the Localazy API Docs yet. */ - public async getProgress( - request: ImportProgressRequest, - config?: RequestConfig, - ): Promise { + 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; + return (await this.api.client.get(`/projects/${projectId}/import/${importBatch}`, config)) as UploadSessionStatus; } protected async getImportedFile( diff --git a/src/enums/upload-status.ts b/src/enums/upload-status.ts index 4861dbc..b63e043 100644 --- a/src/enums/upload-status.ts +++ b/src/enums/upload-status.ts @@ -1,8 +1,8 @@ export enum UploadStatus { - NOT_FOUND = "not_found", - SCHEDULED = "scheduled", - IN_PROGRESS = "in_progress", - DONE = "done", - INVALID_ID = "invalid_id", - ERROR = "error" + NOT_FOUND = 'not_found', + SCHEDULED = 'scheduled', + IN_PROGRESS = 'in_progress', + DONE = 'done', + INVALID_ID = 'invalid_id', + ERROR = 'error', } diff --git a/src/types/key-deprecate-request.ts b/src/types/key-deprecate-request.ts index 5a8055c..ad35bf7 100644 --- a/src/types/key-deprecate-request.ts +++ b/src/types/key-deprecate-request.ts @@ -1,5 +1,5 @@ -import { Project } from "@/types/project"; -import { Key } from "@/types/key"; +import { Project } from '@/types/project'; +import { Key } from '@/types/key'; export type KeyDeprecateRequest = { /** @@ -10,5 +10,5 @@ export type KeyDeprecateRequest = { /** * List of keys identifiers to deprecate. */ - phrases: Key[] | Pick[] | string[]; -} + phrases: Key[] | Pick[] | string[]; +}; diff --git a/src/types/upload-session-status.ts b/src/types/upload-session-status.ts index 62dd391..cb6f970 100644 --- a/src/types/upload-session-status.ts +++ b/src/types/upload-session-status.ts @@ -1,4 +1,4 @@ -import { UploadStatus } from "@/enums/upload-status" +import { UploadStatus } from '@/enums/upload-status'; export type UploadSessionStatus = { /** @@ -20,4 +20,4 @@ export type UploadSessionStatus = { * Number of keys deprecated in the upload session. */ deprecated?: number; -} +};