@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.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +55 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -14,6 +14,8 @@ type ServiceResponse<T> = SuccessResponse<T> | ErrorResponse;
|
|
|
14
14
|
interface ApiResponse<T> {
|
|
15
15
|
Success: boolean;
|
|
16
16
|
Data: T;
|
|
17
|
+
success: boolean;
|
|
18
|
+
data: T;
|
|
17
19
|
}
|
|
18
20
|
type SuccessResponse<T> = {
|
|
19
21
|
type: 'success';
|
|
@@ -47,6 +49,7 @@ declare class BaseService {
|
|
|
47
49
|
private baseUrl;
|
|
48
50
|
constructor(client: AxiosInstance, baseUrl: string);
|
|
49
51
|
private normalizeError;
|
|
52
|
+
private normalizeResponse;
|
|
50
53
|
private request;
|
|
51
54
|
get<T>(path: string, params?: any, requestOptions?: RequestOptions): Promise<ServiceResponse<T>>;
|
|
52
55
|
post<T>(path: string, data: any, requestOptions?: RequestOptions): Promise<ServiceResponse<T>>;
|
|
@@ -2669,7 +2672,7 @@ declare class BzbsService {
|
|
|
2669
2672
|
couponApi: CouponApi;
|
|
2670
2673
|
dashboardApi: DashboardApi;
|
|
2671
2674
|
historyApi: HistoryApi;
|
|
2672
|
-
lineApi: LineApi;
|
|
2675
|
+
lineApi: LineApi | undefined;
|
|
2673
2676
|
notificationApi: NotificationApi;
|
|
2674
2677
|
placeApi: PlaceApi;
|
|
2675
2678
|
pointLogApi: PointLogApi;
|
|
@@ -2679,7 +2682,7 @@ declare class BzbsService {
|
|
|
2679
2682
|
stampApi: StampApi;
|
|
2680
2683
|
forumApi: RequestHelpApi;
|
|
2681
2684
|
blob: Blob;
|
|
2682
|
-
constructor(client: AxiosInstance, baseUrl: string, baseLineUrl: string, baseBlobUrl: string);
|
|
2685
|
+
constructor(client: AxiosInstance, baseUrl: string, baseLineUrl: string | "", baseBlobUrl: string);
|
|
2683
2686
|
}
|
|
2684
2687
|
|
|
2685
2688
|
export { type Address, AddressApi, type ApiResponse, AuthenticateApi, type Badge, BadgeApi, BaseService, Blob, type Buzzebees, type BzbsErrorResponse, BzbsService, type Campaign, CampaignApi, type CampaignDetail, type CartAccessResponse, CartApi, type CartCountResponse, type Category, CategoryApi, type ChatMessage, type ClientError, type ConfirmOtpResponse, type Consent, ConsentApi, type ConsentVersion, type ConsentVersionValue, CouponApi, type CouponResponse, type CouponResponseData, type CreateStampResponse, type Dashboard, DashboardApi, type Detail, type District, type ErrorResponse, type ExpiringPoints, type FavoriteResponse, type ForgetPasswordResponse, HistoryApi, type LikeForumResponse, LineApi, type LineAuthResponse, type LoginResponse, type Maintenance, type Mission, type Notification, NotificationApi, type OtpResponse, type Picture, type Place, PlaceApi, type PlaceService, type PointLog, PointLogApi, ProfileApi, type ProfileResponse, type Province, type Purchase, type RedeemResponse, RegistrationApi, type RegistrationResponse, RequestHelpApi, type RequestHelpCode, type RequestOptions, type ResumeResponse, type ServerError, type ServiceResponse, type Stamp, StampApi, type StampCampaign, type StampHistory, type StampProfileResponse, type StatusResponse, type Style, type SubCampaign, type SubCampaignStyle, type SubDistrict, type SuccessResponse, type Trace, type UpdatedPoints, type UseCampaignResponse, type ValidateOtpResponse, type Version, type ZipCode };
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ type ServiceResponse<T> = SuccessResponse<T> | ErrorResponse;
|
|
|
14
14
|
interface ApiResponse<T> {
|
|
15
15
|
Success: boolean;
|
|
16
16
|
Data: T;
|
|
17
|
+
success: boolean;
|
|
18
|
+
data: T;
|
|
17
19
|
}
|
|
18
20
|
type SuccessResponse<T> = {
|
|
19
21
|
type: 'success';
|
|
@@ -47,6 +49,7 @@ declare class BaseService {
|
|
|
47
49
|
private baseUrl;
|
|
48
50
|
constructor(client: AxiosInstance, baseUrl: string);
|
|
49
51
|
private normalizeError;
|
|
52
|
+
private normalizeResponse;
|
|
50
53
|
private request;
|
|
51
54
|
get<T>(path: string, params?: any, requestOptions?: RequestOptions): Promise<ServiceResponse<T>>;
|
|
52
55
|
post<T>(path: string, data: any, requestOptions?: RequestOptions): Promise<ServiceResponse<T>>;
|
|
@@ -2669,7 +2672,7 @@ declare class BzbsService {
|
|
|
2669
2672
|
couponApi: CouponApi;
|
|
2670
2673
|
dashboardApi: DashboardApi;
|
|
2671
2674
|
historyApi: HistoryApi;
|
|
2672
|
-
lineApi: LineApi;
|
|
2675
|
+
lineApi: LineApi | undefined;
|
|
2673
2676
|
notificationApi: NotificationApi;
|
|
2674
2677
|
placeApi: PlaceApi;
|
|
2675
2678
|
pointLogApi: PointLogApi;
|
|
@@ -2679,7 +2682,7 @@ declare class BzbsService {
|
|
|
2679
2682
|
stampApi: StampApi;
|
|
2680
2683
|
forumApi: RequestHelpApi;
|
|
2681
2684
|
blob: Blob;
|
|
2682
|
-
constructor(client: AxiosInstance, baseUrl: string, baseLineUrl: string, baseBlobUrl: string);
|
|
2685
|
+
constructor(client: AxiosInstance, baseUrl: string, baseLineUrl: string | "", baseBlobUrl: string);
|
|
2683
2686
|
}
|
|
2684
2687
|
|
|
2685
2688
|
export { type Address, AddressApi, type ApiResponse, AuthenticateApi, type Badge, BadgeApi, BaseService, Blob, type Buzzebees, type BzbsErrorResponse, BzbsService, type Campaign, CampaignApi, type CampaignDetail, type CartAccessResponse, CartApi, type CartCountResponse, type Category, CategoryApi, type ChatMessage, type ClientError, type ConfirmOtpResponse, type Consent, ConsentApi, type ConsentVersion, type ConsentVersionValue, CouponApi, type CouponResponse, type CouponResponseData, type CreateStampResponse, type Dashboard, DashboardApi, type Detail, type District, type ErrorResponse, type ExpiringPoints, type FavoriteResponse, type ForgetPasswordResponse, HistoryApi, type LikeForumResponse, LineApi, type LineAuthResponse, type LoginResponse, type Maintenance, type Mission, type Notification, NotificationApi, type OtpResponse, type Picture, type Place, PlaceApi, type PlaceService, type PointLog, PointLogApi, ProfileApi, type ProfileResponse, type Province, type Purchase, type RedeemResponse, RegistrationApi, type RegistrationResponse, RequestHelpApi, type RequestHelpCode, type RequestOptions, type ResumeResponse, type ServerError, type ServiceResponse, type Stamp, StampApi, type StampCampaign, type StampHistory, type StampProfileResponse, type StatusResponse, type Style, type SubCampaign, type SubCampaignStyle, type SubDistrict, type SuccessResponse, type Trace, type UpdatedPoints, type UseCampaignResponse, type ValidateOtpResponse, type Version, type ZipCode };
|
package/dist/index.js
CHANGED
|
@@ -92,6 +92,14 @@ var BaseService = class {
|
|
|
92
92
|
this.baseUrl = baseUrl;
|
|
93
93
|
}
|
|
94
94
|
normalizeError(error) {
|
|
95
|
+
if (error.error) {
|
|
96
|
+
return {
|
|
97
|
+
type: "server-error",
|
|
98
|
+
error: error.error,
|
|
99
|
+
statusCode: error.response.status,
|
|
100
|
+
response: error.response
|
|
101
|
+
};
|
|
102
|
+
}
|
|
95
103
|
if (error.response && error.response.data) {
|
|
96
104
|
return {
|
|
97
105
|
type: "server-error",
|
|
@@ -106,6 +114,48 @@ var BaseService = class {
|
|
|
106
114
|
details: error
|
|
107
115
|
};
|
|
108
116
|
}
|
|
117
|
+
normalizeResponse(response) {
|
|
118
|
+
if (response.status === 204) {
|
|
119
|
+
return { model: {}, response, type: "success" };
|
|
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",
|
|
142
|
+
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
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return { model: response.data, response, type: "success" };
|
|
158
|
+
}
|
|
109
159
|
request(method, path, data, requestOptions) {
|
|
110
160
|
return __async(this, null, function* () {
|
|
111
161
|
var _a;
|
|
@@ -117,41 +167,13 @@ var BaseService = class {
|
|
|
117
167
|
data
|
|
118
168
|
};
|
|
119
169
|
const response = yield this.client.request(__spreadValues({ method, url }, config));
|
|
120
|
-
|
|
121
|
-
return { model: "", response, type: "success" };
|
|
122
|
-
}
|
|
123
|
-
if ("Success" in response.data) {
|
|
124
|
-
const data2 = response.data;
|
|
125
|
-
if (data2.Success) {
|
|
126
|
-
if ("Data" in response.data) {
|
|
127
|
-
return { model: data2.Data, response, type: "success" };
|
|
128
|
-
} else {
|
|
129
|
-
return { model: "", response, type: "success" };
|
|
130
|
-
}
|
|
131
|
-
} else {
|
|
132
|
-
const error = {
|
|
133
|
-
type: "server-error",
|
|
134
|
-
error: {
|
|
135
|
-
requestId: response.data.RequestId || "",
|
|
136
|
-
error: {
|
|
137
|
-
id: response.data.Code || 500,
|
|
138
|
-
message: response.data.Message || "An unexpected error occurred.",
|
|
139
|
-
code: response.data.Code || 500,
|
|
140
|
-
type: "buzzebees"
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
statusCode: response.data.Code || 500,
|
|
144
|
-
response
|
|
145
|
-
};
|
|
146
|
-
return this.normalizeError(error);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return { model: response.data, response, type: "success" };
|
|
170
|
+
return this.normalizeResponse(response);
|
|
150
171
|
} catch (error) {
|
|
151
172
|
return this.normalizeError(error);
|
|
152
173
|
}
|
|
153
174
|
});
|
|
154
175
|
}
|
|
176
|
+
/* if blob type we not include header in requestOptions */
|
|
155
177
|
get(path, params, requestOptions) {
|
|
156
178
|
return __async(this, null, function* () {
|
|
157
179
|
return this.request("get", path, void 0, __spreadProps(__spreadValues({}, requestOptions), { params }));
|
|
@@ -2299,7 +2321,9 @@ var BzbsService = class {
|
|
|
2299
2321
|
this.couponApi = new CouponApi(this.client, this.baseUrl);
|
|
2300
2322
|
this.dashboardApi = new DashboardApi(this.client, this.baseUrl);
|
|
2301
2323
|
this.historyApi = new HistoryApi(this.client, this.baseUrl);
|
|
2302
|
-
|
|
2324
|
+
if (this.baseLineUrl) {
|
|
2325
|
+
this.lineApi = new LineApi(this.client, this.baseLineUrl);
|
|
2326
|
+
}
|
|
2303
2327
|
this.notificationApi = new NotificationApi(this.client, this.baseUrl);
|
|
2304
2328
|
this.placeApi = new PlaceApi(this.client, this.baseUrl);
|
|
2305
2329
|
this.pointLogApi = new PointLogApi(this.client, this.baseUrl);
|