@microsoft/teamsfx 0.6.3-alpha.ffd3f8bc7.0 → 0.6.3-beta.016f72ed1.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.
@@ -132,6 +132,8 @@ ErrorMessage.BasicCredentialAlreadyExists = "Basic credential already exists!";
132
132
  // InvalidParameter Error
133
133
  ErrorMessage.EmptyParameter = "Parameter {0} is empty";
134
134
  ErrorMessage.DuplicateHttpsOptionProperty = "Axios HTTPS agent already defined value for property {0}";
135
+ ErrorMessage.DuplicateApiKeyInHeader = "The request already defined api key in request header with name {0}.";
136
+ ErrorMessage.DuplicateApiKeyInQueryParam = "The request already defined api key in query parameter with name {0}.";
135
137
  /**
136
138
  * Error class with code and message thrown by the SDK.
137
139
  *
@@ -1487,7 +1489,7 @@ function createApiClient(apiEndpoint, authProvider) {
1487
1489
  */
1488
1490
  class BearerTokenAuthProvider {
1489
1491
  /**
1490
- * @param getToken Function that returns the content of bearer token used in http request
1492
+ * @param { () => Promise<string> } getToken - Function that returns the content of bearer token used in http request
1491
1493
  *
1492
1494
  * @beta
1493
1495
  */
@@ -1497,7 +1499,7 @@ class BearerTokenAuthProvider {
1497
1499
  /**
1498
1500
  * Adds authentication info to http requests
1499
1501
  *
1500
- * @param config - Contains all the request information and can be updated to include extra authentication info.
1502
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
1501
1503
  * Refer https://axios-http.com/docs/req_config for detailed document.
1502
1504
  *
1503
1505
  * @returns Updated axios request config.
@@ -1530,8 +1532,11 @@ class BearerTokenAuthProvider {
1530
1532
  class BasicAuthProvider {
1531
1533
  /**
1532
1534
  *
1533
- * @param userName - Username used in basic auth
1534
- * @param password - Password used in basic auth
1535
+ * @param { string } userName - Username used in basic auth
1536
+ * @param { string } password - Password used in basic auth
1537
+ *
1538
+ * @throws {@link ErrorCode|InvalidParameter} - when username or password is empty.
1539
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1535
1540
  *
1536
1541
  * @beta
1537
1542
  */
@@ -1548,12 +1553,13 @@ class BasicAuthProvider {
1548
1553
  /**
1549
1554
  * Adds authentication info to http requests
1550
1555
  *
1551
- * @param config - Contains all the request information and can be updated to include extra authentication info.
1556
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
1552
1557
  * Refer https://axios-http.com/docs/req_config for detailed document.
1553
1558
  *
1554
1559
  * @returns Updated axios request config.
1555
1560
  *
1556
1561
  * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header or auth property already exists in request configuration.
1562
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1557
1563
  *
1558
1564
  * @beta
1559
1565
  */
@@ -1574,6 +1580,92 @@ class BasicAuthProvider {
1574
1580
  }
1575
1581
  }
1576
1582
 
1583
+ // Copyright (c) Microsoft Corporation.
1584
+ /**
1585
+ * Provider that handles API Key authentication
1586
+ *
1587
+ * @beta
1588
+ */
1589
+ class ApiKeyProvider {
1590
+ /**
1591
+ *
1592
+ * @param { string } keyName - The name of request header or query parameter that specifies API Key
1593
+ * @param { string } keyValue - The value of API Key
1594
+ * @param { ApiKeyLocation } keyLocation - The location of API Key: request header or query parameter.
1595
+ *
1596
+ * @throws {@link ErrorCode|InvalidParameter} - when key name or key value is empty.
1597
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1598
+ *
1599
+ * @beta
1600
+ */
1601
+ constructor(keyName, keyValue, keyLocation) {
1602
+ if (!keyName) {
1603
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "keyName"), exports.ErrorCode.InvalidParameter);
1604
+ }
1605
+ if (!keyValue) {
1606
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "keyVaule"), exports.ErrorCode.InvalidParameter);
1607
+ }
1608
+ this.keyName = keyName;
1609
+ this.keyValue = keyValue;
1610
+ this.keyLocation = keyLocation;
1611
+ }
1612
+ /**
1613
+ * Adds authentication info to http requests
1614
+ *
1615
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
1616
+ * Refer https://axios-http.com/docs/req_config for detailed document.
1617
+ *
1618
+ * @returns Updated axios request config.
1619
+ *
1620
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when API key already exists in request header or url query parameter.
1621
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1622
+ *
1623
+ * @beta
1624
+ */
1625
+ AddAuthenticationInfo(config) {
1626
+ return tslib.__awaiter(this, void 0, void 0, function* () {
1627
+ switch (this.keyLocation) {
1628
+ case exports.ApiKeyLocation.Header:
1629
+ if (!config.headers) {
1630
+ config.headers = {};
1631
+ }
1632
+ if (config.headers[this.keyName]) {
1633
+ throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInHeader, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists);
1634
+ }
1635
+ config.headers[this.keyName] = this.keyValue;
1636
+ break;
1637
+ case exports.ApiKeyLocation.QueryParams:
1638
+ if (!config.params) {
1639
+ config.params = {};
1640
+ }
1641
+ const url = new URL(config.url, config.baseURL);
1642
+ if (config.params[this.keyName] || url.searchParams.has(this.keyName)) {
1643
+ throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInQueryParam, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists);
1644
+ }
1645
+ config.params[this.keyName] = this.keyValue;
1646
+ break;
1647
+ }
1648
+ return config;
1649
+ });
1650
+ }
1651
+ }
1652
+ /**
1653
+ * Define available location for API Key location
1654
+ *
1655
+ * @beta
1656
+ */
1657
+ exports.ApiKeyLocation = void 0;
1658
+ (function (ApiKeyLocation) {
1659
+ /**
1660
+ * The API Key is placed in request header
1661
+ */
1662
+ ApiKeyLocation[ApiKeyLocation["Header"] = 0] = "Header";
1663
+ /**
1664
+ * The API Key is placed in query parameter
1665
+ */
1666
+ ApiKeyLocation[ApiKeyLocation["QueryParams"] = 1] = "QueryParams";
1667
+ })(exports.ApiKeyLocation || (exports.ApiKeyLocation = {}));
1668
+
1577
1669
  // Copyright (c) Microsoft Corporation.
1578
1670
  /**
1579
1671
  * Provider that handles Certificate authentication
@@ -1585,6 +1677,8 @@ class CertificateAuthProvider {
1585
1677
  *
1586
1678
  * @param { SecureContextOptions } certOption - information about the cert used in http requests
1587
1679
  *
1680
+ * @throws {@link ErrorCode|InvalidParameter} - when cert option is empty.
1681
+ *
1588
1682
  * @beta
1589
1683
  */
1590
1684
  constructor(certOption) {
@@ -1630,15 +1724,14 @@ class CertificateAuthProvider {
1630
1724
  *
1631
1725
  * @param { string | Buffer } cert - The cert chain in PEM format
1632
1726
  * @param { string | Buffer } key - The private key for the cert chain
1633
- * @param { string? } passphrase - The passphrase for private key
1634
- * @param { string? | Buffer? } ca - Overrides the trusted CA certificates
1727
+ * @param { {passphrase?: string; ca?: string | Buffer} } options - Optional settings when create the cert options.
1635
1728
  *
1636
1729
  * @returns Instance of SecureContextOptions
1637
1730
  *
1638
1731
  * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1639
1732
  *
1640
1733
  */
1641
- function createPemCertOption(cert, key, passphrase, ca) {
1734
+ function createPemCertOption(cert, key, options) {
1642
1735
  if (cert.length === 0) {
1643
1736
  throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "cert"), exports.ErrorCode.InvalidParameter);
1644
1737
  }
@@ -1648,28 +1741,28 @@ function createPemCertOption(cert, key, passphrase, ca) {
1648
1741
  return {
1649
1742
  cert,
1650
1743
  key,
1651
- passphrase,
1652
- ca,
1744
+ passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
1745
+ ca: options === null || options === void 0 ? void 0 : options.ca,
1653
1746
  };
1654
1747
  }
1655
1748
  /**
1656
1749
  * Helper to create SecureContextOptions from PFX format cert
1657
1750
  *
1658
1751
  * @param { string | Buffer } pfx - The content of .pfx file
1659
- * @param { string? } passphrase - Optional. The passphrase of .pfx file
1752
+ * @param { {passphrase?: string} } options - Optional settings when create the cert options.
1660
1753
  *
1661
1754
  * @returns Instance of SecureContextOptions
1662
1755
  *
1663
1756
  * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1664
1757
  *
1665
1758
  */
1666
- function createPfxCertOption(pfx, passphrase) {
1759
+ function createPfxCertOption(pfx, options) {
1667
1760
  if (pfx.length === 0) {
1668
1761
  throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "pfx"), exports.ErrorCode.InvalidParameter);
1669
1762
  }
1670
1763
  return {
1671
1764
  pfx,
1672
- passphrase,
1765
+ passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
1673
1766
  };
1674
1767
  }
1675
1768
 
@@ -2873,6 +2966,7 @@ class MessageBuilder {
2873
2966
  }
2874
2967
  }
2875
2968
 
2969
+ exports.ApiKeyProvider = ApiKeyProvider;
2876
2970
  exports.AppCredential = AppCredential;
2877
2971
  exports.BasicAuthProvider = BasicAuthProvider;
2878
2972
  exports.BearerTokenAuthProvider = BearerTokenAuthProvider;