@bzbs/react-api-client 0.2.0 → 0.2.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/README.md +82 -82
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +63 -63
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
|
@@ -117,6 +117,35 @@ var BaseService = class {
|
|
|
117
117
|
data
|
|
118
118
|
};
|
|
119
119
|
const response = yield this.client.request(__spreadValues({ method, url }, config));
|
|
120
|
+
if (response.status === 204) {
|
|
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
|
+
}
|
|
120
149
|
return { model: response.data, response, type: "success" };
|
|
121
150
|
} catch (error) {
|
|
122
151
|
return this.normalizeError(error);
|