Skip to content

Commit

Permalink
LOC-1114 - Figma Fixes and Improvements (#22)
Browse files Browse the repository at this point in the history
* ✨ feat(Import): add upload status endpoint

* ✨ feat(Key): add deprecate endpoint

* 🐛 fix:(screenshots): fix `removeMetadata` data type

* 🐛 fix(screenshots): fix `addMetadata` and `removeMetadata` params casing

* ✨ feat(`listKeys`): add support for `metadata` parameter

* 🚨 lint: fix

---------

Co-authored-by: david-vaclavek <[email protected]>
  • Loading branch information
david-vaclavek and david-vaclavek authored Jul 16, 2024
1 parent cf94fbe commit 7335902
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/api/methods/api-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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<UploadSessionStatus> {
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,
Expand Down
26 changes: 26 additions & 0 deletions src/api/methods/api-keys.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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<void> {
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);
}
}
8 changes: 8 additions & 0 deletions src/enums/upload-status.ts
Original file line number Diff line number Diff line change
@@ -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',
}
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand All @@ -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';
Expand Down
5 changes: 5 additions & 0 deletions src/types/file-list-keys-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
13 changes: 13 additions & 0 deletions src/types/import-progress-request.ts
Original file line number Diff line number Diff line change
@@ -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;
};
14 changes: 14 additions & 0 deletions src/types/key-deprecate-request.ts
Original file line number Diff line number Diff line change
@@ -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<Key, 'id'>[] | string[];
};
4 changes: 2 additions & 2 deletions src/types/screenshot-update-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 23 additions & 0 deletions src/types/upload-session-status.ts
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 7335902

Please sign in to comment.