@microsoft/teamsfx 2.2.1 → 2.2.2-alpha.21023e5be.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.
@@ -713,8 +713,9 @@ class OnBehalfOfUserCredential {
713
713
  internalLogger.warn(fullErrorMsg);
714
714
  return new ErrorWithCode(fullErrorMsg, exports.ErrorCode.UiRequiredError);
715
715
  }
716
- else if (errorMessage && errorMessage.indexOf("AADSTS500133") >= 0) {
717
- const fullErrorMsg = "Failed to get access token from AAD server, sso token expired: " + errorMessage;
716
+ else if (errorMessage && errorMessage.indexOf("AADSTS50013") >= 0) {
717
+ const fullErrorMsg = "Failed to get access token from AAD server, assertion is invalid because of various reasons: " +
718
+ errorMessage;
718
719
  internalLogger.error(fullErrorMsg);
719
720
  return new ErrorWithCode(fullErrorMsg, exports.ErrorCode.TokenExpiredError);
720
721
  }
@@ -2469,6 +2470,13 @@ class CommandBot$1 {
2469
2470
  function cloneConversation(conversation) {
2470
2471
  return JSON.parse(JSON.stringify(conversation));
2471
2472
  }
2473
+ /**
2474
+ * @internal
2475
+ */
2476
+ function getKey(reference) {
2477
+ var _a, _b;
2478
+ return `_${(_a = reference.conversation) === null || _a === void 0 ? void 0 : _a.tenantId}_${(_b = reference.conversation) === null || _b === void 0 ? void 0 : _b.id}`;
2479
+ }
2472
2480
  /**
2473
2481
  * @internal
2474
2482
  */
@@ -2532,7 +2540,9 @@ class NotificationMiddleware {
2532
2540
  case ActivityType.CurrentBotInstalled:
2533
2541
  case ActivityType.TeamRestored: {
2534
2542
  const reference = botbuilder.TurnContext.getConversationReference(context.activity);
2535
- yield this.conversationReferenceStore.set(reference);
2543
+ yield this.conversationReferenceStore.add(getKey(reference), reference, {
2544
+ overwrite: true,
2545
+ });
2536
2546
  break;
2537
2547
  }
2538
2548
  case ActivityType.CurrentBotMessaged: {
@@ -2542,7 +2552,7 @@ class NotificationMiddleware {
2542
2552
  case ActivityType.CurrentBotUninstalled:
2543
2553
  case ActivityType.TeamDeleted: {
2544
2554
  const reference = botbuilder.TurnContext.getConversationReference(context.activity);
2545
- yield this.conversationReferenceStore.delete(reference);
2555
+ yield this.conversationReferenceStore.remove(getKey(reference), reference);
2546
2556
  break;
2547
2557
  }
2548
2558
  }
@@ -2581,18 +2591,16 @@ class NotificationMiddleware {
2581
2591
  const reference = botbuilder.TurnContext.getConversationReference(context.activity);
2582
2592
  const conversationType = (_a = reference === null || reference === void 0 ? void 0 : reference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
2583
2593
  if (conversationType === "personal" || conversationType === "groupChat") {
2584
- if (!(yield this.conversationReferenceStore.check(reference))) {
2585
- yield this.conversationReferenceStore.set(reference);
2586
- }
2594
+ yield this.conversationReferenceStore.add(getKey(reference), reference, { overwrite: false });
2587
2595
  }
2588
2596
  else if (conversationType === "channel") {
2589
2597
  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;
2590
2598
  if (teamId !== undefined) {
2591
2599
  const teamReference = cloneConversation(reference);
2592
2600
  teamReference.conversation.id = teamId;
2593
- if (!(yield this.conversationReferenceStore.check(teamReference))) {
2594
- yield this.conversationReferenceStore.set(teamReference);
2595
- }
2601
+ yield this.conversationReferenceStore.add(getKey(teamReference), teamReference, {
2602
+ overwrite: false,
2603
+ });
2596
2604
  }
2597
2605
  }
2598
2606
  });
@@ -2705,28 +2713,42 @@ class LocalFileStorage {
2705
2713
  /**
2706
2714
  * @internal
2707
2715
  */
2708
- class ConversationReferenceStore {
2716
+ class DefaultConversationReferenceStore {
2709
2717
  constructor(storage) {
2710
2718
  this.storage = storage;
2711
2719
  }
2712
- check(reference) {
2720
+ add(key, reference, options) {
2713
2721
  return tslib.__awaiter(this, void 0, void 0, function* () {
2714
- const ref = yield this.storage.read(this.getKey(reference));
2715
- return ref !== undefined;
2722
+ if (options.overwrite) {
2723
+ yield this.storage.write(key, reference);
2724
+ return true;
2725
+ }
2726
+ const ref = yield this.storage.read(key);
2727
+ if (ref === undefined) {
2728
+ yield this.storage.write(key, reference);
2729
+ return true;
2730
+ }
2731
+ return false;
2716
2732
  });
2717
2733
  }
2718
- getAll() {
2719
- return this.storage.list();
2720
- }
2721
- set(reference) {
2722
- return this.storage.write(this.getKey(reference), reference);
2723
- }
2724
- delete(reference) {
2725
- return this.storage.delete(this.getKey(reference));
2734
+ remove(key, reference) {
2735
+ return tslib.__awaiter(this, void 0, void 0, function* () {
2736
+ const ref = yield this.storage.read(key);
2737
+ if (ref === undefined) {
2738
+ return false;
2739
+ }
2740
+ yield this.storage.delete(key);
2741
+ return true;
2742
+ });
2726
2743
  }
2727
- getKey(reference) {
2728
- var _a, _b;
2729
- return `_${(_a = reference.conversation) === null || _a === void 0 ? void 0 : _a.tenantId}_${(_b = reference.conversation) === null || _b === void 0 ? void 0 : _b.id}`;
2744
+ list(pageSize, continuationToken) {
2745
+ return tslib.__awaiter(this, void 0, void 0, function* () {
2746
+ const data = yield this.storage.list();
2747
+ return {
2748
+ data,
2749
+ continuationToken: "",
2750
+ };
2751
+ });
2730
2752
  }
2731
2753
  }
2732
2754
 
@@ -3133,7 +3155,7 @@ class NotificationBot$1 {
3133
3155
  constructor(adapter, options) {
3134
3156
  var _a, _b;
3135
3157
  const storage = (_a = options === null || options === void 0 ? void 0 : options.storage) !== null && _a !== void 0 ? _a : new LocalFileStorage(path__namespace.resolve(process.env.RUNNING_ON_AZURE === "1" ? (_b = process.env.TEMP) !== null && _b !== void 0 ? _b : "./" : "./"));
3136
- this.conversationReferenceStore = new ConversationReferenceStore(storage);
3158
+ this.conversationReferenceStore = new DefaultConversationReferenceStore(storage);
3137
3159
  this.adapter = adapter.use(new NotificationMiddleware({
3138
3160
  conversationReferenceStore: this.conversationReferenceStore,
3139
3161
  }));
@@ -3151,7 +3173,7 @@ class NotificationBot$1 {
3151
3173
  if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
3152
3174
  throw new Error("NotificationBot has not been initialized.");
3153
3175
  }
3154
- const references = yield this.conversationReferenceStore.getAll();
3176
+ const { data: references } = yield this.conversationReferenceStore.list();
3155
3177
  const targets = [];
3156
3178
  for (const reference of references) {
3157
3179
  // validate connection
@@ -3171,7 +3193,7 @@ class NotificationBot$1 {
3171
3193
  targets.push(new TeamsBotInstallation$1(this.adapter, reference));
3172
3194
  }
3173
3195
  else {
3174
- yield this.conversationReferenceStore.delete(reference);
3196
+ yield this.conversationReferenceStore.remove(getKey(reference), reference);
3175
3197
  }
3176
3198
  }
3177
3199
  return targets;
@@ -4612,24 +4634,45 @@ class TeamsBotInstallation {
4612
4634
  return channels;
4613
4635
  });
4614
4636
  }
4637
+ /**
4638
+ * Gets a pagined list of members from this bot installation.
4639
+ *
4640
+ * @param pageSize - Suggested number of entries on a page.
4641
+ * @param continuationToken - A continuation token.
4642
+ * @returns An array of members from where the bot is installed.
4643
+ */
4644
+ getPagedMembers(pageSize, continuationToken) {
4645
+ return tslib.__awaiter(this, void 0, void 0, function* () {
4646
+ let result = {
4647
+ data: [],
4648
+ continuationToken: "",
4649
+ };
4650
+ yield this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
4651
+ const pagedMembers = yield botbuilder.TeamsInfo.getPagedMembers(context, pageSize, continuationToken);
4652
+ result = {
4653
+ data: pagedMembers.members.map((m) => new Member(this, m)),
4654
+ continuationToken: pagedMembers.continuationToken,
4655
+ };
4656
+ }));
4657
+ return result;
4658
+ });
4659
+ }
4615
4660
  /**
4616
4661
  * Get members from this bot installation.
4617
4662
  *
4618
4663
  * @returns An array of members from where the bot is installed.
4664
+ *
4665
+ * @deprecated Use `getPagedMembers` instead.
4619
4666
  */
4620
4667
  members() {
4621
4668
  return tslib.__awaiter(this, void 0, void 0, function* () {
4622
4669
  const members = [];
4623
- yield this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
4624
- let continuationToken;
4625
- do {
4626
- const pagedMembers = yield botbuilder.TeamsInfo.getPagedMembers(context, undefined, continuationToken);
4627
- continuationToken = pagedMembers.continuationToken;
4628
- for (const member of pagedMembers.members) {
4629
- members.push(new Member(this, member));
4630
- }
4631
- } while (continuationToken !== undefined);
4632
- }));
4670
+ let continuationToken;
4671
+ do {
4672
+ const pagedData = yield this.getPagedMembers(undefined, continuationToken);
4673
+ continuationToken = pagedData.continuationToken;
4674
+ members.push(...pagedData.data);
4675
+ } while (continuationToken);
4633
4676
  return members;
4634
4677
  });
4635
4678
  }
@@ -4669,29 +4712,49 @@ class NotificationBot {
4669
4712
  */
4670
4713
  constructor(adapter, options) {
4671
4714
  var _a, _b, _c;
4672
- const storage = (_a = options === null || options === void 0 ? void 0 : options.storage) !== null && _a !== void 0 ? _a : new LocalFileStorage(path__namespace.resolve(process.env.RUNNING_ON_AZURE === "1" ? (_b = process.env.TEMP) !== null && _b !== void 0 ? _b : "./" : "./"));
4673
- this.conversationReferenceStore = new ConversationReferenceStore(storage);
4715
+ if (options === null || options === void 0 ? void 0 : options.store) {
4716
+ this.conversationReferenceStore = options.store;
4717
+ }
4718
+ else {
4719
+ const storage = (_a = options === null || options === void 0 ? void 0 : options.storage) !== null && _a !== void 0 ? _a : new LocalFileStorage(path__namespace.resolve(process.env.RUNNING_ON_AZURE === "1" ? (_b = process.env.TEMP) !== null && _b !== void 0 ? _b : "./" : "./"));
4720
+ this.conversationReferenceStore = new DefaultConversationReferenceStore(storage);
4721
+ }
4674
4722
  this.adapter = adapter.use(new NotificationMiddleware({
4675
4723
  conversationReferenceStore: this.conversationReferenceStore,
4676
4724
  }));
4677
4725
  this.botAppId = ((_c = options === null || options === void 0 ? void 0 : options.botAppId) !== null && _c !== void 0 ? _c : process.env.BOT_ID);
4678
4726
  }
4679
4727
  /**
4680
- * Get all targets where the bot is installed.
4728
+ * Create a {@link TeamsBotInstallation} instance with conversation reference.
4729
+ *
4730
+ * @param conversationReference - The bound `ConversationReference`.
4731
+ * @returns - The {@link TeamsBotInstallation} instance or null.
4732
+ */
4733
+ buildTeamsBotInstallation(conversationReference) {
4734
+ if (!conversationReference) {
4735
+ throw new Error("conversationReference is required.");
4736
+ }
4737
+ return new TeamsBotInstallation(this.adapter, conversationReference, this.botAppId);
4738
+ }
4739
+ /**
4740
+ * Gets a pagined list of targets where the bot is installed.
4681
4741
  *
4682
4742
  * @remarks
4683
4743
  * The result is retrieving from the persisted storage.
4684
4744
  *
4685
- * @returns An array of {@link TeamsBotInstallation}.
4745
+ * @param pageSize - Suggested number of entries on a page.
4746
+ * @param continuationToken - A continuation token.
4747
+ *
4748
+ * @returns An array of {@link TeamsBotInstallation} with paged data and continuation token.
4686
4749
  */
4687
- installations() {
4750
+ getPagedInstallations(pageSize, continuationToken) {
4688
4751
  return tslib.__awaiter(this, void 0, void 0, function* () {
4689
4752
  if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
4690
4753
  throw new Error("NotificationBot has not been initialized.");
4691
4754
  }
4692
- const references = yield this.conversationReferenceStore.getAll();
4755
+ const references = yield this.conversationReferenceStore.list(pageSize, continuationToken);
4693
4756
  const targets = [];
4694
- for (const reference of references) {
4757
+ for (const reference of references.data) {
4695
4758
  // validate connection
4696
4759
  let valid = true;
4697
4760
  yield this.adapter.continueConversationAsync(this.botAppId, reference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
@@ -4709,9 +4772,34 @@ class NotificationBot {
4709
4772
  targets.push(new TeamsBotInstallation(this.adapter, reference, this.botAppId));
4710
4773
  }
4711
4774
  else {
4712
- yield this.conversationReferenceStore.delete(reference);
4775
+ yield this.conversationReferenceStore.remove(getKey(reference), reference);
4713
4776
  }
4714
4777
  }
4778
+ return {
4779
+ data: targets,
4780
+ continuationToken: references.continuationToken,
4781
+ };
4782
+ });
4783
+ }
4784
+ /**
4785
+ * Get all targets where the bot is installed.
4786
+ *
4787
+ * @remarks
4788
+ * The result is retrieving from the persisted storage.
4789
+ *
4790
+ * @returns An array of {@link TeamsBotInstallation}.
4791
+ *
4792
+ * @deprecated Use getPagedInstallations instead.
4793
+ */
4794
+ installations() {
4795
+ return tslib.__awaiter(this, void 0, void 0, function* () {
4796
+ let continuationToken;
4797
+ const targets = [];
4798
+ do {
4799
+ const result = yield this.getPagedInstallations(undefined, continuationToken);
4800
+ continuationToken = result.continuationToken;
4801
+ targets.push(...result.data);
4802
+ } while (continuationToken);
4715
4803
  return targets;
4716
4804
  });
4717
4805
  }