@iamnnort/request 1.9.2 → 1.10.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/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +280 -299
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +265 -246
- package/dist/index.mjs.map +1 -1
- package/package.json +26 -26
package/dist/index.js
CHANGED
|
@@ -1,79 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __export = (target, all) => {
|
|
26
|
-
for (var name in all)
|
|
27
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
-
};
|
|
29
|
-
var __copyProps = (to, from, except, desc) => {
|
|
30
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
-
for (let key of __getOwnPropNames(from))
|
|
32
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
-
}
|
|
35
|
-
return to;
|
|
36
|
-
};
|
|
37
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
-
mod
|
|
44
|
-
));
|
|
45
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
-
var __await = function(promise, isYieldStar) {
|
|
47
|
-
this[0] = promise;
|
|
48
|
-
this[1] = isYieldStar;
|
|
49
|
-
};
|
|
50
|
-
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
51
|
-
var resume = (k, v, yes, no) => {
|
|
52
|
-
try {
|
|
53
|
-
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
54
|
-
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
55
|
-
} catch (e) {
|
|
56
|
-
no(e);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
var method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no));
|
|
60
|
-
var it = {};
|
|
61
|
-
return generator = generator.apply(__this, __arguments), it[Symbol.asyncIterator] = () => it, method("next"), method("throw"), method("return"), it;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// src/index.ts
|
|
65
|
-
var src_exports = {};
|
|
66
|
-
__export(src_exports, {
|
|
67
|
-
HttpMethods: () => HttpMethods,
|
|
68
|
-
HttpStatuses: () => HttpStatuses,
|
|
69
|
-
RequestBuilder: () => RequestBuilder,
|
|
70
|
-
RequestDataSource: () => RequestDataSource,
|
|
71
|
-
RequestHelper: () => RequestHelper
|
|
72
|
-
});
|
|
73
|
-
module.exports = __toCommonJS(src_exports);
|
|
74
|
-
|
|
75
|
-
// src/builder.ts
|
|
76
|
-
var import_qs = require("qs");
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/builder.ts
|
|
2
|
+
var _qs = require('qs');
|
|
77
3
|
|
|
78
4
|
// src/types.ts
|
|
79
5
|
var HttpMethods = /* @__PURE__ */ ((HttpMethods2) => {
|
|
@@ -99,39 +25,50 @@ var HttpStatuses = /* @__PURE__ */ ((HttpStatuses2) => {
|
|
|
99
25
|
|
|
100
26
|
// src/builder.ts
|
|
101
27
|
var RequestBuilder = class {
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
102
31
|
constructor(params) {
|
|
103
32
|
this.baseConfig = params.baseConfig;
|
|
104
33
|
this.requestConfig = params.requestConfig;
|
|
105
34
|
this.config = {
|
|
106
|
-
headers:
|
|
35
|
+
headers: {
|
|
107
36
|
Accept: "application/json",
|
|
108
|
-
"Content-Type": "application/json"
|
|
109
|
-
|
|
37
|
+
"Content-Type": "application/json",
|
|
38
|
+
...params.baseConfig.headers,
|
|
39
|
+
...params.requestConfig.headers
|
|
40
|
+
}
|
|
110
41
|
};
|
|
111
42
|
}
|
|
112
43
|
makeContentType() {
|
|
113
44
|
if (this.requestConfig.multipart) {
|
|
114
|
-
this.config =
|
|
115
|
-
|
|
45
|
+
this.config = {
|
|
46
|
+
...this.config,
|
|
47
|
+
headers: {
|
|
48
|
+
...this.config.headers,
|
|
116
49
|
"Content-Type": "multipart/form-data"
|
|
117
|
-
}
|
|
118
|
-
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
119
52
|
return this;
|
|
120
53
|
}
|
|
121
54
|
if (this.requestConfig.urlencoded) {
|
|
122
|
-
this.config =
|
|
123
|
-
|
|
55
|
+
this.config = {
|
|
56
|
+
...this.config,
|
|
57
|
+
headers: {
|
|
58
|
+
...this.config.headers,
|
|
124
59
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
125
|
-
}
|
|
126
|
-
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
127
62
|
return this;
|
|
128
63
|
}
|
|
129
64
|
if (this.requestConfig.xml) {
|
|
130
|
-
this.config =
|
|
131
|
-
|
|
65
|
+
this.config = {
|
|
66
|
+
...this.config,
|
|
67
|
+
headers: {
|
|
68
|
+
...this.config.headers,
|
|
132
69
|
"Content-Type": "text/xml"
|
|
133
|
-
}
|
|
134
|
-
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
135
72
|
return this;
|
|
136
73
|
}
|
|
137
74
|
return this;
|
|
@@ -139,27 +76,32 @@ var RequestBuilder = class {
|
|
|
139
76
|
makeAuth() {
|
|
140
77
|
const auth = this.requestConfig.auth || this.baseConfig.auth;
|
|
141
78
|
if (auth) {
|
|
142
|
-
this.config =
|
|
79
|
+
this.config = {
|
|
80
|
+
...this.config,
|
|
143
81
|
auth
|
|
144
|
-
}
|
|
82
|
+
};
|
|
145
83
|
return this;
|
|
146
84
|
}
|
|
147
85
|
const bearerToken = this.requestConfig.bearerToken || this.baseConfig.bearerToken;
|
|
148
86
|
if (bearerToken) {
|
|
149
|
-
this.config =
|
|
150
|
-
|
|
87
|
+
this.config = {
|
|
88
|
+
...this.config,
|
|
89
|
+
headers: {
|
|
90
|
+
...this.config.headers,
|
|
151
91
|
Authorization: `Bearer ${bearerToken}`
|
|
152
|
-
}
|
|
153
|
-
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
154
94
|
return this;
|
|
155
95
|
}
|
|
156
96
|
const apiKey = this.requestConfig.apiKey || this.baseConfig.apiKey;
|
|
157
97
|
if (apiKey) {
|
|
158
|
-
this.config =
|
|
159
|
-
|
|
98
|
+
this.config = {
|
|
99
|
+
...this.config,
|
|
100
|
+
headers: {
|
|
101
|
+
...this.config.headers,
|
|
160
102
|
"x-api-key": apiKey
|
|
161
|
-
}
|
|
162
|
-
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
163
105
|
return this;
|
|
164
106
|
}
|
|
165
107
|
return this;
|
|
@@ -174,24 +116,24 @@ var RequestBuilder = class {
|
|
|
174
116
|
this.requestConfig.baseUrl,
|
|
175
117
|
this.requestConfig.url,
|
|
176
118
|
...this.requestConfig.urlParts || []
|
|
177
|
-
].map((urlPart) => urlPart
|
|
178
|
-
const isSecureProtocol = urlParts.some(
|
|
179
|
-
(urlPart) => urlPart == null ? void 0 : urlPart.includes("https")
|
|
180
|
-
);
|
|
119
|
+
].map((urlPart) => _optionalChain([urlPart, 'optionalAccess', _2 => _2.toString, 'call', _3 => _3()]));
|
|
120
|
+
const isSecureProtocol = urlParts.some((urlPart) => _optionalChain([urlPart, 'optionalAccess', _4 => _4.includes, 'call', _5 => _5("https")]));
|
|
181
121
|
const protocol = isSecureProtocol ? "https" : "http";
|
|
182
122
|
const actualUrlParts = urlParts.filter((urlPart) => urlPart).map((urlPart) => {
|
|
183
|
-
return urlPart
|
|
123
|
+
return _optionalChain([urlPart, 'optionalAccess', _6 => _6.replace, 'call', _7 => _7(/^(https?:\/\/|\/)?(.*?)(\/?)$/, "$2")]);
|
|
184
124
|
});
|
|
185
125
|
const url = `${protocol}://${actualUrlParts.join("/")}`;
|
|
186
|
-
this.config =
|
|
126
|
+
this.config = {
|
|
127
|
+
...this.config,
|
|
187
128
|
url
|
|
188
|
-
}
|
|
129
|
+
};
|
|
189
130
|
return this;
|
|
190
131
|
}
|
|
191
132
|
makeMethod() {
|
|
192
|
-
this.config =
|
|
133
|
+
this.config = {
|
|
134
|
+
...this.config,
|
|
193
135
|
method: this.requestConfig.method
|
|
194
|
-
}
|
|
136
|
+
};
|
|
195
137
|
return this;
|
|
196
138
|
}
|
|
197
139
|
makeData() {
|
|
@@ -199,31 +141,34 @@ var RequestBuilder = class {
|
|
|
199
141
|
return this;
|
|
200
142
|
}
|
|
201
143
|
if (this.requestConfig.urlencoded) {
|
|
202
|
-
this.config =
|
|
203
|
-
|
|
204
|
-
|
|
144
|
+
this.config = {
|
|
145
|
+
...this.config,
|
|
146
|
+
data: _qs.stringify.call(void 0, this.requestConfig.data)
|
|
147
|
+
};
|
|
205
148
|
return this;
|
|
206
149
|
}
|
|
207
|
-
this.config =
|
|
150
|
+
this.config = {
|
|
151
|
+
...this.config,
|
|
208
152
|
data: this.requestConfig.data
|
|
209
|
-
}
|
|
153
|
+
};
|
|
210
154
|
return this;
|
|
211
155
|
}
|
|
212
156
|
makeParams() {
|
|
213
|
-
this.config =
|
|
157
|
+
this.config = {
|
|
158
|
+
...this.config,
|
|
214
159
|
params: this.requestConfig.params
|
|
215
|
-
}
|
|
160
|
+
};
|
|
216
161
|
return this;
|
|
217
162
|
}
|
|
218
163
|
makeSerializer() {
|
|
219
|
-
this.config =
|
|
164
|
+
this.config = {
|
|
165
|
+
...this.config,
|
|
220
166
|
paramsSerializer: (params) => {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
arrayFormat: (_a = this.baseConfig.serializer) == null ? void 0 : _a.array
|
|
167
|
+
return _qs.stringify.call(void 0, params, {
|
|
168
|
+
arrayFormat: _optionalChain([this, 'access', _8 => _8.baseConfig, 'access', _9 => _9.serializer, 'optionalAccess', _10 => _10.array])
|
|
224
169
|
});
|
|
225
170
|
}
|
|
226
|
-
}
|
|
171
|
+
};
|
|
227
172
|
return this;
|
|
228
173
|
}
|
|
229
174
|
build() {
|
|
@@ -232,248 +177,285 @@ var RequestBuilder = class {
|
|
|
232
177
|
};
|
|
233
178
|
|
|
234
179
|
// src/data-source.ts
|
|
235
|
-
var
|
|
180
|
+
var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
|
|
236
181
|
|
|
237
|
-
// src/logger/
|
|
238
|
-
|
|
239
|
-
var
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
delete params["0"];
|
|
251
|
-
return [url, (0, import_qs2.stringify)(params)].filter((_) => _).join("?");
|
|
252
|
-
} else {
|
|
253
|
-
return url;
|
|
182
|
+
// src/logger/builder.ts
|
|
183
|
+
|
|
184
|
+
var MessageBuilder = class {
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
constructor() {
|
|
190
|
+
this.printQueue = [];
|
|
191
|
+
}
|
|
192
|
+
setRequest(request) {
|
|
193
|
+
this.request = request;
|
|
194
|
+
return this;
|
|
254
195
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const method = ((_a = dto.request) == null ? void 0 : _a.method) || ((_c = (_b = dto.response) == null ? void 0 : _b.config) == null ? void 0 : _c.method) || ((_e = (_d = dto.error) == null ? void 0 : _d.response) == null ? void 0 : _e.config.method);
|
|
259
|
-
if (!method) {
|
|
260
|
-
return "get" /* GET */;
|
|
196
|
+
setResponse(response) {
|
|
197
|
+
this.response = response;
|
|
198
|
+
return this;
|
|
261
199
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
var _a, _b, _c, _d, _e;
|
|
266
|
-
const method = ((_a = dto.request) == null ? void 0 : _a.method) || ((_c = (_b = dto.response) == null ? void 0 : _b.config) == null ? void 0 : _c.method) || ((_e = (_d = dto.error) == null ? void 0 : _d.response) == null ? void 0 : _e.config.method);
|
|
267
|
-
if (!method) {
|
|
268
|
-
return "";
|
|
200
|
+
setError(error) {
|
|
201
|
+
this.error = error;
|
|
202
|
+
return this;
|
|
269
203
|
}
|
|
270
|
-
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
204
|
+
makeType(type) {
|
|
205
|
+
this.printQueue.push(`[${type}]`);
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
makeUrl() {
|
|
209
|
+
const url = _optionalChain([this, 'access', _11 => _11.request, 'optionalAccess', _12 => _12.url]) || _optionalChain([this, 'access', _13 => _13.response, 'optionalAccess', _14 => _14.config, 'optionalAccess', _15 => _15.url]) || _optionalChain([this, 'access', _16 => _16.error, 'optionalAccess', _17 => _17.response, 'optionalAccess', _18 => _18.config, 'access', _19 => _19.url]);
|
|
210
|
+
const params = _optionalChain([this, 'access', _20 => _20.request, 'optionalAccess', _21 => _21.params]) || _optionalChain([this, 'access', _22 => _22.response, 'optionalAccess', _23 => _23.config, 'optionalAccess', _24 => _24.params]) || _optionalChain([this, 'access', _25 => _25.error, 'optionalAccess', _26 => _26.response, 'optionalAccess', _27 => _27.config, 'access', _28 => _28.params]);
|
|
211
|
+
if (url) {
|
|
212
|
+
if (params) {
|
|
213
|
+
delete params["0"];
|
|
214
|
+
this.printQueue.push([url, _qs.stringify.call(void 0, params)].filter((_) => _).join("?"));
|
|
215
|
+
} else {
|
|
216
|
+
this.printQueue.push(url);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return this;
|
|
277
220
|
}
|
|
278
|
-
|
|
279
|
-
|
|
221
|
+
makeMethodText() {
|
|
222
|
+
const method = _optionalChain([this, 'access', _29 => _29.request, 'optionalAccess', _30 => _30.method]) || _optionalChain([this, 'access', _31 => _31.response, 'optionalAccess', _32 => _32.config, 'optionalAccess', _33 => _33.method]) || _optionalChain([this, 'access', _34 => _34.error, 'optionalAccess', _35 => _35.response, 'optionalAccess', _36 => _36.config, 'access', _37 => _37.method]);
|
|
223
|
+
if (method) {
|
|
224
|
+
this.printQueue.push(method.toUpperCase());
|
|
225
|
+
}
|
|
226
|
+
return this;
|
|
280
227
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
228
|
+
makeRequestData() {
|
|
229
|
+
const data = _optionalChain([this, 'access', _38 => _38.request, 'optionalAccess', _39 => _39.data]) || _optionalChain([this, 'access', _40 => _40.response, 'optionalAccess', _41 => _41.config, 'optionalAccess', _42 => _42.data]) || _optionalChain([this, 'access', _43 => _43.error, 'optionalAccess', _44 => _44.response, 'optionalAccess', _45 => _45.config, 'access', _46 => _46.data]);
|
|
230
|
+
if (data) {
|
|
231
|
+
if (typeof data === "string") {
|
|
232
|
+
this.printQueue.push(data);
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
if (Object.keys(data).length) {
|
|
236
|
+
this.printQueue.push(JSON.stringify(data));
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return this;
|
|
288
241
|
}
|
|
289
|
-
|
|
290
|
-
|
|
242
|
+
makeResponseDataText() {
|
|
243
|
+
const data = _optionalChain([this, 'access', _47 => _47.response, 'optionalAccess', _48 => _48.data]) || _optionalChain([this, 'access', _49 => _49.error, 'optionalAccess', _50 => _50.response, 'optionalAccess', _51 => _51.data]);
|
|
244
|
+
if (data) {
|
|
245
|
+
if (typeof data === "string") {
|
|
246
|
+
this.printQueue.push(data);
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
if (Object.keys(data).length) {
|
|
250
|
+
this.printQueue.push(JSON.stringify(data));
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return this;
|
|
291
255
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
256
|
+
makeStatusText() {
|
|
257
|
+
const status = _optionalChain([this, 'access', _52 => _52.response, 'optionalAccess', _53 => _53.status]) || _optionalChain([this, 'access', _54 => _54.error, 'optionalAccess', _55 => _55.response, 'optionalAccess', _56 => _56.status]);
|
|
258
|
+
if (status) {
|
|
259
|
+
this.printQueue.push(`${status}`);
|
|
260
|
+
const statusText = _optionalChain([this, 'access', _57 => _57.response, 'optionalAccess', _58 => _58.statusText]) || _optionalChain([this, 'access', _59 => _59.error, 'optionalAccess', _60 => _60.response, 'optionalAccess', _61 => _61.statusText]);
|
|
261
|
+
if (statusText) {
|
|
262
|
+
this.printQueue.push(statusText);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return this;
|
|
299
266
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
var makeStatusText = (dto = {}) => {
|
|
303
|
-
var _a, _b, _c, _d, _e, _f;
|
|
304
|
-
const status = ((_a = dto.response) == null ? void 0 : _a.status) || ((_c = (_b = dto.error) == null ? void 0 : _b.response) == null ? void 0 : _c.status);
|
|
305
|
-
if (!status) {
|
|
306
|
-
return "";
|
|
267
|
+
build() {
|
|
268
|
+
return this.printQueue.join(" ");
|
|
307
269
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
270
|
+
makeMethod() {
|
|
271
|
+
const method = _optionalChain([this, 'access', _62 => _62.request, 'optionalAccess', _63 => _63.method]) || _optionalChain([this, 'access', _64 => _64.response, 'optionalAccess', _65 => _65.config, 'optionalAccess', _66 => _66.method]) || _optionalChain([this, 'access', _67 => _67.error, 'optionalAccess', _68 => _68.response, 'optionalAccess', _69 => _69.config, 'access', _70 => _70.method]);
|
|
272
|
+
if (!method) {
|
|
273
|
+
return "get" /* GET */;
|
|
274
|
+
}
|
|
275
|
+
return method.toLowerCase();
|
|
276
|
+
}
|
|
277
|
+
makeResponseData() {
|
|
278
|
+
const data = _optionalChain([this, 'access', _71 => _71.response, 'optionalAccess', _72 => _72.data]) || _optionalChain([this, 'access', _73 => _73.error, 'optionalAccess', _74 => _74.response, 'optionalAccess', _75 => _75.data]);
|
|
279
|
+
if (!data) {
|
|
280
|
+
return "";
|
|
281
|
+
}
|
|
282
|
+
if (typeof data === "string") {
|
|
283
|
+
return data;
|
|
284
|
+
}
|
|
285
|
+
return JSON.stringify(data);
|
|
286
|
+
}
|
|
287
|
+
makeStatus() {
|
|
288
|
+
const status = _optionalChain([this, 'access', _76 => _76.response, 'optionalAccess', _77 => _77.status]) || _optionalChain([this, 'access', _78 => _78.error, 'optionalAccess', _79 => _79.response, 'optionalAccess', _80 => _80.status]);
|
|
289
|
+
if (!status) {
|
|
290
|
+
return 500 /* INTERNAL_SERVER_ERROR */;
|
|
291
|
+
}
|
|
292
|
+
return status;
|
|
293
|
+
}
|
|
294
|
+
makeResponse() {
|
|
295
|
+
return {
|
|
296
|
+
success: this.error === void 0,
|
|
297
|
+
status: this.makeStatus(),
|
|
298
|
+
method: this.makeMethod(),
|
|
299
|
+
data: this.makeResponseData()
|
|
300
|
+
};
|
|
311
301
|
}
|
|
312
|
-
return `${status}`;
|
|
313
|
-
};
|
|
314
|
-
var makeResponse = (dto = {}) => {
|
|
315
|
-
return {
|
|
316
|
-
success: dto.error === void 0,
|
|
317
|
-
status: makeStatus(dto),
|
|
318
|
-
method: makeMethod(dto),
|
|
319
|
-
data: makeResponseData(dto)
|
|
320
|
-
};
|
|
321
|
-
};
|
|
322
|
-
var logRequest = (request) => {
|
|
323
|
-
log([
|
|
324
|
-
makeType("Request"),
|
|
325
|
-
makeMethodText({ request }),
|
|
326
|
-
makeUrl({ request }),
|
|
327
|
-
makeRequestData({ request })
|
|
328
|
-
]);
|
|
329
|
-
};
|
|
330
|
-
var logResponse = (response) => {
|
|
331
|
-
log([
|
|
332
|
-
makeType("Response"),
|
|
333
|
-
makeMethodText({ response }),
|
|
334
|
-
makeUrl({ response }),
|
|
335
|
-
makeRequestData({ response }),
|
|
336
|
-
makeStatusText({ response }),
|
|
337
|
-
makeResponseData({ response })
|
|
338
|
-
]);
|
|
339
|
-
};
|
|
340
|
-
var logRequestError = (error) => {
|
|
341
|
-
log([
|
|
342
|
-
makeType("Error"),
|
|
343
|
-
makeMethodText({ error }),
|
|
344
|
-
makeUrl({ error }),
|
|
345
|
-
makeRequestData({ error }),
|
|
346
|
-
makeStatusText({ error }),
|
|
347
|
-
makeResponseData({ error })
|
|
348
|
-
]);
|
|
349
|
-
};
|
|
350
|
-
var log = (messageParts) => {
|
|
351
|
-
const message = messageParts.filter((_) => _).join(" ");
|
|
352
|
-
console.log(message);
|
|
353
|
-
};
|
|
354
|
-
var loggerHelper = {
|
|
355
|
-
makeType,
|
|
356
|
-
makeUrl,
|
|
357
|
-
makeMethod,
|
|
358
|
-
makeMethodText,
|
|
359
|
-
makeRequestData,
|
|
360
|
-
makeResponseData,
|
|
361
|
-
makeStatus,
|
|
362
|
-
makeStatusText,
|
|
363
|
-
makeResponse,
|
|
364
|
-
logRequest,
|
|
365
|
-
logResponse,
|
|
366
|
-
logRequestError
|
|
367
302
|
};
|
|
368
303
|
|
|
304
|
+
// src/logger/service.ts
|
|
305
|
+
var LoggerService = (_class = class {
|
|
306
|
+
__init() {this.context = ""}
|
|
307
|
+
constructor(context = "") {;_class.prototype.__init.call(this);
|
|
308
|
+
this.context = context;
|
|
309
|
+
}
|
|
310
|
+
log(message, context) {
|
|
311
|
+
const ctx = context || this.context || "";
|
|
312
|
+
if (ctx) {
|
|
313
|
+
return console.log(`[${ctx}] ${message}`);
|
|
314
|
+
}
|
|
315
|
+
return console.log(message);
|
|
316
|
+
}
|
|
317
|
+
logRequest(request) {
|
|
318
|
+
const loggerMessageBuilder = new MessageBuilder();
|
|
319
|
+
const message = loggerMessageBuilder.setRequest(request).makeType("Request").makeMethodText().makeUrl().makeRequestData().build();
|
|
320
|
+
return this.log(message);
|
|
321
|
+
}
|
|
322
|
+
logResponse(response) {
|
|
323
|
+
const loggerMessageBuilder = new MessageBuilder();
|
|
324
|
+
const message = loggerMessageBuilder.setResponse(response).makeType("Response").makeMethodText().makeUrl().makeRequestData().makeStatusText().makeResponseDataText().build();
|
|
325
|
+
return this.log(message);
|
|
326
|
+
}
|
|
327
|
+
logRequestError(error) {
|
|
328
|
+
const loggerMessageBuilder = new MessageBuilder();
|
|
329
|
+
const message = loggerMessageBuilder.setError(error).makeType("Error").makeMethodText().makeUrl().makeRequestData().makeStatusText().makeResponseDataText().build();
|
|
330
|
+
return this.log(message);
|
|
331
|
+
}
|
|
332
|
+
makeResponse(response) {
|
|
333
|
+
const loggerMessageBuilder = new MessageBuilder();
|
|
334
|
+
const responseData = loggerMessageBuilder.setResponse(response).makeResponse();
|
|
335
|
+
return responseData;
|
|
336
|
+
}
|
|
337
|
+
makeErrorResponse(error) {
|
|
338
|
+
const loggerMessageBuilder = new MessageBuilder();
|
|
339
|
+
const errorResponseData = loggerMessageBuilder.setError(error).makeResponse();
|
|
340
|
+
return errorResponseData;
|
|
341
|
+
}
|
|
342
|
+
}, _class);
|
|
343
|
+
|
|
369
344
|
// src/data-source.ts
|
|
370
345
|
var RequestDataSource = class {
|
|
346
|
+
|
|
371
347
|
constructor(baseRequestConfig) {
|
|
372
348
|
this.baseRequestConfig = baseRequestConfig;
|
|
373
349
|
}
|
|
374
350
|
common(requestConfig, responseConfig = {}) {
|
|
351
|
+
const loggerService = new LoggerService(this.baseRequestConfig.name);
|
|
375
352
|
const requestBuilder = new RequestBuilder({
|
|
376
353
|
baseConfig: this.baseRequestConfig,
|
|
377
354
|
requestConfig
|
|
378
355
|
});
|
|
379
356
|
const request = requestBuilder.makeContentType().makeAuth().makeUrl().makeMethod().makeParams().makeData().makeSerializer().build();
|
|
380
357
|
if (this.baseRequestConfig.logger) {
|
|
381
|
-
|
|
358
|
+
loggerService.logRequest(request);
|
|
382
359
|
}
|
|
383
|
-
return
|
|
360
|
+
return _axios2.default.request(request).then((response) => {
|
|
384
361
|
if (this.baseRequestConfig.logger) {
|
|
385
|
-
|
|
362
|
+
loggerService.logResponse(response);
|
|
386
363
|
}
|
|
387
364
|
if (responseConfig.raw) {
|
|
388
|
-
return
|
|
365
|
+
return loggerService.makeResponse(response);
|
|
389
366
|
}
|
|
390
367
|
return response.data;
|
|
391
368
|
}).catch((error) => {
|
|
392
|
-
var _a;
|
|
393
369
|
if (this.baseRequestConfig.debug) {
|
|
394
370
|
console.log("Error:", error);
|
|
395
371
|
}
|
|
396
372
|
if (this.baseRequestConfig.logger) {
|
|
397
|
-
|
|
373
|
+
loggerService.logRequestError(error);
|
|
398
374
|
}
|
|
399
375
|
if (responseConfig.raw) {
|
|
400
|
-
return
|
|
376
|
+
return loggerService.makeErrorResponse(error);
|
|
401
377
|
}
|
|
402
|
-
throw (
|
|
378
|
+
throw _optionalChain([error, 'access', _81 => _81.response, 'optionalAccess', _82 => _82.data]) || error.response || new Error(error.message);
|
|
403
379
|
});
|
|
404
380
|
}
|
|
405
381
|
search(config = {}) {
|
|
406
|
-
return this.common(
|
|
382
|
+
return this.common({
|
|
383
|
+
...config,
|
|
407
384
|
method: "get" /* GET */
|
|
408
|
-
}));
|
|
409
|
-
}
|
|
410
|
-
bulkSearch() {
|
|
411
|
-
return __asyncGenerator(this, arguments, function* (config = {}) {
|
|
412
|
-
var _a, _b, _c;
|
|
413
|
-
let pagination = {
|
|
414
|
-
total: 0,
|
|
415
|
-
currentPage: ((_a = config.params) == null ? void 0 : _a.page) || 0,
|
|
416
|
-
lastPage: 0,
|
|
417
|
-
from: 0,
|
|
418
|
-
to: 0,
|
|
419
|
-
pageSize: ((_b = config.params) == null ? void 0 : _b.pageSize) || 30
|
|
420
|
-
};
|
|
421
|
-
do {
|
|
422
|
-
const response = yield new __await(this.common(__spreadProps(__spreadValues({}, config), {
|
|
423
|
-
method: "get" /* GET */,
|
|
424
|
-
params: __spreadProps(__spreadValues({}, config.params), {
|
|
425
|
-
page: pagination.currentPage + 1,
|
|
426
|
-
pageSize: pagination.pageSize
|
|
427
|
-
})
|
|
428
|
-
})));
|
|
429
|
-
if (!((_c = response.data) == null ? void 0 : _c.length)) {
|
|
430
|
-
return [];
|
|
431
|
-
}
|
|
432
|
-
yield response.data;
|
|
433
|
-
pagination = response.pagination;
|
|
434
|
-
} while (pagination.currentPage !== pagination.lastPage);
|
|
435
385
|
});
|
|
436
386
|
}
|
|
387
|
+
async *bulkSearch(config = {}) {
|
|
388
|
+
let pagination = {
|
|
389
|
+
total: 0,
|
|
390
|
+
currentPage: _optionalChain([config, 'access', _83 => _83.params, 'optionalAccess', _84 => _84.page]) || 0,
|
|
391
|
+
lastPage: 0,
|
|
392
|
+
from: 0,
|
|
393
|
+
to: 0,
|
|
394
|
+
pageSize: _optionalChain([config, 'access', _85 => _85.params, 'optionalAccess', _86 => _86.pageSize]) || 30
|
|
395
|
+
};
|
|
396
|
+
do {
|
|
397
|
+
const response = await this.common({
|
|
398
|
+
...config,
|
|
399
|
+
method: "get" /* GET */,
|
|
400
|
+
params: {
|
|
401
|
+
...config.params,
|
|
402
|
+
page: pagination.currentPage + 1,
|
|
403
|
+
pageSize: pagination.pageSize
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
if (!_optionalChain([response, 'access', _87 => _87.data, 'optionalAccess', _88 => _88.length])) {
|
|
407
|
+
return [];
|
|
408
|
+
}
|
|
409
|
+
yield response.data;
|
|
410
|
+
pagination = response.pagination;
|
|
411
|
+
} while (pagination.currentPage !== pagination.lastPage);
|
|
412
|
+
}
|
|
437
413
|
get(id, config = {}) {
|
|
438
|
-
return this.common(
|
|
414
|
+
return this.common({
|
|
415
|
+
...config,
|
|
439
416
|
method: "get" /* GET */,
|
|
440
417
|
url: id
|
|
441
|
-
})
|
|
418
|
+
});
|
|
442
419
|
}
|
|
443
420
|
create(config) {
|
|
444
|
-
return this.common(
|
|
421
|
+
return this.common({
|
|
422
|
+
...config,
|
|
445
423
|
method: "post" /* POST */
|
|
446
|
-
})
|
|
424
|
+
});
|
|
447
425
|
}
|
|
448
426
|
bulkCreate(config) {
|
|
449
|
-
return this.common(
|
|
427
|
+
return this.common({
|
|
428
|
+
...config,
|
|
450
429
|
method: "post" /* POST */,
|
|
451
430
|
url: "/bulk",
|
|
452
431
|
data: {
|
|
453
432
|
bulk: config.data
|
|
454
433
|
}
|
|
455
|
-
})
|
|
434
|
+
});
|
|
456
435
|
}
|
|
457
436
|
update(id, config) {
|
|
458
|
-
return this.common(
|
|
437
|
+
return this.common({
|
|
438
|
+
...config,
|
|
459
439
|
method: "put" /* PUT */,
|
|
460
440
|
url: id
|
|
461
|
-
})
|
|
441
|
+
});
|
|
462
442
|
}
|
|
463
443
|
bulkUpdate(config) {
|
|
464
|
-
return this.common(
|
|
444
|
+
return this.common({
|
|
445
|
+
...config,
|
|
465
446
|
method: "put" /* PUT */,
|
|
466
447
|
url: "/bulk",
|
|
467
448
|
data: {
|
|
468
449
|
bulk: config.data
|
|
469
450
|
}
|
|
470
|
-
})
|
|
451
|
+
});
|
|
471
452
|
}
|
|
472
453
|
remove(id, config = {}) {
|
|
473
|
-
return this.common(
|
|
454
|
+
return this.common({
|
|
455
|
+
...config,
|
|
474
456
|
method: "delete" /* DELETE */,
|
|
475
457
|
url: id
|
|
476
|
-
})
|
|
458
|
+
});
|
|
477
459
|
}
|
|
478
460
|
};
|
|
479
461
|
|
|
@@ -485,12 +467,11 @@ var RequestHelper = class {
|
|
|
485
467
|
});
|
|
486
468
|
}
|
|
487
469
|
};
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
});
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
exports.HttpMethods = HttpMethods; exports.HttpStatuses = HttpStatuses; exports.RequestBuilder = RequestBuilder; exports.RequestDataSource = RequestDataSource; exports.RequestHelper = RequestHelper;
|
|
496
477
|
//# sourceMappingURL=index.js.map
|