@bzbs/react-api-client 0.2.3 → 1.0.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
@@ -41,10 +41,8 @@ var __async = (__this, __arguments, generator) => {
41
41
  // src/api/base-service.ts
42
42
  var BaseService = class {
43
43
  constructor(client, baseUrl) {
44
- if (!client)
45
- throw new Error("Axios client is required.");
46
- if (!baseUrl)
47
- throw new Error("Base URL is required.");
44
+ if (!client) throw new Error("Axios client is required.");
45
+ if (!baseUrl) throw new Error("Base URL is required.");
48
46
  this.client = client;
49
47
  this.baseUrl = baseUrl;
50
48
  }
@@ -75,43 +73,30 @@ var BaseService = class {
75
73
  if (response.status === 204) {
76
74
  return { model: {}, response, type: "success" };
77
75
  }
78
- if ("Success" in response.data || "success" in response.data) {
79
- const data = response.data;
80
- if (data.Success) {
81
- if ("Data" in response.data) {
82
- return { model: data.Data, response, type: "success" };
83
- } else if ("data" in response.data) {
84
- return { model: data.data, response, type: "success" };
85
- } else {
86
- return { model: {}, response, type: "success" };
87
- }
88
- } else if (data.success) {
89
- if ("Data" in response.data) {
90
- return { model: data.Data, response, type: "success" };
91
- } else if ("data" in response.data) {
92
- return { model: data.data, response, type: "success" };
93
- } else {
94
- return { model: {}, response, type: "success" };
95
- }
96
- } else {
97
- const error = {
98
- type: "server-error",
76
+ const data = response.data;
77
+ const isSuccess = (data == null ? void 0 : data.Success) === true || (data == null ? void 0 : data.success) === true;
78
+ if (isSuccess) {
79
+ const model = "Data" in data ? data.Data : "data" in data ? data.data : {};
80
+ return { model, response, type: "success" };
81
+ }
82
+ if ("Success" in data || "success" in data) {
83
+ const error = {
84
+ type: "server-error",
85
+ error: {
86
+ requestId: data.RequestId || "",
99
87
  error: {
100
- requestId: response.data.RequestId || "",
101
- error: {
102
- id: response.data.Code || response.status,
103
- message: response.data.Message || response.statusText,
104
- code: response.data.Code || response.status,
105
- type: "buzzebees"
106
- }
107
- },
108
- statusCode: response.data.Code || response.status,
109
- response
110
- };
111
- return this.normalizeError(error);
112
- }
88
+ id: data.Code || data.code || response.status,
89
+ message: data.Message || data.message || response.statusText,
90
+ code: data.Code || data.code || response.status,
91
+ type: "buzzebees"
92
+ }
93
+ },
94
+ statusCode: data.Code || response.status,
95
+ response
96
+ };
97
+ return this.normalizeError(error);
113
98
  }
114
- return { model: response.data, response, type: "success" };
99
+ return { model: data, response, type: "success" };
115
100
  }
116
101
  request(method, path, data, requestOptions) {
117
102
  return __async(this, null, function* () {
@@ -157,7 +142,9 @@ var BaseService = class {
157
142
  });
158
143
  }
159
144
  joinUrl(baseUrl, path) {
160
- return new URL(path, baseUrl).toString();
145
+ const sanitizedBase = baseUrl.replace(/\/+$/, "");
146
+ const sanitizedPath = path.replace(/^\/+/, "");
147
+ return `${sanitizedBase}/${sanitizedPath}`;
161
148
  }
162
149
  getHeaders(customHeaders) {
163
150
  return __spreadValues({