Skip to content

Commit

Permalink
fix: [#4470] Migrate off @azure/ms-rest-js (#4578)
Browse files Browse the repository at this point in the history
* update yarn lock without ms-rest-js

* remove ms-rest-js in botbuilder

* remove ms-rest-js in botframework-connector

* update botbuilder package.json

* update package json

* update with lint format

* update packages

* update botbuilder api signature

* update yarn.lock
  • Loading branch information
JhontSouth authored and Tracy Boehrer committed Dec 21, 2023
1 parent 44a1c9f commit 2bedf24
Show file tree
Hide file tree
Showing 42 changed files with 568 additions and 527 deletions.
6 changes: 3 additions & 3 deletions libraries/botbuilder/etc/botbuilder.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import { ExtendedUserTokenProvider } from 'botbuilder-core';
import { FileConsentCardResponse } from 'botbuilder-core';
import { GetPropertyPaneConfigurationResponse } from 'botbuilder-core';
import { HandleActionResponse } from 'botbuilder-core';
import { HttpClient } from '@azure/ms-rest-js';
import { HttpOperationResponse } from '@azure/ms-rest-js';
import { HttpClient } from '@azure/core-http';
import { HttpOperationResponse } from '@azure/core-http';
import { ICredentialProvider } from 'botframework-connector';
import { INodeBuffer } from 'botframework-streaming';
import { INodeSocket } from 'botframework-streaming';
Expand Down Expand Up @@ -99,7 +99,7 @@ import { TranscriptInfo } from 'botbuilder-core';
import { TranscriptStore } from 'botbuilder-core';
import { TurnContext } from 'botbuilder-core';
import { UserState } from 'botbuilder-core';
import { WebResource } from '@azure/ms-rest-js';
import { WebResource } from '@azure/core-http';

// Warning: (ae-forgotten-export) The symbol "ConnectorClientBuilder" needs to be exported by the entry point index.d.ts
//
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
},
"dependencies": {
"@azure/ms-rest-js": "^2.7.0",
"@azure/core-http": "^3.0.2",
"@azure/msal-node": "^1.2.0",
"axios": "^0.25.0",
"botbuilder-core": "4.1.6",
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder/src/botFrameworkAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import * as z from 'zod';
import { BotFrameworkHttpAdapter } from './botFrameworkHttpAdapter';
import { ConnectorClientBuilder, Request, Response, ResponseT, WebRequest, WebResponse } from './interfaces';
import { HttpClient, RequestPolicyFactory, userAgentPolicy } from '@azure/ms-rest-js';
import { HttpClient, RequestPolicyFactory, userAgentPolicy } from '@azure/core-http';
import { INodeBufferT, INodeSocketT, LogicT } from './zod';
import { arch, release, type } from 'os';
import { delay, retry } from 'botbuilder-stdlib';
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder/src/cloudAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as z from 'zod';
import type { BotFrameworkHttpAdapter } from './botFrameworkHttpAdapter';
import { Activity, CloudAdapterBase, InvokeResponse, StatusCodes, TurnContext } from 'botbuilder-core';
import { GET, POST, VERSION_PATH } from './streaming';
import { HttpClient, HttpHeaders, HttpOperationResponse, WebResource } from '@azure/ms-rest-js';
import { HttpClient, HttpHeaders, HttpOperationResponse, WebResource } from '@azure/core-http';
import { INodeBufferT, INodeSocketT, LogicT } from './zod';
import { Request, Response, ResponseT } from './interfaces';
import { USER_AGENT } from './botFrameworkAdapter';
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder/src/streaming/streamingHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT License.
*/

import { WebResource, HttpOperationResponse, HttpClient } from '@azure/ms-rest-js';
import { WebResource, HttpOperationResponse, HttpClient } from '@azure/core-http';
import { IStreamingTransportServer, StreamingRequest } from 'botframework-streaming';

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder/tests/botFrameworkAdapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const sinon = require('sinon');
const { BotFrameworkAdapter } = require('../');
const { Conversations } = require('botframework-connector/lib/connectorApi/operations');
const { UserToken, BotSignIn } = require('botframework-connector/lib/tokenApi/operations');
const { userAgentPolicy, HttpHeaders } = require('@azure/ms-rest-js');
const { userAgentPolicy, HttpHeaders } = require('@azure/core-http');

const {
ActivityTypes,
Expand Down
16 changes: 8 additions & 8 deletions libraries/botbuilder/tests/teamsInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.sendMeetingNotification(context, notification, meetingId);
} catch (e) {
assert.deepEqual(errorResponse, e.body);
assert.deepEqual(errorResponse, e.details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1214,7 +1214,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.sendMessageToListOfUsers(context, activity, tenantId, members);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1307,7 +1307,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.sendMessageToAllUsersInTenant(context, activity, tenantId);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1395,7 +1395,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.sendMessageToAllUsersInTeam(context, activity, tenantId, teamId);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1502,7 +1502,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.sendMessageToListOfChannels(context, activity, tenantId, members);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1579,7 +1579,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.getOperationState(context, operationId);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1648,7 +1648,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.getFailedEntries(context, operationId);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down Expand Up @@ -1697,7 +1697,7 @@ describe('TeamsInfo', function () {
try {
await TeamsInfo.cancelOperation(context, operationId);
} catch (e) {
assert.deepEqual(errorResponse, e.errors[0].body);
assert.deepEqual(errorResponse, e.errors[0].details);
isErrorThrown = true;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/botframework-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
}
},
"dependencies": {
"@azure/core-http": "^3.0.2",
"@azure/identity": "^2.0.4",
"@azure/ms-rest-js": "^2.7.0",
"@azure/msal-node": "^1.2.0",
"axios": "^0.25.0",
"base64url": "^3.0.0",
Expand Down
9 changes: 5 additions & 4 deletions libraries/botframework-connector/src/auth/appCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
* Licensed under the MIT License.
*/

import * as msrest from '@azure/ms-rest-js';
import { ConfidentialClientApplication } from '@azure/msal-node';
import { ServiceClientCredentials, WebResource } from '@azure/core-http';
import { TokenCredentials } from './tokenCredentials';
import { AuthenticationConstants } from './authenticationConstants';
import { AuthenticatorResult } from './authenticatorResult';

/**
* General AppCredentials auth implementation and cache.
* Subclasses can implement refreshToken to acquire the token.
*/
export abstract class AppCredentials implements msrest.ServiceClientCredentials {
export abstract class AppCredentials implements ServiceClientCredentials {
private static readonly cache: Map<string, AuthenticatorResult> = new Map<string, AuthenticatorResult>();

appId: string;
Expand Down Expand Up @@ -148,9 +149,9 @@ export abstract class AppCredentials implements msrest.ServiceClientCredentials
* @param webResource The WebResource HTTP request.
* @returns A Promise representing the asynchronous operation.
*/
async signRequest(webResource: msrest.WebResource): Promise<msrest.WebResource> {
async signRequest(webResource: WebResource): Promise<WebResource> {
if (this.shouldSetToken()) {
return new msrest.TokenCredentials(await this.getToken()).signRequest(webResource);
return new TokenCredentials(await this.getToken()).signRequest(webResource);
}

return webResource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BotFrameworkClient } from '../skills';
import { ConversationIdHttpHeaderName } from '../conversationConstants';
import { ServiceClientCredentialsFactory } from './serviceClientCredentialsFactory';
import { USER_AGENT } from './connectorFactoryImpl';
import { WebResource } from '@azure/ms-rest-js';
import { WebResource } from '@azure/core-http';
import { ok } from 'assert';

const botFrameworkClientFetchImpl: typeof fetch = async (input, init) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT License.
*/

import type { ServiceClientCredentials } from '@azure/ms-rest-js';
import type { ServiceClientCredentials } from '@azure/core-http';
import { ServiceClientCredentialsFactory } from './serviceClientCredentialsFactory';
import { ok } from 'assert';
import { CertificateAppCredentials } from './certificateAppCredentials';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { getDefaultUserAgentValue, RequestPolicyFactory, userAgentPolicy } from '@azure/ms-rest-js';
import { getDefaultUserAgentValue, RequestPolicyFactory, userAgentPolicy } from '@azure/core-http';
import { ConnectorClient } from '../connectorApi/connectorClient';
import { ConnectorClientOptions } from '../connectorApi/models';
import { ConnectorFactory } from './connectorFactory';
Expand Down
1 change: 1 addition & 0 deletions libraries/botframework-connector/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ export * from './userTokenClient';

export { MsalAppCredentials } from './msalAppCredentials';
export { MsalServiceClientCredentialsFactory } from './msalServiceClientCredentialsFactory';
export { TokenCredentials } from './tokenCredentials';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import type { IJwtTokenProviderFactory } from './jwtTokenProviderFactory';
import type { ServiceClientCredentials } from '@azure/ms-rest-js';
import type { ServiceClientCredentials } from '@azure/core-http';
import { ManagedIdentityAppCredentials } from './managedIdentityAppCredentials';
import { ServiceClientCredentialsFactory } from './serviceClientCredentialsFactory';
import { ok } from 'assert';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { ConfidentialClientApplication } from '@azure/msal-node';
import { MsalAppCredentials } from './msalAppCredentials';
import { ServiceClientCredentials } from '@azure/ms-rest-js';
import { ServiceClientCredentials } from '@azure/core-http';
import { ServiceClientCredentialsFactory } from './serviceClientCredentialsFactory';
import { AuthenticationConstants } from './authenticationConstants';
import { GovernmentConstants } from './governmentConstants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import type { ServiceClientCredentials } from '@azure/ms-rest-js';
import type { ServiceClientCredentials } from '@azure/core-http';
import { AuthenticationConstants } from './authenticationConstants';
import { GovernmentConstants } from './governmentConstants';
import { MicrosoftAppCredentials } from './microsoftAppCredentials';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { ServiceClientCredentials } from '@azure/ms-rest-js';
import { ServiceClientCredentials } from '@azure/core-http';

// Export underlying type for convenience
export { ServiceClientCredentials };
Expand Down
42 changes: 42 additions & 0 deletions libraries/botframework-connector/src/auth/tokenCredentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

import { HttpHeaders, Constants, WebResourceLike, ServiceClientCredentials } from '@azure/core-http';

const HeaderConstants = Constants.HeaderConstants;
const DEFAULT_AUTHORIZATION_SCHEME = 'Bearer';

/**
* A credentials object that uses a token string and a authorzation scheme to authenticate.
*/
export class TokenCredentials implements ServiceClientCredentials {
token: string;
authorizationScheme: string = DEFAULT_AUTHORIZATION_SCHEME;

/**
* Creates a new TokenCredentials object.
*
* @class
* @param {string} token The token.
* @param {string} [authorizationScheme] The authorization scheme.
*/
constructor(token: string, authorizationScheme: string = DEFAULT_AUTHORIZATION_SCHEME) {
if (!token) {
throw new Error('token cannot be null or undefined.');
}
this.token = token;
this.authorizationScheme = authorizationScheme;
}

/**
* Signs a request with the Authentication header.
*
* @param {WebResourceLike} webResource The WebResourceLike to be signed.
* @returns {Promise<WebResourceLike>} The signed request object.
*/
signRequest(webResource: WebResourceLike) {
if (!webResource.headers) webResource.headers = new HttpHeaders();
webResource.headers.set(HeaderConstants.AUTHORIZATION, `${this.authorizationScheme} ${this.token}`);
return Promise.resolve(webResource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import * as z from 'zod';
import type { ServiceClientCredentials } from '@azure/ms-rest-js';
import type { ServiceClientCredentials } from '@azure/core-http';
import { Activity, SignInUrlResponse, TokenExchangeRequest, TokenResponse, TokenStatus } from 'botframework-schema';
import { ConnectorClientOptions } from '../connectorApi/models';
import { TokenApiClient } from '../tokenApi/tokenApiClient';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as Mappers from './models/mappers';
import * as Models from './models';
import * as msRest from '@azure/ms-rest-js';
import { ServiceClientCredentials } from '@azure/core-http';
import * as operations from './operations';
import { ConnectorClientContext } from './connectorClientContext';

Expand All @@ -20,7 +20,7 @@ class ConnectorClient extends ConnectorClientContext {
* @param credentials Subscription credentials which uniquely identify client subscription.
* @param [options] The parameter options
*/
constructor(credentials: msRest.ServiceClientCredentials, options?: Models.ConnectorClientOptions) {
constructor(credentials: ServiceClientCredentials, options?: Models.ConnectorClientOptions) {
super(credentials, options);
this.attachments = new operations.Attachments(this);
this.conversations = new operations.Conversations(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
* Licensed under the MIT License.
*/

import * as msRest from "@azure/ms-rest-js";
import { ServiceClient, ServiceClientCredentials, getDefaultUserAgentValue } from "@azure/core-http";
import * as Models from "./models";

const packageName = "botframework-connector";
const packageVersion = "4.0.0";

export class ConnectorClientContext extends msRest.ServiceClient {
credentials: msRest.ServiceClientCredentials;
export class ConnectorClientContext extends ServiceClient {
credentials: ServiceClientCredentials;

/**
* Initializes a new instance of the ConnectorClientContext class.
* @param credentials Subscription credentials which uniquely identify client subscription.
* @param [options] The parameter options
*/
constructor(credentials: msRest.ServiceClientCredentials, options?: Models.ConnectorClientOptions) {
constructor(credentials: ServiceClientCredentials, options?: Models.ConnectorClientOptions) {
if (credentials === null || credentials === undefined) {
throw new Error('\'credentials\' cannot be null.');
}
Expand All @@ -27,7 +27,7 @@ export class ConnectorClientContext extends msRest.ServiceClient {
options = {} as Models.ConnectorClientOptions;
}
// TODO This is to workaround fact that AddUserAgent() was removed.
const defaultUserAgent = msRest.getDefaultUserAgentValue();
const defaultUserAgent = getDefaultUserAgentValue();
options.userAgent = `${packageName}/${packageVersion} ${defaultUserAgent} ${options.userAgent || ''}`;

super(credentials, options);
Expand Down
Loading

0 comments on commit 2bedf24

Please sign in to comment.