@bbn/bbn 1.0.342 → 1.0.344
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/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/fn/ajax/ajax.js +86 -40
- package/package.json +1 -1
package/dist/fn/ajax/ajax.js
CHANGED
|
@@ -34,12 +34,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
import isObject from '../type/isObject.js';
|
|
38
37
|
import replaceAll from '../string/replaceAll.js';
|
|
39
38
|
import getRequestId from './getRequestId.js';
|
|
40
39
|
import getLoader from './getLoader.js';
|
|
41
40
|
import extend from '../object/extend.js';
|
|
42
|
-
import numProperties from '../object/numProperties.js';
|
|
43
41
|
import _deleteLoader from './_deleteLoader.js';
|
|
44
42
|
import isFunction from '../type/isFunction.js';
|
|
45
43
|
import _addLoader from './_addLoader.js';
|
|
@@ -105,29 +103,33 @@ export default function ajax() {
|
|
|
105
103
|
args[_i] = arguments[_i];
|
|
106
104
|
}
|
|
107
105
|
return __awaiter(this, void 0, void 0, function () {
|
|
108
|
-
var url, datatype, data, success, failure, abort, requestId_1, loaderObj, aborter,
|
|
106
|
+
var url, datatype, data, success, failure, abort, method, requestId_1, loaderObj, aborter, contentType_1, options, loader_1, tst_1;
|
|
109
107
|
return __generator(this, function (_a) {
|
|
110
108
|
datatype = null;
|
|
111
109
|
data = null;
|
|
112
110
|
success = null;
|
|
113
111
|
failure = null;
|
|
114
112
|
abort = null;
|
|
113
|
+
method = null;
|
|
115
114
|
if (args.length === 1 && args[0] && (typeof args[0] === "object") && args[0].url) {
|
|
116
115
|
url = args[0].url;
|
|
117
|
-
if (args[0].
|
|
118
|
-
|
|
116
|
+
if (args[0].datatype) {
|
|
117
|
+
datatype = args[0].datatype;
|
|
119
118
|
}
|
|
120
|
-
if (args[0].
|
|
121
|
-
|
|
119
|
+
if (args[0].data) {
|
|
120
|
+
data = args[0].data;
|
|
122
121
|
}
|
|
123
122
|
if (args[0].success) {
|
|
124
123
|
success = args[0].success;
|
|
125
124
|
}
|
|
126
|
-
if (args[0].
|
|
127
|
-
|
|
125
|
+
if (args[0].failure) {
|
|
126
|
+
failure = args[0].failure;
|
|
128
127
|
}
|
|
129
|
-
if (args[0].
|
|
130
|
-
|
|
128
|
+
if (args[0].abort) {
|
|
129
|
+
abort = args[0].abort;
|
|
130
|
+
}
|
|
131
|
+
if (args[0].method) {
|
|
132
|
+
method = args[0].method;
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
135
|
else {
|
|
@@ -149,6 +151,9 @@ export default function ajax() {
|
|
|
149
151
|
if (args.length > 5) {
|
|
150
152
|
abort = args[5];
|
|
151
153
|
}
|
|
154
|
+
if (args.length > 6) {
|
|
155
|
+
method = args[6];
|
|
156
|
+
}
|
|
152
157
|
}
|
|
153
158
|
if (typeof url === "string") {
|
|
154
159
|
if (url.indexOf("://") === -1) {
|
|
@@ -163,43 +168,84 @@ export default function ajax() {
|
|
|
163
168
|
if (loaderObj === null || loaderObj === void 0 ? void 0 : loaderObj.loader) {
|
|
164
169
|
return [2 /*return*/, loaderObj.loader];
|
|
165
170
|
}
|
|
166
|
-
if (bbn.env.token) {
|
|
167
|
-
|
|
171
|
+
if (bbn.env.token && bbn.fn.numProperties(data)) {
|
|
172
|
+
data = extend({}, data, { _bbn_token: bbn.env.token });
|
|
173
|
+
if (!method) {
|
|
174
|
+
method = "POST";
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else if (!method) {
|
|
178
|
+
method = "GET";
|
|
168
179
|
}
|
|
169
180
|
aborter = new AbortController();
|
|
181
|
+
contentType_1 = "application/json";
|
|
182
|
+
if (datatype === "json") {
|
|
183
|
+
contentType_1 = "application/json";
|
|
184
|
+
}
|
|
185
|
+
else if (datatype === "text") {
|
|
186
|
+
contentType_1 = "text/javascript";
|
|
187
|
+
}
|
|
188
|
+
else if (datatype === "html") {
|
|
189
|
+
contentType_1 = "text/html";
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
contentType_1 = datatype;
|
|
193
|
+
}
|
|
170
194
|
options = {
|
|
195
|
+
method: method,
|
|
171
196
|
responseType: datatype,
|
|
172
|
-
signal: aborter.signal
|
|
197
|
+
signal: aborter.signal,
|
|
198
|
+
mode: 'cors', // no-cors, *cors, same-origin
|
|
199
|
+
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
|
|
200
|
+
credentials: 'same-origin', // include, *same-origin, omit
|
|
201
|
+
redirect: 'follow', // manual, *follow, error
|
|
202
|
+
referrerPolicy: 'no-referrer', // no-referrer, *client
|
|
203
|
+
headers: {
|
|
204
|
+
'Content-Type': contentType_1,
|
|
205
|
+
}
|
|
173
206
|
};
|
|
174
|
-
if (
|
|
175
|
-
options
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
args_1 = [url];
|
|
181
|
-
if (isObject(data) && numProperties(data) > 0) {
|
|
182
|
-
args_1.push(data);
|
|
183
|
-
}
|
|
184
|
-
args_1.push(options);
|
|
185
|
-
axiosMethod = args_1.length === 2 ? "get" : "post";
|
|
186
|
-
loader_1 = axios[axiosMethod]
|
|
187
|
-
.apply(null, args_1)
|
|
188
|
-
.then(function (res) {
|
|
207
|
+
if (data && bbn.fn.numProperties(data)) {
|
|
208
|
+
options.body = JSON.stringify(data);
|
|
209
|
+
}
|
|
210
|
+
loader_1 = fetch(url, options).then(function (res) {
|
|
189
211
|
_deleteLoader(requestId_1, res);
|
|
190
212
|
bbn.fn.defaultEndLoadingFunction(url, tst_1, data, res);
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
213
|
+
if (res.ok) {
|
|
214
|
+
switch (res.status) {
|
|
215
|
+
case 200:
|
|
216
|
+
var stream = void 0;
|
|
217
|
+
switch (contentType_1) {
|
|
218
|
+
case "application/json":
|
|
219
|
+
if (datatype === "json") {
|
|
220
|
+
stream = res.json();
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
223
|
+
case "text/javascript":
|
|
224
|
+
if (datatype === "text") {
|
|
225
|
+
stream = res.text();
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
case "text/html":
|
|
229
|
+
if (datatype === "html") {
|
|
230
|
+
stream = res.text();
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
default:
|
|
234
|
+
stream = res.blob();
|
|
235
|
+
}
|
|
236
|
+
stream.then(function (d) {
|
|
237
|
+
if (isFunction(success)) {
|
|
238
|
+
bbn.fn.log(["THERE US A SUCCESS FUNCTION", res, loader_1]);
|
|
239
|
+
success(d, res.headers);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
break;
|
|
243
|
+
default:
|
|
244
|
+
//bbn.fn.log(["THIS IS THE DEFAULT FUNCTION", res, loader]);
|
|
245
|
+
bbn.fn.defaultAjaxErrorFunction(loader_1, res);
|
|
246
|
+
}
|
|
247
|
+
return res;
|
|
201
248
|
}
|
|
202
|
-
return res;
|
|
203
249
|
})
|
|
204
250
|
.catch(function (err) {
|
|
205
251
|
var isAbort = axios.isCancel(err);
|