shred-api-client 2.3.3 → 2.3.5-rc.0

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.mjs CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/util/HTTPClient.ts
8
- import fetch from "cross-fetch";
8
+ import axios from "axios";
9
9
  var HOSTS = {
10
10
  prod: "https://api.shreditapp.com",
11
11
  staging: "https://api.staging.shreditapp.com",
@@ -30,37 +30,40 @@ var HTTPClient = class {
30
30
  if (context?.requestId) {
31
31
  headers["X-Request-ID"] = context.requestId;
32
32
  }
33
- const fetchOptions = {
34
- method,
35
- headers
36
- };
37
- if (method !== "GET" && data) {
38
- fetchOptions.body = useLegacyApi ? new URLSearchParams(data).toString() : JSON.stringify(data);
39
- }
40
33
  try {
41
- const response = await fetch(url, fetchOptions);
42
- if (!response.ok) {
43
- const errorText = await response.text();
44
- throw {
45
- status: response.status,
46
- statusText: response.statusText,
47
- body: errorText
48
- };
49
- }
34
+ const response = await axios.request({
35
+ url,
36
+ method,
37
+ headers,
38
+ data: method !== "GET" && data ? useLegacyApi ? new URLSearchParams(data).toString() : data : void 0,
39
+ transformResponse: [(raw) => raw]
40
+ // evita parse automático para podermos tratar manual
41
+ });
50
42
  try {
51
- return await response.json();
43
+ return JSON.parse(response.data);
52
44
  } catch {
53
- return await response.text();
45
+ return response.data;
54
46
  }
55
- } catch (error) {
47
+ } catch (err) {
48
+ const error = err;
56
49
  let parsedBody = {};
57
- try {
58
- parsedBody = error.body ? JSON.parse(error.body) : {};
59
- } catch {
60
- parsedBody = { message: error.body || "Unknown error" };
50
+ if (error.response) {
51
+ try {
52
+ parsedBody = typeof error.response.data === "string" ? JSON.parse(error.response.data) : error.response.data;
53
+ } catch {
54
+ parsedBody = {
55
+ message: error.response.data?.message || error.response.statusText || "Unknown error"
56
+ };
57
+ }
58
+ throw {
59
+ message: parsedBody.message || "Unexpected error occurred",
60
+ status: error.response.status,
61
+ body: error.response.data,
62
+ original: error
63
+ };
61
64
  }
62
65
  throw {
63
- message: parsedBody.message || "Unexpected error occurred",
66
+ message: error.message || "Network error",
64
67
  original: error
65
68
  };
66
69
  }
@@ -739,20 +742,13 @@ var UserAPI = class {
739
742
  );
740
743
  return data.token;
741
744
  }
742
- async createUser(email, name, password, passwordConfirmation, profession, invitationCode) {
745
+ async createUser(create) {
743
746
  const endpointData = user_exports.Endpoints.CreateUser;
744
747
  const data = await this.clientHTTP.makeRequest(
745
748
  this.env,
746
749
  endpointData.uri,
747
750
  endpointData.method,
748
- {
749
- email,
750
- name,
751
- password,
752
- passwordConfirmation,
753
- profession,
754
- invitationCode
755
- },
751
+ create,
756
752
  null
757
753
  );
758
754
  return data;