Skip to content

Commit

Permalink
Api updates (#218)
Browse files Browse the repository at this point in the history
* added docx file import options

* added project file format settings api methods

* version increment
  • Loading branch information
yevheniyJ authored Dec 28, 2022
1 parent 0023672 commit 933d696
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@crowdin/crowdin-api-client",
"version": "1.20.0",
"version": "1.20.1",
"description": "JavaScript library for Crowdin API v2.",
"main": "out/index.js",
"types": "out/index.d.ts",
Expand Down
139 changes: 139 additions & 0 deletions src/projectsGroups/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
BooleanInt,
CrowdinApi,
DownloadLink,
isOptionalNumber,
PaginationOptions,
PatchRequest,
Expand Down Expand Up @@ -181,6 +182,96 @@ export class ProjectsGroups extends CrowdinApi {
const url = `${this.url}/projects/${projectId}`;
return this.patch(url, request, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param fileFormatSettingsId file format settings identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.file-format-settings.custom-segmentations.get
*/
downloadProjectFileFormatSettingsCustomSegmentation(
projectId: number,
fileFormatSettingsId: number,
): Promise<ResponseObject<DownloadLink>> {
const url = `${this.url}/projects/${projectId}/file-format-settings/${fileFormatSettingsId}/custom-segmentations`;
return this.get(url, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param fileFormatSettingsId file format settings identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.file-format-settings.custom-segmentations.delete
*/
resetProjectFileFormatSettingsCustomSegmentation(
projectId: number,
fileFormatSettingsId: number,
): Promise<ResponseObject<DownloadLink>> {
const url = `${this.url}/projects/${projectId}/file-format-settings/${fileFormatSettingsId}/custom-segmentations`;
return this.delete(url, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param options optional parameters for the request
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.file-format-settings.getMany
*/
listProjectFileFormatSettings(
projectId: number,
options?: PaginationOptions,
): Promise<ResponseList<ProjectsGroupsModel.ProjectFileFormatSettings>> {
const url = `${this.url}/projects/${projectId}/file-format-settings`;
return this.getList(url, options?.limit, options?.offset);
}

/**
* @param projectId project identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.file-format-settings.post
*/
addProjectFileFormatSettings(
projectId: number,
request: ProjectsGroupsModel.AddProjectFileFormatSettingsRequest,
): Promise<ResponseObject<ProjectsGroupsModel.ProjectFileFormatSettings>> {
const url = `${this.url}/projects/${projectId}/file-format-settings`;
return this.post(url, request, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param fileFormatSettingsId file format settings identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.file-format-settings.get
*/
getProjectFileFormatSettings(
projectId: number,
fileFormatSettingsId: number,
): Promise<ResponseObject<ProjectsGroupsModel.ProjectFileFormatSettings>> {
const url = `${this.url}/projects/${projectId}/file-format-settings/${fileFormatSettingsId}`;
return this.get(url, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param fileFormatSettingsId file format settings identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.file-format-settings.delete
*/
deleteProjectFileFormatSettings(projectId: number, fileFormatSettingsId: number): Promise<void> {
const url = `${this.url}/projects/${projectId}/file-format-settings/${fileFormatSettingsId}`;
return this.delete(url, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param fileFormatSettingsId file format settings identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.file-format-settings.patch
*/
editProjectFileFormatSettings(
projectId: number,
fileFormatSettingsId: number,
request: PatchRequest[],
): Promise<ResponseObject<ProjectsGroupsModel.ProjectFileFormatSettings>> {
const url = `${this.url}/projects/${projectId}/file-format-settings/${fileFormatSettingsId}`;
return this.patch(url, request, this.defaultConfig());
}
}

export namespace ProjectsGroupsModel {
Expand Down Expand Up @@ -415,4 +506,52 @@ export namespace ProjectsGroupsModel {
groupId?: number;
hasManagerAccess?: BooleanInt;
}

export type Settings =
| PropertyFileFormatSettings
| CommonFileFormatSettings
| XmlFileFormatSettings
| DocxFileFormatSettings;

export interface ProjectFileFormatSettings {
id: number;
name: string;
format: string;
extensions: string[];
settings: Settings;
createdAt: string;
updatedAt: string;
}

export interface AddProjectFileFormatSettingsRequest {
format: string;
settings: Settings;
}

export interface PropertyFileFormatSettings {
escapeQuotes?: 0 | 1 | 2 | 3;
escapeSpecialCharacters?: 0 | 1;
exportPattern?: string;
}

export interface CommonFileFormatSettings {
contentSegmentation?: boolean;
srxStorageId?: number;
exportPattern?: string;
}

export interface XmlFileFormatSettings extends CommonFileFormatSettings {
translateContent?: boolean;
translateAttributes?: boolean;
translatableElements?: string[];
}

export interface DocxFileFormatSettings extends CommonFileFormatSettings {
cleanTagsAggressively?: boolean;
translateHiddenText?: boolean;
translateHyperlinkUrls?: boolean;
translateHiddenRowsAndColumns?: boolean;
importNotes?: boolean;
importHiddenSlides?: boolean;
}
}
17 changes: 14 additions & 3 deletions src/sourceFiles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ export namespace SourceFilesModel {
status: string;
priority: Priority;
path: string;
importOptions: SpreadsheetImportOptions | XmlImportOptions | OtherImportOptions;
importOptions: SpreadsheetImportOptions | XmlImportOptions | OtherImportOptions | DocxFileImportOptions;
exportOptions: GeneralExportOptions | PropertyExportOptions;
createdAt: string;
updatedAt: string;
Expand All @@ -544,7 +544,7 @@ export namespace SourceFilesModel {
directoryId?: number;
title?: string;
type?: FileType;
importOptions?: SpreadsheetImportOptions | XmlImportOptions | OtherImportOptions;
importOptions?: SpreadsheetImportOptions | XmlImportOptions | OtherImportOptions | DocxFileImportOptions;
exportOptions?: GeneralExportOptions | PropertyExportOptions;
attachLabelIds?: number[];
excludedTargetLanguages?: string[];
Expand All @@ -553,7 +553,7 @@ export namespace SourceFilesModel {
export interface ReplaceFileFromStorageRequest {
storageId: number;
updateOption?: UpdateOption;
importOptions?: SpreadsheetImportOptions | XmlImportOptions | OtherImportOptions;
importOptions?: SpreadsheetImportOptions | XmlImportOptions | OtherImportOptions | DocxFileImportOptions;
exportOptions?: GeneralExportOptions | PropertyExportOptions;
attachLabelIds?: number[];
detachLabelIds?: number[];
Expand Down Expand Up @@ -642,6 +642,17 @@ export namespace SourceFilesModel {
srxStorageId: number;
}

export interface DocxFileImportOptions {
cleanTagsAggressively: boolean;
translateHiddenText: boolean;
translateHyperlinkUrls: boolean;
translateHiddenRowsAndColumns: boolean;
importNotes: boolean;
importHiddenSlides: boolean;
contentSegmentation: boolean;
srxStorageId: number;
}

export interface OtherImportOptions {
contentSegmentation: boolean;
srxStorageId: number;
Expand Down
145 changes: 145 additions & 0 deletions tests/projectsGroups/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ describe('Projects and Groups API', () => {
const groupName = 'testGroup';
const sourceLanguageId = 'uk';

const fileFormatSettingsId = 123;
const format = 'docx';
const url = 'crowdin.com';

const limit = 25;

beforeAll(() => {
Expand Down Expand Up @@ -164,6 +168,102 @@ describe('Projects and Groups API', () => {
id: projectId,
name: projectName,
},
})
.get(
`/projects/${projectId}/file-format-settings/${fileFormatSettingsId}/custom-segmentations`,
undefined,
{
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
},
)
.reply(200, {
data: {
url,
},
})
.delete(
`/projects/${projectId}/file-format-settings/${fileFormatSettingsId}/custom-segmentations`,
undefined,
{
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
},
)
.reply(200)
.get(`/projects/${projectId}/file-format-settings`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: [
{
data: {
id: fileFormatSettingsId,
},
},
],
pagination: {
offset: 0,
limit: limit,
},
})
.post(
`/projects/${projectId}/file-format-settings`,
{
format,
settings: {},
},
{
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
},
)
.reply(200, {
data: {
id: fileFormatSettingsId,
},
})
.get(`/projects/${projectId}/file-format-settings/${fileFormatSettingsId}`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: {
id: fileFormatSettingsId,
},
})
.delete(`/projects/${projectId}/file-format-settings/${fileFormatSettingsId}`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200)
.patch(
`/projects/${projectId}/file-format-settings/${fileFormatSettingsId}`,
[
{
value: format,
op: 'replace',
path: '/format',
},
],
{
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
},
)
.reply(200, {
data: {
id: fileFormatSettingsId,
format,
},
});
});

Expand Down Expand Up @@ -245,4 +345,49 @@ describe('Projects and Groups API', () => {
expect(project.data.id).toBe(projectId);
expect(project.data.name).toBe(projectName);
});

it('Download project file format settings custom segmentation', async () => {
const link = await api.downloadProjectFileFormatSettingsCustomSegmentation(projectId, fileFormatSettingsId);
expect(link.data.url).toBe(url);
});

it('Reset project file format settings custom segmentation', async () => {
await api.resetProjectFileFormatSettingsCustomSegmentation(projectId, fileFormatSettingsId);
});

it('List project file format settings', async () => {
const fileSettingsList = await api.listProjectFileFormatSettings(projectId);
expect(fileSettingsList.data.length).toBe(1);
expect(fileSettingsList.data[0].data.id).toBe(fileFormatSettingsId);
expect(fileSettingsList.pagination.limit).toBe(limit);
});

it('Add project file format settings', async () => {
const fileSettings = await api.addProjectFileFormatSettings(projectId, {
format,
settings: {},
});
expect(fileSettings.data.id).toBe(fileFormatSettingsId);
});

it('Get project file format settings', async () => {
const fileSettings = await api.getProjectFileFormatSettings(projectId, fileFormatSettingsId);
expect(fileSettings.data.id).toBe(fileFormatSettingsId);
});

it('Delete project file format settings', async () => {
await api.deleteProjectFileFormatSettings(projectId, fileFormatSettingsId);
});

it('Edit project file format settings', async () => {
const fileSettings = await api.editProjectFileFormatSettings(projectId, fileFormatSettingsId, [
{
op: 'replace',
path: '/format',
value: format,
},
]);
expect(fileSettings.data.id).toBe(fileFormatSettingsId);
expect(fileSettings.data.format).toBe(format);
});
});

0 comments on commit 933d696

Please sign in to comment.