UNPKG

@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

122 lines (120 loc) • 4.24 kB
import { Client as Client$1 } from '@microsoft/teams.common'; import { mergeApiClientSettings } from './api-client-settings.mjs'; export * from './api-client-settings.mjs'; import { ensureApiOutboundTelemetryMiddleware } from './api-outbound-middleware.mjs'; import { BotClient } from './bot/index.mjs'; export * from './bot/index.mjs'; import { ConversationClient } from './conversation/index.mjs'; export * from './conversation/index.mjs'; import { MeetingClient } from './meeting.mjs'; export * from './meeting.mjs'; import { ReactionClient } from './reaction/index.mjs'; export * from './reaction/index.mjs'; import { normalizeServiceUrl } from './service-url.mjs'; import { TeamClient } from './team.mjs'; export * from './team.mjs'; import { createTokenProviderFactory } from './token-provider-factory.mjs'; import { UserClient } from './user/index.mjs'; export * from './user/index.mjs'; 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, httpOptions, apiClientSettings) { this.serviceUrl = normalizeServiceUrl(serviceUrl); this._cloud = apiClientSettings?.cloud; this._tokenProvider = apiClientSettings?.tokenProvider; this._defaultAgenticIdentity = apiClientSettings?.agenticIdentity; if (!httpOptions) { this._http = this.prepareHttpClient(new Client$1()); } else if ("request" in httpOptions) { this._http = this.prepareHttpClient(httpOptions); } else { this._http = this.prepareHttpClient(new Client$1({ ...httpOptions, headers: { ...httpOptions?.headers, "Content-Type": "application/json" } })); } this._apiClientSettings = mergeApiClientSettings(apiClientSettings, this._cloud); this.bots = new BotClient(this.http, this._apiClientSettings, this._cloud); this.users = new UserClient(this.http, this._apiClientSettings, this._cloud); this.conversations = new ConversationClient(this.serviceUrl, this.http, this._apiClientSettings); this.teams = new TeamClient(this.serviceUrl, this.http, this._apiClientSettings); this.meetings = new MeetingClient(this.serviceUrl, this.http, this._apiClientSettings); this.reactions = new 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."); } ensureApiOutboundTelemetryMiddleware(http); if (this._tokenProvider) { http.token = createTokenProviderFactory(this._tokenProvider, this._defaultAgenticIdentity, this._cloud); } this._baseHttp = http; return http; } } export { Client }; //# sourceMappingURL=index.mjs.map //# sourceMappingURL=index.mjs.map