@microsoft/teamsfx-core 0.8.0 → 0.8.1-alpha.249dee5b.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.
Files changed (230) hide show
  1. package/build/common/index.d.ts +1 -0
  2. package/build/common/index.d.ts.map +1 -1
  3. package/build/common/index.js +1 -0
  4. package/build/common/index.js.map +1 -1
  5. package/build/common/permissionInterface.d.ts +20 -0
  6. package/build/common/permissionInterface.d.ts.map +1 -1
  7. package/build/common/permissionInterface.js +8 -0
  8. package/build/common/permissionInterface.js.map +1 -1
  9. package/build/common/tools.d.ts +3 -1
  10. package/build/common/tools.d.ts.map +1 -1
  11. package/build/common/tools.js +14 -1
  12. package/build/common/tools.js.map +1 -1
  13. package/build/core/environment.d.ts +1 -0
  14. package/build/core/environment.d.ts.map +1 -1
  15. package/build/core/environment.js +13 -2
  16. package/build/core/environment.js.map +1 -1
  17. package/build/core/error.d.ts +4 -2
  18. package/build/core/error.d.ts.map +1 -1
  19. package/build/core/error.js +5 -3
  20. package/build/core/error.js.map +1 -1
  21. package/build/core/index.d.ts +6 -10
  22. package/build/core/index.d.ts.map +1 -1
  23. package/build/core/index.js +121 -98
  24. package/build/core/index.js.map +1 -1
  25. package/build/core/middleware/envInfoLoader.d.ts +1 -2
  26. package/build/core/middleware/envInfoLoader.d.ts.map +1 -1
  27. package/build/core/middleware/envInfoLoader.js +77 -60
  28. package/build/core/middleware/envInfoLoader.js.map +1 -1
  29. package/build/core/middleware/envInfoWriter.d.ts +1 -1
  30. package/build/core/middleware/envInfoWriter.d.ts.map +1 -1
  31. package/build/core/middleware/envInfoWriter.js +5 -5
  32. package/build/core/middleware/envInfoWriter.js.map +1 -1
  33. package/build/core/middleware/errorHandler.d.ts.map +1 -1
  34. package/build/core/middleware/errorHandler.js +2 -1
  35. package/build/core/middleware/errorHandler.js.map +1 -1
  36. package/build/core/middleware/projectMigrator.d.ts.map +1 -1
  37. package/build/core/middleware/projectMigrator.js +30 -3
  38. package/build/core/middleware/projectMigrator.js.map +1 -1
  39. package/build/core/middleware/projectSettingsLoader.js +1 -1
  40. package/build/core/middleware/projectSettingsLoader.js.map +1 -1
  41. package/build/core/middleware/questionModel.d.ts.map +1 -1
  42. package/build/core/middleware/questionModel.js +10 -10
  43. package/build/core/middleware/questionModel.js.map +1 -1
  44. package/build/plugins/resource/aad/index.d.ts +2 -2
  45. package/build/plugins/resource/aad/index.d.ts.map +1 -1
  46. package/build/plugins/resource/aad/index.js +4 -4
  47. package/build/plugins/resource/aad/index.js.map +1 -1
  48. package/build/plugins/resource/aad/plugin.d.ts +3 -2
  49. package/build/plugins/resource/aad/plugin.d.ts.map +1 -1
  50. package/build/plugins/resource/aad/plugin.js +4 -4
  51. package/build/plugins/resource/aad/plugin.js.map +1 -1
  52. package/build/plugins/resource/aad/utils/configs.d.ts +0 -1
  53. package/build/plugins/resource/aad/utils/configs.d.ts.map +1 -1
  54. package/build/plugins/resource/aad/utils/configs.js +1 -11
  55. package/build/plugins/resource/aad/utils/configs.js.map +1 -1
  56. package/build/plugins/resource/aad/utils/tokenProvider.d.ts.map +1 -1
  57. package/build/plugins/resource/aad/utils/tokenProvider.js +1 -1
  58. package/build/plugins/resource/aad/utils/tokenProvider.js.map +1 -1
  59. package/build/plugins/resource/aad/v2/index.d.ts +1 -1
  60. package/build/plugins/resource/aad/v2/index.d.ts.map +1 -1
  61. package/build/plugins/resource/aad/v2/index.js +2 -2
  62. package/build/plugins/resource/aad/v2/index.js.map +1 -1
  63. package/build/plugins/resource/apim/v2/index.d.ts +4 -2
  64. package/build/plugins/resource/apim/v2/index.d.ts.map +1 -1
  65. package/build/plugins/resource/apim/v2/index.js +21 -23
  66. package/build/plugins/resource/apim/v2/index.js.map +1 -1
  67. package/build/plugins/resource/appstudio/errors.d.ts +1 -1
  68. package/build/plugins/resource/appstudio/errors.d.ts.map +1 -1
  69. package/build/plugins/resource/appstudio/errors.js +5 -1
  70. package/build/plugins/resource/appstudio/errors.js.map +1 -1
  71. package/build/plugins/resource/appstudio/index.d.ts +2 -2
  72. package/build/plugins/resource/appstudio/index.d.ts.map +1 -1
  73. package/build/plugins/resource/appstudio/index.js +6 -5
  74. package/build/plugins/resource/appstudio/index.js.map +1 -1
  75. package/build/plugins/resource/appstudio/interfaces/IAppDefinition.d.ts +1 -0
  76. package/build/plugins/resource/appstudio/interfaces/IAppDefinition.d.ts.map +1 -1
  77. package/build/plugins/resource/appstudio/plugin.d.ts +3 -3
  78. package/build/plugins/resource/appstudio/plugin.d.ts.map +1 -1
  79. package/build/plugins/resource/appstudio/plugin.js +21 -45
  80. package/build/plugins/resource/appstudio/plugin.js.map +1 -1
  81. package/build/plugins/resource/appstudio/utils/telemetry.d.ts +2 -1
  82. package/build/plugins/resource/appstudio/utils/telemetry.d.ts.map +1 -1
  83. package/build/plugins/resource/appstudio/utils/telemetry.js +1 -0
  84. package/build/plugins/resource/appstudio/utils/telemetry.js.map +1 -1
  85. package/build/plugins/resource/appstudio/v2/index.d.ts +5 -5
  86. package/build/plugins/resource/appstudio/v2/index.d.ts.map +1 -1
  87. package/build/plugins/resource/appstudio/v2/index.js +17 -17
  88. package/build/plugins/resource/appstudio/v2/index.js.map +1 -1
  89. package/build/plugins/resource/bot/v2/index.d.ts +2 -2
  90. package/build/plugins/resource/bot/v2/index.d.ts.map +1 -1
  91. package/build/plugins/resource/bot/v2/index.js +3 -3
  92. package/build/plugins/resource/bot/v2/index.js.map +1 -1
  93. package/build/plugins/resource/frontend/v2/index.d.ts +2 -1
  94. package/build/plugins/resource/frontend/v2/index.d.ts.map +1 -1
  95. package/build/plugins/resource/frontend/v2/index.js +3 -0
  96. package/build/plugins/resource/frontend/v2/index.js.map +1 -1
  97. package/build/plugins/resource/function/v2/index.d.ts +4 -3
  98. package/build/plugins/resource/function/v2/index.d.ts.map +1 -1
  99. package/build/plugins/resource/function/v2/index.js +5 -13
  100. package/build/plugins/resource/function/v2/index.js.map +1 -1
  101. package/build/plugins/resource/identity/index.d.ts +2 -0
  102. package/build/plugins/resource/identity/index.d.ts.map +1 -1
  103. package/build/plugins/resource/identity/index.js +14 -6
  104. package/build/plugins/resource/identity/index.js.map +1 -1
  105. package/build/plugins/resource/identity/utils/contextUtils.d.ts +1 -3
  106. package/build/plugins/resource/identity/utils/contextUtils.d.ts.map +1 -1
  107. package/build/plugins/resource/identity/utils/contextUtils.js +2 -5
  108. package/build/plugins/resource/identity/utils/contextUtils.js.map +1 -1
  109. package/build/plugins/resource/localdebug/constants.d.ts +4 -0
  110. package/build/plugins/resource/localdebug/constants.d.ts.map +1 -1
  111. package/build/plugins/resource/localdebug/constants.js +6 -1
  112. package/build/plugins/resource/localdebug/constants.js.map +1 -1
  113. package/build/plugins/resource/localdebug/index.d.ts.map +1 -1
  114. package/build/plugins/resource/localdebug/index.js +8 -5
  115. package/build/plugins/resource/localdebug/index.js.map +1 -1
  116. package/build/plugins/resource/localdebug/v2/index.d.ts +2 -2
  117. package/build/plugins/resource/localdebug/v2/index.d.ts.map +1 -1
  118. package/build/plugins/resource/localdebug/v2/index.js +2 -2
  119. package/build/plugins/resource/localdebug/v2/index.js.map +1 -1
  120. package/build/plugins/resource/sql/config.d.ts +1 -0
  121. package/build/plugins/resource/sql/config.d.ts.map +1 -1
  122. package/build/plugins/resource/sql/config.js +1 -0
  123. package/build/plugins/resource/sql/config.js.map +1 -1
  124. package/build/plugins/resource/sql/constants.d.ts +3 -0
  125. package/build/plugins/resource/sql/constants.d.ts.map +1 -1
  126. package/build/plugins/resource/sql/constants.js +3 -0
  127. package/build/plugins/resource/sql/constants.js.map +1 -1
  128. package/build/plugins/resource/sql/errors.d.ts +4 -0
  129. package/build/plugins/resource/sql/errors.d.ts.map +1 -1
  130. package/build/plugins/resource/sql/errors.js +4 -0
  131. package/build/plugins/resource/sql/errors.js.map +1 -1
  132. package/build/plugins/resource/sql/plugin.d.ts +4 -1
  133. package/build/plugins/resource/sql/plugin.d.ts.map +1 -1
  134. package/build/plugins/resource/sql/plugin.js +62 -16
  135. package/build/plugins/resource/sql/plugin.js.map +1 -1
  136. package/build/plugins/resource/sql/utils/contextUtils.d.ts +1 -3
  137. package/build/plugins/resource/sql/utils/contextUtils.d.ts.map +1 -1
  138. package/build/plugins/resource/sql/utils/contextUtils.js +2 -5
  139. package/build/plugins/resource/sql/utils/contextUtils.js.map +1 -1
  140. package/build/plugins/resource/sql/v2/index.d.ts +3 -2
  141. package/build/plugins/resource/sql/v2/index.d.ts.map +1 -1
  142. package/build/plugins/resource/sql/v2/index.js +14 -12
  143. package/build/plugins/resource/sql/v2/index.js.map +1 -1
  144. package/build/plugins/resource/utils4v2.d.ts +5 -3
  145. package/build/plugins/resource/utils4v2.d.ts.map +1 -1
  146. package/build/plugins/resource/utils4v2.js +38 -7
  147. package/build/plugins/resource/utils4v2.js.map +1 -1
  148. package/build/plugins/solution/fx-solution/ResourcePluginContainer.d.ts.map +1 -1
  149. package/build/plugins/solution/fx-solution/ResourcePluginContainer.js +4 -2
  150. package/build/plugins/solution/fx-solution/ResourcePluginContainer.js.map +1 -1
  151. package/build/plugins/solution/fx-solution/arm.d.ts +0 -1
  152. package/build/plugins/solution/fx-solution/arm.d.ts.map +1 -1
  153. package/build/plugins/solution/fx-solution/arm.js +2 -6
  154. package/build/plugins/solution/fx-solution/arm.js.map +1 -1
  155. package/build/plugins/solution/fx-solution/commonQuestions.d.ts +2 -2
  156. package/build/plugins/solution/fx-solution/commonQuestions.d.ts.map +1 -1
  157. package/build/plugins/solution/fx-solution/commonQuestions.js +46 -29
  158. package/build/plugins/solution/fx-solution/commonQuestions.js.map +1 -1
  159. package/build/plugins/solution/fx-solution/constants.d.ts +3 -6
  160. package/build/plugins/solution/fx-solution/constants.d.ts.map +1 -1
  161. package/build/plugins/solution/fx-solution/constants.js +3 -6
  162. package/build/plugins/solution/fx-solution/constants.js.map +1 -1
  163. package/build/plugins/solution/fx-solution/executor.d.ts.map +1 -1
  164. package/build/plugins/solution/fx-solution/executor.js +39 -21
  165. package/build/plugins/solution/fx-solution/executor.js.map +1 -1
  166. package/build/plugins/solution/fx-solution/index.d.ts +1 -0
  167. package/build/plugins/solution/fx-solution/index.d.ts.map +1 -1
  168. package/build/plugins/solution/fx-solution/index.js +1 -0
  169. package/build/plugins/solution/fx-solution/index.js.map +1 -1
  170. package/build/plugins/solution/fx-solution/solution.d.ts +6 -5
  171. package/build/plugins/solution/fx-solution/solution.d.ts.map +1 -1
  172. package/build/plugins/solution/fx-solution/solution.js +226 -119
  173. package/build/plugins/solution/fx-solution/solution.js.map +1 -1
  174. package/build/plugins/solution/fx-solution/v2/createEnv.d.ts.map +1 -1
  175. package/build/plugins/solution/fx-solution/v2/createEnv.js +11 -1
  176. package/build/plugins/solution/fx-solution/v2/createEnv.js.map +1 -1
  177. package/build/plugins/solution/fx-solution/v2/executeUserTask.d.ts +2 -2
  178. package/build/plugins/solution/fx-solution/v2/executeUserTask.d.ts.map +1 -1
  179. package/build/plugins/solution/fx-solution/v2/executeUserTask.js +23 -10
  180. package/build/plugins/solution/fx-solution/v2/executeUserTask.js.map +1 -1
  181. package/build/plugins/solution/fx-solution/v2/executor.d.ts.map +1 -1
  182. package/build/plugins/solution/fx-solution/v2/executor.js +9 -1
  183. package/build/plugins/solution/fx-solution/v2/executor.js.map +1 -1
  184. package/build/plugins/solution/fx-solution/v2/generateResourceTemplate.d.ts.map +1 -1
  185. package/build/plugins/solution/fx-solution/v2/generateResourceTemplate.js +8 -2
  186. package/build/plugins/solution/fx-solution/v2/generateResourceTemplate.js.map +1 -1
  187. package/build/plugins/solution/fx-solution/v2/getQuestions.d.ts +5 -1
  188. package/build/plugins/solution/fx-solution/v2/getQuestions.d.ts.map +1 -1
  189. package/build/plugins/solution/fx-solution/v2/getQuestions.js +287 -1
  190. package/build/plugins/solution/fx-solution/v2/getQuestions.js.map +1 -1
  191. package/build/plugins/solution/fx-solution/v2/package.d.ts.map +1 -1
  192. package/build/plugins/solution/fx-solution/v2/package.js +2 -1
  193. package/build/plugins/solution/fx-solution/v2/package.js.map +1 -1
  194. package/build/plugins/solution/fx-solution/v2/provision.d.ts.map +1 -1
  195. package/build/plugins/solution/fx-solution/v2/provision.js +4 -12
  196. package/build/plugins/solution/fx-solution/v2/provision.js.map +1 -1
  197. package/build/plugins/solution/fx-solution/v2/provisionLocal.d.ts.map +1 -1
  198. package/build/plugins/solution/fx-solution/v2/provisionLocal.js +2 -1
  199. package/build/plugins/solution/fx-solution/v2/provisionLocal.js.map +1 -1
  200. package/build/plugins/solution/fx-solution/v2/publish.d.ts +2 -2
  201. package/build/plugins/solution/fx-solution/v2/publish.d.ts.map +1 -1
  202. package/build/plugins/solution/fx-solution/v2/publish.js +9 -9
  203. package/build/plugins/solution/fx-solution/v2/publish.js.map +1 -1
  204. package/build/plugins/solution/fx-solution/v2/scaffolding.d.ts.map +1 -1
  205. package/build/plugins/solution/fx-solution/v2/scaffolding.js +4 -0
  206. package/build/plugins/solution/fx-solution/v2/scaffolding.js.map +1 -1
  207. package/build/plugins/solution/fx-solution/v2/solution.d.ts +6 -4
  208. package/build/plugins/solution/fx-solution/v2/solution.d.ts.map +1 -1
  209. package/build/plugins/solution/fx-solution/v2/solution.js +2 -0
  210. package/build/plugins/solution/fx-solution/v2/solution.js.map +1 -1
  211. package/build/plugins/solution/fx-solution/v2/utils.d.ts +1 -0
  212. package/build/plugins/solution/fx-solution/v2/utils.d.ts.map +1 -1
  213. package/build/plugins/solution/fx-solution/v2/utils.js +5 -1
  214. package/build/plugins/solution/fx-solution/v2/utils.js.map +1 -1
  215. package/package.json +3 -3
  216. package/resource/strings.json +2 -2
  217. package/templates/plugins/resource/bot/bot-msgext.js.default.zip +0 -0
  218. package/templates/plugins/resource/bot/bot-msgext.ts.default.zip +0 -0
  219. package/templates/plugins/resource/bot/bot.js.default.zip +0 -0
  220. package/templates/plugins/resource/bot/bot.ts.default.zip +0 -0
  221. package/templates/plugins/resource/bot/msgext.js.default.zip +0 -0
  222. package/templates/plugins/resource/bot/msgext.ts.default.zip +0 -0
  223. package/templates/plugins/resource/frontend/tab.js.default.zip +0 -0
  224. package/templates/plugins/resource/frontend/tab.ts.default.zip +0 -0
  225. package/templates/plugins/resource/function/function-base.js.default.zip +0 -0
  226. package/templates/plugins/resource/function/function-base.ts.default.zip +0 -0
  227. package/templates/plugins/resource/function/function-triggers.js.HTTPTrigger.zip +0 -0
  228. package/templates/plugins/resource/function/function-triggers.ts.HTTPTrigger.zip +0 -0
  229. package/templates/plugins/resource/sql/bicep/output.template.bicep +1 -0
  230. package/templates/plugins/resource/sql/bicep/sql.template.bicep +3 -2
@@ -18,6 +18,7 @@ const typedi_1 = require("typedi");
18
18
  const util = tslib_1.__importStar(require("util"));
19
19
  const constants_1 = require("../../../common/constants");
20
20
  const localSettingsConstants_1 = require("../../../common/localSettingsConstants");
21
+ const permissionInterface_1 = require("../../../common/permissionInterface");
21
22
  const tools_1 = require("../../../common/tools");
22
23
  const core_1 = require("../../../core");
23
24
  const errorHandler_1 = require("../../../core/middleware/errorHandler");
@@ -795,82 +796,113 @@ let TeamsAppSolution = class TeamsAppSolution {
795
796
  }
796
797
  async localDebug(ctx) {
797
798
  var _a;
798
- if (!this.spfxSelected(ctx)) {
799
- if (ctx.permissionRequestProvider === undefined) {
800
- ctx.permissionRequestProvider = new permissionRequest_1.PermissionRequestFileProvider(ctx.root);
799
+ try {
800
+ if (!this.spfxSelected(ctx)) {
801
+ if (ctx.permissionRequestProvider === undefined) {
802
+ ctx.permissionRequestProvider = new permissionRequest_1.PermissionRequestFileProvider(ctx.root);
803
+ }
804
+ const result = await utils_1.ensurePermissionRequest((_a = ctx.projectSettings) === null || _a === void 0 ? void 0 : _a.solutionSettings, ctx.permissionRequestProvider);
805
+ if (result.isErr()) {
806
+ return result;
807
+ }
801
808
  }
802
- const result = await utils_1.ensurePermissionRequest((_a = ctx.projectSettings) === null || _a === void 0 ? void 0 : _a.solutionSettings, ctx.permissionRequestProvider);
803
- if (result.isErr()) {
804
- return result;
809
+ }
810
+ catch (e) {
811
+ if (e instanceof teamsfx_api_1.UserError || e instanceof teamsfx_api_1.SystemError) {
812
+ return teamsfx_api_1.err(e);
805
813
  }
814
+ return teamsfx_api_1.err(new teamsfx_api_1.SystemError("UnknownError", "check point 1 - " + JSON.stringify(e), "Solution"));
806
815
  }
807
816
  return await this.doLocalDebug(ctx);
808
817
  }
809
818
  async doLocalDebug(ctx) {
810
819
  var _a, _b;
811
- const maybeSelectedPlugins = this.getSelectedPlugins(ctx);
812
- if (maybeSelectedPlugins.isErr()) {
813
- return maybeSelectedPlugins;
814
- }
815
- const selectedPlugins = maybeSelectedPlugins.value;
816
- // Just to trigger M365 login before the concurrent execution of localDebug.
817
- // Because concurrent exectution of localDebug may getAccessToken() concurrently, which
818
- // causes 2 M365 logins before the token caching in common lib takes effect.
819
- await ((_a = ctx.appStudioToken) === null || _a === void 0 ? void 0 : _a.getAccessToken());
820
- const pluginsWithCtx = this.getPluginAndContextArray(ctx, selectedPlugins);
821
- const localDebugWithCtx = pluginsWithCtx.map(([plugin, context]) => {
822
- var _a;
823
- return [(_a = plugin === null || plugin === void 0 ? void 0 : plugin.localDebug) === null || _a === void 0 ? void 0 : _a.bind(plugin), context, plugin.name];
824
- });
825
- const postLocalDebugWithCtx = pluginsWithCtx.map(([plugin, context]) => {
826
- var _a;
827
- return [(_a = plugin === null || plugin === void 0 ? void 0 : plugin.postLocalDebug) === null || _a === void 0 ? void 0 : _a.bind(plugin), context, plugin.name];
828
- });
829
- const localDebugResults = await executor_1.executeConcurrently("", localDebugWithCtx);
830
- for (const localDebugResult of localDebugResults) {
831
- if (localDebugResult.isErr()) {
832
- return localDebugResult;
833
- }
834
- }
835
- if (!this.spfxSelected(ctx)) {
836
- const aadPlugin = this.AadPlugin;
837
- if (selectedPlugins.some((plugin) => plugin.name === aadPlugin.name)) {
838
- const result = await aadPlugin.executeUserTask({
839
- namespace: `${constants_2.PluginNames.SOLUTION}/${constants_2.PluginNames.AAD}`,
840
- method: "setApplicationInContext",
841
- params: { isLocal: true },
842
- }, util_1.getPluginContext(ctx, aadPlugin.name));
843
- if (result.isErr()) {
844
- return result;
820
+ let checkPoint = 1;
821
+ try {
822
+ //check point 2
823
+ const maybeSelectedPlugins = this.getSelectedPlugins(ctx);
824
+ if (maybeSelectedPlugins.isErr()) {
825
+ return maybeSelectedPlugins;
826
+ }
827
+ const selectedPlugins = maybeSelectedPlugins.value;
828
+ checkPoint = 2;
829
+ //check point 3
830
+ // Just to trigger M365 login before the concurrent execution of localDebug.
831
+ // Because concurrent exectution of localDebug may getAccessToken() concurrently, which
832
+ // causes 2 M365 logins before the token caching in common lib takes effect.
833
+ await ((_a = ctx.appStudioToken) === null || _a === void 0 ? void 0 : _a.getAccessToken());
834
+ checkPoint = 3;
835
+ //check point 4
836
+ const pluginsWithCtx = this.getPluginAndContextArray(ctx, selectedPlugins);
837
+ const localDebugWithCtx = pluginsWithCtx.map(([plugin, context]) => {
838
+ var _a;
839
+ return [(_a = plugin === null || plugin === void 0 ? void 0 : plugin.localDebug) === null || _a === void 0 ? void 0 : _a.bind(plugin), context, plugin.name];
840
+ });
841
+ const postLocalDebugWithCtx = pluginsWithCtx.map(([plugin, context]) => {
842
+ var _a;
843
+ return [(_a = plugin === null || plugin === void 0 ? void 0 : plugin.postLocalDebug) === null || _a === void 0 ? void 0 : _a.bind(plugin), context, plugin.name];
844
+ });
845
+ const localDebugResults = await executor_1.executeConcurrently("", localDebugWithCtx);
846
+ for (const localDebugResult of localDebugResults) {
847
+ if (localDebugResult.isErr()) {
848
+ return localDebugResult;
845
849
  }
846
850
  }
847
- }
848
- // set local debug Teams app tenant id in context.
849
- const result = this.loadTeamsAppTenantId(ctx, true, await ((_b = ctx.appStudioToken) === null || _b === void 0 ? void 0 : _b.getJsonObject()));
850
- if (result.isErr()) {
851
- return result;
852
- }
853
- const postLocalDebugResults = await executor_1.executeConcurrently("post", postLocalDebugWithCtx);
854
- const combinedPostLocalDebugResults = teamsfx_api_1.combine(postLocalDebugResults);
855
- if (combinedPostLocalDebugResults.isErr()) {
856
- return combinedPostLocalDebugResults;
857
- }
858
- // set local debug Teams app id in context.
859
- if (postLocalDebugWithCtx.length === combinedPostLocalDebugResults.value.length) {
860
- postLocalDebugWithCtx.map(function (plugin, index) {
861
- var _a, _b;
862
- if (plugin[2] === constants_2.PluginNames.APPST) {
863
- if (tools_1.isMultiEnvEnabled()) {
864
- (_a = ctx.localSettings) === null || _a === void 0 ? void 0 : _a.teamsApp.set(localSettingsConstants_1.LocalSettingsTeamsAppKeys.TeamsAppId, combinedPostLocalDebugResults.value[index]);
865
- }
866
- else {
867
- (_b = ctx.envInfo.profile
868
- .get(constants_2.GLOBAL_CONFIG)) === null || _b === void 0 ? void 0 : _b.set(constants_2.LOCAL_DEBUG_TEAMS_APP_ID, combinedPostLocalDebugResults.value[index]);
851
+ checkPoint = 4;
852
+ //check point 5
853
+ if (!this.spfxSelected(ctx)) {
854
+ const aadPlugin = this.AadPlugin;
855
+ if (selectedPlugins.some((plugin) => plugin.name === aadPlugin.name)) {
856
+ const result = await aadPlugin.executeUserTask({
857
+ namespace: `${constants_2.PluginNames.SOLUTION}/${constants_2.PluginNames.AAD}`,
858
+ method: "setApplicationInContext",
859
+ params: { isLocal: true },
860
+ }, util_1.getPluginContext(ctx, aadPlugin.name));
861
+ if (result.isErr()) {
862
+ return result;
869
863
  }
870
864
  }
871
- });
865
+ }
866
+ checkPoint = 5;
867
+ // check point 6
868
+ // set local debug Teams app tenant id in context.
869
+ const result = this.loadTeamsAppTenantId(ctx, true, await ((_b = ctx.appStudioToken) === null || _b === void 0 ? void 0 : _b.getJsonObject()));
870
+ if (result.isErr()) {
871
+ return result;
872
+ }
873
+ checkPoint = 6;
874
+ //check point 7
875
+ const postLocalDebugResults = await executor_1.executeConcurrently("post", postLocalDebugWithCtx);
876
+ const combinedPostLocalDebugResults = teamsfx_api_1.combine(postLocalDebugResults);
877
+ if (combinedPostLocalDebugResults.isErr()) {
878
+ return combinedPostLocalDebugResults;
879
+ }
880
+ checkPoint = 7;
881
+ //check point 8
882
+ // set local debug Teams app id in context.
883
+ if (postLocalDebugWithCtx.length === combinedPostLocalDebugResults.value.length) {
884
+ postLocalDebugWithCtx.map(function (plugin, index) {
885
+ var _a, _b;
886
+ if (plugin[2] === constants_2.PluginNames.APPST) {
887
+ if (tools_1.isMultiEnvEnabled()) {
888
+ (_a = ctx.localSettings) === null || _a === void 0 ? void 0 : _a.teamsApp.set(localSettingsConstants_1.LocalSettingsTeamsAppKeys.TeamsAppId, combinedPostLocalDebugResults.value[index]);
889
+ }
890
+ else {
891
+ (_b = ctx.envInfo.profile
892
+ .get(constants_2.GLOBAL_CONFIG)) === null || _b === void 0 ? void 0 : _b.set(constants_2.LOCAL_DEBUG_TEAMS_APP_ID, combinedPostLocalDebugResults.value[index]);
893
+ }
894
+ }
895
+ });
896
+ }
897
+ checkPoint = 8;
898
+ return teamsfx_api_1.ok(constants_2.Void);
899
+ }
900
+ catch (e) {
901
+ if (e instanceof teamsfx_api_1.UserError || e instanceof teamsfx_api_1.SystemError) {
902
+ return teamsfx_api_1.err(e);
903
+ }
904
+ return teamsfx_api_1.err(new teamsfx_api_1.SystemError("UnknownError", `check point ${checkPoint} - ${JSON.stringify(e)}`, "Solution"));
872
905
  }
873
- return teamsfx_api_1.ok(constants_2.Void);
874
906
  }
875
907
  async grantPermission(ctx) {
876
908
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
@@ -879,10 +911,20 @@ let TeamsAppSolution = class TeamsAppSolution {
879
911
  });
880
912
  const progressBar = (_b = ctx.ui) === null || _b === void 0 ? void 0 : _b.createProgressBar("Granting permission", 1);
881
913
  try {
882
- const result = await this.checkAndGetCurrentUserInfo(ctx);
914
+ const result = await this.getCurrentUserInfo(ctx);
883
915
  if (result.isErr()) {
884
916
  return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.GrantPermission, result.error, ctx.telemetryReporter));
885
917
  }
918
+ const stateResult = await this.getCurrentCollaborationState(ctx, result.value);
919
+ if (stateResult.state != permissionInterface_1.CollaborationState.OK) {
920
+ if (((_c = ctx.answers) === null || _c === void 0 ? void 0 : _c.platform) === teamsfx_api_1.Platform.CLI) {
921
+ (_d = ctx.ui) === null || _d === void 0 ? void 0 : _d.showMessage("warn", stateResult.message, false);
922
+ }
923
+ return teamsfx_api_1.ok({
924
+ state: stateResult.state,
925
+ message: stateResult.message,
926
+ });
927
+ }
886
928
  const email = ctx.answers["email"];
887
929
  if (!email || email === result.value.userPrincipalName) {
888
930
  return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.GrantPermission, teamsfx_api_1.returnUserError(new Error("Collaborator's email cannot be null or same as current user"), "Solution", constants_2.SolutionError.EmailCannotBeEmptyOrSame), ctx.telemetryReporter));
@@ -893,17 +935,25 @@ let TeamsAppSolution = class TeamsAppSolution {
893
935
  }
894
936
  progressBar === null || progressBar === void 0 ? void 0 : progressBar.start();
895
937
  progressBar === null || progressBar === void 0 ? void 0 : progressBar.next(`Grant permission for user ${email}`);
896
- (_c = ctx.envInfo.profile.get(constants_2.GLOBAL_CONFIG)) === null || _c === void 0 ? void 0 : _c.set(constants_2.USER_INFO, JSON.stringify(userInfo));
897
938
  const pluginsWithCtx = this.getPluginAndContextArray(ctx, [
898
939
  this.AadPlugin,
899
940
  this.AppStudioPlugin,
900
941
  ]);
901
942
  const grantPermissionWithCtx = pluginsWithCtx.map(([plugin, context]) => {
902
- var _a;
903
- return [(_a = plugin === null || plugin === void 0 ? void 0 : plugin.grantPermission) === null || _a === void 0 ? void 0 : _a.bind(plugin), context, plugin.name];
943
+ return [
944
+ (plugin === null || plugin === void 0 ? void 0 : plugin.grantPermission)
945
+ ? (ctx) => plugin.grantPermission.bind(plugin)(ctx, userInfo)
946
+ : undefined,
947
+ context,
948
+ plugin.name,
949
+ ];
904
950
  });
905
- if (((_d = ctx.answers) === null || _d === void 0 ? void 0 : _d.platform) === teamsfx_api_1.Platform.CLI) {
906
- const aadAppTenantId = (_f = (_e = ctx.envInfo.profile) === null || _e === void 0 ? void 0 : _e.get(constants_2.PluginNames.AAD)) === null || _f === void 0 ? void 0 : _f.get(constants_2.REMOTE_TENANT_ID);
951
+ if (((_e = ctx.answers) === null || _e === void 0 ? void 0 : _e.platform) === teamsfx_api_1.Platform.CLI) {
952
+ const aadAppTenantId = (_g = (_f = ctx.envInfo.profile) === null || _f === void 0 ? void 0 : _f.get(constants_2.PluginNames.AAD)) === null || _g === void 0 ? void 0 : _g.get(constants_2.REMOTE_TENANT_ID);
953
+ const envName = ctx.envInfo.envName;
954
+ if (!envName) {
955
+ return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.GrantPermission, teamsfx_api_1.returnSystemError(new Error("Failed to get env name."), "Solution", constants_2.SolutionError.FailedToGetEnvName), ctx.telemetryReporter));
956
+ }
907
957
  const message = [
908
958
  { content: `Account to grant permission: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
909
959
  { content: userInfo.userPrincipalName + "\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
@@ -911,12 +961,11 @@ let TeamsAppSolution = class TeamsAppSolution {
911
961
  content: `Starting grant permission for environment: `,
912
962
  color: teamsfx_api_1.Colors.BRIGHT_WHITE,
913
963
  },
914
- // Todo, when multi-environment is ready, we will update to current environment
915
- { content: "default\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
964
+ { content: `${envName}\n`, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
916
965
  { content: `Tenant ID: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
917
966
  { content: aadAppTenantId + "\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
918
967
  ];
919
- (_g = ctx.ui) === null || _g === void 0 ? void 0 : _g.showMessage("info", message, false);
968
+ (_h = ctx.ui) === null || _h === void 0 ? void 0 : _h.showMessage("info", message, false);
920
969
  }
921
970
  const results = await executor_1.executeConcurrently("", grantPermissionWithCtx);
922
971
  const permissions = [];
@@ -939,36 +988,38 @@ let TeamsAppSolution = class TeamsAppSolution {
939
988
  errorMsg += fxError.error.message + "\n";
940
989
  }
941
990
  }
942
- if (((_h = ctx.answers) === null || _h === void 0 ? void 0 : _h.platform) === teamsfx_api_1.Platform.CLI) {
991
+ if (((_j = ctx.answers) === null || _j === void 0 ? void 0 : _j.platform) === teamsfx_api_1.Platform.CLI) {
943
992
  for (const permission of permissions) {
944
993
  const message = [
945
- { content: `${(_j = permission.roles) === null || _j === void 0 ? void 0 : _j.join(",")} `, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
994
+ { content: `${(_k = permission.roles) === null || _k === void 0 ? void 0 : _k.join(",")} `, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
946
995
  { content: "permission has been granted to ", color: teamsfx_api_1.Colors.BRIGHT_WHITE },
947
996
  { content: permission.name, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
948
997
  { content: ", Resource ID: ", color: teamsfx_api_1.Colors.BRIGHT_WHITE },
949
998
  { content: `${permission.resourceId}`, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
950
999
  ];
951
- (_k = ctx.ui) === null || _k === void 0 ? void 0 : _k.showMessage("info", message, false);
1000
+ (_l = ctx.ui) === null || _l === void 0 ? void 0 : _l.showMessage("info", message, false);
952
1001
  }
953
- (_l = ctx.ui) === null || _l === void 0 ? void 0 : _l.showMessage("info", `\nSkip grant permission for Azure resources. You may want to handle that via Azure portal. `, false);
1002
+ (_m = ctx.ui) === null || _m === void 0 ? void 0 : _m.showMessage("info", `\nSkip grant permission for Azure resources. You may want to handle that via Azure portal. `, false);
954
1003
  if (errorMsg) {
955
1004
  for (const fxError of errors) {
956
- (_m = ctx.ui) === null || _m === void 0 ? void 0 : _m.showMessage("error", errorMsg, false);
1005
+ (_o = ctx.ui) === null || _o === void 0 ? void 0 : _o.showMessage("error", errorMsg, false);
957
1006
  }
958
1007
  }
959
1008
  }
960
1009
  if (errorMsg) {
961
1010
  return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.GrantPermission, teamsfx_api_1.returnUserError(new Error(errorMsg), "Solution", constants_2.SolutionError.FailedToGrantPermission), ctx.telemetryReporter));
962
1011
  }
963
- (_o = ctx.telemetryReporter) === null || _o === void 0 ? void 0 : _o.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.GrantPermission, {
1012
+ (_p = ctx.telemetryReporter) === null || _p === void 0 ? void 0 : _p.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.GrantPermission, {
964
1013
  [constants_2.SolutionTelemetryProperty.Component]: constants_2.SolutionTelemetryComponentName,
965
1014
  [constants_2.SolutionTelemetryProperty.Success]: constants_2.SolutionTelemetrySuccess.Yes,
966
1015
  });
967
- return teamsfx_api_1.ok(permissions);
1016
+ return teamsfx_api_1.ok({
1017
+ state: permissionInterface_1.CollaborationState.OK,
1018
+ permissions,
1019
+ });
968
1020
  }
969
1021
  finally {
970
1022
  await (progressBar === null || progressBar === void 0 ? void 0 : progressBar.end(true));
971
- (_p = ctx.envInfo.profile.get(constants_2.GLOBAL_CONFIG)) === null || _p === void 0 ? void 0 : _p.delete(constants_2.USER_INFO);
972
1023
  this.runningState = SolutionRunningState.Idle;
973
1024
  }
974
1025
  }
@@ -978,22 +1029,40 @@ let TeamsAppSolution = class TeamsAppSolution {
978
1029
  [constants_2.SolutionTelemetryProperty.Component]: constants_2.SolutionTelemetryComponentName,
979
1030
  });
980
1031
  try {
981
- const result = await this.checkAndGetCurrentUserInfo(ctx);
1032
+ const result = await this.getCurrentUserInfo(ctx);
982
1033
  if (result.isErr()) {
983
1034
  return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.CheckPermission, result.error, ctx.telemetryReporter));
984
1035
  }
1036
+ const stateResult = await this.getCurrentCollaborationState(ctx, result.value);
1037
+ if (stateResult.state != permissionInterface_1.CollaborationState.OK) {
1038
+ if (((_b = ctx.answers) === null || _b === void 0 ? void 0 : _b.platform) === teamsfx_api_1.Platform.CLI) {
1039
+ (_c = ctx.ui) === null || _c === void 0 ? void 0 : _c.showMessage("warn", stateResult.message, false);
1040
+ }
1041
+ return teamsfx_api_1.ok({
1042
+ state: stateResult.state,
1043
+ message: stateResult.message,
1044
+ });
1045
+ }
985
1046
  const userInfo = result.value;
986
- (_b = ctx.envInfo.profile.get(constants_2.GLOBAL_CONFIG)) === null || _b === void 0 ? void 0 : _b.set(constants_2.USER_INFO, JSON.stringify(userInfo));
987
1047
  const pluginsWithCtx = this.getPluginAndContextArray(ctx, [
988
1048
  this.AadPlugin,
989
1049
  this.AppStudioPlugin,
990
1050
  ]);
991
1051
  const checkPermissionWithCtx = pluginsWithCtx.map(([plugin, context]) => {
992
- var _a;
993
- return [(_a = plugin === null || plugin === void 0 ? void 0 : plugin.checkPermission) === null || _a === void 0 ? void 0 : _a.bind(plugin), context, plugin.name];
1052
+ return [
1053
+ (plugin === null || plugin === void 0 ? void 0 : plugin.checkPermission)
1054
+ ? (ctx) => plugin.checkPermission.bind(plugin)(ctx, userInfo)
1055
+ : undefined,
1056
+ context,
1057
+ plugin.name,
1058
+ ];
994
1059
  });
995
- if (((_c = ctx.answers) === null || _c === void 0 ? void 0 : _c.platform) === teamsfx_api_1.Platform.CLI) {
996
- const aadAppTenantId = (_e = (_d = ctx.envInfo.profile) === null || _d === void 0 ? void 0 : _d.get(constants_2.PluginNames.AAD)) === null || _e === void 0 ? void 0 : _e.get(constants_2.REMOTE_TENANT_ID);
1060
+ if (((_d = ctx.answers) === null || _d === void 0 ? void 0 : _d.platform) === teamsfx_api_1.Platform.CLI) {
1061
+ const aadAppTenantId = (_f = (_e = ctx.envInfo.profile) === null || _e === void 0 ? void 0 : _e.get(constants_2.PluginNames.AAD)) === null || _f === void 0 ? void 0 : _f.get(constants_2.REMOTE_TENANT_ID);
1062
+ const envName = ctx.envInfo.envName;
1063
+ if (!envName) {
1064
+ return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.CheckPermission, teamsfx_api_1.returnSystemError(new Error("Failed to get env name."), "Solution", constants_2.SolutionError.FailedToGetEnvName), ctx.telemetryReporter));
1065
+ }
997
1066
  const message = [
998
1067
  { content: `Account used to check: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
999
1068
  { content: userInfo.userPrincipalName + "\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
@@ -1001,12 +1070,11 @@ let TeamsAppSolution = class TeamsAppSolution {
1001
1070
  content: `Starting check permission for environment: `,
1002
1071
  color: teamsfx_api_1.Colors.BRIGHT_WHITE,
1003
1072
  },
1004
- // Todo, when multi-environment is ready, we will update to current environment
1005
- { content: "default\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
1073
+ { content: `${envName}\n`, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
1006
1074
  { content: `Tenant ID: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
1007
1075
  { content: aadAppTenantId + "\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
1008
1076
  ];
1009
- (_f = ctx.ui) === null || _f === void 0 ? void 0 : _f.showMessage("info", message, false);
1077
+ (_g = ctx.ui) === null || _g === void 0 ? void 0 : _g.showMessage("info", message, false);
1010
1078
  }
1011
1079
  const results = await executor_1.executeConcurrently("", checkPermissionWithCtx);
1012
1080
  const permissions = [];
@@ -1029,11 +1097,11 @@ let TeamsAppSolution = class TeamsAppSolution {
1029
1097
  errorMsg += fxError.error.message + "\n";
1030
1098
  }
1031
1099
  }
1032
- if (((_g = ctx.answers) === null || _g === void 0 ? void 0 : _g.platform) === teamsfx_api_1.Platform.CLI) {
1100
+ if (((_h = ctx.answers) === null || _h === void 0 ? void 0 : _h.platform) === teamsfx_api_1.Platform.CLI) {
1033
1101
  for (const permission of permissions) {
1034
1102
  const message = [
1035
1103
  { content: `Resource ID: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
1036
- { content: (_h = permission.resourceId) !== null && _h !== void 0 ? _h : "undefined", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
1104
+ { content: (_j = permission.resourceId) !== null && _j !== void 0 ? _j : "undefined", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
1037
1105
  { content: `, Resource Name: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
1038
1106
  { content: permission.name, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
1039
1107
  { content: `, Permission: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
@@ -1042,7 +1110,7 @@ let TeamsAppSolution = class TeamsAppSolution {
1042
1110
  color: teamsfx_api_1.Colors.BRIGHT_MAGENTA,
1043
1111
  },
1044
1112
  ];
1045
- (_j = ctx.ui) === null || _j === void 0 ? void 0 : _j.showMessage("info", message, false);
1113
+ (_k = ctx.ui) === null || _k === void 0 ? void 0 : _k.showMessage("info", message, false);
1046
1114
  }
1047
1115
  }
1048
1116
  if (errorMsg) {
@@ -1050,7 +1118,7 @@ let TeamsAppSolution = class TeamsAppSolution {
1050
1118
  }
1051
1119
  const aadPermission = permissions.find((permission) => permission.name === "Azure AD App");
1052
1120
  const teamsAppPermission = permissions.find((permission) => permission.name === "Teams App");
1053
- (_k = ctx.telemetryReporter) === null || _k === void 0 ? void 0 : _k.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.CheckPermission, {
1121
+ (_l = ctx.telemetryReporter) === null || _l === void 0 ? void 0 : _l.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.CheckPermission, {
1054
1122
  [constants_2.SolutionTelemetryProperty.Component]: constants_2.SolutionTelemetryComponentName,
1055
1123
  [constants_2.SolutionTelemetryProperty.Success]: constants_2.SolutionTelemetrySuccess.Yes,
1056
1124
  [constants_2.SolutionTelemetryProperty.AadPermission]: (aadPermission === null || aadPermission === void 0 ? void 0 : aadPermission.roles)
@@ -1060,34 +1128,55 @@ let TeamsAppSolution = class TeamsAppSolution {
1060
1128
  ? teamsAppPermission.roles.join(";")
1061
1129
  : "undefined",
1062
1130
  });
1063
- return teamsfx_api_1.ok(permissions);
1131
+ return teamsfx_api_1.ok({
1132
+ state: permissionInterface_1.CollaborationState.OK,
1133
+ permissions,
1134
+ });
1064
1135
  }
1065
1136
  finally {
1066
- (_l = ctx.envInfo.profile.get(constants_2.GLOBAL_CONFIG)) === null || _l === void 0 ? void 0 : _l.delete(constants_2.USER_INFO);
1067
1137
  this.runningState = SolutionRunningState.Idle;
1068
1138
  }
1069
1139
  }
1070
1140
  async listCollaborator(ctx) {
1071
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
1141
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1072
1142
  (_a = ctx.telemetryReporter) === null || _a === void 0 ? void 0 : _a.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.ListCollaboratorStart, {
1073
1143
  [constants_2.SolutionTelemetryProperty.Component]: constants_2.SolutionTelemetryComponentName,
1074
1144
  });
1075
1145
  try {
1076
- const result = await this.checkAndGetCurrentUserInfo(ctx);
1146
+ const result = await this.getCurrentUserInfo(ctx);
1077
1147
  if (result.isErr()) {
1078
1148
  return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.ListCollaborator, result.error, ctx.telemetryReporter));
1079
1149
  }
1150
+ const stateResult = await this.getCurrentCollaborationState(ctx, result.value);
1151
+ if (stateResult.state != permissionInterface_1.CollaborationState.OK) {
1152
+ if (((_b = ctx.answers) === null || _b === void 0 ? void 0 : _b.platform) === teamsfx_api_1.Platform.CLI) {
1153
+ (_c = ctx.ui) === null || _c === void 0 ? void 0 : _c.showMessage("warn", stateResult.message, false);
1154
+ }
1155
+ return teamsfx_api_1.ok({
1156
+ state: stateResult.state,
1157
+ message: stateResult.message,
1158
+ });
1159
+ }
1080
1160
  const userInfo = result.value;
1081
1161
  const pluginsWithCtx = this.getPluginAndContextArray(ctx, [
1082
1162
  this.AppStudioPlugin,
1083
1163
  this.AadPlugin,
1084
1164
  ]);
1085
1165
  const listCollaboratorWithCtx = pluginsWithCtx.map(([plugin, context]) => {
1086
- var _a;
1087
- return [(_a = plugin === null || plugin === void 0 ? void 0 : plugin.listCollaborator) === null || _a === void 0 ? void 0 : _a.bind(plugin), context, plugin.name];
1166
+ return [
1167
+ (plugin === null || plugin === void 0 ? void 0 : plugin.listCollaborator)
1168
+ ? (ctx) => plugin.listCollaborator.bind(plugin)(ctx, userInfo)
1169
+ : undefined,
1170
+ context,
1171
+ plugin.name,
1172
+ ];
1088
1173
  });
1089
- if (((_b = ctx.answers) === null || _b === void 0 ? void 0 : _b.platform) === teamsfx_api_1.Platform.CLI) {
1090
- const aadAppTenantId = (_d = (_c = ctx.envInfo.profile) === null || _c === void 0 ? void 0 : _c.get(constants_2.PluginNames.AAD)) === null || _d === void 0 ? void 0 : _d.get(constants_2.REMOTE_TENANT_ID);
1174
+ if (((_d = ctx.answers) === null || _d === void 0 ? void 0 : _d.platform) === teamsfx_api_1.Platform.CLI) {
1175
+ const aadAppTenantId = (_f = (_e = ctx.envInfo.profile) === null || _e === void 0 ? void 0 : _e.get(constants_2.PluginNames.AAD)) === null || _f === void 0 ? void 0 : _f.get(constants_2.REMOTE_TENANT_ID);
1176
+ const envName = ctx.envInfo.envName;
1177
+ if (!envName) {
1178
+ return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.ListCollaborator, teamsfx_api_1.returnSystemError(new Error("Failed to get env name."), "Solution", constants_2.SolutionError.FailedToGetEnvName), ctx.telemetryReporter));
1179
+ }
1091
1180
  const message = [
1092
1181
  { content: `Account used to check: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
1093
1182
  { content: userInfo.userPrincipalName + "\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
@@ -1095,12 +1184,11 @@ let TeamsAppSolution = class TeamsAppSolution {
1095
1184
  content: `Starting list all collaborators for environment: `,
1096
1185
  color: teamsfx_api_1.Colors.BRIGHT_WHITE,
1097
1186
  },
1098
- // Todo, when multi-environment is ready, we will update to current environment
1099
- { content: "default\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
1187
+ { content: `${envName}\n`, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
1100
1188
  { content: `Tenant ID: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
1101
1189
  { content: aadAppTenantId + "\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
1102
1190
  ];
1103
- (_e = ctx.ui) === null || _e === void 0 ? void 0 : _e.showMessage("info", message, false);
1191
+ (_g = ctx.ui) === null || _g === void 0 ? void 0 : _g.showMessage("info", message, false);
1104
1192
  }
1105
1193
  const results = await executor_1.executeConcurrently("", listCollaboratorWithCtx);
1106
1194
  const errors = [];
@@ -1126,14 +1214,14 @@ let TeamsAppSolution = class TeamsAppSolution {
1126
1214
  const aadOwner = aadOwners.find((owner) => owner.userObjectId === teamsAppOwner.userObjectId);
1127
1215
  collaborators.push({
1128
1216
  // Sometimes app studio will return null as userPrincipalName, thus using aad's instead.
1129
- userPrincipalName: (_g = (_f = teamsAppOwner.userPrincipalName) !== null && _f !== void 0 ? _f : aadOwner === null || aadOwner === void 0 ? void 0 : aadOwner.userPrincipalName) !== null && _g !== void 0 ? _g : teamsAppOwner.userObjectId,
1217
+ userPrincipalName: (_j = (_h = teamsAppOwner.userPrincipalName) !== null && _h !== void 0 ? _h : aadOwner === null || aadOwner === void 0 ? void 0 : aadOwner.userPrincipalName) !== null && _j !== void 0 ? _j : teamsAppOwner.userObjectId,
1130
1218
  userObjectId: teamsAppOwner.userObjectId,
1131
1219
  isAadOwner: aadOwner ? true : false,
1132
1220
  aadResourceId: aadOwner ? aadOwner.resourceId : undefined,
1133
1221
  teamsAppResourceId: teamsAppOwner.resourceId,
1134
1222
  });
1135
1223
  }
1136
- if (((_h = ctx.answers) === null || _h === void 0 ? void 0 : _h.platform) === teamsfx_api_1.Platform.CLI) {
1224
+ if (((_k = ctx.answers) === null || _k === void 0 ? void 0 : _k.platform) === teamsfx_api_1.Platform.CLI) {
1137
1225
  for (const collaborator of collaborators) {
1138
1226
  const message = [
1139
1227
  { content: `Account: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
@@ -1149,41 +1237,60 @@ let TeamsAppSolution = class TeamsAppSolution {
1149
1237
  message.push({ content: `\nResource ID: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE }, { content: collaborator.aadResourceId, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA }, { content: `, Resource Name: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE }, { content: `AAD App`, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA }, { content: `, Permission: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE }, { content: `Owner`, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA });
1150
1238
  }
1151
1239
  message.push({ content: "\n", color: teamsfx_api_1.Colors.BRIGHT_WHITE });
1152
- (_j = ctx.ui) === null || _j === void 0 ? void 0 : _j.showMessage("info", message, false);
1240
+ (_l = ctx.ui) === null || _l === void 0 ? void 0 : _l.showMessage("info", message, false);
1153
1241
  }
1154
1242
  }
1155
1243
  const aadOwnerCount = collaborators.filter((collaborator) => collaborator.aadResourceId && collaborator.isAadOwner).length;
1156
- (_k = ctx.telemetryReporter) === null || _k === void 0 ? void 0 : _k.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.ListCollaborator, {
1244
+ (_m = ctx.telemetryReporter) === null || _m === void 0 ? void 0 : _m.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.ListCollaborator, {
1157
1245
  [constants_2.SolutionTelemetryProperty.Component]: constants_2.SolutionTelemetryComponentName,
1158
1246
  [constants_2.SolutionTelemetryProperty.Success]: constants_2.SolutionTelemetrySuccess.Yes,
1159
1247
  [constants_2.SolutionTelemetryProperty.CollaboratorCount]: collaborators.length.toString(),
1160
1248
  [constants_2.SolutionTelemetryProperty.AadOwnerCount]: aadOwnerCount.toString(),
1161
1249
  });
1162
- return teamsfx_api_1.ok(collaborators);
1250
+ return teamsfx_api_1.ok({
1251
+ collaborators: collaborators,
1252
+ state: permissionInterface_1.CollaborationState.OK,
1253
+ });
1163
1254
  }
1164
1255
  finally {
1165
1256
  this.runningState = SolutionRunningState.Idle;
1166
1257
  }
1167
1258
  }
1168
- async checkAndGetCurrentUserInfo(ctx) {
1259
+ async getCurrentUserInfo(ctx) {
1260
+ const user = await this.getUserInfo(ctx);
1261
+ if (!user) {
1262
+ return teamsfx_api_1.err(teamsfx_api_1.returnSystemError(new Error("Failed to retrieve current user info from graph token"), "Solution", constants_2.SolutionError.FailedToRetrieveUserInfo));
1263
+ }
1264
+ return teamsfx_api_1.ok(user);
1265
+ }
1266
+ getCurrentCollaborationState(ctx, user) {
1169
1267
  var _a, _b;
1170
1268
  const canProcess = this.checkWhetherSolutionIsIdle();
1171
1269
  if (canProcess.isErr()) {
1172
- return canProcess;
1270
+ return {
1271
+ state: permissionInterface_1.CollaborationState.SolutionIsNotIdle,
1272
+ message: canProcess.error.message,
1273
+ };
1173
1274
  }
1174
1275
  const provisioned = this.checkWetherProvisionSucceeded(ctx.envInfo.profile);
1175
1276
  if (!provisioned) {
1176
- return teamsfx_api_1.err(teamsfx_api_1.returnUserError(new Error("Failed to process because the resources have not been provisioned yet. Make sure you do the provision first."), "Solution", constants_2.SolutionError.CannotProcessBeforeProvision));
1177
- }
1178
- const user = await this.getUserInfo(ctx);
1179
- if (!user) {
1180
- return teamsfx_api_1.err(teamsfx_api_1.returnSystemError(new Error("Failed to retrieve current user info from graph token"), "Solution", constants_2.SolutionError.FailedToRetrieveUserInfo));
1277
+ const warningMsg = "Failed to process because the resources have not been provisioned yet. Make sure you do the provision first.";
1278
+ return {
1279
+ state: permissionInterface_1.CollaborationState.NotProvisioned,
1280
+ message: warningMsg,
1281
+ };
1181
1282
  }
1182
1283
  const aadAppTenantId = (_b = (_a = ctx.envInfo.profile) === null || _a === void 0 ? void 0 : _a.get(constants_2.PluginNames.AAD)) === null || _b === void 0 ? void 0 : _b.get(constants_2.REMOTE_TENANT_ID);
1183
1284
  if (!aadAppTenantId || user.tenantId != aadAppTenantId) {
1184
- return teamsfx_api_1.err(teamsfx_api_1.returnUserError(new Error("Tenant id of your account and the provisioned Azure AD app does not match. Please check whether you logined with wrong account."), "Solution", constants_2.SolutionError.M365AccountNotMatch));
1285
+ const warningMsg = "Tenant id of your account and the provisioned Azure AD app does not match. Please check whether you logined with wrong account.";
1286
+ return {
1287
+ state: permissionInterface_1.CollaborationState.M365TenantNotMatch,
1288
+ message: warningMsg,
1289
+ };
1185
1290
  }
1186
- return teamsfx_api_1.ok(user);
1291
+ return {
1292
+ state: permissionInterface_1.CollaborationState.OK,
1293
+ };
1187
1294
  }
1188
1295
  loadTeamsAppTenantId(ctx, isLocalDebug, appStudioToken) {
1189
1296
  return utils_1.parseTeamsAppTenantId(appStudioToken).andThen((teamsAppTenantId) => {