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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../../src/Client.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ChC,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"}
|
|
@@ -10,7 +10,7 @@ var RLLEndPoint;
|
|
|
10
10
|
RLLEndPoint["PADS"] = "pads";
|
|
11
11
|
RLLEndPoint["TAGS"] = "tags";
|
|
12
12
|
RLLEndPoint["VEHICLES"] = "vehicles";
|
|
13
|
-
})(RLLEndPoint
|
|
13
|
+
})(RLLEndPoint || (exports.RLLEndPoint = RLLEndPoint = {}));
|
|
14
14
|
var RLLEntity;
|
|
15
15
|
(function (RLLEntity) {
|
|
16
16
|
let LaunchResult;
|
|
@@ -21,7 +21,7 @@ var RLLEntity;
|
|
|
21
21
|
LaunchResult[LaunchResult["PARTIAL_FAILURE"] = 2] = "PARTIAL_FAILURE";
|
|
22
22
|
LaunchResult[LaunchResult["IN_FLIGHT_ABORT_CREWED"] = 3] = "IN_FLIGHT_ABORT_CREWED";
|
|
23
23
|
})(LaunchResult = RLLEntity.LaunchResult || (RLLEntity.LaunchResult = {}));
|
|
24
|
-
})(RLLEntity
|
|
24
|
+
})(RLLEntity || (exports.RLLEntity = RLLEntity = {}));
|
|
25
25
|
exports.RLLQueryParams = {
|
|
26
26
|
id: true,
|
|
27
27
|
page: true,
|
|
@@ -41,4 +41,6 @@ exports.RLLQueryParams = {
|
|
|
41
41
|
search: true,
|
|
42
42
|
slug: true,
|
|
43
43
|
text: true,
|
|
44
|
+
limit: true,
|
|
45
|
+
direction: true,
|
|
44
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/cjs/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"}
|
|
@@ -14,15 +14,16 @@ 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
|
|
21
|
+
abbr?: ISO3166Alpha2.StateCodeUS;
|
|
22
22
|
}
|
|
23
23
|
export interface Company extends RLLRecord {
|
|
24
|
+
name: string;
|
|
24
25
|
country: Country;
|
|
25
|
-
inactive: boolean
|
|
26
|
+
inactive: boolean;
|
|
26
27
|
}
|
|
27
28
|
export enum LaunchResult {
|
|
28
29
|
NOT_SET = -1,
|
|
@@ -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:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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, "
|
|
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
|
-
|
|
102
|
-
company: Omit<Company, "slug" | "inactive" | "country">;
|
|
115
|
+
company: Omit<Company, "inactive" | "country">;
|
|
103
116
|
}
|
|
104
117
|
export {};
|
|
105
118
|
}
|
|
@@ -122,6 +135,8 @@ export declare const RLLQueryParams: {
|
|
|
122
135
|
search: boolean;
|
|
123
136
|
slug: boolean;
|
|
124
137
|
text: boolean;
|
|
138
|
+
limit: boolean;
|
|
139
|
+
direction: boolean;
|
|
125
140
|
};
|
|
126
141
|
export declare namespace RLLQueryConfig {
|
|
127
142
|
interface Base {
|
|
@@ -147,6 +162,8 @@ export declare namespace RLLQueryConfig {
|
|
|
147
162
|
country_code?: ISO3166Alpha2.CountryCode;
|
|
148
163
|
search?: string | number;
|
|
149
164
|
slug?: string | number;
|
|
165
|
+
limit?: number | string;
|
|
166
|
+
direction?: "asc" | "desc";
|
|
150
167
|
}
|
|
151
168
|
export interface Locations extends Base {
|
|
152
169
|
name?: string | number;
|
|
@@ -181,4 +198,10 @@ export type RLLResponse<T> = {
|
|
|
181
198
|
last_page: number;
|
|
182
199
|
result: T;
|
|
183
200
|
};
|
|
201
|
+
export type RLLError = {
|
|
202
|
+
error: string;
|
|
203
|
+
statusCode: number | null;
|
|
204
|
+
message: string;
|
|
205
|
+
server_response: string | null;
|
|
206
|
+
};
|
|
184
207
|
//# sourceMappingURL=application.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../../../src/types/application.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,oBAAY,WAAW;IACrB,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,QAAQ,aAAa;CACtB;AAED,yBAAiB,SAAS,CAAC;IACzB,UAAU,SAAS;QACjB,EAAE,EAAE,MAAM,CAAC;KACZ;IAED,MAAM,WAAW,OAAO;QACtB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../../../src/types/application.ts"],"names":[],"mappings":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,GAAG,IAAI,CAAC;CAChC,CAAC"}
|
package/lib/cjs/types/utils.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { RLLEndPoint, RLLQueryConfig } from "./types/application";
|
|
2
|
+
export declare const formatToRLLISODate: (date: Date) => string;
|
|
2
3
|
export declare const apiKeyValidator: (apiKey: any) => string;
|
|
3
4
|
export declare const optionsValidator: (options: {
|
|
4
5
|
[key: string]: any;
|
|
5
6
|
[key: number]: any;
|
|
6
7
|
[key: symbol]: any;
|
|
7
8
|
}) => void;
|
|
8
|
-
export declare const queryOptionsValidator: (resource: RLLEndPoint, options?: RLLQueryConfig.Companies | RLLQueryConfig.Launches | RLLQueryConfig.Locations | RLLQueryConfig.Missions | RLLQueryConfig.Pads | RLLQueryConfig.Tags | RLLQueryConfig.Vehicles) =>
|
|
9
|
+
export declare const queryOptionsValidator: (resource: RLLEndPoint, options?: RLLQueryConfig.Companies | RLLQueryConfig.Launches | RLLQueryConfig.Locations | RLLQueryConfig.Missions | RLLQueryConfig.Pads | RLLQueryConfig.Tags | RLLQueryConfig.Vehicles) => URLSearchParams;
|
|
9
10
|
export declare const warn: (msg: string) => void;
|
|
10
11
|
export declare const error: (msg: string, type?: "type" | "range" | "error") => void;
|
|
11
12
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQlE,eAAO,MAAM,eAAe,WAAY,GAAG,KAAG,MA2B7C,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;MAEzB,IAeH,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQlE,eAAO,MAAM,kBAAkB,SAAU,IAAI,KAAG,MAE/C,CAAC;AAEF,eAAO,MAAM,eAAe,WAAY,GAAG,KAAG,MA2B7C,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;MAEzB,IAeH,CAAC;AAkLF,eAAO,MAAM,qBAAqB,aACtB,WAAW,YAEjB,eAAe,SAAS,GACxB,eAAe,QAAQ,GACvB,eAAe,SAAS,GACxB,eAAe,QAAQ,GACvB,eAAe,IAAI,GACnB,eAAe,IAAI,GACnB,eAAe,QAAQ,KAC1B,eAwDF,CAAC;AAEF,eAAO,MAAM,IAAI,QAAS,MAAM,SAAyC,CAAC;AAE1E,eAAO,MAAM,KAAK,QACX,MAAM,SACL,MAAM,GAAG,OAAO,GAAG,OAAO,KAC/B,IAYF,CAAC"}
|
package/lib/cjs/utils.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.error = exports.warn = exports.queryOptionsValidator = exports.optionsValidator = exports.apiKeyValidator = void 0;
|
|
3
|
+
exports.error = exports.warn = exports.queryOptionsValidator = exports.optionsValidator = exports.apiKeyValidator = exports.formatToRLLISODate = void 0;
|
|
4
4
|
const standards_1 = require("./types/standards");
|
|
5
5
|
const getLeadingZero = (month, offset = 0) => {
|
|
6
6
|
const str = "0".concat((month + offset).toString());
|
|
7
7
|
return str.slice(-2);
|
|
8
8
|
};
|
|
9
|
+
const formatToRLLISODate = (date) => {
|
|
10
|
+
return date.toISOString().slice(0, 19).concat("Z");
|
|
11
|
+
};
|
|
12
|
+
exports.formatToRLLISODate = formatToRLLISODate;
|
|
9
13
|
const apiKeyValidator = (apiKey) => {
|
|
10
14
|
if (apiKey === undefined) {
|
|
11
15
|
(0, exports.error)("RLL Client requires API Key", "type");
|
|
@@ -39,112 +43,113 @@ const optionsValidator = (options) => {
|
|
|
39
43
|
exports.optionsValidator = optionsValidator;
|
|
40
44
|
const validators = {
|
|
41
45
|
string: (option) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
resolve(option);
|
|
53
|
-
});
|
|
46
|
+
if (typeof option === "number") {
|
|
47
|
+
return option.toString();
|
|
48
|
+
}
|
|
49
|
+
if (typeof option !== "string") {
|
|
50
|
+
throw "Must be a string";
|
|
51
|
+
}
|
|
52
|
+
if (option.length <= 0) {
|
|
53
|
+
throw "String must have length greater than 0";
|
|
54
|
+
}
|
|
55
|
+
return option;
|
|
54
56
|
},
|
|
55
57
|
boolean: (option) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
resolve(option === true ? 1 : 0);
|
|
61
|
-
});
|
|
58
|
+
if (typeof option !== "boolean") {
|
|
59
|
+
throw "Must be a boolean";
|
|
60
|
+
}
|
|
61
|
+
return option === true ? 1 : 0;
|
|
62
62
|
},
|
|
63
63
|
number: (option) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
else {
|
|
74
|
-
resolve(Number(option));
|
|
75
|
-
}
|
|
76
|
-
});
|
|
64
|
+
if (typeof option === "number") {
|
|
65
|
+
return option;
|
|
66
|
+
}
|
|
67
|
+
if (typeof option !== "string" || option === "" || isNaN(Number(option))) {
|
|
68
|
+
throw "Must be a number";
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return Number(option);
|
|
72
|
+
}
|
|
77
73
|
},
|
|
78
74
|
countryCode: (option) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
resolve(option);
|
|
87
|
-
});
|
|
75
|
+
if (typeof option !== "string") {
|
|
76
|
+
throw "Must be a string";
|
|
77
|
+
}
|
|
78
|
+
if (!(0, standards_1.isValidCountryCode)(option)) {
|
|
79
|
+
throw "Invalid country code. Country codes should follow ISO 3166-1 A2 convention, like 'US'.";
|
|
80
|
+
}
|
|
81
|
+
return option;
|
|
88
82
|
},
|
|
89
83
|
stateCode: (option) => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
resolve(option);
|
|
98
|
-
});
|
|
84
|
+
if (typeof option !== "string") {
|
|
85
|
+
throw "Must be a string";
|
|
86
|
+
}
|
|
87
|
+
if (!(0, standards_1.isValidStateCode)(option)) {
|
|
88
|
+
throw "Invalid United States State Code. State Codes should follow ISO 3166-2 convention, like 'FL'.";
|
|
89
|
+
}
|
|
90
|
+
return option;
|
|
99
91
|
},
|
|
100
92
|
cosparId: (option) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
resolve(option);
|
|
109
|
-
});
|
|
93
|
+
if (typeof option !== "string") {
|
|
94
|
+
throw "Must be a string";
|
|
95
|
+
}
|
|
96
|
+
if (!option.match(/^\d{4}\-\d{3}$/g)) {
|
|
97
|
+
throw "Cospar IDs must be in the format of YYYY-NNN (eg. 2023-123)";
|
|
98
|
+
}
|
|
99
|
+
return option;
|
|
110
100
|
},
|
|
111
101
|
shortDate: (option) => {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
date = new Date(parsed);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
date = option;
|
|
124
|
-
}
|
|
125
|
-
resolve(`${date.getUTCFullYear()}-${getLeadingZero(date.getUTCMonth(), 1)}-${getLeadingZero(date.getUTCDate())}`);
|
|
102
|
+
if (typeof option !== "string" && !(option instanceof Date)) {
|
|
103
|
+
throw "Must be a JavaScript Date Object or ISO 8601 Date String";
|
|
104
|
+
}
|
|
105
|
+
let date;
|
|
106
|
+
if (typeof option === "string") {
|
|
107
|
+
const parsed = Date.parse(option);
|
|
108
|
+
if (isNaN(parsed)) {
|
|
109
|
+
throw "Must be an ISO 8601 Date String";
|
|
126
110
|
}
|
|
127
|
-
|
|
128
|
-
}
|
|
111
|
+
date = new Date(parsed);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
date = option;
|
|
115
|
+
}
|
|
116
|
+
return `${date.getUTCFullYear()}-${getLeadingZero(date.getUTCMonth(), 1)}-${getLeadingZero(date.getUTCDate())}`;
|
|
129
117
|
},
|
|
130
118
|
isoDate: (option) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
date = new Date(parsed);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
date = option;
|
|
143
|
-
}
|
|
144
|
-
resolve(date.toISOString().slice(0, 19).concat("Z"));
|
|
119
|
+
if (typeof option !== "string" && !(option instanceof Date)) {
|
|
120
|
+
throw "Must be a JavaScript Date Object or ISO 8601 Date String";
|
|
121
|
+
}
|
|
122
|
+
let date;
|
|
123
|
+
if (typeof option === "string") {
|
|
124
|
+
const parsed = Date.parse(option);
|
|
125
|
+
if (isNaN(parsed)) {
|
|
126
|
+
throw "Must be an ISO 8601 Date String";
|
|
145
127
|
}
|
|
146
|
-
|
|
147
|
-
}
|
|
128
|
+
date = new Date(parsed);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
date = option;
|
|
132
|
+
}
|
|
133
|
+
return (0, exports.formatToRLLISODate)(date);
|
|
134
|
+
},
|
|
135
|
+
limit: (option) => {
|
|
136
|
+
const num = validators.number(option);
|
|
137
|
+
if (num < 1) {
|
|
138
|
+
throw "Must be a number greater than 0";
|
|
139
|
+
}
|
|
140
|
+
if (num > 25) {
|
|
141
|
+
throw "Must be a number less than 26";
|
|
142
|
+
}
|
|
143
|
+
return num;
|
|
144
|
+
},
|
|
145
|
+
direction: (option) => {
|
|
146
|
+
if (typeof option !== "string") {
|
|
147
|
+
throw "Must be a string";
|
|
148
|
+
}
|
|
149
|
+
if (option !== "asc" && option !== "desc") {
|
|
150
|
+
throw 'String must be either "asc" or "desc"';
|
|
151
|
+
}
|
|
152
|
+
return option;
|
|
148
153
|
},
|
|
149
154
|
};
|
|
150
155
|
const optionsMap = {
|
|
@@ -171,6 +176,8 @@ const optionsMap = {
|
|
|
171
176
|
country_code: validators.countryCode,
|
|
172
177
|
search: validators.string,
|
|
173
178
|
slug: validators.string,
|
|
179
|
+
limit: validators.limit,
|
|
180
|
+
direction: validators.direction,
|
|
174
181
|
},
|
|
175
182
|
locations: {
|
|
176
183
|
page: validators.number,
|
|
@@ -204,9 +211,18 @@ const optionsMap = {
|
|
|
204
211
|
};
|
|
205
212
|
const queryOptionsValidator = (resource, options) => {
|
|
206
213
|
const params = new URLSearchParams();
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
214
|
+
if (options === undefined) {
|
|
215
|
+
return params;
|
|
216
|
+
}
|
|
217
|
+
if (typeof options === "string" ||
|
|
218
|
+
typeof options === "number" ||
|
|
219
|
+
typeof options === "boolean" ||
|
|
220
|
+
typeof options === "bigint" ||
|
|
221
|
+
typeof options === "symbol" ||
|
|
222
|
+
typeof options === "function" ||
|
|
223
|
+
options === null ||
|
|
224
|
+
Array.isArray(options)) {
|
|
225
|
+
(0, exports.error)("Invalid type for query options. Must be an object.");
|
|
210
226
|
}
|
|
211
227
|
if ((options.id || "slug" in options || "cospar_id" in options) &&
|
|
212
228
|
Object.keys(options).length > 1) {
|
|
@@ -221,14 +237,15 @@ const queryOptionsValidator = (resource, options) => {
|
|
|
221
237
|
(0, exports.warn)(`Parameter "${option}" is undefined and will be ignored.`);
|
|
222
238
|
continue;
|
|
223
239
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
240
|
+
try {
|
|
241
|
+
const o = optionsMap[resource][option](options[option]);
|
|
242
|
+
params.set(option, o);
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
(0, exports.error)(`Malformed query parameter for resource "${resource}" and parameter: "${option}": ${err}.`, "type");
|
|
246
|
+
}
|
|
230
247
|
}
|
|
231
|
-
return
|
|
248
|
+
return params;
|
|
232
249
|
};
|
|
233
250
|
exports.queryOptionsValidator = queryOptionsValidator;
|
|
234
251
|
const warn = (msg) => console.warn(`[RLL Client]: ${msg}`);
|