From 6185f9e2230a5d095111b3a4db10b56431b1c2a6 Mon Sep 17 00:00:00 2001 From: Viet Huynh Date: Mon, 11 Sep 2023 02:54:55 +0700 Subject: [PATCH] added back node-fetch with dynamic import --- lib/helpers.js | 4 +++ package-lock.json | 89 +++++++++++++++++++++++++++++++++++++++++++++-- package.json | 5 +-- 3 files changed, 94 insertions(+), 4 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index 0e4da8a..40c7b14 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -1,5 +1,9 @@ import { ACCOUNT_EMAIL, ACCOUNT_ID, API_HOST, API_TOKEN } from "./constants.js"; +if (!globalThis.fetch) { + globalThis.fetch = (await import("node-fetch")).default; +} + /** * Fires request to the specified URL. * @param {string} url The URL to which the request will be fired. diff --git a/package-lock.json b/package-lock.json index 5a1681b..11f7448 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,10 +5,19 @@ "packages": { "": { "dependencies": { - "dotenv": "^16.0.3" + "dotenv": "^16.0.3", + "node-fetch": "^3.3.2" }, "engines": { - "node": ">=18" + "node": ">=16" + } + }, + "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==", + "engines": { + "node": ">= 12" } }, "node_modules/dotenv": { @@ -18,6 +27,82 @@ "engines": { "node": ">=12" } + }, + "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==", + "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/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, + "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==", + "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==", + "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/web-streams-polyfill": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", + "engines": { + "node": ">= 8" + } } } } diff --git a/package.json b/package.json index 95f30e5..4b98eef 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "type": "module", "dependencies": { - "dotenv": "^16.0.3" + "dotenv": "^16.0.3", + "node-fetch": "^3.3.2" }, "engines": { - "node" : ">=18" + "node": ">=16" } }