finance-sentiment 2.2.0 → 2.3.1

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/dist/index.js CHANGED
@@ -8,13 +8,57 @@ var StockSentimentError = class extends Error {
8
8
  var ApiError = class extends StockSentimentError {
9
9
  status;
10
10
  detail;
11
- constructor(status, detail) {
11
+ payload;
12
+ constructor(status, detail, payload) {
12
13
  super(`${status}: ${detail}`);
13
14
  this.name = "ApiError";
14
15
  this.status = status;
15
16
  this.detail = detail;
17
+ this.payload = payload;
16
18
  }
17
19
  };
20
+ function isRecord(value) {
21
+ return typeof value === "object" && value !== null && !Array.isArray(value);
22
+ }
23
+ function formatValidationLocation(loc) {
24
+ if (Array.isArray(loc)) {
25
+ return loc.map(String).join(".");
26
+ }
27
+ return loc === void 0 || loc === null ? "" : String(loc);
28
+ }
29
+ function formatErrorDetail(detail) {
30
+ if (typeof detail === "string" && detail.trim()) {
31
+ return detail.trim();
32
+ }
33
+ if (Array.isArray(detail)) {
34
+ const messages = detail.map((item) => {
35
+ if (!isRecord(item)) return null;
36
+ const message = item.msg ?? item.message ?? item.error;
37
+ if (typeof message !== "string" || !message.trim()) return null;
38
+ const location = formatValidationLocation(item.loc);
39
+ return location ? `${location}: ${message.trim()}` : message.trim();
40
+ }).filter((message) => Boolean(message));
41
+ if (messages.length > 0) {
42
+ return messages.join("; ");
43
+ }
44
+ }
45
+ if (isRecord(detail)) {
46
+ for (const key of ["message", "error", "detail"]) {
47
+ const value = detail[key];
48
+ if (typeof value === "string" && value.trim()) {
49
+ return value.trim();
50
+ }
51
+ }
52
+ }
53
+ return JSON.stringify(detail);
54
+ }
55
+ function periodParams(options) {
56
+ return {
57
+ from: options.from,
58
+ to: options.to,
59
+ days: options.days
60
+ };
61
+ }
18
62
  var HttpClient = class {
19
63
  baseUrl;
20
64
  apiKey;
@@ -43,13 +87,14 @@ var HttpClient = class {
43
87
  });
44
88
  if (!response.ok) {
45
89
  let detail;
90
+ let payload;
46
91
  try {
47
- const body = await response.json();
48
- detail = body.detail ?? JSON.stringify(body);
92
+ payload = await response.json();
93
+ detail = isRecord(payload) && "detail" in payload ? formatErrorDetail(payload.detail) : JSON.stringify(payload);
49
94
  } catch {
50
95
  detail = response.statusText || `HTTP ${response.status}`;
51
96
  }
52
- throw new ApiError(response.status, detail);
97
+ throw new ApiError(response.status, detail, payload);
53
98
  }
54
99
  return response.json();
55
100
  }
@@ -73,7 +118,7 @@ var RedditNamespace = class extends PlatformNamespace {
73
118
  /** Get trending stocks on Reddit. */
74
119
  async trending(options = {}) {
75
120
  return this.request("/trending", {
76
- days: options.days,
121
+ ...periodParams(options),
77
122
  limit: options.limit,
78
123
  offset: options.offset,
79
124
  type: options.type
@@ -82,7 +127,7 @@ var RedditNamespace = class extends PlatformNamespace {
82
127
  /** Get trending sectors on Reddit. */
83
128
  async trendingSectors(options = {}) {
84
129
  return this.request("/trending/sectors", {
85
- days: options.days,
130
+ ...periodParams(options),
86
131
  limit: options.limit,
87
132
  offset: options.offset
88
133
  });
@@ -90,7 +135,7 @@ var RedditNamespace = class extends PlatformNamespace {
90
135
  /** Get trending countries on Reddit. */
91
136
  async trendingCountries(options = {}) {
92
137
  return this.request("/trending/countries", {
93
- days: options.days,
138
+ ...periodParams(options),
94
139
  limit: options.limit,
95
140
  offset: options.offset
96
141
  });
@@ -98,13 +143,13 @@ var RedditNamespace = class extends PlatformNamespace {
98
143
  /** Get sentiment for a specific stock ticker. */
99
144
  async stock(ticker, options = {}) {
100
145
  return this.request(`/stock/${encodeURIComponent(ticker)}`, {
101
- days: options.days
146
+ ...periodParams(options)
102
147
  });
103
148
  }
104
149
  /** Get raw Reddit mentions for a specific stock ticker. */
105
150
  async mentions(ticker, options = {}) {
106
151
  return this.request(`/stock/${encodeURIComponent(ticker)}/mentions`, {
107
- days: options.days,
152
+ ...periodParams(options),
108
153
  limit: options.limit,
109
154
  offset: options.offset,
110
155
  include_inherited: options.includeInherited?.toString()
@@ -118,7 +163,7 @@ var RedditNamespace = class extends PlatformNamespace {
118
163
  async search(query, options = {}) {
119
164
  return this.request("/search", {
120
165
  q: query,
121
- days: options.days,
166
+ ...periodParams(options),
122
167
  limit: options.limit
123
168
  });
124
169
  }
@@ -126,13 +171,13 @@ var RedditNamespace = class extends PlatformNamespace {
126
171
  async compare(tickers, options = {}) {
127
172
  return this.request("/compare", {
128
173
  tickers: tickers.join(","),
129
- days: options.days
174
+ ...periodParams(options)
130
175
  });
131
176
  }
132
177
  /** Get the service-level Reddit market sentiment snapshot. */
133
178
  async marketSentiment(options = {}) {
134
179
  return this.request("/market-sentiment", {
135
- days: options.days
180
+ ...periodParams(options)
136
181
  });
137
182
  }
138
183
  /** Get Reddit stock data statistics. */
@@ -152,7 +197,7 @@ var NewsNamespace = class extends PlatformNamespace {
152
197
  /** Get trending stocks from news. */
153
198
  async trending(options = {}) {
154
199
  return this.request("/trending", {
155
- days: options.days,
200
+ ...periodParams(options),
156
201
  limit: options.limit,
157
202
  offset: options.offset,
158
203
  type: options.type,
@@ -162,7 +207,7 @@ var NewsNamespace = class extends PlatformNamespace {
162
207
  /** Get trending sectors from news. */
163
208
  async trendingSectors(options = {}) {
164
209
  return this.request("/trending/sectors", {
165
- days: options.days,
210
+ ...periodParams(options),
166
211
  limit: options.limit,
167
212
  offset: options.offset,
168
213
  source: options.source
@@ -171,7 +216,7 @@ var NewsNamespace = class extends PlatformNamespace {
171
216
  /** Get trending countries from news. */
172
217
  async trendingCountries(options = {}) {
173
218
  return this.request("/trending/countries", {
174
- days: options.days,
219
+ ...periodParams(options),
175
220
  limit: options.limit,
176
221
  offset: options.offset,
177
222
  source: options.source
@@ -180,13 +225,13 @@ var NewsNamespace = class extends PlatformNamespace {
180
225
  /** Get sentiment for a specific stock ticker from news. */
181
226
  async stock(ticker, options = {}) {
182
227
  return this.request(`/stock/${encodeURIComponent(ticker)}`, {
183
- days: options.days
228
+ ...periodParams(options)
184
229
  });
185
230
  }
186
231
  /** Get raw news mentions for a specific stock ticker. */
187
232
  async mentions(ticker, options = {}) {
188
233
  return this.request(`/stock/${encodeURIComponent(ticker)}/mentions`, {
189
- days: options.days,
234
+ ...periodParams(options),
190
235
  limit: options.limit,
191
236
  offset: options.offset
192
237
  });
@@ -199,7 +244,7 @@ var NewsNamespace = class extends PlatformNamespace {
199
244
  async search(query, options = {}) {
200
245
  return this.request("/search", {
201
246
  q: query,
202
- days: options.days,
247
+ ...periodParams(options),
203
248
  limit: options.limit
204
249
  });
205
250
  }
@@ -207,13 +252,13 @@ var NewsNamespace = class extends PlatformNamespace {
207
252
  async compare(tickers, options = {}) {
208
253
  return this.request("/compare", {
209
254
  tickers: tickers.join(","),
210
- days: options.days
255
+ ...periodParams(options)
211
256
  });
212
257
  }
213
258
  /** Get the service-level News market sentiment snapshot. */
214
259
  async marketSentiment(options = {}) {
215
260
  return this.request("/market-sentiment", {
216
- days: options.days
261
+ ...periodParams(options)
217
262
  });
218
263
  }
219
264
  /** Get news data statistics. */
@@ -233,7 +278,7 @@ var XNamespace = class extends PlatformNamespace {
233
278
  /** Get trending stocks on X/Twitter. */
234
279
  async trending(options = {}) {
235
280
  return this.request("/trending", {
236
- days: options.days,
281
+ ...periodParams(options),
237
282
  limit: options.limit,
238
283
  offset: options.offset,
239
284
  type: options.type
@@ -242,7 +287,7 @@ var XNamespace = class extends PlatformNamespace {
242
287
  /** Get trending sectors on X/Twitter. */
243
288
  async trendingSectors(options = {}) {
244
289
  return this.request("/trending/sectors", {
245
- days: options.days,
290
+ ...periodParams(options),
246
291
  limit: options.limit,
247
292
  offset: options.offset
248
293
  });
@@ -250,7 +295,7 @@ var XNamespace = class extends PlatformNamespace {
250
295
  /** Get trending countries on X/Twitter. */
251
296
  async trendingCountries(options = {}) {
252
297
  return this.request("/trending/countries", {
253
- days: options.days,
298
+ ...periodParams(options),
254
299
  limit: options.limit,
255
300
  offset: options.offset
256
301
  });
@@ -258,13 +303,13 @@ var XNamespace = class extends PlatformNamespace {
258
303
  /** Get X/Twitter sentiment for a specific stock ticker. */
259
304
  async stock(ticker, options = {}) {
260
305
  return this.request(`/stock/${encodeURIComponent(ticker)}`, {
261
- days: options.days
306
+ ...periodParams(options)
262
307
  });
263
308
  }
264
309
  /** Get raw X/Twitter mentions for a specific stock ticker. */
265
310
  async mentions(ticker, options = {}) {
266
311
  return this.request(`/stock/${encodeURIComponent(ticker)}/mentions`, {
267
- days: options.days,
312
+ ...periodParams(options),
268
313
  limit: options.limit,
269
314
  offset: options.offset
270
315
  });
@@ -277,7 +322,7 @@ var XNamespace = class extends PlatformNamespace {
277
322
  async search(query, options = {}) {
278
323
  return this.request("/search", {
279
324
  q: query,
280
- days: options.days,
325
+ ...periodParams(options),
281
326
  limit: options.limit
282
327
  });
283
328
  }
@@ -285,13 +330,13 @@ var XNamespace = class extends PlatformNamespace {
285
330
  async compare(tickers, options = {}) {
286
331
  return this.request("/compare", {
287
332
  tickers: tickers.join(","),
288
- days: options.days
333
+ ...periodParams(options)
289
334
  });
290
335
  }
291
336
  /** Get the service-level X/Twitter market sentiment snapshot. */
292
337
  async marketSentiment(options = {}) {
293
338
  return this.request("/market-sentiment", {
294
- days: options.days
339
+ ...periodParams(options)
295
340
  });
296
341
  }
297
342
  /** Get X/Twitter data statistics. */
@@ -311,7 +356,7 @@ var PolymarketNamespace = class extends PlatformNamespace {
311
356
  /** Get trending stocks on Polymarket. */
312
357
  async trending(options = {}) {
313
358
  return this.request("/trending", {
314
- days: options.days,
359
+ ...periodParams(options),
315
360
  limit: options.limit,
316
361
  offset: options.offset,
317
362
  type: options.type
@@ -320,7 +365,7 @@ var PolymarketNamespace = class extends PlatformNamespace {
320
365
  /** Get trending sectors on Polymarket. */
321
366
  async trendingSectors(options = {}) {
322
367
  return this.request("/trending/sectors", {
323
- days: options.days,
368
+ ...periodParams(options),
324
369
  limit: options.limit,
325
370
  offset: options.offset
326
371
  });
@@ -328,7 +373,7 @@ var PolymarketNamespace = class extends PlatformNamespace {
328
373
  /** Get trending countries on Polymarket. */
329
374
  async trendingCountries(options = {}) {
330
375
  return this.request("/trending/countries", {
331
- days: options.days,
376
+ ...periodParams(options),
332
377
  limit: options.limit,
333
378
  offset: options.offset
334
379
  });
@@ -336,13 +381,13 @@ var PolymarketNamespace = class extends PlatformNamespace {
336
381
  /** Get Polymarket sentiment for a specific stock ticker. */
337
382
  async stock(ticker, options = {}) {
338
383
  return this.request(`/stock/${encodeURIComponent(ticker)}`, {
339
- days: options.days
384
+ ...periodParams(options)
340
385
  });
341
386
  }
342
387
  /** Get raw Polymarket snapshots for a specific stock ticker. */
343
388
  async mentions(ticker, options = {}) {
344
389
  return this.request(`/stock/${encodeURIComponent(ticker)}/mentions`, {
345
- days: options.days,
390
+ ...periodParams(options),
346
391
  limit: options.limit,
347
392
  offset: options.offset
348
393
  });
@@ -351,7 +396,7 @@ var PolymarketNamespace = class extends PlatformNamespace {
351
396
  async search(query, options = {}) {
352
397
  return this.request("/search", {
353
398
  q: query,
354
- days: options.days,
399
+ ...periodParams(options),
355
400
  limit: options.limit
356
401
  });
357
402
  }
@@ -359,13 +404,13 @@ var PolymarketNamespace = class extends PlatformNamespace {
359
404
  async compare(tickers, options = {}) {
360
405
  return this.request("/compare", {
361
406
  tickers: tickers.join(","),
362
- days: options.days
407
+ ...periodParams(options)
363
408
  });
364
409
  }
365
410
  /** Get the service-level Polymarket market sentiment snapshot. */
366
411
  async marketSentiment(options = {}) {
367
412
  return this.request("/market-sentiment", {
368
- days: options.days
413
+ ...periodParams(options)
369
414
  });
370
415
  }
371
416
  /** Get Polymarket data statistics. */
@@ -385,7 +430,7 @@ var RedditCryptoNamespace = class extends PlatformNamespace {
385
430
  /** Get trending crypto tokens on Reddit. */
386
431
  async trending(options = {}) {
387
432
  return this.request("/trending", {
388
- days: options.days,
433
+ ...periodParams(options),
389
434
  limit: options.limit,
390
435
  offset: options.offset
391
436
  });
@@ -393,13 +438,13 @@ var RedditCryptoNamespace = class extends PlatformNamespace {
393
438
  /** Get sentiment for a specific crypto token. */
394
439
  async token(symbol, options = {}) {
395
440
  return this.request(`/token/${encodeURIComponent(symbol)}`, {
396
- days: options.days
441
+ ...periodParams(options)
397
442
  });
398
443
  }
399
444
  /** Get raw Reddit mentions for a specific crypto token. */
400
445
  async mentions(symbol, options = {}) {
401
446
  return this.request(`/token/${encodeURIComponent(symbol)}/mentions`, {
402
- days: options.days,
447
+ ...periodParams(options),
403
448
  limit: options.limit,
404
449
  offset: options.offset,
405
450
  include_inherited: options.includeInherited?.toString()
@@ -409,7 +454,7 @@ var RedditCryptoNamespace = class extends PlatformNamespace {
409
454
  async search(query, options = {}) {
410
455
  return this.request("/search", {
411
456
  q: query,
412
- days: options.days,
457
+ ...periodParams(options),
413
458
  limit: options.limit
414
459
  });
415
460
  }
@@ -417,13 +462,13 @@ var RedditCryptoNamespace = class extends PlatformNamespace {
417
462
  async compare(symbols, options = {}) {
418
463
  return this.request("/compare", {
419
464
  symbols: symbols.join(","),
420
- days: options.days
465
+ ...periodParams(options)
421
466
  });
422
467
  }
423
468
  /** Get the service-level Reddit Crypto market sentiment snapshot. */
424
469
  async marketSentiment(options = {}) {
425
470
  return this.request("/market-sentiment", {
426
- days: options.days
471
+ ...periodParams(options)
427
472
  });
428
473
  }
429
474
  /** Get Reddit crypto data statistics. */