UNPKG

@azure-rest/ai-translation-text

Version:

An isomorphic client library for the Azure Cognitive Translator Service

44 lines 2.27 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.default = createClient; const tslib_1 = require("tslib"); const core_client_1 = require("@azure-rest/core-client"); const logger_js_1 = require("./logger.js"); /** * Initialize a new instance of `TextTranslationClient` * @param endpointParam - Supported Text Translation endpoints (protocol and hostname, for example: * https://api.cognitive.microsofttranslator.com). * @param options - the parameter for all optional parameters */ function createClient(endpointParam, _a = {}) { var _b, _c, _d, _e; var { apiVersion = "3.0" } = _a, options = tslib_1.__rest(_a, ["apiVersion"]); const endpointUrl = (_c = (_b = options.endpoint) !== null && _b !== void 0 ? _b : options.baseUrl) !== null && _c !== void 0 ? _c : `${endpointParam}`; const userAgentInfo = `azsdk-js-ai-translation-text-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}` : `${userAgentInfo}`; options = Object.assign(Object.assign({}, options), { userAgentOptions: { userAgentPrefix, }, loggingOptions: { logger: (_e = (_d = options.loggingOptions) === null || _d === void 0 ? void 0 : _d.logger) !== null && _e !== void 0 ? _e : logger_js_1.logger.info, } }); const client = (0, core_client_1.getClient)(endpointUrl, options); client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); client.pipeline.addPolicy({ name: "ClientApiVersionPolicy", sendRequest: (req, next) => { // Use the apiVersion defined in request url directly // Append one if there is no apiVersion and we have one at client options const url = new URL(req.url); if (!url.searchParams.get("api-version") && apiVersion) { req.url = `${req.url}${Array.from(url.searchParams.keys()).length > 0 ? "&" : "?"}api-version=${apiVersion}`; } return next(req); }, }); return client; } //# sourceMappingURL=textTranslationClient.js.map