From 774d2267858453de5275bbb24580c71c2f675beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Fri, 14 Jan 2022 14:10:06 -0500 Subject: [PATCH 1/8] Adding initial thoughts on Kiota JS for Graph --- .github/ISSUE_TEMPLATE/bug_report.md | 10 +- .github/ISSUE_TEMPLATE/feature_request.md | 9 +- changelogs/v3-upgrade-guide.md | 5 +- design/kiota-e2e.md | 147 ++++++++++++++++++ design/large-file-upload-task-design.md | 25 +-- design/publishing.md | 2 +- docs/CancellingAHTTPRequest.md | 23 +-- .../README.md | 2 +- 8 files changed, 174 insertions(+), 49 deletions(-) create mode 100644 design/kiota-e2e.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 0e4f4e7ff..7b7e5952d 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,13 +1,6 @@ --- -name: Bug report -about: Create a report to help us improve -title: '' -labels: '' -assignees: '' ---- - -# Bug Report +name: Bug report about: Create a report to help us improve title: "" labels: "" assignees: "" ---# Bug Report ## Prerequisites @@ -41,6 +34,7 @@ For more information, see the `CONTRIBUTING` guide. Add any other context about the problem here.. ## Usage Information + Request ID - Value of the `requestId` field if you are receiving a Graph API error response SDK Version - [SDK version you are using] diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index a283c162d..84a2da750 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,13 +1,6 @@ --- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: '' -assignees: '' ---- - -# Feature Request +name: Feature request about: Suggest an idea for this project title: "" labels: "" assignees: "" ---# Feature Request ## Is your feature request related to a problem? Please describe diff --git a/changelogs/v3-upgrade-guide.md b/changelogs/v3-upgrade-guide.md index 233e5f894..d84a912cc 100644 --- a/changelogs/v3-upgrade-guide.md +++ b/changelogs/v3-upgrade-guide.md @@ -54,8 +54,9 @@ ## Enhancements ### Introducing support for `@azure/msal-browser` -- The 3.0.0 version introduces `AuthCodeMSALBrowserAuthenticationProvider` which supports authentication using the [MSAL Browser](https://www.npmjs.com/package/@azure/msal-browser) -- `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). + +- The 3.0.0 version introduces `AuthCodeMSALBrowserAuthenticationProvider` which supports authentication using the [MSAL Browser](https://www.npmjs.com/package/@azure/msal-browser) +- `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). ### Introducing support for `@azure/identity TokenCredentials` diff --git a/design/kiota-e2e.md b/design/kiota-e2e.md new file mode 100644 index 000000000..f56dcb143 --- /dev/null +++ b/design/kiota-e2e.md @@ -0,0 +1,147 @@ +# End-to-end usage of kiota-generated SDKs in Javascript + +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. + +## Constraints + +Before we jump into the end-to-end walk-through, it's important to set some constraints. + +| Type | Description | +| --------- | --------------------------------------------------------------------------------------------------------------------------------------------- | +| Platforms | Node : Current and Previous LTS (14 / 16)
Web : Edge, Chrome, Firefox and Safari (Latest released version + immediate previous version) | +| Modules | Node : CommonJS
Web : ES Module (ES6) | +| Types | Typings should be available for both the core and the service libraries for Graph models | + +## NodeJS e2e using the Service library + +```bash +npm install @microsoft/msgraph-sdk-typescript --save +npm install @microsoft/kiota-authentication-azure --save +``` + +```typescript +// App.ts + +import { Client, User, Message, BodyType } from "@microsoft/msgraph-sdk-javascript"; +import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure"; +import { DeviceCodeCredential } from "@azure/identity"; + +const deviceCodeCredentials = new DeviceCodeCredential({ + tenantId: "b61f9af1-d6cf-4cc0-a6f6-befb38bc00ed", + clientId: "bde251a6-0ef9-42a8-a40b-9ad9bb594b2c", +}); + +const scopes = ["User.Read", "Mail.Send"]; + +const graphClient = Client.init({ + accessTokenProvider: new AzureIdentityAccessTokenProvider(deviceCodeCredentials, scopes), +}); + +const me = await getMe(); +const meRaw = await getMeRaw(); +await sendMail(); +await sendMailRaw(); + +async function getMe(): Promise { + return await graphClient.me.get(); +} + +async function getMe(): Promise { + return await graphClient.api("/me").get(); +} + +async function sendMail(): Promise { + const message: Message = { + subject: "Hello Graph TypeScript SDK!", + body: { + contentType: BodyType.Html, + content: "Hello Graph TypeScript SDK!", + }, + toRecipients: [ + { + emailAddress: { + address: "admin@m365x263716.onmicrosoft.com", + }, + }, + ], + }; + + return await client.me.sendMail.post(message); +} + +async function sendMailRaw(): Promise { + const message: Message = { + subject: "Hello Graph TypeScript SDK!", + body: { + contentType: BodyType.Html, + content: "Hello Graph TypeScript SDK!", + }, + toRecipients: [ + { + emailAddress: { + address: "admin@m365x263716.onmicrosoft.com", + }, + }, + ], + }; + + return await client.api("/me/sendMail").post({ + message: message, + }); +} +``` + +## NodeJS e2e using the Core library + +```bash +npm install @microsoft/msgraph-sdk-javascript-core --save +npm install @microsoft/msgraph-sdk-javascript-types --save +npm install @microsoft/kiota-authentication-azure --save +``` + +```typescript +// App.ts + +import { Client } from "@microsoft/msgraph-sdk-javascript-core"; +import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure"; +import { DeviceCodeCredential } from "@azure/identity"; + +const deviceCodeCredentials = new DeviceCodeCredential({ + tenantId: "b61f9af1-d6cf-4cc0-a6f6-befb38bc00ed", + clientId: "bde251a6-0ef9-42a8-a40b-9ad9bb594b2c", +}); + +const scopes = ["User.Read", "Mail.Send"]; + +const graphClient = Client.init({ + accessTokenProvider: new AzureIdentityAccessTokenProvider(deviceCodeCredentials, scopes), +}); + +const me = await getMe(); +await sendMail(); + +async function getMe(): Promise { + return await graphClient.api("/me").get(); +} + +async function sendMail(): Promise { + const message: Message = { + subject: "Hello Graph TypeScript SDK!", + body: { + contentType: BodyType.Html, + content: "Hello Graph TypeScript SDK!", + }, + toRecipients: [ + { + emailAddress: { + address: "admin@m365x263716.onmicrosoft.com", + }, + }, + ], + }; + + return await client.api("/me/sendMail").post({ + message: message, + }); +} +``` diff --git a/design/large-file-upload-task-design.md b/design/large-file-upload-task-design.md index cf4b3468b..f11c165ca 100644 --- a/design/large-file-upload-task-design.md +++ b/design/large-file-upload-task-design.md @@ -4,7 +4,7 @@ This document proposes high-level design modifications to the `LargeFileUploadTa - Enhancement - Support Node.js Stream upload. Issue [#320](https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/320). - Bug Fix - Support large file uploads to Outlook API. Issue [#359](https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/359). -- Enhancement- Support upload progress handler callback. Issue [#305](https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/305). +- Enhancement- Support upload progress handler callback. Issue [#305](https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/305). Outline of the current implementation - @@ -75,21 +75,10 @@ sliceFile(range: Range): ArrayBuffer | Blob { - The LargeFileUploadTask should allow uploads to OneDrive API, Outlook API and PrintDocument API. - Proposed changes- - Add class `UploadResult` containing `location` and `responseBody` properties. - - `location` provides access to the `location` field in the response headers. - - `responseBody` provides access to the Graph API response body. - - The `upload` task should return the `UploadResult` object on successful completion of task. - + - `location` provides access to the `location` field in the response headers. + - `responseBody` provides access to the Graph API response body. + - The `upload` task should return the `UploadResult` object on successful completion of task. + ###### 3. Support upload progress handler callback -- 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. + +- 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. diff --git a/design/publishing.md b/design/publishing.md index b5e0475ca..dc6b0a70a 100644 --- a/design/publishing.md +++ b/design/publishing.md @@ -20,7 +20,7 @@ ##### Current set up - -1. TypeScript Source Code +1. TypeScript Source Code / \ Transpiles into JavaScript 'lib' folder diff --git a/docs/CancellingAHTTPRequest.md b/docs/CancellingAHTTPRequest.md index 9d5659a52..1ed394cd5 100644 --- a/docs/CancellingAHTTPRequest.md +++ b/docs/CancellingAHTTPRequest.md @@ -1,21 +1,22 @@ # Cancel a HTTP request -> The `abort()` method of the AbortController interface aborts a DOM request (e.g. a Fetch request) -> +> The `abort()` method of the AbortController interface aborts a DOM request (e.g. a Fetch request) +> > -- [AbortController interface](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) -References - -* [AbortController interface](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) -* [abortcontroller npm](https://www.npmjs.com/package/abort-controller) -* [abortcontroller-polyfill](https://www.npmjs.com/package/abortcontroller-polyfill) -* [Example of the AbortController implementation](https://github.com/node-fetch/node-fetch#request-cancellation-with-abortsignal) +References - + +- [AbortController interface](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) +- [abortcontroller npm](https://www.npmjs.com/package/abort-controller) +- [abortcontroller-polyfill](https://www.npmjs.com/package/abortcontroller-polyfill) +- [Example of the AbortController implementation](https://github.com/node-fetch/node-fetch#request-cancellation-with-abortsignal) #### Following is how canceling a fetch call works: -* Create an AbortController instance. -* That instance has a signal property. -* Pass the signal as a fetch option for signal. -* Call the AbortController's abort property to cancel all fetches that use that signal. +- Create an AbortController instance. +- That instance has a signal property. +- Pass the signal as a fetch option for signal. +- Call the AbortController's abort property to cancel all fetches that use that signal. #### Setting the AbortController.signal as a fetch option while creating the MSGraph SDK Client instance: diff --git a/samples/javascript/clientInitialization/tokenCredentialAuthenticationProvider/README.md b/samples/javascript/clientInitialization/tokenCredentialAuthenticationProvider/README.md index cfb806355..26ed158d8 100644 --- a/samples/javascript/clientInitialization/tokenCredentialAuthenticationProvider/README.md +++ b/samples/javascript/clientInitialization/tokenCredentialAuthenticationProvider/README.md @@ -18,7 +18,7 @@ 4. Navigate to the samples folder [./samples]and run `npm install` -5. Navigate to secrets.js[./secrets] and populate all the values (tenantId, clientId, clientSecret, scopes) +5. Navigate to secrets.js[./secrets] and populate all the values (tenantId, clientId, clientSecret, scopes) 6. Navigate to tokenCredentialAuthenticationProvider[./samples/javascript/clientInitialization/tokenCredentialAuthenticationProvider] in the samples directory. From d261c7775f3b7118a81f8f84796ad7c1b9d02557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Fri, 14 Jan 2022 14:14:31 -0500 Subject: [PATCH 2/8] Revert "Adding initial thoughts on Kiota JS for Graph" This reverts commit 774d2267858453de5275bbb24580c71c2f675beb. --- .github/ISSUE_TEMPLATE/bug_report.md | 10 +- .github/ISSUE_TEMPLATE/feature_request.md | 9 +- changelogs/v3-upgrade-guide.md | 5 +- design/kiota-e2e.md | 147 ------------------ design/large-file-upload-task-design.md | 25 ++- design/publishing.md | 2 +- docs/CancellingAHTTPRequest.md | 23 ++- .../README.md | 2 +- 8 files changed, 49 insertions(+), 174 deletions(-) delete mode 100644 design/kiota-e2e.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 7b7e5952d..0e4f4e7ff 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,6 +1,13 @@ --- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' -name: Bug report about: Create a report to help us improve title: "" labels: "" assignees: "" ---# Bug Report +--- + +# Bug Report ## Prerequisites @@ -34,7 +41,6 @@ For more information, see the `CONTRIBUTING` guide. Add any other context about the problem here.. ## Usage Information - Request ID - Value of the `requestId` field if you are receiving a Graph API error response SDK Version - [SDK version you are using] diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 84a2da750..a283c162d 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,6 +1,13 @@ --- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' -name: Feature request about: Suggest an idea for this project title: "" labels: "" assignees: "" ---# Feature Request +--- + +# Feature Request ## Is your feature request related to a problem? Please describe diff --git a/changelogs/v3-upgrade-guide.md b/changelogs/v3-upgrade-guide.md index d84a912cc..233e5f894 100644 --- a/changelogs/v3-upgrade-guide.md +++ b/changelogs/v3-upgrade-guide.md @@ -54,9 +54,8 @@ ## Enhancements ### Introducing support for `@azure/msal-browser` - -- The 3.0.0 version introduces `AuthCodeMSALBrowserAuthenticationProvider` which supports authentication using the [MSAL Browser](https://www.npmjs.com/package/@azure/msal-browser) -- `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). +- The 3.0.0 version introduces `AuthCodeMSALBrowserAuthenticationProvider` which supports authentication using the [MSAL Browser](https://www.npmjs.com/package/@azure/msal-browser) +- `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). ### Introducing support for `@azure/identity TokenCredentials` diff --git a/design/kiota-e2e.md b/design/kiota-e2e.md deleted file mode 100644 index f56dcb143..000000000 --- a/design/kiota-e2e.md +++ /dev/null @@ -1,147 +0,0 @@ -# End-to-end usage of kiota-generated SDKs in Javascript - -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. - -## Constraints - -Before we jump into the end-to-end walk-through, it's important to set some constraints. - -| Type | Description | -| --------- | --------------------------------------------------------------------------------------------------------------------------------------------- | -| Platforms | Node : Current and Previous LTS (14 / 16)
Web : Edge, Chrome, Firefox and Safari (Latest released version + immediate previous version) | -| Modules | Node : CommonJS
Web : ES Module (ES6) | -| Types | Typings should be available for both the core and the service libraries for Graph models | - -## NodeJS e2e using the Service library - -```bash -npm install @microsoft/msgraph-sdk-typescript --save -npm install @microsoft/kiota-authentication-azure --save -``` - -```typescript -// App.ts - -import { Client, User, Message, BodyType } from "@microsoft/msgraph-sdk-javascript"; -import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure"; -import { DeviceCodeCredential } from "@azure/identity"; - -const deviceCodeCredentials = new DeviceCodeCredential({ - tenantId: "b61f9af1-d6cf-4cc0-a6f6-befb38bc00ed", - clientId: "bde251a6-0ef9-42a8-a40b-9ad9bb594b2c", -}); - -const scopes = ["User.Read", "Mail.Send"]; - -const graphClient = Client.init({ - accessTokenProvider: new AzureIdentityAccessTokenProvider(deviceCodeCredentials, scopes), -}); - -const me = await getMe(); -const meRaw = await getMeRaw(); -await sendMail(); -await sendMailRaw(); - -async function getMe(): Promise { - return await graphClient.me.get(); -} - -async function getMe(): Promise { - return await graphClient.api("/me").get(); -} - -async function sendMail(): Promise { - const message: Message = { - subject: "Hello Graph TypeScript SDK!", - body: { - contentType: BodyType.Html, - content: "Hello Graph TypeScript SDK!", - }, - toRecipients: [ - { - emailAddress: { - address: "admin@m365x263716.onmicrosoft.com", - }, - }, - ], - }; - - return await client.me.sendMail.post(message); -} - -async function sendMailRaw(): Promise { - const message: Message = { - subject: "Hello Graph TypeScript SDK!", - body: { - contentType: BodyType.Html, - content: "Hello Graph TypeScript SDK!", - }, - toRecipients: [ - { - emailAddress: { - address: "admin@m365x263716.onmicrosoft.com", - }, - }, - ], - }; - - return await client.api("/me/sendMail").post({ - message: message, - }); -} -``` - -## NodeJS e2e using the Core library - -```bash -npm install @microsoft/msgraph-sdk-javascript-core --save -npm install @microsoft/msgraph-sdk-javascript-types --save -npm install @microsoft/kiota-authentication-azure --save -``` - -```typescript -// App.ts - -import { Client } from "@microsoft/msgraph-sdk-javascript-core"; -import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure"; -import { DeviceCodeCredential } from "@azure/identity"; - -const deviceCodeCredentials = new DeviceCodeCredential({ - tenantId: "b61f9af1-d6cf-4cc0-a6f6-befb38bc00ed", - clientId: "bde251a6-0ef9-42a8-a40b-9ad9bb594b2c", -}); - -const scopes = ["User.Read", "Mail.Send"]; - -const graphClient = Client.init({ - accessTokenProvider: new AzureIdentityAccessTokenProvider(deviceCodeCredentials, scopes), -}); - -const me = await getMe(); -await sendMail(); - -async function getMe(): Promise { - return await graphClient.api("/me").get(); -} - -async function sendMail(): Promise { - const message: Message = { - subject: "Hello Graph TypeScript SDK!", - body: { - contentType: BodyType.Html, - content: "Hello Graph TypeScript SDK!", - }, - toRecipients: [ - { - emailAddress: { - address: "admin@m365x263716.onmicrosoft.com", - }, - }, - ], - }; - - return await client.api("/me/sendMail").post({ - message: message, - }); -} -``` diff --git a/design/large-file-upload-task-design.md b/design/large-file-upload-task-design.md index f11c165ca..cf4b3468b 100644 --- a/design/large-file-upload-task-design.md +++ b/design/large-file-upload-task-design.md @@ -4,7 +4,7 @@ This document proposes high-level design modifications to the `LargeFileUploadTa - Enhancement - Support Node.js Stream upload. Issue [#320](https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/320). - Bug Fix - Support large file uploads to Outlook API. Issue [#359](https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/359). -- Enhancement- Support upload progress handler callback. Issue [#305](https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/305). +- Enhancement- Support upload progress handler callback. Issue [#305](https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/305). Outline of the current implementation - @@ -75,10 +75,21 @@ sliceFile(range: Range): ArrayBuffer | Blob { - The LargeFileUploadTask should allow uploads to OneDrive API, Outlook API and PrintDocument API. - Proposed changes- - Add class `UploadResult` containing `location` and `responseBody` properties. - - `location` provides access to the `location` field in the response headers. - - `responseBody` provides access to the Graph API response body. - - The `upload` task should return the `UploadResult` object on successful completion of task. - + - `location` provides access to the `location` field in the response headers. + - `responseBody` provides access to the Graph API response body. + - The `upload` task should return the `UploadResult` object on successful completion of task. + ###### 3. Support upload progress handler callback - -- 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. +- 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. diff --git a/design/publishing.md b/design/publishing.md index dc6b0a70a..b5e0475ca 100644 --- a/design/publishing.md +++ b/design/publishing.md @@ -20,7 +20,7 @@ ##### Current set up - -1. TypeScript Source Code +1. TypeScript Source Code / \ Transpiles into JavaScript 'lib' folder diff --git a/docs/CancellingAHTTPRequest.md b/docs/CancellingAHTTPRequest.md index 1ed394cd5..9d5659a52 100644 --- a/docs/CancellingAHTTPRequest.md +++ b/docs/CancellingAHTTPRequest.md @@ -1,22 +1,21 @@ # Cancel a HTTP request -> The `abort()` method of the AbortController interface aborts a DOM request (e.g. a Fetch request) -> +> The `abort()` method of the AbortController interface aborts a DOM request (e.g. a Fetch request) +> > -- [AbortController interface](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) -References - - -- [AbortController interface](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) -- [abortcontroller npm](https://www.npmjs.com/package/abort-controller) -- [abortcontroller-polyfill](https://www.npmjs.com/package/abortcontroller-polyfill) -- [Example of the AbortController implementation](https://github.com/node-fetch/node-fetch#request-cancellation-with-abortsignal) +References - +* [AbortController interface](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) +* [abortcontroller npm](https://www.npmjs.com/package/abort-controller) +* [abortcontroller-polyfill](https://www.npmjs.com/package/abortcontroller-polyfill) +* [Example of the AbortController implementation](https://github.com/node-fetch/node-fetch#request-cancellation-with-abortsignal) #### Following is how canceling a fetch call works: -- Create an AbortController instance. -- That instance has a signal property. -- Pass the signal as a fetch option for signal. -- Call the AbortController's abort property to cancel all fetches that use that signal. +* Create an AbortController instance. +* That instance has a signal property. +* Pass the signal as a fetch option for signal. +* Call the AbortController's abort property to cancel all fetches that use that signal. #### Setting the AbortController.signal as a fetch option while creating the MSGraph SDK Client instance: diff --git a/samples/javascript/clientInitialization/tokenCredentialAuthenticationProvider/README.md b/samples/javascript/clientInitialization/tokenCredentialAuthenticationProvider/README.md index 26ed158d8..cfb806355 100644 --- a/samples/javascript/clientInitialization/tokenCredentialAuthenticationProvider/README.md +++ b/samples/javascript/clientInitialization/tokenCredentialAuthenticationProvider/README.md @@ -18,7 +18,7 @@ 4. Navigate to the samples folder [./samples]and run `npm install` -5. Navigate to secrets.js[./secrets] and populate all the values (tenantId, clientId, clientSecret, scopes) +5. Navigate to secrets.js[./secrets] and populate all the values (tenantId, clientId, clientSecret, scopes) 6. Navigate to tokenCredentialAuthenticationProvider[./samples/javascript/clientInitialization/tokenCredentialAuthenticationProvider] in the samples directory. From 15fc99f8eb2fb3fc453746875e41778511e873dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Fri, 14 Jan 2022 14:17:54 -0500 Subject: [PATCH 3/8] Adding kiota e2e --- design/kiota-e2e.md | 147 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 design/kiota-e2e.md diff --git a/design/kiota-e2e.md b/design/kiota-e2e.md new file mode 100644 index 000000000..f56dcb143 --- /dev/null +++ b/design/kiota-e2e.md @@ -0,0 +1,147 @@ +# End-to-end usage of kiota-generated SDKs in Javascript + +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. + +## Constraints + +Before we jump into the end-to-end walk-through, it's important to set some constraints. + +| Type | Description | +| --------- | --------------------------------------------------------------------------------------------------------------------------------------------- | +| Platforms | Node : Current and Previous LTS (14 / 16)
Web : Edge, Chrome, Firefox and Safari (Latest released version + immediate previous version) | +| Modules | Node : CommonJS
Web : ES Module (ES6) | +| Types | Typings should be available for both the core and the service libraries for Graph models | + +## NodeJS e2e using the Service library + +```bash +npm install @microsoft/msgraph-sdk-typescript --save +npm install @microsoft/kiota-authentication-azure --save +``` + +```typescript +// App.ts + +import { Client, User, Message, BodyType } from "@microsoft/msgraph-sdk-javascript"; +import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure"; +import { DeviceCodeCredential } from "@azure/identity"; + +const deviceCodeCredentials = new DeviceCodeCredential({ + tenantId: "b61f9af1-d6cf-4cc0-a6f6-befb38bc00ed", + clientId: "bde251a6-0ef9-42a8-a40b-9ad9bb594b2c", +}); + +const scopes = ["User.Read", "Mail.Send"]; + +const graphClient = Client.init({ + accessTokenProvider: new AzureIdentityAccessTokenProvider(deviceCodeCredentials, scopes), +}); + +const me = await getMe(); +const meRaw = await getMeRaw(); +await sendMail(); +await sendMailRaw(); + +async function getMe(): Promise { + return await graphClient.me.get(); +} + +async function getMe(): Promise { + return await graphClient.api("/me").get(); +} + +async function sendMail(): Promise { + const message: Message = { + subject: "Hello Graph TypeScript SDK!", + body: { + contentType: BodyType.Html, + content: "Hello Graph TypeScript SDK!", + }, + toRecipients: [ + { + emailAddress: { + address: "admin@m365x263716.onmicrosoft.com", + }, + }, + ], + }; + + return await client.me.sendMail.post(message); +} + +async function sendMailRaw(): Promise { + const message: Message = { + subject: "Hello Graph TypeScript SDK!", + body: { + contentType: BodyType.Html, + content: "Hello Graph TypeScript SDK!", + }, + toRecipients: [ + { + emailAddress: { + address: "admin@m365x263716.onmicrosoft.com", + }, + }, + ], + }; + + return await client.api("/me/sendMail").post({ + message: message, + }); +} +``` + +## NodeJS e2e using the Core library + +```bash +npm install @microsoft/msgraph-sdk-javascript-core --save +npm install @microsoft/msgraph-sdk-javascript-types --save +npm install @microsoft/kiota-authentication-azure --save +``` + +```typescript +// App.ts + +import { Client } from "@microsoft/msgraph-sdk-javascript-core"; +import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure"; +import { DeviceCodeCredential } from "@azure/identity"; + +const deviceCodeCredentials = new DeviceCodeCredential({ + tenantId: "b61f9af1-d6cf-4cc0-a6f6-befb38bc00ed", + clientId: "bde251a6-0ef9-42a8-a40b-9ad9bb594b2c", +}); + +const scopes = ["User.Read", "Mail.Send"]; + +const graphClient = Client.init({ + accessTokenProvider: new AzureIdentityAccessTokenProvider(deviceCodeCredentials, scopes), +}); + +const me = await getMe(); +await sendMail(); + +async function getMe(): Promise { + return await graphClient.api("/me").get(); +} + +async function sendMail(): Promise { + const message: Message = { + subject: "Hello Graph TypeScript SDK!", + body: { + contentType: BodyType.Html, + content: "Hello Graph TypeScript SDK!", + }, + toRecipients: [ + { + emailAddress: { + address: "admin@m365x263716.onmicrosoft.com", + }, + }, + ], + }; + + return await client.api("/me/sendMail").post({ + message: message, + }); +} +``` From 7a17e7f47ecf2d93cb297ee15787a652a0eb0fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Mon, 17 Jan 2022 09:47:30 -0500 Subject: [PATCH 4/8] Updates --- design/kiota-e2e.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/design/kiota-e2e.md b/design/kiota-e2e.md index f56dcb143..82689204b 100644 --- a/design/kiota-e2e.md +++ b/design/kiota-e2e.md @@ -15,7 +15,8 @@ Before we jump into the end-to-end walk-through, it's important to set some cons ## NodeJS e2e using the Service library ```bash -npm install @microsoft/msgraph-sdk-typescript --save +## Depending on the needs, you could also install the @microsoft/msgraph-sdk-javascript-beta side-by-side with the v1.0 one. Not covered in this walkthrough. +npm install @microsoft/msgraph-sdk-javascript --save ## Installing the Javascript service library should also install the core SDK and the types (based on the version of the service library). npm install @microsoft/kiota-authentication-azure --save ``` @@ -34,23 +35,33 @@ const deviceCodeCredentials = new DeviceCodeCredential({ const scopes = ["User.Read", "Mail.Send"]; const graphClient = Client.init({ + // Note that this is not an authentication provider, but an access token provider. accessTokenProvider: new AzureIdentityAccessTokenProvider(deviceCodeCredentials, scopes), }); +// Calling the API via the fluent API const me = await getMe(); + +// Allowing raw calls (using the .api() method instead of the full fluent API) is important for migration purposes and cases we don't know the resource beforehands (thinking Graph Explorer, mgt-get, etc.) const meRaw = await getMeRaw(); + +// Sending an email via the fluent API await sendMail(); + +// Sending the email via the .api() method await sendMailRaw(); +// The types returned by the fluent API should be the same as the .api() area. It should also be the same (or at least very similar) as the current @microsoft/microsoft-graph-types to offer seamless migration. async function getMe(): Promise { return await graphClient.me.get(); } -async function getMe(): Promise { +async function getMeRaw(): Promise { return await graphClient.api("/me").get(); } async function sendMail(): Promise { + // Noting that we are using Interfaces and not Classes. There is an open discussion about this topic here https://github.com/microsoft/kiota/issues/1013 const message: Message = { subject: "Hello Graph TypeScript SDK!", body: { @@ -96,6 +107,7 @@ async function sendMailRaw(): Promise { ```bash npm install @microsoft/msgraph-sdk-javascript-core --save npm install @microsoft/msgraph-sdk-javascript-types --save +## npm install @microsoft/msgraph-sdk-javascript-types-beta --save npm install @microsoft/kiota-authentication-azure --save ``` From 798159c35b124aadc6672a6206d18956bc6252bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Mon, 17 Jan 2022 10:11:09 -0500 Subject: [PATCH 5/8] Update design/kiota-e2e.md Co-authored-by: Vincent Biret --- design/kiota-e2e.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design/kiota-e2e.md b/design/kiota-e2e.md index 82689204b..338a422f3 100644 --- a/design/kiota-e2e.md +++ b/design/kiota-e2e.md @@ -36,7 +36,7 @@ const scopes = ["User.Read", "Mail.Send"]; const graphClient = Client.init({ // Note that this is not an authentication provider, but an access token provider. - accessTokenProvider: new AzureIdentityAccessTokenProvider(deviceCodeCredentials, scopes), + authenticationTokenProvider: new AzureIdentityAuthenticationProvider(deviceCodeCredentials, scopes), }); // Calling the API via the fluent API From dd24ad977ceecd0cf00475f7cdcaab8870c9a720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Mon, 17 Jan 2022 10:32:08 -0500 Subject: [PATCH 6/8] Adding types from our package --- design/kiota-e2e.md | 1 + 1 file changed, 1 insertion(+) diff --git a/design/kiota-e2e.md b/design/kiota-e2e.md index 82689204b..b2007626f 100644 --- a/design/kiota-e2e.md +++ b/design/kiota-e2e.md @@ -115,6 +115,7 @@ npm install @microsoft/kiota-authentication-azure --save // App.ts import { Client } from "@microsoft/msgraph-sdk-javascript-core"; +import { User, Message, BodyType } from "@microsoft/msgraph-sdk-javascript-core-types"; import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure"; import { DeviceCodeCredential } from "@azure/identity"; From 5d3bd24e16b2a6a3b040be59700e525a5897dbb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Mon, 17 Jan 2022 12:43:45 -0500 Subject: [PATCH 7/8] Adding more concepts to the e2e --- design/kiota-e2e.md | 95 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 20 deletions(-) diff --git a/design/kiota-e2e.md b/design/kiota-e2e.md index 703b52869..edbfe3cb1 100644 --- a/design/kiota-e2e.md +++ b/design/kiota-e2e.md @@ -9,24 +9,45 @@ Before we jump into the end-to-end walk-through, it's important to set some cons | Type | Description | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------- | | Platforms | Node : Current and Previous LTS (14 / 16)
Web : Edge, Chrome, Firefox and Safari (Latest released version + immediate previous version) | -| Modules | Node : CommonJS
Web : ES Module (ES6) | -| Types | Typings should be available for both the core and the service libraries for Graph models | +| Modules | Node : ESM (For preview) and potentially CJS (Based on feedback)
Web : ESM | +| Types | Typings / Models should be available for both the core and the service libraries for Graph models | ## NodeJS e2e using the Service library -```bash -## Depending on the needs, you could also install the @microsoft/msgraph-sdk-javascript-beta side-by-side with the v1.0 one. Not covered in this walkthrough. -npm install @microsoft/msgraph-sdk-javascript --save ## Installing the Javascript service library should also install the core SDK and the types (based on the version of the service library). +### Concept + +This example is utilizing both the core and the service library. That means that as a developer, we want the full fluent API, allowing me discover APIs via the intellisence. Because the service library leverages the core library, we also want to highlight that we can leverage the core components directly (like the `.api()` method). + +### Install the Microsoft Graph Javascript Service Library + +There will be two versions of the service library for the Graph Javascript SDK. The default one will bring the representation of the v1.0 of Microsoft Graph. The second one will bring the representation of the beta of Microsoft Graph. This will be the only difference between these two libraries, as all the handcrafted code (delivering authentication, middlewares, tasks, etc.) will happen in the core library. + +The Microsoft Graph Javascript Service Library includes the following packages: + +- `@microsoft/msgraph-sdk-javascript` ([npm](https://www.npmjs.com/package/@microsoft/msgraph-sdk-javascript-core)) - The service library for making fluent calls to Microsoft Graph v1.0. +- `@microsoft/msgraph-sdk-javascript-beta` ([npm](https://www.npmjs.com/package/@microsoft/msgraph-sdk-javascript-type)) - The service library for making fluent calls to Microsoft Graph beta. + +You can use [npm](https://www.npmjs.com) to install the Microsoft Graph Javascript Service Library : + +```Shell +npm install @microsoft/msgraph-sdk-javascript --save +npm install @microsoft/msgraph-sdk-javascript-beta --save-dev npm install @microsoft/kiota-authentication-azure --save ``` +### Importing the right functionalities from the Graph Javascript Service Library + ```typescript // App.ts import { Client, User, Message, BodyType } from "@microsoft/msgraph-sdk-javascript"; import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure"; import { DeviceCodeCredential } from "@azure/identity"; +``` +### Setting up the app to work with the Graph Javascript Service Library + +```typescript const deviceCodeCredentials = new DeviceCodeCredential({ tenantId: "b61f9af1-d6cf-4cc0-a6f6-befb38bc00ed", clientId: "bde251a6-0ef9-42a8-a40b-9ad9bb594b2c", @@ -35,20 +56,22 @@ const deviceCodeCredentials = new DeviceCodeCredential({ const scopes = ["User.Read", "Mail.Send"]; const graphClient = Client.init({ - // Note that this is not an authentication provider, but an access token provider. authenticationTokenProvider: new AzureIdentityAuthenticationProvider(deviceCodeCredentials, scopes), }); +``` -// Calling the API via the fluent API -const me = await getMe(); +### Calling Microsoft Graph via the Graph Javascript Service Library -// Allowing raw calls (using the .api() method instead of the full fluent API) is important for migration purposes and cases we don't know the resource beforehands (thinking Graph Explorer, mgt-get, etc.) -const meRaw = await getMeRaw(); +The core value of the Microsoft Graph Javascript Service Library is the availability of the Fluent API. This provides developers with typechecking and discoverability when building on Microsoft Graph. This Fluent API is made available via the Request Builder concept and highlights the full spectrum of capabilities on Microsoft Graph. -// Sending an email via the fluent API -await sendMail(); +Models are also available in this package and should reflect the underlying version of Graph we are targeting. Developers using our types should do it in a way that will be familiar to how they are used to with other SDKs and APIs. We should provide an easy-to-use model that feels natural in the Javascript world. This means we should not be forcing developers to use Classes and / or other structures that will make their code less natural to them. -// Sending the email via the .api() method +We have an open issue about the above topic that can be followed here : [TypeScript - Use of interface models instead of class models](https://github.com/microsoft/kiota/issues/1013) + +```typescript +const me = await getMe(); +const meRaw = await getMeRaw(); +await sendMail(); await sendMailRaw(); // The types returned by the fluent API should be the same as the .api() area. It should also be the same (or at least very similar) as the current @microsoft/microsoft-graph-types to offer seamless migration. @@ -56,12 +79,13 @@ async function getMe(): Promise { return await graphClient.me.get(); } +// Allowing raw calls (using the .api() method instead of the full fluent API) is important for migration purposes and cases we don't know the resource beforehands (thinking Graph Explorer, mgt-get, etc.) async function getMeRaw(): Promise { return await graphClient.api("/me").get(); } +// Sending an email via the fluent API async function sendMail(): Promise { - // Noting that we are using Interfaces and not Classes. There is an open discussion about this topic here https://github.com/microsoft/kiota/issues/1013 const message: Message = { subject: "Hello Graph TypeScript SDK!", body: { @@ -80,6 +104,7 @@ async function sendMail(): Promise { return await client.me.sendMail.post(message); } +// Sending the email via the .api() method async function sendMailRaw(): Promise { const message: Message = { subject: "Hello Graph TypeScript SDK!", @@ -104,21 +129,41 @@ async function sendMailRaw(): Promise { ## NodeJS e2e using the Core library -```bash +### Concept + +This example brings very similar concepts, but utilizing only the core library. That means that as a developer, we only care about the core capabilities (authentication, serialization, etc.) but we don't need / want the fluent API. This also highlights that types are still important in this case (similarly to how they were important with the v3 of the SDK using our Typings). + +### Install the Microsoft Graph Javascript Core SDK + +The Microsoft Graph Javascript Core SDK includes the following packages: + +- `@microsoft/msgraph-sdk-javascript-core` ([npm](https://www.npmjs.com/package/@microsoft/msgraph-sdk-javascript))- The core library for making calls to Microsoft Graph. +- `@microsoft/msgraph-sdk-javascript-type` ([npm](https://www.npmjs.com/package/@microsoft/msgraph-sdk-javascript-type)) - The Typescript types for the Microsoft Graph entities. + +You can use [npm](https://www.npmjs.com) to install the Microsoft Graph Javascript SDK: + +```Shell npm install @microsoft/msgraph-sdk-javascript-core --save -npm install @microsoft/msgraph-sdk-javascript-types --save -## npm install @microsoft/msgraph-sdk-javascript-types-beta --save +npm install @microsoft/msgraph-sdk-javascript-types --save-dev npm install @microsoft/kiota-authentication-azure --save ``` -```typescript -// App.ts +As a developer, the only package you really need is the `@microsoft/msgraph-sdk-javascript-core` one. This will deliver the expected capabilities (authentication, middlewares, tasks, etc.) and should be used in a comprehensive way for existing NodeJS developers. The types and authentication packages are recommended but optional. + +### Importing the right functionalities from the Graph Javascript Core SDK +```typescript import { Client } from "@microsoft/msgraph-sdk-javascript-core"; import { User, Message, BodyType } from "@microsoft/msgraph-sdk-javascript-core-types"; import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure"; import { DeviceCodeCredential } from "@azure/identity"; +``` + +### Setting up the app to work with the Graph Javascript Core SDK + +There should not be a difference between using the core library and the service library. The setup code should remain the same to deliver a simplified developer experience. +```typescript const deviceCodeCredentials = new DeviceCodeCredential({ tenantId: "b61f9af1-d6cf-4cc0-a6f6-befb38bc00ed", clientId: "bde251a6-0ef9-42a8-a40b-9ad9bb594b2c", @@ -127,9 +172,19 @@ const deviceCodeCredentials = new DeviceCodeCredential({ const scopes = ["User.Read", "Mail.Send"]; const graphClient = Client.init({ - accessTokenProvider: new AzureIdentityAccessTokenProvider(deviceCodeCredentials, scopes), + authenticationTokenProvider: new AzureIdentityAuthenticationProvider(deviceCodeCredentials, scopes), }); +``` +### Calling Microsoft Graph via the Graph Javascript Core SDK + +Calling the API should be done in a familiar way and should most importantly return the same models that the service library returns. That means that I can build on top of either modules without the need to redefine the types that I'll be receiving back from the API. + +Developers using our types should do it in a way that will be familiar to how they are used to with other SDKs and APIs. We should provide an easy-to-use model that feels natural in the Javascript world. This means we should not be forcing developers to use Classes and / or other structures that will make their code less natural to them. + +We have an open issue about the above topic that can be followed here : [TypeScript - Use of interface models instead of class models](https://github.com/microsoft/kiota/issues/1013) + +```typescript const me = await getMe(); await sendMail(); From 53b94a8680564feea98116095f99e623a4986055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Tue, 15 Feb 2022 15:08:31 -0500 Subject: [PATCH 8/8] Updates to the packages + Reformatingnm --- design/kiota-e2e.md | 54 ++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/design/kiota-e2e.md b/design/kiota-e2e.md index edbfe3cb1..31e776c5a 100644 --- a/design/kiota-e2e.md +++ b/design/kiota-e2e.md @@ -2,17 +2,31 @@ 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. +## Status + +| Date | Version | Author | Status | +| ------------------- | ------- | ---------------- | ------ | +| February 15th, 2022 | v0.2 | Sébastien Levert | Draft | +| January 17th, 2022 | v0.1 | Sébastien Levert | Draft | + ## Constraints Before we jump into the end-to-end walk-through, it's important to set some constraints. -| Type | Description | -| --------- | --------------------------------------------------------------------------------------------------------------------------------------------- | -| Platforms | Node : Current and Previous LTS (14 / 16)
Web : Edge, Chrome, Firefox and Safari (Latest released version + immediate previous version) | -| Modules | Node : ESM (For preview) and potentially CJS (Based on feedback)
Web : ESM | -| Types | Typings / Models should be available for both the core and the service libraries for Graph models | +| Type | Environment | Description | +| --------- | ----------- | ------------------------------------------------------------------------------------------------- | +| Platforms | Node | Current and Previous LTS (14 / 16) | +| Platforms | Web | Edge, Chrome, Firefox and Safari (Latest released version + immediate previous version) | +| Modules | Node | ESM + CJS | +| Modules | Web | ESM | +| Types | All | Typings / Models should be available for both the core and the service libraries for Graph models | + +## Table of Contents -## NodeJS e2e using the Service library +- [NodeJS e2e using the Service library](#node-service-library) +- [NodeJS e2e using the Core library](#node-core-library) + +## NodeJS e2e using the Service library ### Concept @@ -29,10 +43,8 @@ The Microsoft Graph Javascript Service Library includes the following packages: You can use [npm](https://www.npmjs.com) to install the Microsoft Graph Javascript Service Library : -```Shell +```shell npm install @microsoft/msgraph-sdk-javascript --save -npm install @microsoft/msgraph-sdk-javascript-beta --save-dev -npm install @microsoft/kiota-authentication-azure --save ``` ### Importing the right functionalities from the Graph Javascript Service Library @@ -40,8 +52,11 @@ npm install @microsoft/kiota-authentication-azure --save ```typescript // App.ts -import { Client, User, Message, BodyType } from "@microsoft/msgraph-sdk-javascript"; -import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure"; +import { Client } from "@microsoft/msgraph-sdk-javascript"; +import { User, Message, BodyType } from "@microsoft/msgraph-sdk-javascript/models"; + +// The authentication providers would get re-exported from @microsoft/msgraph-sdk-javascript-core/authentication +import { AzureIdentityAuthenticationProvider } from "@microsoft/msgraph-sdk-javascript/authentication"; import { DeviceCodeCredential } from "@azure/identity"; ``` @@ -69,8 +84,8 @@ Models are also available in this package and should reflect the underlying vers We have an open issue about the above topic that can be followed here : [TypeScript - Use of interface models instead of class models](https://github.com/microsoft/kiota/issues/1013) ```typescript -const me = await getMe(); -const meRaw = await getMeRaw(); +const me: User | undefined = await getMe(); +const meRaw: User | undefined = await getMeRaw(); await sendMail(); await sendMailRaw(); @@ -81,7 +96,7 @@ async function getMe(): Promise { // Allowing raw calls (using the .api() method instead of the full fluent API) is important for migration purposes and cases we don't know the resource beforehands (thinking Graph Explorer, mgt-get, etc.) async function getMeRaw(): Promise { - return await graphClient.api("/me").get(); + return await graphClient.api("/me").get(); } // Sending an email via the fluent API @@ -127,7 +142,7 @@ async function sendMailRaw(): Promise { } ``` -## NodeJS e2e using the Core library +## NodeJS e2e using the Core library ### Concept @@ -145,17 +160,16 @@ You can use [npm](https://www.npmjs.com) to install the Microsoft Graph Javascri ```Shell npm install @microsoft/msgraph-sdk-javascript-core --save npm install @microsoft/msgraph-sdk-javascript-types --save-dev -npm install @microsoft/kiota-authentication-azure --save ``` -As a developer, the only package you really need is the `@microsoft/msgraph-sdk-javascript-core` one. This will deliver the expected capabilities (authentication, middlewares, tasks, etc.) and should be used in a comprehensive way for existing NodeJS developers. The types and authentication packages are recommended but optional. +As a developer, the only package you really need is the `@microsoft/msgraph-sdk-javascript-core` one. This will deliver the expected capabilities (authentication, middlewares, tasks, etc.) and should be used in a comprehensive way for existing NodeJS developers. The types are recommended but optional. ### Importing the right functionalities from the Graph Javascript Core SDK ```typescript import { Client } from "@microsoft/msgraph-sdk-javascript-core"; import { User, Message, BodyType } from "@microsoft/msgraph-sdk-javascript-core-types"; -import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure"; +import { AzureIdentityAuthenticationProvider } from "@microsoft/msgraph-sdk-javascript-core/authentication"; import { DeviceCodeCredential } from "@azure/identity"; ``` @@ -185,11 +199,11 @@ Developers using our types should do it in a way that will be familiar to how th We have an open issue about the above topic that can be followed here : [TypeScript - Use of interface models instead of class models](https://github.com/microsoft/kiota/issues/1013) ```typescript -const me = await getMe(); +const me: User = await getMe(); await sendMail(); async function getMe(): Promise { - return await graphClient.api("/me").get(); + return await graphClient.api("/me").get(); } async function sendMail(): Promise {