@microsoft/teamsfx 2.2.3-alpha.9b38c38b5.0 → 2.2.3-alpha.ebba7eb40.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
  /**
@@ -3618,8 +3628,7 @@ class DefaultBotSsoExecutionActivityHandler extends botbuilder.TeamsActivityHand
3618
3628
  timeout: (_h = (_g = ssoConfig.dialog) === null || _g === void 0 ? void 0 : _g.ssoPromptConfig) === null || _h === void 0 ? void 0 : _h.timeout,
3619
3629
  endOnInvalidMessage: (_k = (_j = ssoConfig.dialog) === null || _j === void 0 ? void 0 : _j.ssoPromptConfig) === null || _k === void 0 ? void 0 : _k.endOnInvalidMessage,
3620
3630
  };
3621
- const teamsfx = new TeamsFx(exports.IdentityType.User, Object.assign({}, customConfig));
3622
- this.ssoExecutionDialog = new BotSsoExecutionDialog(dedupStorage, settings, teamsfx);
3631
+ this.ssoExecutionDialog = new BotSsoExecutionDialog(dedupStorage, settings, customConfig, customConfig.initiateLoginEndpoint);
3623
3632
  this.conversationState = conversationState;
3624
3633
  this.dialogState = conversationState.createProperty("DialogState");
3625
3634
  this.userState = userState;
@@ -4074,6 +4083,7 @@ function executionWithTokenAndConfig(context, authConfig, initiateLoginEndpoint,
4074
4083
  }
4075
4084
  /**
4076
4085
  * execution in message extension with SSO token.
4086
+ * @deprecated Use {@link executionWithTokenAndConfig} instead.
4077
4087
  *
4078
4088
  * @param {TurnContext} context - The context object for the current turn.
4079
4089
  * @param {AuthenticationConfiguration} config - User custom the message extension authentication configuration.
@@ -4124,7 +4134,7 @@ function executionWithToken(context, config, scopes, logic) {
4124
4134
  // eslint-disable-next-line no-secrets/no-secrets
4125
4135
  /**
4126
4136
  * Users execute query in message extension with SSO or access token.
4127
- *
4137
+ * @deprecated Use {@link handleMessageExtensionQueryWithSSO} instead.
4128
4138
  *
4129
4139
  * @param {TurnContext} context - The context object for the current turn.
4130
4140
  * @param {AuthenticationConfiguration} config - User custom the message extension authentication configuration.
@@ -4406,12 +4416,10 @@ class Channel {
4406
4416
  * @internal
4407
4417
  */
4408
4418
  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
- });
4419
+ const reference = botbuilder.TurnContext.getConversationReference(context.activity);
4420
+ const channelConversation = cloneConversation(reference);
4421
+ channelConversation.conversation.id = this.info.id || "";
4422
+ return Promise.resolve(channelConversation);
4415
4423
  }
4416
4424
  }
4417
4425
  /**
@@ -4736,6 +4744,29 @@ class NotificationBot {
4736
4744
  }
4737
4745
  return new TeamsBotInstallation(this.adapter, conversationReference, this.botAppId);
4738
4746
  }
4747
+ /**
4748
+ * Validate the installation by getting paged memebers.
4749
+ *
4750
+ * @param conversationReference The bound `ConversationReference`.
4751
+ * @returns Returns false if recieves `BotNotInConversationRoster` error, otherwise returns true.
4752
+ */
4753
+ validateInstallation(conversationReference) {
4754
+ return tslib.__awaiter(this, void 0, void 0, function* () {
4755
+ let isValid = true;
4756
+ yield this.adapter.continueConversationAsync(this.botAppId, conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
4757
+ try {
4758
+ // try get member to see if the installation is still valid
4759
+ yield botbuilder.TeamsInfo.getPagedMembers(context, 1);
4760
+ }
4761
+ catch (error) {
4762
+ if (error.code === "BotNotInConversationRoster") {
4763
+ isValid = false;
4764
+ }
4765
+ }
4766
+ }));
4767
+ return isValid;
4768
+ });
4769
+ }
4739
4770
  /**
4740
4771
  * Gets a pagined list of targets where the bot is installed.
4741
4772
  *
@@ -4747,7 +4778,7 @@ class NotificationBot {
4747
4778
  *
4748
4779
  * @returns An array of {@link TeamsBotInstallation} with paged data and continuation token.
4749
4780
  */
4750
- getPagedInstallations(pageSize, continuationToken) {
4781
+ getPagedInstallations(pageSize, continuationToken, validationEnabled = true) {
4751
4782
  return tslib.__awaiter(this, void 0, void 0, function* () {
4752
4783
  if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
4753
4784
  throw new Error("NotificationBot has not been initialized.");
@@ -4756,19 +4787,12 @@ class NotificationBot {
4756
4787
  const targets = [];
4757
4788
  for (const reference of references.data) {
4758
4789
  // validate connection
4759
- let valid = true;
4760
- yield this.adapter.continueConversationAsync(this.botAppId, reference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
4761
- try {
4762
- // try get member to see if the installation is still valid
4763
- yield botbuilder.TeamsInfo.getPagedMembers(context, 1);
4764
- }
4765
- catch (error) {
4766
- if (error.code === "BotNotInConversationRoster") {
4767
- valid = false;
4768
- }
4769
- }
4770
- }));
4771
- if (valid) {
4790
+ let valid;
4791
+ if (validationEnabled) {
4792
+ // try get member to see if the installation is still valid
4793
+ valid = yield this.validateInstallation(reference);
4794
+ }
4795
+ if (!validationEnabled || (validationEnabled && valid)) {
4772
4796
  targets.push(new TeamsBotInstallation(this.adapter, reference, this.botAppId));
4773
4797
  }
4774
4798
  else {
@@ -5041,9 +5065,9 @@ class ConversationBot {
5041
5065
  // the default error handler
5042
5066
  adapter.onTurnError = (context, error) => tslib.__awaiter(this, void 0, void 0, function* () {
5043
5067
  // This check writes out errors to console.
5044
- console.error(`[onTurnError] unhandled error: ${error}`);
5068
+ console.error(`[onTurnError] unhandled error`, error);
5045
5069
  // Send a trace activity, which will be displayed in Bot Framework Emulator
5046
- yield context.sendTraceActivity("OnTurnError Trace", `${error}`, "https://www.botframework.com/schemas/error", "TurnError");
5070
+ yield context.sendTraceActivity("OnTurnError Trace", error instanceof Error ? error.message : error, "https://www.botframework.com/schemas/error", "TurnError");
5047
5071
  // Send a message to the user
5048
5072
  yield context.sendActivity(`The bot encountered unhandled error: ${error.message}`);
5049
5073
  yield context.sendActivity("To continue to run this bot, please fix the bot source code.");