@flipdish/authorization 0.0.0-preview.185.g0a86e1e → 0.0.0-preview.186.ge17a2e8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -204,7 +204,7 @@ describe("Authorization Tests", () => {
204
204
  Every request carries an `X-Flipdish-Client` header identifying the SDK and the app using it. Outside browsers the same value is also sent as `User-Agent`, for example:
205
205
 
206
206
  ```
207
- Flipdish-authorization-ts/0.0.0-preview.185.g0a86e1e menu-service/2.3.1 env/production node/22.18.0
207
+ Flipdish-authorization-ts/0.0.0-preview.186.ge17a2e8 menu-service/2.3.1 env/production node/22.18.0
208
208
  ```
209
209
 
210
210
  The app name and version are read from the first of these that is set:
package/dist/index.js CHANGED
@@ -809,6 +809,32 @@ var createClient = (config = {}) => {
809
809
  };
810
810
  };
811
811
 
812
+ // src/fetch.ts
813
+ var NULL_BODY_STATUSES = /* @__PURE__ */ new Set([101, 103, 204, 205, 304]);
814
+ function withJsonContentTypeFallback(fetchImpl) {
815
+ const wrapped = async (input, init) => {
816
+ const response = fetchImpl ? await fetchImpl(input, init) : await globalThis.fetch(input, init);
817
+ const contentType = response.headers.get("content-type");
818
+ if (!contentType?.toLowerCase().startsWith("text/plain") || NULL_BODY_STATUSES.has(response.status)) {
819
+ return response;
820
+ }
821
+ const text = await response.clone().text();
822
+ try {
823
+ JSON.parse(text);
824
+ } catch {
825
+ return response;
826
+ }
827
+ const headers = new Headers(response.headers);
828
+ headers.set("content-type", "application/json");
829
+ return new Response(text, {
830
+ status: response.status,
831
+ statusText: response.statusText,
832
+ headers
833
+ });
834
+ };
835
+ return wrapped;
836
+ }
837
+
812
838
  // src/identity.ts
813
839
  var CLIENT_HEADER = "X-Flipdish-Client";
814
840
  function detectRuntime() {
@@ -890,12 +916,13 @@ function defaultIdentityHeaders(sdk) {
890
916
  }
891
917
 
892
918
  // src/sdk-info.ts
893
- var SDK_INFO = { "name": "authorization", "version": "0.0.0-preview.185.g0a86e1e" };
919
+ var SDK_INFO = { "name": "authorization", "version": "0.0.0-preview.186.ge17a2e8" };
894
920
  var DEFAULT_BASE_URL = "https://api.flipdish.co/auth";
895
921
 
896
922
  // src/flipdish-runtime.ts
897
923
  var createClientConfig = (config) => ({
898
924
  ...config,
925
+ fetch: withJsonContentTypeFallback(config?.fetch),
899
926
  headers: mergeHeaders(defaultIdentityHeaders(SDK_INFO), config?.headers)
900
927
  });
901
928
 
@@ -1887,7 +1914,7 @@ function createFlipdishClient(options = {}) {
1887
1914
  createConfig({
1888
1915
  ...config,
1889
1916
  baseUrl,
1890
- ...fetch ? { fetch } : {},
1917
+ fetch: withJsonContentTypeFallback(fetch ?? config?.fetch),
1891
1918
  auth: typeof accessToken === "function" ? () => accessToken() : accessToken,
1892
1919
  headers: mergeHeaders(
1893
1920
  identityHeaders(SDK_INFO, identity),