sentisense 0.77.0 → 0.78.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.
package/dist/cli.cjs CHANGED
@@ -3,22 +3,23 @@
3
3
 
4
4
  // src/errors.ts
5
5
  var SentiSenseError = class extends Error {
6
- constructor(message, status, code) {
6
+ constructor(message, status, code, body) {
7
7
  super(message);
8
8
  this.name = "SentiSenseError";
9
9
  this.status = status;
10
10
  this.code = code;
11
+ this.body = body;
11
12
  }
12
13
  };
13
14
  var AuthenticationError = class extends SentiSenseError {
14
- constructor(message, status, code) {
15
- super(message, status, code);
15
+ constructor(message, status, code, body) {
16
+ super(message, status, code, body);
16
17
  this.name = "AuthenticationError";
17
18
  }
18
19
  };
19
20
  var NotFoundError = class extends SentiSenseError {
20
- constructor(message, code) {
21
- super(message, 404, code);
21
+ constructor(message, code, body) {
22
+ super(message, 404, code, body);
22
23
  this.name = "NotFoundError";
23
24
  }
24
25
  };
@@ -30,22 +31,22 @@ var DeepHistoryUnavailableError = class extends SentiSenseError {
30
31
  }
31
32
  };
32
33
  var RateLimitError = class extends SentiSenseError {
33
- constructor(message, code, retryAfter) {
34
- super(message, 429, code);
34
+ constructor(message, code, retryAfter, body) {
35
+ super(message, 429, code, body);
35
36
  this.name = "RateLimitError";
36
37
  this.retryAfter = retryAfter;
37
38
  }
38
39
  };
39
40
  var TemporarilyUnavailableError = class extends SentiSenseError {
40
- constructor(message, retryAfter, code) {
41
- super(message, 503, code);
41
+ constructor(message, retryAfter, code, body) {
42
+ super(message, 503, code, body);
42
43
  this.name = "TemporarilyUnavailableError";
43
44
  this.retryAfter = retryAfter;
44
45
  }
45
46
  };
46
47
  var APIError = class extends SentiSenseError {
47
- constructor(message, status, code) {
48
- super(message, status, code);
48
+ constructor(message, status, code, body) {
49
+ super(message, status, code, body);
49
50
  this.name = "APIError";
50
51
  }
51
52
  };
@@ -388,8 +389,11 @@ var analystCommand = {
388
389
  "firstSeen and lastSeen bound the notes on record, not employment: the most recent firm",
389
390
  "is where they last published, not necessarily where they work today.",
390
391
  NOT_A_SCORECARD,
391
- "A slug that matches no analyst exits 4."
392
+ "A slug that matches no analyst exits 4.",
393
+ "--json prints the profile response. With --calls it is one object combining two responses,",
394
+ '"profile" and "calls", each the API response with its envelope.'
392
395
  ],
396
+ jsonShape: 'Print the profile response as JSON; with --calls, {"profile": ..., "calls": ...}',
393
397
  flags: {
394
398
  calls: { type: "boolean", describe: "Append their price target notes, newest first" },
395
399
  limit: { type: "number", placeholder: "N", describe: `Calls to request, 1 to 200 (default ${DEFAULT_CALLS})` }
@@ -575,13 +579,45 @@ async function verifyTickerOnEmpty(api, ticker) {
575
579
  function isEtfRedirect(error) {
576
580
  return error instanceof APIError && error.code === "ticker_is_etf";
577
581
  }
582
+ var ETF_QUOTE_PATH = /^\/api\/v1\/etfs\/([^/?#]+)\/quote$/i;
583
+ function etfQuoteSymbol(quote, ticker) {
584
+ if (!Array.isArray(quote.seeInstead)) return void 0;
585
+ const own = /* @__PURE__ */ new Set([ticker.toUpperCase()]);
586
+ if (typeof quote.ticker === "string") own.add(quote.ticker.toUpperCase());
587
+ for (const path of quote.seeInstead) {
588
+ if (typeof path !== "string") continue;
589
+ const match = ETF_QUOTE_PATH.exec(path);
590
+ if (!match) continue;
591
+ let symbol;
592
+ try {
593
+ symbol = decodeURIComponent(match[1]);
594
+ } catch {
595
+ continue;
596
+ }
597
+ if (own.has(symbol.toUpperCase())) return symbol;
598
+ }
599
+ return void 0;
600
+ }
578
601
  async function quoteAnyTicker(api, ticker) {
602
+ let quote;
579
603
  try {
580
- return { kind: "stock", quote: await api.stocks.getQuote(ticker) };
604
+ quote = await api.stocks.getQuote(ticker);
581
605
  } catch (error) {
582
606
  if (!isEtfRedirect(error)) throw error;
583
607
  return { kind: "etf", quote: await api.etfs.quote(ticker) };
584
608
  }
609
+ const fund = etfQuoteSymbol(quote, ticker);
610
+ if (fund === void 0) return { kind: "stock", quote };
611
+ try {
612
+ return { kind: "etf", quote: await api.etfs.quote(fund) };
613
+ } catch (error) {
614
+ const reason = error instanceof Error ? error.message : String(error);
615
+ return {
616
+ kind: "stock",
617
+ quote,
618
+ note: `${ticker}: the fund quote failed (${reason}), so AUM, expense ratio and NAV are missing`
619
+ };
620
+ }
585
621
  }
586
622
  var EMPTY_VERIFY_NOTE = "An empty result verifies the ticker before reporting no data, so a typo exits 4 rather";
587
623
  var EMPTY_VERIFY_NOTE_2 = "than looking like a company with nothing to report.";
@@ -641,8 +677,12 @@ var analystsCommand = {
641
677
  '"$400 to $200" when it moved from a prior target. It is blank when the firm stated',
642
678
  "none, and blank on a free key outside the sample companies.",
643
679
  "--limit trims the rows printed under --coverage; the API returns the whole book either",
644
- "way, and --full prints all of it."
680
+ "way, and --full prints all of it.",
681
+ '--json prints one object combining two responses: "consensus" and "actions", each the API',
682
+ 'response with its envelope ("actions" is null if that call failed). With --coverage it is',
683
+ "the coverage response alone."
645
684
  ],
685
+ jsonShape: 'Print {"consensus": ..., "actions": ...} as JSON; with --coverage, the coverage response',
646
686
  flags: {
647
687
  coverage: { type: "boolean", describe: "Show who covers the ticker, one row per firm" },
648
688
  days: { type: "number", placeholder: "N", describe: "Days of rating history (default 90)" },
@@ -1449,7 +1489,7 @@ var flowsCommand = {
1449
1489
  };
1450
1490
 
1451
1491
  // src/version.ts
1452
- var VERSION = "0.77.0";
1492
+ var VERSION = "0.78.0";
1453
1493
 
1454
1494
  // src/resources/analyst.ts
1455
1495
  var Analyst = class {
@@ -1838,13 +1878,18 @@ var EntityMetrics = class {
1838
1878
  *
1839
1879
  * @param symbol Ticker symbol (e.g. "AAPL") or entity urlSlug.
1840
1880
  * @param metricType The metric to break down (e.g. "mentions" or "sentiment").
1841
- * @param options Optional dimension parameter.
1881
+ * @param options Optional dimension, and an optional window as `startTime` / `endTime` in
1882
+ * epoch milliseconds. Without a window the API uses the last 7 days.
1842
1883
  */
1843
1884
  async getDistribution(symbol, metricType, options = {}) {
1844
- const { dimension = "source" } = options;
1885
+ const { dimension = "source", startTime, endTime } = options;
1845
1886
  return this.client.get(
1846
1887
  `/api/v2/metrics/entity/${encodeURIComponent(symbol)}/distribution/${encodeURIComponent(metricType)}`,
1847
- { dimension }
1888
+ {
1889
+ dimension,
1890
+ ...startTime !== void 0 && { startTime },
1891
+ ...endTime !== void 0 && { endTime }
1892
+ }
1848
1893
  );
1849
1894
  }
1850
1895
  };
@@ -2526,6 +2571,9 @@ var Stocks = class {
2526
2571
  * Get aggregate quote snapshot: live price, today OHLC, 52-week range,
2527
2572
  * market cap, P/E, EPS TTM, and dividend yield in a single call.
2528
2573
  * All fields except `ticker` may be null when upstream data is unavailable.
2574
+ *
2575
+ * A fund ticker gets a normal quote without AUM or NAV, plus `seeInstead` pointing at the
2576
+ * fund quote when that covers it: call `etfs.quote()` for those fields.
2529
2577
  */
2530
2578
  async getQuote(ticker) {
2531
2579
  return this.client.get(`/api/v1/stocks/${encodeURIComponent(ticker)}/quote`);
@@ -2654,6 +2702,18 @@ var Stocks = class {
2654
2702
  async getFundamentals(ticker, options) {
2655
2703
  return this.client.get("/api/v1/stocks/fundamentals", { ticker, ...options });
2656
2704
  }
2705
+ /**
2706
+ * Get up to 40 quarters or 20 years of full financial statements, newest first: the same
2707
+ * period object as `getFundamentals()`, with the trailing-twelve-month, price-ratio and market
2708
+ * fields null on every row. A ticker with no statements resolves with an empty `periods` and a
2709
+ * `reason` rather than throwing.
2710
+ *
2711
+ * Periods served from an SEC-backed record carry the optional provenance fields `source`,
2712
+ * `sourceRef`, `secFiled` and `lineSources`; see {@link Fundamentals}.
2713
+ */
2714
+ async getFundamentalsHistory(ticker, options) {
2715
+ return this.client.get("/api/v1/stocks/fundamentals/history", { ticker, ...options });
2716
+ }
2657
2717
  /** Get available fiscal periods. The periods are in `periods`. */
2658
2718
  async getFundamentalsPeriods(ticker) {
2659
2719
  return this.client.get("/api/v1/stocks/fundamentals/periods", { ticker });
@@ -2967,6 +3027,14 @@ function clampRetryAfter(raw, maxWaitS) {
2967
3027
  function retryAfterSeconds(raw, defaultS, maxWaitS) {
2968
3028
  return clampRetryAfter(raw, maxWaitS) ?? defaultS;
2969
3029
  }
3030
+ async function readErrorBody(response) {
3031
+ try {
3032
+ const parsed = await response.json();
3033
+ return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : void 0;
3034
+ } catch {
3035
+ return void 0;
3036
+ }
3037
+ }
2970
3038
  function sleep(ms) {
2971
3039
  return new Promise((resolve) => setTimeout(resolve, ms));
2972
3040
  }
@@ -3068,13 +3136,12 @@ var SentiSense = class {
3068
3136
  Number.POSITIVE_INFINITY
3069
3137
  );
3070
3138
  if (requestedS > MAX_RATE_LIMIT_WAIT_S) {
3071
- try {
3072
- await response.body?.cancel();
3073
- } catch {
3074
- }
3139
+ const body = await readErrorBody(response);
3075
3140
  throw new TemporarilyUnavailableError(
3076
3141
  `Server asked for a ${Math.round(requestedS)}s wait, longer than this client's ${MAX_RATE_LIMIT_WAIT_S}s budget`,
3077
- requestedS
3142
+ requestedS,
3143
+ void 0,
3144
+ body
3078
3145
  );
3079
3146
  }
3080
3147
  delayMs = requestedS * 1e3;
@@ -3155,32 +3222,29 @@ var SentiSense = class {
3155
3222
  return url.toString();
3156
3223
  }
3157
3224
  async handleErrorResponse(response) {
3158
- let body = {};
3159
- try {
3160
- body = await response.json();
3161
- } catch {
3162
- }
3163
- const message = body.message ?? response.statusText ?? "API request failed";
3164
- const code = body.error;
3225
+ const body = await readErrorBody(response);
3226
+ const message = body?.message ?? response.statusText ?? "API request failed";
3227
+ const code = body?.error;
3165
3228
  switch (response.status) {
3166
3229
  case 401:
3167
3230
  case 403:
3168
3231
  throw new AuthenticationError(
3169
3232
  this.apiKey ? message : `${message} ${MISSING_KEY_HINT}`,
3170
3233
  response.status,
3171
- code
3234
+ code,
3235
+ body
3172
3236
  );
3173
3237
  case 404:
3174
- throw new NotFoundError(message, code);
3238
+ throw new NotFoundError(message, code, body);
3175
3239
  case 429: {
3176
3240
  const retryAfter = clampRetryAfter(
3177
3241
  response.headers.get("Retry-After"),
3178
3242
  MAX_RATE_LIMIT_WAIT_S
3179
3243
  );
3180
- throw new RateLimitError(message, code, retryAfter);
3244
+ throw new RateLimitError(message, code, retryAfter, body);
3181
3245
  }
3182
3246
  default:
3183
- throw new APIError(message, response.status, code);
3247
+ throw new APIError(message, response.status, code, body);
3184
3248
  }
3185
3249
  }
3186
3250
  };
@@ -4677,8 +4741,12 @@ var quoteCommand = {
4677
4741
  "for the terminal layout: piped and --json output carry the quote alone.",
4678
4742
  "JSON is the exact quote response for one ticker, and an object keyed by ticker for more.",
4679
4743
  "An ETF symbol answers with the ETF quote: AUM, expense ratio and NAV in place of market",
4680
- "cap, P/E and EPS. That costs one extra request per ETF symbol."
4744
+ "cap, P/E and EPS. That costs one extra request per ETF symbol.",
4745
+ "With several tickers, one that fails does not lose the rest: the others print, each failed",
4746
+ "symbol is named on stderr, and the exit code is that failure's (4 for an unknown symbol).",
4747
+ "Under --json a failed symbol is left out of the object rather than given a null."
4681
4748
  ],
4749
+ jsonShape: "Print the quote response as JSON; for several tickers, an object keyed by ticker",
4682
4750
  flags: {},
4683
4751
  async run({ args, client, full, mode }) {
4684
4752
  const tickers = args.positionals.map((t) => t.toUpperCase());
@@ -4687,7 +4755,7 @@ var quoteCommand = {
4687
4755
  }
4688
4756
  const api = client();
4689
4757
  const wantName = mode === "pretty";
4690
- const rows = await Promise.all(
4758
+ const settled = await Promise.allSettled(
4691
4759
  tickers.map(async (ticker) => {
4692
4760
  const [answer, profile] = await Promise.all([
4693
4761
  quoteAnyTicker(api, ticker),
@@ -4697,14 +4765,37 @@ var quoteCommand = {
4697
4765
  return { ...answer, ticker, profile };
4698
4766
  })
4699
4767
  );
4700
- if (rows.length === 1) {
4701
- return { json: rows[0].quote, doc: doc(...single(rows[0], full)) };
4768
+ const rows = [];
4769
+ const failed = [];
4770
+ settled.forEach((outcome, index) => {
4771
+ if (outcome.status === "fulfilled") rows.push(outcome.value);
4772
+ else failed.push({ ticker: tickers[index], error: outcome.reason });
4773
+ });
4774
+ if (rows.length === 0) throw failed[0].error;
4775
+ const notes = rows.flatMap((row) => row.note ? [row.note] : []);
4776
+ if (tickers.length === 1) {
4777
+ return { json: rows[0].quote, doc: doc(...single(rows[0], full)), notes };
4702
4778
  }
4703
4779
  const json = {};
4704
4780
  for (const row of rows) json[row.ticker] = row.quote;
4705
- return { json, doc: doc(table(rows, full)) };
4781
+ const result = { json, doc: doc(table(rows, full)), notes };
4782
+ if (failed.length > 0) Object.assign(result, partialFailure(failed, args.flags.debug === true));
4783
+ return result;
4706
4784
  }
4707
4785
  };
4786
+ function partialFailure(failed, debug) {
4787
+ const errors = [];
4788
+ const advice = /* @__PURE__ */ new Set();
4789
+ let exitCode;
4790
+ for (const { ticker, error } of failed) {
4791
+ const report = describeError(error, debug, "quote");
4792
+ if (exitCode === void 0) exitCode = report.exitCode;
4793
+ const [first, ...rest] = report.lines;
4794
+ errors.push(first.replace(/^error: /, `error: ${ticker}: `));
4795
+ for (const line of rest) advice.add(line);
4796
+ }
4797
+ return { errors: [...errors, ...advice], exitCode };
4798
+ }
4708
4799
 
4709
4800
  // src/cli/commands/screen.ts
4710
4801
  var OPS = ["GTE", "LTE", "GT", "LT", "EQ", "NEQ", "IN", "NOT_IN"];
@@ -5070,8 +5161,12 @@ var sentimentCommand = {
5070
5161
  "polarity: it is unbounded, and the bands sit at 5, 13, and 23 either side of zero.",
5071
5162
  "Tone per source is the separate polarity reading, always between -1 and 1, and it is",
5072
5163
  "reported per source rather than blended into one number.",
5073
- "--days sets the Score history window used for the sparkline. Default is 30."
5164
+ "--days sets the Score history window used for the sparkline. Default is 30.",
5165
+ '--json prints one object combining two responses: "sentiment" is the sentiment response,',
5166
+ 'envelope included, and "series" the Score history points (null if that call failed). So',
5167
+ "the Score is at .sentiment.data.sentisenseScore, not .data.sentisenseScore."
5074
5168
  ],
5169
+ jsonShape: 'Print {"sentiment": <sentiment response>, "series": <Score history>} as JSON',
5075
5170
  flags: {
5076
5171
  days: { type: "number", placeholder: "N", describe: `Days of Score history (default ${DEFAULT_DAYS})` }
5077
5172
  },
@@ -5246,12 +5341,12 @@ var EXAMPLE = {
5246
5341
  function pad(text, width) {
5247
5342
  return text.length >= width ? text : text + " ".repeat(width - text.length);
5248
5343
  }
5249
- function flagLines(specs) {
5344
+ function flagLines(specs, overrides = {}) {
5250
5345
  const entries = Object.entries(specs);
5251
5346
  if (entries.length === 0) return [];
5252
5347
  const rendered = entries.map(([name, spec]) => ({
5253
5348
  left: spec.type === "boolean" ? `--${name}` : `--${name} <${spec.placeholder ?? "value"}>`,
5254
- describe: spec.describe
5349
+ describe: overrides[name] ?? spec.describe
5255
5350
  }));
5256
5351
  const width = Math.max(...rendered.map((entry) => entry.left.length));
5257
5352
  return rendered.map((entry) => ` ${pad(entry.left, width)} ${entry.describe}`);
@@ -5271,7 +5366,8 @@ function mainHelp() {
5271
5366
  ),
5272
5367
  "",
5273
5368
  "Output:",
5274
- " Pretty in a terminal, plain text when piped, exact API JSON with --json.",
5369
+ " Pretty in a terminal, plain text when piped, the API's JSON with --json. Where a command",
5370
+ " combines two responses into one object, its help names the keys.",
5275
5371
  " --full widens a command, --plain and --no-color force text, --debug shows stack traces.",
5276
5372
  "",
5277
5373
  "Setup:",
@@ -5304,7 +5400,11 @@ function commandHelp(command) {
5304
5400
  }
5305
5401
  const own = flagLines(command.flags);
5306
5402
  if (own.length > 0) lines.push("", "Flags:", ...own);
5307
- lines.push("", "Common flags:", ...flagLines(GLOBAL_FLAGS));
5403
+ lines.push(
5404
+ "",
5405
+ "Common flags:",
5406
+ ...flagLines(GLOBAL_FLAGS, command.jsonShape ? { json: command.jsonShape } : {})
5407
+ );
5308
5408
  lines.push("", "Examples:", ...command.examples.map((example) => ` ${example}`));
5309
5409
  lines.push(
5310
5410
  "",
@@ -5553,6 +5653,8 @@ async function runCli(argv, io) {
5553
5653
  } else {
5554
5654
  io.stdout(renderPlain(result.doc));
5555
5655
  }
5656
+ for (const line of result.errors ?? []) io.stderr(`${line}
5657
+ `);
5556
5658
  return result.exitCode ?? EXIT.OK;
5557
5659
  } catch (error) {
5558
5660
  const debug = argv.includes("--debug");
package/dist/index.cjs CHANGED
@@ -35,22 +35,23 @@ module.exports = __toCommonJS(index_exports);
35
35
 
36
36
  // src/errors.ts
37
37
  var SentiSenseError = class extends Error {
38
- constructor(message, status, code) {
38
+ constructor(message, status, code, body) {
39
39
  super(message);
40
40
  this.name = "SentiSenseError";
41
41
  this.status = status;
42
42
  this.code = code;
43
+ this.body = body;
43
44
  }
44
45
  };
45
46
  var AuthenticationError = class extends SentiSenseError {
46
- constructor(message, status, code) {
47
- super(message, status, code);
47
+ constructor(message, status, code, body) {
48
+ super(message, status, code, body);
48
49
  this.name = "AuthenticationError";
49
50
  }
50
51
  };
51
52
  var NotFoundError = class extends SentiSenseError {
52
- constructor(message, code) {
53
- super(message, 404, code);
53
+ constructor(message, code, body) {
54
+ super(message, 404, code, body);
54
55
  this.name = "NotFoundError";
55
56
  }
56
57
  };
@@ -62,22 +63,22 @@ var DeepHistoryUnavailableError = class extends SentiSenseError {
62
63
  }
63
64
  };
64
65
  var RateLimitError = class extends SentiSenseError {
65
- constructor(message, code, retryAfter) {
66
- super(message, 429, code);
66
+ constructor(message, code, retryAfter, body) {
67
+ super(message, 429, code, body);
67
68
  this.name = "RateLimitError";
68
69
  this.retryAfter = retryAfter;
69
70
  }
70
71
  };
71
72
  var TemporarilyUnavailableError = class extends SentiSenseError {
72
- constructor(message, retryAfter, code) {
73
- super(message, 503, code);
73
+ constructor(message, retryAfter, code, body) {
74
+ super(message, 503, code, body);
74
75
  this.name = "TemporarilyUnavailableError";
75
76
  this.retryAfter = retryAfter;
76
77
  }
77
78
  };
78
79
  var APIError = class extends SentiSenseError {
79
- constructor(message, status, code) {
80
- super(message, status, code);
80
+ constructor(message, status, code, body) {
81
+ super(message, status, code, body);
81
82
  this.name = "APIError";
82
83
  }
83
84
  };
@@ -469,13 +470,18 @@ var EntityMetrics = class {
469
470
  *
470
471
  * @param symbol Ticker symbol (e.g. "AAPL") or entity urlSlug.
471
472
  * @param metricType The metric to break down (e.g. "mentions" or "sentiment").
472
- * @param options Optional dimension parameter.
473
+ * @param options Optional dimension, and an optional window as `startTime` / `endTime` in
474
+ * epoch milliseconds. Without a window the API uses the last 7 days.
473
475
  */
474
476
  async getDistribution(symbol, metricType, options = {}) {
475
- const { dimension = "source" } = options;
477
+ const { dimension = "source", startTime, endTime } = options;
476
478
  return this.client.get(
477
479
  `/api/v2/metrics/entity/${encodeURIComponent(symbol)}/distribution/${encodeURIComponent(metricType)}`,
478
- { dimension }
480
+ {
481
+ dimension,
482
+ ...startTime !== void 0 && { startTime },
483
+ ...endTime !== void 0 && { endTime }
484
+ }
479
485
  );
480
486
  }
481
487
  };
@@ -1157,6 +1163,9 @@ var Stocks = class {
1157
1163
  * Get aggregate quote snapshot: live price, today OHLC, 52-week range,
1158
1164
  * market cap, P/E, EPS TTM, and dividend yield in a single call.
1159
1165
  * All fields except `ticker` may be null when upstream data is unavailable.
1166
+ *
1167
+ * A fund ticker gets a normal quote without AUM or NAV, plus `seeInstead` pointing at the
1168
+ * fund quote when that covers it: call `etfs.quote()` for those fields.
1160
1169
  */
1161
1170
  async getQuote(ticker) {
1162
1171
  return this.client.get(`/api/v1/stocks/${encodeURIComponent(ticker)}/quote`);
@@ -1285,6 +1294,18 @@ var Stocks = class {
1285
1294
  async getFundamentals(ticker, options) {
1286
1295
  return this.client.get("/api/v1/stocks/fundamentals", { ticker, ...options });
1287
1296
  }
1297
+ /**
1298
+ * Get up to 40 quarters or 20 years of full financial statements, newest first: the same
1299
+ * period object as `getFundamentals()`, with the trailing-twelve-month, price-ratio and market
1300
+ * fields null on every row. A ticker with no statements resolves with an empty `periods` and a
1301
+ * `reason` rather than throwing.
1302
+ *
1303
+ * Periods served from an SEC-backed record carry the optional provenance fields `source`,
1304
+ * `sourceRef`, `secFiled` and `lineSources`; see {@link Fundamentals}.
1305
+ */
1306
+ async getFundamentalsHistory(ticker, options) {
1307
+ return this.client.get("/api/v1/stocks/fundamentals/history", { ticker, ...options });
1308
+ }
1288
1309
  /** Get available fiscal periods. The periods are in `periods`. */
1289
1310
  async getFundamentalsPeriods(ticker) {
1290
1311
  return this.client.get("/api/v1/stocks/fundamentals/periods", { ticker });
@@ -1571,7 +1592,7 @@ function serializeTrackerParams(params) {
1571
1592
  }
1572
1593
 
1573
1594
  // src/version.ts
1574
- var VERSION = "0.77.0";
1595
+ var VERSION = "0.78.0";
1575
1596
 
1576
1597
  // src/client.ts
1577
1598
  var DEFAULT_BASE_URL = "https://app.sentisense.ai";
@@ -1601,6 +1622,14 @@ function clampRetryAfter(raw, maxWaitS) {
1601
1622
  function retryAfterSeconds(raw, defaultS, maxWaitS) {
1602
1623
  return clampRetryAfter(raw, maxWaitS) ?? defaultS;
1603
1624
  }
1625
+ async function readErrorBody(response) {
1626
+ try {
1627
+ const parsed = await response.json();
1628
+ return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : void 0;
1629
+ } catch {
1630
+ return void 0;
1631
+ }
1632
+ }
1604
1633
  function sleep(ms) {
1605
1634
  return new Promise((resolve) => setTimeout(resolve, ms));
1606
1635
  }
@@ -1702,13 +1731,12 @@ var SentiSense = class {
1702
1731
  Number.POSITIVE_INFINITY
1703
1732
  );
1704
1733
  if (requestedS > MAX_RATE_LIMIT_WAIT_S) {
1705
- try {
1706
- await response.body?.cancel();
1707
- } catch {
1708
- }
1734
+ const body = await readErrorBody(response);
1709
1735
  throw new TemporarilyUnavailableError(
1710
1736
  `Server asked for a ${Math.round(requestedS)}s wait, longer than this client's ${MAX_RATE_LIMIT_WAIT_S}s budget`,
1711
- requestedS
1737
+ requestedS,
1738
+ void 0,
1739
+ body
1712
1740
  );
1713
1741
  }
1714
1742
  delayMs = requestedS * 1e3;
@@ -1789,32 +1817,29 @@ var SentiSense = class {
1789
1817
  return url.toString();
1790
1818
  }
1791
1819
  async handleErrorResponse(response) {
1792
- let body = {};
1793
- try {
1794
- body = await response.json();
1795
- } catch {
1796
- }
1797
- const message = body.message ?? response.statusText ?? "API request failed";
1798
- const code = body.error;
1820
+ const body = await readErrorBody(response);
1821
+ const message = body?.message ?? response.statusText ?? "API request failed";
1822
+ const code = body?.error;
1799
1823
  switch (response.status) {
1800
1824
  case 401:
1801
1825
  case 403:
1802
1826
  throw new AuthenticationError(
1803
1827
  this.apiKey ? message : `${message} ${MISSING_KEY_HINT}`,
1804
1828
  response.status,
1805
- code
1829
+ code,
1830
+ body
1806
1831
  );
1807
1832
  case 404:
1808
- throw new NotFoundError(message, code);
1833
+ throw new NotFoundError(message, code, body);
1809
1834
  case 429: {
1810
1835
  const retryAfter = clampRetryAfter(
1811
1836
  response.headers.get("Retry-After"),
1812
1837
  MAX_RATE_LIMIT_WAIT_S
1813
1838
  );
1814
- throw new RateLimitError(message, code, retryAfter);
1839
+ throw new RateLimitError(message, code, retryAfter, body);
1815
1840
  }
1816
1841
  default:
1817
- throw new APIError(message, response.status, code);
1842
+ throw new APIError(message, response.status, code, body);
1818
1843
  }
1819
1844
  }
1820
1845
  };