faye-redis-ng 1.0.2 → 1.1.1

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/NPM_PUBLISH.md DELETED
@@ -1,358 +0,0 @@
1
- # NPM Publishing Guide for faye-redis-ng
2
-
3
- This guide will help you publish `faye-redis-ng` to npm.
4
-
5
- ## 🤖 Automated Publishing with Trusted Publishing (Recommended)
6
-
7
- This project uses **GitHub Actions** with **Trusted Publishing (OIDC)** - the modern, secure way to publish to npm. No tokens needed!
8
-
9
- ### 🔒 Why Trusted Publishing?
10
-
11
- **Traditional method** ❌:
12
- - Create npm token
13
- - Store in GitHub Secrets
14
- - Risk of token leakage
15
- - Manual token rotation
16
-
17
- **Trusted Publishing** ✅:
18
- - Zero tokens to manage
19
- - GitHub authenticates directly with npm
20
- - More secure (OIDC protocol)
21
- - Recommended by npm
22
-
23
- ### Quick Start
24
-
25
- **Step 1**: First manual publish (once)
26
- ```bash
27
- npm login
28
- npm publish --access public
29
- ```
30
-
31
- **Step 2**: Configure on npm
32
- 1. Go to https://www.npmjs.com/package/faye-redis-ng/settings
33
- 2. Publishing access → Add trusted publisher
34
- 3. Provider: **GitHub Actions**
35
- 4. Repository: **YOUR-USERNAME/faye-redis-ng**
36
- 5. Workflow: **publish.yml**
37
-
38
- **Step 3**: Push tags
39
- ```bash
40
- git tag v1.0.1 && git push origin v1.0.1
41
- ```
42
-
43
- **Done!** 🎉 Fully automated, zero secrets.
44
-
45
- **See `.github/SETUP.md` for detailed setup instructions.**
46
-
47
- ---
48
-
49
- ## 📦 Manual Publishing (Alternative)
50
-
51
- If you prefer manual control or need to publish without automation:
52
-
53
- ## Pre-Publishing Checklist
54
-
55
- ### 1. Verify Package Information
56
-
57
- - ✅ Package name: `faye-redis-ng`
58
- - ✅ Version: `1.0.0` (starting fresh for NG version)
59
- - ✅ Description updated
60
- - ✅ Keywords added for discoverability
61
- - ✅ License: MIT (same as original)
62
- - ✅ Repository URL (update when you create your fork)
63
-
64
- ### 2. Prepare Your Repository
65
-
66
- **Important**: Update the repository URL in `package.json` to point to YOUR fork:
67
-
68
- ```json
69
- {
70
- "repository": {
71
- "type": "git",
72
- "url": "https://github.com/YOUR-USERNAME/faye-redis-ng.git"
73
- },
74
- "homepage": "https://github.com/YOUR-USERNAME/faye-redis-ng",
75
- "bugs": "https://github.com/YOUR-USERNAME/faye-redis-ng/issues"
76
- }
77
- ```
78
-
79
- ### 3. Files to Include/Exclude
80
-
81
- Create or update `.npmignore`:
82
-
83
- ```
84
- # Development files
85
- spec/
86
- vendor/
87
- test-*.js
88
- .git/
89
- .gitmodules
90
- *.rdb
91
-
92
- # Documentation (keep these)
93
- !README.md
94
- !CLAUDE.md
95
- !REFACTORING.md
96
- !CHANGELOG.md
97
- !LICENSE
98
- ```
99
-
100
- Or use `files` field in package.json (recommended):
101
-
102
- ```json
103
- {
104
- "files": [
105
- "faye-redis.js",
106
- "README.md",
107
- "CLAUDE.md",
108
- "REFACTORING.md",
109
- "LICENSE"
110
- ]
111
- }
112
- ```
113
-
114
- ### 4. Create Essential Files
115
-
116
- **LICENSE** (if not exists):
117
- ```
118
- MIT License
119
-
120
- Copyright (c) 2011-2013 James Coglan (original faye-redis)
121
- Copyright (c) 2026-present Community Contributors (faye-redis-ng)
122
-
123
- Permission is hereby granted, free of charge, to any person obtaining a copy
124
- of this software and associated documentation files (the "Software"), to deal
125
- in the Software without restriction, including without limitation the rights
126
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
127
- copies of the Software, and to permit persons to whom the Software is
128
- furnished to do so, subject to the following conditions:
129
-
130
- The above copyright notice and this permission notice shall be included in all
131
- copies or substantial portions of the Software.
132
-
133
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
134
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
135
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
136
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
137
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
138
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
139
- SOFTWARE.
140
- ```
141
-
142
- **CHANGELOG.md**:
143
- ```markdown
144
- # Changelog
145
-
146
- All notable changes to faye-redis-ng will be documented in this file.
147
-
148
- ## [1.0.0] - 2026-01-07
149
-
150
- ### Added
151
- - Initial release of faye-redis-ng (Next Generation fork)
152
- - Redis v4 support with Promise-based API
153
- - Automatic reconnection with exponential backoff
154
- - ES6+ class syntax and modern JavaScript features
155
- - Comprehensive error handling and logging
156
- - Auto re-subscribe after reconnection
157
- - Better documentation and examples
158
-
159
- ### Changed
160
- - Upgraded from callback-based to async/await internally
161
- - Updated from prototype-based to ES6 class
162
- - Node.js requirement: >=14.0.0 (was >=0.4.0)
163
- - All Redis commands updated to v4 API
164
-
165
- ### Improved
166
- - Production-ready reconnection handling
167
- - Better error messages and debugging
168
- - Updated dependencies to latest versions
169
- - Modernized codebase while maintaining backward compatibility
170
-
171
- ### Migration
172
- - Drop-in replacement for original faye-redis
173
- - No breaking changes to public API
174
- - Simply replace `require('faye-redis')` with `require('faye-redis-ng')`
175
-
176
- ## Original faye-redis
177
-
178
- This project is a modernized fork of [faye-redis](https://github.com/faye/faye-redis-node) by James Coglan.
179
- ```
180
-
181
- ## Publishing Steps
182
-
183
- ### Step 1: Create npm Account (if you don't have one)
184
-
185
- ```bash
186
- npm adduser
187
- # or
188
- npm login
189
- ```
190
-
191
- ### Step 2: Test Package Locally
192
-
193
- ```bash
194
- # Test installation locally
195
- npm pack
196
-
197
- # This creates faye-redis-ng-1.0.0.tgz
198
- # Test it in another project:
199
- cd /path/to/test-project
200
- npm install /path/to/faye-redis-ng-1.0.0.tgz
201
- ```
202
-
203
- ### Step 3: Verify Package Contents
204
-
205
- ```bash
206
- # Check what will be published
207
- npm publish --dry-run
208
-
209
- # Review the output carefully
210
- ```
211
-
212
- ### Step 4: Run Final Checks
213
-
214
- ```bash
215
- # Lint package.json
216
- npm install -g npm-package-json-lint
217
- npmPkgJsonLint .
218
-
219
- # Or manually verify:
220
- # - All dependencies are correct versions
221
- # - No sensitive information in any files
222
- # - README is complete
223
- # - Version number is correct
224
- ```
225
-
226
- ### Step 5: Publish to npm
227
-
228
- ```bash
229
- # Publish to npm (public)
230
- npm publish --access public
231
-
232
- # If you want to test first, publish to a scoped package:
233
- # npm publish --access public --tag beta
234
- ```
235
-
236
- ### Step 6: Verify Publication
237
-
238
- ```bash
239
- # Check on npm
240
- npm view faye-redis-ng
241
-
242
- # Install and test
243
- npm install faye-redis-ng
244
- ```
245
-
246
- ## Post-Publishing
247
-
248
- ### 1. Create Git Tag
249
-
250
- ```bash
251
- git tag v1.0.0
252
- git push origin v1.0.0
253
- ```
254
-
255
- ### 2. Create GitHub Release
256
-
257
- Go to your GitHub repository and create a release:
258
- - Tag: `v1.0.0`
259
- - Title: `v1.0.0 - Initial Release`
260
- - Description: Copy from CHANGELOG.md
261
-
262
- ### 3. Update Documentation
263
-
264
- - Add badges to README.md with actual npm package link
265
- - Update homepage URL if needed
266
-
267
- ### 4. Announce
268
-
269
- Consider announcing on:
270
- - Twitter/X
271
- - Reddit (r/node, r/javascript)
272
- - Hacker News
273
- - Dev.to
274
-
275
- ## Version Management
276
-
277
- ### Semantic Versioning
278
-
279
- Follow [semver](https://semver.org/):
280
-
281
- - **MAJOR**: Breaking changes (2.0.0)
282
- - **MINOR**: New features, backward compatible (1.1.0)
283
- - **PATCH**: Bug fixes, backward compatible (1.0.1)
284
-
285
- ### Publishing Updates
286
-
287
- ```bash
288
- # For patches (bug fixes)
289
- npm version patch
290
- npm publish
291
-
292
- # For minor (new features)
293
- npm version minor
294
- npm publish
295
-
296
- # For major (breaking changes)
297
- npm version major
298
- npm publish
299
- ```
300
-
301
- ## Troubleshooting
302
-
303
- ### Package Name Already Taken
304
-
305
- If `faye-redis-ng` is taken, consider:
306
- - `@yourscope/faye-redis-ng`
307
- - `faye-redis-modern`
308
- - `faye-redis-v4`
309
- - `faye-redis-next`
310
-
311
- ### Can't Publish
312
-
313
- Common issues:
314
- 1. **Not logged in**: Run `npm login`
315
- 2. **Name conflict**: Choose different name
316
- 3. **Version exists**: Bump version with `npm version patch`
317
- 4. **Email not verified**: Check npm email verification
318
-
319
- ## Security
320
-
321
- ### Before Publishing
322
-
323
- - ✅ No API keys or secrets in code
324
- - ✅ No .env files included
325
- - ✅ Dependencies are from trusted sources
326
- - ✅ Run `npm audit` and fix vulnerabilities
327
-
328
- ```bash
329
- npm audit
330
- npm audit fix
331
- ```
332
-
333
- ### After Publishing
334
-
335
- Set up:
336
- - GitHub security alerts
337
- - Dependabot
338
- - npm 2FA for publishing
339
-
340
- ## Maintenance
341
-
342
- ### Keeping Updated
343
-
344
- 1. Monitor dependencies: `npm outdated`
345
- 2. Update dependencies regularly
346
- 3. Test before publishing updates
347
- 4. Keep CHANGELOG.md updated
348
- 5. Respond to issues and PRs
349
-
350
- ## Questions?
351
-
352
- - npm documentation: https://docs.npmjs.com/
353
- - Semantic versioning: https://semver.org/
354
- - Package.json docs: https://docs.npmjs.com/cli/v10/configuring-npm/package-json
355
-
356
- ---
357
-
358
- **Good luck with your first publish! 🚀**
package/REFACTORING.md DELETED
@@ -1,215 +0,0 @@
1
- # Modernization & Refactoring Summary
2
-
3
- This document summarizes the modernization work performed on the faye-redis codebase in January 2026.
4
-
5
- ## Overview
6
-
7
- The codebase was originally written for Node.js 0.4+ and used outdated patterns and dependencies. It has been fully modernized while maintaining backward compatibility with the Faye engine interface.
8
-
9
- ## Changes Made
10
-
11
- ### 1. Dependencies Upgraded
12
-
13
- **package.json** changes:
14
- - `redis`: `""` → `"^4.7.0"` (major upgrade to Promise-based API)
15
- - `jstest`: `""` → `"^1.0.5"` (version pinned)
16
- - Node.js requirement: `">=0.4.0"` → `">=22.0.0"` (LTS)
17
-
18
- **Other fixes**:
19
- - `.gitmodules`: Changed from `git://` to `https://` protocol (fixes firewall issues)
20
-
21
- ### 2. Code Modernization
22
-
23
- **faye-redis.js** - Complete rewrite with modern JavaScript:
24
-
25
- #### Before (Old Style):
26
- ```javascript
27
- var Engine = function(server, options) {
28
- this._server = server;
29
- this._options = options || {};
30
- var redis = require('redis');
31
- var host = this._options.host || this.DEFAULT_HOST;
32
- // ... prototype-based class
33
- };
34
-
35
- Engine.prototype = {
36
- DEFAULT_HOST: 'localhost',
37
- createClient: function(callback, context) {
38
- var self = this;
39
- this._redis.zadd(this._ns + '/clients', 0, clientId, function(error, added) {
40
- // callback hell
41
- });
42
- }
43
- };
44
- ```
45
-
46
- #### After (Modern Style):
47
- ```javascript
48
- const redis = require('redis');
49
-
50
- class Engine {
51
- constructor(server, options = {}) {
52
- this._server = server;
53
- this._options = options;
54
- // ES6 class with async initialization
55
- }
56
-
57
- async _initializeClients() {
58
- const clientConfig = {
59
- database: db,
60
- ...(auth && { password: auth }),
61
- };
62
- this._redis = redis.createClient(clientConfig);
63
- await this._redis.connect();
64
- }
65
-
66
- createClient(callback, context) {
67
- this._waitForInit().then(async () => {
68
- const added = await this._redis.zAdd(this._ns + '/clients', {
69
- score: 0,
70
- value: clientId
71
- }, { NX: true });
72
- // Clean async/await internally, callback externally
73
- });
74
- }
75
- }
76
-
77
- Engine.prototype.DEFAULT_HOST = 'localhost';
78
- ```
79
-
80
- #### Specific Improvements:
81
- - ✅ `var` → `const`/`let` throughout
82
- - ✅ Prototype-based class → ES6 `class`
83
- - ✅ Callbacks → async/await (internal)
84
- - ✅ Arrow functions for cleaner code
85
- - ✅ Spread operators for configuration
86
- - ✅ Async initialization pattern
87
-
88
- ### 3. Redis v4 API Migration
89
-
90
- Major API changes from old callback-based redis to modern Promise-based redis v4:
91
-
92
- | Old API (v0.x) | New API (v4.x) |
93
- |----------------|----------------|
94
- | `redis.createClient(port, host, options)` | `redis.createClient({ socket: { host, port }, ... })` |
95
- | `client.auth(password)` | Config: `{ password: ... }` |
96
- | `client.zadd(key, score, value, cb)` | `await client.zAdd(key, { score, value })` |
97
- | `client.zscore(key, value, cb)` | `await client.zScore(key, value)` |
98
- | `client.smembers(key, cb)` | `await client.sMembers(key)` |
99
- | `client.getset(key, val, cb)` | `await client.set(key, val, { GET: true })` |
100
- | `client.end()` | `await client.quit()` |
101
- | No connect needed | `await client.connect()` required |
102
-
103
- ### 4. Test Files Updated
104
-
105
- **spec/faye_redis_spec.js**:
106
- - Updated to use `const` instead of `var`
107
- - Migrated Redis client creation to v4 API
108
- - Changed `.auth()` to config-based authentication
109
- - Updated `.flushall(callback)` → `.flushAll()` (Promise-based)
110
- - Updated `.end()` → `.quit()`
111
-
112
- ### 5. Architecture Improvements
113
-
114
- **New async initialization pattern**:
115
- - Redis clients initialize asynchronously in constructor
116
- - `_waitForInit()` method ensures clients are ready before operations
117
- - Maintains callback-based external API for Faye compatibility
118
- - Internal operations use clean async/await
119
-
120
- **Error handling & Reconnection**:
121
- - Added try-catch error logging for all async operations
122
- - Graceful handling of connection errors
123
- - **Automatic reconnection**: Exponential backoff strategy with max 20 retries
124
- - **Re-subscribe on reconnect**: Pub/sub channels automatically re-subscribed
125
- - **Error events**: Connection errors triggered to Faye server
126
- - **Connection state tracking**: `_initialized` flag prevents operations during reconnection
127
-
128
- ## Backward Compatibility
129
-
130
- ✅ **External API unchanged** - All public methods maintain the same callback-based signatures expected by Faye
131
-
132
- ✅ **Configuration compatible** - All existing configuration options work the same way
133
-
134
- ✅ **Redis data model unchanged** - Same keys, data structures, and protocols
135
-
136
- ## Testing Status
137
-
138
- ✅ **Syntax validation passed** - Code loads without errors
139
- ✅ **Module structure verified** - ES6 class exports correctly
140
- ✅ **API compatibility maintained** - Public interface unchanged
141
-
142
- ⚠️ **Full integration tests require**:
143
- 1. Redis server running (not available in current environment)
144
- 2. Faye vendor submodule build (requires fixing old build tool compatibility with Node.js 24)
145
-
146
- ## Files Modified
147
-
148
- 1. `package.json` - Dependencies and Node version updated
149
- 2. `faye-redis.js` - Complete modernization to ES6+ and Redis v4
150
- 3. `spec/faye_redis_spec.js` - Test updates for Redis v4 API
151
- 4. `.gitmodules` - Protocol change to HTTPS
152
- 5. `CLAUDE.md` - Documentation updated with modernization notes
153
- 6. `REFACTORING.md` - This summary (new file)
154
- 7. `test-syntax.js` - Syntax validation script (new file)
155
-
156
- ## Migration Guide for Users
157
-
158
- If you're upgrading from the old version:
159
-
160
- 1. **Update Node.js**: Ensure you have Node.js >= 22.0.0 (LTS)
161
- 2. **Install dependencies**: Run `npm install` to get Redis v4
162
- 3. **No code changes needed**: Your Faye configuration remains the same
163
- 4. **Redis v4 benefits**: Better performance, modern Promise API, improved error handling
164
-
165
- ## Reconnection Mechanism (New Feature)
166
-
167
- The modernized code includes production-ready reconnection handling that was missing in the original:
168
-
169
- ### How It Works
170
-
171
- ```javascript
172
- // Reconnection strategy with exponential backoff
173
- _reconnectStrategy(retries) {
174
- if (retries > 20) {
175
- return new Error('Max reconnection attempts reached');
176
- }
177
- const delay = Math.min(retries * 100, 10000);
178
- return delay; // 100ms, 200ms, 300ms ... up to 10s
179
- }
180
- ```
181
-
182
- ### Event Handlers
183
-
184
- 1. **`error` event**: Logs errors and notifies Faye server
185
- 2. **`reconnecting` event**: Sets `_initialized = false` to pause operations
186
- 3. **`ready` event**: Re-subscribes to pub/sub channels and sets `_initialized = true`
187
-
188
- ### Protection During Reconnection
189
-
190
- All operations use `_waitForInit()` to ensure Redis is ready:
191
- ```javascript
192
- async _waitForInit() {
193
- while (!this._initialized) {
194
- await new Promise(resolve => setTimeout(resolve, 10));
195
- }
196
- }
197
- ```
198
-
199
- This prevents operations from failing during reconnection and automatically resumes when connection is restored.
200
-
201
- ## Next Steps (Optional Future Work)
202
-
203
- - Add TypeScript definitions for better IDE support
204
- - Replace jstest with modern testing framework (Jest/Mocha)
205
- - Add ESLint configuration for code quality
206
- - Add CI/CD with GitHub Actions
207
- - Update Faye vendor submodule to newer version (if available)
208
- - Add metrics/monitoring for reconnection events
209
-
210
- ---
211
-
212
- **Refactored by**: Claude Code
213
- **Date**: January 2026
214
- **Redis version**: 4.7.0
215
- **Node.js target**: >= 22.0.0 (LTS)