@microsoft/teamsfx 0.6.3-alpha.f018de6e6.0 → 0.6.3-alpha.f6638b461.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.
@@ -102,6 +102,8 @@ ErrorMessage.BasicCredentialAlreadyExists = "Basic credential already exists!";
102
102
  // InvalidParameter Error
103
103
  ErrorMessage.EmptyParameter = "Parameter {0} is empty";
104
104
  ErrorMessage.DuplicateHttpsOptionProperty = "Axios HTTPS agent already defined value for property {0}";
105
+ ErrorMessage.DuplicateApiKeyInHeader = "The request already defined api key in request header with name {0}.";
106
+ ErrorMessage.DuplicateApiKeyInQueryParam = "The request already defined api key in query parameter with name {0}.";
105
107
  /**
106
108
  * Error class with code and message thrown by the SDK.
107
109
  *
@@ -1433,7 +1435,7 @@ function createApiClient(apiEndpoint, authProvider) {
1433
1435
  */
1434
1436
  class BearerTokenAuthProvider {
1435
1437
  /**
1436
- * @param getToken Function that returns the content of bearer token used in http request
1438
+ * @param { () => Promise<string> } getToken - Function that returns the content of bearer token used in http request
1437
1439
  *
1438
1440
  * @beta
1439
1441
  */
@@ -1443,7 +1445,7 @@ class BearerTokenAuthProvider {
1443
1445
  /**
1444
1446
  * Adds authentication info to http requests
1445
1447
  *
1446
- * @param config - Contains all the request information and can be updated to include extra authentication info.
1448
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
1447
1449
  * Refer https://axios-http.com/docs/req_config for detailed document.
1448
1450
  *
1449
1451
  * @returns Updated axios request config.
@@ -1474,8 +1476,11 @@ class BearerTokenAuthProvider {
1474
1476
  class BasicAuthProvider {
1475
1477
  /**
1476
1478
  *
1477
- * @param userName - Username used in basic auth
1478
- * @param password - Password used in basic auth
1479
+ * @param { string } userName - Username used in basic auth
1480
+ * @param { string } password - Password used in basic auth
1481
+ *
1482
+ * @throws {@link ErrorCode|InvalidParameter} - when username or password is empty.
1483
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1479
1484
  *
1480
1485
  * @beta
1481
1486
  */
@@ -1492,12 +1497,13 @@ class BasicAuthProvider {
1492
1497
  /**
1493
1498
  * Adds authentication info to http requests
1494
1499
  *
1495
- * @param config - Contains all the request information and can be updated to include extra authentication info.
1500
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
1496
1501
  * Refer https://axios-http.com/docs/req_config for detailed document.
1497
1502
  *
1498
1503
  * @returns Updated axios request config.
1499
1504
  *
1500
1505
  * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header or auth property already exists in request configuration.
1506
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1501
1507
  *
1502
1508
  * @beta
1503
1509
  */
@@ -1516,6 +1522,90 @@ class BasicAuthProvider {
1516
1522
  }
1517
1523
  }
1518
1524
 
1525
+ // Copyright (c) Microsoft Corporation.
1526
+ /**
1527
+ * Provider that handles API Key authentication
1528
+ *
1529
+ * @beta
1530
+ */
1531
+ class ApiKeyProvider {
1532
+ /**
1533
+ *
1534
+ * @param { string } keyName - The name of request header or query parameter that specifies API Key
1535
+ * @param { string } keyValue - The value of API Key
1536
+ * @param { ApiKeyLocation } keyLocation - The location of API Key: request header or query parameter.
1537
+ *
1538
+ * @throws {@link ErrorCode|InvalidParameter} - when key name or key value is empty.
1539
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1540
+ *
1541
+ * @beta
1542
+ */
1543
+ constructor(keyName, keyValue, keyLocation) {
1544
+ if (!keyName) {
1545
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "keyName"), ErrorCode.InvalidParameter);
1546
+ }
1547
+ if (!keyValue) {
1548
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "keyVaule"), ErrorCode.InvalidParameter);
1549
+ }
1550
+ this.keyName = keyName;
1551
+ this.keyValue = keyValue;
1552
+ this.keyLocation = keyLocation;
1553
+ }
1554
+ /**
1555
+ * Adds authentication info to http requests
1556
+ *
1557
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
1558
+ * Refer https://axios-http.com/docs/req_config for detailed document.
1559
+ *
1560
+ * @returns Updated axios request config.
1561
+ *
1562
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when API key already exists in request header or url query parameter.
1563
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1564
+ *
1565
+ * @beta
1566
+ */
1567
+ async AddAuthenticationInfo(config) {
1568
+ switch (this.keyLocation) {
1569
+ case ApiKeyLocation.Header:
1570
+ if (!config.headers) {
1571
+ config.headers = {};
1572
+ }
1573
+ if (config.headers[this.keyName]) {
1574
+ throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInHeader, this.keyName), ErrorCode.AuthorizationInfoAlreadyExists);
1575
+ }
1576
+ config.headers[this.keyName] = this.keyValue;
1577
+ break;
1578
+ case ApiKeyLocation.QueryParams:
1579
+ if (!config.params) {
1580
+ config.params = {};
1581
+ }
1582
+ const url = new URL(config.url, config.baseURL);
1583
+ if (config.params[this.keyName] || url.searchParams.has(this.keyName)) {
1584
+ throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInQueryParam, this.keyName), ErrorCode.AuthorizationInfoAlreadyExists);
1585
+ }
1586
+ config.params[this.keyName] = this.keyValue;
1587
+ break;
1588
+ }
1589
+ return config;
1590
+ }
1591
+ }
1592
+ /**
1593
+ * Define available location for API Key location
1594
+ *
1595
+ * @beta
1596
+ */
1597
+ var ApiKeyLocation;
1598
+ (function (ApiKeyLocation) {
1599
+ /**
1600
+ * The API Key is placed in request header
1601
+ */
1602
+ ApiKeyLocation[ApiKeyLocation["Header"] = 0] = "Header";
1603
+ /**
1604
+ * The API Key is placed in query parameter
1605
+ */
1606
+ ApiKeyLocation[ApiKeyLocation["QueryParams"] = 1] = "QueryParams";
1607
+ })(ApiKeyLocation || (ApiKeyLocation = {}));
1608
+
1519
1609
  // Copyright (c) Microsoft Corporation.
1520
1610
  /**
1521
1611
  * Provider that handles Certificate authentication
@@ -1527,6 +1617,8 @@ class CertificateAuthProvider {
1527
1617
  *
1528
1618
  * @param { SecureContextOptions } certOption - information about the cert used in http requests
1529
1619
  *
1620
+ * @throws {@link ErrorCode|InvalidParameter} - when cert option is empty.
1621
+ *
1530
1622
  * @beta
1531
1623
  */
1532
1624
  constructor(certOption) {
@@ -1570,15 +1662,14 @@ class CertificateAuthProvider {
1570
1662
  *
1571
1663
  * @param { string | Buffer } cert - The cert chain in PEM format
1572
1664
  * @param { string | Buffer } key - The private key for the cert chain
1573
- * @param { string? } passphrase - The passphrase for private key
1574
- * @param { string? | Buffer? } ca - Overrides the trusted CA certificates
1665
+ * @param { {passphrase?: string; ca?: string | Buffer} } options - Optional settings when create the cert options.
1575
1666
  *
1576
1667
  * @returns Instance of SecureContextOptions
1577
1668
  *
1578
1669
  * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1579
1670
  *
1580
1671
  */
1581
- function createPemCertOption(cert, key, passphrase, ca) {
1672
+ function createPemCertOption(cert, key, options) {
1582
1673
  if (cert.length === 0) {
1583
1674
  throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "cert"), ErrorCode.InvalidParameter);
1584
1675
  }
@@ -1588,32 +1679,48 @@ function createPemCertOption(cert, key, passphrase, ca) {
1588
1679
  return {
1589
1680
  cert,
1590
1681
  key,
1591
- passphrase,
1592
- ca,
1682
+ passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
1683
+ ca: options === null || options === void 0 ? void 0 : options.ca,
1593
1684
  };
1594
1685
  }
1595
1686
  /**
1596
1687
  * Helper to create SecureContextOptions from PFX format cert
1597
1688
  *
1598
1689
  * @param { string | Buffer } pfx - The content of .pfx file
1599
- * @param { string? } passphrase - Optional. The passphrase of .pfx file
1690
+ * @param { {passphrase?: string} } options - Optional settings when create the cert options.
1600
1691
  *
1601
1692
  * @returns Instance of SecureContextOptions
1602
1693
  *
1603
1694
  * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1604
1695
  *
1605
1696
  */
1606
- function createPfxCertOption(pfx, passphrase) {
1697
+ function createPfxCertOption(pfx, options) {
1607
1698
  if (pfx.length === 0) {
1608
1699
  throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "pfx"), ErrorCode.InvalidParameter);
1609
1700
  }
1610
1701
  return {
1611
1702
  pfx,
1612
- passphrase,
1703
+ passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
1613
1704
  };
1614
1705
  }
1615
1706
 
1616
1707
  // Copyright (c) Microsoft Corporation.
1708
+ // Following keys are used by SDK internally
1709
+ const ReservedKey = new Set([
1710
+ "authorityHost",
1711
+ "tenantId",
1712
+ "clientId",
1713
+ "clientSecret",
1714
+ "initiateLoginEndpoint",
1715
+ "applicationIdUri",
1716
+ "apiEndpoint",
1717
+ "apiName",
1718
+ "sqlServerEndpoint",
1719
+ "sqlUsername",
1720
+ "sqlPassword",
1721
+ "sqlDatabaseName",
1722
+ "sqlIdentityId",
1723
+ ]);
1617
1724
  /**
1618
1725
  * A class providing credential and configuration.
1619
1726
  * @beta
@@ -1787,10 +1894,10 @@ class TeamsFx {
1787
1894
  this.configuration.set("sqlDatabaseName", env.SQL_DATABASE_NAME);
1788
1895
  this.configuration.set("sqlIdentityId", env.IDENTITY_ID);
1789
1896
  Object.keys(env).forEach((key) => {
1790
- const value = env[key];
1791
- if (key.startsWith("TEAMSFX_") && value) {
1792
- this.configuration.set(key.substring(8), value);
1897
+ if (ReservedKey.has(key)) {
1898
+ internalLogger.warn(`The name of environment variable ${key} is preserved. Will not load it as configuration.`);
1793
1899
  }
1900
+ this.configuration.set(key, env[key]);
1794
1901
  });
1795
1902
  }
1796
1903
  }
@@ -1824,13 +1931,6 @@ class NotificationMiddleware {
1824
1931
  await this.conversationReferenceStore.set(reference);
1825
1932
  break;
1826
1933
  }
1827
- case ActivityType.CurrentBotMessaged: {
1828
- const reference = TurnContext.getConversationReference(context.activity);
1829
- if (!(await this.conversationReferenceStore.check(reference))) {
1830
- await this.conversationReferenceStore.set(reference);
1831
- }
1832
- break;
1833
- }
1834
1934
  case ActivityType.CurrentBotUninstalled:
1835
1935
  case ActivityType.TeamDeleted: {
1836
1936
  const reference = TurnContext.getConversationReference(context.activity);
@@ -1852,9 +1952,6 @@ class NotificationMiddleware {
1852
1952
  return ActivityType.CurrentBotUninstalled;
1853
1953
  }
1854
1954
  }
1855
- else if (activityType === "message") {
1856
- return ActivityType.CurrentBotMessaged;
1857
- }
1858
1955
  else if (activityType === "conversationUpdate") {
1859
1956
  const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
1860
1957
  if (eventType === "teamDeleted") {
@@ -2771,5 +2868,5 @@ class MessageBuilder {
2771
2868
  }
2772
2869
  }
2773
2870
 
2774
- export { AppCredential, BasicAuthProvider, BearerTokenAuthProvider, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, LogLevel, Member, MessageBuilder, MsGraphAuthProvider, NotificationBot, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
2871
+ export { ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, LogLevel, Member, MessageBuilder, MsGraphAuthProvider, NotificationBot, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
2775
2872
  //# sourceMappingURL=index.esm2017.mjs.map