rocket-launch-live-client 0.2.0 → 0.3.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/lib/esm/Client.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { RLLEndPoint, } from "./types/application";
2
2
  import { fetcher } from "./fetcher";
3
3
  import { apiKeyValidator, optionsValidator, queryOptionsValidator, } from "./utils";
4
+ import { RLLWatcher } from "./Watcher";
4
5
  /**
5
6
  * Class representing a RocketLaunch.Live client
6
7
  * @class
@@ -21,8 +22,7 @@ export class RLLClient {
21
22
  constructor(apiKey, options) {
22
23
  // Validate API Key is a valid UUID format
23
24
  // Constructor throws if not
24
- apiKeyValidator(apiKey);
25
- this.apiKey = apiKey;
25
+ this.apiKey = apiKeyValidator(apiKey);
26
26
  if (!options) {
27
27
  return;
28
28
  }
@@ -47,6 +47,19 @@ export class RLLClient {
47
47
  query(endpoint, params) {
48
48
  return fetcher(this.apiKey, endpoint, params, this.config.keyInQueryParams);
49
49
  }
50
+ /**
51
+ * Instantiate a new RLL Watcher which will continually query the API for changes to the launches endpoint
52
+ *
53
+ * @public
54
+ *
55
+ * @param {number} interval - Interval in minutes to query the API for changes. Defaults to 5 minutes, cannot be less than 1 minute
56
+ * @param {RLLQueryConfig.Launches} options - Query options, same as calling the launches method
57
+ *
58
+ * @returns {RLLWatcher}
59
+ */
60
+ watch(interval, options) {
61
+ return new RLLWatcher((params) => this.query(RLLEndPoint.LAUNCHES, params), interval, options);
62
+ }
50
63
  /**
51
64
  * Fetch launch companies
52
65
  *
@@ -64,10 +77,11 @@ export class RLLClient {
64
77
  *
65
78
  * @example
66
79
  *
67
- * const response = client.companies({ country_code: "US" })
80
+ * const response = await client.companies({ country_code: "US" })
68
81
  */
69
82
  companies(options) {
70
- return queryOptionsValidator(RLLEndPoint.COMPANIES, options).then((params) => this.query(RLLEndPoint.COMPANIES, params));
83
+ const params = queryOptionsValidator(RLLEndPoint.COMPANIES, options);
84
+ return this.query(RLLEndPoint.COMPANIES, params);
71
85
  }
72
86
  /**
73
87
  * Fetch launches
@@ -96,10 +110,11 @@ export class RLLClient {
96
110
  *
97
111
  * @example
98
112
  *
99
- * const response = client.launches({ after_date: new Date("2022-10-10") })
113
+ * const response = await client.launches({ after_date: new Date("2022-10-10") })
100
114
  */
101
115
  launches(options) {
102
- return queryOptionsValidator(RLLEndPoint.LAUNCHES, options).then((params) => this.query(RLLEndPoint.LAUNCHES, params));
116
+ const params = queryOptionsValidator(RLLEndPoint.LAUNCHES, options);
117
+ return this.query(RLLEndPoint.LAUNCHES, params);
103
118
  }
104
119
  /**
105
120
  * Fetch launch locations
@@ -118,10 +133,11 @@ export class RLLClient {
118
133
  *
119
134
  * @example
120
135
  *
121
- * const response = client.locations({ country_code: "US" })
136
+ * const response = await client.locations({ country_code: "US" })
122
137
  */
123
138
  locations(options) {
124
- return queryOptionsValidator(RLLEndPoint.LOCATIONS, options).then((params) => this.query(RLLEndPoint.LOCATIONS, params));
139
+ const params = queryOptionsValidator(RLLEndPoint.LOCATIONS, options);
140
+ return this.query(RLLEndPoint.LOCATIONS, params);
125
141
  }
126
142
  /**
127
143
  * Fetch launch Missions
@@ -138,10 +154,11 @@ export class RLLClient {
138
154
  *
139
155
  * @example
140
156
  *
141
- * const response = client.missions({ name: "Mars 2020" })
157
+ * const response = await client.missions({ name: "Mars 2020" })
142
158
  */
143
159
  missions(options) {
144
- return queryOptionsValidator(RLLEndPoint.MISSIONS, options).then((params) => this.query(RLLEndPoint.MISSIONS, params));
160
+ const params = queryOptionsValidator(RLLEndPoint.MISSIONS, options);
161
+ return this.query(RLLEndPoint.MISSIONS, params);
145
162
  }
146
163
  /**
147
164
  * Fetch launch pads
@@ -160,10 +177,11 @@ export class RLLClient {
160
177
  *
161
178
  * @example
162
179
  *
163
- * const response = client.pads({ country_code: "US" })
180
+ * const response = await client.pads({ country_code: "US" })
164
181
  */
165
182
  pads(options) {
166
- return queryOptionsValidator(RLLEndPoint.PADS, options).then((params) => this.query(RLLEndPoint.PADS, params));
183
+ const params = queryOptionsValidator(RLLEndPoint.PADS, options);
184
+ return this.query(RLLEndPoint.PADS, params);
167
185
  }
168
186
  /**
169
187
  * Fetch launch tags
@@ -180,10 +198,11 @@ export class RLLClient {
180
198
  *
181
199
  * @example
182
200
  *
183
- * const response = client.tags({ text: "Crewed" })
201
+ * const response = await client.tags({ text: "Crewed" })
184
202
  */
185
203
  tags(options) {
186
- return queryOptionsValidator(RLLEndPoint.TAGS, options).then((params) => this.query(RLLEndPoint.TAGS, params));
204
+ const params = queryOptionsValidator(RLLEndPoint.TAGS, options);
205
+ return this.query(RLLEndPoint.TAGS, params);
187
206
  }
188
207
  /**
189
208
  * Fetch launch Vehicles
@@ -200,9 +219,10 @@ export class RLLClient {
200
219
  *
201
220
  * @example
202
221
  *
203
- * const response = client.vehicles({ name: "Falcon 9" })
222
+ * const response = await client.vehicles({ name: "Falcon 9" })
204
223
  */
205
224
  vehicles(options) {
206
- return queryOptionsValidator(RLLEndPoint.VEHICLES, options).then((params) => this.query(RLLEndPoint.VEHICLES, params));
225
+ const params = queryOptionsValidator(RLLEndPoint.VEHICLES, options);
226
+ return this.query(RLLEndPoint.VEHICLES, params);
207
227
  }
208
228
  }
@@ -0,0 +1,169 @@
1
+ import EventEmitter from "events";
2
+ import { RLLEndPoint, } from "./types/application";
3
+ import { error, warn, queryOptionsValidator, formatToRLLISODate, } from "./utils";
4
+ const DEFAULT_INTERVAL_IN_MINS = 5;
5
+ const MS_IN_MIN = 60000;
6
+ const intervalValidator = (interval) => {
7
+ if (typeof interval !== "number" && typeof interval !== "string") {
8
+ error("RLLWatcher interval must be a number.");
9
+ return DEFAULT_INTERVAL_IN_MINS;
10
+ }
11
+ if (typeof interval === "string" &&
12
+ (isNaN(Number(interval)) || interval === "")) {
13
+ error("RLLWatcher interval must be a number.", "type");
14
+ return DEFAULT_INTERVAL_IN_MINS;
15
+ }
16
+ const typedInterval = Number(interval);
17
+ if (typedInterval <= 0) {
18
+ error("RLLWatcher interval cannot be a negative number or zero. Watcher intervals should be greater than or equal to 1 minute.");
19
+ return DEFAULT_INTERVAL_IN_MINS;
20
+ }
21
+ if (typedInterval < 1) {
22
+ warn("RLLWatcher does not accept intervals less than 1. Your watcher will default to 5 minute intervals unless corrected.");
23
+ return DEFAULT_INTERVAL_IN_MINS;
24
+ }
25
+ return typedInterval;
26
+ };
27
+ /**
28
+ * Class representing a RocketLaunch.Live Client Watcher
29
+ * @class
30
+ */
31
+ export class RLLWatcher extends EventEmitter {
32
+ _untypedOn = this.on;
33
+ _untypedEmit = this.emit;
34
+ on = (event, listener) => this._untypedOn(event, listener);
35
+ emit = (event, ...args) => this._untypedEmit(event, ...args);
36
+ last_call;
37
+ launches = new Map();
38
+ interval;
39
+ params;
40
+ timer;
41
+ fetcher;
42
+ /**
43
+ * Create a new RocketLaunch.live Client Watcher
44
+ *
45
+ * @param {function(params: URLSearchParams): Promise<RLLResponse<RLLEntity.Launch[]>>} fetcher - fetcher function to make API calls
46
+ * @param {number | string} [interval] - Optional Client Configuration options
47
+ * @param {Object} [options] - Launch Search Options
48
+ * @param {number | string} options.id - Launch id
49
+ * @param {number | string} options.page - Page number of results
50
+ * @param {string} options.cospar_id - Launch COSPAR ID (ie. 2022-123)
51
+ * @param {Date | string} options.before_date - Only return launches before this date
52
+ * @param {Date | string} options.after_date - Only return launches after this date
53
+ * @param {Date | string} options.modified_since - Only return launches with API changes after this date
54
+ * @param {number | string} options.location_id - Launches from this Location
55
+ * @param {number | string} options.pad_id - Launches from this Pad
56
+ * @param {number | string} options.provider_id - Launches from this Company
57
+ * @param {number | string} options.tag_id - Launches with this Tag
58
+ * @param {number | string} options.vehicle_id - Launches on this Vehicle
59
+ * @param {ISO3166Alpha2.StateCodeUS} options.state_abbr - ISO 3166 Alpha 2 US State Code
60
+ * @param {ISO3166Alpha2.CountryCode} options.country_code - ISO 3166 Alpha 2 Country Code
61
+ * @param {number | string} options.search - Launches matching this search string
62
+ * @param {number | string} options.slug - Launches matching this unique slug
63
+ *
64
+ */
65
+ constructor(fetcher, interval = DEFAULT_INTERVAL_IN_MINS, options) {
66
+ super();
67
+ this.last_call = new Date();
68
+ this.fetcher = fetcher;
69
+ this.interval = intervalValidator(interval);
70
+ this.params = queryOptionsValidator(RLLEndPoint.LAUNCHES, options);
71
+ }
72
+ /**
73
+ * Recursive API Caller to iterate through pages
74
+ *
75
+ * @private
76
+ * @function
77
+ *
78
+ * @param {URLSearchParams} params - Search parameters
79
+ * @param {function(results: RLLResponse<RLLEntity.Launch[]>)} callback - To execute on each page
80
+ *
81
+ * @returns {Promise<void>}
82
+ */
83
+ recursivelyFetch = (params, callback) => {
84
+ let page = 1;
85
+ const recursiveFetcher = () => {
86
+ this.emit("call", params);
87
+ return this.fetcher(params).then((results) => {
88
+ callback(results);
89
+ if (results.last_page > page) {
90
+ page++;
91
+ params.set("page", page.toString());
92
+ return recursiveFetcher();
93
+ }
94
+ return;
95
+ });
96
+ };
97
+ return recursiveFetcher();
98
+ };
99
+ /**
100
+ * Query wrapper to trigger events
101
+ *
102
+ * @private
103
+ * @function
104
+ *
105
+ * @returns {void}
106
+ */
107
+ query() {
108
+ const notify = (response) => {
109
+ for (const changedLaunch of response.result) {
110
+ const { id } = changedLaunch;
111
+ const oldLaunch = this.launches.get(id);
112
+ if (oldLaunch) {
113
+ this.emit("change", oldLaunch, changedLaunch);
114
+ }
115
+ else {
116
+ this.emit("new", changedLaunch);
117
+ }
118
+ this.launches.set(changedLaunch.id, changedLaunch);
119
+ }
120
+ };
121
+ this.params.set("modified_since", formatToRLLISODate(this.last_call));
122
+ this.recursivelyFetch(new URLSearchParams(this.params), notify)
123
+ .then(() => {
124
+ this.last_call = new Date();
125
+ })
126
+ .catch((err) => {
127
+ this.emit("error", err);
128
+ });
129
+ }
130
+ /**
131
+ * Begin monitoring API using the configured query parameters.
132
+ *
133
+ * @public
134
+ * @function
135
+ *
136
+ * @returns {void}
137
+ */
138
+ start() {
139
+ const buildCache = (response) => {
140
+ for (const launch of response.result) {
141
+ this.launches.set(launch.id, launch);
142
+ }
143
+ };
144
+ this.recursivelyFetch(new URLSearchParams(this.params), buildCache)
145
+ .then(() => {
146
+ this.emit("ready", this.launches);
147
+ this.last_call = new Date();
148
+ this.timer = setInterval(() => {
149
+ this.query();
150
+ }, this.interval * MS_IN_MIN);
151
+ })
152
+ .catch((err) => {
153
+ this.emit("init_error", err);
154
+ });
155
+ }
156
+ /**
157
+ * Stop monitoring API
158
+ *
159
+ * @public
160
+ * @function
161
+ *
162
+ * @returns {void}
163
+ */
164
+ stop() {
165
+ if (this.timer) {
166
+ clearInterval(this.timer);
167
+ }
168
+ }
169
+ }
@@ -18,22 +18,29 @@ const query = (url, headers) => {
18
18
  let data = [];
19
19
  res.on("data", (chunk) => data.push(chunk));
20
20
  res.on("end", () => {
21
+ const response = Buffer.concat(data).toString();
21
22
  if (res.statusCode === 200) {
22
- const response = Buffer.concat(data).toString();
23
23
  resolve(JSON.parse(response));
24
24
  }
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
25
  else {
33
- reject(res);
26
+ const error = {
27
+ error: "API Call Failed",
28
+ statusCode: res.statusCode ?? null,
29
+ message: "RLLC recieved a response from the server but it did not complete as expected.",
30
+ server_response: JSON.parse(response),
31
+ };
32
+ reject(error);
34
33
  }
35
34
  });
36
35
  });
37
- req.on("error", reject);
36
+ req.on("error", () => {
37
+ const error = {
38
+ error: "Unknown error",
39
+ statusCode: null,
40
+ message: "RLLC recieved an unknown error. This usually means that the HTTP request did not complete",
41
+ server_response: null,
42
+ };
43
+ reject(error);
44
+ });
38
45
  });
39
46
  };
package/lib/esm/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { RLLClient } from "./Client";
2
2
  export { RLLEndPoint, RLLEntity, } from "./types/application";
3
3
  export { RLLClient } from "./Client";
4
+ export { RLLWatcher } from "./Watcher";
4
5
  /**
5
6
  * Generate a RocketLaunch.Live client
6
7
  *
@@ -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;AAQ7B;;;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;IAkBtD;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,KAAK;IASb;;;;;;;;;;;;;;;;;;OAkBG;IACI,SAAS,CAC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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,92 @@
1
+ /// <reference types="node" />
2
+ import EventEmitter from "events";
3
+ import { RLLEntity, RLLError, RLLQueryConfig, RLLResponse } from "./types/application";
4
+ interface IRLLWatcherEvent {
5
+ new: (launch: RLLEntity.Launch) => void;
6
+ change: (oldLaunch: RLLEntity.Launch, newLaunch: RLLEntity.Launch) => void;
7
+ error: (error: RLLError) => void;
8
+ ready: (launches: Map<number, RLLEntity.Launch>) => void;
9
+ init_error: (error: RLLError) => void;
10
+ call: (params: URLSearchParams) => void;
11
+ }
12
+ /**
13
+ * Class representing a RocketLaunch.Live Client Watcher
14
+ * @class
15
+ */
16
+ export declare class RLLWatcher extends EventEmitter {
17
+ private _untypedOn;
18
+ private _untypedEmit;
19
+ on: <K extends keyof IRLLWatcherEvent>(event: K, listener: IRLLWatcherEvent[K]) => this;
20
+ emit: <K extends keyof IRLLWatcherEvent>(event: K, ...args: Parameters<IRLLWatcherEvent[K]>) => boolean;
21
+ private last_call;
22
+ launches: Map<number, RLLEntity.Launch>;
23
+ private interval;
24
+ private params;
25
+ private timer;
26
+ private fetcher;
27
+ /**
28
+ * Create a new RocketLaunch.live Client Watcher
29
+ *
30
+ * @param {function(params: URLSearchParams): Promise<RLLResponse<RLLEntity.Launch[]>>} fetcher - fetcher function to make API calls
31
+ * @param {number | string} [interval] - Optional Client Configuration options
32
+ * @param {Object} [options] - Launch Search Options
33
+ * @param {number | string} options.id - Launch id
34
+ * @param {number | string} options.page - Page number of results
35
+ * @param {string} options.cospar_id - Launch COSPAR ID (ie. 2022-123)
36
+ * @param {Date | string} options.before_date - Only return launches before this date
37
+ * @param {Date | string} options.after_date - Only return launches after this date
38
+ * @param {Date | string} options.modified_since - Only return launches with API changes after this date
39
+ * @param {number | string} options.location_id - Launches from this Location
40
+ * @param {number | string} options.pad_id - Launches from this Pad
41
+ * @param {number | string} options.provider_id - Launches from this Company
42
+ * @param {number | string} options.tag_id - Launches with this Tag
43
+ * @param {number | string} options.vehicle_id - Launches on this Vehicle
44
+ * @param {ISO3166Alpha2.StateCodeUS} options.state_abbr - ISO 3166 Alpha 2 US State Code
45
+ * @param {ISO3166Alpha2.CountryCode} options.country_code - ISO 3166 Alpha 2 Country Code
46
+ * @param {number | string} options.search - Launches matching this search string
47
+ * @param {number | string} options.slug - Launches matching this unique slug
48
+ *
49
+ */
50
+ constructor(fetcher: (params: URLSearchParams) => Promise<RLLResponse<RLLEntity.Launch[]>>, interval?: number | string, options?: RLLQueryConfig.Launches);
51
+ /**
52
+ * Recursive API Caller to iterate through pages
53
+ *
54
+ * @private
55
+ * @function
56
+ *
57
+ * @param {URLSearchParams} params - Search parameters
58
+ * @param {function(results: RLLResponse<RLLEntity.Launch[]>)} callback - To execute on each page
59
+ *
60
+ * @returns {Promise<void>}
61
+ */
62
+ private recursivelyFetch;
63
+ /**
64
+ * Query wrapper to trigger events
65
+ *
66
+ * @private
67
+ * @function
68
+ *
69
+ * @returns {void}
70
+ */
71
+ private query;
72
+ /**
73
+ * Begin monitoring API using the configured query parameters.
74
+ *
75
+ * @public
76
+ * @function
77
+ *
78
+ * @returns {void}
79
+ */
80
+ start(): void;
81
+ /**
82
+ * Stop monitoring API
83
+ *
84
+ * @public
85
+ * @function
86
+ *
87
+ * @returns {void}
88
+ */
89
+ stop(): void;
90
+ }
91
+ export {};
92
+ //# 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,EAC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AgB,CAsBtB;IAEF;;;;;;;OAOG;IACH,OAAO,CAAC,KAAK;IAyBb;;;;;;;OAOG;IACI,KAAK,IAAI,IAAI;IAoBpB;;;;;;;OAOG;IACI,IAAI,IAAI,IAAI;CAKpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../src/fetcher.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,OAAO,cACV,MAAM,YACJ,MAAM,UACR,eAAe,oBACL,OAAO,eAc1B,CAAC"}
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"}
@@ -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,GACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,IAAI,WAAY,MAAM,YAAY,gBAAgB,KAAG,SAClC,CAAC"}
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"}
@@ -14,13 +14,14 @@ export declare namespace RLLEntity {
14
14
  }
15
15
  export interface Country {
16
16
  name: string;
17
- code: ISO3166Alpha2.CountryCode;
17
+ code: ISO3166Alpha2.CountryCode | "";
18
18
  }
19
19
  export interface State {
20
20
  name: string;
21
- abbr: ISO3166Alpha2.StateCodeUS;
21
+ abbr?: ISO3166Alpha2.StateCodeUS;
22
22
  }
23
23
  export interface Company extends RLLRecord {
24
+ name: string;
24
25
  country: Country;
25
26
  inactive: boolean | null;
26
27
  }
@@ -40,12 +41,23 @@ export declare namespace RLLEntity {
40
41
  }
41
42
  export interface Launch extends RLLRecord {
42
43
  name: string;
43
- cospar_id: string;
44
+ cospar_id: string | null;
44
45
  sort_date: string;
45
- provider: Omit<Company, "inactive" | "country">;
46
- vehicle: Omit<Vehicle, "company_id" | "company">;
47
- pad: Omit<Pad, "full_name">;
48
- missions: Omit<Mission, "launch_id">[];
46
+ provider: {
47
+ slug: string;
48
+ } & Omit<Company, "inactive" | "country">;
49
+ vehicle: {
50
+ company_id: number;
51
+ slug: string;
52
+ } & Omit<Vehicle, "company">;
53
+ pad: Omit<Pad, "full_name" | "location"> & {
54
+ location: Omit<Location, "pads" | "utc_offset" | "latitute" | "latitude" | "longitude" | "country" | "state"> & {
55
+ slug: string;
56
+ country: string;
57
+ state: ISO3166Alpha2.StateCodeUS | null;
58
+ };
59
+ };
60
+ missions: Omit<Mission, "launch_id" | "company">[];
49
61
  mission_description: string | null;
50
62
  launch_description: string;
51
63
  win_open: string | null;
@@ -61,6 +73,8 @@ export declare namespace RLLEntity {
61
73
  tags: Omit<Tag, "slug">[];
62
74
  slug: string;
63
75
  weather_summary: string | null;
76
+ weather_condition: string | null;
77
+ weather_wind_mph: number | null;
64
78
  weather_temp: number | null;
65
79
  weather_icon: string | null;
66
80
  weather_updated: string | null;
@@ -77,20 +91,20 @@ export declare namespace RLLEntity {
77
91
  longitude: string;
78
92
  state: State | null;
79
93
  statename?: string | null;
80
- country: Country;
81
- pads: Omit<Pad, "location" | "country" | "state">[];
82
- utc_offset: number;
94
+ country: Country | null;
95
+ pads: Omit<Pad, "full_name" | "location" | "country" | "state">[];
96
+ utc_offset: number | null;
83
97
  }
84
98
  export interface Mission extends RLLRecord {
85
99
  name: string;
86
100
  description: string | null;
87
101
  launch_id: number;
88
- company: Omit<Company, "slug" | "inactive" | "country">;
102
+ company: Omit<Company, "inactive" | "country">;
89
103
  }
90
104
  export interface Pad extends RLLRecord {
91
105
  name: string;
92
106
  full_name: string;
93
- location: Omit<Location, "pads" | "utc_offset" | "latitute">;
107
+ location: Omit<Location, "pads" | "utc_offset" | "latitute" | "statename">;
94
108
  }
95
109
  export interface Tag extends RLLRecord {
96
110
  text: string;
@@ -98,8 +112,7 @@ export declare namespace RLLEntity {
98
112
  }
99
113
  export interface Vehicle extends RLLRecord {
100
114
  name: string;
101
- company_id?: number;
102
- company: Omit<Company, "slug" | "inactive" | "country">;
115
+ company: Omit<Company, "inactive" | "country">;
103
116
  }
104
117
  export {};
105
118
  }
@@ -181,4 +194,10 @@ export type RLLResponse<T> = {
181
194
  last_page: number;
182
195
  result: T;
183
196
  };
197
+ export type RLLError = {
198
+ error: string;
199
+ statusCode: number | null;
200
+ message: string;
201
+ server_response: string | null;
202
+ };
184
203
  //# sourceMappingURL=application.d.ts.map