@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.
@@ -7,6 +7,7 @@ import { ActivityTypes, Channels, TeamsInfo, CardFactory, ActionTypes, MessageFa
7
7
  import { Dialog } from 'botbuilder-dialogs';
8
8
  import { v4 } from 'uuid';
9
9
  import axios from 'axios';
10
+ import { Agent } from 'https';
10
11
  import * as path from 'path';
11
12
  import * as fs from 'fs';
12
13
 
@@ -70,6 +71,10 @@ var ErrorCode;
70
71
  * Identity type error.
71
72
  */
72
73
  ErrorCode["IdentityTypeNotSupported"] = "IdentityTypeNotSupported";
74
+ /**
75
+ * Authentication info already exists error.
76
+ */
77
+ ErrorCode["AuthorizationInfoAlreadyExists"] = "AuthorizationInfoAlreadyExists";
73
78
  })(ErrorCode || (ErrorCode = {}));
74
79
  /**
75
80
  * @internal
@@ -91,6 +96,14 @@ ErrorMessage.FailToAcquireTokenOnBehalfOfUser = "Failed to acquire access token
91
96
  ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
92
97
  // IdentityTypeNotSupported Error
93
98
  ErrorMessage.IdentityTypeNotSupported = "{0} identity is not supported in {1}";
99
+ // AuthorizationInfoError
100
+ ErrorMessage.AuthorizationHeaderAlreadyExists = "Authorization header already exists!";
101
+ ErrorMessage.BasicCredentialAlreadyExists = "Basic credential already exists!";
102
+ // InvalidParameter Error
103
+ ErrorMessage.EmptyParameter = "Parameter {0} is empty";
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}.";
94
107
  /**
95
108
  * Error class with code and message thrown by the SDK.
96
109
  *
@@ -1415,7 +1428,6 @@ function createApiClient(apiEndpoint, authProvider) {
1415
1428
  }
1416
1429
 
1417
1430
  // Copyright (c) Microsoft Corporation.
1418
- // Licensed under the MIT license.
1419
1431
  /**
1420
1432
  * Provider that handles Bearer Token authentication
1421
1433
  *
@@ -1423,7 +1435,7 @@ function createApiClient(apiEndpoint, authProvider) {
1423
1435
  */
1424
1436
  class BearerTokenAuthProvider {
1425
1437
  /**
1426
- * @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
1427
1439
  *
1428
1440
  * @beta
1429
1441
  */
@@ -1433,9 +1445,13 @@ class BearerTokenAuthProvider {
1433
1445
  /**
1434
1446
  * Adds authentication info to http requests
1435
1447
  *
1436
- * @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.
1437
1449
  * Refer https://axios-http.com/docs/req_config for detailed document.
1438
1450
  *
1451
+ * @returns Updated axios request config.
1452
+ *
1453
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header already exists in request configuration.
1454
+ *
1439
1455
  * @beta
1440
1456
  */
1441
1457
  async AddAuthenticationInfo(config) {
@@ -1444,7 +1460,7 @@ class BearerTokenAuthProvider {
1444
1460
  config.headers = {};
1445
1461
  }
1446
1462
  if (config.headers["Authorization"]) {
1447
- throw new Error("Authorization header already exists!");
1463
+ throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, ErrorCode.AuthorizationInfoAlreadyExists);
1448
1464
  }
1449
1465
  config.headers["Authorization"] = `Bearer ${token}`;
1450
1466
  return config;
@@ -1452,6 +1468,259 @@ class BearerTokenAuthProvider {
1452
1468
  }
1453
1469
 
1454
1470
  // Copyright (c) Microsoft Corporation.
1471
+ /**
1472
+ * Provider that handles Basic authentication
1473
+ *
1474
+ * @beta
1475
+ */
1476
+ class BasicAuthProvider {
1477
+ /**
1478
+ *
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.
1484
+ *
1485
+ * @beta
1486
+ */
1487
+ constructor(userName, password) {
1488
+ if (!userName) {
1489
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "username"), ErrorCode.InvalidParameter);
1490
+ }
1491
+ if (!password) {
1492
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "password"), ErrorCode.InvalidParameter);
1493
+ }
1494
+ this.userName = userName;
1495
+ this.password = password;
1496
+ }
1497
+ /**
1498
+ * Adds authentication info to http requests
1499
+ *
1500
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
1501
+ * Refer https://axios-http.com/docs/req_config for detailed document.
1502
+ *
1503
+ * @returns Updated axios request config.
1504
+ *
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.
1507
+ *
1508
+ * @beta
1509
+ */
1510
+ async AddAuthenticationInfo(config) {
1511
+ if (config.headers && config.headers["Authorization"]) {
1512
+ throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, ErrorCode.AuthorizationInfoAlreadyExists);
1513
+ }
1514
+ if (config.auth) {
1515
+ throw new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, ErrorCode.AuthorizationInfoAlreadyExists);
1516
+ }
1517
+ config.auth = {
1518
+ username: this.userName,
1519
+ password: this.password,
1520
+ };
1521
+ return config;
1522
+ }
1523
+ }
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
+
1609
+ // Copyright (c) Microsoft Corporation.
1610
+ /**
1611
+ * Provider that handles Certificate authentication
1612
+ *
1613
+ * @beta
1614
+ */
1615
+ class CertificateAuthProvider {
1616
+ /**
1617
+ *
1618
+ * @param { SecureContextOptions } certOption - information about the cert used in http requests
1619
+ *
1620
+ * @throws {@link ErrorCode|InvalidParameter} - when cert option is empty.
1621
+ *
1622
+ * @beta
1623
+ */
1624
+ constructor(certOption) {
1625
+ if (certOption && Object.keys(certOption).length !== 0) {
1626
+ this.certOption = certOption;
1627
+ }
1628
+ else {
1629
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "certOption"), ErrorCode.InvalidParameter);
1630
+ }
1631
+ }
1632
+ /**
1633
+ * Adds authentication info to http requests.
1634
+ *
1635
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
1636
+ * Refer https://axios-http.com/docs/req_config for detailed document.
1637
+ *
1638
+ * @returns Updated axios request config.
1639
+ *
1640
+ * @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
1641
+ *
1642
+ * @beta
1643
+ */
1644
+ async AddAuthenticationInfo(config) {
1645
+ if (!config.httpsAgent) {
1646
+ config.httpsAgent = new Agent(this.certOption);
1647
+ }
1648
+ else {
1649
+ const existingProperties = new Set(Object.keys(config.httpsAgent.options));
1650
+ for (const property of Object.keys(this.certOption)) {
1651
+ if (existingProperties.has(property)) {
1652
+ throw new ErrorWithCode(formatString(ErrorMessage.DuplicateHttpsOptionProperty, property), ErrorCode.InvalidParameter);
1653
+ }
1654
+ }
1655
+ Object.assign(config.httpsAgent.options, this.certOption);
1656
+ }
1657
+ return config;
1658
+ }
1659
+ }
1660
+ /**
1661
+ * Helper to create SecureContextOptions from PEM format cert
1662
+ *
1663
+ * @param { string | Buffer } cert - The cert chain in PEM format
1664
+ * @param { string | Buffer } key - The private key for the cert chain
1665
+ * @param { {passphrase?: string; ca?: string | Buffer} } options - Optional settings when create the cert options.
1666
+ *
1667
+ * @returns Instance of SecureContextOptions
1668
+ *
1669
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1670
+ *
1671
+ */
1672
+ function createPemCertOption(cert, key, options) {
1673
+ if (cert.length === 0) {
1674
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "cert"), ErrorCode.InvalidParameter);
1675
+ }
1676
+ if (key.length === 0) {
1677
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "key"), ErrorCode.InvalidParameter);
1678
+ }
1679
+ return {
1680
+ cert,
1681
+ key,
1682
+ passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
1683
+ ca: options === null || options === void 0 ? void 0 : options.ca,
1684
+ };
1685
+ }
1686
+ /**
1687
+ * Helper to create SecureContextOptions from PFX format cert
1688
+ *
1689
+ * @param { string | Buffer } pfx - The content of .pfx file
1690
+ * @param { {passphrase?: string} } options - Optional settings when create the cert options.
1691
+ *
1692
+ * @returns Instance of SecureContextOptions
1693
+ *
1694
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1695
+ *
1696
+ */
1697
+ function createPfxCertOption(pfx, options) {
1698
+ if (pfx.length === 0) {
1699
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "pfx"), ErrorCode.InvalidParameter);
1700
+ }
1701
+ return {
1702
+ pfx,
1703
+ passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
1704
+ };
1705
+ }
1706
+
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
+ ]);
1455
1724
  /**
1456
1725
  * A class providing credential and configuration.
1457
1726
  * @beta
@@ -1625,10 +1894,10 @@ class TeamsFx {
1625
1894
  this.configuration.set("sqlDatabaseName", env.SQL_DATABASE_NAME);
1626
1895
  this.configuration.set("sqlIdentityId", env.IDENTITY_ID);
1627
1896
  Object.keys(env).forEach((key) => {
1628
- const value = env[key];
1629
- if (key.startsWith("TEAMSFX_") && value) {
1630
- 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.`);
1631
1899
  }
1900
+ this.configuration.set(key, env[key]);
1632
1901
  });
1633
1902
  }
1634
1903
  }
@@ -1662,13 +1931,6 @@ class NotificationMiddleware {
1662
1931
  await this.conversationReferenceStore.set(reference);
1663
1932
  break;
1664
1933
  }
1665
- case ActivityType.CurrentBotMessaged: {
1666
- const reference = TurnContext.getConversationReference(context.activity);
1667
- if (!(await this.conversationReferenceStore.check(reference))) {
1668
- await this.conversationReferenceStore.set(reference);
1669
- }
1670
- break;
1671
- }
1672
1934
  case ActivityType.CurrentBotUninstalled:
1673
1935
  case ActivityType.TeamDeleted: {
1674
1936
  const reference = TurnContext.getConversationReference(context.activity);
@@ -1690,9 +1952,6 @@ class NotificationMiddleware {
1690
1952
  return ActivityType.CurrentBotUninstalled;
1691
1953
  }
1692
1954
  }
1693
- else if (activityType === "message") {
1694
- return ActivityType.CurrentBotMessaged;
1695
- }
1696
1955
  else if (activityType === "conversationUpdate") {
1697
1956
  const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
1698
1957
  if (eventType === "teamDeleted") {
@@ -2465,8 +2724,8 @@ class MessageBuilder {
2465
2724
  /**
2466
2725
  * Build a bot message activity attached with adaptive card.
2467
2726
  *
2468
- * @param getCardData Function to prepare your card data.
2469
2727
  * @param cardTemplate The adaptive card template.
2728
+ * @param data card data used to render the template.
2470
2729
  * @returns A bot message activity attached with an adaptive card.
2471
2730
  *
2472
2731
  * @example
@@ -2491,19 +2750,18 @@ class MessageBuilder {
2491
2750
  * title: string,
2492
2751
  * description: string
2493
2752
  * };
2494
- * const card = MessageBuilder.attachAdaptiveCard<CardData>(() => {
2495
- * return {
2496
- * title: "sample card title",
2497
- * description: "sample card description"
2498
- * }}, cardTemplate);
2753
+ * const card = MessageBuilder.attachAdaptiveCard<CardData>(
2754
+ * cardTemplate, {
2755
+ * title: "sample card title",
2756
+ * description: "sample card description"
2757
+ * });
2499
2758
  * ```
2500
2759
  *
2501
2760
  * @beta
2502
2761
  */
2503
- static attachAdaptiveCard(getCardData, cardTemplate) {
2504
- const cardData = getCardData();
2762
+ static attachAdaptiveCard(cardTemplate, data) {
2505
2763
  return {
2506
- attachments: [CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(cardData))],
2764
+ attachments: [CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(data))],
2507
2765
  };
2508
2766
  }
2509
2767
  /**
@@ -2610,5 +2868,5 @@ class MessageBuilder {
2610
2868
  }
2611
2869
  }
2612
2870
 
2613
- export { AppCredential, BearerTokenAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, LogLevel, Member, MessageBuilder, MsGraphAuthProvider, NotificationBot, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, 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 };
2614
2872
  //# sourceMappingURL=index.esm2017.mjs.map