@frontegg/rest-api 3.0.1 → 3.0.2
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/ContextHolder.js +64 -100
- package/account-settings/index.js +4 -43
- package/audits/index.js +16 -69
- package/auth/enums.js +2 -2
- package/auth/index.js +352 -2045
- package/auth/interfaces.js +1 -1
- package/auth/secutiry-poilicy/index.js +45 -254
- package/connectivity/index.js +79 -73
- package/constants.js +1 -1
- package/error.js +9 -33
- package/fetch.js +159 -519
- package/index.js +26 -26
- package/jwt.js +19 -45
- package/metadata/index.js +18 -160
- package/node/ContextHolder.js +68 -104
- package/node/account-settings/index.js +4 -46
- package/node/audits/index.js +15 -68
- package/node/auth/enums.js +2 -2
- package/node/auth/index.js +481 -2099
- package/node/auth/interfaces.js +2 -2
- package/node/auth/secutiry-poilicy/index.js +36 -240
- package/node/connectivity/index.js +78 -71
- package/node/constants.js +1 -1
- package/node/error.js +9 -38
- package/node/fetch.js +166 -521
- package/node/index.js +47 -49
- package/node/jwt.js +19 -51
- package/node/metadata/index.js +19 -163
- package/node/notifications/index.js +18 -94
- package/node/reports/index.js +62 -171
- package/node/roles/index.js +34 -172
- package/node/routers.js +2 -2
- package/node/sub-tenants/index.js +12 -126
- package/node/subscriptions/enums.js +4 -4
- package/node/subscriptions/index.js +10 -10
- package/node/subscriptions/interfaces.js +1 -1
- package/node/subscriptions/invoices.js +10 -70
- package/node/subscriptions/managedSubscriptions.js +16 -111
- package/node/subscriptions/paymentMethods.js +15 -69
- package/node/subscriptions/paymentProviders.js +2 -26
- package/node/subscriptions/plans.js +4 -46
- package/node/subscriptions/providers/index.js +1 -1
- package/node/subscriptions/providers/stripe/index.js +10 -106
- package/node/subscriptions/subscriptions.js +16 -111
- package/node/subscriptions/summaries.js +2 -26
- package/node/subscriptions/tenantConfiguration.js +4 -46
- package/node/teams/index.js +57 -406
- package/node/tenants/index.js +8 -86
- package/node/vendor/index.js +2 -26
- package/notifications/index.js +18 -93
- package/package.json +1 -1
- package/reports/index.js +65 -175
- package/roles/index.js +34 -175
- package/routers.js +2 -2
- package/sub-tenants/index.js +12 -127
- package/subscriptions/enums.js +4 -4
- package/subscriptions/invoices.js +12 -70
- package/subscriptions/managedSubscriptions.js +20 -115
- package/subscriptions/paymentMethods.js +16 -70
- package/subscriptions/paymentProviders.js +2 -22
- package/subscriptions/plans.js +4 -43
- package/subscriptions/providers/stripe/index.js +10 -106
- package/subscriptions/subscriptions.js +20 -115
- package/subscriptions/summaries.js +2 -22
- package/subscriptions/tenantConfiguration.js +4 -43
- package/teams/index.js +55 -421
- package/tenants/index.js +8 -85
- package/vendor/index.js +2 -23
package/node/fetch.js
CHANGED
|
@@ -8,26 +8,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.Put = exports.PostDownload = exports.Post = exports.Patch = exports.Get = exports.Delete = void 0;
|
|
9
9
|
exports.getBaseUrl = getBaseUrl;
|
|
10
10
|
|
|
11
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
12
|
-
|
|
13
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
14
|
-
|
|
15
11
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
16
12
|
|
|
17
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
18
|
-
|
|
19
13
|
var _ContextHolder = require("./ContextHolder");
|
|
20
14
|
|
|
21
15
|
var _error = require("./error");
|
|
22
16
|
|
|
23
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
24
|
-
|
|
25
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
26
|
-
|
|
27
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
28
|
-
|
|
29
17
|
function getBaseUrl(context, url) {
|
|
30
|
-
|
|
18
|
+
let baseUrl;
|
|
31
19
|
|
|
32
20
|
if (typeof context.baseUrl === 'function') {
|
|
33
21
|
baseUrl = context.baseUrl(url);
|
|
@@ -35,7 +23,7 @@ function getBaseUrl(context, url) {
|
|
|
35
23
|
baseUrl = context.baseUrl;
|
|
36
24
|
}
|
|
37
25
|
|
|
38
|
-
|
|
26
|
+
const prefix = context.urlPrefix || 'frontegg';
|
|
39
27
|
|
|
40
28
|
if (!baseUrl.endsWith('/')) {
|
|
41
29
|
baseUrl += '/';
|
|
@@ -48,542 +36,199 @@ function getBaseUrl(context, url) {
|
|
|
48
36
|
return baseUrl;
|
|
49
37
|
}
|
|
50
38
|
|
|
51
|
-
function prepareUrl(
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
async function prepareUrl(context, url, params) {
|
|
40
|
+
const baseUrl = getBaseUrl(context, url);
|
|
41
|
+
const paramsToSend = await buildQueryParams(context, params);
|
|
42
|
+
let finalUrl = url.startsWith('http') ? url : `${baseUrl}${url}`;
|
|
43
|
+
const hasKeys = Object.keys(paramsToSend).length > 0;
|
|
54
44
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
while (1) {
|
|
60
|
-
switch (_context8.prev = _context8.next) {
|
|
61
|
-
case 0:
|
|
62
|
-
baseUrl = getBaseUrl(context, url);
|
|
63
|
-
_context8.next = 3;
|
|
64
|
-
return buildQueryParams(context, params);
|
|
65
|
-
|
|
66
|
-
case 3:
|
|
67
|
-
paramsToSend = _context8.sent;
|
|
68
|
-
finalUrl = url.startsWith('http') ? url : "".concat(baseUrl).concat(url);
|
|
69
|
-
hasKeys = Object.keys(paramsToSend).length > 0;
|
|
70
|
-
|
|
71
|
-
if (paramsToSend && hasKeys) {
|
|
72
|
-
urlParams = new URLSearchParams(paramsToSend);
|
|
73
|
-
finalUrl += "?".concat(urlParams);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return _context8.abrupt("return", finalUrl);
|
|
77
|
-
|
|
78
|
-
case 8:
|
|
79
|
-
case "end":
|
|
80
|
-
return _context8.stop();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}, _callee8);
|
|
84
|
-
}));
|
|
85
|
-
return _prepareUrl.apply(this, arguments);
|
|
86
|
-
}
|
|
45
|
+
if (paramsToSend && hasKeys) {
|
|
46
|
+
const urlParams = new URLSearchParams(paramsToSend);
|
|
47
|
+
finalUrl += `?${urlParams}`;
|
|
48
|
+
}
|
|
87
49
|
|
|
88
|
-
|
|
89
|
-
return _buildRequestHeaders.apply(this, arguments);
|
|
50
|
+
return finalUrl;
|
|
90
51
|
}
|
|
91
52
|
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
var _context$tokenResolve;
|
|
95
|
-
|
|
96
|
-
var authToken, headers, _iterator, _step, additionalHeader;
|
|
97
|
-
|
|
98
|
-
return _regenerator["default"].wrap(function _callee9$(_context9) {
|
|
99
|
-
while (1) {
|
|
100
|
-
switch (_context9.prev = _context9.next) {
|
|
101
|
-
case 0:
|
|
102
|
-
_context9.next = 2;
|
|
103
|
-
return ((_context$tokenResolve = context == null ? void 0 : context.tokenResolver) != null ? _context$tokenResolve : _ContextHolder.ContextHolder.getAccessToken)();
|
|
104
|
-
|
|
105
|
-
case 2:
|
|
106
|
-
authToken = _context9.sent;
|
|
107
|
-
headers = {};
|
|
108
|
-
|
|
109
|
-
if (authToken) {
|
|
110
|
-
headers.Authorization = "Bearer ".concat(authToken);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (contentType) {
|
|
114
|
-
headers['Content-Type'] = contentType;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
_context9.t0 = _createForOfIteratorHelper;
|
|
118
|
-
_context9.next = 9;
|
|
119
|
-
return getAdditionalHeaders(context);
|
|
120
|
-
|
|
121
|
-
case 9:
|
|
122
|
-
_context9.t1 = _context9.sent;
|
|
123
|
-
_iterator = (0, _context9.t0)(_context9.t1);
|
|
124
|
-
|
|
125
|
-
try {
|
|
126
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
127
|
-
additionalHeader = _step.value;
|
|
128
|
-
headers["".concat(additionalHeader.key)] = "".concat(additionalHeader.value);
|
|
129
|
-
}
|
|
130
|
-
} catch (err) {
|
|
131
|
-
_iterator.e(err);
|
|
132
|
-
} finally {
|
|
133
|
-
_iterator.f();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
headers['x-frontegg-source'] = 'frontegg-react';
|
|
137
|
-
return _context9.abrupt("return", headers);
|
|
138
|
-
|
|
139
|
-
case 14:
|
|
140
|
-
case "end":
|
|
141
|
-
return _context9.stop();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}, _callee9);
|
|
145
|
-
}));
|
|
146
|
-
return _buildRequestHeaders.apply(this, arguments);
|
|
147
|
-
}
|
|
53
|
+
async function buildRequestHeaders(context, contentType) {
|
|
54
|
+
var _context$tokenResolve;
|
|
148
55
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
56
|
+
const authToken = await ((_context$tokenResolve = context == null ? void 0 : context.tokenResolver) != null ? _context$tokenResolve : _ContextHolder.ContextHolder.getAccessToken)();
|
|
57
|
+
const headers = {};
|
|
152
58
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
case 0:
|
|
161
|
-
if (!params) {
|
|
162
|
-
params = {};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
_context10.next = 3;
|
|
166
|
-
return getAdditionalQueryParams(context);
|
|
167
|
-
|
|
168
|
-
case 3:
|
|
169
|
-
additionalQueryParams = _context10.sent;
|
|
170
|
-
_iterator2 = _createForOfIteratorHelper(additionalQueryParams);
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
174
|
-
queryParam = _step2.value;
|
|
175
|
-
params[queryParam.key] = queryParam.value;
|
|
176
|
-
}
|
|
177
|
-
} catch (err) {
|
|
178
|
-
_iterator2.e(err);
|
|
179
|
-
} finally {
|
|
180
|
-
_iterator2.f();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
keys = Object.keys(params);
|
|
184
|
-
|
|
185
|
-
for (_i = 0, _keys = keys; _i < _keys.length; _i++) {
|
|
186
|
-
key = _keys[_i];
|
|
187
|
-
value = params[key];
|
|
188
|
-
params[key] = (0, _typeof2["default"])(value) === 'object' ? JSON.stringify(value) : value;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return _context10.abrupt("return", params);
|
|
192
|
-
|
|
193
|
-
case 9:
|
|
194
|
-
case "end":
|
|
195
|
-
return _context10.stop();
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}, _callee10);
|
|
199
|
-
}));
|
|
200
|
-
return _buildQueryParams.apply(this, arguments);
|
|
201
|
-
}
|
|
59
|
+
if (authToken) {
|
|
60
|
+
headers.Authorization = `Bearer ${authToken}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (contentType) {
|
|
64
|
+
headers['Content-Type'] = contentType;
|
|
65
|
+
}
|
|
202
66
|
|
|
203
|
-
|
|
204
|
-
|
|
67
|
+
for (const additionalHeader of await getAdditionalHeaders(context)) {
|
|
68
|
+
headers[`${additionalHeader.key}`] = `${additionalHeader.value}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
headers['x-frontegg-source'] = 'frontegg-react';
|
|
72
|
+
return headers;
|
|
205
73
|
}
|
|
206
74
|
|
|
207
|
-
function
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
case 5:
|
|
228
|
-
return _context11.abrupt("return", output);
|
|
229
|
-
|
|
230
|
-
case 6:
|
|
231
|
-
case "end":
|
|
232
|
-
return _context11.stop();
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}, _callee11);
|
|
236
|
-
}));
|
|
237
|
-
return _getAdditionalQueryParams.apply(this, arguments);
|
|
75
|
+
async function buildQueryParams(context, params) {
|
|
76
|
+
if (!params) {
|
|
77
|
+
params = {};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const additionalQueryParams = await getAdditionalQueryParams(context);
|
|
81
|
+
|
|
82
|
+
for (const queryParam of additionalQueryParams) {
|
|
83
|
+
params[queryParam.key] = queryParam.value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const keys = Object.keys(params);
|
|
87
|
+
|
|
88
|
+
for (const key of keys) {
|
|
89
|
+
const value = params[key];
|
|
90
|
+
params[key] = typeof value === 'object' ? JSON.stringify(value) : value;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return params;
|
|
238
94
|
}
|
|
239
95
|
|
|
240
|
-
function
|
|
241
|
-
|
|
96
|
+
async function getAdditionalQueryParams(context) {
|
|
97
|
+
let output = [];
|
|
98
|
+
|
|
99
|
+
if (context.additionalQueryParamsResolver) {
|
|
100
|
+
output = await context.additionalQueryParamsResolver();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return output;
|
|
242
104
|
}
|
|
243
105
|
|
|
244
|
-
function
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (!context.additionalHeadersResolver) {
|
|
254
|
-
_context12.next = 5;
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
_context12.next = 4;
|
|
259
|
-
return context.additionalHeadersResolver();
|
|
260
|
-
|
|
261
|
-
case 4:
|
|
262
|
-
output = _context12.sent;
|
|
263
|
-
|
|
264
|
-
case 5:
|
|
265
|
-
return _context12.abrupt("return", output);
|
|
266
|
-
|
|
267
|
-
case 6:
|
|
268
|
-
case "end":
|
|
269
|
-
return _context12.stop();
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}, _callee12);
|
|
273
|
-
}));
|
|
274
|
-
return _getAdditionalHeaders.apply(this, arguments);
|
|
106
|
+
async function getAdditionalHeaders(context) {
|
|
107
|
+
let output = [];
|
|
108
|
+
|
|
109
|
+
if (context.additionalHeadersResolver) {
|
|
110
|
+
output = await context.additionalHeadersResolver();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return output;
|
|
275
114
|
}
|
|
276
115
|
|
|
277
|
-
|
|
278
|
-
var _ref
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
_context.t0 = _context["catch"](18);
|
|
348
|
-
|
|
349
|
-
case 27:
|
|
350
|
-
if (errorMessage.errors) {
|
|
351
|
-
errorMessage = errorMessage.errors.join(', ');
|
|
352
|
-
} else if (typeof errorMessage !== 'string') {
|
|
353
|
-
errorMessage = "Error ".concat(response.status, " - ").concat(response.statusText);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
if (response.status >= 400 && response.status < 500 && ['warn'].includes((_context$logLevel = context.logLevel) != null ? _context$logLevel : '')) console.warn(errorMessage);else if (response.status === 500 && ['warn', 'error'].includes((_context$logLevel2 = context.logLevel) != null ? _context$logLevel2 : '')) console.error(errorMessage);
|
|
357
|
-
throw new _error.FronteggApiError(errorMessage, response.status);
|
|
358
|
-
|
|
359
|
-
case 30:
|
|
360
|
-
if (!(!opts.responseType || opts.responseType === 'json')) {
|
|
361
|
-
_context.next = 42;
|
|
362
|
-
break;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
_context.prev = 31;
|
|
366
|
-
_context.next = 34;
|
|
367
|
-
return response.json();
|
|
368
|
-
|
|
369
|
-
case 34:
|
|
370
|
-
return _context.abrupt("return", _context.sent);
|
|
371
|
-
|
|
372
|
-
case 37:
|
|
373
|
-
_context.prev = 37;
|
|
374
|
-
_context.t1 = _context["catch"](31);
|
|
375
|
-
return _context.abrupt("return", {});
|
|
376
|
-
|
|
377
|
-
case 40:
|
|
378
|
-
_context.next = 52;
|
|
379
|
-
break;
|
|
380
|
-
|
|
381
|
-
case 42:
|
|
382
|
-
if (!(opts.responseType === 'blob')) {
|
|
383
|
-
_context.next = 49;
|
|
384
|
-
break;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
outputFileName = opts.params.outputFileName;
|
|
388
|
-
_context.next = 46;
|
|
389
|
-
return response.blob().then(function (blob) {
|
|
390
|
-
return URL.createObjectURL(blob);
|
|
391
|
-
}).then(function (url) {
|
|
392
|
-
var tempLink = document.createElement('a');
|
|
393
|
-
tempLink.href = url;
|
|
394
|
-
tempLink.setAttribute('download', outputFileName || 'output');
|
|
395
|
-
tempLink.click();
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
case 46:
|
|
399
|
-
return _context.abrupt("return", _context.sent);
|
|
400
|
-
|
|
401
|
-
case 49:
|
|
402
|
-
_context.next = 51;
|
|
403
|
-
return response.text();
|
|
404
|
-
|
|
405
|
-
case 51:
|
|
406
|
-
return _context.abrupt("return", _context.sent);
|
|
407
|
-
|
|
408
|
-
case 52:
|
|
409
|
-
case "end":
|
|
410
|
-
return _context.stop();
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}, _callee, null, [[18, 25], [31, 37]]);
|
|
414
|
-
}));
|
|
415
|
-
|
|
416
|
-
return function sendRequest(_x10) {
|
|
417
|
-
return _ref.apply(this, arguments);
|
|
418
|
-
};
|
|
419
|
-
}();
|
|
420
|
-
|
|
421
|
-
var Get = function () {
|
|
422
|
-
var _ref3 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2(url, params, opts) {
|
|
423
|
-
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
424
|
-
while (1) {
|
|
425
|
-
switch (_context2.prev = _context2.next) {
|
|
426
|
-
case 0:
|
|
427
|
-
return _context2.abrupt("return", sendRequest((0, _extends2["default"])({
|
|
428
|
-
url: url,
|
|
429
|
-
method: 'GET',
|
|
430
|
-
contentType: 'application/json',
|
|
431
|
-
params: params
|
|
432
|
-
}, opts)));
|
|
433
|
-
|
|
434
|
-
case 1:
|
|
435
|
-
case "end":
|
|
436
|
-
return _context2.stop();
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}, _callee2);
|
|
440
|
-
}));
|
|
441
|
-
|
|
442
|
-
return function Get(_x11, _x12, _x13) {
|
|
443
|
-
return _ref3.apply(this, arguments);
|
|
444
|
-
};
|
|
445
|
-
}();
|
|
116
|
+
const sendRequest = async opts => {
|
|
117
|
+
var _opts$method, _ref, _opts$credentials;
|
|
118
|
+
|
|
119
|
+
const context = _ContextHolder.ContextHolder.getContext();
|
|
120
|
+
|
|
121
|
+
const headers = await buildRequestHeaders(context, opts.contentType);
|
|
122
|
+
const url = await prepareUrl(context, opts.url, opts.params);
|
|
123
|
+
const response = await fetch(url, {
|
|
124
|
+
body: opts.body ? opts.contentType === 'application/json' ? JSON.stringify(opts.body) : opts.body : null,
|
|
125
|
+
method: (_opts$method = opts.method) != null ? _opts$method : 'GET',
|
|
126
|
+
headers: (0, _extends2.default)({}, headers, opts.headers),
|
|
127
|
+
credentials: (_ref = (_opts$credentials = opts.credentials) != null ? _opts$credentials : context.requestCredentials) != null ? _ref : 'same-origin'
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
if (response.status === 302) {
|
|
131
|
+
window.location.href = await response.text();
|
|
132
|
+
return new Promise(() => {});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!response.ok) {
|
|
136
|
+
var _context$logLevel, _context$logLevel2;
|
|
137
|
+
|
|
138
|
+
if (response.status === 413) {
|
|
139
|
+
throw new _error.FronteggApiError('Error request is too large', response.status);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let errorMessage;
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
errorMessage = await response.text();
|
|
146
|
+
errorMessage = JSON.parse(errorMessage);
|
|
147
|
+
} catch (e) {}
|
|
148
|
+
|
|
149
|
+
if (errorMessage.errors) {
|
|
150
|
+
errorMessage = errorMessage.errors.join(', ');
|
|
151
|
+
} else if (typeof errorMessage !== 'string') {
|
|
152
|
+
errorMessage = `Error ${response.status} - ${response.statusText}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (response.status >= 400 && response.status < 500 && ['warn'].includes((_context$logLevel = context.logLevel) != null ? _context$logLevel : '')) console.warn(errorMessage);else if (response.status === 500 && ['warn', 'error'].includes((_context$logLevel2 = context.logLevel) != null ? _context$logLevel2 : '')) console.error(errorMessage);
|
|
156
|
+
throw new _error.FronteggApiError(errorMessage, response.status);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (!opts.responseType || opts.responseType === 'json') {
|
|
160
|
+
try {
|
|
161
|
+
return await response.json();
|
|
162
|
+
} catch (e) {
|
|
163
|
+
return {};
|
|
164
|
+
}
|
|
165
|
+
} else if (opts.responseType === 'blob') {
|
|
166
|
+
const {
|
|
167
|
+
outputFileName
|
|
168
|
+
} = opts.params;
|
|
169
|
+
return await response.blob().then(blob => URL.createObjectURL(blob)).then(url => {
|
|
170
|
+
const tempLink = document.createElement('a');
|
|
171
|
+
tempLink.href = url;
|
|
172
|
+
tempLink.setAttribute('download', outputFileName || 'output');
|
|
173
|
+
tempLink.click();
|
|
174
|
+
});
|
|
175
|
+
} else {
|
|
176
|
+
return await response.text();
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const Get = async (url, params, opts) => sendRequest((0, _extends2.default)({
|
|
181
|
+
url,
|
|
182
|
+
method: 'GET',
|
|
183
|
+
contentType: 'application/json',
|
|
184
|
+
params
|
|
185
|
+
}, opts));
|
|
446
186
|
|
|
447
187
|
exports.Get = Get;
|
|
448
188
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
return _context3.abrupt("return", sendRequest((0, _extends2["default"])({
|
|
456
|
-
url: url,
|
|
457
|
-
method: 'POST',
|
|
458
|
-
contentType: 'application/json',
|
|
459
|
-
body: body
|
|
460
|
-
}, opts)));
|
|
461
|
-
|
|
462
|
-
case 1:
|
|
463
|
-
case "end":
|
|
464
|
-
return _context3.stop();
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}, _callee3);
|
|
468
|
-
}));
|
|
469
|
-
|
|
470
|
-
return function Post(_x14, _x15, _x16) {
|
|
471
|
-
return _ref4.apply(this, arguments);
|
|
472
|
-
};
|
|
473
|
-
}();
|
|
189
|
+
const Post = async (url, body, opts) => sendRequest((0, _extends2.default)({
|
|
190
|
+
url,
|
|
191
|
+
method: 'POST',
|
|
192
|
+
contentType: 'application/json',
|
|
193
|
+
body
|
|
194
|
+
}, opts));
|
|
474
195
|
|
|
475
196
|
exports.Post = Post;
|
|
476
197
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
return _context4.abrupt("return", sendRequest((0, _extends2["default"])({
|
|
484
|
-
url: url,
|
|
485
|
-
method: 'PATCH',
|
|
486
|
-
contentType: 'application/json',
|
|
487
|
-
body: body
|
|
488
|
-
}, opts)));
|
|
489
|
-
|
|
490
|
-
case 1:
|
|
491
|
-
case "end":
|
|
492
|
-
return _context4.stop();
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}, _callee4);
|
|
496
|
-
}));
|
|
497
|
-
|
|
498
|
-
return function Patch(_x17, _x18, _x19) {
|
|
499
|
-
return _ref5.apply(this, arguments);
|
|
500
|
-
};
|
|
501
|
-
}();
|
|
198
|
+
const Patch = async (url, body, opts) => sendRequest((0, _extends2.default)({
|
|
199
|
+
url,
|
|
200
|
+
method: 'PATCH',
|
|
201
|
+
contentType: 'application/json',
|
|
202
|
+
body
|
|
203
|
+
}, opts));
|
|
502
204
|
|
|
503
205
|
exports.Patch = Patch;
|
|
504
206
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
return _context5.abrupt("return", sendRequest((0, _extends2["default"])({
|
|
512
|
-
url: url,
|
|
513
|
-
method: 'PUT',
|
|
514
|
-
contentType: 'application/json',
|
|
515
|
-
body: body
|
|
516
|
-
}, opts)));
|
|
517
|
-
|
|
518
|
-
case 1:
|
|
519
|
-
case "end":
|
|
520
|
-
return _context5.stop();
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}, _callee5);
|
|
524
|
-
}));
|
|
525
|
-
|
|
526
|
-
return function Put(_x20, _x21, _x22) {
|
|
527
|
-
return _ref6.apply(this, arguments);
|
|
528
|
-
};
|
|
529
|
-
}();
|
|
207
|
+
const Put = async (url, body, opts) => sendRequest((0, _extends2.default)({
|
|
208
|
+
url,
|
|
209
|
+
method: 'PUT',
|
|
210
|
+
contentType: 'application/json',
|
|
211
|
+
body
|
|
212
|
+
}, opts));
|
|
530
213
|
|
|
531
214
|
exports.Put = Put;
|
|
532
215
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
return _context6.abrupt("return", sendRequest((0, _extends2["default"])({
|
|
540
|
-
url: url,
|
|
541
|
-
method: 'DELETE',
|
|
542
|
-
contentType: 'application/json',
|
|
543
|
-
body: body
|
|
544
|
-
}, opts)));
|
|
545
|
-
|
|
546
|
-
case 1:
|
|
547
|
-
case "end":
|
|
548
|
-
return _context6.stop();
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}, _callee6);
|
|
552
|
-
}));
|
|
553
|
-
|
|
554
|
-
return function Delete(_x23, _x24, _x25) {
|
|
555
|
-
return _ref7.apply(this, arguments);
|
|
556
|
-
};
|
|
557
|
-
}();
|
|
216
|
+
const Delete = async (url, body, opts) => sendRequest((0, _extends2.default)({
|
|
217
|
+
url,
|
|
218
|
+
method: 'DELETE',
|
|
219
|
+
contentType: 'application/json',
|
|
220
|
+
body
|
|
221
|
+
}, opts));
|
|
558
222
|
|
|
559
223
|
exports.Delete = Delete;
|
|
560
224
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
method: 'POST',
|
|
570
|
-
contentType: 'application/json',
|
|
571
|
-
responseType: 'blob',
|
|
572
|
-
body: body,
|
|
573
|
-
params: params
|
|
574
|
-
}, opts)));
|
|
575
|
-
|
|
576
|
-
case 1:
|
|
577
|
-
case "end":
|
|
578
|
-
return _context7.stop();
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}, _callee7);
|
|
582
|
-
}));
|
|
583
|
-
|
|
584
|
-
return function PostDownload(_x26, _x27, _x28, _x29) {
|
|
585
|
-
return _ref8.apply(this, arguments);
|
|
586
|
-
};
|
|
587
|
-
}();
|
|
225
|
+
const PostDownload = async (url, body, params, opts) => sendRequest((0, _extends2.default)({
|
|
226
|
+
url,
|
|
227
|
+
method: 'POST',
|
|
228
|
+
contentType: 'application/json',
|
|
229
|
+
responseType: 'blob',
|
|
230
|
+
body,
|
|
231
|
+
params
|
|
232
|
+
}, opts));
|
|
588
233
|
|
|
589
234
|
exports.PostDownload = PostDownload;
|