@driveflux/api-swr 4.0.86 → 4.0.87
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 +100 -380
- package/dist/api-models.js +7 -4
- package/dist/api-models.js.map +1 -1
- package/dist/fetcher.js +30 -260
- package/dist/index.js +36 -122
- package/dist/utils.js +13 -97
- package/package.json +4 -4
package/dist/api-legacy/index.js
CHANGED
|
@@ -1,225 +1,3 @@
|
|
|
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
|
-
}
|
|
223
1
|
import { useAuth } from '@driveflux/auth/react/providers';
|
|
224
2
|
import { config } from '@driveflux/config/frontend';
|
|
225
3
|
import { enhancedFetch } from '@driveflux/fetch';
|
|
@@ -231,182 +9,124 @@ import useSWRInfinite from 'swr/infinite';
|
|
|
231
9
|
*
|
|
232
10
|
* @important instead of returning a result, this will always return Success or throw an error containing Error
|
|
233
11
|
* @important if the 3rd param provides an Authorization header, it will be ignored!
|
|
234
|
-
*/
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
if (!result.ok) {
|
|
267
|
-
throw result.val;
|
|
268
|
-
}
|
|
269
|
-
return [
|
|
270
|
-
2,
|
|
271
|
-
result.val
|
|
272
|
-
];
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
})();
|
|
276
|
-
};
|
|
277
|
-
export var isStructuredResponse = function(obj) {
|
|
278
|
-
return obj && (typeof obj === "undefined" ? "undefined" : _type_of(obj)) === 'object' && obj.metadata;
|
|
12
|
+
*/
|
|
13
|
+
export const fetchWithAuth = async (urlParams, options = {}) => {
|
|
14
|
+
const [url, accessToken, otherOptions] = Array.isArray(urlParams)
|
|
15
|
+
? urlParams
|
|
16
|
+
: [urlParams, null];
|
|
17
|
+
const apiHost = config.appUrl;
|
|
18
|
+
const finalUrl = url.startsWith('/') ? `${apiHost}${url}` : url;
|
|
19
|
+
const correlationIdFromSessionStorage = typeof sessionStorage !== 'undefined'
|
|
20
|
+
? sessionStorage.getItem('x-correlation-id')
|
|
21
|
+
: null;
|
|
22
|
+
const result = await enhancedFetch(finalUrl, {
|
|
23
|
+
...options,
|
|
24
|
+
...otherOptions,
|
|
25
|
+
headers: {
|
|
26
|
+
...(options.headers || {}),
|
|
27
|
+
...(otherOptions?.headers || {}),
|
|
28
|
+
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
|
|
29
|
+
...(correlationIdFromSessionStorage
|
|
30
|
+
? { 'x-correlation-id': correlationIdFromSessionStorage }
|
|
31
|
+
: {}),
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
const correlationId = result.metadata?.headers.get('x-correlation-id');
|
|
35
|
+
if (correlationId && typeof sessionStorage !== 'undefined') {
|
|
36
|
+
// We store the correlation id in the session storage so that we can use it in the next request
|
|
37
|
+
sessionStorage.setItem('x-correlation-id', result.metadata?.headers.get('x-correlation-id') || '');
|
|
38
|
+
}
|
|
39
|
+
if (!result.ok) {
|
|
40
|
+
throw result.val;
|
|
41
|
+
}
|
|
42
|
+
return result.val;
|
|
279
43
|
};
|
|
280
|
-
export
|
|
281
|
-
|
|
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
|
-
})();
|
|
44
|
+
export const isStructuredResponse = (obj) => {
|
|
45
|
+
return obj && typeof obj === 'object' && obj.metadata;
|
|
314
46
|
};
|
|
315
|
-
export
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
result.mutate()
|
|
328
|
-
];
|
|
329
|
-
case 1:
|
|
330
|
-
return [
|
|
331
|
-
2,
|
|
332
|
-
!!_state.sent()
|
|
333
|
-
];
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
})();
|
|
337
|
-
}
|
|
47
|
+
export const swrFetch = async (url, options = {}) => {
|
|
48
|
+
const correlationIdFromSessionStorage = typeof sessionStorage !== 'undefined'
|
|
49
|
+
? sessionStorage.getItem('x-correlation-id')
|
|
50
|
+
: null;
|
|
51
|
+
const response = await enhancedFetch(url, {
|
|
52
|
+
...options,
|
|
53
|
+
headers: {
|
|
54
|
+
...(options.headers || {}),
|
|
55
|
+
...(correlationIdFromSessionStorage
|
|
56
|
+
? { 'x-correlation-id': correlationIdFromSessionStorage }
|
|
57
|
+
: {}),
|
|
58
|
+
},
|
|
338
59
|
});
|
|
60
|
+
const correlationId = response.metadata?.headers.get('x-correlation-id');
|
|
61
|
+
if (correlationId && typeof sessionStorage !== 'undefined') {
|
|
62
|
+
// We store the correlation id in the session storage so that we can use it in the next request
|
|
63
|
+
sessionStorage.setItem('x-correlation-id', response.metadata?.headers.get('x-correlation-id') || '');
|
|
64
|
+
}
|
|
65
|
+
if (response.ok) {
|
|
66
|
+
return response.val;
|
|
67
|
+
}
|
|
68
|
+
throw response.val;
|
|
69
|
+
};
|
|
70
|
+
export const useApi = (key, config) => {
|
|
71
|
+
const result = useSWR(key, (url) => swrFetch(url), config);
|
|
72
|
+
return {
|
|
73
|
+
...result,
|
|
74
|
+
revalidate: async () => !!(await result.mutate()),
|
|
75
|
+
};
|
|
339
76
|
};
|
|
340
|
-
export
|
|
77
|
+
export const useApiWithAuth = (key, config) => {
|
|
341
78
|
// TODO
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
revalidate: result.mutate
|
|
349
|
-
});
|
|
79
|
+
const { accessToken } = useAuth();
|
|
80
|
+
const result = useSWR(key ? (Array.isArray(key) ? key : [key, accessToken]) : null, fetchWithAuth, config);
|
|
81
|
+
return {
|
|
82
|
+
...result,
|
|
83
|
+
revalidate: result.mutate,
|
|
84
|
+
};
|
|
350
85
|
};
|
|
351
|
-
export
|
|
86
|
+
export const usePaginationApiWithAuth = (key, config) => {
|
|
352
87
|
// TODO
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
88
|
+
const { accessToken } = useAuth();
|
|
89
|
+
const result = useSWRInfinite((i, p) => {
|
|
90
|
+
let res = null;
|
|
356
91
|
if (typeof key === 'function') {
|
|
357
92
|
res = key(i, p);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (
|
|
361
|
-
return null // reached the end
|
|
362
|
-
;
|
|
93
|
+
}
|
|
94
|
+
else if (isStructuredResponse(p) && key) {
|
|
95
|
+
if (p.metadata?.nextSkip === null) {
|
|
96
|
+
return null; // reached the end
|
|
363
97
|
}
|
|
364
|
-
|
|
365
|
-
res =
|
|
366
|
-
|
|
98
|
+
const separator = key.indexOf('?') !== -1 ? '&' : '?';
|
|
99
|
+
res = p.metadata?.nextSkip
|
|
100
|
+
? `${key}${separator}skip=${p.metadata.nextSkip}`
|
|
101
|
+
: key;
|
|
102
|
+
}
|
|
103
|
+
else if (!p) {
|
|
367
104
|
res = key;
|
|
368
|
-
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
369
107
|
console.error('Wrong key loader or data type supplied to pagination');
|
|
370
108
|
return null;
|
|
371
109
|
}
|
|
372
|
-
return [
|
|
373
|
-
res,
|
|
374
|
-
accessToken
|
|
375
|
-
];
|
|
110
|
+
return [res, accessToken];
|
|
376
111
|
}, fetchWithAuth, config);
|
|
377
|
-
return
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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
|
-
});
|
|
112
|
+
return {
|
|
113
|
+
...result,
|
|
114
|
+
revalidate: async () => !!(await result.mutate()),
|
|
115
|
+
};
|
|
397
116
|
};
|
|
398
117
|
/**
|
|
399
118
|
* TODO
|
|
400
119
|
* @deprecated
|
|
401
|
-
*/
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
Authorization:
|
|
406
|
-
|
|
407
|
-
return function() {
|
|
408
|
-
return enhancedFetch(url, _object_spread({
|
|
409
|
-
headers: headers
|
|
410
|
-
}, options));
|
|
120
|
+
*/
|
|
121
|
+
export const useAuthenticatedFetch = (url, options = {}) => {
|
|
122
|
+
const { accessToken } = useAuth();
|
|
123
|
+
const headers = {
|
|
124
|
+
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : undefined),
|
|
125
|
+
...(options?.headers || {}),
|
|
411
126
|
};
|
|
127
|
+
return () => enhancedFetch(url, {
|
|
128
|
+
headers,
|
|
129
|
+
...options,
|
|
130
|
+
});
|
|
412
131
|
};
|
|
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 const API_MODELS_URLS = {
|
|
3
3
|
Business: '/api/businesses',
|
|
4
4
|
User: '/api/users',
|
|
5
5
|
Inquiry: '/api/inquiries',
|
|
@@ -11,11 +11,14 @@ export var 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(`${config.apiUrl}`)) {
|
|
18
18
|
return model;
|
|
19
19
|
}
|
|
20
|
-
return model in API_MODELS_URLS
|
|
20
|
+
return model in API_MODELS_URLS
|
|
21
|
+
? API_MODELS_URLS[model]
|
|
22
|
+
: `/api/${model}`;
|
|
21
23
|
}
|
|
24
|
+
//# sourceMappingURL=api-models.js.map
|
package/dist/api-models.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-models.js","sourceRoot":"","sources":["../src/api-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAUnD,MAAM,CAAC,MAAM,eAAe,GAAG;IAC9B,QAAQ,EAAE,iBAAiB;IAC3B,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,gBAAgB;IACzB,OAAO,EAAE,eAAe;IACxB,aAAa,EAAE,sBAAsB;IACrC,IAAI,EAAE,YAAY;IAClB,YAAY,EAAE,oBAAoB;IAClC,KAAK,EAAE,aAAa;IACpB,OAAO,EAAE,eAAe;IACxB,uBAAuB,EAAE,mBAAmB;IAC5C,oBAAoB,EAAE,6BAA6B;
|
|
1
|
+
{"version":3,"file":"api-models.js","sourceRoot":"","sources":["../src/api-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAUnD,MAAM,CAAC,MAAM,eAAe,GAAG;IAC9B,QAAQ,EAAE,iBAAiB;IAC3B,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,gBAAgB;IACzB,OAAO,EAAE,eAAe;IACxB,aAAa,EAAE,sBAAsB;IACrC,IAAI,EAAE,YAAY;IAClB,YAAY,EAAE,oBAAoB;IAClC,KAAK,EAAE,aAAa;IACpB,OAAO,EAAE,eAAe;IACxB,uBAAuB,EAAE,mBAAmB;IAC5C,oBAAoB,EAAE,6BAA6B;IACnD,SAAS,EAAE,kBAAkB;CACM,CAAA;AAQpC,MAAM,UAAU,SAAS,CACxB,KAAQ;IAER,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;QACtE,OAAO,KAAK,CAAA;IACb,CAAC;IACD,OAAO,KAAK,IAAI,eAAe;QAC9B,CAAC,CAAC,eAAe,CAAC,KAAqC,CAAC;QACxD,CAAC,CAAC,QAAQ,KAAK,EAAE,CAAA;AACnB,CAAC"}
|
package/dist/fetcher.js
CHANGED
|
@@ -1,221 +1,3 @@
|
|
|
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
|
-
}
|
|
219
1
|
import { config } from '@driveflux/config/frontend';
|
|
220
2
|
import { enhancedFetch } from '@driveflux/fetch';
|
|
221
3
|
/**
|
|
@@ -224,46 +6,34 @@ import { enhancedFetch } from '@driveflux/fetch';
|
|
|
224
6
|
*
|
|
225
7
|
* @important instead of returning a result, this will always return Success or throw an error containing Error
|
|
226
8
|
* @important if the 3rd param provides an Authorization header, it will be ignored!
|
|
227
|
-
*/
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
})();
|
|
9
|
+
*/
|
|
10
|
+
export const fetchWithAuth = async (urlParams, options = {}) => {
|
|
11
|
+
const [url, accessToken] = Array.isArray(urlParams)
|
|
12
|
+
? urlParams
|
|
13
|
+
: [urlParams, null];
|
|
14
|
+
const apiHost = config.appUrl;
|
|
15
|
+
const finalUrl = url.startsWith('/') ? `${apiHost}${url}` : url;
|
|
16
|
+
const correlationIdFromSessionStorage = typeof sessionStorage !== 'undefined'
|
|
17
|
+
? sessionStorage.getItem('x-correlation-id')
|
|
18
|
+
: null;
|
|
19
|
+
const result = await enhancedFetch(finalUrl, {
|
|
20
|
+
...options,
|
|
21
|
+
headers: {
|
|
22
|
+
...(options.headers || {}),
|
|
23
|
+
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
|
|
24
|
+
...(correlationIdFromSessionStorage
|
|
25
|
+
? { 'x-correlation-id': correlationIdFromSessionStorage }
|
|
26
|
+
: {}),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const correlationId = result.metadata?.headers.get('x-correlation-id');
|
|
30
|
+
if (correlationId && typeof sessionStorage !== 'undefined') {
|
|
31
|
+
// We store the correlation id in the session storage so that we can use it in the next request
|
|
32
|
+
sessionStorage.setItem('x-correlation-id', result.metadata?.headers.get('x-correlation-id') || '');
|
|
33
|
+
}
|
|
34
|
+
if (!result.ok) {
|
|
35
|
+
throw result.val;
|
|
36
|
+
}
|
|
37
|
+
return result.val;
|
|
269
38
|
};
|
|
39
|
+
//# sourceMappingURL=fetcher.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,82 +1,3 @@
|
|
|
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
|
-
}
|
|
80
1
|
import { useAuth } from '@driveflux/auth/react/providers';
|
|
81
2
|
import isEmpty from 'lodash/isEmpty.js';
|
|
82
3
|
import { useCallback } from 'react';
|
|
@@ -85,62 +6,55 @@ import useSWRInfinite from 'swr/infinite';
|
|
|
85
6
|
import { getApiUrl } from './api-models.js';
|
|
86
7
|
import { fetchWithAuth } from './fetcher.js';
|
|
87
8
|
import { makeQueryParams } from './utils.js';
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
9
|
+
const getKeyMaker = (model, pageSize, query, accessToken) => {
|
|
10
|
+
const resource = getApiUrl(model);
|
|
11
|
+
const loader = (pageIndex, previousPageData) => {
|
|
91
12
|
if (previousPageData && !previousPageData.next) {
|
|
92
13
|
return null;
|
|
93
14
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
take:
|
|
99
|
-
|
|
15
|
+
const makeFinalQuery = (index) => {
|
|
16
|
+
const take = previousPageData?.take || pageSize;
|
|
17
|
+
return {
|
|
18
|
+
...query,
|
|
19
|
+
skip: previousPageData?.skip || (take ? index * take : undefined),
|
|
20
|
+
take,
|
|
21
|
+
};
|
|
100
22
|
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
23
|
+
const finalQuery = makeFinalQuery(pageIndex);
|
|
24
|
+
const queryString = !isEmpty(finalQuery)
|
|
25
|
+
? `?${makeQueryParams(finalQuery)}`
|
|
26
|
+
: '';
|
|
27
|
+
const url = `${resource}${queryString}`;
|
|
28
|
+
const nextQuery = makeFinalQuery(pageIndex + 1);
|
|
29
|
+
const nextQueryString = !isEmpty(nextQuery)
|
|
30
|
+
? `?${makeQueryParams(nextQuery)}`
|
|
31
|
+
: '';
|
|
32
|
+
const nextUrl = `${resource}${nextQueryString}`;
|
|
107
33
|
// Preload next page
|
|
108
|
-
preload([
|
|
109
|
-
|
|
110
|
-
accessToken
|
|
111
|
-
], fetchWithAuth);
|
|
112
|
-
return [
|
|
113
|
-
url,
|
|
114
|
-
accessToken
|
|
115
|
-
];
|
|
34
|
+
preload([nextUrl, accessToken], fetchWithAuth);
|
|
35
|
+
return [url, accessToken];
|
|
116
36
|
};
|
|
117
37
|
return loader;
|
|
118
38
|
};
|
|
119
|
-
export
|
|
120
|
-
var pageSize = _param.pageSize, query = _param.query, swrConfig = _object_without_properties(_param, [
|
|
121
|
-
"pageSize",
|
|
122
|
-
"query"
|
|
123
|
-
]);
|
|
124
|
-
var _result_data_, _result_data;
|
|
39
|
+
export const useApiPagination = (model, { pageSize, query, ...swrConfig }) => {
|
|
125
40
|
// TODO
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
parallel: true
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
41
|
+
const { accessToken } = useAuth();
|
|
42
|
+
const result = useSWRInfinite(getKeyMaker(model, pageSize || 20, query, accessToken), fetchWithAuth, {
|
|
43
|
+
parallel: true,
|
|
44
|
+
...swrConfig,
|
|
45
|
+
});
|
|
46
|
+
const hasMore = (result?.data?.[0]?.count || 0) > result.size * (pageSize || 20);
|
|
47
|
+
const next = useCallback(() => {
|
|
132
48
|
if (!hasMore) {
|
|
133
49
|
return;
|
|
134
50
|
}
|
|
135
51
|
result.setSize(result.size + 1);
|
|
136
|
-
}, [
|
|
52
|
+
}, [hasMore, result?.size, result.setSize]);
|
|
53
|
+
return {
|
|
54
|
+
...result,
|
|
55
|
+
next,
|
|
137
56
|
hasMore,
|
|
138
|
-
|
|
139
|
-
result.setSize
|
|
140
|
-
]);
|
|
141
|
-
return _object_spread_props(_object_spread({}, result), {
|
|
142
|
-
next: next,
|
|
143
|
-
hasMore: hasMore
|
|
144
|
-
});
|
|
57
|
+
};
|
|
145
58
|
};
|
|
146
59
|
export * from './utils.js';
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
package/dist/utils.js
CHANGED
|
@@ -1,108 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
if (
|
|
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)) {
|
|
1
|
+
export const makeQueryParams = (params) => {
|
|
2
|
+
if (params instanceof URLSearchParams) {
|
|
56
3
|
return params.toString();
|
|
57
4
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
}
|
|
5
|
+
const newParams = new URLSearchParams();
|
|
6
|
+
for (const [key, value] of Object.entries(params)) {
|
|
7
|
+
appendParam(newParams, key, value);
|
|
78
8
|
}
|
|
79
9
|
return newParams.toString();
|
|
80
10
|
};
|
|
81
|
-
|
|
11
|
+
const appendParam = (params, key, value) => {
|
|
82
12
|
if (Array.isArray(value)) {
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
}
|
|
13
|
+
for (const v of value) {
|
|
14
|
+
appendParam(params, key, v);
|
|
102
15
|
}
|
|
103
|
-
}
|
|
16
|
+
}
|
|
17
|
+
else if (value instanceof Date) {
|
|
104
18
|
params.append(key, value.toISOString());
|
|
105
|
-
}
|
|
19
|
+
}
|
|
20
|
+
else if (value !== undefined && value !== null) {
|
|
106
21
|
params.append(key, value.toString());
|
|
107
22
|
}
|
|
108
23
|
};
|
|
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.87",
|
|
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.
|
|
20
|
-
"@driveflux/config": "3.0.
|
|
21
|
-
"@driveflux/db": "4.1.
|
|
19
|
+
"@driveflux/auth": "4.0.86",
|
|
20
|
+
"@driveflux/config": "3.0.10",
|
|
21
|
+
"@driveflux/db": "4.1.18",
|
|
22
22
|
"@driveflux/fetch": "8.0.1",
|
|
23
23
|
"@driveflux/problem": "6.0.1",
|
|
24
24
|
"@driveflux/result": "6.0.1",
|