@microsoft/teamsfx 0.6.3-alpha.81c48cbfc.0 → 0.6.3-alpha.f018de6e6.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,6 +126,9 @@ 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}";
@@ -1493,6 +1500,10 @@ class BearerTokenAuthProvider {
1493
1500
  * @param config - Contains all the request information and can be updated to include extra authentication info.
1494
1501
  * Refer https://axios-http.com/docs/req_config for detailed document.
1495
1502
  *
1503
+ * @returns Updated axios request config.
1504
+ *
1505
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header already exists in request configuration.
1506
+ *
1496
1507
  * @beta
1497
1508
  */
1498
1509
  AddAuthenticationInfo(config) {
@@ -1502,7 +1513,7 @@ class BearerTokenAuthProvider {
1502
1513
  config.headers = {};
1503
1514
  }
1504
1515
  if (config.headers["Authorization"]) {
1505
- throw new Error("Authorization header already exists!");
1516
+ throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1506
1517
  }
1507
1518
  config.headers["Authorization"] = `Bearer ${token}`;
1508
1519
  return config;
@@ -1510,6 +1521,59 @@ class BearerTokenAuthProvider {
1510
1521
  }
1511
1522
  }
1512
1523
 
1524
+ // Copyright (c) Microsoft Corporation.
1525
+ /**
1526
+ * Provider that handles Basic authentication
1527
+ *
1528
+ * @beta
1529
+ */
1530
+ class BasicAuthProvider {
1531
+ /**
1532
+ *
1533
+ * @param userName - Username used in basic auth
1534
+ * @param password - Password used in basic auth
1535
+ *
1536
+ * @beta
1537
+ */
1538
+ constructor(userName, password) {
1539
+ if (!userName) {
1540
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "username"), exports.ErrorCode.InvalidParameter);
1541
+ }
1542
+ if (!password) {
1543
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "password"), exports.ErrorCode.InvalidParameter);
1544
+ }
1545
+ this.userName = userName;
1546
+ this.password = password;
1547
+ }
1548
+ /**
1549
+ * Adds authentication info to http requests
1550
+ *
1551
+ * @param config - Contains all the request information and can be updated to include extra authentication info.
1552
+ * Refer https://axios-http.com/docs/req_config for detailed document.
1553
+ *
1554
+ * @returns Updated axios request config.
1555
+ *
1556
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header or auth property already exists in request configuration.
1557
+ *
1558
+ * @beta
1559
+ */
1560
+ AddAuthenticationInfo(config) {
1561
+ return tslib.__awaiter(this, void 0, void 0, function* () {
1562
+ if (config.headers && config.headers["Authorization"]) {
1563
+ throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1564
+ }
1565
+ if (config.auth) {
1566
+ throw new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1567
+ }
1568
+ config.auth = {
1569
+ username: this.userName,
1570
+ password: this.password,
1571
+ };
1572
+ return config;
1573
+ });
1574
+ }
1575
+ }
1576
+
1513
1577
  // Copyright (c) Microsoft Corporation.
1514
1578
  /**
1515
1579
  * Provider that handles Certificate authentication
@@ -2659,8 +2723,8 @@ class MessageBuilder {
2659
2723
  /**
2660
2724
  * Build a bot message activity attached with adaptive card.
2661
2725
  *
2662
- * @param getCardData Function to prepare your card data.
2663
2726
  * @param cardTemplate The adaptive card template.
2727
+ * @param data card data used to render the template.
2664
2728
  * @returns A bot message activity attached with an adaptive card.
2665
2729
  *
2666
2730
  * @example
@@ -2685,19 +2749,18 @@ class MessageBuilder {
2685
2749
  * title: string,
2686
2750
  * description: string
2687
2751
  * };
2688
- * const card = MessageBuilder.attachAdaptiveCard<CardData>(() => {
2689
- * return {
2690
- * title: "sample card title",
2691
- * description: "sample card description"
2692
- * }}, cardTemplate);
2752
+ * const card = MessageBuilder.attachAdaptiveCard<CardData>(
2753
+ * cardTemplate, {
2754
+ * title: "sample card title",
2755
+ * description: "sample card description"
2756
+ * });
2693
2757
  * ```
2694
2758
  *
2695
2759
  * @beta
2696
2760
  */
2697
- static attachAdaptiveCard(getCardData, cardTemplate) {
2698
- const cardData = getCardData();
2761
+ static attachAdaptiveCard(cardTemplate, data) {
2699
2762
  return {
2700
- attachments: [botbuilder.CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(cardData))],
2763
+ attachments: [botbuilder.CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(data))],
2701
2764
  };
2702
2765
  }
2703
2766
  /**
@@ -2805,6 +2868,7 @@ class MessageBuilder {
2805
2868
  }
2806
2869
 
2807
2870
  exports.AppCredential = AppCredential;
2871
+ exports.BasicAuthProvider = BasicAuthProvider;
2808
2872
  exports.BearerTokenAuthProvider = BearerTokenAuthProvider;
2809
2873
  exports.CertificateAuthProvider = CertificateAuthProvider;
2810
2874
  exports.Channel = Channel;