@microsoft/teamsfx 0.6.3-alpha.768a76f6e.0 → 0.6.3-alpha.8178ded9d.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.
@@ -12,6 +12,7 @@ var botbuilder = require('botbuilder');
12
12
  var botbuilderDialogs = require('botbuilder-dialogs');
13
13
  var uuid = require('uuid');
14
14
  var axios = require('axios');
15
+ var https = require('https');
15
16
  var path = require('path');
16
17
  var fs = require('fs');
17
18
 
@@ -100,6 +101,10 @@ exports.ErrorCode = void 0;
100
101
  * Identity type error.
101
102
  */
102
103
  ErrorCode["IdentityTypeNotSupported"] = "IdentityTypeNotSupported";
104
+ /**
105
+ * Authentication info already exists error.
106
+ */
107
+ ErrorCode["AuthorizationInfoAlreadyExists"] = "AuthorizationInfoAlreadyExists";
103
108
  })(exports.ErrorCode || (exports.ErrorCode = {}));
104
109
  /**
105
110
  * @internal
@@ -121,6 +126,14 @@ ErrorMessage.FailToAcquireTokenOnBehalfOfUser = "Failed to acquire access token
121
126
  ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
122
127
  // IdentityTypeNotSupported Error
123
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!";
132
+ // InvalidParameter Error
133
+ ErrorMessage.EmptyParameter = "Parameter {0} is empty";
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}.";
124
137
  /**
125
138
  * Error class with code and message thrown by the SDK.
126
139
  *
@@ -1476,7 +1489,7 @@ function createApiClient(apiEndpoint, authProvider) {
1476
1489
  */
1477
1490
  class BearerTokenAuthProvider {
1478
1491
  /**
1479
- * @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
1480
1493
  *
1481
1494
  * @beta
1482
1495
  */
@@ -1486,9 +1499,13 @@ class BearerTokenAuthProvider {
1486
1499
  /**
1487
1500
  * Adds authentication info to http requests
1488
1501
  *
1489
- * @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.
1490
1503
  * Refer https://axios-http.com/docs/req_config for detailed document.
1491
1504
  *
1505
+ * @returns Updated axios request config.
1506
+ *
1507
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header already exists in request configuration.
1508
+ *
1492
1509
  * @beta
1493
1510
  */
1494
1511
  AddAuthenticationInfo(config) {
@@ -1498,7 +1515,7 @@ class BearerTokenAuthProvider {
1498
1515
  config.headers = {};
1499
1516
  }
1500
1517
  if (config.headers["Authorization"]) {
1501
- throw new Error("Authorization header already exists!");
1518
+ throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1502
1519
  }
1503
1520
  config.headers["Authorization"] = `Bearer ${token}`;
1504
1521
  return config;
@@ -1507,6 +1524,265 @@ class BearerTokenAuthProvider {
1507
1524
  }
1508
1525
 
1509
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
+
1669
+ // Copyright (c) Microsoft Corporation.
1670
+ /**
1671
+ * Provider that handles Certificate authentication
1672
+ *
1673
+ * @beta
1674
+ */
1675
+ class CertificateAuthProvider {
1676
+ /**
1677
+ *
1678
+ * @param { SecureContextOptions } certOption - information about the cert used in http requests
1679
+ *
1680
+ * @throws {@link ErrorCode|InvalidParameter} - when cert option is empty.
1681
+ *
1682
+ * @beta
1683
+ */
1684
+ constructor(certOption) {
1685
+ if (certOption && Object.keys(certOption).length !== 0) {
1686
+ this.certOption = certOption;
1687
+ }
1688
+ else {
1689
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "certOption"), exports.ErrorCode.InvalidParameter);
1690
+ }
1691
+ }
1692
+ /**
1693
+ * Adds authentication info to http requests.
1694
+ *
1695
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
1696
+ * Refer https://axios-http.com/docs/req_config for detailed document.
1697
+ *
1698
+ * @returns Updated axios request config.
1699
+ *
1700
+ * @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
1701
+ *
1702
+ * @beta
1703
+ */
1704
+ AddAuthenticationInfo(config) {
1705
+ return tslib.__awaiter(this, void 0, void 0, function* () {
1706
+ if (!config.httpsAgent) {
1707
+ config.httpsAgent = new https.Agent(this.certOption);
1708
+ }
1709
+ else {
1710
+ const existingProperties = new Set(Object.keys(config.httpsAgent.options));
1711
+ for (const property of Object.keys(this.certOption)) {
1712
+ if (existingProperties.has(property)) {
1713
+ throw new ErrorWithCode(formatString(ErrorMessage.DuplicateHttpsOptionProperty, property), exports.ErrorCode.InvalidParameter);
1714
+ }
1715
+ }
1716
+ Object.assign(config.httpsAgent.options, this.certOption);
1717
+ }
1718
+ return config;
1719
+ });
1720
+ }
1721
+ }
1722
+ /**
1723
+ * Helper to create SecureContextOptions from PEM format cert
1724
+ *
1725
+ * @param { string | Buffer } cert - The cert chain in PEM format
1726
+ * @param { string | Buffer } key - The private key for the cert chain
1727
+ * @param { {passphrase?: string; ca?: string | Buffer} } options - Optional settings when create the cert options.
1728
+ *
1729
+ * @returns Instance of SecureContextOptions
1730
+ *
1731
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1732
+ *
1733
+ */
1734
+ function createPemCertOption(cert, key, options) {
1735
+ if (cert.length === 0) {
1736
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "cert"), exports.ErrorCode.InvalidParameter);
1737
+ }
1738
+ if (key.length === 0) {
1739
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "key"), exports.ErrorCode.InvalidParameter);
1740
+ }
1741
+ return {
1742
+ cert,
1743
+ key,
1744
+ passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
1745
+ ca: options === null || options === void 0 ? void 0 : options.ca,
1746
+ };
1747
+ }
1748
+ /**
1749
+ * Helper to create SecureContextOptions from PFX format cert
1750
+ *
1751
+ * @param { string | Buffer } pfx - The content of .pfx file
1752
+ * @param { {passphrase?: string} } options - Optional settings when create the cert options.
1753
+ *
1754
+ * @returns Instance of SecureContextOptions
1755
+ *
1756
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1757
+ *
1758
+ */
1759
+ function createPfxCertOption(pfx, options) {
1760
+ if (pfx.length === 0) {
1761
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "pfx"), exports.ErrorCode.InvalidParameter);
1762
+ }
1763
+ return {
1764
+ pfx,
1765
+ passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
1766
+ };
1767
+ }
1768
+
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
+ ]);
1510
1786
  /**
1511
1787
  * A class providing credential and configuration.
1512
1788
  * @beta
@@ -1684,10 +1960,10 @@ class TeamsFx {
1684
1960
  this.configuration.set("sqlDatabaseName", env.SQL_DATABASE_NAME);
1685
1961
  this.configuration.set("sqlIdentityId", env.IDENTITY_ID);
1686
1962
  Object.keys(env).forEach((key) => {
1687
- const value = env[key];
1688
- if (key.startsWith("TEAMSFX_") && value) {
1689
- 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.`);
1690
1965
  }
1966
+ this.configuration.set(key, env[key]);
1691
1967
  });
1692
1968
  }
1693
1969
  }
@@ -1722,13 +1998,6 @@ class NotificationMiddleware {
1722
1998
  yield this.conversationReferenceStore.set(reference);
1723
1999
  break;
1724
2000
  }
1725
- case ActivityType.CurrentBotMessaged: {
1726
- const reference = botbuilder.TurnContext.getConversationReference(context.activity);
1727
- if (!(yield this.conversationReferenceStore.check(reference))) {
1728
- yield this.conversationReferenceStore.set(reference);
1729
- }
1730
- break;
1731
- }
1732
2001
  case ActivityType.CurrentBotUninstalled:
1733
2002
  case ActivityType.TeamDeleted: {
1734
2003
  const reference = botbuilder.TurnContext.getConversationReference(context.activity);
@@ -1751,9 +2020,6 @@ class NotificationMiddleware {
1751
2020
  return ActivityType.CurrentBotUninstalled;
1752
2021
  }
1753
2022
  }
1754
- else if (activityType === "message") {
1755
- return ActivityType.CurrentBotMessaged;
1756
- }
1757
2023
  else if (activityType === "conversationUpdate") {
1758
2024
  const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
1759
2025
  if (eventType === "teamDeleted") {
@@ -2556,8 +2822,8 @@ class MessageBuilder {
2556
2822
  /**
2557
2823
  * Build a bot message activity attached with adaptive card.
2558
2824
  *
2559
- * @param getCardData Function to prepare your card data.
2560
2825
  * @param cardTemplate The adaptive card template.
2826
+ * @param data card data used to render the template.
2561
2827
  * @returns A bot message activity attached with an adaptive card.
2562
2828
  *
2563
2829
  * @example
@@ -2582,19 +2848,18 @@ class MessageBuilder {
2582
2848
  * title: string,
2583
2849
  * description: string
2584
2850
  * };
2585
- * const card = MessageBuilder.attachAdaptiveCard<CardData>(() => {
2586
- * return {
2587
- * title: "sample card title",
2588
- * description: "sample card description"
2589
- * }}, cardTemplate);
2851
+ * const card = MessageBuilder.attachAdaptiveCard<CardData>(
2852
+ * cardTemplate, {
2853
+ * title: "sample card title",
2854
+ * description: "sample card description"
2855
+ * });
2590
2856
  * ```
2591
2857
  *
2592
2858
  * @beta
2593
2859
  */
2594
- static attachAdaptiveCard(getCardData, cardTemplate) {
2595
- const cardData = getCardData();
2860
+ static attachAdaptiveCard(cardTemplate, data) {
2596
2861
  return {
2597
- attachments: [botbuilder.CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(cardData))],
2862
+ attachments: [botbuilder.CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(data))],
2598
2863
  };
2599
2864
  }
2600
2865
  /**
@@ -2701,8 +2966,11 @@ class MessageBuilder {
2701
2966
  }
2702
2967
  }
2703
2968
 
2969
+ exports.ApiKeyProvider = ApiKeyProvider;
2704
2970
  exports.AppCredential = AppCredential;
2971
+ exports.BasicAuthProvider = BasicAuthProvider;
2705
2972
  exports.BearerTokenAuthProvider = BearerTokenAuthProvider;
2973
+ exports.CertificateAuthProvider = CertificateAuthProvider;
2706
2974
  exports.Channel = Channel;
2707
2975
  exports.CommandBot = CommandBot;
2708
2976
  exports.ConversationBot = ConversationBot;
@@ -2718,6 +2986,8 @@ exports.TeamsFx = TeamsFx;
2718
2986
  exports.TeamsUserCredential = TeamsUserCredential;
2719
2987
  exports.createApiClient = createApiClient;
2720
2988
  exports.createMicrosoftGraphClient = createMicrosoftGraphClient;
2989
+ exports.createPemCertOption = createPemCertOption;
2990
+ exports.createPfxCertOption = createPfxCertOption;
2721
2991
  exports.getLogLevel = getLogLevel;
2722
2992
  exports.getTediousConnectionConfig = getTediousConnectionConfig;
2723
2993
  exports.sendAdaptiveCard = sendAdaptiveCard;