@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.
Files changed (50) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +12 -0
  3. package/lib/cjs/client/index.js +170 -0
  4. package/lib/cjs/constants/Endpoints.js +622 -0
  5. package/lib/cjs/index.d.js +2 -0
  6. package/lib/cjs/index.js +46 -0
  7. package/lib/cjs/services/category/index.js +64 -0
  8. package/lib/cjs/services/feature/index.js +42 -0
  9. package/lib/cjs/services/preference/index.js +100 -0
  10. package/lib/cjs/services/user/index.js +85 -0
  11. package/lib/cjs/utils/http.js +51 -0
  12. package/lib/cjs/utils/token.js +36 -0
  13. package/lib/esm/api-services/src/client/index.d.ts +115 -0
  14. package/lib/esm/api-services/src/client/index.d.ts.map +1 -0
  15. package/lib/esm/api-services/src/constants/Endpoints.d.ts +10 -0
  16. package/lib/esm/api-services/src/constants/Endpoints.d.ts.map +1 -0
  17. package/lib/esm/api-services/src/index.d.ts +24 -0
  18. package/lib/esm/api-services/src/index.d.ts.map +1 -0
  19. package/lib/esm/api-services/src/services/category/index.d.ts +13 -0
  20. package/lib/esm/api-services/src/services/category/index.d.ts.map +1 -0
  21. package/lib/esm/api-services/src/services/feature/index.d.ts +10 -0
  22. package/lib/esm/api-services/src/services/feature/index.d.ts.map +1 -0
  23. package/lib/esm/api-services/src/services/preference/index.d.ts +16 -0
  24. package/lib/esm/api-services/src/services/preference/index.d.ts.map +1 -0
  25. package/lib/esm/api-services/src/services/user/index.d.ts +16 -0
  26. package/lib/esm/api-services/src/services/user/index.d.ts.map +1 -0
  27. package/lib/esm/api-services/src/utils/http.d.ts +6 -0
  28. package/lib/esm/api-services/src/utils/http.d.ts.map +1 -0
  29. package/lib/esm/api-services/src/utils/token.d.ts +16 -0
  30. package/lib/esm/api-services/src/utils/token.d.ts.map +1 -0
  31. package/lib/esm/client/index.js +170 -0
  32. package/lib/esm/constants/Endpoints.js +622 -0
  33. package/lib/esm/index.d.js +2 -0
  34. package/lib/esm/index.js +46 -0
  35. package/lib/esm/services/category/index.js +64 -0
  36. package/lib/esm/services/feature/index.js +42 -0
  37. package/lib/esm/services/preference/index.js +100 -0
  38. package/lib/esm/services/user/index.js +85 -0
  39. package/lib/esm/utils/http.js +51 -0
  40. package/lib/esm/utils/src/index.d.ts +7 -0
  41. package/lib/esm/utils/src/index.d.ts.map +1 -0
  42. package/lib/esm/utils/src/utils/string.d.ts +21 -0
  43. package/lib/esm/utils/src/utils/string.d.ts.map +1 -0
  44. package/lib/esm/utils/src/utils/url.d.ts +22 -0
  45. package/lib/esm/utils/src/utils/url.d.ts.map +1 -0
  46. package/lib/esm/utils/token.js +36 -0
  47. package/lib/umd/api-services.js +3 -0
  48. package/lib/umd/api-services.js.LICENSE.txt +1 -0
  49. package/lib/umd/api-services.js.map +1 -0
  50. package/package.json +114 -0
@@ -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;