oilpriceapi 0.7.0 → 0.9.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 +244 -30
- package/dist/cjs/client.js +610 -0
- package/dist/cjs/errors.js +80 -0
- package/dist/cjs/index.js +96 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/resources/alerts.js +387 -0
- package/dist/cjs/resources/analytics.js +188 -0
- package/dist/cjs/resources/bunker-fuels.js +210 -0
- package/dist/cjs/resources/commodities.js +115 -0
- package/dist/cjs/resources/data-quality.js +144 -0
- package/dist/cjs/resources/data-sources.js +298 -0
- package/dist/cjs/resources/diesel.js +119 -0
- package/dist/cjs/resources/drilling.js +269 -0
- package/dist/cjs/resources/ei/drilling-productivity.js +108 -0
- package/dist/cjs/resources/ei/forecasts.js +106 -0
- package/dist/cjs/resources/ei/frac-focus.js +165 -0
- package/dist/cjs/resources/ei/index.js +98 -0
- package/dist/cjs/resources/ei/oil-inventories.js +97 -0
- package/dist/cjs/resources/ei/opec-production.js +97 -0
- package/dist/cjs/resources/ei/rig-counts.js +93 -0
- package/dist/cjs/resources/ei/well-permits.js +136 -0
- package/dist/cjs/resources/forecasts.js +168 -0
- package/dist/cjs/resources/futures.js +424 -0
- package/dist/cjs/resources/indicators.js +79 -0
- package/dist/cjs/resources/raw.js +128 -0
- package/dist/cjs/resources/rig-counts.js +164 -0
- package/dist/cjs/resources/spreads.js +105 -0
- package/dist/cjs/resources/storage.js +166 -0
- package/dist/cjs/resources/streaming.js +350 -0
- package/dist/cjs/resources/webhooks.js +283 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/version.js +24 -0
- package/dist/client.d.ts +130 -3
- package/dist/client.js +206 -30
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +25 -16
- package/dist/index.d.ts +28 -5
- package/dist/index.js +29 -1
- package/dist/resources/alerts.js +31 -77
- package/dist/resources/analytics.d.ts +147 -214
- package/dist/resources/analytics.js +104 -141
- package/dist/resources/bunker-fuels.d.ts +35 -12
- package/dist/resources/bunker-fuels.js +41 -26
- package/dist/resources/commodities.js +2 -1
- package/dist/resources/data-quality.js +2 -1
- package/dist/resources/data-sources.d.ts +31 -31
- package/dist/resources/data-sources.js +30 -85
- package/dist/resources/diesel.d.ts +1 -1
- package/dist/resources/diesel.js +9 -38
- package/dist/resources/drilling.js +2 -1
- package/dist/resources/ei/drilling-productivity.js +2 -1
- package/dist/resources/ei/forecasts.js +2 -1
- package/dist/resources/ei/frac-focus.d.ts +23 -9
- package/dist/resources/ei/frac-focus.js +20 -9
- package/dist/resources/ei/index.js +2 -1
- package/dist/resources/ei/oil-inventories.js +2 -1
- package/dist/resources/ei/opec-production.js +2 -1
- package/dist/resources/ei/rig-counts.js +2 -1
- package/dist/resources/ei/well-permits.d.ts +25 -9
- package/dist/resources/ei/well-permits.js +20 -7
- package/dist/resources/forecasts.d.ts +4 -1
- package/dist/resources/forecasts.js +13 -6
- package/dist/resources/futures.d.ts +178 -1
- package/dist/resources/futures.js +199 -8
- package/dist/resources/indicators.d.ts +170 -0
- package/dist/resources/indicators.js +75 -0
- package/dist/resources/raw.d.ts +94 -0
- package/dist/resources/raw.js +124 -0
- package/dist/resources/rig-counts.js +5 -2
- package/dist/resources/spreads.d.ts +121 -0
- package/dist/resources/spreads.js +101 -0
- package/dist/resources/storage.d.ts +5 -4
- package/dist/resources/storage.js +7 -6
- package/dist/resources/streaming.d.ts +272 -0
- package/dist/resources/streaming.js +342 -0
- package/dist/resources/webhooks.d.ts +73 -23
- package/dist/resources/webhooks.js +59 -77
- package/dist/types.d.ts +43 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +2 -2
- package/package.json +21 -6
package/dist/resources/alerts.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Manage price alert configurations for automated notifications.
|
|
5
5
|
*/
|
|
6
|
+
import { ValidationError } from "../errors.js";
|
|
6
7
|
/**
|
|
7
8
|
* Price Alerts Resource
|
|
8
9
|
*
|
|
@@ -100,7 +101,7 @@ export class AlertsResource {
|
|
|
100
101
|
*/
|
|
101
102
|
async get(id) {
|
|
102
103
|
if (!id || typeof id !== "string") {
|
|
103
|
-
throw new
|
|
104
|
+
throw new ValidationError("Alert ID must be a non-empty string");
|
|
104
105
|
}
|
|
105
106
|
const response = await this.client["request"](`/v1/alerts/${id}`, {});
|
|
106
107
|
// API returns object directly, but handle both formats for compatibility
|
|
@@ -146,16 +147,16 @@ export class AlertsResource {
|
|
|
146
147
|
async create(params) {
|
|
147
148
|
// Validate required fields
|
|
148
149
|
if (!params.name || typeof params.name !== "string") {
|
|
149
|
-
throw new
|
|
150
|
+
throw new ValidationError("Alert name is required and must be a string");
|
|
150
151
|
}
|
|
151
152
|
if (params.name.length < 1 || params.name.length > 100) {
|
|
152
|
-
throw new
|
|
153
|
+
throw new ValidationError("Alert name must be 1-100 characters");
|
|
153
154
|
}
|
|
154
155
|
if (!params.commodity_code || typeof params.commodity_code !== "string") {
|
|
155
|
-
throw new
|
|
156
|
+
throw new ValidationError("Commodity code is required and must be a string");
|
|
156
157
|
}
|
|
157
158
|
if (!params.condition_operator) {
|
|
158
|
-
throw new
|
|
159
|
+
throw new ValidationError("Condition operator is required");
|
|
159
160
|
}
|
|
160
161
|
const validOperators = [
|
|
161
162
|
"greater_than",
|
|
@@ -165,39 +166,34 @@ export class AlertsResource {
|
|
|
165
166
|
"less_than_or_equal",
|
|
166
167
|
];
|
|
167
168
|
if (!validOperators.includes(params.condition_operator)) {
|
|
168
|
-
throw new
|
|
169
|
+
throw new ValidationError(`Invalid operator. Must be one of: ${validOperators.join(", ")}`);
|
|
169
170
|
}
|
|
170
171
|
if (typeof params.condition_value !== "number") {
|
|
171
|
-
throw new
|
|
172
|
+
throw new ValidationError("Condition value must be a number");
|
|
172
173
|
}
|
|
173
174
|
if (params.condition_value <= 0 || params.condition_value > 1000000) {
|
|
174
|
-
throw new
|
|
175
|
+
throw new ValidationError("Condition value must be greater than 0 and less than or equal to 1,000,000");
|
|
175
176
|
}
|
|
176
177
|
// Validate optional fields
|
|
177
178
|
if (params.webhook_url !== undefined) {
|
|
178
179
|
if (typeof params.webhook_url !== "string") {
|
|
179
|
-
throw new
|
|
180
|
+
throw new ValidationError("Webhook URL must be a string");
|
|
180
181
|
}
|
|
181
182
|
if (params.webhook_url && !params.webhook_url.startsWith("https://")) {
|
|
182
|
-
throw new
|
|
183
|
+
throw new ValidationError("Webhook URL must use HTTPS protocol");
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
186
|
if (params.cooldown_minutes !== undefined) {
|
|
186
187
|
if (typeof params.cooldown_minutes !== "number") {
|
|
187
|
-
throw new
|
|
188
|
+
throw new ValidationError("Cooldown minutes must be a number");
|
|
188
189
|
}
|
|
189
190
|
if (params.cooldown_minutes < 0 || params.cooldown_minutes > 1440) {
|
|
190
|
-
throw new
|
|
191
|
+
throw new ValidationError("Cooldown minutes must be between 0 and 1440 (24 hours)");
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
|
-
const
|
|
194
|
-
const response = await fetch(url, {
|
|
194
|
+
const response = await this.client["request"]("/v1/alerts", {}, {
|
|
195
195
|
method: "POST",
|
|
196
|
-
|
|
197
|
-
Authorization: `Bearer ${this.client["apiKey"]}`,
|
|
198
|
-
"Content-Type": "application/json",
|
|
199
|
-
},
|
|
200
|
-
body: JSON.stringify({
|
|
196
|
+
body: {
|
|
201
197
|
price_alert: {
|
|
202
198
|
name: params.name,
|
|
203
199
|
commodity_code: params.commodity_code,
|
|
@@ -208,15 +204,9 @@ export class AlertsResource {
|
|
|
208
204
|
cooldown_minutes: params.cooldown_minutes ?? 60,
|
|
209
205
|
metadata: params.metadata,
|
|
210
206
|
},
|
|
211
|
-
}
|
|
207
|
+
},
|
|
212
208
|
});
|
|
213
|
-
|
|
214
|
-
const errorText = await response.text();
|
|
215
|
-
throw new Error(`Failed to create alert: ${response.status} ${errorText}`);
|
|
216
|
-
}
|
|
217
|
-
const data = (await response.json());
|
|
218
|
-
// API returns object directly, but handle both formats for compatibility
|
|
219
|
-
return "alert" in data ? data.alert : data;
|
|
209
|
+
return "alert" in response ? response.alert : response;
|
|
220
210
|
}
|
|
221
211
|
/**
|
|
222
212
|
* Update an existing price alert
|
|
@@ -251,14 +241,14 @@ export class AlertsResource {
|
|
|
251
241
|
*/
|
|
252
242
|
async update(id, params) {
|
|
253
243
|
if (!id || typeof id !== "string") {
|
|
254
|
-
throw new
|
|
244
|
+
throw new ValidationError("Alert ID must be a non-empty string");
|
|
255
245
|
}
|
|
256
246
|
// Validate fields if provided
|
|
257
247
|
if (params.name !== undefined) {
|
|
258
248
|
if (typeof params.name !== "string" ||
|
|
259
249
|
params.name.length < 1 ||
|
|
260
250
|
params.name.length > 100) {
|
|
261
|
-
throw new
|
|
251
|
+
throw new ValidationError("Alert name must be 1-100 characters");
|
|
262
252
|
}
|
|
263
253
|
}
|
|
264
254
|
if (params.condition_operator !== undefined) {
|
|
@@ -270,48 +260,35 @@ export class AlertsResource {
|
|
|
270
260
|
"less_than_or_equal",
|
|
271
261
|
];
|
|
272
262
|
if (!validOperators.includes(params.condition_operator)) {
|
|
273
|
-
throw new
|
|
263
|
+
throw new ValidationError(`Invalid operator. Must be one of: ${validOperators.join(", ")}`);
|
|
274
264
|
}
|
|
275
265
|
}
|
|
276
266
|
if (params.condition_value !== undefined) {
|
|
277
267
|
if (typeof params.condition_value !== "number") {
|
|
278
|
-
throw new
|
|
268
|
+
throw new ValidationError("Condition value must be a number");
|
|
279
269
|
}
|
|
280
270
|
if (params.condition_value <= 0 || params.condition_value > 1000000) {
|
|
281
|
-
throw new
|
|
271
|
+
throw new ValidationError("Condition value must be greater than 0 and less than or equal to 1,000,000");
|
|
282
272
|
}
|
|
283
273
|
}
|
|
284
274
|
if (params.webhook_url !== undefined && params.webhook_url !== null) {
|
|
285
275
|
if (typeof params.webhook_url !== "string" ||
|
|
286
276
|
!params.webhook_url.startsWith("https://")) {
|
|
287
|
-
throw new
|
|
277
|
+
throw new ValidationError("Webhook URL must be a valid HTTPS URL");
|
|
288
278
|
}
|
|
289
279
|
}
|
|
290
280
|
if (params.cooldown_minutes !== undefined) {
|
|
291
281
|
if (typeof params.cooldown_minutes !== "number" ||
|
|
292
282
|
params.cooldown_minutes < 0 ||
|
|
293
283
|
params.cooldown_minutes > 1440) {
|
|
294
|
-
throw new
|
|
284
|
+
throw new ValidationError("Cooldown minutes must be between 0 and 1440 (24 hours)");
|
|
295
285
|
}
|
|
296
286
|
}
|
|
297
|
-
const
|
|
298
|
-
const response = await fetch(url, {
|
|
287
|
+
const response = await this.client["request"](`/v1/alerts/${id}`, {}, {
|
|
299
288
|
method: "PATCH",
|
|
300
|
-
|
|
301
|
-
Authorization: `Bearer ${this.client["apiKey"]}`,
|
|
302
|
-
"Content-Type": "application/json",
|
|
303
|
-
},
|
|
304
|
-
body: JSON.stringify({
|
|
305
|
-
price_alert: params,
|
|
306
|
-
}),
|
|
289
|
+
body: { price_alert: params },
|
|
307
290
|
});
|
|
308
|
-
|
|
309
|
-
const errorText = await response.text();
|
|
310
|
-
throw new Error(`Failed to update alert: ${response.status} ${errorText}`);
|
|
311
|
-
}
|
|
312
|
-
const data = (await response.json());
|
|
313
|
-
// API returns object directly, but handle both formats for compatibility
|
|
314
|
-
return "alert" in data ? data.alert : data;
|
|
291
|
+
return "alert" in response ? response.alert : response;
|
|
315
292
|
}
|
|
316
293
|
/**
|
|
317
294
|
* Delete a price alert
|
|
@@ -331,20 +308,9 @@ export class AlertsResource {
|
|
|
331
308
|
*/
|
|
332
309
|
async delete(id) {
|
|
333
310
|
if (!id || typeof id !== "string") {
|
|
334
|
-
throw new
|
|
335
|
-
}
|
|
336
|
-
const url = `${this.client["baseUrl"]}/v1/alerts/${id}`;
|
|
337
|
-
const response = await fetch(url, {
|
|
338
|
-
method: "DELETE",
|
|
339
|
-
headers: {
|
|
340
|
-
Authorization: `Bearer ${this.client["apiKey"]}`,
|
|
341
|
-
"Content-Type": "application/json",
|
|
342
|
-
},
|
|
343
|
-
});
|
|
344
|
-
if (!response.ok) {
|
|
345
|
-
const errorText = await response.text();
|
|
346
|
-
throw new Error(`Failed to delete alert: ${response.status} ${errorText}`);
|
|
311
|
+
throw new ValidationError("Alert ID must be a non-empty string");
|
|
347
312
|
}
|
|
313
|
+
await this.client["request"](`/v1/alerts/${id}`, {}, { method: "DELETE" });
|
|
348
314
|
}
|
|
349
315
|
/**
|
|
350
316
|
* Test an alert
|
|
@@ -369,21 +335,9 @@ export class AlertsResource {
|
|
|
369
335
|
*/
|
|
370
336
|
async test(alertId) {
|
|
371
337
|
if (!alertId || typeof alertId !== "string") {
|
|
372
|
-
throw new
|
|
373
|
-
}
|
|
374
|
-
const url = `${this.client["baseUrl"]}/v1/alerts/${alertId}/test`;
|
|
375
|
-
const response = await fetch(url, {
|
|
376
|
-
method: "POST",
|
|
377
|
-
headers: {
|
|
378
|
-
Authorization: `Bearer ${this.client["apiKey"]}`,
|
|
379
|
-
"Content-Type": "application/json",
|
|
380
|
-
},
|
|
381
|
-
});
|
|
382
|
-
if (!response.ok) {
|
|
383
|
-
const errorText = await response.text();
|
|
384
|
-
throw new Error(`Failed to test alert: ${response.status} ${errorText}`);
|
|
338
|
+
throw new ValidationError("Alert ID must be a non-empty string");
|
|
385
339
|
}
|
|
386
|
-
return
|
|
340
|
+
return this.client["request"](`/v1/alerts/${alertId}/test`, {}, { method: "POST" });
|
|
387
341
|
}
|
|
388
342
|
/**
|
|
389
343
|
* Get available alert triggers
|