Repository: medusajs/medusa
File: packages/core/js-sdk/src/client.ts (TypeScript)

Code before:
      const customHeaders = {
        ...this.config.globalHeaders,
        ...(await this.getJwtHeader_()),
        ...init?.headers,
      }
      // We use `headers.set` in order to ensure headers are overwritten in a case-insensitive manner.
      Object.entries(customHeaders).forEach(([key, value]) => {
        if (value === null) {
          headers.delete(key)
        } else {
          headers.set(key, value)
        }
      })

      let normalizedInput: RequestInfo | URL = input
      if (input instanceof URL || typeof input === "string") {
        const baseUrl = new URL(this.config.baseUrl)
        const fullPath = `${baseUrl.pathname.replace(/\/$/, "")}/${input
          .toString()
          .replace(/^\//, "")}`
        normalizedInput = new URL(fullPath, baseUrl.origin)
        if (init?.query) {
          const params = Object.fromEntries(
            normalizedInput.searchParams.entries()
          )
          const stringifiedQuery = stringify(
            { ...params, ...init.query },
            { skipNulls: true }
          )
          normalizedInput.search = stringifiedQuery
        }
      }

      this.logger.debug(
        "Performing request to:\n",
        `URL: ${normalizedInput.toString()}\n`,
        `Headers: ${JSON.stringify(sanitizeHeaders(headers), null, 2)}\n`
      )

      // Any non-request errors (eg. invalid JSON in the response) will be thrown as-is.
      return await fetch(
        normalizedInput,
        normalizeRequest(init, headers, this.config)
      ).then((resp) => {
        this.logger.debug(`Received response with status ${resp.status}\n`)
        return normalizeResponse(resp, headers)
      })
    }
  }

  protected getApiKeyHeader_ = (): { Authorization: string } | {} => {

Review comment (suggestion):
thought: Shouldn't we only set the locale, if it is not explicitly passed? Otherwise, we could be overriding it.

Something like:
```ts
setRequestLocale(url, headers) {
    const carriesLocale =
      url.searchParams.has("locale") ||
      headers.get("content-language")

    if (!carriesLocale && this.locale) {
      url.searchParams.set("locale", this.locale)
    }

    return url
  }
```

Code after:
      }
      case "memory": {
        this.token = ""
        break
      }
    }
  }

  protected initClient(): ClientFetch {
    const defaultHeaders = new Headers({
      "content-type": "application/json",
      accept: "application/json",
      ...this.getApiKeyHeader_(),
      ...this.getPublishableKeyHeader_(),
    })

    this.logger.debug(
      "Initiating Medusa client with default headers:\n",
      `${JSON.stringify(sanitizeHeaders(defaultHeaders), null, 2)}\n`
    )

    return async (input: FetchInput, init?: FetchArgs) => {
      // We always want to fetch the up-to-date JWT token before firing off a request.
      const headers = new Headers(defaultHeaders)
      const customHeaders = {
        "content-language": this.locale,
        ...this.config.globalHeaders,
        ...(await this.getJwtHeader_()),
        ...init?.headers,
      }

      // We use `headers.set` in order to ensure headers are overwritten in a case-insensitive manner.
      Object.entries(customHeaders).forEach(([key, value]) => {
        if (value === null) {
          headers.delete(key)
        } else {
          headers.set(key, value)
        }
      })

      let normalizedInput: RequestInfo | URL = input
      if (input instanceof URL || typeof input === "string") {
        const baseUrl = new URL(this.config.baseUrl)
        const fullPath = `${baseUrl.pathname.replace(/\/$/, "")}/${input
          .toString()
          .replace(/^\//, "")}`
        normalizedInput = new URL(fullPath, baseUrl.origin)
        if (init?.query) {
          const params = Object.fromEntries(
            normalizedInput.searchParams.entries()
          )