import type { OilPriceAPIConfig, Price, LatestPricesOptions, HistoricalPricesOptions, Commodity, CommoditiesResponse, CategoriesResponse, DataConnectorPrice, DataConnectorOptions, DemoPricesResponse, DemoCommoditiesResponse } from "./types.js"; import type { MarketBrief, MarketBriefOptions } from "./resources/market-brief.js"; import { DieselResource } from "./resources/diesel.js"; import { AlertsResource } from "./resources/alerts.js"; import { CommoditiesResource } from "./resources/commodities.js"; import { FuturesResource } from "./resources/futures.js"; import { StorageResource } from "./resources/storage.js"; import { RigCountsResource } from "./resources/rig-counts.js"; import { BunkerFuelsResource } from "./resources/bunker-fuels.js"; import { AnalyticsResource } from "./resources/analytics.js"; import { ForecastsResource } from "./resources/forecasts.js"; import { DataQualityResource } from "./resources/data-quality.js"; import { DrillingIntelligenceResource } from "./resources/drilling.js"; import { EnergyIntelligenceResource } from "./resources/ei/index.js"; import { WebhooksResource } from "./resources/webhooks.js"; import { DataSourcesResource } from "./resources/data-sources.js"; import { SpreadsResource } from "./resources/spreads.js"; import { IndicatorsResource } from "./resources/indicators.js"; import { RawResource } from "./resources/raw.js"; import { StreamingResource } from "./resources/streaming.js"; import { SubscriptionsResource } from "./resources/subscriptions.js"; import { WellProductionResource } from "./resources/well-production.js"; /** * Raw HTTP response wrapper. * * Returned by {@link OilPriceAPI.raw} accessors to expose the underlying * HTTP status code and response headers alongside the parsed data. * * @typeParam T - The parsed response body type. */ export interface APIResponse { /** Parsed response data (same shape the non-raw method would return). */ data: T; /** HTTP status code (e.g., 200, 201). */ status: number; /** Response headers. */ headers: Headers; } /** * Official Node.js client for Oil Price API * * @example * ```typescript * import { OilPriceAPI } from 'oilpriceapi'; * * const client = new OilPriceAPI({ * apiKey: 'your_api_key_here', * retries: 3, * timeout: 30000 * }); * * // Get latest prices * const prices = await client.getLatestPrices(); * * // Get WTI price only * const wti = await client.getLatestPrices({ commodity: 'WTI_USD' }); * * // Get historical data * const historical = await client.getHistoricalPrices({ * period: 'past_week', * commodity: 'BRENT_CRUDE_USD' * }); * ``` */ export declare class OilPriceAPI { private apiKey; private baseUrl; private retries; private retryDelay; private retryStrategy; private timeout; private debug; private appUrl?; private appName?; /** * Diesel prices resource (state averages + station-level pricing) */ readonly diesel: DieselResource; /** * Price alerts resource (create, manage, and monitor alerts) */ readonly alerts: AlertsResource; /** * Commodities resource (metadata and categories) */ readonly commodities: CommoditiesResource; /** * Futures resource (contracts, OHLC, curves, spreads) */ readonly futures: FuturesResource; /** * Storage resource (inventory levels, Cushing, SPR) */ readonly storage: StorageResource; /** * Rig counts resource (Baker Hughes rig count data) */ readonly rigCounts: RigCountsResource; /** * Bunker fuels resource (marine fuel prices at ports) */ readonly bunkerFuels: BunkerFuelsResource; /** * Analytics resource (performance, statistics, correlations) */ readonly analytics: AnalyticsResource; /** * Forecasts resource (EIA/IEA forecasts and accuracy) */ readonly forecasts: ForecastsResource; /** * Data quality resource (quality metrics and reports) */ readonly dataQuality: DataQualityResource; /** * Drilling intelligence resource (US onshore drilling activity) */ readonly drilling: DrillingIntelligenceResource; /** * Energy intelligence resource (comprehensive market intelligence) */ readonly ei: EnergyIntelligenceResource; /** * Webhooks resource (webhook endpoint management) */ readonly webhooks: WebhooksResource; /** * Data sources resource (BYOS - Bring Your Own Source) */ readonly dataSources: DataSourcesResource; /** * Spreads resource (crack, basis, curve structure, margin, physical premium) */ readonly spreads: SpreadsResource; /** * Indicators resource (fuel switching, price context, storage analytics, * annotations, CFTC positioning, congressional trades) */ readonly indicators: IndicatorsResource; /** * Raw-response accessor. * * Mirrors the top-level price/commodity methods but returns the underlying * HTTP status and headers alongside the parsed data via {@link APIResponse}. */ readonly raw: RawResource; /** * Price streaming resource (WebSocket / ActionCable). * * Streaming availability depends on account entitlement. Review current * access at https://www.oilpriceapi.com/pricing. */ readonly stream: StreamingResource; /** * Agent subscriptions ("watches") resource — persistent recurring watches * over commodity codes plus an event poll endpoint (#3245 Phase 2). */ readonly subscriptions: SubscriptionsResource; /** * Well production resource (US national/state/well-level oil & gas * production plus permit-to-production cycle-time analytics). * * Requires the drilling-intelligence tier. Well-level coverage is beta — * limited to states collected from regulatory agencies so far. */ readonly wellProduction: WellProductionResource; constructor(config?: OilPriceAPIConfig); private requireApiKey; /** * Log debug messages if debug mode is enabled */ private log; /** * Calculate delay for retry based on strategy */ private calculateRetryDelay; /** * Sleep for specified milliseconds */ private sleep; /** * Determine if error is retryable */ private isRetryable; /** * Shape a parsed JSON response body into the value returned to callers. * * Centralizes the response-structure handling so that both {@link request} * and {@link requestRaw} return identical data. Handles the latest/historical * envelope shapes as well as the generic `{ data }` fallback used by resource * mutations, alerts, webhooks, etc. */ private shapeResponseData; /** * Internal method to make HTTP requests with retry and timeout. * Supports all HTTP methods (GET, POST, PATCH, DELETE) with consistent * retry logic, timeout handling, and typed error responses. */ private request; /** * Internal method identical to {@link request} but returns the underlying * HTTP status and headers alongside the parsed data. * * Used by the public {@link raw} accessor to expose response metadata * (issue #7) without changing the return shape of existing methods. */ private requestRaw; /** * Get the latest prices for all commodities or a specific commodity * * @param options - Optional filters * @returns Array of price objects * * @example * ```typescript * // Get all latest prices * const allPrices = await client.getLatestPrices(); * * // Get WTI price only * const wti = await client.getLatestPrices({ commodity: 'WTI_USD' }); * ``` */ getLatestPrices(options?: LatestPricesOptions): Promise; /** * Get historical prices for a time period * * @param options - Time period and filter options * @returns Array of historical price objects * * @example * ```typescript * // Get past week of WTI prices * const weekPrices = await client.getHistoricalPrices({ * period: 'past_week', * commodity: 'WTI_USD' * }); * * // Get custom date range * const customPrices = await client.getHistoricalPrices({ * startDate: '2024-01-01', * endDate: '2024-12-31', * commodity: 'BRENT_CRUDE_USD' * }); * ``` */ getHistoricalPrices(options?: HistoricalPricesOptions): Promise; /** * Paginate through historical prices automatically. * * Returns an async generator that yields pages of prices, fetching * the next page only when needed. Avoids loading all data into memory. * * @param options - Same options as getHistoricalPrices, plus perPage (default: 100) * * @example * ```typescript * // Iterate through all pages * for await (const page of client.paginateHistoricalPrices({ * commodity: 'BRENT_CRUDE_USD', * startDate: '2024-01-01', * endDate: '2024-12-31', * perPage: 100, * })) { * console.log(`Got ${page.length} prices`); * // Process each page... * } * * // Or collect all prices * const allPrices: Price[] = []; * for await (const page of client.paginateHistoricalPrices({ commodity: 'WTI_USD' })) { * allPrices.push(...page); * } * ``` */ paginateHistoricalPrices(options?: HistoricalPricesOptions): AsyncGenerator; /** * Get prices from your connected data sources (BYOS) * * Requires Data Connector feature enabled on your organization. * * @example * ```typescript * // Get all connected prices * const prices = await client.getDataConnectorPrices(); * * // Filter by fuel type * const vlsfo = await client.getDataConnectorPrices({ fuelType: 'VLSFO' }); * * // Filter by port * const singapore = await client.getDataConnectorPrices({ port: 'SINGAPORE' }); * ``` */ getDataConnectorPrices(options?: DataConnectorOptions): Promise; /** * Get metadata for all supported commodities * * @returns Object containing array of commodities * * @example * ```typescript * const response = await client.getCommodities(); * console.log(response.commodities); // Array of commodity objects * ``` */ getCommodities(): Promise; /** * Get all commodity categories with their commodities * * @returns Object with category keys mapped to category objects * * @example * ```typescript * const categories = await client.getCommodityCategories(); * console.log(categories.oil.name); // "Oil" * console.log(categories.oil.commodities.length); // 11 * ``` */ getCommodityCategories(): Promise; /** * Get metadata for a specific commodity by code * * @param code - Commodity code (e.g., "WTI_USD", "BRENT_CRUDE_USD") * @returns Commodity metadata object * * @example * ```typescript * const commodity = await client.getCommodity('WTI_USD'); * console.log(commodity.name); // "WTI Crude Oil" * ``` */ getCommodity(code: string): Promise; /** * Get a multi-commodity market brief (OilPriceAPI #3245 Phase 1a). * * Returns a structured summary (latest price, 24h change, freshness, and a * 1-month forecast band) for each requested commodity, optionally with a * natural-language narrative. Counts as a single request against your quota, * like `/v1/prices/batch`. The per-tier cap on `codes` is enforced server-side. * * @param codes - Commodity codes (e.g. ["BRENT_CRUDE_USD", "WTI_USD"]). Shorthand * codes like "WTI"/"BRENT" are accepted and resolved server-side. * @param options - `{ narrative }` to request the natural-language summary. * @returns The structured (and optional narrative) market brief. * * @throws {ValidationError} If `codes` is empty. * * @example * ```typescript * const brief = await client.getMarketBrief(['BRENT_CRUDE_USD', 'WTI_USD']); * for (const c of brief.commodities) { * console.log(`${c.name}: $${c.price} (${c.change_24h_pct}%)`); * } * * // With narrative * const withText = await client.getMarketBrief(['BRENT_CRUDE_USD'], { narrative: true }); * console.log(withText.narrative); * ``` */ getMarketBrief(codes: string[], options?: MarketBriefOptions): Promise; /** * Fetch live sample prices from the public, no-auth demo endpoint. * * Hits `GET /v1/demo/prices` (no API key required) and returns the parsed * `{ prices, meta }` envelope. Useful for trying the client without * credentials. Current limits are returned by the endpoint. * * @example * ```typescript * const demo = await client.getDemoPrices(); * const brent = demo.prices.find(p => p.code === 'BRENT_CRUDE_USD'); * console.log(brent?.price); * ``` */ getDemoPrices(): Promise; /** * Fetch the catalogue of commodities from the public, no-auth demo endpoint. * * Hits `GET /v1/demo/commodities` (no API key required) and returns the parsed * `{ commodities, meta }` envelope, where `meta.free_commodities` lists the * codes currently advertised by the demo endpoint. * * @example * ```typescript * const demo = await client.getDemoCommodities(); * console.log(demo.meta.total, demo.meta.free_commodities); * ``` */ getDemoCommodities(): Promise; /** * Minimal fetch for the no-auth demo endpoints. * * Unlike {@link request}, this does NOT run the latest/historical response * shaping (which would strip the `meta` block) and does NOT require an API * key — it returns the raw `data` envelope from `{ status, data }`. */ private requestDemo; }