1 |
|
2 |
|
3 |
|
4 |
|
5 | 'use strict';
|
6 |
|
7 | Object.defineProperty(exports, '__esModule', { value: true });
|
8 |
|
9 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
10 |
|
11 | var uuid = require('uuid');
|
12 | var tslib = require('tslib');
|
13 | var http = require('http');
|
14 | var https = require('https');
|
15 | var node_fetch = _interopDefault(require('node-fetch'));
|
16 | var FormData = _interopDefault(require('form-data'));
|
17 | var stream = require('stream');
|
18 | var tunnel = require('tunnel');
|
19 | var xml2js = require('xml2js');
|
20 | var os = require('os');
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | function getHeaderKey(headerName) {
|
28 | return headerName.toLowerCase();
|
29 | }
|
30 | function isHttpHeadersLike(object) {
|
31 | if (!object || typeof object !== "object") {
|
32 | return false;
|
33 | }
|
34 | if (typeof object.rawHeaders === "function" &&
|
35 | typeof object.clone === "function" &&
|
36 | typeof object.get === "function" &&
|
37 | typeof object.set === "function" &&
|
38 | typeof object.contains === "function" &&
|
39 | typeof object.remove === "function" &&
|
40 | typeof object.headersArray === "function" &&
|
41 | typeof object.headerValues === "function" &&
|
42 | typeof object.headerNames === "function" &&
|
43 | typeof object.toJson === "function") {
|
44 | return true;
|
45 | }
|
46 | return false;
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 | var HttpHeaders = (function () {
|
52 | function HttpHeaders(rawHeaders) {
|
53 | this._headersMap = {};
|
54 | if (rawHeaders) {
|
55 | for (var headerName in rawHeaders) {
|
56 | this.set(headerName, rawHeaders[headerName]);
|
57 | }
|
58 | }
|
59 | }
|
60 | |
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | HttpHeaders.prototype.set = function (headerName, headerValue) {
|
67 | this._headersMap[getHeaderKey(headerName)] = {
|
68 | name: headerName,
|
69 | value: headerValue.toString(),
|
70 | };
|
71 | };
|
72 | |
73 |
|
74 |
|
75 |
|
76 |
|
77 | HttpHeaders.prototype.get = function (headerName) {
|
78 | var header = this._headersMap[getHeaderKey(headerName)];
|
79 | return !header ? undefined : header.value;
|
80 | };
|
81 | |
82 |
|
83 |
|
84 | HttpHeaders.prototype.contains = function (headerName) {
|
85 | return !!this._headersMap[getHeaderKey(headerName)];
|
86 | };
|
87 | |
88 |
|
89 |
|
90 |
|
91 |
|
92 | HttpHeaders.prototype.remove = function (headerName) {
|
93 | var result = this.contains(headerName);
|
94 | delete this._headersMap[getHeaderKey(headerName)];
|
95 | return result;
|
96 | };
|
97 | |
98 |
|
99 |
|
100 | HttpHeaders.prototype.rawHeaders = function () {
|
101 | var result = {};
|
102 | for (var headerKey in this._headersMap) {
|
103 | var header = this._headersMap[headerKey];
|
104 | result[header.name.toLowerCase()] = header.value;
|
105 | }
|
106 | return result;
|
107 | };
|
108 | |
109 |
|
110 |
|
111 | HttpHeaders.prototype.headersArray = function () {
|
112 | var headers = [];
|
113 | for (var headerKey in this._headersMap) {
|
114 | headers.push(this._headersMap[headerKey]);
|
115 | }
|
116 | return headers;
|
117 | };
|
118 | |
119 |
|
120 |
|
121 | HttpHeaders.prototype.headerNames = function () {
|
122 | var headerNames = [];
|
123 | var headers = this.headersArray();
|
124 | for (var i = 0; i < headers.length; ++i) {
|
125 | headerNames.push(headers[i].name);
|
126 | }
|
127 | return headerNames;
|
128 | };
|
129 | |
130 |
|
131 |
|
132 | HttpHeaders.prototype.headerValues = function () {
|
133 | var headerValues = [];
|
134 | var headers = this.headersArray();
|
135 | for (var i = 0; i < headers.length; ++i) {
|
136 | headerValues.push(headers[i].value);
|
137 | }
|
138 | return headerValues;
|
139 | };
|
140 | |
141 |
|
142 |
|
143 | HttpHeaders.prototype.toJson = function () {
|
144 | return this.rawHeaders();
|
145 | };
|
146 | |
147 |
|
148 |
|
149 | HttpHeaders.prototype.toString = function () {
|
150 | return JSON.stringify(this.toJson());
|
151 | };
|
152 | |
153 |
|
154 |
|
155 | HttpHeaders.prototype.clone = function () {
|
156 | return new HttpHeaders(this.rawHeaders());
|
157 | };
|
158 | return HttpHeaders;
|
159 | }());
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 | function encodeString(value) {
|
168 | return Buffer.from(value).toString("base64");
|
169 | }
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | function encodeByteArray(value) {
|
175 |
|
176 |
|
177 | var bufferValue = value instanceof Buffer ? value : Buffer.from(value.buffer);
|
178 | return bufferValue.toString("base64");
|
179 | }
|
180 |
|
181 |
|
182 |
|
183 |
|
184 | function decodeString(value) {
|
185 | return Buffer.from(value, "base64");
|
186 | }
|
187 |
|
188 |
|
189 |
|
190 | var Constants = {
|
191 | |
192 |
|
193 |
|
194 |
|
195 |
|
196 | msRestVersion: "2.7.0",
|
197 | |
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 | HTTP: "http:",
|
204 | |
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 | HTTPS: "https:",
|
211 | |
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 | HTTP_PROXY: "HTTP_PROXY",
|
218 | |
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 | HTTPS_PROXY: "HTTPS_PROXY",
|
225 | |
226 |
|
227 |
|
228 | NO_PROXY: "NO_PROXY",
|
229 | |
230 |
|
231 |
|
232 | ALL_PROXY: "ALL_PROXY",
|
233 | HttpConstants: {
|
234 | |
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 | HttpVerbs: {
|
241 | PUT: "PUT",
|
242 | GET: "GET",
|
243 | DELETE: "DELETE",
|
244 | POST: "POST",
|
245 | MERGE: "MERGE",
|
246 | HEAD: "HEAD",
|
247 | PATCH: "PATCH",
|
248 | },
|
249 | StatusCodes: {
|
250 | TooManyRequests: 429,
|
251 | },
|
252 | },
|
253 | |
254 |
|
255 |
|
256 | HeaderConstants: {
|
257 | |
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 | AUTHORIZATION: "authorization",
|
264 | AUTHORIZATION_SCHEME: "Bearer",
|
265 | |
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 | RETRY_AFTER: "Retry-After",
|
274 | |
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 | USER_AGENT: "User-Agent",
|
281 | },
|
282 | };
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 | var isNode = typeof process !== "undefined" &&
|
289 | !!process.version &&
|
290 | !!process.versions &&
|
291 | !!process.versions.node;
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 | function encodeUri(uri) {
|
299 | return encodeURIComponent(uri)
|
300 | .replace(/!/g, "%21")
|
301 | .replace(/"/g, "%27")
|
302 | .replace(/\(/g, "%28")
|
303 | .replace(/\)/g, "%29")
|
304 | .replace(/\*/g, "%2A");
|
305 | }
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 | function stripResponse(response) {
|
315 | var strippedResponse = {};
|
316 | strippedResponse.body = response.bodyAsText;
|
317 | strippedResponse.headers = response.headers;
|
318 | strippedResponse.status = response.status;
|
319 | return strippedResponse;
|
320 | }
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 | function stripRequest(request) {
|
330 | var strippedRequest = request.clone();
|
331 | if (strippedRequest.headers) {
|
332 | strippedRequest.headers.remove("authorization");
|
333 | }
|
334 | return strippedRequest;
|
335 | }
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 | function isValidUuid(uuid) {
|
344 | var 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");
|
345 | return validUuidRegex.test(uuid);
|
346 | }
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 | function generateUuid() {
|
353 | return uuid.v4();
|
354 | }
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 | function executePromisesSequentially(promiseFactories, kickstart) {
|
367 | var result = Promise.resolve(kickstart);
|
368 | promiseFactories.forEach(function (promiseFactory) {
|
369 | result = result.then(promiseFactory);
|
370 | });
|
371 | return result;
|
372 | }
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 | function delay(t, value) {
|
380 | return new Promise(function (resolve) { return setTimeout(function () { return resolve(value); }, t); });
|
381 | }
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 | function promiseToCallback(promise) {
|
389 | if (typeof promise.then !== "function") {
|
390 | throw new Error("The provided input is not a Promise.");
|
391 | }
|
392 | return function (cb) {
|
393 | promise.then(function (data) {
|
394 | cb(undefined, data);
|
395 | }, function (err) {
|
396 | cb(err);
|
397 | });
|
398 | };
|
399 | }
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 | function promiseToServiceCallback(promise) {
|
406 | if (typeof promise.then !== "function") {
|
407 | throw new Error("The provided input is not a Promise.");
|
408 | }
|
409 | return function (cb) {
|
410 | promise.then(function (data) {
|
411 | process.nextTick(cb, undefined, data.parsedBody, data.request, data);
|
412 | }, function (err) {
|
413 | process.nextTick(cb, err);
|
414 | });
|
415 | };
|
416 | }
|
417 | function prepareXMLRootList(obj, elementName) {
|
418 | var _a;
|
419 | if (!Array.isArray(obj)) {
|
420 | obj = [obj];
|
421 | }
|
422 | return _a = {}, _a[elementName] = obj, _a;
|
423 | }
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 | function applyMixins(targetCtor, sourceCtors) {
|
430 | sourceCtors.forEach(function (sourceCtors) {
|
431 | Object.getOwnPropertyNames(sourceCtors.prototype).forEach(function (name) {
|
432 | targetCtor.prototype[name] = sourceCtors.prototype[name];
|
433 | });
|
434 | });
|
435 | }
|
436 | var validateISODuration = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 | function isDuration(value) {
|
443 | return validateISODuration.test(value);
|
444 | }
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 | function replaceAll(value, searchValue, replaceValue) {
|
453 | return !value || !searchValue ? value : value.split(searchValue).join(replaceValue || "");
|
454 | }
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 | function isPrimitiveType(value) {
|
462 | return (typeof value !== "object" && typeof value !== "function") || value === null;
|
463 | }
|
464 |
|
465 |
|
466 | var Serializer = (function () {
|
467 | function Serializer(modelMappers, isXML) {
|
468 | if (modelMappers === void 0) { modelMappers = {}; }
|
469 | this.modelMappers = modelMappers;
|
470 | this.isXML = isXML;
|
471 | }
|
472 | Serializer.prototype.validateConstraints = function (mapper, value, objectName) {
|
473 | var failValidation = function (constraintName, constraintValue) {
|
474 | throw new Error("\"" + objectName + "\" with value \"" + value + "\" should satisfy the constraint \"" + constraintName + "\": " + constraintValue + ".");
|
475 | };
|
476 | if (mapper.constraints && value != undefined) {
|
477 | var _a = mapper.constraints, ExclusiveMaximum = _a.ExclusiveMaximum, ExclusiveMinimum = _a.ExclusiveMinimum, InclusiveMaximum = _a.InclusiveMaximum, InclusiveMinimum = _a.InclusiveMinimum, MaxItems = _a.MaxItems, MaxLength = _a.MaxLength, MinItems = _a.MinItems, MinLength = _a.MinLength, MultipleOf = _a.MultipleOf, Pattern = _a.Pattern, UniqueItems = _a.UniqueItems;
|
478 | if (ExclusiveMaximum != undefined && value >= ExclusiveMaximum) {
|
479 | failValidation("ExclusiveMaximum", ExclusiveMaximum);
|
480 | }
|
481 | if (ExclusiveMinimum != undefined && value <= ExclusiveMinimum) {
|
482 | failValidation("ExclusiveMinimum", ExclusiveMinimum);
|
483 | }
|
484 | if (InclusiveMaximum != undefined && value > InclusiveMaximum) {
|
485 | failValidation("InclusiveMaximum", InclusiveMaximum);
|
486 | }
|
487 | if (InclusiveMinimum != undefined && value < InclusiveMinimum) {
|
488 | failValidation("InclusiveMinimum", InclusiveMinimum);
|
489 | }
|
490 | if (MaxItems != undefined && value.length > MaxItems) {
|
491 | failValidation("MaxItems", MaxItems);
|
492 | }
|
493 | if (MaxLength != undefined && value.length > MaxLength) {
|
494 | failValidation("MaxLength", MaxLength);
|
495 | }
|
496 | if (MinItems != undefined && value.length < MinItems) {
|
497 | failValidation("MinItems", MinItems);
|
498 | }
|
499 | if (MinLength != undefined && value.length < MinLength) {
|
500 | failValidation("MinLength", MinLength);
|
501 | }
|
502 | if (MultipleOf != undefined && value % MultipleOf !== 0) {
|
503 | failValidation("MultipleOf", MultipleOf);
|
504 | }
|
505 | if (Pattern) {
|
506 | var pattern = typeof Pattern === "string" ? new RegExp(Pattern) : Pattern;
|
507 | if (typeof value !== "string" || value.match(pattern) === null) {
|
508 | failValidation("Pattern", Pattern);
|
509 | }
|
510 | }
|
511 | if (UniqueItems &&
|
512 | value.some(function (item, i, ar) { return ar.indexOf(item) !== i; })) {
|
513 | failValidation("UniqueItems", UniqueItems);
|
514 | }
|
515 | }
|
516 | };
|
517 | |
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 | Serializer.prototype.serialize = function (mapper, object, objectName) {
|
529 | var payload = {};
|
530 | var mapperType = mapper.type.name;
|
531 | if (!objectName) {
|
532 | objectName = mapper.serializedName;
|
533 | }
|
534 | if (mapperType.match(/^Sequence$/gi) !== null) {
|
535 | payload = [];
|
536 | }
|
537 | if (mapper.isConstant) {
|
538 | object = mapper.defaultValue;
|
539 | }
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 | var required = mapper.required, nullable = mapper.nullable;
|
550 | if (required && nullable && object === undefined) {
|
551 | throw new Error(objectName + " cannot be undefined.");
|
552 | }
|
553 | if (required && !nullable && object == undefined) {
|
554 | throw new Error(objectName + " cannot be null or undefined.");
|
555 | }
|
556 | if (!required && nullable === false && object === null) {
|
557 | throw new Error(objectName + " cannot be null.");
|
558 | }
|
559 | if (object == undefined) {
|
560 | payload = object;
|
561 | }
|
562 | else {
|
563 |
|
564 | this.validateConstraints(mapper, object, objectName);
|
565 | if (mapperType.match(/^any$/gi) !== null) {
|
566 | payload = object;
|
567 | }
|
568 | else if (mapperType.match(/^(Number|String|Boolean|Object|Stream|Uuid)$/gi) !== null) {
|
569 | payload = serializeBasicTypes(mapperType, objectName, object);
|
570 | }
|
571 | else if (mapperType.match(/^Enum$/gi) !== null) {
|
572 | var enumMapper = mapper;
|
573 | payload = serializeEnumType(objectName, enumMapper.type.allowedValues, object);
|
574 | }
|
575 | else if (mapperType.match(/^(Date|DateTime|TimeSpan|DateTimeRfc1123|UnixTime)$/gi) !== null) {
|
576 | payload = serializeDateTypes(mapperType, object, objectName);
|
577 | }
|
578 | else if (mapperType.match(/^ByteArray$/gi) !== null) {
|
579 | payload = serializeByteArrayType(objectName, object);
|
580 | }
|
581 | else if (mapperType.match(/^Base64Url$/gi) !== null) {
|
582 | payload = serializeBase64UrlType(objectName, object);
|
583 | }
|
584 | else if (mapperType.match(/^Sequence$/gi) !== null) {
|
585 | payload = serializeSequenceType(this, mapper, object, objectName);
|
586 | }
|
587 | else if (mapperType.match(/^Dictionary$/gi) !== null) {
|
588 | payload = serializeDictionaryType(this, mapper, object, objectName);
|
589 | }
|
590 | else if (mapperType.match(/^Composite$/gi) !== null) {
|
591 | payload = serializeCompositeType(this, mapper, object, objectName);
|
592 | }
|
593 | }
|
594 | return payload;
|
595 | };
|
596 | |
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 | Serializer.prototype.deserialize = function (mapper, responseBody, objectName) {
|
608 | if (responseBody == undefined) {
|
609 | if (this.isXML && mapper.type.name === "Sequence" && !mapper.xmlIsWrapped) {
|
610 |
|
611 |
|
612 |
|
613 | responseBody = [];
|
614 | }
|
615 |
|
616 | if (mapper.defaultValue !== undefined) {
|
617 | responseBody = mapper.defaultValue;
|
618 | }
|
619 | return responseBody;
|
620 | }
|
621 | var payload;
|
622 | var mapperType = mapper.type.name;
|
623 | if (!objectName) {
|
624 | objectName = mapper.serializedName;
|
625 | }
|
626 | if (mapperType.match(/^Composite$/gi) !== null) {
|
627 | payload = deserializeCompositeType(this, mapper, responseBody, objectName);
|
628 | }
|
629 | else {
|
630 | if (this.isXML) {
|
631 | |
632 |
|
633 |
|
634 |
|
635 |
|
636 | if (responseBody["$"] != undefined && responseBody["_"] != undefined) {
|
637 | responseBody = responseBody["_"];
|
638 | }
|
639 | }
|
640 | if (mapperType.match(/^Number$/gi) !== null) {
|
641 | payload = parseFloat(responseBody);
|
642 | if (isNaN(payload)) {
|
643 | payload = responseBody;
|
644 | }
|
645 | }
|
646 | else if (mapperType.match(/^Boolean$/gi) !== null) {
|
647 | if (responseBody === "true") {
|
648 | payload = true;
|
649 | }
|
650 | else if (responseBody === "false") {
|
651 | payload = false;
|
652 | }
|
653 | else {
|
654 | payload = responseBody;
|
655 | }
|
656 | }
|
657 | else if (mapperType.match(/^(String|Enum|Object|Stream|Uuid|TimeSpan|any)$/gi) !== null) {
|
658 | payload = responseBody;
|
659 | }
|
660 | else if (mapperType.match(/^(Date|DateTime|DateTimeRfc1123)$/gi) !== null) {
|
661 | payload = new Date(responseBody);
|
662 | }
|
663 | else if (mapperType.match(/^UnixTime$/gi) !== null) {
|
664 | payload = unixTimeToDate(responseBody);
|
665 | }
|
666 | else if (mapperType.match(/^ByteArray$/gi) !== null) {
|
667 | payload = decodeString(responseBody);
|
668 | }
|
669 | else if (mapperType.match(/^Base64Url$/gi) !== null) {
|
670 | payload = base64UrlToByteArray(responseBody);
|
671 | }
|
672 | else if (mapperType.match(/^Sequence$/gi) !== null) {
|
673 | payload = deserializeSequenceType(this, mapper, responseBody, objectName);
|
674 | }
|
675 | else if (mapperType.match(/^Dictionary$/gi) !== null) {
|
676 | payload = deserializeDictionaryType(this, mapper, responseBody, objectName);
|
677 | }
|
678 | }
|
679 | if (mapper.isConstant) {
|
680 | payload = mapper.defaultValue;
|
681 | }
|
682 | return payload;
|
683 | };
|
684 | return Serializer;
|
685 | }());
|
686 | function trimEnd(str, ch) {
|
687 | var len = str.length;
|
688 | while (len - 1 >= 0 && str[len - 1] === ch) {
|
689 | --len;
|
690 | }
|
691 | return str.substr(0, len);
|
692 | }
|
693 | function bufferToBase64Url(buffer) {
|
694 | if (!buffer) {
|
695 | return undefined;
|
696 | }
|
697 | if (!(buffer instanceof Uint8Array)) {
|
698 | throw new Error("Please provide an input of type Uint8Array for converting to Base64Url.");
|
699 | }
|
700 |
|
701 | var str = encodeByteArray(buffer);
|
702 |
|
703 | return trimEnd(str, "=").replace(/\+/g, "-").replace(/\//g, "_");
|
704 | }
|
705 | function base64UrlToByteArray(str) {
|
706 | if (!str) {
|
707 | return undefined;
|
708 | }
|
709 | if (str && typeof str.valueOf() !== "string") {
|
710 | throw new Error("Please provide an input of type string for converting to Uint8Array");
|
711 | }
|
712 |
|
713 | str = str.replace(/\-/g, "+").replace(/\_/g, "/");
|
714 |
|
715 | return decodeString(str);
|
716 | }
|
717 | function splitSerializeName(prop) {
|
718 | var classes = [];
|
719 | var partialclass = "";
|
720 | if (prop) {
|
721 | var subwords = prop.split(".");
|
722 | for (var _i = 0, subwords_1 = subwords; _i < subwords_1.length; _i++) {
|
723 | var item = subwords_1[_i];
|
724 | if (item.charAt(item.length - 1) === "\\") {
|
725 | partialclass += item.substr(0, item.length - 1) + ".";
|
726 | }
|
727 | else {
|
728 | partialclass += item;
|
729 | classes.push(partialclass);
|
730 | partialclass = "";
|
731 | }
|
732 | }
|
733 | }
|
734 | return classes;
|
735 | }
|
736 | function dateToUnixTime(d) {
|
737 | if (!d) {
|
738 | return undefined;
|
739 | }
|
740 | if (typeof d.valueOf() === "string") {
|
741 | d = new Date(d);
|
742 | }
|
743 | return Math.floor(d.getTime() / 1000);
|
744 | }
|
745 | function unixTimeToDate(n) {
|
746 | if (!n) {
|
747 | return undefined;
|
748 | }
|
749 | return new Date(n * 1000);
|
750 | }
|
751 | function serializeBasicTypes(typeName, objectName, value) {
|
752 | if (value !== null && value !== undefined) {
|
753 | if (typeName.match(/^Number$/gi) !== null) {
|
754 | if (typeof value !== "number") {
|
755 | throw new Error(objectName + " with value " + value + " must be of type number.");
|
756 | }
|
757 | }
|
758 | else if (typeName.match(/^String$/gi) !== null) {
|
759 | if (typeof value.valueOf() !== "string") {
|
760 | throw new Error(objectName + " with value \"" + value + "\" must be of type string.");
|
761 | }
|
762 | }
|
763 | else if (typeName.match(/^Uuid$/gi) !== null) {
|
764 | if (!(typeof value.valueOf() === "string" && isValidUuid(value))) {
|
765 | throw new Error(objectName + " with value \"" + value + "\" must be of type string and a valid uuid.");
|
766 | }
|
767 | }
|
768 | else if (typeName.match(/^Boolean$/gi) !== null) {
|
769 | if (typeof value !== "boolean") {
|
770 | throw new Error(objectName + " with value " + value + " must be of type boolean.");
|
771 | }
|
772 | }
|
773 | else if (typeName.match(/^Stream$/gi) !== null) {
|
774 | var objectType = typeof value;
|
775 | if (objectType !== "string" &&
|
776 | objectType !== "function" &&
|
777 | !(value instanceof ArrayBuffer) &&
|
778 | !ArrayBuffer.isView(value) &&
|
779 | !(typeof Blob === "function" && value instanceof Blob)) {
|
780 | throw new Error(objectName + " must be a string, Blob, ArrayBuffer, ArrayBufferView, or a function returning NodeJS.ReadableStream.");
|
781 | }
|
782 | }
|
783 | }
|
784 | return value;
|
785 | }
|
786 | function serializeEnumType(objectName, allowedValues, value) {
|
787 | if (!allowedValues) {
|
788 | throw new Error("Please provide a set of allowedValues to validate " + objectName + " as an Enum Type.");
|
789 | }
|
790 | var isPresent = allowedValues.some(function (item) {
|
791 | if (typeof item.valueOf() === "string") {
|
792 | return item.toLowerCase() === value.toLowerCase();
|
793 | }
|
794 | return item === value;
|
795 | });
|
796 | if (!isPresent) {
|
797 | throw new Error(value + " is not a valid value for " + objectName + ". The valid values are: " + JSON.stringify(allowedValues) + ".");
|
798 | }
|
799 | return value;
|
800 | }
|
801 | function serializeByteArrayType(objectName, value) {
|
802 | if (value != undefined) {
|
803 | if (!(value instanceof Uint8Array)) {
|
804 | throw new Error(objectName + " must be of type Uint8Array.");
|
805 | }
|
806 | value = encodeByteArray(value);
|
807 | }
|
808 | return value;
|
809 | }
|
810 | function serializeBase64UrlType(objectName, value) {
|
811 | if (value != undefined) {
|
812 | if (!(value instanceof Uint8Array)) {
|
813 | throw new Error(objectName + " must be of type Uint8Array.");
|
814 | }
|
815 | value = bufferToBase64Url(value);
|
816 | }
|
817 | return value;
|
818 | }
|
819 | function serializeDateTypes(typeName, value, objectName) {
|
820 | if (value != undefined) {
|
821 | if (typeName.match(/^Date$/gi) !== null) {
|
822 | if (!(value instanceof Date ||
|
823 | (typeof value.valueOf() === "string" && !isNaN(Date.parse(value))))) {
|
824 | throw new Error(objectName + " must be an instanceof Date or a string in ISO8601 format.");
|
825 | }
|
826 | value =
|
827 | value instanceof Date
|
828 | ? value.toISOString().substring(0, 10)
|
829 | : new Date(value).toISOString().substring(0, 10);
|
830 | }
|
831 | else if (typeName.match(/^DateTime$/gi) !== null) {
|
832 | if (!(value instanceof Date ||
|
833 | (typeof value.valueOf() === "string" && !isNaN(Date.parse(value))))) {
|
834 | throw new Error(objectName + " must be an instanceof Date or a string in ISO8601 format.");
|
835 | }
|
836 | value = value instanceof Date ? value.toISOString() : new Date(value).toISOString();
|
837 | }
|
838 | else if (typeName.match(/^DateTimeRfc1123$/gi) !== null) {
|
839 | if (!(value instanceof Date ||
|
840 | (typeof value.valueOf() === "string" && !isNaN(Date.parse(value))))) {
|
841 | throw new Error(objectName + " must be an instanceof Date or a string in RFC-1123 format.");
|
842 | }
|
843 | value = value instanceof Date ? value.toUTCString() : new Date(value).toUTCString();
|
844 | }
|
845 | else if (typeName.match(/^UnixTime$/gi) !== null) {
|
846 | if (!(value instanceof Date ||
|
847 | (typeof value.valueOf() === "string" && !isNaN(Date.parse(value))))) {
|
848 | throw new Error(objectName + " must be an instanceof Date or a string in RFC-1123/ISO8601 format " +
|
849 | "for it to be serialized in UnixTime/Epoch format.");
|
850 | }
|
851 | value = dateToUnixTime(value);
|
852 | }
|
853 | else if (typeName.match(/^TimeSpan$/gi) !== null) {
|
854 | if (!isDuration(value)) {
|
855 | throw new Error(objectName + " must be a string in ISO 8601 format. Instead was \"" + value + "\".");
|
856 | }
|
857 | value = value;
|
858 | }
|
859 | }
|
860 | return value;
|
861 | }
|
862 | function serializeSequenceType(serializer, mapper, object, objectName) {
|
863 | if (!Array.isArray(object)) {
|
864 | throw new Error(objectName + " must be of type Array.");
|
865 | }
|
866 | var elementType = mapper.type.element;
|
867 | if (!elementType || typeof elementType !== "object") {
|
868 | throw new Error("element\" metadata for an Array must be defined in the " +
|
869 | ("mapper and it must of type \"object\" in " + objectName + "."));
|
870 | }
|
871 | var tempArray = [];
|
872 | for (var i = 0; i < object.length; i++) {
|
873 | tempArray[i] = serializer.serialize(elementType, object[i], objectName);
|
874 | }
|
875 | return tempArray;
|
876 | }
|
877 | function serializeDictionaryType(serializer, mapper, object, objectName) {
|
878 | if (typeof object !== "object") {
|
879 | throw new Error(objectName + " must be of type object.");
|
880 | }
|
881 | var valueType = mapper.type.value;
|
882 | if (!valueType || typeof valueType !== "object") {
|
883 | throw new Error("\"value\" metadata for a Dictionary must be defined in the " +
|
884 | ("mapper and it must of type \"object\" in " + objectName + "."));
|
885 | }
|
886 | var tempDictionary = {};
|
887 | for (var _i = 0, _a = Object.keys(object); _i < _a.length; _i++) {
|
888 | var key = _a[_i];
|
889 | tempDictionary[key] = serializer.serialize(valueType, object[key], objectName + "." + key);
|
890 | }
|
891 | return tempDictionary;
|
892 | }
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 | function resolveModelProperties(serializer, mapper, objectName) {
|
899 | var modelProps = mapper.type.modelProperties;
|
900 | if (!modelProps) {
|
901 | var className = mapper.type.className;
|
902 | if (!className) {
|
903 | throw new Error("Class name for model \"" + objectName + "\" is not provided in the mapper \"" + JSON.stringify(mapper, undefined, 2) + "\".");
|
904 | }
|
905 | var modelMapper = serializer.modelMappers[className];
|
906 | if (!modelMapper) {
|
907 | throw new Error("mapper() cannot be null or undefined for model \"" + className + "\".");
|
908 | }
|
909 | modelProps = modelMapper.type.modelProperties;
|
910 | if (!modelProps) {
|
911 | throw new Error("modelProperties cannot be null or undefined in the " +
|
912 | ("mapper \"" + JSON.stringify(modelMapper) + "\" of type \"" + className + "\" for object \"" + objectName + "\"."));
|
913 | }
|
914 | }
|
915 | return modelProps;
|
916 | }
|
917 | function serializeCompositeType(serializer, mapper, object, objectName) {
|
918 | var _a;
|
919 | if (getPolymorphicDiscriminatorRecursively(serializer, mapper)) {
|
920 | mapper = getPolymorphicMapper(serializer, mapper, object, "clientName");
|
921 | }
|
922 | if (object != undefined) {
|
923 | var payload = {};
|
924 | var modelProps = resolveModelProperties(serializer, mapper, objectName);
|
925 | for (var _i = 0, _b = Object.keys(modelProps); _i < _b.length; _i++) {
|
926 | var key = _b[_i];
|
927 | var propertyMapper = modelProps[key];
|
928 | if (propertyMapper.readOnly) {
|
929 | continue;
|
930 | }
|
931 | var propName = void 0;
|
932 | var parentObject = payload;
|
933 | if (serializer.isXML) {
|
934 | if (propertyMapper.xmlIsWrapped) {
|
935 | propName = propertyMapper.xmlName;
|
936 | }
|
937 | else {
|
938 | propName = propertyMapper.xmlElementName || propertyMapper.xmlName;
|
939 | }
|
940 | }
|
941 | else {
|
942 | var paths = splitSerializeName(propertyMapper.serializedName);
|
943 | propName = paths.pop();
|
944 | for (var _c = 0, paths_1 = paths; _c < paths_1.length; _c++) {
|
945 | var pathName = paths_1[_c];
|
946 | var childObject = parentObject[pathName];
|
947 | if (childObject == undefined && object[key] != undefined) {
|
948 | parentObject[pathName] = {};
|
949 | }
|
950 | parentObject = parentObject[pathName];
|
951 | }
|
952 | }
|
953 | if (parentObject != undefined) {
|
954 | var propertyObjectName = propertyMapper.serializedName !== ""
|
955 | ? objectName + "." + propertyMapper.serializedName
|
956 | : objectName;
|
957 | var toSerialize = object[key];
|
958 | var polymorphicDiscriminator = getPolymorphicDiscriminatorRecursively(serializer, mapper);
|
959 | if (polymorphicDiscriminator &&
|
960 | polymorphicDiscriminator.clientName === key &&
|
961 | toSerialize == undefined) {
|
962 | toSerialize = mapper.serializedName;
|
963 | }
|
964 | var serializedValue = serializer.serialize(propertyMapper, toSerialize, propertyObjectName);
|
965 | if (serializedValue !== undefined && propName != undefined) {
|
966 | if (propertyMapper.xmlIsAttribute) {
|
967 |
|
968 |
|
969 |
|
970 | parentObject.$ = parentObject.$ || {};
|
971 | parentObject.$[propName] = serializedValue;
|
972 | }
|
973 | else if (propertyMapper.xmlIsWrapped) {
|
974 | parentObject[propName] = (_a = {}, _a[propertyMapper.xmlElementName] = serializedValue, _a);
|
975 | }
|
976 | else {
|
977 | parentObject[propName] = serializedValue;
|
978 | }
|
979 | }
|
980 | }
|
981 | }
|
982 | var additionalPropertiesMapper = mapper.type.additionalProperties;
|
983 | if (additionalPropertiesMapper) {
|
984 | var propNames = Object.keys(modelProps);
|
985 | var _loop_1 = function (clientPropName) {
|
986 | var isAdditionalProperty = propNames.every(function (pn) { return pn !== clientPropName; });
|
987 | if (isAdditionalProperty) {
|
988 | payload[clientPropName] = serializer.serialize(additionalPropertiesMapper, object[clientPropName], objectName + '["' + clientPropName + '"]');
|
989 | }
|
990 | };
|
991 | for (var clientPropName in object) {
|
992 | _loop_1(clientPropName);
|
993 | }
|
994 | }
|
995 | return payload;
|
996 | }
|
997 | return object;
|
998 | }
|
999 | function isSpecialXmlProperty(propertyName) {
|
1000 | return ["$", "_"].includes(propertyName);
|
1001 | }
|
1002 | function deserializeCompositeType(serializer, mapper, responseBody, objectName) {
|
1003 | if (getPolymorphicDiscriminatorRecursively(serializer, mapper)) {
|
1004 | mapper = getPolymorphicMapper(serializer, mapper, responseBody, "serializedName");
|
1005 | }
|
1006 | var modelProps = resolveModelProperties(serializer, mapper, objectName);
|
1007 | var instance = {};
|
1008 | var handledPropertyNames = [];
|
1009 | for (var _i = 0, _a = Object.keys(modelProps); _i < _a.length; _i++) {
|
1010 | var key = _a[_i];
|
1011 | var propertyMapper = modelProps[key];
|
1012 | var paths = splitSerializeName(modelProps[key].serializedName);
|
1013 | handledPropertyNames.push(paths[0]);
|
1014 | var serializedName = propertyMapper.serializedName, xmlName = propertyMapper.xmlName, xmlElementName = propertyMapper.xmlElementName;
|
1015 | var propertyObjectName = objectName;
|
1016 | if (serializedName !== "" && serializedName !== undefined) {
|
1017 | propertyObjectName = objectName + "." + serializedName;
|
1018 | }
|
1019 | var headerCollectionPrefix = propertyMapper.headerCollectionPrefix;
|
1020 | if (headerCollectionPrefix) {
|
1021 | var dictionary = {};
|
1022 | for (var _b = 0, _c = Object.keys(responseBody); _b < _c.length; _b++) {
|
1023 | var headerKey = _c[_b];
|
1024 | if (headerKey.startsWith(headerCollectionPrefix)) {
|
1025 | dictionary[headerKey.substring(headerCollectionPrefix.length)] = serializer.deserialize(propertyMapper.type.value, responseBody[headerKey], propertyObjectName);
|
1026 | }
|
1027 | handledPropertyNames.push(headerKey);
|
1028 | }
|
1029 | instance[key] = dictionary;
|
1030 | }
|
1031 | else if (serializer.isXML) {
|
1032 | if (propertyMapper.xmlIsAttribute && responseBody.$) {
|
1033 | instance[key] = serializer.deserialize(propertyMapper, responseBody.$[xmlName], propertyObjectName);
|
1034 | }
|
1035 | else {
|
1036 | var propertyName = xmlElementName || xmlName || serializedName;
|
1037 | var unwrappedProperty = responseBody[propertyName];
|
1038 | if (propertyMapper.xmlIsWrapped) {
|
1039 | unwrappedProperty = responseBody[xmlName];
|
1040 | unwrappedProperty = unwrappedProperty && unwrappedProperty[xmlElementName];
|
1041 | var isEmptyWrappedList = unwrappedProperty === undefined;
|
1042 | if (isEmptyWrappedList) {
|
1043 | unwrappedProperty = [];
|
1044 | }
|
1045 | }
|
1046 | instance[key] = serializer.deserialize(propertyMapper, unwrappedProperty, propertyObjectName);
|
1047 | }
|
1048 | }
|
1049 | else {
|
1050 |
|
1051 | var propertyInstance = void 0;
|
1052 | var res = responseBody;
|
1053 |
|
1054 | for (var _d = 0, paths_2 = paths; _d < paths_2.length; _d++) {
|
1055 | var item = paths_2[_d];
|
1056 | if (!res)
|
1057 | break;
|
1058 | res = res[item];
|
1059 | }
|
1060 | propertyInstance = res;
|
1061 | var polymorphicDiscriminator = mapper.type.polymorphicDiscriminator;
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 | if (polymorphicDiscriminator &&
|
1072 | key === polymorphicDiscriminator.clientName &&
|
1073 | propertyInstance == undefined) {
|
1074 | propertyInstance = mapper.serializedName;
|
1075 | }
|
1076 | var serializedValue = void 0;
|
1077 |
|
1078 | if (Array.isArray(responseBody[key]) && modelProps[key].serializedName === "") {
|
1079 | propertyInstance = responseBody[key];
|
1080 | var arrayInstance = serializer.deserialize(propertyMapper, propertyInstance, propertyObjectName);
|
1081 |
|
1082 |
|
1083 | for (var _e = 0, _f = Object.entries(instance); _e < _f.length; _e++) {
|
1084 | var _g = _f[_e], key_1 = _g[0], value = _g[1];
|
1085 | if (!arrayInstance.hasOwnProperty(key_1)) {
|
1086 | arrayInstance[key_1] = value;
|
1087 | }
|
1088 | }
|
1089 | instance = arrayInstance;
|
1090 | }
|
1091 | else if (propertyInstance !== undefined || propertyMapper.defaultValue !== undefined) {
|
1092 | serializedValue = serializer.deserialize(propertyMapper, propertyInstance, propertyObjectName);
|
1093 | instance[key] = serializedValue;
|
1094 | }
|
1095 | }
|
1096 | }
|
1097 | var additionalPropertiesMapper = mapper.type.additionalProperties;
|
1098 | if (additionalPropertiesMapper) {
|
1099 | var isAdditionalProperty = function (responsePropName) {
|
1100 | for (var clientPropName in modelProps) {
|
1101 | var paths = splitSerializeName(modelProps[clientPropName].serializedName);
|
1102 | if (paths[0] === responsePropName) {
|
1103 | return false;
|
1104 | }
|
1105 | }
|
1106 | return true;
|
1107 | };
|
1108 | for (var responsePropName in responseBody) {
|
1109 | if (isAdditionalProperty(responsePropName)) {
|
1110 | instance[responsePropName] = serializer.deserialize(additionalPropertiesMapper, responseBody[responsePropName], objectName + '["' + responsePropName + '"]');
|
1111 | }
|
1112 | }
|
1113 | }
|
1114 | else if (responseBody) {
|
1115 | for (var _h = 0, _j = Object.keys(responseBody); _h < _j.length; _h++) {
|
1116 | var key = _j[_h];
|
1117 | if (instance[key] === undefined &&
|
1118 | !handledPropertyNames.includes(key) &&
|
1119 | !isSpecialXmlProperty(key)) {
|
1120 | instance[key] = responseBody[key];
|
1121 | }
|
1122 | }
|
1123 | }
|
1124 | return instance;
|
1125 | }
|
1126 | function deserializeDictionaryType(serializer, mapper, responseBody, objectName) {
|
1127 |
|
1128 | var value = mapper.type.value;
|
1129 | if (!value || typeof value !== "object") {
|
1130 | throw new Error("\"value\" metadata for a Dictionary must be defined in the " +
|
1131 | ("mapper and it must of type \"object\" in " + objectName));
|
1132 | }
|
1133 | if (responseBody) {
|
1134 | var tempDictionary = {};
|
1135 | for (var _i = 0, _a = Object.keys(responseBody); _i < _a.length; _i++) {
|
1136 | var key = _a[_i];
|
1137 | tempDictionary[key] = serializer.deserialize(value, responseBody[key], objectName);
|
1138 | }
|
1139 | return tempDictionary;
|
1140 | }
|
1141 | return responseBody;
|
1142 | }
|
1143 | function deserializeSequenceType(serializer, mapper, responseBody, objectName) {
|
1144 |
|
1145 | var element = mapper.type.element;
|
1146 | if (!element || typeof element !== "object") {
|
1147 | throw new Error("element\" metadata for an Array must be defined in the " +
|
1148 | ("mapper and it must of type \"object\" in " + objectName));
|
1149 | }
|
1150 | if (responseBody) {
|
1151 | if (!Array.isArray(responseBody)) {
|
1152 |
|
1153 | responseBody = [responseBody];
|
1154 | }
|
1155 | var tempArray = [];
|
1156 | for (var i = 0; i < responseBody.length; i++) {
|
1157 | tempArray[i] = serializer.deserialize(element, responseBody[i], objectName + "[" + i + "]");
|
1158 | }
|
1159 | return tempArray;
|
1160 | }
|
1161 | return responseBody;
|
1162 | }
|
1163 | function getPolymorphicMapper(serializer, mapper, object, polymorphicPropertyName) {
|
1164 | var polymorphicDiscriminator = getPolymorphicDiscriminatorRecursively(serializer, mapper);
|
1165 | if (polymorphicDiscriminator) {
|
1166 | var discriminatorName = polymorphicDiscriminator[polymorphicPropertyName];
|
1167 | if (discriminatorName != undefined) {
|
1168 | var discriminatorValue = object[discriminatorName];
|
1169 | if (discriminatorValue != undefined) {
|
1170 | var typeName = mapper.type.uberParent || mapper.type.className;
|
1171 | var indexDiscriminator = discriminatorValue === typeName
|
1172 | ? discriminatorValue
|
1173 | : typeName + "." + discriminatorValue;
|
1174 | var polymorphicMapper = serializer.modelMappers.discriminators[indexDiscriminator];
|
1175 | if (polymorphicMapper) {
|
1176 | mapper = polymorphicMapper;
|
1177 | }
|
1178 | }
|
1179 | }
|
1180 | }
|
1181 | return mapper;
|
1182 | }
|
1183 | function getPolymorphicDiscriminatorRecursively(serializer, mapper) {
|
1184 | return (mapper.type.polymorphicDiscriminator ||
|
1185 | getPolymorphicDiscriminatorSafely(serializer, mapper.type.uberParent) ||
|
1186 | getPolymorphicDiscriminatorSafely(serializer, mapper.type.className));
|
1187 | }
|
1188 | function getPolymorphicDiscriminatorSafely(serializer, typeName) {
|
1189 | return (typeName &&
|
1190 | serializer.modelMappers[typeName] &&
|
1191 | serializer.modelMappers[typeName].type.polymorphicDiscriminator);
|
1192 | }
|
1193 |
|
1194 | function serializeObject(toSerialize) {
|
1195 | if (toSerialize == undefined)
|
1196 | return undefined;
|
1197 | if (toSerialize instanceof Uint8Array) {
|
1198 | toSerialize = encodeByteArray(toSerialize);
|
1199 | return toSerialize;
|
1200 | }
|
1201 | else if (toSerialize instanceof Date) {
|
1202 | return toSerialize.toISOString();
|
1203 | }
|
1204 | else if (Array.isArray(toSerialize)) {
|
1205 | var array = [];
|
1206 | for (var i = 0; i < toSerialize.length; i++) {
|
1207 | array.push(serializeObject(toSerialize[i]));
|
1208 | }
|
1209 | return array;
|
1210 | }
|
1211 | else if (typeof toSerialize === "object") {
|
1212 | var dictionary = {};
|
1213 | for (var property in toSerialize) {
|
1214 | dictionary[property] = serializeObject(toSerialize[property]);
|
1215 | }
|
1216 | return dictionary;
|
1217 | }
|
1218 | return toSerialize;
|
1219 | }
|
1220 |
|
1221 |
|
1222 |
|
1223 | function strEnum(o) {
|
1224 | var result = {};
|
1225 | for (var _i = 0, o_1 = o; _i < o_1.length; _i++) {
|
1226 | var key = o_1[_i];
|
1227 | result[key] = key;
|
1228 | }
|
1229 | return result;
|
1230 | }
|
1231 | var MapperType = strEnum([
|
1232 | "Base64Url",
|
1233 | "Boolean",
|
1234 | "ByteArray",
|
1235 | "Composite",
|
1236 | "Date",
|
1237 | "DateTime",
|
1238 | "DateTimeRfc1123",
|
1239 | "Dictionary",
|
1240 | "Enum",
|
1241 | "Number",
|
1242 | "Object",
|
1243 | "Sequence",
|
1244 | "String",
|
1245 | "Stream",
|
1246 | "TimeSpan",
|
1247 | "UnixTime",
|
1248 | ]);
|
1249 |
|
1250 |
|
1251 | function isWebResourceLike(object) {
|
1252 | if (typeof object !== "object") {
|
1253 | return false;
|
1254 | }
|
1255 | if (typeof object.url === "string" &&
|
1256 | typeof object.method === "string" &&
|
1257 | typeof object.headers === "object" &&
|
1258 | isHttpHeadersLike(object.headers) &&
|
1259 | typeof object.validateRequestProperties === "function" &&
|
1260 | typeof object.prepare === "function" &&
|
1261 | typeof object.clone === "function") {
|
1262 | return true;
|
1263 | }
|
1264 | return false;
|
1265 | }
|
1266 |
|
1267 |
|
1268 |
|
1269 |
|
1270 |
|
1271 |
|
1272 |
|
1273 |
|
1274 | var WebResource = (function () {
|
1275 | function WebResource(url, method, body, query, headers, streamResponseBody, withCredentials, abortSignal, timeout, onUploadProgress, onDownloadProgress, proxySettings, keepAlive, agentSettings, redirectLimit) {
|
1276 | this.streamResponseBody = streamResponseBody;
|
1277 | this.url = url || "";
|
1278 | this.method = method || "GET";
|
1279 | this.headers = isHttpHeadersLike(headers) ? headers : new HttpHeaders(headers);
|
1280 | this.body = body;
|
1281 | this.query = query;
|
1282 | this.formData = undefined;
|
1283 | this.withCredentials = withCredentials || false;
|
1284 | this.abortSignal = abortSignal;
|
1285 | this.timeout = timeout || 0;
|
1286 | this.onUploadProgress = onUploadProgress;
|
1287 | this.onDownloadProgress = onDownloadProgress;
|
1288 | this.proxySettings = proxySettings;
|
1289 | this.keepAlive = keepAlive;
|
1290 | this.agentSettings = agentSettings;
|
1291 | this.redirectLimit = redirectLimit;
|
1292 | }
|
1293 | |
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 | WebResource.prototype.validateRequestProperties = function () {
|
1299 | if (!this.method) {
|
1300 | throw new Error("WebResource.method is required.");
|
1301 | }
|
1302 | if (!this.url) {
|
1303 | throw new Error("WebResource.url is required.");
|
1304 | }
|
1305 | };
|
1306 | |
1307 |
|
1308 |
|
1309 |
|
1310 |
|
1311 | WebResource.prototype.prepare = function (options) {
|
1312 | if (!options) {
|
1313 | throw new Error("options object is required");
|
1314 | }
|
1315 | if (options.method == undefined || typeof options.method.valueOf() !== "string") {
|
1316 | throw new Error("options.method must be a string.");
|
1317 | }
|
1318 | if (options.url && options.pathTemplate) {
|
1319 | throw new Error("options.url and options.pathTemplate are mutually exclusive. Please provide exactly one of them.");
|
1320 | }
|
1321 | if ((options.pathTemplate == undefined || typeof options.pathTemplate.valueOf() !== "string") &&
|
1322 | (options.url == undefined || typeof options.url.valueOf() !== "string")) {
|
1323 | throw new Error("Please provide exactly one of options.pathTemplate or options.url.");
|
1324 | }
|
1325 |
|
1326 | if (options.url) {
|
1327 | if (typeof options.url !== "string") {
|
1328 | throw new Error('options.url must be of type "string".');
|
1329 | }
|
1330 | this.url = options.url;
|
1331 | }
|
1332 |
|
1333 | if (options.method) {
|
1334 | var validMethods = ["GET", "PUT", "HEAD", "DELETE", "OPTIONS", "POST", "PATCH", "TRACE"];
|
1335 | if (validMethods.indexOf(options.method.toUpperCase()) === -1) {
|
1336 | throw new Error('The provided method "' +
|
1337 | options.method +
|
1338 | '" is invalid. Supported HTTP methods are: ' +
|
1339 | JSON.stringify(validMethods));
|
1340 | }
|
1341 | }
|
1342 | this.method = options.method.toUpperCase();
|
1343 |
|
1344 | if (options.pathTemplate) {
|
1345 | var pathTemplate_1 = options.pathTemplate, pathParameters_1 = options.pathParameters;
|
1346 | if (typeof pathTemplate_1 !== "string") {
|
1347 | throw new Error('options.pathTemplate must be of type "string".');
|
1348 | }
|
1349 | if (!options.baseUrl) {
|
1350 | options.baseUrl = "https://management.azure.com";
|
1351 | }
|
1352 | var baseUrl = options.baseUrl;
|
1353 | var url_1 = baseUrl +
|
1354 | (baseUrl.endsWith("/") ? "" : "/") +
|
1355 | (pathTemplate_1.startsWith("/") ? pathTemplate_1.slice(1) : pathTemplate_1);
|
1356 | var segments = url_1.match(/({\w*\s*\w*})/gi);
|
1357 | if (segments && segments.length) {
|
1358 | if (!pathParameters_1) {
|
1359 | throw new Error("pathTemplate: " + pathTemplate_1 + " has been provided. Hence, options.pathParameters must also be provided.");
|
1360 | }
|
1361 | segments.forEach(function (item) {
|
1362 | var pathParamName = item.slice(1, -1);
|
1363 | var pathParam = pathParameters_1[pathParamName];
|
1364 | if (pathParam === null ||
|
1365 | pathParam === undefined ||
|
1366 | !(typeof pathParam === "string" || typeof pathParam === "object")) {
|
1367 | throw new Error("pathTemplate: " + pathTemplate_1 + " contains the path parameter " + pathParamName +
|
1368 | (" however, it is not present in " + pathParameters_1 + " - " + JSON.stringify(pathParameters_1, undefined, 2) + ".") +
|
1369 | ("The value of the path parameter can either be a \"string\" of the form { " + pathParamName + ": \"some sample value\" } or ") +
|
1370 | ("it can be an \"object\" of the form { \"" + pathParamName + "\": { value: \"some sample value\", skipUrlEncoding: true } }."));
|
1371 | }
|
1372 | if (typeof pathParam.valueOf() === "string") {
|
1373 | url_1 = url_1.replace(item, encodeURIComponent(pathParam));
|
1374 | }
|
1375 | if (typeof pathParam.valueOf() === "object") {
|
1376 | if (!pathParam.value) {
|
1377 | throw new Error("options.pathParameters[" + pathParamName + "] is of type \"object\" but it does not contain a \"value\" property.");
|
1378 | }
|
1379 | if (pathParam.skipUrlEncoding) {
|
1380 | url_1 = url_1.replace(item, pathParam.value);
|
1381 | }
|
1382 | else {
|
1383 | url_1 = url_1.replace(item, encodeURIComponent(pathParam.value));
|
1384 | }
|
1385 | }
|
1386 | });
|
1387 | }
|
1388 | this.url = url_1;
|
1389 | }
|
1390 |
|
1391 | if (options.queryParameters) {
|
1392 | var queryParameters = options.queryParameters;
|
1393 | if (typeof queryParameters !== "object") {
|
1394 | throw new Error("options.queryParameters must be of type object. It should be a JSON object " +
|
1395 | "of \"query-parameter-name\" as the key and the \"query-parameter-value\" as the value. " +
|
1396 | "The \"query-parameter-value\" may be fo type \"string\" or an \"object\" of the form { value: \"query-parameter-value\", skipUrlEncoding: true }.");
|
1397 | }
|
1398 |
|
1399 | if (this.url && this.url.indexOf("?") === -1) {
|
1400 | this.url += "?";
|
1401 | }
|
1402 |
|
1403 | var queryParams = [];
|
1404 |
|
1405 | this.query = {};
|
1406 | for (var queryParamName in queryParameters) {
|
1407 | var queryParam = queryParameters[queryParamName];
|
1408 | if (queryParam) {
|
1409 | if (typeof queryParam === "string") {
|
1410 | queryParams.push(queryParamName + "=" + encodeURIComponent(queryParam));
|
1411 | this.query[queryParamName] = encodeURIComponent(queryParam);
|
1412 | }
|
1413 | else if (typeof queryParam === "object") {
|
1414 | if (!queryParam.value) {
|
1415 | throw new Error("options.queryParameters[" + queryParamName + "] is of type \"object\" but it does not contain a \"value\" property.");
|
1416 | }
|
1417 | if (queryParam.skipUrlEncoding) {
|
1418 | queryParams.push(queryParamName + "=" + queryParam.value);
|
1419 | this.query[queryParamName] = queryParam.value;
|
1420 | }
|
1421 | else {
|
1422 | queryParams.push(queryParamName + "=" + encodeURIComponent(queryParam.value));
|
1423 | this.query[queryParamName] = encodeURIComponent(queryParam.value);
|
1424 | }
|
1425 | }
|
1426 | }
|
1427 | }
|
1428 |
|
1429 | this.url += queryParams.join("&");
|
1430 | }
|
1431 |
|
1432 | if (options.headers) {
|
1433 | var headers = options.headers;
|
1434 | for (var _i = 0, _a = Object.keys(options.headers); _i < _a.length; _i++) {
|
1435 | var headerName = _a[_i];
|
1436 | this.headers.set(headerName, headers[headerName]);
|
1437 | }
|
1438 | }
|
1439 |
|
1440 | if (!this.headers.get("accept-language")) {
|
1441 | this.headers.set("accept-language", "en-US");
|
1442 | }
|
1443 |
|
1444 | if (!this.headers.get("x-ms-client-request-id") && !options.disableClientRequestId) {
|
1445 | this.headers.set("x-ms-client-request-id", generateUuid());
|
1446 | }
|
1447 |
|
1448 | if (!this.headers.get("Content-Type")) {
|
1449 | this.headers.set("Content-Type", "application/json; charset=utf-8");
|
1450 | }
|
1451 |
|
1452 | this.body = options.body;
|
1453 | if (options.body != undefined) {
|
1454 |
|
1455 | if (options.bodyIsStream) {
|
1456 | if (!this.headers.get("Transfer-Encoding")) {
|
1457 | this.headers.set("Transfer-Encoding", "chunked");
|
1458 | }
|
1459 | if (this.headers.get("Content-Type") !== "application/octet-stream") {
|
1460 | this.headers.set("Content-Type", "application/octet-stream");
|
1461 | }
|
1462 | }
|
1463 | else {
|
1464 | if (options.serializationMapper) {
|
1465 | this.body = new Serializer(options.mappers).serialize(options.serializationMapper, options.body, "requestBody");
|
1466 | }
|
1467 | if (!options.disableJsonStringifyOnBody) {
|
1468 | this.body = JSON.stringify(options.body);
|
1469 | }
|
1470 | }
|
1471 | }
|
1472 | this.abortSignal = options.abortSignal;
|
1473 | this.onDownloadProgress = options.onDownloadProgress;
|
1474 | this.onUploadProgress = options.onUploadProgress;
|
1475 | this.redirectLimit = options.redirectLimit;
|
1476 | this.streamResponseBody = options.streamResponseBody;
|
1477 | return this;
|
1478 | };
|
1479 | |
1480 |
|
1481 |
|
1482 |
|
1483 | WebResource.prototype.clone = function () {
|
1484 | var result = new WebResource(this.url, this.method, this.body, this.query, this.headers && this.headers.clone(), this.streamResponseBody, this.withCredentials, this.abortSignal, this.timeout, this.onUploadProgress, this.onDownloadProgress, this.proxySettings, this.keepAlive, this.agentSettings, this.redirectLimit);
|
1485 | if (this.formData) {
|
1486 | result.formData = this.formData;
|
1487 | }
|
1488 | if (this.operationSpec) {
|
1489 | result.operationSpec = this.operationSpec;
|
1490 | }
|
1491 | if (this.shouldDeserialize) {
|
1492 | result.shouldDeserialize = this.shouldDeserialize;
|
1493 | }
|
1494 | if (this.operationResponseGetter) {
|
1495 | result.operationResponseGetter = this.operationResponseGetter;
|
1496 | }
|
1497 | return result;
|
1498 | };
|
1499 | return WebResource;
|
1500 | }());
|
1501 |
|
1502 |
|
1503 |
|
1504 |
|
1505 |
|
1506 |
|
1507 |
|
1508 |
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 |
|
1526 | const privateData = new WeakMap();
|
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 | const wrappers = new WeakMap();
|
1534 |
|
1535 |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 | function pd(event) {
|
1542 | const retv = privateData.get(event);
|
1543 | console.assert(
|
1544 | retv != null,
|
1545 | "'this' is expected an Event object, but got",
|
1546 | event
|
1547 | );
|
1548 | return retv
|
1549 | }
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 | function setCancelFlag(data) {
|
1556 | if (data.passiveListener != null) {
|
1557 | if (
|
1558 | typeof console !== "undefined" &&
|
1559 | typeof console.error === "function"
|
1560 | ) {
|
1561 | console.error(
|
1562 | "Unable to preventDefault inside passive event listener invocation.",
|
1563 | data.passiveListener
|
1564 | );
|
1565 | }
|
1566 | return
|
1567 | }
|
1568 | if (!data.event.cancelable) {
|
1569 | return
|
1570 | }
|
1571 |
|
1572 | data.canceled = true;
|
1573 | if (typeof data.event.preventDefault === "function") {
|
1574 | data.event.preventDefault();
|
1575 | }
|
1576 | }
|
1577 |
|
1578 |
|
1579 |
|
1580 |
|
1581 |
|
1582 |
|
1583 |
|
1584 |
|
1585 |
|
1586 |
|
1587 |
|
1588 | function Event(eventTarget, event) {
|
1589 | privateData.set(this, {
|
1590 | eventTarget,
|
1591 | event,
|
1592 | eventPhase: 2,
|
1593 | currentTarget: eventTarget,
|
1594 | canceled: false,
|
1595 | stopped: false,
|
1596 | immediateStopped: false,
|
1597 | passiveListener: null,
|
1598 | timeStamp: event.timeStamp || Date.now(),
|
1599 | });
|
1600 |
|
1601 |
|
1602 | Object.defineProperty(this, "isTrusted", { value: false, enumerable: true });
|
1603 |
|
1604 |
|
1605 | const keys = Object.keys(event);
|
1606 | for (let i = 0; i < keys.length; ++i) {
|
1607 | const key = keys[i];
|
1608 | if (!(key in this)) {
|
1609 | Object.defineProperty(this, key, defineRedirectDescriptor(key));
|
1610 | }
|
1611 | }
|
1612 | }
|
1613 |
|
1614 |
|
1615 | Event.prototype = {
|
1616 | |
1617 |
|
1618 |
|
1619 |
|
1620 | get type() {
|
1621 | return pd(this).event.type
|
1622 | },
|
1623 |
|
1624 | |
1625 |
|
1626 |
|
1627 |
|
1628 | get target() {
|
1629 | return pd(this).eventTarget
|
1630 | },
|
1631 |
|
1632 | |
1633 |
|
1634 |
|
1635 |
|
1636 | get currentTarget() {
|
1637 | return pd(this).currentTarget
|
1638 | },
|
1639 |
|
1640 | |
1641 |
|
1642 |
|
1643 | composedPath() {
|
1644 | const currentTarget = pd(this).currentTarget;
|
1645 | if (currentTarget == null) {
|
1646 | return []
|
1647 | }
|
1648 | return [currentTarget]
|
1649 | },
|
1650 |
|
1651 | |
1652 |
|
1653 |
|
1654 |
|
1655 | get NONE() {
|
1656 | return 0
|
1657 | },
|
1658 |
|
1659 | |
1660 |
|
1661 |
|
1662 |
|
1663 | get CAPTURING_PHASE() {
|
1664 | return 1
|
1665 | },
|
1666 |
|
1667 | |
1668 |
|
1669 |
|
1670 |
|
1671 | get AT_TARGET() {
|
1672 | return 2
|
1673 | },
|
1674 |
|
1675 | |
1676 |
|
1677 |
|
1678 |
|
1679 | get BUBBLING_PHASE() {
|
1680 | return 3
|
1681 | },
|
1682 |
|
1683 | |
1684 |
|
1685 |
|
1686 |
|
1687 | get eventPhase() {
|
1688 | return pd(this).eventPhase
|
1689 | },
|
1690 |
|
1691 | |
1692 |
|
1693 |
|
1694 |
|
1695 | stopPropagation() {
|
1696 | const data = pd(this);
|
1697 |
|
1698 | data.stopped = true;
|
1699 | if (typeof data.event.stopPropagation === "function") {
|
1700 | data.event.stopPropagation();
|
1701 | }
|
1702 | },
|
1703 |
|
1704 | |
1705 |
|
1706 |
|
1707 |
|
1708 | stopImmediatePropagation() {
|
1709 | const data = pd(this);
|
1710 |
|
1711 | data.stopped = true;
|
1712 | data.immediateStopped = true;
|
1713 | if (typeof data.event.stopImmediatePropagation === "function") {
|
1714 | data.event.stopImmediatePropagation();
|
1715 | }
|
1716 | },
|
1717 |
|
1718 | |
1719 |
|
1720 |
|
1721 |
|
1722 | get bubbles() {
|
1723 | return Boolean(pd(this).event.bubbles)
|
1724 | },
|
1725 |
|
1726 | |
1727 |
|
1728 |
|
1729 |
|
1730 | get cancelable() {
|
1731 | return Boolean(pd(this).event.cancelable)
|
1732 | },
|
1733 |
|
1734 | |
1735 |
|
1736 |
|
1737 |
|
1738 | preventDefault() {
|
1739 | setCancelFlag(pd(this));
|
1740 | },
|
1741 |
|
1742 | |
1743 |
|
1744 |
|
1745 |
|
1746 | get defaultPrevented() {
|
1747 | return pd(this).canceled
|
1748 | },
|
1749 |
|
1750 | |
1751 |
|
1752 |
|
1753 |
|
1754 | get composed() {
|
1755 | return Boolean(pd(this).event.composed)
|
1756 | },
|
1757 |
|
1758 | |
1759 |
|
1760 |
|
1761 |
|
1762 | get timeStamp() {
|
1763 | return pd(this).timeStamp
|
1764 | },
|
1765 |
|
1766 | |
1767 |
|
1768 |
|
1769 |
|
1770 |
|
1771 | get srcElement() {
|
1772 | return pd(this).eventTarget
|
1773 | },
|
1774 |
|
1775 | |
1776 |
|
1777 |
|
1778 |
|
1779 |
|
1780 | get cancelBubble() {
|
1781 | return pd(this).stopped
|
1782 | },
|
1783 | set cancelBubble(value) {
|
1784 | if (!value) {
|
1785 | return
|
1786 | }
|
1787 | const data = pd(this);
|
1788 |
|
1789 | data.stopped = true;
|
1790 | if (typeof data.event.cancelBubble === "boolean") {
|
1791 | data.event.cancelBubble = true;
|
1792 | }
|
1793 | },
|
1794 |
|
1795 | |
1796 |
|
1797 |
|
1798 |
|
1799 |
|
1800 | get returnValue() {
|
1801 | return !pd(this).canceled
|
1802 | },
|
1803 | set returnValue(value) {
|
1804 | if (!value) {
|
1805 | setCancelFlag(pd(this));
|
1806 | }
|
1807 | },
|
1808 |
|
1809 | |
1810 |
|
1811 |
|
1812 |
|
1813 |
|
1814 |
|
1815 |
|
1816 | initEvent() {
|
1817 |
|
1818 | },
|
1819 | };
|
1820 |
|
1821 |
|
1822 | Object.defineProperty(Event.prototype, "constructor", {
|
1823 | value: Event,
|
1824 | configurable: true,
|
1825 | writable: true,
|
1826 | });
|
1827 |
|
1828 |
|
1829 | if (typeof window !== "undefined" && typeof window.Event !== "undefined") {
|
1830 | Object.setPrototypeOf(Event.prototype, window.Event.prototype);
|
1831 |
|
1832 |
|
1833 | wrappers.set(window.Event.prototype, Event);
|
1834 | }
|
1835 |
|
1836 |
|
1837 |
|
1838 |
|
1839 |
|
1840 |
|
1841 |
|
1842 | function defineRedirectDescriptor(key) {
|
1843 | return {
|
1844 | get() {
|
1845 | return pd(this).event[key]
|
1846 | },
|
1847 | set(value) {
|
1848 | pd(this).event[key] = value;
|
1849 | },
|
1850 | configurable: true,
|
1851 | enumerable: true,
|
1852 | }
|
1853 | }
|
1854 |
|
1855 |
|
1856 |
|
1857 |
|
1858 |
|
1859 |
|
1860 |
|
1861 | function defineCallDescriptor(key) {
|
1862 | return {
|
1863 | value() {
|
1864 | const event = pd(this).event;
|
1865 | return event[key].apply(event, arguments)
|
1866 | },
|
1867 | configurable: true,
|
1868 | enumerable: true,
|
1869 | }
|
1870 | }
|
1871 |
|
1872 |
|
1873 |
|
1874 |
|
1875 |
|
1876 |
|
1877 |
|
1878 |
|
1879 | function defineWrapper(BaseEvent, proto) {
|
1880 | const keys = Object.keys(proto);
|
1881 | if (keys.length === 0) {
|
1882 | return BaseEvent
|
1883 | }
|
1884 |
|
1885 |
|
1886 | function CustomEvent(eventTarget, event) {
|
1887 | BaseEvent.call(this, eventTarget, event);
|
1888 | }
|
1889 |
|
1890 | CustomEvent.prototype = Object.create(BaseEvent.prototype, {
|
1891 | constructor: { value: CustomEvent, configurable: true, writable: true },
|
1892 | });
|
1893 |
|
1894 |
|
1895 | for (let i = 0; i < keys.length; ++i) {
|
1896 | const key = keys[i];
|
1897 | if (!(key in BaseEvent.prototype)) {
|
1898 | const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
1899 | const isFunc = typeof descriptor.value === "function";
|
1900 | Object.defineProperty(
|
1901 | CustomEvent.prototype,
|
1902 | key,
|
1903 | isFunc
|
1904 | ? defineCallDescriptor(key)
|
1905 | : defineRedirectDescriptor(key)
|
1906 | );
|
1907 | }
|
1908 | }
|
1909 |
|
1910 | return CustomEvent
|
1911 | }
|
1912 |
|
1913 |
|
1914 |
|
1915 |
|
1916 |
|
1917 |
|
1918 |
|
1919 | function getWrapper(proto) {
|
1920 | if (proto == null || proto === Object.prototype) {
|
1921 | return Event
|
1922 | }
|
1923 |
|
1924 | let wrapper = wrappers.get(proto);
|
1925 | if (wrapper == null) {
|
1926 | wrapper = defineWrapper(getWrapper(Object.getPrototypeOf(proto)), proto);
|
1927 | wrappers.set(proto, wrapper);
|
1928 | }
|
1929 | return wrapper
|
1930 | }
|
1931 |
|
1932 |
|
1933 |
|
1934 |
|
1935 |
|
1936 |
|
1937 |
|
1938 |
|
1939 | function wrapEvent(eventTarget, event) {
|
1940 | const Wrapper = getWrapper(Object.getPrototypeOf(event));
|
1941 | return new Wrapper(eventTarget, event)
|
1942 | }
|
1943 |
|
1944 |
|
1945 |
|
1946 |
|
1947 |
|
1948 |
|
1949 |
|
1950 | function isStopped(event) {
|
1951 | return pd(event).immediateStopped
|
1952 | }
|
1953 |
|
1954 |
|
1955 |
|
1956 |
|
1957 |
|
1958 |
|
1959 |
|
1960 |
|
1961 | function setEventPhase(event, eventPhase) {
|
1962 | pd(event).eventPhase = eventPhase;
|
1963 | }
|
1964 |
|
1965 |
|
1966 |
|
1967 |
|
1968 |
|
1969 |
|
1970 |
|
1971 |
|
1972 | function setCurrentTarget(event, currentTarget) {
|
1973 | pd(event).currentTarget = currentTarget;
|
1974 | }
|
1975 |
|
1976 |
|
1977 |
|
1978 |
|
1979 |
|
1980 |
|
1981 |
|
1982 |
|
1983 | function setPassiveListener(event, passiveListener) {
|
1984 | pd(event).passiveListener = passiveListener;
|
1985 | }
|
1986 |
|
1987 |
|
1988 |
|
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 |
|
1997 |
|
1998 |
|
1999 |
|
2000 |
|
2001 | const listenersMap = new WeakMap();
|
2002 |
|
2003 |
|
2004 | const CAPTURE = 1;
|
2005 | const BUBBLE = 2;
|
2006 | const ATTRIBUTE = 3;
|
2007 |
|
2008 |
|
2009 |
|
2010 |
|
2011 |
|
2012 |
|
2013 | function isObject(x) {
|
2014 | return x !== null && typeof x === "object"
|
2015 | }
|
2016 |
|
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 |
|
2022 |
|
2023 | function getListeners(eventTarget) {
|
2024 | const listeners = listenersMap.get(eventTarget);
|
2025 | if (listeners == null) {
|
2026 | throw new TypeError(
|
2027 | "'this' is expected an EventTarget object, but got another value."
|
2028 | )
|
2029 | }
|
2030 | return listeners
|
2031 | }
|
2032 |
|
2033 |
|
2034 |
|
2035 |
|
2036 |
|
2037 |
|
2038 |
|
2039 | function defineEventAttributeDescriptor(eventName) {
|
2040 | return {
|
2041 | get() {
|
2042 | const listeners = getListeners(this);
|
2043 | let node = listeners.get(eventName);
|
2044 | while (node != null) {
|
2045 | if (node.listenerType === ATTRIBUTE) {
|
2046 | return node.listener
|
2047 | }
|
2048 | node = node.next;
|
2049 | }
|
2050 | return null
|
2051 | },
|
2052 |
|
2053 | set(listener) {
|
2054 | if (typeof listener !== "function" && !isObject(listener)) {
|
2055 | listener = null;
|
2056 | }
|
2057 | const listeners = getListeners(this);
|
2058 |
|
2059 |
|
2060 | let prev = null;
|
2061 | let node = listeners.get(eventName);
|
2062 | while (node != null) {
|
2063 | if (node.listenerType === ATTRIBUTE) {
|
2064 |
|
2065 | if (prev !== null) {
|
2066 | prev.next = node.next;
|
2067 | } else if (node.next !== null) {
|
2068 | listeners.set(eventName, node.next);
|
2069 | } else {
|
2070 | listeners.delete(eventName);
|
2071 | }
|
2072 | } else {
|
2073 | prev = node;
|
2074 | }
|
2075 |
|
2076 | node = node.next;
|
2077 | }
|
2078 |
|
2079 |
|
2080 | if (listener !== null) {
|
2081 | const newNode = {
|
2082 | listener,
|
2083 | listenerType: ATTRIBUTE,
|
2084 | passive: false,
|
2085 | once: false,
|
2086 | next: null,
|
2087 | };
|
2088 | if (prev === null) {
|
2089 | listeners.set(eventName, newNode);
|
2090 | } else {
|
2091 | prev.next = newNode;
|
2092 | }
|
2093 | }
|
2094 | },
|
2095 | configurable: true,
|
2096 | enumerable: true,
|
2097 | }
|
2098 | }
|
2099 |
|
2100 |
|
2101 |
|
2102 |
|
2103 |
|
2104 |
|
2105 |
|
2106 | function defineEventAttribute(eventTargetPrototype, eventName) {
|
2107 | Object.defineProperty(
|
2108 | eventTargetPrototype,
|
2109 | `on${eventName}`,
|
2110 | defineEventAttributeDescriptor(eventName)
|
2111 | );
|
2112 | }
|
2113 |
|
2114 |
|
2115 |
|
2116 |
|
2117 |
|
2118 |
|
2119 |
|
2120 | function defineCustomEventTarget(eventNames) {
|
2121 |
|
2122 | function CustomEventTarget() {
|
2123 | EventTarget.call(this);
|
2124 | }
|
2125 |
|
2126 | CustomEventTarget.prototype = Object.create(EventTarget.prototype, {
|
2127 | constructor: {
|
2128 | value: CustomEventTarget,
|
2129 | configurable: true,
|
2130 | writable: true,
|
2131 | },
|
2132 | });
|
2133 |
|
2134 | for (let i = 0; i < eventNames.length; ++i) {
|
2135 | defineEventAttribute(CustomEventTarget.prototype, eventNames[i]);
|
2136 | }
|
2137 |
|
2138 | return CustomEventTarget
|
2139 | }
|
2140 |
|
2141 |
|
2142 |
|
2143 |
|
2144 |
|
2145 |
|
2146 |
|
2147 |
|
2148 |
|
2149 |
|
2150 |
|
2151 |
|
2152 |
|
2153 |
|
2154 | function EventTarget() {
|
2155 |
|
2156 | if (this instanceof EventTarget) {
|
2157 | listenersMap.set(this, new Map());
|
2158 | return
|
2159 | }
|
2160 | if (arguments.length === 1 && Array.isArray(arguments[0])) {
|
2161 | return defineCustomEventTarget(arguments[0])
|
2162 | }
|
2163 | if (arguments.length > 0) {
|
2164 | const types = new Array(arguments.length);
|
2165 | for (let i = 0; i < arguments.length; ++i) {
|
2166 | types[i] = arguments[i];
|
2167 | }
|
2168 | return defineCustomEventTarget(types)
|
2169 | }
|
2170 | throw new TypeError("Cannot call a class as a function")
|
2171 |
|
2172 | }
|
2173 |
|
2174 |
|
2175 | EventTarget.prototype = {
|
2176 | |
2177 |
|
2178 |
|
2179 |
|
2180 |
|
2181 |
|
2182 |
|
2183 | addEventListener(eventName, listener, options) {
|
2184 | if (listener == null) {
|
2185 | return
|
2186 | }
|
2187 | if (typeof listener !== "function" && !isObject(listener)) {
|
2188 | throw new TypeError("'listener' should be a function or an object.")
|
2189 | }
|
2190 |
|
2191 | const listeners = getListeners(this);
|
2192 | const optionsIsObj = isObject(options);
|
2193 | const capture = optionsIsObj
|
2194 | ? Boolean(options.capture)
|
2195 | : Boolean(options);
|
2196 | const listenerType = capture ? CAPTURE : BUBBLE;
|
2197 | const newNode = {
|
2198 | listener,
|
2199 | listenerType,
|
2200 | passive: optionsIsObj && Boolean(options.passive),
|
2201 | once: optionsIsObj && Boolean(options.once),
|
2202 | next: null,
|
2203 | };
|
2204 |
|
2205 |
|
2206 | let node = listeners.get(eventName);
|
2207 | if (node === undefined) {
|
2208 | listeners.set(eventName, newNode);
|
2209 | return
|
2210 | }
|
2211 |
|
2212 |
|
2213 | let prev = null;
|
2214 | while (node != null) {
|
2215 | if (
|
2216 | node.listener === listener &&
|
2217 | node.listenerType === listenerType
|
2218 | ) {
|
2219 |
|
2220 | return
|
2221 | }
|
2222 | prev = node;
|
2223 | node = node.next;
|
2224 | }
|
2225 |
|
2226 |
|
2227 | prev.next = newNode;
|
2228 | },
|
2229 |
|
2230 | |
2231 |
|
2232 |
|
2233 |
|
2234 |
|
2235 |
|
2236 |
|
2237 | removeEventListener(eventName, listener, options) {
|
2238 | if (listener == null) {
|
2239 | return
|
2240 | }
|
2241 |
|
2242 | const listeners = getListeners(this);
|
2243 | const capture = isObject(options)
|
2244 | ? Boolean(options.capture)
|
2245 | : Boolean(options);
|
2246 | const listenerType = capture ? CAPTURE : BUBBLE;
|
2247 |
|
2248 | let prev = null;
|
2249 | let node = listeners.get(eventName);
|
2250 | while (node != null) {
|
2251 | if (
|
2252 | node.listener === listener &&
|
2253 | node.listenerType === listenerType
|
2254 | ) {
|
2255 | if (prev !== null) {
|
2256 | prev.next = node.next;
|
2257 | } else if (node.next !== null) {
|
2258 | listeners.set(eventName, node.next);
|
2259 | } else {
|
2260 | listeners.delete(eventName);
|
2261 | }
|
2262 | return
|
2263 | }
|
2264 |
|
2265 | prev = node;
|
2266 | node = node.next;
|
2267 | }
|
2268 | },
|
2269 |
|
2270 | |
2271 |
|
2272 |
|
2273 |
|
2274 |
|
2275 | dispatchEvent(event) {
|
2276 | if (event == null || typeof event.type !== "string") {
|
2277 | throw new TypeError('"event.type" should be a string.')
|
2278 | }
|
2279 |
|
2280 |
|
2281 | const listeners = getListeners(this);
|
2282 | const eventName = event.type;
|
2283 | let node = listeners.get(eventName);
|
2284 | if (node == null) {
|
2285 | return true
|
2286 | }
|
2287 |
|
2288 |
|
2289 | const wrappedEvent = wrapEvent(this, event);
|
2290 |
|
2291 |
|
2292 |
|
2293 | let prev = null;
|
2294 | while (node != null) {
|
2295 |
|
2296 | if (node.once) {
|
2297 | if (prev !== null) {
|
2298 | prev.next = node.next;
|
2299 | } else if (node.next !== null) {
|
2300 | listeners.set(eventName, node.next);
|
2301 | } else {
|
2302 | listeners.delete(eventName);
|
2303 | }
|
2304 | } else {
|
2305 | prev = node;
|
2306 | }
|
2307 |
|
2308 |
|
2309 | setPassiveListener(
|
2310 | wrappedEvent,
|
2311 | node.passive ? node.listener : null
|
2312 | );
|
2313 | if (typeof node.listener === "function") {
|
2314 | try {
|
2315 | node.listener.call(this, wrappedEvent);
|
2316 | } catch (err) {
|
2317 | if (
|
2318 | typeof console !== "undefined" &&
|
2319 | typeof console.error === "function"
|
2320 | ) {
|
2321 | console.error(err);
|
2322 | }
|
2323 | }
|
2324 | } else if (
|
2325 | node.listenerType !== ATTRIBUTE &&
|
2326 | typeof node.listener.handleEvent === "function"
|
2327 | ) {
|
2328 | node.listener.handleEvent(wrappedEvent);
|
2329 | }
|
2330 |
|
2331 |
|
2332 | if (isStopped(wrappedEvent)) {
|
2333 | break
|
2334 | }
|
2335 |
|
2336 | node = node.next;
|
2337 | }
|
2338 | setPassiveListener(wrappedEvent, null);
|
2339 | setEventPhase(wrappedEvent, 0);
|
2340 | setCurrentTarget(wrappedEvent, null);
|
2341 |
|
2342 | return !wrappedEvent.defaultPrevented
|
2343 | },
|
2344 | };
|
2345 |
|
2346 |
|
2347 | Object.defineProperty(EventTarget.prototype, "constructor", {
|
2348 | value: EventTarget,
|
2349 | configurable: true,
|
2350 | writable: true,
|
2351 | });
|
2352 |
|
2353 |
|
2354 | if (
|
2355 | typeof window !== "undefined" &&
|
2356 | typeof window.EventTarget !== "undefined"
|
2357 | ) {
|
2358 | Object.setPrototypeOf(EventTarget.prototype, window.EventTarget.prototype);
|
2359 | }
|
2360 |
|
2361 |
|
2362 |
|
2363 |
|
2364 |
|
2365 |
|
2366 |
|
2367 |
|
2368 |
|
2369 |
|
2370 | class AbortSignal extends EventTarget {
|
2371 | |
2372 |
|
2373 |
|
2374 | constructor() {
|
2375 | super();
|
2376 | throw new TypeError("AbortSignal cannot be constructed directly");
|
2377 | }
|
2378 | |
2379 |
|
2380 |
|
2381 | get aborted() {
|
2382 | const aborted = abortedFlags.get(this);
|
2383 | if (typeof aborted !== "boolean") {
|
2384 | throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this === null ? "null" : typeof this}`);
|
2385 | }
|
2386 | return aborted;
|
2387 | }
|
2388 | }
|
2389 | defineEventAttribute(AbortSignal.prototype, "abort");
|
2390 |
|
2391 |
|
2392 |
|
2393 | function createAbortSignal() {
|
2394 | const signal = Object.create(AbortSignal.prototype);
|
2395 | EventTarget.call(signal);
|
2396 | abortedFlags.set(signal, false);
|
2397 | return signal;
|
2398 | }
|
2399 |
|
2400 |
|
2401 |
|
2402 | function abortSignal(signal) {
|
2403 | if (abortedFlags.get(signal) !== false) {
|
2404 | return;
|
2405 | }
|
2406 | abortedFlags.set(signal, true);
|
2407 | signal.dispatchEvent({ type: "abort" });
|
2408 | }
|
2409 |
|
2410 |
|
2411 |
|
2412 | const abortedFlags = new WeakMap();
|
2413 |
|
2414 | Object.defineProperties(AbortSignal.prototype, {
|
2415 | aborted: { enumerable: true },
|
2416 | });
|
2417 |
|
2418 | if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
|
2419 | Object.defineProperty(AbortSignal.prototype, Symbol.toStringTag, {
|
2420 | configurable: true,
|
2421 | value: "AbortSignal",
|
2422 | });
|
2423 | }
|
2424 |
|
2425 |
|
2426 |
|
2427 |
|
2428 |
|
2429 | class AbortController {
|
2430 | |
2431 |
|
2432 |
|
2433 | constructor() {
|
2434 | signals.set(this, createAbortSignal());
|
2435 | }
|
2436 | |
2437 |
|
2438 |
|
2439 | get signal() {
|
2440 | return getSignal(this);
|
2441 | }
|
2442 | |
2443 |
|
2444 |
|
2445 | abort() {
|
2446 | abortSignal(getSignal(this));
|
2447 | }
|
2448 | }
|
2449 |
|
2450 |
|
2451 |
|
2452 | const signals = new WeakMap();
|
2453 |
|
2454 |
|
2455 |
|
2456 | function getSignal(controller) {
|
2457 | const signal = signals.get(controller);
|
2458 | if (signal == null) {
|
2459 | throw new TypeError(`Expected 'this' to be an 'AbortController' object, but got ${controller === null ? "null" : typeof controller}`);
|
2460 | }
|
2461 | return signal;
|
2462 | }
|
2463 |
|
2464 | Object.defineProperties(AbortController.prototype, {
|
2465 | signal: { enumerable: true },
|
2466 | abort: { enumerable: true },
|
2467 | });
|
2468 | if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
|
2469 | Object.defineProperty(AbortController.prototype, Symbol.toStringTag, {
|
2470 | configurable: true,
|
2471 | value: "AbortController",
|
2472 | });
|
2473 | }
|
2474 |
|
2475 |
|
2476 | var RestError = (function (_super) {
|
2477 | tslib.__extends(RestError, _super);
|
2478 | function RestError(message, code, statusCode, request, response, body) {
|
2479 | var _this = _super.call(this, message) || this;
|
2480 | _this.code = code;
|
2481 | _this.statusCode = statusCode;
|
2482 | _this.request = request;
|
2483 | _this.response = response;
|
2484 | _this.body = body;
|
2485 | Object.setPrototypeOf(_this, RestError.prototype);
|
2486 | return _this;
|
2487 | }
|
2488 | RestError.REQUEST_SEND_ERROR = "REQUEST_SEND_ERROR";
|
2489 | RestError.REQUEST_ABORTED_ERROR = "REQUEST_ABORTED_ERROR";
|
2490 | RestError.PARSE_ERROR = "PARSE_ERROR";
|
2491 | return RestError;
|
2492 | }(Error));
|
2493 |
|
2494 |
|
2495 | var FetchHttpClient = (function () {
|
2496 | function FetchHttpClient() {
|
2497 | }
|
2498 | FetchHttpClient.prototype.sendRequest = function (httpRequest) {
|
2499 | return tslib.__awaiter(this, void 0, void 0, function () {
|
2500 | var abortController, abortListener, formData, requestForm_1, appendFormValue, _i, _a, formKey, formValue, j, contentType, body, loadedBytes_1, uploadReportStream, platformSpecificRequestInit, requestInit, operationResponse, response, headers, _b, _c, onDownloadProgress_1, responseBody, loadedBytes_2, downloadReportStream, length_1, error_1, fetchError, uploadStreamDone, downloadStreamDone;
|
2501 | return tslib.__generator(this, function (_d) {
|
2502 | switch (_d.label) {
|
2503 | case 0:
|
2504 | if (!httpRequest && typeof httpRequest !== "object") {
|
2505 | throw new Error("'httpRequest' (WebResource) cannot be null or undefined and must be of type object.");
|
2506 | }
|
2507 | abortController = new AbortController();
|
2508 | if (httpRequest.abortSignal) {
|
2509 | if (httpRequest.abortSignal.aborted) {
|
2510 | throw new RestError("The request was aborted", RestError.REQUEST_ABORTED_ERROR, undefined, httpRequest);
|
2511 | }
|
2512 | abortListener = function (event) {
|
2513 | if (event.type === "abort") {
|
2514 | abortController.abort();
|
2515 | }
|
2516 | };
|
2517 | httpRequest.abortSignal.addEventListener("abort", abortListener);
|
2518 | }
|
2519 | if (httpRequest.timeout) {
|
2520 | setTimeout(function () {
|
2521 | abortController.abort();
|
2522 | }, httpRequest.timeout);
|
2523 | }
|
2524 | if (httpRequest.formData) {
|
2525 | formData = httpRequest.formData;
|
2526 | requestForm_1 = new FormData();
|
2527 | appendFormValue = function (key, value) {
|
2528 |
|
2529 | if (typeof value === "function") {
|
2530 | value = value();
|
2531 | }
|
2532 | if (value && value.hasOwnProperty("value") && value.hasOwnProperty("options")) {
|
2533 | requestForm_1.append(key, value.value, value.options);
|
2534 | }
|
2535 | else {
|
2536 | requestForm_1.append(key, value);
|
2537 | }
|
2538 | };
|
2539 | for (_i = 0, _a = Object.keys(formData); _i < _a.length; _i++) {
|
2540 | formKey = _a[_i];
|
2541 | formValue = formData[formKey];
|
2542 | if (Array.isArray(formValue)) {
|
2543 | for (j = 0; j < formValue.length; j++) {
|
2544 | appendFormValue(formKey, formValue[j]);
|
2545 | }
|
2546 | }
|
2547 | else {
|
2548 | appendFormValue(formKey, formValue);
|
2549 | }
|
2550 | }
|
2551 | httpRequest.body = requestForm_1;
|
2552 | httpRequest.formData = undefined;
|
2553 | contentType = httpRequest.headers.get("Content-Type");
|
2554 | if (contentType && contentType.indexOf("multipart/form-data") !== -1) {
|
2555 | if (typeof requestForm_1.getBoundary === "function") {
|
2556 | httpRequest.headers.set("Content-Type", "multipart/form-data; boundary=" + requestForm_1.getBoundary());
|
2557 | }
|
2558 | else {
|
2559 |
|
2560 | httpRequest.headers.remove("Content-Type");
|
2561 | }
|
2562 | }
|
2563 | }
|
2564 | body = httpRequest.body
|
2565 | ? typeof httpRequest.body === "function"
|
2566 | ? httpRequest.body()
|
2567 | : httpRequest.body
|
2568 | : undefined;
|
2569 | if (httpRequest.onUploadProgress && httpRequest.body) {
|
2570 | loadedBytes_1 = 0;
|
2571 | uploadReportStream = new stream.Transform({
|
2572 | transform: function (chunk, _encoding, callback) {
|
2573 | loadedBytes_1 += chunk.length;
|
2574 | httpRequest.onUploadProgress({ loadedBytes: loadedBytes_1 });
|
2575 | callback(undefined, chunk);
|
2576 | },
|
2577 | });
|
2578 | if (isReadableStream(body)) {
|
2579 | body.pipe(uploadReportStream);
|
2580 | }
|
2581 | else {
|
2582 | uploadReportStream.end(body);
|
2583 | }
|
2584 | body = uploadReportStream;
|
2585 | }
|
2586 | return [4 , this.prepareRequest(httpRequest)];
|
2587 | case 1:
|
2588 | platformSpecificRequestInit = _d.sent();
|
2589 | requestInit = tslib.__assign({ body: body, headers: httpRequest.headers.rawHeaders(), method: httpRequest.method, signal: abortController.signal, redirect: "manual" }, platformSpecificRequestInit);
|
2590 | _d.label = 2;
|
2591 | case 2:
|
2592 | _d.trys.push([2, 8, 9, 10]);
|
2593 | return [4 , this.fetch(httpRequest.url, requestInit)];
|
2594 | case 3:
|
2595 | response = _d.sent();
|
2596 | headers = parseHeaders(response.headers);
|
2597 | _b = {
|
2598 | headers: headers,
|
2599 | request: httpRequest,
|
2600 | status: response.status,
|
2601 | readableStreamBody: httpRequest.streamResponseBody
|
2602 | ? response.body
|
2603 | : undefined
|
2604 | };
|
2605 | if (!!httpRequest.streamResponseBody) return [3 , 5];
|
2606 | return [4 , response.text()];
|
2607 | case 4:
|
2608 | _c = _d.sent();
|
2609 | return [3 , 6];
|
2610 | case 5:
|
2611 | _c = undefined;
|
2612 | _d.label = 6;
|
2613 | case 6:
|
2614 | operationResponse = (_b.bodyAsText = _c,
|
2615 | _b.redirected = response.redirected,
|
2616 | _b.url = response.url,
|
2617 | _b);
|
2618 | onDownloadProgress_1 = httpRequest.onDownloadProgress;
|
2619 | if (onDownloadProgress_1) {
|
2620 | responseBody = response.body || undefined;
|
2621 | if (isReadableStream(responseBody)) {
|
2622 | loadedBytes_2 = 0;
|
2623 | downloadReportStream = new stream.Transform({
|
2624 | transform: function (chunk, _encoding, callback) {
|
2625 | loadedBytes_2 += chunk.length;
|
2626 | onDownloadProgress_1({ loadedBytes: loadedBytes_2 });
|
2627 | callback(undefined, chunk);
|
2628 | },
|
2629 | });
|
2630 | responseBody.pipe(downloadReportStream);
|
2631 | operationResponse.readableStreamBody = downloadReportStream;
|
2632 | }
|
2633 | else {
|
2634 | length_1 = parseInt(headers.get("Content-Length")) || undefined;
|
2635 | if (length_1) {
|
2636 |
|
2637 | onDownloadProgress_1({ loadedBytes: length_1 });
|
2638 | }
|
2639 | }
|
2640 | }
|
2641 | return [4 , this.processRequest(operationResponse)];
|
2642 | case 7:
|
2643 | _d.sent();
|
2644 | return [2 , operationResponse];
|
2645 | case 8:
|
2646 | error_1 = _d.sent();
|
2647 | fetchError = error_1;
|
2648 | if (fetchError.code === "ENOTFOUND") {
|
2649 | throw new RestError(fetchError.message, RestError.REQUEST_SEND_ERROR, undefined, httpRequest);
|
2650 | }
|
2651 | else if (fetchError.type === "aborted") {
|
2652 | throw new RestError("The request was aborted", RestError.REQUEST_ABORTED_ERROR, undefined, httpRequest);
|
2653 | }
|
2654 | throw fetchError;
|
2655 | case 9:
|
2656 |
|
2657 | if (httpRequest.abortSignal && abortListener) {
|
2658 | uploadStreamDone = Promise.resolve();
|
2659 | if (isReadableStream(body)) {
|
2660 | uploadStreamDone = isStreamComplete(body);
|
2661 | }
|
2662 | downloadStreamDone = Promise.resolve();
|
2663 | if (isReadableStream(operationResponse === null || operationResponse === void 0 ? void 0 : operationResponse.readableStreamBody)) {
|
2664 | downloadStreamDone = isStreamComplete(operationResponse.readableStreamBody);
|
2665 | }
|
2666 | Promise.all([uploadStreamDone, downloadStreamDone])
|
2667 | .then(function () {
|
2668 | var _a;
|
2669 | (_a = httpRequest.abortSignal) === null || _a === void 0 ? void 0 : _a.removeEventListener("abort", abortListener);
|
2670 | return;
|
2671 | })
|
2672 | .catch(function (_e) { });
|
2673 | }
|
2674 | return [7 ];
|
2675 | case 10: return [2 ];
|
2676 | }
|
2677 | });
|
2678 | });
|
2679 | };
|
2680 | return FetchHttpClient;
|
2681 | }());
|
2682 | function isReadableStream(body) {
|
2683 | return body && typeof body.pipe === "function";
|
2684 | }
|
2685 | function isStreamComplete(stream) {
|
2686 | return new Promise(function (resolve) {
|
2687 | stream.on("close", resolve);
|
2688 | stream.on("end", resolve);
|
2689 | stream.on("error", resolve);
|
2690 | });
|
2691 | }
|
2692 | function parseHeaders(headers) {
|
2693 | var httpHeaders = new HttpHeaders();
|
2694 | headers.forEach(function (value, key) {
|
2695 | httpHeaders.set(key, value);
|
2696 | });
|
2697 | return httpHeaders;
|
2698 | }
|
2699 |
|
2700 |
|
2701 |
|
2702 |
|
2703 |
|
2704 | var URLQuery = (function () {
|
2705 | function URLQuery() {
|
2706 | this._rawQuery = {};
|
2707 | }
|
2708 | |
2709 |
|
2710 |
|
2711 | URLQuery.prototype.any = function () {
|
2712 | return Object.keys(this._rawQuery).length > 0;
|
2713 | };
|
2714 | |
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 | URLQuery.prototype.set = function (parameterName, parameterValue) {
|
2720 | if (parameterName) {
|
2721 | if (parameterValue != undefined) {
|
2722 | var newValue = Array.isArray(parameterValue) ? parameterValue : parameterValue.toString();
|
2723 | this._rawQuery[parameterName] = newValue;
|
2724 | }
|
2725 | else {
|
2726 | delete this._rawQuery[parameterName];
|
2727 | }
|
2728 | }
|
2729 | };
|
2730 | |
2731 |
|
2732 |
|
2733 |
|
2734 | URLQuery.prototype.get = function (parameterName) {
|
2735 | return parameterName ? this._rawQuery[parameterName] : undefined;
|
2736 | };
|
2737 | |
2738 |
|
2739 |
|
2740 | URLQuery.prototype.toString = function () {
|
2741 | var result = "";
|
2742 | for (var parameterName in this._rawQuery) {
|
2743 | if (result) {
|
2744 | result += "&";
|
2745 | }
|
2746 | var parameterValue = this._rawQuery[parameterName];
|
2747 | if (Array.isArray(parameterValue)) {
|
2748 | var parameterStrings = [];
|
2749 | for (var _i = 0, parameterValue_1 = parameterValue; _i < parameterValue_1.length; _i++) {
|
2750 | var parameterValueElement = parameterValue_1[_i];
|
2751 | parameterStrings.push(parameterName + "=" + parameterValueElement);
|
2752 | }
|
2753 | result += parameterStrings.join("&");
|
2754 | }
|
2755 | else {
|
2756 | result += parameterName + "=" + parameterValue;
|
2757 | }
|
2758 | }
|
2759 | return result;
|
2760 | };
|
2761 | |
2762 |
|
2763 |
|
2764 | URLQuery.parse = function (text) {
|
2765 | var result = new URLQuery();
|
2766 | if (text) {
|
2767 | if (text.startsWith("?")) {
|
2768 | text = text.substring(1);
|
2769 | }
|
2770 | var currentState = "ParameterName";
|
2771 | var parameterName = "";
|
2772 | var parameterValue = "";
|
2773 | for (var i = 0; i < text.length; ++i) {
|
2774 | var currentCharacter = text[i];
|
2775 | switch (currentState) {
|
2776 | case "ParameterName":
|
2777 | switch (currentCharacter) {
|
2778 | case "=":
|
2779 | currentState = "ParameterValue";
|
2780 | break;
|
2781 | case "&":
|
2782 | parameterName = "";
|
2783 | parameterValue = "";
|
2784 | break;
|
2785 | default:
|
2786 | parameterName += currentCharacter;
|
2787 | break;
|
2788 | }
|
2789 | break;
|
2790 | case "ParameterValue":
|
2791 | switch (currentCharacter) {
|
2792 | case "&":
|
2793 | result.set(parameterName, parameterValue);
|
2794 | parameterName = "";
|
2795 | parameterValue = "";
|
2796 | currentState = "ParameterName";
|
2797 | break;
|
2798 | default:
|
2799 | parameterValue += currentCharacter;
|
2800 | break;
|
2801 | }
|
2802 | break;
|
2803 | default:
|
2804 | throw new Error("Unrecognized URLQuery parse state: " + currentState);
|
2805 | }
|
2806 | }
|
2807 | if (currentState === "ParameterValue") {
|
2808 | result.set(parameterName, parameterValue);
|
2809 | }
|
2810 | }
|
2811 | return result;
|
2812 | };
|
2813 | return URLQuery;
|
2814 | }());
|
2815 |
|
2816 |
|
2817 |
|
2818 | var URLBuilder = (function () {
|
2819 | function URLBuilder() {
|
2820 | }
|
2821 | |
2822 |
|
2823 |
|
2824 |
|
2825 | URLBuilder.prototype.setScheme = function (scheme) {
|
2826 | if (!scheme) {
|
2827 | this._scheme = undefined;
|
2828 | }
|
2829 | else {
|
2830 | this.set(scheme, "SCHEME");
|
2831 | }
|
2832 | };
|
2833 | |
2834 |
|
2835 |
|
2836 | URLBuilder.prototype.getScheme = function () {
|
2837 | return this._scheme;
|
2838 | };
|
2839 | |
2840 |
|
2841 |
|
2842 |
|
2843 | URLBuilder.prototype.setHost = function (host) {
|
2844 | if (!host) {
|
2845 | this._host = undefined;
|
2846 | }
|
2847 | else {
|
2848 | this.set(host, "SCHEME_OR_HOST");
|
2849 | }
|
2850 | };
|
2851 | |
2852 |
|
2853 |
|
2854 | URLBuilder.prototype.getHost = function () {
|
2855 | return this._host;
|
2856 | };
|
2857 | |
2858 |
|
2859 |
|
2860 |
|
2861 | URLBuilder.prototype.setPort = function (port) {
|
2862 | if (port == undefined || port === "") {
|
2863 | this._port = undefined;
|
2864 | }
|
2865 | else {
|
2866 | this.set(port.toString(), "PORT");
|
2867 | }
|
2868 | };
|
2869 | |
2870 |
|
2871 |
|
2872 | URLBuilder.prototype.getPort = function () {
|
2873 | return this._port;
|
2874 | };
|
2875 | |
2876 |
|
2877 |
|
2878 |
|
2879 | URLBuilder.prototype.setPath = function (path) {
|
2880 | if (!path) {
|
2881 | this._path = undefined;
|
2882 | }
|
2883 | else {
|
2884 | var schemeIndex = path.indexOf("://");
|
2885 | if (schemeIndex !== -1) {
|
2886 | var schemeStart = path.lastIndexOf("/", schemeIndex);
|
2887 |
|
2888 |
|
2889 | this.set(schemeStart === -1 ? path : path.substr(schemeStart + 1), "SCHEME");
|
2890 | }
|
2891 | else {
|
2892 | this.set(path, "PATH");
|
2893 | }
|
2894 | }
|
2895 | };
|
2896 | |
2897 |
|
2898 |
|
2899 |
|
2900 | URLBuilder.prototype.appendPath = function (path) {
|
2901 | if (path) {
|
2902 | var currentPath = this.getPath();
|
2903 | if (currentPath) {
|
2904 | if (!currentPath.endsWith("/")) {
|
2905 | currentPath += "/";
|
2906 | }
|
2907 | if (path.startsWith("/")) {
|
2908 | path = path.substring(1);
|
2909 | }
|
2910 | path = currentPath + path;
|
2911 | }
|
2912 | this.set(path, "PATH");
|
2913 | }
|
2914 | };
|
2915 | |
2916 |
|
2917 |
|
2918 | URLBuilder.prototype.getPath = function () {
|
2919 | return this._path;
|
2920 | };
|
2921 | |
2922 |
|
2923 |
|
2924 | URLBuilder.prototype.setQuery = function (query) {
|
2925 | if (!query) {
|
2926 | this._query = undefined;
|
2927 | }
|
2928 | else {
|
2929 | this._query = URLQuery.parse(query);
|
2930 | }
|
2931 | };
|
2932 | |
2933 |
|
2934 |
|
2935 |
|
2936 |
|
2937 | URLBuilder.prototype.setQueryParameter = function (queryParameterName, queryParameterValue) {
|
2938 | if (queryParameterName) {
|
2939 | if (!this._query) {
|
2940 | this._query = new URLQuery();
|
2941 | }
|
2942 | this._query.set(queryParameterName, queryParameterValue);
|
2943 | }
|
2944 | };
|
2945 | |
2946 |
|
2947 |
|
2948 |
|
2949 | URLBuilder.prototype.getQueryParameterValue = function (queryParameterName) {
|
2950 | return this._query ? this._query.get(queryParameterName) : undefined;
|
2951 | };
|
2952 | |
2953 |
|
2954 |
|
2955 | URLBuilder.prototype.getQuery = function () {
|
2956 | return this._query ? this._query.toString() : undefined;
|
2957 | };
|
2958 | |
2959 |
|
2960 |
|
2961 | URLBuilder.prototype.set = function (text, startState) {
|
2962 | var tokenizer = new URLTokenizer(text, startState);
|
2963 | while (tokenizer.next()) {
|
2964 | var token = tokenizer.current();
|
2965 | if (token) {
|
2966 | switch (token.type) {
|
2967 | case "SCHEME":
|
2968 | this._scheme = token.text || undefined;
|
2969 | break;
|
2970 | case "HOST":
|
2971 | this._host = token.text || undefined;
|
2972 | break;
|
2973 | case "PORT":
|
2974 | this._port = token.text || undefined;
|
2975 | break;
|
2976 | case "PATH":
|
2977 | var tokenPath = token.text || undefined;
|
2978 | if (!this._path || this._path === "/" || tokenPath !== "/") {
|
2979 | this._path = tokenPath;
|
2980 | }
|
2981 | break;
|
2982 | case "QUERY":
|
2983 | this._query = URLQuery.parse(token.text);
|
2984 | break;
|
2985 | default:
|
2986 | throw new Error("Unrecognized URLTokenType: " + token.type);
|
2987 | }
|
2988 | }
|
2989 | }
|
2990 | };
|
2991 | URLBuilder.prototype.toString = function () {
|
2992 | var result = "";
|
2993 | if (this._scheme) {
|
2994 | result += this._scheme + "://";
|
2995 | }
|
2996 | if (this._host) {
|
2997 | result += this._host;
|
2998 | }
|
2999 | if (this._port) {
|
3000 | result += ":" + this._port;
|
3001 | }
|
3002 | if (this._path) {
|
3003 | if (!this._path.startsWith("/")) {
|
3004 | result += "/";
|
3005 | }
|
3006 | result += this._path;
|
3007 | }
|
3008 | if (this._query && this._query.any()) {
|
3009 | result += "?" + this._query.toString();
|
3010 | }
|
3011 | return result;
|
3012 | };
|
3013 | |
3014 |
|
3015 |
|
3016 |
|
3017 | URLBuilder.prototype.replaceAll = function (searchValue, replaceValue) {
|
3018 | if (searchValue) {
|
3019 | this.setScheme(replaceAll(this.getScheme(), searchValue, replaceValue));
|
3020 | this.setHost(replaceAll(this.getHost(), searchValue, replaceValue));
|
3021 | this.setPort(replaceAll(this.getPort(), searchValue, replaceValue));
|
3022 | this.setPath(replaceAll(this.getPath(), searchValue, replaceValue));
|
3023 | this.setQuery(replaceAll(this.getQuery(), searchValue, replaceValue));
|
3024 | }
|
3025 | };
|
3026 | URLBuilder.parse = function (text) {
|
3027 | var result = new URLBuilder();
|
3028 | result.set(text, "SCHEME_OR_HOST");
|
3029 | return result;
|
3030 | };
|
3031 | return URLBuilder;
|
3032 | }());
|
3033 | var URLToken = (function () {
|
3034 | function URLToken(text, type) {
|
3035 | this.text = text;
|
3036 | this.type = type;
|
3037 | }
|
3038 | URLToken.scheme = function (text) {
|
3039 | return new URLToken(text, "SCHEME");
|
3040 | };
|
3041 | URLToken.host = function (text) {
|
3042 | return new URLToken(text, "HOST");
|
3043 | };
|
3044 | URLToken.port = function (text) {
|
3045 | return new URLToken(text, "PORT");
|
3046 | };
|
3047 | URLToken.path = function (text) {
|
3048 | return new URLToken(text, "PATH");
|
3049 | };
|
3050 | URLToken.query = function (text) {
|
3051 | return new URLToken(text, "QUERY");
|
3052 | };
|
3053 | return URLToken;
|
3054 | }());
|
3055 |
|
3056 |
|
3057 |
|
3058 |
|
3059 | function isAlphaNumericCharacter(character) {
|
3060 | var characterCode = character.charCodeAt(0);
|
3061 | return ((48 <= characterCode && characterCode <= 57) ||
|
3062 | (65 <= characterCode && characterCode <= 90) ||
|
3063 | (97 <= characterCode && characterCode <= 122) );
|
3064 | }
|
3065 |
|
3066 |
|
3067 |
|
3068 | var URLTokenizer = (function () {
|
3069 | function URLTokenizer(_text, state) {
|
3070 | this._text = _text;
|
3071 | this._textLength = _text ? _text.length : 0;
|
3072 | this._currentState = state != undefined ? state : "SCHEME_OR_HOST";
|
3073 | this._currentIndex = 0;
|
3074 | }
|
3075 | |
3076 |
|
3077 |
|
3078 |
|
3079 | URLTokenizer.prototype.current = function () {
|
3080 | return this._currentToken;
|
3081 | };
|
3082 | |
3083 |
|
3084 |
|
3085 | URLTokenizer.prototype.next = function () {
|
3086 | if (!hasCurrentCharacter(this)) {
|
3087 | this._currentToken = undefined;
|
3088 | }
|
3089 | else {
|
3090 | switch (this._currentState) {
|
3091 | case "SCHEME":
|
3092 | nextScheme(this);
|
3093 | break;
|
3094 | case "SCHEME_OR_HOST":
|
3095 | nextSchemeOrHost(this);
|
3096 | break;
|
3097 | case "HOST":
|
3098 | nextHost(this);
|
3099 | break;
|
3100 | case "PORT":
|
3101 | nextPort(this);
|
3102 | break;
|
3103 | case "PATH":
|
3104 | nextPath(this);
|
3105 | break;
|
3106 | case "QUERY":
|
3107 | nextQuery(this);
|
3108 | break;
|
3109 | default:
|
3110 | throw new Error("Unrecognized URLTokenizerState: " + this._currentState);
|
3111 | }
|
3112 | }
|
3113 | return !!this._currentToken;
|
3114 | };
|
3115 | return URLTokenizer;
|
3116 | }());
|
3117 |
|
3118 |
|
3119 |
|
3120 | function readRemaining(tokenizer) {
|
3121 | var result = "";
|
3122 | if (tokenizer._currentIndex < tokenizer._textLength) {
|
3123 | result = tokenizer._text.substring(tokenizer._currentIndex);
|
3124 | tokenizer._currentIndex = tokenizer._textLength;
|
3125 | }
|
3126 | return result;
|
3127 | }
|
3128 |
|
3129 |
|
3130 |
|
3131 | function hasCurrentCharacter(tokenizer) {
|
3132 | return tokenizer._currentIndex < tokenizer._textLength;
|
3133 | }
|
3134 |
|
3135 |
|
3136 |
|
3137 | function getCurrentCharacter(tokenizer) {
|
3138 | return tokenizer._text[tokenizer._currentIndex];
|
3139 | }
|
3140 |
|
3141 |
|
3142 |
|
3143 |
|
3144 | function nextCharacter(tokenizer, step) {
|
3145 | if (hasCurrentCharacter(tokenizer)) {
|
3146 | if (!step) {
|
3147 | step = 1;
|
3148 | }
|
3149 | tokenizer._currentIndex += step;
|
3150 | }
|
3151 | }
|
3152 |
|
3153 |
|
3154 |
|
3155 |
|
3156 | function peekCharacters(tokenizer, charactersToPeek) {
|
3157 | var endIndex = tokenizer._currentIndex + charactersToPeek;
|
3158 | if (tokenizer._textLength < endIndex) {
|
3159 | endIndex = tokenizer._textLength;
|
3160 | }
|
3161 | return tokenizer._text.substring(tokenizer._currentIndex, endIndex);
|
3162 | }
|
3163 |
|
3164 |
|
3165 |
|
3166 |
|
3167 | function readWhile(tokenizer, condition) {
|
3168 | var result = "";
|
3169 | while (hasCurrentCharacter(tokenizer)) {
|
3170 | var currentCharacter = getCurrentCharacter(tokenizer);
|
3171 | if (!condition(currentCharacter)) {
|
3172 | break;
|
3173 | }
|
3174 | else {
|
3175 | result += currentCharacter;
|
3176 | nextCharacter(tokenizer);
|
3177 | }
|
3178 | }
|
3179 | return result;
|
3180 | }
|
3181 |
|
3182 |
|
3183 |
|
3184 |
|
3185 | function readWhileLetterOrDigit(tokenizer) {
|
3186 | return readWhile(tokenizer, function (character) { return isAlphaNumericCharacter(character); });
|
3187 | }
|
3188 |
|
3189 |
|
3190 |
|
3191 |
|
3192 | function readUntilCharacter(tokenizer) {
|
3193 | var terminatingCharacters = [];
|
3194 | for (var _i = 1; _i < arguments.length; _i++) {
|
3195 | terminatingCharacters[_i - 1] = arguments[_i];
|
3196 | }
|
3197 | return readWhile(tokenizer, function (character) { return terminatingCharacters.indexOf(character) === -1; });
|
3198 | }
|
3199 | function nextScheme(tokenizer) {
|
3200 | var scheme = readWhileLetterOrDigit(tokenizer);
|
3201 | tokenizer._currentToken = URLToken.scheme(scheme);
|
3202 | if (!hasCurrentCharacter(tokenizer)) {
|
3203 | tokenizer._currentState = "DONE";
|
3204 | }
|
3205 | else {
|
3206 | tokenizer._currentState = "HOST";
|
3207 | }
|
3208 | }
|
3209 | function nextSchemeOrHost(tokenizer) {
|
3210 | var schemeOrHost = readUntilCharacter(tokenizer, ":", "/", "?");
|
3211 | if (!hasCurrentCharacter(tokenizer)) {
|
3212 | tokenizer._currentToken = URLToken.host(schemeOrHost);
|
3213 | tokenizer._currentState = "DONE";
|
3214 | }
|
3215 | else if (getCurrentCharacter(tokenizer) === ":") {
|
3216 | if (peekCharacters(tokenizer, 3) === "://") {
|
3217 | tokenizer._currentToken = URLToken.scheme(schemeOrHost);
|
3218 | tokenizer._currentState = "HOST";
|
3219 | }
|
3220 | else {
|
3221 | tokenizer._currentToken = URLToken.host(schemeOrHost);
|
3222 | tokenizer._currentState = "PORT";
|
3223 | }
|
3224 | }
|
3225 | else {
|
3226 | tokenizer._currentToken = URLToken.host(schemeOrHost);
|
3227 | if (getCurrentCharacter(tokenizer) === "/") {
|
3228 | tokenizer._currentState = "PATH";
|
3229 | }
|
3230 | else {
|
3231 | tokenizer._currentState = "QUERY";
|
3232 | }
|
3233 | }
|
3234 | }
|
3235 | function nextHost(tokenizer) {
|
3236 | if (peekCharacters(tokenizer, 3) === "://") {
|
3237 | nextCharacter(tokenizer, 3);
|
3238 | }
|
3239 | var host = readUntilCharacter(tokenizer, ":", "/", "?");
|
3240 | tokenizer._currentToken = URLToken.host(host);
|
3241 | if (!hasCurrentCharacter(tokenizer)) {
|
3242 | tokenizer._currentState = "DONE";
|
3243 | }
|
3244 | else if (getCurrentCharacter(tokenizer) === ":") {
|
3245 | tokenizer._currentState = "PORT";
|
3246 | }
|
3247 | else if (getCurrentCharacter(tokenizer) === "/") {
|
3248 | tokenizer._currentState = "PATH";
|
3249 | }
|
3250 | else {
|
3251 | tokenizer._currentState = "QUERY";
|
3252 | }
|
3253 | }
|
3254 | function nextPort(tokenizer) {
|
3255 | if (getCurrentCharacter(tokenizer) === ":") {
|
3256 | nextCharacter(tokenizer);
|
3257 | }
|
3258 | var port = readUntilCharacter(tokenizer, "/", "?");
|
3259 | tokenizer._currentToken = URLToken.port(port);
|
3260 | if (!hasCurrentCharacter(tokenizer)) {
|
3261 | tokenizer._currentState = "DONE";
|
3262 | }
|
3263 | else if (getCurrentCharacter(tokenizer) === "/") {
|
3264 | tokenizer._currentState = "PATH";
|
3265 | }
|
3266 | else {
|
3267 | tokenizer._currentState = "QUERY";
|
3268 | }
|
3269 | }
|
3270 | function nextPath(tokenizer) {
|
3271 | var path = readUntilCharacter(tokenizer, "?");
|
3272 | tokenizer._currentToken = URLToken.path(path);
|
3273 | if (!hasCurrentCharacter(tokenizer)) {
|
3274 | tokenizer._currentState = "DONE";
|
3275 | }
|
3276 | else {
|
3277 | tokenizer._currentState = "QUERY";
|
3278 | }
|
3279 | }
|
3280 | function nextQuery(tokenizer) {
|
3281 | if (getCurrentCharacter(tokenizer) === "?") {
|
3282 | nextCharacter(tokenizer);
|
3283 | }
|
3284 | var query = readRemaining(tokenizer);
|
3285 | tokenizer._currentToken = URLToken.query(query);
|
3286 | tokenizer._currentState = "DONE";
|
3287 | }
|
3288 |
|
3289 |
|
3290 | function createProxyAgent(requestUrl, proxySettings, headers) {
|
3291 | var tunnelOptions = {
|
3292 | proxy: {
|
3293 | host: URLBuilder.parse(proxySettings.host).getHost(),
|
3294 | port: proxySettings.port,
|
3295 | headers: (headers && headers.rawHeaders()) || {},
|
3296 | },
|
3297 | };
|
3298 | if (proxySettings.username && proxySettings.password) {
|
3299 | tunnelOptions.proxy.proxyAuth = proxySettings.username + ":" + proxySettings.password;
|
3300 | }
|
3301 | else if (proxySettings.username) {
|
3302 | tunnelOptions.proxy.proxyAuth = "" + proxySettings.username;
|
3303 | }
|
3304 | var requestScheme = URLBuilder.parse(requestUrl).getScheme() || "";
|
3305 | var isRequestHttps = requestScheme.toLowerCase() === "https";
|
3306 | var proxyScheme = URLBuilder.parse(proxySettings.host).getScheme() || "";
|
3307 | var isProxyHttps = proxyScheme.toLowerCase() === "https";
|
3308 | var proxyAgent = {
|
3309 | isHttps: isRequestHttps,
|
3310 | agent: createTunnel(isRequestHttps, isProxyHttps, tunnelOptions),
|
3311 | };
|
3312 | return proxyAgent;
|
3313 | }
|
3314 | function createTunnel(isRequestHttps, isProxyHttps, tunnelOptions) {
|
3315 | if (isRequestHttps && isProxyHttps) {
|
3316 | return tunnel.httpsOverHttps(tunnelOptions);
|
3317 | }
|
3318 | else if (isRequestHttps && !isProxyHttps) {
|
3319 | return tunnel.httpsOverHttp(tunnelOptions);
|
3320 | }
|
3321 | else if (!isRequestHttps && isProxyHttps) {
|
3322 | return tunnel.httpOverHttps(tunnelOptions);
|
3323 | }
|
3324 | else {
|
3325 | return tunnel.httpOverHttp(tunnelOptions);
|
3326 | }
|
3327 | }
|
3328 |
|
3329 |
|
3330 | var NodeFetchHttpClient = (function (_super) {
|
3331 | tslib.__extends(NodeFetchHttpClient, _super);
|
3332 | function NodeFetchHttpClient() {
|
3333 | return _super !== null && _super.apply(this, arguments) || this;
|
3334 | }
|
3335 | NodeFetchHttpClient.prototype.fetch = function (input, init) {
|
3336 | return tslib.__awaiter(this, void 0, void 0, function () {
|
3337 | return tslib.__generator(this, function (_a) {
|
3338 | return [2 , node_fetch(input, init)];
|
3339 | });
|
3340 | });
|
3341 | };
|
3342 | NodeFetchHttpClient.prototype.prepareRequest = function (httpRequest) {
|
3343 | return tslib.__awaiter(this, void 0, void 0, function () {
|
3344 | var requestInit, _a, httpAgent, httpsAgent, tunnel, options, agent;
|
3345 | return tslib.__generator(this, function (_b) {
|
3346 | requestInit = {};
|
3347 | if (httpRequest.agentSettings) {
|
3348 | _a = httpRequest.agentSettings, httpAgent = _a.http, httpsAgent = _a.https;
|
3349 | if (httpsAgent && httpRequest.url.startsWith("https")) {
|
3350 | requestInit.agent = httpsAgent;
|
3351 | }
|
3352 | else if (httpAgent) {
|
3353 | requestInit.agent = httpAgent;
|
3354 | }
|
3355 | }
|
3356 | else if (httpRequest.proxySettings) {
|
3357 | tunnel = createProxyAgent(httpRequest.url, httpRequest.proxySettings, httpRequest.headers);
|
3358 | requestInit.agent = tunnel.agent;
|
3359 | }
|
3360 | if (httpRequest.keepAlive === true) {
|
3361 | if (requestInit.agent) {
|
3362 | requestInit.agent.keepAlive = true;
|
3363 | }
|
3364 | else {
|
3365 | options = { keepAlive: true };
|
3366 | agent = httpRequest.url.startsWith("https")
|
3367 | ? new https.Agent(options)
|
3368 | : new http.Agent(options);
|
3369 | requestInit.agent = agent;
|
3370 | }
|
3371 | }
|
3372 | return [2 , requestInit];
|
3373 | });
|
3374 | });
|
3375 | };
|
3376 | NodeFetchHttpClient.prototype.processRequest = function (_operationResponse) {
|
3377 | return tslib.__awaiter(this, void 0, void 0, function () {
|
3378 | return tslib.__generator(this, function (_a) {
|
3379 |
|
3380 | return [2 ];
|
3381 | });
|
3382 | });
|
3383 | };
|
3384 | return NodeFetchHttpClient;
|
3385 | }(FetchHttpClient));
|
3386 |
|
3387 |
|
3388 | (function (HttpPipelineLogLevel) {
|
3389 | |
3390 |
|
3391 |
|
3392 | HttpPipelineLogLevel[HttpPipelineLogLevel["OFF"] = 0] = "OFF";
|
3393 | |
3394 |
|
3395 |
|
3396 | HttpPipelineLogLevel[HttpPipelineLogLevel["ERROR"] = 1] = "ERROR";
|
3397 | |
3398 |
|
3399 |
|
3400 | HttpPipelineLogLevel[HttpPipelineLogLevel["WARNING"] = 2] = "WARNING";
|
3401 | |
3402 |
|
3403 |
|
3404 | HttpPipelineLogLevel[HttpPipelineLogLevel["INFO"] = 3] = "INFO";
|
3405 | })(exports.HttpPipelineLogLevel || (exports.HttpPipelineLogLevel = {}));
|
3406 |
|
3407 |
|
3408 |
|
3409 |
|
3410 |
|
3411 |
|
3412 |
|
3413 |
|
3414 | function isTokenCredential(credential) {
|
3415 |
|
3416 |
|
3417 |
|
3418 |
|
3419 |
|
3420 | const castCredential = credential;
|
3421 | return (castCredential &&
|
3422 | typeof castCredential.getToken === "function" &&
|
3423 | (castCredential.signRequest === undefined || castCredential.getToken.length > 0));
|
3424 | }
|
3425 |
|
3426 |
|
3427 |
|
3428 |
|
3429 |
|
3430 |
|
3431 |
|
3432 |
|
3433 | function getPathStringFromParameter(parameter) {
|
3434 | return getPathStringFromParameterPath(parameter.parameterPath, parameter.mapper);
|
3435 | }
|
3436 | function getPathStringFromParameterPath(parameterPath, mapper) {
|
3437 | var result;
|
3438 | if (typeof parameterPath === "string") {
|
3439 | result = parameterPath;
|
3440 | }
|
3441 | else if (Array.isArray(parameterPath)) {
|
3442 | result = parameterPath.join(".");
|
3443 | }
|
3444 | else {
|
3445 | result = mapper.serializedName;
|
3446 | }
|
3447 | return result;
|
3448 | }
|
3449 |
|
3450 |
|
3451 | function isStreamOperation(operationSpec) {
|
3452 | var result = false;
|
3453 | for (var statusCode in operationSpec.responses) {
|
3454 | var operationResponse = operationSpec.responses[statusCode];
|
3455 | if (operationResponse.bodyMapper &&
|
3456 | operationResponse.bodyMapper.type.name === MapperType.Stream) {
|
3457 | result = true;
|
3458 | break;
|
3459 | }
|
3460 | }
|
3461 | return result;
|
3462 | }
|
3463 |
|
3464 |
|
3465 | function stringifyXML(obj, opts) {
|
3466 | var builder = new xml2js.Builder({
|
3467 | rootName: (opts || {}).rootName,
|
3468 | renderOpts: {
|
3469 | pretty: false,
|
3470 | },
|
3471 | });
|
3472 | return builder.buildObject(obj);
|
3473 | }
|
3474 | function parseXML(str) {
|
3475 | var xmlParser = new xml2js.Parser({
|
3476 | explicitArray: false,
|
3477 | explicitCharkey: false,
|
3478 | explicitRoot: false,
|
3479 | });
|
3480 | return new Promise(function (resolve, reject) {
|
3481 | if (!str) {
|
3482 | reject(new Error("Document is empty"));
|
3483 | }
|
3484 | else {
|
3485 | xmlParser.parseString(str, function (err, res) {
|
3486 | if (err) {
|
3487 | reject(err);
|
3488 | }
|
3489 | else {
|
3490 | resolve(res);
|
3491 | }
|
3492 | });
|
3493 | }
|
3494 | });
|
3495 | }
|
3496 |
|
3497 |
|
3498 | var BaseRequestPolicy = (function () {
|
3499 | function BaseRequestPolicy(_nextPolicy, _options) {
|
3500 | this._nextPolicy = _nextPolicy;
|
3501 | this._options = _options;
|
3502 | }
|
3503 | |
3504 |
|
3505 |
|
3506 |
|
3507 |
|
3508 | BaseRequestPolicy.prototype.shouldLog = function (logLevel) {
|
3509 | return this._options.shouldLog(logLevel);
|
3510 | };
|
3511 | |
3512 |
|
3513 |
|
3514 |
|
3515 |
|
3516 |
|
3517 | BaseRequestPolicy.prototype.log = function (logLevel, message) {
|
3518 | this._options.log(logLevel, message);
|
3519 | };
|
3520 | return BaseRequestPolicy;
|
3521 | }());
|
3522 |
|
3523 |
|
3524 |
|
3525 | var RequestPolicyOptions = (function () {
|
3526 | function RequestPolicyOptions(_logger) {
|
3527 | this._logger = _logger;
|
3528 | }
|
3529 | |
3530 |
|
3531 |
|
3532 |
|
3533 |
|
3534 | RequestPolicyOptions.prototype.shouldLog = function (logLevel) {
|
3535 | return (!!this._logger &&
|
3536 | logLevel !== exports.HttpPipelineLogLevel.OFF &&
|
3537 | logLevel <= this._logger.minimumLogLevel);
|
3538 | };
|
3539 | |
3540 |
|
3541 |
|
3542 |
|
3543 |
|
3544 |
|
3545 | RequestPolicyOptions.prototype.log = function (logLevel, message) {
|
3546 | if (this._logger && this.shouldLog(logLevel)) {
|
3547 | this._logger.log(logLevel, message);
|
3548 | }
|
3549 | };
|
3550 | return RequestPolicyOptions;
|
3551 | }());
|
3552 |
|
3553 |
|
3554 |
|
3555 |
|
3556 |
|
3557 |
|
3558 | function deserializationPolicy(deserializationContentTypes) {
|
3559 | return {
|
3560 | create: function (nextPolicy, options) {
|
3561 | return new DeserializationPolicy(nextPolicy, deserializationContentTypes, options);
|
3562 | },
|
3563 | };
|
3564 | }
|
3565 | var defaultJsonContentTypes = ["application/json", "text/json"];
|
3566 | var defaultXmlContentTypes = ["application/xml", "application/atom+xml"];
|
3567 |
|
3568 |
|
3569 |
|
3570 |
|
3571 | var DeserializationPolicy = (function (_super) {
|
3572 | tslib.__extends(DeserializationPolicy, _super);
|
3573 | function DeserializationPolicy(nextPolicy, deserializationContentTypes, options) {
|
3574 | var _this = _super.call(this, nextPolicy, options) || this;
|
3575 | _this.jsonContentTypes =
|
3576 | (deserializationContentTypes && deserializationContentTypes.json) || defaultJsonContentTypes;
|
3577 | _this.xmlContentTypes =
|
3578 | (deserializationContentTypes && deserializationContentTypes.xml) || defaultXmlContentTypes;
|
3579 | return _this;
|
3580 | }
|
3581 | DeserializationPolicy.prototype.sendRequest = function (request) {
|
3582 | return tslib.__awaiter(this, void 0, void 0, function () {
|
3583 | var _this = this;
|
3584 | return tslib.__generator(this, function (_a) {
|
3585 | return [2 , this._nextPolicy
|
3586 | .sendRequest(request)
|
3587 | .then(function (response) {
|
3588 | return deserializeResponseBody(_this.jsonContentTypes, _this.xmlContentTypes, response);
|
3589 | })];
|
3590 | });
|
3591 | });
|
3592 | };
|
3593 | return DeserializationPolicy;
|
3594 | }(BaseRequestPolicy));
|
3595 | function getOperationResponse(parsedResponse) {
|
3596 | var result;
|
3597 | var request = parsedResponse.request;
|
3598 | var operationSpec = request.operationSpec;
|
3599 | if (operationSpec) {
|
3600 | var operationResponseGetter = request.operationResponseGetter;
|
3601 | if (!operationResponseGetter) {
|
3602 | result = operationSpec.responses[parsedResponse.status];
|
3603 | }
|
3604 | else {
|
3605 | result = operationResponseGetter(operationSpec, parsedResponse);
|
3606 | }
|
3607 | }
|
3608 | return result;
|
3609 | }
|
3610 | function shouldDeserializeResponse(parsedResponse) {
|
3611 | var shouldDeserialize = parsedResponse.request.shouldDeserialize;
|
3612 | var result;
|
3613 | if (shouldDeserialize === undefined) {
|
3614 | result = true;
|
3615 | }
|
3616 | else if (typeof shouldDeserialize === "boolean") {
|
3617 | result = shouldDeserialize;
|
3618 | }
|
3619 | else {
|
3620 | result = shouldDeserialize(parsedResponse);
|
3621 | }
|
3622 | return result;
|
3623 | }
|
3624 | function deserializeResponseBody(jsonContentTypes, xmlContentTypes, response) {
|
3625 | return parse(jsonContentTypes, xmlContentTypes, response).then(function (parsedResponse) {
|
3626 | var shouldDeserialize = shouldDeserializeResponse(parsedResponse);
|
3627 | if (shouldDeserialize) {
|
3628 | var operationSpec = parsedResponse.request.operationSpec;
|
3629 | if (operationSpec && operationSpec.responses) {
|
3630 | var statusCode = parsedResponse.status;
|
3631 | var expectedStatusCodes = Object.keys(operationSpec.responses);
|
3632 | var hasNoExpectedStatusCodes = expectedStatusCodes.length === 0 ||
|
3633 | (expectedStatusCodes.length === 1 && expectedStatusCodes[0] === "default");
|
3634 | var responseSpec = getOperationResponse(parsedResponse);
|
3635 | var isExpectedStatusCode = hasNoExpectedStatusCodes
|
3636 | ? 200 <= statusCode && statusCode < 300
|
3637 | : !!responseSpec;
|
3638 | if (!isExpectedStatusCode) {
|
3639 | var defaultResponseSpec = operationSpec.responses.default;
|
3640 | if (defaultResponseSpec) {
|
3641 | var initialErrorMessage = isStreamOperation(operationSpec)
|
3642 | ? "Unexpected status code: " + statusCode
|
3643 | : parsedResponse.bodyAsText;
|
3644 | var error = new RestError(initialErrorMessage);
|
3645 | error.statusCode = statusCode;
|
3646 | error.request = stripRequest(parsedResponse.request);
|
3647 | error.response = stripResponse(parsedResponse);
|
3648 | var parsedErrorResponse = parsedResponse.parsedBody;
|
3649 | try {
|
3650 | if (parsedErrorResponse) {
|
3651 | var defaultResponseBodyMapper = defaultResponseSpec.bodyMapper;
|
3652 | if (defaultResponseBodyMapper &&
|
3653 | defaultResponseBodyMapper.serializedName === "CloudError") {
|
3654 | if (parsedErrorResponse.error) {
|
3655 | parsedErrorResponse = parsedErrorResponse.error;
|
3656 | }
|
3657 | if (parsedErrorResponse.code) {
|
3658 | error.code = parsedErrorResponse.code;
|
3659 | }
|
3660 | if (parsedErrorResponse.message) {
|
3661 | error.message = parsedErrorResponse.message;
|
3662 | }
|
3663 | }
|
3664 | else {
|
3665 | var internalError = parsedErrorResponse;
|
3666 | if (parsedErrorResponse.error) {
|
3667 | internalError = parsedErrorResponse.error;
|
3668 | }
|
3669 | error.code = internalError.code;
|
3670 | if (internalError.message) {
|
3671 | error.message = internalError.message;
|
3672 | }
|
3673 | }
|
3674 | if (defaultResponseBodyMapper) {
|
3675 | var valueToDeserialize = parsedErrorResponse;
|
3676 | if (operationSpec.isXML &&
|
3677 | defaultResponseBodyMapper.type.name === MapperType.Sequence) {
|
3678 | valueToDeserialize =
|
3679 | typeof parsedErrorResponse === "object"
|
3680 | ? parsedErrorResponse[defaultResponseBodyMapper.xmlElementName]
|
3681 | : [];
|
3682 | }
|
3683 | error.body = operationSpec.serializer.deserialize(defaultResponseBodyMapper, valueToDeserialize, "error.body");
|
3684 | }
|
3685 | }
|
3686 | }
|
3687 | catch (defaultError) {
|
3688 | error.message = "Error \"" + defaultError.message + "\" occurred in deserializing the responseBody - \"" + parsedResponse.bodyAsText + "\" for the default response.";
|
3689 | }
|
3690 | return Promise.reject(error);
|
3691 | }
|
3692 | }
|
3693 | else if (responseSpec) {
|
3694 | if (responseSpec.bodyMapper) {
|
3695 | var valueToDeserialize = parsedResponse.parsedBody;
|
3696 | if (operationSpec.isXML && responseSpec.bodyMapper.type.name === MapperType.Sequence) {
|
3697 | valueToDeserialize =
|
3698 | typeof valueToDeserialize === "object"
|
3699 | ? valueToDeserialize[responseSpec.bodyMapper.xmlElementName]
|
3700 | : [];
|
3701 | }
|
3702 | try {
|
3703 | parsedResponse.parsedBody = operationSpec.serializer.deserialize(responseSpec.bodyMapper, valueToDeserialize, "operationRes.parsedBody");
|
3704 | }
|
3705 | catch (error) {
|
3706 | var restError = new RestError("Error " + error + " occurred in deserializing the responseBody - " + parsedResponse.bodyAsText);
|
3707 | restError.request = stripRequest(parsedResponse.request);
|
3708 | restError.response = stripResponse(parsedResponse);
|
3709 | return Promise.reject(restError);
|
3710 | }
|
3711 | }
|
3712 | else if (operationSpec.httpMethod === "HEAD") {
|
3713 |
|
3714 | parsedResponse.parsedBody = response.status >= 200 && response.status < 300;
|
3715 | }
|
3716 | if (responseSpec.headersMapper) {
|
3717 | parsedResponse.parsedHeaders = operationSpec.serializer.deserialize(responseSpec.headersMapper, parsedResponse.headers.rawHeaders(), "operationRes.parsedHeaders");
|
3718 | }
|
3719 | }
|
3720 | }
|
3721 | }
|
3722 | return Promise.resolve(parsedResponse);
|
3723 | });
|
3724 | }
|
3725 | function parse(jsonContentTypes, xmlContentTypes, operationResponse) {
|
3726 | var errorHandler = function (err) {
|
3727 | var msg = "Error \"" + err + "\" occurred while parsing the response body - " + operationResponse.bodyAsText + ".";
|
3728 | var errCode = err.code || RestError.PARSE_ERROR;
|
3729 | var e = new RestError(msg, errCode, operationResponse.status, operationResponse.request, operationResponse, operationResponse.bodyAsText);
|
3730 | return Promise.reject(e);
|
3731 | };
|
3732 | if (!operationResponse.request.streamResponseBody && operationResponse.bodyAsText) {
|
3733 | var text_1 = operationResponse.bodyAsText;
|
3734 | var contentType = operationResponse.headers.get("Content-Type") || "";
|
3735 | var contentComponents = !contentType
|
3736 | ? []
|
3737 | : contentType.split(";").map(function (component) { return component.toLowerCase(); });
|
3738 | if (contentComponents.length === 0 ||
|
3739 | contentComponents.some(function (component) { return jsonContentTypes.indexOf(component) !== -1; })) {
|
3740 | return new Promise(function (resolve) {
|
3741 | operationResponse.parsedBody = JSON.parse(text_1);
|
3742 | resolve(operationResponse);
|
3743 | }).catch(errorHandler);
|
3744 | }
|
3745 | else if (contentComponents.some(function (component) { return xmlContentTypes.indexOf(component) !== -1; })) {
|
3746 | return parseXML(text_1)
|
3747 | .then(function (body) {
|
3748 | operationResponse.parsedBody = body;
|
3749 | return operationResponse;
|
3750 | })
|
3751 | .catch(errorHandler);
|
3752 | }
|
3753 | }
|
3754 | return Promise.resolve(operationResponse);
|
3755 | }
|
3756 |
|
3757 |
|
3758 | function exponentialRetryPolicy(retryCount, retryInterval, minRetryInterval, maxRetryInterval) {
|
3759 | return {
|
3760 | create: function (nextPolicy, options) {
|
3761 | return new ExponentialRetryPolicy(nextPolicy, options, retryCount, retryInterval, minRetryInterval, maxRetryInterval);
|
3762 | },
|
3763 | };
|
3764 | }
|
3765 | var DEFAULT_CLIENT_RETRY_INTERVAL = 1000 * 30;
|
3766 | var DEFAULT_CLIENT_RETRY_COUNT = 3;
|
3767 | var DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1000 * 90;
|
3768 | var DEFAULT_CLIENT_MIN_RETRY_INTERVAL = 1000 * 3;
|
3769 |
|
3770 |
|
3771 |
|
3772 |
|
3773 | var ExponentialRetryPolicy = (function (_super) {
|
3774 | tslib.__extends(ExponentialRetryPolicy, _super);
|
3775 | |
3776 |
|
3777 |
|
3778 |
|
3779 |
|
3780 |
|
3781 |
|
3782 |
|
3783 |
|
3784 | function ExponentialRetryPolicy(nextPolicy, options, retryCount, retryInterval, minRetryInterval, maxRetryInterval) {
|
3785 | var _this = _super.call(this, nextPolicy, options) || this;
|
3786 | function isNumber(n) {
|
3787 | return typeof n === "number";
|
3788 | }
|
3789 | _this.retryCount = isNumber(retryCount) ? retryCount : DEFAULT_CLIENT_RETRY_COUNT;
|
3790 | _this.retryInterval = isNumber(retryInterval) ? retryInterval : DEFAULT_CLIENT_RETRY_INTERVAL;
|
3791 | _this.minRetryInterval = isNumber(minRetryInterval)
|
3792 | ? minRetryInterval
|
3793 | : DEFAULT_CLIENT_MIN_RETRY_INTERVAL;
|
3794 | _this.maxRetryInterval = isNumber(maxRetryInterval)
|
3795 | ? maxRetryInterval
|
3796 | : DEFAULT_CLIENT_MAX_RETRY_INTERVAL;
|
3797 | return _this;
|
3798 | }
|
3799 | ExponentialRetryPolicy.prototype.sendRequest = function (request) {
|
3800 | var _this = this;
|
3801 | return this._nextPolicy
|
3802 | .sendRequest(request.clone())
|
3803 | .then(function (response) { return retry(_this, request, response); })
|
3804 | .catch(function (error) { return retry(_this, request, error.response, undefined, error); });
|
3805 | };
|
3806 | return ExponentialRetryPolicy;
|
3807 | }(BaseRequestPolicy));
|
3808 |
|
3809 |
|
3810 |
|
3811 |
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 | function shouldRetry(policy, statusCode, retryData) {
|
3817 | if (statusCode == undefined ||
|
3818 | (statusCode < 500 && statusCode !== 408) ||
|
3819 | statusCode === 501 ||
|
3820 | statusCode === 505) {
|
3821 | return false;
|
3822 | }
|
3823 | var currentCount;
|
3824 | if (!retryData) {
|
3825 | throw new Error("retryData for the ExponentialRetryPolicyFilter cannot be null.");
|
3826 | }
|
3827 | else {
|
3828 | currentCount = retryData && retryData.retryCount;
|
3829 | }
|
3830 | return currentCount < policy.retryCount;
|
3831 | }
|
3832 |
|
3833 |
|
3834 |
|
3835 |
|
3836 |
|
3837 |
|
3838 |
|
3839 | function updateRetryData(policy, retryData, err) {
|
3840 | if (!retryData) {
|
3841 | retryData = {
|
3842 | retryCount: 0,
|
3843 | retryInterval: 0,
|
3844 | };
|
3845 | }
|
3846 | if (err) {
|
3847 | if (retryData.error) {
|
3848 | err.innerError = retryData.error;
|
3849 | }
|
3850 | retryData.error = err;
|
3851 | }
|
3852 |
|
3853 | retryData.retryCount++;
|
3854 |
|
3855 | var incrementDelta = Math.pow(2, retryData.retryCount) - 1;
|
3856 | var boundedRandDelta = policy.retryInterval * 0.8 +
|
3857 | Math.floor(Math.random() * (policy.retryInterval * 1.2 - policy.retryInterval * 0.8));
|
3858 | incrementDelta *= boundedRandDelta;
|
3859 | retryData.retryInterval = Math.min(policy.minRetryInterval + incrementDelta, policy.maxRetryInterval);
|
3860 | return retryData;
|
3861 | }
|
3862 | function retry(policy, request, response, retryData, requestError) {
|
3863 | retryData = updateRetryData(policy, retryData, requestError);
|
3864 | var isAborted = request.abortSignal && request.abortSignal.aborted;
|
3865 | if (!isAborted && shouldRetry(policy, response && response.status, retryData)) {
|
3866 | return delay(retryData.retryInterval)
|
3867 | .then(function () { return policy._nextPolicy.sendRequest(request.clone()); })
|
3868 | .then(function (res) { return retry(policy, request, res, retryData, undefined); })
|
3869 | .catch(function (err) { return retry(policy, request, response, retryData, err); });
|
3870 | }
|
3871 | else if (isAborted || requestError || !response) {
|
3872 |
|
3873 | var err = retryData.error ||
|
3874 | new RestError("Failed to send the request.", RestError.REQUEST_SEND_ERROR, response && response.status, response && response.request, response);
|
3875 | return Promise.reject(err);
|
3876 | }
|
3877 | else {
|
3878 | return Promise.resolve(response);
|
3879 | }
|
3880 | }
|
3881 |
|
3882 |
|
3883 | function generateClientRequestIdPolicy(requestIdHeaderName) {
|
3884 | if (requestIdHeaderName === void 0) { requestIdHeaderName = "x-ms-client-request-id"; }
|
3885 | return {
|
3886 | create: function (nextPolicy, options) {
|
3887 | return new GenerateClientRequestIdPolicy(nextPolicy, options, requestIdHeaderName);
|
3888 | },
|
3889 | };
|
3890 | }
|
3891 | var GenerateClientRequestIdPolicy = (function (_super) {
|
3892 | tslib.__extends(GenerateClientRequestIdPolicy, _super);
|
3893 | function GenerateClientRequestIdPolicy(nextPolicy, options, _requestIdHeaderName) {
|
3894 | var _this = _super.call(this, nextPolicy, options) || this;
|
3895 | _this._requestIdHeaderName = _requestIdHeaderName;
|
3896 | return _this;
|
3897 | }
|
3898 | GenerateClientRequestIdPolicy.prototype.sendRequest = function (request) {
|
3899 | if (!request.headers.contains(this._requestIdHeaderName)) {
|
3900 | request.headers.set(this._requestIdHeaderName, generateUuid());
|
3901 | }
|
3902 | return this._nextPolicy.sendRequest(request);
|
3903 | };
|
3904 | return GenerateClientRequestIdPolicy;
|
3905 | }(BaseRequestPolicy));
|
3906 |
|
3907 |
|
3908 | function getDefaultUserAgentKey() {
|
3909 | return Constants.HeaderConstants.USER_AGENT;
|
3910 | }
|
3911 | function getPlatformSpecificData() {
|
3912 | var runtimeInfo = {
|
3913 | key: "Node",
|
3914 | value: process.version,
|
3915 | };
|
3916 | var osInfo = {
|
3917 | key: "OS",
|
3918 | value: "(" + os.arch() + "-" + os.type() + "-" + os.release() + ")",
|
3919 | };
|
3920 | return [runtimeInfo, osInfo];
|
3921 | }
|
3922 |
|
3923 |
|
3924 | function getRuntimeInfo() {
|
3925 | var msRestRuntime = {
|
3926 | key: "ms-rest-js",
|
3927 | value: Constants.msRestVersion,
|
3928 | };
|
3929 | return [msRestRuntime];
|
3930 | }
|
3931 | function getUserAgentString(telemetryInfo, keySeparator, valueSeparator) {
|
3932 | if (keySeparator === void 0) { keySeparator = " "; }
|
3933 | if (valueSeparator === void 0) { valueSeparator = "/"; }
|
3934 | return telemetryInfo
|
3935 | .map(function (info) {
|
3936 | var value = info.value ? "" + valueSeparator + info.value : "";
|
3937 | return "" + info.key + value;
|
3938 | })
|
3939 | .join(keySeparator);
|
3940 | }
|
3941 | var getDefaultUserAgentHeaderName = getDefaultUserAgentKey;
|
3942 | function getDefaultUserAgentValue() {
|
3943 | var runtimeInfo = getRuntimeInfo();
|
3944 | var platformSpecificData = getPlatformSpecificData();
|
3945 | var userAgent = getUserAgentString(runtimeInfo.concat(platformSpecificData));
|
3946 | return userAgent;
|
3947 | }
|
3948 | function userAgentPolicy(userAgentData) {
|
3949 | var key = !userAgentData || userAgentData.key == undefined ? getDefaultUserAgentKey() : userAgentData.key;
|
3950 | var value = !userAgentData || userAgentData.value == undefined
|
3951 | ? getDefaultUserAgentValue()
|
3952 | : userAgentData.value;
|
3953 | return {
|
3954 | create: function (nextPolicy, options) {
|
3955 | return new UserAgentPolicy(nextPolicy, options, key, value);
|
3956 | },
|
3957 | };
|
3958 | }
|
3959 | var UserAgentPolicy = (function (_super) {
|
3960 | tslib.__extends(UserAgentPolicy, _super);
|
3961 | function UserAgentPolicy(_nextPolicy, _options, headerKey, headerValue) {
|
3962 | var _this = _super.call(this, _nextPolicy, _options) || this;
|
3963 | _this._nextPolicy = _nextPolicy;
|
3964 | _this._options = _options;
|
3965 | _this.headerKey = headerKey;
|
3966 | _this.headerValue = headerValue;
|
3967 | return _this;
|
3968 | }
|
3969 | UserAgentPolicy.prototype.sendRequest = function (request) {
|
3970 | this.addUserAgentHeader(request);
|
3971 | return this._nextPolicy.sendRequest(request);
|
3972 | };
|
3973 | UserAgentPolicy.prototype.addUserAgentHeader = function (request) {
|
3974 | if (!request.headers) {
|
3975 | request.headers = new HttpHeaders();
|
3976 | }
|
3977 | if (!request.headers.get(this.headerKey) && this.headerValue) {
|
3978 | request.headers.set(this.headerKey, this.headerValue);
|
3979 | }
|
3980 | };
|
3981 | return UserAgentPolicy;
|
3982 | }(BaseRequestPolicy));
|
3983 |
|
3984 |
|
3985 | var DefaultRedirectOptions = {
|
3986 | handleRedirects: true,
|
3987 | maxRetries: 20,
|
3988 | };
|
3989 | function redirectPolicy(maximumRetries) {
|
3990 | if (maximumRetries === void 0) { maximumRetries = 20; }
|
3991 | return {
|
3992 | create: function (nextPolicy, options) {
|
3993 | return new RedirectPolicy(nextPolicy, options, maximumRetries);
|
3994 | },
|
3995 | };
|
3996 | }
|
3997 | var RedirectPolicy = (function (_super) {
|
3998 | tslib.__extends(RedirectPolicy, _super);
|
3999 | function RedirectPolicy(nextPolicy, options, maxRetries) {
|
4000 | if (maxRetries === void 0) { maxRetries = 20; }
|
4001 | var _this = _super.call(this, nextPolicy, options) || this;
|
4002 | _this.maxRetries = maxRetries;
|
4003 | return _this;
|
4004 | }
|
4005 | RedirectPolicy.prototype.sendRequest = function (request) {
|
4006 | var _this = this;
|
4007 | return this._nextPolicy
|
4008 | .sendRequest(request)
|
4009 | .then(function (response) { return handleRedirect(_this, response, 0); });
|
4010 | };
|
4011 | return RedirectPolicy;
|
4012 | }(BaseRequestPolicy));
|
4013 | function handleRedirect(policy, response, currentRetries) {
|
4014 | var request = response.request, status = response.status;
|
4015 | var locationHeader = response.headers.get("location");
|
4016 | if (locationHeader &&
|
4017 | (status === 300 ||
|
4018 | (status === 301 && ["GET", "HEAD"].includes(request.method)) ||
|
4019 | (status === 302 && ["GET", "POST", "HEAD"].includes(request.method)) ||
|
4020 | (status === 303 && "POST" === request.method) ||
|
4021 | status === 307) &&
|
4022 | ((request.redirectLimit !== undefined && currentRetries < request.redirectLimit) ||
|
4023 | (request.redirectLimit === undefined && currentRetries < policy.maxRetries))) {
|
4024 | var builder = URLBuilder.parse(request.url);
|
4025 | builder.setPath(locationHeader);
|
4026 | request.url = builder.toString();
|
4027 |
|
4028 |
|
4029 |
|
4030 | if ((status === 302 || status === 303) && request.method === "POST") {
|
4031 | request.method = "GET";
|
4032 | delete request.body;
|
4033 | }
|
4034 | return policy._nextPolicy
|
4035 | .sendRequest(request)
|
4036 | .then(function (res) { return handleRedirect(policy, res, currentRetries + 1); })
|
4037 | .then(function (res) { return recordRedirect(res, request.url); });
|
4038 | }
|
4039 | return Promise.resolve(response);
|
4040 | }
|
4041 | function recordRedirect(response, redirect) {
|
4042 |
|
4043 |
|
4044 | if (!response.redirected) {
|
4045 | response.redirected = true;
|
4046 | response.url = redirect;
|
4047 | }
|
4048 | return response;
|
4049 | }
|
4050 |
|
4051 | function rpRegistrationPolicy(retryTimeout) {
|
4052 | if (retryTimeout === void 0) { retryTimeout = 30; }
|
4053 | return {
|
4054 | create: function (nextPolicy, options) {
|
4055 | return new RPRegistrationPolicy(nextPolicy, options, retryTimeout);
|
4056 | },
|
4057 | };
|
4058 | }
|
4059 | var RPRegistrationPolicy = (function (_super) {
|
4060 | tslib.__extends(RPRegistrationPolicy, _super);
|
4061 | function RPRegistrationPolicy(nextPolicy, options, _retryTimeout) {
|
4062 | if (_retryTimeout === void 0) { _retryTimeout = 30; }
|
4063 | var _this = _super.call(this, nextPolicy, options) || this;
|
4064 | _this._retryTimeout = _retryTimeout;
|
4065 | return _this;
|
4066 | }
|
4067 | RPRegistrationPolicy.prototype.sendRequest = function (request) {
|
4068 | var _this = this;
|
4069 | return this._nextPolicy
|
4070 | .sendRequest(request.clone())
|
4071 | .then(function (response) { return registerIfNeeded(_this, request, response); });
|
4072 | };
|
4073 | return RPRegistrationPolicy;
|
4074 | }(BaseRequestPolicy));
|
4075 | function registerIfNeeded(policy, request, response) {
|
4076 | if (response.status === 409) {
|
4077 | var rpName = checkRPNotRegisteredError(response.bodyAsText);
|
4078 | if (rpName) {
|
4079 | var urlPrefix = extractSubscriptionUrl(request.url);
|
4080 | return (registerRP(policy, urlPrefix, rpName, request)
|
4081 |
|
4082 |
|
4083 |
|
4084 | .catch(function () { return false; })
|
4085 | .then(function (registrationStatus) {
|
4086 | if (registrationStatus) {
|
4087 |
|
4088 |
|
4089 | request.headers.set("x-ms-client-request-id", generateUuid());
|
4090 | return policy._nextPolicy.sendRequest(request.clone());
|
4091 | }
|
4092 | return response;
|
4093 | }));
|
4094 | }
|
4095 | }
|
4096 | return Promise.resolve(response);
|
4097 | }
|
4098 |
|
4099 |
|
4100 |
|
4101 |
|
4102 |
|
4103 |
|
4104 | function getRequestEssentials(originalRequest, reuseUrlToo) {
|
4105 | if (reuseUrlToo === void 0) { reuseUrlToo = false; }
|
4106 | var reqOptions = originalRequest.clone();
|
4107 | if (reuseUrlToo) {
|
4108 | reqOptions.url = originalRequest.url;
|
4109 | }
|
4110 |
|
4111 |
|
4112 | reqOptions.headers.set("x-ms-client-request-id", generateUuid());
|
4113 |
|
4114 | reqOptions.headers.set("Content-Type", "application/json; charset=utf-8");
|
4115 | return reqOptions;
|
4116 | }
|
4117 |
|
4118 |
|
4119 |
|
4120 |
|
4121 |
|
4122 |
|
4123 | function checkRPNotRegisteredError(body) {
|
4124 | var result, responseBody;
|
4125 | if (body) {
|
4126 | try {
|
4127 | responseBody = JSON.parse(body);
|
4128 | }
|
4129 | catch (err) {
|
4130 |
|
4131 | }
|
4132 | if (responseBody &&
|
4133 | responseBody.error &&
|
4134 | responseBody.error.message &&
|
4135 | responseBody.error.code &&
|
4136 | responseBody.error.code === "MissingSubscriptionRegistration") {
|
4137 | var matchRes = responseBody.error.message.match(/.*'(.*)'/i);
|
4138 | if (matchRes) {
|
4139 | result = matchRes.pop();
|
4140 | }
|
4141 | }
|
4142 | }
|
4143 | return result;
|
4144 | }
|
4145 |
|
4146 |
|
4147 |
|
4148 |
|
4149 |
|
4150 |
|
4151 | function extractSubscriptionUrl(url) {
|
4152 | var result;
|
4153 | var matchRes = url.match(/.*\/subscriptions\/[a-f0-9-]+\//gi);
|
4154 | if (matchRes && matchRes[0]) {
|
4155 | result = matchRes[0];
|
4156 | }
|
4157 | else {
|
4158 | throw new Error("Unable to extract subscriptionId from the given url - " + url + ".");
|
4159 | }
|
4160 | return result;
|
4161 | }
|
4162 |
|
4163 |
|
4164 |
|
4165 |
|
4166 |
|
4167 |
|
4168 |
|
4169 |
|
4170 |
|
4171 | function registerRP(policy, urlPrefix, provider, originalRequest) {
|
4172 | var postUrl = urlPrefix + "providers/" + provider + "/register?api-version=2016-02-01";
|
4173 | var getUrl = urlPrefix + "providers/" + provider + "?api-version=2016-02-01";
|
4174 | var reqOptions = getRequestEssentials(originalRequest);
|
4175 | reqOptions.method = "POST";
|
4176 | reqOptions.url = postUrl;
|
4177 | return policy._nextPolicy.sendRequest(reqOptions).then(function (response) {
|
4178 | if (response.status !== 200) {
|
4179 | throw new Error("Autoregistration of " + provider + " failed. Please try registering manually.");
|
4180 | }
|
4181 | return getRegistrationStatus(policy, getUrl, originalRequest);
|
4182 | });
|
4183 | }
|
4184 |
|
4185 |
|
4186 |
|
4187 |
|
4188 |
|
4189 |
|
4190 |
|
4191 |
|
4192 |
|
4193 | function getRegistrationStatus(policy, url, originalRequest) {
|
4194 | var reqOptions = getRequestEssentials(originalRequest);
|
4195 | reqOptions.url = url;
|
4196 | reqOptions.method = "GET";
|
4197 | return policy._nextPolicy.sendRequest(reqOptions).then(function (res) {
|
4198 | var obj = res.parsedBody;
|
4199 | if (res.parsedBody && obj.registrationState && obj.registrationState === "Registered") {
|
4200 | return true;
|
4201 | }
|
4202 | else {
|
4203 | return delay(policy._retryTimeout * 1000)
|
4204 | .then(function () { return getRegistrationStatus(policy, url, originalRequest); });
|
4205 | }
|
4206 | });
|
4207 | }
|
4208 |
|
4209 |
|
4210 | function signingPolicy(authenticationProvider) {
|
4211 | return {
|
4212 | create: function (nextPolicy, options) {
|
4213 | return new SigningPolicy(nextPolicy, options, authenticationProvider);
|
4214 | },
|
4215 | };
|
4216 | }
|
4217 | var SigningPolicy = (function (_super) {
|
4218 | tslib.__extends(SigningPolicy, _super);
|
4219 | function SigningPolicy(nextPolicy, options, authenticationProvider) {
|
4220 | var _this = _super.call(this, nextPolicy, options) || this;
|
4221 | _this.authenticationProvider = authenticationProvider;
|
4222 | return _this;
|
4223 | }
|
4224 | SigningPolicy.prototype.signRequest = function (request) {
|
4225 | return this.authenticationProvider.signRequest(request);
|
4226 | };
|
4227 | SigningPolicy.prototype.sendRequest = function (request) {
|
4228 | var _this = this;
|
4229 | return this.signRequest(request).then(function (nextRequest) {
|
4230 | return _this._nextPolicy.sendRequest(nextRequest);
|
4231 | });
|
4232 | };
|
4233 | return SigningPolicy;
|
4234 | }(BaseRequestPolicy));
|
4235 |
|
4236 |
|
4237 | function systemErrorRetryPolicy(retryCount, retryInterval, minRetryInterval, maxRetryInterval) {
|
4238 | return {
|
4239 | create: function (nextPolicy, options) {
|
4240 | return new SystemErrorRetryPolicy(nextPolicy, options, retryCount, retryInterval, minRetryInterval, maxRetryInterval);
|
4241 | },
|
4242 | };
|
4243 | }
|
4244 |
|
4245 |
|
4246 |
|
4247 |
|
4248 |
|
4249 |
|
4250 |
|
4251 |
|
4252 |
|
4253 |
|
4254 | var SystemErrorRetryPolicy = (function (_super) {
|
4255 | tslib.__extends(SystemErrorRetryPolicy, _super);
|
4256 | function SystemErrorRetryPolicy(nextPolicy, options, retryCount, retryInterval, minRetryInterval, maxRetryInterval) {
|
4257 | var _this = _super.call(this, nextPolicy, options) || this;
|
4258 | _this.DEFAULT_CLIENT_RETRY_INTERVAL = 1000 * 30;
|
4259 | _this.DEFAULT_CLIENT_RETRY_COUNT = 3;
|
4260 | _this.DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1000 * 90;
|
4261 | _this.DEFAULT_CLIENT_MIN_RETRY_INTERVAL = 1000 * 3;
|
4262 | _this.retryCount = typeof retryCount === "number" ? retryCount : _this.DEFAULT_CLIENT_RETRY_COUNT;
|
4263 | _this.retryInterval =
|
4264 | typeof retryInterval === "number" ? retryInterval : _this.DEFAULT_CLIENT_RETRY_INTERVAL;
|
4265 | _this.minRetryInterval =
|
4266 | typeof minRetryInterval === "number"
|
4267 | ? minRetryInterval
|
4268 | : _this.DEFAULT_CLIENT_MIN_RETRY_INTERVAL;
|
4269 | _this.maxRetryInterval =
|
4270 | typeof maxRetryInterval === "number"
|
4271 | ? maxRetryInterval
|
4272 | : _this.DEFAULT_CLIENT_MAX_RETRY_INTERVAL;
|
4273 | return _this;
|
4274 | }
|
4275 | SystemErrorRetryPolicy.prototype.sendRequest = function (request) {
|
4276 | var _this = this;
|
4277 | return this._nextPolicy
|
4278 | .sendRequest(request.clone())
|
4279 | .catch(function (error) { return retry$1(_this, request, error.response, error); });
|
4280 | };
|
4281 | return SystemErrorRetryPolicy;
|
4282 | }(BaseRequestPolicy));
|
4283 |
|
4284 |
|
4285 |
|
4286 |
|
4287 |
|
4288 |
|
4289 |
|
4290 | function shouldRetry$1(policy, retryData) {
|
4291 | var currentCount;
|
4292 | if (!retryData) {
|
4293 | throw new Error("retryData for the SystemErrorRetryPolicyFilter cannot be null.");
|
4294 | }
|
4295 | else {
|
4296 | currentCount = retryData && retryData.retryCount;
|
4297 | }
|
4298 | return currentCount < policy.retryCount;
|
4299 | }
|
4300 |
|
4301 |
|
4302 |
|
4303 |
|
4304 |
|
4305 |
|
4306 | function updateRetryData$1(policy, retryData, err) {
|
4307 | if (!retryData) {
|
4308 | retryData = {
|
4309 | retryCount: 0,
|
4310 | retryInterval: 0,
|
4311 | };
|
4312 | }
|
4313 | if (err) {
|
4314 | if (retryData.error) {
|
4315 | err.innerError = retryData.error;
|
4316 | }
|
4317 | retryData.error = err;
|
4318 | }
|
4319 |
|
4320 | retryData.retryCount++;
|
4321 |
|
4322 | var incrementDelta = Math.pow(2, retryData.retryCount) - 1;
|
4323 | var boundedRandDelta = policy.retryInterval * 0.8 + Math.floor(Math.random() * (policy.retryInterval * 0.4));
|
4324 | incrementDelta *= boundedRandDelta;
|
4325 | retryData.retryInterval = Math.min(policy.minRetryInterval + incrementDelta, policy.maxRetryInterval);
|
4326 | return retryData;
|
4327 | }
|
4328 | function retry$1(policy, request, operationResponse, err, retryData) {
|
4329 | return tslib.__awaiter(this, void 0, void 0, function () {
|
4330 | var error_1;
|
4331 | return tslib.__generator(this, function (_a) {
|
4332 | switch (_a.label) {
|
4333 | case 0:
|
4334 | retryData = updateRetryData$1(policy, retryData, err);
|
4335 | if (!(err &&
|
4336 | err.code &&
|
4337 | shouldRetry$1(policy, retryData) &&
|
4338 | (err.code === "ETIMEDOUT" ||
|
4339 | err.code === "ESOCKETTIMEDOUT" ||
|
4340 | err.code === "ECONNREFUSED" ||
|
4341 | err.code === "ECONNRESET" ||
|
4342 | err.code === "ENOENT"))) return [3 , 5];
|
4343 | _a.label = 1;
|
4344 | case 1:
|
4345 | _a.trys.push([1, 3, , 4]);
|
4346 | return [4 , delay(retryData.retryInterval)];
|
4347 | case 2:
|
4348 | _a.sent();
|
4349 | return [2 , policy._nextPolicy.sendRequest(request.clone())];
|
4350 | case 3:
|
4351 | error_1 = _a.sent();
|
4352 | return [2 , retry$1(policy, request, operationResponse, error_1, retryData)];
|
4353 | case 4: return [3 , 6];
|
4354 | case 5:
|
4355 | if (err) {
|
4356 |
|
4357 | return [2 , Promise.reject(retryData.error)];
|
4358 | }
|
4359 | return [2 , operationResponse];
|
4360 | case 6: return [2 ];
|
4361 | }
|
4362 | });
|
4363 | });
|
4364 | }
|
4365 |
|
4366 |
|
4367 | (function (QueryCollectionFormat) {
|
4368 | QueryCollectionFormat["Csv"] = ",";
|
4369 | QueryCollectionFormat["Ssv"] = " ";
|
4370 | QueryCollectionFormat["Tsv"] = "\t";
|
4371 | QueryCollectionFormat["Pipes"] = "|";
|
4372 | QueryCollectionFormat["Multi"] = "Multi";
|
4373 | })(exports.QueryCollectionFormat || (exports.QueryCollectionFormat = {}));
|
4374 |
|
4375 |
|
4376 | function agentPolicy(agentSettings) {
|
4377 | return {
|
4378 | create: function (nextPolicy, options) {
|
4379 | return new AgentPolicy(nextPolicy, options, agentSettings);
|
4380 | },
|
4381 | };
|
4382 | }
|
4383 | var AgentPolicy = (function (_super) {
|
4384 | tslib.__extends(AgentPolicy, _super);
|
4385 | function AgentPolicy(nextPolicy, options, agentSettings) {
|
4386 | var _this = _super.call(this, nextPolicy, options) || this;
|
4387 | _this.agentSettings = agentSettings;
|
4388 | return _this;
|
4389 | }
|
4390 | AgentPolicy.prototype.sendRequest = function (request) {
|
4391 | if (!request.agentSettings) {
|
4392 | request.agentSettings = this.agentSettings;
|
4393 | }
|
4394 | return this._nextPolicy.sendRequest(request);
|
4395 | };
|
4396 | return AgentPolicy;
|
4397 | }(BaseRequestPolicy));
|
4398 |
|
4399 |
|
4400 |
|
4401 |
|
4402 |
|
4403 | var noProxyList = loadNoProxy();
|
4404 | var byPassedList = new Map();
|
4405 |
|
4406 |
|
4407 |
|
4408 | function getEnvironmentValue(name) {
|
4409 | if (process.env[name]) {
|
4410 | return process.env[name];
|
4411 | }
|
4412 | else if (process.env[name.toLowerCase()]) {
|
4413 | return process.env[name.toLowerCase()];
|
4414 | }
|
4415 | return undefined;
|
4416 | }
|
4417 | function loadEnvironmentProxyValue() {
|
4418 | if (!process) {
|
4419 | return undefined;
|
4420 | }
|
4421 | var httpsProxy = getEnvironmentValue(Constants.HTTPS_PROXY);
|
4422 | var allProxy = getEnvironmentValue(Constants.ALL_PROXY);
|
4423 | var httpProxy = getEnvironmentValue(Constants.HTTP_PROXY);
|
4424 | return httpsProxy || allProxy || httpProxy;
|
4425 | }
|
4426 |
|
4427 |
|
4428 |
|
4429 | function isBypassed(uri) {
|
4430 | if (noProxyList.length === 0) {
|
4431 | return false;
|
4432 | }
|
4433 | var host = URLBuilder.parse(uri).getHost();
|
4434 | if (byPassedList.has(host)) {
|
4435 | return byPassedList.get(host);
|
4436 | }
|
4437 | var isBypassedFlag = false;
|
4438 | for (var _i = 0, noProxyList_1 = noProxyList; _i < noProxyList_1.length; _i++) {
|
4439 | var pattern = noProxyList_1[_i];
|
4440 | if (pattern[0] === ".") {
|
4441 |
|
4442 |
|
4443 | if (host.endsWith(pattern)) {
|
4444 | isBypassedFlag = true;
|
4445 | }
|
4446 | else {
|
4447 | if (host.length === pattern.length - 1 && host === pattern.slice(1)) {
|
4448 | isBypassedFlag = true;
|
4449 | }
|
4450 | }
|
4451 | }
|
4452 | else {
|
4453 | if (host === pattern) {
|
4454 | isBypassedFlag = true;
|
4455 | }
|
4456 | }
|
4457 | }
|
4458 | byPassedList.set(host, isBypassedFlag);
|
4459 | return isBypassedFlag;
|
4460 | }
|
4461 |
|
4462 |
|
4463 |
|
4464 | function loadNoProxy() {
|
4465 | var noProxy = getEnvironmentValue(Constants.NO_PROXY);
|
4466 | if (noProxy) {
|
4467 | return noProxy
|
4468 | .split(",")
|
4469 | .map(function (item) { return item.trim(); })
|
4470 | .filter(function (item) { return item.length; });
|
4471 | }
|
4472 | return [];
|
4473 | }
|
4474 |
|
4475 |
|
4476 |
|
4477 | function extractAuthFromUrl(url) {
|
4478 | var atIndex = url.indexOf("@");
|
4479 | if (atIndex === -1) {
|
4480 | return { urlWithoutAuth: url };
|
4481 | }
|
4482 | var schemeIndex = url.indexOf("://");
|
4483 | var authStart = schemeIndex !== -1 ? schemeIndex + 3 : 0;
|
4484 | var auth = url.substring(authStart, atIndex);
|
4485 | var colonIndex = auth.indexOf(":");
|
4486 | var hasPassword = colonIndex !== -1;
|
4487 | var username = hasPassword ? auth.substring(0, colonIndex) : auth;
|
4488 | var password = hasPassword ? auth.substring(colonIndex + 1) : undefined;
|
4489 | var urlWithoutAuth = url.substring(0, authStart) + url.substring(atIndex + 1);
|
4490 | return {
|
4491 | username: username,
|
4492 | password: password,
|
4493 | urlWithoutAuth: urlWithoutAuth,
|
4494 | };
|
4495 | }
|
4496 | function getDefaultProxySettings(proxyUrl) {
|
4497 | if (!proxyUrl) {
|
4498 | proxyUrl = loadEnvironmentProxyValue();
|
4499 | if (!proxyUrl) {
|
4500 | return undefined;
|
4501 | }
|
4502 | }
|
4503 | var _a = extractAuthFromUrl(proxyUrl), username = _a.username, password = _a.password, urlWithoutAuth = _a.urlWithoutAuth;
|
4504 | var parsedUrl = URLBuilder.parse(urlWithoutAuth);
|
4505 | var schema = parsedUrl.getScheme() ? parsedUrl.getScheme() + "://" : "";
|
4506 | return {
|
4507 | host: schema + parsedUrl.getHost(),
|
4508 | port: Number.parseInt(parsedUrl.getPort() || "80"),
|
4509 | username: username,
|
4510 | password: password,
|
4511 | };
|
4512 | }
|
4513 | function proxyPolicy(proxySettings) {
|
4514 | if (!proxySettings) {
|
4515 | proxySettings = getDefaultProxySettings();
|
4516 | }
|
4517 | return {
|
4518 | create: function (nextPolicy, options) {
|
4519 | return new ProxyPolicy(nextPolicy, options, proxySettings);
|
4520 | },
|
4521 | };
|
4522 | }
|
4523 | var ProxyPolicy = (function (_super) {
|
4524 | tslib.__extends(ProxyPolicy, _super);
|
4525 | function ProxyPolicy(nextPolicy, options, proxySettings) {
|
4526 | var _this = _super.call(this, nextPolicy, options) || this;
|
4527 | _this.proxySettings = proxySettings;
|
4528 | return _this;
|
4529 | }
|
4530 | ProxyPolicy.prototype.sendRequest = function (request) {
|
4531 | if (!request.proxySettings && !isBypassed(request.url)) {
|
4532 | request.proxySettings = this.proxySettings;
|
4533 | }
|
4534 | return this._nextPolicy.sendRequest(request);
|
4535 | };
|
4536 | return ProxyPolicy;
|
4537 | }(BaseRequestPolicy));
|
4538 |
|
4539 |
|
4540 | var StatusCodes = Constants.HttpConstants.StatusCodes;
|
4541 | var DEFAULT_RETRY_COUNT = 3;
|
4542 | function throttlingRetryPolicy(maxRetries) {
|
4543 | if (maxRetries === void 0) { maxRetries = DEFAULT_RETRY_COUNT; }
|
4544 | return {
|
4545 | create: function (nextPolicy, options) {
|
4546 | return new ThrottlingRetryPolicy(nextPolicy, options, maxRetries);
|
4547 | },
|
4548 | };
|
4549 | }
|
4550 |
|
4551 |
|
4552 |
|
4553 |
|
4554 |
|
4555 |
|
4556 | var ThrottlingRetryPolicy = (function (_super) {
|
4557 | tslib.__extends(ThrottlingRetryPolicy, _super);
|
4558 | function ThrottlingRetryPolicy(nextPolicy, options, retryLimit) {
|
4559 | var _this = _super.call(this, nextPolicy, options) || this;
|
4560 | _this.retryLimit = retryLimit;
|
4561 | return _this;
|
4562 | }
|
4563 | ThrottlingRetryPolicy.prototype.sendRequest = function (httpRequest) {
|
4564 | return tslib.__awaiter(this, void 0, void 0, function () {
|
4565 | var _this = this;
|
4566 | return tslib.__generator(this, function (_a) {
|
4567 | return [2 , this._nextPolicy.sendRequest(httpRequest.clone()).then(function (response) {
|
4568 | return _this.retry(httpRequest, response, 0);
|
4569 | })];
|
4570 | });
|
4571 | });
|
4572 | };
|
4573 | ThrottlingRetryPolicy.prototype.retry = function (httpRequest, httpResponse, retryCount) {
|
4574 | return tslib.__awaiter(this, void 0, void 0, function () {
|
4575 | var retryAfterHeader, delayInMs, res;
|
4576 | return tslib.__generator(this, function (_a) {
|
4577 | switch (_a.label) {
|
4578 | case 0:
|
4579 | if (httpResponse.status !== StatusCodes.TooManyRequests) {
|
4580 | return [2 , httpResponse];
|
4581 | }
|
4582 | retryAfterHeader = httpResponse.headers.get(Constants.HeaderConstants.RETRY_AFTER);
|
4583 | if (!(retryAfterHeader && retryCount < this.retryLimit)) return [3 , 3];
|
4584 | delayInMs = ThrottlingRetryPolicy.parseRetryAfterHeader(retryAfterHeader);
|
4585 | if (!delayInMs) return [3 , 3];
|
4586 | return [4 , delay(delayInMs)];
|
4587 | case 1:
|
4588 | _a.sent();
|
4589 | return [4 , this._nextPolicy.sendRequest(httpRequest)];
|
4590 | case 2:
|
4591 | res = _a.sent();
|
4592 | return [2 , this.retry(httpRequest, res, retryCount + 1)];
|
4593 | case 3: return [2 , httpResponse];
|
4594 | }
|
4595 | });
|
4596 | });
|
4597 | };
|
4598 | ThrottlingRetryPolicy.parseRetryAfterHeader = function (headerValue) {
|
4599 | var retryAfterInSeconds = Number(headerValue);
|
4600 | if (Number.isNaN(retryAfterInSeconds)) {
|
4601 | return ThrottlingRetryPolicy.parseDateRetryAfterHeader(headerValue);
|
4602 | }
|
4603 | else {
|
4604 | return retryAfterInSeconds * 1000;
|
4605 | }
|
4606 | };
|
4607 | ThrottlingRetryPolicy.parseDateRetryAfterHeader = function (headerValue) {
|
4608 | try {
|
4609 | var now = Date.now();
|
4610 | var date = Date.parse(headerValue);
|
4611 | var diff = date - now;
|
4612 | return Number.isNaN(diff) ? undefined : diff;
|
4613 | }
|
4614 | catch (error) {
|
4615 | return undefined;
|
4616 | }
|
4617 | };
|
4618 | return ThrottlingRetryPolicy;
|
4619 | }(BaseRequestPolicy));
|
4620 |
|
4621 |
|
4622 | var DEFAULT_AUTHORIZATION_SCHEME = "Bearer";
|
4623 |
|
4624 |
|
4625 |
|
4626 | var azureResourceManagerEndpoints = [
|
4627 | "https://management.windows.net",
|
4628 | "https://management.chinacloudapi.cn",
|
4629 | "https://management.usgovcloudapi.net",
|
4630 | "https://management.cloudapi.de",
|
4631 | ];
|
4632 |
|
4633 |
|
4634 |
|
4635 |
|
4636 | var AzureIdentityCredentialAdapter = (function () {
|
4637 | function AzureIdentityCredentialAdapter(azureTokenCredential, scopes) {
|
4638 | if (scopes === void 0) { scopes = "https://management.azure.com/.default"; }
|
4639 | this.azureTokenCredential = azureTokenCredential;
|
4640 | this.scopes = scopes;
|
4641 | }
|
4642 | AzureIdentityCredentialAdapter.prototype.getToken = function () {
|
4643 | return tslib.__awaiter(this, void 0, void 0, function () {
|
4644 | var accessToken, result;
|
4645 | return tslib.__generator(this, function (_a) {
|
4646 | switch (_a.label) {
|
4647 | case 0: return [4 , this.azureTokenCredential.getToken(this.scopes)];
|
4648 | case 1:
|
4649 | accessToken = _a.sent();
|
4650 | if (accessToken !== null) {
|
4651 | result = {
|
4652 | accessToken: accessToken.token,
|
4653 | tokenType: DEFAULT_AUTHORIZATION_SCHEME,
|
4654 | expiresOn: accessToken.expiresOnTimestamp,
|
4655 | };
|
4656 | return [2 , result];
|
4657 | }
|
4658 | else {
|
4659 | throw new Error("Could find token for scope");
|
4660 | }
|
4661 | }
|
4662 | });
|
4663 | });
|
4664 | };
|
4665 | AzureIdentityCredentialAdapter.prototype.signRequest = function (webResource) {
|
4666 | return tslib.__awaiter(this, void 0, void 0, function () {
|
4667 | var tokenResponse;
|
4668 | return tslib.__generator(this, function (_a) {
|
4669 | switch (_a.label) {
|
4670 | case 0: return [4 , this.getToken()];
|
4671 | case 1:
|
4672 | tokenResponse = _a.sent();
|
4673 | webResource.headers.set(Constants.HeaderConstants.AUTHORIZATION, tokenResponse.tokenType + " " + tokenResponse.accessToken);
|
4674 | return [2 , Promise.resolve(webResource)];
|
4675 | }
|
4676 | });
|
4677 | });
|
4678 | };
|
4679 | return AzureIdentityCredentialAdapter;
|
4680 | }());
|
4681 |
|
4682 |
|
4683 |
|
4684 |
|
4685 |
|
4686 |
|
4687 | var ServiceClient = (function () {
|
4688 | |
4689 |
|
4690 |
|
4691 |
|
4692 |
|
4693 |
|
4694 | function ServiceClient(credentials, options) {
|
4695 | if (!options) {
|
4696 | options = {};
|
4697 | }
|
4698 | if (options.baseUri) {
|
4699 | this.baseUri = options.baseUri;
|
4700 | }
|
4701 | var serviceClientCredentials;
|
4702 | if (isTokenCredential(credentials)) {
|
4703 | var scope = undefined;
|
4704 | if ((options === null || options === void 0 ? void 0 : options.baseUri) && azureResourceManagerEndpoints.includes(options === null || options === void 0 ? void 0 : options.baseUri)) {
|
4705 | scope = options.baseUri + "/.default";
|
4706 | }
|
4707 | serviceClientCredentials = new AzureIdentityCredentialAdapter(credentials, scope);
|
4708 | }
|
4709 | else {
|
4710 | serviceClientCredentials = credentials;
|
4711 | }
|
4712 | if (serviceClientCredentials && !serviceClientCredentials.signRequest) {
|
4713 | throw new Error("credentials argument needs to implement signRequest method");
|
4714 | }
|
4715 | this._withCredentials = options.withCredentials || false;
|
4716 | this._httpClient = options.httpClient || new NodeFetchHttpClient();
|
4717 | this._requestPolicyOptions = new RequestPolicyOptions(options.httpPipelineLogger);
|
4718 | var requestPolicyFactories;
|
4719 | if (Array.isArray(options.requestPolicyFactories)) {
|
4720 | requestPolicyFactories = options.requestPolicyFactories;
|
4721 | }
|
4722 | else {
|
4723 | requestPolicyFactories = createDefaultRequestPolicyFactories(serviceClientCredentials, options);
|
4724 | if (options.requestPolicyFactories) {
|
4725 | var newRequestPolicyFactories = options.requestPolicyFactories(requestPolicyFactories);
|
4726 | if (newRequestPolicyFactories) {
|
4727 | requestPolicyFactories = newRequestPolicyFactories;
|
4728 | }
|
4729 | }
|
4730 | }
|
4731 | this._requestPolicyFactories = requestPolicyFactories;
|
4732 | }
|
4733 | |
4734 |
|
4735 |
|
4736 | ServiceClient.prototype.sendRequest = function (options) {
|
4737 | if (options === null || options === undefined || typeof options !== "object") {
|
4738 | throw new Error("options cannot be null or undefined and it must be of type object.");
|
4739 | }
|
4740 | var httpRequest;
|
4741 | try {
|
4742 | if (isWebResourceLike(options)) {
|
4743 | options.validateRequestProperties();
|
4744 | httpRequest = options;
|
4745 | }
|
4746 | else {
|
4747 | httpRequest = new WebResource();
|
4748 | httpRequest = httpRequest.prepare(options);
|
4749 | }
|
4750 | }
|
4751 | catch (error) {
|
4752 | return Promise.reject(error);
|
4753 | }
|
4754 | var httpPipeline = this._httpClient;
|
4755 | if (this._requestPolicyFactories && this._requestPolicyFactories.length > 0) {
|
4756 | for (var i = this._requestPolicyFactories.length - 1; i >= 0; --i) {
|
4757 | httpPipeline = this._requestPolicyFactories[i].create(httpPipeline, this._requestPolicyOptions);
|
4758 | }
|
4759 | }
|
4760 | return httpPipeline.sendRequest(httpRequest);
|
4761 | };
|
4762 | |
4763 |
|
4764 |
|
4765 |
|
4766 |
|
4767 |
|
4768 | ServiceClient.prototype.sendOperationRequest = function (operationArguments, operationSpec, callback) {
|
4769 | if (typeof operationArguments.options === "function") {
|
4770 | callback = operationArguments.options;
|
4771 | operationArguments.options = undefined;
|
4772 | }
|
4773 | var httpRequest = new WebResource();
|
4774 | var result;
|
4775 | try {
|
4776 | var baseUri = operationSpec.baseUrl || this.baseUri;
|
4777 | if (!baseUri) {
|
4778 | throw new Error("If operationSpec.baseUrl is not specified, then the ServiceClient must have a baseUri string property that contains the base URL to use.");
|
4779 | }
|
4780 | httpRequest.method = operationSpec.httpMethod;
|
4781 | httpRequest.operationSpec = operationSpec;
|
4782 | var requestUrl = URLBuilder.parse(baseUri);
|
4783 | if (operationSpec.path) {
|
4784 | requestUrl.appendPath(operationSpec.path);
|
4785 | }
|
4786 | if (operationSpec.urlParameters && operationSpec.urlParameters.length > 0) {
|
4787 | for (var _i = 0, _a = operationSpec.urlParameters; _i < _a.length; _i++) {
|
4788 | var urlParameter = _a[_i];
|
4789 | var urlParameterValue = getOperationArgumentValueFromParameter(this, operationArguments, urlParameter, operationSpec.serializer);
|
4790 | urlParameterValue = operationSpec.serializer.serialize(urlParameter.mapper, urlParameterValue, getPathStringFromParameter(urlParameter));
|
4791 | if (!urlParameter.skipEncoding) {
|
4792 | urlParameterValue = encodeURIComponent(urlParameterValue);
|
4793 | }
|
4794 | requestUrl.replaceAll("{" + (urlParameter.mapper.serializedName || getPathStringFromParameter(urlParameter)) + "}", urlParameterValue);
|
4795 | }
|
4796 | }
|
4797 | if (operationSpec.queryParameters && operationSpec.queryParameters.length > 0) {
|
4798 | for (var _b = 0, _c = operationSpec.queryParameters; _b < _c.length; _b++) {
|
4799 | var queryParameter = _c[_b];
|
4800 | var queryParameterValue = getOperationArgumentValueFromParameter(this, operationArguments, queryParameter, operationSpec.serializer);
|
4801 | if (queryParameterValue != undefined) {
|
4802 | queryParameterValue = operationSpec.serializer.serialize(queryParameter.mapper, queryParameterValue, getPathStringFromParameter(queryParameter));
|
4803 | if (queryParameter.collectionFormat != undefined) {
|
4804 | if (queryParameter.collectionFormat === exports.QueryCollectionFormat.Multi) {
|
4805 | if (queryParameterValue.length === 0) {
|
4806 | queryParameterValue = "";
|
4807 | }
|
4808 | else {
|
4809 | for (var index in queryParameterValue) {
|
4810 | var item = queryParameterValue[index];
|
4811 | queryParameterValue[index] = item == undefined ? "" : item.toString();
|
4812 | }
|
4813 | }
|
4814 | }
|
4815 | else if (queryParameter.collectionFormat === exports.QueryCollectionFormat.Ssv ||
|
4816 | queryParameter.collectionFormat === exports.QueryCollectionFormat.Tsv) {
|
4817 | queryParameterValue = queryParameterValue.join(queryParameter.collectionFormat);
|
4818 | }
|
4819 | }
|
4820 | if (!queryParameter.skipEncoding) {
|
4821 | if (Array.isArray(queryParameterValue)) {
|
4822 | for (var index in queryParameterValue) {
|
4823 | if (queryParameterValue[index] !== undefined &&
|
4824 | queryParameterValue[index] !== null) {
|
4825 | queryParameterValue[index] = encodeURIComponent(queryParameterValue[index]);
|
4826 | }
|
4827 | }
|
4828 | }
|
4829 | else {
|
4830 | queryParameterValue = encodeURIComponent(queryParameterValue);
|
4831 | }
|
4832 | }
|
4833 | if (queryParameter.collectionFormat != undefined &&
|
4834 | queryParameter.collectionFormat !== exports.QueryCollectionFormat.Multi &&
|
4835 | queryParameter.collectionFormat !== exports.QueryCollectionFormat.Ssv &&
|
4836 | queryParameter.collectionFormat !== exports.QueryCollectionFormat.Tsv) {
|
4837 | queryParameterValue = queryParameterValue.join(queryParameter.collectionFormat);
|
4838 | }
|
4839 | requestUrl.setQueryParameter(queryParameter.mapper.serializedName || getPathStringFromParameter(queryParameter), queryParameterValue);
|
4840 | }
|
4841 | }
|
4842 | }
|
4843 | httpRequest.url = requestUrl.toString();
|
4844 | var contentType = operationSpec.contentType || this.requestContentType;
|
4845 | if (contentType) {
|
4846 | httpRequest.headers.set("Content-Type", contentType);
|
4847 | }
|
4848 | if (operationSpec.headerParameters) {
|
4849 | for (var _d = 0, _e = operationSpec.headerParameters; _d < _e.length; _d++) {
|
4850 | var headerParameter = _e[_d];
|
4851 | var headerValue = getOperationArgumentValueFromParameter(this, operationArguments, headerParameter, operationSpec.serializer);
|
4852 | if (headerValue != undefined) {
|
4853 | headerValue = operationSpec.serializer.serialize(headerParameter.mapper, headerValue, getPathStringFromParameter(headerParameter));
|
4854 | var headerCollectionPrefix = headerParameter.mapper
|
4855 | .headerCollectionPrefix;
|
4856 | if (headerCollectionPrefix) {
|
4857 | for (var _f = 0, _g = Object.keys(headerValue); _f < _g.length; _f++) {
|
4858 | var key = _g[_f];
|
4859 | httpRequest.headers.set(headerCollectionPrefix + key, headerValue[key]);
|
4860 | }
|
4861 | }
|
4862 | else {
|
4863 | httpRequest.headers.set(headerParameter.mapper.serializedName ||
|
4864 | getPathStringFromParameter(headerParameter), headerValue);
|
4865 | }
|
4866 | }
|
4867 | }
|
4868 | }
|
4869 | var options = operationArguments.options;
|
4870 | if (options) {
|
4871 | if (options.customHeaders) {
|
4872 | for (var customHeaderName in options.customHeaders) {
|
4873 | httpRequest.headers.set(customHeaderName, options.customHeaders[customHeaderName]);
|
4874 | }
|
4875 | }
|
4876 | if (options.abortSignal) {
|
4877 | httpRequest.abortSignal = options.abortSignal;
|
4878 | }
|
4879 | if (options.timeout) {
|
4880 | httpRequest.timeout = options.timeout;
|
4881 | }
|
4882 | if (options.onUploadProgress) {
|
4883 | httpRequest.onUploadProgress = options.onUploadProgress;
|
4884 | }
|
4885 | if (options.onDownloadProgress) {
|
4886 | httpRequest.onDownloadProgress = options.onDownloadProgress;
|
4887 | }
|
4888 | }
|
4889 | httpRequest.withCredentials = this._withCredentials;
|
4890 | serializeRequestBody(this, httpRequest, operationArguments, operationSpec);
|
4891 | if (httpRequest.streamResponseBody == undefined) {
|
4892 | httpRequest.streamResponseBody = isStreamOperation(operationSpec);
|
4893 | }
|
4894 | result = this.sendRequest(httpRequest).then(function (res) {
|
4895 | return flattenResponse(res, operationSpec.responses[res.status]);
|
4896 | });
|
4897 | }
|
4898 | catch (error) {
|
4899 | result = Promise.reject(error);
|
4900 | }
|
4901 | var cb = callback;
|
4902 | if (cb) {
|
4903 | result
|
4904 |
|
4905 | .then(function (res) { return cb(null, res._response.parsedBody, res._response.request, res._response); })
|
4906 | .catch(function (err) { return cb(err); });
|
4907 | }
|
4908 | return result;
|
4909 | };
|
4910 | return ServiceClient;
|
4911 | }());
|
4912 | function serializeRequestBody(serviceClient, httpRequest, operationArguments, operationSpec) {
|
4913 | if (operationSpec.requestBody && operationSpec.requestBody.mapper) {
|
4914 | httpRequest.body = getOperationArgumentValueFromParameter(serviceClient, operationArguments, operationSpec.requestBody, operationSpec.serializer);
|
4915 | var bodyMapper = operationSpec.requestBody.mapper;
|
4916 | var required = bodyMapper.required, xmlName = bodyMapper.xmlName, xmlElementName = bodyMapper.xmlElementName, serializedName = bodyMapper.serializedName;
|
4917 | var typeName = bodyMapper.type.name;
|
4918 | try {
|
4919 | if (httpRequest.body != undefined || required) {
|
4920 | var requestBodyParameterPathString = getPathStringFromParameter(operationSpec.requestBody);
|
4921 | httpRequest.body = operationSpec.serializer.serialize(bodyMapper, httpRequest.body, requestBodyParameterPathString);
|
4922 | var isStream = typeName === MapperType.Stream;
|
4923 | if (operationSpec.isXML) {
|
4924 | if (typeName === MapperType.Sequence) {
|
4925 | httpRequest.body = stringifyXML(prepareXMLRootList(httpRequest.body, xmlElementName || xmlName || serializedName), { rootName: xmlName || serializedName });
|
4926 | }
|
4927 | else if (!isStream) {
|
4928 | httpRequest.body = stringifyXML(httpRequest.body, {
|
4929 | rootName: xmlName || serializedName,
|
4930 | });
|
4931 | }
|
4932 | }
|
4933 | else if (!isStream) {
|
4934 | httpRequest.body = JSON.stringify(httpRequest.body);
|
4935 | }
|
4936 | }
|
4937 | }
|
4938 | catch (error) {
|
4939 | throw new Error("Error \"" + error.message + "\" occurred in serializing the payload - " + JSON.stringify(serializedName, undefined, " ") + ".");
|
4940 | }
|
4941 | }
|
4942 | else if (operationSpec.formDataParameters && operationSpec.formDataParameters.length > 0) {
|
4943 | httpRequest.formData = {};
|
4944 | for (var _i = 0, _a = operationSpec.formDataParameters; _i < _a.length; _i++) {
|
4945 | var formDataParameter = _a[_i];
|
4946 | var formDataParameterValue = getOperationArgumentValueFromParameter(serviceClient, operationArguments, formDataParameter, operationSpec.serializer);
|
4947 | if (formDataParameterValue != undefined) {
|
4948 | var formDataParameterPropertyName = formDataParameter.mapper.serializedName || getPathStringFromParameter(formDataParameter);
|
4949 | httpRequest.formData[formDataParameterPropertyName] = operationSpec.serializer.serialize(formDataParameter.mapper, formDataParameterValue, getPathStringFromParameter(formDataParameter));
|
4950 | }
|
4951 | }
|
4952 | }
|
4953 | }
|
4954 | function isRequestPolicyFactory(instance) {
|
4955 | return typeof instance.create === "function";
|
4956 | }
|
4957 | function getValueOrFunctionResult(value, defaultValueCreator) {
|
4958 | var result;
|
4959 | if (typeof value === "string") {
|
4960 | result = value;
|
4961 | }
|
4962 | else {
|
4963 | result = defaultValueCreator();
|
4964 | if (typeof value === "function") {
|
4965 | result = value(result);
|
4966 | }
|
4967 | }
|
4968 | return result;
|
4969 | }
|
4970 | function createDefaultRequestPolicyFactories(credentials, options) {
|
4971 | var factories = [];
|
4972 | if (options.generateClientRequestIdHeader) {
|
4973 | factories.push(generateClientRequestIdPolicy(options.clientRequestIdHeaderName));
|
4974 | }
|
4975 | if (credentials) {
|
4976 | if (isRequestPolicyFactory(credentials)) {
|
4977 | factories.push(credentials);
|
4978 | }
|
4979 | else {
|
4980 | factories.push(signingPolicy(credentials));
|
4981 | }
|
4982 | }
|
4983 | var userAgentHeaderName = getValueOrFunctionResult(options.userAgentHeaderName, getDefaultUserAgentHeaderName);
|
4984 | var userAgentHeaderValue = getValueOrFunctionResult(options.userAgent, getDefaultUserAgentValue);
|
4985 | if (userAgentHeaderName && userAgentHeaderValue) {
|
4986 | factories.push(userAgentPolicy({ key: userAgentHeaderName, value: userAgentHeaderValue }));
|
4987 | }
|
4988 | var redirectOptions = tslib.__assign(tslib.__assign({}, DefaultRedirectOptions), options.redirectOptions);
|
4989 | if (redirectOptions.handleRedirects) {
|
4990 | factories.push(redirectPolicy(redirectOptions.maxRetries));
|
4991 | }
|
4992 | factories.push(rpRegistrationPolicy(options.rpRegistrationRetryTimeout));
|
4993 | if (!options.noRetryPolicy) {
|
4994 | factories.push(exponentialRetryPolicy());
|
4995 | factories.push(systemErrorRetryPolicy());
|
4996 | factories.push(throttlingRetryPolicy());
|
4997 | }
|
4998 | factories.push(deserializationPolicy(options.deserializationContentTypes));
|
4999 | var proxySettings = options.proxySettings || getDefaultProxySettings();
|
5000 | if (proxySettings) {
|
5001 | factories.push(proxyPolicy(proxySettings));
|
5002 | }
|
5003 | if (options.agentSettings) {
|
5004 | factories.push(agentPolicy(options.agentSettings));
|
5005 | }
|
5006 | return factories;
|
5007 | }
|
5008 | function getOperationArgumentValueFromParameter(serviceClient, operationArguments, parameter, serializer) {
|
5009 | return getOperationArgumentValueFromParameterPath(serviceClient, operationArguments, parameter.parameterPath, parameter.mapper, serializer);
|
5010 | }
|
5011 | function getOperationArgumentValueFromParameterPath(serviceClient, operationArguments, parameterPath, parameterMapper, serializer) {
|
5012 | var value;
|
5013 | if (typeof parameterPath === "string") {
|
5014 | parameterPath = [parameterPath];
|
5015 | }
|
5016 | if (Array.isArray(parameterPath)) {
|
5017 | if (parameterPath.length > 0) {
|
5018 | if (parameterMapper.isConstant) {
|
5019 | value = parameterMapper.defaultValue;
|
5020 | }
|
5021 | else {
|
5022 | var propertySearchResult = getPropertyFromParameterPath(operationArguments, parameterPath);
|
5023 | if (!propertySearchResult.propertyFound) {
|
5024 | propertySearchResult = getPropertyFromParameterPath(serviceClient, parameterPath);
|
5025 | }
|
5026 | var useDefaultValue = false;
|
5027 | if (!propertySearchResult.propertyFound) {
|
5028 | useDefaultValue =
|
5029 | parameterMapper.required ||
|
5030 | (parameterPath[0] === "options" && parameterPath.length === 2);
|
5031 | }
|
5032 | value = useDefaultValue ? parameterMapper.defaultValue : propertySearchResult.propertyValue;
|
5033 | }
|
5034 |
|
5035 | var parameterPathString = getPathStringFromParameterPath(parameterPath, parameterMapper);
|
5036 | serializer.serialize(parameterMapper, value, parameterPathString);
|
5037 | }
|
5038 | }
|
5039 | else {
|
5040 | if (parameterMapper.required) {
|
5041 | value = {};
|
5042 | }
|
5043 | for (var propertyName in parameterPath) {
|
5044 | var propertyMapper = parameterMapper.type.modelProperties[propertyName];
|
5045 | var propertyPath = parameterPath[propertyName];
|
5046 | var propertyValue = getOperationArgumentValueFromParameterPath(serviceClient, operationArguments, propertyPath, propertyMapper, serializer);
|
5047 |
|
5048 | var propertyPathString = getPathStringFromParameterPath(propertyPath, propertyMapper);
|
5049 | serializer.serialize(propertyMapper, propertyValue, propertyPathString);
|
5050 | if (propertyValue !== undefined) {
|
5051 | if (!value) {
|
5052 | value = {};
|
5053 | }
|
5054 | value[propertyName] = propertyValue;
|
5055 | }
|
5056 | }
|
5057 | }
|
5058 | return value;
|
5059 | }
|
5060 | function getPropertyFromParameterPath(parent, parameterPath) {
|
5061 | var result = { propertyFound: false };
|
5062 | var i = 0;
|
5063 | for (; i < parameterPath.length; ++i) {
|
5064 | var parameterPathPart = parameterPath[i];
|
5065 |
|
5066 | if (parent != undefined && parameterPathPart in parent) {
|
5067 | parent = parent[parameterPathPart];
|
5068 | }
|
5069 | else {
|
5070 | break;
|
5071 | }
|
5072 | }
|
5073 | if (i === parameterPath.length) {
|
5074 | result.propertyValue = parent;
|
5075 | result.propertyFound = true;
|
5076 | }
|
5077 | return result;
|
5078 | }
|
5079 | function flattenResponse(_response, responseSpec) {
|
5080 | var parsedHeaders = _response.parsedHeaders;
|
5081 | var bodyMapper = responseSpec && responseSpec.bodyMapper;
|
5082 | var addOperationResponse = function (obj) {
|
5083 | return Object.defineProperty(obj, "_response", {
|
5084 | value: _response,
|
5085 | });
|
5086 | };
|
5087 | if (bodyMapper) {
|
5088 | var typeName = bodyMapper.type.name;
|
5089 | if (typeName === "Stream") {
|
5090 | return addOperationResponse(tslib.__assign(tslib.__assign({}, parsedHeaders), { blobBody: _response.blobBody, readableStreamBody: _response.readableStreamBody }));
|
5091 | }
|
5092 | var modelProperties_1 = (typeName === "Composite" && bodyMapper.type.modelProperties) || {};
|
5093 | var isPageableResponse = Object.keys(modelProperties_1).some(function (k) { return modelProperties_1[k].serializedName === ""; });
|
5094 | if (typeName === "Sequence" || isPageableResponse) {
|
5095 |
|
5096 |
|
5097 | var parsedBody = Array.isArray(_response.parsedBody) ? _response.parsedBody : [];
|
5098 | var arrayResponse = tslib.__spreadArrays(parsedBody);
|
5099 | for (var _i = 0, _a = Object.keys(modelProperties_1); _i < _a.length; _i++) {
|
5100 | var key = _a[_i];
|
5101 | if (modelProperties_1[key].serializedName) {
|
5102 | arrayResponse[key] = _response.parsedBody[key];
|
5103 | }
|
5104 | }
|
5105 | if (parsedHeaders) {
|
5106 | for (var _b = 0, _c = Object.keys(parsedHeaders); _b < _c.length; _b++) {
|
5107 | var key = _c[_b];
|
5108 | arrayResponse[key] = parsedHeaders[key];
|
5109 | }
|
5110 | }
|
5111 | addOperationResponse(arrayResponse);
|
5112 | return arrayResponse;
|
5113 | }
|
5114 | if (typeName === "Composite" || typeName === "Dictionary") {
|
5115 | return addOperationResponse(tslib.__assign(tslib.__assign({}, parsedHeaders), _response.parsedBody));
|
5116 | }
|
5117 | }
|
5118 | if (bodyMapper ||
|
5119 | _response.request.method === "HEAD" ||
|
5120 | isPrimitiveType(_response.parsedBody)) {
|
5121 |
|
5122 | return addOperationResponse(tslib.__assign(tslib.__assign({}, parsedHeaders), { body: _response.parsedBody }));
|
5123 | }
|
5124 | return addOperationResponse(tslib.__assign(tslib.__assign({}, parsedHeaders), _response.parsedBody));
|
5125 | }
|
5126 |
|
5127 |
|
5128 | function logPolicy(logger) {
|
5129 | if (logger === void 0) { logger = console.log; }
|
5130 | return {
|
5131 | create: function (nextPolicy, options) {
|
5132 | return new LogPolicy(nextPolicy, options, logger);
|
5133 | },
|
5134 | };
|
5135 | }
|
5136 | var LogPolicy = (function (_super) {
|
5137 | tslib.__extends(LogPolicy, _super);
|
5138 | function LogPolicy(nextPolicy, options, logger) {
|
5139 | if (logger === void 0) { logger = console.log; }
|
5140 | var _this = _super.call(this, nextPolicy, options) || this;
|
5141 | _this.logger = logger;
|
5142 | return _this;
|
5143 | }
|
5144 | LogPolicy.prototype.sendRequest = function (request) {
|
5145 | var _this = this;
|
5146 | return this._nextPolicy.sendRequest(request).then(function (response) { return logResponse(_this, response); });
|
5147 | };
|
5148 | return LogPolicy;
|
5149 | }(BaseRequestPolicy));
|
5150 | function logResponse(policy, response) {
|
5151 | policy.logger(">> Request: " + JSON.stringify(response.request, undefined, 2));
|
5152 | policy.logger(">> Response status code: " + response.status);
|
5153 | var responseBody = response.bodyAsText;
|
5154 | policy.logger(">> Body: " + responseBody);
|
5155 | return Promise.resolve(response);
|
5156 | }
|
5157 |
|
5158 |
|
5159 | var HeaderConstants = Constants.HeaderConstants;
|
5160 | var DEFAULT_AUTHORIZATION_SCHEME$1 = "Bearer";
|
5161 |
|
5162 |
|
5163 |
|
5164 | var TokenCredentials = (function () {
|
5165 | |
5166 |
|
5167 |
|
5168 |
|
5169 |
|
5170 |
|
5171 |
|
5172 | function TokenCredentials(token, authorizationScheme) {
|
5173 | if (authorizationScheme === void 0) { authorizationScheme = DEFAULT_AUTHORIZATION_SCHEME$1; }
|
5174 | this.authorizationScheme = DEFAULT_AUTHORIZATION_SCHEME$1;
|
5175 | if (!token) {
|
5176 | throw new Error("token cannot be null or undefined.");
|
5177 | }
|
5178 | this.token = token;
|
5179 | this.authorizationScheme = authorizationScheme;
|
5180 | }
|
5181 | |
5182 |
|
5183 |
|
5184 |
|
5185 |
|
5186 |
|
5187 | TokenCredentials.prototype.signRequest = function (webResource) {
|
5188 | if (!webResource.headers)
|
5189 | webResource.headers = new HttpHeaders();
|
5190 | webResource.headers.set(HeaderConstants.AUTHORIZATION, this.authorizationScheme + " " + this.token);
|
5191 | return Promise.resolve(webResource);
|
5192 | };
|
5193 | return TokenCredentials;
|
5194 | }());
|
5195 |
|
5196 |
|
5197 | var HeaderConstants$1 = Constants.HeaderConstants;
|
5198 | var DEFAULT_AUTHORIZATION_SCHEME$2 = "Basic";
|
5199 | var BasicAuthenticationCredentials = (function () {
|
5200 | |
5201 |
|
5202 |
|
5203 |
|
5204 |
|
5205 |
|
5206 |
|
5207 |
|
5208 | function BasicAuthenticationCredentials(userName, password, authorizationScheme) {
|
5209 | if (authorizationScheme === void 0) { authorizationScheme = DEFAULT_AUTHORIZATION_SCHEME$2; }
|
5210 | this.authorizationScheme = DEFAULT_AUTHORIZATION_SCHEME$2;
|
5211 | if (userName === null || userName === undefined || typeof userName.valueOf() !== "string") {
|
5212 | throw new Error("userName cannot be null or undefined and must be of type string.");
|
5213 | }
|
5214 | if (password === null || password === undefined || typeof password.valueOf() !== "string") {
|
5215 | throw new Error("password cannot be null or undefined and must be of type string.");
|
5216 | }
|
5217 | this.userName = userName;
|
5218 | this.password = password;
|
5219 | this.authorizationScheme = authorizationScheme;
|
5220 | }
|
5221 | |
5222 |
|
5223 |
|
5224 |
|
5225 |
|
5226 |
|
5227 | BasicAuthenticationCredentials.prototype.signRequest = function (webResource) {
|
5228 | var credentials = this.userName + ":" + this.password;
|
5229 | var encodedCredentials = this.authorizationScheme + " " + encodeString(credentials);
|
5230 | if (!webResource.headers)
|
5231 | webResource.headers = new HttpHeaders();
|
5232 | webResource.headers.set(HeaderConstants$1.AUTHORIZATION, encodedCredentials);
|
5233 | return Promise.resolve(webResource);
|
5234 | };
|
5235 | return BasicAuthenticationCredentials;
|
5236 | }());
|
5237 |
|
5238 |
|
5239 |
|
5240 |
|
5241 |
|
5242 | var ApiKeyCredentials = (function () {
|
5243 | |
5244 |
|
5245 |
|
5246 |
|
5247 | function ApiKeyCredentials(options) {
|
5248 | if (!options || (options && !options.inHeader && !options.inQuery)) {
|
5249 | throw new Error("options cannot be null or undefined. Either \"inHeader\" or \"inQuery\" property of the options object needs to be provided.");
|
5250 | }
|
5251 | this.inHeader = options.inHeader;
|
5252 | this.inQuery = options.inQuery;
|
5253 | }
|
5254 | |
5255 |
|
5256 |
|
5257 |
|
5258 |
|
5259 |
|
5260 | ApiKeyCredentials.prototype.signRequest = function (webResource) {
|
5261 | if (!webResource) {
|
5262 | return Promise.reject(new Error("webResource cannot be null or undefined and must be of type \"object\"."));
|
5263 | }
|
5264 | if (this.inHeader) {
|
5265 | if (!webResource.headers) {
|
5266 | webResource.headers = new HttpHeaders();
|
5267 | }
|
5268 | for (var headerName in this.inHeader) {
|
5269 | webResource.headers.set(headerName, this.inHeader[headerName]);
|
5270 | }
|
5271 | }
|
5272 | if (this.inQuery) {
|
5273 | if (!webResource.url) {
|
5274 | return Promise.reject(new Error("url cannot be null in the request object."));
|
5275 | }
|
5276 | if (webResource.url.indexOf("?") < 0) {
|
5277 | webResource.url += "?";
|
5278 | }
|
5279 | for (var key in this.inQuery) {
|
5280 | if (!webResource.url.endsWith("?")) {
|
5281 | webResource.url += "&";
|
5282 | }
|
5283 | webResource.url += key + "=" + this.inQuery[key];
|
5284 | }
|
5285 | }
|
5286 | return Promise.resolve(webResource);
|
5287 | };
|
5288 | return ApiKeyCredentials;
|
5289 | }());
|
5290 |
|
5291 |
|
5292 | var TopicCredentials = (function (_super) {
|
5293 | tslib.__extends(TopicCredentials, _super);
|
5294 | |
5295 |
|
5296 |
|
5297 |
|
5298 |
|
5299 |
|
5300 | function TopicCredentials(topicKey) {
|
5301 | var _this = this;
|
5302 | if (!topicKey || (topicKey && typeof topicKey !== "string")) {
|
5303 | throw new Error("topicKey cannot be null or undefined and must be of type string.");
|
5304 | }
|
5305 | var options = {
|
5306 | inHeader: {
|
5307 | "aeg-sas-key": topicKey,
|
5308 | },
|
5309 | };
|
5310 | _this = _super.call(this, options) || this;
|
5311 | return _this;
|
5312 | }
|
5313 | return TopicCredentials;
|
5314 | }(ApiKeyCredentials));
|
5315 |
|
5316 |
|
5317 | var DomainCredentials = (function (_super) {
|
5318 | tslib.__extends(DomainCredentials, _super);
|
5319 | |
5320 |
|
5321 |
|
5322 |
|
5323 |
|
5324 |
|
5325 | function DomainCredentials(domainKey) {
|
5326 | var _this = this;
|
5327 | if (!domainKey || (domainKey && typeof domainKey !== "string")) {
|
5328 | throw new Error("domainKey cannot be null or undefined and must be of type string.");
|
5329 | }
|
5330 | var options = {
|
5331 | inHeader: {
|
5332 | "aeg-sas-key": domainKey,
|
5333 | },
|
5334 | };
|
5335 | _this = _super.call(this, options) || this;
|
5336 | return _this;
|
5337 | }
|
5338 | return DomainCredentials;
|
5339 | }(ApiKeyCredentials));
|
5340 |
|
5341 | exports.ApiKeyCredentials = ApiKeyCredentials;
|
5342 | exports.AzureIdentityCredentialAdapter = AzureIdentityCredentialAdapter;
|
5343 | exports.BaseRequestPolicy = BaseRequestPolicy;
|
5344 | exports.BasicAuthenticationCredentials = BasicAuthenticationCredentials;
|
5345 | exports.Constants = Constants;
|
5346 | exports.DefaultHttpClient = NodeFetchHttpClient;
|
5347 | exports.DomainCredentials = DomainCredentials;
|
5348 | exports.HttpHeaders = HttpHeaders;
|
5349 | exports.MapperType = MapperType;
|
5350 | exports.RequestPolicyOptions = RequestPolicyOptions;
|
5351 | exports.RestError = RestError;
|
5352 | exports.Serializer = Serializer;
|
5353 | exports.ServiceClient = ServiceClient;
|
5354 | exports.TokenCredentials = TokenCredentials;
|
5355 | exports.TopicCredentials = TopicCredentials;
|
5356 | exports.URLBuilder = URLBuilder;
|
5357 | exports.URLQuery = URLQuery;
|
5358 | exports.WebResource = WebResource;
|
5359 | exports.agentPolicy = agentPolicy;
|
5360 | exports.applyMixins = applyMixins;
|
5361 | exports.delay = delay;
|
5362 | exports.deserializationPolicy = deserializationPolicy;
|
5363 | exports.deserializeResponseBody = deserializeResponseBody;
|
5364 | exports.encodeUri = encodeUri;
|
5365 | exports.executePromisesSequentially = executePromisesSequentially;
|
5366 | exports.exponentialRetryPolicy = exponentialRetryPolicy;
|
5367 | exports.flattenResponse = flattenResponse;
|
5368 | exports.generateClientRequestIdPolicy = generateClientRequestIdPolicy;
|
5369 | exports.generateUuid = generateUuid;
|
5370 | exports.getDefaultProxySettings = getDefaultProxySettings;
|
5371 | exports.getDefaultUserAgentValue = getDefaultUserAgentValue;
|
5372 | exports.isDuration = isDuration;
|
5373 | exports.isNode = isNode;
|
5374 | exports.isValidUuid = isValidUuid;
|
5375 | exports.logPolicy = logPolicy;
|
5376 | exports.promiseToCallback = promiseToCallback;
|
5377 | exports.promiseToServiceCallback = promiseToServiceCallback;
|
5378 | exports.proxyPolicy = proxyPolicy;
|
5379 | exports.redirectPolicy = redirectPolicy;
|
5380 | exports.serializeObject = serializeObject;
|
5381 | exports.signingPolicy = signingPolicy;
|
5382 | exports.stripRequest = stripRequest;
|
5383 | exports.stripResponse = stripResponse;
|
5384 | exports.systemErrorRetryPolicy = systemErrorRetryPolicy;
|
5385 | exports.throttlingRetryPolicy = throttlingRetryPolicy;
|
5386 | exports.userAgentPolicy = userAgentPolicy;
|
5387 |
|