@microsoft/teamsfx 2.2.1-rc.1 → 2.2.2-alpha.09fb224aa.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.
@@ -680,8 +680,9 @@ class OnBehalfOfUserCredential {
680
680
  internalLogger.warn(fullErrorMsg);
681
681
  return new ErrorWithCode(fullErrorMsg, ErrorCode.UiRequiredError);
682
682
  }
683
- else if (errorMessage && errorMessage.indexOf("AADSTS500133") >= 0) {
684
- const fullErrorMsg = "Failed to get access token from AAD server, sso token expired: " + errorMessage;
683
+ else if (errorMessage && errorMessage.indexOf("AADSTS50013") >= 0) {
684
+ const fullErrorMsg = "Failed to get access token from AAD server, assertion is invalid because of various reasons: " +
685
+ errorMessage;
685
686
  internalLogger.error(fullErrorMsg);
686
687
  return new ErrorWithCode(fullErrorMsg, ErrorCode.TokenExpiredError);
687
688
  }
@@ -2396,6 +2397,13 @@ class CommandBot$1 {
2396
2397
  function cloneConversation(conversation) {
2397
2398
  return JSON.parse(JSON.stringify(conversation));
2398
2399
  }
2400
+ /**
2401
+ * @internal
2402
+ */
2403
+ function getKey(reference) {
2404
+ var _a, _b;
2405
+ return `_${(_a = reference.conversation) === null || _a === void 0 ? void 0 : _a.tenantId}_${(_b = reference.conversation) === null || _b === void 0 ? void 0 : _b.id}`;
2406
+ }
2399
2407
  /**
2400
2408
  * @internal
2401
2409
  */
@@ -2458,7 +2466,9 @@ class NotificationMiddleware {
2458
2466
  case ActivityType.CurrentBotInstalled:
2459
2467
  case ActivityType.TeamRestored: {
2460
2468
  const reference = TurnContext.getConversationReference(context.activity);
2461
- await this.conversationReferenceStore.set(reference);
2469
+ await this.conversationReferenceStore.add(getKey(reference), reference, {
2470
+ overwrite: true,
2471
+ });
2462
2472
  break;
2463
2473
  }
2464
2474
  case ActivityType.CurrentBotMessaged: {
@@ -2468,7 +2478,7 @@ class NotificationMiddleware {
2468
2478
  case ActivityType.CurrentBotUninstalled:
2469
2479
  case ActivityType.TeamDeleted: {
2470
2480
  const reference = TurnContext.getConversationReference(context.activity);
2471
- await this.conversationReferenceStore.delete(reference);
2481
+ await this.conversationReferenceStore.remove(getKey(reference), reference);
2472
2482
  break;
2473
2483
  }
2474
2484
  }
@@ -2505,18 +2515,16 @@ class NotificationMiddleware {
2505
2515
  const reference = TurnContext.getConversationReference(context.activity);
2506
2516
  const conversationType = (_a = reference === null || reference === void 0 ? void 0 : reference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
2507
2517
  if (conversationType === "personal" || conversationType === "groupChat") {
2508
- if (!(await this.conversationReferenceStore.check(reference))) {
2509
- await this.conversationReferenceStore.set(reference);
2510
- }
2518
+ await this.conversationReferenceStore.add(getKey(reference), reference, { overwrite: false });
2511
2519
  }
2512
2520
  else if (conversationType === "channel") {
2513
2521
  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;
2514
2522
  if (teamId !== undefined) {
2515
2523
  const teamReference = cloneConversation(reference);
2516
2524
  teamReference.conversation.id = teamId;
2517
- if (!(await this.conversationReferenceStore.check(teamReference))) {
2518
- await this.conversationReferenceStore.set(teamReference);
2519
- }
2525
+ await this.conversationReferenceStore.add(getKey(teamReference), teamReference, {
2526
+ overwrite: false,
2527
+ });
2520
2528
  }
2521
2529
  }
2522
2530
  }
@@ -2618,26 +2626,36 @@ class LocalFileStorage {
2618
2626
  /**
2619
2627
  * @internal
2620
2628
  */
2621
- class ConversationReferenceStore {
2629
+ class DefaultConversationReferenceStore {
2622
2630
  constructor(storage) {
2623
2631
  this.storage = storage;
2624
2632
  }
2625
- async check(reference) {
2626
- const ref = await this.storage.read(this.getKey(reference));
2627
- return ref !== undefined;
2628
- }
2629
- getAll() {
2630
- return this.storage.list();
2631
- }
2632
- set(reference) {
2633
- return this.storage.write(this.getKey(reference), reference);
2633
+ async add(key, reference, options) {
2634
+ if (options.overwrite) {
2635
+ await this.storage.write(key, reference);
2636
+ return true;
2637
+ }
2638
+ const ref = await this.storage.read(key);
2639
+ if (ref === undefined) {
2640
+ await this.storage.write(key, reference);
2641
+ return true;
2642
+ }
2643
+ return false;
2634
2644
  }
2635
- delete(reference) {
2636
- return this.storage.delete(this.getKey(reference));
2645
+ async remove(key, reference) {
2646
+ const ref = await this.storage.read(key);
2647
+ if (ref === undefined) {
2648
+ return false;
2649
+ }
2650
+ await this.storage.delete(key);
2651
+ return true;
2637
2652
  }
2638
- getKey(reference) {
2639
- var _a, _b;
2640
- return `_${(_a = reference.conversation) === null || _a === void 0 ? void 0 : _a.tenantId}_${(_b = reference.conversation) === null || _b === void 0 ? void 0 : _b.id}`;
2653
+ async list(pageSize, continuationToken) {
2654
+ const data = await this.storage.list();
2655
+ return {
2656
+ data,
2657
+ continuationToken: "",
2658
+ };
2641
2659
  }
2642
2660
  }
2643
2661
 
@@ -3022,7 +3040,7 @@ class NotificationBot$1 {
3022
3040
  constructor(adapter, options) {
3023
3041
  var _a, _b;
3024
3042
  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 : "./" : "./"));
3025
- this.conversationReferenceStore = new ConversationReferenceStore(storage);
3043
+ this.conversationReferenceStore = new DefaultConversationReferenceStore(storage);
3026
3044
  this.adapter = adapter.use(new NotificationMiddleware({
3027
3045
  conversationReferenceStore: this.conversationReferenceStore,
3028
3046
  }));
@@ -3039,7 +3057,7 @@ class NotificationBot$1 {
3039
3057
  if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
3040
3058
  throw new Error("NotificationBot has not been initialized.");
3041
3059
  }
3042
- const references = await this.conversationReferenceStore.getAll();
3060
+ const { data: references } = await this.conversationReferenceStore.list();
3043
3061
  const targets = [];
3044
3062
  for (const reference of references) {
3045
3063
  // validate connection
@@ -3059,7 +3077,7 @@ class NotificationBot$1 {
3059
3077
  targets.push(new TeamsBotInstallation$1(this.adapter, reference));
3060
3078
  }
3061
3079
  else {
3062
- await this.conversationReferenceStore.delete(reference);
3080
+ await this.conversationReferenceStore.remove(getKey(reference), reference);
3063
3081
  }
3064
3082
  }
3065
3083
  return targets;
@@ -4442,23 +4460,42 @@ class TeamsBotInstallation {
4442
4460
  }
4443
4461
  return channels;
4444
4462
  }
4463
+ /**
4464
+ * Gets a pagined list of members from this bot installation.
4465
+ *
4466
+ * @param pageSize - Suggested number of entries on a page.
4467
+ * @param continuationToken - A continuation token.
4468
+ * @returns An array of members from where the bot is installed.
4469
+ */
4470
+ async getPagedMembers(pageSize, continuationToken) {
4471
+ let result = {
4472
+ data: [],
4473
+ continuationToken: "",
4474
+ };
4475
+ await this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, async (context) => {
4476
+ const pagedMembers = await TeamsInfo.getPagedMembers(context, pageSize, continuationToken);
4477
+ result = {
4478
+ data: pagedMembers.members.map((m) => new Member(this, m)),
4479
+ continuationToken: pagedMembers.continuationToken,
4480
+ };
4481
+ });
4482
+ return result;
4483
+ }
4445
4484
  /**
4446
4485
  * Get members from this bot installation.
4447
4486
  *
4448
4487
  * @returns An array of members from where the bot is installed.
4488
+ *
4489
+ * @deprecated Use `getPagedMembers` instead.
4449
4490
  */
4450
4491
  async members() {
4451
4492
  const members = [];
4452
- await this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, async (context) => {
4453
- let continuationToken;
4454
- do {
4455
- const pagedMembers = await TeamsInfo.getPagedMembers(context, undefined, continuationToken);
4456
- continuationToken = pagedMembers.continuationToken;
4457
- for (const member of pagedMembers.members) {
4458
- members.push(new Member(this, member));
4459
- }
4460
- } while (continuationToken !== undefined);
4461
- });
4493
+ let continuationToken;
4494
+ do {
4495
+ const pagedData = await this.getPagedMembers(undefined, continuationToken);
4496
+ continuationToken = pagedData.continuationToken;
4497
+ members.push(...pagedData.data);
4498
+ } while (continuationToken);
4462
4499
  return members;
4463
4500
  }
4464
4501
  /**
@@ -4495,28 +4532,48 @@ class NotificationBot {
4495
4532
  */
4496
4533
  constructor(adapter, options) {
4497
4534
  var _a, _b, _c;
4498
- 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 : "./" : "./"));
4499
- this.conversationReferenceStore = new ConversationReferenceStore(storage);
4535
+ if (options === null || options === void 0 ? void 0 : options.store) {
4536
+ this.conversationReferenceStore = options.store;
4537
+ }
4538
+ else {
4539
+ 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 : "./" : "./"));
4540
+ this.conversationReferenceStore = new DefaultConversationReferenceStore(storage);
4541
+ }
4500
4542
  this.adapter = adapter.use(new NotificationMiddleware({
4501
4543
  conversationReferenceStore: this.conversationReferenceStore,
4502
4544
  }));
4503
4545
  this.botAppId = ((_c = options === null || options === void 0 ? void 0 : options.botAppId) !== null && _c !== void 0 ? _c : process.env.BOT_ID);
4504
4546
  }
4505
4547
  /**
4506
- * Get all targets where the bot is installed.
4548
+ * Create a {@link TeamsBotInstallation} instance with conversation reference.
4549
+ *
4550
+ * @param conversationReference - The bound `ConversationReference`.
4551
+ * @returns - The {@link TeamsBotInstallation} instance or null.
4552
+ */
4553
+ buildTeamsBotInstallation(conversationReference) {
4554
+ if (!conversationReference) {
4555
+ throw new Error("conversationReference is required.");
4556
+ }
4557
+ return new TeamsBotInstallation(this.adapter, conversationReference, this.botAppId);
4558
+ }
4559
+ /**
4560
+ * Gets a pagined list of targets where the bot is installed.
4507
4561
  *
4508
4562
  * @remarks
4509
4563
  * The result is retrieving from the persisted storage.
4510
4564
  *
4511
- * @returns An array of {@link TeamsBotInstallation}.
4565
+ * @param pageSize - Suggested number of entries on a page.
4566
+ * @param continuationToken - A continuation token.
4567
+ *
4568
+ * @returns An array of {@link TeamsBotInstallation} with paged data and continuation token.
4512
4569
  */
4513
- async installations() {
4570
+ async getPagedInstallations(pageSize, continuationToken) {
4514
4571
  if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
4515
4572
  throw new Error("NotificationBot has not been initialized.");
4516
4573
  }
4517
- const references = await this.conversationReferenceStore.getAll();
4574
+ const references = await this.conversationReferenceStore.list(pageSize, continuationToken);
4518
4575
  const targets = [];
4519
- for (const reference of references) {
4576
+ for (const reference of references.data) {
4520
4577
  // validate connection
4521
4578
  let valid = true;
4522
4579
  await this.adapter.continueConversationAsync(this.botAppId, reference, async (context) => {
@@ -4534,9 +4591,32 @@ class NotificationBot {
4534
4591
  targets.push(new TeamsBotInstallation(this.adapter, reference, this.botAppId));
4535
4592
  }
4536
4593
  else {
4537
- await this.conversationReferenceStore.delete(reference);
4594
+ await this.conversationReferenceStore.remove(getKey(reference), reference);
4538
4595
  }
4539
4596
  }
4597
+ return {
4598
+ data: targets,
4599
+ continuationToken: references.continuationToken,
4600
+ };
4601
+ }
4602
+ /**
4603
+ * Get all targets where the bot is installed.
4604
+ *
4605
+ * @remarks
4606
+ * The result is retrieving from the persisted storage.
4607
+ *
4608
+ * @returns An array of {@link TeamsBotInstallation}.
4609
+ *
4610
+ * @deprecated Use getPagedInstallations instead.
4611
+ */
4612
+ async installations() {
4613
+ let continuationToken;
4614
+ const targets = [];
4615
+ do {
4616
+ const result = await this.getPagedInstallations(undefined, continuationToken);
4617
+ continuationToken = result.continuationToken;
4618
+ targets.push(...result.data);
4619
+ } while (continuationToken);
4540
4620
  return targets;
4541
4621
  }
4542
4622
  /**