@microsoft/teamsfx-react 3.0.0-alpha.46da7cd00.0 → 3.0.1-alpha.ru6q1vrv0.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 +6 -0
- package/build/cjs/BaseDashboard.d.ts +54 -0
- package/build/cjs/BaseDashboard.d.ts.map +1 -0
- package/build/cjs/BaseDashboard.js +102 -0
- package/build/cjs/BaseWidget.d.ts +63 -0
- package/build/cjs/BaseWidget.d.ts.map +1 -0
- package/build/cjs/BaseWidget.js +149 -0
- package/build/cjs/index.d.ts +7 -5
- package/build/cjs/index.d.ts.map +1 -1
- package/build/cjs/index.js +20 -16
- package/build/cjs/useData.d.ts +33 -33
- package/build/cjs/useData.js +47 -47
- package/build/cjs/useGraph.d.ts +32 -32
- package/build/cjs/useGraph.js +151 -151
- package/build/cjs/useTeams.d.ts +30 -30
- package/build/cjs/useTeams.js +82 -82
- package/build/cjs/useTeamsFx.d.ts +41 -41
- package/build/cjs/useTeamsFx.js +34 -34
- package/build/cjs/useTeamsUserCredential.d.ts +41 -41
- package/build/cjs/useTeamsUserCredential.js +34 -34
- package/build/esm/BaseDashboard.d.ts +54 -0
- package/build/esm/BaseDashboard.d.ts.map +1 -0
- package/build/esm/BaseDashboard.js +99 -0
- package/build/esm/BaseWidget.d.ts +63 -0
- package/build/esm/BaseWidget.d.ts.map +1 -0
- package/build/esm/BaseWidget.js +146 -0
- package/build/esm/index.d.ts +7 -5
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +9 -7
- package/build/esm/useData.d.ts +33 -33
- package/build/esm/useData.js +43 -43
- package/build/esm/useGraph.d.ts +32 -32
- package/build/esm/useGraph.js +146 -146
- package/build/esm/useTeams.d.ts +30 -30
- package/build/esm/useTeams.js +78 -78
- package/build/esm/useTeamsFx.d.ts +41 -41
- package/build/esm/useTeamsFx.js +30 -30
- package/build/esm/useTeamsUserCredential.d.ts +41 -41
- package/build/esm/useTeamsUserCredential.js +30 -30
- package/package.json +6 -5
package/build/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export { useTeams } from "./useTeams";
|
|
2
|
-
export { useData } from "./useData";
|
|
3
|
-
export { useTeamsFx, TeamsFxContext } from "./useTeamsFx";
|
|
4
|
-
export { useTeamsUserCredential, TeamsContextWithCredential } from "./useTeamsUserCredential";
|
|
5
|
-
export { useGraph, useGraphWithCredential } from "./useGraph";
|
|
1
|
+
export { useTeams } from "./useTeams";
|
|
2
|
+
export { useData } from "./useData";
|
|
3
|
+
export { useTeamsFx, TeamsFxContext } from "./useTeamsFx";
|
|
4
|
+
export { useTeamsUserCredential, TeamsContextWithCredential } from "./useTeamsUserCredential";
|
|
5
|
+
export { useGraph, useGraphWithCredential } from "./useGraph";
|
|
6
|
+
export { BaseDashboard } from "./BaseDashboard";
|
|
7
|
+
export { BaseWidget } from "./BaseWidget";
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
package/build/esm/index.d.ts.map
CHANGED
|
@@ -1 +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,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
|
|
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,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
package/build/esm/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
export { useTeams } from "./useTeams";
|
|
4
|
-
export { useData } from "./useData";
|
|
5
|
-
export { useTeamsFx } from "./useTeamsFx";
|
|
6
|
-
export { useTeamsUserCredential } from "./useTeamsUserCredential";
|
|
7
|
-
export { useGraph, useGraphWithCredential } from "./useGraph";
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
export { useTeams } from "./useTeams";
|
|
4
|
+
export { useData } from "./useData";
|
|
5
|
+
export { useTeamsFx } from "./useTeamsFx";
|
|
6
|
+
export { useTeamsUserCredential } from "./useTeamsUserCredential";
|
|
7
|
+
export { useGraph, useGraphWithCredential } from "./useGraph";
|
|
8
|
+
export { BaseDashboard } from "./BaseDashboard";
|
|
9
|
+
export { BaseWidget } from "./BaseWidget";
|
package/build/esm/useData.d.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
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 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
|
+
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 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
|
package/build/esm/useData.js
CHANGED
|
@@ -1,43 +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
|
-
}
|
|
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
|
+
}
|
package/build/esm/useGraph.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { Data } from "./useData";
|
|
2
|
-
import { TeamsFx, TeamsUserCredential } from "@microsoft/teamsfx";
|
|
3
|
-
import { Client } from "@microsoft/microsoft-graph-client";
|
|
4
|
-
type GraphOption = {
|
|
5
|
-
scope?: string[];
|
|
6
|
-
teamsfx?: TeamsFx;
|
|
7
|
-
};
|
|
8
|
-
type GraphOptionWithCredential = {
|
|
9
|
-
scope?: string[];
|
|
10
|
-
credential?: TeamsUserCredential;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Helper function to call Microsoft Graph API with authentication.
|
|
14
|
-
*
|
|
15
|
-
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
16
|
-
* @param options - teamsfx instance and OAuth resource scope.
|
|
17
|
-
* @returns data, loading status, error and reload function
|
|
18
|
-
*
|
|
19
|
-
* @beta
|
|
20
|
-
*/
|
|
21
|
-
export declare function useGraph<T>(fetchGraphDataAsync: (graph: Client, teamsfx: TeamsFx, scope: string[]) => Promise<T>, options?: GraphOption): Data<T>;
|
|
22
|
-
/**
|
|
23
|
-
* Helper function to call Microsoft Graph API with authentication.
|
|
24
|
-
*
|
|
25
|
-
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
26
|
-
* @param options - Authentication configuration and OAuth resource scope.
|
|
27
|
-
* @returns data, loading status, error and reload function
|
|
28
|
-
*
|
|
29
|
-
* @beta
|
|
30
|
-
*/
|
|
31
|
-
export declare function useGraphWithCredential<T>(fetchGraphDataAsync: (graph: Client, credential: TeamsUserCredential, scope: string[]) => Promise<T>, options?: GraphOptionWithCredential): Data<T>;
|
|
32
|
-
export {};
|
|
1
|
+
import { Data } from "./useData";
|
|
2
|
+
import { TeamsFx, TeamsUserCredential } from "@microsoft/teamsfx";
|
|
3
|
+
import { Client } from "@microsoft/microsoft-graph-client";
|
|
4
|
+
type GraphOption = {
|
|
5
|
+
scope?: string[];
|
|
6
|
+
teamsfx?: TeamsFx;
|
|
7
|
+
};
|
|
8
|
+
type GraphOptionWithCredential = {
|
|
9
|
+
scope?: string[];
|
|
10
|
+
credential?: TeamsUserCredential;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Helper function to call Microsoft Graph API with authentication.
|
|
14
|
+
*
|
|
15
|
+
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
16
|
+
* @param options - teamsfx instance and OAuth resource scope.
|
|
17
|
+
* @returns data, loading status, error and reload function
|
|
18
|
+
*
|
|
19
|
+
* @beta
|
|
20
|
+
*/
|
|
21
|
+
export declare function useGraph<T>(fetchGraphDataAsync: (graph: Client, teamsfx: TeamsFx, scope: string[]) => Promise<T>, options?: GraphOption): Data<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Helper function to call Microsoft Graph API with authentication.
|
|
24
|
+
*
|
|
25
|
+
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
26
|
+
* @param options - Authentication configuration and OAuth resource scope.
|
|
27
|
+
* @returns data, loading status, error and reload function
|
|
28
|
+
*
|
|
29
|
+
* @beta
|
|
30
|
+
*/
|
|
31
|
+
export declare function useGraphWithCredential<T>(fetchGraphDataAsync: (graph: Client, credential: TeamsUserCredential, scope: string[]) => Promise<T>, options?: GraphOptionWithCredential): Data<T>;
|
|
32
|
+
export {};
|
|
33
33
|
//# sourceMappingURL=useGraph.d.ts.map
|
package/build/esm/useGraph.js
CHANGED
|
@@ -1,146 +1,146 @@
|
|
|
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, TeamsUserCredential, createMicrosoftGraphClientWithCredential, } 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
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Helper function to call Microsoft Graph API with authentication.
|
|
71
|
-
*
|
|
72
|
-
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
73
|
-
* @param options - Authentication configuration and OAuth resource scope.
|
|
74
|
-
* @returns data, loading status, error and reload function
|
|
75
|
-
*
|
|
76
|
-
* @beta
|
|
77
|
-
*/
|
|
78
|
-
export function useGraphWithCredential(fetchGraphDataAsync, options) {
|
|
79
|
-
var _this = this;
|
|
80
|
-
var credential;
|
|
81
|
-
if (!(options === null || options === void 0 ? void 0 : options.credential)) {
|
|
82
|
-
var authConfig = {
|
|
83
|
-
clientId: process.env.REACT_APP_CLIENT_ID,
|
|
84
|
-
initiateLoginEndpoint: process.env.REACT_APP_START_LOGIN_PAGE_URL,
|
|
85
|
-
};
|
|
86
|
-
credential = new TeamsUserCredential(authConfig);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
credential = options === null || options === void 0 ? void 0 : options.credential;
|
|
90
|
-
}
|
|
91
|
-
var scope;
|
|
92
|
-
if (!(options === null || options === void 0 ? void 0 : options.scope)) {
|
|
93
|
-
scope = ["User.Read"];
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
scope = options.scope;
|
|
97
|
-
}
|
|
98
|
-
var _a = useState(false), needConsent = _a[0], setNeedConsent = _a[1];
|
|
99
|
-
var _b = useData(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
100
|
-
var err_3, helpLink, graph, graphData, err_4;
|
|
101
|
-
var _a, _b;
|
|
102
|
-
return __generator(this, function (_c) {
|
|
103
|
-
switch (_c.label) {
|
|
104
|
-
case 0:
|
|
105
|
-
if (!needConsent) return [3 /*break*/, 4];
|
|
106
|
-
_c.label = 1;
|
|
107
|
-
case 1:
|
|
108
|
-
_c.trys.push([1, 3, , 4]);
|
|
109
|
-
return [4 /*yield*/, credential.login(scope)];
|
|
110
|
-
case 2:
|
|
111
|
-
_c.sent();
|
|
112
|
-
setNeedConsent(false);
|
|
113
|
-
return [3 /*break*/, 4];
|
|
114
|
-
case 3:
|
|
115
|
-
err_3 = _c.sent();
|
|
116
|
-
if (err_3 instanceof ErrorWithCode && ((_a = err_3.message) === null || _a === void 0 ? void 0 : _a.includes("CancelledByUser"))) {
|
|
117
|
-
helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
118
|
-
err_3.message +=
|
|
119
|
-
'\nIf you see "AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application" ' +
|
|
120
|
-
"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 " +
|
|
121
|
-
"cli (version < 0.11.0). Please refer to the help link for how to fix the issue: ".concat(helpLink);
|
|
122
|
-
}
|
|
123
|
-
throw err_3;
|
|
124
|
-
case 4:
|
|
125
|
-
_c.trys.push([4, 6, , 7]);
|
|
126
|
-
graph = createMicrosoftGraphClientWithCredential(credential, scope);
|
|
127
|
-
return [4 /*yield*/, fetchGraphDataAsync(graph, credential, scope)];
|
|
128
|
-
case 5:
|
|
129
|
-
graphData = _c.sent();
|
|
130
|
-
return [2 /*return*/, graphData];
|
|
131
|
-
case 6:
|
|
132
|
-
err_4 = _c.sent();
|
|
133
|
-
if (err_4 instanceof GraphError && ((_b = err_4.code) === null || _b === void 0 ? void 0 : _b.includes("UiRequiredError"))) {
|
|
134
|
-
// Silently fail for user didn't consent error
|
|
135
|
-
setNeedConsent(true);
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
throw err_4;
|
|
139
|
-
}
|
|
140
|
-
return [3 /*break*/, 7];
|
|
141
|
-
case 7: return [2 /*return*/];
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}); }), data = _b.data, error = _b.error, loading = _b.loading, reload = _b.reload;
|
|
145
|
-
return { data: data, error: error, loading: loading, reload: reload };
|
|
146
|
-
}
|
|
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, TeamsUserCredential, createMicrosoftGraphClientWithCredential, } 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
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Helper function to call Microsoft Graph API with authentication.
|
|
71
|
+
*
|
|
72
|
+
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
73
|
+
* @param options - Authentication configuration and OAuth resource scope.
|
|
74
|
+
* @returns data, loading status, error and reload function
|
|
75
|
+
*
|
|
76
|
+
* @beta
|
|
77
|
+
*/
|
|
78
|
+
export function useGraphWithCredential(fetchGraphDataAsync, options) {
|
|
79
|
+
var _this = this;
|
|
80
|
+
var credential;
|
|
81
|
+
if (!(options === null || options === void 0 ? void 0 : options.credential)) {
|
|
82
|
+
var authConfig = {
|
|
83
|
+
clientId: process.env.REACT_APP_CLIENT_ID,
|
|
84
|
+
initiateLoginEndpoint: process.env.REACT_APP_START_LOGIN_PAGE_URL,
|
|
85
|
+
};
|
|
86
|
+
credential = new TeamsUserCredential(authConfig);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
credential = options === null || options === void 0 ? void 0 : options.credential;
|
|
90
|
+
}
|
|
91
|
+
var scope;
|
|
92
|
+
if (!(options === null || options === void 0 ? void 0 : options.scope)) {
|
|
93
|
+
scope = ["User.Read"];
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
scope = options.scope;
|
|
97
|
+
}
|
|
98
|
+
var _a = useState(false), needConsent = _a[0], setNeedConsent = _a[1];
|
|
99
|
+
var _b = useData(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
100
|
+
var err_3, helpLink, graph, graphData, err_4;
|
|
101
|
+
var _a, _b;
|
|
102
|
+
return __generator(this, function (_c) {
|
|
103
|
+
switch (_c.label) {
|
|
104
|
+
case 0:
|
|
105
|
+
if (!needConsent) return [3 /*break*/, 4];
|
|
106
|
+
_c.label = 1;
|
|
107
|
+
case 1:
|
|
108
|
+
_c.trys.push([1, 3, , 4]);
|
|
109
|
+
return [4 /*yield*/, credential.login(scope)];
|
|
110
|
+
case 2:
|
|
111
|
+
_c.sent();
|
|
112
|
+
setNeedConsent(false);
|
|
113
|
+
return [3 /*break*/, 4];
|
|
114
|
+
case 3:
|
|
115
|
+
err_3 = _c.sent();
|
|
116
|
+
if (err_3 instanceof ErrorWithCode && ((_a = err_3.message) === null || _a === void 0 ? void 0 : _a.includes("CancelledByUser"))) {
|
|
117
|
+
helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
118
|
+
err_3.message +=
|
|
119
|
+
'\nIf you see "AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application" ' +
|
|
120
|
+
"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 " +
|
|
121
|
+
"cli (version < 0.11.0). Please refer to the help link for how to fix the issue: ".concat(helpLink);
|
|
122
|
+
}
|
|
123
|
+
throw err_3;
|
|
124
|
+
case 4:
|
|
125
|
+
_c.trys.push([4, 6, , 7]);
|
|
126
|
+
graph = createMicrosoftGraphClientWithCredential(credential, scope);
|
|
127
|
+
return [4 /*yield*/, fetchGraphDataAsync(graph, credential, scope)];
|
|
128
|
+
case 5:
|
|
129
|
+
graphData = _c.sent();
|
|
130
|
+
return [2 /*return*/, graphData];
|
|
131
|
+
case 6:
|
|
132
|
+
err_4 = _c.sent();
|
|
133
|
+
if (err_4 instanceof GraphError && ((_b = err_4.code) === null || _b === void 0 ? void 0 : _b.includes("UiRequiredError"))) {
|
|
134
|
+
// Silently fail for user didn't consent error
|
|
135
|
+
setNeedConsent(true);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
throw err_4;
|
|
139
|
+
}
|
|
140
|
+
return [3 /*break*/, 7];
|
|
141
|
+
case 7: return [2 /*return*/];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}); }), data = _b.data, error = _b.error, loading = _b.loading, reload = _b.reload;
|
|
145
|
+
return { data: data, error: error, loading: loading, reload: reload };
|
|
146
|
+
}
|
package/build/esm/useTeams.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { app } from "@microsoft/teams-js";
|
|
2
|
-
import { Theme } from "@fluentui/react-components";
|
|
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: Theme;
|
|
24
|
-
themeString: string;
|
|
25
|
-
context?: app.Context;
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
setTheme: (theme: string | undefined) => void;
|
|
29
|
-
}
|
|
30
|
-
];
|
|
1
|
+
import { app } from "@microsoft/teams-js";
|
|
2
|
+
import { Theme } from "@fluentui/react-components";
|
|
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: Theme;
|
|
24
|
+
themeString: string;
|
|
25
|
+
context?: app.Context;
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
setTheme: (theme: string | undefined) => void;
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
31
|
//# sourceMappingURL=useTeams.d.ts.map
|