Skip to content

Commit 1847eb6

Browse files
author
Andrew Omondi
committed
Merge branch 'main' into andrueastman/untypedNodes
2 parents dd20b2f + 66e2edd commit 1847eb6

13 files changed

+46
-58
lines changed

package-lock.json

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

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"@types/chai": "^4.3.11",
88
"@types/mocha": "^10.0.6",
99
"@types/node": "^20.11.15",
10-
"@types/node-fetch": "^2.6.11",
1110
"@types/sinon": "^17.0.3",
1211
"@typescript-eslint/eslint-plugin": "^7.0.1",
1312
"@typescript-eslint/parser": "^7.0.1",

packages/abstractions/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"dependencies": {
3737
"@opentelemetry/api": "^1.7.0",
38-
"@std-uritemplate/std-uritemplate": "^0.0.53",
38+
"@std-uritemplate/std-uritemplate": "^0.0.54",
3939
"guid-typescript": "^1.0.9",
4040
"tinyduration": "^3.3.0",
4141
"tslib": "^2.6.2",

packages/http/fetch/docs/design/isomorphic.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ To achieve the isomorphism, the library is set up in the following ways:
3131

3232
Often times the library will have code which is different for the browser and node environments.
3333
Examples:
34-
- Browsers use a global `fetch` defined in the `DOM` while node relies on an external library such as `node-fetch` or `undici`.
3534
- `ReadableStream` are different interfaces in node and browser.
3635

3736
To manage such differences, separate files are maintained when the code can be different for node or browser.
3837

3938
For example:
40-
- The `DefaultFetchHandler` uses `node-fetch` for node and the `dom` fetch for browser.
39+
- Browser environment doesn't require a `RedirectHandler` middleware while the `Node.js` environment does.
4140
- Map this difference as follows:
4241

4342
```json
@@ -129,7 +128,7 @@ export type FetchRequestInit = Omit<RequestInit, "body" | "headers" | "redirect"
129128
/**
130129
* Request's body
131130
* Expected type in case of dom - ReadableStream | XMLHttpRequestBodyInit|null
132-
* Expected type in case of node-fetch - | Blob | Buffer | URLSearchParams | NodeJS.ReadableStream | string|null
131+
* Expected type in case of node.js - | Blob | Buffer | URLSearchParams | NodeJS.ReadableStream | string|null
133132
*/
134133
body?: unknown;
135134
}

packages/http/fetch/docs/design/testing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- Test formats:
77
- script to test `CommonJS` modules: `npm run test:cjs`
88
- script to test `ES` modules: `npm run test:es`
9-
- Examples of node environment specific tests: Test `DefaultFetchHandler` using `node-fetch` library.
9+
- Examples of node environment specific tests: Test `middlewareFactory.ts`.
1010

1111

1212
### Testing for browser

packages/http/fetch/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"@microsoft/kiota-abstractions": "^1.0.0-preview.44",
4242
"@opentelemetry/api": "^1.7.0",
4343
"guid-typescript": "^1.0.9",
44-
"node-fetch": "^2.7.0",
4544
"tslib": "^2.6.2"
4645
},
4746
"publishConfig": {

packages/http/fetch/src/kiotaClientFactory.ts

+27-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,34 @@ export class KiotaClientFactory {
99
/**
1010
* @public
1111
* @static
12-
* Returns an instance of HttpClient with the provided middlewares and custom fetch implementation
12+
* Returns an instance of HttpClient with the provided middlewares and custom fetch implementation both parameters are optional.
13+
* if not provided, the default fetch implementation and middlewares will be used.
14+
* @param {(request: string, init?: RequestInit) => Promise < Response >} customFetch - a Fetch API implementation
15+
* @param {Middleware[]} middlewares - an aray of Middleware handlers
16+
* If middlewares param is undefined, the httpClient instance will use the default array of middlewares.
17+
* Set middlewares to `null` if you do not wish to use middlewares.
18+
* If custom fetch is undefined, the httpClient instance uses the `DefaultFetchHandler`
1319
* @returns a HttpClient instance
20+
* @example
21+
* ```Typescript
22+
* // Example usage of KiotaClientFactory.create method with both customFetch and middlewares parameters provided
23+
* KiotaClientFactory.create(customFetch, [middleware1, middleware2]);
24+
* ```
25+
* @example
26+
* ```Typescript
27+
* // Example usage of KiotaClientFactory.create method with only customFetch parameter provided
28+
* KiotaClientFactory.create(customFetch);
29+
* ```
30+
* @example
31+
* ```Typescript
32+
* // Example usage of KiotaClientFactory.create method with only middlewares parameter provided
33+
* KiotaClientFactory.create(undefined, [middleware1, middleware2]);
34+
* ```
35+
* @example
36+
* ```Typescript
37+
* // Example usage of KiotaClientFactory.create method with no parameters provided
38+
* KiotaClientFactory.create();
39+
* ```
1440
*/
1541
public static create(customFetch: (request: string, init: RequestInit) => Promise<Response> = fetch as any, middlewares?: Middleware[]): HttpClient {
1642
const middleware = middlewares || MiddlewareFactory.getDefaultMiddlewares(customFetch);

packages/http/fetch/src/utils/fetchDefinitions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type FetchHeaders = Headers & {
3636
*/
3737
values?(): IterableIterator<string>;
3838

39-
/** Node-fetch extension */
39+
/** Node extension */
4040
raw?(): Record<string, string[]>;
4141
};
4242

@@ -48,7 +48,7 @@ export type FetchRequestInit = Omit<RequestInit, "body" | "headers" | "redirect"
4848
/**
4949
* Request's body
5050
* Expected type in case of dom - ReadableStream | XMLHttpRequestBodyInit|null
51-
* Expected type in case of node-fetch - | Blob | Buffer | URLSearchParams | NodeJS.ReadableStream | string|null
51+
* Expected type in case of node.js - | Blob | Buffer | URLSearchParams | NodeJS.ReadableStream | string|null
5252
*/
5353
body?: unknown;
5454
/**

packages/http/fetch/test/common/ChaosHandler.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import { HttpMethod } from "@microsoft/kiota-abstractions";
99
import { assert } from "chai";
10-
import { Response } from "node-fetch";
1110

1211
import { ChaosHandler, ChaosStrategy, type FetchRequestInit } from "../../src";
1312
import { DummyFetchHandler } from "./middleware/dummyFetchHandler";

packages/http/fetch/test/common/fetchRequestAdapter.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ var Response = Response;
1919
if (typeof Response !== "object") {
2020
Response = getResponse();
2121
}
22+
2223
describe("FetchRequestAdapter.ts", () => {
2324
describe("getClaimsFromResponse", () => {
2425
it("should get claims from response header", async () => {
2526
const mockHttpClient = new HttpClient();
2627
let executeFetchCount = 0;
2728
mockHttpClient.executeFetch = async (url: string, requestInit: RequestInit, requestOptions?: Record<string, RequestOption>) => {
28-
let response = new Response("", {
29+
let response = new Response(null, {
2930
status: 204,
3031
} as ResponseInit);
3132
if (executeFetchCount === 0) {
@@ -103,7 +104,7 @@ describe("FetchRequestAdapter.ts", () => {
103104
}
104105
});
105106
describe("send returns object on content", () => {
106-
for (const statusCode of [200, 201, 202, 203, 205]) {
107+
for (const statusCode of [200, 201, 202, 203]) {
107108
it(`should return object for status code ${statusCode}`, async () => {
108109
const mockHttpClient = new HttpClient();
109110
mockHttpClient.executeFetch = async (url: string, requestInit: RequestInit, requestOptions?: Record<string, RequestOption>) => {

packages/http/fetch/test/common/middleware/headersInspectionHandler.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
import { assert } from "chai";
9-
import { Response } from "node-fetch";
109

1110
import { HeadersInspectionHandler, HeadersInspectionOptions } from "../../../src";
1211
import { DummyFetchHandler } from "./dummyFetchHandler";

packages/http/fetch/test/node/RedirectHandler.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
import { assert } from "chai";
9-
import { Response } from "node-fetch";
109

1110
import { RedirectHandlerOptionKey, RedirectHandlerOptions } from "../../src/middlewares/options/redirectHandlerOptions";
1211
import { RedirectHandler } from "../../src/middlewares/redirectHandler";

packages/http/fetch/test/testUtils.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Response } from "node-fetch";
2-
31
export function getResponse() {
42
return Response;
53
}

0 commit comments

Comments
 (0)