@azure/storage-file-share 12.23.0-alpha.20240528.1 → 12.23.0-alpha.20240530.1

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ var coreAuth = require('@azure/core-auth');
9
9
  var coreHttpCompat = require('@azure/core-http-compat');
10
10
  var coreClient = require('@azure/core-client');
11
11
  var coreXml = require('@azure/core-xml');
12
- var logger$2 = require('@azure/logger');
12
+ var logger$1 = require('@azure/logger');
13
13
  var abortController = require('@azure/abort-controller');
14
14
  var crypto = require('crypto');
15
15
  var coreTracing = require('@azure/core-tracing');
@@ -692,6 +692,36 @@ function truncatedISO8061Date(date, withMilliseconds = true) {
692
692
  ? dateString.substring(0, dateString.length - 1) + "0000" + "Z"
693
693
  : dateString.substring(0, dateString.length - 5) + "Z";
694
694
  }
695
+ /**
696
+ * Delay specified time interval.
697
+ *
698
+ * @param timeInMs -
699
+ * @param aborter -
700
+ * @param abortError -
701
+ */
702
+ async function delay(timeInMs, aborter, abortError) {
703
+ return new Promise((resolve, reject) => {
704
+ /* eslint-disable-next-line prefer-const */
705
+ let timeout;
706
+ const abortHandler = () => {
707
+ if (timeout !== undefined) {
708
+ clearTimeout(timeout);
709
+ }
710
+ reject(abortError);
711
+ };
712
+ const resolveHandler = () => {
713
+ if (aborter !== undefined) {
714
+ aborter.removeEventListener("abort", abortHandler);
715
+ }
716
+ resolve();
717
+ };
718
+ /* eslint-disable-next-line prefer-const */
719
+ timeout = setTimeout(resolveHandler, timeInMs);
720
+ if (aborter !== undefined) {
721
+ aborter.addEventListener("abort", abortHandler);
722
+ }
723
+ });
724
+ }
695
725
  /**
696
726
  * Extracts account name from the url
697
727
  * @param url - url to extract the account name from
@@ -1365,7 +1395,7 @@ function getCanonicalName(accountName, shareName, filePath) {
1365
1395
  /**
1366
1396
  * The `@azure/logger` configuration for this package.
1367
1397
  */
1368
- const logger$1 = logger$2.createClientLogger("storage-file-share");
1398
+ const logger = logger$1.createClientLogger("storage-file-share");
1369
1399
 
1370
1400
  // Copyright (c) Microsoft Corporation.
1371
1401
  // Licensed under the MIT license.
@@ -1407,165 +1437,6 @@ class BaseRequestPolicy {
1407
1437
  }
1408
1438
  }
1409
1439
 
1410
- // Copyright (c) Microsoft Corporation.
1411
- // Licensed under the MIT license.
1412
- const URLConstants = {
1413
- Parameters: {
1414
- FORCE_BROWSER_NO_CACHE: "_",
1415
- SIGNATURE: "sig",
1416
- SNAPSHOT: "snapshot",
1417
- VERSIONID: "versionid",
1418
- TIMEOUT: "timeout",
1419
- },
1420
- };
1421
- const HeaderConstants = {
1422
- AUTHORIZATION: "Authorization",
1423
- AUTHORIZATION_SCHEME: "Bearer",
1424
- CONTENT_ENCODING: "Content-Encoding",
1425
- CONTENT_ID: "Content-ID",
1426
- CONTENT_LANGUAGE: "Content-Language",
1427
- CONTENT_LENGTH: "Content-Length",
1428
- CONTENT_MD5: "Content-Md5",
1429
- CONTENT_TRANSFER_ENCODING: "Content-Transfer-Encoding",
1430
- CONTENT_TYPE: "Content-Type",
1431
- COOKIE: "Cookie",
1432
- DATE: "date",
1433
- IF_MATCH: "if-match",
1434
- IF_MODIFIED_SINCE: "if-modified-since",
1435
- IF_NONE_MATCH: "if-none-match",
1436
- IF_UNMODIFIED_SINCE: "if-unmodified-since",
1437
- PREFIX_FOR_STORAGE: "x-ms-",
1438
- RANGE: "Range",
1439
- USER_AGENT: "User-Agent",
1440
- X_MS_CLIENT_REQUEST_ID: "x-ms-client-request-id",
1441
- X_MS_COPY_SOURCE: "x-ms-copy-source",
1442
- X_MS_DATE: "x-ms-date",
1443
- X_MS_ERROR_CODE: "x-ms-error-code",
1444
- X_MS_VERSION: "x-ms-version",
1445
- };
1446
-
1447
- // Copyright (c) Microsoft Corporation.
1448
- // Licensed under the MIT license.
1449
- /**
1450
- * Set URL parameter name and value. If name exists in URL parameters, old value
1451
- * will be replaced by name key. If not provide value, the parameter will be deleted.
1452
- *
1453
- * @param url - Source URL string
1454
- * @param name - Parameter name
1455
- * @param value - Parameter value
1456
- * @returns An updated URL string
1457
- */
1458
- function setURLParameter(url, name, value) {
1459
- const urlParsed = new URL(url);
1460
- const encodedName = encodeURIComponent(name);
1461
- const encodedValue = value ? encodeURIComponent(value) : undefined;
1462
- // mutating searchParams will change the encoding, so we have to do this ourselves
1463
- const searchString = urlParsed.search === "" ? "?" : urlParsed.search;
1464
- const searchPieces = [];
1465
- for (const pair of searchString.slice(1).split("&")) {
1466
- if (pair) {
1467
- const [key] = pair.split("=", 2);
1468
- if (key !== encodedName) {
1469
- searchPieces.push(pair);
1470
- }
1471
- }
1472
- }
1473
- if (encodedValue) {
1474
- searchPieces.push(`${encodedName}=${encodedValue}`);
1475
- }
1476
- urlParsed.search = searchPieces.length ? `?${searchPieces.join("&")}` : "";
1477
- return urlParsed.toString();
1478
- }
1479
- /**
1480
- * Set URL host.
1481
- *
1482
- * @param url - Source URL string
1483
- * @param host - New host string
1484
- * @returns An updated URL string
1485
- */
1486
- function setURLHost(url, host) {
1487
- const urlParsed = new URL(url);
1488
- urlParsed.hostname = host;
1489
- return urlParsed.toString();
1490
- }
1491
- /**
1492
- * Get URL path from an URL string.
1493
- *
1494
- * @param url - Source URL string
1495
- */
1496
- function getURLPath(url) {
1497
- try {
1498
- const urlParsed = new URL(url);
1499
- return urlParsed.pathname;
1500
- }
1501
- catch (e) {
1502
- return undefined;
1503
- }
1504
- }
1505
- /**
1506
- * Get URL query key value pairs from an URL string.
1507
- *
1508
- * @param url -
1509
- */
1510
- function getURLQueries(url) {
1511
- let queryString = new URL(url).search;
1512
- if (!queryString) {
1513
- return {};
1514
- }
1515
- queryString = queryString.trim();
1516
- queryString = queryString.startsWith("?") ? queryString.substring(1) : queryString;
1517
- let querySubStrings = queryString.split("&");
1518
- querySubStrings = querySubStrings.filter((value) => {
1519
- const indexOfEqual = value.indexOf("=");
1520
- const lastIndexOfEqual = value.lastIndexOf("=");
1521
- return (indexOfEqual > 0 && indexOfEqual === lastIndexOfEqual && lastIndexOfEqual < value.length - 1);
1522
- });
1523
- const queries = {};
1524
- for (const querySubString of querySubStrings) {
1525
- const splitResults = querySubString.split("=");
1526
- const key = splitResults[0];
1527
- const value = splitResults[1];
1528
- queries[key] = value;
1529
- }
1530
- return queries;
1531
- }
1532
- /**
1533
- * Delay specified time interval.
1534
- *
1535
- * @param timeInMs -
1536
- * @param aborter -
1537
- * @param abortError -
1538
- */
1539
- async function delay(timeInMs, aborter, abortError) {
1540
- return new Promise((resolve, reject) => {
1541
- /* eslint-disable-next-line prefer-const */
1542
- let timeout;
1543
- const abortHandler = () => {
1544
- if (timeout !== undefined) {
1545
- clearTimeout(timeout);
1546
- }
1547
- reject(abortError);
1548
- };
1549
- const resolveHandler = () => {
1550
- if (aborter !== undefined) {
1551
- aborter.removeEventListener("abort", abortHandler);
1552
- }
1553
- resolve();
1554
- };
1555
- timeout = setTimeout(resolveHandler, timeInMs);
1556
- if (aborter !== undefined) {
1557
- aborter.addEventListener("abort", abortHandler);
1558
- }
1559
- });
1560
- }
1561
-
1562
- // Copyright (c) Microsoft Corporation.
1563
- // Licensed under the MIT license.
1564
- /**
1565
- * The `@azure/logger` configuration for this package.
1566
- */
1567
- const logger = logger$2.createClientLogger("storage-blob");
1568
-
1569
1440
  // Copyright (c) Microsoft Corporation.
1570
1441
  // Licensed under the MIT license.
1571
1442
  /**
@@ -1588,7 +1459,6 @@ const DEFAULT_RETRY_OPTIONS$1 = {
1588
1459
  maxTries: 4,
1589
1460
  retryDelayInMs: 4 * 1000,
1590
1461
  retryPolicyType: exports.StorageRetryPolicyType.EXPONENTIAL,
1591
- secondaryHost: "",
1592
1462
  tryTimeoutInMs: undefined, // Use server side default timeout strategy
1593
1463
  };
1594
1464
  const RETRY_ABORT_ERROR$1 = new abortController.AbortError("The operation was aborted.");
@@ -1624,9 +1494,6 @@ class StorageRetryPolicy extends BaseRequestPolicy {
1624
1494
  maxRetryDelayInMs: retryOptions.maxRetryDelayInMs && retryOptions.maxRetryDelayInMs >= 0
1625
1495
  ? retryOptions.maxRetryDelayInMs
1626
1496
  : DEFAULT_RETRY_OPTIONS$1.maxRetryDelayInMs,
1627
- secondaryHost: retryOptions.secondaryHost
1628
- ? retryOptions.secondaryHost
1629
- : DEFAULT_RETRY_OPTIONS$1.secondaryHost,
1630
1497
  };
1631
1498
  }
1632
1499
  /**
@@ -1649,16 +1516,10 @@ class StorageRetryPolicy extends BaseRequestPolicy {
1649
1516
  */
1650
1517
  async attemptSendRequest(request, secondaryHas404, attempt) {
1651
1518
  const newRequest = request.clone();
1652
- const isPrimaryRetry = secondaryHas404 ||
1653
- !this.retryOptions.secondaryHost ||
1654
- !(request.method === "GET" || request.method === "HEAD" || request.method === "OPTIONS") ||
1655
- attempt % 2 === 1;
1656
- if (!isPrimaryRetry) {
1657
- newRequest.url = setURLHost(newRequest.url, this.retryOptions.secondaryHost);
1658
- }
1519
+ const isPrimaryRetry = true;
1659
1520
  // Set the server-side timeout query parameter "timeout=[seconds]"
1660
1521
  if (this.retryOptions.tryTimeoutInMs) {
1661
- newRequest.url = setURLParameter(newRequest.url, URLConstants.Parameters.TIMEOUT, Math.floor(this.retryOptions.tryTimeoutInMs / 1000).toString());
1522
+ newRequest.url = setURLParameter$1(newRequest.url, URLConstants$1.Parameters.TIMEOUT, Math.floor(this.retryOptions.tryTimeoutInMs / 1000).toString());
1662
1523
  }
1663
1524
  let response;
1664
1525
  try {
@@ -1787,6 +1648,117 @@ class StorageRetryPolicyFactory {
1787
1648
  }
1788
1649
  }
1789
1650
 
1651
+ // Copyright (c) Microsoft Corporation.
1652
+ // Licensed under the MIT license.
1653
+ const URLConstants = {
1654
+ Parameters: {
1655
+ FORCE_BROWSER_NO_CACHE: "_",
1656
+ SIGNATURE: "sig",
1657
+ SNAPSHOT: "snapshot",
1658
+ VERSIONID: "versionid",
1659
+ TIMEOUT: "timeout",
1660
+ },
1661
+ };
1662
+ const HeaderConstants = {
1663
+ AUTHORIZATION: "Authorization",
1664
+ AUTHORIZATION_SCHEME: "Bearer",
1665
+ CONTENT_ENCODING: "Content-Encoding",
1666
+ CONTENT_ID: "Content-ID",
1667
+ CONTENT_LANGUAGE: "Content-Language",
1668
+ CONTENT_LENGTH: "Content-Length",
1669
+ CONTENT_MD5: "Content-Md5",
1670
+ CONTENT_TRANSFER_ENCODING: "Content-Transfer-Encoding",
1671
+ CONTENT_TYPE: "Content-Type",
1672
+ COOKIE: "Cookie",
1673
+ DATE: "date",
1674
+ IF_MATCH: "if-match",
1675
+ IF_MODIFIED_SINCE: "if-modified-since",
1676
+ IF_NONE_MATCH: "if-none-match",
1677
+ IF_UNMODIFIED_SINCE: "if-unmodified-since",
1678
+ PREFIX_FOR_STORAGE: "x-ms-",
1679
+ RANGE: "Range",
1680
+ USER_AGENT: "User-Agent",
1681
+ X_MS_CLIENT_REQUEST_ID: "x-ms-client-request-id",
1682
+ X_MS_COPY_SOURCE: "x-ms-copy-source",
1683
+ X_MS_DATE: "x-ms-date",
1684
+ X_MS_ERROR_CODE: "x-ms-error-code",
1685
+ X_MS_VERSION: "x-ms-version",
1686
+ };
1687
+
1688
+ // Copyright (c) Microsoft Corporation.
1689
+ // Licensed under the MIT license.
1690
+ /**
1691
+ * Set URL parameter name and value. If name exists in URL parameters, old value
1692
+ * will be replaced by name key. If not provide value, the parameter will be deleted.
1693
+ *
1694
+ * @param url - Source URL string
1695
+ * @param name - Parameter name
1696
+ * @param value - Parameter value
1697
+ * @returns An updated URL string
1698
+ */
1699
+ function setURLParameter(url, name, value) {
1700
+ const urlParsed = new URL(url);
1701
+ const encodedName = encodeURIComponent(name);
1702
+ const encodedValue = value ? encodeURIComponent(value) : undefined;
1703
+ // mutating searchParams will change the encoding, so we have to do this ourselves
1704
+ const searchString = urlParsed.search === "" ? "?" : urlParsed.search;
1705
+ const searchPieces = [];
1706
+ for (const pair of searchString.slice(1).split("&")) {
1707
+ if (pair) {
1708
+ const [key] = pair.split("=", 2);
1709
+ if (key !== encodedName) {
1710
+ searchPieces.push(pair);
1711
+ }
1712
+ }
1713
+ }
1714
+ if (encodedValue) {
1715
+ searchPieces.push(`${encodedName}=${encodedValue}`);
1716
+ }
1717
+ urlParsed.search = searchPieces.length ? `?${searchPieces.join("&")}` : "";
1718
+ return urlParsed.toString();
1719
+ }
1720
+ /**
1721
+ * Get URL path from an URL string.
1722
+ *
1723
+ * @param url - Source URL string
1724
+ */
1725
+ function getURLPath(url) {
1726
+ try {
1727
+ const urlParsed = new URL(url);
1728
+ return urlParsed.pathname;
1729
+ }
1730
+ catch (e) {
1731
+ return undefined;
1732
+ }
1733
+ }
1734
+ /**
1735
+ * Get URL query key value pairs from an URL string.
1736
+ *
1737
+ * @param url -
1738
+ */
1739
+ function getURLQueries(url) {
1740
+ let queryString = new URL(url).search;
1741
+ if (!queryString) {
1742
+ return {};
1743
+ }
1744
+ queryString = queryString.trim();
1745
+ queryString = queryString.startsWith("?") ? queryString.substring(1) : queryString;
1746
+ let querySubStrings = queryString.split("&");
1747
+ querySubStrings = querySubStrings.filter((value) => {
1748
+ const indexOfEqual = value.indexOf("=");
1749
+ const lastIndexOfEqual = value.lastIndexOf("=");
1750
+ return (indexOfEqual > 0 && indexOfEqual === lastIndexOfEqual && lastIndexOfEqual < value.length - 1);
1751
+ });
1752
+ const queries = {};
1753
+ for (const querySubString of querySubStrings) {
1754
+ const splitResults = querySubString.split("=");
1755
+ const key = splitResults[0];
1756
+ const value = splitResults[1];
1757
+ queries[key] = value;
1758
+ }
1759
+ return queries;
1760
+ }
1761
+
1790
1762
  // Copyright (c) Microsoft Corporation.
1791
1763
  // Licensed under the MIT license.
1792
1764
  /**
@@ -2129,13 +2101,12 @@ const RETRY_ABORT_ERROR = new abortController.AbortError("The operation was abor
2129
2101
  * Retry policy with exponential retry and linear retry implemented.
2130
2102
  */
2131
2103
  function storageRetryPolicy(options = {}) {
2132
- var _a, _b, _c, _d, _e, _f;
2104
+ var _a, _b, _c, _d, _e;
2133
2105
  const retryPolicyType = (_a = options.retryPolicyType) !== null && _a !== void 0 ? _a : DEFAULT_RETRY_OPTIONS.retryPolicyType;
2134
2106
  const maxTries = (_b = options.maxTries) !== null && _b !== void 0 ? _b : DEFAULT_RETRY_OPTIONS.maxTries;
2135
2107
  const retryDelayInMs = (_c = options.retryDelayInMs) !== null && _c !== void 0 ? _c : DEFAULT_RETRY_OPTIONS.retryDelayInMs;
2136
2108
  const maxRetryDelayInMs = (_d = options.maxRetryDelayInMs) !== null && _d !== void 0 ? _d : DEFAULT_RETRY_OPTIONS.maxRetryDelayInMs;
2137
- const secondaryHost = (_e = options.secondaryHost) !== null && _e !== void 0 ? _e : DEFAULT_RETRY_OPTIONS.secondaryHost;
2138
- const tryTimeoutInMs = (_f = options.tryTimeoutInMs) !== null && _f !== void 0 ? _f : DEFAULT_RETRY_OPTIONS.tryTimeoutInMs;
2109
+ const tryTimeoutInMs = (_e = options.tryTimeoutInMs) !== null && _e !== void 0 ? _e : DEFAULT_RETRY_OPTIONS.tryTimeoutInMs;
2139
2110
  function shouldRetry({ isPrimaryRetry, attempt, response, error, }) {
2140
2111
  var _a, _b;
2141
2112
  if (attempt >= maxTries) {
@@ -2176,7 +2147,7 @@ function storageRetryPolicy(options = {}) {
2176
2147
  }
2177
2148
  function calculateDelay(isPrimaryRetry, attempt) {
2178
2149
  let delayTimeInMs = 0;
2179
- if (isPrimaryRetry) {
2150
+ {
2180
2151
  switch (retryPolicyType) {
2181
2152
  case StorageRetryPolicyType.EXPONENTIAL:
2182
2153
  delayTimeInMs = Math.min((Math.pow(2, attempt - 1) - 1) * retryDelayInMs, maxRetryDelayInMs);
@@ -2186,9 +2157,6 @@ function storageRetryPolicy(options = {}) {
2186
2157
  break;
2187
2158
  }
2188
2159
  }
2189
- else {
2190
- delayTimeInMs = Math.random() * 1000;
2191
- }
2192
2160
  logger.info(`RetryPolicy: Delay for ${delayTimeInMs}ms`);
2193
2161
  return delayTimeInMs;
2194
2162
  }
@@ -2197,21 +2165,17 @@ function storageRetryPolicy(options = {}) {
2197
2165
  async sendRequest(request, next) {
2198
2166
  // Set the server-side timeout query parameter "timeout=[seconds]"
2199
2167
  if (tryTimeoutInMs) {
2200
- request.url = setURLParameter(request.url, URLConstants.Parameters.TIMEOUT, String(Math.floor(tryTimeoutInMs / 1000)));
2168
+ request.url = setURLParameter$1(request.url, URLConstants$1.Parameters.TIMEOUT, String(Math.floor(tryTimeoutInMs / 1000)));
2201
2169
  }
2202
2170
  const primaryUrl = request.url;
2203
- const secondaryUrl = secondaryHost ? setURLHost(request.url, secondaryHost) : undefined;
2204
2171
  let secondaryHas404 = false;
2205
2172
  let attempt = 1;
2206
2173
  let retryAgain = true;
2207
2174
  let response;
2208
2175
  let error;
2209
2176
  while (retryAgain) {
2210
- const isPrimaryRetry = secondaryHas404 ||
2211
- !secondaryUrl ||
2212
- !["GET", "HEAD", "OPTIONS"].includes(request.method) ||
2213
- attempt % 2 === 1;
2214
- request.url = isPrimaryRetry ? primaryUrl : secondaryUrl;
2177
+ const isPrimaryRetry = true;
2178
+ request.url = primaryUrl;
2215
2179
  response = undefined;
2216
2180
  error = undefined;
2217
2181
  try {
@@ -2536,7 +2500,7 @@ function getCoreClientOptions(pipeline) {
2536
2500
  corePipeline = coreClient.createClientPipeline(Object.assign(Object.assign({}, restOptions), { loggingOptions: {
2537
2501
  additionalAllowedHeaderNames: StorageFileLoggingAllowedHeaderNames,
2538
2502
  additionalAllowedQueryParameters: StorageFileLoggingAllowedQueryParameters,
2539
- logger: logger$1.info,
2503
+ logger: logger.info,
2540
2504
  }, userAgentOptions: {
2541
2505
  userAgentPrefix,
2542
2506
  }, serializationOptions: {
@@ -11812,7 +11776,7 @@ function toShareProtocolsString(protocols = {}) {
11812
11776
  protocolStr = "SMB";
11813
11777
  }
11814
11778
  if (protocols.nfsEnabled === true) {
11815
- logger$1.info(`Using "NFS" in favor of "SMB" for the share protocol as currently they can't be supported at the same time.`);
11779
+ logger.info(`Using "NFS" in favor of "SMB" for the share protocol as currently they can't be supported at the same time.`);
11816
11780
  protocolStr = "NFS";
11817
11781
  }
11818
11782
  return protocolStr;
@@ -15288,6 +15252,6 @@ exports.generateAccountSASQueryParameters = generateAccountSASQueryParameters;
15288
15252
  exports.generateFileSASQueryParameters = generateFileSASQueryParameters;
15289
15253
  exports.getFileServiceAccountAudience = getFileServiceAccountAudience;
15290
15254
  exports.isPipelineLike = isPipelineLike;
15291
- exports.logger = logger$1;
15255
+ exports.logger = logger;
15292
15256
  exports.newPipeline = newPipeline;
15293
15257
  //# sourceMappingURL=index.js.map