Skip to content

Commit af4d3ae

Browse files
author
Serhii Kozlovskyi
committed
feat: update API domain configuration to replace baseUrl with apiDomain for improved flexibility
1 parent 9bc69d7 commit af4d3ae

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/core/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ export interface Credentials {
2929
/** Yor Crowdin Enterprise organization name */
3030
organization?: string;
3131

32-
/** API base URL */
32+
/** @deprecated API base URL. Use `apiDomain` instead` */
3333
baseUrl?: string;
34+
35+
/** API domain (e.g., 'api.crowdin.com') */
36+
apiDomain?: string;
3437
}
3538

3639
/**
@@ -207,7 +210,7 @@ export function handleHttpClientError(error: HttpClientError): never {
207210
}
208211

209212
export abstract class CrowdinApi {
210-
private static readonly CROWDIN_URL_SUFFIX: string = 'api.crowdin.com/api/v2';
213+
private static readonly CROWDIN_API_DOMAIN: string = 'api.crowdin.com';
211214
private static readonly AXIOS_INSTANCE = new AxiosProvider().axios;
212215
private static readonly FETCH_INSTANCE = new FetchClient();
213216

@@ -218,6 +221,8 @@ export abstract class CrowdinApi {
218221
/** @internal */
219222
readonly url: string;
220223
/** @internal */
224+
readonly apiDomain: string;
225+
/** @internal */
221226
readonly config: ClientConfig | undefined;
222227
/** @internal */
223228
readonly retryService: RetryService;
@@ -232,14 +237,15 @@ export abstract class CrowdinApi {
232237
constructor(credentials: Credentials, config?: ClientConfig) {
233238
this.token = credentials.token;
234239
this.organization = credentials.organization;
240+
this.apiDomain = credentials.apiDomain || CrowdinApi.CROWDIN_API_DOMAIN;
235241

236242
if (credentials.baseUrl) {
237243
this.url = credentials.baseUrl;
238244
} else {
239245
if (this.organization) {
240-
this.url = `https://${this.organization}.${CrowdinApi.CROWDIN_URL_SUFFIX}`;
246+
this.url = `https://${this.organization}.${this.apiDomain}/api/v2`;
241247
} else {
242-
this.url = `https://${CrowdinApi.CROWDIN_URL_SUFFIX}`;
248+
this.url = `https://${this.apiDomain}/api/v2`;
243249
}
244250
}
245251

@@ -272,10 +278,11 @@ export abstract class CrowdinApi {
272278
if (config?.url) {
273279
url = config.url;
274280
} else {
281+
const baseDomain = this.apiDomain || CrowdinApi.CROWDIN_API_DOMAIN;
275282
if (this.organization) {
276-
url = `https://${this.organization}.api.crowdin.com/api/graphql`;
283+
url = `https://${this.organization}.${baseDomain}/api/graphql`;
277284
} else {
278-
url = 'https://api.crowdin.com/api/graphql';
285+
url = `https://${baseDomain}/api/graphql`;
279286
}
280287
}
281288

0 commit comments

Comments
 (0)