@bzbs/react-api-client 0.2.1 → 0.2.3

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
@@ -49,6 +49,14 @@ var BaseService = class {
49
49
  this.baseUrl = baseUrl;
50
50
  }
51
51
  normalizeError(error) {
52
+ if (error.error) {
53
+ return {
54
+ type: "server-error",
55
+ error: error.error,
56
+ statusCode: error.response.status,
57
+ response: error.response
58
+ };
59
+ }
52
60
  if (error.response && error.response.data) {
53
61
  return {
54
62
  type: "server-error",
@@ -63,6 +71,48 @@ var BaseService = class {
63
71
  details: error
64
72
  };
65
73
  }
74
+ normalizeResponse(response) {
75
+ if (response.status === 204) {
76
+ return { model: {}, response, type: "success" };
77
+ }
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",
99
+ 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
+ }
113
+ }
114
+ return { model: response.data, response, type: "success" };
115
+ }
66
116
  request(method, path, data, requestOptions) {
67
117
  return __async(this, null, function* () {
68
118
  var _a;
@@ -74,41 +124,13 @@ var BaseService = class {
74
124
  data
75
125
  };
76
126
  const response = yield this.client.request(__spreadValues({ method, url }, config));
77
- if (response.status === 204) {
78
- return { model: "", response, type: "success" };
79
- }
80
- if ("Success" in response.data) {
81
- const data2 = response.data;
82
- if (data2.Success) {
83
- if ("Data" in response.data) {
84
- return { model: data2.Data, response, type: "success" };
85
- } else {
86
- return { model: "", response, type: "success" };
87
- }
88
- } else {
89
- const error = {
90
- type: "server-error",
91
- error: {
92
- requestId: response.data.RequestId || "",
93
- error: {
94
- id: response.data.Code || 500,
95
- message: response.data.Message || "An unexpected error occurred.",
96
- code: response.data.Code || 500,
97
- type: "buzzebees"
98
- }
99
- },
100
- statusCode: response.data.Code || 500,
101
- response
102
- };
103
- return this.normalizeError(error);
104
- }
105
- }
106
- return { model: response.data, response, type: "success" };
127
+ return this.normalizeResponse(response);
107
128
  } catch (error) {
108
129
  return this.normalizeError(error);
109
130
  }
110
131
  });
111
132
  }
133
+ /* if blob type we not include header in requestOptions */
112
134
  get(path, params, requestOptions) {
113
135
  return __async(this, null, function* () {
114
136
  return this.request("get", path, void 0, __spreadProps(__spreadValues({}, requestOptions), { params }));
@@ -2256,7 +2278,9 @@ var BzbsService = class {
2256
2278
  this.couponApi = new CouponApi(this.client, this.baseUrl);
2257
2279
  this.dashboardApi = new DashboardApi(this.client, this.baseUrl);
2258
2280
  this.historyApi = new HistoryApi(this.client, this.baseUrl);
2259
- this.lineApi = new LineApi(this.client, this.baseLineUrl);
2281
+ if (this.baseLineUrl) {
2282
+ this.lineApi = new LineApi(this.client, this.baseLineUrl);
2283
+ }
2260
2284
  this.notificationApi = new NotificationApi(this.client, this.baseUrl);
2261
2285
  this.placeApi = new PlaceApi(this.client, this.baseUrl);
2262
2286
  this.pointLogApi = new PointLogApi(this.client, this.baseUrl);