UNPKG

botframework-connector

Version:

Bot Connector is autorest generated connector client.

60 lines 2.62 kB
"use strict"; /** * @module botframework-connector */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EmulatorApiClient = void 0; const cross_fetch_1 = __importDefault(require("cross-fetch")); /** * The purpose of this class is to emulate an api client. */ class EmulatorApiClient { /** * OAuth card emulation. * * @remarks If the emulation fails, an error containing the status code from the server is thrown. * * @param credentials [AppCredentials](xref:botframework-connector.AppCredentials) for OAuth. * @param emulatorUrl The URL of the emulator. * @param emulate `true` to send an emulated OAuth card to the emulator; or `false` to not send the card. * @returns `true` on a successful emulation of OAuthCards. */ static emulateOAuthCards(credentials, emulatorUrl, emulate) { return __awaiter(this, void 0, void 0, function* () { const token = yield credentials.getToken(); const requestUrl = emulatorUrl + (emulatorUrl.endsWith('/') ? '' : '/') + `api/usertoken/emulateOAuthCards?emulate=${(!!emulate).toString()}`; const res = yield (0, cross_fetch_1.default)(requestUrl, { method: 'POST', headers: { Authorization: `Bearer ${token}`, }, }); if (res.ok) { return true; } else { throw new Error(`EmulateOAuthCards failed with status code: ${res.status}`); } }); } } exports.EmulatorApiClient = EmulatorApiClient; //# sourceMappingURL=emulatorApiClient.js.map