@microsoft/teamsfx-react 2.0.0-experimental.0 → 2.0.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 (42) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +12 -2
  3. package/build/{index.d.ts → cjs/index.d.ts} +4 -3
  4. package/build/cjs/index.d.ts.map +1 -0
  5. package/build/{index.js → cjs/index.js} +13 -11
  6. package/build/{useData.d.ts → cjs/useData.d.ts} +33 -33
  7. package/build/cjs/useData.d.ts.map +1 -0
  8. package/build/cjs/useData.js +47 -0
  9. package/build/{useGraph.d.ts → cjs/useGraph.d.ts} +18 -18
  10. package/build/cjs/useGraph.d.ts.map +1 -0
  11. package/build/cjs/useGraph.js +72 -0
  12. package/build/cjs/useTeams.d.ts +31 -0
  13. package/build/cjs/useTeams.d.ts.map +1 -0
  14. package/build/cjs/useTeams.js +82 -0
  15. package/build/{useTeamsFx.d.ts → cjs/useTeamsFx.d.ts} +41 -41
  16. package/build/cjs/useTeamsFx.d.ts.map +1 -0
  17. package/build/cjs/useTeamsFx.js +34 -0
  18. package/build/esm/index.d.ts +5 -0
  19. package/build/esm/index.d.ts.map +1 -0
  20. package/build/esm/index.js +6 -0
  21. package/build/esm/useData.d.ts +34 -0
  22. package/build/esm/useData.d.ts.map +1 -0
  23. package/build/esm/useData.js +43 -0
  24. package/build/esm/useGraph.d.ts +19 -0
  25. package/build/esm/useGraph.d.ts.map +1 -0
  26. package/build/esm/useGraph.js +68 -0
  27. package/build/esm/useTeams.d.ts +31 -0
  28. package/build/esm/useTeams.d.ts.map +1 -0
  29. package/build/esm/useTeams.js +78 -0
  30. package/build/esm/useTeamsFx.d.ts +42 -0
  31. package/build/esm/useTeamsFx.d.ts.map +1 -0
  32. package/build/esm/useTeamsFx.js +30 -0
  33. package/package.json +33 -19
  34. package/CHANGELOG.md +0 -4
  35. package/NOTICE.txt +0 -14833
  36. package/build/index.d.ts.map +0 -1
  37. package/build/useData.d.ts.map +0 -1
  38. package/build/useData.js +0 -45
  39. package/build/useGraph.d.ts.map +0 -1
  40. package/build/useGraph.js +0 -57
  41. package/build/useTeamsFx.d.ts.map +0 -1
  42. package/build/useTeamsFx.js +0 -30
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useData.d.ts","sourceRoot":"","sources":["../src/useData.ts"],"names":[],"mappings":"AAKA,aAAK,KAAK,CAAC,CAAC,IAAI;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,CAAC,CAAC;IACT;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAOF,oBAAY,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,GAAG;IAC/B;;OAEG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC;AAeF;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,cAAc,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAChC,OAAO,CAAC,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,GAC9B,IAAI,CAAC,CAAC,CAAC,CAeT"}
package/build/useData.js DELETED
@@ -1,45 +0,0 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT license.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.useData = void 0;
6
- const react_1 = require("react");
7
- const createReducer = () => (state, action) => {
8
- switch (action.type) {
9
- case "loading":
10
- return { data: state.data, loading: true };
11
- case "result":
12
- return { data: action.result, loading: false };
13
- case "error":
14
- return { loading: false, error: action.error };
15
- }
16
- };
17
- /**
18
- * Helper function to fetch data with status and error.
19
- *
20
- * @param fetchDataAsync - async function of how to fetch data
21
- * @param options - if autoLoad is true, reload data immediately
22
- * @returns data, loading status, error and reload function
23
- *
24
- * @beta
25
- */
26
- function useData(fetchDataAsync, options) {
27
- var _a;
28
- const auto = (_a = options === null || options === void 0 ? void 0 : options.autoLoad) !== null && _a !== void 0 ? _a : true;
29
- const [{ data, loading, error }, dispatch] = (0, react_1.useReducer)(createReducer(), {
30
- loading: auto,
31
- });
32
- function reload() {
33
- if (!loading)
34
- dispatch({ type: "loading" });
35
- fetchDataAsync()
36
- .then((data) => dispatch({ type: "result", result: data }))
37
- .catch((error) => dispatch({ type: "error", error }));
38
- }
39
- (0, react_1.useEffect)(() => {
40
- if (auto)
41
- reload();
42
- }, []);
43
- return { data, loading, error, reload };
44
- }
45
- exports.useData = useData;
@@ -1 +0,0 @@
1
- {"version":3,"file":"useGraph.d.ts","sourceRoot":"","sources":["../src/useGraph.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAW,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAA6C,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,MAAM,EAAc,MAAM,mCAAmC,CAAC;AAGvE,aAAK,WAAW,GAAG;IACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EACrF,OAAO,CAAC,EAAE,WAAW,GACpB,IAAI,CAAC,CAAC,CAAC,CAiCT"}
package/build/useGraph.js DELETED
@@ -1,57 +0,0 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT license.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.useGraph = void 0;
6
- const useData_1 = require("./useData");
7
- const teamsfx_1 = require("@microsoft/teamsfx");
8
- const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
9
- const react_1 = require("react");
10
- /**
11
- * Helper function to call Microsoft Graph API with authentication.
12
- *
13
- * @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
14
- * @param options - teamsfx instance and OAuth resource scope.
15
- * @returns data, loading status, error and reload function
16
- *
17
- * @beta
18
- */
19
- function useGraph(fetchGraphDataAsync, options) {
20
- const { scope, teamsfx } = Object.assign({ scope: ["User.Read"], teamsfx: new teamsfx_1.TeamsFx() }, options);
21
- const [needConsent, setNeedConsent] = (0, react_1.useState)(false);
22
- const { data, error, loading, reload } = (0, useData_1.useData)(async () => {
23
- var _a, _b;
24
- if (needConsent) {
25
- try {
26
- await teamsfx.login(scope);
27
- // Important: tokens are stored in sessionStorage, read more here: https://aka.ms/teamsfx-session-storage-notice
28
- }
29
- catch (err) {
30
- if (err instanceof teamsfx_1.ErrorWithCode && ((_a = err.message) === null || _a === void 0 ? void 0 : _a.includes("CancelledByUser"))) {
31
- const helpLink = "https://aka.ms/teamsfx-auth-code-flow";
32
- err.message +=
33
- '\nIf you see "AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application" ' +
34
- "in the popup window, you may be using unmatched version for TeamsFx SDK (version >= 0.5.0) and Teams Toolkit (version < 3.3.0) or " +
35
- `cli (version < 0.11.0). Please refer to the help link for how to fix the issue: ${helpLink}`;
36
- }
37
- throw err;
38
- }
39
- }
40
- try {
41
- const graph = (0, teamsfx_1.createMicrosoftGraphClient)(teamsfx, scope);
42
- const graphData = await fetchGraphDataAsync(graph, teamsfx, scope);
43
- return graphData;
44
- }
45
- catch (err) {
46
- if (err instanceof microsoft_graph_client_1.GraphError && ((_b = err.code) === null || _b === void 0 ? void 0 : _b.includes("UiRequiredError"))) {
47
- // Silently fail for user didn't consent error
48
- setNeedConsent(true);
49
- }
50
- else {
51
- throw err;
52
- }
53
- }
54
- });
55
- return { data, error, loading, reload };
56
- }
57
- exports.useGraph = useGraph;
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTeamsFx.d.ts","sourceRoot":"","sources":["../src/useTeamsFx.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyC,OAAO,EAAgB,MAAM,oBAAoB,CAAC;AAElG,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG1D,oBAAY,cAAc,GAAG;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;IACrB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IAEH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,cAAc,CAYjF"}
@@ -1,30 +0,0 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT license.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.useTeamsFx = void 0;
6
- const teamsfx_1 = require("@microsoft/teamsfx");
7
- const msteams_react_base_component_1 = require("msteams-react-base-component");
8
- const useData_1 = require("./useData");
9
- /**
10
- * Initialize TeamsFx SDK with customized configuration.
11
- *
12
- * @param teamsfxConfig - custom configuration to override default ones.
13
- * @returns TeamsFxContext object
14
- *
15
- * @beta
16
- */
17
- function useTeamsFx(teamsfxConfig) {
18
- const [result] = (0, msteams_react_base_component_1.useTeams)({});
19
- const { data, error, loading } = (0, useData_1.useData)(async () => {
20
- if (process.env.NODE_ENV === "development") {
21
- (0, teamsfx_1.setLogLevel)(teamsfx_1.LogLevel.Verbose);
22
- (0, teamsfx_1.setLogFunction)((level, message) => {
23
- console.log(message);
24
- });
25
- }
26
- return new teamsfx_1.TeamsFx(teamsfx_1.IdentityType.User, teamsfxConfig);
27
- });
28
- return Object.assign({ teamsfx: data, error, loading }, result);
29
- }
30
- exports.useTeamsFx = useTeamsFx;