@microsoft/teams.api
Version:
<p> <a href="https://www.npmjs.com/package/@microsoft/teams.api" target="_blank"> <img src="https://img.shields.io/npm/v/@microsoft/teams.api/latest" /> </a> <a href="https://www.npmjs.com/package/@microsoft/teams.api?activeTab=code" t
159 lines (156 loc) • 5.64 kB
JavaScript
'use strict';
var teams_common = require('@microsoft/teams.common');
var apiClientSettings = require('./api-client-settings');
var apiOutboundMiddleware = require('./api-outbound-middleware');
var bot = require('./bot');
var conversation = require('./conversation');
var meeting = require('./meeting');
var reaction = require('./reaction');
var serviceUrl = require('./service-url');
var team = require('./team');
var tokenProviderFactory = require('./token-provider-factory');
var user = require('./user');
class Client {
serviceUrl;
bots;
users;
conversations;
teams;
meetings;
reactions;
get http() {
return this._http;
}
set http(v) {
const http = this.prepareHttpClient(v);
this.bots.http = http;
this.users.http = http;
this.conversations.http = http;
this.teams.http = http;
this.meetings.http = http;
this.reactions.http = http;
this._http = http;
}
_http;
_baseHttp;
_apiClientSettings;
_tokenProvider;
_cloud;
_defaultAgenticIdentity;
constructor(serviceUrl$1, httpOptions, apiClientSettings$1) {
this.serviceUrl = serviceUrl.normalizeServiceUrl(serviceUrl$1);
this._cloud = apiClientSettings$1?.cloud;
this._tokenProvider = apiClientSettings$1?.tokenProvider;
this._defaultAgenticIdentity = apiClientSettings$1?.agenticIdentity;
if (!httpOptions) {
this._http = this.prepareHttpClient(new teams_common.Client());
} else if ("request" in httpOptions) {
this._http = this.prepareHttpClient(httpOptions);
} else {
this._http = this.prepareHttpClient(new teams_common.Client({
...httpOptions,
headers: {
...httpOptions?.headers,
"Content-Type": "application/json"
}
}));
}
this._apiClientSettings = apiClientSettings.mergeApiClientSettings(apiClientSettings$1, this._cloud);
this.bots = new bot.BotClient(this.http, this._apiClientSettings, this._cloud);
this.users = new user.UserClient(this.http, this._apiClientSettings, this._cloud);
this.conversations = new conversation.ConversationClient(this.serviceUrl, this.http, this._apiClientSettings);
this.teams = new team.TeamClient(this.serviceUrl, this.http, this._apiClientSettings);
this.meetings = new meeting.MeetingClient(this.serviceUrl, this.http, this._apiClientSettings);
this.reactions = new reaction.ReactionClient(this.serviceUrl, this.http, this._apiClientSettings);
}
/**
* Create a scoped API client that reuses this client's HTTP configuration and token provider.
*/
clone(options = {}) {
const { serviceUrl, agenticIdentity, ...apiClientSettings } = options;
const http = this._baseHttp.clone();
if (this._tokenProvider) {
http.token = void 0;
}
return new Client(
serviceUrl ?? this.serviceUrl,
http,
{
...this._apiClientSettings,
...apiClientSettings,
...agenticIdentity === void 0 ? {} : { agenticIdentity: agenticIdentity ?? void 0 }
}
);
}
/**
* Create a scoped API client for the provided agentic identity.
*
* @param agenticIdentity Agentic operation identity used by the scoped client
* when acquiring auth tokens.
*/
forAgenticIdentity(agenticIdentity) {
return this.clone({ agenticIdentity });
}
/**
* Create a scoped API client for the provided Bot Framework service URL.
*/
fromServiceUrl(options) {
return this.clone(options);
}
prepareHttpClient(http) {
if (this._tokenProvider && http.token !== void 0) {
throw new Error("Cannot use both a token provider and an HTTP client token.");
}
apiOutboundMiddleware.ensureApiOutboundTelemetryMiddleware(http);
if (this._tokenProvider) {
http.token = tokenProviderFactory.createTokenProviderFactory(this._tokenProvider, this._defaultAgenticIdentity, this._cloud);
}
this._baseHttp = http;
return http;
}
}
exports.Client = Client;
Object.keys(apiClientSettings).forEach(function (k) {
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return apiClientSettings[k]; }
});
});
Object.keys(bot).forEach(function (k) {
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return bot[k]; }
});
});
Object.keys(conversation).forEach(function (k) {
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return conversation[k]; }
});
});
Object.keys(meeting).forEach(function (k) {
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return meeting[k]; }
});
});
Object.keys(reaction).forEach(function (k) {
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return reaction[k]; }
});
});
Object.keys(team).forEach(function (k) {
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return team[k]; }
});
});
Object.keys(user).forEach(function (k) {
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return user[k]; }
});
});
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map