eventregistry 10.0.0 → 11.0.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.
Files changed (198) hide show
  1. package/AGENT-RECIPES.md +86 -0
  2. package/CHANGELOG.md +47 -0
  3. package/MIGRATION.md +22 -4
  4. package/README.md +49 -1
  5. package/dist/cjs/abort.d.ts +14 -0
  6. package/dist/cjs/abort.js +71 -0
  7. package/dist/cjs/abort.js.map +1 -0
  8. package/dist/cjs/base.js +8 -2
  9. package/dist/cjs/base.js.map +1 -1
  10. package/dist/cjs/errors.d.ts +66 -0
  11. package/dist/cjs/errors.js +75 -0
  12. package/dist/cjs/errors.js.map +1 -0
  13. package/dist/cjs/eventRegistry.d.ts +47 -15
  14. package/dist/cjs/eventRegistry.js +237 -185
  15. package/dist/cjs/eventRegistry.js.map +1 -1
  16. package/dist/cjs/fluent/recent.d.ts +7 -2
  17. package/dist/cjs/fluent/recent.js +7 -3
  18. package/dist/cjs/fluent/recent.js.map +1 -1
  19. package/dist/cjs/guards.d.ts +12 -0
  20. package/dist/cjs/guards.js +75 -0
  21. package/dist/cjs/guards.js.map +1 -0
  22. package/dist/cjs/http.d.ts +5 -0
  23. package/dist/cjs/http.js +64 -11
  24. package/dist/cjs/http.js.map +1 -1
  25. package/dist/cjs/index.d.ts +7 -0
  26. package/dist/cjs/index.js +17 -4
  27. package/dist/cjs/index.js.map +1 -1
  28. package/dist/cjs/logger.d.ts +2 -0
  29. package/dist/cjs/logger.js +6 -2
  30. package/dist/cjs/logger.js.map +1 -1
  31. package/dist/cjs/mutex.d.ts +2 -1
  32. package/dist/cjs/mutex.js +19 -2
  33. package/dist/cjs/mutex.js.map +1 -1
  34. package/dist/cjs/query.js +4 -4
  35. package/dist/cjs/query.js.map +1 -1
  36. package/dist/cjs/queryArticle.js +3 -2
  37. package/dist/cjs/queryArticle.js.map +1 -1
  38. package/dist/cjs/queryArticles.d.ts +6 -6
  39. package/dist/cjs/queryArticles.js +19 -18
  40. package/dist/cjs/queryArticles.js.map +1 -1
  41. package/dist/cjs/queryEvent.d.ts +1 -0
  42. package/dist/cjs/queryEvent.js +11 -5
  43. package/dist/cjs/queryEvent.js.map +1 -1
  44. package/dist/cjs/queryEvents.js +8 -7
  45. package/dist/cjs/queryEvents.js.map +1 -1
  46. package/dist/cjs/queryIterator.d.ts +2 -0
  47. package/dist/cjs/queryIterator.js +18 -10
  48. package/dist/cjs/queryIterator.js.map +1 -1
  49. package/dist/cjs/queryMentions.d.ts +1 -0
  50. package/dist/cjs/queryMentions.js +14 -8
  51. package/dist/cjs/queryMentions.js.map +1 -1
  52. package/dist/cjs/queryStory.d.ts +9 -6
  53. package/dist/cjs/queryStory.js +4 -4
  54. package/dist/cjs/queryStory.js.map +1 -1
  55. package/dist/cjs/recent.d.ts +18 -6
  56. package/dist/cjs/recent.js +26 -8
  57. package/dist/cjs/recent.js.map +1 -1
  58. package/dist/cjs/recentFeed.d.ts +35 -0
  59. package/dist/cjs/recentFeed.js +76 -0
  60. package/dist/cjs/recentFeed.js.map +1 -0
  61. package/dist/cjs/returnInfo.js +2 -2
  62. package/dist/cjs/returnInfo.js.map +1 -1
  63. package/dist/cjs/topicPage.js +7 -3
  64. package/dist/cjs/topicPage.js.map +1 -1
  65. package/dist/cjs/types.d.ts +63 -7
  66. package/dist/cjs/usage.d.ts +39 -0
  67. package/dist/cjs/usage.js +62 -0
  68. package/dist/cjs/usage.js.map +1 -0
  69. package/dist/cjs/version.d.ts +1 -1
  70. package/dist/cjs/version.js +1 -1
  71. package/dist/esm/abort.d.ts +14 -0
  72. package/dist/esm/abort.js +65 -0
  73. package/dist/esm/abort.js.map +1 -0
  74. package/dist/esm/analytics.d.ts +2 -2
  75. package/dist/esm/base.js +8 -2
  76. package/dist/esm/base.js.map +1 -1
  77. package/dist/esm/counts.d.ts +2 -2
  78. package/dist/esm/dailyShares.d.ts +2 -2
  79. package/dist/esm/errors.d.ts +66 -0
  80. package/dist/esm/errors.js +67 -0
  81. package/dist/esm/errors.js.map +1 -0
  82. package/dist/esm/eventForText.d.ts +3 -3
  83. package/dist/esm/eventRegistry.d.ts +67 -35
  84. package/dist/esm/eventRegistry.js +238 -186
  85. package/dist/esm/eventRegistry.js.map +1 -1
  86. package/dist/esm/fluent/analytics.d.ts +2 -2
  87. package/dist/esm/fluent/articles.d.ts +5 -5
  88. package/dist/esm/fluent/counts.d.ts +2 -2
  89. package/dist/esm/fluent/eventForText.d.ts +1 -1
  90. package/dist/esm/fluent/events.d.ts +5 -5
  91. package/dist/esm/fluent/info.d.ts +2 -2
  92. package/dist/esm/fluent/mentions.d.ts +3 -3
  93. package/dist/esm/fluent/recent.d.ts +9 -4
  94. package/dist/esm/fluent/recent.js +7 -3
  95. package/dist/esm/fluent/recent.js.map +1 -1
  96. package/dist/esm/fluent/shares.d.ts +2 -2
  97. package/dist/esm/fluent/stories.d.ts +3 -3
  98. package/dist/esm/fluent/topicPages.d.ts +3 -3
  99. package/dist/esm/fluent/trends.d.ts +3 -3
  100. package/dist/esm/guards.d.ts +12 -0
  101. package/dist/esm/guards.js +70 -0
  102. package/dist/esm/guards.js.map +1 -0
  103. package/dist/esm/helpers/analytics.d.ts +2 -2
  104. package/dist/esm/helpers/articles.d.ts +4 -4
  105. package/dist/esm/helpers/counts.d.ts +2 -2
  106. package/dist/esm/helpers/eventForText.d.ts +1 -1
  107. package/dist/esm/helpers/events.d.ts +4 -4
  108. package/dist/esm/helpers/info.d.ts +2 -2
  109. package/dist/esm/helpers/mentions.d.ts +2 -2
  110. package/dist/esm/helpers/recent.d.ts +2 -2
  111. package/dist/esm/helpers/shares.d.ts +2 -2
  112. package/dist/esm/helpers/stories.d.ts +3 -3
  113. package/dist/esm/helpers/topicPages.d.ts +3 -3
  114. package/dist/esm/helpers/trends.d.ts +3 -3
  115. package/dist/esm/helpers/uri.d.ts +2 -2
  116. package/dist/esm/http.d.ts +5 -0
  117. package/dist/esm/http.js +64 -11
  118. package/dist/esm/http.js.map +1 -1
  119. package/dist/esm/index.d.ts +54 -47
  120. package/dist/esm/index.js +4 -0
  121. package/dist/esm/index.js.map +1 -1
  122. package/dist/esm/info.d.ts +2 -2
  123. package/dist/esm/logger.d.ts +2 -0
  124. package/dist/esm/logger.js +6 -2
  125. package/dist/esm/logger.js.map +1 -1
  126. package/dist/esm/mutex.d.ts +2 -1
  127. package/dist/esm/mutex.js +19 -2
  128. package/dist/esm/mutex.js.map +1 -1
  129. package/dist/esm/query.d.ts +2 -2
  130. package/dist/esm/query.js +4 -4
  131. package/dist/esm/query.js.map +1 -1
  132. package/dist/esm/queryArticle.d.ts +3 -3
  133. package/dist/esm/queryArticle.js +3 -2
  134. package/dist/esm/queryArticle.js.map +1 -1
  135. package/dist/esm/queryArticles.d.ts +12 -12
  136. package/dist/esm/queryArticles.js +19 -18
  137. package/dist/esm/queryArticles.js.map +1 -1
  138. package/dist/esm/queryEvent.d.ts +6 -5
  139. package/dist/esm/queryEvent.js +11 -5
  140. package/dist/esm/queryEvent.js.map +1 -1
  141. package/dist/esm/queryEvents.d.ts +6 -6
  142. package/dist/esm/queryEvents.js +8 -7
  143. package/dist/esm/queryEvents.js.map +1 -1
  144. package/dist/esm/queryIterator.d.ts +2 -0
  145. package/dist/esm/queryIterator.js +18 -10
  146. package/dist/esm/queryIterator.js.map +1 -1
  147. package/dist/esm/queryMentions.d.ts +4 -3
  148. package/dist/esm/queryMentions.js +14 -8
  149. package/dist/esm/queryMentions.js.map +1 -1
  150. package/dist/esm/queryStory.d.ts +11 -8
  151. package/dist/esm/queryStory.js +4 -4
  152. package/dist/esm/queryStory.js.map +1 -1
  153. package/dist/esm/recent.d.ts +21 -9
  154. package/dist/esm/recent.js +26 -8
  155. package/dist/esm/recent.js.map +1 -1
  156. package/dist/esm/recentFeed.d.ts +35 -0
  157. package/dist/esm/recentFeed.js +70 -0
  158. package/dist/esm/recentFeed.js.map +1 -0
  159. package/dist/esm/returnInfo.d.ts +1 -1
  160. package/dist/esm/returnInfo.js +2 -2
  161. package/dist/esm/returnInfo.js.map +1 -1
  162. package/dist/esm/topicPage.d.ts +3 -3
  163. package/dist/esm/topicPage.js +7 -3
  164. package/dist/esm/topicPage.js.map +1 -1
  165. package/dist/esm/topicPages.d.ts +1 -1
  166. package/dist/esm/trends.d.ts +2 -2
  167. package/dist/esm/types.d.ts +69 -13
  168. package/dist/esm/usage.d.ts +39 -0
  169. package/dist/esm/usage.js +58 -0
  170. package/dist/esm/usage.js.map +1 -0
  171. package/dist/esm/version.d.ts +1 -1
  172. package/dist/esm/version.js +1 -1
  173. package/package.json +21 -12
  174. package/src/abort.ts +70 -0
  175. package/src/base.ts +8 -2
  176. package/src/errors.ts +105 -0
  177. package/src/eventRegistry.ts +285 -185
  178. package/src/fluent/recent.ts +9 -5
  179. package/src/guards.ts +79 -0
  180. package/src/http.ts +70 -11
  181. package/src/index.ts +7 -0
  182. package/src/logger.ts +7 -2
  183. package/src/mutex.ts +20 -2
  184. package/src/query.ts +4 -4
  185. package/src/queryArticle.ts +3 -2
  186. package/src/queryArticles.ts +25 -17
  187. package/src/queryEvent.ts +12 -5
  188. package/src/queryEvents.ts +9 -8
  189. package/src/queryIterator.ts +20 -9
  190. package/src/queryMentions.ts +16 -9
  191. package/src/queryStory.ts +11 -4
  192. package/src/recent.ts +35 -10
  193. package/src/recentFeed.ts +91 -0
  194. package/src/returnInfo.ts +2 -2
  195. package/src/topicPage.ts +7 -3
  196. package/src/types.ts +66 -7
  197. package/src/usage.ts +79 -0
  198. package/src/version.ts +1 -1
@@ -0,0 +1,86 @@
1
+ # Recipes for agents and automated pipelines
2
+
3
+ Programs that read news on their own, such as agents, monitors and enrichment jobs, share a few needs: spend tokens on purpose, stop when told to, and survive a flaky network. This page shows the pattern we recommend and the SDK options that support it. Everything here uses plain SDK calls; a runnable version is in [`examples/agentRecipesExamples.ts`](examples/agentRecipesExamples.ts).
4
+
5
+ ## Suggest, scan, triage, retrieve
6
+
7
+ Most questions can be answered by reading a handful of articles out of hundreds. Reading all of them is slow and costs tokens, so work in four steps, each cheaper than the next.
8
+
9
+ 1. **Suggest.** Turn names into Event Registry URIs. A concept URI is far more precise than a keyword, because it already separates "Apple" the company from the fruit.
10
+
11
+ ```ts
12
+ const conceptUri = await er.concepts.uri("Tesla"); // throws if nothing matches
13
+ ```
14
+
15
+ 2. **Scan.** Fetch many articles but only their titles. Set `bodyLen: 0` in `ArticleInfoFlags` so no body text is returned, and set `isDuplicateFilter: "skipDuplicates"` so a wire story that 40 outlets copied appears once.
16
+
17
+ ```ts
18
+ const titlesOnly = new ReturnInfo({ articleInfo: new ArticleInfoFlags({ bodyLen: 0 }) });
19
+ const response = await er.articles
20
+ .search({ conceptUri, lang: "eng", isDuplicateFilter: "skipDuplicates" })
21
+ .info({ count: 100, returnInfo: titlesOnly })
22
+ .exec();
23
+ ```
24
+
25
+ If the scan returns fewer than about 20 rows, widen or tighten the filter once (for example `keywordLoc: "title"`, or a different `sortBy`) instead of repeating the search with reworded keywords. Each search costs tokens.
26
+
27
+ 3. **Triage.** Read the titles and choose the articles worth a full read. This is the step where your agent or your own code decides; the SDK is not involved. Keep the article URIs, discard the rest.
28
+
29
+ 4. **Retrieve.** Ask for full details of the chosen URIs only. `QueryArticle` accepts a list of up to 100 URIs, so one call is enough.
30
+
31
+ ```ts
32
+ const details = await er.execQuery(new QueryArticle(uris, new RequestArticleInfo()));
33
+ ```
34
+
35
+ The same pattern works for events: scan with `er.events.search(...)`, triage on titles, and retrieve the chosen events. Event queries cost more tokens per call than article queries, so prefer a concept URI to keywords and avoid repeating them.
36
+
37
+ ## Set a token budget
38
+
39
+ Give an unattended job a ceiling so a bug cannot drain the account.
40
+
41
+ ```ts
42
+ const er = new EventRegistry({ apiKey, maxTokens: 500 });
43
+ ```
44
+
45
+ Once the tokens reported by the API since the client was created (plus the last reported cost of the endpoint about to be called) would pass `maxTokens`, the next call throws `ErBudgetExceededError` without sending a request. The API reports a call's cost only after it has run, so the guard can overshoot by one call; treat it as a safety net, not an exact meter. Read the totals with `er.usage.session`, the last call with `er.usage.last`, and the account balance with `await er.getRemainingTokens()`.
46
+
47
+ ## Stop on demand and bound the time
48
+
49
+ Pass an `AbortSignal` and an overall deadline in the constructor or per call.
50
+
51
+ ```ts
52
+ const controller = new AbortController();
53
+ const scoped = er.withOptions({ signal: controller.signal, timeoutMs: 30_000 });
54
+ const response = await scoped.articles.search({ conceptUri }).exec();
55
+ ```
56
+
57
+ `withOptions` returns a view of the same client, so rate limits, usage totals and the request queue stay shared. The deadline covers queueing, retries and backoff waits together. Aborting rejects with the abort reason, and an expired deadline rejects with `ErTimeoutError`; no request is left running.
58
+
59
+ ## Retry behaviour
60
+
61
+ Failed requests are retried with exponential backoff, capped at 30 seconds, and `Retry-After` is honoured on 429 and 503. By default a request is retried up to 5 times; set `repeatFailedRequestCount` to change that (`-1` retries until the request succeeds, `0` fails fast). When the API answers with an error that is not retried, the response carries an `ErApiError` with the status, the API's error code and, when present, the request id and token cost, so an agent can decide what to do next.
62
+
63
+ ## Watch for new content
64
+
65
+ `er.recent.articles()` and `er.recent.events()` poll the minute stream. Awaiting them does one poll; iterating them keeps polling.
66
+
67
+ ```ts
68
+ for await (const article of er.recent.articles({
69
+ pollMs: 60_000,
70
+ signal: controller.signal,
71
+ cursor: await loadCursor(), // resume where the last run stopped
72
+ onCursor: (cursor) => saveCursor(cursor) // called whenever the position moves
73
+ })) {
74
+ handle(article);
75
+ }
76
+ ```
77
+
78
+ Store the cursor wherever your job keeps state. Without one, the feed starts at the stream's current position and skips what was published while the job was down.
79
+
80
+ ## Refuse malformed data
81
+
82
+ A pipeline that acts on responses should not continue on a payload that lost its results array. Set `validate: true` and every `execQuery` response is checked against the documented top-level shapes; a mismatch throws `ErValidationError` listing each problem by JSON path. Unknown extra fields never fail the check, so API additions do not break you. The option is off by default.
83
+
84
+ ```ts
85
+ const er = new EventRegistry({ apiKey, validate: true });
86
+ ```
package/CHANGELOG.md CHANGED
@@ -2,6 +2,53 @@
2
2
 
3
3
  This log contains changes specific to the NodeJS SDK.
4
4
 
5
+ ## [v11.0.0](https://www.npmjs.com/package/eventregistry/v/11.0.0) (2026-11-25)
6
+
7
+ Also contains everything listed under `10.1.0` below, which was never published to npm.
8
+
9
+ **Breaking**
10
+ - The default `repeatFailedRequestCount` is now `5` (was `-1`, retry indefinitely), so a down API no longer hangs a call forever. Set `repeatFailedRequestCount: -1` to keep the old behaviour.
11
+
12
+ **Added**
13
+ - `throwOnError` config option: failed calls throw (`ErApiError` for HTTP failures) instead of resolving to `{ error }`. Off by default.
14
+ - `suggestAuthors`, `suggestEventTypes` and `suggestIndustries` also take `{ page, count }` as the second argument, and `suggestSourcesAtCoordinate` takes `{ count }` as the fourth. The positional forms still work. Extra parameters are now sent correctly (the old `...otherParams` rest array was spread as numeric keys).
15
+ - `retryDelayMs` and `maxRetryDelayMs` are part of the client config type.
16
+
17
+ **Changed**
18
+ - A malformed `settings.json` now reports the file and the parse error. Unsupported-parameter warnings go through one logger helper. Iterators buffer pages and `jsonRequest` and `jsonRequestAnalytics` share one request path; behaviour is unchanged.
19
+
20
+ **Fixed**
21
+ - `throwOnError` applies to every request, not only `execQuery()`: suggesters (`suggestConcepts`, …), URI lookups (`getConceptUri`, …), analytics calls and other `jsonRequest` / `jsonRequestAnalytics` callers throw on failure instead of resolving to `{ error }`.
22
+ - `new RequestMentionsConceptAggr()` no longer throws with its defaults: `mentionsSampleSize` now defaults to `20000` (was `100000`, above the `20000` cap).
23
+ - `TopicPage.loadTopicPageFromER()` starts from a clean definition; concepts, keywords and settings added earlier no longer leak into the loaded page.
24
+ - `TopicPage.loadTopicPageFromDefinition()` and `loadTopicPageFromFile()` accept definitions that carry `startSourceRankPercentile` or `endSourceRankPercentile`, so a saved definition with source rank limits loads again instead of being ignored.
25
+ - `ComplexArticleQuery`'s `hasDuplicateFilter` option is typed `"skipHasDuplicates" | "keepOnlyHasDuplicates" | "keepAll"`, the values the API accepts (it was typed with the `isDuplicateFilter` values, so the valid values needed a cast).
26
+ - `RequestArticlesRecentActivity` sends `updatesafterBlogUri` and `updatesAfterPrUri` as `recentActivityArticlesBlogUpdatesAfterUri` and `recentActivityArticlesPrUpdatesAfterUri` (both were sent as the news key and overwrote `updatesAfterNewsUri`). `updatesAfterBlogUri` is accepted as a camel-case alias for `updatesafterBlogUri`.
27
+ - `new QueryMentions()` without `requestedResult` asks for the mention list (`RequestMentionsInfo`), like the other queries and the Python SDK. It sent no `resultType` before.
28
+ - `QueryMentions` has the same two fixes as `QueryEvents` below: it sends `ignoreKeywords` as `ignoreKeyword`, and sends `sourceOper` / `sourceGroupOper`.
29
+ - `QueryEvents` sends `ignoreKeywords` under the `ignoreKeyword` key the API reads (it was sent as `ignoreKeywords` and ignored), and sends `sourceOper` / `sourceGroupOper`, so `QueryItems.AND` on `sourceUri` or `sourceGroupUri` works instead of throwing. Both match `QueryArticles` and the Python SDK.
30
+ - Recent-activity times (`updatesAfterTm`, `updatesUntilTm`) are sent in UTC without a zone suffix (`2026-01-01T10:00:00`), as the Python SDK sends them. A datetime string without a zone is now read as UTC. Before, it was read as local time, so the time sent was shifted on machines outside UTC.
31
+ - `ComplexArticleQuery` and `ComplexEventQuery` keep a `minSentiment` or `maxSentiment` of `0` in the filter; it was dropped as if unset.
32
+ - TypeScript users can set options that were published as `undefined`-only in the `.d.ts`: `RequestArticlesConceptAggr`'s `conceptCountPerType`, `RequestStorySimilarStories`' `conceptInfoList`, `dateStart`, `dateEnd` and `lang`, `GetRecentEvents`' `mandatoryLang`, and `GetRecentArticles`' `mandatorySourceLocation` and `lang`. No runtime change.
33
+
34
+ ## [v10.1.0](https://www.npmjs.com/package/eventregistry/v/10.1.0) (2026-11-11)
35
+
36
+ Additive release on top of `10.0.0`; nothing was removed or renamed. **The classic class-based API is permanent**: it carries no `@deprecated` tags and there is no plan to remove it. See [MIGRATION.md](MIGRATION.md#the-classic-api-is-permanent).
37
+
38
+ **Added**
39
+ - Typed `ErApiError` for failed HTTP calls (status, API error code and message, request id, token cost, `Retry-After`). `execQuery` error responses expose it as `apiError` next to the existing string `error`.
40
+ - Retry backoff is now exponential with jitter (base `retryDelayMs`, capped at `maxRetryDelayMs`) and honours `Retry-After` on 429 and 503. The default of retrying indefinitely (`repeatFailedRequestCount: -1`) is unchanged.
41
+ - Cancellation and deadlines: `signal` (an `AbortSignal`) and `timeoutMs` in the constructor config, per call on the classic `execQuery`/`getUsageInfo`/`getRemainingTokens` options, and for helpers and fluent calls through `er.withOptions({ signal, timeoutMs })`. The signal also stops requests waiting in the queue and pending backoff waits. Timeouts reject with `ErTimeoutError`.
42
+ - Usage accounting and an optional budget guard: `er.usage` (last call and session totals from the `req-tokens`, `req-action` and `req-archive` headers) and the `maxTokens` option, which rejects with `ErBudgetExceededError` before a call that would exceed the budget. The guard estimates the next call from the last cost of the same endpoint, so it can overshoot by one call.
43
+ - `er.recent.articles()` and `er.recent.events()` return a `RecentFeed`: `await` it for one poll (as before) or iterate it with `for await` to poll continuously, with `pollMs`, a resumable cursor (`getCursor`/`setCursor`, `onCursor`), `signal` and `timeoutMs`. `recentArticlesFeed` and `recentEventsFeed` are exported for direct use.
44
+ - Opt-in `validate: true`: responses are checked with hand-written guards for the top-level shapes of articles, events, mentions, URI/weight lists, aggregates and concept trends, and a mismatch throws `ErValidationError`. Unknown fields are ignored. Off by default.
45
+ - API reference generated with TypeDoc and published to GitHub Pages (`npm run docs`).
46
+ - [AGENT-RECIPES.md](AGENT-RECIPES.md) and a runnable `examples/agentRecipesExamples.ts` for the suggest, scan, triage, retrieve workflow.
47
+ - CI imports the ESM build in Bun and in workerd (through Miniflare) and constructs the client. Supported runtimes are listed in the README.
48
+
49
+ **Changed**
50
+ - The package imports `node:fs` and `node:path` (was `fs` and `path`). Behaviour on Node is identical; on Cloudflare Workers the `nodejs_compat` flag is required.
51
+
5
52
  ## [v10.0.0](https://www.npmjs.com/package/eventregistry/v/10.0.0) (2026-10-09)
6
53
 
7
54
  Upgrade guide for the last published line (`9.1.1`): [MIGRATION.md](MIGRATION.md). **The classic class-based API (`QueryArticles`, `QueryEvents`, `execQuery()`, iterators, complex queries, …) remains fully supported** — class names were not removed or renamed.
package/MIGRATION.md CHANGED
@@ -1,8 +1,22 @@
1
- # Migrating to eventregistry 10.0.0
1
+ # Migrating to eventregistry 11.0.0
2
2
 
3
- This guide covers moving from **`9.1.1`** (the last version on npm) to **`10.0.0`**. Read the [CHANGELOG](CHANGELOG.md) for the itemized list; this document explains the *why* and shows copy-paste examples.
3
+ Coming from `10.x`, read [From 10.x to 11.0.0](#from-10x-to-1100). Coming from `9.1.1`, read the whole guide: [From 9.1.1 to 10.0.0](#from-911-to-1000) first, then the `11.0.0` change. Read the [CHANGELOG](CHANGELOG.md) for the itemized list; this document explains the *why* and shows copy-paste examples.
4
4
 
5
- There was no published `9.1.2` or `11.0.0`. Everything that landed on `development` after `9.1.1` ships as this major.
5
+ ## From 10.x to 11.0.0
6
+
7
+ One breaking change: **failed requests are retried 5 times by default, not indefinitely.** `repeatFailedRequestCount` now defaults to `5` (was `-1`). Before, a down API or a broken network could hang a call forever; now it gives up after 5 retries and the call resolves to `{ error }` (or throws, with `throwOnError: true`).
8
+
9
+ To keep the old behaviour, set it back explicitly:
10
+
11
+ ```typescript
12
+ const er = new EventRegistry({ apiKey: "YOUR_API_KEY", repeatFailedRequestCount: -1 });
13
+ ```
14
+
15
+ Nothing else was removed or renamed. `11.0.0` also contains the additive `10.1.0` features (typed `ErApiError`, cancellation and deadlines, usage accounting and `maxTokens`, `RecentFeed`, opt-in `validate`), which were never published as a separate version, plus `throwOnError` and the `{ page, count }` form for the paged suggesters. See the [CHANGELOG](CHANGELOG.md) for details.
16
+
17
+ ## From 9.1.1 to 10.0.0
18
+
19
+ This part covers moving from **`9.1.1`** to **`10.0.0`**. There was no published `9.1.2`: everything that landed on `development` after `9.1.1` shipped as `10.0.0`. The retry default described below (`-1`) changed again in `11.0.0`.
6
20
 
7
21
  ## TL;DR
8
22
 
@@ -12,6 +26,10 @@ There was no published `9.1.2` or `11.0.0`. Everything that landed on `developme
12
26
  - New in 10.0.0: an optional ergonomic surface (`er.articles`, `searchArticles()`, `conceptUri()`, …) that wraps the same classic classes.
13
27
  - Under the hood: Axios → native `fetch`, Winston → a lightweight built-in `Logger`, moment → `Date`, dual CJS/ESM, TypeScript `strict`.
14
28
 
29
+ ## The classic API is permanent
30
+
31
+ The classic class-based API (`QueryArticles`, `QueryEvents`, `Request*`, iterators, complex queries, `er.execQuery()`) is a permanent part of this package, not a stepping stone. It carries no `@deprecated` tags, no codemod is planned and it will not be removed in a future major. The helpers and fluent namespaces are thin wrappers over it, so both surfaces get the same fixes and features. Pick whichever reads better; mixing them in one codebase is fine.
32
+
15
33
  ## 1. Classic API — still supported; runtime defaults changed
16
34
 
17
35
  This `9.1.1` pattern is still valid:
@@ -141,7 +159,7 @@ The library's own source now compiles under TypeScript `strict` mode. Consequenc
141
159
 
142
160
  - **Node.js 18+ is a hard requirement** — `fetch`/`Headers`/`AbortController` are global built-ins starting with Node 18. There is no polyfill bundled.
143
161
  - Axios is no longer a dependency — smaller install, no transitive Axios CVEs to track.
144
- - Stop-status-code list (`204`, `400`, `401`, `403`, `530`) does not retry. Transient HTTP/network failures still retry (`repeatFailedRequestCount: -1` by default). Invalid JSON bodies and JSON parse failures on HTTP 200 fail immediately instead of looping.
162
+ - Stop-status-code list (`204`, `400`, `401`, `403`, `530`) does not retry. Transient HTTP/network failures still retry (`repeatFailedRequestCount: 5` by default since `11.0.0`, `-1` before; set `-1` to retry indefinitely). Invalid JSON bodies and JSON parse failures on HTTP 200 fail immediately instead of looping.
145
163
  - If you were reaching into Axios-specific error shapes (`error.response`, `error.isAxiosError`, interceptors, etc.) anywhere in your own error handling, update those call sites — `jsonRequest` still swallows transport failures into `{ error: string, … }` rather than throwing an Axios error. `getLastHeaders()` is a Fetch `Headers` object.
146
164
 
147
165
  ## 5. Logging: Winston removed, `Logger`/`LogLevel` API unchanged
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ This is the official SDK for NewsAPI.ai, a news API developed and operated by Event Registry.
2
+
1
3
  ## Accessing Event Registry data through JS
2
4
 
3
5
  This library contains classes that allow one to easily access the event and article information from Event Registry (https://eventregistry.org).
@@ -6,6 +8,20 @@ Most of the package is quite similar to [Event Registry Python](https://github.c
6
8
 
7
9
  Node.js 24.11.0 is the supported development target. Starting with `10.0.0`, Node.js **18+ is a hard runtime requirement** (the HTTP layer uses native `fetch`); see [MIGRATION.md](MIGRATION.md) for details.
8
10
 
11
+ ### Supported runtimes
12
+
13
+ | Runtime | Status |
14
+ |---|---|
15
+ | Node.js 18, 20, 22, 24 | Tested in CI (full suite; unit tests on 20+). |
16
+ | Bun | The ESM build is imported and the client constructed in CI. |
17
+ | Cloudflare Workers (workerd) | The ESM build is loaded in workerd through Miniflare in CI. Needs the `nodejs_compat` compatibility flag and a recent compatibility date (the CI check uses 2026-01-01; 2025-01-01 lacks `node:fs`), because the package imports `node:fs` for optional `settings.json` and log files. File access is skipped when the files do not exist. |
18
+
19
+ Deno and browsers are not tested. The package has no runtime dependencies and needs a global `fetch`.
20
+
21
+ API reference (generated with TypeDoc from the strict build): https://eventregistry.github.io/event-registry-node-js/ — run `npm run docs` to build it locally into `docs-site/`.
22
+
23
+ Building an agent or an unattended pipeline? See [AGENT-RECIPES.md](AGENT-RECIPES.md) for the suggest, scan, triage, retrieve pattern plus budgets, cancellation and resumable feeds.
24
+
9
25
  ### Installation
10
26
 
11
27
  Event Registry package can be installed using the NodeJS Package Manager. Type the following in the command line:
@@ -45,7 +61,7 @@ The same style is available for `er.events`, `er.mentions`, `er.stories`, `er.tr
45
61
 
46
62
  ### Classic API (fully supported)
47
63
 
48
- The classic class-based API — `QueryArticles`, `QueryEvents`, `Request*Info`, iterators, complex queries, `er.execQuery()` — is **fully supported** in `10.0.0` and is not going anywhere. Class names from `9.1.1` were not removed; some defaults and return shapes did change (HTTPS hosts, delay, retries, `GetRecentEvents`). See [MIGRATION.md](MIGRATION.md). The fluent/helpers layer is additive sugar over the same classes.
64
+ The classic class-based API — `QueryArticles`, `QueryEvents`, `Request*Info`, iterators, complex queries, `er.execQuery()` — is **permanent**: it is fully supported, carries no deprecation tags and will not be removed. Class names from `9.1.1` were not removed; some defaults and return shapes did change (HTTPS hosts, delay, retries, `GetRecentEvents`). See [MIGRATION.md](MIGRATION.md). The fluent/helpers layer is additive sugar over the same classes.
49
65
 
50
66
  ```typescript
51
67
  import { EventRegistry, QueryArticles, RequestArticlesInfo, QueryArticlesIter } from "eventregistry";
@@ -62,6 +78,36 @@ er.getConceptUri("George Clooney").then((conceptUri) => {
62
78
 
63
79
  Use whichever style fits a given file or team; the two can be mixed freely within the same project, even the same function.
64
80
 
81
+ ### Errors and retries
82
+
83
+ By default a failed call resolves to an object with a string `error` (and `apiError`, a typed `ErApiError`, for HTTP failures), so check `response.error`. Set `throwOnError: true` to make failed calls throw instead: HTTP failures throw `ErApiError` (with `status`, `apiCode`, `apiError`, `requestId`, `tokens` and `retryAfterMs`), other failures a plain `Error`.
84
+
85
+ ```typescript
86
+ import { EventRegistry, ErApiError, QueryArticles } from "eventregistry";
87
+
88
+ const er = new EventRegistry({ apiKey: "YOUR_API_KEY", throwOnError: true });
89
+ try {
90
+ const response = await er.execQuery(new QueryArticles({ keywords: "Tesla" }));
91
+ console.info(response);
92
+ } catch (err) {
93
+ if (err instanceof ErApiError) {
94
+ console.error(err.status, err.apiError);
95
+ }
96
+ }
97
+ ```
98
+
99
+ Transient failures are retried up to `repeatFailedRequestCount` times (default `5`, since `11.0.0`; it was `-1`, retry indefinitely). Waits grow exponentially with jitter from `retryDelayMs` (default `5000`) up to `maxRetryDelayMs` (default `30000`), and `Retry-After` is honoured on 429 and 503. Status codes 204, 400, 401, 403 and 530 are never retried. Set `repeatFailedRequestCount: -1` to retry indefinitely, or `0` to fail fast.
100
+
101
+ ### Suggesters
102
+
103
+ The `suggest*` methods on `EventRegistry` resolve a label prefix to candidate URIs. `suggestAuthors`, `suggestEventTypes` and `suggestIndustries` take paging either positionally or as an object, and `suggestSourcesAtCoordinate` does the same for its count:
104
+
105
+ ```typescript
106
+ await er.suggestAuthors("john", 2, 5); // page 2, 5 results
107
+ await er.suggestAuthors("john", { page: 2, count: 5 });
108
+ await er.suggestSourcesAtCoordinate(40.7, -74.0, 50, { count: 10 });
109
+ ```
110
+
65
111
  ### Usage: dual import/require
66
112
 
67
113
  The package provides the same API to ES module/TypeScript imports and CommonJS `require` calls:
@@ -270,6 +316,8 @@ er.getCategoryUri("business").then((businessUri) => {
270
316
 
271
317
  Depending on your interest and existing knowledge of the `eventregistry` package you can check different things:
272
318
 
319
+ For method signatures and option types, the [API reference](https://eventregistry.github.io/event-registry-node-js/) is the current source. The wiki pages below explain the concepts and may lag behind the 10.x API.
320
+
273
321
  **[Terminology](https://github.com/EventRegistry/event-registry-node-js/wiki/Terminology)**. There are numerous terms in the Event Registry that you will constantly see. If you don't know what we mean by an *event*, *story*, *concept* or *category*, you should definitely check this page first.
274
322
 
275
323
  **[Learn about `EventRegistry` class](https://github.com/EventRegistry/event-registry-node-js/wiki/Eventregistry-class)**. You will need to use the `EventRegistry` class whenever you will want to interact with Event Registry so you should learn about it.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Combine an optional caller signal with an optional overall deadline into one signal.
3
+ * `AbortSignal.any` is Node 20+, so this links the two by hand (the package floor is Node 18).
4
+ */
5
+ export declare function composeSignal(signals: (AbortSignal | undefined)[], timeoutMs?: number): {
6
+ signal?: AbortSignal;
7
+ dispose: () => void;
8
+ };
9
+ /** The abort reason as an Error (a custom `abort(reason)` value that is not an Error is wrapped). */
10
+ export declare function abortReason(signal?: AbortSignal): Error;
11
+ /** `setTimeout` as a promise that rejects with the signal's reason as soon as the signal aborts. */
12
+ export declare function abortableSleep(ms: number, signal?: AbortSignal): Promise<void>;
13
+ /** True when an error means the caller cancelled, ran out of time or out of budget, so it must propagate instead of being logged away. */
14
+ export declare function isCancellation(error: unknown, signal?: AbortSignal): boolean;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.composeSignal = composeSignal;
4
+ exports.abortReason = abortReason;
5
+ exports.abortableSleep = abortableSleep;
6
+ exports.isCancellation = isCancellation;
7
+ const errors_1 = require("./errors");
8
+ /**
9
+ * Combine an optional caller signal with an optional overall deadline into one signal.
10
+ * `AbortSignal.any` is Node 20+, so this links the two by hand (the package floor is Node 18).
11
+ */
12
+ function composeSignal(signals, timeoutMs) {
13
+ const given = signals.filter((s) => s !== undefined);
14
+ if (given.length === 0 && !timeoutMs) {
15
+ return { dispose: () => undefined };
16
+ }
17
+ const controller = new AbortController();
18
+ const listeners = [];
19
+ let timer;
20
+ const alreadyAborted = given.find((s) => s.aborted);
21
+ if (alreadyAborted) {
22
+ controller.abort(alreadyAborted.reason);
23
+ }
24
+ else {
25
+ for (const s of given) {
26
+ const onAbort = () => controller.abort(s.reason);
27
+ s.addEventListener("abort", onAbort, { once: true });
28
+ listeners.push([s, onAbort]);
29
+ }
30
+ if (timeoutMs) {
31
+ timer = setTimeout(() => controller.abort(new errors_1.ErTimeoutError(timeoutMs)), timeoutMs);
32
+ }
33
+ }
34
+ return {
35
+ signal: controller.signal,
36
+ dispose: () => {
37
+ clearTimeout(timer);
38
+ for (const [s, onAbort] of listeners) {
39
+ s.removeEventListener("abort", onAbort);
40
+ }
41
+ }
42
+ };
43
+ }
44
+ /** The abort reason as an Error (a custom `abort(reason)` value that is not an Error is wrapped). */
45
+ function abortReason(signal) {
46
+ const reason = signal?.reason;
47
+ return reason instanceof Error ? reason : new Error(typeof reason === "string" ? reason : "The operation was aborted");
48
+ }
49
+ /** `setTimeout` as a promise that rejects with the signal's reason as soon as the signal aborts. */
50
+ function abortableSleep(ms, signal) {
51
+ return new Promise((resolve, reject) => {
52
+ if (signal?.aborted) {
53
+ reject(abortReason(signal));
54
+ return;
55
+ }
56
+ const onAbort = () => {
57
+ clearTimeout(timer);
58
+ reject(abortReason(signal));
59
+ };
60
+ const timer = setTimeout(() => {
61
+ signal?.removeEventListener("abort", onAbort);
62
+ resolve();
63
+ }, ms);
64
+ signal?.addEventListener("abort", onAbort, { once: true });
65
+ });
66
+ }
67
+ /** True when an error means the caller cancelled, ran out of time or out of budget, so it must propagate instead of being logged away. */
68
+ function isCancellation(error, signal) {
69
+ return signal?.aborted === true || error instanceof errors_1.ErTimeoutError || error instanceof errors_1.ErBudgetExceededError;
70
+ }
71
+ //# sourceMappingURL=abort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abort.js","sourceRoot":"","sources":["../../src/abort.ts"],"names":[],"mappings":";;AAMA,sCAiCC;AAGD,kCAGC;AAGD,wCAgBC;AAGD,wCAEC;AArED,qCAAiE;AAEjE;;;GAGG;AACH,SAAgB,aAAa,CACzB,OAAoC,EACpC,SAAkB;IAElB,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAoB,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACvE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QACnC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;IACxC,CAAC;IACD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,SAAS,GAAgC,EAAE,CAAC;IAClD,IAAI,KAAgD,CAAC;IACrD,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IACpD,IAAI,cAAc,EAAE,CAAC;QACjB,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;SAAM,CAAC;QACJ,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACpB,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YACjD,CAAC,CAAC,g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,CAAC,CAAC;YACpB,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;QAChC,CAAC,CAAC;QACF,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC1B,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9C,OAAO,EAAE,CAAC;QACd,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACP,CAAC;AAED,0IAA0I;AAC1I,SAAgB,cAAc,CAAC,KAAc,EAAE,MAAoB;IAC/D,OAAO,MAAM,EAAE,OAAO,KAAK,IAAI,IAAI,KAAK,YAAY,uBAAc,IAAI,KAAK,YAAY,8BAAqB,CAAC;AACjH,CAAC"}
package/dist/cjs/base.js CHANGED
@@ -36,14 +36,20 @@ class QueryParamsBase {
36
36
  * Encode datetime into UTC ISO format which can be sent to ER.
37
37
  */
38
38
  static encodeDateTime(val, format) {
39
- const date = val instanceof Date ? val : new Date(val);
39
+ // As in the Python SDK, a datetime string without a zone is UTC, not local time.
40
+ const zoneless = typeof val === "string" && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?$/.test(val);
41
+ const date = val instanceof Date ? val : new Date(zoneless ? `${val}Z` : val);
40
42
  if (isNaN(date.getTime())) {
41
43
  throw new Error("Datetime was not recognizable. Use `new Date()` or string in ISO format");
42
44
  }
43
45
  if (format === "YYYY-MM-DD") {
44
46
  return date.toISOString().slice(0, 10);
45
47
  }
46
- return date.toISOString();
48
+ if (zoneless) {
49
+ return val;
50
+ }
51
+ // The API takes UTC without a zone suffix, which is what the Python SDK sends.
52
+ return date.toISOString().replace(/(\.000)?Z$/, "");
47
53
  }
48
54
  /**
49
55
  * Return the parameters.
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot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,CAAC,MAAM,CAAC;QAC5B,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YAC3C,SAAS,GAAG,EAAE,GAAG,SAAS,EAAE,GAAI,UAAsD,EAAE,MAAM,EAAE,CAAC;QACrG,CAAC;QAED,MAAM,uBAAuB,GAAG,IAAI,CAAC,0BAA0B,EAAE,CAAC;QAClE,IAAI,uBAAuB,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;YACtC,SAAS,GAAG,EAAE,GAAG,SAAS,EAAE,UAAU,EAAE,uBAAuB,EAAE,CAAC;QACtE,CAAC;QACD,OAAO,eAAe,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IAEM,0BAA0B;QAC7B,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAE,MAAiC,EAAE,UAAU,KAAK,SAAS,CAAC,EAAE,CAAC;YACvG,OAAO,EAAE,CAAC;QACd,CAAC;QACD,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,OAAQ,IAAI,CAAC,cAAc,CAAC,CAAC,CAA4B,EAAE,UAAU,CAAC;QAC1E,CAAC;aAAM,CAAC;YACJ,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAE,MAAiC,EAAE,UAAU,CAAC,CAAC;QAC/F,CAAC;IACL,CAAC;CAGJ;AA/CD,sBA+CC;AAED;;GAEG;AACH,SAAgB,KAAK,CAAC,EAAU;IAC5B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Error thrown by the HTTP layer when the Event Registry API answers with a non-200 status.
3
+ * `response` mirrors the shape older code read from the previous Axios-style errors.
4
+ */
5
+ export declare class ErApiError extends Error {
6
+ readonly status: number;
7
+ readonly statusText: string;
8
+ /** Machine-readable error code from the response body, when the API sends one. */
9
+ readonly apiCode?: string;
10
+ /** Error string from the response body, when the API sends one. */
11
+ readonly apiError?: string;
12
+ /** Request id from the response headers, when the API sends one. */
13
+ readonly requestId?: string;
14
+ /** Tokens the failed request cost, when the API reports it (`req-tokens` header). */
15
+ readonly tokens?: number;
16
+ /** Parsed `Retry-After` header in milliseconds, when present. */
17
+ readonly retryAfterMs?: number;
18
+ readonly response: {
19
+ status: number;
20
+ statusText: string;
21
+ };
22
+ constructor(init: {
23
+ status: number;
24
+ statusText: string;
25
+ apiCode?: string;
26
+ apiError?: string;
27
+ requestId?: string;
28
+ tokens?: number;
29
+ retryAfterMs?: number;
30
+ });
31
+ }
32
+ /** Parse a `Retry-After` header value (delta-seconds or HTTP-date) into milliseconds. */
33
+ export declare function parseRetryAfter(value: string | null, now?: number): number | undefined;
34
+ /** Thrown when the overall `timeoutMs` of a call (queueing, retries and backoff included) runs out. */
35
+ export declare class ErTimeoutError extends Error {
36
+ readonly timeoutMs: number;
37
+ constructor(timeoutMs: number);
38
+ }
39
+ /**
40
+ * Thrown before a request is sent when the `maxTokens` budget would be exceeded.
41
+ * The check uses the token cost the API reported for earlier calls (see `Usage`), so it is an estimate.
42
+ */
43
+ export declare class ErBudgetExceededError extends Error {
44
+ readonly maxTokens: number;
45
+ /** Tokens spent by this client since construction or the last `usage.reset()`. */
46
+ readonly spentTokens: number;
47
+ /** Estimated cost of the refused call (the last reported cost of the same path, 0 when unknown). */
48
+ readonly estimatedTokens: number;
49
+ readonly path: string;
50
+ constructor(details: {
51
+ maxTokens: number;
52
+ spentTokens: number;
53
+ estimatedTokens: number;
54
+ path: string;
55
+ });
56
+ }
57
+ /**
58
+ * Thrown by `EventRegistry` when `validate: true` is set and a response does not have the documented shape.
59
+ * Unknown extra fields never fail validation; only missing or mistyped documented fields do.
60
+ */
61
+ export declare class ErValidationError extends Error {
62
+ /** One line per problem, each starting with the JSON path, e.g. `articles.results[3].uri: expected a string`. */
63
+ readonly issues: string[];
64
+ readonly path: string;
65
+ constructor(path: string, issues: string[]);
66
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErValidationError = exports.ErBudgetExceededError = exports.ErTimeoutError = exports.ErApiError = void 0;
4
+ exports.parseRetryAfter = parseRetryAfter;
5
+ /**
6
+ * Error thrown by the HTTP layer when the Event Registry API answers with a non-200 status.
7
+ * `response` mirrors the shape older code read from the previous Axios-style errors.
8
+ */
9
+ class ErApiError extends Error {
10
+ constructor(init) {
11
+ super(init.apiError || init.statusText || `HTTP ${init.status}`);
12
+ this.name = "ErApiError";
13
+ this.status = init.status;
14
+ this.statusText = init.statusText;
15
+ this.apiCode = init.apiCode;
16
+ this.apiError = init.apiError;
17
+ this.requestId = init.requestId;
18
+ this.tokens = init.tokens;
19
+ this.retryAfterMs = init.retryAfterMs;
20
+ this.response = { status: init.status, statusText: init.statusText };
21
+ }
22
+ }
23
+ exports.ErApiError = ErApiError;
24
+ /** Parse a `Retry-After` header value (delta-seconds or HTTP-date) into milliseconds. */
25
+ function parseRetryAfter(value, now = Date.now()) {
26
+ if (value === null || value.trim() === "") {
27
+ return undefined;
28
+ }
29
+ const seconds = Number(value);
30
+ if (Number.isFinite(seconds)) {
31
+ return seconds >= 0 ? Math.round(seconds * 1000) : undefined;
32
+ }
33
+ const date = Date.parse(value);
34
+ return Number.isNaN(date) ? undefined : Math.max(0, date - now);
35
+ }
36
+ /** Thrown when the overall `timeoutMs` of a call (queueing, retries and backoff included) runs out. */
37
+ class ErTimeoutError extends Error {
38
+ constructor(timeoutMs) {
39
+ super(`Request timed out after ${timeoutMs} ms`);
40
+ this.name = "ErTimeoutError";
41
+ this.timeoutMs = timeoutMs;
42
+ }
43
+ }
44
+ exports.ErTimeoutError = ErTimeoutError;
45
+ /**
46
+ * Thrown before a request is sent when the `maxTokens` budget would be exceeded.
47
+ * The check uses the token cost the API reported for earlier calls (see `Usage`), so it is an estimate.
48
+ */
49
+ class ErBudgetExceededError extends Error {
50
+ constructor(details) {
51
+ super(`Token budget of ${details.maxTokens} would be exceeded by ${details.path}: ${details.spentTokens} spent, about ${details.estimatedTokens} needed`);
52
+ this.name = "ErBudgetExceededError";
53
+ this.maxTokens = details.maxTokens;
54
+ this.spentTokens = details.spentTokens;
55
+ this.estimatedTokens = details.estimatedTokens;
56
+ this.path = details.path;
57
+ Object.setPrototypeOf(this, new.target.prototype);
58
+ }
59
+ }
60
+ exports.ErBudgetExceededError = ErBudgetExceededError;
61
+ /**
62
+ * Thrown by `EventRegistry` when `validate: true` is set and a response does not have the documented shape.
63
+ * Unknown extra fields never fail validation; only missing or mistyped documented fields do.
64
+ */
65
+ class ErValidationError extends Error {
66
+ constructor(path, issues) {
67
+ super(`Unexpected response shape from ${path}: ${issues.slice(0, 3).join("; ")}${issues.length > 3 ? ` (+${issues.length - 3} more)` : ""}`);
68
+ this.name = "ErValidationError";
69
+ this.issues = issues;
70
+ this.path = path;
71
+ Object.setPrototypeOf(this, new.target.prototype);
72
+ }
73
+ }
74
+ exports.ErValidationError = ErValidationError;
75
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AA0CA,0CAUC;AApDD;;;GAGG;AACH,MAAa,UAAW,SAAQ,KAAK;IAejC,YAAY,IAQX;QACG,KAAK,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU,IAAI,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OA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