eventregistry 9.1.0 → 10.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 (413) hide show
  1. package/CHANGELOG.md +207 -0
  2. package/LICENSE +21 -21
  3. package/MIGRATION.md +177 -0
  4. package/README.md +292 -234
  5. package/dist/{analytics.d.ts → cjs/analytics.d.ts} +2 -1
  6. package/dist/cjs/analytics.js +174 -0
  7. package/dist/cjs/analytics.js.map +1 -0
  8. package/dist/{base.d.ts → cjs/base.d.ts} +9 -9
  9. package/dist/cjs/base.js +189 -0
  10. package/dist/cjs/base.js.map +1 -0
  11. package/dist/cjs/counts.js +120 -0
  12. package/dist/cjs/counts.js.map +1 -0
  13. package/dist/cjs/dailyShares.js +46 -0
  14. package/dist/cjs/dailyShares.js.map +1 -0
  15. package/dist/{data.d.ts → cjs/data.d.ts} +32 -5
  16. package/dist/cjs/data.js.map +1 -0
  17. package/dist/{eventForText.d.ts → cjs/eventForText.d.ts} +1 -1
  18. package/dist/cjs/eventForText.js +61 -0
  19. package/dist/cjs/eventForText.js.map +1 -0
  20. package/dist/{eventRegistry.d.ts → cjs/eventRegistry.d.ts} +127 -28
  21. package/dist/cjs/eventRegistry.js +887 -0
  22. package/dist/cjs/eventRegistry.js.map +1 -0
  23. package/dist/cjs/fluent/analytics.d.ts +24 -0
  24. package/dist/cjs/fluent/analytics.js +47 -0
  25. package/dist/cjs/fluent/analytics.js.map +1 -0
  26. package/dist/cjs/fluent/articles.d.ts +23 -0
  27. package/dist/cjs/fluent/articles.js +34 -0
  28. package/dist/cjs/fluent/articles.js.map +1 -0
  29. package/dist/cjs/fluent/counts.d.ts +8 -0
  30. package/dist/cjs/fluent/counts.js +17 -0
  31. package/dist/cjs/fluent/counts.js.map +1 -0
  32. package/dist/cjs/fluent/eventForText.d.ts +4 -0
  33. package/dist/cjs/fluent/eventForText.js +8 -0
  34. package/dist/cjs/fluent/eventForText.js.map +1 -0
  35. package/dist/cjs/fluent/events.d.ts +23 -0
  36. package/dist/cjs/fluent/events.js +34 -0
  37. package/dist/cjs/fluent/events.js.map +1 -0
  38. package/dist/cjs/fluent/info.d.ts +10 -0
  39. package/dist/cjs/fluent/info.js +23 -0
  40. package/dist/cjs/fluent/info.js.map +1 -0
  41. package/dist/cjs/fluent/mentions.d.ts +18 -0
  42. package/dist/cjs/fluent/mentions.js +31 -0
  43. package/dist/cjs/fluent/mentions.js.map +1 -0
  44. package/dist/cjs/fluent/recent.d.ts +8 -0
  45. package/dist/cjs/fluent/recent.js +17 -0
  46. package/dist/cjs/fluent/recent.js.map +1 -0
  47. package/dist/cjs/fluent/shares.d.ts +8 -0
  48. package/dist/cjs/fluent/shares.js +17 -0
  49. package/dist/cjs/fluent/shares.js.map +1 -0
  50. package/dist/cjs/fluent/stories.d.ts +8 -0
  51. package/dist/cjs/fluent/stories.js +14 -0
  52. package/dist/cjs/fluent/stories.js.map +1 -0
  53. package/dist/cjs/fluent/topicPages.d.ts +10 -0
  54. package/dist/cjs/fluent/topicPages.js +20 -0
  55. package/dist/cjs/fluent/topicPages.js.map +1 -0
  56. package/dist/cjs/fluent/trends.d.ts +11 -0
  57. package/dist/cjs/fluent/trends.js +23 -0
  58. package/dist/cjs/fluent/trends.js.map +1 -0
  59. package/dist/cjs/helpers/analytics.d.ts +68 -0
  60. package/dist/cjs/helpers/analytics.js +100 -0
  61. package/dist/cjs/helpers/analytics.js.map +1 -0
  62. package/dist/cjs/helpers/articles.d.ts +24 -0
  63. package/dist/cjs/helpers/articles.js +31 -0
  64. package/dist/cjs/helpers/articles.js.map +1 -0
  65. package/dist/cjs/helpers/counts.d.ts +4 -0
  66. package/dist/cjs/helpers/counts.js +12 -0
  67. package/dist/cjs/helpers/counts.js.map +1 -0
  68. package/dist/cjs/helpers/eventForText.d.ts +6 -0
  69. package/dist/cjs/helpers/eventForText.js +13 -0
  70. package/dist/cjs/helpers/eventForText.js.map +1 -0
  71. package/dist/cjs/helpers/events.d.ts +18 -0
  72. package/dist/cjs/helpers/events.js +31 -0
  73. package/dist/cjs/helpers/events.js.map +1 -0
  74. package/dist/cjs/helpers/info.d.ts +6 -0
  75. package/dist/cjs/helpers/info.js +20 -0
  76. package/dist/cjs/helpers/info.js.map +1 -0
  77. package/dist/cjs/helpers/mentions.d.ts +10 -0
  78. package/dist/cjs/helpers/mentions.js +21 -0
  79. package/dist/cjs/helpers/mentions.js.map +1 -0
  80. package/dist/cjs/helpers/recent.d.ts +10 -0
  81. package/dist/cjs/helpers/recent.js +18 -0
  82. package/dist/cjs/helpers/recent.js.map +1 -0
  83. package/dist/cjs/helpers/shares.d.ts +4 -0
  84. package/dist/cjs/helpers/shares.js +12 -0
  85. package/dist/cjs/helpers/shares.js.map +1 -0
  86. package/dist/cjs/helpers/stories.d.ts +7 -0
  87. package/dist/cjs/helpers/stories.js +13 -0
  88. package/dist/cjs/helpers/stories.js.map +1 -0
  89. package/dist/cjs/helpers/topicPages.d.ts +16 -0
  90. package/dist/cjs/helpers/topicPages.js +29 -0
  91. package/dist/cjs/helpers/topicPages.js.map +1 -0
  92. package/dist/cjs/helpers/trends.d.ts +7 -0
  93. package/dist/cjs/helpers/trends.js +20 -0
  94. package/dist/cjs/helpers/trends.js.map +1 -0
  95. package/dist/cjs/helpers/uri.d.ts +42 -0
  96. package/dist/cjs/helpers/uri.js +78 -0
  97. package/dist/cjs/helpers/uri.js.map +1 -0
  98. package/dist/cjs/http.d.ts +18 -0
  99. package/dist/cjs/http.js +88 -0
  100. package/dist/cjs/http.js.map +1 -0
  101. package/dist/cjs/index.d.ts +47 -0
  102. package/dist/{index.js → cjs/index.js} +90 -2
  103. package/dist/cjs/index.js.map +1 -0
  104. package/dist/cjs/info.js +115 -0
  105. package/dist/cjs/info.js.map +1 -0
  106. package/dist/{logger.d.ts → cjs/logger.d.ts} +13 -10
  107. package/dist/cjs/logger.js +179 -0
  108. package/dist/cjs/logger.js.map +1 -0
  109. package/dist/cjs/mutex.d.ts +6 -0
  110. package/dist/cjs/mutex.js +27 -0
  111. package/dist/cjs/mutex.js.map +1 -0
  112. package/dist/cjs/package.json +3 -0
  113. package/dist/{query.d.ts → cjs/query.d.ts} +5 -8
  114. package/dist/cjs/query.js +248 -0
  115. package/dist/cjs/query.js.map +1 -0
  116. package/dist/{queryArticle.d.ts → cjs/queryArticle.d.ts} +5 -5
  117. package/dist/cjs/queryArticle.js +120 -0
  118. package/dist/cjs/queryArticle.js.map +1 -0
  119. package/dist/{queryArticles.d.ts → cjs/queryArticles.d.ts} +40 -73
  120. package/dist/cjs/queryArticles.js +456 -0
  121. package/dist/cjs/queryArticles.js.map +1 -0
  122. package/dist/{queryEvent.d.ts → cjs/queryEvent.d.ts} +6 -6
  123. package/dist/cjs/queryEvent.js +417 -0
  124. package/dist/cjs/queryEvent.js.map +1 -0
  125. package/dist/{queryEvents.d.ts → cjs/queryEvents.d.ts} +30 -39
  126. package/dist/cjs/queryEvents.js +567 -0
  127. package/dist/cjs/queryEvents.js.map +1 -0
  128. package/dist/cjs/queryIterator.d.ts +34 -0
  129. package/dist/cjs/queryIterator.js +77 -0
  130. package/dist/cjs/queryIterator.js.map +1 -0
  131. package/dist/{queryMentions.d.ts → cjs/queryMentions.d.ts} +18 -18
  132. package/dist/cjs/queryMentions.js +440 -0
  133. package/dist/cjs/queryMentions.js.map +1 -0
  134. package/dist/{queryStory.d.ts → cjs/queryStory.d.ts} +23 -23
  135. package/dist/cjs/queryStory.js +120 -0
  136. package/dist/cjs/queryStory.js.map +1 -0
  137. package/dist/{recent.d.ts → cjs/recent.d.ts} +8 -8
  138. package/dist/cjs/recent.js +63 -0
  139. package/dist/cjs/recent.js.map +1 -0
  140. package/dist/{returnInfo.d.ts → cjs/returnInfo.d.ts} +21 -23
  141. package/dist/cjs/returnInfo.js +292 -0
  142. package/dist/cjs/returnInfo.js.map +1 -0
  143. package/dist/{topicPage.d.ts → cjs/topicPage.d.ts} +3 -3
  144. package/dist/cjs/topicPage.js +454 -0
  145. package/dist/cjs/topicPage.js.map +1 -0
  146. package/dist/cjs/topicPages.d.ts +13 -0
  147. package/dist/cjs/topicPages.js +22 -0
  148. package/dist/cjs/topicPages.js.map +1 -0
  149. package/dist/{trends.d.ts → cjs/trends.d.ts} +13 -13
  150. package/dist/cjs/trends.js +64 -0
  151. package/dist/cjs/trends.js.map +1 -0
  152. package/dist/{types.d.ts → cjs/types.d.ts} +135 -33
  153. package/dist/cjs/types.js.map +1 -0
  154. package/dist/cjs/version.d.ts +1 -0
  155. package/dist/cjs/version.js +5 -0
  156. package/dist/cjs/version.js.map +1 -0
  157. package/dist/esm/analytics.d.ts +83 -0
  158. package/dist/esm/analytics.js +170 -0
  159. package/dist/esm/analytics.js.map +1 -0
  160. package/dist/esm/base.d.ts +82 -0
  161. package/dist/esm/base.js +182 -0
  162. package/dist/esm/base.js.map +1 -0
  163. package/dist/esm/counts.d.ts +81 -0
  164. package/dist/esm/counts.js +114 -0
  165. package/dist/esm/counts.js.map +1 -0
  166. package/dist/esm/dailyShares.d.ts +10 -0
  167. package/dist/esm/dailyShares.js +41 -0
  168. package/dist/esm/dailyShares.js.map +1 -0
  169. package/dist/esm/data.d.ts +296 -0
  170. package/dist/esm/data.js +3 -0
  171. package/dist/esm/data.js.map +1 -0
  172. package/dist/esm/eventForText.d.ts +48 -0
  173. package/dist/esm/eventForText.js +57 -0
  174. package/dist/esm/eventForText.js.map +1 -0
  175. package/dist/esm/eventRegistry.d.ts +343 -0
  176. package/dist/esm/eventRegistry.js +849 -0
  177. package/dist/esm/eventRegistry.js.map +1 -0
  178. package/dist/esm/fluent/analytics.d.ts +24 -0
  179. package/dist/esm/fluent/analytics.js +43 -0
  180. package/dist/esm/fluent/analytics.js.map +1 -0
  181. package/dist/esm/fluent/articles.d.ts +23 -0
  182. package/dist/esm/fluent/articles.js +30 -0
  183. package/dist/esm/fluent/articles.js.map +1 -0
  184. package/dist/esm/fluent/counts.d.ts +8 -0
  185. package/dist/esm/fluent/counts.js +13 -0
  186. package/dist/esm/fluent/counts.js.map +1 -0
  187. package/dist/esm/fluent/eventForText.d.ts +4 -0
  188. package/dist/esm/fluent/eventForText.js +5 -0
  189. package/dist/esm/fluent/eventForText.js.map +1 -0
  190. package/dist/esm/fluent/events.d.ts +23 -0
  191. package/dist/esm/fluent/events.js +30 -0
  192. package/dist/esm/fluent/events.js.map +1 -0
  193. package/dist/esm/fluent/info.d.ts +10 -0
  194. package/dist/esm/fluent/info.js +19 -0
  195. package/dist/esm/fluent/info.js.map +1 -0
  196. package/dist/esm/fluent/mentions.d.ts +18 -0
  197. package/dist/esm/fluent/mentions.js +27 -0
  198. package/dist/esm/fluent/mentions.js.map +1 -0
  199. package/dist/esm/fluent/recent.d.ts +8 -0
  200. package/dist/esm/fluent/recent.js +13 -0
  201. package/dist/esm/fluent/recent.js.map +1 -0
  202. package/dist/esm/fluent/shares.d.ts +8 -0
  203. package/dist/esm/fluent/shares.js +13 -0
  204. package/dist/esm/fluent/shares.js.map +1 -0
  205. package/dist/esm/fluent/stories.d.ts +8 -0
  206. package/dist/esm/fluent/stories.js +10 -0
  207. package/dist/esm/fluent/stories.js.map +1 -0
  208. package/dist/esm/fluent/topicPages.d.ts +10 -0
  209. package/dist/esm/fluent/topicPages.js +16 -0
  210. package/dist/esm/fluent/topicPages.js.map +1 -0
  211. package/dist/esm/fluent/trends.d.ts +11 -0
  212. package/dist/esm/fluent/trends.js +19 -0
  213. package/dist/esm/fluent/trends.js.map +1 -0
  214. package/dist/esm/helpers/analytics.d.ts +68 -0
  215. package/dist/esm/helpers/analytics.js +86 -0
  216. package/dist/esm/helpers/analytics.js.map +1 -0
  217. package/dist/esm/helpers/articles.d.ts +24 -0
  218. package/dist/esm/helpers/articles.js +26 -0
  219. package/dist/esm/helpers/articles.js.map +1 -0
  220. package/dist/esm/helpers/counts.d.ts +4 -0
  221. package/dist/esm/helpers/counts.js +8 -0
  222. package/dist/esm/helpers/counts.js.map +1 -0
  223. package/dist/esm/helpers/eventForText.d.ts +6 -0
  224. package/dist/esm/helpers/eventForText.js +10 -0
  225. package/dist/esm/helpers/eventForText.js.map +1 -0
  226. package/dist/esm/helpers/events.d.ts +18 -0
  227. package/dist/esm/helpers/events.js +26 -0
  228. package/dist/esm/helpers/events.js.map +1 -0
  229. package/dist/esm/helpers/info.d.ts +6 -0
  230. package/dist/esm/helpers/info.js +14 -0
  231. package/dist/esm/helpers/info.js.map +1 -0
  232. package/dist/esm/helpers/mentions.d.ts +10 -0
  233. package/dist/esm/helpers/mentions.js +17 -0
  234. package/dist/esm/helpers/mentions.js.map +1 -0
  235. package/dist/esm/helpers/recent.d.ts +10 -0
  236. package/dist/esm/helpers/recent.js +14 -0
  237. package/dist/esm/helpers/recent.js.map +1 -0
  238. package/dist/esm/helpers/shares.d.ts +4 -0
  239. package/dist/esm/helpers/shares.js +8 -0
  240. package/dist/esm/helpers/shares.js.map +1 -0
  241. package/dist/esm/helpers/stories.d.ts +7 -0
  242. package/dist/esm/helpers/stories.js +10 -0
  243. package/dist/esm/helpers/stories.js.map +1 -0
  244. package/dist/esm/helpers/topicPages.d.ts +16 -0
  245. package/dist/esm/helpers/topicPages.js +24 -0
  246. package/dist/esm/helpers/topicPages.js.map +1 -0
  247. package/dist/esm/helpers/trends.d.ts +7 -0
  248. package/dist/esm/helpers/trends.js +14 -0
  249. package/dist/esm/helpers/trends.js.map +1 -0
  250. package/dist/esm/helpers/uri.d.ts +42 -0
  251. package/dist/esm/helpers/uri.js +68 -0
  252. package/dist/esm/helpers/uri.js.map +1 -0
  253. package/dist/esm/http.d.ts +18 -0
  254. package/dist/esm/http.js +85 -0
  255. package/dist/esm/http.js.map +1 -0
  256. package/dist/esm/index.d.ts +47 -0
  257. package/dist/esm/index.js +47 -0
  258. package/dist/esm/index.js.map +1 -0
  259. package/dist/esm/info.d.ts +61 -0
  260. package/dist/esm/info.js +108 -0
  261. package/dist/esm/info.js.map +1 -0
  262. package/dist/esm/logger.d.ts +47 -0
  263. package/dist/esm/logger.js +142 -0
  264. package/dist/esm/logger.js.map +1 -0
  265. package/dist/esm/mutex.d.ts +6 -0
  266. package/dist/esm/mutex.js +23 -0
  267. package/dist/esm/mutex.js.map +1 -0
  268. package/dist/esm/package.json +3 -0
  269. package/dist/esm/query.d.ts +50 -0
  270. package/dist/esm/query.js +240 -0
  271. package/dist/esm/query.js.map +1 -0
  272. package/dist/esm/queryArticle.d.ts +61 -0
  273. package/dist/esm/queryArticle.js +111 -0
  274. package/dist/esm/queryArticle.js.map +1 -0
  275. package/dist/esm/queryArticles.d.ts +111 -0
  276. package/dist/esm/queryArticles.js +438 -0
  277. package/dist/esm/queryArticles.js.map +1 -0
  278. package/dist/esm/queryEvent.d.ts +140 -0
  279. package/dist/esm/queryEvent.js +403 -0
  280. package/dist/esm/queryEvent.js.map +1 -0
  281. package/dist/esm/queryEvents.d.ts +201 -0
  282. package/dist/esm/queryEvents.js +545 -0
  283. package/dist/esm/queryEvents.js.map +1 -0
  284. package/dist/esm/queryIterator.d.ts +34 -0
  285. package/dist/esm/queryIterator.js +73 -0
  286. package/dist/esm/queryIterator.js.map +1 -0
  287. package/dist/esm/queryMentions.d.ts +96 -0
  288. package/dist/esm/queryMentions.js +425 -0
  289. package/dist/esm/queryMentions.js.map +1 -0
  290. package/dist/esm/queryStory.d.ts +58 -0
  291. package/dist/esm/queryStory.js +110 -0
  292. package/dist/esm/queryStory.js.map +1 -0
  293. package/dist/esm/recent.d.ts +23 -0
  294. package/dist/esm/recent.js +58 -0
  295. package/dist/esm/recent.js.map +1 -0
  296. package/dist/esm/returnInfo.d.ts +66 -0
  297. package/dist/esm/returnInfo.js +245 -0
  298. package/dist/esm/returnInfo.js.map +1 -0
  299. package/dist/esm/topicPage.d.ts +157 -0
  300. package/dist/esm/topicPage.js +417 -0
  301. package/dist/esm/topicPage.js.map +1 -0
  302. package/dist/esm/topicPages.d.ts +13 -0
  303. package/dist/esm/topicPages.js +18 -0
  304. package/dist/esm/topicPages.js.map +1 -0
  305. package/dist/esm/trends.d.ts +35 -0
  306. package/dist/esm/trends.js +56 -0
  307. package/dist/esm/trends.js.map +1 -0
  308. package/dist/esm/types.d.ts +2555 -0
  309. package/dist/esm/types.js +2 -0
  310. package/dist/esm/types.js.map +1 -0
  311. package/dist/esm/version.d.ts +1 -0
  312. package/dist/esm/version.js +2 -0
  313. package/dist/esm/version.js.map +1 -0
  314. package/package.json +71 -42
  315. package/src/analytics.ts +197 -0
  316. package/src/base.ts +200 -0
  317. package/src/counts.ts +118 -0
  318. package/src/dailyShares.ts +46 -0
  319. package/src/data.ts +310 -0
  320. package/src/eventForText.ts +60 -0
  321. package/src/eventRegistry.ts +1005 -0
  322. package/src/fluent/analytics.ts +84 -0
  323. package/src/fluent/articles.ts +40 -0
  324. package/src/fluent/counts.ts +15 -0
  325. package/src/fluent/eventForText.ts +10 -0
  326. package/src/fluent/events.ts +40 -0
  327. package/src/fluent/info.ts +23 -0
  328. package/src/fluent/mentions.ts +34 -0
  329. package/src/fluent/recent.ts +15 -0
  330. package/src/fluent/shares.ts +15 -0
  331. package/src/fluent/stories.ts +12 -0
  332. package/src/fluent/topicPages.ts +20 -0
  333. package/src/fluent/trends.ts +34 -0
  334. package/src/helpers/analytics.ts +134 -0
  335. package/src/helpers/articles.ts +42 -0
  336. package/src/helpers/counts.ts +19 -0
  337. package/src/helpers/eventForText.ts +16 -0
  338. package/src/helpers/events.ts +43 -0
  339. package/src/helpers/info.ts +31 -0
  340. package/src/helpers/mentions.ts +27 -0
  341. package/src/helpers/recent.ts +22 -0
  342. package/src/helpers/shares.ts +17 -0
  343. package/src/helpers/stories.ts +16 -0
  344. package/src/helpers/topicPages.ts +28 -0
  345. package/src/helpers/trends.ts +36 -0
  346. package/src/helpers/uri.ts +78 -0
  347. package/src/http.ts +110 -0
  348. package/src/index.ts +205 -0
  349. package/src/info.ts +120 -0
  350. package/src/logger.ts +177 -0
  351. package/src/mutex.ts +22 -0
  352. package/src/query.ts +258 -0
  353. package/src/queryArticle.ts +138 -0
  354. package/src/queryArticles.ts +576 -0
  355. package/src/queryEvent.ts +503 -0
  356. package/src/queryEvents.ts +672 -0
  357. package/src/queryIterator.ts +89 -0
  358. package/src/queryMentions.ts +552 -0
  359. package/src/queryStory.ts +152 -0
  360. package/src/recent.ts +73 -0
  361. package/src/returnInfo.ts +372 -0
  362. package/src/topicPage.ts +481 -0
  363. package/src/topicPages.ts +18 -0
  364. package/src/trends.ts +62 -0
  365. package/src/types.ts +2678 -0
  366. package/src/version.ts +1 -0
  367. package/dist/analytics.js +0 -337
  368. package/dist/analytics.js.map +0 -1
  369. package/dist/base.js +0 -262
  370. package/dist/base.js.map +0 -1
  371. package/dist/counts.js +0 -163
  372. package/dist/counts.js.map +0 -1
  373. package/dist/dailyShares.js +0 -91
  374. package/dist/dailyShares.js.map +0 -1
  375. package/dist/data.js.map +0 -1
  376. package/dist/eventForText.js +0 -127
  377. package/dist/eventForText.js.map +0 -1
  378. package/dist/eventRegistry.js +0 -1099
  379. package/dist/eventRegistry.js.map +0 -1
  380. package/dist/index.d.ts +0 -21
  381. package/dist/index.js.map +0 -1
  382. package/dist/info.js +0 -172
  383. package/dist/info.js.map +0 -1
  384. package/dist/logger.js +0 -144
  385. package/dist/logger.js.map +0 -1
  386. package/dist/query.js +0 -334
  387. package/dist/query.js.map +0 -1
  388. package/dist/queryArticle.js +0 -184
  389. package/dist/queryArticle.js.map +0 -1
  390. package/dist/queryArticles.js +0 -730
  391. package/dist/queryArticles.js.map +0 -1
  392. package/dist/queryEvent.js +0 -588
  393. package/dist/queryEvent.js.map +0 -1
  394. package/dist/queryEvents.js +0 -826
  395. package/dist/queryEvents.js.map +0 -1
  396. package/dist/queryMentions.js +0 -638
  397. package/dist/queryMentions.js.map +0 -1
  398. package/dist/queryStory.js +0 -195
  399. package/dist/queryStory.js.map +0 -1
  400. package/dist/recent.js +0 -200
  401. package/dist/recent.js.map +0 -1
  402. package/dist/returnInfo.js +0 -333
  403. package/dist/returnInfo.js.map +0 -1
  404. package/dist/topicPage.js +0 -600
  405. package/dist/topicPage.js.map +0 -1
  406. package/dist/trends.js +0 -116
  407. package/dist/trends.js.map +0 -1
  408. package/dist/types.js.map +0 -1
  409. /package/dist/{counts.d.ts → cjs/counts.d.ts} +0 -0
  410. /package/dist/{dailyShares.d.ts → cjs/dailyShares.d.ts} +0 -0
  411. /package/dist/{data.js → cjs/data.js} +0 -0
  412. /package/dist/{info.d.ts → cjs/info.d.ts} +0 -0
  413. /package/dist/{types.js → cjs/types.js} +0 -0
@@ -0,0 +1,1005 @@
1
+ import * as fs from "fs";
2
+ import { Mutex } from "./mutex";
3
+ import { erFetch, ErHttpResponse } from "./http";
4
+ import { ConceptInfoFlags, ReturnInfo } from "./returnInfo";
5
+ import { ER } from "./types";
6
+ import { QueryParamsBase, sleep } from "./base";
7
+ import { QueryArticle } from "./queryArticle";
8
+ import { QueryArticles } from "./queryArticles";
9
+ import { QueryEvents } from "./queryEvents";
10
+ import { QueryEvent } from "./queryEvent";
11
+ import { Logger } from "./logger";
12
+ import { __version__ } from "./version";
13
+ import { ArticlesFluent } from "./fluent/articles";
14
+ import { EventsFluent } from "./fluent/events";
15
+ import { MentionsFluent } from "./fluent/mentions";
16
+ import { StoriesFluent } from "./fluent/stories";
17
+ import { TrendsFluent } from "./fluent/trends";
18
+ import { CountsFluent } from "./fluent/counts";
19
+ import { SharesFluent } from "./fluent/shares";
20
+ import { RecentFluent } from "./fluent/recent";
21
+ import { InfoFluent } from "./fluent/info";
22
+ import { TopicPagesFluent } from "./fluent/topicPages";
23
+ import { AnalyticsFluent } from "./fluent/analytics";
24
+ import { createEventForTextFluent, EventForTextFluent } from "./fluent/eventForText";
25
+ import {
26
+ authorUri as resolveAuthorUri,
27
+ categoryUri as resolveCategoryUri,
28
+ conceptClassUri as resolveConceptClassUri,
29
+ conceptUri as resolveConceptUri,
30
+ eventTypeUri as resolveEventTypeUri,
31
+ locationUri as resolveLocationUri,
32
+ sourceGroupUri as resolveSourceGroupUri,
33
+ sourceUri as resolveSourceUri
34
+ } from "./helpers/uri";
35
+
36
+ type UriSuggestion = {
37
+ uri?: string;
38
+ };
39
+
40
+ /**
41
+ * Picks the given field off the first (best) match returned by a suggestX() call.
42
+ * Backs every getXUri() resolver below — they all follow the same
43
+ * "take the top suggestion's identifying field" shape.
44
+ */
45
+ function firstMatchField<T, K extends keyof T>(matches: T[] | undefined, field: K): T[K] | undefined {
46
+ return matches?.[0]?.[field];
47
+ }
48
+
49
+ /**
50
+ * @class EventRegistry
51
+ * Main class responsible for obtaining results form the Event Registry
52
+ */
53
+ export class EventRegistry {
54
+ public logger: Logger;
55
+ /** Ergonomic article search/iterate/get façade — see `ArticlesFluent`. */
56
+ public readonly articles: ArticlesFluent;
57
+ /** Ergonomic event search/iterate/get façade — see `EventsFluent`. */
58
+ public readonly events: EventsFluent;
59
+ /** Ergonomic mentions search/iterate façade — see `MentionsFluent`. */
60
+ public readonly mentions: MentionsFluent;
61
+ /** Ergonomic story lookup façade — see `StoriesFluent`. */
62
+ public readonly stories: StoriesFluent;
63
+ /** Ergonomic trending concepts/categories façade — see `TrendsFluent`. */
64
+ public readonly trends: TrendsFluent;
65
+ /** Ergonomic concept/category mention-count façade — see `CountsFluent`. */
66
+ public readonly counts: CountsFluent;
67
+ /** Ergonomic top-shared articles/events façade — see `SharesFluent`. */
68
+ public readonly shares: SharesFluent;
69
+ /** Ergonomic recent activity façade — see `RecentFluent`. */
70
+ public readonly recent: RecentFluent;
71
+ /** Ergonomic source/concept/category info façade — see `InfoFluent`. */
72
+ public readonly info: InfoFluent;
73
+ /** Ergonomic topic page listing/loading/building façade — see `TopicPagesFluent`. */
74
+ public readonly topicPages: TopicPagesFluent;
75
+ /** Ergonomic text analytics façade — see `AnalyticsFluent`. */
76
+ public readonly analytics: AnalyticsFluent;
77
+ /** Ergonomic callable form of `GetEventForText.compute()`. */
78
+ public readonly eventForText: EventForTextFluent;
79
+ /** Ergonomic concept uri resolution — see `helpers/uri.conceptUri`. */
80
+ public readonly concepts: {
81
+ uri: (label: string, args?: ER.GetConceptUriArguments) => Promise<string>;
82
+ };
83
+ /** Ergonomic category uri resolution — see `helpers/uri.categoryUri`. */
84
+ public readonly categories: {
85
+ uri: (label: string) => Promise<string>;
86
+ };
87
+ /** Ergonomic news source/source group uri resolution — see `helpers/uri.sourceUri`. */
88
+ public readonly sources: {
89
+ uri: (label: string, dataType?: ER.DataType[] | ER.DataType) => Promise<string>;
90
+ groupUri: (label: string) => Promise<string>;
91
+ };
92
+ /** Ergonomic location uri resolution — see `helpers/uri.locationUri`. */
93
+ public readonly locations: {
94
+ uri: (label: string, args?: ER.GetLocationUriArguments) => Promise<string>;
95
+ };
96
+ /** Ergonomic event type uri resolution — see `helpers/uri.eventTypeUri`. */
97
+ public readonly eventTypes: {
98
+ uri: (label: string) => Promise<string>;
99
+ };
100
+ /** Ergonomic concept class uri resolution — see `helpers/uri.conceptClassUri`. */
101
+ public readonly conceptClasses: {
102
+ uri: (label: string, lang?: string) => Promise<string>;
103
+ };
104
+ /** Ergonomic author uri resolution — see `helpers/uri.authorUri`. */
105
+ public readonly authors: {
106
+ uri: (label: string) => Promise<string>;
107
+ };
108
+ private config: ER.Config = {
109
+ host: "https://eventregistry.org",
110
+ hostAnalytics: "https://analytics.eventregistry.org",
111
+ logging: false,
112
+ minDelayBetweenRequests: 0.5,
113
+ repeatFailedRequestCount: -1,
114
+ verboseOutput: false,
115
+ allowUseOfArchive: true
116
+ };
117
+ private headers = new Headers();
118
+ private dailyAvailableRequests = -1;
119
+ private remainingAvailableRequests = -1;
120
+ private lastQueryTime = 0;
121
+ private _logRequests = false;
122
+ private readonly lock: Mutex;
123
+ private extraParams: Record<string, unknown> | null = null;
124
+ private readonly stopStatusCodes = [204, 400, 401, 403, 530];
125
+ constructor(config: ER.Config = {}) {
126
+ this.lock = new Mutex();
127
+
128
+ const settingsPath = config.settingsFName || "settings.json";
129
+ let fileSettings: ER.Config = {};
130
+ if (fs && fs.existsSync(settingsPath)) {
131
+ fileSettings = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
132
+ }
133
+
134
+ this.config = {
135
+ ...this.config,
136
+ ...fileSettings,
137
+ ...config,
138
+ host: config.host ?? fileSettings.host ?? this.config.host,
139
+ hostAnalytics: config.hostAnalytics ?? fileSettings.hostAnalytics ?? this.config.hostAnalytics,
140
+ apiKey: config.apiKey !== undefined ? config.apiKey : fileSettings.apiKey
141
+ };
142
+
143
+ this._logRequests = this.config.logging ?? false;
144
+ this.logger = new Logger({ logging: this.config.logging, logRequests: this._logRequests });
145
+
146
+ if (config.apiKey) {
147
+ this.logger.debug("using user provided API key for making requests");
148
+ } else if (fileSettings.apiKey) {
149
+ this.logger.debug("found apiKey in settings file which will be used for making requests");
150
+ }
151
+
152
+ if (this.config?.apiKey === undefined || this.config?.apiKey === null) {
153
+ this.logger.info("No API key was provided. You will be allowed to perform only a very limited number of requests per day.");
154
+ }
155
+ this.logger.debug(`Event Registry host: ${this.config.host}`);
156
+ this.logger.debug(`Text analytics host: ${this.config.hostAnalytics}`);
157
+ this.config.minDelayBetweenRequests = (this.config.minDelayBetweenRequests ?? 0.5) * 1000;
158
+
159
+ this.articles = new ArticlesFluent(this);
160
+ this.events = new EventsFluent(this);
161
+ this.mentions = new MentionsFluent(this);
162
+ this.stories = new StoriesFluent(this);
163
+ this.trends = new TrendsFluent(this);
164
+ this.counts = new CountsFluent(this);
165
+ this.shares = new SharesFluent(this);
166
+ this.recent = new RecentFluent(this);
167
+ this.info = new InfoFluent(this);
168
+ this.topicPages = new TopicPagesFluent(this);
169
+ this.analytics = new AnalyticsFluent(this);
170
+ this.eventForText = createEventForTextFluent(this);
171
+ this.concepts = {
172
+ uri: (label: string, args?: ER.GetConceptUriArguments) => resolveConceptUri(this, label, args)
173
+ };
174
+ this.categories = {
175
+ uri: (label: string) => resolveCategoryUri(this, label)
176
+ };
177
+ this.sources = {
178
+ uri: (label: string, dataType?: ER.DataType[] | ER.DataType) => resolveSourceUri(this, label, dataType),
179
+ groupUri: (label: string) => resolveSourceGroupUri(this, label)
180
+ };
181
+ this.locations = {
182
+ uri: (label: string, args?: ER.GetLocationUriArguments) => resolveLocationUri(this, label, args)
183
+ };
184
+ this.eventTypes = {
185
+ uri: (label: string) => resolveEventTypeUri(this, label)
186
+ };
187
+ this.conceptClasses = {
188
+ uri: (label: string, lang?: string) => resolveConceptClassUri(this, label, lang)
189
+ };
190
+ this.authors = {
191
+ uri: (label: string) => resolveAuthorUri(this, label)
192
+ };
193
+ }
194
+
195
+ public getHost(): string {
196
+ return this.config.host ?? "https://eventregistry.org";
197
+ }
198
+
199
+ public getHostAnalytics(): string {
200
+ return this.config.hostAnalytics ?? "https://analytics.eventregistry.org";
201
+ }
202
+
203
+ public getApiKey(): string | undefined {
204
+ return this.config.apiKey;
205
+ }
206
+
207
+ /** Minimum delay between requests in seconds (constructor units). */
208
+ public getMinDelayBetweenRequests(): number {
209
+ return (this.config.minDelayBetweenRequests ?? 500) / 1000;
210
+ }
211
+
212
+ public getRepeatFailedRequestCount(): number {
213
+ return this.config.repeatFailedRequestCount ?? -1;
214
+ }
215
+
216
+ /**
217
+ * Check the latest Node.js SDK version and log if this client is outdated.
218
+ * Prefers `/static/nodejsSDKVersion.txt` on the API host; if that file is missing
219
+ * (or the request fails), falls back to the npm registry `latest` document.
220
+ */
221
+ public async checkVersion(): Promise<void> {
222
+ try {
223
+ const latestVersion = (await this.readHostSdkVersion()) ?? (await this.readNpmLatestVersion());
224
+ if (latestVersion === undefined || latestVersion.length > 20) {
225
+ return;
226
+ }
227
+ const currentVersion = __version__;
228
+ const latestParts = latestVersion.split(".");
229
+ const currentParts = currentVersion.split(".");
230
+ for (let i = 0; i < latestParts.length && i < currentParts.length; i++) {
231
+ const latest = parseInt(latestParts[i], 10);
232
+ const current = parseInt(currentParts[i], 10);
233
+ if (latest > current) {
234
+ this.logger.info("==============\nYour version of the module is outdated, please update to the latest version");
235
+ this.logger.info(`Your version is ${currentVersion} while the latest is ${latestVersion}`);
236
+ this.logger.info("Update by calling: npm install eventregistry@latest\n==============");
237
+ return;
238
+ }
239
+ if (latest < current) {
240
+ return;
241
+ }
242
+ }
243
+ } catch {
244
+ // ignore version check failures
245
+ }
246
+ }
247
+
248
+ private async readHostSdkVersion(): Promise<string | undefined> {
249
+ try {
250
+ const resp = await erFetch<string>({
251
+ url: `${this.config.host}/static/nodejsSDKVersion.txt`,
252
+ method: "GET",
253
+ responseType: "text",
254
+ retry: 0,
255
+ stopStatusCodes: [204, 400, 401, 403, 404, 530]
256
+ });
257
+ return resp.data.trim();
258
+ } catch {
259
+ return undefined;
260
+ }
261
+ }
262
+
263
+ private async readNpmLatestVersion(): Promise<string | undefined> {
264
+ try {
265
+ const resp = await erFetch<{ version?: string }>({
266
+ url: "https://registry.npmjs.org/eventregistry/latest",
267
+ method: "GET",
268
+ retry: 0
269
+ });
270
+ const version = resp.data?.version;
271
+ return typeof version === "string" ? version.trim() : undefined;
272
+ } catch {
273
+ return undefined;
274
+ }
275
+ }
276
+
277
+ public setExtraParams(params: Record<string, unknown> | null): void {
278
+ if (params !== null && (typeof params !== "object" || Array.isArray(params))) {
279
+ throw new TypeError("params must be an object or null");
280
+ }
281
+ this.extraParams = params;
282
+ }
283
+
284
+ private createErrorResponse<T>(error: unknown): ErHttpResponse<T> {
285
+ const message = error instanceof Error ? error.message : String(error);
286
+ return {
287
+ data: { error: message } as T,
288
+ status: 0,
289
+ statusText: "error",
290
+ headers: new Headers()
291
+ };
292
+ }
293
+
294
+ /**
295
+ * Should all requests be logged to a file or not?
296
+ */
297
+ public setLogging(logging: boolean) {
298
+ this._logRequests = logging;
299
+ this.logger.toggleRequestLogging(logging);
300
+ }
301
+
302
+ public get allowUseOfArchive() {
303
+ return this.config.allowUseOfArchive;
304
+ }
305
+
306
+ public get verboseOutput() {
307
+ return this.config.verboseOutput;
308
+ }
309
+
310
+ /**
311
+ * Main method for executing the search queries.
312
+ * @param query instance of Query class
313
+ */
314
+ public async execQuery<T = ER.SuccessfulResponse<unknown>>(
315
+ query: { path: string; getQueryParams: () => Record<string, unknown> },
316
+ allowUseOfArchive: boolean = this.config.allowUseOfArchive ?? true
317
+ ): Promise<ER.Response<T>> {
318
+ const params = query.getQueryParams();
319
+ const request = await this.jsonRequest<ER.Response<T>>(query.path, params, allowUseOfArchive);
320
+ if (!request?.data && this.config?.verboseOutput) {
321
+ this.logger.error("Request did not return with the 'data' property.");
322
+ }
323
+ return (request?.data || {} as ER.Response<T>);
324
+ }
325
+
326
+ /**
327
+ * Wait until minDelayBetweenRequests has elapsed since the last attempt.
328
+ * Must run while holding `this.lock`.
329
+ */
330
+ private async waitForTurn(): Promise<void> {
331
+ const now = Date.now();
332
+ const minDelayBetweenRequests = this.config.minDelayBetweenRequests ?? 500;
333
+ if (this.lastQueryTime && now - this.lastQueryTime < minDelayBetweenRequests) {
334
+ await sleep(minDelayBetweenRequests - (now - this.lastQueryTime));
335
+ }
336
+ }
337
+
338
+ public async jsonRequestAnalytics<T = unknown>(path: string, parameters?: Record<string, unknown>, headers?: Record<string, unknown>, cookies?: Record<string, unknown>): Promise<ErHttpResponse<T>> {
339
+ let request: ErHttpResponse<T>;
340
+ await this.lock.acquire();
341
+ try {
342
+ await this.waitForTurn();
343
+ parameters = {
344
+ ...parameters,
345
+ ...(this.extraParams || {}),
346
+ apiKey: this.config?.apiKey
347
+ };
348
+ let requestHeaders: Record<string, string> = {...(headers as Record<string, string> || {})};
349
+ if (!!headers) {
350
+ requestHeaders = {...(headers as Record<string, string>)};
351
+ }
352
+ if (!!cookies) {
353
+ const cookieString = Object.keys(cookies).map((key) => key + "=" + cookies[key]).join(";") + ";";
354
+ requestHeaders = {...requestHeaders, Cookie: cookieString};
355
+ }
356
+ try {
357
+ request = await erFetch<T>({
358
+ url: `${this.config.hostAnalytics}${path}`,
359
+ method: "POST",
360
+ body: parameters,
361
+ headers: requestHeaders,
362
+ timeoutMs: 600_000,
363
+ retry: this.config.repeatFailedRequestCount,
364
+ retryDelayMs: 5000,
365
+ stopStatusCodes: this.stopStatusCodes
366
+ });
367
+ } finally {
368
+ this.lastQueryTime = Date.now();
369
+ }
370
+ this.headers = request.headers;
371
+ if (request?.status !== 200) {
372
+ throw new Error(request?.statusText);
373
+ }
374
+ const errorMessage = (request?.data as Record<string, string>)?.error || "";
375
+ if (errorMessage) {
376
+ throw new Error(errorMessage);
377
+ }
378
+ } catch (error: unknown) {
379
+ request = this.createErrorResponse<T>(error);
380
+ const err = error as { stack?: string; message?: string; response?: { status?: number; statusText?: string; data?: unknown }; errno?: unknown };
381
+ if (this.config.verboseOutput) {
382
+ this.logger.error("Event Registry Analytics exception while executing the request.");
383
+ if (err && err.stack && err.message) {
384
+ this.logger.error(err.message);
385
+ } else {
386
+ this.logger.error(`${err?.response?.status}: ${err?.response?.statusText} => ${err?.response?.data}`);
387
+ }
388
+ }
389
+ // try to print out the error that should be passed by in case the server is down or responds with errors
390
+ if (this.config?.logging) {
391
+ this.logger.error(String(err?.errno ?? error));
392
+ }
393
+ } finally {
394
+ this.lock.release();
395
+ }
396
+ return request;
397
+ }
398
+
399
+ /**
400
+ * Make a request for json data
401
+ * @param path url on er (e.g. "/api/v1/article")
402
+ * @param parameters Optional parameters to be included in the request
403
+ */
404
+ public async jsonRequest<T = unknown>(path: string, parameters?: Record<string, unknown>, allowUseOfArchive: boolean = this.config.allowUseOfArchive ?? true): Promise<ErHttpResponse<T>> {
405
+ let request: ErHttpResponse<T>;
406
+ await this.lock.acquire();
407
+ try {
408
+ await this.waitForTurn();
409
+ if (this._logRequests) {
410
+ if (Object.keys(parameters || {}).length > 0) {
411
+ this.logger.logRequest("# " + JSON.stringify(parameters) + "\n");
412
+ }
413
+ this.logger.logRequest(path + "\n\n");
414
+ }
415
+ parameters = {
416
+ ...parameters,
417
+ ...(this.extraParams || {}),
418
+ apiKey: this.config?.apiKey
419
+ };
420
+ if (!allowUseOfArchive) {
421
+ parameters = {...parameters, forceMaxDataTimeWindow: 31};
422
+ }
423
+ try {
424
+ request = await erFetch<T>({
425
+ url: `${this.config.host}${path}`,
426
+ method: "POST",
427
+ body: parameters,
428
+ timeoutMs: 600_000,
429
+ retry: this.config.repeatFailedRequestCount,
430
+ retryDelayMs: 5000,
431
+ stopStatusCodes: this.stopStatusCodes
432
+ });
433
+ } finally {
434
+ this.lastQueryTime = Date.now();
435
+ }
436
+ this.headers = request.headers;
437
+ if (request?.status !== 200) {
438
+ throw new Error(request?.statusText);
439
+ }
440
+ if (this.getLastHeader("warning")) {
441
+ this.logger.warn(`WARNING: ${this.getLastHeader("warning")}`);
442
+ }
443
+ this.dailyAvailableRequests = Number(this.getLastHeader("x-ratelimit-limit", "-1"));
444
+ this.remainingAvailableRequests = Number(this.getLastHeader("x-ratelimit-remaining", "-1"));
445
+ const errorMessage = (request?.data as Record<string, string>)?.error || "";
446
+ if (errorMessage) {
447
+ throw new Error(errorMessage);
448
+ }
449
+ } catch (error: unknown) {
450
+ request = this.createErrorResponse<T>(error);
451
+ const err = error as { stack?: string; message?: string; response?: { status?: number; statusText?: string; data?: unknown }; errno?: unknown };
452
+ // try to print out the error that should be passed by in case the server is down or responds with errors
453
+ if (this.config.verboseOutput) {
454
+ this.logger.error("Event Registry exception while executing the request.");
455
+ if (err && err.stack && err.message) {
456
+ this.logger.error(err.message);
457
+ } else {
458
+ this.logger.error(`${err?.response?.status}: ${err?.response?.statusText} => ${err?.response?.data}`);
459
+ }
460
+ }
461
+ if (this.config?.logging) {
462
+ this.logger.error(String(err?.errno ?? error));
463
+ }
464
+ } finally {
465
+ this.lock.release();
466
+ }
467
+ return request;
468
+ }
469
+
470
+ /**
471
+ * get the number of requests that are still available for the user today. Information is only accessible after you make some query.
472
+ */
473
+ public getRemainingAvailableRequests() {
474
+ return this.remainingAvailableRequests;
475
+ }
476
+
477
+ /**
478
+ * get the total number of requests that the user can make in a day. Information is only accessible after you make some query.
479
+ */
480
+ public getDailyAvailableRequests() {
481
+ return this.dailyAvailableRequests;
482
+ }
483
+
484
+ /**
485
+ * Return the headers returned in the response object of the last executed request
486
+ */
487
+ public getLastHeaders(): Headers {
488
+ return this.headers;
489
+ }
490
+
491
+ /**
492
+ * Get a value of the header headerName that was set in the headers in the last response object
493
+ */
494
+ public getLastHeader(headerName: string, dfltVal?: string) {
495
+ return this.headers.get(headerName) ?? dfltVal;
496
+ }
497
+
498
+ /**
499
+ * print some statistics about the last executed request
500
+ */
501
+ public printLastReqStats() {
502
+ this.logger.info(`Tokens used by the request: ${this.getLastHeader("req-tokens")}`);
503
+ this.logger.info(`Performed action: ${this.getLastHeader("req-action")}`);
504
+ this.logger.info(`Was archive used for the query: ${this.getLastReqArchiveUse() ? "Yes" : "No"}`);
505
+ }
506
+
507
+ /**
508
+ * return true or false depending on whether the last request used the archive or not
509
+ */
510
+ public getLastReqArchiveUse() {
511
+ return this.getLastHeader("req-archive", "0") === "1";
512
+ }
513
+
514
+ /**
515
+ * Return the number of used and total available tokens. Can be used at any time (also before making queries)
516
+ */
517
+ public async getUsageInfo(): Promise<ER.UsageInfo> {
518
+ const request = await this.jsonRequest("/api/v1/usage");
519
+ return request.data as ER.UsageInfo;
520
+ }
521
+
522
+ public async getServiceStatus(): Promise<ER.UsageInfo> {
523
+ const request = await this.jsonRequest("/api/v1/getServiceStatus");
524
+ return request.data as ER.UsageInfo;
525
+ }
526
+
527
+ public getUrl(query: QueryArticles | QueryArticle | QueryEvents | QueryEvent) {
528
+ if (!(query instanceof QueryParamsBase)) {
529
+ if (this.config.verboseOutput) {
530
+ this.logger.warn("query parameter should be an instance of a class that has Query as a base class, such as QueryArticles or QueryEvents");
531
+ }
532
+ }
533
+ const allParams = query.getQueryParams();
534
+ return `${this.config?.host}${query?.path}?${Object.keys(allParams).map(key => `${key}=${allParams[key]}`).join("&")}`;
535
+ }
536
+
537
+ /**
538
+ * Return a list of concepts that contain the given prefix.
539
+ * Returned matching concepts are sorted based on their frequency of occurrence in news (from most to least frequent)
540
+ * @param prefix input text that should be contained in the concept
541
+ * @param args Object which contains a host of optional parameters
542
+ */
543
+ public async suggestConcepts(prefix: string, args: ER.SuggestConceptsArguments = {}) {
544
+ const { sources = [ "concepts" ] as ER.ConceptType[], lang = "eng", conceptLang = "eng", page = 1, count = 20, returnInfo = new ReturnInfo(), ...otherParams } = args;
545
+ if (page <= 0) {
546
+ throw new RangeError("page parameter should be above 0");
547
+ }
548
+
549
+ let params: Record<string, unknown> = {
550
+ prefix: prefix,
551
+ source: sources,
552
+ lang: lang,
553
+ conceptLang: conceptLang,
554
+ page: page,
555
+ count: count
556
+ };
557
+ params = {...params, ...otherParams, ...returnInfo.getParams()};
558
+ const request = await this.jsonRequest<UriSuggestion[]>("/api/v1/suggestConceptsFast", params);
559
+ return request.data;
560
+ }
561
+
562
+ /**
563
+ * Return a list of dmoz categories that contain the prefix
564
+ * @param prefix input text that should be contained in the category name
565
+ * @param args Object which contains a host of optional parameters
566
+ */
567
+ public async suggestCategories(prefix: string, args: ER.SuggestCategoriesArguments = {}) {
568
+ const {page = 1, count = 20, returnInfo = new ReturnInfo(), ...otherParams} = args;
569
+ if (page <= 0) {
570
+ throw new RangeError("page parameter should be above 0");
571
+ }
572
+ let params: Record<string, unknown> = {prefix, page, count};
573
+ params = {...params, ...otherParams, ...returnInfo.getParams()};
574
+ const request = await this.jsonRequest<UriSuggestion[]>("/api/v1/suggestCategoriesFast", params);
575
+ return request.data;
576
+ }
577
+
578
+ /**
579
+ * Return a list of news sources that match the prefix
580
+ * @param prefix input text that should be contained in the source name or uri
581
+ * @param args Object which contains a host of optional parameters
582
+ */
583
+ public async suggestNewsSources(prefix: string, args: ER.SuggestNewsSourcesArguments = {}) {
584
+ const {page = 1, count = 20, dataType = ["news", "pr", "blog"], ...otherParams} = args;
585
+ if (page <= 0) {
586
+ throw new RangeError("page parameter should be above 0");
587
+ }
588
+ const request = await this.jsonRequest<UriSuggestion[]>("/api/v1/suggestSourcesFast", {prefix, page, dataType, count, ...otherParams});
589
+ return request.data;
590
+ }
591
+
592
+ /**
593
+ * Return a list of news source groups that match the prefix
594
+ * @param prefix input text that should be contained in the source group name or uri
595
+ * @param args Object which contains a host of optional parameters
596
+ */
597
+ public async suggestSourceGroups(prefix: string, args: ER.SuggestSourceGroupsArguments = {}) {
598
+ const {page = 1, count = 20, ...otherParams} = args;
599
+ if (page <= 0) {
600
+ throw new RangeError("page parameter should be above 0");
601
+ }
602
+ const request = await this.jsonRequest<UriSuggestion[]>("/api/v1/suggestSourceGroups", {prefix, page, count, ...otherParams});
603
+ return request.data;
604
+ }
605
+
606
+ /**
607
+ * Return a list of geo locations (cities or countries) that contain the prefix
608
+ * @param prefix input text that should be contained in the location name
609
+ * @param args Object which contains a host of optional parameters
610
+ */
611
+ public async suggestLocations(prefix: string, args: ER.SuggestLocationsArguments = {}): Promise<ER.Location[]> {
612
+ const {
613
+ sources = ["place", "country"],
614
+ lang = "eng",
615
+ count = 20,
616
+ countryUri = "",
617
+ sortByDistanceTo,
618
+ returnInfo = new ReturnInfo(),
619
+ ...otherParams
620
+ } = args;
621
+ let params: Record<string, unknown> = {
622
+ prefix: prefix,
623
+ count: count,
624
+ source: sources,
625
+ lang: lang,
626
+ countryUri: countryUri
627
+ };
628
+ params = {...params, ...otherParams, ...returnInfo?.getParams()};
629
+ if (sortByDistanceTo) {
630
+ if (!Array.isArray(sortByDistanceTo)) {
631
+ throw new Error("sortByDistanceTo has to contain a tuple with latitude and longitude of the location");
632
+ }
633
+
634
+ if (sortByDistanceTo.length !== 2) {
635
+ throw new Error("The sortByDistanceTo should contain two numbers");
636
+ }
637
+
638
+ params["closeToLat"] = sortByDistanceTo[0];
639
+ params["closeToLon"] = sortByDistanceTo[1];
640
+ }
641
+ const request = await this.jsonRequest("/api/v1/suggestLocationsFast", params);
642
+ return request?.data as ER.Location[];
643
+ }
644
+
645
+ /**
646
+ * Return a list of geo locations (cities or places) that are close to the provided (lat, long) values
647
+ * @param latitude latitude part of the coordinate
648
+ * @param longitude longitude part of the coordinate
649
+ * @param radiusKm radius in kilometers around the coordinates inside which the locations should be returned
650
+ * @param args Object which contains a host of optional parameters
651
+ */
652
+ public async suggestLocationsAtCoordinate(latitude: number, longitude: number, radiusKm: number, args: ER.SuggestLocationsAtCoordinateArguments = {}) {
653
+ const {
654
+ limitToCities = false,
655
+ lang = "eng",
656
+ count = 20,
657
+ ignoreNonWiki = true,
658
+ returnInfo = new ReturnInfo(),
659
+ ...otherParams
660
+ } = args;
661
+ if (typeof latitude !== "number") {
662
+ throw new Error("The 'latitude' should be a number");
663
+ }
664
+ if (typeof longitude !== "number") {
665
+ throw new Error("The 'longitude' should be a number");
666
+ }
667
+ let params = {
668
+ action: "getLocationsAtCoordinate",
669
+ lat: latitude,
670
+ lon: longitude,
671
+ radius: radiusKm,
672
+ limitToCities: limitToCities,
673
+ count: count,
674
+ lang: lang,
675
+ ignoreNonWiki: ignoreNonWiki
676
+ };
677
+ params = {...params, ...otherParams, ...returnInfo?.getParams()};
678
+ const request = await this.jsonRequest("/api/v1/suggestLocationsFast", params);
679
+ return request?.data;
680
+ }
681
+
682
+ /**
683
+ * Return a list of news sources that are close to the provided (lat, long) values
684
+ * @param latitude latitude part of the coordinate
685
+ * @param longitude longitude part of the coordinate
686
+ * @param radiusKm radius in kilometers around the coordinates inside which the news sources should be located
687
+ * @param count number of returned suggestions
688
+ */
689
+ public async suggestSourcesAtCoordinate(latitude: number, longitude: number, radiusKm: number, count = 20, ...otherParams: unknown[]) {
690
+ if (typeof latitude !== "number") {
691
+ throw new Error("The 'latitude' should be a number");
692
+ }
693
+ if (typeof longitude !== "number") {
694
+ throw new Error("The 'longitude' should be a number");
695
+ }
696
+ const params = {
697
+ action: "getSourcesAtCoordinate",
698
+ lat: latitude,
699
+ lon: longitude,
700
+ radius: radiusKm,
701
+ count: count,
702
+ ...otherParams
703
+ };
704
+ const request = await this.jsonRequest("/api/v1/suggestSourcesFast", params);
705
+ return request?.data;
706
+ }
707
+
708
+ /**
709
+ * Return a list of news sources that are close to the provided (lat, long) values
710
+ * @param conceptUri concept that represents a geographic location for which we would like to obtain a list of sources located at the place
711
+ * @param args Object which contains a host of optional parameters
712
+ */
713
+ public async suggestSourcesAtPlace(conceptUri: string, args: ER.SuggestSourcesAtPlaceArguments = {}) {
714
+ const { page = 1, count = 20, dataType = "news", ...otherParams } = args;
715
+ const params = {
716
+ action: "getSourcesAtPlace",
717
+ conceptUri: conceptUri,
718
+ page: page,
719
+ count: count,
720
+ dataType: dataType,
721
+ ...otherParams
722
+ };
723
+ const request = await this.jsonRequest("/api/v1/suggestSourcesFast", params);
724
+ return request.data;
725
+ }
726
+
727
+ /**
728
+ * Return a list of news sources that match the prefix
729
+ * @param prefix: input text that should be contained in the author name and source url
730
+ * @param page: page of results
731
+ * @param count: number of returned suggestions
732
+ */
733
+ public async suggestAuthors(prefix: string, page = 1, count = 20, ...otherParams: unknown[]) {
734
+ if (page <= 0) {
735
+ throw new Error("Page parameter should be above 0.");
736
+ }
737
+ const params = {
738
+ prefix,
739
+ page,
740
+ count,
741
+ ...otherParams
742
+ };
743
+ const request = await this.jsonRequest<ER.Author[]>("/api/v1/suggestAuthorsFast", params);
744
+ return request.data;
745
+ }
746
+
747
+ /**
748
+ * Return a list of event types that match the prefix
749
+ * @param prefix: input text that should be contained in the industry name
750
+ * @param page: page of results
751
+ * @param count: number of returned suggestions
752
+ */
753
+ public async suggestEventTypes(prefix: string, page = 1, count = 20, ...otherParams: unknown[]) {
754
+ if (page <= 0) {
755
+ throw new Error("Page parameter should be above 0.");
756
+ }
757
+ const params = {
758
+ prefix,
759
+ page,
760
+ count,
761
+ ...otherParams
762
+ };
763
+ const request = await this.jsonRequest<UriSuggestion[]>("/api/v1/eventType/suggestEventTypes", params);
764
+ return request.data;
765
+ }
766
+
767
+ /**
768
+ * Return a list of industries that match the prefix. Note: Industries can only be used when querying mentions (QueryMentions, QueryMentionsIter)
769
+ * @param prefix: input text that should be contained in the industry name
770
+ * @param page: page of results
771
+ * @param count: number of returned suggestions
772
+ */
773
+ public async suggestIndustries(prefix: string, page = 1, count = 20, ...otherParams: unknown[]) {
774
+ if (page <= 0) {
775
+ throw new Error("Page parameter should be above 0.");
776
+ }
777
+ const params = {
778
+ prefix,
779
+ page,
780
+ count,
781
+ ...otherParams
782
+ };
783
+ const request = await this.jsonRequest("/api/v1/eventType/suggestIndustries", params);
784
+ return request.data;
785
+ }
786
+
787
+ /**
788
+ * Return a list of SDG uris. Note: Industries can only be used when querying mentions (QueryMentions, QueryMentionsIter)
789
+ */
790
+ public async getSdgUris() {
791
+ const request = await this.jsonRequest("/api/v1/eventType/sdg/getItems");
792
+ return request.data;
793
+ }
794
+
795
+ /**
796
+ * Return a list of SASB uris. Note: SASB uris can only be used when querying mentions (QueryMentions, QueryMentionsIter)
797
+ */
798
+ public async getSasbUris() {
799
+ const request = await this.jsonRequest("/api/v1/eventType/sasb/getItems");
800
+ return request.data;
801
+ }
802
+
803
+ /**
804
+ * Return a list of concept classes that match the given prefix
805
+ * @param prefix input text that should be contained in the category name
806
+ * @param args Object which contains a host of optional parameters
807
+ */
808
+ public async suggestConceptClasses(prefix: string, args: ER.SuggestConceptClassesArguments = {}) {
809
+ const {
810
+ lang = "eng",
811
+ conceptLang = "eng",
812
+ source = ["dbpedia", "custom"],
813
+ page = 1,
814
+ count = 20,
815
+ returnInfo = new ReturnInfo(),
816
+ ...otherParams
817
+ } = args;
818
+ if (page < 1) {
819
+ throw new Error("page parameter should be above 0");
820
+ }
821
+ let params: Record<string, unknown> = { prefix, lang, conceptLang, source, page, count};
822
+ params = {...params, ...otherParams, ...returnInfo?.getParams()};
823
+ const request = await this.jsonRequest<UriSuggestion[]>("/api/v1/suggestConceptClasses", params);
824
+ return request?.data;
825
+ }
826
+
827
+ /**
828
+ * return a concept uri that is the best match for the given concept label
829
+ * if there are multiple matches for the given conceptLabel,
830
+ * they are sorted based on their frequency of occurrence in news (most to least frequent)
831
+ * @param conceptLabel partial or full name of the concept for which to return the concept uri
832
+ * @param args Object which contains a host of optional parameters
833
+ */
834
+ public async getConceptUri(conceptLabel: string, args: ER.GetConceptUriArguments = {}) {
835
+ const { lang = "eng", sources = [ "concepts" ] } = args;
836
+ const matches = await this.suggestConcepts(conceptLabel, { lang, sources });
837
+ return firstMatchField(matches, "uri");
838
+ }
839
+
840
+ /**
841
+ * Return a location uri that is the best match for the given location label
842
+ * @param locationLabel partial or full location name for which to return the location uri
843
+ * @param args Object which contains a host of optional parameters
844
+ */
845
+ public async getLocationUri(locationLabel: string, args: ER.GetLocationUriArguments = {}) {
846
+ const { lang = "eng", sources = [ "place", "country" ], countryUri, sortByDistanceTo } = args;
847
+ const sourcesList = Array.isArray(sources) ? sources : [sources];
848
+ const matches = await this.suggestLocations(locationLabel, { lang, sources: sourcesList, countryUri, sortByDistanceTo });
849
+ return firstMatchField(matches, "wikiUri");
850
+ }
851
+
852
+ /**
853
+ * Return a category uri that is the best match for the given label
854
+ * @param categoryLabel partial or full name of the category for which to return category uri
855
+ */
856
+ public async getCategoryUri(categoryLabel: string) {
857
+ const matches = await this.suggestCategories(categoryLabel);
858
+ return firstMatchField(matches, "uri");
859
+ }
860
+
861
+ /**
862
+ * Return an event type uri that is the best match for the given label
863
+ * @param eventTypeLabel partial or full name of the event type for which to return the uri
864
+ */
865
+ public async getEventTypeUri(eventTypeLabel: string) {
866
+ const matches = await this.suggestEventTypes(eventTypeLabel);
867
+ return firstMatchField(matches, "uri");
868
+ }
869
+
870
+ /**
871
+ * Return the news source that best matches the source name
872
+ * @param sourceName partial or full name of the source or source uri for which to return source uri
873
+ * @param dataType: return the source uri that provides content of these data types
874
+ */
875
+ public async getNewsSourceUri(sourceName: string, dataType: ER.DataType[] | ER.DataType = ["news", "pr", "blog"]) {
876
+ const matches = await this.suggestNewsSources(sourceName, { dataType });
877
+ return firstMatchField(matches, "uri");
878
+ }
879
+
880
+ /**
881
+ * alternative (shorter) name for the method getNewsSourceUri()
882
+ */
883
+ public async getSourceUri(sourceName: string, dataType: ER.DataType[] | ER.DataType = ["news", "pr", "blog"]) {
884
+ return await this.getNewsSourceUri(sourceName, dataType);
885
+ }
886
+
887
+ /**
888
+ * Return the URI of the source group that best matches the name
889
+ * @param sourceGroupName partial or full name of the source group
890
+ */
891
+ public async getSourceGroupUri(sourceGroupName: string) {
892
+ const matches = await this.suggestSourceGroups(sourceGroupName);
893
+ return firstMatchField(matches, "uri");
894
+ }
895
+
896
+ /**
897
+ * Return a uri of the concept class that is the best match for the given label
898
+ * @param classLabel partial or full name of the concept class for which to return class uri
899
+ * @param lang language in which the class label is specified
900
+ */
901
+ public async getConceptClassUri(classLabel: string, lang = "eng") {
902
+ const matches = await this.suggestConceptClasses(classLabel, {lang});
903
+ return firstMatchField(matches, "uri");
904
+ }
905
+
906
+ /**
907
+ * Return detailed information about a particular concept
908
+ * @param conceptUri uri of the concept
909
+ * @param returnInfo what details about the concept should be included in the returned information
910
+ */
911
+ public async getConceptInfo(conceptUri: string, returnInfo?: ReturnInfo) {
912
+ if (!returnInfo) {
913
+ const conceptInfo = new ConceptInfoFlags({ synonyms: true, image: true, description: true });
914
+ returnInfo = new ReturnInfo({ conceptInfo });
915
+ }
916
+ let params = {
917
+ uri: conceptUri,
918
+ action: "getInfo"
919
+ };
920
+ params = {...params, ...(returnInfo?.getParams() ?? {})};
921
+ const request = await this.jsonRequest("/api/v1/concept/getInfo", params);
922
+ return request.data;
923
+ }
924
+
925
+ /**
926
+ * return author uri that is the best match for the given author name (and potentially source url)
927
+ * if there are multiple matches for the given author name, they are sorted based on the number of articles they have written (from most to least frequent)
928
+ * @param authorName: partial or full name of the author, potentially also containing the source url (e.g. "george brown nytimes")
929
+ */
930
+ public async getAuthorUri(authorName: string) {
931
+ const matches = await this.suggestAuthors(authorName);
932
+ return firstMatchField(matches, "uri");
933
+ }
934
+
935
+ public static getUriFromUriWgt(uriWgtList: string[]) {
936
+ if (!Array.isArray(uriWgtList)) {
937
+ throw new Error("uriWgtList has to be a list of strings that represent article uris");
938
+ }
939
+ return uriWgtList.map((uriWgt) => uriWgt.split(":")[0]);
940
+ }
941
+
942
+ // Additional utility functions
943
+
944
+ /**
945
+ * If you have article urls and you want to query them in ER you first have to obtain their uris in the ER.
946
+ * @param articleUrls a single article url or a list of article urls
947
+ */
948
+ public async getArticleUris(articleUrls: string | string[]) {
949
+ if (!Array.isArray(articleUrls) && typeof articleUrls !== "string") {
950
+ throw new Error("Expected a single article url or a list of urls");
951
+ }
952
+ const request = await this.jsonRequest<Record<string, unknown>>("/api/v1/articleMapper", { articleUrl: articleUrls});
953
+ return request.data;
954
+ }
955
+
956
+ /**
957
+ * Return information about the latest imported article
958
+ */
959
+ public async getSourceGroups() {
960
+ const request = await this.jsonRequest("/api/v1/sourceGroup/getSourceGroups", { action: "getSourceGroups"});
961
+ return request.data;
962
+ }
963
+
964
+ /**
965
+ * Return info about the source group
966
+ */
967
+ public async getSourceGroup(sourceGroupUri: string) {
968
+ const request = await this.jsonRequest("/api/v1/sourceGroup/getSourceGroupInfo", { action: "getSourceGroupInfo", uri: sourceGroupUri});
969
+ return request.data;
970
+ }
971
+ }
972
+
973
+ /**
974
+ * @class ArticleMapper
975
+ * Create instance of article mapper it will map from article urls to article uris
976
+ * the mappings can be remembered so it will not repeat requests for the same article urls
977
+ */
978
+ export class ArticleMapper {
979
+ private er: EventRegistry;
980
+ private articleUrlToUri: Record<string, unknown> = {};
981
+ private rememberMappings = true;
982
+
983
+ constructor(er: EventRegistry, rememberMapping = true) {
984
+ this.er = er;
985
+ this.rememberMappings = rememberMapping;
986
+ }
987
+
988
+ /**
989
+ * Given the article url, return an array with 0, 1 or more article uris.
990
+ * Not all returned article uris are necessarily valid anymore.
991
+ * For news sources of lower importance we remove the duplicated articles and just keep the latest content
992
+ * @param articleUrl string containing the article url
993
+ */
994
+ public async getArticleUri(articleUrl: string) {
995
+ if (this.articleUrlToUri.hasOwnProperty(articleUrl)) {
996
+ return this.articleUrlToUri[articleUrl];
997
+ }
998
+ const response = await this.er.getArticleUris(articleUrl);
999
+ const value = response?.[articleUrl];
1000
+ if (this.rememberMappings && value) {
1001
+ this.articleUrlToUri = { ...this.articleUrlToUri, [articleUrl]: value };
1002
+ }
1003
+ return value;
1004
+ }
1005
+ }