// TODO: better import syntax? import {BaseAPIRequestFactory, RequiredError, COLLECTION_FORMATS} from './baseapi'; import {Configuration} from '../configuration'; import {RequestContext, HttpMethod, ResponseContext, HttpFile, HttpInfo} from '../http/http'; import {ObjectSerializer} from '../models/ObjectSerializer'; import {ApiException} from './exception'; import {canConsumeForm, isCodeInRange} from '../util'; import {SecurityAuthentication} from '../auth/auth'; import { DeleteManualTranslationsRequest } from '../models/DeleteManualTranslationsRequest'; import { ErrorResponse } from '../models/ErrorResponse'; import { ExportManualTranslationsRequest } from '../models/ExportManualTranslationsRequest'; /** * no description */ export class ManualTranslationApiRequestFactory extends BaseAPIRequestFactory { /** * Delete manual translations. Version: 26.7.0.cl or later Deletes all manual translations for the org. Requires `ADMINISTRATION` (**Can administer ThoughtSpot**), `ORG_ADMINISTRATION` (**Can administer Org**), or `APPLICATION_ADMINISTRATION` (**Can administer application**) privilege. #### Usage guidelines - This deletes **all** translation entries for the targeted org. The operation cannot be undone. - Defaults to `ORG` scope if not specified. - Set `scope` to `CLUSTER` to delete translations uploaded in the All-Org context. * @param deleteManualTranslationsRequest */ public async deleteManualTranslations(deleteManualTranslationsRequest: DeleteManualTranslationsRequest, _options?: Configuration): Promise { let _config = _options || this.configuration; // verify required parameter 'deleteManualTranslationsRequest' is not null or undefined if (deleteManualTranslationsRequest === null || deleteManualTranslationsRequest === undefined) { throw new RequiredError("ManualTranslationApi", "deleteManualTranslations", "deleteManualTranslationsRequest"); } // Path Params const localVarPath = '/api/rest/2.0/localizations/manual-translation/delete'; // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") requestContext.setHeaderParam("User-Agent", "ThoughtSpot-Client/typescript/2.29.1") requestContext.setHeaderParam("X-ThoughtSpot-Client", "ThoughtSpot-ts-client/2.29.1") // Body Params const contentType = ObjectSerializer.getPreferredMediaType([ "application/json" ]); requestContext.setHeaderParam("Content-Type", contentType); const serializedBody = ObjectSerializer.stringify( ObjectSerializer.serialize(deleteManualTranslationsRequest, "DeleteManualTranslationsRequest", ""), contentType ); requestContext.setBody(serializedBody); let authMethod: SecurityAuthentication | undefined; // Apply auth methods authMethod = _config.authMethods["bearerAuth"] if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } /** * Export manual translations as a CSV file. Version: 26.7.0.cl or later Downloads all manual translations for the org as a CSV file. Requires `ADMINISTRATION` (**Can administer ThoughtSpot**), `ORG_ADMINISTRATION` (**Can administer Org**), or `APPLICATION_ADMINISTRATION` (**Can administer application**) privilege. #### Usage guidelines - The response is a CSV file with columns: `content`, `locale`, `translated-content`. - Defaults to `ORG` scope if not specified. - Set `scope` to `CLUSTER` to export translations from the All-Org context. - `scope` accepts only `ORG` (default) and `CLUSTER`, in uppercase. Any other value returns a `400` error. - Returns a `400` error if no translations exist for the targeted org or cluster scope. * @param exportManualTranslationsRequest */ public async exportManualTranslations(exportManualTranslationsRequest: ExportManualTranslationsRequest, _options?: Configuration): Promise { let _config = _options || this.configuration; // verify required parameter 'exportManualTranslationsRequest' is not null or undefined if (exportManualTranslationsRequest === null || exportManualTranslationsRequest === undefined) { throw new RequiredError("ManualTranslationApi", "exportManualTranslations", "exportManualTranslationsRequest"); } // Path Params const localVarPath = '/api/rest/2.0/localizations/manual-translation/export'; // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") requestContext.setHeaderParam("User-Agent", "ThoughtSpot-Client/typescript/2.29.1") requestContext.setHeaderParam("X-ThoughtSpot-Client", "ThoughtSpot-ts-client/2.29.1") // Body Params const contentType = ObjectSerializer.getPreferredMediaType([ "application/json" ]); requestContext.setHeaderParam("Content-Type", contentType); const serializedBody = ObjectSerializer.stringify( ObjectSerializer.serialize(exportManualTranslationsRequest, "ExportManualTranslationsRequest", ""), contentType ); requestContext.setBody(serializedBody); let authMethod: SecurityAuthentication | undefined; // Apply auth methods authMethod = _config.authMethods["bearerAuth"] if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } /** * Get translations bundle for a locale. Version: 26.7.0.cl or later Retrieves all translations for a specific locale as a JSON map. Available to all authenticated users. No additional privileges are required. #### Usage guidelines - `locale` parameter must be a hyphenated locale code, in any case (for example, `fr-fr`, `de-de`, `JA-JP`). - Returns a JSON object with a `translations` map where each key is the original string and each value is the translated string. - If the org has no translations for the requested locale, the endpoint falls back to cluster-level translations. - Returns an empty `translations` map (not an error) if no entries exist at either level. * @param locale Locale code for which to retrieve translations. For example, `fr-fr`, `de-de`, `JA-JP`. */ public async getManualTranslationBundle(locale: string, _options?: Configuration): Promise { let _config = _options || this.configuration; // verify required parameter 'locale' is not null or undefined if (locale === null || locale === undefined) { throw new RequiredError("ManualTranslationApi", "getManualTranslationBundle", "locale"); } // Path Params const localVarPath = '/api/rest/2.0/localizations/manual-translation/locales/{locale}/export' .replace('{locale}', encodeURIComponent(String(locale))); // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") requestContext.setHeaderParam("User-Agent", "ThoughtSpot-Client/typescript/2.29.1") requestContext.setHeaderParam("X-ThoughtSpot-Client", "ThoughtSpot-ts-client/2.29.1") let authMethod: SecurityAuthentication | undefined; // Apply auth methods authMethod = _config.authMethods["bearerAuth"] if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } /** * Import manual translations from a CSV file. Version: 26.7.0.cl or later Uploads a CSV file containing manual translations and upserts them into the database. Requires `ADMINISTRATION` (**Can administer ThoughtSpot**), `ORG_ADMINISTRATION` (**Can administer Org**), or `APPLICATION_ADMINISTRATION` (**Can administer application**) privilege. #### Usage guidelines - The CSV file must have exactly three columns in this order: `content`, `locale`, `translated-content`. - Maximum file size: **30 MB**. Maximum rows: **10,000**. - Only `.csv` files are accepted. - The import performs an **upsert**: existing entries matched by `(org_id, locale, content)` are updated; new entries are inserted. Entries not in the upload are left untouched. - Set `scope` to `CLUSTER` to upload translations to the All-Org context. Cluster-level translations act as defaults for orgs that have no translations for a locale. - `scope` accepts only `ORG` (default) and `CLUSTER`, in uppercase. Any other value returns a `400` error. * @param translationsFile CSV file containing translations. The file must have three columns: `content`, `locale`, `translated-content`. Max file size: 30 MB. Max rows: 10,000. * @param scope Org scope for the import. `ORG` (default) targets the calling user\\\'s current org. `CLUSTER` targets the All-Org context. */ public async importManualTranslations(translationsFile: HttpFile, scope?: string, _options?: Configuration): Promise { let _config = _options || this.configuration; // verify required parameter 'translationsFile' is not null or undefined if (translationsFile === null || translationsFile === undefined) { throw new RequiredError("ManualTranslationApi", "importManualTranslations", "translationsFile"); } // Path Params const localVarPath = '/api/rest/2.0/localizations/manual-translation/import'; // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") requestContext.setHeaderParam("User-Agent", "ThoughtSpot-Client/typescript/2.29.1") requestContext.setHeaderParam("X-ThoughtSpot-Client", "ThoughtSpot-ts-client/2.29.1") // Form Params const useForm = canConsumeForm([ 'multipart/form-data', ]); let localVarFormParams if (useForm) { localVarFormParams = new FormData(); } else { localVarFormParams = new URLSearchParams(); } if (translationsFile !== undefined) { // TODO: replace .append with .set if (localVarFormParams instanceof FormData) { localVarFormParams.append('translations_file', translationsFile, translationsFile.name); } } if (scope !== undefined) { // TODO: replace .append with .set localVarFormParams.append('scope', scope as any); } requestContext.setBody(localVarFormParams); if(!useForm) { const contentType = ObjectSerializer.getPreferredMediaType([ "multipart/form-data" ]); requestContext.setHeaderParam("Content-Type", contentType); } let authMethod: SecurityAuthentication | undefined; // Apply auth methods authMethod = _config.authMethods["bearerAuth"] if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth: SecurityAuthentication | undefined = _config?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } } export class ManualTranslationApiResponseProcessor { /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to deleteManualTranslations * @throws ApiException if the response code was not in [200, 299] */ public async deleteManualTranslationsWithHttpInfo(response: ResponseContext): Promise> { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("204", response.httpStatusCode)) { return new HttpInfo(response.httpStatusCode, response.headers, response.body, undefined); } if (isCodeInRange("400", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Operation failed", body, response.headers); } if (isCodeInRange("401", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unauthorized access.", body, response.headers); } if (isCodeInRange("403", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Forbidden access.", body, response.headers); } if (isCodeInRange("500", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Operation failed", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: void = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "void", "" ) as void; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to exportManualTranslations * @throws ApiException if the response code was not in [200, 299] */ public async exportManualTranslationsWithHttpInfo(response: ResponseContext): Promise> { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: HttpFile = await response.getBodyAsFile() as any as HttpFile; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } if (isCodeInRange("400", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "binary" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Invalid request.", body, response.headers); } if (isCodeInRange("401", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "binary" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unauthorized access.", body, response.headers); } if (isCodeInRange("403", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "binary" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Forbidden access.", body, response.headers); } if (isCodeInRange("404", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "binary" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "No translations file found.", body, response.headers); } if (isCodeInRange("500", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "binary" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unexpected error.", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: HttpFile = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "HttpFile", "binary" ) as HttpFile; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to getManualTranslationBundle * @throws ApiException if the response code was not in [200, 299] */ public async getManualTranslationBundleWithHttpInfo(response: ResponseContext): Promise> { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: any = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "any", "" ) as any; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } if (isCodeInRange("400", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Invalid request.", body, response.headers); } if (isCodeInRange("401", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unauthorized access.", body, response.headers); } if (isCodeInRange("403", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Forbidden access.", body, response.headers); } if (isCodeInRange("404", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "No translations found for the requested locale.", body, response.headers); } if (isCodeInRange("500", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unexpected error.", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: any = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "any", "" ) as any; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to importManualTranslations * @throws ApiException if the response code was not in [200, 299] */ public async importManualTranslationsWithHttpInfo(response: ResponseContext): Promise> { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("204", response.httpStatusCode)) { return new HttpInfo(response.httpStatusCode, response.headers, response.body, undefined); } if (isCodeInRange("400", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Operation failed", body, response.headers); } if (isCodeInRange("401", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unauthorized access.", body, response.headers); } if (isCodeInRange("403", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Forbidden access.", body, response.headers); } if (isCodeInRange("500", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Operation failed", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: void = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "void", "" ) as void; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } }