@microsoft/teamsfx 0.6.3-alpha.633d9d21e.0 → 0.6.3-alpha.6b8bcebfe.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.
@@ -101,6 +101,10 @@ exports.ErrorCode = void 0;
101
101
  * Identity type error.
102
102
  */
103
103
  ErrorCode["IdentityTypeNotSupported"] = "IdentityTypeNotSupported";
104
+ /**
105
+ * Authentication info already exists error.
106
+ */
107
+ ErrorCode["AuthorizationInfoAlreadyExists"] = "AuthorizationInfoAlreadyExists";
104
108
  })(exports.ErrorCode || (exports.ErrorCode = {}));
105
109
  /**
106
110
  * @internal
@@ -122,9 +126,14 @@ ErrorMessage.FailToAcquireTokenOnBehalfOfUser = "Failed to acquire access token
122
126
  ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
123
127
  // IdentityTypeNotSupported Error
124
128
  ErrorMessage.IdentityTypeNotSupported = "{0} identity is not supported in {1}";
129
+ // AuthorizationInfoError
130
+ ErrorMessage.AuthorizationHeaderAlreadyExists = "Authorization header already exists!";
131
+ ErrorMessage.BasicCredentialAlreadyExists = "Basic credential already exists!";
125
132
  // InvalidParameter Error
126
133
  ErrorMessage.EmptyParameter = "Parameter {0} is empty";
127
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}.";
128
137
  /**
129
138
  * Error class with code and message thrown by the SDK.
130
139
  *
@@ -1480,7 +1489,7 @@ function createApiClient(apiEndpoint, authProvider) {
1480
1489
  */
1481
1490
  class BearerTokenAuthProvider {
1482
1491
  /**
1483
- * @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
1484
1493
  *
1485
1494
  * @beta
1486
1495
  */
@@ -1490,9 +1499,13 @@ class BearerTokenAuthProvider {
1490
1499
  /**
1491
1500
  * Adds authentication info to http requests
1492
1501
  *
1493
- * @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.
1494
1503
  * Refer https://axios-http.com/docs/req_config for detailed document.
1495
1504
  *
1505
+ * @returns Updated axios request config.
1506
+ *
1507
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header already exists in request configuration.
1508
+ *
1496
1509
  * @beta
1497
1510
  */
1498
1511
  AddAuthenticationInfo(config) {
@@ -1502,7 +1515,7 @@ class BearerTokenAuthProvider {
1502
1515
  config.headers = {};
1503
1516
  }
1504
1517
  if (config.headers["Authorization"]) {
1505
- throw new Error("Authorization header already exists!");
1518
+ throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1506
1519
  }
1507
1520
  config.headers["Authorization"] = `Bearer ${token}`;
1508
1521
  return config;
@@ -1510,6 +1523,149 @@ class BearerTokenAuthProvider {
1510
1523
  }
1511
1524
  }
1512
1525
 
1526
+ // Copyright (c) Microsoft Corporation.
1527
+ /**
1528
+ * Provider that handles Basic authentication
1529
+ *
1530
+ * @beta
1531
+ */
1532
+ class BasicAuthProvider {
1533
+ /**
1534
+ *
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.
1540
+ *
1541
+ * @beta
1542
+ */
1543
+ constructor(userName, password) {
1544
+ if (!userName) {
1545
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "username"), exports.ErrorCode.InvalidParameter);
1546
+ }
1547
+ if (!password) {
1548
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "password"), exports.ErrorCode.InvalidParameter);
1549
+ }
1550
+ this.userName = userName;
1551
+ this.password = password;
1552
+ }
1553
+ /**
1554
+ * Adds authentication info to http requests
1555
+ *
1556
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
1557
+ * Refer https://axios-http.com/docs/req_config for detailed document.
1558
+ *
1559
+ * @returns Updated axios request config.
1560
+ *
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.
1563
+ *
1564
+ * @beta
1565
+ */
1566
+ AddAuthenticationInfo(config) {
1567
+ return tslib.__awaiter(this, void 0, void 0, function* () {
1568
+ if (config.headers && config.headers["Authorization"]) {
1569
+ throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1570
+ }
1571
+ if (config.auth) {
1572
+ throw new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1573
+ }
1574
+ config.auth = {
1575
+ username: this.userName,
1576
+ password: this.password,
1577
+ };
1578
+ return config;
1579
+ });
1580
+ }
1581
+ }
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
+
1513
1669
  // Copyright (c) Microsoft Corporation.
1514
1670
  /**
1515
1671
  * Provider that handles Certificate authentication
@@ -1521,6 +1677,8 @@ class CertificateAuthProvider {
1521
1677
  *
1522
1678
  * @param { SecureContextOptions } certOption - information about the cert used in http requests
1523
1679
  *
1680
+ * @throws {@link ErrorCode|InvalidParameter} - when cert option is empty.
1681
+ *
1524
1682
  * @beta
1525
1683
  */
1526
1684
  constructor(certOption) {
@@ -1566,15 +1724,14 @@ class CertificateAuthProvider {
1566
1724
  *
1567
1725
  * @param { string | Buffer } cert - The cert chain in PEM format
1568
1726
  * @param { string | Buffer } key - The private key for the cert chain
1569
- * @param { string? } passphrase - The passphrase for private key
1570
- * @param { string? | Buffer? } ca - Overrides the trusted CA certificates
1727
+ * @param { {passphrase?: string; ca?: string | Buffer} } options - Optional settings when create the cert options.
1571
1728
  *
1572
1729
  * @returns Instance of SecureContextOptions
1573
1730
  *
1574
1731
  * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1575
1732
  *
1576
1733
  */
1577
- function createPemCertOption(cert, key, passphrase, ca) {
1734
+ function createPemCertOption(cert, key, options) {
1578
1735
  if (cert.length === 0) {
1579
1736
  throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "cert"), exports.ErrorCode.InvalidParameter);
1580
1737
  }
@@ -1584,32 +1741,48 @@ function createPemCertOption(cert, key, passphrase, ca) {
1584
1741
  return {
1585
1742
  cert,
1586
1743
  key,
1587
- passphrase,
1588
- ca,
1744
+ passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
1745
+ ca: options === null || options === void 0 ? void 0 : options.ca,
1589
1746
  };
1590
1747
  }
1591
1748
  /**
1592
1749
  * Helper to create SecureContextOptions from PFX format cert
1593
1750
  *
1594
1751
  * @param { string | Buffer } pfx - The content of .pfx file
1595
- * @param { string? } passphrase - Optional. The passphrase of .pfx file
1752
+ * @param { {passphrase?: string} } options - Optional settings when create the cert options.
1596
1753
  *
1597
1754
  * @returns Instance of SecureContextOptions
1598
1755
  *
1599
1756
  * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1600
1757
  *
1601
1758
  */
1602
- function createPfxCertOption(pfx, passphrase) {
1759
+ function createPfxCertOption(pfx, options) {
1603
1760
  if (pfx.length === 0) {
1604
1761
  throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "pfx"), exports.ErrorCode.InvalidParameter);
1605
1762
  }
1606
1763
  return {
1607
1764
  pfx,
1608
- passphrase,
1765
+ passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
1609
1766
  };
1610
1767
  }
1611
1768
 
1612
1769
  // Copyright (c) Microsoft Corporation.
1770
+ // Following keys are used by SDK internally
1771
+ const ReservedKey = new Set([
1772
+ "authorityHost",
1773
+ "tenantId",
1774
+ "clientId",
1775
+ "clientSecret",
1776
+ "initiateLoginEndpoint",
1777
+ "applicationIdUri",
1778
+ "apiEndpoint",
1779
+ "apiName",
1780
+ "sqlServerEndpoint",
1781
+ "sqlUsername",
1782
+ "sqlPassword",
1783
+ "sqlDatabaseName",
1784
+ "sqlIdentityId",
1785
+ ]);
1613
1786
  /**
1614
1787
  * A class providing credential and configuration.
1615
1788
  * @beta
@@ -1787,10 +1960,10 @@ class TeamsFx {
1787
1960
  this.configuration.set("sqlDatabaseName", env.SQL_DATABASE_NAME);
1788
1961
  this.configuration.set("sqlIdentityId", env.IDENTITY_ID);
1789
1962
  Object.keys(env).forEach((key) => {
1790
- const value = env[key];
1791
- if (key.startsWith("TEAMSFX_") && value) {
1792
- this.configuration.set(key.substring(8), value);
1963
+ if (ReservedKey.has(key)) {
1964
+ internalLogger.warn(`The name of environment variable ${key} is preserved. Will not load it as configuration.`);
1793
1965
  }
1966
+ this.configuration.set(key, env[key]);
1794
1967
  });
1795
1968
  }
1796
1969
  }
@@ -1825,13 +1998,6 @@ class NotificationMiddleware {
1825
1998
  yield this.conversationReferenceStore.set(reference);
1826
1999
  break;
1827
2000
  }
1828
- case ActivityType.CurrentBotMessaged: {
1829
- const reference = botbuilder.TurnContext.getConversationReference(context.activity);
1830
- if (!(yield this.conversationReferenceStore.check(reference))) {
1831
- yield this.conversationReferenceStore.set(reference);
1832
- }
1833
- break;
1834
- }
1835
2001
  case ActivityType.CurrentBotUninstalled:
1836
2002
  case ActivityType.TeamDeleted: {
1837
2003
  const reference = botbuilder.TurnContext.getConversationReference(context.activity);
@@ -1854,9 +2020,6 @@ class NotificationMiddleware {
1854
2020
  return ActivityType.CurrentBotUninstalled;
1855
2021
  }
1856
2022
  }
1857
- else if (activityType === "message") {
1858
- return ActivityType.CurrentBotMessaged;
1859
- }
1860
2023
  else if (activityType === "conversationUpdate") {
1861
2024
  const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
1862
2025
  if (eventType === "teamDeleted") {
@@ -2659,8 +2822,8 @@ class MessageBuilder {
2659
2822
  /**
2660
2823
  * Build a bot message activity attached with adaptive card.
2661
2824
  *
2662
- * @param getCardData Function to prepare your card data.
2663
2825
  * @param cardTemplate The adaptive card template.
2826
+ * @param data card data used to render the template.
2664
2827
  * @returns A bot message activity attached with an adaptive card.
2665
2828
  *
2666
2829
  * @example
@@ -2685,19 +2848,18 @@ class MessageBuilder {
2685
2848
  * title: string,
2686
2849
  * description: string
2687
2850
  * };
2688
- * const card = MessageBuilder.attachAdaptiveCard<CardData>(() => {
2689
- * return {
2690
- * title: "sample card title",
2691
- * description: "sample card description"
2692
- * }}, cardTemplate);
2851
+ * const card = MessageBuilder.attachAdaptiveCard<CardData>(
2852
+ * cardTemplate, {
2853
+ * title: "sample card title",
2854
+ * description: "sample card description"
2855
+ * });
2693
2856
  * ```
2694
2857
  *
2695
2858
  * @beta
2696
2859
  */
2697
- static attachAdaptiveCard(getCardData, cardTemplate) {
2698
- const cardData = getCardData();
2860
+ static attachAdaptiveCard(cardTemplate, data) {
2699
2861
  return {
2700
- attachments: [botbuilder.CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(cardData))],
2862
+ attachments: [botbuilder.CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(data))],
2701
2863
  };
2702
2864
  }
2703
2865
  /**
@@ -2804,7 +2966,9 @@ class MessageBuilder {
2804
2966
  }
2805
2967
  }
2806
2968
 
2969
+ exports.ApiKeyProvider = ApiKeyProvider;
2807
2970
  exports.AppCredential = AppCredential;
2971
+ exports.BasicAuthProvider = BasicAuthProvider;
2808
2972
  exports.BearerTokenAuthProvider = BearerTokenAuthProvider;
2809
2973
  exports.CertificateAuthProvider = CertificateAuthProvider;
2810
2974
  exports.Channel = Channel;