oilpriceapi 0.7.0 → 0.8.2

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.
Files changed (60) hide show
  1. package/README.md +43 -11
  2. package/dist/cjs/client.js +490 -0
  3. package/dist/cjs/errors.js +80 -0
  4. package/dist/cjs/index.js +82 -0
  5. package/dist/cjs/package.json +1 -0
  6. package/dist/cjs/resources/alerts.js +387 -0
  7. package/dist/cjs/resources/analytics.js +226 -0
  8. package/dist/cjs/resources/bunker-fuels.js +196 -0
  9. package/dist/cjs/resources/commodities.js +115 -0
  10. package/dist/cjs/resources/data-quality.js +144 -0
  11. package/dist/cjs/resources/data-sources.js +297 -0
  12. package/dist/cjs/resources/diesel.js +119 -0
  13. package/dist/cjs/resources/drilling.js +269 -0
  14. package/dist/cjs/resources/ei/drilling-productivity.js +108 -0
  15. package/dist/cjs/resources/ei/forecasts.js +106 -0
  16. package/dist/cjs/resources/ei/frac-focus.js +155 -0
  17. package/dist/cjs/resources/ei/index.js +98 -0
  18. package/dist/cjs/resources/ei/oil-inventories.js +97 -0
  19. package/dist/cjs/resources/ei/opec-production.js +97 -0
  20. package/dist/cjs/resources/ei/rig-counts.js +93 -0
  21. package/dist/cjs/resources/ei/well-permits.js +124 -0
  22. package/dist/cjs/resources/forecasts.js +162 -0
  23. package/dist/cjs/resources/futures.js +233 -0
  24. package/dist/cjs/resources/rig-counts.js +161 -0
  25. package/dist/cjs/resources/storage.js +166 -0
  26. package/dist/cjs/resources/webhooks.js +294 -0
  27. package/dist/cjs/types.js +2 -0
  28. package/dist/cjs/version.js +24 -0
  29. package/dist/client.d.ts +33 -2
  30. package/dist/client.js +70 -14
  31. package/dist/errors.d.ts +6 -0
  32. package/dist/errors.js +25 -16
  33. package/dist/index.d.ts +16 -2
  34. package/dist/index.js +24 -1
  35. package/dist/resources/alerts.js +31 -77
  36. package/dist/resources/analytics.js +8 -7
  37. package/dist/resources/bunker-fuels.js +5 -4
  38. package/dist/resources/commodities.js +2 -1
  39. package/dist/resources/data-quality.js +2 -1
  40. package/dist/resources/data-sources.js +21 -77
  41. package/dist/resources/diesel.d.ts +1 -1
  42. package/dist/resources/diesel.js +9 -38
  43. package/dist/resources/drilling.js +2 -1
  44. package/dist/resources/ei/drilling-productivity.js +2 -1
  45. package/dist/resources/ei/forecasts.js +2 -1
  46. package/dist/resources/ei/frac-focus.js +4 -3
  47. package/dist/resources/ei/index.js +2 -1
  48. package/dist/resources/ei/oil-inventories.js +2 -1
  49. package/dist/resources/ei/opec-production.js +2 -1
  50. package/dist/resources/ei/rig-counts.js +2 -1
  51. package/dist/resources/ei/well-permits.js +2 -1
  52. package/dist/resources/forecasts.js +2 -1
  53. package/dist/resources/futures.js +9 -8
  54. package/dist/resources/storage.js +2 -1
  55. package/dist/resources/webhooks.d.ts +36 -0
  56. package/dist/resources/webhooks.js +60 -67
  57. package/dist/types.d.ts +2 -1
  58. package/dist/version.d.ts +1 -1
  59. package/dist/version.js +2 -2
  60. package/package.json +15 -6
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ /**
3
+ * Rig Counts Resource
4
+ *
5
+ * Access Baker Hughes rig count data including current counts, historical trends,
6
+ * and breakdowns by basin, state, and rig type.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.RigCountsResource = void 0;
10
+ /**
11
+ * Rig Counts Resource
12
+ *
13
+ * Access Baker Hughes rig count data including current counts, historical data,
14
+ * trends, and summaries.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { OilPriceAPI } from 'oilpriceapi';
19
+ *
20
+ * const client = new OilPriceAPI({ apiKey: 'your_key' });
21
+ *
22
+ * // Get latest rig count
23
+ * const latest = await client.rigCounts.latest();
24
+ * console.log(`Total rigs: ${latest.total}`);
25
+ * console.log(`Oil: ${latest.oil}, Gas: ${latest.gas}`);
26
+ *
27
+ * // Get summary with changes
28
+ * const summary = await client.rigCounts.summary();
29
+ * console.log(`Week-over-week: ${summary.week_change}`);
30
+ * console.log(`Year-over-year: ${summary.year_change}`);
31
+ * ```
32
+ */
33
+ class RigCountsResource {
34
+ constructor(client) {
35
+ this.client = client;
36
+ }
37
+ /**
38
+ * Get latest rig count data
39
+ *
40
+ * Returns the most recent Baker Hughes rig count.
41
+ *
42
+ * @returns Latest rig count data
43
+ *
44
+ * @throws {OilPriceAPIError} If API request fails
45
+ * @throws {AuthenticationError} If API key is invalid
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const latest = await client.rigCounts.latest();
50
+ * console.log(`Total rigs: ${latest.total}`);
51
+ * console.log(`Oil rigs: ${latest.oil}`);
52
+ * console.log(`Gas rigs: ${latest.gas}`);
53
+ * console.log(`Change: ${latest.change}`);
54
+ * ```
55
+ */
56
+ async latest() {
57
+ return this.client["request"]("/v1/rig-counts/latest", {});
58
+ }
59
+ /**
60
+ * Get current rig count data
61
+ *
62
+ * Alias for latest(). Returns the most recent Baker Hughes rig count.
63
+ *
64
+ * @returns Current rig count data
65
+ *
66
+ * @throws {OilPriceAPIError} If API request fails
67
+ * @throws {AuthenticationError} If API key is invalid
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const current = await client.rigCounts.current();
72
+ * console.log(`Total rigs: ${current.total}`);
73
+ * ```
74
+ */
75
+ async current() {
76
+ return this.client["request"]("/v1/rig-counts/current", {});
77
+ }
78
+ /**
79
+ * Get historical rig count data
80
+ *
81
+ * Returns time series of rig counts.
82
+ *
83
+ * @param options - Date range filters
84
+ * @returns Array of historical rig count data
85
+ *
86
+ * @throws {OilPriceAPIError} If API request fails
87
+ * @throws {AuthenticationError} If API key is invalid
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const history = await client.rigCounts.historical({
92
+ * startDate: '2024-01-01',
93
+ * endDate: '2024-12-31'
94
+ * });
95
+ *
96
+ * history.forEach(point => {
97
+ * console.log(`${point.date}: ${point.total} rigs (${point.oil} oil, ${point.gas} gas)`);
98
+ * });
99
+ * ```
100
+ */
101
+ async historical(options) {
102
+ const params = {};
103
+ if (options?.startDate)
104
+ params.start_date = options.startDate;
105
+ if (options?.endDate)
106
+ params.end_date = options.endDate;
107
+ const response = await this.client["request"]("/v1/rig-counts/historical", params);
108
+ return Array.isArray(response) ? response : response.data;
109
+ }
110
+ /**
111
+ * Get rig count trend analysis
112
+ *
113
+ * Returns trend analysis for a specified time period.
114
+ *
115
+ * @param period - Time period (e.g., "week", "month", "quarter", "year")
116
+ * @returns Trend analysis data
117
+ *
118
+ * @throws {OilPriceAPIError} If API request fails
119
+ * @throws {AuthenticationError} If API key is invalid
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * const monthlyTrend = await client.rigCounts.trends('month');
124
+ * console.log(`Monthly average: ${monthlyTrend.average}`);
125
+ * console.log(`Trend: ${monthlyTrend.trend}`);
126
+ * console.log(`Change: ${monthlyTrend.change_percent}%`);
127
+ * ```
128
+ */
129
+ async trends(period) {
130
+ const params = {};
131
+ if (period)
132
+ params.period = period;
133
+ return this.client["request"]("/v1/rig-counts/trends", params);
134
+ }
135
+ /**
136
+ * Get rig count summary
137
+ *
138
+ * Returns comprehensive summary including current count and changes
139
+ * across multiple time periods.
140
+ *
141
+ * @returns Rig count summary
142
+ *
143
+ * @throws {OilPriceAPIError} If API request fails
144
+ * @throws {AuthenticationError} If API key is invalid
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const summary = await client.rigCounts.summary();
149
+ * console.log(`Current: ${summary.current}`);
150
+ * console.log(`Week-over-week: ${summary.week_change}`);
151
+ * console.log(`Month-over-month: ${summary.month_change}`);
152
+ * console.log(`Year-over-year: ${summary.year_change}`);
153
+ * console.log(`Oil rigs: ${summary.breakdown.oil}`);
154
+ * console.log(`Gas rigs: ${summary.breakdown.gas}`);
155
+ * ```
156
+ */
157
+ async summary() {
158
+ return this.client["request"]("/v1/rig-counts/summary", {});
159
+ }
160
+ }
161
+ exports.RigCountsResource = RigCountsResource;
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ /**
3
+ * Storage Resource
4
+ *
5
+ * Access crude oil storage data including total US inventory, Cushing hub levels,
6
+ * Strategic Petroleum Reserve (SPR), and regional breakdowns.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.StorageResource = void 0;
10
+ const errors_js_1 = require("../errors.js");
11
+ /**
12
+ * Storage Resource
13
+ *
14
+ * Access crude oil storage data for US inventory levels, Cushing hub,
15
+ * Strategic Petroleum Reserve, and regional breakdowns.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { OilPriceAPI } from 'oilpriceapi';
20
+ *
21
+ * const client = new OilPriceAPI({ apiKey: 'your_key' });
22
+ *
23
+ * // Get all storage data
24
+ * const storage = await client.storage.all();
25
+ * console.log(`Total US inventory: ${storage.level} ${storage.unit}`);
26
+ *
27
+ * // Get Cushing levels
28
+ * const cushing = await client.storage.cushing();
29
+ * console.log(`Cushing: ${cushing.level} ${cushing.unit}`);
30
+ *
31
+ * // Get SPR levels
32
+ * const spr = await client.storage.spr();
33
+ * console.log(`SPR: ${spr.level} ${spr.unit}`);
34
+ * ```
35
+ */
36
+ class StorageResource {
37
+ constructor(client) {
38
+ this.client = client;
39
+ }
40
+ /**
41
+ * Get all current storage levels
42
+ *
43
+ * Returns total US commercial crude oil inventory.
44
+ *
45
+ * @returns Current storage data
46
+ *
47
+ * @throws {OilPriceAPIError} If API request fails
48
+ * @throws {AuthenticationError} If API key is invalid
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * const storage = await client.storage.all();
53
+ * console.log(`Total inventory: ${storage.level} ${storage.unit}`);
54
+ * if (storage.change) {
55
+ * console.log(`Change: ${storage.change > 0 ? '+' : ''}${storage.change}`);
56
+ * }
57
+ * ```
58
+ */
59
+ async all() {
60
+ return this.client["request"]("/v1/storage", {});
61
+ }
62
+ /**
63
+ * Get Cushing, OK storage levels
64
+ *
65
+ * Returns current inventory at Cushing, Oklahoma - the key delivery point
66
+ * for WTI crude oil futures.
67
+ *
68
+ * @returns Cushing storage data
69
+ *
70
+ * @throws {OilPriceAPIError} If API request fails
71
+ * @throws {AuthenticationError} If API key is invalid
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const cushing = await client.storage.cushing();
76
+ * console.log(`Cushing inventory: ${cushing.level} ${cushing.unit}`);
77
+ * console.log(`Week-over-week change: ${cushing.change_percent}%`);
78
+ * ```
79
+ */
80
+ async cushing() {
81
+ return this.client["request"]("/v1/storage/cushing", {});
82
+ }
83
+ /**
84
+ * Get Strategic Petroleum Reserve (SPR) levels
85
+ *
86
+ * Returns current US Strategic Petroleum Reserve inventory.
87
+ *
88
+ * @returns SPR storage data
89
+ *
90
+ * @throws {OilPriceAPIError} If API request fails
91
+ * @throws {AuthenticationError} If API key is invalid
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const spr = await client.storage.spr();
96
+ * console.log(`SPR inventory: ${spr.level} ${spr.unit}`);
97
+ * ```
98
+ */
99
+ async spr() {
100
+ return this.client["request"]("/v1/storage/spr", {});
101
+ }
102
+ /**
103
+ * Get regional storage breakdown
104
+ *
105
+ * Returns storage levels by region (PADD districts) or a specific region.
106
+ *
107
+ * @param region - Optional region code (e.g., "PADD1", "PADD2", "PADD3")
108
+ * @returns Regional storage data
109
+ *
110
+ * @throws {OilPriceAPIError} If API request fails
111
+ * @throws {AuthenticationError} If API key is invalid
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * // Get all regions
116
+ * const regions = await client.storage.regional();
117
+ *
118
+ * // Get specific region (Gulf Coast)
119
+ * const gulfCoast = await client.storage.regional('PADD3');
120
+ * console.log(`PADD 3 (Gulf Coast): ${gulfCoast.level} ${gulfCoast.unit}`);
121
+ * ```
122
+ */
123
+ async regional(region) {
124
+ const params = {};
125
+ if (region)
126
+ params.region = region;
127
+ return this.client["request"]("/v1/storage/regional", params);
128
+ }
129
+ /**
130
+ * Get historical storage data
131
+ *
132
+ * Returns time series of storage levels for a specific location.
133
+ *
134
+ * @param code - Storage location code (e.g., "US", "CUSHING", "SPR")
135
+ * @param options - Date range filters
136
+ * @returns Array of historical storage data
137
+ *
138
+ * @throws {NotFoundError} If location code not found
139
+ * @throws {OilPriceAPIError} If API request fails
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * const history = await client.storage.history('CUSHING', {
144
+ * startDate: '2024-01-01',
145
+ * endDate: '2024-12-31'
146
+ * });
147
+ *
148
+ * history.forEach(point => {
149
+ * console.log(`${point.date}: ${point.level} ${point.unit}`);
150
+ * });
151
+ * ```
152
+ */
153
+ async history(code, options) {
154
+ if (!code || typeof code !== "string") {
155
+ throw new errors_js_1.ValidationError("Storage location code must be a non-empty string");
156
+ }
157
+ const params = {};
158
+ if (options?.startDate)
159
+ params.start_date = options.startDate;
160
+ if (options?.endDate)
161
+ params.end_date = options.endDate;
162
+ const response = await this.client["request"](`/v1/storage/${code}/history`, params);
163
+ return Array.isArray(response) ? response : response.data;
164
+ }
165
+ }
166
+ exports.StorageResource = StorageResource;
@@ -0,0 +1,294 @@
1
+ "use strict";
2
+ /**
3
+ * Webhooks Resource
4
+ *
5
+ * Manage webhook endpoints for real-time event notifications.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.WebhooksResource = void 0;
9
+ const errors_js_1 = require("../errors.js");
10
+ const index_js_1 = require("../index.js");
11
+ /**
12
+ * Webhooks Resource
13
+ *
14
+ * Manage webhook endpoints for real-time notifications about price changes,
15
+ * alerts, and other events.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { OilPriceAPI } from 'oilpriceapi';
20
+ *
21
+ * const client = new OilPriceAPI({ apiKey: 'your_key' });
22
+ *
23
+ * // Create a webhook
24
+ * const webhook = await client.webhooks.create({
25
+ * name: 'Price Updates',
26
+ * url: 'https://myapp.com/webhooks/prices',
27
+ * events: ['price.updated', 'alert.triggered'],
28
+ * enabled: true
29
+ * });
30
+ *
31
+ * // Test the webhook
32
+ * const test = await client.webhooks.test(webhook.id);
33
+ * console.log(`Test result: ${test.success ? 'passed' : 'failed'}`);
34
+ *
35
+ * // List all webhooks
36
+ * const webhooks = await client.webhooks.list();
37
+ * webhooks.forEach(wh => {
38
+ * console.log(`${wh.name}: ${wh.successful_deliveries} successful`);
39
+ * });
40
+ *
41
+ * // Update webhook
42
+ * await client.webhooks.update(webhook.id, {
43
+ * enabled: false
44
+ * });
45
+ *
46
+ * // Delete webhook
47
+ * await client.webhooks.delete(webhook.id);
48
+ * ```
49
+ */
50
+ class WebhooksResource {
51
+ constructor(client) {
52
+ this.client = client;
53
+ }
54
+ /**
55
+ * List all webhook endpoints
56
+ *
57
+ * @returns Array of webhook endpoints
58
+ *
59
+ * @throws {OilPriceAPIError} If API request fails
60
+ * @throws {AuthenticationError} If API key is invalid
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const webhooks = await client.webhooks.list();
65
+ * webhooks.forEach(wh => {
66
+ * console.log(`${wh.name} (${wh.enabled ? 'enabled' : 'disabled'})`);
67
+ * console.log(` Events: ${wh.events.join(', ')}`);
68
+ * });
69
+ * ```
70
+ */
71
+ async list() {
72
+ const response = await this.client["request"]("/v1/webhooks", {});
73
+ return Array.isArray(response) ? response : response.webhooks;
74
+ }
75
+ /**
76
+ * Get a specific webhook endpoint
77
+ *
78
+ * @param id - Webhook ID
79
+ * @returns Webhook endpoint details
80
+ *
81
+ * @throws {NotFoundError} If webhook not found
82
+ * @throws {OilPriceAPIError} If API request fails
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * const webhook = await client.webhooks.get('webhook-id');
87
+ * console.log(`${webhook.name}: ${webhook.url}`);
88
+ * console.log(`Success rate: ${webhook.successful_deliveries}/${webhook.successful_deliveries + webhook.failed_deliveries}`);
89
+ * ```
90
+ */
91
+ async get(id) {
92
+ if (!id || typeof id !== "string") {
93
+ throw new errors_js_1.ValidationError("Webhook ID must be a non-empty string");
94
+ }
95
+ const response = await this.client["request"](`/v1/webhooks/${id}`, {});
96
+ return "webhook" in response ? response.webhook : response;
97
+ }
98
+ /**
99
+ * Create a new webhook endpoint
100
+ *
101
+ * @param params - Webhook configuration
102
+ * @returns Created webhook endpoint
103
+ *
104
+ * @throws {OilPriceAPIError} If API request fails
105
+ * @throws {AuthenticationError} If API key is invalid
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const webhook = await client.webhooks.create({
110
+ * name: 'Production Alerts',
111
+ * url: 'https://api.myapp.com/webhooks',
112
+ * events: ['alert.triggered', 'price.updated'],
113
+ * secret: 'my-webhook-secret',
114
+ * enabled: true
115
+ * });
116
+ * console.log(`Webhook created: ${webhook.id}`);
117
+ * ```
118
+ */
119
+ async create(params) {
120
+ if (!params.name || typeof params.name !== "string") {
121
+ throw new errors_js_1.ValidationError("Webhook name is required");
122
+ }
123
+ if (!params.url || !params.url.startsWith("https://")) {
124
+ throw new errors_js_1.ValidationError("Webhook URL must use HTTPS protocol");
125
+ }
126
+ if (!params.events || !Array.isArray(params.events) || params.events.length === 0) {
127
+ throw new errors_js_1.ValidationError("At least one event type is required");
128
+ }
129
+ const response = await this.client["request"]("/v1/webhooks", {}, {
130
+ method: "POST",
131
+ body: {
132
+ webhook: {
133
+ name: params.name,
134
+ url: params.url,
135
+ events: params.events,
136
+ enabled: params.enabled ?? true,
137
+ secret: params.secret,
138
+ metadata: params.metadata,
139
+ },
140
+ },
141
+ });
142
+ return "webhook" in response ? response.webhook : response;
143
+ }
144
+ /**
145
+ * Update a webhook endpoint
146
+ *
147
+ * @param id - Webhook ID
148
+ * @param params - Fields to update
149
+ * @returns Updated webhook endpoint
150
+ *
151
+ * @throws {NotFoundError} If webhook not found
152
+ * @throws {OilPriceAPIError} If API request fails
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * // Disable a webhook
157
+ * await client.webhooks.update(webhookId, { enabled: false });
158
+ *
159
+ * // Change events
160
+ * await client.webhooks.update(webhookId, {
161
+ * events: ['alert.triggered']
162
+ * });
163
+ * ```
164
+ */
165
+ async update(id, params) {
166
+ if (!id || typeof id !== "string") {
167
+ throw new errors_js_1.ValidationError("Webhook ID must be a non-empty string");
168
+ }
169
+ if (params.url !== undefined && !params.url.startsWith("https://")) {
170
+ throw new errors_js_1.ValidationError("Webhook URL must use HTTPS protocol");
171
+ }
172
+ if (params.events !== undefined &&
173
+ (!Array.isArray(params.events) || params.events.length === 0)) {
174
+ throw new errors_js_1.ValidationError("Events must be a non-empty array");
175
+ }
176
+ const response = await this.client["request"](`/v1/webhooks/${id}`, {}, {
177
+ method: "PATCH",
178
+ body: { webhook: params },
179
+ });
180
+ return "webhook" in response ? response.webhook : response;
181
+ }
182
+ /**
183
+ * Delete a webhook endpoint
184
+ *
185
+ * @param id - Webhook ID
186
+ *
187
+ * @throws {NotFoundError} If webhook not found
188
+ * @throws {OilPriceAPIError} If API request fails
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * await client.webhooks.delete(webhookId);
193
+ * console.log('Webhook deleted');
194
+ * ```
195
+ */
196
+ async delete(id) {
197
+ if (!id || typeof id !== "string") {
198
+ throw new errors_js_1.ValidationError("Webhook ID must be a non-empty string");
199
+ }
200
+ await this.client["request"](`/v1/webhooks/${id}`, {}, { method: "DELETE" });
201
+ }
202
+ /**
203
+ * Test a webhook endpoint
204
+ *
205
+ * Sends a test payload to the webhook URL to verify it's reachable.
206
+ *
207
+ * @param id - Webhook ID
208
+ * @returns Test results
209
+ *
210
+ * @throws {NotFoundError} If webhook not found
211
+ * @throws {OilPriceAPIError} If API request fails
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * const test = await client.webhooks.test(webhookId);
216
+ * console.log(`Test ${test.success ? 'passed' : 'failed'}`);
217
+ * console.log(`Response time: ${test.response_time_ms}ms`);
218
+ * if (!test.success) {
219
+ * console.log(`Error: ${test.error}`);
220
+ * }
221
+ * ```
222
+ */
223
+ async test(id) {
224
+ if (!id || typeof id !== "string") {
225
+ throw new errors_js_1.ValidationError("Webhook ID must be a non-empty string");
226
+ }
227
+ return this.client["request"](`/v1/webhooks/${id}/test`, {}, { method: "POST" });
228
+ }
229
+ /**
230
+ * Get webhook event history
231
+ *
232
+ * Returns recent delivery events for a webhook.
233
+ *
234
+ * @param id - Webhook ID
235
+ * @returns Array of webhook events
236
+ *
237
+ * @throws {NotFoundError} If webhook not found
238
+ * @throws {OilPriceAPIError} If API request fails
239
+ *
240
+ * @example
241
+ * ```typescript
242
+ * const events = await client.webhooks.events(webhookId);
243
+ * events.forEach(event => {
244
+ * console.log(`${event.event_type}: ${event.status} (${event.attempts} attempts)`);
245
+ * });
246
+ * ```
247
+ */
248
+ async events(id) {
249
+ if (!id || typeof id !== "string") {
250
+ throw new errors_js_1.ValidationError("Webhook ID must be a non-empty string");
251
+ }
252
+ const response = await this.client["request"](`/v1/webhooks/${id}/events`, {});
253
+ return Array.isArray(response) ? response : response.events;
254
+ }
255
+ /**
256
+ * Verify a webhook signature.
257
+ *
258
+ * Validates that a webhook payload was sent by OilPriceAPI by checking
259
+ * the HMAC-SHA256 signature. Uses constant-time comparison to prevent
260
+ * timing attacks.
261
+ *
262
+ * @param payload - Raw request body (string or Buffer)
263
+ * @param signature - Value of the X-OilPriceAPI-Signature header (e.g., "sha256=abc123...")
264
+ * @param secret - Your webhook signing secret
265
+ * @returns true if signature is valid
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * import express from 'express';
270
+ * import { OilPriceAPI } from 'oilpriceapi';
271
+ *
272
+ * const app = express();
273
+ * const client = new OilPriceAPI({ apiKey: 'your_key' });
274
+ *
275
+ * // Use raw body parser for webhook routes
276
+ * app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
277
+ * const signature = req.headers['x-oilpriceapi-signature'] as string;
278
+ * const isValid = client.webhooks.verifySignature(req.body, signature, 'your_secret');
279
+ *
280
+ * if (!isValid) {
281
+ * return res.status(401).send('Invalid signature');
282
+ * }
283
+ *
284
+ * const event = JSON.parse(req.body.toString());
285
+ * console.log('Verified webhook:', event.type);
286
+ * res.sendStatus(200);
287
+ * });
288
+ * ```
289
+ */
290
+ verifySignature(payload, signature, secret) {
291
+ return (0, index_js_1.verifyWebhookSignature)(payload, signature, secret);
292
+ }
293
+ }
294
+ exports.WebhooksResource = WebhooksResource;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SDK_NAME = exports.SDK_VERSION = void 0;
4
+ exports.buildUserAgent = buildUserAgent;
5
+ /**
6
+ * SDK Version - centralized to ensure consistency across all headers
7
+ *
8
+ * This version must be updated when publishing a new release.
9
+ * It's used in:
10
+ * - User-Agent header: oilpriceapi-node/{version}
11
+ * - X-Client-Version header
12
+ * - Package.json (should match)
13
+ */
14
+ exports.SDK_VERSION = "0.8.2";
15
+ /**
16
+ * SDK identifier used in User-Agent and X-Api-Client headers
17
+ */
18
+ exports.SDK_NAME = "oilpriceapi-node";
19
+ /**
20
+ * Build the full User-Agent string
21
+ */
22
+ function buildUserAgent() {
23
+ return `${exports.SDK_NAME}/${exports.SDK_VERSION} node/${process.version}`;
24
+ }
package/dist/client.d.ts CHANGED
@@ -105,7 +105,7 @@ export declare class OilPriceAPI {
105
105
  * Data sources resource (BYOS - Bring Your Own Source)
106
106
  */
107
107
  readonly dataSources: DataSourcesResource;
108
- constructor(config: OilPriceAPIConfig);
108
+ constructor(config?: OilPriceAPIConfig);
109
109
  /**
110
110
  * Log debug messages if debug mode is enabled
111
111
  */
@@ -123,7 +123,9 @@ export declare class OilPriceAPI {
123
123
  */
124
124
  private isRetryable;
125
125
  /**
126
- * Internal method to make HTTP requests with retry and timeout
126
+ * Internal method to make HTTP requests with retry and timeout.
127
+ * Supports all HTTP methods (GET, POST, PATCH, DELETE) with consistent
128
+ * retry logic, timeout handling, and typed error responses.
127
129
  */
128
130
  private request;
129
131
  /**
@@ -165,6 +167,35 @@ export declare class OilPriceAPI {
165
167
  * ```
166
168
  */
167
169
  getHistoricalPrices(options?: HistoricalPricesOptions): Promise<Price[]>;
170
+ /**
171
+ * Paginate through historical prices automatically.
172
+ *
173
+ * Returns an async generator that yields pages of prices, fetching
174
+ * the next page only when needed. Avoids loading all data into memory.
175
+ *
176
+ * @param options - Same options as getHistoricalPrices, plus perPage (default: 100)
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * // Iterate through all pages
181
+ * for await (const page of client.paginateHistoricalPrices({
182
+ * commodity: 'BRENT_CRUDE_USD',
183
+ * startDate: '2024-01-01',
184
+ * endDate: '2024-12-31',
185
+ * perPage: 100,
186
+ * })) {
187
+ * console.log(`Got ${page.length} prices`);
188
+ * // Process each page...
189
+ * }
190
+ *
191
+ * // Or collect all prices
192
+ * const allPrices: Price[] = [];
193
+ * for await (const page of client.paginateHistoricalPrices({ commodity: 'WTI_USD' })) {
194
+ * allPrices.push(...page);
195
+ * }
196
+ * ```
197
+ */
198
+ paginateHistoricalPrices(options?: HistoricalPricesOptions): AsyncGenerator<Price[]>;
168
199
  /**
169
200
  * Get prices from your connected data sources (BYOS)
170
201
  *