oilpriceapi 0.5.1 → 0.6.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 CHANGED
@@ -99,6 +99,25 @@ const prices = await client.getHistoricalPrices({
99
99
  console.log(`Got ${prices.length} data points for 2024`);
100
100
  ```
101
101
 
102
+ ### Performance Optimization (New in v0.6.0)
103
+
104
+ For year-long queries, use the `interval` parameter to dramatically improve response times:
105
+
106
+ ```typescript
107
+ // FAST: Daily aggregation returns 365 data points (~1 second)
108
+ const yearlyPrices = await client.getHistoricalPrices({
109
+ period: 'past_year',
110
+ commodity: 'BRENT_CRUDE_USD',
111
+ interval: 'daily' // Options: 'raw', 'hourly', 'daily', 'weekly', 'monthly'
112
+ });
113
+
114
+ console.log(`Got ${yearlyPrices.length} daily averages`);
115
+ // Output: Got 365 daily averages
116
+
117
+ // SLOW: Raw data returns 600k+ points (can take 74+ seconds)
118
+ // Only use 'raw' when you need every individual price point
119
+ ```
120
+
102
121
  ### Get Diesel Prices (New in v0.4.0)
103
122
 
104
123
  #### Get State Average Diesel Price
@@ -454,6 +473,9 @@ Get historical prices for a time period.
454
473
  - `options.commodity` (string, optional) - Filter by commodity code
455
474
  - `options.startDate` (string, optional) - Start date in ISO 8601 format (YYYY-MM-DD)
456
475
  - `options.endDate` (string, optional) - End date in ISO 8601 format (YYYY-MM-DD)
476
+ - `options.interval` (string, optional) - Aggregation interval: "raw", "hourly", "daily", "weekly", "monthly". **Performance tip:** Use "daily" for year-long queries (365 points vs 600k+ raw points)
477
+ - `options.perPage` (number, optional) - Results per page (default: 100, max: 1000)
478
+ - `options.page` (number, optional) - Page number for pagination (default: 1)
457
479
 
458
480
  **Returns:** `Promise<Price[]>`
459
481
 
package/dist/client.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { OilPriceAPIError, AuthenticationError, RateLimitError, NotFoundError, ServerError, TimeoutError, } from './errors.js';
2
2
  import { DieselResource } from './resources/diesel.js';
3
3
  import { AlertsResource } from './resources/alerts.js';
4
+ import { SDK_VERSION, SDK_NAME, buildUserAgent } from './version.js';
4
5
  /**
5
6
  * Official Node.js client for Oil Price API
6
7
  *
@@ -126,9 +127,9 @@ export class OilPriceAPI {
126
127
  headers: {
127
128
  'Authorization': `Bearer ${this.apiKey}`,
128
129
  'Content-Type': 'application/json',
129
- 'User-Agent': 'oilpriceapi-node/0.5.1 node/' + process.version,
130
- 'X-Api-Client': 'oilpriceapi-node',
131
- 'X-Client-Version': '0.5.1',
130
+ 'User-Agent': buildUserAgent(),
131
+ 'X-Api-Client': SDK_NAME,
132
+ 'X-Client-Version': SDK_VERSION,
132
133
  },
133
134
  signal: controller.signal,
134
135
  });
@@ -293,7 +294,28 @@ export class OilPriceAPI {
293
294
  if (options?.endDate) {
294
295
  params.end_date = options.endDate;
295
296
  }
296
- return this.request('/v1/prices', params);
297
+ // PERFORMANCE FIX (December 24, 2025):
298
+ // Pass interval parameter to enable aggregated queries
299
+ // This reduces response times from 74s to <1s for year-long queries
300
+ // by returning 365 daily points instead of 600k+ raw points
301
+ if (options?.interval) {
302
+ params.interval = options.interval;
303
+ }
304
+ // Pagination parameters
305
+ if (options?.perPage !== undefined) {
306
+ params.per_page = options.perPage.toString();
307
+ }
308
+ if (options?.page !== undefined) {
309
+ params.page = options.page.toString();
310
+ }
311
+ // CRITICAL FIX (December 17, 2025):
312
+ // Use /v1/prices/past_year endpoint instead of /v1/prices
313
+ // The /v1/prices endpoint does NOT correctly handle start_date/end_date parameters
314
+ // This was the same bug that affected the Python SDK (fixed in v1.4.4)
315
+ // Issue: SDK was returning wrong dates for historical queries
316
+ // Root Cause: Backend has_scope :by_period not working on /v1/prices
317
+ // Solution: Use /v1/prices/past_year which uses direct WHERE clauses
318
+ return this.request('/v1/prices/past_year', params);
297
319
  }
298
320
  /**
299
321
  * Get metadata for all supported commodities
package/dist/index.d.ts CHANGED
@@ -6,7 +6,8 @@
6
6
  * @packageDocumentation
7
7
  */
8
8
  export { OilPriceAPI } from './client.js';
9
- export type { OilPriceAPIConfig, RetryStrategy, Price, LatestPricesOptions, HistoricalPricesOptions, HistoricalPeriod, Commodity, CommoditiesResponse, CommodityCategory, CategoriesResponse, } from './types.js';
9
+ export { SDK_VERSION, SDK_NAME } from './version.js';
10
+ export type { OilPriceAPIConfig, RetryStrategy, Price, LatestPricesOptions, HistoricalPricesOptions, HistoricalPeriod, AggregationInterval, Commodity, CommoditiesResponse, CommodityCategory, CategoriesResponse, } from './types.js';
10
11
  export type { DieselPrice, DieselStation, DieselStationsResponse, GetDieselStationsOptions, } from './resources/diesel.js';
11
12
  export type { PriceAlert, CreateAlertParams, UpdateAlertParams, AlertOperator, WebhookTestResponse, } from './resources/alerts.js';
12
13
  export { OilPriceAPIError, AuthenticationError, RateLimitError, NotFoundError, ServerError, TimeoutError, } from './errors.js';
package/dist/index.js CHANGED
@@ -6,4 +6,5 @@
6
6
  * @packageDocumentation
7
7
  */
8
8
  export { OilPriceAPI } from './client.js';
9
+ export { SDK_VERSION, SDK_NAME } from './version.js';
9
10
  export { OilPriceAPIError, AuthenticationError, RateLimitError, NotFoundError, ServerError, TimeoutError, } from './errors.js';
package/dist/types.d.ts CHANGED
@@ -120,6 +120,14 @@ export interface LatestPricesOptions {
120
120
  * Time period options for historical data
121
121
  */
122
122
  export type HistoricalPeriod = 'past_week' | 'past_month' | 'past_year';
123
+ /**
124
+ * Aggregation interval for historical data
125
+ *
126
+ * PERFORMANCE TIP: Use 'daily' or 'weekly' for year-long queries to reduce
127
+ * response times from 74s to <1s. The 'raw' option returns individual price
128
+ * points which can be 600k+ records for a year of BRENT data.
129
+ */
130
+ export type AggregationInterval = 'raw' | 'hourly' | 'daily' | 'weekly' | 'monthly';
123
131
  /**
124
132
  * Options for fetching historical prices
125
133
  */
@@ -142,6 +150,28 @@ export interface HistoricalPricesOptions {
142
150
  * Example: "2024-12-31"
143
151
  */
144
152
  endDate?: string;
153
+ /**
154
+ * Aggregation interval for the data
155
+ *
156
+ * PERFORMANCE: For year-long queries, use 'daily' (365 points) or 'weekly' (52 points)
157
+ * instead of 'raw' (600k+ points for BRENT) to dramatically improve response times.
158
+ *
159
+ * @default API default (raw for short periods, may be aggregated for long periods)
160
+ */
161
+ interval?: AggregationInterval;
162
+ /**
163
+ * Number of results per page
164
+ *
165
+ * @default 100 (API default)
166
+ * @max 1000
167
+ */
168
+ perPage?: number;
169
+ /**
170
+ * Page number for pagination (1-indexed)
171
+ *
172
+ * @default 1
173
+ */
174
+ page?: number;
145
175
  }
146
176
  /**
147
177
  * Represents commodity metadata
@@ -0,0 +1,18 @@
1
+ /**
2
+ * SDK Version - centralized to ensure consistency across all headers
3
+ *
4
+ * This version must be updated when publishing a new release.
5
+ * It's used in:
6
+ * - User-Agent header: oilpriceapi-node/{version}
7
+ * - X-Client-Version header
8
+ * - Package.json (should match)
9
+ */
10
+ export declare const SDK_VERSION = "0.6.0";
11
+ /**
12
+ * SDK identifier used in User-Agent and X-Api-Client headers
13
+ */
14
+ export declare const SDK_NAME = "oilpriceapi-node";
15
+ /**
16
+ * Build the full User-Agent string
17
+ */
18
+ export declare function buildUserAgent(): string;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * SDK Version - centralized to ensure consistency across all headers
3
+ *
4
+ * This version must be updated when publishing a new release.
5
+ * It's used in:
6
+ * - User-Agent header: oilpriceapi-node/{version}
7
+ * - X-Client-Version header
8
+ * - Package.json (should match)
9
+ */
10
+ export const SDK_VERSION = '0.6.0';
11
+ /**
12
+ * SDK identifier used in User-Agent and X-Api-Client headers
13
+ */
14
+ export const SDK_NAME = 'oilpriceapi-node';
15
+ /**
16
+ * Build the full User-Agent string
17
+ */
18
+ export function buildUserAgent() {
19
+ return `${SDK_NAME}/${SDK_VERSION} node/${process.version}`;
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oilpriceapi",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "Official Node.js SDK for Oil Price API - Real-time and historical oil & commodity prices",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -55,6 +55,7 @@
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/node": "^20.10.0",
58
+ "@vitest/coverage-v8": "^1.0.0",
58
59
  "typescript": "^5.3.0",
59
60
  "vitest": "^1.0.0"
60
61
  }