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