Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Strings based API methods #328

Merged
merged 25 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/applications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
* @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<JSON>> {
getApplicationData(
applicationId: string,
path: string,
): Promise<ResponseObject<ApplicationsModel.ApplicationData>> {
const url = `${this.url}/applications/${applicationId}/api/${path}`;
return this.get(url, this.defaultConfig());
}
Expand All @@ -26,7 +29,7 @@
applicationId: string,
path: string,
request: ApplicationsModel.ApplicationData,
): Promise<ResponseObject<JSON>> {
): Promise<ResponseObject<ApplicationsModel.ApplicationData>> {
const url = `${this.url}/applications/${applicationId}/api/${path}`;
return this.put(url, request, this.defaultConfig());
}
Expand All @@ -41,7 +44,7 @@
applicationId: string,
path: string,
request: ApplicationsModel.ApplicationData,
): Promise<ResponseObject<JSON>> {
): Promise<ResponseObject<ApplicationsModel.ApplicationData>> {
const url = `${this.url}/applications/${applicationId}/api/${path}`;
return this.post(url, request, this.defaultConfig());
}
Expand All @@ -66,7 +69,7 @@
applicationId: string,
path: string,
request: ApplicationsModel.ApplicationData,
): Promise<ResponseObject<JSON>> {
): Promise<ResponseObject<ApplicationsModel.ApplicationData>> {
const url = `${this.url}/applications/${applicationId}/api/${path}`;
return this.patch(url, request, this.defaultConfig());
}
Expand All @@ -74,6 +77,6 @@

export namespace ApplicationsModel {
export interface ApplicationData {
[key: string]: any;

Check warning on line 80 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 80 in src/applications/index.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Unexpected any. Specify a different type
}
}
31 changes: 18 additions & 13 deletions src/bundles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,38 @@ export class Bundles extends CrowdinApi {
projectId: number,
bundleId: number,
options?: PaginationOptions,
): Promise<ResponseList<BundlesModel.BundleFile>> {
): Promise<ResponseList<SourceFilesModel.File>> {
const url = `${this.url}/projects/${projectId}/bundles/${bundleId}/files`;
return this.getList(url, options?.limit, options?.offset);
}

/**
* @param projectId project identifier
* @param bundleId bundle identifier
* @param options optional parameters for the request
*/
listBundleBranches(
projectId: number,
bundleId: number,
options?: PaginationOptions,
): Promise<ResponseList<SourceFilesModel.Branch>> {
const url = `${this.url}/projects/${projectId}/bundles/${bundleId}/branches`;
return this.getList(url, options?.limit, options?.offset);
}
}

export namespace BundlesModel {
export interface Bundle {
id: number;
name: string;
format: string;
sourcePatterns: string[];
ignorePatterns: string[];
exportPattern: string;
isMultilingual: boolean;
includeProjectSourceLanguage: boolean;
labelIds: number[];
excludeLabelIds: number[];
createdAt: string;
updatedAt: string;
}
Expand All @@ -143,18 +159,7 @@ export namespace BundlesModel {
isMultilingual?: boolean;
includeProjectSourceLanguage?: boolean;
labelIds?: number[];
}

export interface BundleFile {
id: number;
projectId: number;
branchId: number;
directoryId: number;
name: string;
title: string;
type: SourceFilesModel.FileType;
path: string;
status: string;
excludeLabelIds?: number[];
}

export interface ExportAttributes {
Expand Down
27 changes: 27 additions & 0 deletions src/clients/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CrowdinApi, PaginationOptions, ResponseList } from '../core';

/**
* Clients are the organizations that order professional translation services from Vendors.
* Clients can invite an existing organization to become a Vendor for them.
*
* Use the API to get a list of the Clients you already cooperate with as a Vendor.
*/
export class Clients extends CrowdinApi {
/**
* @param options optional pagination parameters for the request
* @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.clients.getMany
*/
listClients(options?: PaginationOptions): Promise<ResponseList<ClientsModel.Client>> {
const url = `${this.url}/clients`;
return this.getList(url, options?.limit, options?.offset);
}
}

export namespace ClientsModel {
export interface Client {
id: number;
name: string;
description: string;
status: 'pending' | 'confirmed' | 'rejected';
}
}
25 changes: 22 additions & 3 deletions src/distributions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export class Distributions extends CrowdinApi {
*/
createDistribution(
projectId: number,
request: DistributionsModel.CreateDistributionRequest,
request:
| DistributionsModel.CreateDistributionRequest
| DistributionsModel.CreateDistributionStringsBasedRequest,
): Promise<ResponseObject<DistributionsModel.Distribution>> {
const url = `${this.url}/projects/${projectId}/distributions`;
return this.post(url, request, this.defaultConfig());
Expand Down Expand Up @@ -90,7 +92,9 @@ export class Distributions extends CrowdinApi {
getDistributionRelease(
projectId: number,
hash: string,
): Promise<ResponseObject<DistributionsModel.DistributionRelease>> {
): Promise<
ResponseObject<DistributionsModel.DistributionRelease | DistributionsModel.DistributionStringsBasedRelease>
> {
const url = `${this.url}/projects/${projectId}/distributions/${hash}/release`;
return this.get(url, this.defaultConfig());
}
Expand All @@ -104,7 +108,9 @@ export class Distributions extends CrowdinApi {
createDistributionRelease(
projectId: number,
hash: string,
): Promise<ResponseObject<DistributionsModel.DistributionRelease>> {
): Promise<
ResponseObject<DistributionsModel.DistributionRelease | DistributionsModel.DistributionStringsBasedRelease>
> {
const url = `${this.url}/projects/${projectId}/distributions/${hash}/release`;
return this.post(url, {}, this.defaultConfig());
}
Expand Down Expand Up @@ -143,6 +149,11 @@ export namespace DistributionsModel {
labelIds?: number[];
}

export interface CreateDistributionStringsBasedRequest {
name: string;
bundleIds: number[];
}

export interface DistributionRelease {
status: string;
progress: number;
Expand All @@ -151,5 +162,13 @@ export namespace DistributionsModel {
date: string;
}

export interface DistributionStringsBasedRelease {
status: string;
progress: number;
currentLanguageId: string;
currentBranchId: number;
date: string;
}

export type ExportMode = 'default' | 'bundle';
}
1 change: 1 addition & 0 deletions src/glossaries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ export namespace GlossariesModel {
type?: Type;
gender?: Gender;
note?: string;
url?: string;
conceptId?: number;
}

Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Applications } from './applications';
import { Bundles } from './bundles';
import { Clients } from './clients';
import { ClientConfig, Credentials, CrowdinApi } from './core';
import { Dictionaries } from './dictionaries';
import { Distributions } from './distributions';
Expand Down Expand Up @@ -30,6 +31,7 @@ import { Workflows } from './workflows';

export * from './applications';
export * from './bundles';
export * from './clients';
export * from './core';
export * from './dictionaries';
export * from './distributions';
Expand Down Expand Up @@ -93,6 +95,7 @@ export default class Client extends CrowdinApi {
readonly stringCommentsApi: StringComments;
readonly bundlesApi: Bundles;
readonly notificationsApi: Notifications;
readonly clientsApi: Clients;

constructor(credentials: Credentials, config?: ClientConfig) {
super(credentials, config);
Expand Down Expand Up @@ -124,5 +127,6 @@ export default class Client extends CrowdinApi {
this.stringCommentsApi = new StringComments(credentials, config);
this.bundlesApi = new Bundles(credentials, config);
this.notificationsApi = new Notifications(credentials, config);
this.clientsApi = new Clients(credentials, config);
}
}
12 changes: 9 additions & 3 deletions src/labels/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Labels extends CrowdinApi {
* @param options optional pagination parameters for the request
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.labels.getMany
*/
listLabels(projectId: number, options?: PaginationOptions): Promise<ResponseList<LabelsModel.Label>>;
listLabels(projectId: number, options?: LabelsModel.ListLabelsParams): Promise<ResponseList<LabelsModel.Label>>;
/**
* @param projectId project identifier
* @param limit maximum number of items to retrieve (default 25)
Expand All @@ -19,13 +19,14 @@ export class Labels extends CrowdinApi {
listLabels(projectId: number, limit?: number, offset?: number): Promise<ResponseList<LabelsModel.Label>>;
listLabels(
projectId: number,
options?: number | PaginationOptions,
options?: number | LabelsModel.ListLabelsParams,
deprecatedOffset?: number,
): Promise<ResponseList<LabelsModel.Label>> {
if (isOptionalNumber(options, '1' in arguments)) {
options = { limit: options, offset: deprecatedOffset };
}
const url = `${this.url}/projects/${projectId}/labels`;
let url = `${this.url}/projects/${projectId}/labels`;
url = this.addQueryParam(url, 'isSystem', options.isSystem);
return this.getList(url, options.limit, options.offset);
}

Expand Down Expand Up @@ -134,9 +135,14 @@ export class Labels extends CrowdinApi {
}

export namespace LabelsModel {
export interface ListLabelsParams extends PaginationOptions {
isSystem?: number;
}

export interface Label {
id: number;
title: string;
isSystem: boolean;
}

export interface AddLabelRequest {
Expand Down
20 changes: 16 additions & 4 deletions src/machineTranslation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,29 @@ export namespace MachineTranslationModel {
type: number;
credentials: Credentials;
projectIds: number[];
supportedLanguageIds: string[];
supportedLanguagePairs: Record<string, string[]>;
enabledLanguageIds: string[];
enabledProjectIds: number[];
isEnabled: boolean;
}

export interface Credentials {
[key: string]: number;
}
export type Credentials =
| { apiKey: string }
| { credentials: string }
| { model: string; apiKey: string }
| { endpoint: string; apiKey: string }
| { url: string }
| { accessKey: string; secretKey: string };

export interface CreateMachineTranslationRequest {
name: string;
groupId?: number;
type: string;
credentials: string[];
credentials: Credentials;
enabledLanguageIds?: string[];
enabledProjectIds?: number[];
isEnabled?: boolean;
}

export interface TranslateRequest {
Expand Down
5 changes: 4 additions & 1 deletion src/notifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export class Notifications extends CrowdinApi {
* @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.notify.post
*/
sendNotificationToOrganizationMembers(
request: NotificationsModel.NotificationByUsers | NotificationsModel.NotificationByRole,
request:
| NotificationsModel.Notification
| NotificationsModel.NotificationByUsers
| NotificationsModel.NotificationByRole,
): Promise<void> {
const url = `${this.url}/notify`;
return this.post(url, request, this.defaultConfig());
Expand Down
49 changes: 5 additions & 44 deletions src/organizationWebhooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CrowdinApi, PaginationOptions, PatchRequest, ResponseList, ResponseObject } from '../core';
import { WebhooksModel } from '../webhooks';

/**
* Webhooks allow you to collect information about events that happen in your Crowdin account.
Expand All @@ -10,7 +11,7 @@ export class OrganizationWebhooks extends CrowdinApi {
* @param options optional pagination parameters for the request
* @see https://developer.crowdin.com/api/v2/#operation/api.webhooks.getMany
*/
listWebhooks(options?: PaginationOptions): Promise<ResponseList<OrganizationWebhooksModel.Webhook>> {
listWebhooks(options?: PaginationOptions): Promise<ResponseList<WebhooksModel.Webhook>> {
const url = `${this.url}/webhooks`;
return this.getList(url, options?.limit, options?.offset);
}
Expand All @@ -19,9 +20,7 @@ export class OrganizationWebhooks extends CrowdinApi {
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.webhooks.post
*/
addWebhook(
request: OrganizationWebhooksModel.AddWebhookRequest,
): Promise<ResponseObject<OrganizationWebhooksModel.Webhook>> {
addWebhook(request: WebhooksModel.AddWebhookRequest): Promise<ResponseObject<WebhooksModel.Webhook>> {
const url = `${this.url}/webhooks`;
return this.post(url, request, this.defaultConfig());
}
Expand All @@ -30,7 +29,7 @@ export class OrganizationWebhooks extends CrowdinApi {
* @param webhookId webhook identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.webhooks.get
*/
getWebhook(webhookId: number): Promise<ResponseObject<OrganizationWebhooksModel.Webhook>> {
getWebhook(webhookId: number): Promise<ResponseObject<WebhooksModel.Webhook>> {
const url = `${this.url}/webhooks/${webhookId}`;
return this.get(url, this.defaultConfig());
}
Expand All @@ -49,46 +48,8 @@ export class OrganizationWebhooks extends CrowdinApi {
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.webhooks.patch
*/
editWebhook(
webhookId: number,
request: PatchRequest[],
): Promise<ResponseObject<OrganizationWebhooksModel.Webhook>> {
editWebhook(webhookId: number, request: PatchRequest[]): Promise<ResponseObject<WebhooksModel.Webhook>> {
const url = `${this.url}/webhooks/${webhookId}`;
return this.patch(url, request, this.defaultConfig());
}
}

export namespace OrganizationWebhooksModel {
export interface Webhook {
id: number;
name: string;
url: string;
events: Event[];
headers: string[];
payload: string[];
isActive: boolean;
batchingEnabled: boolean;
requestType: RequestType;
contentType: ContentType;
createdAt: string;
updatedAt: string;
}

export interface AddWebhookRequest {
name: string;
url: string;
isActive?: boolean;
batchingEnabled?: boolean;
contentType?: ContentType;
events: Event[];
headers?: Record<string, string>;
requestType: RequestType;
payload?: any;
}

export type ContentType = 'multipart/form-data' | 'application/json' | 'application/x-www-form-urlencoded';

export type Event = 'project.created' | 'project.deleted' | 'group.created' | 'group.deleted';

export type RequestType = 'POST' | 'GET';
}
Loading
Loading