Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/remove nodefetch #3180

Merged
merged 4 commits into from
Dec 16, 2024
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
2 changes: 1 addition & 1 deletion docs/core/behaviors.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function CompanyDefault(): TimelinePipe<Queryable> {
DefaultHeaders(),
// use the default init, but change the base url to beta
DefaultInit("https://graph.microsoft.com/beta"),
// use node-fetch with retry
// use fetch with retry
NodeFetchWithRetry(),
// use the default parsing
DefaultParse(),
Expand Down
2 changes: 1 addition & 1 deletion docs/nodejs/behaviors.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The article describes the behaviors exported by the `@pnp/nodejs` library. Pleas

## NodeFetch

This behavior, for use in nodejs, provides basic fetch support through the `node-fetch` package. It replaces any other registered observers on the send moment by default, but this can be controlled via the props. Remember, when registering observers on the send moment only the first one will be used so not replacing
This behavior, for use in nodejs, provides basic fetch support using native fetch api. It replaces any other registered observers on the send moment by default, but this can be controlled via the props. Remember, when registering observers on the send moment only the first one will be used so not replacing

> For fetch configuration in browsers please see [@pnp/queryable behaviors]("../../../queryable/behaviors.md).

Expand Down
97 changes: 3 additions & 94 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"findup-sync": "5.0.0",
"globby": "14.0.2",
"mocha": "10.7.3",
"node-fetch": "3.3.2",
"prettyjson": "1.2.5",
"string-replace-loader": "3.1.0",
"tslib": "2.7.0",
Expand Down Expand Up @@ -72,7 +71,7 @@
"sharepoint framework"
],
"engines": {
"node": ">=14.15.1"
"node": ">=18.17.1"
},
"engineStrict": true,
"maintainers": [
Expand Down
5 changes: 2 additions & 3 deletions packages/nodejs/behaviors/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { LogLevel } from "@pnp/logging";
import { HttpRequestError, Queryable } from "@pnp/queryable";
import { default as nodeFetch } from "node-fetch";
import { delay, TimelinePipe } from "@pnp/core";

export interface INodeFetchProps {
Expand All @@ -24,7 +23,7 @@ export function NodeFetch(props?: INodeFetchProps): TimelinePipe<Queryable> {

this.log(`Fetch: ${init.method} ${url.toString()}`, LogLevel.Verbose);

return <any>nodeFetch(url.toString(), <any>init);
return <any>fetch(url.toString(), <any>init);
});

return instance;
Expand Down Expand Up @@ -93,7 +92,7 @@ export function NodeFetchWithRetry(props?: INodeFetchWithRetryProps): TimelinePi

this.log(`Fetch: ${init.method} ${url.toString()}`, LogLevel.Verbose);

response = await <any>nodeFetch(url.toString(), <any>init);
response = await <any>fetch(url.toString(), <any>init);

// if we got a good response, return it, otherwise see if we can retry
return response.ok ? response : retry();
Expand Down
18 changes: 0 additions & 18 deletions packages/nodejs/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
declare let global: any;
import * as NodeFetch from "node-fetch";

(function (g) {

// patch these globally for nodejs
if (!g.Headers) {
g.Headers = NodeFetch.Headers;
}
if (!g.Request) {
g.Request = NodeFetch.Request;
}
if (!g.Response) {
g.Response = NodeFetch.Response;
}

})(global);

export * from "./behaviors/msal.js";
export * from "./behaviors/fetch.js";
export * from "./behaviors/spdefault.js";
Expand Down
1 change: 0 additions & 1 deletion packages/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"@pnp/queryable": "0.0.0-PLACEHOLDER",
"@pnp/sp": "0.0.0-PLACEHOLDER",
"@pnp/graph": "0.0.0-PLACEHOLDER",
"node-fetch": "3.3.2",
"tslib": "2.7.0"
}
}
4 changes: 2 additions & 2 deletions test/queryable/behaviors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ResolveOnData,
CacheKey,
} from "@pnp/queryable";
import { default as nodeFetch } from "node-fetch";

import "@pnp/sp/webs";
import "@pnp/sp/fields";
import { getRandomString } from "@pnp/core";
Expand Down Expand Up @@ -166,7 +166,7 @@ describe("Behaviors", function () {
query.using(Timeout(50));
query.using(ResolveOnData(), RejectOnError());

query.on.send.replace(async (url, init) => <any>nodeFetch(url.toString(), <any>init));
query.on.send.replace(async (url, init) => <any>fetch(url.toString(), <any>init));

try {

Expand Down
4 changes: 2 additions & 2 deletions test/test-recording-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ The [test recording](./test-recording.ts) replaces the default `.send` behavior

1. Generate file names for body and init
2. Look-up if files exist, and if so construct and return a new Response object based on the data
3. If no files exist and operating in read mode, make the request with node-fetch and return the Response
4. If no files exist and operating in write mode, make the request with node-fetch and write the response data to the fs
3. If no files exist and operating in read mode, make the request and return the Response
4. If no files exist and operating in write mode, make the request and write the response data to the fs


3 changes: 1 addition & 2 deletions test/test-recording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { join, resolve } from "path";
import { Context, Suite } from "mocha";
import { TestProps } from "./test-props.js";
import { PnPTestHeaderName } from "./pnp-test.js";
import { default as nodeFetch } from "node-fetch";

// TODO:: a way to record tests from the browser -> console.log what we would save in a file along with the generated filename

Expand Down Expand Up @@ -135,7 +134,7 @@ function RequestRecorderCache(resolvedRecordingPath: string, mode: "playback" |
}
}

const response: Response = await <any>nodeFetch(url.toString(), <any>init);
const response: Response = await <any>fetch(url.toString(), <any>init);

if (mode === "record") {

Expand Down
Loading