diff --git a/README.md b/README.md index b8040c7..a65ce74 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ import { QueryConfiguration } from "https://deno.land/x/entsoe_api_client/mod.ts npm install entsoe-api-client --save ``` +### Note +Using an older version of Node.js? Use 0.x versions of this library for fetch compatibility. ## Documentation diff --git a/scripts/build_npm.ts b/scripts/build_npm.ts index 9cdf1b9..e78a325 100644 --- a/scripts/build_npm.ts +++ b/scripts/build_npm.ts @@ -13,7 +13,6 @@ await build({ outDir: "./npm", shims: { deno: "dev", - undici: true // Undici is for fetch support in old node versions }, mappings: { "https://deno.land/x/zipjs@v2.6.63/index.js": { diff --git a/src/query.ts b/src/query.ts index 46fd7f4..2182a4a 100644 --- a/src/query.ts +++ b/src/query.ts @@ -256,6 +256,7 @@ const Query = async (securityToken: string, params: QueryParameters): Promise<(P const query = ComposeQuery(securityToken, params); // Construct url and get result + // @ts-expect-error fetch is not recognised as a valid global. const result = await fetch(`${ENTSOE_ENDPOINT}?${query}`); // Check for 401 @@ -282,6 +283,9 @@ const Query = async (securityToken: string, params: QueryParameters): Promise<(P for (const xmlFileEntry of await zipReader.getEntries()) { // Unzip file const stringDataWriter = new TextWriter(); + + if (typeof xmlFileEntry.getData !== "function") break; + await xmlFileEntry.getData(stringDataWriter); const xmlFileData = await stringDataWriter.getData();