rocket-launch-live-client 0.1.0 → 0.1.1
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/dist/Client.d.ts +12 -0
- package/dist/Client.js +12 -0
- package/dist/Client.js.map +1 -1
- package/package.json +1 -1
- package/tsconfig.json +1 -1
- package/src/Client.ts +0 -262
- package/src/fetcher.ts +0 -50
- package/src/index.ts +0 -29
- package/src/types/application.ts +0 -193
- package/src/types/standards.ts +0 -317
- package/src/utils.ts +0 -294
package/dist/Client.d.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { RLLClientOptions, RLLEntity, RLLQueryConfig, RLLResponse } from "./types/application";
|
|
2
|
+
/**
|
|
3
|
+
* Class representing a RocketLaunch.Live client
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
2
6
|
declare class RLLClient {
|
|
3
7
|
private apiKey;
|
|
4
8
|
private config;
|
|
9
|
+
/**
|
|
10
|
+
* Create a new RocketLaunch.live Client
|
|
11
|
+
*
|
|
12
|
+
* @param {string} apiKey - Your RocketLaunch.Live API Key
|
|
13
|
+
* @param {Object} [options] - Optional Client Configuration options
|
|
14
|
+
* @param {boolean} options.keyInQueryParams - Set to true to send your API Key via Query parameters instead of Authorization Header (not recommended)
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
5
17
|
constructor(apiKey: string, options?: RLLClientOptions);
|
|
6
18
|
/**
|
|
7
19
|
* Used internally to make API query
|
package/dist/Client.js
CHANGED
|
@@ -3,7 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
var application_1 = require("./types/application");
|
|
4
4
|
var fetcher_1 = require("./fetcher");
|
|
5
5
|
var utils_1 = require("./utils");
|
|
6
|
+
/**
|
|
7
|
+
* Class representing a RocketLaunch.Live client
|
|
8
|
+
* @class
|
|
9
|
+
*/
|
|
6
10
|
var RLLClient = /** @class */ (function () {
|
|
11
|
+
/**
|
|
12
|
+
* Create a new RocketLaunch.live Client
|
|
13
|
+
*
|
|
14
|
+
* @param {string} apiKey - Your RocketLaunch.Live API Key
|
|
15
|
+
* @param {Object} [options] - Optional Client Configuration options
|
|
16
|
+
* @param {boolean} options.keyInQueryParams - Set to true to send your API Key via Query parameters instead of Authorization Header (not recommended)
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
7
19
|
function RLLClient(apiKey, options) {
|
|
8
20
|
this.config = {
|
|
9
21
|
keyInQueryParams: false,
|
package/dist/Client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":";;AAAA,mDAM6B;AAC7B,qCAAoC;AACpC,iCAIiB;AAEjB;IAME,mBAAY,MAAc,EAAE,OAA0B;
|
|
1
|
+
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED
package/src/Client.ts
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RLLClientOptions,
|
|
3
|
-
RLLEndPoint,
|
|
4
|
-
RLLEntity,
|
|
5
|
-
RLLQueryConfig,
|
|
6
|
-
RLLResponse,
|
|
7
|
-
} from "./types/application";
|
|
8
|
-
import { fetcher } from "./fetcher";
|
|
9
|
-
import {
|
|
10
|
-
apiKeyValidator,
|
|
11
|
-
optionsValidator,
|
|
12
|
-
queryOptionsValidator,
|
|
13
|
-
} from "./utils";
|
|
14
|
-
|
|
15
|
-
class RLLClient {
|
|
16
|
-
private apiKey: string;
|
|
17
|
-
private config = {
|
|
18
|
-
keyInQueryParams: false,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
constructor(apiKey: string, options?: RLLClientOptions) {
|
|
22
|
-
// Validate API Key is a valid UUID format
|
|
23
|
-
// Constructor throws if not
|
|
24
|
-
apiKeyValidator(apiKey);
|
|
25
|
-
this.apiKey = apiKey;
|
|
26
|
-
|
|
27
|
-
if (!options) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Validate Options with warnings or throws
|
|
32
|
-
optionsValidator(options);
|
|
33
|
-
|
|
34
|
-
if (options.keyInQueryParams) {
|
|
35
|
-
this.config.keyInQueryParams = options.keyInQueryParams;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Used internally to make API query
|
|
41
|
-
*
|
|
42
|
-
* @private
|
|
43
|
-
*
|
|
44
|
-
* @template T
|
|
45
|
-
*
|
|
46
|
-
* @param {string} endpoint - API endpoint (ie. "/launches")
|
|
47
|
-
* @param {URLSearchParams} params - API Search Params
|
|
48
|
-
*
|
|
49
|
-
* @returns {Promise<T>}
|
|
50
|
-
*/
|
|
51
|
-
private query<T>(endpoint: string, params: URLSearchParams): Promise<T> {
|
|
52
|
-
return fetcher<T>(
|
|
53
|
-
this.apiKey,
|
|
54
|
-
endpoint,
|
|
55
|
-
params,
|
|
56
|
-
this.config.keyInQueryParams
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Fetch launch companies
|
|
62
|
-
*
|
|
63
|
-
* @public
|
|
64
|
-
* @function
|
|
65
|
-
*
|
|
66
|
-
* @param {Object} [options] - Launch Company Search Options
|
|
67
|
-
* @param {number | string} options.id - Company id
|
|
68
|
-
* @param {number | string} options.page - Page number of results
|
|
69
|
-
* @param {number | string} options.name - Company name
|
|
70
|
-
* @param {ISO3166Alpha2.CountryCode} options.country_code - ISO 3166 Alpha 2 Country Code
|
|
71
|
-
* @param {boolean} options.inactive - Company inactive status
|
|
72
|
-
*
|
|
73
|
-
* @returns {Promise<RLLResponse<RLLEntity.Company[]>>} Array of companies wrapped in a standard RLL Response
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
*
|
|
77
|
-
* const response = client.companies({ country_code: "US" })
|
|
78
|
-
*/
|
|
79
|
-
public companies(
|
|
80
|
-
options?: RLLQueryConfig.Companies
|
|
81
|
-
): Promise<RLLResponse<RLLEntity.Company[]>> {
|
|
82
|
-
return queryOptionsValidator(RLLEndPoint.COMPANIES, options).then(
|
|
83
|
-
(params) =>
|
|
84
|
-
this.query<RLLResponse<RLLEntity.Company[]>>(
|
|
85
|
-
RLLEndPoint.COMPANIES,
|
|
86
|
-
params
|
|
87
|
-
)
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Fetch launches
|
|
93
|
-
*
|
|
94
|
-
* @public
|
|
95
|
-
* @function
|
|
96
|
-
*
|
|
97
|
-
* @param {Object} [options] - Launch Search Options
|
|
98
|
-
* @param {number | string} options.id - Launch id
|
|
99
|
-
* @param {number | string} options.page - Page number of results
|
|
100
|
-
* @param {string} options.cospar_id - Launch COSPAR ID (ie. 2022-123)
|
|
101
|
-
* @param {Date | string} options.before_date - Only return launches before this date
|
|
102
|
-
* @param {Date | string} options.after_date - Only return launches after this date
|
|
103
|
-
* @param {Date | string} options.modified_since - Only return launches with API changes after this date
|
|
104
|
-
* @param {number | string} options.location_id - Launches from this Location
|
|
105
|
-
* @param {number | string} options.pad_id - Launches from this Pad
|
|
106
|
-
* @param {number | string} options.provider_id - Launches from this Company
|
|
107
|
-
* @param {number | string} options.tag_id - Launches with this Tag
|
|
108
|
-
* @param {number | string} options.vehicle_id - Launches on this Vehicle
|
|
109
|
-
* @param {ISO3166Alpha2.StateCodeUS} options.state_abbr - ISO 3166 Alpha 2 US State Code
|
|
110
|
-
* @param {ISO3166Alpha2.CountryCode} options.country_code - ISO 3166 Alpha 2 Country Code
|
|
111
|
-
* @param {number | string} options.search - Launches matching this search string
|
|
112
|
-
* @param {number | string} options.slug - Launches matching this unique slug
|
|
113
|
-
*
|
|
114
|
-
* @returns {Promise<RLLResponse<RLLEntity.Launch[]>>} Array of companies wrapped in a standard RLL Response
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
*
|
|
118
|
-
* const response = client.launches({ after_date: new Date("2022-10-10") })
|
|
119
|
-
*/
|
|
120
|
-
public launches(
|
|
121
|
-
options?: RLLQueryConfig.Launches
|
|
122
|
-
): Promise<RLLResponse<RLLEntity.Launch[]>> {
|
|
123
|
-
return queryOptionsValidator(RLLEndPoint.LAUNCHES, options).then((params) =>
|
|
124
|
-
this.query<RLLResponse<RLLEntity.Launch[]>>(RLLEndPoint.LAUNCHES, params)
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Fetch launch locations
|
|
130
|
-
*
|
|
131
|
-
* @public
|
|
132
|
-
* @function
|
|
133
|
-
*
|
|
134
|
-
* @param {Object} [options] - Launch Location Search Options
|
|
135
|
-
* @param {number | string} options.id - Location id
|
|
136
|
-
* @param {number | string} options.page - Page number of results
|
|
137
|
-
* @param {number | string} options.name - Location name
|
|
138
|
-
* @param {ISO3166Alpha2.StateCodeUS} options.state_abbr - ISO 3166 Alpha 2 US State Code
|
|
139
|
-
* @param {ISO3166Alpha2.CountryCode} options.country_code - ISO 3166 Alpha 2 Country Code
|
|
140
|
-
*
|
|
141
|
-
* @returns {Promise<RLLResponse<RLLEntity.Location[]>>} Array of companies wrapped in a standard RLL Response
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
*
|
|
145
|
-
* const response = client.locations({ country_code: "US" })
|
|
146
|
-
*/
|
|
147
|
-
public locations(
|
|
148
|
-
options?: RLLQueryConfig.Locations
|
|
149
|
-
): Promise<RLLResponse<RLLEntity.Location[]>> {
|
|
150
|
-
return queryOptionsValidator(RLLEndPoint.LOCATIONS, options).then(
|
|
151
|
-
(params) =>
|
|
152
|
-
this.query<RLLResponse<RLLEntity.Location[]>>(
|
|
153
|
-
RLLEndPoint.LOCATIONS,
|
|
154
|
-
params
|
|
155
|
-
)
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Fetch launch Missions
|
|
161
|
-
*
|
|
162
|
-
* @public
|
|
163
|
-
* @function
|
|
164
|
-
*
|
|
165
|
-
* @param {Object} [options] - Launch Mission Search Options
|
|
166
|
-
* @param {number | string} options.id - Mission id
|
|
167
|
-
* @param {number | string} options.page - Page number of results
|
|
168
|
-
* @param {number | string} options.name - Mission name
|
|
169
|
-
*
|
|
170
|
-
* @returns {Promise<RLLResponse<RLLEntity.Mission[]>>} Array of companies wrapped in a standard RLL Response
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
*
|
|
174
|
-
* const response = client.missions({ name: "Mars 2020" })
|
|
175
|
-
*/
|
|
176
|
-
public missions(
|
|
177
|
-
options?: RLLQueryConfig.Missions
|
|
178
|
-
): Promise<RLLResponse<RLLEntity.Mission[]>> {
|
|
179
|
-
return queryOptionsValidator(RLLEndPoint.MISSIONS, options).then((params) =>
|
|
180
|
-
this.query<RLLResponse<RLLEntity.Mission[]>>(RLLEndPoint.MISSIONS, params)
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Fetch launch pads
|
|
186
|
-
*
|
|
187
|
-
* @public
|
|
188
|
-
* @function
|
|
189
|
-
*
|
|
190
|
-
* @param {Object} [options] - Launch Pad Search Options
|
|
191
|
-
* @param {number | string} options.id - Pad id
|
|
192
|
-
* @param {number | string} options.page - Page number of results
|
|
193
|
-
* @param {number | string} options.name - Pad name
|
|
194
|
-
* @param {ISO3166Alpha2.StateCodeUS} options.state_abbr - ISO 3166 Alpha 2 US State Code
|
|
195
|
-
* @param {ISO3166Alpha2.CountryCode} options.country_code - ISO 3166 Alpha 2 Country Code
|
|
196
|
-
*
|
|
197
|
-
* @returns {Promise<RLLResponse<RLLEntity.Pad[]>>} Array of companies wrapped in a standard RLL Response
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
*
|
|
201
|
-
* const response = client.pads({ country_code: "US" })
|
|
202
|
-
*/
|
|
203
|
-
public pads(
|
|
204
|
-
options?: RLLQueryConfig.Pads
|
|
205
|
-
): Promise<RLLResponse<RLLEntity.Pad[]>> {
|
|
206
|
-
return queryOptionsValidator(RLLEndPoint.PADS, options).then((params) =>
|
|
207
|
-
this.query<RLLResponse<RLLEntity.Pad[]>>(RLLEndPoint.PADS, params)
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Fetch launch tags
|
|
213
|
-
*
|
|
214
|
-
* @public
|
|
215
|
-
* @function
|
|
216
|
-
*
|
|
217
|
-
* @param {Object} [options] - Launch Tag Search Options
|
|
218
|
-
* @param {number | string} options.id - Tag id
|
|
219
|
-
* @param {number | string} options.page - Page number of results
|
|
220
|
-
* @param {number | string} options.text - Tag text
|
|
221
|
-
*
|
|
222
|
-
* @returns {Promise<RLLResponse<RLLEntity.Tag[]>>} Array of companies wrapped in a standard RLL Response
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
*
|
|
226
|
-
* const response = client.tags({ text: "Crewed" })
|
|
227
|
-
*/
|
|
228
|
-
public tags(
|
|
229
|
-
options?: RLLQueryConfig.Tags
|
|
230
|
-
): Promise<RLLResponse<RLLEntity.Tag[]>> {
|
|
231
|
-
return queryOptionsValidator(RLLEndPoint.TAGS, options).then((params) =>
|
|
232
|
-
this.query<RLLResponse<RLLEntity.Tag[]>>(RLLEndPoint.TAGS, params)
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Fetch launch Vehicles
|
|
238
|
-
*
|
|
239
|
-
* @public
|
|
240
|
-
* @function
|
|
241
|
-
*
|
|
242
|
-
* @param {Object} [options] - Launch Vehicles Search Options
|
|
243
|
-
* @param {number | string} options.id - Vehicle id
|
|
244
|
-
* @param {number | string} options.page - Page number of results
|
|
245
|
-
* @param {number | string} options.name - Vehicle name
|
|
246
|
-
*
|
|
247
|
-
* @returns {Promise<RLLResponse<RLLEntity.Vehicle[]>>} Array of companies wrapped in a standard RLL Response
|
|
248
|
-
*
|
|
249
|
-
* @example
|
|
250
|
-
*
|
|
251
|
-
* const response = client.vehicles({ name: "Falcon 9" })
|
|
252
|
-
*/
|
|
253
|
-
public vehicles(
|
|
254
|
-
options?: RLLQueryConfig.Vehicles
|
|
255
|
-
): Promise<RLLResponse<RLLEntity.Vehicle[]>> {
|
|
256
|
-
return queryOptionsValidator(RLLEndPoint.VEHICLES, options).then((params) =>
|
|
257
|
-
this.query<RLLResponse<RLLEntity.Vehicle[]>>(RLLEndPoint.VEHICLES, params)
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export default RLLClient;
|
package/src/fetcher.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
const https = require("node:https");
|
|
2
|
-
|
|
3
|
-
const BASE_URL = "https://fdo.rocketlaunch.live";
|
|
4
|
-
|
|
5
|
-
export const fetcher = <T>(
|
|
6
|
-
apiKey: string,
|
|
7
|
-
endpoint: string,
|
|
8
|
-
params: URLSearchParams,
|
|
9
|
-
keyInQueryParams: boolean
|
|
10
|
-
): Promise<T> => {
|
|
11
|
-
const url = new URL("json/" + endpoint, BASE_URL);
|
|
12
|
-
let headers: HeadersInit | undefined;
|
|
13
|
-
|
|
14
|
-
if (keyInQueryParams) {
|
|
15
|
-
params.set("key", apiKey);
|
|
16
|
-
} else {
|
|
17
|
-
headers = { authorization: `Bearer ${apiKey}` };
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
params.forEach((v, k) => url.searchParams.set(k, v));
|
|
21
|
-
|
|
22
|
-
return query<T>(url, headers);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const query = <T>(url: URL, headers?: HeadersInit): Promise<T> => {
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
const req = https.get(url, { headers }, (res) => {
|
|
28
|
-
let data = [];
|
|
29
|
-
|
|
30
|
-
res.on("data", (chunk) => data.push(chunk));
|
|
31
|
-
|
|
32
|
-
res.on("end", () => {
|
|
33
|
-
if (res.statusCode === 200) {
|
|
34
|
-
const response = Buffer.concat(data).toString();
|
|
35
|
-
resolve(JSON.parse(response));
|
|
36
|
-
} else if (res.statusCode === 404) {
|
|
37
|
-
reject({
|
|
38
|
-
error: "Resource not found",
|
|
39
|
-
statusCode: 404,
|
|
40
|
-
message:
|
|
41
|
-
"The server returned a 404 Not Found response. Check that your API key is valid, and that you are not requesting a page number beyond the available results.",
|
|
42
|
-
});
|
|
43
|
-
} else {
|
|
44
|
-
reject(res);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
req.on("error", reject);
|
|
49
|
-
});
|
|
50
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import RLLClient from "./Client";
|
|
2
|
-
import { RLLClientOptions } from "./types/application";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Generate a RocketLaunch.Live client
|
|
6
|
-
*
|
|
7
|
-
* @public
|
|
8
|
-
* @function
|
|
9
|
-
*
|
|
10
|
-
* @param {string} apiKey - Your RocketLaunch.Live API Key
|
|
11
|
-
* @param {Object} [options] - Optional Client Configuration options
|
|
12
|
-
* @param {boolean} options.keyInQueryParams - Set to true to send your API Key via Query parameters instead of Authorization Header (not recommended)
|
|
13
|
-
*
|
|
14
|
-
* @returns {RLLCLient}
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
*
|
|
18
|
-
* const MY_KEY = process.env.ROCKETLAUNCH_LIVE_API_KEY
|
|
19
|
-
*
|
|
20
|
-
* const client = clientGenerator(MY_KEY, { keyInQueryParams: true })
|
|
21
|
-
*/
|
|
22
|
-
const clientGenerator = (
|
|
23
|
-
apiKey: string,
|
|
24
|
-
options?: RLLClientOptions
|
|
25
|
-
): RLLClient => {
|
|
26
|
-
return new RLLClient(apiKey, options);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default clientGenerator;
|
package/src/types/application.ts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { ISO3166Alpha2 } from "./standards";
|
|
2
|
-
|
|
3
|
-
export enum RLLEndPoint {
|
|
4
|
-
COMPANIES = "companies",
|
|
5
|
-
LAUNCHES = "launches",
|
|
6
|
-
LOCATIONS = "locations",
|
|
7
|
-
MISSIONS = "missions",
|
|
8
|
-
PADS = "pads",
|
|
9
|
-
TAGS = "tags",
|
|
10
|
-
VEHICLES = "vehicles",
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface RLLRecord {
|
|
14
|
-
id: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export namespace RLLEntity {
|
|
18
|
-
interface Country {
|
|
19
|
-
name: string;
|
|
20
|
-
code: ISO3166Alpha2.CountryCode;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface State {
|
|
24
|
-
name: string;
|
|
25
|
-
abbr: ISO3166Alpha2.StateCodeUS;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface Company extends RLLRecord {
|
|
29
|
-
country: Country;
|
|
30
|
-
inactive: boolean | null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
enum LaunchResult {
|
|
34
|
-
NOT_SET = -1,
|
|
35
|
-
FAILURE = 0,
|
|
36
|
-
SUCCESS = 1,
|
|
37
|
-
PARTIAL_FAILURE = 2,
|
|
38
|
-
IN_FLIGHT_ABORT_CREWED = 3,
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface Media extends RLLRecord {
|
|
42
|
-
media_url: string | null;
|
|
43
|
-
youtube_vidid: string | null;
|
|
44
|
-
featured: boolean;
|
|
45
|
-
ldfeatured: boolean;
|
|
46
|
-
approved: boolean;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface Launch extends RLLRecord {
|
|
50
|
-
name: string;
|
|
51
|
-
cospar_id: string;
|
|
52
|
-
sort_date: string;
|
|
53
|
-
provider: Omit<Company, "inactive" | "country">;
|
|
54
|
-
vehicle: Omit<Vehicle, "company_id" | "company">;
|
|
55
|
-
pad: Omit<Pad, "full_name">;
|
|
56
|
-
missions: Omit<Mission, "launch_id">[];
|
|
57
|
-
mission_description: string | null;
|
|
58
|
-
launch_description: string;
|
|
59
|
-
win_open: string | null;
|
|
60
|
-
t0: string | null;
|
|
61
|
-
win_close: string | null;
|
|
62
|
-
est_date: {
|
|
63
|
-
month: number | null;
|
|
64
|
-
day: number | null;
|
|
65
|
-
year: number | null;
|
|
66
|
-
quarter: number | null;
|
|
67
|
-
};
|
|
68
|
-
date_str: string;
|
|
69
|
-
tags: Omit<Tag, "slug">[];
|
|
70
|
-
slug: string;
|
|
71
|
-
weather_summary: string | null;
|
|
72
|
-
weather_temp: number | null;
|
|
73
|
-
weather_icon: string | null;
|
|
74
|
-
weather_updated: string | null;
|
|
75
|
-
quicktext: string;
|
|
76
|
-
media?: Media[];
|
|
77
|
-
result: LaunchResult;
|
|
78
|
-
suborbital: boolean;
|
|
79
|
-
modified: string;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface Location extends RLLRecord {
|
|
83
|
-
name: string;
|
|
84
|
-
latitute: string; // original API had a typo which was preserved for backwards compatibility
|
|
85
|
-
latitude: string;
|
|
86
|
-
longitude: string;
|
|
87
|
-
state: State | null;
|
|
88
|
-
statename?: string | null;
|
|
89
|
-
country: Country;
|
|
90
|
-
pads: Omit<Pad, "location" | "country" | "state">[];
|
|
91
|
-
utc_offset: number;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface Mission extends RLLRecord {
|
|
95
|
-
name: string;
|
|
96
|
-
description: string | null;
|
|
97
|
-
launch_id: number;
|
|
98
|
-
company: Omit<Company, "slug" | "inactive" | "country">;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export interface Pad extends RLLRecord {
|
|
102
|
-
name: string;
|
|
103
|
-
full_name: string;
|
|
104
|
-
location: Omit<Location, "pads" | "utc_offset" | "latitute">;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export interface Tag extends RLLRecord {
|
|
108
|
-
text: string;
|
|
109
|
-
slug: string;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export interface Vehicle extends RLLRecord {
|
|
113
|
-
name: string;
|
|
114
|
-
company_id?: number;
|
|
115
|
-
company: Omit<Company, "slug" | "inactive" | "country">;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
interface RLLBaseQueryConfig {
|
|
120
|
-
id?: number | string;
|
|
121
|
-
page?: number | string;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export namespace RLLQueryConfig {
|
|
125
|
-
export interface Companies extends RLLBaseQueryConfig {
|
|
126
|
-
name?: string | number;
|
|
127
|
-
country_code?: ISO3166Alpha2.CountryCode;
|
|
128
|
-
inactive?: boolean;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface Launches extends RLLBaseQueryConfig {
|
|
132
|
-
cospar_id?: string;
|
|
133
|
-
after_date?: Date | string;
|
|
134
|
-
before_date?: Date | string;
|
|
135
|
-
modified_since?: Date | string;
|
|
136
|
-
location_id?: number | string;
|
|
137
|
-
pad_id?: number | string;
|
|
138
|
-
provider_id?: number | string;
|
|
139
|
-
tag_id?: number | string;
|
|
140
|
-
vehicle_id?: number | string;
|
|
141
|
-
state_abbr?: ISO3166Alpha2.StateCodeUS;
|
|
142
|
-
country_code?: ISO3166Alpha2.CountryCode;
|
|
143
|
-
search?: string | number;
|
|
144
|
-
slug?: string | number;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export interface Locations extends RLLBaseQueryConfig {
|
|
148
|
-
name?: string | number;
|
|
149
|
-
state_abbr?: ISO3166Alpha2.StateCodeUS;
|
|
150
|
-
country_code?: ISO3166Alpha2.CountryCode;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export interface Missions extends RLLBaseQueryConfig {
|
|
154
|
-
name?: string | number;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export interface Pads extends RLLBaseQueryConfig {
|
|
158
|
-
name?: string | number;
|
|
159
|
-
state_abbr?: ISO3166Alpha2.StateCodeUS;
|
|
160
|
-
country_code?: ISO3166Alpha2.CountryCode;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export interface Tags extends RLLBaseQueryConfig {
|
|
164
|
-
text?: string | number;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export interface Vehicles extends RLLBaseQueryConfig {
|
|
168
|
-
name?: string | number;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export interface All
|
|
172
|
-
extends Companies,
|
|
173
|
-
Launches,
|
|
174
|
-
Locations,
|
|
175
|
-
Missions,
|
|
176
|
-
Pads,
|
|
177
|
-
Tags,
|
|
178
|
-
Vehicles {}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export type RLLClientOptions = {
|
|
182
|
-
keyInQueryParams?: boolean;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
export type RLLResponse<T> = {
|
|
186
|
-
errors?: string[];
|
|
187
|
-
valid_auth: boolean;
|
|
188
|
-
count: number;
|
|
189
|
-
limit: number;
|
|
190
|
-
total: number;
|
|
191
|
-
last_page: number;
|
|
192
|
-
result: T;
|
|
193
|
-
};
|
package/src/types/standards.ts
DELETED
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
export const countryCodes = {
|
|
2
|
-
AF: "AF",
|
|
3
|
-
AL: "AL",
|
|
4
|
-
DZ: "DZ",
|
|
5
|
-
AS: "AS",
|
|
6
|
-
AD: "AD",
|
|
7
|
-
AO: "AO",
|
|
8
|
-
AI: "AI",
|
|
9
|
-
AQ: "AQ",
|
|
10
|
-
AG: "AG",
|
|
11
|
-
AR: "AR",
|
|
12
|
-
AM: "AM",
|
|
13
|
-
AW: "AW",
|
|
14
|
-
AU: "AU",
|
|
15
|
-
AT: "AT",
|
|
16
|
-
AZ: "AZ",
|
|
17
|
-
BS: "BS",
|
|
18
|
-
BH: "BH",
|
|
19
|
-
BD: "BD",
|
|
20
|
-
BB: "BB",
|
|
21
|
-
BY: "BY",
|
|
22
|
-
BE: "BE",
|
|
23
|
-
BZ: "BZ",
|
|
24
|
-
BJ: "BJ",
|
|
25
|
-
BM: "BM",
|
|
26
|
-
BT: "BT",
|
|
27
|
-
BO: "BO",
|
|
28
|
-
BQ: "BQ",
|
|
29
|
-
BA: "BA",
|
|
30
|
-
BW: "BW",
|
|
31
|
-
BV: "BV",
|
|
32
|
-
BR: "BR",
|
|
33
|
-
IO: "IO",
|
|
34
|
-
BN: "BN",
|
|
35
|
-
BG: "BG",
|
|
36
|
-
BF: "BF",
|
|
37
|
-
BI: "BI",
|
|
38
|
-
CV: "CV",
|
|
39
|
-
KH: "KH",
|
|
40
|
-
CM: "CM",
|
|
41
|
-
CA: "CA",
|
|
42
|
-
KY: "KY",
|
|
43
|
-
CF: "CF",
|
|
44
|
-
TD: "TD",
|
|
45
|
-
CL: "CL",
|
|
46
|
-
CN: "CN",
|
|
47
|
-
CX: "CX",
|
|
48
|
-
CC: "CC",
|
|
49
|
-
CO: "CO",
|
|
50
|
-
KM: "KM",
|
|
51
|
-
CD: "CD",
|
|
52
|
-
CG: "CG",
|
|
53
|
-
CK: "CK",
|
|
54
|
-
CR: "CR",
|
|
55
|
-
HR: "HR",
|
|
56
|
-
CU: "CU",
|
|
57
|
-
CW: "CW",
|
|
58
|
-
CY: "CY",
|
|
59
|
-
CZ: "CZ",
|
|
60
|
-
CI: "CI",
|
|
61
|
-
DK: "DK",
|
|
62
|
-
DJ: "DJ",
|
|
63
|
-
DM: "DM",
|
|
64
|
-
DO: "DO",
|
|
65
|
-
EC: "EC",
|
|
66
|
-
EG: "EG",
|
|
67
|
-
SV: "SV",
|
|
68
|
-
GQ: "GQ",
|
|
69
|
-
ER: "ER",
|
|
70
|
-
EE: "EE",
|
|
71
|
-
SZ: "SZ",
|
|
72
|
-
ET: "ET",
|
|
73
|
-
FK: "FK",
|
|
74
|
-
FO: "FO",
|
|
75
|
-
FJ: "FJ",
|
|
76
|
-
FI: "FI",
|
|
77
|
-
FR: "FR",
|
|
78
|
-
GF: "GF",
|
|
79
|
-
PF: "PF",
|
|
80
|
-
TF: "TF",
|
|
81
|
-
GA: "GA",
|
|
82
|
-
GM: "GM",
|
|
83
|
-
GE: "GE",
|
|
84
|
-
DE: "DE",
|
|
85
|
-
GH: "GH",
|
|
86
|
-
GI: "GI",
|
|
87
|
-
GR: "GR",
|
|
88
|
-
GL: "GL",
|
|
89
|
-
GD: "GD",
|
|
90
|
-
GP: "GP",
|
|
91
|
-
GU: "GU",
|
|
92
|
-
GT: "GT",
|
|
93
|
-
GG: "GG",
|
|
94
|
-
GN: "GN",
|
|
95
|
-
GW: "GW",
|
|
96
|
-
GY: "GY",
|
|
97
|
-
HT: "HT",
|
|
98
|
-
HM: "HM",
|
|
99
|
-
VA: "VA",
|
|
100
|
-
HN: "HN",
|
|
101
|
-
HK: "HK",
|
|
102
|
-
HU: "HU",
|
|
103
|
-
IS: "IS",
|
|
104
|
-
IN: "IN",
|
|
105
|
-
ID: "ID",
|
|
106
|
-
IR: "IR",
|
|
107
|
-
IQ: "IQ",
|
|
108
|
-
IE: "IE",
|
|
109
|
-
IM: "IM",
|
|
110
|
-
IL: "IL",
|
|
111
|
-
IT: "IT",
|
|
112
|
-
JM: "JM",
|
|
113
|
-
JP: "JP",
|
|
114
|
-
JE: "JE",
|
|
115
|
-
JO: "JO",
|
|
116
|
-
KZ: "KZ",
|
|
117
|
-
KE: "KE",
|
|
118
|
-
KI: "KI",
|
|
119
|
-
KP: "KP",
|
|
120
|
-
KR: "KR",
|
|
121
|
-
KW: "KW",
|
|
122
|
-
KG: "KG",
|
|
123
|
-
LA: "LA",
|
|
124
|
-
LV: "LV",
|
|
125
|
-
LB: "LB",
|
|
126
|
-
LS: "LS",
|
|
127
|
-
LR: "LR",
|
|
128
|
-
LY: "LY",
|
|
129
|
-
LI: "LI",
|
|
130
|
-
LT: "LT",
|
|
131
|
-
LU: "LU",
|
|
132
|
-
MO: "MO",
|
|
133
|
-
MG: "MG",
|
|
134
|
-
MW: "MW",
|
|
135
|
-
MY: "MY",
|
|
136
|
-
MV: "MV",
|
|
137
|
-
ML: "ML",
|
|
138
|
-
MT: "MT",
|
|
139
|
-
MH: "MH",
|
|
140
|
-
MQ: "MQ",
|
|
141
|
-
MR: "MR",
|
|
142
|
-
MU: "MU",
|
|
143
|
-
YT: "YT",
|
|
144
|
-
MX: "MX",
|
|
145
|
-
FM: "FM",
|
|
146
|
-
MD: "MD",
|
|
147
|
-
MC: "MC",
|
|
148
|
-
MN: "MN",
|
|
149
|
-
ME: "ME",
|
|
150
|
-
MS: "MS",
|
|
151
|
-
MA: "MA",
|
|
152
|
-
MZ: "MZ",
|
|
153
|
-
MM: "MM",
|
|
154
|
-
NA: "NA",
|
|
155
|
-
NR: "NR",
|
|
156
|
-
NP: "NP",
|
|
157
|
-
NL: "NL",
|
|
158
|
-
NC: "NC",
|
|
159
|
-
NZ: "NZ",
|
|
160
|
-
NI: "NI",
|
|
161
|
-
NE: "NE",
|
|
162
|
-
NG: "NG",
|
|
163
|
-
NU: "NU",
|
|
164
|
-
NF: "NF",
|
|
165
|
-
MP: "MP",
|
|
166
|
-
NO: "NO",
|
|
167
|
-
OM: "OM",
|
|
168
|
-
PK: "PK",
|
|
169
|
-
PW: "PW",
|
|
170
|
-
PS: "PS",
|
|
171
|
-
PA: "PA",
|
|
172
|
-
PG: "PG",
|
|
173
|
-
PY: "PY",
|
|
174
|
-
PE: "PE",
|
|
175
|
-
PH: "PH",
|
|
176
|
-
PN: "PN",
|
|
177
|
-
PL: "PL",
|
|
178
|
-
PT: "PT",
|
|
179
|
-
PR: "PR",
|
|
180
|
-
QA: "QA",
|
|
181
|
-
MK: "MK",
|
|
182
|
-
RO: "RO",
|
|
183
|
-
RU: "RU",
|
|
184
|
-
RW: "RW",
|
|
185
|
-
RE: "RE",
|
|
186
|
-
BL: "BL",
|
|
187
|
-
SH: "SH",
|
|
188
|
-
KN: "KN",
|
|
189
|
-
LC: "LC",
|
|
190
|
-
MF: "MF",
|
|
191
|
-
PM: "PM",
|
|
192
|
-
VC: "VC",
|
|
193
|
-
WS: "WS",
|
|
194
|
-
SM: "SM",
|
|
195
|
-
ST: "ST",
|
|
196
|
-
SA: "SA",
|
|
197
|
-
SN: "SN",
|
|
198
|
-
RS: "RS",
|
|
199
|
-
SC: "SC",
|
|
200
|
-
SL: "SL",
|
|
201
|
-
SG: "SG",
|
|
202
|
-
SX: "SX",
|
|
203
|
-
SK: "SK",
|
|
204
|
-
SI: "SI",
|
|
205
|
-
SB: "SB",
|
|
206
|
-
SO: "SO",
|
|
207
|
-
ZA: "ZA",
|
|
208
|
-
GS: "GS",
|
|
209
|
-
SS: "SS",
|
|
210
|
-
ES: "ES",
|
|
211
|
-
LK: "LK",
|
|
212
|
-
SD: "SD",
|
|
213
|
-
SR: "SR",
|
|
214
|
-
SJ: "SJ",
|
|
215
|
-
SE: "SE",
|
|
216
|
-
CH: "CH",
|
|
217
|
-
SY: "SY",
|
|
218
|
-
TW: "TW",
|
|
219
|
-
TJ: "TJ",
|
|
220
|
-
TZ: "TZ",
|
|
221
|
-
TH: "TH",
|
|
222
|
-
TL: "TL",
|
|
223
|
-
TG: "TG",
|
|
224
|
-
TK: "TK",
|
|
225
|
-
TO: "TO",
|
|
226
|
-
TT: "TT",
|
|
227
|
-
TN: "TN",
|
|
228
|
-
TR: "TR",
|
|
229
|
-
TM: "TM",
|
|
230
|
-
TC: "TC",
|
|
231
|
-
TV: "TV",
|
|
232
|
-
UG: "UG",
|
|
233
|
-
UA: "UA",
|
|
234
|
-
AE: "AE",
|
|
235
|
-
GB: "GB",
|
|
236
|
-
UM: "UM",
|
|
237
|
-
US: "US",
|
|
238
|
-
UY: "UY",
|
|
239
|
-
UZ: "UZ",
|
|
240
|
-
VU: "VU",
|
|
241
|
-
VE: "VE",
|
|
242
|
-
VN: "VN",
|
|
243
|
-
VG: "VG",
|
|
244
|
-
VI: "VI",
|
|
245
|
-
WF: "WF",
|
|
246
|
-
EH: "EH",
|
|
247
|
-
YE: "YE",
|
|
248
|
-
ZM: "ZM",
|
|
249
|
-
ZW: "ZW",
|
|
250
|
-
AX: "AX",
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
export const usStateCodes = {
|
|
254
|
-
AL: "AL",
|
|
255
|
-
AK: "AK",
|
|
256
|
-
AZ: "AZ",
|
|
257
|
-
AR: "AR",
|
|
258
|
-
CA: "CA",
|
|
259
|
-
CO: "CO",
|
|
260
|
-
CT: "CT",
|
|
261
|
-
DE: "DE",
|
|
262
|
-
FL: "FL",
|
|
263
|
-
GA: "GA",
|
|
264
|
-
HI: "HI",
|
|
265
|
-
ID: "ID",
|
|
266
|
-
IL: "IL",
|
|
267
|
-
IN: "IN",
|
|
268
|
-
IA: "IA",
|
|
269
|
-
KS: "KS",
|
|
270
|
-
KY: "KY",
|
|
271
|
-
LA: "LA",
|
|
272
|
-
ME: "ME",
|
|
273
|
-
MD: "MD",
|
|
274
|
-
MA: "MA",
|
|
275
|
-
MI: "MI",
|
|
276
|
-
MN: "MN",
|
|
277
|
-
MS: "MS",
|
|
278
|
-
MO: "MO",
|
|
279
|
-
MT: "MT",
|
|
280
|
-
NE: "NE",
|
|
281
|
-
NV: "NV",
|
|
282
|
-
NH: "NH",
|
|
283
|
-
NJ: "NJ",
|
|
284
|
-
NM: "NM",
|
|
285
|
-
NY: "NY",
|
|
286
|
-
NC: "NC",
|
|
287
|
-
ND: "ND",
|
|
288
|
-
OH: "OH",
|
|
289
|
-
OK: "OK",
|
|
290
|
-
OR: "OR",
|
|
291
|
-
PA: "PA",
|
|
292
|
-
RI: "RI",
|
|
293
|
-
SC: "SC",
|
|
294
|
-
SD: "SD",
|
|
295
|
-
TN: "TN",
|
|
296
|
-
TX: "TX",
|
|
297
|
-
UT: "UT",
|
|
298
|
-
VT: "VT",
|
|
299
|
-
VA: "VA",
|
|
300
|
-
WA: "WA",
|
|
301
|
-
WV: "WV",
|
|
302
|
-
WI: "WI",
|
|
303
|
-
WY: "WY",
|
|
304
|
-
DC: "DC",
|
|
305
|
-
AS: "AS",
|
|
306
|
-
GU: "GU",
|
|
307
|
-
MP: "MP",
|
|
308
|
-
PR: "PR",
|
|
309
|
-
UM: "UM",
|
|
310
|
-
VI: "VI",
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
export namespace ISO3166Alpha2 {
|
|
314
|
-
export type CountryCode = keyof typeof countryCodes;
|
|
315
|
-
|
|
316
|
-
export type StateCodeUS = keyof typeof usStateCodes;
|
|
317
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import { RLLEndPoint, RLLQueryConfig } from "./types/application";
|
|
2
|
-
import { countryCodes, usStateCodes } from "./types/standards";
|
|
3
|
-
|
|
4
|
-
const getLeadingZero = (month: number, offset: number = 0): string => {
|
|
5
|
-
const str = "0".concat((month + offset).toString());
|
|
6
|
-
return str.slice(-2);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const apiKeyValidator = (apiKey: any): void => {
|
|
10
|
-
if (apiKey === undefined) {
|
|
11
|
-
error("RLL Client requires API Key", "type");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (typeof apiKey !== "string") {
|
|
15
|
-
error("RLL Client API Key must be a string", "type");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (apiKey === "") {
|
|
19
|
-
error("RLL Client API Key cannot be an empty string", "type");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const validator = apiKey.match(
|
|
23
|
-
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
if (validator === null) {
|
|
27
|
-
error(
|
|
28
|
-
"RLL Client API Key appears malformed. RLL Client API Keys are in UUID format.",
|
|
29
|
-
"type"
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const optionsValidator = (options: {}): void => {
|
|
35
|
-
for (const option in options) {
|
|
36
|
-
if (option !== "keyInQueryParams") {
|
|
37
|
-
warn(
|
|
38
|
-
`RLL Client options do not accept a "${option}" property. This property will be ignored.`
|
|
39
|
-
);
|
|
40
|
-
} else {
|
|
41
|
-
if (typeof options[option] !== "boolean") {
|
|
42
|
-
error(
|
|
43
|
-
"RLL Client configuration option 'keyInQueryParams' must be a boolean.",
|
|
44
|
-
"type"
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const validators = {
|
|
52
|
-
string: (option: any): Promise<string> => {
|
|
53
|
-
return new Promise((resolve, reject) => {
|
|
54
|
-
if (typeof option === "number") {
|
|
55
|
-
resolve(option.toString());
|
|
56
|
-
}
|
|
57
|
-
if (typeof option !== "string") {
|
|
58
|
-
return reject("Must be a string");
|
|
59
|
-
}
|
|
60
|
-
if (option.length <= 0) {
|
|
61
|
-
return reject("String must have length greater than 0");
|
|
62
|
-
}
|
|
63
|
-
resolve(option);
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
boolean: (option: any): Promise<number> => {
|
|
67
|
-
return new Promise((resolve, reject) => {
|
|
68
|
-
if (typeof option !== "boolean") {
|
|
69
|
-
return reject("Must be a boolean");
|
|
70
|
-
}
|
|
71
|
-
resolve(option === true ? 1 : 0);
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
number: (option: any): Promise<number> => {
|
|
75
|
-
return new Promise((resolve, reject) => {
|
|
76
|
-
if (typeof option === "number") {
|
|
77
|
-
return resolve(option);
|
|
78
|
-
}
|
|
79
|
-
if (
|
|
80
|
-
typeof option !== "string" ||
|
|
81
|
-
option === "" ||
|
|
82
|
-
isNaN(Number(option))
|
|
83
|
-
) {
|
|
84
|
-
return reject("Must be a number");
|
|
85
|
-
} else {
|
|
86
|
-
resolve(Number(option));
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
},
|
|
90
|
-
countryCode: (option: any): Promise<string> => {
|
|
91
|
-
return new Promise((resolve, reject) => {
|
|
92
|
-
if (typeof option !== "string") {
|
|
93
|
-
return reject("Must be a string");
|
|
94
|
-
}
|
|
95
|
-
if (!countryCodes[option]) {
|
|
96
|
-
return reject(
|
|
97
|
-
"Invalid country code. Country codes should follow ISO 3166-1 A2 convention, like 'US'."
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
resolve(option);
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
stateCode: (option: any): Promise<string> => {
|
|
104
|
-
return new Promise((resolve, reject) => {
|
|
105
|
-
if (typeof option !== "string") {
|
|
106
|
-
return reject("Must be a string");
|
|
107
|
-
}
|
|
108
|
-
if (!usStateCodes[option]) {
|
|
109
|
-
return reject(
|
|
110
|
-
"Invalid United States State Code. State Codes should follow ISO 3166-2 convention, like 'FL'."
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
resolve(option);
|
|
114
|
-
});
|
|
115
|
-
},
|
|
116
|
-
cosparId: (option: any): Promise<string> => {
|
|
117
|
-
return new Promise((resolve, reject) => {
|
|
118
|
-
if (typeof option !== "string") {
|
|
119
|
-
return reject("Must be a string");
|
|
120
|
-
}
|
|
121
|
-
if (!option.match(/^\d{4}\-\d{3}$/g)) {
|
|
122
|
-
return reject(
|
|
123
|
-
"Cospar IDs must be in the format of YYYY-NNN (eg. 2023-123)"
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
resolve(option);
|
|
127
|
-
});
|
|
128
|
-
},
|
|
129
|
-
shortDate: (option: any): Promise<string> => {
|
|
130
|
-
return new Promise((resolve, reject) => {
|
|
131
|
-
if (typeof option === "string" || option instanceof Date) {
|
|
132
|
-
let date: Date;
|
|
133
|
-
|
|
134
|
-
if (typeof option === "string") {
|
|
135
|
-
const parsed = Date.parse(option);
|
|
136
|
-
if (isNaN(parsed)) {
|
|
137
|
-
return reject("Must be an ISO 8601 Date String");
|
|
138
|
-
}
|
|
139
|
-
date = new Date(parsed);
|
|
140
|
-
} else {
|
|
141
|
-
date = option;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
resolve(
|
|
145
|
-
`${date.getUTCFullYear()}-${getLeadingZero(
|
|
146
|
-
date.getUTCMonth(),
|
|
147
|
-
1
|
|
148
|
-
)}-${getLeadingZero(date.getUTCDate())}`
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
return reject("Must be a JavaScript Date Object or ISO 8601 Date String");
|
|
152
|
-
});
|
|
153
|
-
},
|
|
154
|
-
isoDate: (option: any): Promise<string> => {
|
|
155
|
-
return new Promise((resolve, reject) => {
|
|
156
|
-
if (typeof option === "string" || option instanceof Date) {
|
|
157
|
-
let date: Date;
|
|
158
|
-
|
|
159
|
-
if (typeof option === "string") {
|
|
160
|
-
const parsed = Date.parse(option);
|
|
161
|
-
if (isNaN(parsed)) {
|
|
162
|
-
return reject("Must be an ISO 8601 Date String");
|
|
163
|
-
}
|
|
164
|
-
date = new Date(parsed);
|
|
165
|
-
} else {
|
|
166
|
-
date = option;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
resolve(date.toISOString().slice(0, 19).concat("Z"));
|
|
170
|
-
}
|
|
171
|
-
return reject("Must be a JavaScript Date Object or ISO 8601 Date String");
|
|
172
|
-
});
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
const optionsMap = {
|
|
177
|
-
companies: {
|
|
178
|
-
page: validators.number,
|
|
179
|
-
id: validators.number,
|
|
180
|
-
name: validators.string,
|
|
181
|
-
country_code: validators.countryCode,
|
|
182
|
-
inactive: validators.boolean,
|
|
183
|
-
},
|
|
184
|
-
launches: {
|
|
185
|
-
page: validators.number,
|
|
186
|
-
id: validators.number,
|
|
187
|
-
cospar_id: validators.cosparId,
|
|
188
|
-
after_date: validators.shortDate,
|
|
189
|
-
before_date: validators.shortDate,
|
|
190
|
-
modified_since: validators.isoDate,
|
|
191
|
-
location_id: validators.number,
|
|
192
|
-
pad_id: validators.number,
|
|
193
|
-
provider_id: validators.number,
|
|
194
|
-
tag_id: validators.number,
|
|
195
|
-
vehicle_id: validators.number,
|
|
196
|
-
state_abbr: validators.stateCode,
|
|
197
|
-
country_code: validators.countryCode,
|
|
198
|
-
search: validators.string,
|
|
199
|
-
slug: validators.string,
|
|
200
|
-
},
|
|
201
|
-
locations: {
|
|
202
|
-
page: validators.number,
|
|
203
|
-
id: validators.number,
|
|
204
|
-
name: validators.string,
|
|
205
|
-
state_abbr: validators.stateCode,
|
|
206
|
-
country_code: validators.countryCode,
|
|
207
|
-
},
|
|
208
|
-
missions: {
|
|
209
|
-
page: validators.number,
|
|
210
|
-
id: validators.number,
|
|
211
|
-
name: validators.string,
|
|
212
|
-
},
|
|
213
|
-
pads: {
|
|
214
|
-
page: validators.number,
|
|
215
|
-
id: validators.number,
|
|
216
|
-
name: validators.string,
|
|
217
|
-
state_abbr: validators.stateCode,
|
|
218
|
-
country_code: validators.countryCode,
|
|
219
|
-
},
|
|
220
|
-
tags: {
|
|
221
|
-
page: validators.number,
|
|
222
|
-
id: validators.number,
|
|
223
|
-
text: validators.string,
|
|
224
|
-
},
|
|
225
|
-
vehicles: {
|
|
226
|
-
page: validators.number,
|
|
227
|
-
id: validators.number,
|
|
228
|
-
name: validators.string,
|
|
229
|
-
},
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
export const queryOptionsValidator = (
|
|
233
|
-
resource: RLLEndPoint,
|
|
234
|
-
options?: RLLQueryConfig.All
|
|
235
|
-
): Promise<URLSearchParams> => {
|
|
236
|
-
const params = new URLSearchParams();
|
|
237
|
-
const paramsPromises = [];
|
|
238
|
-
|
|
239
|
-
if (!options) {
|
|
240
|
-
return Promise.resolve(params);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (
|
|
244
|
-
(options.id || options.slug || options.cospar_id) &&
|
|
245
|
-
Object.keys(options).length > 1
|
|
246
|
-
) {
|
|
247
|
-
warn(
|
|
248
|
-
"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."
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
for (const option in options) {
|
|
253
|
-
if (!optionsMap[resource][option]) {
|
|
254
|
-
warn(
|
|
255
|
-
`Parameter "${option}" is not a valid option for the ${resource} endpoint. It will be ignored.`
|
|
256
|
-
);
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (options[option] === undefined) {
|
|
261
|
-
warn(`Parameter "${option}" is undefined and will be ignored.`);
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const promise = optionsMap[resource][option](options[option])
|
|
266
|
-
.then((o) => params.set(option, o))
|
|
267
|
-
.catch((err) => {
|
|
268
|
-
throw `Malformed query parameter for resource "${resource}" and parameter: "${option}": ${err}.`;
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
paramsPromises.push(promise);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return Promise.all(paramsPromises).then(() => params);
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
export const warn = (msg: string) => console.warn(`[RLL Client]: ${msg}`);
|
|
278
|
-
|
|
279
|
-
export const error = (
|
|
280
|
-
msg: string,
|
|
281
|
-
type: "type" | "range" | "error" = "error"
|
|
282
|
-
) => {
|
|
283
|
-
switch (type) {
|
|
284
|
-
case "error": {
|
|
285
|
-
throw new Error(`[RLL Client]: ${msg}`);
|
|
286
|
-
}
|
|
287
|
-
case "type": {
|
|
288
|
-
throw new TypeError(`[RLL Client]: ${msg}`);
|
|
289
|
-
}
|
|
290
|
-
case "range": {
|
|
291
|
-
throw new RangeError(`[RLL Client]: ${msg}`);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
};
|