@bzbs/react-api-client 0.2.3 → 1.0.1

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 CHANGED
@@ -56,8 +56,12 @@ declare class BaseService {
56
56
  put<T>(path: string, data: any, requestOptions?: RequestOptions): Promise<ServiceResponse<T>>;
57
57
  delete<T>(path: string, requestOptions?: RequestOptions): Promise<ServiceResponse<T>>;
58
58
  patch<T>(path: string, data: any, requestOptions?: RequestOptions): Promise<ServiceResponse<T>>;
59
- private joinUrl;
60
- private getHeaders;
59
+ joinUrl(baseUrl: string, path: string): string;
60
+ getHeaders(customHeaders?: {
61
+ [key: string]: string;
62
+ }): {
63
+ [key: string]: string;
64
+ };
61
65
  }
62
66
 
63
67
  interface LoginResponse {
package/dist/index.d.ts CHANGED
@@ -56,8 +56,12 @@ declare class BaseService {
56
56
  put<T>(path: string, data: any, requestOptions?: RequestOptions): Promise<ServiceResponse<T>>;
57
57
  delete<T>(path: string, requestOptions?: RequestOptions): Promise<ServiceResponse<T>>;
58
58
  patch<T>(path: string, data: any, requestOptions?: RequestOptions): Promise<ServiceResponse<T>>;
59
- private joinUrl;
60
- private getHeaders;
59
+ joinUrl(baseUrl: string, path: string): string;
60
+ getHeaders(customHeaders?: {
61
+ [key: string]: string;
62
+ }): {
63
+ [key: string]: string;
64
+ };
61
65
  }
62
66
 
63
67
  interface LoginResponse {
package/dist/index.js CHANGED
@@ -118,43 +118,30 @@ var BaseService = class {
118
118
  if (response.status === 204) {
119
119
  return { model: {}, response, type: "success" };
120
120
  }
121
- if ("Success" in response.data || "success" in response.data) {
122
- const data = response.data;
123
- if (data.Success) {
124
- if ("Data" in response.data) {
125
- return { model: data.Data, response, type: "success" };
126
- } else if ("data" in response.data) {
127
- return { model: data.data, response, type: "success" };
128
- } else {
129
- return { model: {}, response, type: "success" };
130
- }
131
- } else if (data.success) {
132
- if ("Data" in response.data) {
133
- return { model: data.Data, response, type: "success" };
134
- } else if ("data" in response.data) {
135
- return { model: data.data, response, type: "success" };
136
- } else {
137
- return { model: {}, response, type: "success" };
138
- }
139
- } else {
140
- const error = {
141
- type: "server-error",
121
+ const data = response.data;
122
+ const isSuccess = (data == null ? void 0 : data.Success) === true || (data == null ? void 0 : data.success) === true;
123
+ if (isSuccess) {
124
+ const model = "Data" in data ? data.Data : "data" in data ? data.data : {};
125
+ return { model, response, type: "success" };
126
+ }
127
+ if ("Success" in data || "success" in data) {
128
+ const error = {
129
+ type: "server-error",
130
+ error: {
131
+ requestId: data.RequestId || "",
142
132
  error: {
143
- requestId: response.data.RequestId || "",
144
- error: {
145
- id: response.data.Code || response.status,
146
- message: response.data.Message || response.statusText,
147
- code: response.data.Code || response.status,
148
- type: "buzzebees"
149
- }
150
- },
151
- statusCode: response.data.Code || response.status,
152
- response
153
- };
154
- return this.normalizeError(error);
155
- }
133
+ id: data.Code || data.code || response.status,
134
+ message: data.Message || data.message || response.statusText,
135
+ code: data.Code || data.code || response.status,
136
+ type: "buzzebees"
137
+ }
138
+ },
139
+ statusCode: data.Code || response.status,
140
+ response
141
+ };
142
+ return this.normalizeError(error);
156
143
  }
157
- return { model: response.data, response, type: "success" };
144
+ return { model: data, response, type: "success" };
158
145
  }
159
146
  request(method, path, data, requestOptions) {
160
147
  return __async(this, null, function* () {
@@ -200,7 +187,9 @@ var BaseService = class {
200
187
  });
201
188
  }
202
189
  joinUrl(baseUrl, path) {
203
- return new URL(path, baseUrl).toString();
190
+ const sanitizedBase = baseUrl.replace(/\/+$/, "");
191
+ const sanitizedPath = path.replace(/^\/+/, "");
192
+ return `${sanitizedBase}/${sanitizedPath}`;
204
193
  }
205
194
  getHeaders(customHeaders) {
206
195
  return __spreadValues({
@@ -1199,7 +1188,7 @@ var HistoryApi = class extends BaseService {
1199
1188
  */
1200
1189
  redeemHistories(params, requestOptions) {
1201
1190
  return __async(this, null, function* () {
1202
- return yield this.get(
1191
+ const response = yield this.get(
1203
1192
  "redeem",
1204
1193
  __spreadValues({
1205
1194
  byConfig: params.byConfig,
@@ -1212,6 +1201,18 @@ var HistoryApi = class extends BaseService {
1212
1201
  }, params.options),
1213
1202
  requestOptions
1214
1203
  );
1204
+ if (response.type === "success") {
1205
+ const purchases = response.model.map((item) => {
1206
+ var _a, _b;
1207
+ return __spreadProps(__spreadValues({}, item), {
1208
+ ParcelNo: (_b = (_a = item.ParcelNo) != null ? _a : item.PacelNo) != null ? _b : void 0
1209
+ });
1210
+ });
1211
+ return __spreadProps(__spreadValues({}, response), {
1212
+ model: purchases
1213
+ });
1214
+ }
1215
+ return response;
1215
1216
  });
1216
1217
  }
1217
1218
  /**