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