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/AUTOMATION.md DELETED
@@ -1,256 +0,0 @@
1
- # Automation Setup Complete! 🤖
2
-
3
- ## ✅ What's Been Set Up
4
-
5
- Your repository now has **fully automated publishing** via GitHub Actions!
6
-
7
- ### 📁 New Files Created
8
-
9
- ```
10
- .github/
11
- ├── workflows/
12
- │ ├── ci.yml # Run tests on every push/PR
13
- │ └── publish.yml # Auto-publish on git tags
14
- ├── SETUP.md # Detailed setup instructions
15
- └── RELEASE.md # Quick release guide
16
- ```
17
-
18
- ### 🔄 Automated Workflows
19
-
20
- #### 1. CI Workflow (Continuous Integration)
21
-
22
- **Triggers**: Every push to main/master/develop branches, and all PRs
23
-
24
- **What it does**:
25
- - ✅ Tests with Node.js 22
26
- - ✅ Spins up Redis service
27
- - ✅ Runs syntax checks
28
- - ✅ Runs integration tests
29
- - ✅ Verifies package can be built
30
-
31
- **Status**: Check at https://github.com/YOUR-USERNAME/faye-redis-ng/actions
32
-
33
- #### 2. Publish Workflow (Auto-Deploy)
34
-
35
- **Triggers**: When you push a version tag (e.g., `v1.0.1`)
36
-
37
- **What it does**:
38
- 1. ✅ Verifies tag matches package.json version
39
- 2. ✅ Runs all tests
40
- 3. ✅ Publishes to npm with provenance
41
- 4. ✅ Extracts changelog for this version
42
- 5. ✅ Creates GitHub Release
43
- 6. ✅ Uploads package tarball
44
-
45
- **Status**: Automatic on tag push
46
-
47
- ## 🚀 How to Use (3 Steps!)
48
-
49
- ### Step 1: One-Time Setup (5 minutes) - Trusted Publishing
50
-
51
- This project uses **Trusted Publishing (OIDC)** - the modern, secure way to publish to npm. No tokens needed!
52
-
53
- #### A. First Publish (Manual, Once)
54
-
55
- ```bash
56
- # Login to npm
57
- npm login
58
-
59
- # Publish first version manually
60
- npm publish --access public
61
- ```
62
-
63
- #### B. Configure Trusted Publishing on npm
64
-
65
- 1. Go to https://www.npmjs.com/package/faye-redis-ng
66
- 2. Click **Settings** → **Publishing access**
67
- 3. Click **Add trusted publisher**
68
- 4. Fill in:
69
- - Provider: **GitHub Actions**
70
- - Repository owner: **YOUR-GITHUB-USERNAME**
71
- - Repository name: **faye-redis-ng**
72
- - Workflow name: **publish.yml**
73
- 5. Click **Add**
74
-
75
- **Done!** No tokens, no secrets, fully automated and secure.
76
-
77
- ### Step 2: Make Changes
78
-
79
- Work on your code as usual:
80
-
81
- ```bash
82
- git add .
83
- git commit -m "Fix bug in client reconnection"
84
- ```
85
-
86
- ### Step 3: Release!
87
-
88
- When ready to publish:
89
-
90
- ```bash
91
- # For bug fixes (1.0.1 → 1.0.2)
92
- npm version patch -m "Fix: description"
93
-
94
- # For new features (1.0.1 → 1.1.0)
95
- npm version minor -m "Feature: description"
96
-
97
- # For breaking changes (1.0.1 → 2.0.0)
98
- npm version major -m "Breaking: description"
99
-
100
- # Push everything
101
- git push origin master --follow-tags
102
- ```
103
-
104
- **That's it!** GitHub Actions takes over and:
105
- - Runs all tests
106
- - Publishes to npm
107
- - Creates GitHub Release
108
- - Posts success notification
109
-
110
- ## 📊 Monitoring
111
-
112
- ### Check CI Status
113
-
114
- Every push shows status:
115
- - ✅ Green check = All tests passed
116
- - ❌ Red X = Tests failed
117
- - 🟡 Yellow = Running
118
-
119
- View details: https://github.com/YOUR-USERNAME/faye-redis-ng/actions
120
-
121
- ### Check Published Version
122
-
123
- After releasing:
124
- 1. **npm**: https://www.npmjs.com/package/faye-redis-ng
125
- 2. **GitHub Releases**: https://github.com/YOUR-USERNAME/faye-redis-ng/releases
126
-
127
- ## 🎯 Example: First Release (v1.0.1)
128
-
129
- ```bash
130
- # 1. Ensure everything is committed
131
- git status # Should be clean
132
-
133
- # 2. Create release
134
- git tag v1.0.1
135
- git push origin master
136
- git push origin v1.0.1
137
-
138
- # 3. Watch automation (optional)
139
- # Go to: https://github.com/YOUR-USERNAME/faye-redis-ng/actions
140
- # Watch the "Publish to npm" workflow run
141
-
142
- # 4. Verify (after 1-2 minutes)
143
- npm view faye-redis-ng
144
- # Should show version 1.0.1
145
- ```
146
-
147
- ## 🔒 Security Features
148
-
149
- Your automation includes:
150
-
151
- - ✅ **Trusted Publishing (OIDC)**: No tokens to manage or leak
152
- - ✅ **npm Provenance**: Cryptographic proof of where package was built
153
- - ✅ **Zero Secrets**: GitHub authenticates directly with npm
154
- - ✅ **Version Verification**: Prevents publishing wrong versions
155
- - ✅ **Automated Testing**: Every release is tested first
156
- - ✅ **Minimal Permissions**: Only specific workflow can publish
157
-
158
- ## 📋 Quick Reference
159
-
160
- ### Common Commands
161
-
162
- ```bash
163
- # Check CI status locally
164
- npm test
165
-
166
- # Preview what will be published
167
- npm pack --dry-run
168
-
169
- # Create patch release
170
- npm version patch && git push origin master --follow-tags
171
-
172
- # Create minor release
173
- npm version minor && git push origin master --follow-tags
174
-
175
- # Create major release
176
- npm version major && git push origin master --follow-tags
177
- ```
178
-
179
- ### Troubleshooting
180
-
181
- | Problem | Solution |
182
- |---------|----------|
183
- | Workflow didn't trigger | Check tag starts with `v` (v1.0.1) |
184
- | npm publish 403 error | Verify trusted publisher configured on npm |
185
- | Tests failed | Fix tests, push new commit, re-tag |
186
- | Version already exists | Bump version again |
187
- | First publish fails | Do manual `npm publish` first, then configure trusted publishing |
188
-
189
- ## 📚 Documentation
190
-
191
- - **Full Setup Guide**: `.github/SETUP.md`
192
- - **Quick Release**: `.github/RELEASE.md`
193
- - **CI Workflow**: `.github/workflows/ci.yml`
194
- - **Publish Workflow**: `.github/workflows/publish.yml`
195
-
196
- ## 🎉 Benefits
197
-
198
- **Before automation (manual)**:
199
- 1. Run tests manually
200
- 2. `npm login`
201
- 3. `npm publish`
202
- 4. Create GitHub release manually
203
- 5. Write release notes
204
- 6. Upload files
205
- 7. Hope nothing breaks
206
-
207
- **With automation + Trusted Publishing**:
208
- 1. `git push origin v1.0.1`
209
- 2. ☕ Coffee break
210
- 3. ✅ Done!
211
-
212
- **No tokens to manage, no secrets to worry about, fully automated!**
213
-
214
- ## ⚡ Advanced Features
215
-
216
- ### Branch Protection (Optional)
217
-
218
- Protect your main branch:
219
- 1. Settings → Branches → Add rule
220
- 2. Branch name: `master`
221
- 3. Enable: "Require status checks to pass"
222
- 4. Select: "test" and "lint"
223
- 5. Save
224
-
225
- Now all PRs must pass tests before merging!
226
-
227
- ### Auto-versioning (Optional)
228
-
229
- Add to `package.json`:
230
- ```json
231
- {
232
- "scripts": {
233
- "release:patch": "npm version patch && git push --follow-tags",
234
- "release:minor": "npm version minor && git push --follow-tags",
235
- "release:major": "npm version major && git push --follow-tags"
236
- }
237
- }
238
- ```
239
-
240
- Then just: `npm run release:patch`
241
-
242
- ## 🆘 Need Help?
243
-
244
- 1. Check `.github/SETUP.md` for detailed instructions
245
- 2. Review workflow logs in Actions tab
246
- 3. Verify trusted publisher is configured on npm
247
- 4. Check package.json version matches tag
248
- 5. Ensure first manual publish is done before automation
249
-
250
- ---
251
-
252
- **Automation setup by**: Claude Code
253
- **Date**: January 2026
254
- **Ready to publish**: YES! 🚀
255
-
256
- **Next step**: Follow "Step 1: One-Time Setup" above, then push your first tag!
package/CHANGELOG.md DELETED
@@ -1,98 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to faye-redis-ng will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [1.0.1] - 2026-01-07
9
-
10
- ### Fixed
11
- - **Critical**: Fixed `clientExists` method parameter order from `(callback, context, clientId)` to `(clientId, callback, context)` to match original faye-redis API
12
- - This was causing "Invalid argument type" errors in Redis operations
13
- - Also fixed internal call in `publish` method to use correct parameter order
14
-
15
- ### Changed
16
- - **Node.js requirement**: Updated from `>=14.0.0` to `>=22.0.0` (LTS)
17
- - Now requires Node.js 22 LTS for long-term support and modern features
18
-
19
- ## [1.0.0] - 2026-01-07
20
-
21
- ### 🎉 Initial Release of faye-redis-ng
22
-
23
- This is the first release of **faye-redis-ng** (Next Generation), a modern fork of the original faye-redis with significant improvements while maintaining 100% backward compatibility.
24
-
25
- ### Added
26
- - **Redis v4 support** with modern Promise-based API
27
- - **Automatic reconnection** with exponential backoff strategy
28
- - Retries with delays: 100ms, 200ms, 300ms ... up to 10s
29
- - Max 20 retries (~2 minutes) before giving up
30
- - Auto re-subscribe to pub/sub channels after reconnection
31
- - **ES6+ class syntax** replacing prototype-based patterns
32
- - **Comprehensive error handling** with error event triggers
33
- - **Connection state tracking** via `_initialized` flag
34
- - **Modern JavaScript features**: const/let, arrow functions, async/await, spread operators
35
- - **Better logging** for debugging and monitoring
36
- - **Integration tests** independent of Faye vendor submodule
37
- - **Comprehensive documentation**: README, CLAUDE.md, REFACTORING.md, NPM_PUBLISH.md
38
-
39
- ### Changed
40
- - **Package name**: `faye-redis` → `faye-redis-ng`
41
- - **Version**: Starting at 1.0.0 for NG fork
42
- - **Node.js requirement**: `>=0.4.0` → `>=22.0.0` (LTS)
43
- - **Redis client**: Upgraded to v4 Promise-based API
44
- - **Code structure**: Prototype-based → ES6 class
45
- - **Internal implementation**: Callbacks → async/await
46
-
47
- ### Improved
48
- - Production-ready reliability with automatic reconnection
49
- - Better error messages with contextual information
50
- - Code maintainability with modern JavaScript patterns
51
- - Testing with standalone integration test suite
52
-
53
- ### Fixed
54
- - Git submodule URL changed from `git://` to `https://`
55
- - Deprecated `getset` command replaced with modern API
56
- - Connection loss scenarios now handled gracefully
57
-
58
- ### Migration from Original faye-redis
59
-
60
- **Drop-in replacement** - just update package name:
61
-
62
- ```bash
63
- npm uninstall faye-redis
64
- npm install faye-redis-ng
65
- ```
66
-
67
- Change require statement:
68
- ```javascript
69
- const redis = require('faye-redis-ng');
70
- ```
71
-
72
- That's it! No other changes needed.
73
-
74
- ---
75
-
76
- ## Original faye-redis History
77
-
78
- Below is the changelog from the original [faye-redis](https://github.com/faye/faye-redis-node) project by James Coglan.
79
-
80
- ### 0.2.0 / 2013-10-01
81
-
82
- * Trigger the `close` event as required by Faye 1.0
83
-
84
- ### 0.1.3 / 2013-05-11
85
-
86
- * Fix a bug due to a misuse of `this`
87
-
88
- ### 0.1.2 / 2013-04-28
89
-
90
- * Improve garbage collection to avoid leaking Redis memory
91
-
92
- ### 0.1.1 / 2012-07-15
93
-
94
- * Fix an implicit global variable leak (missing semicolon)
95
-
96
- ### 0.1.0 / 2012-02-26
97
-
98
- * Initial release: Redis backend for Faye 0.8
package/CLAUDE.md DELETED
@@ -1,134 +0,0 @@
1
- # CLAUDE.md
2
-
3
- This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
-
5
- ## Project Overview
6
-
7
- faye-redis is a Redis-based backend engine for the Faye messaging server. It enables distributing a single Faye service across multiple front-end web servers by storing state and routing messages through Redis. The engine implements the Faye engine interface and manages client connections, subscriptions, message queuing, and pub/sub through Redis.
8
-
9
- ## Development Setup
10
-
11
- ```bash
12
- # Initialize git submodules and prepare dependencies (required for first-time setup)
13
- make prepare
14
-
15
- # Install dependencies only
16
- npm install
17
- ```
18
-
19
- The project depends on the Faye library as a git submodule in `vendor/faye`. The Makefile's `prepare` target initializes this submodule, installs Faye's dependencies, and builds Faye before installing this project's dependencies.
20
-
21
- **Note**: The codebase has been modernized (January 2026) to use ES6+ syntax and Redis v4 API. Node.js >= 22.0.0 (LTS) is now required.
22
-
23
- ## Running Tests
24
-
25
- ```bash
26
- # Run all tests
27
- npm test
28
- # or
29
- node spec/runner.js
30
- ```
31
-
32
- Tests require a Redis server. The test suite:
33
- - Uses the jstest framework
34
- - Imports shared engine specs from the Faye submodule (`vendor/faye/spec/javascript/engine_spec`)
35
- - Tests both regular Redis connections and Unix socket connections
36
- - Uses password "foobared" for local testing (no password in CI/Travis)
37
- - Creates unique namespaces per test run using timestamps to avoid conflicts
38
-
39
- For local development, Redis should be configured with `requirepass foobared` (see `spec/redis.conf` for reference configuration).
40
-
41
- ## Architecture
42
-
43
- ### Core Engine (faye-redis.js)
44
-
45
- The Engine is the main class that implements the Faye engine interface:
46
-
47
- - **Initialization**: Creates two Redis connections - one for commands (`_redis`) and one for pub/sub subscriptions (`_subscriber`)
48
- - **Connection Management**: Supports both TCP connections (host/port) and Unix socket connections
49
- - **Namespace Support**: All Redis keys are prefixed with an optional namespace to allow multiple Faye instances to share one Redis database
50
-
51
- ### Data Model in Redis
52
-
53
- - **Clients**: Stored as sorted set at `{namespace}/clients` with scores as last-ping timestamps (used for garbage collection)
54
- - **Client Subscriptions**: Set at `{namespace}/clients/{clientId}/channels` containing channel names
55
- - **Channel Subscribers**: Set at `{namespace}/channels{channelName}` containing client IDs
56
- - **Message Queues**: List at `{namespace}/clients/{clientId}/messages` containing JSON-serialized messages
57
- - **Locks**: Keys at `{namespace}/locks/{lockName}` for distributed locking (used by GC)
58
- - **Pub/Sub Channels**:
59
- - `{namespace}/notifications/messages` - notifies when new messages are queued for a client
60
- - `{namespace}/notifications/close` - notifies when a client disconnects
61
-
62
- ### Key Methods
63
-
64
- - `createClient()`: Generates unique client ID using server's `generateId()` and stores in Redis sorted set
65
- - `clientExists()`: Checks if client timestamp is recent (within 1.6 * server timeout)
66
- - `destroyClient()`: Removes client from all subscribed channels and deletes message queue
67
- - `ping()`: Updates client's timestamp in sorted set to keep connection alive
68
- - `subscribe()/unsubscribe()`: Manages client-channel membership in both directions (client's channels and channel's clients)
69
- - `publish()`: Finds all subscribers to given channels via `SUNION`, queues messages, and sends notifications
70
- - `emptyQueue()`: Delivers all queued messages for a client and clears the queue
71
- - `gc()`: Periodically removes stale clients (those not pinged within 2 * server timeout) using distributed lock
72
- - `_withLock()`: Implements distributed locking using Redis SETNX and GETSET with automatic expiry
73
-
74
- ### Event Flow
75
-
76
- 1. **Message Publishing**: Server calls `publish()` → finds subscribers via SUNION → queues message for each subscriber → publishes notification to message channel
77
- 2. **Message Delivery**: Subscriber receives notification → calls `emptyQueue()` → retrieves and delivers messages to client → deletes queue
78
- 3. **Garbage Collection**: Runs every 60 seconds (configurable) → acquires distributed lock → finds stale clients → destroys each one
79
-
80
- ## Configuration Options
81
-
82
- When integrating faye-redis as a Faye engine, these options are available:
83
-
84
- - `host`: Redis hostname (default: 'localhost')
85
- - `port`: Redis port (default: 6379)
86
- - `password`: Redis password for auth (default: none)
87
- - `database`: Redis database number (default: 0)
88
- - `namespace`: Key prefix for isolation (default: '')
89
- - `socket`: Unix socket path (alternative to host/port)
90
- - `gc`: Garbage collection interval in seconds (default: 60)
91
-
92
- ## Testing Notes
93
-
94
- - The TRAVIS environment variable disables Unix socket tests in CI
95
- - Tests create a unique namespace per run to avoid interference between test runs
96
- - Tests call `flushAll` after completion to clean up Redis (updated to Redis v4 API)
97
- - Shared behavior specs from Faye ensure engine compatibility
98
-
99
- ## Modernization Changes (2026)
100
-
101
- The codebase has been refactored with the following improvements:
102
-
103
- ### Code Modernization
104
- - **ES6 Class Syntax**: Converted from prototype-based to ES6 `class`
105
- - **const/let**: Replaced all `var` declarations with `const`/`let`
106
- - **Arrow Functions**: Used where appropriate for cleaner syntax
107
- - **Async/Await**: Internal Redis operations use async/await while maintaining callback-based external API for Faye compatibility
108
- - **Template Literals**: Used spread operators and modern JavaScript features
109
-
110
- ### Dependencies Updated
111
- - **redis**: Upgraded from unspecified to `^4.7.0` (Promise-based API)
112
- - **jstest**: Fixed to `^1.0.5`
113
- - **Node.js**: Minimum version requirement updated from `>=0.4.0` to `>=22.0.0` (LTS)
114
- - **Git submodules**: Updated from `git://` to `https://` protocol
115
-
116
- ### Redis v4 API Changes
117
- The engine now uses Redis v4's Promise-based API:
118
- - `createClient()` with configuration object instead of positional arguments
119
- - Methods return Promises (used with async/await internally)
120
- - Connection requires explicit `.connect()` call
121
- - Method names updated to camelCase (e.g., `zAdd`, `sMembers`, `rPush`)
122
- - Deprecated `getSet` replaced with `set(..., { GET: true })`
123
- - Authentication via config object instead of `.auth()` method
124
-
125
- ### Backward Compatibility
126
- The external API remains callback-based to maintain compatibility with Faye. Internal implementation uses async/await for cleaner code while wrapping results in callbacks for the Faye engine interface.
127
-
128
- ### Reconnection Handling
129
- The engine includes automatic Redis reconnection handling:
130
- - **Exponential backoff**: Retries with increasing delays (100ms, 200ms, ... up to 10s)
131
- - **Max retries**: 20 attempts (~2 minutes) before giving up
132
- - **Auto re-subscribe**: Pub/sub channels are automatically re-subscribed after reconnection
133
- - **Error events**: Connection errors are logged and triggered to the Faye server
134
- - **State tracking**: `_initialized` flag tracks connection readiness
@@ -1,4 +0,0 @@
1
- # Code of Conduct
2
-
3
- All projects under the [Faye](https://github.com/faye) umbrella are covered by
4
- the [Code of Conduct](https://github.com/faye/code-of-conduct).