diff --git a/lib/services/billingManagement/LICENSE.txt b/lib/services/billingManagement/LICENSE.txt index 5431ba98b9..8f3d856145 100644 --- a/lib/services/billingManagement/LICENSE.txt +++ b/lib/services/billingManagement/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/billingManagement/lib/billingManagementClient.d.ts b/lib/services/billingManagement/lib/billingManagementClient.d.ts index 4699b6243c..a1f5b36dd1 100644 --- a/lib/services/billingManagement/lib/billingManagementClient.d.ts +++ b/lib/services/billingManagement/lib/billingManagementClient.d.ts @@ -59,6 +59,7 @@ export default class BillingManagementClient extends AzureServiceClient { enrollmentAccounts: operations.EnrollmentAccounts; billingPeriods: operations.BillingPeriods; invoices: operations.Invoices; + products: operations.Products; operations: operations.Operations; } diff --git a/lib/services/billingManagement/lib/billingManagementClient.js b/lib/services/billingManagement/lib/billingManagementClient.js index 0aa1ebef16..84f5c62494 100644 --- a/lib/services/billingManagement/lib/billingManagementClient.js +++ b/lib/services/billingManagement/lib/billingManagementClient.js @@ -50,7 +50,7 @@ class BillingManagementClient extends ServiceClient { super(credentials, options); - this.apiVersion = '2018-03-01-preview'; + this.apiVersion = '2018-11-01-preview'; this.acceptLanguage = 'en-US'; this.longRunningOperationRetryTimeout = 30; this.generateClientRequestId = true; @@ -75,6 +75,7 @@ class BillingManagementClient extends ServiceClient { this.enrollmentAccounts = new operations.EnrollmentAccounts(this); this.billingPeriods = new operations.BillingPeriods(this); this.invoices = new operations.Invoices(this); + this.products = new operations.Products(this); this.operations = new operations.Operations(this); this.models = models; msRest.addSerializationMixin(this); diff --git a/lib/services/billingManagement/lib/models/index.d.ts b/lib/services/billingManagement/lib/models/index.d.ts index 5520273f45..811fdc1004 100644 --- a/lib/services/billingManagement/lib/models/index.d.ts +++ b/lib/services/billingManagement/lib/models/index.d.ts @@ -16,6 +16,19 @@ export { BaseResource } from 'ms-rest-azure'; export { CloudError } from 'ms-rest-azure'; +/** + * @class + * Initializes a new instance of the TransferProductProperties class. + * @constructor + * The properties of the product to initiate a transfer. + * + * @member {string} [destinationInvoiceSectionId] Destination invoice section + * id. + */ +export interface TransferProductProperties { + destinationInvoiceSectionId?: string; +} + /** * @class * Initializes a new instance of the Resource class. diff --git a/lib/services/billingManagement/lib/models/index.js b/lib/services/billingManagement/lib/models/index.js index 046580e949..29708a21dc 100644 --- a/lib/services/billingManagement/lib/models/index.js +++ b/lib/services/billingManagement/lib/models/index.js @@ -18,6 +18,7 @@ var msRestAzure = require('ms-rest-azure'); exports.BaseResource = msRestAzure.BaseResource; exports.CloudError = msRestAzure.CloudError; +exports.TransferProductProperties = require('./transferProductProperties'); exports.Resource = require('./resource'); exports.EnrollmentAccount = require('./enrollmentAccount'); exports.BillingPeriod = require('./billingPeriod'); diff --git a/lib/services/billingManagement/lib/models/transferProductProperties.js b/lib/services/billingManagement/lib/models/transferProductProperties.js new file mode 100644 index 0000000000..8d96fbafef --- /dev/null +++ b/lib/services/billingManagement/lib/models/transferProductProperties.js @@ -0,0 +1,53 @@ +/* + * 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'; + +/** + * The properties of the product to initiate a transfer. + * + */ +class TransferProductProperties { + /** + * Create a TransferProductProperties. + * @member {string} [destinationInvoiceSectionId] Destination invoice section + * id. + */ + constructor() { + } + + /** + * Defines the metadata of TransferProductProperties + * + * @returns {object} metadata of TransferProductProperties + * + */ + mapper() { + return { + required: false, + serializedName: 'TransferProductProperties', + type: { + name: 'Composite', + className: 'TransferProductProperties', + modelProperties: { + destinationInvoiceSectionId: { + required: false, + serializedName: 'destinationInvoiceSectionId', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = TransferProductProperties; diff --git a/lib/services/billingManagement/lib/operations/index.d.ts b/lib/services/billingManagement/lib/operations/index.d.ts index 3131b77c2e..6e8726aa69 100644 --- a/lib/services/billingManagement/lib/operations/index.d.ts +++ b/lib/services/billingManagement/lib/operations/index.d.ts @@ -693,6 +693,83 @@ export interface Invoices { listNext(nextPageLink: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } +/** + * @class + * Products + * __NOTE__: An instance of this class is automatically created for an + * instance of the BillingManagementClient. + */ +export interface Products { + + + /** + * The operation to transfer a Product to another InvoiceSection. + * + * @param {string} billingAccountId billing Account Id. + * + * @param {string} invoiceSectionId Invoice Id. + * + * @param {string} productName Product Id. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.destinationInvoiceSectionId] Destination invoice + * section id. + * + * @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. + */ + transferWithHttpOperationResponse(billingAccountId: string, invoiceSectionId: string, productName: string, options?: { destinationInvoiceSectionId? : string, customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * The operation to transfer a Product to another InvoiceSection. + * + * @param {string} billingAccountId billing Account Id. + * + * @param {string} invoiceSectionId Invoice Id. + * + * @param {string} productName Product Id. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.destinationInvoiceSectionId] Destination invoice + * section id. + * + * @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 {null} - 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. + * + * {null} [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. + */ + transfer(billingAccountId: string, invoiceSectionId: string, productName: string, options?: { destinationInvoiceSectionId? : string, customHeaders? : { [headerName: string]: string; } }): Promise; + transfer(billingAccountId: string, invoiceSectionId: string, productName: string, callback: ServiceCallback): void; + transfer(billingAccountId: string, invoiceSectionId: string, productName: string, options: { destinationInvoiceSectionId? : string, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; +} + /** * @class * Operations diff --git a/lib/services/billingManagement/lib/operations/index.js b/lib/services/billingManagement/lib/operations/index.js index ae2c2db552..0099628d7d 100644 --- a/lib/services/billingManagement/lib/operations/index.js +++ b/lib/services/billingManagement/lib/operations/index.js @@ -17,4 +17,5 @@ exports.EnrollmentAccounts = require('./enrollmentAccounts'); exports.BillingPeriods = require('./billingPeriods'); exports.Invoices = require('./invoices'); +exports.Products = require('./products'); exports.Operations = require('./operations'); diff --git a/lib/services/billingManagement/lib/operations/products.js b/lib/services/billingManagement/lib/operations/products.js new file mode 100644 index 0000000000..5d6ff3dc59 --- /dev/null +++ b/lib/services/billingManagement/lib/operations/products.js @@ -0,0 +1,281 @@ +/* + * 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; + +/** + * The operation to transfer a Product to another InvoiceSection. + * + * @param {string} billingAccountId billing Account Id. + * + * @param {string} invoiceSectionId Invoice Id. + * + * @param {string} productName Product Id. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.destinationInvoiceSectionId] Destination invoice + * section id. + * + * @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. + * + * {null} [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 _transfer(billingAccountId, invoiceSectionId, productName, 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.'); + } + let destinationInvoiceSectionId = (options && options.destinationInvoiceSectionId !== undefined) ? options.destinationInvoiceSectionId : undefined; + // Validate + try { + if (billingAccountId === null || billingAccountId === undefined || typeof billingAccountId.valueOf() !== 'string') { + throw new Error('billingAccountId cannot be null or undefined and it must be of type string.'); + } + if (invoiceSectionId === null || invoiceSectionId === undefined || typeof invoiceSectionId.valueOf() !== 'string') { + throw new Error('invoiceSectionId cannot be null or undefined and it must be of type string.'); + } + if (productName === null || productName === undefined || typeof productName.valueOf() !== 'string') { + throw new Error('productName 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 (destinationInvoiceSectionId !== null && destinationInvoiceSectionId !== undefined && typeof destinationInvoiceSectionId.valueOf() !== 'string') { + throw new Error('destinationInvoiceSectionId 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 (destinationInvoiceSectionId !== null && destinationInvoiceSectionId !== undefined) { + parameters = new client.models['TransferProductProperties'](); + parameters.destinationInvoiceSectionId = destinationInvoiceSectionId; + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}/products/{productName}/transfer'; + requestUrl = requestUrl.replace('{billingAccountId}', encodeURIComponent(billingAccountId)); + requestUrl = requestUrl.replace('{invoiceSectionId}', encodeURIComponent(invoiceSectionId)); + requestUrl = requestUrl.replace('{productName}', encodeURIComponent(productName)); + 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['TransferProductProperties']().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 !== 202) { + 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; + + return callback(null, result, httpRequest, response); + }); +} + +/** Class representing a Products. */ +class Products { + /** + * Create a Products. + * @param {BillingManagementClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._transfer = _transfer; + } + + /** + * The operation to transfer a Product to another InvoiceSection. + * + * @param {string} billingAccountId billing Account Id. + * + * @param {string} invoiceSectionId Invoice Id. + * + * @param {string} productName Product Id. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.destinationInvoiceSectionId] Destination invoice + * section id. + * + * @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. + */ + transferWithHttpOperationResponse(billingAccountId, invoiceSectionId, productName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._transfer(billingAccountId, invoiceSectionId, productName, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * The operation to transfer a Product to another InvoiceSection. + * + * @param {string} billingAccountId billing Account Id. + * + * @param {string} invoiceSectionId Invoice Id. + * + * @param {string} productName Product Id. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.destinationInvoiceSectionId] Destination invoice + * section id. + * + * @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 {null} - 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. + * + * {null} [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. + */ + transfer(billingAccountId, invoiceSectionId, productName, 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._transfer(billingAccountId, invoiceSectionId, productName, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._transfer(billingAccountId, invoiceSectionId, productName, options, optionalCallback); + } + } + +} + +module.exports = Products;