@azure/core-client 1.4.0-alpha.20211123.3 → 1.4.0-alpha.20220106.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,17 +1,21 @@
1
1
  # Release History
2
2
 
3
- ## 1.4.0 (Unreleased)
3
+ ## 1.4.0 (2022-01-06)
4
4
 
5
5
  ### Features Added
6
6
 
7
7
  - Added a new function `authorizeRequestOnClaimChallenge`, that can be used with the `@azure/core-rest-pipeline`'s `bearerTokenAuthenticationPolicy` to support [Continuous Access Evaluation (CAE) challenges](https://docs.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation).
8
- - Call the `bearerTokenAuthenticationPolicy` with the following options: `bearerTokenAuthenticationPolicy({ authorizeRequestOnChallenge: authorizeRequestOnClaimChallenge })`. Once provided, the `bearerTokenAuthenticationPolicy` policy will internally handle Continuous Access Evaluation (CAE) challenges. When it can't complete a challenge it will return the 401 (unauthorized) response from ARM.
8
+ - Call the `bearerTokenAuthenticationPolicy` with the following options: `bearerTokenAuthenticationPolicy({ authorizeRequestOnChallenge: authorizeRequestOnClaimChallenge })`. Once provided, the `bearerTokenAuthenticationPolicy` policy will internally handle Continuous Access Evaluation (CAE) challenges. When it can't complete a challenge it will return the 401 (unauthorized) response from ARM.
9
9
 
10
- ### Breaking Changes
10
+ ### Bugs Fixed
11
+
12
+ - Fixed a serializer issue with nested polymorphics. [PR #19455](https://github.com/Azure/azure-sdk-for-js/pull/19455)
13
+
14
+ ## 1.3.3 (2021-12-02)
11
15
 
12
16
  ### Bugs Fixed
13
17
 
14
- ### Other Changes
18
+ - Added a check to handle undefined value during the parsing of query parameters. Please refer to [PR #18621](https://github.com/Azure/azure-sdk-for-js/pull/18621) for further details.
15
19
 
16
20
  ## 1.3.2 (2021-10-25)
17
21
 
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var coreRestPipeline = require('@azure/core-rest-pipeline');
6
- var logger$1 = require('@azure/logger');
6
+ var logger = require('@azure/logger');
7
7
  require('@azure/core-asynciterator-polyfill');
8
8
 
9
9
  // Copyright (c) Microsoft Corporation.
@@ -117,7 +117,7 @@ function flattenResponse(fullResponse, responseSpec) {
117
117
  body: fullResponse.parsedBody,
118
118
  headers: parsedHeaders,
119
119
  hasNullableType: isNullable,
120
- shouldWrapBody: isPrimitiveBody(fullResponse.parsedBody, expectedBodyTypeName)
120
+ shouldWrapBody: isPrimitiveBody(fullResponse.parsedBody, expectedBodyTypeName),
121
121
  });
122
122
  }
123
123
 
@@ -144,6 +144,7 @@ function decodeString(value) {
144
144
  /**
145
145
  * Decodes a base64 string into a string.
146
146
  * @param value - the base64 string to decode
147
+ * @internal
147
148
  */
148
149
  function decodeStringToString(value) {
149
150
  return Buffer.from(value, "base64").toString();
@@ -171,7 +172,7 @@ class SerializerImpl {
171
172
  throw new Error(`"${objectName}" with value "${value}" should satisfy the constraint "${constraintName}": ${constraintValue}.`);
172
173
  };
173
174
  if (mapper.constraints && value !== undefined && value !== null) {
174
- const { ExclusiveMaximum, ExclusiveMinimum, InclusiveMaximum, InclusiveMinimum, MaxItems, MaxLength, MinItems, MinLength, MultipleOf, Pattern, UniqueItems } = mapper.constraints;
175
+ const { ExclusiveMaximum, ExclusiveMinimum, InclusiveMaximum, InclusiveMinimum, MaxItems, MaxLength, MinItems, MinLength, MultipleOf, Pattern, UniqueItems, } = mapper.constraints;
175
176
  if (ExclusiveMaximum !== undefined && value >= ExclusiveMaximum) {
176
177
  failValidation("ExclusiveMaximum", ExclusiveMaximum);
177
178
  }
@@ -230,8 +231,8 @@ class SerializerImpl {
230
231
  xml: {
231
232
  rootName: (_a = options.xml.rootName) !== null && _a !== void 0 ? _a : "",
232
233
  includeRoot: (_b = options.xml.includeRoot) !== null && _b !== void 0 ? _b : false,
233
- xmlCharKey: (_c = options.xml.xmlCharKey) !== null && _c !== void 0 ? _c : XML_CHARKEY
234
- }
234
+ xmlCharKey: (_c = options.xml.xmlCharKey) !== null && _c !== void 0 ? _c : XML_CHARKEY,
235
+ },
235
236
  };
236
237
  let payload = {};
237
238
  const mapperType = mapper.type.name;
@@ -319,8 +320,8 @@ class SerializerImpl {
319
320
  xml: {
320
321
  rootName: (_a = options.xml.rootName) !== null && _a !== void 0 ? _a : "",
321
322
  includeRoot: (_b = options.xml.includeRoot) !== null && _b !== void 0 ? _b : false,
322
- xmlCharKey: (_c = options.xml.xmlCharKey) !== null && _c !== void 0 ? _c : XML_CHARKEY
323
- }
323
+ xmlCharKey: (_c = options.xml.xmlCharKey) !== null && _c !== void 0 ? _c : XML_CHARKEY,
324
+ },
324
325
  };
325
326
  if (responseBody === undefined || responseBody === null) {
326
327
  if (this.isXML && mapper.type.name === "Sequence" && !mapper.xmlIsWrapped) {
@@ -425,9 +426,7 @@ function bufferToBase64Url(buffer) {
425
426
  // Uint8Array to Base64.
426
427
  const str = encodeByteArray(buffer);
427
428
  // Base64 to Base64Url.
428
- return trimEnd(str, "=")
429
- .replace(/\+/g, "-")
430
- .replace(/\//g, "_");
429
+ return trimEnd(str, "=").replace(/\+/g, "-").replace(/\//g, "_");
431
430
  }
432
431
  function base64UrlToByteArray(str) {
433
432
  if (!str) {
@@ -586,14 +585,21 @@ function serializeDateTypes(typeName, value, objectName) {
586
585
  return value;
587
586
  }
588
587
  function serializeSequenceType(serializer, mapper, object, objectName, isXml, options) {
588
+ var _a;
589
589
  if (!Array.isArray(object)) {
590
590
  throw new Error(`${objectName} must be of type Array.`);
591
591
  }
592
- const elementType = mapper.type.element;
592
+ let elementType = mapper.type.element;
593
593
  if (!elementType || typeof elementType !== "object") {
594
594
  throw new Error(`element" metadata for an Array must be defined in the ` +
595
595
  `mapper and it must of type "object" in ${objectName}.`);
596
596
  }
597
+ // Quirk: Composite mappers referenced by `element` might
598
+ // not have *all* properties declared (like uberParent),
599
+ // so let's try to look up the full definition by name.
600
+ if (elementType.type.name === "Composite" && elementType.type.className) {
601
+ elementType = (_a = serializer.modelMappers[elementType.type.className]) !== null && _a !== void 0 ? _a : elementType;
602
+ }
597
603
  const tempArray = [];
598
604
  for (let i = 0; i < object.length; i++) {
599
605
  const serializedValue = serializer.serialize(elementType, object[i], objectName, options);
@@ -949,8 +955,8 @@ function deserializeDictionaryType(serializer, mapper, responseBody, objectName,
949
955
  return responseBody;
950
956
  }
951
957
  function deserializeSequenceType(serializer, mapper, responseBody, objectName, options) {
952
- /* jshint validthis: true */
953
- const element = mapper.type.element;
958
+ var _a;
959
+ let element = mapper.type.element;
954
960
  if (!element || typeof element !== "object") {
955
961
  throw new Error(`element" metadata for an Array must be defined in the ` +
956
962
  `mapper and it must of type "object" in ${objectName}`);
@@ -960,6 +966,12 @@ function deserializeSequenceType(serializer, mapper, responseBody, objectName, o
960
966
  // xml2js will interpret a single element array as just the element, so force it to be an array
961
967
  responseBody = [responseBody];
962
968
  }
969
+ // Quirk: Composite mappers referenced by `element` might
970
+ // not have *all* properties declared (like uberParent),
971
+ // so let's try to look up the full definition by name.
972
+ if (element.type.name === "Composite" && element.type.className) {
973
+ element = (_a = serializer.modelMappers[element.type.className]) !== null && _a !== void 0 ? _a : element;
974
+ }
963
975
  const tempArray = [];
964
976
  for (let i = 0; i < responseBody.length; i++) {
965
977
  tempArray[i] = serializer.deserialize(element, responseBody[i], `${objectName}[${i}]`, options);
@@ -971,8 +983,12 @@ function deserializeSequenceType(serializer, mapper, responseBody, objectName, o
971
983
  function getPolymorphicMapper(serializer, mapper, object, polymorphicPropertyName) {
972
984
  const polymorphicDiscriminator = getPolymorphicDiscriminatorRecursively(serializer, mapper);
973
985
  if (polymorphicDiscriminator) {
974
- const discriminatorName = polymorphicDiscriminator[polymorphicPropertyName];
986
+ let discriminatorName = polymorphicDiscriminator[polymorphicPropertyName];
975
987
  if (discriminatorName) {
988
+ // The serializedName might have \\, which we just want to ignore
989
+ if (polymorphicPropertyName === "serializedName") {
990
+ discriminatorName = discriminatorName.replace(/\\/gi, "");
991
+ }
976
992
  const discriminatorValue = object[discriminatorName];
977
993
  if (discriminatorValue !== undefined && discriminatorValue !== null) {
978
994
  const typeName = mapper.type.uberParent || mapper.type.className;
@@ -1017,7 +1033,7 @@ const MapperTypeNames = {
1017
1033
  String: "String",
1018
1034
  Stream: "Stream",
1019
1035
  TimeSpan: "TimeSpan",
1020
- UnixTime: "UnixTime"
1036
+ UnixTime: "UnixTime",
1021
1037
  };
1022
1038
 
1023
1039
  // Copyright (c) Microsoft Corporation.
@@ -1103,7 +1119,7 @@ function getOperationArgumentValueFromParameter(operationArguments, parameter, f
1103
1119
  const propertyPath = parameterPath[propertyName];
1104
1120
  const propertyValue = getOperationArgumentValueFromParameter(operationArguments, {
1105
1121
  parameterPath: propertyPath,
1106
- mapper: propertyMapper
1122
+ mapper: propertyMapper,
1107
1123
  }, fallbackObject);
1108
1124
  if (propertyValue !== undefined) {
1109
1125
  if (!value) {
@@ -1149,7 +1165,7 @@ const CollectionFormatToDelimiterMap = {
1149
1165
  SSV: " ",
1150
1166
  Multi: "Multi",
1151
1167
  TSV: "\t",
1152
- Pipes: "|"
1168
+ Pipes: "|",
1153
1169
  };
1154
1170
  function getRequestUrl(baseUri, operationSpec, operationArguments, fallbackObject) {
1155
1171
  const urlReplacements = calculateUrlReplacements(operationSpec, operationArguments, fallbackObject);
@@ -1284,7 +1300,7 @@ function calculateQueryParameters(operationSpec, operationArguments, fallbackObj
1284
1300
  }
1285
1301
  return {
1286
1302
  queryParams: result,
1287
- sequenceParams
1303
+ sequenceParams,
1288
1304
  };
1289
1305
  }
1290
1306
  function simpleParseQueryParams(queryString) {
@@ -1398,15 +1414,15 @@ function deserializationPolicy(options = {}) {
1398
1414
  xml: {
1399
1415
  rootName: (_e = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.rootName) !== null && _e !== void 0 ? _e : "",
1400
1416
  includeRoot: (_f = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.includeRoot) !== null && _f !== void 0 ? _f : false,
1401
- xmlCharKey: (_g = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.xmlCharKey) !== null && _g !== void 0 ? _g : XML_CHARKEY
1402
- }
1417
+ xmlCharKey: (_g = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.xmlCharKey) !== null && _g !== void 0 ? _g : XML_CHARKEY,
1418
+ },
1403
1419
  };
1404
1420
  return {
1405
1421
  name: deserializationPolicyName,
1406
1422
  async sendRequest(request, next) {
1407
1423
  const response = await next(request);
1408
1424
  return deserializeResponseBody(jsonContentTypes, xmlContentTypes, response, updatedOptions, parseXML);
1409
- }
1425
+ },
1410
1426
  };
1411
1427
  }
1412
1428
  function getOperationResponseMap(parsedResponse) {
@@ -1476,7 +1492,7 @@ async function deserializeResponseBody(jsonContentTypes, xmlContentTypes, respon
1476
1492
  const restError = new coreRestPipeline.RestError(`Error ${deserializeError} occurred in deserializing the responseBody - ${parsedResponse.bodyAsText}`, {
1477
1493
  statusCode: parsedResponse.status,
1478
1494
  request: parsedResponse.request,
1479
- response: parsedResponse
1495
+ response: parsedResponse,
1480
1496
  });
1481
1497
  throw restError;
1482
1498
  }
@@ -1519,7 +1535,7 @@ function handleErrorResponse(parsedResponse, operationSpec, responseSpec) {
1519
1535
  const error = new coreRestPipeline.RestError(initialErrorMessage, {
1520
1536
  statusCode: parsedResponse.status,
1521
1537
  request: parsedResponse.request,
1522
- response: parsedResponse
1538
+ response: parsedResponse,
1523
1539
  });
1524
1540
  // If the item failed but there's no error spec or default spec to deserialize the error,
1525
1541
  // we should fail so we just throw the parsed response
@@ -1556,7 +1572,8 @@ function handleErrorResponse(parsedResponse, operationSpec, responseSpec) {
1556
1572
  }
1557
1573
  // If error response has headers, try to deserialize it using default header mapper
1558
1574
  if (parsedResponse.headers && defaultHeadersMapper) {
1559
- error.response.parsedHeaders = operationSpec.serializer.deserialize(defaultHeadersMapper, parsedResponse.headers.toJSON(), "operationRes.parsedHeaders");
1575
+ error.response.parsedHeaders =
1576
+ operationSpec.serializer.deserialize(defaultHeadersMapper, parsedResponse.headers.toJSON(), "operationRes.parsedHeaders");
1560
1577
  }
1561
1578
  }
1562
1579
  catch (defaultError) {
@@ -1595,7 +1612,7 @@ async function parse(jsonContentTypes, xmlContentTypes, operationResponse, opts,
1595
1612
  code: errCode,
1596
1613
  statusCode: operationResponse.status,
1597
1614
  request: operationResponse.request,
1598
- response: operationResponse
1615
+ response: operationResponse,
1599
1616
  });
1600
1617
  throw e;
1601
1618
  }
@@ -1625,7 +1642,7 @@ function serializationPolicy(options = {}) {
1625
1642
  serializeRequestBody(request, operationArguments, operationSpec, stringifyXML);
1626
1643
  }
1627
1644
  return next(request);
1628
- }
1645
+ },
1629
1646
  };
1630
1647
  }
1631
1648
  /**
@@ -1670,14 +1687,14 @@ function serializeRequestBody(request, operationArguments, operationSpec, string
1670
1687
  xml: {
1671
1688
  rootName: (_b = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.rootName) !== null && _b !== void 0 ? _b : "",
1672
1689
  includeRoot: (_c = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.includeRoot) !== null && _c !== void 0 ? _c : false,
1673
- xmlCharKey: (_d = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.xmlCharKey) !== null && _d !== void 0 ? _d : XML_CHARKEY
1674
- }
1690
+ xmlCharKey: (_d = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.xmlCharKey) !== null && _d !== void 0 ? _d : XML_CHARKEY,
1691
+ },
1675
1692
  };
1676
1693
  const xmlCharKey = updatedOptions.xml.xmlCharKey;
1677
1694
  if (operationSpec.requestBody && operationSpec.requestBody.mapper) {
1678
1695
  request.body = getOperationArgumentValueFromParameter(operationArguments, operationSpec.requestBody);
1679
1696
  const bodyMapper = operationSpec.requestBody.mapper;
1680
- const { required, serializedName, xmlName, xmlElementName, xmlNamespace, xmlNamespacePrefix, nullable } = bodyMapper;
1697
+ const { required, serializedName, xmlName, xmlElementName, xmlNamespace, xmlNamespacePrefix, nullable, } = bodyMapper;
1681
1698
  const typeName = bodyMapper.type.name;
1682
1699
  try {
1683
1700
  if ((request.body !== undefined && request.body !== null) ||
@@ -1695,7 +1712,7 @@ function serializeRequestBody(request, operationArguments, operationSpec, string
1695
1712
  else if (!isStream) {
1696
1713
  request.body = stringifyXML(value, {
1697
1714
  rootName: xmlName || serializedName,
1698
- xmlCharKey
1715
+ xmlCharKey,
1699
1716
  });
1700
1717
  }
1701
1718
  }
@@ -1763,12 +1780,12 @@ function createClientPipeline(options = {}) {
1763
1780
  if (options.credentialOptions) {
1764
1781
  pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
1765
1782
  credential: options.credentialOptions.credential,
1766
- scopes: options.credentialOptions.credentialScopes
1783
+ scopes: options.credentialOptions.credentialScopes,
1767
1784
  }));
1768
1785
  }
1769
1786
  pipeline.addPolicy(serializationPolicy(options.serializationOptions), { phase: "Serialize" });
1770
1787
  pipeline.addPolicy(deserializationPolicy(options.deserializationOptions), {
1771
- phase: "Deserialize"
1788
+ phase: "Deserialize",
1772
1789
  });
1773
1790
  return pipeline;
1774
1791
  }
@@ -1812,7 +1829,7 @@ class ServiceClient {
1812
1829
  // not part of OperationArguments
1813
1830
  const url = getRequestUrl(baseUri, operationSpec, operationArguments, this);
1814
1831
  const request = coreRestPipeline.createPipelineRequest({
1815
- url
1832
+ url,
1816
1833
  });
1817
1834
  request.method = operationSpec.httpMethod;
1818
1835
  const operationInfo = getOperationRequestInfo(request);
@@ -1895,7 +1912,7 @@ function getCredentialScopes(options) {
1895
1912
  }
1896
1913
 
1897
1914
  // Copyright (c) Microsoft Corporation.
1898
- const logger = logger$1.createClientLogger("authorizeRequestOnClaimChallenge");
1915
+ const defaultLogger = logger.createClientLogger("authorizeRequestOnClaimChallenge");
1899
1916
  /**
1900
1917
  * Converts: `Bearer a="b", c="d", Bearer d="e", f="g"`.
1901
1918
  * Into: `[ { a: 'b', c: 'd' }, { d: 'e', f: 'g' } ]`.
@@ -1939,6 +1956,7 @@ function parseCAEChallenge(challenges) {
1939
1956
  */
1940
1957
  async function authorizeRequestOnClaimChallenge(onChallengeOptions) {
1941
1958
  const { scopes, response } = onChallengeOptions;
1959
+ const logger = onChallengeOptions.logger || defaultLogger;
1942
1960
  const challenge = response.headers.get("WWW-Authenticate");
1943
1961
  if (!challenge) {
1944
1962
  logger.info(`The WWW-Authenticate header was missing. Failed to perform the Continuous Access Evaluation authentication flow.`);
@@ -1951,7 +1969,7 @@ async function authorizeRequestOnClaimChallenge(onChallengeOptions) {
1951
1969
  return false;
1952
1970
  }
1953
1971
  const accessToken = await onChallengeOptions.getAccessToken(parsedChallenge.scope ? [parsedChallenge.scope] : scopes, {
1954
- claims: decodeStringToString(parsedChallenge.claims)
1972
+ claims: decodeStringToString(parsedChallenge.claims),
1955
1973
  });
1956
1974
  if (!accessToken) {
1957
1975
  return false;