oilpriceapi 0.6.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 (80) hide show
  1. package/README.md +418 -123
  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 +116 -5
  30. package/dist/client.js +169 -47
  31. package/dist/errors.d.ts +6 -0
  32. package/dist/errors.js +25 -16
  33. package/dist/index.d.ts +45 -6
  34. package/dist/index.js +40 -3
  35. package/dist/resources/alerts.d.ts +52 -15
  36. package/dist/resources/alerts.js +121 -109
  37. package/dist/resources/analytics.d.ts +325 -0
  38. package/dist/resources/analytics.js +222 -0
  39. package/dist/resources/bunker-fuels.d.ts +270 -0
  40. package/dist/resources/bunker-fuels.js +192 -0
  41. package/dist/resources/commodities.d.ts +148 -0
  42. package/dist/resources/commodities.js +111 -0
  43. package/dist/resources/data-quality.d.ts +229 -0
  44. package/dist/resources/data-quality.js +140 -0
  45. package/dist/resources/data-sources.d.ts +365 -0
  46. package/dist/resources/data-sources.js +293 -0
  47. package/dist/resources/diesel.d.ts +1 -1
  48. package/dist/resources/diesel.js +9 -38
  49. package/dist/resources/drilling.d.ts +403 -0
  50. package/dist/resources/drilling.js +265 -0
  51. package/dist/resources/ei/drilling-productivity.d.ts +173 -0
  52. package/dist/resources/ei/drilling-productivity.js +104 -0
  53. package/dist/resources/ei/forecasts.d.ts +177 -0
  54. package/dist/resources/ei/forecasts.js +102 -0
  55. package/dist/resources/ei/frac-focus.d.ts +212 -0
  56. package/dist/resources/ei/frac-focus.js +151 -0
  57. package/dist/resources/ei/index.d.ts +140 -0
  58. package/dist/resources/ei/index.js +88 -0
  59. package/dist/resources/ei/oil-inventories.d.ts +155 -0
  60. package/dist/resources/ei/oil-inventories.js +93 -0
  61. package/dist/resources/ei/opec-production.d.ts +146 -0
  62. package/dist/resources/ei/opec-production.js +93 -0
  63. package/dist/resources/ei/rig-counts.d.ts +131 -0
  64. package/dist/resources/ei/rig-counts.js +89 -0
  65. package/dist/resources/ei/well-permits.d.ts +178 -0
  66. package/dist/resources/ei/well-permits.js +120 -0
  67. package/dist/resources/forecasts.d.ts +200 -0
  68. package/dist/resources/forecasts.js +158 -0
  69. package/dist/resources/futures.d.ts +322 -0
  70. package/dist/resources/futures.js +229 -0
  71. package/dist/resources/rig-counts.d.ts +221 -0
  72. package/dist/resources/rig-counts.js +157 -0
  73. package/dist/resources/storage.d.ts +182 -0
  74. package/dist/resources/storage.js +162 -0
  75. package/dist/resources/webhooks.d.ts +326 -0
  76. package/dist/resources/webhooks.js +290 -0
  77. package/dist/types.d.ts +79 -8
  78. package/dist/version.d.ts +1 -1
  79. package/dist/version.js +2 -2
  80. package/package.json +17 -8
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Storage Resource
3
+ *
4
+ * Access crude oil storage data including total US inventory, Cushing hub levels,
5
+ * Strategic Petroleum Reserve (SPR), and regional breakdowns.
6
+ */
7
+ import type { OilPriceAPI } from "../client.js";
8
+ /**
9
+ * Storage level data
10
+ */
11
+ export interface StorageData {
12
+ /** Storage location code */
13
+ code: string;
14
+ /** Location name */
15
+ name?: string;
16
+ /** Current storage level */
17
+ level: number;
18
+ /** Unit of measurement (typically "thousand_barrels" or "million_barrels") */
19
+ unit: string;
20
+ /** ISO timestamp when data was recorded */
21
+ timestamp: string;
22
+ /** Change from previous period */
23
+ change?: number;
24
+ /** Percentage change */
25
+ change_percent?: number;
26
+ /** Additional metadata */
27
+ metadata?: Record<string, unknown>;
28
+ }
29
+ /**
30
+ * Historical storage data point
31
+ */
32
+ export interface HistoricalStorageData {
33
+ /** Date in YYYY-MM-DD format */
34
+ date: string;
35
+ /** Storage level */
36
+ level: number;
37
+ /** Unit of measurement */
38
+ unit: string;
39
+ /** Week-over-week change */
40
+ change?: number;
41
+ }
42
+ /**
43
+ * Options for historical storage query
44
+ */
45
+ export interface HistoricalStorageOptions {
46
+ /** Start date in ISO 8601 format (YYYY-MM-DD) */
47
+ startDate?: string;
48
+ /** End date in ISO 8601 format (YYYY-MM-DD) */
49
+ endDate?: string;
50
+ }
51
+ /**
52
+ * Storage Resource
53
+ *
54
+ * Access crude oil storage data for US inventory levels, Cushing hub,
55
+ * Strategic Petroleum Reserve, and regional breakdowns.
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * import { OilPriceAPI } from 'oilpriceapi';
60
+ *
61
+ * const client = new OilPriceAPI({ apiKey: 'your_key' });
62
+ *
63
+ * // Get all storage data
64
+ * const storage = await client.storage.all();
65
+ * console.log(`Total US inventory: ${storage.level} ${storage.unit}`);
66
+ *
67
+ * // Get Cushing levels
68
+ * const cushing = await client.storage.cushing();
69
+ * console.log(`Cushing: ${cushing.level} ${cushing.unit}`);
70
+ *
71
+ * // Get SPR levels
72
+ * const spr = await client.storage.spr();
73
+ * console.log(`SPR: ${spr.level} ${spr.unit}`);
74
+ * ```
75
+ */
76
+ export declare class StorageResource {
77
+ private client;
78
+ constructor(client: OilPriceAPI);
79
+ /**
80
+ * Get all current storage levels
81
+ *
82
+ * Returns total US commercial crude oil inventory.
83
+ *
84
+ * @returns Current storage data
85
+ *
86
+ * @throws {OilPriceAPIError} If API request fails
87
+ * @throws {AuthenticationError} If API key is invalid
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const storage = await client.storage.all();
92
+ * console.log(`Total inventory: ${storage.level} ${storage.unit}`);
93
+ * if (storage.change) {
94
+ * console.log(`Change: ${storage.change > 0 ? '+' : ''}${storage.change}`);
95
+ * }
96
+ * ```
97
+ */
98
+ all(): Promise<StorageData>;
99
+ /**
100
+ * Get Cushing, OK storage levels
101
+ *
102
+ * Returns current inventory at Cushing, Oklahoma - the key delivery point
103
+ * for WTI crude oil futures.
104
+ *
105
+ * @returns Cushing storage data
106
+ *
107
+ * @throws {OilPriceAPIError} If API request fails
108
+ * @throws {AuthenticationError} If API key is invalid
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const cushing = await client.storage.cushing();
113
+ * console.log(`Cushing inventory: ${cushing.level} ${cushing.unit}`);
114
+ * console.log(`Week-over-week change: ${cushing.change_percent}%`);
115
+ * ```
116
+ */
117
+ cushing(): Promise<StorageData>;
118
+ /**
119
+ * Get Strategic Petroleum Reserve (SPR) levels
120
+ *
121
+ * Returns current US Strategic Petroleum Reserve inventory.
122
+ *
123
+ * @returns SPR storage data
124
+ *
125
+ * @throws {OilPriceAPIError} If API request fails
126
+ * @throws {AuthenticationError} If API key is invalid
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * const spr = await client.storage.spr();
131
+ * console.log(`SPR inventory: ${spr.level} ${spr.unit}`);
132
+ * ```
133
+ */
134
+ spr(): Promise<StorageData>;
135
+ /**
136
+ * Get regional storage breakdown
137
+ *
138
+ * Returns storage levels by region (PADD districts) or a specific region.
139
+ *
140
+ * @param region - Optional region code (e.g., "PADD1", "PADD2", "PADD3")
141
+ * @returns Regional storage data
142
+ *
143
+ * @throws {OilPriceAPIError} If API request fails
144
+ * @throws {AuthenticationError} If API key is invalid
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // Get all regions
149
+ * const regions = await client.storage.regional();
150
+ *
151
+ * // Get specific region (Gulf Coast)
152
+ * const gulfCoast = await client.storage.regional('PADD3');
153
+ * console.log(`PADD 3 (Gulf Coast): ${gulfCoast.level} ${gulfCoast.unit}`);
154
+ * ```
155
+ */
156
+ regional(region?: string): Promise<StorageData | StorageData[]>;
157
+ /**
158
+ * Get historical storage data
159
+ *
160
+ * Returns time series of storage levels for a specific location.
161
+ *
162
+ * @param code - Storage location code (e.g., "US", "CUSHING", "SPR")
163
+ * @param options - Date range filters
164
+ * @returns Array of historical storage data
165
+ *
166
+ * @throws {NotFoundError} If location code not found
167
+ * @throws {OilPriceAPIError} If API request fails
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const history = await client.storage.history('CUSHING', {
172
+ * startDate: '2024-01-01',
173
+ * endDate: '2024-12-31'
174
+ * });
175
+ *
176
+ * history.forEach(point => {
177
+ * console.log(`${point.date}: ${point.level} ${point.unit}`);
178
+ * });
179
+ * ```
180
+ */
181
+ history(code: string, options?: HistoricalStorageOptions): Promise<HistoricalStorageData[]>;
182
+ }
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Storage Resource
3
+ *
4
+ * Access crude oil storage data including total US inventory, Cushing hub levels,
5
+ * Strategic Petroleum Reserve (SPR), and regional breakdowns.
6
+ */
7
+ import { ValidationError } from "../errors.js";
8
+ /**
9
+ * Storage Resource
10
+ *
11
+ * Access crude oil storage data for US inventory levels, Cushing hub,
12
+ * Strategic Petroleum Reserve, and regional breakdowns.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { OilPriceAPI } from 'oilpriceapi';
17
+ *
18
+ * const client = new OilPriceAPI({ apiKey: 'your_key' });
19
+ *
20
+ * // Get all storage data
21
+ * const storage = await client.storage.all();
22
+ * console.log(`Total US inventory: ${storage.level} ${storage.unit}`);
23
+ *
24
+ * // Get Cushing levels
25
+ * const cushing = await client.storage.cushing();
26
+ * console.log(`Cushing: ${cushing.level} ${cushing.unit}`);
27
+ *
28
+ * // Get SPR levels
29
+ * const spr = await client.storage.spr();
30
+ * console.log(`SPR: ${spr.level} ${spr.unit}`);
31
+ * ```
32
+ */
33
+ export class StorageResource {
34
+ constructor(client) {
35
+ this.client = client;
36
+ }
37
+ /**
38
+ * Get all current storage levels
39
+ *
40
+ * Returns total US commercial crude oil inventory.
41
+ *
42
+ * @returns Current storage data
43
+ *
44
+ * @throws {OilPriceAPIError} If API request fails
45
+ * @throws {AuthenticationError} If API key is invalid
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const storage = await client.storage.all();
50
+ * console.log(`Total inventory: ${storage.level} ${storage.unit}`);
51
+ * if (storage.change) {
52
+ * console.log(`Change: ${storage.change > 0 ? '+' : ''}${storage.change}`);
53
+ * }
54
+ * ```
55
+ */
56
+ async all() {
57
+ return this.client["request"]("/v1/storage", {});
58
+ }
59
+ /**
60
+ * Get Cushing, OK storage levels
61
+ *
62
+ * Returns current inventory at Cushing, Oklahoma - the key delivery point
63
+ * for WTI crude oil futures.
64
+ *
65
+ * @returns Cushing storage data
66
+ *
67
+ * @throws {OilPriceAPIError} If API request fails
68
+ * @throws {AuthenticationError} If API key is invalid
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * const cushing = await client.storage.cushing();
73
+ * console.log(`Cushing inventory: ${cushing.level} ${cushing.unit}`);
74
+ * console.log(`Week-over-week change: ${cushing.change_percent}%`);
75
+ * ```
76
+ */
77
+ async cushing() {
78
+ return this.client["request"]("/v1/storage/cushing", {});
79
+ }
80
+ /**
81
+ * Get Strategic Petroleum Reserve (SPR) levels
82
+ *
83
+ * Returns current US Strategic Petroleum Reserve inventory.
84
+ *
85
+ * @returns SPR storage data
86
+ *
87
+ * @throws {OilPriceAPIError} If API request fails
88
+ * @throws {AuthenticationError} If API key is invalid
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const spr = await client.storage.spr();
93
+ * console.log(`SPR inventory: ${spr.level} ${spr.unit}`);
94
+ * ```
95
+ */
96
+ async spr() {
97
+ return this.client["request"]("/v1/storage/spr", {});
98
+ }
99
+ /**
100
+ * Get regional storage breakdown
101
+ *
102
+ * Returns storage levels by region (PADD districts) or a specific region.
103
+ *
104
+ * @param region - Optional region code (e.g., "PADD1", "PADD2", "PADD3")
105
+ * @returns Regional storage data
106
+ *
107
+ * @throws {OilPriceAPIError} If API request fails
108
+ * @throws {AuthenticationError} If API key is invalid
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * // Get all regions
113
+ * const regions = await client.storage.regional();
114
+ *
115
+ * // Get specific region (Gulf Coast)
116
+ * const gulfCoast = await client.storage.regional('PADD3');
117
+ * console.log(`PADD 3 (Gulf Coast): ${gulfCoast.level} ${gulfCoast.unit}`);
118
+ * ```
119
+ */
120
+ async regional(region) {
121
+ const params = {};
122
+ if (region)
123
+ params.region = region;
124
+ return this.client["request"]("/v1/storage/regional", params);
125
+ }
126
+ /**
127
+ * Get historical storage data
128
+ *
129
+ * Returns time series of storage levels for a specific location.
130
+ *
131
+ * @param code - Storage location code (e.g., "US", "CUSHING", "SPR")
132
+ * @param options - Date range filters
133
+ * @returns Array of historical storage data
134
+ *
135
+ * @throws {NotFoundError} If location code not found
136
+ * @throws {OilPriceAPIError} If API request fails
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * const history = await client.storage.history('CUSHING', {
141
+ * startDate: '2024-01-01',
142
+ * endDate: '2024-12-31'
143
+ * });
144
+ *
145
+ * history.forEach(point => {
146
+ * console.log(`${point.date}: ${point.level} ${point.unit}`);
147
+ * });
148
+ * ```
149
+ */
150
+ async history(code, options) {
151
+ if (!code || typeof code !== "string") {
152
+ throw new ValidationError("Storage location code must be a non-empty string");
153
+ }
154
+ const params = {};
155
+ if (options?.startDate)
156
+ params.start_date = options.startDate;
157
+ if (options?.endDate)
158
+ params.end_date = options.endDate;
159
+ const response = await this.client["request"](`/v1/storage/${code}/history`, params);
160
+ return Array.isArray(response) ? response : response.data;
161
+ }
162
+ }
@@ -0,0 +1,326 @@
1
+ /**
2
+ * Webhooks Resource
3
+ *
4
+ * Manage webhook endpoints for real-time event notifications.
5
+ */
6
+ import type { OilPriceAPI } from "../client.js";
7
+ /**
8
+ * Webhook endpoint configuration
9
+ */
10
+ export interface WebhookEndpoint {
11
+ /** Unique webhook identifier */
12
+ id: string;
13
+ /** User-friendly webhook name */
14
+ name: string;
15
+ /** Webhook URL (must be HTTPS) */
16
+ url: string;
17
+ /** Event types to subscribe to */
18
+ events: string[];
19
+ /** Whether the webhook is active */
20
+ enabled: boolean;
21
+ /** Optional secret for signature verification */
22
+ secret?: string;
23
+ /** Optional metadata */
24
+ metadata?: Record<string, unknown>;
25
+ /** Number of successful deliveries */
26
+ successful_deliveries: number;
27
+ /** Number of failed deliveries */
28
+ failed_deliveries: number;
29
+ /** Last delivery status */
30
+ last_delivery_status?: "success" | "failed";
31
+ /** ISO timestamp of last delivery attempt */
32
+ last_delivery_at?: string;
33
+ /** ISO timestamp when webhook was created */
34
+ created_at: string;
35
+ /** ISO timestamp when webhook was last updated */
36
+ updated_at: string;
37
+ }
38
+ /**
39
+ * Parameters for creating a webhook
40
+ */
41
+ export interface CreateWebhookParams {
42
+ /** User-friendly webhook name */
43
+ name: string;
44
+ /** Webhook URL (must be HTTPS) */
45
+ url: string;
46
+ /** Event types to subscribe to */
47
+ events: string[];
48
+ /** Whether to enable immediately (default: true) */
49
+ enabled?: boolean;
50
+ /** Optional secret for signature verification */
51
+ secret?: string;
52
+ /** Optional metadata */
53
+ metadata?: Record<string, unknown>;
54
+ }
55
+ /**
56
+ * Parameters for updating a webhook
57
+ */
58
+ export interface UpdateWebhookParams {
59
+ /** User-friendly webhook name */
60
+ name?: string;
61
+ /** Webhook URL */
62
+ url?: string;
63
+ /** Event types to subscribe to */
64
+ events?: string[];
65
+ /** Whether the webhook is active */
66
+ enabled?: boolean;
67
+ /** Secret for signature verification */
68
+ secret?: string;
69
+ /** Metadata */
70
+ metadata?: Record<string, unknown>;
71
+ }
72
+ /**
73
+ * Webhook test response
74
+ */
75
+ export interface WebhookTestResponse {
76
+ /** Test result status */
77
+ success: boolean;
78
+ /** HTTP status code from webhook endpoint */
79
+ status_code: number;
80
+ /** Response time in milliseconds */
81
+ response_time_ms: number;
82
+ /** Response body from webhook endpoint */
83
+ response_body?: string;
84
+ /** Error message if test failed */
85
+ error?: string;
86
+ }
87
+ /**
88
+ * Webhook event record
89
+ */
90
+ export interface WebhookEvent {
91
+ /** Event ID */
92
+ id: string;
93
+ /** Webhook endpoint ID */
94
+ webhook_id: string;
95
+ /** Event type */
96
+ event_type: string;
97
+ /** Event payload */
98
+ payload: Record<string, unknown>;
99
+ /** Delivery status */
100
+ status: "pending" | "success" | "failed";
101
+ /** Number of delivery attempts */
102
+ attempts: number;
103
+ /** HTTP status code from delivery */
104
+ status_code?: number;
105
+ /** Error message if delivery failed */
106
+ error?: string;
107
+ /** ISO timestamp when event was created */
108
+ created_at: string;
109
+ /** ISO timestamp of last delivery attempt */
110
+ delivered_at?: string;
111
+ }
112
+ /**
113
+ * Webhooks Resource
114
+ *
115
+ * Manage webhook endpoints for real-time notifications about price changes,
116
+ * alerts, and other events.
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * import { OilPriceAPI } from 'oilpriceapi';
121
+ *
122
+ * const client = new OilPriceAPI({ apiKey: 'your_key' });
123
+ *
124
+ * // Create a webhook
125
+ * const webhook = await client.webhooks.create({
126
+ * name: 'Price Updates',
127
+ * url: 'https://myapp.com/webhooks/prices',
128
+ * events: ['price.updated', 'alert.triggered'],
129
+ * enabled: true
130
+ * });
131
+ *
132
+ * // Test the webhook
133
+ * const test = await client.webhooks.test(webhook.id);
134
+ * console.log(`Test result: ${test.success ? 'passed' : 'failed'}`);
135
+ *
136
+ * // List all webhooks
137
+ * const webhooks = await client.webhooks.list();
138
+ * webhooks.forEach(wh => {
139
+ * console.log(`${wh.name}: ${wh.successful_deliveries} successful`);
140
+ * });
141
+ *
142
+ * // Update webhook
143
+ * await client.webhooks.update(webhook.id, {
144
+ * enabled: false
145
+ * });
146
+ *
147
+ * // Delete webhook
148
+ * await client.webhooks.delete(webhook.id);
149
+ * ```
150
+ */
151
+ export declare class WebhooksResource {
152
+ private client;
153
+ constructor(client: OilPriceAPI);
154
+ /**
155
+ * List all webhook endpoints
156
+ *
157
+ * @returns Array of webhook endpoints
158
+ *
159
+ * @throws {OilPriceAPIError} If API request fails
160
+ * @throws {AuthenticationError} If API key is invalid
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * const webhooks = await client.webhooks.list();
165
+ * webhooks.forEach(wh => {
166
+ * console.log(`${wh.name} (${wh.enabled ? 'enabled' : 'disabled'})`);
167
+ * console.log(` Events: ${wh.events.join(', ')}`);
168
+ * });
169
+ * ```
170
+ */
171
+ list(): Promise<WebhookEndpoint[]>;
172
+ /**
173
+ * Get a specific webhook endpoint
174
+ *
175
+ * @param id - Webhook ID
176
+ * @returns Webhook endpoint details
177
+ *
178
+ * @throws {NotFoundError} If webhook not found
179
+ * @throws {OilPriceAPIError} If API request fails
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * const webhook = await client.webhooks.get('webhook-id');
184
+ * console.log(`${webhook.name}: ${webhook.url}`);
185
+ * console.log(`Success rate: ${webhook.successful_deliveries}/${webhook.successful_deliveries + webhook.failed_deliveries}`);
186
+ * ```
187
+ */
188
+ get(id: string): Promise<WebhookEndpoint>;
189
+ /**
190
+ * Create a new webhook endpoint
191
+ *
192
+ * @param params - Webhook configuration
193
+ * @returns Created webhook endpoint
194
+ *
195
+ * @throws {OilPriceAPIError} If API request fails
196
+ * @throws {AuthenticationError} If API key is invalid
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * const webhook = await client.webhooks.create({
201
+ * name: 'Production Alerts',
202
+ * url: 'https://api.myapp.com/webhooks',
203
+ * events: ['alert.triggered', 'price.updated'],
204
+ * secret: 'my-webhook-secret',
205
+ * enabled: true
206
+ * });
207
+ * console.log(`Webhook created: ${webhook.id}`);
208
+ * ```
209
+ */
210
+ create(params: CreateWebhookParams): Promise<WebhookEndpoint>;
211
+ /**
212
+ * Update a webhook endpoint
213
+ *
214
+ * @param id - Webhook ID
215
+ * @param params - Fields to update
216
+ * @returns Updated webhook endpoint
217
+ *
218
+ * @throws {NotFoundError} If webhook not found
219
+ * @throws {OilPriceAPIError} If API request fails
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * // Disable a webhook
224
+ * await client.webhooks.update(webhookId, { enabled: false });
225
+ *
226
+ * // Change events
227
+ * await client.webhooks.update(webhookId, {
228
+ * events: ['alert.triggered']
229
+ * });
230
+ * ```
231
+ */
232
+ update(id: string, params: UpdateWebhookParams): Promise<WebhookEndpoint>;
233
+ /**
234
+ * Delete a webhook endpoint
235
+ *
236
+ * @param id - Webhook ID
237
+ *
238
+ * @throws {NotFoundError} If webhook not found
239
+ * @throws {OilPriceAPIError} If API request fails
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * await client.webhooks.delete(webhookId);
244
+ * console.log('Webhook deleted');
245
+ * ```
246
+ */
247
+ delete(id: string): Promise<void>;
248
+ /**
249
+ * Test a webhook endpoint
250
+ *
251
+ * Sends a test payload to the webhook URL to verify it's reachable.
252
+ *
253
+ * @param id - Webhook ID
254
+ * @returns Test results
255
+ *
256
+ * @throws {NotFoundError} If webhook not found
257
+ * @throws {OilPriceAPIError} If API request fails
258
+ *
259
+ * @example
260
+ * ```typescript
261
+ * const test = await client.webhooks.test(webhookId);
262
+ * console.log(`Test ${test.success ? 'passed' : 'failed'}`);
263
+ * console.log(`Response time: ${test.response_time_ms}ms`);
264
+ * if (!test.success) {
265
+ * console.log(`Error: ${test.error}`);
266
+ * }
267
+ * ```
268
+ */
269
+ test(id: string): Promise<WebhookTestResponse>;
270
+ /**
271
+ * Get webhook event history
272
+ *
273
+ * Returns recent delivery events for a webhook.
274
+ *
275
+ * @param id - Webhook ID
276
+ * @returns Array of webhook events
277
+ *
278
+ * @throws {NotFoundError} If webhook not found
279
+ * @throws {OilPriceAPIError} If API request fails
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * const events = await client.webhooks.events(webhookId);
284
+ * events.forEach(event => {
285
+ * console.log(`${event.event_type}: ${event.status} (${event.attempts} attempts)`);
286
+ * });
287
+ * ```
288
+ */
289
+ events(id: string): Promise<WebhookEvent[]>;
290
+ /**
291
+ * Verify a webhook signature.
292
+ *
293
+ * Validates that a webhook payload was sent by OilPriceAPI by checking
294
+ * the HMAC-SHA256 signature. Uses constant-time comparison to prevent
295
+ * timing attacks.
296
+ *
297
+ * @param payload - Raw request body (string or Buffer)
298
+ * @param signature - Value of the X-OilPriceAPI-Signature header (e.g., "sha256=abc123...")
299
+ * @param secret - Your webhook signing secret
300
+ * @returns true if signature is valid
301
+ *
302
+ * @example
303
+ * ```typescript
304
+ * import express from 'express';
305
+ * import { OilPriceAPI } from 'oilpriceapi';
306
+ *
307
+ * const app = express();
308
+ * const client = new OilPriceAPI({ apiKey: 'your_key' });
309
+ *
310
+ * // Use raw body parser for webhook routes
311
+ * app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
312
+ * const signature = req.headers['x-oilpriceapi-signature'] as string;
313
+ * const isValid = client.webhooks.verifySignature(req.body, signature, 'your_secret');
314
+ *
315
+ * if (!isValid) {
316
+ * return res.status(401).send('Invalid signature');
317
+ * }
318
+ *
319
+ * const event = JSON.parse(req.body.toString());
320
+ * console.log('Verified webhook:', event.type);
321
+ * res.sendStatus(200);
322
+ * });
323
+ * ```
324
+ */
325
+ verifySignature(payload: string | Buffer, signature: string, secret: string): boolean;
326
+ }