@@ -10,15 +10,23 @@ import {isEqual, differenceWith} from 'lodash'
1010import { CognitiveServicesCredentials } from '@azure/ms-rest-azure-js'
1111import { LUISAuthoringClient } from '@azure/cognitiveservices-luis-authoring'
1212import * as path from 'path'
13+ import fetch from 'node-fetch'
14+ const retCode = require ( './../utils/enums/CLI-errors' )
15+ const exception = require ( './../utils/exception' )
1316const Content = require ( './../lu/lu' )
1417const LUOptions = require ( './../lu/luOptions' )
1518
1619export class LuBuildCore {
1720 private readonly client : any
21+ private readonly subscriptionKey : string
22+ private readonly endpoint : string
23+
24+ constructor ( subscriptionKey : string , endpoint : string ) {
25+ this . subscriptionKey = subscriptionKey
26+ this . endpoint = endpoint
1827
19- constructor ( authoringKey : string , endpoint : string ) {
2028 // new luis api client
21- const creds = new CognitiveServicesCredentials ( authoringKey )
29+ const creds = new CognitiveServicesCredentials ( subscriptionKey )
2230 this . client = new LUISAuthoringClient ( creds , endpoint )
2331 }
2432
@@ -35,9 +43,23 @@ export class LuBuildCore {
3543 }
3644
3745 public async importApplication ( currentApp : any ) : Promise < any > {
38- let response = await this . client . apps . importMethod ( currentApp )
46+ // let response = await this.client.apps.importMethod(currentApp)
3947
40- return response
48+ const name = `?appName=${ currentApp . name } `
49+ const url = this . endpoint + '/luis/authoring/v3.0-preview/apps/import' + name
50+ const headers = {
51+ 'Content-Type' : 'application/json' ,
52+ 'Ocp-Apim-Subscription-Key' : this . subscriptionKey
53+ }
54+
55+ const response = await fetch ( url , { method : 'POST' , headers, body : JSON . stringify ( currentApp ) } )
56+ const messageData = await response . json ( )
57+
58+ if ( messageData . error ) {
59+ throw ( new exception ( retCode . errorCode . LUIS_API_CALL_FAILED , messageData . error . message ) )
60+ }
61+
62+ return messageData
4163 }
4264
4365 public async exportApplication ( appId : string , versionId : string ) {
@@ -91,7 +113,23 @@ export class LuBuildCore {
91113 }
92114
93115 public async importNewVersion ( appId : string , app : any , options : any ) {
94- await this . client . versions . importMethod ( appId , app , options )
116+ // await this.client.versions.importMethod(appId, app, options)
117+
118+ const versionId = `?versionId=${ options . versionId } `
119+ let url = this . endpoint + '/luis/authoring/v3.0-preview/apps/' + appId + '/versions/import' + versionId
120+ const headers = {
121+ 'Content-Type' : 'application/json' ,
122+ 'Ocp-Apim-Subscription-Key' : this . subscriptionKey
123+ }
124+
125+ const response = await fetch ( url , { method : 'POST' , headers, body : JSON . stringify ( app ) } )
126+ const messageData = await response . json ( )
127+
128+ if ( messageData . error ) {
129+ throw ( new exception ( retCode . errorCode . LUIS_API_CALL_FAILED , messageData . error . message ) )
130+ }
131+
132+ return messageData
95133 }
96134
97135 public async listApplicationVersions ( appId : string ) {
0 commit comments