From 99645fa054b74be51fb735b32e489ffad55545d2 Mon Sep 17 00:00:00 2001 From: YHorodyskyi <120653542+YHorodyskyi@users.noreply.github.com> Date: Tue, 9 Jan 2024 11:23:27 +0200 Subject: [PATCH] feat: allow graphql for crowdin.com, add croql to listTmSegments (#361) --- src/core/index.ts | 14 +++++++------- src/translationMemory/index.ts | 12 ++++++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/core/index.ts b/src/core/index.ts index 6b9e4b6e3..8b7584a09 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -254,15 +254,15 @@ export abstract class CrowdinApi { } graphql(req: { query: string; operationName?: string; variables?: any }): Promise> { - if (!this.organization) { - throw new Error('GraphQL API could be used only with Crowdin Enterprise.'); + let url; + + if (this.organization) { + url = `https://${this.organization}.api.crowdin.com/api/graphql`; + } else { + url = 'https://api.crowdin.com/api/graphql'; } - return this.post>( - `https://${this.organization}.api.crowdin.com/api/graphql`, - req, - this.defaultConfig(), - ); + return this.post>(url, req, this.defaultConfig()); } protected addQueryParam(url: string, name: string, value?: string | number): string { diff --git a/src/translationMemory/index.ts b/src/translationMemory/index.ts index 9dea2c52a..90c22a865 100644 --- a/src/translationMemory/index.ts +++ b/src/translationMemory/index.ts @@ -95,8 +95,12 @@ export class TranslationMemory extends CrowdinApi { * @param options optional paramerers for the request * @see https://developer.crowdin.com/api/v2/#operation/api.tms.segments.getMany */ - listTmSegments(tmId: number, options?: PaginationOptions): Promise> { - const url = `${this.url}/tms/${tmId}/segments`; + listTmSegments( + tmId: number, + options?: TranslationMemoryModel.ListSegmentsOptions, + ): Promise> { + let url = `${this.url}/tms/${tmId}/segments`; + url = this.addQueryParam(url, 'croql', options?.croql); return this.getList(url, options?.limit, options?.offset); } @@ -358,6 +362,10 @@ export namespace TranslationMemoryModel { userId?: number; } + export interface ListSegmentsOptions extends PaginationOptions { + croql?: string; + } + export interface TMSegment { id: number; records: TMSegmentRecord[];