diff --git a/README.md b/README.md index 84b840ce0..95daa65d1 100644 --- a/README.md +++ b/README.md @@ -85,4 +85,3 @@ This library would not be possible without these rockstars. Copyright (c) 2022 0xs34n Licensed under the [MIT license](https://github.com/0xs34n/starknet.js/blob/main/LICENSE). - diff --git a/__tests__/jest.setup.ts b/__tests__/jest.setup.ts index 7183664bb..339df0c36 100644 --- a/__tests__/jest.setup.ts +++ b/__tests__/jest.setup.ts @@ -1,6 +1,6 @@ -/* eslint-disable no-console */ -import 'isomorphic-unfetch'; +import 'isomorphic-fetch'; +/* eslint-disable no-console */ import { register } from 'fetch-intercept'; jest.setTimeout(50 * 60 * 1000); diff --git a/package-lock.json b/package-lock.json index f395a0e66..ef69c057e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "elliptic": "^6.5.4", "ethereum-cryptography": "^1.0.3", "hash.js": "^1.1.7", - "isomorphic-unfetch": "^3.1.0", + "isomorphic-fetch": "^3.0.0", "json-bigint": "^1.0.0", "minimalistic-assert": "^1.0.1", "pako": "^2.0.4", @@ -7669,13 +7669,13 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, - "node_modules/isomorphic-unfetch": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/isomorphic-unfetch/-/isomorphic-unfetch-3.1.0.tgz", - "integrity": "sha512-geDJjpoZ8N0kWexiwkX8F9NkTsXhetLPVbZFQ+JTW239QNOwvB0gniuR1Wc6f0AMTn7/mFGyXvHTifrCp/GH8Q==", + "node_modules/isomorphic-fetch": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz", + "integrity": "sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==", "dependencies": { "node-fetch": "^2.6.1", - "unfetch": "^4.2.0" + "whatwg-fetch": "^3.4.1" } }, "node_modules/issue-parser": { @@ -15599,11 +15599,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/unfetch": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/unfetch/-/unfetch-4.2.0.tgz", - "integrity": "sha512-F9p7yYCn6cIW9El1zi0HI6vqpeIvBsr3dSuRO6Xuppb1u5rXpCPmMvLSyECLhybr9isec8Ohl0hPekMVrEinDA==" - }, "node_modules/unicode-canonical-property-names-ecmascript": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", @@ -15794,8 +15789,7 @@ "node_modules/whatwg-fetch": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz", - "integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==", - "dev": true + "integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==" }, "node_modules/whatwg-mimetype": { "version": "3.0.0", @@ -21821,13 +21815,13 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, - "isomorphic-unfetch": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/isomorphic-unfetch/-/isomorphic-unfetch-3.1.0.tgz", - "integrity": "sha512-geDJjpoZ8N0kWexiwkX8F9NkTsXhetLPVbZFQ+JTW239QNOwvB0gniuR1Wc6f0AMTn7/mFGyXvHTifrCp/GH8Q==", + "isomorphic-fetch": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz", + "integrity": "sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==", "requires": { "node-fetch": "^2.6.1", - "unfetch": "^4.2.0" + "whatwg-fetch": "^3.4.1" } }, "issue-parser": { @@ -27721,11 +27715,6 @@ "which-boxed-primitive": "^1.0.2" } }, - "unfetch": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/unfetch/-/unfetch-4.2.0.tgz", - "integrity": "sha512-F9p7yYCn6cIW9El1zi0HI6vqpeIvBsr3dSuRO6Xuppb1u5rXpCPmMvLSyECLhybr9isec8Ohl0hPekMVrEinDA==" - }, "unicode-canonical-property-names-ecmascript": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", @@ -27886,8 +27875,7 @@ "whatwg-fetch": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz", - "integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==", - "dev": true + "integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==" }, "whatwg-mimetype": { "version": "3.0.0", diff --git a/package.json b/package.json index 1c59735c5..0333eaea5 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "elliptic": "^6.5.4", "ethereum-cryptography": "^1.0.3", "hash.js": "^1.1.7", - "isomorphic-unfetch": "^3.1.0", + "isomorphic-fetch": "^3.0.0", "json-bigint": "^1.0.0", "minimalistic-assert": "^1.0.1", "pako": "^2.0.4", diff --git a/src/provider/default.ts b/src/provider/default.ts index a05d291bf..71487c7ae 100644 --- a/src/provider/default.ts +++ b/src/provider/default.ts @@ -1,4 +1,3 @@ -import fetch from 'isomorphic-unfetch'; import urljoin from 'url-join'; import { ONE, StarknetChainId, ZERO } from '../constants'; @@ -20,6 +19,7 @@ import { Invocation, TransactionReceiptResponse, } from '../types'; +import fetch from '../utils/fetchPonyfill'; import { getSelectorFromName } from '../utils/hash'; import { parse, parseAlwaysAsBig, stringify } from '../utils/json'; import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number'; diff --git a/src/utils/fetchPonyfill.ts b/src/utils/fetchPonyfill.ts new file mode 100644 index 000000000..dbb815814 --- /dev/null +++ b/src/utils/fetchPonyfill.ts @@ -0,0 +1,4 @@ +export default (typeof window !== 'undefined' && window.fetch) || // use buildin fetch in browser if available + (typeof global !== 'undefined' && global.fetch) || // use buildin fetch in node, react-native and service worker if available + // eslint-disable-next-line global-require + require('isomorphic-fetch'); // ponyfill fetch in node and browsers that don't have it