@microsoft/teamsfx-react 1.0.6-rc.1 → 2.0.0-alpha.28543dcd0.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.
- package/README.md +12 -2
- package/build/{index.d.ts → cjs/index.d.ts} +1 -0
- package/build/cjs/index.d.ts.map +1 -0
- package/build/{index.js → cjs/index.js} +3 -1
- package/build/{useData.d.ts → cjs/useData.d.ts} +0 -0
- package/build/cjs/useData.d.ts.map +1 -0
- package/build/cjs/useData.js +47 -0
- package/build/{useGraph.d.ts → cjs/useGraph.d.ts} +0 -0
- package/build/cjs/useGraph.d.ts.map +1 -0
- package/build/cjs/useGraph.js +72 -0
- package/build/cjs/useTeams.d.ts +31 -0
- package/build/cjs/useTeams.d.ts.map +1 -0
- package/build/cjs/useTeams.js +82 -0
- package/build/{useTeamsFx.d.ts → cjs/useTeamsFx.d.ts} +0 -0
- package/build/cjs/useTeamsFx.d.ts.map +1 -0
- package/build/cjs/useTeamsFx.js +34 -0
- package/build/esm/index.d.ts +5 -0
- package/build/esm/index.d.ts.map +1 -0
- package/build/esm/index.js +6 -0
- package/build/esm/useData.d.ts +34 -0
- package/build/esm/useData.d.ts.map +1 -0
- package/build/esm/useData.js +43 -0
- package/build/esm/useGraph.d.ts +19 -0
- package/build/esm/useGraph.d.ts.map +1 -0
- package/build/esm/useGraph.js +68 -0
- package/build/esm/useTeams.d.ts +31 -0
- package/build/esm/useTeams.d.ts.map +1 -0
- package/build/esm/useTeams.js +78 -0
- package/build/esm/useTeamsFx.d.ts +42 -0
- package/build/esm/useTeamsFx.d.ts.map +1 -0
- package/build/esm/useTeamsFx.js +30 -0
- package/package.json +34 -21
- package/build/index.d.ts.map +0 -1
- package/build/useData.d.ts.map +0 -1
- package/build/useData.js +0 -45
- package/build/useGraph.d.ts.map +0 -1
- package/build/useGraph.js +0 -58
- package/build/useTeamsFx.d.ts.map +0 -1
- package/build/useTeamsFx.js +0 -30
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Please check the [README](https://github.com/OfficeDev/TeamsFx/blob/main/package
|
|
|
21
21
|
### Prerequisites
|
|
22
22
|
|
|
23
23
|
- Node.js version 10.x.x or higher
|
|
24
|
-
- TeamsFx SDK version 0.6.0 or higher
|
|
24
|
+
- TeamsFx SDK version 0.6.0 or higher
|
|
25
25
|
- A project created by the Teams Toolkit VS Code extension or `teamsfx` CLI tool.
|
|
26
26
|
|
|
27
27
|
### Install the `@microsoft/teamsfx-react` package
|
|
@@ -32,7 +32,12 @@ Install the TeamsFx SDK for TypeScript/JavaScript with `npm`:
|
|
|
32
32
|
npm install @microsoft/teamsfx-react
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
Please also install the peer dependencies if you are using npm 6.
|
|
35
|
+
Please also install the peer dependencies if you are using npm 6.
|
|
36
|
+
```bash
|
|
37
|
+
npm install @microsoft/teamsfx@^2.0.0 @microsoft/teams-js@^2.0.0 react@^16.8.6 react-dom@^16.8.6 @fluentui/react-northstar@^0.62.0 msteams-react-base-component@^3.1.1
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Note that for `@microsoft/teamsfx-react@^2.0.0`, it depends on `@microsoft/teamsfx@^2.0.0` and `@microsoft/teams-js@^2.0.0`. If you wish to use lower versions, please install the peer dependencies as follows:
|
|
36
41
|
```bash
|
|
37
42
|
npm install @microsoft/teamsfx@^0.6.0 react@^16.8.6 @fluentui/react-northstar@^0.60.1 msteams-react-base-component@^3.1.1
|
|
38
43
|
```
|
|
@@ -92,6 +97,11 @@ Fundamental helper hook function to do asynchronized operation like fetch data f
|
|
|
92
97
|
It returns custom data, loading status, error object and reload function.
|
|
93
98
|
By default, it will fetch the data once the component has been initialized.
|
|
94
99
|
|
|
100
|
+
### useTeams
|
|
101
|
+
The hook is based on the Microsoft Teams JavaScript SDK, the Fluent UI components and Microsoft Graph Toolkit, merged from [msteams-react-base-component](https://github.com/wictorwilen/msteams-react-base-component).
|
|
102
|
+
It returns a tuple of where an object of properties are in the first field and an object of methods in the second.
|
|
103
|
+
If you want to manually set the initial theme, please pass the config object to `useTeams()`.
|
|
104
|
+
|
|
95
105
|
### useTeamsFx
|
|
96
106
|
Initialize TeamsFx and Teams JS SDK, in a development environment, verbose logging message will be printed to console.
|
|
97
107
|
It returns the TeamsFx instance as data.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,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"}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
3
|
// Licensed under the MIT license.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.useGraph = exports.useTeamsFx = exports.useData = void 0;
|
|
5
|
+
exports.useGraph = exports.useTeamsFx = exports.useData = exports.useTeams = void 0;
|
|
6
|
+
var useTeams_1 = require("./useTeams");
|
|
7
|
+
Object.defineProperty(exports, "useTeams", { enumerable: true, get: function () { return useTeams_1.useTeams; } });
|
|
6
8
|
var useData_1 = require("./useData");
|
|
7
9
|
Object.defineProperty(exports, "useData", { enumerable: true, get: function () { return useData_1.useData; } });
|
|
8
10
|
var useTeamsFx_1 = require("./useTeamsFx");
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
var react_1 = require("react");
|
|
7
|
+
var createReducer = function () {
|
|
8
|
+
return function (state, action) {
|
|
9
|
+
switch (action.type) {
|
|
10
|
+
case "loading":
|
|
11
|
+
return { data: state.data, loading: true };
|
|
12
|
+
case "result":
|
|
13
|
+
return { data: action.result, loading: false };
|
|
14
|
+
case "error":
|
|
15
|
+
return { loading: false, error: action.error };
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Helper function to fetch data with status and error.
|
|
21
|
+
*
|
|
22
|
+
* @param fetchDataAsync - async function of how to fetch data
|
|
23
|
+
* @param options - if autoLoad is true, reload data immediately
|
|
24
|
+
* @returns data, loading status, error and reload function
|
|
25
|
+
*
|
|
26
|
+
* @beta
|
|
27
|
+
*/
|
|
28
|
+
function useData(fetchDataAsync, options) {
|
|
29
|
+
var _a;
|
|
30
|
+
var auto = (_a = options === null || options === void 0 ? void 0 : options.autoLoad) !== null && _a !== void 0 ? _a : true;
|
|
31
|
+
var _b = (0, react_1.useReducer)(createReducer(), {
|
|
32
|
+
loading: auto,
|
|
33
|
+
}), _c = _b[0], data = _c.data, loading = _c.loading, error = _c.error, dispatch = _b[1];
|
|
34
|
+
function reload() {
|
|
35
|
+
if (!loading)
|
|
36
|
+
dispatch({ type: "loading" });
|
|
37
|
+
fetchDataAsync()
|
|
38
|
+
.then(function (data) { return dispatch({ type: "result", result: data }); })
|
|
39
|
+
.catch(function (error) { return dispatch({ type: "error", error: error }); });
|
|
40
|
+
}
|
|
41
|
+
(0, react_1.useEffect)(function () {
|
|
42
|
+
if (auto)
|
|
43
|
+
reload();
|
|
44
|
+
}, []);
|
|
45
|
+
return { data: data, loading: loading, error: error, reload: reload };
|
|
46
|
+
}
|
|
47
|
+
exports.useData = useData;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
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,CAkCT"}
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
var tslib_1 = require("tslib");
|
|
7
|
+
var useData_1 = require("./useData");
|
|
8
|
+
var teamsfx_1 = require("@microsoft/teamsfx");
|
|
9
|
+
var microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
|
|
10
|
+
var react_1 = require("react");
|
|
11
|
+
/**
|
|
12
|
+
* Helper function to call Microsoft Graph API with authentication.
|
|
13
|
+
*
|
|
14
|
+
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
15
|
+
* @param options - teamsfx instance and OAuth resource scope.
|
|
16
|
+
* @returns data, loading status, error and reload function
|
|
17
|
+
*
|
|
18
|
+
* @beta
|
|
19
|
+
*/
|
|
20
|
+
function useGraph(fetchGraphDataAsync, options) {
|
|
21
|
+
var _this = this;
|
|
22
|
+
var _a = tslib_1.__assign({ scope: ["User.Read"], teamsfx: new teamsfx_1.TeamsFx() }, options), scope = _a.scope, teamsfx = _a.teamsfx;
|
|
23
|
+
var _b = (0, react_1.useState)(false), needConsent = _b[0], setNeedConsent = _b[1];
|
|
24
|
+
var _c = (0, useData_1.useData)(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
25
|
+
var err_1, helpLink, graph, graphData, err_2;
|
|
26
|
+
var _a, _b;
|
|
27
|
+
return tslib_1.__generator(this, function (_c) {
|
|
28
|
+
switch (_c.label) {
|
|
29
|
+
case 0:
|
|
30
|
+
if (!needConsent) return [3 /*break*/, 4];
|
|
31
|
+
_c.label = 1;
|
|
32
|
+
case 1:
|
|
33
|
+
_c.trys.push([1, 3, , 4]);
|
|
34
|
+
return [4 /*yield*/, teamsfx.login(scope)];
|
|
35
|
+
case 2:
|
|
36
|
+
_c.sent();
|
|
37
|
+
setNeedConsent(false);
|
|
38
|
+
return [3 /*break*/, 4];
|
|
39
|
+
case 3:
|
|
40
|
+
err_1 = _c.sent();
|
|
41
|
+
if (err_1 instanceof teamsfx_1.ErrorWithCode && ((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("CancelledByUser"))) {
|
|
42
|
+
helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
43
|
+
err_1.message +=
|
|
44
|
+
'\nIf you see "AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application" ' +
|
|
45
|
+
"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 " +
|
|
46
|
+
"cli (version < 0.11.0). Please refer to the help link for how to fix the issue: ".concat(helpLink);
|
|
47
|
+
}
|
|
48
|
+
throw err_1;
|
|
49
|
+
case 4:
|
|
50
|
+
_c.trys.push([4, 6, , 7]);
|
|
51
|
+
graph = (0, teamsfx_1.createMicrosoftGraphClient)(teamsfx, scope);
|
|
52
|
+
return [4 /*yield*/, fetchGraphDataAsync(graph, teamsfx, scope)];
|
|
53
|
+
case 5:
|
|
54
|
+
graphData = _c.sent();
|
|
55
|
+
return [2 /*return*/, graphData];
|
|
56
|
+
case 6:
|
|
57
|
+
err_2 = _c.sent();
|
|
58
|
+
if (err_2 instanceof microsoft_graph_client_1.GraphError && ((_b = err_2.code) === null || _b === void 0 ? void 0 : _b.includes("UiRequiredError"))) {
|
|
59
|
+
// Silently fail for user didn't consent error
|
|
60
|
+
setNeedConsent(true);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw err_2;
|
|
64
|
+
}
|
|
65
|
+
return [3 /*break*/, 7];
|
|
66
|
+
case 7: return [2 /*return*/];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}); }), data = _c.data, error = _c.error, loading = _c.loading, reload = _c.reload;
|
|
70
|
+
return { data: data, error: error, loading: loading, reload: reload };
|
|
71
|
+
}
|
|
72
|
+
exports.useGraph = useGraph;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { app } from "@microsoft/teams-js";
|
|
2
|
+
import { ThemePrepared } from "@fluentui/react-northstar";
|
|
3
|
+
/**
|
|
4
|
+
* Microsoft Teams React hook
|
|
5
|
+
* @param options optional options
|
|
6
|
+
* @returns A tuple with properties and methods
|
|
7
|
+
* properties:
|
|
8
|
+
* - inTeams: boolean = true if inside Microsoft Teams
|
|
9
|
+
* - fullscreen: boolean = true if in full screen mode
|
|
10
|
+
* - theme: Fluent UI Theme
|
|
11
|
+
* - themeString: string - representation of the theme (default, dark or contrast)
|
|
12
|
+
* - context - the Microsoft Teams JS SDK context
|
|
13
|
+
* methods:
|
|
14
|
+
* - setTheme - manually set the theme
|
|
15
|
+
*/
|
|
16
|
+
export declare function useTeams(options?: {
|
|
17
|
+
initialTheme?: string;
|
|
18
|
+
setThemeHandler?: (theme?: string) => void;
|
|
19
|
+
}): [
|
|
20
|
+
{
|
|
21
|
+
inTeams?: boolean;
|
|
22
|
+
fullScreen?: boolean;
|
|
23
|
+
theme: ThemePrepared;
|
|
24
|
+
themeString: string;
|
|
25
|
+
context?: app.Context;
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
setTheme: (theme: string | undefined) => void;
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
//# sourceMappingURL=useTeams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTeams.d.ts","sourceRoot":"","sources":["../../src/useTeams.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,GAAG,EAAS,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAIL,aAAa,EACd,MAAM,2BAA2B,CAAC;AAQnC;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C,GAAG;IACF;QACE,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,KAAK,EAAE,aAAa,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;KACvB;IACD;QACE,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;KAC/C;CACF,CA4DA"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT license.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.useTeams = void 0;
|
|
6
|
+
var react_1 = require("react");
|
|
7
|
+
var react_dom_1 = require("react-dom");
|
|
8
|
+
var teams_js_1 = require("@microsoft/teams-js");
|
|
9
|
+
var react_northstar_1 = require("@fluentui/react-northstar");
|
|
10
|
+
var getTheme = function () {
|
|
11
|
+
var urlParams = new URLSearchParams(window.location.search);
|
|
12
|
+
var theme = urlParams.get("theme");
|
|
13
|
+
return theme == null ? undefined : theme;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Microsoft Teams React hook
|
|
17
|
+
* @param options optional options
|
|
18
|
+
* @returns A tuple with properties and methods
|
|
19
|
+
* properties:
|
|
20
|
+
* - inTeams: boolean = true if inside Microsoft Teams
|
|
21
|
+
* - fullscreen: boolean = true if in full screen mode
|
|
22
|
+
* - theme: Fluent UI Theme
|
|
23
|
+
* - themeString: string - representation of the theme (default, dark or contrast)
|
|
24
|
+
* - context - the Microsoft Teams JS SDK context
|
|
25
|
+
* methods:
|
|
26
|
+
* - setTheme - manually set the theme
|
|
27
|
+
*/
|
|
28
|
+
function useTeams(options) {
|
|
29
|
+
var _a = (0, react_1.useState)(undefined), inTeams = _a[0], setInTeams = _a[1];
|
|
30
|
+
var _b = (0, react_1.useState)(undefined), fullScreen = _b[0], setFullScreen = _b[1];
|
|
31
|
+
var _c = (0, react_1.useState)(react_northstar_1.teamsTheme), theme = _c[0], setTheme = _c[1];
|
|
32
|
+
var _d = (0, react_1.useState)("default"), themeString = _d[0], setThemeString = _d[1];
|
|
33
|
+
var initialTheme = (0, react_1.useState)(options && options.initialTheme ? options.initialTheme : getTheme())[0];
|
|
34
|
+
var _e = (0, react_1.useState)(undefined), context = _e[0], setContext = _e[1];
|
|
35
|
+
var themeChangeHandler = function (theme) {
|
|
36
|
+
setThemeString(theme || "default");
|
|
37
|
+
switch (theme) {
|
|
38
|
+
case "dark":
|
|
39
|
+
setTheme(react_northstar_1.teamsDarkTheme);
|
|
40
|
+
break;
|
|
41
|
+
case "contrast":
|
|
42
|
+
setTheme(react_northstar_1.teamsHighContrastTheme);
|
|
43
|
+
break;
|
|
44
|
+
case "default":
|
|
45
|
+
default:
|
|
46
|
+
setTheme(react_northstar_1.teamsTheme);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var overrideThemeHandler = (options === null || options === void 0 ? void 0 : options.setThemeHandler)
|
|
50
|
+
? options.setThemeHandler
|
|
51
|
+
: themeChangeHandler;
|
|
52
|
+
(0, react_1.useEffect)(function () {
|
|
53
|
+
// set initial theme based on options or query string
|
|
54
|
+
overrideThemeHandler(initialTheme);
|
|
55
|
+
teams_js_1.app
|
|
56
|
+
.initialize()
|
|
57
|
+
.then(function () {
|
|
58
|
+
teams_js_1.app
|
|
59
|
+
.getContext()
|
|
60
|
+
.then(function (context) {
|
|
61
|
+
(0, react_dom_1.unstable_batchedUpdates)(function () {
|
|
62
|
+
setInTeams(true);
|
|
63
|
+
setContext(context);
|
|
64
|
+
setFullScreen(context.page.isFullScreen);
|
|
65
|
+
});
|
|
66
|
+
overrideThemeHandler(context.app.theme);
|
|
67
|
+
teams_js_1.app.registerOnThemeChangeHandler(overrideThemeHandler);
|
|
68
|
+
teams_js_1.pages.registerFullScreenHandler(function (isFullScreen) {
|
|
69
|
+
setFullScreen(isFullScreen);
|
|
70
|
+
});
|
|
71
|
+
})
|
|
72
|
+
.catch(function () {
|
|
73
|
+
setInTeams(false);
|
|
74
|
+
});
|
|
75
|
+
})
|
|
76
|
+
.catch(function () {
|
|
77
|
+
setInTeams(false);
|
|
78
|
+
});
|
|
79
|
+
}, []);
|
|
80
|
+
return [{ inTeams: inTeams, fullScreen: fullScreen, theme: theme, context: context, themeString: themeString }, { setTheme: overrideThemeHandler }];
|
|
81
|
+
}
|
|
82
|
+
exports.useTeams = useTeams;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
var tslib_1 = require("tslib");
|
|
7
|
+
var teamsfx_1 = require("@microsoft/teamsfx");
|
|
8
|
+
var useTeams_1 = require("./useTeams");
|
|
9
|
+
var useData_1 = require("./useData");
|
|
10
|
+
/**
|
|
11
|
+
* Initialize TeamsFx SDK with customized configuration.
|
|
12
|
+
*
|
|
13
|
+
* @param teamsfxConfig - custom configuration to override default ones.
|
|
14
|
+
* @returns TeamsFxContext object
|
|
15
|
+
*
|
|
16
|
+
* @beta
|
|
17
|
+
*/
|
|
18
|
+
function useTeamsFx(teamsfxConfig) {
|
|
19
|
+
var _this = this;
|
|
20
|
+
var result = (0, useTeams_1.useTeams)({})[0];
|
|
21
|
+
var _a = (0, useData_1.useData)(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
22
|
+
return tslib_1.__generator(this, function (_a) {
|
|
23
|
+
if (process.env.NODE_ENV === "development") {
|
|
24
|
+
(0, teamsfx_1.setLogLevel)(teamsfx_1.LogLevel.Verbose);
|
|
25
|
+
(0, teamsfx_1.setLogFunction)(function (level, message) {
|
|
26
|
+
console.log(message);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return [2 /*return*/, new teamsfx_1.TeamsFx(teamsfx_1.IdentityType.User, teamsfxConfig)];
|
|
30
|
+
});
|
|
31
|
+
}); }), data = _a.data, error = _a.error, loading = _a.loading;
|
|
32
|
+
return tslib_1.__assign({ teamsfx: data, error: error, loading: loading }, result);
|
|
33
|
+
}
|
|
34
|
+
exports.useTeamsFx = useTeamsFx;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,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"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
declare type State<T> = {
|
|
2
|
+
/**
|
|
3
|
+
* User data.
|
|
4
|
+
*/
|
|
5
|
+
data?: T;
|
|
6
|
+
/**
|
|
7
|
+
* Status of data loading.
|
|
8
|
+
*/
|
|
9
|
+
loading: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Error information.
|
|
12
|
+
*/
|
|
13
|
+
error?: unknown;
|
|
14
|
+
};
|
|
15
|
+
export declare type Data<T> = State<T> & {
|
|
16
|
+
/**
|
|
17
|
+
* reload function.
|
|
18
|
+
*/
|
|
19
|
+
reload: () => void;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Helper function to fetch data with status and error.
|
|
23
|
+
*
|
|
24
|
+
* @param fetchDataAsync - async function of how to fetch data
|
|
25
|
+
* @param options - if autoLoad is true, reload data immediately
|
|
26
|
+
* @returns data, loading status, error and reload function
|
|
27
|
+
*
|
|
28
|
+
* @beta
|
|
29
|
+
*/
|
|
30
|
+
export declare function useData<T>(fetchDataAsync: () => Promise<T>, options?: {
|
|
31
|
+
autoLoad: boolean;
|
|
32
|
+
}): Data<T>;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=useData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { useEffect, useReducer } from "react";
|
|
4
|
+
var createReducer = function () {
|
|
5
|
+
return function (state, action) {
|
|
6
|
+
switch (action.type) {
|
|
7
|
+
case "loading":
|
|
8
|
+
return { data: state.data, loading: true };
|
|
9
|
+
case "result":
|
|
10
|
+
return { data: action.result, loading: false };
|
|
11
|
+
case "error":
|
|
12
|
+
return { loading: false, error: action.error };
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Helper function to fetch data with status and error.
|
|
18
|
+
*
|
|
19
|
+
* @param fetchDataAsync - async function of how to fetch data
|
|
20
|
+
* @param options - if autoLoad is true, reload data immediately
|
|
21
|
+
* @returns data, loading status, error and reload function
|
|
22
|
+
*
|
|
23
|
+
* @beta
|
|
24
|
+
*/
|
|
25
|
+
export function useData(fetchDataAsync, options) {
|
|
26
|
+
var _a;
|
|
27
|
+
var auto = (_a = options === null || options === void 0 ? void 0 : options.autoLoad) !== null && _a !== void 0 ? _a : true;
|
|
28
|
+
var _b = useReducer(createReducer(), {
|
|
29
|
+
loading: auto,
|
|
30
|
+
}), _c = _b[0], data = _c.data, loading = _c.loading, error = _c.error, dispatch = _b[1];
|
|
31
|
+
function reload() {
|
|
32
|
+
if (!loading)
|
|
33
|
+
dispatch({ type: "loading" });
|
|
34
|
+
fetchDataAsync()
|
|
35
|
+
.then(function (data) { return dispatch({ type: "result", result: data }); })
|
|
36
|
+
.catch(function (error) { return dispatch({ type: "error", error: error }); });
|
|
37
|
+
}
|
|
38
|
+
useEffect(function () {
|
|
39
|
+
if (auto)
|
|
40
|
+
reload();
|
|
41
|
+
}, []);
|
|
42
|
+
return { data: data, loading: loading, error: error, reload: reload };
|
|
43
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Data } from "./useData";
|
|
2
|
+
import { TeamsFx } from "@microsoft/teamsfx";
|
|
3
|
+
import { Client } from "@microsoft/microsoft-graph-client";
|
|
4
|
+
declare type GraphOption = {
|
|
5
|
+
scope?: string[];
|
|
6
|
+
teamsfx?: TeamsFx;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Helper function to call Microsoft Graph API with authentication.
|
|
10
|
+
*
|
|
11
|
+
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
12
|
+
* @param options - teamsfx instance and OAuth resource scope.
|
|
13
|
+
* @returns data, loading status, error and reload function
|
|
14
|
+
*
|
|
15
|
+
* @beta
|
|
16
|
+
*/
|
|
17
|
+
export declare function useGraph<T>(fetchGraphDataAsync: (graph: Client, teamsfx: TeamsFx, scope: string[]) => Promise<T>, options?: GraphOption): Data<T>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=useGraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,CAkCT"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { __assign, __awaiter, __generator } from "tslib";
|
|
4
|
+
import { useData } from "./useData";
|
|
5
|
+
import { TeamsFx, createMicrosoftGraphClient, ErrorWithCode } from "@microsoft/teamsfx";
|
|
6
|
+
import { GraphError } from "@microsoft/microsoft-graph-client";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
/**
|
|
9
|
+
* Helper function to call Microsoft Graph API with authentication.
|
|
10
|
+
*
|
|
11
|
+
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
12
|
+
* @param options - teamsfx instance and OAuth resource scope.
|
|
13
|
+
* @returns data, loading status, error and reload function
|
|
14
|
+
*
|
|
15
|
+
* @beta
|
|
16
|
+
*/
|
|
17
|
+
export function useGraph(fetchGraphDataAsync, options) {
|
|
18
|
+
var _this = this;
|
|
19
|
+
var _a = __assign({ scope: ["User.Read"], teamsfx: new TeamsFx() }, options), scope = _a.scope, teamsfx = _a.teamsfx;
|
|
20
|
+
var _b = useState(false), needConsent = _b[0], setNeedConsent = _b[1];
|
|
21
|
+
var _c = useData(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
22
|
+
var err_1, helpLink, graph, graphData, err_2;
|
|
23
|
+
var _a, _b;
|
|
24
|
+
return __generator(this, function (_c) {
|
|
25
|
+
switch (_c.label) {
|
|
26
|
+
case 0:
|
|
27
|
+
if (!needConsent) return [3 /*break*/, 4];
|
|
28
|
+
_c.label = 1;
|
|
29
|
+
case 1:
|
|
30
|
+
_c.trys.push([1, 3, , 4]);
|
|
31
|
+
return [4 /*yield*/, teamsfx.login(scope)];
|
|
32
|
+
case 2:
|
|
33
|
+
_c.sent();
|
|
34
|
+
setNeedConsent(false);
|
|
35
|
+
return [3 /*break*/, 4];
|
|
36
|
+
case 3:
|
|
37
|
+
err_1 = _c.sent();
|
|
38
|
+
if (err_1 instanceof ErrorWithCode && ((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("CancelledByUser"))) {
|
|
39
|
+
helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
40
|
+
err_1.message +=
|
|
41
|
+
'\nIf you see "AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application" ' +
|
|
42
|
+
"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 " +
|
|
43
|
+
"cli (version < 0.11.0). Please refer to the help link for how to fix the issue: ".concat(helpLink);
|
|
44
|
+
}
|
|
45
|
+
throw err_1;
|
|
46
|
+
case 4:
|
|
47
|
+
_c.trys.push([4, 6, , 7]);
|
|
48
|
+
graph = createMicrosoftGraphClient(teamsfx, scope);
|
|
49
|
+
return [4 /*yield*/, fetchGraphDataAsync(graph, teamsfx, scope)];
|
|
50
|
+
case 5:
|
|
51
|
+
graphData = _c.sent();
|
|
52
|
+
return [2 /*return*/, graphData];
|
|
53
|
+
case 6:
|
|
54
|
+
err_2 = _c.sent();
|
|
55
|
+
if (err_2 instanceof GraphError && ((_b = err_2.code) === null || _b === void 0 ? void 0 : _b.includes("UiRequiredError"))) {
|
|
56
|
+
// Silently fail for user didn't consent error
|
|
57
|
+
setNeedConsent(true);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
throw err_2;
|
|
61
|
+
}
|
|
62
|
+
return [3 /*break*/, 7];
|
|
63
|
+
case 7: return [2 /*return*/];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}); }), data = _c.data, error = _c.error, loading = _c.loading, reload = _c.reload;
|
|
67
|
+
return { data: data, error: error, loading: loading, reload: reload };
|
|
68
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { app } from "@microsoft/teams-js";
|
|
2
|
+
import { ThemePrepared } from "@fluentui/react-northstar";
|
|
3
|
+
/**
|
|
4
|
+
* Microsoft Teams React hook
|
|
5
|
+
* @param options optional options
|
|
6
|
+
* @returns A tuple with properties and methods
|
|
7
|
+
* properties:
|
|
8
|
+
* - inTeams: boolean = true if inside Microsoft Teams
|
|
9
|
+
* - fullscreen: boolean = true if in full screen mode
|
|
10
|
+
* - theme: Fluent UI Theme
|
|
11
|
+
* - themeString: string - representation of the theme (default, dark or contrast)
|
|
12
|
+
* - context - the Microsoft Teams JS SDK context
|
|
13
|
+
* methods:
|
|
14
|
+
* - setTheme - manually set the theme
|
|
15
|
+
*/
|
|
16
|
+
export declare function useTeams(options?: {
|
|
17
|
+
initialTheme?: string;
|
|
18
|
+
setThemeHandler?: (theme?: string) => void;
|
|
19
|
+
}): [
|
|
20
|
+
{
|
|
21
|
+
inTeams?: boolean;
|
|
22
|
+
fullScreen?: boolean;
|
|
23
|
+
theme: ThemePrepared;
|
|
24
|
+
themeString: string;
|
|
25
|
+
context?: app.Context;
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
setTheme: (theme: string | undefined) => void;
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
//# sourceMappingURL=useTeams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTeams.d.ts","sourceRoot":"","sources":["../../src/useTeams.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,GAAG,EAAS,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAIL,aAAa,EACd,MAAM,2BAA2B,CAAC;AAQnC;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C,GAAG;IACF;QACE,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,KAAK,EAAE,aAAa,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;KACvB;IACD;QACE,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;KAC/C;CACF,CA4DA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { unstable_batchedUpdates as batchedUpdates } from "react-dom";
|
|
5
|
+
import { app, pages } from "@microsoft/teams-js";
|
|
6
|
+
import { teamsDarkTheme, teamsHighContrastTheme, teamsTheme, } from "@fluentui/react-northstar";
|
|
7
|
+
var getTheme = function () {
|
|
8
|
+
var urlParams = new URLSearchParams(window.location.search);
|
|
9
|
+
var theme = urlParams.get("theme");
|
|
10
|
+
return theme == null ? undefined : theme;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Microsoft Teams React hook
|
|
14
|
+
* @param options optional options
|
|
15
|
+
* @returns A tuple with properties and methods
|
|
16
|
+
* properties:
|
|
17
|
+
* - inTeams: boolean = true if inside Microsoft Teams
|
|
18
|
+
* - fullscreen: boolean = true if in full screen mode
|
|
19
|
+
* - theme: Fluent UI Theme
|
|
20
|
+
* - themeString: string - representation of the theme (default, dark or contrast)
|
|
21
|
+
* - context - the Microsoft Teams JS SDK context
|
|
22
|
+
* methods:
|
|
23
|
+
* - setTheme - manually set the theme
|
|
24
|
+
*/
|
|
25
|
+
export function useTeams(options) {
|
|
26
|
+
var _a = useState(undefined), inTeams = _a[0], setInTeams = _a[1];
|
|
27
|
+
var _b = useState(undefined), fullScreen = _b[0], setFullScreen = _b[1];
|
|
28
|
+
var _c = useState(teamsTheme), theme = _c[0], setTheme = _c[1];
|
|
29
|
+
var _d = useState("default"), themeString = _d[0], setThemeString = _d[1];
|
|
30
|
+
var initialTheme = useState(options && options.initialTheme ? options.initialTheme : getTheme())[0];
|
|
31
|
+
var _e = useState(undefined), context = _e[0], setContext = _e[1];
|
|
32
|
+
var themeChangeHandler = function (theme) {
|
|
33
|
+
setThemeString(theme || "default");
|
|
34
|
+
switch (theme) {
|
|
35
|
+
case "dark":
|
|
36
|
+
setTheme(teamsDarkTheme);
|
|
37
|
+
break;
|
|
38
|
+
case "contrast":
|
|
39
|
+
setTheme(teamsHighContrastTheme);
|
|
40
|
+
break;
|
|
41
|
+
case "default":
|
|
42
|
+
default:
|
|
43
|
+
setTheme(teamsTheme);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var overrideThemeHandler = (options === null || options === void 0 ? void 0 : options.setThemeHandler)
|
|
47
|
+
? options.setThemeHandler
|
|
48
|
+
: themeChangeHandler;
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
// set initial theme based on options or query string
|
|
51
|
+
overrideThemeHandler(initialTheme);
|
|
52
|
+
app
|
|
53
|
+
.initialize()
|
|
54
|
+
.then(function () {
|
|
55
|
+
app
|
|
56
|
+
.getContext()
|
|
57
|
+
.then(function (context) {
|
|
58
|
+
batchedUpdates(function () {
|
|
59
|
+
setInTeams(true);
|
|
60
|
+
setContext(context);
|
|
61
|
+
setFullScreen(context.page.isFullScreen);
|
|
62
|
+
});
|
|
63
|
+
overrideThemeHandler(context.app.theme);
|
|
64
|
+
app.registerOnThemeChangeHandler(overrideThemeHandler);
|
|
65
|
+
pages.registerFullScreenHandler(function (isFullScreen) {
|
|
66
|
+
setFullScreen(isFullScreen);
|
|
67
|
+
});
|
|
68
|
+
})
|
|
69
|
+
.catch(function () {
|
|
70
|
+
setInTeams(false);
|
|
71
|
+
});
|
|
72
|
+
})
|
|
73
|
+
.catch(function () {
|
|
74
|
+
setInTeams(false);
|
|
75
|
+
});
|
|
76
|
+
}, []);
|
|
77
|
+
return [{ inTeams: inTeams, fullScreen: fullScreen, theme: theme, context: context, themeString: themeString }, { setTheme: overrideThemeHandler }];
|
|
78
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TeamsFx } from "@microsoft/teamsfx";
|
|
2
|
+
import { ThemePrepared } from "@fluentui/react-northstar";
|
|
3
|
+
export declare type TeamsFxContext = {
|
|
4
|
+
/**
|
|
5
|
+
* Instance of TeamsFx.
|
|
6
|
+
*/
|
|
7
|
+
teamsfx?: TeamsFx;
|
|
8
|
+
/**
|
|
9
|
+
* Status of data loading.
|
|
10
|
+
*/
|
|
11
|
+
loading: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Error information.
|
|
14
|
+
*/
|
|
15
|
+
error: unknown;
|
|
16
|
+
/**
|
|
17
|
+
* Indicates that current environment is in Teams
|
|
18
|
+
*/
|
|
19
|
+
inTeams?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Teams theme.
|
|
22
|
+
*/
|
|
23
|
+
theme: ThemePrepared;
|
|
24
|
+
/**
|
|
25
|
+
* Teams theme string.
|
|
26
|
+
*/
|
|
27
|
+
themeString: string;
|
|
28
|
+
/**
|
|
29
|
+
* Teams context object.
|
|
30
|
+
*/
|
|
31
|
+
context?: any;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Initialize TeamsFx SDK with customized configuration.
|
|
35
|
+
*
|
|
36
|
+
* @param teamsfxConfig - custom configuration to override default ones.
|
|
37
|
+
* @returns TeamsFxContext object
|
|
38
|
+
*
|
|
39
|
+
* @beta
|
|
40
|
+
*/
|
|
41
|
+
export declare function useTeamsFx(teamsfxConfig?: Record<string, string>): TeamsFxContext;
|
|
42
|
+
//# sourceMappingURL=useTeamsFx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { __assign, __awaiter, __generator } from "tslib";
|
|
4
|
+
import { LogLevel, setLogLevel, setLogFunction, TeamsFx, IdentityType } from "@microsoft/teamsfx";
|
|
5
|
+
import { useTeams } from "./useTeams";
|
|
6
|
+
import { useData } from "./useData";
|
|
7
|
+
/**
|
|
8
|
+
* Initialize TeamsFx SDK with customized configuration.
|
|
9
|
+
*
|
|
10
|
+
* @param teamsfxConfig - custom configuration to override default ones.
|
|
11
|
+
* @returns TeamsFxContext object
|
|
12
|
+
*
|
|
13
|
+
* @beta
|
|
14
|
+
*/
|
|
15
|
+
export function useTeamsFx(teamsfxConfig) {
|
|
16
|
+
var _this = this;
|
|
17
|
+
var result = useTeams({})[0];
|
|
18
|
+
var _a = useData(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
19
|
+
return __generator(this, function (_a) {
|
|
20
|
+
if (process.env.NODE_ENV === "development") {
|
|
21
|
+
setLogLevel(LogLevel.Verbose);
|
|
22
|
+
setLogFunction(function (level, message) {
|
|
23
|
+
console.log(message);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return [2 /*return*/, new TeamsFx(IdentityType.User, teamsfxConfig)];
|
|
27
|
+
});
|
|
28
|
+
}); }), data = _a.data, error = _a.error, loading = _a.loading;
|
|
29
|
+
return __assign({ teamsfx: data, error: error, loading: loading }, result);
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/teamsfx-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.28543dcd0.0",
|
|
4
4
|
"description": "React helper functions for Microsoft TeamsFx",
|
|
5
|
-
"main": "build/index.js",
|
|
6
|
-
"
|
|
5
|
+
"main": "build/cjs/index.js",
|
|
6
|
+
"module": "build/esm/index.js",
|
|
7
|
+
"types": "build/cjs/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
7
9
|
"license": "MIT",
|
|
8
10
|
"keywords": [
|
|
9
11
|
"teamsfx",
|
|
@@ -15,53 +17,64 @@
|
|
|
15
17
|
"build/**/*"
|
|
16
18
|
],
|
|
17
19
|
"scripts": {
|
|
18
|
-
"build": "rimraf build && npx tsc -p
|
|
20
|
+
"build": "rimraf build && npx tsc -p tsconfig.json && npx tsc -p tsconfig.es.json",
|
|
19
21
|
"lint:staged": "lint-staged",
|
|
20
22
|
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
21
23
|
"test": "npm run test:unit",
|
|
22
|
-
"test:unit": "
|
|
24
|
+
"test:unit": "jest --ci --reporters=jest-junit --reporters=default --coverage --coverageDirectory='coverage' --collectCoverageFrom='src/*.{ts,tsx,js}'",
|
|
23
25
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
24
26
|
"format-check": "prettier --list-different \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
25
27
|
"check-sensitive": "npx eslint --plugin 'no-secrets' --cache --ignore-pattern 'package.json' --ignore-pattern 'package-lock.json'",
|
|
26
28
|
"precommit": "npm run check-sensitive && lint-staged"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|
|
29
|
-
"@fluentui/react-northstar": "^0.
|
|
31
|
+
"@fluentui/react-northstar": "^0.62.0",
|
|
30
32
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
31
33
|
"@microsoft/microsoft-graph-client": "^3.0.1",
|
|
32
|
-
"@microsoft/teams-js": "^
|
|
33
|
-
"@microsoft/teamsfx": "
|
|
34
|
+
"@microsoft/teams-js": "^2.0.0",
|
|
35
|
+
"@microsoft/teamsfx": "2.0.0-alpha.28543dcd0.0",
|
|
36
|
+
"@testing-library/react": "^12.1.1",
|
|
34
37
|
"@testing-library/react-hooks": "^7.0.2",
|
|
35
|
-
"@types/
|
|
36
|
-
"@types/
|
|
38
|
+
"@types/enzyme": "^3.10.10",
|
|
39
|
+
"@types/jest": "^27.0.2",
|
|
37
40
|
"@types/react": "^16.8.0",
|
|
38
41
|
"@types/react-dom": "^16.8.0",
|
|
39
|
-
"@types/sinon": "^10.0.11",
|
|
40
42
|
"@typescript-eslint/eslint-plugin": "^5.13.0",
|
|
41
43
|
"@typescript-eslint/parser": "^5.13.0",
|
|
42
|
-
"
|
|
43
|
-
"eslint": "^
|
|
44
|
+
"eslint": "^8.15.0",
|
|
45
|
+
"eslint-config-standard": "^17.0.0",
|
|
44
46
|
"eslint-plugin-import": "^2.25.4",
|
|
47
|
+
"eslint-plugin-jest": "^26.1.0",
|
|
48
|
+
"eslint-plugin-n": "^15.2.0",
|
|
45
49
|
"eslint-plugin-no-secrets": "^0.8.9",
|
|
46
50
|
"eslint-plugin-prettier": "^4.0.0",
|
|
51
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
52
|
+
"eslint-plugin-react": "^7.26.0",
|
|
53
|
+
"eslint-plugin-react-hooks": "^4.2.0",
|
|
47
54
|
"isomorphic-fetch": "^3.0.0",
|
|
55
|
+
"jest": "^28.1.0",
|
|
56
|
+
"jest-environment-jsdom": "^28.1.0",
|
|
57
|
+
"jest-junit": "^13.0.0",
|
|
58
|
+
"jwt-decode": "^3.1.2",
|
|
48
59
|
"lint-staged": "^12.3.4",
|
|
49
|
-
"mocha": "^
|
|
50
|
-
"msteams-react-base-component": "^3.1.1",
|
|
60
|
+
"mocha": "^10.0.0",
|
|
51
61
|
"nyc": "^15.1.0",
|
|
52
62
|
"prettier": "^2.5.1",
|
|
53
63
|
"react": "^16.9.0",
|
|
54
64
|
"react-dom": "^16.9.0",
|
|
55
65
|
"react-test-renderer": "^16.9.0",
|
|
56
66
|
"rimraf": "^3.0.2",
|
|
57
|
-
"
|
|
67
|
+
"scheduler": "^0.20.2",
|
|
68
|
+
"ts-jest": "^28.0.2",
|
|
69
|
+
"typescript": "latest"
|
|
58
70
|
},
|
|
59
71
|
"peerDependencies": {
|
|
60
|
-
"@fluentui/react-northstar": "^0.
|
|
72
|
+
"@fluentui/react-northstar": "^0.62.0",
|
|
61
73
|
"@microsoft/microsoft-graph-client": "^3.0.1",
|
|
62
|
-
"@microsoft/
|
|
63
|
-
"
|
|
64
|
-
"react": "^16.8.6"
|
|
74
|
+
"@microsoft/teams-js": "^2.0.0",
|
|
75
|
+
"@microsoft/teamsfx": ">2.0.0-alpha",
|
|
76
|
+
"react": "^16.8.6",
|
|
77
|
+
"react-dom": "^16.8.6"
|
|
65
78
|
},
|
|
66
79
|
"publishConfig": {
|
|
67
80
|
"access": "public"
|
|
@@ -71,5 +84,5 @@
|
|
|
71
84
|
"npx eslint --cache --fix --quiet"
|
|
72
85
|
]
|
|
73
86
|
},
|
|
74
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "a3291f6e8d183a96b18d79f27689e9687eb36e1a"
|
|
75
88
|
}
|
package/build/index.d.ts.map
DELETED
|
@@ -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"}
|
package/build/useData.d.ts.map
DELETED
|
@@ -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;
|
package/build/useGraph.d.ts.map
DELETED
|
@@ -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,CAkCT"}
|
package/build/useGraph.js
DELETED
|
@@ -1,58 +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
|
-
setNeedConsent(false);
|
|
28
|
-
// Important: tokens are stored in sessionStorage, read more here: https://aka.ms/teamsfx-session-storage-notice
|
|
29
|
-
}
|
|
30
|
-
catch (err) {
|
|
31
|
-
if (err instanceof teamsfx_1.ErrorWithCode && ((_a = err.message) === null || _a === void 0 ? void 0 : _a.includes("CancelledByUser"))) {
|
|
32
|
-
const helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
33
|
-
err.message +=
|
|
34
|
-
'\nIf you see "AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application" ' +
|
|
35
|
-
"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 " +
|
|
36
|
-
`cli (version < 0.11.0). Please refer to the help link for how to fix the issue: ${helpLink}`;
|
|
37
|
-
}
|
|
38
|
-
throw err;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
const graph = (0, teamsfx_1.createMicrosoftGraphClient)(teamsfx, scope);
|
|
43
|
-
const graphData = await fetchGraphDataAsync(graph, teamsfx, scope);
|
|
44
|
-
return graphData;
|
|
45
|
-
}
|
|
46
|
-
catch (err) {
|
|
47
|
-
if (err instanceof microsoft_graph_client_1.GraphError && ((_b = err.code) === null || _b === void 0 ? void 0 : _b.includes("UiRequiredError"))) {
|
|
48
|
-
// Silently fail for user didn't consent error
|
|
49
|
-
setNeedConsent(true);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
throw err;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
return { data, error, loading, reload };
|
|
57
|
-
}
|
|
58
|
-
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"}
|
package/build/useTeamsFx.js
DELETED
|
@@ -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;
|