@microsoft/teamsfx 1.1.2-alpha.11f97f07d.0 → 1.1.2-alpha.16418f119.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.
@@ -31,6 +31,30 @@ var ErrorCode;
31
31
  * Channel is not supported error.
32
32
  */
33
33
  ErrorCode["ChannelNotSupported"] = "ChannelNotSupported";
34
+ /**
35
+ * Failed to retrieve sso token
36
+ */
37
+ ErrorCode["FailedToRetrieveSsoToken"] = "FailedToRetrieveSsoToken";
38
+ /**
39
+ * Failed to process sso handler
40
+ */
41
+ ErrorCode["FailedToProcessSsoHandler"] = "FailedToProcessSsoHandler";
42
+ /**
43
+ * Cannot find command
44
+ */
45
+ ErrorCode["CannotFindCommand"] = "CannotFindCommand";
46
+ /**
47
+ * Failed to run sso step
48
+ */
49
+ ErrorCode["FailedToRunSsoStep"] = "FailedToRunSsoStep";
50
+ /**
51
+ * Failed to run dedup step
52
+ */
53
+ ErrorCode["FailedToRunDedupStep"] = "FailedToRunDedupStep";
54
+ /**
55
+ * Sso activity handler is undefined
56
+ */
57
+ ErrorCode["SsoActivityHandlerIsUndefined"] = "SsoActivityHandlerIsUndefined";
34
58
  /**
35
59
  * Runtime is not supported error.
36
60
  */
@@ -86,6 +110,15 @@ ErrorMessage.NodejsRuntimeNotSupported = "{0} is not supported in Node.";
86
110
  ErrorMessage.FailToAcquireTokenOnBehalfOfUser = "Failed to acquire access token on behalf of user: {0}";
87
111
  // ChannelNotSupported Error
88
112
  ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
113
+ ErrorMessage.FailedToProcessSsoHandler = "Failed to process sso handler: {0}";
114
+ // FailedToRetrieveSsoToken Error
115
+ ErrorMessage.FailedToRetrieveSsoToken = "Failed to retrieve sso token, user failed to finish the AAD consent flow.";
116
+ // CannotFindCommand Error
117
+ ErrorMessage.CannotFindCommand = "Cannot find command: {0}";
118
+ ErrorMessage.FailedToRunSsoStep = "Failed to run dialog to retrieve sso token: {0}";
119
+ ErrorMessage.FailedToRunDedupStep = "Failed to run dialog to remove duplicated messages: {0}";
120
+ // SsoActivityHandlerIsUndefined Error
121
+ ErrorMessage.SsoActivityHandlerIsNull = "Sso command can only be used or added when sso activity handler is not undefined";
89
122
  // IdentityTypeNotSupported Error
90
123
  ErrorMessage.IdentityTypeNotSupported = "{0} identity is not supported in {1}";
91
124
  // AuthorizationInfoError
@@ -96,6 +129,7 @@ ErrorMessage.EmptyParameter = "Parameter {0} is empty";
96
129
  ErrorMessage.DuplicateHttpsOptionProperty = "Axios HTTPS agent already defined value for property {0}";
97
130
  ErrorMessage.DuplicateApiKeyInHeader = "The request already defined api key in request header with name {0}.";
98
131
  ErrorMessage.DuplicateApiKeyInQueryParam = "The request already defined api key in query parameter with name {0}.";
132
+ ErrorMessage.OnlySupportInQueryActivity = "The handleMessageExtensionQueryWithToken only support in handleTeamsMessagingExtensionQuery with composeExtension/query type.";
99
133
  /**
100
134
  * Error class with code and message thrown by the SDK.
101
135
  */
@@ -506,18 +540,19 @@ class TeamsUserCredential {
506
540
  * await credential.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
507
541
  * ```
508
542
  * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
543
+ * @param { string[] } resources - The optional list of resources for full trust Teams apps.
509
544
  *
510
545
  * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
511
546
  * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
512
547
  * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
513
548
  * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
514
549
  */
515
- async login(scopes) {
550
+ async login(scopes, resources) {
516
551
  validateScopesType(scopes);
517
552
  const scopesStr = typeof scopes === "string" ? scopes : scopes.join(" ");
518
553
  internalLogger.info(`Popup login page to get user's access token with scopes: ${scopesStr}`);
519
554
  if (!this.initialized) {
520
- await this.init();
555
+ await this.init(resources);
521
556
  }
522
557
  return new Promise((resolve, reject) => {
523
558
  microsoftTeams.initialize(() => {
@@ -569,6 +604,9 @@ class TeamsUserCredential {
569
604
  * Get access token from credential.
570
605
  *
571
606
  * Important: Access tokens are stored in sessionStorage, read more here: https://aka.ms/teamsfx-session-storage-notice
607
+ * Important: Full trust applications do not read the resource information from the webApplicationInfo section of the app
608
+ * manifest. Instead, this resource (along with any additional resources from which to request tokens) must be provided
609
+ * as a list of resources to the getToken() method through a GetTeamsUserTokenOptions object.
572
610
  *
573
611
  * @example
574
612
  * ```typescript
@@ -582,6 +620,9 @@ class TeamsUserCredential {
582
620
  * await credential.getToken("User.Read Application.Read.All") // Get Graph access token for multiple scopes using space-separated string
583
621
  * await credential.getToken("https://graph.microsoft.com/User.Read") // Get Graph access token with full resource URI
584
622
  * await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
623
+ *
624
+ * const options: GetTeamsUserTokenOptions = { resources: ["https://domain.example.com"] }; // set up resources for full trust apps.
625
+ * await credential.getToken([], options) // Get sso token from teams client - only use this approach for full trust apps.
585
626
  * ```
586
627
  *
587
628
  * @param {string | string[]} scopes - The list of scopes for which the token will have access.
@@ -598,8 +639,10 @@ class TeamsUserCredential {
598
639
  * Throw error if get access token failed.
599
640
  */
600
641
  async getToken(scopes, options) {
642
+ var _a;
601
643
  validateScopesType(scopes);
602
- const ssoToken = await this.getSSOToken();
644
+ const resources = (_a = options) === null || _a === void 0 ? void 0 : _a.resources;
645
+ const ssoToken = await this.getSSOToken(resources);
603
646
  const scopeStr = typeof scopes === "string" ? scopes : scopes.join(" ");
604
647
  if (scopeStr === "") {
605
648
  internalLogger.info("Get SSO token");
@@ -608,7 +651,7 @@ class TeamsUserCredential {
608
651
  else {
609
652
  internalLogger.info("Get access token with scopes: " + scopeStr);
610
653
  if (!this.initialized) {
611
- await this.init();
654
+ await this.init(resources);
612
655
  }
613
656
  let tokenResponse;
614
657
  const scopesArray = typeof scopes === "string" ? scopes.split(" ") : scopes;
@@ -654,6 +697,8 @@ class TeamsUserCredential {
654
697
  /**
655
698
  * Get basic user info from SSO token
656
699
  *
700
+ * @param {string[]} resources - The optional list of resources for full trust Teams apps.
701
+ *
657
702
  * @example
658
703
  * ```typescript
659
704
  * const currentUser = await credential.getUserInfo();
@@ -665,13 +710,13 @@ class TeamsUserCredential {
665
710
  *
666
711
  * @returns Basic user info with user displayName, objectId and preferredUserName.
667
712
  */
668
- async getUserInfo() {
713
+ async getUserInfo(resources) {
669
714
  internalLogger.info("Get basic user info from SSO token");
670
- const ssoToken = await this.getSSOToken();
715
+ const ssoToken = await this.getSSOToken(resources);
671
716
  return getUserInfoFromSsoToken(ssoToken.token);
672
717
  }
673
- async init() {
674
- const ssoToken = await this.getSSOToken();
718
+ async init(resources) {
719
+ const ssoToken = await this.getSSOToken(resources);
675
720
  const info = getTenantIdAndLoginHintFromSsoToken(ssoToken.token);
676
721
  this.loginHint = info.loginHint;
677
722
  this.tid = info.tid;
@@ -690,9 +735,12 @@ class TeamsUserCredential {
690
735
  /**
691
736
  * Get SSO token using teams SDK
692
737
  * It will try to get SSO token from memory first, if SSO token doesn't exist or about to expired, then it will using teams SDK to get SSO token
738
+ *
739
+ * @param {string[]} resources - The optional list of resources for full trust Teams apps.
740
+ *
693
741
  * @returns SSO token
694
742
  */
695
- getSSOToken() {
743
+ getSSOToken(resources) {
696
744
  return new Promise((resolve, reject) => {
697
745
  if (this.ssoToken) {
698
746
  if (this.ssoToken.expiresOnTimestamp - Date.now() > tokenRefreshTimeSpanInMillisecond) {
@@ -730,7 +778,7 @@ class TeamsUserCredential {
730
778
  internalLogger.error(errorMsg);
731
779
  reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
732
780
  },
733
- resources: [],
781
+ resources: resources !== null && resources !== void 0 ? resources : [],
734
782
  });
735
783
  });
736
784
  }
@@ -1247,8 +1295,9 @@ class TeamsFx {
1247
1295
  this.configuration = new Map();
1248
1296
  this.loadFromEnv();
1249
1297
  if (customConfig) {
1250
- for (const key of Object.keys(customConfig)) {
1251
- const value = customConfig[key];
1298
+ const myConfig = Object.assign({}, customConfig);
1299
+ for (const key of Object.keys(myConfig)) {
1300
+ const value = myConfig[key];
1252
1301
  if (value) {
1253
1302
  this.configuration.set(key, value);
1254
1303
  }
@@ -1296,11 +1345,11 @@ class TeamsFx {
1296
1345
  }
1297
1346
  return this.teamsUserCredential;
1298
1347
  }
1299
- async getUserInfo() {
1300
- return await this.getCredential().getUserInfo();
1348
+ async getUserInfo(resources) {
1349
+ return await this.getCredential().getUserInfo(resources);
1301
1350
  }
1302
- async login(scopes) {
1303
- await this.getCredential().login(scopes);
1351
+ async login(scopes, resources) {
1352
+ await this.getCredential().login(scopes, resources);
1304
1353
  }
1305
1354
  setSsoToken(ssoToken) {
1306
1355
  return this;
@@ -1423,6 +1472,47 @@ class ConversationBot {
1423
1472
  }
1424
1473
  }
1425
1474
 
1475
+ // Copyright (c) Microsoft Corporation.
1476
+ /*
1477
+ * Sso execution dialog, use to handle sso command
1478
+ */
1479
+ class BotSsoExecutionDialog {
1480
+ /**
1481
+ * Creates a new instance of the BotSsoExecutionDialog.
1482
+ * @param dedupStorage Helper storage to remove duplicated messages
1483
+ * @param requiredScopes The list of scopes for which the token will have access
1484
+ * @param teamsfx {@link TeamsFx} instance for authentication
1485
+ */
1486
+ constructor(dedupStorage, requiredScopes, teamsfx) {
1487
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "BotSsoExecutionDialog"), ErrorCode.RuntimeNotSupported);
1488
+ }
1489
+ /**
1490
+ * Add TeamsFxBotSsoCommandHandler instance
1491
+ * @param handler {@link BotSsoExecutionDialogHandler} callback function
1492
+ * @param triggerPatterns The trigger pattern
1493
+ */
1494
+ addCommand(handler, triggerPatterns) {
1495
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "BotSsoExecutionDialog"), ErrorCode.RuntimeNotSupported);
1496
+ }
1497
+ /**
1498
+ * The run method handles the incoming activity (in the form of a DialogContext) and passes it through the dialog system.
1499
+ *
1500
+ * @param context The context object for the current turn.
1501
+ * @param accessor The instance of StatePropertyAccessor for dialog system.
1502
+ */
1503
+ async run(context, accessor) {
1504
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "BotSsoExecutionDialog"), ErrorCode.RuntimeNotSupported);
1505
+ }
1506
+ /**
1507
+ * Called when the component is ending.
1508
+ *
1509
+ * @param context Context for the current turn of conversation.
1510
+ */
1511
+ async onEndDialog(context) {
1512
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "BotSsoExecutionDialog"), ErrorCode.RuntimeNotSupported);
1513
+ }
1514
+ }
1515
+
1426
1516
  // Copyright (c) Microsoft Corporation.
1427
1517
  /**
1428
1518
  * Send a plain text message to a notification target.
@@ -1632,6 +1722,14 @@ class TeamsBotInstallation {
1632
1722
  async members() {
1633
1723
  throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1634
1724
  }
1725
+ /**
1726
+ * Get team details from this bot installation
1727
+ *
1728
+ * @returns the team details if bot is installed into a team, otherwise returns undefined.
1729
+ */
1730
+ async getTeamDetails() {
1731
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1732
+ }
1635
1733
  }
1636
1734
  /**
1637
1735
  * Provide static utilities for bot notification.
@@ -1686,7 +1784,87 @@ class NotificationBot {
1686
1784
  static async installations() {
1687
1785
  throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "NotificationBot"), ErrorCode.RuntimeNotSupported);
1688
1786
  }
1689
- }
1787
+ /**
1788
+ * Returns the first {@link Member} where predicate is true, and undefined otherwise.
1789
+ *
1790
+ * @remarks
1791
+ * Only work on server side.
1792
+ *
1793
+ * @param predicate find calls predicate once for each member of the installation,
1794
+ * until it finds one where predicate returns true. If such a member is found, find
1795
+ * immediately returns that member. Otherwise, find returns undefined.
1796
+ * @param scope the scope to find members from the installations
1797
+ * (personal chat, group chat, Teams channel).
1798
+ * @returns the first {@link Member} where predicate is true, and undefined otherwise.
1799
+ */
1800
+ async findMember(predicate, scope) {
1801
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "NotificationBot"), ErrorCode.RuntimeNotSupported);
1802
+ }
1803
+ /**
1804
+ * Returns the first {@link Channel} where predicate is true, and undefined otherwise.
1805
+ *
1806
+ * @remarks
1807
+ * Only work on server side.
1808
+ *
1809
+ * @param predicate find calls predicate once for each channel of the installation,
1810
+ * until it finds one where predicate returns true. If such a channel is found, find
1811
+ * immediately returns that channel. Otherwise, find returns undefined.
1812
+ * @returns the first {@link Channel} where predicate is true, and undefined otherwise.
1813
+ */
1814
+ async findChannel(predicate) {
1815
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "NotificationBot"), ErrorCode.RuntimeNotSupported);
1816
+ }
1817
+ /**
1818
+ * Returns all {@link Member} where predicate is true, and empty array otherwise.
1819
+ *
1820
+ * @remarks
1821
+ * Only work on server side.
1822
+ *
1823
+ * @param predicate find calls predicate for each member of the installation.
1824
+ * @param scope the scope to find members from the installations
1825
+ * (personal chat, group chat, Teams channel).
1826
+ * @returns an array of {@link Member} where predicate is true, and empty array otherwise.
1827
+ */
1828
+ async findAllMembers(predicate, scope) {
1829
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "NotificationBot"), ErrorCode.RuntimeNotSupported);
1830
+ }
1831
+ /**
1832
+ * Returns all {@link Channel} where predicate is true, and empty array otherwise.
1833
+ *
1834
+ * @remarks
1835
+ * Only work on server side.
1836
+ *
1837
+ * @param predicate find calls predicate for each channel of the installation.
1838
+ * @returns an array of {@link Channel} where predicate is true, and empty array otherwise.
1839
+ */
1840
+ async findAllChannels(predicate) {
1841
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "NotificationBot"), ErrorCode.RuntimeNotSupported);
1842
+ }
1843
+ }
1844
+ /**
1845
+ * The search scope when calling {@link NotificationBot.findMember} and {@link NotificationBot.findAllMembers}.
1846
+ * The search scope is a flagged enum and it can be combined with `|`.
1847
+ * For example, to search from personal chat and group chat, use `SearchScope.Person | SearchScope.Group`.
1848
+ */
1849
+ var SearchScope;
1850
+ (function (SearchScope) {
1851
+ /**
1852
+ * Search members from the installations in personal chat only.
1853
+ */
1854
+ SearchScope[SearchScope["Person"] = 1] = "Person";
1855
+ /**
1856
+ * Search members from the installations in group chat only.
1857
+ */
1858
+ SearchScope[SearchScope["Group"] = 2] = "Group";
1859
+ /**
1860
+ * Search members from the installations in Teams channel only.
1861
+ */
1862
+ SearchScope[SearchScope["Channel"] = 4] = "Channel";
1863
+ /**
1864
+ * Search members from all installations including personal chat, group chat and Teams channel.
1865
+ */
1866
+ SearchScope[SearchScope["All"] = 7] = "All";
1867
+ })(SearchScope || (SearchScope = {}));
1690
1868
 
1691
1869
  // Copyright (c) Microsoft Corporation.
1692
1870
  /**
@@ -1727,6 +1905,22 @@ class CommandBot {
1727
1905
  registerCommands(commands) {
1728
1906
  throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandBot"), ErrorCode.RuntimeNotSupported);
1729
1907
  }
1908
+ /**
1909
+ * Registers a sso command into the command bot.
1910
+ *
1911
+ * @param command The command to register.
1912
+ */
1913
+ registerSsoCommand(ssoCommand) {
1914
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandBot"), ErrorCode.RuntimeNotSupported);
1915
+ }
1916
+ /**
1917
+ * Registers commands into the command bot.
1918
+ *
1919
+ * @param commands The commands to register.
1920
+ */
1921
+ registerSsoCommands(ssoCommands) {
1922
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandBot"), ErrorCode.RuntimeNotSupported);
1923
+ }
1730
1924
  }
1731
1925
 
1732
1926
  /**
@@ -1767,5 +1961,14 @@ class CardActionBot {
1767
1961
  }
1768
1962
  }
1769
1963
 
1770
- export { AdaptiveCardResponse, ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, CardActionBot, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, InvokeResponseErrorCode, LogLevel, Member, MsGraphAuthProvider, NotificationBot, NotificationTargetType, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
1964
+ /**
1965
+ * Users execute query with SSO or Access Token.
1966
+ * @remarks
1967
+ * Only works in in server side.
1968
+ */
1969
+ async function handleMessageExtensionQueryWithToken(context, config, scopes, logic) {
1970
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "queryWithToken in message extension"), ErrorCode.RuntimeNotSupported);
1971
+ }
1972
+
1973
+ export { AdaptiveCardResponse, ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, BotSsoExecutionDialog, CardActionBot, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, InvokeResponseErrorCode, LogLevel, Member, MsGraphAuthProvider, NotificationBot, NotificationTargetType, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, handleMessageExtensionQueryWithToken, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
1771
1974
  //# sourceMappingURL=index.esm2017.js.map