shred-api-client 2.3.5-rc.7 → 2.3.5

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.js CHANGED
@@ -48,7 +48,7 @@ __export(index_exports, {
48
48
  module.exports = __toCommonJS(index_exports);
49
49
 
50
50
  // src/util/HTTPClient.ts
51
- var import_axios = __toESM(require("axios"));
51
+ var import_cross_fetch = __toESM(require("cross-fetch"));
52
52
  var HOSTS = {
53
53
  prod: "https://api.shreditapp.com",
54
54
  staging: "https://api.staging.shreditapp.com",
@@ -61,7 +61,6 @@ var OLD_HOSTS = {
61
61
  };
62
62
  var HTTPClient = class {
63
63
  async makeRequest(env, uri, method, data, context, useLegacyApi) {
64
- var _a;
65
64
  const hostDict = useLegacyApi ? OLD_HOSTS : HOSTS;
66
65
  const host = hostDict[env] || hostDict.staging;
67
66
  const url = host + uri;
@@ -74,40 +73,37 @@ var HTTPClient = class {
74
73
  if (context == null ? void 0 : context.requestId) {
75
74
  headers["X-Request-ID"] = context.requestId;
76
75
  }
76
+ const fetchOptions = {
77
+ method,
78
+ headers
79
+ };
80
+ if (method !== "GET" && data) {
81
+ fetchOptions.body = useLegacyApi ? new URLSearchParams(data).toString() : JSON.stringify(data);
82
+ }
77
83
  try {
78
- const response = await import_axios.default.request({
79
- url,
80
- method,
81
- headers,
82
- data: method !== "GET" && data ? useLegacyApi ? new URLSearchParams(data).toString() : data : void 0,
83
- transformResponse: [(raw) => raw]
84
- // evita parse automático para podermos tratar manual
85
- });
84
+ const response = await (0, import_cross_fetch.default)(url, fetchOptions);
85
+ if (!response.ok) {
86
+ const errorText = await response.text();
87
+ throw {
88
+ status: response.status,
89
+ statusText: response.statusText,
90
+ body: errorText
91
+ };
92
+ }
86
93
  try {
87
- return JSON.parse(response.data);
94
+ return await response.json();
88
95
  } catch {
89
- return response.data;
96
+ return await response.text();
90
97
  }
91
- } catch (err) {
92
- const error = err;
98
+ } catch (error) {
93
99
  let parsedBody = {};
94
- if (error.response) {
95
- try {
96
- parsedBody = typeof error.response.data === "string" ? JSON.parse(error.response.data) : error.response.data;
97
- } catch {
98
- parsedBody = {
99
- message: ((_a = error.response.data) == null ? void 0 : _a.message) || error.response.statusText || "Unknown error"
100
- };
101
- }
102
- throw {
103
- message: parsedBody.message || "Unexpected error occurred",
104
- status: error.response.status,
105
- body: error.response.data,
106
- original: error
107
- };
100
+ try {
101
+ parsedBody = error.body ? JSON.parse(error.body) : {};
102
+ } catch {
103
+ parsedBody = { message: error.body || "Unknown error" };
108
104
  }
109
105
  throw {
110
- message: error.message || "Network error",
106
+ message: parsedBody.message || "Unexpected error occurred",
111
107
  original: error
112
108
  };
113
109
  }