@microsoft/teamsfx 2.3.1-alpha.cea4e2840.0 → 2.3.1-alpha.da51b018b.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
  */
@@ -2668,7 +2669,8 @@ class NotificationMiddleware {
2668
2669
  */
2669
2670
  class LocalFileStorage {
2670
2671
  constructor(fileDir) {
2671
- this.localFileName = ".notification.localstore.json";
2672
+ var _a;
2673
+ this.localFileName = (_a = process.env.TEAMSFX_NOTIFICATION_STORE_FILENAME) !== null && _a !== void 0 ? _a : ".notification.localstore.json";
2672
2674
  this.filePath = path__namespace.resolve(fileDir, this.localFileName);
2673
2675
  }
2674
2676
  read(key) {
@@ -4030,9 +4032,9 @@ class MessageBuilder {
4030
4032
  * @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
4031
4033
  * @param {string | string[]} scopes - The list of scopes for which the token will have access.
4032
4034
  *
4033
- * @returns SignIn link CardAction with 200 status code.
4035
+ * @returns SignIn link SilentAuth CardAction with 200 status code.
4034
4036
  */
4035
- function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
4037
+ function getSignInResponseForMessageExtensionWithSilentAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
4036
4038
  const scopesArray = getScopesArray(scopes);
4037
4039
  const signInLink = `${initiateLoginEndpoint}?scope=${encodeURI(scopesArray.join(" "))}&clientId=${authConfig.clientId}&tenantId=${authConfig.tenantId}`;
4038
4040
  return {
@@ -4050,6 +4052,34 @@ function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiate
4050
4052
  },
4051
4053
  };
4052
4054
  }
4055
+ /**
4056
+ * Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions.
4057
+ * This method just a workaround for link unfurling now.
4058
+ *
4059
+ * @param {OnBehalfOfCredentialAuthConfig} authConfig - User custom the message extension authentication configuration.
4060
+ * @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
4061
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
4062
+ *
4063
+ * @returns SignIn link Auth CardAction with 200 status code.
4064
+ */
4065
+ function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
4066
+ const scopesArray = getScopesArray(scopes);
4067
+ const signInLink = `${initiateLoginEndpoint}?scope=${encodeURI(scopesArray.join(" "))}&clientId=${authConfig.clientId}&tenantId=${authConfig.tenantId}`;
4068
+ return {
4069
+ composeExtension: {
4070
+ type: "auth",
4071
+ suggestedActions: {
4072
+ actions: [
4073
+ {
4074
+ type: "openUrl",
4075
+ value: signInLink,
4076
+ title: "Message Extension OAuth",
4077
+ },
4078
+ ],
4079
+ },
4080
+ },
4081
+ };
4082
+ }
4053
4083
  /**
4054
4084
  * Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions.
4055
4085
  * This method only work on MessageExtension with Query now.
@@ -4099,7 +4129,7 @@ function executionWithTokenAndConfig(context, authConfig, initiateLoginEndpoint,
4099
4129
  const valueObj = context.activity.value;
4100
4130
  if (!valueObj.authentication || !valueObj.authentication.token) {
4101
4131
  internalLogger.verbose("No AccessToken in request, return silentAuth for AccessToken");
4102
- return getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes);
4132
+ return getSignInResponseForMessageExtensionWithSilentAuthConfig(authConfig, initiateLoginEndpoint, scopes);
4103
4133
  }
4104
4134
  try {
4105
4135
  const credential = new OnBehalfOfUserCredential(valueObj.authentication.token, authConfig);
@@ -4117,12 +4147,25 @@ function executionWithTokenAndConfig(context, authConfig, initiateLoginEndpoint,
4117
4147
  }
4118
4148
  }
4119
4149
  catch (err) {
4120
- if (err instanceof ErrorWithCode && err.code === exports.ErrorCode.UiRequiredError) {
4150
+ if (err instanceof ErrorWithCode &&
4151
+ err.code === exports.ErrorCode.UiRequiredError &&
4152
+ context.activity.name === "composeExtension/query") {
4121
4153
  internalLogger.verbose("User not consent yet, return 412 to user consent first.");
4122
4154
  const response = { status: 412 };
4123
4155
  yield context.sendActivity({ value: response, type: botbuilder.ActivityTypes.InvokeResponse });
4124
4156
  return;
4125
4157
  }
4158
+ else if (err instanceof ErrorWithCode &&
4159
+ err.code === exports.ErrorCode.UiRequiredError &&
4160
+ context.activity.name === "composeExtension/queryLink") {
4161
+ internalLogger.verbose("User not consent yet, return auth card for user login");
4162
+ const response = getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes);
4163
+ yield context.sendActivity({
4164
+ value: { status: 200, body: response },
4165
+ type: botbuilder.ActivityTypes.InvokeResponse,
4166
+ });
4167
+ return;
4168
+ }
4126
4169
  throw err;
4127
4170
  }
4128
4171
  });
@@ -4231,6 +4274,33 @@ function handleMessageExtensionQueryWithSSO(context, config, initiateLoginEndpoi
4231
4274
  }
4232
4275
  return yield executionWithTokenAndConfig(context, config !== null && config !== void 0 ? config : {}, initiateLoginEndpoint, scopes, logic);
4233
4276
  });
4277
+ }
4278
+ /**
4279
+ * Users execute link query in message extension with SSO or access token.
4280
+ *
4281
+ * @param {TurnContext} context - The context object for the current turn.
4282
+ * @param {OnBehalfOfCredentialAuthConfig} config - User custom the message extension authentication configuration.
4283
+ * @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
4284
+ * @param {string| string[]} scopes - The list of scopes for which the token will have access.
4285
+ * @param {function} logic - Business logic when executing the link query in message extension with SSO or access token.
4286
+ *
4287
+ * @throws {@link ErrorCode|InternalError} when User invoke not response to message extension link query.
4288
+ * @throws {@link ErrorCode|InternalError} when failed to get access token with unknown error.
4289
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
4290
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
4291
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
4292
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
4293
+ *
4294
+ * @returns A MessageExtension Response for the activity. If the logic not return any, return void instead.
4295
+ */
4296
+ function handleMessageExtensionLinkQueryWithSSO(context, config, initiateLoginEndpoint, scopes, logic) {
4297
+ return __awaiter(this, void 0, void 0, function* () {
4298
+ if (context.activity.name != "composeExtension/queryLink") {
4299
+ internalLogger.error(ErrorMessage.OnlySupportInLinkQueryActivity);
4300
+ throw new ErrorWithCode(formatString(ErrorMessage.OnlySupportInLinkQueryActivity), exports.ErrorCode.FailedOperation);
4301
+ }
4302
+ return yield executionWithTokenAndConfig(context, config !== null && config !== void 0 ? config : {}, initiateLoginEndpoint, scopes, logic);
4303
+ });
4234
4304
  }
4235
4305
 
4236
4306
  /**
@@ -5198,6 +5268,7 @@ exports.createPemCertOption = createPemCertOption;
5198
5268
  exports.createPfxCertOption = createPfxCertOption;
5199
5269
  exports.getLogLevel = getLogLevel;
5200
5270
  exports.getTediousConnectionConfig = getTediousConnectionConfig;
5271
+ exports.handleMessageExtensionLinkQueryWithSSO = handleMessageExtensionLinkQueryWithSSO;
5201
5272
  exports.handleMessageExtensionQueryWithSSO = handleMessageExtensionQueryWithSSO;
5202
5273
  exports.handleMessageExtensionQueryWithToken = handleMessageExtensionQueryWithToken;
5203
5274
  exports.sendAdaptiveCard = sendAdaptiveCard$1;