-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsRestBundle.js
4093 lines (3726 loc) · 199 KB
/
msRestBundle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var msRest =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 18);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(process) {
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const uuid = __webpack_require__(19);
const FormData = __webpack_require__(22);
const webResource_1 = __webpack_require__(3);
const constants_1 = __webpack_require__(2);
const restError_1 = __webpack_require__(8);
const httpOperationResponse_1 = __webpack_require__(9);
/**
* Provides the fetch() method based on the environment.
* @returns {fetch} fetch - The fetch() method available in the environment to make requests
*/
function getFetch() {
// using window.Fetch in Edge gives a TypeMismatchError
// (https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8546263/).
// Hence we will be using the fetch-ponyfill for Edge.
if (typeof window !== "undefined" && window.fetch && window.navigator &&
window.navigator.userAgent && window.navigator.userAgent.indexOf("Edge/") === -1) {
return window.fetch.bind(window);
}
return __webpack_require__(23)({ useCookie: true }).fetch;
}
exports.getFetch = getFetch;
/**
* A constant that provides the fetch() method based on the environment.
*/
exports.myFetch = getFetch();
/**
* A constant that indicates whether the environment is node.js or browser based.
*/
exports.isNode = typeof navigator === "undefined" && typeof process !== "undefined";
/**
* Checks if a parsed URL is HTTPS
*
* @param {object} urlToCheck The url to check
* @return {boolean} True if the URL is HTTPS; false otherwise.
*/
function urlIsHTTPS(urlToCheck) {
return urlToCheck.protocol.toLowerCase() === constants_1.Constants.HTTPS;
}
exports.urlIsHTTPS = urlIsHTTPS;
/**
* Checks if a value is null or undefined.
*
* @param {object} value The value to check for null or undefined.
* @return {boolean} True if the value is null or undefined, false otherwise.
*/
// TODO: Audit the usages of this and remove them.
// Read: https://medium.com/@basarat/null-vs-undefined-in-typescript-land-dc0c7a5f240a
// https://github.com/Microsoft/TypeScript/issues/7426
function objectIsNull(value) {
return value === null || value === undefined;
}
exports.objectIsNull = objectIsNull;
/**
* Encodes an URI.
*
* @param {string} uri The URI to be encoded.
* @return {string} The encoded URI.
*/
function encodeUri(uri) {
return encodeURIComponent(uri)
.replace(/!/g, "%21")
.replace(/"/g, "%27")
.replace(/\(/g, "%28")
.replace(/\)/g, "%29")
.replace(/\*/g, "%2A");
}
exports.encodeUri = encodeUri;
/**
* Returns a stripped version of the Http Response which only contains body,
* headers and the status.
*
* @param {nodeFetch.Response} response - The Http Response
*
* @return {object} strippedResponse - The stripped version of Http Response.
*/
function stripResponse(response) {
const strippedResponse = {};
strippedResponse.body = response.body;
strippedResponse.headers = response.headers;
strippedResponse.status = response.status;
return strippedResponse;
}
exports.stripResponse = stripResponse;
/**
* Returns a stripped version of the Http Request that does not contain the
* Authorization header.
*
* @param {object} request - The Http Request object
*
* @return {object} strippedRequest - The stripped version of Http Request.
*/
function stripRequest(request) {
let strippedRequest = new webResource_1.WebResource();
try {
strippedRequest = JSON.parse(JSON.stringify(request));
if (strippedRequest.headers && strippedRequest.headers.Authorization) {
delete strippedRequest.headers.Authorization;
}
else if (strippedRequest.headers && strippedRequest.headers.authorization) {
delete strippedRequest.headers.authorization;
}
}
catch (err) {
const errMsg = err.message;
err.message = `Error - "${errMsg}" occured while creating a stripped version of the request object - "${request}".`;
return err;
}
return strippedRequest;
}
exports.stripRequest = stripRequest;
/**
* Validates the given uuid as a string
*
* @param {string} uuid - The uuid as a string that needs to be validated
*
* @return {boolean} result - True if the uuid is valid; false otherwise.
*/
function isValidUuid(uuid) {
const validUuidRegex = new RegExp("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", "ig");
return validUuidRegex.test(uuid);
}
exports.isValidUuid = isValidUuid;
/**
* Provides an array of values of an object. For example
* for a given object { "a": "foo", "b": "bar" }, the method returns ["foo", "bar"].
*
* @param {object} obj - An object whose properties need to be enumerated so that it"s values can be provided as an array
*
* @return {array} result - An array of values of the given object.
*/
function objectValues(obj) {
const result = [];
if (obj && obj instanceof Object) {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
result.push(obj[key]);
}
}
}
else {
throw new Error(`The provided object ${JSON.stringify(obj, undefined, 2)} is not a valid object that can be ` +
`enumerated to provide its values as an array.`);
}
return result;
}
exports.objectValues = objectValues;
/**
* Generated UUID
*
* @return {string} RFC4122 v4 UUID.
*/
function generateUuid() {
return uuid.v4();
}
exports.generateUuid = generateUuid;
/*
* Executes an array of promises sequentially. Inspiration of this method is here:
* https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html. An awesome blog on promises!
*
* @param {Array} promiseFactories An array of promise factories(A function that return a promise)
*
* @param {any} [kickstart] Input to the first promise that is used to kickstart the promise chain.
* If not provided then the promise chain starts with undefined.
*
* @return A chain of resolved or rejected promises
*/
function executePromisesSequentially(promiseFactories, kickstart) {
let result = Promise.resolve(kickstart);
promiseFactories.forEach((promiseFactory) => {
result = result.then(promiseFactory);
});
return result;
}
exports.executePromisesSequentially = executePromisesSequentially;
/*
* Merges source object into the target object
* @param {object} source The object that needs to be merged
*
* @param {object} target The object to be merged into
*
* @returns {object} target - Returns the merged target object.
*/
function mergeObjects(source, target) {
Object.keys(source).forEach((key) => {
target[key] = source[key];
});
return target;
}
exports.mergeObjects = mergeObjects;
/**
* A wrapper for setTimeout that resolves a promise after t milliseconds.
* @param {number} t - The number of milliseconds to be delayed.
* @param {T} value - The value to be resolved with after a timeout of t milliseconds.
* @returns {Promise<T>} - Resolved promise
*/
function delay(t, value) {
return new Promise((resolve) => setTimeout(() => resolve(value), t));
}
exports.delay = delay;
/**
* Utility function to create a K:V from a list of strings
*/
function strEnum(o) {
/* tslint:disable:no-null-keyword */
return o.reduce((res, key) => {
res[key] = key;
return res;
}, Object.create(null));
/* tslint:enable:no-null-keyword */
}
exports.strEnum = strEnum;
/**
* Converts a Promise to a callback.
* @param {Promise<any>} promise - The Promise to be converted to a callback
* @returns {Function} fn - A function that takes the callback (cb: Function): void
*/
function promiseToCallback(promise) {
if (typeof promise.then !== "function") {
throw new Error("The provided input is not a Promise.");
}
return (cb) => {
promise.then((data) => {
process.nextTick(cb, undefined, data);
}, (err) => {
process.nextTick(cb, err);
});
};
}
exports.promiseToCallback = promiseToCallback;
/**
* Converts a Promise to a service callback.
* @param {Promise<HttpOperationResponse>} promise - The Promise of HttpOperationResponse to be converted to a service callback
* @returns {Function} fn - A function that takes the service callback (cb: ServiceCallback<T>): void
*/
function promiseToServiceCallback(promise) {
if (typeof promise.then !== "function") {
throw new Error("The provided input is not a Promise.");
}
return (cb) => {
promise.then((data) => {
process.nextTick(cb, undefined, data.bodyAsJson, data.request, data.response);
}, (err) => {
process.nextTick(cb, err);
});
};
}
exports.promiseToServiceCallback = promiseToServiceCallback;
/**
* Sends the request and returns the received response.
* @param {WebResource} options - The request to be sent.
* @returns {Promise<HttpOperationResponse} operationResponse - The response object.
*/
function dispatchRequest(options) {
return __awaiter(this, void 0, void 0, function* () {
if (!options) {
return Promise.reject(new Error("options (WebResource) cannot be null or undefined and must be of type object."));
}
if (options.formData) {
const formData = options.formData;
const requestForm = new FormData();
const appendFormValue = (key, value) => {
if (value && value.hasOwnProperty("value") && value.hasOwnProperty("options")) {
requestForm.append(key, value.value, value.options);
}
else {
requestForm.append(key, value);
}
};
for (const formKey in formData) {
if (formData.hasOwnProperty(formKey)) {
const formValue = formData[formKey];
if (formValue instanceof Array) {
for (let j = 0; j < formValue.length; j++) {
appendFormValue(formKey, formValue[j]);
}
}
else {
appendFormValue(formKey, formValue);
}
}
}
options.body = requestForm;
options.formData = undefined;
if (options.headers && options.headers["Content-Type"] &&
options.headers["Content-Type"].indexOf("multipart/form-data") > -1 && typeof requestForm.getBoundary === "function") {
options.headers["Content-Type"] = `multipart/form-data; boundary=${requestForm.getBoundary()}`;
}
}
let res;
try {
res = yield exports.myFetch(options.url, options);
}
catch (err) {
return Promise.reject(err);
}
const operationResponse = new httpOperationResponse_1.HttpOperationResponse(options, res);
if (!options.rawResponse) {
try {
operationResponse.bodyAsText = yield res.text();
}
catch (err) {
const msg = `Error "${err}" occured while converting the raw response body into string.`;
const errCode = err.code || "RAWTEXT_CONVERSION_ERROR";
const e = new restError_1.RestError(msg, errCode, res.status, options, res, res.body);
return Promise.reject(e);
}
try {
if (operationResponse.bodyAsText) {
operationResponse.bodyAsJson = JSON.parse(operationResponse.bodyAsText);
}
}
catch (err) {
const msg = `Error "${err}" occured while executing JSON.parse on the response body - ${operationResponse.bodyAsText}.`;
const errCode = err.code || "JSON_PARSE_ERROR";
const e = new restError_1.RestError(msg, errCode, res.status, options, res, operationResponse.bodyAsText);
return Promise.reject(e);
}
}
return Promise.resolve(operationResponse);
});
}
exports.dispatchRequest = dispatchRequest;
/**
* Applies the properties on the prototype of sourceCtors to the prototype of targetCtor
* @param {object} targetCtor The target object on which the properties need to be applied.
* @param {Array<object>} sourceCtors An array of source objects from which the properties need to be taken.
*/
function applyMixins(targetCtor, sourceCtors) {
sourceCtors.forEach(sourceCtors => {
Object.getOwnPropertyNames(sourceCtors.prototype).forEach(name => {
targetCtor.prototype[name] = sourceCtors.prototype[name];
});
});
}
exports.applyMixins = applyMixins;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)))
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
class BaseFilter {
constructor() { }
before(request) {
return Promise.resolve(request);
}
after(response) {
return Promise.resolve(response);
}
}
exports.BaseFilter = BaseFilter;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Constants = {
/**
* The ms-rest version
* @const
* @type {string}
*/
msRestVersion: "0.1.0",
/**
* Specifies HTTP.
*
* @const
* @type {string}
*/
HTTP: "http:",
/**
* Specifies HTTPS.
*
* @const
* @type {string}
*/
HTTPS: "https:",
/**
* Specifies HTTP Proxy.
*
* @const
* @type {string}
*/
HTTP_PROXY: "HTTP_PROXY",
/**
* Specifies HTTPS Proxy.
*
* @const
* @type {string}
*/
HTTPS_PROXY: "HTTPS_PROXY",
HttpConstants: {
/**
* Http Verbs
*
* @const
* @enum {string}
*/
HttpVerbs: {
PUT: "PUT",
GET: "GET",
DELETE: "DELETE",
POST: "POST",
MERGE: "MERGE",
HEAD: "HEAD",
PATCH: "PATCH"
},
},
/**
* Defines constants for use with HTTP headers.
*/
HeaderConstants: {
/**
* The Authorization header.
*
* @const
* @type {string}
*/
AUTHORIZATION: "authorization",
AUTHORIZATION_SCHEME: "Bearer",
/**
* The UserAgent header.
*
* @const
* @type {string}
*/
USER_AGENT: "User-Agent"
}
};
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = __webpack_require__(0);
const serializer_1 = __webpack_require__(10);
/**
* Creates a new WebResource object.
*
* This class provides an abstraction over a REST call by being library / implementation agnostic and wrapping the necessary
* properties to initiate a request.
*
* @constructor
*/
class WebResource {
constructor(url, method, body, query, headers = {}, rawResponse = false) {
this.headers = {};
this.rawResponse = rawResponse;
this.url = url || "";
this.method = method || "GET";
this.headers = headers || {};
this.body = body;
this.query = query;
this.formData = undefined;
}
/**
* Validates that the required properties such as method, url, headers["Content-Type"],
* headers["accept-language"] are defined. It will throw an error if one of the above
* mentioned properties are not defined.
*/
validateRequestProperties() {
if (!this.method || !this.url || !this.headers["Content-Type"] || !this.headers["accept-language"]) {
throw new Error("method, url, headers[\"Content-Type\"], headers[\"accept-language\"] are " +
"required properties before making a request. Either provide them or use WebResource.prepare() method.");
}
return;
}
/**
* Prepares the request.
* @param {RequestPrepareOptions} options - Options to provide for preparing the request.
* @returns {object} WebResource Returns the prepared WebResource (HTTP Request) object that needs to be given to the request pipeline.
*/
prepare(options) {
if (options === null || options === undefined || typeof options !== "object") {
throw new Error("options cannot be null or undefined and must be of type object");
}
if (options.method === null || options.method === undefined || typeof options.method.valueOf() !== "string") {
throw new Error("options.method cannot be null or undefined and it must be of type string.");
}
if (options.url && options.pathTemplate) {
throw new Error("options.url and options.pathTemplate are mutually exclusive. Please provide either of them.");
}
if ((options.pathTemplate === null || options.pathTemplate === undefined || typeof options.pathTemplate.valueOf() !== "string") && (options.url === null || options.url === undefined || typeof options.url.valueOf() !== "string")) {
throw new Error("Please provide either options.pathTemplate or options.url. Currently none of them were provided.");
}
// set the url if it is provided.
if (options.url) {
if (typeof options.url !== "string") {
throw new Error("options.url must be of type \"string\".");
}
this.url = options.url;
}
// set the method
if (options.method) {
const validMethods = ["GET", "PUT", "HEAD", "DELETE", "OPTIONS", "POST", "PATCH", "TRACE"];
if (validMethods.indexOf(options.method.toUpperCase()) === -1) {
throw new Error("The provided method \"" + options.method + "\" is invalid. Supported HTTP methods are: " + JSON.stringify(validMethods));
}
}
this.method = options.method.toUpperCase();
// construct the url if path template is provided
if (options.pathTemplate) {
if (typeof options.pathTemplate !== "string") {
throw new Error("options.pathTemplate must be of type \"string\".");
}
if (!options.baseUrl) {
options.baseUrl = "https://management.azure.com";
}
const baseUrl = options.baseUrl;
let url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + (options.pathTemplate.startsWith("/") ? options.pathTemplate.slice(1) : options.pathTemplate);
const segments = url.match(/({\w*\s*\w*})/ig);
if (segments && segments.length) {
if (options.pathParameters === null || options.pathParameters === undefined || typeof options.pathParameters !== "object") {
throw new Error(`pathTemplate: ${options.pathTemplate} has been provided. Hence, options.pathParameters ` +
`cannot be null or undefined and must be of type "object".`);
}
segments.forEach(function (item) {
const pathParamName = item.slice(1, -1);
const pathParam = options.pathParameters[pathParamName];
if (pathParam === null || pathParam === undefined || !(typeof pathParam === "string" || typeof pathParam === "object")) {
throw new Error(`pathTemplate: ${options.pathTemplate} contains the path parameter ${pathParamName}` +
` however, it is not present in ${options.pathParameters} - ${JSON.stringify(options.pathParameters, undefined, 2)}.` +
`The value of the path parameter can either be a "string" of the form { ${pathParamName}: "some sample value" } or ` +
`it can be an "object" of the form { "${pathParamName}": { value: "some sample value", skipUrlEncoding: true } }.`);
}
if (typeof pathParam.valueOf() === "string") {
url = url.replace(item, encodeURIComponent(pathParam));
}
if (typeof pathParam.valueOf() === "object") {
if (!pathParam.value) {
throw new Error(`options.pathParameters[${pathParamName}] is of type "object" but it does not contain a "value" property.`);
}
if (pathParam.skipUrlEncoding) {
url = url.replace(item, pathParam.value);
}
else {
url = url.replace(item, encodeURIComponent(pathParam.value));
}
}
});
}
this.url = url;
}
// append query parameters to the url if they are provided. They can be provided with pathTemplate or url option.
if (options.queryParameters) {
if (typeof options.queryParameters !== "object") {
throw new Error(`options.queryParameters must be of type object. It should be a JSON object ` +
`of "query-parameter-name" as the key and the "query-parameter-value" as the value. ` +
`The "query-parameter-value" may be fo type "string" or an "object" of the form { value: "query-parameter-value", skipUrlEncoding: true }.`);
}
// append question mark if it is not present in the url
if (this.url && this.url.indexOf("?") === -1) {
this.url += "?";
}
// construct queryString
const queryParams = [];
const queryParameters = options.queryParameters;
// We need to populate this.query as a dictionary if the request is being used for Sway's validateRequest().
this.query = {};
for (const queryParamName in queryParameters) {
const queryParam = queryParameters[queryParamName];
if (queryParam) {
if (typeof queryParam === "string") {
queryParams.push(queryParamName + "=" + encodeURIComponent(queryParam));
this.query[queryParamName] = encodeURIComponent(queryParam);
}
else if (typeof queryParam === "object") {
if (!queryParam.value) {
throw new Error(`options.queryParameters[${queryParamName}] is of type "object" but it does not contain a "value" property.`);
}
if (queryParam.skipUrlEncoding) {
queryParams.push(queryParamName + "=" + queryParam.value);
this.query[queryParamName] = queryParam.value;
}
else {
queryParams.push(queryParamName + "=" + encodeURIComponent(queryParam.value));
this.query[queryParamName] = encodeURIComponent(queryParam.value);
}
}
}
} // end-of-for
// append the queryString
this.url += queryParams.join("&");
}
// add headers to the request if they are provided
if (options.headers) {
const headers = options.headers;
for (const headerName in headers) {
if (headers.hasOwnProperty(headerName)) {
this.headers[headerName] = headers[headerName];
}
}
}
// ensure accept-language is set correctly
if (!this.headers["accept-language"]) {
this.headers["accept-language"] = "en-US";
}
// ensure the request-id is set correctly
if (!this.headers["x-ms-client-request-id"] && !options.disableClientRequestId) {
this.headers["x-ms-client-request-id"] = utils_1.generateUuid();
}
// default
if (!this.headers["Content-Type"]) {
this.headers["Content-Type"] = "application/json; charset=utf-8";
}
// set the request body. request.js automatically sets the Content-Length request header, so we need not set it explicilty
this.body = undefined;
if (options.body !== null && options.body !== undefined) {
// body as a stream special case. set the body as-is and check for some special request headers specific to sending a stream.
if (options.bodyIsStream) {
this.body = options.body;
if (!this.headers["Transfer-Encoding"]) {
this.headers["Transfer-Encoding"] = "chunked";
}
if (this.headers["Content-Type"] !== "application/octet-stream") {
this.headers["Content-Type"] = "application/octet-stream";
}
}
else {
let serializedBody = undefined;
if (options.serializationMapper) {
serializedBody = new serializer_1.Serializer(options.mappers).serialize(options.serializationMapper, options.body, "requestBody");
}
if (options.disableJsonStringifyOnBody) {
this.body = serializedBody || options.body;
}
else {
this.body = serializedBody ? JSON.stringify(serializedBody) : JSON.stringify(options.body);
}
}
}
return this;
}
}
exports.WebResource = WebResource;
/***/ }),
/* 4 */
/***/ (function(module, exports) {
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] }
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {// Unique ID creation requires a high quality random # generator. In the
// browser this is a little complicated due to unknown quality of Math.random()
// and inconsistent support for the `crypto` API. We do the best we can via
// feature-detection
var rng;
var crypto = global.crypto || global.msCrypto; // for IE 11
if (crypto && crypto.getRandomValues) {
// WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef
rng = function whatwgRNG() {
crypto.getRandomValues(rnds8);
return rnds8;
};
}
if (!rng) {
// Math.random()-based (RNG)
//
// If all else fails, use Math.random(). It's fast, but is of unspecified
// quality.
var rnds = new Array(16);
rng = function() {
for (var i = 0, r; i < 16; i++) {
if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
}
return rnds;
};
}
module.exports = rng;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(6)))
/***/ }),
/* 6 */
/***/ (function(module, exports) {
var g;
// This works in non-strict mode
g = (function() {
return this;
})();
try {
// This works if eval is allowed (see CSP)
g = g || Function("return this")() || (1,eval)("this");
} catch(e) {
// This works if the window reference is available
if(typeof window === "object")
g = window;
}
// g can still be undefined, but nothing to do about it...
// We return undefined, instead of nothing here, so it's
// easier to handle this case. if(!global) { ...}
module.exports = g;
/***/ }),
/* 7 */
/***/ (function(module, exports) {
/**