@bzbs/react-api-client 0.2.0 → 0.2.2

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 CHANGED
@@ -1,82 +1,82 @@
1
- # Installing
2
-
3
- Using npm :
4
-
5
- ```bash
6
- npm i @bzbs/react-api-client
7
- ```
8
-
9
- Once the package is installed, you can import the library using import or require approach:
10
-
11
- ```js
12
- import { BzbsService } from '@bzbs/react-api-client';
13
- ```
14
-
15
- You must to have AxiosInstance, Base URL and Line URL for library require:
16
-
17
- ```js
18
- const axiosClient = axios.create({});
19
- const baseUrl = 'https://www.xxx-api.com/api/';
20
- const lineUrl = 'https://api.line.me/v2/bot/';
21
- ```
22
-
23
- And defind const and export libraty to using:
24
-
25
- ```js
26
- export const bzbsService = new BzbsService(axiosClient, baseUrl, lineUrl);
27
- ```
28
-
29
- If you have default header you can add to AxiosInstance brfore:
30
-
31
- ```js
32
- const defaultOptions = {
33
- headers: {
34
- 'Content-Type': 'application/json, multipart/form-data',
35
- 'App-Id': 2952697274802274,
36
- 'Ocp-Apim-Subscription-Key': '89c1d9bafb65486aa02606f63cb86b5c',
37
- },
38
- };
39
-
40
- axiosClient.defaults.headers.common = defaultOptions.headers;
41
- ```
42
-
43
- ## Example
44
-
45
- Create service-config.tsx file:
46
-
47
- ```tsx
48
- import { BzbsService } from '@bzbs/react-api-client';
49
- import axios from 'axios';
50
-
51
- const defaultOptions = {
52
- headers: {
53
- 'Content-Type': 'application/json, multipart/form-data',
54
- 'App-Id': 2952697274802274,
55
- 'Ocp-Apim-Subscription-Key': '89c1d9bafb65486aa02606f63cb86b5c',
56
- },
57
- };
58
-
59
- var axiosClient = axios.create({});
60
- axiosClient.defaults.headers.common = defaultOptions.headers;
61
-
62
- const baseUrl = 'https://apigateway.buzzebees-uat.com/api/';
63
- const lineUrl = 'https://api.line.me/v2/bot/';
64
-
65
- export const bzbsService = new BzbsService(axiosClient, baseUrl, lineUrl);
66
- ```
67
-
68
- Using service API in another files:
69
-
70
- ```tsx
71
- import { bzbsService } from './src/service-config';
72
-
73
- const campaigList = async () => {
74
- await bzbsService.campaignApi?.campaign({
75
- config: 'campaign_buzzebeesdemo',
76
- byConfig: true,
77
- skip: 0,
78
- top: 10,
79
- deviceLocale: 1054,
80
- });
81
- };
82
- ```
1
+ # Installing
2
+
3
+ Using npm :
4
+
5
+ ```bash
6
+ npm i @bzbs/react-api-client
7
+ ```
8
+
9
+ Once the package is installed, you can import the library using import or require approach:
10
+
11
+ ```js
12
+ import { BzbsService } from '@bzbs/react-api-client';
13
+ ```
14
+
15
+ You must to have AxiosInstance, Base URL and Line URL for library require:
16
+
17
+ ```js
18
+ const axiosClient = axios.create({});
19
+ const baseUrl = 'https://www.xxx-api.com/api/';
20
+ const lineUrl = 'https://api.line.me/v2/bot/';
21
+ ```
22
+
23
+ And defind const and export libraty to using:
24
+
25
+ ```js
26
+ export const bzbsService = new BzbsService(axiosClient, baseUrl, lineUrl);
27
+ ```
28
+
29
+ If you have default header you can add to AxiosInstance brfore:
30
+
31
+ ```js
32
+ const defaultOptions = {
33
+ headers: {
34
+ 'Content-Type': 'application/json, multipart/form-data',
35
+ 'App-Id': 2952697274802274,
36
+ 'Ocp-Apim-Subscription-Key': '89c1d9bafb65486aa02606f63cb86b5c',
37
+ },
38
+ };
39
+
40
+ axiosClient.defaults.headers.common = defaultOptions.headers;
41
+ ```
42
+
43
+ ## Example
44
+
45
+ Create service-config.tsx file:
46
+
47
+ ```tsx
48
+ import { BzbsService } from '@bzbs/react-api-client';
49
+ import axios from 'axios';
50
+
51
+ const defaultOptions = {
52
+ headers: {
53
+ 'Content-Type': 'application/json, multipart/form-data',
54
+ 'App-Id': 2952697274802274,
55
+ 'Ocp-Apim-Subscription-Key': '89c1d9bafb65486aa02606f63cb86b5c',
56
+ },
57
+ };
58
+
59
+ var axiosClient = axios.create({});
60
+ axiosClient.defaults.headers.common = defaultOptions.headers;
61
+
62
+ const baseUrl = 'https://apigateway.buzzebees-uat.com/api/';
63
+ const lineUrl = 'https://api.line.me/v2/bot/';
64
+
65
+ export const bzbsService = new BzbsService(axiosClient, baseUrl, lineUrl);
66
+ ```
67
+
68
+ Using service API in another files:
69
+
70
+ ```tsx
71
+ import { bzbsService } from './src/service-config';
72
+
73
+ const campaigList = async () => {
74
+ await bzbsService.campaignApi?.campaign({
75
+ config: 'campaign_buzzebeesdemo',
76
+ byConfig: true,
77
+ skip: 0,
78
+ top: 10,
79
+ deviceLocale: 1054,
80
+ });
81
+ };
82
+ ```
package/dist/index.d.mts CHANGED
@@ -11,6 +11,10 @@ interface BzbsErrorResponse {
11
11
  }
12
12
 
13
13
  type ServiceResponse<T> = SuccessResponse<T> | ErrorResponse;
14
+ interface ApiResponse<T> {
15
+ Success: boolean;
16
+ Data: T;
17
+ }
14
18
  type SuccessResponse<T> = {
15
19
  type: 'success';
16
20
  model: T;
@@ -2678,4 +2682,4 @@ declare class BzbsService {
2678
2682
  constructor(client: AxiosInstance, baseUrl: string, baseLineUrl: string, baseBlobUrl: string);
2679
2683
  }
2680
2684
 
2681
- export { type Address, AddressApi, 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 };
2685
+ 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
@@ -11,6 +11,10 @@ interface BzbsErrorResponse {
11
11
  }
12
12
 
13
13
  type ServiceResponse<T> = SuccessResponse<T> | ErrorResponse;
14
+ interface ApiResponse<T> {
15
+ Success: boolean;
16
+ Data: T;
17
+ }
14
18
  type SuccessResponse<T> = {
15
19
  type: 'success';
16
20
  model: T;
@@ -2678,4 +2682,4 @@ declare class BzbsService {
2678
2682
  constructor(client: AxiosInstance, baseUrl: string, baseLineUrl: string, baseBlobUrl: string);
2679
2683
  }
2680
2684
 
2681
- export { type Address, AddressApi, 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 };
2685
+ 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",
@@ -117,6 +125,35 @@ var BaseService = class {
117
125
  data
118
126
  };
119
127
  const response = yield this.client.request(__spreadValues({ method, url }, config));
128
+ if (response.status === 204) {
129
+ return { model: "", response, type: "success" };
130
+ }
131
+ if ("Success" in response.data) {
132
+ const data2 = response.data;
133
+ if (data2.Success) {
134
+ if ("Data" in response.data) {
135
+ return { model: data2.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 || 500,
146
+ message: response.data.Message || "An unexpected error occurred.",
147
+ code: response.data.Code || 500,
148
+ type: "buzzebees"
149
+ }
150
+ },
151
+ statusCode: response.data.Code || 500,
152
+ response
153
+ };
154
+ return this.normalizeError(error);
155
+ }
156
+ }
120
157
  return { model: response.data, response, type: "success" };
121
158
  } catch (error) {
122
159
  return this.normalizeError(error);