microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
lib/app-center-node-client/src/codepush/operations/codePushDeployments.js
1534lines · 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 | * Gets a list of CodePush deployments for the given app |
| 14 | * |
| 15 | * @param {string} appName The name of the application |
| 16 | * |
| 17 | * @param {string} ownerName The name of the owner |
| 18 | * |
| 19 | * @param {object} [options] Optional Parameters. |
| 20 | * |
| 21 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 22 | * request |
| 23 | * |
| 24 | * @param {function} callback - The callback. |
| 25 | * |
| 26 | * @returns {function} callback(err, result, request, response) |
| 27 | * |
| 28 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 29 | * |
| 30 | * {array} [result] - The deserialized result object if an error did not occur. |
| 31 | * |
| 32 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 33 | * |
| 34 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 35 | */ |
| 36 | function _list(appName, ownerName, options, callback) { |
| 37 | /* jshint validthis: true */ |
| 38 | let client = this.client; |
| 39 | if(!callback && typeof options === 'function') { |
| 40 | callback = options; |
| 41 | options = null; |
| 42 | } |
| 43 | if (!callback) { |
| 44 | throw new Error('callback cannot be null.'); |
| 45 | } |
| 46 | // Validate |
| 47 | try { |
| 48 | if (appName === null || appName === undefined || typeof appName.valueOf() !== 'string') { |
| 49 | throw new Error('appName cannot be null or undefined and it must be of type string.'); |
| 50 | } |
| 51 | if (ownerName === null || ownerName === undefined || typeof ownerName.valueOf() !== 'string') { |
| 52 | throw new Error('ownerName cannot be null or undefined and it must be of type string.'); |
| 53 | } |
| 54 | } catch (error) { |
| 55 | return callback(error); |
| 56 | } |
| 57 | |
| 58 | // Construct URL |
| 59 | let baseUrl = this.client.baseUri; |
| 60 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/apps/{owner_name}/{app_name}/deployments'; |
| 61 | requestUrl = requestUrl.replace('{app_name}', encodeURIComponent(appName)); |
| 62 | requestUrl = requestUrl.replace('{owner_name}', encodeURIComponent(ownerName)); |
| 63 | |
| 64 | // Create HTTP transport objects |
| 65 | let httpRequest = new WebResource(); |
| 66 | httpRequest.method = 'GET'; |
| 67 | httpRequest.url = requestUrl; |
| 68 | httpRequest.headers = {}; |
| 69 | // Set Headers |
| 70 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 71 | if(options) { |
| 72 | for(let headerName in options['customHeaders']) { |
| 73 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 74 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | httpRequest.body = null; |
| 79 | // Send Request |
| 80 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 81 | if (err) { |
| 82 | return callback(err); |
| 83 | } |
| 84 | let statusCode = response.statusCode; |
| 85 | if (statusCode !== 200) { |
| 86 | let error = new Error(responseBody); |
| 87 | error.statusCode = response.statusCode; |
| 88 | error.request = msRest.stripRequest(httpRequest); |
| 89 | error.response = msRest.stripResponse(response); |
| 90 | if (responseBody === '') responseBody = null; |
| 91 | let parsedErrorResponse; |
| 92 | try { |
| 93 | parsedErrorResponse = JSON.parse(responseBody); |
| 94 | if (parsedErrorResponse) { |
| 95 | let internalError = null; |
| 96 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 97 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 98 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 99 | } |
| 100 | } catch (defaultError) { |
| 101 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 102 | `- "${responseBody}" for the default response.`; |
| 103 | return callback(error); |
| 104 | } |
| 105 | return callback(error); |
| 106 | } |
| 107 | // Create Result |
| 108 | let result = null; |
| 109 | if (responseBody === '') responseBody = null; |
| 110 | // Deserialize Response |
| 111 | if (statusCode === 200) { |
| 112 | let parsedResponse = null; |
| 113 | try { |
| 114 | parsedResponse = JSON.parse(responseBody); |
| 115 | result = JSON.parse(responseBody); |
| 116 | if (parsedResponse !== null && parsedResponse !== undefined) { |
| 117 | let resultMapper = { |
| 118 | required: false, |
| 119 | serializedName: 'parsedResponse', |
| 120 | type: { |
| 121 | name: 'Sequence', |
| 122 | element: { |
| 123 | required: false, |
| 124 | serializedName: 'DeploymentElementType', |
| 125 | type: { |
| 126 | name: 'Composite', |
| 127 | className: 'Deployment' |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | }; |
| 132 | result = client.deserialize(resultMapper, parsedResponse, 'result'); |
| 133 | } |
| 134 | } catch (error) { |
| 135 | let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); |
| 136 | deserializationError.request = msRest.stripRequest(httpRequest); |
| 137 | deserializationError.response = msRest.stripResponse(response); |
| 138 | return callback(deserializationError); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | return callback(null, result, httpRequest, response); |
| 143 | }); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Creates a CodePush Deployment for the given app |
| 148 | * |
| 149 | * @param {string} appName The name of the application |
| 150 | * |
| 151 | * @param {object} deployment Deployment to be created |
| 152 | * |
| 153 | * @param {string} [deployment.key] |
| 154 | * |
| 155 | * @param {string} deployment.name |
| 156 | * |
| 157 | * @param {object} [deployment.latestRelease] |
| 158 | * |
| 159 | * @param {string} [deployment.latestRelease.label] |
| 160 | * |
| 161 | * @param {string} [deployment.latestRelease.packageHash] |
| 162 | * |
| 163 | * @param {string} [deployment.latestRelease.blobUrl] |
| 164 | * |
| 165 | * @param {object} [deployment.latestRelease.diffPackageMap] |
| 166 | * |
| 167 | * @param {string} [deployment.latestRelease.originalDeployment] Set on |
| 168 | * 'Promote' |
| 169 | * |
| 170 | * @param {string} [deployment.latestRelease.originalLabel] Set on 'Promote' |
| 171 | * and 'Rollback' |
| 172 | * |
| 173 | * @param {string} [deployment.latestRelease.releasedBy] |
| 174 | * |
| 175 | * @param {string} [deployment.latestRelease.releaseMethod] The release method |
| 176 | * is unknown if unspecified. Possible values include: 'Upload', 'Promote', |
| 177 | * 'Rollback' |
| 178 | * |
| 179 | * @param {number} [deployment.latestRelease.size] |
| 180 | * |
| 181 | * @param {number} [deployment.latestRelease.uploadTime] |
| 182 | * |
| 183 | * @param {string} [deployment.latestRelease.targetBinaryRange] |
| 184 | * |
| 185 | * @param {string} [deployment.latestRelease.description] |
| 186 | * |
| 187 | * @param {boolean} [deployment.latestRelease.isDisabled] |
| 188 | * |
| 189 | * @param {boolean} [deployment.latestRelease.isMandatory] |
| 190 | * |
| 191 | * @param {number} [deployment.latestRelease.rollout] |
| 192 | * |
| 193 | * @param {string} ownerName The name of the owner |
| 194 | * |
| 195 | * @param {object} [options] Optional Parameters. |
| 196 | * |
| 197 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 198 | * request |
| 199 | * |
| 200 | * @param {function} callback - The callback. |
| 201 | * |
| 202 | * @returns {function} callback(err, result, request, response) |
| 203 | * |
| 204 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 205 | * |
| 206 | * {object} [result] - The deserialized result object if an error did not occur. |
| 207 | * See {@link Deployment} for more information. |
| 208 | * |
| 209 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 210 | * |
| 211 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 212 | */ |
| 213 | function _create(appName, deployment, ownerName, options, callback) { |
| 214 | /* jshint validthis: true */ |
| 215 | let client = this.client; |
| 216 | if(!callback && typeof options === 'function') { |
| 217 | callback = options; |
| 218 | options = null; |
| 219 | } |
| 220 | if (!callback) { |
| 221 | throw new Error('callback cannot be null.'); |
| 222 | } |
| 223 | // Validate |
| 224 | try { |
| 225 | if (appName === null || appName === undefined || typeof appName.valueOf() !== 'string') { |
| 226 | throw new Error('appName cannot be null or undefined and it must be of type string.'); |
| 227 | } |
| 228 | if (deployment === null || deployment === undefined) { |
| 229 | throw new Error('deployment cannot be null or undefined.'); |
| 230 | } |
| 231 | if (ownerName === null || ownerName === undefined || typeof ownerName.valueOf() !== 'string') { |
| 232 | throw new Error('ownerName cannot be null or undefined and it must be of type string.'); |
| 233 | } |
| 234 | } catch (error) { |
| 235 | return callback(error); |
| 236 | } |
| 237 | |
| 238 | // Construct URL |
| 239 | let baseUrl = this.client.baseUri; |
| 240 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/apps/{owner_name}/{app_name}/deployments'; |
| 241 | requestUrl = requestUrl.replace('{app_name}', encodeURIComponent(appName)); |
| 242 | requestUrl = requestUrl.replace('{owner_name}', encodeURIComponent(ownerName)); |
| 243 | |
| 244 | // Create HTTP transport objects |
| 245 | let httpRequest = new WebResource(); |
| 246 | httpRequest.method = 'POST'; |
| 247 | httpRequest.url = requestUrl; |
| 248 | httpRequest.headers = {}; |
| 249 | // Set Headers |
| 250 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 251 | if(options) { |
| 252 | for(let headerName in options['customHeaders']) { |
| 253 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 254 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | // Serialize Request |
| 259 | let requestContent = null; |
| 260 | let requestModel = null; |
| 261 | try { |
| 262 | if (deployment !== null && deployment !== undefined) { |
| 263 | let requestModelMapper = new client.models['Deployment']().mapper(); |
| 264 | requestModel = client.serialize(requestModelMapper, deployment, 'deployment'); |
| 265 | requestContent = JSON.stringify(requestModel); |
| 266 | } |
| 267 | } catch (error) { |
| 268 | let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + |
| 269 | `payload - ${JSON.stringify(deployment, null, 2)}.`); |
| 270 | return callback(serializationError); |
| 271 | } |
| 272 | httpRequest.body = requestContent; |
| 273 | // Send Request |
| 274 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 275 | if (err) { |
| 276 | return callback(err); |
| 277 | } |
| 278 | let statusCode = response.statusCode; |
| 279 | if (statusCode !== 201) { |
| 280 | let error = new Error(responseBody); |
| 281 | error.statusCode = response.statusCode; |
| 282 | error.request = msRest.stripRequest(httpRequest); |
| 283 | error.response = msRest.stripResponse(response); |
| 284 | if (responseBody === '') responseBody = null; |
| 285 | let parsedErrorResponse; |
| 286 | try { |
| 287 | parsedErrorResponse = JSON.parse(responseBody); |
| 288 | if (parsedErrorResponse) { |
| 289 | let internalError = null; |
| 290 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 291 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 292 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 293 | } |
| 294 | } catch (defaultError) { |
| 295 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 296 | `- "${responseBody}" for the default response.`; |
| 297 | return callback(error); |
| 298 | } |
| 299 | return callback(error); |
| 300 | } |
| 301 | // Create Result |
| 302 | let result = null; |
| 303 | if (responseBody === '') responseBody = null; |
| 304 | // Deserialize Response |
| 305 | if (statusCode === 201) { |
| 306 | let parsedResponse = null; |
| 307 | try { |
| 308 | parsedResponse = JSON.parse(responseBody); |
| 309 | result = JSON.parse(responseBody); |
| 310 | if (parsedResponse !== null && parsedResponse !== undefined) { |
| 311 | let resultMapper = new client.models['Deployment']().mapper(); |
| 312 | result = client.deserialize(resultMapper, parsedResponse, 'result'); |
| 313 | } |
| 314 | } catch (error) { |
| 315 | let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); |
| 316 | deserializationError.request = msRest.stripRequest(httpRequest); |
| 317 | deserializationError.response = msRest.stripResponse(response); |
| 318 | return callback(deserializationError); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | return callback(null, result, httpRequest, response); |
| 323 | }); |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Deletes a CodePush Deployment for the given app |
| 328 | * |
| 329 | * @param {string} appName The name of the application |
| 330 | * |
| 331 | * @param {string} deploymentName deployment name |
| 332 | * |
| 333 | * @param {string} ownerName The name of the owner |
| 334 | * |
| 335 | * @param {object} [options] Optional Parameters. |
| 336 | * |
| 337 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 338 | * request |
| 339 | * |
| 340 | * @param {function} callback - The callback. |
| 341 | * |
| 342 | * @returns {function} callback(err, result, request, response) |
| 343 | * |
| 344 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 345 | * |
| 346 | * {null} [result] - The deserialized result object if an error did not occur. |
| 347 | * |
| 348 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 349 | * |
| 350 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 351 | */ |
| 352 | function _deleteMethod(appName, deploymentName, ownerName, options, callback) { |
| 353 | /* jshint validthis: true */ |
| 354 | let client = this.client; |
| 355 | if(!callback && typeof options === 'function') { |
| 356 | callback = options; |
| 357 | options = null; |
| 358 | } |
| 359 | if (!callback) { |
| 360 | throw new Error('callback cannot be null.'); |
| 361 | } |
| 362 | // Validate |
| 363 | try { |
| 364 | if (appName === null || appName === undefined || typeof appName.valueOf() !== 'string') { |
| 365 | throw new Error('appName cannot be null or undefined and it must be of type string.'); |
| 366 | } |
| 367 | if (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') { |
| 368 | throw new Error('deploymentName cannot be null or undefined and it must be of type string.'); |
| 369 | } |
| 370 | if (ownerName === null || ownerName === undefined || typeof ownerName.valueOf() !== 'string') { |
| 371 | throw new Error('ownerName cannot be null or undefined and it must be of type string.'); |
| 372 | } |
| 373 | } catch (error) { |
| 374 | return callback(error); |
| 375 | } |
| 376 | |
| 377 | // Construct URL |
| 378 | let baseUrl = this.client.baseUri; |
| 379 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/apps/{owner_name}/{app_name}/deployments/{deployment_name}'; |
| 380 | requestUrl = requestUrl.replace('{app_name}', encodeURIComponent(appName)); |
| 381 | requestUrl = requestUrl.replace('{deployment_name}', encodeURIComponent(deploymentName)); |
| 382 | requestUrl = requestUrl.replace('{owner_name}', encodeURIComponent(ownerName)); |
| 383 | |
| 384 | // Create HTTP transport objects |
| 385 | let httpRequest = new WebResource(); |
| 386 | httpRequest.method = 'DELETE'; |
| 387 | httpRequest.url = requestUrl; |
| 388 | httpRequest.headers = {}; |
| 389 | // Set Headers |
| 390 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 391 | if(options) { |
| 392 | for(let headerName in options['customHeaders']) { |
| 393 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 394 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | httpRequest.body = null; |
| 399 | // Send Request |
| 400 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 401 | if (err) { |
| 402 | return callback(err); |
| 403 | } |
| 404 | let statusCode = response.statusCode; |
| 405 | if (statusCode < 200 || statusCode >= 300) { |
| 406 | let error = new Error(responseBody); |
| 407 | error.statusCode = response.statusCode; |
| 408 | error.request = msRest.stripRequest(httpRequest); |
| 409 | error.response = msRest.stripResponse(response); |
| 410 | if (responseBody === '') responseBody = null; |
| 411 | let parsedErrorResponse; |
| 412 | try { |
| 413 | parsedErrorResponse = JSON.parse(responseBody); |
| 414 | if (parsedErrorResponse) { |
| 415 | let internalError = null; |
| 416 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 417 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 418 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 419 | } |
| 420 | } catch (defaultError) { |
| 421 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 422 | `- "${responseBody}" for the default response.`; |
| 423 | return callback(error); |
| 424 | } |
| 425 | return callback(error); |
| 426 | } |
| 427 | // Create Result |
| 428 | let result = null; |
| 429 | if (responseBody === '') responseBody = null; |
| 430 | |
| 431 | return callback(null, result, httpRequest, response); |
| 432 | }); |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * Gets a CodePush Deployment for the given app |
| 437 | * |
| 438 | * @param {string} appName The name of the application |
| 439 | * |
| 440 | * @param {string} deploymentName deployment name |
| 441 | * |
| 442 | * @param {string} ownerName The name of the owner |
| 443 | * |
| 444 | * @param {object} [options] Optional Parameters. |
| 445 | * |
| 446 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 447 | * request |
| 448 | * |
| 449 | * @param {function} callback - The callback. |
| 450 | * |
| 451 | * @returns {function} callback(err, result, request, response) |
| 452 | * |
| 453 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 454 | * |
| 455 | * {object} [result] - The deserialized result object if an error did not occur. |
| 456 | * See {@link Deployment} for more information. |
| 457 | * |
| 458 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 459 | * |
| 460 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 461 | */ |
| 462 | function _get(appName, deploymentName, ownerName, options, callback) { |
| 463 | /* jshint validthis: true */ |
| 464 | let client = this.client; |
| 465 | if(!callback && typeof options === 'function') { |
| 466 | callback = options; |
| 467 | options = null; |
| 468 | } |
| 469 | if (!callback) { |
| 470 | throw new Error('callback cannot be null.'); |
| 471 | } |
| 472 | // Validate |
| 473 | try { |
| 474 | if (appName === null || appName === undefined || typeof appName.valueOf() !== 'string') { |
| 475 | throw new Error('appName cannot be null or undefined and it must be of type string.'); |
| 476 | } |
| 477 | if (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') { |
| 478 | throw new Error('deploymentName cannot be null or undefined and it must be of type string.'); |
| 479 | } |
| 480 | if (ownerName === null || ownerName === undefined || typeof ownerName.valueOf() !== 'string') { |
| 481 | throw new Error('ownerName cannot be null or undefined and it must be of type string.'); |
| 482 | } |
| 483 | } catch (error) { |
| 484 | return callback(error); |
| 485 | } |
| 486 | |
| 487 | // Construct URL |
| 488 | let baseUrl = this.client.baseUri; |
| 489 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/apps/{owner_name}/{app_name}/deployments/{deployment_name}'; |
| 490 | requestUrl = requestUrl.replace('{app_name}', encodeURIComponent(appName)); |
| 491 | requestUrl = requestUrl.replace('{deployment_name}', encodeURIComponent(deploymentName)); |
| 492 | requestUrl = requestUrl.replace('{owner_name}', encodeURIComponent(ownerName)); |
| 493 | |
| 494 | // Create HTTP transport objects |
| 495 | let httpRequest = new WebResource(); |
| 496 | httpRequest.method = 'GET'; |
| 497 | httpRequest.url = requestUrl; |
| 498 | httpRequest.headers = {}; |
| 499 | // Set Headers |
| 500 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 501 | if(options) { |
| 502 | for(let headerName in options['customHeaders']) { |
| 503 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 504 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | httpRequest.body = null; |
| 509 | // Send Request |
| 510 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 511 | if (err) { |
| 512 | return callback(err); |
| 513 | } |
| 514 | let statusCode = response.statusCode; |
| 515 | if (statusCode !== 200) { |
| 516 | let error = new Error(responseBody); |
| 517 | error.statusCode = response.statusCode; |
| 518 | error.request = msRest.stripRequest(httpRequest); |
| 519 | error.response = msRest.stripResponse(response); |
| 520 | if (responseBody === '') responseBody = null; |
| 521 | let parsedErrorResponse; |
| 522 | try { |
| 523 | parsedErrorResponse = JSON.parse(responseBody); |
| 524 | if (parsedErrorResponse) { |
| 525 | let internalError = null; |
| 526 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 527 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 528 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 529 | } |
| 530 | } catch (defaultError) { |
| 531 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 532 | `- "${responseBody}" for the default response.`; |
| 533 | return callback(error); |
| 534 | } |
| 535 | return callback(error); |
| 536 | } |
| 537 | // Create Result |
| 538 | let result = null; |
| 539 | if (responseBody === '') responseBody = null; |
| 540 | // Deserialize Response |
| 541 | if (statusCode === 200) { |
| 542 | let parsedResponse = null; |
| 543 | try { |
| 544 | parsedResponse = JSON.parse(responseBody); |
| 545 | result = JSON.parse(responseBody); |
| 546 | if (parsedResponse !== null && parsedResponse !== undefined) { |
| 547 | let resultMapper = new client.models['Deployment']().mapper(); |
| 548 | result = client.deserialize(resultMapper, parsedResponse, 'result'); |
| 549 | } |
| 550 | } catch (error) { |
| 551 | let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); |
| 552 | deserializationError.request = msRest.stripRequest(httpRequest); |
| 553 | deserializationError.response = msRest.stripResponse(response); |
| 554 | return callback(deserializationError); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | return callback(null, result, httpRequest, response); |
| 559 | }); |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * Modifies a CodePush Deployment for the given app |
| 564 | * |
| 565 | * @param {string} appName The name of the application |
| 566 | * |
| 567 | * @param {object} deployment Deployment modification. All fields are optional |
| 568 | * and only provided fields will get updated. |
| 569 | * |
| 570 | * @param {string} deployment.name |
| 571 | * |
| 572 | * @param {string} deploymentName deployment name |
| 573 | * |
| 574 | * @param {string} ownerName The name of the owner |
| 575 | * |
| 576 | * @param {object} [options] Optional Parameters. |
| 577 | * |
| 578 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 579 | * request |
| 580 | * |
| 581 | * @param {function} callback - The callback. |
| 582 | * |
| 583 | * @returns {function} callback(err, result, request, response) |
| 584 | * |
| 585 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 586 | * |
| 587 | * {null} [result] - The deserialized result object if an error did not occur. |
| 588 | * |
| 589 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 590 | * |
| 591 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 592 | */ |
| 593 | function _update(appName, deployment, deploymentName, ownerName, options, callback) { |
| 594 | /* jshint validthis: true */ |
| 595 | let client = this.client; |
| 596 | if(!callback && typeof options === 'function') { |
| 597 | callback = options; |
| 598 | options = null; |
| 599 | } |
| 600 | if (!callback) { |
| 601 | throw new Error('callback cannot be null.'); |
| 602 | } |
| 603 | // Validate |
| 604 | try { |
| 605 | if (appName === null || appName === undefined || typeof appName.valueOf() !== 'string') { |
| 606 | throw new Error('appName cannot be null or undefined and it must be of type string.'); |
| 607 | } |
| 608 | if (deployment === null || deployment === undefined) { |
| 609 | throw new Error('deployment cannot be null or undefined.'); |
| 610 | } |
| 611 | if (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') { |
| 612 | throw new Error('deploymentName cannot be null or undefined and it must be of type string.'); |
| 613 | } |
| 614 | if (ownerName === null || ownerName === undefined || typeof ownerName.valueOf() !== 'string') { |
| 615 | throw new Error('ownerName cannot be null or undefined and it must be of type string.'); |
| 616 | } |
| 617 | } catch (error) { |
| 618 | return callback(error); |
| 619 | } |
| 620 | |
| 621 | // Construct URL |
| 622 | let baseUrl = this.client.baseUri; |
| 623 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/apps/{owner_name}/{app_name}/deployments/{deployment_name}'; |
| 624 | requestUrl = requestUrl.replace('{app_name}', encodeURIComponent(appName)); |
| 625 | requestUrl = requestUrl.replace('{deployment_name}', encodeURIComponent(deploymentName)); |
| 626 | requestUrl = requestUrl.replace('{owner_name}', encodeURIComponent(ownerName)); |
| 627 | |
| 628 | // Create HTTP transport objects |
| 629 | let httpRequest = new WebResource(); |
| 630 | httpRequest.method = 'PATCH'; |
| 631 | httpRequest.url = requestUrl; |
| 632 | httpRequest.headers = {}; |
| 633 | // Set Headers |
| 634 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 635 | if(options) { |
| 636 | for(let headerName in options['customHeaders']) { |
| 637 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 638 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 639 | } |
| 640 | } |
| 641 | } |
| 642 | // Serialize Request |
| 643 | let requestContent = null; |
| 644 | let requestModel = null; |
| 645 | try { |
| 646 | if (deployment !== null && deployment !== undefined) { |
| 647 | let requestModelMapper = new client.models['DeploymentModification']().mapper(); |
| 648 | requestModel = client.serialize(requestModelMapper, deployment, 'deployment'); |
| 649 | requestContent = JSON.stringify(requestModel); |
| 650 | } |
| 651 | } catch (error) { |
| 652 | let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + |
| 653 | `payload - ${JSON.stringify(deployment, null, 2)}.`); |
| 654 | return callback(serializationError); |
| 655 | } |
| 656 | httpRequest.body = requestContent; |
| 657 | // Send Request |
| 658 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 659 | if (err) { |
| 660 | return callback(err); |
| 661 | } |
| 662 | let statusCode = response.statusCode; |
| 663 | if (statusCode < 200 || statusCode >= 300) { |
| 664 | let error = new Error(responseBody); |
| 665 | error.statusCode = response.statusCode; |
| 666 | error.request = msRest.stripRequest(httpRequest); |
| 667 | error.response = msRest.stripResponse(response); |
| 668 | if (responseBody === '') responseBody = null; |
| 669 | let parsedErrorResponse; |
| 670 | try { |
| 671 | parsedErrorResponse = JSON.parse(responseBody); |
| 672 | if (parsedErrorResponse) { |
| 673 | let internalError = null; |
| 674 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 675 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 676 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 677 | } |
| 678 | } catch (defaultError) { |
| 679 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 680 | `- "${responseBody}" for the default response.`; |
| 681 | return callback(error); |
| 682 | } |
| 683 | return callback(error); |
| 684 | } |
| 685 | // Create Result |
| 686 | let result = null; |
| 687 | if (responseBody === '') responseBody = null; |
| 688 | |
| 689 | return callback(null, result, httpRequest, response); |
| 690 | }); |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * Promote one release (default latest one) from one deployment to another |
| 695 | * |
| 696 | * @param {string} appName The name of the application |
| 697 | * |
| 698 | * @param {string} deploymentName deployment name |
| 699 | * |
| 700 | * @param {string} ownerName The name of the owner |
| 701 | * |
| 702 | * @param {string} promoteDeploymentName deployment name |
| 703 | * |
| 704 | * @param {object} [options] Optional Parameters. |
| 705 | * |
| 706 | * @param {object} [options.release] Release to be promoted, only needs to |
| 707 | * provide optional fields, description, label, disabled, mandatory, rollout, |
| 708 | * targetBinaryVersion |
| 709 | * |
| 710 | * @param {string} [options.release.label] |
| 711 | * |
| 712 | * @param {string} [options.release.targetBinaryRange] |
| 713 | * |
| 714 | * @param {string} [options.release.description] |
| 715 | * |
| 716 | * @param {boolean} [options.release.isDisabled] |
| 717 | * |
| 718 | * @param {boolean} [options.release.isMandatory] |
| 719 | * |
| 720 | * @param {number} [options.release.rollout] |
| 721 | * |
| 722 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 723 | * request |
| 724 | * |
| 725 | * @param {function} callback - The callback. |
| 726 | * |
| 727 | * @returns {function} callback(err, result, request, response) |
| 728 | * |
| 729 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 730 | * |
| 731 | * {object} [result] - The deserialized result object if an error did not occur. |
| 732 | * See {@link CodePushRelease} for more information. |
| 733 | * |
| 734 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 735 | * |
| 736 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 737 | */ |
| 738 | function _promote(appName, deploymentName, ownerName, promoteDeploymentName, options, callback) { |
| 739 | /* jshint validthis: true */ |
| 740 | let client = this.client; |
| 741 | if(!callback && typeof options === 'function') { |
| 742 | callback = options; |
| 743 | options = null; |
| 744 | } |
| 745 | if (!callback) { |
| 746 | throw new Error('callback cannot be null.'); |
| 747 | } |
| 748 | let release = (options && options.release !== undefined) ? options.release : undefined; |
| 749 | // Validate |
| 750 | try { |
| 751 | if (appName === null || appName === undefined || typeof appName.valueOf() !== 'string') { |
| 752 | throw new Error('appName cannot be null or undefined and it must be of type string.'); |
| 753 | } |
| 754 | if (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') { |
| 755 | throw new Error('deploymentName cannot be null or undefined and it must be of type string.'); |
| 756 | } |
| 757 | if (ownerName === null || ownerName === undefined || typeof ownerName.valueOf() !== 'string') { |
| 758 | throw new Error('ownerName cannot be null or undefined and it must be of type string.'); |
| 759 | } |
| 760 | if (promoteDeploymentName === null || promoteDeploymentName === undefined || typeof promoteDeploymentName.valueOf() !== 'string') { |
| 761 | throw new Error('promoteDeploymentName cannot be null or undefined and it must be of type string.'); |
| 762 | } |
| 763 | } catch (error) { |
| 764 | return callback(error); |
| 765 | } |
| 766 | |
| 767 | // Construct URL |
| 768 | let baseUrl = this.client.baseUri; |
| 769 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/apps/{owner_name}/{app_name}/deployments/{deployment_name}/promote_release/{promote_deployment_name}'; |
| 770 | requestUrl = requestUrl.replace('{app_name}', encodeURIComponent(appName)); |
| 771 | requestUrl = requestUrl.replace('{deployment_name}', encodeURIComponent(deploymentName)); |
| 772 | requestUrl = requestUrl.replace('{owner_name}', encodeURIComponent(ownerName)); |
| 773 | requestUrl = requestUrl.replace('{promote_deployment_name}', encodeURIComponent(promoteDeploymentName)); |
| 774 | |
| 775 | // Create HTTP transport objects |
| 776 | let httpRequest = new WebResource(); |
| 777 | httpRequest.method = 'POST'; |
| 778 | httpRequest.url = requestUrl; |
| 779 | httpRequest.headers = {}; |
| 780 | // Set Headers |
| 781 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 782 | if(options) { |
| 783 | for(let headerName in options['customHeaders']) { |
| 784 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 785 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 786 | } |
| 787 | } |
| 788 | } |
| 789 | // Serialize Request |
| 790 | let requestContent = null; |
| 791 | let requestModel = null; |
| 792 | try { |
| 793 | if (release !== null && release !== undefined) { |
| 794 | let requestModelMapper = new client.models['CodePushReleasePromote']().mapper(); |
| 795 | requestModel = client.serialize(requestModelMapper, release, 'release'); |
| 796 | requestContent = JSON.stringify(requestModel); |
| 797 | } |
| 798 | } catch (error) { |
| 799 | let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + |
| 800 | `payload - ${JSON.stringify(release, null, 2)}.`); |
| 801 | return callback(serializationError); |
| 802 | } |
| 803 | httpRequest.body = requestContent; |
| 804 | // Send Request |
| 805 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 806 | if (err) { |
| 807 | return callback(err); |
| 808 | } |
| 809 | let statusCode = response.statusCode; |
| 810 | if (statusCode !== 200) { |
| 811 | let error = new Error(responseBody); |
| 812 | error.statusCode = response.statusCode; |
| 813 | error.request = msRest.stripRequest(httpRequest); |
| 814 | error.response = msRest.stripResponse(response); |
| 815 | if (responseBody === '') responseBody = null; |
| 816 | let parsedErrorResponse; |
| 817 | try { |
| 818 | parsedErrorResponse = JSON.parse(responseBody); |
| 819 | if (parsedErrorResponse) { |
| 820 | let internalError = null; |
| 821 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 822 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 823 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 824 | } |
| 825 | } catch (defaultError) { |
| 826 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 827 | `- "${responseBody}" for the default response.`; |
| 828 | return callback(error); |
| 829 | } |
| 830 | return callback(error); |
| 831 | } |
| 832 | // Create Result |
| 833 | let result = null; |
| 834 | if (responseBody === '') responseBody = null; |
| 835 | // Deserialize Response |
| 836 | if (statusCode === 200) { |
| 837 | let parsedResponse = null; |
| 838 | try { |
| 839 | parsedResponse = JSON.parse(responseBody); |
| 840 | result = JSON.parse(responseBody); |
| 841 | if (parsedResponse !== null && parsedResponse !== undefined) { |
| 842 | let resultMapper = new client.models['CodePushRelease']().mapper(); |
| 843 | result = client.deserialize(resultMapper, parsedResponse, 'result'); |
| 844 | } |
| 845 | } catch (error) { |
| 846 | let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); |
| 847 | deserializationError.request = msRest.stripRequest(httpRequest); |
| 848 | deserializationError.response = msRest.stripResponse(response); |
| 849 | return callback(deserializationError); |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | return callback(null, result, httpRequest, response); |
| 854 | }); |
| 855 | } |
| 856 | |
| 857 | /** Class representing a CodePushDeployments. */ |
| 858 | class CodePushDeployments { |
| 859 | /** |
| 860 | * Create a CodePushDeployments. |
| 861 | * @param {CodepushClient} client Reference to the service client. |
| 862 | */ |
| 863 | constructor(client) { |
| 864 | this.client = client; |
| 865 | this._list = _list; |
| 866 | this._create = _create; |
| 867 | this._deleteMethod = _deleteMethod; |
| 868 | this._get = _get; |
| 869 | this._update = _update; |
| 870 | this._promote = _promote; |
| 871 | } |
| 872 | |
| 873 | /** |
| 874 | * Gets a list of CodePush deployments for the given app |
| 875 | * |
| 876 | * @param {string} appName The name of the application |
| 877 | * |
| 878 | * @param {string} ownerName The name of the owner |
| 879 | * |
| 880 | * @param {object} [options] Optional Parameters. |
| 881 | * |
| 882 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 883 | * request |
| 884 | * |
| 885 | * @returns {Promise} A promise is returned |
| 886 | * |
| 887 | * @resolve {HttpOperationResponse<Array>} - The deserialized result object. |
| 888 | * |
| 889 | * @reject {Error} - The error object. |
| 890 | */ |
| 891 | listWithHttpOperationResponse(appName, ownerName, options) { |
| 892 | let client = this.client; |
| 893 | let self = this; |
| 894 | return new Promise((resolve, reject) => { |
| 895 | self._list(appName, ownerName, options, (err, result, request, response) => { |
| 896 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 897 | httpOperationResponse.body = result; |
| 898 | if (err) { reject(err); } |
| 899 | else { resolve(httpOperationResponse); } |
| 900 | return; |
| 901 | }); |
| 902 | }); |
| 903 | } |
| 904 | |
| 905 | /** |
| 906 | * Gets a list of CodePush deployments for the given app |
| 907 | * |
| 908 | * @param {string} appName The name of the application |
| 909 | * |
| 910 | * @param {string} ownerName The name of the owner |
| 911 | * |
| 912 | * @param {object} [options] Optional Parameters. |
| 913 | * |
| 914 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 915 | * request |
| 916 | * |
| 917 | * @param {function} [optionalCallback] - The optional callback. |
| 918 | * |
| 919 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 920 | * then it returns the callback else returns a Promise. |
| 921 | * |
| 922 | * {Promise} A promise is returned |
| 923 | * |
| 924 | * @resolve {Array} - The deserialized result object. |
| 925 | * |
| 926 | * @reject {Error} - The error object. |
| 927 | * |
| 928 | * {function} optionalCallback(err, result, request, response) |
| 929 | * |
| 930 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 931 | * |
| 932 | * {array} [result] - The deserialized result object if an error did not occur. |
| 933 | * |
| 934 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 935 | * |
| 936 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 937 | */ |
| 938 | list(appName, ownerName, options, optionalCallback) { |
| 939 | let client = this.client; |
| 940 | let self = this; |
| 941 | if (!optionalCallback && typeof options === 'function') { |
| 942 | optionalCallback = options; |
| 943 | options = null; |
| 944 | } |
| 945 | if (!optionalCallback) { |
| 946 | return new Promise((resolve, reject) => { |
| 947 | self._list(appName, ownerName, options, (err, result, request, response) => { |
| 948 | if (err) { reject(err); } |
| 949 | else { resolve(result); } |
| 950 | return; |
| 951 | }); |
| 952 | }); |
| 953 | } else { |
| 954 | return self._list(appName, ownerName, options, optionalCallback); |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | /** |
| 959 | * Creates a CodePush Deployment for the given app |
| 960 | * |
| 961 | * @param {string} appName The name of the application |
| 962 | * |
| 963 | * @param {object} deployment Deployment to be created |
| 964 | * |
| 965 | * @param {string} [deployment.key] |
| 966 | * |
| 967 | * @param {string} deployment.name |
| 968 | * |
| 969 | * @param {object} [deployment.latestRelease] |
| 970 | * |
| 971 | * @param {string} [deployment.latestRelease.label] |
| 972 | * |
| 973 | * @param {string} [deployment.latestRelease.packageHash] |
| 974 | * |
| 975 | * @param {string} [deployment.latestRelease.blobUrl] |
| 976 | * |
| 977 | * @param {object} [deployment.latestRelease.diffPackageMap] |
| 978 | * |
| 979 | * @param {string} [deployment.latestRelease.originalDeployment] Set on |
| 980 | * 'Promote' |
| 981 | * |
| 982 | * @param {string} [deployment.latestRelease.originalLabel] Set on 'Promote' |
| 983 | * and 'Rollback' |
| 984 | * |
| 985 | * @param {string} [deployment.latestRelease.releasedBy] |
| 986 | * |
| 987 | * @param {string} [deployment.latestRelease.releaseMethod] The release method |
| 988 | * is unknown if unspecified. Possible values include: 'Upload', 'Promote', |
| 989 | * 'Rollback' |
| 990 | * |
| 991 | * @param {number} [deployment.latestRelease.size] |
| 992 | * |
| 993 | * @param {number} [deployment.latestRelease.uploadTime] |
| 994 | * |
| 995 | * @param {string} [deployment.latestRelease.targetBinaryRange] |
| 996 | * |
| 997 | * @param {string} [deployment.latestRelease.description] |
| 998 | * |
| 999 | * @param {boolean} [deployment.latestRelease.isDisabled] |
| 1000 | * |
| 1001 | * @param {boolean} [deployment.latestRelease.isMandatory] |
| 1002 | * |
| 1003 | * @param {number} [deployment.latestRelease.rollout] |
| 1004 | * |
| 1005 | * @param {string} ownerName The name of the owner |
| 1006 | * |
| 1007 | * @param {object} [options] Optional Parameters. |
| 1008 | * |
| 1009 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1010 | * request |
| 1011 | * |
| 1012 | * @returns {Promise} A promise is returned |
| 1013 | * |
| 1014 | * @resolve {HttpOperationResponse<Deployment>} - The deserialized result object. |
| 1015 | * |
| 1016 | * @reject {Error} - The error object. |
| 1017 | */ |
| 1018 | createWithHttpOperationResponse(appName, deployment, ownerName, options) { |
| 1019 | let client = this.client; |
| 1020 | let self = this; |
| 1021 | return new Promise((resolve, reject) => { |
| 1022 | self._create(appName, deployment, ownerName, options, (err, result, request, response) => { |
| 1023 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 1024 | httpOperationResponse.body = result; |
| 1025 | if (err) { reject(err); } |
| 1026 | else { resolve(httpOperationResponse); } |
| 1027 | return; |
| 1028 | }); |
| 1029 | }); |
| 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * Creates a CodePush Deployment for the given app |
| 1034 | * |
| 1035 | * @param {string} appName The name of the application |
| 1036 | * |
| 1037 | * @param {object} deployment Deployment to be created |
| 1038 | * |
| 1039 | * @param {string} [deployment.key] |
| 1040 | * |
| 1041 | * @param {string} deployment.name |
| 1042 | * |
| 1043 | * @param {object} [deployment.latestRelease] |
| 1044 | * |
| 1045 | * @param {string} [deployment.latestRelease.label] |
| 1046 | * |
| 1047 | * @param {string} [deployment.latestRelease.packageHash] |
| 1048 | * |
| 1049 | * @param {string} [deployment.latestRelease.blobUrl] |
| 1050 | * |
| 1051 | * @param {object} [deployment.latestRelease.diffPackageMap] |
| 1052 | * |
| 1053 | * @param {string} [deployment.latestRelease.originalDeployment] Set on |
| 1054 | * 'Promote' |
| 1055 | * |
| 1056 | * @param {string} [deployment.latestRelease.originalLabel] Set on 'Promote' |
| 1057 | * and 'Rollback' |
| 1058 | * |
| 1059 | * @param {string} [deployment.latestRelease.releasedBy] |
| 1060 | * |
| 1061 | * @param {string} [deployment.latestRelease.releaseMethod] The release method |
| 1062 | * is unknown if unspecified. Possible values include: 'Upload', 'Promote', |
| 1063 | * 'Rollback' |
| 1064 | * |
| 1065 | * @param {number} [deployment.latestRelease.size] |
| 1066 | * |
| 1067 | * @param {number} [deployment.latestRelease.uploadTime] |
| 1068 | * |
| 1069 | * @param {string} [deployment.latestRelease.targetBinaryRange] |
| 1070 | * |
| 1071 | * @param {string} [deployment.latestRelease.description] |
| 1072 | * |
| 1073 | * @param {boolean} [deployment.latestRelease.isDisabled] |
| 1074 | * |
| 1075 | * @param {boolean} [deployment.latestRelease.isMandatory] |
| 1076 | * |
| 1077 | * @param {number} [deployment.latestRelease.rollout] |
| 1078 | * |
| 1079 | * @param {string} ownerName The name of the owner |
| 1080 | * |
| 1081 | * @param {object} [options] Optional Parameters. |
| 1082 | * |
| 1083 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1084 | * request |
| 1085 | * |
| 1086 | * @param {function} [optionalCallback] - The optional callback. |
| 1087 | * |
| 1088 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 1089 | * then it returns the callback else returns a Promise. |
| 1090 | * |
| 1091 | * {Promise} A promise is returned |
| 1092 | * |
| 1093 | * @resolve {Deployment} - The deserialized result object. |
| 1094 | * |
| 1095 | * @reject {Error} - The error object. |
| 1096 | * |
| 1097 | * {function} optionalCallback(err, result, request, response) |
| 1098 | * |
| 1099 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 1100 | * |
| 1101 | * {object} [result] - The deserialized result object if an error did not occur. |
| 1102 | * See {@link Deployment} for more information. |
| 1103 | * |
| 1104 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 1105 | * |
| 1106 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 1107 | */ |
| 1108 | create(appName, deployment, ownerName, options, optionalCallback) { |
| 1109 | let client = this.client; |
| 1110 | let self = this; |
| 1111 | if (!optionalCallback && typeof options === 'function') { |
| 1112 | optionalCallback = options; |
| 1113 | options = null; |
| 1114 | } |
| 1115 | if (!optionalCallback) { |
| 1116 | return new Promise((resolve, reject) => { |
| 1117 | self._create(appName, deployment, ownerName, options, (err, result, request, response) => { |
| 1118 | if (err) { reject(err); } |
| 1119 | else { resolve(result); } |
| 1120 | return; |
| 1121 | }); |
| 1122 | }); |
| 1123 | } else { |
| 1124 | return self._create(appName, deployment, ownerName, options, optionalCallback); |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * Deletes a CodePush Deployment for the given app |
| 1130 | * |
| 1131 | * @param {string} appName The name of the application |
| 1132 | * |
| 1133 | * @param {string} deploymentName deployment name |
| 1134 | * |
| 1135 | * @param {string} ownerName The name of the owner |
| 1136 | * |
| 1137 | * @param {object} [options] Optional Parameters. |
| 1138 | * |
| 1139 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1140 | * request |
| 1141 | * |
| 1142 | * @returns {Promise} A promise is returned |
| 1143 | * |
| 1144 | * @resolve {HttpOperationResponse<null>} - The deserialized result object. |
| 1145 | * |
| 1146 | * @reject {Error} - The error object. |
| 1147 | */ |
| 1148 | deleteMethodWithHttpOperationResponse(appName, deploymentName, ownerName, options) { |
| 1149 | let client = this.client; |
| 1150 | let self = this; |
| 1151 | return new Promise((resolve, reject) => { |
| 1152 | self._deleteMethod(appName, deploymentName, ownerName, options, (err, result, request, response) => { |
| 1153 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 1154 | httpOperationResponse.body = result; |
| 1155 | if (err) { reject(err); } |
| 1156 | else { resolve(httpOperationResponse); } |
| 1157 | return; |
| 1158 | }); |
| 1159 | }); |
| 1160 | } |
| 1161 | |
| 1162 | /** |
| 1163 | * Deletes a CodePush Deployment for the given app |
| 1164 | * |
| 1165 | * @param {string} appName The name of the application |
| 1166 | * |
| 1167 | * @param {string} deploymentName deployment name |
| 1168 | * |
| 1169 | * @param {string} ownerName The name of the owner |
| 1170 | * |
| 1171 | * @param {object} [options] Optional Parameters. |
| 1172 | * |
| 1173 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1174 | * request |
| 1175 | * |
| 1176 | * @param {function} [optionalCallback] - The optional callback. |
| 1177 | * |
| 1178 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 1179 | * then it returns the callback else returns a Promise. |
| 1180 | * |
| 1181 | * {Promise} A promise is returned |
| 1182 | * |
| 1183 | * @resolve {null} - The deserialized result object. |
| 1184 | * |
| 1185 | * @reject {Error} - The error object. |
| 1186 | * |
| 1187 | * {function} optionalCallback(err, result, request, response) |
| 1188 | * |
| 1189 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 1190 | * |
| 1191 | * {null} [result] - The deserialized result object if an error did not occur. |
| 1192 | * |
| 1193 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 1194 | * |
| 1195 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 1196 | */ |
| 1197 | deleteMethod(appName, deploymentName, ownerName, options, optionalCallback) { |
| 1198 | let client = this.client; |
| 1199 | let self = this; |
| 1200 | if (!optionalCallback && typeof options === 'function') { |
| 1201 | optionalCallback = options; |
| 1202 | options = null; |
| 1203 | } |
| 1204 | if (!optionalCallback) { |
| 1205 | return new Promise((resolve, reject) => { |
| 1206 | self._deleteMethod(appName, deploymentName, ownerName, options, (err, result, request, response) => { |
| 1207 | if (err) { reject(err); } |
| 1208 | else { resolve(result); } |
| 1209 | return; |
| 1210 | }); |
| 1211 | }); |
| 1212 | } else { |
| 1213 | return self._deleteMethod(appName, deploymentName, ownerName, options, optionalCallback); |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | /** |
| 1218 | * Gets a CodePush Deployment for the given app |
| 1219 | * |
| 1220 | * @param {string} appName The name of the application |
| 1221 | * |
| 1222 | * @param {string} deploymentName deployment name |
| 1223 | * |
| 1224 | * @param {string} ownerName The name of the owner |
| 1225 | * |
| 1226 | * @param {object} [options] Optional Parameters. |
| 1227 | * |
| 1228 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1229 | * request |
| 1230 | * |
| 1231 | * @returns {Promise} A promise is returned |
| 1232 | * |
| 1233 | * @resolve {HttpOperationResponse<Deployment>} - The deserialized result object. |
| 1234 | * |
| 1235 | * @reject {Error} - The error object. |
| 1236 | */ |
| 1237 | getWithHttpOperationResponse(appName, deploymentName, ownerName, options) { |
| 1238 | let client = this.client; |
| 1239 | let self = this; |
| 1240 | return new Promise((resolve, reject) => { |
| 1241 | self._get(appName, deploymentName, ownerName, options, (err, result, request, response) => { |
| 1242 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 1243 | httpOperationResponse.body = result; |
| 1244 | if (err) { reject(err); } |
| 1245 | else { resolve(httpOperationResponse); } |
| 1246 | return; |
| 1247 | }); |
| 1248 | }); |
| 1249 | } |
| 1250 | |
| 1251 | /** |
| 1252 | * Gets a CodePush Deployment for the given app |
| 1253 | * |
| 1254 | * @param {string} appName The name of the application |
| 1255 | * |
| 1256 | * @param {string} deploymentName deployment name |
| 1257 | * |
| 1258 | * @param {string} ownerName The name of the owner |
| 1259 | * |
| 1260 | * @param {object} [options] Optional Parameters. |
| 1261 | * |
| 1262 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1263 | * request |
| 1264 | * |
| 1265 | * @param {function} [optionalCallback] - The optional callback. |
| 1266 | * |
| 1267 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 1268 | * then it returns the callback else returns a Promise. |
| 1269 | * |
| 1270 | * {Promise} A promise is returned |
| 1271 | * |
| 1272 | * @resolve {Deployment} - The deserialized result object. |
| 1273 | * |
| 1274 | * @reject {Error} - The error object. |
| 1275 | * |
| 1276 | * {function} optionalCallback(err, result, request, response) |
| 1277 | * |
| 1278 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 1279 | * |
| 1280 | * {object} [result] - The deserialized result object if an error did not occur. |
| 1281 | * See {@link Deployment} for more information. |
| 1282 | * |
| 1283 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 1284 | * |
| 1285 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 1286 | */ |
| 1287 | get(appName, deploymentName, ownerName, options, optionalCallback) { |
| 1288 | let client = this.client; |
| 1289 | let self = this; |
| 1290 | if (!optionalCallback && typeof options === 'function') { |
| 1291 | optionalCallback = options; |
| 1292 | options = null; |
| 1293 | } |
| 1294 | if (!optionalCallback) { |
| 1295 | return new Promise((resolve, reject) => { |
| 1296 | self._get(appName, deploymentName, ownerName, options, (err, result, request, response) => { |
| 1297 | if (err) { reject(err); } |
| 1298 | else { resolve(result); } |
| 1299 | return; |
| 1300 | }); |
| 1301 | }); |
| 1302 | } else { |
| 1303 | return self._get(appName, deploymentName, ownerName, options, optionalCallback); |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | /** |
| 1308 | * Modifies a CodePush Deployment for the given app |
| 1309 | * |
| 1310 | * @param {string} appName The name of the application |
| 1311 | * |
| 1312 | * @param {object} deployment Deployment modification. All fields are optional |
| 1313 | * and only provided fields will get updated. |
| 1314 | * |
| 1315 | * @param {string} deployment.name |
| 1316 | * |
| 1317 | * @param {string} deploymentName deployment name |
| 1318 | * |
| 1319 | * @param {string} ownerName The name of the owner |
| 1320 | * |
| 1321 | * @param {object} [options] Optional Parameters. |
| 1322 | * |
| 1323 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1324 | * request |
| 1325 | * |
| 1326 | * @returns {Promise} A promise is returned |
| 1327 | * |
| 1328 | * @resolve {HttpOperationResponse<null>} - The deserialized result object. |
| 1329 | * |
| 1330 | * @reject {Error} - The error object. |
| 1331 | */ |
| 1332 | updateWithHttpOperationResponse(appName, deployment, deploymentName, ownerName, options) { |
| 1333 | let client = this.client; |
| 1334 | let self = this; |
| 1335 | return new Promise((resolve, reject) => { |
| 1336 | self._update(appName, deployment, deploymentName, ownerName, options, (err, result, request, response) => { |
| 1337 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 1338 | httpOperationResponse.body = result; |
| 1339 | if (err) { reject(err); } |
| 1340 | else { resolve(httpOperationResponse); } |
| 1341 | return; |
| 1342 | }); |
| 1343 | }); |
| 1344 | } |
| 1345 | |
| 1346 | /** |
| 1347 | * Modifies a CodePush Deployment for the given app |
| 1348 | * |
| 1349 | * @param {string} appName The name of the application |
| 1350 | * |
| 1351 | * @param {object} deployment Deployment modification. All fields are optional |
| 1352 | * and only provided fields will get updated. |
| 1353 | * |
| 1354 | * @param {string} deployment.name |
| 1355 | * |
| 1356 | * @param {string} deploymentName deployment name |
| 1357 | * |
| 1358 | * @param {string} ownerName The name of the owner |
| 1359 | * |
| 1360 | * @param {object} [options] Optional Parameters. |
| 1361 | * |
| 1362 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1363 | * request |
| 1364 | * |
| 1365 | * @param {function} [optionalCallback] - The optional callback. |
| 1366 | * |
| 1367 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 1368 | * then it returns the callback else returns a Promise. |
| 1369 | * |
| 1370 | * {Promise} A promise is returned |
| 1371 | * |
| 1372 | * @resolve {null} - The deserialized result object. |
| 1373 | * |
| 1374 | * @reject {Error} - The error object. |
| 1375 | * |
| 1376 | * {function} optionalCallback(err, result, request, response) |
| 1377 | * |
| 1378 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 1379 | * |
| 1380 | * {null} [result] - The deserialized result object if an error did not occur. |
| 1381 | * |
| 1382 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 1383 | * |
| 1384 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 1385 | */ |
| 1386 | update(appName, deployment, deploymentName, ownerName, options, optionalCallback) { |
| 1387 | let client = this.client; |
| 1388 | let self = this; |
| 1389 | if (!optionalCallback && typeof options === 'function') { |
| 1390 | optionalCallback = options; |
| 1391 | options = null; |
| 1392 | } |
| 1393 | if (!optionalCallback) { |
| 1394 | return new Promise((resolve, reject) => { |
| 1395 | self._update(appName, deployment, deploymentName, ownerName, options, (err, result, request, response) => { |
| 1396 | if (err) { reject(err); } |
| 1397 | else { resolve(result); } |
| 1398 | return; |
| 1399 | }); |
| 1400 | }); |
| 1401 | } else { |
| 1402 | return self._update(appName, deployment, deploymentName, ownerName, options, optionalCallback); |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | /** |
| 1407 | * Promote one release (default latest one) from one deployment to another |
| 1408 | * |
| 1409 | * @param {string} appName The name of the application |
| 1410 | * |
| 1411 | * @param {string} deploymentName deployment name |
| 1412 | * |
| 1413 | * @param {string} ownerName The name of the owner |
| 1414 | * |
| 1415 | * @param {string} promoteDeploymentName deployment name |
| 1416 | * |
| 1417 | * @param {object} [options] Optional Parameters. |
| 1418 | * |
| 1419 | * @param {object} [options.release] Release to be promoted, only needs to |
| 1420 | * provide optional fields, description, label, disabled, mandatory, rollout, |
| 1421 | * targetBinaryVersion |
| 1422 | * |
| 1423 | * @param {string} [options.release.label] |
| 1424 | * |
| 1425 | * @param {string} [options.release.targetBinaryRange] |
| 1426 | * |
| 1427 | * @param {string} [options.release.description] |
| 1428 | * |
| 1429 | * @param {boolean} [options.release.isDisabled] |
| 1430 | * |
| 1431 | * @param {boolean} [options.release.isMandatory] |
| 1432 | * |
| 1433 | * @param {number} [options.release.rollout] |
| 1434 | * |
| 1435 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1436 | * request |
| 1437 | * |
| 1438 | * @returns {Promise} A promise is returned |
| 1439 | * |
| 1440 | * @resolve {HttpOperationResponse<CodePushRelease>} - The deserialized result object. |
| 1441 | * |
| 1442 | * @reject {Error} - The error object. |
| 1443 | */ |
| 1444 | promoteWithHttpOperationResponse(appName, deploymentName, ownerName, promoteDeploymentName, options) { |
| 1445 | let client = this.client; |
| 1446 | let self = this; |
| 1447 | return new Promise((resolve, reject) => { |
| 1448 | self._promote(appName, deploymentName, ownerName, promoteDeploymentName, options, (err, result, request, response) => { |
| 1449 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 1450 | httpOperationResponse.body = result; |
| 1451 | if (err) { reject(err); } |
| 1452 | else { resolve(httpOperationResponse); } |
| 1453 | return; |
| 1454 | }); |
| 1455 | }); |
| 1456 | } |
| 1457 | |
| 1458 | /** |
| 1459 | * Promote one release (default latest one) from one deployment to another |
| 1460 | * |
| 1461 | * @param {string} appName The name of the application |
| 1462 | * |
| 1463 | * @param {string} deploymentName deployment name |
| 1464 | * |
| 1465 | * @param {string} ownerName The name of the owner |
| 1466 | * |
| 1467 | * @param {string} promoteDeploymentName deployment name |
| 1468 | * |
| 1469 | * @param {object} [options] Optional Parameters. |
| 1470 | * |
| 1471 | * @param {object} [options.release] Release to be promoted, only needs to |
| 1472 | * provide optional fields, description, label, disabled, mandatory, rollout, |
| 1473 | * targetBinaryVersion |
| 1474 | * |
| 1475 | * @param {string} [options.release.label] |
| 1476 | * |
| 1477 | * @param {string} [options.release.targetBinaryRange] |
| 1478 | * |
| 1479 | * @param {string} [options.release.description] |
| 1480 | * |
| 1481 | * @param {boolean} [options.release.isDisabled] |
| 1482 | * |
| 1483 | * @param {boolean} [options.release.isMandatory] |
| 1484 | * |
| 1485 | * @param {number} [options.release.rollout] |
| 1486 | * |
| 1487 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1488 | * request |
| 1489 | * |
| 1490 | * @param {function} [optionalCallback] - The optional callback. |
| 1491 | * |
| 1492 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 1493 | * then it returns the callback else returns a Promise. |
| 1494 | * |
| 1495 | * {Promise} A promise is returned |
| 1496 | * |
| 1497 | * @resolve {CodePushRelease} - The deserialized result object. |
| 1498 | * |
| 1499 | * @reject {Error} - The error object. |
| 1500 | * |
| 1501 | * {function} optionalCallback(err, result, request, response) |
| 1502 | * |
| 1503 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 1504 | * |
| 1505 | * {object} [result] - The deserialized result object if an error did not occur. |
| 1506 | * See {@link CodePushRelease} for more information. |
| 1507 | * |
| 1508 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 1509 | * |
| 1510 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 1511 | */ |
| 1512 | promote(appName, deploymentName, ownerName, promoteDeploymentName, options, optionalCallback) { |
| 1513 | let client = this.client; |
| 1514 | let self = this; |
| 1515 | if (!optionalCallback && typeof options === 'function') { |
| 1516 | optionalCallback = options; |
| 1517 | options = null; |
| 1518 | } |
| 1519 | if (!optionalCallback) { |
| 1520 | return new Promise((resolve, reject) => { |
| 1521 | self._promote(appName, deploymentName, ownerName, promoteDeploymentName, options, (err, result, request, response) => { |
| 1522 | if (err) { reject(err); } |
| 1523 | else { resolve(result); } |
| 1524 | return; |
| 1525 | }); |
| 1526 | }); |
| 1527 | } else { |
| 1528 | return self._promote(appName, deploymentName, ownerName, promoteDeploymentName, options, optionalCallback); |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | } |
| 1533 | |
| 1534 | module.exports = CodePushDeployments; |
| 1535 | |