oilpriceapi 0.8.2 → 0.9.1
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 +201 -19
- package/dist/cjs/client.js +139 -19
- package/dist/cjs/index.js +17 -3
- package/dist/cjs/resources/analytics.js +99 -137
- package/dist/cjs/resources/bunker-fuels.js +37 -23
- package/dist/cjs/resources/data-sources.js +13 -12
- package/dist/cjs/resources/ei/frac-focus.js +16 -6
- package/dist/cjs/resources/ei/well-permits.js +18 -6
- package/dist/cjs/resources/forecasts.js +11 -5
- package/dist/cjs/resources/futures.js +244 -16
- package/dist/cjs/resources/indicators.js +79 -0
- package/dist/cjs/resources/raw.js +128 -0
- package/dist/cjs/resources/rig-counts.js +5 -2
- package/dist/cjs/resources/spreads.js +105 -0
- package/dist/cjs/resources/storage.js +5 -5
- package/dist/cjs/resources/streaming.js +350 -0
- package/dist/cjs/resources/webhooks.js +3 -14
- package/dist/cjs/version.js +1 -1
- package/dist/client.d.ts +97 -1
- package/dist/client.js +139 -19
- package/dist/index.d.ts +12 -3
- package/dist/index.js +5 -0
- package/dist/resources/analytics.d.ts +147 -214
- package/dist/resources/analytics.js +99 -137
- package/dist/resources/bunker-fuels.d.ts +35 -12
- package/dist/resources/bunker-fuels.js +37 -23
- package/dist/resources/data-sources.d.ts +31 -31
- package/dist/resources/data-sources.js +13 -12
- package/dist/resources/ei/frac-focus.d.ts +23 -9
- package/dist/resources/ei/frac-focus.js +16 -6
- package/dist/resources/ei/well-permits.d.ts +25 -9
- package/dist/resources/ei/well-permits.js +18 -6
- package/dist/resources/forecasts.d.ts +4 -1
- package/dist/resources/forecasts.js +11 -5
- package/dist/resources/futures.d.ts +287 -33
- package/dist/resources/futures.js +241 -15
- 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 +5 -5
- package/dist/resources/streaming.d.ts +272 -0
- package/dist/resources/streaming.js +342 -0
- package/dist/resources/webhooks.d.ts +37 -23
- package/dist/resources/webhooks.js +3 -14
- package/dist/types.d.ts +41 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -1
package/dist/client.js
CHANGED
|
@@ -14,6 +14,10 @@ import { EnergyIntelligenceResource } from "./resources/ei/index.js";
|
|
|
14
14
|
import { WebhooksResource } from "./resources/webhooks.js";
|
|
15
15
|
import { DataSourcesResource } from "./resources/data-sources.js";
|
|
16
16
|
import { SDK_VERSION, SDK_NAME, buildUserAgent } from "./version.js";
|
|
17
|
+
import { SpreadsResource } from "./resources/spreads.js";
|
|
18
|
+
import { IndicatorsResource } from "./resources/indicators.js";
|
|
19
|
+
import { RawResource } from "./resources/raw.js";
|
|
20
|
+
import { StreamingResource } from "./resources/streaming.js";
|
|
17
21
|
/**
|
|
18
22
|
* Official Node.js client for Oil Price API
|
|
19
23
|
*
|
|
@@ -69,6 +73,10 @@ export class OilPriceAPI {
|
|
|
69
73
|
this.ei = new EnergyIntelligenceResource(this);
|
|
70
74
|
this.webhooks = new WebhooksResource(this);
|
|
71
75
|
this.dataSources = new DataSourcesResource(this);
|
|
76
|
+
this.spreads = new SpreadsResource(this);
|
|
77
|
+
this.indicators = new IndicatorsResource(this);
|
|
78
|
+
this.raw = new RawResource(this);
|
|
79
|
+
this.stream = new StreamingResource(this);
|
|
72
80
|
}
|
|
73
81
|
/**
|
|
74
82
|
* Log debug messages if debug mode is enabled
|
|
@@ -122,12 +130,51 @@ export class OilPriceAPI {
|
|
|
122
130
|
// Don't retry on client errors (4xx except 429)
|
|
123
131
|
return false;
|
|
124
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Shape a parsed JSON response body into the value returned to callers.
|
|
135
|
+
*
|
|
136
|
+
* Centralizes the response-structure handling so that both {@link request}
|
|
137
|
+
* and {@link requestRaw} return identical data. Handles the latest/historical
|
|
138
|
+
* envelope shapes as well as the generic `{ data }` fallback used by resource
|
|
139
|
+
* mutations, alerts, webhooks, etc.
|
|
140
|
+
*/
|
|
141
|
+
shapeResponseData(responseData) {
|
|
142
|
+
// Handle different response structures
|
|
143
|
+
// Latest endpoint: { status, data: { price, ... } }
|
|
144
|
+
// Historical endpoint: { status, data: { prices: [...] } }
|
|
145
|
+
if (responseData.status === "success" && responseData.data) {
|
|
146
|
+
if (responseData.data.prices) {
|
|
147
|
+
// Historical endpoint - return prices array
|
|
148
|
+
this.log(`Returning ${responseData.data.prices.length} prices`);
|
|
149
|
+
return responseData.data.prices;
|
|
150
|
+
}
|
|
151
|
+
else if (responseData.data.price !== undefined) {
|
|
152
|
+
// Latest endpoint - wrap single price in array
|
|
153
|
+
this.log("Returning single price (wrapped in array)");
|
|
154
|
+
return [responseData.data];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Fallback - return data as-is (used by resource mutations, alerts, webhooks, etc.)
|
|
158
|
+
this.log("Returning data as-is");
|
|
159
|
+
return (responseData.data !== undefined ? responseData.data : responseData);
|
|
160
|
+
}
|
|
125
161
|
/**
|
|
126
162
|
* Internal method to make HTTP requests with retry and timeout.
|
|
127
163
|
* Supports all HTTP methods (GET, POST, PATCH, DELETE) with consistent
|
|
128
164
|
* retry logic, timeout handling, and typed error responses.
|
|
129
165
|
*/
|
|
130
166
|
async request(endpoint, params, options) {
|
|
167
|
+
const { data } = await this.requestRaw(endpoint, params, options);
|
|
168
|
+
return data;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Internal method identical to {@link request} but returns the underlying
|
|
172
|
+
* HTTP status and headers alongside the parsed data.
|
|
173
|
+
*
|
|
174
|
+
* Used by the public {@link raw} accessor to expose response metadata
|
|
175
|
+
* (issue #7) without changing the return shape of existing methods.
|
|
176
|
+
*/
|
|
177
|
+
async requestRaw(endpoint, params, options) {
|
|
131
178
|
// Build URL with query parameters
|
|
132
179
|
const url = new URL(`${this.baseUrl}${endpoint}`);
|
|
133
180
|
if (params) {
|
|
@@ -218,7 +265,11 @@ export class OilPriceAPI {
|
|
|
218
265
|
const responseText = await response.text();
|
|
219
266
|
if (!responseText) {
|
|
220
267
|
this.log("Empty response body");
|
|
221
|
-
return {
|
|
268
|
+
return {
|
|
269
|
+
data: {},
|
|
270
|
+
status: response.status,
|
|
271
|
+
headers: response.headers,
|
|
272
|
+
};
|
|
222
273
|
}
|
|
223
274
|
// Parse successful response
|
|
224
275
|
const responseData = JSON.parse(responseText);
|
|
@@ -226,24 +277,11 @@ export class OilPriceAPI {
|
|
|
226
277
|
status: responseData.status,
|
|
227
278
|
hasData: !!responseData.data,
|
|
228
279
|
});
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
// Historical endpoint - return prices array
|
|
235
|
-
this.log(`Returning ${responseData.data.prices.length} prices`);
|
|
236
|
-
return responseData.data.prices;
|
|
237
|
-
}
|
|
238
|
-
else if (responseData.data.price !== undefined) {
|
|
239
|
-
// Latest endpoint - wrap single price in array
|
|
240
|
-
this.log("Returning single price (wrapped in array)");
|
|
241
|
-
return [responseData.data];
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
// Fallback - return data as-is (used by resource mutations, alerts, webhooks, etc.)
|
|
245
|
-
this.log("Returning data as-is");
|
|
246
|
-
return (responseData.data !== undefined ? responseData.data : responseData);
|
|
280
|
+
return {
|
|
281
|
+
data: this.shapeResponseData(responseData),
|
|
282
|
+
status: response.status,
|
|
283
|
+
headers: response.headers,
|
|
284
|
+
};
|
|
247
285
|
}
|
|
248
286
|
catch (error) {
|
|
249
287
|
// Handle abort (timeout)
|
|
@@ -483,4 +521,86 @@ export class OilPriceAPI {
|
|
|
483
521
|
async getCommodity(code) {
|
|
484
522
|
return this.request(`/v1/commodities/${code}`, {});
|
|
485
523
|
}
|
|
524
|
+
/**
|
|
525
|
+
* Fetch live sample prices from the public, no-auth demo endpoint.
|
|
526
|
+
*
|
|
527
|
+
* Hits `GET /v1/demo/prices` (no API key required) and returns the parsed
|
|
528
|
+
* `{ prices, meta }` envelope. Useful for trying the client without
|
|
529
|
+
* credentials. Subject to the demo rate limit (~20 requests/hour).
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```typescript
|
|
533
|
+
* const demo = await client.getDemoPrices();
|
|
534
|
+
* const brent = demo.prices.find(p => p.code === 'BRENT_CRUDE_USD');
|
|
535
|
+
* console.log(brent?.price);
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
async getDemoPrices() {
|
|
539
|
+
return this.requestDemo("/v1/demo/prices");
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Fetch the catalogue of commodities from the public, no-auth demo endpoint.
|
|
543
|
+
*
|
|
544
|
+
* Hits `GET /v1/demo/commodities` (no API key required) and returns the parsed
|
|
545
|
+
* `{ commodities, meta }` envelope, where `meta.free_commodities` lists the
|
|
546
|
+
* codes available on the free demo tier.
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* ```typescript
|
|
550
|
+
* const demo = await client.getDemoCommodities();
|
|
551
|
+
* console.log(demo.meta.total, demo.meta.free_commodities);
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
async getDemoCommodities() {
|
|
555
|
+
return this.requestDemo("/v1/demo/commodities");
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Minimal fetch for the no-auth demo endpoints.
|
|
559
|
+
*
|
|
560
|
+
* Unlike {@link request}, this does NOT run the latest/historical response
|
|
561
|
+
* shaping (which would strip the `meta` block) and does NOT require an API
|
|
562
|
+
* key — it returns the raw `data` envelope from `{ status, data }`.
|
|
563
|
+
*/
|
|
564
|
+
async requestDemo(endpoint) {
|
|
565
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
566
|
+
this.log(`Demo request: ${url}`);
|
|
567
|
+
const controller = new AbortController();
|
|
568
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
569
|
+
try {
|
|
570
|
+
const response = await fetch(url, {
|
|
571
|
+
method: "GET",
|
|
572
|
+
headers: {
|
|
573
|
+
"Content-Type": "application/json",
|
|
574
|
+
"User-Agent": buildUserAgent(),
|
|
575
|
+
"X-SDK-Name": SDK_NAME,
|
|
576
|
+
"X-SDK-Version": SDK_VERSION,
|
|
577
|
+
},
|
|
578
|
+
signal: controller.signal,
|
|
579
|
+
});
|
|
580
|
+
if (!response.ok) {
|
|
581
|
+
const body = await response.text();
|
|
582
|
+
let message = `HTTP ${response.status}: ${response.statusText}`;
|
|
583
|
+
try {
|
|
584
|
+
const json = JSON.parse(body);
|
|
585
|
+
message = json.message || json.error || message;
|
|
586
|
+
}
|
|
587
|
+
catch {
|
|
588
|
+
// non-JSON error body
|
|
589
|
+
}
|
|
590
|
+
throw new OilPriceAPIError(message, response.status, "HTTP_ERROR");
|
|
591
|
+
}
|
|
592
|
+
const parsed = JSON.parse(await response.text());
|
|
593
|
+
// Demo envelope is { status: "success", data: { ... } }.
|
|
594
|
+
return (parsed.data !== undefined ? parsed.data : parsed);
|
|
595
|
+
}
|
|
596
|
+
catch (error) {
|
|
597
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
598
|
+
throw new TimeoutError("Request timeout", this.timeout);
|
|
599
|
+
}
|
|
600
|
+
throw error;
|
|
601
|
+
}
|
|
602
|
+
finally {
|
|
603
|
+
clearTimeout(timeoutId);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
486
606
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,15 +6,22 @@
|
|
|
6
6
|
* @packageDocumentation
|
|
7
7
|
*/
|
|
8
8
|
export { OilPriceAPI } from "./client.js";
|
|
9
|
+
export type { APIResponse } from "./client.js";
|
|
9
10
|
export { SDK_VERSION, SDK_NAME } from "./version.js";
|
|
10
|
-
export type { OilPriceAPIConfig, RetryStrategy, Price, LatestPricesOptions, HistoricalPricesOptions, HistoricalPeriod, AggregationInterval, Commodity, CommoditiesResponse, CommodityCategory, CategoriesResponse, DataConnectorPrice, DataConnectorOptions, } from "./types.js";
|
|
11
|
+
export type { OilPriceAPIConfig, RetryStrategy, Price, LatestPricesOptions, HistoricalPricesOptions, HistoricalPeriod, AggregationInterval, Commodity, CommoditiesResponse, CommodityCategory, CategoriesResponse, DataConnectorPrice, DataConnectorOptions, DemoPrice, DemoPricesResponse, DemoCommoditiesResponse, } from "./types.js";
|
|
11
12
|
export type { DieselPrice, DieselStation, DieselStationsResponse, GetDieselStationsOptions, } from "./resources/diesel.js";
|
|
12
13
|
export type { PriceAlert, CreateAlertParams, UpdateAlertParams, AlertOperator, } from "./resources/alerts.js";
|
|
13
|
-
export type { FuturesPrice, HistoricalFuturesPrice, HistoricalFuturesOptions, FuturesOHLC, IntradayPrice, IntradayFuturesData, FuturesSpread, FuturesCurvePoint, FuturesCurveData, ContinuousContractPrice, ContinuousFuturesData, } from "./resources/futures.js";
|
|
14
|
+
export type { FuturesPrice, HistoricalFuturesPrice, HistoricalFuturesOptions, FuturesOHLC, IntradayPrice, IntradayFuturesData, FuturesSpread, FuturesCurvePoint, FuturesCurveData, ContinuousContractPrice, ContinuousFuturesData, FuturesSpreadHistoryPoint, FuturesSpreadHistory, FuturesContractFamilySlug, } from "./resources/futures.js";
|
|
15
|
+
export { FUTURES_CONTRACTS, FUTURES_FAMILY_SLUGS, FuturesContractFamily, } from "./resources/futures.js";
|
|
16
|
+
export type { SpreadType, SpreadValue, HistoricalSpreadValue, HistoricalSpreadOptions, } from "./resources/spreads.js";
|
|
17
|
+
export { SpreadsResource } from "./resources/spreads.js";
|
|
18
|
+
export type { IndicatorType, FuelSwitchingIndicator, PriceContextIndicator, StorageAnalyticsIndicator, AnnotationIndicator, CFTCPositioningIndicator, CongressionalTradeIndicator, } from "./resources/indicators.js";
|
|
19
|
+
export { IndicatorsResource } from "./resources/indicators.js";
|
|
20
|
+
export { RawResource } from "./resources/raw.js";
|
|
14
21
|
export type { StorageData, HistoricalStorageData, HistoricalStorageOptions, } from "./resources/storage.js";
|
|
15
22
|
export type { RigCountData, HistoricalRigCountData, HistoricalRigCountOptions, RigCountTrend, RigCountSummary, } from "./resources/rig-counts.js";
|
|
16
23
|
export type { BunkerFuelPrice, PortBunkerPrices, PortPriceComparison, BunkerFuelSpreads, HistoricalBunkerPrice, HistoricalBunkerOptions, } from "./resources/bunker-fuels.js";
|
|
17
|
-
export type { PerformanceMetrics, PerformanceOptions, StatisticalAnalysis, CorrelationAnalysis, TrendAnalysis, SpreadAnalysis,
|
|
24
|
+
export type { PerformanceMetrics, PerformanceOptions, StatisticalAnalysis, CorrelationAnalysis, CorrelationOptions, TrendAnalysis, TrendOptions, SpreadAnalysis, SpreadOptions, ForecastOptions, PriceForecast as AnalyticsPriceForecast, } from "./resources/analytics.js";
|
|
18
25
|
export type { MonthlyForecast, ForecastAccuracy, ArchivedForecast } from "./resources/forecasts.js";
|
|
19
26
|
export type { DataQualitySummary, DataQualityReportMeta, DataQualityReport, } from "./resources/data-quality.js";
|
|
20
27
|
export type { DrillingIntelligenceData, LatestDrillingData, DrillingSummary, DrillingTrend, FracSpreadData, WellPermitData, DUCWellData, CompletionData, WellsDrilledData, BasinDrillingData, } from "./resources/drilling.js";
|
|
@@ -36,6 +43,8 @@ export { DrillingIntelligenceResource } from "./resources/drilling.js";
|
|
|
36
43
|
export { EnergyIntelligenceResource, EIRigCountsResource, EIOilInventoriesResource, EIOPECProductionResource, EIDrillingProductivityResource, EIForecastsResource, EIWellPermitsResource, EIFracFocusResource, } from "./resources/ei/index.js";
|
|
37
44
|
export { WebhooksResource } from "./resources/webhooks.js";
|
|
38
45
|
export { DataSourcesResource } from "./resources/data-sources.js";
|
|
46
|
+
export { StreamingResource, PriceStreamSubscription, ENERGY_PRICES_CHANNEL, } from "./resources/streaming.js";
|
|
47
|
+
export type { StreamPricesOptions, PriceUpdateHandler, StreamMessage, WelcomeMessage, PriceUpdateMessage, RigCountUpdateMessage, StreamedPrice, StreamedPriceMap, } from "./resources/streaming.js";
|
|
39
48
|
/**
|
|
40
49
|
* Standalone webhook signature verification.
|
|
41
50
|
*
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
9
9
|
export { OilPriceAPI } from "./client.js";
|
|
10
10
|
export { SDK_VERSION, SDK_NAME } from "./version.js";
|
|
11
|
+
export { FUTURES_CONTRACTS, FUTURES_FAMILY_SLUGS, FuturesContractFamily, } from "./resources/futures.js";
|
|
12
|
+
export { SpreadsResource } from "./resources/spreads.js";
|
|
13
|
+
export { IndicatorsResource } from "./resources/indicators.js";
|
|
14
|
+
export { RawResource } from "./resources/raw.js";
|
|
11
15
|
export { OilPriceAPIError, AuthenticationError, RateLimitError, NotFoundError, ServerError, ValidationError, TimeoutError, } from "./errors.js";
|
|
12
16
|
export { DieselResource } from "./resources/diesel.js";
|
|
13
17
|
export { AlertsResource } from "./resources/alerts.js";
|
|
@@ -23,6 +27,7 @@ export { DrillingIntelligenceResource } from "./resources/drilling.js";
|
|
|
23
27
|
export { EnergyIntelligenceResource, EIRigCountsResource, EIOilInventoriesResource, EIOPECProductionResource, EIDrillingProductivityResource, EIForecastsResource, EIWellPermitsResource, EIFracFocusResource, } from "./resources/ei/index.js";
|
|
24
28
|
export { WebhooksResource } from "./resources/webhooks.js";
|
|
25
29
|
export { DataSourcesResource } from "./resources/data-sources.js";
|
|
30
|
+
export { StreamingResource, PriceStreamSubscription, ENERGY_PRICES_CHANNEL, } from "./resources/streaming.js";
|
|
26
31
|
/**
|
|
27
32
|
* Standalone webhook signature verification.
|
|
28
33
|
*
|