@azure/core-rest-pipeline 1.4.1-alpha.20220114.1 → 1.5.0

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,14 +1,16 @@
1
1
  # Release History
2
2
 
3
- ## 1.4.1 (Unreleased)
3
+ ## 1.5.0 (2022-02-03)
4
4
 
5
5
  ### Features Added
6
6
 
7
- ### Breaking Changes
7
+ - Added new phase "Sign" for policies that sign the request for security purposes. [#20129](https://github.com/Azure/azure-sdk-for-js/pull/20129)
8
8
 
9
9
  ### Bugs Fixed
10
10
 
11
- ### Other Changes
11
+ - Updated the HTTP tracing span names to conform to the [OpenTelemetry Specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#name). [#19838](https://github.com/Azure/azure-sdk-for-js/pull/19838)
12
+ - New HTTP spans will use the `HTTP <VERB>` convention instead of using the URL path.
13
+ - Addressed an issue where policy order might change in cases where there are no policies inside a phase specified by an "afterPhase" constraint. [#20129](https://github.com/Azure/azure-sdk-for-js/pull/20129)
12
14
 
13
15
  ## 1.4.0 (2022-01-06)
14
16
 
package/dist/index.js CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- var FormData = _interopDefault(require('form-data'));
5
+ var FormData = require('form-data');
8
6
  var logger$1 = require('@azure/logger');
9
7
  var url = require('url');
10
8
  var httpsProxyAgent$1 = require('https-proxy-agent');
@@ -19,9 +17,35 @@ var stream = require('stream');
19
17
  var util = require('util');
20
18
  var uuid = require('uuid');
21
19
 
20
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
+
22
+ function _interopNamespace(e) {
23
+ if (e && e.__esModule) return e;
24
+ var n = Object.create(null);
25
+ if (e) {
26
+ Object.keys(e).forEach(function (k) {
27
+ if (k !== 'default') {
28
+ var d = Object.getOwnPropertyDescriptor(e, k);
29
+ Object.defineProperty(n, k, d.get ? d : {
30
+ enumerable: true,
31
+ get: function () { return e[k]; }
32
+ });
33
+ }
34
+ });
35
+ }
36
+ n["default"] = e;
37
+ return Object.freeze(n);
38
+ }
39
+
40
+ var FormData__default = /*#__PURE__*/_interopDefaultLegacy(FormData);
41
+ var os__namespace = /*#__PURE__*/_interopNamespace(os);
42
+ var http__namespace = /*#__PURE__*/_interopNamespace(http);
43
+ var https__namespace = /*#__PURE__*/_interopNamespace(https);
44
+ var zlib__namespace = /*#__PURE__*/_interopNamespace(zlib);
45
+
22
46
  // Copyright (c) Microsoft Corporation.
23
47
  // Licensed under the MIT license.
24
- const ValidPhaseNames = new Set(["Deserialize", "Serialize", "Retry"]);
48
+ const ValidPhaseNames = new Set(["Deserialize", "Serialize", "Retry", "Sign"]);
25
49
  /**
26
50
  * A private implementation of Pipeline.
27
51
  * Do not export this class from the package.
@@ -96,6 +120,7 @@ class HttpPipeline {
96
120
  * 2. Policies not in a phase
97
121
  * 3. Deserialize Phase
98
122
  * 4. Retry Phase
123
+ * 5. Sign Phase
99
124
  *
100
125
  * Within each phase, policies are executed in the order
101
126
  * they were added unless they were specified to execute
@@ -123,14 +148,22 @@ class HttpPipeline {
123
148
  const result = [];
124
149
  // Track all policies we know about.
125
150
  const policyMap = new Map();
151
+ function createPhase(name) {
152
+ return {
153
+ name,
154
+ policies: new Set(),
155
+ hasRun: false,
156
+ };
157
+ }
126
158
  // Track policies for each phase.
127
- const serializePhase = new Set();
128
- const noPhase = new Set();
129
- const deserializePhase = new Set();
130
- const retryPhase = new Set();
159
+ const serializePhase = createPhase("Serialize");
160
+ const noPhase = createPhase("None");
161
+ const deserializePhase = createPhase("Deserialize");
162
+ const retryPhase = createPhase("Retry");
163
+ const signPhase = createPhase("Sign");
131
164
  // a list of phases in order
132
- const orderedPhases = [serializePhase, noPhase, deserializePhase, retryPhase];
133
- // Small helper function to map phase name to each Set bucket.
165
+ const orderedPhases = [serializePhase, noPhase, deserializePhase, retryPhase, signPhase];
166
+ // Small helper function to map phase name to each Phase
134
167
  function getPhase(phase) {
135
168
  if (phase === "Retry") {
136
169
  return retryPhase;
@@ -141,6 +174,9 @@ class HttpPipeline {
141
174
  else if (phase === "Deserialize") {
142
175
  return deserializePhase;
143
176
  }
177
+ else if (phase === "Sign") {
178
+ return signPhase;
179
+ }
144
180
  else {
145
181
  return noPhase;
146
182
  }
@@ -163,7 +199,7 @@ class HttpPipeline {
163
199
  }
164
200
  policyMap.set(policyName, node);
165
201
  const phase = getPhase(options.phase);
166
- phase.add(node);
202
+ phase.policies.add(node);
167
203
  }
168
204
  // Now that each policy has a node, connect dependency references.
169
205
  for (const descriptor of this._policies) {
@@ -197,11 +233,14 @@ class HttpPipeline {
197
233
  }
198
234
  }
199
235
  function walkPhase(phase) {
236
+ phase.hasRun = true;
200
237
  // Sets iterate in insertion order
201
- for (const node of phase) {
202
- if (node.afterPhase && node.afterPhase.size) {
238
+ for (const node of phase.policies) {
239
+ if (node.afterPhase && (!node.afterPhase.hasRun || node.afterPhase.policies.size)) {
203
240
  // If this node is waiting on a phase to complete,
204
241
  // we need to skip it for now.
242
+ // Even if the phase is empty, we should wait for it
243
+ // to be walked to avoid re-ordering policies.
205
244
  continue;
206
245
  }
207
246
  if (node.dependsOn.size === 0) {
@@ -214,20 +253,16 @@ class HttpPipeline {
214
253
  dependant.dependsOn.delete(node);
215
254
  }
216
255
  policyMap.delete(node.policy.name);
217
- phase.delete(node);
256
+ phase.policies.delete(node);
218
257
  }
219
258
  }
220
259
  }
221
260
  function walkPhases() {
222
- let noPhaseRan = false;
223
261
  for (const phase of orderedPhases) {
224
262
  walkPhase(phase);
225
- if (phase === noPhase) {
226
- noPhaseRan = true;
227
- }
228
263
  // if the phase isn't complete
229
- if (phase.size > 0 && phase !== noPhase) {
230
- if (noPhaseRan === false) {
264
+ if (phase.policies.size > 0 && phase !== noPhase) {
265
+ if (!noPhase.hasRun) {
231
266
  // Try running noPhase to see if that unblocks this phase next tick.
232
267
  // This can happen if a phase that happens before noPhase
233
268
  // is waiting on a noPhase policy to complete.
@@ -239,13 +274,16 @@ class HttpPipeline {
239
274
  }
240
275
  }
241
276
  // Iterate until we've put every node in the result list.
277
+ let iteration = 0;
242
278
  while (policyMap.size > 0) {
279
+ iteration++;
243
280
  const initialResultLength = result.length;
244
281
  // Keep walking each phase in order until we can order every node.
245
282
  walkPhases();
246
- // The result list *should* get at least one larger each time.
283
+ // The result list *should* get at least one larger each time
284
+ // after the first full pass.
247
285
  // Otherwise, we're going to loop forever.
248
- if (result.length <= initialResultLength) {
286
+ if (result.length <= initialResultLength && iteration > 1) {
249
287
  throw new Error("Cannot satisfy policy dependencies due to requirements cycle.");
250
288
  }
251
289
  }
@@ -324,7 +362,7 @@ function wwwFormUrlEncode(formData) {
324
362
  return urlSearchParams.toString();
325
363
  }
326
364
  async function prepareFormData(formData, request) {
327
- const requestForm = new FormData();
365
+ const requestForm = new FormData__default["default"]();
328
366
  for (const formKey of Object.keys(formData)) {
329
367
  const formValue = formData[formKey];
330
368
  if (Array.isArray(formValue)) {
@@ -842,12 +880,12 @@ function getHeaderName() {
842
880
  */
843
881
  function setPlatformSpecificData(map) {
844
882
  map.set("Node", process.version);
845
- map.set("OS", `(${os.arch()}-${os.type()}-${os.release()})`);
883
+ map.set("OS", `(${os__namespace.arch()}-${os__namespace.type()}-${os__namespace.release()})`);
846
884
  }
847
885
 
848
886
  // Copyright (c) Microsoft Corporation.
849
887
  // Licensed under the MIT license.
850
- const SDK_VERSION = "1.4.1";
888
+ const SDK_VERSION = "1.5.0";
851
889
 
852
890
  // Copyright (c) Microsoft Corporation.
853
891
  function getUserAgentString(telemetryInfo) {
@@ -1555,7 +1593,7 @@ class NodeHttpClient {
1555
1593
  headers: request.headers.toJSON({ preserveCase: true }),
1556
1594
  };
1557
1595
  return new Promise((resolve, reject) => {
1558
- const req = isInsecure ? http.request(options, resolve) : https.request(options, resolve);
1596
+ const req = isInsecure ? http__namespace.request(options, resolve) : https__namespace.request(options, resolve);
1559
1597
  req.once("error", (err) => {
1560
1598
  var _a;
1561
1599
  reject(new RestError(err.message, { code: (_a = err.code) !== null && _a !== void 0 ? _a : RestError.REQUEST_SEND_ERROR, request }));
@@ -1590,7 +1628,7 @@ class NodeHttpClient {
1590
1628
  if (!request.disableKeepAlive) {
1591
1629
  if (isInsecure) {
1592
1630
  if (!this.httpKeepAliveAgent) {
1593
- this.httpKeepAliveAgent = new http.Agent({
1631
+ this.httpKeepAliveAgent = new http__namespace.Agent({
1594
1632
  keepAlive: true,
1595
1633
  });
1596
1634
  }
@@ -1598,7 +1636,7 @@ class NodeHttpClient {
1598
1636
  }
1599
1637
  else {
1600
1638
  if (!this.httpsKeepAliveAgent) {
1601
- this.httpsKeepAliveAgent = new https.Agent({
1639
+ this.httpsKeepAliveAgent = new https__namespace.Agent({
1602
1640
  keepAlive: true,
1603
1641
  });
1604
1642
  }
@@ -1606,10 +1644,10 @@ class NodeHttpClient {
1606
1644
  }
1607
1645
  }
1608
1646
  else if (isInsecure) {
1609
- return http.globalAgent;
1647
+ return http__namespace.globalAgent;
1610
1648
  }
1611
1649
  else {
1612
- return https.globalAgent;
1650
+ return https__namespace.globalAgent;
1613
1651
  }
1614
1652
  }
1615
1653
  }
@@ -1631,12 +1669,12 @@ function getResponseHeaders(res) {
1631
1669
  function getDecodedResponseStream(stream, headers) {
1632
1670
  const contentEncoding = headers.get("Content-Encoding");
1633
1671
  if (contentEncoding === "gzip") {
1634
- const unzip = zlib.createGunzip();
1672
+ const unzip = zlib__namespace.createGunzip();
1635
1673
  stream.pipe(unzip);
1636
1674
  return unzip;
1637
1675
  }
1638
1676
  else if (contentEncoding === "deflate") {
1639
- const inflate = zlib.createInflate();
1677
+ const inflate = zlib__namespace.createInflate();
1640
1678
  stream.pipe(inflate);
1641
1679
  return inflate;
1642
1680
  }