@driveflux/api-swr 4.0.87 → 4.0.88
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/api-legacy/index.js +380 -100
- package/dist/api-models.js +4 -7
- package/dist/fetcher.js +260 -30
- package/dist/index.js +122 -36
- package/dist/utils.js +97 -13
- package/package.json +3 -3
package/dist/api-legacy/index.js
CHANGED
|
@@ -1,3 +1,225 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _async_to_generator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
+
}
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _define_property(obj, key, value) {
|
|
39
|
+
if (key in obj) {
|
|
40
|
+
Object.defineProperty(obj, key, {
|
|
41
|
+
value: value,
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
obj[key] = value;
|
|
48
|
+
}
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
function _iterable_to_array_limit(arr, i) {
|
|
52
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
53
|
+
if (_i == null) return;
|
|
54
|
+
var _arr = [];
|
|
55
|
+
var _n = true;
|
|
56
|
+
var _d = false;
|
|
57
|
+
var _s, _e;
|
|
58
|
+
try {
|
|
59
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
60
|
+
_arr.push(_s.value);
|
|
61
|
+
if (i && _arr.length === i) break;
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
_d = true;
|
|
65
|
+
_e = err;
|
|
66
|
+
} finally{
|
|
67
|
+
try {
|
|
68
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
69
|
+
} finally{
|
|
70
|
+
if (_d) throw _e;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return _arr;
|
|
74
|
+
}
|
|
75
|
+
function _non_iterable_rest() {
|
|
76
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
77
|
+
}
|
|
78
|
+
function _object_spread(target) {
|
|
79
|
+
for(var i = 1; i < arguments.length; i++){
|
|
80
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
81
|
+
var ownKeys = Object.keys(source);
|
|
82
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
83
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
84
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
ownKeys.forEach(function(key) {
|
|
88
|
+
_define_property(target, key, source[key]);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return target;
|
|
92
|
+
}
|
|
93
|
+
function ownKeys(object, enumerableOnly) {
|
|
94
|
+
var keys = Object.keys(object);
|
|
95
|
+
if (Object.getOwnPropertySymbols) {
|
|
96
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
97
|
+
if (enumerableOnly) {
|
|
98
|
+
symbols = symbols.filter(function(sym) {
|
|
99
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
keys.push.apply(keys, symbols);
|
|
103
|
+
}
|
|
104
|
+
return keys;
|
|
105
|
+
}
|
|
106
|
+
function _object_spread_props(target, source) {
|
|
107
|
+
source = source != null ? source : {};
|
|
108
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
109
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
110
|
+
} else {
|
|
111
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
112
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return target;
|
|
116
|
+
}
|
|
117
|
+
function _sliced_to_array(arr, i) {
|
|
118
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
119
|
+
}
|
|
120
|
+
function _type_of(obj) {
|
|
121
|
+
"@swc/helpers - typeof";
|
|
122
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
123
|
+
}
|
|
124
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
125
|
+
if (!o) return;
|
|
126
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
127
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
128
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
129
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
130
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
131
|
+
}
|
|
132
|
+
function _ts_generator(thisArg, body) {
|
|
133
|
+
var f, y, t, _ = {
|
|
134
|
+
label: 0,
|
|
135
|
+
sent: function() {
|
|
136
|
+
if (t[0] & 1) throw t[1];
|
|
137
|
+
return t[1];
|
|
138
|
+
},
|
|
139
|
+
trys: [],
|
|
140
|
+
ops: []
|
|
141
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
142
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
143
|
+
return this;
|
|
144
|
+
}), g;
|
|
145
|
+
function verb(n) {
|
|
146
|
+
return function(v) {
|
|
147
|
+
return step([
|
|
148
|
+
n,
|
|
149
|
+
v
|
|
150
|
+
]);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function step(op) {
|
|
154
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
155
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
156
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
157
|
+
if (y = 0, t) op = [
|
|
158
|
+
op[0] & 2,
|
|
159
|
+
t.value
|
|
160
|
+
];
|
|
161
|
+
switch(op[0]){
|
|
162
|
+
case 0:
|
|
163
|
+
case 1:
|
|
164
|
+
t = op;
|
|
165
|
+
break;
|
|
166
|
+
case 4:
|
|
167
|
+
_.label++;
|
|
168
|
+
return {
|
|
169
|
+
value: op[1],
|
|
170
|
+
done: false
|
|
171
|
+
};
|
|
172
|
+
case 5:
|
|
173
|
+
_.label++;
|
|
174
|
+
y = op[1];
|
|
175
|
+
op = [
|
|
176
|
+
0
|
|
177
|
+
];
|
|
178
|
+
continue;
|
|
179
|
+
case 7:
|
|
180
|
+
op = _.ops.pop();
|
|
181
|
+
_.trys.pop();
|
|
182
|
+
continue;
|
|
183
|
+
default:
|
|
184
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
185
|
+
_ = 0;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
189
|
+
_.label = op[1];
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
193
|
+
_.label = t[1];
|
|
194
|
+
t = op;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
if (t && _.label < t[2]) {
|
|
198
|
+
_.label = t[2];
|
|
199
|
+
_.ops.push(op);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
if (t[2]) _.ops.pop();
|
|
203
|
+
_.trys.pop();
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
op = body.call(thisArg, _);
|
|
207
|
+
} catch (e) {
|
|
208
|
+
op = [
|
|
209
|
+
6,
|
|
210
|
+
e
|
|
211
|
+
];
|
|
212
|
+
y = 0;
|
|
213
|
+
} finally{
|
|
214
|
+
f = t = 0;
|
|
215
|
+
}
|
|
216
|
+
if (op[0] & 5) throw op[1];
|
|
217
|
+
return {
|
|
218
|
+
value: op[0] ? op[1] : void 0,
|
|
219
|
+
done: true
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
1
223
|
import { useAuth } from '@driveflux/auth/react/providers';
|
|
2
224
|
import { config } from '@driveflux/config/frontend';
|
|
3
225
|
import { enhancedFetch } from '@driveflux/fetch';
|
|
@@ -9,124 +231,182 @@ import useSWRInfinite from 'swr/infinite';
|
|
|
9
231
|
*
|
|
10
232
|
* @important instead of returning a result, this will always return Success or throw an error containing Error
|
|
11
233
|
* @important if the 3rd param provides an Authorization header, it will be ignored!
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
234
|
+
*/ export var fetchWithAuth = function(urlParams) {
|
|
235
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
236
|
+
return _async_to_generator(function() {
|
|
237
|
+
var _result_metadata, _ref, url, accessToken, otherOptions, apiHost, finalUrl, correlationIdFromSessionStorage, result, correlationId, _result_metadata1;
|
|
238
|
+
return _ts_generator(this, function(_state) {
|
|
239
|
+
switch(_state.label){
|
|
240
|
+
case 0:
|
|
241
|
+
_ref = _sliced_to_array(Array.isArray(urlParams) ? urlParams : [
|
|
242
|
+
urlParams,
|
|
243
|
+
null
|
|
244
|
+
], 3), url = _ref[0], accessToken = _ref[1], otherOptions = _ref[2];
|
|
245
|
+
apiHost = config.appUrl;
|
|
246
|
+
finalUrl = url.startsWith('/') ? "".concat(apiHost).concat(url) : url;
|
|
247
|
+
correlationIdFromSessionStorage = typeof sessionStorage !== 'undefined' ? sessionStorage.getItem('x-correlation-id') : null;
|
|
248
|
+
return [
|
|
249
|
+
4,
|
|
250
|
+
enhancedFetch(finalUrl, _object_spread_props(_object_spread({}, options, otherOptions), {
|
|
251
|
+
headers: _object_spread({}, options.headers || {}, (otherOptions === null || otherOptions === void 0 ? void 0 : otherOptions.headers) || {}, accessToken ? {
|
|
252
|
+
Authorization: "Bearer ".concat(accessToken)
|
|
253
|
+
} : {}, correlationIdFromSessionStorage ? {
|
|
254
|
+
'x-correlation-id': correlationIdFromSessionStorage
|
|
255
|
+
} : {})
|
|
256
|
+
}))
|
|
257
|
+
];
|
|
258
|
+
case 1:
|
|
259
|
+
result = _state.sent();
|
|
260
|
+
correlationId = (_result_metadata = result.metadata) === null || _result_metadata === void 0 ? void 0 : _result_metadata.headers.get('x-correlation-id');
|
|
261
|
+
if (correlationId && typeof sessionStorage !== 'undefined') {
|
|
262
|
+
;
|
|
263
|
+
// We store the correlation id in the session storage so that we can use it in the next request
|
|
264
|
+
sessionStorage.setItem('x-correlation-id', ((_result_metadata1 = result.metadata) === null || _result_metadata1 === void 0 ? void 0 : _result_metadata1.headers.get('x-correlation-id')) || '');
|
|
265
|
+
}
|
|
266
|
+
if (!result.ok) {
|
|
267
|
+
throw result.val;
|
|
268
|
+
}
|
|
269
|
+
return [
|
|
270
|
+
2,
|
|
271
|
+
result.val
|
|
272
|
+
];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
})();
|
|
43
276
|
};
|
|
44
|
-
export
|
|
45
|
-
return obj && typeof obj === 'object' && obj.metadata;
|
|
277
|
+
export var isStructuredResponse = function(obj) {
|
|
278
|
+
return obj && (typeof obj === "undefined" ? "undefined" : _type_of(obj)) === 'object' && obj.metadata;
|
|
46
279
|
};
|
|
47
|
-
export
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
280
|
+
export var swrFetch = function(url) {
|
|
281
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
282
|
+
return _async_to_generator(function() {
|
|
283
|
+
var _response_metadata, correlationIdFromSessionStorage, response, correlationId, _response_metadata1;
|
|
284
|
+
return _ts_generator(this, function(_state) {
|
|
285
|
+
switch(_state.label){
|
|
286
|
+
case 0:
|
|
287
|
+
correlationIdFromSessionStorage = typeof sessionStorage !== 'undefined' ? sessionStorage.getItem('x-correlation-id') : null;
|
|
288
|
+
return [
|
|
289
|
+
4,
|
|
290
|
+
enhancedFetch(url, _object_spread_props(_object_spread({}, options), {
|
|
291
|
+
headers: _object_spread({}, options.headers || {}, correlationIdFromSessionStorage ? {
|
|
292
|
+
'x-correlation-id': correlationIdFromSessionStorage
|
|
293
|
+
} : {})
|
|
294
|
+
}))
|
|
295
|
+
];
|
|
296
|
+
case 1:
|
|
297
|
+
response = _state.sent();
|
|
298
|
+
correlationId = (_response_metadata = response.metadata) === null || _response_metadata === void 0 ? void 0 : _response_metadata.headers.get('x-correlation-id');
|
|
299
|
+
if (correlationId && typeof sessionStorage !== 'undefined') {
|
|
300
|
+
;
|
|
301
|
+
// We store the correlation id in the session storage so that we can use it in the next request
|
|
302
|
+
sessionStorage.setItem('x-correlation-id', ((_response_metadata1 = response.metadata) === null || _response_metadata1 === void 0 ? void 0 : _response_metadata1.headers.get('x-correlation-id')) || '');
|
|
303
|
+
}
|
|
304
|
+
if (response.ok) {
|
|
305
|
+
return [
|
|
306
|
+
2,
|
|
307
|
+
response.val
|
|
308
|
+
];
|
|
309
|
+
}
|
|
310
|
+
throw response.val;
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
})();
|
|
69
314
|
};
|
|
70
|
-
export
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
315
|
+
export var useApi = function(key, config) {
|
|
316
|
+
var result = useSWR(key, function(url) {
|
|
317
|
+
return swrFetch(url);
|
|
318
|
+
}, config);
|
|
319
|
+
return _object_spread_props(_object_spread({}, result), {
|
|
320
|
+
revalidate: function() {
|
|
321
|
+
return _async_to_generator(function() {
|
|
322
|
+
return _ts_generator(this, function(_state) {
|
|
323
|
+
switch(_state.label){
|
|
324
|
+
case 0:
|
|
325
|
+
return [
|
|
326
|
+
4,
|
|
327
|
+
result.mutate()
|
|
328
|
+
];
|
|
329
|
+
case 1:
|
|
330
|
+
return [
|
|
331
|
+
2,
|
|
332
|
+
!!_state.sent()
|
|
333
|
+
];
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
})();
|
|
337
|
+
}
|
|
338
|
+
});
|
|
76
339
|
};
|
|
77
|
-
export
|
|
340
|
+
export var useApiWithAuth = function(key, config) {
|
|
78
341
|
// TODO
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
342
|
+
var accessToken = useAuth().accessToken;
|
|
343
|
+
var result = useSWR(key ? Array.isArray(key) ? key : [
|
|
344
|
+
key,
|
|
345
|
+
accessToken
|
|
346
|
+
] : null, fetchWithAuth, config);
|
|
347
|
+
return _object_spread_props(_object_spread({}, result), {
|
|
348
|
+
revalidate: result.mutate
|
|
349
|
+
});
|
|
85
350
|
};
|
|
86
|
-
export
|
|
351
|
+
export var usePaginationApiWithAuth = function(key, config) {
|
|
87
352
|
// TODO
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
353
|
+
var accessToken = useAuth().accessToken;
|
|
354
|
+
var result = useSWRInfinite(function(i, p) {
|
|
355
|
+
var res = null;
|
|
91
356
|
if (typeof key === 'function') {
|
|
92
357
|
res = key(i, p);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (p.metadata
|
|
96
|
-
return null
|
|
358
|
+
} else if (isStructuredResponse(p) && key) {
|
|
359
|
+
var _p_metadata, _p_metadata1;
|
|
360
|
+
if (((_p_metadata = p.metadata) === null || _p_metadata === void 0 ? void 0 : _p_metadata.nextSkip) === null) {
|
|
361
|
+
return null // reached the end
|
|
362
|
+
;
|
|
97
363
|
}
|
|
98
|
-
|
|
99
|
-
res = p.metadata
|
|
100
|
-
|
|
101
|
-
: key;
|
|
102
|
-
}
|
|
103
|
-
else if (!p) {
|
|
364
|
+
var separator = key.indexOf('?') !== -1 ? '&' : '?';
|
|
365
|
+
res = ((_p_metadata1 = p.metadata) === null || _p_metadata1 === void 0 ? void 0 : _p_metadata1.nextSkip) ? "".concat(key).concat(separator, "skip=").concat(p.metadata.nextSkip) : key;
|
|
366
|
+
} else if (!p) {
|
|
104
367
|
res = key;
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
368
|
+
} else {
|
|
107
369
|
console.error('Wrong key loader or data type supplied to pagination');
|
|
108
370
|
return null;
|
|
109
371
|
}
|
|
110
|
-
return [
|
|
372
|
+
return [
|
|
373
|
+
res,
|
|
374
|
+
accessToken
|
|
375
|
+
];
|
|
111
376
|
}, fetchWithAuth, config);
|
|
112
|
-
return {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
377
|
+
return _object_spread_props(_object_spread({}, result), {
|
|
378
|
+
revalidate: function() {
|
|
379
|
+
return _async_to_generator(function() {
|
|
380
|
+
return _ts_generator(this, function(_state) {
|
|
381
|
+
switch(_state.label){
|
|
382
|
+
case 0:
|
|
383
|
+
return [
|
|
384
|
+
4,
|
|
385
|
+
result.mutate()
|
|
386
|
+
];
|
|
387
|
+
case 1:
|
|
388
|
+
return [
|
|
389
|
+
2,
|
|
390
|
+
!!_state.sent()
|
|
391
|
+
];
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
})();
|
|
395
|
+
}
|
|
396
|
+
});
|
|
116
397
|
};
|
|
117
398
|
/**
|
|
118
399
|
* TODO
|
|
119
400
|
* @deprecated
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
401
|
+
*/ export var useAuthenticatedFetch = function(url) {
|
|
402
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
403
|
+
var accessToken = useAuth().accessToken;
|
|
404
|
+
var headers = _object_spread({}, accessToken ? {
|
|
405
|
+
Authorization: "Bearer ".concat(accessToken)
|
|
406
|
+
} : undefined, (options === null || options === void 0 ? void 0 : options.headers) || {});
|
|
407
|
+
return function() {
|
|
408
|
+
return enhancedFetch(url, _object_spread({
|
|
409
|
+
headers: headers
|
|
410
|
+
}, options));
|
|
126
411
|
};
|
|
127
|
-
return () => enhancedFetch(url, {
|
|
128
|
-
headers,
|
|
129
|
-
...options,
|
|
130
|
-
});
|
|
131
412
|
};
|
|
132
|
-
//# sourceMappingURL=index.js.map
|
package/dist/api-models.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { config } from '@driveflux/config/frontend';
|
|
2
|
-
export
|
|
2
|
+
export var API_MODELS_URLS = {
|
|
3
3
|
Business: '/api/businesses',
|
|
4
4
|
User: '/api/users',
|
|
5
5
|
Inquiry: '/api/inquiries',
|
|
@@ -11,14 +11,11 @@ export const API_MODELS_URLS = {
|
|
|
11
11
|
Invoice: '/api/invoices',
|
|
12
12
|
SubscriptionReservation: '/api/reservations',
|
|
13
13
|
SubscriptionContract: '/api/subscription-contracts',
|
|
14
|
-
EmailSent: '/api/emails-sent'
|
|
14
|
+
EmailSent: '/api/emails-sent'
|
|
15
15
|
};
|
|
16
16
|
export function getApiUrl(model) {
|
|
17
|
-
if (model.startsWith('/api') || model.startsWith(
|
|
17
|
+
if (model.startsWith('/api') || model.startsWith("".concat(config.apiUrl))) {
|
|
18
18
|
return model;
|
|
19
19
|
}
|
|
20
|
-
return model in API_MODELS_URLS
|
|
21
|
-
? API_MODELS_URLS[model]
|
|
22
|
-
: `/api/${model}`;
|
|
20
|
+
return model in API_MODELS_URLS ? API_MODELS_URLS[model] : "/api/".concat(model);
|
|
23
21
|
}
|
|
24
|
-
//# sourceMappingURL=api-models.js.map
|
package/dist/fetcher.js
CHANGED
|
@@ -1,3 +1,221 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _async_to_generator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
+
}
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _define_property(obj, key, value) {
|
|
39
|
+
if (key in obj) {
|
|
40
|
+
Object.defineProperty(obj, key, {
|
|
41
|
+
value: value,
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
obj[key] = value;
|
|
48
|
+
}
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
function _iterable_to_array_limit(arr, i) {
|
|
52
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
53
|
+
if (_i == null) return;
|
|
54
|
+
var _arr = [];
|
|
55
|
+
var _n = true;
|
|
56
|
+
var _d = false;
|
|
57
|
+
var _s, _e;
|
|
58
|
+
try {
|
|
59
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
60
|
+
_arr.push(_s.value);
|
|
61
|
+
if (i && _arr.length === i) break;
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
_d = true;
|
|
65
|
+
_e = err;
|
|
66
|
+
} finally{
|
|
67
|
+
try {
|
|
68
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
69
|
+
} finally{
|
|
70
|
+
if (_d) throw _e;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return _arr;
|
|
74
|
+
}
|
|
75
|
+
function _non_iterable_rest() {
|
|
76
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
77
|
+
}
|
|
78
|
+
function _object_spread(target) {
|
|
79
|
+
for(var i = 1; i < arguments.length; i++){
|
|
80
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
81
|
+
var ownKeys = Object.keys(source);
|
|
82
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
83
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
84
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
ownKeys.forEach(function(key) {
|
|
88
|
+
_define_property(target, key, source[key]);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return target;
|
|
92
|
+
}
|
|
93
|
+
function ownKeys(object, enumerableOnly) {
|
|
94
|
+
var keys = Object.keys(object);
|
|
95
|
+
if (Object.getOwnPropertySymbols) {
|
|
96
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
97
|
+
if (enumerableOnly) {
|
|
98
|
+
symbols = symbols.filter(function(sym) {
|
|
99
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
keys.push.apply(keys, symbols);
|
|
103
|
+
}
|
|
104
|
+
return keys;
|
|
105
|
+
}
|
|
106
|
+
function _object_spread_props(target, source) {
|
|
107
|
+
source = source != null ? source : {};
|
|
108
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
109
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
110
|
+
} else {
|
|
111
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
112
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return target;
|
|
116
|
+
}
|
|
117
|
+
function _sliced_to_array(arr, i) {
|
|
118
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
119
|
+
}
|
|
120
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
121
|
+
if (!o) return;
|
|
122
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
123
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
124
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
125
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
126
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
127
|
+
}
|
|
128
|
+
function _ts_generator(thisArg, body) {
|
|
129
|
+
var f, y, t, _ = {
|
|
130
|
+
label: 0,
|
|
131
|
+
sent: function() {
|
|
132
|
+
if (t[0] & 1) throw t[1];
|
|
133
|
+
return t[1];
|
|
134
|
+
},
|
|
135
|
+
trys: [],
|
|
136
|
+
ops: []
|
|
137
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
138
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
139
|
+
return this;
|
|
140
|
+
}), g;
|
|
141
|
+
function verb(n) {
|
|
142
|
+
return function(v) {
|
|
143
|
+
return step([
|
|
144
|
+
n,
|
|
145
|
+
v
|
|
146
|
+
]);
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function step(op) {
|
|
150
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
151
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
152
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
153
|
+
if (y = 0, t) op = [
|
|
154
|
+
op[0] & 2,
|
|
155
|
+
t.value
|
|
156
|
+
];
|
|
157
|
+
switch(op[0]){
|
|
158
|
+
case 0:
|
|
159
|
+
case 1:
|
|
160
|
+
t = op;
|
|
161
|
+
break;
|
|
162
|
+
case 4:
|
|
163
|
+
_.label++;
|
|
164
|
+
return {
|
|
165
|
+
value: op[1],
|
|
166
|
+
done: false
|
|
167
|
+
};
|
|
168
|
+
case 5:
|
|
169
|
+
_.label++;
|
|
170
|
+
y = op[1];
|
|
171
|
+
op = [
|
|
172
|
+
0
|
|
173
|
+
];
|
|
174
|
+
continue;
|
|
175
|
+
case 7:
|
|
176
|
+
op = _.ops.pop();
|
|
177
|
+
_.trys.pop();
|
|
178
|
+
continue;
|
|
179
|
+
default:
|
|
180
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
181
|
+
_ = 0;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
185
|
+
_.label = op[1];
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
189
|
+
_.label = t[1];
|
|
190
|
+
t = op;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
if (t && _.label < t[2]) {
|
|
194
|
+
_.label = t[2];
|
|
195
|
+
_.ops.push(op);
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
if (t[2]) _.ops.pop();
|
|
199
|
+
_.trys.pop();
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
op = body.call(thisArg, _);
|
|
203
|
+
} catch (e) {
|
|
204
|
+
op = [
|
|
205
|
+
6,
|
|
206
|
+
e
|
|
207
|
+
];
|
|
208
|
+
y = 0;
|
|
209
|
+
} finally{
|
|
210
|
+
f = t = 0;
|
|
211
|
+
}
|
|
212
|
+
if (op[0] & 5) throw op[1];
|
|
213
|
+
return {
|
|
214
|
+
value: op[0] ? op[1] : void 0,
|
|
215
|
+
done: true
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
1
219
|
import { config } from '@driveflux/config/frontend';
|
|
2
220
|
import { enhancedFetch } from '@driveflux/fetch';
|
|
3
221
|
/**
|
|
@@ -6,34 +224,46 @@ import { enhancedFetch } from '@driveflux/fetch';
|
|
|
6
224
|
*
|
|
7
225
|
* @important instead of returning a result, this will always return Success or throw an error containing Error
|
|
8
226
|
* @important if the 3rd param provides an Authorization header, it will be ignored!
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
227
|
+
*/ export var fetchWithAuth = function(urlParams) {
|
|
228
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
229
|
+
return _async_to_generator(function() {
|
|
230
|
+
var _result_metadata, _ref, url, accessToken, apiHost, finalUrl, correlationIdFromSessionStorage, result, correlationId, _result_metadata1;
|
|
231
|
+
return _ts_generator(this, function(_state) {
|
|
232
|
+
switch(_state.label){
|
|
233
|
+
case 0:
|
|
234
|
+
_ref = _sliced_to_array(Array.isArray(urlParams) ? urlParams : [
|
|
235
|
+
urlParams,
|
|
236
|
+
null
|
|
237
|
+
], 2), url = _ref[0], accessToken = _ref[1];
|
|
238
|
+
apiHost = config.appUrl;
|
|
239
|
+
finalUrl = url.startsWith('/') ? "".concat(apiHost).concat(url) : url;
|
|
240
|
+
correlationIdFromSessionStorage = typeof sessionStorage !== 'undefined' ? sessionStorage.getItem('x-correlation-id') : null;
|
|
241
|
+
return [
|
|
242
|
+
4,
|
|
243
|
+
enhancedFetch(finalUrl, _object_spread_props(_object_spread({}, options), {
|
|
244
|
+
headers: _object_spread({}, options.headers || {}, accessToken ? {
|
|
245
|
+
Authorization: "Bearer ".concat(accessToken)
|
|
246
|
+
} : {}, correlationIdFromSessionStorage ? {
|
|
247
|
+
'x-correlation-id': correlationIdFromSessionStorage
|
|
248
|
+
} : {})
|
|
249
|
+
}))
|
|
250
|
+
];
|
|
251
|
+
case 1:
|
|
252
|
+
result = _state.sent();
|
|
253
|
+
correlationId = (_result_metadata = result.metadata) === null || _result_metadata === void 0 ? void 0 : _result_metadata.headers.get('x-correlation-id');
|
|
254
|
+
if (correlationId && typeof sessionStorage !== 'undefined') {
|
|
255
|
+
;
|
|
256
|
+
// We store the correlation id in the session storage so that we can use it in the next request
|
|
257
|
+
sessionStorage.setItem('x-correlation-id', ((_result_metadata1 = result.metadata) === null || _result_metadata1 === void 0 ? void 0 : _result_metadata1.headers.get('x-correlation-id')) || '');
|
|
258
|
+
}
|
|
259
|
+
if (!result.ok) {
|
|
260
|
+
throw result.val;
|
|
261
|
+
}
|
|
262
|
+
return [
|
|
263
|
+
2,
|
|
264
|
+
result.val
|
|
265
|
+
];
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
})();
|
|
38
269
|
};
|
|
39
|
-
//# sourceMappingURL=fetcher.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,82 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _object_spread(target) {
|
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
+
var ownKeys = Object.keys(source);
|
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
ownKeys.forEach(function(key) {
|
|
24
|
+
_define_property(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
}
|
|
29
|
+
function ownKeys(object, enumerableOnly) {
|
|
30
|
+
var keys = Object.keys(object);
|
|
31
|
+
if (Object.getOwnPropertySymbols) {
|
|
32
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
33
|
+
if (enumerableOnly) {
|
|
34
|
+
symbols = symbols.filter(function(sym) {
|
|
35
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
keys.push.apply(keys, symbols);
|
|
39
|
+
}
|
|
40
|
+
return keys;
|
|
41
|
+
}
|
|
42
|
+
function _object_spread_props(target, source) {
|
|
43
|
+
source = source != null ? source : {};
|
|
44
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
45
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
46
|
+
} else {
|
|
47
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
48
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return target;
|
|
52
|
+
}
|
|
53
|
+
function _object_without_properties(source, excluded) {
|
|
54
|
+
if (source == null) return {};
|
|
55
|
+
var target = _object_without_properties_loose(source, excluded);
|
|
56
|
+
var key, i;
|
|
57
|
+
if (Object.getOwnPropertySymbols) {
|
|
58
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
59
|
+
for(i = 0; i < sourceSymbolKeys.length; i++){
|
|
60
|
+
key = sourceSymbolKeys[i];
|
|
61
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
62
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
63
|
+
target[key] = source[key];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return target;
|
|
67
|
+
}
|
|
68
|
+
function _object_without_properties_loose(source, excluded) {
|
|
69
|
+
if (source == null) return {};
|
|
70
|
+
var target = {};
|
|
71
|
+
var sourceKeys = Object.keys(source);
|
|
72
|
+
var key, i;
|
|
73
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
74
|
+
key = sourceKeys[i];
|
|
75
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
76
|
+
target[key] = source[key];
|
|
77
|
+
}
|
|
78
|
+
return target;
|
|
79
|
+
}
|
|
1
80
|
import { useAuth } from '@driveflux/auth/react/providers';
|
|
2
81
|
import isEmpty from 'lodash/isEmpty.js';
|
|
3
82
|
import { useCallback } from 'react';
|
|
@@ -6,55 +85,62 @@ import useSWRInfinite from 'swr/infinite';
|
|
|
6
85
|
import { getApiUrl } from './api-models.js';
|
|
7
86
|
import { fetchWithAuth } from './fetcher.js';
|
|
8
87
|
import { makeQueryParams } from './utils.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
88
|
+
var getKeyMaker = function(model, pageSize, query, accessToken) {
|
|
89
|
+
var resource = getApiUrl(model);
|
|
90
|
+
var loader = function(pageIndex, previousPageData) {
|
|
12
91
|
if (previousPageData && !previousPageData.next) {
|
|
13
92
|
return null;
|
|
14
93
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
94
|
+
var makeFinalQuery = function(index) {
|
|
95
|
+
var take = (previousPageData === null || previousPageData === void 0 ? void 0 : previousPageData.take) || pageSize;
|
|
96
|
+
return _object_spread_props(_object_spread({}, query), {
|
|
97
|
+
skip: (previousPageData === null || previousPageData === void 0 ? void 0 : previousPageData.skip) || (take ? index * take : undefined),
|
|
98
|
+
take: take
|
|
99
|
+
});
|
|
22
100
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const nextQueryString = !isEmpty(nextQuery)
|
|
30
|
-
? `?${makeQueryParams(nextQuery)}`
|
|
31
|
-
: '';
|
|
32
|
-
const nextUrl = `${resource}${nextQueryString}`;
|
|
101
|
+
var finalQuery = makeFinalQuery(pageIndex);
|
|
102
|
+
var queryString = !isEmpty(finalQuery) ? "?".concat(makeQueryParams(finalQuery)) : '';
|
|
103
|
+
var url = "".concat(resource).concat(queryString);
|
|
104
|
+
var nextQuery = makeFinalQuery(pageIndex + 1);
|
|
105
|
+
var nextQueryString = !isEmpty(nextQuery) ? "?".concat(makeQueryParams(nextQuery)) : '';
|
|
106
|
+
var nextUrl = "".concat(resource).concat(nextQueryString);
|
|
33
107
|
// Preload next page
|
|
34
|
-
preload([
|
|
35
|
-
|
|
108
|
+
preload([
|
|
109
|
+
nextUrl,
|
|
110
|
+
accessToken
|
|
111
|
+
], fetchWithAuth);
|
|
112
|
+
return [
|
|
113
|
+
url,
|
|
114
|
+
accessToken
|
|
115
|
+
];
|
|
36
116
|
};
|
|
37
117
|
return loader;
|
|
38
118
|
};
|
|
39
|
-
export
|
|
119
|
+
export var useApiPagination = function(model, _param) {
|
|
120
|
+
var pageSize = _param.pageSize, query = _param.query, swrConfig = _object_without_properties(_param, [
|
|
121
|
+
"pageSize",
|
|
122
|
+
"query"
|
|
123
|
+
]);
|
|
124
|
+
var _result_data_, _result_data;
|
|
40
125
|
// TODO
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
parallel: true
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const next = useCallback(() => {
|
|
126
|
+
var accessToken = useAuth().accessToken;
|
|
127
|
+
var result = useSWRInfinite(getKeyMaker(model, pageSize || 20, query, accessToken), fetchWithAuth, _object_spread({
|
|
128
|
+
parallel: true
|
|
129
|
+
}, swrConfig));
|
|
130
|
+
var hasMore = ((result === null || result === void 0 ? void 0 : (_result_data = result.data) === null || _result_data === void 0 ? void 0 : (_result_data_ = _result_data[0]) === null || _result_data_ === void 0 ? void 0 : _result_data_.count) || 0) > result.size * (pageSize || 20);
|
|
131
|
+
var next = useCallback(function() {
|
|
48
132
|
if (!hasMore) {
|
|
49
133
|
return;
|
|
50
134
|
}
|
|
51
135
|
result.setSize(result.size + 1);
|
|
52
|
-
}, [
|
|
53
|
-
return {
|
|
54
|
-
...result,
|
|
55
|
-
next,
|
|
136
|
+
}, [
|
|
56
137
|
hasMore,
|
|
57
|
-
|
|
138
|
+
result === null || result === void 0 ? void 0 : result.size,
|
|
139
|
+
result.setSize
|
|
140
|
+
]);
|
|
141
|
+
return _object_spread_props(_object_spread({}, result), {
|
|
142
|
+
next: next,
|
|
143
|
+
hasMore: hasMore
|
|
144
|
+
});
|
|
58
145
|
};
|
|
59
146
|
export * from './utils.js';
|
|
60
|
-
//# sourceMappingURL=index.js.map
|
package/dist/utils.js
CHANGED
|
@@ -1,24 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
if (
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _instanceof(left, right) {
|
|
10
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
11
|
+
return !!right[Symbol.hasInstance](left);
|
|
12
|
+
} else {
|
|
13
|
+
return left instanceof right;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _iterable_to_array_limit(arr, i) {
|
|
17
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
18
|
+
if (_i == null) return;
|
|
19
|
+
var _arr = [];
|
|
20
|
+
var _n = true;
|
|
21
|
+
var _d = false;
|
|
22
|
+
var _s, _e;
|
|
23
|
+
try {
|
|
24
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
25
|
+
_arr.push(_s.value);
|
|
26
|
+
if (i && _arr.length === i) break;
|
|
27
|
+
}
|
|
28
|
+
} catch (err) {
|
|
29
|
+
_d = true;
|
|
30
|
+
_e = err;
|
|
31
|
+
} finally{
|
|
32
|
+
try {
|
|
33
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
34
|
+
} finally{
|
|
35
|
+
if (_d) throw _e;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return _arr;
|
|
39
|
+
}
|
|
40
|
+
function _non_iterable_rest() {
|
|
41
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
42
|
+
}
|
|
43
|
+
function _sliced_to_array(arr, i) {
|
|
44
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
45
|
+
}
|
|
46
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
47
|
+
if (!o) return;
|
|
48
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
49
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
50
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
51
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
52
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
53
|
+
}
|
|
54
|
+
export var makeQueryParams = function(params) {
|
|
55
|
+
if (_instanceof(params, URLSearchParams)) {
|
|
3
56
|
return params.toString();
|
|
4
57
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
58
|
+
var newParams = new URLSearchParams();
|
|
59
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
60
|
+
try {
|
|
61
|
+
for(var _iterator = Object.entries(params)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
62
|
+
var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
|
|
63
|
+
appendParam(newParams, key, value);
|
|
64
|
+
}
|
|
65
|
+
} catch (err) {
|
|
66
|
+
_didIteratorError = true;
|
|
67
|
+
_iteratorError = err;
|
|
68
|
+
} finally{
|
|
69
|
+
try {
|
|
70
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
71
|
+
_iterator.return();
|
|
72
|
+
}
|
|
73
|
+
} finally{
|
|
74
|
+
if (_didIteratorError) {
|
|
75
|
+
throw _iteratorError;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
8
78
|
}
|
|
9
79
|
return newParams.toString();
|
|
10
80
|
};
|
|
11
|
-
|
|
81
|
+
var appendParam = function(params, key, value) {
|
|
12
82
|
if (Array.isArray(value)) {
|
|
13
|
-
|
|
14
|
-
|
|
83
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
84
|
+
try {
|
|
85
|
+
for(var _iterator = value[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
86
|
+
var v = _step.value;
|
|
87
|
+
appendParam(params, key, v);
|
|
88
|
+
}
|
|
89
|
+
} catch (err) {
|
|
90
|
+
_didIteratorError = true;
|
|
91
|
+
_iteratorError = err;
|
|
92
|
+
} finally{
|
|
93
|
+
try {
|
|
94
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
95
|
+
_iterator.return();
|
|
96
|
+
}
|
|
97
|
+
} finally{
|
|
98
|
+
if (_didIteratorError) {
|
|
99
|
+
throw _iteratorError;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
15
102
|
}
|
|
16
|
-
}
|
|
17
|
-
else if (value instanceof Date) {
|
|
103
|
+
} else if (_instanceof(value, Date)) {
|
|
18
104
|
params.append(key, value.toISOString());
|
|
19
|
-
}
|
|
20
|
-
else if (value !== undefined && value !== null) {
|
|
105
|
+
} else if (value !== undefined && value !== null) {
|
|
21
106
|
params.append(key, value.toString());
|
|
22
107
|
}
|
|
23
108
|
};
|
|
24
|
-
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driveflux/api-swr",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.88",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@driveflux/auth": "4.0.
|
|
19
|
+
"@driveflux/auth": "4.0.87",
|
|
20
20
|
"@driveflux/config": "3.0.10",
|
|
21
|
-
"@driveflux/db": "4.1.
|
|
21
|
+
"@driveflux/db": "4.1.19",
|
|
22
22
|
"@driveflux/fetch": "8.0.1",
|
|
23
23
|
"@driveflux/problem": "6.0.1",
|
|
24
24
|
"@driveflux/result": "6.0.1",
|