Skip to content

Commit 774d226

Browse files
Adding initial thoughts on Kiota JS for Graph
1 parent 0346656 commit 774d226

File tree

8 files changed

+174
-49
lines changed

8 files changed

+174
-49
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
---
2-
name: Bug report
3-
about: Create a report to help us improve
4-
title: ''
5-
labels: ''
6-
assignees: ''
72

8-
---
9-
10-
# Bug Report
3+
name: Bug report about: Create a report to help us improve title: "" labels: "" assignees: "" ---# Bug Report
114

125
## Prerequisites
136

@@ -41,6 +34,7 @@ For more information, see the `CONTRIBUTING` guide.
4134
Add any other context about the problem here..
4235

4336
## Usage Information
37+
4438
Request ID - Value of the `requestId` field if you are receiving a Graph API error response
4539

4640
SDK Version - [SDK version you are using]

.github/ISSUE_TEMPLATE/feature_request.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
---
2-
name: Feature request
3-
about: Suggest an idea for this project
4-
title: ''
5-
labels: ''
6-
assignees: ''
72

8-
---
9-
10-
# Feature Request
3+
name: Feature request about: Suggest an idea for this project title: "" labels: "" assignees: "" ---# Feature Request
114

125
## Is your feature request related to a problem? Please describe
136

changelogs/v3-upgrade-guide.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@
5454
## Enhancements
5555

5656
### Introducing support for `@azure/msal-browser`
57-
- The 3.0.0 version introduces `AuthCodeMSALBrowserAuthenticationProvider` which supports authentication using the [MSAL Browser](https://www.npmjs.com/package/@azure/msal-browser)
58-
- `AuthCodeMSALBrowserAuthenticationProvider` enables authorization using the Authentication Code Flow with PKCE. Learn more about the [AuthCodeMSALBrowserAuthenticationProvider](https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/docs/AuthCodeMSALBrowserAuthenticationProvider.md).
57+
58+
- The 3.0.0 version introduces `AuthCodeMSALBrowserAuthenticationProvider` which supports authentication using the [MSAL Browser](https://www.npmjs.com/package/@azure/msal-browser)
59+
- `AuthCodeMSALBrowserAuthenticationProvider` enables authorization using the Authentication Code Flow with PKCE. Learn more about the [AuthCodeMSALBrowserAuthenticationProvider](https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/docs/AuthCodeMSALBrowserAuthenticationProvider.md).
5960

6061
### Introducing support for `@azure/identity TokenCredentials`
6162

design/kiota-e2e.md

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# End-to-end usage of kiota-generated SDKs in Javascript
2+
3+
While working with the Kiota + Javascript teams, it became clear that we needed more context and provide a better vision on how we should be using a kiota-generated SDK. This design document aims at providing clarity and a better understanding on how developers will be using our SDKs and the underlying kiota packages.
4+
5+
## Constraints
6+
7+
Before we jump into the end-to-end walk-through, it's important to set some constraints.
8+
9+
| Type | Description |
10+
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
11+
| Platforms | Node : Current and Previous LTS (14 / 16)<br /> Web : Edge, Chrome, Firefox and Safari (Latest released version + immediate previous version) |
12+
| Modules | Node : CommonJS<br /> Web : ES Module (ES6) |
13+
| Types | Typings should be available for both the core and the service libraries for Graph models |
14+
15+
## NodeJS e2e using the Service library
16+
17+
```bash
18+
npm install @microsoft/msgraph-sdk-typescript --save
19+
npm install @microsoft/kiota-authentication-azure --save
20+
```
21+
22+
```typescript
23+
// App.ts
24+
25+
import { Client, User, Message, BodyType } from "@microsoft/msgraph-sdk-javascript";
26+
import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure";
27+
import { DeviceCodeCredential } from "@azure/identity";
28+
29+
const deviceCodeCredentials = new DeviceCodeCredential({
30+
tenantId: "b61f9af1-d6cf-4cc0-a6f6-befb38bc00ed",
31+
clientId: "bde251a6-0ef9-42a8-a40b-9ad9bb594b2c",
32+
});
33+
34+
const scopes = ["User.Read", "Mail.Send"];
35+
36+
const graphClient = Client.init({
37+
accessTokenProvider: new AzureIdentityAccessTokenProvider(deviceCodeCredentials, scopes),
38+
});
39+
40+
const me = await getMe();
41+
const meRaw = await getMeRaw();
42+
await sendMail();
43+
await sendMailRaw();
44+
45+
async function getMe(): Promise<User | undefined> {
46+
return await graphClient.me.get();
47+
}
48+
49+
async function getMe(): Promise<User | undefined> {
50+
return await graphClient.api("/me").get();
51+
}
52+
53+
async function sendMail(): Promise<void> {
54+
const message: Message = {
55+
subject: "Hello Graph TypeScript SDK!",
56+
body: {
57+
contentType: BodyType.Html,
58+
content: "<bold>Hello Graph TypeScript SDK!</bold>",
59+
},
60+
toRecipients: [
61+
{
62+
emailAddress: {
63+
address: "[email protected]",
64+
},
65+
},
66+
],
67+
};
68+
69+
return await client.me.sendMail.post(message);
70+
}
71+
72+
async function sendMailRaw(): Promise<void> {
73+
const message: Message = {
74+
subject: "Hello Graph TypeScript SDK!",
75+
body: {
76+
contentType: BodyType.Html,
77+
content: "<bold>Hello Graph TypeScript SDK!</bold>",
78+
},
79+
toRecipients: [
80+
{
81+
emailAddress: {
82+
address: "[email protected]",
83+
},
84+
},
85+
],
86+
};
87+
88+
return await client.api("/me/sendMail").post({
89+
message: message,
90+
});
91+
}
92+
```
93+
94+
## NodeJS e2e using the Core library
95+
96+
```bash
97+
npm install @microsoft/msgraph-sdk-javascript-core --save
98+
npm install @microsoft/msgraph-sdk-javascript-types --save
99+
npm install @microsoft/kiota-authentication-azure --save
100+
```
101+
102+
```typescript
103+
// App.ts
104+
105+
import { Client } from "@microsoft/msgraph-sdk-javascript-core";
106+
import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure";
107+
import { DeviceCodeCredential } from "@azure/identity";
108+
109+
const deviceCodeCredentials = new DeviceCodeCredential({
110+
tenantId: "b61f9af1-d6cf-4cc0-a6f6-befb38bc00ed",
111+
clientId: "bde251a6-0ef9-42a8-a40b-9ad9bb594b2c",
112+
});
113+
114+
const scopes = ["User.Read", "Mail.Send"];
115+
116+
const graphClient = Client.init({
117+
accessTokenProvider: new AzureIdentityAccessTokenProvider(deviceCodeCredentials, scopes),
118+
});
119+
120+
const me = await getMe();
121+
await sendMail();
122+
123+
async function getMe(): Promise<User | undefined> {
124+
return await graphClient.api("/me").get();
125+
}
126+
127+
async function sendMail(): Promise<void> {
128+
const message: Message = {
129+
subject: "Hello Graph TypeScript SDK!",
130+
body: {
131+
contentType: BodyType.Html,
132+
content: "<bold>Hello Graph TypeScript SDK!</bold>",
133+
},
134+
toRecipients: [
135+
{
136+
emailAddress: {
137+
address: "[email protected]",
138+
},
139+
},
140+
],
141+
};
142+
143+
return await client.api("/me/sendMail").post({
144+
message: message,
145+
});
146+
}
147+
```

design/large-file-upload-task-design.md

+7-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This document proposes high-level design modifications to the `LargeFileUploadTa
44

55
- Enhancement - Support Node.js Stream upload. Issue [#320](https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/320).
66
- Bug Fix - Support large file uploads to Outlook API. Issue [#359](https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/359).
7-
- Enhancement- Support upload progress handler callback. Issue [#305](https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/305).
7+
- Enhancement- Support upload progress handler callback. Issue [#305](https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/305).
88

99
Outline of the current implementation -
1010

@@ -75,21 +75,10 @@ sliceFile(range: Range): ArrayBuffer | Blob {
7575
- The LargeFileUploadTask should allow uploads to OneDrive API, Outlook API and PrintDocument API.
7676
- Proposed changes-
7777
- Add class `UploadResult` containing `location` and `responseBody` properties.
78-
- `location` provides access to the `location` field in the response headers.
79-
- `responseBody` provides access to the Graph API response body.
80-
- The `upload` task should return the `UploadResult` object on successful completion of task.
81-
78+
- `location` provides access to the `location` field in the response headers.
79+
- `responseBody` provides access to the Graph API response body.
80+
- The `upload` task should return the `UploadResult` object on successful completion of task.
81+
8282
###### 3. Support upload progress handler callback
83-
- Proposed changes -
84-
- Add interface -> `interface UploadEventHandler{
85-
extraCallbackParam?: unknown;
86-
progress(range: Range, extraCallbackParam?: unknown):void
87-
}`
88-
- Add uploadEventHandlers option to ->
89-
```
90-
interface LargeFileUploadTaskOptions {
91-
rangeSize?: number;
92-
uploadEventHandlers?: UploadEventHandler;
93-
}
94-
```
95-
- In the `upload` function call the `uploadEventHandlers.progress()` function if defined.
83+
84+
- Proposed changes - - Add interface -> `interface UploadEventHandler{ extraCallbackParam?: unknown; progress(range: Range, extraCallbackParam?: unknown):void }` - Add uploadEventHandlers option to -> `interface LargeFileUploadTaskOptions { rangeSize?: number; uploadEventHandlers?: UploadEventHandler; }` - In the `upload` function call the `uploadEventHandlers.progress()` function if defined.

design/publishing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
##### Current set up -
2222

23-
1. TypeScript Source Code
23+
1. TypeScript Source Code
2424
/ \
2525
Transpiles into JavaScript
2626
'lib' folder

docs/CancellingAHTTPRequest.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# Cancel a HTTP request
22

3-
> The `abort()` method of the AbortController interface aborts a DOM request (e.g. a Fetch request)
4-
>
3+
> The `abort()` method of the AbortController interface aborts a DOM request (e.g. a Fetch request)
4+
>
55
> -- [AbortController interface](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)
66
7-
References -
8-
* [AbortController interface](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)
9-
* [abortcontroller npm](https://www.npmjs.com/package/abort-controller)
10-
* [abortcontroller-polyfill](https://www.npmjs.com/package/abortcontroller-polyfill)
11-
* [Example of the AbortController implementation](https://github.com/node-fetch/node-fetch#request-cancellation-with-abortsignal)
7+
References -
8+
9+
- [AbortController interface](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)
10+
- [abortcontroller npm](https://www.npmjs.com/package/abort-controller)
11+
- [abortcontroller-polyfill](https://www.npmjs.com/package/abortcontroller-polyfill)
12+
- [Example of the AbortController implementation](https://github.com/node-fetch/node-fetch#request-cancellation-with-abortsignal)
1213

1314
#### Following is how canceling a fetch call works:
1415

15-
* Create an AbortController instance.
16-
* That instance has a signal property.
17-
* Pass the signal as a fetch option for signal.
18-
* Call the AbortController's abort property to cancel all fetches that use that signal.
16+
- Create an AbortController instance.
17+
- That instance has a signal property.
18+
- Pass the signal as a fetch option for signal.
19+
- Call the AbortController's abort property to cancel all fetches that use that signal.
1920

2021
#### Setting the AbortController.signal as a fetch option while creating the MSGraph SDK Client instance:
2122

samples/javascript/clientInitialization/tokenCredentialAuthenticationProvider/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
4. Navigate to the samples folder [./samples]and run `npm install`
2020

21-
5. Navigate to secrets.js[./secrets] and populate all the values (tenantId, clientId, clientSecret, scopes)
21+
5. Navigate to secrets.js[./secrets] and populate all the values (tenantId, clientId, clientSecret, scopes)
2222

2323
6. Navigate to tokenCredentialAuthenticationProvider[./samples/javascript/clientInitialization/tokenCredentialAuthenticationProvider] in the samples directory.
2424

0 commit comments

Comments
 (0)