microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
lib/app-center-node-client/src/account/operations/orgInvitations.js
1222lines · 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 | * Invites a new or existing user to an organization |
| 14 | * |
| 15 | * @param {string} orgName The organization's name |
| 16 | * |
| 17 | * @param {object} [options] Optional Parameters. |
| 18 | * |
| 19 | * @param {object} [options.userEmail] The email of the user to invite |
| 20 | * |
| 21 | * @param {string} options.userEmail.userEmail The user's email address' |
| 22 | * |
| 23 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 24 | * request |
| 25 | * |
| 26 | * @param {function} callback - The callback. |
| 27 | * |
| 28 | * @returns {function} callback(err, result, request, response) |
| 29 | * |
| 30 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 31 | * |
| 32 | * {null} [result] - The deserialized result object if an error did not occur. |
| 33 | * |
| 34 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 35 | * |
| 36 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 37 | */ |
| 38 | function _create(orgName, options, callback) { |
| 39 | /* jshint validthis: true */ |
| 40 | let client = this.client; |
| 41 | if(!callback && typeof options === 'function') { |
| 42 | callback = options; |
| 43 | options = null; |
| 44 | } |
| 45 | if (!callback) { |
| 46 | throw new Error('callback cannot be null.'); |
| 47 | } |
| 48 | let userEmail = (options && options.userEmail !== undefined) ? options.userEmail : undefined; |
| 49 | // Validate |
| 50 | try { |
| 51 | if (orgName === null || orgName === undefined || typeof orgName.valueOf() !== 'string') { |
| 52 | throw new Error('orgName 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/orgs/{org_name}/invitations'; |
| 61 | requestUrl = requestUrl.replace('{org_name}', encodeURIComponent(orgName)); |
| 62 | |
| 63 | // Create HTTP transport objects |
| 64 | let httpRequest = new WebResource(); |
| 65 | httpRequest.method = 'POST'; |
| 66 | httpRequest.url = requestUrl; |
| 67 | httpRequest.headers = {}; |
| 68 | // Set Headers |
| 69 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 70 | if(options) { |
| 71 | for(let headerName in options['customHeaders']) { |
| 72 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 73 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | // Serialize Request |
| 78 | let requestContent = null; |
| 79 | let requestModel = null; |
| 80 | try { |
| 81 | if (userEmail !== null && userEmail !== undefined) { |
| 82 | let requestModelMapper = new client.models['UserEmailRequest']().mapper(); |
| 83 | requestModel = client.serialize(requestModelMapper, userEmail, 'userEmail'); |
| 84 | requestContent = JSON.stringify(requestModel); |
| 85 | } |
| 86 | } catch (error) { |
| 87 | let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + |
| 88 | `payload - ${JSON.stringify(userEmail, null, 2)}.`); |
| 89 | return callback(serializationError); |
| 90 | } |
| 91 | httpRequest.body = requestContent; |
| 92 | // Send Request |
| 93 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 94 | if (err) { |
| 95 | return callback(err); |
| 96 | } |
| 97 | let statusCode = response.statusCode; |
| 98 | if (statusCode < 200 || statusCode >= 300) { |
| 99 | let error = new Error(responseBody); |
| 100 | error.statusCode = response.statusCode; |
| 101 | error.request = msRest.stripRequest(httpRequest); |
| 102 | error.response = msRest.stripResponse(response); |
| 103 | if (responseBody === '') responseBody = null; |
| 104 | let parsedErrorResponse; |
| 105 | try { |
| 106 | parsedErrorResponse = JSON.parse(responseBody); |
| 107 | if (parsedErrorResponse) { |
| 108 | let internalError = null; |
| 109 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 110 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 111 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 112 | } |
| 113 | } catch (defaultError) { |
| 114 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 115 | `- "${responseBody}" for the default response.`; |
| 116 | return callback(error); |
| 117 | } |
| 118 | return callback(error); |
| 119 | } |
| 120 | // Create Result |
| 121 | let result = null; |
| 122 | if (responseBody === '') responseBody = null; |
| 123 | |
| 124 | return callback(null, result, httpRequest, response); |
| 125 | }); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Removes a user's invitation to an organization |
| 130 | * |
| 131 | * @param {string} orgName The organization's name |
| 132 | * |
| 133 | * @param {object} [options] Optional Parameters. |
| 134 | * |
| 135 | * @param {object} [options.userEmail] The email of the user whose invitation |
| 136 | * should be removed |
| 137 | * |
| 138 | * @param {string} options.userEmail.userEmail The user's email address' |
| 139 | * |
| 140 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 141 | * request |
| 142 | * |
| 143 | * @param {function} callback - The callback. |
| 144 | * |
| 145 | * @returns {function} callback(err, result, request, response) |
| 146 | * |
| 147 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 148 | * |
| 149 | * {null} [result] - The deserialized result object if an error did not occur. |
| 150 | * |
| 151 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 152 | * |
| 153 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 154 | */ |
| 155 | function _deleteMethod(orgName, options, callback) { |
| 156 | /* jshint validthis: true */ |
| 157 | let client = this.client; |
| 158 | if(!callback && typeof options === 'function') { |
| 159 | callback = options; |
| 160 | options = null; |
| 161 | } |
| 162 | if (!callback) { |
| 163 | throw new Error('callback cannot be null.'); |
| 164 | } |
| 165 | let userEmail = (options && options.userEmail !== undefined) ? options.userEmail : undefined; |
| 166 | // Validate |
| 167 | try { |
| 168 | if (orgName === null || orgName === undefined || typeof orgName.valueOf() !== 'string') { |
| 169 | throw new Error('orgName cannot be null or undefined and it must be of type string.'); |
| 170 | } |
| 171 | } catch (error) { |
| 172 | return callback(error); |
| 173 | } |
| 174 | |
| 175 | // Construct URL |
| 176 | let baseUrl = this.client.baseUri; |
| 177 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/orgs/{org_name}/invitations'; |
| 178 | requestUrl = requestUrl.replace('{org_name}', encodeURIComponent(orgName)); |
| 179 | |
| 180 | // Create HTTP transport objects |
| 181 | let httpRequest = new WebResource(); |
| 182 | httpRequest.method = 'DELETE'; |
| 183 | httpRequest.url = requestUrl; |
| 184 | httpRequest.headers = {}; |
| 185 | // Set Headers |
| 186 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 187 | if(options) { |
| 188 | for(let headerName in options['customHeaders']) { |
| 189 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 190 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | // Serialize Request |
| 195 | let requestContent = null; |
| 196 | let requestModel = null; |
| 197 | try { |
| 198 | if (userEmail !== null && userEmail !== undefined) { |
| 199 | let requestModelMapper = new client.models['UserEmailRequest']().mapper(); |
| 200 | requestModel = client.serialize(requestModelMapper, userEmail, 'userEmail'); |
| 201 | requestContent = JSON.stringify(requestModel); |
| 202 | } |
| 203 | } catch (error) { |
| 204 | let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + |
| 205 | `payload - ${JSON.stringify(userEmail, null, 2)}.`); |
| 206 | return callback(serializationError); |
| 207 | } |
| 208 | httpRequest.body = requestContent; |
| 209 | // Send Request |
| 210 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 211 | if (err) { |
| 212 | return callback(err); |
| 213 | } |
| 214 | let statusCode = response.statusCode; |
| 215 | if (statusCode < 200 || statusCode >= 300) { |
| 216 | let error = new Error(responseBody); |
| 217 | error.statusCode = response.statusCode; |
| 218 | error.request = msRest.stripRequest(httpRequest); |
| 219 | error.response = msRest.stripResponse(response); |
| 220 | if (responseBody === '') responseBody = null; |
| 221 | let parsedErrorResponse; |
| 222 | try { |
| 223 | parsedErrorResponse = JSON.parse(responseBody); |
| 224 | if (parsedErrorResponse) { |
| 225 | let internalError = null; |
| 226 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 227 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 228 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 229 | } |
| 230 | } catch (defaultError) { |
| 231 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 232 | `- "${responseBody}" for the default response.`; |
| 233 | return callback(error); |
| 234 | } |
| 235 | return callback(error); |
| 236 | } |
| 237 | // Create Result |
| 238 | let result = null; |
| 239 | if (responseBody === '') responseBody = null; |
| 240 | |
| 241 | return callback(null, result, httpRequest, response); |
| 242 | }); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Gets the pending invitations for the organization |
| 247 | * |
| 248 | * @param {string} orgName The organization's name |
| 249 | * |
| 250 | * @param {object} [options] Optional Parameters. |
| 251 | * |
| 252 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 253 | * request |
| 254 | * |
| 255 | * @param {function} callback - The callback. |
| 256 | * |
| 257 | * @returns {function} callback(err, result, request, response) |
| 258 | * |
| 259 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 260 | * |
| 261 | * {array} [result] - The deserialized result object if an error did not occur. |
| 262 | * |
| 263 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 264 | * |
| 265 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 266 | */ |
| 267 | function _listPending(orgName, options, callback) { |
| 268 | /* jshint validthis: true */ |
| 269 | let client = this.client; |
| 270 | if(!callback && typeof options === 'function') { |
| 271 | callback = options; |
| 272 | options = null; |
| 273 | } |
| 274 | if (!callback) { |
| 275 | throw new Error('callback cannot be null.'); |
| 276 | } |
| 277 | // Validate |
| 278 | try { |
| 279 | if (orgName === null || orgName === undefined || typeof orgName.valueOf() !== 'string') { |
| 280 | throw new Error('orgName cannot be null or undefined and it must be of type string.'); |
| 281 | } |
| 282 | } catch (error) { |
| 283 | return callback(error); |
| 284 | } |
| 285 | |
| 286 | // Construct URL |
| 287 | let baseUrl = this.client.baseUri; |
| 288 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/orgs/{org_name}/invitations'; |
| 289 | requestUrl = requestUrl.replace('{org_name}', encodeURIComponent(orgName)); |
| 290 | |
| 291 | // Create HTTP transport objects |
| 292 | let httpRequest = new WebResource(); |
| 293 | httpRequest.method = 'GET'; |
| 294 | httpRequest.url = requestUrl; |
| 295 | httpRequest.headers = {}; |
| 296 | // Set Headers |
| 297 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 298 | if(options) { |
| 299 | for(let headerName in options['customHeaders']) { |
| 300 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 301 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | httpRequest.body = null; |
| 306 | // Send Request |
| 307 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 308 | if (err) { |
| 309 | return callback(err); |
| 310 | } |
| 311 | let statusCode = response.statusCode; |
| 312 | if (statusCode !== 200) { |
| 313 | let error = new Error(responseBody); |
| 314 | error.statusCode = response.statusCode; |
| 315 | error.request = msRest.stripRequest(httpRequest); |
| 316 | error.response = msRest.stripResponse(response); |
| 317 | if (responseBody === '') responseBody = null; |
| 318 | let parsedErrorResponse; |
| 319 | try { |
| 320 | parsedErrorResponse = JSON.parse(responseBody); |
| 321 | if (parsedErrorResponse) { |
| 322 | let internalError = null; |
| 323 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 324 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 325 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 326 | } |
| 327 | } catch (defaultError) { |
| 328 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 329 | `- "${responseBody}" for the default response.`; |
| 330 | return callback(error); |
| 331 | } |
| 332 | return callback(error); |
| 333 | } |
| 334 | // Create Result |
| 335 | let result = null; |
| 336 | if (responseBody === '') responseBody = null; |
| 337 | // Deserialize Response |
| 338 | if (statusCode === 200) { |
| 339 | let parsedResponse = null; |
| 340 | try { |
| 341 | parsedResponse = JSON.parse(responseBody); |
| 342 | result = JSON.parse(responseBody); |
| 343 | if (parsedResponse !== null && parsedResponse !== undefined) { |
| 344 | let resultMapper = { |
| 345 | required: false, |
| 346 | serializedName: 'parsedResponse', |
| 347 | type: { |
| 348 | name: 'Sequence', |
| 349 | element: { |
| 350 | required: false, |
| 351 | serializedName: 'OrganizationInvitationSimpleDetailResponseElementType', |
| 352 | type: { |
| 353 | name: 'Composite', |
| 354 | className: 'OrganizationInvitationSimpleDetailResponse' |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | }; |
| 359 | result = client.deserialize(resultMapper, parsedResponse, 'result'); |
| 360 | } |
| 361 | } catch (error) { |
| 362 | let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); |
| 363 | deserializationError.request = msRest.stripRequest(httpRequest); |
| 364 | deserializationError.response = msRest.stripResponse(response); |
| 365 | return callback(deserializationError); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | return callback(null, result, httpRequest, response); |
| 370 | }); |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * Cancels an existing organization for the user and sends a new one |
| 375 | * |
| 376 | * @param {string} orgName The organization's name |
| 377 | * |
| 378 | * @param {object} [options] Optional Parameters. |
| 379 | * |
| 380 | * @param {object} [options.userEmail] The email of the user for which to |
| 381 | * resend the invitation |
| 382 | * |
| 383 | * @param {string} options.userEmail.userEmail The user's email address' |
| 384 | * |
| 385 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 386 | * request |
| 387 | * |
| 388 | * @param {function} callback - The callback. |
| 389 | * |
| 390 | * @returns {function} callback(err, result, request, response) |
| 391 | * |
| 392 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 393 | * |
| 394 | * {null} [result] - The deserialized result object if an error did not occur. |
| 395 | * |
| 396 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 397 | * |
| 398 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 399 | */ |
| 400 | function _sendNewInvitation(orgName, options, callback) { |
| 401 | /* jshint validthis: true */ |
| 402 | let client = this.client; |
| 403 | if(!callback && typeof options === 'function') { |
| 404 | callback = options; |
| 405 | options = null; |
| 406 | } |
| 407 | if (!callback) { |
| 408 | throw new Error('callback cannot be null.'); |
| 409 | } |
| 410 | let userEmail = (options && options.userEmail !== undefined) ? options.userEmail : undefined; |
| 411 | // Validate |
| 412 | try { |
| 413 | if (orgName === null || orgName === undefined || typeof orgName.valueOf() !== 'string') { |
| 414 | throw new Error('orgName cannot be null or undefined and it must be of type string.'); |
| 415 | } |
| 416 | } catch (error) { |
| 417 | return callback(error); |
| 418 | } |
| 419 | |
| 420 | // Construct URL |
| 421 | let baseUrl = this.client.baseUri; |
| 422 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/orgs/{org_name}/invitations/resend'; |
| 423 | requestUrl = requestUrl.replace('{org_name}', encodeURIComponent(orgName)); |
| 424 | |
| 425 | // Create HTTP transport objects |
| 426 | let httpRequest = new WebResource(); |
| 427 | httpRequest.method = 'POST'; |
| 428 | httpRequest.url = requestUrl; |
| 429 | httpRequest.headers = {}; |
| 430 | // Set Headers |
| 431 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 432 | if(options) { |
| 433 | for(let headerName in options['customHeaders']) { |
| 434 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 435 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | // Serialize Request |
| 440 | let requestContent = null; |
| 441 | let requestModel = null; |
| 442 | try { |
| 443 | if (userEmail !== null && userEmail !== undefined) { |
| 444 | let requestModelMapper = new client.models['UserEmailRequest']().mapper(); |
| 445 | requestModel = client.serialize(requestModelMapper, userEmail, 'userEmail'); |
| 446 | requestContent = JSON.stringify(requestModel); |
| 447 | } |
| 448 | } catch (error) { |
| 449 | let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + |
| 450 | `payload - ${JSON.stringify(userEmail, null, 2)}.`); |
| 451 | return callback(serializationError); |
| 452 | } |
| 453 | httpRequest.body = requestContent; |
| 454 | // Send Request |
| 455 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 456 | if (err) { |
| 457 | return callback(err); |
| 458 | } |
| 459 | let statusCode = response.statusCode; |
| 460 | if (statusCode < 200 || statusCode >= 300) { |
| 461 | let error = new Error(responseBody); |
| 462 | error.statusCode = response.statusCode; |
| 463 | error.request = msRest.stripRequest(httpRequest); |
| 464 | error.response = msRest.stripResponse(response); |
| 465 | if (responseBody === '') responseBody = null; |
| 466 | let parsedErrorResponse; |
| 467 | try { |
| 468 | parsedErrorResponse = JSON.parse(responseBody); |
| 469 | if (parsedErrorResponse) { |
| 470 | let internalError = null; |
| 471 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 472 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 473 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 474 | } |
| 475 | } catch (defaultError) { |
| 476 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 477 | `- "${responseBody}" for the default response.`; |
| 478 | return callback(error); |
| 479 | } |
| 480 | return callback(error); |
| 481 | } |
| 482 | // Create Result |
| 483 | let result = null; |
| 484 | if (responseBody === '') responseBody = null; |
| 485 | |
| 486 | return callback(null, result, httpRequest, response); |
| 487 | }); |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | * Accepts a pending organization invitation for the specified user |
| 492 | * |
| 493 | * @param {string} invitationToken The app invitation token that was sent to |
| 494 | * the user |
| 495 | * |
| 496 | * @param {object} [options] Optional Parameters. |
| 497 | * |
| 498 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 499 | * request |
| 500 | * |
| 501 | * @param {function} callback - The callback. |
| 502 | * |
| 503 | * @returns {function} callback(err, result, request, response) |
| 504 | * |
| 505 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 506 | * |
| 507 | * {null} [result] - The deserialized result object if an error did not occur. |
| 508 | * |
| 509 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 510 | * |
| 511 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 512 | */ |
| 513 | function _accept(invitationToken, options, callback) { |
| 514 | /* jshint validthis: true */ |
| 515 | let client = this.client; |
| 516 | if(!callback && typeof options === 'function') { |
| 517 | callback = options; |
| 518 | options = null; |
| 519 | } |
| 520 | if (!callback) { |
| 521 | throw new Error('callback cannot be null.'); |
| 522 | } |
| 523 | // Validate |
| 524 | try { |
| 525 | if (invitationToken === null || invitationToken === undefined || typeof invitationToken.valueOf() !== 'string') { |
| 526 | throw new Error('invitationToken cannot be null or undefined and it must be of type string.'); |
| 527 | } |
| 528 | } catch (error) { |
| 529 | return callback(error); |
| 530 | } |
| 531 | |
| 532 | // Construct URL |
| 533 | let baseUrl = this.client.baseUri; |
| 534 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/user/invitations/orgs/{invitation_token}/accept'; |
| 535 | requestUrl = requestUrl.replace('{invitation_token}', encodeURIComponent(invitationToken)); |
| 536 | |
| 537 | // Create HTTP transport objects |
| 538 | let httpRequest = new WebResource(); |
| 539 | httpRequest.method = 'POST'; |
| 540 | httpRequest.url = requestUrl; |
| 541 | httpRequest.headers = {}; |
| 542 | // Set Headers |
| 543 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 544 | if(options) { |
| 545 | for(let headerName in options['customHeaders']) { |
| 546 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 547 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | httpRequest.body = null; |
| 552 | // Send Request |
| 553 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 554 | if (err) { |
| 555 | return callback(err); |
| 556 | } |
| 557 | let statusCode = response.statusCode; |
| 558 | if (statusCode < 200 || statusCode >= 300) { |
| 559 | let error = new Error(responseBody); |
| 560 | error.statusCode = response.statusCode; |
| 561 | error.request = msRest.stripRequest(httpRequest); |
| 562 | error.response = msRest.stripResponse(response); |
| 563 | if (responseBody === '') responseBody = null; |
| 564 | let parsedErrorResponse; |
| 565 | try { |
| 566 | parsedErrorResponse = JSON.parse(responseBody); |
| 567 | if (parsedErrorResponse) { |
| 568 | let internalError = null; |
| 569 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 570 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 571 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 572 | } |
| 573 | } catch (defaultError) { |
| 574 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 575 | `- "${responseBody}" for the default response.`; |
| 576 | return callback(error); |
| 577 | } |
| 578 | return callback(error); |
| 579 | } |
| 580 | // Create Result |
| 581 | let result = null; |
| 582 | if (responseBody === '') responseBody = null; |
| 583 | |
| 584 | return callback(null, result, httpRequest, response); |
| 585 | }); |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * Rejects a pending organization invitation |
| 590 | * |
| 591 | * @param {string} invitationToken The app invitation token that was sent to |
| 592 | * the user |
| 593 | * |
| 594 | * @param {object} [options] Optional Parameters. |
| 595 | * |
| 596 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 597 | * request |
| 598 | * |
| 599 | * @param {function} callback - The callback. |
| 600 | * |
| 601 | * @returns {function} callback(err, result, request, response) |
| 602 | * |
| 603 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 604 | * |
| 605 | * {null} [result] - The deserialized result object if an error did not occur. |
| 606 | * |
| 607 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 608 | * |
| 609 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 610 | */ |
| 611 | function _reject(invitationToken, options, callback) { |
| 612 | /* jshint validthis: true */ |
| 613 | let client = this.client; |
| 614 | if(!callback && typeof options === 'function') { |
| 615 | callback = options; |
| 616 | options = null; |
| 617 | } |
| 618 | if (!callback) { |
| 619 | throw new Error('callback cannot be null.'); |
| 620 | } |
| 621 | // Validate |
| 622 | try { |
| 623 | if (invitationToken === null || invitationToken === undefined || typeof invitationToken.valueOf() !== 'string') { |
| 624 | throw new Error('invitationToken cannot be null or undefined and it must be of type string.'); |
| 625 | } |
| 626 | } catch (error) { |
| 627 | return callback(error); |
| 628 | } |
| 629 | |
| 630 | // Construct URL |
| 631 | let baseUrl = this.client.baseUri; |
| 632 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/user/invitations/orgs/{invitation_token}/reject'; |
| 633 | requestUrl = requestUrl.replace('{invitation_token}', encodeURIComponent(invitationToken)); |
| 634 | |
| 635 | // Create HTTP transport objects |
| 636 | let httpRequest = new WebResource(); |
| 637 | httpRequest.method = 'POST'; |
| 638 | httpRequest.url = requestUrl; |
| 639 | httpRequest.headers = {}; |
| 640 | // Set Headers |
| 641 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 642 | if(options) { |
| 643 | for(let headerName in options['customHeaders']) { |
| 644 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 645 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | httpRequest.body = null; |
| 650 | // Send Request |
| 651 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 652 | if (err) { |
| 653 | return callback(err); |
| 654 | } |
| 655 | let statusCode = response.statusCode; |
| 656 | if (statusCode < 200 || statusCode >= 300) { |
| 657 | let error = new Error(responseBody); |
| 658 | error.statusCode = response.statusCode; |
| 659 | error.request = msRest.stripRequest(httpRequest); |
| 660 | error.response = msRest.stripResponse(response); |
| 661 | if (responseBody === '') responseBody = null; |
| 662 | let parsedErrorResponse; |
| 663 | try { |
| 664 | parsedErrorResponse = JSON.parse(responseBody); |
| 665 | if (parsedErrorResponse) { |
| 666 | let internalError = null; |
| 667 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 668 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 669 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 670 | } |
| 671 | } catch (defaultError) { |
| 672 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 673 | `- "${responseBody}" for the default response.`; |
| 674 | return callback(error); |
| 675 | } |
| 676 | return callback(error); |
| 677 | } |
| 678 | // Create Result |
| 679 | let result = null; |
| 680 | if (responseBody === '') responseBody = null; |
| 681 | |
| 682 | return callback(null, result, httpRequest, response); |
| 683 | }); |
| 684 | } |
| 685 | |
| 686 | /** Class representing a OrgInvitations. */ |
| 687 | class OrgInvitations { |
| 688 | /** |
| 689 | * Create a OrgInvitations. |
| 690 | * @param {AccountClient} client Reference to the service client. |
| 691 | */ |
| 692 | constructor(client) { |
| 693 | this.client = client; |
| 694 | this._create = _create; |
| 695 | this._deleteMethod = _deleteMethod; |
| 696 | this._listPending = _listPending; |
| 697 | this._sendNewInvitation = _sendNewInvitation; |
| 698 | this._accept = _accept; |
| 699 | this._reject = _reject; |
| 700 | } |
| 701 | |
| 702 | /** |
| 703 | * Invites a new or existing user to an organization |
| 704 | * |
| 705 | * @param {string} orgName The organization's name |
| 706 | * |
| 707 | * @param {object} [options] Optional Parameters. |
| 708 | * |
| 709 | * @param {object} [options.userEmail] The email of the user to invite |
| 710 | * |
| 711 | * @param {string} options.userEmail.userEmail The user's email address' |
| 712 | * |
| 713 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 714 | * request |
| 715 | * |
| 716 | * @returns {Promise} A promise is returned |
| 717 | * |
| 718 | * @resolve {HttpOperationResponse<null>} - The deserialized result object. |
| 719 | * |
| 720 | * @reject {Error} - The error object. |
| 721 | */ |
| 722 | createWithHttpOperationResponse(orgName, options) { |
| 723 | let client = this.client; |
| 724 | let self = this; |
| 725 | return new Promise((resolve, reject) => { |
| 726 | self._create(orgName, options, (err, result, request, response) => { |
| 727 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 728 | httpOperationResponse.body = result; |
| 729 | if (err) { reject(err); } |
| 730 | else { resolve(httpOperationResponse); } |
| 731 | return; |
| 732 | }); |
| 733 | }); |
| 734 | } |
| 735 | |
| 736 | /** |
| 737 | * Invites a new or existing user to an organization |
| 738 | * |
| 739 | * @param {string} orgName The organization's name |
| 740 | * |
| 741 | * @param {object} [options] Optional Parameters. |
| 742 | * |
| 743 | * @param {object} [options.userEmail] The email of the user to invite |
| 744 | * |
| 745 | * @param {string} options.userEmail.userEmail The user's email address' |
| 746 | * |
| 747 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 748 | * request |
| 749 | * |
| 750 | * @param {function} [optionalCallback] - The optional callback. |
| 751 | * |
| 752 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 753 | * then it returns the callback else returns a Promise. |
| 754 | * |
| 755 | * {Promise} A promise is returned |
| 756 | * |
| 757 | * @resolve {null} - The deserialized result object. |
| 758 | * |
| 759 | * @reject {Error} - The error object. |
| 760 | * |
| 761 | * {function} optionalCallback(err, result, request, response) |
| 762 | * |
| 763 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 764 | * |
| 765 | * {null} [result] - The deserialized result object if an error did not occur. |
| 766 | * |
| 767 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 768 | * |
| 769 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 770 | */ |
| 771 | create(orgName, options, optionalCallback) { |
| 772 | let client = this.client; |
| 773 | let self = this; |
| 774 | if (!optionalCallback && typeof options === 'function') { |
| 775 | optionalCallback = options; |
| 776 | options = null; |
| 777 | } |
| 778 | if (!optionalCallback) { |
| 779 | return new Promise((resolve, reject) => { |
| 780 | self._create(orgName, options, (err, result, request, response) => { |
| 781 | if (err) { reject(err); } |
| 782 | else { resolve(result); } |
| 783 | return; |
| 784 | }); |
| 785 | }); |
| 786 | } else { |
| 787 | return self._create(orgName, options, optionalCallback); |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | /** |
| 792 | * Removes a user's invitation to an organization |
| 793 | * |
| 794 | * @param {string} orgName The organization's name |
| 795 | * |
| 796 | * @param {object} [options] Optional Parameters. |
| 797 | * |
| 798 | * @param {object} [options.userEmail] The email of the user whose invitation |
| 799 | * should be removed |
| 800 | * |
| 801 | * @param {string} options.userEmail.userEmail The user's email address' |
| 802 | * |
| 803 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 804 | * request |
| 805 | * |
| 806 | * @returns {Promise} A promise is returned |
| 807 | * |
| 808 | * @resolve {HttpOperationResponse<null>} - The deserialized result object. |
| 809 | * |
| 810 | * @reject {Error} - The error object. |
| 811 | */ |
| 812 | deleteMethodWithHttpOperationResponse(orgName, options) { |
| 813 | let client = this.client; |
| 814 | let self = this; |
| 815 | return new Promise((resolve, reject) => { |
| 816 | self._deleteMethod(orgName, options, (err, result, request, response) => { |
| 817 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 818 | httpOperationResponse.body = result; |
| 819 | if (err) { reject(err); } |
| 820 | else { resolve(httpOperationResponse); } |
| 821 | return; |
| 822 | }); |
| 823 | }); |
| 824 | } |
| 825 | |
| 826 | /** |
| 827 | * Removes a user's invitation to an organization |
| 828 | * |
| 829 | * @param {string} orgName The organization's name |
| 830 | * |
| 831 | * @param {object} [options] Optional Parameters. |
| 832 | * |
| 833 | * @param {object} [options.userEmail] The email of the user whose invitation |
| 834 | * should be removed |
| 835 | * |
| 836 | * @param {string} options.userEmail.userEmail The user's email address' |
| 837 | * |
| 838 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 839 | * request |
| 840 | * |
| 841 | * @param {function} [optionalCallback] - The optional callback. |
| 842 | * |
| 843 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 844 | * then it returns the callback else returns a Promise. |
| 845 | * |
| 846 | * {Promise} A promise is returned |
| 847 | * |
| 848 | * @resolve {null} - The deserialized result object. |
| 849 | * |
| 850 | * @reject {Error} - The error object. |
| 851 | * |
| 852 | * {function} optionalCallback(err, result, request, response) |
| 853 | * |
| 854 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 855 | * |
| 856 | * {null} [result] - The deserialized result object if an error did not occur. |
| 857 | * |
| 858 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 859 | * |
| 860 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 861 | */ |
| 862 | deleteMethod(orgName, options, optionalCallback) { |
| 863 | let client = this.client; |
| 864 | let self = this; |
| 865 | if (!optionalCallback && typeof options === 'function') { |
| 866 | optionalCallback = options; |
| 867 | options = null; |
| 868 | } |
| 869 | if (!optionalCallback) { |
| 870 | return new Promise((resolve, reject) => { |
| 871 | self._deleteMethod(orgName, options, (err, result, request, response) => { |
| 872 | if (err) { reject(err); } |
| 873 | else { resolve(result); } |
| 874 | return; |
| 875 | }); |
| 876 | }); |
| 877 | } else { |
| 878 | return self._deleteMethod(orgName, options, optionalCallback); |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | /** |
| 883 | * Gets the pending invitations for the organization |
| 884 | * |
| 885 | * @param {string} orgName The organization's name |
| 886 | * |
| 887 | * @param {object} [options] Optional Parameters. |
| 888 | * |
| 889 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 890 | * request |
| 891 | * |
| 892 | * @returns {Promise} A promise is returned |
| 893 | * |
| 894 | * @resolve {HttpOperationResponse<Array>} - The deserialized result object. |
| 895 | * |
| 896 | * @reject {Error} - The error object. |
| 897 | */ |
| 898 | listPendingWithHttpOperationResponse(orgName, options) { |
| 899 | let client = this.client; |
| 900 | let self = this; |
| 901 | return new Promise((resolve, reject) => { |
| 902 | self._listPending(orgName, options, (err, result, request, response) => { |
| 903 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 904 | httpOperationResponse.body = result; |
| 905 | if (err) { reject(err); } |
| 906 | else { resolve(httpOperationResponse); } |
| 907 | return; |
| 908 | }); |
| 909 | }); |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * Gets the pending invitations for the organization |
| 914 | * |
| 915 | * @param {string} orgName The organization's name |
| 916 | * |
| 917 | * @param {object} [options] Optional Parameters. |
| 918 | * |
| 919 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 920 | * request |
| 921 | * |
| 922 | * @param {function} [optionalCallback] - The optional callback. |
| 923 | * |
| 924 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 925 | * then it returns the callback else returns a Promise. |
| 926 | * |
| 927 | * {Promise} A promise is returned |
| 928 | * |
| 929 | * @resolve {Array} - The deserialized result object. |
| 930 | * |
| 931 | * @reject {Error} - The error object. |
| 932 | * |
| 933 | * {function} optionalCallback(err, result, request, response) |
| 934 | * |
| 935 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 936 | * |
| 937 | * {array} [result] - The deserialized result object if an error did not occur. |
| 938 | * |
| 939 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 940 | * |
| 941 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 942 | */ |
| 943 | listPending(orgName, options, optionalCallback) { |
| 944 | let client = this.client; |
| 945 | let self = this; |
| 946 | if (!optionalCallback && typeof options === 'function') { |
| 947 | optionalCallback = options; |
| 948 | options = null; |
| 949 | } |
| 950 | if (!optionalCallback) { |
| 951 | return new Promise((resolve, reject) => { |
| 952 | self._listPending(orgName, options, (err, result, request, response) => { |
| 953 | if (err) { reject(err); } |
| 954 | else { resolve(result); } |
| 955 | return; |
| 956 | }); |
| 957 | }); |
| 958 | } else { |
| 959 | return self._listPending(orgName, options, optionalCallback); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | /** |
| 964 | * Cancels an existing organization for the user and sends a new one |
| 965 | * |
| 966 | * @param {string} orgName The organization's name |
| 967 | * |
| 968 | * @param {object} [options] Optional Parameters. |
| 969 | * |
| 970 | * @param {object} [options.userEmail] The email of the user for which to |
| 971 | * resend the invitation |
| 972 | * |
| 973 | * @param {string} options.userEmail.userEmail The user's email address' |
| 974 | * |
| 975 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 976 | * request |
| 977 | * |
| 978 | * @returns {Promise} A promise is returned |
| 979 | * |
| 980 | * @resolve {HttpOperationResponse<null>} - The deserialized result object. |
| 981 | * |
| 982 | * @reject {Error} - The error object. |
| 983 | */ |
| 984 | sendNewInvitationWithHttpOperationResponse(orgName, options) { |
| 985 | let client = this.client; |
| 986 | let self = this; |
| 987 | return new Promise((resolve, reject) => { |
| 988 | self._sendNewInvitation(orgName, options, (err, result, request, response) => { |
| 989 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 990 | httpOperationResponse.body = result; |
| 991 | if (err) { reject(err); } |
| 992 | else { resolve(httpOperationResponse); } |
| 993 | return; |
| 994 | }); |
| 995 | }); |
| 996 | } |
| 997 | |
| 998 | /** |
| 999 | * Cancels an existing organization for the user and sends a new one |
| 1000 | * |
| 1001 | * @param {string} orgName The organization's name |
| 1002 | * |
| 1003 | * @param {object} [options] Optional Parameters. |
| 1004 | * |
| 1005 | * @param {object} [options.userEmail] The email of the user for which to |
| 1006 | * resend the invitation |
| 1007 | * |
| 1008 | * @param {string} options.userEmail.userEmail The user's email address' |
| 1009 | * |
| 1010 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1011 | * request |
| 1012 | * |
| 1013 | * @param {function} [optionalCallback] - The optional callback. |
| 1014 | * |
| 1015 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 1016 | * then it returns the callback else returns a Promise. |
| 1017 | * |
| 1018 | * {Promise} A promise is returned |
| 1019 | * |
| 1020 | * @resolve {null} - The deserialized result object. |
| 1021 | * |
| 1022 | * @reject {Error} - The error object. |
| 1023 | * |
| 1024 | * {function} optionalCallback(err, result, request, response) |
| 1025 | * |
| 1026 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 1027 | * |
| 1028 | * {null} [result] - The deserialized result object if an error did not occur. |
| 1029 | * |
| 1030 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 1031 | * |
| 1032 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 1033 | */ |
| 1034 | sendNewInvitation(orgName, options, optionalCallback) { |
| 1035 | let client = this.client; |
| 1036 | let self = this; |
| 1037 | if (!optionalCallback && typeof options === 'function') { |
| 1038 | optionalCallback = options; |
| 1039 | options = null; |
| 1040 | } |
| 1041 | if (!optionalCallback) { |
| 1042 | return new Promise((resolve, reject) => { |
| 1043 | self._sendNewInvitation(orgName, options, (err, result, request, response) => { |
| 1044 | if (err) { reject(err); } |
| 1045 | else { resolve(result); } |
| 1046 | return; |
| 1047 | }); |
| 1048 | }); |
| 1049 | } else { |
| 1050 | return self._sendNewInvitation(orgName, options, optionalCallback); |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | /** |
| 1055 | * Accepts a pending organization invitation for the specified user |
| 1056 | * |
| 1057 | * @param {string} invitationToken The app invitation token that was sent to |
| 1058 | * the user |
| 1059 | * |
| 1060 | * @param {object} [options] Optional Parameters. |
| 1061 | * |
| 1062 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1063 | * request |
| 1064 | * |
| 1065 | * @returns {Promise} A promise is returned |
| 1066 | * |
| 1067 | * @resolve {HttpOperationResponse<null>} - The deserialized result object. |
| 1068 | * |
| 1069 | * @reject {Error} - The error object. |
| 1070 | */ |
| 1071 | acceptWithHttpOperationResponse(invitationToken, options) { |
| 1072 | let client = this.client; |
| 1073 | let self = this; |
| 1074 | return new Promise((resolve, reject) => { |
| 1075 | self._accept(invitationToken, options, (err, result, request, response) => { |
| 1076 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 1077 | httpOperationResponse.body = result; |
| 1078 | if (err) { reject(err); } |
| 1079 | else { resolve(httpOperationResponse); } |
| 1080 | return; |
| 1081 | }); |
| 1082 | }); |
| 1083 | } |
| 1084 | |
| 1085 | /** |
| 1086 | * Accepts a pending organization invitation for the specified user |
| 1087 | * |
| 1088 | * @param {string} invitationToken The app invitation token that was sent to |
| 1089 | * the user |
| 1090 | * |
| 1091 | * @param {object} [options] Optional Parameters. |
| 1092 | * |
| 1093 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1094 | * request |
| 1095 | * |
| 1096 | * @param {function} [optionalCallback] - The optional callback. |
| 1097 | * |
| 1098 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 1099 | * then it returns the callback else returns a Promise. |
| 1100 | * |
| 1101 | * {Promise} A promise is returned |
| 1102 | * |
| 1103 | * @resolve {null} - The deserialized result object. |
| 1104 | * |
| 1105 | * @reject {Error} - The error object. |
| 1106 | * |
| 1107 | * {function} optionalCallback(err, result, request, response) |
| 1108 | * |
| 1109 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 1110 | * |
| 1111 | * {null} [result] - The deserialized result object if an error did not occur. |
| 1112 | * |
| 1113 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 1114 | * |
| 1115 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 1116 | */ |
| 1117 | accept(invitationToken, options, optionalCallback) { |
| 1118 | let client = this.client; |
| 1119 | let self = this; |
| 1120 | if (!optionalCallback && typeof options === 'function') { |
| 1121 | optionalCallback = options; |
| 1122 | options = null; |
| 1123 | } |
| 1124 | if (!optionalCallback) { |
| 1125 | return new Promise((resolve, reject) => { |
| 1126 | self._accept(invitationToken, options, (err, result, request, response) => { |
| 1127 | if (err) { reject(err); } |
| 1128 | else { resolve(result); } |
| 1129 | return; |
| 1130 | }); |
| 1131 | }); |
| 1132 | } else { |
| 1133 | return self._accept(invitationToken, options, optionalCallback); |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | /** |
| 1138 | * Rejects a pending organization invitation |
| 1139 | * |
| 1140 | * @param {string} invitationToken The app invitation token that was sent to |
| 1141 | * the user |
| 1142 | * |
| 1143 | * @param {object} [options] Optional Parameters. |
| 1144 | * |
| 1145 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1146 | * request |
| 1147 | * |
| 1148 | * @returns {Promise} A promise is returned |
| 1149 | * |
| 1150 | * @resolve {HttpOperationResponse<null>} - The deserialized result object. |
| 1151 | * |
| 1152 | * @reject {Error} - The error object. |
| 1153 | */ |
| 1154 | rejectWithHttpOperationResponse(invitationToken, options) { |
| 1155 | let client = this.client; |
| 1156 | let self = this; |
| 1157 | return new Promise((resolve, reject) => { |
| 1158 | self._reject(invitationToken, options, (err, result, request, response) => { |
| 1159 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 1160 | httpOperationResponse.body = result; |
| 1161 | if (err) { reject(err); } |
| 1162 | else { resolve(httpOperationResponse); } |
| 1163 | return; |
| 1164 | }); |
| 1165 | }); |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * Rejects a pending organization invitation |
| 1170 | * |
| 1171 | * @param {string} invitationToken The app invitation token that was sent to |
| 1172 | * the user |
| 1173 | * |
| 1174 | * @param {object} [options] Optional Parameters. |
| 1175 | * |
| 1176 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 1177 | * request |
| 1178 | * |
| 1179 | * @param {function} [optionalCallback] - The optional callback. |
| 1180 | * |
| 1181 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 1182 | * then it returns the callback else returns a Promise. |
| 1183 | * |
| 1184 | * {Promise} A promise is returned |
| 1185 | * |
| 1186 | * @resolve {null} - The deserialized result object. |
| 1187 | * |
| 1188 | * @reject {Error} - The error object. |
| 1189 | * |
| 1190 | * {function} optionalCallback(err, result, request, response) |
| 1191 | * |
| 1192 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 1193 | * |
| 1194 | * {null} [result] - The deserialized result object if an error did not occur. |
| 1195 | * |
| 1196 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 1197 | * |
| 1198 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 1199 | */ |
| 1200 | reject(invitationToken, options, optionalCallback) { |
| 1201 | let client = this.client; |
| 1202 | let self = this; |
| 1203 | if (!optionalCallback && typeof options === 'function') { |
| 1204 | optionalCallback = options; |
| 1205 | options = null; |
| 1206 | } |
| 1207 | if (!optionalCallback) { |
| 1208 | return new Promise((resolve, reject) => { |
| 1209 | self._reject(invitationToken, options, (err, result, request, response) => { |
| 1210 | if (err) { reject(err); } |
| 1211 | else { resolve(result); } |
| 1212 | return; |
| 1213 | }); |
| 1214 | }); |
| 1215 | } else { |
| 1216 | return self._reject(invitationToken, options, optionalCallback); |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | } |
| 1221 | |
| 1222 | module.exports = OrgInvitations; |
| 1223 | |