rocket-launch-live-client 1.0.3 → 2.0.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/README.md +105 -61
- package/lib/{esm/types/Client.d.ts → Client.d.ts} +6 -8
- package/lib/Client.js +61 -0
- package/lib/fetcher.d.ts +5 -0
- package/lib/fetcher.js +146 -0
- package/lib/{cjs/types/index.d.ts → index.d.ts} +0 -1
- package/lib/index.js +4 -0
- package/lib/{cjs/types/types → types}/application.d.ts +41 -27
- package/lib/types/application.js +41 -0
- package/lib/types/standards.d.ts +8 -0
- package/lib/types/standards.js +314 -0
- package/lib/{cjs/types/utils.d.ts → utils.d.ts} +1 -4
- package/lib/{esm/utils.js → utils.js} +18 -4
- package/lib/{cjs/types → watcher}/Watcher.d.ts +16 -12
- package/lib/watcher/Watcher.js +145 -0
- package/lib/watcher/index.d.ts +25 -0
- package/lib/watcher/index.js +3 -0
- package/package.json +30 -26
- package/lib/cjs/Client.js +0 -233
- package/lib/cjs/Watcher.js +0 -172
- package/lib/cjs/fetcher.js +0 -61
- package/lib/cjs/index.js +0 -30
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/types/Client.d.ts +0 -189
- package/lib/cjs/types/application.js +0 -46
- package/lib/cjs/types/fetcher.d.ts +0 -2
- package/lib/cjs/types/standards.js +0 -321
- package/lib/cjs/types/types/standards.d.ts +0 -316
- package/lib/cjs/utils.js +0 -266
- package/lib/esm/Client.js +0 -229
- package/lib/esm/Watcher.js +0 -168
- package/lib/esm/fetcher.js +0 -54
- package/lib/esm/index.mjs +0 -22
- package/lib/esm/package.json +0 -3
- package/lib/esm/types/Watcher.d.ts +0 -81
- package/lib/esm/types/application.js +0 -43
- package/lib/esm/types/fetcher.d.ts +0 -2
- package/lib/esm/types/index.d.ts +0 -24
- package/lib/esm/types/standards.js +0 -316
- package/lib/esm/types/types/application.d.ts +0 -206
- package/lib/esm/types/types/standards.d.ts +0 -316
- package/lib/esm/types/utils.d.ts +0 -12
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
export declare const countryCodes: {
|
|
2
|
-
AF: string;
|
|
3
|
-
AL: string;
|
|
4
|
-
DZ: string;
|
|
5
|
-
AS: string;
|
|
6
|
-
AD: string;
|
|
7
|
-
AO: string;
|
|
8
|
-
AI: string;
|
|
9
|
-
AQ: string;
|
|
10
|
-
AG: string;
|
|
11
|
-
AR: string;
|
|
12
|
-
AM: string;
|
|
13
|
-
AW: string;
|
|
14
|
-
AU: string;
|
|
15
|
-
AT: string;
|
|
16
|
-
AZ: string;
|
|
17
|
-
BS: string;
|
|
18
|
-
BH: string;
|
|
19
|
-
BD: string;
|
|
20
|
-
BB: string;
|
|
21
|
-
BY: string;
|
|
22
|
-
BE: string;
|
|
23
|
-
BZ: string;
|
|
24
|
-
BJ: string;
|
|
25
|
-
BM: string;
|
|
26
|
-
BT: string;
|
|
27
|
-
BO: string;
|
|
28
|
-
BQ: string;
|
|
29
|
-
BA: string;
|
|
30
|
-
BW: string;
|
|
31
|
-
BV: string;
|
|
32
|
-
BR: string;
|
|
33
|
-
IO: string;
|
|
34
|
-
BN: string;
|
|
35
|
-
BG: string;
|
|
36
|
-
BF: string;
|
|
37
|
-
BI: string;
|
|
38
|
-
CV: string;
|
|
39
|
-
KH: string;
|
|
40
|
-
CM: string;
|
|
41
|
-
CA: string;
|
|
42
|
-
KY: string;
|
|
43
|
-
CF: string;
|
|
44
|
-
TD: string;
|
|
45
|
-
CL: string;
|
|
46
|
-
CN: string;
|
|
47
|
-
CX: string;
|
|
48
|
-
CC: string;
|
|
49
|
-
CO: string;
|
|
50
|
-
KM: string;
|
|
51
|
-
CD: string;
|
|
52
|
-
CG: string;
|
|
53
|
-
CK: string;
|
|
54
|
-
CR: string;
|
|
55
|
-
HR: string;
|
|
56
|
-
CU: string;
|
|
57
|
-
CW: string;
|
|
58
|
-
CY: string;
|
|
59
|
-
CZ: string;
|
|
60
|
-
CI: string;
|
|
61
|
-
DK: string;
|
|
62
|
-
DJ: string;
|
|
63
|
-
DM: string;
|
|
64
|
-
DO: string;
|
|
65
|
-
EC: string;
|
|
66
|
-
EG: string;
|
|
67
|
-
SV: string;
|
|
68
|
-
GQ: string;
|
|
69
|
-
ER: string;
|
|
70
|
-
EE: string;
|
|
71
|
-
SZ: string;
|
|
72
|
-
ET: string;
|
|
73
|
-
FK: string;
|
|
74
|
-
FO: string;
|
|
75
|
-
FJ: string;
|
|
76
|
-
FI: string;
|
|
77
|
-
FR: string;
|
|
78
|
-
GF: string;
|
|
79
|
-
PF: string;
|
|
80
|
-
TF: string;
|
|
81
|
-
GA: string;
|
|
82
|
-
GM: string;
|
|
83
|
-
GE: string;
|
|
84
|
-
DE: string;
|
|
85
|
-
GH: string;
|
|
86
|
-
GI: string;
|
|
87
|
-
GR: string;
|
|
88
|
-
GL: string;
|
|
89
|
-
GD: string;
|
|
90
|
-
GP: string;
|
|
91
|
-
GU: string;
|
|
92
|
-
GT: string;
|
|
93
|
-
GG: string;
|
|
94
|
-
GN: string;
|
|
95
|
-
GW: string;
|
|
96
|
-
GY: string;
|
|
97
|
-
HT: string;
|
|
98
|
-
HM: string;
|
|
99
|
-
VA: string;
|
|
100
|
-
HN: string;
|
|
101
|
-
HK: string;
|
|
102
|
-
HU: string;
|
|
103
|
-
IS: string;
|
|
104
|
-
IN: string;
|
|
105
|
-
ID: string;
|
|
106
|
-
IR: string;
|
|
107
|
-
IQ: string;
|
|
108
|
-
IE: string;
|
|
109
|
-
IM: string;
|
|
110
|
-
IL: string;
|
|
111
|
-
IT: string;
|
|
112
|
-
JM: string;
|
|
113
|
-
JP: string;
|
|
114
|
-
JE: string;
|
|
115
|
-
JO: string;
|
|
116
|
-
KZ: string;
|
|
117
|
-
KE: string;
|
|
118
|
-
KI: string;
|
|
119
|
-
KP: string;
|
|
120
|
-
KR: string;
|
|
121
|
-
KW: string;
|
|
122
|
-
KG: string;
|
|
123
|
-
LA: string;
|
|
124
|
-
LV: string;
|
|
125
|
-
LB: string;
|
|
126
|
-
LS: string;
|
|
127
|
-
LR: string;
|
|
128
|
-
LY: string;
|
|
129
|
-
LI: string;
|
|
130
|
-
LT: string;
|
|
131
|
-
LU: string;
|
|
132
|
-
MO: string;
|
|
133
|
-
MG: string;
|
|
134
|
-
MW: string;
|
|
135
|
-
MY: string;
|
|
136
|
-
MV: string;
|
|
137
|
-
ML: string;
|
|
138
|
-
MT: string;
|
|
139
|
-
MH: string;
|
|
140
|
-
MQ: string;
|
|
141
|
-
MR: string;
|
|
142
|
-
MU: string;
|
|
143
|
-
YT: string;
|
|
144
|
-
MX: string;
|
|
145
|
-
FM: string;
|
|
146
|
-
MD: string;
|
|
147
|
-
MC: string;
|
|
148
|
-
MN: string;
|
|
149
|
-
ME: string;
|
|
150
|
-
MS: string;
|
|
151
|
-
MA: string;
|
|
152
|
-
MZ: string;
|
|
153
|
-
MM: string;
|
|
154
|
-
NA: string;
|
|
155
|
-
NR: string;
|
|
156
|
-
NP: string;
|
|
157
|
-
NL: string;
|
|
158
|
-
NC: string;
|
|
159
|
-
NZ: string;
|
|
160
|
-
NI: string;
|
|
161
|
-
NE: string;
|
|
162
|
-
NG: string;
|
|
163
|
-
NU: string;
|
|
164
|
-
NF: string;
|
|
165
|
-
MP: string;
|
|
166
|
-
NO: string;
|
|
167
|
-
OM: string;
|
|
168
|
-
PK: string;
|
|
169
|
-
PW: string;
|
|
170
|
-
PS: string;
|
|
171
|
-
PA: string;
|
|
172
|
-
PG: string;
|
|
173
|
-
PY: string;
|
|
174
|
-
PE: string;
|
|
175
|
-
PH: string;
|
|
176
|
-
PN: string;
|
|
177
|
-
PL: string;
|
|
178
|
-
PT: string;
|
|
179
|
-
PR: string;
|
|
180
|
-
QA: string;
|
|
181
|
-
MK: string;
|
|
182
|
-
RO: string;
|
|
183
|
-
RU: string;
|
|
184
|
-
RW: string;
|
|
185
|
-
RE: string;
|
|
186
|
-
BL: string;
|
|
187
|
-
SH: string;
|
|
188
|
-
KN: string;
|
|
189
|
-
LC: string;
|
|
190
|
-
MF: string;
|
|
191
|
-
PM: string;
|
|
192
|
-
VC: string;
|
|
193
|
-
WS: string;
|
|
194
|
-
SM: string;
|
|
195
|
-
ST: string;
|
|
196
|
-
SA: string;
|
|
197
|
-
SN: string;
|
|
198
|
-
RS: string;
|
|
199
|
-
SC: string;
|
|
200
|
-
SL: string;
|
|
201
|
-
SG: string;
|
|
202
|
-
SX: string;
|
|
203
|
-
SK: string;
|
|
204
|
-
SI: string;
|
|
205
|
-
SB: string;
|
|
206
|
-
SO: string;
|
|
207
|
-
ZA: string;
|
|
208
|
-
GS: string;
|
|
209
|
-
SS: string;
|
|
210
|
-
ES: string;
|
|
211
|
-
LK: string;
|
|
212
|
-
SD: string;
|
|
213
|
-
SR: string;
|
|
214
|
-
SJ: string;
|
|
215
|
-
SE: string;
|
|
216
|
-
CH: string;
|
|
217
|
-
SY: string;
|
|
218
|
-
TW: string;
|
|
219
|
-
TJ: string;
|
|
220
|
-
TZ: string;
|
|
221
|
-
TH: string;
|
|
222
|
-
TL: string;
|
|
223
|
-
TG: string;
|
|
224
|
-
TK: string;
|
|
225
|
-
TO: string;
|
|
226
|
-
TT: string;
|
|
227
|
-
TN: string;
|
|
228
|
-
TR: string;
|
|
229
|
-
TM: string;
|
|
230
|
-
TC: string;
|
|
231
|
-
TV: string;
|
|
232
|
-
UG: string;
|
|
233
|
-
UA: string;
|
|
234
|
-
AE: string;
|
|
235
|
-
GB: string;
|
|
236
|
-
UM: string;
|
|
237
|
-
US: string;
|
|
238
|
-
UY: string;
|
|
239
|
-
UZ: string;
|
|
240
|
-
VU: string;
|
|
241
|
-
VE: string;
|
|
242
|
-
VN: string;
|
|
243
|
-
VG: string;
|
|
244
|
-
VI: string;
|
|
245
|
-
WF: string;
|
|
246
|
-
EH: string;
|
|
247
|
-
YE: string;
|
|
248
|
-
ZM: string;
|
|
249
|
-
ZW: string;
|
|
250
|
-
AX: string;
|
|
251
|
-
};
|
|
252
|
-
export declare const usStateCodes: {
|
|
253
|
-
AL: string;
|
|
254
|
-
AK: string;
|
|
255
|
-
AZ: string;
|
|
256
|
-
AR: string;
|
|
257
|
-
CA: string;
|
|
258
|
-
CO: string;
|
|
259
|
-
CT: string;
|
|
260
|
-
DE: string;
|
|
261
|
-
FL: string;
|
|
262
|
-
GA: string;
|
|
263
|
-
HI: string;
|
|
264
|
-
ID: string;
|
|
265
|
-
IL: string;
|
|
266
|
-
IN: string;
|
|
267
|
-
IA: string;
|
|
268
|
-
KS: string;
|
|
269
|
-
KY: string;
|
|
270
|
-
LA: string;
|
|
271
|
-
ME: string;
|
|
272
|
-
MD: string;
|
|
273
|
-
MA: string;
|
|
274
|
-
MI: string;
|
|
275
|
-
MN: string;
|
|
276
|
-
MS: string;
|
|
277
|
-
MO: string;
|
|
278
|
-
MT: string;
|
|
279
|
-
NE: string;
|
|
280
|
-
NV: string;
|
|
281
|
-
NH: string;
|
|
282
|
-
NJ: string;
|
|
283
|
-
NM: string;
|
|
284
|
-
NY: string;
|
|
285
|
-
NC: string;
|
|
286
|
-
ND: string;
|
|
287
|
-
OH: string;
|
|
288
|
-
OK: string;
|
|
289
|
-
OR: string;
|
|
290
|
-
PA: string;
|
|
291
|
-
RI: string;
|
|
292
|
-
SC: string;
|
|
293
|
-
SD: string;
|
|
294
|
-
TN: string;
|
|
295
|
-
TX: string;
|
|
296
|
-
UT: string;
|
|
297
|
-
VT: string;
|
|
298
|
-
VA: string;
|
|
299
|
-
WA: string;
|
|
300
|
-
WV: string;
|
|
301
|
-
WI: string;
|
|
302
|
-
WY: string;
|
|
303
|
-
DC: string;
|
|
304
|
-
AS: string;
|
|
305
|
-
GU: string;
|
|
306
|
-
MP: string;
|
|
307
|
-
PR: string;
|
|
308
|
-
UM: string;
|
|
309
|
-
VI: string;
|
|
310
|
-
};
|
|
311
|
-
export declare const isValidCountryCode: (code: string) => code is "AF" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AI" | "AQ" | "AG" | "AR" | "AM" | "AW" | "AU" | "AT" | "AZ" | "BS" | "BH" | "BD" | "BB" | "BY" | "BE" | "BZ" | "BJ" | "BM" | "BT" | "BO" | "BQ" | "BA" | "BW" | "BV" | "BR" | "IO" | "BN" | "BG" | "BF" | "BI" | "CV" | "KH" | "CM" | "CA" | "KY" | "CF" | "TD" | "CL" | "CN" | "CX" | "CC" | "CO" | "KM" | "CD" | "CG" | "CK" | "CR" | "HR" | "CU" | "CW" | "CY" | "CZ" | "CI" | "DK" | "DJ" | "DM" | "DO" | "EC" | "EG" | "SV" | "GQ" | "ER" | "EE" | "SZ" | "ET" | "FK" | "FO" | "FJ" | "FI" | "FR" | "GF" | "PF" | "TF" | "GA" | "GM" | "GE" | "DE" | "GH" | "GI" | "GR" | "GL" | "GD" | "GP" | "GU" | "GT" | "GG" | "GN" | "GW" | "GY" | "HT" | "HM" | "VA" | "HN" | "HK" | "HU" | "IS" | "IN" | "ID" | "IR" | "IQ" | "IE" | "IM" | "IL" | "IT" | "JM" | "JP" | "JE" | "JO" | "KZ" | "KE" | "KI" | "KP" | "KR" | "KW" | "KG" | "LA" | "LV" | "LB" | "LS" | "LR" | "LY" | "LI" | "LT" | "LU" | "MO" | "MG" | "MW" | "MY" | "MV" | "ML" | "MT" | "MH" | "MQ" | "MR" | "MU" | "YT" | "MX" | "FM" | "MD" | "MC" | "MN" | "ME" | "MS" | "MA" | "MZ" | "MM" | "NA" | "NR" | "NP" | "NL" | "NC" | "NZ" | "NI" | "NE" | "NG" | "NU" | "NF" | "MP" | "NO" | "OM" | "PK" | "PW" | "PS" | "PA" | "PG" | "PY" | "PE" | "PH" | "PN" | "PL" | "PT" | "PR" | "QA" | "MK" | "RO" | "RU" | "RW" | "RE" | "BL" | "SH" | "KN" | "LC" | "MF" | "PM" | "VC" | "WS" | "SM" | "ST" | "SA" | "SN" | "RS" | "SC" | "SL" | "SG" | "SX" | "SK" | "SI" | "SB" | "SO" | "ZA" | "GS" | "SS" | "ES" | "LK" | "SD" | "SR" | "SJ" | "SE" | "CH" | "SY" | "TW" | "TJ" | "TZ" | "TH" | "TL" | "TG" | "TK" | "TO" | "TT" | "TN" | "TR" | "TM" | "TC" | "TV" | "UG" | "UA" | "AE" | "GB" | "UM" | "US" | "UY" | "UZ" | "VU" | "VE" | "VN" | "VG" | "VI" | "WF" | "EH" | "YE" | "ZM" | "ZW" | "AX";
|
|
312
|
-
export declare const isValidStateCode: (code: string) => code is "AL" | "AS" | "AR" | "AZ" | "CA" | "KY" | "CO" | "GA" | "DE" | "GU" | "VA" | "IN" | "ID" | "IL" | "LA" | "MO" | "MT" | "MD" | "MN" | "ME" | "MS" | "MA" | "NC" | "NE" | "MP" | "PA" | "PR" | "SC" | "SD" | "TN" | "UM" | "VI" | "AK" | "CT" | "FL" | "HI" | "IA" | "KS" | "MI" | "NV" | "NH" | "NJ" | "NM" | "NY" | "ND" | "OH" | "OK" | "OR" | "RI" | "TX" | "UT" | "VT" | "WA" | "WV" | "WI" | "WY" | "DC";
|
|
313
|
-
export declare namespace ISO3166Alpha2 {
|
|
314
|
-
type CountryCode = keyof typeof countryCodes;
|
|
315
|
-
type StateCodeUS = keyof typeof usStateCodes;
|
|
316
|
-
}
|
package/lib/cjs/utils.js
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.error = exports.warn = exports.queryOptionsValidator = exports.optionsValidator = exports.apiKeyValidator = exports.formatToRLLISODate = void 0;
|
|
4
|
-
const standards_js_1 = require("./types/standards.js");
|
|
5
|
-
const getLeadingZero = (month, offset = 0) => {
|
|
6
|
-
const str = "0".concat((month + offset).toString());
|
|
7
|
-
return str.slice(-2);
|
|
8
|
-
};
|
|
9
|
-
const formatToRLLISODate = (date) => {
|
|
10
|
-
return date.toISOString().slice(0, 19).concat("Z");
|
|
11
|
-
};
|
|
12
|
-
exports.formatToRLLISODate = formatToRLLISODate;
|
|
13
|
-
const apiKeyValidator = (apiKey) => {
|
|
14
|
-
if (apiKey === undefined) {
|
|
15
|
-
(0, exports.error)("RLL Client requires API Key", "type");
|
|
16
|
-
}
|
|
17
|
-
if (typeof apiKey !== "string") {
|
|
18
|
-
(0, exports.error)("RLL Client API Key must be a string", "type");
|
|
19
|
-
}
|
|
20
|
-
const trimmedKey = apiKey.trim();
|
|
21
|
-
if (trimmedKey === "") {
|
|
22
|
-
(0, exports.error)("RLL Client API Key cannot be an empty string", "type");
|
|
23
|
-
}
|
|
24
|
-
const validator = trimmedKey.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i);
|
|
25
|
-
if (validator === null) {
|
|
26
|
-
(0, exports.error)("RLL Client API Key appears malformed. RLL Client API Keys are in UUID format.", "type");
|
|
27
|
-
}
|
|
28
|
-
return trimmedKey;
|
|
29
|
-
};
|
|
30
|
-
exports.apiKeyValidator = apiKeyValidator;
|
|
31
|
-
const optionsValidator = (options) => {
|
|
32
|
-
for (const option in options) {
|
|
33
|
-
if (option !== "keyInQueryParams") {
|
|
34
|
-
(0, exports.warn)(`RLL Client options do not accept a "${option}" property. This property will be ignored.`);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
if (typeof options[option] !== "boolean") {
|
|
38
|
-
(0, exports.error)("RLL Client configuration option 'keyInQueryParams' must be a boolean.", "type");
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
exports.optionsValidator = optionsValidator;
|
|
44
|
-
const validators = {
|
|
45
|
-
string: (option) => {
|
|
46
|
-
if (typeof option === "number") {
|
|
47
|
-
return option.toString();
|
|
48
|
-
}
|
|
49
|
-
if (typeof option !== "string") {
|
|
50
|
-
throw "Must be a string";
|
|
51
|
-
}
|
|
52
|
-
if (option.length <= 0) {
|
|
53
|
-
throw "String must have length greater than 0";
|
|
54
|
-
}
|
|
55
|
-
return option;
|
|
56
|
-
},
|
|
57
|
-
boolean: (option) => {
|
|
58
|
-
if (typeof option !== "boolean") {
|
|
59
|
-
throw "Must be a boolean";
|
|
60
|
-
}
|
|
61
|
-
return option === true ? 1 : 0;
|
|
62
|
-
},
|
|
63
|
-
number: (option) => {
|
|
64
|
-
if (typeof option === "number") {
|
|
65
|
-
return option;
|
|
66
|
-
}
|
|
67
|
-
if (typeof option !== "string" || option === "" || isNaN(Number(option))) {
|
|
68
|
-
throw "Must be a number";
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
return Number(option);
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
countryCode: (option) => {
|
|
75
|
-
if (typeof option !== "string") {
|
|
76
|
-
throw "Must be a string";
|
|
77
|
-
}
|
|
78
|
-
if (!(0, standards_js_1.isValidCountryCode)(option)) {
|
|
79
|
-
throw "Invalid country code. Country codes should follow ISO 3166-1 A2 convention, like 'US'.";
|
|
80
|
-
}
|
|
81
|
-
return option;
|
|
82
|
-
},
|
|
83
|
-
stateCode: (option) => {
|
|
84
|
-
if (typeof option !== "string") {
|
|
85
|
-
throw "Must be a string";
|
|
86
|
-
}
|
|
87
|
-
if (!(0, standards_js_1.isValidStateCode)(option)) {
|
|
88
|
-
throw "Invalid United States State Code. State Codes should follow ISO 3166-2 convention, like 'FL'.";
|
|
89
|
-
}
|
|
90
|
-
return option;
|
|
91
|
-
},
|
|
92
|
-
cosparId: (option) => {
|
|
93
|
-
if (typeof option !== "string") {
|
|
94
|
-
throw "Must be a string";
|
|
95
|
-
}
|
|
96
|
-
if (!option.match(/^\d{4}\-\d{3}$/g)) {
|
|
97
|
-
throw "Cospar IDs must be in the format of YYYY-NNN (eg. 2023-123)";
|
|
98
|
-
}
|
|
99
|
-
return option;
|
|
100
|
-
},
|
|
101
|
-
shortDate: (option) => {
|
|
102
|
-
if (typeof option !== "string" && !(option instanceof Date)) {
|
|
103
|
-
throw "Must be a JavaScript Date Object or ISO 8601 Date String";
|
|
104
|
-
}
|
|
105
|
-
let date;
|
|
106
|
-
if (typeof option === "string") {
|
|
107
|
-
const parsed = Date.parse(option);
|
|
108
|
-
if (isNaN(parsed)) {
|
|
109
|
-
throw "Must be an ISO 8601 Date String";
|
|
110
|
-
}
|
|
111
|
-
date = new Date(parsed);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
date = option;
|
|
115
|
-
}
|
|
116
|
-
return `${date.getUTCFullYear()}-${getLeadingZero(date.getUTCMonth(), 1)}-${getLeadingZero(date.getUTCDate())}`;
|
|
117
|
-
},
|
|
118
|
-
isoDate: (option) => {
|
|
119
|
-
if (typeof option !== "string" && !(option instanceof Date)) {
|
|
120
|
-
throw "Must be a JavaScript Date Object or ISO 8601 Date String";
|
|
121
|
-
}
|
|
122
|
-
let date;
|
|
123
|
-
if (typeof option === "string") {
|
|
124
|
-
const parsed = Date.parse(option);
|
|
125
|
-
if (isNaN(parsed)) {
|
|
126
|
-
throw "Must be an ISO 8601 Date String";
|
|
127
|
-
}
|
|
128
|
-
date = new Date(parsed);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
date = option;
|
|
132
|
-
}
|
|
133
|
-
return (0, exports.formatToRLLISODate)(date);
|
|
134
|
-
},
|
|
135
|
-
limit: (option) => {
|
|
136
|
-
const num = validators.number(option);
|
|
137
|
-
if (num < 1) {
|
|
138
|
-
throw "Must be a number greater than 0";
|
|
139
|
-
}
|
|
140
|
-
if (num > 25) {
|
|
141
|
-
throw "Must be a number less than 26";
|
|
142
|
-
}
|
|
143
|
-
return num;
|
|
144
|
-
},
|
|
145
|
-
direction: (option) => {
|
|
146
|
-
if (typeof option !== "string") {
|
|
147
|
-
throw "Must be a string";
|
|
148
|
-
}
|
|
149
|
-
if (option !== "asc" && option !== "desc") {
|
|
150
|
-
throw 'String must be either "asc" or "desc"';
|
|
151
|
-
}
|
|
152
|
-
return option;
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
const optionsMap = {
|
|
156
|
-
companies: {
|
|
157
|
-
page: validators.number,
|
|
158
|
-
id: validators.number,
|
|
159
|
-
name: validators.string,
|
|
160
|
-
country_code: validators.countryCode,
|
|
161
|
-
inactive: validators.boolean,
|
|
162
|
-
},
|
|
163
|
-
launches: {
|
|
164
|
-
page: validators.number,
|
|
165
|
-
id: validators.number,
|
|
166
|
-
cospar_id: validators.cosparId,
|
|
167
|
-
after_date: validators.shortDate,
|
|
168
|
-
before_date: validators.shortDate,
|
|
169
|
-
modified_since: validators.isoDate,
|
|
170
|
-
location_id: validators.number,
|
|
171
|
-
pad_id: validators.number,
|
|
172
|
-
provider_id: validators.number,
|
|
173
|
-
tag_id: validators.number,
|
|
174
|
-
vehicle_id: validators.number,
|
|
175
|
-
state_abbr: validators.stateCode,
|
|
176
|
-
country_code: validators.countryCode,
|
|
177
|
-
search: validators.string,
|
|
178
|
-
slug: validators.string,
|
|
179
|
-
limit: validators.limit,
|
|
180
|
-
direction: validators.direction,
|
|
181
|
-
},
|
|
182
|
-
locations: {
|
|
183
|
-
page: validators.number,
|
|
184
|
-
id: validators.number,
|
|
185
|
-
name: validators.string,
|
|
186
|
-
state_abbr: validators.stateCode,
|
|
187
|
-
country_code: validators.countryCode,
|
|
188
|
-
},
|
|
189
|
-
missions: {
|
|
190
|
-
page: validators.number,
|
|
191
|
-
id: validators.number,
|
|
192
|
-
name: validators.string,
|
|
193
|
-
},
|
|
194
|
-
pads: {
|
|
195
|
-
page: validators.number,
|
|
196
|
-
id: validators.number,
|
|
197
|
-
name: validators.string,
|
|
198
|
-
state_abbr: validators.stateCode,
|
|
199
|
-
country_code: validators.countryCode,
|
|
200
|
-
},
|
|
201
|
-
tags: {
|
|
202
|
-
page: validators.number,
|
|
203
|
-
id: validators.number,
|
|
204
|
-
text: validators.string,
|
|
205
|
-
},
|
|
206
|
-
vehicles: {
|
|
207
|
-
page: validators.number,
|
|
208
|
-
id: validators.number,
|
|
209
|
-
name: validators.string,
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
const queryOptionsValidator = (resource, options) => {
|
|
213
|
-
const params = new URLSearchParams();
|
|
214
|
-
if (options === undefined) {
|
|
215
|
-
return params;
|
|
216
|
-
}
|
|
217
|
-
if (typeof options === "string" ||
|
|
218
|
-
typeof options === "number" ||
|
|
219
|
-
typeof options === "boolean" ||
|
|
220
|
-
typeof options === "bigint" ||
|
|
221
|
-
typeof options === "symbol" ||
|
|
222
|
-
typeof options === "function" ||
|
|
223
|
-
options === null ||
|
|
224
|
-
Array.isArray(options)) {
|
|
225
|
-
(0, exports.error)("Invalid type for query options. Must be an object.");
|
|
226
|
-
}
|
|
227
|
-
if ((options.id || "slug" in options || "cospar_id" in options) &&
|
|
228
|
-
Object.keys(options).length > 1) {
|
|
229
|
-
(0, exports.warn)("Using 'id', 'slug', or 'cospar_id' as query parameters generally returns a single result. Combining it with other parameters may not be achieving the result you expect.");
|
|
230
|
-
}
|
|
231
|
-
for (const option in options) {
|
|
232
|
-
if (!(option in optionsMap[resource])) {
|
|
233
|
-
(0, exports.warn)(`Parameter "${option}" is not a valid option for the ${resource} endpoint. It will be ignored.`);
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
if (options[option] === undefined) {
|
|
237
|
-
(0, exports.warn)(`Parameter "${option}" is undefined and will be ignored.`);
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
try {
|
|
241
|
-
const o = optionsMap[resource][option](options[option]);
|
|
242
|
-
params.set(option, o);
|
|
243
|
-
}
|
|
244
|
-
catch (err) {
|
|
245
|
-
(0, exports.error)(`Malformed query parameter for resource "${resource}" and parameter: "${option}": ${err}.`, "type");
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return params;
|
|
249
|
-
};
|
|
250
|
-
exports.queryOptionsValidator = queryOptionsValidator;
|
|
251
|
-
const warn = (msg) => console.warn(`[RLL Client]: ${msg}`);
|
|
252
|
-
exports.warn = warn;
|
|
253
|
-
const error = (msg, type = "error") => {
|
|
254
|
-
switch (type) {
|
|
255
|
-
case "error": {
|
|
256
|
-
throw new Error(`[RLL Client]: ${msg}`);
|
|
257
|
-
}
|
|
258
|
-
case "type": {
|
|
259
|
-
throw new TypeError(`[RLL Client]: ${msg}`);
|
|
260
|
-
}
|
|
261
|
-
case "range": {
|
|
262
|
-
throw new RangeError(`[RLL Client]: ${msg}`);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
exports.error = error;
|