Skip to content

Commit

Permalink
feat: applications api updates (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ committed Jul 7, 2024
1 parent c1f7df4 commit 2ebbc05
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
76 changes: 42 additions & 34 deletions src/applications/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CrowdinApi, ResponseObject, PatchRequest, Pagination } from '../core';
import { CrowdinApi, ResponseObject, PatchRequest, Pagination, ResponseList } from '../core';

/**
* Crowdin Apps are web applications that can be integrated with Crowdin to extend its functionality.
Expand All @@ -10,29 +10,27 @@ export class Applications extends CrowdinApi {
* @param options optional pagination parameters for the request
* @see https://developer.crowdin.com/api/v2/#operation/api.applications.installations.getMany
*/
listApplicationInstallations(options?: Pagination): Promise<ResponseObject<ApplicationsModel.ApplicationData>> {
listApplicationInstallations(options?: Pagination): Promise<ResponseList<ApplicationsModel.Application>> {
const url = `${this.url}/applications/installations`;
return this.getList(url, options?.limit, options?.offset);
}

/**
* @param applicationUrl Manifest URL
* @param permissions application permissions
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.applications.installations.post
*/
installApplication(
applicationUrl: string,
permissions?: ApplicationsModel.ApplicationPermissions,
): Promise<ResponseObject<ApplicationsModel.ApplicationData>> {
request: ApplicationsModel.InstallApplication,
): Promise<ResponseObject<ApplicationsModel.Application>> {
const url = `${this.url}/applications/installations`;
return this.post(url, { url: applicationUrl, permissions: permissions }, this.defaultConfig());
return this.post(url, request, this.defaultConfig());
}

/**
* @param applicationId application identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.applications.installations.get
*/
getApplicationInstallation(applicationId: string): Promise<ResponseObject<ApplicationsModel.ApplicationData>> {
getApplicationInstallation(applicationId: string): Promise<ResponseObject<ApplicationsModel.Application>> {
const url = `${this.url}/applications/installations/${applicationId}`;
return this.get(url, this.defaultConfig());
}
Expand All @@ -45,7 +43,7 @@ export class Applications extends CrowdinApi {
deleteApplicationInstallation(
applicationId: string,
force?: boolean,
): Promise<ResponseObject<ApplicationsModel.ApplicationData>> {
): Promise<ResponseObject<ApplicationsModel.Application>> {
const url = `${this.url}/applications/installations/${applicationId}`;
if (force) {
this.addQueryParam(url, 'force', String(force));
Expand All @@ -61,7 +59,7 @@ export class Applications extends CrowdinApi {
editApplicationInstallation(
applicationId: string,
request: PatchRequest[],
): Promise<ResponseObject<ApplicationsModel.ApplicationData>> {
): Promise<ResponseObject<ApplicationsModel.Application>> {
const url = `${this.url}/applications/installations/${applicationId}`;
return this.patch(url, request, this.defaultConfig());
}
Expand All @@ -71,10 +69,7 @@ export class Applications extends CrowdinApi {
* @param path path implemented by the application
* @see https://developer.crowdin.com/api/v2/#operation/api.applications.api.get
*/
getApplicationData(
applicationId: string,
path: string,
): Promise<ResponseObject<ApplicationsModel.ApplicationData>> {
getApplicationData(applicationId: string, path: string): Promise<ResponseObject<any>> {

Check warning on line 72 in src/applications/index.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Unexpected any. Specify a different type
const url = `${this.url}/applications/${applicationId}/api/${path}`;
return this.get(url, this.defaultConfig());
}
Expand All @@ -85,11 +80,7 @@ export class Applications extends CrowdinApi {
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.applications.api.put
*/
updateOrRestoreApplicationData(
applicationId: string,
path: string,
request: ApplicationsModel.ApplicationData,
): Promise<ResponseObject<ApplicationsModel.ApplicationData>> {
updateOrRestoreApplicationData(applicationId: string, path: string, request: any): Promise<ResponseObject<any>> {

Check warning on line 83 in src/applications/index.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Unexpected any. Specify a different type

Check warning on line 83 in src/applications/index.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Unexpected any. Specify a different type
const url = `${this.url}/applications/${applicationId}/api/${path}`;
return this.put(url, request, this.defaultConfig());
}
Expand All @@ -100,11 +91,7 @@ export class Applications extends CrowdinApi {
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.applications.api.post
*/
addApplicationData(
applicationId: string,
path: string,
request: ApplicationsModel.ApplicationData,
): Promise<ResponseObject<ApplicationsModel.ApplicationData>> {
addApplicationData(applicationId: string, path: string, request: any): Promise<ResponseObject<any>> {

Check warning on line 94 in src/applications/index.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Unexpected any. Specify a different type

Check warning on line 94 in src/applications/index.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Unexpected any. Specify a different type
const url = `${this.url}/applications/${applicationId}/api/${path}`;
return this.post(url, request, this.defaultConfig());
}
Expand All @@ -125,29 +112,50 @@ export class Applications extends CrowdinApi {
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.applications.api.patch
*/
editApplicationData(
applicationId: string,
path: string,
request: ApplicationsModel.ApplicationData,
): Promise<ResponseObject<ApplicationsModel.ApplicationData>> {
editApplicationData(applicationId: string, path: string, request: any): Promise<ResponseObject<any>> {

Check warning on line 115 in src/applications/index.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Unexpected any. Specify a different type

Check warning on line 115 in src/applications/index.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Unexpected any. Specify a different type
const url = `${this.url}/applications/${applicationId}/api/${path}`;
return this.patch(url, request, this.defaultConfig());
}
}

export namespace ApplicationsModel {
export interface ApplicationData {
[key: string]: any;
export interface Application {
identifier: string;
name: string;
description: string;
logo: string;
baseUrl: string;
manifestUrl: string;
createdAt: string;
modules: ApplicationModule[];
scopes: string[];
permissions: ApplicationPermissions;
defaultPermissions: any;

Check warning on line 133 in src/applications/index.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Unexpected any. Specify a different type
limitReached: boolean;
}

export interface InstallApplication {
url: string;
permissions?: ApplicationPermissions;
modules?: ApplicationModule[];
}

export interface ApplicationPermissions {
user: {
value: 'all' | 'owner' | 'managers' | 'guests' | 'restricted';
ids: Array<number>;
ids: number[];
};
project: {
value: 'own' | 'restricted';
ids: Array<number>;
ids: number[];
};
}

export interface ApplicationModule {
key: string;
type?: string;
data?: any;
authenticationType?: string;
permissions: Omit<ApplicationPermissions, 'project'>;
}
}
4 changes: 0 additions & 4 deletions src/translations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,6 @@ export namespace TranslationsModel {
importEqSuggestions?: boolean;
autoApproveImported?: boolean;
translateHidden?: boolean;
/**
* @deprecated
*/
markAddedTranslationsAsDone?: boolean;
}

export interface UploadTranslationStringsRequest {
Expand Down
4 changes: 3 additions & 1 deletion tests/applications/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ describe('Applications API', () => {
});

it('Install Application', async () => {
await api.installApplication('https://localhost.dev/crowdin.json');
await api.installApplication({
url: 'https://localhost.dev/crowdin.json',
});
});

it('Get Application Installation', async () => {
Expand Down

0 comments on commit 2ebbc05

Please sign in to comment.