Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
1. Implementation of middleware options at both client and request level
2. Added docs for the middleware options
3. Added middleware util to have utils for middlewares
4. Added public for constructor for more readability
  • Loading branch information
muthurathinam-m committed Jan 30, 2019
1 parent 56d4950 commit ada88f7
Show file tree
Hide file tree
Showing 50 changed files with 698 additions and 544 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@
"${workspaceRoot}/spec/development/workload/*.js"
],
"cwd": "${workspaceRoot}",
"preLaunchTask": "Run Build",
"outFiles": [],
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "node",
"request": "launch",
"name": "Run middleware tests",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": [
"${workspaceRoot}/spec/middleware/*.js"
],
"cwd": "${workspaceRoot}",
"preLaunchTask": "Run Build",
"outFiles": [],
"internalConsoleOptions": "openOnSessionStart"
}
Expand Down
4 changes: 2 additions & 2 deletions docs/CustomMiddlewareChain.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ As name suggests it comes in middle of something and that is request and respons

### Implement Middlewares

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.
Create a custom middleware pipeline by implementing the [Middleware](../src/middleware/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.

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.

Expand Down Expand Up @@ -146,4 +146,4 @@ export class MyLoggingHandler implements Middleware {
}
```

Refer [MiddlewareOptions](../src/IMiddlewareOptions.ts) interface to know its structure.
Refer [MiddlewareOptions](../src/middleware/option/IMiddlewareOption.ts) interface to know its structure.
17 changes: 16 additions & 1 deletion docs/OtherAPIs.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ try {
}
```

## MIDDLEWAREOPTION

You can pass in the middleware options for a request through `.middlewareOption()`. This takes array of strongly typed middleware options, these middleware options should be an implementation of MiddlewareOption interface

```typescript
try {
let res = await client.api("/me/messages").middlewareOption([
new RetryHandlerOption(5000)
]).get();
console.log(res);
} catch (error) {
throw error;
}
```

## RESPONSETYPE

To set a custom response type, use the`.responseType(<ResponseType>)` method. Refer [ResponseType.ts](./src/ResponseType.ts) for available options.
Expand All @@ -85,4 +100,4 @@ try {
} catch (error) {
throw error;
}
````
````
98 changes: 10 additions & 88 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
"tslib": "^1.9.3"
},
"devDependencies": {
"@types/fetch-mock": "^7.2.2",
"@types/isomorphic-fetch": "0.0.34",
"@types/mocha": "^5.2.5",
"@types/node": "^10.12.10",
"browserify": "^16.2.3",
"chai": "^4.2.0",
"fetch-mock": "^7.2.5",
"msal": "^0.2.4",
"mocha": "^5.2.0",
"typescript": "^3.1.6",
Expand All @@ -33,12 +31,12 @@
"web:js": "node browserify-with-dependencies.js > lib/graph-js-sdk-web.js && uglifyjs ./lib/graph-js-sdk-web.js --output ./lib/graph-js-sdk-web.js",
"core:js": "node browserify.js > lib/graph-js-sdk-core.js && uglifyjs ./lib/graph-js-sdk-core.js --output ./lib/graph-js-sdk-core.js",
"build": "npm run compile && npm run web:js && npm run core:js",
"test": "mocha lib/spec/content && mocha lib/spec/core && mocha lib/spec/tasks",
"test": "mocha lib/spec/content && mocha lib/spec/core && mocha lib/spec/middleware && mocha lib/spec/tasks",
"test:content": "tsc -p spec && mocha spec/content",
"test:core": "tsc -p spec && mocha spec/core",
"test:middleware": "tsc -p spec && mocha spec/middleware",
"test:tasks": "tsc -p spec && mocha spec/tasks",
"test:development": "tsc -p spec && mocha spec/development/middleware && mocha spec/development/workload",
"test:middleware": "tsc -p spec && mocha spec/development/middleware",
"test:development": "tsc -p spec && mocha spec/development/workload",
"test:workload": "tsc -p spec && mocha spec/development/workload",
"prepack": "npm install && npm run build && npm run test"
},
Expand Down
2 changes: 1 addition & 1 deletion samples/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

You can get an access token by doing the following:

1. Rename [secrets.sample.json](./secrets.example.json) to secrets.json
1. Rename [secrets.sample.json](./secrets.sample.json) to secrets.json
2. Go to Graph Explorer.
3. Login with the account you want to use to run the node samples.
4. Open the F12 dev tools.
Expand Down
File renamed without changes.
15 changes: 0 additions & 15 deletions spec/CustomHTTPHandler.ts

This file was deleted.

20 changes: 18 additions & 2 deletions spec/DummyAuthenticationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,27 @@
* -------------------------------------------------------------------------------------------
*/

/**
* @module DummyAuthenticationProvider
*/

import { AuthenticationProvider } from "../src/IAuthenticationProvider";

/**
* @class
* @implements AuthenticationProvider
* Class representing DummyAuthenticationProvider
*/
export class DummyAuthenticationProvider implements AuthenticationProvider {

/**
* @public
* @async
* To get the access token
* @returns The promise that resolves to an access token
*/
public async getAccessToken(): Promise<any> {
let token = "DUMMY_TOKEN";
const token = "DUMMY_TOKEN";
return Promise.resolve(token);
}
}
}
32 changes: 32 additions & 0 deletions spec/DummyHTTPMessageHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/

/**
* @module DummyHTTPMessageHandler
*/

import { Context } from "../src/IContext";
import { Middleware } from "../src/middleware/IMiddleware";

/**
* @class
* @implements Middleware
* Class representing DummyHTTPMessageHandler
*/
export class DummyHTTPMessageHandler implements Middleware {

/**
* @public
* @async
* To execute the current middleware
* @param {Context} context - The request context object
* @returns A promise that resolves to nothing
*/
public async execute(context: Context) {
return;
}
}
38 changes: 38 additions & 0 deletions spec/DummyHandlerOption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/

/**
* @module DummyHandlerOption
*/

import { MiddlewareOption } from "../src/middleware/option/IMiddlewareOption";

/**
* @class
* @implements MiddlewareOption
* Class for DummyHandlerOption
*/

export class DummyHandlerOption implements MiddlewareOption {

/**
* @public
* A member holding a dummy string
*/
public dummyString: string;

/**
* @public
* @async
* To create an instance of DummyHandlerOption
* @param {string} dummyString - The dummy string
* @returns An instance of DummyHandlerOption
*/
public constructor(dummyString: string = "dummy") {
this.dummyString = dummyString;
}
}
Loading

0 comments on commit ada88f7

Please sign in to comment.