- Notifications
You must be signed in to change notification settings - Fork 232
Client init with middleware array #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits Select commit Hold shift + click to select a range
7712318 Passing midddleware array in client options
nikithauc b426829 Tests for middleware array
nikithauc 8e4a34a Removing try catch
nikithauc 6191c42 ifnode condition,chain middleware test
nikithauc 164d73e Adding missing exports
nikithauc 2d88002 Array initialization
nikithauc 4a06c26 Merge branch 'dev' into nikithauc/middleware-array
nikithauc cee76af merging with dev
nikithauc 62d2213 Using spread operator
nikithauc 63b28ce Checking if middleware is not empty
nikithauc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /** | ||
| * ------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. | ||
| * See License in the project root for license information. | ||
| * ------------------------------------------------------------------------------------------- | ||
| */ | ||
| | ||
| import { assert } from "chai"; | ||
| | ||
| import { AuthenticationHandler, CustomAuthenticationProvider, HTTPMessageHandler, RedirectHandler, RetryHandler, TelemetryHandler } from "../../src"; | ||
| import { AuthProvider } from "../../src/IAuthProvider"; | ||
| import { MiddlewareFactory } from "../../src/middleware/MiddlewareFactory"; | ||
| | ||
| describe("MiddlewareFactory", () => { | ||
| it("Should return the default pipeline", () => { | ||
| const provider: AuthProvider = (done) => { | ||
| done(null, "dummy_token"); | ||
| }; | ||
| const defaultMiddleWareArray = MiddlewareFactory.getDefaultMiddlewareChain(new CustomAuthenticationProvider(provider)); | ||
| | ||
| assert.isTrue(defaultMiddleWareArray[0] instanceof AuthenticationHandler); | ||
| assert.isTrue(defaultMiddleWareArray[1] instanceof RetryHandler); | ||
| assert.isTrue(defaultMiddleWareArray[2] instanceof RedirectHandler); | ||
| assert.isTrue(defaultMiddleWareArray[3] instanceof TelemetryHandler); | ||
| assert.isTrue(defaultMiddleWareArray[4] instanceof HTTPMessageHandler); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /** | ||
| * ------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. | ||
| * See License in the project root for license information. | ||
| * ------------------------------------------------------------------------------------------- | ||
| */ | ||
| | ||
| /** | ||
| * @module MiddlewareFactory | ||
| */ | ||
| | ||
| import { AuthenticationProvider } from "../IAuthenticationProvider"; | ||
| | ||
| import { AuthenticationHandler } from "./AuthenticationHandler"; | ||
| import { HTTPMessageHandler } from "./HTTPMessageHandler"; | ||
| import { Middleware } from "./IMiddleware"; | ||
| import { RedirectHandlerOptions } from "./options/RedirectHandlerOptions"; | ||
| import { RetryHandlerOptions } from "./options/RetryHandlerOptions"; | ||
| import { RedirectHandler } from "./RedirectHandler"; | ||
| import { RetryHandler } from "./RetryHandler"; | ||
| import { TelemetryHandler } from "./TelemetryHandler"; | ||
| | ||
| /** | ||
| * @private | ||
| * To check whether the environment is node or not | ||
| * @returns A boolean representing the environment is node or not | ||
| */ | ||
| const isNodeEnvironment = (): boolean => { | ||
| return typeof process === "object" && typeof require === "function"; | ||
| }; | ||
| | ||
| /** | ||
| * @class | ||
| * Class containing function(s) related to the middleware pipelines. | ||
| */ | ||
| export class MiddlewareFactory { | ||
| /** | ||
| * @public | ||
| * @static | ||
| * Returns the default middleware chain an array with the middleware handlers | ||
| * @param {AuthenticationProvider} authProvider - The authentication provider instance | ||
| * @returns an array of the middleware handlers of the default middleware chain | ||
| */ | ||
| public static getDefaultMiddlewareChain(authProvider: AuthenticationProvider): Middleware[] { | ||
| const middleware: Middleware[] = []; | ||
| const authenticationHandler = new AuthenticationHandler(authProvider); | ||
| const retryHandler = new RetryHandler(new RetryHandlerOptions()); | ||
| const telemetryHandler = new TelemetryHandler(); | ||
| const httpMessageHandler = new HTTPMessageHandler(); | ||
| | ||
| middleware.push(authenticationHandler); | ||
| middleware.push(retryHandler); | ||
| if (isNodeEnvironment()) { | ||
MIchaelMainer marked this conversation as resolved. Show resolved Hide resolved | ||
| const redirectHandler = new RedirectHandler(new RedirectHandlerOptions()); | ||
| middleware.push(redirectHandler); | ||
| } | ||
| middleware.push(telemetryHandler); | ||
| middleware.push(httpMessageHandler); | ||
| | ||
| return middleware; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.