diff --git a/lib/services/cognitiveServicesManagement/LICENSE.txt b/lib/services/cognitiveServicesManagement/LICENSE.txt index 5431ba98b9..8f3d856145 100644 --- a/lib/services/cognitiveServicesManagement/LICENSE.txt +++ b/lib/services/cognitiveServicesManagement/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018 Microsoft +Copyright (c) 2019 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 diff --git a/lib/services/cognitiveServicesManagement/README.md b/lib/services/cognitiveServicesManagement/README.md index 73aef99130..8d2ea27b0a 100644 --- a/lib/services/cognitiveServicesManagement/README.md +++ b/lib/services/cognitiveServicesManagement/README.md @@ -43,6 +43,3 @@ msRestAzure.interactiveLogin().then((creds) => { ### Related projects - [Microsoft Azure SDK for Node.js](https://github.com/Azure/azure-sdk-for-node) - - -![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-node%2Flib%2Fservices%2FcognitiveServicesManagement%2FREADME.png) diff --git a/lib/services/cognitiveServicesManagement/lib/cognitiveServicesManagementClient.d.ts b/lib/services/cognitiveServicesManagement/lib/cognitiveServicesManagementClient.d.ts index 1ed201f2bb..c36c5f9170 100644 --- a/lib/services/cognitiveServicesManagement/lib/cognitiveServicesManagementClient.d.ts +++ b/lib/services/cognitiveServicesManagement/lib/cognitiveServicesManagementClient.d.ts @@ -60,6 +60,7 @@ export default class CognitiveServicesManagementClient extends AzureServiceClien resourceSkus: operations.ResourceSkus; operations: operations.Operations; checkSkuAvailability: operations.CheckSkuAvailability; + locations: operations.Locations; } export { CognitiveServicesManagementClient, models as CognitiveServicesManagementModels }; diff --git a/lib/services/cognitiveServicesManagement/lib/cognitiveServicesManagementClient.js b/lib/services/cognitiveServicesManagement/lib/cognitiveServicesManagementClient.js index 5b59f983d0..848fb84e6f 100644 --- a/lib/services/cognitiveServicesManagement/lib/cognitiveServicesManagementClient.js +++ b/lib/services/cognitiveServicesManagement/lib/cognitiveServicesManagementClient.js @@ -76,6 +76,7 @@ class CognitiveServicesManagementClient extends ServiceClient { this.resourceSkus = new operations.ResourceSkus(this); this.operations = new operations.Operations(this); this.checkSkuAvailability = new operations.CheckSkuAvailability(this); + this.locations = new operations.Locations(this); this.models = models; msRest.addSerializationMixin(this); } diff --git a/lib/services/cognitiveServicesManagement/lib/models/checkDomainAvailabilityParameter.js b/lib/services/cognitiveServicesManagement/lib/models/checkDomainAvailabilityParameter.js new file mode 100644 index 0000000000..9ee6b18f14 --- /dev/null +++ b/lib/services/cognitiveServicesManagement/lib/models/checkDomainAvailabilityParameter.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'; + +/** + * Check Domain availability parameter. + * + */ +class CheckDomainAvailabilityParameter { + /** + * Create a CheckDomainAvailabilityParameter. + * @property {string} subdomainName The subdomain name to use. + * @property {string} type The Type of the resource. + */ + constructor() { + } + + /** + * Defines the metadata of CheckDomainAvailabilityParameter + * + * @returns {object} metadata of CheckDomainAvailabilityParameter + * + */ + mapper() { + return { + required: false, + serializedName: 'CheckDomainAvailabilityParameter', + type: { + name: 'Composite', + className: 'CheckDomainAvailabilityParameter', + modelProperties: { + subdomainName: { + required: true, + serializedName: 'subdomainName', + type: { + name: 'String' + } + }, + type: { + required: true, + serializedName: 'type', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = CheckDomainAvailabilityParameter; diff --git a/lib/services/cognitiveServicesManagement/lib/models/checkDomainAvailabilityResult.js b/lib/services/cognitiveServicesManagement/lib/models/checkDomainAvailabilityResult.js new file mode 100644 index 0000000000..0b9359b307 --- /dev/null +++ b/lib/services/cognitiveServicesManagement/lib/models/checkDomainAvailabilityResult.js @@ -0,0 +1,77 @@ +/* + * 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'; + +/** + * Check Domain availability result. + * + */ +class CheckDomainAvailabilityResult { + /** + * Create a CheckDomainAvailabilityResult. + * @property {boolean} [isSubdomainAvailable] Indicates the given SKU is + * available or not. + * @property {string} [reason] Reason why the SKU is not available. + * @property {string} [subdomainName] The subdomain name to use. + * @property {string} [type] The Type of the resource. + */ + constructor() { + } + + /** + * Defines the metadata of CheckDomainAvailabilityResult + * + * @returns {object} metadata of CheckDomainAvailabilityResult + * + */ + mapper() { + return { + required: false, + serializedName: 'CheckDomainAvailabilityResult', + type: { + name: 'Composite', + className: 'CheckDomainAvailabilityResult', + modelProperties: { + isSubdomainAvailable: { + required: false, + serializedName: 'isSubdomainAvailable', + type: { + name: 'Boolean' + } + }, + reason: { + required: false, + serializedName: 'reason', + type: { + name: 'String' + } + }, + subdomainName: { + required: false, + serializedName: 'subdomainName', + type: { + name: 'String' + } + }, + type: { + required: false, + serializedName: 'type', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = CheckDomainAvailabilityResult; diff --git a/lib/services/cognitiveServicesManagement/lib/models/cognitiveServicesAccount.js b/lib/services/cognitiveServicesManagement/lib/models/cognitiveServicesAccount.js index 72dab98741..db92cf8dde 100644 --- a/lib/services/cognitiveServicesManagement/lib/models/cognitiveServicesAccount.js +++ b/lib/services/cognitiveServicesManagement/lib/models/cognitiveServicesAccount.js @@ -32,6 +32,8 @@ class CognitiveServicesAccount extends models['BaseResource'] { * 'Failed' * @property {string} [endpoint] Endpoint of the created account. * @property {string} [internalId] The internal identifier. + * @property {string} [customSubDomainName] Optional subdomain name used for + * token-based authentication. * @property {object} [sku] The SKU of Cognitive Services account. * @property {string} [sku.name] Gets or sets the sku name. Required for * account creation, optional for update. @@ -121,6 +123,13 @@ class CognitiveServicesAccount extends models['BaseResource'] { name: 'String' } }, + customSubDomainName: { + required: false, + serializedName: 'properties.customSubDomainName', + type: { + name: 'String' + } + }, sku: { required: false, serializedName: 'sku', diff --git a/lib/services/cognitiveServicesManagement/lib/models/index.d.ts b/lib/services/cognitiveServicesManagement/lib/models/index.d.ts index 205511cf21..83e257a78c 100644 --- a/lib/services/cognitiveServicesManagement/lib/models/index.d.ts +++ b/lib/services/cognitiveServicesManagement/lib/models/index.d.ts @@ -118,6 +118,10 @@ export interface CognitiveServicesAccount extends BaseResource { * The internal identifier. */ internalId?: string; + /** + * Optional subdomain name used for token-based authentication. + */ + customSubDomainName?: string; /** * The SKU of Cognitive Services account. */ @@ -329,6 +333,20 @@ export interface CheckSkuAvailabilityParameter { type: string; } +/** + * Check Domain availability parameter. + */ +export interface CheckDomainAvailabilityParameter { + /** + * The subdomain name to use. + */ + subdomainName: string; + /** + * The Type of the resource. + */ + type: string; +} + /** * Check SKU availability result. */ @@ -369,6 +387,28 @@ export interface CheckSkuAvailabilityResultList { value?: CheckSkuAvailabilityResult[]; } +/** + * Check Domain availability result. + */ +export interface CheckDomainAvailabilityResult { + /** + * Indicates the given SKU is available or not. + */ + isSubdomainAvailable?: boolean; + /** + * Reason why the SKU is not available. + */ + reason?: string; + /** + * The subdomain name to use. + */ + subdomainName?: string; + /** + * The Type of the resource. + */ + type?: string; +} + export interface ResourceSkuRestrictionInfo { /** * Locations where the SKU is restricted diff --git a/lib/services/cognitiveServicesManagement/lib/models/index.js b/lib/services/cognitiveServicesManagement/lib/models/index.js index 0ec9e6e9f3..97cd815d07 100644 --- a/lib/services/cognitiveServicesManagement/lib/models/index.js +++ b/lib/services/cognitiveServicesManagement/lib/models/index.js @@ -34,8 +34,10 @@ exports.ErrorModel = require('./errorModel'); exports.OperationDisplayInfo = require('./operationDisplayInfo'); exports.OperationEntity = require('./operationEntity'); exports.CheckSkuAvailabilityParameter = require('./checkSkuAvailabilityParameter'); +exports.CheckDomainAvailabilityParameter = require('./checkDomainAvailabilityParameter'); exports.CheckSkuAvailabilityResult = require('./checkSkuAvailabilityResult'); exports.CheckSkuAvailabilityResultList = require('./checkSkuAvailabilityResultList'); +exports.CheckDomainAvailabilityResult = require('./checkDomainAvailabilityResult'); exports.ResourceSkuRestrictionInfo = require('./resourceSkuRestrictionInfo'); exports.ResourceSkuRestrictions = require('./resourceSkuRestrictions'); exports.ResourceSku = require('./resourceSku'); diff --git a/lib/services/cognitiveServicesManagement/lib/operations/account.js b/lib/services/cognitiveServicesManagement/lib/operations/account.js new file mode 100644 index 0000000000..d72fae6155 --- /dev/null +++ b/lib/services/cognitiveServicesManagement/lib/operations/account.js @@ -0,0 +1,291 @@ +/* + * 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 msRestAzure = require('ms-rest-azure'); +const WebResource = msRest.WebResource; + +/** + * Check available SKUs. + * + * @param {string} location Resource location. + * + * @param {string} subdomainName The subdomain name to use. + * + * @param {string} type The Type of the resource. + * + * @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 CheckDomainAvailabilityResult} 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 _checkDomainAvailabilityPost(location, subdomainName, type, 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.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') { + throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.'); + } + if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') { + throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.'); + } + if (location === null || location === undefined || typeof location.valueOf() !== 'string') { + throw new Error('location cannot be null or undefined and it must be of type string.'); + } + if (subdomainName === null || subdomainName === undefined || typeof subdomainName.valueOf() !== 'string') { + throw new Error('subdomainName cannot be null or undefined and it must be of type string.'); + } + if (type === null || type === undefined || typeof type.valueOf() !== 'string') { + throw new Error('type cannot be null or undefined and it must be of type string.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + let parameters; + if ((subdomainName !== null && subdomainName !== undefined) || (type !== null && type !== undefined)) { + parameters = new client.models['CheckDomainAvailabilityParameter'](); + parameters.subdomainName = subdomainName; + parameters.type = type; + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.CognitiveServices/locations/{location}/checkDomainAvailability'; + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + requestUrl = requestUrl.replace('{location}', encodeURIComponent(location)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'POST'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + 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 (parameters !== null && parameters !== undefined) { + let requestModelMapper = new client.models['CheckDomainAvailabilityParameter']().mapper(); + requestModel = client.serialize(requestModelMapper, parameters, 'parameters'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(parameters, 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) { + if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; + if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; + if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['CloudError']().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['CheckDomainAvailabilityResult']().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 Account. */ +class Account { + /** + * Create a Account. + * @param {CognitiveServicesManagementClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._checkDomainAvailabilityPost = _checkDomainAvailabilityPost; + } + + /** + * Check available SKUs. + * + * @param {string} location Resource location. + * + * @param {string} subdomainName The subdomain name to use. + * + * @param {string} type The Type of the resource. + * + * @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. + */ + checkDomainAvailabilityPostWithHttpOperationResponse(location, subdomainName, type, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._checkDomainAvailabilityPost(location, subdomainName, type, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Check available SKUs. + * + * @param {string} location Resource location. + * + * @param {string} subdomainName The subdomain name to use. + * + * @param {string} type The Type of the resource. + * + * @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 {CheckDomainAvailabilityResult} - 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 CheckDomainAvailabilityResult} 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. + */ + checkDomainAvailabilityPost(location, subdomainName, type, 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._checkDomainAvailabilityPost(location, subdomainName, type, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._checkDomainAvailabilityPost(location, subdomainName, type, options, optionalCallback); + } + } + +} + +module.exports = Account; diff --git a/lib/services/cognitiveServicesManagement/lib/operations/index.d.ts b/lib/services/cognitiveServicesManagement/lib/operations/index.d.ts index 93833d8469..d7ae276eb2 100644 --- a/lib/services/cognitiveServicesManagement/lib/operations/index.d.ts +++ b/lib/services/cognitiveServicesManagement/lib/operations/index.d.ts @@ -1152,3 +1152,76 @@ export interface CheckSkuAvailability { list(location: string, skus: string[], kind: string, type: string, callback: ServiceCallback): void; list(location: string, skus: string[], kind: string, type: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } + +/** + * @class + * Locations + * __NOTE__: An instance of this class is automatically created for an + * instance of the CognitiveServicesManagementClient. + */ +export interface Locations { + + + /** + * Check available SKUs. + * + * @param {string} location Resource location. + * + * @param {string} subdomainName The subdomain name to use. + * + * @param {string} type The Type of the resource. + * + * @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. + */ + checkDomainAvailabilityPostWithHttpOperationResponse(location: string, subdomainName: string, type: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Check available SKUs. + * + * @param {string} location Resource location. + * + * @param {string} subdomainName The subdomain name to use. + * + * @param {string} type The Type of the resource. + * + * @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 {CheckDomainAvailabilityResult} - 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. + * + * {CheckDomainAvailabilityResult} [result] - The deserialized result object if an error did not occur. + * See {@link CheckDomainAvailabilityResult} 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. + */ + checkDomainAvailabilityPost(location: string, subdomainName: string, type: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + checkDomainAvailabilityPost(location: string, subdomainName: string, type: string, callback: ServiceCallback): void; + checkDomainAvailabilityPost(location: string, subdomainName: string, type: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; +} diff --git a/lib/services/cognitiveServicesManagement/lib/operations/index.js b/lib/services/cognitiveServicesManagement/lib/operations/index.js index 23332ec46b..6492d509dd 100644 --- a/lib/services/cognitiveServicesManagement/lib/operations/index.js +++ b/lib/services/cognitiveServicesManagement/lib/operations/index.js @@ -18,3 +18,4 @@ exports.Accounts = require('./accounts'); exports.ResourceSkus = require('./resourceSkus'); exports.Operations = require('./operations'); exports.CheckSkuAvailability = require('./checkSkuAvailability'); +exports.Locations = require('./locations'); diff --git a/lib/services/cognitiveServicesManagement/lib/operations/locations.js b/lib/services/cognitiveServicesManagement/lib/operations/locations.js new file mode 100644 index 0000000000..fc6d64576a --- /dev/null +++ b/lib/services/cognitiveServicesManagement/lib/operations/locations.js @@ -0,0 +1,291 @@ +/* + * 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 msRestAzure = require('ms-rest-azure'); +const WebResource = msRest.WebResource; + +/** + * Check available SKUs. + * + * @param {string} location Resource location. + * + * @param {string} subdomainName The subdomain name to use. + * + * @param {string} type The Type of the resource. + * + * @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 CheckDomainAvailabilityResult} 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 _checkDomainAvailabilityPost(location, subdomainName, type, 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.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') { + throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.'); + } + if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') { + throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.'); + } + if (location === null || location === undefined || typeof location.valueOf() !== 'string') { + throw new Error('location cannot be null or undefined and it must be of type string.'); + } + if (subdomainName === null || subdomainName === undefined || typeof subdomainName.valueOf() !== 'string') { + throw new Error('subdomainName cannot be null or undefined and it must be of type string.'); + } + if (type === null || type === undefined || typeof type.valueOf() !== 'string') { + throw new Error('type cannot be null or undefined and it must be of type string.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + let parameters; + if ((subdomainName !== null && subdomainName !== undefined) || (type !== null && type !== undefined)) { + parameters = new client.models['CheckDomainAvailabilityParameter'](); + parameters.subdomainName = subdomainName; + parameters.type = type; + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.CognitiveServices/locations/{location}/checkDomainAvailability'; + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + requestUrl = requestUrl.replace('{location}', encodeURIComponent(location)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'POST'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + 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 (parameters !== null && parameters !== undefined) { + let requestModelMapper = new client.models['CheckDomainAvailabilityParameter']().mapper(); + requestModel = client.serialize(requestModelMapper, parameters, 'parameters'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(parameters, 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) { + if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; + if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; + if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['CloudError']().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['CheckDomainAvailabilityResult']().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 Locations. */ +class Locations { + /** + * Create a Locations. + * @param {CognitiveServicesManagementClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._checkDomainAvailabilityPost = _checkDomainAvailabilityPost; + } + + /** + * Check available SKUs. + * + * @param {string} location Resource location. + * + * @param {string} subdomainName The subdomain name to use. + * + * @param {string} type The Type of the resource. + * + * @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. + */ + checkDomainAvailabilityPostWithHttpOperationResponse(location, subdomainName, type, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._checkDomainAvailabilityPost(location, subdomainName, type, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Check available SKUs. + * + * @param {string} location Resource location. + * + * @param {string} subdomainName The subdomain name to use. + * + * @param {string} type The Type of the resource. + * + * @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 {CheckDomainAvailabilityResult} - 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 CheckDomainAvailabilityResult} 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. + */ + checkDomainAvailabilityPost(location, subdomainName, type, 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._checkDomainAvailabilityPost(location, subdomainName, type, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._checkDomainAvailabilityPost(location, subdomainName, type, options, optionalCallback); + } + } + +} + +module.exports = Locations;