@microsoft/teamsfx 2.2.3-alpha.25b558a2a.0 → 2.2.3-alpha.5925cbfed.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.
@@ -425,6 +425,7 @@ function getAuthority(authorityHost, tenantId) {
425
425
  return normalizedAuthorityHost + "/" + tenantId;
426
426
  }
427
427
 
428
+ // Copyright (c) Microsoft Corporation.
428
429
  /**
429
430
  * @internal
430
431
  */
@@ -747,9 +748,7 @@ class TeamsUserCredential {
747
748
  * Can only be used within Teams.
748
749
  */
749
750
  login(scopes, resources) {
750
- return tslib.__awaiter(this, void 0, void 0, function* () {
751
- throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported);
752
- });
751
+ return Promise.reject(new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported));
753
752
  }
754
753
  /**
755
754
  * Get access token from credential.
@@ -757,9 +756,7 @@ class TeamsUserCredential {
757
756
  * Can only be used within Teams.
758
757
  */
759
758
  getToken(scopes, options) {
760
- return tslib.__awaiter(this, void 0, void 0, function* () {
761
- throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported);
762
- });
759
+ return Promise.reject(new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported));
763
760
  }
764
761
  /**
765
762
  * Get basic user info from SSO token
@@ -770,14 +767,16 @@ class TeamsUserCredential {
770
767
  * Can only be used within Teams.
771
768
  */
772
769
  getUserInfo(resources) {
773
- throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported);
770
+ return Promise.reject(new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported));
774
771
  }
775
772
  }
776
773
 
777
774
  // Copyright (c) Microsoft Corporation.
778
775
  const defaultScope = "https://graph.microsoft.com/.default";
776
+ // eslint-disable-next-line no-secrets/no-secrets
779
777
  /**
780
778
  * Microsoft Graph auth provider for Teams Framework
779
+ * @deprecated Use `TokenCredentialAuthenticationProvider` from `@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials` instead.
781
780
  */
782
781
  class MsGraphAuthProvider {
783
782
  constructor(credentialOrTeamsFx, scopes) {
@@ -807,7 +806,7 @@ class MsGraphAuthProvider {
807
806
  */
808
807
  getAccessToken() {
809
808
  return tslib.__awaiter(this, void 0, void 0, function* () {
810
- internalLogger.info(`Get Graph Access token with scopes: '${this.scopes}'`);
809
+ internalLogger.info(`Get Graph Access token with scopes: '${this.scopes.toString()}'`);
811
810
  let accessToken;
812
811
  if (this.credentialOrTeamsFx.getCredential) {
813
812
  accessToken = yield this.credentialOrTeamsFx
@@ -834,6 +833,14 @@ class MsGraphAuthProvider {
834
833
  // Copyright (c) Microsoft Corporation.
835
834
  /**
836
835
  * Get Microsoft graph client.
836
+ * @deprecated Use `TokenCredentialAuthenticationProvider` and `Client.initWithMiddleware` instead.
837
+ * ```typescript
838
+ * const authProvider = new TokenCredentialAuthenticationProvider(credential, { scopes: scope });
839
+ * const graph = Client.initWithMiddleware({
840
+ * authProvider: authProvider,
841
+ * });
842
+ * ```
843
+ *
837
844
  * @example
838
845
  * Get Microsoft graph client by TokenCredential
839
846
  * ```typescript
@@ -891,6 +898,14 @@ function createMicrosoftGraphClient(teamsfx, scopes) {
891
898
  // eslint-disable-next-line no-secrets/no-secrets
892
899
  /**
893
900
  * Get Microsoft graph client.
901
+ * @deprecated Use `TokenCredentialAuthenticationProvider` and `Client.initWithMiddleware` instead.
902
+ * ```typescript
903
+ * const authProvider = new TokenCredentialAuthenticationProvider(credential, { scopes: scope });
904
+ * const graph = Client.initWithMiddleware({
905
+ * authProvider: authProvider,
906
+ * });
907
+ * ```
908
+ *
894
909
  * @example
895
910
  * Get Microsoft graph client by TokenCredential
896
911
  * ```typescript
@@ -1048,7 +1063,7 @@ function isMsiAuthentication(teamsfx) {
1048
1063
  function generateDefaultConfig(teamsfx, databaseName) {
1049
1064
  internalLogger.verbose(`SQL server ${teamsfx.getConfig("sqlServerEndpoint")}
1050
1065
  , user name ${teamsfx.getConfig("sqlUsername")}
1051
- , database name ${databaseName}`);
1066
+ , database name ${databaseName ? databaseName : ""}`);
1052
1067
  const config = {
1053
1068
  server: teamsfx.getConfig("sqlServerEndpoint"),
1054
1069
  authentication: {
@@ -1102,7 +1117,7 @@ function generateTokenConfig(teamsfx, databaseName) {
1102
1117
  };
1103
1118
  internalLogger.verbose(`Generate token configuration success
1104
1119
  , server endpoint is ${teamsfx.getConfig("sqlServerEndpoint")}
1105
- , database name is ${databaseName}`);
1120
+ , database name is ${databaseName ? databaseName : ""}`);
1106
1121
  return config;
1107
1122
  }
1108
1123
  internalLogger.error(`Generate token configuration
@@ -1376,7 +1391,8 @@ class TeamsBotSsoPrompt extends botbuilderDialogs.Dialog {
1376
1391
  return tslib.__awaiter(this, void 0, void 0, function* () {
1377
1392
  internalLogger.verbose("Send OAuth card to get SSO token");
1378
1393
  const account = yield botbuilder.TeamsInfo.getMember(context, context.activity.from.id);
1379
- internalLogger.verbose("Get Teams member account user principal name: " + account.userPrincipalName);
1394
+ internalLogger.verbose("Get Teams member account user principal name: " +
1395
+ (account.userPrincipalName ? account.userPrincipalName : ""));
1380
1396
  const loginHint = account.userPrincipalName ? account.userPrincipalName : "";
1381
1397
  const signInResource = this.getSignInResource(loginHint);
1382
1398
  const card = botbuilder.CardFactory.oauthCard("", "Teams SSO Sign In", "Sign In", signInResource.signInLink, signInResource.tokenExchangeResource);
@@ -1584,19 +1600,17 @@ class BasicAuthProvider {
1584
1600
  * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1585
1601
  */
1586
1602
  AddAuthenticationInfo(config) {
1587
- return tslib.__awaiter(this, void 0, void 0, function* () {
1588
- if (config.headers && config.headers["Authorization"]) {
1589
- throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1590
- }
1591
- if (config.auth) {
1592
- throw new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1593
- }
1594
- config.auth = {
1595
- username: this.userName,
1596
- password: this.password,
1597
- };
1598
- return config;
1599
- });
1603
+ if (config.headers && config.headers["Authorization"]) {
1604
+ return Promise.reject(new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists));
1605
+ }
1606
+ if (config.auth) {
1607
+ return Promise.reject(new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists));
1608
+ }
1609
+ config.auth = {
1610
+ username: this.userName,
1611
+ password: this.password,
1612
+ };
1613
+ return Promise.resolve(config);
1600
1614
  }
1601
1615
  }
1602
1616
 
@@ -1637,34 +1651,32 @@ class ApiKeyProvider {
1637
1651
  * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1638
1652
  */
1639
1653
  AddAuthenticationInfo(config) {
1640
- return tslib.__awaiter(this, void 0, void 0, function* () {
1641
- switch (this.keyLocation) {
1642
- case exports.ApiKeyLocation.Header:
1643
- if (!config.headers) {
1644
- config.headers = {};
1645
- }
1646
- if (config.headers[this.keyName]) {
1647
- throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInHeader, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists);
1648
- }
1649
- config.headers[this.keyName] = this.keyValue;
1650
- break;
1651
- case exports.ApiKeyLocation.QueryParams:
1652
- if (!config.params) {
1653
- config.params = {};
1654
- }
1655
- let urlHasDefinedApiKey = false;
1656
- if (config.url) {
1657
- const url = new URL(config.url, config.baseURL);
1658
- urlHasDefinedApiKey = url.searchParams.has(this.keyName);
1659
- }
1660
- if (config.params[this.keyName] || urlHasDefinedApiKey) {
1661
- throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInQueryParam, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists);
1662
- }
1663
- config.params[this.keyName] = this.keyValue;
1664
- break;
1665
- }
1666
- return config;
1667
- });
1654
+ switch (this.keyLocation) {
1655
+ case exports.ApiKeyLocation.Header:
1656
+ if (!config.headers) {
1657
+ config.headers = {};
1658
+ }
1659
+ if (config.headers[this.keyName]) {
1660
+ return Promise.reject(new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInHeader, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists));
1661
+ }
1662
+ config.headers[this.keyName] = this.keyValue;
1663
+ break;
1664
+ case exports.ApiKeyLocation.QueryParams:
1665
+ if (!config.params) {
1666
+ config.params = {};
1667
+ }
1668
+ let urlHasDefinedApiKey = false;
1669
+ if (config.url) {
1670
+ const url = new URL(config.url, config.baseURL);
1671
+ urlHasDefinedApiKey = url.searchParams.has(this.keyName);
1672
+ }
1673
+ if (config.params[this.keyName] || urlHasDefinedApiKey) {
1674
+ return Promise.reject(new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInQueryParam, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists));
1675
+ }
1676
+ config.params[this.keyName] = this.keyValue;
1677
+ break;
1678
+ }
1679
+ return Promise.resolve(config);
1668
1680
  }
1669
1681
  }
1670
1682
  /**
@@ -1712,21 +1724,19 @@ class CertificateAuthProvider {
1712
1724
  * @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
1713
1725
  */
1714
1726
  AddAuthenticationInfo(config) {
1715
- return tslib.__awaiter(this, void 0, void 0, function* () {
1716
- if (!config.httpsAgent) {
1717
- config.httpsAgent = new https.Agent(this.certOption);
1718
- }
1719
- else {
1720
- const existingProperties = new Set(Object.keys(config.httpsAgent.options));
1721
- for (const property of Object.keys(this.certOption)) {
1722
- if (existingProperties.has(property)) {
1723
- throw new ErrorWithCode(formatString(ErrorMessage.DuplicateHttpsOptionProperty, property), exports.ErrorCode.InvalidParameter);
1724
- }
1727
+ if (!config.httpsAgent) {
1728
+ config.httpsAgent = new https.Agent(this.certOption);
1729
+ }
1730
+ else {
1731
+ const existingProperties = new Set(Object.keys(config.httpsAgent.options));
1732
+ for (const property of Object.keys(this.certOption)) {
1733
+ if (existingProperties.has(property)) {
1734
+ return Promise.reject(new ErrorWithCode(formatString(ErrorMessage.DuplicateHttpsOptionProperty, property), exports.ErrorCode.InvalidParameter));
1725
1735
  }
1726
- Object.assign(config.httpsAgent.options, this.certOption);
1727
1736
  }
1728
- return config;
1729
- });
1737
+ Object.assign(config.httpsAgent.options, this.certOption);
1738
+ }
1739
+ return Promise.resolve(config);
1730
1740
  }
1731
1741
  }
1732
1742
  /**
@@ -1795,6 +1805,8 @@ const ReservedKey = new Set([
1795
1805
  ]);
1796
1806
  /**
1797
1807
  * A class providing credential and configuration.
1808
+ * @deprecated Please use {@link TeamsUserCredential}
1809
+ * in browser environment and {@link OnBehalfOfUserCredential} or {@link AppCredential} in NodeJS.
1798
1810
  */
1799
1811
  class TeamsFx {
1800
1812
  /**
@@ -2813,7 +2825,7 @@ class Channel$1 {
2813
2825
  return tslib.__awaiter(this, void 0, void 0, function* () {
2814
2826
  const response = {};
2815
2827
  yield this.parent.adapter.continueConversation(this.parent.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
2816
- const conversation = yield this.newConversation(context);
2828
+ const conversation = this.newConversation(context);
2817
2829
  yield this.parent.adapter.continueConversation(conversation, (ctx) => tslib.__awaiter(this, void 0, void 0, function* () {
2818
2830
  try {
2819
2831
  const res = yield ctx.sendActivity(text);
@@ -2844,7 +2856,7 @@ class Channel$1 {
2844
2856
  return tslib.__awaiter(this, void 0, void 0, function* () {
2845
2857
  const response = {};
2846
2858
  yield this.parent.adapter.continueConversation(this.parent.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
2847
- const conversation = yield this.newConversation(context);
2859
+ const conversation = this.newConversation(context);
2848
2860
  yield this.parent.adapter.continueConversation(conversation, (ctx) => tslib.__awaiter(this, void 0, void 0, function* () {
2849
2861
  try {
2850
2862
  const res = yield ctx.sendActivity({
@@ -2869,12 +2881,10 @@ class Channel$1 {
2869
2881
  * @internal
2870
2882
  */
2871
2883
  newConversation(context) {
2872
- return tslib.__awaiter(this, void 0, void 0, function* () {
2873
- const reference = botbuilder.TurnContext.getConversationReference(context.activity);
2874
- const channelConversation = cloneConversation(reference);
2875
- channelConversation.conversation.id = this.info.id || "";
2876
- return channelConversation;
2877
- });
2884
+ const reference = botbuilder.TurnContext.getConversationReference(context.activity);
2885
+ const channelConversation = cloneConversation(reference);
2886
+ channelConversation.conversation.id = this.info.id || "";
2887
+ return channelConversation;
2878
2888
  }
2879
2889
  }
2880
2890
  /**
@@ -4074,6 +4084,7 @@ function executionWithTokenAndConfig(context, authConfig, initiateLoginEndpoint,
4074
4084
  }
4075
4085
  /**
4076
4086
  * execution in message extension with SSO token.
4087
+ * @deprecated Use {@link executionWithTokenAndConfig} instead.
4077
4088
  *
4078
4089
  * @param {TurnContext} context - The context object for the current turn.
4079
4090
  * @param {AuthenticationConfiguration} config - User custom the message extension authentication configuration.
@@ -4124,7 +4135,7 @@ function executionWithToken(context, config, scopes, logic) {
4124
4135
  // eslint-disable-next-line no-secrets/no-secrets
4125
4136
  /**
4126
4137
  * Users execute query in message extension with SSO or access token.
4127
- *
4138
+ * @deprecated Use {@link handleMessageExtensionQueryWithSSO} instead.
4128
4139
  *
4129
4140
  * @param {TurnContext} context - The context object for the current turn.
4130
4141
  * @param {AuthenticationConfiguration} config - User custom the message extension authentication configuration.
@@ -4406,12 +4417,10 @@ class Channel {
4406
4417
  * @internal
4407
4418
  */
4408
4419
  newConversation(context) {
4409
- return tslib.__awaiter(this, void 0, void 0, function* () {
4410
- const reference = botbuilder.TurnContext.getConversationReference(context.activity);
4411
- const channelConversation = cloneConversation(reference);
4412
- channelConversation.conversation.id = this.info.id || "";
4413
- return channelConversation;
4414
- });
4420
+ const reference = botbuilder.TurnContext.getConversationReference(context.activity);
4421
+ const channelConversation = cloneConversation(reference);
4422
+ channelConversation.conversation.id = this.info.id || "";
4423
+ return Promise.resolve(channelConversation);
4415
4424
  }
4416
4425
  }
4417
4426
  /**
@@ -5057,9 +5066,9 @@ class ConversationBot {
5057
5066
  // the default error handler
5058
5067
  adapter.onTurnError = (context, error) => tslib.__awaiter(this, void 0, void 0, function* () {
5059
5068
  // This check writes out errors to console.
5060
- console.error(`[onTurnError] unhandled error: ${error}`);
5069
+ console.error(`[onTurnError] unhandled error`, error);
5061
5070
  // Send a trace activity, which will be displayed in Bot Framework Emulator
5062
- yield context.sendTraceActivity("OnTurnError Trace", `${error}`, "https://www.botframework.com/schemas/error", "TurnError");
5071
+ yield context.sendTraceActivity("OnTurnError Trace", error instanceof Error ? error.message : error, "https://www.botframework.com/schemas/error", "TurnError");
5063
5072
  // Send a message to the user
5064
5073
  yield context.sendActivity(`The bot encountered unhandled error: ${error.message}`);
5065
5074
  yield context.sendActivity("To continue to run this bot, please fix the bot source code.");