@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.
@@ -167,6 +167,7 @@ ErrorMessage.DuplicateHttpsOptionProperty = "Axios HTTPS agent already defined v
167
167
  ErrorMessage.DuplicateApiKeyInHeader = "The request already defined api key in request header with name {0}.";
168
168
  ErrorMessage.DuplicateApiKeyInQueryParam = "The request already defined api key in query parameter with name {0}.";
169
169
  ErrorMessage.OnlySupportInQueryActivity = "The handleMessageExtensionQueryWithToken only support in handleTeamsMessagingExtensionQuery with composeExtension/query type.";
170
+ ErrorMessage.OnlySupportInLinkQueryActivity = "The handleMessageExtensionLinkQueryWithSSO only support in handleTeamsAppBasedLinkQuery with composeExtension/queryLink type.";
170
171
  /**
171
172
  * Error class with code and message thrown by the SDK.
172
173
  */
@@ -1564,7 +1565,7 @@ function createApiClient(apiEndpoint, authProvider) {
1564
1565
  });
1565
1566
  instance.interceptors.request.use(function (config) {
1566
1567
  return __awaiter(this, void 0, void 0, function* () {
1567
- return yield authProvider.AddAuthenticationInfo(config);
1568
+ return (yield authProvider.AddAuthenticationInfo(config));
1568
1569
  });
1569
1570
  });
1570
1571
  return instance;
@@ -2641,7 +2642,7 @@ class NotificationMiddleware {
2641
2642
  return ActivityType.Unknown;
2642
2643
  }
2643
2644
  tryAddMessagedReference(context) {
2644
- var _a, _b, _c, _d;
2645
+ var _a, _b, _c, _d, _e, _f;
2645
2646
  return __awaiter(this, void 0, void 0, function* () {
2646
2647
  const reference = botbuilder.TurnContext.getConversationReference(context.activity);
2647
2648
  const conversationType = (_a = reference === null || reference === void 0 ? void 0 : reference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
@@ -2650,7 +2651,9 @@ class NotificationMiddleware {
2650
2651
  }
2651
2652
  else if (conversationType === "channel") {
2652
2653
  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;
2653
- if (teamId !== undefined) {
2654
+ const channelId = (_f = (_e = context.activity.channelData) === null || _e === void 0 ? void 0 : _e.channel) === null || _f === void 0 ? void 0 : _f.id;
2655
+ // `teamId === channelId` means General channel. Ignore messaging in non-General channel.
2656
+ if (teamId !== undefined && (channelId === undefined || teamId === channelId)) {
2654
2657
  const teamReference = cloneConversation(reference);
2655
2658
  teamReference.conversation.id = teamId;
2656
2659
  yield this.conversationReferenceStore.add(getKey(teamReference), teamReference, {
@@ -2668,7 +2671,8 @@ class NotificationMiddleware {
2668
2671
  */
2669
2672
  class LocalFileStorage {
2670
2673
  constructor(fileDir) {
2671
- this.localFileName = ".notification.localstore.json";
2674
+ var _a;
2675
+ this.localFileName = (_a = process.env.TEAMSFX_NOTIFICATION_STORE_FILENAME) !== null && _a !== void 0 ? _a : ".notification.localstore.json";
2672
2676
  this.filePath = path__namespace.resolve(fileDir, this.localFileName);
2673
2677
  }
2674
2678
  read(key) {
@@ -4030,9 +4034,9 @@ class MessageBuilder {
4030
4034
  * @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
4031
4035
  * @param {string | string[]} scopes - The list of scopes for which the token will have access.
4032
4036
  *
4033
- * @returns SignIn link CardAction with 200 status code.
4037
+ * @returns SignIn link SilentAuth CardAction with 200 status code.
4034
4038
  */
4035
- function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
4039
+ function getSignInResponseForMessageExtensionWithSilentAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
4036
4040
  const scopesArray = getScopesArray(scopes);
4037
4041
  const signInLink = `${initiateLoginEndpoint}?scope=${encodeURI(scopesArray.join(" "))}&clientId=${authConfig.clientId}&tenantId=${authConfig.tenantId}`;
4038
4042
  return {
@@ -4050,6 +4054,34 @@ function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiate
4050
4054
  },
4051
4055
  };
4052
4056
  }
4057
+ /**
4058
+ * Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions.
4059
+ * This method just a workaround for link unfurling now.
4060
+ *
4061
+ * @param {OnBehalfOfCredentialAuthConfig} authConfig - User custom the message extension authentication configuration.
4062
+ * @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
4063
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
4064
+ *
4065
+ * @returns SignIn link Auth CardAction with 200 status code.
4066
+ */
4067
+ function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
4068
+ const scopesArray = getScopesArray(scopes);
4069
+ const signInLink = `${initiateLoginEndpoint}?scope=${encodeURI(scopesArray.join(" "))}&clientId=${authConfig.clientId}&tenantId=${authConfig.tenantId}`;
4070
+ return {
4071
+ composeExtension: {
4072
+ type: "auth",
4073
+ suggestedActions: {
4074
+ actions: [
4075
+ {
4076
+ type: "openUrl",
4077
+ value: signInLink,
4078
+ title: "Message Extension OAuth",
4079
+ },
4080
+ ],
4081
+ },
4082
+ },
4083
+ };
4084
+ }
4053
4085
  /**
4054
4086
  * Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions.
4055
4087
  * This method only work on MessageExtension with Query now.
@@ -4099,7 +4131,7 @@ function executionWithTokenAndConfig(context, authConfig, initiateLoginEndpoint,
4099
4131
  const valueObj = context.activity.value;
4100
4132
  if (!valueObj.authentication || !valueObj.authentication.token) {
4101
4133
  internalLogger.verbose("No AccessToken in request, return silentAuth for AccessToken");
4102
- return getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes);
4134
+ return getSignInResponseForMessageExtensionWithSilentAuthConfig(authConfig, initiateLoginEndpoint, scopes);
4103
4135
  }
4104
4136
  try {
4105
4137
  const credential = new OnBehalfOfUserCredential(valueObj.authentication.token, authConfig);
@@ -4117,12 +4149,25 @@ function executionWithTokenAndConfig(context, authConfig, initiateLoginEndpoint,
4117
4149
  }
4118
4150
  }
4119
4151
  catch (err) {
4120
- if (err instanceof ErrorWithCode && err.code === exports.ErrorCode.UiRequiredError) {
4152
+ if (err instanceof ErrorWithCode &&
4153
+ err.code === exports.ErrorCode.UiRequiredError &&
4154
+ context.activity.name === "composeExtension/query") {
4121
4155
  internalLogger.verbose("User not consent yet, return 412 to user consent first.");
4122
4156
  const response = { status: 412 };
4123
4157
  yield context.sendActivity({ value: response, type: botbuilder.ActivityTypes.InvokeResponse });
4124
4158
  return;
4125
4159
  }
4160
+ else if (err instanceof ErrorWithCode &&
4161
+ err.code === exports.ErrorCode.UiRequiredError &&
4162
+ context.activity.name === "composeExtension/queryLink") {
4163
+ internalLogger.verbose("User not consent yet, return auth card for user login");
4164
+ const response = getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes);
4165
+ yield context.sendActivity({
4166
+ value: { status: 200, body: response },
4167
+ type: botbuilder.ActivityTypes.InvokeResponse,
4168
+ });
4169
+ return;
4170
+ }
4126
4171
  throw err;
4127
4172
  }
4128
4173
  });
@@ -4231,6 +4276,33 @@ function handleMessageExtensionQueryWithSSO(context, config, initiateLoginEndpoi
4231
4276
  }
4232
4277
  return yield executionWithTokenAndConfig(context, config !== null && config !== void 0 ? config : {}, initiateLoginEndpoint, scopes, logic);
4233
4278
  });
4279
+ }
4280
+ /**
4281
+ * Users execute link query in message extension with SSO or access token.
4282
+ *
4283
+ * @param {TurnContext} context - The context object for the current turn.
4284
+ * @param {OnBehalfOfCredentialAuthConfig} config - User custom the message extension authentication configuration.
4285
+ * @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
4286
+ * @param {string| string[]} scopes - The list of scopes for which the token will have access.
4287
+ * @param {function} logic - Business logic when executing the link query in message extension with SSO or access token.
4288
+ *
4289
+ * @throws {@link ErrorCode|InternalError} when User invoke not response to message extension link query.
4290
+ * @throws {@link ErrorCode|InternalError} when failed to get access token with unknown error.
4291
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
4292
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
4293
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
4294
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
4295
+ *
4296
+ * @returns A MessageExtension Response for the activity. If the logic not return any, return void instead.
4297
+ */
4298
+ function handleMessageExtensionLinkQueryWithSSO(context, config, initiateLoginEndpoint, scopes, logic) {
4299
+ return __awaiter(this, void 0, void 0, function* () {
4300
+ if (context.activity.name != "composeExtension/queryLink") {
4301
+ internalLogger.error(ErrorMessage.OnlySupportInLinkQueryActivity);
4302
+ throw new ErrorWithCode(formatString(ErrorMessage.OnlySupportInLinkQueryActivity), exports.ErrorCode.FailedOperation);
4303
+ }
4304
+ return yield executionWithTokenAndConfig(context, config !== null && config !== void 0 ? config : {}, initiateLoginEndpoint, scopes, logic);
4305
+ });
4234
4306
  }
4235
4307
 
4236
4308
  /**
@@ -5198,6 +5270,7 @@ exports.createPemCertOption = createPemCertOption;
5198
5270
  exports.createPfxCertOption = createPfxCertOption;
5199
5271
  exports.getLogLevel = getLogLevel;
5200
5272
  exports.getTediousConnectionConfig = getTediousConnectionConfig;
5273
+ exports.handleMessageExtensionLinkQueryWithSSO = handleMessageExtensionLinkQueryWithSSO;
5201
5274
  exports.handleMessageExtensionQueryWithSSO = handleMessageExtensionQueryWithSSO;
5202
5275
  exports.handleMessageExtensionQueryWithToken = handleMessageExtensionQueryWithToken;
5203
5276
  exports.sendAdaptiveCard = sendAdaptiveCard$1;