From 70f678dead5c5a2994e74e7f0aff1bfba25abf72 Mon Sep 17 00:00:00 2001 From: Andrew Bulat Date: Tue, 24 Jun 2025 20:42:18 +0100 Subject: [PATCH] Add a deprecation warning `environment`, `restHost` and `realtimeHost` client options These client options have been deprecated in [1] if favor of the new `ClientOptions.endpoint` parameter. They were marked as deprecated only in the type declaration file, meaning that non-TypeScript users wouldn't see the deprecation warning. This PR adds an explicit deprecation warning log message when using these deprecated client options. [1] https://github.com/ably/ably-js/pull/1973 --- src/common/lib/util/defaults.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/common/lib/util/defaults.ts b/src/common/lib/util/defaults.ts index e871a8e19..0a040b467 100644 --- a/src/common/lib/util/defaults.ts +++ b/src/common/lib/util/defaults.ts @@ -274,10 +274,21 @@ export function normaliseOptions( MsgPack: MsgPack | null, logger: Logger | null, // should only be omitted by tests ): NormalisedClientOptions { - checkIfClientOptionsAreValid(options); - const loggerToUse = logger ?? Logger.defaultLogger; + // Deprecated options + if (options.environment) { + loggerToUse.deprecated('The `environment` client option', 'Use the `endpoint` client option instead.'); + } + if (options.restHost) { + loggerToUse.deprecated('The `restHost` client option', 'Use the `endpoint` client option instead.'); + } + if (options.realtimeHost) { + loggerToUse.deprecated('The `realtimeHost` client option', 'Use the `endpoint` client option instead.'); + } + + checkIfClientOptionsAreValid(options); + if (typeof options.recover === 'function' && options.closeOnUnload === true) { Logger.logAction( loggerToUse,