@microsoft/teamsfx 2.3.1-alpha.da822cd72.0 → 2.3.1-alpha.df8521401.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.
@@ -8,8 +8,8 @@ import { Dialog, ComponentDialog, WaterfallDialog, DialogSet, DialogTurnStatus }
8
8
  import { v4 } from 'uuid';
9
9
  import axios from 'axios';
10
10
  import { Agent } from 'https';
11
- import * as path from 'path';
12
- import * as fs from 'fs';
11
+ import { resolve } from 'path';
12
+ import { access, readFile, writeFile } from 'fs';
13
13
  import { AdaptiveCards } from '@microsoft/adaptivecards-tools';
14
14
 
15
15
  // Copyright (c) Microsoft Corporation.
@@ -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,8 +2562,9 @@ class NotificationMiddleware {
2559
2562
  */
2560
2563
  class LocalFileStorage {
2561
2564
  constructor(fileDir) {
2562
- this.localFileName = ".notification.localstore.json";
2563
- this.filePath = path.resolve(fileDir, this.localFileName);
2565
+ var _a;
2566
+ this.localFileName = (_a = process.env.TEAMSFX_NOTIFICATION_STORE_FILENAME) !== null && _a !== void 0 ? _a : ".notification.localstore.json";
2567
+ this.filePath = resolve(fileDir, this.localFileName);
2564
2568
  }
2565
2569
  async read(key) {
2566
2570
  if (!(await this.storeFileExists())) {
@@ -2596,7 +2600,7 @@ class LocalFileStorage {
2596
2600
  storeFileExists() {
2597
2601
  return new Promise((resolve) => {
2598
2602
  try {
2599
- fs.access(this.filePath, (err) => {
2603
+ access(this.filePath, (err) => {
2600
2604
  if (err) {
2601
2605
  resolve(false);
2602
2606
  }
@@ -2613,7 +2617,7 @@ class LocalFileStorage {
2613
2617
  readFromFile() {
2614
2618
  return new Promise((resolve, reject) => {
2615
2619
  try {
2616
- fs.readFile(this.filePath, { encoding: "utf-8" }, (err, rawData) => {
2620
+ readFile(this.filePath, { encoding: "utf-8" }, (err, rawData) => {
2617
2621
  if (err) {
2618
2622
  reject(err);
2619
2623
  }
@@ -2631,7 +2635,7 @@ class LocalFileStorage {
2631
2635
  return new Promise((resolve, reject) => {
2632
2636
  try {
2633
2637
  const rawData = JSON.stringify(data, undefined, 2);
2634
- fs.writeFile(this.filePath, rawData, { encoding: "utf-8" }, (err) => {
2638
+ writeFile(this.filePath, rawData, { encoding: "utf-8" }, (err) => {
2635
2639
  if (err) {
2636
2640
  reject(err);
2637
2641
  }
@@ -3062,7 +3066,7 @@ class NotificationBot$1 {
3062
3066
  */
3063
3067
  constructor(adapter, options) {
3064
3068
  var _a, _b;
3065
- const storage = (_a = options === null || options === void 0 ? void 0 : options.storage) !== null && _a !== void 0 ? _a : new LocalFileStorage(path.resolve(process.env.RUNNING_ON_AZURE === "1" ? (_b = process.env.TEMP) !== null && _b !== void 0 ? _b : "./" : "./"));
3069
+ const storage = (_a = options === null || options === void 0 ? void 0 : options.storage) !== null && _a !== void 0 ? _a : new LocalFileStorage(resolve(process.env.RUNNING_ON_AZURE === "1" ? (_b = process.env.TEMP) !== null && _b !== void 0 ? _b : "./" : "./"));
3066
3070
  this.conversationReferenceStore = new DefaultConversationReferenceStore(storage);
3067
3071
  this.adapter = adapter.use(new NotificationMiddleware({
3068
3072
  conversationReferenceStore: this.conversationReferenceStore,
@@ -3223,7 +3227,7 @@ var SearchScope$1;
3223
3227
  SearchScope[SearchScope["All"] = 7] = "All";
3224
3228
  })(SearchScope$1 || (SearchScope$1 = {}));
3225
3229
 
3226
- /******************************************************************************
3230
+ /*! *****************************************************************************
3227
3231
  Copyright (c) Microsoft Corporation.
3228
3232
 
3229
3233
  Permission to use, copy, modify, and/or distribute this software for any
@@ -3248,12 +3252,7 @@ function __rest(s, e) {
3248
3252
  t[p[i]] = s[p[i]];
3249
3253
  }
3250
3254
  return t;
3251
- }
3252
-
3253
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
3254
- var e = new Error(message);
3255
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
3256
- };
3255
+ }
3257
3256
 
3258
3257
  // Copyright (c) Microsoft Corporation.
3259
3258
  let DIALOG_NAME = "BotSsoExecutionDialog";
@@ -3884,9 +3883,9 @@ class MessageBuilder {
3884
3883
  * @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
3885
3884
  * @param {string | string[]} scopes - The list of scopes for which the token will have access.
3886
3885
  *
3887
- * @returns SignIn link CardAction with 200 status code.
3886
+ * @returns SignIn link SilentAuth CardAction with 200 status code.
3888
3887
  */
3889
- function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
3888
+ function getSignInResponseForMessageExtensionWithSilentAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
3890
3889
  const scopesArray = getScopesArray(scopes);
3891
3890
  const signInLink = `${initiateLoginEndpoint}?scope=${encodeURI(scopesArray.join(" "))}&clientId=${authConfig.clientId}&tenantId=${authConfig.tenantId}`;
3892
3891
  return {
@@ -3904,6 +3903,34 @@ function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiate
3904
3903
  },
3905
3904
  };
3906
3905
  }
3906
+ /**
3907
+ * Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions.
3908
+ * This method just a workaround for link unfurling now.
3909
+ *
3910
+ * @param {OnBehalfOfCredentialAuthConfig} authConfig - User custom the message extension authentication configuration.
3911
+ * @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
3912
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
3913
+ *
3914
+ * @returns SignIn link Auth CardAction with 200 status code.
3915
+ */
3916
+ function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
3917
+ const scopesArray = getScopesArray(scopes);
3918
+ const signInLink = `${initiateLoginEndpoint}?scope=${encodeURI(scopesArray.join(" "))}&clientId=${authConfig.clientId}&tenantId=${authConfig.tenantId}`;
3919
+ return {
3920
+ composeExtension: {
3921
+ type: "auth",
3922
+ suggestedActions: {
3923
+ actions: [
3924
+ {
3925
+ type: "openUrl",
3926
+ value: signInLink,
3927
+ title: "Message Extension OAuth",
3928
+ },
3929
+ ],
3930
+ },
3931
+ },
3932
+ };
3933
+ }
3907
3934
  /**
3908
3935
  * Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions.
3909
3936
  * This method only work on MessageExtension with Query now.
@@ -3952,7 +3979,7 @@ async function executionWithTokenAndConfig(context, authConfig, initiateLoginEnd
3952
3979
  const valueObj = context.activity.value;
3953
3980
  if (!valueObj.authentication || !valueObj.authentication.token) {
3954
3981
  internalLogger.verbose("No AccessToken in request, return silentAuth for AccessToken");
3955
- return getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes);
3982
+ return getSignInResponseForMessageExtensionWithSilentAuthConfig(authConfig, initiateLoginEndpoint, scopes);
3956
3983
  }
3957
3984
  try {
3958
3985
  const credential = new OnBehalfOfUserCredential(valueObj.authentication.token, authConfig);
@@ -3970,12 +3997,25 @@ async function executionWithTokenAndConfig(context, authConfig, initiateLoginEnd
3970
3997
  }
3971
3998
  }
3972
3999
  catch (err) {
3973
- if (err instanceof ErrorWithCode && err.code === ErrorCode.UiRequiredError) {
4000
+ if (err instanceof ErrorWithCode &&
4001
+ err.code === ErrorCode.UiRequiredError &&
4002
+ context.activity.name === "composeExtension/query") {
3974
4003
  internalLogger.verbose("User not consent yet, return 412 to user consent first.");
3975
4004
  const response = { status: 412 };
3976
4005
  await context.sendActivity({ value: response, type: ActivityTypes.InvokeResponse });
3977
4006
  return;
3978
4007
  }
4008
+ else if (err instanceof ErrorWithCode &&
4009
+ err.code === ErrorCode.UiRequiredError &&
4010
+ context.activity.name === "composeExtension/queryLink") {
4011
+ internalLogger.verbose("User not consent yet, return auth card for user login");
4012
+ const response = getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes);
4013
+ await context.sendActivity({
4014
+ value: { status: 200, body: response },
4015
+ type: ActivityTypes.InvokeResponse,
4016
+ });
4017
+ return;
4018
+ }
3979
4019
  throw err;
3980
4020
  }
3981
4021
  }
@@ -4077,6 +4117,31 @@ async function handleMessageExtensionQueryWithSSO(context, config, initiateLogin
4077
4117
  throw new ErrorWithCode(formatString(ErrorMessage.OnlySupportInQueryActivity), ErrorCode.FailedOperation);
4078
4118
  }
4079
4119
  return await executionWithTokenAndConfig(context, config !== null && config !== void 0 ? config : {}, initiateLoginEndpoint, scopes, logic);
4120
+ }
4121
+ /**
4122
+ * Users execute link query in message extension with SSO or access token.
4123
+ *
4124
+ * @param {TurnContext} context - The context object for the current turn.
4125
+ * @param {OnBehalfOfCredentialAuthConfig} config - User custom the message extension authentication configuration.
4126
+ * @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
4127
+ * @param {string| string[]} scopes - The list of scopes for which the token will have access.
4128
+ * @param {function} logic - Business logic when executing the link query in message extension with SSO or access token.
4129
+ *
4130
+ * @throws {@link ErrorCode|InternalError} when User invoke not response to message extension link query.
4131
+ * @throws {@link ErrorCode|InternalError} when failed to get access token with unknown error.
4132
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
4133
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
4134
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
4135
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
4136
+ *
4137
+ * @returns A MessageExtension Response for the activity. If the logic not return any, return void instead.
4138
+ */
4139
+ async function handleMessageExtensionLinkQueryWithSSO(context, config, initiateLoginEndpoint, scopes, logic) {
4140
+ if (context.activity.name != "composeExtension/queryLink") {
4141
+ internalLogger.error(ErrorMessage.OnlySupportInLinkQueryActivity);
4142
+ throw new ErrorWithCode(formatString(ErrorMessage.OnlySupportInLinkQueryActivity), ErrorCode.FailedOperation);
4143
+ }
4144
+ return await executionWithTokenAndConfig(context, config !== null && config !== void 0 ? config : {}, initiateLoginEndpoint, scopes, logic);
4080
4145
  }
4081
4146
 
4082
4147
  /**
@@ -4594,7 +4659,7 @@ class NotificationBot {
4594
4659
  this.conversationReferenceStore = options.store;
4595
4660
  }
4596
4661
  else {
4597
- const storage = (_a = options === null || options === void 0 ? void 0 : options.storage) !== null && _a !== void 0 ? _a : new LocalFileStorage(path.resolve(process.env.RUNNING_ON_AZURE === "1" ? (_b = process.env.TEMP) !== null && _b !== void 0 ? _b : "./" : "./"));
4662
+ const storage = (_a = options === null || options === void 0 ? void 0 : options.storage) !== null && _a !== void 0 ? _a : new LocalFileStorage(resolve(process.env.RUNNING_ON_AZURE === "1" ? (_b = process.env.TEMP) !== null && _b !== void 0 ? _b : "./" : "./"));
4598
4663
  this.conversationReferenceStore = new DefaultConversationReferenceStore(storage);
4599
4664
  }
4600
4665
  this.adapter = adapter.use(new NotificationMiddleware({
@@ -4977,5 +5042,5 @@ var conversationWithCloudAdapter = /*#__PURE__*/Object.freeze({
4977
5042
  CardActionBot: CardActionBot
4978
5043
  });
4979
5044
 
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 };
5045
+ 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
5046
  //# sourceMappingURL=index.esm2017.mjs.map