@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/README.md +82 -82
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +30 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -40
- package/dist/index.mjs.map +1 -1
- package/package.json +63 -63
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
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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:
|
|
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
|
-
|
|
145
|
+
const sanitizedBase = baseUrl.replace(/\/+$/, "");
|
|
146
|
+
const sanitizedPath = path.replace(/^\/+/, "");
|
|
147
|
+
return `${sanitizedBase}/${sanitizedPath}`;
|
|
161
148
|
}
|
|
162
149
|
getHeaders(customHeaders) {
|
|
163
150
|
return __spreadValues({
|