Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f48ed18
updated broken link in README
krototype Aug 16, 2019
8178222
Merge pull request #218 from microsoftgraph/abhsriva/updateREADME
krototype Aug 22, 2019
2ec9a2f
Merge branch 'master' into dev
muthu-rathinam Aug 27, 2019
32daeb8
Post request with empty body, now working fine.
krototype Sep 16, 2019
eed1515
Merge branch 'dev' into abhsriva/emptyPostRequest
krototype Sep 16, 2019
6850658
updated the tests for this case
krototype Sep 16, 2019
f7c333b
Merge branch 'abhsriva/emptyPostRequest' of https://github.com/micros…
krototype Sep 17, 2019
2ebf666
made change to use undefined instead of null as classname
krototype Sep 17, 2019
7baaf98
Merge pull request #229 from microsoftgraph/abhsriva/emptyPostRequest
krototype Oct 3, 2019
834fcf3
added functionality to simplify building middleware chain
krototype Oct 15, 2019
b2f7d3b
Merge branch 'dev' into build_middleware_chain
krototype Oct 15, 2019
de8a55b
Merge pull request #239 from microsoftgraph/build_middleware_chain
krototype Oct 18, 2019
072bed1
Updated GraphRequest.ts for .count() scenario
krototype Oct 22, 2019
b9a66b4
Merge pull request #243 from microsoftgraph/abhsriva/update-count
krototype Oct 25, 2019
c3e0ef3
Bumped version to '2.1.0-Preview.1'
muthu-rathinam Oct 25, 2019
4a6c3c2
Bump version to 2.1.0
nikithauc Sep 30, 2020
9bb69d3
Merge branch 'master' into nikithauc/Release-2.1.0
nikithauc Sep 30, 2020
8fbc543
Changing condition for checking content type
nikithauc Sep 30, 2020
2759d38
Merge branch 'nikithauc/Release-2.1.0' of https://github.com/microsof…
nikithauc Sep 30, 2020
4d96da5
Condition change.
nikithauc Sep 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/CustomMiddlewareChain.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,4 @@ export class MyLoggingHandler implements Middleware {
}
}
```

Refer [MiddlewareOptions](../src/middleware/option/IMiddlewareOptions.ts) interface to know its structure.
Refer [MiddlewareOptions](../src/middleware/options/IMiddlewareOptions.ts) interface to know its structure.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/microsoft-graph-client",
"version": "2.0.0",
"version": "2.1.0",
"description": "Microsoft Graph Client Library",
"main": "lib/src/index.js",
"module": "lib/es/index.js",
Expand Down
7 changes: 6 additions & 1 deletion spec/core/GraphRequestUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ describe("GraphRequestUtil.ts", () => {
node2.link = node1;
try {
serializeContent(node1);
throw new Error("Something wrong with the serialize content, it should stringify cyclic referenced objects");
throw new Error("Something wrong with the serialize content, it should not stringify cyclic referenced objects");
} catch (error) {
assert.equal(error.message, "Unable to stringify the content");
}
});

it("Should return undefined for the case of undefined content value", () => {
const val = undefined;
assert.equal(serializeContent(val), undefined);
});
});
});
39 changes: 39 additions & 0 deletions spec/core/HTTPClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@

import { assert } from "chai";

import { Client } from "../../src/Client";
import { HTTPClient } from "../../src/HTTPClient";
import { Context } from "../../src/IContext";
import { FetchOptions } from "../../src/IFetchOptions";
import { RedirectHandlerOptions } from "../../src/middleware/options/RedirectHandlerOptions";
import { RedirectHandler } from "../../src/middleware/RedirectHandler";
import { TelemetryHandler } from "../../src/middleware/TelemetryHandler";
import { DummyHTTPMessageHandler } from "../DummyHTTPMessageHandler";

describe("HTTPClient.ts", () => {
Expand Down Expand Up @@ -68,4 +72,39 @@ describe("HTTPClient.ts", () => {
}
});
});

describe("getMiddlewareArray", () => {
it("Should work fine for a single middleware in the chain, which does have a getNext method", () => {
const telemetryHandler = new TelemetryHandler();
const tempHttpClient: HTTPClient = new HTTPClient(telemetryHandler);
assert.equal(tempHttpClient.getMiddlewareArray().length, 1);
});

it("Should work fine for a single middleware in the chain, which doesn't have a getNext method", () => {
const tempHttpClient: HTTPClient = new HTTPClient(httpMessageHandler);
assert.equal(tempHttpClient.getMiddlewareArray().length, 1);
});

it("Should work fine for a chain containing many middlewares", () => {
const telemetryHandler = new TelemetryHandler();
const redirectHandler = new RedirectHandler(new RedirectHandlerOptions());
redirectHandler.setNext(telemetryHandler);
telemetryHandler.setNext(httpMessageHandler);
const tempHttpClient: HTTPClient = new HTTPClient(redirectHandler);
assert.equal(tempHttpClient.getMiddlewareArray().length, 3);
});
});

describe("setMiddlewareArray", () => {
it("Should make a chain out of the provided array of middlewares", () => {
const telemetryHandler = new TelemetryHandler();
const redirectHandler = new RedirectHandler(new RedirectHandlerOptions());
redirectHandler.setNext(httpMessageHandler);
const tempHttpClient: HTTPClient = new HTTPClient(redirectHandler);
const middlewareArray = tempHttpClient.getMiddlewareArray();
middlewareArray.splice(1, 0, telemetryHandler);
tempHttpClient.setMiddlewareArray(middlewareArray);
assert.equal(tempHttpClient.getMiddlewareArray().length, 3);
});
});
});
19 changes: 19 additions & 0 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { HTTPClient } from "./HTTPClient";
import { HTTPClientFactory } from "./HTTPClientFactory";
import { ClientOptions } from "./IClientOptions";
import { Options } from "./IOptions";
import { Middleware } from "./middleware/IMiddleware";
import { validatePolyFilling } from "./ValidatePolyFilling";

export class Client {
Expand Down Expand Up @@ -103,6 +104,24 @@ export class Client {
this.httpClient = httpClient;
}

/**
* @public
* function to get the array of middlewares in use right now
* @returns An array of middlewares
*/
public getMiddlewareChain() {
return this.httpClient.getMiddlewareArray();
}

/**
* @public
* function to set the middleware chain
* @param {Middleware[]} middlewareArray - An array of middlewares
*/
public setMiddlewareChain(middlewareArray: Middleware[]) {
return this.httpClient.setMiddlewareArray(middlewareArray);
}

/**
* @public
* Entry point to make requests
Expand Down
2 changes: 1 addition & 1 deletion src/GraphRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ export class GraphRequest {
* @param {boolean} isCount - The count boolean
* @returns The same GraphRequest instance that is being called with
*/
public count(isCount: boolean): GraphRequest {
public count(isCount: boolean = false): GraphRequest {
this.urlComponents.oDataQueryParams.$count = isCount.toString();
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/GraphRequestUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const urlJoin = (urlSegments: string[]): string => {
*/

export const serializeContent = (content: any): any => {
const className: string = content.constructor.name;
const className: string = content && content.constructor && content.constructor.name;
if (className === "Buffer" || className === "Blob" || className === "File" || className === "FormData" || typeof content === "string") {
return content;
}
Expand Down
31 changes: 31 additions & 0 deletions src/HTTPClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,37 @@ export class HTTPClient {
this.middleware = middleware;
}

/**
* @public
* To get an array of Middleware, used in middleware chain
* @returns An array of middlewares
*/
public getMiddlewareArray(): Middleware[] {
const middlewareArray: Middleware[] = [];
let currentMiddleware = this.middleware;
while (currentMiddleware) {
middlewareArray.push(currentMiddleware);
if (currentMiddleware.getNext) {
currentMiddleware = currentMiddleware.getNext();
} else {
break;
}
}
return middlewareArray;
}

/**
* @public
* To set the middleware chain
* @param {Middleware[]} middlewareArray - The array containing the middlewares
*/
public setMiddlewareArray(middlewareArray: Middleware[]) {
for (let num = 0; num < middlewareArray.length - 1; num += 1) {
middlewareArray[num].setNext(middlewareArray[num + 1]);
}
this.middleware = middlewareArray[0];
}

/**
* @public
* @async
Expand Down
2 changes: 1 addition & 1 deletion src/Version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
* @module Version
*/

export const PACKAGE_VERSION = "2.0.0";
export const PACKAGE_VERSION = "2.1.0";
9 changes: 9 additions & 0 deletions src/middleware/AuthenticationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,13 @@ export class AuthenticationHandler implements Middleware {
public setNext(next: Middleware): void {
this.nextMiddleware = next;
}

/**
* @public
* To get the next middleware in the chain
* @returns next Middleware instance
*/
public getNext(): Middleware {
return this.nextMiddleware;
}
}
1 change: 1 addition & 0 deletions src/middleware/IMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ import { Context } from "../IContext";
export interface Middleware {
execute: (context: Context) => Promise<void>;
setNext?: (middleware: Middleware) => void;
getNext?: () => Middleware;
}
9 changes: 9 additions & 0 deletions src/middleware/RedirectHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,13 @@ export class RedirectHandler implements Middleware {
public setNext(next: Middleware): void {
this.nextMiddleware = next;
}

/**
* @public
* To get the next middleware in the chain
* @returns next Middleware instance
*/
public getNext(): Middleware {
return this.nextMiddleware;
}
}
9 changes: 9 additions & 0 deletions src/middleware/RetryHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,13 @@ export class RetryHandler implements Middleware {
public setNext(next: Middleware): void {
this.nextMiddleware = next;
}

/**
* @public
* To get the next middleware in the chain
* @returns next Middleware instance
*/
public getNext(): Middleware {
return this.nextMiddleware;
}
}
9 changes: 9 additions & 0 deletions src/middleware/TelemetryHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,13 @@ export class TelemetryHandler implements Middleware {
public setNext(next: Middleware): void {
this.nextMiddleware = next;
}

/**
* @public
* To get the next middleware in the chain
* @returns next Middleware instance
*/
public getNext(): Middleware {
return this.nextMiddleware;
}
}