rocket-launch-live-client 0.2.1 → 1.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 +197 -5
- package/lib/cjs/Client.js +35 -14
- package/lib/cjs/Watcher.js +175 -0
- package/lib/cjs/fetcher.js +18 -10
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/types/Client.d.ts +19 -7
- package/lib/cjs/types/Client.d.ts.map +1 -1
- package/lib/cjs/types/Watcher.d.ts +81 -0
- package/lib/cjs/types/Watcher.d.ts.map +1 -0
- package/lib/cjs/types/application.js +4 -2
- package/lib/cjs/types/fetcher.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +2 -1
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/types/application.d.ts +38 -15
- package/lib/cjs/types/types/application.d.ts.map +1 -1
- package/lib/cjs/types/utils.d.ts +2 -1
- package/lib/cjs/types/utils.d.ts.map +1 -1
- package/lib/cjs/utils.js +118 -101
- package/lib/esm/Client.js +46 -21
- package/lib/esm/Watcher.js +182 -0
- package/lib/esm/fetcher.js +27 -13
- package/lib/esm/index.mjs +13 -4
- package/lib/esm/types/Client.d.ts +19 -7
- package/lib/esm/types/Client.d.ts.map +1 -1
- package/lib/esm/types/Watcher.d.ts +81 -0
- package/lib/esm/types/Watcher.d.ts.map +1 -0
- package/lib/esm/types/application.js +10 -5
- package/lib/esm/types/fetcher.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +2 -1
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/standards.js +11 -6
- package/lib/esm/types/types/application.d.ts +38 -15
- package/lib/esm/types/types/application.d.ts.map +1 -1
- package/lib/esm/types/utils.d.ts +2 -1
- package/lib/esm/types/utils.d.ts.map +1 -1
- package/lib/esm/utils.js +140 -115
- package/package.json +9 -13
package/lib/esm/Client.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RLLClient = void 0;
|
|
4
|
+
const application_1 = require("./types/application");
|
|
5
|
+
const fetcher_1 = require("./fetcher");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const Watcher_1 = require("./Watcher");
|
|
4
8
|
/**
|
|
5
9
|
* Class representing a RocketLaunch.Live client
|
|
6
10
|
* @class
|
|
7
11
|
*/
|
|
8
|
-
|
|
12
|
+
class RLLClient {
|
|
9
13
|
apiKey;
|
|
10
14
|
config = {
|
|
11
15
|
keyInQueryParams: false,
|
|
@@ -21,12 +25,12 @@ export class RLLClient {
|
|
|
21
25
|
constructor(apiKey, options) {
|
|
22
26
|
// Validate API Key is a valid UUID format
|
|
23
27
|
// Constructor throws if not
|
|
24
|
-
this.apiKey = apiKeyValidator(apiKey);
|
|
28
|
+
this.apiKey = (0, utils_1.apiKeyValidator)(apiKey);
|
|
25
29
|
if (!options) {
|
|
26
30
|
return;
|
|
27
31
|
}
|
|
28
32
|
// Validate Options with warnings or throws
|
|
29
|
-
optionsValidator(options);
|
|
33
|
+
(0, utils_1.optionsValidator)(options);
|
|
30
34
|
if (options.keyInQueryParams) {
|
|
31
35
|
this.config.keyInQueryParams = options.keyInQueryParams;
|
|
32
36
|
}
|
|
@@ -44,7 +48,20 @@ export class RLLClient {
|
|
|
44
48
|
* @returns {Promise<T>}
|
|
45
49
|
*/
|
|
46
50
|
query(endpoint, params) {
|
|
47
|
-
return fetcher(this.apiKey, endpoint, params, this.config.keyInQueryParams);
|
|
51
|
+
return (0, fetcher_1.fetcher)(this.apiKey, endpoint, params, this.config.keyInQueryParams);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Instantiate a new RLL Watcher which will continually query the API for changes to the launches endpoint
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*
|
|
58
|
+
* @param {number} interval - Interval in minutes to query the API for changes. Defaults to 5 minutes, cannot be less than 1 minute
|
|
59
|
+
* @param {RLLQueryConfig.Launches} options - Query options, same as calling the launches method
|
|
60
|
+
*
|
|
61
|
+
* @returns {RLLWatcher}
|
|
62
|
+
*/
|
|
63
|
+
watch(interval, options) {
|
|
64
|
+
return new Watcher_1.RLLWatcher((params) => this.query(application_1.RLLEndPoint.LAUNCHES, params), interval, options);
|
|
48
65
|
}
|
|
49
66
|
/**
|
|
50
67
|
* Fetch launch companies
|
|
@@ -63,10 +80,11 @@ export class RLLClient {
|
|
|
63
80
|
*
|
|
64
81
|
* @example
|
|
65
82
|
*
|
|
66
|
-
* const response = client.companies({ country_code: "US" })
|
|
83
|
+
* const response = await client.companies({ country_code: "US" })
|
|
67
84
|
*/
|
|
68
85
|
companies(options) {
|
|
69
|
-
|
|
86
|
+
const params = (0, utils_1.queryOptionsValidator)(application_1.RLLEndPoint.COMPANIES, options);
|
|
87
|
+
return this.query(application_1.RLLEndPoint.COMPANIES, params);
|
|
70
88
|
}
|
|
71
89
|
/**
|
|
72
90
|
* Fetch launches
|
|
@@ -95,10 +113,11 @@ export class RLLClient {
|
|
|
95
113
|
*
|
|
96
114
|
* @example
|
|
97
115
|
*
|
|
98
|
-
* const response = client.launches({ after_date: new Date("2022-10-10") })
|
|
116
|
+
* const response = await client.launches({ after_date: new Date("2022-10-10") })
|
|
99
117
|
*/
|
|
100
118
|
launches(options) {
|
|
101
|
-
|
|
119
|
+
const params = (0, utils_1.queryOptionsValidator)(application_1.RLLEndPoint.LAUNCHES, options);
|
|
120
|
+
return this.query(application_1.RLLEndPoint.LAUNCHES, params);
|
|
102
121
|
}
|
|
103
122
|
/**
|
|
104
123
|
* Fetch launch locations
|
|
@@ -117,10 +136,11 @@ export class RLLClient {
|
|
|
117
136
|
*
|
|
118
137
|
* @example
|
|
119
138
|
*
|
|
120
|
-
* const response = client.locations({ country_code: "US" })
|
|
139
|
+
* const response = await client.locations({ country_code: "US" })
|
|
121
140
|
*/
|
|
122
141
|
locations(options) {
|
|
123
|
-
|
|
142
|
+
const params = (0, utils_1.queryOptionsValidator)(application_1.RLLEndPoint.LOCATIONS, options);
|
|
143
|
+
return this.query(application_1.RLLEndPoint.LOCATIONS, params);
|
|
124
144
|
}
|
|
125
145
|
/**
|
|
126
146
|
* Fetch launch Missions
|
|
@@ -137,10 +157,11 @@ export class RLLClient {
|
|
|
137
157
|
*
|
|
138
158
|
* @example
|
|
139
159
|
*
|
|
140
|
-
* const response = client.missions({ name: "Mars 2020" })
|
|
160
|
+
* const response = await client.missions({ name: "Mars 2020" })
|
|
141
161
|
*/
|
|
142
162
|
missions(options) {
|
|
143
|
-
|
|
163
|
+
const params = (0, utils_1.queryOptionsValidator)(application_1.RLLEndPoint.MISSIONS, options);
|
|
164
|
+
return this.query(application_1.RLLEndPoint.MISSIONS, params);
|
|
144
165
|
}
|
|
145
166
|
/**
|
|
146
167
|
* Fetch launch pads
|
|
@@ -159,10 +180,11 @@ export class RLLClient {
|
|
|
159
180
|
*
|
|
160
181
|
* @example
|
|
161
182
|
*
|
|
162
|
-
* const response = client.pads({ country_code: "US" })
|
|
183
|
+
* const response = await client.pads({ country_code: "US" })
|
|
163
184
|
*/
|
|
164
185
|
pads(options) {
|
|
165
|
-
|
|
186
|
+
const params = (0, utils_1.queryOptionsValidator)(application_1.RLLEndPoint.PADS, options);
|
|
187
|
+
return this.query(application_1.RLLEndPoint.PADS, params);
|
|
166
188
|
}
|
|
167
189
|
/**
|
|
168
190
|
* Fetch launch tags
|
|
@@ -179,10 +201,11 @@ export class RLLClient {
|
|
|
179
201
|
*
|
|
180
202
|
* @example
|
|
181
203
|
*
|
|
182
|
-
* const response = client.tags({ text: "Crewed" })
|
|
204
|
+
* const response = await client.tags({ text: "Crewed" })
|
|
183
205
|
*/
|
|
184
206
|
tags(options) {
|
|
185
|
-
|
|
207
|
+
const params = (0, utils_1.queryOptionsValidator)(application_1.RLLEndPoint.TAGS, options);
|
|
208
|
+
return this.query(application_1.RLLEndPoint.TAGS, params);
|
|
186
209
|
}
|
|
187
210
|
/**
|
|
188
211
|
* Fetch launch Vehicles
|
|
@@ -199,9 +222,11 @@ export class RLLClient {
|
|
|
199
222
|
*
|
|
200
223
|
* @example
|
|
201
224
|
*
|
|
202
|
-
* const response = client.vehicles({ name: "Falcon 9" })
|
|
225
|
+
* const response = await client.vehicles({ name: "Falcon 9" })
|
|
203
226
|
*/
|
|
204
227
|
vehicles(options) {
|
|
205
|
-
|
|
228
|
+
const params = (0, utils_1.queryOptionsValidator)(application_1.RLLEndPoint.VEHICLES, options);
|
|
229
|
+
return this.query(application_1.RLLEndPoint.VEHICLES, params);
|
|
206
230
|
}
|
|
207
231
|
}
|
|
232
|
+
exports.RLLClient = RLLClient;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RLLWatcher = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
const application_1 = require("./types/application");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const DEFAULT_INTERVAL_IN_MINS = 5;
|
|
11
|
+
const MS_IN_MIN = 60000;
|
|
12
|
+
const intervalValidator = (interval) => {
|
|
13
|
+
if (typeof interval !== "number" && typeof interval !== "string") {
|
|
14
|
+
(0, utils_1.error)("RLLWatcher interval must be a number.");
|
|
15
|
+
return DEFAULT_INTERVAL_IN_MINS;
|
|
16
|
+
}
|
|
17
|
+
if (typeof interval === "string" &&
|
|
18
|
+
(isNaN(Number(interval)) || interval === "")) {
|
|
19
|
+
(0, utils_1.error)("RLLWatcher interval must be a number.", "type");
|
|
20
|
+
return DEFAULT_INTERVAL_IN_MINS;
|
|
21
|
+
}
|
|
22
|
+
const typedInterval = Number(interval);
|
|
23
|
+
if (typedInterval <= 0) {
|
|
24
|
+
(0, utils_1.error)("RLLWatcher interval cannot be a negative number or zero. Watcher intervals should be greater than or equal to 1 minute.");
|
|
25
|
+
return DEFAULT_INTERVAL_IN_MINS;
|
|
26
|
+
}
|
|
27
|
+
if (typedInterval < 1) {
|
|
28
|
+
(0, utils_1.warn)("RLLWatcher does not accept intervals less than 1. Your watcher will default to 5 minute intervals unless corrected.");
|
|
29
|
+
return DEFAULT_INTERVAL_IN_MINS;
|
|
30
|
+
}
|
|
31
|
+
return typedInterval;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Class representing a RocketLaunch.Live Client Watcher
|
|
35
|
+
* @class
|
|
36
|
+
*/
|
|
37
|
+
class RLLWatcher extends events_1.default {
|
|
38
|
+
_untypedOn;
|
|
39
|
+
_untypedEmit;
|
|
40
|
+
last_call;
|
|
41
|
+
launches = new Map();
|
|
42
|
+
interval;
|
|
43
|
+
params;
|
|
44
|
+
timer;
|
|
45
|
+
fetcher;
|
|
46
|
+
/**
|
|
47
|
+
* Create a new RocketLaunch.live Client Watcher
|
|
48
|
+
*
|
|
49
|
+
* @param {function(params: URLSearchParams): Promise<RLLResponse<RLLEntity.Launch[]>>} fetcher - fetcher function to make API calls
|
|
50
|
+
* @param {number | string} [interval] - Optional Client Configuration options
|
|
51
|
+
* @param {Object} [options] - Launch Search Options
|
|
52
|
+
* @param {number | string} options.id - Launch id
|
|
53
|
+
* @param {number | string} options.page - Page number of results
|
|
54
|
+
* @param {string} options.cospar_id - Launch COSPAR ID (ie. 2022-123)
|
|
55
|
+
* @param {Date | string} options.before_date - Only return launches before this date
|
|
56
|
+
* @param {Date | string} options.after_date - Only return launches after this date
|
|
57
|
+
* @param {Date | string} options.modified_since - Only return launches with API changes after this date
|
|
58
|
+
* @param {number | string} options.location_id - Launches from this Location
|
|
59
|
+
* @param {number | string} options.pad_id - Launches from this Pad
|
|
60
|
+
* @param {number | string} options.provider_id - Launches from this Company
|
|
61
|
+
* @param {number | string} options.tag_id - Launches with this Tag
|
|
62
|
+
* @param {number | string} options.vehicle_id - Launches on this Vehicle
|
|
63
|
+
* @param {ISO3166Alpha2.StateCodeUS} options.state_abbr - ISO 3166 Alpha 2 US State Code
|
|
64
|
+
* @param {ISO3166Alpha2.CountryCode} options.country_code - ISO 3166 Alpha 2 Country Code
|
|
65
|
+
* @param {number | string} options.search - Launches matching this search string
|
|
66
|
+
* @param {number | string} options.slug - Launches matching this unique slug
|
|
67
|
+
*
|
|
68
|
+
*/
|
|
69
|
+
constructor(fetcher, interval = DEFAULT_INTERVAL_IN_MINS, options) {
|
|
70
|
+
super();
|
|
71
|
+
// Reassign default Event Emitter methods
|
|
72
|
+
this._untypedOn = this.on;
|
|
73
|
+
this._untypedEmit = this.emit;
|
|
74
|
+
// Methord Overide for type safety
|
|
75
|
+
this.on = (event, listener) => this._untypedOn(event, listener);
|
|
76
|
+
this.emit = (event, ...args) => this._untypedEmit(event, ...args);
|
|
77
|
+
this.last_call = new Date();
|
|
78
|
+
this.fetcher = fetcher;
|
|
79
|
+
this.interval = intervalValidator(interval);
|
|
80
|
+
this.params = (0, utils_1.queryOptionsValidator)(application_1.RLLEndPoint.LAUNCHES, options);
|
|
81
|
+
// ignore any limit params as these cause unnecessary API calls and do not serve the Watcher role
|
|
82
|
+
this.params.delete("limit");
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Recursive API Caller to iterate through pages
|
|
86
|
+
*
|
|
87
|
+
* @private
|
|
88
|
+
* @function
|
|
89
|
+
*
|
|
90
|
+
* @param {URLSearchParams} params - Search parameters
|
|
91
|
+
* @param {function(results: RLLResponse<RLLEntity.Launch[]>)} callback - To execute on each page
|
|
92
|
+
*
|
|
93
|
+
* @returns {Promise<void>}
|
|
94
|
+
*/
|
|
95
|
+
recursivelyFetch = (params, callback) => {
|
|
96
|
+
let page = 1;
|
|
97
|
+
const recursiveFetcher = () => {
|
|
98
|
+
this.emit("call", params);
|
|
99
|
+
return this.fetcher(params).then((results) => {
|
|
100
|
+
callback(results);
|
|
101
|
+
if (results.last_page > page) {
|
|
102
|
+
page++;
|
|
103
|
+
params.set("page", page.toString());
|
|
104
|
+
return recursiveFetcher();
|
|
105
|
+
}
|
|
106
|
+
return;
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
return recursiveFetcher();
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Query wrapper to trigger events
|
|
113
|
+
*
|
|
114
|
+
* @private
|
|
115
|
+
* @function
|
|
116
|
+
*
|
|
117
|
+
* @returns {void}
|
|
118
|
+
*/
|
|
119
|
+
query() {
|
|
120
|
+
const notify = (response) => {
|
|
121
|
+
for (const changedLaunch of response.result) {
|
|
122
|
+
const { id } = changedLaunch;
|
|
123
|
+
const oldLaunch = this.launches.get(id);
|
|
124
|
+
if (oldLaunch) {
|
|
125
|
+
this.emit("change", oldLaunch, changedLaunch);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
this.emit("new", changedLaunch);
|
|
129
|
+
}
|
|
130
|
+
this.launches.set(changedLaunch.id, changedLaunch);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
this.params.set("modified_since", (0, utils_1.formatToRLLISODate)(this.last_call));
|
|
134
|
+
this.recursivelyFetch(new URLSearchParams(this.params), notify)
|
|
135
|
+
.then(() => {
|
|
136
|
+
this.last_call = new Date();
|
|
137
|
+
})
|
|
138
|
+
.catch((err) => {
|
|
139
|
+
this.emit("error", err);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Begin monitoring API using the configured query parameters.
|
|
144
|
+
*
|
|
145
|
+
* @public
|
|
146
|
+
* @function
|
|
147
|
+
*
|
|
148
|
+
* @returns {void}
|
|
149
|
+
*/
|
|
150
|
+
start() {
|
|
151
|
+
const buildCache = (response) => {
|
|
152
|
+
for (const launch of response.result) {
|
|
153
|
+
this.launches.set(launch.id, launch);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
this.recursivelyFetch(new URLSearchParams(this.params), buildCache)
|
|
157
|
+
.then(() => {
|
|
158
|
+
this.emit("ready", this.launches);
|
|
159
|
+
this.last_call = new Date();
|
|
160
|
+
this.timer = setInterval(() => {
|
|
161
|
+
this.query();
|
|
162
|
+
}, this.interval * MS_IN_MIN);
|
|
163
|
+
})
|
|
164
|
+
.catch((err) => {
|
|
165
|
+
this.emit("init_error", err);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Stop monitoring API
|
|
170
|
+
*
|
|
171
|
+
* @public
|
|
172
|
+
* @function
|
|
173
|
+
*
|
|
174
|
+
* @returns {void}
|
|
175
|
+
*/
|
|
176
|
+
stop() {
|
|
177
|
+
if (this.timer) {
|
|
178
|
+
clearInterval(this.timer);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.RLLWatcher = RLLWatcher;
|
package/lib/esm/fetcher.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fetcher = void 0;
|
|
7
|
+
const https_1 = __importDefault(require("https"));
|
|
2
8
|
const BASE_URL = "https://fdo.rocketlaunch.live";
|
|
3
|
-
|
|
9
|
+
const fetcher = (apiKey, endpoint, params, keyInQueryParams) => {
|
|
4
10
|
const url = new URL("json/" + endpoint, BASE_URL);
|
|
5
11
|
let headers;
|
|
6
12
|
if (keyInQueryParams) {
|
|
@@ -12,28 +18,36 @@ export const fetcher = (apiKey, endpoint, params, keyInQueryParams) => {
|
|
|
12
18
|
params.forEach((v, k) => url.searchParams.set(k, v));
|
|
13
19
|
return query(url, headers);
|
|
14
20
|
};
|
|
21
|
+
exports.fetcher = fetcher;
|
|
15
22
|
const query = (url, headers) => {
|
|
16
23
|
return new Promise((resolve, reject) => {
|
|
17
|
-
const req =
|
|
24
|
+
const req = https_1.default.get(url, { headers }, (res) => {
|
|
18
25
|
let data = [];
|
|
19
26
|
res.on("data", (chunk) => data.push(chunk));
|
|
20
27
|
res.on("end", () => {
|
|
28
|
+
const response = Buffer.concat(data).toString();
|
|
21
29
|
if (res.statusCode === 200) {
|
|
22
|
-
const response = Buffer.concat(data).toString();
|
|
23
30
|
resolve(JSON.parse(response));
|
|
24
31
|
}
|
|
25
|
-
else if (res.statusCode === 404) {
|
|
26
|
-
reject({
|
|
27
|
-
error: "Resource not found",
|
|
28
|
-
statusCode: 404,
|
|
29
|
-
message: "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.",
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
32
|
else {
|
|
33
|
-
|
|
33
|
+
const error = {
|
|
34
|
+
error: "API Call Failed",
|
|
35
|
+
statusCode: res.statusCode ?? null,
|
|
36
|
+
message: "RLLC recieved a response from the server but it did not complete as expected.",
|
|
37
|
+
server_response: JSON.parse(response),
|
|
38
|
+
};
|
|
39
|
+
reject(error);
|
|
34
40
|
}
|
|
35
41
|
});
|
|
36
42
|
});
|
|
37
|
-
req.on("error",
|
|
43
|
+
req.on("error", () => {
|
|
44
|
+
const error = {
|
|
45
|
+
error: "Unknown error",
|
|
46
|
+
statusCode: null,
|
|
47
|
+
message: "RLLC recieved an unknown error. This usually means that the HTTP request did not complete",
|
|
48
|
+
server_response: null,
|
|
49
|
+
};
|
|
50
|
+
reject(error);
|
|
51
|
+
});
|
|
38
52
|
});
|
|
39
53
|
};
|
package/lib/esm/index.mjs
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rllc = exports.RLLWatcher = exports.RLLClient = exports.RLLEntity = exports.RLLEndPoint = void 0;
|
|
4
|
+
const Client_1 = require("./Client");
|
|
5
|
+
var application_1 = require("./types/application");
|
|
6
|
+
Object.defineProperty(exports, "RLLEndPoint", { enumerable: true, get: function () { return application_1.RLLEndPoint; } });
|
|
7
|
+
Object.defineProperty(exports, "RLLEntity", { enumerable: true, get: function () { return application_1.RLLEntity; } });
|
|
8
|
+
var Client_2 = require("./Client");
|
|
9
|
+
Object.defineProperty(exports, "RLLClient", { enumerable: true, get: function () { return Client_2.RLLClient; } });
|
|
10
|
+
var Watcher_1 = require("./Watcher");
|
|
11
|
+
Object.defineProperty(exports, "RLLWatcher", { enumerable: true, get: function () { return Watcher_1.RLLWatcher; } });
|
|
4
12
|
/**
|
|
5
13
|
* Generate a RocketLaunch.Live client
|
|
6
14
|
*
|
|
@@ -18,4 +26,5 @@ export { RLLClient } from "./Client";
|
|
|
18
26
|
* const MY_KEY = process.env.ROCKETLAUNCH_LIVE_API_KEY
|
|
19
27
|
* const client = rllc(MY_KEY, { keyInQueryParams: true })
|
|
20
28
|
*/
|
|
21
|
-
|
|
29
|
+
const rllc = (apiKey, options) => new Client_1.RLLClient(apiKey, options);
|
|
30
|
+
exports.rllc = rllc;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RLLClientOptions, RLLEntity, RLLQueryConfig, RLLResponse } from "./types/application";
|
|
2
|
+
import { RLLWatcher } from "./Watcher";
|
|
2
3
|
/**
|
|
3
4
|
* Class representing a RocketLaunch.Live client
|
|
4
5
|
* @class
|
|
@@ -28,6 +29,17 @@ export declare class RLLClient {
|
|
|
28
29
|
* @returns {Promise<T>}
|
|
29
30
|
*/
|
|
30
31
|
private query;
|
|
32
|
+
/**
|
|
33
|
+
* Instantiate a new RLL Watcher which will continually query the API for changes to the launches endpoint
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*
|
|
37
|
+
* @param {number} interval - Interval in minutes to query the API for changes. Defaults to 5 minutes, cannot be less than 1 minute
|
|
38
|
+
* @param {RLLQueryConfig.Launches} options - Query options, same as calling the launches method
|
|
39
|
+
*
|
|
40
|
+
* @returns {RLLWatcher}
|
|
41
|
+
*/
|
|
42
|
+
watch(interval?: number | string, options?: RLLQueryConfig.Launches): RLLWatcher;
|
|
31
43
|
/**
|
|
32
44
|
* Fetch launch companies
|
|
33
45
|
*
|
|
@@ -45,7 +57,7 @@ export declare class RLLClient {
|
|
|
45
57
|
*
|
|
46
58
|
* @example
|
|
47
59
|
*
|
|
48
|
-
* const response = client.companies({ country_code: "US" })
|
|
60
|
+
* const response = await client.companies({ country_code: "US" })
|
|
49
61
|
*/
|
|
50
62
|
companies(options?: RLLQueryConfig.Companies): Promise<RLLResponse<RLLEntity.Company[]>>;
|
|
51
63
|
/**
|
|
@@ -75,7 +87,7 @@ export declare class RLLClient {
|
|
|
75
87
|
*
|
|
76
88
|
* @example
|
|
77
89
|
*
|
|
78
|
-
* const response = client.launches({ after_date: new Date("2022-10-10") })
|
|
90
|
+
* const response = await client.launches({ after_date: new Date("2022-10-10") })
|
|
79
91
|
*/
|
|
80
92
|
launches(options?: RLLQueryConfig.Launches): Promise<RLLResponse<RLLEntity.Launch[]>>;
|
|
81
93
|
/**
|
|
@@ -95,7 +107,7 @@ export declare class RLLClient {
|
|
|
95
107
|
*
|
|
96
108
|
* @example
|
|
97
109
|
*
|
|
98
|
-
* const response = client.locations({ country_code: "US" })
|
|
110
|
+
* const response = await client.locations({ country_code: "US" })
|
|
99
111
|
*/
|
|
100
112
|
locations(options?: RLLQueryConfig.Locations): Promise<RLLResponse<RLLEntity.Location[]>>;
|
|
101
113
|
/**
|
|
@@ -113,7 +125,7 @@ export declare class RLLClient {
|
|
|
113
125
|
*
|
|
114
126
|
* @example
|
|
115
127
|
*
|
|
116
|
-
* const response = client.missions({ name: "Mars 2020" })
|
|
128
|
+
* const response = await client.missions({ name: "Mars 2020" })
|
|
117
129
|
*/
|
|
118
130
|
missions(options?: RLLQueryConfig.Missions): Promise<RLLResponse<RLLEntity.Mission[]>>;
|
|
119
131
|
/**
|
|
@@ -133,7 +145,7 @@ export declare class RLLClient {
|
|
|
133
145
|
*
|
|
134
146
|
* @example
|
|
135
147
|
*
|
|
136
|
-
* const response = client.pads({ country_code: "US" })
|
|
148
|
+
* const response = await client.pads({ country_code: "US" })
|
|
137
149
|
*/
|
|
138
150
|
pads(options?: RLLQueryConfig.Pads): Promise<RLLResponse<RLLEntity.Pad[]>>;
|
|
139
151
|
/**
|
|
@@ -151,7 +163,7 @@ export declare class RLLClient {
|
|
|
151
163
|
*
|
|
152
164
|
* @example
|
|
153
165
|
*
|
|
154
|
-
* const response = client.tags({ text: "Crewed" })
|
|
166
|
+
* const response = await client.tags({ text: "Crewed" })
|
|
155
167
|
*/
|
|
156
168
|
tags(options?: RLLQueryConfig.Tags): Promise<RLLResponse<RLLEntity.Tag[]>>;
|
|
157
169
|
/**
|
|
@@ -169,7 +181,7 @@ export declare class RLLClient {
|
|
|
169
181
|
*
|
|
170
182
|
* @example
|
|
171
183
|
*
|
|
172
|
-
* const response = client.vehicles({ name: "Falcon 9" })
|
|
184
|
+
* const response = await client.vehicles({ name: "Falcon 9" })
|
|
173
185
|
*/
|
|
174
186
|
vehicles(options?: RLLQueryConfig.Vehicles): Promise<RLLResponse<RLLEntity.Vehicle[]>>;
|
|
175
187
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../../src/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAEhB,SAAS,EACT,cAAc,EACd,WAAW,EACZ,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../../src/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAEhB,SAAS,EACT,cAAc,EACd,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAO7B,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAEZ;IAEF;;;;;;;OAOG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB;IAiBtD;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,KAAK;IASb;;;;;;;;;OASG;IACI,KAAK,CACV,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAC1B,OAAO,CAAC,EAAE,cAAc,CAAC,QAAQ,GAChC,UAAU;IAYb;;;;;;;;;;;;;;;;;;OAkBG;IACI,SAAS,CACd,OAAO,CAAC,EAAE,cAAc,CAAC,SAAS,GACjC,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;IAQ5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACI,QAAQ,CACb,OAAO,CAAC,EAAE,cAAc,CAAC,QAAQ,GAChC,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;IAQ3C;;;;;;;;;;;;;;;;;;OAkBG;IACI,SAAS,CACd,OAAO,CAAC,EAAE,cAAc,CAAC,SAAS,GACjC,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;IAQ7C;;;;;;;;;;;;;;;;OAgBG;IACI,QAAQ,CACb,OAAO,CAAC,EAAE,cAAc,CAAC,QAAQ,GAChC,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;IAQ5C;;;;;;;;;;;;;;;;;;OAkBG;IACI,IAAI,CACT,OAAO,CAAC,EAAE,cAAc,CAAC,IAAI,GAC5B,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC;IAKxC;;;;;;;;;;;;;;;;OAgBG;IACI,IAAI,CACT,OAAO,CAAC,EAAE,cAAc,CAAC,IAAI,GAC5B,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC;IAKxC;;;;;;;;;;;;;;;;OAgBG;IACI,QAAQ,CACb,OAAO,CAAC,EAAE,cAAc,CAAC,QAAQ,GAChC,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;CAO7C"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import EventEmitter from "events";
|
|
3
|
+
import { RLLEntity, RLLQueryConfig, RLLResponse } from "./types/application";
|
|
4
|
+
/**
|
|
5
|
+
* Class representing a RocketLaunch.Live Client Watcher
|
|
6
|
+
* @class
|
|
7
|
+
*/
|
|
8
|
+
export declare class RLLWatcher extends EventEmitter {
|
|
9
|
+
private _untypedOn;
|
|
10
|
+
private _untypedEmit;
|
|
11
|
+
private last_call;
|
|
12
|
+
launches: Map<number, RLLEntity.Launch>;
|
|
13
|
+
private interval;
|
|
14
|
+
private params;
|
|
15
|
+
private timer;
|
|
16
|
+
private fetcher;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new RocketLaunch.live Client Watcher
|
|
19
|
+
*
|
|
20
|
+
* @param {function(params: URLSearchParams): Promise<RLLResponse<RLLEntity.Launch[]>>} fetcher - fetcher function to make API calls
|
|
21
|
+
* @param {number | string} [interval] - Optional Client Configuration options
|
|
22
|
+
* @param {Object} [options] - Launch Search Options
|
|
23
|
+
* @param {number | string} options.id - Launch id
|
|
24
|
+
* @param {number | string} options.page - Page number of results
|
|
25
|
+
* @param {string} options.cospar_id - Launch COSPAR ID (ie. 2022-123)
|
|
26
|
+
* @param {Date | string} options.before_date - Only return launches before this date
|
|
27
|
+
* @param {Date | string} options.after_date - Only return launches after this date
|
|
28
|
+
* @param {Date | string} options.modified_since - Only return launches with API changes after this date
|
|
29
|
+
* @param {number | string} options.location_id - Launches from this Location
|
|
30
|
+
* @param {number | string} options.pad_id - Launches from this Pad
|
|
31
|
+
* @param {number | string} options.provider_id - Launches from this Company
|
|
32
|
+
* @param {number | string} options.tag_id - Launches with this Tag
|
|
33
|
+
* @param {number | string} options.vehicle_id - Launches on this Vehicle
|
|
34
|
+
* @param {ISO3166Alpha2.StateCodeUS} options.state_abbr - ISO 3166 Alpha 2 US State Code
|
|
35
|
+
* @param {ISO3166Alpha2.CountryCode} options.country_code - ISO 3166 Alpha 2 Country Code
|
|
36
|
+
* @param {number | string} options.search - Launches matching this search string
|
|
37
|
+
* @param {number | string} options.slug - Launches matching this unique slug
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
constructor(fetcher: (params: URLSearchParams) => Promise<RLLResponse<RLLEntity.Launch[]>>, interval?: number | string, options?: RLLQueryConfig.Launches);
|
|
41
|
+
/**
|
|
42
|
+
* Recursive API Caller to iterate through pages
|
|
43
|
+
*
|
|
44
|
+
* @private
|
|
45
|
+
* @function
|
|
46
|
+
*
|
|
47
|
+
* @param {URLSearchParams} params - Search parameters
|
|
48
|
+
* @param {function(results: RLLResponse<RLLEntity.Launch[]>)} callback - To execute on each page
|
|
49
|
+
*
|
|
50
|
+
* @returns {Promise<void>}
|
|
51
|
+
*/
|
|
52
|
+
private recursivelyFetch;
|
|
53
|
+
/**
|
|
54
|
+
* Query wrapper to trigger events
|
|
55
|
+
*
|
|
56
|
+
* @private
|
|
57
|
+
* @function
|
|
58
|
+
*
|
|
59
|
+
* @returns {void}
|
|
60
|
+
*/
|
|
61
|
+
private query;
|
|
62
|
+
/**
|
|
63
|
+
* Begin monitoring API using the configured query parameters.
|
|
64
|
+
*
|
|
65
|
+
* @public
|
|
66
|
+
* @function
|
|
67
|
+
*
|
|
68
|
+
* @returns {void}
|
|
69
|
+
*/
|
|
70
|
+
start(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Stop monitoring API
|
|
73
|
+
*
|
|
74
|
+
* @public
|
|
75
|
+
* @function
|
|
76
|
+
*
|
|
77
|
+
* @returns {void}
|
|
78
|
+
*/
|
|
79
|
+
stop(): void;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=Watcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Watcher.d.ts","sourceRoot":"","sources":["../../../src/Watcher.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,EAEL,SAAS,EAET,cAAc,EAEd,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAqD7B;;;GAGG;AACH,qBAAa,UAAW,SAAQ,YAAY;IAC1C,OAAO,CAAC,UAAU,CAGR;IACV,OAAO,CAAC,YAAY,CAA0D;IAC9E,OAAO,CAAC,SAAS,CAAO;IACjB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAa;IAC3D,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,OAAO,CAE+B;IAE9C;;;;;;;;;;;;;;;;;;;;;;OAsBG;gBAED,OAAO,EAAE,CACP,MAAM,EAAE,eAAe,KACpB,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,EAC7C,QAAQ,GAAE,MAAM,GAAG,MAAiC,EACpD,OAAO,CAAC,EAAE,cAAc,CAAC,QAAQ;IA4BnC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,gBAAgB,CAsBtB;IAEF;;;;;;;OAOG;IACH,OAAO,CAAC,KAAK;IAyBb;;;;;;;OAOG;IACI,KAAK,IAAI,IAAI;IAoBpB;;;;;;;OAOG;IACI,IAAI,IAAI,IAAI;CAKpB"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RLLQueryParams = exports.RLLEntity = exports.RLLEndPoint = void 0;
|
|
4
|
+
var RLLEndPoint;
|
|
2
5
|
(function (RLLEndPoint) {
|
|
3
6
|
RLLEndPoint["COMPANIES"] = "companies";
|
|
4
7
|
RLLEndPoint["LAUNCHES"] = "launches";
|
|
@@ -7,8 +10,8 @@ export var RLLEndPoint;
|
|
|
7
10
|
RLLEndPoint["PADS"] = "pads";
|
|
8
11
|
RLLEndPoint["TAGS"] = "tags";
|
|
9
12
|
RLLEndPoint["VEHICLES"] = "vehicles";
|
|
10
|
-
})(RLLEndPoint || (RLLEndPoint = {}));
|
|
11
|
-
|
|
13
|
+
})(RLLEndPoint || (exports.RLLEndPoint = RLLEndPoint = {}));
|
|
14
|
+
var RLLEntity;
|
|
12
15
|
(function (RLLEntity) {
|
|
13
16
|
let LaunchResult;
|
|
14
17
|
(function (LaunchResult) {
|
|
@@ -18,8 +21,8 @@ export var RLLEntity;
|
|
|
18
21
|
LaunchResult[LaunchResult["PARTIAL_FAILURE"] = 2] = "PARTIAL_FAILURE";
|
|
19
22
|
LaunchResult[LaunchResult["IN_FLIGHT_ABORT_CREWED"] = 3] = "IN_FLIGHT_ABORT_CREWED";
|
|
20
23
|
})(LaunchResult = RLLEntity.LaunchResult || (RLLEntity.LaunchResult = {}));
|
|
21
|
-
})(RLLEntity || (RLLEntity = {}));
|
|
22
|
-
|
|
24
|
+
})(RLLEntity || (exports.RLLEntity = RLLEntity = {}));
|
|
25
|
+
exports.RLLQueryParams = {
|
|
23
26
|
id: true,
|
|
24
27
|
page: true,
|
|
25
28
|
name: true,
|
|
@@ -38,4 +41,6 @@ export const RLLQueryParams = {
|
|
|
38
41
|
search: true,
|
|
39
42
|
slug: true,
|
|
40
43
|
text: true,
|
|
44
|
+
limit: true,
|
|
45
|
+
direction: true,
|
|
41
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../src/fetcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../src/fetcher.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,OAAO,cACV,MAAM,YACJ,MAAM,UACR,eAAe,oBACL,OAAO,eAc1B,CAAC"}
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { RLLClient } from "./Client";
|
|
2
2
|
import { RLLClientOptions } from "./types/application";
|
|
3
|
-
export { RLLEndPoint, RLLResponse, RLLClientOptions, RLLQueryConfig, RLLEntity, } from "./types/application";
|
|
3
|
+
export { RLLEndPoint, RLLResponse, RLLClientOptions, RLLQueryConfig, RLLEntity, RLLError, } from "./types/application";
|
|
4
4
|
export { ISO3166Alpha2 } from "./types/standards";
|
|
5
5
|
export { RLLClient } from "./Client";
|
|
6
|
+
export { RLLWatcher } from "./Watcher";
|
|
6
7
|
/**
|
|
7
8
|
* Generate a RocketLaunch.Live client
|
|
8
9
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EACL,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EACL,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,QAAQ,GACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,IAAI,WAAY,MAAM,YAAY,gBAAgB,KAAG,SAClC,CAAC"}
|