@azure/communication-chat
Version:
Azure client library for Azure Communication Chat services
70 lines • 2.99 kB
JavaScript
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
import * as coreClient from "@azure/core-client";
import { ChatThreadImpl, ChatImpl } from "./operations/index.js";
export class ChatApiClient extends coreClient.ServiceClient {
/**
* Initializes a new instance of the ChatApiClient class.
* @param endpoint The endpoint of the Azure Communication resource.
* @param options The parameter options
*/
constructor(endpoint, options) {
var _a, _b;
if (endpoint === undefined) {
throw new Error("'endpoint' cannot be null");
}
// Initializing default values for options
if (!options) {
options = {};
}
const defaults = {
requestContentType: "application/json; charset=utf-8",
};
const packageDetails = `azsdk-js-communication-chat/1.6.0`;
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
: `${packageDetails}`;
const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: {
userAgentPrefix,
}, endpoint: (_b = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUri) !== null && _b !== void 0 ? _b : "{endpoint}" });
super(optionsWithDefaults);
// Parameter assignments
this.endpoint = endpoint;
// Assigning values to Constant parameters
this.apiVersion = options.apiVersion || "2025-03-15";
this.chatThread = new ChatThreadImpl(this);
this.chat = new ChatImpl(this);
this.addCustomApiVersionPolicy(options.apiVersion);
}
/** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */
addCustomApiVersionPolicy(apiVersion) {
if (!apiVersion) {
return;
}
const apiVersionPolicy = {
name: "CustomApiVersionPolicy",
async sendRequest(request, next) {
const param = request.url.split("?");
if (param.length > 1) {
const newParams = param[1].split("&").map((item) => {
if (item.indexOf("api-version") > -1) {
return "api-version=" + apiVersion;
}
else {
return item;
}
});
request.url = param[0] + "?" + newParams.join("&");
}
return next(request);
},
};
this.pipeline.addPolicy(apiVersionPolicy);
}
}
//# sourceMappingURL=chatApiClient.js.map