Skip to content

Commit

Permalink
api updates (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ authored Jul 18, 2021
1 parent fca155d commit cefe17d
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 97 deletions.
2 changes: 1 addition & 1 deletion 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.11.1",
"version": "1.11.2",
"description": "JavaScript library for Crowdin API v2.",
"main": "out/index.js",
"types": "out/index.d.ts",
Expand Down
29 changes: 28 additions & 1 deletion src/projectsGroups/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ export namespace ProjectsGroupsModel {
vendorId?: number;
mtEngineId?: number;
description?: string;
translateDuplicates?: TranslateDuplicates;
isMtAllowed?: boolean;
autoSubstitution?: boolean;
autoTranslateDialects?: boolean;
publicDownloads?: boolean;
useGlobalTm?: boolean;
delayedWorkflowStart?: boolean;
skipUntranslatedStrings?: boolean;
skipUntranslatedFiles?: boolean;
Expand All @@ -178,12 +184,20 @@ export namespace ProjectsGroupsModel {
identifier?: string;
normalizePlaceholder?: boolean;
saveMetaInfoInSource?: boolean;
inContext?: boolean;
inContextProcessHiddenStrings?: boolean;
inContextPseudoLanguageId?: string;
qaCheckIsActive?: boolean;
qaCheckCategories?: CheckCategories;
customQaCheckIds?: number[];
languageMapping?: LanguageMapping;
}

export interface ProjectSettings extends Project {
translateDuplicates: number;
translateDuplicates: TranslateDuplicates;
isMtAllowed: boolean;
autoSubstitution: boolean;
exportTranslatedOnly: boolean;
skipUntranslatedStrings: boolean;
skipUntranslatedFiles: boolean;
exportApprovedOnly: boolean;
Expand All @@ -193,13 +207,15 @@ export namespace ProjectsGroupsModel {
normalizePlaceholder: boolean;
saveMetaInfoInSource: boolean;
inContext: boolean;
inContextProcessHiddenStrings: string;
inContextPseudoLanguageId: string;
isSuspended: string;
qaCheckIsActive: boolean;
qaCheckCategories: CheckCategories;
customQaCheckIds: number[];
languageMapping: LanguageMapping;
inContextPseudoLanguage: LanguagesModel.Language;
delayedWorkflowStart: boolean;
}

export enum Type {
Expand Down Expand Up @@ -229,6 +245,8 @@ export namespace ProjectsGroupsModel {
wrongTranslation: boolean;
spellcheck: boolean;
icu: boolean;
terms: boolean;
duplicate: boolean;
}

export interface LanguageMapping {
Expand All @@ -245,4 +263,13 @@ export namespace ProjectsGroupsModel {
osx_code: string;
osx_locale: string;
}

export enum TranslateDuplicates {
SHOW = 0,
HIDE_REGULAR_DETECTION = 1,
SHOW_AUTO_TRANSLATE = 2,
SHOW_WITHIN_VERION_BRANCH_REGULAR_DETECTION = 3,
HIDE_STRICT_DETECTION = 4,
SHOW_WITHIN_VERION_BRANCH_STRICT_DETECTION = 5,
}
}
3 changes: 3 additions & 0 deletions src/sourceFiles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ export namespace SourceFilesModel {
exportOptions: GeneralExportOptions | PropertyExportOptions;
createdAt: string;
updatedAt: string;
excludedTargetLanguages: string[];
}

export interface CreateFileRequest {
Expand Down Expand Up @@ -498,10 +499,12 @@ export namespace SourceFilesModel {
translateAttributes: boolean;
contentSegmentation: boolean;
translatableElements: string[];
srxStorageId: number;
}

export interface OtherImportOptions {
contentSegmentation: boolean;
srxStorageId: number;
}

export interface GeneralExportOptions {
Expand Down
94 changes: 39 additions & 55 deletions src/users/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
import { CrowdinApi, Pagination, ResponseList, ResponseObject } from '../core';

export class Users extends CrowdinApi {
/**
*
* @param projectId project identifier
* @param search search users by firstName, lastName or username
* @param role defines role type
* @param languageId language identifier
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
*/
listProjectMembers(
projectId: number,
search?: string,
role?: UsersModel.Role,
languageId?: string,
limit?: number,
offset?: number,
): Promise<ResponseList<UsersModel.ProjectMember>> {
let url = `${this.url}/projects/${projectId}/members`;
url = this.addQueryParam(url, 'search', search);
url = this.addQueryParam(url, 'role', role);
url = this.addQueryParam(url, 'languageId', languageId);
return this.getList(url, limit, offset);
}

/**
*
* @param projectId project identifier
Expand All @@ -22,7 +46,7 @@ export class Users extends CrowdinApi {
getProjectMemberPermissions(
projectId: number,
memberId: number,
): Promise<ResponseObject<UsersModel.ProjectMemberPermissions>> {
): Promise<ResponseObject<UsersModel.ProjectMember>> {
const url = `${this.url}/projects/${projectId}/members/${memberId}`;
return this.get(url, this.defaultConfig());
}
Expand All @@ -36,7 +60,7 @@ export class Users extends CrowdinApi {
projectId: number,
memberId: number,
request: UsersModel.ReplaceProjectMemberRequest,
): Promise<ResponseObject<UsersModel.ProjectMemberPermissions>> {
): Promise<ResponseObject<UsersModel.ProjectMember>> {
const url = `${this.url}/projects/${projectId}/members/${memberId}`;
return this.put(url, request, this.defaultConfig());
}
Expand Down Expand Up @@ -84,40 +108,6 @@ export class Users extends CrowdinApi {
const url = `${this.url}/user`;
return this.get(url, this.defaultConfig());
}

/**
*
* @param projectId project identifier
* @param search search users by firstName, lastName or username
* @param role defines role type
* @param languageId language identifier
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
*/
listProjectMembers(
projectId: number,
search?: string,
role?: UsersModel.Role,
languageId?: string,
limit?: number,
offset?: number,
): Promise<ResponseList<UsersModel.ProjectMember>> {
let url = `${this.url}/projects/${projectId}/members`;
url = this.addQueryParam(url, 'search', search);
url = this.addQueryParam(url, 'role', role);
url = this.addQueryParam(url, 'languageId', languageId);
return this.getList(url, limit, offset);
}

/**
*
* @param projectId project identifier
* @param memberId member identifier
*/
getMemberInfo(projectId: number, memberId: number): Promise<ResponseObject<UsersModel.ProjectMember>> {
const url = `${this.url}/projects/${projectId}/members/${memberId}`;
return this.get(url, this.defaultConfig());
}
}

export namespace UsersModel {
Expand Down Expand Up @@ -151,11 +141,22 @@ export namespace UsersModel {
id: number;
username: string;
fullName: string;
firstName: string;
lastName: string;
isManager: boolean;
managerOfGroup: Group;
accessToAllWorkflowSteps: boolean;
role: Role;
permissions: any;
avatarUrl: string;
joinedAt: string;
timezone: string;
givenAccessAt: string;
}

export interface Group {
id: number;
name: string;
}

export enum Role {
Expand All @@ -166,23 +167,6 @@ export namespace UsersModel {
BLOCKED = 'blocked',
}

export interface ProjectMemberPermissions {
id: number;
username: string;
firstName: string;
lastName: string;
isManager: boolean;
managerOfGroup: Manager;
accessToAllWorkflowSteps: boolean;
permissions: any;
givenAccessAt: string;
}

export interface Manager {
id: number;
name: string;
}

export interface AddProjectMemberRequest {
userIds: number[];
accessToAllWorkflowSteps?: boolean;
Expand All @@ -191,8 +175,8 @@ export namespace UsersModel {
}

export interface AddProjectMemberResponse {
skipped: ResponseObject<ProjectMemberPermissions>[];
added: ResponseObject<ProjectMemberPermissions>[];
skipped: ResponseObject<ProjectMember>[];
added: ResponseObject<ProjectMember>[];
pagination: Pagination;
}

Expand Down
63 changes: 24 additions & 39 deletions tests/users/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ describe('Users API', () => {

beforeAll(() => {
scope = nock(api.url)
.get(`/projects/${projectId}/members`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: [
{
data: {
id: id,
},
},
],
pagination: {
offset: 0,
limit: limit,
},
})
.post(
`/projects/${projectId}/members`,
{
Expand Down Expand Up @@ -99,34 +117,6 @@ describe('Users API', () => {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: {
id: id,
},
})
.get(`/projects/${projectId}/members`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: [
{
data: {
id: id,
},
},
],
pagination: {
offset: 0,
limit: limit,
},
})
.get(`/projects/${projectId}/members/${id}`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: {
id: id,
Expand All @@ -138,6 +128,12 @@ describe('Users API', () => {
scope.done();
});

it('List Project Members', async () => {
const members = await api.listProjectMembers(projectId);
expect(members.data.length).toBe(1);
expect(members.data[0].data.id).toBe(id);
});

it('Add Project Member', async () => {
const resp = await api.addProjectMember(projectId, {
userIds: [id],
Expand Down Expand Up @@ -176,15 +172,4 @@ describe('Users API', () => {
const user = await api.getAuthenticatedUser();
expect(user.data.id).toBe(id);
});

it('List Project Members', async () => {
const members = await api.listProjectMembers(projectId);
expect(members.data.length).toBe(1);
expect(members.data[0].data.id).toBe(id);
});

it('Get Member Info', async () => {
const user = await api.getMemberInfo(projectId, id);
expect(user.data.id).toBe(id);
});
});

0 comments on commit cefe17d

Please sign in to comment.