Skip to content

Commit 65e63f6

Browse files
authored
feat: update API domain configuration (#593)
1 parent 7336ceb commit 65e63f6

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/core/index.ts

Lines changed: 12 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

@@ -273,9 +279,9 @@ export abstract class CrowdinApi {
273279
url = config.url;
274280
} else {
275281
if (this.organization) {
276-
url = `https://${this.organization}.api.crowdin.com/api/graphql`;
282+
url = `https://${this.organization}.${this.apiDomain}/api/graphql`;
277283
} else {
278-
url = 'https://api.crowdin.com/api/graphql';
284+
url = `https://${this.apiDomain}/api/graphql`;
279285
}
280286
}
281287

0 commit comments

Comments
 (0)