@ledgerhq/hw-transport-http 6.27.13 → 6.27.14-next.0
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/CHANGELOG.md +8 -0
- package/lib/HttpTransport.js +63 -137
- package/lib/HttpTransport.js.map +1 -1
- package/lib/WebSocketTransport.js +108 -178
- package/lib/WebSocketTransport.js.map +1 -1
- package/lib/withStaticURLs.d.ts +3 -3
- package/lib/withStaticURLs.d.ts.map +1 -1
- package/lib/withStaticURLs.js +59 -135
- package/lib/withStaticURLs.js.map +1 -1
- package/lib-es/HttpTransport.js +57 -132
- package/lib-es/HttpTransport.js.map +1 -1
- package/lib-es/WebSocketTransport.js +103 -174
- package/lib-es/WebSocketTransport.js.map +1 -1
- package/lib-es/withStaticURLs.d.ts +3 -3
- package/lib-es/withStaticURLs.d.ts.map +1 -1
- package/lib-es/withStaticURLs.js +55 -131
- package/lib-es/withStaticURLs.js.map +1 -1
- package/package.json +5 -6
package/lib/withStaticURLs.js
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -23,133 +8,72 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
9
|
});
|
|
25
10
|
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (_) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
13
|
};
|
|
56
|
-
exports
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
.then(function (urls) {
|
|
84
|
-
return Promise.all(urls.map(function (url) {
|
|
85
|
-
return getTransport(url)
|
|
86
|
-
.check(url)
|
|
87
|
-
.then(function () { return [url]; })["catch"](function () { return []; });
|
|
88
|
-
}));
|
|
89
|
-
})
|
|
90
|
-
.then(function (arrs) { return arrs.reduce(function (acc, a) { return acc.concat(a); }, []); });
|
|
91
|
-
};
|
|
92
|
-
StaticTransport.listen = function (observer) {
|
|
93
|
-
var unsubscribed = false;
|
|
94
|
-
var seen = {};
|
|
95
|
-
function checkLoop() {
|
|
96
|
-
var _this = this;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const HttpTransport_1 = __importDefault(require("./HttpTransport"));
|
|
16
|
+
const WebSocketTransport_1 = __importDefault(require("./WebSocketTransport"));
|
|
17
|
+
const hw_transport_1 = __importDefault(require("@ledgerhq/hw-transport"));
|
|
18
|
+
const getTransport = (url) => !url.startsWith("ws") ? HttpTransport_1.default : WebSocketTransport_1.default;
|
|
19
|
+
const inferURLs = (urls) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const r = yield (typeof urls === "function" ? urls() : urls);
|
|
21
|
+
return typeof r === "string" ? [r] : r;
|
|
22
|
+
});
|
|
23
|
+
exports.default = (urls) => {
|
|
24
|
+
class StaticTransport extends hw_transport_1.default {
|
|
25
|
+
}
|
|
26
|
+
StaticTransport.isSupported = HttpTransport_1.default.isSupported;
|
|
27
|
+
StaticTransport.list = () => inferURLs(urls)
|
|
28
|
+
.then((urls) => Promise.all(urls.map((url) => getTransport(url)
|
|
29
|
+
.check(url)
|
|
30
|
+
.then(() => [url])
|
|
31
|
+
.catch(() => []))))
|
|
32
|
+
.then((arrs) => arrs.reduce((acc, a) => acc.concat(a), []));
|
|
33
|
+
StaticTransport.listen = (observer) => {
|
|
34
|
+
let unsubscribed = false;
|
|
35
|
+
const seen = {};
|
|
36
|
+
function checkLoop() {
|
|
37
|
+
if (unsubscribed)
|
|
38
|
+
return;
|
|
39
|
+
inferURLs(urls)
|
|
40
|
+
.then((urls) => Promise.all(urls.map((url) => __awaiter(this, void 0, void 0, function* () {
|
|
97
41
|
if (unsubscribed)
|
|
98
42
|
return;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
observer.next({
|
|
119
|
-
type: "add",
|
|
120
|
-
descriptor: url
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
return [3 /*break*/, 4];
|
|
124
|
-
case 3:
|
|
125
|
-
e_1 = _a.sent();
|
|
126
|
-
// nothing
|
|
127
|
-
if (seen[url]) {
|
|
128
|
-
delete seen[url];
|
|
129
|
-
observer.next({
|
|
130
|
-
type: "remove",
|
|
131
|
-
descriptor: url
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
return [3 /*break*/, 4];
|
|
135
|
-
case 4: return [2 /*return*/];
|
|
136
|
-
}
|
|
43
|
+
try {
|
|
44
|
+
yield getTransport(url).check(url);
|
|
45
|
+
if (unsubscribed)
|
|
46
|
+
return;
|
|
47
|
+
if (!seen[url]) {
|
|
48
|
+
seen[url] = 1;
|
|
49
|
+
observer.next({
|
|
50
|
+
type: "add",
|
|
51
|
+
descriptor: url,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
// nothing
|
|
57
|
+
if (seen[url]) {
|
|
58
|
+
delete seen[url];
|
|
59
|
+
observer.next({
|
|
60
|
+
type: "remove",
|
|
61
|
+
descriptor: url,
|
|
137
62
|
});
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
.then(function () { return new Promise(function (success) { return setTimeout(success, 5000); }); })
|
|
141
|
-
.then(checkLoop);
|
|
142
|
-
}
|
|
143
|
-
checkLoop();
|
|
144
|
-
return {
|
|
145
|
-
unsubscribe: function () {
|
|
146
|
-
unsubscribed = true;
|
|
63
|
+
}
|
|
147
64
|
}
|
|
148
|
-
}
|
|
65
|
+
}))))
|
|
66
|
+
.then(() => new Promise((success) => setTimeout(success, 5000)))
|
|
67
|
+
.then(checkLoop);
|
|
68
|
+
}
|
|
69
|
+
checkLoop();
|
|
70
|
+
return {
|
|
71
|
+
unsubscribe: () => {
|
|
72
|
+
unsubscribed = true;
|
|
73
|
+
},
|
|
149
74
|
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}(hw_transport_1["default"]));
|
|
75
|
+
};
|
|
76
|
+
StaticTransport.open = (url) => getTransport(url).open(url);
|
|
153
77
|
return StaticTransport;
|
|
154
|
-
}
|
|
78
|
+
};
|
|
155
79
|
//# sourceMappingURL=withStaticURLs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withStaticURLs.js","sourceRoot":"","sources":["../src/withStaticURLs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withStaticURLs.js","sourceRoot":"","sources":["../src/withStaticURLs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,oEAA4C;AAC5C,8EAAsD;AACtD,0EAA+C;AAO/C,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,EAAE,CAC3B,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,uBAAa,CAAC,CAAC,CAAC,4BAAkB,CAAC;AAM7D,MAAM,SAAS,GAAG,CAAO,IAAQ,EAAqB,EAAE;IACtD,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC7D,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC,CAAA,CAAC;AAEF,kBAAe,CAAC,IAAQ,EAAoB,EAAE;IAC5C,MAAM,eAAgB,SAAQ,sBAAS;;IAC9B,2BAAW,GAAG,uBAAa,CAAC,WAAW,CAAC;IACxC,oBAAI,GAAG,GAAsB,EAAE,CACpC,SAAS,CAAC,IAAI,CAAC;SACZ,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CACb,OAAO,CAAC,GAAG,CACT,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACf,YAAY,CAAC,GAAG,CAAC;SACd,KAAK,CAAC,GAAG,CAAC;SACV,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;SACjB,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CACnB,CAC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OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;iBAC/D,IAAI,CAAC,SAAS,CAAC,CAAC;QACrB,CAAC;QAED,SAAS,EAAE,CAAC;QACZ,OAAO;YACL,WAAW,EAAE,GAAG,EAAE;gBAChB,YAAY,GAAG,IAAI,CAAC;YACtB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IACK,oBAAI,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAGrD,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC"}
|
package/lib-es/HttpTransport.js
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -22,33 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
22
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
8
|
});
|
|
24
9
|
};
|
|
25
|
-
var
|
|
26
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
27
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
28
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
29
|
-
function step(op) {
|
|
30
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
31
|
-
while (_) try {
|
|
32
|
-
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;
|
|
33
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
34
|
-
switch (op[0]) {
|
|
35
|
-
case 0: case 1: t = op; break;
|
|
36
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
37
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
38
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
39
|
-
default:
|
|
40
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
41
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
42
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
43
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
44
|
-
if (t[2]) _.ops.pop();
|
|
45
|
-
_.trys.pop(); continue;
|
|
46
|
-
}
|
|
47
|
-
op = body.call(thisArg, _);
|
|
48
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
49
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
|
-
}
|
|
51
|
-
};
|
|
10
|
+
var _a;
|
|
52
11
|
import Transport from "@ledgerhq/hw-transport";
|
|
53
12
|
import { TransportError } from "@ledgerhq/errors";
|
|
54
13
|
import axios from "axios";
|
|
@@ -56,98 +15,64 @@ import { log } from "@ledgerhq/logs";
|
|
|
56
15
|
/**
|
|
57
16
|
* HTTP transport implementation
|
|
58
17
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return _this;
|
|
65
|
-
}
|
|
66
|
-
HttpTransport.open = function (url, timeout) {
|
|
67
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
-
return __generator(this, function (_b) {
|
|
69
|
-
switch (_b.label) {
|
|
70
|
-
case 0: return [4 /*yield*/, HttpTransport.check(url, timeout)];
|
|
71
|
-
case 1:
|
|
72
|
-
_b.sent();
|
|
73
|
-
return [2 /*return*/, new HttpTransport(url)];
|
|
74
|
-
}
|
|
75
|
-
});
|
|
18
|
+
export default class HttpTransport extends Transport {
|
|
19
|
+
static open(url, timeout) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
yield HttpTransport.check(url, timeout);
|
|
22
|
+
return new HttpTransport(url);
|
|
76
23
|
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
})];
|
|
97
|
-
case 1:
|
|
98
|
-
response = _b.sent();
|
|
99
|
-
if (response.status !== 200) {
|
|
100
|
-
throw new TransportError("failed to communicate to server. code=" + response.status, "HttpTransportStatus" + response.status);
|
|
101
|
-
}
|
|
102
|
-
return [4 /*yield*/, response.data];
|
|
103
|
-
case 2:
|
|
104
|
-
body = _b.sent();
|
|
105
|
-
if (body.error)
|
|
106
|
-
throw body.error;
|
|
107
|
-
log("apdu", "<= " + body.data);
|
|
108
|
-
return [2 /*return*/, Buffer.from(body.data, "hex")];
|
|
109
|
-
}
|
|
24
|
+
}
|
|
25
|
+
constructor(url) {
|
|
26
|
+
super();
|
|
27
|
+
this.url = url;
|
|
28
|
+
}
|
|
29
|
+
exchange(apdu) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const apduHex = apdu.toString("hex");
|
|
32
|
+
log("apdu", "=> " + apduHex);
|
|
33
|
+
const response = yield axios({
|
|
34
|
+
method: "POST",
|
|
35
|
+
url: this.url,
|
|
36
|
+
headers: {
|
|
37
|
+
Accept: "application/json",
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
},
|
|
40
|
+
data: JSON.stringify({
|
|
41
|
+
apduHex,
|
|
42
|
+
}),
|
|
110
43
|
});
|
|
44
|
+
if (response.status !== 200) {
|
|
45
|
+
throw new TransportError("failed to communicate to server. code=" + response.status, "HttpTransportStatus" + response.status);
|
|
46
|
+
}
|
|
47
|
+
const body = yield response.data;
|
|
48
|
+
if (body.error)
|
|
49
|
+
throw body.error;
|
|
50
|
+
log("apdu", "<= " + body.data);
|
|
51
|
+
return Buffer.from(body.data, "hex");
|
|
111
52
|
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
53
|
+
}
|
|
54
|
+
setScrambleKey() { }
|
|
55
|
+
close() {
|
|
115
56
|
return Promise.resolve();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
case 1:
|
|
138
|
-
response = _b.sent();
|
|
139
|
-
if (response.status !== 200) {
|
|
140
|
-
throw new TransportError("failed to access HttpTransport(" +
|
|
141
|
-
url +
|
|
142
|
-
"): status " +
|
|
143
|
-
response.status, "HttpTransportNotAccessible");
|
|
144
|
-
}
|
|
145
|
-
return [2 /*return*/];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
return HttpTransport;
|
|
151
|
-
}(Transport));
|
|
152
|
-
export default HttpTransport;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
_a = HttpTransport;
|
|
60
|
+
HttpTransport.isSupported = () => Promise.resolve(typeof fetch === "function");
|
|
61
|
+
// this transport is not discoverable
|
|
62
|
+
HttpTransport.list = () => Promise.resolve([]);
|
|
63
|
+
HttpTransport.listen = (_observer) => ({
|
|
64
|
+
unsubscribe: () => { },
|
|
65
|
+
});
|
|
66
|
+
HttpTransport.check = (url, timeout = 5000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
const response = yield axios({
|
|
68
|
+
url,
|
|
69
|
+
timeout,
|
|
70
|
+
});
|
|
71
|
+
if (response.status !== 200) {
|
|
72
|
+
throw new TransportError("failed to access HttpTransport(" +
|
|
73
|
+
url +
|
|
74
|
+
"): status " +
|
|
75
|
+
response.status, "HttpTransportNotAccessible");
|
|
76
|
+
}
|
|
77
|
+
});
|
|
153
78
|
//# sourceMappingURL=HttpTransport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpTransport.js","sourceRoot":"","sources":["../src/HttpTransport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HttpTransport.js","sourceRoot":"","sources":["../src/HttpTransport.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC;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