@bzbs/react-api-client 0.2.2 → 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 +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +42 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -36
- 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
|
}
|
|
@@ -71,6 +69,35 @@ var BaseService = class {
|
|
|
71
69
|
details: error
|
|
72
70
|
};
|
|
73
71
|
}
|
|
72
|
+
normalizeResponse(response) {
|
|
73
|
+
if (response.status === 204) {
|
|
74
|
+
return { model: {}, response, type: "success" };
|
|
75
|
+
}
|
|
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 || "",
|
|
87
|
+
error: {
|
|
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);
|
|
98
|
+
}
|
|
99
|
+
return { model: data, response, type: "success" };
|
|
100
|
+
}
|
|
74
101
|
request(method, path, data, requestOptions) {
|
|
75
102
|
return __async(this, null, function* () {
|
|
76
103
|
var _a;
|
|
@@ -82,41 +109,13 @@ var BaseService = class {
|
|
|
82
109
|
data
|
|
83
110
|
};
|
|
84
111
|
const response = yield this.client.request(__spreadValues({ method, url }, config));
|
|
85
|
-
|
|
86
|
-
return { model: "", response, type: "success" };
|
|
87
|
-
}
|
|
88
|
-
if ("Success" in response.data) {
|
|
89
|
-
const data2 = response.data;
|
|
90
|
-
if (data2.Success) {
|
|
91
|
-
if ("Data" in response.data) {
|
|
92
|
-
return { model: data2.Data, response, type: "success" };
|
|
93
|
-
} else {
|
|
94
|
-
return { model: "", response, type: "success" };
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
-
const error = {
|
|
98
|
-
type: "server-error",
|
|
99
|
-
error: {
|
|
100
|
-
requestId: response.data.RequestId || "",
|
|
101
|
-
error: {
|
|
102
|
-
id: response.data.Code || 500,
|
|
103
|
-
message: response.data.Message || "An unexpected error occurred.",
|
|
104
|
-
code: response.data.Code || 500,
|
|
105
|
-
type: "buzzebees"
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
statusCode: response.data.Code || 500,
|
|
109
|
-
response
|
|
110
|
-
};
|
|
111
|
-
return this.normalizeError(error);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return { model: response.data, response, type: "success" };
|
|
112
|
+
return this.normalizeResponse(response);
|
|
115
113
|
} catch (error) {
|
|
116
114
|
return this.normalizeError(error);
|
|
117
115
|
}
|
|
118
116
|
});
|
|
119
117
|
}
|
|
118
|
+
/* if blob type we not include header in requestOptions */
|
|
120
119
|
get(path, params, requestOptions) {
|
|
121
120
|
return __async(this, null, function* () {
|
|
122
121
|
return this.request("get", path, void 0, __spreadProps(__spreadValues({}, requestOptions), { params }));
|
|
@@ -143,7 +142,9 @@ var BaseService = class {
|
|
|
143
142
|
});
|
|
144
143
|
}
|
|
145
144
|
joinUrl(baseUrl, path) {
|
|
146
|
-
|
|
145
|
+
const sanitizedBase = baseUrl.replace(/\/+$/, "");
|
|
146
|
+
const sanitizedPath = path.replace(/^\/+/, "");
|
|
147
|
+
return `${sanitizedBase}/${sanitizedPath}`;
|
|
147
148
|
}
|
|
148
149
|
getHeaders(customHeaders) {
|
|
149
150
|
return __spreadValues({
|
|
@@ -2264,7 +2265,9 @@ var BzbsService = class {
|
|
|
2264
2265
|
this.couponApi = new CouponApi(this.client, this.baseUrl);
|
|
2265
2266
|
this.dashboardApi = new DashboardApi(this.client, this.baseUrl);
|
|
2266
2267
|
this.historyApi = new HistoryApi(this.client, this.baseUrl);
|
|
2267
|
-
|
|
2268
|
+
if (this.baseLineUrl) {
|
|
2269
|
+
this.lineApi = new LineApi(this.client, this.baseLineUrl);
|
|
2270
|
+
}
|
|
2268
2271
|
this.notificationApi = new NotificationApi(this.client, this.baseUrl);
|
|
2269
2272
|
this.placeApi = new PlaceApi(this.client, this.baseUrl);
|
|
2270
2273
|
this.pointLogApi = new PointLogApi(this.client, this.baseUrl);
|