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