@congruent-stack/congruent-api-fetch 0.12.0 → 0.12.1

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/dist/index.cjs CHANGED
@@ -30,12 +30,19 @@ function createFetchClient(contract, options) {
30
30
  const finalRequestInit = options.enhanceRequestInit ? options.enhanceRequestInit(requestInit, input) : requestInit;
31
31
  const response = await fetch(fullUrlAddress, finalRequestInit);
32
32
  const responseCode = response.status;
33
+ const responseHeaders = Object.fromEntries(response.headers.entries());
34
+ if (responseCode === congruentApi.HttpStatusCode.NoContent_204 || responseCode === congruentApi.HttpStatusCode.NotModified_304) {
35
+ return {
36
+ code: responseCode,
37
+ headers: responseHeaders,
38
+ body: void 0
39
+ };
40
+ }
33
41
  const responseContentType = response.headers.get("content-type") || "";
34
42
  if (!responseContentType.includes("application/json")) {
35
43
  throw new Error(`Expected 'application/json' content-type in response header, but got '${responseContentType}'`);
36
44
  }
37
- const responseHeaders = Object.fromEntries(response.headers.entries());
38
- const responseBody = responseCode === congruentApi.HttpStatusCode.NoContent_204 ? void 0 : await response.json();
45
+ const responseBody = await response.json();
39
46
  return {
40
47
  code: responseCode,
41
48
  headers: responseHeaders,
package/dist/index.mjs CHANGED
@@ -28,12 +28,19 @@ function createFetchClient(contract, options) {
28
28
  const finalRequestInit = options.enhanceRequestInit ? options.enhanceRequestInit(requestInit, input) : requestInit;
29
29
  const response = await fetch(fullUrlAddress, finalRequestInit);
30
30
  const responseCode = response.status;
31
+ const responseHeaders = Object.fromEntries(response.headers.entries());
32
+ if (responseCode === HttpStatusCode.NoContent_204 || responseCode === HttpStatusCode.NotModified_304) {
33
+ return {
34
+ code: responseCode,
35
+ headers: responseHeaders,
36
+ body: void 0
37
+ };
38
+ }
31
39
  const responseContentType = response.headers.get("content-type") || "";
32
40
  if (!responseContentType.includes("application/json")) {
33
41
  throw new Error(`Expected 'application/json' content-type in response header, but got '${responseContentType}'`);
34
42
  }
35
- const responseHeaders = Object.fromEntries(response.headers.entries());
36
- const responseBody = responseCode === HttpStatusCode.NoContent_204 ? void 0 : await response.json();
43
+ const responseBody = await response.json();
37
44
  return {
38
45
  code: responseCode,
39
46
  headers: responseHeaders,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@congruent-stack/congruent-api-fetch",
3
3
  "type": "module",
4
- "version": "0.12.0",
4
+ "version": "0.12.1",
5
5
  "description": "Typescript schema-first tooling for agnostic REST APIs.",
6
6
  "keywords": [],
7
7
  "author": "congruent-stack",
@@ -20,7 +20,7 @@
20
20
  }
21
21
  },
22
22
  "peerDependencies": {
23
- "@congruent-stack/congruent-api": "0.12.0"
23
+ "@congruent-stack/congruent-api": "0.12.1"
24
24
  },
25
25
  "devDependencies": {
26
26
  "pkgroll": "2.14.5",