worldstate-emitter 2.2.13 → 2.3.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/README.md CHANGED
@@ -5,93 +5,285 @@ Suuuper simple emitter for worldstate events.
5
5
  Very opinionated decisions on what events and event names, as well as.... everything else
6
6
 
7
7
  [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
8
+ [![npm](https://img.shields.io/npm/v/worldstate-emitter.svg)](https://www.npmjs.com/package/worldstate-emitter)
9
+ [![npm downloads](https://img.shields.io/npm/dm/worldstate-emitter.svg)](https://www.npmjs.com/package/worldstate-emitter)
10
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue.svg)](https://www.typescriptlang.org/)
11
+ [![Discord](https://img.shields.io/discord/256087517353213954.svg?logo=discord)](https://discord.gg/jGZxH9f)
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install worldstate-emitter
17
+ ```
18
+
19
+ This package requires Node.js 20.10.0 or higher and is an ES Module.
20
+
21
+ ### Peer Dependencies
22
+
23
+ You'll also need to install the following peer dependencies:
24
+
25
+ ```bash
26
+ npm install warframe-worldstate-parser@^5 warframe-worldstate-data@^3
27
+ ```
28
+
29
+ ### Optional Dependencies
30
+
31
+ For better logging support:
32
+
33
+ ```bash
34
+ npm install winston@^3
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ### Basic Example
40
+
41
+ ```typescript
42
+ import WorldstateEmitter from "worldstate-emitter";
43
+
44
+ // Create emitter instance
45
+ const emitter = await WorldstateEmitter.make({
46
+ locale: "en",
47
+ features: ["worldstate", "rss", "twitter"],
48
+ });
49
+
50
+ // Listen for worldstate events
51
+ emitter.on("ws:update:event", (event) => {
52
+ console.log("New worldstate event:", event.id);
53
+ });
54
+
55
+ // Listen for RSS posts
56
+ emitter.on("rss", (post) => {
57
+ console.log("New forum post:", post.title);
58
+ });
59
+
60
+ // Listen for tweets
61
+ emitter.on("tweet", (tweet) => {
62
+ console.log("New tweet:", tweet.text);
63
+ });
64
+
65
+ // Get current worldstate
66
+ const worldstate = emitter.getWorldstate("en");
67
+ console.log("Current worldstate:", worldstate);
68
+ ```
69
+
70
+ ### TypeScript Support
71
+
72
+ This package is written in TypeScript and includes full type definitions. All types are automatically available when using TypeScript:
73
+
74
+ ```typescript
75
+ import WorldstateEmitter from "worldstate-emitter";
76
+ import type WorldState from "warframe-worldstate-parser";
77
+
78
+ const emitter = await WorldstateEmitter.make({ locale: "en" });
79
+
80
+ // TypeScript will infer the correct types
81
+ const ws: WorldState | undefined = emitter.getWorldstate("en");
82
+ ```
83
+
84
+ ### Configuration Options
85
+
86
+ ```typescript
87
+ interface WorldstateEmitterOptions {
88
+ locale?: string; // Language to filter events (e.g., 'en', 'es', 'de')
89
+ features?: string[]; // Features to enable: 'worldstate', 'rss', 'twitter'
90
+ }
91
+
92
+ const emitter = await WorldstateEmitter.make({
93
+ locale: "en", // Optional: filter to English only
94
+ features: ["worldstate", "rss"], // Optional: only enable these features
95
+ });
96
+ ```
97
+
98
+ ### Environment Variables
99
+
100
+ Configure the emitter with environment variables:
101
+
102
+ - `LOG_LEVEL` - Logging level (default: `error`)
103
+ - `WORLDSTATE_URL` - Custom worldstate API URL
104
+ - `KUVA_URL` - Custom Kuva/Arbitration data URL
105
+ - `SENTIENT_URL` - Custom Sentient Anomaly data URL
106
+ - `WORLDSTATE_CRON` - Cron pattern for worldstate updates (default: `25 */5 * * * *`)
107
+ - `WS_EXTERNAL_CRON` - Cron pattern for external data (default: `0 */10 * * * *`)
108
+ - `WS_EMITTER_FEATURES` - Comma-separated list of features to enable
109
+ - `TWITTER_KEY` - Twitter API consumer key
110
+ - `TWITTER_SECRET` - Twitter API consumer secret
111
+ - `TWITTER_BEARER_TOKEN` - Twitter API bearer token
112
+ - `TWITTER_TIMEOUT` - Twitter update interval in ms (default: `60000`)
8
113
 
9
114
  ## Emitter Events
10
115
 
11
- | Emitter Event | Emit key | description |
12
- |:--------------|-------------|---------------------------------------------|
13
- | RSS | `rss` | New forum post from DE |
14
- | Worldstate | `ws:update` | New Worldstate event |
15
- | Tweet | `tweet` | New tweet from one of the selected accounts |
116
+ ### Main Events
16
117
 
118
+ | Emitter Event | Emit key | Description |
119
+ | :---------------- | ------------------ | ------------------------------------------- |
120
+ | RSS | `rss` | New forum post from DE |
121
+ | Raw Worldstate | `ws:update:raw` | Raw worldstate data updated |
122
+ | Parsed Worldstate | `ws:update:parsed` | Parsed worldstate data available |
123
+ | Worldstate Event | `ws:update:event` | Individual worldstate event |
124
+ | Tweet | `tweet` | New tweet from one of the selected accounts |
125
+
126
+ ### API Methods
127
+
128
+ | Method | Parameters | Returns | Description |
129
+ | :---------------- | :------------------ | :------------------------ | :---------------------------- |
130
+ | `getRss()` | - | `RssFeedItem[]` | Get current RSS feed items |
131
+ | `getWorldstate()` | `language?: string` | `WorldState \| undefined` | Get worldstate for a language |
132
+ | `getTwitter()` | - | `Promise<any>` | Get Twitter data |
133
+ | `debug` | - | `DebugInfo` | Get debug information |
134
+
135
+ **Parameters:**
136
+
137
+ - `language` - Defaults to `en`. Any locale from [`warframe-worldstate-data`](https://github.com/WFCD/warframe-worldstate-data)
17
138
 
18
139
  <details>
19
140
  <summary>Twitter Accounts</summary>
20
141
 
21
- - [Warframe](https://twitter.com/playwarframe) (warframe)
22
- - [Digital Extremes](https://twitter.com/digitalextremes) (digitalextremes)
23
- - [[DE]Pablo](https://twitter.com/PabloPoon) (pablo)
24
- - [Cameron Rogers](https://twitter.com/cam_rogers) (cameron)
25
- - [[DE]Rebecca](https://twitter.com/rebbford) (rebecca)
26
- - [[DE]Steve](https://twitter.com/sj_sinclair) (steve)
27
- - [[DE]Danielle](https://twitter.com/soelloo) (danielle)
28
- - [[DE]Megan](https://twitter.com/moitoi) (megan)
29
- - [[DE]George](https://twitter.com/GameSoundDesign) (george)
30
- - [[DE]Maciej](https://twitter.com/msinilo) (maciej)
31
- - [[DE]Sheldon](https://twitter.com/sheldoncarter) (sheldon)
32
- - [[DE]Marcus](https://twitter.com/narcbag) (narc)
33
- - [[DE]Helen](https://twitter.com/helen_heikkila) (helen)
34
- - [Tobiah (me)](https://twitter.com/tobitenno) (tobiah)
35
- - [WF Discord](https://twitter.com/wfdiscord) (wfdiscord)
142
+ - [Warframe](https://twitter.com/playwarframe) (warframe)
143
+ - [Digital Extremes](https://twitter.com/digitalextremes) (digitalextremes)
144
+ - [[DE]Pablo](https://twitter.com/PabloPoon) (pablo)
145
+ - [Cameron Rogers](https://twitter.com/cam_rogers) (cameron)
146
+ - [[DE]Rebecca](https://twitter.com/rebbford) (rebecca)
147
+ - [[DE]Steve](https://twitter.com/sj_sinclair) (steve)
148
+ - [[DE]Danielle](https://twitter.com/soelloo) (danielle)
149
+ - [[DE]Megan](https://twitter.com/moitoi) (megan)
150
+ - [[DE]George](https://twitter.com/GameSoundDesign) (george)
151
+ - [[DE]Maciej](https://twitter.com/msinilo) (maciej)
152
+ - [[DE]Sheldon](https://twitter.com/sheldoncarter) (sheldon)
153
+ - [[DE]Marcus](https://twitter.com/narcbag) (narc)
154
+ - [[DE]Helen](https://twitter.com/helen_heikkila) (helen)
155
+ - [Tobiah (me)](https://twitter.com/tobitenno) (tobiah)
156
+ - [WF Discord](https://twitter.com/wfdiscord) (wfdiscord)
36
157
  </details>
37
158
 
38
159
  <br />
39
160
  <details> <summary>Twitter Events</summary>
40
161
 
41
- - `tweet`
42
- - `retweet`
43
- - `reply`
44
- - `quote`
162
+ - `tweet`
163
+ - `retweet`
164
+ - `reply`
165
+ - `quote`
45
166
  </details>
46
167
 
47
168
  <br />
48
169
  <details><summary>RSS Feeds</summary>
49
170
 
50
- - [Players helping Players](https://forums.warframe.com/forum/38-players-helping-players)
51
- - [PC Updates](https://forums.warframe.com/forum/3-pc-update-notes)
52
- - [PC Announcements](https://forums.warframe.com/forum/2-pc-announcements)
53
- - [PS4 Updates](https://forums.warframe.com/forum/152-ps4-update-notes)
54
- - [PS4 Announcements](https://forums.warframe.com/forum/151-ps4-announcements)
55
- - [XB1 Updates](https://forums.warframe.com/forum/253-xbox-one-update-notes)
56
- - [XB1 Announcements](https://forums.warframe.com/forum/252-xbox-one-announcements)
57
- - [Switch Updates](https://forums.warframe.com/forum/1196-nintendo-switch-update-notes)
58
- - [Switch Announcements](https://forums.warframe.com/forum/1198-nintendo-switch-announcements)
59
- - [News](https://forums.warframe.com/forum/170-announcements-events)
60
- - [Developers Workshop](https://forums.warframe.com/forum/123-developer-workshop-update-notes)
61
-
171
+ - [Players helping Players](https://forums.warframe.com/forum/38-players-helping-players)
172
+ - [PC Updates](https://forums.warframe.com/forum/3-pc-update-notes)
173
+ - [PC Announcements](https://forums.warframe.com/forum/2-pc-announcements)
174
+ - [PS4 Updates](https://forums.warframe.com/forum/152-ps4-update-notes)
175
+ - [PS4 Announcements](https://forums.warframe.com/forum/151-ps4-announcements)
176
+ - [XB1 Updates](https://forums.warframe.com/forum/253-xbox-one-update-notes)
177
+ - [XB1 Announcements](https://forums.warframe.com/forum/252-xbox-one-announcements)
178
+ - [Switch Updates](https://forums.warframe.com/forum/1196-nintendo-switch-update-notes)
179
+ - [Switch Announcements](https://forums.warframe.com/forum/1198-nintendo-switch-announcements)
180
+ - [News](https://forums.warframe.com/forum/170-announcements-events)
181
+ - [Developers Workshop](https://forums.warframe.com/forum/123-developer-workshop-update-notes)
182
+
62
183
  <details><summary>Staff Replies</summary>
63
184
 
64
- - [[DE]Rebecca](https://forums.warframe.com/discover/839)
65
- - [[DE]Danielle](https://forums.warframe.com/discover/840)
66
- - [[DE]Drew](https://forums.warframe.com/discover/841)
67
- - [[DE]Glen](https://forums.warframe.com/discover/842)
68
- - [[DE]Taylor](https://forums.warframe.com/discover/1171)
69
- - [[DE]Steve](https://forums.warframe.com/discover/1777)
70
- - [[DE]Helen](https://forums.warframe.com/discover/1291)
71
- - [[DE]Saske](https://forums.warframe.com/discover/1294)
72
- - [[DE]Kaz](https://forums.warframe.com/discover/1295)
73
- - [[DE]Pablo](https://forums.warframe.com/discover/1299)
74
- - [[DE]Connor](https://forums.warframe.com/discover/1778)
75
- - [[DE]Marcus](https://forums.warframe.com/discover/1779)
76
- - [[DE]George](https://forums.warframe.com/discover/1780)
77
- - [[DE]Bear](https://forums.warframe.com/discover/1781)
185
+ - [[DE]Rebecca](https://forums.warframe.com/discover/839)
186
+ - [[DE]Danielle](https://forums.warframe.com/discover/840)
187
+ - [[DE]Drew](https://forums.warframe.com/discover/841)
188
+ - [[DE]Glen](https://forums.warframe.com/discover/842)
189
+ - [[DE]Taylor](https://forums.warframe.com/discover/1171)
190
+ - [[DE]Steve](https://forums.warframe.com/discover/1777)
191
+ - [[DE]Helen](https://forums.warframe.com/discover/1291)
192
+ - [[DE]Saske](https://forums.warframe.com/discover/1294)
193
+ - [[DE]Kaz](https://forums.warframe.com/discover/1295)
194
+ - [[DE]Pablo](https://forums.warframe.com/discover/1299)
195
+ - [[DE]Connor](https://forums.warframe.com/discover/1778)
196
+ - [[DE]Marcus](https://forums.warframe.com/discover/1779)
197
+ - [[DE]George](https://forums.warframe.com/discover/1780)
198
+ - [[DE]Bear](https://forums.warframe.com/discover/1781)
78
199
  </details>
79
200
  </details>
80
201
 
81
202
  <br />
82
- <details><summary>Other Methods</summary>
83
203
 
84
- Method | Params | Output
85
- :-- | -- | --
86
- `getRss` | -- | Map of RSS feeds with `url` and `items`
87
- `getWorldstate` | `platform`, `locale` | Worldstate objects
88
- -- | `platform` | Defaults to `pc`. One of `pc`, `ps4`, `xb1`, `swi`.
89
- -- | `locale` | Defaults to `en`. Any of the locales included in [`worldstate-data`](https://github.com/WFCD/warframe-worldstate-data)
204
+ ## Development
90
205
 
91
- `*` Denote required
206
+ ### Building
92
207
 
93
- </details>
94
- <br />
208
+ This project is written in TypeScript and uses `tsdown` for building:
209
+
210
+ ```bash
211
+ npm run build
212
+ ```
213
+
214
+ This generates:
215
+
216
+ - `dist/index.mjs` - Compiled JavaScript module
217
+ - `dist/index.d.mts` - TypeScript type definitions
218
+
219
+ ### Testing
220
+
221
+ ```bash
222
+ npm test
223
+ ```
224
+
225
+ Tests use Mocha with `tsx` for TypeScript support.
226
+
227
+ ### Linting
228
+
229
+ This project uses Biome for linting and formatting:
230
+
231
+ ```bash
232
+ npm run lint # Check for issues
233
+ npm run lint:fix # Auto-fix issues
234
+ ```
235
+
236
+ ### Documentation
237
+
238
+ Generate TypeDoc documentation:
239
+
240
+ ```bash
241
+ npm run build:docs
242
+ ```
243
+
244
+ ## Project Structure
245
+
246
+ ```haskell
247
+ worldstate-emitter/
248
+ ├── handlers/ # Event handlers
249
+ │ ├── events/ # Event processors
250
+ │ ├── RSS.ts # RSS feed handler
251
+ │ ├── Twitter.ts # Twitter API handler
252
+ │ └── Worldstate.ts # Worldstate handler
253
+ ├── utilities/ # Utility classes and functions
254
+ │ ├── Cache.ts # Cron-based cache
255
+ │ ├── WSCache.ts # Worldstate cache wrapper
256
+ │ ├── env.ts # Environment configuration
257
+ │ └── index.ts # Shared utilities
258
+ ├── resources/ # Configuration files
259
+ │ ├── config.ts # URL and cron patterns
260
+ │ ├── rssFeeds.json # RSS feed definitions
261
+ │ └── tweeters.json # Twitter accounts to watch
262
+ ├── types/ # TypeScript type definitions
263
+ ├── test/ # Test files
264
+ └── dist/ # Build output (generated)
265
+ ```
266
+
267
+ ## Contributing
268
+
269
+ This project uses:
270
+
271
+ - **TypeScript** with strict mode
272
+ - **Biome** for linting and formatting
273
+ - **Conventional Commits** for commit messages
274
+ - **Semantic Release** for automated versioning
275
+
276
+ Before submitting a PR:
277
+
278
+ 1. Run `npm run lint:fix` to format code
279
+ 2. Run `npm test` to ensure tests pass
280
+ 3. Run `npm run build` to verify the build
281
+ 4. Use conventional commit messages
282
+
283
+ ## License
284
+
285
+ Apache-2.0
95
286
 
96
287
  ## Help & Contact
288
+
97
289
  [![Discord](https://img.shields.io/discord/256087517353213954.svg?logo=discord)](https://discord.gg/jGZxH9f)
@@ -0,0 +1,56 @@
1
+ import EventEmitter from "node:events";
2
+ import { RSSItem } from "rss-feed-emitter";
3
+ import WorldState from "warframe-worldstate-parser";
4
+
5
+ //#region index.d.ts
6
+ interface WorldstateEmitterOptions {
7
+ locale?: string;
8
+ features?: string[];
9
+ }
10
+ interface RssFeedItem {
11
+ url: string;
12
+ items: RSSItem[];
13
+ }
14
+ interface DebugInfo {
15
+ rss?: RssFeedItem[];
16
+ worldstate?: WorldState;
17
+ twitter?: unknown;
18
+ }
19
+ declare class WorldstateEmitter extends EventEmitter {
20
+ #private;
21
+ static make({
22
+ locale,
23
+ features
24
+ }?: WorldstateEmitterOptions): Promise<WorldstateEmitter>;
25
+ /**
26
+ * Pull in and instantiate emitters
27
+ * @param options - Configuration options
28
+ */
29
+ constructor({
30
+ locale
31
+ }?: WorldstateEmitterOptions);
32
+ /**
33
+ * Set up internal logging
34
+ * @private
35
+ */
36
+ private setupLogging;
37
+ /**
38
+ * Get current rss feed items
39
+ * @returns RSS feed items
40
+ */
41
+ getRss(): RssFeedItem[] | undefined;
42
+ /**
43
+ * Get a specific worldstate, defaulting to 'pc' for the platform and 'en' for the language
44
+ * @param language - locale/language to fetch
45
+ * @returns Requested worldstate
46
+ */
47
+ getWorldstate(language?: string): WorldState | undefined;
48
+ get debug(): DebugInfo;
49
+ /**
50
+ * Get Twitter data
51
+ * @returns Promised twitter data
52
+ */
53
+ getTwitter(): Promise<unknown>;
54
+ }
55
+ //#endregion
56
+ export { WorldstateEmitter as default };