@digipair/skill-http 0.50.15 → 0.52.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/index.cjs.js CHANGED
@@ -15,15 +15,25 @@ function _extends() {
15
15
 
16
16
  let HttpService = class HttpService {
17
17
  async call(url, method, data, headers, signal) {
18
+ const requestHeaders = _extends({
19
+ Accept: this.IS_JSON ? 'application/json' : '*/*'
20
+ }, data ? {
21
+ 'Content-Type': 'application/json'
22
+ } : {}, headers);
23
+ let body = undefined;
24
+ if (requestHeaders['Content-Type'] === 'application/json') {
25
+ body = JSON.stringify(data);
26
+ } else if (requestHeaders['Content-Type'] === 'application/x-www-form-urlencoded') {
27
+ const params = new URLSearchParams(data);
28
+ body = params.toString();
29
+ } else {
30
+ body = data;
31
+ }
18
32
  const response = await fetch(url, {
19
33
  signal,
20
34
  method,
21
- headers: _extends({
22
- Accept: this.IS_JSON ? 'application/json' : '*/*'
23
- }, data ? {
24
- 'Content-Type': 'application/json'
25
- } : {}, headers),
26
- body: data ? this.IS_JSON ? JSON.stringify(data) : data : undefined
35
+ headers: requestHeaders,
36
+ body
27
37
  });
28
38
  if (!response.ok) throw new Error('[SKILL-HTTP] REQUEST FAILED: ' + response.status);
29
39
  return this.IS_JSON ? response.json() : response.text();
package/index.esm.js CHANGED
@@ -11,15 +11,25 @@ function _extends() {
11
11
 
12
12
  let HttpService = class HttpService {
13
13
  async call(url, method, data, headers, signal) {
14
+ const requestHeaders = _extends({
15
+ Accept: this.IS_JSON ? 'application/json' : '*/*'
16
+ }, data ? {
17
+ 'Content-Type': 'application/json'
18
+ } : {}, headers);
19
+ let body = undefined;
20
+ if (requestHeaders['Content-Type'] === 'application/json') {
21
+ body = JSON.stringify(data);
22
+ } else if (requestHeaders['Content-Type'] === 'application/x-www-form-urlencoded') {
23
+ const params = new URLSearchParams(data);
24
+ body = params.toString();
25
+ } else {
26
+ body = data;
27
+ }
14
28
  const response = await fetch(url, {
15
29
  signal,
16
30
  method,
17
- headers: _extends({
18
- Accept: this.IS_JSON ? 'application/json' : '*/*'
19
- }, data ? {
20
- 'Content-Type': 'application/json'
21
- } : {}, headers),
22
- body: data ? this.IS_JSON ? JSON.stringify(data) : data : undefined
31
+ headers: requestHeaders,
32
+ body
23
33
  });
24
34
  if (!response.ok) throw new Error('[SKILL-HTTP] REQUEST FAILED: ' + response.status);
25
35
  return this.IS_JSON ? response.json() : response.text();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digipair/skill-http",
3
- "version": "0.50.15",
3
+ "version": "0.52.1",
4
4
  "dependencies": {
5
5
  "form-data": "4.0.1"
6
6
  },