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/README.md +182 -1
- package/lib/cjs/Client.js +36 -16
- package/lib/cjs/Watcher.js +171 -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 +92 -0
- package/lib/cjs/types/Watcher.d.ts.map +1 -0
- 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 +33 -14
- package/lib/cjs/types/types/application.d.ts.map +1 -1
- package/lib/cjs/types/utils.d.ts +3 -2
- package/lib/cjs/types/utils.d.ts.map +1 -1
- package/lib/cjs/utils.js +101 -103
- package/lib/esm/Client.js +36 -16
- package/lib/esm/Watcher.js +169 -0
- package/lib/esm/fetcher.js +17 -10
- package/lib/esm/index.mjs +1 -0
- 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 +92 -0
- package/lib/esm/types/Watcher.d.ts.map +1 -0
- 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/types/application.d.ts +33 -14
- package/lib/esm/types/types/application.d.ts.map +1 -1
- package/lib/esm/types/utils.d.ts +3 -2
- package/lib/esm/types/utils.d.ts.map +1 -1
- package/lib/esm/utils.js +99 -102
- package/package.json +1 -4
|
@@ -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,EACT,QAAQ,EACR,cAAc,EACd,WAAW,EACZ,MAAM,qBAAqB,CAAC;AA4C7B,UAAU,gBAAgB;IACxB,GAAG,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC;IACxC,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC;IAC3E,KAAK,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;IACjC,KAAK,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACzD,UAAU,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;IACtC,IAAI,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,CAAC;CACzC;AAED;;;GAGG;AACH,qBAAa,UAAW,SAAQ,YAAY;IAC1C,OAAO,CAAC,UAAU,CAAW;IAC7B,OAAO,CAAC,YAAY,CAAa;IAC1B,EAAE,iFAGN,IAAI,CAAqC;IACrC,IAAI,4FAGR,OAAO,CAAsC;IAChD,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,CAA2B;IACxC,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;IAUnC;;;;;;;;;;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 +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,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
|
|
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:
|
|
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
|
}
|
|
@@ -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
|
|
@@ -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":"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,GAAG,EAAE,CAAC;KACtC;IAED,MAAM,WAAW,KAAK;QACpB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC;KAClC;IAED,MAAM,WAAW,OAAQ,SAAQ,SAAS;QACxC,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;KAC1B;IAED,MAAM,MAAM,YAAY;QACtB,OAAO,KAAK;QACZ,OAAO,IAAI;QACX,OAAO,IAAI;QACX,eAAe,IAAI;QACnB,sBAAsB,IAAI;KAC3B;IAED,MAAM,WAAW,KAAM,SAAQ,SAAS;QACtC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7B,QAAQ,EAAE,OAAO,CAAC;QAClB,UAAU,EAAE,OAAO,CAAC;QACpB,QAAQ,EAAE,OAAO,CAAC;KACnB;IAED,MAAM,WAAW,MAAO,SAAQ,SAAS;QACvC,IAAI,EAAE,MAAM,CA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IACd,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,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
|
|
2
|
+
export declare const formatToRLLISODate: (date: Date) => string;
|
|
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,
|
|
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;AA6JF,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");
|
|
@@ -13,13 +17,15 @@ const apiKeyValidator = (apiKey) => {
|
|
|
13
17
|
if (typeof apiKey !== "string") {
|
|
14
18
|
(0, exports.error)("RLL Client API Key must be a string", "type");
|
|
15
19
|
}
|
|
16
|
-
|
|
20
|
+
const trimmedKey = apiKey.trim();
|
|
21
|
+
if (trimmedKey === "") {
|
|
17
22
|
(0, exports.error)("RLL Client API Key cannot be an empty string", "type");
|
|
18
23
|
}
|
|
19
|
-
const validator =
|
|
24
|
+
const validator = trimmedKey.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i);
|
|
20
25
|
if (validator === null) {
|
|
21
26
|
(0, exports.error)("RLL Client API Key appears malformed. RLL Client API Keys are in UUID format.", "type");
|
|
22
27
|
}
|
|
28
|
+
return trimmedKey;
|
|
23
29
|
};
|
|
24
30
|
exports.apiKeyValidator = apiKeyValidator;
|
|
25
31
|
const optionsValidator = (options) => {
|
|
@@ -37,112 +43,94 @@ const optionsValidator = (options) => {
|
|
|
37
43
|
exports.optionsValidator = optionsValidator;
|
|
38
44
|
const validators = {
|
|
39
45
|
string: (option) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
resolve(option);
|
|
51
|
-
});
|
|
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;
|
|
52
56
|
},
|
|
53
57
|
boolean: (option) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
resolve(option === true ? 1 : 0);
|
|
59
|
-
});
|
|
58
|
+
if (typeof option !== "boolean") {
|
|
59
|
+
throw "Must be a boolean";
|
|
60
|
+
}
|
|
61
|
+
return option === true ? 1 : 0;
|
|
60
62
|
},
|
|
61
63
|
number: (option) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
else {
|
|
72
|
-
resolve(Number(option));
|
|
73
|
-
}
|
|
74
|
-
});
|
|
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
|
+
}
|
|
75
73
|
},
|
|
76
74
|
countryCode: (option) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
resolve(option);
|
|
85
|
-
});
|
|
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;
|
|
86
82
|
},
|
|
87
83
|
stateCode: (option) => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
resolve(option);
|
|
96
|
-
});
|
|
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;
|
|
97
91
|
},
|
|
98
92
|
cosparId: (option) => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
resolve(option);
|
|
107
|
-
});
|
|
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;
|
|
108
100
|
},
|
|
109
101
|
shortDate: (option) => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
date = new Date(parsed);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
date = option;
|
|
122
|
-
}
|
|
123
|
-
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";
|
|
124
110
|
}
|
|
125
|
-
|
|
126
|
-
}
|
|
111
|
+
date = new Date(parsed);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
date = option;
|
|
115
|
+
}
|
|
116
|
+
return `${date.getUTCFullYear()}-${getLeadingZero(date.getUTCMonth(), 1)}-${getLeadingZero(date.getUTCDate())}`;
|
|
127
117
|
},
|
|
128
118
|
isoDate: (option) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
date = new Date(parsed);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
date = option;
|
|
141
|
-
}
|
|
142
|
-
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";
|
|
143
127
|
}
|
|
144
|
-
|
|
145
|
-
}
|
|
128
|
+
date = new Date(parsed);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
date = option;
|
|
132
|
+
}
|
|
133
|
+
return (0, exports.formatToRLLISODate)(date);
|
|
146
134
|
},
|
|
147
135
|
};
|
|
148
136
|
const optionsMap = {
|
|
@@ -202,9 +190,18 @@ const optionsMap = {
|
|
|
202
190
|
};
|
|
203
191
|
const queryOptionsValidator = (resource, options) => {
|
|
204
192
|
const params = new URLSearchParams();
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
193
|
+
if (options === undefined) {
|
|
194
|
+
return params;
|
|
195
|
+
}
|
|
196
|
+
if (typeof options === "string" ||
|
|
197
|
+
typeof options === "number" ||
|
|
198
|
+
typeof options === "boolean" ||
|
|
199
|
+
typeof options === "bigint" ||
|
|
200
|
+
typeof options === "symbol" ||
|
|
201
|
+
typeof options === "function" ||
|
|
202
|
+
options === null ||
|
|
203
|
+
Array.isArray(options)) {
|
|
204
|
+
(0, exports.error)("Invalid type for query options. Must be an object.");
|
|
208
205
|
}
|
|
209
206
|
if ((options.id || "slug" in options || "cospar_id" in options) &&
|
|
210
207
|
Object.keys(options).length > 1) {
|
|
@@ -219,14 +216,15 @@ const queryOptionsValidator = (resource, options) => {
|
|
|
219
216
|
(0, exports.warn)(`Parameter "${option}" is undefined and will be ignored.`);
|
|
220
217
|
continue;
|
|
221
218
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
219
|
+
try {
|
|
220
|
+
const o = optionsMap[resource][option](options[option]);
|
|
221
|
+
params.set(option, o);
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
(0, exports.error)(`Malformed query parameter for resource "${resource}" and parameter: "${option}": ${err}.`, "type");
|
|
225
|
+
}
|
|
228
226
|
}
|
|
229
|
-
return
|
|
227
|
+
return params;
|
|
230
228
|
};
|
|
231
229
|
exports.queryOptionsValidator = queryOptionsValidator;
|
|
232
230
|
const warn = (msg) => console.warn(`[RLL Client]: ${msg}`);
|