1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | exports.fetchAsync = void 0;
|
13 | const isNode = require("detect-node");
|
14 | require("isomorphic-fetch");
|
15 |
|
16 |
|
17 | require("abortcontroller-polyfill/dist/abortcontroller-polyfill-only");
|
18 | const fetchAsync = (endpoint, options = {}, timeoutMs = 20000) => __awaiter(void 0, void 0, void 0, function* () {
|
19 | if (options.signal || options.timeout) {
|
20 | throw new Error('Cannot call fetchAsync with options.signal or options.timeout. To set a timeout, please use the supplied "timeoutMs" parameter.');
|
21 | }
|
22 | let optionsWithAbortParam;
|
23 | if (!isNode) {
|
24 | const controller = new AbortController();
|
25 | const signal = controller.signal;
|
26 | setTimeout(() => {
|
27 | controller.abort();
|
28 | }, timeoutMs);
|
29 | optionsWithAbortParam = Object.assign({ signal }, options);
|
30 | }
|
31 | else {
|
32 |
|
33 |
|
34 |
|
35 | optionsWithAbortParam = Object.assign({ timeout: timeoutMs }, options);
|
36 | }
|
37 | const response = yield fetch(endpoint, optionsWithAbortParam);
|
38 | return response;
|
39 | });
|
40 | exports.fetchAsync = fetchAsync;
|
41 |
|
\ | No newline at end of file |