Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 16 additions & 16 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
]
},
"dependencies": {
"@microsoft/kiota-abstractions": "^1.0.0-preview.1",
"@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.1",
"@microsoft/kiota-abstractions": "^1.0.0-preview.5",
"@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.6",
"tslib": "^2.2.0"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class Client implements GraphBaseClient {
baseUrl: GRAPH_BASE_URL,
debugLogging: false,
defaultVersion: GRAPH_API_VERSION,
authProvider: undefined
};

/**
Expand Down Expand Up @@ -67,7 +68,7 @@ export class Client implements GraphBaseClient {
error.message = "Unable to Create Client, Please provide an authentication provider";
throw error;
}
const allowedHosts = updateAndReturnAllAllowedHosts(clientOptions.authProvider, this.config.customHosts);
const allowedHosts = updateAndReturnAllAllowedHosts(clientOptions.authProvider);

if (!clientOptions.middleware) {
httpClient = new HttpClient(undefined, ...[].concat(getDefaultMiddlewareChain(clientOptions, allowedHosts)));
Expand Down
11 changes: 5 additions & 6 deletions src/GraphRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/**
* @module GraphRequest
*/
import { RequestOption } from "@microsoft/kiota-abstractions";
import { HttpClient } from "@microsoft/kiota-http-fetchlibrary";

import { GraphClientError } from "./GraphClientError";
Expand All @@ -18,7 +19,6 @@ import { GraphResponseHandler } from "./GraphResponseHandler";
import { ClientOptions } from "./IClientOptions";
import { FetchOptions } from "./IFetchOptions";
import { GraphRequestCallback } from "./IGraphRequestCallback";
import { MiddlewareOptions } from "./middleware/options/IMiddlewareOptions";
import { RequestMethod } from "./RequestMethod";
import { ResponseType } from "./ResponseType";
/**
Expand Down Expand Up @@ -62,7 +62,6 @@ export class GraphRequest {
*/
private httpClient: HttpClient;


/**
* @private
* A member variable to hold client options
Expand Down Expand Up @@ -91,7 +90,7 @@ export class GraphRequest {
* @private
* A member to hold the array of middleware options for a request
*/
private _middlewareOptions: MiddlewareOptions[];
private _middlewareOptions: Record<string, RequestOption>;

/**
* @private
Expand Down Expand Up @@ -119,7 +118,7 @@ export class GraphRequest {
};
this._headers = {};
this._options = {};
this._middlewareOptions = [];
this._middlewareOptions = {};
this.parsePath(path);
}

Expand Down Expand Up @@ -368,7 +367,7 @@ export class GraphRequest {
this.updateRequestOptions(options);

try {
const rawResponse = await this.httpClient.executeFetch(request as string, options);
const rawResponse = await this.httpClient.executeFetch(request as string, options, this._middlewareOptions);

const response: any = await GraphResponseHandler.getResponse(rawResponse, this._responseType, callback);
return response;
Expand Down Expand Up @@ -466,7 +465,7 @@ export class GraphRequest {
* @param {MiddlewareOptions[]} options - The array of middleware options
* @returns The same GraphRequest instance that is being called with
*/
public middlewareOptions(options: MiddlewareOptions[]): GraphRequest {
public middlewareOptions(options: Record<string, RequestOption>): GraphRequest {
this._middlewareOptions = options;
return this;
}
Expand Down
5 changes: 2 additions & 3 deletions src/GraphRequestUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ const isCustomHostValid = (host: string) => {
* @param customHosts
* @returns
*/
export const updateAndReturnAllAllowedHosts = (authProvider: BaseBearerTokenAuthenticationProvider, customHosts: Set<string>): Set<string> => {
export const updateAndReturnAllAllowedHosts = (authProvider: BaseBearerTokenAuthenticationProvider): Set<string> => {
const hostsValidator = authProvider.accessTokenProvider.getAllowedHostsValidator();
const allowedHosts = customHosts ? new Set([...customHosts, ...hostsValidator.getAllowedHosts()]) : new Set(hostsValidator.getAllowedHosts());
const hostSetWithGraphandCustomHosts = customHosts ? new Set([...allowedHosts, ...GRAPH_URLS, ...customHosts]) : new Set([...allowedHosts, ...GRAPH_URLS]);
const hostSetWithGraphandCustomHosts = new Set([...hostsValidator.getAllowedHosts(), ...GRAPH_URLS])
hostsValidator.setAllowedHosts(hostSetWithGraphandCustomHosts);
return hostSetWithGraphandCustomHosts;
};
6 changes: 1 addition & 5 deletions src/IClientOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ import { FetchOptions } from "./IFetchOptions";
*/

export interface ClientOptions {
authProvider?: BaseBearerTokenAuthenticationProvider;
authProvider: BaseBearerTokenAuthenticationProvider;
baseUrl?: string;
debugLogging?: boolean;
defaultVersion?: string;
fetchOptions?: FetchOptions;
middleware?: Middleware | Middleware[];
customFetch?: (input: string, init?: RequestInit) => Promise<Response>;
/**
* Example - If URL is "https://test_host/v1.0", then set property "customHosts" as "customHosts: Set<string>(["test_host"])"
*/
customHosts?: Set<string>;
}
1 change: 0 additions & 1 deletion src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export { RetryHandler, RedirectHandler, TelemetryHandler, RetryHandlerOptions, H
export { BatchRequestBody, RequestData, BatchRequestContent, BatchRequestData, BatchRequestStep } from "../content/BatchRequestContent";
export { BatchResponseBody, BatchResponseContent } from "../content/BatchResponseContent";

export { MiddlewareOptions } from "../middleware/options/IMiddlewareOptions";
export { FeatureUsageFlag } from "../middleware/Telemetry/TelemetryFeatureUsageFlag";
export { ChaosHandlerOptions } from "../middleware/options/ChaosHandlerOptions";
export { ChaosStrategy } from "../middleware/options/ChaosStrategy";
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export { RetryHandler, RedirectHandler, TelemetryHandler, RedirectHandlerOptionK
export { BatchRequestBody, RequestData, BatchRequestContent, BatchRequestData, BatchRequestStep } from "./content/BatchRequestContent";
export { BatchResponseBody, BatchResponseContent } from "./content/BatchResponseContent";

export { MiddlewareOptions } from "./middleware/options/IMiddlewareOptions";
export { FeatureUsageFlag } from "./middleware/Telemetry/TelemetryFeatureUsageFlag";
export { ChaosHandlerOptions } from "./middleware/options/ChaosHandlerOptions";
export { ChaosStrategy } from "./middleware/options/ChaosStrategy";
Expand Down
14 changes: 0 additions & 14 deletions src/middleware/options/IMiddlewareOptions.ts

This file was deleted.

15 changes: 8 additions & 7 deletions src/tasks/PageIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
* @module PageIterator
*/

import { RequestOption } from "@microsoft/kiota-abstractions/src/requestOption";

import { FetchOptions } from "../IFetchOptions";
import { Client } from "../index";
import { MiddlewareOptions } from "../middleware/options/IMiddlewareOptions";
import { GraphBaseClient } from "../requestBuilderUtils/GraphBaseClient";

/**
* Signature representing PageCollection
Expand All @@ -31,12 +32,12 @@ export interface PageCollection {
* Signature to define the request options to be sent during request.
* The values of the GraphRequestOptions properties are passed to the Graph Request object.
* @property {HeadersInit} headers - the header options for the request
* @property {MiddlewareOptions[]} middlewareoptions - The middleware options for the request
* @property { Record<string, RequestOption>} middlewareoptions - The middleware options for the request
* @property {FetchOptions} options - The fetch options for the request
*/
export interface GraphRequestOptions {
headers?: HeadersInit;
middlewareOptions?: MiddlewareOptions[];
headers?: Record<string, string>;
middlewareOptions?: Record<string, RequestOption>;
options?: FetchOptions;
}

Expand All @@ -55,7 +56,7 @@ export class PageIterator {
* @private
* Member holding the GraphClient instance
*/
private client: Client;
private client: GraphBaseClient;

/**
* @private
Expand Down Expand Up @@ -103,7 +104,7 @@ export class PageIterator {
* @param {GraphRequestOptions} requestOptions - The request options
* @returns An instance of a PageIterator
*/
public constructor(client: Client, pageCollection: PageCollection, callback: PageIteratorCallback, requestOptions?: GraphRequestOptions) {
public constructor(client: GraphBaseClient, pageCollection: PageCollection, callback: PageIteratorCallback, requestOptions?: GraphRequestOptions) {
this.client = client;
this.collection = pageCollection.value;
this.nextLink = pageCollection["@odata.nextLink"];
Expand Down
10 changes: 7 additions & 3 deletions test/DummyHandlerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
* -------------------------------------------------------------------------------------------
*/

import { RequestOption } from "@microsoft/kiota-abstractions";

/**
* @module DummyHandlerOptions
*/

import { MiddlewareOptions } from "../src/middleware/options/IMiddlewareOptions";

/**
* @class
* @implements MiddlewareOptions
* Class for DummyHandlerOptions
*/

export class DummyHandlerOptions implements MiddlewareOptions {
export class DummyHandlerOptions implements RequestOption {
/**
* @public
* A member holding a dummy string
Expand All @@ -34,4 +34,8 @@ export class DummyHandlerOptions implements MiddlewareOptions {
public constructor(dummyString = "dummy") {
this.dummyString = dummyString;
}

public getKey(): string {
return "DummyHandlerOptions";
}
}
7 changes: 4 additions & 3 deletions test/browser/middleware/MiddlewareFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* -------------------------------------------------------------------------------------------
*/

import { CustomFetchHandler, RedirectHandler, RetryHandler, TelemetryHandler } from "@microsoft/kiota-http-fetchlibrary";
import { CustomFetchHandler, ParametersNameDecodingHandler, RedirectHandler, RetryHandler, TelemetryHandler } from "@microsoft/kiota-http-fetchlibrary";
import { assert } from "chai";

import { ClientOptions, SimpleAuthenticationProvider } from "../../../src";
Expand All @@ -25,7 +25,8 @@ describe("MiddlewareFactory", () => {

assert.isTrue(defaultMiddleWareArray[0] instanceof AuthenticationHandler);
assert.isTrue(defaultMiddleWareArray[1] instanceof RetryHandler);
assert.isTrue(defaultMiddleWareArray[2] instanceof TelemetryHandler);
assert.isTrue(defaultMiddleWareArray[3] instanceof CustomFetchHandler);
assert.isTrue(defaultMiddleWareArray[2] instanceof ParametersNameDecodingHandler);
assert.isTrue(defaultMiddleWareArray[3] instanceof TelemetryHandler);
assert.isTrue(defaultMiddleWareArray[4] instanceof CustomFetchHandler);
});
});
22 changes: 11 additions & 11 deletions test/development/workload/PageIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { Event } from "@microsoft/microsoft-graph-types";
import { assert } from "chai";

import { Client, ClientOptions } from "../../../src";
import { Client, ClientOptions, SimpleAccessTokenProvider, SimpleAuthenticationProvider } from "../../../src";
import { ChaosHandler } from "../../../src/middleware/ChaosHandler";
import { ChaosHandlerOptions } from "../../../src/middleware/options/ChaosHandlerOptions";
import { ChaosStrategy } from "../../../src/middleware/options/ChaosStrategy";
Expand All @@ -21,7 +21,7 @@ describe("PageIterator", () => {
const pst = "Pacific Standard Time";
const testURL = "/me/events";

before(async function() {
before(async function () {
this.timeout(20000);

const response = await client.api(testURL + "?count=true").get();
Expand All @@ -46,11 +46,7 @@ describe("PageIterator", () => {
});

it("same headers passed with pageIterator", async () => {
const response = await client
.api(`${testURL}?$top=2`)
.headers(pstHeader)
.select("id,start,end")
.get();
const response = await client.api(`${testURL}?$top=2`).headers(pstHeader).select("id,start,end").get();

const callback: PageIteratorCallback = (eventResponse) => {
const event = eventResponse as Event;
Expand All @@ -63,7 +59,7 @@ describe("PageIterator", () => {
await pageIterator.iterate();
assert.isTrue(pageIterator.isComplete());
}
}).timeout(30 * 1000);
}).timeout(0);

it("different headers passed with pageIterator", async () => {
const response = await client
Expand All @@ -90,7 +86,7 @@ describe("PageIterator", () => {
await pageIterator.iterate();
assert.isTrue(pageIterator.isComplete());
}
}).timeout(30 * 1000);
}).timeout(0);

// TODO - Temporariliy commenting this test.
it("setting middleware with pageIterator", async () => {
Expand All @@ -103,6 +99,9 @@ describe("PageIterator", () => {
};
};
const clientOptions: ClientOptions = {
authProvider: new SimpleAuthenticationProvider(async () => {
return "Dummy_Token";
}),
middleware,
};
const responseBody = { value: [{ event1: "value1" }, { event2: "value2" }] };
Expand All @@ -113,8 +112,9 @@ describe("PageIterator", () => {
return true;
};

const middlewareOptions = [new ChaosHandlerOptions(ChaosStrategy.MANUAL, "middleware options for pageIterator", 200, 0, JSON.stringify(responseBody), new Headers({ "Content-Type": "application/json", "content-length": "100" }))];
const requestOptions = { middlewareOptions };
const middlewareOptions = new ChaosHandlerOptions(ChaosStrategy.MANUAL, "middleware options for pageIterator", 200, 0, JSON.stringify(responseBody), new Headers({ "Content-Type": "application/json", "content-length": "100" }));
const key = middlewareOptions.getKey();
const requestOptions: GraphRequestOptions = { middlewareOptions: { [key]: middlewareOptions } };

const client = Client.init(clientOptions);
const pageIterator = new PageIterator(client, getPageCollection(), callback, requestOptions);
Expand Down
Loading