@selfcommunity/api-services 0.1.2-alpha.0
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/LICENSE.md +21 -0
- package/README.md +12 -0
- package/lib/cjs/client/index.js +170 -0
- package/lib/cjs/constants/Endpoints.js +622 -0
- package/lib/cjs/index.d.js +2 -0
- package/lib/cjs/index.js +46 -0
- package/lib/cjs/services/category/index.js +64 -0
- package/lib/cjs/services/feature/index.js +42 -0
- package/lib/cjs/services/preference/index.js +100 -0
- package/lib/cjs/services/user/index.js +85 -0
- package/lib/cjs/utils/http.js +51 -0
- package/lib/cjs/utils/token.js +36 -0
- package/lib/esm/api-services/src/client/index.d.ts +115 -0
- package/lib/esm/api-services/src/client/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/constants/Endpoints.d.ts +10 -0
- package/lib/esm/api-services/src/constants/Endpoints.d.ts.map +1 -0
- package/lib/esm/api-services/src/index.d.ts +24 -0
- package/lib/esm/api-services/src/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/services/category/index.d.ts +13 -0
- package/lib/esm/api-services/src/services/category/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/services/feature/index.d.ts +10 -0
- package/lib/esm/api-services/src/services/feature/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/services/preference/index.d.ts +16 -0
- package/lib/esm/api-services/src/services/preference/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/services/user/index.d.ts +16 -0
- package/lib/esm/api-services/src/services/user/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/utils/http.d.ts +6 -0
- package/lib/esm/api-services/src/utils/http.d.ts.map +1 -0
- package/lib/esm/api-services/src/utils/token.d.ts +16 -0
- package/lib/esm/api-services/src/utils/token.d.ts.map +1 -0
- package/lib/esm/client/index.js +170 -0
- package/lib/esm/constants/Endpoints.js +622 -0
- package/lib/esm/index.d.js +2 -0
- package/lib/esm/index.js +46 -0
- package/lib/esm/services/category/index.js +64 -0
- package/lib/esm/services/feature/index.js +42 -0
- package/lib/esm/services/preference/index.js +100 -0
- package/lib/esm/services/user/index.js +85 -0
- package/lib/esm/utils/http.js +51 -0
- package/lib/esm/utils/src/index.d.ts +7 -0
- package/lib/esm/utils/src/index.d.ts.map +1 -0
- package/lib/esm/utils/src/utils/string.d.ts +21 -0
- package/lib/esm/utils/src/utils/string.d.ts.map +1 -0
- package/lib/esm/utils/src/utils/url.d.ts +22 -0
- package/lib/esm/utils/src/utils/url.d.ts.map +1 -0
- package/lib/esm/utils/token.js +36 -0
- package/lib/umd/api-services.js +3 -0
- package/lib/umd/api-services.js.LICENSE.txt +1 -0
- package/lib/umd/api-services.js.map +1 -0
- package/package.json +114 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Quentral Srl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
@selfcommunity/api-services
|
|
2
|
+
=============
|
|
3
|
+
|
|
4
|
+
[](https://github.com/selfcommunity/community-js/blob/master/LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/@selfcommunity/api-services)
|
|
6
|
+
[](https://www.npmjs.com/package/@selfcommunity/api-services)
|
|
7
|
+
[](https://twitter.com/community_self)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Install
|
|
11
|
+
|
|
12
|
+
`npm install @selfcommunity/api-services`
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = exports.ApiClient = void 0;
|
|
5
|
+
|
|
6
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
7
|
+
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create an abstraction wrapping of axios
|
|
12
|
+
* Create a sort of interface between axios and the rest of application
|
|
13
|
+
* This makes it easy for instance, to swap axios out for another package,
|
|
14
|
+
* should we choose to do so in the future, without it breaking our app.
|
|
15
|
+
*/
|
|
16
|
+
class ApiClient {
|
|
17
|
+
createClient(config) {
|
|
18
|
+
return _axios.default.create(Object.assign({}, config && config.baseURL && {
|
|
19
|
+
baseURL: config.baseURL
|
|
20
|
+
}, {
|
|
21
|
+
responseType: 'json',
|
|
22
|
+
headers: Object.assign({}, config && config.accessToken && {
|
|
23
|
+
Authorization: `Token ${config.accessToken}`
|
|
24
|
+
}),
|
|
25
|
+
timeout: ApiClient.DEFAULT_TIMEOUT
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor(config) {
|
|
30
|
+
this.setDefaultHeader = ({
|
|
31
|
+
name,
|
|
32
|
+
value,
|
|
33
|
+
methods
|
|
34
|
+
}) => {
|
|
35
|
+
const headers = this.client.defaults.headers;
|
|
36
|
+
|
|
37
|
+
if (Array.isArray(methods)) {
|
|
38
|
+
methods.forEach(method => {
|
|
39
|
+
if (headers[method]) {
|
|
40
|
+
headers[method][name] = value;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
headers.common[name] = value;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
this.client = this.createClient(config);
|
|
49
|
+
this.setDefaultHeader({
|
|
50
|
+
name: 'Content-Type',
|
|
51
|
+
value: 'application/x-www-form-urlencoded',
|
|
52
|
+
methods: ['post']
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get client instance
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
getClientInstance() {
|
|
61
|
+
return this.client;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Change configuration
|
|
65
|
+
* @param config
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
config(config) {
|
|
70
|
+
this.client(config);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Set default header
|
|
74
|
+
* @param name
|
|
75
|
+
* @param value
|
|
76
|
+
* @param methods
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* setSupportWithCredentials
|
|
82
|
+
* Disable/enable withCredentials
|
|
83
|
+
* Bypass cookie if disabled
|
|
84
|
+
* @param enable
|
|
85
|
+
*/
|
|
86
|
+
setSupportWithCredentials(enable) {
|
|
87
|
+
this.client.defaults.withCredentials = enable;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* setBasePortal
|
|
91
|
+
* Set base path of all http requests
|
|
92
|
+
* @param portal
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
setBasePortal(baseUrl) {
|
|
97
|
+
this.client.defaults.baseURL = baseUrl;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* setAuthorizeToken
|
|
101
|
+
* Set authorization header for all http requests
|
|
102
|
+
* @param token
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
setAuthorizeToken(token) {
|
|
107
|
+
if (token) {
|
|
108
|
+
this.setDefaultHeader({
|
|
109
|
+
name: 'Authorization',
|
|
110
|
+
value: `Bearer ${token}`
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* request wrapper
|
|
116
|
+
* @param config
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
request(config) {
|
|
121
|
+
return this.client.request(config);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* get wrapper
|
|
125
|
+
* @param path
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
get(path) {
|
|
130
|
+
return this.client.get(path);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* post wrapper
|
|
134
|
+
* @param path
|
|
135
|
+
* @param payload
|
|
136
|
+
* @param config
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
post(path, payload, config) {
|
|
141
|
+
return config ? this.client.post(path, payload, config) : this.client.post(path, payload);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* patch wrapper
|
|
145
|
+
* @param path
|
|
146
|
+
* @param object
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
patch(path, payload) {
|
|
151
|
+
return this.client.patch(path, payload);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* put wrapper
|
|
155
|
+
* @param path
|
|
156
|
+
* @param payload
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
put(path, payload) {
|
|
161
|
+
return this.client.put(path, payload);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
exports.ApiClient = ApiClient;
|
|
167
|
+
ApiClient.DEFAULT_TIMEOUT = 10 * 1000;
|
|
168
|
+
const client = new ApiClient();
|
|
169
|
+
var _default = client;
|
|
170
|
+
exports.default = _default;
|