@microsoft/teamsfx-react 2.0.0-experimental.0 → 2.0.0-rc.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/LICENSE +21 -21
- package/README.md +12 -2
- package/build/{index.d.ts → cjs/index.d.ts} +4 -3
- package/build/cjs/index.d.ts.map +1 -0
- package/build/{index.js → cjs/index.js} +13 -11
- package/build/{useData.d.ts → cjs/useData.d.ts} +33 -33
- 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} +18 -18
- 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} +41 -41
- 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 +33 -19
- package/CHANGELOG.md +0 -4
- package/NOTICE.txt +0 -14833
- 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 -57
- package/build/useTeamsFx.d.ts.map +0 -1
- package/build/useTeamsFx.js +0 -30
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 Microsoft
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Microsoft
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
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.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { useTeams } from "./useTeams";
|
|
2
|
+
export { useData } from "./useData";
|
|
3
|
+
export { useTeamsFx, TeamsFxContext } from "./useTeamsFx";
|
|
4
|
+
export { useGraph } from "./useGraph";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation.
|
|
3
|
-
// Licensed under the MIT license.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.useGraph = exports.useTeamsFx = exports.useData = void 0;
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "
|
|
10
|
-
var
|
|
11
|
-
Object.defineProperty(exports, "
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT license.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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; } });
|
|
8
|
+
var useData_1 = require("./useData");
|
|
9
|
+
Object.defineProperty(exports, "useData", { enumerable: true, get: function () { return useData_1.useData; } });
|
|
10
|
+
var useTeamsFx_1 = require("./useTeamsFx");
|
|
11
|
+
Object.defineProperty(exports, "useTeamsFx", { enumerable: true, get: function () { return useTeamsFx_1.useTeamsFx; } });
|
|
12
|
+
var useGraph_1 = require("./useGraph");
|
|
13
|
+
Object.defineProperty(exports, "useGraph", { enumerable: true, get: function () { return useGraph_1.useGraph; } });
|
|
@@ -1,34 +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 {};
|
|
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
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,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;
|
|
@@ -1,19 +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 {};
|
|
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
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,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;
|
|
@@ -1,42 +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;
|
|
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
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,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"}
|