Upgrade azure auth and runtime clients (#497)

* Upgrade azure auth and runtime clients and adjust tests and src ode accordingly

* Fix lint issues

* trigger build

* Upgrade @azure/cognitiveservices-luis-authoring to v4.0.0-preview.1

Co-authored-by: Emilio Munoz <munoz_emilio@hotmail.com>
This commit is contained in:
JSpru 2020-01-29 02:15:37 -08:00 коммит произвёл GitHub
Родитель d5257b9289
Коммит 096a1fd13c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 47 добавлений и 41 удалений

Просмотреть файл

@ -1,5 +1,5 @@
dependencies:
'@azure/cognitiveservices-luis-authoring': 3.0.1
'@azure/cognitiveservices-luis-runtime': 5.0.0
'@azure/ms-rest-azure-js': 2.0.1
'@oclif/command': 1.5.19
'@oclif/config': 1.13.3
@ -25,8 +25,6 @@ dependencies:
antlr4: 4.7.2
applicationinsights: 1.6.0
await-delay: 1.0.0
azure-cognitiveservices-luis-authoring: 2.1.1
azure-cognitiveservices-luis-runtime: 3.0.0
botbuilder-lg: 4.7.0-preview
botframework-expressions: 4.7.0-preview
botframework-schema: 4.7.0
@ -55,7 +53,6 @@ dependencies:
md5: 2.2.1
mime-types: 2.1.26
minimist: 1.2.0
ms-rest: 2.5.3
nock: 11.7.2
node-fetch: 2.6.0
nyc: 14.1.1
@ -83,6 +80,20 @@ packages:
dev: false
resolution:
integrity: sha512-GfRZbJPREWtSOQUy6iZzNw/7k/apnijgONgUN5XnGMmbNSdrLrxZFBSKGwr9jNGYmcaqF+opR28QJZw4KMnzgg==
/@azure/cognitiveservices-luis-authoring/4.0.0-preview.1:
dependencies:
'@azure/ms-rest-js': 2.0.5
tslib: 1.10.0
dev: false
resolution:
integrity: sha512-HAhnf+57iHn1s7U5H7Rr51JZQINeJeT0uxtXr/Ksa6wbmZDOm+VApWnFwp/+QH1ZnW8S6Qf0roKtuTeEBjmBZA==
/@azure/cognitiveservices-luis-runtime/5.0.0:
dependencies:
'@azure/ms-rest-js': 2.0.5
tslib: 1.10.0
dev: false
resolution:
integrity: sha512-HzrRVohaqHdbvxEmON2JThnjfPFpF4PW05RDg8sRS7KsfetjozgQhP57vjJH2ERkJlAWUkoQCtLboAswCWcZQA==
/@azure/ms-rest-azure-js/2.0.1:
dependencies:
'@azure/ms-rest-js': 2.0.5
@ -6117,6 +6128,9 @@ packages:
version: 0.0.0
'file:projects/bf-luis-cli.tgz':
dependencies:
'@azure/cognitiveservices-luis-authoring': 4.0.0-preview.1
'@azure/cognitiveservices-luis-runtime': 5.0.0
'@azure/ms-rest-azure-js': 2.0.1
'@oclif/command': 1.5.19
'@oclif/config': 1.13.3
'@oclif/dev-cli': 1.22.2
@ -6148,7 +6162,7 @@ packages:
dev: false
name: '@rush-temp/bf-luis-cli'
resolution:
integrity: sha512-IzADAHOaGXtzGvts+jWkLeI5I8XSBDekw9TW+7sYO+x1FXcgPkz22xKHGnN1kP/mH4GJFCx7KCFZr7T5P/XeZA==
integrity: sha512-JH3A+XDHWIh3PXmu/g7kh1Fe5m/3IsBfTaL6Ofq63DbQfjaMJxX6f63Ut4mDR/2uvb/zF2X/m8kHQtsZuwyg2g==
tarball: 'file:projects/bf-luis-cli.tgz'
version: 0.0.0
'file:projects/bf-qnamaker.tgz':
@ -6234,7 +6248,7 @@ packages:
version: 0.0.0
registry: ''
specifiers:
'@azure/cognitiveservices-luis-authoring': 3.0.1
'@azure/cognitiveservices-luis-runtime': 5.0.0
'@azure/ms-rest-azure-js': 2.0.1
'@oclif/command': ~1.5.19
'@oclif/config': ~1.13.3
@ -6260,8 +6274,6 @@ specifiers:
antlr4: ^4.7.2
applicationinsights: ^1.0.8
await-delay: ^1.0.0
azure-cognitiveservices-luis-authoring: 2.1.1
azure-cognitiveservices-luis-runtime: 3.0.0
botbuilder-lg: ~4.7.0-preview
botframework-expressions: ~4.7.0-preview
botframework-schema: ^4.5.1
@ -6290,7 +6302,6 @@ specifiers:
md5: ^2.2.1
mime-types: ^2.1.18
minimist: ^1.2.0
ms-rest: 2.5.3
nock: ^11.7.0
node-fetch: ^2.1.2
nyc: ^14.1.1

Просмотреть файл

@ -37,16 +37,16 @@
"version": "npm run doc:readme && git add README.md"
},
"dependencies": {
"@azure/cognitiveservices-luis-authoring": "4.0.0-preview.1",
"@azure/cognitiveservices-luis-runtime": "5.0.0",
"@azure/ms-rest-azure-js": "2.0.1",
"@microsoft/bf-cli-command": "1.0.0",
"@oclif/command": "~1.5.19",
"@oclif/config": "~1.13.3",
"@oclif/errors": "~1.2.2",
"@types/sinon": "^7.5.0",
"azure-cognitiveservices-luis-authoring": "2.1.1",
"azure-cognitiveservices-luis-runtime": "3.0.0",
"cli-ux": "~5.3.3",
"fs-extra": "^8.1.0",
"ms-rest": "2.5.3",
"tslib": "^1.10.0"
},
"devDependencies": {

Просмотреть файл

@ -56,16 +56,16 @@ export default class LuisApplicationCreate extends Command {
const applicationCreateObject = {name, culture, description, versionId, usageScenario, tokenizerVersion}
try {
const newAppId = await client.apps.add(applicationCreateObject, options)
this.log(`App successfully created with id ${newAppId}.`)
const response = await client.apps.add(applicationCreateObject, options)
this.log(`App successfully created with id ${response.body}.`)
if (save) {
const config = {
appId: newAppId,
appId: response.body,
endpoint,
subscriptionKey
}
const response = await this.saveImportedConfig(config, configDir)
if (response) this.log('Config settings saved')
const saveConfigResponse = await this.saveImportedConfig(config, configDir)
if (saveConfigResponse) this.log('Config settings saved')
}
} catch (err) {
throw new CLIError(`Failed to create app: ${err}`)

Просмотреть файл

@ -45,8 +45,8 @@ export default class LuisApplicationImport extends Command {
if (name) options.appName = name
try {
const newAppId = await client.apps.importMethod(JSON.parse(appJSON), options)
this.log(`App successfully imported with id ${newAppId}.`)
const response = await client.apps.importMethod(JSON.parse(appJSON), options)
this.log(`App successfully imported with id ${response.body}.`)
} catch (err) {
throw new CLIError(`Failed to import app: ${err}`)
}

Просмотреть файл

@ -70,7 +70,7 @@ export default class LuisApplicationQuery extends Command {
}
try {
const predictionData = await client.predictionOperations.getSlotPrediction(appId, slotName, predictionRequest, options)
const predictionData = await client.prediction.getSlotPrediction(appId, slotName, predictionRequest, options)
this.log(`${JSON.stringify(predictionData, null, 2)}`)
} catch (err) {
throw new CLIError(`Failed to fetch prediction data: ${err}`)

Просмотреть файл

@ -46,8 +46,8 @@ export default class LuisVersionImport extends Command {
const client = utils.getLUISClient(subscriptionKey, endpoint)
try {
const newVersionId = await client.versions.importMethod(appId, JSON.parse(appJSON), options)
this.log(`App version successfully imported as version ${newVersionId}.`)
const response = await client.versions.importMethod(appId, JSON.parse(appJSON), options)
this.log(`App version successfully imported as version ${response.body}.`)
} catch (err) {
throw new CLIError(`Failed to import app version: ${err}`)
}

Просмотреть файл

@ -3,12 +3,12 @@
* Licensed under the MIT License.
*/
import {LUISAuthoringClient} from '@azure/cognitiveservices-luis-authoring'
import {LUISRuntimeClient} from '@azure/cognitiveservices-luis-runtime'
import {CognitiveServicesCredentials} from '@azure/ms-rest-azure-js'
import {CLIError, utils} from '@microsoft/bf-cli-command'
const path = require('path')
const fs = require('fs-extra')
const msRest = require('ms-rest')
const {LUISAuthoringClient} = require('azure-cognitiveservices-luis-authoring')
const {LUISRuntimeClient} = require('azure-cognitiveservices-luis-runtime')
const configPrefix = 'luis__'
@ -50,18 +50,13 @@ const writeUserConfig = async (userconfig: any, configPath: string) => {
}
const getLUISClient = (subscriptionKey: string, endpoint: string, runtime: boolean) => {
const token = {
inHeader: {
'Ocp-Apim-Subscription-Key': subscriptionKey
}
}
const creds = new msRest.ApiKeyCredentials(token)
const authoringKey = subscriptionKey
const creds = new CognitiveServicesCredentials(authoringKey)
const luisClient = runtime ?
new LUISRuntimeClient(creds, endpoint) :
new LUISAuthoringClient(creds, endpoint)
luisClient.baseUri = runtime ?
'https://westus.api.cognitive.microsoft.com/luis/prediction/v3.0/' :
'https://westus.api.cognitive.microsoft.com/luis/authoring/v3.0-preview/'
return luisClient
}
@ -93,7 +88,7 @@ const processInputs = async (flags: any, flagLabels: string[], configDir: string
.filter(flag => flag !== 'help')
.map((flag: string) => {
if (flag === 'in') {
// rename property since 'in' is a reserved keyword in Javascript
// rename property since 'in' is a reserved keyword
input[`${flag}Val`] = flags[flag]
}
input[flag] = flags[flag] || (config ? config[configPrefix + flag] : null)

Просмотреть файл

@ -54,8 +54,8 @@ describe('luis:application:create', () => {
.stdout()
.stderr()
.command(['luis:application:create', '--endpoint', 'undefined', '--name', 'orange_app', '--subscriptionKey', uuidv1(), '--culture', 'en-us', '--description', 'test description', '--versionId', '0.04'])
.it('fails to create an app and displays an error message if the endpoint is null', ctx => {
expect(ctx.stderr).to.contain('Access denied due to invalid subscription key or wrong API endpoint.')
.it('fails to create an app and displays an error message if the endpoint is undefined', ctx => {
expect(ctx.stderr).to.contain('Failed to create app: TypeError: Only absolute URLs are supported\n')
})
})

Просмотреть файл

@ -57,8 +57,8 @@ describe('luis:application:rename', () => {
.stdout()
.stderr()
.command(['luis:application:rename', '--endpoint', 'undefined', '--subscriptionKey', uuidv1(), '--appId', uuidv1(), '--name', 'sample-app', '--description', 'test description'])
.it('fails to create an app and displays an error message if the endpoint is null', ctx => {
expect(ctx.stderr).to.contain('Access denied due to invalid subscription key or wrong API endpoint.')
.it('fails to create an app and displays an error message if the endpoint is undefined', ctx => {
expect(ctx.stderr).to.contain('Failed to rename app: TypeError: Only absolute URLs are supported\n')
})
})

Просмотреть файл

@ -51,8 +51,8 @@ describe('luis:version:rename', () => {
.stdout()
.stderr()
.command(['luis:version:rename', '--endpoint', 'undefined', '--subscriptionKey', uuidv1(), '--appId', uuidv1(), '--versionId', '0.1', '--newVersionId', '0.2'])
.it('fails to rename application version and displays an error message if the endpoint is null', ctx => {
expect(ctx.stderr).to.contain('Access denied due to invalid subscription key or wrong API endpoint.')
.it('fails to rename application version and displays an error message if the endpoint is undefined', ctx => {
expect(ctx.stderr).to.contain('Failed to rename app version: TypeError: Only absolute URLs are supported\n')
})
})