@microsoft/teamsfx 2.2.3-alpha.0237b70e3.0 → 2.2.3-alpha.13d1e618d.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.
@@ -854,7 +854,7 @@ class MsGraphAuthProvider {
854
854
  * };
855
855
  * const prompt = new TeamsBotSsoPrompt(dialogId, {
856
856
  * config: config
857
- * scopes: '["User.Read"],
857
+ * scopes: ["User.Read"],
858
858
  * });
859
859
  * this.addDialog(prompt);
860
860
  *
@@ -1584,19 +1584,17 @@ class BasicAuthProvider {
1584
1584
  * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1585
1585
  */
1586
1586
  AddAuthenticationInfo(config) {
1587
- return tslib.__awaiter(this, void 0, void 0, function* () {
1588
- if (config.headers && config.headers["Authorization"]) {
1589
- throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1590
- }
1591
- if (config.auth) {
1592
- throw new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1593
- }
1594
- config.auth = {
1595
- username: this.userName,
1596
- password: this.password,
1597
- };
1598
- return config;
1599
- });
1587
+ if (config.headers && config.headers["Authorization"]) {
1588
+ return Promise.reject(new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists));
1589
+ }
1590
+ if (config.auth) {
1591
+ return Promise.reject(new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists));
1592
+ }
1593
+ config.auth = {
1594
+ username: this.userName,
1595
+ password: this.password,
1596
+ };
1597
+ return Promise.resolve(config);
1600
1598
  }
1601
1599
  }
1602
1600
 
@@ -1637,34 +1635,32 @@ class ApiKeyProvider {
1637
1635
  * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1638
1636
  */
1639
1637
  AddAuthenticationInfo(config) {
1640
- return tslib.__awaiter(this, void 0, void 0, function* () {
1641
- switch (this.keyLocation) {
1642
- case exports.ApiKeyLocation.Header:
1643
- if (!config.headers) {
1644
- config.headers = {};
1645
- }
1646
- if (config.headers[this.keyName]) {
1647
- throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInHeader, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists);
1648
- }
1649
- config.headers[this.keyName] = this.keyValue;
1650
- break;
1651
- case exports.ApiKeyLocation.QueryParams:
1652
- if (!config.params) {
1653
- config.params = {};
1654
- }
1655
- let urlHasDefinedApiKey = false;
1656
- if (config.url) {
1657
- const url = new URL(config.url, config.baseURL);
1658
- urlHasDefinedApiKey = url.searchParams.has(this.keyName);
1659
- }
1660
- if (config.params[this.keyName] || urlHasDefinedApiKey) {
1661
- throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInQueryParam, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists);
1662
- }
1663
- config.params[this.keyName] = this.keyValue;
1664
- break;
1665
- }
1666
- return config;
1667
- });
1638
+ switch (this.keyLocation) {
1639
+ case exports.ApiKeyLocation.Header:
1640
+ if (!config.headers) {
1641
+ config.headers = {};
1642
+ }
1643
+ if (config.headers[this.keyName]) {
1644
+ return Promise.reject(new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInHeader, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists));
1645
+ }
1646
+ config.headers[this.keyName] = this.keyValue;
1647
+ break;
1648
+ case exports.ApiKeyLocation.QueryParams:
1649
+ if (!config.params) {
1650
+ config.params = {};
1651
+ }
1652
+ let urlHasDefinedApiKey = false;
1653
+ if (config.url) {
1654
+ const url = new URL(config.url, config.baseURL);
1655
+ urlHasDefinedApiKey = url.searchParams.has(this.keyName);
1656
+ }
1657
+ if (config.params[this.keyName] || urlHasDefinedApiKey) {
1658
+ return Promise.reject(new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInQueryParam, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists));
1659
+ }
1660
+ config.params[this.keyName] = this.keyValue;
1661
+ break;
1662
+ }
1663
+ return Promise.resolve(config);
1668
1664
  }
1669
1665
  }
1670
1666
  /**
@@ -1712,21 +1708,19 @@ class CertificateAuthProvider {
1712
1708
  * @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
1713
1709
  */
1714
1710
  AddAuthenticationInfo(config) {
1715
- return tslib.__awaiter(this, void 0, void 0, function* () {
1716
- if (!config.httpsAgent) {
1717
- config.httpsAgent = new https.Agent(this.certOption);
1718
- }
1719
- else {
1720
- const existingProperties = new Set(Object.keys(config.httpsAgent.options));
1721
- for (const property of Object.keys(this.certOption)) {
1722
- if (existingProperties.has(property)) {
1723
- throw new ErrorWithCode(formatString(ErrorMessage.DuplicateHttpsOptionProperty, property), exports.ErrorCode.InvalidParameter);
1724
- }
1711
+ if (!config.httpsAgent) {
1712
+ config.httpsAgent = new https.Agent(this.certOption);
1713
+ }
1714
+ else {
1715
+ const existingProperties = new Set(Object.keys(config.httpsAgent.options));
1716
+ for (const property of Object.keys(this.certOption)) {
1717
+ if (existingProperties.has(property)) {
1718
+ return Promise.reject(new ErrorWithCode(formatString(ErrorMessage.DuplicateHttpsOptionProperty, property), exports.ErrorCode.InvalidParameter));
1725
1719
  }
1726
- Object.assign(config.httpsAgent.options, this.certOption);
1727
1720
  }
1728
- return config;
1729
- });
1721
+ Object.assign(config.httpsAgent.options, this.certOption);
1722
+ }
1723
+ return Promise.resolve(config);
1730
1724
  }
1731
1725
  }
1732
1726
  /**
@@ -2813,7 +2807,7 @@ class Channel$1 {
2813
2807
  return tslib.__awaiter(this, void 0, void 0, function* () {
2814
2808
  const response = {};
2815
2809
  yield this.parent.adapter.continueConversation(this.parent.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
2816
- const conversation = yield this.newConversation(context);
2810
+ const conversation = this.newConversation(context);
2817
2811
  yield this.parent.adapter.continueConversation(conversation, (ctx) => tslib.__awaiter(this, void 0, void 0, function* () {
2818
2812
  try {
2819
2813
  const res = yield ctx.sendActivity(text);
@@ -2844,7 +2838,7 @@ class Channel$1 {
2844
2838
  return tslib.__awaiter(this, void 0, void 0, function* () {
2845
2839
  const response = {};
2846
2840
  yield this.parent.adapter.continueConversation(this.parent.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
2847
- const conversation = yield this.newConversation(context);
2841
+ const conversation = this.newConversation(context);
2848
2842
  yield this.parent.adapter.continueConversation(conversation, (ctx) => tslib.__awaiter(this, void 0, void 0, function* () {
2849
2843
  try {
2850
2844
  const res = yield ctx.sendActivity({
@@ -2869,12 +2863,10 @@ class Channel$1 {
2869
2863
  * @internal
2870
2864
  */
2871
2865
  newConversation(context) {
2872
- return tslib.__awaiter(this, void 0, void 0, function* () {
2873
- const reference = botbuilder.TurnContext.getConversationReference(context.activity);
2874
- const channelConversation = cloneConversation(reference);
2875
- channelConversation.conversation.id = this.info.id || "";
2876
- return channelConversation;
2877
- });
2866
+ const reference = botbuilder.TurnContext.getConversationReference(context.activity);
2867
+ const channelConversation = cloneConversation(reference);
2868
+ channelConversation.conversation.id = this.info.id || "";
2869
+ return channelConversation;
2878
2870
  }
2879
2871
  }
2880
2872
  /**
@@ -4736,6 +4728,29 @@ class NotificationBot {
4736
4728
  }
4737
4729
  return new TeamsBotInstallation(this.adapter, conversationReference, this.botAppId);
4738
4730
  }
4731
+ /**
4732
+ * Validate the installation by getting paged memebers.
4733
+ *
4734
+ * @param conversationReference The bound `ConversationReference`.
4735
+ * @returns Returns false if recieves `BotNotInConversationRoster` error, otherwise returns true.
4736
+ */
4737
+ validateInstallation(conversationReference) {
4738
+ return tslib.__awaiter(this, void 0, void 0, function* () {
4739
+ let isValid = true;
4740
+ yield this.adapter.continueConversationAsync(this.botAppId, conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
4741
+ try {
4742
+ // try get member to see if the installation is still valid
4743
+ yield botbuilder.TeamsInfo.getPagedMembers(context, 1);
4744
+ }
4745
+ catch (error) {
4746
+ if (error.code === "BotNotInConversationRoster") {
4747
+ isValid = false;
4748
+ }
4749
+ }
4750
+ }));
4751
+ return isValid;
4752
+ });
4753
+ }
4739
4754
  /**
4740
4755
  * Gets a pagined list of targets where the bot is installed.
4741
4756
  *
@@ -4747,7 +4762,7 @@ class NotificationBot {
4747
4762
  *
4748
4763
  * @returns An array of {@link TeamsBotInstallation} with paged data and continuation token.
4749
4764
  */
4750
- getPagedInstallations(pageSize, continuationToken) {
4765
+ getPagedInstallations(pageSize, continuationToken, validationEnabled = true) {
4751
4766
  return tslib.__awaiter(this, void 0, void 0, function* () {
4752
4767
  if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
4753
4768
  throw new Error("NotificationBot has not been initialized.");
@@ -4756,19 +4771,12 @@ class NotificationBot {
4756
4771
  const targets = [];
4757
4772
  for (const reference of references.data) {
4758
4773
  // validate connection
4759
- let valid = true;
4760
- yield this.adapter.continueConversationAsync(this.botAppId, reference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
4761
- try {
4762
- // try get member to see if the installation is still valid
4763
- yield botbuilder.TeamsInfo.getPagedMembers(context, 1);
4764
- }
4765
- catch (error) {
4766
- if (error.code === "BotNotInConversationRoster") {
4767
- valid = false;
4768
- }
4769
- }
4770
- }));
4771
- if (valid) {
4774
+ let valid;
4775
+ if (validationEnabled) {
4776
+ // try get member to see if the installation is still valid
4777
+ valid = yield this.validateInstallation(reference);
4778
+ }
4779
+ if (!validationEnabled || (validationEnabled && valid)) {
4772
4780
  targets.push(new TeamsBotInstallation(this.adapter, reference, this.botAppId));
4773
4781
  }
4774
4782
  else {