@microsoft/teamsfx 2.3.1-alpha.caf90521c.0 → 2.3.1-alpha.cfa4f4721.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.
@@ -138,6 +138,7 @@ ErrorMessage.DuplicateHttpsOptionProperty = "Axios HTTPS agent already defined v
138
138
  ErrorMessage.DuplicateApiKeyInHeader = "The request already defined api key in request header with name {0}.";
139
139
  ErrorMessage.DuplicateApiKeyInQueryParam = "The request already defined api key in query parameter with name {0}.";
140
140
  ErrorMessage.OnlySupportInQueryActivity = "The handleMessageExtensionQueryWithToken only support in handleTeamsMessagingExtensionQuery with composeExtension/query type.";
141
+ ErrorMessage.OnlySupportInLinkQueryActivity = "The handleMessageExtensionLinkQueryWithSSO only support in handleTeamsAppBasedLinkQuery with composeExtension/queryLink type.";
141
142
  /**
142
143
  * Error class with code and message thrown by the SDK.
143
144
  */
@@ -1474,7 +1475,7 @@ function createApiClient(apiEndpoint, authProvider) {
1474
1475
  baseURL: apiEndpoint,
1475
1476
  });
1476
1477
  instance.interceptors.request.use(async function (config) {
1477
- return await authProvider.AddAuthenticationInfo(config);
1478
+ return (await authProvider.AddAuthenticationInfo(config));
1478
1479
  });
1479
1480
  return instance;
1480
1481
  }
@@ -2534,7 +2535,7 @@ class NotificationMiddleware {
2534
2535
  return ActivityType.Unknown;
2535
2536
  }
2536
2537
  async tryAddMessagedReference(context) {
2537
- var _a, _b, _c, _d;
2538
+ var _a, _b, _c, _d, _e, _f;
2538
2539
  const reference = TurnContext.getConversationReference(context.activity);
2539
2540
  const conversationType = (_a = reference === null || reference === void 0 ? void 0 : reference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
2540
2541
  if (conversationType === "personal" || conversationType === "groupChat") {
@@ -2542,7 +2543,9 @@ class NotificationMiddleware {
2542
2543
  }
2543
2544
  else if (conversationType === "channel") {
2544
2545
  const teamId = (_d = (_c = (_b = context.activity) === null || _b === void 0 ? void 0 : _b.channelData) === null || _c === void 0 ? void 0 : _c.team) === null || _d === void 0 ? void 0 : _d.id;
2545
- if (teamId !== undefined) {
2546
+ const channelId = (_f = (_e = context.activity.channelData) === null || _e === void 0 ? void 0 : _e.channel) === null || _f === void 0 ? void 0 : _f.id;
2547
+ // `teamId === channelId` means General channel. Ignore messaging in non-General channel.
2548
+ if (teamId !== undefined && (channelId === undefined || teamId === channelId)) {
2546
2549
  const teamReference = cloneConversation(reference);
2547
2550
  teamReference.conversation.id = teamId;
2548
2551
  await this.conversationReferenceStore.add(getKey(teamReference), teamReference, {
@@ -2559,7 +2562,8 @@ class NotificationMiddleware {
2559
2562
  */
2560
2563
  class LocalFileStorage {
2561
2564
  constructor(fileDir) {
2562
- this.localFileName = ".notification.localstore.json";
2565
+ var _a;
2566
+ this.localFileName = (_a = process.env.TEAMSFX_NOTIFICATION_STORE_FILENAME) !== null && _a !== void 0 ? _a : ".notification.localstore.json";
2563
2567
  this.filePath = path.resolve(fileDir, this.localFileName);
2564
2568
  }
2565
2569
  async read(key) {
@@ -3884,9 +3888,9 @@ class MessageBuilder {
3884
3888
  * @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
3885
3889
  * @param {string | string[]} scopes - The list of scopes for which the token will have access.
3886
3890
  *
3887
- * @returns SignIn link CardAction with 200 status code.
3891
+ * @returns SignIn link SilentAuth CardAction with 200 status code.
3888
3892
  */
3889
- function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
3893
+ function getSignInResponseForMessageExtensionWithSilentAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
3890
3894
  const scopesArray = getScopesArray(scopes);
3891
3895
  const signInLink = `${initiateLoginEndpoint}?scope=${encodeURI(scopesArray.join(" "))}&clientId=${authConfig.clientId}&tenantId=${authConfig.tenantId}`;
3892
3896
  return {
@@ -3904,6 +3908,34 @@ function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiate
3904
3908
  },
3905
3909
  };
3906
3910
  }
3911
+ /**
3912
+ * Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions.
3913
+ * This method just a workaround for link unfurling now.
3914
+ *
3915
+ * @param {OnBehalfOfCredentialAuthConfig} authConfig - User custom the message extension authentication configuration.
3916
+ * @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
3917
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
3918
+ *
3919
+ * @returns SignIn link Auth CardAction with 200 status code.
3920
+ */
3921
+ function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
3922
+ const scopesArray = getScopesArray(scopes);
3923
+ const signInLink = `${initiateLoginEndpoint}?scope=${encodeURI(scopesArray.join(" "))}&clientId=${authConfig.clientId}&tenantId=${authConfig.tenantId}`;
3924
+ return {
3925
+ composeExtension: {
3926
+ type: "auth",
3927
+ suggestedActions: {
3928
+ actions: [
3929
+ {
3930
+ type: "openUrl",
3931
+ value: signInLink,
3932
+ title: "Message Extension OAuth",
3933
+ },
3934
+ ],
3935
+ },
3936
+ },
3937
+ };
3938
+ }
3907
3939
  /**
3908
3940
  * Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions.
3909
3941
  * This method only work on MessageExtension with Query now.
@@ -3952,7 +3984,7 @@ async function executionWithTokenAndConfig(context, authConfig, initiateLoginEnd
3952
3984
  const valueObj = context.activity.value;
3953
3985
  if (!valueObj.authentication || !valueObj.authentication.token) {
3954
3986
  internalLogger.verbose("No AccessToken in request, return silentAuth for AccessToken");
3955
- return getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes);
3987
+ return getSignInResponseForMessageExtensionWithSilentAuthConfig(authConfig, initiateLoginEndpoint, scopes);
3956
3988
  }
3957
3989
  try {
3958
3990
  const credential = new OnBehalfOfUserCredential(valueObj.authentication.token, authConfig);
@@ -3970,12 +4002,25 @@ async function executionWithTokenAndConfig(context, authConfig, initiateLoginEnd
3970
4002
  }
3971
4003
  }
3972
4004
  catch (err) {
3973
- if (err instanceof ErrorWithCode && err.code === ErrorCode.UiRequiredError) {
4005
+ if (err instanceof ErrorWithCode &&
4006
+ err.code === ErrorCode.UiRequiredError &&
4007
+ context.activity.name === "composeExtension/query") {
3974
4008
  internalLogger.verbose("User not consent yet, return 412 to user consent first.");
3975
4009
  const response = { status: 412 };
3976
4010
  await context.sendActivity({ value: response, type: ActivityTypes.InvokeResponse });
3977
4011
  return;
3978
4012
  }
4013
+ else if (err instanceof ErrorWithCode &&
4014
+ err.code === ErrorCode.UiRequiredError &&
4015
+ context.activity.name === "composeExtension/queryLink") {
4016
+ internalLogger.verbose("User not consent yet, return auth card for user login");
4017
+ const response = getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes);
4018
+ await context.sendActivity({
4019
+ value: { status: 200, body: response },
4020
+ type: ActivityTypes.InvokeResponse,
4021
+ });
4022
+ return;
4023
+ }
3979
4024
  throw err;
3980
4025
  }
3981
4026
  }
@@ -4077,6 +4122,31 @@ async function handleMessageExtensionQueryWithSSO(context, config, initiateLogin
4077
4122
  throw new ErrorWithCode(formatString(ErrorMessage.OnlySupportInQueryActivity), ErrorCode.FailedOperation);
4078
4123
  }
4079
4124
  return await executionWithTokenAndConfig(context, config !== null && config !== void 0 ? config : {}, initiateLoginEndpoint, scopes, logic);
4125
+ }
4126
+ /**
4127
+ * Users execute link query in message extension with SSO or access token.
4128
+ *
4129
+ * @param {TurnContext} context - The context object for the current turn.
4130
+ * @param {OnBehalfOfCredentialAuthConfig} config - User custom the message extension authentication configuration.
4131
+ * @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
4132
+ * @param {string| string[]} scopes - The list of scopes for which the token will have access.
4133
+ * @param {function} logic - Business logic when executing the link query in message extension with SSO or access token.
4134
+ *
4135
+ * @throws {@link ErrorCode|InternalError} when User invoke not response to message extension link query.
4136
+ * @throws {@link ErrorCode|InternalError} when failed to get access token with unknown error.
4137
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
4138
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
4139
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
4140
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
4141
+ *
4142
+ * @returns A MessageExtension Response for the activity. If the logic not return any, return void instead.
4143
+ */
4144
+ async function handleMessageExtensionLinkQueryWithSSO(context, config, initiateLoginEndpoint, scopes, logic) {
4145
+ if (context.activity.name != "composeExtension/queryLink") {
4146
+ internalLogger.error(ErrorMessage.OnlySupportInLinkQueryActivity);
4147
+ throw new ErrorWithCode(formatString(ErrorMessage.OnlySupportInLinkQueryActivity), ErrorCode.FailedOperation);
4148
+ }
4149
+ return await executionWithTokenAndConfig(context, config !== null && config !== void 0 ? config : {}, initiateLoginEndpoint, scopes, logic);
4080
4150
  }
4081
4151
 
4082
4152
  /**
@@ -4977,5 +5047,5 @@ var conversationWithCloudAdapter = /*#__PURE__*/Object.freeze({
4977
5047
  CardActionBot: CardActionBot
4978
5048
  });
4979
5049
 
4980
- export { AdaptiveCardResponse, ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, conversationWithCloudAdapter as BotBuilderCloudAdapter, BotSsoExecutionDialog, CardActionBot$1 as CardActionBot, CertificateAuthProvider, Channel$1 as Channel, CommandBot$1 as CommandBot, ConversationBot$1 as ConversationBot, ErrorCode, ErrorWithCode, IdentityType, InvokeResponseErrorCode, InvokeResponseFactory, LogLevel, Member$1 as Member, MessageBuilder, MsGraphAuthProvider, NotificationBot$1 as NotificationBot, NotificationTargetType, OnBehalfOfUserCredential, SearchScope$1 as SearchScope, TeamsBotInstallation$1 as TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createMicrosoftGraphClientWithCredential, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, handleMessageExtensionQueryWithSSO, handleMessageExtensionQueryWithToken, sendAdaptiveCard$1 as sendAdaptiveCard, sendMessage$1 as sendMessage, setLogFunction, setLogLevel, setLogger };
5050
+ export { AdaptiveCardResponse, ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, conversationWithCloudAdapter as BotBuilderCloudAdapter, BotSsoExecutionDialog, CardActionBot$1 as CardActionBot, CertificateAuthProvider, Channel$1 as Channel, CommandBot$1 as CommandBot, ConversationBot$1 as ConversationBot, ErrorCode, ErrorWithCode, IdentityType, InvokeResponseErrorCode, InvokeResponseFactory, LogLevel, Member$1 as Member, MessageBuilder, MsGraphAuthProvider, NotificationBot$1 as NotificationBot, NotificationTargetType, OnBehalfOfUserCredential, SearchScope$1 as SearchScope, TeamsBotInstallation$1 as TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createMicrosoftGraphClientWithCredential, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, handleMessageExtensionLinkQueryWithSSO, handleMessageExtensionQueryWithSSO, handleMessageExtensionQueryWithToken, sendAdaptiveCard$1 as sendAdaptiveCard, sendMessage$1 as sendMessage, setLogFunction, setLogLevel, setLogger };
4981
5051
  //# sourceMappingURL=index.esm2017.mjs.map