@skravets/eapi 0.0.4 → 0.0.6

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
@@ -62,6 +62,7 @@ class EApi {
62
62
  headers: {
63
63
  "user-agent": "EAPI SDK",
64
64
  Authorization: `Basic ${btoa(`${this.options.client.id}:${this.options.client.secret}`)}`,
65
+ ...data ? { "content-type": "application/json" } : {},
65
66
  ...this.options.requestOptions?.headers,
66
67
  ...options?.headers
67
68
  }
@@ -71,7 +72,14 @@ class EApi {
71
72
  if (!response.ok) {
72
73
  throw new Error(`${response.status} ${await response.text()}`);
73
74
  }
74
- return response.json();
75
+ const contentType = response.headers.get("content-type");
76
+ const length = response.headers.get("content-length");
77
+ if (contentType?.includes("application/json")) {
78
+ return response.json();
79
+ } else if (length) {
80
+ return response.text();
81
+ }
82
+ return void 0;
75
83
  }
76
84
  on(type, handler) {
77
85
  this.listeners.push({ event: type, handler });
package/dist/index.js CHANGED
@@ -60,6 +60,7 @@ class EApi {
60
60
  headers: {
61
61
  "user-agent": "EAPI SDK",
62
62
  Authorization: `Basic ${btoa(`${this.options.client.id}:${this.options.client.secret}`)}`,
63
+ ...data ? { "content-type": "application/json" } : {},
63
64
  ...this.options.requestOptions?.headers,
64
65
  ...options?.headers
65
66
  }
@@ -69,7 +70,14 @@ class EApi {
69
70
  if (!response.ok) {
70
71
  throw new Error(`${response.status} ${await response.text()}`);
71
72
  }
72
- return response.json();
73
+ const contentType = response.headers.get("content-type");
74
+ const length = response.headers.get("content-length");
75
+ if (contentType?.includes("application/json")) {
76
+ return response.json();
77
+ } else if (length) {
78
+ return response.text();
79
+ }
80
+ return void 0;
73
81
  }
74
82
  on(type, handler) {
75
83
  this.listeners.push({ event: type, handler });
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@skravets/eapi",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "module": "./dist/index.js",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.ts",
7
7
  "scripts": {
8
- "build": "bunx pkgroll"
8
+ "build": "bunx pkgroll",
9
+ "prepublishOnly": "bunx pkgroll"
9
10
  },
10
11
  "exports": {
11
12
  ".": {