eventregistry 8.11.1 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/analytics.d.ts +82 -82
  2. package/dist/analytics.js +336 -330
  3. package/dist/analytics.js.map +1 -1
  4. package/dist/base.d.ts +82 -81
  5. package/dist/base.js +261 -219
  6. package/dist/base.js.map +1 -1
  7. package/dist/counts.d.ts +81 -81
  8. package/dist/counts.js +162 -149
  9. package/dist/counts.js.map +1 -1
  10. package/dist/dailyShares.d.ts +10 -10
  11. package/dist/dailyShares.js +90 -77
  12. package/dist/dailyShares.js.map +1 -1
  13. package/dist/data.d.ts +269 -268
  14. package/dist/data.js +3 -3
  15. package/dist/eventForText.d.ts +48 -48
  16. package/dist/eventForText.js +126 -123
  17. package/dist/eventForText.js.map +1 -1
  18. package/dist/eventRegistry.d.ts +244 -224
  19. package/dist/eventRegistry.js +1098 -1018
  20. package/dist/eventRegistry.js.map +1 -1
  21. package/dist/index.d.ts +21 -20
  22. package/dist/index.js +128 -122
  23. package/dist/index.js.map +1 -1
  24. package/dist/info.d.ts +61 -61
  25. package/dist/info.js +171 -158
  26. package/dist/info.js.map +1 -1
  27. package/dist/logger.d.ts +44 -0
  28. package/dist/logger.js +144 -0
  29. package/dist/logger.js.map +1 -0
  30. package/dist/query.d.ts +53 -53
  31. package/dist/query.js +333 -290
  32. package/dist/query.js.map +1 -1
  33. package/dist/queryArticle.d.ts +61 -61
  34. package/dist/queryArticle.js +183 -168
  35. package/dist/queryArticle.js.map +1 -1
  36. package/dist/queryArticles.d.ts +144 -160
  37. package/dist/queryArticles.js +729 -701
  38. package/dist/queryArticles.js.map +1 -1
  39. package/dist/queryEvent.d.ts +140 -140
  40. package/dist/queryEvent.js +587 -569
  41. package/dist/queryEvent.js.map +1 -1
  42. package/dist/queryEvents.d.ts +210 -210
  43. package/dist/queryEvents.js +825 -798
  44. package/dist/queryEvents.js.map +1 -1
  45. package/dist/queryMentions.d.ts +96 -96
  46. package/dist/queryMentions.js +637 -600
  47. package/dist/queryMentions.js.map +1 -1
  48. package/dist/queryStory.d.ts +58 -58
  49. package/dist/queryStory.js +194 -174
  50. package/dist/queryStory.js.map +1 -1
  51. package/dist/recent.d.ts +23 -23
  52. package/dist/recent.js +199 -179
  53. package/dist/recent.js.map +1 -1
  54. package/dist/returnInfo.d.ts +68 -66
  55. package/dist/returnInfo.js +332 -304
  56. package/dist/returnInfo.js.map +1 -1
  57. package/dist/topicPage.d.ts +157 -157
  58. package/dist/topicPage.js +599 -604
  59. package/dist/topicPage.js.map +1 -1
  60. package/dist/trends.d.ts +35 -35
  61. package/dist/trends.js +115 -102
  62. package/dist/trends.js.map +1 -1
  63. package/dist/types.d.ts +2453 -2155
  64. package/dist/types.js +2 -2
  65. package/package.json +13 -13
package/dist/topicPage.js CHANGED
@@ -1,605 +1,600 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- }
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- var __assign = (this && this.__assign) || function () {
16
- __assign = Object.assign || function(t) {
17
- for (var s, i = 1, n = arguments.length; i < n; i++) {
18
- s = arguments[i];
19
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
- t[p] = s[p];
21
- }
22
- return t;
23
- };
24
- return __assign.apply(this, arguments);
25
- };
26
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (_) try {
41
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
- var __rest = (this && this.__rest) || function (s, e) {
62
- var t = {};
63
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
64
- t[p] = s[p];
65
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
66
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
67
- t[p[i]] = s[p[i]];
68
- return t;
69
- };
70
- var __read = (this && this.__read) || function (o, n) {
71
- var m = typeof Symbol === "function" && o[Symbol.iterator];
72
- if (!m) return o;
73
- var i = m.call(o), r, ar = [], e;
74
- try {
75
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
76
- }
77
- catch (error) { e = { error: error }; }
78
- finally {
79
- try {
80
- if (r && !r.done && (m = i["return"])) m.call(i);
81
- }
82
- finally { if (e) throw e.error; }
83
- }
84
- return ar;
85
- };
86
- var __spread = (this && this.__spread) || function () {
87
- for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
88
- return ar;
89
- };
90
- Object.defineProperty(exports, "__esModule", { value: true });
91
- var fs = require("fs");
92
- var _ = require("lodash");
93
- var base_1 = require("./base");
94
- var returnInfo_1 = require("./returnInfo");
95
- var TopicPage = /** @class */ (function (_super) {
96
- __extends(TopicPage, _super);
97
- function TopicPage(eventRegistry) {
98
- var _this = _super.call(this) || this;
99
- _this.eventRegistry = eventRegistry;
100
- _this.emptyTopicPage = {
101
- autoAddArticles: true,
102
- articleHasDuplicate: "keepAll",
103
- articleHasEvent: "keepAll",
104
- articleIsDuplicate: "skipDuplicates",
105
- maxDaysBack: 7,
106
- articleTreshWgt: 0,
107
- eventTreshWgt: 0,
108
- concepts: [],
109
- keywords: [],
110
- categories: [],
111
- sources: [],
112
- sourceGroups: [],
113
- sourceLocations: [],
114
- locations: [],
115
- langs: [],
116
- restrictToSetConcepts: false,
117
- restrictToSetCategories: false,
118
- restrictToSetSources: false,
119
- restrictToSetLocations: false,
120
- dataType: ["news"]
121
- };
122
- _this.concept = {};
123
- _this.topicPage = _this.createEmptyTopicPage();
124
- return _this;
125
- }
126
- TopicPage.prototype.isTopicPage = function (definition) {
127
- return _.isEqual(_.keys(this.emptyTopicPage), _.keys(definition));
128
- };
129
- TopicPage.prototype.createEmptyTopicPage = function () {
130
- return this.emptyTopicPage;
131
- };
132
- /**
133
- * Load an existing topic page from Event Registry based on the topic page URI
134
- * @param uri uri of the topic page saved in your Event Registry account
135
- */
136
- TopicPage.prototype.loadTopicPageFromER = function (uri) {
137
- return __awaiter(this, void 0, void 0, function () {
138
- var params, _a;
139
- return __generator(this, function (_b) {
140
- switch (_b.label) {
141
- case 0:
142
- params = {
143
- action: "getTopicPageJson",
144
- includeConceptDescription: true,
145
- includeConceptImage: true,
146
- includeTopicPageDefinition: true,
147
- includeTopicPageOwner: true,
148
- uri: uri
149
- };
150
- this.topicPage = this.createEmptyTopicPage();
151
- _a = this;
152
- return [4 /*yield*/, this.eventRegistry.jsonRequest("/api/v1/topicPage", params)];
153
- case 1:
154
- _a.concept = _b.sent();
155
- if (_.has(this.concept, "data.error")) {
156
- throw new Error(_.get(this.concept, "data.error", ""));
157
- }
158
- this.topicPage = _.extend({}, this.topicPage, _.get(this.concept, "data.topicPage", {}));
159
- return [2 /*return*/, this.topicPage];
160
- }
161
- });
162
- });
163
- };
164
- /**
165
- * Load the topic page definition from an object
166
- * @param definition topic page definition
167
- */
168
- TopicPage.prototype.loadTopicPageFromDefinition = function (definition) {
169
- if (this.isTopicPage(definition)) {
170
- this.topicPage = definition;
171
- }
172
- };
173
- /**
174
- * Load topic page from an existing file
175
- * @param filepath file that contains the topic page definition
176
- */
177
- TopicPage.prototype.loadTopicPageFromFile = function (filepath) {
178
- if (fs && fs.existsSync(filepath)) {
179
- var definition = JSON.parse(fs.readFileSync(filepath, "utf8"));
180
- if (this.isTopicPage(definition)) {
181
- this.topicPage = definition;
182
- }
183
- }
184
- };
185
- /**
186
- * Return an object containing the topic page definition. you can use it to load a topic page later
187
- */
188
- TopicPage.prototype.saveTopicPageDefinition = function () {
189
- return this.topicPage;
190
- };
191
- /**
192
- * Save the topic page definition to a file
193
- * @param filepath location of the file to which you'll save the topic page definition
194
- */
195
- TopicPage.prototype.saveTopicPageDefinitionToFile = function (filepath) {
196
- fs.writeFileSync(filepath, JSON.stringify(this.topicPage, null, 4), "utf8");
197
- };
198
- Object.defineProperty(TopicPage.prototype, "articleThreshold", {
199
- /**
200
- * What is the minimum total weight that an article has to have in order to get it among the results?
201
- */
202
- set: function (value) {
203
- if (_.isNumber(value) && value >= 0) {
204
- this.topicPage.articleTreshWgt = value;
205
- }
206
- },
207
- enumerable: true,
208
- configurable: true
209
- });
210
- Object.defineProperty(TopicPage.prototype, "eventThreshold", {
211
- /**
212
- * What is the minimum total weight that an event has to have in order to get it among the results?
213
- */
214
- set: function (value) {
215
- if (_.isNumber(value) && value >= 0) {
216
- this.topicPage.eventTreshWgt = value;
217
- }
218
- },
219
- enumerable: true,
220
- configurable: true
221
- });
222
- Object.defineProperty(TopicPage.prototype, "articleIsDuplicateFilter", {
223
- /**
224
- * Some articles can be duplicates of other articles. What should be done with them. Possible values are:
225
- * "skipDuplicates" (skip the resulting articles that are duplicates of other articles),
226
- * "keepOnlyDuplicates" (return only the duplicate articles) and
227
- * "keepAll" (no filtering, default)
228
- */
229
- set: function (value) {
230
- if (value === "skipDuplicates" || value === "keepOnlyDuplicates" || value === "keepAll") {
231
- this.topicPage.articleIsDuplicate = value;
232
- }
233
- },
234
- enumerable: true,
235
- configurable: true
236
- });
237
- Object.defineProperty(TopicPage.prototype, "articleHasEventFilter", {
238
- /**
239
- * Some articles describe a known event and some don't. This filter allows you to filter the resulting articles based on this criteria.
240
- * Possible values are:
241
- * "skipArticlesWithoutEvent" (skip articles that are not describing any known event in ER),
242
- * "keepOnlyArticlesWithoutEvent" (return only the articles that are not describing any known event in ER) and
243
- * "keepAll" (no filtering, default)
244
- */
245
- set: function (value) {
246
- if (value === "skipArticlesWithoutEvent" || value === "keepOnlyArticlesWithoutEvent" || value === "keepAll") {
247
- this.topicPage.articleHasEvent = value;
248
- }
249
- },
250
- enumerable: true,
251
- configurable: true
252
- });
253
- Object.defineProperty(TopicPage.prototype, "articleHasDuplicateFilter", {
254
- /**
255
- * Some articles are later copied by others. What should be done with such articles. Possible values are:
256
- * "skipHasDuplicates" (skip the articles that have been later copied by others),
257
- * "keepOnlyHasDuplicates" (return only the articles that have been later copied by others) and
258
- * "keepAll" (no filtering, default)
259
- */
260
- set: function (value) {
261
- if (value === "skipHasDuplicates" || value === "keepOnlyHasDuplicates" || value === "keepAll") {
262
- this.topicPage.articleHasDuplicate = value;
263
- }
264
- },
265
- enumerable: true,
266
- configurable: true
267
- });
268
- Object.defineProperty(TopicPage.prototype, "dataTypes", {
269
- /**
270
- * What data types should we search? "news" (news content, default), "pr" (press releases), or "blog".
271
- * If you want to use multiple data types, put them in an array (e.g. ["news", "pr"])
272
- */
273
- set: function (dataTypes) {
274
- this.topicPage.dataType = dataTypes;
275
- },
276
- enumerable: true,
277
- configurable: true
278
- });
279
- Object.defineProperty(TopicPage.prototype, "sourceRankStartPercentile", {
280
- set: function (startPercentile) {
281
- if (_.isUndefined(startPercentile)) {
282
- startPercentile = 0;
283
- }
284
- if (startPercentile < 0 || startPercentile > 90) {
285
- throw new RangeError("startPercentile is out of valid values (0 - 90)");
286
- }
287
- if (!_.isNil(this.topicPage.endSourceRankPercentile) && _.isNumber(this.topicPage.endSourceRankPercentile) && startPercentile >= this.topicPage.endSourceRankPercentile) {
288
- throw new RangeError("startPercentile has to be smaller than endPercentile");
289
- }
290
- if (startPercentile % 10 !== 0) {
291
- throw new Error("startPecentile has to be a multiple of 10");
292
- }
293
- this.topicPage.startSourceRankPercentile = startPercentile;
294
- },
295
- enumerable: true,
296
- configurable: true
297
- });
298
- Object.defineProperty(TopicPage.prototype, "sourceRankEndPercentile", {
299
- set: function (endPercentile) {
300
- if (_.isUndefined(endPercentile)) {
301
- endPercentile = 100;
302
- }
303
- if (endPercentile < 10 || endPercentile > 100) {
304
- throw new RangeError("endPercentile is out of valid values (10 - 100)");
305
- }
306
- if (!_.isNil(this.topicPage.startSourceRankPercentile) && _.isNumber(this.topicPage.startSourceRankPercentile) && this.topicPage.startSourceRankPercentile >= endPercentile) {
307
- throw new RangeError("startPercentile has to be smaller than endPercentile");
308
- }
309
- if (endPercentile % 10 !== 0) {
310
- throw new Error("endPercentile has to be a multiple of 10");
311
- }
312
- this.topicPage.endSourceRankPercentile = endPercentile;
313
- },
314
- enumerable: true,
315
- configurable: true
316
- });
317
- Object.defineProperty(TopicPage.prototype, "maxDaysBack", {
318
- /**
319
- * What is the maximum allowed age of the results?
320
- */
321
- set: function (maxDaysBack) {
322
- if (!_.isNumber(maxDaysBack)) {
323
- throw new Error("maxDaysBack value has to be a positive number");
324
- }
325
- if (maxDaysBack <= 0) {
326
- throw new RangeError("maxDaysBack value has to be a positive number");
327
- }
328
- this.topicPage.maxDaysBack = maxDaysBack;
329
- },
330
- enumerable: true,
331
- configurable: true
332
- });
333
- TopicPage.prototype.clearConcepts = function () {
334
- this.topicPage.concepts = [];
335
- };
336
- TopicPage.prototype.clearKeywords = function () {
337
- this.topicPage.keywords = [];
338
- };
339
- TopicPage.prototype.clearCategories = function () {
340
- this.topicPage.categories = [];
341
- };
342
- TopicPage.prototype.clearSources = function () {
343
- this.topicPage.sources = [];
344
- };
345
- TopicPage.prototype.clearSourceLocations = function () {
346
- this.topicPage.sourceLocations = [];
347
- };
348
- TopicPage.prototype.clearSourceGroups = function () {
349
- this.topicPage.sourceGroups = [];
350
- };
351
- TopicPage.prototype.clearLocations = function () {
352
- this.topicPage.locations = [];
353
- };
354
- /**
355
- * Add a relevant concept to the topic page
356
- * @param uri uri of the concept to be added
357
- * @param weight importance of the provided concept (typically in range 1 - 50)
358
- */
359
- TopicPage.prototype.addConcept = function (uri, wgt, args) {
360
- if (args === void 0) { args = {}; }
361
- if (!_.isNumber(wgt)) {
362
- throw new Error("Weight value has to be a positive or negative number");
363
- }
364
- var label = args.label, conceptType = args.conceptType, _a = args.required, required = _a === void 0 ? false : _a, _b = args.excluded, excluded = _b === void 0 ? false : _b;
365
- if (required && excluded) {
366
- throw new Error("Parameters required and excluded can not be true at the same time");
367
- }
368
- var concept = { uri: uri, wgt: wgt, required: required, excluded: excluded };
369
- if (!_.isUndefined(label)) {
370
- _.set(concept, "label", label);
371
- }
372
- if (!_.isUndefined(conceptType)) {
373
- _.set(concept, "type", conceptType);
374
- }
375
- this.topicPage.concepts = __spread(this.topicPage.concepts, [concept]);
376
- };
377
- /**
378
- * Add a relevant keyword to the topic page
379
- * @param keyword keyword or phrase to be added
380
- * @param weight importance of the provided keyword (typically in range 1 - 50)
381
- */
382
- TopicPage.prototype.addKeyword = function (keyword, wgt, args) {
383
- if (args === void 0) { args = {}; }
384
- if (!_.isNumber(wgt)) {
385
- throw new Error("Weight value has to be a positive or negative number");
386
- }
387
- var _a = args.required, required = _a === void 0 ? false : _a, _b = args.excluded, excluded = _b === void 0 ? false : _b;
388
- this.topicPage.keywords = __spread(this.topicPage.keywords, [{ keyword: keyword, wgt: wgt, required: required, excluded: excluded }]);
389
- };
390
- /**
391
- * Add a relevant category to the topic page
392
- * @param uri uri of the category to be added
393
- * @param weight importance of the provided category (typically in range 1 - 50)
394
- */
395
- TopicPage.prototype.addCategory = function (uri, wgt, args) {
396
- if (args === void 0) { args = {}; }
397
- if (!_.isNumber(wgt)) {
398
- throw new Error("Weight value has to be a positive or negative number");
399
- }
400
- var _a = args.required, required = _a === void 0 ? false : _a, _b = args.excluded, excluded = _b === void 0 ? false : _b;
401
- this.topicPage.categories = __spread(this.topicPage.categories, [{ uri: uri, wgt: wgt, required: required, excluded: excluded }]);
402
- };
403
- /**
404
- * Add a news source to the topic page
405
- * @param uri uri of the news source to add to the topic page
406
- * @param weight importance of the news source (typically in range 1 - 50)
407
- */
408
- TopicPage.prototype.addSource = function (uri, wgt, args) {
409
- if (args === void 0) { args = {}; }
410
- if (!_.isNumber(wgt)) {
411
- throw new Error("Weight value has to be a positive or negative number");
412
- }
413
- var _a = args.excluded, excluded = _a === void 0 ? false : _a;
414
- this.topicPage.sources = __spread(this.topicPage.sources, [{ uri: uri, wgt: wgt, excluded: excluded }]);
415
- };
416
- /**
417
- * Add a list of relevant sources by identifying them by their geographic location
418
- * @param uri uri of the location where the sources should be geographically located
419
- * @param weight importance of the provided list of sources (typically in range 1 - 50)
420
- */
421
- TopicPage.prototype.addSourceLocation = function (uri, wgt, args) {
422
- if (args === void 0) { args = {}; }
423
- if (!_.isNumber(wgt)) {
424
- throw new Error("Weight value has to be a positive or negative number");
425
- }
426
- var _a = args.excluded, excluded = _a === void 0 ? false : _a;
427
- this.topicPage.sourceLocations = __spread(this.topicPage.sourceLocations, [{ uri: uri, wgt: wgt, excluded: excluded }]);
428
- };
429
- /**
430
- * Add a list of relevant sources by specifying a whole source group to the topic page
431
- * @param sourceGroupUri uri of the source group to add
432
- * @param weight importance of the provided list of sources (typically in range 1 - 50)
433
- */
434
- TopicPage.prototype.addSourceGroup = function (uri, wgt, args) {
435
- if (args === void 0) { args = {}; }
436
- if (!_.isNumber(wgt)) {
437
- throw new Error("Weight value has to be a positive or negative number");
438
- }
439
- var _a = args.excluded, excluded = _a === void 0 ? false : _a;
440
- this.topicPage.sourceGroups = __spread(this.topicPage.sourceGroups, [{ uri: uri, wgt: wgt, excluded: excluded }]);
441
- };
442
- /**
443
- * Add relevant location to the topic page
444
- * @param locationUri uri of the location to add
445
- * @param weight importance of the provided location (typically in range 1 - 50)
446
- */
447
- TopicPage.prototype.addLocation = function (locationUri, weight) {
448
- if (!_.isNumber(weight)) {
449
- throw new Error("Weight value has to be a positive or negative number");
450
- }
451
- this.topicPage.locations = __spread(this.topicPage.locations, [{ uri: locationUri, wgt: weight }]);
452
- };
453
- Object.defineProperty(TopicPage.prototype, "languages", {
454
- /**
455
- * Restrict the results to the list of specified languages
456
- */
457
- set: function (languages) {
458
- if (!_.isArray(languages)) {
459
- languages = [languages];
460
- }
461
- if (_.every(languages, function (language) { return _.size(language) === 3; })) {
462
- this.topicPage.langs = languages;
463
- }
464
- else {
465
- throw new Error("Expected to get language in ISO3 code");
466
- }
467
- },
468
- enumerable: true,
469
- configurable: true
470
- });
471
- Object.defineProperty(TopicPage.prototype, "restrictToSetConceptsAndKeywords", {
472
- /**
473
- * if true then the results have to mention at least one of the specified concepts or keywords
474
- */
475
- set: function (restrict) {
476
- if (!_.isBoolean(restrict)) {
477
- throw new Error("Restrict value has to be a boolean value");
478
- }
479
- this.topicPage.restrictToSetConcepts = restrict;
480
- },
481
- enumerable: true,
482
- configurable: true
483
- });
484
- Object.defineProperty(TopicPage.prototype, "restrictToSetCategories", {
485
- /**
486
- * if set to true then return only results that are assigned to one of the specified categories
487
- */
488
- set: function (restrict) {
489
- if (!_.isBoolean(restrict)) {
490
- throw new Error("Restrict value has to be a boolean value");
491
- }
492
- this.topicPage.restrictToSetCategories = restrict;
493
- },
494
- enumerable: true,
495
- configurable: true
496
- });
497
- Object.defineProperty(TopicPage.prototype, "restrictToSetSources", {
498
- /**
499
- * if set to true then return only results from one of the specified news sources
500
- * this includes also sources set by source groups or by source locations
501
- */
502
- set: function (restrict) {
503
- if (!_.isBoolean(restrict)) {
504
- throw new Error("Restrict value has to be a boolean value");
505
- }
506
- this.topicPage.restrictToSetSources = restrict;
507
- },
508
- enumerable: true,
509
- configurable: true
510
- });
511
- Object.defineProperty(TopicPage.prototype, "restrictToSetLocations", {
512
- /**
513
- * if set to true, then return only results that are located at one of the specified locations
514
- */
515
- set: function (restrict) {
516
- if (!_.isBoolean(restrict)) {
517
- throw new Error("Restrict value has to be a boolean value");
518
- }
519
- this.topicPage.restrictToSetLocations = restrict;
520
- },
521
- enumerable: true,
522
- configurable: true
523
- });
524
- /**
525
- * Return a list of articles that match the topic page
526
- * @param args {EventRegistryStatic.TopicPageArticles} Object which contains a host of optional parameters
527
- */
528
- TopicPage.prototype.getArticles = function (args) {
529
- if (args === void 0) { args = {}; }
530
- return __awaiter(this, void 0, void 0, function () {
531
- var _a, page, _b, count, _c, sortBy, _d, sortByAsc, _e, dataType, _f, returnInfo, otherParameters, params, request;
532
- return __generator(this, function (_g) {
533
- switch (_g.label) {
534
- case 0:
535
- _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 100 : _b, _c = args.sortBy, sortBy = _c === void 0 ? "rel" : _c, _d = args.sortByAsc, sortByAsc = _d === void 0 ? false : _d, _e = args.dataType, dataType = _e === void 0 ? "news" : _e, _f = args.returnInfo, returnInfo = _f === void 0 ? new returnInfo_1.ReturnInfo() : _f, otherParameters = __rest(args, ["page", "count", "sortBy", "sortByAsc", "dataType", "returnInfo"]);
536
- if (page < 1) {
537
- throw new RangeError("page has to be >= 1");
538
- }
539
- if (count > 100) {
540
- throw new RangeError("At most 100 articles can be returned at a time");
541
- }
542
- params = _.extend({}, {
543
- action: "getArticlesForTopicPage",
544
- resultType: "articles",
545
- dataType: this.topicPage.dataType,
546
- articlesCount: count,
547
- articlesSortBy: sortBy,
548
- articlesSortByAsc: sortByAsc,
549
- articlesPage: page,
550
- topicPage: JSON.stringify(this.topicPage),
551
- }, returnInfo.getParams());
552
- if (!_.isEmpty(otherParameters)) {
553
- params = __assign({}, params, otherParameters);
554
- }
555
- return [4 /*yield*/, this.eventRegistry.jsonRequest("/api/v1/article", params)];
556
- case 1:
557
- request = _g.sent();
558
- return [2 /*return*/, _.get(request, "data", { articles: { results: [] } })];
559
- }
560
- });
561
- });
562
- };
563
- /**
564
- * Return a list of events that match the topic page
565
- * @param args {EventRegistryStatic.TopicPageEvents} Object which contains a host of optional parameters
566
- */
567
- TopicPage.prototype.getEvents = function (args) {
568
- if (args === void 0) { args = {}; }
569
- return __awaiter(this, void 0, void 0, function () {
570
- var _a, page, _b, count, _c, sortBy, _d, sortByAsc, _e, returnInfo, otherParameters, params, request;
571
- return __generator(this, function (_f) {
572
- switch (_f.label) {
573
- case 0:
574
- _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 50 : _b, _c = args.sortBy, sortBy = _c === void 0 ? "rel" : _c, _d = args.sortByAsc, sortByAsc = _d === void 0 ? false : _d, _e = args.returnInfo, returnInfo = _e === void 0 ? new returnInfo_1.ReturnInfo() : _e, otherParameters = __rest(args, ["page", "count", "sortBy", "sortByAsc", "returnInfo"]);
575
- if (page < 1) {
576
- throw new RangeError("page has to be >= 1");
577
- }
578
- if (count > 50) {
579
- throw new RangeError("At most 50 events can be returned at a time");
580
- }
581
- params = _.extend({}, {
582
- action: "getEventsForTopicPage",
583
- resultType: "events",
584
- dataType: this.topicPage.dataType,
585
- eventsCount: count,
586
- eventsSortBy: sortBy,
587
- eventsSortByAsc: sortByAsc,
588
- eventsPage: page,
589
- topicPage: JSON.stringify(this.topicPage),
590
- }, returnInfo.getParams());
591
- if (!_.isEmpty(otherParameters)) {
592
- params = __assign({}, params, otherParameters);
593
- }
594
- return [4 /*yield*/, this.eventRegistry.jsonRequest("/api/v1/event", params)];
595
- case 1:
596
- request = _f.sent();
597
- return [2 /*return*/, _.get(request, "data", { events: { results: [] } })];
598
- }
599
- });
600
- });
601
- };
602
- return TopicPage;
603
- }(base_1.QueryParamsBase));
604
- exports.TopicPage = TopicPage;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ var __rest = (this && this.__rest) || function (s, e) {
65
+ var t = {};
66
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
67
+ t[p] = s[p];
68
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
69
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
70
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
71
+ t[p[i]] = s[p[i]];
72
+ }
73
+ return t;
74
+ };
75
+ var __read = (this && this.__read) || function (o, n) {
76
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
77
+ if (!m) return o;
78
+ var i = m.call(o), r, ar = [], e;
79
+ try {
80
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
81
+ }
82
+ catch (error) { e = { error: error }; }
83
+ finally {
84
+ try {
85
+ if (r && !r.done && (m = i["return"])) m.call(i);
86
+ }
87
+ finally { if (e) throw e.error; }
88
+ }
89
+ return ar;
90
+ };
91
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
92
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
93
+ if (ar || !(i in from)) {
94
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
95
+ ar[i] = from[i];
96
+ }
97
+ }
98
+ return to.concat(ar || Array.prototype.slice.call(from));
99
+ };
100
+ Object.defineProperty(exports, "__esModule", { value: true });
101
+ exports.TopicPage = void 0;
102
+ var fs = require("fs");
103
+ var base_1 = require("./base");
104
+ var returnInfo_1 = require("./returnInfo");
105
+ var TopicPage = /** @class */ (function (_super) {
106
+ __extends(TopicPage, _super);
107
+ function TopicPage(eventRegistry) {
108
+ var _this = _super.call(this) || this;
109
+ _this.eventRegistry = eventRegistry;
110
+ _this.emptyTopicPage = {
111
+ autoAddArticles: true,
112
+ articleHasDuplicate: "keepAll",
113
+ articleHasEvent: "keepAll",
114
+ articleIsDuplicate: "skipDuplicates",
115
+ maxDaysBack: 7,
116
+ articleTreshWgt: 0,
117
+ eventTreshWgt: 0,
118
+ concepts: [],
119
+ keywords: [],
120
+ categories: [],
121
+ sources: [],
122
+ sourceGroups: [],
123
+ sourceLocations: [],
124
+ locations: [],
125
+ langs: [],
126
+ restrictToSetConcepts: false,
127
+ restrictToSetCategories: false,
128
+ restrictToSetSources: false,
129
+ restrictToSetLocations: false,
130
+ dataType: ["news"]
131
+ };
132
+ _this.concept = {};
133
+ _this.topicPage = _this.createEmptyTopicPage();
134
+ return _this;
135
+ }
136
+ TopicPage.prototype.isTopicPage = function (definition) {
137
+ return Object.keys(this.emptyTopicPage).sort().toString() === Object.keys(definition).sort().toString();
138
+ };
139
+ TopicPage.prototype.createEmptyTopicPage = function () {
140
+ return this.emptyTopicPage;
141
+ };
142
+ /**
143
+ * Load an existing topic page from Event Registry based on the topic page URI
144
+ * @param uri uri of the topic page saved in your Event Registry account
145
+ */
146
+ TopicPage.prototype.loadTopicPageFromER = function (uri) {
147
+ return __awaiter(this, void 0, void 0, function () {
148
+ var params, _a;
149
+ var _b, _c, _d;
150
+ return __generator(this, function (_e) {
151
+ switch (_e.label) {
152
+ case 0:
153
+ params = {
154
+ action: "getTopicPageJson",
155
+ includeConceptDescription: true,
156
+ includeConceptImage: true,
157
+ includeTopicPageDefinition: true,
158
+ includeTopicPageOwner: true,
159
+ uri: uri
160
+ };
161
+ this.topicPage = this.createEmptyTopicPage();
162
+ _a = this;
163
+ return [4 /*yield*/, this.eventRegistry.jsonRequest("/api/v1/topicPage", params)];
164
+ case 1:
165
+ _a.concept = _e.sent();
166
+ if ((_c = (_b = this.concept) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) {
167
+ throw new Error(this.concept.data.error || "");
168
+ }
169
+ this.topicPage = __assign(__assign({}, this.topicPage), (((_d = this.concept.data) === null || _d === void 0 ? void 0 : _d.topicPage) || {}));
170
+ return [2 /*return*/, this.topicPage];
171
+ }
172
+ });
173
+ });
174
+ };
175
+ /**
176
+ * Load the topic page definition from an object
177
+ * @param definition topic page definition
178
+ */
179
+ TopicPage.prototype.loadTopicPageFromDefinition = function (definition) {
180
+ if (this.isTopicPage(definition)) {
181
+ this.topicPage = definition;
182
+ }
183
+ };
184
+ /**
185
+ * Load topic page from an existing file
186
+ * @param filepath file that contains the topic page definition
187
+ */
188
+ TopicPage.prototype.loadTopicPageFromFile = function (filepath) {
189
+ if (fs && fs.existsSync(filepath)) {
190
+ var definition = JSON.parse(fs.readFileSync(filepath, "utf8"));
191
+ if (this.isTopicPage(definition)) {
192
+ this.topicPage = definition;
193
+ }
194
+ }
195
+ };
196
+ /**
197
+ * Return an object containing the topic page definition. you can use it to load a topic page later
198
+ */
199
+ TopicPage.prototype.saveTopicPageDefinition = function () {
200
+ return this.topicPage;
201
+ };
202
+ /**
203
+ * Save the topic page definition to a file
204
+ * @param filepath location of the file to which you'll save the topic page definition
205
+ */
206
+ TopicPage.prototype.saveTopicPageDefinitionToFile = function (filepath) {
207
+ fs.writeFileSync(filepath, JSON.stringify(this.topicPage, null, 4), "utf8");
208
+ };
209
+ Object.defineProperty(TopicPage.prototype, "articleThreshold", {
210
+ /**
211
+ * What is the minimum total weight that an article has to have in order to get it among the results?
212
+ */
213
+ set: function (value) {
214
+ if (typeof value === "number" && value >= 0) {
215
+ this.topicPage.articleTreshWgt = value;
216
+ }
217
+ },
218
+ enumerable: false,
219
+ configurable: true
220
+ });
221
+ Object.defineProperty(TopicPage.prototype, "eventThreshold", {
222
+ /**
223
+ * What is the minimum total weight that an event has to have in order to get it among the results?
224
+ */
225
+ set: function (value) {
226
+ if (typeof value === "number" && value >= 0) {
227
+ this.topicPage.eventTreshWgt = value;
228
+ }
229
+ },
230
+ enumerable: false,
231
+ configurable: true
232
+ });
233
+ Object.defineProperty(TopicPage.prototype, "articleIsDuplicateFilter", {
234
+ /**
235
+ * Some articles can be duplicates of other articles. What should be done with them. Possible values are:
236
+ * "skipDuplicates" (skip the resulting articles that are duplicates of other articles),
237
+ * "keepOnlyDuplicates" (return only the duplicate articles) and
238
+ * "keepAll" (no filtering, default)
239
+ */
240
+ set: function (value) {
241
+ if (value === "skipDuplicates" || value === "keepOnlyDuplicates" || value === "keepAll") {
242
+ this.topicPage.articleIsDuplicate = value;
243
+ }
244
+ },
245
+ enumerable: false,
246
+ configurable: true
247
+ });
248
+ Object.defineProperty(TopicPage.prototype, "articleHasEventFilter", {
249
+ /**
250
+ * Some articles describe a known event and some don't. This filter allows you to filter the resulting articles based on this criteria.
251
+ * Possible values are:
252
+ * "skipArticlesWithoutEvent" (skip articles that are not describing any known event in ER),
253
+ * "keepOnlyArticlesWithoutEvent" (return only the articles that are not describing any known event in ER) and
254
+ * "keepAll" (no filtering, default)
255
+ */
256
+ set: function (value) {
257
+ if (value === "skipArticlesWithoutEvent" || value === "keepOnlyArticlesWithoutEvent" || value === "keepAll") {
258
+ this.topicPage.articleHasEvent = value;
259
+ }
260
+ },
261
+ enumerable: false,
262
+ configurable: true
263
+ });
264
+ Object.defineProperty(TopicPage.prototype, "articleHasDuplicateFilter", {
265
+ /**
266
+ * Some articles are later copied by others. What should be done with such articles. Possible values are:
267
+ * "skipHasDuplicates" (skip the articles that have been later copied by others),
268
+ * "keepOnlyHasDuplicates" (return only the articles that have been later copied by others) and
269
+ * "keepAll" (no filtering, default)
270
+ */
271
+ set: function (value) {
272
+ if (value === "skipHasDuplicates" || value === "keepOnlyHasDuplicates" || value === "keepAll") {
273
+ this.topicPage.articleHasDuplicate = value;
274
+ }
275
+ },
276
+ enumerable: false,
277
+ configurable: true
278
+ });
279
+ Object.defineProperty(TopicPage.prototype, "dataTypes", {
280
+ /**
281
+ * What data types should we search? "news" (news content, default), "pr" (press releases), or "blog".
282
+ * If you want to use multiple data types, put them in an array (e.g. ["news", "pr"])
283
+ */
284
+ set: function (dataTypes) {
285
+ this.topicPage.dataType = dataTypes;
286
+ },
287
+ enumerable: false,
288
+ configurable: true
289
+ });
290
+ Object.defineProperty(TopicPage.prototype, "sourceRankStartPercentile", {
291
+ set: function (startPercentile) {
292
+ if (startPercentile === undefined) {
293
+ startPercentile = 0;
294
+ }
295
+ if (startPercentile < 0 || startPercentile > 90) {
296
+ throw new RangeError("startPercentile is out of valid values (0 - 90)");
297
+ }
298
+ if (this.topicPage.endSourceRankPercentile !== null && typeof this.topicPage.endSourceRankPercentile === "number" && startPercentile >= this.topicPage.endSourceRankPercentile) {
299
+ throw new RangeError("startPercentile has to be smaller than endPercentile");
300
+ }
301
+ if (startPercentile % 10 !== 0) {
302
+ throw new Error("startPecentile has to be a multiple of 10");
303
+ }
304
+ this.topicPage.startSourceRankPercentile = startPercentile;
305
+ },
306
+ enumerable: false,
307
+ configurable: true
308
+ });
309
+ Object.defineProperty(TopicPage.prototype, "sourceRankEndPercentile", {
310
+ set: function (endPercentile) {
311
+ if (endPercentile === undefined) {
312
+ endPercentile = 100;
313
+ }
314
+ if (endPercentile < 10 || endPercentile > 100) {
315
+ throw new RangeError("endPercentile is out of valid values (10 - 100)");
316
+ }
317
+ if (this.topicPage.startSourceRankPercentile !== null && typeof this.topicPage.startSourceRankPercentile === 'number' && this.topicPage.startSourceRankPercentile >= endPercentile) {
318
+ throw new RangeError("startPercentile has to be smaller than endPercentile");
319
+ }
320
+ if (endPercentile % 10 !== 0) {
321
+ throw new Error("endPercentile has to be a multiple of 10");
322
+ }
323
+ this.topicPage.endSourceRankPercentile = endPercentile;
324
+ },
325
+ enumerable: false,
326
+ configurable: true
327
+ });
328
+ Object.defineProperty(TopicPage.prototype, "maxDaysBack", {
329
+ /**
330
+ * What is the maximum allowed age of the results?
331
+ */
332
+ set: function (maxDaysBack) {
333
+ if (typeof maxDaysBack !== "number" || maxDaysBack < 0) {
334
+ throw new Error("maxDaysBack value has to be a positive number");
335
+ }
336
+ if (maxDaysBack <= 0) {
337
+ throw new RangeError("maxDaysBack value has to be a positive number");
338
+ }
339
+ this.topicPage.maxDaysBack = maxDaysBack;
340
+ },
341
+ enumerable: false,
342
+ configurable: true
343
+ });
344
+ TopicPage.prototype.clearConcepts = function () {
345
+ this.topicPage.concepts = [];
346
+ };
347
+ TopicPage.prototype.clearKeywords = function () {
348
+ this.topicPage.keywords = [];
349
+ };
350
+ TopicPage.prototype.clearCategories = function () {
351
+ this.topicPage.categories = [];
352
+ };
353
+ TopicPage.prototype.clearSources = function () {
354
+ this.topicPage.sources = [];
355
+ };
356
+ TopicPage.prototype.clearSourceLocations = function () {
357
+ this.topicPage.sourceLocations = [];
358
+ };
359
+ TopicPage.prototype.clearSourceGroups = function () {
360
+ this.topicPage.sourceGroups = [];
361
+ };
362
+ TopicPage.prototype.clearLocations = function () {
363
+ this.topicPage.locations = [];
364
+ };
365
+ /**
366
+ * Add a relevant concept to the topic page
367
+ * @param uri uri of the concept to be added
368
+ * @param weight importance of the provided concept (typically in range 1 - 50)
369
+ */
370
+ TopicPage.prototype.addConcept = function (uri, wgt, args) {
371
+ if (args === void 0) { args = {}; }
372
+ if (typeof wgt !== "number") {
373
+ throw new Error("Weight value has to be a positive or negative number");
374
+ }
375
+ var label = args.label, conceptType = args.conceptType, _a = args.required, required = _a === void 0 ? false : _a, _b = args.excluded, excluded = _b === void 0 ? false : _b;
376
+ if (required && excluded) {
377
+ throw new Error("Parameters required and excluded can not be true at the same time");
378
+ }
379
+ var concept = { uri: uri, wgt: wgt, required: required, excluded: excluded };
380
+ if (label !== undefined) {
381
+ concept.label = label;
382
+ }
383
+ if (conceptType !== undefined) {
384
+ concept.type = conceptType;
385
+ }
386
+ this.topicPage.concepts = __spreadArray(__spreadArray([], __read(this.topicPage.concepts), false), [concept], false);
387
+ };
388
+ /**
389
+ * Add a relevant keyword to the topic page
390
+ * @param keyword keyword or phrase to be added
391
+ * @param weight importance of the provided keyword (typically in range 1 - 50)
392
+ */
393
+ TopicPage.prototype.addKeyword = function (keyword, wgt, args) {
394
+ if (args === void 0) { args = {}; }
395
+ if (typeof wgt !== "number") {
396
+ throw new Error("Weight value has to be a positive or negative number");
397
+ }
398
+ var _a = args.required, required = _a === void 0 ? false : _a, _b = args.excluded, excluded = _b === void 0 ? false : _b;
399
+ this.topicPage.keywords = __spreadArray(__spreadArray([], __read(this.topicPage.keywords), false), [{ keyword: keyword, wgt: wgt, required: required, excluded: excluded }], false);
400
+ };
401
+ /**
402
+ * Add a relevant category to the topic page
403
+ * @param uri uri of the category to be added
404
+ * @param weight importance of the provided category (typically in range 1 - 50)
405
+ */
406
+ TopicPage.prototype.addCategory = function (uri, wgt, args) {
407
+ if (args === void 0) { args = {}; }
408
+ if (typeof wgt !== "number") {
409
+ throw new Error("Weight value has to be a positive or negative number");
410
+ }
411
+ var _a = args.required, required = _a === void 0 ? false : _a, _b = args.excluded, excluded = _b === void 0 ? false : _b;
412
+ this.topicPage.categories = __spreadArray(__spreadArray([], __read(this.topicPage.categories), false), [{ uri: uri, wgt: wgt, required: required, excluded: excluded }], false);
413
+ };
414
+ /**
415
+ * Add a news source to the topic page
416
+ * @param uri uri of the news source to add to the topic page
417
+ * @param weight importance of the news source (typically in range 1 - 50)
418
+ */
419
+ TopicPage.prototype.addSource = function (uri, wgt, args) {
420
+ if (args === void 0) { args = {}; }
421
+ if (typeof wgt !== "number") {
422
+ throw new Error("Weight value has to be a positive or negative number");
423
+ }
424
+ var _a = args.excluded, excluded = _a === void 0 ? false : _a;
425
+ this.topicPage.sources = __spreadArray(__spreadArray([], __read(this.topicPage.sources), false), [{ uri: uri, wgt: wgt, excluded: excluded }], false);
426
+ };
427
+ /**
428
+ * Add a list of relevant sources by identifying them by their geographic location
429
+ * @param uri uri of the location where the sources should be geographically located
430
+ * @param weight importance of the provided list of sources (typically in range 1 - 50)
431
+ */
432
+ TopicPage.prototype.addSourceLocation = function (uri, wgt, args) {
433
+ if (args === void 0) { args = {}; }
434
+ if (typeof wgt !== "number") {
435
+ throw new Error("Weight value has to be a positive or negative number");
436
+ }
437
+ var _a = args.excluded, excluded = _a === void 0 ? false : _a;
438
+ this.topicPage.sourceLocations = __spreadArray(__spreadArray([], __read(this.topicPage.sourceLocations), false), [{ uri: uri, wgt: wgt, excluded: excluded }], false);
439
+ };
440
+ /**
441
+ * Add a list of relevant sources by specifying a whole source group to the topic page
442
+ * @param sourceGroupUri uri of the source group to add
443
+ * @param weight importance of the provided list of sources (typically in range 1 - 50)
444
+ */
445
+ TopicPage.prototype.addSourceGroup = function (uri, wgt, args) {
446
+ if (args === void 0) { args = {}; }
447
+ if (typeof wgt !== "number") {
448
+ throw new Error("Weight value has to be a positive or negative number");
449
+ }
450
+ var _a = args.excluded, excluded = _a === void 0 ? false : _a;
451
+ this.topicPage.sourceGroups = __spreadArray(__spreadArray([], __read(this.topicPage.sourceGroups), false), [{ uri: uri, wgt: wgt, excluded: excluded }], false);
452
+ };
453
+ /**
454
+ * Add relevant location to the topic page
455
+ * @param locationUri uri of the location to add
456
+ * @param weight importance of the provided location (typically in range 1 - 50)
457
+ */
458
+ TopicPage.prototype.addLocation = function (locationUri, weight) {
459
+ if (typeof weight !== "number") {
460
+ throw new Error("Weight value has to be a positive or negative number");
461
+ }
462
+ this.topicPage.locations = __spreadArray(__spreadArray([], __read(this.topicPage.locations), false), [{ uri: locationUri, wgt: weight }], false);
463
+ };
464
+ Object.defineProperty(TopicPage.prototype, "languages", {
465
+ /**
466
+ * Restrict the results to the list of specified languages
467
+ */
468
+ set: function (languages) {
469
+ if (!Array.isArray(languages)) {
470
+ languages = [languages];
471
+ }
472
+ if (languages.every(function (language) { return language.length === 3; })) {
473
+ this.topicPage.langs = languages;
474
+ }
475
+ else {
476
+ throw new Error("Expected to get language in ISO3 code");
477
+ }
478
+ },
479
+ enumerable: false,
480
+ configurable: true
481
+ });
482
+ Object.defineProperty(TopicPage.prototype, "restrictToSetConceptsAndKeywords", {
483
+ /**
484
+ * if true then the results have to mention at least one of the specified concepts or keywords
485
+ */
486
+ set: function (restrict) {
487
+ if (typeof restrict !== "boolean") {
488
+ throw new Error("Restrict value has to be a boolean value");
489
+ }
490
+ this.topicPage.restrictToSetConcepts = restrict;
491
+ },
492
+ enumerable: false,
493
+ configurable: true
494
+ });
495
+ Object.defineProperty(TopicPage.prototype, "restrictToSetCategories", {
496
+ /**
497
+ * if set to true then return only results that are assigned to one of the specified categories
498
+ */
499
+ set: function (restrict) {
500
+ if (typeof restrict !== "boolean") {
501
+ throw new Error("Restrict value has to be a boolean value");
502
+ }
503
+ this.topicPage.restrictToSetCategories = restrict;
504
+ },
505
+ enumerable: false,
506
+ configurable: true
507
+ });
508
+ Object.defineProperty(TopicPage.prototype, "restrictToSetSources", {
509
+ /**
510
+ * if set to true then return only results from one of the specified news sources
511
+ * this includes also sources set by source groups or by source locations
512
+ */
513
+ set: function (restrict) {
514
+ if (typeof restrict !== "boolean") {
515
+ throw new Error("Restrict value has to be a boolean value");
516
+ }
517
+ this.topicPage.restrictToSetSources = restrict;
518
+ },
519
+ enumerable: false,
520
+ configurable: true
521
+ });
522
+ Object.defineProperty(TopicPage.prototype, "restrictToSetLocations", {
523
+ /**
524
+ * if set to true, then return only results that are located at one of the specified locations
525
+ */
526
+ set: function (restrict) {
527
+ if (typeof restrict !== "boolean") {
528
+ throw new Error("Restrict value has to be a boolean value");
529
+ }
530
+ this.topicPage.restrictToSetLocations = restrict;
531
+ },
532
+ enumerable: false,
533
+ configurable: true
534
+ });
535
+ /**
536
+ * Return a list of articles that match the topic page
537
+ * @param args {ER.TopicPageArticles} Object which contains a host of optional parameters
538
+ */
539
+ TopicPage.prototype.getArticles = function () {
540
+ return __awaiter(this, arguments, void 0, function (args) {
541
+ var _a, page, _b, count, _c, sortBy, _d, sortByAsc, _e, dataType, _f, returnInfo, otherParameters, params, request;
542
+ var _g;
543
+ if (args === void 0) { args = {}; }
544
+ return __generator(this, function (_h) {
545
+ switch (_h.label) {
546
+ case 0:
547
+ _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 100 : _b, _c = args.sortBy, sortBy = _c === void 0 ? "rel" : _c, _d = args.sortByAsc, sortByAsc = _d === void 0 ? false : _d, _e = args.dataType, dataType = _e === void 0 ? "news" : _e, _f = args.returnInfo, returnInfo = _f === void 0 ? new returnInfo_1.ReturnInfo() : _f, otherParameters = __rest(args, ["page", "count", "sortBy", "sortByAsc", "dataType", "returnInfo"]);
548
+ if (page < 1) {
549
+ throw new RangeError("page has to be >= 1");
550
+ }
551
+ if (count > 100) {
552
+ throw new RangeError("At most 100 articles can be returned at a time");
553
+ }
554
+ params = __assign({ action: "getArticlesForTopicPage", resultType: "articles", dataType: this.topicPage.dataType, articlesCount: count, articlesSortBy: sortBy, articlesSortByAsc: sortByAsc, articlesPage: page, topicPage: JSON.stringify(this.topicPage) }, returnInfo.getParams());
555
+ if (Object.keys(otherParameters).length > 0) {
556
+ params = __assign(__assign({}, params), otherParameters);
557
+ }
558
+ return [4 /*yield*/, this.eventRegistry.jsonRequest("/api/v1/article", params)];
559
+ case 1:
560
+ request = _h.sent();
561
+ return [2 /*return*/, (_g = request === null || request === void 0 ? void 0 : request.data) !== null && _g !== void 0 ? _g : { articles: { results: [] } }];
562
+ }
563
+ });
564
+ });
565
+ };
566
+ /**
567
+ * Return a list of events that match the topic page
568
+ * @param args {ER.TopicPageEvents} Object which contains a host of optional parameters
569
+ */
570
+ TopicPage.prototype.getEvents = function () {
571
+ return __awaiter(this, arguments, void 0, function (args) {
572
+ var _a, page, _b, count, _c, sortBy, _d, sortByAsc, _e, returnInfo, otherParameters, params, request;
573
+ var _f;
574
+ if (args === void 0) { args = {}; }
575
+ return __generator(this, function (_g) {
576
+ switch (_g.label) {
577
+ case 0:
578
+ _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 50 : _b, _c = args.sortBy, sortBy = _c === void 0 ? "rel" : _c, _d = args.sortByAsc, sortByAsc = _d === void 0 ? false : _d, _e = args.returnInfo, returnInfo = _e === void 0 ? new returnInfo_1.ReturnInfo() : _e, otherParameters = __rest(args, ["page", "count", "sortBy", "sortByAsc", "returnInfo"]);
579
+ if (page < 1) {
580
+ throw new RangeError("page has to be >= 1");
581
+ }
582
+ if (count > 50) {
583
+ throw new RangeError("At most 50 events can be returned at a time");
584
+ }
585
+ params = __assign({ action: "getEventsForTopicPage", resultType: "events", dataType: this.topicPage.dataType, eventsCount: count, eventsSortBy: sortBy, eventsSortByAsc: sortByAsc, eventsPage: page, topicPage: JSON.stringify(this.topicPage) }, returnInfo.getParams());
586
+ if (Object.keys(otherParameters).length > 0) {
587
+ params = __assign(__assign({}, params), otherParameters);
588
+ }
589
+ return [4 /*yield*/, this.eventRegistry.jsonRequest("/api/v1/event", params)];
590
+ case 1:
591
+ request = _g.sent();
592
+ return [2 /*return*/, (_f = request === null || request === void 0 ? void 0 : request.data) !== null && _f !== void 0 ? _f : { events: { results: [] } }];
593
+ }
594
+ });
595
+ });
596
+ };
597
+ return TopicPage;
598
+ }(base_1.QueryParamsBase));
599
+ exports.TopicPage = TopicPage;
605
600
  //# sourceMappingURL=topicPage.js.map