Skip to content

Support Ably v2#50

Open
keithbrink wants to merge 1 commit into
ably-forks:masterfrom
keithbrink:master
Open

Support Ably v2#50
keithbrink wants to merge 1 commit into
ably-forks:masterfrom
keithbrink:master

Conversation

@keithbrink

@keithbrink keithbrink commented Jun 11, 2026

Copy link
Copy Markdown

Updates the Ably integration to require and work with ably@^2.0, including v2 type exports, promise-based realtime/presence/auth calls, and removal of ably/promises usage. Preserves the Echo channel API while handling Ably v2 clientId-change reconnects and presence operation failures correctly. Updates sandbox-backed tests to use the nonprod sandbox endpoint and documents the breaking dependency change in the Ably changelog.

Summary by CodeRabbit

  • Breaking Changes

    • Updated to Ably v2.x with dropped v1.x support
    • Transitioned Ably APIs from callback-based to promise-based patterns
    • Updated installation instructions accordingly
  • Improvements

    • Made callback parameters optional in presence and private channel methods for added flexibility

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR upgrades the laravel-echo codebase from Ably v1 to v2, converting all callback-based APIs to promise-based equivalents, updating the type system to reference top-level ably exports, converting imports to type-only for tree-shaking, and adjusting test configuration and assertions accordingly.

Changes

Ably v2 SDK upgrade

Layer / File(s) Summary
Dependencies and build tooling
.github/README.md, CHANGELOG-ABLY.md, package.json, rollup.config.js
Package dependencies upgraded to ably@^2.0, dev tooling added for @babel/preset-typescript and @rollup/plugin-node-resolve, Rollup configuration updated to include node-resolve plugin before TypeScript, and breaking changes documented.
Type system and import refactoring
typings/ably.ts, src/channel/ably-channel.ts, src/channel/ably-presence-channel.ts, src/channel/ably/utils.ts, src/channel/*.ts, src/connector/*.ts, src/echo.ts
Type aliases in typings/ably.ts updated to pull from top-level ably.* exports instead of ably.Types.* namespace. Runtime imports of Channel, PresenceChannel, AblyRealtime, and TokenDetails converted to type-only imports across all channel and connector modules for improved tree-shaking.
Channel lifecycle promise migration
src/channel/ably-channel.ts
subscribe() now calls channel.attach() with promise error routing to _alertErrorListeners; unsubscribe() calls channel.detach() with the same error handling; listen() and listenToAll() add .catch(this._alertErrorListeners) to subscription promises.
Presence operations promise migration
src/channel/ably-presence-channel.ts, src/channel/ably-private-channel.ts
Presence methods (here, joining, leaving, enter, leave, update, whisper) converted from callback-required signatures to promise-based API calls. Callbacks now optional; on success they receive null (or resolved value for here), on error they receive the error or it routes to _alertErrorListeners. Channel whisper method similarly converts to promise-based publishing.
Authorization and token flow
src/channel/ably/auth.ts
Timestamp generation changed to promise-based ablyClient.getTimestamp(), token expiry check uses ablyClient.getTimestampUsingOffset(), debug logging removed, and client ID change handler re-attaches all channels via setTimeout with error handling. tryAuthorizeOnSameConnection converted from callback-based auth.authorize to promise form.
HTTP request handling
src/channel/ably/utils.ts
httpRequest method rewritten to use promise-based doUri call with .then/.catch chaining, method lowercasing moved outside conditional, and callback now receives result.error and result.body from resolved promise.
Test configuration and async conversion
tests/ably/*.test.ts, tests/ably/setup/mock-auth-server.ts
Echo Ably client configurations changed from environment: 'sandbox' to endpoint: 'nonprod:sandbox' across all test files. Mock auth server constructor updated from environment parameter to endpoint. Callback-based tests converted to async/await, including HTTP mocking for header assertions. Error message assertions made case-insensitive and unused test helpers removed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hop along as Ably scales from one to two,
Promises replace callbacks through and through.
Type-only imports trim the build so light,
Sandbox endpoints shine with brand new sight.
Echo bounces higher, promises so bright! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The pull request title 'Support Ably v2' directly and clearly describes the main objective of the changeset: upgrading the Ably integration to support version 2.x.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@keithbrink keithbrink changed the title Support Ably v2 (#1) Support Ably v2 Jun 11, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@package.json`:
- Line 49: Update package.json's engines.node to match Ably v2's Node
requirement: change the "engines.node" value from ">=10" to ">=16" (or
">=16.0.0") so it aligns with the declared peerDependencies.ably "^2.0". Ensure
the updated engines.node entry is in package.json and run a quick install/test
to confirm no other engine constraints conflict.

In `@src/echo.ts`:
- Line 1: The current export incorrectly re-exports type-only imports as runtime
values; in src/echo.ts keep the existing import type { Channel, PresenceChannel
} and change the export to separate runtime and type exports—export { Connector
} (runtime) and export type { Channel, PresenceChannel } (types) so Channel and
PresenceChannel are only exported as types and not as values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 501ca499-dc1f-45d7-9eb3-5d2d7aaa6494

📥 Commits

Reviewing files that changed from the base of the PR and between 2c25f34 and 167b588.

📒 Files selected for processing (26)
  • .github/README.md
  • CHANGELOG-ABLY.md
  • package.json
  • rollup.config.js
  • src/channel/ably-channel.ts
  • src/channel/ably-presence-channel.ts
  • src/channel/ably-private-channel.ts
  • src/channel/ably/auth.ts
  • src/channel/ably/utils.ts
  • src/channel/null-presence-channel.ts
  • src/channel/presence-channel.ts
  • src/channel/pusher-presence-channel.ts
  • src/channel/socketio-presence-channel.ts
  • src/connector/ably-connector.ts
  • src/connector/connector.ts
  • src/connector/null-connector.ts
  • src/echo.ts
  • tests/ably/ably-channel.test.ts
  • tests/ably/ably-connection.test.ts
  • tests/ably/ably-presence-channel.test.ts
  • tests/ably/ably-private-channel.test.ts
  • tests/ably/ably-sandbox.test.ts
  • tests/ably/ably-user-login.test.ts
  • tests/ably/ably-user-rest-publishing.test.ts
  • tests/ably/setup/mock-auth-server.ts
  • typings/ably.ts

Comment thread package.json
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/parser": "^5.14.0",
"ably": "^1.2",
"ably": "^2.0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

python - <<'PY'
import json, urllib.request

with open("package.json", "r", encoding="utf-8") as f:
    pkg = json.load(f)

repo_engine = pkg.get("engines", {}).get("node")
ably_range = (
    pkg.get("peerDependencies", {}).get("ably")
    or pkg.get("devDependencies", {}).get("ably")
)

print("package.json engines.node:", repo_engine)
print("package.json ably range:", ably_range)

data = json.loads(
    urllib.request.urlopen("https://registry.npmjs.org/ably", timeout=20).read().decode("utf-8")
)

versions = sorted(
    [v for v in data.get("versions", {}) if v.startswith("2.")],
    key=lambda s: [int(x) for x in s.split(".")]
)

print("\nRecent ably 2.x versions and their engines:")
for v in versions[-10:]:
    eng = data["versions"][v].get("engines")
    print(f"{v}: {eng}")
PY

Repository: ably-forks/laravel-echo

Length of output: 2742


🏁 Script executed:

#!/bin/bash
set -euo pipefail
nl -ba package.json | sed -n '35,90p'

Repository: ably-forks/laravel-echo

Length of output: 110


🌐 Web query:

Ably JavaScript SDK v2 engines.node minimum Node version

💡 Result:

The Ably JavaScript SDK v2 requires a minimum Node.js version of 16 [1][2]. The engines.node field in the package.json for the SDK is set to >=16 [3]. While v2 was initially tested against Node.js versions 16, 18, and 20 [1][3], it remains compatible with Node.js 16 or greater [4].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== engines block =="
rg -n '"engines"\s*:' package.json || true
awk 'NR>=1 && NR<=120 {print NR ":" $0}' package.json | rg -n --context 0 '"engines"|"node"|\"ably\"' -n || true

echo
echo "== excerpt around ably entries =="
awk 'NR>=40 && NR<=90 {print NR ":" $0}' package.json | rg -n '"ably"|\"engines\"|\"node\"' || true

echo
echo "== parsed values =="
node -e "const pkg=require('./package.json'); console.log('engines.node=',pkg.engines?.node); console.log('ably=', pkg.peerDependencies?.ably || pkg.devDependencies?.ably || pkg.dependencies?.ably);"

Repository: ably-forks/laravel-echo

Length of output: 421


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== engines.node excerpt =="
awk 'NR>=55 && NR<=75 {print NR ":" $0}' package.json

echo
echo "== ably entries =="
rg -n '"ably"\s*:' package.json
rg -n '"ably"\s*:' package.json -n --context 2 || true

Repository: ably-forks/laravel-echo

Length of output: 843


🏁 Script executed:

#!/bin/bash
set -euo pipefail
# Fallback: print a slightly wider window for peer/dev deps
echo "== deps excerpt (40-90) =="
awk 'NR>=40 && NR<=90 {print NR ":" $0}' package.json

Repository: ably-forks/laravel-echo

Length of output: 1124


Align engines.node with Ably v2’s Node requirement

package.json sets engines.node to >=10, but it also declares peerDependencies.ably as ^2.0 (Ably JS v2), which requires Node.js >=16. Update engines.node accordingly to avoid consumer install/runtime breakage.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` at line 49, Update package.json's engines.node to match Ably
v2's Node requirement: change the "engines.node" value from ">=10" to ">=16" (or
">=16.0.0") so it aligns with the declared peerDependencies.ably "^2.0". Ensure
the updated engines.node entry is in package.json and run a quick install/test
to confirm no other engine constraints conflict.

Comment thread src/echo.ts
@@ -1,4 +1,4 @@
import { Channel, PresenceChannel } from './channel';
import type { Channel, PresenceChannel } from './channel';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read-only verification for import-type/export mismatch in src/echo.ts
rg -nP "import\s+type\s+\{[^}]*\b(Channel|PresenceChannel)\b[^}]*\}\s+from\s+'\.\/channel';" src/echo.ts
rg -nP "export\s+\{[^}]*\bChannel\b[^}]*\};|export\s+\{[^}]*\bPresenceChannel\b[^}]*\};" src/echo.ts

Repository: ably-forks/laravel-echo

Length of output: 180


Fix type-only re-exports in src/echo.ts to avoid TS “type used as a value” build failures.

Channel/PresenceChannel are imported via import type, but are re-exported as runtime values in export { Connector, Channel, PresenceChannel };. Re-export them as types instead.

Suggested fix
-import type { Channel, PresenceChannel } from './channel';
+import type { Channel, PresenceChannel } from './channel';
 import { AblyConnector, Connector, PusherConnector, SocketIoConnector, NullConnector } from './connector';
@@
-export { Connector, Channel, PresenceChannel };
+export { Connector };
+export type { Channel, PresenceChannel };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/echo.ts` at line 1, The current export incorrectly re-exports type-only
imports as runtime values; in src/echo.ts keep the existing import type {
Channel, PresenceChannel } and change the export to separate runtime and type
exports—export { Connector } (runtime) and export type { Channel,
PresenceChannel } (types) so Channel and PresenceChannel are only exported as
types and not as values.

@ttypic ttypic left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the contribution! We’ll take a closer look next week. Do you have any other reason for the upgrade besides keeping the dependency up to date?

@keithbrink

Copy link
Copy Markdown
Author

Yes, allow a stricter CSP configuration.

Ably v1’s webpack bundle uses new Function("return this") for global object detection, which is blocked by strict script-src CSPs (without unsafe-eval). Upgrading to v2 eliminates that eval call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants