diff --git a/docs/core/behaviors.md b/docs/core/behaviors.md index 2b2544241..a552f6d96 100644 --- a/docs/core/behaviors.md +++ b/docs/core/behaviors.md @@ -57,7 +57,7 @@ export function CompanyDefault(): TimelinePipe { 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(), diff --git a/docs/nodejs/behaviors.md b/docs/nodejs/behaviors.md index c14ac2983..85594a380 100644 --- a/docs/nodejs/behaviors.md +++ b/docs/nodejs/behaviors.md @@ -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). diff --git a/package-lock.json b/package-lock.json index 590cb3574..fea2328cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@pnp/monorepo", - "version": "4.6.0", + "version": "4.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@pnp/monorepo", - "version": "4.6.0", + "version": "4.7.0", "license": "MIT", "devDependencies": { "@azure/identity": "4.4.1", @@ -32,7 +32,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", @@ -43,7 +42,7 @@ "yargs": "17.7.2" }, "engines": { - "node": ">=14.15.1" + "node": ">=18.17.1" } }, "node_modules/@azure/abort-controller": { @@ -2299,15 +2298,6 @@ "node": ">= 8" } }, - "node_modules/data-uri-to-buffer": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", - "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", - "dev": true, - "engines": { - "node": ">= 12" - } - }, "node_modules/debug": { "version": "4.3.7", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", @@ -3080,29 +3070,6 @@ "node": ">=0.8.0" } }, - "node_modules/fetch-blob": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", - "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "paypal", - "url": "https://paypal.me/jimmywarting" - } - ], - "dependencies": { - "node-domexception": "^1.0.0", - "web-streams-polyfill": "^3.0.3" - }, - "engines": { - "node": "^12.20 || >= 14.13" - } - }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -3286,18 +3253,6 @@ "node": ">=0.10.0" } }, - "node_modules/formdata-polyfill": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", - "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", - "dev": true, - "dependencies": { - "fetch-blob": "^3.1.2" - }, - "engines": { - "node": ">=12.20.0" - } - }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -4902,43 +4857,6 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, - "node_modules/node-domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "github", - "url": "https://paypal.me/jimmywarting" - } - ], - "engines": { - "node": ">=10.5.0" - } - }, - "node_modules/node-fetch": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", - "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", - "dev": true, - "dependencies": { - "data-uri-to-buffer": "^4.0.0", - "fetch-blob": "^3.1.4", - "formdata-polyfill": "^4.0.10" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/node-fetch" - } - }, "node_modules/node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -6729,15 +6647,6 @@ "minimalistic-assert": "^1.0.0" } }, - "node_modules/web-streams-polyfill": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", - "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", - "dev": true, - "engines": { - "node": ">= 8" - } - }, "node_modules/webpack": { "version": "5.95.0", "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.95.0.tgz", diff --git a/package.json b/package.json index 2806c7e1d..ec0fb7a68 100644 --- a/package.json +++ b/package.json @@ -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", @@ -72,7 +71,7 @@ "sharepoint framework" ], "engines": { - "node": ">=14.15.1" + "node": ">=18.17.1" }, "engineStrict": true, "maintainers": [ diff --git a/packages/nodejs/behaviors/fetch.ts b/packages/nodejs/behaviors/fetch.ts index 876c5f5b3..993ea3f4c 100644 --- a/packages/nodejs/behaviors/fetch.ts +++ b/packages/nodejs/behaviors/fetch.ts @@ -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 { @@ -24,7 +23,7 @@ export function NodeFetch(props?: INodeFetchProps): TimelinePipe { this.log(`Fetch: ${init.method} ${url.toString()}`, LogLevel.Verbose); - return nodeFetch(url.toString(), init); + return fetch(url.toString(), init); }); return instance; @@ -93,7 +92,7 @@ export function NodeFetchWithRetry(props?: INodeFetchWithRetryProps): TimelinePi this.log(`Fetch: ${init.method} ${url.toString()}`, LogLevel.Verbose); - response = await nodeFetch(url.toString(), init); + response = await fetch(url.toString(), init); // if we got a good response, return it, otherwise see if we can retry return response.ok ? response : retry(); diff --git a/packages/nodejs/index.ts b/packages/nodejs/index.ts index 7e2fe495c..1d8d3894f 100644 --- a/packages/nodejs/index.ts +++ b/packages/nodejs/index.ts @@ -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"; diff --git a/packages/nodejs/package.json b/packages/nodejs/package.json index 1b182660e..96ab52414 100644 --- a/packages/nodejs/package.json +++ b/packages/nodejs/package.json @@ -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" } } \ No newline at end of file diff --git a/test/queryable/behaviors.ts b/test/queryable/behaviors.ts index d2e001b90..b8625506c 100644 --- a/test/queryable/behaviors.ts +++ b/test/queryable/behaviors.ts @@ -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"; @@ -166,7 +166,7 @@ describe("Behaviors", function () { query.using(Timeout(50)); query.using(ResolveOnData(), RejectOnError()); - query.on.send.replace(async (url, init) => nodeFetch(url.toString(), init)); + query.on.send.replace(async (url, init) => fetch(url.toString(), init)); try { diff --git a/test/test-recording-setup.md b/test/test-recording-setup.md index 3b1b01630..e281f1731 100644 --- a/test/test-recording-setup.md +++ b/test/test-recording-setup.md @@ -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 diff --git a/test/test-recording.ts b/test/test-recording.ts index 7a11e25e5..6ea8127f5 100644 --- a/test/test-recording.ts +++ b/test/test-recording.ts @@ -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 @@ -135,7 +134,7 @@ function RequestRecorderCache(resolvedRecordingPath: string, mode: "playback" | } } - const response: Response = await nodeFetch(url.toString(), init); + const response: Response = await fetch(url.toString(), init); if (mode === "record") {