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,365 @@
1
+ /**
2
+ * Data Sources Resource
3
+ *
4
+ * Manage custom data source integrations for Bring Your Own Source (BYOS) feature.
5
+ */
6
+ import type { OilPriceAPI } from "../client.js";
7
+ /**
8
+ * Data source types
9
+ */
10
+ export type DataSourceType = "api" | "database" | "file" | "sftp" | "webhook" | "custom";
11
+ /**
12
+ * Data source status
13
+ */
14
+ export type DataSourceStatus = "active" | "paused" | "error" | "pending";
15
+ /**
16
+ * Data source configuration
17
+ */
18
+ export interface DataSource {
19
+ /** Unique data source identifier */
20
+ id: string;
21
+ /** User-friendly name */
22
+ name: string;
23
+ /** Data source type */
24
+ type: DataSourceType;
25
+ /** Connection configuration (encrypted) */
26
+ config: Record<string, unknown>;
27
+ /** Whether the data source is active */
28
+ enabled: boolean;
29
+ /** Current status */
30
+ status: DataSourceStatus;
31
+ /** Last successful sync timestamp */
32
+ last_sync_at?: string;
33
+ /** Next scheduled sync timestamp */
34
+ next_sync_at?: string;
35
+ /** Sync frequency in minutes */
36
+ sync_frequency_minutes?: number;
37
+ /** Number of successful syncs */
38
+ successful_syncs: number;
39
+ /** Number of failed syncs */
40
+ failed_syncs: number;
41
+ /** Last error message */
42
+ last_error?: string;
43
+ /** Optional metadata */
44
+ metadata?: Record<string, unknown>;
45
+ /** ISO timestamp when source was created */
46
+ created_at: string;
47
+ /** ISO timestamp when source was last updated */
48
+ updated_at: string;
49
+ }
50
+ /**
51
+ * Parameters for creating a data source
52
+ */
53
+ export interface CreateDataSourceParams {
54
+ /** User-friendly name */
55
+ name: string;
56
+ /** Data source type */
57
+ type: DataSourceType;
58
+ /** Connection configuration */
59
+ config: Record<string, unknown>;
60
+ /** Whether to enable immediately (default: true) */
61
+ enabled?: boolean;
62
+ /** Sync frequency in minutes (default: 60) */
63
+ sync_frequency_minutes?: number;
64
+ /** Optional metadata */
65
+ metadata?: Record<string, unknown>;
66
+ }
67
+ /**
68
+ * Parameters for updating a data source
69
+ */
70
+ export interface UpdateDataSourceParams {
71
+ /** User-friendly name */
72
+ name?: string;
73
+ /** Connection configuration */
74
+ config?: Record<string, unknown>;
75
+ /** Whether the data source is active */
76
+ enabled?: boolean;
77
+ /** Sync frequency in minutes */
78
+ sync_frequency_minutes?: number;
79
+ /** Metadata */
80
+ metadata?: Record<string, unknown>;
81
+ }
82
+ /**
83
+ * Data source test response
84
+ */
85
+ export interface DataSourceTestResponse {
86
+ /** Test result status */
87
+ success: boolean;
88
+ /** Connection test duration in milliseconds */
89
+ duration_ms: number;
90
+ /** Number of records fetched in test */
91
+ records_count?: number;
92
+ /** Sample data */
93
+ sample_data?: Record<string, unknown>[];
94
+ /** Error message if test failed */
95
+ error?: string;
96
+ }
97
+ /**
98
+ * Data source sync log entry
99
+ */
100
+ export interface DataSourceLog {
101
+ /** Log entry ID */
102
+ id: string;
103
+ /** Data source ID */
104
+ data_source_id: string;
105
+ /** Sync status */
106
+ status: "success" | "failed";
107
+ /** Number of records synced */
108
+ records_synced?: number;
109
+ /** Sync duration in milliseconds */
110
+ duration_ms?: number;
111
+ /** Error message if sync failed */
112
+ error?: string;
113
+ /** ISO timestamp when sync started */
114
+ started_at: string;
115
+ /** ISO timestamp when sync completed */
116
+ completed_at?: string;
117
+ }
118
+ /**
119
+ * Data source health metrics
120
+ */
121
+ export interface DataSourceHealth {
122
+ /** Data source ID */
123
+ id: string;
124
+ /** Overall health status */
125
+ status: "healthy" | "degraded" | "down";
126
+ /** Success rate (0-100) */
127
+ success_rate: number;
128
+ /** Average sync duration in milliseconds */
129
+ avg_duration_ms: number;
130
+ /** Last sync status */
131
+ last_sync_status?: "success" | "failed";
132
+ /** Last sync timestamp */
133
+ last_sync_at?: string;
134
+ /** Recent errors */
135
+ recent_errors?: string[];
136
+ }
137
+ /**
138
+ * Credential rotation response
139
+ */
140
+ export interface CredentialRotationResponse {
141
+ /** Whether rotation was successful */
142
+ success: boolean;
143
+ /** New credential ID or reference */
144
+ credential_id?: string;
145
+ /** Message */
146
+ message?: string;
147
+ }
148
+ /**
149
+ * Data Sources Resource
150
+ *
151
+ * Manage custom data source integrations for importing your own price data
152
+ * into the platform (BYOS - Bring Your Own Source feature).
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * import { OilPriceAPI } from 'oilpriceapi';
157
+ *
158
+ * const client = new OilPriceAPI({ apiKey: 'your_key' });
159
+ *
160
+ * // Create a data source
161
+ * const source = await client.dataSources.create({
162
+ * name: 'Internal Price Feed',
163
+ * type: 'api',
164
+ * config: {
165
+ * url: 'https://internal.company.com/api/prices',
166
+ * auth_type: 'bearer',
167
+ * token: 'secret-token'
168
+ * },
169
+ * sync_frequency_minutes: 30
170
+ * });
171
+ *
172
+ * // Test the data source
173
+ * const test = await client.dataSources.test(source.id);
174
+ * console.log(`Test result: ${test.success}`);
175
+ *
176
+ * // Check health
177
+ * const health = await client.dataSources.health(source.id);
178
+ * console.log(`Health: ${health.status}`);
179
+ * console.log(`Success rate: ${health.success_rate}%`);
180
+ *
181
+ * // View sync logs
182
+ * const logs = await client.dataSources.logs(source.id);
183
+ * logs.forEach(log => {
184
+ * console.log(`${log.started_at}: ${log.status} - ${log.records_synced} records`);
185
+ * });
186
+ * ```
187
+ */
188
+ export declare class DataSourcesResource {
189
+ private client;
190
+ constructor(client: OilPriceAPI);
191
+ /**
192
+ * List all data sources
193
+ *
194
+ * @returns Array of data sources
195
+ *
196
+ * @throws {OilPriceAPIError} If API request fails
197
+ * @throws {AuthenticationError} If API key is invalid
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * const sources = await client.dataSources.list();
202
+ * sources.forEach(source => {
203
+ * console.log(`${source.name}: ${source.status}`);
204
+ * console.log(` Success rate: ${source.successful_syncs}/${source.successful_syncs + source.failed_syncs}`);
205
+ * });
206
+ * ```
207
+ */
208
+ list(): Promise<DataSource[]>;
209
+ /**
210
+ * Get a specific data source
211
+ *
212
+ * @param id - Data source ID
213
+ * @returns Data source details
214
+ *
215
+ * @throws {NotFoundError} If data source not found
216
+ * @throws {OilPriceAPIError} If API request fails
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * const source = await client.dataSources.get('source-id');
221
+ * console.log(`${source.name} (${source.type})`);
222
+ * console.log(`Last sync: ${source.last_sync_at}`);
223
+ * ```
224
+ */
225
+ get(id: string): Promise<DataSource>;
226
+ /**
227
+ * Create a new data source
228
+ *
229
+ * @param params - Data source configuration
230
+ * @returns Created data source
231
+ *
232
+ * @throws {OilPriceAPIError} If API request fails
233
+ * @throws {AuthenticationError} If API key is invalid
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * const source = await client.dataSources.create({
238
+ * name: 'SFTP Price Feed',
239
+ * type: 'sftp',
240
+ * config: {
241
+ * host: 'sftp.example.com',
242
+ * username: 'user',
243
+ * password: 'pass',
244
+ * path: '/prices/daily.csv'
245
+ * },
246
+ * sync_frequency_minutes: 1440 // Daily
247
+ * });
248
+ * ```
249
+ */
250
+ create(params: CreateDataSourceParams): Promise<DataSource>;
251
+ /**
252
+ * Update a data source
253
+ *
254
+ * @param id - Data source ID
255
+ * @param params - Fields to update
256
+ * @returns Updated data source
257
+ *
258
+ * @throws {NotFoundError} If data source not found
259
+ * @throws {OilPriceAPIError} If API request fails
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * // Pause a data source
264
+ * await client.dataSources.update(sourceId, { enabled: false });
265
+ *
266
+ * // Update sync frequency
267
+ * await client.dataSources.update(sourceId, {
268
+ * sync_frequency_minutes: 120
269
+ * });
270
+ * ```
271
+ */
272
+ update(id: string, params: UpdateDataSourceParams): Promise<DataSource>;
273
+ /**
274
+ * Delete a data source
275
+ *
276
+ * @param id - Data source ID
277
+ *
278
+ * @throws {NotFoundError} If data source not found
279
+ * @throws {OilPriceAPIError} If API request fails
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * await client.dataSources.delete(sourceId);
284
+ * console.log('Data source deleted');
285
+ * ```
286
+ */
287
+ delete(id: string): Promise<void>;
288
+ /**
289
+ * Test a data source connection
290
+ *
291
+ * @param id - Data source ID
292
+ * @returns Test results
293
+ *
294
+ * @throws {NotFoundError} If data source not found
295
+ * @throws {OilPriceAPIError} If API request fails
296
+ *
297
+ * @example
298
+ * ```typescript
299
+ * const test = await client.dataSources.test(sourceId);
300
+ * console.log(`Connection test: ${test.success ? 'passed' : 'failed'}`);
301
+ * console.log(`Duration: ${test.duration_ms}ms`);
302
+ * if (test.sample_data) {
303
+ * console.log(`Sample records: ${test.sample_data.length}`);
304
+ * }
305
+ * ```
306
+ */
307
+ test(id: string): Promise<DataSourceTestResponse>;
308
+ /**
309
+ * Get data source sync logs
310
+ *
311
+ * @param id - Data source ID
312
+ * @returns Array of sync log entries
313
+ *
314
+ * @throws {NotFoundError} If data source not found
315
+ * @throws {OilPriceAPIError} If API request fails
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * const logs = await client.dataSources.logs(sourceId);
320
+ * logs.forEach(log => {
321
+ * console.log(`${log.started_at}: ${log.status}`);
322
+ * if (log.records_synced) {
323
+ * console.log(` ${log.records_synced} records in ${log.duration_ms}ms`);
324
+ * }
325
+ * });
326
+ * ```
327
+ */
328
+ logs(id: string): Promise<DataSourceLog[]>;
329
+ /**
330
+ * Get data source health metrics
331
+ *
332
+ * @param id - Data source ID
333
+ * @returns Health metrics
334
+ *
335
+ * @throws {NotFoundError} If data source not found
336
+ * @throws {OilPriceAPIError} If API request fails
337
+ *
338
+ * @example
339
+ * ```typescript
340
+ * const health = await client.dataSources.health(sourceId);
341
+ * console.log(`Status: ${health.status}`);
342
+ * console.log(`Success rate: ${health.success_rate}%`);
343
+ * console.log(`Avg duration: ${health.avg_duration_ms}ms`);
344
+ * ```
345
+ */
346
+ health(id: string): Promise<DataSourceHealth>;
347
+ /**
348
+ * Rotate data source credentials
349
+ *
350
+ * Updates stored credentials with new values and re-encrypts them.
351
+ *
352
+ * @param id - Data source ID
353
+ * @returns Rotation result
354
+ *
355
+ * @throws {NotFoundError} If data source not found
356
+ * @throws {OilPriceAPIError} If API request fails
357
+ *
358
+ * @example
359
+ * ```typescript
360
+ * const result = await client.dataSources.rotateCredentials(sourceId);
361
+ * console.log(`Credential rotation: ${result.success ? 'success' : 'failed'}`);
362
+ * ```
363
+ */
364
+ rotateCredentials(id: string): Promise<CredentialRotationResponse>;
365
+ }
@@ -0,0 +1,293 @@
1
+ /**
2
+ * Data Sources Resource
3
+ *
4
+ * Manage custom data source integrations for Bring Your Own Source (BYOS) feature.
5
+ */
6
+ import { ValidationError } from "../errors.js";
7
+ /**
8
+ * Data Sources Resource
9
+ *
10
+ * Manage custom data source integrations for importing your own price data
11
+ * into the platform (BYOS - Bring Your Own Source feature).
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { OilPriceAPI } from 'oilpriceapi';
16
+ *
17
+ * const client = new OilPriceAPI({ apiKey: 'your_key' });
18
+ *
19
+ * // Create a data source
20
+ * const source = await client.dataSources.create({
21
+ * name: 'Internal Price Feed',
22
+ * type: 'api',
23
+ * config: {
24
+ * url: 'https://internal.company.com/api/prices',
25
+ * auth_type: 'bearer',
26
+ * token: 'secret-token'
27
+ * },
28
+ * sync_frequency_minutes: 30
29
+ * });
30
+ *
31
+ * // Test the data source
32
+ * const test = await client.dataSources.test(source.id);
33
+ * console.log(`Test result: ${test.success}`);
34
+ *
35
+ * // Check health
36
+ * const health = await client.dataSources.health(source.id);
37
+ * console.log(`Health: ${health.status}`);
38
+ * console.log(`Success rate: ${health.success_rate}%`);
39
+ *
40
+ * // View sync logs
41
+ * const logs = await client.dataSources.logs(source.id);
42
+ * logs.forEach(log => {
43
+ * console.log(`${log.started_at}: ${log.status} - ${log.records_synced} records`);
44
+ * });
45
+ * ```
46
+ */
47
+ export class DataSourcesResource {
48
+ constructor(client) {
49
+ this.client = client;
50
+ }
51
+ /**
52
+ * List all data sources
53
+ *
54
+ * @returns Array of data sources
55
+ *
56
+ * @throws {OilPriceAPIError} If API request fails
57
+ * @throws {AuthenticationError} If API key is invalid
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const sources = await client.dataSources.list();
62
+ * sources.forEach(source => {
63
+ * console.log(`${source.name}: ${source.status}`);
64
+ * console.log(` Success rate: ${source.successful_syncs}/${source.successful_syncs + source.failed_syncs}`);
65
+ * });
66
+ * ```
67
+ */
68
+ async list() {
69
+ const response = await this.client["request"]("/v1/data-sources", {});
70
+ return Array.isArray(response) ? response : response.data_sources;
71
+ }
72
+ /**
73
+ * Get a specific data source
74
+ *
75
+ * @param id - Data source ID
76
+ * @returns Data source details
77
+ *
78
+ * @throws {NotFoundError} If data source not found
79
+ * @throws {OilPriceAPIError} If API request fails
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const source = await client.dataSources.get('source-id');
84
+ * console.log(`${source.name} (${source.type})`);
85
+ * console.log(`Last sync: ${source.last_sync_at}`);
86
+ * ```
87
+ */
88
+ async get(id) {
89
+ if (!id || typeof id !== "string") {
90
+ throw new ValidationError("Data source ID must be a non-empty string");
91
+ }
92
+ const response = await this.client["request"](`/v1/data-sources/${id}`, {});
93
+ return "data_source" in response ? response.data_source : response;
94
+ }
95
+ /**
96
+ * Create a new data source
97
+ *
98
+ * @param params - Data source configuration
99
+ * @returns Created data source
100
+ *
101
+ * @throws {OilPriceAPIError} If API request fails
102
+ * @throws {AuthenticationError} If API key is invalid
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const source = await client.dataSources.create({
107
+ * name: 'SFTP Price Feed',
108
+ * type: 'sftp',
109
+ * config: {
110
+ * host: 'sftp.example.com',
111
+ * username: 'user',
112
+ * password: 'pass',
113
+ * path: '/prices/daily.csv'
114
+ * },
115
+ * sync_frequency_minutes: 1440 // Daily
116
+ * });
117
+ * ```
118
+ */
119
+ async create(params) {
120
+ if (!params.name || typeof params.name !== "string") {
121
+ throw new ValidationError("Data source name is required");
122
+ }
123
+ if (!params.type) {
124
+ throw new ValidationError("Data source type is required");
125
+ }
126
+ if (!params.config || typeof params.config !== "object") {
127
+ throw new ValidationError("Data source config is required");
128
+ }
129
+ const response = await this.client["request"]("/v1/data-sources", {}, {
130
+ method: "POST",
131
+ body: {
132
+ data_source: {
133
+ name: params.name,
134
+ type: params.type,
135
+ config: params.config,
136
+ enabled: params.enabled ?? true,
137
+ sync_frequency_minutes: params.sync_frequency_minutes ?? 60,
138
+ metadata: params.metadata,
139
+ },
140
+ },
141
+ });
142
+ return "data_source" in response ? response.data_source : response;
143
+ }
144
+ /**
145
+ * Update a data source
146
+ *
147
+ * @param id - Data source ID
148
+ * @param params - Fields to update
149
+ * @returns Updated data source
150
+ *
151
+ * @throws {NotFoundError} If data source not found
152
+ * @throws {OilPriceAPIError} If API request fails
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * // Pause a data source
157
+ * await client.dataSources.update(sourceId, { enabled: false });
158
+ *
159
+ * // Update sync frequency
160
+ * await client.dataSources.update(sourceId, {
161
+ * sync_frequency_minutes: 120
162
+ * });
163
+ * ```
164
+ */
165
+ async update(id, params) {
166
+ if (!id || typeof id !== "string") {
167
+ throw new ValidationError("Data source ID must be a non-empty string");
168
+ }
169
+ const response = await this.client["request"](`/v1/data-sources/${id}`, {}, {
170
+ method: "PATCH",
171
+ body: { data_source: params },
172
+ });
173
+ return "data_source" in response ? response.data_source : response;
174
+ }
175
+ /**
176
+ * Delete a data source
177
+ *
178
+ * @param id - Data source ID
179
+ *
180
+ * @throws {NotFoundError} If data source not found
181
+ * @throws {OilPriceAPIError} If API request fails
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * await client.dataSources.delete(sourceId);
186
+ * console.log('Data source deleted');
187
+ * ```
188
+ */
189
+ async delete(id) {
190
+ if (!id || typeof id !== "string") {
191
+ throw new ValidationError("Data source ID must be a non-empty string");
192
+ }
193
+ await this.client["request"](`/v1/data-sources/${id}`, {}, { method: "DELETE" });
194
+ }
195
+ /**
196
+ * Test a data source connection
197
+ *
198
+ * @param id - Data source ID
199
+ * @returns Test results
200
+ *
201
+ * @throws {NotFoundError} If data source not found
202
+ * @throws {OilPriceAPIError} If API request fails
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * const test = await client.dataSources.test(sourceId);
207
+ * console.log(`Connection test: ${test.success ? 'passed' : 'failed'}`);
208
+ * console.log(`Duration: ${test.duration_ms}ms`);
209
+ * if (test.sample_data) {
210
+ * console.log(`Sample records: ${test.sample_data.length}`);
211
+ * }
212
+ * ```
213
+ */
214
+ async test(id) {
215
+ if (!id || typeof id !== "string") {
216
+ throw new ValidationError("Data source ID must be a non-empty string");
217
+ }
218
+ return this.client["request"](`/v1/data-sources/${id}/test`, {}, { method: "POST" });
219
+ }
220
+ /**
221
+ * Get data source sync logs
222
+ *
223
+ * @param id - Data source ID
224
+ * @returns Array of sync log entries
225
+ *
226
+ * @throws {NotFoundError} If data source not found
227
+ * @throws {OilPriceAPIError} If API request fails
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const logs = await client.dataSources.logs(sourceId);
232
+ * logs.forEach(log => {
233
+ * console.log(`${log.started_at}: ${log.status}`);
234
+ * if (log.records_synced) {
235
+ * console.log(` ${log.records_synced} records in ${log.duration_ms}ms`);
236
+ * }
237
+ * });
238
+ * ```
239
+ */
240
+ async logs(id) {
241
+ if (!id || typeof id !== "string") {
242
+ throw new ValidationError("Data source ID must be a non-empty string");
243
+ }
244
+ const response = await this.client["request"](`/v1/data-sources/${id}/logs`, {});
245
+ return Array.isArray(response) ? response : response.logs;
246
+ }
247
+ /**
248
+ * Get data source health metrics
249
+ *
250
+ * @param id - Data source ID
251
+ * @returns Health metrics
252
+ *
253
+ * @throws {NotFoundError} If data source not found
254
+ * @throws {OilPriceAPIError} If API request fails
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * const health = await client.dataSources.health(sourceId);
259
+ * console.log(`Status: ${health.status}`);
260
+ * console.log(`Success rate: ${health.success_rate}%`);
261
+ * console.log(`Avg duration: ${health.avg_duration_ms}ms`);
262
+ * ```
263
+ */
264
+ async health(id) {
265
+ if (!id || typeof id !== "string") {
266
+ throw new ValidationError("Data source ID must be a non-empty string");
267
+ }
268
+ return this.client["request"](`/v1/data-sources/${id}/health`, {});
269
+ }
270
+ /**
271
+ * Rotate data source credentials
272
+ *
273
+ * Updates stored credentials with new values and re-encrypts them.
274
+ *
275
+ * @param id - Data source ID
276
+ * @returns Rotation result
277
+ *
278
+ * @throws {NotFoundError} If data source not found
279
+ * @throws {OilPriceAPIError} If API request fails
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * const result = await client.dataSources.rotateCredentials(sourceId);
284
+ * console.log(`Credential rotation: ${result.success ? 'success' : 'failed'}`);
285
+ * ```
286
+ */
287
+ async rotateCredentials(id) {
288
+ if (!id || typeof id !== "string") {
289
+ throw new ValidationError("Data source ID must be a non-empty string");
290
+ }
291
+ return this.client["request"](`/v1/data-sources/${id}/rotate-credentials`, {}, { method: "POST" });
292
+ }
293
+ }
@@ -1,4 +1,4 @@
1
- import type { OilPriceAPI } from '../client.js';
1
+ import type { OilPriceAPI } from "../client.js";
2
2
  /**
3
3
  * Diesel price data for a specific state or region
4
4
  */