@microsoft/teamsfx-react 2.0.0-beta.0 → 2.0.0-beta.1
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/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/useData.d.ts +25 -9
- package/build/useData.d.ts.map +1 -1
- package/build/useData.js +6 -8
- package/build/useGraph.d.ts +8 -9
- package/build/useGraph.d.ts.map +1 -1
- package/build/useGraph.js +29 -37
- package/build/useTeamsFx.d.ts +39 -8
- package/build/useTeamsFx.d.ts.map +1 -1
- package/build/useTeamsFx.js +9 -14
- package/package.json +2 -2
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,MAAM,cAAc,CAAC;
|
|
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
CHANGED
|
@@ -1,18 +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
|
+
};
|
|
1
21
|
/**
|
|
2
22
|
* Helper function to fetch data with status and error.
|
|
3
23
|
*
|
|
4
|
-
* @param
|
|
24
|
+
* @param fetchDataAsync - async function of how to fetch data
|
|
5
25
|
* @param options - if autoLoad is true, reload data immediately
|
|
6
26
|
* @returns data, loading status, error and reload function
|
|
7
27
|
*
|
|
8
28
|
* @beta
|
|
9
29
|
*/
|
|
10
|
-
export declare function useData<T>(
|
|
11
|
-
|
|
12
|
-
}):
|
|
13
|
-
|
|
14
|
-
loading: boolean;
|
|
15
|
-
error: any;
|
|
16
|
-
reload: () => void;
|
|
17
|
-
};
|
|
30
|
+
export declare function useData<T>(fetchDataAsync: () => Promise<T>, options?: {
|
|
31
|
+
autoLoad: boolean;
|
|
32
|
+
}): Data<T>;
|
|
33
|
+
export {};
|
|
18
34
|
//# sourceMappingURL=useData.d.ts.map
|
package/build/useData.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useData.d.ts","sourceRoot":"","sources":["../src/useData.ts"],"names":[],"mappings":"
|
|
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
CHANGED
|
@@ -17,24 +17,22 @@ const createReducer = () => (state, action) => {
|
|
|
17
17
|
/**
|
|
18
18
|
* Helper function to fetch data with status and error.
|
|
19
19
|
*
|
|
20
|
-
* @param
|
|
20
|
+
* @param fetchDataAsync - async function of how to fetch data
|
|
21
21
|
* @param options - if autoLoad is true, reload data immediately
|
|
22
22
|
* @returns data, loading status, error and reload function
|
|
23
23
|
*
|
|
24
24
|
* @beta
|
|
25
25
|
*/
|
|
26
|
-
function useData(
|
|
27
|
-
|
|
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;
|
|
28
29
|
const [{ data, loading, error }, dispatch] = (0, react_1.useReducer)(createReducer(), {
|
|
29
|
-
loading:
|
|
30
|
+
loading: auto,
|
|
30
31
|
});
|
|
31
32
|
function reload() {
|
|
32
33
|
if (!loading)
|
|
33
34
|
dispatch({ type: "loading" });
|
|
34
|
-
|
|
35
|
-
throw new Error("invalid argument to useData, a function is required");
|
|
36
|
-
}
|
|
37
|
-
asyncFn()
|
|
35
|
+
fetchDataAsync()
|
|
38
36
|
.then((data) => dispatch({ type: "result", result: data }))
|
|
39
37
|
.catch((error) => dispatch({ type: "error", error }));
|
|
40
38
|
}
|
package/build/useGraph.d.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
+
import { Data } from "./useData";
|
|
1
2
|
import { TeamsFx } from "@microsoft/teamsfx";
|
|
2
3
|
import { Client } from "@microsoft/microsoft-graph-client";
|
|
4
|
+
declare type GraphOption = {
|
|
5
|
+
scope?: string[];
|
|
6
|
+
teamsfx?: TeamsFx;
|
|
7
|
+
};
|
|
3
8
|
/**
|
|
4
9
|
* Helper function to call Microsoft Graph API with authentication.
|
|
5
10
|
*
|
|
6
|
-
* @param
|
|
11
|
+
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
7
12
|
* @param options - teamsfx instance and OAuth resource scope.
|
|
8
13
|
* @returns data, loading status, error and reload function
|
|
9
14
|
*
|
|
10
15
|
* @beta
|
|
11
16
|
*/
|
|
12
|
-
export declare function useGraph<T>(
|
|
13
|
-
|
|
14
|
-
}): {
|
|
15
|
-
data: T | undefined;
|
|
16
|
-
error: any;
|
|
17
|
-
loading: boolean;
|
|
18
|
-
reload: () => void;
|
|
19
|
-
};
|
|
17
|
+
export declare function useGraph<T>(fetchGraphDataAsync: (graph: Client, teamsfx: TeamsFx, scope: string[]) => Promise<T>, options?: GraphOption): Data<T>;
|
|
18
|
+
export {};
|
|
20
19
|
//# sourceMappingURL=useGraph.d.ts.map
|
package/build/useGraph.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGraph.d.ts","sourceRoot":"","sources":["../src/useGraph.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGraph.d.ts","sourceRoot":"","sources":["../src/useGraph.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAW,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAA6C,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,MAAM,EAAc,MAAM,mCAAmC,CAAC;AAGvE,aAAK,WAAW,GAAG;IACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EACrF,OAAO,CAAC,EAAE,WAAW,GACpB,IAAI,CAAC,CAAC,CAAC,CAiCT"}
|
package/build/useGraph.js
CHANGED
|
@@ -6,60 +6,52 @@ exports.useGraph = void 0;
|
|
|
6
6
|
const useData_1 = require("./useData");
|
|
7
7
|
const teamsfx_1 = require("@microsoft/teamsfx");
|
|
8
8
|
const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
|
|
9
|
+
const react_1 = require("react");
|
|
9
10
|
/**
|
|
10
11
|
* Helper function to call Microsoft Graph API with authentication.
|
|
11
12
|
*
|
|
12
|
-
* @param
|
|
13
|
+
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
13
14
|
* @param options - teamsfx instance and OAuth resource scope.
|
|
14
15
|
* @returns data, loading status, error and reload function
|
|
15
16
|
*
|
|
16
17
|
* @beta
|
|
17
18
|
*/
|
|
18
|
-
function useGraph(
|
|
19
|
-
const { scope } = Object.assign({ scope: ["User.Read"] }, options);
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
catch (err) {
|
|
28
|
-
if (err instanceof microsoft_graph_client_1.GraphError && ((_a = err.code) === null || _a === void 0 ? void 0 : _a.includes("UiRequiredError"))) {
|
|
29
|
-
// Silently fail for user didn't login error
|
|
19
|
+
function useGraph(fetchGraphDataAsync, options) {
|
|
20
|
+
const { scope, teamsfx } = Object.assign({ scope: ["User.Read"], teamsfx: new teamsfx_1.TeamsFx() }, options);
|
|
21
|
+
const [needConsent, setNeedConsent] = (0, react_1.useState)(false);
|
|
22
|
+
const { data, error, loading, reload } = (0, useData_1.useData)(async () => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
if (needConsent) {
|
|
25
|
+
try {
|
|
26
|
+
await teamsfx.login(scope);
|
|
27
|
+
// Important: tokens are stored in sessionStorage, read more here: https://aka.ms/teamsfx-session-storage-notice
|
|
30
28
|
}
|
|
31
|
-
|
|
29
|
+
catch (err) {
|
|
30
|
+
if (err instanceof teamsfx_1.ErrorWithCode && ((_a = err.message) === null || _a === void 0 ? void 0 : _a.includes("CancelledByUser"))) {
|
|
31
|
+
const helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
32
|
+
err.message +=
|
|
33
|
+
'\nIf you see "AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application" ' +
|
|
34
|
+
"in the popup window, you may be using unmatched version for TeamsFx SDK (version >= 0.5.0) and Teams Toolkit (version < 3.3.0) or " +
|
|
35
|
+
`cli (version < 0.11.0). Please refer to the help link for how to fix the issue: ${helpLink}`;
|
|
36
|
+
}
|
|
32
37
|
throw err;
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
|
-
});
|
|
36
|
-
const { data, error, loading, reload } = (0, useData_1.useData)(async () => {
|
|
37
|
-
var _a;
|
|
38
40
|
try {
|
|
39
|
-
const teamsfx = new teamsfx_1.TeamsFx();
|
|
40
|
-
await teamsfx.login(scope);
|
|
41
|
-
// Important: tokens are stored in sessionStorage, read more here: https://aka.ms/teamsfx-session-storage-notice
|
|
42
41
|
const graph = (0, teamsfx_1.createMicrosoftGraphClient)(teamsfx, scope);
|
|
43
|
-
|
|
42
|
+
const graphData = await fetchGraphDataAsync(graph, teamsfx, scope);
|
|
43
|
+
return graphData;
|
|
44
44
|
}
|
|
45
45
|
catch (err) {
|
|
46
|
-
if (err instanceof
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
if (err instanceof microsoft_graph_client_1.GraphError && ((_b = err.code) === null || _b === void 0 ? void 0 : _b.includes("UiRequiredError"))) {
|
|
47
|
+
// Silently fail for user didn't consent error
|
|
48
|
+
setNeedConsent(true);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw err;
|
|
52
52
|
}
|
|
53
|
-
throw err;
|
|
54
53
|
}
|
|
55
|
-
}
|
|
56
|
-
return data
|
|
57
|
-
? { data, error, loading, reload }
|
|
58
|
-
: {
|
|
59
|
-
data: initial.data,
|
|
60
|
-
error: initial.error,
|
|
61
|
-
loading: initial.loading,
|
|
62
|
-
reload,
|
|
63
|
-
};
|
|
54
|
+
});
|
|
55
|
+
return { data, error, loading, reload };
|
|
64
56
|
}
|
|
65
57
|
exports.useGraph = useGraph;
|
package/build/useTeamsFx.d.ts
CHANGED
|
@@ -1,11 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
*/
|
|
8
11
|
loading: boolean;
|
|
9
|
-
|
|
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;
|
|
10
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;
|
|
11
42
|
//# sourceMappingURL=useTeamsFx.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTeamsFx.d.ts","sourceRoot":"","sources":["../src/useTeamsFx.ts"],"names":[],"mappings":"
|
|
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
CHANGED
|
@@ -14,22 +14,17 @@ const useData_1 = require("./useData");
|
|
|
14
14
|
*
|
|
15
15
|
* @beta
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
let initialized = false;
|
|
19
|
-
function useTeamsFx() {
|
|
17
|
+
function useTeamsFx(teamsfxConfig) {
|
|
20
18
|
const [result] = (0, msteams_react_base_component_1.useTeams)({});
|
|
21
|
-
const { error, loading } = (0, useData_1.useData)(async () => {
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
initialized = true;
|
|
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
|
+
});
|
|
30
25
|
}
|
|
26
|
+
return new teamsfx_1.TeamsFx(teamsfx_1.IdentityType.User, teamsfxConfig);
|
|
31
27
|
});
|
|
32
|
-
|
|
33
|
-
return Object.assign({ error, loading, isInTeams }, result);
|
|
28
|
+
return Object.assign({ teamsfx: data, error, loading }, result);
|
|
34
29
|
}
|
|
35
30
|
exports.useTeamsFx = useTeamsFx;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/teamsfx-react",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"description": "React helper functions for Microsoft TeamsFx",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@fluentui/react-northstar": "^0.62.0",
|
|
61
61
|
"@microsoft/microsoft-graph-client": "^3.0.1",
|
|
62
62
|
"@microsoft/teamsfx": "2.0.0-beta.0",
|
|
63
|
-
"msteams-react-base-component": "
|
|
63
|
+
"msteams-react-base-component": "4.0.1",
|
|
64
64
|
"react": "^16.8.6"
|
|
65
65
|
},
|
|
66
66
|
"publishConfig": {
|