@bzbs/react-api-client 0.0.1 → 0.0.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.
Files changed (2) hide show
  1. package/README.md +73 -45
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,54 +1,82 @@
1
- ###### Example initail Lib ####
1
+ # Installing
2
2
 
3
- // "use client";
4
- import axios, { AxiosError } from "axios";
5
- import { bzbsService } from "module-demo-bzbs";
6
- import { EnvConfig } from "./utils/env-config";
7
- import curlirize from 'axios-curlirize';
3
+ Using npm :
8
4
 
9
- var client = axios.create({});
5
+ ```bash
6
+ npm i @bzbs/react-api-client
7
+ ```
10
8
 
9
+ Once the package is installed, you can import the library using import or require approach:
11
10
 
12
- client.interceptors.request.use(
13
- async (config) => {
14
- config.headers["Content-Type"] = "application/json, multipart/form-data";
15
- config.headers["App-Id"] = 2952697274802274;
16
- config.headers["Ocp-Apim-Subscription-Key"] =
17
- "89c1d9bafb65486aa02606f63cb86b5c";
11
+ ```js
12
+ import { BzbsService } from '@bzbs/react-api-client';
13
+ ```
18
14
 
19
- // if (accessToken) {
20
- // config.headers["Authorization"] = `token ${accessToken.value}`;
21
- // }
22
- return config;
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',
23
37
  },
24
- (error) => {
25
- return Promise.reject(error);
26
- }
27
- );
38
+ };
39
+
40
+ axiosClient.defaults.headers.common = defaultOptions.headers;
41
+ ```
42
+
43
+ ## Example
28
44
 
29
- // Response interceptor
30
- client.interceptors.response.use(
31
- (response) => {
32
- console.log("response : %O", response.data);
45
+ Create service-config.tsx file:
33
46
 
34
- return response;
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',
35
56
  },
36
- (error) => {
37
- // Handle response errors here
38
-
39
- if (error instanceof AxiosError) {
40
- console.log("error AxiosError: %O", error.message);
41
- } else {
42
- console.log("object: %O", error);
43
- }
44
- return Promise.reject(error);
45
- }
46
- );
47
- curlirize(client);
48
- export const serviceBzbs = new bzbsService(
49
- client,
50
- "https://apigateway.buzzebees-uat.com/api/",
51
- "aaa"
52
- );
53
-
54
- ######
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bzbs/react-api-client",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "React API Client for Buzzebees",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -38,7 +38,7 @@
38
38
  "acorn": "^8.11.3",
39
39
  "acorn-walk": "^8.3.2",
40
40
  "arg": "^4.1.3",
41
- "axios": "^1.6.8",
41
+ "axios": "^1.7.2",
42
42
  "create-require": "^1.1.1",
43
43
  "diff": "^4.0.2",
44
44
  "make-error": "^1.3.6",