import { ErrorResponse } from "./types";
import { GLOBAL_OPTIONS, searchParams } from "./utils";
import { version } from "./version";

export const fetchGet = <T>(
  url: string,
  data: { [x: string]: string } = {},
  signal?: AbortSignal
): Promise<T> => {
  const options: RequestInit = {
    method: "GET",
    headers: {
      'X-W3W-Wrapper': `what3words-JavaScript/${version} (${navigator.userAgent})`,
    }
  };

  if (signal !== undefined) {
    options.signal = signal;
  }

  if (typeof GLOBAL_OPTIONS.key === "string" && GLOBAL_OPTIONS.key.length > 0) {
    data["key"] = GLOBAL_OPTIONS.key;
  }

  let hasError = false;
  return fetch(
    `${GLOBAL_OPTIONS.baseUrl}/${url}?${searchParams(data)}`,
    options
  )
    .then(response => {
      hasError = !response.ok;
      return response.json();
    })
    .then(data => {
      if (hasError) {
        throw (data as ErrorResponse).error;
      }
      return data;
    });
};

import { ErrorResponse } from "./types";
import { GLOBAL_OPTIONS, searchParams } from "./utils";

export const fetchGet = <T>(
  url: string,
  data: { [x: string]: string } = {},
  signal?: AbortSignal
): Promise<T> => {
  const options: RequestInit = {
    method: "GET"
  };

  if (signal !== undefined) {
    options.signal = signal;
  }

  if (typeof GLOBAL_OPTIONS.key === "string" && GLOBAL_OPTIONS.key.length > 0) {
    data["key"] = GLOBAL_OPTIONS.key;
  }

  let hasError = false;
  return fetch(
    `${GLOBAL_OPTIONS.baseUrl}/${url}?${searchParams(data)}`,
    options
  )
    .then(response => {
      hasError = !response.ok;
      return response.json();
    })
    .then(data => {
      if (hasError) {
        throw (data as ErrorResponse).error;
      }
      return data;
    });
};

--- 
+++ 
@@ -1,5 +1,6 @@
 import { ErrorResponse } from "./types";
 import { GLOBAL_OPTIONS, searchParams } from "./utils";
+import { version } from "./version";
 
 export const fetchGet = <T>(
   url: string,
@@ -7,7 +8,10 @@
   signal?: AbortSignal
 ): Promise<T> => {
   const options: RequestInit = {
-    method: "GET"
+    method: "GET",
+    headers: {
+      'X-W3W-Wrapper': `what3words-JavaScript/${version} (${navigator.userAgent})`,
+    }
   };
 
   if (signal !== undefined) {
Add `X-W3W-Wrapper` head to API requests
