@fin.cx/opendata 3.2.0 → 3.3.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.
@@ -217,6 +217,7 @@ export class SecEdgarProvider implements IFundamentalsProvider {
217
217
  /**
218
218
  * Fetch the SEC ticker-to-CIK mapping list
219
219
  * Cached for 24 hours (list updates daily)
220
+ * Uses native fetch for automatic gzip decompression
220
221
  */
221
222
  private async fetchTickerList(): Promise<any> {
222
223
  // Check cache
@@ -230,29 +231,44 @@ export class SecEdgarProvider implements IFundamentalsProvider {
230
231
  // Wait for rate limit slot
231
232
  await this.rateLimiter.waitForSlot();
232
233
 
233
- // Fetch from SEC
234
- const response = await plugins.smartrequest.SmartRequest.create()
235
- .url(this.tickersUrl)
236
- .headers({
237
- 'User-Agent': this.userAgent,
238
- 'Accept': 'application/json'
239
- })
240
- .timeout(this.config.timeout)
241
- .get();
242
-
243
- const data = await response.json();
244
-
245
- // Cache the list
246
- this.tickerListCache = {
247
- data,
248
- timestamp: new Date()
249
- };
234
+ // Fetch from SEC using native fetch (handles gzip automatically)
235
+ const controller = new AbortController();
236
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
237
+
238
+ try {
239
+ const response = await fetch(this.tickersUrl, {
240
+ headers: {
241
+ 'User-Agent': this.userAgent,
242
+ 'Accept': 'application/json'
243
+ // Note: Accept-Encoding is set automatically by fetch
244
+ },
245
+ signal: controller.signal
246
+ });
247
+
248
+ clearTimeout(timeoutId);
249
+
250
+ if (!response.ok) {
251
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
252
+ }
253
+
254
+ const data = await response.json();
255
+
256
+ // Cache the list
257
+ this.tickerListCache = {
258
+ data,
259
+ timestamp: new Date()
260
+ };
250
261
 
251
- return data;
262
+ return data;
263
+ } catch (error) {
264
+ clearTimeout(timeoutId);
265
+ throw error;
266
+ }
252
267
  }
253
268
 
254
269
  /**
255
270
  * Fetch company facts from SEC EDGAR
271
+ * Uses native fetch for automatic gzip decompression
256
272
  */
257
273
  private async fetchCompanyFacts(cik: string): Promise<any> {
258
274
  // Pad CIK to 10 digits
@@ -262,26 +278,39 @@ export class SecEdgarProvider implements IFundamentalsProvider {
262
278
  // Wait for rate limit slot
263
279
  await this.rateLimiter.waitForSlot();
264
280
 
265
- // Fetch from SEC
266
- const response = await plugins.smartrequest.SmartRequest.create()
267
- .url(url)
268
- .headers({
269
- 'User-Agent': this.userAgent,
270
- 'Accept': 'application/json',
271
- 'Accept-Encoding': 'gzip, deflate',
272
- 'Host': 'data.sec.gov'
273
- })
274
- .timeout(this.config.timeout)
275
- .get();
276
-
277
- const data = await response.json();
278
-
279
- // Validate response
280
- if (!data || !data.facts) {
281
- throw new Error('Invalid response from SEC EDGAR API');
282
- }
281
+ // Fetch from SEC using native fetch (handles gzip automatically)
282
+ const controller = new AbortController();
283
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
283
284
 
284
- return data;
285
+ try {
286
+ const response = await fetch(url, {
287
+ headers: {
288
+ 'User-Agent': this.userAgent,
289
+ 'Accept': 'application/json',
290
+ 'Host': 'data.sec.gov'
291
+ // Note: Accept-Encoding is set automatically by fetch and gzip is handled transparently
292
+ },
293
+ signal: controller.signal
294
+ });
295
+
296
+ clearTimeout(timeoutId);
297
+
298
+ if (!response.ok) {
299
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
300
+ }
301
+
302
+ const data = await response.json();
303
+
304
+ // Validate response
305
+ if (!data || !data.facts) {
306
+ throw new Error('Invalid response from SEC EDGAR API');
307
+ }
308
+
309
+ return data;
310
+ } catch (error) {
311
+ clearTimeout(timeoutId);
312
+ throw error;
313
+ }
285
314
  }
286
315
 
287
316
  /**
@@ -382,20 +411,29 @@ export class SecEdgarProvider implements IFundamentalsProvider {
382
411
 
383
412
  /**
384
413
  * Check if SEC EDGAR API is available
414
+ * Uses native fetch for automatic gzip decompression
385
415
  */
386
416
  public async isAvailable(): Promise<boolean> {
387
417
  try {
388
418
  // Test with Apple's well-known CIK
389
419
  const url = `${this.baseUrl}/companyfacts/CIK0000320193.json`;
390
420
 
391
- const response = await plugins.smartrequest.SmartRequest.create()
392
- .url(url)
393
- .headers({
421
+ const controller = new AbortController();
422
+ const timeoutId = setTimeout(() => controller.abort(), 5000);
423
+
424
+ const response = await fetch(url, {
425
+ headers: {
394
426
  'User-Agent': this.userAgent,
395
427
  'Accept': 'application/json'
396
- })
397
- .timeout(5000)
398
- .get();
428
+ },
429
+ signal: controller.signal
430
+ });
431
+
432
+ clearTimeout(timeoutId);
433
+
434
+ if (!response.ok) {
435
+ return false;
436
+ }
399
437
 
400
438
  const data = await response.json();
401
439
  return data && data.facts !== undefined;