sentisense 0.67.0 → 0.68.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/README.md CHANGED
@@ -34,7 +34,7 @@ npm install sentisense
34
34
  ```typescript
35
35
  import SentiSense from "sentisense";
36
36
 
37
- const client = new SentiSense({ apiKey: process.env.SENTISENSE_API_KEY });
37
+ const client = new SentiSense(); // reads SENTISENSE_API_KEY, or pass { apiKey }
38
38
 
39
39
  const price = await client.stocks.getPrice("AAPL");
40
40
  console.log(price.currentPrice);
@@ -166,7 +166,7 @@ const client = new SentiSense({
166
166
 
167
167
  | Option | Default | What it does |
168
168
  |--------|---------|--------------|
169
- | `apiKey` | none | Sent as `X-SentiSense-API-Key`. Required by every endpoint. |
169
+ | `apiKey` | `SENTISENSE_API_KEY` env var | Sent as `X-SentiSense-API-Key`. Required by every endpoint. An explicit value wins over the environment. |
170
170
  | `baseUrl` | `https://app.sentisense.ai` | Override for a non-production host. |
171
171
  | `timeout` | `30000` | Per-request timeout in milliseconds. |
172
172
  | `maxRetries` | `3` | Retries the per-minute 429 and 5xx, honouring `Retry-After`. The monthly-allowance 429 is never retried. Set `0` to fail fast. |
package/dist/cli.cjs CHANGED
@@ -1409,7 +1409,7 @@ var flowsCommand = {
1409
1409
  };
1410
1410
 
1411
1411
  // src/version.ts
1412
- var VERSION = "0.67.0";
1412
+ var VERSION = "0.68.0";
1413
1413
 
1414
1414
  // src/resources/analyst.ts
1415
1415
  var Analyst = class {
@@ -2800,9 +2800,22 @@ function retryAfterSeconds(raw, defaultS, maxWaitS) {
2800
2800
  function sleep(ms) {
2801
2801
  return new Promise((resolve) => setTimeout(resolve, ms));
2802
2802
  }
2803
+ var MISSING_KEY_HINT = "(No API key was sent. Set the SENTISENSE_API_KEY environment variable or pass apiKey; get a free key at https://app.sentisense.ai/get-api-key)";
2804
+ function resolveApiKey(explicit) {
2805
+ if (explicit === null) return void 0;
2806
+ if (explicit) return explicit;
2807
+ try {
2808
+ if (typeof process !== "undefined" && process.env) {
2809
+ const fromEnv = process.env.SENTISENSE_API_KEY?.trim();
2810
+ if (fromEnv) return fromEnv;
2811
+ }
2812
+ } catch {
2813
+ }
2814
+ return void 0;
2815
+ }
2803
2816
  var SentiSense = class {
2804
2817
  constructor(options = {}) {
2805
- this.apiKey = options.apiKey;
2818
+ this.apiKey = resolveApiKey(options.apiKey);
2806
2819
  this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
2807
2820
  this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
2808
2821
  this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
@@ -2982,7 +2995,11 @@ var SentiSense = class {
2982
2995
  switch (response.status) {
2983
2996
  case 401:
2984
2997
  case 403:
2985
- throw new AuthenticationError(message, response.status, code);
2998
+ throw new AuthenticationError(
2999
+ this.apiKey ? message : `${message} ${MISSING_KEY_HINT}`,
3000
+ response.status,
3001
+ code
3002
+ );
2986
3003
  case 404:
2987
3004
  throw new NotFoundError(message, code);
2988
3005
  case 429: {
@@ -3186,7 +3203,8 @@ function userAgentSuffix(context) {
3186
3203
  function createClient(context, options = {}) {
3187
3204
  if (!options.anonymous && !context.apiKey) throw new MissingKeyError();
3188
3205
  return new SentiSense({
3189
- apiKey: options.anonymous ? void 0 : context.apiKey,
3206
+ // null, not undefined: an anonymous probe must not pick up SENTISENSE_API_KEY from the library fallback.
3207
+ apiKey: options.anonymous ? null : context.apiKey,
3190
3208
  baseUrl: context.baseUrl,
3191
3209
  maxRetries: 0,
3192
3210
  userAgentSuffix: userAgentSuffix(context)
package/dist/index.cjs CHANGED
@@ -1441,7 +1441,7 @@ var Trackers = class {
1441
1441
  };
1442
1442
 
1443
1443
  // src/version.ts
1444
- var VERSION = "0.67.0";
1444
+ var VERSION = "0.68.0";
1445
1445
 
1446
1446
  // src/client.ts
1447
1447
  var DEFAULT_BASE_URL = "https://app.sentisense.ai";
@@ -1474,9 +1474,22 @@ function retryAfterSeconds(raw, defaultS, maxWaitS) {
1474
1474
  function sleep(ms) {
1475
1475
  return new Promise((resolve) => setTimeout(resolve, ms));
1476
1476
  }
1477
+ var MISSING_KEY_HINT = "(No API key was sent. Set the SENTISENSE_API_KEY environment variable or pass apiKey; get a free key at https://app.sentisense.ai/get-api-key)";
1478
+ function resolveApiKey(explicit) {
1479
+ if (explicit === null) return void 0;
1480
+ if (explicit) return explicit;
1481
+ try {
1482
+ if (typeof process !== "undefined" && process.env) {
1483
+ const fromEnv = process.env.SENTISENSE_API_KEY?.trim();
1484
+ if (fromEnv) return fromEnv;
1485
+ }
1486
+ } catch {
1487
+ }
1488
+ return void 0;
1489
+ }
1477
1490
  var SentiSense = class {
1478
1491
  constructor(options = {}) {
1479
- this.apiKey = options.apiKey;
1492
+ this.apiKey = resolveApiKey(options.apiKey);
1480
1493
  this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
1481
1494
  this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
1482
1495
  this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
@@ -1656,7 +1669,11 @@ var SentiSense = class {
1656
1669
  switch (response.status) {
1657
1670
  case 401:
1658
1671
  case 403:
1659
- throw new AuthenticationError(message, response.status, code);
1672
+ throw new AuthenticationError(
1673
+ this.apiKey ? message : `${message} ${MISSING_KEY_HINT}`,
1674
+ response.status,
1675
+ code
1676
+ );
1660
1677
  case 404:
1661
1678
  throw new NotFoundError(message, code);
1662
1679
  case 429: {