rocket-launch-live-client 0.2.1 → 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 +35 -14
- 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 +2 -1
- package/lib/cjs/types/utils.d.ts.map +1 -1
- package/lib/cjs/utils.js +97 -101
- package/lib/esm/Client.js +35 -14
- 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 +2 -1
- package/lib/esm/types/utils.d.ts.map +1 -1
- package/lib/esm/utils.js +95 -100
- package/package.json +1 -4
package/lib/esm/utils.js
CHANGED
|
@@ -3,6 +3,9 @@ const getLeadingZero = (month, offset = 0) => {
|
|
|
3
3
|
const str = "0".concat((month + offset).toString());
|
|
4
4
|
return str.slice(-2);
|
|
5
5
|
};
|
|
6
|
+
export const formatToRLLISODate = (date) => {
|
|
7
|
+
return date.toISOString().slice(0, 19).concat("Z");
|
|
8
|
+
};
|
|
6
9
|
export const apiKeyValidator = (apiKey) => {
|
|
7
10
|
if (apiKey === undefined) {
|
|
8
11
|
error("RLL Client requires API Key", "type");
|
|
@@ -34,112 +37,94 @@ export const optionsValidator = (options) => {
|
|
|
34
37
|
};
|
|
35
38
|
const validators = {
|
|
36
39
|
string: (option) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
resolve(option);
|
|
48
|
-
});
|
|
40
|
+
if (typeof option === "number") {
|
|
41
|
+
return option.toString();
|
|
42
|
+
}
|
|
43
|
+
if (typeof option !== "string") {
|
|
44
|
+
throw "Must be a string";
|
|
45
|
+
}
|
|
46
|
+
if (option.length <= 0) {
|
|
47
|
+
throw "String must have length greater than 0";
|
|
48
|
+
}
|
|
49
|
+
return option;
|
|
49
50
|
},
|
|
50
51
|
boolean: (option) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
resolve(option === true ? 1 : 0);
|
|
56
|
-
});
|
|
52
|
+
if (typeof option !== "boolean") {
|
|
53
|
+
throw "Must be a boolean";
|
|
54
|
+
}
|
|
55
|
+
return option === true ? 1 : 0;
|
|
57
56
|
},
|
|
58
57
|
number: (option) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
else {
|
|
69
|
-
resolve(Number(option));
|
|
70
|
-
}
|
|
71
|
-
});
|
|
58
|
+
if (typeof option === "number") {
|
|
59
|
+
return option;
|
|
60
|
+
}
|
|
61
|
+
if (typeof option !== "string" || option === "" || isNaN(Number(option))) {
|
|
62
|
+
throw "Must be a number";
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return Number(option);
|
|
66
|
+
}
|
|
72
67
|
},
|
|
73
68
|
countryCode: (option) => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
resolve(option);
|
|
82
|
-
});
|
|
69
|
+
if (typeof option !== "string") {
|
|
70
|
+
throw "Must be a string";
|
|
71
|
+
}
|
|
72
|
+
if (!isValidCountryCode(option)) {
|
|
73
|
+
throw "Invalid country code. Country codes should follow ISO 3166-1 A2 convention, like 'US'.";
|
|
74
|
+
}
|
|
75
|
+
return option;
|
|
83
76
|
},
|
|
84
77
|
stateCode: (option) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
resolve(option);
|
|
93
|
-
});
|
|
78
|
+
if (typeof option !== "string") {
|
|
79
|
+
throw "Must be a string";
|
|
80
|
+
}
|
|
81
|
+
if (!isValidStateCode(option)) {
|
|
82
|
+
throw "Invalid United States State Code. State Codes should follow ISO 3166-2 convention, like 'FL'.";
|
|
83
|
+
}
|
|
84
|
+
return option;
|
|
94
85
|
},
|
|
95
86
|
cosparId: (option) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
resolve(option);
|
|
104
|
-
});
|
|
87
|
+
if (typeof option !== "string") {
|
|
88
|
+
throw "Must be a string";
|
|
89
|
+
}
|
|
90
|
+
if (!option.match(/^\d{4}\-\d{3}$/g)) {
|
|
91
|
+
throw "Cospar IDs must be in the format of YYYY-NNN (eg. 2023-123)";
|
|
92
|
+
}
|
|
93
|
+
return option;
|
|
105
94
|
},
|
|
106
95
|
shortDate: (option) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
date = new Date(parsed);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
date = option;
|
|
119
|
-
}
|
|
120
|
-
resolve(`${date.getUTCFullYear()}-${getLeadingZero(date.getUTCMonth(), 1)}-${getLeadingZero(date.getUTCDate())}`);
|
|
96
|
+
if (typeof option !== "string" && !(option instanceof Date)) {
|
|
97
|
+
throw "Must be a JavaScript Date Object or ISO 8601 Date String";
|
|
98
|
+
}
|
|
99
|
+
let date;
|
|
100
|
+
if (typeof option === "string") {
|
|
101
|
+
const parsed = Date.parse(option);
|
|
102
|
+
if (isNaN(parsed)) {
|
|
103
|
+
throw "Must be an ISO 8601 Date String";
|
|
121
104
|
}
|
|
122
|
-
|
|
123
|
-
}
|
|
105
|
+
date = new Date(parsed);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
date = option;
|
|
109
|
+
}
|
|
110
|
+
return `${date.getUTCFullYear()}-${getLeadingZero(date.getUTCMonth(), 1)}-${getLeadingZero(date.getUTCDate())}`;
|
|
124
111
|
},
|
|
125
112
|
isoDate: (option) => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
date = new Date(parsed);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
date = option;
|
|
138
|
-
}
|
|
139
|
-
resolve(date.toISOString().slice(0, 19).concat("Z"));
|
|
113
|
+
if (typeof option !== "string" && !(option instanceof Date)) {
|
|
114
|
+
throw "Must be a JavaScript Date Object or ISO 8601 Date String";
|
|
115
|
+
}
|
|
116
|
+
let date;
|
|
117
|
+
if (typeof option === "string") {
|
|
118
|
+
const parsed = Date.parse(option);
|
|
119
|
+
if (isNaN(parsed)) {
|
|
120
|
+
throw "Must be an ISO 8601 Date String";
|
|
140
121
|
}
|
|
141
|
-
|
|
142
|
-
}
|
|
122
|
+
date = new Date(parsed);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
date = option;
|
|
126
|
+
}
|
|
127
|
+
return formatToRLLISODate(date);
|
|
143
128
|
},
|
|
144
129
|
};
|
|
145
130
|
const optionsMap = {
|
|
@@ -199,9 +184,18 @@ const optionsMap = {
|
|
|
199
184
|
};
|
|
200
185
|
export const queryOptionsValidator = (resource, options) => {
|
|
201
186
|
const params = new URLSearchParams();
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
187
|
+
if (options === undefined) {
|
|
188
|
+
return params;
|
|
189
|
+
}
|
|
190
|
+
if (typeof options === "string" ||
|
|
191
|
+
typeof options === "number" ||
|
|
192
|
+
typeof options === "boolean" ||
|
|
193
|
+
typeof options === "bigint" ||
|
|
194
|
+
typeof options === "symbol" ||
|
|
195
|
+
typeof options === "function" ||
|
|
196
|
+
options === null ||
|
|
197
|
+
Array.isArray(options)) {
|
|
198
|
+
error("Invalid type for query options. Must be an object.");
|
|
205
199
|
}
|
|
206
200
|
if ((options.id || "slug" in options || "cospar_id" in options) &&
|
|
207
201
|
Object.keys(options).length > 1) {
|
|
@@ -216,14 +210,15 @@ export const queryOptionsValidator = (resource, options) => {
|
|
|
216
210
|
warn(`Parameter "${option}" is undefined and will be ignored.`);
|
|
217
211
|
continue;
|
|
218
212
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
213
|
+
try {
|
|
214
|
+
const o = optionsMap[resource][option](options[option]);
|
|
215
|
+
params.set(option, o);
|
|
216
|
+
}
|
|
217
|
+
catch (err) {
|
|
218
|
+
error(`Malformed query parameter for resource "${resource}" and parameter: "${option}": ${err}.`, "type");
|
|
219
|
+
}
|
|
225
220
|
}
|
|
226
|
-
return
|
|
221
|
+
return params;
|
|
227
222
|
};
|
|
228
223
|
export const warn = (msg) => console.warn(`[RLL Client]: ${msg}`);
|
|
229
224
|
export const error = (msg, type = "error") => {
|
package/package.json
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rocket-launch-live-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A Node.JS client for interacting with the RocketLaunch.Live API",
|
|
5
5
|
"types": "./lib/cjs/types/index.d.ts",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"clear": "rm -rf ./lib",
|
|
9
|
-
"dev": "nodemon ./lib/test.js --ignore 'lib/**' -e ts --exec \"npm run compile\"",
|
|
10
|
-
"compile": "npm run clear && tsc && node ./lib/test.js",
|
|
11
9
|
"build": "npm run clear && npm run build:esm && npm run build:cjs",
|
|
12
10
|
"build:esm": "tsc -p ./configs/tsconfig.esm.json && mv lib/esm/index.js lib/esm/index.mjs",
|
|
13
11
|
"build:cjs": "tsc -p ./configs/tsconfig.cjs.json",
|
|
14
|
-
"start": "node ./lib/test.js",
|
|
15
12
|
"prepublish": "npm run build",
|
|
16
13
|
"test": "mocha",
|
|
17
14
|
"test:watch": "mocha --watch"
|