Skip to content

Commit 9194878

Browse files
Resolving review comments, Adding polyfilling for node env, Fixing issue #129
1 parent 2fc151b commit 9194878

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1158
-1246
lines changed

CONTRIBUTING.md

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
Contribute to this documentation
2-
3-
Thank you for your interest in our documentation!
1+
# Contributing
42

53
* [Ways to contribute](#ways-to-contribute)
64
* [Contribute using GitHub](#contribute-using-github)
@@ -101,10 +99,10 @@ To make the contribution process as seamless as possible, follow these steps.
10199

102100
#### To create a new branch
103101

104-
1. Open Git Bash.
105-
2. At the Git Bash command prompt, type `git pull upstream master:<new branch name>`. This creates a new branch locally that is copied from the latest MicrosoftGraph master branch.
106-
3. At the Git Bash command prompt, type `git push origin <new branch name>`. This alerts GitHub to the new branch. You should now see the new branch in your fork of the repository on GitHub.
107-
4. At the Git Bash command prompt, type `git checkout <new branch name>` to switch to your new branch.
102+
1.Open Git Bash.
103+
2.At the Git Bash command prompt, type `git pull upstream master:<new branch name>`. This creates a new branch locally that is copied from the latest MicrosoftGraph master branch.
104+
3.At the Git Bash command prompt, type `git push origin <new branch name>`. This alerts GitHub to the new branch. You should now see the new branch in your fork of the repository on GitHub.
105+
4.At the Git Bash command prompt, type `git checkout <new branch name>` to switch to your new branch.
108106

109107
#### Add new content or edit existing content
110108

@@ -117,7 +115,7 @@ The files in `C:\Users\<yourusername>\<repo name>` are a working copy of the new
117115
git add .
118116
git commit -v -a -m "<Describe the changes made in this commit>"
119117

120-
The `add` command adds your changes to a staging area in preparation for committing them to the repository. The period after the `add` command specifies that you want to stage all of the files that you added or modified, checking subfolders recursively. (If you don't want to commit all of the changes, you can add specific files. You can also undo a commit. For help, type `git add -help` or `git status`.)
118+
The `add` command adds your changes to a staging area in preparation for committing them to the repository. The period after the `add` command specifies that you want to stage all of the files that you added or modified, checking sub folders recursively. (If you don't want to commit all of the changes, you can add specific files. You can also undo a commit. For help, type `git add -help` or `git status`.)
121119

122120
The `commit` command applies the staged changes to the repository. The switch `-m` means you are providing the commit comment in the command line. The -v and -a switches can be omitted. The -v switch is for verbose output from the command, and -a does what you already did with the add command.
123121

@@ -129,13 +127,13 @@ When you're finished with your work and are ready to have it merged into the mai
129127

130128
#### To submit a pull request to the main repository
131129

132-
1. In the Git Bash command prompt, type `git push origin <new branch name>`. In your local repository, `origin` refers to your GitHub repository that you cloned the local repository from. This command pushes the current state of your new branch, including all commits made in the previous steps, to your GitHub fork.
133-
2. On the GitHub site, navigate in your fork to the new branch.
134-
3. Choose the **Pull Request** button at the top of the page.
135-
4. Verify the Base branch is `microsoftgraph/<repo name>@master` and the Head branch is `<your username>/<repo name>@<branch name>`.
136-
5. Choose the **Update Commit Range** button.
137-
6. Add a title to your pull request, and describe all the changes you're making.
138-
7. Submit the pull request.
130+
1.In the Git Bash command prompt, type `git push origin <new branch name>`. In your local repository, `origin` refers to your GitHub repository that you cloned the local repository from. This command pushes the current state of your new branch, including all commits made in the previous steps, to your GitHub fork.
131+
2.On the GitHub site, navigate in your fork to the new branch.
132+
3.Choose the **Pull Request** button at the top of the page.
133+
4.Verify the Base branch is `microsoftgraph/<repo name>@master` and the Head branch is `<your username>/<repo name>@<branch name>`.
134+
5.Choose the **Update Commit Range** button.
135+
6.Add a title to your pull request, and describe all the changes you're making.
136+
7.Submit the pull request.
139137

140138
One of the site administrators will process your pull request. Your pull request will surface on the microsoftgraph/<repo name> site under Issues. When the pull request is accepted, the issue will be resolved.
141139

README.md

+70-10
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,27 @@ The Microsoft Graph JavaScript client library is a lightweight wrapper around th
1717
npm install @microsoft/microsoft-graph-client
1818
```
1919

20+
import `@microsoft/microsoft-graph-client` into your module.
21+
22+
```typescript
23+
import { Client } from "@microsoft/microsoft-graph-client";
24+
```
25+
26+
In case your environment have support for or have polyfill for [Fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) [[support](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#Browser_compatibility)] and [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) [[support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Browser_compatibility)], import `./node_modules/@microsoft/microsoft-graph-client/lib/src/core/index` into your module which doesn't have polyfills for these.
27+
28+
```typescript
29+
import {Client} from "./node_modules/@microsoft/microsoft-graph-client/lib/src/core/index";
30+
```
31+
2032
### Via Script Tag
2133

22-
Include [lib/graph-js-sdk-web.js](./lib/graph-js-sdk-web.js) in your page.
34+
Include [lib/graph-js-sdk-core.js](./lib/graph-js-sdk-core.js) in your page.
35+
36+
```HTML
37+
<script type="text/javascript" src="graph-js-sdk-core.js"></script>
38+
```
39+
40+
In case your browser doesn't have support for [Fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) [[support](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#Browser_compatibility)] and [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) [[support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Browser_compatibility)], you can polyfill them and include as above or you can use [lib/graph-js-sdk-web.js](./lib/graph-js-sdk-web.js) which includes polyfills.
2341

2442
```HTML
2543
<script type="text/javascript" src="graph-js-sdk-web.js"></script>
@@ -33,7 +51,7 @@ Register your application to use Microsoft Graph API using one of the following
3351
supported authentication portals:
3452

3553
* [Microsoft Application Registration Portal](https://apps.dev.microsoft.com):
36-
Register a new application that works with Microsoft Account and/or
54+
Register a new application that works with Microsoft Accounts and/or
3755
organizational accounts using the unified V2 Authentication Endpoint.
3856
* [Microsoft Azure Active Directory](https://manage.windowsazure.com): Register
3957
a new application in your tenant's Active Directory to support work or school
@@ -42,9 +60,37 @@ supported authentication portals:
4260
### 2. Authenticate for the Microsoft Graph service
4361

4462
The Microsoft Graph JavaScript Client Library has an adapter implementation ([MSALAuthenticationProvider](src/MSALAuthenticationProvider.ts)) for [MSAL](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-core) (Microsoft Authentication Library) which takes care of getting the `accessToken`. MSAL library does not ship with this library, user have to include it externally (For including MSAL, refer [this](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-core#installation)).
45-
Creating an instance of MSALAuthenticationProvider,
63+
64+
> **Note:** MSAL is supported only for frontend applications, for server-side authentication you have to implement your own AuthenticationProvider. Refer implementing [Custom Authentication Provider](./docs/CustomAuthenticationProvider.md).
65+
66+
#### Creating an instance of MSALAuthenticationProvider in browser environment
67+
68+
Refer devDependencies in [package.json](./package.json) for the compatible msal version and update that version in below.
69+
70+
```html
71+
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/<version>/js/msal.min.js"></script>
72+
```
73+
74+
```typescript
75+
const clientID = 'your_client_id'; // Client Id of the registered application
76+
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes
77+
const options = { // An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options
78+
redirectUri: "Your redirect URI"
79+
};
80+
const authProvider = new MicrosoftGraph.MSALAuthenticationProvider(clientId, scopes, options);
81+
```
82+
83+
#### Creating an instance of MSALAuthenticationProvider in node environment
84+
85+
Refer devDependencies in [package.json](./package.json) for the compatible msal version and update that version in below.
86+
87+
```cmd
88+
npm install msal@<version>
89+
```
4690

4791
```typescript
92+
import { MSALAuthenticationProvider } from "./node_modules/@microsoft/microsoft-graph-client/lib/src/MSALAuthenticationProvider";
93+
4894
const clientID = 'your_client_id'; // Client Id of the registered application
4995
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes
5096
const options = { // An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options
@@ -53,26 +99,40 @@ const options = { // An Optional options for initializing the MSAL @see https://
5399
const authProvider = new MSALAuthenticationProvider(clientId, scopes, options);
54100
```
55101

56-
User can integrate own preferred authentication library by implementing `IAuthenticationProvider` interface.
102+
User can integrate own preferred authentication library by implementing `IAuthenticationProvider` interface. Refer implementing [Custom Authentication Provider](./docs/CustomAuthenticationProvider.md).
57103

58104
### 3. Initialize a Microsoft Graph Client object with an authentication provider
59105

60-
An instance of the **Client** class handles requests to Microsoft Graph API and processing the responses. To create a new instance of this class, you need to provide an instance of [`IAuthenticationProvider`](src/IAuthenticationProvider.ts) which needs to be passed as a value for `authProvider` key in [`Options`](src/IOptions.ts) to a static initializer method `Client.init`.
106+
An instance of the **Client** class handles requests to Microsoft Graph API and processing the responses. To create a new instance of this class, you need to provide an instance of [`IAuthenticationProvider`](src/IAuthenticationProvider.ts) which needs to be passed as a value for `authProvider` key in [`ClientOptions`](src/IClientOptions.ts) to a static initializer method `Client.initWithMiddleware`.
107+
108+
#### For browser environment
109+
110+
```typescript
111+
const options = {
112+
authProvider // An instance created from previous step
113+
};
114+
const Client = MicrosoftGraph.Client;
115+
const client = Client.initWithMiddleware(options);
116+
```
117+
118+
#### For node environment
61119

62120
```typescript
121+
import { Client } from "@microsoft/microsoft-graph-client";
122+
63123
const options = {
64124
authProvider // An instance created from previous step
65125
};
66-
const client = MicrosoftGraph.Client.init(options);
126+
const client = Client.initWithMiddleware(options);
67127
```
68128

69-
For more information on initializing client, refer [this](./docs/CreatingClientInstance.md).
129+
For more information on initializing client, refer [this document](./docs/CreatingClientInstance.md).
70130

71131
### 4. Make requests to the graph
72132

73-
Once you have authentication setup and an instance of Client, you can begin to make calls to the service. All requests should be start with `client.api(path)` and end with an action.
133+
Once you have authentication setup and an instance of Client, you can begin to make calls to the service. All requests should be start with `client.api(path)` and end with an [action](./docs/Actions.md).
74134

75-
Getting user details,
135+
Getting user details
76136

77137
```typescript
78138
try {
@@ -143,4 +203,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
143203

144204
## Third Party Notices
145205

146-
See [Third Party Notices](https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/master/THIRD%20PARTY%20NOTICES) for information on the packages that are included in the [package.json](https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/master/package.json)
206+
See [Third Party Notices](./THIRD%20PARTY%20NOTICES) for information on the packages that are included in the [package.json](./package.json)

THIRD PARTY NOTICES

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ This file is based on or incorporates material from the projects listed below (T
22
reserves all other rights not expressly granted under this agreement, whether by implication, estoppel or otherwise.
33

44
tslib
5+
6+
isomorphic-fetch
7+
8+
es6-promise
59

610
Provided for Informational Purposes Only
711

docs/CreatingClientInstance.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Initialization of the Client can be done in one of below two ways
66

77
In order to instantiate a Client object, one has to pass in the `authProvider` or `middleware` chain in [ClientOptions](../src/IClientOptions.ts).
88

9-
### 1. Default Middleware chain
9+
### Option A. Default Middleware chain
1010

1111
Pass an instance of a class which implementing [AuthenticationProvider](../src/IAuthenticationProvider.ts) interface as `authProvider` in [ClientOptions](../src/IClientOptions.ts), which will instantiate the Client with default set of middleware chain.
1212

@@ -32,7 +32,7 @@ const client = Client.initWithMiddleware(clientOptions);
3232

3333
Refer, [custom authentication provider](./CustomAuthenticationProvider.md) for more detailed information.
3434

35-
### 2. Custom Middleware chain
35+
### Option B. Custom Middleware chain
3636

3737
Want to have complete control over the request and the response objects, one can provide his own chain of middleware.
3838
Have to pass first middleware in the chain as `middleware` in [ClientOptions](../src/IClientOptions.ts).

docs/CustomMiddlewareChain.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ As name suggests it comes in middle of something and that is request and respons
88

99
### Implement Middlewares
1010

11-
Create own set of middlewares by implementing [Middleware](../src/IMiddleware.ts) interface. Here two middlewares are created one for handling Logging and another for handling http request and response.
11+
Create a custom middleware pipeline by implementing the [Middleware](../src/IMiddleware.ts) interface. The following examples demonstrate how to create a custom logging middleware and how to create a custom http request a response handler.
1212

1313
First middleware is passed with the context object containing request, and other middleware specific options. One has to explicitly make call to execute method of the next middleware with context object once the current middleware work is over.
1414

15-
NOTE: Http message handler should set the response object in the context object.
16-
1715
```typescript
1816
// MyLoggingHandler.ts
1917
import { Middleware } from "@microsoft/microsoft-graph-client";
@@ -32,7 +30,7 @@ export class MyLoggingHandler implements Middleware {
3230
url = context.request.url;
3331
}
3432
console.log(url);
35-
await this.nextMiddleware.execute(context);
33+
return await this.nextMiddleware.execute(context);
3634
} catch(error) {
3735
throw error;
3836
}
@@ -44,6 +42,8 @@ export class MyLoggingHandler implements Middleware {
4442
}
4543
```
4644

45+
> **Note:** Http message handler should set the response object in the context object.
46+
4747
```typescript
4848
// MyHttpMessageHandler.ts
4949
import { Middleware } from "@microsoft/microsoft-graph-client";
@@ -55,6 +55,7 @@ export class MyHttpMessageHandler implements Middleware {
5555
let response = await fetch(context.request, context.options);
5656
// Set the response back in the context
5757
context.response = response;
58+
return;
5859
} catch (error) {
5960
throw error;
6061
}

docs/GettingRawResponse.md

+5-19
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,15 @@
22

33
Steps for getting the raw response [i.e [Response Object](https://developer.mozilla.org/en-US/docs/Web/API/Response)]
44

5-
**Initialize the Client**
5+
## Initialize the Client
66

7-
```typescript
8-
const options = {
9-
authProvider: yourAuthProvider
10-
};
11-
const client = MicrosoftGraph.Client.init(options);
12-
```
13-
14-
**Save request to get the raw response before calling action**
15-
16-
The graph request will be returned for all the method calls except for actions, because they makes call to the server, so have to save the copy of graph request instance before calling actions
17-
18-
```typescript
19-
const graphRequest = client.api("/me").select("displayName")
20-
let response = await graphRequest.get();
21-
```
7+
Refer [this documentation](../CreatingClientInstance.md) for initializing the client.
228

23-
**Get the raw response**
9+
## Getting Raw Response by setting ResponseType
2410

25-
Use `.getRawResponse()` method to get the raw response
11+
To get the raw response set the responseType of a request to ResponseType.RAW.
2612

2713
```typescript
28-
let rawResponse = graphRequest.getRawResponse();
14+
const rawResponse = client.api("/me").select("displayName").responseType(ResponseType.RAW).get();
2915
console.log(rawResponse);
3016
```

0 commit comments

Comments
 (0)