worldstate-emitter 1.0.4 → 1.0.8

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 (76) hide show
  1. package/README.md +6 -6
  2. package/SECURITY.md +17 -0
  3. package/handlers/Twitter.js +2 -2
  4. package/handlers/Worldstate.js +16 -163
  5. package/handlers/events/arrayLike.js +20 -0
  6. package/handlers/events/checkOverrides.js +19 -0
  7. package/handlers/events/cycleLike.js +1 -1
  8. package/handlers/events/eKeyOverrides.js +28 -0
  9. package/handlers/events/kuva.js +31 -0
  10. package/handlers/events/objectLike.js +1 -1
  11. package/handlers/events/parse.js +72 -0
  12. package/package.json +63 -20
  13. package/resources/tweeters.json +3 -3
  14. package/utilities/WSCache.js +5 -1
  15. package/.codeclimate.yml +0 -13
  16. package/.eslintrc.json +0 -33
  17. package/.github/.stale.yml +0 -13
  18. package/.github/CODEOWNERS +0 -1
  19. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -27
  20. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  21. package/.github/PULL_REQUEST_TEMPLATE.md +0 -17
  22. package/.github/update_docs.sh +0 -22
  23. package/.snyk +0 -8
  24. package/docs/RSS.html +0 -424
  25. package/docs/TwitterCache.html +0 -900
  26. package/docs/WSCache.html +0 -734
  27. package/docs/Worldstate.html +0 -1294
  28. package/docs/classes.list.html +0 -344
  29. package/docs/fonts/glyphicons-halflings-regular.eot +0 -0
  30. package/docs/fonts/glyphicons-halflings-regular.svg +0 -288
  31. package/docs/fonts/glyphicons-halflings-regular.ttf +0 -0
  32. package/docs/fonts/glyphicons-halflings-regular.woff +0 -0
  33. package/docs/fonts/glyphicons-halflings-regular.woff2 +0 -0
  34. package/docs/global.html +0 -1882
  35. package/docs/handlers_RSS.js.html +0 -321
  36. package/docs/handlers_Twitter.js.html +0 -431
  37. package/docs/handlers_Worldstate.js.html +0 -559
  38. package/docs/img/glyphicons-halflings-white.png +0 -0
  39. package/docs/img/glyphicons-halflings.png +0 -0
  40. package/docs/index.html +0 -402
  41. package/docs/quicksearch.html +0 -31
  42. package/docs/scripts/docstrap.lib.js +0 -11
  43. package/docs/scripts/fulltext-search-ui.js +0 -89
  44. package/docs/scripts/fulltext-search.js +0 -36
  45. package/docs/scripts/lunr.min.js +0 -6
  46. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
  47. package/docs/scripts/prettify/jquery.min.js +0 -6
  48. package/docs/scripts/prettify/lang-css.js +0 -21
  49. package/docs/scripts/prettify/prettify.js +0 -496
  50. package/docs/scripts/sunlight.js +0 -1157
  51. package/docs/scripts/toc.js +0 -203
  52. package/docs/styles/darkstrap.css +0 -960
  53. package/docs/styles/prettify-tomorrow.css +0 -132
  54. package/docs/styles/site.cerulean.css +0 -7008
  55. package/docs/styles/site.cosmo.css +0 -7061
  56. package/docs/styles/site.cyborg.css +0 -7048
  57. package/docs/styles/site.darkly.css +0 -7171
  58. package/docs/styles/site.darkstrap.css +0 -5638
  59. package/docs/styles/site.dibs-bootstrap.css +0 -5899
  60. package/docs/styles/site.flatly.css +0 -7147
  61. package/docs/styles/site.journal.css +0 -6973
  62. package/docs/styles/site.lumen.css +0 -7298
  63. package/docs/styles/site.paper.css +0 -7623
  64. package/docs/styles/site.readable.css +0 -6997
  65. package/docs/styles/site.sandstone.css +0 -7035
  66. package/docs/styles/site.simplex.css +0 -7023
  67. package/docs/styles/site.slate.css +0 -7343
  68. package/docs/styles/site.spacelab.css +0 -7055
  69. package/docs/styles/site.superhero.css +0 -7131
  70. package/docs/styles/site.united.css +0 -6895
  71. package/docs/styles/site.yeti.css +0 -7195
  72. package/docs/styles/sunlight.dark.css +0 -345
  73. package/docs/styles/sunlight.default.css +0 -344
  74. package/docs/utilities_WSCache.js.html +0 -322
  75. package/docs/utilities_index.js.html +0 -338
  76. package/jsdoc-config.json +0 -35
@@ -1,431 +0,0 @@
1
- <!DOCTYPE html>
2
-
3
- <html lang="en">
4
- <head>
5
- <meta charset="utf-8">
6
- <meta name="viewport" content="width=device-width">
7
- <title>Worldstate Emitter Source: handlers/Twitter.js</title>
8
-
9
- <!--[if lt IE 9]>
10
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11
- <![endif]-->
12
- <link type="text/css" rel="stylesheet" href="styles/sunlight.dark.css">
13
-
14
- <link type="text/css" rel="stylesheet" href="styles/site.cosmo.css">
15
-
16
- </head>
17
-
18
- <body>
19
-
20
- <div class="navbar navbar-default navbar-fixed-top navbar-inverse">
21
- <div class="container">
22
- <div class="navbar-header">
23
- <a class="navbar-brand" href="index.html">Worldstate Emitter</a>
24
- <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
25
- <span class="icon-bar"></span>
26
- <span class="icon-bar"></span>
27
- <span class="icon-bar"></span>
28
- </button>
29
- </div>
30
- <div class="navbar-collapse collapse" id="topNavigation">
31
- <ul class="nav navbar-nav">
32
-
33
- <li class="dropdown">
34
- <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
35
- <ul class="dropdown-menu inline">
36
- <li><a href="RSS.html">RSS</a></li><li><a href="TwitterCache.html">TwitterCache</a></li><li><a href="Worldstate.html">Worldstate</a></li><li><a href="WSCache.html">WSCache</a></li>
37
- </ul>
38
- </li>
39
-
40
- <li class="dropdown">
41
- <a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
42
- <ul class="dropdown-menu inline">
43
- <li><a href="global.html#arrayLike">arrayLike</a></li><li><a href="global.html#between">between</a></li><li><a href="global.html#checkOverrides">checkOverrides</a></li><li><a href="global.html#fromNow">fromNow</a></li><li><a href="global.html#groupBy">groupBy</a></li><li><a href="global.html#initCycleStart">initCycleStart</a></li><li><a href="global.html#kuvaProcessing">kuvaProcessing</a></li><li><a href="global.html#lastUpdated">lastUpdated</a></li><li><a href="global.html#parseNew">parseNew</a></li>
44
- </ul>
45
- </li>
46
-
47
- </ul>
48
-
49
- <div class="col-sm-3 col-md-3">
50
- <form class="navbar-form" role="search">
51
- <div class="input-group">
52
- <input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
53
- <div class="input-group-btn">
54
- <button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
55
- </div>
56
- </div>
57
- </form>
58
- </div>
59
-
60
- </div>
61
-
62
- </div>
63
- </div>
64
-
65
-
66
- <div class="container" id="toc-content">
67
- <div class="row">
68
-
69
-
70
- <div class="col-md-12">
71
-
72
- <div id="main">
73
-
74
-
75
- <h1 class="page-title">Source: handlers/Twitter.js</h1>
76
-
77
- <section>
78
- <article>
79
- <pre
80
- class="sunlight-highlight-javascript linenums">'use strict';
81
-
82
- const Twitter = require('twitter');
83
- const toWatch = require('../resources/tweeters.json');
84
-
85
- const { logger } = require('../utilities');
86
-
87
- const determineTweetType = (tweet) => {
88
- if (tweet.in_reply_to_status_id) {
89
- return ('reply');
90
- }
91
- if (tweet.quoted_status_id) {
92
- return ('quote');
93
- }
94
- if (tweet.retweeted_status) {
95
- return ('retweet');
96
- }
97
- return ('tweet');
98
- };
99
-
100
- const parseAuthor = (tweet) => ({
101
- name: tweet.user.name,
102
- handle: tweet.user.screen_name,
103
- url: `https://twitter.com/${tweet.user.screen_name}`,
104
- avatar: `${tweet.user.profile_image_url.replace('_normal.jpg', '.jpg')}`,
105
- });
106
-
107
- const parseQuoted = (tweet, type) => (tweet[type]
108
- ? {
109
- text: tweet[type].full_text,
110
- author: {
111
- name: tweet[type].user.name,
112
- handle: tweet[type].user.screen_name,
113
- },
114
- }
115
- : undefined);
116
-
117
- const parseTweet = (tweets, watchable) => {
118
- const [tweet] = tweets;
119
- const type = determineTweetType(tweet);
120
- return {
121
- id: `twitter.${watchable.plain}.${type}`,
122
- uniqueId: String(tweets[0].id_str),
123
- text: tweet.full_text,
124
- url: `https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}`,
125
- mediaUrl: tweet.entities.media ? tweet.entities.media[0].media_url : undefined,
126
- isReply: typeof tweet.in_reply_to_status_id !== 'undefined',
127
- author: parseAuthor(tweet),
128
- quote: parseQuoted(tweet, 'quoted_status'),
129
- retweet: parseQuoted(tweet, 'retweeted_status'),
130
- createdAt: new Date(tweet.created_at),
131
- };
132
- };
133
-
134
- /**
135
- * Twitter event handler
136
- */
137
- class TwitterCache {
138
- /**
139
- * Create a new Twitter self-updating cache
140
- * @param {EventEmitter} eventEmitter emitter to push new tweets to
141
- */
142
- constructor(eventEmitter) {
143
- this.emitter = eventEmitter;
144
- this.timeout = process.env.TWITTER_TIMEOUT || 60000;
145
- this.initTime = Date.now();
146
-
147
- const clientInfo = {
148
- consumer_key: process.env.TWITTER_KEY,
149
- consumer_secret: process.env.TWITTER_SECRET,
150
- bearer_token: process.env.TWITTER_BEARER_TOKEN,
151
- };
152
-
153
- this.clientInfoValid = clientInfo.consumer_key
154
- &amp;&amp; clientInfo.consumer_secret
155
- &amp;&amp; clientInfo.bearer_token;
156
-
157
- this.initClient(clientInfo);
158
- }
159
-
160
- initClient(clientInfo) {
161
- try {
162
- if (this.clientInfoValid) {
163
- this.client = new Twitter(clientInfo);
164
-
165
- // don't attempt anything else if authentication fails
166
- this.toWatch = toWatch;
167
- this.currentData = null;
168
- this.lastUpdated = Date.now() - 60000;
169
- this.updateInterval = setInterval(() => this.update(), this.timeout);
170
- this.update();
171
- } else {
172
- logger.warn(`Twitter client not initialized... invalid token: ${clientInfo.bearer_token}`);
173
- }
174
- } catch (err) {
175
- this.client = undefined;
176
- this.clientInfoValid = false;
177
- logger.error(err);
178
- }
179
- }
180
-
181
- /**
182
- * Force the cache to update
183
- * @returns {Promise} the currently updating promise.
184
- */
185
- async update() {
186
- if (!this.clientInfoValid) return undefined;
187
-
188
- if (!this.toWatch) {
189
- logger.verbose('Not processing twitter, no data to watch.');
190
- return undefined;
191
- }
192
-
193
- if (!this.client) {
194
- logger.verbose('Not processing twitter, no client to connect.');
195
- return undefined;
196
- }
197
-
198
- this.updating = this.getParseableData();
199
-
200
- return this.updating;
201
- }
202
-
203
- /**
204
- * Get data able to be parsed from twitter.
205
- * @returns {Promise.&lt;Array.&lt;Object>>} Twieets
206
- */
207
- async getParseableData() {
208
- logger.silly('Starting Twitter update...');
209
- const parsedData = [];
210
- try {
211
- for (const watchable of this.toWatch) {
212
- const tweets = await this.client.get('statuses/user_timeline', {
213
- screen_name: watchable.acc_name,
214
- tweet_mode: 'extended',
215
- count: 1,
216
- });
217
- const tweet = parseTweet(tweets, watchable);
218
- parsedData.push(tweet);
219
-
220
- if (tweet.createdAt.getTime() > this.lastUpdated) {
221
- this.emitter.emit('tweet', tweet);
222
- }
223
- }
224
- } catch (error) {
225
- this.onError(error);
226
- }
227
- this.lastUpdated = Date.now();
228
- return parsedData;
229
- }
230
-
231
- /**
232
- * Handle errors that arise while fetching data from twitter
233
- * @param {[type]} error twitter error
234
- */
235
- onError(error) {
236
- if (error[0] &amp;&amp; error[0].code === 32) {
237
- this.clientInfoValid = false;
238
- logger.info('wiping twitter client data, could not authenticate...');
239
- } else {
240
- logger.debug(JSON.stringify(error));
241
- }
242
- }
243
-
244
- /**
245
- * Get the current data or a promise with the current data
246
- * @returns {Promise.&lt;Object> | Object} either the current data
247
- * if it's not updating, or the promise returning the new data
248
- */
249
- async getData() {
250
- if (!this.clientInfoValid) return undefined;
251
-
252
- if (this.updating) {
253
- return this.updating;
254
- }
255
- return this.currentData;
256
- }
257
- }
258
-
259
- module.exports = TwitterCache;
260
- </pre>
261
- </article>
262
- </section>
263
-
264
-
265
-
266
-
267
-
268
- </div>
269
- </div>
270
-
271
- <div class="clearfix"></div>
272
-
273
-
274
-
275
- </div>
276
- </div>
277
-
278
-
279
- <div class="modal fade" id="searchResults">
280
- <div class="modal-dialog">
281
- <div class="modal-content">
282
- <div class="modal-header">
283
- <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
284
- <h4 class="modal-title">Search results</h4>
285
- </div>
286
- <div class="modal-body"></div>
287
- <div class="modal-footer">
288
- <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
289
- </div>
290
- </div><!-- /.modal-content -->
291
- </div><!-- /.modal-dialog -->
292
- </div>
293
-
294
-
295
- <footer>
296
-
297
-
298
- <span class="copyright">
299
- ©2020, WFCD
300
- </span>
301
-
302
- <span class="jsdoc-message">
303
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a>
304
-
305
- on Monday, August 10th 2020, 15:25:12
306
-
307
- using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
308
- </span>
309
- </footer>
310
-
311
- <script src="scripts/docstrap.lib.js"></script>
312
- <script src="scripts/toc.js"></script>
313
-
314
- <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
315
-
316
-
317
- <script>
318
- $( function () {
319
- $( "[id*='$']" ).each( function () {
320
- var $this = $( this );
321
-
322
- $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
323
- } );
324
-
325
- $( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
326
- var $this = $( this );
327
-
328
- var example = $this.find( "code" );
329
- exampleText = example.html();
330
- var lang = /{@lang (.*?)}/.exec( exampleText );
331
- if ( lang && lang[1] ) {
332
- exampleText = exampleText.replace( lang[0], "" );
333
- example.html( exampleText );
334
- lang = lang[1];
335
- } else {
336
- var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
337
- lang = langClassMatch ? langClassMatch[1] : "javascript";
338
- }
339
-
340
- if ( lang ) {
341
-
342
- $this
343
- .addClass( "sunlight-highlight-" + lang )
344
- .addClass( "linenums" )
345
- .html( example.html() );
346
-
347
- }
348
- } );
349
-
350
- Sunlight.highlightAll( {
351
- lineNumbers : true,
352
- showMenu : true,
353
- enableDoclinks : true
354
- } );
355
-
356
- $.catchAnchorLinks( {
357
- navbarOffset: 10
358
- } );
359
- $( "#toc" ).toc( {
360
- anchorName : function ( i, heading, prefix ) {
361
- return $( heading ).attr( "id" ) || ( prefix + i );
362
- },
363
- selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
364
- showAndHide : false,
365
- smoothScrolling: true
366
- } );
367
-
368
- $( "#main span[id^='toc']" ).addClass( "toc-shim" );
369
- $( '.dropdown-toggle' ).dropdown();
370
-
371
- $( "table" ).each( function () {
372
- var $this = $( this );
373
- $this.addClass('table');
374
- } );
375
-
376
- } );
377
- </script>
378
-
379
-
380
-
381
- <!--Navigation and Symbol Display-->
382
-
383
- <script>
384
- $( function () {
385
- $( '#main' ).localScroll( {
386
- offset : { top : 60 } //offset by the height of your header (give or take a few px, see what works for you)
387
- } );
388
- $( "dt.name" ).each( function () {
389
- var $this = $( this ).find("h4");
390
- var icon = $( "<i/>" ).addClass( "icon-plus-sign" ).addClass( "pull-right" ).addClass( "icon-white" );
391
- var dt = $(this);
392
- var children = dt.next( "dd" );
393
-
394
- dt.prepend( icon ).css( {cursor : "pointer"} );
395
- dt.addClass( "member-collapsed" ).addClass( "member" );
396
-
397
-
398
- children.hide();
399
-
400
- dt.children().on( "click", function () {
401
- children = dt.next( "dd" );
402
- children.slideToggle( "fast", function () {
403
-
404
- if ( children.is( ":visible" ) ) {
405
- icon.addClass( "icon-minus-sign" ).removeClass( "icon-plus-sign" ).removeClass( "icon-white" );
406
- dt.addClass( "member-open" ).animate( "member-collapsed" );
407
- } else {
408
- icon.addClass( "icon-plus-sign" ).removeClass( "icon-minus-sign" ).addClass( "icon-white" );
409
- dt.addClass( "member-collapsed" ).removeClass( "member-open" );
410
- }
411
- } );
412
- } );
413
-
414
- } );
415
- } );
416
- </script>
417
-
418
-
419
- <!--Google Analytics-->
420
-
421
-
422
-
423
- <script type="text/javascript">
424
- $(document).ready(function() {
425
- SearcherDisplay.init();
426
- });
427
- </script>
428
-
429
-
430
- </body>
431
- </html>