@microsoft/teamsfx-react 0.0.2-alpha.a4c0338b1.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 -0
- package/README.md +149 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +12 -0
- package/build/index.js.map +1 -0
- package/build/useData.d.ts +34 -0
- package/build/useData.d.ts.map +1 -0
- package/build/useData.js +46 -0
- package/build/useData.js.map +1 -0
- package/build/useGraph.d.ts +19 -0
- package/build/useGraph.d.ts.map +1 -0
- package/build/useGraph.js +58 -0
- package/build/useGraph.js.map +1 -0
- package/build/useTeamsFx.d.ts +42 -0
- package/build/useTeamsFx.d.ts.map +1 -0
- package/build/useTeamsFx.js +31 -0
- package/build/useTeamsFx.js.map +1 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +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.
|
package/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# TeamsFx SDK for React
|
|
2
|
+
|
|
3
|
+
TeamsFx SDK provides [React hooks](https://reactjs.org/docs/hooks-intro.html) to reduce the developer tasks of integrating TeamsFx with React and leverage Teams SSO.
|
|
4
|
+
|
|
5
|
+
Use the library to:
|
|
6
|
+
|
|
7
|
+
- Call Graph API using an authenticated client.
|
|
8
|
+
- Customize TeamsFx easily in React app.
|
|
9
|
+
|
|
10
|
+
[Source code](https://github.com/OfficeDev/TeamsFx/tree/main/packages/sdk-react) |
|
|
11
|
+
[Package (NPM)](https://www.npmjs.com/package/@microsoft/teamsfx-react) |
|
|
12
|
+
[Samples](https://github.com/OfficeDev/TeamsFx-Samples)
|
|
13
|
+
|
|
14
|
+
## Getting started
|
|
15
|
+
|
|
16
|
+
> Important: Please be advised that access tokens are stored in sessionStorage for you by default. This can make it possible for malicious code in your app (or code pasted into a console on your page) to access APIs at the same privilege level as your client application. Please ensure you only request the minimum necessary scopes from your client application and perform any sensitive operations from server-side code that your client has to authenticate with.
|
|
17
|
+
|
|
18
|
+
TeamsFx SDK and React hooks are pre-configured in scaffolded project using Teams Toolkit extension for Visual Studio and vscode, or the `teamsfx` cli from the `teamsfx-cli` npm package.
|
|
19
|
+
Please check the [README](https://github.com/OfficeDev/TeamsFx/blob/main/packages/vscode-extension/README.md) to see how to create a Teams App project.
|
|
20
|
+
|
|
21
|
+
### Prerequisites
|
|
22
|
+
|
|
23
|
+
- Node.js version 10.x.x or higher
|
|
24
|
+
- TeamsFx SDK version 0.6.0 or higher
|
|
25
|
+
- A project created by the Teams Toolkit VS Code extension or `teamsfx` CLI tool.
|
|
26
|
+
|
|
27
|
+
### Install the `@microsoft/teamsfx-react` package
|
|
28
|
+
|
|
29
|
+
Install the TeamsFx SDK for TypeScript/JavaScript with `npm`:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install @microsoft/teamsfx-react
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Please also install the peer dependencies if you are using npm 6.
|
|
36
|
+
```bash
|
|
37
|
+
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
|
+
```
|
|
39
|
+
|
|
40
|
+
### Scenario
|
|
41
|
+
|
|
42
|
+
TeamsFx SDK for React is built to be used in React application. You can develop a new react web app for Teams Tab scenario.
|
|
43
|
+
|
|
44
|
+
### Calling the Microsoft Graph API
|
|
45
|
+
|
|
46
|
+
The SDK provides custom React hook `useGraph()` that provides an authenticated Graph client instance. Please use this hook to call Microsoft Graph API.
|
|
47
|
+
|
|
48
|
+
#### 1. Implement business logic and specify resource scope
|
|
49
|
+
|
|
50
|
+
Use the snippet below:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const { loading, error, data, reload } = useGraph(
|
|
54
|
+
async (graph, teamsfx, scope) => {
|
|
55
|
+
// Call graph api directly to get user profile information
|
|
56
|
+
const profile = await graph.api("/me").get();
|
|
57
|
+
|
|
58
|
+
let photoUrl = "";
|
|
59
|
+
try {
|
|
60
|
+
const photo = await graph.api("/me/photo/$value").get();
|
|
61
|
+
photoUrl = URL.createObjectURL(photo);
|
|
62
|
+
} catch {
|
|
63
|
+
// Could not fetch photo from user's profile, return empty string as placeholder.
|
|
64
|
+
}
|
|
65
|
+
return { profile, photoUrl };
|
|
66
|
+
},
|
|
67
|
+
{ scope: ["User.Read"] }
|
|
68
|
+
);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### 2. Render Graph data with React
|
|
72
|
+
|
|
73
|
+
You can bind the `reload` function with a button to refresh data on demand.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
return (
|
|
77
|
+
<div>
|
|
78
|
+
<h3>Example: Get the user's profile</h3>
|
|
79
|
+
<div className="section-margin">
|
|
80
|
+
<p>Click below to authorize button to grant permission to using Microsoft Graph.</p>
|
|
81
|
+
<Button primary content="Authorize" disabled={loading} onClick={reload} />
|
|
82
|
+
<PersonCardFluentUI loading={loading} data={data} error={error} />
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## React Hook list
|
|
89
|
+
|
|
90
|
+
### useData
|
|
91
|
+
Fundamental helper hook function to do asynchronized operation like fetch data from a remote database / backend API.
|
|
92
|
+
It returns custom data, loading status, error object and reload function.
|
|
93
|
+
By default, it will fetch the data once the component has been initialized.
|
|
94
|
+
|
|
95
|
+
### useTeamsFx
|
|
96
|
+
Initialize TeamsFx and Teams JS SDK, in a development environment, verbose logging message will be printed to console.
|
|
97
|
+
It returns the TeamsFx instance as data.
|
|
98
|
+
If you want to customize TeamsFx like customizing setting, please pass the config object to `useTeamsFx()`.
|
|
99
|
+
|
|
100
|
+
### useGraph
|
|
101
|
+
This hook function leverage `useData` to call Graph API. It will execute the fetchGraphDataAsync function that the developer passes in first.
|
|
102
|
+
If user has not consented to the scopes of AAD resources, `useGraph()` will automatically call `teamsfx.login()` to pop up the consent dialog.
|
|
103
|
+
So, developers can focus on the business logic of how to fetch Microsoft Graph data.
|
|
104
|
+
|
|
105
|
+
## Next steps
|
|
106
|
+
|
|
107
|
+
Please take a look at the [Samples](https://github.com/OfficeDev/TeamsFx-Samples) project for detailed examples on how to use this library.
|
|
108
|
+
|
|
109
|
+
## Related projects
|
|
110
|
+
|
|
111
|
+
- [Microsoft Teams Toolkit for Visual Studio Code](https://github.com/OfficeDev/TeamsFx/tree/main/packages/vscode-extension)
|
|
112
|
+
- [TeamsFx SDK](https://github.com/OfficeDev/TeamsFx/tree/main/packages/sdk)
|
|
113
|
+
|
|
114
|
+
## Data Collection.
|
|
115
|
+
|
|
116
|
+
The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft's privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.
|
|
117
|
+
|
|
118
|
+
## Code of Conduct
|
|
119
|
+
|
|
120
|
+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
|
121
|
+
|
|
122
|
+
## Contributing
|
|
123
|
+
|
|
124
|
+
There are many ways in which you can participate in the project, for example:
|
|
125
|
+
|
|
126
|
+
- [Submit bugs and feature requests](https://github.com/OfficeDev/TeamsFx/issues), and help us verify as they are checked in
|
|
127
|
+
- Review [source code changes](https://github.com/OfficeDev/TeamsFx/pulls)
|
|
128
|
+
|
|
129
|
+
If you are interested in fixing issues and contributing directly to the code base, please see the [Contributing Guide](./CONTRIBUTING.md).
|
|
130
|
+
|
|
131
|
+
## Reporting Security Issues
|
|
132
|
+
|
|
133
|
+
**Please do not report security vulnerabilities through public GitHub issues.**
|
|
134
|
+
|
|
135
|
+
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
|
|
136
|
+
|
|
137
|
+
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
|
|
138
|
+
|
|
139
|
+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
|
|
140
|
+
|
|
141
|
+
## Trademarks
|
|
142
|
+
|
|
143
|
+
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
148
|
+
|
|
149
|
+
Licensed under the [MIT](LICENSE.txt) license.
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +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,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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 useData_1 = require("./useData");
|
|
7
|
+
Object.defineProperty(exports, "useData", { enumerable: true, get: function () { return useData_1.useData; } });
|
|
8
|
+
var useTeamsFx_1 = require("./useTeamsFx");
|
|
9
|
+
Object.defineProperty(exports, "useTeamsFx", { enumerable: true, get: function () { return useTeamsFx_1.useTeamsFx; } });
|
|
10
|
+
var useGraph_1 = require("./useGraph");
|
|
11
|
+
Object.defineProperty(exports, "useGraph", { enumerable: true, get: function () { return useGraph_1.useGraph; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,2CAA0D;AAAjD,wGAAA,UAAU,OAAA;AACnB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA"}
|
|
@@ -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"}
|
package/build/useData.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
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;
|
|
46
|
+
//# sourceMappingURL=useData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useData.js","sourceRoot":"","sources":["../src/useData.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,iCAA8C;AA6B9C,MAAM,aAAa,GACjB,GAAM,EAAE,CACR,CAAC,KAAe,EAAE,MAAiB,EAAY,EAAE;IAC/C,QAAQ,MAAM,CAAC,IAAI,EAAE;QACnB,KAAK,SAAS;YACZ,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC7C,KAAK,QAAQ;YACX,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QACjD,KAAK,OAAO;YACV,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;KAClD;AACH,CAAC,CAAC;AAEJ;;;;;;;;GAQG;AACH,SAAgB,OAAO,CACrB,cAAgC,EAChC,OAA+B;;IAE/B,MAAM,IAAI,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,IAAI,CAAC;IACvC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,GAAG,IAAA,kBAAU,EAAC,aAAa,EAAK,EAAE;QAC1E,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;IACH,SAAS,MAAM;QACb,IAAI,CAAC,OAAO;YAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QAC5C,cAAc,EAAE;aACb,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;aAC1D,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IACD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,IAAI;YAAE,MAAM,EAAE,CAAC;IACrB,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC1C,CAAC;AAlBD,0BAkBC"}
|
|
@@ -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,CAiCT"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT license.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.useGraph = void 0;
|
|
6
|
+
const useData_1 = require("./useData");
|
|
7
|
+
const teamsfx_1 = require("@microsoft/teamsfx");
|
|
8
|
+
const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
/**
|
|
11
|
+
* Helper function to call Microsoft Graph API with authentication.
|
|
12
|
+
*
|
|
13
|
+
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
14
|
+
* @param options - teamsfx instance and OAuth resource scope.
|
|
15
|
+
* @returns data, loading status, error and reload function
|
|
16
|
+
*
|
|
17
|
+
* @beta
|
|
18
|
+
*/
|
|
19
|
+
function useGraph(fetchGraphDataAsync, options) {
|
|
20
|
+
const { scope, teamsfx } = Object.assign({ scope: ["User.Read"], teamsfx: new teamsfx_1.TeamsFx() }, options);
|
|
21
|
+
const [needConsent, setNeedConsent] = (0, react_1.useState)(false);
|
|
22
|
+
const { data, error, loading, reload } = (0, useData_1.useData)(async () => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
if (needConsent) {
|
|
25
|
+
try {
|
|
26
|
+
await teamsfx.login(scope);
|
|
27
|
+
// Important: tokens are stored in sessionStorage, read more here: https://aka.ms/teamsfx-session-storage-notice
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
if (err instanceof teamsfx_1.ErrorWithCode && ((_a = err.message) === null || _a === void 0 ? void 0 : _a.includes("CancelledByUser"))) {
|
|
31
|
+
const helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
32
|
+
err.message +=
|
|
33
|
+
'\nIf you see "AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application" ' +
|
|
34
|
+
"in the popup window, you may be using unmatched version for TeamsFx SDK (version >= 0.5.0) and Teams Toolkit (version < 3.3.0) or " +
|
|
35
|
+
`cli (version < 0.11.0). Please refer to the help link for how to fix the issue: ${helpLink}`;
|
|
36
|
+
}
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const graph = (0, teamsfx_1.createMicrosoftGraphClient)(teamsfx, scope);
|
|
42
|
+
const graphData = await fetchGraphDataAsync(graph, teamsfx, scope);
|
|
43
|
+
return graphData;
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
if (err instanceof microsoft_graph_client_1.GraphError && ((_b = err.code) === null || _b === void 0 ? void 0 : _b.includes("UiRequiredError"))) {
|
|
47
|
+
// Silently fail for user didn't consent error
|
|
48
|
+
setNeedConsent(true);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return { data, error, loading, reload };
|
|
56
|
+
}
|
|
57
|
+
exports.useGraph = useGraph;
|
|
58
|
+
//# sourceMappingURL=useGraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGraph.js","sourceRoot":"","sources":["../src/useGraph.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,uCAA0C;AAC1C,gDAAwF;AACxF,8EAAuE;AACvE,iCAAiC;AAOjC;;;;;;;;GAQG;AACH,SAAgB,QAAQ,CACtB,mBAAqF,EACrF,OAAqB;IAErB,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,mBAAK,KAAK,EAAE,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,IAAI,iBAAO,EAAE,IAAK,OAAO,CAAE,CAAC;IACxF,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IACtD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,iBAAO,EAAC,KAAK,IAAI,EAAE;;QAC1D,IAAI,WAAW,EAAE;YACf,IAAI;gBACF,MAAM,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAC3B,gHAAgH;aACjH;YAAC,OAAO,GAAY,EAAE;gBACrB,IAAI,GAAG,YAAY,uBAAa,KAAI,MAAA,GAAG,CAAC,OAAO,0CAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAA,EAAE;oBAC5E,MAAM,QAAQ,GAAG,uCAAuC,CAAC;oBACzD,GAAG,CAAC,OAAO;wBACT,kIAAkI;4BAClI,oIAAoI;4BACpI,mFAAmF,QAAQ,EAAE,CAAC;iBACjG;gBACD,MAAM,GAAG,CAAC;aACX;SACF;QACD,IAAI;YACF,MAAM,KAAK,GAAG,IAAA,oCAA0B,EAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YACzD,MAAM,SAAS,GAAG,MAAM,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YACnE,OAAO,SAAS,CAAC;SAClB;QAAC,OAAO,GAAY,EAAE;YACrB,IAAI,GAAG,YAAY,mCAAU,KAAI,MAAA,GAAG,CAAC,IAAI,0CAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAA,EAAE;gBACtE,8CAA8C;gBAC9C,cAAc,CAAC,IAAI,CAAC,CAAC;aACtB;iBAAM;gBACL,MAAM,GAAG,CAAC;aACX;SACF;IACH,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAC1C,CAAC;AApCD,4BAoCC"}
|
|
@@ -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,31 @@
|
|
|
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;
|
|
31
|
+
//# sourceMappingURL=useTeamsFx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTeamsFx.js","sourceRoot":"","sources":["../src/useTeamsFx.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,gDAAkG;AAClG,+EAAwD;AAExD,uCAAoC;AAkCpC;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,aAAsC;IAC/D,MAAM,CAAC,MAAM,CAAC,GAAG,IAAA,uCAAQ,EAAC,EAAE,CAAC,CAAC;IAC9B,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAA,iBAAO,EAAC,KAAK,IAAI,EAAE;QAClD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE;YAC1C,IAAA,qBAAW,EAAC,kBAAQ,CAAC,OAAO,CAAC,CAAC;YAC9B,IAAA,wBAAc,EAAC,CAAC,KAAe,EAAE,OAAe,EAAE,EAAE;gBAClD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC,CAAC,CAAC;SACJ;QACD,OAAO,IAAI,iBAAO,CAAC,sBAAY,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IACH,uBAAS,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,IAAK,MAAM,EAAG;AACtD,CAAC;AAZD,gCAYC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@microsoft/teamsfx-react",
|
|
3
|
+
"version": "0.0.2-alpha.a4c0338b1.0",
|
|
4
|
+
"description": "React helper functions for Microsoft TeamsFx",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"teamsfx",
|
|
10
|
+
"react"
|
|
11
|
+
],
|
|
12
|
+
"repository": "https://github.com/OfficeDev/TeamsFx",
|
|
13
|
+
"author": "Microsoft Corporation",
|
|
14
|
+
"files": [
|
|
15
|
+
"build/**/*"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "rimraf build && npx tsc -p ./",
|
|
19
|
+
"lint:staged": "lint-staged",
|
|
20
|
+
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
21
|
+
"test": "npm run test:unit",
|
|
22
|
+
"test:unit": "nyc mocha --no-timeouts --require init.js --require ts-node/register test/**/*.test.ts",
|
|
23
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
24
|
+
"format-check": "prettier --list-different \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
25
|
+
"check-sensitive": "npx eslint --plugin 'no-secrets' --cache --ignore-pattern 'package.json' --ignore-pattern 'package-lock.json'",
|
|
26
|
+
"precommit": "npm run check-sensitive && lint-staged"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@fluentui/react-northstar": "^0.60.1",
|
|
30
|
+
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
31
|
+
"@microsoft/microsoft-graph-client": "^3.0.1",
|
|
32
|
+
"@microsoft/teams-js": "^1.9.0",
|
|
33
|
+
"@microsoft/teamsfx": "0.6.1-alpha.a4c0338b1.0",
|
|
34
|
+
"@testing-library/react-hooks": "^7.0.2",
|
|
35
|
+
"@types/chai": "^4.3.0",
|
|
36
|
+
"@types/mocha": "^9.1.0",
|
|
37
|
+
"@types/react": "^16.8.0",
|
|
38
|
+
"@types/react-dom": "^16.8.0",
|
|
39
|
+
"@types/sinon": "^10.0.11",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^5.13.0",
|
|
41
|
+
"@typescript-eslint/parser": "^5.13.0",
|
|
42
|
+
"chai": "^4.3.6",
|
|
43
|
+
"eslint": "^7.32.0",
|
|
44
|
+
"eslint-plugin-import": "^2.25.4",
|
|
45
|
+
"eslint-plugin-no-secrets": "^0.8.9",
|
|
46
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
47
|
+
"isomorphic-fetch": "^3.0.0",
|
|
48
|
+
"lint-staged": "^12.3.4",
|
|
49
|
+
"mocha": "^9.2.1",
|
|
50
|
+
"msteams-react-base-component": "^3.1.1",
|
|
51
|
+
"nyc": "^15.1.0",
|
|
52
|
+
"prettier": "^2.5.1",
|
|
53
|
+
"react": "^16.9.0",
|
|
54
|
+
"react-dom": "^16.9.0",
|
|
55
|
+
"react-test-renderer": "^16.9.0",
|
|
56
|
+
"rimraf": "^3.0.2",
|
|
57
|
+
"sinon": "^13.0.1"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@fluentui/react-northstar": "^0.60.1",
|
|
61
|
+
"@microsoft/microsoft-graph-client": "^3.0.1",
|
|
62
|
+
"@microsoft/teamsfx": "^0.6.0",
|
|
63
|
+
"msteams-react-base-component": "^3.1.1",
|
|
64
|
+
"react": "^16.8.6"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
69
|
+
"lint-staged": {
|
|
70
|
+
"*.{js,jsx,css,ts,tsx}": [
|
|
71
|
+
"npx eslint --cache --fix --quiet"
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"gitHead": "20dedb8423d91224ce2d78802ee5244047df7410"
|
|
75
|
+
}
|