diff --git a/lib/services/luis/authoring/LICENSE.txt b/lib/services/luis/authoring/LICENSE.txt index a70e8cf660..5431ba98b9 100644 --- a/lib/services/luis/authoring/LICENSE.txt +++ b/lib/services/luis/authoring/LICENSE.txt @@ -1,21 +1,21 @@ -The MIT License (MIT) - -Copyright (c) 2018 Microsoft - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +The MIT License (MIT) + +Copyright (c) 2018 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/lib/services/luis/authoring/README.md b/lib/services/luis/authoring/README.md index 9f6daa4e1a..66cf2de7e9 100644 --- a/lib/services/luis/authoring/README.md +++ b/lib/services/luis/authoring/README.md @@ -1,44 +1,44 @@ ---- -uid: azure-cognitiveservices-luis-authoring -summary: *content - ---- -# Microsoft Azure SDK for Node.js - LUISAuthoringClient -This project provides a Node.js package for accessing Azure. Right now it supports: -- **Node.js version 6.x.x or higher** - -## Features - - -## How to Install - -```bash -npm install azure-cognitiveservices-luis-authoring -``` - -## How to use - -### Authentication, client creation and listPhraseLists features as an example. - -```javascript -const msRest = require("ms-rest"); -const LUISAuthoringClient = require("azure-cognitiveservices-luis-authoring"); -const token = ""; -const creds = new msRest.TokenCredentials(token); -const subscriptionId = ""; -const client = new LUISAuthoringClient(creds, subscriptionId); -const appId = ec7b1657-199d-4d8a-bbb2-89a11a42e02a; -const versionId = "testversionId"; -const skip = 1; -const take = 1; -client.features.listPhraseLists(appId, versionId, skip, take).then((result) => { - console.log("The result is:"); - console.log(result); -}).catch((err) => { - console.log('An error occurred:'); - console.dir(err, {depth: null, colors: true}); -}); - -## Related projects - -- [Microsoft Azure SDK for Node.js](https://github.com/Azure/azure-sdk-for-node) +--- +uid: azure-cognitiveservices-luis-authoring +summary: *content + +--- +# Microsoft Azure SDK for Node.js - LUISAuthoringClient +This project provides a Node.js package for accessing Azure. Right now it supports: +- **Node.js version 6.x.x or higher** + +## Features + + +## How to Install + +```bash +npm install azure-cognitiveservices-luis-authoring +``` + +## How to use + +### Authentication, client creation and listPhraseLists features as an example. + +```javascript +const msRest = require("ms-rest"); +const LUISAuthoringClient = require("azure-cognitiveservices-luis-authoring"); +const token = ""; +const creds = new msRest.TokenCredentials(token); +const subscriptionId = ""; +const client = new LUISAuthoringClient(creds, subscriptionId); +const appId = ec7b1657-199d-4d8a-bbb2-89a11a42e02a; +const versionId = "testversionId"; +const skip = 1; +const take = 1; +client.features.listPhraseLists(appId, versionId, skip, take).then((result) => { + console.log("The result is:"); + console.log(result); +}).catch((err) => { + console.log('An error occurred:'); + console.dir(err, {depth: null, colors: true}); +}); + +## Related projects + +- [Microsoft Azure SDK for Node.js](https://github.com/Azure/azure-sdk-for-node) diff --git a/lib/services/luis/authoring/lib/lUISAuthoringClient.d.ts b/lib/services/luis/authoring/lib/lUISAuthoringClient.d.ts index 08ffd0ea4f..016adef630 100644 --- a/lib/services/luis/authoring/lib/lUISAuthoringClient.d.ts +++ b/lib/services/luis/authoring/lib/lUISAuthoringClient.d.ts @@ -47,6 +47,7 @@ export default class LUISAuthoringClient extends ServiceClient { train: operations.Train; permissions: operations.Permissions; pattern: operations.Pattern; + settings: operations.Settings; } export { LUISAuthoringClient, models as LUISAuthoringModels }; diff --git a/lib/services/luis/authoring/lib/lUISAuthoringClient.js b/lib/services/luis/authoring/lib/lUISAuthoringClient.js index b5fa344490..ada27b1c25 100644 --- a/lib/services/luis/authoring/lib/lUISAuthoringClient.js +++ b/lib/services/luis/authoring/lib/lUISAuthoringClient.js @@ -59,6 +59,7 @@ class LUISAuthoringClient extends ServiceClient { this.train = new operations.Train(this); this.permissions = new operations.Permissions(this); this.pattern = new operations.Pattern(this); + this.settings = new operations.Settings(this); this.models = models; msRest.addSerializationMixin(this); } diff --git a/lib/services/luis/authoring/lib/models/appVersionSettingObject.js b/lib/services/luis/authoring/lib/models/appVersionSettingObject.js new file mode 100644 index 0000000000..e4d264da96 --- /dev/null +++ b/lib/services/luis/authoring/lib/models/appVersionSettingObject.js @@ -0,0 +1,60 @@ +/* + * 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. + */ + +'use strict'; + +/** + * Object model of an application version setting. + * + */ +class AppVersionSettingObject { + /** + * Create a AppVersionSettingObject. + * @member {string} [name] The application version setting name. + * @member {string} [value] The application version setting value. + */ + constructor() { + } + + /** + * Defines the metadata of AppVersionSettingObject + * + * @returns {object} metadata of AppVersionSettingObject + * + */ + mapper() { + return { + required: false, + serializedName: 'AppVersionSettingObject', + type: { + name: 'Composite', + className: 'AppVersionSettingObject', + modelProperties: { + name: { + required: false, + serializedName: 'name', + type: { + name: 'String' + } + }, + value: { + required: false, + serializedName: 'value', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = AppVersionSettingObject; diff --git a/lib/services/luis/authoring/lib/models/applicationPublishObject.js b/lib/services/luis/authoring/lib/models/applicationPublishObject.js index 3bc2e06e17..558152074f 100644 --- a/lib/services/luis/authoring/lib/models/applicationPublishObject.js +++ b/lib/services/luis/authoring/lib/models/applicationPublishObject.js @@ -20,8 +20,6 @@ class ApplicationPublishObject { * @member {string} [versionId] The version ID to publish. * @member {boolean} [isStaging] Indicates if the staging slot should be * used, instead of the Production one. Default value: false . - * @member {string} [region] The target region that the application is - * published to. */ constructor() { } @@ -54,13 +52,6 @@ class ApplicationPublishObject { type: { name: 'Boolean' } - }, - region: { - required: false, - serializedName: 'region', - type: { - name: 'String' - } } } } diff --git a/lib/services/luis/authoring/lib/models/index.d.ts b/lib/services/luis/authoring/lib/models/index.d.ts index 2613285b07..856d2a8e70 100644 --- a/lib/services/luis/authoring/lib/models/index.d.ts +++ b/lib/services/luis/authoring/lib/models/index.d.ts @@ -580,13 +580,10 @@ export interface HierarchicalModel { * @member {string} [versionId] The version ID to publish. * @member {boolean} [isStaging] Indicates if the staging slot should be used, * instead of the Production one. Default value: false . - * @member {string} [region] The target region that the application is - * published to. */ export interface ApplicationPublishObject { versionId?: string; isStaging?: boolean; - region?: string; } /** @@ -1756,6 +1753,20 @@ export interface LabelTextObject { text?: string; } +/** + * @class + * Initializes a new instance of the AppVersionSettingObject class. + * @constructor + * Object model of an application version setting. + * + * @member {string} [name] The application version setting name. + * @member {string} [value] The application version setting value. + */ +export interface AppVersionSettingObject { + name?: string; + value?: string; +} + /** * @class * Initializes a new instance of the HierarchicalChildModelUpdateObject class. diff --git a/lib/services/luis/authoring/lib/models/index.js b/lib/services/luis/authoring/lib/models/index.js index ea15399868..2063beae51 100644 --- a/lib/services/luis/authoring/lib/models/index.js +++ b/lib/services/luis/authoring/lib/models/index.js @@ -112,6 +112,7 @@ exports.RegexEntityExtractor = require('./regexEntityExtractor'); exports.PatternAnyEntityExtractor = require('./patternAnyEntityExtractor'); exports.PatternRuleInfo = require('./patternRuleInfo'); exports.LabelTextObject = require('./labelTextObject'); +exports.AppVersionSettingObject = require('./appVersionSettingObject'); exports.HierarchicalChildModelUpdateObject = require('./hierarchicalChildModelUpdateObject'); exports.HierarchicalChildModelCreateObject = require('./hierarchicalChildModelCreateObject'); exports.CompositeChildModelCreateObject = require('./compositeChildModelCreateObject'); diff --git a/lib/services/luis/authoring/lib/operations/apps.js b/lib/services/luis/authoring/lib/operations/apps.js index dd2ab9e476..4c43862aeb 100644 --- a/lib/services/luis/authoring/lib/operations/apps.js +++ b/lib/services/luis/authoring/lib/operations/apps.js @@ -1552,9 +1552,6 @@ function _deleteMethod(appId, options, callback) { * @param {boolean} [applicationPublishObject.isStaging] Indicates if the * staging slot should be used, instead of the Production one. * - * @param {string} [applicationPublishObject.region] The target region that the - * application is published to. - * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -3852,9 +3849,6 @@ class Apps { * @param {boolean} [applicationPublishObject.isStaging] Indicates if the * staging slot should be used, instead of the Production one. * - * @param {string} [applicationPublishObject.region] The target region that the - * application is published to. - * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -3894,9 +3888,6 @@ class Apps { * @param {boolean} [applicationPublishObject.isStaging] Indicates if the * staging slot should be used, instead of the Production one. * - * @param {string} [applicationPublishObject.region] The target region that the - * application is published to. - * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the diff --git a/lib/services/luis/authoring/lib/operations/index.d.ts b/lib/services/luis/authoring/lib/operations/index.d.ts index 41061b4451..5318661967 100644 --- a/lib/services/luis/authoring/lib/operations/index.d.ts +++ b/lib/services/luis/authoring/lib/operations/index.d.ts @@ -8840,9 +8840,6 @@ export interface Apps { * @param {boolean} [applicationPublishObject.isStaging] Indicates if the * staging slot should be used, instead of the Production one. * - * @param {string} [applicationPublishObject.region] The target region that the - * application is published to. - * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -8870,9 +8867,6 @@ export interface Apps { * @param {boolean} [applicationPublishObject.isStaging] Indicates if the * staging slot should be used, instead of the Production one. * - * @param {string} [applicationPublishObject.region] The target region that the - * application is published to. - * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -10942,3 +10936,147 @@ export interface Pattern { getIntentPatterns(appId: string, versionId: string, intentId: string, callback: ServiceCallback): void; getIntentPatterns(appId: string, versionId: string, intentId: string, options: { skip? : number, take? : number, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } + +/** + * @class + * Settings + * __NOTE__: An instance of this class is automatically created for an + * instance of the LUISAuthoringClient. + */ +export interface Settings { + + + /** + * Gets the application version settings. + * + * @param {uuid} appId The application ID. + * + * @param {string} versionId The version ID. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + listWithHttpOperationResponse(appId: string, versionId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Gets the application version settings. + * + * @param {uuid} appId The application ID. + * + * @param {string} versionId The version ID. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {Array} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {Array} [result] - The deserialized result object if an error did not occur. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + list(appId: string, versionId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + list(appId: string, versionId: string, callback: ServiceCallback): void; + list(appId: string, versionId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Updates the application version settings. + * + * @param {uuid} appId The application ID. + * + * @param {string} versionId The version ID. + * + * @param {object} listOfAppVersionSettingObject A list of the updated + * application version settings. + * + * @param {string} [listOfAppVersionSettingObject.name] The application version + * setting name. + * + * @param {string} [listOfAppVersionSettingObject.value] The application + * version setting value. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + updateWithHttpOperationResponse(appId: string, versionId: string, listOfAppVersionSettingObject: models.AppVersionSettingObject, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Updates the application version settings. + * + * @param {uuid} appId The application ID. + * + * @param {string} versionId The version ID. + * + * @param {object} listOfAppVersionSettingObject A list of the updated + * application version settings. + * + * @param {string} [listOfAppVersionSettingObject.name] The application version + * setting name. + * + * @param {string} [listOfAppVersionSettingObject.value] The application + * version setting value. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {OperationStatus} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {OperationStatus} [result] - The deserialized result object if an error did not occur. + * See {@link OperationStatus} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + update(appId: string, versionId: string, listOfAppVersionSettingObject: models.AppVersionSettingObject, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + update(appId: string, versionId: string, listOfAppVersionSettingObject: models.AppVersionSettingObject, callback: ServiceCallback): void; + update(appId: string, versionId: string, listOfAppVersionSettingObject: models.AppVersionSettingObject, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; +} diff --git a/lib/services/luis/authoring/lib/operations/index.js b/lib/services/luis/authoring/lib/operations/index.js index ef0073f054..3cefaa62cb 100644 --- a/lib/services/luis/authoring/lib/operations/index.js +++ b/lib/services/luis/authoring/lib/operations/index.js @@ -22,3 +22,4 @@ exports.Versions = require('./versions'); exports.Train = require('./train'); exports.Permissions = require('./permissions'); exports.Pattern = require('./pattern'); +exports.Settings = require('./settings'); diff --git a/lib/services/luis/authoring/lib/operations/settings.js b/lib/services/luis/authoring/lib/operations/settings.js new file mode 100644 index 0000000000..2eef1a6c4a --- /dev/null +++ b/lib/services/luis/authoring/lib/operations/settings.js @@ -0,0 +1,516 @@ +/* + * 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. + */ + +'use strict'; + +const msRest = require('ms-rest'); +const WebResource = msRest.WebResource; + +/** + * Gets the application version settings. + * + * @param {uuid} appId The application ID. + * + * @param {string} versionId The version ID. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {array} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _list(appId, versionId, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + if (appId === null || appId === undefined || typeof appId.valueOf() !== 'string' || !msRest.isValidUuid(appId)) { + throw new Error('appId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + if (versionId === null || versionId === undefined || typeof versionId.valueOf() !== 'string') { + throw new Error('versionId cannot be null or undefined and it must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'apps/{appId}/versions/{versionId}/settings'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{appId}', encodeURIComponent(appId.toString())); + requestUrl = requestUrl.replace('{versionId}', encodeURIComponent(versionId)); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = { + required: false, + serializedName: 'parsedResponse', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'AppVersionSettingObjectElementType', + type: { + name: 'Composite', + className: 'AppVersionSettingObject' + } + } + } + }; + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** + * Updates the application version settings. + * + * @param {uuid} appId The application ID. + * + * @param {string} versionId The version ID. + * + * @param {object} listOfAppVersionSettingObject A list of the updated + * application version settings. + * + * @param {string} [listOfAppVersionSettingObject.name] The application version + * setting name. + * + * @param {string} [listOfAppVersionSettingObject.value] The application + * version setting value. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link OperationStatus} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _update(appId, versionId, listOfAppVersionSettingObject, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + if (appId === null || appId === undefined || typeof appId.valueOf() !== 'string' || !msRest.isValidUuid(appId)) { + throw new Error('appId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + if (versionId === null || versionId === undefined || typeof versionId.valueOf() !== 'string') { + throw new Error('versionId cannot be null or undefined and it must be of type string.'); + } + if (listOfAppVersionSettingObject === null || listOfAppVersionSettingObject === undefined) { + throw new Error('listOfAppVersionSettingObject cannot be null or undefined.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'apps/{appId}/versions/{versionId}/settings'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{appId}', encodeURIComponent(appId.toString())); + requestUrl = requestUrl.replace('{versionId}', encodeURIComponent(versionId)); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'PUT'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (listOfAppVersionSettingObject !== null && listOfAppVersionSettingObject !== undefined) { + let requestModelMapper = new client.models['AppVersionSettingObject']().mapper(); + requestModel = client.serialize(requestModelMapper, listOfAppVersionSettingObject, 'listOfAppVersionSettingObject'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(listOfAppVersionSettingObject, null, 2)}.`); + return callback(serializationError); + } + httpRequest.body = requestContent; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['OperationStatus']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** Class representing a Settings. */ +class Settings { + /** + * Create a Settings. + * @param {LUISAuthoringClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._list = _list; + this._update = _update; + } + + /** + * Gets the application version settings. + * + * @param {uuid} appId The application ID. + * + * @param {string} versionId The version ID. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + listWithHttpOperationResponse(appId, versionId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._list(appId, versionId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Gets the application version settings. + * + * @param {uuid} appId The application ID. + * + * @param {string} versionId The version ID. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {Array} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {array} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + list(appId, versionId, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._list(appId, versionId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._list(appId, versionId, options, optionalCallback); + } + } + + /** + * Updates the application version settings. + * + * @param {uuid} appId The application ID. + * + * @param {string} versionId The version ID. + * + * @param {object} listOfAppVersionSettingObject A list of the updated + * application version settings. + * + * @param {string} [listOfAppVersionSettingObject.name] The application version + * setting name. + * + * @param {string} [listOfAppVersionSettingObject.value] The application + * version setting value. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + updateWithHttpOperationResponse(appId, versionId, listOfAppVersionSettingObject, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._update(appId, versionId, listOfAppVersionSettingObject, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Updates the application version settings. + * + * @param {uuid} appId The application ID. + * + * @param {string} versionId The version ID. + * + * @param {object} listOfAppVersionSettingObject A list of the updated + * application version settings. + * + * @param {string} [listOfAppVersionSettingObject.name] The application version + * setting name. + * + * @param {string} [listOfAppVersionSettingObject.value] The application + * version setting value. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {OperationStatus} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link OperationStatus} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + update(appId, versionId, listOfAppVersionSettingObject, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._update(appId, versionId, listOfAppVersionSettingObject, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._update(appId, versionId, listOfAppVersionSettingObject, options, optionalCallback); + } + } + +} + +module.exports = Settings;