From 9fd70810a11c6ca8f3bab0415d72eee8a24c162f Mon Sep 17 00:00:00 2001 From: JhontSouth Date: Tue, 31 Oct 2023 11:48:35 -0500 Subject: [PATCH] update lint formats --- .../botbuilder-ai/etc/botbuilder-ai.api.md | 4 +- libraries/botbuilder-ai/package.json | 1 + libraries/botbuilder-ai/src/index.ts | 1 - .../src/luisRuntimeClientContext.ts | 16 +++---- .../src/luisV2-models/sentiment.ts | 3 +- .../tests/luisRecognizer.test.js | 8 ++-- .../botframework-connector/src/auth/index.ts | 1 + .../src/auth/tokenCredentials.ts | 45 ++++++++++++++++++ yarn.lock | 47 ++++++++++++++++++- 9 files changed, 108 insertions(+), 18 deletions(-) create mode 100644 libraries/botframework-connector/src/auth/tokenCredentials.ts diff --git a/libraries/botbuilder-ai/etc/botbuilder-ai.api.md b/libraries/botbuilder-ai/etc/botbuilder-ai.api.md index 4fb88020a0..910b5da04e 100644 --- a/libraries/botbuilder-ai/etc/botbuilder-ai.api.md +++ b/libraries/botbuilder-ai/etc/botbuilder-ai.api.md @@ -23,12 +23,12 @@ import { DialogTurnResult } from 'botbuilder-dialogs'; import { EnumExpression } from 'adaptive-expressions'; import { Expression } from 'adaptive-expressions'; import { IntExpression } from 'adaptive-expressions'; -import * as msRest from '@azure/ms-rest-js'; import { NumberExpression } from 'adaptive-expressions'; import { ObjectExpression } from 'adaptive-expressions'; import { Recognizer } from 'botbuilder-dialogs'; import { RecognizerConfiguration } from 'botbuilder-dialogs'; import { RecognizerResult } from 'botbuilder-core'; +import { RequestOptionsBase } from '@azure/core-http'; import { ServiceCollection } from 'botbuilder-dialogs-adaptive-runtime-core'; import { StringExpression } from 'adaptive-expressions'; import { TemplateInterface } from 'botbuilder-dialogs'; @@ -290,7 +290,7 @@ export class LuisComponentRegistration extends ComponentRegistration { } // @public -export interface LuisPredictionOptions extends msRest.RequestOptionsBase { +export interface LuisPredictionOptions extends RequestOptionsBase { bingSpellCheckSubscriptionKey?: string; includeAllIntents?: boolean; includeInstanceData?: boolean; diff --git a/libraries/botbuilder-ai/package.json b/libraries/botbuilder-ai/package.json index a3b1aa7581..813b59eee4 100644 --- a/libraries/botbuilder-ai/package.json +++ b/libraries/botbuilder-ai/package.json @@ -27,6 +27,7 @@ } }, "dependencies": { + "@azure/core-http": "^3.0.2", "adaptive-expressions": "4.1.6", "botbuilder-core": "4.1.6", "botbuilder-dialogs": "4.1.6", diff --git a/libraries/botbuilder-ai/src/index.ts b/libraries/botbuilder-ai/src/index.ts index 9acd133a6d..ce9bc07f49 100644 --- a/libraries/botbuilder-ai/src/index.ts +++ b/libraries/botbuilder-ai/src/index.ts @@ -69,4 +69,3 @@ export { RankerTypes, ServiceType, } from './qnamaker-interfaces'; - diff --git a/libraries/botbuilder-ai/src/luisRuntimeClientContext.ts b/libraries/botbuilder-ai/src/luisRuntimeClientContext.ts index 5cd2c12e4e..b45254b328 100644 --- a/libraries/botbuilder-ai/src/luisRuntimeClientContext.ts +++ b/libraries/botbuilder-ai/src/luisRuntimeClientContext.ts @@ -7,17 +7,21 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import { ServiceClient, ServiceClientCredentials, ServiceClientOptions, getDefaultUserAgentValue } from "@azure/core-http"; +import { ServiceClient, ServiceClientCredentials, ServiceClientOptions } from '@azure/core-http'; +/** + * Client for LUIS context + */ export class LUISRuntimeClientContext extends ServiceClient { endpoint: string; credentials: ServiceClientCredentials; /** * Initializes a new instance of the LUISRuntimeClientContext class. + * + * @param credentials Subscription credentials which uniquely identify client subscription. * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: * https://westus.api.cognitive.microsoft.com). - * @param credentials Subscription credentials which uniquely identify client subscription. * @param [options] The parameter options */ constructor(credentials: ServiceClientCredentials, endpoint: string, options?: ServiceClientOptions) { @@ -32,14 +36,10 @@ export class LUISRuntimeClientContext extends ServiceClient { options = {}; } - if (!options.userAgent) { - const defaultUserAgent = getDefaultUserAgentValue(); - } - super(credentials, options); - this.baseUri = "{Endpoint}/luis/v3.0-preview"; - this.requestContentType = "application/json; charset=utf-8"; + this.baseUri = '{Endpoint}/luis/v3.0-preview'; + this.requestContentType = 'application/json; charset=utf-8'; this.endpoint = endpoint; this.credentials = credentials; } diff --git a/libraries/botbuilder-ai/src/luisV2-models/sentiment.ts b/libraries/botbuilder-ai/src/luisV2-models/sentiment.ts index 750f7ab158..3e6270911e 100644 --- a/libraries/botbuilder-ai/src/luisV2-models/sentiment.ts +++ b/libraries/botbuilder-ai/src/luisV2-models/sentiment.ts @@ -2,12 +2,11 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for * license information. - * + * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ - import { RequestOptionsBase, HttpResponse } from '@azure/core-http'; /** diff --git a/libraries/botbuilder-ai/tests/luisRecognizer.test.js b/libraries/botbuilder-ai/tests/luisRecognizer.test.js index df5a2b38a5..466f49bead 100644 --- a/libraries/botbuilder-ai/tests/luisRecognizer.test.js +++ b/libraries/botbuilder-ai/tests/luisRecognizer.test.js @@ -401,7 +401,7 @@ describe('LuisRecognizer', function () { assert(res.entities.Address[0].$instance.State[0].score); assert( res.entities.Address[0].$instance.State[0].score > 0 && - res.entities.Address[0].$instance.State[0].score <= 1 + res.entities.Address[0].$instance.State[0].score <= 1 ); }); @@ -500,7 +500,8 @@ describe('LuisRecognizer', function () { returnStatusCode(400); const context = new TestContext({ text: 'Hello world!' }); - const errorResponse = "Response 400: The request's body or parameters are incorrect, meaning they are missing, malformed, or too large."; + const errorResponse = + "Response 400: The request's body or parameters are incorrect, meaning they are missing, malformed, or too large."; try { await recognizer.recognize(context); } catch (error) { @@ -560,7 +561,8 @@ describe('LuisRecognizer', function () { returnStatusCode(414); const context = new TestContext({ text: 'Hello world!' }); - const errorResponse = 'Response 414: The query is too long. Please reduce the query length to 500 or less characters.'; + const errorResponse = + 'Response 414: The query is too long. Please reduce the query length to 500 or less characters.'; try { await recognizer.recognize(context); } catch (error) { diff --git a/libraries/botframework-connector/src/auth/index.ts b/libraries/botframework-connector/src/auth/index.ts index 5d78f5bc5c..38a5cb890e 100644 --- a/libraries/botframework-connector/src/auth/index.ts +++ b/libraries/botframework-connector/src/auth/index.ts @@ -39,3 +39,4 @@ export * from './userTokenClient'; export { MsalAppCredentials } from './msalAppCredentials'; export { MsalServiceClientCredentialsFactory } from './msalServiceClientCredentialsFactory'; +export { TokenCredentials } from './tokenCredentials'; diff --git a/libraries/botframework-connector/src/auth/tokenCredentials.ts b/libraries/botframework-connector/src/auth/tokenCredentials.ts new file mode 100644 index 0000000000..8f814e3522 --- /dev/null +++ b/libraries/botframework-connector/src/auth/tokenCredentials.ts @@ -0,0 +1,45 @@ +// 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. + * + * @constructor + * @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. + * @return {Promise} 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); + } +} diff --git a/yarn.lock b/yarn.lock index 9b4b4b766a..7ada2c0944 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14,6 +14,15 @@ resolved "https://registry.yarnpkg.com/@azure/core-asynciterator-polyfill/-/core-asynciterator-polyfill-1.0.0.tgz#dcccebb88406e5c76e0e1d52e8cc4c43a68b3ee7" integrity sha512-kmv8CGrPfN9SwMwrkiBK9VTQYxdFQEGe0BmQk+M8io56P9KNzpAxcWE/1fxJj7uouwN4kXF0BHW8DNlgx+wtCg== +"@azure/core-auth@^1.1.4": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@azure/core-auth/-/core-auth-1.5.0.tgz#a41848c5c31cb3b7c84c409885267d55a2c92e44" + integrity sha512-udzoBuYG1VBoHVohDTrvKjyzel34zt77Bhp7dQntVGGD0ehVq48owENbBG8fIgkHRNUBQH5k1r0hpoMu5L8+kw== + dependencies: + "@azure/abort-controller" "^1.0.0" + "@azure/core-util" "^1.1.0" + tslib "^2.2.0" + "@azure/core-auth@^1.2.0", "@azure/core-auth@^1.4.0": version "1.4.0" resolved "https://registry.yarnpkg.com/@azure/core-auth/-/core-auth-1.4.0.tgz#6fa9661c1705857820dbc216df5ba5665ac36a9e" @@ -134,6 +143,14 @@ dependencies: tslib "^2.0.0" +"@azure/core-util@^1.1.0": + version "1.6.1" + resolved "https://registry.yarnpkg.com/@azure/core-util/-/core-util-1.6.1.tgz#fea221c4fa43c26543bccf799beb30c1c7878f5a" + integrity sha512-h5taHeySlsV9qxuK64KZxy4iln1BtMYlNt5jbuEFN3UFSAd1EwKg/Gjl5a6tZ/W8t6li3xPnutOx7zbDyXnPmQ== + dependencies: + "@azure/abort-controller" "^1.0.0" + tslib "^2.2.0" + "@azure/core-util@^1.1.1": version "1.3.2" resolved "https://registry.yarnpkg.com/@azure/core-util/-/core-util-1.3.2.tgz#3f8cfda1e87fac0ce84f8c1a42fcd6d2a986632d" @@ -214,6 +231,20 @@ resolved "https://registry.yarnpkg.com/@azure/ms-rest-azure-env/-/ms-rest-azure-env-2.0.0.tgz#45809f89763a480924e21d3c620cd40866771625" integrity sha512-dG76W7ElfLi+fbTjnZVGj+M9e0BIEJmRxU6fHaUQ12bZBe8EJKYb2GV50YWNaP2uJiVQ5+7nXEVj1VN1UQtaEw== +"@azure/ms-rest-js@^2.7.0": + version "2.7.0" + resolved "https://registry.yarnpkg.com/@azure/ms-rest-js/-/ms-rest-js-2.7.0.tgz#8639065577ffdf4946951e1d246334ebfd72d537" + integrity sha512-ngbzWbqF+NmztDOpLBVDxYM+XLcUj7nKhxGbSU9WtIsXfRB//cf2ZbAG5HkOrhU9/wd/ORRB6lM/d69RKVjiyA== + dependencies: + "@azure/core-auth" "^1.1.4" + abort-controller "^3.0.0" + form-data "^2.5.0" + node-fetch "^2.6.7" + tslib "^1.10.0" + tunnel "0.0.6" + uuid "^8.3.2" + xml2js "^0.5.0" + "@azure/msal-browser@^2.16.0": version "2.17.0" resolved "https://registry.yarnpkg.com/@azure/msal-browser/-/msal-browser-2.17.0.tgz#beb7d91e6123534b42c0d2ce85eda42a136a8555" @@ -2654,6 +2685,13 @@ abbrev@1: resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== +abort-controller@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392" + integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg== + dependencies: + event-target-shim "^5.0.0" + accepts@^1.3.7, accepts@~1.3.8: version "1.3.8" resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.8.tgz#0bf0be125b67014adcb0b0921e62db7bffe16b2e" @@ -5857,6 +5895,11 @@ event-emitter@~0.3.5: d "1" es5-ext "~0.10.14" +event-target-shim@^5.0.0: + version "5.0.1" + resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789" + integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== + events@^3.0.0: version "3.2.0" resolved "https://registry.yarnpkg.com/events/-/events-3.2.0.tgz#93b87c18f8efcd4202a461aec4dfc0556b639379" @@ -13009,7 +13052,7 @@ tsconfig-paths@^3.9.0: minimist "^1.2.0" strip-bom "^3.0.0" -tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: +tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== @@ -13046,7 +13089,7 @@ tty-browserify@0.0.1: resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.1.tgz#3f05251ee17904dfd0677546670db9651682b811" integrity sha512-C3TaO7K81YvjCgQH9Q1S3R3P3BtN3RIM8n+OvX4il1K1zgE8ZhI0op7kClgkxtutIE8hQrcrHBXvIheqKUUCxw== -tunnel@^0.0.6: +tunnel@0.0.6, tunnel@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c" integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==