microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
lib/app-center-node-client/src/codepush/operations/codePushAcquisition.js
782lines · modecode
| 1 | /* |
| 2 | * Code generated by Microsoft (R) AutoRest Code Generator. |
| 3 | * Changes may cause incorrect behavior and will be lost if the code is |
| 4 | * regenerated. |
| 5 | */ |
| 6 | |
| 7 | 'use strict'; |
| 8 | |
| 9 | const msRest = require('ms-rest'); |
| 10 | const WebResource = msRest.WebResource; |
| 11 | |
| 12 | /** |
| 13 | * Report Deployment status metric |
| 14 | * |
| 15 | * @param {object} releaseMetadata Deployment status metric properties |
| 16 | * |
| 17 | * @param {string} releaseMetadata.deploymentKey |
| 18 | * |
| 19 | * @param {string} [releaseMetadata.label] |
| 20 | * |
| 21 | * @param {string} [releaseMetadata.appVersion] |
| 22 | * |
| 23 | * @param {string} [releaseMetadata.previousDeploymentKey] |
| 24 | * |
| 25 | * @param {string} [releaseMetadata.previousLabelOrAppVersion] |
| 26 | * |
| 27 | * @param {string} [releaseMetadata.status] |
| 28 | * |
| 29 | * @param {string} [releaseMetadata.clientUniqueId] |
| 30 | * |
| 31 | * @param {object} [options] Optional Parameters. |
| 32 | * |
| 33 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 34 | * request |
| 35 | * |
| 36 | * @param {function} callback - The callback. |
| 37 | * |
| 38 | * @returns {function} callback(err, result, request, response) |
| 39 | * |
| 40 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 41 | * |
| 42 | * {null} [result] - The deserialized result object if an error did not occur. |
| 43 | * |
| 44 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 45 | * |
| 46 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 47 | */ |
| 48 | function _updateDeployStatus(releaseMetadata, options, callback) { |
| 49 | /* jshint validthis: true */ |
| 50 | let client = this.client; |
| 51 | if(!callback && typeof options === 'function') { |
| 52 | callback = options; |
| 53 | options = null; |
| 54 | } |
| 55 | if (!callback) { |
| 56 | throw new Error('callback cannot be null.'); |
| 57 | } |
| 58 | // Validate |
| 59 | try { |
| 60 | if (releaseMetadata === null || releaseMetadata === undefined) { |
| 61 | throw new Error('releaseMetadata cannot be null or undefined.'); |
| 62 | } |
| 63 | } catch (error) { |
| 64 | return callback(error); |
| 65 | } |
| 66 | |
| 67 | // Construct URL |
| 68 | let baseUrl = this.client.baseUri; |
| 69 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/apps/deployments/releases/report_status/deploy'; |
| 70 | |
| 71 | // Create HTTP transport objects |
| 72 | let httpRequest = new WebResource(); |
| 73 | httpRequest.method = 'POST'; |
| 74 | httpRequest.url = requestUrl; |
| 75 | httpRequest.headers = {}; |
| 76 | // Set Headers |
| 77 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 78 | if(options) { |
| 79 | for(let headerName in options['customHeaders']) { |
| 80 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 81 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | // Serialize Request |
| 86 | let requestContent = null; |
| 87 | let requestModel = null; |
| 88 | try { |
| 89 | if (releaseMetadata !== null && releaseMetadata !== undefined) { |
| 90 | let requestModelMapper = new client.models['CodePushStatusMetricMetadata']().mapper(); |
| 91 | requestModel = client.serialize(requestModelMapper, releaseMetadata, 'releaseMetadata'); |
| 92 | requestContent = JSON.stringify(requestModel); |
| 93 | } |
| 94 | } catch (error) { |
| 95 | let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + |
| 96 | `payload - ${JSON.stringify(releaseMetadata, null, 2)}.`); |
| 97 | return callback(serializationError); |
| 98 | } |
| 99 | httpRequest.body = requestContent; |
| 100 | // Send Request |
| 101 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 102 | if (err) { |
| 103 | return callback(err); |
| 104 | } |
| 105 | let statusCode = response.statusCode; |
| 106 | if (statusCode !== 200) { |
| 107 | let error = new Error(responseBody); |
| 108 | error.statusCode = response.statusCode; |
| 109 | error.request = msRest.stripRequest(httpRequest); |
| 110 | error.response = msRest.stripResponse(response); |
| 111 | if (responseBody === '') responseBody = null; |
| 112 | let parsedErrorResponse; |
| 113 | try { |
| 114 | parsedErrorResponse = JSON.parse(responseBody); |
| 115 | if (parsedErrorResponse) { |
| 116 | let internalError = null; |
| 117 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 118 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 119 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 120 | } |
| 121 | } catch (defaultError) { |
| 122 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 123 | `- "${responseBody}" for the default response.`; |
| 124 | return callback(error); |
| 125 | } |
| 126 | return callback(error); |
| 127 | } |
| 128 | // Create Result |
| 129 | let result = null; |
| 130 | if (responseBody === '') responseBody = null; |
| 131 | |
| 132 | return callback(null, result, httpRequest, response); |
| 133 | }); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Report download of specified release |
| 138 | * |
| 139 | * @param {object} releaseMetadata Deployment status metric properties |
| 140 | * |
| 141 | * @param {string} releaseMetadata.deploymentKey |
| 142 | * |
| 143 | * @param {string} [releaseMetadata.label] |
| 144 | * |
| 145 | * @param {string} [releaseMetadata.appVersion] |
| 146 | * |
| 147 | * @param {string} [releaseMetadata.previousDeploymentKey] |
| 148 | * |
| 149 | * @param {string} [releaseMetadata.previousLabelOrAppVersion] |
| 150 | * |
| 151 | * @param {string} [releaseMetadata.status] |
| 152 | * |
| 153 | * @param {string} [releaseMetadata.clientUniqueId] |
| 154 | * |
| 155 | * @param {object} [options] Optional Parameters. |
| 156 | * |
| 157 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 158 | * request |
| 159 | * |
| 160 | * @param {function} callback - The callback. |
| 161 | * |
| 162 | * @returns {function} callback(err, result, request, response) |
| 163 | * |
| 164 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 165 | * |
| 166 | * {null} [result] - The deserialized result object if an error did not occur. |
| 167 | * |
| 168 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 169 | * |
| 170 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 171 | */ |
| 172 | function _updateDownloadStatus(releaseMetadata, options, callback) { |
| 173 | /* jshint validthis: true */ |
| 174 | let client = this.client; |
| 175 | if(!callback && typeof options === 'function') { |
| 176 | callback = options; |
| 177 | options = null; |
| 178 | } |
| 179 | if (!callback) { |
| 180 | throw new Error('callback cannot be null.'); |
| 181 | } |
| 182 | // Validate |
| 183 | try { |
| 184 | if (releaseMetadata === null || releaseMetadata === undefined) { |
| 185 | throw new Error('releaseMetadata cannot be null or undefined.'); |
| 186 | } |
| 187 | } catch (error) { |
| 188 | return callback(error); |
| 189 | } |
| 190 | |
| 191 | // Construct URL |
| 192 | let baseUrl = this.client.baseUri; |
| 193 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/apps/deployments/releases/report_status/download'; |
| 194 | |
| 195 | // Create HTTP transport objects |
| 196 | let httpRequest = new WebResource(); |
| 197 | httpRequest.method = 'POST'; |
| 198 | httpRequest.url = requestUrl; |
| 199 | httpRequest.headers = {}; |
| 200 | // Set Headers |
| 201 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 202 | if(options) { |
| 203 | for(let headerName in options['customHeaders']) { |
| 204 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 205 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | // Serialize Request |
| 210 | let requestContent = null; |
| 211 | let requestModel = null; |
| 212 | try { |
| 213 | if (releaseMetadata !== null && releaseMetadata !== undefined) { |
| 214 | let requestModelMapper = new client.models['CodePushStatusMetricMetadata']().mapper(); |
| 215 | requestModel = client.serialize(requestModelMapper, releaseMetadata, 'releaseMetadata'); |
| 216 | requestContent = JSON.stringify(requestModel); |
| 217 | } |
| 218 | } catch (error) { |
| 219 | let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + |
| 220 | `payload - ${JSON.stringify(releaseMetadata, null, 2)}.`); |
| 221 | return callback(serializationError); |
| 222 | } |
| 223 | httpRequest.body = requestContent; |
| 224 | // Send Request |
| 225 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 226 | if (err) { |
| 227 | return callback(err); |
| 228 | } |
| 229 | let statusCode = response.statusCode; |
| 230 | if (statusCode !== 200) { |
| 231 | let error = new Error(responseBody); |
| 232 | error.statusCode = response.statusCode; |
| 233 | error.request = msRest.stripRequest(httpRequest); |
| 234 | error.response = msRest.stripResponse(response); |
| 235 | if (responseBody === '') responseBody = null; |
| 236 | let parsedErrorResponse; |
| 237 | try { |
| 238 | parsedErrorResponse = JSON.parse(responseBody); |
| 239 | if (parsedErrorResponse) { |
| 240 | let internalError = null; |
| 241 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 242 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 243 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 244 | } |
| 245 | } catch (defaultError) { |
| 246 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 247 | `- "${responseBody}" for the default response.`; |
| 248 | return callback(error); |
| 249 | } |
| 250 | return callback(error); |
| 251 | } |
| 252 | // Create Result |
| 253 | let result = null; |
| 254 | if (responseBody === '') responseBody = null; |
| 255 | |
| 256 | return callback(null, result, httpRequest, response); |
| 257 | }); |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Check for updates |
| 262 | * |
| 263 | * @param {string} appVersion |
| 264 | * |
| 265 | * @param {string} deploymentKey |
| 266 | * |
| 267 | * @param {object} [options] Optional Parameters. |
| 268 | * |
| 269 | * @param {string} [options.clientUniqueId] |
| 270 | * |
| 271 | * @param {boolean} [options.isCompanion] |
| 272 | * |
| 273 | * @param {string} [options.label] |
| 274 | * |
| 275 | * @param {string} [options.packageHash] |
| 276 | * |
| 277 | * @param {string} [options.previousDeploymentKey] |
| 278 | * |
| 279 | * @param {string} [options.previousLabelOrAppVersion] |
| 280 | * |
| 281 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 282 | * request |
| 283 | * |
| 284 | * @param {function} callback - The callback. |
| 285 | * |
| 286 | * @returns {function} callback(err, result, request, response) |
| 287 | * |
| 288 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 289 | * |
| 290 | * {object} [result] - The deserialized result object if an error did not occur. |
| 291 | * See {@link UpdateCheckResponse} for more information. |
| 292 | * |
| 293 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 294 | * |
| 295 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 296 | */ |
| 297 | function _updateCheck(appVersion, deploymentKey, options, callback) { |
| 298 | /* jshint validthis: true */ |
| 299 | let client = this.client; |
| 300 | if(!callback && typeof options === 'function') { |
| 301 | callback = options; |
| 302 | options = null; |
| 303 | } |
| 304 | if (!callback) { |
| 305 | throw new Error('callback cannot be null.'); |
| 306 | } |
| 307 | let clientUniqueId = (options && options.clientUniqueId !== undefined) ? options.clientUniqueId : undefined; |
| 308 | let isCompanion = (options && options.isCompanion !== undefined) ? options.isCompanion : undefined; |
| 309 | let label = (options && options.label !== undefined) ? options.label : undefined; |
| 310 | let packageHash = (options && options.packageHash !== undefined) ? options.packageHash : undefined; |
| 311 | let previousDeploymentKey = (options && options.previousDeploymentKey !== undefined) ? options.previousDeploymentKey : undefined; |
| 312 | let previousLabelOrAppVersion = (options && options.previousLabelOrAppVersion !== undefined) ? options.previousLabelOrAppVersion : undefined; |
| 313 | // Validate |
| 314 | try { |
| 315 | if (appVersion === null || appVersion === undefined || typeof appVersion.valueOf() !== 'string') { |
| 316 | throw new Error('appVersion cannot be null or undefined and it must be of type string.'); |
| 317 | } |
| 318 | if (clientUniqueId !== null && clientUniqueId !== undefined && typeof clientUniqueId.valueOf() !== 'string') { |
| 319 | throw new Error('clientUniqueId must be of type string.'); |
| 320 | } |
| 321 | if (deploymentKey === null || deploymentKey === undefined || typeof deploymentKey.valueOf() !== 'string') { |
| 322 | throw new Error('deploymentKey cannot be null or undefined and it must be of type string.'); |
| 323 | } |
| 324 | if (isCompanion !== null && isCompanion !== undefined && typeof isCompanion !== 'boolean') { |
| 325 | throw new Error('isCompanion must be of type boolean.'); |
| 326 | } |
| 327 | if (label !== null && label !== undefined && typeof label.valueOf() !== 'string') { |
| 328 | throw new Error('label must be of type string.'); |
| 329 | } |
| 330 | if (packageHash !== null && packageHash !== undefined && typeof packageHash.valueOf() !== 'string') { |
| 331 | throw new Error('packageHash must be of type string.'); |
| 332 | } |
| 333 | if (previousDeploymentKey !== null && previousDeploymentKey !== undefined && typeof previousDeploymentKey.valueOf() !== 'string') { |
| 334 | throw new Error('previousDeploymentKey must be of type string.'); |
| 335 | } |
| 336 | if (previousLabelOrAppVersion !== null && previousLabelOrAppVersion !== undefined && typeof previousLabelOrAppVersion.valueOf() !== 'string') { |
| 337 | throw new Error('previousLabelOrAppVersion must be of type string.'); |
| 338 | } |
| 339 | } catch (error) { |
| 340 | return callback(error); |
| 341 | } |
| 342 | |
| 343 | // Construct URL |
| 344 | let baseUrl = this.client.baseUri; |
| 345 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/apps/deployments/releases/updateCheck'; |
| 346 | let queryParameters = []; |
| 347 | queryParameters.push('app_version=' + encodeURIComponent(appVersion)); |
| 348 | if (clientUniqueId !== null && clientUniqueId !== undefined) { |
| 349 | queryParameters.push('client_unique_id=' + encodeURIComponent(clientUniqueId)); |
| 350 | } |
| 351 | queryParameters.push('deployment_key=' + encodeURIComponent(deploymentKey)); |
| 352 | if (isCompanion !== null && isCompanion !== undefined) { |
| 353 | queryParameters.push('is_companion=' + encodeURIComponent(isCompanion.toString())); |
| 354 | } |
| 355 | if (label !== null && label !== undefined) { |
| 356 | queryParameters.push('label=' + encodeURIComponent(label)); |
| 357 | } |
| 358 | if (packageHash !== null && packageHash !== undefined) { |
| 359 | queryParameters.push('package_hash=' + encodeURIComponent(packageHash)); |
| 360 | } |
| 361 | if (previousDeploymentKey !== null && previousDeploymentKey !== undefined) { |
| 362 | queryParameters.push('previous_deployment_key=' + encodeURIComponent(previousDeploymentKey)); |
| 363 | } |
| 364 | if (previousLabelOrAppVersion !== null && previousLabelOrAppVersion !== undefined) { |
| 365 | queryParameters.push('previous_label_or_app_version=' + encodeURIComponent(previousLabelOrAppVersion)); |
| 366 | } |
| 367 | if (queryParameters.length > 0) { |
| 368 | requestUrl += '?' + queryParameters.join('&'); |
| 369 | } |
| 370 | |
| 371 | // Create HTTP transport objects |
| 372 | let httpRequest = new WebResource(); |
| 373 | httpRequest.method = 'GET'; |
| 374 | httpRequest.url = requestUrl; |
| 375 | httpRequest.headers = {}; |
| 376 | // Set Headers |
| 377 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 378 | if(options) { |
| 379 | for(let headerName in options['customHeaders']) { |
| 380 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 381 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | httpRequest.body = null; |
| 386 | // Send Request |
| 387 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 388 | if (err) { |
| 389 | return callback(err); |
| 390 | } |
| 391 | let statusCode = response.statusCode; |
| 392 | if (statusCode !== 200) { |
| 393 | let error = new Error(responseBody); |
| 394 | error.statusCode = response.statusCode; |
| 395 | error.request = msRest.stripRequest(httpRequest); |
| 396 | error.response = msRest.stripResponse(response); |
| 397 | if (responseBody === '') responseBody = null; |
| 398 | let parsedErrorResponse; |
| 399 | try { |
| 400 | parsedErrorResponse = JSON.parse(responseBody); |
| 401 | if (parsedErrorResponse) { |
| 402 | let internalError = null; |
| 403 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 404 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 405 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 406 | } |
| 407 | } catch (defaultError) { |
| 408 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 409 | `- "${responseBody}" for the default response.`; |
| 410 | return callback(error); |
| 411 | } |
| 412 | return callback(error); |
| 413 | } |
| 414 | // Create Result |
| 415 | let result = null; |
| 416 | if (responseBody === '') responseBody = null; |
| 417 | // Deserialize Response |
| 418 | if (statusCode === 200) { |
| 419 | let parsedResponse = null; |
| 420 | try { |
| 421 | parsedResponse = JSON.parse(responseBody); |
| 422 | result = JSON.parse(responseBody); |
| 423 | if (parsedResponse !== null && parsedResponse !== undefined) { |
| 424 | let resultMapper = new client.models['UpdateCheckResponse']().mapper(); |
| 425 | result = client.deserialize(resultMapper, parsedResponse, 'result'); |
| 426 | } |
| 427 | } catch (error) { |
| 428 | let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); |
| 429 | deserializationError.request = msRest.stripRequest(httpRequest); |
| 430 | deserializationError.response = msRest.stripResponse(response); |
| 431 | return callback(deserializationError); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | return callback(null, result, httpRequest, response); |
| 436 | }); |
| 437 | } |
| 438 | |
| 439 | /** Class representing a CodePushAcquisition. */ |
| 440 | class CodePushAcquisition { |
| 441 | /** |
| 442 | * Create a CodePushAcquisition. |
| 443 | * @param {CodepushClient} client Reference to the service client. |
| 444 | */ |
| 445 | constructor(client) { |
| 446 | this.client = client; |
| 447 | this._updateDeployStatus = _updateDeployStatus; |
| 448 | this._updateDownloadStatus = _updateDownloadStatus; |
| 449 | this._updateCheck = _updateCheck; |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * Report Deployment status metric |
| 454 | * |
| 455 | * @param {object} releaseMetadata Deployment status metric properties |
| 456 | * |
| 457 | * @param {string} releaseMetadata.deploymentKey |
| 458 | * |
| 459 | * @param {string} [releaseMetadata.label] |
| 460 | * |
| 461 | * @param {string} [releaseMetadata.appVersion] |
| 462 | * |
| 463 | * @param {string} [releaseMetadata.previousDeploymentKey] |
| 464 | * |
| 465 | * @param {string} [releaseMetadata.previousLabelOrAppVersion] |
| 466 | * |
| 467 | * @param {string} [releaseMetadata.status] |
| 468 | * |
| 469 | * @param {string} [releaseMetadata.clientUniqueId] |
| 470 | * |
| 471 | * @param {object} [options] Optional Parameters. |
| 472 | * |
| 473 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 474 | * request |
| 475 | * |
| 476 | * @returns {Promise} A promise is returned |
| 477 | * |
| 478 | * @resolve {HttpOperationResponse<null>} - The deserialized result object. |
| 479 | * |
| 480 | * @reject {Error} - The error object. |
| 481 | */ |
| 482 | updateDeployStatusWithHttpOperationResponse(releaseMetadata, options) { |
| 483 | let client = this.client; |
| 484 | let self = this; |
| 485 | return new Promise((resolve, reject) => { |
| 486 | self._updateDeployStatus(releaseMetadata, options, (err, result, request, response) => { |
| 487 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 488 | httpOperationResponse.body = result; |
| 489 | if (err) { reject(err); } |
| 490 | else { resolve(httpOperationResponse); } |
| 491 | return; |
| 492 | }); |
| 493 | }); |
| 494 | } |
| 495 | |
| 496 | /** |
| 497 | * Report Deployment status metric |
| 498 | * |
| 499 | * @param {object} releaseMetadata Deployment status metric properties |
| 500 | * |
| 501 | * @param {string} releaseMetadata.deploymentKey |
| 502 | * |
| 503 | * @param {string} [releaseMetadata.label] |
| 504 | * |
| 505 | * @param {string} [releaseMetadata.appVersion] |
| 506 | * |
| 507 | * @param {string} [releaseMetadata.previousDeploymentKey] |
| 508 | * |
| 509 | * @param {string} [releaseMetadata.previousLabelOrAppVersion] |
| 510 | * |
| 511 | * @param {string} [releaseMetadata.status] |
| 512 | * |
| 513 | * @param {string} [releaseMetadata.clientUniqueId] |
| 514 | * |
| 515 | * @param {object} [options] Optional Parameters. |
| 516 | * |
| 517 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 518 | * request |
| 519 | * |
| 520 | * @param {function} [optionalCallback] - The optional callback. |
| 521 | * |
| 522 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 523 | * then it returns the callback else returns a Promise. |
| 524 | * |
| 525 | * {Promise} A promise is returned |
| 526 | * |
| 527 | * @resolve {null} - The deserialized result object. |
| 528 | * |
| 529 | * @reject {Error} - The error object. |
| 530 | * |
| 531 | * {function} optionalCallback(err, result, request, response) |
| 532 | * |
| 533 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 534 | * |
| 535 | * {null} [result] - The deserialized result object if an error did not occur. |
| 536 | * |
| 537 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 538 | * |
| 539 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 540 | */ |
| 541 | updateDeployStatus(releaseMetadata, options, optionalCallback) { |
| 542 | let client = this.client; |
| 543 | let self = this; |
| 544 | if (!optionalCallback && typeof options === 'function') { |
| 545 | optionalCallback = options; |
| 546 | options = null; |
| 547 | } |
| 548 | if (!optionalCallback) { |
| 549 | return new Promise((resolve, reject) => { |
| 550 | self._updateDeployStatus(releaseMetadata, options, (err, result, request, response) => { |
| 551 | if (err) { reject(err); } |
| 552 | else { resolve(result); } |
| 553 | return; |
| 554 | }); |
| 555 | }); |
| 556 | } else { |
| 557 | return self._updateDeployStatus(releaseMetadata, options, optionalCallback); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * Report download of specified release |
| 563 | * |
| 564 | * @param {object} releaseMetadata Deployment status metric properties |
| 565 | * |
| 566 | * @param {string} releaseMetadata.deploymentKey |
| 567 | * |
| 568 | * @param {string} [releaseMetadata.label] |
| 569 | * |
| 570 | * @param {string} [releaseMetadata.appVersion] |
| 571 | * |
| 572 | * @param {string} [releaseMetadata.previousDeploymentKey] |
| 573 | * |
| 574 | * @param {string} [releaseMetadata.previousLabelOrAppVersion] |
| 575 | * |
| 576 | * @param {string} [releaseMetadata.status] |
| 577 | * |
| 578 | * @param {string} [releaseMetadata.clientUniqueId] |
| 579 | * |
| 580 | * @param {object} [options] Optional Parameters. |
| 581 | * |
| 582 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 583 | * request |
| 584 | * |
| 585 | * @returns {Promise} A promise is returned |
| 586 | * |
| 587 | * @resolve {HttpOperationResponse<null>} - The deserialized result object. |
| 588 | * |
| 589 | * @reject {Error} - The error object. |
| 590 | */ |
| 591 | updateDownloadStatusWithHttpOperationResponse(releaseMetadata, options) { |
| 592 | let client = this.client; |
| 593 | let self = this; |
| 594 | return new Promise((resolve, reject) => { |
| 595 | self._updateDownloadStatus(releaseMetadata, options, (err, result, request, response) => { |
| 596 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 597 | httpOperationResponse.body = result; |
| 598 | if (err) { reject(err); } |
| 599 | else { resolve(httpOperationResponse); } |
| 600 | return; |
| 601 | }); |
| 602 | }); |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * Report download of specified release |
| 607 | * |
| 608 | * @param {object} releaseMetadata Deployment status metric properties |
| 609 | * |
| 610 | * @param {string} releaseMetadata.deploymentKey |
| 611 | * |
| 612 | * @param {string} [releaseMetadata.label] |
| 613 | * |
| 614 | * @param {string} [releaseMetadata.appVersion] |
| 615 | * |
| 616 | * @param {string} [releaseMetadata.previousDeploymentKey] |
| 617 | * |
| 618 | * @param {string} [releaseMetadata.previousLabelOrAppVersion] |
| 619 | * |
| 620 | * @param {string} [releaseMetadata.status] |
| 621 | * |
| 622 | * @param {string} [releaseMetadata.clientUniqueId] |
| 623 | * |
| 624 | * @param {object} [options] Optional Parameters. |
| 625 | * |
| 626 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 627 | * request |
| 628 | * |
| 629 | * @param {function} [optionalCallback] - The optional callback. |
| 630 | * |
| 631 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 632 | * then it returns the callback else returns a Promise. |
| 633 | * |
| 634 | * {Promise} A promise is returned |
| 635 | * |
| 636 | * @resolve {null} - The deserialized result object. |
| 637 | * |
| 638 | * @reject {Error} - The error object. |
| 639 | * |
| 640 | * {function} optionalCallback(err, result, request, response) |
| 641 | * |
| 642 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 643 | * |
| 644 | * {null} [result] - The deserialized result object if an error did not occur. |
| 645 | * |
| 646 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 647 | * |
| 648 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 649 | */ |
| 650 | updateDownloadStatus(releaseMetadata, options, optionalCallback) { |
| 651 | let client = this.client; |
| 652 | let self = this; |
| 653 | if (!optionalCallback && typeof options === 'function') { |
| 654 | optionalCallback = options; |
| 655 | options = null; |
| 656 | } |
| 657 | if (!optionalCallback) { |
| 658 | return new Promise((resolve, reject) => { |
| 659 | self._updateDownloadStatus(releaseMetadata, options, (err, result, request, response) => { |
| 660 | if (err) { reject(err); } |
| 661 | else { resolve(result); } |
| 662 | return; |
| 663 | }); |
| 664 | }); |
| 665 | } else { |
| 666 | return self._updateDownloadStatus(releaseMetadata, options, optionalCallback); |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * Check for updates |
| 672 | * |
| 673 | * @param {string} appVersion |
| 674 | * |
| 675 | * @param {string} deploymentKey |
| 676 | * |
| 677 | * @param {object} [options] Optional Parameters. |
| 678 | * |
| 679 | * @param {string} [options.clientUniqueId] |
| 680 | * |
| 681 | * @param {boolean} [options.isCompanion] |
| 682 | * |
| 683 | * @param {string} [options.label] |
| 684 | * |
| 685 | * @param {string} [options.packageHash] |
| 686 | * |
| 687 | * @param {string} [options.previousDeploymentKey] |
| 688 | * |
| 689 | * @param {string} [options.previousLabelOrAppVersion] |
| 690 | * |
| 691 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 692 | * request |
| 693 | * |
| 694 | * @returns {Promise} A promise is returned |
| 695 | * |
| 696 | * @resolve {HttpOperationResponse<UpdateCheckResponse>} - The deserialized result object. |
| 697 | * |
| 698 | * @reject {Error} - The error object. |
| 699 | */ |
| 700 | updateCheckWithHttpOperationResponse(appVersion, deploymentKey, options) { |
| 701 | let client = this.client; |
| 702 | let self = this; |
| 703 | return new Promise((resolve, reject) => { |
| 704 | self._updateCheck(appVersion, deploymentKey, options, (err, result, request, response) => { |
| 705 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 706 | httpOperationResponse.body = result; |
| 707 | if (err) { reject(err); } |
| 708 | else { resolve(httpOperationResponse); } |
| 709 | return; |
| 710 | }); |
| 711 | }); |
| 712 | } |
| 713 | |
| 714 | /** |
| 715 | * Check for updates |
| 716 | * |
| 717 | * @param {string} appVersion |
| 718 | * |
| 719 | * @param {string} deploymentKey |
| 720 | * |
| 721 | * @param {object} [options] Optional Parameters. |
| 722 | * |
| 723 | * @param {string} [options.clientUniqueId] |
| 724 | * |
| 725 | * @param {boolean} [options.isCompanion] |
| 726 | * |
| 727 | * @param {string} [options.label] |
| 728 | * |
| 729 | * @param {string} [options.packageHash] |
| 730 | * |
| 731 | * @param {string} [options.previousDeploymentKey] |
| 732 | * |
| 733 | * @param {string} [options.previousLabelOrAppVersion] |
| 734 | * |
| 735 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 736 | * request |
| 737 | * |
| 738 | * @param {function} [optionalCallback] - The optional callback. |
| 739 | * |
| 740 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 741 | * then it returns the callback else returns a Promise. |
| 742 | * |
| 743 | * {Promise} A promise is returned |
| 744 | * |
| 745 | * @resolve {UpdateCheckResponse} - The deserialized result object. |
| 746 | * |
| 747 | * @reject {Error} - The error object. |
| 748 | * |
| 749 | * {function} optionalCallback(err, result, request, response) |
| 750 | * |
| 751 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 752 | * |
| 753 | * {object} [result] - The deserialized result object if an error did not occur. |
| 754 | * See {@link UpdateCheckResponse} for more information. |
| 755 | * |
| 756 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 757 | * |
| 758 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 759 | */ |
| 760 | updateCheck(appVersion, deploymentKey, options, optionalCallback) { |
| 761 | let client = this.client; |
| 762 | let self = this; |
| 763 | if (!optionalCallback && typeof options === 'function') { |
| 764 | optionalCallback = options; |
| 765 | options = null; |
| 766 | } |
| 767 | if (!optionalCallback) { |
| 768 | return new Promise((resolve, reject) => { |
| 769 | self._updateCheck(appVersion, deploymentKey, options, (err, result, request, response) => { |
| 770 | if (err) { reject(err); } |
| 771 | else { resolve(result); } |
| 772 | return; |
| 773 | }); |
| 774 | }); |
| 775 | } else { |
| 776 | return self._updateCheck(appVersion, deploymentKey, options, optionalCallback); |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | } |
| 781 | |
| 782 | module.exports = CodePushAcquisition; |
| 783 | |