diff --git a/integration/messaging/package.json b/integration/messaging/package.json index 2d19ff133c0..36720151f53 100644 --- a/integration/messaging/package.json +++ b/integration/messaging/package.json @@ -15,7 +15,7 @@ "express": "4.18.2", "geckodriver": "2.0.4", "mocha": "9.2.2", - "node-fetch": "2.6.7", + "undici": "5.26.5", "selenium-assistant": "6.1.1" } } diff --git a/integration/messaging/test/utils/sendMessage.js b/integration/messaging/test/utils/sendMessage.js index 9d3b93986f1..1d2e95054eb 100644 --- a/integration/messaging/test/utils/sendMessage.js +++ b/integration/messaging/test/utils/sendMessage.js @@ -15,7 +15,7 @@ * limitations under the License. */ -const fetch = require('node-fetch'); +const undici = require('undici'); const FCM_SEND_ENDPOINT = 'https://fcm.googleapis.com/fcm/send'; // Rotatable fcm server key. It's generally a bad idea to expose server keys. The reason is to // simplify testing process (no need to implement server side decryption of git secret). The @@ -28,7 +28,7 @@ module.exports = async payload => { 'Requesting to send an FCM message with payload: ' + JSON.stringify(payload) ); - const response = await fetch(FCM_SEND_ENDPOINT, { + const response = await undici.fetch(FCM_SEND_ENDPOINT, { method: 'POST', body: JSON.stringify(payload), headers: { diff --git a/packages/rules-unit-testing/package.json b/packages/rules-unit-testing/package.json index a3d84cd4f36..c5bf7a77811 100644 --- a/packages/rules-unit-testing/package.json +++ b/packages/rules-unit-testing/package.json @@ -54,6 +54,7 @@ "url": "https://github.com/firebase/firebase-js-sdk/issues" }, "dependencies": { + "undici": "5.26.5", "node-fetch": "2.6.7", "@types/node-fetch": "2.6.4" } diff --git a/packages/rules-unit-testing/src/impl/rules.ts b/packages/rules-unit-testing/src/impl/rules.ts index 7d4d900367f..ef96f168012 100644 --- a/packages/rules-unit-testing/src/impl/rules.ts +++ b/packages/rules-unit-testing/src/impl/rules.ts @@ -17,7 +17,7 @@ import { HostAndPort } from '../public_types'; import { makeUrl } from './url'; -import fetch from 'node-fetch'; +import { fetch as undiciFetch } from 'undici'; /** * @private @@ -29,7 +29,7 @@ export async function loadDatabaseRules( ): Promise { const url = makeUrl(hostAndPort, '/.settings/rules.json'); url.searchParams.append('ns', databaseName); - const resp = await fetch(url, { + const resp = await undiciFetch(url, { method: 'PUT', headers: { Authorization: 'Bearer owner' }, body: rules @@ -48,7 +48,7 @@ export async function loadFirestoreRules( projectId: string, rules: string ): Promise { - const resp = await fetch( + const resp = await undiciFetch( makeUrl(hostAndPort, `/emulator/v1/projects/${projectId}:securityRules`), { method: 'PUT', @@ -72,7 +72,7 @@ export async function loadStorageRules( hostAndPort: HostAndPort, rules: string ): Promise { - const resp = await fetch(makeUrl(hostAndPort, '/internal/setRules'), { + const resp = await undiciFetch(makeUrl(hostAndPort, '/internal/setRules'), { method: 'PUT', headers: { 'Content-Type': 'application/json' diff --git a/packages/rules-unit-testing/src/impl/test_environment.ts b/packages/rules-unit-testing/src/impl/test_environment.ts index 5b32e8776f4..ff4c5f29eed 100644 --- a/packages/rules-unit-testing/src/impl/test_environment.ts +++ b/packages/rules-unit-testing/src/impl/test_environment.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import fetch from 'node-fetch'; +import { fetch as undiciFetch } from 'undici'; import firebase from 'firebase/compat/app'; import 'firebase/compat/firestore'; import 'firebase/compat/database'; @@ -106,7 +106,7 @@ export class RulesTestEnvironmentImpl implements RulesTestEnvironment { this.checkNotDestroyed(); assertEmulatorRunning(this.emulators, 'firestore'); - const resp = await fetch( + const resp = await undiciFetch( makeUrl( this.emulators.firestore, `/emulator/v1/projects/${this.projectId}/databases/(default)/documents` diff --git a/packages/rules-unit-testing/src/util.ts b/packages/rules-unit-testing/src/util.ts index 3fff44a066b..65e5a9ed635 100644 --- a/packages/rules-unit-testing/src/util.ts +++ b/packages/rules-unit-testing/src/util.ts @@ -21,7 +21,7 @@ import { } from './impl/discovery'; import { fixHostname, makeUrl } from './impl/url'; import { HostAndPort } from './public_types'; -import fetch from 'node-fetch'; +import { fetch as undiciFetch } from 'undici'; /** * Run a setup function with background Cloud Functions triggers disabled. This can be used to @@ -79,7 +79,7 @@ export async function withFunctionTriggersDisabled( hub.host = fixHostname(hub.host); makeUrl(hub, '/functions/disableBackgroundTriggers'); // Disable background triggers - const disableRes = await fetch( + const disableRes = await undiciFetch( makeUrl(hub, '/functions/disableBackgroundTriggers'), { method: 'PUT' @@ -98,7 +98,7 @@ export async function withFunctionTriggersDisabled( result = await maybeFn(); } finally { // Re-enable background triggers - const enableRes = await fetch( + const enableRes = await undiciFetch( makeUrl(hub, '/functions/enableBackgroundTriggers'), { method: 'PUT' diff --git a/packages/rules-unit-testing/test/util.test.ts b/packages/rules-unit-testing/test/util.test.ts index 9dc778fb93e..b81c6fa5142 100644 --- a/packages/rules-unit-testing/test/util.test.ts +++ b/packages/rules-unit-testing/test/util.test.ts @@ -165,7 +165,7 @@ describe('assertFails()', () => { describe('withFunctionTriggersDisabled()', () => { it('disabling function triggers does not throw, returns value', async function () { - const fetchSpy = sinon.spy(require('node-fetch'), 'default'); + const fetchSpy = sinon.spy(require('undici'), 'fetch'); const res = await withFunctionTriggersDisabled(() => { return Promise.resolve(1234); @@ -176,7 +176,7 @@ describe('withFunctionTriggersDisabled()', () => { }); it('disabling function triggers always re-enables, event when the function throws', async function () { - const fetchSpy = sinon.spy(require('node-fetch'), 'default'); + const fetchSpy = sinon.spy(require('undici'), 'fetch'); const res = withFunctionTriggersDisabled(() => { throw new Error('I throw!'); diff --git a/packages/storage/src/implementation/type.ts b/packages/storage/src/implementation/type.ts index 33fb7bb227d..7d5bc0e19e5 100644 --- a/packages/storage/src/implementation/type.ts +++ b/packages/storage/src/implementation/type.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import { isNode } from '@firebase/util'; import { invalidArgument } from './error'; export function isJustDef(p: T | null | undefined): p is T | null { @@ -40,9 +39,7 @@ export function isNativeBlob(p: unknown): p is Blob { } export function isNativeBlobDefined(): boolean { - // Note: The `isNode()` check can be removed when `node-fetch` adds native Blob support - // PR: https://github.com/node-fetch/node-fetch/pull/1664 - return typeof Blob !== 'undefined' && !isNode(); + return typeof Blob !== 'undefined'; } export function validateNumber(