From af8475967f11f30e8bc33a24f315b9b8c7710f60 Mon Sep 17 00:00:00 2001 From: thilllon Date: Sat, 19 Sep 2026 23:54:38 +0900 Subject: [PATCH] fix(types): retain dependencies of public declarations --- lib/types/index.d.ts | 38 +++++++++++++++++++++++++++- package-lock.json | 1 + package.json | 1 + src/core/types/api/subscription.ts | 2 -- src/node/components/configuration.ts | 26 +++++++++++++++++++ src/node/index.ts | 4 +-- src/transport/node-transport.ts | 27 +------------------- test/release/declarations.test.ts | 30 ++++++++++++++++++++++ 8 files changed, 98 insertions(+), 31 deletions(-) create mode 100644 test/release/declarations.test.ts diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index 7b45e8908..8709c6733 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -33,7 +33,7 @@ declare class PubNub extends PubNubCore< * @throws An error if {@link PubNub} client already configured to use `keepAlive`. * `keepAlive` and `proxy` can't be used simultaneously. */ - setProxy(configuration?: NodeTransportProxyConfiguration): void; + setProxy(configuration?: PubNub.NodeTransportProxyConfiguration): void; } /** @@ -2683,6 +2683,32 @@ declare namespace PubNub { ): Promise; } + /** + * Proxy configuration accepted by {@link PubNub.setProxy}. + * + * This replaces the `proxy-agent` package's `ProxyAgentOptions`. The common fields used by callers + * (`hostname`/`host`, `port`, `protocol`, `auth`) are mapped onto an `undici` proxy URI + * by the Node.js transport. A fully-formed proxy URI string is also accepted. + * + * **Known limitation (deferred to a later iteration):** unlike `proxy-agent`, `undici`'s `ProxyAgent` + * does not support SOCKS proxies, PAC files, or `HTTP(S)_PROXY`/`NO_PROXY` environment-variable + * auto-detection. Only explicit HTTP/HTTPS proxies are handled here. + */ + export type NodeTransportProxyConfiguration = + | string + | { + /** Proxy host name (alias of {@link host}). */ + hostname?: string; + /** Proxy host name. */ + host?: string; + /** Proxy port. */ + port?: number; + /** Proxy protocol (`'http'` / `'https'`). Defaults to `http`. */ + protocol?: string; + /** Basic-auth credentials in `user:password` form. */ + auth?: string; + }; + /** * NodeJS platform PubNub client configuration. */ @@ -7077,6 +7103,16 @@ declare namespace PubNub { message: DataSyncData; }; + /** + * Extended DataSync change real-time event. + * + * Type extended for listener manager support. + */ + type DataSyncEvent = { + type: PubNubEventType.DataSync; + data: DataSyncObject; + }; + /** * Subscribe request parameters. */ diff --git a/package-lock.json b/package-lock.json index d32bd2543..d37e8870c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "@types/lil-uuid": "^0.1.3", "@types/mocha": "^9.1.1", "@types/nock": "^9.3.1", + "@types/node": "^22.13.14", "@types/node-fetch": "^2.6.11", "@types/sinon": "^17.0.3", "@types/text-encoding": "^0.0.39", diff --git a/package.json b/package.json index d5e2c98f3..87cbd83f1 100644 --- a/package.json +++ b/package.json @@ -91,6 +91,7 @@ "@types/lil-uuid": "^0.1.3", "@types/mocha": "^9.1.1", "@types/nock": "^9.3.1", + "@types/node": "^22.13.14", "@types/node-fetch": "^2.6.11", "@types/sinon": "^17.0.3", "@types/text-encoding": "^0.0.39", diff --git a/src/core/types/api/subscription.ts b/src/core/types/api/subscription.ts index 9ec013ad6..eb6cb80ab 100644 --- a/src/core/types/api/subscription.ts +++ b/src/core/types/api/subscription.ts @@ -542,8 +542,6 @@ export type DataSyncObject = Event & { * Extended DataSync change real-time event. * * Type extended for listener manager support. - * - * @internal */ type DataSyncEvent = { type: PubNubEventType.DataSync; diff --git a/src/node/components/configuration.ts b/src/node/components/configuration.ts index ee6f8731c..1dd45caa1 100644 --- a/src/node/components/configuration.ts +++ b/src/node/components/configuration.ts @@ -22,6 +22,32 @@ import { ICryptoModule } from '../../core/interfaces/crypto-module'; const KEEP_ALIVE = false; // endregion +/** + * Proxy configuration accepted by {@link PubNub.setProxy}. + * + * This replaces the `proxy-agent` package's `ProxyAgentOptions`. The common fields used by callers + * (`hostname`/`host`, `port`, `protocol`, `auth`) are mapped onto an `undici` proxy URI + * by the Node.js transport. A fully-formed proxy URI string is also accepted. + * + * **Known limitation (deferred to a later iteration):** unlike `proxy-agent`, `undici`'s `ProxyAgent` + * does not support SOCKS proxies, PAC files, or `HTTP(S)_PROXY`/`NO_PROXY` environment-variable + * auto-detection. Only explicit HTTP/HTTPS proxies are handled here. + */ +export type NodeTransportProxyConfiguration = + | string + | { + /** Proxy host name (alias of {@link host}). */ + hostname?: string; + /** Proxy host name. */ + host?: string; + /** Proxy port. */ + port?: number; + /** Proxy protocol (`'http'` / `'https'`). Defaults to `http`. */ + protocol?: string; + /** Basic-auth credentials in `user:password` form. */ + auth?: string; + }; + /** * NodeJS platform PubNub client configuration. */ diff --git a/src/node/index.ts b/src/node/index.ts index db3b930e3..df282058b 100755 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -6,13 +6,13 @@ import { NodeCryptoModule, LegacyCryptor, AesCbcCryptor } from '../crypto/module import type { NodeCryptoModule as CryptoModuleType } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; import { ExtendedConfiguration, PlatformConfiguration } from '../core/interfaces/configuration'; -import { PubNubConfiguration, setDefaults } from './components/configuration'; +import { PubNubConfiguration, NodeTransportProxyConfiguration, setDefaults } from './components/configuration'; import PubNubFile, { PubNubFileParameters } from '../file/modules/node'; import { CryptorConfiguration } from '../core/interfaces/crypto-module'; import { makeConfiguration } from '../core/components/configuration'; import { TokenManager } from '../core/components/token_manager'; import { Cryptography } from '../core/interfaces/cryptography'; -import { NodeTransport, NodeTransportProxyConfiguration } from '../transport/node-transport'; +import { NodeTransport } from '../transport/node-transport'; import { PubNubMiddleware } from '../transport/middleware'; import { PubNubFileConstructor } from '../core/types/file'; import { decode } from '../core/components/base64_codec'; diff --git a/src/transport/node-transport.ts b/src/transport/node-transport.ts index 4172d70d1..648675600 100644 --- a/src/transport/node-transport.ts +++ b/src/transport/node-transport.ts @@ -8,6 +8,7 @@ import { Agent, ProxyAgent, Dispatcher, buildConnector } from 'undici'; import { Buffer } from 'buffer'; import * as zlib from 'zlib'; +import type { NodeTransportProxyConfiguration } from '../node/components/configuration'; import { CancellationController, TransportRequest } from '../core/types/transport-request'; import { Transport, TransportKeepAlive } from '../core/interfaces/transport'; import { TransportResponse } from '../core/types/transport-response'; @@ -18,32 +19,6 @@ import { PubNubAPIError } from '../errors/pubnub-api-error'; import { PubNubFileInterface } from '../core/types/file'; import { queryStringFromObject } from '../core/utils'; -/** - * Proxy configuration accepted by {@link NodeTransport.setProxy}. - * - * This replaces the `proxy-agent` package's `ProxyAgentOptions`. The common fields used by callers - * (`hostname`/`host`, `port`, `protocol`, `auth`) are mapped onto an `undici` {@link ProxyAgent} URI - * by {@link NodeTransport.proxyAgentOptions}. A fully-formed proxy URI string is also accepted. - * - * **Known limitation (deferred to a later iteration):** unlike `proxy-agent`, `undici`'s `ProxyAgent` - * does not support SOCKS proxies, PAC files, or `HTTP(S)_PROXY`/`NO_PROXY` environment-variable - * auto-detection. Only explicit HTTP/HTTPS proxies are handled here. - */ -export type NodeTransportProxyConfiguration = - | string - | { - /** Proxy host name (alias of {@link host}). */ - hostname?: string; - /** Proxy host name. */ - host?: string; - /** Proxy port. */ - port?: number; - /** Proxy protocol (`'http'` / `'https'`). Defaults to `http`. */ - protocol?: string; - /** Basic-auth credentials in `user:password` form. */ - auth?: string; - }; - /** * Class representing a `fetch`-based Node.js transport provider. * diff --git a/test/release/declarations.test.ts b/test/release/declarations.test.ts new file mode 100644 index 000000000..a7f7f3d44 --- /dev/null +++ b/test/release/declarations.test.ts @@ -0,0 +1,30 @@ +import assert from 'assert'; +import path from 'path'; +import * as ts from 'typescript'; + +describe('published TypeScript declarations', () => { + it('type-checks the complete public bundle without skipLibCheck', function () { + this.timeout(30000); + + const program = ts.createProgram([path.resolve(__dirname, '../../lib/types/index.d.ts')], { + target: ts.ScriptTarget.ES2022, + module: ts.ModuleKind.NodeNext, + moduleResolution: ts.ModuleResolutionKind.NodeNext, + strict: true, + skipLibCheck: false, + noEmit: true, + types: ['node'], + }); + const diagnostics = ts.getPreEmitDiagnostics(program); + + assert.strictEqual( + diagnostics.length, + 0, + ts.formatDiagnosticsWithColorAndContext(diagnostics, { + getCanonicalFileName: (fileName) => fileName, + getCurrentDirectory: () => process.cwd(), + getNewLine: () => '\n', + }), + ); + }); +});