@portal-hq/utils 0.2.12 → 0.2.14
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/lib/commonjs/errors/invalid-rpc-config-error.js +10 -0
- package/lib/esm/errors/invalid-rpc-config-error.js +26 -0
- package/package.json +1 -1
- package/lib/currency/countries/country-codes.js +0 -248
- package/lib/currency/countries/currency-codes.js +0 -246
- package/lib/currency/countries/index.js +0 -2
- package/lib/currency/index.js +0 -25
- package/lib/definitions/index.js +0 -4
- package/lib/errors/http-error.js +0 -8
- package/lib/errors/index.js +0 -8
- package/lib/errors/invalid-api-key-error.js +0 -8
- package/lib/errors/invalid-chain-id-error.js +0 -8
- package/lib/errors/invalid-gateway-config-error.js +0 -8
- package/lib/errors/missing-option-error.js +0 -8
- package/lib/errors/mpc-signing-error.js +0 -8
- package/lib/errors/no-address-error.js +0 -8
- package/lib/errors/provider-rpc-error.js +0 -49
- package/lib/eth-requests/index.js +0 -83
- package/lib/http-request/index.js +0 -70
- package/lib/index.js +0 -6
- package/lib/requesters/http.js +0 -50
- package/lib/requesters/index.js +0 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class InvalidRpcConfigError extends Error {
|
|
4
|
+
constructor() {
|
|
5
|
+
super('[Portal] A valid RPC configuration was not provided.');
|
|
6
|
+
// Set the prototype explicitly.
|
|
7
|
+
Object.setPrototypeOf(this, InvalidRpcConfigError.prototype);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.default = InvalidRpcConfigError;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
var InvalidRpcConfigError = /** @class */ (function (_super) {
|
|
17
|
+
__extends(InvalidRpcConfigError, _super);
|
|
18
|
+
function InvalidRpcConfigError() {
|
|
19
|
+
var _this = _super.call(this, '[Portal] A valid RPC configuration was not provided.') || this;
|
|
20
|
+
// Set the prototype explicitly.
|
|
21
|
+
Object.setPrototypeOf(_this, InvalidRpcConfigError.prototype);
|
|
22
|
+
return _this;
|
|
23
|
+
}
|
|
24
|
+
return InvalidRpcConfigError;
|
|
25
|
+
}(Error));
|
|
26
|
+
export default InvalidRpcConfigError;
|
package/package.json
CHANGED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
const countryCodes = {
|
|
2
|
-
AD: 'Andorra',
|
|
3
|
-
AE: 'United Arab Emirates',
|
|
4
|
-
AF: 'Afghanistan',
|
|
5
|
-
AG: 'Antigua and Barbuda',
|
|
6
|
-
AI: 'Anguilla',
|
|
7
|
-
AL: 'Albania',
|
|
8
|
-
AM: 'Armenia',
|
|
9
|
-
AN: 'Netherlands Antilles',
|
|
10
|
-
AO: 'Angola',
|
|
11
|
-
AQ: 'Antarctica',
|
|
12
|
-
AR: 'Argentina',
|
|
13
|
-
AS: 'American Samoa',
|
|
14
|
-
AT: 'Austria',
|
|
15
|
-
AU: 'Australia',
|
|
16
|
-
AW: 'Aruba',
|
|
17
|
-
AZ: 'Azerbaijan',
|
|
18
|
-
BA: 'Bosnia and Herzegovina',
|
|
19
|
-
BB: 'Barbados',
|
|
20
|
-
BD: 'Bangladesh',
|
|
21
|
-
BE: 'Belgium',
|
|
22
|
-
BF: 'Burkina Faso',
|
|
23
|
-
BG: 'Bulgaria',
|
|
24
|
-
BH: 'Bahrain',
|
|
25
|
-
BI: 'Burundi',
|
|
26
|
-
BJ: 'Benin',
|
|
27
|
-
BM: 'Bermuda',
|
|
28
|
-
BN: 'Brunei',
|
|
29
|
-
BO: 'Bolivia',
|
|
30
|
-
BR: 'Brazil',
|
|
31
|
-
BS: 'Bahamas',
|
|
32
|
-
BT: 'Bhutan',
|
|
33
|
-
BV: 'Bouvet Island',
|
|
34
|
-
BW: 'Botswana',
|
|
35
|
-
BY: 'Belarus',
|
|
36
|
-
BZ: 'Belize',
|
|
37
|
-
CA: 'Canada',
|
|
38
|
-
CC: 'Cocos (Keeling) Islands',
|
|
39
|
-
CD: 'The Democratic Republic of Congo',
|
|
40
|
-
CF: 'Central African Republic',
|
|
41
|
-
CG: 'Congo',
|
|
42
|
-
CH: 'Switzerland',
|
|
43
|
-
CI: 'Ivory Coast',
|
|
44
|
-
CK: 'Cook Islands',
|
|
45
|
-
CL: 'Chile',
|
|
46
|
-
CM: 'Cameroon',
|
|
47
|
-
CN: 'China',
|
|
48
|
-
CO: 'Colombia',
|
|
49
|
-
CR: 'Costa Rica',
|
|
50
|
-
CU: 'Cuba',
|
|
51
|
-
CV: 'Cape Verde',
|
|
52
|
-
CX: 'Christmas Island',
|
|
53
|
-
CY: 'Cyprus',
|
|
54
|
-
CZ: 'Czech Republic',
|
|
55
|
-
DE: 'Germany',
|
|
56
|
-
DJ: 'Djibouti',
|
|
57
|
-
DK: 'Denmark',
|
|
58
|
-
DM: 'Dominica',
|
|
59
|
-
DO: 'Dominican Republic',
|
|
60
|
-
DZ: 'Algeria',
|
|
61
|
-
EC: 'Ecuador',
|
|
62
|
-
EE: 'Estonia',
|
|
63
|
-
EG: 'Egypt',
|
|
64
|
-
EH: 'Western Sahara',
|
|
65
|
-
ER: 'Eritrea',
|
|
66
|
-
ES: 'Spain',
|
|
67
|
-
ET: 'Ethiopia',
|
|
68
|
-
FI: 'Finland',
|
|
69
|
-
FJ: 'Fiji Islands',
|
|
70
|
-
FK: 'Falkland Islands',
|
|
71
|
-
FM: 'Micronesia, Federated States of',
|
|
72
|
-
FO: 'Faroe Islands',
|
|
73
|
-
FR: 'France',
|
|
74
|
-
GA: 'Gabon',
|
|
75
|
-
GB: 'Northern Ireland',
|
|
76
|
-
GD: 'Grenada',
|
|
77
|
-
GE: 'Georgia',
|
|
78
|
-
GF: 'French Guiana',
|
|
79
|
-
GG: 'Guernsey',
|
|
80
|
-
GH: 'Ghana',
|
|
81
|
-
GI: 'Gibraltar',
|
|
82
|
-
GL: 'Greenland',
|
|
83
|
-
GM: 'Gambia',
|
|
84
|
-
GN: 'Guinea',
|
|
85
|
-
GP: 'Guadeloupe',
|
|
86
|
-
GQ: 'Equatorial Guinea',
|
|
87
|
-
GR: 'Greece',
|
|
88
|
-
GS: 'South Georgia and the South Sandwich Islands',
|
|
89
|
-
GT: 'Guatemala',
|
|
90
|
-
GU: 'Guam',
|
|
91
|
-
GW: 'Guinea-Bissau',
|
|
92
|
-
GY: 'Guyana',
|
|
93
|
-
HK: 'Hong Kong',
|
|
94
|
-
HM: 'Heard Island and McDonald Islands',
|
|
95
|
-
HN: 'Honduras',
|
|
96
|
-
HR: 'Croatia',
|
|
97
|
-
HT: 'Haiti',
|
|
98
|
-
HU: 'Hungary',
|
|
99
|
-
ID: 'Indonesia',
|
|
100
|
-
IE: 'Ireland',
|
|
101
|
-
IL: 'Israel',
|
|
102
|
-
IM: 'Isle of Man',
|
|
103
|
-
IN: 'India',
|
|
104
|
-
IO: 'British Indian Ocean Territory',
|
|
105
|
-
IQ: 'Iraq',
|
|
106
|
-
IR: 'Iran',
|
|
107
|
-
IS: 'Iceland',
|
|
108
|
-
IT: 'Italy',
|
|
109
|
-
JE: 'Jersey',
|
|
110
|
-
JM: 'Jamaica',
|
|
111
|
-
JO: 'Jordan',
|
|
112
|
-
JP: 'Japan',
|
|
113
|
-
KE: 'Kenya',
|
|
114
|
-
KG: 'Kyrgyzstan',
|
|
115
|
-
KH: 'Cambodia',
|
|
116
|
-
KI: 'Kiribati',
|
|
117
|
-
KM: 'Comoros',
|
|
118
|
-
KN: 'Saint Kitts and Nevis',
|
|
119
|
-
KP: 'North Korea',
|
|
120
|
-
KR: 'South Korea',
|
|
121
|
-
KW: 'Kuwait',
|
|
122
|
-
KY: 'Cayman Islands',
|
|
123
|
-
KZ: 'Kazakhstan',
|
|
124
|
-
LA: 'Laos',
|
|
125
|
-
LB: 'Lebanon',
|
|
126
|
-
LC: 'Saint Lucia',
|
|
127
|
-
LI: 'Liechtenstein',
|
|
128
|
-
LK: 'Sri Lanka',
|
|
129
|
-
LR: 'Liberia',
|
|
130
|
-
LS: 'Lesotho',
|
|
131
|
-
LT: 'Lithuania',
|
|
132
|
-
LU: 'Luxembourg',
|
|
133
|
-
LV: 'Latvia',
|
|
134
|
-
LY: 'Libyan Arab Jamahiriya',
|
|
135
|
-
MA: 'Morocco',
|
|
136
|
-
MC: 'Monaco',
|
|
137
|
-
MD: 'Moldova',
|
|
138
|
-
ME: 'Montenegro',
|
|
139
|
-
MG: 'Madagascar',
|
|
140
|
-
MH: 'Marshall Islands',
|
|
141
|
-
MK: 'North Macedonia',
|
|
142
|
-
ML: 'Mali',
|
|
143
|
-
MM: 'Myanmar',
|
|
144
|
-
MN: 'Mongolia',
|
|
145
|
-
MO: 'Macao',
|
|
146
|
-
MP: 'Northern Mariana Islands',
|
|
147
|
-
MQ: 'Martinique',
|
|
148
|
-
MR: 'Mauritania',
|
|
149
|
-
MS: 'Montserrat',
|
|
150
|
-
MT: 'Malta',
|
|
151
|
-
MU: 'Mauritius',
|
|
152
|
-
MV: 'Maldives',
|
|
153
|
-
MW: 'Malawi',
|
|
154
|
-
MX: 'Mexico',
|
|
155
|
-
MY: 'Malaysia',
|
|
156
|
-
MZ: 'Mozambique',
|
|
157
|
-
NA: 'Namibia',
|
|
158
|
-
NC: 'New Caledonia',
|
|
159
|
-
NE: 'Niger',
|
|
160
|
-
NF: 'Norfolk Island',
|
|
161
|
-
NG: 'Nigeria',
|
|
162
|
-
NI: 'Nicaragua',
|
|
163
|
-
NL: 'Netherlands',
|
|
164
|
-
NO: 'Norway',
|
|
165
|
-
NP: 'Nepal',
|
|
166
|
-
NR: 'Nauru',
|
|
167
|
-
NU: 'Niue',
|
|
168
|
-
NZ: 'New Zealand',
|
|
169
|
-
OM: 'Oman',
|
|
170
|
-
PA: 'Panama',
|
|
171
|
-
PE: 'Peru',
|
|
172
|
-
PF: 'French Polynesia',
|
|
173
|
-
PG: 'Papua New Guinea',
|
|
174
|
-
PH: 'Philippines',
|
|
175
|
-
PK: 'Pakistan',
|
|
176
|
-
PL: 'Poland',
|
|
177
|
-
PM: 'Saint Pierre and Miquelon',
|
|
178
|
-
PN: 'Pitcairn',
|
|
179
|
-
PR: 'Puerto Rico',
|
|
180
|
-
PS: 'Palestine',
|
|
181
|
-
PT: 'Portugal',
|
|
182
|
-
PW: 'Palau',
|
|
183
|
-
PY: 'Paraguay',
|
|
184
|
-
QA: 'Qatar',
|
|
185
|
-
RE: 'Reunion',
|
|
186
|
-
RO: 'Romania',
|
|
187
|
-
RS: 'Serbia',
|
|
188
|
-
RU: 'Russian Federation',
|
|
189
|
-
RW: 'Rwanda',
|
|
190
|
-
SA: 'Saudi Arabia',
|
|
191
|
-
SB: 'Solomon Islands',
|
|
192
|
-
SC: 'Seychelles',
|
|
193
|
-
SD: 'Sudan',
|
|
194
|
-
SE: 'Sweden',
|
|
195
|
-
SG: 'Singapore',
|
|
196
|
-
SH: 'Saint Helena',
|
|
197
|
-
SI: 'Slovenia',
|
|
198
|
-
SJ: 'Svalbard and Jan Mayen',
|
|
199
|
-
SK: 'Slovakia',
|
|
200
|
-
SL: 'Sierra Leone',
|
|
201
|
-
SM: 'San Marino',
|
|
202
|
-
SN: 'Senegal',
|
|
203
|
-
SO: 'Somalia',
|
|
204
|
-
SR: 'Suriname',
|
|
205
|
-
SS: 'South Sudan',
|
|
206
|
-
ST: 'Sao Tome and Principe',
|
|
207
|
-
SV: 'El Salvador',
|
|
208
|
-
SY: 'Syria',
|
|
209
|
-
SZ: 'Swaziland',
|
|
210
|
-
TC: 'Turks and Caicos Islands',
|
|
211
|
-
TD: 'Chad',
|
|
212
|
-
TF: 'French Southern territories',
|
|
213
|
-
TG: 'Togo',
|
|
214
|
-
TH: 'Thailand',
|
|
215
|
-
TJ: 'Tajikistan',
|
|
216
|
-
TK: 'Tokelau',
|
|
217
|
-
TL: 'Timor-Leste',
|
|
218
|
-
TM: 'Turkmenistan',
|
|
219
|
-
TN: 'Tunisia',
|
|
220
|
-
TO: 'Tonga',
|
|
221
|
-
TP: 'East Timor',
|
|
222
|
-
TR: 'Turkey',
|
|
223
|
-
TT: 'Trinidad and Tobago',
|
|
224
|
-
TV: 'Tuvalu',
|
|
225
|
-
TZ: 'Tanzania',
|
|
226
|
-
UA: 'Ukraine',
|
|
227
|
-
UG: 'Uganda',
|
|
228
|
-
UK: 'United Kingdom',
|
|
229
|
-
UM: 'United States Minor Outlying Islands',
|
|
230
|
-
US: 'United States',
|
|
231
|
-
UY: 'Uruguay',
|
|
232
|
-
UZ: 'Uzbekistan',
|
|
233
|
-
VA: 'Holy See (Vatican City State)',
|
|
234
|
-
VC: 'Saint Vincent and the Grenadines',
|
|
235
|
-
VE: 'Venezuela',
|
|
236
|
-
VG: 'Virgin Islands, British',
|
|
237
|
-
VI: 'Virgin Islands, U.S.',
|
|
238
|
-
VN: 'Vietnam',
|
|
239
|
-
VU: 'Vanuatu',
|
|
240
|
-
WF: 'Wallis and Futuna',
|
|
241
|
-
WS: 'Samoa',
|
|
242
|
-
YE: 'Yemen',
|
|
243
|
-
YT: 'Mayotte',
|
|
244
|
-
ZA: 'South Africa',
|
|
245
|
-
ZM: 'Zambia',
|
|
246
|
-
ZW: 'Zimbabwe',
|
|
247
|
-
};
|
|
248
|
-
export default countryCodes;
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
const currencyCodes = {
|
|
2
|
-
Afghanistan: 'AFN',
|
|
3
|
-
Albania: 'ALL',
|
|
4
|
-
Algeria: 'DZD',
|
|
5
|
-
'American Samoa': 'USD',
|
|
6
|
-
Andorra: 'EUR',
|
|
7
|
-
Angola: 'AOA',
|
|
8
|
-
Anguilla: 'XCD',
|
|
9
|
-
Antarctica: 'XCD',
|
|
10
|
-
'Antigua and Barbuda': 'XCD',
|
|
11
|
-
Argentina: 'ARS',
|
|
12
|
-
Armenia: 'AMD',
|
|
13
|
-
Aruba: 'AWG',
|
|
14
|
-
Australia: 'AUD',
|
|
15
|
-
Austria: 'EUR',
|
|
16
|
-
Azerbaijan: 'AZN',
|
|
17
|
-
Bahamas: 'BSD',
|
|
18
|
-
Bahrain: 'BHD',
|
|
19
|
-
Bangladesh: 'BDT',
|
|
20
|
-
Barbados: 'BBD',
|
|
21
|
-
Belarus: 'BYR',
|
|
22
|
-
Belgium: 'EUR',
|
|
23
|
-
Belize: 'BZD',
|
|
24
|
-
Benin: 'XOF',
|
|
25
|
-
Bermuda: 'BMD',
|
|
26
|
-
Bhutan: 'BTN',
|
|
27
|
-
Bolivia: 'BOB',
|
|
28
|
-
'Bosnia and Herzegovina': 'BAM',
|
|
29
|
-
Botswana: 'BWP',
|
|
30
|
-
'Bouvet Island': 'NOK',
|
|
31
|
-
Brazil: 'BRL',
|
|
32
|
-
'British Indian Ocean Territory': 'USD',
|
|
33
|
-
Brunei: 'BND',
|
|
34
|
-
Bulgaria: 'BGN',
|
|
35
|
-
'Burkina Faso': 'XOF',
|
|
36
|
-
Burundi: 'BIF',
|
|
37
|
-
Cambodia: 'KHR',
|
|
38
|
-
Cameroon: 'XAF',
|
|
39
|
-
Canada: 'CAD',
|
|
40
|
-
'Cape Verde': 'CVE',
|
|
41
|
-
'Cayman Islands': 'KYD',
|
|
42
|
-
'Central African Republic': 'XAF',
|
|
43
|
-
Chad: 'XAF',
|
|
44
|
-
Chile: 'CLP',
|
|
45
|
-
China: 'CNY',
|
|
46
|
-
'Christmas Island': 'AUD',
|
|
47
|
-
'Cocos (Keeling) Islands': 'AUD',
|
|
48
|
-
Colombia: 'COP',
|
|
49
|
-
Comoros: 'KMF',
|
|
50
|
-
Congo: 'XAF',
|
|
51
|
-
'Cook Islands': 'NZD',
|
|
52
|
-
'Costa Rica': 'CRC',
|
|
53
|
-
Croatia: 'HRK',
|
|
54
|
-
Cuba: 'CUP',
|
|
55
|
-
Cyprus: 'EUR',
|
|
56
|
-
'Czech Republic': 'CZK',
|
|
57
|
-
Denmark: 'DKK',
|
|
58
|
-
Djibouti: 'DJF',
|
|
59
|
-
Dominica: 'XCD',
|
|
60
|
-
'Dominican Republic': 'DOP',
|
|
61
|
-
'East Timor': 'USD',
|
|
62
|
-
Ecuador: 'ECS',
|
|
63
|
-
Egypt: 'EGP',
|
|
64
|
-
'El Salvador': 'SVC',
|
|
65
|
-
England: 'GBP',
|
|
66
|
-
'Equatorial Guinea': 'XAF',
|
|
67
|
-
Eritrea: 'ERN',
|
|
68
|
-
Estonia: 'EUR',
|
|
69
|
-
Ethiopia: 'ETB',
|
|
70
|
-
'Falkland Islands': 'FKP',
|
|
71
|
-
'Faroe Islands': 'DKK',
|
|
72
|
-
'Fiji Islands': 'FJD',
|
|
73
|
-
Finland: 'EUR',
|
|
74
|
-
France: 'EUR',
|
|
75
|
-
'French Guiana': 'EUR',
|
|
76
|
-
'French Polynesia': 'XPF',
|
|
77
|
-
'French Southern territories': 'EUR',
|
|
78
|
-
Gabon: 'XAF',
|
|
79
|
-
Gambia: 'GMD',
|
|
80
|
-
Georgia: 'GEL',
|
|
81
|
-
Germany: 'EUR',
|
|
82
|
-
Ghana: 'GHS',
|
|
83
|
-
Gibraltar: 'GIP',
|
|
84
|
-
Greece: 'EUR',
|
|
85
|
-
Greenland: 'DKK',
|
|
86
|
-
Grenada: 'XCD',
|
|
87
|
-
Guadeloupe: 'EUR',
|
|
88
|
-
Guam: 'USD',
|
|
89
|
-
Guatemala: 'QTQ',
|
|
90
|
-
Guinea: 'GNF',
|
|
91
|
-
'Guinea-Bissau': 'CFA',
|
|
92
|
-
Guyana: 'GYD',
|
|
93
|
-
Haiti: 'HTG',
|
|
94
|
-
'Heard Island and McDonald Islands': 'AUD',
|
|
95
|
-
'Holy See (Vatican City State)': 'EUR',
|
|
96
|
-
Honduras: 'HNL',
|
|
97
|
-
'Hong Kong': 'HKD',
|
|
98
|
-
Hungary: 'HUF',
|
|
99
|
-
Iceland: 'ISK',
|
|
100
|
-
India: 'INR',
|
|
101
|
-
Indonesia: 'IDR',
|
|
102
|
-
Iran: 'IRR',
|
|
103
|
-
Iraq: 'IQD',
|
|
104
|
-
Ireland: 'EUR',
|
|
105
|
-
Israel: 'ILS',
|
|
106
|
-
Italy: 'EUR',
|
|
107
|
-
'Ivory Coast': 'XOF',
|
|
108
|
-
Jamaica: 'JMD',
|
|
109
|
-
Japan: 'JPY',
|
|
110
|
-
Jordan: 'JOD',
|
|
111
|
-
Kazakhstan: 'KZT',
|
|
112
|
-
Kenya: 'KES',
|
|
113
|
-
Kiribati: 'AUD',
|
|
114
|
-
Kuwait: 'KWD',
|
|
115
|
-
Kyrgyzstan: 'KGS',
|
|
116
|
-
Laos: 'LAK',
|
|
117
|
-
Latvia: 'LVL',
|
|
118
|
-
Lebanon: 'LBP',
|
|
119
|
-
Lesotho: 'LSL',
|
|
120
|
-
Liberia: 'LRD',
|
|
121
|
-
'Libyan Arab Jamahiriya': 'LYD',
|
|
122
|
-
Liechtenstein: 'CHF',
|
|
123
|
-
Lithuania: 'LTL',
|
|
124
|
-
Luxembourg: 'EUR',
|
|
125
|
-
Macao: 'MOP',
|
|
126
|
-
'North Macedonia': 'MKD',
|
|
127
|
-
Madagascar: 'MGF',
|
|
128
|
-
Malawi: 'MWK',
|
|
129
|
-
Malaysia: 'MYR',
|
|
130
|
-
Maldives: 'MVR',
|
|
131
|
-
Mali: 'XOF',
|
|
132
|
-
Malta: 'EUR',
|
|
133
|
-
'Marshall Islands': 'USD',
|
|
134
|
-
Martinique: 'EUR',
|
|
135
|
-
Mauritania: 'MRO',
|
|
136
|
-
Mauritius: 'MUR',
|
|
137
|
-
Mayotte: 'EUR',
|
|
138
|
-
Mexico: 'MXN',
|
|
139
|
-
'Micronesia, Federated States of': 'USD',
|
|
140
|
-
Moldova: 'MDL',
|
|
141
|
-
Monaco: 'EUR',
|
|
142
|
-
Mongolia: 'MNT',
|
|
143
|
-
Montserrat: 'XCD',
|
|
144
|
-
Morocco: 'MAD',
|
|
145
|
-
Mozambique: 'MZN',
|
|
146
|
-
Myanmar: 'MMR',
|
|
147
|
-
Namibia: 'NAD',
|
|
148
|
-
Nauru: 'AUD',
|
|
149
|
-
Nepal: 'NPR',
|
|
150
|
-
Netherlands: 'EUR',
|
|
151
|
-
'Netherlands Antilles': 'ANG',
|
|
152
|
-
'New Caledonia': 'XPF',
|
|
153
|
-
'New Zealand': 'NZD',
|
|
154
|
-
Nicaragua: 'NIO',
|
|
155
|
-
Niger: 'XOF',
|
|
156
|
-
Nigeria: 'NGN',
|
|
157
|
-
Niue: 'NZD',
|
|
158
|
-
'Norfolk Island': 'AUD',
|
|
159
|
-
'North Korea': 'KPW',
|
|
160
|
-
'Northern Ireland': 'GBP',
|
|
161
|
-
'Northern Mariana Islands': 'USD',
|
|
162
|
-
Norway: 'NOK',
|
|
163
|
-
Oman: 'OMR',
|
|
164
|
-
Pakistan: 'PKR',
|
|
165
|
-
Palau: 'USD',
|
|
166
|
-
Palestine: null,
|
|
167
|
-
Panama: 'PAB',
|
|
168
|
-
'Papua New Guinea': 'PGK',
|
|
169
|
-
Paraguay: 'PYG',
|
|
170
|
-
Peru: 'PEN',
|
|
171
|
-
Philippines: 'PHP',
|
|
172
|
-
Pitcairn: 'NZD',
|
|
173
|
-
Poland: 'PLN',
|
|
174
|
-
Portugal: 'EUR',
|
|
175
|
-
'Puerto Rico': 'USD',
|
|
176
|
-
Qatar: 'QAR',
|
|
177
|
-
Reunion: 'EUR',
|
|
178
|
-
Romania: 'RON',
|
|
179
|
-
'Russian Federation': 'RUB',
|
|
180
|
-
Rwanda: 'RWF',
|
|
181
|
-
'Saint Helena': 'SHP',
|
|
182
|
-
'Saint Kitts and Nevis': 'XCD',
|
|
183
|
-
'Saint Lucia': 'XCD',
|
|
184
|
-
'Saint Pierre and Miquelon': 'EUR',
|
|
185
|
-
'Saint Vincent and the Grenadines': 'XCD',
|
|
186
|
-
Samoa: 'WST',
|
|
187
|
-
'San Marino': 'EUR',
|
|
188
|
-
'Sao Tome and Principe': 'STD',
|
|
189
|
-
'Saudi Arabia': 'SAR',
|
|
190
|
-
Scotland: 'GBP',
|
|
191
|
-
Senegal: 'XOF',
|
|
192
|
-
Serbia: 'RSD',
|
|
193
|
-
Seychelles: 'SCR',
|
|
194
|
-
'Sierra Leone': 'SLL',
|
|
195
|
-
Singapore: 'SGD',
|
|
196
|
-
Slovakia: 'EUR',
|
|
197
|
-
Slovenia: 'EUR',
|
|
198
|
-
'Solomon Islands': 'SBD',
|
|
199
|
-
Somalia: 'SOS',
|
|
200
|
-
'South Africa': 'ZAR',
|
|
201
|
-
'South Georgia and the South Sandwich Islands': 'GBP',
|
|
202
|
-
'South Korea': 'KRW',
|
|
203
|
-
'South Sudan': 'SSP',
|
|
204
|
-
Spain: 'EUR',
|
|
205
|
-
'Sri Lanka': 'LKR',
|
|
206
|
-
Sudan: 'SDG',
|
|
207
|
-
Suriname: 'SRD',
|
|
208
|
-
'Svalbard and Jan Mayen': 'NOK',
|
|
209
|
-
Swaziland: 'SZL',
|
|
210
|
-
Sweden: 'SEK',
|
|
211
|
-
Switzerland: 'CHF',
|
|
212
|
-
Syria: 'SYP',
|
|
213
|
-
Tajikistan: 'TJS',
|
|
214
|
-
Tanzania: 'TZS',
|
|
215
|
-
Thailand: 'THB',
|
|
216
|
-
'The Democratic Republic of Congo': 'CDF',
|
|
217
|
-
Togo: 'XOF',
|
|
218
|
-
Tokelau: 'NZD',
|
|
219
|
-
Tonga: 'TOP',
|
|
220
|
-
'Trinidad and Tobago': 'TTD',
|
|
221
|
-
Tunisia: 'TND',
|
|
222
|
-
Turkey: 'TRY',
|
|
223
|
-
Turkmenistan: 'TMT',
|
|
224
|
-
'Turks and Caicos Islands': 'USD',
|
|
225
|
-
Tuvalu: 'AUD',
|
|
226
|
-
Uganda: 'UGX',
|
|
227
|
-
Ukraine: 'UAH',
|
|
228
|
-
'United Arab Emirates': 'AED',
|
|
229
|
-
'United Kingdom': 'GBP',
|
|
230
|
-
'United States': 'USD',
|
|
231
|
-
'United States Minor Outlying Islands': 'USD',
|
|
232
|
-
Uruguay: 'UYU',
|
|
233
|
-
Uzbekistan: 'UZS',
|
|
234
|
-
Vanuatu: 'VUV',
|
|
235
|
-
Venezuela: 'VEF',
|
|
236
|
-
Vietnam: 'VND',
|
|
237
|
-
'Virgin Islands, British': 'USD',
|
|
238
|
-
'Virgin Islands, U.S.': 'USD',
|
|
239
|
-
Wales: 'GBP',
|
|
240
|
-
'Wallis and Futuna': 'XPF',
|
|
241
|
-
'Western Sahara': 'MAD',
|
|
242
|
-
Yemen: 'YER',
|
|
243
|
-
Zambia: 'ZMW',
|
|
244
|
-
Zimbabwe: 'ZWD',
|
|
245
|
-
};
|
|
246
|
-
export default currencyCodes;
|
package/lib/currency/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { countryCodes, currencyCodes } from './countries';
|
|
11
|
-
export const convert = (value, from = 'ETH', countryCode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
-
const country = countryCodes[countryCode || 'US'];
|
|
13
|
-
if (!country) {
|
|
14
|
-
throw new Error(`Unable to find country name for country code: ${countryCode}.`);
|
|
15
|
-
}
|
|
16
|
-
const to = currencyCodes[country];
|
|
17
|
-
if (!to) {
|
|
18
|
-
throw new Error(`Unable to find currency code for country: ${country}.`);
|
|
19
|
-
}
|
|
20
|
-
const url = `https://min-api.cryptocompare.com/data/price?fsym=${from}&tsyms=${from},${to}`;
|
|
21
|
-
const response = yield fetch(url);
|
|
22
|
-
const data = yield response.json();
|
|
23
|
-
const convertedValue = Math.round((value / (1 / data[to]) + Number.EPSILON) * 100) / 100;
|
|
24
|
-
return convertedValue;
|
|
25
|
-
});
|
package/lib/definitions/index.js
DELETED
package/lib/errors/http-error.js
DELETED
package/lib/errors/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { default as HttpError } from './http-error';
|
|
2
|
-
export { default as InvalidApiKeyError } from './invalid-api-key-error';
|
|
3
|
-
export { default as InvalidChainIdError } from './invalid-chain-id-error';
|
|
4
|
-
export { default as InvalidGatewayConfigError } from './invalid-gateway-config-error';
|
|
5
|
-
export { default as MissingOptionError } from './missing-option-error';
|
|
6
|
-
export { default as MpcSigningError } from './mpc-signing-error';
|
|
7
|
-
export { default as NoAddressError } from './no-address-error';
|
|
8
|
-
export { default as ProviderRpcError, RpcErrorCodes, } from './provider-rpc-error';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
class InvalidApiKeyError extends Error {
|
|
2
|
-
constructor() {
|
|
3
|
-
super('[Portal] A valid Portal Client API Key was not provided.');
|
|
4
|
-
// Set the prototype explicitly.
|
|
5
|
-
Object.setPrototypeOf(this, InvalidApiKeyError.prototype);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export default InvalidApiKeyError;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
class InvalidChainIdError extends Error {
|
|
2
|
-
constructor() {
|
|
3
|
-
super('[Portal] A valid Ethereum Chain ID was not provided.');
|
|
4
|
-
// Set the prototype explicitly.
|
|
5
|
-
Object.setPrototypeOf(this, InvalidChainIdError.prototype);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export default InvalidChainIdError;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
class InvalidGatewayConfigError extends Error {
|
|
2
|
-
constructor() {
|
|
3
|
-
super('[Portal] A valid Gateway configuration was not provided.');
|
|
4
|
-
// Set the prototype explicitly.
|
|
5
|
-
Object.setPrototypeOf(this, InvalidGatewayConfigError.prototype);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export default InvalidGatewayConfigError;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
class MissingOptionError extends Error {
|
|
2
|
-
constructor({ className, option }) {
|
|
3
|
-
super(`[Portal] Instance option '${option}' is required when instantiating ${className}.`);
|
|
4
|
-
// Set the prototype explicitly.
|
|
5
|
-
Object.setPrototypeOf(this, MissingOptionError.prototype);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export default MissingOptionError;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
class MpcSigningError extends Error {
|
|
2
|
-
constructor(message) {
|
|
3
|
-
super(`[Portal] An error occurred in the MPC signing process: ${message}`);
|
|
4
|
-
// Set the prototype explicitly.
|
|
5
|
-
Object.setPrototypeOf(this, MpcSigningError.prototype);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export default MpcSigningError;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export var RpcErrorCodes;
|
|
2
|
-
(function (RpcErrorCodes) {
|
|
3
|
-
RpcErrorCodes[RpcErrorCodes["UserRejectedRequest"] = 4001] = "UserRejectedRequest";
|
|
4
|
-
RpcErrorCodes[RpcErrorCodes["Unauthorized"] = 4100] = "Unauthorized";
|
|
5
|
-
RpcErrorCodes[RpcErrorCodes["UnsupportedMethod"] = 4200] = "UnsupportedMethod";
|
|
6
|
-
RpcErrorCodes[RpcErrorCodes["Disconnected"] = 4900] = "Disconnected";
|
|
7
|
-
RpcErrorCodes[RpcErrorCodes["ChainDisconnected"] = 4901] = "ChainDisconnected";
|
|
8
|
-
})(RpcErrorCodes || (RpcErrorCodes = {}));
|
|
9
|
-
const providerErrors = {
|
|
10
|
-
4001: {
|
|
11
|
-
name: 'User Rejected Request',
|
|
12
|
-
description: 'The user rejected the request.',
|
|
13
|
-
},
|
|
14
|
-
4100: {
|
|
15
|
-
name: 'Unauthorized',
|
|
16
|
-
description: 'The requested method and/or account has not been authorized by the user.',
|
|
17
|
-
},
|
|
18
|
-
4200: {
|
|
19
|
-
name: 'Unsupported Method',
|
|
20
|
-
description: 'The Provider does not support the requested method.',
|
|
21
|
-
},
|
|
22
|
-
4900: {
|
|
23
|
-
name: 'Disconnected',
|
|
24
|
-
description: 'The Provider is disconnected from all chains.',
|
|
25
|
-
},
|
|
26
|
-
4901: {
|
|
27
|
-
name: 'Chain Disconnected',
|
|
28
|
-
description: 'The Provider is not connected to the requested chain.',
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
class ProviderRpcError extends Error {
|
|
32
|
-
constructor({ code, data }) {
|
|
33
|
-
const log = console;
|
|
34
|
-
const definition = providerErrors[code];
|
|
35
|
-
if (!definition) {
|
|
36
|
-
log.warn(`[Portal] ProviderRpcError instantiated with unknown error code ${code}. Attempting to continue with limited context.`);
|
|
37
|
-
}
|
|
38
|
-
const message = definition
|
|
39
|
-
? `${definition.name} - ${definition.description}`
|
|
40
|
-
: '';
|
|
41
|
-
super(`[Portal] RPC Error: ${code} ${message}`);
|
|
42
|
-
// Set the prototype explicitly.
|
|
43
|
-
Object.setPrototypeOf(this, ProviderRpcError.prototype);
|
|
44
|
-
this.code = code;
|
|
45
|
-
this.data = data;
|
|
46
|
-
this.definition = definition;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
export default ProviderRpcError;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { convert } from '../currency';
|
|
11
|
-
const hexStringToString = (hexInput) => {
|
|
12
|
-
// Get the proper hex string
|
|
13
|
-
const byteArray = Array.from(hexStringToByteArray(hexInput.replace('0x', '')));
|
|
14
|
-
// Create an array of characters
|
|
15
|
-
const stringArray = byteArray.reduce((acc, charCode) => {
|
|
16
|
-
// Add the character matching the charCode
|
|
17
|
-
acc.push(String.fromCharCode(charCode));
|
|
18
|
-
// Return the accumulator
|
|
19
|
-
return acc;
|
|
20
|
-
}, []);
|
|
21
|
-
// Join the array of characters
|
|
22
|
-
const string = stringArray.join('');
|
|
23
|
-
// Return the final string
|
|
24
|
-
return string;
|
|
25
|
-
};
|
|
26
|
-
const hexStringToByteArray = (hexString) => {
|
|
27
|
-
// Verify the length of the string
|
|
28
|
-
if (hexString.length % 2 !== 0) {
|
|
29
|
-
throw Error('[Portal] hexStringToByteArray() detected invalid input lenth for hexString.');
|
|
30
|
-
}
|
|
31
|
-
// Get the total bytes
|
|
32
|
-
const totalBytes = hexString.length / 2;
|
|
33
|
-
// Initialize a Uint8Array with a length matching totalBytes
|
|
34
|
-
const byteArray = new Uint8Array(totalBytes);
|
|
35
|
-
// Loop of the resulting array
|
|
36
|
-
for (let i = 0; i < totalBytes; i++) {
|
|
37
|
-
// Get the byte at the current index
|
|
38
|
-
const substring = hexString.substring(i * 2, i * 2 + 2).toLowerCase();
|
|
39
|
-
// Get the integer matching the current byte and push to the array
|
|
40
|
-
byteArray[i] = parseInt(substring, 16);
|
|
41
|
-
}
|
|
42
|
-
// Return a byte array
|
|
43
|
-
return byteArray;
|
|
44
|
-
};
|
|
45
|
-
const hexStringToNumber = (hexBalance) => {
|
|
46
|
-
const balanceNumber = Number(hexBalance);
|
|
47
|
-
console.log(`balanceNumber`, balanceNumber);
|
|
48
|
-
const balance = Math.round((balanceNumber / 1e18) * 1000000) / 1000000;
|
|
49
|
-
return balance;
|
|
50
|
-
};
|
|
51
|
-
export const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
-
let requestData;
|
|
53
|
-
console.log(`Request: `, JSON.stringify({ method, params }));
|
|
54
|
-
const txParam0 = Array.isArray(params) ? params[0] : params;
|
|
55
|
-
const txParam1 = Array.isArray(params) ? params[1] : null;
|
|
56
|
-
switch (method) {
|
|
57
|
-
case 'eth_sendTransaction':
|
|
58
|
-
case 'eth_signTransaction':
|
|
59
|
-
const payload = txParam0;
|
|
60
|
-
const value = hexStringToNumber(payload.value);
|
|
61
|
-
requestData = {
|
|
62
|
-
data: payload.data,
|
|
63
|
-
from: payload.from,
|
|
64
|
-
to: payload.to,
|
|
65
|
-
value,
|
|
66
|
-
valueConverted: yield convert(value),
|
|
67
|
-
};
|
|
68
|
-
console.log(`requestData: `, requestData);
|
|
69
|
-
break;
|
|
70
|
-
case 'eth_sign':
|
|
71
|
-
case 'personal_sign':
|
|
72
|
-
requestData = {
|
|
73
|
-
message: hexStringToString(txParam0),
|
|
74
|
-
};
|
|
75
|
-
break;
|
|
76
|
-
default:
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
method,
|
|
81
|
-
data: requestData,
|
|
82
|
-
};
|
|
83
|
-
});
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { HttpError } from '../errors';
|
|
2
|
-
class HttpRequest {
|
|
3
|
-
constructor({ body = {}, headers = {}, method, url }) {
|
|
4
|
-
this.body = body;
|
|
5
|
-
this.headers = headers;
|
|
6
|
-
this.method = method;
|
|
7
|
-
this.url = url;
|
|
8
|
-
this.request = new XMLHttpRequest();
|
|
9
|
-
this.request.open(this.method, this.url, true);
|
|
10
|
-
}
|
|
11
|
-
send() {
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
// Sets headers on the request
|
|
14
|
-
this.prepareRequest();
|
|
15
|
-
// Sends the request with a formatted request body
|
|
16
|
-
const body = this.prepareBody();
|
|
17
|
-
this.request.send(body);
|
|
18
|
-
// Adds an event listener for when the request state changes
|
|
19
|
-
this.request.onreadystatechange = () => {
|
|
20
|
-
if (this.request.readyState === 4) {
|
|
21
|
-
// readyState 4 means the request has completed
|
|
22
|
-
if (this.request.status !== 200) {
|
|
23
|
-
// If we didn't get an 'OK' status, error out
|
|
24
|
-
reject(new HttpError({
|
|
25
|
-
message: this.request.responseText,
|
|
26
|
-
status: this.request.status,
|
|
27
|
-
statusText: this.request.statusText,
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
// Otherwise, resolve a parsed response object
|
|
32
|
-
resolve(this.buildResponse());
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
buildResponse() {
|
|
39
|
-
try {
|
|
40
|
-
// Try parsing the response body into a JSON object
|
|
41
|
-
const response = JSON.parse(this.request.response);
|
|
42
|
-
return response;
|
|
43
|
-
}
|
|
44
|
-
catch (_a) {
|
|
45
|
-
// If JSON parsing doesn't work, just return the response body however it came back
|
|
46
|
-
return this.request.response;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
prepareBody() {
|
|
50
|
-
if (this.headers['Content-Type'] === 'application/json') {
|
|
51
|
-
// Stringify if we're declaring this request to be a JSON request
|
|
52
|
-
return JSON.stringify(this.body);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// Otherwise, build a serialized string
|
|
56
|
-
const params = [];
|
|
57
|
-
for (const [key, value] of Object.entries(this.body)) {
|
|
58
|
-
params.push(`${key}=${value}`);
|
|
59
|
-
}
|
|
60
|
-
return params.join('&');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
prepareRequest() {
|
|
64
|
-
// Add all of the defined headers to the request
|
|
65
|
-
for (const [key, value] of Object.entries(this.headers)) {
|
|
66
|
-
this.request.setRequestHeader(key, value);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
export default HttpRequest;
|
package/lib/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { convert } from './currency';
|
|
2
|
-
export { KeychainAdapter, PortalApi, Storage } from './definitions';
|
|
3
|
-
export { HttpError, InvalidApiKeyError, InvalidChainIdError, InvalidGatewayConfigError, MissingOptionError, MpcSigningError, NoAddressError, ProviderRpcError, RpcErrorCodes, } from './errors';
|
|
4
|
-
export { parseRequest } from './eth-requests';
|
|
5
|
-
export { default as HttpRequest } from './http-request';
|
|
6
|
-
export { HttpRequester } from './requesters';
|
package/lib/requesters/http.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { HttpRequest } from '../index';
|
|
11
|
-
class HttpRequester {
|
|
12
|
-
constructor({ baseUrl }) {
|
|
13
|
-
this.baseUrl = baseUrl.startsWith('https://')
|
|
14
|
-
? baseUrl
|
|
15
|
-
: `https://${baseUrl}`;
|
|
16
|
-
}
|
|
17
|
-
get(path, options) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
const requestOptions = {
|
|
20
|
-
method: 'GET',
|
|
21
|
-
url: `${this.baseUrl}${path}`,
|
|
22
|
-
};
|
|
23
|
-
if (options && options.headers) {
|
|
24
|
-
requestOptions.headers = this.buildHeaders(options.headers);
|
|
25
|
-
}
|
|
26
|
-
const request = new HttpRequest(requestOptions);
|
|
27
|
-
const response = (yield request.send());
|
|
28
|
-
return response;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
post(path, options) {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const requestOptions = {
|
|
34
|
-
method: 'POST',
|
|
35
|
-
url: `${this.baseUrl}${path}`,
|
|
36
|
-
};
|
|
37
|
-
requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
|
|
38
|
-
if (options && options.body) {
|
|
39
|
-
requestOptions.body = options.body;
|
|
40
|
-
}
|
|
41
|
-
const request = new HttpRequest(requestOptions);
|
|
42
|
-
const response = (yield request.send());
|
|
43
|
-
return response;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
buildHeaders(headers) {
|
|
47
|
-
return Object.assign({ 'Content-Type': 'application/json' }, headers);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export default HttpRequester;
|
package/lib/requesters/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as HttpRequester } from './http';
|