@bzbs/react-api-client 0.0.20 → 0.0.22
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.d.mts +25 -11
- package/dist/index.d.ts +25 -11
- package/dist/index.js +47 -100
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -100
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
17
20
|
var __async = (__this, __arguments, generator) => {
|
|
18
21
|
return new Promise((resolve, reject) => {
|
|
19
22
|
var fulfilled = (value) => {
|
|
@@ -38,133 +41,77 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
41
|
// src/api/base-service.ts
|
|
39
42
|
var BaseService = class {
|
|
40
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.");
|
|
41
48
|
this.client = client;
|
|
42
49
|
this.baseUrl = baseUrl;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
}
|
|
51
|
+
normalizeError(error) {
|
|
52
|
+
if (error.response && error.response.data) {
|
|
53
|
+
return {
|
|
54
|
+
type: "server-error",
|
|
55
|
+
error: error.response.data,
|
|
56
|
+
statusCode: error.response.status,
|
|
57
|
+
response: error.response
|
|
58
|
+
};
|
|
48
59
|
}
|
|
60
|
+
return {
|
|
61
|
+
type: "client-error",
|
|
62
|
+
message: error.message || "An unexpected error occurred.",
|
|
63
|
+
details: error
|
|
64
|
+
};
|
|
49
65
|
}
|
|
50
|
-
|
|
66
|
+
request(method, path, data, requestOptions) {
|
|
51
67
|
return __async(this, null, function* () {
|
|
52
|
-
var _a
|
|
68
|
+
var _a;
|
|
53
69
|
try {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
model: response == null ? void 0 : response.data,
|
|
61
|
-
response,
|
|
62
|
-
error: void 0
|
|
70
|
+
const url = this.joinUrl((_a = requestOptions == null ? void 0 : requestOptions.baseUrl) != null ? _a : this.baseUrl, path);
|
|
71
|
+
const config = {
|
|
72
|
+
params: requestOptions == null ? void 0 : requestOptions.params,
|
|
73
|
+
headers: this.getHeaders(requestOptions == null ? void 0 : requestOptions.headers),
|
|
74
|
+
data
|
|
63
75
|
};
|
|
76
|
+
const response = yield this.client.request(__spreadValues({ method, url }, config));
|
|
77
|
+
return { model: response.data, response, type: "success" };
|
|
64
78
|
} catch (error) {
|
|
65
|
-
return
|
|
66
|
-
model: void 0,
|
|
67
|
-
response: void 0,
|
|
68
|
-
error: error.response ? error.response.data : (_b = error.response) != null ? _b : error
|
|
69
|
-
};
|
|
79
|
+
return this.normalizeError(error);
|
|
70
80
|
}
|
|
71
81
|
});
|
|
72
82
|
}
|
|
83
|
+
get(path, params, requestOptions) {
|
|
84
|
+
return __async(this, null, function* () {
|
|
85
|
+
return this.request("get", path, void 0, __spreadProps(__spreadValues({}, requestOptions), { params }));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
73
88
|
post(path, data, requestOptions) {
|
|
74
89
|
return __async(this, null, function* () {
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const response = yield this.client.post(
|
|
78
|
-
this.joinUrl((_a = requestOptions == null ? void 0 : requestOptions.baseUrl) != null ? _a : this.baseUrl, path),
|
|
79
|
-
data,
|
|
80
|
-
requestOptions
|
|
81
|
-
);
|
|
82
|
-
return {
|
|
83
|
-
model: response == null ? void 0 : response.data,
|
|
84
|
-
response,
|
|
85
|
-
error: void 0
|
|
86
|
-
};
|
|
87
|
-
} catch (error) {
|
|
88
|
-
return {
|
|
89
|
-
model: void 0,
|
|
90
|
-
response: void 0,
|
|
91
|
-
error: error.response ? error.response.data : (_b = error.response) != null ? _b : error
|
|
92
|
-
};
|
|
93
|
-
}
|
|
90
|
+
return this.request("post", path, data, requestOptions);
|
|
94
91
|
});
|
|
95
92
|
}
|
|
96
93
|
put(path, data, requestOptions) {
|
|
97
94
|
return __async(this, null, function* () {
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
const response = yield this.client.put(
|
|
101
|
-
this.joinUrl((_a = requestOptions == null ? void 0 : requestOptions.baseUrl) != null ? _a : this.baseUrl, path),
|
|
102
|
-
data,
|
|
103
|
-
requestOptions
|
|
104
|
-
);
|
|
105
|
-
return {
|
|
106
|
-
model: response == null ? void 0 : response.data,
|
|
107
|
-
response,
|
|
108
|
-
error: void 0
|
|
109
|
-
};
|
|
110
|
-
} catch (error) {
|
|
111
|
-
return {
|
|
112
|
-
model: void 0,
|
|
113
|
-
response: void 0,
|
|
114
|
-
error: error.response ? error.response.data : (_b = error.response) != null ? _b : error
|
|
115
|
-
};
|
|
116
|
-
}
|
|
95
|
+
return this.request("put", path, data, requestOptions);
|
|
117
96
|
});
|
|
118
97
|
}
|
|
119
98
|
delete(path, requestOptions) {
|
|
120
99
|
return __async(this, null, function* () {
|
|
121
|
-
|
|
122
|
-
try {
|
|
123
|
-
const response = yield this.client.delete(
|
|
124
|
-
this.joinUrl((_a = requestOptions == null ? void 0 : requestOptions.baseUrl) != null ? _a : this.baseUrl, path),
|
|
125
|
-
requestOptions
|
|
126
|
-
);
|
|
127
|
-
return {
|
|
128
|
-
model: response == null ? void 0 : response.data,
|
|
129
|
-
response,
|
|
130
|
-
error: void 0
|
|
131
|
-
};
|
|
132
|
-
} catch (error) {
|
|
133
|
-
return {
|
|
134
|
-
model: void 0,
|
|
135
|
-
response: void 0,
|
|
136
|
-
error: error.response ? error.response.data : (_b = error.response) != null ? _b : error
|
|
137
|
-
};
|
|
138
|
-
}
|
|
100
|
+
return this.request("delete", path, void 0, requestOptions);
|
|
139
101
|
});
|
|
140
102
|
}
|
|
141
103
|
patch(path, data, requestOptions) {
|
|
142
104
|
return __async(this, null, function* () {
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
const response = yield this.client.patch(
|
|
146
|
-
this.joinUrl((_a = requestOptions == null ? void 0 : requestOptions.baseUrl) != null ? _a : this.baseUrl, path),
|
|
147
|
-
data,
|
|
148
|
-
requestOptions
|
|
149
|
-
);
|
|
150
|
-
return {
|
|
151
|
-
model: response == null ? void 0 : response.data,
|
|
152
|
-
response,
|
|
153
|
-
error: void 0
|
|
154
|
-
};
|
|
155
|
-
} catch (error) {
|
|
156
|
-
return {
|
|
157
|
-
model: void 0,
|
|
158
|
-
response: void 0,
|
|
159
|
-
error: error.response ? error.response.data : (_b = error.response) != null ? _b : error
|
|
160
|
-
};
|
|
161
|
-
}
|
|
105
|
+
return this.request("patch", path, data, requestOptions);
|
|
162
106
|
});
|
|
163
107
|
}
|
|
164
108
|
joinUrl(baseUrl, path) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
109
|
+
return new URL(path, baseUrl).toString();
|
|
110
|
+
}
|
|
111
|
+
getHeaders(customHeaders) {
|
|
112
|
+
return __spreadValues({
|
|
113
|
+
"Content-Type": "application/json"
|
|
114
|
+
}, customHeaders);
|
|
168
115
|
}
|
|
169
116
|
};
|
|
170
117
|
|
|
@@ -864,7 +811,7 @@ var CartApi = class extends BaseService {
|
|
|
864
811
|
*/
|
|
865
812
|
cartCount(requestOptions) {
|
|
866
813
|
return __async(this, null, function* () {
|
|
867
|
-
return yield this.get(
|
|
814
|
+
return yield this.get("cart/count", {}, requestOptions);
|
|
868
815
|
});
|
|
869
816
|
}
|
|
870
817
|
/**
|