Skip to content

Commit ada88f7

Browse files
Changes:
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
1 parent 56d4950 commit ada88f7

Some content is hidden

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

50 files changed

+698
-544
lines changed

.vscode/launch.json

+14
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@
3535
"${workspaceRoot}/spec/development/workload/*.js"
3636
],
3737
"cwd": "${workspaceRoot}",
38+
"preLaunchTask": "Run Build",
39+
"outFiles": [],
40+
"internalConsoleOptions": "openOnSessionStart"
41+
},
42+
{
43+
"type": "node",
44+
"request": "launch",
45+
"name": "Run middleware tests",
46+
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
47+
"args": [
48+
"${workspaceRoot}/spec/middleware/*.js"
49+
],
50+
"cwd": "${workspaceRoot}",
51+
"preLaunchTask": "Run Build",
3852
"outFiles": [],
3953
"internalConsoleOptions": "openOnSessionStart"
4054
}

docs/CustomMiddlewareChain.md

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

99
### Implement Middlewares
1010

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.
11+
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.
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

@@ -146,4 +146,4 @@ export class MyLoggingHandler implements Middleware {
146146
}
147147
```
148148

149-
Refer [MiddlewareOptions](../src/IMiddlewareOptions.ts) interface to know its structure.
149+
Refer [MiddlewareOptions](../src/middleware/option/IMiddlewareOption.ts) interface to know its structure.

docs/OtherAPIs.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ try {
7474
}
7575
```
7676

77+
## MIDDLEWAREOPTION
78+
79+
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
80+
81+
```typescript
82+
try {
83+
let res = await client.api("/me/messages").middlewareOption([
84+
new RetryHandlerOption(5000)
85+
]).get();
86+
console.log(res);
87+
} catch (error) {
88+
throw error;
89+
}
90+
```
91+
7792
## RESPONSETYPE
7893

7994
To set a custom response type, use the`.responseType(<ResponseType>)` method. Refer [ResponseType.ts](./src/ResponseType.ts) for available options.
@@ -85,4 +100,4 @@ try {
85100
} catch (error) {
86101
throw error;
87102
}
88-
````
103+
````

package-lock.json

+10-88
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
"tslib": "^1.9.3"
1616
},
1717
"devDependencies": {
18-
"@types/fetch-mock": "^7.2.2",
1918
"@types/isomorphic-fetch": "0.0.34",
2019
"@types/mocha": "^5.2.5",
2120
"@types/node": "^10.12.10",
2221
"browserify": "^16.2.3",
2322
"chai": "^4.2.0",
24-
"fetch-mock": "^7.2.5",
2523
"msal": "^0.2.4",
2624
"mocha": "^5.2.0",
2725
"typescript": "^3.1.6",
@@ -33,12 +31,12 @@
3331
"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",
3432
"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",
3533
"build": "npm run compile && npm run web:js && npm run core:js",
36-
"test": "mocha lib/spec/content && mocha lib/spec/core && mocha lib/spec/tasks",
34+
"test": "mocha lib/spec/content && mocha lib/spec/core && mocha lib/spec/middleware && mocha lib/spec/tasks",
3735
"test:content": "tsc -p spec && mocha spec/content",
3836
"test:core": "tsc -p spec && mocha spec/core",
37+
"test:middleware": "tsc -p spec && mocha spec/middleware",
3938
"test:tasks": "tsc -p spec && mocha spec/tasks",
40-
"test:development": "tsc -p spec && mocha spec/development/middleware && mocha spec/development/workload",
41-
"test:middleware": "tsc -p spec && mocha spec/development/middleware",
39+
"test:development": "tsc -p spec && mocha spec/development/workload",
4240
"test:workload": "tsc -p spec && mocha spec/development/workload",
4341
"prepack": "npm install && npm run build && npm run test"
4442
},

samples/node/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
You can get an access token by doing the following:
66

7-
1. Rename [secrets.sample.json](./secrets.example.json) to secrets.json
7+
1. Rename [secrets.sample.json](./secrets.sample.json) to secrets.json
88
2. Go to Graph Explorer.
99
3. Login with the account you want to use to run the node samples.
1010
4. Open the F12 dev tools.
File renamed without changes.

spec/CustomHTTPHandler.ts

-15
This file was deleted.

spec/DummyAuthenticationProvider.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,27 @@
55
* -------------------------------------------------------------------------------------------
66
*/
77

8+
/**
9+
* @module DummyAuthenticationProvider
10+
*/
11+
812
import { AuthenticationProvider } from "../src/IAuthenticationProvider";
913

14+
/**
15+
* @class
16+
* @implements AuthenticationProvider
17+
* Class representing DummyAuthenticationProvider
18+
*/
1019
export class DummyAuthenticationProvider implements AuthenticationProvider {
20+
21+
/**
22+
* @public
23+
* @async
24+
* To get the access token
25+
* @returns The promise that resolves to an access token
26+
*/
1127
public async getAccessToken(): Promise<any> {
12-
let token = "DUMMY_TOKEN";
28+
const token = "DUMMY_TOKEN";
1329
return Promise.resolve(token);
1430
}
15-
}
31+
}

spec/DummyHTTPMessageHandler.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* -------------------------------------------------------------------------------------------
3+
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
4+
* See License in the project root for license information.
5+
* -------------------------------------------------------------------------------------------
6+
*/
7+
8+
/**
9+
* @module DummyHTTPMessageHandler
10+
*/
11+
12+
import { Context } from "../src/IContext";
13+
import { Middleware } from "../src/middleware/IMiddleware";
14+
15+
/**
16+
* @class
17+
* @implements Middleware
18+
* Class representing DummyHTTPMessageHandler
19+
*/
20+
export class DummyHTTPMessageHandler implements Middleware {
21+
22+
/**
23+
* @public
24+
* @async
25+
* To execute the current middleware
26+
* @param {Context} context - The request context object
27+
* @returns A promise that resolves to nothing
28+
*/
29+
public async execute(context: Context) {
30+
return;
31+
}
32+
}

spec/DummyHandlerOption.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* -------------------------------------------------------------------------------------------
3+
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
4+
* See License in the project root for license information.
5+
* -------------------------------------------------------------------------------------------
6+
*/
7+
8+
/**
9+
* @module DummyHandlerOption
10+
*/
11+
12+
import { MiddlewareOption } from "../src/middleware/option/IMiddlewareOption";
13+
14+
/**
15+
* @class
16+
* @implements MiddlewareOption
17+
* Class for DummyHandlerOption
18+
*/
19+
20+
export class DummyHandlerOption implements MiddlewareOption {
21+
22+
/**
23+
* @public
24+
* A member holding a dummy string
25+
*/
26+
public dummyString: string;
27+
28+
/**
29+
* @public
30+
* @async
31+
* To create an instance of DummyHandlerOption
32+
* @param {string} dummyString - The dummy string
33+
* @returns An instance of DummyHandlerOption
34+
*/
35+
public constructor(dummyString: string = "dummy") {
36+
this.dummyString = dummyString;
37+
}
38+
}

0 commit comments

Comments
 (0)